@milaboratories/pl-middle-layer 1.43.17 → 1.43.18

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (35) hide show
  1. package/dist/js_render/index.cjs +1 -1
  2. package/dist/js_render/index.cjs.map +1 -1
  3. package/dist/js_render/index.d.ts.map +1 -1
  4. package/dist/js_render/index.js +1 -1
  5. package/dist/js_render/index.js.map +1 -1
  6. package/dist/middle_layer/active_cfg.cjs +6 -2
  7. package/dist/middle_layer/active_cfg.cjs.map +1 -1
  8. package/dist/middle_layer/active_cfg.d.ts.map +1 -1
  9. package/dist/middle_layer/active_cfg.js +7 -3
  10. package/dist/middle_layer/active_cfg.js.map +1 -1
  11. package/dist/middle_layer/project.cjs +3 -0
  12. package/dist/middle_layer/project.cjs.map +1 -1
  13. package/dist/middle_layer/project.d.ts +2 -0
  14. package/dist/middle_layer/project.d.ts.map +1 -1
  15. package/dist/middle_layer/project.js +3 -0
  16. package/dist/middle_layer/project.js.map +1 -1
  17. package/dist/middle_layer/project_overview.cjs +9 -1
  18. package/dist/middle_layer/project_overview.cjs.map +1 -1
  19. package/dist/middle_layer/project_overview.d.ts.map +1 -1
  20. package/dist/middle_layer/project_overview.js +10 -2
  21. package/dist/middle_layer/project_overview.js.map +1 -1
  22. package/dist/model/project_helper.cjs.map +1 -1
  23. package/dist/model/project_helper.js.map +1 -1
  24. package/dist/mutator/block-pack/block_pack.cjs +20 -10
  25. package/dist/mutator/block-pack/block_pack.cjs.map +1 -1
  26. package/dist/mutator/block-pack/block_pack.d.ts.map +1 -1
  27. package/dist/mutator/block-pack/block_pack.js +20 -10
  28. package/dist/mutator/block-pack/block_pack.js.map +1 -1
  29. package/package.json +12 -12
  30. package/src/js_render/index.ts +2 -1
  31. package/src/middle_layer/active_cfg.ts +7 -3
  32. package/src/middle_layer/project.ts +4 -0
  33. package/src/middle_layer/project_overview.ts +11 -2
  34. package/src/model/project_helper.ts +1 -1
  35. package/src/mutator/block-pack/block_pack.ts +26 -13
@@ -1 +1 @@
1
- {"version":3,"file":"block_pack.cjs","sources":["../../../src/mutator/block-pack/block_pack.ts"],"sourcesContent":["import type { AnyResourceRef, PlTransaction, ResourceType } from '@milaboratories/pl-client';\nimport { field } from '@milaboratories/pl-client';\nimport { loadTemplate } from '../template/template_loading';\nimport type { BlockPackExplicit, BlockPackSpecAny, BlockPackSpecPrepared } from '../../model';\nimport type { Signer } from '@milaboratories/ts-helpers';\nimport { assertNever } from '@milaboratories/ts-helpers';\nimport fs from 'node:fs';\nimport type { Dispatcher } from 'undici';\nimport { request } from 'undici';\nimport { createFrontend } from './frontend';\nimport type { BlockConfigContainer } from '@platforma-sdk/model';\nimport { loadPackDescription, RegistryV1 } from '@platforma-sdk/block-tools';\nimport type { BlockPackInfo } from '../../model/block_pack';\nimport { resolveDevPacket } from '../../dev_env';\nimport { getDevV2PacketMtime } from '../../block_registry';\nimport type { V2RegistryProvider } from '../../block_registry/registry-v2-provider';\nimport { LRUCache } from 'lru-cache';\nimport type { BlockPackSpec } from '@milaboratories/pl-model-middle-layer';\nimport { WorkerManager } from '../../worker/WorkerManager';\n\nexport const BlockPackCustomType: ResourceType = { name: 'BlockPackCustom', version: '1' };\nexport const BlockPackTemplateField = 'template';\nexport const BlockPackFrontendField = 'frontend';\n\n/** Ensure trailing slash */\nfunction tSlash(str: string): string {\n if (str.endsWith('/')) return str;\n else return `${str}/`;\n}\n\nfunction bufferToString(buffer: ArrayBuffer): string {\n return Buffer.from(buffer).toString('utf8');\n}\n\nfunction bufferToJson(buffer: ArrayBuffer): unknown {\n return JSON.parse(bufferToString(buffer));\n}\n\nexport class BlockPackPreparer {\n constructor(\n private readonly v2RegistryProvider: V2RegistryProvider,\n private readonly signer: Signer,\n private readonly http?: Dispatcher,\n ) {}\n\n private readonly remoteContentCache = new LRUCache<string, ArrayBuffer>({\n max: 500,\n maxSize: 128 * 1024 * 1024,\n fetchMethod: async (key) => {\n const httpOptions = this.http !== undefined ? { dispatcher: this.http } : {};\n return await (await request(key, httpOptions)).body.arrayBuffer();\n },\n sizeCalculation: (value) => value.byteLength,\n });\n\n public async getBlockConfigContainer(spec: BlockPackSpecAny): Promise<BlockConfigContainer> {\n switch (spec.type) {\n case 'explicit':\n return spec.config;\n\n case 'prepared':\n return spec.config;\n\n case 'dev-v1': {\n const devPaths = await resolveDevPacket(spec.folder, false);\n const configContent = await fs.promises.readFile(devPaths.config, { encoding: 'utf-8' });\n return JSON.parse(configContent) as BlockConfigContainer;\n }\n\n case 'dev-v2': {\n const description = await loadPackDescription(spec.folder);\n const configContent = await fs.promises.readFile(description.components.model.file, {\n encoding: 'utf-8',\n });\n return JSON.parse(configContent) as BlockConfigContainer;\n }\n\n case 'from-registry-v1': {\n const urlPrefix = `${tSlash(spec.registryUrl)}${RegistryV1.packageContentPrefix({ organization: spec.id.organization, package: spec.id.name, version: spec.id.version })}`;\n\n const configResponse = await this.remoteContentCache.forceFetch(`${urlPrefix}/config.json`);\n return bufferToJson(configResponse) as BlockConfigContainer;\n }\n\n case 'from-registry-v2': {\n const registry = this.v2RegistryProvider.getRegistry(spec.registryUrl);\n const components = await registry.getComponents(spec.id);\n const configResponse = await this.remoteContentCache.forceFetch(components.model.url);\n return bufferToJson(configResponse) as BlockConfigContainer;\n }\n\n default:\n return assertNever(spec);\n }\n }\n\n public async prepare(spec: BlockPackSpecAny): Promise<BlockPackSpecPrepared> {\n if (spec.type === 'prepared') {\n return spec;\n }\n\n const explicit = await this.prepareWithoutUnpacking(spec);\n\n await using workerManager = new WorkerManager();\n\n return {\n ...explicit,\n type: 'prepared',\n template: {\n type: 'prepared',\n data: await workerManager.process('parseTemplate', explicit.template.content),\n },\n };\n }\n\n private async prepareWithoutUnpacking(spec: BlockPackExplicit | BlockPackSpec): Promise<BlockPackExplicit> {\n switch (spec.type) {\n case 'explicit':\n return spec;\n\n case 'dev-v1': {\n const devPaths = await resolveDevPacket(spec.folder, false);\n\n // template\n const templateContent = await fs.promises.readFile(devPaths.workflow);\n\n // config\n const config = JSON.parse(\n await fs.promises.readFile(devPaths.config, 'utf-8'),\n ) as BlockConfigContainer;\n\n // frontend\n const frontendPath = devPaths.ui;\n\n return {\n type: 'explicit',\n template: {\n type: 'explicit',\n content: templateContent,\n },\n config,\n frontend: {\n type: 'local',\n path: frontendPath,\n signature: this.signer.sign(frontendPath),\n },\n source: spec,\n };\n }\n\n case 'dev-v2': {\n const description = await loadPackDescription(spec.folder);\n const config = JSON.parse(\n await fs.promises.readFile(description.components.model.file, {\n encoding: 'utf-8',\n }),\n ) as BlockConfigContainer;\n const workflowContent = await fs.promises.readFile(\n description.components.workflow.main.file,\n );\n const frontendPath = description.components.ui.folder;\n const source = { ...spec };\n if (spec.mtime === undefined)\n // if absent, calculating the mtime here, so the block will correctly show whether it can be updated\n source.mtime = await getDevV2PacketMtime(description);\n return {\n type: 'explicit',\n template: {\n type: 'explicit',\n content: workflowContent,\n },\n config,\n frontend: {\n type: 'local',\n path: frontendPath,\n signature: this.signer.sign(frontendPath),\n },\n source,\n };\n }\n\n case 'from-registry-v1': {\n const urlPrefix = `${tSlash(spec.registryUrl)}${RegistryV1.packageContentPrefix({ organization: spec.id.organization, package: spec.id.name, version: spec.id.version })}`;\n\n const templateUrl = `${urlPrefix}/template.plj.gz`;\n // template\n const templateResponse = await this.remoteContentCache.forceFetch(templateUrl);\n const templateContent = new Uint8Array(templateResponse);\n\n // config\n const configResponse = await this.remoteContentCache.forceFetch(`${urlPrefix}/config.json`);\n const config = bufferToJson(configResponse) as BlockConfigContainer;\n\n return {\n type: 'explicit',\n template: {\n type: 'explicit',\n content: templateContent,\n },\n config,\n frontend: {\n type: 'url',\n url: `${urlPrefix}/frontend.tgz`,\n },\n source: spec,\n };\n }\n\n case 'from-registry-v2': {\n const registry = this.v2RegistryProvider.getRegistry(spec.registryUrl);\n const components = await registry.getComponents(spec.id);\n const getModel = async () =>\n bufferToJson(await this.remoteContentCache.forceFetch(components.model.url)) as BlockConfigContainer;\n const getWorkflow = async () =>\n await this.remoteContentCache.forceFetch(components.workflow.main.url);\n\n const [model, workflow] = await Promise.all([getModel(), getWorkflow()]);\n\n return {\n type: 'explicit',\n template: {\n type: 'explicit',\n content: Buffer.from(workflow),\n },\n config: model,\n frontend: {\n type: 'url',\n url: components.ui.url,\n },\n source: spec,\n };\n }\n\n default:\n return assertNever(spec);\n }\n }\n}\n\nfunction createCustomBlockPack(tx: PlTransaction, spec: BlockPackSpecPrepared): AnyResourceRef {\n const blockPackInfo: BlockPackInfo = { config: spec.config, source: spec.source };\n const bp = tx.createStruct(BlockPackCustomType, JSON.stringify(blockPackInfo));\n tx.createField(field(bp, BlockPackTemplateField), 'Input', loadTemplate(tx, spec.template));\n tx.createField(field(bp, BlockPackFrontendField), 'Input', createFrontend(tx, spec.frontend));\n tx.lock(bp);\n\n return bp;\n}\n\nexport function createBlockPack(tx: PlTransaction, spec: BlockPackSpecPrepared): AnyResourceRef {\n switch (spec.type) {\n case 'prepared':\n return createCustomBlockPack(tx, spec);\n default:\n return assertNever(spec.type);\n }\n}\n"],"names":["LRUCache","request","resolveDevPacket","loadPackDescription","RegistryV1","assertNever","__addDisposableResource","WorkerManager","getDevV2PacketMtime","field","loadTemplate","createFrontend"],"mappings":";;;;;;;;;;;;;;;AAoBO,MAAM,mBAAmB,GAAiB,EAAE,IAAI,EAAE,iBAAiB,EAAE,OAAO,EAAE,GAAG;AACjF,MAAM,sBAAsB,GAAG;AAC/B,MAAM,sBAAsB,GAAG;AAEtC;AACA,SAAS,MAAM,CAAC,GAAW,EAAA;AACzB,IAAA,IAAI,GAAG,CAAC,QAAQ,CAAC,GAAG,CAAC;AAAE,QAAA,OAAO,GAAG;;QAC5B,OAAO,CAAA,EAAG,GAAG,CAAA,CAAA,CAAG;AACvB;AAEA,SAAS,cAAc,CAAC,MAAmB,EAAA;IACzC,OAAO,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC;AAC7C;AAEA,SAAS,Y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E,EAAE,sBAAsB,CAAC,EAAE,OAAO,EAAEC,6BAAY,CAAC,EAAE,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAC;IAC3F,EAAE,CAAC,WAAW,CAACD,cAAK,CAAC,EAAE,EAAE,sBAAsB,CAAC,EAAE,OAAO,EAAEE,uBAAc,CAAC,EAAE,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAC;AAC7F,IAAA,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC;AAEX,IAAA,OAAO,EAAE;AACX;AAEM,SAAU,eAAe,CAAC,EAAiB,EAAE,IAA2B,EAAA;AAC5E,IAAA,QAAQ,IAAI,CAAC,IAAI;AACf,QAAA,KAAK,UAAU;AACb,YAAA,OAAO,qBAAqB,CAAC,EAAE,EAAE,IAAI,CAAC;AACxC,QAAA;AACE,YAAA,OAAON,qBAAW,CAAC,IAAI,CAAC,IAAI,CAAC;;AAEnC;;;;;;;;"}
1
+ {"version":3,"file":"block_pack.cjs","sources":["../../../src/mutator/block-pack/block_pack.ts"],"sourcesContent":["import type { AnyResourceRef, PlTransaction, ResourceType } from '@milaboratories/pl-client';\nimport { field } from '@milaboratories/pl-client';\nimport { loadTemplate } from '../template/template_loading';\nimport type { BlockPackExplicit, BlockPackSpecAny, BlockPackSpecPrepared } from '../../model';\nimport type { Signer } from '@milaboratories/ts-helpers';\nimport { assertNever } from '@milaboratories/ts-helpers';\nimport fs from 'node:fs';\nimport type { Dispatcher } from 'undici';\nimport { request } from 'undici';\nimport { createFrontend } from './frontend';\nimport type { BlockConfigContainer } from '@platforma-sdk/model';\nimport { Code } from '@platforma-sdk/model';\nimport { loadPackDescription, RegistryV1 } from '@platforma-sdk/block-tools';\nimport type { BlockPackInfo } from '../../model/block_pack';\nimport { resolveDevPacket } from '../../dev_env';\nimport { getDevV2PacketMtime } from '../../block_registry';\nimport type { V2RegistryProvider } from '../../block_registry/registry-v2-provider';\nimport { LRUCache } from 'lru-cache';\nimport type { BlockPackSpec } from '@milaboratories/pl-model-middle-layer';\nimport { WorkerManager } from '../../worker/WorkerManager';\nimport { z } from 'zod';\n\nexport const BlockPackCustomType: ResourceType = { name: 'BlockPackCustom', version: '1' };\nexport const BlockPackTemplateField = 'template';\nexport const BlockPackFrontendField = 'frontend';\n\n/** Ensure trailing slash */\nfunction tSlash(str: string): string {\n if (str.endsWith('/')) return str;\n else return `${str}/`;\n}\n\nfunction parseStringConfig(configContent: string): BlockConfigContainer {\n const res = z.record(z.string(), z.unknown()).safeParse(JSON.parse(configContent));\n\n if (!res.success) {\n throw new Error('Invalid config content');\n }\n\n if (!Code.safeParse(res.data.code).success) {\n throw new Error('No code bundle');\n }\n\n return res.data as BlockConfigContainer;\n}\n\nfunction parseBufferConfig(buffer: ArrayBuffer): BlockConfigContainer {\n return parseStringConfig(Buffer.from(buffer).toString('utf8'));\n}\n\nexport class BlockPackPreparer {\n constructor(\n private readonly v2RegistryProvider: V2RegistryProvider,\n private readonly signer: Signer,\n private readonly http?: Dispatcher,\n ) {}\n\n private readonly remoteContentCache = new LRUCache<string, ArrayBuffer>({\n max: 500,\n maxSize: 128 * 1024 * 1024,\n fetchMethod: async (key) => {\n const httpOptions = this.http !== undefined ? { dispatcher: this.http } : {};\n return await (await request(key, httpOptions)).body.arrayBuffer();\n },\n sizeCalculation: (value) => value.byteLength,\n });\n\n public async getBlockConfigContainer(spec: BlockPackSpecAny): Promise<BlockConfigContainer> {\n switch (spec.type) {\n case 'explicit':\n return spec.config;\n\n case 'prepared':\n return spec.config;\n\n case 'dev-v1': {\n const devPaths = await resolveDevPacket(spec.folder, false);\n console.log('devPaths', devPaths);\n const configContent = await fs.promises.readFile(devPaths.config, { encoding: 'utf-8' });\n return JSON.parse(configContent);\n }\n\n case 'dev-v2': {\n const description = await loadPackDescription(spec.folder);\n const configContent = await fs.promises.readFile(description.components.model.file, {\n encoding: 'utf-8',\n });\n return parseStringConfig(configContent);\n }\n\n case 'from-registry-v1': {\n const urlPrefix = `${tSlash(spec.registryUrl)}${RegistryV1.packageContentPrefix({ organization: spec.id.organization, package: spec.id.name, version: spec.id.version })}`;\n\n const configResponse = await this.remoteContentCache.forceFetch(`${urlPrefix}/config.json`);\n return JSON.parse(Buffer.from(configResponse).toString('utf8'));\n }\n\n case 'from-registry-v2': {\n const registry = this.v2RegistryProvider.getRegistry(spec.registryUrl);\n const components = await registry.getComponents(spec.id);\n const configResponse = await this.remoteContentCache.forceFetch(components.model.url);\n return parseBufferConfig(configResponse);\n }\n\n default:\n return assertNever(spec);\n }\n }\n\n public async prepare(spec: BlockPackSpecAny): Promise<BlockPackSpecPrepared> {\n if (spec.type === 'prepared') {\n return spec;\n }\n\n const explicit = await this.prepareWithoutUnpacking(spec);\n\n await using workerManager = new WorkerManager();\n\n return {\n ...explicit,\n type: 'prepared',\n template: {\n type: 'prepared',\n data: await workerManager.process('parseTemplate', explicit.template.content),\n },\n };\n }\n\n private async prepareWithoutUnpacking(spec: BlockPackExplicit | BlockPackSpec): Promise<BlockPackExplicit> {\n switch (spec.type) {\n case 'explicit':\n return spec;\n\n case 'dev-v1': {\n const devPaths = await resolveDevPacket(spec.folder, false);\n\n // template\n const templateContent = await fs.promises.readFile(devPaths.workflow);\n\n // config\n const config = JSON.parse(\n await fs.promises.readFile(devPaths.config, 'utf-8'),\n );\n\n // frontend\n const frontendPath = devPaths.ui;\n\n return {\n type: 'explicit',\n template: {\n type: 'explicit',\n content: templateContent,\n },\n config,\n frontend: {\n type: 'local',\n path: frontendPath,\n signature: this.signer.sign(frontendPath),\n },\n source: spec,\n };\n }\n\n case 'dev-v2': {\n const description = await loadPackDescription(spec.folder);\n const config = parseStringConfig(\n await fs.promises.readFile(description.components.model.file, {\n encoding: 'utf-8',\n }),\n );\n const workflowContent = await fs.promises.readFile(\n description.components.workflow.main.file,\n );\n const frontendPath = description.components.ui.folder;\n const source = { ...spec };\n if (spec.mtime === undefined)\n // if absent, calculating the mtime here, so the block will correctly show whether it can be updated\n source.mtime = await getDevV2PacketMtime(description);\n return {\n type: 'explicit',\n template: {\n type: 'explicit',\n content: workflowContent,\n },\n config,\n frontend: {\n type: 'local',\n path: frontendPath,\n signature: this.signer.sign(frontendPath),\n },\n source,\n };\n }\n\n case 'from-registry-v1': {\n const urlPrefix = `${tSlash(spec.registryUrl)}${RegistryV1.packageContentPrefix({ organization: spec.id.organization, package: spec.id.name, version: spec.id.version })}`;\n\n const templateUrl = `${urlPrefix}/template.plj.gz`;\n // template\n const templateResponse = await this.remoteContentCache.forceFetch(templateUrl);\n const templateContent = new Uint8Array(templateResponse);\n\n // config\n const configResponse = await this.remoteContentCache.forceFetch(`${urlPrefix}/config.json`);\n const config = JSON.parse(Buffer.from(configResponse).toString('utf8')) as BlockConfigContainer;\n\n return {\n type: 'explicit',\n template: {\n type: 'explicit',\n content: templateContent,\n },\n config,\n frontend: {\n type: 'url',\n url: `${urlPrefix}/frontend.tgz`,\n },\n source: spec,\n };\n }\n\n case 'from-registry-v2': {\n const registry = this.v2RegistryProvider.getRegistry(spec.registryUrl);\n const components = await registry.getComponents(spec.id);\n const getModel = async () =>\n parseBufferConfig(await this.remoteContentCache.forceFetch(components.model.url));\n const getWorkflow = async () =>\n await this.remoteContentCache.forceFetch(components.workflow.main.url);\n\n const [model, workflow] = await Promise.all([getModel(), getWorkflow()]);\n\n return {\n type: 'explicit',\n template: {\n type: 'explicit',\n content: Buffer.from(workflow),\n },\n config: model,\n frontend: {\n type: 'url',\n url: components.ui.url,\n },\n source: spec,\n };\n }\n\n default:\n return assertNever(spec);\n }\n }\n}\n\nfunction createCustomBlockPack(tx: PlTransaction, spec: BlockPackSpecPrepared): AnyResourceRef {\n const blockPackInfo: BlockPackInfo = { config: spec.config, source: spec.source };\n const bp = tx.createStruct(BlockPackCustomType, JSON.stringify(blockPackInfo));\n tx.createField(field(bp, BlockPackTemplateField), 'Input', loadTemplate(tx, spec.template));\n tx.createField(field(bp, BlockPackFrontendField), 'Input', createFrontend(tx, spec.frontend));\n tx.lock(bp);\n\n return bp;\n}\n\nexport function createBlockPack(tx: PlTransaction, spec: BlockPackSpecPrepared): AnyResourceRef {\n switch (spec.type) {\n case 'prepared':\n return createCustomBlockPack(tx, spec);\n default:\n return assertNever(spec.type);\n }\n}\n"],"names":["z","Code","LRUCache","request","resolveDevPacket","loadPackDescription","RegistryV1","assertNever","__addDisposableResource","WorkerManager","getDevV2PacketMtime","field","loadTemplate","createFrontend"],"mappings":";;;;;;;;;;;;;;;;;AAsBO,MAAM,mBAAmB,GAAiB,EAAE,IAAI,EAAE,iBAAiB,EAAE,OAAO,EAAE,GAAG;AACjF,MAAM,sBAAsB,GAAG;AAC/B,MAAM,sBAAsB,GAAG;AAEtC;AACA,SAAS,MAAM,CAAC,GAAW,EAAA;AACzB,IAAA,IAAI,GAAG,CAAC,QAAQ,CAAC,GAAG,CAAC;AAAE,QAAA,OAAO,GAAG;;QAC5B,OAAO,CAAA,EAAG,GAAG,CAAA,CAAA,CAAG;AACvB;AAEA,SAAS,iBAAiB,CAAC,aAAqB,EAAA;IAC9C,MAAM,GAAG,GAAGA,KAAC,CAAC,MAAM,CAACA,KAAC,CAAC,MAAM,EAAE,EAAEA,KAAC,CAAC,OAAO,EAAE,CAAC,CAAC,SAAS,CAAC,IAAI,CAAC,KAAK,CAAC,aAAa,CAAC,CAAC;AAElF,IAAA,IAAI,CAAC,GAAG,CAAC,OAAO,EAAE;AAChB,QAAA,MAAM,IAAI,KAAK,CAAC,wBAAwB,CAAC;IAC3C;AAEA,IAAA,IAAI,CAACC,UAAI,CAAC,SAAS,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,OAAO,EAAE;AAC1C,QAAA,MAAM,IAAI,KAAK,CAAC,gBAAgB,CAAC;IACnC;IAEA,OAAO,GAAG,CAAC,IAA4B;AACzC;AAEA,SAAS,iBAAiB,CAAC,MAAmB,EAAA;AAC5C,IAAA,OAAO,iBAAiB,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC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OAAO,CAAC,QAAQ,CAAC,kBAAkB;IACnC,OAAO,CAAC,QAAQ,CAAC,MAAM;IACvB,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAC;gBAFL,kBAAkB,EAAE,kBAAkB,EACtC,MAAM,EAAE,MAAM,EACd,IAAI,CAAC,EAAE,UAAU,YAAA;IAGpC,OAAO,CAAC,QAAQ,CAAC,kBAAkB,CAQhC;IAEU,uBAAuB,CAAC,IAAI,EAAE,gBAAgB,GAAG,OAAO,CAAC,oBAAoB,CAAC;IA0C9E,OAAO,CAAC,IAAI,EAAE,gBAAgB,GAAG,OAAO,CAAC,qBAAqB,CAAC;YAmB9D,uBAAuB;CA0HtC;AAYD,wBAAgB,eAAe,CAAC,EAAE,EAAE,aAAa,EAAE,IAAI,EAAE,qBAAqB,GAAG,cAAc,CAO9F"}
@@ -5,11 +5,13 @@ import { assertNever } from '@milaboratories/ts-helpers';
5
5
  import fs from 'node:fs';
6
6
  import { request } from 'undici';
7
7
  import { createFrontend } from './frontend.js';
8
+ import { Code } from '@platforma-sdk/model';
8
9
  import { RegistryV1, loadPackDescription } from '@platforma-sdk/block-tools';
9
10
  import { resolveDevPacket } from '../../dev_env/index.js';
10
11
  import { getDevV2PacketMtime } from '../../block_registry/registry.js';
11
12
  import { LRUCache } from 'lru-cache';
12
13
  import { WorkerManager } from '../../worker/WorkerManager.js';
14
+ import { z } from 'zod';
13
15
 
14
16
  const BlockPackCustomType = { name: 'BlockPackCustom', version: '1' };
15
17
  const BlockPackTemplateField = 'template';
@@ -21,11 +23,18 @@ function tSlash(str) {
21
23
  else
22
24
  return `${str}/`;
23
25
  }
24
- function bufferToString(buffer) {
25
- return Buffer.from(buffer).toString('utf8');
26
+ function parseStringConfig(configContent) {
27
+ const res = z.record(z.string(), z.unknown()).safeParse(JSON.parse(configContent));
28
+ if (!res.success) {
29
+ throw new Error('Invalid config content');
30
+ }
31
+ if (!Code.safeParse(res.data.code).success) {
32
+ throw new Error('No code bundle');
33
+ }
34
+ return res.data;
26
35
  }
27
- function bufferToJson(buffer) {
28
- return JSON.parse(bufferToString(buffer));
36
+ function parseBufferConfig(buffer) {
37
+ return parseStringConfig(Buffer.from(buffer).toString('utf8'));
29
38
  }
30
39
  class BlockPackPreparer {
31
40
  v2RegistryProvider;
@@ -53,6 +62,7 @@ class BlockPackPreparer {
53
62
  return spec.config;
54
63
  case 'dev-v1': {
55
64
  const devPaths = await resolveDevPacket(spec.folder);
65
+ console.log('devPaths', devPaths);
56
66
  const configContent = await fs.promises.readFile(devPaths.config, { encoding: 'utf-8' });
57
67
  return JSON.parse(configContent);
58
68
  }
@@ -61,18 +71,18 @@ class BlockPackPreparer {
61
71
  const configContent = await fs.promises.readFile(description.components.model.file, {
62
72
  encoding: 'utf-8',
63
73
  });
64
- return JSON.parse(configContent);
74
+ return parseStringConfig(configContent);
65
75
  }
66
76
  case 'from-registry-v1': {
67
77
  const urlPrefix = `${tSlash(spec.registryUrl)}${RegistryV1.packageContentPrefix({ organization: spec.id.organization, package: spec.id.name, version: spec.id.version })}`;
68
78
  const configResponse = await this.remoteContentCache.forceFetch(`${urlPrefix}/config.json`);
69
- return bufferToJson(configResponse);
79
+ return JSON.parse(Buffer.from(configResponse).toString('utf8'));
70
80
  }
71
81
  case 'from-registry-v2': {
72
82
  const registry = this.v2RegistryProvider.getRegistry(spec.registryUrl);
73
83
  const components = await registry.getComponents(spec.id);
74
84
  const configResponse = await this.remoteContentCache.forceFetch(components.model.url);
75
- return bufferToJson(configResponse);
85
+ return parseBufferConfig(configResponse);
76
86
  }
77
87
  default:
78
88
  return assertNever(spec);
@@ -134,7 +144,7 @@ class BlockPackPreparer {
134
144
  }
135
145
  case 'dev-v2': {
136
146
  const description = await loadPackDescription(spec.folder);
137
- const config = JSON.parse(await fs.promises.readFile(description.components.model.file, {
147
+ const config = parseStringConfig(await fs.promises.readFile(description.components.model.file, {
138
148
  encoding: 'utf-8',
139
149
  }));
140
150
  const workflowContent = await fs.promises.readFile(description.components.workflow.main.file);
@@ -166,7 +176,7 @@ class BlockPackPreparer {
166
176
  const templateContent = new Uint8Array(templateResponse);
167
177
  // config
168
178
  const configResponse = await this.remoteContentCache.forceFetch(`${urlPrefix}/config.json`);
169
- const config = bufferToJson(configResponse);
179
+ const config = JSON.parse(Buffer.from(configResponse).toString('utf8'));
170
180
  return {
171
181
  type: 'explicit',
172
182
  template: {
@@ -184,7 +194,7 @@ class BlockPackPreparer {
184
194
  case 'from-registry-v2': {
185
195
  const registry = this.v2RegistryProvider.getRegistry(spec.registryUrl);
186
196
  const components = await registry.getComponents(spec.id);
187
- const getModel = async () => bufferToJson(await this.remoteContentCache.forceFetch(components.model.url));
197
+ const getModel = async () => parseBufferConfig(await this.remoteContentCache.forceFetch(components.model.url));
188
198
  const getWorkflow = async () => await this.remoteContentCache.forceFetch(components.workflow.main.url);
189
199
  const [model, workflow] = await Promise.all([getModel(), getWorkflow()]);
190
200
  return {
@@ -1 +1 @@
1
- {"version":3,"file":"block_pack.js","sources":["../../../src/mutator/block-pack/block_pack.ts"],"sourcesContent":["import type { AnyResourceRef, PlTransaction, ResourceType } from '@milaboratories/pl-client';\nimport { field } from '@milaboratories/pl-client';\nimport { loadTemplate } from '../template/template_loading';\nimport type { BlockPackExplicit, BlockPackSpecAny, BlockPackSpecPrepared } from '../../model';\nimport type { Signer } from '@milaboratories/ts-helpers';\nimport { assertNever } from '@milaboratories/ts-helpers';\nimport fs from 'node:fs';\nimport type { Dispatcher } from 'undici';\nimport { request } from 'undici';\nimport { createFrontend } from './frontend';\nimport type { BlockConfigContainer } from '@platforma-sdk/model';\nimport { loadPackDescription, RegistryV1 } from '@platforma-sdk/block-tools';\nimport type { BlockPackInfo } from '../../model/block_pack';\nimport { resolveDevPacket } from '../../dev_env';\nimport { getDevV2PacketMtime } from '../../block_registry';\nimport type { V2RegistryProvider } from '../../block_registry/registry-v2-provider';\nimport { LRUCache } from 'lru-cache';\nimport type { BlockPackSpec } from '@milaboratories/pl-model-middle-layer';\nimport { WorkerManager } from '../../worker/WorkerManager';\n\nexport const BlockPackCustomType: ResourceType = { name: 'BlockPackCustom', version: '1' };\nexport const BlockPackTemplateField = 'template';\nexport const BlockPackFrontendField = 'frontend';\n\n/** Ensure trailing slash */\nfunction tSlash(str: string): string {\n if (str.endsWith('/')) return str;\n else return `${str}/`;\n}\n\nfunction bufferToString(buffer: ArrayBuffer): string {\n return Buffer.from(buffer).toString('utf8');\n}\n\nfunction bufferToJson(buffer: ArrayBuffer): unknown {\n return JSON.parse(bufferToString(buffer));\n}\n\nexport class BlockPackPreparer {\n constructor(\n private readonly v2RegistryProvider: V2RegistryProvider,\n private readonly signer: Signer,\n private readonly http?: Dispatcher,\n ) {}\n\n private readonly remoteContentCache = new LRUCache<string, ArrayBuffer>({\n max: 500,\n maxSize: 128 * 1024 * 1024,\n fetchMethod: async (key) => {\n const httpOptions = this.http !== undefined ? { dispatcher: this.http } : {};\n return await (await request(key, httpOptions)).body.arrayBuffer();\n },\n sizeCalculation: (value) => value.byteLength,\n });\n\n public async getBlockConfigContainer(spec: BlockPackSpecAny): Promise<BlockConfigContainer> {\n switch (spec.type) {\n case 'explicit':\n return spec.config;\n\n case 'prepared':\n return spec.config;\n\n case 'dev-v1': {\n const devPaths = await resolveDevPacket(spec.folder, false);\n const configContent = await fs.promises.readFile(devPaths.config, { encoding: 'utf-8' });\n return JSON.parse(configContent) as BlockConfigContainer;\n }\n\n case 'dev-v2': {\n const description = await loadPackDescription(spec.folder);\n const configContent = await fs.promises.readFile(description.components.model.file, {\n encoding: 'utf-8',\n });\n return JSON.parse(configContent) as BlockConfigContainer;\n }\n\n case 'from-registry-v1': {\n const urlPrefix = `${tSlash(spec.registryUrl)}${RegistryV1.packageContentPrefix({ organization: spec.id.organization, package: spec.id.name, version: spec.id.version })}`;\n\n const configResponse = await this.remoteContentCache.forceFetch(`${urlPrefix}/config.json`);\n return bufferToJson(configResponse) as BlockConfigContainer;\n }\n\n case 'from-registry-v2': {\n const registry = this.v2RegistryProvider.getRegistry(spec.registryUrl);\n const components = await registry.getComponents(spec.id);\n const configResponse = await this.remoteContentCache.forceFetch(components.model.url);\n return bufferToJson(configResponse) as BlockConfigContainer;\n }\n\n default:\n return assertNever(spec);\n }\n }\n\n public async prepare(spec: BlockPackSpecAny): Promise<BlockPackSpecPrepared> {\n if (spec.type === 'prepared') {\n return spec;\n }\n\n const explicit = await this.prepareWithoutUnpacking(spec);\n\n await using workerManager = new WorkerManager();\n\n return {\n ...explicit,\n type: 'prepared',\n template: {\n type: 'prepared',\n data: await workerManager.process('parseTemplate', explicit.template.content),\n },\n };\n }\n\n private async prepareWithoutUnpacking(spec: BlockPackExplicit | BlockPackSpec): Promise<BlockPackExplicit> {\n switch (spec.type) {\n case 'explicit':\n return spec;\n\n case 'dev-v1': {\n const devPaths = await resolveDevPacket(spec.folder, false);\n\n // template\n const templateContent = await fs.promises.readFile(devPaths.workflow);\n\n // config\n const config = JSON.parse(\n await fs.promises.readFile(devPaths.config, 'utf-8'),\n ) as BlockConfigContainer;\n\n // frontend\n const frontendPath = devPaths.ui;\n\n return {\n type: 'explicit',\n template: {\n type: 'explicit',\n content: templateContent,\n },\n config,\n frontend: {\n type: 'local',\n path: frontendPath,\n signature: this.signer.sign(frontendPath),\n },\n source: spec,\n };\n }\n\n case 'dev-v2': {\n const description = await loadPackDescription(spec.folder);\n const config = JSON.parse(\n await fs.promises.readFile(description.components.model.file, {\n encoding: 'utf-8',\n }),\n ) as BlockConfigContainer;\n const workflowContent = await fs.promises.readFile(\n description.components.workflow.main.file,\n );\n const frontendPath = description.components.ui.folder;\n const source = { ...spec };\n if (spec.mtime === undefined)\n // if absent, calculating the mtime here, so the block will correctly show whether it can be updated\n source.mtime = await getDevV2PacketMtime(description);\n return {\n type: 'explicit',\n template: {\n type: 'explicit',\n content: workflowContent,\n },\n config,\n frontend: {\n type: 'local',\n path: frontendPath,\n signature: this.signer.sign(frontendPath),\n },\n source,\n };\n }\n\n case 'from-registry-v1': {\n const urlPrefix = `${tSlash(spec.registryUrl)}${RegistryV1.packageContentPrefix({ organization: spec.id.organization, package: spec.id.name, version: spec.id.version })}`;\n\n const templateUrl = `${urlPrefix}/template.plj.gz`;\n // template\n const templateResponse = await this.remoteContentCache.forceFetch(templateUrl);\n const templateContent = new Uint8Array(templateResponse);\n\n // config\n const configResponse = await this.remoteContentCache.forceFetch(`${urlPrefix}/config.json`);\n const config = bufferToJson(configResponse) as BlockConfigContainer;\n\n return {\n type: 'explicit',\n template: {\n type: 'explicit',\n content: templateContent,\n },\n config,\n frontend: {\n type: 'url',\n url: `${urlPrefix}/frontend.tgz`,\n },\n source: spec,\n };\n }\n\n case 'from-registry-v2': {\n const registry = this.v2RegistryProvider.getRegistry(spec.registryUrl);\n const components = await registry.getComponents(spec.id);\n const getModel = async () =>\n bufferToJson(await this.remoteContentCache.forceFetch(components.model.url)) as BlockConfigContainer;\n const getWorkflow = async () =>\n await this.remoteContentCache.forceFetch(components.workflow.main.url);\n\n const [model, workflow] = await Promise.all([getModel(), getWorkflow()]);\n\n return {\n type: 'explicit',\n template: {\n type: 'explicit',\n content: Buffer.from(workflow),\n },\n config: model,\n frontend: {\n type: 'url',\n url: components.ui.url,\n },\n source: spec,\n };\n }\n\n default:\n return assertNever(spec);\n }\n }\n}\n\nfunction createCustomBlockPack(tx: PlTransaction, spec: BlockPackSpecPrepared): AnyResourceRef {\n const blockPackInfo: BlockPackInfo = { config: spec.config, source: spec.source };\n const bp = tx.createStruct(BlockPackCustomType, JSON.stringify(blockPackInfo));\n tx.createField(field(bp, BlockPackTemplateField), 'Input', loadTemplate(tx, spec.template));\n tx.createField(field(bp, BlockPackFrontendField), 'Input', createFrontend(tx, spec.frontend));\n tx.lock(bp);\n\n return bp;\n}\n\nexport function createBlockPack(tx: PlTransaction, spec: BlockPackSpecPrepared): AnyResourceRef {\n switch (spec.type) {\n case 'prepared':\n return createCustomBlockPack(tx, spec);\n default:\n return assertNever(spec.type);\n }\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;AA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oBAAA,MAAM,EAAE,IAAI;iBACb;YACH;AAEA,YAAA;AACE,gBAAA,OAAO,WAAW,CAAC,IAAI,CAAC;;IAE9B;AACD;AAED,SAAS,qBAAqB,CAAC,EAAiB,EAAE,IAA2B,EAAA;AAC3E,IAAA,MAAM,aAAa,GAAkB,EAAE,MAAM,EAAE,IAAI,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,CAAC,MAAM,EAAE;AACjF,IAAA,MAAM,EAAE,GAAG,EAAE,CAAC,YAAY,CAAC,mBAAmB,EAAE,IAAI,CAAC,SAAS,CAAC,aAAa,CAAC,CAAC;IAC9E,EAAE,CAAC,WAAW,CAAC,KAAK,CAAC,EAAE,EAAE,sBAAsB,CAAC,EAAE,OAAO,EAAE,YAAY,CAAC,EAAE,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAC;IAC3F,EAAE,CAAC,WAAW,CAAC,KAAK,CAAC,EAAE,EAAE,sBAAsB,CAAC,EAAE,OAAO,EAAE,cAAc,CAAC,EAAE,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAC;AAC7F,IAAA,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC;AAEX,IAAA,OAAO,EAAE;AACX;AAEM,SAAU,eAAe,CAAC,EAAiB,EAAE,IAA2B,EAAA;AAC5E,IAAA,QAAQ,IAAI,CAAC,IAAI;AACf,QAAA,KAAK,UAAU;AACb,YAAA,OAAO,qBAAqB,CAAC,EAAE,EAAE,IAAI,CAAC;AACxC,QAAA;AACE,YAAA,OAAO,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC;;AAEnC;;;;"}
1
+ {"version":3,"file":"block_pack.js","sources":["../../../src/mutator/block-pack/block_pack.ts"],"sourcesContent":["import type { AnyResourceRef, PlTransaction, ResourceType } from '@milaboratories/pl-client';\nimport { field } from '@milaboratories/pl-client';\nimport { loadTemplate } from '../template/template_loading';\nimport type { BlockPackExplicit, BlockPackSpecAny, BlockPackSpecPrepared } from '../../model';\nimport type { Signer } from '@milaboratories/ts-helpers';\nimport { assertNever } from '@milaboratories/ts-helpers';\nimport fs from 'node:fs';\nimport type { Dispatcher } from 'undici';\nimport { request } from 'undici';\nimport { createFrontend } from './frontend';\nimport type { BlockConfigContainer } from '@platforma-sdk/model';\nimport { Code } from '@platforma-sdk/model';\nimport { loadPackDescription, RegistryV1 } from '@platforma-sdk/block-tools';\nimport type { BlockPackInfo } from '../../model/block_pack';\nimport { resolveDevPacket } from '../../dev_env';\nimport { getDevV2PacketMtime } from '../../block_registry';\nimport type { V2RegistryProvider } from '../../block_registry/registry-v2-provider';\nimport { LRUCache } from 'lru-cache';\nimport type { BlockPackSpec } from '@milaboratories/pl-model-middle-layer';\nimport { WorkerManager } from '../../worker/WorkerManager';\nimport { z } from 'zod';\n\nexport const BlockPackCustomType: ResourceType = { name: 'BlockPackCustom', version: '1' };\nexport const BlockPackTemplateField = 'template';\nexport const BlockPackFrontendField = 'frontend';\n\n/** Ensure trailing slash */\nfunction tSlash(str: string): string {\n if (str.endsWith('/')) return str;\n else return `${str}/`;\n}\n\nfunction parseStringConfig(configContent: string): BlockConfigContainer {\n const res = z.record(z.string(), z.unknown()).safeParse(JSON.parse(configContent));\n\n if (!res.success) {\n throw new Error('Invalid config content');\n }\n\n if (!Code.safeParse(res.data.code).success) {\n throw new Error('No code bundle');\n }\n\n return res.data as BlockConfigContainer;\n}\n\nfunction parseBufferConfig(buffer: ArrayBuffer): BlockConfigContainer {\n return parseStringConfig(Buffer.from(buffer).toString('utf8'));\n}\n\nexport class BlockPackPreparer {\n constructor(\n private readonly v2RegistryProvider: V2RegistryProvider,\n private readonly signer: Signer,\n private readonly http?: Dispatcher,\n ) {}\n\n private readonly remoteContentCache = new LRUCache<string, ArrayBuffer>({\n max: 500,\n maxSize: 128 * 1024 * 1024,\n fetchMethod: async (key) => {\n const httpOptions = this.http !== undefined ? { dispatcher: this.http } : {};\n return await (await request(key, httpOptions)).body.arrayBuffer();\n },\n sizeCalculation: (value) => value.byteLength,\n });\n\n public async getBlockConfigContainer(spec: BlockPackSpecAny): Promise<BlockConfigContainer> {\n switch (spec.type) {\n case 'explicit':\n return spec.config;\n\n case 'prepared':\n return spec.config;\n\n case 'dev-v1': {\n const devPaths = await resolveDevPacket(spec.folder, false);\n console.log('devPaths', devPaths);\n const configContent = await fs.promises.readFile(devPaths.config, { encoding: 'utf-8' });\n return JSON.parse(configContent);\n }\n\n case 'dev-v2': {\n const description = await loadPackDescription(spec.folder);\n const configContent = await fs.promises.readFile(description.components.model.file, {\n encoding: 'utf-8',\n });\n return parseStringConfig(configContent);\n }\n\n case 'from-registry-v1': {\n const urlPrefix = `${tSlash(spec.registryUrl)}${RegistryV1.packageContentPrefix({ organization: spec.id.organization, package: spec.id.name, version: spec.id.version })}`;\n\n const configResponse = await this.remoteContentCache.forceFetch(`${urlPrefix}/config.json`);\n return JSON.parse(Buffer.from(configResponse).toString('utf8'));\n }\n\n case 'from-registry-v2': {\n const registry = this.v2RegistryProvider.getRegistry(spec.registryUrl);\n const components = await registry.getComponents(spec.id);\n const configResponse = await this.remoteContentCache.forceFetch(components.model.url);\n return parseBufferConfig(configResponse);\n }\n\n default:\n return assertNever(spec);\n }\n }\n\n public async prepare(spec: BlockPackSpecAny): Promise<BlockPackSpecPrepared> {\n if (spec.type === 'prepared') {\n return spec;\n }\n\n const explicit = await this.prepareWithoutUnpacking(spec);\n\n await using workerManager = new WorkerManager();\n\n return {\n ...explicit,\n type: 'prepared',\n template: {\n type: 'prepared',\n data: await workerManager.process('parseTemplate', explicit.template.content),\n },\n };\n }\n\n private async prepareWithoutUnpacking(spec: BlockPackExplicit | BlockPackSpec): Promise<BlockPackExplicit> {\n switch (spec.type) {\n case 'explicit':\n return spec;\n\n case 'dev-v1': {\n const devPaths = await resolveDevPacket(spec.folder, false);\n\n // template\n const templateContent = await fs.promises.readFile(devPaths.workflow);\n\n // config\n const config = JSON.parse(\n await fs.promises.readFile(devPaths.config, 'utf-8'),\n );\n\n // frontend\n const frontendPath = devPaths.ui;\n\n return {\n type: 'explicit',\n template: {\n type: 'explicit',\n content: templateContent,\n },\n config,\n frontend: {\n type: 'local',\n path: frontendPath,\n signature: this.signer.sign(frontendPath),\n },\n source: spec,\n };\n }\n\n case 'dev-v2': {\n const description = await loadPackDescription(spec.folder);\n const config = parseStringConfig(\n await fs.promises.readFile(description.components.model.file, {\n encoding: 'utf-8',\n }),\n );\n const workflowContent = await fs.promises.readFile(\n description.components.workflow.main.file,\n );\n const frontendPath = description.components.ui.folder;\n const source = { ...spec };\n if (spec.mtime === undefined)\n // if absent, calculating the mtime here, so the block will correctly show whether it can be updated\n source.mtime = await getDevV2PacketMtime(description);\n return {\n type: 'explicit',\n template: {\n type: 'explicit',\n content: workflowContent,\n },\n config,\n frontend: {\n type: 'local',\n path: frontendPath,\n signature: this.signer.sign(frontendPath),\n },\n source,\n };\n }\n\n case 'from-registry-v1': {\n const urlPrefix = `${tSlash(spec.registryUrl)}${RegistryV1.packageContentPrefix({ organization: spec.id.organization, package: spec.id.name, version: spec.id.version })}`;\n\n const templateUrl = `${urlPrefix}/template.plj.gz`;\n // template\n const templateResponse = await this.remoteContentCache.forceFetch(templateUrl);\n const templateContent = new Uint8Array(templateResponse);\n\n // config\n const configResponse = await this.remoteContentCache.forceFetch(`${urlPrefix}/config.json`);\n const config = JSON.parse(Buffer.from(configResponse).toString('utf8')) as BlockConfigContainer;\n\n return {\n type: 'explicit',\n template: {\n type: 'explicit',\n content: templateContent,\n },\n config,\n frontend: {\n type: 'url',\n url: `${urlPrefix}/frontend.tgz`,\n },\n source: spec,\n };\n }\n\n case 'from-registry-v2': {\n const registry = this.v2RegistryProvider.getRegistry(spec.registryUrl);\n const components = await registry.getComponents(spec.id);\n const getModel = async () =>\n parseBufferConfig(await this.remoteContentCache.forceFetch(components.model.url));\n const getWorkflow = async () =>\n await this.remoteContentCache.forceFetch(components.workflow.main.url);\n\n const [model, workflow] = await Promise.all([getModel(), getWorkflow()]);\n\n return {\n type: 'explicit',\n template: {\n type: 'explicit',\n content: Buffer.from(workflow),\n },\n config: model,\n frontend: {\n type: 'url',\n url: components.ui.url,\n },\n source: spec,\n };\n }\n\n default:\n return assertNever(spec);\n }\n }\n}\n\nfunction createCustomBlockPack(tx: PlTransaction, spec: BlockPackSpecPrepared): AnyResourceRef {\n const blockPackInfo: BlockPackInfo = { config: spec.config, source: spec.source };\n const bp = tx.createStruct(BlockPackCustomType, JSON.stringify(blockPackInfo));\n tx.createField(field(bp, BlockPackTemplateField), 'Input', loadTemplate(tx, spec.template));\n tx.createField(field(bp, BlockPackFrontendField), 'Input', createFrontend(tx, spec.frontend));\n tx.lock(bp);\n\n return bp;\n}\n\nexport function createBlockPack(tx: PlTransaction, spec: BlockPackSpecPrepared): AnyResourceRef {\n switch (spec.type) {\n case 'prepared':\n return createCustomBlockPack(tx, spec);\n default:\n return assertNever(spec.type);\n }\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;;;AAsBO,MAAM,mBAAmB,GAAiB,EAAE,IAAI,EAAE,iBAAiB,EAAE,OAAO,EAAE,GAAG;AACjF,MAAM,sBAAsB,GAAG;AAC/B,MAAM,sBAAsB,GAAG;AAEtC;AACA,SAAS,MAAM,CAAC,GAAW,EAAA;AACzB,IAAA,IAAI,GAAG,CAAC,QAAQ,CAAC,GAAG,CAAC;AAAE,QAAA,OAAO,GAAG;;QAC5B,OAAO,CAAA,EAAG,GAAG,CAAA,CAAA,CAAG;AACvB;AAEA,SAAS,iBAAiB,CAAC,aAAqB,EAAA;IAC9C,MAAM,GAAG,GAAG,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC,SAAS,CAAC,IAAI,CAAC,KAAK,CAAC,aAAa,CAAC,CAAC;AAElF,IAAA,IAAI,CAAC,GAAG,CAAC,OAAO,EAAE;AAChB,QAAA,MAAM,IAAI,KAAK,CAAC,wBAAwB,CAAC;IAC3C;AAEA,IAAA,IAAI,CAAC,IAAI,CAAC,SAA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A;AACE,gBAAA,OAAO,WAAW,CAAC,IAAI,CAAC;;IAE9B;AACD;AAED,SAAS,qBAAqB,CAAC,EAAiB,EAAE,IAA2B,EAAA;AAC3E,IAAA,MAAM,aAAa,GAAkB,EAAE,MAAM,EAAE,IAAI,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,CAAC,MAAM,EAAE;AACjF,IAAA,MAAM,EAAE,GAAG,EAAE,CAAC,YAAY,CAAC,mBAAmB,EAAE,IAAI,CAAC,SAAS,CAAC,aAAa,CAAC,CAAC;IAC9E,EAAE,CAAC,WAAW,CAAC,KAAK,CAAC,EAAE,EAAE,sBAAsB,CAAC,EAAE,OAAO,EAAE,YAAY,CAAC,EAAE,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAC;IAC3F,EAAE,CAAC,WAAW,CAAC,KAAK,CAAC,EAAE,EAAE,sBAAsB,CAAC,EAAE,OAAO,EAAE,cAAc,CAAC,EAAE,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAC;AAC7F,IAAA,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC;AAEX,IAAA,OAAO,EAAE;AACX;AAEM,SAAU,eAAe,CAAC,EAAiB,EAAE,IAA2B,EAAA;AAC5E,IAAA,QAAQ,IAAI,CAAC,IAAI;AACf,QAAA,KAAK,UAAU;AACb,YAAA,OAAO,qBAAqB,CAAC,EAAE,EAAE,IAAI,CAAC;AACxC,QAAA;AACE,YAAA,OAAO,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC;;AAEnC;;;;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@milaboratories/pl-middle-layer",
3
- "version": "1.43.17",
3
+ "version": "1.43.18",
4
4
  "description": "Pl Middle Layer",
5
5
  "engines": {
6
6
  "node": ">=22.19.0"
@@ -29,20 +29,20 @@
29
29
  "es-toolkit": "^1.39.10",
30
30
  "@milaboratories/pl-http": "1.2.0",
31
31
  "@milaboratories/computable": "2.7.1",
32
- "@platforma-sdk/block-tools": "2.6.12",
33
- "@milaboratories/pl-drivers": "1.11.6",
34
- "@milaboratories/pl-model-common": "1.21.0",
35
- "@milaboratories/pl-model-middle-layer": "1.8.31",
36
- "@milaboratories/resolve-helper": "1.1.1",
37
- "@milaboratories/pl-model-backend": "1.1.14",
32
+ "@platforma-sdk/block-tools": "2.6.13",
33
+ "@milaboratories/pl-model-common": "1.21.1",
38
34
  "@milaboratories/pl-client": "2.14.0",
35
+ "@milaboratories/resolve-helper": "1.1.1",
36
+ "@milaboratories/pl-drivers": "1.11.7",
39
37
  "@milaboratories/pl-tree": "1.8.4",
40
- "@platforma-sdk/model": "1.44.1",
38
+ "@milaboratories/pl-model-backend": "1.1.14",
39
+ "@milaboratories/pl-model-middle-layer": "1.8.32",
40
+ "@platforma-sdk/model": "1.44.4",
41
41
  "@milaboratories/ts-helpers": "1.5.1",
42
42
  "@platforma-sdk/workflow-tengo": "5.3.2",
43
+ "@milaboratories/pl-config": "1.7.6",
43
44
  "@milaboratories/pl-errors": "1.1.29",
44
- "@milaboratories/pl-deployments": "2.10.0",
45
- "@milaboratories/pl-config": "1.7.6"
45
+ "@milaboratories/pl-deployments": "2.10.0"
46
46
  },
47
47
  "devDependencies": {
48
48
  "semver": "^7.7.2",
@@ -51,9 +51,9 @@
51
51
  "vitest": "^2.1.9",
52
52
  "@types/node": "~24.5.2",
53
53
  "@milaboratories/build-configs": "1.0.8",
54
- "@milaboratories/ts-configs": "1.0.6",
54
+ "@milaboratories/ts-builder": "1.0.5",
55
55
  "@milaboratories/eslint-config": "1.0.4",
56
- "@milaboratories/ts-builder": "1.0.5"
56
+ "@milaboratories/ts-configs": "1.0.6"
57
57
  },
58
58
  "scripts": {
59
59
  "type-check": "ts-builder types --target node",
@@ -74,12 +74,13 @@ export function computableFromRF(
74
74
  configKey: string,
75
75
  ops: Partial<ComputableRenderingOps> = {},
76
76
  ): Computable<unknown> {
77
- const { code, featureFlags } = codeWithInfo;
78
77
  // adding configKey to reload all outputs on block-pack update
79
78
  const key = `${ctx.blockId}#lambda#${configKey}#${fh.handle}`;
80
79
  ops = { ...ops, key };
81
80
  if (ops.mode === undefined && fh.retentive === true) ops.mode = 'StableOnlyRetentive';
82
81
  return Computable.makeRaw((cCtx) => {
82
+ const { code, featureFlags } = codeWithInfo;
83
+
83
84
  if (getDebugFlags().logOutputRecalculations)
84
85
  console.log(`Block lambda recalculation : ${key} (${cCtx.changeSourceMarker}; ${cCtx.bodyInvocations} invocations)`);
85
86
 
@@ -8,7 +8,7 @@ import { allBlocks } from '../model/project_model_util';
8
8
  import { constructBlockContext } from './block_ctx';
9
9
  import { computableFromCfgOrRF, isActive } from './render';
10
10
  import { getBlockPackInfo } from './util';
11
- import { extractCodeWithInfo } from '@platforma-sdk/model';
11
+ import { extractCodeWithInfo, wrapCallback } from '@platforma-sdk/model';
12
12
 
13
13
  /** Returns derived general project state form the project resource */
14
14
  export function activeConfigs(
@@ -24,6 +24,9 @@ export function activeConfigs(
24
24
  const bp = getBlockPackInfo(prj, id);
25
25
  if (bp === undefined) continue;
26
26
 
27
+ const codeWithInfoOrError = wrapCallback(() => extractCodeWithInfo(bp.cfg));
28
+ if (codeWithInfoOrError.error) continue;
29
+
27
30
  const activeOutputConfigs = Object.entries(bp.cfg.outputs)
28
31
  .map(([, cfg]) => cfg)
29
32
  .filter((cfg) => isActive(cfg))
@@ -33,10 +36,11 @@ export function activeConfigs(
33
36
 
34
37
  const blockCtx = constructBlockContext(prj.persist(), id);
35
38
 
36
- for (const cfg of activeOutputConfigs)
39
+ for (const cfg of activeOutputConfigs) {
37
40
  ret.push(
38
- Computable.wrapError(computableFromCfgOrRF(env, blockCtx, cfg, extractCodeWithInfo(bp.cfg), bp.bpId)),
41
+ Computable.wrapError(computableFromCfgOrRF(env, blockCtx, cfg, codeWithInfoOrError.value, bp.bpId)),
39
42
  );
43
+ }
40
44
  }
41
45
 
42
46
  return ret;
@@ -490,6 +490,10 @@ export class Project {
490
490
  await this.destroy();
491
491
  }
492
492
 
493
+ public dumpState(): ExtendedResourceData[] {
494
+ return this.projectTree.dumpState();
495
+ }
496
+
493
497
  public static async init(env: MiddleLayerEnvironment, rid: ResourceId): Promise<Project> {
494
498
  // Applying migrations to the project resource, if needed
495
499
  await applyProjectMigrations(env.pl, rid);
@@ -25,7 +25,8 @@ import type {
25
25
  } from '@milaboratories/pl-model-middle-layer';
26
26
  import { constructBlockContextArgsOnly } from './block_ctx';
27
27
  import { ifNotUndef } from '../cfg_render/util';
28
- import { extractCodeWithInfo, type BlockSection } from '@platforma-sdk/model';
28
+ import { type BlockSection } from '@platforma-sdk/model';
29
+ import { extractCodeWithInfo, wrapCallback } from '@platforma-sdk/model';
29
30
  import { computableFromCfgOrRF } from './render';
30
31
  import type { NavigationStates } from './navigation_states';
31
32
  import { getBlockPackInfo } from './util';
@@ -163,7 +164,15 @@ export function projectOverview(
163
164
  };
164
165
  }
165
166
  const blockCtxArgsOnly = constructBlockContextArgsOnly(prjEntry, id);
166
- const codeWithInfo = extractCodeWithInfo(cfg);
167
+ const codeWithInfoOrError = wrapCallback(() => extractCodeWithInfo(cfg));
168
+ if (codeWithInfoOrError.error) {
169
+ return {
170
+ title: codeWithInfoOrError.error.message,
171
+ isIncompatibleWithRuntime: true,
172
+ featureFlags: cfg.featureFlags,
173
+ };
174
+ }
175
+ const codeWithInfo = codeWithInfoOrError.value;
167
176
  return {
168
177
  sections: computableFromCfgOrRF(
169
178
  env,
@@ -27,7 +27,7 @@ export class ProjectHelper {
27
27
  const blockConfig = req.blockConfig();
28
28
  if (blockConfig.enrichmentTargets === undefined) return undefined;
29
29
  const args = req.args();
30
- const result = executeSingleLambda(this.quickJs, blockConfig.enrichmentTargets, extractCodeWithInfo(blockConfig)!, args) as PlRef[];
30
+ const result = executeSingleLambda(this.quickJs, blockConfig.enrichmentTargets, extractCodeWithInfo(blockConfig), args) as PlRef[];
31
31
  return result;
32
32
  }
33
33
 
@@ -9,6 +9,7 @@ import type { Dispatcher } from 'undici';
9
9
  import { request } from 'undici';
10
10
  import { createFrontend } from './frontend';
11
11
  import type { BlockConfigContainer } from '@platforma-sdk/model';
12
+ import { Code } from '@platforma-sdk/model';
12
13
  import { loadPackDescription, RegistryV1 } from '@platforma-sdk/block-tools';
13
14
  import type { BlockPackInfo } from '../../model/block_pack';
14
15
  import { resolveDevPacket } from '../../dev_env';
@@ -17,6 +18,7 @@ import type { V2RegistryProvider } from '../../block_registry/registry-v2-provid
17
18
  import { LRUCache } from 'lru-cache';
18
19
  import type { BlockPackSpec } from '@milaboratories/pl-model-middle-layer';
19
20
  import { WorkerManager } from '../../worker/WorkerManager';
21
+ import { z } from 'zod';
20
22
 
21
23
  export const BlockPackCustomType: ResourceType = { name: 'BlockPackCustom', version: '1' };
22
24
  export const BlockPackTemplateField = 'template';
@@ -28,12 +30,22 @@ function tSlash(str: string): string {
28
30
  else return `${str}/`;
29
31
  }
30
32
 
31
- function bufferToString(buffer: ArrayBuffer): string {
32
- return Buffer.from(buffer).toString('utf8');
33
+ function parseStringConfig(configContent: string): BlockConfigContainer {
34
+ const res = z.record(z.string(), z.unknown()).safeParse(JSON.parse(configContent));
35
+
36
+ if (!res.success) {
37
+ throw new Error('Invalid config content');
38
+ }
39
+
40
+ if (!Code.safeParse(res.data.code).success) {
41
+ throw new Error('No code bundle');
42
+ }
43
+
44
+ return res.data as BlockConfigContainer;
33
45
  }
34
46
 
35
- function bufferToJson(buffer: ArrayBuffer): unknown {
36
- return JSON.parse(bufferToString(buffer));
47
+ function parseBufferConfig(buffer: ArrayBuffer): BlockConfigContainer {
48
+ return parseStringConfig(Buffer.from(buffer).toString('utf8'));
37
49
  }
38
50
 
39
51
  export class BlockPackPreparer {
@@ -63,8 +75,9 @@ export class BlockPackPreparer {
63
75
 
64
76
  case 'dev-v1': {
65
77
  const devPaths = await resolveDevPacket(spec.folder, false);
78
+ console.log('devPaths', devPaths);
66
79
  const configContent = await fs.promises.readFile(devPaths.config, { encoding: 'utf-8' });
67
- return JSON.parse(configContent) as BlockConfigContainer;
80
+ return JSON.parse(configContent);
68
81
  }
69
82
 
70
83
  case 'dev-v2': {
@@ -72,21 +85,21 @@ export class BlockPackPreparer {
72
85
  const configContent = await fs.promises.readFile(description.components.model.file, {
73
86
  encoding: 'utf-8',
74
87
  });
75
- return JSON.parse(configContent) as BlockConfigContainer;
88
+ return parseStringConfig(configContent);
76
89
  }
77
90
 
78
91
  case 'from-registry-v1': {
79
92
  const urlPrefix = `${tSlash(spec.registryUrl)}${RegistryV1.packageContentPrefix({ organization: spec.id.organization, package: spec.id.name, version: spec.id.version })}`;
80
93
 
81
94
  const configResponse = await this.remoteContentCache.forceFetch(`${urlPrefix}/config.json`);
82
- return bufferToJson(configResponse) as BlockConfigContainer;
95
+ return JSON.parse(Buffer.from(configResponse).toString('utf8'));
83
96
  }
84
97
 
85
98
  case 'from-registry-v2': {
86
99
  const registry = this.v2RegistryProvider.getRegistry(spec.registryUrl);
87
100
  const components = await registry.getComponents(spec.id);
88
101
  const configResponse = await this.remoteContentCache.forceFetch(components.model.url);
89
- return bufferToJson(configResponse) as BlockConfigContainer;
102
+ return parseBufferConfig(configResponse);
90
103
  }
91
104
 
92
105
  default:
@@ -127,7 +140,7 @@ export class BlockPackPreparer {
127
140
  // config
128
141
  const config = JSON.parse(
129
142
  await fs.promises.readFile(devPaths.config, 'utf-8'),
130
- ) as BlockConfigContainer;
143
+ );
131
144
 
132
145
  // frontend
133
146
  const frontendPath = devPaths.ui;
@@ -150,11 +163,11 @@ export class BlockPackPreparer {
150
163
 
151
164
  case 'dev-v2': {
152
165
  const description = await loadPackDescription(spec.folder);
153
- const config = JSON.parse(
166
+ const config = parseStringConfig(
154
167
  await fs.promises.readFile(description.components.model.file, {
155
168
  encoding: 'utf-8',
156
169
  }),
157
- ) as BlockConfigContainer;
170
+ );
158
171
  const workflowContent = await fs.promises.readFile(
159
172
  description.components.workflow.main.file,
160
173
  );
@@ -189,7 +202,7 @@ export class BlockPackPreparer {
189
202
 
190
203
  // config
191
204
  const configResponse = await this.remoteContentCache.forceFetch(`${urlPrefix}/config.json`);
192
- const config = bufferToJson(configResponse) as BlockConfigContainer;
205
+ const config = JSON.parse(Buffer.from(configResponse).toString('utf8')) as BlockConfigContainer;
193
206
 
194
207
  return {
195
208
  type: 'explicit',
@@ -210,7 +223,7 @@ export class BlockPackPreparer {
210
223
  const registry = this.v2RegistryProvider.getRegistry(spec.registryUrl);
211
224
  const components = await registry.getComponents(spec.id);
212
225
  const getModel = async () =>
213
- bufferToJson(await this.remoteContentCache.forceFetch(components.model.url)) as BlockConfigContainer;
226
+ parseBufferConfig(await this.remoteContentCache.forceFetch(components.model.url));
214
227
  const getWorkflow = async () =>
215
228
  await this.remoteContentCache.forceFetch(components.workflow.main.url);
216
229