@platforma-sdk/model 1.57.2 → 1.58.1

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 (94) hide show
  1. package/dist/block_migrations.cjs +60 -77
  2. package/dist/block_migrations.cjs.map +1 -1
  3. package/dist/block_migrations.d.ts +35 -32
  4. package/dist/block_migrations.d.ts.map +1 -1
  5. package/dist/block_migrations.js +60 -78
  6. package/dist/block_migrations.js.map +1 -1
  7. package/dist/block_model.cjs +18 -14
  8. package/dist/block_model.cjs.map +1 -1
  9. package/dist/block_model.d.ts +5 -5
  10. package/dist/block_model.d.ts.map +1 -1
  11. package/dist/block_model.js +18 -14
  12. package/dist/block_model.js.map +1 -1
  13. package/dist/block_model_legacy.cjs +1 -0
  14. package/dist/block_model_legacy.cjs.map +1 -1
  15. package/dist/block_model_legacy.d.ts.map +1 -1
  16. package/dist/block_model_legacy.js +1 -0
  17. package/dist/block_model_legacy.js.map +1 -1
  18. package/dist/block_storage.cjs +24 -20
  19. package/dist/block_storage.cjs.map +1 -1
  20. package/dist/block_storage.d.ts +20 -16
  21. package/dist/block_storage.d.ts.map +1 -1
  22. package/dist/block_storage.js +24 -20
  23. package/dist/block_storage.js.map +1 -1
  24. package/dist/block_storage_callbacks.cjs +4 -3
  25. package/dist/block_storage_callbacks.cjs.map +1 -1
  26. package/dist/block_storage_callbacks.d.ts +7 -5
  27. package/dist/block_storage_callbacks.d.ts.map +1 -1
  28. package/dist/block_storage_callbacks.js +4 -3
  29. package/dist/block_storage_callbacks.js.map +1 -1
  30. package/dist/components/PFrameForGraphs.cjs +0 -117
  31. package/dist/components/PFrameForGraphs.cjs.map +1 -1
  32. package/dist/components/PFrameForGraphs.d.ts +3 -5
  33. package/dist/components/PFrameForGraphs.d.ts.map +1 -1
  34. package/dist/components/PFrameForGraphs.js +2 -117
  35. package/dist/components/PFrameForGraphs.js.map +1 -1
  36. package/dist/index.cjs +8 -5
  37. package/dist/index.cjs.map +1 -1
  38. package/dist/index.d.ts +4 -3
  39. package/dist/index.d.ts.map +1 -1
  40. package/dist/index.js +5 -3
  41. package/dist/index.js.map +1 -1
  42. package/dist/package.json.cjs +1 -1
  43. package/dist/package.json.js +1 -1
  44. package/dist/pframe_utils/axes.cjs +131 -0
  45. package/dist/pframe_utils/axes.cjs.map +1 -0
  46. package/dist/pframe_utils/axes.d.ts +15 -0
  47. package/dist/pframe_utils/axes.d.ts.map +1 -0
  48. package/dist/pframe_utils/axes.js +128 -0
  49. package/dist/pframe_utils/axes.js.map +1 -0
  50. package/dist/pframe_utils/columns.cjs +4 -8
  51. package/dist/pframe_utils/columns.cjs.map +1 -1
  52. package/dist/pframe_utils/columns.js +1 -5
  53. package/dist/pframe_utils/columns.js.map +1 -1
  54. package/dist/pframe_utils/index.cjs +0 -3
  55. package/dist/pframe_utils/index.cjs.map +1 -1
  56. package/dist/pframe_utils/index.js +0 -3
  57. package/dist/pframe_utils/index.js.map +1 -1
  58. package/dist/platforma.d.ts +12 -2
  59. package/dist/platforma.d.ts.map +1 -1
  60. package/dist/plugin_handle.cjs +29 -0
  61. package/dist/plugin_handle.cjs.map +1 -0
  62. package/dist/plugin_handle.d.ts +51 -0
  63. package/dist/plugin_handle.d.ts.map +1 -0
  64. package/dist/plugin_handle.js +25 -0
  65. package/dist/plugin_handle.js.map +1 -0
  66. package/dist/plugin_model.cjs +29 -29
  67. package/dist/plugin_model.cjs.map +1 -1
  68. package/dist/plugin_model.d.ts +43 -35
  69. package/dist/plugin_model.d.ts.map +1 -1
  70. package/dist/plugin_model.js +29 -29
  71. package/dist/plugin_model.js.map +1 -1
  72. package/dist/render/api.cjs +9 -5
  73. package/dist/render/api.cjs.map +1 -1
  74. package/dist/render/api.d.ts +11 -5
  75. package/dist/render/api.d.ts.map +1 -1
  76. package/dist/render/api.js +9 -5
  77. package/dist/render/api.js.map +1 -1
  78. package/package.json +6 -6
  79. package/src/block_migrations.test.ts +109 -12
  80. package/src/block_migrations.ts +63 -87
  81. package/src/block_model.ts +34 -20
  82. package/src/block_model_legacy.ts +1 -0
  83. package/src/block_storage.test.ts +11 -10
  84. package/src/block_storage.ts +40 -32
  85. package/src/block_storage_callbacks.ts +12 -10
  86. package/src/components/PFrameForGraphs.ts +4 -167
  87. package/src/index.ts +24 -2
  88. package/src/pframe_utils/axes.ts +175 -0
  89. package/src/pframe_utils/columns.ts +2 -2
  90. package/src/platforma.ts +17 -2
  91. package/src/plugin_handle.ts +85 -0
  92. package/src/plugin_model.test.ts +2 -2
  93. package/src/plugin_model.ts +120 -58
  94. package/src/render/api.ts +21 -11
@@ -1 +1 @@
1
- {"version":3,"file":"block_model_legacy.d.ts","sourceRoot":"","sources":["../src/block_model_legacy.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,kBAAkB,EAClB,YAAY,EAEZ,KAAK,EACL,0BAA0B,EAE3B,MAAM,iCAAiC,CAAC;AACzC,OAAO,KAAK,EAAE,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAGnE,OAAO,KAAK,EAAkC,WAAW,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC5F,OAAO,KAAK,EAAE,yBAAyB,EAAE,oBAAoB,EAAE,MAAM,UAAU,CAAC;AAGhF,OAAO,KAAK,EACV,yBAAyB,EACzB,kBAAkB,EAClB,cAAc,EACd,UAAU,EACV,uBAAuB,EACvB,uBAAuB,EACxB,MAAM,WAAW,CAAC;AAEnB,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAErD,KAAK,oBAAoB,GAAG,SAAS,YAAY,EAAE,CAAC;AAEpD,KAAK,kBAAkB,CAAC,GAAG,SAAS,WAAW,EAAE,IAAI,EAAE,OAAO,IAAI,OAAO,CACvE,GAAG,EACH,YAAY,CAAC,GAAG,EAAE,cAAc,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC,SAAS,oBAAoB,GAAG,IAAI,GAAG,KAAK,CAC7F,CAAC;AAEF,KAAK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,uBAAuB,CAAC,IAAI,EAAE,UAAU,EAAE,OAAO,CAAC,EAAE,OAAO,EAAE,IAAI,CAAC,CACrF;IAEM,IAAI,CACT,UAAU,EAAE,CAAC,GACZ,iBAAiB,CAClB,WAAW,CAAC,IAAI,EAAE,uBAAuB,CAAC,IAAI,EAAE,UAAU,EAAE,OAAO,CAAC,EAAE,OAAO,EAAE,IAAI,CAAC,CACrF;CAgFF"}
@@ -247,6 +247,7 @@ class BlockModel {
247
247
  withStatus: Boolean(isConfigLambda(value) && value.withStatus),
248
248
  },
249
249
  ])),
250
+ pluginIds: [],
250
251
  },
251
252
  };
252
253
  }
@@ -1 +1 @@
1
- {"version":3,"file":"block_model_legacy.js","sources":["../src/block_model_legacy.ts"],"sourcesContent":["import type {\n BlockRenderingMode,\n BlockSection,\n AnyFunction,\n PlRef,\n BlockCodeKnownFeatureFlags,\n BlockConfigContainer,\n} from \"@milaboratories/pl-model-common\";\nimport type { Checked, ConfigResult, TypedConfig } from \"./config\";\nimport { getImmediate } from \"./config\";\nimport { getPlatformaInstance, isInUI, tryRegisterCallback } from \"./internal\";\nimport type { Platforma, PlatformaApiVersion, PlatformaV1, PlatformaV2 } from \"./platforma\";\nimport type { InferRenderFunctionReturn, RenderFunctionLegacy } from \"./render\";\nimport { RenderCtxLegacy } from \"./render\";\nimport { PlatformaSDKVersion } from \"./version\";\nimport type {\n TypedConfigOrConfigLambda,\n ConfigRenderLambda,\n StdCtxArgsOnly,\n DeriveHref,\n ConfigRenderLambdaFlags,\n InferOutputsFromConfigs,\n} from \"./bconfig\";\nimport { downgradeCfgOrLambda, isConfigLambda } from \"./bconfig\";\nimport type { PlatformaExtended } from \"./platforma\";\n\ntype SectionsExpectedType = readonly BlockSection[];\n\ntype SectionsCfgChecked<Cfg extends TypedConfig, Args, UiState> = Checked<\n Cfg,\n ConfigResult<Cfg, StdCtxArgsOnly<Args, UiState>> extends SectionsExpectedType ? true : false\n>;\n\ntype InputsValidExpectedType = boolean;\n\ntype InputsValidCfgChecked<Cfg extends TypedConfig, Args, UiState> = Checked<\n Cfg,\n ConfigResult<Cfg, StdCtxArgsOnly<Args, UiState>> extends InputsValidExpectedType ? true : false\n>;\n\ntype NoOb = Record<string, never>;\n\n/** Main entry point that each block should use in it's \"config\" module. Don't forget\n * to call {@link done()} at the end of configuration. Value returned by this builder must be\n * exported as constant with name \"platforma\" from the \"config\" module. */\nexport class BlockModel<\n Args,\n OutputsCfg extends Record<string, TypedConfigOrConfigLambda>,\n UiState,\n Href extends `/${string}` = \"/\",\n> {\n private constructor(\n private config: {\n readonly renderingMode: BlockRenderingMode;\n readonly initialArgs?: Args;\n readonly initialUiState: UiState;\n readonly outputs: OutputsCfg;\n readonly inputsValid: TypedConfigOrConfigLambda;\n readonly sections: TypedConfigOrConfigLambda;\n readonly title?: ConfigRenderLambda;\n readonly subtitle?: ConfigRenderLambda;\n readonly tags?: ConfigRenderLambda;\n readonly enrichmentTargets?: ConfigRenderLambda;\n readonly featureFlags: BlockCodeKnownFeatureFlags;\n },\n ) {}\n\n public static get INITIAL_BLOCK_FEATURE_FLAGS(): BlockCodeKnownFeatureFlags {\n return {\n supportsLazyState: true,\n requiresUIAPIVersion: 1,\n requiresModelAPIVersion: 1,\n requiresCreatePTable: 2,\n };\n }\n\n /** Initiates configuration builder */\n public static create(renderingMode: BlockRenderingMode): BlockModel<NoOb, {}, NoOb>;\n /** Initiates configuration builder */\n public static create(): BlockModel<NoOb, {}, NoOb>;\n /**\n * Initiates configuration builder\n * @deprecated use create method without generic parameter\n */\n public static create<Args>(renderingMode: BlockRenderingMode): BlockModel<Args, {}, NoOb>;\n /**\n * Initiates configuration builder\n * @deprecated use create method without generic parameter\n */\n public static create<Args>(): BlockModel<Args, {}, NoOb>;\n public static create(renderingMode: BlockRenderingMode = \"Heavy\"): BlockModel<NoOb, {}, NoOb> {\n return new BlockModel<NoOb, {}, NoOb>({\n renderingMode,\n initialUiState: {},\n outputs: {},\n inputsValid: getImmediate(true),\n sections: getImmediate([]),\n featureFlags: BlockModel.INITIAL_BLOCK_FEATURE_FLAGS,\n });\n }\n\n /**\n * Add output cell to the configuration\n *\n * @param key output cell name, that can be later used to retrieve the rendered value\n * @param cfg configuration describing how to render cell value from the blocks\n * workflow outputs\n * @deprecated use lambda-based API\n * */\n public output<const Key extends string, const Cfg extends TypedConfig>(\n key: Key,\n cfg: Cfg,\n ): BlockModel<Args, OutputsCfg & { [K in Key]: Cfg }, UiState, Href>;\n /**\n * Add output cell wrapped with additional status information to the configuration\n *\n * @param key output cell name, that can be later used to retrieve the rendered value\n * @param rf callback calculating output value using context, that allows to access\n * workflows outputs and interact with platforma drivers\n * @param flags additional flags that may alter lambda rendering procedure\n * */\n public output<const Key extends string, const RF extends RenderFunctionLegacy<Args, UiState>>(\n key: Key,\n rf: RF,\n flags: ConfigRenderLambdaFlags & { withStatus: true },\n ): BlockModel<\n Args,\n OutputsCfg & {\n [K in Key]: ConfigRenderLambda<InferRenderFunctionReturn<RF>> & { withStatus: true };\n },\n UiState,\n Href\n >;\n /**\n * Add output cell to the configuration\n *\n * @param key output cell name, that can be later used to retrieve the rendered value\n * @param rf callback calculating output value using context, that allows to access\n * workflows outputs and interact with platforma drivers\n * @param flags additional flags that may alter lambda rendering procedure\n * */\n public output<const Key extends string, const RF extends RenderFunctionLegacy<Args, UiState>>(\n key: Key,\n rf: RF,\n flags?: ConfigRenderLambdaFlags,\n ): BlockModel<\n Args,\n OutputsCfg & { [K in Key]: ConfigRenderLambda<InferRenderFunctionReturn<RF>> },\n UiState,\n Href\n >;\n public output(\n key: string,\n cfgOrRf: TypedConfig | AnyFunction,\n flags: ConfigRenderLambdaFlags = {},\n ): BlockModel<Args, OutputsCfg, UiState, Href> {\n if (typeof cfgOrRf === \"function\") {\n const handle = `output#${key}`;\n tryRegisterCallback(handle, () => cfgOrRf(new RenderCtxLegacy()));\n return new BlockModel({\n ...this.config,\n outputs: {\n ...this.config.outputs,\n [key]: {\n __renderLambda: true,\n handle,\n ...flags,\n },\n },\n });\n } else {\n return new BlockModel({\n ...this.config,\n outputs: {\n ...this.config.outputs,\n [key]: cfgOrRf,\n },\n });\n }\n }\n\n /** Shortcut for {@link output} with retentive flag set to true. */\n public retentiveOutput<\n const Key extends string,\n const RF extends RenderFunctionLegacy<Args, UiState>,\n >(key: Key, rf: RF) {\n return this.output(key, rf, { retentive: true });\n }\n\n /** Shortcut for {@link output} with withStatus flag set to true. */\n public outputWithStatus<\n const Key extends string,\n const RF extends RenderFunctionLegacy<Args, UiState>,\n >(key: Key, rf: RF) {\n return this.output(key, rf, { withStatus: true });\n }\n\n /** Shortcut for {@link output} with retentive and withStatus flags set to true. */\n public retentiveOutputWithStatus<\n const Key extends string,\n const RF extends RenderFunctionLegacy<Args, UiState>,\n >(key: Key, rf: RF) {\n return this.output(key, rf, { retentive: true, withStatus: true });\n }\n\n /** Sets custom configuration predicate on the block args at which block can be executed\n * @deprecated use lambda-based API */\n public argsValid<Cfg extends TypedConfig>(\n cfg: Cfg & InputsValidCfgChecked<Cfg, Args, UiState>,\n ): BlockModel<Args, OutputsCfg, UiState, Href>;\n /** Sets custom configuration predicate on the block args at which block can be executed */\n public argsValid<RF extends RenderFunctionLegacy<Args, UiState, boolean>>(\n rf: RF,\n ): BlockModel<Args, OutputsCfg, UiState, Href>;\n public argsValid(\n cfgOrRf: TypedConfig | AnyFunction,\n ): BlockModel<Args, OutputsCfg, UiState, `/${string}`> {\n if (typeof cfgOrRf === \"function\") {\n tryRegisterCallback(\"inputsValid\", () => cfgOrRf(new RenderCtxLegacy()));\n return new BlockModel<Args, OutputsCfg, UiState>({\n ...this.config,\n inputsValid: {\n __renderLambda: true,\n handle: \"inputsValid\",\n },\n });\n } else {\n return new BlockModel<Args, OutputsCfg, UiState>({\n ...this.config,\n inputsValid: cfgOrRf,\n });\n }\n }\n\n /** Sets the config to generate list of section in the left block overviews panel\n * @deprecated use lambda-based API */\n public sections<const S extends SectionsExpectedType>(\n rf: S,\n ): BlockModel<Args, OutputsCfg, UiState, DeriveHref<S>>;\n /** Sets the config to generate list of section in the left block overviews panel */\n public sections<\n const Ret extends SectionsExpectedType,\n const RF extends RenderFunctionLegacy<Args, UiState, Ret>,\n >(rf: RF): BlockModel<Args, OutputsCfg, UiState, DeriveHref<ReturnType<RF>>>;\n public sections<const Cfg extends TypedConfig>(\n cfg: Cfg & SectionsCfgChecked<Cfg, Args, UiState>,\n ): BlockModel<\n Args,\n OutputsCfg,\n UiState,\n DeriveHref<ConfigResult<Cfg, StdCtxArgsOnly<Args, UiState>>>\n >;\n public sections(\n arrOrCfgOrRf: SectionsExpectedType | TypedConfig | AnyFunction,\n ): BlockModel<Args, OutputsCfg, UiState, `/${string}`> {\n if (Array.isArray(arrOrCfgOrRf)) {\n return this.sections(getImmediate(arrOrCfgOrRf));\n } else if (typeof arrOrCfgOrRf === \"function\") {\n tryRegisterCallback(\"sections\", () => arrOrCfgOrRf(new RenderCtxLegacy()));\n return new BlockModel<Args, OutputsCfg, UiState>({\n ...this.config,\n sections: {\n __renderLambda: true,\n handle: \"sections\",\n },\n });\n } else {\n return new BlockModel<Args, OutputsCfg, UiState>({\n ...this.config,\n sections: arrOrCfgOrRf as TypedConfig,\n });\n }\n }\n\n /** Sets a rendering function to derive block title, shown for the block in the left blocks-overview panel. */\n public title(\n rf: RenderFunctionLegacy<Args, UiState, string>,\n ): BlockModel<Args, OutputsCfg, UiState, Href> {\n tryRegisterCallback(\"title\", () => rf(new RenderCtxLegacy()));\n return new BlockModel<Args, OutputsCfg, UiState, Href>({\n ...this.config,\n title: {\n __renderLambda: true,\n handle: \"title\",\n },\n });\n }\n\n public subtitle(\n rf: RenderFunctionLegacy<Args, UiState, string>,\n ): BlockModel<Args, OutputsCfg, UiState, Href> {\n tryRegisterCallback(\"subtitle\", () => rf(new RenderCtxLegacy()));\n return new BlockModel<Args, OutputsCfg, UiState, Href>({\n ...this.config,\n subtitle: {\n __renderLambda: true,\n handle: \"subtitle\",\n },\n });\n }\n\n public tags(\n rf: RenderFunctionLegacy<Args, UiState, string[]>,\n ): BlockModel<Args, OutputsCfg, UiState, Href> {\n tryRegisterCallback(\"tags\", () => rf(new RenderCtxLegacy()));\n return new BlockModel<Args, OutputsCfg, UiState, Href>({\n ...this.config,\n tags: {\n __renderLambda: true,\n handle: \"tags\",\n },\n });\n }\n\n /**\n * Sets initial args for the block, this value must be specified.\n * @deprecated use {@link withArgs}\n * */\n public initialArgs(value: Args): BlockModel<Args, OutputsCfg, UiState, Href> {\n return this.withArgs(value);\n }\n\n /** Sets initial args for the block, this value must be specified. */\n public withArgs<Args>(initialArgs: Args): BlockModel<Args, OutputsCfg, UiState, Href> {\n return new BlockModel<Args, OutputsCfg, UiState, Href>({\n ...this.config,\n initialArgs,\n });\n }\n\n /** Defines type and sets initial value for block UiState. */\n public withUiState<UiState>(\n initialUiState: UiState,\n ): BlockModel<Args, OutputsCfg, UiState, Href> {\n return new BlockModel<Args, OutputsCfg, UiState, Href>({\n ...this.config,\n initialUiState,\n });\n }\n\n /** Sets or overrides feature flags for the block. */\n public withFeatureFlags(\n flags: Partial<BlockCodeKnownFeatureFlags>,\n ): BlockModel<Args, OutputsCfg, UiState, Href> {\n return new BlockModel<Args, OutputsCfg, UiState, Href>({\n ...this.config,\n featureFlags: {\n ...this.config.featureFlags,\n ...flags,\n },\n });\n }\n\n /**\n * Defines how to derive list of upstream references this block is meant to enrich with its exports from block args.\n * Influences dependency graph construction.\n */\n public enriches(lambda: (args: Args) => PlRef[]): BlockModel<Args, OutputsCfg, UiState, Href> {\n tryRegisterCallback(\"enrichmentTargets\", lambda);\n return new BlockModel<Args, OutputsCfg, UiState, Href>({\n ...this.config,\n enrichmentTargets: {\n __renderLambda: true,\n handle: \"enrichmentTargets\",\n },\n });\n }\n\n public done(\n apiVersion?: 1,\n ): PlatformaExtended<\n PlatformaV1<Args, InferOutputsFromConfigs<Args, OutputsCfg, UiState>, UiState, Href>\n >;\n\n public done(\n apiVersion: 2,\n ): PlatformaExtended<\n PlatformaV2<Args, InferOutputsFromConfigs<Args, OutputsCfg, UiState>, UiState, Href>\n >;\n\n /** Renders all provided block settings into a pre-configured platforma API\n * instance, that can be used in frontend to interact with block state, and\n * other features provided by the platforma to the block. */\n public done(\n apiVersion: PlatformaApiVersion = 1,\n ): PlatformaExtended<\n Platforma<Args, InferOutputsFromConfigs<Args, OutputsCfg, UiState>, UiState, Href>\n > {\n return this.withFeatureFlags({\n ...this.config.featureFlags,\n requiresUIAPIVersion: apiVersion,\n }).#done();\n }\n\n #done(): PlatformaExtended<\n Platforma<Args, InferOutputsFromConfigs<Args, OutputsCfg, UiState>, UiState, Href>\n > {\n if (this.config.initialArgs === undefined) throw new Error(\"Initial arguments not set.\");\n\n const config: BlockConfigContainer = {\n v4: undefined,\n v3: {\n configVersion: 3,\n modelAPIVersion: 1,\n sdkVersion: PlatformaSDKVersion,\n renderingMode: this.config.renderingMode,\n initialArgs: this.config.initialArgs,\n initialUiState: this.config.initialUiState,\n inputsValid: this.config.inputsValid,\n sections: this.config.sections,\n title: this.config.title,\n subtitle: this.config.subtitle,\n tags: this.config.tags,\n outputs: this.config.outputs,\n enrichmentTargets: this.config.enrichmentTargets,\n featureFlags: this.config.featureFlags,\n },\n\n // fields below are added to allow previous desktop versions read generated configs\n sdkVersion: PlatformaSDKVersion,\n renderingMode: this.config.renderingMode,\n initialArgs: this.config.initialArgs,\n inputsValid: downgradeCfgOrLambda(this.config.inputsValid),\n sections: downgradeCfgOrLambda(this.config.sections),\n outputs: Object.fromEntries(\n Object.entries(this.config.outputs).map(([key, value]) => [\n key,\n downgradeCfgOrLambda(value),\n ]),\n ),\n };\n\n globalThis.platformaApiVersion = this.config.featureFlags\n .requiresUIAPIVersion as PlatformaApiVersion;\n\n if (!isInUI())\n // we are in the configuration rendering routine, not in actual UI\n return { config } as any;\n // normal operation inside the UI\n else\n return {\n ...getPlatformaInstance({\n sdkVersion: PlatformaSDKVersion,\n apiVersion: platformaApiVersion,\n }),\n blockModelInfo: {\n outputs: Object.fromEntries(\n Object.entries(this.config.outputs).map(([key, value]) => [\n key,\n {\n withStatus: Boolean(isConfigLambda(value) && value.withStatus),\n },\n ]),\n ),\n },\n };\n }\n}\n"],"names":[],"mappings":";;;;;;;;;;AA0CA;;AAE0E;MAC7D,UAAU,CAAA;AAOX,IAAA,MAAA;AADV,IAAA,WAAA,CACU,MAYP,EAAA;QAZO,IAAA,CAAA,MAAM,GAAN,MAAM;IAab;AAEI,IAAA,WAAW,2BAA2B,GAAA;QAC3C,OAAO;AACL,YAAA,iBAAiB,EAAE,IAAI;AACvB,YAAA,oBAAoB,EAAE,CAAC;AACvB,YAAA,uBAAuB,EAAE,CAAC;AAC1B,YAAA,oBAAoB,EAAE,CAAC;SACxB;IACH;AAgBO,IAAA,OAAO,MAAM,CAAC,aAAA,GAAoC,OAAO,EAAA;QAC9D,OAAO,IAAI,UAAU,CAAiB;YACpC,aAAa;AACb,YAAA,cAAc,EAAE,EAAE;AAClB,YAAA,OAAO,EAAE,EAAE;AACX,YAAA,WAAW,EAAE,YAAY,CAAC,IAAI,CAAC;AAC/B,YAAA,QAAQ,EAAE,YAAY,CAAC,EAAE,CAAC;YAC1B,YAAY,EAAE,UAAU,CAAC,2BAA2B;AACrD,SAAA,CAAC;IACJ;AAoDO,IAAA,MAAM,CACX,GAAW,EACX,OAAkC,EAClC,QAAiC,EAAE,EAAA;AAEnC,QAAA,IAAI,OAAO,OAAO,KAAK,UAAU,EAAE;AACjC,YAAA,MAAM,MAAM,GAAG,CAAA,OAAA,EAAU,GAAG,EAAE;AAC9B,YAAA,mBAAmB,CAAC,MAAM,EAAE,MAAM,OAAO,CAAC,IAAI,eAAe,EAAE,CAAC,CAAC;YACjE,OAAO,IAAI,UAAU,CAAC;gBACpB,GAAG,IAAI,CAAC,MAAM;AACd,gBAAA,OAAO,EAAE;AACP,oBAAA,GAAG,IAAI,CAAC,MAAM,CAAC,OAAO;oBACtB,CAAC,GAAG,GAAG;AACL,wBAAA,cAAc,EAAE,IAAI;wBACpB,MAAM;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AAI,CAAC,MAAM,CAAC,aAAa;AACxC,YAAA,WAAW,EAAE,IAAI,CAAC,MAAM,CAAC,WAAW;YACpC,WAAW,EAAE,oBAAoB,CAAC,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC;YAC1D,QAAQ,EAAE,oBAAoB,CAAC,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC;YACpD,OAAO,EAAE,MAAM,CAAC,WAAW,CACzB,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,KAAK;gBACxD,GAAG;gBACH,oBAAoB,CAAC,KAAK,CAAC;AAC5B,aAAA,CAAC,CACH;SACF;AAED,QAAA,UAAU,CAAC,mBAAmB,GAAG,IAAI,CAAC,MAAM,CAAC;AAC1C,aAAA,oBAA2C;QAE9C,IAAI,CAAC,MAAM,EAAE;;YAEX,OAAO,EAAE,MAAM,EAAS;;;YAGxB,OAAO;AACL,gBAAA,GAAG,oBAAoB,CAAC;AACtB,oBAAA,UAAU,EAAE,mBAAmB;AAC/B,oBAAA,UAAU,EAAE,mBAAmB;iBAChC,CAAC;AACF,gBAAA,cAAc,EAAE;oBACd,OAAO,EAAE,MAAM,CAAC,WAAW,CACzB,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,KAAK;wBACxD,GAAG;AACH,wBAAA;4BACE,UAAU,EAAE,OAAO,CAAC,cAAc,CAAC,KAAK,CAAC,IAAI,KAAK,CAAC,UAAU,CAAC;AAC/D,yBAAA;AACF,qBAAA,CAAC,CACH;AACF,iBAAA;aACF;IACL;AACD;;;;"}
1
+ {"version":3,"file":"block_model_legacy.js","sources":["../src/block_model_legacy.ts"],"sourcesContent":["import type {\n BlockRenderingMode,\n BlockSection,\n AnyFunction,\n PlRef,\n BlockCodeKnownFeatureFlags,\n BlockConfigContainer,\n} from \"@milaboratories/pl-model-common\";\nimport type { Checked, ConfigResult, TypedConfig } from \"./config\";\nimport { getImmediate } from \"./config\";\nimport { getPlatformaInstance, isInUI, tryRegisterCallback } from \"./internal\";\nimport type { Platforma, PlatformaApiVersion, PlatformaV1, PlatformaV2 } from \"./platforma\";\nimport type { InferRenderFunctionReturn, RenderFunctionLegacy } from \"./render\";\nimport { RenderCtxLegacy } from \"./render\";\nimport { PlatformaSDKVersion } from \"./version\";\nimport type {\n TypedConfigOrConfigLambda,\n ConfigRenderLambda,\n StdCtxArgsOnly,\n DeriveHref,\n ConfigRenderLambdaFlags,\n InferOutputsFromConfigs,\n} from \"./bconfig\";\nimport { downgradeCfgOrLambda, isConfigLambda } from \"./bconfig\";\nimport type { PlatformaExtended } from \"./platforma\";\n\ntype SectionsExpectedType = readonly BlockSection[];\n\ntype SectionsCfgChecked<Cfg extends TypedConfig, Args, UiState> = Checked<\n Cfg,\n ConfigResult<Cfg, StdCtxArgsOnly<Args, UiState>> extends SectionsExpectedType ? true : false\n>;\n\ntype InputsValidExpectedType = boolean;\n\ntype InputsValidCfgChecked<Cfg extends TypedConfig, Args, UiState> = Checked<\n Cfg,\n ConfigResult<Cfg, StdCtxArgsOnly<Args, UiState>> extends InputsValidExpectedType ? true : false\n>;\n\ntype NoOb = Record<string, never>;\n\n/** Main entry point that each block should use in it's \"config\" module. Don't forget\n * to call {@link done()} at the end of configuration. Value returned by this builder must be\n * exported as constant with name \"platforma\" from the \"config\" module. */\nexport class BlockModel<\n Args,\n OutputsCfg extends Record<string, TypedConfigOrConfigLambda>,\n UiState,\n Href extends `/${string}` = \"/\",\n> {\n private constructor(\n private config: {\n readonly renderingMode: BlockRenderingMode;\n readonly initialArgs?: Args;\n readonly initialUiState: UiState;\n readonly outputs: OutputsCfg;\n readonly inputsValid: TypedConfigOrConfigLambda;\n readonly sections: TypedConfigOrConfigLambda;\n readonly title?: ConfigRenderLambda;\n readonly subtitle?: ConfigRenderLambda;\n readonly tags?: ConfigRenderLambda;\n readonly enrichmentTargets?: ConfigRenderLambda;\n readonly featureFlags: BlockCodeKnownFeatureFlags;\n },\n ) {}\n\n public static get INITIAL_BLOCK_FEATURE_FLAGS(): BlockCodeKnownFeatureFlags {\n return {\n supportsLazyState: true,\n requiresUIAPIVersion: 1,\n requiresModelAPIVersion: 1,\n requiresCreatePTable: 2,\n };\n }\n\n /** Initiates configuration builder */\n public static create(renderingMode: BlockRenderingMode): BlockModel<NoOb, {}, NoOb>;\n /** Initiates configuration builder */\n public static create(): BlockModel<NoOb, {}, NoOb>;\n /**\n * Initiates configuration builder\n * @deprecated use create method without generic parameter\n */\n public static create<Args>(renderingMode: BlockRenderingMode): BlockModel<Args, {}, NoOb>;\n /**\n * Initiates configuration builder\n * @deprecated use create method without generic parameter\n */\n public static create<Args>(): BlockModel<Args, {}, NoOb>;\n public static create(renderingMode: BlockRenderingMode = \"Heavy\"): BlockModel<NoOb, {}, NoOb> {\n return new BlockModel<NoOb, {}, NoOb>({\n renderingMode,\n initialUiState: {},\n outputs: {},\n inputsValid: getImmediate(true),\n sections: getImmediate([]),\n featureFlags: BlockModel.INITIAL_BLOCK_FEATURE_FLAGS,\n });\n }\n\n /**\n * Add output cell to the configuration\n *\n * @param key output cell name, that can be later used to retrieve the rendered value\n * @param cfg configuration describing how to render cell value from the blocks\n * workflow outputs\n * @deprecated use lambda-based API\n * */\n public output<const Key extends string, const Cfg extends TypedConfig>(\n key: Key,\n cfg: Cfg,\n ): BlockModel<Args, OutputsCfg & { [K in Key]: Cfg }, UiState, Href>;\n /**\n * Add output cell wrapped with additional status information to the configuration\n *\n * @param key output cell name, that can be later used to retrieve the rendered value\n * @param rf callback calculating output value using context, that allows to access\n * workflows outputs and interact with platforma drivers\n * @param flags additional flags that may alter lambda rendering procedure\n * */\n public output<const Key extends string, const RF extends RenderFunctionLegacy<Args, UiState>>(\n key: Key,\n rf: RF,\n flags: ConfigRenderLambdaFlags & { withStatus: true },\n ): BlockModel<\n Args,\n OutputsCfg & {\n [K in Key]: ConfigRenderLambda<InferRenderFunctionReturn<RF>> & { withStatus: true };\n },\n UiState,\n Href\n >;\n /**\n * Add output cell to the configuration\n *\n * @param key output cell name, that can be later used to retrieve the rendered value\n * @param rf callback calculating output value using context, that allows to access\n * workflows outputs and interact with platforma drivers\n * @param flags additional flags that may alter lambda rendering procedure\n * */\n public output<const Key extends string, const RF extends RenderFunctionLegacy<Args, UiState>>(\n key: Key,\n rf: RF,\n flags?: ConfigRenderLambdaFlags,\n ): BlockModel<\n Args,\n OutputsCfg & { [K in Key]: ConfigRenderLambda<InferRenderFunctionReturn<RF>> },\n UiState,\n Href\n >;\n public output(\n key: string,\n cfgOrRf: TypedConfig | AnyFunction,\n flags: ConfigRenderLambdaFlags = {},\n ): BlockModel<Args, OutputsCfg, UiState, Href> {\n if (typeof cfgOrRf === \"function\") {\n const handle = `output#${key}`;\n tryRegisterCallback(handle, () => cfgOrRf(new RenderCtxLegacy()));\n return new BlockModel({\n ...this.config,\n outputs: {\n ...this.config.outputs,\n [key]: {\n __renderLambda: true,\n handle,\n ...flags,\n },\n },\n });\n } else {\n return new BlockModel({\n ...this.config,\n outputs: {\n ...this.config.outputs,\n [key]: cfgOrRf,\n },\n });\n }\n }\n\n /** Shortcut for {@link output} with retentive flag set to true. */\n public retentiveOutput<\n const Key extends string,\n const RF extends RenderFunctionLegacy<Args, UiState>,\n >(key: Key, rf: RF) {\n return this.output(key, rf, { retentive: true });\n }\n\n /** Shortcut for {@link output} with withStatus flag set to true. */\n public outputWithStatus<\n const Key extends string,\n const RF extends RenderFunctionLegacy<Args, UiState>,\n >(key: Key, rf: RF) {\n return this.output(key, rf, { withStatus: true });\n }\n\n /** Shortcut for {@link output} with retentive and withStatus flags set to true. */\n public retentiveOutputWithStatus<\n const Key extends string,\n const RF extends RenderFunctionLegacy<Args, UiState>,\n >(key: Key, rf: RF) {\n return this.output(key, rf, { retentive: true, withStatus: true });\n }\n\n /** Sets custom configuration predicate on the block args at which block can be executed\n * @deprecated use lambda-based API */\n public argsValid<Cfg extends TypedConfig>(\n cfg: Cfg & InputsValidCfgChecked<Cfg, Args, UiState>,\n ): BlockModel<Args, OutputsCfg, UiState, Href>;\n /** Sets custom configuration predicate on the block args at which block can be executed */\n public argsValid<RF extends RenderFunctionLegacy<Args, UiState, boolean>>(\n rf: RF,\n ): BlockModel<Args, OutputsCfg, UiState, Href>;\n public argsValid(\n cfgOrRf: TypedConfig | AnyFunction,\n ): BlockModel<Args, OutputsCfg, UiState, `/${string}`> {\n if (typeof cfgOrRf === \"function\") {\n tryRegisterCallback(\"inputsValid\", () => cfgOrRf(new RenderCtxLegacy()));\n return new BlockModel<Args, OutputsCfg, UiState>({\n ...this.config,\n inputsValid: {\n __renderLambda: true,\n handle: \"inputsValid\",\n },\n });\n } else {\n return new BlockModel<Args, OutputsCfg, UiState>({\n ...this.config,\n inputsValid: cfgOrRf,\n });\n }\n }\n\n /** Sets the config to generate list of section in the left block overviews panel\n * @deprecated use lambda-based API */\n public sections<const S extends SectionsExpectedType>(\n rf: S,\n ): BlockModel<Args, OutputsCfg, UiState, DeriveHref<S>>;\n /** Sets the config to generate list of section in the left block overviews panel */\n public sections<\n const Ret extends SectionsExpectedType,\n const RF extends RenderFunctionLegacy<Args, UiState, Ret>,\n >(rf: RF): BlockModel<Args, OutputsCfg, UiState, DeriveHref<ReturnType<RF>>>;\n public sections<const Cfg extends TypedConfig>(\n cfg: Cfg & SectionsCfgChecked<Cfg, Args, UiState>,\n ): BlockModel<\n Args,\n OutputsCfg,\n UiState,\n DeriveHref<ConfigResult<Cfg, StdCtxArgsOnly<Args, UiState>>>\n >;\n public sections(\n arrOrCfgOrRf: SectionsExpectedType | TypedConfig | AnyFunction,\n ): BlockModel<Args, OutputsCfg, UiState, `/${string}`> {\n if (Array.isArray(arrOrCfgOrRf)) {\n return this.sections(getImmediate(arrOrCfgOrRf));\n } else if (typeof arrOrCfgOrRf === \"function\") {\n tryRegisterCallback(\"sections\", () => arrOrCfgOrRf(new RenderCtxLegacy()));\n return new BlockModel<Args, OutputsCfg, UiState>({\n ...this.config,\n sections: {\n __renderLambda: true,\n handle: \"sections\",\n },\n });\n } else {\n return new BlockModel<Args, OutputsCfg, UiState>({\n ...this.config,\n sections: arrOrCfgOrRf as TypedConfig,\n });\n }\n }\n\n /** Sets a rendering function to derive block title, shown for the block in the left blocks-overview panel. */\n public title(\n rf: RenderFunctionLegacy<Args, UiState, string>,\n ): BlockModel<Args, OutputsCfg, UiState, Href> {\n tryRegisterCallback(\"title\", () => rf(new RenderCtxLegacy()));\n return new BlockModel<Args, OutputsCfg, UiState, Href>({\n ...this.config,\n title: {\n __renderLambda: true,\n handle: \"title\",\n },\n });\n }\n\n public subtitle(\n rf: RenderFunctionLegacy<Args, UiState, string>,\n ): BlockModel<Args, OutputsCfg, UiState, Href> {\n tryRegisterCallback(\"subtitle\", () => rf(new RenderCtxLegacy()));\n return new BlockModel<Args, OutputsCfg, UiState, Href>({\n ...this.config,\n subtitle: {\n __renderLambda: true,\n handle: \"subtitle\",\n },\n });\n }\n\n public tags(\n rf: RenderFunctionLegacy<Args, UiState, string[]>,\n ): BlockModel<Args, OutputsCfg, UiState, Href> {\n tryRegisterCallback(\"tags\", () => rf(new RenderCtxLegacy()));\n return new BlockModel<Args, OutputsCfg, UiState, Href>({\n ...this.config,\n tags: {\n __renderLambda: true,\n handle: \"tags\",\n },\n });\n }\n\n /**\n * Sets initial args for the block, this value must be specified.\n * @deprecated use {@link withArgs}\n * */\n public initialArgs(value: Args): BlockModel<Args, OutputsCfg, UiState, Href> {\n return this.withArgs(value);\n }\n\n /** Sets initial args for the block, this value must be specified. */\n public withArgs<Args>(initialArgs: Args): BlockModel<Args, OutputsCfg, UiState, Href> {\n return new BlockModel<Args, OutputsCfg, UiState, Href>({\n ...this.config,\n initialArgs,\n });\n }\n\n /** Defines type and sets initial value for block UiState. */\n public withUiState<UiState>(\n initialUiState: UiState,\n ): BlockModel<Args, OutputsCfg, UiState, Href> {\n return new BlockModel<Args, OutputsCfg, UiState, Href>({\n ...this.config,\n initialUiState,\n });\n }\n\n /** Sets or overrides feature flags for the block. */\n public withFeatureFlags(\n flags: Partial<BlockCodeKnownFeatureFlags>,\n ): BlockModel<Args, OutputsCfg, UiState, Href> {\n return new BlockModel<Args, OutputsCfg, UiState, Href>({\n ...this.config,\n featureFlags: {\n ...this.config.featureFlags,\n ...flags,\n },\n });\n }\n\n /**\n * Defines how to derive list of upstream references this block is meant to enrich with its exports from block args.\n * Influences dependency graph construction.\n */\n public enriches(lambda: (args: Args) => PlRef[]): BlockModel<Args, OutputsCfg, UiState, Href> {\n tryRegisterCallback(\"enrichmentTargets\", lambda);\n return new BlockModel<Args, OutputsCfg, UiState, Href>({\n ...this.config,\n enrichmentTargets: {\n __renderLambda: true,\n handle: \"enrichmentTargets\",\n },\n });\n }\n\n public done(\n apiVersion?: 1,\n ): PlatformaExtended<\n PlatformaV1<Args, InferOutputsFromConfigs<Args, OutputsCfg, UiState>, UiState, Href>\n >;\n\n public done(\n apiVersion: 2,\n ): PlatformaExtended<\n PlatformaV2<Args, InferOutputsFromConfigs<Args, OutputsCfg, UiState>, UiState, Href>\n >;\n\n /** Renders all provided block settings into a pre-configured platforma API\n * instance, that can be used in frontend to interact with block state, and\n * other features provided by the platforma to the block. */\n public done(\n apiVersion: PlatformaApiVersion = 1,\n ): PlatformaExtended<\n Platforma<Args, InferOutputsFromConfigs<Args, OutputsCfg, UiState>, UiState, Href>\n > {\n return this.withFeatureFlags({\n ...this.config.featureFlags,\n requiresUIAPIVersion: apiVersion,\n }).#done();\n }\n\n #done(): PlatformaExtended<\n Platforma<Args, InferOutputsFromConfigs<Args, OutputsCfg, UiState>, UiState, Href>\n > {\n if (this.config.initialArgs === undefined) throw new Error(\"Initial arguments not set.\");\n\n const config: BlockConfigContainer = {\n v4: undefined,\n v3: {\n configVersion: 3,\n modelAPIVersion: 1,\n sdkVersion: PlatformaSDKVersion,\n renderingMode: this.config.renderingMode,\n initialArgs: this.config.initialArgs,\n initialUiState: this.config.initialUiState,\n inputsValid: this.config.inputsValid,\n sections: this.config.sections,\n title: this.config.title,\n subtitle: this.config.subtitle,\n tags: this.config.tags,\n outputs: this.config.outputs,\n enrichmentTargets: this.config.enrichmentTargets,\n featureFlags: this.config.featureFlags,\n },\n\n // fields below are added to allow previous desktop versions read generated configs\n sdkVersion: PlatformaSDKVersion,\n renderingMode: this.config.renderingMode,\n initialArgs: this.config.initialArgs,\n inputsValid: downgradeCfgOrLambda(this.config.inputsValid),\n sections: downgradeCfgOrLambda(this.config.sections),\n outputs: Object.fromEntries(\n Object.entries(this.config.outputs).map(([key, value]) => [\n key,\n downgradeCfgOrLambda(value),\n ]),\n ),\n };\n\n globalThis.platformaApiVersion = this.config.featureFlags\n .requiresUIAPIVersion as PlatformaApiVersion;\n\n if (!isInUI())\n // we are in the configuration rendering routine, not in actual UI\n return { config } as any;\n // normal operation inside the UI\n else\n return {\n ...getPlatformaInstance({\n sdkVersion: PlatformaSDKVersion,\n apiVersion: platformaApiVersion,\n }),\n blockModelInfo: {\n outputs: Object.fromEntries(\n Object.entries(this.config.outputs).map(([key, value]) => [\n key,\n {\n withStatus: Boolean(isConfigLambda(value) && value.withStatus),\n },\n ]),\n ),\n pluginIds: [],\n },\n };\n }\n}\n"],"names":[],"mappings":";;;;;;;;;;AA0CA;;AAE0E;MAC7D,UAAU,CAAA;AAOX,IAAA,MAAA;AADV,IAAA,WAAA,CACU,MAYP,EAAA;QAZO,IAAA,CAAA,MAAM,GAAN,MAAM;IAab;AAEI,IAAA,WAAW,2BAA2B,GAAA;QAC3C,OAAO;AACL,YAAA,iBAAiB,EAAE,IAAI;AACvB,YAAA,oBAAoB,EAAE,CAAC;AACvB,YAAA,uBAAuB,EAAE,CAAC;AAC1B,YAAA,oBAAoB,EAAE,CAAC;SACxB;IACH;AAgBO,IAAA,OAAO,MAAM,CAAC,aAAA,GAAoC,OAAO,EAAA;QAC9D,OAAO,IAAI,UAA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AC1C,aAAA,oBAA2C;QAE9C,IAAI,CAAC,MAAM,EAAE;;YAEX,OAAO,EAAE,MAAM,EAAS;;;YAGxB,OAAO;AACL,gBAAA,GAAG,oBAAoB,CAAC;AACtB,oBAAA,UAAU,EAAE,mBAAmB;AAC/B,oBAAA,UAAU,EAAE,mBAAmB;iBAChC,CAAC;AACF,gBAAA,cAAc,EAAE;oBACd,OAAO,EAAE,MAAM,CAAC,WAAW,CACzB,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,KAAK;wBACxD,GAAG;AACH,wBAAA;4BACE,UAAU,EAAE,OAAO,CAAC,cAAc,CAAC,KAAK,CAAC,IAAI,KAAK,CAAC,UAAU,CAAC;AAC/D,yBAAA;AACF,qBAAA,CAAC,CACH;AACD,oBAAA,SAAS,EAAE,EAAE;AACd,iBAAA;aACF;IACL;AACD;;;;"}
@@ -27,7 +27,7 @@ const BLOCK_STORAGE_SCHEMA_VERSION = "v1";
27
27
  * Default data version for new blocks without migrations.
28
28
  * Unique identifier ensures blocks are created via DataModel API.
29
29
  */
30
- const DATA_MODEL_DEFAULT_VERSION = "__pl_v1_d4e8f2a1__";
30
+ const DATA_MODEL_LEGACY_VERSION = "__pl_v1_d4e8f2a1__";
31
31
  /**
32
32
  * Type guard to check if a value is a valid BlockStorage object.
33
33
  * Checks for the discriminator key and valid schema version.
@@ -47,10 +47,10 @@ function isBlockStorage(value) {
47
47
  * Creates a BlockStorage with the given initial data
48
48
  *
49
49
  * @param initialData - The initial data value (defaults to empty object)
50
- * @param version - The initial data version key (defaults to DATA_MODEL_DEFAULT_VERSION)
50
+ * @param version - The initial data version key (defaults to DATA_MODEL_LEGACY_VERSION)
51
51
  * @returns A new BlockStorage instance with discriminator key
52
52
  */
53
- function createBlockStorage(initialData = {}, version = DATA_MODEL_DEFAULT_VERSION) {
53
+ function createBlockStorage(initialData = {}, version = DATA_MODEL_LEGACY_VERSION) {
54
54
  return {
55
55
  [BLOCK_STORAGE_KEY]: BLOCK_STORAGE_SCHEMA_VERSION,
56
56
  __dataVersion: version,
@@ -74,7 +74,7 @@ function normalizeBlockStorage(raw) {
74
74
  ...storage,
75
75
  // Fix for early released version where __dataVersion was a number
76
76
  __dataVersion: typeof storage.__dataVersion === "number"
77
- ? DATA_MODEL_DEFAULT_VERSION
77
+ ? DATA_MODEL_LEGACY_VERSION
78
78
  : storage.__dataVersion,
79
79
  // Ensure plugin fields have defaults
80
80
  __pluginRegistry: storage.__pluginRegistry ?? {},
@@ -127,7 +127,7 @@ function updateStorageData(storage, payload) {
127
127
  const { pluginId, value } = payload;
128
128
  const currentPlugins = storage.__plugins ?? {};
129
129
  const existingEntry = currentPlugins[pluginId];
130
- const version = existingEntry?.__dataVersion ?? DATA_MODEL_DEFAULT_VERSION;
130
+ const version = existingEntry?.__dataVersion ?? DATA_MODEL_LEGACY_VERSION;
131
131
  return {
132
132
  ...storage,
133
133
  __plugins: {
@@ -204,32 +204,33 @@ function migrateBlockStorage(storage, config) {
204
204
  const oldPlugins = storage.__plugins ?? {};
205
205
  const oldRegistry = storage.__pluginRegistry ?? {};
206
206
  const newPlugins = {};
207
- for (const [pluginId, pluginName] of Object.entries(newPluginRegistry)) {
208
- const existingEntry = oldPlugins[pluginId];
209
- const existingName = oldRegistry[pluginId];
207
+ for (const [key, pluginName] of Object.entries(newPluginRegistry)) {
208
+ const handle = key;
209
+ const existingEntry = oldPlugins[handle];
210
+ const existingName = oldRegistry[handle];
210
211
  try {
211
212
  if (existingEntry && existingName === pluginName) {
212
213
  // Plugin exists with same type - migrate its data
213
- const migrated = migratePluginData(pluginId, {
214
+ const migrated = migratePluginData(handle, {
214
215
  version: existingEntry.__dataVersion,
215
216
  data: existingEntry.__data,
216
217
  });
217
218
  if (migrated) {
218
- newPlugins[pluginId] = { __dataVersion: migrated.version, __data: migrated.data };
219
+ newPlugins[handle] = { __dataVersion: migrated.version, __data: migrated.data };
219
220
  }
220
221
  // If undefined returned, plugin is intentionally removed
221
222
  }
222
223
  else {
223
224
  // New plugin or type changed - create with initial data
224
- const initial = createPluginData(pluginId);
225
- newPlugins[pluginId] = { __dataVersion: initial.version, __data: initial.data };
225
+ const initial = createPluginData(handle);
226
+ newPlugins[handle] = { __dataVersion: initial.version, __data: initial.data };
226
227
  }
227
228
  }
228
229
  catch (error) {
229
230
  return {
230
231
  success: false,
231
232
  error: error instanceof Error ? error.message : String(error),
232
- failedAt: pluginId,
233
+ failedAt: handle,
233
234
  };
234
235
  }
235
236
  }
@@ -250,22 +251,25 @@ function migrateBlockStorage(storage, config) {
250
251
  * Gets plugin-specific data from block storage.
251
252
  * Accepts raw storage (any format) and normalizes internally.
252
253
  *
254
+ * When called with a typed PluginHandle<F>, the return type is automatically
255
+ * inferred from the factory's phantom `__types.data` field.
256
+ *
253
257
  * @param rawStorage - Raw block storage (may be legacy format or BlockStorage)
254
- * @param pluginId - The plugin instance id
255
- * @returns The plugin data
256
- * @throws If pluginId is not found in storage
258
+ * @param handle - The plugin handle (branded plugin instance id)
259
+ * @returns The plugin data, typed via factory inference
260
+ * @throws If plugin is not found in storage
257
261
  */
258
- function getPluginData(rawStorage, pluginId) {
262
+ function getPluginData(rawStorage, handle) {
259
263
  const storage = normalizeBlockStorage(rawStorage);
260
- const pluginEntry = storage.__plugins?.[pluginId];
264
+ const pluginEntry = storage.__plugins?.[handle];
261
265
  if (!pluginEntry)
262
- throw new Error(`Plugin '${pluginId}' not found in block storage`);
266
+ throw new Error(`Plugin '${handle}' not found in block storage`);
263
267
  return pluginEntry.__data;
264
268
  }
265
269
 
266
270
  exports.BLOCK_STORAGE_KEY = BLOCK_STORAGE_KEY;
267
271
  exports.BLOCK_STORAGE_SCHEMA_VERSION = BLOCK_STORAGE_SCHEMA_VERSION;
268
- exports.DATA_MODEL_DEFAULT_VERSION = DATA_MODEL_DEFAULT_VERSION;
272
+ exports.DATA_MODEL_LEGACY_VERSION = DATA_MODEL_LEGACY_VERSION;
269
273
  exports.createBlockStorage = createBlockStorage;
270
274
  exports.deriveDataFromStorage = deriveDataFromStorage;
271
275
  exports.getPluginData = getPluginData;
@@ -1 +1 @@
1
- {"version":3,"file":"block_storage.cjs","sources":["../src/block_storage.ts"],"sourcesContent":["/**\n * BlockStorage - Typed storage abstraction for block persistent data.\n *\n * This module provides:\n * - A typed structure for block storage with versioning and plugin support\n * - Utility functions for manipulating storage\n * - Handler interfaces for model-level customization\n *\n * @module block_storage\n */\n\nimport type { Branded } from \"@milaboratories/pl-model-common\";\nimport type { DataMigrationResult, DataVersioned } from \"./block_migrations\";\n\n// =============================================================================\n// Core Types\n// =============================================================================\n\n/**\n * Discriminator key for BlockStorage format detection.\n * This unique hash-based key identifies data as BlockStorage vs legacy formats.\n */\nexport const BLOCK_STORAGE_KEY = \"__pl_a7f3e2b9__\";\n\n/**\n * Current BlockStorage schema version.\n * Increment this when the storage structure itself changes (not block state migrations).\n */\nexport const BLOCK_STORAGE_SCHEMA_VERSION = \"v1\";\n\n/**\n * Default data version for new blocks without migrations.\n * Unique identifier ensures blocks are created via DataModel API.\n */\nexport const DATA_MODEL_DEFAULT_VERSION = \"__pl_v1_d4e8f2a1__\";\n\n/**\n * Type for valid schema versions\n */\nexport type BlockStorageSchemaVersion = \"v1\"; // Add 'v2', 'v3', etc. as schema evolves\n\n/**\n * Branded type for plugin names - globally unique plugin type identifiers.\n * Using a branded type enforces explicit casting (`as PluginName`) which makes\n * it easy to find all plugin name definitions in the codebase and verify uniqueness.\n */\nexport type PluginName = Branded<string, \"PluginName\">;\n\n/**\n * Plugin registry - maps pluginId (unique within a block) to pluginName (globally unique plugin type).\n * Using a Record highlights that pluginIds must be unique within a block.\n */\nexport type PluginRegistry = Record<string, PluginName>;\n\n/**\n * Versioned data - used for both block data and plugin data\n */\nexport interface VersionedData<TData = unknown> {\n /** Version of the data, used for migrations */\n __dataVersion: string;\n /** The persistent data */\n __data: TData;\n}\n\n/**\n * Core BlockStorage type that holds:\n * - __pl_a7f3e2b9__: Schema version (discriminator key identifies BlockStorage format)\n * - __dataVersion: Version key for block data migrations\n * - __data: The block's user-facing data (state)\n * - __pluginRegistry: Map from pluginId to pluginName (optional)\n * - __plugins: Plugin-specific data keyed by pluginId (optional)\n */\nexport type BlockStorage<TState = unknown> = {\n /** Schema version - the key itself is the discriminator */\n readonly [BLOCK_STORAGE_KEY]: BlockStorageSchemaVersion;\n /** Registry of plugins: pluginId -> pluginName */\n __pluginRegistry?: PluginRegistry;\n /** Plugin-specific data, keyed by pluginId */\n __plugins?: Record<string, VersionedData<unknown>>;\n} & VersionedData<TState>;\n\n/**\n * Type guard to check if a value is a valid BlockStorage object.\n * Checks for the discriminator key and valid schema version.\n */\nexport function isBlockStorage(value: unknown): value is BlockStorage {\n if (value === null || typeof value !== \"object\") return false;\n const obj = value as Record<string, unknown>;\n const schemaVersion = obj[BLOCK_STORAGE_KEY];\n // Currently only 'v1' is valid, but this allows future versions\n return schemaVersion === \"v1\"; // Add more versions as schema evolves\n}\n\n// =============================================================================\n// Factory Functions\n// =============================================================================\n\n/**\n * Creates a BlockStorage with the given initial data\n *\n * @param initialData - The initial data value (defaults to empty object)\n * @param version - The initial data version key (defaults to DATA_MODEL_DEFAULT_VERSION)\n * @returns A new BlockStorage instance with discriminator key\n */\nexport function createBlockStorage<TState = unknown>(\n initialData: TState = {} as TState,\n version: string = DATA_MODEL_DEFAULT_VERSION,\n): BlockStorage<TState> {\n return {\n [BLOCK_STORAGE_KEY]: BLOCK_STORAGE_SCHEMA_VERSION,\n __dataVersion: version,\n __data: initialData,\n __pluginRegistry: {},\n __plugins: {},\n };\n}\n\n/**\n * Normalizes raw storage data to BlockStorage format.\n * If the input is already a BlockStorage, returns it as-is (with defaults for missing fields).\n * If the input is legacy format (raw state), wraps it in BlockStorage structure.\n *\n * @param raw - Raw storage data (may be legacy format or BlockStorage)\n * @returns Normalized BlockStorage\n */\nexport function normalizeBlockStorage<TState = unknown>(raw: unknown): BlockStorage<TState> {\n if (isBlockStorage(raw)) {\n const storage = raw as BlockStorage<TState>;\n return {\n ...storage,\n // Fix for early released version where __dataVersion was a number\n __dataVersion:\n typeof storage.__dataVersion === \"number\"\n ? DATA_MODEL_DEFAULT_VERSION\n : storage.__dataVersion,\n // Ensure plugin fields have defaults\n __pluginRegistry: storage.__pluginRegistry ?? {},\n __plugins: storage.__plugins ?? {},\n };\n }\n // Legacy format: raw is the state directly\n return createBlockStorage(raw as TState);\n}\n\n// =============================================================================\n// Data Access & Update Functions\n// =============================================================================\n\n/**\n * Gets the data from BlockStorage\n *\n * @param storage - The BlockStorage instance\n * @returns The data value\n */\nexport function getStorageData<TState>(storage: BlockStorage<TState>): TState {\n return storage.__data;\n}\n\n/**\n * Derives data from raw block storage.\n * This function is meant to be called from sdk/ui-vue to extract\n * user-facing data from the raw storage returned by the middle layer.\n *\n * The middle layer returns raw storage (opaque to it), and the UI\n * uses this function to derive the actual data value.\n *\n * @param rawStorage - Raw storage data from middle layer (may be any format)\n * @returns The extracted data value, or undefined if storage is undefined/null\n */\nexport function deriveDataFromStorage<TData = unknown>(rawStorage: unknown): TData {\n // Normalize to BlockStorage format (handles legacy formats too)\n const storage = normalizeBlockStorage<TData>(rawStorage);\n return getStorageData(storage);\n}\n\n/** Payload for storage mutation operations. SDK defines specific operations. */\nexport type MutateStoragePayload<T = unknown> =\n | { operation: \"update-block-data\"; value: T }\n | { operation: \"update-plugin-data\"; pluginId: string; value: unknown };\n\n/**\n * Updates the data in BlockStorage (immutable)\n *\n * @param storage - The current BlockStorage\n * @param payload - The update payload with operation and value\n * @returns A new BlockStorage with updated data\n */\nexport function updateStorageData<TValue = unknown>(\n storage: BlockStorage<TValue>,\n payload: MutateStoragePayload<TValue>,\n): BlockStorage<TValue> {\n switch (payload.operation) {\n case \"update-block-data\":\n return { ...storage, __data: payload.value };\n case \"update-plugin-data\": {\n const { pluginId, value } = payload;\n const currentPlugins = storage.__plugins ?? {};\n const existingEntry = currentPlugins[pluginId];\n const version = existingEntry?.__dataVersion ?? DATA_MODEL_DEFAULT_VERSION;\n return {\n ...storage,\n __plugins: {\n ...currentPlugins,\n [pluginId]: {\n __dataVersion: version,\n __data: value,\n },\n },\n };\n }\n default:\n throw new Error(`Unknown storage operation: ${(payload as { operation: string }).operation}`);\n }\n}\n\n/**\n * Storage debug view returned by __pl_storage_debugView callback.\n * Used by developer tools to display block storage info.\n */\nexport interface StorageDebugView {\n /** Current data version key */\n dataVersion: string;\n /** Raw data payload stored in BlockStorage */\n data: unknown;\n}\n\n// =============================================================================\n// Atomic Migration\n// =============================================================================\n\n/**\n * Result of a successful atomic migration.\n */\nexport interface MigrationSuccess<TState> {\n success: true;\n /** The fully migrated storage - commit this to persist */\n storage: BlockStorage<TState>;\n}\n\n/**\n * Result of a failed atomic migration.\n * The original storage is untouched - user must choose to abort or reset.\n */\nexport interface MigrationFailure {\n success: false;\n /** Description of what failed */\n error: string;\n /** Which step failed: 'block' or pluginId */\n failedAt: string;\n}\n\nexport type MigrationResult<TState> = MigrationSuccess<TState> | MigrationFailure;\n\n/**\n * Configuration for atomic block storage migration.\n * Callbacks use DataVersioned format (the DataModel API format).\n * Conversion to internal VersionedData format is handled by migrateBlockStorage().\n */\nexport interface MigrateBlockStorageConfig {\n /** Migrate block data from any version to latest */\n migrateBlockData: (versioned: DataVersioned<unknown>) => DataMigrationResult<unknown>;\n /** Migrate each plugin's data. Return undefined to remove the plugin. */\n migratePluginData: (\n pluginId: string,\n versioned: DataVersioned<unknown>,\n ) => DataMigrationResult<unknown> | undefined;\n /** The new plugin registry after migration (pluginId -> pluginName) */\n newPluginRegistry: PluginRegistry;\n /** Factory to create initial data for new plugins */\n createPluginData: (pluginId: string) => DataVersioned<unknown>;\n}\n\n/**\n * Performs atomic migration of block storage including block data and all plugins.\n *\n * Migration is atomic: either everything succeeds and a new storage is returned,\n * or an error is returned and the original storage is completely untouched.\n *\n * Migration steps:\n * 1. Migrate block data\n * 2. For each plugin in newPluginRegistry:\n * - If plugin exists with same name: migrate its data\n * - Otherwise (new or type changed): create with initial data\n * Plugins not in newPluginRegistry are dropped.\n *\n * If any step throws, migration fails and original storage is preserved.\n * User can then choose to:\n * - Abort: keep original storage, don't update block\n * - Reset: call createBlockStorage() to start fresh\n *\n * @param storage - The original storage (will not be modified)\n * @param config - Migration configuration\n * @returns Migration result - either success with new storage, or failure with error info\n *\n * @example\n * const result = migrateBlockStorage(storage, {\n * migrateBlockData: (versioned) => blockDataModel.migrate(versioned),\n * migratePluginData: (pluginId, versioned) => getPluginModel(pluginId).migrate(versioned),\n * newPluginRegistry: { table1: 'dataTable' as PluginName },\n * createPluginData: (pluginId) => getPluginModel(pluginId).getDefaultData(),\n * });\n *\n * if (result.success) {\n * commitStorage(result.storage);\n * } else {\n * const userChoice = await askUser(`Migration failed: ${result.error}. Reset data?`);\n * if (userChoice === 'reset') {\n * commitStorage(createBlockStorage(initialData, currentVersion));\n * }\n * // else: abort, keep original\n * }\n */\nexport function migrateBlockStorage(\n storage: BlockStorage<unknown>,\n config: MigrateBlockStorageConfig,\n): MigrationResult<unknown> {\n const { migrateBlockData, migratePluginData, newPluginRegistry, createPluginData } = config;\n\n // Step 1: Migrate block data\n let migratedData: unknown;\n let newVersion: string;\n try {\n const result = migrateBlockData({ version: storage.__dataVersion, data: storage.__data });\n migratedData = result.data;\n newVersion = result.version;\n } catch (error) {\n return {\n success: false,\n error: error instanceof Error ? error.message : String(error),\n failedAt: \"block\",\n };\n }\n\n // Step 2: Migrate plugins\n const oldPlugins = storage.__plugins ?? {};\n const oldRegistry = storage.__pluginRegistry ?? {};\n const newPlugins: Record<string, VersionedData<unknown>> = {};\n\n for (const [pluginId, pluginName] of Object.entries(newPluginRegistry)) {\n const existingEntry = oldPlugins[pluginId];\n const existingName = oldRegistry[pluginId];\n\n try {\n if (existingEntry && existingName === pluginName) {\n // Plugin exists with same type - migrate its data\n const migrated = migratePluginData(pluginId, {\n version: existingEntry.__dataVersion,\n data: existingEntry.__data,\n });\n if (migrated) {\n newPlugins[pluginId] = { __dataVersion: migrated.version, __data: migrated.data };\n }\n // If undefined returned, plugin is intentionally removed\n } else {\n // New plugin or type changed - create with initial data\n const initial = createPluginData(pluginId);\n newPlugins[pluginId] = { __dataVersion: initial.version, __data: initial.data };\n }\n } catch (error) {\n return {\n success: false,\n error: error instanceof Error ? error.message : String(error),\n failedAt: pluginId,\n };\n }\n }\n\n // Step 3: Build final storage atomically\n const migratedStorage: BlockStorage = {\n [BLOCK_STORAGE_KEY]: BLOCK_STORAGE_SCHEMA_VERSION,\n __dataVersion: newVersion,\n __data: migratedData,\n __pluginRegistry: newPluginRegistry,\n __plugins: newPlugins,\n };\n\n return {\n success: true,\n storage: migratedStorage,\n };\n}\n\n/**\n * Gets plugin-specific data from block storage.\n * Accepts raw storage (any format) and normalizes internally.\n *\n * @param rawStorage - Raw block storage (may be legacy format or BlockStorage)\n * @param pluginId - The plugin instance id\n * @returns The plugin data\n * @throws If pluginId is not found in storage\n */\nexport function getPluginData<TData = unknown>(rawStorage: unknown, pluginId: string): TData {\n const storage = normalizeBlockStorage(rawStorage);\n const pluginEntry = storage.__plugins?.[pluginId];\n if (!pluginEntry) throw new Error(`Plugin '${pluginId}' not found in block storage`);\n return pluginEntry.__data as TData;\n}\n"],"names":[],"mappings":";;AAAA;;;;;;;;;AASG;AAKH;AACA;AACA;AAEA;;;AAGG;AACI,MAAM,iBAAiB,GAAG;AAEjC;;;AAGG;AACI,MAAM,4BAA4B,GAAG;AAE5C;;;AAGG;AACI,MAAM,0BAA0B,GAAG;AA+C1C;;;AAGG;AACG,SAAU,cAAc,CAAC,KAAc,EAAA;AAC3C,IAAA,IAAI,KAAK,KAAK,IAAI,IAAI,OAAO,KAAK,KAAK,QAAQ;AAAE,QAAA,OAAO,KAAK;IAC7D,MAAM,GAAG,GAAG,KAAgC;AAC5C,IAAA,MAAM,aAAa,GAAG,GAAG,CAAC,iBAAiB,CAAC;;AAE5C,IAAA,OAAO,aAAa,KAAK,IAAI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eAAe,GAAiB;QACpC,CAAC,iBAAiB,GAAG,4BAA4B;AACjD,QAAA,aAAa,EAAE,UAAU;AACzB,QAAA,MAAM,EAAE,YAAY;AACpB,QAAA,gBAAgB,EAAE,iBAAiB;AACnC,QAAA,SAAS,EAAE,UAAU;KACtB;IAED,OAAO;AACL,QAAA,OAAO,EAAE,IAAI;AACb,QAAA,OAAO,EAAE,eAAe;KACzB;AACH;AAEA;;;;;;;;AAQG;AACG,SAAU,aAAa,CAAkB,UAAmB,EAAE,QAAgB,EAAA;AAClF,IAAA,MAAM,OAAO,GAAG,qBAAqB,CAAC,UAAU,CAAC;IACjD,MAAM,WAAW,GAAG,OAAO,CAAC,SAAS,GAAG,QAAQ,CAAC;AACjD,IAAA,IAAI,CAAC,WAAW;AAAE,QAAA,MAAM,IAAI,KAAK,CAAC,WAAW,QAAQ,CAAA,4BAAA,CAA8B,CAAC;IACpF,OAAO,WAAW,CAAC,MAAe;AACpC;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"block_storage.cjs","sources":["../src/block_storage.ts"],"sourcesContent":["/**\n * BlockStorage - Typed storage abstraction for block persistent data.\n *\n * This module provides:\n * - A typed structure for block storage with versioning and plugin support\n * - Utility functions for manipulating storage\n * - Handler interfaces for model-level customization\n *\n * @module block_storage\n */\n\nimport type { Branded } from \"@milaboratories/pl-model-common\";\nimport type { DataVersioned } from \"./block_migrations\";\nimport type { PluginHandle, PluginFactoryLike, InferFactoryData } from \"./plugin_handle\";\n\n// =============================================================================\n// Core Types\n// =============================================================================\n\n/**\n * Discriminator key for BlockStorage format detection.\n * This unique hash-based key identifies data as BlockStorage vs legacy formats.\n */\nexport const BLOCK_STORAGE_KEY = \"__pl_a7f3e2b9__\";\n\n/**\n * Current BlockStorage schema version.\n * Increment this when the storage structure itself changes (not block state migrations).\n */\nexport const BLOCK_STORAGE_SCHEMA_VERSION = \"v1\";\n\n/**\n * Default data version for new blocks without migrations.\n * Unique identifier ensures blocks are created via DataModel API.\n */\nexport const DATA_MODEL_LEGACY_VERSION = \"__pl_v1_d4e8f2a1__\";\n\n/**\n * Type for valid schema versions\n */\nexport type BlockStorageSchemaVersion = \"v1\"; // Add 'v2', 'v3', etc. as schema evolves\n\n/**\n * Branded type for plugin names - globally unique plugin type identifiers.\n * Using a branded type enforces explicit casting (`as PluginName`) which makes\n * it easy to find all plugin name definitions in the codebase and verify uniqueness.\n */\nexport type PluginName = Branded<string, \"PluginName\">;\n\n/**\n * Plugin registry - maps pluginId (unique within a block) to pluginName (globally unique plugin type).\n * Using a Record highlights that pluginIds must be unique within a block.\n */\nexport type PluginRegistry = Record<PluginHandle, PluginName>;\n\n/**\n * Versioned data - used for both block data and plugin data\n */\nexport interface VersionedData<TData = unknown> {\n /** Version of the data, used for migrations */\n __dataVersion: string;\n /** The persistent data */\n __data: TData;\n}\n\n/**\n * Core BlockStorage type that holds:\n * - __pl_a7f3e2b9__: Schema version (discriminator key identifies BlockStorage format)\n * - __dataVersion: Version key for block data migrations\n * - __data: The block's user-facing data (state)\n * - __pluginRegistry: Map from pluginId to pluginName (optional)\n * - __plugins: Plugin-specific data keyed by pluginId (optional)\n */\nexport type BlockStorage<TState = unknown> = {\n /** Schema version - the key itself is the discriminator */\n readonly [BLOCK_STORAGE_KEY]: BlockStorageSchemaVersion;\n /** Registry of plugins: pluginId -> pluginName */\n __pluginRegistry?: PluginRegistry;\n /** Plugin-specific data, keyed by plugin handle */\n __plugins?: Record<PluginHandle, VersionedData<unknown>>;\n} & VersionedData<TState>;\n\n/**\n * Type guard to check if a value is a valid BlockStorage object.\n * Checks for the discriminator key and valid schema version.\n */\nexport function isBlockStorage(value: unknown): value is BlockStorage {\n if (value === null || typeof value !== \"object\") return false;\n const obj = value as Record<string, unknown>;\n const schemaVersion = obj[BLOCK_STORAGE_KEY];\n // Currently only 'v1' is valid, but this allows future versions\n return schemaVersion === \"v1\"; // Add more versions as schema evolves\n}\n\n// =============================================================================\n// Factory Functions\n// =============================================================================\n\n/**\n * Creates a BlockStorage with the given initial data\n *\n * @param initialData - The initial data value (defaults to empty object)\n * @param version - The initial data version key (defaults to DATA_MODEL_LEGACY_VERSION)\n * @returns A new BlockStorage instance with discriminator key\n */\nexport function createBlockStorage<TState = unknown>(\n initialData: TState = {} as TState,\n version: string = DATA_MODEL_LEGACY_VERSION,\n): BlockStorage<TState> {\n return {\n [BLOCK_STORAGE_KEY]: BLOCK_STORAGE_SCHEMA_VERSION,\n __dataVersion: version,\n __data: initialData,\n __pluginRegistry: {},\n __plugins: {},\n };\n}\n\n/**\n * Normalizes raw storage data to BlockStorage format.\n * If the input is already a BlockStorage, returns it as-is (with defaults for missing fields).\n * If the input is legacy format (raw state), wraps it in BlockStorage structure.\n *\n * @param raw - Raw storage data (may be legacy format or BlockStorage)\n * @returns Normalized BlockStorage\n */\nexport function normalizeBlockStorage<TState = unknown>(raw: unknown): BlockStorage<TState> {\n if (isBlockStorage(raw)) {\n const storage = raw as BlockStorage<TState>;\n return {\n ...storage,\n // Fix for early released version where __dataVersion was a number\n __dataVersion:\n typeof storage.__dataVersion === \"number\"\n ? DATA_MODEL_LEGACY_VERSION\n : storage.__dataVersion,\n // Ensure plugin fields have defaults\n __pluginRegistry: storage.__pluginRegistry ?? {},\n __plugins: storage.__plugins ?? {},\n };\n }\n // Legacy format: raw is the state directly\n return createBlockStorage(raw as TState);\n}\n\n// =============================================================================\n// Data Access & Update Functions\n// =============================================================================\n\n/**\n * Gets the data from BlockStorage\n *\n * @param storage - The BlockStorage instance\n * @returns The data value\n */\nexport function getStorageData<TState>(storage: BlockStorage<TState>): TState {\n return storage.__data;\n}\n\n/**\n * Derives data from raw block storage.\n * This function is meant to be called from sdk/ui-vue to extract\n * user-facing data from the raw storage returned by the middle layer.\n *\n * The middle layer returns raw storage (opaque to it), and the UI\n * uses this function to derive the actual data value.\n *\n * @param rawStorage - Raw storage data from middle layer (may be any format)\n * @returns The extracted data value, or undefined if storage is undefined/null\n */\nexport function deriveDataFromStorage<TData = unknown>(rawStorage: unknown): TData {\n // Normalize to BlockStorage format (handles legacy formats too)\n const storage = normalizeBlockStorage<TData>(rawStorage);\n return getStorageData(storage);\n}\n\n/** Payload for storage mutation operations. SDK defines specific operations. */\nexport type MutateStoragePayload<T = unknown> =\n | { operation: \"update-block-data\"; value: T }\n | { operation: \"update-plugin-data\"; pluginId: PluginHandle; value: unknown };\n\n/**\n * Updates the data in BlockStorage (immutable)\n *\n * @param storage - The current BlockStorage\n * @param payload - The update payload with operation and value\n * @returns A new BlockStorage with updated data\n */\nexport function updateStorageData<TValue = unknown>(\n storage: BlockStorage<TValue>,\n payload: MutateStoragePayload<TValue>,\n): BlockStorage<TValue> {\n switch (payload.operation) {\n case \"update-block-data\":\n return { ...storage, __data: payload.value };\n case \"update-plugin-data\": {\n const { pluginId, value } = payload;\n const currentPlugins = storage.__plugins ?? {};\n const existingEntry = currentPlugins[pluginId];\n const version = existingEntry?.__dataVersion ?? DATA_MODEL_LEGACY_VERSION;\n return {\n ...storage,\n __plugins: {\n ...currentPlugins,\n [pluginId]: {\n __dataVersion: version,\n __data: value,\n },\n },\n };\n }\n default:\n throw new Error(`Unknown storage operation: ${(payload as { operation: string }).operation}`);\n }\n}\n\n/**\n * Storage debug view returned by __pl_storage_debugView callback.\n * Used by developer tools to display block storage info.\n */\nexport interface StorageDebugView {\n /** Current data version key */\n dataVersion: string;\n /** Raw data payload stored in BlockStorage */\n data: unknown;\n}\n\n// =============================================================================\n// Atomic Migration\n// =============================================================================\n\n/**\n * Result of a successful atomic migration.\n */\nexport interface MigrationSuccess<TState> {\n success: true;\n /** The fully migrated storage - commit this to persist */\n storage: BlockStorage<TState>;\n}\n\n/**\n * Result of a failed atomic migration.\n * The original storage is untouched - user must choose to abort or reset.\n */\nexport interface MigrationFailure {\n success: false;\n /** Description of what failed */\n error: string;\n /** Which step failed: 'block' or pluginId */\n failedAt: string;\n}\n\nexport type MigrationResult<TState> = MigrationSuccess<TState> | MigrationFailure;\n\n/**\n * Configuration for atomic block storage migration.\n * Callbacks use DataVersioned format (the DataModel API format).\n * Conversion to internal VersionedData format is handled by migrateBlockStorage().\n */\nexport interface MigrateBlockStorageConfig {\n /** Migrate block data from any version to latest. Throws on failure. */\n migrateBlockData: (versioned: DataVersioned<unknown>) => DataVersioned<unknown>;\n /** Migrate each plugin's data. Return undefined to remove the plugin. Throws on failure. */\n migratePluginData: (\n handle: PluginHandle,\n versioned: DataVersioned<unknown>,\n ) => DataVersioned<unknown> | undefined;\n /** The new plugin registry after migration (pluginId -> pluginName) */\n newPluginRegistry: PluginRegistry;\n /** Factory to create initial data for new plugins */\n createPluginData: (handle: PluginHandle) => DataVersioned<unknown>;\n}\n\n/**\n * Performs atomic migration of block storage including block data and all plugins.\n *\n * Migration is atomic: either everything succeeds and a new storage is returned,\n * or an error is returned and the original storage is completely untouched.\n *\n * Migration steps:\n * 1. Migrate block data\n * 2. For each plugin in newPluginRegistry:\n * - If plugin exists with same name: migrate its data\n * - Otherwise (new or type changed): create with initial data\n * Plugins not in newPluginRegistry are dropped.\n *\n * If any step throws, migration fails and original storage is preserved.\n * User can then choose to:\n * - Abort: keep original storage, don't update block\n * - Reset: call createBlockStorage() to start fresh\n *\n * @param storage - The original storage (will not be modified)\n * @param config - Migration configuration\n * @returns Migration result - either success with new storage, or failure with error info\n *\n * @example\n * const result = migrateBlockStorage(storage, {\n * migrateBlockData: (versioned) => blockDataModel.migrate(versioned),\n * migratePluginData: (pluginId, versioned) => getPluginModel(pluginId).migrate(versioned),\n * newPluginRegistry: { table1: 'dataTable' as PluginName },\n * createPluginData: (pluginId) => getPluginModel(pluginId).getDefaultData(),\n * });\n *\n * if (result.success) {\n * commitStorage(result.storage);\n * } else {\n * const userChoice = await askUser(`Migration failed: ${result.error}. Reset data?`);\n * if (userChoice === 'reset') {\n * commitStorage(createBlockStorage(initialData, currentVersion));\n * }\n * // else: abort, keep original\n * }\n */\nexport function migrateBlockStorage(\n storage: BlockStorage<unknown>,\n config: MigrateBlockStorageConfig,\n): MigrationResult<unknown> {\n const { migrateBlockData, migratePluginData, newPluginRegistry, createPluginData } = config;\n\n // Step 1: Migrate block data\n let migratedData: unknown;\n let newVersion: string;\n try {\n const result = migrateBlockData({ version: storage.__dataVersion, data: storage.__data });\n migratedData = result.data;\n newVersion = result.version;\n } catch (error) {\n return {\n success: false,\n error: error instanceof Error ? error.message : String(error),\n failedAt: \"block\",\n };\n }\n\n // Step 2: Migrate plugins\n const oldPlugins = storage.__plugins ?? {};\n const oldRegistry = storage.__pluginRegistry ?? {};\n const newPlugins: Record<PluginHandle, VersionedData<unknown>> = {};\n\n for (const [key, pluginName] of Object.entries(newPluginRegistry)) {\n const handle = key as PluginHandle;\n const existingEntry = oldPlugins[handle];\n const existingName = oldRegistry[handle];\n\n try {\n if (existingEntry && existingName === pluginName) {\n // Plugin exists with same type - migrate its data\n const migrated = migratePluginData(handle, {\n version: existingEntry.__dataVersion,\n data: existingEntry.__data,\n });\n if (migrated) {\n newPlugins[handle] = { __dataVersion: migrated.version, __data: migrated.data };\n }\n // If undefined returned, plugin is intentionally removed\n } else {\n // New plugin or type changed - create with initial data\n const initial = createPluginData(handle);\n newPlugins[handle] = { __dataVersion: initial.version, __data: initial.data };\n }\n } catch (error) {\n return {\n success: false,\n error: error instanceof Error ? error.message : String(error),\n failedAt: handle,\n };\n }\n }\n\n // Step 3: Build final storage atomically\n const migratedStorage: BlockStorage = {\n [BLOCK_STORAGE_KEY]: BLOCK_STORAGE_SCHEMA_VERSION,\n __dataVersion: newVersion,\n __data: migratedData,\n __pluginRegistry: newPluginRegistry,\n __plugins: newPlugins,\n };\n\n return {\n success: true,\n storage: migratedStorage,\n };\n}\n\n/**\n * Gets plugin-specific data from block storage.\n * Accepts raw storage (any format) and normalizes internally.\n *\n * When called with a typed PluginHandle<F>, the return type is automatically\n * inferred from the factory's phantom `__types.data` field.\n *\n * @param rawStorage - Raw block storage (may be legacy format or BlockStorage)\n * @param handle - The plugin handle (branded plugin instance id)\n * @returns The plugin data, typed via factory inference\n * @throws If plugin is not found in storage\n */\nexport function getPluginData<F extends PluginFactoryLike>(\n rawStorage: unknown,\n handle: PluginHandle<F>,\n): InferFactoryData<F> {\n const storage = normalizeBlockStorage(rawStorage);\n const pluginEntry = storage.__plugins?.[handle];\n if (!pluginEntry) throw new Error(`Plugin '${handle}' not found in block storage`);\n return pluginEntry.__data as InferFactoryData<F>;\n}\n"],"names":[],"mappings":";;AAAA;;;;;;;;;AASG;AAMH;AACA;AACA;AAEA;;;AAGG;AACI,MAAM,iBAAiB,GAAG;AAEjC;;;AAGG;AACI,MAAM,4BAA4B,GAAG;AAE5C;;;AAGG;AACI,MAAM,yBAAyB,GAAG;AA+CzC;;;AAGG;AACG,SAAU,cAAc,CAAC,KAAc,EAAA;AAC3C,IAAA,IAAI,KAAK,KAAK,IAAI,IAAI,OAAO,KAAK,KAAK,QAAQ;AAAE,QAAA,OAAO,KAAK;IAC7D,MAAM,GAAG,GAAG,KAAgC;AAC5C,IAAA,MAAM,aAAa,GAAG,GAAG,CAAC,iBAAiB,CAAC;;AAE5C,IAAA,OAAO,aAAa,KAAK,IAAI,CAAC;AAChC;AAEA;AACA;AACA;AAEA;;;;;;AAMG;SACa,kBAAkB,CAChC,cAAsB,EAAY,EAClC,UAAkB,yBAAyB,EAAA;IAE3C,OAAO;QACL,CAAC,iBAAiB,GAAG,4BAA4B;AACjD,QAAA,aAAa,EAAE,OAAO;AACtB,QAAA,MAAM,EAAE,WAAW;AACnB,QAAA,gBAAgB,EAAE,EAAE;AACpB,QAAA,SAAS,EAAE,EAAE;KACd;AACH;AAEA;;;;;;;AAOG;AACG,SAAU,qBAAqB,CAAmB,GAAY,EAAA;AAClE,IAAA,IAAI,cAAc,CAAC,GAAG,CAAC,EAAE;QACvB,MAAM,OAAO,GAAG,GAA2B;QAC3C,OAAO;AACL,YAAA,GAAG,OAAO;;AAEV,YAAA,aAAa,EACX,OAAO,OAAO,CAAC,aAAa,KAAK;AAC/B,kBAAE;kBACA,OAAO,CAAC,aAAa;;AAE3B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,CAA8B,CAAC;IAClF,OAAO,WAAW,CAAC,MAA6B;AAClD;;;;;;;;;;;;;;"}
@@ -9,7 +9,8 @@
9
9
  * @module block_storage
10
10
  */
11
11
  import type { Branded } from "@milaboratories/pl-model-common";
12
- import type { DataMigrationResult, DataVersioned } from "./block_migrations";
12
+ import type { DataVersioned } from "./block_migrations";
13
+ import type { PluginHandle, PluginFactoryLike, InferFactoryData } from "./plugin_handle";
13
14
  /**
14
15
  * Discriminator key for BlockStorage format detection.
15
16
  * This unique hash-based key identifies data as BlockStorage vs legacy formats.
@@ -24,7 +25,7 @@ export declare const BLOCK_STORAGE_SCHEMA_VERSION = "v1";
24
25
  * Default data version for new blocks without migrations.
25
26
  * Unique identifier ensures blocks are created via DataModel API.
26
27
  */
27
- export declare const DATA_MODEL_DEFAULT_VERSION = "__pl_v1_d4e8f2a1__";
28
+ export declare const DATA_MODEL_LEGACY_VERSION = "__pl_v1_d4e8f2a1__";
28
29
  /**
29
30
  * Type for valid schema versions
30
31
  */
@@ -39,7 +40,7 @@ export type PluginName = Branded<string, "PluginName">;
39
40
  * Plugin registry - maps pluginId (unique within a block) to pluginName (globally unique plugin type).
40
41
  * Using a Record highlights that pluginIds must be unique within a block.
41
42
  */
42
- export type PluginRegistry = Record<string, PluginName>;
43
+ export type PluginRegistry = Record<PluginHandle, PluginName>;
43
44
  /**
44
45
  * Versioned data - used for both block data and plugin data
45
46
  */
@@ -62,8 +63,8 @@ export type BlockStorage<TState = unknown> = {
62
63
  readonly [BLOCK_STORAGE_KEY]: BlockStorageSchemaVersion;
63
64
  /** Registry of plugins: pluginId -> pluginName */
64
65
  __pluginRegistry?: PluginRegistry;
65
- /** Plugin-specific data, keyed by pluginId */
66
- __plugins?: Record<string, VersionedData<unknown>>;
66
+ /** Plugin-specific data, keyed by plugin handle */
67
+ __plugins?: Record<PluginHandle, VersionedData<unknown>>;
67
68
  } & VersionedData<TState>;
68
69
  /**
69
70
  * Type guard to check if a value is a valid BlockStorage object.
@@ -74,7 +75,7 @@ export declare function isBlockStorage(value: unknown): value is BlockStorage;
74
75
  * Creates a BlockStorage with the given initial data
75
76
  *
76
77
  * @param initialData - The initial data value (defaults to empty object)
77
- * @param version - The initial data version key (defaults to DATA_MODEL_DEFAULT_VERSION)
78
+ * @param version - The initial data version key (defaults to DATA_MODEL_LEGACY_VERSION)
78
79
  * @returns A new BlockStorage instance with discriminator key
79
80
  */
80
81
  export declare function createBlockStorage<TState = unknown>(initialData?: TState, version?: string): BlockStorage<TState>;
@@ -112,7 +113,7 @@ export type MutateStoragePayload<T = unknown> = {
112
113
  value: T;
113
114
  } | {
114
115
  operation: "update-plugin-data";
115
- pluginId: string;
116
+ pluginId: PluginHandle;
116
117
  value: unknown;
117
118
  };
118
119
  /**
@@ -159,14 +160,14 @@ export type MigrationResult<TState> = MigrationSuccess<TState> | MigrationFailur
159
160
  * Conversion to internal VersionedData format is handled by migrateBlockStorage().
160
161
  */
161
162
  export interface MigrateBlockStorageConfig {
162
- /** Migrate block data from any version to latest */
163
- migrateBlockData: (versioned: DataVersioned<unknown>) => DataMigrationResult<unknown>;
164
- /** Migrate each plugin's data. Return undefined to remove the plugin. */
165
- migratePluginData: (pluginId: string, versioned: DataVersioned<unknown>) => DataMigrationResult<unknown> | undefined;
163
+ /** Migrate block data from any version to latest. Throws on failure. */
164
+ migrateBlockData: (versioned: DataVersioned<unknown>) => DataVersioned<unknown>;
165
+ /** Migrate each plugin's data. Return undefined to remove the plugin. Throws on failure. */
166
+ migratePluginData: (handle: PluginHandle, versioned: DataVersioned<unknown>) => DataVersioned<unknown> | undefined;
166
167
  /** The new plugin registry after migration (pluginId -> pluginName) */
167
168
  newPluginRegistry: PluginRegistry;
168
169
  /** Factory to create initial data for new plugins */
169
- createPluginData: (pluginId: string) => DataVersioned<unknown>;
170
+ createPluginData: (handle: PluginHandle) => DataVersioned<unknown>;
170
171
  }
171
172
  /**
172
173
  * Performs atomic migration of block storage including block data and all plugins.
@@ -213,10 +214,13 @@ export declare function migrateBlockStorage(storage: BlockStorage<unknown>, conf
213
214
  * Gets plugin-specific data from block storage.
214
215
  * Accepts raw storage (any format) and normalizes internally.
215
216
  *
217
+ * When called with a typed PluginHandle<F>, the return type is automatically
218
+ * inferred from the factory's phantom `__types.data` field.
219
+ *
216
220
  * @param rawStorage - Raw block storage (may be legacy format or BlockStorage)
217
- * @param pluginId - The plugin instance id
218
- * @returns The plugin data
219
- * @throws If pluginId is not found in storage
221
+ * @param handle - The plugin handle (branded plugin instance id)
222
+ * @returns The plugin data, typed via factory inference
223
+ * @throws If plugin is not found in storage
220
224
  */
221
- export declare function getPluginData<TData = unknown>(rawStorage: unknown, pluginId: string): TData;
225
+ export declare function getPluginData<F extends PluginFactoryLike>(rawStorage: unknown, handle: PluginHandle<F>): InferFactoryData<F>;
222
226
  //# sourceMappingURL=block_storage.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"block_storage.d.ts","sourceRoot":"","sources":["../src/block_storage.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,iCAAiC,CAAC;AAC/D,OAAO,KAAK,EAAE,mBAAmB,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAM7E;;;GAGG;AACH,eAAO,MAAM,iBAAiB,oBAAoB,CAAC;AAEnD;;;GAGG;AACH,eAAO,MAAM,4BAA4B,OAAO,CAAC;AAEjD;;;GAGG;AACH,eAAO,MAAM,0BAA0B,uBAAuB,CAAC;AAE/D;;GAEG;AACH,MAAM,MAAM,yBAAyB,GAAG,IAAI,CAAC;AAE7C;;;;GAIG;AACH,MAAM,MAAM,UAAU,GAAG,OAAO,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC;AAEvD;;;GAGG;AACH,MAAM,MAAM,cAAc,GAAG,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC;AAExD;;GAEG;AACH,MAAM,WAAW,aAAa,CAAC,KAAK,GAAG,OAAO;IAC5C,+CAA+C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,OAAO,CAAC,CAkE1B;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,aAAa,CAAC,CAAC,SAAS,iBAAiB,EACvD,UAAU,EAAE,OAAO,EACnB,MAAM,EAAE,YAAY,CAAC,CAAC,CAAC,GACtB,gBAAgB,CAAC,CAAC,CAAC,CAKrB"}
@@ -25,7 +25,7 @@ const BLOCK_STORAGE_SCHEMA_VERSION = "v1";
25
25
  * Default data version for new blocks without migrations.
26
26
  * Unique identifier ensures blocks are created via DataModel API.
27
27
  */
28
- const DATA_MODEL_DEFAULT_VERSION = "__pl_v1_d4e8f2a1__";
28
+ const DATA_MODEL_LEGACY_VERSION = "__pl_v1_d4e8f2a1__";
29
29
  /**
30
30
  * Type guard to check if a value is a valid BlockStorage object.
31
31
  * Checks for the discriminator key and valid schema version.
@@ -45,10 +45,10 @@ function isBlockStorage(value) {
45
45
  * Creates a BlockStorage with the given initial data
46
46
  *
47
47
  * @param initialData - The initial data value (defaults to empty object)
48
- * @param version - The initial data version key (defaults to DATA_MODEL_DEFAULT_VERSION)
48
+ * @param version - The initial data version key (defaults to DATA_MODEL_LEGACY_VERSION)
49
49
  * @returns A new BlockStorage instance with discriminator key
50
50
  */
51
- function createBlockStorage(initialData = {}, version = DATA_MODEL_DEFAULT_VERSION) {
51
+ function createBlockStorage(initialData = {}, version = DATA_MODEL_LEGACY_VERSION) {
52
52
  return {
53
53
  [BLOCK_STORAGE_KEY]: BLOCK_STORAGE_SCHEMA_VERSION,
54
54
  __dataVersion: version,
@@ -72,7 +72,7 @@ function normalizeBlockStorage(raw) {
72
72
  ...storage,
73
73
  // Fix for early released version where __dataVersion was a number
74
74
  __dataVersion: typeof storage.__dataVersion === "number"
75
- ? DATA_MODEL_DEFAULT_VERSION
75
+ ? DATA_MODEL_LEGACY_VERSION
76
76
  : storage.__dataVersion,
77
77
  // Ensure plugin fields have defaults
78
78
  __pluginRegistry: storage.__pluginRegistry ?? {},
@@ -125,7 +125,7 @@ function updateStorageData(storage, payload) {
125
125
  const { pluginId, value } = payload;
126
126
  const currentPlugins = storage.__plugins ?? {};
127
127
  const existingEntry = currentPlugins[pluginId];
128
- const version = existingEntry?.__dataVersion ?? DATA_MODEL_DEFAULT_VERSION;
128
+ const version = existingEntry?.__dataVersion ?? DATA_MODEL_LEGACY_VERSION;
129
129
  return {
130
130
  ...storage,
131
131
  __plugins: {
@@ -202,32 +202,33 @@ function migrateBlockStorage(storage, config) {
202
202
  const oldPlugins = storage.__plugins ?? {};
203
203
  const oldRegistry = storage.__pluginRegistry ?? {};
204
204
  const newPlugins = {};
205
- for (const [pluginId, pluginName] of Object.entries(newPluginRegistry)) {
206
- const existingEntry = oldPlugins[pluginId];
207
- const existingName = oldRegistry[pluginId];
205
+ for (const [key, pluginName] of Object.entries(newPluginRegistry)) {
206
+ const handle = key;
207
+ const existingEntry = oldPlugins[handle];
208
+ const existingName = oldRegistry[handle];
208
209
  try {
209
210
  if (existingEntry && existingName === pluginName) {
210
211
  // Plugin exists with same type - migrate its data
211
- const migrated = migratePluginData(pluginId, {
212
+ const migrated = migratePluginData(handle, {
212
213
  version: existingEntry.__dataVersion,
213
214
  data: existingEntry.__data,
214
215
  });
215
216
  if (migrated) {
216
- newPlugins[pluginId] = { __dataVersion: migrated.version, __data: migrated.data };
217
+ newPlugins[handle] = { __dataVersion: migrated.version, __data: migrated.data };
217
218
  }
218
219
  // If undefined returned, plugin is intentionally removed
219
220
  }
220
221
  else {
221
222
  // New plugin or type changed - create with initial data
222
- const initial = createPluginData(pluginId);
223
- newPlugins[pluginId] = { __dataVersion: initial.version, __data: initial.data };
223
+ const initial = createPluginData(handle);
224
+ newPlugins[handle] = { __dataVersion: initial.version, __data: initial.data };
224
225
  }
225
226
  }
226
227
  catch (error) {
227
228
  return {
228
229
  success: false,
229
230
  error: error instanceof Error ? error.message : String(error),
230
- failedAt: pluginId,
231
+ failedAt: handle,
231
232
  };
232
233
  }
233
234
  }
@@ -248,18 +249,21 @@ function migrateBlockStorage(storage, config) {
248
249
  * Gets plugin-specific data from block storage.
249
250
  * Accepts raw storage (any format) and normalizes internally.
250
251
  *
252
+ * When called with a typed PluginHandle<F>, the return type is automatically
253
+ * inferred from the factory's phantom `__types.data` field.
254
+ *
251
255
  * @param rawStorage - Raw block storage (may be legacy format or BlockStorage)
252
- * @param pluginId - The plugin instance id
253
- * @returns The plugin data
254
- * @throws If pluginId is not found in storage
256
+ * @param handle - The plugin handle (branded plugin instance id)
257
+ * @returns The plugin data, typed via factory inference
258
+ * @throws If plugin is not found in storage
255
259
  */
256
- function getPluginData(rawStorage, pluginId) {
260
+ function getPluginData(rawStorage, handle) {
257
261
  const storage = normalizeBlockStorage(rawStorage);
258
- const pluginEntry = storage.__plugins?.[pluginId];
262
+ const pluginEntry = storage.__plugins?.[handle];
259
263
  if (!pluginEntry)
260
- throw new Error(`Plugin '${pluginId}' not found in block storage`);
264
+ throw new Error(`Plugin '${handle}' not found in block storage`);
261
265
  return pluginEntry.__data;
262
266
  }
263
267
 
264
- export { BLOCK_STORAGE_KEY, BLOCK_STORAGE_SCHEMA_VERSION, DATA_MODEL_DEFAULT_VERSION, createBlockStorage, deriveDataFromStorage, getPluginData, getStorageData, isBlockStorage, migrateBlockStorage, normalizeBlockStorage, updateStorageData };
268
+ export { BLOCK_STORAGE_KEY, BLOCK_STORAGE_SCHEMA_VERSION, DATA_MODEL_LEGACY_VERSION, createBlockStorage, deriveDataFromStorage, getPluginData, getStorageData, isBlockStorage, migrateBlockStorage, normalizeBlockStorage, updateStorageData };
265
269
  //# sourceMappingURL=block_storage.js.map