@accordproject/template-engine 2.0.3 → 2.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (127) hide show
  1. package/dist/index.d.ts +123 -2
  2. package/dist/index.js +1437 -21
  3. package/dist/index.js.map +1 -1
  4. package/dist/index.mjs +1414 -0
  5. package/dist/index.mjs.map +1 -0
  6. package/dist/runtime.tgz +0 -0
  7. package/package.json +7 -3
  8. package/dist/Common.d.ts +0 -20
  9. package/dist/Common.js +0 -55
  10. package/dist/Common.js.map +0 -1
  11. package/dist/TemplateMarkInterpreter.d.ts +0 -34
  12. package/dist/TemplateMarkInterpreter.js +0 -401
  13. package/dist/TemplateMarkInterpreter.js.map +0 -1
  14. package/dist/TemplateMarkToJavaScriptCompiler.d.ts +0 -19
  15. package/dist/TemplateMarkToJavaScriptCompiler.js +0 -96
  16. package/dist/TemplateMarkToJavaScriptCompiler.js.map +0 -1
  17. package/dist/TemplateMarkToTypeScriptCompiler.d.ts +0 -77
  18. package/dist/TemplateMarkToTypeScriptCompiler.js +0 -311
  19. package/dist/TemplateMarkToTypeScriptCompiler.js.map +0 -1
  20. package/dist/TypeScriptCompilationContext.d.ts +0 -15
  21. package/dist/TypeScriptCompilationContext.js +0 -57
  22. package/dist/TypeScriptCompilationContext.js.map +0 -1
  23. package/dist/TypeScriptRuntime.d.ts +0 -14
  24. package/dist/TypeScriptRuntime.js +0 -79
  25. package/dist/TypeScriptRuntime.js.map +0 -1
  26. package/dist/TypeScriptToJavaScriptCompiler.d.ts +0 -14
  27. package/dist/TypeScriptToJavaScriptCompiler.js +0 -59
  28. package/dist/TypeScriptToJavaScriptCompiler.js.map +0 -1
  29. package/dist/compilers/Clause.d.ts +0 -14
  30. package/dist/compilers/Clause.js +0 -43
  31. package/dist/compilers/Clause.js.map +0 -1
  32. package/dist/compilers/Common.d.ts +0 -66
  33. package/dist/compilers/Common.js +0 -180
  34. package/dist/compilers/Common.js.map +0 -1
  35. package/dist/compilers/Conditional.d.ts +0 -12
  36. package/dist/compilers/Conditional.js +0 -36
  37. package/dist/compilers/Conditional.js.map +0 -1
  38. package/dist/compilers/ContractDefinition.d.ts +0 -8
  39. package/dist/compilers/ContractDefinition.js +0 -33
  40. package/dist/compilers/ContractDefinition.js.map +0 -1
  41. package/dist/compilers/EnumVariable.d.ts +0 -8
  42. package/dist/compilers/EnumVariable.js +0 -28
  43. package/dist/compilers/EnumVariable.js.map +0 -1
  44. package/dist/compilers/FormattedVariable.d.ts +0 -8
  45. package/dist/compilers/FormattedVariable.js +0 -29
  46. package/dist/compilers/FormattedVariable.js.map +0 -1
  47. package/dist/compilers/Formula.d.ts +0 -8
  48. package/dist/compilers/Formula.js +0 -24
  49. package/dist/compilers/Formula.js.map +0 -1
  50. package/dist/compilers/Join.d.ts +0 -8
  51. package/dist/compilers/Join.js +0 -23
  52. package/dist/compilers/Join.js.map +0 -1
  53. package/dist/compilers/ListBlock.d.ts +0 -11
  54. package/dist/compilers/ListBlock.js +0 -39
  55. package/dist/compilers/ListBlock.js.map +0 -1
  56. package/dist/compilers/NodeCompilers.d.ts +0 -7
  57. package/dist/compilers/NodeCompilers.js +0 -89
  58. package/dist/compilers/NodeCompilers.js.map +0 -1
  59. package/dist/compilers/Optional.d.ts +0 -11
  60. package/dist/compilers/Optional.js +0 -48
  61. package/dist/compilers/Optional.js.map +0 -1
  62. package/dist/compilers/Variable.d.ts +0 -8
  63. package/dist/compilers/Variable.js +0 -28
  64. package/dist/compilers/Variable.js.map +0 -1
  65. package/dist/compilers/With.d.ts +0 -10
  66. package/dist/compilers/With.js +0 -23
  67. package/dist/compilers/With.js.map +0 -1
  68. package/dist/drafting/Boolean/index.d.ts +0 -6
  69. package/dist/drafting/Boolean/index.js +0 -30
  70. package/dist/drafting/Boolean/index.js.map +0 -1
  71. package/dist/drafting/DateTime/index.d.ts +0 -7
  72. package/dist/drafting/DateTime/index.js +0 -33
  73. package/dist/drafting/DateTime/index.js.map +0 -1
  74. package/dist/drafting/Double/format.d.ts +0 -13
  75. package/dist/drafting/Double/format.js +0 -55
  76. package/dist/drafting/Double/format.js.map +0 -1
  77. package/dist/drafting/Double/index.d.ts +0 -7
  78. package/dist/drafting/Double/index.js +0 -33
  79. package/dist/drafting/Double/index.js.map +0 -1
  80. package/dist/drafting/Integer/format.d.ts +0 -13
  81. package/dist/drafting/Integer/format.js +0 -45
  82. package/dist/drafting/Integer/format.js.map +0 -1
  83. package/dist/drafting/Integer/index.d.ts +0 -7
  84. package/dist/drafting/Integer/index.js +0 -33
  85. package/dist/drafting/Integer/index.js.map +0 -1
  86. package/dist/drafting/Long/index.d.ts +0 -7
  87. package/dist/drafting/Long/index.js +0 -33
  88. package/dist/drafting/Long/index.js.map +0 -1
  89. package/dist/drafting/MonetaryAmount/currencycode.d.ts +0 -35
  90. package/dist/drafting/MonetaryAmount/currencycode.js +0 -53
  91. package/dist/drafting/MonetaryAmount/currencycode.js.map +0 -1
  92. package/dist/drafting/MonetaryAmount/index.d.ts +0 -12
  93. package/dist/drafting/MonetaryAmount/index.js +0 -67
  94. package/dist/drafting/MonetaryAmount/index.js.map +0 -1
  95. package/dist/drafting/String/index.d.ts +0 -6
  96. package/dist/drafting/String/index.js +0 -25
  97. package/dist/drafting/String/index.js.map +0 -1
  98. package/dist/drafting/index.d.ts +0 -1
  99. package/dist/drafting/index.js +0 -40
  100. package/dist/drafting/index.js.map +0 -1
  101. package/dist/model-gen/concerto.d.ts +0 -13
  102. package/dist/model-gen/concerto.js +0 -5
  103. package/dist/model-gen/concerto.js.map +0 -1
  104. package/dist/model-gen/concerto.metamodel@1.0.0.d.ts +0 -196
  105. package/dist/model-gen/concerto.metamodel@1.0.0.js +0 -5
  106. package/dist/model-gen/concerto.metamodel@1.0.0.js.map +0 -1
  107. package/dist/model-gen/concerto@1.0.0.d.ts +0 -19
  108. package/dist/model-gen/concerto@1.0.0.js +0 -5
  109. package/dist/model-gen/concerto@1.0.0.js.map +0 -1
  110. package/dist/model-gen/org.accordproject.ciceromark@0.6.0.d.ts +0 -49
  111. package/dist/model-gen/org.accordproject.ciceromark@0.6.0.js +0 -5
  112. package/dist/model-gen/org.accordproject.ciceromark@0.6.0.js.map +0 -1
  113. package/dist/model-gen/org.accordproject.commonmark@0.5.0.d.ts +0 -89
  114. package/dist/model-gen/org.accordproject.commonmark@0.5.0.js +0 -5
  115. package/dist/model-gen/org.accordproject.commonmark@0.5.0.js.map +0 -1
  116. package/dist/model-gen/org.accordproject.templatemark@0.5.0.d.ts +0 -76
  117. package/dist/model-gen/org.accordproject.templatemark@0.5.0.js +0 -12
  118. package/dist/model-gen/org.accordproject.templatemark@0.5.0.js.map +0 -1
  119. package/dist/runtime/declarations.d.ts +0 -2
  120. package/dist/runtime/declarations.js +0 -21
  121. package/dist/runtime/declarations.js.map +0 -1
  122. package/dist/runtime/runtime.d.ts +0 -1
  123. package/dist/runtime/runtime.js +0 -20
  124. package/dist/runtime/runtime.js.map +0 -1
  125. package/dist/utils.d.ts +0 -5
  126. package/dist/utils.js +0 -43
  127. package/dist/utils.js.map +0 -1
package/dist/index.d.ts CHANGED
@@ -1,2 +1,123 @@
1
- export { TemplateMarkInterpreter } from './TemplateMarkInterpreter';
2
- export { TemplateMarkToTypeScriptCompiler } from './TemplateMarkToTypeScriptCompiler';
1
+ import * as _accordproject_concerto_core_types_lib_model_resource from '@accordproject/concerto-core/types/lib/model/resource';
2
+ import { ModelManager, ClassDeclaration, Resource } from '@accordproject/concerto-core';
3
+ import { FileWriter } from '@accordproject/concerto-util';
4
+
5
+ type TemplateData = Record<string, unknown>;
6
+
7
+ /**
8
+ * BEWARE - this type is duplicated in TypeScriptCompilationContext
9
+ * for use by code generation
10
+ */
11
+ type GenerationOptions = {
12
+ now?: string;
13
+ locale?: string;
14
+ };
15
+
16
+ /**
17
+ * A template engine: merges the markup and logic of a template with
18
+ * JSON data to produce JSON data.
19
+ */
20
+ declare class TemplateMarkInterpreter {
21
+ modelManager: ModelManager;
22
+ templateClass: ClassDeclaration;
23
+ clauseLibrary: object;
24
+ constructor(modelManager: ModelManager, clauseLibrary: object, templateConceptFqn?: string);
25
+ /**
26
+ * Checks that a TemplateMark JSON document is valid with respect to the
27
+ * TemplateMark model, as well as the template model.
28
+ *
29
+ * Checks:
30
+ * 1. Variable names are valid properties in the template model
31
+ * 2. Optional properties have guards
32
+ * @param {*} templateMark the TemplateMark JSON object
33
+ * @returns {*} TemplateMark JSON that has been typed checked and has type metadata added
34
+ * @throws {Error} if the templateMark document is invalid
35
+ */
36
+ checkTypes(templateMark: object): object;
37
+ /**
38
+ * Compiles the code nodes containing TS to code nodes containing JS.
39
+ * @param {*} templateMark the TemplateMark JSON object
40
+ * @returns {*} TemplateMark JSON with JS nodes
41
+ * @throws {Error} if the templateMark document is invalid
42
+ */
43
+ compileTypeScriptToJavaScript(templateMark: object): Promise<object>;
44
+ validateCiceroMark(ciceroMark: object): _accordproject_concerto_core_types_lib_model_resource;
45
+ generate(templateMark: object, data: TemplateData, options?: GenerationOptions): Promise<any>;
46
+ }
47
+
48
+ type CompilationOptions = {
49
+ skipGenerator?: boolean;
50
+ skipCopyRuntime?: boolean;
51
+ };
52
+ /**
53
+ * Converts TemplateMark DOM to a Typescript function, that, when run with JSON data
54
+ * that conforms to the template model will produce AgreementMark JSON output.
55
+ */
56
+ declare class TemplateMarkToTypeScriptCompiler {
57
+ modelManager: ModelManager;
58
+ templateClass: ClassDeclaration;
59
+ constructor(modelManager: ModelManager, templateConceptFqn?: string);
60
+ writeFunction(fw: FileWriter, functionName: string, returnType: string, code: string): void;
61
+ /**
62
+ * Get a model manager with templatemark model
63
+ * @param {string} outputDir the output directory
64
+ * @returns {ModelManager} the model manager
65
+ */
66
+ getTemplateMarkModelManager(): ModelManager;
67
+ /**
68
+ * Get a model manager with templatemark model
69
+ * @param {string} outputDir the output directory
70
+ * @returns {ModelManager} the model manager
71
+ */
72
+ getCiceroMarkModelManager(): ModelManager;
73
+ generateTypeScript(modelManager: ModelManager, outputDir: string): void;
74
+ generateSampleData(modelManager: ModelManager, outputDir: string): void;
75
+ /**
76
+ * The main iteration function over templatemark. This function
77
+ * looks up an INodeCompiler that can handle each templatemark node
78
+ * and delegates to it for code generation.
79
+ * Note that the result of code generation (a CiceroMark node) is left in
80
+ * the $result global varianble.
81
+ * @param {FileWriter} fw the file writer to use
82
+ * @param {number} level the indentation level
83
+ * @param {object} templateMark the templatemark node to iterate over
84
+ */
85
+ static doIt(fw: FileWriter, level: number, templateMark: any): void;
86
+ /**
87
+ * Converts a TemplateMark document to typescript code that is parameterised
88
+ * by the 'data' argument.
89
+ *
90
+ * The strategy is to traverse the template mark json, converting each node into
91
+ * typescript statements that add an equivalent ciceromark node. Variables will
92
+ * pull values from 'data'.
93
+ *
94
+ * Conditionals and formulae will call the functions produced by
95
+ * compileUserCode.
96
+ *
97
+ * Note that code generation process is itself recursive, for example, when
98
+ * a list definition node is encountered the list must be iterated over
99
+ * based on a variable value coming from data, and code must be
100
+ * generated to produce each list item.
101
+ *
102
+ * All internal variables are prefixed with '$' to ensure (?)
103
+ * that they cannot collide with end user variable names.
104
+ *
105
+ * @param {IDocument} templateMark the TemplateMark Concerto resource
106
+ * @param {string} outputDir the output directory for code
107
+ */
108
+ compileGenerator(templateMark: any, outputDir: string): void;
109
+ /**
110
+ * Decompresses the base64 zipped runtime into an output folder.
111
+ * @param {string} outputDir the output directory to copy the runtime to
112
+ */
113
+ copyRuntime(outputDir: string): void;
114
+ /**
115
+ * Create package.json for the generated code
116
+ * @param {string} outputDir the output directory to copy the runtime to
117
+ */
118
+ createPackage(outputDir: string): void;
119
+ compile(templateMark: Resource | any, outputDir: string, options?: CompilationOptions): void;
120
+ compileUserCode(templateMark: any, outputDir: string): void;
121
+ }
122
+
123
+ export { TemplateMarkInterpreter, TemplateMarkToTypeScriptCompiler };