@platforma-sdk/tengo-builder 2.1.14 → 2.1.15
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/bin/run.js +6 -0
- package/dist/commands/build.cjs +172 -0
- package/dist/commands/build.cjs.map +1 -0
- package/dist/commands/build.d.ts +4 -6
- package/dist/commands/build.js +149 -0
- package/dist/commands/build.js.map +1 -0
- package/dist/commands/check.cjs +39 -0
- package/dist/commands/check.cjs.map +1 -0
- package/dist/commands/check.d.ts +1 -3
- package/dist/commands/check.js +37 -0
- package/dist/commands/check.js.map +1 -0
- package/dist/commands/dump/all.cjs +20 -0
- package/dist/commands/dump/all.cjs.map +1 -0
- package/dist/commands/dump/all.d.ts +0 -1
- package/dist/commands/dump/all.js +18 -0
- package/dist/commands/dump/all.js.map +1 -0
- package/dist/commands/dump/assets.cjs +20 -0
- package/dist/commands/dump/assets.cjs.map +1 -0
- package/dist/commands/dump/assets.d.ts +0 -1
- package/dist/commands/dump/assets.js +18 -0
- package/dist/commands/dump/assets.js.map +1 -0
- package/dist/commands/dump/libs.cjs +24 -0
- package/dist/commands/dump/libs.cjs.map +1 -0
- package/dist/commands/dump/libs.d.ts +1 -3
- package/dist/commands/dump/libs.js +22 -0
- package/dist/commands/dump/libs.js.map +1 -0
- package/dist/commands/dump/software.cjs +20 -0
- package/dist/commands/dump/software.cjs.map +1 -0
- package/dist/commands/dump/software.d.ts +0 -1
- package/dist/commands/dump/software.js +18 -0
- package/dist/commands/dump/software.js.map +1 -0
- package/dist/commands/dump/templates.cjs +20 -0
- package/dist/commands/dump/templates.cjs.map +1 -0
- package/dist/commands/dump/templates.d.ts +0 -1
- package/dist/commands/dump/templates.js +18 -0
- package/dist/commands/dump/templates.js.map +1 -0
- package/dist/commands/dump/tests.cjs +20 -0
- package/dist/commands/dump/tests.cjs.map +1 -0
- package/dist/commands/dump/tests.d.ts +0 -1
- package/dist/commands/dump/tests.js +18 -0
- package/dist/commands/dump/tests.js.map +1 -0
- package/dist/commands/test.cjs +36 -0
- package/dist/commands/test.cjs.map +1 -0
- package/dist/commands/test.d.ts +1 -3
- package/dist/commands/test.js +34 -0
- package/dist/commands/test.js.map +1 -0
- package/dist/compiler/artifactset.cjs +75 -0
- package/dist/compiler/artifactset.cjs.map +1 -0
- package/dist/compiler/artifactset.d.ts +0 -1
- package/dist/compiler/artifactset.js +71 -0
- package/dist/compiler/artifactset.js.map +1 -0
- package/dist/compiler/compiler.cjs +314 -0
- package/dist/compiler/compiler.cjs.map +1 -0
- package/dist/compiler/compiler.d.ts +0 -1
- package/dist/compiler/compiler.js +312 -0
- package/dist/compiler/compiler.js.map +1 -0
- package/dist/compiler/compileroptions.cjs +45 -0
- package/dist/compiler/compileroptions.cjs.map +1 -0
- package/dist/compiler/compileroptions.d.ts +0 -1
- package/dist/compiler/compileroptions.js +41 -0
- package/dist/compiler/compileroptions.js.map +1 -0
- package/dist/compiler/main.cjs +387 -0
- package/dist/compiler/main.cjs.map +1 -0
- package/dist/compiler/main.d.ts +0 -1
- package/dist/compiler/main.js +359 -0
- package/dist/compiler/main.js.map +1 -0
- package/dist/compiler/package.cjs +65 -0
- package/dist/compiler/package.cjs.map +1 -0
- package/dist/compiler/package.d.ts +0 -1
- package/dist/compiler/package.js +55 -0
- package/dist/compiler/package.js.map +1 -0
- package/dist/compiler/source.cjs +292 -0
- package/dist/compiler/source.cjs.map +1 -0
- package/dist/compiler/source.d.ts +0 -1
- package/dist/compiler/source.js +285 -0
- package/dist/compiler/source.js.map +1 -0
- package/dist/compiler/template.cjs +48 -0
- package/dist/compiler/template.cjs.map +1 -0
- package/dist/compiler/template.d.ts +0 -1
- package/dist/compiler/template.js +44 -0
- package/dist/compiler/template.js.map +1 -0
- package/dist/compiler/test.artifacts.d.ts +0 -1
- package/dist/compiler/util.cjs +75 -0
- package/dist/compiler/util.cjs.map +1 -0
- package/dist/compiler/util.d.ts +0 -1
- package/dist/compiler/util.js +50 -0
- package/dist/compiler/util.js.map +1 -0
- package/dist/index.cjs +28 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +0 -1
- package/dist/index.js +23 -41
- package/dist/index.js.map +1 -1
- package/dist/shared/basecmd.cjs +31 -0
- package/dist/shared/basecmd.cjs.map +1 -0
- package/dist/shared/basecmd.d.ts +4 -6
- package/dist/shared/basecmd.js +28 -0
- package/dist/shared/basecmd.js.map +1 -0
- package/dist/shared/dump.cjs +117 -0
- package/dist/shared/dump.cjs.map +1 -0
- package/dist/shared/dump.d.ts +0 -1
- package/dist/shared/dump.js +110 -0
- package/dist/shared/dump.js.map +1 -0
- package/dist/shared/proc.cjs +26 -0
- package/dist/shared/proc.cjs.map +1 -0
- package/dist/shared/proc.d.ts +0 -1
- package/dist/shared/proc.js +23 -0
- package/dist/shared/proc.js.map +1 -0
- package/package.json +13 -10
- package/dist/commands/build.d.ts.map +0 -1
- package/dist/commands/check.d.ts.map +0 -1
- package/dist/commands/dump/all.d.ts.map +0 -1
- package/dist/commands/dump/assets.d.ts.map +0 -1
- package/dist/commands/dump/libs.d.ts.map +0 -1
- package/dist/commands/dump/software.d.ts.map +0 -1
- package/dist/commands/dump/templates.d.ts.map +0 -1
- package/dist/commands/dump/tests.d.ts.map +0 -1
- package/dist/commands/test.d.ts.map +0 -1
- package/dist/compiler/artifactset.d.ts.map +0 -1
- package/dist/compiler/compiler.d.ts.map +0 -1
- package/dist/compiler/compileroptions.d.ts.map +0 -1
- package/dist/compiler/main.d.ts.map +0 -1
- package/dist/compiler/package.d.ts.map +0 -1
- package/dist/compiler/source.d.ts.map +0 -1
- package/dist/compiler/template.d.ts.map +0 -1
- package/dist/compiler/test.artifacts.d.ts.map +0 -1
- package/dist/compiler/util.d.ts.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/index.mjs +0 -1198
- package/dist/index.mjs.map +0 -1
- package/dist/shared/basecmd.d.ts.map +0 -1
- package/dist/shared/dump.d.ts.map +0 -1
- package/dist/shared/proc.d.ts.map +0 -1
|
@@ -0,0 +1,312 @@
|
|
|
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';
|
|
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, [...trace, artifactNameToString(dep)]);
|
|
37
|
+
break;
|
|
38
|
+
}
|
|
39
|
+
case 'software': {
|
|
40
|
+
const software = this.getSoftwareOrError(dep);
|
|
41
|
+
data.template.software[artifactNameToString(dep)] = {
|
|
42
|
+
...formatArtefactNameAndVersion(software.fullName),
|
|
43
|
+
sourceHash: software.sourceHash,
|
|
44
|
+
};
|
|
45
|
+
data.hashToSource[software.sourceHash] = software.src;
|
|
46
|
+
break;
|
|
47
|
+
}
|
|
48
|
+
case 'asset': {
|
|
49
|
+
const asset = this.getAssetOrError(dep);
|
|
50
|
+
// Yes, we temporarily put assets into 'software' section of template, so controller can
|
|
51
|
+
// handle it the right way without updates
|
|
52
|
+
data.template.software[artifactNameToString(dep)] = {
|
|
53
|
+
...formatArtefactNameAndVersion(asset.fullName),
|
|
54
|
+
sourceHash: asset.sourceHash,
|
|
55
|
+
};
|
|
56
|
+
data.hashToSource[asset.sourceHash] = asset.src;
|
|
57
|
+
break;
|
|
58
|
+
}
|
|
59
|
+
case 'template': {
|
|
60
|
+
if (typedArtifactNamesEquals(fullName, dep))
|
|
61
|
+
// skipping self reference
|
|
62
|
+
continue;
|
|
63
|
+
const tpl = this.getTemplateOrError(dep);
|
|
64
|
+
data.template.templates[artifactNameToString(dep)] = tpl.data.template;
|
|
65
|
+
data.hashToSource[tpl.data.template.sourceHash] = tpl.source;
|
|
66
|
+
// add all the sources of transitivedependencies to the resulted hashToSource
|
|
67
|
+
for (const [hash, src] of Object.entries(tpl.data.hashToSource)) {
|
|
68
|
+
data.hashToSource[hash] = src;
|
|
69
|
+
}
|
|
70
|
+
break;
|
|
71
|
+
}
|
|
72
|
+
case 'test':
|
|
73
|
+
throw new Error(`dependencies tree error: tests should never be part of template: `
|
|
74
|
+
+ `${typedArtifactNameToString(dep)} is dependency of ${artifactNameToString(fullName)}`);
|
|
75
|
+
default:
|
|
76
|
+
assertNever(dep.type);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
/** This method assumes that all dependencies are already added to the compiler's context */
|
|
81
|
+
compileAndAddTemplate(tplSrc) {
|
|
82
|
+
if (tplSrc.fullName.type !== 'template')
|
|
83
|
+
throw new Error('unexpected source type');
|
|
84
|
+
// creating template with unpopulated dependencies
|
|
85
|
+
const tplData = {
|
|
86
|
+
type: 'pl.tengo-template.v3',
|
|
87
|
+
hashToSource: {
|
|
88
|
+
[tplSrc.sourceHash]: tplSrc.src,
|
|
89
|
+
},
|
|
90
|
+
template: {
|
|
91
|
+
...formatArtefactNameAndVersion(tplSrc.fullName),
|
|
92
|
+
templates: {},
|
|
93
|
+
libs: {},
|
|
94
|
+
software: {},
|
|
95
|
+
assets: {},
|
|
96
|
+
sourceHash: tplSrc.sourceHash,
|
|
97
|
+
},
|
|
98
|
+
};
|
|
99
|
+
applyTemplateCompilerOptions(tplSrc.compilerOptions, tplData.template);
|
|
100
|
+
// collecting dependencies in output format
|
|
101
|
+
this.populateTemplateDataFromDependencies(tplSrc.fullName, tplData, tplSrc.dependencies, []);
|
|
102
|
+
return tplData;
|
|
103
|
+
}
|
|
104
|
+
addLib(lib) {
|
|
105
|
+
const libFromMap = this.libs.add(lib.compileMode, lib, false);
|
|
106
|
+
if (libFromMap && !fullNameEquals(lib.fullName, libFromMap.fullName))
|
|
107
|
+
throw new Error(`compiler already contain such library: adding = ${fullNameToString(lib.fullName)}, contains = ${fullNameToString(libFromMap.fullName)}`);
|
|
108
|
+
}
|
|
109
|
+
allLibs() {
|
|
110
|
+
return this.libs.array(this.compileMode);
|
|
111
|
+
}
|
|
112
|
+
getLib(name) {
|
|
113
|
+
if (name.type !== 'library')
|
|
114
|
+
throw new Error(`illegal artifact type: got ${name.type} instead of 'library`);
|
|
115
|
+
return this.libs.get(this.compileMode, name);
|
|
116
|
+
}
|
|
117
|
+
getLibOrError(name) {
|
|
118
|
+
const lib = this.getLib(name);
|
|
119
|
+
if (!lib)
|
|
120
|
+
throw new Error(`library not found: ${artifactNameToString(name)}`);
|
|
121
|
+
return lib;
|
|
122
|
+
}
|
|
123
|
+
checkLibs() {
|
|
124
|
+
this.libs.forEach(this.compileMode, (lib) => {
|
|
125
|
+
for (const dep of lib.dependencies) {
|
|
126
|
+
if (dep.type === 'test')
|
|
127
|
+
throw new Error(`test should never be dependency of production code: ${typedArtifactNameToString(dep)} test is dependency of ${fullNameToString(lib.fullName)}`);
|
|
128
|
+
if (!this.getArtefact(dep))
|
|
129
|
+
throw new Error(`unresolved dependency ${typedArtifactNameToString(dep)} for ${fullNameToString(lib.fullName)}`);
|
|
130
|
+
}
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
addSoftware(software) {
|
|
134
|
+
const swFromMap = this.software.add(software.compileMode, software, false);
|
|
135
|
+
if (swFromMap && !fullNameEquals(software.fullName, swFromMap.fullName))
|
|
136
|
+
throw new Error(`compiler already contain info for software: adding = ${fullNameToString(software.fullName)}, contains = ${fullNameToString(swFromMap.fullName)}`);
|
|
137
|
+
}
|
|
138
|
+
allSoftware() {
|
|
139
|
+
return this.software.array(this.compileMode);
|
|
140
|
+
}
|
|
141
|
+
getSoftware(name) {
|
|
142
|
+
if (name.type !== 'software')
|
|
143
|
+
throw new Error(`illegal artifact type: got ${name.type} instead of 'software`);
|
|
144
|
+
return this.software.get(this.compileMode, name);
|
|
145
|
+
}
|
|
146
|
+
getSoftwareOrError(name) {
|
|
147
|
+
const software = this.getSoftware(name);
|
|
148
|
+
if (!software)
|
|
149
|
+
throw new Error(`software info not found: ${artifactNameToString(name)}`);
|
|
150
|
+
return software;
|
|
151
|
+
}
|
|
152
|
+
addAsset(asset) {
|
|
153
|
+
const assetFromMap = this.assets.add(asset.compileMode, asset, false);
|
|
154
|
+
if (assetFromMap && !fullNameEquals(asset.fullName, assetFromMap.fullName))
|
|
155
|
+
throw new Error(`compiler already contain info for asset: adding = ${fullNameToString(asset.fullName)}, contains = ${fullNameToString(assetFromMap.fullName)}`);
|
|
156
|
+
}
|
|
157
|
+
allAssets() {
|
|
158
|
+
return this.assets.array(this.compileMode);
|
|
159
|
+
}
|
|
160
|
+
getAsset(name) {
|
|
161
|
+
if (name.type !== 'asset')
|
|
162
|
+
throw new Error(`illegal artifact type: got ${name.type} instead of 'asset`);
|
|
163
|
+
return this.assets.get(this.compileMode, name);
|
|
164
|
+
}
|
|
165
|
+
getAssetOrError(name) {
|
|
166
|
+
const asset = this.getAsset(name);
|
|
167
|
+
if (!asset)
|
|
168
|
+
throw new Error(`asset info not found: ${artifactNameToString(name)}`);
|
|
169
|
+
return asset;
|
|
170
|
+
}
|
|
171
|
+
addTemplate(tpl) {
|
|
172
|
+
const tplFromMap = this.templates.add(tpl.compileMode, tpl, false);
|
|
173
|
+
if (tplFromMap && !fullNameEquals(tpl.fullName, tplFromMap.fullName))
|
|
174
|
+
throw new Error(`compiler already contain such template: adding = ${fullNameToString(tpl.fullName)}, contains = ${fullNameToString(tplFromMap.fullName)}`);
|
|
175
|
+
}
|
|
176
|
+
allTemplates() {
|
|
177
|
+
return this.templates.array(this.compileMode);
|
|
178
|
+
}
|
|
179
|
+
getTemplate(name) {
|
|
180
|
+
if (name.type !== 'template')
|
|
181
|
+
throw new Error(`illegal artifact type: got ${name.type} instead of 'template`);
|
|
182
|
+
return this.templates.get(this.compileMode, name);
|
|
183
|
+
}
|
|
184
|
+
getTemplateOrError(name) {
|
|
185
|
+
const tpl = this.getTemplate(name);
|
|
186
|
+
if (!tpl)
|
|
187
|
+
throw new Error(`template not found: ${artifactNameToString(name)}`);
|
|
188
|
+
return tpl;
|
|
189
|
+
}
|
|
190
|
+
getArtefact(name) {
|
|
191
|
+
switch (name.type) {
|
|
192
|
+
case 'template':
|
|
193
|
+
return this.getTemplate(name);
|
|
194
|
+
case 'library':
|
|
195
|
+
return this.getLib(name);
|
|
196
|
+
case 'software':
|
|
197
|
+
return this.getSoftware(name);
|
|
198
|
+
case 'asset':
|
|
199
|
+
return this.getAsset(name);
|
|
200
|
+
case 'test':
|
|
201
|
+
// Tests are ignored by the complier. They should never be compiled into templates or libs and
|
|
202
|
+
// should never be a dependency.
|
|
203
|
+
return undefined;
|
|
204
|
+
default:
|
|
205
|
+
assertNever(name.type);
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
compileAndAdd(sources) {
|
|
209
|
+
const result = {
|
|
210
|
+
templates: [],
|
|
211
|
+
libs: [],
|
|
212
|
+
software: [],
|
|
213
|
+
assets: [],
|
|
214
|
+
};
|
|
215
|
+
let current = [];
|
|
216
|
+
for (const src of sources) {
|
|
217
|
+
if (src.fullName.type === 'library') {
|
|
218
|
+
// add libraries 'as-is' to be able to resolve them as dependencies
|
|
219
|
+
this.addLib(src);
|
|
220
|
+
result.libs.push(src);
|
|
221
|
+
}
|
|
222
|
+
else if (src.fullName.type === 'software') {
|
|
223
|
+
// add software 'as-is' to be able to resolve them as dependencies
|
|
224
|
+
this.addSoftware(src);
|
|
225
|
+
result.software.push(src);
|
|
226
|
+
}
|
|
227
|
+
else if (src.fullName.type === 'asset') {
|
|
228
|
+
// add assets 'as-is' to be able to resolve them as dependencies
|
|
229
|
+
this.addAsset(src);
|
|
230
|
+
result.assets.push(src);
|
|
231
|
+
}
|
|
232
|
+
else {
|
|
233
|
+
current.push(src);
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
while (current.length > 0) {
|
|
237
|
+
const unprocessed = [];
|
|
238
|
+
for (const src of current) {
|
|
239
|
+
//
|
|
240
|
+
// If one of the dependencies can't be resolved with current compiler context,
|
|
241
|
+
// we put aside the source until next iteration, in hope that the dependency
|
|
242
|
+
// will be satisfied then.
|
|
243
|
+
//
|
|
244
|
+
// This is equivalent to topological sorting of input sources.
|
|
245
|
+
//
|
|
246
|
+
const unsatisfied = src.dependencies.filter((dep) => !this.getArtefact(dep)
|
|
247
|
+
// allow self reference for templates
|
|
248
|
+
&& !(src.fullName.type === 'template' && typedArtifactNamesEquals(src.fullName, dep)));
|
|
249
|
+
if (unsatisfied.length > 0) {
|
|
250
|
+
let errorMessage = `Unsatisfied dependencies in ${fullNameToString(src.fullName)}:\n`;
|
|
251
|
+
for (const dep of unsatisfied) {
|
|
252
|
+
errorMessage += ` - ${typedArtifactNameToString(dep)}\n`;
|
|
253
|
+
}
|
|
254
|
+
unprocessed.push({ src, err: new Error(errorMessage) });
|
|
255
|
+
continue;
|
|
256
|
+
}
|
|
257
|
+
// type specific processing
|
|
258
|
+
switch (src.fullName.type) {
|
|
259
|
+
case 'library':
|
|
260
|
+
// libraries are added as is
|
|
261
|
+
this.addLib(src);
|
|
262
|
+
result.libs.push(src);
|
|
263
|
+
break;
|
|
264
|
+
case 'software':
|
|
265
|
+
// software dependencies are added as is
|
|
266
|
+
this.addSoftware(src);
|
|
267
|
+
result.software.push(src);
|
|
268
|
+
break;
|
|
269
|
+
case 'asset':
|
|
270
|
+
// software dependencies are added as is
|
|
271
|
+
this.addAsset(src);
|
|
272
|
+
result.assets.push(src);
|
|
273
|
+
break;
|
|
274
|
+
case 'template':
|
|
275
|
+
// templates are compiled and then added
|
|
276
|
+
try {
|
|
277
|
+
const tpl = this.compileAndAddTemplate(src);
|
|
278
|
+
const tplWithSrc = newTemplateWithSource(src.compileMode, src.fullName, tpl, src.src);
|
|
279
|
+
this.addTemplate(tplWithSrc);
|
|
280
|
+
result.templates.push(tplWithSrc);
|
|
281
|
+
}
|
|
282
|
+
catch (error) {
|
|
283
|
+
const err = error;
|
|
284
|
+
let errorMessage = `Unsatisfied dependencies in ${fullNameToString(src.fullName)}:\n`;
|
|
285
|
+
errorMessage += ` - ${err.message}\n`;
|
|
286
|
+
unprocessed.push({ src, err: Error(errorMessage) }); // one or more dependencies are not resolvable yet
|
|
287
|
+
}
|
|
288
|
+
break;
|
|
289
|
+
case 'test':
|
|
290
|
+
// Ignore tests: they never should be part of compiled code or be a dependency.
|
|
291
|
+
break;
|
|
292
|
+
default:
|
|
293
|
+
assertNever(src.fullName.type);
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
// checking that we successfully added at least one source,
|
|
297
|
+
// if not all the source files in unprocessed array have unmet dependencies
|
|
298
|
+
if (current.length === unprocessed.length) {
|
|
299
|
+
let errorMessage = '';
|
|
300
|
+
for (const u of unprocessed) {
|
|
301
|
+
errorMessage += `\n${u.err.message}`;
|
|
302
|
+
}
|
|
303
|
+
throw new Error(errorMessage);
|
|
304
|
+
}
|
|
305
|
+
current = unprocessed.map(({ src: ArtifactSource }) => ArtifactSource);
|
|
306
|
+
}
|
|
307
|
+
return result;
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
export { TengoTemplateCompiler };
|
|
312
|
+
//# sourceMappingURL=compiler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compiler.js","sources":["../../src/compiler/compiler.ts"],"sourcesContent":["import type { ArtifactSource } from './source';\nimport type { TemplateWithSource } from './template';\nimport { newTemplateWithSource } from './template';\nimport type {\n TypedArtifactName, FullArtifactName,\n CompileMode,\n} from './package';\nimport {\n fullNameToString,\n typedArtifactNameToString,\n artifactNameToString,\n formatArtefactNameAndVersion, typedArtifactNamesEquals,\n fullNameEquals,\n} from './package';\nimport { ArtifactStore } from './artifactset';\nimport { assertNever } from './util';\nimport { applyLibraryCompilerOptions, applyTemplateCompilerOptions } from './compileroptions';\nimport type { CompiledTemplateV3 } from '@milaboratories/pl-model-backend';\n\n/** A compilation result. */\nexport interface TemplatesAndLibs {\n templates: TemplateWithSource[];\n libs: ArtifactSource[];\n software: ArtifactSource[];\n assets: ArtifactSource[];\n}\n\nexport class TengoTemplateCompiler {\n private readonly libs = new ArtifactStore<ArtifactSource>((src) => src.fullName);\n private readonly software = new ArtifactStore<ArtifactSource>((src) => src.fullName);\n private readonly assets = new ArtifactStore<ArtifactSource>((src) => src.fullName);\n private readonly templates = new ArtifactStore<TemplateWithSource>((tpl) => tpl.fullName);\n\n constructor(\n private readonly compileMode: CompileMode,\n ) { }\n\n /** Recursively add dependencies to the template. */\n private populateTemplateDataFromDependencies(\n fullName: FullArtifactName,\n data: CompiledTemplateV3,\n deps: TypedArtifactName[],\n trace: string[],\n ) {\n for (const dep of deps) {\n switch (dep.type) {\n case 'library': {\n const lib = this.getLibOrError(dep);\n\n const recursionStart = trace.indexOf(artifactNameToString(dep));\n if (recursionStart >= 0) {\n const errorMessage = `library import recursion detected: `\n + `${trace.slice(recursionStart).join(' -> ')} -> ${artifactNameToString(dep)}`;\n throw new Error(errorMessage);\n }\n\n const tplLib = {\n ...formatArtefactNameAndVersion(lib.fullName),\n sourceHash: lib.sourceHash,\n };\n\n applyLibraryCompilerOptions(lib.compilerOptions, tplLib);\n data.template.libs[artifactNameToString(dep)] = tplLib;\n data.hashToSource[tplLib.sourceHash] = lib.src;\n\n // populate with transient library dependencies\n this.populateTemplateDataFromDependencies(fullName, data, lib.dependencies, [...trace, artifactNameToString(dep)]);\n\n break;\n }\n case 'software': {\n const software = this.getSoftwareOrError(dep);\n data.template.software[artifactNameToString(dep)] = {\n ...formatArtefactNameAndVersion(software.fullName),\n sourceHash: software.sourceHash,\n };\n data.hashToSource[software.sourceHash] = software.src;\n\n break;\n }\n case 'asset': {\n const asset = this.getAssetOrError(dep);\n // Yes, we temporarily put assets into 'software' section of template, so controller can\n // handle it the right way without updates\n data.template.software[artifactNameToString(dep)] = {\n ...formatArtefactNameAndVersion(asset.fullName),\n sourceHash: asset.sourceHash,\n };\n data.hashToSource[asset.sourceHash] = asset.src;\n break;\n }\n case 'template': {\n if (typedArtifactNamesEquals(fullName, dep))\n // skipping self reference\n continue;\n\n const tpl = this.getTemplateOrError(dep);\n data.template.templates[artifactNameToString(dep)] = tpl.data.template;\n data.hashToSource[tpl.data.template.sourceHash] = tpl.source;\n\n // add all the sources of transitivedependencies to the resulted hashToSource\n for (const [hash, src] of Object.entries(tpl.data.hashToSource)) {\n data.hashToSource[hash] = src;\n }\n\n break;\n }\n case 'test':\n throw new Error(\n `dependencies tree error: tests should never be part of template: `\n + `${typedArtifactNameToString(dep)} is dependency of ${artifactNameToString(fullName)}`,\n );\n default:\n assertNever(dep.type);\n }\n }\n }\n\n /** This method assumes that all dependencies are already added to the compiler's context */\n private compileAndAddTemplate(tplSrc: ArtifactSource): CompiledTemplateV3 {\n if (tplSrc.fullName.type !== 'template')\n throw new Error('unexpected source type');\n\n // creating template with unpopulated dependencies\n const tplData: CompiledTemplateV3 = {\n type: 'pl.tengo-template.v3',\n hashToSource: {\n [tplSrc.sourceHash]: tplSrc.src,\n },\n template: {\n ...formatArtefactNameAndVersion(tplSrc.fullName),\n templates: {},\n libs: {},\n software: {},\n assets: {},\n sourceHash: tplSrc.sourceHash,\n },\n };\n\n applyTemplateCompilerOptions(tplSrc.compilerOptions, tplData.template);\n\n // collecting dependencies in output format\n this.populateTemplateDataFromDependencies(tplSrc.fullName, tplData, tplSrc.dependencies, []);\n\n return tplData;\n }\n\n addLib(lib: ArtifactSource) {\n const libFromMap = this.libs.add(lib.compileMode, lib, false);\n if (libFromMap && !fullNameEquals(lib.fullName, libFromMap.fullName))\n throw new Error(\n `compiler already contain such library: adding = ${fullNameToString(lib.fullName)}, contains = ${fullNameToString(libFromMap.fullName)}`,\n );\n }\n\n allLibs(): ArtifactSource[] {\n return this.libs.array(this.compileMode);\n }\n\n getLib(name: TypedArtifactName): ArtifactSource | undefined {\n if (name.type !== 'library')\n throw new Error(`illegal artifact type: got ${name.type} instead of 'library`);\n return this.libs.get(this.compileMode, name);\n }\n\n getLibOrError(name: TypedArtifactName): ArtifactSource {\n const lib = this.getLib(name);\n if (!lib)\n throw new Error(`library not found: ${artifactNameToString(name)}`);\n return lib;\n }\n\n checkLibs() {\n this.libs.forEach(this.compileMode, (lib) => {\n for (const dep of lib.dependencies) {\n if (dep.type === 'test')\n throw new Error(`test should never be dependency of production code: ${typedArtifactNameToString(dep)} test is dependency of ${fullNameToString(lib.fullName)}`);\n\n if (!this.getArtefact(dep))\n throw new Error(`unresolved dependency ${typedArtifactNameToString(dep)} for ${fullNameToString(lib.fullName)}`);\n }\n });\n }\n\n addSoftware(software: ArtifactSource) {\n const swFromMap = this.software.add(software.compileMode, software, false);\n if (swFromMap && !fullNameEquals(software.fullName, swFromMap.fullName))\n throw new Error(\n `compiler already contain info for software: adding = ${fullNameToString(software.fullName)}, contains = ${fullNameToString(swFromMap.fullName)}`,\n );\n }\n\n allSoftware(): ArtifactSource[] {\n return this.software.array(this.compileMode);\n }\n\n getSoftware(name: TypedArtifactName): ArtifactSource | undefined {\n if (name.type !== 'software')\n throw new Error(`illegal artifact type: got ${name.type} instead of 'software`);\n\n return this.software.get(this.compileMode, name);\n }\n\n getSoftwareOrError(name: TypedArtifactName): ArtifactSource {\n const software = this.getSoftware(name);\n if (!software)\n throw new Error(`software info not found: ${artifactNameToString(name)}`);\n return software;\n }\n\n addAsset(asset: ArtifactSource) {\n const assetFromMap = this.assets.add(asset.compileMode, asset, false);\n if (assetFromMap && !fullNameEquals(asset.fullName, assetFromMap.fullName))\n throw new Error(\n `compiler already contain info for asset: adding = ${fullNameToString(asset.fullName)}, contains = ${fullNameToString(assetFromMap.fullName)}`,\n );\n }\n\n allAssets(): ArtifactSource[] {\n return this.assets.array(this.compileMode);\n }\n\n getAsset(name: TypedArtifactName): ArtifactSource | undefined {\n if (name.type !== 'asset')\n throw new Error(`illegal artifact type: got ${name.type} instead of 'asset`);\n\n return this.assets.get(this.compileMode, name);\n }\n\n getAssetOrError(name: TypedArtifactName): ArtifactSource {\n const asset = this.getAsset(name);\n if (!asset)\n throw new Error(`asset info not found: ${artifactNameToString(name)}`);\n return asset;\n }\n\n addTemplate(tpl: TemplateWithSource) {\n const tplFromMap = this.templates.add(tpl.compileMode, tpl, false);\n if (tplFromMap && !fullNameEquals(tpl.fullName, tplFromMap.fullName))\n throw new Error(\n `compiler already contain such template: adding = ${fullNameToString(tpl.fullName)}, contains = ${fullNameToString(tplFromMap.fullName)}`,\n );\n }\n\n allTemplates(): TemplateWithSource[] {\n return this.templates.array(this.compileMode);\n }\n\n getTemplate(name: TypedArtifactName): TemplateWithSource | undefined {\n if (name.type !== 'template')\n throw new Error(`illegal artifact type: got ${name.type} instead of 'template`);\n return this.templates.get(this.compileMode, name);\n }\n\n getTemplateOrError(name: TypedArtifactName): TemplateWithSource {\n const tpl = this.getTemplate(name);\n if (!tpl)\n throw new Error(`template not found: ${artifactNameToString(name)}`);\n return tpl;\n }\n\n getArtefact(name: TypedArtifactName): ArtifactSource | TemplateWithSource | undefined {\n switch (name.type) {\n case 'template':\n return this.getTemplate(name);\n case 'library':\n return this.getLib(name);\n case 'software':\n return this.getSoftware(name);\n case 'asset':\n return this.getAsset(name);\n case 'test':\n // Tests are ignored by the complier. They should never be compiled into templates or libs and\n // should never be a dependency.\n return undefined;\n default:\n assertNever(name.type);\n }\n }\n\n compileAndAdd(sources: ArtifactSource[]): TemplatesAndLibs {\n const result: TemplatesAndLibs = {\n templates: [],\n libs: [],\n software: [],\n assets: [],\n };\n\n let current: ArtifactSource[] = [];\n\n for (const src of sources) {\n if (src.fullName.type === 'library') {\n // add libraries 'as-is' to be able to resolve them as dependencies\n this.addLib(src);\n result.libs.push(src);\n } else if (src.fullName.type === 'software') {\n // add software 'as-is' to be able to resolve them as dependencies\n this.addSoftware(src);\n result.software.push(src);\n } else if (src.fullName.type === 'asset') {\n // add assets 'as-is' to be able to resolve them as dependencies\n this.addAsset(src);\n result.assets.push(src);\n } else {\n current.push(src);\n }\n }\n\n while (current.length > 0) {\n const unprocessed: { src: ArtifactSource; err: Error }[] = [];\n\n for (const src of current) {\n //\n // If one of the dependencies can't be resolved with current compiler context,\n // we put aside the source until next iteration, in hope that the dependency\n // will be satisfied then.\n //\n // This is equivalent to topological sorting of input sources.\n //\n const unsatisfied = src.dependencies.filter((dep) =>\n !this.getArtefact(dep)\n // allow self reference for templates\n && !(src.fullName.type === 'template' && typedArtifactNamesEquals(src.fullName, dep)),\n );\n if (unsatisfied.length > 0) {\n let errorMessage = `Unsatisfied dependencies in ${fullNameToString(src.fullName)}:\\n`;\n for (const dep of unsatisfied) {\n errorMessage += ` - ${typedArtifactNameToString(dep)}\\n`;\n }\n unprocessed.push({ src, err: new Error(errorMessage) });\n\n continue;\n }\n\n // type specific processing\n switch (src.fullName.type) {\n case 'library':\n // libraries are added as is\n this.addLib(src);\n result.libs.push(src);\n break;\n case 'software':\n // software dependencies are added as is\n this.addSoftware(src);\n result.software.push(src);\n break;\n case 'asset':\n // software dependencies are added as is\n this.addAsset(src);\n result.assets.push(src);\n break;\n case 'template':\n // templates are compiled and then added\n try {\n const tpl = this.compileAndAddTemplate(src);\n const tplWithSrc = newTemplateWithSource(src.compileMode, src.fullName, tpl, src.src);\n this.addTemplate(tplWithSrc);\n result.templates.push(tplWithSrc);\n } catch (error: unknown) {\n const err = error as Error;\n let errorMessage = `Unsatisfied dependencies in ${fullNameToString(src.fullName)}:\\n`;\n errorMessage += ` - ${err.message}\\n`;\n\n unprocessed.push({ src, err: Error(errorMessage) }); // one or more dependencies are not resolvable yet\n }\n break;\n case 'test':\n // Ignore tests: they never should be part of compiled code or be a dependency.\n break;\n default:\n assertNever(src.fullName.type);\n }\n }\n\n // checking that we successfully added at least one source,\n // if not all the source files in unprocessed array have unmet dependencies\n if (current.length === unprocessed.length) {\n let errorMessage = '';\n\n for (const u of unprocessed) {\n errorMessage += `\\n${u.err.message}`;\n }\n throw new Error(errorMessage);\n }\n\n current = unprocessed.map(({ src: ArtifactSource }) => ArtifactSource);\n }\n\n return result;\n }\n}\n"],"names":[],"mappings":";;;;;;MA2Ba,qBAAqB,CAAA;AAOb,IAAA,WAAA;AANF,IAAA,IAAI,GAAG,IAAI,aAAa,CAAiB,CAAC,GAAG,KAAK,GAAG,CAAC,QAAQ,CAAC;AAC/D,IAAA,QAAQ,GAAG,IAAI,aAAa,CAAiB,CAAC,GAAG,KAAK,GAAG,CAAC,QAAQ,CAAC;AACnE,IAAA,MAAM,GAAG,IAAI,aAAa,CAAiB,CAAC,GAAG,KAAK,GAAG,CAAC,QAAQ,CAAC;AACjE,IAAA,SA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AA,OAAO,GAAG,WAAW,CAAC,GAAG,CAAC,CAAC,EAAE,GAAG,EAAE,cAAc,EAAE,KAAK,cAAc,CAAC;QACxE;AAEA,QAAA,OAAO,MAAM;IACf;AACD;;;;"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var util = require('./util.cjs');
|
|
4
|
+
|
|
5
|
+
function applyTemplateCompilerOptions(opts, tpl) {
|
|
6
|
+
for (const opt of opts) {
|
|
7
|
+
switch (opt.name) {
|
|
8
|
+
case 'hash_override': {
|
|
9
|
+
tpl.hashOverride = hashOverride(opt.args);
|
|
10
|
+
break;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
function applyLibraryCompilerOptions(opts, _lib) {
|
|
16
|
+
for (const opt of opts) {
|
|
17
|
+
switch (opt.name) {
|
|
18
|
+
case 'hash_override': {
|
|
19
|
+
throw new Error(`hash_override compiler option can be used ONLY on template level. Even in templates it is already dangerous enough`
|
|
20
|
+
+ ` to potentially break everything in Platforma Backend. In libraries with the transitive dependencies`
|
|
21
|
+
+ ` resolution and flattening of libraries list on template level, it becomes so unpredictibally disasterous, that`
|
|
22
|
+
+ ` we are doomed to never find the ends of a knot if anything goes wrong.`);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
function hashOverride(args) {
|
|
28
|
+
if (args.length != 1) {
|
|
29
|
+
throw new Error('hash_override compiler option expects exactly one argument: hash_override <some string>. Note, you can use only UUID as a value.');
|
|
30
|
+
}
|
|
31
|
+
const override = args[0].toLowerCase();
|
|
32
|
+
if (!util.isUUID(override)) {
|
|
33
|
+
throw new Error('hash_override must contain valid UUID as an override. As hash_override affects deduplication,'
|
|
34
|
+
+ ' it becomes completely not possible to distinguish several different templates from each other on backend\'s side.'
|
|
35
|
+
+ ' This means, if you set hash_override to a simple value (say, letter "a") on two completely different templates,'
|
|
36
|
+
+ ' they will be marked as interchangeable on backend\'s side with unpredictable consequences.'
|
|
37
|
+
+ ' UUID looks like a safe enough tradeoff between the feature usage simplicity and duplication safety');
|
|
38
|
+
}
|
|
39
|
+
return override;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
exports.applyLibraryCompilerOptions = applyLibraryCompilerOptions;
|
|
43
|
+
exports.applyTemplateCompilerOptions = applyTemplateCompilerOptions;
|
|
44
|
+
exports.hashOverride = hashOverride;
|
|
45
|
+
//# sourceMappingURL=compileroptions.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compileroptions.cjs","sources":["../../src/compiler/compileroptions.ts"],"sourcesContent":["import type { TemplateDataV3, TemplateLibDataV3 } from '@milaboratories/pl-model-backend';\nimport type { CompilerOption } from './package';\nimport * as util from './util';\n\nexport function applyTemplateCompilerOptions(opts: CompilerOption[], tpl: TemplateDataV3) {\n for (const opt of opts) {\n switch (opt.name) {\n case 'hash_override': {\n tpl.hashOverride = hashOverride(opt.args);\n break;\n }\n }\n }\n}\n\nexport function applyLibraryCompilerOptions(opts: CompilerOption[], _lib: TemplateLibDataV3) {\n for (const opt of opts) {\n switch (opt.name) {\n case 'hash_override': {\n throw new Error(\n `hash_override compiler option can be used ONLY on template level. Even in templates it is already dangerous enough`\n + ` to potentially break everything in Platforma Backend. In libraries with the transitive dependencies`\n + ` resolution and flattening of libraries list on template level, it becomes so unpredictibally disasterous, that`\n + ` we are doomed to never find the ends of a knot if anything goes wrong.`,\n );\n }\n }\n }\n}\n\nexport function hashOverride(args: string[]): string {\n if (args.length != 1) {\n throw new Error(\n 'hash_override compiler option expects exactly one argument: hash_override <some string>. Note, you can use only UUID as a value.',\n );\n }\n\n const override = args[0].toLowerCase();\n\n if (!util.isUUID(override)) {\n throw new Error(\n 'hash_override must contain valid UUID as an override. As hash_override affects deduplication,'\n + ' it becomes completely not possible to distinguish several different templates from each other on backend\\'s side.'\n + ' This means, if you set hash_override to a simple value (say, letter \"a\") on two completely different templates,'\n + ' they will be marked as interchangeable on backend\\'s side with unpredictable consequences.'\n + ' UUID looks like a safe enough tradeoff between the feature usage simplicity and duplication safety',\n );\n }\n\n return override;\n}\n"],"names":["util.isUUID"],"mappings":";;;;AAIM,SAAU,4BAA4B,CAAC,IAAsB,EAAE,GAAmB,EAAA;AACtF,IAAA,KAAK,MAAM,GAAG,IAAI,IAAI,EAAE;AACtB,QAAA,QAAQ,GAAG,CAAC,IAAI;YACd,KAAK,eAAe,EAAE;gBACpB,GAAG,CAAC,YAAY,GAAG,YAAY,CAAC,GAAG,CAAC,IAAI,CAAC;gBACzC;YACF;;IAEJ;AACF;AAEM,SAAU,2BAA2B,CAAC,IAAsB,EAAE,IAAuB,EAAA;AACzF,IAAA,KAAK,MAAM,GAAG,IAAI,IAAI,EAAE;AACtB,QAAA,QAAQ,GAAG,CAAC,IAAI;YACd,KAAK,eAAe,EAAE;gBACpB,MAAM,IAAI,KAAK,CACb,CAAA,kHAAA;sBACE,CAAA,oGAAA;sBACA,CAAA,+GAAA;AACA,sBAAA,CAAA,uEAAA,CAAyE,CAC5E;YACH;;IAEJ;AACF;AAEM,SAAU,YAAY,CAAC,IAAc,EAAA;AACzC,IAAA,IAAI,IAAI,CAAC,MAAM,IAAI,CAAC,EAAE;AACpB,QAAA,MAAM,IAAI,KAAK,CACb,kIAAkI,CACnI;IACH;IAEA,MAAM,QAAQ,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE;IAEtC,IAAI,CAACA,WAAW,CAAC,QAAQ,CAAC,EAAE;QAC1B,MAAM,IAAI,KAAK,CACb;cACE;cACA;cACA;AACA,cAAA,qGAAqG,CACxG;IACH;AAEA,IAAA,OAAO,QAAQ;AACjB;;;;;;"}
|
|
@@ -3,4 +3,3 @@ import { CompilerOption } from './package';
|
|
|
3
3
|
export declare function applyTemplateCompilerOptions(opts: CompilerOption[], tpl: TemplateDataV3): void;
|
|
4
4
|
export declare function applyLibraryCompilerOptions(opts: CompilerOption[], _lib: TemplateLibDataV3): void;
|
|
5
5
|
export declare function hashOverride(args: string[]): string;
|
|
6
|
-
//# sourceMappingURL=compileroptions.d.ts.map
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { isUUID } from './util.js';
|
|
2
|
+
|
|
3
|
+
function applyTemplateCompilerOptions(opts, tpl) {
|
|
4
|
+
for (const opt of opts) {
|
|
5
|
+
switch (opt.name) {
|
|
6
|
+
case 'hash_override': {
|
|
7
|
+
tpl.hashOverride = hashOverride(opt.args);
|
|
8
|
+
break;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
function applyLibraryCompilerOptions(opts, _lib) {
|
|
14
|
+
for (const opt of opts) {
|
|
15
|
+
switch (opt.name) {
|
|
16
|
+
case 'hash_override': {
|
|
17
|
+
throw new Error(`hash_override compiler option can be used ONLY on template level. Even in templates it is already dangerous enough`
|
|
18
|
+
+ ` to potentially break everything in Platforma Backend. In libraries with the transitive dependencies`
|
|
19
|
+
+ ` resolution and flattening of libraries list on template level, it becomes so unpredictibally disasterous, that`
|
|
20
|
+
+ ` we are doomed to never find the ends of a knot if anything goes wrong.`);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
function hashOverride(args) {
|
|
26
|
+
if (args.length != 1) {
|
|
27
|
+
throw new Error('hash_override compiler option expects exactly one argument: hash_override <some string>. Note, you can use only UUID as a value.');
|
|
28
|
+
}
|
|
29
|
+
const override = args[0].toLowerCase();
|
|
30
|
+
if (!isUUID(override)) {
|
|
31
|
+
throw new Error('hash_override must contain valid UUID as an override. As hash_override affects deduplication,'
|
|
32
|
+
+ ' it becomes completely not possible to distinguish several different templates from each other on backend\'s side.'
|
|
33
|
+
+ ' This means, if you set hash_override to a simple value (say, letter "a") on two completely different templates,'
|
|
34
|
+
+ ' they will be marked as interchangeable on backend\'s side with unpredictable consequences.'
|
|
35
|
+
+ ' UUID looks like a safe enough tradeoff between the feature usage simplicity and duplication safety');
|
|
36
|
+
}
|
|
37
|
+
return override;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export { applyLibraryCompilerOptions, applyTemplateCompilerOptions, hashOverride };
|
|
41
|
+
//# sourceMappingURL=compileroptions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compileroptions.js","sources":["../../src/compiler/compileroptions.ts"],"sourcesContent":["import type { TemplateDataV3, TemplateLibDataV3 } from '@milaboratories/pl-model-backend';\nimport type { CompilerOption } from './package';\nimport * as util from './util';\n\nexport function applyTemplateCompilerOptions(opts: CompilerOption[], tpl: TemplateDataV3) {\n for (const opt of opts) {\n switch (opt.name) {\n case 'hash_override': {\n tpl.hashOverride = hashOverride(opt.args);\n break;\n }\n }\n }\n}\n\nexport function applyLibraryCompilerOptions(opts: CompilerOption[], _lib: TemplateLibDataV3) {\n for (const opt of opts) {\n switch (opt.name) {\n case 'hash_override': {\n throw new Error(\n `hash_override compiler option can be used ONLY on template level. Even in templates it is already dangerous enough`\n + ` to potentially break everything in Platforma Backend. In libraries with the transitive dependencies`\n + ` resolution and flattening of libraries list on template level, it becomes so unpredictibally disasterous, that`\n + ` we are doomed to never find the ends of a knot if anything goes wrong.`,\n );\n }\n }\n }\n}\n\nexport function hashOverride(args: string[]): string {\n if (args.length != 1) {\n throw new Error(\n 'hash_override compiler option expects exactly one argument: hash_override <some string>. Note, you can use only UUID as a value.',\n );\n }\n\n const override = args[0].toLowerCase();\n\n if (!util.isUUID(override)) {\n throw new Error(\n 'hash_override must contain valid UUID as an override. As hash_override affects deduplication,'\n + ' it becomes completely not possible to distinguish several different templates from each other on backend\\'s side.'\n + ' This means, if you set hash_override to a simple value (say, letter \"a\") on two completely different templates,'\n + ' they will be marked as interchangeable on backend\\'s side with unpredictable consequences.'\n + ' UUID looks like a safe enough tradeoff between the feature usage simplicity and duplication safety',\n );\n }\n\n return override;\n}\n"],"names":["util.isUUID"],"mappings":";;AAIM,SAAU,4BAA4B,CAAC,IAAsB,EAAE,GAAmB,EAAA;AACtF,IAAA,KAAK,MAAM,GAAG,IAAI,IAAI,EAAE;AACtB,QAAA,QAAQ,GAAG,CAAC,IAAI;YACd,KAAK,eAAe,EAAE;gBACpB,GAAG,CAAC,YAAY,GAAG,YAAY,CAAC,GAAG,CAAC,IAAI,CAAC;gBACzC;YACF;;IAEJ;AACF;AAEM,SAAU,2BAA2B,CAAC,IAAsB,EAAE,IAAuB,EAAA;AACzF,IAAA,KAAK,MAAM,GAAG,IAAI,IAAI,EAAE;AACtB,QAAA,QAAQ,GAAG,CAAC,IAAI;YACd,KAAK,eAAe,EAAE;gBACpB,MAAM,IAAI,KAAK,CACb,CAAA,kHAAA;sBACE,CAAA,oGAAA;sBACA,CAAA,+GAAA;AACA,sBAAA,CAAA,uEAAA,CAAyE,CAC5E;YACH;;IAEJ;AACF;AAEM,SAAU,YAAY,CAAC,IAAc,EAAA;AACzC,IAAA,IAAI,IAAI,CAAC,MAAM,IAAI,CAAC,EAAE;AACpB,QAAA,MAAM,IAAI,KAAK,CACb,kIAAkI,CACnI;IACH;IAEA,MAAM,QAAQ,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE;IAEtC,IAAI,CAACA,MAAW,CAAC,QAAQ,CAAC,EAAE;QAC1B,MAAM,IAAI,KAAK,CACb;cACE;cACA;cACA;AACA,cAAA,qGAAqG,CACxG;IACH;AAEA,IAAA,OAAO,QAAQ;AACjB;;;;"}
|