@milaboratories/pl-middle-layer 1.45.5 → 1.46.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 (132) hide show
  1. package/dist/index.cjs +58 -0
  2. package/dist/index.cjs.map +1 -1
  3. package/dist/index.js +2 -0
  4. package/dist/index.js.map +1 -1
  5. package/dist/js_render/computable_context.cjs +37 -7
  6. package/dist/js_render/computable_context.cjs.map +1 -1
  7. package/dist/js_render/computable_context.d.ts.map +1 -1
  8. package/dist/js_render/computable_context.js +37 -7
  9. package/dist/js_render/computable_context.js.map +1 -1
  10. package/dist/js_render/context.cjs +12 -4
  11. package/dist/js_render/context.cjs.map +1 -1
  12. package/dist/js_render/context.d.ts +9 -0
  13. package/dist/js_render/context.d.ts.map +1 -1
  14. package/dist/js_render/context.js +12 -4
  15. package/dist/js_render/context.js.map +1 -1
  16. package/dist/js_render/index.cjs +1 -1
  17. package/dist/js_render/index.cjs.map +1 -1
  18. package/dist/js_render/index.js +1 -1
  19. package/dist/js_render/index.js.map +1 -1
  20. package/dist/middle_layer/block.cjs +7 -8
  21. package/dist/middle_layer/block.cjs.map +1 -1
  22. package/dist/middle_layer/block.d.ts +4 -4
  23. package/dist/middle_layer/block.d.ts.map +1 -1
  24. package/dist/middle_layer/block.js +7 -8
  25. package/dist/middle_layer/block.js.map +1 -1
  26. package/dist/middle_layer/block_ctx.cjs +67 -13
  27. package/dist/middle_layer/block_ctx.cjs.map +1 -1
  28. package/dist/middle_layer/block_ctx.d.ts +4 -7
  29. package/dist/middle_layer/block_ctx.d.ts.map +1 -1
  30. package/dist/middle_layer/block_ctx.js +68 -14
  31. package/dist/middle_layer/block_ctx.js.map +1 -1
  32. package/dist/middle_layer/block_ctx_unsafe.cjs +10 -3
  33. package/dist/middle_layer/block_ctx_unsafe.cjs.map +1 -1
  34. package/dist/middle_layer/block_ctx_unsafe.d.ts +1 -1
  35. package/dist/middle_layer/block_ctx_unsafe.d.ts.map +1 -1
  36. package/dist/middle_layer/block_ctx_unsafe.js +10 -3
  37. package/dist/middle_layer/block_ctx_unsafe.js.map +1 -1
  38. package/dist/middle_layer/frontend_path.cjs +1 -0
  39. package/dist/middle_layer/frontend_path.cjs.map +1 -1
  40. package/dist/middle_layer/frontend_path.js +1 -0
  41. package/dist/middle_layer/frontend_path.js.map +1 -1
  42. package/dist/middle_layer/middle_layer.cjs +1 -0
  43. package/dist/middle_layer/middle_layer.cjs.map +1 -1
  44. package/dist/middle_layer/middle_layer.d.ts +1 -1
  45. package/dist/middle_layer/middle_layer.d.ts.map +1 -1
  46. package/dist/middle_layer/middle_layer.js +1 -0
  47. package/dist/middle_layer/middle_layer.js.map +1 -1
  48. package/dist/middle_layer/project.cjs +75 -28
  49. package/dist/middle_layer/project.cjs.map +1 -1
  50. package/dist/middle_layer/project.d.ts +34 -7
  51. package/dist/middle_layer/project.d.ts.map +1 -1
  52. package/dist/middle_layer/project.js +76 -29
  53. package/dist/middle_layer/project.js.map +1 -1
  54. package/dist/middle_layer/project_overview.cjs +32 -11
  55. package/dist/middle_layer/project_overview.cjs.map +1 -1
  56. package/dist/middle_layer/project_overview.d.ts.map +1 -1
  57. package/dist/middle_layer/project_overview.js +32 -11
  58. package/dist/middle_layer/project_overview.js.map +1 -1
  59. package/dist/middle_layer/render.cjs +1 -1
  60. package/dist/middle_layer/render.cjs.map +1 -1
  61. package/dist/middle_layer/render.js +1 -1
  62. package/dist/middle_layer/render.js.map +1 -1
  63. package/dist/middle_layer/render.test.d.ts.map +1 -1
  64. package/dist/model/block_storage_helper.cjs +210 -0
  65. package/dist/model/block_storage_helper.cjs.map +1 -0
  66. package/dist/model/block_storage_helper.d.ts +98 -0
  67. package/dist/model/block_storage_helper.d.ts.map +1 -0
  68. package/dist/model/block_storage_helper.js +153 -0
  69. package/dist/model/block_storage_helper.js.map +1 -0
  70. package/dist/model/index.d.ts +2 -1
  71. package/dist/model/index.d.ts.map +1 -1
  72. package/dist/model/project_helper.cjs +177 -0
  73. package/dist/model/project_helper.cjs.map +1 -1
  74. package/dist/model/project_helper.d.ts +110 -1
  75. package/dist/model/project_helper.d.ts.map +1 -1
  76. package/dist/model/project_helper.js +178 -1
  77. package/dist/model/project_helper.js.map +1 -1
  78. package/dist/model/project_model.cjs +6 -3
  79. package/dist/model/project_model.cjs.map +1 -1
  80. package/dist/model/project_model.d.ts +3 -2
  81. package/dist/model/project_model.d.ts.map +1 -1
  82. package/dist/model/project_model.js +6 -4
  83. package/dist/model/project_model.js.map +1 -1
  84. package/dist/mutator/block-pack/block_pack.cjs +1 -2
  85. package/dist/mutator/block-pack/block_pack.cjs.map +1 -1
  86. package/dist/mutator/block-pack/block_pack.d.ts.map +1 -1
  87. package/dist/mutator/block-pack/block_pack.js +1 -2
  88. package/dist/mutator/block-pack/block_pack.js.map +1 -1
  89. package/dist/mutator/block-pack/frontend.cjs +1 -0
  90. package/dist/mutator/block-pack/frontend.cjs.map +1 -1
  91. package/dist/mutator/block-pack/frontend.js +1 -0
  92. package/dist/mutator/block-pack/frontend.js.map +1 -1
  93. package/dist/mutator/migration.cjs +64 -3
  94. package/dist/mutator/migration.cjs.map +1 -1
  95. package/dist/mutator/migration.d.ts.map +1 -1
  96. package/dist/mutator/migration.js +66 -5
  97. package/dist/mutator/migration.js.map +1 -1
  98. package/dist/mutator/project-v3.test.d.ts +2 -0
  99. package/dist/mutator/project-v3.test.d.ts.map +1 -0
  100. package/dist/mutator/project.cjs +282 -41
  101. package/dist/mutator/project.cjs.map +1 -1
  102. package/dist/mutator/project.d.ts +77 -12
  103. package/dist/mutator/project.d.ts.map +1 -1
  104. package/dist/mutator/project.js +283 -42
  105. package/dist/mutator/project.js.map +1 -1
  106. package/dist/pool/result_pool.cjs +9 -6
  107. package/dist/pool/result_pool.cjs.map +1 -1
  108. package/dist/pool/result_pool.d.ts.map +1 -1
  109. package/dist/pool/result_pool.js +9 -6
  110. package/dist/pool/result_pool.js.map +1 -1
  111. package/package.json +15 -15
  112. package/src/js_render/computable_context.ts +37 -7
  113. package/src/js_render/context.ts +12 -5
  114. package/src/js_render/index.ts +1 -1
  115. package/src/middle_layer/block.ts +13 -14
  116. package/src/middle_layer/block_ctx.ts +70 -23
  117. package/src/middle_layer/block_ctx_unsafe.ts +11 -4
  118. package/src/middle_layer/middle_layer.ts +2 -1
  119. package/src/middle_layer/project.ts +86 -40
  120. package/src/middle_layer/project_overview.ts +44 -20
  121. package/src/middle_layer/render.test.ts +1 -1
  122. package/src/middle_layer/render.ts +1 -1
  123. package/src/model/block_storage_helper.ts +213 -0
  124. package/src/model/index.ts +2 -1
  125. package/src/model/project_helper.ts +249 -1
  126. package/src/model/project_model.ts +9 -5
  127. package/src/mutator/block-pack/block_pack.ts +1 -2
  128. package/src/mutator/migration.ts +79 -6
  129. package/src/mutator/project-v3.test.ts +280 -0
  130. package/src/mutator/project.test.ts +27 -27
  131. package/src/mutator/project.ts +351 -68
  132. package/src/pool/result_pool.ts +11 -4
@@ -14,7 +14,7 @@ function isActive(cfg) {
14
14
  function computableFromCfgOrRF(env, ctx, cfgOrFh, codeWithInfo, configKey, ops = {}) {
15
15
  if (model.isConfigLambda(cfgOrFh)) {
16
16
  if (codeWithInfo === undefined)
17
- throw new Error('No code bundle.');
17
+ throw new Error('computableFromCfgOrRF: No code bundle.');
18
18
  return index.computableFromRF(env, ctx, cfgOrFh, codeWithInfo, configKey, ops);
19
19
  }
20
20
  else
@@ -1 +1 @@
1
- {"version":3,"file":"render.cjs","sources":["../../src/middle_layer/render.ts"],"sourcesContent":["import type { BlockCodeWithInfo, TypedConfigOrConfigLambda } from '@platforma-sdk/model';\nimport { isConfigLambda } from '@platforma-sdk/model';\nimport type { Computable, ComputableRenderingOps } from '@milaboratories/computable';\nimport { computableFromCfg } from '../cfg_render/executor';\nimport type { MiddleLayerEnvironment } from './middle_layer';\nimport { computableFromRF } from '../js_render';\nimport type { BlockContextAny } from './block_ctx';\nimport { hasActiveCfgComponents } from '../cfg_render/util';\n\nexport function isActive(cfg: TypedConfigOrConfigLambda): boolean {\n if (isConfigLambda(cfg)) return cfg.isActive === true;\n else return hasActiveCfgComponents(cfg);\n}\n\nexport function computableFromCfgOrRF(\n env: MiddleLayerEnvironment,\n ctx: BlockContextAny,\n cfgOrFh: TypedConfigOrConfigLambda,\n codeWithInfo: BlockCodeWithInfo | undefined,\n configKey: string,\n ops: Partial<ComputableRenderingOps> = {},\n): Computable<unknown> {\n if (isConfigLambda(cfgOrFh)) {\n if (codeWithInfo === undefined) throw new Error('No code bundle.');\n return computableFromRF(env, ctx, cfgOrFh, codeWithInfo, configKey, ops);\n } else return computableFromCfg(env.driverKit, ctx, cfgOrFh, ops);\n}\n"],"names":["isConfigLambda","hasActiveCfgComponents","computableFromRF","computableFromCfg"],"mappings":";;;;;;;AASM,SAAU,QAAQ,CAAC,GAA8B,EAAA;IACrD,IAAIA,oBAAc,CAAC,GAAG,CAAC;AAAE,QAAA,OAAO,GAAG,CAAC,QAAQ,KAAK,IAAI;;AAChD,QAAA,OAAOC,2BAAsB,CAAC,GAAG,CAAC;AACzC;AAEM,SAAU,qBAAqB,CACnC,GAA2B,EAC3B,GAAoB,EACpB,OAAkC,EAClC,YAA2C,EAC3C,SAAiB,EACjB,MAAuC,EAAE,EAAA;AAEzC,IAAA,IAAID,oBAAc,CAAC,OAAO,CAAC,EAAE;QAC3B,IAAI,YAAY,KAAK,SAAS;AAAE,YAAA,MAAM,IAAI,KAAK,CAAC,iBAAiB,CAAC;AAClE,QAAA,OAAOE,sBAAgB,CAAC,GAAG,EAAE,GAAG,EAAE,OAAO,EAAE,YAAY,EAAE,SAAS,EAAE,GAAG,CAAC;IAC1E;;AAAO,QAAA,OAAOC,0BAAiB,CAAC,GAAG,CAAC,SAAS,EAAE,GAAG,EAAE,OAAO,EAAE,GAAG,CAAC;AACnE;;;;;"}
1
+ {"version":3,"file":"render.cjs","sources":["../../src/middle_layer/render.ts"],"sourcesContent":["import type { BlockCodeWithInfo, TypedConfigOrConfigLambda } from '@platforma-sdk/model';\nimport { isConfigLambda } from '@platforma-sdk/model';\nimport type { Computable, ComputableRenderingOps } from '@milaboratories/computable';\nimport { computableFromCfg } from '../cfg_render/executor';\nimport type { MiddleLayerEnvironment } from './middle_layer';\nimport { computableFromRF } from '../js_render';\nimport type { BlockContextAny } from './block_ctx';\nimport { hasActiveCfgComponents } from '../cfg_render/util';\n\nexport function isActive(cfg: TypedConfigOrConfigLambda): boolean {\n if (isConfigLambda(cfg)) return cfg.isActive === true;\n else return hasActiveCfgComponents(cfg);\n}\n\nexport function computableFromCfgOrRF(\n env: MiddleLayerEnvironment,\n ctx: BlockContextAny,\n cfgOrFh: TypedConfigOrConfigLambda,\n codeWithInfo: BlockCodeWithInfo | undefined,\n configKey: string,\n ops: Partial<ComputableRenderingOps> = {},\n): Computable<unknown> {\n if (isConfigLambda(cfgOrFh)) {\n if (codeWithInfo === undefined) throw new Error('computableFromCfgOrRF: No code bundle.');\n return computableFromRF(env, ctx, cfgOrFh, codeWithInfo, configKey, ops);\n } else return computableFromCfg(env.driverKit, ctx, cfgOrFh, ops);\n}\n"],"names":["isConfigLambda","hasActiveCfgComponents","computableFromRF","computableFromCfg"],"mappings":";;;;;;;AASM,SAAU,QAAQ,CAAC,GAA8B,EAAA;IACrD,IAAIA,oBAAc,CAAC,GAAG,CAAC;AAAE,QAAA,OAAO,GAAG,CAAC,QAAQ,KAAK,IAAI;;AAChD,QAAA,OAAOC,2BAAsB,CAAC,GAAG,CAAC;AACzC;AAEM,SAAU,qBAAqB,CACnC,GAA2B,EAC3B,GAAoB,EACpB,OAAkC,EAClC,YAA2C,EAC3C,SAAiB,EACjB,MAAuC,EAAE,EAAA;AAEzC,IAAA,IAAID,oBAAc,CAAC,OAAO,CAAC,EAAE;QAC3B,IAAI,YAAY,KAAK,SAAS;AAAE,YAAA,MAAM,IAAI,KAAK,CAAC,wCAAwC,CAAC;AACzF,QAAA,OAAOE,sBAAgB,CAAC,GAAG,EAAE,GAAG,EAAE,OAAO,EAAE,YAAY,EAAE,SAAS,EAAE,GAAG,CAAC;IAC1E;;AAAO,QAAA,OAAOC,0BAAiB,CAAC,GAAG,CAAC,SAAS,EAAE,GAAG,EAAE,OAAO,EAAE,GAAG,CAAC;AACnE;;;;;"}
@@ -12,7 +12,7 @@ function isActive(cfg) {
12
12
  function computableFromCfgOrRF(env, ctx, cfgOrFh, codeWithInfo, configKey, ops = {}) {
13
13
  if (isConfigLambda(cfgOrFh)) {
14
14
  if (codeWithInfo === undefined)
15
- throw new Error('No code bundle.');
15
+ throw new Error('computableFromCfgOrRF: No code bundle.');
16
16
  return computableFromRF(env, ctx, cfgOrFh, codeWithInfo, configKey, ops);
17
17
  }
18
18
  else
@@ -1 +1 @@
1
- {"version":3,"file":"render.js","sources":["../../src/middle_layer/render.ts"],"sourcesContent":["import type { BlockCodeWithInfo, TypedConfigOrConfigLambda } from '@platforma-sdk/model';\nimport { isConfigLambda } from '@platforma-sdk/model';\nimport type { Computable, ComputableRenderingOps } from '@milaboratories/computable';\nimport { computableFromCfg } from '../cfg_render/executor';\nimport type { MiddleLayerEnvironment } from './middle_layer';\nimport { computableFromRF } from '../js_render';\nimport type { BlockContextAny } from './block_ctx';\nimport { hasActiveCfgComponents } from '../cfg_render/util';\n\nexport function isActive(cfg: TypedConfigOrConfigLambda): boolean {\n if (isConfigLambda(cfg)) return cfg.isActive === true;\n else return hasActiveCfgComponents(cfg);\n}\n\nexport function computableFromCfgOrRF(\n env: MiddleLayerEnvironment,\n ctx: BlockContextAny,\n cfgOrFh: TypedConfigOrConfigLambda,\n codeWithInfo: BlockCodeWithInfo | undefined,\n configKey: string,\n ops: Partial<ComputableRenderingOps> = {},\n): Computable<unknown> {\n if (isConfigLambda(cfgOrFh)) {\n if (codeWithInfo === undefined) throw new Error('No code bundle.');\n return computableFromRF(env, ctx, cfgOrFh, codeWithInfo, configKey, ops);\n } else return computableFromCfg(env.driverKit, ctx, cfgOrFh, ops);\n}\n"],"names":[],"mappings":";;;;;AASM,SAAU,QAAQ,CAAC,GAA8B,EAAA;IACrD,IAAI,cAAc,CAAC,GAAG,CAAC;AAAE,QAAA,OAAO,GAAG,CAAC,QAAQ,KAAK,IAAI;;AAChD,QAAA,OAAO,sBAAsB,CAAC,GAAG,CAAC;AACzC;AAEM,SAAU,qBAAqB,CACnC,GAA2B,EAC3B,GAAoB,EACpB,OAAkC,EAClC,YAA2C,EAC3C,SAAiB,EACjB,MAAuC,EAAE,EAAA;AAEzC,IAAA,IAAI,cAAc,CAAC,OAAO,CAAC,EAAE;QAC3B,IAAI,YAAY,KAAK,SAAS;AAAE,YAAA,MAAM,IAAI,KAAK,CAAC,iBAAiB,CAAC;AAClE,QAAA,OAAO,gBAAgB,CAAC,GAAG,EAAE,GAAG,EAAE,OAAO,EAAE,YAAY,EAAE,SAAS,EAAE,GAAG,CAAC;IAC1E;;AAAO,QAAA,OAAO,iBAAiB,CAAC,GAAG,CAAC,SAAS,EAAE,GAAG,EAAE,OAAO,EAAE,GAAG,CAAC;AACnE;;;;"}
1
+ {"version":3,"file":"render.js","sources":["../../src/middle_layer/render.ts"],"sourcesContent":["import type { BlockCodeWithInfo, TypedConfigOrConfigLambda } from '@platforma-sdk/model';\nimport { isConfigLambda } from '@platforma-sdk/model';\nimport type { Computable, ComputableRenderingOps } from '@milaboratories/computable';\nimport { computableFromCfg } from '../cfg_render/executor';\nimport type { MiddleLayerEnvironment } from './middle_layer';\nimport { computableFromRF } from '../js_render';\nimport type { BlockContextAny } from './block_ctx';\nimport { hasActiveCfgComponents } from '../cfg_render/util';\n\nexport function isActive(cfg: TypedConfigOrConfigLambda): boolean {\n if (isConfigLambda(cfg)) return cfg.isActive === true;\n else return hasActiveCfgComponents(cfg);\n}\n\nexport function computableFromCfgOrRF(\n env: MiddleLayerEnvironment,\n ctx: BlockContextAny,\n cfgOrFh: TypedConfigOrConfigLambda,\n codeWithInfo: BlockCodeWithInfo | undefined,\n configKey: string,\n ops: Partial<ComputableRenderingOps> = {},\n): Computable<unknown> {\n if (isConfigLambda(cfgOrFh)) {\n if (codeWithInfo === undefined) throw new Error('computableFromCfgOrRF: No code bundle.');\n return computableFromRF(env, ctx, cfgOrFh, codeWithInfo, configKey, ops);\n } else return computableFromCfg(env.driverKit, ctx, cfgOrFh, ops);\n}\n"],"names":[],"mappings":";;;;;AASM,SAAU,QAAQ,CAAC,GAA8B,EAAA;IACrD,IAAI,cAAc,CAAC,GAAG,CAAC;AAAE,QAAA,OAAO,GAAG,CAAC,QAAQ,KAAK,IAAI;;AAChD,QAAA,OAAO,sBAAsB,CAAC,GAAG,CAAC;AACzC;AAEM,SAAU,qBAAqB,CACnC,GAA2B,EAC3B,GAAoB,EACpB,OAAkC,EAClC,YAA2C,EAC3C,SAAiB,EACjB,MAAuC,EAAE,EAAA;AAEzC,IAAA,IAAI,cAAc,CAAC,OAAO,CAAC,EAAE;QAC3B,IAAI,YAAY,KAAK,SAAS;AAAE,YAAA,MAAM,IAAI,KAAK,CAAC,wCAAwC,CAAC;AACzF,QAAA,OAAO,gBAAgB,CAAC,GAAG,EAAE,GAAG,EAAE,OAAO,EAAE,YAAY,EAAE,SAAS,EAAE,GAAG,CAAC;IAC1E;;AAAO,QAAA,OAAO,iBAAiB,CAAC,GAAG,CAAC,SAAS,EAAE,GAAG,EAAE,OAAO,EAAE,GAAG,CAAC;AACnE;;;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"render.test.d.ts","sourceRoot":"","sources":["../../src/middle_layer/render.test.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAE7C,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAGpC,wBAAsB,MAAM,CAC1B,EAAE,EAAE,CAAC,EAAE,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,GACzD,OAAO,CAAC,IAAI,CAAC,CAqBf;AAED,wBAAsB,cAAc,CAAC,GAAG,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,GAAE,MAAa,iBAsBzF"}
1
+ {"version":3,"file":"render.test.d.ts","sourceRoot":"","sources":["../../src/middle_layer/render.test.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAE7C,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAGpC,wBAAsB,MAAM,CAC1B,EAAE,EAAE,CAAC,EAAE,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,GACzD,OAAO,CAAC,IAAI,CAAC,CAsBf;AAED,wBAAsB,cAAc,CAAC,GAAG,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,GAAE,MAAa,iBAsBzF"}
@@ -0,0 +1,210 @@
1
+ 'use strict';
2
+
3
+ var model = require('@platforma-sdk/model');
4
+
5
+ /**
6
+ * Block Storage Helper - Middle layer utilities for BlockStorage operations.
7
+ *
8
+ * This module provides the bridge between the SDK's BlockStorage abstraction
9
+ * and the middle layer's storage operations. Block developers never interact
10
+ * with this - they only see `state`.
11
+ *
12
+ * @module block_storage_helper
13
+ */
14
+ /**
15
+ * Parses raw blockStorage data (from resource tree) into BlockStorage.
16
+ * Handles both legacy format (raw state) and new format (BlockStorage).
17
+ *
18
+ * @param rawData - Raw data from blockStorage field (may be string or parsed object)
19
+ * @returns Normalized BlockStorage object
20
+ */
21
+ function parseBlockStorage(rawData) {
22
+ if (rawData === undefined || rawData === null) {
23
+ return model.createBlockStorage({});
24
+ }
25
+ // If it's a string, parse it first
26
+ if (typeof rawData === 'string') {
27
+ try {
28
+ const parsed = JSON.parse(rawData);
29
+ return model.normalizeBlockStorage(parsed);
30
+ }
31
+ catch {
32
+ // If parsing fails, treat the string as the state itself
33
+ return model.createBlockStorage(rawData);
34
+ }
35
+ }
36
+ return model.normalizeBlockStorage(rawData);
37
+ }
38
+ /**
39
+ * Extracts the user-facing data from BlockStorage.
40
+ * This is what block developers see in their .args() callbacks.
41
+ *
42
+ * @param storage - The BlockStorage object
43
+ * @returns The data value that developers work with
44
+ */
45
+ function extractDataForDeveloper(storage) {
46
+ return model.getStorageData(storage);
47
+ }
48
+ /**
49
+ * Creates a new BlockStorage with updated state.
50
+ * Used when setState is called from the frontend.
51
+ *
52
+ * @param currentStorage - Current BlockStorage (or undefined for new blocks)
53
+ * @param newState - New state from developer
54
+ * @param handlers - Optional custom handlers (defaults to standard handlers)
55
+ * @returns Updated BlockStorage
56
+ */
57
+ function applyStateUpdate(currentStorage, newState, handlers = model.defaultBlockStorageHandlers) {
58
+ const storage = currentStorage ?? model.createBlockStorage({});
59
+ const transform = handlers.transformStateForStorage ?? model.defaultBlockStorageHandlers.transformStateForStorage;
60
+ return transform(storage, newState);
61
+ }
62
+ /**
63
+ * Serializes BlockStorage for writing to the resource tree.
64
+ *
65
+ * @param storage - The BlockStorage to serialize
66
+ * @returns JSON string
67
+ */
68
+ function serializeBlockStorage(storage) {
69
+ return JSON.stringify(storage);
70
+ }
71
+ /**
72
+ * Checks if the storage needs migration based on version.
73
+ *
74
+ * @param storage - Current BlockStorage
75
+ * @param targetVersion - Target schema version
76
+ * @returns true if migration is needed
77
+ */
78
+ function needsMigration(storage, targetVersion) {
79
+ return model.getStorageDataVersion(storage) < targetVersion;
80
+ }
81
+ /**
82
+ * Migrates BlockStorage from one version to another.
83
+ *
84
+ * @param storage - Current BlockStorage
85
+ * @param fromVersion - Source version
86
+ * @param toVersion - Target version
87
+ * @param handlers - Optional custom handlers
88
+ * @returns Migrated BlockStorage
89
+ */
90
+ function migrateBlockStorage(storage, fromVersion, toVersion, handlers = model.defaultBlockStorageHandlers) {
91
+ const migrate = handlers.migrateStorage ?? model.defaultBlockStorageHandlers.migrateStorage;
92
+ return migrate(storage, fromVersion, toVersion);
93
+ }
94
+ /**
95
+ * Checks if the raw data is in legacy V1/V2 format.
96
+ * V1/V2 blocks stored { args, uiState } directly, not wrapped in BlockStorage.
97
+ *
98
+ * @param rawData - Raw data from blockStorage field
99
+ * @returns true if data is in legacy format
100
+ */
101
+ function isLegacyV1V2Format(rawData) {
102
+ if (rawData === null || typeof rawData !== 'object')
103
+ return false;
104
+ // If it has the discriminator, it's BlockStorage format
105
+ if (model.isBlockStorage(rawData))
106
+ return false;
107
+ const obj = rawData;
108
+ // Legacy format has 'args' and/or 'uiState' at top level, no discriminator
109
+ return ('args' in obj || 'uiState' in obj);
110
+ }
111
+ /**
112
+ * Converts legacy V1/V2 format to BlockStorage.
113
+ * For backward compatibility with existing blocks.
114
+ *
115
+ * @param legacyData - Data in { args, uiState } format
116
+ * @returns BlockStorage with legacy data as state
117
+ */
118
+ function convertLegacyToBlockStorage(legacyData) {
119
+ return model.createBlockStorage(legacyData, 1);
120
+ }
121
+ /**
122
+ * Smart parser that handles all storage formats:
123
+ * - New BlockStorage format
124
+ * - Legacy V1/V2 format ({ args, uiState })
125
+ * - Raw state (any other format)
126
+ *
127
+ * @param rawData - Raw data from blockStorage field
128
+ * @returns Normalized BlockStorage
129
+ */
130
+ function parseBlockStorageSmart(rawData) {
131
+ if (rawData === undefined || rawData === null) {
132
+ return model.createBlockStorage({});
133
+ }
134
+ // If it's a string, parse it first
135
+ let parsed = rawData;
136
+ if (typeof rawData === 'string') {
137
+ try {
138
+ parsed = JSON.parse(rawData);
139
+ }
140
+ catch {
141
+ // If parsing fails, treat the string as the state itself
142
+ return model.createBlockStorage(rawData);
143
+ }
144
+ }
145
+ // Check for legacy V1/V2 format
146
+ if (isLegacyV1V2Format(parsed)) {
147
+ return convertLegacyToBlockStorage(parsed);
148
+ }
149
+ // Use standard normalization
150
+ return model.normalizeBlockStorage(parsed);
151
+ }
152
+
153
+ Object.defineProperty(exports, "BLOCK_STORAGE_KEY", {
154
+ enumerable: true,
155
+ get: function () { return model.BLOCK_STORAGE_KEY; }
156
+ });
157
+ Object.defineProperty(exports, "BLOCK_STORAGE_SCHEMA_VERSION", {
158
+ enumerable: true,
159
+ get: function () { return model.BLOCK_STORAGE_SCHEMA_VERSION; }
160
+ });
161
+ Object.defineProperty(exports, "createBlockStorage", {
162
+ enumerable: true,
163
+ get: function () { return model.createBlockStorage; }
164
+ });
165
+ Object.defineProperty(exports, "defaultBlockStorageHandlers", {
166
+ enumerable: true,
167
+ get: function () { return model.defaultBlockStorageHandlers; }
168
+ });
169
+ Object.defineProperty(exports, "getPluginData", {
170
+ enumerable: true,
171
+ get: function () { return model.getPluginData; }
172
+ });
173
+ Object.defineProperty(exports, "getStorageData", {
174
+ enumerable: true,
175
+ get: function () { return model.getStorageData; }
176
+ });
177
+ Object.defineProperty(exports, "getStorageDataVersion", {
178
+ enumerable: true,
179
+ get: function () { return model.getStorageDataVersion; }
180
+ });
181
+ Object.defineProperty(exports, "isBlockStorage", {
182
+ enumerable: true,
183
+ get: function () { return model.isBlockStorage; }
184
+ });
185
+ Object.defineProperty(exports, "normalizeBlockStorage", {
186
+ enumerable: true,
187
+ get: function () { return model.normalizeBlockStorage; }
188
+ });
189
+ Object.defineProperty(exports, "setPluginData", {
190
+ enumerable: true,
191
+ get: function () { return model.setPluginData; }
192
+ });
193
+ Object.defineProperty(exports, "updateStorageData", {
194
+ enumerable: true,
195
+ get: function () { return model.updateStorageData; }
196
+ });
197
+ Object.defineProperty(exports, "updateStorageDataVersion", {
198
+ enumerable: true,
199
+ get: function () { return model.updateStorageDataVersion; }
200
+ });
201
+ exports.applyStateUpdate = applyStateUpdate;
202
+ exports.convertLegacyToBlockStorage = convertLegacyToBlockStorage;
203
+ exports.extractDataForDeveloper = extractDataForDeveloper;
204
+ exports.isLegacyV1V2Format = isLegacyV1V2Format;
205
+ exports.migrateBlockStorage = migrateBlockStorage;
206
+ exports.needsMigration = needsMigration;
207
+ exports.parseBlockStorage = parseBlockStorage;
208
+ exports.parseBlockStorageSmart = parseBlockStorageSmart;
209
+ exports.serializeBlockStorage = serializeBlockStorage;
210
+ //# sourceMappingURL=block_storage_helper.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"block_storage_helper.cjs","sources":["../../src/model/block_storage_helper.ts"],"sourcesContent":["/**\n * Block Storage Helper - Middle layer utilities for BlockStorage operations.\n *\n * This module provides the bridge between the SDK's BlockStorage abstraction\n * and the middle layer's storage operations. Block developers never interact\n * with this - they only see `state`.\n *\n * @module block_storage_helper\n */\n\nimport type {\n BlockStorage,\n BlockStorageHandlers,\n} from '@platforma-sdk/model';\nimport {\n BLOCK_STORAGE_KEY,\n BLOCK_STORAGE_SCHEMA_VERSION,\n createBlockStorage,\n defaultBlockStorageHandlers,\n getPluginData,\n getStorageData,\n getStorageDataVersion,\n isBlockStorage,\n normalizeBlockStorage,\n setPluginData,\n updateStorageData,\n updateStorageDataVersion,\n} from '@platforma-sdk/model';\n\n// Re-export types for convenience\nexport type { BlockStorage, BlockStorageHandlers };\n\n// Re-export utilities that middle layer needs\nexport {\n BLOCK_STORAGE_KEY,\n BLOCK_STORAGE_SCHEMA_VERSION,\n createBlockStorage,\n defaultBlockStorageHandlers,\n getPluginData,\n getStorageData,\n getStorageDataVersion,\n isBlockStorage,\n normalizeBlockStorage,\n setPluginData,\n updateStorageData,\n updateStorageDataVersion,\n};\n\n/**\n * Parses raw blockStorage data (from resource tree) into BlockStorage.\n * Handles both legacy format (raw state) and new format (BlockStorage).\n *\n * @param rawData - Raw data from blockStorage field (may be string or parsed object)\n * @returns Normalized BlockStorage object\n */\nexport function parseBlockStorage<TState = unknown>(rawData: unknown): BlockStorage<TState> {\n if (rawData === undefined || rawData === null) {\n return createBlockStorage<TState>({} as TState);\n }\n\n // If it's a string, parse it first\n if (typeof rawData === 'string') {\n try {\n const parsed = JSON.parse(rawData);\n return normalizeBlockStorage<TState>(parsed);\n } catch {\n // If parsing fails, treat the string as the state itself\n return createBlockStorage(rawData as unknown as TState);\n }\n }\n\n return normalizeBlockStorage<TState>(rawData);\n}\n\n/**\n * Extracts the user-facing data from BlockStorage.\n * This is what block developers see in their .args() callbacks.\n *\n * @param storage - The BlockStorage object\n * @returns The data value that developers work with\n */\nexport function extractDataForDeveloper<TState>(storage: BlockStorage<TState>): TState {\n return getStorageData(storage);\n}\n\n/**\n * Creates a new BlockStorage with updated state.\n * Used when setState is called from the frontend.\n *\n * @param currentStorage - Current BlockStorage (or undefined for new blocks)\n * @param newState - New state from developer\n * @param handlers - Optional custom handlers (defaults to standard handlers)\n * @returns Updated BlockStorage\n */\nexport function applyStateUpdate<TState>(\n currentStorage: BlockStorage<TState> | undefined,\n newState: TState,\n handlers: BlockStorageHandlers<TState> = defaultBlockStorageHandlers as BlockStorageHandlers<TState>,\n): BlockStorage<TState> {\n const storage = currentStorage ?? createBlockStorage<TState>({} as TState);\n const transform = handlers.transformStateForStorage ?? defaultBlockStorageHandlers.transformStateForStorage;\n return transform(storage, newState) as BlockStorage<TState>;\n}\n\n/**\n * Serializes BlockStorage for writing to the resource tree.\n *\n * @param storage - The BlockStorage to serialize\n * @returns JSON string\n */\nexport function serializeBlockStorage(storage: BlockStorage): string {\n return JSON.stringify(storage);\n}\n\n/**\n * Checks if the storage needs migration based on version.\n *\n * @param storage - Current BlockStorage\n * @param targetVersion - Target schema version\n * @returns true if migration is needed\n */\nexport function needsMigration(storage: BlockStorage, targetVersion: number): boolean {\n return getStorageDataVersion(storage) < targetVersion;\n}\n\n/**\n * Migrates BlockStorage from one version to another.\n *\n * @param storage - Current BlockStorage\n * @param fromVersion - Source version\n * @param toVersion - Target version\n * @param handlers - Optional custom handlers\n * @returns Migrated BlockStorage\n */\nexport function migrateBlockStorage<TState>(\n storage: BlockStorage<TState>,\n fromVersion: number,\n toVersion: number,\n handlers: BlockStorageHandlers<TState> = defaultBlockStorageHandlers as BlockStorageHandlers<TState>,\n): BlockStorage<TState> {\n const migrate = handlers.migrateStorage ?? defaultBlockStorageHandlers.migrateStorage;\n return migrate(storage, fromVersion, toVersion) as BlockStorage<TState>;\n}\n\n/**\n * V1/V2 legacy format - state stored as { args, uiState }\n */\nexport interface LegacyV1V2State {\n args?: unknown;\n uiState?: unknown;\n}\n\n/**\n * Checks if the raw data is in legacy V1/V2 format.\n * V1/V2 blocks stored { args, uiState } directly, not wrapped in BlockStorage.\n *\n * @param rawData - Raw data from blockStorage field\n * @returns true if data is in legacy format\n */\nexport function isLegacyV1V2Format(rawData: unknown): rawData is LegacyV1V2State {\n if (rawData === null || typeof rawData !== 'object') return false;\n // If it has the discriminator, it's BlockStorage format\n if (isBlockStorage(rawData)) return false;\n\n const obj = rawData as Record<string, unknown>;\n // Legacy format has 'args' and/or 'uiState' at top level, no discriminator\n return ('args' in obj || 'uiState' in obj);\n}\n\n/**\n * Converts legacy V1/V2 format to BlockStorage.\n * For backward compatibility with existing blocks.\n *\n * @param legacyData - Data in { args, uiState } format\n * @returns BlockStorage with legacy data as state\n */\nexport function convertLegacyToBlockStorage(legacyData: LegacyV1V2State): BlockStorage<LegacyV1V2State> {\n return createBlockStorage(legacyData, 1);\n}\n\n/**\n * Smart parser that handles all storage formats:\n * - New BlockStorage format\n * - Legacy V1/V2 format ({ args, uiState })\n * - Raw state (any other format)\n *\n * @param rawData - Raw data from blockStorage field\n * @returns Normalized BlockStorage\n */\nexport function parseBlockStorageSmart<TState = unknown>(rawData: unknown): BlockStorage<TState> {\n if (rawData === undefined || rawData === null) {\n return createBlockStorage<TState>({} as TState);\n }\n\n // If it's a string, parse it first\n let parsed = rawData;\n if (typeof rawData === 'string') {\n try {\n parsed = JSON.parse(rawData);\n } catch {\n // If parsing fails, treat the string as the state itself\n return createBlockStorage(rawData as unknown as TState);\n }\n }\n\n // Check for legacy V1/V2 format\n if (isLegacyV1V2Format(parsed)) {\n return convertLegacyToBlockStorage(parsed) as unknown as BlockStorage<TState>;\n }\n\n // Use standard normalization\n return normalizeBlockStorage<TState>(parsed);\n}\n"],"names":["createBlockStorage","normalizeBlockStorage","getStorageData","defaultBlockStorageHandlers","getStorageDataVersion","isBlockStorage"],"mappings":";;;;AAAA;;;;;;;;AAQG;AAwCH;;;;;;AAMG;AACG,SAAU,iBAAiB,CAAmB,OAAgB,EAAA;IACl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le layer utilities for BlockStorage operations.
3
+ *
4
+ * This module provides the bridge between the SDK's BlockStorage abstraction
5
+ * and the middle layer's storage operations. Block developers never interact
6
+ * with this - they only see `state`.
7
+ *
8
+ * @module block_storage_helper
9
+ */
10
+ import type { BlockStorage, BlockStorageHandlers } from '@platforma-sdk/model';
11
+ import { BLOCK_STORAGE_KEY, BLOCK_STORAGE_SCHEMA_VERSION, createBlockStorage, defaultBlockStorageHandlers, getPluginData, getStorageData, getStorageDataVersion, isBlockStorage, normalizeBlockStorage, setPluginData, updateStorageData, updateStorageDataVersion } from '@platforma-sdk/model';
12
+ export type { BlockStorage, BlockStorageHandlers };
13
+ export { BLOCK_STORAGE_KEY, BLOCK_STORAGE_SCHEMA_VERSION, createBlockStorage, defaultBlockStorageHandlers, getPluginData, getStorageData, getStorageDataVersion, isBlockStorage, normalizeBlockStorage, setPluginData, updateStorageData, updateStorageDataVersion, };
14
+ /**
15
+ * Parses raw blockStorage data (from resource tree) into BlockStorage.
16
+ * Handles both legacy format (raw state) and new format (BlockStorage).
17
+ *
18
+ * @param rawData - Raw data from blockStorage field (may be string or parsed object)
19
+ * @returns Normalized BlockStorage object
20
+ */
21
+ export declare function parseBlockStorage<TState = unknown>(rawData: unknown): BlockStorage<TState>;
22
+ /**
23
+ * Extracts the user-facing data from BlockStorage.
24
+ * This is what block developers see in their .args() callbacks.
25
+ *
26
+ * @param storage - The BlockStorage object
27
+ * @returns The data value that developers work with
28
+ */
29
+ export declare function extractDataForDeveloper<TState>(storage: BlockStorage<TState>): TState;
30
+ /**
31
+ * Creates a new BlockStorage with updated state.
32
+ * Used when setState is called from the frontend.
33
+ *
34
+ * @param currentStorage - Current BlockStorage (or undefined for new blocks)
35
+ * @param newState - New state from developer
36
+ * @param handlers - Optional custom handlers (defaults to standard handlers)
37
+ * @returns Updated BlockStorage
38
+ */
39
+ export declare function applyStateUpdate<TState>(currentStorage: BlockStorage<TState> | undefined, newState: TState, handlers?: BlockStorageHandlers<TState>): BlockStorage<TState>;
40
+ /**
41
+ * Serializes BlockStorage for writing to the resource tree.
42
+ *
43
+ * @param storage - The BlockStorage to serialize
44
+ * @returns JSON string
45
+ */
46
+ export declare function serializeBlockStorage(storage: BlockStorage): string;
47
+ /**
48
+ * Checks if the storage needs migration based on version.
49
+ *
50
+ * @param storage - Current BlockStorage
51
+ * @param targetVersion - Target schema version
52
+ * @returns true if migration is needed
53
+ */
54
+ export declare function needsMigration(storage: BlockStorage, targetVersion: number): boolean;
55
+ /**
56
+ * Migrates BlockStorage from one version to another.
57
+ *
58
+ * @param storage - Current BlockStorage
59
+ * @param fromVersion - Source version
60
+ * @param toVersion - Target version
61
+ * @param handlers - Optional custom handlers
62
+ * @returns Migrated BlockStorage
63
+ */
64
+ export declare function migrateBlockStorage<TState>(storage: BlockStorage<TState>, fromVersion: number, toVersion: number, handlers?: BlockStorageHandlers<TState>): BlockStorage<TState>;
65
+ /**
66
+ * V1/V2 legacy format - state stored as { args, uiState }
67
+ */
68
+ export interface LegacyV1V2State {
69
+ args?: unknown;
70
+ uiState?: unknown;
71
+ }
72
+ /**
73
+ * Checks if the raw data is in legacy V1/V2 format.
74
+ * V1/V2 blocks stored { args, uiState } directly, not wrapped in BlockStorage.
75
+ *
76
+ * @param rawData - Raw data from blockStorage field
77
+ * @returns true if data is in legacy format
78
+ */
79
+ export declare function isLegacyV1V2Format(rawData: unknown): rawData is LegacyV1V2State;
80
+ /**
81
+ * Converts legacy V1/V2 format to BlockStorage.
82
+ * For backward compatibility with existing blocks.
83
+ *
84
+ * @param legacyData - Data in { args, uiState } format
85
+ * @returns BlockStorage with legacy data as state
86
+ */
87
+ export declare function convertLegacyToBlockStorage(legacyData: LegacyV1V2State): BlockStorage<LegacyV1V2State>;
88
+ /**
89
+ * Smart parser that handles all storage formats:
90
+ * - New BlockStorage format
91
+ * - Legacy V1/V2 format ({ args, uiState })
92
+ * - Raw state (any other format)
93
+ *
94
+ * @param rawData - Raw data from blockStorage field
95
+ * @returns Normalized BlockStorage
96
+ */
97
+ export declare function parseBlockStorageSmart<TState = unknown>(rawData: unknown): BlockStorage<TState>;
98
+ //# sourceMappingURL=block_storage_helper.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"block_storage_helper.d.ts","sourceRoot":"","sources":["../../src/model/block_storage_helper.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EACV,YAAY,EACZ,oBAAoB,EACrB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EACL,iBAAiB,EACjB,4BAA4B,EAC5B,kBAAkB,EAClB,2BAA2B,EAC3B,aAAa,EACb,cAAc,EACd,qBAAqB,EACrB,cAAc,EACd,qBAAqB,EACrB,aAAa,EACb,iBAAiB,EACjB,wBAAwB,EACzB,MAAM,sBAAsB,CAAC;AAG9B,YAAY,EAAE,YAAY,EAAE,oBAAoB,EAAE,CAAC;AAGnD,OAAO,EACL,iBAAiB,EACjB,4BAA4B,EAC5B,kBAAkB,EAClB,2BAA2B,EAC3B,aAAa,EACb,cAAc,EACd,qBAAqB,EACrB,cAAc,EACd,qBAAqB,EACrB,aAAa,EACb,iBAAiB,EACjB,wBAAwB,GACzB,CAAC;AAEF;;;;;;GAMG;AACH,wBAAgB,iBAAiB,CAAC,MAAM,GAAG,OAAO,EAAE,OAAO,EAAE,OAAO,GAAG,YAAY,CAAC,MAAM,CAAC,CAiB1F;AAED;;;;;;GAMG;AACH,wBAAgB,uBAAuB,CAAC,MAAM,EAAE,OAAO,EAAE,YAAY,CAAC,MAAM,CAAC,GAAG,MAAM,CAErF;AAED;;;;;;;;GAQG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EACrC,cAAc,EAAE,YAAY,CAAC,MAAM,CAAC,GAAG,SAAS,EAChD,QAAQ,EAAE,MAAM,EAChB,QAAQ,GAAE,oBAAoB,CAAC,MAAM,CAA+D,GACnG,YAAY,CAAC,MAAM,CAAC,CAItB;AAED;;;;;GAKG;AACH,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,YAAY,GAAG,MAAM,CAEnE;AAED;;;;;;GAMG;AACH,wBAAgB,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,GAAG,OAAO,CAEpF;AAED;;;;;;;;GAQG;AACH,wBAAgB,mBAAmB,CAAC,MAAM,EACxC,OAAO,EAAE,YAAY,CAAC,MAAM,CAAC,EAC7B,WAAW,EAAE,MAAM,EACnB,SAAS,EAAE,MAAM,EACjB,QAAQ,GAAE,oBAAoB,CAAC,MAAM,CAA+D,GACnG,YAAY,CAAC,MAAM,CAAC,CAGtB;AAED;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AAED;;;;;;GAMG;AACH,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,IAAI,eAAe,CAQ/E;AAED;;;;;;GAMG;AACH,wBAAgB,2BAA2B,CAAC,UAAU,EAAE,eAAe,GAAG,YAAY,CAAC,eAAe,CAAC,CAEtG;AAED;;;;;;;;GAQG;AACH,wBAAgB,sBAAsB,CAAC,MAAM,GAAG,OAAO,EAAE,OAAO,EAAE,OAAO,GAAG,YAAY,CAAC,MAAM,CAAC,CAuB/F"}
@@ -0,0 +1,153 @@
1
+ import { defaultBlockStorageHandlers, createBlockStorage, normalizeBlockStorage, getStorageData, getStorageDataVersion, isBlockStorage } from '@platforma-sdk/model';
2
+ export { BLOCK_STORAGE_KEY, BLOCK_STORAGE_SCHEMA_VERSION, createBlockStorage, defaultBlockStorageHandlers, getPluginData, getStorageData, getStorageDataVersion, isBlockStorage, normalizeBlockStorage, setPluginData, updateStorageData, updateStorageDataVersion } from '@platforma-sdk/model';
3
+
4
+ /**
5
+ * Block Storage Helper - Middle layer utilities for BlockStorage operations.
6
+ *
7
+ * This module provides the bridge between the SDK's BlockStorage abstraction
8
+ * and the middle layer's storage operations. Block developers never interact
9
+ * with this - they only see `state`.
10
+ *
11
+ * @module block_storage_helper
12
+ */
13
+ /**
14
+ * Parses raw blockStorage data (from resource tree) into BlockStorage.
15
+ * Handles both legacy format (raw state) and new format (BlockStorage).
16
+ *
17
+ * @param rawData - Raw data from blockStorage field (may be string or parsed object)
18
+ * @returns Normalized BlockStorage object
19
+ */
20
+ function parseBlockStorage(rawData) {
21
+ if (rawData === undefined || rawData === null) {
22
+ return createBlockStorage({});
23
+ }
24
+ // If it's a string, parse it first
25
+ if (typeof rawData === 'string') {
26
+ try {
27
+ const parsed = JSON.parse(rawData);
28
+ return normalizeBlockStorage(parsed);
29
+ }
30
+ catch {
31
+ // If parsing fails, treat the string as the state itself
32
+ return createBlockStorage(rawData);
33
+ }
34
+ }
35
+ return normalizeBlockStorage(rawData);
36
+ }
37
+ /**
38
+ * Extracts the user-facing data from BlockStorage.
39
+ * This is what block developers see in their .args() callbacks.
40
+ *
41
+ * @param storage - The BlockStorage object
42
+ * @returns The data value that developers work with
43
+ */
44
+ function extractDataForDeveloper(storage) {
45
+ return getStorageData(storage);
46
+ }
47
+ /**
48
+ * Creates a new BlockStorage with updated state.
49
+ * Used when setState is called from the frontend.
50
+ *
51
+ * @param currentStorage - Current BlockStorage (or undefined for new blocks)
52
+ * @param newState - New state from developer
53
+ * @param handlers - Optional custom handlers (defaults to standard handlers)
54
+ * @returns Updated BlockStorage
55
+ */
56
+ function applyStateUpdate(currentStorage, newState, handlers = defaultBlockStorageHandlers) {
57
+ const storage = currentStorage ?? createBlockStorage({});
58
+ const transform = handlers.transformStateForStorage ?? defaultBlockStorageHandlers.transformStateForStorage;
59
+ return transform(storage, newState);
60
+ }
61
+ /**
62
+ * Serializes BlockStorage for writing to the resource tree.
63
+ *
64
+ * @param storage - The BlockStorage to serialize
65
+ * @returns JSON string
66
+ */
67
+ function serializeBlockStorage(storage) {
68
+ return JSON.stringify(storage);
69
+ }
70
+ /**
71
+ * Checks if the storage needs migration based on version.
72
+ *
73
+ * @param storage - Current BlockStorage
74
+ * @param targetVersion - Target schema version
75
+ * @returns true if migration is needed
76
+ */
77
+ function needsMigration(storage, targetVersion) {
78
+ return getStorageDataVersion(storage) < targetVersion;
79
+ }
80
+ /**
81
+ * Migrates BlockStorage from one version to another.
82
+ *
83
+ * @param storage - Current BlockStorage
84
+ * @param fromVersion - Source version
85
+ * @param toVersion - Target version
86
+ * @param handlers - Optional custom handlers
87
+ * @returns Migrated BlockStorage
88
+ */
89
+ function migrateBlockStorage(storage, fromVersion, toVersion, handlers = defaultBlockStorageHandlers) {
90
+ const migrate = handlers.migrateStorage ?? defaultBlockStorageHandlers.migrateStorage;
91
+ return migrate(storage, fromVersion, toVersion);
92
+ }
93
+ /**
94
+ * Checks if the raw data is in legacy V1/V2 format.
95
+ * V1/V2 blocks stored { args, uiState } directly, not wrapped in BlockStorage.
96
+ *
97
+ * @param rawData - Raw data from blockStorage field
98
+ * @returns true if data is in legacy format
99
+ */
100
+ function isLegacyV1V2Format(rawData) {
101
+ if (rawData === null || typeof rawData !== 'object')
102
+ return false;
103
+ // If it has the discriminator, it's BlockStorage format
104
+ if (isBlockStorage(rawData))
105
+ return false;
106
+ const obj = rawData;
107
+ // Legacy format has 'args' and/or 'uiState' at top level, no discriminator
108
+ return ('args' in obj || 'uiState' in obj);
109
+ }
110
+ /**
111
+ * Converts legacy V1/V2 format to BlockStorage.
112
+ * For backward compatibility with existing blocks.
113
+ *
114
+ * @param legacyData - Data in { args, uiState } format
115
+ * @returns BlockStorage with legacy data as state
116
+ */
117
+ function convertLegacyToBlockStorage(legacyData) {
118
+ return createBlockStorage(legacyData, 1);
119
+ }
120
+ /**
121
+ * Smart parser that handles all storage formats:
122
+ * - New BlockStorage format
123
+ * - Legacy V1/V2 format ({ args, uiState })
124
+ * - Raw state (any other format)
125
+ *
126
+ * @param rawData - Raw data from blockStorage field
127
+ * @returns Normalized BlockStorage
128
+ */
129
+ function parseBlockStorageSmart(rawData) {
130
+ if (rawData === undefined || rawData === null) {
131
+ return createBlockStorage({});
132
+ }
133
+ // If it's a string, parse it first
134
+ let parsed = rawData;
135
+ if (typeof rawData === 'string') {
136
+ try {
137
+ parsed = JSON.parse(rawData);
138
+ }
139
+ catch {
140
+ // If parsing fails, treat the string as the state itself
141
+ return createBlockStorage(rawData);
142
+ }
143
+ }
144
+ // Check for legacy V1/V2 format
145
+ if (isLegacyV1V2Format(parsed)) {
146
+ return convertLegacyToBlockStorage(parsed);
147
+ }
148
+ // Use standard normalization
149
+ return normalizeBlockStorage(parsed);
150
+ }
151
+
152
+ export { applyStateUpdate, convertLegacyToBlockStorage, extractDataForDeveloper, isLegacyV1V2Format, migrateBlockStorage, needsMigration, parseBlockStorage, parseBlockStorageSmart, serializeBlockStorage };
153
+ //# sourceMappingURL=block_storage_helper.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"block_storage_helper.js","sources":["../../src/model/block_storage_helper.ts"],"sourcesContent":["/**\n * Block Storage Helper - Middle layer utilities for BlockStorage operations.\n *\n * This module provides the bridge between the SDK's BlockStorage abstraction\n * and the middle layer's storage operations. Block developers never interact\n * with this - they only see `state`.\n *\n * @module block_storage_helper\n */\n\nimport type {\n BlockStorage,\n BlockStorageHandlers,\n} from '@platforma-sdk/model';\nimport {\n BLOCK_STORAGE_KEY,\n BLOCK_STORAGE_SCHEMA_VERSION,\n createBlockStorage,\n defaultBlockStorageHandlers,\n getPluginData,\n getStorageData,\n getStorageDataVersion,\n isBlockStorage,\n normalizeBlockStorage,\n setPluginData,\n updateStorageData,\n updateStorageDataVersion,\n} from '@platforma-sdk/model';\n\n// Re-export types for convenience\nexport type { BlockStorage, BlockStorageHandlers };\n\n// Re-export utilities that middle layer needs\nexport {\n BLOCK_STORAGE_KEY,\n BLOCK_STORAGE_SCHEMA_VERSION,\n createBlockStorage,\n defaultBlockStorageHandlers,\n getPluginData,\n getStorageData,\n getStorageDataVersion,\n isBlockStorage,\n normalizeBlockStorage,\n setPluginData,\n updateStorageData,\n updateStorageDataVersion,\n};\n\n/**\n * Parses raw blockStorage data (from resource tree) into BlockStorage.\n * Handles both legacy format (raw state) and new format (BlockStorage).\n *\n * @param rawData - Raw data from blockStorage field (may be string or parsed object)\n * @returns Normalized BlockStorage object\n */\nexport function parseBlockStorage<TState = unknown>(rawData: unknown): BlockStorage<TState> {\n if (rawData === undefined || rawData === null) {\n return createBlockStorage<TState>({} as TState);\n }\n\n // If it's a string, parse it first\n if (typeof rawData === 'string') {\n try {\n const parsed = JSON.parse(rawData);\n return normalizeBlockStorage<TState>(parsed);\n } catch {\n // If parsing fails, treat the string as the state itself\n return createBlockStorage(rawData as unknown as TState);\n }\n }\n\n return normalizeBlockStorage<TState>(rawData);\n}\n\n/**\n * Extracts the user-facing data from BlockStorage.\n * This is what block developers see in their .args() callbacks.\n *\n * @param storage - The BlockStorage object\n * @returns The data value that developers work with\n */\nexport function extractDataForDeveloper<TState>(storage: BlockStorage<TState>): TState {\n return getStorageData(storage);\n}\n\n/**\n * Creates a new BlockStorage with updated state.\n * Used when setState is called from the frontend.\n *\n * @param currentStorage - Current BlockStorage (or undefined for new blocks)\n * @param newState - New state from developer\n * @param handlers - Optional custom handlers (defaults to standard handlers)\n * @returns Updated BlockStorage\n */\nexport function applyStateUpdate<TState>(\n currentStorage: BlockStorage<TState> | undefined,\n newState: TState,\n handlers: BlockStorageHandlers<TState> = defaultBlockStorageHandlers as BlockStorageHandlers<TState>,\n): BlockStorage<TState> {\n const storage = currentStorage ?? createBlockStorage<TState>({} as TState);\n const transform = handlers.transformStateForStorage ?? defaultBlockStorageHandlers.transformStateForStorage;\n return transform(storage, newState) as BlockStorage<TState>;\n}\n\n/**\n * Serializes BlockStorage for writing to the resource tree.\n *\n * @param storage - The BlockStorage to serialize\n * @returns JSON string\n */\nexport function serializeBlockStorage(storage: BlockStorage): string {\n return JSON.stringify(storage);\n}\n\n/**\n * Checks if the storage needs migration based on version.\n *\n * @param storage - Current BlockStorage\n * @param targetVersion - Target schema version\n * @returns true if migration is needed\n */\nexport function needsMigration(storage: BlockStorage, targetVersion: number): boolean {\n return getStorageDataVersion(storage) < targetVersion;\n}\n\n/**\n * Migrates BlockStorage from one version to another.\n *\n * @param storage - Current BlockStorage\n * @param fromVersion - Source version\n * @param toVersion - Target version\n * @param handlers - Optional custom handlers\n * @returns Migrated BlockStorage\n */\nexport function migrateBlockStorage<TState>(\n storage: BlockStorage<TState>,\n fromVersion: number,\n toVersion: number,\n handlers: BlockStorageHandlers<TState> = defaultBlockStorageHandlers as BlockStorageHandlers<TState>,\n): BlockStorage<TState> {\n const migrate = handlers.migrateStorage ?? defaultBlockStorageHandlers.migrateStorage;\n return migrate(storage, fromVersion, toVersion) as BlockStorage<TState>;\n}\n\n/**\n * V1/V2 legacy format - state stored as { args, uiState }\n */\nexport interface LegacyV1V2State {\n args?: unknown;\n uiState?: unknown;\n}\n\n/**\n * Checks if the raw data is in legacy V1/V2 format.\n * V1/V2 blocks stored { args, uiState } directly, not wrapped in BlockStorage.\n *\n * @param rawData - Raw data from blockStorage field\n * @returns true if data is in legacy format\n */\nexport function isLegacyV1V2Format(rawData: unknown): rawData is LegacyV1V2State {\n if (rawData === null || typeof rawData !== 'object') return false;\n // If it has the discriminator, it's BlockStorage format\n if (isBlockStorage(rawData)) return false;\n\n const obj = rawData as Record<string, unknown>;\n // Legacy format has 'args' and/or 'uiState' at top level, no discriminator\n return ('args' in obj || 'uiState' in obj);\n}\n\n/**\n * Converts legacy V1/V2 format to BlockStorage.\n * For backward compatibility with existing blocks.\n *\n * @param legacyData - Data in { args, uiState } format\n * @returns BlockStorage with legacy data as state\n */\nexport function convertLegacyToBlockStorage(legacyData: LegacyV1V2State): BlockStorage<LegacyV1V2State> {\n return createBlockStorage(legacyData, 1);\n}\n\n/**\n * Smart parser that handles all storage formats:\n * - New BlockStorage format\n * - Legacy V1/V2 format ({ args, uiState })\n * - Raw state (any other format)\n *\n * @param rawData - Raw data from blockStorage field\n * @returns Normalized BlockStorage\n */\nexport function parseBlockStorageSmart<TState = unknown>(rawData: unknown): BlockStorage<TState> {\n if (rawData === undefined || rawData === null) {\n return createBlockStorage<TState>({} as TState);\n }\n\n // If it's a string, parse it first\n let parsed = rawData;\n if (typeof rawData === 'string') {\n try {\n parsed = JSON.parse(rawData);\n } catch {\n // If parsing fails, treat the string as the state itself\n return createBlockStorage(rawData as unknown as TState);\n }\n }\n\n // Check for legacy V1/V2 format\n if (isLegacyV1V2Format(parsed)) {\n return convertLegacyToBlockStorage(parsed) as unknown as BlockStorage<TState>;\n }\n\n // Use standard normalization\n return normalizeBlockStorage<TState>(parsed);\n}\n"],"names":[],"mappings":";;;AAAA;;;;;;;;AAQG;AAwCH;;;;;;AAMG;AACG,SAAU,iBAAiB,CAAmB,OAAgB,EAAA;IAClE,IAAI,OAAO,KAAK,SAAS,IAAI,OAAO,KAAK,IAAI,EAAE;AAC7C,QAAA,OAAO,kBAAkB,CAAS,EAAY,CAAC;IACjD;;AAGA,IAAA,IAAI,OAAO,OAAO,KAAK,QAAQ,EAAE;AAC/B,QAAA,IAAI;YACF,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC;AAClC,YAAA,OAAO,qBAAqB,CAAS,MAAM,CAAC;QAC9C;AAAE,QAAA,MAAM;;AAEN,YAAA,OAAO,kBAAkB,CAAC,OAA4B,CAAC;QACzD;IACF;AAEA,IAAA,OAAO,qBAAqB,CAAS,OAAO,CAAC;AAC/C;AAEA;;;;;;AAMG;AACG,SAAU,uBAAuB,CAAS,OAA6B,EAAA;AAC3E,IAAA,OAAO,cAAc,CAAC,OAAO,CAAC;AAChC;AAEA;;;;;;;;AAQG;AACG,SAAU,gBAAgB,CAC9B,cAAgD,EAChD,QAAgB,EAChB,WAAyC,2BAA2D,EAAA;IAEpG,MAAM,OAAO,GAAG,cAAc,IAAI,kBAAkB,CAAS,EAAY,CAAC;IAC1E,MAAM,SAAS,GAAG,QAAQ,CAAC,wBAAwB,IAAI,2BAA2B,CAAC,wBAAwB;AAC3G,IAAA,OAAO,SAAS,CAAC,OAAO,EA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A,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC;QAC9B;AAAE,QAAA,MAAM;;AAEN,YAAA,OAAO,kBAAkB,CAAC,OAA4B,CAAC;QACzD;IACF;;AAGA,IAAA,IAAI,kBAAkB,CAAC,MAAM,CAAC,EAAE;AAC9B,QAAA,OAAO,2BAA2B,CAAC,MAAM,CAAoC;IAC/E;;AAGA,IAAA,OAAO,qBAAqB,CAAS,MAAM,CAAC;AAC9C;;;;"}
@@ -1,3 +1,4 @@
1
1
  export * from './block_pack_spec';
2
- export { type ProjectListEntry } from './project_model';
2
+ export * from './block_storage_helper';
3
+ export { type ProjectListEntry, type ProjectField } from './project_model';
3
4
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/model/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC;AAClC,OAAO,EAAE,KAAK,gBAAgB,EAAE,MAAM,iBAAiB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/model/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC;AAClC,cAAc,wBAAwB,CAAC;AACvC,OAAO,EAAE,KAAK,gBAAgB,EAAE,KAAK,YAAY,EAAE,MAAM,iBAAiB,CAAC"}