@accordproject/template-engine 1.0.0 → 1.0.2

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.
Files changed (43) hide show
  1. package/package.json +5 -2
  2. package/.github/workflows/npm-publish.yml +0 -37
  3. package/assets/template-compilation.png +0 -0
  4. package/assets/template-interpreter.png +0 -0
  5. package/src/Common.ts +0 -58
  6. package/src/TemplateMarkInterpreter.ts +0 -420
  7. package/src/TemplateMarkToJavaScriptCompiler.ts +0 -99
  8. package/src/TemplateMarkToTypeScriptCompiler.ts +0 -276
  9. package/src/TypeScriptCompilationContext.ts +0 -73
  10. package/src/TypeScriptRuntime.ts +0 -64
  11. package/src/TypeScriptToJavaScriptCompiler.ts +0 -59
  12. package/src/compilers/Clause.ts +0 -63
  13. package/src/compilers/Common.ts +0 -215
  14. package/src/compilers/Conditional.ts +0 -53
  15. package/src/compilers/ContractDefinition.ts +0 -31
  16. package/src/compilers/FormattedVariable.ts +0 -41
  17. package/src/compilers/Formula.ts +0 -36
  18. package/src/compilers/Join.ts +0 -33
  19. package/src/compilers/ListBlock.ts +0 -55
  20. package/src/compilers/NodeCompilers.ts +0 -90
  21. package/src/compilers/Optional.ts +0 -65
  22. package/src/compilers/Variable.ts +0 -40
  23. package/src/compilers/With.ts +0 -37
  24. package/src/drafting/Boolean/index.ts +0 -26
  25. package/src/drafting/DateTime/index.ts +0 -28
  26. package/src/drafting/Double/format.ts +0 -50
  27. package/src/drafting/Double/index.ts +0 -30
  28. package/src/drafting/Integer/format.ts +0 -41
  29. package/src/drafting/Integer/index.ts +0 -32
  30. package/src/drafting/Long/index.ts +0 -30
  31. package/src/drafting/MonetaryAmount/currencycode.ts +0 -49
  32. package/src/drafting/MonetaryAmount/index.ts +0 -73
  33. package/src/drafting/String/index.ts +0 -22
  34. package/src/drafting/index.ts +0 -31
  35. package/src/index.ts +0 -15
  36. package/src/markdown-common.d.ts +0 -14
  37. package/src/model-gen/concerto.metamodel@1.0.0.ts +0 -267
  38. package/src/model-gen/concerto@1.0.0.ts +0 -71
  39. package/src/model-gen/org.accordproject.ciceromark@0.6.0.ts +0 -82
  40. package/src/model-gen/org.accordproject.commonmark@0.5.0.ts +0 -159
  41. package/src/model-gen/org.accordproject.templatemark@0.4.0.ts +0 -119
  42. package/tsconfig.build.json +0 -4
  43. package/tsconfig.json +0 -101
@@ -1,37 +0,0 @@
1
- /*
2
- * Licensed under the Apache License, Version 2.0 (the "License");
3
- * you may not use this file except in compliance with the License.
4
- * You may obtain a copy of the License at
5
- *
6
- * http://www.apache.org/licenses/LICENSE-2.0
7
- *
8
- * Unless required by applicable law or agreed to in writing, software
9
- * distributed under the License is distributed on an "AS IS" BASIS,
10
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
- * See the License for the specific language governing permissions and
12
- * limitations under the License.
13
- */
14
- import { FileWriter } from '@accordproject/concerto-util';
15
- import { TemplateMarkModel } from '@accordproject/markdown-common';
16
- import { IWithDefinition } from '../model-gen/org.accordproject.templatemark@0.4.0';
17
- import { AbstractComplexCompiler, writeCloseDataScope, writeDebug, writeOpenDataScope } from './Common';
18
-
19
- export class With extends AbstractComplexCompiler {
20
- static TYPE = `${TemplateMarkModel.NAMESPACE}.WithDefinition`;
21
- constructor() {
22
- super(false);
23
- }
24
-
25
- enter(fw:FileWriter, level:number,templateMarkNode:IWithDefinition) {
26
- writeDebug(fw, level, templateMarkNode);
27
- writeOpenDataScope(fw,level,templateMarkNode.name);
28
- }
29
-
30
- // eslint-disable-next-line @typescript-eslint/no-unused-vars, @typescript-eslint/no-empty-function
31
- generate(fw:FileWriter, level:number, templateMarkNode:IWithDefinition) {
32
- }
33
-
34
- exit(fw:FileWriter, level:number) {
35
- writeCloseDataScope(fw,level);
36
- }
37
- }
@@ -1,26 +0,0 @@
1
- /*
2
- * Licensed under the Apache License, Version 2.0 (the "License");
3
- * you may not use this file except in compliance with the License.
4
- * You may obtain a copy of the License at
5
- *
6
- * http://www.apache.org/licenses/LICENSE-2.0
7
- *
8
- * Unless required by applicable law or agreed to in writing, software
9
- * distributed under the License is distributed on an "AS IS" BASIS,
10
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
- * See the License for the specific language governing permissions and
12
- * limitations under the License.
13
- */
14
-
15
- /**
16
- * Creates a drafter for Boolean
17
- * @param {Boolean} value the Boolean
18
- * @returns {string} the text
19
- */
20
- export default function booleanDrafter(value:boolean) : string {
21
- if (value) {
22
- return 'true';
23
- } else {
24
- return 'false';
25
- }
26
- }
@@ -1,28 +0,0 @@
1
- /*
2
- * Licensed under the Apache License, Version 2.0 (the "License");
3
- * you may not use this file except in compliance with the License.
4
- * You may obtain a copy of the License at
5
- *
6
- * http://www.apache.org/licenses/LICENSE-2.0
7
- *
8
- * Unless required by applicable law or agreed to in writing, software
9
- * distributed under the License is distributed on an "AS IS" BASIS,
10
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
- * See the License for the specific language governing permissions and
12
- * limitations under the License.
13
- */
14
-
15
- import dayjs from 'dayjs';
16
- import utc from 'dayjs/plugin/utc';
17
- dayjs.extend(utc);
18
-
19
- /**
20
- * Creates a drafter for DateTime
21
- * @param {string} value the DateTime
22
- * @param {object} format the the format
23
- * @returns {string} the text
24
- */
25
- export default function dateTimeDrafter(value:string,format:string) : string {
26
- const f = format ? format : 'MM/DD/YYYY';
27
- return dayjs.utc(value).format(f);
28
- }
@@ -1,50 +0,0 @@
1
- /*
2
- * Licensed under the Apache License, Version 2.0 (the "License");
3
- * you may not use this file except in compliance with the License.
4
- * You may obtain a copy of the License at
5
- *
6
- * http://www.apache.org/licenses/LICENSE-2.0
7
- *
8
- * Unless required by applicable law or agreed to in writing, software
9
- * distributed under the License is distributed on an "AS IS" BASIS,
10
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
- * See the License for the specific language governing permissions and
12
- * limitations under the License.
13
- */
14
-
15
- /**
16
- * Creates a drafter for Double
17
- * @param {number} value - the double
18
- * @returns {string} the text
19
- */
20
- export function draftDoubleIEEE(value:number) : string {
21
- if (Math.floor(value) === value) {
22
- return (new Number(value)).toFixed(1); // Make sure there is always decimal point
23
- } else {
24
- return '' + value;
25
- }
26
- }
27
-
28
- /**
29
- * Creates a drafter for a formatted Double
30
- * @param {number} value - the Double
31
- * @param {string} format - the format
32
- * @returns {object} the parser
33
- */
34
- export function draftDoubleFormat(value:number,format:string) : string {
35
- return format.replace(/0(.)0((.)(0+))?/gi, function(_a,sep1,_b,sep2,digits){
36
- const len = digits ? digits.length : 0;
37
- const vs = value.toFixed(len);
38
- let res = '';
39
- if (sep2) {
40
- const d = vs.substring(vs.length - len);
41
- res += sep2 + d;
42
- }
43
- let i = vs.substring(0,vs.length - (len === 0 ? 0 : len+1));
44
- while (i.length > 3) {
45
- res = sep1 + i.substring(i.length - 3) + res;
46
- i = i.substring(0, i.length - 3);
47
- }
48
- return i + res;
49
- });
50
- }
@@ -1,30 +0,0 @@
1
- /*
2
- * Licensed under the Apache License, Version 2.0 (the "License");
3
- * you may not use this file except in compliance with the License.
4
- * You may obtain a copy of the License at
5
- *
6
- * http://www.apache.org/licenses/LICENSE-2.0
7
- *
8
- * Unless required by applicable law or agreed to in writing, software
9
- * distributed under the License is distributed on an "AS IS" BASIS,
10
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
- * See the License for the specific language governing permissions and
12
- * limitations under the License.
13
- */
14
-
15
- import { draftDoubleIEEE } from './format';
16
- import { draftDoubleFormat } from './format';
17
-
18
- /**
19
- * Creates a drafter for a double
20
- * @param {number} value - the Double
21
- * @param {string} format - the format
22
- * @returns {string} the text
23
- */
24
- export default function doubleDrafter(value:number,format:string) : string {
25
- if (format) {
26
- return draftDoubleFormat(value,format);
27
- } else {
28
- return draftDoubleIEEE(value);
29
- }
30
- }
@@ -1,41 +0,0 @@
1
- /*
2
- * Licensed under the Apache License, Version 2.0 (the "License");
3
- * you may not use this file except in compliance with the License.
4
- * You may obtain a copy of the License at
5
- *
6
- * http://www.apache.org/licenses/LICENSE-2.0
7
- *
8
- * Unless required by applicable law or agreed to in writing, software
9
- * distributed under the License is distributed on an "AS IS" BASIS,
10
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
- * See the License for the specific language governing permissions and
12
- * limitations under the License.
13
- */
14
-
15
- /**
16
- * Creates a drafter for Integer
17
- * @param {number} value - the integer
18
- * @returns {string} the text
19
- */
20
- export function draftInteger(value:number) : string {
21
- return '' + value;
22
- }
23
-
24
- /**
25
- * Creates a drafter for a formatted Integer
26
- * @param {number} value - the Integer
27
- * @param {string} format - the format
28
- * @returns {object} the parser
29
- */
30
- export function draftIntegerFormat(value:number,format:string) : string {
31
- return format.replace(/0(.)0/gi, function(_a,sep1){
32
- const vs = value.toFixed(0);
33
- let res = '';
34
- let i = vs.substring(0,vs.length);
35
- while (i.length > 3) {
36
- res = sep1 + i.substring(i.length - 3) + res;
37
- i = i.substring(0, i.length - 3);
38
- }
39
- return i + res;
40
- });
41
- }
@@ -1,32 +0,0 @@
1
- /*
2
- * Licensed under the Apache License, Version 2.0 (the "License");
3
- * you may not use this file except in compliance with the License.
4
- * You may obtain a copy of the License at
5
- *
6
- * http://www.apache.org/licenses/LICENSE-2.0
7
- *
8
- * Unless required by applicable law or agreed to in writing, software
9
- * distributed under the License is distributed on an "AS IS" BASIS,
10
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
- * See the License for the specific language governing permissions and
12
- * limitations under the License.
13
- */
14
-
15
- 'use strict';
16
-
17
- import { draftInteger } from './format';
18
- import { draftIntegerFormat } from './format';
19
-
20
- /**
21
- * Creates a drafter for an Integer
22
- * @param {number} value - the integer
23
- * @param {string} format - the format
24
- * @returns {string} the text
25
- */
26
- export default function integerDrafter(value:number,format:string) : string {
27
- if (format) {
28
- return draftIntegerFormat(value,format);
29
- } else {
30
- return draftInteger(value);
31
- }
32
- }
@@ -1,30 +0,0 @@
1
- /*
2
- * Licensed under the Apache License, Version 2.0 (the "License");
3
- * you may not use this file except in compliance with the License.
4
- * You may obtain a copy of the License at
5
- *
6
- * http://www.apache.org/licenses/LICENSE-2.0
7
- *
8
- * Unless required by applicable law or agreed to in writing, software
9
- * distributed under the License is distributed on an "AS IS" BASIS,
10
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
- * See the License for the specific language governing permissions and
12
- * limitations under the License.
13
- */
14
-
15
- import { draftInteger as draftLong } from '../Integer/format';
16
- import { draftIntegerFormat as draftLongFormat } from '../Integer/format';
17
-
18
- /**
19
- * Creates a drafter for a long
20
- * @param {number} value - the Long
21
- * @param {string} format - the format
22
- * @returns {string} the text
23
- */
24
- export default function longDrafter(value:number,format:string) : string {
25
- if (format) {
26
- return draftLongFormat(value,format);
27
- } else {
28
- return draftLong(value);
29
- }
30
- }
@@ -1,49 +0,0 @@
1
- /*
2
- * Licensed under the Apache License, Version 2.0 (the "License");
3
- * you may not use this file except in compliance with the License.
4
- * You may obtain a copy of the License at
5
- *
6
- * http://www.apache.org/licenses/LICENSE-2.0
7
- *
8
- * Unless required by applicable law or agreed to in writing, software
9
- * distributed under the License is distributed on an "AS IS" BASIS,
10
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
- * See the License for the specific language governing permissions and
12
- * limitations under the License.
13
- */
14
-
15
- export enum CurrencyCode {
16
- 'USD' = '$',
17
- 'EUR'= '€',
18
- 'JPY'= '¥',
19
- 'GBP'= '£',
20
- 'AUD'= 'A$',
21
- 'CAD'= 'C$',
22
- 'CHF'= 'CHF',
23
- 'CNY'= '元',
24
- 'HKD'= 'HK$',
25
- 'NZD'= 'NZ$',
26
- 'KRW'= '₩',
27
- 'SGD'= 'S$',
28
- 'MXN'= 'MEX$',
29
- 'INR'= '₹',
30
- 'RUB'= '₽',
31
- 'ZAR'= 'R',
32
- 'TRY'= '₺',
33
- 'BRL'= 'R$',
34
- 'TWD'= 'NT$',
35
- 'PLN'= 'zł',
36
- 'THB'= '฿',
37
- 'IDR'= 'Rp',
38
- 'HUF'= 'Ft',
39
- 'CZK'= 'Kč',
40
- 'ILS'= '₪',
41
- 'CLP'= 'CLP$',
42
- 'PHP'= '₱',
43
- 'AED'= 'د.إ',
44
- 'COP'= 'COL$',
45
- 'SAR'= '﷼',
46
- 'MYR'= 'RM',
47
- 'RON'= 'L',
48
- 'BGN'= 'лв.'
49
- }
@@ -1,73 +0,0 @@
1
- /*
2
- * Licensed under the Apache License, Version 2.0 (the "License");
3
- * you may not use this file except in compliance with the License.
4
- * You may obtain a copy of the License at
5
- *
6
- * http://www.apache.org/licenses/LICENSE-2.0
7
- *
8
- * Unless required by applicable law or agreed to in writing, software
9
- * distributed under the License is distributed on an "AS IS" BASIS,
10
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
- * See the License for the specific language governing permissions and
12
- * limitations under the License.
13
- */
14
-
15
- import { draftDoubleIEEE } from '../Double/format';
16
- import { draftDoubleFormat } from '../Double/format';
17
- import { CurrencyCode } from './currencycode';
18
-
19
- type MonetaryAmount = {
20
- doubleValue: number;
21
- currencyCode: string;
22
- };
23
-
24
- /**
25
- * Creates a drafter for monetary amount with no format
26
- * @param {object} value the monetary amount
27
- * @returns {string} the text
28
- */
29
- function monetaryAmountDefaultDrafter(value:MonetaryAmount) {
30
- return '' + draftDoubleIEEE(value.doubleValue) + ' ' + value.currencyCode;
31
- }
32
-
33
- /**
34
- * Symbol from a currency code
35
- * @param {string} c - the currency code
36
- * @returns {string} the symbol
37
- */
38
- function codeSymbol(c:string) : string {
39
- const index: number = Object.keys(CurrencyCode).indexOf(c);
40
- if(index >=0) {
41
- return Object.values(CurrencyCode)[index];
42
- }
43
- else {
44
- return c;
45
- }
46
- }
47
-
48
- /**
49
- * Creates a drafter for monetary amount with a given format
50
- * @param {object} value the monetary amount
51
- * @param {string} format the format
52
- * @returns {string} the text
53
- */
54
- function monetaryAmountFormatDrafter(value:MonetaryAmount,format:string) : string {
55
- return draftDoubleFormat(value.doubleValue,
56
- format
57
- .replace(/K/gi,codeSymbol(value.currencyCode))
58
- .replace(/CCC/gi,value.currencyCode));
59
- }
60
-
61
- /**
62
- * Creates a drafter for a monetary amount
63
- * @param {object} value the monetary amount
64
- * @param {string} format the format
65
- * @returns {string} the text
66
- */
67
- export default function monetaryAmountDrafter(value:MonetaryAmount,format:string) : string {
68
- if (format) {
69
- return monetaryAmountFormatDrafter(value,format);
70
- } else {
71
- return monetaryAmountDefaultDrafter(value);
72
- }
73
- }
@@ -1,22 +0,0 @@
1
- /*
2
- * Licensed under the Apache License, Version 2.0 (the "License");
3
- * you may not use this file except in compliance with the License.
4
- * You may obtain a copy of the License at
5
- *
6
- * http://www.apache.org/licenses/LICENSE-2.0
7
- *
8
- * Unless required by applicable law or agreed to in writing, software
9
- * distributed under the License is distributed on an "AS IS" BASIS,
10
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
- * See the License for the specific language governing permissions and
12
- * limitations under the License.
13
- */
14
-
15
- /**
16
- * Creates a drafter for String
17
- * @param {object} value the String
18
- * @returns {string} the text
19
- */
20
- export default function stringDrafter(value:string) : string {
21
- return value;
22
- }
@@ -1,31 +0,0 @@
1
- /*
2
- * Licensed under the Apache License, Version 2.0 (the "License");
3
- * you may not use this file except in compliance with the License.
4
- * You may obtain a copy of the License at
5
- *
6
- * http://www.apache.org/licenses/LICENSE-2.0
7
- *
8
- * Unless required by applicable law or agreed to in writing, software
9
- * distributed under the License is distributed on an "AS IS" BASIS,
10
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
- * See the License for the specific language governing permissions and
12
- * limitations under the License.
13
- */
14
-
15
- import booleanDrafter from './Boolean';
16
- import dateTimeDrafter from './DateTime';
17
- import doubleDrafter from './Double';
18
- import integerDrafter from './Integer';
19
- import longDrafter from './Long';
20
- import monetaryAmountDrafter from './MonetaryAmount';
21
- import stringDrafter from './String';
22
-
23
- export const draftingMap = new Map<string, (value: any, format: string) => string>([
24
- ['Boolean', booleanDrafter],
25
- ['DateTime', dateTimeDrafter],
26
- ['Double', doubleDrafter],
27
- ['Integer', integerDrafter],
28
- ['Long', longDrafter],
29
- ['MonetaryAmount', monetaryAmountDrafter],
30
- ['String', stringDrafter],
31
- ]);
package/src/index.ts DELETED
@@ -1,15 +0,0 @@
1
- /*
2
- * Licensed under the Apache License, Version 2.0 (the "License");
3
- * you may not use this file except in compliance with the License.
4
- * You may obtain a copy of the License at
5
- *
6
- * http://www.apache.org/licenses/LICENSE-2.0
7
- *
8
- * Unless required by applicable law or agreed to in writing, software
9
- * distributed under the License is distributed on an "AS IS" BASIS,
10
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
- * See the License for the specific language governing permissions and
12
- * limitations under the License.
13
- */
14
-
15
- export { TemplateMarkInterpreter } from './TemplateMarkInterpreter';
@@ -1,14 +0,0 @@
1
- /*
2
- * Licensed under the Apache License, Version 2.0 (the "License");
3
- * you may not use this file except in compliance with the License.
4
- * You may obtain a copy of the License at
5
- *
6
- * http://www.apache.org/licenses/LICENSE-2.0
7
- *
8
- * Unless required by applicable law or agreed to in writing, software
9
- * distributed under the License is distributed on an "AS IS" BASIS,
10
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
- * See the License for the specific language governing permissions and
12
- * limitations under the License.
13
- */
14
- declare module '@accordproject/markdown-common'