@platforma-sdk/tengo-builder 4.0.9 → 4.0.11

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 (93) hide show
  1. package/bin/run.js +5 -10
  2. package/dist/cli.cjs +27 -0
  3. package/dist/cli.cjs.map +1 -0
  4. package/dist/cli.d.ts +8 -0
  5. package/dist/cli.d.ts.map +1 -0
  6. package/dist/cli.js +26 -0
  7. package/dist/cli.js.map +1 -0
  8. package/dist/commands/build.cjs +18 -16
  9. package/dist/commands/build.cjs.map +1 -1
  10. package/dist/commands/build.js +16 -14
  11. package/dist/commands/build.js.map +1 -1
  12. package/dist/commands/check.cjs +13 -15
  13. package/dist/commands/check.cjs.map +1 -1
  14. package/dist/commands/check.js +14 -15
  15. package/dist/commands/check.js.map +1 -1
  16. package/dist/commands/dump/artifacts.cjs +10 -15
  17. package/dist/commands/dump/artifacts.cjs.map +1 -1
  18. package/dist/commands/dump/artifacts.js +11 -15
  19. package/dist/commands/dump/artifacts.js.map +1 -1
  20. package/dist/commands/dump/software.cjs +10 -12
  21. package/dist/commands/dump/software.cjs.map +1 -1
  22. package/dist/commands/dump/software.js +11 -12
  23. package/dist/commands/dump/software.js.map +1 -1
  24. package/dist/commands/test.cjs +13 -15
  25. package/dist/commands/test.cjs.map +1 -1
  26. package/dist/commands/test.js +14 -15
  27. package/dist/commands/test.js.map +1 -1
  28. package/dist/compiler/artifactset.cjs +2 -0
  29. package/dist/compiler/artifactset.cjs.map +1 -1
  30. package/dist/compiler/artifactset.js +2 -1
  31. package/dist/compiler/artifactset.js.map +1 -1
  32. package/dist/compiler/compiler.cjs +1 -0
  33. package/dist/compiler/compiler.cjs.map +1 -1
  34. package/dist/compiler/compiler.js +1 -0
  35. package/dist/compiler/compiler.js.map +1 -1
  36. package/dist/compiler/compileroptions.cjs +1 -0
  37. package/dist/compiler/compileroptions.cjs.map +1 -1
  38. package/dist/compiler/compileroptions.js +1 -1
  39. package/dist/compiler/compileroptions.js.map +1 -1
  40. package/dist/compiler/main.cjs +5 -3
  41. package/dist/compiler/main.cjs.map +1 -1
  42. package/dist/compiler/main.js +1 -1
  43. package/dist/compiler/main.js.map +1 -1
  44. package/dist/compiler/pack_limits.cjs +2 -0
  45. package/dist/compiler/pack_limits.cjs.map +1 -1
  46. package/dist/compiler/pack_limits.js +1 -1
  47. package/dist/compiler/pack_limits.js.map +1 -1
  48. package/dist/compiler/package.cjs.map +1 -1
  49. package/dist/compiler/package.js.map +1 -1
  50. package/dist/compiler/source.cjs +10 -1
  51. package/dist/compiler/source.cjs.map +1 -1
  52. package/dist/compiler/source.js +8 -1
  53. package/dist/compiler/source.js.map +1 -1
  54. package/dist/compiler/template.cjs +0 -1
  55. package/dist/compiler/template.cjs.map +1 -1
  56. package/dist/compiler/template.js.map +1 -1
  57. package/dist/compiler/util.cjs +3 -3
  58. package/dist/compiler/util.cjs.map +1 -1
  59. package/dist/compiler/util.js.map +1 -1
  60. package/dist/index.cjs +3 -17
  61. package/dist/index.d.ts +2 -17
  62. package/dist/index.js +2 -17
  63. package/dist/shared/basecmd.cjs +33 -45
  64. package/dist/shared/basecmd.cjs.map +1 -1
  65. package/dist/shared/basecmd.js +30 -42
  66. package/dist/shared/basecmd.js.map +1 -1
  67. package/dist/shared/dump.cjs.map +1 -1
  68. package/dist/shared/dump.js.map +1 -1
  69. package/dist/shared/proc.cjs +0 -1
  70. package/dist/shared/proc.cjs.map +1 -1
  71. package/dist/shared/proc.js.map +1 -1
  72. package/package.json +9 -20
  73. package/src/cli.ts +27 -0
  74. package/src/commands/build.ts +16 -12
  75. package/src/commands/check.ts +14 -19
  76. package/src/commands/dump/artifacts.ts +11 -14
  77. package/src/commands/dump/software.ts +11 -13
  78. package/src/commands/test.ts +14 -15
  79. package/src/index.ts +1 -15
  80. package/src/shared/basecmd.ts +36 -32
  81. package/dist/commands/build.d.ts +0 -18
  82. package/dist/commands/build.d.ts.map +0 -1
  83. package/dist/commands/check.d.ts +0 -16
  84. package/dist/commands/check.d.ts.map +0 -1
  85. package/dist/commands/dump/artifacts.d.ts +0 -16
  86. package/dist/commands/dump/artifacts.d.ts.map +0 -1
  87. package/dist/commands/dump/software.d.ts +0 -15
  88. package/dist/commands/dump/software.d.ts.map +0 -1
  89. package/dist/commands/test.d.ts +0 -16
  90. package/dist/commands/test.d.ts.map +0 -1
  91. package/dist/index.cjs.map +0 -1
  92. package/dist/index.d.ts.map +0 -1
  93. package/dist/index.js.map +0 -1
@@ -1,19 +1,18 @@
1
1
  import { createLogger } from "../../compiler/util.js";
2
- import { GlobalFlags } from "../../shared/basecmd.js";
2
+ import { GlobalOptions, addOptions } from "../../shared/basecmd.js";
3
3
  import { dumpSoftware } from "../../shared/dump.js";
4
- import { Command } from "@oclif/core";
4
+ import { Command } from "commander";
5
5
  import { stdout } from "node:process";
6
6
  //#region src/commands/dump/software.ts
7
- var DumpSoftware = class DumpSoftware extends Command {
8
- static description = "parse sources in current package and dump all software descriptors used by templates";
9
- static examples = ["<%= config.bin %> <%= command.id %>"];
10
- static flags = { ...GlobalFlags };
11
- async run() {
12
- const { flags } = await this.parse(DumpSoftware);
13
- dumpSoftware(createLogger(flags["log-level"]), stdout);
14
- }
15
- };
7
+ function dumpSoftwareCommand() {
8
+ const cmd = new Command("software").description("parse sources in current package and dump all software descriptors used by templates");
9
+ addOptions(cmd, GlobalOptions());
10
+ cmd.action(async (o) => {
11
+ dumpSoftware(createLogger(o.logLevel), stdout);
12
+ });
13
+ return cmd;
14
+ }
16
15
  //#endregion
17
- export { DumpSoftware as default };
16
+ export { dumpSoftwareCommand as default };
18
17
 
19
18
  //# sourceMappingURL=software.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"software.js","names":["opts.GlobalFlags"],"sources":["../../../src/commands/dump/software.ts"],"sourcesContent":["import { Command } from \"@oclif/core\";\nimport { createLogger } from \"../../compiler/util\";\nimport { dumpSoftware } from \"../../shared/dump\";\nimport { stdout } from \"node:process\";\nimport * as opts from \"../../shared/basecmd\";\n\nexport default class DumpSoftware extends Command {\n static override description =\n \"parse sources in current package and dump all software descriptors used by templates\";\n\n static override examples = [\"<%= config.bin %> <%= command.id %>\"];\n\n static override flags = {\n ...opts.GlobalFlags,\n };\n\n public async run(): Promise<void> {\n const { flags } = await this.parse(DumpSoftware);\n const logger = createLogger(flags[\"log-level\"]);\n dumpSoftware(logger, stdout);\n }\n}\n"],"mappings":";;;;;;AAMA,IAAqB,eAArB,MAAqB,qBAAqB,QAAQ;CAChD,OAAgB,cACd;CAEF,OAAgB,WAAW,CAAC,sCAAsC;CAElE,OAAgB,QAAQ,EACtB,GAAGA,aACJ;CAED,MAAa,MAAqB;EAChC,MAAM,EAAE,UAAU,MAAM,KAAK,MAAM,aAAa;AAEhD,eADe,aAAa,MAAM,aAAa,EAC1B,OAAO"}
1
+ {"version":3,"file":"software.js","names":["opts.GlobalOptions"],"sources":["../../../src/commands/dump/software.ts"],"sourcesContent":["import { Command } from \"commander\";\nimport { createLogger } from \"../../compiler/util\";\nimport { dumpSoftware } from \"../../shared/dump\";\nimport { stdout } from \"node:process\";\nimport * as opts from \"../../shared/basecmd\";\n\nexport default function dumpSoftwareCommand(): Command {\n const cmd = new Command(\"software\").description(\n \"parse sources in current package and dump all software descriptors used by templates\",\n );\n\n opts.addOptions(cmd, opts.GlobalOptions());\n\n cmd.action(async (o) => {\n const logger = createLogger(o.logLevel as string);\n dumpSoftware(logger, stdout);\n });\n\n return cmd;\n}\n"],"mappings":";;;;;;AAMA,SAAwB,sBAA+B;CACrD,MAAM,MAAM,IAAI,QAAQ,UAAU,CAAC,CAAC,YAClC,sFACF;CAEA,WAAgB,KAAKA,cAAmB,CAAC;CAEzC,IAAI,OAAO,OAAO,MAAM;EAEtB,aADe,aAAa,EAAE,QACZ,GAAG,MAAM;CAC7B,CAAC;CAED,OAAO;AACT"}
@@ -1,21 +1,18 @@
1
- require("../_virtual/_rolldown/runtime.cjs");
2
1
  const require_util = require("../compiler/util.cjs");
3
2
  const require_basecmd = require("../shared/basecmd.cjs");
4
3
  const require_dump = require("../shared/dump.cjs");
5
4
  const require_proc = require("../shared/proc.cjs");
6
- let _oclif_core = require("@oclif/core");
5
+ let commander = require("commander");
7
6
  let _milaboratories_tengo_tester = require("@milaboratories/tengo-tester");
8
7
  //#region src/commands/test.ts
9
- var Test = class Test extends _oclif_core.Command {
10
- static description = "run tengo unit tests (.test.tengo)";
11
- static strict = false;
12
- static flags = { ...require_basecmd.GlobalFlags };
13
- static examples = ["<%= config.bin %> <%= command.id %>"];
14
- async run() {
15
- const { flags } = await this.parse(Test);
16
- const logger = require_util.createLogger(flags["log-level"]);
17
- const testerArgs = this.argv.length == 0 ? ["./src"] : this.argv;
18
- const tester = require_proc.spawnEmbed(_milaboratories_tengo_tester.TengoTesterBinaryPath, "run", "--log-level", flags["log-level"], "--artifacts", "-", ...testerArgs);
8
+ function testCommand() {
9
+ const cmd = new commander.Command("test").description("run tengo unit tests (.test.tengo)");
10
+ cmd.argument("[paths...]", "source paths to test (defaults to ./src)");
11
+ require_basecmd.addOptions(cmd, require_basecmd.GlobalOptions());
12
+ cmd.action(async (paths, o) => {
13
+ const logLevel = o.logLevel;
14
+ const logger = require_util.createLogger(logLevel);
15
+ const tester = require_proc.spawnEmbed(_milaboratories_tengo_tester.TengoTesterBinaryPath, "run", "--log-level", logLevel, "--artifacts", "-", ...paths.length == 0 ? ["./src"] : paths);
19
16
  try {
20
17
  require_dump.dumpArtifacts(logger, tester.stdin);
21
18
  } catch (err) {
@@ -25,9 +22,10 @@ var Test = class Test extends _oclif_core.Command {
25
22
  const code = await require_proc.waitFor(tester);
26
23
  process.exit(code);
27
24
  }
28
- }
29
- };
25
+ });
26
+ return cmd;
27
+ }
30
28
  //#endregion
31
- exports.default = Test;
29
+ exports.default = testCommand;
32
30
 
33
31
  //# sourceMappingURL=test.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"test.cjs","names":["Command","GlobalFlags","createLogger","spawnEmbed","TengoTesterBinaryPath","waitFor"],"sources":["../../src/commands/test.ts"],"sourcesContent":["import { Command } from \"@oclif/core\";\nimport { createLogger } from \"../compiler/util\";\nimport { dumpArtifacts } from \"../shared/dump\";\nimport { GlobalFlags } from \"../shared/basecmd\";\nimport { spawnEmbed, waitFor } from \"../shared/proc\";\nimport { TengoTesterBinaryPath } from \"@milaboratories/tengo-tester\";\n\nexport default class Test extends Command {\n static override description = \"run tengo unit tests (.test.tengo)\";\n\n static strict = false;\n\n static override flags = { ...GlobalFlags };\n\n static override examples = [\"<%= config.bin %> <%= command.id %>\"];\n\n public async run(): Promise<void> {\n const { flags } = await this.parse(Test);\n const logger = createLogger(flags[\"log-level\"]);\n\n const testerArgs: string[] = this.argv.length == 0 ? [\"./src\"] : this.argv;\n\n const tester = spawnEmbed(\n TengoTesterBinaryPath,\n \"run\",\n \"--log-level\",\n flags[\"log-level\"],\n \"--artifacts\",\n \"-\",\n ...testerArgs,\n );\n\n try {\n dumpArtifacts(logger, tester.stdin);\n } catch (err: unknown) {\n logger.error(err);\n } finally {\n tester.stdin.end();\n const code = await waitFor(tester);\n process.exit(code);\n }\n }\n}\n"],"mappings":";;;;;;;;AAOA,IAAqB,OAArB,MAAqB,aAAaA,YAAAA,QAAQ;CACxC,OAAgB,cAAc;CAE9B,OAAO,SAAS;CAEhB,OAAgB,QAAQ,EAAE,GAAGC,gBAAAA,aAAa;CAE1C,OAAgB,WAAW,CAAC,sCAAsC;CAElE,MAAa,MAAqB;EAChC,MAAM,EAAE,UAAU,MAAM,KAAK,MAAM,KAAK;EACxC,MAAM,SAASC,aAAAA,aAAa,MAAM,aAAa;EAE/C,MAAM,aAAuB,KAAK,KAAK,UAAU,IAAI,CAAC,QAAQ,GAAG,KAAK;EAEtE,MAAM,SAASC,aAAAA,WACbC,6BAAAA,uBACA,OACA,eACA,MAAM,cACN,eACA,KACA,GAAG,WACJ;AAED,MAAI;AACF,gBAAA,cAAc,QAAQ,OAAO,MAAM;WAC5B,KAAc;AACrB,UAAO,MAAM,IAAI;YACT;AACR,UAAO,MAAM,KAAK;GAClB,MAAM,OAAO,MAAMC,aAAAA,QAAQ,OAAO;AAClC,WAAQ,KAAK,KAAK"}
1
+ {"version":3,"file":"test.cjs","names":["Command","GlobalOptions","createLogger","spawnEmbed","TengoTesterBinaryPath","waitFor"],"sources":["../../src/commands/test.ts"],"sourcesContent":["import { Command } from \"commander\";\nimport { createLogger } from \"../compiler/util\";\nimport { dumpArtifacts } from \"../shared/dump\";\nimport { addOptions, GlobalOptions } from \"../shared/basecmd\";\nimport { spawnEmbed, waitFor } from \"../shared/proc\";\nimport { TengoTesterBinaryPath } from \"@milaboratories/tengo-tester\";\n\nexport default function testCommand(): Command {\n const cmd = new Command(\"test\").description(\"run tengo unit tests (.test.tengo)\");\n\n cmd.argument(\"[paths...]\", \"source paths to test (defaults to ./src)\");\n addOptions(cmd, GlobalOptions());\n\n cmd.action(async (paths: string[], o) => {\n const logLevel = o.logLevel as string;\n const logger = createLogger(logLevel);\n\n const testerArgs: string[] = paths.length == 0 ? [\"./src\"] : paths;\n\n const tester = spawnEmbed(\n TengoTesterBinaryPath,\n \"run\",\n \"--log-level\",\n logLevel,\n \"--artifacts\",\n \"-\",\n ...testerArgs,\n );\n\n try {\n dumpArtifacts(logger, tester.stdin);\n } catch (err: unknown) {\n logger.error(err);\n } finally {\n tester.stdin.end();\n const code = await waitFor(tester);\n process.exit(code);\n }\n });\n\n return cmd;\n}\n"],"mappings":";;;;;;;AAOA,SAAwB,cAAuB;CAC7C,MAAM,MAAM,IAAIA,UAAAA,QAAQ,MAAM,CAAC,CAAC,YAAY,oCAAoC;CAEhF,IAAI,SAAS,cAAc,0CAA0C;CACrE,gBAAA,WAAW,KAAKC,gBAAAA,cAAc,CAAC;CAE/B,IAAI,OAAO,OAAO,OAAiB,MAAM;EACvC,MAAM,WAAW,EAAE;EACnB,MAAM,SAASC,aAAAA,aAAa,QAAQ;EAIpC,MAAM,SAASC,aAAAA,WACbC,6BAAAA,uBACA,OACA,eACA,UACA,eACA,KACA,GAT2B,MAAM,UAAU,IAAI,CAAC,OAAO,IAAI,KAU7D;EAEA,IAAI;GACF,aAAA,cAAc,QAAQ,OAAO,KAAK;EACpC,SAAS,KAAc;GACrB,OAAO,MAAM,GAAG;EAClB,UAAU;GACR,OAAO,MAAM,IAAI;GACjB,MAAM,OAAO,MAAMC,aAAAA,QAAQ,MAAM;GACjC,QAAQ,KAAK,IAAI;EACnB;CACF,CAAC;CAED,OAAO;AACT"}
@@ -1,20 +1,18 @@
1
1
  import { createLogger } from "../compiler/util.js";
2
- import { GlobalFlags } from "../shared/basecmd.js";
2
+ import { GlobalOptions, addOptions } from "../shared/basecmd.js";
3
3
  import { dumpArtifacts } from "../shared/dump.js";
4
4
  import { spawnEmbed, waitFor } from "../shared/proc.js";
5
- import { Command } from "@oclif/core";
5
+ import { Command } from "commander";
6
6
  import { TengoTesterBinaryPath } from "@milaboratories/tengo-tester";
7
7
  //#region src/commands/test.ts
8
- var Test = class Test extends Command {
9
- static description = "run tengo unit tests (.test.tengo)";
10
- static strict = false;
11
- static flags = { ...GlobalFlags };
12
- static examples = ["<%= config.bin %> <%= command.id %>"];
13
- async run() {
14
- const { flags } = await this.parse(Test);
15
- const logger = createLogger(flags["log-level"]);
16
- const testerArgs = this.argv.length == 0 ? ["./src"] : this.argv;
17
- const tester = spawnEmbed(TengoTesterBinaryPath, "run", "--log-level", flags["log-level"], "--artifacts", "-", ...testerArgs);
8
+ function testCommand() {
9
+ const cmd = new Command("test").description("run tengo unit tests (.test.tengo)");
10
+ cmd.argument("[paths...]", "source paths to test (defaults to ./src)");
11
+ addOptions(cmd, GlobalOptions());
12
+ cmd.action(async (paths, o) => {
13
+ const logLevel = o.logLevel;
14
+ const logger = createLogger(logLevel);
15
+ const tester = spawnEmbed(TengoTesterBinaryPath, "run", "--log-level", logLevel, "--artifacts", "-", ...paths.length == 0 ? ["./src"] : paths);
18
16
  try {
19
17
  dumpArtifacts(logger, tester.stdin);
20
18
  } catch (err) {
@@ -24,9 +22,10 @@ var Test = class Test extends Command {
24
22
  const code = await waitFor(tester);
25
23
  process.exit(code);
26
24
  }
27
- }
28
- };
25
+ });
26
+ return cmd;
27
+ }
29
28
  //#endregion
30
- export { Test as default };
29
+ export { testCommand as default };
31
30
 
32
31
  //# sourceMappingURL=test.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"test.js","names":[],"sources":["../../src/commands/test.ts"],"sourcesContent":["import { Command } from \"@oclif/core\";\nimport { createLogger } from \"../compiler/util\";\nimport { dumpArtifacts } from \"../shared/dump\";\nimport { GlobalFlags } from \"../shared/basecmd\";\nimport { spawnEmbed, waitFor } from \"../shared/proc\";\nimport { TengoTesterBinaryPath } from \"@milaboratories/tengo-tester\";\n\nexport default class Test extends Command {\n static override description = \"run tengo unit tests (.test.tengo)\";\n\n static strict = false;\n\n static override flags = { ...GlobalFlags };\n\n static override examples = [\"<%= config.bin %> <%= command.id %>\"];\n\n public async run(): Promise<void> {\n const { flags } = await this.parse(Test);\n const logger = createLogger(flags[\"log-level\"]);\n\n const testerArgs: string[] = this.argv.length == 0 ? [\"./src\"] : this.argv;\n\n const tester = spawnEmbed(\n TengoTesterBinaryPath,\n \"run\",\n \"--log-level\",\n flags[\"log-level\"],\n \"--artifacts\",\n \"-\",\n ...testerArgs,\n );\n\n try {\n dumpArtifacts(logger, tester.stdin);\n } catch (err: unknown) {\n logger.error(err);\n } finally {\n tester.stdin.end();\n const code = await waitFor(tester);\n process.exit(code);\n }\n }\n}\n"],"mappings":";;;;;;;AAOA,IAAqB,OAArB,MAAqB,aAAa,QAAQ;CACxC,OAAgB,cAAc;CAE9B,OAAO,SAAS;CAEhB,OAAgB,QAAQ,EAAE,GAAG,aAAa;CAE1C,OAAgB,WAAW,CAAC,sCAAsC;CAElE,MAAa,MAAqB;EAChC,MAAM,EAAE,UAAU,MAAM,KAAK,MAAM,KAAK;EACxC,MAAM,SAAS,aAAa,MAAM,aAAa;EAE/C,MAAM,aAAuB,KAAK,KAAK,UAAU,IAAI,CAAC,QAAQ,GAAG,KAAK;EAEtE,MAAM,SAAS,WACb,uBACA,OACA,eACA,MAAM,cACN,eACA,KACA,GAAG,WACJ;AAED,MAAI;AACF,iBAAc,QAAQ,OAAO,MAAM;WAC5B,KAAc;AACrB,UAAO,MAAM,IAAI;YACT;AACR,UAAO,MAAM,KAAK;GAClB,MAAM,OAAO,MAAM,QAAQ,OAAO;AAClC,WAAQ,KAAK,KAAK"}
1
+ {"version":3,"file":"test.js","names":[],"sources":["../../src/commands/test.ts"],"sourcesContent":["import { Command } from \"commander\";\nimport { createLogger } from \"../compiler/util\";\nimport { dumpArtifacts } from \"../shared/dump\";\nimport { addOptions, GlobalOptions } from \"../shared/basecmd\";\nimport { spawnEmbed, waitFor } from \"../shared/proc\";\nimport { TengoTesterBinaryPath } from \"@milaboratories/tengo-tester\";\n\nexport default function testCommand(): Command {\n const cmd = new Command(\"test\").description(\"run tengo unit tests (.test.tengo)\");\n\n cmd.argument(\"[paths...]\", \"source paths to test (defaults to ./src)\");\n addOptions(cmd, GlobalOptions());\n\n cmd.action(async (paths: string[], o) => {\n const logLevel = o.logLevel as string;\n const logger = createLogger(logLevel);\n\n const testerArgs: string[] = paths.length == 0 ? [\"./src\"] : paths;\n\n const tester = spawnEmbed(\n TengoTesterBinaryPath,\n \"run\",\n \"--log-level\",\n logLevel,\n \"--artifacts\",\n \"-\",\n ...testerArgs,\n );\n\n try {\n dumpArtifacts(logger, tester.stdin);\n } catch (err: unknown) {\n logger.error(err);\n } finally {\n tester.stdin.end();\n const code = await waitFor(tester);\n process.exit(code);\n }\n });\n\n return cmd;\n}\n"],"mappings":";;;;;;;AAOA,SAAwB,cAAuB;CAC7C,MAAM,MAAM,IAAI,QAAQ,MAAM,CAAC,CAAC,YAAY,oCAAoC;CAEhF,IAAI,SAAS,cAAc,0CAA0C;CACrE,WAAW,KAAK,cAAc,CAAC;CAE/B,IAAI,OAAO,OAAO,OAAiB,MAAM;EACvC,MAAM,WAAW,EAAE;EACnB,MAAM,SAAS,aAAa,QAAQ;EAIpC,MAAM,SAAS,WACb,uBACA,OACA,eACA,UACA,eACA,KACA,GAT2B,MAAM,UAAU,IAAI,CAAC,OAAO,IAAI,KAU7D;EAEA,IAAI;GACF,cAAc,QAAQ,OAAO,KAAK;EACpC,SAAS,KAAc;GACrB,OAAO,MAAM,GAAG;EAClB,UAAU;GACR,OAAO,MAAM,IAAI;GACjB,MAAM,OAAO,MAAM,QAAQ,MAAM;GACjC,QAAQ,KAAK,IAAI;EACnB;CACF,CAAC;CAED,OAAO;AACT"}
@@ -2,6 +2,7 @@ const require_util = require("./util.cjs");
2
2
  const require_package = require("./package.cjs");
3
3
  //#region src/compiler/artifactset.ts
4
4
  var ArtifactMap = class {
5
+ nameExtractor;
5
6
  map = /* @__PURE__ */ new Map();
6
7
  constructor(nameExtractor) {
7
8
  this.nameExtractor = nameExtractor;
@@ -59,6 +60,7 @@ var ArtifactStore = class {
59
60
  }
60
61
  };
61
62
  //#endregion
63
+ exports.ArtifactMap = ArtifactMap;
62
64
  exports.ArtifactStore = ArtifactStore;
63
65
  exports.createArtifactNameSet = createArtifactNameSet;
64
66
 
@@ -1 +1 @@
1
- {"version":3,"file":"artifactset.cjs","names":["artifactKey"],"sources":["../../src/compiler/artifactset.ts"],"sourcesContent":["import type { CompileMode, TypedArtifactName } from \"./package\";\nimport { artifactKey } from \"./package\";\nimport { assertNever } from \"./util\";\n\nexport class ArtifactMap<T> {\n private readonly map = new Map<string, T>();\n\n constructor(private readonly nameExtractor: (obj: T) => TypedArtifactName) {}\n\n add(obj: T, replace: boolean = true): T | undefined {\n const key = artifactKey(this.nameExtractor(obj));\n const ret = this.map.get(key);\n if (ret && !replace) return ret;\n this.map.set(key, obj);\n return ret;\n }\n\n get(name: TypedArtifactName): T | undefined {\n return this.map.get(artifactKey(name));\n }\n\n get array(): T[] {\n const ret: T[] = [];\n this.map.forEach((obj) => ret.push(obj));\n return ret;\n }\n\n forEach(callback: (value: T, key: TypedArtifactName) => void) {\n this.map.forEach((v) => callback(v, this.nameExtractor(v)));\n }\n}\n\nexport function createArtifactNameSet(): ArtifactMap<TypedArtifactName> {\n return new ArtifactMap<TypedArtifactName>((obj) => obj);\n}\n\n/**\n * ArtifactStore is a store for artifacts that are compiled for different modes.\n * It is used to collect all artifacts from the dependency tree and compile them for different modes.\n */\nexport class ArtifactStore<T> {\n // private readonly dev: ArtifactMap<T>;\n private readonly dist: ArtifactMap<T>;\n\n constructor(nameExtractor: (obj: T) => TypedArtifactName) {\n // this.dev = new ArtifactMap<T>(nameExtractor);\n this.dist = new ArtifactMap<T>(nameExtractor);\n }\n\n add(mode: CompileMode, obj: T, replace: boolean = true): T | undefined {\n switch (mode) {\n case \"dist\":\n return this.dist.add(obj, replace);\n\n default:\n assertNever(mode);\n }\n }\n\n get(mode: CompileMode, name: TypedArtifactName): T | undefined {\n switch (mode) {\n case \"dist\":\n return this.dist.get(name);\n\n default:\n assertNever(mode);\n }\n }\n\n array(mode: CompileMode): T[] {\n const ret: T[] = [];\n this.forEach(mode, (obj) => ret.push(obj));\n return ret;\n }\n\n forEach(mode: CompileMode, callback: (value: T, key: TypedArtifactName) => void) {\n this.dist.forEach((obj, k) => callback(this.get(mode, k) ?? obj, k));\n }\n}\n"],"mappings":";;;AAIA,IAAa,cAAb,MAA4B;CAC1B,sBAAuB,IAAI,KAAgB;CAE3C,YAAY,eAA+D;AAA9C,OAAA,gBAAA;;CAE7B,IAAI,KAAQ,UAAmB,MAAqB;EAClD,MAAM,MAAMA,gBAAAA,YAAY,KAAK,cAAc,IAAI,CAAC;EAChD,MAAM,MAAM,KAAK,IAAI,IAAI,IAAI;AAC7B,MAAI,OAAO,CAAC,QAAS,QAAO;AAC5B,OAAK,IAAI,IAAI,KAAK,IAAI;AACtB,SAAO;;CAGT,IAAI,MAAwC;AAC1C,SAAO,KAAK,IAAI,IAAIA,gBAAAA,YAAY,KAAK,CAAC;;CAGxC,IAAI,QAAa;EACf,MAAM,MAAW,EAAE;AACnB,OAAK,IAAI,SAAS,QAAQ,IAAI,KAAK,IAAI,CAAC;AACxC,SAAO;;CAGT,QAAQ,UAAsD;AAC5D,OAAK,IAAI,SAAS,MAAM,SAAS,GAAG,KAAK,cAAc,EAAE,CAAC,CAAC;;;AAI/D,SAAgB,wBAAwD;AACtE,QAAO,IAAI,aAAgC,QAAQ,IAAI;;;;;;AAOzD,IAAa,gBAAb,MAA8B;CAE5B;CAEA,YAAY,eAA8C;AAExD,OAAK,OAAO,IAAI,YAAe,cAAc;;CAG/C,IAAI,MAAmB,KAAQ,UAAmB,MAAqB;AACrE,UAAQ,MAAR;GACE,KAAK,OACH,QAAO,KAAK,KAAK,IAAI,KAAK,QAAQ;GAEpC,QACE,cAAA,YAAY,KAAK;;;CAIvB,IAAI,MAAmB,MAAwC;AAC7D,UAAQ,MAAR;GACE,KAAK,OACH,QAAO,KAAK,KAAK,IAAI,KAAK;GAE5B,QACE,cAAA,YAAY,KAAK;;;CAIvB,MAAM,MAAwB;EAC5B,MAAM,MAAW,EAAE;AACnB,OAAK,QAAQ,OAAO,QAAQ,IAAI,KAAK,IAAI,CAAC;AAC1C,SAAO;;CAGT,QAAQ,MAAmB,UAAsD;AAC/E,OAAK,KAAK,SAAS,KAAK,MAAM,SAAS,KAAK,IAAI,MAAM,EAAE,IAAI,KAAK,EAAE,CAAC"}
1
+ {"version":3,"file":"artifactset.cjs","names":["artifactKey"],"sources":["../../src/compiler/artifactset.ts"],"sourcesContent":["import type { CompileMode, TypedArtifactName } from \"./package\";\nimport { artifactKey } from \"./package\";\nimport { assertNever } from \"./util\";\n\nexport class ArtifactMap<T> {\n private readonly map = new Map<string, T>();\n\n constructor(private readonly nameExtractor: (obj: T) => TypedArtifactName) {}\n\n add(obj: T, replace: boolean = true): T | undefined {\n const key = artifactKey(this.nameExtractor(obj));\n const ret = this.map.get(key);\n if (ret && !replace) return ret;\n this.map.set(key, obj);\n return ret;\n }\n\n get(name: TypedArtifactName): T | undefined {\n return this.map.get(artifactKey(name));\n }\n\n get array(): T[] {\n const ret: T[] = [];\n this.map.forEach((obj) => ret.push(obj));\n return ret;\n }\n\n forEach(callback: (value: T, key: TypedArtifactName) => void) {\n this.map.forEach((v) => callback(v, this.nameExtractor(v)));\n }\n}\n\nexport function createArtifactNameSet(): ArtifactMap<TypedArtifactName> {\n return new ArtifactMap<TypedArtifactName>((obj) => obj);\n}\n\n/**\n * ArtifactStore is a store for artifacts that are compiled for different modes.\n * It is used to collect all artifacts from the dependency tree and compile them for different modes.\n */\nexport class ArtifactStore<T> {\n // private readonly dev: ArtifactMap<T>;\n private readonly dist: ArtifactMap<T>;\n\n constructor(nameExtractor: (obj: T) => TypedArtifactName) {\n // this.dev = new ArtifactMap<T>(nameExtractor);\n this.dist = new ArtifactMap<T>(nameExtractor);\n }\n\n add(mode: CompileMode, obj: T, replace: boolean = true): T | undefined {\n switch (mode) {\n case \"dist\":\n return this.dist.add(obj, replace);\n\n default:\n assertNever(mode);\n }\n }\n\n get(mode: CompileMode, name: TypedArtifactName): T | undefined {\n switch (mode) {\n case \"dist\":\n return this.dist.get(name);\n\n default:\n assertNever(mode);\n }\n }\n\n array(mode: CompileMode): T[] {\n const ret: T[] = [];\n this.forEach(mode, (obj) => ret.push(obj));\n return ret;\n }\n\n forEach(mode: CompileMode, callback: (value: T, key: TypedArtifactName) => void) {\n this.dist.forEach((obj, k) => callback(this.get(mode, k) ?? obj, k));\n }\n}\n"],"mappings":";;;AAIA,IAAa,cAAb,MAA4B;CAGG;CAF7B,sBAAuB,IAAI,IAAe;CAE1C,YAAY,eAA+D;EAA9C,KAAA,gBAAA;CAA+C;CAE5E,IAAI,KAAQ,UAAmB,MAAqB;EAClD,MAAM,MAAMA,gBAAAA,YAAY,KAAK,cAAc,GAAG,CAAC;EAC/C,MAAM,MAAM,KAAK,IAAI,IAAI,GAAG;EAC5B,IAAI,OAAO,CAAC,SAAS,OAAO;EAC5B,KAAK,IAAI,IAAI,KAAK,GAAG;EACrB,OAAO;CACT;CAEA,IAAI,MAAwC;EAC1C,OAAO,KAAK,IAAI,IAAIA,gBAAAA,YAAY,IAAI,CAAC;CACvC;CAEA,IAAI,QAAa;EACf,MAAM,MAAW,CAAC;EAClB,KAAK,IAAI,SAAS,QAAQ,IAAI,KAAK,GAAG,CAAC;EACvC,OAAO;CACT;CAEA,QAAQ,UAAsD;EAC5D,KAAK,IAAI,SAAS,MAAM,SAAS,GAAG,KAAK,cAAc,CAAC,CAAC,CAAC;CAC5D;AACF;AAEA,SAAgB,wBAAwD;CACtE,OAAO,IAAI,aAAgC,QAAQ,GAAG;AACxD;;;;;AAMA,IAAa,gBAAb,MAA8B;CAE5B;CAEA,YAAY,eAA8C;EAExD,KAAK,OAAO,IAAI,YAAe,aAAa;CAC9C;CAEA,IAAI,MAAmB,KAAQ,UAAmB,MAAqB;EACrE,QAAQ,MAAR;GACE,KAAK,QACH,OAAO,KAAK,KAAK,IAAI,KAAK,OAAO;GAEnC,SACE,aAAA,YAAY,IAAI;EACpB;CACF;CAEA,IAAI,MAAmB,MAAwC;EAC7D,QAAQ,MAAR;GACE,KAAK,QACH,OAAO,KAAK,KAAK,IAAI,IAAI;GAE3B,SACE,aAAA,YAAY,IAAI;EACpB;CACF;CAEA,MAAM,MAAwB;EAC5B,MAAM,MAAW,CAAC;EAClB,KAAK,QAAQ,OAAO,QAAQ,IAAI,KAAK,GAAG,CAAC;EACzC,OAAO;CACT;CAEA,QAAQ,MAAmB,UAAsD;EAC/E,KAAK,KAAK,SAAS,KAAK,MAAM,SAAS,KAAK,IAAI,MAAM,CAAC,KAAK,KAAK,CAAC,CAAC;CACrE;AACF"}
@@ -2,6 +2,7 @@ import { assertNever } from "./util.js";
2
2
  import { artifactKey } from "./package.js";
3
3
  //#region src/compiler/artifactset.ts
4
4
  var ArtifactMap = class {
5
+ nameExtractor;
5
6
  map = /* @__PURE__ */ new Map();
6
7
  constructor(nameExtractor) {
7
8
  this.nameExtractor = nameExtractor;
@@ -59,6 +60,6 @@ var ArtifactStore = class {
59
60
  }
60
61
  };
61
62
  //#endregion
62
- export { ArtifactStore, createArtifactNameSet };
63
+ export { ArtifactMap, ArtifactStore, createArtifactNameSet };
63
64
 
64
65
  //# sourceMappingURL=artifactset.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"artifactset.js","names":[],"sources":["../../src/compiler/artifactset.ts"],"sourcesContent":["import type { CompileMode, TypedArtifactName } from \"./package\";\nimport { artifactKey } from \"./package\";\nimport { assertNever } from \"./util\";\n\nexport class ArtifactMap<T> {\n private readonly map = new Map<string, T>();\n\n constructor(private readonly nameExtractor: (obj: T) => TypedArtifactName) {}\n\n add(obj: T, replace: boolean = true): T | undefined {\n const key = artifactKey(this.nameExtractor(obj));\n const ret = this.map.get(key);\n if (ret && !replace) return ret;\n this.map.set(key, obj);\n return ret;\n }\n\n get(name: TypedArtifactName): T | undefined {\n return this.map.get(artifactKey(name));\n }\n\n get array(): T[] {\n const ret: T[] = [];\n this.map.forEach((obj) => ret.push(obj));\n return ret;\n }\n\n forEach(callback: (value: T, key: TypedArtifactName) => void) {\n this.map.forEach((v) => callback(v, this.nameExtractor(v)));\n }\n}\n\nexport function createArtifactNameSet(): ArtifactMap<TypedArtifactName> {\n return new ArtifactMap<TypedArtifactName>((obj) => obj);\n}\n\n/**\n * ArtifactStore is a store for artifacts that are compiled for different modes.\n * It is used to collect all artifacts from the dependency tree and compile them for different modes.\n */\nexport class ArtifactStore<T> {\n // private readonly dev: ArtifactMap<T>;\n private readonly dist: ArtifactMap<T>;\n\n constructor(nameExtractor: (obj: T) => TypedArtifactName) {\n // this.dev = new ArtifactMap<T>(nameExtractor);\n this.dist = new ArtifactMap<T>(nameExtractor);\n }\n\n add(mode: CompileMode, obj: T, replace: boolean = true): T | undefined {\n switch (mode) {\n case \"dist\":\n return this.dist.add(obj, replace);\n\n default:\n assertNever(mode);\n }\n }\n\n get(mode: CompileMode, name: TypedArtifactName): T | undefined {\n switch (mode) {\n case \"dist\":\n return this.dist.get(name);\n\n default:\n assertNever(mode);\n }\n }\n\n array(mode: CompileMode): T[] {\n const ret: T[] = [];\n this.forEach(mode, (obj) => ret.push(obj));\n return ret;\n }\n\n forEach(mode: CompileMode, callback: (value: T, key: TypedArtifactName) => void) {\n this.dist.forEach((obj, k) => callback(this.get(mode, k) ?? obj, k));\n }\n}\n"],"mappings":";;;AAIA,IAAa,cAAb,MAA4B;CAC1B,sBAAuB,IAAI,KAAgB;CAE3C,YAAY,eAA+D;AAA9C,OAAA,gBAAA;;CAE7B,IAAI,KAAQ,UAAmB,MAAqB;EAClD,MAAM,MAAM,YAAY,KAAK,cAAc,IAAI,CAAC;EAChD,MAAM,MAAM,KAAK,IAAI,IAAI,IAAI;AAC7B,MAAI,OAAO,CAAC,QAAS,QAAO;AAC5B,OAAK,IAAI,IAAI,KAAK,IAAI;AACtB,SAAO;;CAGT,IAAI,MAAwC;AAC1C,SAAO,KAAK,IAAI,IAAI,YAAY,KAAK,CAAC;;CAGxC,IAAI,QAAa;EACf,MAAM,MAAW,EAAE;AACnB,OAAK,IAAI,SAAS,QAAQ,IAAI,KAAK,IAAI,CAAC;AACxC,SAAO;;CAGT,QAAQ,UAAsD;AAC5D,OAAK,IAAI,SAAS,MAAM,SAAS,GAAG,KAAK,cAAc,EAAE,CAAC,CAAC;;;AAI/D,SAAgB,wBAAwD;AACtE,QAAO,IAAI,aAAgC,QAAQ,IAAI;;;;;;AAOzD,IAAa,gBAAb,MAA8B;CAE5B;CAEA,YAAY,eAA8C;AAExD,OAAK,OAAO,IAAI,YAAe,cAAc;;CAG/C,IAAI,MAAmB,KAAQ,UAAmB,MAAqB;AACrE,UAAQ,MAAR;GACE,KAAK,OACH,QAAO,KAAK,KAAK,IAAI,KAAK,QAAQ;GAEpC,QACE,aAAY,KAAK;;;CAIvB,IAAI,MAAmB,MAAwC;AAC7D,UAAQ,MAAR;GACE,KAAK,OACH,QAAO,KAAK,KAAK,IAAI,KAAK;GAE5B,QACE,aAAY,KAAK;;;CAIvB,MAAM,MAAwB;EAC5B,MAAM,MAAW,EAAE;AACnB,OAAK,QAAQ,OAAO,QAAQ,IAAI,KAAK,IAAI,CAAC;AAC1C,SAAO;;CAGT,QAAQ,MAAmB,UAAsD;AAC/E,OAAK,KAAK,SAAS,KAAK,MAAM,SAAS,KAAK,IAAI,MAAM,EAAE,IAAI,KAAK,EAAE,CAAC"}
1
+ {"version":3,"file":"artifactset.js","names":[],"sources":["../../src/compiler/artifactset.ts"],"sourcesContent":["import type { CompileMode, TypedArtifactName } from \"./package\";\nimport { artifactKey } from \"./package\";\nimport { assertNever } from \"./util\";\n\nexport class ArtifactMap<T> {\n private readonly map = new Map<string, T>();\n\n constructor(private readonly nameExtractor: (obj: T) => TypedArtifactName) {}\n\n add(obj: T, replace: boolean = true): T | undefined {\n const key = artifactKey(this.nameExtractor(obj));\n const ret = this.map.get(key);\n if (ret && !replace) return ret;\n this.map.set(key, obj);\n return ret;\n }\n\n get(name: TypedArtifactName): T | undefined {\n return this.map.get(artifactKey(name));\n }\n\n get array(): T[] {\n const ret: T[] = [];\n this.map.forEach((obj) => ret.push(obj));\n return ret;\n }\n\n forEach(callback: (value: T, key: TypedArtifactName) => void) {\n this.map.forEach((v) => callback(v, this.nameExtractor(v)));\n }\n}\n\nexport function createArtifactNameSet(): ArtifactMap<TypedArtifactName> {\n return new ArtifactMap<TypedArtifactName>((obj) => obj);\n}\n\n/**\n * ArtifactStore is a store for artifacts that are compiled for different modes.\n * It is used to collect all artifacts from the dependency tree and compile them for different modes.\n */\nexport class ArtifactStore<T> {\n // private readonly dev: ArtifactMap<T>;\n private readonly dist: ArtifactMap<T>;\n\n constructor(nameExtractor: (obj: T) => TypedArtifactName) {\n // this.dev = new ArtifactMap<T>(nameExtractor);\n this.dist = new ArtifactMap<T>(nameExtractor);\n }\n\n add(mode: CompileMode, obj: T, replace: boolean = true): T | undefined {\n switch (mode) {\n case \"dist\":\n return this.dist.add(obj, replace);\n\n default:\n assertNever(mode);\n }\n }\n\n get(mode: CompileMode, name: TypedArtifactName): T | undefined {\n switch (mode) {\n case \"dist\":\n return this.dist.get(name);\n\n default:\n assertNever(mode);\n }\n }\n\n array(mode: CompileMode): T[] {\n const ret: T[] = [];\n this.forEach(mode, (obj) => ret.push(obj));\n return ret;\n }\n\n forEach(mode: CompileMode, callback: (value: T, key: TypedArtifactName) => void) {\n this.dist.forEach((obj, k) => callback(this.get(mode, k) ?? obj, k));\n }\n}\n"],"mappings":";;;AAIA,IAAa,cAAb,MAA4B;CAGG;CAF7B,sBAAuB,IAAI,IAAe;CAE1C,YAAY,eAA+D;EAA9C,KAAA,gBAAA;CAA+C;CAE5E,IAAI,KAAQ,UAAmB,MAAqB;EAClD,MAAM,MAAM,YAAY,KAAK,cAAc,GAAG,CAAC;EAC/C,MAAM,MAAM,KAAK,IAAI,IAAI,GAAG;EAC5B,IAAI,OAAO,CAAC,SAAS,OAAO;EAC5B,KAAK,IAAI,IAAI,KAAK,GAAG;EACrB,OAAO;CACT;CAEA,IAAI,MAAwC;EAC1C,OAAO,KAAK,IAAI,IAAI,YAAY,IAAI,CAAC;CACvC;CAEA,IAAI,QAAa;EACf,MAAM,MAAW,CAAC;EAClB,KAAK,IAAI,SAAS,QAAQ,IAAI,KAAK,GAAG,CAAC;EACvC,OAAO;CACT;CAEA,QAAQ,UAAsD;EAC5D,KAAK,IAAI,SAAS,MAAM,SAAS,GAAG,KAAK,cAAc,CAAC,CAAC,CAAC;CAC5D;AACF;AAEA,SAAgB,wBAAwD;CACtE,OAAO,IAAI,aAAgC,QAAQ,GAAG;AACxD;;;;;AAMA,IAAa,gBAAb,MAA8B;CAE5B;CAEA,YAAY,eAA8C;EAExD,KAAK,OAAO,IAAI,YAAe,aAAa;CAC9C;CAEA,IAAI,MAAmB,KAAQ,UAAmB,MAAqB;EACrE,QAAQ,MAAR;GACE,KAAK,QACH,OAAO,KAAK,KAAK,IAAI,KAAK,OAAO;GAEnC,SACE,YAAY,IAAI;EACpB;CACF;CAEA,IAAI,MAAmB,MAAwC;EAC7D,QAAQ,MAAR;GACE,KAAK,QACH,OAAO,KAAK,KAAK,IAAI,IAAI;GAE3B,SACE,YAAY,IAAI;EACpB;CACF;CAEA,MAAM,MAAwB;EAC5B,MAAM,MAAW,CAAC;EAClB,KAAK,QAAQ,OAAO,QAAQ,IAAI,KAAK,GAAG,CAAC;EACzC,OAAO;CACT;CAEA,QAAQ,MAAmB,UAAsD;EAC/E,KAAK,KAAK,SAAS,KAAK,MAAM,SAAS,KAAK,IAAI,MAAM,CAAC,KAAK,KAAK,CAAC,CAAC;CACrE;AACF"}
@@ -12,6 +12,7 @@ function addRequiredCapability(template, capability) {
12
12
  if (!template.requiredCapabilities.includes(capability)) template.requiredCapabilities.push(capability);
13
13
  }
14
14
  var TengoTemplateCompiler = class {
15
+ compileMode;
15
16
  libs = new require_artifactset.ArtifactStore((src) => src.fullName);
16
17
  software = new require_artifactset.ArtifactStore((src) => src.fullName);
17
18
  assets = new require_artifactset.ArtifactStore((src) => src.fullName);
@@ -1 +1 @@
1
- {"version":3,"file":"compiler.cjs","names":["ArtifactStore","artifactNameToString","formatArtefactNameAndVersion","typedArtifactNamesEquals","typedArtifactNameToString","fullNameEquals","fullNameToString","newTemplateWithSource"],"sources":["../../src/compiler/compiler.ts"],"sourcesContent":["import type { ArtifactSource } from \"./source\";\nimport type { TemplateWithSource } from \"./template\";\nimport { newTemplateWithSource } from \"./template\";\nimport type { TypedArtifactName, FullArtifactName, CompileMode } from \"./package\";\nimport {\n fullNameToString,\n typedArtifactNameToString,\n artifactNameToString,\n formatArtefactNameAndVersion,\n typedArtifactNamesEquals,\n fullNameEquals,\n} from \"./package\";\nimport { ArtifactStore } from \"./artifactset\";\nimport { assertNever } from \"./util\";\nimport { applyLibraryCompilerOptions, applyTemplateCompilerOptions } from \"./compileroptions\";\nimport type {\n BackendCapability,\n CompiledTemplateV3,\n TemplateDataV3,\n} from \"@milaboratories/pl-model-backend\";\n\n/** Add a capability token to a template's `requiredCapabilities` list,\n * skipping duplicates. Initializes the array lazily so the field stays\n * absent for templates that need nothing. */\nfunction addRequiredCapability(template: TemplateDataV3, capability: BackendCapability): void {\n template.requiredCapabilities = template.requiredCapabilities ?? [];\n if (!template.requiredCapabilities.includes(capability)) {\n template.requiredCapabilities.push(capability);\n }\n}\n\n/** A compilation result. */\nexport interface TemplatesAndLibs {\n templates: TemplateWithSource[];\n libs: ArtifactSource[];\n software: ArtifactSource[];\n assets: ArtifactSource[];\n wasm: 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 wasm = new ArtifactStore<ArtifactSource>((src) => src.fullName);\n private readonly templates = new ArtifactStore<TemplateWithSource>((tpl) => tpl.fullName);\n\n constructor(private readonly compileMode: CompileMode) {}\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 =\n `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, [\n ...trace,\n artifactNameToString(dep),\n ]);\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 \"wasm\": {\n const wasm = this.getWasmOrError(dep);\n data.template.wasm = data.template.wasm ?? {};\n data.template.wasm[artifactNameToString(dep)] = {\n ...formatArtefactNameAndVersion(wasm.fullName),\n sourceHash: wasm.sourceHash,\n };\n data.hashToSource[wasm.sourceHash] = wasm.src;\n // Embedding a wasm artifact means this template requires the\n // backend's wasm runtime to run. The token is propagated upward\n // when this template is in turn embedded as a sub-template.\n addRequiredCapability(data.template, \"wasm:v1\");\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 // Union the sub-template's compile-time-computed capability\n // requirements into ours, so the top template carries the full\n // transitive set without consumers having to walk the tree.\n for (const cap of tpl.data.template.requiredCapabilities ?? []) {\n addRequiredCapability(data.template, cap);\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\") 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) 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(\n `test should never be dependency of production code: ${typedArtifactNameToString(dep)} test is dependency of ${fullNameToString(lib.fullName)}`,\n );\n\n if (!this.getArtefact(dep))\n throw new Error(\n `unresolved dependency ${typedArtifactNameToString(dep)} for ${fullNameToString(lib.fullName)}`,\n );\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) 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) throw new Error(`asset info not found: ${artifactNameToString(name)}`);\n return asset;\n }\n\n addWasm(wasm: ArtifactSource) {\n const wasmFromMap = this.wasm.add(wasm.compileMode, wasm, false);\n if (wasmFromMap && !fullNameEquals(wasm.fullName, wasmFromMap.fullName))\n throw new Error(\n `compiler already contain info for wasm: adding = ${fullNameToString(wasm.fullName)}, contains = ${fullNameToString(wasmFromMap.fullName)}`,\n );\n }\n\n allWasm(): ArtifactSource[] {\n return this.wasm.array(this.compileMode);\n }\n\n getWasm(name: TypedArtifactName): ArtifactSource | undefined {\n if (name.type !== \"wasm\")\n throw new Error(`illegal artifact type: got ${name.type} instead of 'wasm'`);\n\n return this.wasm.get(this.compileMode, name);\n }\n\n getWasmOrError(name: TypedArtifactName): ArtifactSource {\n const wasm = this.getWasm(name);\n if (!wasm) throw new Error(`wasm info not found: ${artifactNameToString(name)}`);\n return wasm;\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) 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 \"wasm\":\n return this.getWasm(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 wasm: [],\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 if (src.fullName.type === \"wasm\") {\n // add wasm 'as-is' to be able to resolve them as dependencies\n this.addWasm(src);\n result.wasm.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(\n (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 \"wasm\":\n // wasm dependencies are added as is\n this.addWasm(src);\n result.wasm.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"],"mappings":";;;;;;;;;AAwBA,SAAS,sBAAsB,UAA0B,YAAqC;AAC5F,UAAS,uBAAuB,SAAS,wBAAwB,EAAE;AACnE,KAAI,CAAC,SAAS,qBAAqB,SAAS,WAAW,CACrD,UAAS,qBAAqB,KAAK,WAAW;;AAalD,IAAa,wBAAb,MAAmC;CACjC,OAAwB,IAAIA,oBAAAA,eAA+B,QAAQ,IAAI,SAAS;CAChF,WAA4B,IAAIA,oBAAAA,eAA+B,QAAQ,IAAI,SAAS;CACpF,SAA0B,IAAIA,oBAAAA,eAA+B,QAAQ,IAAI,SAAS;CAClF,OAAwB,IAAIA,oBAAAA,eAA+B,QAAQ,IAAI,SAAS;CAChF,YAA6B,IAAIA,oBAAAA,eAAmC,QAAQ,IAAI,SAAS;CAEzF,YAAY,aAA2C;AAA1B,OAAA,cAAA;;;CAG7B,qCACE,UACA,MACA,MACA,OACA;AACA,OAAK,MAAM,OAAO,KAChB,SAAQ,IAAI,MAAZ;GACE,KAAK,WAAW;IACd,MAAM,MAAM,KAAK,cAAc,IAAI;IAEnC,MAAM,iBAAiB,MAAM,QAAQC,gBAAAA,qBAAqB,IAAI,CAAC;AAC/D,QAAI,kBAAkB,GAAG;KACvB,MAAM,eACJ,sCACG,MAAM,MAAM,eAAe,CAAC,KAAK,OAAO,CAAC,MAAMA,gBAAAA,qBAAqB,IAAI;AAC7E,WAAM,IAAI,MAAM,aAAa;;IAG/B,MAAM,SAAS;KACb,GAAGC,gBAAAA,6BAA6B,IAAI,SAAS;KAC7C,YAAY,IAAI;KACjB;AAED,4BAAA,4BAA4B,IAAI,iBAAiB,OAAO;AACxD,SAAK,SAAS,KAAKD,gBAAAA,q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,CAAC;;AAErD;KACF,KAAK,OAEH;KACF,QACE,cAAA,YAAY,IAAI,SAAS,KAAK;;;AAMpC,OAAI,QAAQ,WAAW,YAAY,QAAQ;IACzC,IAAI,eAAe;AAEnB,SAAK,MAAM,KAAK,YACd,iBAAgB,KAAK,EAAE,IAAI;AAE7B,UAAM,IAAI,MAAM,aAAa;;AAG/B,aAAU,YAAY,KAAK,EAAE,KAAK,qBAAqB,eAAe;;AAGxE,SAAO"}
1
+ {"version":3,"file":"compiler.cjs","names":["ArtifactStore","artifactNameToString","formatArtefactNameAndVersion","typedArtifactNamesEquals","typedArtifactNameToString","fullNameEquals","fullNameToString","newTemplateWithSource"],"sources":["../../src/compiler/compiler.ts"],"sourcesContent":["import type { ArtifactSource } from \"./source\";\nimport type { TemplateWithSource } from \"./template\";\nimport { newTemplateWithSource } from \"./template\";\nimport type { TypedArtifactName, FullArtifactName, CompileMode } from \"./package\";\nimport {\n fullNameToString,\n typedArtifactNameToString,\n artifactNameToString,\n formatArtefactNameAndVersion,\n typedArtifactNamesEquals,\n fullNameEquals,\n} from \"./package\";\nimport { ArtifactStore } from \"./artifactset\";\nimport { assertNever } from \"./util\";\nimport { applyLibraryCompilerOptions, applyTemplateCompilerOptions } from \"./compileroptions\";\nimport type {\n BackendCapability,\n CompiledTemplateV3,\n TemplateDataV3,\n} from \"@milaboratories/pl-model-backend\";\n\n/** Add a capability token to a template's `requiredCapabilities` list,\n * skipping duplicates. Initializes the array lazily so the field stays\n * absent for templates that need nothing. */\nfunction addRequiredCapability(template: TemplateDataV3, capability: BackendCapability): void {\n template.requiredCapabilities = template.requiredCapabilities ?? [];\n if (!template.requiredCapabilities.includes(capability)) {\n template.requiredCapabilities.push(capability);\n }\n}\n\n/** A compilation result. */\nexport interface TemplatesAndLibs {\n templates: TemplateWithSource[];\n libs: ArtifactSource[];\n software: ArtifactSource[];\n assets: ArtifactSource[];\n wasm: 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 wasm = new ArtifactStore<ArtifactSource>((src) => src.fullName);\n private readonly templates = new ArtifactStore<TemplateWithSource>((tpl) => tpl.fullName);\n\n constructor(private readonly compileMode: CompileMode) {}\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 =\n `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, [\n ...trace,\n artifactNameToString(dep),\n ]);\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 \"wasm\": {\n const wasm = this.getWasmOrError(dep);\n data.template.wasm = data.template.wasm ?? {};\n data.template.wasm[artifactNameToString(dep)] = {\n ...formatArtefactNameAndVersion(wasm.fullName),\n sourceHash: wasm.sourceHash,\n };\n data.hashToSource[wasm.sourceHash] = wasm.src;\n // Embedding a wasm artifact means this template requires the\n // backend's wasm runtime to run. The token is propagated upward\n // when this template is in turn embedded as a sub-template.\n addRequiredCapability(data.template, \"wasm:v1\");\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 // Union the sub-template's compile-time-computed capability\n // requirements into ours, so the top template carries the full\n // transitive set without consumers having to walk the tree.\n for (const cap of tpl.data.template.requiredCapabilities ?? []) {\n addRequiredCapability(data.template, cap);\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\") 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) 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(\n `test should never be dependency of production code: ${typedArtifactNameToString(dep)} test is dependency of ${fullNameToString(lib.fullName)}`,\n );\n\n if (!this.getArtefact(dep))\n throw new Error(\n `unresolved dependency ${typedArtifactNameToString(dep)} for ${fullNameToString(lib.fullName)}`,\n );\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) 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) throw new Error(`asset info not found: ${artifactNameToString(name)}`);\n return asset;\n }\n\n addWasm(wasm: ArtifactSource) {\n const wasmFromMap = this.wasm.add(wasm.compileMode, wasm, false);\n if (wasmFromMap && !fullNameEquals(wasm.fullName, wasmFromMap.fullName))\n throw new Error(\n `compiler already contain info for wasm: adding = ${fullNameToString(wasm.fullName)}, contains = ${fullNameToString(wasmFromMap.fullName)}`,\n );\n }\n\n allWasm(): ArtifactSource[] {\n return this.wasm.array(this.compileMode);\n }\n\n getWasm(name: TypedArtifactName): ArtifactSource | undefined {\n if (name.type !== \"wasm\")\n throw new Error(`illegal artifact type: got ${name.type} instead of 'wasm'`);\n\n return this.wasm.get(this.compileMode, name);\n }\n\n getWasmOrError(name: TypedArtifactName): ArtifactSource {\n const wasm = this.getWasm(name);\n if (!wasm) throw new Error(`wasm info not found: ${artifactNameToString(name)}`);\n return wasm;\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) 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 \"wasm\":\n return this.getWasm(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 wasm: [],\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 if (src.fullName.type === \"wasm\") {\n // add wasm 'as-is' to be able to resolve them as dependencies\n this.addWasm(src);\n result.wasm.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(\n (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 \"wasm\":\n // wasm dependencies are added as is\n this.addWasm(src);\n result.wasm.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"],"mappings":";;;;;;;;;AAwBA,SAAS,sBAAsB,UAA0B,YAAqC;CAC5F,SAAS,uBAAuB,SAAS,wBAAwB,CAAC;CAClE,IAAI,CAAC,SAAS,qBAAqB,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jC;GACF;GAIA,IAAI,QAAQ,WAAW,YAAY,QAAQ;IACzC,IAAI,eAAe;IAEnB,KAAK,MAAM,KAAK,aACd,gBAAgB,KAAK,EAAE,IAAI;IAE7B,MAAM,IAAI,MAAM,YAAY;GAC9B;GAEA,UAAU,YAAY,KAAK,EAAE,KAAK,qBAAqB,cAAc;EACvE;EAEA,OAAO;CACT;AACF"}
@@ -12,6 +12,7 @@ function addRequiredCapability(template, capability) {
12
12
  if (!template.requiredCapabilities.includes(capability)) template.requiredCapabilities.push(capability);
13
13
  }
14
14
  var TengoTemplateCompiler = class {
15
+ compileMode;
15
16
  libs = new ArtifactStore((src) => src.fullName);
16
17
  software = new ArtifactStore((src) => src.fullName);
17
18
  assets = new ArtifactStore((src) => src.fullName);
@@ -1 +1 @@
1
- {"version":3,"file":"compiler.js","names":[],"sources":["../../src/compiler/compiler.ts"],"sourcesContent":["import type { ArtifactSource } from \"./source\";\nimport type { TemplateWithSource } from \"./template\";\nimport { newTemplateWithSource } from \"./template\";\nimport type { TypedArtifactName, FullArtifactName, CompileMode } from \"./package\";\nimport {\n fullNameToString,\n typedArtifactNameToString,\n artifactNameToString,\n formatArtefactNameAndVersion,\n typedArtifactNamesEquals,\n fullNameEquals,\n} from \"./package\";\nimport { ArtifactStore } from \"./artifactset\";\nimport { assertNever } from \"./util\";\nimport { applyLibraryCompilerOptions, applyTemplateCompilerOptions } from \"./compileroptions\";\nimport type {\n BackendCapability,\n CompiledTemplateV3,\n TemplateDataV3,\n} from \"@milaboratories/pl-model-backend\";\n\n/** Add a capability token to a template's `requiredCapabilities` list,\n * skipping duplicates. Initializes the array lazily so the field stays\n * absent for templates that need nothing. */\nfunction addRequiredCapability(template: TemplateDataV3, capability: BackendCapability): void {\n template.requiredCapabilities = template.requiredCapabilities ?? [];\n if (!template.requiredCapabilities.includes(capability)) {\n template.requiredCapabilities.push(capability);\n }\n}\n\n/** A compilation result. */\nexport interface TemplatesAndLibs {\n templates: TemplateWithSource[];\n libs: ArtifactSource[];\n software: ArtifactSource[];\n assets: ArtifactSource[];\n wasm: 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 wasm = new ArtifactStore<ArtifactSource>((src) => src.fullName);\n private readonly templates = new ArtifactStore<TemplateWithSource>((tpl) => tpl.fullName);\n\n constructor(private readonly compileMode: CompileMode) {}\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 =\n `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, [\n ...trace,\n artifactNameToString(dep),\n ]);\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 \"wasm\": {\n const wasm = this.getWasmOrError(dep);\n data.template.wasm = data.template.wasm ?? {};\n data.template.wasm[artifactNameToString(dep)] = {\n ...formatArtefactNameAndVersion(wasm.fullName),\n sourceHash: wasm.sourceHash,\n };\n data.hashToSource[wasm.sourceHash] = wasm.src;\n // Embedding a wasm artifact means this template requires the\n // backend's wasm runtime to run. The token is propagated upward\n // when this template is in turn embedded as a sub-template.\n addRequiredCapability(data.template, \"wasm:v1\");\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 // Union the sub-template's compile-time-computed capability\n // requirements into ours, so the top template carries the full\n // transitive set without consumers having to walk the tree.\n for (const cap of tpl.data.template.requiredCapabilities ?? []) {\n addRequiredCapability(data.template, cap);\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\") 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) 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(\n `test should never be dependency of production code: ${typedArtifactNameToString(dep)} test is dependency of ${fullNameToString(lib.fullName)}`,\n );\n\n if (!this.getArtefact(dep))\n throw new Error(\n `unresolved dependency ${typedArtifactNameToString(dep)} for ${fullNameToString(lib.fullName)}`,\n );\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) 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) throw new Error(`asset info not found: ${artifactNameToString(name)}`);\n return asset;\n }\n\n addWasm(wasm: ArtifactSource) {\n const wasmFromMap = this.wasm.add(wasm.compileMode, wasm, false);\n if (wasmFromMap && !fullNameEquals(wasm.fullName, wasmFromMap.fullName))\n throw new Error(\n `compiler already contain info for wasm: adding = ${fullNameToString(wasm.fullName)}, contains = ${fullNameToString(wasmFromMap.fullName)}`,\n );\n }\n\n allWasm(): ArtifactSource[] {\n return this.wasm.array(this.compileMode);\n }\n\n getWasm(name: TypedArtifactName): ArtifactSource | undefined {\n if (name.type !== \"wasm\")\n throw new Error(`illegal artifact type: got ${name.type} instead of 'wasm'`);\n\n return this.wasm.get(this.compileMode, name);\n }\n\n getWasmOrError(name: TypedArtifactName): ArtifactSource {\n const wasm = this.getWasm(name);\n if (!wasm) throw new Error(`wasm info not found: ${artifactNameToString(name)}`);\n return wasm;\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) 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 \"wasm\":\n return this.getWasm(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 wasm: [],\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 if (src.fullName.type === \"wasm\") {\n // add wasm 'as-is' to be able to resolve them as dependencies\n this.addWasm(src);\n result.wasm.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(\n (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 \"wasm\":\n // wasm dependencies are added as is\n this.addWasm(src);\n result.wasm.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"],"mappings":";;;;;;;;;AAwBA,SA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AACzB;KACF,KAAK;AAEH,WAAK,SAAS,IAAI;AAClB,aAAO,OAAO,KAAK,IAAI;AACvB;KACF,KAAK;AAEH,WAAK,QAAQ,IAAI;AACjB,aAAO,KAAK,KAAK,IAAI;AACrB;KACF,KAAK;AAEH,UAAI;OACF,MAAM,MAAM,KAAK,sBAAsB,IAAI;OAC3C,MAAM,aAAa,sBAAsB,IAAI,aAAa,IAAI,UAAU,KAAK,IAAI,IAAI;AACrF,YAAK,YAAY,WAAW;AAC5B,cAAO,UAAU,KAAK,WAAW;eAC1B,OAAgB;OACvB,MAAM,MAAM;OACZ,IAAI,eAAe,+BAA+B,iBAAiB,IAAI,SAAS,CAAC;AACjF,uBAAgB,OAAO,IAAI,QAAQ;AAEnC,mBAAY,KAAK;QAAE;QAAK,KAAK,MAAM,aAAa;QAAE,CAAC;;AAErD;KACF,KAAK,OAEH;KACF,QACE,aAAY,IAAI,SAAS,KAAK;;;AAMpC,OAAI,QAAQ,WAAW,YAAY,QAAQ;IACzC,IAAI,eAAe;AAEnB,SAAK,MAAM,KAAK,YACd,iBAAgB,KAAK,EAAE,IAAI;AAE7B,UAAM,IAAI,MAAM,aAAa;;AAG/B,aAAU,YAAY,KAAK,EAAE,KAAK,qBAAqB,eAAe;;AAGxE,SAAO"}
1
+ {"version":3,"file":"compiler.js","names":[],"sources":["../../src/compiler/compiler.ts"],"sourcesContent":["import type { ArtifactSource } from \"./source\";\nimport type { TemplateWithSource } from \"./template\";\nimport { newTemplateWithSource } from \"./template\";\nimport type { TypedArtifactName, FullArtifactName, CompileMode } from \"./package\";\nimport {\n fullNameToString,\n typedArtifactNameToString,\n artifactNameToString,\n formatArtefactNameAndVersion,\n typedArtifactNamesEquals,\n fullNameEquals,\n} from \"./package\";\nimport { ArtifactStore } from \"./artifactset\";\nimport { assertNever } from \"./util\";\nimport { applyLibraryCompilerOptions, applyTemplateCompilerOptions } from \"./compileroptions\";\nimport type {\n BackendCapability,\n CompiledTemplateV3,\n TemplateDataV3,\n} from \"@milaboratories/pl-model-backend\";\n\n/** Add a capability token to a template's `requiredCapabilities` list,\n * skipping duplicates. Initializes the array lazily so the field stays\n * absent for templates that need nothing. */\nfunction addRequiredCapability(template: TemplateDataV3, capability: BackendCapability): void {\n template.requiredCapabilities = template.requiredCapabilities ?? [];\n if (!template.requiredCapabilities.includes(capability)) {\n template.requiredCapabilities.push(capability);\n }\n}\n\n/** A compilation result. */\nexport interface TemplatesAndLibs {\n templates: TemplateWithSource[];\n libs: ArtifactSource[];\n software: ArtifactSource[];\n assets: ArtifactSource[];\n wasm: 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 wasm = new ArtifactStore<ArtifactSource>((src) => src.fullName);\n private readonly templates = new ArtifactStore<TemplateWithSource>((tpl) => tpl.fullName);\n\n constructor(private readonly compileMode: CompileMode) {}\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 =\n `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, [\n ...trace,\n artifactNameToString(dep),\n ]);\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 \"wasm\": {\n const wasm = this.getWasmOrError(dep);\n data.template.wasm = data.template.wasm ?? {};\n data.template.wasm[artifactNameToString(dep)] = {\n ...formatArtefactNameAndVersion(wasm.fullName),\n sourceHash: wasm.sourceHash,\n };\n data.hashToSource[wasm.sourceHash] = wasm.src;\n // Embedding a wasm artifact means this template requires the\n // backend's wasm runtime to run. The token is propagated upward\n // when this template is in turn embedded as a sub-template.\n addRequiredCapability(data.template, \"wasm:v1\");\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 // Union the sub-template's compile-time-computed capability\n // requirements into ours, so the top template carries the full\n // transitive set without consumers having to walk the tree.\n for (const cap of tpl.data.template.requiredCapabilities ?? []) {\n addRequiredCapability(data.template, cap);\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\") 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) 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(\n `test should never be dependency of production code: ${typedArtifactNameToString(dep)} test is dependency of ${fullNameToString(lib.fullName)}`,\n );\n\n if (!this.getArtefact(dep))\n throw new Error(\n `unresolved dependency ${typedArtifactNameToString(dep)} for ${fullNameToString(lib.fullName)}`,\n );\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) 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) throw new Error(`asset info not found: ${artifactNameToString(name)}`);\n return asset;\n }\n\n addWasm(wasm: ArtifactSource) {\n const wasmFromMap = this.wasm.add(wasm.compileMode, wasm, false);\n if (wasmFromMap && !fullNameEquals(wasm.fullName, wasmFromMap.fullName))\n throw new Error(\n `compiler already contain info for wasm: adding = ${fullNameToString(wasm.fullName)}, contains = ${fullNameToString(wasmFromMap.fullName)}`,\n );\n }\n\n allWasm(): ArtifactSource[] {\n return this.wasm.array(this.compileMode);\n }\n\n getWasm(name: TypedArtifactName): ArtifactSource | undefined {\n if (name.type !== \"wasm\")\n throw new Error(`illegal artifact type: got ${name.type} instead of 'wasm'`);\n\n return this.wasm.get(this.compileMode, name);\n }\n\n getWasmOrError(name: TypedArtifactName): ArtifactSource {\n const wasm = this.getWasm(name);\n if (!wasm) throw new Error(`wasm info not found: ${artifactNameToString(name)}`);\n return wasm;\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) 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 \"wasm\":\n return this.getWasm(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 wasm: [],\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 if (src.fullName.type === \"wasm\") {\n // add wasm 'as-is' to be able to resolve them as dependencies\n this.addWasm(src);\n result.wasm.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(\n (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 \"wasm\":\n // wasm dependencies are added as is\n this.addWasm(src);\n result.wasm.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"],"mappings":";;;;;;;;;AAwBA,SAAS,sBAAsB,UAA0B,YAAqC;CAC5F,SAAS,uBAAuB,SAAS,wBAAwB,CAAC;CAClE,IAAI,CAAC,SAAS,qBAAqB,SAAS,UAAU,GACpD,SAAS,qBAAqB,KAAK,UAAU;AAEjD;AAWA,IAAa,wBAAb,MAAmC;CAOJ;CAN7B,OAAwB,IAAI,eAA+B,QAAQ,IAAI,QAAQ;CAC/E,WAA4B,IAAI,eAA+B,QAAQ,IAAI,QAAQ;CACnF,SAA0B,IAAI,eAA+B,QAAQ,IAAI,QAAQ;CACjF,OAAwB,IAAI,eAA+B,QAAQ,IAAI,QAAQ;CAC/E,YAA6B,IAAI,eAAmC,QAAQ,IAAI,QAAQ;CAExF,YAAY,aAA2C;EAA1B,KAAA,cAAA;CAA2B;;CAGxD,qCACE,UACA,MACA,MACA,OACA;EACA,KAAK,MAAM,OAAO,MAChB,QAAQ,IAAI,MAAZ;GACE,KAAK,WAAW;IACd,MAAM,MAAM,KAAK,cAAc,GAAG;IAElC,MAAM,iBAAiB,MAAM,QAAQ,qBAAqB,GAAG,CAAC;IAC9D,IAAI,kBAAkB,GAAG;KACvB,MAAM,eACJ,sCACG,MAAM,MAAM,cAAc,CAAC,CAAC,KAAK,MAAM,EAAE,MAAM,qBAAqB,GAAG;KAC5E,MAAM,IAAI,MAAM,YAAY;IAC9B;IAEA,MAAM,SAAS;KACb,GAAG,6BAA6B,IAAI,QAAQ;KAC5C,YAAY,IAAI;IAClB;IAEA,4BAA4B,IAAI,iBAAiB,MAAM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AgB,KAAK,EAAE,IAAI;IAE7B,MAAM,IAAI,MAAM,YAAY;GAC9B;GAEA,UAAU,YAAY,KAAK,EAAE,KAAK,qBAAqB,cAAc;EACvE;EAEA,OAAO;CACT;AACF"}
@@ -21,5 +21,6 @@ function hashOverride(args) {
21
21
  //#endregion
22
22
  exports.applyLibraryCompilerOptions = applyLibraryCompilerOptions;
23
23
  exports.applyTemplateCompilerOptions = applyTemplateCompilerOptions;
24
+ exports.hashOverride = hashOverride;
24
25
 
25
26
  //# sourceMappingURL=compileroptions.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"compileroptions.cjs","names":[],"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"],"mappings":";;AAIA,SAAgB,6BAA6B,MAAwB,KAAqB;AACxF,MAAK,MAAM,OAAO,KAChB,SAAQ,IAAI,MAAZ;EACE,KAAK;AACH,OAAI,eAAe,aAAa,IAAI,KAAK;AACzC;;;AAMR,SAAgB,4BAA4B,MAAwB,MAAyB;AAC3F,MAAK,MAAM,OAAO,KAChB,SAAQ,IAAI,MAAZ;EACE,KAAK,gBACH,OAAM,IAAI,MACR,+YAID;;;AAMT,SAAgB,aAAa,MAAwB;AACnD,KAAI,KAAK,UAAU,EACjB,OAAM,IAAI,MACR,mIACD;CAGH,MAAM,WAAW,KAAK,GAAG,aAAa;AAEtC,KAAI,CAAA,aAAA,OAAa,SAAS,CACxB,OAAM,IAAI,MACR,ggBAKD;AAGH,QAAO"}
1
+ {"version":3,"file":"compileroptions.cjs","names":[],"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"],"mappings":";;AAIA,SAAgB,6BAA6B,MAAwB,KAAqB;CACxF,KAAK,MAAM,OAAO,MAChB,QAAQ,IAAI,MAAZ;EACE,KAAK;GACH,IAAI,eAAe,aAAa,IAAI,IAAI;GACxC;CAEJ;AAEJ;AAEA,SAAgB,4BAA4B,MAAwB,MAAyB;CAC3F,KAAK,MAAM,OAAO,MAChB,QAAQ,IAAI,MAAZ;EACE,KAAK,iBACH,MAAM,IAAI,MACR,8YAIF;CAEJ;AAEJ;AAEA,SAAgB,aAAa,MAAwB;CACnD,IAAI,KAAK,UAAU,GACjB,MAAM,IAAI,MACR,kIACF;CAGF,MAAM,WAAW,KAAK,EAAE,CAAC,YAAY;CAErC,IAAI,CAAA,aAAA,OAAa,QAAQ,GACvB,MAAM,IAAI,MACR,+fAKF;CAGF,OAAO;AACT"}
@@ -19,6 +19,6 @@ function hashOverride(args) {
19
19
  return override;
20
20
  }
21
21
  //#endregion
22
- export { applyLibraryCompilerOptions, applyTemplateCompilerOptions };
22
+ export { applyLibraryCompilerOptions, applyTemplateCompilerOptions, hashOverride };
23
23
 
24
24
  //# sourceMappingURL=compileroptions.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"compileroptions.js","names":["util.isUUID"],"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"],"mappings":";;AAIA,SAAgB,6BAA6B,MAAwB,KAAqB;AACxF,MAAK,MAAM,OAAO,KAChB,SAAQ,IAAI,MAAZ;EACE,KAAK;AACH,OAAI,eAAe,aAAa,IAAI,KAAK;AACzC;;;AAMR,SAAgB,4BAA4B,MAAwB,MAAyB;AAC3F,MAAK,MAAM,OAAO,KAChB,SAAQ,IAAI,MAAZ;EACE,KAAK,gBACH,OAAM,IAAI,MACR,+YAID;;;AAMT,SAAgB,aAAa,MAAwB;AACnD,KAAI,KAAK,UAAU,EACjB,OAAM,IAAI,MACR,mIACD;CAGH,MAAM,WAAW,KAAK,GAAG,aAAa;AAEtC,KAAI,CAACA,OAAY,SAAS,CACxB,OAAM,IAAI,MACR,ggBAKD;AAGH,QAAO"}
1
+ {"version":3,"file":"compileroptions.js","names":["util.isUUID"],"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"],"mappings":";;AAIA,SAAgB,6BAA6B,MAAwB,KAAqB;CACxF,KAAK,MAAM,OAAO,MAChB,QAAQ,IAAI,MAAZ;EACE,KAAK;GACH,IAAI,eAAe,aAAa,IAAI,IAAI;GACxC;CAEJ;AAEJ;AAEA,SAAgB,4BAA4B,MAAwB,MAAyB;CAC3F,KAAK,MAAM,OAAO,MAChB,QAAQ,IAAI,MAAZ;EACE,KAAK,iBACH,MAAM,IAAI,MACR,8YAIF;CAEJ;AAEJ;AAEA,SAAgB,aAAa,MAAwB;CACnD,IAAI,KAAK,UAAU,GACjB,MAAM,IAAI,MACR,kIACF;CAGF,MAAM,WAAW,KAAK,EAAE,CAAC,YAAY;CAErC,IAAI,CAACA,OAAY,QAAQ,GACvB,MAAM,IAAI,MACR,+fAKF;CAGF,OAAO;AACT"}
@@ -6,11 +6,11 @@ const require_compiler = require("./compiler.cjs");
6
6
  const require_source = require("./source.cjs");
7
7
  const require_pack_limits = require("./pack_limits.cjs");
8
8
  let node_path = require("node:path");
9
- node_path = require_runtime.__toESM(node_path);
9
+ node_path = require_runtime.__toESM(node_path, 1);
10
10
  let node_fs = require("node:fs");
11
- node_fs = require_runtime.__toESM(node_fs);
11
+ node_fs = require_runtime.__toESM(node_fs, 1);
12
12
  let node_zlib = require("node:zlib");
13
- node_zlib = require_runtime.__toESM(node_zlib);
13
+ node_zlib = require_runtime.__toESM(node_zlib, 1);
14
14
  let _milaboratories_pl_model_backend = require("@milaboratories/pl-model-backend");
15
15
  let _milaboratories_resolve_helper = require("@milaboratories/resolve-helper");
16
16
  //#region src/compiler/main.ts
@@ -430,9 +430,11 @@ function savePacks(logger, compiled, mode) {
430
430
  }
431
431
  //#endregion
432
432
  exports.compile = compile;
433
+ exports.fullNameFromFileName = fullNameFromFileName;
433
434
  exports.getPackageInfo = getPackageInfo;
434
435
  exports.newCompiler = newCompiler;
435
436
  exports.parseSources = parseSources;
437
+ exports.resolvePackageJsonRoot = resolvePackageJsonRoot;
436
438
  exports.savePacks = savePacks;
437
439
 
438
440
  //# sourceMappingURL=main.cjs.map