@milaboratories/pl-middle-layer 1.74.19 → 1.76.0

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 (87) hide show
  1. package/dist/index.cjs +1 -0
  2. package/dist/index.d.ts +3 -2
  3. package/dist/index.js +2 -2
  4. package/dist/middle_layer/block.cjs.map +1 -1
  5. package/dist/middle_layer/block.js.map +1 -1
  6. package/dist/middle_layer/block_action_context.cjs +57 -0
  7. package/dist/middle_layer/block_action_context.cjs.map +1 -0
  8. package/dist/middle_layer/block_action_context.d.ts +47 -0
  9. package/dist/middle_layer/block_action_context.d.ts.map +1 -0
  10. package/dist/middle_layer/block_action_context.js +57 -0
  11. package/dist/middle_layer/block_action_context.js.map +1 -0
  12. package/dist/middle_layer/build_stamp.cjs +1 -1
  13. package/dist/middle_layer/build_stamp.js +1 -1
  14. package/dist/middle_layer/column_links.cjs +106 -0
  15. package/dist/middle_layer/column_links.cjs.map +1 -0
  16. package/dist/middle_layer/column_links.js +104 -0
  17. package/dist/middle_layer/column_links.js.map +1 -0
  18. package/dist/middle_layer/index.d.ts +2 -1
  19. package/dist/middle_layer/middle_layer.cjs +1 -0
  20. package/dist/middle_layer/middle_layer.cjs.map +1 -1
  21. package/dist/middle_layer/middle_layer.js +1 -0
  22. package/dist/middle_layer/middle_layer.js.map +1 -1
  23. package/dist/middle_layer/project.cjs +53 -19
  24. package/dist/middle_layer/project.cjs.map +1 -1
  25. package/dist/middle_layer/project.d.ts +6 -0
  26. package/dist/middle_layer/project.d.ts.map +1 -1
  27. package/dist/middle_layer/project.js +54 -20
  28. package/dist/middle_layer/project.js.map +1 -1
  29. package/dist/middle_layer/project_overview.cjs +56 -24
  30. package/dist/middle_layer/project_overview.cjs.map +1 -1
  31. package/dist/middle_layer/project_overview.js +55 -25
  32. package/dist/middle_layer/project_overview.js.map +1 -1
  33. package/dist/model/args_derivation.cjs +153 -0
  34. package/dist/model/args_derivation.cjs.map +1 -0
  35. package/dist/model/args_derivation.d.ts +21 -0
  36. package/dist/model/args_derivation.d.ts.map +1 -0
  37. package/dist/model/args_derivation.js +148 -0
  38. package/dist/model/args_derivation.js.map +1 -0
  39. package/dist/model/project_helper.cjs +34 -8
  40. package/dist/model/project_helper.cjs.map +1 -1
  41. package/dist/model/project_helper.d.ts +18 -5
  42. package/dist/model/project_helper.d.ts.map +1 -1
  43. package/dist/model/project_helper.js +34 -8
  44. package/dist/model/project_helper.js.map +1 -1
  45. package/dist/model/project_model.cjs +2 -1
  46. package/dist/model/project_model.cjs.map +1 -1
  47. package/dist/model/project_model.d.ts +1 -1
  48. package/dist/model/project_model.js +2 -1
  49. package/dist/model/project_model.js.map +1 -1
  50. package/dist/mutator/project.cjs +73 -12
  51. package/dist/mutator/project.cjs.map +1 -1
  52. package/dist/mutator/project.d.ts +1 -0
  53. package/dist/mutator/project.d.ts.map +1 -1
  54. package/dist/mutator/project.js +73 -12
  55. package/dist/mutator/project.js.map +1 -1
  56. package/dist/mutator/template/render_block.cjs +35 -2
  57. package/dist/mutator/template/render_block.cjs.map +1 -1
  58. package/dist/mutator/template/render_block.js +35 -4
  59. package/dist/mutator/template/render_block.js.map +1 -1
  60. package/dist/mutator/template/render_template.cjs +16 -1
  61. package/dist/mutator/template/render_template.cjs.map +1 -1
  62. package/dist/mutator/template/render_template.d.ts +12 -1
  63. package/dist/mutator/template/render_template.d.ts.map +1 -1
  64. package/dist/mutator/template/render_template.js +16 -2
  65. package/dist/mutator/template/render_template.js.map +1 -1
  66. package/package.json +16 -16
  67. package/src/middle_layer/block.ts +4 -1
  68. package/src/middle_layer/block_action_context.test.ts +148 -0
  69. package/src/middle_layer/block_action_context.ts +162 -0
  70. package/src/middle_layer/column_links.test.ts +350 -0
  71. package/src/middle_layer/column_links.ts +152 -0
  72. package/src/middle_layer/index.ts +6 -0
  73. package/src/middle_layer/middle_layer.ts +2 -0
  74. package/src/middle_layer/project.ts +52 -5
  75. package/src/middle_layer/project_overview.test.ts +200 -0
  76. package/src/middle_layer/project_overview.ts +82 -28
  77. package/src/model/args.test.ts +39 -1
  78. package/src/model/args_derivation.test.ts +326 -0
  79. package/src/model/args_derivation.ts +194 -0
  80. package/src/model/project_helper.ts +55 -25
  81. package/src/model/project_model.ts +7 -2
  82. package/src/mutator/project-v3.test.ts +105 -1
  83. package/src/mutator/project.ts +128 -37
  84. package/src/mutator/project_action_context.test.ts +178 -0
  85. package/src/mutator/template/render_block.ts +70 -5
  86. package/src/mutator/template/render_template.ts +22 -2
  87. package/src/test/fake_project.ts +222 -0
package/dist/index.cjs CHANGED
@@ -83,6 +83,7 @@ exports.canGrantToEveryone = require_sharing_model.canGrantToEveryone;
83
83
  exports.canImpersonate = require_sharing_model.canImpersonate;
84
84
  exports.checkNetwork = require_network_check.checkNetwork;
85
85
  exports.createRenderTemplate = require_render_template.createRenderTemplate;
86
+ exports.createRenderTemplateWithResource = require_render_template.createRenderTemplateWithResource;
86
87
  exports.decodeEnvelopeData = require_sharing_model.decodeEnvelopeData;
87
88
  exports.deriveGlobalPObjectId = require_data.deriveGlobalPObjectId;
88
89
  exports.deriveLocalPObjectId = require_data.deriveLocalPObjectId;
package/dist/index.d.ts CHANGED
@@ -16,6 +16,7 @@ import { CachedTemplate, ExplicitTemplate, PreparedTemplate, TemplateFromFile, T
16
16
  import { BlockPackExplicit, BlockPackSpecAny, BlockPackSpecPrepared, FrontendFromFolder, FrontendFromFolderData, FrontendFromFolderResourceType, FrontendFromLocalTgz, FrontendFromLocalTgzData, FrontendFromLocalTgzResourceType, FrontendFromUrl, FrontendFromUrlData, FrontendFromUrlResourceType, FrontendSpec } from "./model/block_pack_spec.js";
17
17
  import { TemplateParseOutcome, parseProjectTemplateV1Yaml } from "./model/template_parser.js";
18
18
  import "./model/index.js";
19
+ import { BlockActionContextMode, BlockActionContextNode, BlockActionReading, BlockActionTransition } from "./middle_layer/block_action_context.js";
19
20
  import { Project } from "./middle_layer/project.js";
20
21
  import { DefaultDriverKitOpsPaths, DefaultDriverKitOpsSettings, DefaultMiddleLayerOpsPaths, DefaultMiddleLayerOpsSettings, DriverKitOps, DriverKitOpsConstructor, DriverKitOpsPaths, DriverKitOpsSettings, MiddleLayerDebugOptions, MiddleLayerOps, MiddleLayerOpsConstructor, MiddleLayerOpsPaths, MiddleLayerOpsSettings, TreeSnapshotOps } from "./middle_layer/ops.js";
21
22
  import { MiddleLayerDriverKit, initDriverKit } from "./middle_layer/driver_kit.js";
@@ -26,7 +27,7 @@ import "./middle_layer/index.js";
26
27
  import { CheckNetworkOpts, checkNetwork, initNetworkCheck } from "./network_check/network_check.js";
27
28
  import { TengoTemplateGet, TengoTemplateGetRegistry, TengoTemplateGetTemplate, TengoTemplateGetTemplateURI, TengoTemplatePack, TengoTemplatePackConvert, TengoTemplatePackConvertTemplate, TengoTemplatePackConvertTemplatePack, loadTemplate, prepareTemplateSpec } from "./mutator/template/template_loading.js";
28
29
  import { ACCESS_COUNT_KEY, ACCESS_KEY_PREFIX, GC_ACCESS_THRESHOLD, GC_MAX_ENTRIES, TemplateCacheFieldName, TemplateCacheStat, TemplateCacheType, cacheBlockPackTemplate, dropTemplateCache, flattenTemplateTree, getOrCreateTemplateCache, invalidateTemplateCacheId, loadTemplateCached, runGc } from "./mutator/template/template_cache.js";
29
- import { createRenderTemplate } from "./mutator/template/render_template.js";
30
+ import { createRenderTemplate, createRenderTemplateWithResource } from "./mutator/template/render_template.js";
30
31
  import { duplicateProject } from "./mutator/project.js";
31
32
  import { parseFinalPObjectCollection } from "./pool/p_object_collection.js";
32
33
  import { deriveGlobalPObjectId, deriveLocalPObjectId } from "./pool/data.js";
@@ -36,4 +37,4 @@ export * from "@platforma-sdk/model";
36
37
  export * from "@milaboratories/pl-model-middle-layer";
37
38
  export * from "@milaboratories/pl-deployments";
38
39
  export * from "@milaboratories/pl-client";
39
- export { ACCESS_COUNT_KEY, ACCESS_KEY_PREFIX, type AppliedEntry, type AvailableShare, BlockArgsAuthorKeyPrefix, BlockPackExplicit, type BlockPackProvider, BlockPackRegistry, BlockPackSpecAny, BlockPackSpecPrepared, CachedTemplate, CentralBlockRegistry, CheckNetworkOpts, type CreateProjectFromTemplateOutcome, DefaultDriverKitOpsPaths, DefaultDriverKitOpsSettings, DefaultMiddleLayerOpsPaths, DefaultMiddleLayerOpsSettings, DriverKitOps, DriverKitOpsConstructor, DriverKitOpsPaths, DriverKitOpsSettings, EnvelopeData, EnvelopeFolder, EnvelopeFolderId, EnvelopeFolderProject, type EnvelopeFolderSummary, EnvelopeFolderTemplate, EnvelopeMode, EnvelopePayload, EnvelopePayloadKind, EnvelopeProject, EnvelopeSchemaVersion, EnvelopeSchemaVersionCurrent, type ExactResolution, ExplicitTemplate, type FieldType, FoldersField, type FoldersListing, type FoldersProjectEntry, FoldersResourceType, type FoldersTemplateEntry, FrontendFromFolder, FrontendFromFolderData, FrontendFromFolderResourceType, FrontendFromLocalTgz, FrontendFromLocalTgzData, FrontendFromLocalTgzResourceType, FrontendFromUrl, FrontendFromUrlData, FrontendFromUrlResourceType, FrontendSpec, GC_ACCESS_THRESHOLD, GC_MAX_ENTRIES, HiddenFieldPrefix, type InternalLsDriver, KindAwareRegistry, type KindResolution, MiddleLayer, MiddleLayerDebugOptions, MiddleLayerDriverKit, MiddleLayerOps, MiddleLayerOpsConstructor, MiddleLayerOpsPaths, MiddleLayerOpsSettings, type OutgoingShare, PreparedTemplate, Project, ProjectCreatedTimestamp, type ProjectField, ProjectFieldUuid, type ProjectId, ProjectLastModifiedTimestamp, type ProjectListEntry, ProjectMetaKey, ProjectResourceType, ProjectStructureAuthorKey, ProjectStructureKey, type ProjectTemplateExportOutcome, ProjectsField, ProjectsResourceType, type ResolvedEntry, type ResourceType, type SaveProjectAsTemplateOutcome, SchemaVersionCurrent, SchemaVersionKey, ShareAudience, ShareFolderOptions, ShareHidden, ShareId, ShareOptions, ShareOutcome, ShareProjectsOptions, ShareReplaceOption, ShareTemplateOptions, SharedEnvelopeResourceType, SharingOutboxField, SharingOutboxResourceType, SharingStateField, SharingStateResourceType, type StoredTemplateData, type TemplateApplyProblem, type TemplateApplyReport, TemplateCacheFieldName, TemplateCacheStat, TemplateCacheType, TemplateEntryRejected, type TemplateExportProblem, TemplateFromFile, TemplateFromRegistry, type TemplateId, type TemplateListEntry, type TemplateParseOutcome, type TemplateResolveOutcome, TemplateSpecAny, TemplateSpecPrepared, TemplatesField, TengoTemplateGet, TengoTemplateGetRegistry, TengoTemplateGetTemplate, TengoTemplateGetTemplateURI, TengoTemplatePack, TengoTemplatePackConvert, TengoTemplatePackConvertTemplate, TengoTemplatePackConvertTemplatePack, type TreeSnapshotMiss, TreeSnapshotOps, type TreeSnapshotStat, V1CentralDevSnapshotRegistry, V1CentralRegistry, V2RegistryProvider, asShareId, cacheBlockPackTemplate, canGrantToEveryone, canImpersonate, checkNetwork, createRenderTemplate, decodeEnvelopeData, deriveGlobalPObjectId, deriveLocalPObjectId, dropTemplateCache, duplicateProject, envelopeFolderRoot, envelopeProjectMap, flattenTemplateTree, getDevV1PacketMtime, getDevV2PacketMtime, getFromPackV2Mtime, getOrCreateTemplateCache, hiddenField, hiddenFieldShareId, initDriverKit, initNetworkCheck, invalidateTemplateCacheId, isHiddenField, kindCapableRegistryIds, loadTemplate, loadTemplateCached, locationOf, newEnvelopeFolderId, newProjectFieldUuid, newShareId, normalizeEnvelopeData, parseBlockPackName, parseFinalPObjectCollection, parseProjectTemplateV1Yaml, prepareTemplateSpec, resolveTemplateEntries, runGc, stringifyProjectTemplateV1, templateBlockPackProvider };
40
+ export { ACCESS_COUNT_KEY, ACCESS_KEY_PREFIX, type AppliedEntry, type AvailableShare, type BlockActionContextMode, type BlockActionContextNode, type BlockActionReading, type BlockActionTransition, BlockArgsAuthorKeyPrefix, BlockPackExplicit, type BlockPackProvider, BlockPackRegistry, BlockPackSpecAny, BlockPackSpecPrepared, CachedTemplate, CentralBlockRegistry, CheckNetworkOpts, type CreateProjectFromTemplateOutcome, DefaultDriverKitOpsPaths, DefaultDriverKitOpsSettings, DefaultMiddleLayerOpsPaths, DefaultMiddleLayerOpsSettings, DriverKitOps, DriverKitOpsConstructor, DriverKitOpsPaths, DriverKitOpsSettings, EnvelopeData, EnvelopeFolder, EnvelopeFolderId, EnvelopeFolderProject, type EnvelopeFolderSummary, EnvelopeFolderTemplate, EnvelopeMode, EnvelopePayload, EnvelopePayloadKind, EnvelopeProject, EnvelopeSchemaVersion, EnvelopeSchemaVersionCurrent, type ExactResolution, ExplicitTemplate, type FieldType, FoldersField, type FoldersListing, type FoldersProjectEntry, FoldersResourceType, type FoldersTemplateEntry, FrontendFromFolder, FrontendFromFolderData, FrontendFromFolderResourceType, FrontendFromLocalTgz, FrontendFromLocalTgzData, FrontendFromLocalTgzResourceType, FrontendFromUrl, FrontendFromUrlData, FrontendFromUrlResourceType, FrontendSpec, GC_ACCESS_THRESHOLD, GC_MAX_ENTRIES, HiddenFieldPrefix, type InternalLsDriver, KindAwareRegistry, type KindResolution, MiddleLayer, MiddleLayerDebugOptions, MiddleLayerDriverKit, MiddleLayerOps, MiddleLayerOpsConstructor, MiddleLayerOpsPaths, MiddleLayerOpsSettings, type OutgoingShare, PreparedTemplate, Project, ProjectCreatedTimestamp, type ProjectField, ProjectFieldUuid, type ProjectId, ProjectLastModifiedTimestamp, type ProjectListEntry, ProjectMetaKey, ProjectResourceType, ProjectStructureAuthorKey, ProjectStructureKey, type ProjectTemplateExportOutcome, ProjectsField, ProjectsResourceType, type ResolvedEntry, type ResourceType, type SaveProjectAsTemplateOutcome, SchemaVersionCurrent, SchemaVersionKey, ShareAudience, ShareFolderOptions, ShareHidden, ShareId, ShareOptions, ShareOutcome, ShareProjectsOptions, ShareReplaceOption, ShareTemplateOptions, SharedEnvelopeResourceType, SharingOutboxField, SharingOutboxResourceType, SharingStateField, SharingStateResourceType, type StoredTemplateData, type TemplateApplyProblem, type TemplateApplyReport, TemplateCacheFieldName, TemplateCacheStat, TemplateCacheType, TemplateEntryRejected, type TemplateExportProblem, TemplateFromFile, TemplateFromRegistry, type TemplateId, type TemplateListEntry, type TemplateParseOutcome, type TemplateResolveOutcome, TemplateSpecAny, TemplateSpecPrepared, TemplatesField, TengoTemplateGet, TengoTemplateGetRegistry, TengoTemplateGetTemplate, TengoTemplateGetTemplateURI, TengoTemplatePack, TengoTemplatePackConvert, TengoTemplatePackConvertTemplate, TengoTemplatePackConvertTemplatePack, type TreeSnapshotMiss, TreeSnapshotOps, type TreeSnapshotStat, V1CentralDevSnapshotRegistry, V1CentralRegistry, V2RegistryProvider, asShareId, cacheBlockPackTemplate, canGrantToEveryone, canImpersonate, checkNetwork, createRenderTemplate, createRenderTemplateWithResource, decodeEnvelopeData, deriveGlobalPObjectId, deriveLocalPObjectId, dropTemplateCache, duplicateProject, envelopeFolderRoot, envelopeProjectMap, flattenTemplateTree, getDevV1PacketMtime, getDevV2PacketMtime, getFromPackV2Mtime, getOrCreateTemplateCache, hiddenField, hiddenFieldShareId, initDriverKit, initNetworkCheck, invalidateTemplateCacheId, isHiddenField, kindCapableRegistryIds, loadTemplate, loadTemplateCached, locationOf, newEnvelopeFolderId, newProjectFieldUuid, newShareId, normalizeEnvelopeData, parseBlockPackName, parseFinalPObjectCollection, parseProjectTemplateV1Yaml, prepareTemplateSpec, resolveTemplateEntries, runGc, stringifyProjectTemplateV1, templateBlockPackProvider };
package/dist/index.js CHANGED
@@ -7,7 +7,7 @@ import { BlockArgsAuthorKeyPrefix, ProjectCreatedTimestamp, ProjectLastModifiedT
7
7
  import { ProjectsField, ProjectsResourceType } from "./middle_layer/project_list.js";
8
8
  import { TemplatesField } from "./middle_layer/template_list.js";
9
9
  import { FoldersField, FoldersResourceType } from "./middle_layer/folders.js";
10
- import { createRenderTemplate } from "./mutator/template/render_template.js";
10
+ import { createRenderTemplate, createRenderTemplateWithResource } from "./mutator/template/render_template.js";
11
11
  import { TengoTemplateGet, TengoTemplateGetRegistry, TengoTemplateGetTemplate, TengoTemplateGetTemplateURI, TengoTemplatePack, TengoTemplatePackConvert, TengoTemplatePackConvertTemplate, TengoTemplatePackConvertTemplatePack, loadTemplate, prepareTemplateSpec } from "./mutator/template/template_loading.js";
12
12
  import { FrontendFromFolderResourceType, FrontendFromLocalTgzResourceType, FrontendFromUrlResourceType } from "./model/block_pack_spec.js";
13
13
  import { EnvelopeSchemaVersionCurrent, HiddenFieldPrefix, SharedEnvelopeResourceType, SharingOutboxField, SharingOutboxResourceType, SharingStateField, SharingStateResourceType, asShareId, canGrantToEveryone, canImpersonate, decodeEnvelopeData, envelopeFolderRoot, envelopeProjectMap, hiddenField, hiddenFieldShareId, isHiddenField, newEnvelopeFolderId, newProjectFieldUuid, newShareId, normalizeEnvelopeData } from "./model/sharing_model.js";
@@ -30,4 +30,4 @@ export * from "@platforma-sdk/model";
30
30
  export * from "@milaboratories/pl-model-middle-layer";
31
31
  export * from "@milaboratories/pl-deployments";
32
32
  export * from "@milaboratories/pl-client";
33
- export { ACCESS_COUNT_KEY, ACCESS_KEY_PREFIX, BlockArgsAuthorKeyPrefix, BlockPackRegistry, CentralBlockRegistry, DefaultDriverKitOpsPaths, DefaultDriverKitOpsSettings, DefaultMiddleLayerOpsPaths, DefaultMiddleLayerOpsSettings, EnvelopeSchemaVersionCurrent, FoldersField, FoldersResourceType, FrontendFromFolderResourceType, FrontendFromLocalTgzResourceType, FrontendFromUrlResourceType, GC_ACCESS_THRESHOLD, GC_MAX_ENTRIES, HiddenFieldPrefix, MiddleLayer, Project, ProjectCreatedTimestamp, ProjectLastModifiedTimestamp, ProjectMetaKey, ProjectResourceType, ProjectStructureAuthorKey, ProjectStructureKey, ProjectsField, ProjectsResourceType, SchemaVersionCurrent, SchemaVersionKey, SharedEnvelopeResourceType, SharingOutboxField, SharingOutboxResourceType, SharingStateField, SharingStateResourceType, TemplateCacheFieldName, TemplateCacheType, TemplateEntryRejected, TemplatesField, TengoTemplateGet, TengoTemplateGetRegistry, TengoTemplateGetTemplate, TengoTemplateGetTemplateURI, TengoTemplatePack, TengoTemplatePackConvert, TengoTemplatePackConvertTemplate, TengoTemplatePackConvertTemplatePack, V1CentralDevSnapshotRegistry, V1CentralRegistry, V2RegistryProvider, asShareId, cacheBlockPackTemplate, canGrantToEveryone, canImpersonate, checkNetwork, createRenderTemplate, decodeEnvelopeData, deriveGlobalPObjectId, deriveLocalPObjectId, dropTemplateCache, duplicateProject, envelopeFolderRoot, envelopeProjectMap, flattenTemplateTree, getDevV1PacketMtime, getDevV2PacketMtime, getFromPackV2Mtime, getOrCreateTemplateCache, hiddenField, hiddenFieldShareId, initDriverKit, initNetworkCheck, invalidateTemplateCacheId, isHiddenField, kindCapableRegistryIds, loadTemplate, loadTemplateCached, locationOf, newEnvelopeFolderId, newProjectFieldUuid, newShareId, normalizeEnvelopeData, parseBlockPackName, parseFinalPObjectCollection, parseProjectTemplateV1Yaml, prepareTemplateSpec, resolveTemplateEntries, runGc, stringifyProjectTemplateV1, templateBlockPackProvider };
33
+ export { ACCESS_COUNT_KEY, ACCESS_KEY_PREFIX, BlockArgsAuthorKeyPrefix, BlockPackRegistry, CentralBlockRegistry, DefaultDriverKitOpsPaths, DefaultDriverKitOpsSettings, DefaultMiddleLayerOpsPaths, DefaultMiddleLayerOpsSettings, EnvelopeSchemaVersionCurrent, FoldersField, FoldersResourceType, FrontendFromFolderResourceType, FrontendFromLocalTgzResourceType, FrontendFromUrlResourceType, GC_ACCESS_THRESHOLD, GC_MAX_ENTRIES, HiddenFieldPrefix, MiddleLayer, Project, ProjectCreatedTimestamp, ProjectLastModifiedTimestamp, ProjectMetaKey, ProjectResourceType, ProjectStructureAuthorKey, ProjectStructureKey, ProjectsField, ProjectsResourceType, SchemaVersionCurrent, SchemaVersionKey, SharedEnvelopeResourceType, SharingOutboxField, SharingOutboxResourceType, SharingStateField, SharingStateResourceType, TemplateCacheFieldName, TemplateCacheType, TemplateEntryRejected, TemplatesField, TengoTemplateGet, TengoTemplateGetRegistry, TengoTemplateGetTemplate, TengoTemplateGetTemplateURI, TengoTemplatePack, TengoTemplatePackConvert, TengoTemplatePackConvertTemplate, TengoTemplatePackConvertTemplatePack, V1CentralDevSnapshotRegistry, V1CentralRegistry, V2RegistryProvider, asShareId, cacheBlockPackTemplate, canGrantToEveryone, canImpersonate, checkNetwork, createRenderTemplate, createRenderTemplateWithResource, decodeEnvelopeData, deriveGlobalPObjectId, deriveLocalPObjectId, dropTemplateCache, duplicateProject, envelopeFolderRoot, envelopeProjectMap, flattenTemplateTree, getDevV1PacketMtime, getDevV2PacketMtime, getFromPackV2Mtime, getOrCreateTemplateCache, hiddenField, hiddenFieldShareId, initDriverKit, initNetworkCheck, invalidateTemplateCacheId, isHiddenField, kindCapableRegistryIds, loadTemplate, loadTemplateCached, locationOf, newEnvelopeFolderId, newProjectFieldUuid, newShareId, normalizeEnvelopeData, parseBlockPackName, parseFinalPObjectCollection, parseProjectTemplateV1Yaml, prepareTemplateSpec, resolveTemplateEntries, runGc, stringifyProjectTemplateV1, templateBlockPackProvider };
@@ -1 +1 @@
1
- {"version":3,"file":"block.cjs","names":["Computable","resourceIdToString","constructBlockContextArgsOnly","deepFreeze","blockArgsAuthorKey","getDebugFlags","constructBlockContext","ifNotUndef","getBlockPackInfo","computableFromCfgOrRF","extractCodeWithInfo"],"sources":["../../src/middle_layer/block.ts"],"sourcesContent":["import type { PlTreeEntry } from \"@milaboratories/pl-tree\";\nimport type {\n ComputableCtx,\n ComputableStableDefined,\n ComputableValueOrErrors,\n} from \"@milaboratories/computable\";\nimport { Computable } from \"@milaboratories/computable\";\nimport { constructBlockContext, constructBlockContextArgsOnly } from \"./block_ctx\";\nimport { blockArgsAuthorKey } from \"../model/project_model\";\nimport { ifNotUndef } from \"../cfg_render/util\";\nimport type { MiddleLayerEnvironment } from \"./middle_layer\";\nimport { getBlockPackInfo } from \"./util\";\nimport type { AuthorMarker, BlockStateInternalV3 } from \"@milaboratories/pl-model-middle-layer\";\nimport { computableFromCfgOrRF } from \"./render\";\nimport { resourceIdToString } from \"@milaboratories/pl-client\";\nimport { deepFreeze } from \"@milaboratories/ts-helpers\";\nimport { extractCodeWithInfo } from \"@platforma-sdk/model\";\nimport { getDebugFlags } from \"../debug\";\n\nexport type BlockParameters = Omit<BlockStateInternalV3, \"outputs\" | \"navigationState\">;\n\nexport function getBlockParameters(\n projectEntry: PlTreeEntry,\n blockId: string,\n): Computable<BlockParameters>;\nexport function getBlockParameters(\n projectEntry: PlTreeEntry,\n blockId: string,\n cCtx: ComputableCtx,\n): BlockParameters;\nexport function getBlockParameters(\n projectEntry: PlTreeEntry,\n blockId: string,\n cCtx?: ComputableCtx,\n): BlockParameters | Computable<BlockParameters> {\n if (cCtx === undefined)\n return Computable.make((c) => getBlockParameters(projectEntry, blockId, c), {\n key: `inputs#${resourceIdToString(projectEntry.rid)}#${blockId}`,\n });\n\n const prj = cCtx.accessor(projectEntry).node();\n const ctx = constructBlockContextArgsOnly(projectEntry, blockId);\n const blockStorageJson = ctx.blockStorage(cCtx);\n // Parse raw storage JSON - UI will derive data using sdk/model\n const blockStorage =\n blockStorageJson !== undefined ? deepFreeze(JSON.parse(blockStorageJson)) : undefined;\n return {\n author: prj.getKeyValueAsJson<AuthorMarker>(blockArgsAuthorKey(blockId)),\n blockStorage,\n };\n}\n\nexport function blockOutputs(\n projectEntry: PlTreeEntry,\n blockId: string,\n env: MiddleLayerEnvironment,\n): ComputableStableDefined<Record<string, ComputableValueOrErrors<unknown>>> {\n const key = \"outputs#\" + resourceIdToString(projectEntry.rid) + \"#\" + blockId;\n return Computable.make(\n (c) => {\n if (getDebugFlags().logOutputRecalculations) {\n console.log(\n `blockOutput recalculation : ${key} (${c.changeSourceMarker}; ${c.bodyInvocations} invocations)`,\n );\n }\n\n const prj = c.accessor(projectEntry).node();\n const ctx = constructBlockContext(projectEntry, blockId);\n\n return ifNotUndef(getBlockPackInfo(prj, blockId), ({ cfg, bpId, info }) => {\n const outputs: Record<string, Computable<any>> = {};\n for (const [cellId, cellCfg] of Object.entries(cfg.outputs)) {\n const computableOutput = computableFromCfgOrRF(\n env,\n ctx,\n cellCfg,\n extractCodeWithInfo(cfg),\n bpId,\n {},\n info.source,\n );\n outputs[cellId] = Computable.wrapError(computableOutput, 1);\n }\n return outputs;\n });\n },\n { key },\n ).withStableType();\n}\n"],"mappings":";;;;;;;;;;;AA8BA,SAAgB,mBACd,cACA,SACA,MAC+C;CAC/C,IAAI,SAAS,KAAA,GACX,OAAOA,2BAAAA,WAAW,MAAM,MAAM,mBAAmB,cAAc,SAAS,CAAC,GAAG,EAC1E,KAAK,WAAA,GAAUC,0BAAAA,mBAAAA,CAAmB,aAAa,GAAG,EAAE,GAAG,UACzD,CAAC;CAEH,MAAM,MAAM,KAAK,SAAS,YAAY,CAAC,CAAC,KAAK;CAE7C,MAAM,mBADMC,kBAAAA,8BAA8B,cAAc,OAC7B,CAAC,CAAC,aAAa,IAAI;CAE9C,MAAM,eACJ,qBAAqB,KAAA,KAAA,GAAYC,2BAAAA,WAAAA,CAAW,KAAK,MAAM,gBAAgB,CAAC,IAAI,KAAA;CAC9E,OAAO;EACL,QAAQ,IAAI,kBAAgCC,sBAAAA,mBAAmB,OAAO,CAAC;EACvE;CACF;AACF;AAEA,SAAgB,aACd,cACA,SACA,KAC2E;CAC3E,MAAM,MAAM,cAAA,GAAaH,0BAAAA,mBAAAA,CAAmB,aAAa,GAAG,IAAI,MAAM;CACtE,OAAOD,2BAAAA,WAAW,MACf,MAAM;EACL,IAAIK,cAAAA,cAAc,CAAC,CAAC,yBAClB,QAAQ,IACN,+BAA+B,IAAI,IAAI,EAAE,mBAAmB,IAAI,EAAE,gBAAgB,cACpF;EAGF,MAAM,MAAM,EAAE,SAAS,YAAY,CAAC,CAAC,KAAK;EAC1C,MAAM,MAAMC,kBAAAA,sBAAsB,cAAc,OAAO;EAEvD,OAAOC,aAAAA,WAAWC,eAAAA,iBAAiB,KAAK,OAAO,IAAI,EAAE,KAAK,MAAM,WAAW;GACzE,MAAM,UAA2C,CAAC;GAClD,KAAK,MAAM,CAAC,QAAQ,YAAY,OAAO,QAAQ,IAAI,OAAO,GAAG;IAC3D,MAAM,mBAAmBC,eAAAA,sBACvB,KACA,KACA,UAAA,GACAC,qBAAAA,oBAAAA,CAAoB,GAAG,GACvB,MACA,CAAC,GACD,KAAK,MACP;IACA,QAAQ,UAAUV,2BAAAA,WAAW,UAAU,kBAAkB,CAAC;GAC5D;GACA,OAAO;EACT,CAAC;CACH,GACA,EAAE,IAAI,CACR,CAAC,CAAC,eAAe;AACnB"}
1
+ {"version":3,"file":"block.cjs","names":["Computable","resourceIdToString","constructBlockContextArgsOnly","deepFreeze","blockArgsAuthorKey","getDebugFlags","constructBlockContext","ifNotUndef","getBlockPackInfo","computableFromCfgOrRF","extractCodeWithInfo"],"sources":["../../src/middle_layer/block.ts"],"sourcesContent":["import type { PlTreeEntry } from \"@milaboratories/pl-tree\";\nimport type {\n ComputableCtx,\n ComputableStableDefined,\n ComputableValueOrErrors,\n} from \"@milaboratories/computable\";\nimport { Computable } from \"@milaboratories/computable\";\nimport { constructBlockContext, constructBlockContextArgsOnly } from \"./block_ctx\";\nimport { blockArgsAuthorKey } from \"../model/project_model\";\nimport { ifNotUndef } from \"../cfg_render/util\";\nimport type { MiddleLayerEnvironment } from \"./middle_layer\";\nimport { getBlockPackInfo } from \"./util\";\nimport type { AuthorMarker, BlockStateInternalV3 } from \"@milaboratories/pl-model-middle-layer\";\nimport { computableFromCfgOrRF } from \"./render\";\nimport { resourceIdToString } from \"@milaboratories/pl-client\";\nimport { deepFreeze } from \"@milaboratories/ts-helpers\";\nimport { extractCodeWithInfo } from \"@platforma-sdk/model\";\nimport { getDebugFlags } from \"../debug\";\n\nexport type BlockParameters = Omit<\n BlockStateInternalV3,\n \"outputs\" | \"navigationState\" | \"columnLinks\"\n>;\n\nexport function getBlockParameters(\n projectEntry: PlTreeEntry,\n blockId: string,\n): Computable<BlockParameters>;\nexport function getBlockParameters(\n projectEntry: PlTreeEntry,\n blockId: string,\n cCtx: ComputableCtx,\n): BlockParameters;\nexport function getBlockParameters(\n projectEntry: PlTreeEntry,\n blockId: string,\n cCtx?: ComputableCtx,\n): BlockParameters | Computable<BlockParameters> {\n if (cCtx === undefined)\n return Computable.make((c) => getBlockParameters(projectEntry, blockId, c), {\n key: `inputs#${resourceIdToString(projectEntry.rid)}#${blockId}`,\n });\n\n const prj = cCtx.accessor(projectEntry).node();\n const ctx = constructBlockContextArgsOnly(projectEntry, blockId);\n const blockStorageJson = ctx.blockStorage(cCtx);\n // Parse raw storage JSON - UI will derive data using sdk/model\n const blockStorage =\n blockStorageJson !== undefined ? deepFreeze(JSON.parse(blockStorageJson)) : undefined;\n return {\n author: prj.getKeyValueAsJson<AuthorMarker>(blockArgsAuthorKey(blockId)),\n blockStorage,\n };\n}\n\nexport function blockOutputs(\n projectEntry: PlTreeEntry,\n blockId: string,\n env: MiddleLayerEnvironment,\n): ComputableStableDefined<Record<string, ComputableValueOrErrors<unknown>>> {\n const key = \"outputs#\" + resourceIdToString(projectEntry.rid) + \"#\" + blockId;\n return Computable.make(\n (c) => {\n if (getDebugFlags().logOutputRecalculations) {\n console.log(\n `blockOutput recalculation : ${key} (${c.changeSourceMarker}; ${c.bodyInvocations} invocations)`,\n );\n }\n\n const prj = c.accessor(projectEntry).node();\n const ctx = constructBlockContext(projectEntry, blockId);\n\n return ifNotUndef(getBlockPackInfo(prj, blockId), ({ cfg, bpId, info }) => {\n const outputs: Record<string, Computable<any>> = {};\n for (const [cellId, cellCfg] of Object.entries(cfg.outputs)) {\n const computableOutput = computableFromCfgOrRF(\n env,\n ctx,\n cellCfg,\n extractCodeWithInfo(cfg),\n bpId,\n {},\n info.source,\n );\n outputs[cellId] = Computable.wrapError(computableOutput, 1);\n }\n return outputs;\n });\n },\n { key },\n ).withStableType();\n}\n"],"mappings":";;;;;;;;;;;AAiCA,SAAgB,mBACd,cACA,SACA,MAC+C;CAC/C,IAAI,SAAS,KAAA,GACX,OAAOA,2BAAAA,WAAW,MAAM,MAAM,mBAAmB,cAAc,SAAS,CAAC,GAAG,EAC1E,KAAK,WAAA,GAAU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names":[],"sources":["../../src/middle_layer/block.ts"],"sourcesContent":["import type { PlTreeEntry } from \"@milaboratories/pl-tree\";\nimport type {\n ComputableCtx,\n ComputableStableDefined,\n ComputableValueOrErrors,\n} from \"@milaboratories/computable\";\nimport { Computable } from \"@milaboratories/computable\";\nimport { constructBlockContext, constructBlockContextArgsOnly } from \"./block_ctx\";\nimport { blockArgsAuthorKey } from \"../model/project_model\";\nimport { ifNotUndef } from \"../cfg_render/util\";\nimport type { MiddleLayerEnvironment } from \"./middle_layer\";\nimport { getBlockPackInfo } from \"./util\";\nimport type { AuthorMarker, BlockStateInternalV3 } from \"@milaboratories/pl-model-middle-layer\";\nimport { computableFromCfgOrRF } from \"./render\";\nimport { resourceIdToString } from \"@milaboratories/pl-client\";\nimport { deepFreeze } from \"@milaboratories/ts-helpers\";\nimport { extractCodeWithInfo } from \"@platforma-sdk/model\";\nimport { getDebugFlags } from \"../debug\";\n\nexport type BlockParameters = Omit<BlockStateInternalV3, \"outputs\" | \"navigationState\">;\n\nexport function getBlockParameters(\n projectEntry: PlTreeEntry,\n blockId: string,\n): Computable<BlockParameters>;\nexport function getBlockParameters(\n projectEntry: PlTreeEntry,\n blockId: string,\n cCtx: ComputableCtx,\n): BlockParameters;\nexport function getBlockParameters(\n projectEntry: PlTreeEntry,\n blockId: string,\n cCtx?: ComputableCtx,\n): BlockParameters | Computable<BlockParameters> {\n if (cCtx === undefined)\n return Computable.make((c) => getBlockParameters(projectEntry, blockId, c), {\n key: `inputs#${resourceIdToString(projectEntry.rid)}#${blockId}`,\n });\n\n const prj = cCtx.accessor(projectEntry).node();\n const ctx = constructBlockContextArgsOnly(projectEntry, blockId);\n const blockStorageJson = ctx.blockStorage(cCtx);\n // Parse raw storage JSON - UI will derive data using sdk/model\n const blockStorage =\n blockStorageJson !== undefined ? deepFreeze(JSON.parse(blockStorageJson)) : undefined;\n return {\n author: prj.getKeyValueAsJson<AuthorMarker>(blockArgsAuthorKey(blockId)),\n blockStorage,\n };\n}\n\nexport function blockOutputs(\n projectEntry: PlTreeEntry,\n blockId: string,\n env: MiddleLayerEnvironment,\n): ComputableStableDefined<Record<string, ComputableValueOrErrors<unknown>>> {\n const key = \"outputs#\" + resourceIdToString(projectEntry.rid) + \"#\" + blockId;\n return Computable.make(\n (c) => {\n if (getDebugFlags().logOutputRecalculations) {\n console.log(\n `blockOutput recalculation : ${key} (${c.changeSourceMarker}; ${c.bodyInvocations} invocations)`,\n );\n }\n\n const prj = c.accessor(projectEntry).node();\n const ctx = constructBlockContext(projectEntry, blockId);\n\n return ifNotUndef(getBlockPackInfo(prj, blockId), ({ cfg, bpId, info }) => {\n const outputs: Record<string, Computable<any>> = {};\n for (const [cellId, cellCfg] of Object.entries(cfg.outputs)) {\n const computableOutput = computableFromCfgOrRF(\n env,\n ctx,\n cellCfg,\n extractCodeWithInfo(cfg),\n bpId,\n {},\n info.source,\n );\n outputs[cellId] = Computable.wrapError(computableOutput, 1);\n }\n return outputs;\n });\n },\n { key },\n ).withStableType();\n}\n"],"mappings":";;;;;;;;;;;AA8BA,SAAgB,mBACd,cACA,SACA,MAC+C;CAC/C,IAAI,SAAS,KAAA,GACX,OAAO,WAAW,MAAM,MAAM,mBAAmB,cAAc,SAAS,CAAC,GAAG,EAC1E,KAAK,UAAU,mBAAmB,aAAa,GAAG,EAAE,GAAG,UACzD,CAAC;CAEH,MAAM,MAAM,KAAK,SAAS,YAAY,CAAC,CAAC,KAAK;CAE7C,MAAM,mBADM,8BAA8B,cAAc,OAC7B,CAAC,CAAC,aAAa,IAAI;CAE9C,MAAM,eACJ,qBAAqB,KAAA,IAAY,WAAW,KAAK,MAAM,gBAAgB,CAAC,IAAI,KAAA;CAC9E,OAAO;EACL,QAAQ,IAAI,kBAAgC,mBAAmB,OAAO,CAAC;EACvE;CACF;AACF;AAEA,SAAgB,aACd,cACA,SACA,KAC2E;CAC3E,MAAM,MAAM,aAAa,mBAAmB,aAAa,GAAG,IAAI,MAAM;CACtE,OAAO,WAAW,MACf,MAAM;EACL,IAAI,cAAc,CAAC,CAAC,yBAClB,QAAQ,IACN,+BAA+B,IAAI,IAAI,EAAE,mBAAmB,IAAI,EAAE,gBAAgB,cACpF;EAGF,MAAM,MAAM,EAAE,SAAS,YAAY,CAAC,CAAC,KAAK;EAC1C,MAAM,MAAM,sBAAsB,cAAc,OAAO;EAEvD,OAAO,WAAW,iBAAiB,KAAK,OAAO,IAAI,EAAE,KAAK,MAAM,WAAW;GACzE,MAAM,UAA2C,CAAC;GAClD,KAAK,MAAM,CAAC,QAAQ,YAAY,OAAO,QAAQ,IAAI,OAAO,GAAG;IAC3D,MAAM,mBAAmB,sBACvB,KACA,KACA,SACA,oBAAoB,GAAG,GACvB,MACA,CAAC,GACD,KAAK,MACP;IACA,QAAQ,UAAU,WAAW,UAAU,kBAAkB,CAAC;GAC5D;GACA,OAAO;EACT,CAAC;CACH,GACA,EAAE,IAAI,CACR,CAAC,CAAC,eAAe;AACnB"}
1
+ {"version":3,"file":"block.js","names":[],"sources":["../../src/middle_layer/block.ts"],"sourcesContent":["import type { PlTreeEntry } from \"@milaboratories/pl-tree\";\nimport type {\n ComputableCtx,\n ComputableStableDefined,\n ComputableValueOrErrors,\n} from \"@milaboratories/computable\";\nimport { Computable } from \"@milaboratories/computable\";\nimport { constructBlockContext, constructBlockContextArgsOnly } from \"./block_ctx\";\nimport { blockArgsAuthorKey } from \"../model/project_model\";\nimport { ifNotUndef } from \"../cfg_render/util\";\nimport type { MiddleLayerEnvironment } from \"./middle_layer\";\nimport { getBlockPackInfo } from \"./util\";\nimport type { AuthorMarker, BlockStateInternalV3 } from \"@milaboratories/pl-model-middle-layer\";\nimport { computableFromCfgOrRF } from \"./render\";\nimport { resourceIdToString } from \"@milaboratories/pl-client\";\nimport { deepFreeze } from \"@milaboratories/ts-helpers\";\nimport { extractCodeWithInfo } from \"@platforma-sdk/model\";\nimport { getDebugFlags } from \"../debug\";\n\nexport type BlockParameters = Omit<\n BlockStateInternalV3,\n \"outputs\" | \"navigationState\" | \"columnLinks\"\n>;\n\nexport function getBlockParameters(\n projectEntry: PlTreeEntry,\n blockId: string,\n): Computable<BlockParameters>;\nexport function getBlockParameters(\n projectEntry: PlTreeEntry,\n blockId: string,\n cCtx: ComputableCtx,\n): BlockParameters;\nexport function getBlockParameters(\n projectEntry: PlTreeEntry,\n blockId: string,\n cCtx?: ComputableCtx,\n): BlockParameters | Computable<BlockParameters> {\n if (cCtx === undefined)\n return Computable.make((c) => getBlockParameters(projectEntry, blockId, c), {\n key: `inputs#${resourceIdToString(projectEntry.rid)}#${blockId}`,\n });\n\n const prj = cCtx.accessor(projectEntry).node();\n const ctx = constructBlockContextArgsOnly(projectEntry, blockId);\n const blockStorageJson = ctx.blockStorage(cCtx);\n // Parse raw storage JSON - UI will derive data using sdk/model\n const blockStorage =\n blockStorageJson !== undefined ? deepFreeze(JSON.parse(blockStorageJson)) : undefined;\n return {\n author: prj.getKeyValueAsJson<AuthorMarker>(blockArgsAuthorKey(blockId)),\n blockStorage,\n };\n}\n\nexport function blockOutputs(\n projectEntry: PlTreeEntry,\n blockId: string,\n env: MiddleLayerEnvironment,\n): ComputableStableDefined<Record<string, ComputableValueOrErrors<unknown>>> {\n const key = \"outputs#\" + resourceIdToString(projectEntry.rid) + \"#\" + blockId;\n return Computable.make(\n (c) => {\n if (getDebugFlags().logOutputRecalculations) {\n console.log(\n `blockOutput recalculation : ${key} (${c.changeSourceMarker}; ${c.bodyInvocations} invocations)`,\n );\n }\n\n const prj = c.accessor(projectEntry).node();\n const ctx = constructBlockContext(projectEntry, blockId);\n\n return ifNotUndef(getBlockPackInfo(prj, blockId), ({ cfg, bpId, info }) => {\n const outputs: Record<string, Computable<any>> = {};\n for (const [cellId, cellCfg] of Object.entries(cfg.outputs)) {\n const computableOutput = computableFromCfgOrRF(\n env,\n ctx,\n cellCfg,\n extractCodeWithInfo(cfg),\n bpId,\n {},\n info.source,\n );\n outputs[cellId] = Computable.wrapError(computableOutput, 1);\n }\n return outputs;\n });\n },\n { key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
+ const require_project_model = require("../model/project_model.cjs");
2
+ let _milaboratories_pl_client = require("@milaboratories/pl-client");
3
+ // src/middle_layer/block_action_context.ts
4
+ const childFieldPrefix = "child/";
5
+ async function readBlockActionContextTree(pl, projectRid, blockId, mode) {
6
+ return await pl.withReadTx("readBlockActionContextTree", async (tx) => {
7
+ const project = await tx.getResourceData(projectRid, true);
8
+ const fieldName = require_project_model.projectFieldName(blockId, mode === "prod" ? "prodActionContext" : "stagingActionContext");
9
+ const actionContextField = project.fields.find((f) => f.name === fieldName);
10
+ if (actionContextField === void 0 || (0, _milaboratories_pl_client.isNullSignedResourceId)(actionContextField.value)) return void 0;
11
+ return await readActionContextNode(tx, actionContextField.value);
12
+ });
13
+ }
14
+ async function readActionContextNode(tx, contextRef) {
15
+ const [context, kvs] = await Promise.all([tx.getResourceData(contextRef, true), tx.listKeyValuesString(contextRef)]);
16
+ const baggage = context.data === void 0 || context.data.length === 0 ? {} : JSON.parse(Buffer.from(context.data).toString());
17
+ const transitions = [];
18
+ const readings = [];
19
+ for (const { key, value } of kvs) {
20
+ const parts = key.split("/");
21
+ if (parts[0] === "transition" && parts.length === 4) {
22
+ const parsed = JSON.parse(value);
23
+ transitions.push({
24
+ namespace: parts[1],
25
+ resource: parts[2],
26
+ timestampNs: parts[3],
27
+ state: parsed.state ?? "",
28
+ detail: parsed.detail ?? "",
29
+ reason: parsed.reason ?? ""
30
+ });
31
+ } else if (parts[0] === "reading" && parts.length === 4) readings.push({
32
+ namespace: parts[1],
33
+ resource: parts[2],
34
+ key: parts[3],
35
+ value
36
+ });
37
+ }
38
+ transitions.sort((a, b) => compareDecimal(a.timestampNs, b.timestampNs));
39
+ const childRefs = [];
40
+ for (const f of context.fields) if (f.name.startsWith(childFieldPrefix) && !(0, _milaboratories_pl_client.isNullSignedResourceId)(f.value)) childRefs.push(f.value);
41
+ const children = await Promise.all(childRefs.map((ref) => readActionContextNode(tx, ref)));
42
+ return {
43
+ contextId: String((0, _milaboratories_pl_client.parseSignedResourceId)(contextRef).globalId),
44
+ resource: transitions.find((t) => t.namespace === "render")?.resource,
45
+ baggage,
46
+ transitions,
47
+ readings,
48
+ children
49
+ };
50
+ }
51
+ /** Compares non-negative decimal integers given as strings. */
52
+ function compareDecimal(a, b) {
53
+ return a.length !== b.length ? a.length - b.length : a < b ? -1 : a > b ? 1 : 0;
54
+ }
55
+ exports.readBlockActionContextTree = readBlockActionContextTree;
56
+
57
+ //# sourceMappingURL=block_action_context.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"block_action_context.cjs","names":["projectFieldName","isNullSignedResourceId","parseSignedResourceId"],"sources":["../../src/middle_layer/block_action_context.ts"],"sourcesContent":["import type {\n KeyValueString,\n OptionalSignedResourceId,\n SignedResourceId,\n} from \"@milaboratories/pl-client\";\nimport { isNullSignedResourceId, parseSignedResourceId } from \"@milaboratories/pl-client\";\nimport { projectFieldName } from \"../model/project_model\";\n\n/** Which render of a block the action context tree belongs to. */\nexport type BlockActionContextMode = \"prod\" | \"staging\";\n\n/** An action transition: transition/<namespace>/<resource>/<ns> in an action context. */\nexport type BlockActionTransition = {\n namespace: string;\n /** The resource that reported, e.g. the render or a command it created. */\n resource: string;\n /** Server clock in nanoseconds when the transition was recorded, as a decimal string. */\n timestampNs: string;\n state: string;\n detail: string;\n reason: string;\n};\n\n/**\n * A reading: reading/<namespace>/<resource>/<key> in an action context. The backend sets it asynchronously:\n * of two readings of one key, the one from the transaction opened later stays.\n */\nexport type BlockActionReading = {\n namespace: string;\n resource: string;\n key: string;\n /** Opaque bytes as UTF-8 text; the reporter owns the format. */\n value: string;\n};\n\n/** One action context: the action context of one render and the renders it created. */\nexport type BlockActionContextNode = {\n /**\n * Global resource ID of this ActionContext resource itself, as a decimal string. Not the ID of the\n * render it describes: that is {@link BlockActionContextNode.resource}. Pass it back to the MCP\n * tool to fetch this node's subtree.\n */\n contextId: string;\n /**\n * The render the context belongs to: the resource of its first transition under namespace \"render\",\n * which the workflow controller records when it evaluates the render.\n * Undefined until that transition is applied, or on a backend without block action context reports.\n */\n resource?: string;\n /** Context baggage: name, block-pack, block-id, run-id and so on. */\n baggage: Record<string, string>;\n /** In time order. */\n transitions: BlockActionTransition[];\n readings: BlockActionReading[];\n children: BlockActionContextNode[];\n};\n\nconst childFieldPrefix = \"child/\";\n\n/**\n * Reads the action context tree of a block render: the root action context the project holds in\n * <blockId>-prodActionContext or <blockId>-stagingActionContext, and every child context under it.\n * Reads the current state in one transaction; it does not watch for changes.\n *\n * @returns undefined when the block has no action context: it was not rendered yet, or the backend\n * does not support block action context.\n */\n/**\n * The part of a read transaction the reader uses: a {@link PlTransaction} satisfies it, and a test\n * can serve it without a backend.\n */\nexport interface ActionContextReadTx {\n getResourceData(\n rId: SignedResourceId,\n loadFields: true,\n ): Promise<{\n readonly data?: Uint8Array;\n readonly fields: readonly { readonly name: string; readonly value: OptionalSignedResourceId }[];\n }>;\n listKeyValuesString(rId: SignedResourceId): Promise<KeyValueString[]>;\n}\n\n/** The part of a client the reader uses: a {@link PlClient} satisfies it. */\nexport interface ActionContextReader {\n withReadTx<T>(name: string, body: (tx: ActionContextReadTx) => Promise<T>): Promise<T>;\n}\n\nexport async function readBlockActionContextTree(\n pl: ActionContextReader,\n projectRid: SignedResourceId,\n blockId: string,\n mode: BlockActionContextMode,\n): Promise<BlockActionContextNode | undefined> {\n return await pl.withReadTx(\"readBlockActionContextTree\", async (tx) => {\n const project = await tx.getResourceData(projectRid, true);\n const fieldName = projectFieldName(\n blockId,\n mode === \"prod\" ? \"prodActionContext\" : \"stagingActionContext\",\n );\n const actionContextField = project.fields.find((f) => f.name === fieldName);\n if (actionContextField === undefined || isNullSignedResourceId(actionContextField.value))\n return undefined;\n\n return await readActionContextNode(tx, actionContextField.value);\n });\n}\n\nasync function readActionContextNode(\n tx: ActionContextReadTx,\n contextRef: SignedResourceId,\n): Promise<BlockActionContextNode> {\n const [context, kvs] = await Promise.all([\n tx.getResourceData(contextRef, true),\n tx.listKeyValuesString(contextRef),\n ]);\n\n const baggage =\n context.data === undefined || context.data.length === 0\n ? {}\n : (JSON.parse(Buffer.from(context.data).toString()) as Record<string, string>);\n\n const transitions: BlockActionTransition[] = [];\n const readings: BlockActionReading[] = [];\n for (const { key, value } of kvs) {\n const parts = key.split(\"/\");\n if (parts[0] === \"transition\" && parts.length === 4) {\n const parsed = JSON.parse(value) as { state?: string; detail?: string; reason?: string };\n transitions.push({\n namespace: parts[1],\n resource: parts[2],\n timestampNs: parts[3],\n state: parsed.state ?? \"\",\n detail: parsed.detail ?? \"\",\n reason: parsed.reason ?? \"\",\n });\n } else if (parts[0] === \"reading\" && parts.length === 4) {\n readings.push({ namespace: parts[1], resource: parts[2], key: parts[3], value });\n }\n }\n transitions.sort((a, b) => compareDecimal(a.timestampNs, b.timestampNs));\n\n const childRefs: SignedResourceId[] = [];\n for (const f of context.fields) {\n if (f.name.startsWith(childFieldPrefix) && !isNullSignedResourceId(f.value))\n childRefs.push(f.value);\n }\n const children = await Promise.all(childRefs.map((ref) => readActionContextNode(tx, ref)));\n\n return {\n contextId: String(parseSignedResourceId(contextRef).globalId),\n resource: transitions.find((t) => t.namespace === \"render\")?.resource,\n baggage,\n transitions,\n readings,\n children,\n };\n}\n\n/** Compares non-negative decimal integers given as strings. */\nfunction compareDecimal(a: string, b: string): number {\n return a.length !== b.length ? a.length - b.length : a < b ? -1 : a > b ? 1 : 0;\n}\n"],"mappings":";;;AAyDA,MAAM,mBAAmB;AA8BzB,eAAsB,2BACpB,IACA,YACA,SACA,MAC6C;CAC7C,OAAO,MAAM,GAAG,WAAW,8BAA8B,OAAO,OAAO;EACrE,MAAM,UAAU,MAAM,GAAG,gBAAgB,YAAY,IAAI;EACzD,MAAM,YAAYA,sBAAAA,iBAChB,SACA,SAAS,SAAS,sBAAsB,sBAC1C;EACA,MAAM,qBAAqB,QAAQ,OAAO,MAAM,MAAM,EAAE,SAAS,SAAS;EAC1E,IAAI,uBAAuB,KAAA,MAAA,GAAaC,0BAAAA,uBAAAA,CA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AAG,CAAC,CAAC;CAEzF,OAAO;EACL,WAAW,QAAA,GAAOC,0BAAAA,sBAAAA,CAAsB,UAAU,CAAC,CAAC,QAAQ;EAC5D,UAAU,YAAY,MAAM,MAAM,EAAE,cAAc,QAAQ,CAAC,EAAE;EAC7D;EACA;EACA;EACA;CACF;AACF;;AAGA,SAAS,eAAe,GAAW,GAAmB;CACpD,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,SAAS,EAAE,SAAS,IAAI,IAAI,KAAK,IAAI,IAAI,IAAI;AAChF"}
@@ -0,0 +1,47 @@
1
+ import { SignedResourceId } from "@milaboratories/pl-client";
2
+ /** Which render of a block the action context tree belongs to. */
3
+ export type BlockActionContextMode = "prod" | "staging";
4
+ /** An action transition: transition/<namespace>/<resource>/<ns> in an action context. */
5
+ export type BlockActionTransition = {
6
+ namespace: string;
7
+ /** The resource that reported, e.g. the render or a command it created. */
8
+ resource: string;
9
+ /** Server clock in nanoseconds when the transition was recorded, as a decimal string. */
10
+ timestampNs: string;
11
+ state: string;
12
+ detail: string;
13
+ reason: string;
14
+ };
15
+ /**
16
+ * A reading: reading/<namespace>/<resource>/<key> in an action context. The backend sets it asynchronously:
17
+ * of two readings of one key, the one from the transaction opened later stays.
18
+ */
19
+ export type BlockActionReading = {
20
+ namespace: string;
21
+ resource: string;
22
+ key: string;
23
+ /** Opaque bytes as UTF-8 text; the reporter owns the format. */
24
+ value: string;
25
+ };
26
+ /** One action context: the action context of one render and the renders it created. */
27
+ export type BlockActionContextNode = {
28
+ /**
29
+ * Global resource ID of this ActionContext resource itself, as a decimal string. Not the ID of the
30
+ * render it describes: that is {@link BlockActionContextNode.resource}. Pass it back to the MCP
31
+ * tool to fetch this node's subtree.
32
+ */
33
+ contextId: string;
34
+ /**
35
+ * The render the context belongs to: the resource of its first transition under namespace "render",
36
+ * which the workflow controller records when it evaluates the render.
37
+ * Undefined until that transition is applied, or on a backend without block action context reports.
38
+ */
39
+ resource?: string;
40
+ /** Context baggage: name, block-pack, block-id, run-id and so on. */
41
+ baggage: Record<string, string>;
42
+ /** In time order. */
43
+ transitions: BlockActionTransition[];
44
+ readings: BlockActionReading[];
45
+ children: BlockActionContextNode[];
46
+ };
47
+ //# sourceMappingURL=block_action_context.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"block_action_context.d.ts","names":[],"sources":["../../src/middle_layer/block_action_context.ts"],"mappings":";;YASY;;YAGA;EACV;;EAEA;;EAEA;EACA;EACA;EACA;;;;;;YAOU;EACV;EACA;EACA;;EAEA;;;YAIU;;;;;;EAMV;;;;;;EAMA;;EAEA,SAAS;;EAET,aAAa;EACb,UAAU;EACV,UAAU"}
@@ -0,0 +1,57 @@
1
+ import { projectFieldName } from "../model/project_model.js";
2
+ import { isNullSignedResourceId, parseSignedResourceId } from "@milaboratories/pl-client";
3
+ // src/middle_layer/block_action_context.ts
4
+ const childFieldPrefix = "child/";
5
+ async function readBlockActionContextTree(pl, projectRid, blockId, mode) {
6
+ return await pl.withReadTx("readBlockActionContextTree", async (tx) => {
7
+ const project = await tx.getResourceData(projectRid, true);
8
+ const fieldName = projectFieldName(blockId, mode === "prod" ? "prodActionContext" : "stagingActionContext");
9
+ const actionContextField = project.fields.find((f) => f.name === fieldName);
10
+ if (actionContextField === void 0 || isNullSignedResourceId(actionContextField.value)) return void 0;
11
+ return await readActionContextNode(tx, actionContextField.value);
12
+ });
13
+ }
14
+ async function readActionContextNode(tx, contextRef) {
15
+ const [context, kvs] = await Promise.all([tx.getResourceData(contextRef, true), tx.listKeyValuesString(contextRef)]);
16
+ const baggage = context.data === void 0 || context.data.length === 0 ? {} : JSON.parse(Buffer.from(context.data).toString());
17
+ const transitions = [];
18
+ const readings = [];
19
+ for (const { key, value } of kvs) {
20
+ const parts = key.split("/");
21
+ if (parts[0] === "transition" && parts.length === 4) {
22
+ const parsed = JSON.parse(value);
23
+ transitions.push({
24
+ namespace: parts[1],
25
+ resource: parts[2],
26
+ timestampNs: parts[3],
27
+ state: parsed.state ?? "",
28
+ detail: parsed.detail ?? "",
29
+ reason: parsed.reason ?? ""
30
+ });
31
+ } else if (parts[0] === "reading" && parts.length === 4) readings.push({
32
+ namespace: parts[1],
33
+ resource: parts[2],
34
+ key: parts[3],
35
+ value
36
+ });
37
+ }
38
+ transitions.sort((a, b) => compareDecimal(a.timestampNs, b.timestampNs));
39
+ const childRefs = [];
40
+ for (const f of context.fields) if (f.name.startsWith(childFieldPrefix) && !isNullSignedResourceId(f.value)) childRefs.push(f.value);
41
+ const children = await Promise.all(childRefs.map((ref) => readActionContextNode(tx, ref)));
42
+ return {
43
+ contextId: String(parseSignedResourceId(contextRef).globalId),
44
+ resource: transitions.find((t) => t.namespace === "render")?.resource,
45
+ baggage,
46
+ transitions,
47
+ readings,
48
+ children
49
+ };
50
+ }
51
+ /** Compares non-negative decimal integers given as strings. */
52
+ function compareDecimal(a, b) {
53
+ return a.length !== b.length ? a.length - b.length : a < b ? -1 : a > b ? 1 : 0;
54
+ }
55
+ export { readBlockActionContextTree };
56
+
57
+ //# sourceMappingURL=block_action_context.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"block_action_context.js","names":[],"sources":["../../src/middle_layer/block_action_context.ts"],"sourcesContent":["import type {\n KeyValueString,\n OptionalSignedResourceId,\n SignedResourceId,\n} from \"@milaboratories/pl-client\";\nimport { isNullSignedResourceId, parseSignedResourceId } from \"@milaboratories/pl-client\";\nimport { projectFieldName } from \"../model/project_model\";\n\n/** Which render of a block the action context tree belongs to. */\nexport type BlockActionContextMode = \"prod\" | \"staging\";\n\n/** An action transition: transition/<namespace>/<resource>/<ns> in an action context. */\nexport type BlockActionTransition = {\n namespace: string;\n /** The resource that reported, e.g. the render or a command it created. */\n resource: string;\n /** Server clock in nanoseconds when the transition was recorded, as a decimal string. */\n timestampNs: string;\n state: string;\n detail: string;\n reason: string;\n};\n\n/**\n * A reading: reading/<namespace>/<resource>/<key> in an action context. The backend sets it asynchronously:\n * of two readings of one key, the one from the transaction opened later stays.\n */\nexport type BlockActionReading = {\n namespace: string;\n resource: string;\n key: string;\n /** Opaque bytes as UTF-8 text; the reporter owns the format. */\n value: string;\n};\n\n/** One action context: the action context of one render and the renders it created. */\nexport type BlockActionContextNode = {\n /**\n * Global resource ID of this ActionContext resource itself, as a decimal string. Not the ID of the\n * render it describes: that is {@link BlockActionContextNode.resource}. Pass it back to the MCP\n * tool to fetch this node's subtree.\n */\n contextId: string;\n /**\n * The render the context belongs to: the resource of its first transition under namespace \"render\",\n * which the workflow controller records when it evaluates the render.\n * Undefined until that transition is applied, or on a backend without block action context reports.\n */\n resource?: string;\n /** Context baggage: name, block-pack, block-id, run-id and so on. */\n baggage: Record<string, string>;\n /** In time order. */\n transitions: BlockActionTransition[];\n readings: BlockActionReading[];\n children: BlockActionContextNode[];\n};\n\nconst childFieldPrefix = \"child/\";\n\n/**\n * Reads the action context tree of a block render: the root action context the project holds in\n * <blockId>-prodActionContext or <blockId>-stagingActionContext, and every child context under it.\n * Reads the current state in one transaction; it does not watch for changes.\n *\n * @returns undefined when the block has no action context: it was not rendered yet, or the backend\n * does not support block action context.\n */\n/**\n * The part of a read transaction the reader uses: a {@link PlTransaction} satisfies it, and a test\n * can serve it without a backend.\n */\nexport interface ActionContextReadTx {\n getResourceData(\n rId: SignedResourceId,\n loadFields: true,\n ): Promise<{\n readonly data?: Uint8Array;\n readonly fields: readonly { readonly name: string; readonly value: OptionalSignedResourceId }[];\n }>;\n listKeyValuesString(rId: SignedResourceId): Promise<KeyValueString[]>;\n}\n\n/** The part of a client the reader uses: a {@link PlClient} satisfies it. */\nexport interface ActionContextReader {\n withReadTx<T>(name: string, body: (tx: ActionContextReadTx) => Promise<T>): Promise<T>;\n}\n\nexport async function readBlockActionContextTree(\n pl: ActionContextReader,\n projectRid: SignedResourceId,\n blockId: string,\n mode: BlockActionContextMode,\n): Promise<BlockActionContextNode | undefined> {\n return await pl.withReadTx(\"readBlockActionContextTree\", async (tx) => {\n const project = await tx.getResourceData(projectRid, true);\n const fieldName = projectFieldName(\n blockId,\n mode === \"prod\" ? \"prodActionContext\" : \"stagingActionContext\",\n );\n const actionContextField = project.fields.find((f) => f.name === fieldName);\n if (actionContextField === undefined || isNullSignedResourceId(actionContextField.value))\n return undefined;\n\n return await readActionContextNode(tx, actionContextField.value);\n });\n}\n\nasync function readActionContextNode(\n tx: ActionContextReadTx,\n contextRef: SignedResourceId,\n): Promise<BlockActionContextNode> {\n const [context, kvs] = await Promise.all([\n tx.getResourceData(contextRef, true),\n tx.listKeyValuesString(contextRef),\n ]);\n\n const baggage =\n context.data === undefined || context.data.length === 0\n ? {}\n : (JSON.parse(Buffer.from(context.data).toString()) as Record<string, string>);\n\n const transitions: BlockActionTransition[] = [];\n const readings: BlockActionReading[] = [];\n for (const { key, value } of kvs) {\n const parts = key.split(\"/\");\n if (parts[0] === \"transition\" && parts.length === 4) {\n const parsed = JSON.parse(value) as { state?: string; detail?: string; reason?: string };\n transitions.push({\n namespace: parts[1],\n resource: parts[2],\n timestampNs: parts[3],\n state: parsed.state ?? \"\",\n detail: parsed.detail ?? \"\",\n reason: parsed.reason ?? \"\",\n });\n } else if (parts[0] === \"reading\" && parts.length === 4) {\n readings.push({ namespace: parts[1], resource: parts[2], key: parts[3], value });\n }\n }\n transitions.sort((a, b) => compareDecimal(a.timestampNs, b.timestampNs));\n\n const childRefs: SignedResourceId[] = [];\n for (const f of context.fields) {\n if (f.name.startsWith(childFieldPrefix) && !isNullSignedResourceId(f.value))\n childRefs.push(f.value);\n }\n const children = await Promise.all(childRefs.map((ref) => readActionContextNode(tx, ref)));\n\n return {\n contextId: String(parseSignedResourceId(contextRef).globalId),\n resource: transitions.find((t) => t.namespace === \"render\")?.resource,\n baggage,\n transitions,\n readings,\n children,\n };\n}\n\n/** Compares non-negative decimal integers given as strings. */\nfunction compareDecimal(a: string, b: string): number {\n return a.length !== b.length ? a.length - b.length : a < b ? -1 : a > b ? 1 : 0;\n}\n"],"mappings":";;;AAyDA,MAAM,mBAAmB;AA8BzB,eAAs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M,eAAe,EAAE,aAAa,EAAE,WAAW,CAAC;CAEvE,MAAM,YAAgC,CAAC;CACvC,KAAK,MAAM,KAAK,QAAQ,QACtB,IAAI,EAAE,KAAK,WAAW,gBAAgB,KAAK,CAAC,uBAAuB,EAAE,KAAK,GACxE,UAAU,KAAK,EAAE,KAAK;CAE1B,MAAM,WAAW,MAAM,QAAQ,IAAI,UAAU,KAAK,QAAQ,sBAAsB,IAAI,GAAG,CAAC,CAAC;CAEzF,OAAO;EACL,WAAW,OAAO,sBAAsB,UAAU,CAAC,CAAC,QAAQ;EAC5D,UAAU,YAAY,MAAM,MAAM,EAAE,cAAc,QAAQ,CAAC,EAAE;EAC7D;EACA;EACA;EACA;CACF;AACF;;AAGA,SAAS,eAAe,GAAW,GAAmB;CACpD,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,SAAS,EAAE,SAAS,IAAI,IAAI,KAAK,IAAI,IAAI,IAAI;AAChF"}
@@ -1,7 +1,7 @@
1
1
  // src/middle_layer/build_stamp.ts
2
2
  function injectedStamp() {
3
3
  try {
4
- return "612998d6a210-dirty-1793801850548";
4
+ return "082d6d37cf86-dirty-1793815175256";
5
5
  } catch {
6
6
  return;
7
7
  }
@@ -1,7 +1,7 @@
1
1
  // src/middle_layer/build_stamp.ts
2
2
  function injectedStamp() {
3
3
  try {
4
- return "612998d6a210-dirty-1793801850521";
4
+ return "082d6d37cf86-dirty-1793815175234";
5
5
  } catch {
6
6
  return;
7
7
  }
@@ -0,0 +1,106 @@
1
+ const require_project_model = require("../model/project_model.cjs");
2
+ const require_project_model_util = require("../model/project_model_util.cjs");
3
+ let _milaboratories_ts_helpers = require("@milaboratories/ts-helpers");
4
+ let _milaboratories_pl_model_common = require("@milaboratories/pl-model-common");
5
+ let _milaboratories_computable = require("@milaboratories/computable");
6
+ // src/middle_layer/column_links.ts
7
+ /**
8
+ * Outputs of other blocks that the args of the block reference, checked against what the last
9
+ * runs of their producers export; `undefined` when they could not be computed. Reads the order
10
+ * of the blocks, the args of the block, and of each producer above it that the args reference:
11
+ * whether it has a last run, the results of that run as far as the referenced columns go, and,
12
+ * only to label a column the run does not export, the results the producer prepares before it
13
+ * is run.
14
+ */
15
+ function blockDependencies(prjEntry, blockId, env) {
16
+ return _milaboratories_computable.Computable.make((ctx) => (0, _milaboratories_pl_model_common.computeDependencies)(columnLinksSource(ctx.accessor(prjEntry).node(), env), blockId), { recover: forgetFailed(env, "dependencies") });
17
+ }
18
+ /**
19
+ * Blocks whose args reference outputs of the block, each reference checked against what the
20
+ * last run of the block exports; `undefined` when they could not be computed. Reads the order of
21
+ * the blocks, the args of the block and of every block below it, and of the block's own runs:
22
+ * whether it has a last run, the results of that run as far as the referenced columns go, and,
23
+ * only to label a column the run does not export, the results it prepares before it is run.
24
+ */
25
+ function blockDependents(prjEntry, blockId, env) {
26
+ return _milaboratories_computable.Computable.make((ctx) => (0, _milaboratories_pl_model_common.computeDependents)(columnLinksSource(ctx.accessor(prjEntry).node(), env), blockId), { recover: forgetFailed(env, "dependents") });
27
+ }
28
+ /**
29
+ * Column links of a block with the blocks they name labelled by their titles in the project
30
+ * overview, the names the project shows; a block the overview has no title for stays unlabelled.
31
+ * `undefined` while either side is not computed.
32
+ */
33
+ function labelBlockColumnLinks(links, blocks) {
34
+ const { blockId, dependencies, dependents } = links;
35
+ if (dependencies === void 0 || dependents === void 0) return void 0;
36
+ const named = /* @__PURE__ */ new Set([...dependencies.map((link) => link.producer.blockId), ...dependents.map((link) => link.holderBlockId)]);
37
+ const labels = {};
38
+ for (const { id, title } of blocks) if (named.has(id) && title !== void 0) labels[id] = title;
39
+ return {
40
+ blockId,
41
+ dependencies,
42
+ dependents,
43
+ labels
44
+ };
45
+ }
46
+ /** Logs why a side of the column links failed; the side is then not computed. */
47
+ function forgetFailed(env, side) {
48
+ return (cause) => {
49
+ env.logger.error(new Error(`Error in column links: ${side}`, { cause }));
50
+ };
51
+ }
52
+ function columnLinksSource(prj, env) {
53
+ const structure = (0, _milaboratories_ts_helpers.notEmpty)(prj.getKeyValueAsJson(require_project_model.ProjectStructureKey));
54
+ return {
55
+ blockIds: [...require_project_model_util.allBlocks(structure)].map(({ id }) => id),
56
+ referencesOf: (blockId, kind) => {
57
+ const args = readArgs(prj, blockId, kind);
58
+ if (args === void 0) return void 0;
59
+ return env.projectHelper.getColumnReferences(args.id, () => args.getDataAsJson());
60
+ },
61
+ lastRunOf: (blockId) => readLastRun(prj, blockId),
62
+ stagingOf: (blockId) => readStaging(prj, blockId)
63
+ };
64
+ }
65
+ /** The project field holding a block's args of each kind. */
66
+ const ARGS_FIELD = {
67
+ current: "currentArgs",
68
+ lastRun: "prodArgs"
69
+ };
70
+ function readArgs(prj, blockId, kind) {
71
+ return prj.traverse({
72
+ field: require_project_model.projectFieldName(blockId, ARGS_FIELD[kind]),
73
+ assertFieldType: "Dynamic",
74
+ stableIfNotFound: true
75
+ });
76
+ }
77
+ /**
78
+ * A block has a last run while it holds the args of that run. The results of the run fail to
79
+ * render when their field, or the result list itself, has an error.
80
+ */
81
+ function readLastRun(prj, blockId) {
82
+ if (readArgs(prj, blockId, "lastRun") === void 0) return { type: "notRun" };
83
+ const ctx = prj.traverseOrError({
84
+ field: require_project_model.projectFieldName(blockId, "prodUiCtx"),
85
+ stableIfNotFound: true
86
+ });
87
+ if (ctx === void 0) return { type: "rendering" };
88
+ if (!ctx.ok || ctx.value.getError() !== void 0) return { type: "failed" };
89
+ return {
90
+ type: "rendered",
91
+ ctx: ctx.value
92
+ };
93
+ }
94
+ /** The results a block prepares before it is run; `undefined` while there are none, or they failed. */
95
+ function readStaging(prj, blockId) {
96
+ const ctx = prj.traverseOrError({
97
+ field: require_project_model.projectFieldName(blockId, "stagingUiCtx"),
98
+ stableIfNotFound: true
99
+ });
100
+ return ctx !== void 0 && ctx.ok ? ctx.value : void 0;
101
+ }
102
+ exports.blockDependencies = blockDependencies;
103
+ exports.blockDependents = blockDependents;
104
+ exports.labelBlockColumnLinks = labelBlockColumnLinks;
105
+
106
+ //# sourceMappingURL=column_links.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"column_links.cjs","names":["Computable","computeDependencies","computeDependents","notEmpty","ProjectStructureKey","allBlocks","projectFieldName"],"sources":["../../src/middle_layer/column_links.ts"],"sourcesContent":["import { Computable } from \"@milaboratories/computable\";\nimport type { PlTreeEntry, PlTreeNodeAccessor } from \"@milaboratories/pl-tree\";\nimport { notEmpty } from \"@milaboratories/ts-helpers\";\nimport {\n computeDependencies,\n computeDependents,\n type BlockColumnLinks,\n type ArgsKind,\n type ColumnLinksSource,\n type ProducerRun,\n type ColumnLink,\n} from \"@milaboratories/pl-model-common\";\nimport type { BlockStateOverview } from \"@milaboratories/pl-model-middle-layer\";\nimport type { ProjectStructure } from \"../model/project_model\";\nimport { ProjectStructureKey, projectFieldName } from \"../model/project_model\";\nimport { allBlocks } from \"../model/project_model_util\";\nimport type { MiddleLayerEnvironment } from \"./middle_layer\";\n\n/** What the column links computables read besides the project tree. */\nexport type ColumnLinksEnv = Pick<MiddleLayerEnvironment, \"projectHelper\" | \"logger\">;\n\n/**\n * Outputs of other blocks that the args of the block reference, checked against what the last\n * runs of their producers export; `undefined` when they could not be computed. Reads the order\n * of the blocks, the args of the block, and of each producer above it that the args reference:\n * whether it has a last run, the results of that run as far as the referenced columns go, and,\n * only to label a column the run does not export, the results the producer prepares before it\n * is run.\n */\nexport function blockDependencies(\n prjEntry: PlTreeEntry,\n blockId: string,\n env: ColumnLinksEnv,\n): Computable<ColumnLink[] | undefined> {\n return Computable.make(\n (ctx) => computeDependencies(columnLinksSource(ctx.accessor(prjEntry).node(), env), blockId),\n { recover: forgetFailed(env, \"dependencies\") },\n );\n}\n\n/**\n * Blocks whose args reference outputs of the block, each reference checked against what the\n * last run of the block exports; `undefined` when they could not be computed. Reads the order of\n * the blocks, the args of the block and of every block below it, and of the block's own runs:\n * whether it has a last run, the results of that run as far as the referenced columns go, and,\n * only to label a column the run does not export, the results it prepares before it is run.\n */\nexport function blockDependents(\n prjEntry: PlTreeEntry,\n blockId: string,\n env: ColumnLinksEnv,\n): Computable<ColumnLink[] | undefined> {\n return Computable.make(\n (ctx) => computeDependents(columnLinksSource(ctx.accessor(prjEntry).node(), env), blockId),\n { recover: forgetFailed(env, \"dependents\") },\n );\n}\n\n/**\n * Column links of a block with the blocks they name labelled by their titles in the project\n * overview, the names the project shows; a block the overview has no title for stays unlabelled.\n * `undefined` while either side is not computed.\n */\nexport function labelBlockColumnLinks(\n links: {\n blockId: string;\n dependencies: undefined | ColumnLink[];\n dependents: undefined | ColumnLink[];\n },\n blocks: readonly Pick<BlockStateOverview, \"id\" | \"title\">[],\n): BlockColumnLinks | undefined {\n const { blockId, dependencies, dependents } = links;\n if (dependencies === undefined || dependents === undefined) return undefined;\n const named = new Set([\n ...dependencies.map((link) => link.producer.blockId),\n ...dependents.map((link) => link.holderBlockId),\n ]);\n const labels: Record<string, string> = {};\n for (const { id, title } of blocks) {\n if (named.has(id) && title !== undefined) labels[id] = title;\n }\n return { blockId, dependencies, dependents, labels };\n}\n\n// Internals\n\n/** Logs why a side of the column links failed; the side is then not computed. */\nfunction forgetFailed(env: ColumnLinksEnv, side: \"dependencies\" | \"dependents\") {\n return (cause: unknown[]): undefined => {\n env.logger.error(new Error(`Error in column links: ${side}`, { cause }));\n return undefined;\n };\n}\n\nfunction columnLinksSource(\n prj: PlTreeNodeAccessor,\n env: ColumnLinksEnv,\n): ColumnLinksSource<PlTreeNodeAccessor> {\n const structure = notEmpty(prj.getKeyValueAsJson<ProjectStructure>(ProjectStructureKey));\n return {\n blockIds: [...allBlocks(structure)].map(({ id }) => id),\n referencesOf: (blockId, kind) => {\n const args = readArgs(prj, blockId, kind);\n if (args === undefined) return undefined;\n return env.projectHelper.getColumnReferences(args.id, () => args.getDataAsJson());\n },\n lastRunOf: (blockId) => readLastRun(prj, blockId),\n stagingOf: (blockId) => readStaging(prj, blockId),\n };\n}\n\n/** The project field holding a block's args of each kind. */\nconst ARGS_FIELD = { current: \"currentArgs\", lastRun: \"prodArgs\" } as const satisfies Record<\n ArgsKind,\n string\n>;\n\nfunction readArgs(\n prj: PlTreeNodeAccessor,\n blockId: string,\n kind: ArgsKind,\n): undefined | PlTreeNodeAccessor {\n return prj.traverse({\n field: projectFieldName(blockId, ARGS_FIELD[kind]),\n assertFieldType: \"Dynamic\",\n stableIfNotFound: true,\n });\n}\n\n/**\n * A block has a last run while it holds the args of that run. The results of the run fail to\n * render when their field, or the result list itself, has an error.\n */\nfunction readLastRun(prj: PlTreeNodeAccessor, blockId: string): ProducerRun<PlTreeNodeAccessor> {\n if (readArgs(prj, blockId, \"lastRun\") === undefined) return { type: \"notRun\" };\n const ctx = prj.traverseOrError({\n field: projectFieldName(blockId, \"prodUiCtx\"),\n stableIfNotFound: true,\n });\n if (ctx === undefined) return { type: \"rendering\" };\n if (!ctx.ok || ctx.value.getError() !== undefined) return { type: \"failed\" };\n return { type: \"rendered\", ctx: ctx.value };\n}\n\n/** The results a block prepares before it is run; `undefined` while there are none, or they failed. */\nfunction readStaging(prj: PlTreeNodeAccessor, blockId: string): undefined | PlTreeNodeAccessor {\n const ctx = prj.traverseOrError({\n field: projectFieldName(blockId, \"stagingUiCtx\"),\n stableIfNotFound: true,\n });\n return ctx !== undefined && ctx.ok ? ctx.value : undefined;\n}\n"],"mappings":";;;;;;;;;;;;;;AA6BA,SAAgB,kBACd,UACA,SACA,KACsC;CACtC,OAAOA,2BAAAA,WAAW,MACf,SAAA,GAAQC,gCAAAA,oBAAAA,CAAoB,kBAAkB,IAAI,SAAS,QAAQ,CAAC,CAAC,KAAK,GAAG,GAAG,GAAG,OAAO,GAC3F,EAAE,SAAS,aAAa,KAAK,cAAc,EAAE,CAC/C;AACF;;;;;;;;AASA,SAAgB,gBACd,UACA,SACA,KACsC;CACtC,OAAOD,2BAAAA,WAAW,MACf,SAAA,GAAQE,gCAAAA,kBAAAA,CAAkB,kBAAkB,IAAI,SAAS,QAAQ,CAAC,CAAC,KAAK,GAAG,GAAG,GAAG,OAA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EAClB,OAAOC,sBAAAA,iBAAiB,SAAS,WAAW,KAAK;EACjD,iBAAiB;EACjB,kBAAkB;CACpB,CAAC;AACH;;;;;AAMA,SAAS,YAAY,KAAyB,SAAkD;CAC9F,IAAI,SAAS,KAAK,SAAS,SAAS,MAAM,KAAA,GAAW,OAAO,EAAE,MAAM,SAAS;CAC7E,MAAM,MAAM,IAAI,gBAAgB;EAC9B,OAAOA,sBAAAA,iBAAiB,SAAS,WAAW;EAC5C,kBAAkB;CACpB,CAAC;CACD,IAAI,QAAQ,KAAA,GAAW,OAAO,EAAE,MAAM,YAAY;CAClD,IAAI,CAAC,IAAI,MAAM,IAAI,MAAM,SAAS,MAAM,KAAA,GAAW,OAAO,EAAE,MAAM,SAAS;CAC3E,OAAO;EAAE,MAAM;EAAY,KAAK,IAAI;CAAM;AAC5C;;AAGA,SAAS,YAAY,KAAyB,SAAiD;CAC7F,MAAM,MAAM,IAAI,gBAAgB;EAC9B,OAAOA,sBAAAA,iBAAiB,SAAS,cAAc;EAC/C,kBAAkB;CACpB,CAAC;CACD,OAAO,QAAQ,KAAA,KAAa,IAAI,KAAK,IAAI,QAAQ,KAAA;AACnD"}
@@ -0,0 +1,104 @@
1
+ import { ProjectStructureKey, projectFieldName } from "../model/project_model.js";
2
+ import { allBlocks } from "../model/project_model_util.js";
3
+ import { notEmpty } from "@milaboratories/ts-helpers";
4
+ import { computeDependencies, computeDependents } from "@milaboratories/pl-model-common";
5
+ import { Computable } from "@milaboratories/computable";
6
+ // src/middle_layer/column_links.ts
7
+ /**
8
+ * Outputs of other blocks that the args of the block reference, checked against what the last
9
+ * runs of their producers export; `undefined` when they could not be computed. Reads the order
10
+ * of the blocks, the args of the block, and of each producer above it that the args reference:
11
+ * whether it has a last run, the results of that run as far as the referenced columns go, and,
12
+ * only to label a column the run does not export, the results the producer prepares before it
13
+ * is run.
14
+ */
15
+ function blockDependencies(prjEntry, blockId, env) {
16
+ return Computable.make((ctx) => computeDependencies(columnLinksSource(ctx.accessor(prjEntry).node(), env), blockId), { recover: forgetFailed(env, "dependencies") });
17
+ }
18
+ /**
19
+ * Blocks whose args reference outputs of the block, each reference checked against what the
20
+ * last run of the block exports; `undefined` when they could not be computed. Reads the order of
21
+ * the blocks, the args of the block and of every block below it, and of the block's own runs:
22
+ * whether it has a last run, the results of that run as far as the referenced columns go, and,
23
+ * only to label a column the run does not export, the results it prepares before it is run.
24
+ */
25
+ function blockDependents(prjEntry, blockId, env) {
26
+ return Computable.make((ctx) => computeDependents(columnLinksSource(ctx.accessor(prjEntry).node(), env), blockId), { recover: forgetFailed(env, "dependents") });
27
+ }
28
+ /**
29
+ * Column links of a block with the blocks they name labelled by their titles in the project
30
+ * overview, the names the project shows; a block the overview has no title for stays unlabelled.
31
+ * `undefined` while either side is not computed.
32
+ */
33
+ function labelBlockColumnLinks(links, blocks) {
34
+ const { blockId, dependencies, dependents } = links;
35
+ if (dependencies === void 0 || dependents === void 0) return void 0;
36
+ const named = /* @__PURE__ */ new Set([...dependencies.map((link) => link.producer.blockId), ...dependents.map((link) => link.holderBlockId)]);
37
+ const labels = {};
38
+ for (const { id, title } of blocks) if (named.has(id) && title !== void 0) labels[id] = title;
39
+ return {
40
+ blockId,
41
+ dependencies,
42
+ dependents,
43
+ labels
44
+ };
45
+ }
46
+ /** Logs why a side of the column links failed; the side is then not computed. */
47
+ function forgetFailed(env, side) {
48
+ return (cause) => {
49
+ env.logger.error(new Error(`Error in column links: ${side}`, { cause }));
50
+ };
51
+ }
52
+ function columnLinksSource(prj, env) {
53
+ const structure = notEmpty(prj.getKeyValueAsJson(ProjectStructureKey));
54
+ return {
55
+ blockIds: [...allBlocks(structure)].map(({ id }) => id),
56
+ referencesOf: (blockId, kind) => {
57
+ const args = readArgs(prj, blockId, kind);
58
+ if (args === void 0) return void 0;
59
+ return env.projectHelper.getColumnReferences(args.id, () => args.getDataAsJson());
60
+ },
61
+ lastRunOf: (blockId) => readLastRun(prj, blockId),
62
+ stagingOf: (blockId) => readStaging(prj, blockId)
63
+ };
64
+ }
65
+ /** The project field holding a block's args of each kind. */
66
+ const ARGS_FIELD = {
67
+ current: "currentArgs",
68
+ lastRun: "prodArgs"
69
+ };
70
+ function readArgs(prj, blockId, kind) {
71
+ return prj.traverse({
72
+ field: projectFieldName(blockId, ARGS_FIELD[kind]),
73
+ assertFieldType: "Dynamic",
74
+ stableIfNotFound: true
75
+ });
76
+ }
77
+ /**
78
+ * A block has a last run while it holds the args of that run. The results of the run fail to
79
+ * render when their field, or the result list itself, has an error.
80
+ */
81
+ function readLastRun(prj, blockId) {
82
+ if (readArgs(prj, blockId, "lastRun") === void 0) return { type: "notRun" };
83
+ const ctx = prj.traverseOrError({
84
+ field: projectFieldName(blockId, "prodUiCtx"),
85
+ stableIfNotFound: true
86
+ });
87
+ if (ctx === void 0) return { type: "rendering" };
88
+ if (!ctx.ok || ctx.value.getError() !== void 0) return { type: "failed" };
89
+ return {
90
+ type: "rendered",
91
+ ctx: ctx.value
92
+ };
93
+ }
94
+ /** The results a block prepares before it is run; `undefined` while there are none, or they failed. */
95
+ function readStaging(prj, blockId) {
96
+ const ctx = prj.traverseOrError({
97
+ field: projectFieldName(blockId, "stagingUiCtx"),
98
+ stableIfNotFound: true
99
+ });
100
+ return ctx !== void 0 && ctx.ok ? ctx.value : void 0;
101
+ }
102
+ export { blockDependencies, blockDependents, labelBlockColumnLinks };
103
+
104
+ //# sourceMappingURL=column_links.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"column_links.js","names":[],"sources":["../../src/middle_layer/column_links.ts"],"sourcesContent":["import { Computable } from \"@milaboratories/computable\";\nimport type { PlTreeEntry, PlTreeNodeAccessor } from \"@milaboratories/pl-tree\";\nimport { notEmpty } from \"@milaboratories/ts-helpers\";\nimport {\n computeDependencies,\n computeDependents,\n type BlockColumnLinks,\n type ArgsKind,\n type ColumnLinksSource,\n type ProducerRun,\n type ColumnLink,\n} from \"@milaboratories/pl-model-common\";\nimport type { BlockStateOverview } from \"@milaboratories/pl-model-middle-layer\";\nimport type { ProjectStructure } from \"../model/project_model\";\nimport { ProjectStructureKey, projectFieldName } from \"../model/project_model\";\nimport { allBlocks } from \"../model/project_model_util\";\nimport type { MiddleLayerEnvironment } from \"./middle_layer\";\n\n/** What the column links computables read besides the project tree. */\nexport type ColumnLinksEnv = Pick<MiddleLayerEnvironment, \"projectHelper\" | \"logger\">;\n\n/**\n * Outputs of other blocks that the args of the block reference, checked against what the last\n * runs of their producers export; `undefined` when they could not be computed. Reads the order\n * of the blocks, the args of the block, and of each producer above it that the args reference:\n * whether it has a last run, the results of that run as far as the referenced columns go, and,\n * only to label a column the run does not export, the results the producer prepares before it\n * is run.\n */\nexport function blockDependencies(\n prjEntry: PlTreeEntry,\n blockId: string,\n env: ColumnLinksEnv,\n): Computable<ColumnLink[] | undefined> {\n return Computable.make(\n (ctx) => computeDependencies(columnLinksSource(ctx.accessor(prjEntry).node(), env), blockId),\n { recover: forgetFailed(env, \"dependencies\") },\n );\n}\n\n/**\n * Blocks whose args reference outputs of the block, each reference checked against what the\n * last run of the block exports; `undefined` when they could not be computed. Reads the order of\n * the blocks, the args of the block and of every block below it, and of the block's own runs:\n * whether it has a last run, the results of that run as far as the referenced columns go, and,\n * only to label a column the run does not export, the results it prepares before it is run.\n */\nexport function blockDependents(\n prjEntry: PlTreeEntry,\n blockId: string,\n env: ColumnLinksEnv,\n): Computable<ColumnLink[] | undefined> {\n return Computable.make(\n (ctx) => computeDependents(columnLinksSource(ctx.accessor(prjEntry).node(), env), blockId),\n { recover: forgetFailed(env, \"dependents\") },\n );\n}\n\n/**\n * Column links of a block with the blocks they name labelled by their titles in the project\n * overview, the names the project shows; a block the overview has no title for stays unlabelled.\n * `undefined` while either side is not computed.\n */\nexport function labelBlockColumnLinks(\n links: {\n blockId: string;\n dependencies: undefined | ColumnLink[];\n dependents: undefined | ColumnLink[];\n },\n blocks: readonly Pick<BlockStateOverview, \"id\" | \"title\">[],\n): BlockColumnLinks | undefined {\n const { blockId, dependencies, dependents } = links;\n if (dependencies === undefined || dependents === undefined) return undefined;\n const named = new Set([\n ...dependencies.map((link) => link.producer.blockId),\n ...dependents.map((link) => link.holderBlockId),\n ]);\n const labels: Record<string, string> = {};\n for (const { id, title } of blocks) {\n if (named.has(id) && title !== undefined) labels[id] = title;\n }\n return { blockId, dependencies, dependents, labels };\n}\n\n// Internals\n\n/** Logs why a side of the column links failed; the side is then not computed. */\nfunction forgetFailed(env: ColumnLinksEnv, side: \"dependencies\" | \"dependents\") {\n return (cause: unknown[]): undefined => {\n env.logger.error(new Error(`Error in column links: ${side}`, { cause }));\n return undefined;\n };\n}\n\nfunction columnLinksSource(\n prj: PlTreeNodeAccessor,\n env: ColumnLinksEnv,\n): ColumnLinksSource<PlTreeNodeAccessor> {\n const structure = notEmpty(prj.getKeyValueAsJson<ProjectStructure>(ProjectStructureKey));\n return {\n blockIds: [...allBlocks(structure)].map(({ id }) => id),\n referencesOf: (blockId, kind) => {\n const args = readArgs(prj, blockId, kind);\n if (args === undefined) return undefined;\n return env.projectHelper.getColumnReferences(args.id, () => args.getDataAsJson());\n },\n lastRunOf: (blockId) => readLastRun(prj, blockId),\n stagingOf: (blockId) => readStaging(prj, blockId),\n };\n}\n\n/** The project field holding a block's args of each kind. */\nconst ARGS_FIELD = { current: \"currentArgs\", lastRun: \"prodArgs\" } as const satisfies Record<\n ArgsKind,\n string\n>;\n\nfunction readArgs(\n prj: PlTreeNodeAccessor,\n blockId: string,\n kind: ArgsKind,\n): undefined | PlTreeNodeAccessor {\n return prj.traverse({\n field: projectFieldName(blockId, ARGS_FIELD[kind]),\n assertFieldType: \"Dynamic\",\n stableIfNotFound: true,\n });\n}\n\n/**\n * A block has a last run while it holds the args of that run. The results of the run fail to\n * render when their field, or the result list itself, has an error.\n */\nfunction readLastRun(prj: PlTreeNodeAccessor, blockId: string): ProducerRun<PlTreeNodeAccessor> {\n if (readArgs(prj, blockId, \"lastRun\") === undefined) return { type: \"notRun\" };\n const ctx = prj.traverseOrError({\n field: projectFieldName(blockId, \"prodUiCtx\"),\n stableIfNotFound: true,\n });\n if (ctx === undefined) return { type: \"rendering\" };\n if (!ctx.ok || ctx.value.getError() !== undefined) return { type: \"failed\" };\n return { type: \"rendered\", ctx: ctx.value };\n}\n\n/** The results a block prepares before it is run; `undefined` while there are none, or they failed. */\nfunction readStaging(prj: PlTreeNodeAccessor, blockId: string): undefined | PlTreeNodeAccessor {\n const ctx = prj.traverseOrError({\n field: projectFieldName(blockId, \"stagingUiCtx\"),\n stableIfNotFound: true,\n });\n return ctx !== undefined && ctx.ok ? ctx.value : undefined;\n}\n"],"mappings":";;;;;;;;;;;;;;AA6BA,SAAgB,kBACd,UACA,SACA,KACsC;CACtC,OAAO,WAAW,MACf,QAAQ,oBAAoB,kBAAkB,IAAI,SAAS,QAAQ,CAAC,CAAC,KAAK,GAAG,GAAG,GAAG,OAAO,GAC3F,EAAE,SAAS,aAAa,KAAK,cAAc,EAAE,CAC/C;AACF;;;;;;;;AASA,SAAgB,gBACd,UACA,SACA,KACsC;CACtC,OAAO,WAAW,MACf,QAAQ,kBAAkB,kBAAkB,IAAI,SAAS,QAAQ,CAAC,CAAC,KAAK,GAAG,GAAG,GAAG,OAAO,GACzF,EAAE,SAAS,aAAa,KAAK,YAAY,EAAE,CAC7C;AACF;;;;;;AAOA,SAAgB,sBACd,OAKA,QAC8B;CAC9B,MAAM,EAAE,SAAS,cAAc,eAAe;CAC9C,IAAI,iBAAiB,KAAA,KAAa,eAAe,KAAA,GAAW,OAAO,KAAA;CACnE,MAAM,wBAAQ,IAAI,IAAI,CACpB,GAAG,aAAa,KAAK,SAAS,KAAK,SAAS,OAAO,GACnD,GAAG,WAAW,KAAK,SAAS,KAAK,aAAa,CAChD,CAAC;CACD,MAAM,SAAiC,CAAC;CACxC,KAAK,MAAM,EAAE,IAAI,WAAW,QAC1B,IAAI,MAAM,IAAI,EAAE,KAAK,UAAU,KAAA,GAAW,OAAO,MAAM;CAEzD,OAAO;EAAE;EAAS;EAAc;EA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