@platforma-sdk/tengo-builder 3.0.0 → 3.0.2

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.
@@ -1,10 +1,8 @@
1
- require("../_virtual/_rolldown/runtime.cjs");
2
1
  const require_util = require("./util.cjs");
3
2
  const require_package = require("./package.cjs");
4
3
  const require_template = require("./template.cjs");
5
4
  const require_artifactset = require("./artifactset.cjs");
6
5
  const require_compileroptions = require("./compileroptions.cjs");
7
- let _milaboratories_pl_model_backend = require("@milaboratories/pl-model-backend");
8
6
  //#region src/compiler/compiler.ts
9
7
  /** Add a capability token to a template's `requiredCapabilities` list,
10
8
  * skipping duplicates. Initializes the array lazily so the field stays
@@ -68,7 +66,7 @@ var TengoTemplateCompiler = class {
68
66
  sourceHash: wasm.sourceHash
69
67
  };
70
68
  data.hashToSource[wasm.sourceHash] = wasm.src;
71
- addRequiredCapability(data.template, _milaboratories_pl_model_backend.CapabilityWasm);
69
+ addRequiredCapability(data.template, "wasm:v1");
72
70
  break;
73
71
  }
74
72
  case "template": {
@@ -1 +1 @@
1
- {"version":3,"file":"compiler.cjs","names":["ArtifactStore","artifactNameToString","formatArtefactNameAndVersion","CapabilityWasm","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 { CompiledTemplateV3, TemplateDataV3 } from \"@milaboratories/pl-model-backend\";\nimport { CapabilityWasm } 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: string): 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, CapabilityWasm);\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":";;;;;;;;;;;AAqBA,SAAS,sBAAsB,UAA0B,YAA0B;AACjF,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,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I,SAAS,CAAC;AACjF,uBAAgB,OAAO,IAAI,QAAQ;AAEnC,mBAAY,KAAK;QAAE;QAAK,KAAK,MAAM,aAAa;QAAE,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,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G/B,aAAU,YAAY,KAAK,EAAE,KAAK,qBAAqB,eAAe;;AAGxE,SAAO"}
@@ -3,7 +3,6 @@ import { artifactNameToString, formatArtefactNameAndVersion, fullNameEquals, ful
3
3
  import { newTemplateWithSource } from "./template.js";
4
4
  import { ArtifactStore } from "./artifactset.js";
5
5
  import { applyLibraryCompilerOptions, applyTemplateCompilerOptions } from "./compileroptions.js";
6
- import { CapabilityWasm } from "@milaboratories/pl-model-backend";
7
6
  //#region src/compiler/compiler.ts
8
7
  /** Add a capability token to a template's `requiredCapabilities` list,
9
8
  * skipping duplicates. Initializes the array lazily so the field stays
@@ -67,7 +66,7 @@ var TengoTemplateCompiler = class {
67
66
  sourceHash: wasm.sourceHash
68
67
  };
69
68
  data.hashToSource[wasm.sourceHash] = wasm.src;
70
- addRequiredCapability(data.template, CapabilityWasm);
69
+ addRequiredCapability(data.template, "wasm:v1");
71
70
  break;
72
71
  }
73
72
  case "template": {
@@ -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 { CompiledTemplateV3, TemplateDataV3 } from \"@milaboratories/pl-model-backend\";\nimport { CapabilityWasm } 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: string): 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, CapabilityWasm);\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":";;;;;;;;;;AAqBA,SAAS,sBAAsB,UAA0B,YAA0B;AACjF,UAAS,uBAAuB,SAAS,wBAAwB,EAAE;AACnE,KAAI,CAAC,SAAS,qBAAqB,SAAS,WAAW,CACrD,UAAS,qBAAqB,KAAK,WAAW;;AAalD,IAAa,wBAAb,MAAmC;CACjC,OAAwB,IAAI,eAA+B,QAAQ,IAAI,SAAS;CAChF,WAA4B,IAAI,eAA+B,QAAQ,IAAI,SAAS;CACpF,SAA0B,IAAI,eAA+B,QAAQ,IAAI,SAAS;CAClF,OAAwB,IAAI,eAA+B,QAAQ,IAAI,SAAS;CAChF,YAA6B,IAAI,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,QAAQ,qBAAqB,IAAI,CAAC;AAC/D,QAAI,kBAAkB,GAAG;KACvB,MAAM,eACJ,sCACG,MAAM,MAAM,eAAe,CAAC,KAAK,OAAO,CAAC,MAAM,qBAAqB,IAAI;AAC7E,WAAM,IAAI,MAAM,aAAa;;IAG/B,MAAM,SAAS;KACb,GAAG,6BAA6B,IAAI,SAAS;KAC7C,YAAY,IAAI;KACjB;AAED,gCAA4B,IAAI,iBAAiB,OAAO;AACxD,SAAK,SAAS,KAAK,qBAAqB,IAAI,IAAI;AAChD,SAAK,aAAa,OAAO,cAAc,IAAI;AAG3C,SAAK,qCAAqC,UAAU,MAAM,IAAI,cAAc,CAC1E,GAAG,OACH,qBAAqB,IAAI,CAC1B,CAAC;AAEF;;GAEF,KAAK,YAAY;IACf,MAAM,WAAW,KAAK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EH,WAAK,OAAO,IAAI;AAChB,aAAO,KAAK,KAAK,IAAI;AACrB;KACF,KAAK;AAEH,WAAK,YAAY,IAAI;AACrB,aAAO,SAAS,KAAK,IAAI;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;AAC5F,UAAS,uBAAuB,SAAS,wBAAwB,EAAE;AACnE,KAAI,CAAC,SAAS,qBAAqB,SAAS,WAAW,CACrD,UAAS,qBAAqB,KAAK,WAAW;;AAalD,IAAa,wBAAb,MAAmC;CACjC,OAAwB,IAAI,eAA+B,QAAQ,IAAI,SAAS;CAChF,WAA4B,IAAI,eAA+B,QAAQ,IAAI,SAAS;CACpF,SAA0B,IAAI,eAA+B,QAAQ,IAAI,SAAS;CAClF,OAAwB,IAAI,eAA+B,QAAQ,IAAI,SAAS;CAChF,YAA6B,IAAI,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,QAAQ,qBAAqB,IAAI,CAAC;AAC/D,QAAI,kBAAkB,GAAG;KACvB,MAAM,eACJ,sCACG,MAAM,MAAM,eAAe,CAAC,KAAK,OAAO,CAAC,MAAM,qBAAqB,IAAI;AAC7E,WAAM,IAAI,MAAM,aAAa;;IAG/B,MAAM,SAAS;KACb,G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@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@platforma-sdk/tengo-builder",
3
- "version": "3.0.0",
3
+ "version": "3.0.2",
4
4
  "description": "Pl Tengo Template Builder",
5
5
  "license": "UNLICENSED",
6
6
  "bin": {
@@ -16,7 +16,7 @@
16
16
  "@milaboratories/tengo-tester": "^1.6.4",
17
17
  "@oclif/core": "^4.0.37",
18
18
  "winston": "^3.17.0",
19
- "@milaboratories/pl-model-backend": "1.3.0",
19
+ "@milaboratories/pl-model-backend": "1.3.2",
20
20
  "@milaboratories/resolve-helper": "1.1.3",
21
21
  "@milaboratories/ts-helpers": "1.8.2"
22
22
  },
@@ -25,10 +25,10 @@
25
25
  "@vitest/coverage-istanbul": "^4.1.3",
26
26
  "typescript": "~5.9.3",
27
27
  "vitest": "^4.1.3",
28
- "@milaboratories/build-configs": "2.0.0",
28
+ "@milaboratories/oclif-index": "1.1.1",
29
29
  "@milaboratories/ts-builder": "1.5.0",
30
- "@milaboratories/ts-configs": "1.2.3",
31
- "@milaboratories/oclif-index": "1.1.1"
30
+ "@milaboratories/build-configs": "2.0.0",
31
+ "@milaboratories/ts-configs": "1.2.3"
32
32
  },
33
33
  "oclif": {
34
34
  "bin": "pl-tengo",
@@ -13,13 +13,16 @@ import {
13
13
  import { ArtifactStore } from "./artifactset";
14
14
  import { assertNever } from "./util";
15
15
  import { applyLibraryCompilerOptions, applyTemplateCompilerOptions } from "./compileroptions";
16
- import type { CompiledTemplateV3, TemplateDataV3 } from "@milaboratories/pl-model-backend";
17
- import { CapabilityWasm } from "@milaboratories/pl-model-backend";
16
+ import type {
17
+ BackendCapability,
18
+ CompiledTemplateV3,
19
+ TemplateDataV3,
20
+ } from "@milaboratories/pl-model-backend";
18
21
 
19
22
  /** Add a capability token to a template's `requiredCapabilities` list,
20
23
  * skipping duplicates. Initializes the array lazily so the field stays
21
24
  * absent for templates that need nothing. */
22
- function addRequiredCapability(template: TemplateDataV3, capability: string): void {
25
+ function addRequiredCapability(template: TemplateDataV3, capability: BackendCapability): void {
23
26
  template.requiredCapabilities = template.requiredCapabilities ?? [];
24
27
  if (!template.requiredCapabilities.includes(capability)) {
25
28
  template.requiredCapabilities.push(capability);
@@ -113,7 +116,7 @@ export class TengoTemplateCompiler {
113
116
  // Embedding a wasm artifact means this template requires the
114
117
  // backend's wasm runtime to run. The token is propagated upward
115
118
  // when this template is in turn embedded as a sub-template.
116
- addRequiredCapability(data.template, CapabilityWasm);
119
+ addRequiredCapability(data.template, "wasm:v1");
117
120
  break;
118
121
  }
119
122
  case "template": {