@platforma-sdk/tengo-builder 2.4.25 → 2.4.26

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 (106) hide show
  1. package/dist/_virtual/_rolldown/runtime.cjs +29 -0
  2. package/dist/commands/build.cjs +106 -150
  3. package/dist/commands/build.cjs.map +1 -1
  4. package/dist/commands/build.d.ts +15 -10
  5. package/dist/commands/build.js +101 -126
  6. package/dist/commands/build.js.map +1 -1
  7. package/dist/commands/check.cjs +32 -36
  8. package/dist/commands/check.cjs.map +1 -1
  9. package/dist/commands/check.d.ts +13 -8
  10. package/dist/commands/check.js +30 -33
  11. package/dist/commands/check.js.map +1 -1
  12. package/dist/commands/dump/artifacts.cjs +22 -22
  13. package/dist/commands/dump/artifacts.cjs.map +1 -1
  14. package/dist/commands/dump/artifacts.d.ts +13 -8
  15. package/dist/commands/dump/artifacts.js +20 -19
  16. package/dist/commands/dump/artifacts.js.map +1 -1
  17. package/dist/commands/dump/software.cjs +19 -21
  18. package/dist/commands/dump/software.cjs.map +1 -1
  19. package/dist/commands/dump/software.d.ts +12 -7
  20. package/dist/commands/dump/software.js +17 -18
  21. package/dist/commands/dump/software.js.map +1 -1
  22. package/dist/commands/test.cjs +32 -33
  23. package/dist/commands/test.cjs.map +1 -1
  24. package/dist/commands/test.d.ts +13 -8
  25. package/dist/commands/test.js +30 -30
  26. package/dist/commands/test.js.map +1 -1
  27. package/dist/compiler/artifactset.cjs +59 -68
  28. package/dist/compiler/artifactset.cjs.map +1 -1
  29. package/dist/compiler/artifactset.js +60 -66
  30. package/dist/compiler/artifactset.js.map +1 -1
  31. package/dist/compiler/compiler.cjs +241 -314
  32. package/dist/compiler/compiler.cjs.map +1 -1
  33. package/dist/compiler/compiler.js +241 -312
  34. package/dist/compiler/compiler.js.map +1 -1
  35. package/dist/compiler/compileroptions.cjs +16 -35
  36. package/dist/compiler/compileroptions.cjs.map +1 -1
  37. package/dist/compiler/compileroptions.js +17 -33
  38. package/dist/compiler/compileroptions.js.map +1 -1
  39. package/dist/compiler/main.cjs +258 -334
  40. package/dist/compiler/main.cjs.map +1 -1
  41. package/dist/compiler/main.js +256 -311
  42. package/dist/compiler/main.js.map +1 -1
  43. package/dist/compiler/package.cjs +21 -35
  44. package/dist/compiler/package.cjs.map +1 -1
  45. package/dist/compiler/package.js +21 -34
  46. package/dist/compiler/package.js.map +1 -1
  47. package/dist/compiler/source.cjs +239 -308
  48. package/dist/compiler/source.cjs.map +1 -1
  49. package/dist/compiler/source.js +239 -304
  50. package/dist/compiler/source.js.map +1 -1
  51. package/dist/compiler/template.cjs +30 -35
  52. package/dist/compiler/template.cjs.map +1 -1
  53. package/dist/compiler/template.js +29 -33
  54. package/dist/compiler/template.js.map +1 -1
  55. package/dist/compiler/util.cjs +40 -61
  56. package/dist/compiler/util.cjs.map +1 -1
  57. package/dist/compiler/util.js +36 -39
  58. package/dist/compiler/util.js.map +1 -1
  59. package/dist/index.cjs +14 -14
  60. package/dist/index.cjs.map +1 -1
  61. package/dist/index.d.ts +15 -11
  62. package/dist/index.js +13 -12
  63. package/dist/index.js.map +1 -1
  64. package/dist/shared/basecmd.cjs +42 -33
  65. package/dist/shared/basecmd.cjs.map +1 -1
  66. package/dist/shared/basecmd.js +41 -31
  67. package/dist/shared/basecmd.js.map +1 -1
  68. package/dist/shared/dump.cjs +73 -107
  69. package/dist/shared/dump.cjs.map +1 -1
  70. package/dist/shared/dump.js +73 -105
  71. package/dist/shared/dump.js.map +1 -1
  72. package/dist/shared/proc.cjs +22 -18
  73. package/dist/shared/proc.cjs.map +1 -1
  74. package/dist/shared/proc.js +21 -16
  75. package/dist/shared/proc.js.map +1 -1
  76. package/package.json +8 -8
  77. package/dist/commands/build.d.ts.map +0 -1
  78. package/dist/commands/check.d.ts.map +0 -1
  79. package/dist/commands/dump/artifacts.d.ts.map +0 -1
  80. package/dist/commands/dump/software.d.ts.map +0 -1
  81. package/dist/commands/test.d.ts.map +0 -1
  82. package/dist/compiler/artifactset.d.ts +0 -24
  83. package/dist/compiler/artifactset.d.ts.map +0 -1
  84. package/dist/compiler/compiler.d.ts +0 -42
  85. package/dist/compiler/compiler.d.ts.map +0 -1
  86. package/dist/compiler/compileroptions.d.ts +0 -6
  87. package/dist/compiler/compileroptions.d.ts.map +0 -1
  88. package/dist/compiler/main.d.ts +0 -35
  89. package/dist/compiler/main.d.ts.map +0 -1
  90. package/dist/compiler/package.d.ts +0 -44
  91. package/dist/compiler/package.d.ts.map +0 -1
  92. package/dist/compiler/source.d.ts +0 -54
  93. package/dist/compiler/source.d.ts.map +0 -1
  94. package/dist/compiler/template.d.ts +0 -22
  95. package/dist/compiler/template.d.ts.map +0 -1
  96. package/dist/compiler/test.artifacts.d.ts +0 -47
  97. package/dist/compiler/test.artifacts.d.ts.map +0 -1
  98. package/dist/compiler/util.d.ts +0 -8
  99. package/dist/compiler/util.d.ts.map +0 -1
  100. package/dist/index.d.ts.map +0 -1
  101. package/dist/shared/basecmd.d.ts +0 -12
  102. package/dist/shared/basecmd.d.ts.map +0 -1
  103. package/dist/shared/dump.d.ts +0 -6
  104. package/dist/shared/dump.d.ts.map +0 -1
  105. package/dist/shared/proc.d.ts +0 -5
  106. package/dist/shared/proc.d.ts.map +0 -1
@@ -1,315 +1,244 @@
1
- import { newTemplateWithSource } from './template.js';
2
- import { typedArtifactNameToString, artifactNameToString, typedArtifactNamesEquals, formatArtefactNameAndVersion, fullNameEquals, fullNameToString } from './package.js';
3
- import { ArtifactStore } from './artifactset.js';
4
- import { assertNever } from './util.js';
5
- import { applyLibraryCompilerOptions, applyTemplateCompilerOptions } from './compileroptions.js';
1
+ import { assertNever } from "./util.js";
2
+ import { artifactNameToString, formatArtefactNameAndVersion, fullNameEquals, fullNameToString, typedArtifactNameToString, typedArtifactNamesEquals } from "./package.js";
3
+ import { newTemplateWithSource } from "./template.js";
4
+ import { ArtifactStore } from "./artifactset.js";
5
+ import { applyLibraryCompilerOptions, applyTemplateCompilerOptions } from "./compileroptions.js";
6
6
 
7
- class TengoTemplateCompiler {
8
- compileMode;
9
- libs = new ArtifactStore((src) => src.fullName);
10
- software = new ArtifactStore((src) => src.fullName);
11
- assets = new ArtifactStore((src) => src.fullName);
12
- templates = new ArtifactStore((tpl) => tpl.fullName);
13
- constructor(compileMode) {
14
- this.compileMode = compileMode;
15
- }
16
- /** Recursively add dependencies to the template. */
17
- populateTemplateDataFromDependencies(fullName, data, deps, trace) {
18
- for (const dep of deps) {
19
- switch (dep.type) {
20
- case "library": {
21
- const lib = this.getLibOrError(dep);
22
- const recursionStart = trace.indexOf(artifactNameToString(dep));
23
- if (recursionStart >= 0) {
24
- const errorMessage = `library import recursion detected: ` +
25
- `${trace.slice(recursionStart).join(" -> ")} -> ${artifactNameToString(dep)}`;
26
- throw new Error(errorMessage);
27
- }
28
- const tplLib = {
29
- ...formatArtefactNameAndVersion(lib.fullName),
30
- sourceHash: lib.sourceHash,
31
- };
32
- applyLibraryCompilerOptions(lib.compilerOptions);
33
- data.template.libs[artifactNameToString(dep)] = tplLib;
34
- data.hashToSource[tplLib.sourceHash] = lib.src;
35
- // populate with transient library dependencies
36
- this.populateTemplateDataFromDependencies(fullName, data, lib.dependencies, [
37
- ...trace,
38
- artifactNameToString(dep),
39
- ]);
40
- break;
41
- }
42
- case "software": {
43
- const software = this.getSoftwareOrError(dep);
44
- data.template.software[artifactNameToString(dep)] = {
45
- ...formatArtefactNameAndVersion(software.fullName),
46
- sourceHash: software.sourceHash,
47
- };
48
- data.hashToSource[software.sourceHash] = software.src;
49
- break;
50
- }
51
- case "asset": {
52
- const asset = this.getAssetOrError(dep);
53
- // Yes, we temporarily put assets into 'software' section of template, so controller can
54
- // handle it the right way without updates
55
- data.template.software[artifactNameToString(dep)] = {
56
- ...formatArtefactNameAndVersion(asset.fullName),
57
- sourceHash: asset.sourceHash,
58
- };
59
- data.hashToSource[asset.sourceHash] = asset.src;
60
- break;
61
- }
62
- case "template": {
63
- if (typedArtifactNamesEquals(fullName, dep))
64
- // skipping self reference
65
- continue;
66
- const tpl = this.getTemplateOrError(dep);
67
- data.template.templates[artifactNameToString(dep)] = tpl.data.template;
68
- data.hashToSource[tpl.data.template.sourceHash] = tpl.source;
69
- // add all the sources of transitivedependencies to the resulted hashToSource
70
- for (const [hash, src] of Object.entries(tpl.data.hashToSource)) {
71
- data.hashToSource[hash] = src;
72
- }
73
- break;
74
- }
75
- case "test":
76
- throw new Error(`dependencies tree error: tests should never be part of template: ` +
77
- `${typedArtifactNameToString(dep)} is dependency of ${artifactNameToString(fullName)}`);
78
- default:
79
- assertNever(dep.type);
80
- }
81
- }
82
- }
83
- /** This method assumes that all dependencies are already added to the compiler's context */
84
- compileAndAddTemplate(tplSrc) {
85
- if (tplSrc.fullName.type !== "template")
86
- throw new Error("unexpected source type");
87
- // creating template with unpopulated dependencies
88
- const tplData = {
89
- type: "pl.tengo-template.v3",
90
- hashToSource: {
91
- [tplSrc.sourceHash]: tplSrc.src,
92
- },
93
- template: {
94
- ...formatArtefactNameAndVersion(tplSrc.fullName),
95
- templates: {},
96
- libs: {},
97
- software: {},
98
- assets: {},
99
- sourceHash: tplSrc.sourceHash,
100
- },
101
- };
102
- applyTemplateCompilerOptions(tplSrc.compilerOptions, tplData.template);
103
- // collecting dependencies in output format
104
- this.populateTemplateDataFromDependencies(tplSrc.fullName, tplData, tplSrc.dependencies, []);
105
- return tplData;
106
- }
107
- addLib(lib) {
108
- const libFromMap = this.libs.add(lib.compileMode, lib, false);
109
- if (libFromMap && !fullNameEquals(lib.fullName, libFromMap.fullName))
110
- throw new Error(`compiler already contain such library: adding = ${fullNameToString(lib.fullName)}, contains = ${fullNameToString(libFromMap.fullName)}`);
111
- }
112
- allLibs() {
113
- return this.libs.array(this.compileMode);
114
- }
115
- getLib(name) {
116
- if (name.type !== "library")
117
- throw new Error(`illegal artifact type: got ${name.type} instead of 'library`);
118
- return this.libs.get(this.compileMode, name);
119
- }
120
- getLibOrError(name) {
121
- const lib = this.getLib(name);
122
- if (!lib)
123
- throw new Error(`library not found: ${artifactNameToString(name)}`);
124
- return lib;
125
- }
126
- checkLibs() {
127
- this.libs.forEach(this.compileMode, (lib) => {
128
- for (const dep of lib.dependencies) {
129
- if (dep.type === "test")
130
- throw new Error(`test should never be dependency of production code: ${typedArtifactNameToString(dep)} test is dependency of ${fullNameToString(lib.fullName)}`);
131
- if (!this.getArtefact(dep))
132
- throw new Error(`unresolved dependency ${typedArtifactNameToString(dep)} for ${fullNameToString(lib.fullName)}`);
133
- }
134
- });
135
- }
136
- addSoftware(software) {
137
- const swFromMap = this.software.add(software.compileMode, software, false);
138
- if (swFromMap && !fullNameEquals(software.fullName, swFromMap.fullName))
139
- throw new Error(`compiler already contain info for software: adding = ${fullNameToString(software.fullName)}, contains = ${fullNameToString(swFromMap.fullName)}`);
140
- }
141
- allSoftware() {
142
- return this.software.array(this.compileMode);
143
- }
144
- getSoftware(name) {
145
- if (name.type !== "software")
146
- throw new Error(`illegal artifact type: got ${name.type} instead of 'software`);
147
- return this.software.get(this.compileMode, name);
148
- }
149
- getSoftwareOrError(name) {
150
- const software = this.getSoftware(name);
151
- if (!software)
152
- throw new Error(`software info not found: ${artifactNameToString(name)}`);
153
- return software;
154
- }
155
- addAsset(asset) {
156
- const assetFromMap = this.assets.add(asset.compileMode, asset, false);
157
- if (assetFromMap && !fullNameEquals(asset.fullName, assetFromMap.fullName))
158
- throw new Error(`compiler already contain info for asset: adding = ${fullNameToString(asset.fullName)}, contains = ${fullNameToString(assetFromMap.fullName)}`);
159
- }
160
- allAssets() {
161
- return this.assets.array(this.compileMode);
162
- }
163
- getAsset(name) {
164
- if (name.type !== "asset")
165
- throw new Error(`illegal artifact type: got ${name.type} instead of 'asset`);
166
- return this.assets.get(this.compileMode, name);
167
- }
168
- getAssetOrError(name) {
169
- const asset = this.getAsset(name);
170
- if (!asset)
171
- throw new Error(`asset info not found: ${artifactNameToString(name)}`);
172
- return asset;
173
- }
174
- addTemplate(tpl) {
175
- const tplFromMap = this.templates.add(tpl.compileMode, tpl, false);
176
- if (tplFromMap && !fullNameEquals(tpl.fullName, tplFromMap.fullName))
177
- throw new Error(`compiler already contain such template: adding = ${fullNameToString(tpl.fullName)}, contains = ${fullNameToString(tplFromMap.fullName)}`);
178
- }
179
- allTemplates() {
180
- return this.templates.array(this.compileMode);
181
- }
182
- getTemplate(name) {
183
- if (name.type !== "template")
184
- throw new Error(`illegal artifact type: got ${name.type} instead of 'template`);
185
- return this.templates.get(this.compileMode, name);
186
- }
187
- getTemplateOrError(name) {
188
- const tpl = this.getTemplate(name);
189
- if (!tpl)
190
- throw new Error(`template not found: ${artifactNameToString(name)}`);
191
- return tpl;
192
- }
193
- getArtefact(name) {
194
- switch (name.type) {
195
- case "template":
196
- return this.getTemplate(name);
197
- case "library":
198
- return this.getLib(name);
199
- case "software":
200
- return this.getSoftware(name);
201
- case "asset":
202
- return this.getAsset(name);
203
- case "test":
204
- // Tests are ignored by the complier. They should never be compiled into templates or libs and
205
- // should never be a dependency.
206
- return undefined;
207
- default:
208
- assertNever(name.type);
209
- }
210
- }
211
- compileAndAdd(sources) {
212
- const result = {
213
- templates: [],
214
- libs: [],
215
- software: [],
216
- assets: [],
217
- };
218
- let current = [];
219
- for (const src of sources) {
220
- if (src.fullName.type === "library") {
221
- // add libraries 'as-is' to be able to resolve them as dependencies
222
- this.addLib(src);
223
- result.libs.push(src);
224
- }
225
- else if (src.fullName.type === "software") {
226
- // add software 'as-is' to be able to resolve them as dependencies
227
- this.addSoftware(src);
228
- result.software.push(src);
229
- }
230
- else if (src.fullName.type === "asset") {
231
- // add assets 'as-is' to be able to resolve them as dependencies
232
- this.addAsset(src);
233
- result.assets.push(src);
234
- }
235
- else {
236
- current.push(src);
237
- }
238
- }
239
- while (current.length > 0) {
240
- const unprocessed = [];
241
- for (const src of current) {
242
- //
243
- // If one of the dependencies can't be resolved with current compiler context,
244
- // we put aside the source until next iteration, in hope that the dependency
245
- // will be satisfied then.
246
- //
247
- // This is equivalent to topological sorting of input sources.
248
- //
249
- const unsatisfied = src.dependencies.filter((dep) => !this.getArtefact(dep) &&
250
- // allow self reference for templates
251
- !(src.fullName.type === "template" && typedArtifactNamesEquals(src.fullName, dep)));
252
- if (unsatisfied.length > 0) {
253
- let errorMessage = `Unsatisfied dependencies in ${fullNameToString(src.fullName)}:\n`;
254
- for (const dep of unsatisfied) {
255
- errorMessage += ` - ${typedArtifactNameToString(dep)}\n`;
256
- }
257
- unprocessed.push({ src, err: new Error(errorMessage) });
258
- continue;
259
- }
260
- // type specific processing
261
- switch (src.fullName.type) {
262
- case "library":
263
- // libraries are added as is
264
- this.addLib(src);
265
- result.libs.push(src);
266
- break;
267
- case "software":
268
- // software dependencies are added as is
269
- this.addSoftware(src);
270
- result.software.push(src);
271
- break;
272
- case "asset":
273
- // software dependencies are added as is
274
- this.addAsset(src);
275
- result.assets.push(src);
276
- break;
277
- case "template":
278
- // templates are compiled and then added
279
- try {
280
- const tpl = this.compileAndAddTemplate(src);
281
- const tplWithSrc = newTemplateWithSource(src.compileMode, src.fullName, tpl, src.src);
282
- this.addTemplate(tplWithSrc);
283
- result.templates.push(tplWithSrc);
284
- }
285
- catch (error) {
286
- const err = error;
287
- let errorMessage = `Unsatisfied dependencies in ${fullNameToString(src.fullName)}:\n`;
288
- errorMessage += ` - ${err.message}\n`;
289
- unprocessed.push({ src, err: Error(errorMessage) }); // one or more dependencies are not resolvable yet
290
- }
291
- break;
292
- case "test":
293
- // Ignore tests: they never should be part of compiled code or be a dependency.
294
- break;
295
- default:
296
- assertNever(src.fullName.type);
297
- }
298
- }
299
- // checking that we successfully added at least one source,
300
- // if not all the source files in unprocessed array have unmet dependencies
301
- if (current.length === unprocessed.length) {
302
- let errorMessage = "";
303
- for (const u of unprocessed) {
304
- errorMessage += `\n${u.err.message}`;
305
- }
306
- throw new Error(errorMessage);
307
- }
308
- current = unprocessed.map(({ src: ArtifactSource }) => ArtifactSource);
309
- }
310
- return result;
311
- }
312
- }
7
+ //#region src/compiler/compiler.ts
8
+ var TengoTemplateCompiler = class {
9
+ libs = new ArtifactStore((src) => src.fullName);
10
+ software = new ArtifactStore((src) => src.fullName);
11
+ assets = new ArtifactStore((src) => src.fullName);
12
+ templates = new ArtifactStore((tpl) => tpl.fullName);
13
+ constructor(compileMode) {
14
+ this.compileMode = compileMode;
15
+ }
16
+ /** Recursively add dependencies to the template. */
17
+ populateTemplateDataFromDependencies(fullName, data, deps, trace) {
18
+ for (const dep of deps) switch (dep.type) {
19
+ case "library": {
20
+ const lib = this.getLibOrError(dep);
21
+ const recursionStart = trace.indexOf(artifactNameToString(dep));
22
+ if (recursionStart >= 0) {
23
+ const errorMessage = `library import recursion detected: ${trace.slice(recursionStart).join(" -> ")} -> ${artifactNameToString(dep)}`;
24
+ throw new Error(errorMessage);
25
+ }
26
+ const tplLib = {
27
+ ...formatArtefactNameAndVersion(lib.fullName),
28
+ sourceHash: lib.sourceHash
29
+ };
30
+ applyLibraryCompilerOptions(lib.compilerOptions, tplLib);
31
+ data.template.libs[artifactNameToString(dep)] = tplLib;
32
+ data.hashToSource[tplLib.sourceHash] = lib.src;
33
+ this.populateTemplateDataFromDependencies(fullName, data, lib.dependencies, [...trace, artifactNameToString(dep)]);
34
+ break;
35
+ }
36
+ case "software": {
37
+ const software = this.getSoftwareOrError(dep);
38
+ data.template.software[artifactNameToString(dep)] = {
39
+ ...formatArtefactNameAndVersion(software.fullName),
40
+ sourceHash: software.sourceHash
41
+ };
42
+ data.hashToSource[software.sourceHash] = software.src;
43
+ break;
44
+ }
45
+ case "asset": {
46
+ const asset = this.getAssetOrError(dep);
47
+ data.template.software[artifactNameToString(dep)] = {
48
+ ...formatArtefactNameAndVersion(asset.fullName),
49
+ sourceHash: asset.sourceHash
50
+ };
51
+ data.hashToSource[asset.sourceHash] = asset.src;
52
+ break;
53
+ }
54
+ case "template": {
55
+ if (typedArtifactNamesEquals(fullName, dep)) continue;
56
+ const tpl = this.getTemplateOrError(dep);
57
+ data.template.templates[artifactNameToString(dep)] = tpl.data.template;
58
+ data.hashToSource[tpl.data.template.sourceHash] = tpl.source;
59
+ for (const [hash, src] of Object.entries(tpl.data.hashToSource)) data.hashToSource[hash] = src;
60
+ break;
61
+ }
62
+ case "test": throw new Error(`dependencies tree error: tests should never be part of template: ${typedArtifactNameToString(dep)} is dependency of ${artifactNameToString(fullName)}`);
63
+ default: assertNever(dep.type);
64
+ }
65
+ }
66
+ /** This method assumes that all dependencies are already added to the compiler's context */
67
+ compileAndAddTemplate(tplSrc) {
68
+ if (tplSrc.fullName.type !== "template") throw new Error("unexpected source type");
69
+ const tplData = {
70
+ type: "pl.tengo-template.v3",
71
+ hashToSource: { [tplSrc.sourceHash]: tplSrc.src },
72
+ template: {
73
+ ...formatArtefactNameAndVersion(tplSrc.fullName),
74
+ templates: {},
75
+ libs: {},
76
+ software: {},
77
+ assets: {},
78
+ sourceHash: tplSrc.sourceHash
79
+ }
80
+ };
81
+ applyTemplateCompilerOptions(tplSrc.compilerOptions, tplData.template);
82
+ this.populateTemplateDataFromDependencies(tplSrc.fullName, tplData, tplSrc.dependencies, []);
83
+ return tplData;
84
+ }
85
+ addLib(lib) {
86
+ const libFromMap = this.libs.add(lib.compileMode, lib, false);
87
+ if (libFromMap && !fullNameEquals(lib.fullName, libFromMap.fullName)) throw new Error(`compiler already contain such library: adding = ${fullNameToString(lib.fullName)}, contains = ${fullNameToString(libFromMap.fullName)}`);
88
+ }
89
+ allLibs() {
90
+ return this.libs.array(this.compileMode);
91
+ }
92
+ getLib(name) {
93
+ if (name.type !== "library") throw new Error(`illegal artifact type: got ${name.type} instead of 'library`);
94
+ return this.libs.get(this.compileMode, name);
95
+ }
96
+ getLibOrError(name) {
97
+ const lib = this.getLib(name);
98
+ if (!lib) throw new Error(`library not found: ${artifactNameToString(name)}`);
99
+ return lib;
100
+ }
101
+ checkLibs() {
102
+ this.libs.forEach(this.compileMode, (lib) => {
103
+ for (const dep of lib.dependencies) {
104
+ if (dep.type === "test") throw new Error(`test should never be dependency of production code: ${typedArtifactNameToString(dep)} test is dependency of ${fullNameToString(lib.fullName)}`);
105
+ if (!this.getArtefact(dep)) throw new Error(`unresolved dependency ${typedArtifactNameToString(dep)} for ${fullNameToString(lib.fullName)}`);
106
+ }
107
+ });
108
+ }
109
+ addSoftware(software) {
110
+ const swFromMap = this.software.add(software.compileMode, software, false);
111
+ if (swFromMap && !fullNameEquals(software.fullName, swFromMap.fullName)) throw new Error(`compiler already contain info for software: adding = ${fullNameToString(software.fullName)}, contains = ${fullNameToString(swFromMap.fullName)}`);
112
+ }
113
+ allSoftware() {
114
+ return this.software.array(this.compileMode);
115
+ }
116
+ getSoftware(name) {
117
+ if (name.type !== "software") throw new Error(`illegal artifact type: got ${name.type} instead of 'software`);
118
+ return this.software.get(this.compileMode, name);
119
+ }
120
+ getSoftwareOrError(name) {
121
+ const software = this.getSoftware(name);
122
+ if (!software) throw new Error(`software info not found: ${artifactNameToString(name)}`);
123
+ return software;
124
+ }
125
+ addAsset(asset) {
126
+ const assetFromMap = this.assets.add(asset.compileMode, asset, false);
127
+ if (assetFromMap && !fullNameEquals(asset.fullName, assetFromMap.fullName)) throw new Error(`compiler already contain info for asset: adding = ${fullNameToString(asset.fullName)}, contains = ${fullNameToString(assetFromMap.fullName)}`);
128
+ }
129
+ allAssets() {
130
+ return this.assets.array(this.compileMode);
131
+ }
132
+ getAsset(name) {
133
+ if (name.type !== "asset") throw new Error(`illegal artifact type: got ${name.type} instead of 'asset`);
134
+ return this.assets.get(this.compileMode, name);
135
+ }
136
+ getAssetOrError(name) {
137
+ const asset = this.getAsset(name);
138
+ if (!asset) throw new Error(`asset info not found: ${artifactNameToString(name)}`);
139
+ return asset;
140
+ }
141
+ addTemplate(tpl) {
142
+ const tplFromMap = this.templates.add(tpl.compileMode, tpl, false);
143
+ if (tplFromMap && !fullNameEquals(tpl.fullName, tplFromMap.fullName)) throw new Error(`compiler already contain such template: adding = ${fullNameToString(tpl.fullName)}, contains = ${fullNameToString(tplFromMap.fullName)}`);
144
+ }
145
+ allTemplates() {
146
+ return this.templates.array(this.compileMode);
147
+ }
148
+ getTemplate(name) {
149
+ if (name.type !== "template") throw new Error(`illegal artifact type: got ${name.type} instead of 'template`);
150
+ return this.templates.get(this.compileMode, name);
151
+ }
152
+ getTemplateOrError(name) {
153
+ const tpl = this.getTemplate(name);
154
+ if (!tpl) throw new Error(`template not found: ${artifactNameToString(name)}`);
155
+ return tpl;
156
+ }
157
+ getArtefact(name) {
158
+ switch (name.type) {
159
+ case "template": return this.getTemplate(name);
160
+ case "library": return this.getLib(name);
161
+ case "software": return this.getSoftware(name);
162
+ case "asset": return this.getAsset(name);
163
+ case "test": return;
164
+ default: assertNever(name.type);
165
+ }
166
+ }
167
+ compileAndAdd(sources) {
168
+ const result = {
169
+ templates: [],
170
+ libs: [],
171
+ software: [],
172
+ assets: []
173
+ };
174
+ let current = [];
175
+ for (const src of sources) if (src.fullName.type === "library") {
176
+ this.addLib(src);
177
+ result.libs.push(src);
178
+ } else if (src.fullName.type === "software") {
179
+ this.addSoftware(src);
180
+ result.software.push(src);
181
+ } else if (src.fullName.type === "asset") {
182
+ this.addAsset(src);
183
+ result.assets.push(src);
184
+ } else current.push(src);
185
+ while (current.length > 0) {
186
+ const unprocessed = [];
187
+ for (const src of current) {
188
+ const unsatisfied = src.dependencies.filter((dep) => !this.getArtefact(dep) && !(src.fullName.type === "template" && typedArtifactNamesEquals(src.fullName, dep)));
189
+ if (unsatisfied.length > 0) {
190
+ let errorMessage = `Unsatisfied dependencies in ${fullNameToString(src.fullName)}:\n`;
191
+ for (const dep of unsatisfied) errorMessage += ` - ${typedArtifactNameToString(dep)}\n`;
192
+ unprocessed.push({
193
+ src,
194
+ err: new Error(errorMessage)
195
+ });
196
+ continue;
197
+ }
198
+ switch (src.fullName.type) {
199
+ case "library":
200
+ this.addLib(src);
201
+ result.libs.push(src);
202
+ break;
203
+ case "software":
204
+ this.addSoftware(src);
205
+ result.software.push(src);
206
+ break;
207
+ case "asset":
208
+ this.addAsset(src);
209
+ result.assets.push(src);
210
+ break;
211
+ case "template":
212
+ try {
213
+ const tpl = this.compileAndAddTemplate(src);
214
+ const tplWithSrc = newTemplateWithSource(src.compileMode, src.fullName, tpl, src.src);
215
+ this.addTemplate(tplWithSrc);
216
+ result.templates.push(tplWithSrc);
217
+ } catch (error) {
218
+ const err = error;
219
+ let errorMessage = `Unsatisfied dependencies in ${fullNameToString(src.fullName)}:\n`;
220
+ errorMessage += ` - ${err.message}\n`;
221
+ unprocessed.push({
222
+ src,
223
+ err: Error(errorMessage)
224
+ });
225
+ }
226
+ break;
227
+ case "test": break;
228
+ default: assertNever(src.fullName.type);
229
+ }
230
+ }
231
+ if (current.length === unprocessed.length) {
232
+ let errorMessage = "";
233
+ for (const u of unprocessed) errorMessage += `\n${u.err.message}`;
234
+ throw new Error(errorMessage);
235
+ }
236
+ current = unprocessed.map(({ src: ArtifactSource }) => ArtifactSource);
237
+ }
238
+ return result;
239
+ }
240
+ };
313
241
 
242
+ //#endregion
314
243
  export { TengoTemplateCompiler };
315
- //# sourceMappingURL=compiler.js.map
244
+ //# sourceMappingURL=compiler.js.map