@platforma-sdk/tengo-builder 2.4.13 → 2.4.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -4
- package/bin/run.js +5 -5
- package/dist/commands/build.cjs +36 -36
- package/dist/commands/build.cjs.map +1 -1
- package/dist/commands/build.d.ts +5 -5
- package/dist/commands/build.js +36 -36
- package/dist/commands/build.js.map +1 -1
- package/dist/commands/check.cjs +5 -5
- package/dist/commands/check.cjs.map +1 -1
- package/dist/commands/check.d.ts +2 -2
- package/dist/commands/check.d.ts.map +1 -1
- package/dist/commands/check.js +5 -5
- package/dist/commands/check.js.map +1 -1
- package/dist/commands/dump/artifacts.cjs +4 -6
- package/dist/commands/dump/artifacts.cjs.map +1 -1
- package/dist/commands/dump/artifacts.d.ts +2 -2
- package/dist/commands/dump/artifacts.d.ts.map +1 -1
- package/dist/commands/dump/artifacts.js +4 -6
- package/dist/commands/dump/artifacts.js.map +1 -1
- package/dist/commands/dump/software.cjs +3 -5
- package/dist/commands/dump/software.cjs.map +1 -1
- package/dist/commands/dump/software.d.ts +2 -2
- package/dist/commands/dump/software.d.ts.map +1 -1
- package/dist/commands/dump/software.js +3 -5
- package/dist/commands/dump/software.js.map +1 -1
- package/dist/commands/test.cjs +5 -5
- package/dist/commands/test.cjs.map +1 -1
- package/dist/commands/test.d.ts +2 -2
- package/dist/commands/test.d.ts.map +1 -1
- package/dist/commands/test.js +5 -5
- package/dist/commands/test.js.map +1 -1
- package/dist/compiler/artifactset.cjs +2 -2
- package/dist/compiler/artifactset.cjs.map +1 -1
- package/dist/compiler/artifactset.d.ts +1 -1
- package/dist/compiler/artifactset.d.ts.map +1 -1
- package/dist/compiler/artifactset.js +2 -2
- package/dist/compiler/artifactset.js.map +1 -1
- package/dist/compiler/compiler.cjs +37 -34
- package/dist/compiler/compiler.cjs.map +1 -1
- package/dist/compiler/compiler.d.ts +3 -3
- package/dist/compiler/compiler.d.ts.map +1 -1
- package/dist/compiler/compiler.js +37 -34
- package/dist/compiler/compiler.js.map +1 -1
- package/dist/compiler/compileroptions.cjs +12 -12
- package/dist/compiler/compileroptions.cjs.map +1 -1
- package/dist/compiler/compileroptions.d.ts +2 -2
- package/dist/compiler/compileroptions.js +12 -12
- package/dist/compiler/compileroptions.js.map +1 -1
- package/dist/compiler/main.cjs +58 -58
- package/dist/compiler/main.cjs.map +1 -1
- package/dist/compiler/main.d.ts +6 -6
- package/dist/compiler/main.d.ts.map +1 -1
- package/dist/compiler/main.js +58 -58
- package/dist/compiler/main.js.map +1 -1
- package/dist/compiler/package.cjs +5 -2
- package/dist/compiler/package.cjs.map +1 -1
- package/dist/compiler/package.d.ts +6 -6
- package/dist/compiler/package.d.ts.map +1 -1
- package/dist/compiler/package.js +5 -2
- package/dist/compiler/package.js.map +1 -1
- package/dist/compiler/source.cjs +50 -52
- package/dist/compiler/source.cjs.map +1 -1
- package/dist/compiler/source.d.ts +2 -2
- package/dist/compiler/source.d.ts.map +1 -1
- package/dist/compiler/source.js +50 -52
- package/dist/compiler/source.js.map +1 -1
- package/dist/compiler/template.cjs +7 -7
- package/dist/compiler/template.cjs.map +1 -1
- package/dist/compiler/template.d.ts +2 -2
- package/dist/compiler/template.d.ts.map +1 -1
- package/dist/compiler/template.js +7 -7
- package/dist/compiler/template.js.map +1 -1
- package/dist/compiler/test.artifacts.d.ts +1 -1
- package/dist/compiler/test.artifacts.d.ts.map +1 -1
- package/dist/compiler/util.cjs +12 -12
- package/dist/compiler/util.cjs.map +1 -1
- package/dist/compiler/util.d.ts +2 -2
- package/dist/compiler/util.js +12 -12
- package/dist/compiler/util.js.map +1 -1
- package/dist/index.cjs +5 -5
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +7 -7
- package/dist/index.js +5 -5
- package/dist/index.js.map +1 -1
- package/dist/shared/basecmd.cjs +15 -15
- package/dist/shared/basecmd.cjs.map +1 -1
- package/dist/shared/basecmd.d.ts +4 -4
- package/dist/shared/basecmd.js +15 -15
- package/dist/shared/basecmd.js.map +1 -1
- package/dist/shared/dump.cjs +28 -28
- package/dist/shared/dump.cjs.map +1 -1
- package/dist/shared/dump.d.ts +2 -2
- package/dist/shared/dump.d.ts.map +1 -1
- package/dist/shared/dump.js +28 -28
- package/dist/shared/dump.js.map +1 -1
- package/dist/shared/proc.cjs +5 -5
- package/dist/shared/proc.cjs.map +1 -1
- package/dist/shared/proc.d.ts +2 -2
- package/dist/shared/proc.js +5 -5
- package/dist/shared/proc.js.map +1 -1
- package/package.json +21 -19
- package/src/commands/build.ts +57 -55
- package/src/commands/check.ts +15 -12
- package/src/commands/dump/artifacts.ts +11 -15
- package/src/commands/dump/software.ts +9 -10
- package/src/commands/test.ts +15 -12
- package/src/compiler/artifactset.ts +7 -9
- package/src/compiler/compiler.test.ts +134 -137
- package/src/compiler/compiler.ts +62 -62
- package/src/compiler/compileroptions.ts +15 -15
- package/src/compiler/main.test.ts +23 -23
- package/src/compiler/main.ts +83 -100
- package/src/compiler/package.ts +14 -12
- package/src/compiler/source.test.ts +191 -183
- package/src/compiler/source.ts +106 -79
- package/src/compiler/template.test.ts +50 -49
- package/src/compiler/template.ts +11 -21
- package/src/compiler/test.artifacts.ts +47 -47
- package/src/compiler/util.ts +17 -17
- package/src/index.ts +10 -10
- package/src/shared/basecmd.ts +16 -16
- package/src/shared/dump.ts +49 -70
- package/src/shared/proc.ts +8 -8
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"compiler.cjs","sources":["../../src/compiler/compiler.ts"],"sourcesContent":["import type { ArtifactSource } from './source';\nimport type { TemplateWithSource } from './template';\nimport { newTemplateWithSource } from './template';\nimport type {\n TypedArtifactName, FullArtifactName,\n CompileMode,\n} from './package';\nimport {\n fullNameToString,\n typedArtifactNameToString,\n artifactNameToString,\n formatArtefactNameAndVersion, typedArtifactNamesEquals,\n fullNameEquals,\n} from './package';\nimport { ArtifactStore } from './artifactset';\nimport { assertNever } from './util';\nimport { applyLibraryCompilerOptions, applyTemplateCompilerOptions } from './compileroptions';\nimport type { CompiledTemplateV3 } from '@milaboratories/pl-model-backend';\n\n/** A compilation result. */\nexport interface TemplatesAndLibs {\n templates: TemplateWithSource[];\n libs: ArtifactSource[];\n software: ArtifactSource[];\n assets: ArtifactSource[];\n}\n\nexport class TengoTemplateCompiler {\n private readonly libs = new ArtifactStore<ArtifactSource>((src) => src.fullName);\n private readonly software = new ArtifactStore<ArtifactSource>((src) => src.fullName);\n private readonly assets = new ArtifactStore<ArtifactSource>((src) => src.fullName);\n private readonly templates = new ArtifactStore<TemplateWithSource>((tpl) => tpl.fullName);\n\n constructor(\n private readonly compileMode: CompileMode,\n ) { }\n\n /** Recursively add dependencies to the template. */\n private populateTemplateDataFromDependencies(\n fullName: FullArtifactName,\n data: CompiledTemplateV3,\n deps: TypedArtifactName[],\n trace: string[],\n ) {\n for (const dep of deps) {\n switch (dep.type) {\n case 'library': {\n const lib = this.getLibOrError(dep);\n\n const recursionStart = trace.indexOf(artifactNameToString(dep));\n if (recursionStart >= 0) {\n const errorMessage = `library import recursion detected: `\n + `${trace.slice(recursionStart).join(' -> ')} -> ${artifactNameToString(dep)}`;\n throw new Error(errorMessage);\n }\n\n const tplLib = {\n ...formatArtefactNameAndVersion(lib.fullName),\n sourceHash: lib.sourceHash,\n };\n\n applyLibraryCompilerOptions(lib.compilerOptions, tplLib);\n data.template.libs[artifactNameToString(dep)] = tplLib;\n data.hashToSource[tplLib.sourceHash] = lib.src;\n\n // populate with transient library dependencies\n this.populateTemplateDataFromDependencies(fullName, data, lib.dependencies, [...trace, artifactNameToString(dep)]);\n\n break;\n }\n case 'software': {\n const software = this.getSoftwareOrError(dep);\n data.template.software[artifactNameToString(dep)] = {\n ...formatArtefactNameAndVersion(software.fullName),\n sourceHash: software.sourceHash,\n };\n data.hashToSource[software.sourceHash] = software.src;\n\n break;\n }\n case 'asset': {\n const asset = this.getAssetOrError(dep);\n // Yes, we temporarily put assets into 'software' section of template, so controller can\n // handle it the right way without updates\n data.template.software[artifactNameToString(dep)] = {\n ...formatArtefactNameAndVersion(asset.fullName),\n sourceHash: asset.sourceHash,\n };\n data.hashToSource[asset.sourceHash] = asset.src;\n break;\n }\n case 'template': {\n if (typedArtifactNamesEquals(fullName, dep))\n // skipping self reference\n continue;\n\n const tpl = this.getTemplateOrError(dep);\n data.template.templates[artifactNameToString(dep)] = tpl.data.template;\n data.hashToSource[tpl.data.template.sourceHash] = tpl.source;\n\n // add all the sources of transitivedependencies to the resulted hashToSource\n for (const [hash, src] of Object.entries(tpl.data.hashToSource)) {\n data.hashToSource[hash] = src;\n }\n\n break;\n }\n case 'test':\n throw new Error(\n `dependencies tree error: tests should never be part of template: `\n + `${typedArtifactNameToString(dep)} is dependency of ${artifactNameToString(fullName)}`,\n );\n default:\n assertNever(dep.type);\n }\n }\n }\n\n /** This method assumes that all dependencies are already added to the compiler's context */\n private compileAndAddTemplate(tplSrc: ArtifactSource): CompiledTemplateV3 {\n if (tplSrc.fullName.type !== 'template')\n throw new Error('unexpected source type');\n\n // creating template with unpopulated dependencies\n const tplData: CompiledTemplateV3 = {\n type: 'pl.tengo-template.v3',\n hashToSource: {\n [tplSrc.sourceHash]: tplSrc.src,\n },\n template: {\n ...formatArtefactNameAndVersion(tplSrc.fullName),\n templates: {},\n libs: {},\n software: {},\n assets: {},\n sourceHash: tplSrc.sourceHash,\n },\n };\n\n applyTemplateCompilerOptions(tplSrc.compilerOptions, tplData.template);\n\n // collecting dependencies in output format\n this.populateTemplateDataFromDependencies(tplSrc.fullName, tplData, tplSrc.dependencies, []);\n\n return tplData;\n }\n\n addLib(lib: ArtifactSource) {\n const libFromMap = this.libs.add(lib.compileMode, lib, false);\n if (libFromMap && !fullNameEquals(lib.fullName, libFromMap.fullName))\n throw new Error(\n `compiler already contain such library: adding = ${fullNameToString(lib.fullName)}, contains = ${fullNameToString(libFromMap.fullName)}`,\n );\n }\n\n allLibs(): ArtifactSource[] {\n return this.libs.array(this.compileMode);\n }\n\n getLib(name: TypedArtifactName): ArtifactSource | undefined {\n if (name.type !== 'library')\n throw new Error(`illegal artifact type: got ${name.type} instead of 'library`);\n return this.libs.get(this.compileMode, name);\n }\n\n getLibOrError(name: TypedArtifactName): ArtifactSource {\n const lib = this.getLib(name);\n if (!lib)\n throw new Error(`library not found: ${artifactNameToString(name)}`);\n return lib;\n }\n\n checkLibs() {\n this.libs.forEach(this.compileMode, (lib) => {\n for (const dep of lib.dependencies) {\n if (dep.type === 'test')\n throw new Error(`test should never be dependency of production code: ${typedArtifactNameToString(dep)} test is dependency of ${fullNameToString(lib.fullName)}`);\n\n if (!this.getArtefact(dep))\n throw new Error(`unresolved dependency ${typedArtifactNameToString(dep)} for ${fullNameToString(lib.fullName)}`);\n }\n });\n }\n\n addSoftware(software: ArtifactSource) {\n const swFromMap = this.software.add(software.compileMode, software, false);\n if (swFromMap && !fullNameEquals(software.fullName, swFromMap.fullName))\n throw new Error(\n `compiler already contain info for software: adding = ${fullNameToString(software.fullName)}, contains = ${fullNameToString(swFromMap.fullName)}`,\n );\n }\n\n allSoftware(): ArtifactSource[] {\n return this.software.array(this.compileMode);\n }\n\n getSoftware(name: TypedArtifactName): ArtifactSource | undefined {\n if (name.type !== 'software')\n throw new Error(`illegal artifact type: got ${name.type} instead of 'software`);\n\n return this.software.get(this.compileMode, name);\n }\n\n getSoftwareOrError(name: TypedArtifactName): ArtifactSource {\n const software = this.getSoftware(name);\n if (!software)\n throw new Error(`software info not found: ${artifactNameToString(name)}`);\n return software;\n }\n\n addAsset(asset: ArtifactSource) {\n const assetFromMap = this.assets.add(asset.compileMode, asset, false);\n if (assetFromMap && !fullNameEquals(asset.fullName, assetFromMap.fullName))\n throw new Error(\n `compiler already contain info for asset: adding = ${fullNameToString(asset.fullName)}, contains = ${fullNameToString(assetFromMap.fullName)}`,\n );\n }\n\n allAssets(): ArtifactSource[] {\n return this.assets.array(this.compileMode);\n }\n\n getAsset(name: TypedArtifactName): ArtifactSource | undefined {\n if (name.type !== 'asset')\n throw new Error(`illegal artifact type: got ${name.type} instead of 'asset`);\n\n return this.assets.get(this.compileMode, name);\n }\n\n getAssetOrError(name: TypedArtifactName): ArtifactSource {\n const asset = this.getAsset(name);\n if (!asset)\n throw new Error(`asset info not found: ${artifactNameToString(name)}`);\n return asset;\n }\n\n addTemplate(tpl: TemplateWithSource) {\n const tplFromMap = this.templates.add(tpl.compileMode, tpl, false);\n if (tplFromMap && !fullNameEquals(tpl.fullName, tplFromMap.fullName))\n throw new Error(\n `compiler already contain such template: adding = ${fullNameToString(tpl.fullName)}, contains = ${fullNameToString(tplFromMap.fullName)}`,\n );\n }\n\n allTemplates(): TemplateWithSource[] {\n return this.templates.array(this.compileMode);\n }\n\n getTemplate(name: TypedArtifactName): TemplateWithSource | undefined {\n if (name.type !== 'template')\n throw new Error(`illegal artifact type: got ${name.type} instead of 'template`);\n return this.templates.get(this.compileMode, name);\n }\n\n getTemplateOrError(name: TypedArtifactName): TemplateWithSource {\n const tpl = this.getTemplate(name);\n if (!tpl)\n throw new Error(`template not found: ${artifactNameToString(name)}`);\n return tpl;\n }\n\n getArtefact(name: TypedArtifactName): ArtifactSource | TemplateWithSource | undefined {\n switch (name.type) {\n case 'template':\n return this.getTemplate(name);\n case 'library':\n return this.getLib(name);\n case 'software':\n return this.getSoftware(name);\n case 'asset':\n return this.getAsset(name);\n case 'test':\n // Tests are ignored by the complier. They should never be compiled into templates or libs and\n // should never be a dependency.\n return undefined;\n default:\n assertNever(name.type);\n }\n }\n\n compileAndAdd(sources: ArtifactSource[]): TemplatesAndLibs {\n const result: TemplatesAndLibs = {\n templates: [],\n libs: [],\n software: [],\n assets: [],\n };\n\n let current: ArtifactSource[] = [];\n\n for (const src of sources) {\n if (src.fullName.type === 'library') {\n // add libraries 'as-is' to be able to resolve them as dependencies\n this.addLib(src);\n result.libs.push(src);\n } else if (src.fullName.type === 'software') {\n // add software 'as-is' to be able to resolve them as dependencies\n this.addSoftware(src);\n result.software.push(src);\n } else if (src.fullName.type === 'asset') {\n // add assets 'as-is' to be able to resolve them as dependencies\n this.addAsset(src);\n result.assets.push(src);\n } else {\n current.push(src);\n }\n }\n\n while (current.length > 0) {\n const unprocessed: { src: ArtifactSource; err: Error }[] = [];\n\n for (const src of current) {\n //\n // If one of the dependencies can't be resolved with current compiler context,\n // we put aside the source until next iteration, in hope that the dependency\n // will be satisfied then.\n //\n // This is equivalent to topological sorting of input sources.\n //\n const unsatisfied = src.dependencies.filter((dep) =>\n !this.getArtefact(dep)\n // allow self reference for templates\n && !(src.fullName.type === 'template' && typedArtifactNamesEquals(src.fullName, dep)),\n );\n if (unsatisfied.length > 0) {\n let errorMessage = `Unsatisfied dependencies in ${fullNameToString(src.fullName)}:\\n`;\n for (const dep of unsatisfied) {\n errorMessage += ` - ${typedArtifactNameToString(dep)}\\n`;\n }\n unprocessed.push({ src, err: new Error(errorMessage) });\n\n continue;\n }\n\n // type specific processing\n switch (src.fullName.type) {\n case 'library':\n // libraries are added as is\n this.addLib(src);\n result.libs.push(src);\n break;\n case 'software':\n // software dependencies are added as is\n this.addSoftware(src);\n result.software.push(src);\n break;\n case 'asset':\n // software dependencies are added as is\n this.addAsset(src);\n result.assets.push(src);\n break;\n case 'template':\n // templates are compiled and then added\n try {\n const tpl = this.compileAndAddTemplate(src);\n const tplWithSrc = newTemplateWithSource(src.compileMode, src.fullName, tpl, src.src);\n this.addTemplate(tplWithSrc);\n result.templates.push(tplWithSrc);\n } catch (error: unknown) {\n const err = error as Error;\n let errorMessage = `Unsatisfied dependencies in ${fullNameToString(src.fullName)}:\\n`;\n errorMessage += ` - ${err.message}\\n`;\n\n unprocessed.push({ src, err: Error(errorMessage) }); // one or more dependencies are not resolvable yet\n }\n break;\n case 'test':\n // Ignore tests: they never should be part of compiled code or be a dependency.\n break;\n default:\n assertNever(src.fullName.type);\n }\n }\n\n // checking that we successfully added at least one source,\n // if not all the source files in unprocessed array have unmet dependencies\n if (current.length === unprocessed.length) {\n let errorMessage = '';\n\n for (const u of unprocessed) {\n errorMessage += `\\n${u.err.message}`;\n }\n throw new Error(errorMessage);\n }\n\n current = unprocessed.map(({ src: ArtifactSource }) => ArtifactSource);\n }\n\n return result;\n }\n}\n"],"names":["ArtifactStore","artifactNameToString","formatArtefactNameAndVersion","applyLibraryCompilerOptions","typedArtifactNamesEquals","typedArtifactNameToString","assertNever","applyTemplateCompilerOptions","fullNameEquals","fullNameToString","newTemplateWithSource"],"mappings":";;;;;;;;MA2Ba,qBAAqB,CAAA;AAOb,IAAA,WAAA;AANF,IAAA,IAAI,GAAG,IAAIA,yBAAa,CAAiB,CAAC,GAAG,KAAK,GAAG,CAAC,QAAQ,CAAC;AAC/D,IAAA,QAAQ,GAAG,IAAIA,yBAAa,CAAiB,CAAC,GAAG,KAAK,GAAG,CAAC,QAAQ,CAAC;AACnE,IAAA,MAAM,GAAG,IAAIA,yBAAa,CAAiB,CAAC,GAAG,KAAK,GAAG,CAAC,QAAQ,CAAC;AACjE,IAAA,SAAS,GAAG,IAAIA,yBAAa,CAAqB,CAAC,GAAG,KAAK,GAAG,CAAC,QAAQ,CAAC;AAEzF,IAAA,WAAA,CACmB,WAAwB,EAAA;QAAxB,IAAA,CAAA,WAAW,GAAX,WAAW;IAC1B;;AAGI,IAAA,oCAAoC,CAC1C,QAA0B,EAC1B,IAAwB,EACxB,IAAyB,EACzB,KAAe,EAAA;AAEf,QAAA,KAAK,MAAM,GAAG,IAAI,IAAI,EAAE;AACtB,YAAA,QAAQ,GAAG,CAAC,IAAI;gBACd,KAAK,SAAS,EAAE;oBACd,MAAM,GAAG,GAAG,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC;oBAEnC,MAAM,cAAc,GAAG,KAAK,CAAC,OAAO,CAACC,6BAAoB,CAAC,GAAG,CAAC,CAAC;AAC/D,oBAAA,IAAI,cAAc,IAAI,CAAC,EAAE;wBACvB,MAAM,YAAY,GAAG,CAAA,mCAAA;AACjB,8BAAA,CAAA,EAAG,KAAK,CAAC,KAAK,CAAC,cAAc,CAAC,CAAC,I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+BD,yBAAgB,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAA,GAAA,CAAK;AACrF,4BAAA,YAAY,IAAI,CAAA,IAAA,EAAO,GAAG,CAAC,OAAO,IAAI;AAEtC,4BAAA,WAAW,CAAC,IAAI,CAAC,EAAE,GAAG,EAAE,GAAG,EAAE,KAAK,CAAC,YAAY,CAAC,EAAE,CAAC,CAAC;wBACtD;wBACA;AACF,oBAAA,KAAK,MAAM;;wBAET;AACF,oBAAA;AACE,wBAAAH,gBAAW,CAAC,GAAG,CAAC,QAAQ,CAAC,IAAI,CAAC;;YAEpC;;;YAIA,IAAI,OAAO,CAAC,MAAM,KAAK,WAAW,CAAC,MAAM,EAAE;gBACzC,IAAI,YAAY,GAAG,EAAE;AAErB,gBAAA,KAAK,MAAM,CAAC,IAAI,WAAW,EAAE;oBAC3B,YAAY,IAAI,KAAK,CAAC,CAAC,GAAG,CAAC,OAAO,EAAE;gBACtC;AACA,gBAAA,MAAM,IAAI,KAAK,CAAC,YAAY,CAAC;YAC/B;AAEA,YAAA,OAAO,GAAG,WAAW,CAAC,GAAG,CAAC,CAAC,EAAE,GAAG,EAAE,cAAc,EAAE,KAAK,cAAc,CAAC;QACxE;AAEA,QAAA,OAAO,MAAM;IACf;AACD;;;;"}
|
|
1
|
+
{"version":3,"file":"compiler.cjs","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 } from \"@milaboratories/pl-model-backend\";\n\n/** A compilation result. */\nexport interface TemplatesAndLibs {\n templates: TemplateWithSource[];\n libs: ArtifactSource[];\n software: ArtifactSource[];\n assets: ArtifactSource[];\n}\n\nexport class TengoTemplateCompiler {\n private readonly libs = new ArtifactStore<ArtifactSource>((src) => src.fullName);\n private readonly software = new ArtifactStore<ArtifactSource>((src) => src.fullName);\n private readonly assets = new ArtifactStore<ArtifactSource>((src) => src.fullName);\n private readonly templates = new ArtifactStore<TemplateWithSource>((tpl) => tpl.fullName);\n\n constructor(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 \"template\": {\n if (typedArtifactNamesEquals(fullName, dep))\n // skipping self reference\n continue;\n\n const tpl = this.getTemplateOrError(dep);\n data.template.templates[artifactNameToString(dep)] = tpl.data.template;\n data.hashToSource[tpl.data.template.sourceHash] = tpl.source;\n\n // add all the sources of transitivedependencies to the resulted hashToSource\n for (const [hash, src] of Object.entries(tpl.data.hashToSource)) {\n data.hashToSource[hash] = src;\n }\n\n break;\n }\n case \"test\":\n throw new Error(\n `dependencies tree error: tests should never be part of template: ` +\n `${typedArtifactNameToString(dep)} is dependency of ${artifactNameToString(fullName)}`,\n );\n default:\n assertNever(dep.type);\n }\n }\n }\n\n /** This method assumes that all dependencies are already added to the compiler's context */\n private compileAndAddTemplate(tplSrc: ArtifactSource): CompiledTemplateV3 {\n if (tplSrc.fullName.type !== \"template\") 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 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 \"test\":\n // Tests are ignored by the complier. They should never be compiled into templates or libs and\n // should never be a dependency.\n return undefined;\n default:\n assertNever(name.type);\n }\n }\n\n compileAndAdd(sources: ArtifactSource[]): TemplatesAndLibs {\n const result: TemplatesAndLibs = {\n templates: [],\n libs: [],\n software: [],\n assets: [],\n };\n\n let current: ArtifactSource[] = [];\n\n for (const src of sources) {\n if (src.fullName.type === \"library\") {\n // add libraries 'as-is' to be able to resolve them as dependencies\n this.addLib(src);\n result.libs.push(src);\n } else if (src.fullName.type === \"software\") {\n // add software 'as-is' to be able to resolve them as dependencies\n this.addSoftware(src);\n result.software.push(src);\n } else if (src.fullName.type === \"asset\") {\n // add assets 'as-is' to be able to resolve them as dependencies\n this.addAsset(src);\n result.assets.push(src);\n } else {\n current.push(src);\n }\n }\n\n while (current.length > 0) {\n const unprocessed: { src: ArtifactSource; err: Error }[] = [];\n\n for (const src of current) {\n //\n // If one of the dependencies can't be resolved with current compiler context,\n // we put aside the source until next iteration, in hope that the dependency\n // will be satisfied then.\n //\n // This is equivalent to topological sorting of input sources.\n //\n const unsatisfied = src.dependencies.filter(\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 \"template\":\n // templates are compiled and then added\n try {\n const tpl = this.compileAndAddTemplate(src);\n const tplWithSrc = newTemplateWithSource(src.compileMode, src.fullName, tpl, src.src);\n this.addTemplate(tplWithSrc);\n result.templates.push(tplWithSrc);\n } catch (error: unknown) {\n const err = error as Error;\n let errorMessage = `Unsatisfied dependencies in ${fullNameToString(src.fullName)}:\\n`;\n errorMessage += ` - ${err.message}\\n`;\n\n unprocessed.push({ src, err: Error(errorMessage) }); // one or more dependencies are not resolvable yet\n }\n break;\n case \"test\":\n // Ignore tests: they never should be part of compiled code or be a dependency.\n break;\n default:\n assertNever(src.fullName.type);\n }\n }\n\n // checking that we successfully added at least one source,\n // if not all the source files in unprocessed array have unmet dependencies\n if (current.length === unprocessed.length) {\n let errorMessage = \"\";\n\n for (const u of unprocessed) {\n errorMessage += `\\n${u.err.message}`;\n }\n throw new Error(errorMessage);\n }\n\n current = unprocessed.map(({ src: ArtifactSource }) => ArtifactSource);\n }\n\n return result;\n }\n}\n"],"names":["ArtifactStore","artifactNameToString","formatArtefactNameAndVersion","applyLibraryCompilerOptions","typedArtifactNamesEquals","typedArtifactNameToString","assertNever","applyTemplateCompilerOptions","fullNameEquals","fullNameToString","newTemplateWithSource"],"mappings":";;;;;;;;MAyBa,qBAAqB,CAAA;AAMH,IAAA,WAAA;AALZ,IAAA,IAAI,GAAG,IAAIA,yBAAa,CAAiB,CAAC,GAAG,KAAK,GAAG,CAAC,QAAQ,CAAC;AAC/D,IAAA,QAAQ,GAAG,IAAIA,yBAAa,CAAiB,CAAC,GAAG,KAAK,GAAG,CAAC,QAAQ,CAAC;AACnE,IAAA,MAAM,GAAG,IAAIA,yBAAa,CAAiB,CAAC,GAAG,KAAK,GAAG,CAAC,QAAQ,CAAC;AACjE,IAAA,SAAS,GAAG,IAAIA,yBAAa,CAAqB,CAAC,GAAG,KAAK,GAAG,CAAC,QAAQ,CAAC;AAEzF,IAAA,WAAA,CAA6B,WAAwB,EAAA;QAAxB,IAAA,CAAA,WAAW,GAAX,WAAW;IAAgB;;AAGhD,IAAA,oCAAoC,CAC1C,QAA0B,EAC1B,IAAwB,EACxB,IAAyB,EACzB,KAAe,EAAA;AAEf,QAAA,KAAK,MAAM,GAAG,IAAI,IAAI,EAAE;AACtB,YAAA,QAAQ,GAAG,CAAC,IAAI;gBACd,KAAK,SAAS,EAAE;oBACd,MAAM,GAAG,GAAG,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC;oBAEnC,MAAM,cAAc,GAAG,KAAK,CAAC,OAAO,CAACC,6BAAoB,CAAC,GAAG,CAAC,CAAC;AAC/D,oBAAA,IAAI,cAAc,IAAI,CAAC,EAAE;wBACvB,MAAM,YAAY,GAChB,CAAA,mCAAA,CAAqC;AACrC,4BAAA,CAAA,EAAG,KAAK,CAAC,KAAK,CAAC,cAAc,CAAC,CAAC,IAAI,CAAC,MAA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AG,CAAA,4BAAA,EAA+BD,yBAAgB,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAA,GAAA,CAAK;AACrF,4BAAA,YAAY,IAAI,CAAA,IAAA,EAAO,GAAG,CAAC,OAAO,IAAI;AAEtC,4BAAA,WAAW,CAAC,IAAI,CAAC,EAAE,GAAG,EAAE,GAAG,EAAE,KAAK,CAAC,YAAY,CAAC,EAAE,CAAC,CAAC;wBACtD;wBACA;AACF,oBAAA,KAAK,MAAM;;wBAET;AACF,oBAAA;AACE,wBAAAH,gBAAW,CAAC,GAAG,CAAC,QAAQ,CAAC,IAAI,CAAC;;YAEpC;;;YAIA,IAAI,OAAO,CAAC,MAAM,KAAK,WAAW,CAAC,MAAM,EAAE;gBACzC,IAAI,YAAY,GAAG,EAAE;AAErB,gBAAA,KAAK,MAAM,CAAC,IAAI,WAAW,EAAE;oBAC3B,YAAY,IAAI,KAAK,CAAC,CAAC,GAAG,CAAC,OAAO,EAAE;gBACtC;AACA,gBAAA,MAAM,IAAI,KAAK,CAAC,YAAY,CAAC;YAC/B;AAEA,YAAA,OAAO,GAAG,WAAW,CAAC,GAAG,CAAC,CAAC,EAAE,GAAG,EAAE,cAAc,EAAE,KAAK,cAAc,CAAC;QACxE;AAEA,QAAA,OAAO,MAAM;IACf;AACD;;;;"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type { ArtifactSource } from
|
|
2
|
-
import type { TemplateWithSource } from
|
|
3
|
-
import type { TypedArtifactName, CompileMode } from
|
|
1
|
+
import type { ArtifactSource } from "./source";
|
|
2
|
+
import type { TemplateWithSource } from "./template";
|
|
3
|
+
import type { TypedArtifactName, CompileMode } from "./package";
|
|
4
4
|
/** A compilation result. */
|
|
5
5
|
export interface TemplatesAndLibs {
|
|
6
6
|
templates: TemplateWithSource[];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"compiler.d.ts","sourceRoot":"","sources":["../../src/compiler/compiler.ts"],"names":[],"mappings":"AAAA,OAAO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AE,iBAAiB,GAAG,cAAc,GAAG,SAAS;IAOhE,kBAAkB,CAAC,IAAI,EAAE,iBAAiB,GAAG,cAAc;IAM3D,QAAQ,CAAC,KAAK,EAAE,cAAc;IAQ9B,SAAS,IAAI,cAAc,EAAE;IAI7B,QAAQ,CAAC,IAAI,EAAE,iBAAiB,GAAG,cAAc,GAAG,SAAS;IAO7D,eAAe,CAAC,IAAI,EAAE,iBAAiB,GAAG,cAAc;IAMxD,WAAW,CAAC,GAAG,EAAE,kBAAkB;IAQnC,YAAY,IAAI,kBAAkB,EAAE;IAIpC,WAAW,CAAC,IAAI,EAAE,iBAAiB,GAAG,kBAAkB,GAAG,SAAS;IAMpE,kBAAkB,CAAC,IAAI,EAAE,iBAAiB,GAAG,kBAAkB;IAM/D,WAAW,CAAC,IAAI,EAAE,iBAAiB,GAAG,cAAc,GAAG,kBAAkB,GAAG,SAAS;IAmBrF,aAAa,CAAC,OAAO,EAAE,cAAc,EAAE,GAAG,gBAAgB;CA+G3D"}
|
|
@@ -17,12 +17,12 @@ class TengoTemplateCompiler {
|
|
|
17
17
|
populateTemplateDataFromDependencies(fullName, data, deps, trace) {
|
|
18
18
|
for (const dep of deps) {
|
|
19
19
|
switch (dep.type) {
|
|
20
|
-
case
|
|
20
|
+
case "library": {
|
|
21
21
|
const lib = this.getLibOrError(dep);
|
|
22
22
|
const recursionStart = trace.indexOf(artifactNameToString(dep));
|
|
23
23
|
if (recursionStart >= 0) {
|
|
24
|
-
const errorMessage = `library import recursion detected: `
|
|
25
|
-
|
|
24
|
+
const errorMessage = `library import recursion detected: ` +
|
|
25
|
+
`${trace.slice(recursionStart).join(" -> ")} -> ${artifactNameToString(dep)}`;
|
|
26
26
|
throw new Error(errorMessage);
|
|
27
27
|
}
|
|
28
28
|
const tplLib = {
|
|
@@ -33,10 +33,13 @@ class TengoTemplateCompiler {
|
|
|
33
33
|
data.template.libs[artifactNameToString(dep)] = tplLib;
|
|
34
34
|
data.hashToSource[tplLib.sourceHash] = lib.src;
|
|
35
35
|
// populate with transient library dependencies
|
|
36
|
-
this.populateTemplateDataFromDependencies(fullName, data, lib.dependencies, [
|
|
36
|
+
this.populateTemplateDataFromDependencies(fullName, data, lib.dependencies, [
|
|
37
|
+
...trace,
|
|
38
|
+
artifactNameToString(dep),
|
|
39
|
+
]);
|
|
37
40
|
break;
|
|
38
41
|
}
|
|
39
|
-
case
|
|
42
|
+
case "software": {
|
|
40
43
|
const software = this.getSoftwareOrError(dep);
|
|
41
44
|
data.template.software[artifactNameToString(dep)] = {
|
|
42
45
|
...formatArtefactNameAndVersion(software.fullName),
|
|
@@ -45,7 +48,7 @@ class TengoTemplateCompiler {
|
|
|
45
48
|
data.hashToSource[software.sourceHash] = software.src;
|
|
46
49
|
break;
|
|
47
50
|
}
|
|
48
|
-
case
|
|
51
|
+
case "asset": {
|
|
49
52
|
const asset = this.getAssetOrError(dep);
|
|
50
53
|
// Yes, we temporarily put assets into 'software' section of template, so controller can
|
|
51
54
|
// handle it the right way without updates
|
|
@@ -56,7 +59,7 @@ class TengoTemplateCompiler {
|
|
|
56
59
|
data.hashToSource[asset.sourceHash] = asset.src;
|
|
57
60
|
break;
|
|
58
61
|
}
|
|
59
|
-
case
|
|
62
|
+
case "template": {
|
|
60
63
|
if (typedArtifactNamesEquals(fullName, dep))
|
|
61
64
|
// skipping self reference
|
|
62
65
|
continue;
|
|
@@ -69,9 +72,9 @@ class TengoTemplateCompiler {
|
|
|
69
72
|
}
|
|
70
73
|
break;
|
|
71
74
|
}
|
|
72
|
-
case
|
|
73
|
-
throw new Error(`dependencies tree error: tests should never be part of template: `
|
|
74
|
-
|
|
75
|
+
case "test":
|
|
76
|
+
throw new Error(`dependencies tree error: tests should never be part of template: ` +
|
|
77
|
+
`${typedArtifactNameToString(dep)} is dependency of ${artifactNameToString(fullName)}`);
|
|
75
78
|
default:
|
|
76
79
|
assertNever(dep.type);
|
|
77
80
|
}
|
|
@@ -79,11 +82,11 @@ class TengoTemplateCompiler {
|
|
|
79
82
|
}
|
|
80
83
|
/** This method assumes that all dependencies are already added to the compiler's context */
|
|
81
84
|
compileAndAddTemplate(tplSrc) {
|
|
82
|
-
if (tplSrc.fullName.type !==
|
|
83
|
-
throw new Error(
|
|
85
|
+
if (tplSrc.fullName.type !== "template")
|
|
86
|
+
throw new Error("unexpected source type");
|
|
84
87
|
// creating template with unpopulated dependencies
|
|
85
88
|
const tplData = {
|
|
86
|
-
type:
|
|
89
|
+
type: "pl.tengo-template.v3",
|
|
87
90
|
hashToSource: {
|
|
88
91
|
[tplSrc.sourceHash]: tplSrc.src,
|
|
89
92
|
},
|
|
@@ -110,7 +113,7 @@ class TengoTemplateCompiler {
|
|
|
110
113
|
return this.libs.array(this.compileMode);
|
|
111
114
|
}
|
|
112
115
|
getLib(name) {
|
|
113
|
-
if (name.type !==
|
|
116
|
+
if (name.type !== "library")
|
|
114
117
|
throw new Error(`illegal artifact type: got ${name.type} instead of 'library`);
|
|
115
118
|
return this.libs.get(this.compileMode, name);
|
|
116
119
|
}
|
|
@@ -123,7 +126,7 @@ class TengoTemplateCompiler {
|
|
|
123
126
|
checkLibs() {
|
|
124
127
|
this.libs.forEach(this.compileMode, (lib) => {
|
|
125
128
|
for (const dep of lib.dependencies) {
|
|
126
|
-
if (dep.type ===
|
|
129
|
+
if (dep.type === "test")
|
|
127
130
|
throw new Error(`test should never be dependency of production code: ${typedArtifactNameToString(dep)} test is dependency of ${fullNameToString(lib.fullName)}`);
|
|
128
131
|
if (!this.getArtefact(dep))
|
|
129
132
|
throw new Error(`unresolved dependency ${typedArtifactNameToString(dep)} for ${fullNameToString(lib.fullName)}`);
|
|
@@ -139,7 +142,7 @@ class TengoTemplateCompiler {
|
|
|
139
142
|
return this.software.array(this.compileMode);
|
|
140
143
|
}
|
|
141
144
|
getSoftware(name) {
|
|
142
|
-
if (name.type !==
|
|
145
|
+
if (name.type !== "software")
|
|
143
146
|
throw new Error(`illegal artifact type: got ${name.type} instead of 'software`);
|
|
144
147
|
return this.software.get(this.compileMode, name);
|
|
145
148
|
}
|
|
@@ -158,7 +161,7 @@ class TengoTemplateCompiler {
|
|
|
158
161
|
return this.assets.array(this.compileMode);
|
|
159
162
|
}
|
|
160
163
|
getAsset(name) {
|
|
161
|
-
if (name.type !==
|
|
164
|
+
if (name.type !== "asset")
|
|
162
165
|
throw new Error(`illegal artifact type: got ${name.type} instead of 'asset`);
|
|
163
166
|
return this.assets.get(this.compileMode, name);
|
|
164
167
|
}
|
|
@@ -177,7 +180,7 @@ class TengoTemplateCompiler {
|
|
|
177
180
|
return this.templates.array(this.compileMode);
|
|
178
181
|
}
|
|
179
182
|
getTemplate(name) {
|
|
180
|
-
if (name.type !==
|
|
183
|
+
if (name.type !== "template")
|
|
181
184
|
throw new Error(`illegal artifact type: got ${name.type} instead of 'template`);
|
|
182
185
|
return this.templates.get(this.compileMode, name);
|
|
183
186
|
}
|
|
@@ -189,15 +192,15 @@ class TengoTemplateCompiler {
|
|
|
189
192
|
}
|
|
190
193
|
getArtefact(name) {
|
|
191
194
|
switch (name.type) {
|
|
192
|
-
case
|
|
195
|
+
case "template":
|
|
193
196
|
return this.getTemplate(name);
|
|
194
|
-
case
|
|
197
|
+
case "library":
|
|
195
198
|
return this.getLib(name);
|
|
196
|
-
case
|
|
199
|
+
case "software":
|
|
197
200
|
return this.getSoftware(name);
|
|
198
|
-
case
|
|
201
|
+
case "asset":
|
|
199
202
|
return this.getAsset(name);
|
|
200
|
-
case
|
|
203
|
+
case "test":
|
|
201
204
|
// Tests are ignored by the complier. They should never be compiled into templates or libs and
|
|
202
205
|
// should never be a dependency.
|
|
203
206
|
return undefined;
|
|
@@ -214,17 +217,17 @@ class TengoTemplateCompiler {
|
|
|
214
217
|
};
|
|
215
218
|
let current = [];
|
|
216
219
|
for (const src of sources) {
|
|
217
|
-
if (src.fullName.type ===
|
|
220
|
+
if (src.fullName.type === "library") {
|
|
218
221
|
// add libraries 'as-is' to be able to resolve them as dependencies
|
|
219
222
|
this.addLib(src);
|
|
220
223
|
result.libs.push(src);
|
|
221
224
|
}
|
|
222
|
-
else if (src.fullName.type ===
|
|
225
|
+
else if (src.fullName.type === "software") {
|
|
223
226
|
// add software 'as-is' to be able to resolve them as dependencies
|
|
224
227
|
this.addSoftware(src);
|
|
225
228
|
result.software.push(src);
|
|
226
229
|
}
|
|
227
|
-
else if (src.fullName.type ===
|
|
230
|
+
else if (src.fullName.type === "asset") {
|
|
228
231
|
// add assets 'as-is' to be able to resolve them as dependencies
|
|
229
232
|
this.addAsset(src);
|
|
230
233
|
result.assets.push(src);
|
|
@@ -243,9 +246,9 @@ class TengoTemplateCompiler {
|
|
|
243
246
|
//
|
|
244
247
|
// This is equivalent to topological sorting of input sources.
|
|
245
248
|
//
|
|
246
|
-
const unsatisfied = src.dependencies.filter((dep) => !this.getArtefact(dep)
|
|
249
|
+
const unsatisfied = src.dependencies.filter((dep) => !this.getArtefact(dep) &&
|
|
247
250
|
// allow self reference for templates
|
|
248
|
-
|
|
251
|
+
!(src.fullName.type === "template" && typedArtifactNamesEquals(src.fullName, dep)));
|
|
249
252
|
if (unsatisfied.length > 0) {
|
|
250
253
|
let errorMessage = `Unsatisfied dependencies in ${fullNameToString(src.fullName)}:\n`;
|
|
251
254
|
for (const dep of unsatisfied) {
|
|
@@ -256,22 +259,22 @@ class TengoTemplateCompiler {
|
|
|
256
259
|
}
|
|
257
260
|
// type specific processing
|
|
258
261
|
switch (src.fullName.type) {
|
|
259
|
-
case
|
|
262
|
+
case "library":
|
|
260
263
|
// libraries are added as is
|
|
261
264
|
this.addLib(src);
|
|
262
265
|
result.libs.push(src);
|
|
263
266
|
break;
|
|
264
|
-
case
|
|
267
|
+
case "software":
|
|
265
268
|
// software dependencies are added as is
|
|
266
269
|
this.addSoftware(src);
|
|
267
270
|
result.software.push(src);
|
|
268
271
|
break;
|
|
269
|
-
case
|
|
272
|
+
case "asset":
|
|
270
273
|
// software dependencies are added as is
|
|
271
274
|
this.addAsset(src);
|
|
272
275
|
result.assets.push(src);
|
|
273
276
|
break;
|
|
274
|
-
case
|
|
277
|
+
case "template":
|
|
275
278
|
// templates are compiled and then added
|
|
276
279
|
try {
|
|
277
280
|
const tpl = this.compileAndAddTemplate(src);
|
|
@@ -286,7 +289,7 @@ class TengoTemplateCompiler {
|
|
|
286
289
|
unprocessed.push({ src, err: Error(errorMessage) }); // one or more dependencies are not resolvable yet
|
|
287
290
|
}
|
|
288
291
|
break;
|
|
289
|
-
case
|
|
292
|
+
case "test":
|
|
290
293
|
// Ignore tests: they never should be part of compiled code or be a dependency.
|
|
291
294
|
break;
|
|
292
295
|
default:
|
|
@@ -296,7 +299,7 @@ class TengoTemplateCompiler {
|
|
|
296
299
|
// checking that we successfully added at least one source,
|
|
297
300
|
// if not all the source files in unprocessed array have unmet dependencies
|
|
298
301
|
if (current.length === unprocessed.length) {
|
|
299
|
-
let errorMessage =
|
|
302
|
+
let errorMessage = "";
|
|
300
303
|
for (const u of unprocessed) {
|
|
301
304
|
errorMessage += `\n${u.err.message}`;
|
|
302
305
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"compiler.js","sources":["../../src/compiler/compiler.ts"],"sourcesContent":["import type { ArtifactSource } from './source';\nimport type { TemplateWithSource } from './template';\nimport { newTemplateWithSource } from './template';\nimport type {\n TypedArtifactName, FullArtifactName,\n CompileMode,\n} from './package';\nimport {\n fullNameToString,\n typedArtifactNameToString,\n artifactNameToString,\n formatArtefactNameAndVersion, typedArtifactNamesEquals,\n fullNameEquals,\n} from './package';\nimport { ArtifactStore } from './artifactset';\nimport { assertNever } from './util';\nimport { applyLibraryCompilerOptions, applyTemplateCompilerOptions } from './compileroptions';\nimport type { CompiledTemplateV3 } from '@milaboratories/pl-model-backend';\n\n/** A compilation result. */\nexport interface TemplatesAndLibs {\n templates: TemplateWithSource[];\n libs: ArtifactSource[];\n software: ArtifactSource[];\n assets: ArtifactSource[];\n}\n\nexport class TengoTemplateCompiler {\n private readonly libs = new ArtifactStore<ArtifactSource>((src) => src.fullName);\n private readonly software = new ArtifactStore<ArtifactSource>((src) => src.fullName);\n private readonly assets = new ArtifactStore<ArtifactSource>((src) => src.fullName);\n private readonly templates = new ArtifactStore<TemplateWithSource>((tpl) => tpl.fullName);\n\n constructor(\n private readonly compileMode: CompileMode,\n ) { }\n\n /** Recursively add dependencies to the template. */\n private populateTemplateDataFromDependencies(\n fullName: FullArtifactName,\n data: CompiledTemplateV3,\n deps: TypedArtifactName[],\n trace: string[],\n ) {\n for (const dep of deps) {\n switch (dep.type) {\n case 'library': {\n const lib = this.getLibOrError(dep);\n\n const recursionStart = trace.indexOf(artifactNameToString(dep));\n if (recursionStart >= 0) {\n const errorMessage = `library import recursion detected: `\n + `${trace.slice(recursionStart).join(' -> ')} -> ${artifactNameToString(dep)}`;\n throw new Error(errorMessage);\n }\n\n const tplLib = {\n ...formatArtefactNameAndVersion(lib.fullName),\n sourceHash: lib.sourceHash,\n };\n\n applyLibraryCompilerOptions(lib.compilerOptions, tplLib);\n data.template.libs[artifactNameToString(dep)] = tplLib;\n data.hashToSource[tplLib.sourceHash] = lib.src;\n\n // populate with transient library dependencies\n this.populateTemplateDataFromDependencies(fullName, data, lib.dependencies, [...trace, artifactNameToString(dep)]);\n\n break;\n }\n case 'software': {\n const software = this.getSoftwareOrError(dep);\n data.template.software[artifactNameToString(dep)] = {\n ...formatArtefactNameAndVersion(software.fullName),\n sourceHash: software.sourceHash,\n };\n data.hashToSource[software.sourceHash] = software.src;\n\n break;\n }\n case 'asset': {\n const asset = this.getAssetOrError(dep);\n // Yes, we temporarily put assets into 'software' section of template, so controller can\n // handle it the right way without updates\n data.template.software[artifactNameToString(dep)] = {\n ...formatArtefactNameAndVersion(asset.fullName),\n sourceHash: asset.sourceHash,\n };\n data.hashToSource[asset.sourceHash] = asset.src;\n break;\n }\n case 'template': {\n if (typedArtifactNamesEquals(fullName, dep))\n // skipping self reference\n continue;\n\n const tpl = this.getTemplateOrError(dep);\n data.template.templates[artifactNameToString(dep)] = tpl.data.template;\n data.hashToSource[tpl.data.template.sourceHash] = tpl.source;\n\n // add all the sources of transitivedependencies to the resulted hashToSource\n for (const [hash, src] of Object.entries(tpl.data.hashToSource)) {\n data.hashToSource[hash] = src;\n }\n\n break;\n }\n case 'test':\n throw new Error(\n `dependencies tree error: tests should never be part of template: `\n + `${typedArtifactNameToString(dep)} is dependency of ${artifactNameToString(fullName)}`,\n );\n default:\n assertNever(dep.type);\n }\n }\n }\n\n /** This method assumes that all dependencies are already added to the compiler's context */\n private compileAndAddTemplate(tplSrc: ArtifactSource): CompiledTemplateV3 {\n if (tplSrc.fullName.type !== 'template')\n throw new Error('unexpected source type');\n\n // creating template with unpopulated dependencies\n const tplData: CompiledTemplateV3 = {\n type: 'pl.tengo-template.v3',\n hashToSource: {\n [tplSrc.sourceHash]: tplSrc.src,\n },\n template: {\n ...formatArtefactNameAndVersion(tplSrc.fullName),\n templates: {},\n libs: {},\n software: {},\n assets: {},\n sourceHash: tplSrc.sourceHash,\n },\n };\n\n applyTemplateCompilerOptions(tplSrc.compilerOptions, tplData.template);\n\n // collecting dependencies in output format\n this.populateTemplateDataFromDependencies(tplSrc.fullName, tplData, tplSrc.dependencies, []);\n\n return tplData;\n }\n\n addLib(lib: ArtifactSource) {\n const libFromMap = this.libs.add(lib.compileMode, lib, false);\n if (libFromMap && !fullNameEquals(lib.fullName, libFromMap.fullName))\n throw new Error(\n `compiler already contain such library: adding = ${fullNameToString(lib.fullName)}, contains = ${fullNameToString(libFromMap.fullName)}`,\n );\n }\n\n allLibs(): ArtifactSource[] {\n return this.libs.array(this.compileMode);\n }\n\n getLib(name: TypedArtifactName): ArtifactSource | undefined {\n if (name.type !== 'library')\n throw new Error(`illegal artifact type: got ${name.type} instead of 'library`);\n return this.libs.get(this.compileMode, name);\n }\n\n getLibOrError(name: TypedArtifactName): ArtifactSource {\n const lib = this.getLib(name);\n if (!lib)\n throw new Error(`library not found: ${artifactNameToString(name)}`);\n return lib;\n }\n\n checkLibs() {\n this.libs.forEach(this.compileMode, (lib) => {\n for (const dep of lib.dependencies) {\n if (dep.type === 'test')\n throw new Error(`test should never be dependency of production code: ${typedArtifactNameToString(dep)} test is dependency of ${fullNameToString(lib.fullName)}`);\n\n if (!this.getArtefact(dep))\n throw new Error(`unresolved dependency ${typedArtifactNameToString(dep)} for ${fullNameToString(lib.fullName)}`);\n }\n });\n }\n\n addSoftware(software: ArtifactSource) {\n const swFromMap = this.software.add(software.compileMode, software, false);\n if (swFromMap && !fullNameEquals(software.fullName, swFromMap.fullName))\n throw new Error(\n `compiler already contain info for software: adding = ${fullNameToString(software.fullName)}, contains = ${fullNameToString(swFromMap.fullName)}`,\n );\n }\n\n allSoftware(): ArtifactSource[] {\n return this.software.array(this.compileMode);\n }\n\n getSoftware(name: TypedArtifactName): ArtifactSource | undefined {\n if (name.type !== 'software')\n throw new Error(`illegal artifact type: got ${name.type} instead of 'software`);\n\n return this.software.get(this.compileMode, name);\n }\n\n getSoftwareOrError(name: TypedArtifactName): ArtifactSource {\n const software = this.getSoftware(name);\n if (!software)\n throw new Error(`software info not found: ${artifactNameToString(name)}`);\n return software;\n }\n\n addAsset(asset: ArtifactSource) {\n const assetFromMap = this.assets.add(asset.compileMode, asset, false);\n if (assetFromMap && !fullNameEquals(asset.fullName, assetFromMap.fullName))\n throw new Error(\n `compiler already contain info for asset: adding = ${fullNameToString(asset.fullName)}, contains = ${fullNameToString(assetFromMap.fullName)}`,\n );\n }\n\n allAssets(): ArtifactSource[] {\n return this.assets.array(this.compileMode);\n }\n\n getAsset(name: TypedArtifactName): ArtifactSource | undefined {\n if (name.type !== 'asset')\n throw new Error(`illegal artifact type: got ${name.type} instead of 'asset`);\n\n return this.assets.get(this.compileMode, name);\n }\n\n getAssetOrError(name: TypedArtifactName): ArtifactSource {\n const asset = this.getAsset(name);\n if (!asset)\n throw new Error(`asset info not found: ${artifactNameToString(name)}`);\n return asset;\n }\n\n addTemplate(tpl: TemplateWithSource) {\n const tplFromMap = this.templates.add(tpl.compileMode, tpl, false);\n if (tplFromMap && !fullNameEquals(tpl.fullName, tplFromMap.fullName))\n throw new Error(\n `compiler already contain such template: adding = ${fullNameToString(tpl.fullName)}, contains = ${fullNameToString(tplFromMap.fullName)}`,\n );\n }\n\n allTemplates(): TemplateWithSource[] {\n return this.templates.array(this.compileMode);\n }\n\n getTemplate(name: TypedArtifactName): TemplateWithSource | undefined {\n if (name.type !== 'template')\n throw new Error(`illegal artifact type: got ${name.type} instead of 'template`);\n return this.templates.get(this.compileMode, name);\n }\n\n getTemplateOrError(name: TypedArtifactName): TemplateWithSource {\n const tpl = this.getTemplate(name);\n if (!tpl)\n throw new Error(`template not found: ${artifactNameToString(name)}`);\n return tpl;\n }\n\n getArtefact(name: TypedArtifactName): ArtifactSource | TemplateWithSource | undefined {\n switch (name.type) {\n case 'template':\n return this.getTemplate(name);\n case 'library':\n return this.getLib(name);\n case 'software':\n return this.getSoftware(name);\n case 'asset':\n return this.getAsset(name);\n case 'test':\n // Tests are ignored by the complier. They should never be compiled into templates or libs and\n // should never be a dependency.\n return undefined;\n default:\n assertNever(name.type);\n }\n }\n\n compileAndAdd(sources: ArtifactSource[]): TemplatesAndLibs {\n const result: TemplatesAndLibs = {\n templates: [],\n libs: [],\n software: [],\n assets: [],\n };\n\n let current: ArtifactSource[] = [];\n\n for (const src of sources) {\n if (src.fullName.type === 'library') {\n // add libraries 'as-is' to be able to resolve them as dependencies\n this.addLib(src);\n result.libs.push(src);\n } else if (src.fullName.type === 'software') {\n // add software 'as-is' to be able to resolve them as dependencies\n this.addSoftware(src);\n result.software.push(src);\n } else if (src.fullName.type === 'asset') {\n // add assets 'as-is' to be able to resolve them as dependencies\n this.addAsset(src);\n result.assets.push(src);\n } else {\n current.push(src);\n }\n }\n\n while (current.length > 0) {\n const unprocessed: { src: ArtifactSource; err: Error }[] = [];\n\n for (const src of current) {\n //\n // If one of the dependencies can't be resolved with current compiler context,\n // we put aside the source until next iteration, in hope that the dependency\n // will be satisfied then.\n //\n // This is equivalent to topological sorting of input sources.\n //\n const unsatisfied = src.dependencies.filter((dep) =>\n !this.getArtefact(dep)\n // allow self reference for templates\n && !(src.fullName.type === 'template' && typedArtifactNamesEquals(src.fullName, dep)),\n );\n if (unsatisfied.length > 0) {\n let errorMessage = `Unsatisfied dependencies in ${fullNameToString(src.fullName)}:\\n`;\n for (const dep of unsatisfied) {\n errorMessage += ` - ${typedArtifactNameToString(dep)}\\n`;\n }\n unprocessed.push({ src, err: new Error(errorMessage) });\n\n continue;\n }\n\n // type specific processing\n switch (src.fullName.type) {\n case 'library':\n // libraries are added as is\n this.addLib(src);\n result.libs.push(src);\n break;\n case 'software':\n // software dependencies are added as is\n this.addSoftware(src);\n result.software.push(src);\n break;\n case 'asset':\n // software dependencies are added as is\n this.addAsset(src);\n result.assets.push(src);\n break;\n case 'template':\n // templates are compiled and then added\n try {\n const tpl = this.compileAndAddTemplate(src);\n const tplWithSrc = newTemplateWithSource(src.compileMode, src.fullName, tpl, src.src);\n this.addTemplate(tplWithSrc);\n result.templates.push(tplWithSrc);\n } catch (error: unknown) {\n const err = error as Error;\n let errorMessage = `Unsatisfied dependencies in ${fullNameToString(src.fullName)}:\\n`;\n errorMessage += ` - ${err.message}\\n`;\n\n unprocessed.push({ src, err: Error(errorMessage) }); // one or more dependencies are not resolvable yet\n }\n break;\n case 'test':\n // Ignore tests: they never should be part of compiled code or be a dependency.\n break;\n default:\n assertNever(src.fullName.type);\n }\n }\n\n // checking that we successfully added at least one source,\n // if not all the source files in unprocessed array have unmet dependencies\n if (current.length === unprocessed.length) {\n let errorMessage = '';\n\n for (const u of unprocessed) {\n errorMessage += `\\n${u.err.message}`;\n }\n throw new Error(errorMessage);\n }\n\n current = unprocessed.map(({ src: ArtifactSource }) => ArtifactSource);\n }\n\n return result;\n }\n}\n"],"names":[],"mappings":";;;;;;MA2Ba,qBAAqB,CAAA;AAOb,IAAA,WAAA;AANF,IAAA,IAAI,GAAG,IAAI,aAAa,CAAiB,CAAC,GAAG,KAAK,GAAG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zC,IAAI,YAAY,GAAG,EAAE;AAErB,gBAAA,KAAK,MAAM,CAAC,IAAI,WAAW,EAAE;oBAC3B,YAAY,IAAI,KAAK,CAAC,CAAC,GAAG,CAAC,OAAO,EAAE;gBACtC;AACA,gBAAA,MAAM,IAAI,KAAK,CAAC,YAAY,CAAC;YAC/B;AAEA,YAAA,OAAO,GAAG,WAAW,CAAC,GAAG,CAAC,CAAC,EAAE,GAAG,EAAE,cAAc,EAAE,KAAK,cAAc,CAAC;QACxE;AAEA,QAAA,OAAO,MAAM;IACf;AACD;;;;"}
|
|
1
|
+
{"version":3,"file":"compiler.js","sources":["../../src/compiler/compiler.ts"],"sourcesContent":["import type { ArtifactSource } from \"./source\";\nimport type { TemplateWithSource } from \"./template\";\nimport { newTemplateWithSource } from \"./template\";\nimport type { 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 } from \"@milaboratories/pl-model-backend\";\n\n/** A compilation result. */\nexport interface TemplatesAndLibs {\n templates: TemplateWithSource[];\n libs: ArtifactSource[];\n software: ArtifactSource[];\n assets: ArtifactSource[];\n}\n\nexport class TengoTemplateCompiler {\n private readonly libs = new ArtifactStore<ArtifactSource>((src) => src.fullName);\n private readonly software = new ArtifactStore<ArtifactSource>((src) => src.fullName);\n private readonly assets = new ArtifactStore<ArtifactSource>((src) => src.fullName);\n private readonly templates = new ArtifactStore<TemplateWithSource>((tpl) => tpl.fullName);\n\n constructor(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 \"template\": {\n if (typedArtifactNamesEquals(fullName, dep))\n // skipping self reference\n continue;\n\n const tpl = this.getTemplateOrError(dep);\n data.template.templates[artifactNameToString(dep)] = tpl.data.template;\n data.hashToSource[tpl.data.template.sourceHash] = tpl.source;\n\n // add all the sources of transitivedependencies to the resulted hashToSource\n for (const [hash, src] of Object.entries(tpl.data.hashToSource)) {\n data.hashToSource[hash] = src;\n }\n\n break;\n }\n case \"test\":\n throw new Error(\n `dependencies tree error: tests should never be part of template: ` +\n `${typedArtifactNameToString(dep)} is dependency of ${artifactNameToString(fullName)}`,\n );\n default:\n assertNever(dep.type);\n }\n }\n }\n\n /** This method assumes that all dependencies are already added to the compiler's context */\n private compileAndAddTemplate(tplSrc: ArtifactSource): CompiledTemplateV3 {\n if (tplSrc.fullName.type !== \"template\") 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 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 \"test\":\n // Tests are ignored by the complier. They should never be compiled into templates or libs and\n // should never be a dependency.\n return undefined;\n default:\n assertNever(name.type);\n }\n }\n\n compileAndAdd(sources: ArtifactSource[]): TemplatesAndLibs {\n const result: TemplatesAndLibs = {\n templates: [],\n libs: [],\n software: [],\n assets: [],\n };\n\n let current: ArtifactSource[] = [];\n\n for (const src of sources) {\n if (src.fullName.type === \"library\") {\n // add libraries 'as-is' to be able to resolve them as dependencies\n this.addLib(src);\n result.libs.push(src);\n } else if (src.fullName.type === \"software\") {\n // add software 'as-is' to be able to resolve them as dependencies\n this.addSoftware(src);\n result.software.push(src);\n } else if (src.fullName.type === \"asset\") {\n // add assets 'as-is' to be able to resolve them as dependencies\n this.addAsset(src);\n result.assets.push(src);\n } else {\n current.push(src);\n }\n }\n\n while (current.length > 0) {\n const unprocessed: { src: ArtifactSource; err: Error }[] = [];\n\n for (const src of current) {\n //\n // If one of the dependencies can't be resolved with current compiler context,\n // we put aside the source until next iteration, in hope that the dependency\n // will be satisfied then.\n //\n // This is equivalent to topological sorting of input sources.\n //\n const unsatisfied = src.dependencies.filter(\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 \"template\":\n // templates are compiled and then added\n try {\n const tpl = this.compileAndAddTemplate(src);\n const tplWithSrc = newTemplateWithSource(src.compileMode, src.fullName, tpl, src.src);\n this.addTemplate(tplWithSrc);\n result.templates.push(tplWithSrc);\n } catch (error: unknown) {\n const err = error as Error;\n let errorMessage = `Unsatisfied dependencies in ${fullNameToString(src.fullName)}:\\n`;\n errorMessage += ` - ${err.message}\\n`;\n\n unprocessed.push({ src, err: Error(errorMessage) }); // one or more dependencies are not resolvable yet\n }\n break;\n case \"test\":\n // Ignore tests: they never should be part of compiled code or be a dependency.\n break;\n default:\n assertNever(src.fullName.type);\n }\n }\n\n // checking that we successfully added at least one source,\n // if not all the source files in unprocessed array have unmet dependencies\n if (current.length === unprocessed.length) {\n let errorMessage = \"\";\n\n for (const u of unprocessed) {\n errorMessage += `\\n${u.err.message}`;\n }\n throw new Error(errorMessage);\n }\n\n current = unprocessed.map(({ src: ArtifactSource }) => ArtifactSource);\n }\n\n return result;\n }\n}\n"],"names":[],"mappings":";;;;;;MAyBa,qBAAqB,CAAA;AAMH,IAAA,WAAA;AALZ,IAAA,IAAI,GAAG,IAAI,aAAa,CAAiB,CAAC,GAAG,KAAK,GAAG,CAAC,QAAQ,CAAC;AAC/D,IAAA,QAAQ,GAAG,IAAI,aAAa,CAAiB,CAAC,GAAG,KAAK,GAAG,CAAC,QAAQ,CAAC;AACnE,IAAA,MAAM,GAAG,IAAI,aAAa,CAAiB,CAAC,GAAG,KAAK,GAAG,CAAC,QAAQ,CAAC;AACjE,IAAA,SAAS,GAAG,IAAI,aA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AAY,CAAC;YAC/B;AAEA,YAAA,OAAO,GAAG,WAAW,CAAC,GAAG,CAAC,CAAC,EAAE,GAAG,EAAE,cAAc,EAAE,KAAK,cAAc,CAAC;QACxE;AAEA,QAAA,OAAO,MAAM;IACf;AACD;;;;"}
|
|
@@ -5,7 +5,7 @@ var util = require('./util.cjs');
|
|
|
5
5
|
function applyTemplateCompilerOptions(opts, tpl) {
|
|
6
6
|
for (const opt of opts) {
|
|
7
7
|
switch (opt.name) {
|
|
8
|
-
case
|
|
8
|
+
case "hash_override": {
|
|
9
9
|
tpl.hashOverride = hashOverride(opt.args);
|
|
10
10
|
break;
|
|
11
11
|
}
|
|
@@ -15,26 +15,26 @@ function applyTemplateCompilerOptions(opts, tpl) {
|
|
|
15
15
|
function applyLibraryCompilerOptions(opts, _lib) {
|
|
16
16
|
for (const opt of opts) {
|
|
17
17
|
switch (opt.name) {
|
|
18
|
-
case
|
|
19
|
-
throw new Error(`hash_override compiler option can be used ONLY on template level. Even in templates it is already dangerous enough`
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
18
|
+
case "hash_override": {
|
|
19
|
+
throw new Error(`hash_override compiler option can be used ONLY on template level. Even in templates it is already dangerous enough` +
|
|
20
|
+
` to potentially break everything in Platforma Backend. In libraries with the transitive dependencies` +
|
|
21
|
+
` resolution and flattening of libraries list on template level, it becomes so unpredictibally disasterous, that` +
|
|
22
|
+
` we are doomed to never find the ends of a knot if anything goes wrong.`);
|
|
23
23
|
}
|
|
24
24
|
}
|
|
25
25
|
}
|
|
26
26
|
}
|
|
27
27
|
function hashOverride(args) {
|
|
28
28
|
if (args.length != 1) {
|
|
29
|
-
throw new Error(
|
|
29
|
+
throw new Error("hash_override compiler option expects exactly one argument: hash_override <some string>. Note, you can use only UUID as a value.");
|
|
30
30
|
}
|
|
31
31
|
const override = args[0].toLowerCase();
|
|
32
32
|
if (!util.isUUID(override)) {
|
|
33
|
-
throw new Error(
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
33
|
+
throw new Error("hash_override must contain valid UUID as an override. As hash_override affects deduplication," +
|
|
34
|
+
" it becomes completely not possible to distinguish several different templates from each other on backend's side." +
|
|
35
|
+
' This means, if you set hash_override to a simple value (say, letter "a") on two completely different templates,' +
|
|
36
|
+
" they will be marked as interchangeable on backend's side with unpredictable consequences." +
|
|
37
|
+
" UUID looks like a safe enough tradeoff between the feature usage simplicity and duplication safety");
|
|
38
38
|
}
|
|
39
39
|
return override;
|
|
40
40
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"compileroptions.cjs","sources":["../../src/compiler/compileroptions.ts"],"sourcesContent":["import type { TemplateDataV3, TemplateLibDataV3 } from
|
|
1
|
+
{"version":3,"file":"compileroptions.cjs","sources":["../../src/compiler/compileroptions.ts"],"sourcesContent":["import type { TemplateDataV3, TemplateLibDataV3 } from \"@milaboratories/pl-model-backend\";\nimport type { CompilerOption } from \"./package\";\nimport * as util from \"./util\";\n\nexport function applyTemplateCompilerOptions(opts: CompilerOption[], tpl: TemplateDataV3) {\n for (const opt of opts) {\n switch (opt.name) {\n case \"hash_override\": {\n tpl.hashOverride = hashOverride(opt.args);\n break;\n }\n }\n }\n}\n\nexport function applyLibraryCompilerOptions(opts: CompilerOption[], _lib: TemplateLibDataV3) {\n for (const opt of opts) {\n switch (opt.name) {\n case \"hash_override\": {\n throw new Error(\n `hash_override compiler option can be used ONLY on template level. Even in templates it is already dangerous enough` +\n ` to potentially break everything in Platforma Backend. In libraries with the transitive dependencies` +\n ` resolution and flattening of libraries list on template level, it becomes so unpredictibally disasterous, that` +\n ` we are doomed to never find the ends of a knot if anything goes wrong.`,\n );\n }\n }\n }\n}\n\nexport function hashOverride(args: string[]): string {\n if (args.length != 1) {\n throw new Error(\n \"hash_override compiler option expects exactly one argument: hash_override <some string>. Note, you can use only UUID as a value.\",\n );\n }\n\n const override = args[0].toLowerCase();\n\n if (!util.isUUID(override)) {\n throw new Error(\n \"hash_override must contain valid UUID as an override. As hash_override affects deduplication,\" +\n \" it becomes completely not possible to distinguish several different templates from each other on backend's side.\" +\n ' This means, if you set hash_override to a simple value (say, letter \"a\") on two completely different templates,' +\n \" they will be marked as interchangeable on backend's side with unpredictable consequences.\" +\n \" UUID looks like a safe enough tradeoff between the feature usage simplicity and duplication safety\",\n );\n }\n\n return override;\n}\n"],"names":["util.isUUID"],"mappings":";;;;AAIM,SAAU,4BAA4B,CAAC,IAAsB,EAAE,GAAmB,EAAA;AACtF,IAAA,KAAK,MAAM,GAAG,IAAI,IAAI,EAAE;AACtB,QAAA,QAAQ,GAAG,CAAC,IAAI;YACd,KAAK,eAAe,EAAE;gBACpB,GAAG,CAAC,YAAY,GAAG,YAAY,CAAC,GAAG,CAAC,IAAI,CAAC;gBACzC;YACF;;IAEJ;AACF;AAEM,SAAU,2BAA2B,CAAC,IAAsB,EAAE,IAAuB,EAAA;AACzF,IAAA,KAAK,MAAM,GAAG,IAAI,IAAI,EAAE;AACtB,QAAA,QAAQ,GAAG,CAAC,IAAI;YACd,KAAK,eAAe,EAAE;gBACpB,MAAM,IAAI,KAAK,CACb,CAAA,kHAAA,CAAoH;oBAClH,CAAA,oGAAA,CAAsG;oBACtG,CAAA,+GAAA,CAAiH;AACjH,oBAAA,CAAA,uEAAA,CAAyE,CAC5E;YACH;;IAEJ;AACF;AAEM,SAAU,YAAY,CAAC,IAAc,EAAA;AACzC,IAAA,IAAI,IAAI,CAAC,MAAM,IAAI,CAAC,EAAE;AACpB,QAAA,MAAM,IAAI,KAAK,CACb,kIAAkI,CACnI;IACH;IAEA,MAAM,QAAQ,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE;IAEtC,IAAI,CAACA,WAAW,CAAC,QAAQ,CAAC,EAAE;QAC1B,MAAM,IAAI,KAAK,CACb,+FAA+F;YAC7F,mHAAmH;YACnH,kHAAkH;YAClH,4FAA4F;AAC5F,YAAA,qGAAqG,CACxG;IACH;AAEA,IAAA,OAAO,QAAQ;AACjB;;;;;;"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { TemplateDataV3, TemplateLibDataV3 } from
|
|
2
|
-
import type { CompilerOption } from
|
|
1
|
+
import type { TemplateDataV3, TemplateLibDataV3 } from "@milaboratories/pl-model-backend";
|
|
2
|
+
import type { CompilerOption } from "./package";
|
|
3
3
|
export declare function applyTemplateCompilerOptions(opts: CompilerOption[], tpl: TemplateDataV3): void;
|
|
4
4
|
export declare function applyLibraryCompilerOptions(opts: CompilerOption[], _lib: TemplateLibDataV3): void;
|
|
5
5
|
export declare function hashOverride(args: string[]): string;
|
|
@@ -3,7 +3,7 @@ import { isUUID } from './util.js';
|
|
|
3
3
|
function applyTemplateCompilerOptions(opts, tpl) {
|
|
4
4
|
for (const opt of opts) {
|
|
5
5
|
switch (opt.name) {
|
|
6
|
-
case
|
|
6
|
+
case "hash_override": {
|
|
7
7
|
tpl.hashOverride = hashOverride(opt.args);
|
|
8
8
|
break;
|
|
9
9
|
}
|
|
@@ -13,26 +13,26 @@ function applyTemplateCompilerOptions(opts, tpl) {
|
|
|
13
13
|
function applyLibraryCompilerOptions(opts, _lib) {
|
|
14
14
|
for (const opt of opts) {
|
|
15
15
|
switch (opt.name) {
|
|
16
|
-
case
|
|
17
|
-
throw new Error(`hash_override compiler option can be used ONLY on template level. Even in templates it is already dangerous enough`
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
16
|
+
case "hash_override": {
|
|
17
|
+
throw new Error(`hash_override compiler option can be used ONLY on template level. Even in templates it is already dangerous enough` +
|
|
18
|
+
` to potentially break everything in Platforma Backend. In libraries with the transitive dependencies` +
|
|
19
|
+
` resolution and flattening of libraries list on template level, it becomes so unpredictibally disasterous, that` +
|
|
20
|
+
` we are doomed to never find the ends of a knot if anything goes wrong.`);
|
|
21
21
|
}
|
|
22
22
|
}
|
|
23
23
|
}
|
|
24
24
|
}
|
|
25
25
|
function hashOverride(args) {
|
|
26
26
|
if (args.length != 1) {
|
|
27
|
-
throw new Error(
|
|
27
|
+
throw new Error("hash_override compiler option expects exactly one argument: hash_override <some string>. Note, you can use only UUID as a value.");
|
|
28
28
|
}
|
|
29
29
|
const override = args[0].toLowerCase();
|
|
30
30
|
if (!isUUID(override)) {
|
|
31
|
-
throw new Error(
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
31
|
+
throw new Error("hash_override must contain valid UUID as an override. As hash_override affects deduplication," +
|
|
32
|
+
" it becomes completely not possible to distinguish several different templates from each other on backend's side." +
|
|
33
|
+
' This means, if you set hash_override to a simple value (say, letter "a") on two completely different templates,' +
|
|
34
|
+
" they will be marked as interchangeable on backend's side with unpredictable consequences." +
|
|
35
|
+
" UUID looks like a safe enough tradeoff between the feature usage simplicity and duplication safety");
|
|
36
36
|
}
|
|
37
37
|
return override;
|
|
38
38
|
}
|