@platforma-sdk/model 1.58.5 → 1.58.9

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 (365) hide show
  1. package/dist/_virtual/_rolldown/runtime.cjs +43 -0
  2. package/dist/_virtual/_rolldown/runtime.js +18 -0
  3. package/dist/annotations/converter.cjs +15 -20
  4. package/dist/annotations/converter.cjs.map +1 -1
  5. package/dist/annotations/converter.d.ts +6 -2
  6. package/dist/annotations/converter.js +14 -18
  7. package/dist/annotations/converter.js.map +1 -1
  8. package/dist/annotations/index.cjs +1 -0
  9. package/dist/annotations/index.d.ts +2 -3
  10. package/dist/annotations/index.js +1 -0
  11. package/dist/annotations/types.d.ts +21 -16
  12. package/dist/bconfig/index.cjs +2 -0
  13. package/dist/bconfig/index.d.ts +5 -6
  14. package/dist/bconfig/index.js +2 -0
  15. package/dist/bconfig/lambdas.d.ts +52 -52
  16. package/dist/bconfig/normalization.cjs +13 -18
  17. package/dist/bconfig/normalization.cjs.map +1 -1
  18. package/dist/bconfig/normalization.d.ts +10 -6
  19. package/dist/bconfig/normalization.js +12 -16
  20. package/dist/bconfig/normalization.js.map +1 -1
  21. package/dist/bconfig/types.cjs +4 -3
  22. package/dist/bconfig/types.cjs.map +1 -1
  23. package/dist/bconfig/types.d.ts +10 -5
  24. package/dist/bconfig/types.js +4 -2
  25. package/dist/bconfig/types.js.map +1 -1
  26. package/dist/bconfig/util.d.ts +7 -4
  27. package/dist/bconfig/v3.d.ts +10 -6
  28. package/dist/block_api_v1.d.ts +62 -58
  29. package/dist/block_api_v2.d.ts +51 -47
  30. package/dist/block_api_v3.d.ts +33 -29
  31. package/dist/block_migrations.cjs +481 -413
  32. package/dist/block_migrations.cjs.map +1 -1
  33. package/dist/block_migrations.d.ts +258 -204
  34. package/dist/block_migrations.js +482 -408
  35. package/dist/block_migrations.js.map +1 -1
  36. package/dist/block_model.cjs +312 -343
  37. package/dist/block_model.cjs.map +1 -1
  38. package/dist/block_model.d.ts +143 -147
  39. package/dist/block_model.js +312 -341
  40. package/dist/block_model.js.map +1 -1
  41. package/dist/block_model_legacy.cjs +231 -255
  42. package/dist/block_model_legacy.cjs.map +1 -1
  43. package/dist/block_model_legacy.d.ts +108 -106
  44. package/dist/block_model_legacy.js +231 -253
  45. package/dist/block_model_legacy.js.map +1 -1
  46. package/dist/block_state_patch.d.ts +10 -10
  47. package/dist/block_state_util.cjs +15 -19
  48. package/dist/block_state_util.cjs.map +1 -1
  49. package/dist/block_state_util.d.ts +14 -13
  50. package/dist/block_state_util.js +15 -18
  51. package/dist/block_state_util.js.map +1 -1
  52. package/dist/block_storage.cjs +233 -238
  53. package/dist/block_storage.cjs.map +1 -1
  54. package/dist/block_storage.d.ts +62 -78
  55. package/dist/block_storage.js +234 -237
  56. package/dist/block_storage.js.map +1 -1
  57. package/dist/block_storage_callbacks.cjs +156 -195
  58. package/dist/block_storage_callbacks.cjs.map +1 -1
  59. package/dist/block_storage_callbacks.js +156 -192
  60. package/dist/block_storage_callbacks.js.map +1 -1
  61. package/dist/block_storage_facade.cjs +29 -85
  62. package/dist/block_storage_facade.cjs.map +1 -1
  63. package/dist/block_storage_facade.d.ts +83 -126
  64. package/dist/block_storage_facade.js +29 -83
  65. package/dist/block_storage_facade.js.map +1 -1
  66. package/dist/components/PFrameForGraphs.cjs +26 -24
  67. package/dist/components/PFrameForGraphs.cjs.map +1 -1
  68. package/dist/components/PFrameForGraphs.d.ts +12 -7
  69. package/dist/components/PFrameForGraphs.js +25 -22
  70. package/dist/components/PFrameForGraphs.js.map +1 -1
  71. package/dist/components/PlAnnotations/filter.d.ts +62 -79
  72. package/dist/components/PlAnnotations/filters_ui.cjs +135 -171
  73. package/dist/components/PlAnnotations/filters_ui.cjs.map +1 -1
  74. package/dist/components/PlAnnotations/filters_ui.d.ts +48 -46
  75. package/dist/components/PlAnnotations/filters_ui.js +135 -170
  76. package/dist/components/PlAnnotations/filters_ui.js.map +1 -1
  77. package/dist/components/PlAnnotations/index.d.ts +2 -3
  78. package/dist/components/PlDataTable/index.cjs +2 -0
  79. package/dist/components/PlDataTable/index.d.ts +3 -5
  80. package/dist/components/PlDataTable/index.js +2 -0
  81. package/dist/components/PlDataTable/labels.cjs +59 -81
  82. package/dist/components/PlDataTable/labels.cjs.map +1 -1
  83. package/dist/components/PlDataTable/labels.js +58 -79
  84. package/dist/components/PlDataTable/labels.js.map +1 -1
  85. package/dist/components/PlDataTable/state-migration.cjs +186 -144
  86. package/dist/components/PlDataTable/state-migration.cjs.map +1 -1
  87. package/dist/components/PlDataTable/state-migration.d.ts +85 -82
  88. package/dist/components/PlDataTable/state-migration.js +185 -142
  89. package/dist/components/PlDataTable/state-migration.js.map +1 -1
  90. package/dist/components/PlDataTable/table.cjs +172 -194
  91. package/dist/components/PlDataTable/table.cjs.map +1 -1
  92. package/dist/components/PlDataTable/table.d.ts +16 -12
  93. package/dist/components/PlDataTable/table.js +171 -192
  94. package/dist/components/PlDataTable/table.js.map +1 -1
  95. package/dist/components/PlDataTable/v4.d.ts +84 -119
  96. package/dist/components/PlDataTable/v5.d.ts +80 -103
  97. package/dist/components/PlMultiSequenceAlignment.cjs +27 -29
  98. package/dist/components/PlMultiSequenceAlignment.cjs.map +1 -1
  99. package/dist/components/PlMultiSequenceAlignment.d.ts +36 -27
  100. package/dist/components/PlMultiSequenceAlignment.js +26 -27
  101. package/dist/components/PlMultiSequenceAlignment.js.map +1 -1
  102. package/dist/components/PlSelectionModel.cjs +7 -6
  103. package/dist/components/PlSelectionModel.cjs.map +1 -1
  104. package/dist/components/PlSelectionModel.d.ts +10 -8
  105. package/dist/components/PlSelectionModel.js +7 -5
  106. package/dist/components/PlSelectionModel.js.map +1 -1
  107. package/dist/components/index.cjs +8 -0
  108. package/dist/components/index.d.ts +11 -6
  109. package/dist/components/index.js +8 -0
  110. package/dist/config/actions.cjs +138 -171
  111. package/dist/config/actions.cjs.map +1 -1
  112. package/dist/config/actions.d.ts +47 -47
  113. package/dist/config/actions.js +146 -178
  114. package/dist/config/actions.js.map +1 -1
  115. package/dist/config/actions_kinds.d.ts +114 -121
  116. package/dist/config/index.cjs +1 -0
  117. package/dist/config/index.d.ts +6 -7
  118. package/dist/config/index.js +1 -0
  119. package/dist/config/model.d.ts +131 -127
  120. package/dist/config/model_meta.d.ts +4 -1
  121. package/dist/config/type_engine.d.ts +22 -21
  122. package/dist/config/type_util.d.ts +12 -10
  123. package/dist/env_value.cjs +5 -6
  124. package/dist/env_value.cjs.map +1 -1
  125. package/dist/env_value.d.ts +4 -1
  126. package/dist/env_value.js +5 -5
  127. package/dist/env_value.js.map +1 -1
  128. package/dist/filters/converters/filterToQuery.cjs +273 -239
  129. package/dist/filters/converters/filterToQuery.cjs.map +1 -1
  130. package/dist/filters/converters/filterToQuery.d.ts +6 -2
  131. package/dist/filters/converters/filterToQuery.js +272 -237
  132. package/dist/filters/converters/filterToQuery.js.map +1 -1
  133. package/dist/filters/converters/filterUiToExpressionImpl.cjs +56 -85
  134. package/dist/filters/converters/filterUiToExpressionImpl.cjs.map +1 -1
  135. package/dist/filters/converters/filterUiToExpressionImpl.d.ts +8 -4
  136. package/dist/filters/converters/filterUiToExpressionImpl.js +55 -83
  137. package/dist/filters/converters/filterUiToExpressionImpl.js.map +1 -1
  138. package/dist/filters/converters/index.cjs +2 -0
  139. package/dist/filters/converters/index.d.ts +2 -3
  140. package/dist/filters/converters/index.js +2 -0
  141. package/dist/filters/distill.cjs +59 -60
  142. package/dist/filters/distill.cjs.map +1 -1
  143. package/dist/filters/distill.d.ts +6 -3
  144. package/dist/filters/distill.js +58 -58
  145. package/dist/filters/distill.js.map +1 -1
  146. package/dist/filters/index.cjs +4 -0
  147. package/dist/filters/index.d.ts +5 -4
  148. package/dist/filters/index.js +4 -0
  149. package/dist/filters/traverse.cjs +31 -40
  150. package/dist/filters/traverse.cjs.map +1 -1
  151. package/dist/filters/traverse.js +31 -39
  152. package/dist/filters/traverse.js.map +1 -1
  153. package/dist/filters/types.d.ts +10 -7
  154. package/dist/index.cjs +193 -187
  155. package/dist/index.d.ts +61 -28
  156. package/dist/index.js +49 -41
  157. package/dist/internal.cjs +48 -62
  158. package/dist/internal.cjs.map +1 -1
  159. package/dist/internal.js +49 -60
  160. package/dist/internal.js.map +1 -1
  161. package/dist/package.cjs +12 -0
  162. package/dist/package.cjs.map +1 -0
  163. package/dist/package.js +6 -0
  164. package/dist/package.js.map +1 -0
  165. package/dist/pframe.cjs +32 -37
  166. package/dist/pframe.cjs.map +1 -1
  167. package/dist/pframe.d.ts +14 -10
  168. package/dist/pframe.js +32 -35
  169. package/dist/pframe.js.map +1 -1
  170. package/dist/pframe_utils/axes.cjs +81 -114
  171. package/dist/pframe_utils/axes.cjs.map +1 -1
  172. package/dist/pframe_utils/axes.d.ts +10 -13
  173. package/dist/pframe_utils/axes.js +80 -112
  174. package/dist/pframe_utils/axes.js.map +1 -1
  175. package/dist/pframe_utils/columns.cjs +61 -81
  176. package/dist/pframe_utils/columns.cjs.map +1 -1
  177. package/dist/pframe_utils/columns.d.ts +15 -6
  178. package/dist/pframe_utils/columns.js +60 -79
  179. package/dist/pframe_utils/columns.js.map +1 -1
  180. package/dist/pframe_utils/index.cjs +232 -253
  181. package/dist/pframe_utils/index.cjs.map +1 -1
  182. package/dist/pframe_utils/index.d.ts +39 -35
  183. package/dist/pframe_utils/index.js +231 -251
  184. package/dist/pframe_utils/index.js.map +1 -1
  185. package/dist/platforma.d.ts +48 -46
  186. package/dist/plugin_handle.cjs +6 -14
  187. package/dist/plugin_handle.cjs.map +1 -1
  188. package/dist/plugin_handle.d.ts +20 -25
  189. package/dist/plugin_handle.js +6 -13
  190. package/dist/plugin_handle.js.map +1 -1
  191. package/dist/plugin_model.cjs +364 -163
  192. package/dist/plugin_model.cjs.map +1 -1
  193. package/dist/plugin_model.d.ts +280 -129
  194. package/dist/plugin_model.js +362 -163
  195. package/dist/plugin_model.js.map +1 -1
  196. package/dist/raw_globals.cjs +10 -22
  197. package/dist/raw_globals.cjs.map +1 -1
  198. package/dist/raw_globals.d.ts +8 -5
  199. package/dist/raw_globals.js +10 -20
  200. package/dist/raw_globals.js.map +1 -1
  201. package/dist/ref_util.cjs +14 -13
  202. package/dist/ref_util.cjs.map +1 -1
  203. package/dist/ref_util.d.ts +18 -12
  204. package/dist/ref_util.js +14 -11
  205. package/dist/ref_util.js.map +1 -1
  206. package/dist/render/accessor.cjs +213 -226
  207. package/dist/render/accessor.cjs.map +1 -1
  208. package/dist/render/accessor.d.ts +115 -120
  209. package/dist/render/accessor.js +212 -224
  210. package/dist/render/accessor.js.map +1 -1
  211. package/dist/render/api.cjs +478 -580
  212. package/dist/render/api.cjs.map +1 -1
  213. package/dist/render/api.d.ts +207 -209
  214. package/dist/render/api.js +476 -578
  215. package/dist/render/api.js.map +1 -1
  216. package/dist/render/future.cjs +28 -32
  217. package/dist/render/future.cjs.map +1 -1
  218. package/dist/render/future.d.ts +15 -11
  219. package/dist/render/future.js +28 -30
  220. package/dist/render/future.js.map +1 -1
  221. package/dist/render/index.cjs +8 -0
  222. package/dist/render/index.d.ts +10 -8
  223. package/dist/render/index.js +8 -0
  224. package/dist/render/internal.cjs +33 -29
  225. package/dist/render/internal.cjs.map +1 -1
  226. package/dist/render/internal.d.ts +78 -72
  227. package/dist/render/internal.js +29 -26
  228. package/dist/render/internal.js.map +1 -1
  229. package/dist/render/traversal_ops.d.ts +42 -43
  230. package/dist/render/util/axis_filtering.cjs +63 -86
  231. package/dist/render/util/axis_filtering.cjs.map +1 -1
  232. package/dist/render/util/axis_filtering.d.ts +10 -7
  233. package/dist/render/util/axis_filtering.js +63 -85
  234. package/dist/render/util/axis_filtering.js.map +1 -1
  235. package/dist/render/util/column_collection.cjs +266 -321
  236. package/dist/render/util/column_collection.cjs.map +1 -1
  237. package/dist/render/util/column_collection.d.ts +47 -47
  238. package/dist/render/util/column_collection.js +264 -319
  239. package/dist/render/util/column_collection.js.map +1 -1
  240. package/dist/render/util/index.cjs +4 -0
  241. package/dist/render/util/index.d.ts +4 -5
  242. package/dist/render/util/index.js +4 -0
  243. package/dist/render/util/label.cjs +129 -163
  244. package/dist/render/util/label.cjs.map +1 -1
  245. package/dist/render/util/label.d.ts +45 -46
  246. package/dist/render/util/label.js +128 -161
  247. package/dist/render/util/label.js.map +1 -1
  248. package/dist/render/util/pcolumn_data.cjs +315 -375
  249. package/dist/render/util/pcolumn_data.cjs.map +1 -1
  250. package/dist/render/util/pcolumn_data.d.ts +33 -32
  251. package/dist/render/util/pcolumn_data.js +314 -373
  252. package/dist/render/util/pcolumn_data.js.map +1 -1
  253. package/dist/render/util/pframe_upgraders.cjs +37 -42
  254. package/dist/render/util/pframe_upgraders.cjs.map +1 -1
  255. package/dist/render/util/pframe_upgraders.js +37 -41
  256. package/dist/render/util/pframe_upgraders.js.map +1 -1
  257. package/dist/render/util/split_selectors.d.ts +13 -9
  258. package/dist/version.cjs +6 -8
  259. package/dist/version.cjs.map +1 -1
  260. package/dist/version.d.ts +7 -4
  261. package/dist/version.js +5 -5
  262. package/dist/version.js.map +1 -1
  263. package/package.json +10 -4
  264. package/src/block_migrations.test.ts +184 -14
  265. package/src/block_migrations.ts +185 -30
  266. package/src/block_model.ts +111 -66
  267. package/src/block_storage.test.ts +147 -3
  268. package/src/block_storage.ts +43 -8
  269. package/src/block_storage_callbacks.ts +9 -4
  270. package/src/env_value.ts +0 -2
  271. package/src/index.ts +12 -11
  272. package/src/internal.ts +0 -1
  273. package/src/platforma.ts +4 -4
  274. package/src/plugin_handle.ts +1 -1
  275. package/src/plugin_model.test.ts +217 -21
  276. package/src/plugin_model.ts +450 -55
  277. package/src/raw_globals.ts +0 -1
  278. package/dist/annotations/converter.d.ts.map +0 -1
  279. package/dist/annotations/index.d.ts.map +0 -1
  280. package/dist/annotations/types.d.ts.map +0 -1
  281. package/dist/bconfig/index.d.ts.map +0 -1
  282. package/dist/bconfig/lambdas.d.ts.map +0 -1
  283. package/dist/bconfig/normalization.d.ts.map +0 -1
  284. package/dist/bconfig/types.d.ts.map +0 -1
  285. package/dist/bconfig/util.d.ts.map +0 -1
  286. package/dist/bconfig/v3.d.ts.map +0 -1
  287. package/dist/block_api_v1.d.ts.map +0 -1
  288. package/dist/block_api_v2.d.ts.map +0 -1
  289. package/dist/block_api_v3.d.ts.map +0 -1
  290. package/dist/block_migrations.d.ts.map +0 -1
  291. package/dist/block_model.d.ts.map +0 -1
  292. package/dist/block_model_legacy.d.ts.map +0 -1
  293. package/dist/block_state_patch.d.ts.map +0 -1
  294. package/dist/block_state_util.d.ts.map +0 -1
  295. package/dist/block_storage.d.ts.map +0 -1
  296. package/dist/block_storage_callbacks.d.ts +0 -115
  297. package/dist/block_storage_callbacks.d.ts.map +0 -1
  298. package/dist/block_storage_facade.d.ts.map +0 -1
  299. package/dist/components/PFrameForGraphs.d.ts.map +0 -1
  300. package/dist/components/PlAnnotations/filter.d.ts.map +0 -1
  301. package/dist/components/PlAnnotations/filters_ui.d.ts.map +0 -1
  302. package/dist/components/PlAnnotations/index.d.ts.map +0 -1
  303. package/dist/components/PlAnnotations/types.d.ts +0 -3
  304. package/dist/components/PlAnnotations/types.d.ts.map +0 -1
  305. package/dist/components/PlDataTable/index.d.ts.map +0 -1
  306. package/dist/components/PlDataTable/labels.d.ts +0 -7
  307. package/dist/components/PlDataTable/labels.d.ts.map +0 -1
  308. package/dist/components/PlDataTable/state-migration.d.ts.map +0 -1
  309. package/dist/components/PlDataTable/table.d.ts.map +0 -1
  310. package/dist/components/PlDataTable/v4.d.ts.map +0 -1
  311. package/dist/components/PlDataTable/v5.d.ts.map +0 -1
  312. package/dist/components/PlMultiSequenceAlignment.d.ts.map +0 -1
  313. package/dist/components/PlSelectionModel.d.ts.map +0 -1
  314. package/dist/components/index.d.ts.map +0 -1
  315. package/dist/config/actions.d.ts.map +0 -1
  316. package/dist/config/actions_kinds.d.ts.map +0 -1
  317. package/dist/config/index.d.ts.map +0 -1
  318. package/dist/config/model.d.ts.map +0 -1
  319. package/dist/config/model_meta.d.ts.map +0 -1
  320. package/dist/config/type_engine.d.ts.map +0 -1
  321. package/dist/config/type_util.d.ts.map +0 -1
  322. package/dist/env_value.d.ts.map +0 -1
  323. package/dist/filters/converters/filterToQuery.d.ts.map +0 -1
  324. package/dist/filters/converters/filterUiToExpressionImpl.d.ts.map +0 -1
  325. package/dist/filters/converters/index.d.ts.map +0 -1
  326. package/dist/filters/distill.d.ts.map +0 -1
  327. package/dist/filters/index.d.ts.map +0 -1
  328. package/dist/filters/traverse.d.ts +0 -27
  329. package/dist/filters/traverse.d.ts.map +0 -1
  330. package/dist/filters/types.d.ts.map +0 -1
  331. package/dist/index.cjs.map +0 -1
  332. package/dist/index.d.ts.map +0 -1
  333. package/dist/index.js.map +0 -1
  334. package/dist/internal.d.ts +0 -36
  335. package/dist/internal.d.ts.map +0 -1
  336. package/dist/package.json.cjs +0 -6
  337. package/dist/package.json.cjs.map +0 -1
  338. package/dist/package.json.js +0 -4
  339. package/dist/package.json.js.map +0 -1
  340. package/dist/pframe.d.ts.map +0 -1
  341. package/dist/pframe_utils/axes.d.ts.map +0 -1
  342. package/dist/pframe_utils/columns.d.ts.map +0 -1
  343. package/dist/pframe_utils/index.d.ts.map +0 -1
  344. package/dist/pframe_utils/querySpec.d.ts +0 -2
  345. package/dist/pframe_utils/querySpec.d.ts.map +0 -1
  346. package/dist/platforma.d.ts.map +0 -1
  347. package/dist/plugin_handle.d.ts.map +0 -1
  348. package/dist/plugin_model.d.ts.map +0 -1
  349. package/dist/raw_globals.d.ts.map +0 -1
  350. package/dist/ref_util.d.ts.map +0 -1
  351. package/dist/render/accessor.d.ts.map +0 -1
  352. package/dist/render/api.d.ts.map +0 -1
  353. package/dist/render/future.d.ts.map +0 -1
  354. package/dist/render/index.d.ts.map +0 -1
  355. package/dist/render/internal.d.ts.map +0 -1
  356. package/dist/render/traversal_ops.d.ts.map +0 -1
  357. package/dist/render/util/axis_filtering.d.ts.map +0 -1
  358. package/dist/render/util/column_collection.d.ts.map +0 -1
  359. package/dist/render/util/index.d.ts.map +0 -1
  360. package/dist/render/util/label.d.ts.map +0 -1
  361. package/dist/render/util/pcolumn_data.d.ts.map +0 -1
  362. package/dist/render/util/pframe_upgraders.d.ts +0 -3
  363. package/dist/render/util/pframe_upgraders.d.ts.map +0 -1
  364. package/dist/render/util/split_selectors.d.ts.map +0 -1
  365. package/dist/version.d.ts.map +0 -1
@@ -1,426 +1,500 @@
1
- import { DATA_MODEL_LEGACY_VERSION } from './block_storage.js';
1
+ import { DATA_MODEL_LEGACY_VERSION } from "./block_storage.js";
2
2
 
3
+ //#region src/block_migrations.ts
3
4
  /** Create a DataVersioned wrapper with correct shape */
4
- function makeDataVersioned(version, data) {
5
- return { version, data };
6
- }
7
- /** Thrown when a migration step fails. */
8
- class DataMigrationError extends Error {
9
- name = "DataMigrationError";
10
- constructor(message) {
11
- super(message);
12
- }
5
+ function makeVersionedData(version, data) {
6
+ return {
7
+ version,
8
+ data
9
+ };
13
10
  }
14
11
  /** Thrown by recover() to signal unrecoverable data. */
15
- class DataUnrecoverableError extends Error {
16
- name = "DataUnrecoverableError";
17
- constructor(dataVersion) {
18
- super(`Unknown version '${dataVersion}'`);
19
- }
20
- }
12
+ var DataUnrecoverableError = class extends Error {
13
+ name = "DataUnrecoverableError";
14
+ constructor(dataVersion) {
15
+ super(`Unknown version '${dataVersion}'`);
16
+ }
17
+ };
21
18
  function isDataUnrecoverableError(error) {
22
- return error instanceof Error && error.name === "DataUnrecoverableError";
19
+ return error instanceof Error && error.name === "DataUnrecoverableError";
23
20
  }
24
21
  /**
25
- * Default recover function for unknown versions.
26
- * Use as fallback at the end of custom recover functions.
27
- *
28
- * @example
29
- * .recover((version, data) => {
30
- * if (version === 'legacy') {
31
- * return transformLegacyData(data);
32
- * }
33
- * return defaultRecover(version, data);
34
- * })
35
- */
22
+ * Default recover function for unknown versions.
23
+ * Use as fallback at the end of custom recover functions.
24
+ *
25
+ * @example
26
+ * .recover((version, data) => {
27
+ * if (version === 'legacy') {
28
+ * return transformLegacyData(data);
29
+ * }
30
+ * return defaultRecover(version, data);
31
+ * })
32
+ */
36
33
  const defaultRecover = (version, _data) => {
37
- throw new DataUnrecoverableError(version);
34
+ throw new DataUnrecoverableError(version);
38
35
  };
39
36
  /** Symbol for internal builder creation method */
40
37
  const FROM_BUILDER = Symbol("fromBuilder");
41
38
  /**
42
- * Abstract base for both migration chain types.
43
- * Holds shared state, buildStep() helper, and init().
44
- * migrate() cannot be shared due to a TypeScript limitation: when the base class
45
- * migrate() return type is abstract, subclasses cannot narrow it without losing type safety.
46
- * Each subclass therefore owns its migrate() with the correct concrete return type.
47
- *
48
- * @internal
49
- */
50
- class MigrationChainBase {
51
- versionChain;
52
- migrationSteps;
53
- constructor(state) {
54
- this.versionChain = state.versionChain;
55
- this.migrationSteps = state.steps;
56
- }
57
- /** Appends a migration step and returns the new versionChain and steps arrays. */
58
- buildStep(nextVersion, fn) {
59
- if (this.versionChain.includes(nextVersion)) {
60
- throw new Error(`Duplicate version '${nextVersion}' in migration chain`);
61
- }
62
- const fromVersion = this.versionChain[this.versionChain.length - 1];
63
- const step = {
64
- fromVersion,
65
- toVersion: nextVersion,
66
- migrate: fn,
67
- };
68
- return {
69
- versionChain: [...this.versionChain, nextVersion],
70
- steps: [...this.migrationSteps, step],
71
- };
72
- }
73
- /** Returns recover-specific fields for DataModel construction. Overridden by WithRecover. */
74
- recoverState() {
75
- return {};
76
- }
77
- /**
78
- * Finalize the DataModel with initial data factory.
79
- *
80
- * @param initialData - Factory function returning the initial state
81
- * @returns Finalized DataModel instance
82
- */
83
- init(initialData) {
84
- return DataModel[FROM_BUILDER]({
85
- versionChain: this.versionChain,
86
- steps: this.migrationSteps,
87
- initialDataFn: initialData,
88
- ...this.recoverState(),
89
- });
90
- }
91
- }
39
+ * Abstract base for both migration chain types.
40
+ * Holds shared state, buildStep() helper, and init().
41
+ * migrate() cannot be shared due to a TypeScript limitation: when the base class
42
+ * migrate() return type is abstract, subclasses cannot narrow it without losing type safety.
43
+ * Each subclass therefore owns its migrate() with the correct concrete return type.
44
+ *
45
+ * @internal
46
+ */
47
+ var MigrationChainBase = class {
48
+ versionChain;
49
+ migrationSteps;
50
+ transferSteps;
51
+ constructor(state) {
52
+ this.versionChain = state.versionChain;
53
+ this.migrationSteps = state.steps;
54
+ this.transferSteps = state.transferSteps ?? [];
55
+ }
56
+ /** Appends a migration step and returns the new versionChain and steps arrays. */
57
+ buildStep(nextVersion, fn) {
58
+ if (this.versionChain.includes(nextVersion)) throw new Error(`Duplicate version '${nextVersion}' in migration chain`);
59
+ const step = {
60
+ fromVersion: this.versionChain[this.versionChain.length - 1],
61
+ toVersion: nextVersion,
62
+ migrate: fn
63
+ };
64
+ return {
65
+ versionChain: [...this.versionChain, nextVersion],
66
+ steps: [...this.migrationSteps, step]
67
+ };
68
+ }
69
+ /** Validates uniqueness and records a TransferStep. */
70
+ buildTransfer(target, extract) {
71
+ if (this.transferSteps.some((t) => t.pluginId === target.id)) throw new Error(`Duplicate transfer for plugin '${target.id}'`);
72
+ const entry = {
73
+ pluginId: target.id,
74
+ beforeStepIndex: this.migrationSteps.length,
75
+ extract,
76
+ targetVersion: target.transferVersion
77
+ };
78
+ return { transferSteps: [...this.transferSteps, entry] };
79
+ }
80
+ /** Returns recover-specific fields for DataModel construction. Overridden by WithRecover. */
81
+ recoverState() {
82
+ return {};
83
+ }
84
+ /**
85
+ * Finalize the DataModel with initial data factory.
86
+ *
87
+ * @param initialData - Factory function returning the initial state
88
+ * @returns Finalized DataModel instance
89
+ */
90
+ init(initialData) {
91
+ return DataModel[FROM_BUILDER]({
92
+ versionChain: this.versionChain,
93
+ steps: this.migrationSteps,
94
+ transferSteps: this.transferSteps,
95
+ initialDataFn: initialData,
96
+ ...this.recoverState()
97
+ });
98
+ }
99
+ };
92
100
  /**
93
- * Migration chain after recover() or upgradeLegacy() has been called.
94
- * Further migrate() calls are allowed; recover() and upgradeLegacy() are not
95
- * (enforced by type — no such methods on this class).
96
- *
97
- * @typeParam Current - Data type at the current point in the chain
98
- * @internal
99
- */
100
- class DataModelMigrationChainWithRecover extends MigrationChainBase {
101
- recoverFn;
102
- recoverFromIndex;
103
- /** @internal */
104
- constructor(state) {
105
- super(state);
106
- this.recoverFn = state.recoverFn;
107
- this.recoverFromIndex = state.recoverFromIndex;
108
- }
109
- recoverState() {
110
- return {
111
- recoverFn: this.recoverFn,
112
- recoverFromIndex: this.recoverFromIndex,
113
- };
114
- }
115
- /**
116
- * Add a migration step. Same semantics as on the base chain.
117
- * recover() and upgradeLegacy() are not available one has already been called.
118
- */
119
- migrate(nextVersion, fn) {
120
- const { versionChain, steps } = this.buildStep(nextVersion, fn);
121
- return new DataModelMigrationChainWithRecover({
122
- versionChain,
123
- steps,
124
- recoverFn: this.recoverFn,
125
- recoverFromIndex: this.recoverFromIndex,
126
- });
127
- }
128
- }
101
+ * Migration chain after recover() or upgradeLegacy() has been called.
102
+ * Further migrate() and transfer() calls are allowed; recover() and upgradeLegacy() are not
103
+ * (enforced by type — no such methods on this class).
104
+ *
105
+ * @typeParam Current - Data type at the current point in the chain
106
+ * @typeParam Transfers - Accumulated transfer types keyed by plugin ID
107
+ * @internal
108
+ */
109
+ var DataModelMigrationChainWithRecover = class DataModelMigrationChainWithRecover extends MigrationChainBase {
110
+ recoverFn;
111
+ recoverFromIndex;
112
+ /** @internal */
113
+ constructor(state) {
114
+ super(state);
115
+ this.recoverFn = state.recoverFn;
116
+ this.recoverFromIndex = state.recoverFromIndex;
117
+ }
118
+ recoverState() {
119
+ return {
120
+ recoverFn: this.recoverFn,
121
+ recoverFromIndex: this.recoverFromIndex
122
+ };
123
+ }
124
+ /**
125
+ * Add a migration step. Same semantics as on the base chain.
126
+ * recover() and upgradeLegacy() are not available — one has already been called.
127
+ */
128
+ migrate(nextVersion, fn) {
129
+ const { versionChain, steps } = this.buildStep(nextVersion, fn);
130
+ return new DataModelMigrationChainWithRecover({
131
+ versionChain,
132
+ steps,
133
+ transferSteps: this.transferSteps,
134
+ recoverFn: this.recoverFn,
135
+ recoverFromIndex: this.recoverFromIndex
136
+ });
137
+ }
138
+ /**
139
+ * Extract data at the current chain position for seeding a new plugin.
140
+ * The extract function's return type must match the plugin's transfer data type.
141
+ * Duplicate plugin IDs are rejected at both type and runtime level.
142
+ */
143
+ transfer(target, extract) {
144
+ const { transferSteps } = this.buildTransfer(target, extract);
145
+ return new DataModelMigrationChainWithRecover({
146
+ versionChain: this.versionChain,
147
+ steps: this.migrationSteps,
148
+ transferSteps,
149
+ recoverFn: this.recoverFn,
150
+ recoverFromIndex: this.recoverFromIndex
151
+ });
152
+ }
153
+ };
129
154
  /**
130
- * Migration chain builder.
131
- * Each migrate() call advances the current data type. recover() can be called once
132
- * at any point — it removes itself from the returned chain so it cannot be called again.
133
- * Duplicate version keys throw at runtime.
134
- *
135
- * @typeParam Current - Data type at the current point in the migration chain
136
- * @internal
137
- */
138
- class DataModelMigrationChain extends MigrationChainBase {
139
- /** @internal */
140
- constructor({ versionChain, steps = [], }) {
141
- super({ versionChain, steps });
142
- }
143
- /**
144
- * Add a migration step transforming data from the current version to the next.
145
- *
146
- * @typeParam Next - Data type of the next version
147
- * @param nextVersion - Version key to migrate to (must be unique in the chain)
148
- * @param fn - Migration function
149
- * @returns Builder with the next version as current
150
- *
151
- * @example
152
- * .migrate<BlockDataV2>("v2", (v1) => ({ ...v1, labels: [] }))
153
- */
154
- migrate(nextVersion, fn) {
155
- const { versionChain, steps } = this.buildStep(nextVersion, fn);
156
- return new DataModelMigrationChain({ versionChain, steps });
157
- }
158
- /**
159
- * Set a recovery handler for unknown or legacy versions.
160
- *
161
- * The recover function is called when data has a version not in the migration chain.
162
- * It must return data of the type at this point in the chain (Current). Any migrate()
163
- * steps added after recover() will then run on the recovered data.
164
- *
165
- * Can only be called once — the returned chain has no recover() method.
166
- *
167
- * @param fn - Recovery function returning Current (the type at this chain position)
168
- * @returns Builder with migrate() and init() but without recover()
169
- *
170
- * @example
171
- * // Recover between migrations — recovered data goes through v3 migration
172
- * new DataModelBuilder<V1>("v1")
173
- * .migrate<V2>("v2", (v1) => ({ ...v1, label: "" }))
174
- * .recover((version, data) => {
175
- * if (version === 'legacy') return transformLegacy(data); // returns V2
176
- * return defaultRecover(version, data);
177
- * })
178
- * .migrate<V3>("v3", (v2) => ({ ...v2, description: "" }))
179
- * .init(() => ({ count: 0, label: "", description: "" }));
180
- */
181
- recover(fn) {
182
- return new DataModelMigrationChainWithRecover({
183
- versionChain: this.versionChain,
184
- steps: this.migrationSteps,
185
- recoverFn: fn,
186
- recoverFromIndex: this.migrationSteps.length,
187
- });
188
- }
189
- }
155
+ * Migration chain builder.
156
+ * Each migrate() call advances the current data type. recover() can be called once
157
+ * at any point — it removes itself from the returned chain so it cannot be called again.
158
+ * Duplicate version keys throw at runtime.
159
+ *
160
+ * @typeParam Current - Data type at the current point in the migration chain
161
+ * @typeParam Transfers - Accumulated transfer types keyed by plugin ID
162
+ * @internal
163
+ */
164
+ var DataModelMigrationChain = class DataModelMigrationChain extends MigrationChainBase {
165
+ /** @internal */
166
+ constructor({ versionChain, steps = [], transferSteps = [] }) {
167
+ super({
168
+ versionChain,
169
+ steps,
170
+ transferSteps
171
+ });
172
+ }
173
+ /**
174
+ * Add a migration step transforming data from the current version to the next.
175
+ *
176
+ * @typeParam Next - Data type of the next version
177
+ * @param nextVersion - Version key to migrate to (must be unique in the chain)
178
+ * @param fn - Migration function
179
+ * @returns Builder with the next version as current
180
+ *
181
+ * @example
182
+ * .migrate<BlockDataV2>("v2", (v1) => ({ ...v1, labels: [] }))
183
+ */
184
+ migrate(nextVersion, fn) {
185
+ const { versionChain, steps } = this.buildStep(nextVersion, fn);
186
+ return new DataModelMigrationChain({
187
+ versionChain,
188
+ steps,
189
+ transferSteps: this.transferSteps
190
+ });
191
+ }
192
+ /**
193
+ * Extract data at the current chain position for seeding a new plugin.
194
+ * The extract function's return type must match the plugin's transfer data type.
195
+ * Duplicate plugin IDs are rejected at both type and runtime level.
196
+ *
197
+ * Calling .transfer() on DataModelInitialChain returns DataModelMigrationChain,
198
+ * which removes .upgradeLegacy() from the chain (preventing a problematic combination).
199
+ *
200
+ * @example
201
+ * .from<V1>("v1")
202
+ * .transfer(tablePlugin, (v1) => ({ state: v1.tableState }))
203
+ * .migrate<V2>("v2", ({ tableState: _, ...rest }) => rest)
204
+ */
205
+ transfer(target, extract) {
206
+ const { transferSteps } = this.buildTransfer(target, extract);
207
+ return new DataModelMigrationChain({
208
+ versionChain: this.versionChain,
209
+ steps: this.migrationSteps,
210
+ transferSteps
211
+ });
212
+ }
213
+ /**
214
+ * Set a recovery handler for unknown or legacy versions.
215
+ *
216
+ * The recover function is called when data has a version not in the migration chain.
217
+ * It must return data of the type at this point in the chain (Current). Any migrate()
218
+ * steps added after recover() will then run on the recovered data.
219
+ *
220
+ * Can only be called once — the returned chain has no recover() method.
221
+ *
222
+ * @param fn - Recovery function returning Current (the type at this chain position)
223
+ * @returns Builder with migrate() and init() but without recover()
224
+ *
225
+ * @example
226
+ * // Recover between migrations — recovered data goes through v3 migration
227
+ * new DataModelBuilder<V1>("v1")
228
+ * .migrate<V2>("v2", (v1) => ({ ...v1, label: "" }))
229
+ * .recover((version, data) => {
230
+ * if (version === 'legacy') return transformLegacy(data); // returns V2
231
+ * return defaultRecover(version, data);
232
+ * })
233
+ * .migrate<V3>("v3", (v2) => ({ ...v2, description: "" }))
234
+ * .init(() => ({ count: 0, label: "", description: "" }));
235
+ */
236
+ recover(fn) {
237
+ return new DataModelMigrationChainWithRecover({
238
+ versionChain: this.versionChain,
239
+ steps: this.migrationSteps,
240
+ transferSteps: this.transferSteps,
241
+ recoverFn: fn,
242
+ recoverFromIndex: this.migrationSteps.length
243
+ });
244
+ }
245
+ };
190
246
  /**
191
- * Initial migration chain returned by `.from()`.
192
- * Extends DataModelMigrationChain with `upgradeLegacy()` — available only before
193
- * any `.migrate()` calls, since legacy data always arrives at the initial version.
194
- *
195
- * @typeParam Current - Data type at the initial version
196
- * @internal
197
- */
198
- class DataModelInitialChain extends DataModelMigrationChain {
199
- /**
200
- * Handle legacy V1 model state ({ args, uiState }) when upgrading a block from
201
- * BlockModel V1 to BlockModelV3.
202
- *
203
- * When a V1 block is upgraded, its stored state `{ args, uiState }` is normalized
204
- * to the internal default version. This method inserts a migration step from that
205
- * internal version to the version specified in `.from()`, using the provided typed
206
- * callback to transform the legacy shape. Non-legacy data passes through unchanged.
207
- *
208
- * Must be called right after `.from()` — not available after `.migrate()` calls.
209
- * Any `.migrate()` steps added after `upgradeLegacy()` will run on the transformed result.
210
- *
211
- * Can only be called once — the returned chain has no upgradeLegacy() method.
212
- * Mutually exclusive with recover().
213
- *
214
- * @typeParam Args - Type of the legacy block args
215
- * @typeParam UiState - Type of the legacy block uiState
216
- * @param fn - Typed transform from { args, uiState } to Current
217
- * @returns Builder with migrate() and init() but without recover() or upgradeLegacy()
218
- *
219
- * @example
220
- * type OldArgs = { inputFile: string; threshold: number };
221
- * type OldUiState = { selectedTab: string };
222
- * type BlockData = { inputFile: string; threshold: number; selectedTab: string };
223
- *
224
- * const dataModel = new DataModelBuilder()
225
- * .from<BlockData>("v1")
226
- * .upgradeLegacy<OldArgs, OldUiState>(({ args, uiState }) => ({
227
- * inputFile: args.inputFile,
228
- * threshold: args.threshold,
229
- * selectedTab: uiState.selectedTab,
230
- * }))
231
- * .init(() => ({ inputFile: '', threshold: 0, selectedTab: 'main' }));
232
- */
233
- upgradeLegacy(fn) {
234
- const wrappedFn = (data) => {
235
- if (data !== null && typeof data === "object" && "args" in data) {
236
- return fn(data);
237
- }
238
- return data;
239
- };
240
- // Insert DATA_MODEL_LEGACY_VERSION as the true first version
241
- // with a migration step that transforms legacy data to the user's initial version.
242
- const initialVersion = this.versionChain[0];
243
- const step = {
244
- fromVersion: DATA_MODEL_LEGACY_VERSION,
245
- toVersion: initialVersion,
246
- migrate: wrappedFn,
247
- };
248
- return new DataModelMigrationChainWithRecover({
249
- versionChain: [DATA_MODEL_LEGACY_VERSION, ...this.versionChain],
250
- steps: [step, ...this.migrationSteps],
251
- });
252
- }
253
- }
247
+ * Initial migration chain returned by `.from()`.
248
+ * Extends DataModelMigrationChain with `upgradeLegacy()` — available only before
249
+ * any `.migrate()` calls, since legacy data always arrives at the initial version.
250
+ *
251
+ * @typeParam Current - Data type at the initial version
252
+ * @typeParam Transfers - Accumulated transfer types keyed by plugin ID
253
+ * @internal
254
+ */
255
+ var DataModelInitialChain = class extends DataModelMigrationChain {
256
+ /**
257
+ * Handle legacy V1 model state ({ args, uiState }) when upgrading a block from
258
+ * BlockModel V1 to BlockModelV3.
259
+ *
260
+ * When a V1 block is upgraded, its stored state `{ args, uiState }` is normalized
261
+ * to the internal default version. This method inserts a migration step from that
262
+ * internal version to the version specified in `.from()`, using the provided typed
263
+ * callback to transform the legacy shape. Non-legacy data passes through unchanged.
264
+ *
265
+ * Must be called right after `.from()` not available after `.migrate()` calls.
266
+ * Any `.migrate()` steps added after `upgradeLegacy()` will run on the transformed result.
267
+ *
268
+ * Can only be called once — the returned chain has no upgradeLegacy() method.
269
+ * Mutually exclusive with recover().
270
+ *
271
+ * @typeParam Args - Type of the legacy block args
272
+ * @typeParam UiState - Type of the legacy block uiState
273
+ * @param fn - Typed transform from { args, uiState } to Current
274
+ * @returns Builder with migrate() and init() but without recover() or upgradeLegacy()
275
+ *
276
+ * @example
277
+ * type OldArgs = { inputFile: string; threshold: number };
278
+ * type OldUiState = { selectedTab: string };
279
+ * type BlockData = { inputFile: string; threshold: number; selectedTab: string };
280
+ *
281
+ * const dataModel = new DataModelBuilder()
282
+ * .from<BlockData>("v1")
283
+ * .upgradeLegacy<OldArgs, OldUiState>(({ args, uiState }) => ({
284
+ * inputFile: args.inputFile,
285
+ * threshold: args.threshold,
286
+ * selectedTab: uiState.selectedTab,
287
+ * }))
288
+ * .init(() => ({ inputFile: '', threshold: 0, selectedTab: 'main' }));
289
+ */
290
+ upgradeLegacy(fn) {
291
+ const wrappedFn = (data) => {
292
+ if (data !== null && typeof data === "object" && "args" in data) return fn(data);
293
+ return data;
294
+ };
295
+ const step = {
296
+ fromVersion: DATA_MODEL_LEGACY_VERSION,
297
+ toVersion: this.versionChain[0],
298
+ migrate: wrappedFn
299
+ };
300
+ return new DataModelMigrationChainWithRecover({
301
+ versionChain: [DATA_MODEL_LEGACY_VERSION, ...this.versionChain],
302
+ steps: [step, ...this.migrationSteps],
303
+ transferSteps: this.transferSteps.map((t) => ({
304
+ ...t,
305
+ beforeStepIndex: t.beforeStepIndex + 1
306
+ }))
307
+ });
308
+ }
309
+ };
254
310
  /**
255
- * Builder entry point for creating DataModel with type-safe migrations.
256
- *
257
- * @example
258
- * // Simple (no migrations):
259
- * const dataModel = new DataModelBuilder()
260
- * .from<BlockData>("v1")
261
- * .init(() => ({ numbers: [] }));
262
- *
263
- * @example
264
- * // With migrations:
265
- * const dataModel = new DataModelBuilder()
266
- * .from<BlockDataV1>("v1")
267
- * .migrate<BlockDataV2>("v2", (v1) => ({ ...v1, labels: [] }))
268
- * .migrate<BlockDataV3>("v3", (v2) => ({ ...v2, description: '' }))
269
- * .init(() => ({ numbers: [], labels: [], description: '' }));
270
- *
271
- * @example
272
- * // With recover() between migrations — recovered data goes through remaining migrations:
273
- * const dataModelChain = new DataModelBuilder()
274
- * .from<BlockDataV1>("v1")
275
- * .migrate<BlockDataV2>("v2", (v1) => ({ ...v1, labels: [] }));
276
- *
277
- * // recover() placed before the v3 migration: recovered data goes through v3
278
- * const dataModel = dataModelChain
279
- * .recover((version, data) => {
280
- * if (version === 'legacy' && isLegacyData(data)) return transformLegacy(data); // returns V2
281
- * return defaultRecover(version, data);
282
- * })
283
- * .migrate<BlockDataV3>("v3", (v2) => ({ ...v2, description: '' }))
284
- * .init(() => ({ numbers: [], labels: [], description: '' }));
285
- *
286
- * @example
287
- * // With upgradeLegacy() — typed upgrade from BlockModel V1 state:
288
- * type OldArgs = { inputFile: string };
289
- * type OldUiState = { selectedTab: string };
290
- * type BlockData = { inputFile: string; selectedTab: string };
291
- *
292
- * const dataModel = new DataModelBuilder()
293
- * .from<BlockData>("v1")
294
- * .upgradeLegacy<OldArgs, OldUiState>(({ args, uiState }) => ({
295
- * inputFile: args.inputFile,
296
- * selectedTab: uiState.selectedTab,
297
- * }))
298
- * .init(() => ({ inputFile: '', selectedTab: 'main' }));
299
- */
300
- class DataModelBuilder {
301
- /**
302
- * Start the migration chain with the given initial data type and version key.
303
- *
304
- * @typeParam T - Data type for the initial version
305
- * @param initialVersion - Version key string (e.g. "v1")
306
- * @returns Migration chain builder
307
- */
308
- from(initialVersion) {
309
- return new DataModelInitialChain({ versionChain: [initialVersion] });
310
- }
311
- }
311
+ * Builder entry point for creating DataModel with type-safe migrations.
312
+ *
313
+ * @example
314
+ * // Simple (no migrations):
315
+ * const dataModel = new DataModelBuilder()
316
+ * .from<BlockData>("v1")
317
+ * .init(() => ({ numbers: [] }));
318
+ *
319
+ * @example
320
+ * // With migrations:
321
+ * const dataModel = new DataModelBuilder()
322
+ * .from<BlockDataV1>("v1")
323
+ * .migrate<BlockDataV2>("v2", (v1) => ({ ...v1, labels: [] }))
324
+ * .migrate<BlockDataV3>("v3", (v2) => ({ ...v2, description: '' }))
325
+ * .init(() => ({ numbers: [], labels: [], description: '' }));
326
+ *
327
+ * @example
328
+ * // With recover() between migrations — recovered data goes through remaining migrations:
329
+ * const dataModelChain = new DataModelBuilder()
330
+ * .from<BlockDataV1>("v1")
331
+ * .migrate<BlockDataV2>("v2", (v1) => ({ ...v1, labels: [] }));
332
+ *
333
+ * // recover() placed before the v3 migration: recovered data goes through v3
334
+ * const dataModel = dataModelChain
335
+ * .recover((version, data) => {
336
+ * if (version === 'legacy' && isLegacyData(data)) return transformLegacy(data); // returns V2
337
+ * return defaultRecover(version, data);
338
+ * })
339
+ * .migrate<BlockDataV3>("v3", (v2) => ({ ...v2, description: '' }))
340
+ * .init(() => ({ numbers: [], labels: [], description: '' }));
341
+ *
342
+ * @example
343
+ * // With upgradeLegacy() — typed upgrade from BlockModel V1 state:
344
+ * type OldArgs = { inputFile: string };
345
+ * type OldUiState = { selectedTab: string };
346
+ * type BlockData = { inputFile: string; selectedTab: string };
347
+ *
348
+ * const dataModel = new DataModelBuilder()
349
+ * .from<BlockData>("v1")
350
+ * .upgradeLegacy<OldArgs, OldUiState>(({ args, uiState }) => ({
351
+ * inputFile: args.inputFile,
352
+ * selectedTab: uiState.selectedTab,
353
+ * }))
354
+ * .init(() => ({ inputFile: '', selectedTab: 'main' }));
355
+ */
356
+ var DataModelBuilder = class {
357
+ /**
358
+ * Start the migration chain with the given initial data type and version key.
359
+ *
360
+ * @typeParam T - Data type for the initial version
361
+ * @param initialVersion - Version key string (e.g. "v1")
362
+ * @returns Migration chain builder
363
+ */
364
+ from(initialVersion) {
365
+ return new DataModelInitialChain({ versionChain: [initialVersion] });
366
+ }
367
+ };
312
368
  /**
313
- * DataModel defines the block's data structure, initial values, and migrations.
314
- * Used by BlockModelV3 to manage data state.
315
- *
316
- * Use `new DataModelBuilder()` to create a DataModel.
317
- *
318
- * @example
319
- * // With recover() between migrations:
320
- * // Recovered data (V2) goes through the v2→v3 migration automatically.
321
- * const dataModel = new DataModelBuilder()
322
- * .from<V1>("v1")
323
- * .migrate<V2>("v2", (v1) => ({ ...v1, label: "" }))
324
- * .recover((version, data) => {
325
- * if (version === "legacy") return transformLegacy(data); // returns V2
326
- * return defaultRecover(version, data);
327
- * })
328
- * .migrate<V3>("v3", (v2) => ({ ...v2, description: "" }))
329
- * .init(() => ({ count: 0, label: "", description: "" }));
330
- */
331
- class DataModel {
332
- /** Latest version key — O(1) access for the common "already current" check. */
333
- latestVersion;
334
- /** Maps each known version key to the index of the first step to run from it. O(1) lookup. */
335
- stepsByFromVersion;
336
- steps;
337
- initialDataFn;
338
- recoverFn;
339
- recoverFromIndex;
340
- constructor({ versionChain, steps, initialDataFn, recoverFn = defaultRecover, recoverFromIndex, }) {
341
- if (versionChain.length === 0) {
342
- throw new Error("DataModel requires at least one version key");
343
- }
344
- this.latestVersion = versionChain[versionChain.length - 1];
345
- this.stepsByFromVersion = new Map(versionChain.map((v, i) => [v, i]));
346
- this.steps = steps;
347
- this.initialDataFn = initialDataFn;
348
- this.recoverFn = recoverFn;
349
- this.recoverFromIndex = recoverFromIndex ?? steps.length;
350
- }
351
- /**
352
- * Internal method for creating DataModel from builder.
353
- * Uses Symbol key to prevent external access.
354
- * @internal
355
- */
356
- static [FROM_BUILDER](state) {
357
- return new DataModel(state);
358
- }
359
- /**
360
- * The latest (current) version key in the migration chain.
361
- */
362
- get version() {
363
- return this.latestVersion;
364
- }
365
- /**
366
- * Get a fresh copy of the initial data.
367
- */
368
- initialData() {
369
- return this.initialDataFn();
370
- }
371
- /**
372
- * Get initial data wrapped with current version.
373
- * Used when creating new blocks or resetting to defaults.
374
- */
375
- getDefaultData() {
376
- return makeDataVersioned(this.latestVersion, this.initialDataFn());
377
- }
378
- recoverFrom(data, version) {
379
- // Step 1: call the recover function to get data at the recover point
380
- // Let errors (including DataUnrecoverableError) propagate to the caller.
381
- let currentData = this.recoverFn(version, data);
382
- // Step 2: run any migrations that were added after recover() in the chain
383
- for (let i = this.recoverFromIndex; i < this.steps.length; i++) {
384
- const step = this.steps[i];
385
- currentData = step.migrate(currentData);
386
- }
387
- return { version: this.latestVersion, data: currentData };
388
- }
389
- /**
390
- * Migrate versioned data from any version to the latest.
391
- *
392
- * - If version is in chain, applies needed migrations (O(1) lookup)
393
- * - If version is unknown, attempts recovery; falls back to initial data
394
- * - If a migration step fails, throws so the caller can preserve original data
395
- *
396
- * @param versioned - Data with version tag
397
- * @returns Migrated data at the latest version
398
- * @throws If a migration step from a known version fails
399
- */
400
- migrate(versioned) {
401
- const { version: fromVersion, data } = versioned;
402
- if (fromVersion === this.latestVersion) {
403
- return { version: this.latestVersion, data: data };
404
- }
405
- const startIndex = this.stepsByFromVersion.get(fromVersion);
406
- if (startIndex === undefined) {
407
- try {
408
- return this.recoverFrom(data, fromVersion);
409
- }
410
- catch {
411
- // Recovery failed (unknown version, recover fn threw, or post-recover
412
- // migration failed) — reset to initial data rather than blocking the update.
413
- return this.getDefaultData();
414
- }
415
- }
416
- let currentData = data;
417
- for (let i = startIndex; i < this.steps.length; i++) {
418
- const step = this.steps[i];
419
- currentData = step.migrate(currentData);
420
- }
421
- return { version: this.latestVersion, data: currentData };
422
- }
423
- }
369
+ * DataModel defines the block's data structure, initial values, and migrations.
370
+ * Used by BlockModelV3 to manage data state.
371
+ *
372
+ * Use `new DataModelBuilder()` to create a DataModel.
373
+ *
374
+ * @example
375
+ * // With recover() between migrations:
376
+ * // Recovered data (V2) goes through the v2→v3 migration automatically.
377
+ * const dataModel = new DataModelBuilder()
378
+ * .from<V1>("v1")
379
+ * .migrate<V2>("v2", (v1) => ({ ...v1, label: "" }))
380
+ * .recover((version, data) => {
381
+ * if (version === "legacy") return transformLegacy(data); // returns V2
382
+ * return defaultRecover(version, data);
383
+ * })
384
+ * .migrate<V3>("v3", (v2) => ({ ...v2, description: "" }))
385
+ * .init(() => ({ count: 0, label: "", description: "" }));
386
+ */
387
+ var DataModel = class DataModel {
388
+ /** Latest version key — O(1) access for the common "already current" check. */
389
+ latestVersion;
390
+ /** Maps each known version key to the index of the first step to run from it. O(1) lookup. */
391
+ stepsByFromVersion;
392
+ steps;
393
+ transferSteps;
394
+ initialDataFn;
395
+ recoverFn;
396
+ recoverFromIndex;
397
+ constructor({ versionChain, steps, transferSteps = [], initialDataFn, recoverFn = defaultRecover, recoverFromIndex }) {
398
+ if (versionChain.length === 0) throw new Error("DataModel requires at least one version key");
399
+ this.latestVersion = versionChain[versionChain.length - 1];
400
+ this.stepsByFromVersion = new Map(versionChain.map((v, i) => [v, i]));
401
+ this.steps = steps;
402
+ this.transferSteps = transferSteps;
403
+ this.initialDataFn = initialDataFn;
404
+ this.recoverFn = recoverFn;
405
+ this.recoverFromIndex = recoverFromIndex ?? steps.length;
406
+ }
407
+ /**
408
+ * Internal method for creating DataModel from builder.
409
+ * Uses Symbol key to prevent external access.
410
+ * @internal
411
+ */
412
+ static [FROM_BUILDER](state) {
413
+ return new DataModel(state);
414
+ }
415
+ /**
416
+ * The latest (current) version key in the migration chain.
417
+ */
418
+ get version() {
419
+ return this.latestVersion;
420
+ }
421
+ /**
422
+ * Get a fresh copy of the initial data.
423
+ */
424
+ initialData() {
425
+ return this.initialDataFn();
426
+ }
427
+ /**
428
+ * Get initial data wrapped with current version.
429
+ * Used when creating new blocks or resetting to defaults.
430
+ */
431
+ getDefaultData() {
432
+ return makeVersionedData(this.latestVersion, this.initialDataFn());
433
+ }
434
+ recoverFrom(data, version) {
435
+ let currentData = this.recoverFn(version, data);
436
+ for (let i = this.recoverFromIndex; i < this.steps.length; i++) currentData = this.steps[i].migrate(currentData);
437
+ return {
438
+ version: this.latestVersion,
439
+ data: currentData
440
+ };
441
+ }
442
+ /**
443
+ * Migrate versioned data from any version to the latest.
444
+ * Collects transfer extractions at their designated chain positions.
445
+ *
446
+ * - If version is in chain, applies needed migrations (O(1) lookup)
447
+ * - If version is unknown, attempts recovery; falls back to initial data
448
+ * - If a migration step fails, throws so the caller can preserve original data
449
+ *
450
+ * Transfers only fire during normal step-by-step migration:
451
+ * - Recovery path: returns empty transfers
452
+ * - Fast-path (already at latest): returns empty transfers
453
+ *
454
+ * @param versioned - Data with version tag
455
+ * @returns Migrated data at the latest version with transfer record
456
+ * @throws If a migration step from a known version fails
457
+ */
458
+ migrate(versioned) {
459
+ const { version: fromVersion, data } = versioned;
460
+ if (fromVersion === this.latestVersion) return {
461
+ version: this.latestVersion,
462
+ data,
463
+ transfers: {}
464
+ };
465
+ const startIndex = this.stepsByFromVersion.get(fromVersion);
466
+ if (startIndex === void 0) try {
467
+ return {
468
+ ...this.recoverFrom(data, fromVersion),
469
+ transfers: {}
470
+ };
471
+ } catch {
472
+ return {
473
+ ...this.getDefaultData(),
474
+ transfers: {}
475
+ };
476
+ }
477
+ let currentData = data;
478
+ const transfers = {};
479
+ for (let i = startIndex; i < this.steps.length; i++) {
480
+ for (const t of this.transferSteps) if (t.beforeStepIndex === i) transfers[t.pluginId] = {
481
+ version: t.targetVersion,
482
+ data: t.extract(currentData)
483
+ };
484
+ currentData = this.steps[i].migrate(currentData);
485
+ }
486
+ for (const t of this.transferSteps) if (t.beforeStepIndex >= this.steps.length && t.beforeStepIndex >= startIndex) transfers[t.pluginId] = {
487
+ version: t.targetVersion,
488
+ data: t.extract(currentData)
489
+ };
490
+ return {
491
+ version: this.latestVersion,
492
+ data: currentData,
493
+ transfers
494
+ };
495
+ }
496
+ };
424
497
 
425
- export { DataMigrationError, DataModel, DataModelBuilder, DataUnrecoverableError, defaultRecover, isDataUnrecoverableError, makeDataVersioned };
426
- //# sourceMappingURL=block_migrations.js.map
498
+ //#endregion
499
+ export { DataModel, DataModelBuilder, isDataUnrecoverableError };
500
+ //# sourceMappingURL=block_migrations.js.map