@accordproject/template-engine 2.0.3 → 2.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/dist/index.d.ts +123 -2
- package/dist/index.js +1437 -21
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1414 -0
- package/dist/index.mjs.map +1 -0
- package/dist/runtime.tgz +0 -0
- package/package.json +7 -3
- package/dist/Common.d.ts +0 -20
- package/dist/Common.js +0 -55
- package/dist/Common.js.map +0 -1
- package/dist/TemplateMarkInterpreter.d.ts +0 -34
- package/dist/TemplateMarkInterpreter.js +0 -401
- package/dist/TemplateMarkInterpreter.js.map +0 -1
- package/dist/TemplateMarkToJavaScriptCompiler.d.ts +0 -19
- package/dist/TemplateMarkToJavaScriptCompiler.js +0 -96
- package/dist/TemplateMarkToJavaScriptCompiler.js.map +0 -1
- package/dist/TemplateMarkToTypeScriptCompiler.d.ts +0 -77
- package/dist/TemplateMarkToTypeScriptCompiler.js +0 -311
- package/dist/TemplateMarkToTypeScriptCompiler.js.map +0 -1
- package/dist/TypeScriptCompilationContext.d.ts +0 -15
- package/dist/TypeScriptCompilationContext.js +0 -57
- package/dist/TypeScriptCompilationContext.js.map +0 -1
- package/dist/TypeScriptRuntime.d.ts +0 -14
- package/dist/TypeScriptRuntime.js +0 -79
- package/dist/TypeScriptRuntime.js.map +0 -1
- package/dist/TypeScriptToJavaScriptCompiler.d.ts +0 -14
- package/dist/TypeScriptToJavaScriptCompiler.js +0 -59
- package/dist/TypeScriptToJavaScriptCompiler.js.map +0 -1
- package/dist/compilers/Clause.d.ts +0 -14
- package/dist/compilers/Clause.js +0 -43
- package/dist/compilers/Clause.js.map +0 -1
- package/dist/compilers/Common.d.ts +0 -66
- package/dist/compilers/Common.js +0 -180
- package/dist/compilers/Common.js.map +0 -1
- package/dist/compilers/Conditional.d.ts +0 -12
- package/dist/compilers/Conditional.js +0 -36
- package/dist/compilers/Conditional.js.map +0 -1
- package/dist/compilers/ContractDefinition.d.ts +0 -8
- package/dist/compilers/ContractDefinition.js +0 -33
- package/dist/compilers/ContractDefinition.js.map +0 -1
- package/dist/compilers/EnumVariable.d.ts +0 -8
- package/dist/compilers/EnumVariable.js +0 -28
- package/dist/compilers/EnumVariable.js.map +0 -1
- package/dist/compilers/FormattedVariable.d.ts +0 -8
- package/dist/compilers/FormattedVariable.js +0 -29
- package/dist/compilers/FormattedVariable.js.map +0 -1
- package/dist/compilers/Formula.d.ts +0 -8
- package/dist/compilers/Formula.js +0 -24
- package/dist/compilers/Formula.js.map +0 -1
- package/dist/compilers/Join.d.ts +0 -8
- package/dist/compilers/Join.js +0 -23
- package/dist/compilers/Join.js.map +0 -1
- package/dist/compilers/ListBlock.d.ts +0 -11
- package/dist/compilers/ListBlock.js +0 -39
- package/dist/compilers/ListBlock.js.map +0 -1
- package/dist/compilers/NodeCompilers.d.ts +0 -7
- package/dist/compilers/NodeCompilers.js +0 -89
- package/dist/compilers/NodeCompilers.js.map +0 -1
- package/dist/compilers/Optional.d.ts +0 -11
- package/dist/compilers/Optional.js +0 -48
- package/dist/compilers/Optional.js.map +0 -1
- package/dist/compilers/Variable.d.ts +0 -8
- package/dist/compilers/Variable.js +0 -28
- package/dist/compilers/Variable.js.map +0 -1
- package/dist/compilers/With.d.ts +0 -10
- package/dist/compilers/With.js +0 -23
- package/dist/compilers/With.js.map +0 -1
- package/dist/drafting/Boolean/index.d.ts +0 -6
- package/dist/drafting/Boolean/index.js +0 -30
- package/dist/drafting/Boolean/index.js.map +0 -1
- package/dist/drafting/DateTime/index.d.ts +0 -7
- package/dist/drafting/DateTime/index.js +0 -33
- package/dist/drafting/DateTime/index.js.map +0 -1
- package/dist/drafting/Double/format.d.ts +0 -13
- package/dist/drafting/Double/format.js +0 -55
- package/dist/drafting/Double/format.js.map +0 -1
- package/dist/drafting/Double/index.d.ts +0 -7
- package/dist/drafting/Double/index.js +0 -33
- package/dist/drafting/Double/index.js.map +0 -1
- package/dist/drafting/Integer/format.d.ts +0 -13
- package/dist/drafting/Integer/format.js +0 -45
- package/dist/drafting/Integer/format.js.map +0 -1
- package/dist/drafting/Integer/index.d.ts +0 -7
- package/dist/drafting/Integer/index.js +0 -33
- package/dist/drafting/Integer/index.js.map +0 -1
- package/dist/drafting/Long/index.d.ts +0 -7
- package/dist/drafting/Long/index.js +0 -33
- package/dist/drafting/Long/index.js.map +0 -1
- package/dist/drafting/MonetaryAmount/currencycode.d.ts +0 -35
- package/dist/drafting/MonetaryAmount/currencycode.js +0 -53
- package/dist/drafting/MonetaryAmount/currencycode.js.map +0 -1
- package/dist/drafting/MonetaryAmount/index.d.ts +0 -12
- package/dist/drafting/MonetaryAmount/index.js +0 -67
- package/dist/drafting/MonetaryAmount/index.js.map +0 -1
- package/dist/drafting/String/index.d.ts +0 -6
- package/dist/drafting/String/index.js +0 -25
- package/dist/drafting/String/index.js.map +0 -1
- package/dist/drafting/index.d.ts +0 -1
- package/dist/drafting/index.js +0 -40
- package/dist/drafting/index.js.map +0 -1
- package/dist/model-gen/concerto.d.ts +0 -13
- package/dist/model-gen/concerto.js +0 -5
- package/dist/model-gen/concerto.js.map +0 -1
- package/dist/model-gen/concerto.metamodel@1.0.0.d.ts +0 -196
- package/dist/model-gen/concerto.metamodel@1.0.0.js +0 -5
- package/dist/model-gen/concerto.metamodel@1.0.0.js.map +0 -1
- package/dist/model-gen/concerto@1.0.0.d.ts +0 -19
- package/dist/model-gen/concerto@1.0.0.js +0 -5
- package/dist/model-gen/concerto@1.0.0.js.map +0 -1
- package/dist/model-gen/org.accordproject.ciceromark@0.6.0.d.ts +0 -49
- package/dist/model-gen/org.accordproject.ciceromark@0.6.0.js +0 -5
- package/dist/model-gen/org.accordproject.ciceromark@0.6.0.js.map +0 -1
- package/dist/model-gen/org.accordproject.commonmark@0.5.0.d.ts +0 -89
- package/dist/model-gen/org.accordproject.commonmark@0.5.0.js +0 -5
- package/dist/model-gen/org.accordproject.commonmark@0.5.0.js.map +0 -1
- package/dist/model-gen/org.accordproject.templatemark@0.5.0.d.ts +0 -76
- package/dist/model-gen/org.accordproject.templatemark@0.5.0.js +0 -12
- package/dist/model-gen/org.accordproject.templatemark@0.5.0.js.map +0 -1
- package/dist/runtime/declarations.d.ts +0 -2
- package/dist/runtime/declarations.js +0 -21
- package/dist/runtime/declarations.js.map +0 -1
- package/dist/runtime/runtime.d.ts +0 -1
- package/dist/runtime/runtime.js +0 -20
- package/dist/runtime/runtime.js.map +0 -1
- package/dist/utils.d.ts +0 -5
- package/dist/utils.js +0 -43
- package/dist/utils.js.map +0 -1
|
@@ -1,311 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
-
};
|
|
28
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
exports.TemplateMarkToTypeScriptCompiler = void 0;
|
|
30
|
-
/*
|
|
31
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
32
|
-
* you may not use this file except in compliance with the License.
|
|
33
|
-
* You may obtain a copy of the License at
|
|
34
|
-
*
|
|
35
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
36
|
-
*
|
|
37
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
38
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
39
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
40
|
-
* See the License for the specific language governing permissions and
|
|
41
|
-
* limitations under the License.
|
|
42
|
-
*/
|
|
43
|
-
const traverse_1 = __importDefault(require("traverse"));
|
|
44
|
-
const fs_1 = require("fs");
|
|
45
|
-
const tar = __importStar(require("tar"));
|
|
46
|
-
const stream_1 = require("stream");
|
|
47
|
-
const markdown_common_1 = require("@accordproject/markdown-common");
|
|
48
|
-
const concerto_core_1 = require("@accordproject/concerto-core");
|
|
49
|
-
const concerto_codegen_1 = require("@accordproject/concerto-codegen");
|
|
50
|
-
const concerto_util_1 = require("@accordproject/concerto-util");
|
|
51
|
-
const NodeCompilers_1 = require("./compilers/NodeCompilers");
|
|
52
|
-
const Common_1 = require("./compilers/Common");
|
|
53
|
-
const Common_2 = require("./Common");
|
|
54
|
-
const runtime_1 = require("./runtime/runtime");
|
|
55
|
-
const utils_1 = require("./utils");
|
|
56
|
-
/**
|
|
57
|
-
* Converts TemplateMark DOM to a Typescript function, that, when run with JSON data
|
|
58
|
-
* that conforms to the template model will produce AgreementMark JSON output.
|
|
59
|
-
*/
|
|
60
|
-
class TemplateMarkToTypeScriptCompiler {
|
|
61
|
-
constructor(modelManager, templateConceptFqn) {
|
|
62
|
-
this.modelManager = modelManager;
|
|
63
|
-
this.templateClass = (0, Common_2.getTemplateClassDeclaration)(this.modelManager, templateConceptFqn);
|
|
64
|
-
}
|
|
65
|
-
writeFunction(fw, functionName, returnType, code) {
|
|
66
|
-
fw.writeLine(0, (0, utils_1.writeFunctionToString)(this.templateClass, functionName, returnType, code));
|
|
67
|
-
}
|
|
68
|
-
/**
|
|
69
|
-
* Get a model manager with templatemark model
|
|
70
|
-
* @param {string} outputDir the output directory
|
|
71
|
-
* @returns {ModelManager} the model manager
|
|
72
|
-
*/
|
|
73
|
-
getTemplateMarkModelManager() {
|
|
74
|
-
const modelManager = new concerto_core_1.ModelManager({ strict: true });
|
|
75
|
-
modelManager.addCTOModel(markdown_common_1.ConcertoMetaModel.MODEL, 'concertometamodel.cto');
|
|
76
|
-
modelManager.addCTOModel(markdown_common_1.CommonMarkModel.MODEL, 'commonmark.cto');
|
|
77
|
-
modelManager.addCTOModel(markdown_common_1.TemplateMarkModel.MODEL, 'templatemark.cto');
|
|
78
|
-
return modelManager;
|
|
79
|
-
}
|
|
80
|
-
/**
|
|
81
|
-
* Get a model manager with templatemark model
|
|
82
|
-
* @param {string} outputDir the output directory
|
|
83
|
-
* @returns {ModelManager} the model manager
|
|
84
|
-
*/
|
|
85
|
-
getCiceroMarkModelManager() {
|
|
86
|
-
const modelManager = new concerto_core_1.ModelManager({ strict: true });
|
|
87
|
-
modelManager.addCTOModel(markdown_common_1.ConcertoMetaModel.MODEL, 'concertometamodel.cto');
|
|
88
|
-
modelManager.addCTOModel(markdown_common_1.CommonMarkModel.MODEL, 'commonmark.cto');
|
|
89
|
-
modelManager.addCTOModel(markdown_common_1.CiceroMarkModel.MODEL, 'ciceromark.cto');
|
|
90
|
-
return modelManager;
|
|
91
|
-
}
|
|
92
|
-
generateTypeScript(modelManager, outputDir) {
|
|
93
|
-
// generate the TS code for the template model
|
|
94
|
-
const tsVisitor = new concerto_codegen_1.CodeGen.TypescriptVisitor();
|
|
95
|
-
const parameters = {
|
|
96
|
-
fileWriter: new concerto_util_1.FileWriter(outputDir)
|
|
97
|
-
};
|
|
98
|
-
modelManager.accept(tsVisitor, parameters);
|
|
99
|
-
}
|
|
100
|
-
generateSampleData(modelManager, outputDir) {
|
|
101
|
-
const factory = new concerto_core_1.Factory(modelManager);
|
|
102
|
-
const instance = factory.newResource(this.templateClass.getNamespace(), this.templateClass.getName(), this.templateClass.isIdentified() ? 'sample' : undefined, { generate: 'sample', includeOptionalFields: true });
|
|
103
|
-
(0, fs_1.writeFileSync)(`${outputDir}/sample.json`, JSON.stringify(instance, null, 2));
|
|
104
|
-
}
|
|
105
|
-
/**
|
|
106
|
-
* The main iteration function over templatemark. This function
|
|
107
|
-
* looks up an INodeCompiler that can handle each templatemark node
|
|
108
|
-
* and delegates to it for code generation.
|
|
109
|
-
* Note that the result of code generation (a CiceroMark node) is left in
|
|
110
|
-
* the $result global varianble.
|
|
111
|
-
* @param {FileWriter} fw the file writer to use
|
|
112
|
-
* @param {number} level the indentation level
|
|
113
|
-
* @param {object} templateMark the templatemark node to iterate over
|
|
114
|
-
*/
|
|
115
|
-
static doIt(fw, level, templateMark) {
|
|
116
|
-
fw.writeLine(level, `// start processing ${concerto_core_1.ModelUtil.getShortName(templateMark.$class)}`);
|
|
117
|
-
(0, traverse_1.default)(templateMark).forEach(function (context) {
|
|
118
|
-
if (typeof context === 'object' && context.$class && typeof context.$class === 'string') {
|
|
119
|
-
const nodeClass = context.$class;
|
|
120
|
-
const compiler = (0, NodeCompilers_1.getCompiler)(nodeClass);
|
|
121
|
-
const sourceLevel = level + 1;
|
|
122
|
-
this.before(() => {
|
|
123
|
-
compiler.enter(fw, sourceLevel, context);
|
|
124
|
-
compiler.generate(fw, sourceLevel, context, TemplateMarkToTypeScriptCompiler.doIt);
|
|
125
|
-
});
|
|
126
|
-
this.after(() => {
|
|
127
|
-
compiler.exit(fw, sourceLevel, context);
|
|
128
|
-
});
|
|
129
|
-
}
|
|
130
|
-
});
|
|
131
|
-
fw.writeLine(level, `// end processing ${concerto_core_1.ModelUtil.getShortName(templateMark.$class)}`);
|
|
132
|
-
}
|
|
133
|
-
/**
|
|
134
|
-
* Converts a TemplateMark document to typescript code that is parameterised
|
|
135
|
-
* by the 'data' argument.
|
|
136
|
-
*
|
|
137
|
-
* The strategy is to traverse the template mark json, converting each node into
|
|
138
|
-
* typescript statements that add an equivalent ciceromark node. Variables will
|
|
139
|
-
* pull values from 'data'.
|
|
140
|
-
*
|
|
141
|
-
* Conditionals and formulae will call the functions produced by
|
|
142
|
-
* compileUserCode.
|
|
143
|
-
*
|
|
144
|
-
* Note that code generation process is itself recursive, for example, when
|
|
145
|
-
* a list definition node is encountered the list must be iterated over
|
|
146
|
-
* based on a variable value coming from data, and code must be
|
|
147
|
-
* generated to produce each list item.
|
|
148
|
-
*
|
|
149
|
-
* All internal variables are prefixed with '$' to ensure (?)
|
|
150
|
-
* that they cannot collide with end user variable names.
|
|
151
|
-
*
|
|
152
|
-
* @param {IDocument} templateMark the TemplateMark Concerto resource
|
|
153
|
-
* @param {string} outputDir the output directory for code
|
|
154
|
-
*/
|
|
155
|
-
compileGenerator(templateMark, outputDir) {
|
|
156
|
-
const fw = new concerto_util_1.FileWriter(outputDir);
|
|
157
|
-
fw.openFile('index.ts');
|
|
158
|
-
fw.writeLine(0, '// generated code');
|
|
159
|
-
fw.writeLine(0, 'import { readFileSync } from \'fs\';');
|
|
160
|
-
fw.writeLine(0, 'import { generator } from \'./generator\';');
|
|
161
|
-
fw.writeLine(0, 'if(process.argv.length === 3) {');
|
|
162
|
-
fw.writeLine(1, 'const result = generator( JSON.parse(readFileSync(process.argv[2], \'utf-8\')), {}, {});');
|
|
163
|
-
fw.writeLine(1, 'console.log(JSON.stringify(result, null, 2));');
|
|
164
|
-
fw.writeLine(0, '}');
|
|
165
|
-
fw.writeLine(0, 'else {');
|
|
166
|
-
fw.writeLine(1, 'console.log(\'First argument is path to JSON data file\');');
|
|
167
|
-
fw.writeLine(0, '}');
|
|
168
|
-
fw.closeFile();
|
|
169
|
-
fw.openFile('generator.ts');
|
|
170
|
-
fw.writeLine(0, '// generated code, do not modify');
|
|
171
|
-
fw.writeLine(0, '');
|
|
172
|
-
fw.writeLine(0, '// IMPORTS');
|
|
173
|
-
(0, Common_1.writeImports)(fw, 0, this.templateClass);
|
|
174
|
-
fw.writeLine(0, '');
|
|
175
|
-
fw.writeLine(0, '// GENERATOR');
|
|
176
|
-
(0, Common_1.writeProlog)(fw, 0, this.templateClass);
|
|
177
|
-
TemplateMarkToTypeScriptCompiler.doIt(fw, 1, templateMark);
|
|
178
|
-
(0, Common_1.writeEpilog)(fw, 0);
|
|
179
|
-
fw.closeFile();
|
|
180
|
-
}
|
|
181
|
-
/**
|
|
182
|
-
* Decompresses the base64 zipped runtime into an output folder.
|
|
183
|
-
* @param {string} outputDir the output directory to copy the runtime to
|
|
184
|
-
*/
|
|
185
|
-
copyRuntime(outputDir) {
|
|
186
|
-
(0, utils_1.ensureDirSync)(`${outputDir}/${Common_1.RUNTIME_DIR}`);
|
|
187
|
-
const runtimeBuffer = Buffer.from(runtime_1.RUNTIME_TGZ_BASE64, 'base64');
|
|
188
|
-
const s = new stream_1.Readable();
|
|
189
|
-
s.push(runtimeBuffer);
|
|
190
|
-
s.push(null);
|
|
191
|
-
s.pipe(tar.x({
|
|
192
|
-
strip: 2,
|
|
193
|
-
C: `${outputDir}/${Common_1.RUNTIME_DIR}`
|
|
194
|
-
}));
|
|
195
|
-
}
|
|
196
|
-
/**
|
|
197
|
-
* Create package.json for the generated code
|
|
198
|
-
* @param {string} outputDir the output directory to copy the runtime to
|
|
199
|
-
*/
|
|
200
|
-
createPackage(outputDir) {
|
|
201
|
-
const packageJson = {
|
|
202
|
-
'name': 'generated',
|
|
203
|
-
'version': '1.0.0',
|
|
204
|
-
'description': 'TypeScript code generated from TemplateMark',
|
|
205
|
-
'engines': {
|
|
206
|
-
'node': '>=14',
|
|
207
|
-
'npm': '>=6'
|
|
208
|
-
},
|
|
209
|
-
'keywords': [
|
|
210
|
-
'accord project',
|
|
211
|
-
'template',
|
|
212
|
-
'templatemark'
|
|
213
|
-
],
|
|
214
|
-
'dependencies': {
|
|
215
|
-
'dayjs': '1.11.7',
|
|
216
|
-
'jsonpath': '^1.1.1',
|
|
217
|
-
},
|
|
218
|
-
'devDependencies': {
|
|
219
|
-
'@types/node': '^20.2.0',
|
|
220
|
-
'ts-node': '^10.9.1',
|
|
221
|
-
'typescript': '^5.0.2',
|
|
222
|
-
'@types/jsonpath': '^0.2.0'
|
|
223
|
-
},
|
|
224
|
-
'scripts': {
|
|
225
|
-
'start': 'ts-node index.ts sample.json'
|
|
226
|
-
}
|
|
227
|
-
};
|
|
228
|
-
(0, fs_1.writeFileSync)(`${outputDir}/package.json`, JSON.stringify(packageJson, null, 2));
|
|
229
|
-
}
|
|
230
|
-
compile(templateMark, outputDir, options) {
|
|
231
|
-
// create output dir
|
|
232
|
-
(0, utils_1.ensureDirSync)(outputDir);
|
|
233
|
-
// generate sample data
|
|
234
|
-
this.generateSampleData(this.modelManager, outputDir);
|
|
235
|
-
// generate the models
|
|
236
|
-
this.generateTypeScript(this.modelManager, outputDir);
|
|
237
|
-
this.generateTypeScript(this.getTemplateMarkModelManager(), outputDir);
|
|
238
|
-
this.generateTypeScript(this.getCiceroMarkModelManager(), outputDir);
|
|
239
|
-
// generate names for all the nodes containing user code
|
|
240
|
-
const namedTemplateMark = (0, utils_1.nameUserCode)(templateMark.toJSON ? templateMark.toJSON() : templateMark);
|
|
241
|
-
// compile the user code
|
|
242
|
-
this.compileUserCode(namedTemplateMark, outputDir);
|
|
243
|
-
// copy the runtime
|
|
244
|
-
if (!options?.skipCopyRuntime) {
|
|
245
|
-
this.copyRuntime(outputDir);
|
|
246
|
-
}
|
|
247
|
-
// compile the generator
|
|
248
|
-
if (!options?.skipGenerator) {
|
|
249
|
-
this.createPackage(outputDir);
|
|
250
|
-
this.compileGenerator(namedTemplateMark, outputDir);
|
|
251
|
-
}
|
|
252
|
-
}
|
|
253
|
-
compileUserCode(templateMark, outputDir) {
|
|
254
|
-
const fw = new concerto_util_1.FileWriter(outputDir);
|
|
255
|
-
fw.openFile('usercode.ts');
|
|
256
|
-
fw.writeLine(0, '// generated code, do not modify');
|
|
257
|
-
fw.writeLine(0, '');
|
|
258
|
-
fw.writeLine(0, '// IMPORTS');
|
|
259
|
-
fw.writeLine(0, `import * as TemplateModel from './${this.templateClass.getNamespace()}';`);
|
|
260
|
-
fw.writeLine(0, 'import dayjs from \'dayjs\';');
|
|
261
|
-
fw.writeLine(0, 'import jp from \'jsonpath\';');
|
|
262
|
-
fw.writeLine(0, 'import {GenerationOptions} from \'./runtime/TypeScriptRuntime\';');
|
|
263
|
-
fw.writeLine(0, '');
|
|
264
|
-
const templateMarkDom = templateMark;
|
|
265
|
-
const functionNodes = (0, traverse_1.default)(templateMarkDom).reduce(function (acc, x) {
|
|
266
|
-
if (x && x.$class === `${markdown_common_1.TemplateMarkModel.NAMESPACE}.FormulaDefinition`) {
|
|
267
|
-
acc.push({
|
|
268
|
-
name: x.name,
|
|
269
|
-
code: x.code,
|
|
270
|
-
});
|
|
271
|
-
}
|
|
272
|
-
return acc;
|
|
273
|
-
}, []);
|
|
274
|
-
const conditionalNodes = (0, traverse_1.default)(templateMarkDom).reduce(function (acc, x) {
|
|
275
|
-
if (x && x.$class === `${markdown_common_1.TemplateMarkModel.NAMESPACE}.ConditionalDefinition` && x.condition) {
|
|
276
|
-
acc.push({
|
|
277
|
-
name: x.functionName,
|
|
278
|
-
code: x.condition,
|
|
279
|
-
});
|
|
280
|
-
}
|
|
281
|
-
return acc;
|
|
282
|
-
}, []);
|
|
283
|
-
const clauseNodes = (0, traverse_1.default)(templateMarkDom).reduce(function (acc, x) {
|
|
284
|
-
if (x && x.$class === `${markdown_common_1.TemplateMarkModel.NAMESPACE}.ClauseDefinition` && x.condition) {
|
|
285
|
-
acc.push({
|
|
286
|
-
name: x.functionName,
|
|
287
|
-
code: x.condition,
|
|
288
|
-
});
|
|
289
|
-
}
|
|
290
|
-
return acc;
|
|
291
|
-
}, []);
|
|
292
|
-
fw.writeLine(0, '// FORMULAE');
|
|
293
|
-
functionNodes.forEach((fun) => {
|
|
294
|
-
this.writeFunction(fw, `${fun.name}`, 'any', fun.code.contents);
|
|
295
|
-
});
|
|
296
|
-
fw.writeLine(0, '');
|
|
297
|
-
fw.writeLine(0, '// CONDITIONALS');
|
|
298
|
-
conditionalNodes.forEach((fun) => {
|
|
299
|
-
this.writeFunction(fw, `${fun.name}`, 'boolean', fun.code.contents);
|
|
300
|
-
});
|
|
301
|
-
fw.writeLine(0, '');
|
|
302
|
-
fw.writeLine(0, '// CLAUSES');
|
|
303
|
-
clauseNodes.forEach((fun) => {
|
|
304
|
-
this.writeFunction(fw, `${fun.name}`, 'boolean', fun.code.contents);
|
|
305
|
-
});
|
|
306
|
-
fw.writeLine(0, '');
|
|
307
|
-
fw.closeFile();
|
|
308
|
-
}
|
|
309
|
-
}
|
|
310
|
-
exports.TemplateMarkToTypeScriptCompiler = TemplateMarkToTypeScriptCompiler;
|
|
311
|
-
//# sourceMappingURL=TemplateMarkToTypeScriptCompiler.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"TemplateMarkToTypeScriptCompiler.js","sourceRoot":"","sources":["../src/TemplateMarkToTypeScriptCompiler.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;;;GAYG;AACH,wDAAgC;AAChC,2BAAmC;AACnC,yCAA2B;AAC3B,mCAAkC;AAElC,oEAAwH;AAExH,gEAAsH;AACtH,sEAA0D;AAC1D,gEAA0D;AAC1D,6DAAwD;AACxD,+CAAyF;AACzF,qCAAuD;AACvD,+CAAuD;AACvD,mCAA6E;AAS7E;;;GAGG;AACH,MAAa,gCAAgC;IAIzC,YAAY,YAA0B,EAAC,kBAA2B;QAC9D,IAAI,CAAC,YAAY,GAAG,YAAY,CAAC;QACjC,IAAI,CAAC,aAAa,GAAG,IAAA,oC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,CAAC,CAAC,GAAQ,EAAE,EAAE;YAC/B,IAAI,CAAC,aAAa,CAAC,EAAE,EAAE,GAAG,GAAG,CAAC,IAAI,EAAE,EAAE,KAAK,EAAE,GAAG,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QACpE,CAAC,CAAC,CAAC;QACH,EAAE,CAAC,SAAS,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;QAEpB,EAAE,CAAC,SAAS,CAAC,CAAC,EAAE,iBAAiB,CAAC,CAAC;QACnC,gBAAgB,CAAC,OAAO,CAAC,CAAC,GAAQ,EAAE,EAAE;YAClC,IAAI,CAAC,aAAa,CAAC,EAAE,EAAE,GAAG,GAAG,CAAC,IAAI,EAAE,EAAE,SAAS,EAAE,GAAG,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QACxE,CAAC,CAAC,CAAC;QACH,EAAE,CAAC,SAAS,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;QAEpB,EAAE,CAAC,SAAS,CAAC,CAAC,EAAE,YAAY,CAAC,CAAC;QAC9B,WAAW,CAAC,OAAO,CAAC,CAAC,GAAQ,EAAE,EAAE;YAC7B,IAAI,CAAC,aAAa,CAAC,EAAE,EAAE,GAAG,GAAG,CAAC,IAAI,EAAE,EAAE,SAAS,EAAE,GAAG,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QACxE,CAAC,CAAC,CAAC;QACH,EAAE,CAAC,SAAS,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;QAEpB,EAAE,CAAC,SAAS,EAAE,CAAC;IACnB,CAAC;CACJ;AArSD,4EAqSC"}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { ClassDeclaration, ModelManager } from '@accordproject/concerto-core';
|
|
2
|
-
/**
|
|
3
|
-
* This class creates the typescript types
|
|
4
|
-
* required to compile Typescript expressions (used in
|
|
5
|
-
* formulae, conditions and clauses) to JavaScript. It uses
|
|
6
|
-
* these to create a compilation context for '@typescript/twoslash'
|
|
7
|
-
* which is used to compile the typescript code.
|
|
8
|
-
*/
|
|
9
|
-
export declare class TypeScriptCompilationContext {
|
|
10
|
-
modelManager: ModelManager;
|
|
11
|
-
templateClass: ClassDeclaration;
|
|
12
|
-
constructor(modelManager: ModelManager, templateConceptFqn?: string);
|
|
13
|
-
getTypeScriptFiles(): Record<string, string>;
|
|
14
|
-
getCompilationContext(): string;
|
|
15
|
-
}
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.TypeScriptCompilationContext = void 0;
|
|
4
|
-
const concerto_codegen_1 = require("@accordproject/concerto-codegen");
|
|
5
|
-
const concerto_util_1 = require("@accordproject/concerto-util");
|
|
6
|
-
const Common_1 = require("./Common");
|
|
7
|
-
/**
|
|
8
|
-
* This class creates the typescript types
|
|
9
|
-
* required to compile Typescript expressions (used in
|
|
10
|
-
* formulae, conditions and clauses) to JavaScript. It uses
|
|
11
|
-
* these to create a compilation context for '@typescript/twoslash'
|
|
12
|
-
* which is used to compile the typescript code.
|
|
13
|
-
*/
|
|
14
|
-
class TypeScriptCompilationContext {
|
|
15
|
-
constructor(modelManager, templateConceptFqn) {
|
|
16
|
-
this.modelManager = modelManager;
|
|
17
|
-
this.templateClass = (0, Common_1.getTemplateClassDeclaration)(this.modelManager, templateConceptFqn);
|
|
18
|
-
}
|
|
19
|
-
getTypeScriptFiles() {
|
|
20
|
-
const result = {};
|
|
21
|
-
const visitor = new concerto_codegen_1.CodeGen.TypescriptVisitor();
|
|
22
|
-
const writer = new concerto_util_1.InMemoryWriter();
|
|
23
|
-
const params = {
|
|
24
|
-
fileWriter: writer
|
|
25
|
-
};
|
|
26
|
-
this.modelManager.accept(visitor, params);
|
|
27
|
-
writer.getFilesInMemory().forEach((value, key) => {
|
|
28
|
-
result[key] = value;
|
|
29
|
-
});
|
|
30
|
-
return result;
|
|
31
|
-
}
|
|
32
|
-
getCompilationContext() {
|
|
33
|
-
const files = this.getTypeScriptFiles();
|
|
34
|
-
let result = '';
|
|
35
|
-
Object.keys(files).forEach(key => {
|
|
36
|
-
const content = files[key];
|
|
37
|
-
result += `
|
|
38
|
-
// @filename: ${key}
|
|
39
|
-
${content}
|
|
40
|
-
`;
|
|
41
|
-
});
|
|
42
|
-
result += `
|
|
43
|
-
// @filename: code.ts
|
|
44
|
-
import * as TemplateModel from './${this.templateClass.getNamespace()}';
|
|
45
|
-
import dayjs from 'dayjs';
|
|
46
|
-
import jp from 'jsonpath';
|
|
47
|
-
|
|
48
|
-
type GenerationOptions = {
|
|
49
|
-
now?:string,
|
|
50
|
-
locale?:string
|
|
51
|
-
}
|
|
52
|
-
`;
|
|
53
|
-
return result;
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
exports.TypeScriptCompilationContext = TypeScriptCompilationContext;
|
|
57
|
-
//# sourceMappingURL=TypeScriptCompilationContext.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"TypeScriptCompilationContext.js","sourceRoot":"","sources":["../src/TypeScriptCompilationContext.ts"],"names":[],"mappings":";;;AAcA,sEAA0D;AAC1D,gEAA8D;AAC9D,qCAAuD;AAEvD;;;;;;GAMG;AACH,MAAa,4BAA4B;IAKrC,YAAY,YAAyB,EAAC,kBAA2B;QAC7D,IAAI,CAAC,YAAY,GAAG,YAAY,CAAC;QACjC,IAAI,CAAC,aAAa,GAAG,IAAA,oCAA2B,EAAC,IAAI,CAAC,YAAY,EAAE,kBAAkB,CAAC,CAAC;IAC5F,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,KAAK,EAAE,GAAG,EAAE,EAAE;YAC9C,MAAM,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;QACxB,CAAC,CAAC,CAAC;QACH,OAAO,MAAM,CAAC;IAClB,CAAC;IAED,qBAAqB;QACjB,MAAM,KAAK,GAAG,IAAI,CAAC,kBAAkB,EAAE,CAAC;QAExC,IAAI,MAAM,GAAG,EAAE,CAAC;QAEhB,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,OAAO,CAAE,GAAG,CAAC,EAAE;YAC9B,MAAM,OAAO,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC;YAC3B,MAAM,IAAI;gBACN,GAAG;EACjB,OAAO;CACR,CAAC;QACM,CAAC,CAAC,CAAC;QAEH,MAAM,IAAI;;oCAEkB,IAAI,CAAC,aAAa,CAAC,YAAY,EAAE;;;;;;;;CAQpE,CAAC;QACM,OAAO,MAAM,CAAC;IAClB,CAAC;CACJ;AApDD,oEAoDC"}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* BEWARE - this type is duplicated in TypeScriptCompilationContext
|
|
3
|
-
* for use by code generation
|
|
4
|
-
*/
|
|
5
|
-
export type GenerationOptions = {
|
|
6
|
-
now?: string;
|
|
7
|
-
locale?: string;
|
|
8
|
-
};
|
|
9
|
-
export declare function joinList(data: Array<string>, joinDef: any, options?: GenerationOptions): string;
|
|
10
|
-
export declare function peek($data: any[]): any;
|
|
11
|
-
export declare function peekProperty($data: any[], propertyName: string, allowUndefined?: boolean): any;
|
|
12
|
-
export declare function push($data: any[], item: any): number;
|
|
13
|
-
export declare function addChild($data: any[], item: any): void;
|
|
14
|
-
export declare function pop($data: any[]): any;
|
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.pop = exports.addChild = exports.push = exports.peekProperty = exports.peek = exports.joinList = void 0;
|
|
4
|
-
/*
|
|
5
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
-
* you may not use this file except in compliance with the License.
|
|
7
|
-
* You may obtain a copy of the License at
|
|
8
|
-
*
|
|
9
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
-
*
|
|
11
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
-
* See the License for the specific language governing permissions and
|
|
15
|
-
* limitations under the License.
|
|
16
|
-
*/
|
|
17
|
-
const DEBUG = false;
|
|
18
|
-
function joinList(data, joinDef, options) {
|
|
19
|
-
if (joinDef.separator) {
|
|
20
|
-
return data.join(joinDef.separator);
|
|
21
|
-
}
|
|
22
|
-
else {
|
|
23
|
-
const formatter = new Intl.ListFormat(joinDef.locale ? joinDef.locale : options?.locale, {
|
|
24
|
-
style: joinDef.style,
|
|
25
|
-
type: joinDef.type
|
|
26
|
-
});
|
|
27
|
-
return formatter.format(data);
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
exports.joinList = joinList;
|
|
31
|
-
/**
|
|
32
|
-
* These utility functions are used by the typescript code that
|
|
33
|
-
* is generated from TemplateMark. They manage a stack to improve
|
|
34
|
-
* debuggability.
|
|
35
|
-
*/
|
|
36
|
-
function dump(op, $data) {
|
|
37
|
-
if (DEBUG) {
|
|
38
|
-
console.log(`${op}: ${JSON.stringify($data)}`);
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
function peek($data) {
|
|
42
|
-
if ($data.length <= 0) {
|
|
43
|
-
throw new Error('Empty array');
|
|
44
|
-
}
|
|
45
|
-
const result = $data[$data.length - 1];
|
|
46
|
-
dump('peek', $data);
|
|
47
|
-
return result;
|
|
48
|
-
}
|
|
49
|
-
exports.peek = peek;
|
|
50
|
-
function peekProperty($data, propertyName, allowUndefined = false) {
|
|
51
|
-
const head = peek($data);
|
|
52
|
-
const result = head[propertyName];
|
|
53
|
-
if (!allowUndefined && result === undefined) {
|
|
54
|
-
throw new Error(`Undefined property ${propertyName}. Current stack is ${JSON.stringify($data)}`);
|
|
55
|
-
}
|
|
56
|
-
return result;
|
|
57
|
-
}
|
|
58
|
-
exports.peekProperty = peekProperty;
|
|
59
|
-
function push($data, item) {
|
|
60
|
-
const result = $data.push(item);
|
|
61
|
-
dump('push', $data);
|
|
62
|
-
return result;
|
|
63
|
-
}
|
|
64
|
-
exports.push = push;
|
|
65
|
-
function addChild($data, item) {
|
|
66
|
-
const node = peek($data);
|
|
67
|
-
node.nodes ? node.nodes.push(item) : node.nodes = [item];
|
|
68
|
-
}
|
|
69
|
-
exports.addChild = addChild;
|
|
70
|
-
function pop($data) {
|
|
71
|
-
if ($data.length <= 0) {
|
|
72
|
-
throw new Error('Empty array');
|
|
73
|
-
}
|
|
74
|
-
const result = $data.pop();
|
|
75
|
-
dump('pop', $data);
|
|
76
|
-
return result;
|
|
77
|
-
}
|
|
78
|
-
exports.pop = pop;
|
|
79
|
-
//# sourceMappingURL=TypeScriptRuntime.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"TypeScriptRuntime.js","sourceRoot":"","sources":["../src/TypeScriptRuntime.ts"],"names":[],"mappings":";;;AAAA;;;;;;;;;;;;GAYG;AACH,MAAM,KAAK,GAAG,KAAK,CAAC;AAcpB,SAAgB,QAAQ,CAAC,IAAkB,EAAE,OAAW,EAAE,OAA0B;IAChF,IAAG,OAAO,CAAC,SAAS,EAAE;QAClB,OAAO,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;KACvC;SACI;QACD,MAAM,SAAS,GAAG,IAAI,IAAI,CAAC,UAAU,CAAE,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,C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MAAM,EAAE,KAAK,CAAC,CAAC;IACpB,OAAO,MAAM,CAAC;AAClB,CAAC;AAJD,oBAIC;AAED,SAAgB,QAAQ,CAAC,KAAW,EAAE,IAAQ;IAC1C,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC;IACzB,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,GAAG,CAAC,IAAI,CAAC,CAAC;AAC7D,CAAC;AAHD,4BAGC;AAED,SAAgB,GAAG,CAAC,KAAW;IAC3B,IAAG,KAAK,CAAC,MAAM,IAAI,CAAC,EAAE;QAClB,MAAM,IAAI,KAAK,CAAC,aAAa,CAAC,CAAC;KAClC;IACD,MAAM,MAAM,GAAG,KAAK,CAAC,GAAG,EAAE,CAAC;IAC3B,IAAI,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;IACnB,OAAO,MAAM,CAAC;AAClB,CAAC;AAPD,kBAOC"}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { TwoSlashReturn } from '@typescript/twoslash';
|
|
2
|
-
import { ModelManager } from '@accordproject/concerto-core';
|
|
3
|
-
/**
|
|
4
|
-
* Compiles user Typescript code to JavaScript, This uses the '@typescript/twoslash'
|
|
5
|
-
* project which is maintained by the Typescript team and powers their web playground.
|
|
6
|
-
* It uses the TypeScriptCompilationContext class to construct a payload for twoslash
|
|
7
|
-
* that is composed of multiple TS files to compile, along with their 3rd-party module
|
|
8
|
-
* dependencies.
|
|
9
|
-
*/
|
|
10
|
-
export declare class TypeScriptToJavaScriptCompiler {
|
|
11
|
-
context: string;
|
|
12
|
-
constructor(modelManager: ModelManager, templateConceptFqn?: string);
|
|
13
|
-
compile(typescript: string): TwoSlashReturn;
|
|
14
|
-
}
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.TypeScriptToJavaScriptCompiler = void 0;
|
|
7
|
-
/*
|
|
8
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
9
|
-
* you may not use this file except in compliance with the License.
|
|
10
|
-
* You may obtain a copy of the License at
|
|
11
|
-
*
|
|
12
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
13
|
-
*
|
|
14
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
15
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
16
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
17
|
-
* See the License for the specific language governing permissions and
|
|
18
|
-
* limitations under the License.
|
|
19
|
-
*/
|
|
20
|
-
const typescript_1 = __importDefault(require("typescript"));
|
|
21
|
-
const vfs_1 = require("@typescript/vfs");
|
|
22
|
-
const twoslash_1 = require("@typescript/twoslash");
|
|
23
|
-
const TypeScriptCompilationContext_1 = require("./TypeScriptCompilationContext");
|
|
24
|
-
const declarations_1 = require("./runtime/declarations");
|
|
25
|
-
/**
|
|
26
|
-
* Compiles user Typescript code to JavaScript, This uses the '@typescript/twoslash'
|
|
27
|
-
* project which is maintained by the Typescript team and powers their web playground.
|
|
28
|
-
* It uses the TypeScriptCompilationContext class to construct a payload for twoslash
|
|
29
|
-
* that is composed of multiple TS files to compile, along with their 3rd-party module
|
|
30
|
-
* dependencies.
|
|
31
|
-
*/
|
|
32
|
-
class TypeScriptToJavaScriptCompiler {
|
|
33
|
-
constructor(modelManager, templateConceptFqn) {
|
|
34
|
-
this.context = new TypeScriptCompilationContext_1.TypeScriptCompilationContext(modelManager, templateConceptFqn).getCompilationContext();
|
|
35
|
-
}
|
|
36
|
-
compile(typescript) {
|
|
37
|
-
const fsMap = (0, vfs_1.createDefaultMapFromNodeModules)({
|
|
38
|
-
target: typescript_1.default.ScriptTarget.ES2020,
|
|
39
|
-
});
|
|
40
|
-
fsMap.set('/node_modules/@types/dayjs/index.d.ts', Buffer.from(declarations_1.DAYJS_BASE64, 'base64').toString());
|
|
41
|
-
fsMap.set('/node_modules/@types/jsonpath/index.d.ts', Buffer.from(declarations_1.JSONPATH_BASE64, 'base64').toString());
|
|
42
|
-
const twoSlashCode = `
|
|
43
|
-
${this.context}
|
|
44
|
-
${typescript}
|
|
45
|
-
`;
|
|
46
|
-
const options = {
|
|
47
|
-
fsMap,
|
|
48
|
-
defaultOptions: {
|
|
49
|
-
showEmit: true,
|
|
50
|
-
noErrorValidation: true,
|
|
51
|
-
showEmittedFile: 'code.js'
|
|
52
|
-
}
|
|
53
|
-
};
|
|
54
|
-
const result = (0, twoslash_1.twoslasher)(twoSlashCode, 'ts', options);
|
|
55
|
-
return result;
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
exports.TypeScriptToJavaScriptCompiler = TypeScriptToJavaScriptCompiler;
|
|
59
|
-
//# sourceMappingURL=TypeScriptToJavaScriptCompiler.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"TypeScriptToJavaScriptCompiler.js","sourceRoot":"","sources":["../src/TypeScriptToJavaScriptCompiler.ts"],"names":[],"mappings":";;;;;;AAAA;;;;;;;;;;;;GAYG;AACH,4DAA4B;AAC5B,yCAAkE;AAClE,mDAAmF;AAEnF,iFAA8E;AAC9E,yDAAuE;AAEvE;;;;;;GAMG;AACH,MAAa,8BAA8B;IAGvC,YAAY,YAA0B,EAAE,kBAA2B;QAC/D,IAAI,CAAC,OAAO,GAAG,IAAI,2DAA4B,CAAC,YAAY,EAAE,kBAAkB,CAAC,CAAC,qBAAqB,EAAE,CAAC;IAC9G,CAAC;IAED,OAAO,CAAC,UAAkB;QACtB,MAAM,KAAK,GAAG,IAAA,qCAA+B,EAAC;YAC1C,MAAM,EAAE,oBAAE,CAAC,YAAY,CAAC,MAAM;SACjC,CAAC,CAAC;QAEH,KAAK,CAAC,GAAG,CAAC,uCAAuC,EAAE,MAAM,CAAC,IAAI,CAAC,2BAAY,EAAE,QAAQ,CAAC,CAAC,QAAQ,EAAE,CAAC,CAAC;QACnG,KAAK,CAAC,GAAG,CAAC,0CAA0C,EAAE,MAAM,CAAC,IAAI,CAAC,8BAAe,EAAE,QAAQ,CAAC,CAAC,QAAQ,EAAE,CAAC,CAAC;QAEzG,MAAM,YAAY,GAAE;EAC1B,IAAI,CAAC,OAAO;EACZ,UAAU;CACX,CAAC;QAEM,MAAM,OAAO,GAAoB;YAC7B,KAAK;YACL,cAAc,EAAE;gBACZ,QAAQ,EAAE,IAAI;gBACd,iBAAiB,EAAE,IAAI;gBACvB,eAAe,EAAE,SAAS;aAC7B;SACJ,CAAC;QACF,MAAM,MAAM,GAAG,IAAA,qBAAU,EAAC,YAAY,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC;QACvD,OAAO,MAAM,CAAC;IAClB,CAAC;CACJ;AA/BD,wEA+BC"}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { FileWriter } from '@accordproject/concerto-util';
|
|
2
|
-
import { IClauseDefinition, IWithDefinition } from '../model-gen/org.accordproject.templatemark@0.5.0';
|
|
3
|
-
import { AbstractComplexCompiler } from './Common';
|
|
4
|
-
interface INamedClauseDefinition extends IClauseDefinition {
|
|
5
|
-
readonly functionName: string;
|
|
6
|
-
}
|
|
7
|
-
export declare class Clause extends AbstractComplexCompiler {
|
|
8
|
-
static TYPE: string;
|
|
9
|
-
constructor();
|
|
10
|
-
enter(fw: FileWriter, level: number, templateMarkNode: IWithDefinition): void;
|
|
11
|
-
generate(fw: FileWriter, level: number, templateMarkNode: INamedClauseDefinition): void;
|
|
12
|
-
exit(fw: FileWriter, level: number): void;
|
|
13
|
-
}
|
|
14
|
-
export {};
|
package/dist/compilers/Clause.js
DELETED
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Clause = void 0;
|
|
4
|
-
const markdown_common_1 = require("@accordproject/markdown-common");
|
|
5
|
-
const Common_1 = require("./Common");
|
|
6
|
-
class Clause extends Common_1.AbstractComplexCompiler {
|
|
7
|
-
constructor() {
|
|
8
|
-
super(false);
|
|
9
|
-
}
|
|
10
|
-
enter(fw, level, templateMarkNode) {
|
|
11
|
-
(0, Common_1.writeDebug)(fw, level, templateMarkNode);
|
|
12
|
-
(0, Common_1.writeOpenNodeScope)(fw, level);
|
|
13
|
-
(0, Common_1.writeOpenDataScope)(fw, level, templateMarkNode.name);
|
|
14
|
-
}
|
|
15
|
-
generate(fw, level, templateMarkNode) {
|
|
16
|
-
const clone = (0, Common_1.makeCiceroMark)(templateMarkNode);
|
|
17
|
-
delete clone.condition;
|
|
18
|
-
delete clone.functionName;
|
|
19
|
-
const para = { $class: `${markdown_common_1.CommonMarkModel.NAMESPACE}.Paragraph` };
|
|
20
|
-
(0, Common_1.writeOpenGenerateScope)(fw, level);
|
|
21
|
-
if (templateMarkNode.condition) {
|
|
22
|
-
fw.writeLine(level, `const isTrue:boolean = UserCode.${templateMarkNode.functionName}(data,library,options)`);
|
|
23
|
-
}
|
|
24
|
-
else {
|
|
25
|
-
fw.writeLine(level, 'const isTrue:boolean = true;');
|
|
26
|
-
}
|
|
27
|
-
fw.writeLine(level, 'if(isTrue) {');
|
|
28
|
-
fw.writeLine(level, `return ${JSON.stringify(clone)} as ${(0, Common_1.getTypeScriptType)(clone.$class)};`);
|
|
29
|
-
fw.writeLine(level, '}');
|
|
30
|
-
fw.writeLine(level, 'else {');
|
|
31
|
-
fw.writeLine(level, `return ${JSON.stringify(para)} as ${(0, Common_1.getTypeScriptType)(para.$class)};`);
|
|
32
|
-
fw.writeLine(level, '}');
|
|
33
|
-
(0, Common_1.writeCloseGenerateScope)(fw, level);
|
|
34
|
-
delete templateMarkNode.condition;
|
|
35
|
-
}
|
|
36
|
-
exit(fw, level) {
|
|
37
|
-
(0, Common_1.writeCloseDataScope)(fw, level);
|
|
38
|
-
(0, Common_1.writeCloseNodeScope)(fw, level);
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
exports.Clause = Clause;
|
|
42
|
-
Clause.TYPE = `${markdown_common_1.TemplateMarkModel.NAMESPACE}.ClauseDefinition`;
|
|
43
|
-
//# sourceMappingURL=Clause.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Clause.js","sourceRoot":"","sources":["../../src/compilers/Clause.ts"],"names":[],"mappings":";;;AAcA,oEAAmF;AAInF,qCAAqO;AAMrO,MAAa,MAAO,SAAQ,gCAAuB;IAE/C;QACI,KAAK,CAAC,KAAK,CAAC,CAAC;IACjB,CAAC;IAED,KAAK,CAAC,EAAa,EAAE,KAAY,EAAC,gBAAgC;QAC9D,IAAA,mBAAU,EAAC,EAAE,EAAE,KAAK,EAAE,gBAAgB,CAAC,CAAC;QACxC,IAAA,2BAAkB,EAAC,EAAE,EAAC,KAAK,CAAC,CAAC;QAC7B,IAAA,2BAAkB,EAAC,EAAE,EAAC,KAAK,EAAC,gBAAgB,CAAC,IAAI,CAAC,CAAC;IACvD,CAAC;IAED,QAAQ,CAAC,EAAa,EAAE,KAAY,EAAE,gBAAuC;QACzE,MAAM,KAAK,GAAG,IAAA,uBAAc,EAAC,gBAAgB,CAAY,CAAC;QAC1D,OAAQ,KAAa,CAAC,SAAS,CAAC;QAChC,OAAQ,KAAa,CAAC,YAAY,CAAC;QACnC,MAAM,IAAI,GAAG,EAAC,MAAM,EAAE,GAAG,iCAAe,CAAC,SAAS,YAAY,EAAe,CAAC;QAC9E,IAAA,+BAAsB,EAAC,EAAE,EAAE,KAAK,CAAC,CAAC;QAClC,IAAG,gBAAgB,CAAC,SAAS,EAAE;YAC3B,EAAE,CAAC,SAAS,CAAC,KAAK,EAAE,mCAAmC,gBAAgB,CAAC,YAAY,wBAAwB,CAAC,CAAC;SACjH;aACI;YACD,EAAE,CAAC,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