@platforma-sdk/tengo-builder 2.4.13 → 2.4.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.
Files changed (123) hide show
  1. package/README.md +4 -4
  2. package/bin/run.js +5 -5
  3. package/dist/commands/build.cjs +36 -36
  4. package/dist/commands/build.cjs.map +1 -1
  5. package/dist/commands/build.d.ts +5 -5
  6. package/dist/commands/build.js +36 -36
  7. package/dist/commands/build.js.map +1 -1
  8. package/dist/commands/check.cjs +5 -5
  9. package/dist/commands/check.cjs.map +1 -1
  10. package/dist/commands/check.d.ts +2 -2
  11. package/dist/commands/check.d.ts.map +1 -1
  12. package/dist/commands/check.js +5 -5
  13. package/dist/commands/check.js.map +1 -1
  14. package/dist/commands/dump/artifacts.cjs +4 -6
  15. package/dist/commands/dump/artifacts.cjs.map +1 -1
  16. package/dist/commands/dump/artifacts.d.ts +2 -2
  17. package/dist/commands/dump/artifacts.d.ts.map +1 -1
  18. package/dist/commands/dump/artifacts.js +4 -6
  19. package/dist/commands/dump/artifacts.js.map +1 -1
  20. package/dist/commands/dump/software.cjs +3 -5
  21. package/dist/commands/dump/software.cjs.map +1 -1
  22. package/dist/commands/dump/software.d.ts +2 -2
  23. package/dist/commands/dump/software.d.ts.map +1 -1
  24. package/dist/commands/dump/software.js +3 -5
  25. package/dist/commands/dump/software.js.map +1 -1
  26. package/dist/commands/test.cjs +5 -5
  27. package/dist/commands/test.cjs.map +1 -1
  28. package/dist/commands/test.d.ts +2 -2
  29. package/dist/commands/test.d.ts.map +1 -1
  30. package/dist/commands/test.js +5 -5
  31. package/dist/commands/test.js.map +1 -1
  32. package/dist/compiler/artifactset.cjs +2 -2
  33. package/dist/compiler/artifactset.cjs.map +1 -1
  34. package/dist/compiler/artifactset.d.ts +1 -1
  35. package/dist/compiler/artifactset.d.ts.map +1 -1
  36. package/dist/compiler/artifactset.js +2 -2
  37. package/dist/compiler/artifactset.js.map +1 -1
  38. package/dist/compiler/compiler.cjs +37 -34
  39. package/dist/compiler/compiler.cjs.map +1 -1
  40. package/dist/compiler/compiler.d.ts +3 -3
  41. package/dist/compiler/compiler.d.ts.map +1 -1
  42. package/dist/compiler/compiler.js +37 -34
  43. package/dist/compiler/compiler.js.map +1 -1
  44. package/dist/compiler/compileroptions.cjs +12 -12
  45. package/dist/compiler/compileroptions.cjs.map +1 -1
  46. package/dist/compiler/compileroptions.d.ts +2 -2
  47. package/dist/compiler/compileroptions.js +12 -12
  48. package/dist/compiler/compileroptions.js.map +1 -1
  49. package/dist/compiler/main.cjs +58 -58
  50. package/dist/compiler/main.cjs.map +1 -1
  51. package/dist/compiler/main.d.ts +6 -6
  52. package/dist/compiler/main.d.ts.map +1 -1
  53. package/dist/compiler/main.js +58 -58
  54. package/dist/compiler/main.js.map +1 -1
  55. package/dist/compiler/package.cjs +5 -2
  56. package/dist/compiler/package.cjs.map +1 -1
  57. package/dist/compiler/package.d.ts +6 -6
  58. package/dist/compiler/package.d.ts.map +1 -1
  59. package/dist/compiler/package.js +5 -2
  60. package/dist/compiler/package.js.map +1 -1
  61. package/dist/compiler/source.cjs +50 -52
  62. package/dist/compiler/source.cjs.map +1 -1
  63. package/dist/compiler/source.d.ts +2 -2
  64. package/dist/compiler/source.d.ts.map +1 -1
  65. package/dist/compiler/source.js +50 -52
  66. package/dist/compiler/source.js.map +1 -1
  67. package/dist/compiler/template.cjs +7 -7
  68. package/dist/compiler/template.cjs.map +1 -1
  69. package/dist/compiler/template.d.ts +2 -2
  70. package/dist/compiler/template.d.ts.map +1 -1
  71. package/dist/compiler/template.js +7 -7
  72. package/dist/compiler/template.js.map +1 -1
  73. package/dist/compiler/test.artifacts.d.ts +1 -1
  74. package/dist/compiler/test.artifacts.d.ts.map +1 -1
  75. package/dist/compiler/util.cjs +12 -12
  76. package/dist/compiler/util.cjs.map +1 -1
  77. package/dist/compiler/util.d.ts +2 -2
  78. package/dist/compiler/util.js +12 -12
  79. package/dist/compiler/util.js.map +1 -1
  80. package/dist/index.cjs +5 -5
  81. package/dist/index.cjs.map +1 -1
  82. package/dist/index.d.ts +7 -7
  83. package/dist/index.js +5 -5
  84. package/dist/index.js.map +1 -1
  85. package/dist/shared/basecmd.cjs +15 -15
  86. package/dist/shared/basecmd.cjs.map +1 -1
  87. package/dist/shared/basecmd.d.ts +4 -4
  88. package/dist/shared/basecmd.js +15 -15
  89. package/dist/shared/basecmd.js.map +1 -1
  90. package/dist/shared/dump.cjs +28 -28
  91. package/dist/shared/dump.cjs.map +1 -1
  92. package/dist/shared/dump.d.ts +2 -2
  93. package/dist/shared/dump.d.ts.map +1 -1
  94. package/dist/shared/dump.js +28 -28
  95. package/dist/shared/dump.js.map +1 -1
  96. package/dist/shared/proc.cjs +5 -5
  97. package/dist/shared/proc.cjs.map +1 -1
  98. package/dist/shared/proc.d.ts +2 -2
  99. package/dist/shared/proc.js +5 -5
  100. package/dist/shared/proc.js.map +1 -1
  101. package/package.json +21 -19
  102. package/src/commands/build.ts +57 -55
  103. package/src/commands/check.ts +15 -12
  104. package/src/commands/dump/artifacts.ts +11 -15
  105. package/src/commands/dump/software.ts +9 -10
  106. package/src/commands/test.ts +15 -12
  107. package/src/compiler/artifactset.ts +7 -9
  108. package/src/compiler/compiler.test.ts +134 -137
  109. package/src/compiler/compiler.ts +62 -62
  110. package/src/compiler/compileroptions.ts +15 -15
  111. package/src/compiler/main.test.ts +23 -23
  112. package/src/compiler/main.ts +83 -100
  113. package/src/compiler/package.ts +14 -12
  114. package/src/compiler/source.test.ts +191 -183
  115. package/src/compiler/source.ts +106 -79
  116. package/src/compiler/template.test.ts +50 -49
  117. package/src/compiler/template.ts +11 -21
  118. package/src/compiler/test.artifacts.ts +47 -47
  119. package/src/compiler/util.ts +17 -17
  120. package/src/index.ts +10 -10
  121. package/src/shared/basecmd.ts +16 -16
  122. package/src/shared/dump.ts +49 -70
  123. package/src/shared/proc.ts +8 -8
@@ -1,4 +1,4 @@
1
- import { readFileSync } from 'node:fs';
1
+ import { readFileSync } from "node:fs";
2
2
  import {
3
3
  type TypedArtifactName,
4
4
  type FullArtifactName,
@@ -6,42 +6,42 @@ import {
6
6
  type CompileMode,
7
7
  type CompilerOption,
8
8
  fullNameToString,
9
- } from './package';
10
- import type { ArtifactMap } from './artifactset';
11
- import { createArtifactNameSet } from './artifactset';
12
- import { createHash } from 'node:crypto';
13
- import type { MiLogger } from '@milaboratories/ts-helpers';
9
+ } from "./package";
10
+ import type { ArtifactMap } from "./artifactset";
11
+ import { createArtifactNameSet } from "./artifactset";
12
+ import { createHash } from "node:crypto";
13
+ import type { MiLogger } from "@milaboratories/ts-helpers";
14
14
 
15
15
  // matches any valid name in tengo. Don't forget to use '\b' when needed to limit the boundaries!
16
- const namePattern = '[_a-zA-Z][_a-zA-Z0-9]*';
16
+ const namePattern = "[_a-zA-Z][_a-zA-Z0-9]*";
17
17
 
18
18
  const functionCallRE = (moduleName: string, fnName: string) => {
19
19
  return new RegExp(
20
- `\\b${moduleName}\\.(?<fnCall>(?<fnName>`
21
- + fnName
22
- + `)\\s*\\(\\s*"(?<templateName>[^"]+)"\\s*\\))`,
23
- 'g',
20
+ `\\b${moduleName}\\.(?<fnCall>(?<fnName>` +
21
+ fnName +
22
+ `)\\s*\\(\\s*"(?<templateName>[^"]+)"\\s*\\))`,
23
+ "g",
24
24
  );
25
25
  };
26
26
 
27
27
  const functionCallLikeRE = (moduleName: string, fnName: string) => {
28
- return new RegExp(
29
- `\\b${moduleName}\\.(?<fnName>`
30
- + fnName
31
- + `)\\s*\\(`,
32
- 'g',
33
- );
28
+ return new RegExp(`\\b${moduleName}\\.(?<fnName>` + fnName + `)\\s*\\(`, "g");
34
29
  };
35
30
 
36
- export const newGetTemplateIdRE = (moduleName: string) => functionCallRE(moduleName, 'getTemplateId');
37
- export const newGetSoftwareInfoRE = (moduleName: string) => functionCallRE(moduleName, 'getSoftwareInfo');
38
-
39
- const newImportTemplateRE = (moduleName: string) => functionCallRE(moduleName, 'importTemplate');
40
- const newImportTemplateDetector = (moduleName: string) => functionCallLikeRE(moduleName, 'importTemplate');
41
- const newImportSoftwareRE = (moduleName: string) => functionCallRE(moduleName, 'importSoftware');
42
- const newImportSoftwareDetector = (moduleName: string) => functionCallLikeRE(moduleName, 'importSoftware');
43
- const newImportAssetRE = (moduleName: string) => functionCallRE(moduleName, 'importAsset');
44
- const newImportAssetDetector = (moduleName: string) => functionCallLikeRE(moduleName, 'importAsset');
31
+ export const newGetTemplateIdRE = (moduleName: string) =>
32
+ functionCallRE(moduleName, "getTemplateId");
33
+ export const newGetSoftwareInfoRE = (moduleName: string) =>
34
+ functionCallRE(moduleName, "getSoftwareInfo");
35
+
36
+ const newImportTemplateRE = (moduleName: string) => functionCallRE(moduleName, "importTemplate");
37
+ const newImportTemplateDetector = (moduleName: string) =>
38
+ functionCallLikeRE(moduleName, "importTemplate");
39
+ const newImportSoftwareRE = (moduleName: string) => functionCallRE(moduleName, "importSoftware");
40
+ const newImportSoftwareDetector = (moduleName: string) =>
41
+ functionCallLikeRE(moduleName, "importSoftware");
42
+ const newImportAssetRE = (moduleName: string) => functionCallRE(moduleName, "importAsset");
43
+ const newImportAssetDetector = (moduleName: string) =>
44
+ functionCallLikeRE(moduleName, "importAsset");
45
45
 
46
46
  const emptyLineRE = /^\s*$/;
47
47
  const compilerOptionRE = /^\/\/tengo:[\w]/;
@@ -69,11 +69,11 @@ const dependencyRE = /(?<pkgName>[^"]+)?:(?<depID>[^"]+)/; // use it to parse <m
69
69
  * //tengo:<option name> [<option arg1> [<option arg 2> [...]]]
70
70
  */
71
71
  const parseComplierOption = (opt: string): CompilerOption => {
72
- const parts = opt.split(' ');
73
- const namePart = parts[0].split(':');
72
+ const parts = opt.split(" ");
73
+ const namePart = parts[0].split(":");
74
74
  if (namePart.length != 2) {
75
75
  throw new Error(
76
- 'compiler option format is wrong: expect to have option name after \'tengo:\' prefix, like \'tengo:MyOption\'',
76
+ "compiler option format is wrong: expect to have option name after 'tengo:' prefix, like 'tengo:MyOption'",
77
77
  );
78
78
  }
79
79
  const optName = namePart[1];
@@ -133,7 +133,15 @@ export function parseSource(
133
133
  ): ArtifactSource {
134
134
  const { deps, normalized, opts } = parseSourceData(logger, src, fullSourceName, normalize);
135
135
 
136
- return new ArtifactSource(mode, fullSourceName, getSha256(normalized), normalized, '', deps.array, opts);
136
+ return new ArtifactSource(
137
+ mode,
138
+ fullSourceName,
139
+ getSha256(normalized),
140
+ normalized,
141
+ "",
142
+ deps.array,
143
+ opts,
144
+ );
137
145
  }
138
146
 
139
147
  /**
@@ -149,15 +157,15 @@ function parseSourceData(
149
157
  fullSourceName: FullArtifactName,
150
158
  globalizeImports: boolean,
151
159
  ): {
152
- normalized: string;
153
- deps: ArtifactMap<TypedArtifactName>;
154
- opts: CompilerOption[];
155
- } {
160
+ normalized: string;
161
+ deps: ArtifactMap<TypedArtifactName>;
162
+ opts: CompilerOption[];
163
+ } {
156
164
  const dependencySet = createArtifactNameSet();
157
165
  const optionList: CompilerOption[] = [];
158
166
 
159
167
  // iterating over lines
160
- const lines = src.split('\n');
168
+ const lines = src.split("\n");
161
169
 
162
170
  // processedLines keep all the original lines from <src>.
163
171
  // If <globalizeImport>==true, the parser modifies 'import' and 'getTemplateId' lines
@@ -169,7 +177,7 @@ function parseSourceData(
169
177
  canDetectOptions: true,
170
178
  artifactImportREs: new Map<string, [ArtifactType, RegExp][]>(),
171
179
  importLikeREs: new Map<string, [ArtifactType, RegExp][]>(),
172
- multilineStatement: '',
180
+ multilineStatement: "",
173
181
  lineNo: 0,
174
182
  };
175
183
 
@@ -177,13 +185,12 @@ function parseSourceData(
177
185
  parserContext.lineNo++;
178
186
 
179
187
  try {
180
- const { line: processedLine, context: newContext, artifacts, option } = parseSingleSourceLine(
181
- logger,
182
- line,
183
- parserContext,
184
- fullSourceName.pkg,
185
- globalizeImports,
186
- );
188
+ const {
189
+ line: processedLine,
190
+ context: newContext,
191
+ artifacts,
192
+ option,
193
+ } = parseSingleSourceLine(logger, line, parserContext, fullSourceName.pkg, globalizeImports);
187
194
  processedLines.push(processedLine);
188
195
  parserContext = newContext;
189
196
 
@@ -195,12 +202,15 @@ function parseSourceData(
195
202
  }
196
203
  } catch (error: unknown) {
197
204
  const err = error as Error;
198
- throw new Error(`[line ${parserContext.lineNo} in ${fullNameToString(fullSourceName)}]: ${err.message}\n\t${line}`, { cause: err });
205
+ throw new Error(
206
+ `[line ${parserContext.lineNo} in ${fullNameToString(fullSourceName)}]: ${err.message}\n\t${line}`,
207
+ { cause: err },
208
+ );
199
209
  }
200
210
  }
201
211
 
202
212
  return {
203
- normalized: processedLines.join('\n'),
213
+ normalized: processedLines.join("\n"),
204
214
  deps: dependencySet,
205
215
  opts: optionList,
206
216
  };
@@ -233,7 +243,7 @@ export function parseSingleSourceLine(
233
243
  if (multilineCommentEndRE.exec(line)) {
234
244
  context.isInCommentBlock = false;
235
245
  }
236
- return { line: '', context, artifacts: [], option: undefined };
246
+ return { line: "", context, artifacts: [], option: undefined };
237
247
  }
238
248
 
239
249
  if (compilerOptionRE.exec(line)) {
@@ -241,7 +251,9 @@ export function parseSingleSourceLine(
241
251
  logger.error(
242
252
  `[line ${context.lineNo}]: compiler option '//tengo:' was detected, but it cannot be applied as compiler options can be set only at the file header, before any code line'`,
243
253
  );
244
- throw new Error('tengo compiler options (\'//tengo:\' comments) can be set only in file header');
254
+ throw new Error(
255
+ "tengo compiler options ('//tengo:' comments) can be set only in file header",
256
+ );
245
257
  }
246
258
  return { line, context, artifacts: [], option: parseComplierOption(line) };
247
259
  }
@@ -254,18 +266,18 @@ export function parseSingleSourceLine(
254
266
  }
255
267
 
256
268
  if (singlelineCommentRE.test(line) || singlelineTerminatedCommentRE.test(line)) {
257
- return { line: '', context, artifacts: [], option: undefined };
269
+ return { line: "", context, artifacts: [], option: undefined };
258
270
  }
259
271
 
260
- const canBeInlinedComment = line.includes('*/');
272
+ const canBeInlinedComment = line.includes("*/");
261
273
  if (multilineCommentStartRE.exec(line) && !canBeInlinedComment) {
262
274
  context.isInCommentBlock = true;
263
- return { line: '', context, artifacts: [], option: undefined };
275
+ return { line: "", context, artifacts: [], option: undefined };
264
276
  }
265
277
 
266
278
  const statement = context.multilineStatement + line.trim();
267
279
 
268
- const mayContainAComment = line.includes('//') || line.includes('/*');
280
+ const mayContainAComment = line.includes("//") || line.includes("/*");
269
281
  if (multilineStatementRE.test(line) && !mayContainAComment) {
270
282
  // We accumulate multiline statements into single line before analyzing them.
271
283
  // This dramatically simplifies parsing logic: things like
@@ -295,7 +307,7 @@ export function parseSingleSourceLine(
295
307
  return result;
296
308
  }
297
309
 
298
- context.multilineStatement = ''; // reset accumulated multiline statement parts once we reach statement end.
310
+ context.multilineStatement = ""; // reset accumulated multiline statement parts once we reach statement end.
299
311
 
300
312
  if (emptyLineRE.exec(statement)) {
301
313
  return { line, context, artifacts: [], option: undefined };
@@ -320,60 +332,63 @@ function processModuleImport(
320
332
  // If we have plapi, ll or assets, then try to parse
321
333
  // getTemplateId, getSoftwareInfo, getSoftware and getAsset calls.
322
334
 
323
- if (iInfo.module === 'plapi') {
335
+ if (iInfo.module === "plapi") {
324
336
  if (!context.artifactImportREs.has(iInfo.module)) {
325
337
  context.artifactImportREs.set(iInfo.module, [
326
- ['template', newGetTemplateIdRE(iInfo.alias)],
327
- ['software', newGetSoftwareInfoRE(iInfo.alias)],
338
+ ["template", newGetTemplateIdRE(iInfo.alias)],
339
+ ["software", newGetSoftwareInfoRE(iInfo.alias)],
328
340
  ]);
329
341
  }
330
342
  return { line: originalLine, context, artifacts: [], option: undefined };
331
343
  }
332
344
 
333
345
  if (
334
- iInfo.module === '@milaboratory/tengo-sdk:ll'
335
- || iInfo.module === '@platforma-sdk/workflow-tengo:ll'
336
- || ((localPackageName === '@milaboratory/tengo-sdk'
337
- || localPackageName === '@platforma-sdk/workflow-tengo')
338
- && iInfo.module === ':ll')
346
+ iInfo.module === "@milaboratory/tengo-sdk:ll" ||
347
+ iInfo.module === "@platforma-sdk/workflow-tengo:ll" ||
348
+ ((localPackageName === "@milaboratory/tengo-sdk" ||
349
+ localPackageName === "@platforma-sdk/workflow-tengo") &&
350
+ iInfo.module === ":ll")
339
351
  ) {
340
352
  if (!context.artifactImportREs.has(iInfo.module)) {
341
353
  context.artifactImportREs.set(iInfo.module, [
342
- ['template', newImportTemplateRE(iInfo.alias)],
343
- ['software', newImportSoftwareRE(iInfo.alias)],
354
+ ["template", newImportTemplateRE(iInfo.alias)],
355
+ ["software", newImportSoftwareRE(iInfo.alias)],
344
356
  ]);
345
357
  }
346
358
  }
347
359
 
348
360
  if (
349
- iInfo.module === '@milaboratory/tengo-sdk:assets'
350
- || iInfo.module === '@platforma-sdk/workflow-tengo:assets'
351
- || ((localPackageName === '@milaboratory/tengo-sdk'
352
- || localPackageName === '@platforma-sdk/workflow-tengo')
353
- && iInfo.module === ':assets')
361
+ iInfo.module === "@milaboratory/tengo-sdk:assets" ||
362
+ iInfo.module === "@platforma-sdk/workflow-tengo:assets" ||
363
+ ((localPackageName === "@milaboratory/tengo-sdk" ||
364
+ localPackageName === "@platforma-sdk/workflow-tengo") &&
365
+ iInfo.module === ":assets")
354
366
  ) {
355
367
  if (!context.artifactImportREs.has(iInfo.module)) {
356
368
  context.artifactImportREs.set(iInfo.module, [
357
- ['template', newImportTemplateRE(iInfo.alias)],
358
- ['software', newImportSoftwareRE(iInfo.alias)],
359
- ['asset', newImportAssetRE(iInfo.alias)],
369
+ ["template", newImportTemplateRE(iInfo.alias)],
370
+ ["software", newImportSoftwareRE(iInfo.alias)],
371
+ ["asset", newImportAssetRE(iInfo.alias)],
360
372
  ]);
361
373
  context.importLikeREs.set(iInfo.module, [
362
- ['template', newImportTemplateDetector(iInfo.alias)],
363
- ['software', newImportSoftwareDetector(iInfo.alias)],
364
- ['asset', newImportAssetDetector(iInfo.alias)],
374
+ ["template", newImportTemplateDetector(iInfo.alias)],
375
+ ["software", newImportSoftwareDetector(iInfo.alias)],
376
+ ["asset", newImportAssetDetector(iInfo.alias)],
365
377
  ]);
366
378
  }
367
379
  }
368
380
 
369
- const artifact = parseArtifactName(iInfo.module, 'library', localPackageName);
381
+ const artifact = parseArtifactName(iInfo.module, "library", localPackageName);
370
382
  if (!artifact) {
371
383
  // not a Platforma Tengo library import
372
384
  return { line: originalLine, context, artifacts: [], option: undefined };
373
385
  }
374
386
 
375
387
  if (globalizeImports) {
376
- originalLine = originalLine.replace(importInstruction[0], ` := import("${artifact.pkg}:${artifact.id}")`);
388
+ originalLine = originalLine.replace(
389
+ importInstruction[0],
390
+ ` := import("${artifact.pkg}:${artifact.id}")`,
391
+ );
377
392
  }
378
393
 
379
394
  return { line: originalLine, context, artifacts: [artifact], option: undefined };
@@ -396,7 +411,14 @@ function processAssetImport(
396
411
  const importInstruction = importRE.exec(statement);
397
412
 
398
413
  if (importInstruction) {
399
- return processModuleImport(importInstruction, originalLine, statement, context, localPackageName, globalizeImports);
414
+ return processModuleImport(
415
+ importInstruction,
416
+ originalLine,
417
+ statement,
418
+ context,
419
+ localPackageName,
420
+ globalizeImports,
421
+ );
400
422
  }
401
423
 
402
424
  if (context.artifactImportREs.size > 0) {
@@ -429,7 +451,10 @@ function processAssetImport(
429
451
 
430
452
  if (globalizeImports) {
431
453
  // Replace all occurrences of this fnCall in originalLine
432
- originalLine = originalLine.replaceAll(fnCall, `${fnName}("${artifact.pkg}:${artifact.id}")`);
454
+ originalLine = originalLine.replaceAll(
455
+ fnCall,
456
+ `${fnName}("${artifact.pkg}:${artifact.id}")`,
457
+ );
433
458
  }
434
459
  }
435
460
 
@@ -446,7 +471,9 @@ function processAssetImport(
446
471
  continue;
447
472
  }
448
473
 
449
- throw Error(`incorrect '${artifactType}' import statement: use string literal as ID (variables are not allowed) in the same line with brackets (i.e. 'importSoftware("sw:main")').`);
474
+ throw Error(
475
+ `incorrect '${artifactType}' import statement: use string literal as ID (variables are not allowed) in the same line with brackets (i.e. 'importSoftware("sw:main")').`,
476
+ );
450
477
  }
451
478
  }
452
479
  }
@@ -504,5 +531,5 @@ function parseArtifactName(
504
531
  }
505
532
 
506
533
  export function getSha256(source: string): string {
507
- return createHash('sha256').update(source).digest('hex');
534
+ return createHash("sha256").update(source).digest("hex");
508
535
  }
@@ -1,64 +1,65 @@
1
- import { newTemplateFromContent, newTemplateFromData, Template } from './template';
2
- import { formatArtefactNameAndVersion, FullArtifactName } from './package';
3
- import { test, expect } from 'vitest';
1
+ import { newTemplateFromContent, newTemplateFromData } from "./template";
2
+ import { formatArtefactNameAndVersion, FullArtifactName } from "./package";
3
+ import { test, expect } from "vitest";
4
4
 
5
- test('template serialization / deserialization', () => {
5
+ test("template serialization / deserialization", () => {
6
6
  const name: FullArtifactName = {
7
- type: 'template',
8
- pkg: '@milaboratory/some-package',
9
- id: 'the-template',
10
- version: '1.2.3'
7
+ type: "template",
8
+ pkg: "@milaboratory/some-package",
9
+ id: "the-template",
10
+ version: "1.2.3",
11
11
  };
12
- const template1 = newTemplateFromData(
13
- 'dist',
14
- name,
15
- {
16
- type: 'pl.tengo-template.v3',
17
- hashToSource: {
18
- "asdasd": "src1...",
19
- "asdasd2": "src2...",
20
- "asdasd3": "src3...",
21
- },
22
- template: {
23
- sourceHash: "asdasd3",
24
- ...formatArtefactNameAndVersion(name),
25
- libs: {
26
- 'asdasd': {
27
- name: '@milaboratory/some-package:the-library',
28
- version: '1.2.3',
29
- sourceHash: 'asdasd'
30
- }
12
+ const template1 = newTemplateFromData("dist", name, {
13
+ type: "pl.tengo-template.v3",
14
+ hashToSource: {
15
+ asdasd: "src1...",
16
+ asdasd2: "src2...",
17
+ asdasd3: "src3...",
18
+ },
19
+ template: {
20
+ sourceHash: "asdasd3",
21
+ ...formatArtefactNameAndVersion(name),
22
+ libs: {
23
+ asdasd: {
24
+ name: "@milaboratory/some-package:the-library",
25
+ version: "1.2.3",
26
+ sourceHash: "asdasd",
31
27
  },
32
- templates: {
33
- 'asdasd2': {
34
- name: '@milaboratory/some-package:the-template-1',
35
- version: '1.2.3',
36
- libs: {
37
- '@milaboratory/some-package:the-library:1.2.4': {
38
- name: '@milaboratory/some-package:the-library',
39
- version: '1.2.4',
40
- sourceHash: 'asdasd2'
41
- }
28
+ },
29
+ templates: {
30
+ asdasd2: {
31
+ name: "@milaboratory/some-package:the-template-1",
32
+ version: "1.2.3",
33
+ libs: {
34
+ "@milaboratory/some-package:the-library:1.2.4": {
35
+ name: "@milaboratory/some-package:the-library",
36
+ version: "1.2.4",
37
+ sourceHash: "asdasd2",
42
38
  },
43
- templates: {},
44
- software: {},
45
- assets: {},
46
- sourceHash: 'src 1...'
47
- }
39
+ },
40
+ templates: {},
41
+ software: {},
42
+ assets: {},
43
+ sourceHash: "src 1...",
48
44
  },
49
- software: {},
50
- assets: {},
51
45
  },
52
- }
53
- );
46
+ software: {},
47
+ assets: {},
48
+ },
49
+ });
54
50
 
55
51
  const template2 = newTemplateFromContent(
56
- 'dist',
57
- { type: 'template', pkg: '@milaboratory/some-package', id: 'the-template', version: '1.2.3' },
52
+ "dist",
53
+ { type: "template", pkg: "@milaboratory/some-package", id: "the-template", version: "1.2.3" },
58
54
  template1.content,
59
55
  );
60
56
 
61
- console.log('Size: raw', JSON.stringify(template1.data).length, 'compressed', template1.content.byteLength);
57
+ console.log(
58
+ "Size: raw",
59
+ JSON.stringify(template1.data).length,
60
+ "compressed",
61
+ template1.content.byteLength,
62
+ );
62
63
 
63
64
  expect(template2.data).toStrictEqual(template1.data);
64
65
  });
@@ -1,17 +1,7 @@
1
- import type {
2
- CompileMode,
3
- FullArtifactName,
4
- FullArtifactNameWithoutType,
5
- } from './package';
6
- import {
7
- fullNameWithoutTypeToString,
8
- parseArtefactNameAndVersion,
9
- } from './package';
10
- import type { CompiledTemplateV3 } from '@milaboratories/pl-model-backend';
11
- import {
12
- parseTemplate,
13
- serializeTemplate,
14
- } from '@milaboratories/pl-model-backend';
1
+ import type { CompileMode, FullArtifactName, FullArtifactNameWithoutType } from "./package";
2
+ import { fullNameWithoutTypeToString, parseArtefactNameAndVersion } from "./package";
3
+ import type { CompiledTemplateV3 } from "@milaboratories/pl-model-backend";
4
+ import { parseTemplate, serializeTemplate } from "@milaboratories/pl-model-backend";
15
5
 
16
6
  /** Just a holder for template data, compilation options, full name and source code.
17
7
  * It mimics ArtifactSource interface.
@@ -66,8 +56,8 @@ export function newTemplateFromContent(
66
56
  content: Uint8Array,
67
57
  ): Template {
68
58
  const data = parseTemplate(content);
69
- if (data.type !== 'pl.tengo-template.v3') {
70
- throw new Error('malformed v3 template');
59
+ if (data.type !== "pl.tengo-template.v3") {
60
+ throw new Error("malformed v3 template");
71
61
  }
72
62
 
73
63
  validateTemplateName(fullName, data);
@@ -91,12 +81,12 @@ function validateTemplateName(fullName: FullArtifactName, data: CompiledTemplate
91
81
  const nameFromData: FullArtifactNameWithoutType = parseArtefactNameAndVersion(data.template);
92
82
 
93
83
  if (
94
- nameFromData.pkg !== fullName.pkg
95
- || nameFromData.id !== fullName.id
96
- || nameFromData.version !== fullName.version
84
+ nameFromData.pkg !== fullName.pkg ||
85
+ nameFromData.id !== fullName.id ||
86
+ nameFromData.version !== fullName.version
97
87
  )
98
88
  throw new Error(
99
- `Compiled template name don't match it's package and file names: `
100
- + `${fullNameWithoutTypeToString(nameFromData)} != ${fullNameWithoutTypeToString(fullName)}`,
89
+ `Compiled template name don't match it's package and file names: ` +
90
+ `${fullNameWithoutTypeToString(nameFromData)} != ${fullNameWithoutTypeToString(fullName)}`,
101
91
  );
102
92
  }