@accordproject/template-engine 1.0.3 → 1.0.5
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.d.ts +20 -0
- package/dist/Common.js +59 -0
- package/dist/Common.js.map +1 -0
- package/dist/TemplateMarkInterpreter.d.ts +34 -0
- package/dist/TemplateMarkInterpreter.js +432 -0
- package/dist/TemplateMarkInterpreter.js.map +1 -0
- package/dist/TemplateMarkToJavaScriptCompiler.d.ts +19 -0
- package/dist/TemplateMarkToJavaScriptCompiler.js +90 -0
- package/dist/TemplateMarkToJavaScriptCompiler.js.map +1 -0
- package/dist/TemplateMarkToTypeScriptCompiler.d.ts +69 -0
- package/dist/TemplateMarkToTypeScriptCompiler.js +239 -0
- package/dist/TemplateMarkToTypeScriptCompiler.js.map +1 -0
- package/dist/TypeScriptCompilationContext.d.ts +15 -0
- package/dist/TypeScriptCompilationContext.js +45 -0
- package/dist/TypeScriptCompilationContext.js.map +1 -0
- package/dist/TypeScriptRuntime.d.ts +5 -0
- package/dist/TypeScriptRuntime.js +67 -0
- package/dist/TypeScriptRuntime.js.map +1 -0
- package/dist/TypeScriptToJavaScriptCompiler.d.ts +14 -0
- package/dist/TypeScriptToJavaScriptCompiler.js +57 -0
- package/dist/TypeScriptToJavaScriptCompiler.js.map +1 -0
- package/dist/compilers/Clause.d.ts +14 -0
- package/dist/compilers/Clause.js +60 -0
- package/dist/compilers/Clause.js.map +1 -0
- package/dist/compilers/Common.d.ts +66 -0
- package/dist/compilers/Common.js +206 -0
- package/dist/compilers/Common.js.map +1 -0
- package/dist/compilers/Conditional.d.ts +12 -0
- package/dist/compilers/Conditional.js +53 -0
- package/dist/compilers/Conditional.js.map +1 -0
- package/dist/compilers/ContractDefinition.d.ts +8 -0
- package/dist/compilers/ContractDefinition.js +50 -0
- package/dist/compilers/ContractDefinition.js.map +1 -0
- package/dist/compilers/FormattedVariable.d.ts +8 -0
- package/dist/compilers/FormattedVariable.js +46 -0
- package/dist/compilers/FormattedVariable.js.map +1 -0
- package/dist/compilers/Formula.d.ts +8 -0
- package/dist/compilers/Formula.js +41 -0
- package/dist/compilers/Formula.js.map +1 -0
- package/dist/compilers/Join.d.ts +8 -0
- package/dist/compilers/Join.js +39 -0
- package/dist/compilers/Join.js.map +1 -0
- package/dist/compilers/ListBlock.d.ts +11 -0
- package/dist/compilers/ListBlock.js +57 -0
- package/dist/compilers/ListBlock.js.map +1 -0
- package/dist/compilers/NodeCompilers.d.ts +7 -0
- package/dist/compilers/NodeCompilers.js +87 -0
- package/dist/compilers/NodeCompilers.js.map +1 -0
- package/dist/compilers/Optional.d.ts +11 -0
- package/dist/compilers/Optional.js +65 -0
- package/dist/compilers/Optional.js.map +1 -0
- package/dist/compilers/Variable.d.ts +8 -0
- package/dist/compilers/Variable.js +45 -0
- package/dist/compilers/Variable.js.map +1 -0
- package/dist/compilers/With.d.ts +10 -0
- package/dist/compilers/With.js +40 -0
- package/dist/compilers/With.js.map +1 -0
- package/dist/drafting/Boolean/index.d.ts +6 -0
- package/dist/drafting/Boolean/index.js +30 -0
- package/dist/drafting/Boolean/index.js.map +1 -0
- package/dist/drafting/DateTime/index.d.ts +7 -0
- package/dist/drafting/DateTime/index.js +33 -0
- package/dist/drafting/DateTime/index.js.map +1 -0
- package/dist/drafting/Double/format.d.ts +13 -0
- package/dist/drafting/Double/format.js +55 -0
- package/dist/drafting/Double/format.js.map +1 -0
- package/dist/drafting/Double/index.d.ts +7 -0
- package/dist/drafting/Double/index.js +33 -0
- package/dist/drafting/Double/index.js.map +1 -0
- package/dist/drafting/Integer/format.d.ts +13 -0
- package/dist/drafting/Integer/format.js +45 -0
- package/dist/drafting/Integer/format.js.map +1 -0
- package/dist/drafting/Integer/index.d.ts +7 -0
- package/dist/drafting/Integer/index.js +33 -0
- package/dist/drafting/Integer/index.js.map +1 -0
- package/dist/drafting/Long/index.d.ts +7 -0
- package/dist/drafting/Long/index.js +33 -0
- package/dist/drafting/Long/index.js.map +1 -0
- package/dist/drafting/MonetaryAmount/currencycode.d.ts +35 -0
- package/dist/drafting/MonetaryAmount/currencycode.js +53 -0
- package/dist/drafting/MonetaryAmount/currencycode.js.map +1 -0
- package/dist/drafting/MonetaryAmount/index.d.ts +12 -0
- package/dist/drafting/MonetaryAmount/index.js +67 -0
- package/dist/drafting/MonetaryAmount/index.js.map +1 -0
- package/dist/drafting/String/index.d.ts +6 -0
- package/dist/drafting/String/index.js +25 -0
- package/dist/drafting/String/index.js.map +1 -0
- package/dist/drafting/index.d.ts +1 -0
- package/dist/drafting/index.js +36 -0
- package/dist/drafting/index.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +21 -0
- package/dist/index.js.map +1 -0
- package/dist/model-gen/concerto.metamodel@1.0.0.d.ts +173 -0
- package/dist/model-gen/concerto.metamodel@1.0.0.js +5 -0
- package/dist/model-gen/concerto.metamodel@1.0.0.js.map +1 -0
- package/dist/model-gen/concerto@1.0.0.d.ts +18 -0
- package/dist/model-gen/concerto@1.0.0.js +5 -0
- package/dist/model-gen/concerto@1.0.0.js.map +1 -0
- package/dist/model-gen/org.accordproject.ciceromark@0.6.0.d.ts +49 -0
- package/dist/model-gen/org.accordproject.ciceromark@0.6.0.js +5 -0
- package/dist/model-gen/org.accordproject.ciceromark@0.6.0.js.map +1 -0
- package/dist/model-gen/org.accordproject.commonmark@0.5.0.d.ts +89 -0
- package/dist/model-gen/org.accordproject.commonmark@0.5.0.js +5 -0
- package/dist/model-gen/org.accordproject.commonmark@0.5.0.js.map +1 -0
- package/dist/model-gen/org.accordproject.templatemark@0.4.0.d.ts +72 -0
- package/dist/model-gen/org.accordproject.templatemark@0.4.0.js +11 -0
- package/dist/model-gen/org.accordproject.templatemark@0.4.0.js.map +1 -0
- package/package.json +3 -3
|
@@ -0,0 +1,90 @@
|
|
|
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 __importDefault = (this && this.__importDefault) || function (mod) {
|
|
16
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
17
|
+
};
|
|
18
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
|
+
exports.TemplateMarkToJavaScriptCompiler = void 0;
|
|
20
|
+
var traverse_1 = __importDefault(require("traverse"));
|
|
21
|
+
var markdown_common_1 = require("@accordproject/markdown-common");
|
|
22
|
+
var TypeScriptToJavaScriptCompiler_1 = require("./TypeScriptToJavaScriptCompiler");
|
|
23
|
+
var Common_1 = require("./Common");
|
|
24
|
+
var TemplateMarkToTypeScriptCompiler_1 = require("./TemplateMarkToTypeScriptCompiler");
|
|
25
|
+
var CODE_NODES = [
|
|
26
|
+
"".concat(markdown_common_1.TemplateMarkModel.NAMESPACE, ".FormulaDefinition"),
|
|
27
|
+
"".concat(markdown_common_1.TemplateMarkModel.NAMESPACE, ".ConditionalDefinition"),
|
|
28
|
+
"".concat(markdown_common_1.TemplateMarkModel.NAMESPACE, ".ClauseDefinition"),
|
|
29
|
+
];
|
|
30
|
+
/**
|
|
31
|
+
* Compiles all the Typescript nodes in a TemplateMark JSON
|
|
32
|
+
* to ES_2020 and returns a modified TemplateMark JSON.
|
|
33
|
+
*/
|
|
34
|
+
var TemplateMarkToJavaScriptCompiler = /** @class */ (function () {
|
|
35
|
+
function TemplateMarkToJavaScriptCompiler(modelManager) {
|
|
36
|
+
this.modelManager = modelManager;
|
|
37
|
+
this.compiler = new TypeScriptToJavaScriptCompiler_1.TypeScriptToJavaScriptCompiler(modelManager);
|
|
38
|
+
this.templateClass = (0, Common_1.getTemplateClassDeclaration)(modelManager);
|
|
39
|
+
}
|
|
40
|
+
TemplateMarkToJavaScriptCompiler.prototype.compile = function (templateJson) {
|
|
41
|
+
var namedTemplateMark = TemplateMarkToTypeScriptCompiler_1.TemplateMarkToTypeScriptCompiler.nameUserCode(templateJson);
|
|
42
|
+
var functionCompiler = new TemplateMarkToTypeScriptCompiler_1.TemplateMarkToTypeScriptCompiler(this.modelManager);
|
|
43
|
+
// eslint-disable-next-line @typescript-eslint/no-this-alias
|
|
44
|
+
var that = this;
|
|
45
|
+
var errors = Array();
|
|
46
|
+
var compiled = (0, traverse_1.default)(namedTemplateMark).map(function (x) {
|
|
47
|
+
if (x && CODE_NODES.includes(x.$class)) {
|
|
48
|
+
if (x.code) { // formula
|
|
49
|
+
var result = that.compiler.compile(functionCompiler.writeFunctionToString(x.name, 'any', x.code.contents));
|
|
50
|
+
if (result.errors.length === 0) {
|
|
51
|
+
x.code.contents = result.code;
|
|
52
|
+
x.code.type = 'ES_2020';
|
|
53
|
+
this.update(x);
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
errors.push({
|
|
57
|
+
nodeId: x.name,
|
|
58
|
+
code: x.code.contents,
|
|
59
|
+
errors: result.errors
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
else if (x.condition) { // condition or clause (boolean condition)
|
|
64
|
+
var result = that.compiler.compile(functionCompiler.writeFunctionToString(x.functionName, 'boolean', x.condition.contents));
|
|
65
|
+
if (result.errors.length === 0) {
|
|
66
|
+
x.condition.contents = result.code;
|
|
67
|
+
x.condition.type = 'ES_2020';
|
|
68
|
+
this.update(x);
|
|
69
|
+
}
|
|
70
|
+
else {
|
|
71
|
+
errors.push({
|
|
72
|
+
nodeId: x.functionName,
|
|
73
|
+
code: x.condition.contents,
|
|
74
|
+
errors: result.errors
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
if (errors.length === 0) {
|
|
81
|
+
return compiled;
|
|
82
|
+
}
|
|
83
|
+
else {
|
|
84
|
+
throw errors;
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
return TemplateMarkToJavaScriptCompiler;
|
|
88
|
+
}());
|
|
89
|
+
exports.TemplateMarkToJavaScriptCompiler = TemplateMarkToJavaScriptCompiler;
|
|
90
|
+
//# sourceMappingURL=TemplateMarkToJavaScriptCompiler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TemplateMarkToJavaScriptCompiler.js","sourceRoot":"","sources":["../src/TemplateMarkToJavaScriptCompiler.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;GAYG;;;;;;AAEH,sDAAgC;AAChC,kEAAmE;AAEnE,mFAAkF;AAElF,mCAAuD;AACvD,uFAAsF;AAEtF,IAAM,UAAU,GAAG;IACf,UAAG,mCAAiB,CAAC,SAAS,uBAAoB;IAClD,UAAG,mCAAiB,CAAC,SAAS,2BAAwB;IACtD,UAAG,mCAAiB,CAAC,SAAS,sBAAmB;CACpD,CAAC;AAQF;;;GAGG;AACH;IAKI,0CAAY,YAA0B;QAClC,IAAI,CAAC,YAAY,GAAG,YAAY,CAAC;QACjC,IAAI,CAAC,QAAQ,GAAG,IAAI,+DAA8B,CAAC,YAAY,CAAC,CAAC;QACjE,IAAI,CAAC,aAAa,GAAG,IAAA,oCAA2B,EAAC,YAAY,CAAC,CAAC;IACnE,CAAC;IAED,kDAAO,GAAP,UAAQ,YAAiB;QACrB,IAAM,iBAAiB,GAAG,mEAAgC,CAAC,YAAY,CAAC,YAAY,CAAC,CAAC;QACtF,IAAM,gBAAgB,GAAG,IAAI,mEAAgC,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;QAEjF,4DAA4D;QAC5D,IAAM,IAAI,GAAG,IAAI,CAAC;QAClB,IA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nC,CAAC,CAAC,SAAS,CAAC,IAAI,GAAG,SAAS,CAAC;wBAC7B,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;qBAClB;yBACI;wBACD,MAAM,CAAC,IAAI,CAAC;4BACR,MAAM,EAAE,CAAC,CAAC,YAAY;4BACtB,IAAI,EAAE,CAAC,CAAC,SAAS,CAAC,QAAQ;4BAC1B,MAAM,EAAE,MAAM,CAAC,MAAM;yBACxB,CAAC,CAAC;qBACN;iBACJ;aACJ;QACL,CAAC,CAAC,CAAC;QAEH,IAAG,MAAM,CAAC,MAAM,KAAK,CAAC,EAAE;YACpB,OAAO,QAAQ,CAAC;SACnB;aACI;YACD,MAAM,MAAM,CAAC;SAChB;IACL,CAAC;IACL,uCAAC;AAAD,CAAC,AA5DD,IA4DC;AA5DY,4EAAgC"}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { ClassDeclaration, ModelManager, Resource } from '@accordproject/concerto-core';
|
|
2
|
+
import { FileWriter } from '@accordproject/concerto-util';
|
|
3
|
+
export declare type ProcessingFunction = (fw: FileWriter, level: number, resource: any) => void;
|
|
4
|
+
export declare type CompilationOptions = {
|
|
5
|
+
skipGenerator?: boolean;
|
|
6
|
+
skipCopyRuntime?: boolean;
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* Converts TemplateMark DOM to a Typescript function, that, when run with JSON data
|
|
10
|
+
* that conforms to the template model will produce AgreementMark JSON output.
|
|
11
|
+
*/
|
|
12
|
+
export declare class TemplateMarkToTypeScriptCompiler {
|
|
13
|
+
modelManager: ModelManager;
|
|
14
|
+
templateClass: ClassDeclaration;
|
|
15
|
+
constructor(modelManager: ModelManager);
|
|
16
|
+
writeFunctionToString(functionName: string, returnType: string, code: string): string;
|
|
17
|
+
writeFunction(fw: FileWriter, functionName: string, returnType: string, code: string): void;
|
|
18
|
+
/**
|
|
19
|
+
* Get a model manager with templatemark model
|
|
20
|
+
* @param {string} outputDir the output directory
|
|
21
|
+
* @returns {ModelManager} the model manager
|
|
22
|
+
*/
|
|
23
|
+
getTemplateMarkModelManager(): ModelManager;
|
|
24
|
+
/**
|
|
25
|
+
* Get a model manager with templatemark model
|
|
26
|
+
* @param {string} outputDir the output directory
|
|
27
|
+
* @returns {ModelManager} the model manager
|
|
28
|
+
*/
|
|
29
|
+
getCiceroMarkModelManager(): ModelManager;
|
|
30
|
+
generateTypeScript(modelManager: ModelManager, outputDir: string): void;
|
|
31
|
+
/**
|
|
32
|
+
* The main iteration function over templatemark. This function
|
|
33
|
+
* looks up an INodeCompiler that can handle each templatemark node
|
|
34
|
+
* and delegates to it for code generation.
|
|
35
|
+
* Note that the result of code generation (a CiceroMark node) is left in
|
|
36
|
+
* the $result global varianble.
|
|
37
|
+
* @param {FileWriter} fw the file writer to use
|
|
38
|
+
* @param {number} level the indentation level
|
|
39
|
+
* @param {object} templateMark the templatemark node to iterate over
|
|
40
|
+
*/
|
|
41
|
+
static doIt(fw: FileWriter, level: number, templateMark: any): void;
|
|
42
|
+
/**
|
|
43
|
+
* Converts a TemplateMark document to typescript code that is parameterised
|
|
44
|
+
* by the 'data' argument.
|
|
45
|
+
*
|
|
46
|
+
* The strategy is to traverse the template mark json, converting each node into
|
|
47
|
+
* typescript statements that add an equivalent ciceromark node. Variables will
|
|
48
|
+
* pull values from 'data'.
|
|
49
|
+
*
|
|
50
|
+
* Conditionals and formulae will call the functions produced by
|
|
51
|
+
* compileUserCode.
|
|
52
|
+
*
|
|
53
|
+
* Note that code generation process is itself recursive, for example, when
|
|
54
|
+
* a list definition node is encountered the list must be iterated over
|
|
55
|
+
* based on a variable value coming from data, and code must be
|
|
56
|
+
* generated to produce each list item.
|
|
57
|
+
*
|
|
58
|
+
* All internal variables are prefixed with '$' to ensure (?)
|
|
59
|
+
* that they cannot collide with end user variable names.
|
|
60
|
+
*
|
|
61
|
+
* @param {IDocument} templateMark the TemplateMark Concerto resource
|
|
62
|
+
* @param {string} outputDir the output directory for code
|
|
63
|
+
*/
|
|
64
|
+
compileGenerator(templateMark: Resource, outputDir: string): void;
|
|
65
|
+
copyRuntime(outputDir: string): void;
|
|
66
|
+
compile(templateMark: Resource, outputDir: string, options?: CompilationOptions): void;
|
|
67
|
+
static nameUserCode(templateMarkDom: any): any;
|
|
68
|
+
compileUserCode(templateMark: Resource, outputDir: string): void;
|
|
69
|
+
}
|
|
@@ -0,0 +1,239 @@
|
|
|
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.TemplateMarkToTypeScriptCompiler = 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
|
+
var traverse_1 = __importDefault(require("traverse"));
|
|
21
|
+
var fs_extra_1 = require("fs-extra");
|
|
22
|
+
var markdown_common_1 = require("@accordproject/markdown-common");
|
|
23
|
+
var concerto_core_1 = require("@accordproject/concerto-core");
|
|
24
|
+
var concerto_tools_1 = require("@accordproject/concerto-tools");
|
|
25
|
+
var concerto_util_1 = require("@accordproject/concerto-util");
|
|
26
|
+
var NodeCompilers_1 = require("./compilers/NodeCompilers");
|
|
27
|
+
var Common_1 = require("./compilers/Common");
|
|
28
|
+
var Common_2 = require("./Common");
|
|
29
|
+
/**
|
|
30
|
+
* Converts TemplateMark DOM to a Typescript function, that, when run with JSON data
|
|
31
|
+
* that conforms to the template model will produce AgreementMark JSON output.
|
|
32
|
+
*/
|
|
33
|
+
var TemplateMarkToTypeScriptCompiler = /** @class */ (function () {
|
|
34
|
+
function TemplateMarkToTypeScriptCompiler(modelManager) {
|
|
35
|
+
this.modelManager = modelManager;
|
|
36
|
+
this.templateClass = (0, Common_2.getTemplateClassDeclaration)(this.modelManager);
|
|
37
|
+
}
|
|
38
|
+
TemplateMarkToTypeScriptCompiler.prototype.writeFunctionToString = function (functionName, returnType, code) {
|
|
39
|
+
var result = '';
|
|
40
|
+
result += '/// ---cut---\n';
|
|
41
|
+
result += "export function ".concat(functionName, "(data:TemplateModel.I").concat(this.templateClass.getName(), ", library:any, now:dayjs.Dayjs) : ").concat(returnType, " {\n");
|
|
42
|
+
this.templateClass.getProperties().forEach(function (p) {
|
|
43
|
+
result += " const ".concat(p.getName(), " = data.").concat(p.getName(), ";\n");
|
|
44
|
+
});
|
|
45
|
+
result += ' ' + code.trim() + '\n';
|
|
46
|
+
result += '}\n';
|
|
47
|
+
result += '\n';
|
|
48
|
+
return result;
|
|
49
|
+
};
|
|
50
|
+
TemplateMarkToTypeScriptCompiler.prototype.writeFunction = function (fw, functionName, returnType, code) {
|
|
51
|
+
fw.writeLine(0, this.writeFunctionToString(functionName, returnType, code));
|
|
52
|
+
};
|
|
53
|
+
/**
|
|
54
|
+
* Get a model manager with templatemark model
|
|
55
|
+
* @param {string} outputDir the output directory
|
|
56
|
+
* @returns {ModelManager} the model manager
|
|
57
|
+
*/
|
|
58
|
+
TemplateMarkToTypeScriptCompiler.prototype.getTemplateMarkModelManager = function () {
|
|
59
|
+
var modelManager = new concerto_core_1.ModelManager({ strict: true });
|
|
60
|
+
modelManager.addCTOModel(markdown_common_1.ConcertoMetaModel.MODEL, 'concertometamodel.cto');
|
|
61
|
+
modelManager.addCTOModel(markdown_common_1.CommonMarkModel.MODEL, 'commonmark.cto');
|
|
62
|
+
modelManager.addCTOModel(markdown_common_1.TemplateMarkModel.MODEL, 'templatemark.cto');
|
|
63
|
+
return modelManager;
|
|
64
|
+
};
|
|
65
|
+
/**
|
|
66
|
+
* Get a model manager with templatemark model
|
|
67
|
+
* @param {string} outputDir the output directory
|
|
68
|
+
* @returns {ModelManager} the model manager
|
|
69
|
+
*/
|
|
70
|
+
TemplateMarkToTypeScriptCompiler.prototype.getCiceroMarkModelManager = function () {
|
|
71
|
+
var modelManager = new concerto_core_1.ModelManager({ strict: true });
|
|
72
|
+
modelManager.addCTOModel(markdown_common_1.ConcertoMetaModel.MODEL, 'concertometamodel.cto');
|
|
73
|
+
modelManager.addCTOModel(markdown_common_1.CommonMarkModel.MODEL, 'commonmark.cto');
|
|
74
|
+
modelManager.addCTOModel(markdown_common_1.CiceroMarkModel.MODEL, 'ciceromark.cto');
|
|
75
|
+
return modelManager;
|
|
76
|
+
};
|
|
77
|
+
TemplateMarkToTypeScriptCompiler.prototype.generateTypeScript = function (modelManager, outputDir) {
|
|
78
|
+
// generate the TS code for the template model
|
|
79
|
+
var tsVisitor = new concerto_tools_1.CodeGen.TypescriptVisitor();
|
|
80
|
+
var parameters = {
|
|
81
|
+
fileWriter: new concerto_util_1.FileWriter(outputDir)
|
|
82
|
+
};
|
|
83
|
+
modelManager.accept(tsVisitor, parameters);
|
|
84
|
+
};
|
|
85
|
+
/**
|
|
86
|
+
* The main iteration function over templatemark. This function
|
|
87
|
+
* looks up an INodeCompiler that can handle each templatemark node
|
|
88
|
+
* and delegates to it for code generation.
|
|
89
|
+
* Note that the result of code generation (a CiceroMark node) is left in
|
|
90
|
+
* the $result global varianble.
|
|
91
|
+
* @param {FileWriter} fw the file writer to use
|
|
92
|
+
* @param {number} level the indentation level
|
|
93
|
+
* @param {object} templateMark the templatemark node to iterate over
|
|
94
|
+
*/
|
|
95
|
+
TemplateMarkToTypeScriptCompiler.doIt = function (fw, level, templateMark) {
|
|
96
|
+
fw.writeLine(level, "// start processing ".concat(concerto_core_1.ModelUtil.getShortName(templateMark.$class)));
|
|
97
|
+
(0, traverse_1.default)(templateMark).forEach(function (context) {
|
|
98
|
+
if (typeof context === 'object' && context.$class && typeof context.$class === 'string') {
|
|
99
|
+
var nodeClass = context.$class;
|
|
100
|
+
var compiler_1 = (0, NodeCompilers_1.getCompiler)(nodeClass);
|
|
101
|
+
var sourceLevel_1 = level + 1;
|
|
102
|
+
this.before(function () {
|
|
103
|
+
compiler_1.enter(fw, sourceLevel_1, context);
|
|
104
|
+
compiler_1.generate(fw, sourceLevel_1, context, TemplateMarkToTypeScriptCompiler.doIt);
|
|
105
|
+
});
|
|
106
|
+
this.after(function () {
|
|
107
|
+
compiler_1.exit(fw, sourceLevel_1, context);
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
fw.writeLine(level, "// end processing ".concat(concerto_core_1.ModelUtil.getShortName(templateMark.$class)));
|
|
112
|
+
};
|
|
113
|
+
/**
|
|
114
|
+
* Converts a TemplateMark document to typescript code that is parameterised
|
|
115
|
+
* by the 'data' argument.
|
|
116
|
+
*
|
|
117
|
+
* The strategy is to traverse the template mark json, converting each node into
|
|
118
|
+
* typescript statements that add an equivalent ciceromark node. Variables will
|
|
119
|
+
* pull values from 'data'.
|
|
120
|
+
*
|
|
121
|
+
* Conditionals and formulae will call the functions produced by
|
|
122
|
+
* compileUserCode.
|
|
123
|
+
*
|
|
124
|
+
* Note that code generation process is itself recursive, for example, when
|
|
125
|
+
* a list definition node is encountered the list must be iterated over
|
|
126
|
+
* based on a variable value coming from data, and code must be
|
|
127
|
+
* generated to produce each list item.
|
|
128
|
+
*
|
|
129
|
+
* All internal variables are prefixed with '$' to ensure (?)
|
|
130
|
+
* that they cannot collide with end user variable names.
|
|
131
|
+
*
|
|
132
|
+
* @param {IDocument} templateMark the TemplateMark Concerto resource
|
|
133
|
+
* @param {string} outputDir the output directory for code
|
|
134
|
+
*/
|
|
135
|
+
TemplateMarkToTypeScriptCompiler.prototype.compileGenerator = function (templateMark, outputDir) {
|
|
136
|
+
var fw = new concerto_util_1.FileWriter(outputDir);
|
|
137
|
+
fw.openFile('generator.ts');
|
|
138
|
+
fw.writeLine(0, '// generated code, do not modify');
|
|
139
|
+
fw.writeLine(0, '');
|
|
140
|
+
fw.writeLine(0, '// IMPORTS');
|
|
141
|
+
(0, Common_1.writeImports)(fw, 0, this.templateClass);
|
|
142
|
+
fw.writeLine(0, '');
|
|
143
|
+
fw.writeLine(0, '// GENERATOR');
|
|
144
|
+
(0, Common_1.writeProlog)(fw, 0, this.templateClass);
|
|
145
|
+
TemplateMarkToTypeScriptCompiler.doIt(fw, 1, templateMark);
|
|
146
|
+
(0, Common_1.writeEpilog)(fw, 0);
|
|
147
|
+
fw.closeFile();
|
|
148
|
+
};
|
|
149
|
+
TemplateMarkToTypeScriptCompiler.prototype.copyRuntime = function (outputDir) {
|
|
150
|
+
(0, fs_extra_1.copySync)('./src/drafting', "".concat(outputDir, "/").concat(Common_1.RUNTIME_DIR, "/drafting"));
|
|
151
|
+
(0, fs_extra_1.copySync)('./src/TypeScriptRuntime.ts', "".concat(outputDir, "/").concat(Common_1.RUNTIME_DIR, "/TypeScriptRuntime.ts"));
|
|
152
|
+
};
|
|
153
|
+
TemplateMarkToTypeScriptCompiler.prototype.compile = function (templateMark, outputDir, options) {
|
|
154
|
+
// generate the model
|
|
155
|
+
this.generateTypeScript(this.modelManager, "".concat(outputDir));
|
|
156
|
+
this.generateTypeScript(this.getTemplateMarkModelManager(), "".concat(outputDir));
|
|
157
|
+
this.generateTypeScript(this.getCiceroMarkModelManager(), "".concat(outputDir));
|
|
158
|
+
// generate names for all the nodes containing user code
|
|
159
|
+
var namedTemplateMark = TemplateMarkToTypeScriptCompiler.nameUserCode(templateMark.toJSON());
|
|
160
|
+
// compile the user code
|
|
161
|
+
this.compileUserCode(namedTemplateMark, outputDir);
|
|
162
|
+
// compile the generator
|
|
163
|
+
if (!(options === null || options === void 0 ? void 0 : options.skipCopyRuntime)) {
|
|
164
|
+
this.copyRuntime(outputDir);
|
|
165
|
+
}
|
|
166
|
+
// compile the generator
|
|
167
|
+
if (!(options === null || options === void 0 ? void 0 : options.skipGenerator)) {
|
|
168
|
+
this.compileGenerator(namedTemplateMark, outputDir);
|
|
169
|
+
}
|
|
170
|
+
};
|
|
171
|
+
TemplateMarkToTypeScriptCompiler.nameUserCode = function (templateMarkDom) {
|
|
172
|
+
return (0, traverse_1.default)(templateMarkDom).map(function (x) {
|
|
173
|
+
if (x && ((x.$class === "".concat(markdown_common_1.TemplateMarkModel.NAMESPACE, ".ConditionalDefinition") && x.condition) ||
|
|
174
|
+
("".concat(markdown_common_1.TemplateMarkModel.NAMESPACE, ".ClauseDefinition") && x.condition))) {
|
|
175
|
+
x.functionName = "condition_".concat(this.path.join('_'));
|
|
176
|
+
}
|
|
177
|
+
this.update(x);
|
|
178
|
+
});
|
|
179
|
+
};
|
|
180
|
+
TemplateMarkToTypeScriptCompiler.prototype.compileUserCode = function (templateMark, outputDir) {
|
|
181
|
+
var _this = this;
|
|
182
|
+
var fw = new concerto_util_1.FileWriter(outputDir);
|
|
183
|
+
fw.openFile('usercode.ts');
|
|
184
|
+
fw.writeLine(0, '// generated code, do not modify');
|
|
185
|
+
fw.writeLine(0, '');
|
|
186
|
+
fw.writeLine(0, '// IMPORTS');
|
|
187
|
+
fw.writeLine(0, "import * as TemplateModel from './".concat(this.templateClass.getNamespace(), "';"));
|
|
188
|
+
fw.writeLine(0, 'import dayjs from \'dayjs\';');
|
|
189
|
+
fw.writeLine(0, 'import jp from \'jsonpath\';');
|
|
190
|
+
fw.writeLine(0, '');
|
|
191
|
+
var templateMarkDom = templateMark;
|
|
192
|
+
var functionNodes = (0, traverse_1.default)(templateMarkDom).reduce(function (acc, x) {
|
|
193
|
+
if (x && x.$class === "".concat(markdown_common_1.TemplateMarkModel.NAMESPACE, ".FormulaDefinition")) {
|
|
194
|
+
acc.push({
|
|
195
|
+
name: x.name,
|
|
196
|
+
code: x.code,
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
return acc;
|
|
200
|
+
}, []);
|
|
201
|
+
var conditionalNodes = (0, traverse_1.default)(templateMarkDom).reduce(function (acc, x) {
|
|
202
|
+
if (x && x.$class === "".concat(markdown_common_1.TemplateMarkModel.NAMESPACE, ".ConditionalDefinition") && x.condition) {
|
|
203
|
+
acc.push({
|
|
204
|
+
name: x.functionName,
|
|
205
|
+
code: x.condition,
|
|
206
|
+
});
|
|
207
|
+
}
|
|
208
|
+
return acc;
|
|
209
|
+
}, []);
|
|
210
|
+
var clauseNodes = (0, traverse_1.default)(templateMarkDom).reduce(function (acc, x) {
|
|
211
|
+
if (x && x.$class === "".concat(markdown_common_1.TemplateMarkModel.NAMESPACE, ".ClauseDefinition") && x.condition) {
|
|
212
|
+
acc.push({
|
|
213
|
+
name: x.functionName,
|
|
214
|
+
code: x.condition,
|
|
215
|
+
});
|
|
216
|
+
}
|
|
217
|
+
return acc;
|
|
218
|
+
}, []);
|
|
219
|
+
fw.writeLine(0, '// FORMULAE');
|
|
220
|
+
functionNodes.forEach(function (fun) {
|
|
221
|
+
_this.writeFunction(fw, "".concat(fun.name), 'any', fun.code.contents);
|
|
222
|
+
});
|
|
223
|
+
fw.writeLine(0, '');
|
|
224
|
+
fw.writeLine(0, '// CONDITIONALS');
|
|
225
|
+
conditionalNodes.forEach(function (fun) {
|
|
226
|
+
_this.writeFunction(fw, "".concat(fun.name), 'boolean', fun.code.contents);
|
|
227
|
+
});
|
|
228
|
+
fw.writeLine(0, '');
|
|
229
|
+
fw.writeLine(0, '// CLAUSES');
|
|
230
|
+
clauseNodes.forEach(function (fun) {
|
|
231
|
+
_this.writeFunction(fw, "".concat(fun.name), 'boolean', fun.code.contents);
|
|
232
|
+
});
|
|
233
|
+
fw.writeLine(0, '');
|
|
234
|
+
fw.closeFile();
|
|
235
|
+
};
|
|
236
|
+
return TemplateMarkToTypeScriptCompiler;
|
|
237
|
+
}());
|
|
238
|
+
exports.TemplateMarkToTypeScriptCompiler = TemplateMarkToTypeScriptCompiler;
|
|
239
|
+
//# sourceMappingURL=TemplateMarkToTypeScriptCompiler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TemplateMarkToTypeScriptCompiler.js","sourceRoot":"","sources":["../src/TemplateMarkToTypeScriptCompiler.ts"],"names":[],"mappings":";;;;;;AAAA;;;;;;;;;;;;GAYG;AACH,sDAAgC;AAChC,qCAAoC;AAEpC,kEAAwH;AAExH,8DAA6G;AAC7G,gEAAwD;AACxD,8DAA0D;AAC1D,2DAAwD;AACxD,6CAAyF;AACzF,mCAAuD;AAUvD;;;GAGG;AACH;IAII,0CAAY,YAA0B;QAClC,IAAI,CAAC,YAAY,GAAG,YAAY,CAAC;QACjC,IAAI,CAAC,aAAa,GAAG,IAAA,oCAA2B,EAAC,IAAI,CAAC,YAAY,CAAC,CAAC;IACxE,CAAC;IAED,gEAAqB,GAArB,UAAsB,YAAoB,EAAE,UAAiB,EAAE,IAAY;QACvE,IAAI,MAAM,GAAG,EAAE,CAAC;QAChB,MAAM,IAAI,iBAAiB,CAAC;QAC5B,MAAM,IAAI,0BAAmB,YAAY,kCAAwB,IAAI,CAAC,aAAa,CAAC,OAAO,EAAE,+CAAqC,UAAU,SAAM,CAAC;QACnJ,IAAI,CAAC,aAAa,CAAC,aAAa,EAAE,CAAC,OAAO,CAAC,UAAC,CAAW;YACnD,MAAM,IAAI,mBAAY,CAAC,CAAC,OAAO,EAAE,qBAAW,CAAC,CAAC,OAAO,EAAE,QAAK,CAAC;QACjE,CAAC,CAAC,CAAC;QACH,MAAM,IAAI,KAAK,GAAG,IAAI,CAAC,IAAI,EAAE,GAAG,IAAI,CAAC;QACrC,MAAM,IAAI,KAAK,CAAC;QAChB,MAAM,IAAI,IAAI,CAAC;QAEf,OAAO,MAAM,CAAC;IAClB,CAAC;IAED,wDAAa,GAAb,UAAc,EAAc,EAAE,YAAoB,EAAE,UAAiB,EAAE,IAAY;QAC/E,EAAE,CAAC,SAAS,CAA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AC,CAAC;QACxE,CAAC,CAAC,CAAC;QACH,EAAE,CAAC,SAAS,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;QAEpB,EAAE,CAAC,SAAS,EAAE,CAAC;IACnB,CAAC;IACL,uCAAC;AAAD,CAAC,AA9OD,IA8OC;AA9OY,4EAAgC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
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);
|
|
13
|
+
getTypeScriptFiles(): Record<string, string>;
|
|
14
|
+
getCompilationContext(): string;
|
|
15
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TypeScriptCompilationContext = void 0;
|
|
4
|
+
var concerto_tools_1 = require("@accordproject/concerto-tools");
|
|
5
|
+
var concerto_util_1 = require("@accordproject/concerto-util");
|
|
6
|
+
var 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
|
+
var TypeScriptCompilationContext = /** @class */ (function () {
|
|
15
|
+
function TypeScriptCompilationContext(modelManager) {
|
|
16
|
+
this.modelManager = modelManager;
|
|
17
|
+
this.templateClass = (0, Common_1.getTemplateClassDeclaration)(this.modelManager);
|
|
18
|
+
}
|
|
19
|
+
TypeScriptCompilationContext.prototype.getTypeScriptFiles = function () {
|
|
20
|
+
var result = {};
|
|
21
|
+
var visitor = new concerto_tools_1.CodeGen.TypescriptVisitor();
|
|
22
|
+
var writer = new concerto_util_1.InMemoryWriter();
|
|
23
|
+
var params = {
|
|
24
|
+
fileWriter: writer
|
|
25
|
+
};
|
|
26
|
+
this.modelManager.accept(visitor, params);
|
|
27
|
+
writer.getFilesInMemory().forEach(function (value, key) {
|
|
28
|
+
result[key] = value;
|
|
29
|
+
});
|
|
30
|
+
return result;
|
|
31
|
+
};
|
|
32
|
+
TypeScriptCompilationContext.prototype.getCompilationContext = function () {
|
|
33
|
+
var files = this.getTypeScriptFiles();
|
|
34
|
+
var result = '';
|
|
35
|
+
Object.keys(files).forEach(function (key) {
|
|
36
|
+
var content = files[key];
|
|
37
|
+
result += "\n// @filename: ".concat(key, "\n").concat(content, "\n");
|
|
38
|
+
});
|
|
39
|
+
result += "\n// @filename: code.ts\nimport * as TemplateModel from './".concat(this.templateClass.getNamespace(), "';\nimport dayjs from 'dayjs';\nimport jp from 'jsonpath';\n");
|
|
40
|
+
return result;
|
|
41
|
+
};
|
|
42
|
+
return TypeScriptCompilationContext;
|
|
43
|
+
}());
|
|
44
|
+
exports.TypeScriptCompilationContext = TypeScriptCompilationContext;
|
|
45
|
+
//# sourceMappingURL=TypeScriptCompilationContext.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TypeScriptCompilationContext.js","sourceRoot":"","sources":["../src/TypeScriptCompilationContext.ts"],"names":[],"mappings":";;;AAcA,gEAAwD;AACxD,8DAA8D;AAC9D,mCAAuD;AAEvD;;;;;;GAMG;AACH;IAKI,sCAAY,YAAyB;QACjC,IAAI,CAAC,YAAY,GAAG,YAAY,CAAC;QACjC,IAAI,CAAC,aAAa,GAAG,IAAA,oCAA2B,EAAC,IAAI,CAAC,YAAY,CAAC,CAAC;IACxE,CAAC;IAED,yDAAkB,GAAlB;QACI,IAAM,MAAM,GAAyB,EAAE,CAAC;QAExC,IAAM,OAAO,GAAG,IAAI,wBAAO,CAAC,iBAAiB,EAAE,CAAC;QAChD,IAAM,MAAM,GAAG,IAAI,8BAAc,EAAE,CAAC;QAEpC,IAAM,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,UAAC,KAAK,EAAE,GAAG;YAC1C,MAAM,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;QACxB,CAAC,CAAC,CAAC;QACH,OAAO,MAAM,CAAC;IAClB,CAAC;IAED,4DAAqB,GAArB;QACI,IAAM,KAAK,GAAG,IAAI,CAAC,kBAAkB,EAAE,CAAC;QAExC,IAAI,MAAM,GAAG,EAAE,CAAC;QAEhB,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,OAAO,CAAE,UAAA,GAAG;YAC3B,IAAM,OAAO,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC;YAC3B,MAAM,IAAI,0BACN,GAAG,eACjB,OAAO,OACR,CAAC;QACM,CAAC,CAAC,CAAC;QAEH,MAAM,IAAI,qEAEkB,IAAI,CAAC,aAAa,CAAC,YAAY,EAAE,iEAGpE,CAAC;QACM,OAAO,MAAM,CAAC;IAClB,CAAC;IACL,mCAAC;AAAD,CAAC,AA/CD,IA+CC;AA/CY,oEAA4B"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export declare function peek($data: any[]): any;
|
|
2
|
+
export declare function peekProperty($data: any[], propertyName: string, allowUndefined?: boolean): any;
|
|
3
|
+
export declare function push($data: any[], item: any): number;
|
|
4
|
+
export declare function addChild($data: any[], item: any): void;
|
|
5
|
+
export declare function pop($data: any[]): any;
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.pop = exports.addChild = exports.push = exports.peekProperty = exports.peek = 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
|
+
var DEBUG = false;
|
|
18
|
+
/**
|
|
19
|
+
* These utility functions are used by the typescript code that
|
|
20
|
+
* is generated from TemplateMark. They manage a stack to improve
|
|
21
|
+
* debuggability.
|
|
22
|
+
*/
|
|
23
|
+
function dump(op, $data) {
|
|
24
|
+
if (DEBUG) {
|
|
25
|
+
console.log("".concat(op, ": ").concat(JSON.stringify($data)));
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
function peek($data) {
|
|
29
|
+
if ($data.length <= 0) {
|
|
30
|
+
throw new Error('Empty array');
|
|
31
|
+
}
|
|
32
|
+
var result = $data[$data.length - 1];
|
|
33
|
+
dump('peek', $data);
|
|
34
|
+
return result;
|
|
35
|
+
}
|
|
36
|
+
exports.peek = peek;
|
|
37
|
+
function peekProperty($data, propertyName, allowUndefined) {
|
|
38
|
+
if (allowUndefined === void 0) { allowUndefined = false; }
|
|
39
|
+
var head = peek($data);
|
|
40
|
+
var result = head[propertyName];
|
|
41
|
+
if (!allowUndefined && result === undefined) {
|
|
42
|
+
throw new Error("Undefined property ".concat(propertyName, ". Current stack is ").concat(JSON.stringify($data)));
|
|
43
|
+
}
|
|
44
|
+
return result;
|
|
45
|
+
}
|
|
46
|
+
exports.peekProperty = peekProperty;
|
|
47
|
+
function push($data, item) {
|
|
48
|
+
var result = $data.push(item);
|
|
49
|
+
dump('push', $data);
|
|
50
|
+
return result;
|
|
51
|
+
}
|
|
52
|
+
exports.push = push;
|
|
53
|
+
function addChild($data, item) {
|
|
54
|
+
var node = peek($data);
|
|
55
|
+
node.nodes ? node.nodes.push(item) : node.nodes = [item];
|
|
56
|
+
}
|
|
57
|
+
exports.addChild = addChild;
|
|
58
|
+
function pop($data) {
|
|
59
|
+
if ($data.length <= 0) {
|
|
60
|
+
throw new Error('Empty array');
|
|
61
|
+
}
|
|
62
|
+
var result = $data.pop();
|
|
63
|
+
dump('pop', $data);
|
|
64
|
+
return result;
|
|
65
|
+
}
|
|
66
|
+
exports.pop = pop;
|
|
67
|
+
//# sourceMappingURL=TypeScriptRuntime.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TypeScriptRuntime.js","sourceRoot":"","sources":["../src/TypeScriptRuntime.ts"],"names":[],"mappings":";;;AAAA;;;;;;;;;;;;GAYG;AACH,IAAM,KAAK,GAAG,KAAK,CAAC;AAEpB;;;;GAIG;AAEH,SAAS,IAAI,CAAC,EAAS,EAAE,KAAW;IAChC,IAAG,KAAK,EAAE;QACN,OAAO,CAAC,GAAG,CAAC,UAAG,EAAE,eAAK,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAE,CAAC,CAAC;KAClD;AACL,CAAC;AAED,SAAgB,IAAI,CAAC,KAAW;IAC5B,IAAG,KAAK,CAAC,MAAM,IAAI,CAAC,EAAE;QAClB,MAAM,IAAI,KAAK,CAAC,aAAa,CAAC,CAAC;KAClC;IACD,IAAM,MAAM,GAAG,KAAK,CAAC,KAAK,CAAC,MAAM,GAAC,CAAC,CAAC,CAAC;IACrC,IAAI,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;IACpB,OAAO,MAAM,CAAC;AAClB,CAAC;A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|
+
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);
|
|
13
|
+
compile(typescript: string): TwoSlashReturn;
|
|
14
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
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
|
+
var typescript_1 = __importDefault(require("typescript"));
|
|
21
|
+
var vfs_1 = require("@typescript/vfs");
|
|
22
|
+
var twoslash_1 = require("@typescript/twoslash");
|
|
23
|
+
var fs_extra_1 = require("fs-extra");
|
|
24
|
+
var TypeScriptCompilationContext_1 = require("./TypeScriptCompilationContext");
|
|
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
|
+
var TypeScriptToJavaScriptCompiler = /** @class */ (function () {
|
|
33
|
+
function TypeScriptToJavaScriptCompiler(modelManager) {
|
|
34
|
+
this.context = new TypeScriptCompilationContext_1.TypeScriptCompilationContext(modelManager).getCompilationContext();
|
|
35
|
+
}
|
|
36
|
+
TypeScriptToJavaScriptCompiler.prototype.compile = function (typescript) {
|
|
37
|
+
var fsMap = (0, vfs_1.createDefaultMapFromNodeModules)({
|
|
38
|
+
target: typescript_1.default.ScriptTarget.ES2020,
|
|
39
|
+
});
|
|
40
|
+
fsMap.set('/node_modules/@types/dayjs/index.d.ts', (0, fs_extra_1.readFileSync)('./node_modules/dayjs/index.d.ts', 'utf-8'));
|
|
41
|
+
fsMap.set('/node_modules/@types/jsonpath/index.d.ts', (0, fs_extra_1.readFileSync)('./node_modules/@types/jsonpath/index.d.ts', 'utf-8'));
|
|
42
|
+
var twoSlashCode = "\n".concat(this.context, "\n").concat(typescript, "\n");
|
|
43
|
+
var options = {
|
|
44
|
+
fsMap: fsMap,
|
|
45
|
+
defaultOptions: {
|
|
46
|
+
showEmit: true,
|
|
47
|
+
noErrorValidation: true,
|
|
48
|
+
showEmittedFile: 'code.js'
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
var result = (0, twoslash_1.twoslasher)(twoSlashCode, 'ts', options);
|
|
52
|
+
return result;
|
|
53
|
+
};
|
|
54
|
+
return TypeScriptToJavaScriptCompiler;
|
|
55
|
+
}());
|
|
56
|
+
exports.TypeScriptToJavaScriptCompiler = TypeScriptToJavaScriptCompiler;
|
|
57
|
+
//# sourceMappingURL=TypeScriptToJavaScriptCompiler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TypeScriptToJavaScriptCompiler.js","sourceRoot":"","sources":["../src/TypeScriptToJavaScriptCompiler.ts"],"names":[],"mappings":";;;;;;AAAA;;;;;;;;;;;;GAYG;AACH,0DAA4B;AAC5B,uCAAkE;AAClE,iDAAmF;AACnF,qCAAwC;AAExC,+EAA8E;AAE9E;;;;;;GAMG;AACH;IAGI,wCAAY,YAA0B;QAClC,IAAI,CAAC,OAAO,GAAG,IAAI,2DAA4B,CAAC,YAAY,CAAC,CAAC,qBAAqB,EAAE,CAAC;IAC1F,CAAC;IAED,gDAAO,GAAP,UAAQ,UAAkB;QACtB,IAAM,KAAK,GAAG,IAAA,qCAA+B,EAAC;YAC1C,MAAM,EAAE,oBAAE,CAAC,YAAY,CAAC,MAAM;SACjC,CAAC,CAAC;QAEH,KAAK,CAAC,GAAG,CAAC,uCAAuC,EAAE,IAAA,uBAAY,EAAC,iCAAiC,EAAE,OAAO,CAAC,CAAC,CAAC;QAC7G,KAAK,CAAC,GAAG,CAAC,0CAA0C,EAAE,IAAA,uBAAY,EAAC,2CAA2C,EAAE,OAAO,CAAC,CAAC,CAAC;QAE1H,IAAM,YAAY,GAAE,YAC1B,IAAI,CAAC,OAAO,eACZ,UAAU,OACX,CAAC;QAEM,IAAM,OAAO,GAAoB;YAC7B,KAAK,OAAA;YACL,cAAc,EAAE;gBACZ,QAAQ,EAAE,IAAI;gBACd,iBAAiB,EAAE,IAAI;gBACvB,eAAe,EAAE,SAAS;aAC7B;SACJ,CAAC;QACF,IAAM,MAAM,GAAG,IAAA,qBAAU,EAAC,YAAY,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC;QACvD,OAAO,MAAM,CAAC;IAClB,CAAC;IACL,qCAAC;AAAD,CAAC,AA/BD,IA+BC;AA/BY,wEAA8B"}
|