@milaboratories/pl-middle-layer 1.66.8 → 1.66.10

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.
@@ -28,24 +28,24 @@ function createTemplateV3Tree(tx, tplData) {
28
28
  return createResourceCached(tplData.template, TemplateRenderer, tplData.hashToSource);
29
29
  }
30
30
  const LibRenderer = {
31
- updateCacheKey(resource, hash, sources) {
32
- hash.update(_milaboratories_pl_model_backend.PlTemplateLibV1.type.name).update(_milaboratories_pl_model_backend.PlTemplateLibV1.type.version).update(resource.name).update(resource.version).update(getSourceCode(resource.name, sources, resource.sourceHash));
31
+ updateCacheKey(resource, hash, _sources) {
32
+ hash.update(_milaboratories_pl_model_backend.PlTemplateLibV1.type.name).update(_milaboratories_pl_model_backend.PlTemplateLibV1.type.version).update(resource.name).update(resource.version).update(resource.sourceHash);
33
33
  },
34
34
  render(resource, tx, _creator, sources) {
35
35
  return tx.createValue(_milaboratories_pl_model_backend.PlTemplateLibV1.type, JSON.stringify(_milaboratories_pl_model_backend.PlTemplateLibV1.fromV3Data(resource, getSourceCode(resource.name, sources, resource.sourceHash)).data));
36
36
  }
37
37
  };
38
38
  const WasmRenderer = {
39
- updateCacheKey(resource, hash, sources) {
40
- hash.update(_milaboratories_pl_model_backend.PlWasmV1.type.name).update(_milaboratories_pl_model_backend.PlWasmV1.type.version).update(resource.name).update(resource.version).update(getSourceCode(resource.name, sources, resource.sourceHash));
39
+ updateCacheKey(resource, hash, _sources) {
40
+ hash.update(_milaboratories_pl_model_backend.PlWasmV1.type.name).update(_milaboratories_pl_model_backend.PlWasmV1.type.version).update(resource.name).update(resource.version).update(resource.sourceHash);
41
41
  },
42
42
  render(resource, tx, _creator, sources) {
43
43
  return tx.createValue(_milaboratories_pl_model_backend.PlWasmV1.type, JSON.stringify(_milaboratories_pl_model_backend.PlWasmV1.fromV3Data(resource, getSourceCode(resource.name, sources, resource.sourceHash)).data));
44
44
  }
45
45
  };
46
46
  const SoftwareInfoRenderer = {
47
- updateCacheKey(resource, hash, sources) {
48
- hash.update(_milaboratories_pl_model_backend.PlTemplateSoftwareV1.type.name).update(_milaboratories_pl_model_backend.PlTemplateSoftwareV1.type.version).update(resource.name).update(resource.version).update(getSourceCode(resource.name, sources, resource.sourceHash));
47
+ updateCacheKey(resource, hash, _sources) {
48
+ hash.update(_milaboratories_pl_model_backend.PlTemplateSoftwareV1.type.name).update(_milaboratories_pl_model_backend.PlTemplateSoftwareV1.type.version).update(resource.name).update(resource.version).update(resource.sourceHash);
49
49
  },
50
50
  render(resource, tx, _creator, sources) {
51
51
  const sw = _milaboratories_pl_model_backend.PlTemplateSoftwareV1.fromV3Data(resource, getSourceCode(resource.name, sources, resource.sourceHash));
@@ -57,7 +57,7 @@ const SoftwareInfoRenderer = {
57
57
  };
58
58
  const TemplateRenderer = {
59
59
  updateCacheKey(resource, hash, sources) {
60
- hash.update(_milaboratories_pl_model_backend.PlTemplateV1.type.name).update(_milaboratories_pl_model_backend.PlTemplateV1.type.version).update(resource.hashOverride ?? "no-override").update(resource.name).update(resource.version).update(getSourceCode(resource.name, sources, resource.sourceHash));
60
+ hash.update(_milaboratories_pl_model_backend.PlTemplateV1.type.name).update(_milaboratories_pl_model_backend.PlTemplateV1.type.version).update(resource.hashOverride ?? "no-override").update(resource.name).update(resource.version).update(resource.sourceHash);
61
61
  const srt = (entries) => {
62
62
  entries.sort((a, b) => a[0] === b[0] ? 0 : a[0] < b[0] ? -1 : 1);
63
63
  return entries;
@@ -1 +1 @@
1
- {"version":3,"file":"direct_template_loader_v3.cjs","names":["PlTemplateLibV1","PlWasmV1","PlTemplateSoftwareV1","PlTemplateV1","PlTemplateOverrideV1"],"sources":["../../../src/mutator/template/direct_template_loader_v3.ts"],"sourcesContent":["import type { AnyRef, AnyResourceRef, PlTransaction } from \"@milaboratories/pl-client\";\nimport type { Hash } from \"node:crypto\";\nimport { createHash } from \"node:crypto\";\nimport type {\n CompiledTemplateV3,\n TemplateDataV3,\n TemplateLibDataV3,\n TemplateSoftwareDataV3,\n TemplateWasmDataV3,\n} from \"@milaboratories/pl-model-backend\";\nimport {\n PlTemplateLibV1,\n PlTemplateSoftwareV1,\n PlTemplateV1,\n PlTemplateOverrideV1,\n PlWasmV1,\n} from \"@milaboratories/pl-model-backend\";\nimport { notEmpty } from \"@milaboratories/ts-helpers\";\n\n/**\n * Renders the tree of templates by caching all resource ids\n * by their cache keys.\n * It's different from v2 version because we provide\n * the hash map of the code of all sources everywhere.\n * It does a double-dispatch on the node type (template, library etc),\n * and creates resources.\n *\n * IMO, it'd be clearer to rewrite it with Visitor pattern, and separate\n * tree traversing and operations on it, but I don't have time to do it now.\n */\nexport function createTemplateV3Tree(tx: PlTransaction, tplData: CompiledTemplateV3): AnyRef {\n const resourceCache = new Map<string, AnyResourceRef>();\n\n const createResourceCached = <T>(\n resource: T,\n renderer: Renderer<T>,\n hashToSource: Record<string, string>,\n ): AnyResourceRef => {\n const key: Hash = createHash(\"sha256\");\n renderer.updateCacheKey(resource, key, hashToSource);\n\n const rKey = key.digest(\"hex\");\n\n if (!resourceCache.has(rKey)) {\n const rId = renderer.render(resource, tx, createResourceCached, hashToSource);\n resourceCache.set(rKey, rId);\n }\n\n return resourceCache.get(rKey)!;\n };\n\n return createResourceCached(tplData.template, TemplateRenderer, tplData.hashToSource);\n}\n\ntype Renderer<T> = {\n /** Updates the cache key by adding all info of the artifact. */\n updateCacheKey: CacheKey<T>;\n /** Create resources for all dependencies recursively and then for this artifact. */\n render: (\n resource: T,\n tx: PlTransaction,\n creator: Creator,\n sources: Record<string, string>,\n ) => AnyResourceRef;\n};\ntype CacheKey<T> = (resource: T, key: Hash, sources: Record<string, string>) => void;\ntype Creator = <T>(\n resource: T,\n renderer: Renderer<T>,\n sources: Record<string, string>,\n) => AnyResourceRef;\n\nconst LibRenderer: Renderer<TemplateLibDataV3> = {\n updateCacheKey(resource, hash, sources) {\n hash\n .update(PlTemplateLibV1.type.name)\n .update(PlTemplateLibV1.type.version)\n .update(resource.name)\n .update(resource.version)\n .update(getSourceCode(resource.name, sources, resource.sourceHash));\n },\n render(resource, tx, _creator, sources) {\n return tx.createValue(\n PlTemplateLibV1.type,\n JSON.stringify(\n PlTemplateLibV1.fromV3Data(\n resource,\n getSourceCode(resource.name, sources, resource.sourceHash),\n ).data,\n ),\n );\n },\n};\n\nconst WasmRenderer: Renderer<TemplateWasmDataV3> = {\n updateCacheKey(resource, hash, sources) {\n hash\n .update(PlWasmV1.type.name)\n .update(PlWasmV1.type.version)\n .update(resource.name)\n .update(resource.version)\n .update(getSourceCode(resource.name, sources, resource.sourceHash));\n },\n render(resource, tx, _creator, sources) {\n return tx.createValue(\n PlWasmV1.type,\n JSON.stringify(\n PlWasmV1.fromV3Data(resource, getSourceCode(resource.name, sources, resource.sourceHash))\n .data,\n ),\n );\n },\n};\n\nconst SoftwareInfoRenderer: Renderer<TemplateSoftwareDataV3> = {\n updateCacheKey(resource, hash, sources) {\n hash\n .update(PlTemplateSoftwareV1.type.name)\n .update(PlTemplateSoftwareV1.type.version)\n .update(resource.name)\n .update(resource.version)\n .update(getSourceCode(resource.name, sources, resource.sourceHash));\n },\n render(resource, tx, _creator, sources) {\n const sw = PlTemplateSoftwareV1.fromV3Data(\n resource,\n getSourceCode(resource.name, sources, resource.sourceHash),\n );\n const ref = tx.createStruct(PlTemplateSoftwareV1.type, sw.data);\n tx.setKValue(ref, PlTemplateSoftwareV1.metaNameKey, JSON.stringify(sw.name));\n tx.lock(ref);\n return ref;\n },\n};\n\nconst TemplateRenderer: Renderer<TemplateDataV3> = {\n updateCacheKey(resource, hash, sources) {\n hash\n .update(PlTemplateV1.type.name)\n .update(PlTemplateV1.type.version)\n .update(resource.hashOverride ?? \"no-override\")\n .update(resource.name)\n .update(resource.version)\n .update(getSourceCode(resource.name, sources, resource.sourceHash));\n\n const srt = <T>(entries: [string, T][]): [string, T][] => {\n entries.sort((a, b) => (a[0] === b[0] ? 0 : a[0] < b[0] ? -1 : 1));\n return entries;\n };\n\n for (const [libId, lib] of srt(Object.entries(resource.libs ?? {}))) {\n hash.update(\"lib:\" + libId);\n LibRenderer.updateCacheKey(lib, hash, sources);\n }\n for (const [swId, sw] of srt(Object.entries(resource.software ?? {}))) {\n hash.update(\"soft:\" + swId);\n SoftwareInfoRenderer.updateCacheKey(sw, hash, sources);\n }\n for (const [swId, sw] of srt(Object.entries(resource.assets ?? {}))) {\n hash.update(\"asset:\" + swId);\n SoftwareInfoRenderer.updateCacheKey(sw, hash, sources);\n }\n for (const [tplId, tpl] of srt(Object.entries(resource.templates ?? {}))) {\n hash.update(\"tpl:\" + tplId);\n this.updateCacheKey(tpl, hash, sources);\n }\n for (const [wasmId, wasm] of srt(Object.entries(resource.wasm ?? {}))) {\n hash.update(\"wasm:\" + wasmId);\n WasmRenderer.updateCacheKey(wasm, hash, sources);\n }\n },\n render(resource, tx, _creator, sources) {\n const tplRef = tx.createStruct(\n PlTemplateV1.type,\n JSON.stringify(\n PlTemplateV1.fromV3Data(\n resource,\n getSourceCode(resource.name, sources, resource.sourceHash),\n ).data,\n ),\n );\n // Render libraries\n for (const [libId, lib] of Object.entries(resource.libs ?? {})) {\n const fld = PlTemplateV1.libField(tplRef, libId);\n tx.createField(fld, \"Input\");\n tx.setField(fld, _creator(lib, LibRenderer, sources));\n }\n\n // Render software and assets\n for (const [swId, sw] of Object.entries(resource.software ?? {})) {\n const fld = PlTemplateV1.swField(tplRef, swId);\n tx.createField(fld, \"Input\");\n tx.setField(fld, _creator(sw, SoftwareInfoRenderer, sources));\n }\n for (const [swId, sw] of Object.entries(resource.assets ?? {})) {\n const fld = PlTemplateV1.swField(tplRef, swId);\n tx.createField(fld, \"Input\");\n tx.setField(fld, _creator(sw, SoftwareInfoRenderer, sources));\n }\n\n // Render dependency templates\n for (const [depTplId, depTpl] of Object.entries(resource.templates ?? {})) {\n const fld = PlTemplateV1.tplField(tplRef, depTplId);\n tx.createField(fld, \"Input\");\n tx.setField(fld, _creator(depTpl, TemplateRenderer, sources));\n }\n\n // Render wasm dependencies. The field name (alias) feeds straight into\n // the backend's TengoTemplateV1.wasm map and becomes the lookup key in\n // RuntimeV1.deps.Wasm consumed by plapi.loadWasm.\n for (const [wasmId, wasm] of Object.entries(resource.wasm ?? {})) {\n const fld = PlTemplateV1.wasmField(tplRef, wasmId);\n tx.createField(fld, \"Input\");\n tx.setField(fld, _creator(wasm, WasmRenderer, sources));\n }\n\n tx.lock(tplRef);\n\n if (!resource.hashOverride) return tplRef;\n\n // Override template hash with proxy resource, when hash override is configured for template\n const overrideRef = tx.createStruct(\n PlTemplateOverrideV1.type,\n JSON.stringify(PlTemplateOverrideV1.fromV3Data(resource)),\n );\n const fld = PlTemplateOverrideV1.tplField(overrideRef);\n tx.createField(fld, \"Service\");\n tx.setField(fld, tplRef);\n tx.lock(overrideRef);\n return overrideRef;\n },\n};\n\n/**\n * Gets a source code of the artifact by its source hash.\n * the source hash was calculated and stored by tengo compiler\n * and is different from the hash we're using for caching here.\n */\nfunction getSourceCode(name: string, sources: Record<string, string>, sourceHash: string): string {\n return notEmpty(\n sources[sourceHash],\n `trying to get \"${name}\" source: sources map doesn't contain source hash ${sourceHash}`,\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;AA8BA,SAAgB,qBAAqB,IAAmB,SAAqC;CAC3F,MAAM,gCAAgB,IAAI,IAA4B;CAEtD,MAAM,wBACJ,UACA,UACA,iBACmB;EACnB,MAAM,OAAA,GAAA,YAAA,WAAA,CAAuB,QAAQ;EACrC,SAAS,eAAe,UAAU,KAAK,YAAY;EAEnD,MAAM,OAAO,IAAI,OAAO,KAAK;EAE7B,IAAI,CAAC,cAAc,IAAI,IAAI,GAAG;GAC5B,MAAM,MAAM,SAAS,OAAO,UAAU,IAAI,sBAAsB,YAAY;GAC5E,cAAc,IAAI,MAAM,GAAG;EAC7B;EAEA,OAAO,cAAc,IAAI,IAAI;CAC/B;CAEA,OAAO,qBAAqB,QAAQ,UAAU,kBAAkB,QAAQ,YAAY;AACtF;AAo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U,WAAW,OAAO,QAAQ,SAAS,aAAa,CAAC,CAAC,GAAG;GACzE,MAAM,MAAMA,iCAAAA,aAAa,SAAS,QAAQ,QAAQ;GAClD,GAAG,YAAY,KAAK,OAAO;GAC3B,GAAG,SAAS,KAAK,SAAS,QAAQ,kBAAkB,OAAO,CAAC;EAC9D;EAKA,KAAK,MAAM,CAAC,QAAQ,SAAS,OAAO,QAAQ,SAAS,QAAQ,CAAC,CAAC,GAAG;GAChE,MAAM,MAAMA,iCAAAA,aAAa,UAAU,QAAQ,MAAM;GACjD,GAAG,YAAY,KAAK,OAAO;GAC3B,GAAG,SAAS,KAAK,SAAS,MAAM,cAAc,OAAO,CAAC;EACxD;EAEA,GAAG,KAAK,MAAM;EAEd,IAAI,CAAC,SAAS,cAAc,OAAO;EAGnC,MAAM,cAAc,GAAG,aACrBC,iCAAAA,qBAAqB,MACrB,KAAK,UAAUA,iCAAAA,qBAAqB,WAAW,QAAQ,CAAC,CAC1D;EACA,MAAM,MAAMA,iCAAAA,qBAAqB,SAAS,WAAW;EACrD,GAAG,YAAY,KAAK,SAAS;EAC7B,GAAG,SAAS,KAAK,MAAM;EACvB,GAAG,KAAK,WAAW;EACnB,OAAO;CACT;AACF;;;;;;AAOA,SAAS,cAAc,MAAc,SAAiC,YAA4B;CAChG,QAAA,GAAA,2BAAA,SAAA,CACE,QAAQ,aACR,kBAAkB,KAAK,oDAAoD,YAC7E;AACF"}
1
+ {"version":3,"file":"direct_template_loader_v3.cjs","names":["PlTemplateLibV1","PlWasmV1","PlTemplateSoftwareV1","PlTemplateV1","PlTemplateOverrideV1"],"sources":["../../../src/mutator/template/direct_template_loader_v3.ts"],"sourcesContent":["import type { AnyRef, AnyResourceRef, PlTransaction } from \"@milaboratories/pl-client\";\nimport type { Hash } from \"node:crypto\";\nimport { createHash } from \"node:crypto\";\nimport type {\n CompiledTemplateV3,\n TemplateDataV3,\n TemplateLibDataV3,\n TemplateSoftwareDataV3,\n TemplateWasmDataV3,\n} from \"@milaboratories/pl-model-backend\";\nimport {\n PlTemplateLibV1,\n PlTemplateSoftwareV1,\n PlTemplateV1,\n PlTemplateOverrideV1,\n PlWasmV1,\n} from \"@milaboratories/pl-model-backend\";\nimport { notEmpty } from \"@milaboratories/ts-helpers\";\n\n/**\n * Renders the tree of templates by caching all resource ids\n * by their cache keys.\n * It's different from v2 version because we provide\n * the hash map of the code of all sources everywhere.\n * It does a double-dispatch on the node type (template, library etc),\n * and creates resources.\n *\n * IMO, it'd be clearer to rewrite it with Visitor pattern, and separate\n * tree traversing and operations on it, but I don't have time to do it now.\n */\nexport function createTemplateV3Tree(tx: PlTransaction, tplData: CompiledTemplateV3): AnyRef {\n const resourceCache = new Map<string, AnyResourceRef>();\n\n const createResourceCached = <T>(\n resource: T,\n renderer: Renderer<T>,\n hashToSource: Record<string, string>,\n ): AnyResourceRef => {\n const key: Hash = createHash(\"sha256\");\n renderer.updateCacheKey(resource, key, hashToSource);\n\n const rKey = key.digest(\"hex\");\n\n if (!resourceCache.has(rKey)) {\n const rId = renderer.render(resource, tx, createResourceCached, hashToSource);\n resourceCache.set(rKey, rId);\n }\n\n return resourceCache.get(rKey)!;\n };\n\n return createResourceCached(tplData.template, TemplateRenderer, tplData.hashToSource);\n}\n\ntype Renderer<T> = {\n /** Updates the cache key by adding all info of the artifact. */\n updateCacheKey: CacheKey<T>;\n /** Create resources for all dependencies recursively and then for this artifact. */\n render: (\n resource: T,\n tx: PlTransaction,\n creator: Creator,\n sources: Record<string, string>,\n ) => AnyResourceRef;\n};\ntype CacheKey<T> = (resource: T, key: Hash, sources: Record<string, string>) => void;\ntype Creator = <T>(\n resource: T,\n renderer: Renderer<T>,\n sources: Record<string, string>,\n) => AnyResourceRef;\n\nconst LibRenderer: Renderer<TemplateLibDataV3> = {\n updateCacheKey(resource, hash, _sources) {\n // sourceHash is already the sha256 of this source (the hashToSource key), so hash it\n // directly instead of streaming the full source through sha256 again.\n hash\n .update(PlTemplateLibV1.type.name)\n .update(PlTemplateLibV1.type.version)\n .update(resource.name)\n .update(resource.version)\n .update(resource.sourceHash);\n },\n render(resource, tx, _creator, sources) {\n return tx.createValue(\n PlTemplateLibV1.type,\n JSON.stringify(\n PlTemplateLibV1.fromV3Data(\n resource,\n getSourceCode(resource.name, sources, resource.sourceHash),\n ).data,\n ),\n );\n },\n};\n\nconst WasmRenderer: Renderer<TemplateWasmDataV3> = {\n updateCacheKey(resource, hash, _sources) {\n hash\n .update(PlWasmV1.type.name)\n .update(PlWasmV1.type.version)\n .update(resource.name)\n .update(resource.version)\n .update(resource.sourceHash);\n },\n render(resource, tx, _creator, sources) {\n return tx.createValue(\n PlWasmV1.type,\n JSON.stringify(\n PlWasmV1.fromV3Data(resource, getSourceCode(resource.name, sources, resource.sourceHash))\n .data,\n ),\n );\n },\n};\n\nconst SoftwareInfoRenderer: Renderer<TemplateSoftwareDataV3> = {\n updateCacheKey(resource, hash, _sources) {\n hash\n .update(PlTemplateSoftwareV1.type.name)\n .update(PlTemplateSoftwareV1.type.version)\n .update(resource.name)\n .update(resource.version)\n .update(resource.sourceHash);\n },\n render(resource, tx, _creator, sources) {\n const sw = PlTemplateSoftwareV1.fromV3Data(\n resource,\n getSourceCode(resource.name, sources, resource.sourceHash),\n );\n const ref = tx.createStruct(PlTemplateSoftwareV1.type, sw.data);\n tx.setKValue(ref, PlTemplateSoftwareV1.metaNameKey, JSON.stringify(sw.name));\n tx.lock(ref);\n return ref;\n },\n};\n\nconst TemplateRenderer: Renderer<TemplateDataV3> = {\n updateCacheKey(resource, hash, sources) {\n hash\n .update(PlTemplateV1.type.name)\n .update(PlTemplateV1.type.version)\n .update(resource.hashOverride ?? \"no-override\")\n .update(resource.name)\n .update(resource.version)\n .update(resource.sourceHash);\n\n const srt = <T>(entries: [string, T][]): [string, T][] => {\n entries.sort((a, b) => (a[0] === b[0] ? 0 : a[0] < b[0] ? -1 : 1));\n return entries;\n };\n\n for (const [libId, lib] of srt(Object.entries(resource.libs ?? {}))) {\n hash.update(\"lib:\" + libId);\n LibRenderer.updateCacheKey(lib, hash, sources);\n }\n for (const [swId, sw] of srt(Object.entries(resource.software ?? {}))) {\n hash.update(\"soft:\" + swId);\n SoftwareInfoRenderer.updateCacheKey(sw, hash, sources);\n }\n for (const [swId, sw] of srt(Object.entries(resource.assets ?? {}))) {\n hash.update(\"asset:\" + swId);\n SoftwareInfoRenderer.updateCacheKey(sw, hash, sources);\n }\n for (const [tplId, tpl] of srt(Object.entries(resource.templates ?? {}))) {\n hash.update(\"tpl:\" + tplId);\n this.updateCacheKey(tpl, hash, sources);\n }\n for (const [wasmId, wasm] of srt(Object.entries(resource.wasm ?? {}))) {\n hash.update(\"wasm:\" + wasmId);\n WasmRenderer.updateCacheKey(wasm, hash, sources);\n }\n },\n render(resource, tx, _creator, sources) {\n const tplRef = tx.createStruct(\n PlTemplateV1.type,\n JSON.stringify(\n PlTemplateV1.fromV3Data(\n resource,\n getSourceCode(resource.name, sources, resource.sourceHash),\n ).data,\n ),\n );\n // Render libraries\n for (const [libId, lib] of Object.entries(resource.libs ?? {})) {\n const fld = PlTemplateV1.libField(tplRef, libId);\n tx.createField(fld, \"Input\");\n tx.setField(fld, _creator(lib, LibRenderer, sources));\n }\n\n // Render software and assets\n for (const [swId, sw] of Object.entries(resource.software ?? {})) {\n const fld = PlTemplateV1.swField(tplRef, swId);\n tx.createField(fld, \"Input\");\n tx.setField(fld, _creator(sw, SoftwareInfoRenderer, sources));\n }\n for (const [swId, sw] of Object.entries(resource.assets ?? {})) {\n const fld = PlTemplateV1.swField(tplRef, swId);\n tx.createField(fld, \"Input\");\n tx.setField(fld, _creator(sw, SoftwareInfoRenderer, sources));\n }\n\n // Render dependency templates\n for (const [depTplId, depTpl] of Object.entries(resource.templates ?? {})) {\n const fld = PlTemplateV1.tplField(tplRef, depTplId);\n tx.createField(fld, \"Input\");\n tx.setField(fld, _creator(depTpl, TemplateRenderer, sources));\n }\n\n // Render wasm dependencies. The field name (alias) feeds straight into\n // the backend's TengoTemplateV1.wasm map and becomes the lookup key in\n // RuntimeV1.deps.Wasm consumed by plapi.loadWasm.\n for (const [wasmId, wasm] of Object.entries(resource.wasm ?? {})) {\n const fld = PlTemplateV1.wasmField(tplRef, wasmId);\n tx.createField(fld, \"Input\");\n tx.setField(fld, _creator(wasm, WasmRenderer, sources));\n }\n\n tx.lock(tplRef);\n\n if (!resource.hashOverride) return tplRef;\n\n // Override template hash with proxy resource, when hash override is configured for template\n const overrideRef = tx.createStruct(\n PlTemplateOverrideV1.type,\n JSON.stringify(PlTemplateOverrideV1.fromV3Data(resource)),\n );\n const fld = PlTemplateOverrideV1.tplField(overrideRef);\n tx.createField(fld, \"Service\");\n tx.setField(fld, tplRef);\n tx.lock(overrideRef);\n return overrideRef;\n },\n};\n\n/**\n * Gets a source code of the artifact by its source hash.\n * the source hash was calculated and stored by tengo compiler\n * and is different from the hash we're using for caching here.\n */\nfunction getSourceCode(name: string, sources: Record<string, string>, sourceHash: string): string {\n return notEmpty(\n sources[sourceHash],\n `trying to get \"${name}\" source: sources map doesn't contain source hash ${sourceHash}`,\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;AA8BA,SAAgB,qBAAqB,IAAmB,SAAqC;CAC3F,MAAM,gCAAgB,IAAI,IAA4B;CAEtD,MAAM,wBACJ,UACA,UACA,iBACmB;EACnB,MAAM,OAAA,GAAA,YAAA,WAAA,CAAuB,QAAQ;EACrC,SAAS,eAAe,UAAU,KAAK,YAAY;EAEnD,MAAM,OAAO,IAAI,OAAO,KAAK;EAE7B,IAAI,CAAC,cAAc,IAAI,IAAI,GAAG;GAC5B,MAAM,MAAM,SAAS,OAAO,UAAU,IAAI,sBAAsB,YAAY;GAC5E,cAAc,IAAI,MAAM,GAAG;EAC7B;EAEA,OAAO,cAAc,IAAI,IAAI;CAC/B;CAEA,OAAO,qBAAqB,QAAQ,UAAU,kBAAkB,QAAQ,YAAY;AACtF;AAoBA,MAAM,cAA2C;CAC/C,eAAe,UAAU,MAAM,UAAU;EAGvC,KACG,OAA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kB,OAAO,CAAC;EAC9D;EAKA,KAAK,MAAM,CAAC,QAAQ,SAAS,OAAO,QAAQ,SAAS,QAAQ,CAAC,CAAC,GAAG;GAChE,MAAM,MAAMA,iCAAAA,aAAa,UAAU,QAAQ,MAAM;GACjD,GAAG,YAAY,KAAK,OAAO;GAC3B,GAAG,SAAS,KAAK,SAAS,MAAM,cAAc,OAAO,CAAC;EACxD;EAEA,GAAG,KAAK,MAAM;EAEd,IAAI,CAAC,SAAS,cAAc,OAAO;EAGnC,MAAM,cAAc,GAAG,aACrBC,iCAAAA,qBAAqB,MACrB,KAAK,UAAUA,iCAAAA,qBAAqB,WAAW,QAAQ,CAAC,CAC1D;EACA,MAAM,MAAMA,iCAAAA,qBAAqB,SAAS,WAAW;EACrD,GAAG,YAAY,KAAK,SAAS;EAC7B,GAAG,SAAS,KAAK,MAAM;EACvB,GAAG,KAAK,WAAW;EACnB,OAAO;CACT;AACF;;;;;;AAOA,SAAS,cAAc,MAAc,SAAiC,YAA4B;CAChG,QAAA,GAAA,2BAAA,SAAA,CACE,QAAQ,aACR,kBAAkB,KAAK,oDAAoD,YAC7E;AACF"}
@@ -28,24 +28,24 @@ function createTemplateV3Tree(tx, tplData) {
28
28
  return createResourceCached(tplData.template, TemplateRenderer, tplData.hashToSource);
29
29
  }
30
30
  const LibRenderer = {
31
- updateCacheKey(resource, hash, sources) {
32
- hash.update(PlTemplateLibV1.type.name).update(PlTemplateLibV1.type.version).update(resource.name).update(resource.version).update(getSourceCode(resource.name, sources, resource.sourceHash));
31
+ updateCacheKey(resource, hash, _sources) {
32
+ hash.update(PlTemplateLibV1.type.name).update(PlTemplateLibV1.type.version).update(resource.name).update(resource.version).update(resource.sourceHash);
33
33
  },
34
34
  render(resource, tx, _creator, sources) {
35
35
  return tx.createValue(PlTemplateLibV1.type, JSON.stringify(PlTemplateLibV1.fromV3Data(resource, getSourceCode(resource.name, sources, resource.sourceHash)).data));
36
36
  }
37
37
  };
38
38
  const WasmRenderer = {
39
- updateCacheKey(resource, hash, sources) {
40
- hash.update(PlWasmV1.type.name).update(PlWasmV1.type.version).update(resource.name).update(resource.version).update(getSourceCode(resource.name, sources, resource.sourceHash));
39
+ updateCacheKey(resource, hash, _sources) {
40
+ hash.update(PlWasmV1.type.name).update(PlWasmV1.type.version).update(resource.name).update(resource.version).update(resource.sourceHash);
41
41
  },
42
42
  render(resource, tx, _creator, sources) {
43
43
  return tx.createValue(PlWasmV1.type, JSON.stringify(PlWasmV1.fromV3Data(resource, getSourceCode(resource.name, sources, resource.sourceHash)).data));
44
44
  }
45
45
  };
46
46
  const SoftwareInfoRenderer = {
47
- updateCacheKey(resource, hash, sources) {
48
- hash.update(PlTemplateSoftwareV1.type.name).update(PlTemplateSoftwareV1.type.version).update(resource.name).update(resource.version).update(getSourceCode(resource.name, sources, resource.sourceHash));
47
+ updateCacheKey(resource, hash, _sources) {
48
+ hash.update(PlTemplateSoftwareV1.type.name).update(PlTemplateSoftwareV1.type.version).update(resource.name).update(resource.version).update(resource.sourceHash);
49
49
  },
50
50
  render(resource, tx, _creator, sources) {
51
51
  const sw = PlTemplateSoftwareV1.fromV3Data(resource, getSourceCode(resource.name, sources, resource.sourceHash));
@@ -57,7 +57,7 @@ const SoftwareInfoRenderer = {
57
57
  };
58
58
  const TemplateRenderer = {
59
59
  updateCacheKey(resource, hash, sources) {
60
- hash.update(PlTemplateV1.type.name).update(PlTemplateV1.type.version).update(resource.hashOverride ?? "no-override").update(resource.name).update(resource.version).update(getSourceCode(resource.name, sources, resource.sourceHash));
60
+ hash.update(PlTemplateV1.type.name).update(PlTemplateV1.type.version).update(resource.hashOverride ?? "no-override").update(resource.name).update(resource.version).update(resource.sourceHash);
61
61
  const srt = (entries) => {
62
62
  entries.sort((a, b) => a[0] === b[0] ? 0 : a[0] < b[0] ? -1 : 1);
63
63
  return entries;
@@ -1 +1 @@
1
- {"version":3,"file":"direct_template_loader_v3.js","names":[],"sources":["../../../src/mutator/template/direct_template_loader_v3.ts"],"sourcesContent":["import type { AnyRef, AnyResourceRef, PlTransaction } from \"@milaboratories/pl-client\";\nimport type { Hash } from \"node:crypto\";\nimport { createHash } from \"node:crypto\";\nimport type {\n CompiledTemplateV3,\n TemplateDataV3,\n TemplateLibDataV3,\n TemplateSoftwareDataV3,\n TemplateWasmDataV3,\n} from \"@milaboratories/pl-model-backend\";\nimport {\n PlTemplateLibV1,\n PlTemplateSoftwareV1,\n PlTemplateV1,\n PlTemplateOverrideV1,\n PlWasmV1,\n} from \"@milaboratories/pl-model-backend\";\nimport { notEmpty } from \"@milaboratories/ts-helpers\";\n\n/**\n * Renders the tree of templates by caching all resource ids\n * by their cache keys.\n * It's different from v2 version because we provide\n * the hash map of the code of all sources everywhere.\n * It does a double-dispatch on the node type (template, library etc),\n * and creates resources.\n *\n * IMO, it'd be clearer to rewrite it with Visitor pattern, and separate\n * tree traversing and operations on it, but I don't have time to do it now.\n */\nexport function createTemplateV3Tree(tx: PlTransaction, tplData: CompiledTemplateV3): AnyRef {\n const resourceCache = new Map<string, AnyResourceRef>();\n\n const createResourceCached = <T>(\n resource: T,\n renderer: Renderer<T>,\n hashToSource: Record<string, string>,\n ): AnyResourceRef => {\n const key: Hash = createHash(\"sha256\");\n renderer.updateCacheKey(resource, key, hashToSource);\n\n const rKey = key.digest(\"hex\");\n\n if (!resourceCache.has(rKey)) {\n const rId = renderer.render(resource, tx, createResourceCached, hashToSource);\n resourceCache.set(rKey, rId);\n }\n\n return resourceCache.get(rKey)!;\n };\n\n return createResourceCached(tplData.template, TemplateRenderer, tplData.hashToSource);\n}\n\ntype Renderer<T> = {\n /** Updates the cache key by adding all info of the artifact. */\n updateCacheKey: CacheKey<T>;\n /** Create resources for all dependencies recursively and then for this artifact. */\n render: (\n resource: T,\n tx: PlTransaction,\n creator: Creator,\n sources: Record<string, string>,\n ) => AnyResourceRef;\n};\ntype CacheKey<T> = (resource: T, key: Hash, sources: Record<string, string>) => void;\ntype Creator = <T>(\n resource: T,\n renderer: Renderer<T>,\n sources: Record<string, string>,\n) => AnyResourceRef;\n\nconst LibRenderer: Renderer<TemplateLibDataV3> = {\n updateCacheKey(resource, hash, sources) {\n hash\n .update(PlTemplateLibV1.type.name)\n .update(PlTemplateLibV1.type.version)\n .update(resource.name)\n .update(resource.version)\n .update(getSourceCode(resource.name, sources, resource.sourceHash));\n },\n render(resource, tx, _creator, sources) {\n return tx.createValue(\n PlTemplateLibV1.type,\n JSON.stringify(\n PlTemplateLibV1.fromV3Data(\n resource,\n getSourceCode(resource.name, sources, resource.sourceHash),\n ).data,\n ),\n );\n },\n};\n\nconst WasmRenderer: Renderer<TemplateWasmDataV3> = {\n updateCacheKey(resource, hash, sources) {\n hash\n .update(PlWasmV1.type.name)\n .update(PlWasmV1.type.version)\n .update(resource.name)\n .update(resource.version)\n .update(getSourceCode(resource.name, sources, resource.sourceHash));\n },\n render(resource, tx, _creator, sources) {\n return tx.createValue(\n PlWasmV1.type,\n JSON.stringify(\n PlWasmV1.fromV3Data(resource, getSourceCode(resource.name, sources, resource.sourceHash))\n .data,\n ),\n );\n },\n};\n\nconst SoftwareInfoRenderer: Renderer<TemplateSoftwareDataV3> = {\n updateCacheKey(resource, hash, sources) {\n hash\n .update(PlTemplateSoftwareV1.type.name)\n .update(PlTemplateSoftwareV1.type.version)\n .update(resource.name)\n .update(resource.version)\n .update(getSourceCode(resource.name, sources, resource.sourceHash));\n },\n render(resource, tx, _creator, sources) {\n const sw = PlTemplateSoftwareV1.fromV3Data(\n resource,\n getSourceCode(resource.name, sources, resource.sourceHash),\n );\n const ref = tx.createStruct(PlTemplateSoftwareV1.type, sw.data);\n tx.setKValue(ref, PlTemplateSoftwareV1.metaNameKey, JSON.stringify(sw.name));\n tx.lock(ref);\n return ref;\n },\n};\n\nconst TemplateRenderer: Renderer<TemplateDataV3> = {\n updateCacheKey(resource, hash, sources) {\n hash\n .update(PlTemplateV1.type.name)\n .update(PlTemplateV1.type.version)\n .update(resource.hashOverride ?? \"no-override\")\n .update(resource.name)\n .update(resource.version)\n .update(getSourceCode(resource.name, sources, resource.sourceHash));\n\n const srt = <T>(entries: [string, T][]): [string, T][] => {\n entries.sort((a, b) => (a[0] === b[0] ? 0 : a[0] < b[0] ? -1 : 1));\n return entries;\n };\n\n for (const [libId, lib] of srt(Object.entries(resource.libs ?? {}))) {\n hash.update(\"lib:\" + libId);\n LibRenderer.updateCacheKey(lib, hash, sources);\n }\n for (const [swId, sw] of srt(Object.entries(resource.software ?? {}))) {\n hash.update(\"soft:\" + swId);\n SoftwareInfoRenderer.updateCacheKey(sw, hash, sources);\n }\n for (const [swId, sw] of srt(Object.entries(resource.assets ?? {}))) {\n hash.update(\"asset:\" + swId);\n SoftwareInfoRenderer.updateCacheKey(sw, hash, sources);\n }\n for (const [tplId, tpl] of srt(Object.entries(resource.templates ?? {}))) {\n hash.update(\"tpl:\" + tplId);\n this.updateCacheKey(tpl, hash, sources);\n }\n for (const [wasmId, wasm] of srt(Object.entries(resource.wasm ?? {}))) {\n hash.update(\"wasm:\" + wasmId);\n WasmRenderer.updateCacheKey(wasm, hash, sources);\n }\n },\n render(resource, tx, _creator, sources) {\n const tplRef = tx.createStruct(\n PlTemplateV1.type,\n JSON.stringify(\n PlTemplateV1.fromV3Data(\n resource,\n getSourceCode(resource.name, sources, resource.sourceHash),\n ).data,\n ),\n );\n // Render libraries\n for (const [libId, lib] of Object.entries(resource.libs ?? {})) {\n const fld = PlTemplateV1.libField(tplRef, libId);\n tx.createField(fld, \"Input\");\n tx.setField(fld, _creator(lib, LibRenderer, sources));\n }\n\n // Render software and assets\n for (const [swId, sw] of Object.entries(resource.software ?? {})) {\n const fld = PlTemplateV1.swField(tplRef, swId);\n tx.createField(fld, \"Input\");\n tx.setField(fld, _creator(sw, SoftwareInfoRenderer, sources));\n }\n for (const [swId, sw] of Object.entries(resource.assets ?? {})) {\n const fld = PlTemplateV1.swField(tplRef, swId);\n tx.createField(fld, \"Input\");\n tx.setField(fld, _creator(sw, SoftwareInfoRenderer, sources));\n }\n\n // Render dependency templates\n for (const [depTplId, depTpl] of Object.entries(resource.templates ?? {})) {\n const fld = PlTemplateV1.tplField(tplRef, depTplId);\n tx.createField(fld, \"Input\");\n tx.setField(fld, _creator(depTpl, TemplateRenderer, sources));\n }\n\n // Render wasm dependencies. The field name (alias) feeds straight into\n // the backend's TengoTemplateV1.wasm map and becomes the lookup key in\n // RuntimeV1.deps.Wasm consumed by plapi.loadWasm.\n for (const [wasmId, wasm] of Object.entries(resource.wasm ?? {})) {\n const fld = PlTemplateV1.wasmField(tplRef, wasmId);\n tx.createField(fld, \"Input\");\n tx.setField(fld, _creator(wasm, WasmRenderer, sources));\n }\n\n tx.lock(tplRef);\n\n if (!resource.hashOverride) return tplRef;\n\n // Override template hash with proxy resource, when hash override is configured for template\n const overrideRef = tx.createStruct(\n PlTemplateOverrideV1.type,\n JSON.stringify(PlTemplateOverrideV1.fromV3Data(resource)),\n );\n const fld = PlTemplateOverrideV1.tplField(overrideRef);\n tx.createField(fld, \"Service\");\n tx.setField(fld, tplRef);\n tx.lock(overrideRef);\n return overrideRef;\n },\n};\n\n/**\n * Gets a source code of the artifact by its source hash.\n * the source hash was calculated and stored by tengo compiler\n * and is different from the hash we're using for caching here.\n */\nfunction getSourceCode(name: string, sources: Record<string, string>, sourceHash: string): string {\n return notEmpty(\n sources[sourceHash],\n `trying to get \"${name}\" source: sources map doesn't contain source hash ${sourceHash}`,\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;AA8BA,SAAgB,qBAAqB,IAAmB,SAAqC;CAC3F,MAAM,gCAAgB,IAAI,IAA4B;CAEtD,MAAM,wBACJ,UACA,UACA,iBACmB;EACnB,MAAM,MAAY,WAAW,QAAQ;EACrC,SAAS,eAAe,UAAU,KAAK,YAAY;EAEnD,MAAM,OAAO,IAAI,OAAO,KAAK;EAE7B,IAAI,CAAC,cAAc,IAAI,IAAI,GAAG;GAC5B,MAAM,MAAM,SAAS,OAAO,UAAU,IAAI,sBAAsB,YAAY;GAC5E,cAAc,IAAI,MA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a,SAAS,QAAQ,QAAQ;GAClD,GAAG,YAAY,KAAK,OAAO;GAC3B,GAAG,SAAS,KAAK,SAAS,QAAQ,kBAAkB,OAAO,CAAC;EAC9D;EAKA,KAAK,MAAM,CAAC,QAAQ,SAAS,OAAO,QAAQ,SAAS,QAAQ,CAAC,CAAC,GAAG;GAChE,MAAM,MAAM,aAAa,UAAU,QAAQ,MAAM;GACjD,GAAG,YAAY,KAAK,OAAO;GAC3B,GAAG,SAAS,KAAK,SAAS,MAAM,cAAc,OAAO,CAAC;EACxD;EAEA,GAAG,KAAK,MAAM;EAEd,IAAI,CAAC,SAAS,cAAc,OAAO;EAGnC,MAAM,cAAc,GAAG,aACrB,qBAAqB,MACrB,KAAK,UAAU,qBAAqB,WAAW,QAAQ,CAAC,CAC1D;EACA,MAAM,MAAM,qBAAqB,SAAS,WAAW;EACrD,GAAG,YAAY,KAAK,SAAS;EAC7B,GAAG,SAAS,KAAK,MAAM;EACvB,GAAG,KAAK,WAAW;EACnB,OAAO;CACT;AACF;;;;;;AAOA,SAAS,cAAc,MAAc,SAAiC,YAA4B;CAChG,OAAO,SACL,QAAQ,aACR,kBAAkB,KAAK,oDAAoD,YAC7E;AACF"}
1
+ {"version":3,"file":"direct_template_loader_v3.js","names":[],"sources":["../../../src/mutator/template/direct_template_loader_v3.ts"],"sourcesContent":["import type { AnyRef, AnyResourceRef, PlTransaction } from \"@milaboratories/pl-client\";\nimport type { Hash } from \"node:crypto\";\nimport { createHash } from \"node:crypto\";\nimport type {\n CompiledTemplateV3,\n TemplateDataV3,\n TemplateLibDataV3,\n TemplateSoftwareDataV3,\n TemplateWasmDataV3,\n} from \"@milaboratories/pl-model-backend\";\nimport {\n PlTemplateLibV1,\n PlTemplateSoftwareV1,\n PlTemplateV1,\n PlTemplateOverrideV1,\n PlWasmV1,\n} from \"@milaboratories/pl-model-backend\";\nimport { notEmpty } from \"@milaboratories/ts-helpers\";\n\n/**\n * Renders the tree of templates by caching all resource ids\n * by their cache keys.\n * It's different from v2 version because we provide\n * the hash map of the code of all sources everywhere.\n * It does a double-dispatch on the node type (template, library etc),\n * and creates resources.\n *\n * IMO, it'd be clearer to rewrite it with Visitor pattern, and separate\n * tree traversing and operations on it, but I don't have time to do it now.\n */\nexport function createTemplateV3Tree(tx: PlTransaction, tplData: CompiledTemplateV3): AnyRef {\n const resourceCache = new Map<string, AnyResourceRef>();\n\n const createResourceCached = <T>(\n resource: T,\n renderer: Renderer<T>,\n hashToSource: Record<string, string>,\n ): AnyResourceRef => {\n const key: Hash = createHash(\"sha256\");\n renderer.updateCacheKey(resource, key, hashToSource);\n\n const rKey = key.digest(\"hex\");\n\n if (!resourceCache.has(rKey)) {\n const rId = renderer.render(resource, tx, createResourceCached, hashToSource);\n resourceCache.set(rKey, rId);\n }\n\n return resourceCache.get(rKey)!;\n };\n\n return createResourceCached(tplData.template, TemplateRenderer, tplData.hashToSource);\n}\n\ntype Renderer<T> = {\n /** Updates the cache key by adding all info of the artifact. */\n updateCacheKey: CacheKey<T>;\n /** Create resources for all dependencies recursively and then for this artifact. */\n render: (\n resource: T,\n tx: PlTransaction,\n creator: Creator,\n sources: Record<string, string>,\n ) => AnyResourceRef;\n};\ntype CacheKey<T> = (resource: T, key: Hash, sources: Record<string, string>) => void;\ntype Creator = <T>(\n resource: T,\n renderer: Renderer<T>,\n sources: Record<string, string>,\n) => AnyResourceRef;\n\nconst LibRenderer: Renderer<TemplateLibDataV3> = {\n updateCacheKey(resource, hash, _sources) {\n // sourceHash is already the sha256 of this source (the hashToSource key), so hash it\n // directly instead of streaming the full source through sha256 again.\n hash\n .update(PlTemplateLibV1.type.name)\n .update(PlTemplateLibV1.type.version)\n .update(resource.name)\n .update(resource.version)\n .update(resource.sourceHash);\n },\n render(resource, tx, _creator, sources) {\n return tx.createValue(\n PlTemplateLibV1.type,\n JSON.stringify(\n PlTemplateLibV1.fromV3Data(\n resource,\n getSourceCode(resource.name, sources, resource.sourceHash),\n ).data,\n ),\n );\n },\n};\n\nconst WasmRenderer: Renderer<TemplateWasmDataV3> = {\n updateCacheKey(resource, hash, _sources) {\n hash\n .update(PlWasmV1.type.name)\n .update(PlWasmV1.type.version)\n .update(resource.name)\n .update(resource.version)\n .update(resource.sourceHash);\n },\n render(resource, tx, _creator, sources) {\n return tx.createValue(\n PlWasmV1.type,\n JSON.stringify(\n PlWasmV1.fromV3Data(resource, getSourceCode(resource.name, sources, resource.sourceHash))\n .data,\n ),\n );\n },\n};\n\nconst SoftwareInfoRenderer: Renderer<TemplateSoftwareDataV3> = {\n updateCacheKey(resource, hash, _sources) {\n hash\n .update(PlTemplateSoftwareV1.type.name)\n .update(PlTemplateSoftwareV1.type.version)\n .update(resource.name)\n .update(resource.version)\n .update(resource.sourceHash);\n },\n render(resource, tx, _creator, sources) {\n const sw = PlTemplateSoftwareV1.fromV3Data(\n resource,\n getSourceCode(resource.name, sources, resource.sourceHash),\n );\n const ref = tx.createStruct(PlTemplateSoftwareV1.type, sw.data);\n tx.setKValue(ref, PlTemplateSoftwareV1.metaNameKey, JSON.stringify(sw.name));\n tx.lock(ref);\n return ref;\n },\n};\n\nconst TemplateRenderer: Renderer<TemplateDataV3> = {\n updateCacheKey(resource, hash, sources) {\n hash\n .update(PlTemplateV1.type.name)\n .update(PlTemplateV1.type.version)\n .update(resource.hashOverride ?? \"no-override\")\n .update(resource.name)\n .update(resource.version)\n .update(resource.sourceHash);\n\n const srt = <T>(entries: [string, T][]): [string, T][] => {\n entries.sort((a, b) => (a[0] === b[0] ? 0 : a[0] < b[0] ? -1 : 1));\n return entries;\n };\n\n for (const [libId, lib] of srt(Object.entries(resource.libs ?? {}))) {\n hash.update(\"lib:\" + libId);\n LibRenderer.updateCacheKey(lib, hash, sources);\n }\n for (const [swId, sw] of srt(Object.entries(resource.software ?? {}))) {\n hash.update(\"soft:\" + swId);\n SoftwareInfoRenderer.updateCacheKey(sw, hash, sources);\n }\n for (const [swId, sw] of srt(Object.entries(resource.assets ?? {}))) {\n hash.update(\"asset:\" + swId);\n SoftwareInfoRenderer.updateCacheKey(sw, hash, sources);\n }\n for (const [tplId, tpl] of srt(Object.entries(resource.templates ?? {}))) {\n hash.update(\"tpl:\" + tplId);\n this.updateCacheKey(tpl, hash, sources);\n }\n for (const [wasmId, wasm] of srt(Object.entries(resource.wasm ?? {}))) {\n hash.update(\"wasm:\" + wasmId);\n WasmRenderer.updateCacheKey(wasm, hash, sources);\n }\n },\n render(resource, tx, _creator, sources) {\n const tplRef = tx.createStruct(\n PlTemplateV1.type,\n JSON.stringify(\n PlTemplateV1.fromV3Data(\n resource,\n getSourceCode(resource.name, sources, resource.sourceHash),\n ).data,\n ),\n );\n // Render libraries\n for (const [libId, lib] of Object.entries(resource.libs ?? {})) {\n const fld = PlTemplateV1.libField(tplRef, libId);\n tx.createField(fld, \"Input\");\n tx.setField(fld, _creator(lib, LibRenderer, sources));\n }\n\n // Render software and assets\n for (const [swId, sw] of Object.entries(resource.software ?? {})) {\n const fld = PlTemplateV1.swField(tplRef, swId);\n tx.createField(fld, \"Input\");\n tx.setField(fld, _creator(sw, SoftwareInfoRenderer, sources));\n }\n for (const [swId, sw] of Object.entries(resource.assets ?? {})) {\n const fld = PlTemplateV1.swField(tplRef, swId);\n tx.createField(fld, \"Input\");\n tx.setField(fld, _creator(sw, SoftwareInfoRenderer, sources));\n }\n\n // Render dependency templates\n for (const [depTplId, depTpl] of Object.entries(resource.templates ?? {})) {\n const fld = PlTemplateV1.tplField(tplRef, depTplId);\n tx.createField(fld, \"Input\");\n tx.setField(fld, _creator(depTpl, TemplateRenderer, sources));\n }\n\n // Render wasm dependencies. The field name (alias) feeds straight into\n // the backend's TengoTemplateV1.wasm map and becomes the lookup key in\n // RuntimeV1.deps.Wasm consumed by plapi.loadWasm.\n for (const [wasmId, wasm] of Object.entries(resource.wasm ?? {})) {\n const fld = PlTemplateV1.wasmField(tplRef, wasmId);\n tx.createField(fld, \"Input\");\n tx.setField(fld, _creator(wasm, WasmRenderer, sources));\n }\n\n tx.lock(tplRef);\n\n if (!resource.hashOverride) return tplRef;\n\n // Override template hash with proxy resource, when hash override is configured for template\n const overrideRef = tx.createStruct(\n PlTemplateOverrideV1.type,\n JSON.stringify(PlTemplateOverrideV1.fromV3Data(resource)),\n );\n const fld = PlTemplateOverrideV1.tplField(overrideRef);\n tx.createField(fld, \"Service\");\n tx.setField(fld, tplRef);\n tx.lock(overrideRef);\n return overrideRef;\n },\n};\n\n/**\n * Gets a source code of the artifact by its source hash.\n * the source hash was calculated and stored by tengo compiler\n * and is different from the hash we're using for caching here.\n */\nfunction getSourceCode(name: string, sources: Record<string, string>, sourceHash: string): string {\n return notEmpty(\n sources[sourceHash],\n `trying to get \"${name}\" source: sources map doesn't contain source hash ${sourceHash}`,\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;AA8BA,SAAgB,qBAAqB,IAAmB,SAAqC;CAC3F,MAAM,gCAAgB,IAAI,IAA4B;CAEtD,MAAM,wBACJ,UACA,UACA,iBACmB;EACnB,MAAM,MAAY,WAAW,QAAQ;EACrC,SAAS,eAAe,UAAU,KAAK,YAAY;EAEnD,MAAM,OAAO,IAAI,OAAO,KAAK;EAE7B,IAAI,CAAC,cAAc,IAAI,IAAI,GAAG;GAC5B,MAAM,MAAM,SAAS,OAAO,UAAU,IAAI,sBAAsB,YAAY;GAC5E,cAAc,IAAI,MAAM,GAAG;EAC7B;EAEA,OAAO,cAAc,IAAI,IAAI;CAC/B;CAEA,OAAO,qBAAqB,QAAQ,UAAU,kBAAkB,QAAQ,YAAY;AACtF;AAoBA,MAAM,cAA2C;CAC/C,eAAe,UAAU,MAAM,UAAU;EAGvC,KACG,OAAO,gBAAgB,KAAK,IAAI,CAAC,CACjC,OAAO,gBAAgB,KAAK,OAAO,CAAC,CACpC,OAAO,SAAS,IAAI,CAAC,CACrB,OAAO,SAAS,OAAO,CAAC,CACxB,OAAO,SAAS,UAAU;CAC/B;CACA,OAAO,UAAU,IAAI,UAAU,SAAS;EACtC,OAAO,GAAG,YACR,gBAAgB,MACh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ACrD,GAAG,YAAY,KAAK,SAAS;EAC7B,GAAG,SAAS,KAAK,MAAM;EACvB,GAAG,KAAK,WAAW;EACnB,OAAO;CACT;AACF;;;;;;AAOA,SAAS,cAAc,MAAc,SAAiC,YAA4B;CAChG,OAAO,SACL,QAAQ,aACR,kBAAkB,KAAK,oDAAoD,YAC7E;AACF"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@milaboratories/pl-middle-layer",
3
- "version": "1.66.8",
3
+ "version": "1.66.10",
4
4
  "description": "Pl Middle Layer",
5
5
  "keywords": [],
6
6
  "license": "UNLICENSED",
@@ -31,24 +31,24 @@
31
31
  "utility-types": "^3.11.0",
32
32
  "yaml": "^2.8.0",
33
33
  "zod": "~3.25.76",
34
- "@milaboratories/columns-collection-driver": "0.2.2",
35
- "@milaboratories/computable": "2.9.8",
36
- "@milaboratories/pf-driver": "1.8.4",
37
34
  "@milaboratories/helpers": "1.14.5",
38
- "@milaboratories/pf-spec-driver": "1.4.23",
39
- "@milaboratories/pl-deployments": "3.0.13",
40
- "@milaboratories/pl-client": "3.14.3",
41
- "@milaboratories/pl-drivers": "1.16.11",
42
- "@milaboratories/pl-errors": "1.4.32",
35
+ "@milaboratories/columns-collection-driver": "0.2.3",
36
+ "@milaboratories/pf-driver": "1.8.5",
37
+ "@milaboratories/computable": "2.9.8",
38
+ "@milaboratories/pf-spec-driver": "1.4.24",
39
+ "@milaboratories/pl-deployments": "3.0.14",
43
40
  "@milaboratories/pl-http": "1.2.4",
44
- "@milaboratories/pl-model-backend": "1.4.17",
45
- "@milaboratories/pl-model-common": "1.47.2",
46
- "@milaboratories/pl-model-middle-layer": "1.30.14",
47
- "@milaboratories/resolve-helper": "1.1.3",
48
- "@milaboratories/pl-tree": "1.13.2",
49
- "@platforma-sdk/block-tools": "2.12.8",
50
- "@platforma-sdk/model": "1.80.8",
41
+ "@milaboratories/pl-drivers": "1.16.12",
42
+ "@milaboratories/pl-client": "3.14.4",
43
+ "@milaboratories/pl-model-backend": "1.4.18",
44
+ "@milaboratories/pl-errors": "1.4.33",
45
+ "@milaboratories/pl-model-common": "1.47.3",
46
+ "@milaboratories/pl-model-middle-layer": "1.30.15",
47
+ "@milaboratories/pl-tree": "1.13.3",
51
48
  "@milaboratories/ts-helpers": "1.8.6",
49
+ "@milaboratories/resolve-helper": "1.1.3",
50
+ "@platforma-sdk/block-tools": "2.12.9",
51
+ "@platforma-sdk/model": "1.80.10",
52
52
  "@platforma-sdk/workflow-tengo": "6.8.2"
53
53
  },
54
54
  "devDependencies": {
@@ -71,13 +71,15 @@ type Creator = <T>(
71
71
  ) => AnyResourceRef;
72
72
 
73
73
  const LibRenderer: Renderer<TemplateLibDataV3> = {
74
- updateCacheKey(resource, hash, sources) {
74
+ updateCacheKey(resource, hash, _sources) {
75
+ // sourceHash is already the sha256 of this source (the hashToSource key), so hash it
76
+ // directly instead of streaming the full source through sha256 again.
75
77
  hash
76
78
  .update(PlTemplateLibV1.type.name)
77
79
  .update(PlTemplateLibV1.type.version)
78
80
  .update(resource.name)
79
81
  .update(resource.version)
80
- .update(getSourceCode(resource.name, sources, resource.sourceHash));
82
+ .update(resource.sourceHash);
81
83
  },
82
84
  render(resource, tx, _creator, sources) {
83
85
  return tx.createValue(
@@ -93,13 +95,13 @@ const LibRenderer: Renderer<TemplateLibDataV3> = {
93
95
  };
94
96
 
95
97
  const WasmRenderer: Renderer<TemplateWasmDataV3> = {
96
- updateCacheKey(resource, hash, sources) {
98
+ updateCacheKey(resource, hash, _sources) {
97
99
  hash
98
100
  .update(PlWasmV1.type.name)
99
101
  .update(PlWasmV1.type.version)
100
102
  .update(resource.name)
101
103
  .update(resource.version)
102
- .update(getSourceCode(resource.name, sources, resource.sourceHash));
104
+ .update(resource.sourceHash);
103
105
  },
104
106
  render(resource, tx, _creator, sources) {
105
107
  return tx.createValue(
@@ -113,13 +115,13 @@ const WasmRenderer: Renderer<TemplateWasmDataV3> = {
113
115
  };
114
116
 
115
117
  const SoftwareInfoRenderer: Renderer<TemplateSoftwareDataV3> = {
116
- updateCacheKey(resource, hash, sources) {
118
+ updateCacheKey(resource, hash, _sources) {
117
119
  hash
118
120
  .update(PlTemplateSoftwareV1.type.name)
119
121
  .update(PlTemplateSoftwareV1.type.version)
120
122
  .update(resource.name)
121
123
  .update(resource.version)
122
- .update(getSourceCode(resource.name, sources, resource.sourceHash));
124
+ .update(resource.sourceHash);
123
125
  },
124
126
  render(resource, tx, _creator, sources) {
125
127
  const sw = PlTemplateSoftwareV1.fromV3Data(
@@ -141,7 +143,7 @@ const TemplateRenderer: Renderer<TemplateDataV3> = {
141
143
  .update(resource.hashOverride ?? "no-override")
142
144
  .update(resource.name)
143
145
  .update(resource.version)
144
- .update(getSourceCode(resource.name, sources, resource.sourceHash));
146
+ .update(resource.sourceHash);
145
147
 
146
148
  const srt = <T>(entries: [string, T][]): [string, T][] => {
147
149
  entries.sort((a, b) => (a[0] === b[0] ? 0 : a[0] < b[0] ? -1 : 1));