From c444f51423cc2a0ec1311380a2daee27573b36db Mon Sep 17 00:00:00 2001 From: Sirttas Date: Mon, 8 Jun 2026 08:27:42 +0200 Subject: [PATCH] js editor + fix js runner --- docs/mammon-api.yml | 13 ++++++++ src/generated/mammon/api.ts | 61 +++++++++++++++++++++++++++++++++++++ src/mammon/mammonService.ts | 6 ---- src/rules/ScriptEditor.vue | 2 +- src/rules/rules.ts | 5 ++- 5 files changed, 79 insertions(+), 8 deletions(-) diff --git a/docs/mammon-api.yml b/docs/mammon-api.yml index 288933d..87217ed 100644 --- a/docs/mammon-api.yml +++ b/docs/mammon-api.yml @@ -295,6 +295,19 @@ paths: description: New activities fetched and stored "400": description: No character with this id + /rule-books/script-definitions: + get: + tags: + - rule-book + summary: Download the TypeScript definitions for the rule script runtime + operationId: getScriptDefinitions + responses: + "200": + description: The rule-runner.d.ts type definitions + content: + text/plain: + schema: + type: string /ledgers: get: tags: diff --git a/src/generated/mammon/api.ts b/src/generated/mammon/api.ts index 09dd446..38c479c 100644 --- a/src/generated/mammon/api.ts +++ b/src/generated/mammon/api.ts @@ -1377,6 +1377,36 @@ export const RuleBookApiAxiosParamCreator = function (configuration?: Configurat options: localVarRequestOptions, }; }, + /** + * + * @summary Download the TypeScript definitions for the rule script runtime + * @param {*} [options] Override http request option. + * @throws {RequiredError} + */ + getScriptDefinitions: async (options: RawAxiosRequestConfig = {}): Promise => { + const localVarPath = `/rule-books/script-definitions`; + // use dummy base URL string because the URL constructor only accepts absolute URLs. + const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL); + let baseOptions; + if (configuration) { + baseOptions = configuration.baseOptions; + } + + const localVarRequestOptions = { method: 'GET', ...baseOptions, ...options}; + const localVarHeaderParameter = {} as any; + const localVarQueryParameter = {} as any; + + localVarHeaderParameter['Accept'] = 'text/plain'; + + setSearchParams(localVarUrlObj, localVarQueryParameter); + let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {}; + localVarRequestOptions.headers = {...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers}; + + return { + url: toPathString(localVarUrlObj), + options: localVarRequestOptions, + }; + }, /** * * @summary Update a rule book @@ -1463,6 +1493,18 @@ export const RuleBookApiFp = function(configuration?: Configuration) { const localVarOperationServerBasePath = operationServerMap['RuleBookApi.findRuleBookById']?.[localVarOperationServerIndex]?.url; return (axios, basePath) => createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration)(axios, localVarOperationServerBasePath || basePath); }, + /** + * + * @summary Download the TypeScript definitions for the rule script runtime + * @param {*} [options] Override http request option. + * @throws {RequiredError} + */ + async getScriptDefinitions(options?: RawAxiosRequestConfig): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise> { + const localVarAxiosArgs = await localVarAxiosParamCreator.getScriptDefinitions(options); + const localVarOperationServerIndex = configuration?.serverIndex ?? 0; + const localVarOperationServerBasePath = operationServerMap['RuleBookApi.getScriptDefinitions']?.[localVarOperationServerIndex]?.url; + return (axios, basePath) => createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration)(axios, localVarOperationServerBasePath || basePath); + }, /** * * @summary Update a rule book @@ -1515,6 +1557,15 @@ export const RuleBookApiFactory = function (configuration?: Configuration, baseP findRuleBookById(ruleBookId: string, options?: RawAxiosRequestConfig): AxiosPromise { return localVarFp.findRuleBookById(ruleBookId, options).then((request) => request(axios, basePath)); }, + /** + * + * @summary Download the TypeScript definitions for the rule script runtime + * @param {*} [options] Override http request option. + * @throws {RequiredError} + */ + getScriptDefinitions(options?: RawAxiosRequestConfig): AxiosPromise { + return localVarFp.getScriptDefinitions(options).then((request) => request(axios, basePath)); + }, /** * * @summary Update a rule book @@ -1565,6 +1616,16 @@ export class RuleBookApi extends BaseAPI { return RuleBookApiFp(this.configuration).findRuleBookById(ruleBookId, options).then((request) => request(this.axios, this.basePath)); } + /** + * + * @summary Download the TypeScript definitions for the rule script runtime + * @param {*} [options] Override http request option. + * @throws {RequiredError} + */ + public getScriptDefinitions(options?: RawAxiosRequestConfig) { + return RuleBookApiFp(this.configuration).getScriptDefinitions(options).then((request) => request(this.axios, this.basePath)); + } + /** * * @summary Update a rule book diff --git a/src/mammon/mammonService.ts b/src/mammon/mammonService.ts index 8fd09b4..8291789 100644 --- a/src/mammon/mammonService.ts +++ b/src/mammon/mammonService.ts @@ -23,12 +23,6 @@ const mammonAxiosInstance = axios.create({ }) logResource(mammonAxiosInstance) -export const fetchScriptDefinitions = (): Promise => - mammonAxiosInstance.get('rule-books/script-definitions', { - responseType: 'text', - headers: {Accept: 'text/plain'}, - }).then(response => response.data); - export const ledgerApi = new LedgerApi(undefined, mammonUrl, mammonAxiosInstance); export const transactionApi = new TransactionApi(undefined, mammonUrl, mammonAxiosInstance); export const characterApi = new CharacterApi(undefined, mammonUrl, mammonAxiosInstance); diff --git a/src/rules/ScriptEditor.vue b/src/rules/ScriptEditor.vue index 3801242..d23b147 100644 --- a/src/rules/ScriptEditor.vue +++ b/src/rules/ScriptEditor.vue @@ -3,7 +3,7 @@ import * as monaco from 'monaco-editor'; import editorWorker from 'monaco-editor/esm/vs/editor/editor.worker?worker'; import tsWorker from 'monaco-editor/esm/vs/language/typescript/ts.worker?worker'; import {onBeforeUnmount, onMounted, ref, watch} from 'vue'; -import {fetchScriptDefinitions} from '@/mammon'; +import {fetchScriptDefinitions} from './rules'; (self as unknown as { MonacoEnvironment: { getWorker(workerId: string, label: string): Worker } }).MonacoEnvironment = { getWorker(_workerId: string, label: string) { diff --git a/src/rules/rules.ts b/src/rules/rules.ts index 59afbc9..558e1cc 100644 --- a/src/rules/rules.ts +++ b/src/rules/rules.ts @@ -45,4 +45,7 @@ export const findCharacterRuleBookByCharacterId = (characterId: number): Promise .catch(() => ({characterId, ruleBookId: '', bindings: {}})); export const setCharacterRuleBookForCharacter = (characterId: number, ruleBook: SetCharacterRuleBookRequest): Promise => characterRuleBookApi.setCharacterRuleBookForCharacter(characterId, ruleBook) - .then(response => response.data); \ No newline at end of file + .then(response => response.data); + +export const fetchScriptDefinitions = (): Promise => + ruleBookApi.getScriptDefinitions({responseType: 'text'}).then(response => response.data); \ No newline at end of file