@accordproject/template-engine 1.0.19 → 2.0.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/Common.js +9 -9
- package/dist/Common.js.map +1 -1
- package/dist/TemplateMarkInterpreter.d.ts +2 -2
- package/dist/TemplateMarkInterpreter.js +121 -158
- package/dist/TemplateMarkInterpreter.js.map +1 -1
- package/dist/TemplateMarkToJavaScriptCompiler.js +31 -24
- package/dist/TemplateMarkToJavaScriptCompiler.js.map +1 -1
- package/dist/TemplateMarkToTypeScriptCompiler.js +94 -94
- package/dist/TemplateMarkToTypeScriptCompiler.js.map +1 -1
- package/dist/TypeScriptCompilationContext.js +34 -22
- package/dist/TypeScriptCompilationContext.js.map +1 -1
- package/dist/TypeScriptRuntime.d.ts +9 -0
- package/dist/TypeScriptRuntime.js +24 -12
- package/dist/TypeScriptRuntime.js.map +1 -1
- package/dist/TypeScriptToJavaScriptCompiler.js +18 -16
- package/dist/TypeScriptToJavaScriptCompiler.js.map +1 -1
- package/dist/compilers/Clause.d.ts +1 -1
- package/dist/compilers/Clause.js +18 -35
- package/dist/compilers/Clause.js.map +1 -1
- package/dist/compilers/Common.js +55 -81
- package/dist/compilers/Common.js.map +1 -1
- package/dist/compilers/Conditional.d.ts +1 -1
- package/dist/compilers/Conditional.js +12 -29
- package/dist/compilers/Conditional.js.map +1 -1
- package/dist/compilers/ContractDefinition.d.ts +1 -1
- package/dist/compilers/ContractDefinition.js +10 -27
- package/dist/compilers/ContractDefinition.js.map +1 -1
- package/dist/compilers/EnumVariable.d.ts +1 -1
- package/dist/compilers/EnumVariable.js +12 -29
- package/dist/compilers/EnumVariable.js.map +1 -1
- package/dist/compilers/FormattedVariable.d.ts +1 -1
- package/dist/compilers/FormattedVariable.js +14 -31
- package/dist/compilers/FormattedVariable.js.map +1 -1
- package/dist/compilers/Formula.d.ts +1 -1
- package/dist/compilers/Formula.js +14 -31
- package/dist/compilers/Formula.js.map +1 -1
- package/dist/compilers/Join.d.ts +1 -1
- package/dist/compilers/Join.js +12 -28
- package/dist/compilers/Join.js.map +1 -1
- package/dist/compilers/ListBlock.d.ts +1 -1
- package/dist/compilers/ListBlock.js +17 -35
- package/dist/compilers/ListBlock.js.map +1 -1
- package/dist/compilers/NodeCompilers.js +44 -44
- package/dist/compilers/NodeCompilers.js.map +1 -1
- package/dist/compilers/Optional.d.ts +1 -1
- package/dist/compilers/Optional.js +17 -34
- package/dist/compilers/Optional.js.map +1 -1
- package/dist/compilers/Variable.d.ts +1 -1
- package/dist/compilers/Variable.js +12 -29
- package/dist/compilers/Variable.js.map +1 -1
- package/dist/compilers/With.d.ts +1 -1
- package/dist/compilers/With.js +13 -30
- package/dist/compilers/With.js.map +1 -1
- package/dist/drafting/DateTime/index.js +3 -3
- package/dist/drafting/DateTime/index.js.map +1 -1
- package/dist/drafting/Double/format.js +5 -5
- package/dist/drafting/Double/format.js.map +1 -1
- package/dist/drafting/Double/index.js +2 -2
- package/dist/drafting/Double/index.js.map +1 -1
- package/dist/drafting/Integer/format.js +3 -3
- package/dist/drafting/Integer/format.js.map +1 -1
- package/dist/drafting/Integer/index.js +2 -2
- package/dist/drafting/Integer/index.js.map +1 -1
- package/dist/drafting/Long/index.js +2 -2
- package/dist/drafting/Long/index.js.map +1 -1
- package/dist/drafting/MonetaryAmount/index.js +4 -4
- package/dist/drafting/MonetaryAmount/index.js.map +1 -1
- package/dist/drafting/index.js +7 -7
- package/dist/drafting/index.js.map +1 -1
- package/dist/model-gen/concerto.d.ts +13 -0
- package/dist/model-gen/concerto.js +5 -0
- package/dist/model-gen/concerto.js.map +1 -0
- package/dist/model-gen/concerto.metamodel@1.0.0.d.ts +24 -1
- package/dist/model-gen/concerto@1.0.0.d.ts +3 -2
- package/dist/model-gen/org.accordproject.commonmark@0.5.0.d.ts +2 -2
- package/dist/model-gen/{org.accordproject.templatemark@0.4.0.d.ts → org.accordproject.templatemark@0.5.0.d.ts} +5 -1
- package/dist/model-gen/{org.accordproject.templatemark@0.4.0.js → org.accordproject.templatemark@0.5.0.js} +3 -2
- package/dist/model-gen/org.accordproject.templatemark@0.5.0.js.map +1 -0
- package/dist/runtime/runtime.d.ts +1 -1
- package/dist/runtime/runtime.js +1 -1
- package/dist/runtime/runtime.js.map +1 -1
- package/dist/runtime.tgz +0 -0
- package/package.json +9 -9
- package/dist/model-gen/org.accordproject.templatemark@0.4.0.js.map +0 -1
|
@@ -17,39 +17,46 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
17
17
|
};
|
|
18
18
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
19
|
exports.TemplateMarkToJavaScriptCompiler = void 0;
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
20
|
+
const traverse_1 = __importDefault(require("traverse"));
|
|
21
|
+
const markdown_common_1 = require("@accordproject/markdown-common");
|
|
22
|
+
const TypeScriptToJavaScriptCompiler_1 = require("./TypeScriptToJavaScriptCompiler");
|
|
23
|
+
const Common_1 = require("./Common");
|
|
24
|
+
const TemplateMarkToTypeScriptCompiler_1 = require("./TemplateMarkToTypeScriptCompiler");
|
|
25
|
+
const org_accordproject_templatemark_0_5_0_1 = require("./model-gen/org.accordproject.templatemark@0.5.0");
|
|
26
|
+
const CODE_NODES = [
|
|
27
|
+
`${markdown_common_1.TemplateMarkModel.NAMESPACE}.FormulaDefinition`,
|
|
28
|
+
`${markdown_common_1.TemplateMarkModel.NAMESPACE}.ConditionalDefinition`,
|
|
29
|
+
`${markdown_common_1.TemplateMarkModel.NAMESPACE}.ClauseDefinition`,
|
|
29
30
|
];
|
|
31
|
+
function checkCode(code) {
|
|
32
|
+
if (code.type !== org_accordproject_templatemark_0_5_0_1.CodeType.TYPESCRIPT) {
|
|
33
|
+
throw new Error(`Cannot compile ${code.contents} as it is not Typescript.`);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
30
36
|
/**
|
|
31
37
|
* Compiles all the Typescript nodes in a TemplateMark JSON
|
|
32
38
|
* to ES_2020 and returns a modified TemplateMark JSON.
|
|
33
39
|
*/
|
|
34
|
-
|
|
35
|
-
|
|
40
|
+
class TemplateMarkToJavaScriptCompiler {
|
|
41
|
+
constructor(modelManager, templateConceptFqn) {
|
|
36
42
|
this.modelManager = modelManager;
|
|
37
43
|
this.compiler = new TypeScriptToJavaScriptCompiler_1.TypeScriptToJavaScriptCompiler(modelManager, templateConceptFqn);
|
|
38
44
|
this.templateClass = (0, Common_1.getTemplateClassDeclaration)(modelManager, templateConceptFqn);
|
|
39
45
|
}
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
46
|
+
compile(templateJson) {
|
|
47
|
+
const namedTemplateMark = TemplateMarkToTypeScriptCompiler_1.TemplateMarkToTypeScriptCompiler.nameUserCode(templateJson);
|
|
48
|
+
const functionCompiler = new TemplateMarkToTypeScriptCompiler_1.TemplateMarkToTypeScriptCompiler(this.modelManager, this.templateClass.getFullyQualifiedName());
|
|
43
49
|
// eslint-disable-next-line @typescript-eslint/no-this-alias
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
50
|
+
const that = this;
|
|
51
|
+
const errors = Array();
|
|
52
|
+
const compiled = (0, traverse_1.default)(namedTemplateMark).map(function (x) {
|
|
47
53
|
if (x && CODE_NODES.includes(x.$class)) {
|
|
48
54
|
if (x.code) { // formula
|
|
49
|
-
|
|
55
|
+
checkCode(x.code);
|
|
56
|
+
const result = that.compiler.compile(functionCompiler.writeFunctionToString(x.name, 'any', x.code.contents));
|
|
50
57
|
if (result.errors.length === 0) {
|
|
51
58
|
x.code.contents = result.code;
|
|
52
|
-
x.code.type =
|
|
59
|
+
x.code.type = org_accordproject_templatemark_0_5_0_1.CodeType.ES_2020;
|
|
53
60
|
this.update(x);
|
|
54
61
|
}
|
|
55
62
|
else {
|
|
@@ -61,10 +68,11 @@ var TemplateMarkToJavaScriptCompiler = /** @class */ (function () {
|
|
|
61
68
|
}
|
|
62
69
|
}
|
|
63
70
|
else if (x.condition) { // condition or clause (boolean condition)
|
|
64
|
-
|
|
71
|
+
checkCode(x.condition);
|
|
72
|
+
const result = that.compiler.compile(functionCompiler.writeFunctionToString(x.functionName, 'boolean', x.condition.contents));
|
|
65
73
|
if (result.errors.length === 0) {
|
|
66
74
|
x.condition.contents = result.code;
|
|
67
|
-
x.condition.type =
|
|
75
|
+
x.condition.type = org_accordproject_templatemark_0_5_0_1.CodeType.ES_2020;
|
|
68
76
|
this.update(x);
|
|
69
77
|
}
|
|
70
78
|
else {
|
|
@@ -83,8 +91,7 @@ var TemplateMarkToJavaScriptCompiler = /** @class */ (function () {
|
|
|
83
91
|
else {
|
|
84
92
|
throw errors;
|
|
85
93
|
}
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
}());
|
|
94
|
+
}
|
|
95
|
+
}
|
|
89
96
|
exports.TemplateMarkToJavaScriptCompiler = TemplateMarkToJavaScriptCompiler;
|
|
90
97
|
//# sourceMappingURL=TemplateMarkToJavaScriptCompiler.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TemplateMarkToJavaScriptCompiler.js","sourceRoot":"","sources":["../src/TemplateMarkToJavaScriptCompiler.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;GAYG;;;;;;AAEH,
|
|
1
|
+
{"version":3,"file":"TemplateMarkToJavaScriptCompiler.js","sourceRoot":"","sources":["../src/TemplateMarkToJavaScriptCompiler.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;GAYG;;;;;;AAEH,wDAAgC;AAChC,oEAAmE;AAEnE,qFAAkF;AAElF,qCAAuD;AACvD,yFAAsF;AACtF,2GAAmF;AAEnF,MAAM,UAAU,GAAG;IACf,GAAG,mCAAiB,CAAC,SAAS,oBAAoB;IAClD,GAAG,mCAAiB,CAAC,SAAS,wBAAwB;IACtD,GAAG,mCAAiB,CAAC,SAAS,mBAAmB;CACpD,CAAC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AM,CAAC,MAAM,KAAK,CAAC,EAAE;YACpB,OAAO,QAAQ,CAAC;SACnB;aACI;YACD,MAAM,MAAM,CAAC;SAChB;IACL,CAAC;CACJ;AA9DD,4EA8DC"}
|
|
@@ -40,79 +40,81 @@ exports.TemplateMarkToTypeScriptCompiler = void 0;
|
|
|
40
40
|
* See the License for the specific language governing permissions and
|
|
41
41
|
* limitations under the License.
|
|
42
42
|
*/
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
43
|
+
const traverse_1 = __importDefault(require("traverse"));
|
|
44
|
+
const fs_extra_1 = require("fs-extra");
|
|
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
55
|
/**
|
|
56
56
|
* Converts TemplateMark DOM to a Typescript function, that, when run with JSON data
|
|
57
57
|
* that conforms to the template model will produce AgreementMark JSON output.
|
|
58
58
|
*/
|
|
59
|
-
|
|
60
|
-
|
|
59
|
+
class TemplateMarkToTypeScriptCompiler {
|
|
60
|
+
constructor(modelManager, templateConceptFqn) {
|
|
61
61
|
this.modelManager = modelManager;
|
|
62
62
|
this.templateClass = (0, Common_2.getTemplateClassDeclaration)(this.modelManager, templateConceptFqn);
|
|
63
63
|
}
|
|
64
|
-
|
|
65
|
-
|
|
64
|
+
writeFunctionToString(functionName, returnType, code) {
|
|
65
|
+
let result = '';
|
|
66
66
|
result += '/// ---cut---\n';
|
|
67
|
-
result +=
|
|
68
|
-
|
|
69
|
-
|
|
67
|
+
result += `export function ${functionName}(data:TemplateModel.I${this.templateClass.getName()}, library:any, options:GenerationOptions) : ${returnType} {\n`;
|
|
68
|
+
result += ' const now = dayjs(options?.now);\n';
|
|
69
|
+
result += ' const locale = options?.locale;\n';
|
|
70
|
+
this.templateClass.getProperties().forEach((p) => {
|
|
71
|
+
result += ` const ${p.getName()} = data.${p.getName()};\n`;
|
|
70
72
|
});
|
|
71
73
|
result += ' ' + code.trim() + '\n';
|
|
72
74
|
result += '}\n';
|
|
73
75
|
result += '\n';
|
|
74
76
|
return result;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
+
}
|
|
78
|
+
writeFunction(fw, functionName, returnType, code) {
|
|
77
79
|
fw.writeLine(0, this.writeFunctionToString(functionName, returnType, code));
|
|
78
|
-
}
|
|
80
|
+
}
|
|
79
81
|
/**
|
|
80
82
|
* Get a model manager with templatemark model
|
|
81
83
|
* @param {string} outputDir the output directory
|
|
82
84
|
* @returns {ModelManager} the model manager
|
|
83
85
|
*/
|
|
84
|
-
|
|
85
|
-
|
|
86
|
+
getTemplateMarkModelManager() {
|
|
87
|
+
const modelManager = new concerto_core_1.ModelManager({ strict: true });
|
|
86
88
|
modelManager.addCTOModel(markdown_common_1.ConcertoMetaModel.MODEL, 'concertometamodel.cto');
|
|
87
89
|
modelManager.addCTOModel(markdown_common_1.CommonMarkModel.MODEL, 'commonmark.cto');
|
|
88
90
|
modelManager.addCTOModel(markdown_common_1.TemplateMarkModel.MODEL, 'templatemark.cto');
|
|
89
91
|
return modelManager;
|
|
90
|
-
}
|
|
92
|
+
}
|
|
91
93
|
/**
|
|
92
94
|
* Get a model manager with templatemark model
|
|
93
95
|
* @param {string} outputDir the output directory
|
|
94
96
|
* @returns {ModelManager} the model manager
|
|
95
97
|
*/
|
|
96
|
-
|
|
97
|
-
|
|
98
|
+
getCiceroMarkModelManager() {
|
|
99
|
+
const modelManager = new concerto_core_1.ModelManager({ strict: true });
|
|
98
100
|
modelManager.addCTOModel(markdown_common_1.ConcertoMetaModel.MODEL, 'concertometamodel.cto');
|
|
99
101
|
modelManager.addCTOModel(markdown_common_1.CommonMarkModel.MODEL, 'commonmark.cto');
|
|
100
102
|
modelManager.addCTOModel(markdown_common_1.CiceroMarkModel.MODEL, 'ciceromark.cto');
|
|
101
103
|
return modelManager;
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
+
}
|
|
105
|
+
generateTypeScript(modelManager, outputDir) {
|
|
104
106
|
// generate the TS code for the template model
|
|
105
|
-
|
|
106
|
-
|
|
107
|
+
const tsVisitor = new concerto_codegen_1.CodeGen.TypescriptVisitor();
|
|
108
|
+
const parameters = {
|
|
107
109
|
fileWriter: new concerto_util_1.FileWriter(outputDir)
|
|
108
110
|
};
|
|
109
111
|
modelManager.accept(tsVisitor, parameters);
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
(0, fs_extra_1.writeFileSync)(
|
|
115
|
-
}
|
|
112
|
+
}
|
|
113
|
+
generateSampleData(modelManager, outputDir) {
|
|
114
|
+
const factory = new concerto_core_1.Factory(modelManager);
|
|
115
|
+
const instance = factory.newResource(this.templateClass.getNamespace(), this.templateClass.getName(), this.templateClass.isIdentified() ? 'sample' : undefined, { generate: 'sample', includeOptionalFields: true });
|
|
116
|
+
(0, fs_extra_1.writeFileSync)(`${outputDir}/sample.json`, JSON.stringify(instance, null, 2));
|
|
117
|
+
}
|
|
116
118
|
/**
|
|
117
119
|
* The main iteration function over templatemark. This function
|
|
118
120
|
* looks up an INodeCompiler that can handle each templatemark node
|
|
@@ -123,24 +125,24 @@ var TemplateMarkToTypeScriptCompiler = /** @class */ (function () {
|
|
|
123
125
|
* @param {number} level the indentation level
|
|
124
126
|
* @param {object} templateMark the templatemark node to iterate over
|
|
125
127
|
*/
|
|
126
|
-
|
|
127
|
-
fw.writeLine(level,
|
|
128
|
+
static doIt(fw, level, templateMark) {
|
|
129
|
+
fw.writeLine(level, `// start processing ${concerto_core_1.ModelUtil.getShortName(templateMark.$class)}`);
|
|
128
130
|
(0, traverse_1.default)(templateMark).forEach(function (context) {
|
|
129
131
|
if (typeof context === 'object' && context.$class && typeof context.$class === 'string') {
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
this.before(
|
|
134
|
-
|
|
135
|
-
|
|
132
|
+
const nodeClass = context.$class;
|
|
133
|
+
const compiler = (0, NodeCompilers_1.getCompiler)(nodeClass);
|
|
134
|
+
const sourceLevel = level + 1;
|
|
135
|
+
this.before(() => {
|
|
136
|
+
compiler.enter(fw, sourceLevel, context);
|
|
137
|
+
compiler.generate(fw, sourceLevel, context, TemplateMarkToTypeScriptCompiler.doIt);
|
|
136
138
|
});
|
|
137
|
-
this.after(
|
|
138
|
-
|
|
139
|
+
this.after(() => {
|
|
140
|
+
compiler.exit(fw, sourceLevel, context);
|
|
139
141
|
});
|
|
140
142
|
}
|
|
141
143
|
});
|
|
142
|
-
fw.writeLine(level,
|
|
143
|
-
}
|
|
144
|
+
fw.writeLine(level, `// end processing ${concerto_core_1.ModelUtil.getShortName(templateMark.$class)}`);
|
|
145
|
+
}
|
|
144
146
|
/**
|
|
145
147
|
* Converts a TemplateMark document to typescript code that is parameterised
|
|
146
148
|
* by the 'data' argument.
|
|
@@ -163,15 +165,14 @@ var TemplateMarkToTypeScriptCompiler = /** @class */ (function () {
|
|
|
163
165
|
* @param {IDocument} templateMark the TemplateMark Concerto resource
|
|
164
166
|
* @param {string} outputDir the output directory for code
|
|
165
167
|
*/
|
|
166
|
-
|
|
167
|
-
|
|
168
|
+
compileGenerator(templateMark, outputDir) {
|
|
169
|
+
const fw = new concerto_util_1.FileWriter(outputDir);
|
|
168
170
|
fw.openFile('index.ts');
|
|
169
171
|
fw.writeLine(0, '// generated code');
|
|
170
172
|
fw.writeLine(0, 'import { readFileSync } from \'fs\';');
|
|
171
|
-
fw.writeLine(0, 'import dayjs from \'dayjs\';');
|
|
172
173
|
fw.writeLine(0, 'import { generator } from \'./generator\';');
|
|
173
174
|
fw.writeLine(0, 'if(process.argv.length === 3) {');
|
|
174
|
-
fw.writeLine(1, 'const result = generator( JSON.parse(readFileSync(process.argv[2], \'utf-8\')), {},
|
|
175
|
+
fw.writeLine(1, 'const result = generator( JSON.parse(readFileSync(process.argv[2], \'utf-8\')), {}, {});');
|
|
175
176
|
fw.writeLine(1, 'console.log(JSON.stringify(result, null, 2));');
|
|
176
177
|
fw.writeLine(0, '}');
|
|
177
178
|
fw.writeLine(0, 'else {');
|
|
@@ -189,28 +190,28 @@ var TemplateMarkToTypeScriptCompiler = /** @class */ (function () {
|
|
|
189
190
|
TemplateMarkToTypeScriptCompiler.doIt(fw, 1, templateMark);
|
|
190
191
|
(0, Common_1.writeEpilog)(fw, 0);
|
|
191
192
|
fw.closeFile();
|
|
192
|
-
}
|
|
193
|
+
}
|
|
193
194
|
/**
|
|
194
195
|
* Decompresses the base64 zipped runtime into an output folder.
|
|
195
196
|
* @param {string} outputDir the output directory to copy the runtime to
|
|
196
197
|
*/
|
|
197
|
-
|
|
198
|
-
(0, fs_extra_1.ensureDirSync)(
|
|
199
|
-
|
|
200
|
-
|
|
198
|
+
copyRuntime(outputDir) {
|
|
199
|
+
(0, fs_extra_1.ensureDirSync)(`${outputDir}/${Common_1.RUNTIME_DIR}`);
|
|
200
|
+
const runtimeBuffer = Buffer.from(runtime_1.RUNTIME_TGZ_BASE64, 'base64');
|
|
201
|
+
const s = new stream_1.Readable();
|
|
201
202
|
s.push(runtimeBuffer);
|
|
202
203
|
s.push(null);
|
|
203
204
|
s.pipe(tar.x({
|
|
204
205
|
strip: 2,
|
|
205
|
-
C:
|
|
206
|
+
C: `${outputDir}/${Common_1.RUNTIME_DIR}`
|
|
206
207
|
}));
|
|
207
|
-
}
|
|
208
|
+
}
|
|
208
209
|
/**
|
|
209
210
|
* Create package.json for the generated code
|
|
210
211
|
* @param {string} outputDir the output directory to copy the runtime to
|
|
211
212
|
*/
|
|
212
|
-
|
|
213
|
-
|
|
213
|
+
createPackage(outputDir) {
|
|
214
|
+
const packageJson = {
|
|
214
215
|
'name': 'generated',
|
|
215
216
|
'version': '1.0.0',
|
|
216
217
|
'description': 'TypeScript code generated from TemplateMark',
|
|
@@ -237,9 +238,9 @@ var TemplateMarkToTypeScriptCompiler = /** @class */ (function () {
|
|
|
237
238
|
'start': 'ts-node index.ts sample.json'
|
|
238
239
|
}
|
|
239
240
|
};
|
|
240
|
-
(0, fs_extra_1.writeFileSync)(
|
|
241
|
-
}
|
|
242
|
-
|
|
241
|
+
(0, fs_extra_1.writeFileSync)(`${outputDir}/package.json`, JSON.stringify(packageJson, null, 2));
|
|
242
|
+
}
|
|
243
|
+
compile(templateMark, outputDir, options) {
|
|
243
244
|
// create output dir
|
|
244
245
|
(0, fs_extra_1.ensureDirSync)(outputDir);
|
|
245
246
|
// generate sample data
|
|
@@ -249,42 +250,42 @@ var TemplateMarkToTypeScriptCompiler = /** @class */ (function () {
|
|
|
249
250
|
this.generateTypeScript(this.getTemplateMarkModelManager(), outputDir);
|
|
250
251
|
this.generateTypeScript(this.getCiceroMarkModelManager(), outputDir);
|
|
251
252
|
// generate names for all the nodes containing user code
|
|
252
|
-
|
|
253
|
+
const namedTemplateMark = TemplateMarkToTypeScriptCompiler.nameUserCode(templateMark.toJSON ? templateMark.toJSON() : templateMark);
|
|
253
254
|
// compile the user code
|
|
254
255
|
this.compileUserCode(namedTemplateMark, outputDir);
|
|
255
256
|
// copy the runtime
|
|
256
|
-
if (!
|
|
257
|
+
if (!options?.skipCopyRuntime) {
|
|
257
258
|
this.copyRuntime(outputDir);
|
|
258
259
|
}
|
|
259
260
|
// compile the generator
|
|
260
|
-
if (!
|
|
261
|
+
if (!options?.skipGenerator) {
|
|
261
262
|
this.createPackage(outputDir);
|
|
262
263
|
this.compileGenerator(namedTemplateMark, outputDir);
|
|
263
264
|
}
|
|
264
|
-
}
|
|
265
|
-
|
|
265
|
+
}
|
|
266
|
+
static nameUserCode(templateMarkDom) {
|
|
266
267
|
return (0, traverse_1.default)(templateMarkDom).map(function (x) {
|
|
267
|
-
if (x && ((x.$class ===
|
|
268
|
-
(
|
|
269
|
-
x.functionName =
|
|
268
|
+
if (x && ((x.$class === `${markdown_common_1.TemplateMarkModel.NAMESPACE}.ConditionalDefinition` && x.condition) ||
|
|
269
|
+
(`${markdown_common_1.TemplateMarkModel.NAMESPACE}.ClauseDefinition` && x.condition))) {
|
|
270
|
+
x.functionName = `condition_${this.path.join('_')}`;
|
|
270
271
|
}
|
|
271
272
|
this.update(x);
|
|
272
273
|
});
|
|
273
|
-
}
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
var fw = new concerto_util_1.FileWriter(outputDir);
|
|
274
|
+
}
|
|
275
|
+
compileUserCode(templateMark, outputDir) {
|
|
276
|
+
const fw = new concerto_util_1.FileWriter(outputDir);
|
|
277
277
|
fw.openFile('usercode.ts');
|
|
278
278
|
fw.writeLine(0, '// generated code, do not modify');
|
|
279
279
|
fw.writeLine(0, '');
|
|
280
280
|
fw.writeLine(0, '// IMPORTS');
|
|
281
|
-
fw.writeLine(0,
|
|
281
|
+
fw.writeLine(0, `import * as TemplateModel from './${this.templateClass.getNamespace()}';`);
|
|
282
282
|
fw.writeLine(0, 'import dayjs from \'dayjs\';');
|
|
283
283
|
fw.writeLine(0, 'import jp from \'jsonpath\';');
|
|
284
|
+
fw.writeLine(0, 'import {GenerationOptions} from \'./runtime/TypeScriptRuntime\';');
|
|
284
285
|
fw.writeLine(0, '');
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
if (x && x.$class ===
|
|
286
|
+
const templateMarkDom = templateMark;
|
|
287
|
+
const functionNodes = (0, traverse_1.default)(templateMarkDom).reduce(function (acc, x) {
|
|
288
|
+
if (x && x.$class === `${markdown_common_1.TemplateMarkModel.NAMESPACE}.FormulaDefinition`) {
|
|
288
289
|
acc.push({
|
|
289
290
|
name: x.name,
|
|
290
291
|
code: x.code,
|
|
@@ -292,8 +293,8 @@ var TemplateMarkToTypeScriptCompiler = /** @class */ (function () {
|
|
|
292
293
|
}
|
|
293
294
|
return acc;
|
|
294
295
|
}, []);
|
|
295
|
-
|
|
296
|
-
if (x && x.$class ===
|
|
296
|
+
const conditionalNodes = (0, traverse_1.default)(templateMarkDom).reduce(function (acc, x) {
|
|
297
|
+
if (x && x.$class === `${markdown_common_1.TemplateMarkModel.NAMESPACE}.ConditionalDefinition` && x.condition) {
|
|
297
298
|
acc.push({
|
|
298
299
|
name: x.functionName,
|
|
299
300
|
code: x.condition,
|
|
@@ -301,8 +302,8 @@ var TemplateMarkToTypeScriptCompiler = /** @class */ (function () {
|
|
|
301
302
|
}
|
|
302
303
|
return acc;
|
|
303
304
|
}, []);
|
|
304
|
-
|
|
305
|
-
if (x && x.$class ===
|
|
305
|
+
const clauseNodes = (0, traverse_1.default)(templateMarkDom).reduce(function (acc, x) {
|
|
306
|
+
if (x && x.$class === `${markdown_common_1.TemplateMarkModel.NAMESPACE}.ClauseDefinition` && x.condition) {
|
|
306
307
|
acc.push({
|
|
307
308
|
name: x.functionName,
|
|
308
309
|
code: x.condition,
|
|
@@ -311,23 +312,22 @@ var TemplateMarkToTypeScriptCompiler = /** @class */ (function () {
|
|
|
311
312
|
return acc;
|
|
312
313
|
}, []);
|
|
313
314
|
fw.writeLine(0, '// FORMULAE');
|
|
314
|
-
functionNodes.forEach(
|
|
315
|
-
|
|
315
|
+
functionNodes.forEach((fun) => {
|
|
316
|
+
this.writeFunction(fw, `${fun.name}`, 'any', fun.code.contents);
|
|
316
317
|
});
|
|
317
318
|
fw.writeLine(0, '');
|
|
318
319
|
fw.writeLine(0, '// CONDITIONALS');
|
|
319
|
-
conditionalNodes.forEach(
|
|
320
|
-
|
|
320
|
+
conditionalNodes.forEach((fun) => {
|
|
321
|
+
this.writeFunction(fw, `${fun.name}`, 'boolean', fun.code.contents);
|
|
321
322
|
});
|
|
322
323
|
fw.writeLine(0, '');
|
|
323
324
|
fw.writeLine(0, '// CLAUSES');
|
|
324
|
-
clauseNodes.forEach(
|
|
325
|
-
|
|
325
|
+
clauseNodes.forEach((fun) => {
|
|
326
|
+
this.writeFunction(fw, `${fun.name}`, 'boolean', fun.code.contents);
|
|
326
327
|
});
|
|
327
328
|
fw.writeLine(0, '');
|
|
328
329
|
fw.closeFile();
|
|
329
|
-
}
|
|
330
|
-
|
|
331
|
-
}());
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
332
|
exports.TemplateMarkToTypeScriptCompiler = TemplateMarkToTypeScriptCompiler;
|
|
333
333
|
//# sourceMappingURL=TemplateMarkToTypeScriptCompiler.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TemplateMarkToTypeScriptCompiler.js","sourceRoot":"","sources":["../src/TemplateMarkToTypeScriptCompiler.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;;;GAYG;AACH,
|
|
1
|
+
{"version":3,"file":"TemplateMarkToTypeScriptCompiler.js","sourceRoot":"","sources":["../src/TemplateMarkToTypeScriptCompiler.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;;;GAYG;AACH,wDAAgC;AAChC,uCAAwD;AACxD,yCAA2B;AAC3B,mCAAkC;AAElC,oEAAwH;AAExH,gEAAsH;AACtH,sEAA0D;AAC1D,gEAA0D;AAC1D,6DAAwD;AACxD,+CAAyF;AACzF,qCAAuD;AACvD,+CAAuD;AASvD;;;GAGG;AACH,MAAa,gCAAgC;IAIzC,YAAY,YAA0B,EAAC,kBAA2B;QAC9D,IAAI,CAAC,YAAY,GAAG,YAAY,CAAC;QACjC,IAAI,CAAC,aAAa,GAAG,IAAA,oCAA2B,EAAC,IAAI,CAAC,YAAY,EAAC,kBAAkB,CAAC,CAAC;IAC3F,CAAC;IAED,qBAAqB,CAAC,YAA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;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;AA/TD,4EA+TC"}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.TypeScriptCompilationContext = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
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
7
|
/**
|
|
8
8
|
* This class creates the typescript types
|
|
9
9
|
* required to compile Typescript expressions (used in
|
|
@@ -11,35 +11,47 @@ var Common_1 = require("./Common");
|
|
|
11
11
|
* these to create a compilation context for '@typescript/twoslash'
|
|
12
12
|
* which is used to compile the typescript code.
|
|
13
13
|
*/
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
class TypeScriptCompilationContext {
|
|
15
|
+
constructor(modelManager, templateConceptFqn) {
|
|
16
16
|
this.modelManager = modelManager;
|
|
17
17
|
this.templateClass = (0, Common_1.getTemplateClassDeclaration)(this.modelManager, templateConceptFqn);
|
|
18
18
|
}
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
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
24
|
fileWriter: writer
|
|
25
25
|
};
|
|
26
26
|
this.modelManager.accept(visitor, params);
|
|
27
|
-
writer.getFilesInMemory().forEach(
|
|
27
|
+
writer.getFilesInMemory().forEach((value, key) => {
|
|
28
28
|
result[key] = value;
|
|
29
29
|
});
|
|
30
30
|
return result;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
Object.keys(files).forEach(
|
|
36
|
-
|
|
37
|
-
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
|
+
`;
|
|
38
41
|
});
|
|
39
|
-
result +=
|
|
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
|
+
`;
|
|
40
53
|
return result;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
}());
|
|
54
|
+
}
|
|
55
|
+
}
|
|
44
56
|
exports.TypeScriptCompilationContext = TypeScriptCompilationContext;
|
|
45
57
|
//# sourceMappingURL=TypeScriptCompilationContext.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TypeScriptCompilationContext.js","sourceRoot":"","sources":["../src/TypeScriptCompilationContext.ts"],"names":[],"mappings":";;;AAcA,
|
|
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,3 +1,12 @@
|
|
|
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;
|
|
1
10
|
export declare function peek($data: any[]): any;
|
|
2
11
|
export declare function peekProperty($data: any[], propertyName: string, allowUndefined?: boolean): any;
|
|
3
12
|
export declare function push($data: any[], item: any): number;
|