@accordproject/template-engine 5.0.0 → 5.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +39 -0
- package/lib/JavaScriptEvaluator.js +18 -17
- package/lib/JavaScriptEvaluator.js.map +1 -1
- package/lib/TemplateArchiveProcessor.d.ts +26 -1
- package/lib/TemplateArchiveProcessor.js +72 -8
- package/lib/TemplateArchiveProcessor.js.map +1 -1
- package/lib/TemplateMarkInterpreter.d.ts +12 -1
- package/lib/TemplateMarkInterpreter.js +133 -29
- package/lib/TemplateMarkInterpreter.js.map +1 -1
- package/lib/TemplateMarkToJavaScriptCompiler.d.ts +32 -1
- package/lib/TemplateMarkToJavaScriptCompiler.js +54 -6
- package/lib/TemplateMarkToJavaScriptCompiler.js.map +1 -1
- package/lib/TypeScriptCompilationContext.d.ts +2 -1
- package/lib/TypeScriptCompilationContext.js +12 -1
- package/lib/TypeScriptCompilationContext.js.map +1 -1
- package/lib/TypeScriptToJavaScriptCompiler.d.ts +7 -2
- package/lib/TypeScriptToJavaScriptCompiler.js +99 -35
- package/lib/TypeScriptToJavaScriptCompiler.js.map +1 -1
- package/lib/UserLogic.d.ts +59 -0
- package/lib/UserLogic.js +129 -0
- package/lib/UserLogic.js.map +1 -0
- package/lib/drafting/Double/format.js +5 -1
- package/lib/drafting/Double/format.js.map +1 -1
- package/lib/drafting/Integer/format.js +5 -1
- package/lib/drafting/Integer/format.js.map +1 -1
- package/lib/index.d.ts +2 -0
- package/lib/index.js +3 -1
- package/lib/index.js.map +1 -1
- package/lib/llm/LLMConfig.d.ts +50 -0
- package/lib/llm/LLMConfig.js +68 -1
- package/lib/llm/LLMConfig.js.map +1 -1
- package/lib/llm/LLMExecutor.d.ts +3 -1
- package/lib/llm/LLMExecutor.js +3 -2
- package/lib/llm/LLMExecutor.js.map +1 -1
- package/lib/llm/Reasoners.d.ts +83 -10
- package/lib/llm/Reasoners.js +127 -73
- package/lib/llm/Reasoners.js.map +1 -1
- package/lib/llm/index.d.ts +15 -0
- package/lib/llm/index.js +50 -0
- package/lib/llm/index.js.map +1 -0
- package/lib/runtime/typescriptLibs.d.ts +2 -0
- package/lib/runtime/typescriptLibs.js +21 -0
- package/lib/runtime/typescriptLibs.js.map +1 -0
- package/lib/utils.d.ts +29 -1
- package/lib/utils.js +62 -2
- package/lib/utils.js.map +1 -1
- package/package.json +29 -3
- package/umd/template-engine.js +5 -5
- package/umd/template-engine.js.LICENSE.txt +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TemplateMarkToJavaScriptCompiler.js","sourceRoot":"","sources":["../src/TemplateMarkToJavaScriptCompiler.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;GAYG;;;;;;
|
|
1
|
+
{"version":3,"file":"TemplateMarkToJavaScriptCompiler.js","sourceRoot":"","sources":["../src/TemplateMarkToJavaScriptCompiler.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;GAYG;;;;;;AAgEH,kCASC;AAvED,uDAAuD;AAEvD,wDAAgC;AAChC,oEAAmE;AAEnE,qFAAkF;AAElF,2GAAmF;AACnF,mCAA2F;AAE3F,MAAM,UAAU,GAAG;IACf,GAAG,mCAAiB,CAAC,SAAS,oBAAoB;IAClD,GAAG,mCAAiB,CAAC,SAAS,wBAAwB;IACtD,GAAG,mCAAiB,CAAC,SAAS,mBAAmB;CACpD,CAAC;AAQF;;;;GAIG;AACH,MAAa,wBAAyB,SAAQ,cAAc;IAGxD;;;OAGG;IACH,YAAY,MAAuB;QAC/B,KAAK,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE;YACzB,MAAM,OAAO,GAAG,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE;gBAC7B,MAAM,GAAG,GAAG,CAAC,CAAC,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,IAAI,SAAS,CAAC,CAAC,SAAS,G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,MAAM,IAAI,wBAAwB,CAAC,MAAM,CAAC,CAAC;QAC/C,CAAC;IACL,CAAC;CACJ;AAhED,4EAgEC"}
|
|
@@ -9,7 +9,8 @@ import { ClassDeclaration, ModelManager } from '@accordproject/concerto-core';
|
|
|
9
9
|
export declare class TypeScriptCompilationContext {
|
|
10
10
|
modelManager: ModelManager;
|
|
11
11
|
templateClass: ClassDeclaration;
|
|
12
|
-
|
|
12
|
+
userLogicSymbols: string[];
|
|
13
|
+
constructor(modelManager: ModelManager, templateConceptFqn?: string, userLogicSymbols?: string[]);
|
|
13
14
|
getTypeScriptFiles(): Record<string, string>;
|
|
14
15
|
/**
|
|
15
16
|
* Builds a TypeScript union type over the concrete types assignable to a runtime
|
|
@@ -12,9 +12,10 @@ const utils_1 = require("./utils");
|
|
|
12
12
|
* which is used to compile the typescript code.
|
|
13
13
|
*/
|
|
14
14
|
class TypeScriptCompilationContext {
|
|
15
|
-
constructor(modelManager, templateConceptFqn) {
|
|
15
|
+
constructor(modelManager, templateConceptFqn, userLogicSymbols = []) {
|
|
16
16
|
this.modelManager = modelManager;
|
|
17
17
|
this.templateClass = (0, utils_1.getTemplateClassDeclaration)(this.modelManager, templateConceptFqn);
|
|
18
|
+
this.userLogicSymbols = userLogicSymbols;
|
|
18
19
|
}
|
|
19
20
|
getTypeScriptFiles() {
|
|
20
21
|
const result = {};
|
|
@@ -163,6 +164,16 @@ type GenerationOptions = {
|
|
|
163
164
|
locale?:string
|
|
164
165
|
}
|
|
165
166
|
`;
|
|
167
|
+
// Ambient declarations for top-level symbols in the template's
|
|
168
|
+
// logic/logic.ts so formula expressions like {{% helperFn(...) %}}
|
|
169
|
+
// type-check. At runtime the formula evaluator prepends the
|
|
170
|
+
// compiled logic JS, so the same symbols resolve to real values.
|
|
171
|
+
if (this.userLogicSymbols.length > 0) {
|
|
172
|
+
result += '\n';
|
|
173
|
+
this.userLogicSymbols.forEach(name => {
|
|
174
|
+
result += `declare const ${name}: any;\n`;
|
|
175
|
+
});
|
|
176
|
+
}
|
|
166
177
|
return result;
|
|
167
178
|
}
|
|
168
179
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TypeScriptCompilationContext.js","sourceRoot":"","sources":["../src/TypeScriptCompilationContext.ts"],"names":[],"mappings":";;;AAcA,sEAA0D;AAC1D,gEAA8D;AAC9D,mCAOiB;AAEjB;;;;;;GAMG;AACH,MAAa,4BAA4B;
|
|
1
|
+
{"version":3,"file":"TypeScriptCompilationContext.js","sourceRoot":"","sources":["../src/TypeScriptCompilationContext.ts"],"names":[],"mappings":";;;AAcA,sEAA0D;AAC1D,gEAA8D;AAC9D,mCAOiB;AAEjB;;;;;;GAMG;AACH,MAAa,4BAA4B;IAMrC,YAAY,YAAyB,EAAC,kBAA2B,EAAE,mBAA6B,EAAE;QAC9F,IAAI,CAAC,YAAY,GAAG,YAAY,CAAC;QACjC,IAAI,CAAC,aAAa,GAAG,IAAA,mCAA2B,EAAC,IAAI,CAAC,YAAY,EAAE,kBAAkB,CAAC,CAAC;QACxF,IAAI,CAAC,gBAAgB,GAAG,gBAAgB,CAAC;IAC7C,CAAC;IAED,kBAAkB;QACd,MAAM,MAAM,GAAyB,EAAE,CAAC;QAExC,MAAM,OAAO,GAAG,IAAI,0BAAO,CAAC,iBAAiB,EAAE,CAAC;QAChD,MAAM,MAAM,GAAG,IAAI,8BAAc,EAAE,CAAC;QAEpC,MAAM,MAAM,GAAG;YACX,UAAU,EAAE,MAAM;SACrB,CAAC;QACF,IAAI,CAAC,YAAY,CAAC,MAAM,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;QAC1C,MAAM,CAAC,gBAAgB,EAAE,CAAC,OAAO,CAAE,CAAC,KAAa,EAAE,GAAW,EAAE,EAAE;YAC9D,MAAM,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;QACxB,CAAC,CAAC,CAAC;QACH,OAAO,MAAM,CAAC;IAClB,CAAC;IAED;;;;;;;;;;;;;OAaG;IACK,iBAAiB,C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|
-
|
|
7
|
+
/** @deprecated unused: the typescript module and its lib files are bundled */
|
|
8
|
+
typescriptUrl?: string;
|
|
9
|
+
constructor(modelManager: ModelManager, templateConceptFqn?: string, userLogicSymbols?: string[]);
|
|
10
|
+
/**
|
|
11
|
+
* Loads the typescript module and its lib files. Must be awaited before compile.
|
|
12
|
+
* @param {string} [typescriptUrl] deprecated and unused
|
|
13
|
+
*/
|
|
9
14
|
initialize(typescriptUrl?: string): Promise<void>;
|
|
10
15
|
compile(typescript: string): TwoSlashReturn;
|
|
11
16
|
}
|
|
@@ -60,15 +60,16 @@ const lzstring = __importStar(require("lz-string"));
|
|
|
60
60
|
* that is composed of multiple TS files to compile, along with their 3rd-party module
|
|
61
61
|
* dependencies.
|
|
62
62
|
*
|
|
63
|
-
* Note that the 'typescript' module is
|
|
64
|
-
*
|
|
63
|
+
* Note that the 'typescript' module is loaded from node_modules (Node.js) or from the
|
|
64
|
+
* bundle (browser). This module is used by twoslash. Its lib.*.d.ts files are read from
|
|
65
|
+
* node_modules (Node.js) or from the bundle (browser), so no network requests are made.
|
|
65
66
|
*
|
|
66
67
|
* The 'updateRuntimeDependencies' script it used to package type declarations for 3rd-party
|
|
67
68
|
* modules that we need to expose to user TS code: dayjs and jsonpath, these also need to be
|
|
68
|
-
* added to the twoslash compilation context.
|
|
69
|
+
* added to the twoslash compilation context. It also packages the TypeScript lib files
|
|
70
|
+
* for the browser.
|
|
69
71
|
*/
|
|
70
|
-
|
|
71
|
-
// https://microsoft.github.io/monaco-editor/typedoc/enums/languages.typescript.ScriptTarget.html#ES2020
|
|
72
|
+
// https://microsoft.github.io/monaco-editor/typedoc/enums/languages.typescript.ScriptTarget.html#ES2022
|
|
72
73
|
// enum ScriptTarget {
|
|
73
74
|
// /** @deprecated */
|
|
74
75
|
// ES3 = 0,
|
|
@@ -87,7 +88,7 @@ const TYPESCRIPT_URL = process.env.TYPESCRIPT_URL ? process.env.TYPESCRIPT_URL :
|
|
|
87
88
|
// JSON = 100,
|
|
88
89
|
// Latest = 99,
|
|
89
90
|
// }
|
|
90
|
-
const SCRIPT_TARGET = 9;
|
|
91
|
+
const SCRIPT_TARGET = 9; // ES2022
|
|
91
92
|
// enum ModuleKind {
|
|
92
93
|
// None = 0,
|
|
93
94
|
// CommonJS = 1,
|
|
@@ -103,40 +104,101 @@ const SCRIPT_TARGET = 9;
|
|
|
103
104
|
// NodeNext = 199,
|
|
104
105
|
// Preserve = 200,
|
|
105
106
|
// }
|
|
106
|
-
const MODULE_KIND = 6;
|
|
107
|
+
const MODULE_KIND = 6; // ES2020 modules
|
|
108
|
+
/**
|
|
109
|
+
* User code is compiled against the ES2022 lib only, which is what the browser bundle
|
|
110
|
+
* contains (see the 'updateRuntimeDependencies' script), so the DOM and web worker globals
|
|
111
|
+
* are not available. console is declared separately because its declaration lives in
|
|
112
|
+
* the DOM lib.
|
|
113
|
+
*/
|
|
114
|
+
const CONSOLE_LIB = 'lib.console.d.ts';
|
|
115
|
+
const CONSOLE_DECLARATION = `
|
|
116
|
+
interface Console {
|
|
117
|
+
assert(condition?: boolean, ...data: any[]): void;
|
|
118
|
+
clear(): void;
|
|
119
|
+
count(label?: string): void;
|
|
120
|
+
countReset(label?: string): void;
|
|
121
|
+
debug(...data: any[]): void;
|
|
122
|
+
dir(item?: any, options?: any): void;
|
|
123
|
+
error(...data: any[]): void;
|
|
124
|
+
group(...data: any[]): void;
|
|
125
|
+
groupCollapsed(...data: any[]): void;
|
|
126
|
+
groupEnd(): void;
|
|
127
|
+
info(...data: any[]): void;
|
|
128
|
+
log(...data: any[]): void;
|
|
129
|
+
table(tabularData?: any, properties?: string[]): void;
|
|
130
|
+
time(label?: string): void;
|
|
131
|
+
timeEnd(label?: string): void;
|
|
132
|
+
timeLog(label?: string, ...data: any[]): void;
|
|
133
|
+
trace(...data: any[]): void;
|
|
134
|
+
warn(...data: any[]): void;
|
|
135
|
+
}
|
|
136
|
+
declare var console: Console;
|
|
137
|
+
`;
|
|
138
|
+
const LIBS = ['lib.es2022.d.ts', CONSOLE_LIB];
|
|
139
|
+
/**
|
|
140
|
+
* Loading the typescript module and its lib.*.d.ts files is expensive, so it is done
|
|
141
|
+
* once per module and shared by every compiler instance. Callers must copy fsMap before
|
|
142
|
+
* handing it to twoslash, because twoslash writes the files it compiles into the map
|
|
143
|
+
* it is given.
|
|
144
|
+
*/
|
|
145
|
+
let typeScriptLibrary;
|
|
146
|
+
async function loadTypeScriptLibrary() {
|
|
147
|
+
let ts;
|
|
148
|
+
let fsMap;
|
|
149
|
+
if (typeof window === 'undefined') {
|
|
150
|
+
// node does not (yet) support http(s) imports
|
|
151
|
+
// see: https://nodejs.org/api/esm.html#https-and-http-imports
|
|
152
|
+
ts = (await Promise.resolve().then(() => __importStar(require('typescript')))).default;
|
|
153
|
+
if (!ts) {
|
|
154
|
+
throw new Error('Failed to load typescript module');
|
|
155
|
+
}
|
|
156
|
+
fsMap = (0, vfs_1.createDefaultMapFromNodeModules)({
|
|
157
|
+
target: SCRIPT_TARGET,
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
else {
|
|
161
|
+
// Use the bundled typescript in the browser rather than a dynamic CDN module
|
|
162
|
+
// import: webpack cannot resolve the runtime CDN URL ('Cannot find module
|
|
163
|
+
// https://...'), and twoslash already pulls typescript into the browser bundle.
|
|
164
|
+
ts = (await Promise.resolve().then(() => __importStar(require('typescript')))).default;
|
|
165
|
+
if (!ts) {
|
|
166
|
+
throw new Error('Failed to load typescript module');
|
|
167
|
+
}
|
|
168
|
+
// the lib files are bundled too, rather than fetched from the TypeScript CDN
|
|
169
|
+
const { TYPESCRIPT_LIBS } = await Promise.resolve().then(() => __importStar(require('./runtime/typescriptLibs')));
|
|
170
|
+
fsMap = new Map(Object.entries(TYPESCRIPT_LIBS));
|
|
171
|
+
}
|
|
172
|
+
fsMap.set(`/${CONSOLE_LIB}`, CONSOLE_DECLARATION);
|
|
173
|
+
fsMap.set('/node_modules/@types/dayjs/index.d.ts', Buffer.from(declarations_1.DAYJS_BASE64, 'base64').toString());
|
|
174
|
+
fsMap.set('/node_modules/@types/jsonpath/index.d.ts', Buffer.from(declarations_1.JSONPATH_BASE64, 'base64').toString());
|
|
175
|
+
return { ts, fsMap };
|
|
176
|
+
}
|
|
177
|
+
function getTypeScriptLibrary() {
|
|
178
|
+
if (!typeScriptLibrary) {
|
|
179
|
+
typeScriptLibrary = loadTypeScriptLibrary().catch((err) => {
|
|
180
|
+
// don't cache a failed load, so that a later call can retry
|
|
181
|
+
typeScriptLibrary = undefined;
|
|
182
|
+
throw err;
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
return typeScriptLibrary;
|
|
186
|
+
}
|
|
107
187
|
class TypeScriptToJavaScriptCompiler {
|
|
108
|
-
constructor(modelManager, templateConceptFqn) {
|
|
109
|
-
this.context = new TypeScriptCompilationContext_1.TypeScriptCompilationContext(modelManager, templateConceptFqn).getCompilationContext();
|
|
110
|
-
this.typescriptUrl = TYPESCRIPT_URL;
|
|
188
|
+
constructor(modelManager, templateConceptFqn, userLogicSymbols = []) {
|
|
189
|
+
this.context = new TypeScriptCompilationContext_1.TypeScriptCompilationContext(modelManager, templateConceptFqn, userLogicSymbols).getCompilationContext();
|
|
111
190
|
}
|
|
191
|
+
/**
|
|
192
|
+
* Loads the typescript module and its lib files. Must be awaited before compile.
|
|
193
|
+
* @param {string} [typescriptUrl] deprecated and unused
|
|
194
|
+
*/
|
|
112
195
|
async initialize(typescriptUrl) {
|
|
113
196
|
if (typescriptUrl) {
|
|
114
197
|
this.typescriptUrl = typescriptUrl;
|
|
115
198
|
}
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
this.ts = (await Promise.resolve().then(() => __importStar(require('typescript')))).default;
|
|
120
|
-
if (!this.ts) {
|
|
121
|
-
throw new Error('Failed to load typescript module');
|
|
122
|
-
}
|
|
123
|
-
this.fsMap = (0, vfs_1.createDefaultMapFromNodeModules)({
|
|
124
|
-
target: SCRIPT_TARGET,
|
|
125
|
-
});
|
|
126
|
-
}
|
|
127
|
-
else {
|
|
128
|
-
// Use the bundled typescript in the browser rather than a dynamic CDN module
|
|
129
|
-
// import: webpack cannot resolve the runtime CDN URL ('Cannot find module
|
|
130
|
-
// https://...'), and twoslash already pulls typescript into the browser bundle.
|
|
131
|
-
this.ts = (await Promise.resolve().then(() => __importStar(require('typescript')))).default;
|
|
132
|
-
if (!this.ts) {
|
|
133
|
-
throw new Error('Failed to load typescript module');
|
|
134
|
-
}
|
|
135
|
-
// lib.d.ts files are still fetched from the CDN at runtime (a browser fetch).
|
|
136
|
-
this.fsMap = await (0, vfs_1.createDefaultMapFromCDN)({ target: SCRIPT_TARGET }, this.ts.version, false, this.ts);
|
|
137
|
-
}
|
|
138
|
-
this.fsMap.set('/node_modules/@types/dayjs/index.d.ts', Buffer.from(declarations_1.DAYJS_BASE64, 'base64').toString());
|
|
139
|
-
this.fsMap.set('/node_modules/@types/jsonpath/index.d.ts', Buffer.from(declarations_1.JSONPATH_BASE64, 'base64').toString());
|
|
199
|
+
const library = await getTypeScriptLibrary();
|
|
200
|
+
this.ts = library.ts;
|
|
201
|
+
this.fsMap = new Map(library.fsMap);
|
|
140
202
|
}
|
|
141
203
|
compile(typescript) {
|
|
142
204
|
if (!this.fsMap) {
|
|
@@ -147,11 +209,13 @@ ${this.context}
|
|
|
147
209
|
${typescript}
|
|
148
210
|
`;
|
|
149
211
|
const options = {
|
|
150
|
-
|
|
212
|
+
// twoslash writes the compiled files into the map, so give it a fresh copy
|
|
213
|
+
fsMap: new Map(this.fsMap),
|
|
151
214
|
tsModule: this.ts,
|
|
152
215
|
defaultCompilerOptions: {
|
|
153
216
|
target: SCRIPT_TARGET,
|
|
154
217
|
module: MODULE_KIND,
|
|
218
|
+
lib: LIBS,
|
|
155
219
|
},
|
|
156
220
|
lzstringModule: lzstring,
|
|
157
221
|
defaultOptions: {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TypeScriptToJavaScriptCompiler.js","sourceRoot":"","sources":["../src/TypeScriptToJavaScriptCompiler.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;GAYG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEH,uDAAuD;AAEvD,
|
|
1
|
+
{"version":3,"file":"TypeScriptToJavaScriptCompiler.js","sourceRoot":"","sources":["../src/TypeScriptToJavaScriptCompiler.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;GAYG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEH,uDAAuD;AAEvD,yCAAkE;AAClE,mDAAmF;AAEnF,iFAA8E;AAC9E,yDAAuE;AACvE,oDAAsC;AAEtC;;;;;;;;;;;;;;;GAeG;AAEH,wGAAwG;AACpG,sBAAsB;AACtB,yBAAyB;AACzB,eAAe;AACf,eAAe;AACf,kBAAkB;AAClB,kBAAkB;AAClB,kBAAkB;AAClB,kBAAkB;AAClB,kBAAkB;AAClB,kBAAkB;AAClB,kBAAkB;AAClB,kBAAkB;AAClB,mBAAmB;AACnB,mBAAmB;AACnB,mBAAmB;AACnB,kBAAkB;AAClB,mBAAmB;AACnB,IAAI;AAER,MAAM,aAAa,GAAG,CAAC,CAAA,CAAC,SAAS;AAE7B,oBAAoB;AACpB,gBAAgB;AAChB,oBAAoB;AACpB,eAAe;AACf,eAAe;AACf,kBAAkB;AAClB,kBAAkB;AAClB,kBAAkB;AAClB,kBAAkB;AAClB,mBAAmB;AACnB,oBAAoB;AACpB,oBAAoB;AACpB,sBAAsB;AACtB,sBAAsB;AACtB,IAAI;AAER,MAAM,WAAW,GAAG,CAAC,CAAC,CAAC,iBAAiB;AAExC;;;;;GAKG;AACH,MAAM,WAAW,GAAG,kBAAkB,CAAC;AACvC,MAAM,mBAAmB,GAAG;;;;;;;;;;;;;;;;;;;;;;CAsB3B,CAAC;AACF,MAAM,IAAI,GAAG,CAAC,iBAAiB,EAAE,WAAW,CAAC,CAAC;AAO9C;;;;;GAKG;AACH,IAAI,iBAAyD,CAAC;AAE9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EAAC,QAAQ;YACvB,cAAc,EAAE;gBACZ,QAAQ,EAAE,IAAI;gBACd,iBAAiB,EAAE,IAAI;gBACvB,eAAe,EAAE,SAAS;aAC7B;SACJ,CAAC;QACF,6BAA6B;QAC7B,MAAM,MAAM,GAAG,IAAA,qBAAU,EAAC,YAAY,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC;QACvD,OAAO,MAAM,CAAC;IAClB,CAAC;CACJ;AAtDD,wEAsDC"}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { ModelManager } from '@accordproject/concerto-core';
|
|
2
|
+
/**
|
|
3
|
+
* The result of compiling the user-authored logic.ts that ships
|
|
4
|
+
* with a template archive. Used by TemplateArchiveProcessor.draft
|
|
5
|
+
* to expose helper symbols to formula expressions like
|
|
6
|
+
* {{% helperFn(...) %}}.
|
|
7
|
+
*/
|
|
8
|
+
export type CompiledUserLogic = {
|
|
9
|
+
/** Raw TypeScript source from logic/logic.ts */
|
|
10
|
+
source: string;
|
|
11
|
+
/** Compiled JavaScript (ESM) output */
|
|
12
|
+
compiledJs: string;
|
|
13
|
+
/**
|
|
14
|
+
* Top-level identifiers (functions, classes, const/let/var bindings)
|
|
15
|
+
* declared by logic.ts. Used to populate `declare const X: any`
|
|
16
|
+
* stubs when compiling inline formulas, so user helper functions
|
|
17
|
+
* type-check.
|
|
18
|
+
*/
|
|
19
|
+
symbols: string[];
|
|
20
|
+
/**
|
|
21
|
+
* `compiledJs` with `import`/`export` statements stripped so it can be
|
|
22
|
+
* spliced into a formula function body as a runtime prelude.
|
|
23
|
+
*/
|
|
24
|
+
prelude: string;
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* Compiles the template's logic/logic.ts to JavaScript, using the same
|
|
28
|
+
* compilation context as TemplateArchiveProcessor.compileLogic (see issue #147).
|
|
29
|
+
* @param {ModelManager} modelManager the template's model manager
|
|
30
|
+
* @param {string} templateConceptFqn the fully qualified name of the template concept
|
|
31
|
+
* @param {string} source the TypeScript source of logic/logic.ts
|
|
32
|
+
* @returns {Promise<CompiledUserLogic>} the compiled user logic
|
|
33
|
+
*/
|
|
34
|
+
export declare function compileUserLogic(modelManager: ModelManager, templateConceptFqn: string, source: string): Promise<CompiledUserLogic>;
|
|
35
|
+
/**
|
|
36
|
+
* Builds a CompiledUserLogic from logic.ts source and its already compiled JavaScript.
|
|
37
|
+
* @param {string} source the TypeScript source of logic/logic.ts
|
|
38
|
+
* @param {string} compiledJs the compiled JavaScript for the source
|
|
39
|
+
* @returns {Promise<CompiledUserLogic>} the compiled user logic
|
|
40
|
+
*/
|
|
41
|
+
export declare function toCompiledUserLogic(source: string, compiledJs: string): Promise<CompiledUserLogic>;
|
|
42
|
+
/**
|
|
43
|
+
* Removes top-level `import` statements and the `export` keyword from
|
|
44
|
+
* JS source so that the remaining declarations can be evaluated inside
|
|
45
|
+
* a function body via `new Function(...)`. The compiled output of
|
|
46
|
+
* logic.ts is an ES module; both `import` and `export` are syntax
|
|
47
|
+
* errors inside a `new Function` body.
|
|
48
|
+
* @param {string} js the JavaScript source
|
|
49
|
+
* @returns {string} the JavaScript without module syntax
|
|
50
|
+
*/
|
|
51
|
+
export declare function stripModuleSyntax(js: string): string;
|
|
52
|
+
/**
|
|
53
|
+
* Returns the names of the top-level runtime values (functions, classes and
|
|
54
|
+
* const/let/var bindings) declared by a TypeScript source file. Ambient
|
|
55
|
+
* (`declare`) declarations and type-only declarations are ignored.
|
|
56
|
+
* @param {string} source the TypeScript source
|
|
57
|
+
* @returns {Promise<string[]>} the declared names
|
|
58
|
+
*/
|
|
59
|
+
export declare function extractTopLevelSymbols(source: string): Promise<string[]>;
|
package/lib/UserLogic.js
ADDED
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
* you may not use this file except in compliance with the License.
|
|
5
|
+
* You may obtain a copy of the License at
|
|
6
|
+
*
|
|
7
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
*
|
|
9
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
* See the License for the specific language governing permissions and
|
|
13
|
+
* limitations under the License.
|
|
14
|
+
*/
|
|
15
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
16
|
+
if (k2 === undefined) k2 = k;
|
|
17
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
18
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
19
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
20
|
+
}
|
|
21
|
+
Object.defineProperty(o, k2, desc);
|
|
22
|
+
}) : (function(o, m, k, k2) {
|
|
23
|
+
if (k2 === undefined) k2 = k;
|
|
24
|
+
o[k2] = m[k];
|
|
25
|
+
}));
|
|
26
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
27
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
28
|
+
}) : function(o, v) {
|
|
29
|
+
o["default"] = v;
|
|
30
|
+
});
|
|
31
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
32
|
+
var ownKeys = function(o) {
|
|
33
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
34
|
+
var ar = [];
|
|
35
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
36
|
+
return ar;
|
|
37
|
+
};
|
|
38
|
+
return ownKeys(o);
|
|
39
|
+
};
|
|
40
|
+
return function (mod) {
|
|
41
|
+
if (mod && mod.__esModule) return mod;
|
|
42
|
+
var result = {};
|
|
43
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
44
|
+
__setModuleDefault(result, mod);
|
|
45
|
+
return result;
|
|
46
|
+
};
|
|
47
|
+
})();
|
|
48
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
49
|
+
exports.compileUserLogic = compileUserLogic;
|
|
50
|
+
exports.toCompiledUserLogic = toCompiledUserLogic;
|
|
51
|
+
exports.stripModuleSyntax = stripModuleSyntax;
|
|
52
|
+
exports.extractTopLevelSymbols = extractTopLevelSymbols;
|
|
53
|
+
const TypeScriptToJavaScriptCompiler_1 = require("./TypeScriptToJavaScriptCompiler");
|
|
54
|
+
/**
|
|
55
|
+
* Compiles the template's logic/logic.ts to JavaScript, using the same
|
|
56
|
+
* compilation context as TemplateArchiveProcessor.compileLogic (see issue #147).
|
|
57
|
+
* @param {ModelManager} modelManager the template's model manager
|
|
58
|
+
* @param {string} templateConceptFqn the fully qualified name of the template concept
|
|
59
|
+
* @param {string} source the TypeScript source of logic/logic.ts
|
|
60
|
+
* @returns {Promise<CompiledUserLogic>} the compiled user logic
|
|
61
|
+
*/
|
|
62
|
+
async function compileUserLogic(modelManager, templateConceptFqn, source) {
|
|
63
|
+
const compiler = new TypeScriptToJavaScriptCompiler_1.TypeScriptToJavaScriptCompiler(modelManager, templateConceptFqn);
|
|
64
|
+
await compiler.initialize();
|
|
65
|
+
const result = compiler.compile(source);
|
|
66
|
+
return toCompiledUserLogic(source, result.code || '');
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Builds a CompiledUserLogic from logic.ts source and its already compiled JavaScript.
|
|
70
|
+
* @param {string} source the TypeScript source of logic/logic.ts
|
|
71
|
+
* @param {string} compiledJs the compiled JavaScript for the source
|
|
72
|
+
* @returns {Promise<CompiledUserLogic>} the compiled user logic
|
|
73
|
+
*/
|
|
74
|
+
async function toCompiledUserLogic(source, compiledJs) {
|
|
75
|
+
const prelude = stripModuleSyntax(compiledJs);
|
|
76
|
+
const symbols = await extractTopLevelSymbols(source);
|
|
77
|
+
return { source, compiledJs, symbols, prelude };
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Removes top-level `import` statements and the `export` keyword from
|
|
81
|
+
* JS source so that the remaining declarations can be evaluated inside
|
|
82
|
+
* a function body via `new Function(...)`. The compiled output of
|
|
83
|
+
* logic.ts is an ES module; both `import` and `export` are syntax
|
|
84
|
+
* errors inside a `new Function` body.
|
|
85
|
+
* @param {string} js the JavaScript source
|
|
86
|
+
* @returns {string} the JavaScript without module syntax
|
|
87
|
+
*/
|
|
88
|
+
function stripModuleSyntax(js) {
|
|
89
|
+
let result = js;
|
|
90
|
+
// Drop import statements (single or multi-line).
|
|
91
|
+
result = result.replace(/^[ \t]*import[\s\S]*?(?:;|\n)/gm, '');
|
|
92
|
+
// Drop `export default <expr>;` lines entirely.
|
|
93
|
+
result = result.replace(/^[ \t]*export\s+default\s+[^;\n]*;?\s*$/gm, '');
|
|
94
|
+
// Strip a leading `export ` keyword from declarations
|
|
95
|
+
// (`export function`, `export class`, `export const`, ...).
|
|
96
|
+
result = result.replace(/^[ \t]*export\s+(?=(?:async\s+)?(?:abstract\s+)?(?:function|class|const|let|var|interface|type|enum)\b)/gm, '');
|
|
97
|
+
return result;
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Returns the names of the top-level runtime values (functions, classes and
|
|
101
|
+
* const/let/var bindings) declared by a TypeScript source file. Ambient
|
|
102
|
+
* (`declare`) declarations and type-only declarations are ignored.
|
|
103
|
+
* @param {string} source the TypeScript source
|
|
104
|
+
* @returns {Promise<string[]>} the declared names
|
|
105
|
+
*/
|
|
106
|
+
async function extractTopLevelSymbols(source) {
|
|
107
|
+
const tsImport = await Promise.resolve().then(() => __importStar(require('typescript')));
|
|
108
|
+
const ts = ('default' in tsImport && tsImport.default ? tsImport.default : tsImport);
|
|
109
|
+
const sourceFile = ts.createSourceFile('logic.ts', source, ts.ScriptTarget.Latest, true, ts.ScriptKind.TS);
|
|
110
|
+
const names = new Set();
|
|
111
|
+
for (const statement of sourceFile.statements) {
|
|
112
|
+
const modifiers = ts.canHaveModifiers(statement) ? ts.getModifiers(statement) : undefined;
|
|
113
|
+
if (modifiers?.some(m => m.kind === ts.SyntaxKind.DeclareKeyword)) {
|
|
114
|
+
continue;
|
|
115
|
+
}
|
|
116
|
+
if ((ts.isFunctionDeclaration(statement) || ts.isClassDeclaration(statement)) && statement.name) {
|
|
117
|
+
names.add(statement.name.text);
|
|
118
|
+
}
|
|
119
|
+
else if (ts.isVariableStatement(statement)) {
|
|
120
|
+
for (const declaration of statement.declarationList.declarations) {
|
|
121
|
+
if (ts.isIdentifier(declaration.name)) {
|
|
122
|
+
names.add(declaration.name.text);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
return Array.from(names);
|
|
128
|
+
}
|
|
129
|
+
//# sourceMappingURL=UserLogic.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"UserLogic.js","sourceRoot":"","sources":["../src/UserLogic.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;GAYG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsCH,4CASC;AAQD,kDAIC;AAWD,8CAUC;AASD,wDAsBC;AA5GD,qFAAkF;AA2BlF;;;;;;;GAOG;AACI,KAAK,UAAU,gBAAgB,CAClC,YAA0B,EAC1B,kBAA0B,EAC1B,MAAc;IAEd,MAAM,QAAQ,GAAG,IAAI,+DAA8B,CAAC,YAAY,EAAE,kBAAkB,CAAC,CAAC;IACtF,MAAM,QAAQ,CAAC,UAAU,EAAE,CAAC;IAC5B,MAAM,MAAM,GAAG,QAAQ,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;IACxC,OAAO,mBAAmB,CAAC,MAAM,EAAE,MAAM,CAAC,IAAI,IAAI,EAAE,CAAC,CAAC;AAC1D,CAAC;AAED;;;;;GAKG;AACI,KAAK,UAAU,mBAAmB,CAAC,MAAc,EAAE,UAAkB;IACxE,MAAM,OAAO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AAS,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;QAC1F,IAAI,SAAS,EAAE,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,EAAE,CAAC,UAAU,CAAC,cAAc,CAAC,EAAE,CAAC;YAChE,SAAS;QACb,CAAC;QACD,IAAI,CAAC,EAAE,CAAC,qBAAqB,CAAC,SAAS,CAAC,IAAI,EAAE,CAAC,kBAAkB,CAAC,SAAS,CAAC,CAAC,IAAI,SAAS,CAAC,IAAI,EAAE,CAAC;YAC9F,KAAK,CAAC,GAAG,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACnC,CAAC;aACI,IAAI,EAAE,CAAC,mBAAmB,CAAC,SAAS,CAAC,EAAE,CAAC;YACzC,KAAK,MAAM,WAAW,IAAI,SAAS,CAAC,eAAe,CAAC,YAAY,EAAE,CAAC;gBAC/D,IAAI,EAAE,CAAC,YAAY,CAAC,WAAW,CAAC,IAAI,CAAC,EAAE,CAAC;oBACpC,KAAK,CAAC,GAAG,CAAC,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;gBACrC,CAAC;YACL,CAAC;QACL,CAAC;IACL,CAAC;IACD,OAAO,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;AAC7B,CAAC"}
|
|
@@ -51,11 +51,15 @@ function draftDoubleFormat(value, format) {
|
|
|
51
51
|
res += sep2 + d;
|
|
52
52
|
}
|
|
53
53
|
let i = vs.substring(0, vs.length - (len === 0 ? 0 : len + 1));
|
|
54
|
+
// Group the digits only. Leaving the minus sign in place would let it
|
|
55
|
+
// be counted as a digit, so -123 would be grouped as -,123.
|
|
56
|
+
const sign = i.startsWith('-') ? '-' : '';
|
|
57
|
+
i = i.substring(sign.length);
|
|
54
58
|
while (i.length > 3) {
|
|
55
59
|
res = sep1 + i.substring(i.length - 3) + res;
|
|
56
60
|
i = i.substring(0, i.length - 3);
|
|
57
61
|
}
|
|
58
|
-
return i + res;
|
|
62
|
+
return sign + i + res;
|
|
59
63
|
});
|
|
60
64
|
}
|
|
61
65
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"format.js","sourceRoot":"","sources":["../../../src/drafting/Double/format.ts"],"names":[],"mappings":";;AAoBA,0CAMC;AAQD,
|
|
1
|
+
{"version":3,"file":"format.js","sourceRoot":"","sources":["../../../src/drafting/Double/format.ts"],"names":[],"mappings":";;AAoBA,0CAMC;AAQD,8CA0BC;AA5DD;;;;;;;;;;;;GAYG;AACH,uCAAiC;AAEjC;;;;GAIG;AACH,SAAgB,eAAe,CAAC,KAAY;IACxC,IAAI,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,KAAK,KAAK,EAAE,CAAC;QAC9B,OAAO,CAAC,IAAI,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,0CAA0C;IACrF,CAAC;SAAM,CAAC;QACJ,OAAO,EAAE,GAAG,KAAK,CAAC;IACtB,CAAC;AACL,CAAC;AAED;;;;;GAKG;AACH,SAAgB,iBAAiB,CAAC,KAAY,EAAC,MAAwB;IACnE,IAAG,MAAM,KAAG,MAAM,EAAE,CAAC;QACjB,MAAM,SAAS,GAAW,IAAI,kBAAO,EAAE,CAAC;QACxC,MAAM,GAAG,GAAQ,SAAS,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;QAC1C,OAAO,GAAG,CAAC;IACf,CAAC;SAAM,CAAC;QACJ,OAAO,MAAM,CAAC,OAAO,CAAC,mBAAmB,EAAE,UAAS,EAAE,EAAC,IAAI,EAAC,EAAE,EAAC,IAAI,EAAC,MAAM;YACtE,MAAM,GAAG,GAAG,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;YACvC,MAAM,EAAE,GAAG,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;YAC9B,IAAI,GAAG,GAAG,EAAE,CAAC;YACb,IAAI,IAAI,EAAE,CAAC;gBACP,MAAM,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,EAAE,CAAC,MAAM,GAAG,GAAG,CAAC,CAAC;gBACxC,GAAG,IAAI,IAAI,GAAG,CAAC,CAAC;YACpB,CAAC;YACD,IAAI,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,CAAC,EAAC,EAAE,CAAC,MAAM,GAAG,CAAC,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,GAAC,CAAC,CAAC,CAAC,CAAC;YAC5D,sEAAsE;YACtE,4DAA4D;YAC5D,MAAM,IAAI,GAAG,CAAC,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC;YAC1C,CAAC,GAAG,CAAC,CAAC,SAAS,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;YAC7B,OAAO,CAAC,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;gBAClB,GAAG,GAAG,IAAI,GAAG,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC,GAAG,GAAG,CAAC;gBAC7C,CAAC,GAAG,CAAC,CAAC,SAAS,CAAC,CAAC,EAAE,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;YACrC,CAAC;YACD,OAAO,IAAI,GAAG,CAAC,GAAG,GAAG,CAAC;QAC1B,CAAC,CAAC,CAAC;IACP,CAAC;AACL,CAAC"}
|
|
@@ -41,11 +41,15 @@ function draftIntegerFormat(value, format) {
|
|
|
41
41
|
const vs = value.toFixed(0);
|
|
42
42
|
let res = '';
|
|
43
43
|
let i = vs.substring(0, vs.length);
|
|
44
|
+
// Group the digits only. Leaving the minus sign in place would let it
|
|
45
|
+
// be counted as a digit, so -123 would be grouped as -,123.
|
|
46
|
+
const sign = i.startsWith('-') ? '-' : '';
|
|
47
|
+
i = i.substring(sign.length);
|
|
44
48
|
while (i.length > 3) {
|
|
45
49
|
res = sep1 + i.substring(i.length - 3) + res;
|
|
46
50
|
i = i.substring(0, i.length - 3);
|
|
47
51
|
}
|
|
48
|
-
return i + res;
|
|
52
|
+
return sign + i + res;
|
|
49
53
|
});
|
|
50
54
|
}
|
|
51
55
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"format.js","sourceRoot":"","sources":["../../../src/drafting/Integer/format.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;GAYG;;AAUH,oCAEC;AAQD,
|
|
1
|
+
{"version":3,"file":"format.js","sourceRoot":"","sources":["../../../src/drafting/Integer/format.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;GAYG;;AAUH,oCAEC;AAQD,gDAqBC;AAvCD,uCAAiC;AAGjC;;;;GAIG;AACH,SAAgB,YAAY,CAAC,KAAY;IACrC,OAAO,EAAE,GAAG,KAAK,CAAC;AACtB,CAAC;AAED;;;;;GAKG;AACH,SAAgB,kBAAkB,CAAC,KAAY,EAAC,MAAwB;IACpE,IAAI,MAAM,KAAK,MAAM,EAAE,CAAC;QACpB,MAAM,SAAS,GAAW,IAAI,kBAAO,EAAE,CAAC;QACxC,MAAM,GAAG,GAAQ,SAAS,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;QAC1C,OAAO,GAAG,CAAC;IACf,CAAC;SAAM,CAAC;QACJ,OAAO,MAAM,CAAC,OAAO,CAAC,SAAS,EAAE,UAAS,EAAE,EAAC,IAAI;YAC7C,MAAM,EAAE,GAAG,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;YAC5B,IAAI,GAAG,GAAG,EAAE,CAAC;YACb,IAAI,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,CAAC,EAAC,EAAE,CAAC,MAAM,CAAC,CAAC;YAClC,sEAAsE;YACtE,4DAA4D;YAC5D,MAAM,IAAI,GAAG,CAAC,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC;YAC1C,CAAC,GAAG,CAAC,CAAC,SAAS,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;YAC7B,OAAO,CAAC,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;gBAClB,GAAG,GAAG,IAAI,GAAG,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC,GAAG,GAAG,CAAC;gBAC7C,CAAC,GAAG,CAAC,CAAC,SAAS,CAAC,CAAC,EAAE,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;YACrC,CAAC;YACD,OAAO,IAAI,GAAG,CAAC,GAAG,GAAG,CAAC;QAC1B,CAAC,CAAC,CAAC;IACP,CAAC;AACL,CAAC"}
|
package/lib/index.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import type { TemplateLogic } from './slc/SmartLegalContract.d.ts';
|
|
2
2
|
export { TemplateMarkInterpreter } from './TemplateMarkInterpreter';
|
|
3
3
|
export { TemplateArchiveProcessor } from './TemplateArchiveProcessor';
|
|
4
|
+
export { TemplateCompilationError } from './TemplateMarkToJavaScriptCompiler';
|
|
5
|
+
export type { CompilerError } from './TemplateMarkToJavaScriptCompiler';
|
|
4
6
|
export { TemplateLogic };
|
|
5
7
|
export * from './utils';
|
|
6
8
|
export { ModelManager } from '@accordproject/concerto-core';
|
package/lib/index.js
CHANGED
|
@@ -27,11 +27,13 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
27
27
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
28
28
|
};
|
|
29
29
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
30
|
-
exports.TemplateMarkTransformer = exports.ModelManager = exports.TemplateArchiveProcessor = exports.TemplateMarkInterpreter = void 0;
|
|
30
|
+
exports.TemplateMarkTransformer = exports.ModelManager = exports.TemplateCompilationError = exports.TemplateArchiveProcessor = exports.TemplateMarkInterpreter = void 0;
|
|
31
31
|
var TemplateMarkInterpreter_1 = require("./TemplateMarkInterpreter");
|
|
32
32
|
Object.defineProperty(exports, "TemplateMarkInterpreter", { enumerable: true, get: function () { return TemplateMarkInterpreter_1.TemplateMarkInterpreter; } });
|
|
33
33
|
var TemplateArchiveProcessor_1 = require("./TemplateArchiveProcessor");
|
|
34
34
|
Object.defineProperty(exports, "TemplateArchiveProcessor", { enumerable: true, get: function () { return TemplateArchiveProcessor_1.TemplateArchiveProcessor; } });
|
|
35
|
+
var TemplateMarkToJavaScriptCompiler_1 = require("./TemplateMarkToJavaScriptCompiler");
|
|
36
|
+
Object.defineProperty(exports, "TemplateCompilationError", { enumerable: true, get: function () { return TemplateMarkToJavaScriptCompiler_1.TemplateCompilationError; } });
|
|
35
37
|
__exportStar(require("./utils"), exports);
|
|
36
38
|
// Re-exported for convenience so a single browser bundle can run the full
|
|
37
39
|
// model -> template -> agreement flow (and so consumers share one concerto instance).
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;GAYG;;;;;;;;;;;;;;;;;AAIH,qEAAoE;AAA3D,kIAAA,uBAAuB,OAAA;AAChC,uEAAsE;AAA7D,oIAAA,wBAAwB,OAAA;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;GAYG;;;;;;;;;;;;;;;;;AAIH,qEAAoE;AAA3D,kIAAA,uBAAuB,OAAA;AAChC,uEAAsE;AAA7D,oIAAA,wBAAwB,OAAA;AACjC,uFAA8E;AAArE,4IAAA,wBAAwB,OAAA;AAGjC,0CAAwB;AAExB,0EAA0E;AAC1E,sFAAsF;AACtF,8DAA4D;AAAnD,6GAAA,YAAY,OAAA;AACrB,sEAA2E;AAAlE,4HAAA,uBAAuB,OAAA"}
|
package/lib/llm/LLMConfig.d.ts
CHANGED
|
@@ -36,6 +36,13 @@ export interface BaseProviderConfig {
|
|
|
36
36
|
topP?: number;
|
|
37
37
|
retries?: number;
|
|
38
38
|
timeoutMs?: number;
|
|
39
|
+
/**
|
|
40
|
+
* Extra options merged into the underlying provider SDK's client
|
|
41
|
+
* constructor, e.g. `{ dangerouslyAllowBrowser: true }` for the OpenAI and
|
|
42
|
+
* Anthropic SDKs when running client-side. Node consumers never need this;
|
|
43
|
+
* browser consumers set it once here instead of forking the reasoner.
|
|
44
|
+
*/
|
|
45
|
+
clientOptions?: Record<string, unknown>;
|
|
39
46
|
}
|
|
40
47
|
/**
|
|
41
48
|
* Configuration for Groq models.
|
|
@@ -119,3 +126,46 @@ export interface LLMExecutorConfig {
|
|
|
119
126
|
provider: LLMProviderConfig;
|
|
120
127
|
verbose?: boolean;
|
|
121
128
|
}
|
|
129
|
+
/**
|
|
130
|
+
* Which tuning knobs a provider's reasoner actually reads off its config —
|
|
131
|
+
* see `Reasoners.ts`. Lets a caller building a settings UI skip rendering a
|
|
132
|
+
* control (e.g. Temperature) that the chosen provider would silently ignore.
|
|
133
|
+
*/
|
|
134
|
+
export interface ProviderCapabilities {
|
|
135
|
+
/** Reasoning-effort levels the provider accepts, or null if it takes none. */
|
|
136
|
+
effort: readonly ReasoningEffort[] | null;
|
|
137
|
+
/** Whether {@link BaseProviderConfig.temperature} is read. Currently `groq` only. */
|
|
138
|
+
temperature: boolean;
|
|
139
|
+
/** Whether extended thinking can be toggled. Currently `anthropic` only. */
|
|
140
|
+
thinking: boolean;
|
|
141
|
+
/** Whether the provider enforces a JSON Schema on its own output. */
|
|
142
|
+
structuredOutput: boolean;
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Capability matrix, keyed by provider id. Kept next to the reasoners it
|
|
146
|
+
* describes so a change to what a reasoner reads off its config can't drift
|
|
147
|
+
* from what this table promises.
|
|
148
|
+
*/
|
|
149
|
+
export declare const PROVIDER_CAPABILITIES: Record<LLMProviderConfig['provider'], ProviderCapabilities>;
|
|
150
|
+
/**
|
|
151
|
+
* Reads the capabilities of a provider, defaulting to "no tuning knobs" for
|
|
152
|
+
* an id this table doesn't recognise.
|
|
153
|
+
* @param provider - a provider id, e.g. from a saved or in-progress config
|
|
154
|
+
* @returns the provider's capabilities
|
|
155
|
+
*/
|
|
156
|
+
export declare function getProviderCapabilities(provider: string): ProviderCapabilities;
|
|
157
|
+
/**
|
|
158
|
+
* Whether a provider configuration — complete, or still being filled in on a
|
|
159
|
+
* settings form — has everything its reasoner needs to run: a provider, a
|
|
160
|
+
* model, and (for the providers that require one) an API key or custom
|
|
161
|
+
* endpoint. Takes a loosely-typed draft rather than {@link LLMProviderConfig}
|
|
162
|
+
* itself, since a form in progress won't yet satisfy that union.
|
|
163
|
+
* @param config - the draft configuration to check
|
|
164
|
+
* @returns true once a provider, model and (where required) credentials are set
|
|
165
|
+
*/
|
|
166
|
+
export declare function isLLMConfigured(config: {
|
|
167
|
+
provider?: string;
|
|
168
|
+
model?: string;
|
|
169
|
+
apiKey?: string;
|
|
170
|
+
customEndpoint?: string;
|
|
171
|
+
} | null | undefined): boolean;
|