@milaboratories/milaboratories.pool-explorer.model 1.1.4 → 1.1.5

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.
@@ -1,16 +1,16 @@
1
1
   WARN  Issue while reading "/home/runner/_work/platforma/platforma/.npmrc". Failed to replace env in config: ${NPMJS_TOKEN}
2
2
 
3
- > @milaboratories/milaboratories.pool-explorer.model@1.1.4 build /home/runner/_work/platforma/platforma/etc/blocks/pool-explorer/model
3
+ > @milaboratories/milaboratories.pool-explorer.model@1.1.5 build /home/runner/_work/platforma/platforma/etc/blocks/pool-explorer/model
4
4
  > ts-builder build --target block-model && block-tools build-model
5
5
 
6
6
  Building block-model project...
7
7
  ↳ rollup -c /configs/rollup.block-model.config.js
8
8
  
9
9
  ./src/index.ts → dist, dist...
10
- created dist, dist in 2.4s
10
+ created dist, dist in 1.7s
11
11
  
12
12
  ./src/index.ts → dist...
13
13
  (!) Circular dependency
14
14
  ../../../../sdk/model/dist/components/PFrameForGraphs.js -> ../../../../sdk/model/dist/pframe_utils/columns.js -> ../../../../sdk/model/dist/components/PFrameForGraphs.js
15
- created dist in 3.7s
15
+ created dist in 3.4s
16
16
  Build completed successfully
@@ -1,5 +1,5 @@
1
1
   WARN  Issue while reading "/home/runner/_work/platforma/platforma/.npmrc". Failed to replace env in config: ${NPMJS_TOKEN}
2
2
 
3
- > @milaboratories/milaboratories.pool-explorer.model@1.1.4 lint /home/runner/_work/platforma/platforma/etc/blocks/pool-explorer/model
3
+ > @milaboratories/milaboratories.pool-explorer.model@1.1.5 lint /home/runner/_work/platforma/platforma/etc/blocks/pool-explorer/model
4
4
  > eslint .
5
5
 
@@ -1,6 +1,6 @@
1
1
   WARN  Issue while reading "/home/runner/_work/platforma/platforma/.npmrc". Failed to replace env in config: ${NPMJS_TOKEN}
2
2
 
3
- > @milaboratories/milaboratories.pool-explorer.model@1.1.4 type-check /home/runner/_work/platforma/platforma/etc/blocks/pool-explorer/model
3
+ > @milaboratories/milaboratories.pool-explorer.model@1.1.5 type-check /home/runner/_work/platforma/platforma/etc/blocks/pool-explorer/model
4
4
  > ts-builder types --target block-model
5
5
 
6
6
  ↳ tsc --noEmit --project ./tsconfig.json --customConditions ,
package/CHANGELOG.md CHANGED
@@ -1,5 +1,12 @@
1
1
  # @milaboratories/milaboratories.pool-explorer.model
2
2
 
3
+ ## 1.1.5
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [57799dd]
8
+ - @platforma-sdk/model@1.53.2
9
+
3
10
  ## 1.1.4
4
11
 
5
12
  ### Patch Changes
package/dist/bundle.js CHANGED
@@ -72,7 +72,13 @@
72
72
  function normalizeBlockStorage(raw) {
73
73
  if (isBlockStorage(raw)) {
74
74
  const storage = raw;
75
- return { ...storage, __dataVersion: String(storage.__dataVersion) };
75
+ return {
76
+ ...storage,
77
+ // Fix for early released version where __dataVersion was a number
78
+ __dataVersion: typeof storage.__dataVersion === 'number'
79
+ ? DATA_MODEL_DEFAULT_VERSION
80
+ : storage.__dataVersion,
81
+ };
76
82
  }
77
83
  // Legacy format: raw is the state directly
78
84
  return createBlockStorage(raw);
@@ -7523,7 +7529,7 @@
7523
7529
  }
7524
7530
  }
7525
7531
 
7526
- var version = "1.53.1";
7532
+ var version = "1.53.2";
7527
7533
 
7528
7534
  const PlatformaSDKVersion = version;
7529
7535
 
@@ -7555,7 +7561,7 @@
7555
7561
  *
7556
7562
  * Callbacks registered by DataModel.registerCallbacks():
7557
7563
  * - `__pl_data_initial`: () => initial data
7558
- * - `__pl_data_migrate`: (versioned) => DataMigrationResult
7564
+ * - `__pl_data_upgrade`: (versioned) => DataMigrationResult
7559
7565
  * - `__pl_storage_initial`: () => initial BlockStorage as JSON string
7560
7566
  *
7561
7567
  * @module block_storage_vm
@@ -7660,7 +7666,7 @@
7660
7666
  * Runs storage migration using the DataModel's migrate callback.
7661
7667
  * This is the main entry point for the middle layer to trigger migrations.
7662
7668
  *
7663
- * Uses the '__pl_data_migrate' callback registered by DataModel.registerCallbacks() which:
7669
+ * Uses the '__pl_data_upgrade' callback registered by DataModel.registerCallbacks() which:
7664
7670
  * - Handles all migration logic internally
7665
7671
  * - Returns { version, data, warning? } - warning present if reset to initial data
7666
7672
  *
@@ -7685,9 +7691,9 @@
7685
7691
  });
7686
7692
  };
7687
7693
  // Get the migrate callback (registered by DataModel.registerCallbacks())
7688
- const migrateCallback = ctx.callbackRegistry['__pl_data_migrate'];
7694
+ const migrateCallback = ctx.callbackRegistry['__pl_data_upgrade'];
7689
7695
  if (typeof migrateCallback !== 'function') {
7690
- return { error: '__pl_data_migrate callback not found (DataModel not registered)' };
7696
+ return { error: '__pl_data_upgrade callback not found (DataModel not registered)' };
7691
7697
  }
7692
7698
  // Call the migrator's migrate function
7693
7699
  let result;
@@ -8014,54 +8020,38 @@
8014
8020
  function isDataUnrecoverableError(error) {
8015
8021
  return error instanceof Error && error.name === 'DataUnrecoverableError';
8016
8022
  }
8017
- /** Default recover function for unknown versions */
8023
+ /**
8024
+ * Default recover function for unknown versions.
8025
+ * Use as fallback at the end of custom recover functions.
8026
+ *
8027
+ * @example
8028
+ * .recover((version, data) => {
8029
+ * if (version === 'legacy') {
8030
+ * return transformLegacyData(data);
8031
+ * }
8032
+ * return defaultRecover(version, data);
8033
+ * })
8034
+ */
8018
8035
  const defaultRecover = (version, _data) => {
8019
8036
  throw new DataUnrecoverableError(version);
8020
8037
  };
8021
- /** Internal builder for chaining migrations */
8022
- class DataModelBuilder {
8023
- versionChain;
8024
- migrationSteps;
8025
- recoverFn;
8026
- constructor(versionChain, steps = [], recoverFn) {
8027
- this.versionChain = versionChain;
8028
- this.migrationSteps = steps;
8029
- this.recoverFn = recoverFn;
8030
- }
8031
- /** Start a migration chain from an initial version */
8032
- static from(initialVersion) {
8033
- return new DataModelBuilder([initialVersion]);
8034
- }
8035
- /** Add a migration step to the target version */
8036
- migrate(nextVersion, fn) {
8037
- if (this.versionChain.includes(nextVersion)) {
8038
- throw new Error(`Duplicate version '${nextVersion}' in migration chain`);
8039
- }
8040
- const fromVersion = this.versionChain[this.versionChain.length - 1];
8041
- const step = { fromVersion, toVersion: nextVersion, migrate: fn };
8042
- return new DataModelBuilder([...this.versionChain, nextVersion], [...this.migrationSteps, step]);
8043
- }
8044
- /** Set recovery handler for unknown or unsupported versions */
8045
- recover(fn) {
8046
- return new DataModelBuilder([...this.versionChain], [...this.migrationSteps], fn);
8047
- }
8048
- /** Finalize with initial data, creating the DataModel */
8049
- create(initialData, ..._) {
8050
- return DataModel._fromBuilder(this.versionChain, this.migrationSteps, initialData, this.recoverFn);
8051
- }
8052
- }
8038
+ /** Symbol for internal builder creation method */
8039
+ const FROM_BUILDER = Symbol('fromBuilder');
8053
8040
  /**
8054
8041
  * DataModel defines the block's data structure, initial values, and migrations.
8055
8042
  * Used by BlockModelV3 to manage data state.
8056
8043
  *
8044
+ * Two ways to create a DataModel:
8045
+ *
8046
+ * 1. **Simple (no migrations)** - Use `DataModel.create()`:
8057
8047
  * @example
8058
- * // Simple data model (no migrations)
8059
8048
  * const dataModel = DataModel.create<BlockData>(() => ({
8060
8049
  * numbers: [],
8061
8050
  * labels: [],
8062
8051
  * }));
8063
8052
  *
8064
- * // Data model with migrations
8053
+ * 2. **With migrations** - Use `new DataModelBuilder<VersionedData>()`:
8054
+ * @example
8065
8055
  * const Version = defineDataVersions({
8066
8056
  * V1: 'v1',
8067
8057
  * V2: 'v2',
@@ -8074,8 +8064,8 @@
8074
8064
  * [Version.V3]: { numbers: number[]; labels: string[]; description: string };
8075
8065
  * };
8076
8066
  *
8077
- * const dataModel = DataModel
8078
- * .from<VersionedData>(Version.V1)
8067
+ * const dataModel = new DataModelBuilder<VersionedData>()
8068
+ * .from(Version.V1)
8079
8069
  * .migrate(Version.V2, (data) => ({ ...data, labels: [] }))
8080
8070
  * .migrate(Version.V3, (data) => ({ ...data, description: '' }))
8081
8071
  * .recover((version, data) => {
@@ -8084,49 +8074,76 @@
8084
8074
  * }
8085
8075
  * return defaultRecover(version, data);
8086
8076
  * })
8087
- * .create(() => ({ numbers: [], labels: [], description: '' }));
8077
+ * .init(() => ({ numbers: [], labels: [], description: '' }));
8088
8078
  */
8089
8079
  class DataModel {
8090
8080
  versionChain;
8091
8081
  steps;
8092
8082
  initialDataFn;
8093
8083
  recoverFn;
8094
- constructor(versionChain, steps, initialData, recover = defaultRecover) {
8084
+ constructor({ versionChain, steps, initialDataFn, recoverFn = defaultRecover, }) {
8095
8085
  if (versionChain.length === 0) {
8096
8086
  throw new Error('DataModel requires at least one version key');
8097
8087
  }
8098
8088
  this.versionChain = versionChain;
8099
8089
  this.steps = steps;
8100
- this.initialDataFn = initialData;
8101
- this.recoverFn = recover;
8102
- }
8103
- /** Start a migration chain from an initial type */
8104
- static from(initialVersion) {
8105
- return DataModelBuilder.from(initialVersion);
8090
+ this.initialDataFn = initialDataFn;
8091
+ this.recoverFn = recoverFn;
8106
8092
  }
8107
- /** Create a data model with just initial data (no migrations) */
8093
+ /**
8094
+ * Create a DataModel with just initial data (no migrations).
8095
+ *
8096
+ * Use this for simple blocks that don't need version migrations.
8097
+ * The version will be set to an internal default value.
8098
+ *
8099
+ * @typeParam S - The state type
8100
+ * @param initialData - Factory function returning initial state
8101
+ * @param version - Optional custom version key (defaults to internal version)
8102
+ * @returns Finalized DataModel instance
8103
+ *
8104
+ * @example
8105
+ * const dataModel = DataModel.create<BlockData>(() => ({
8106
+ * numbers: [],
8107
+ * labels: [],
8108
+ * }));
8109
+ */
8108
8110
  static create(initialData, version = DATA_MODEL_DEFAULT_VERSION) {
8109
- return new DataModel([version], [], initialData);
8111
+ return new DataModel({
8112
+ versionChain: [version],
8113
+ steps: [],
8114
+ initialDataFn: initialData,
8115
+ });
8110
8116
  }
8111
- /** Create from builder (internal use) */
8112
- static _fromBuilder(versionChain, steps, initialData, recover) {
8113
- return new DataModel(versionChain, steps, initialData, recover);
8117
+ /**
8118
+ * Internal method for creating DataModel from builder.
8119
+ * Uses Symbol key to prevent external access.
8120
+ * @internal
8121
+ */
8122
+ static [FROM_BUILDER](state) {
8123
+ return new DataModel(state);
8114
8124
  }
8115
8125
  /**
8116
- * Latest version key.
8126
+ * The latest (current) version key in the migration chain.
8117
8127
  */
8118
8128
  get version() {
8119
8129
  return this.versionChain[this.versionChain.length - 1];
8120
8130
  }
8121
- /** Number of migration steps */
8131
+ /**
8132
+ * Number of migration steps defined.
8133
+ */
8122
8134
  get migrationCount() {
8123
8135
  return this.steps.length;
8124
8136
  }
8125
- /** Get initial data */
8137
+ /**
8138
+ * Get a fresh copy of the initial data.
8139
+ */
8126
8140
  initialData() {
8127
8141
  return this.initialDataFn();
8128
8142
  }
8129
- /** Get default data wrapped with current version */
8143
+ /**
8144
+ * Get initial data wrapped with current version.
8145
+ * Used when creating new blocks or resetting to defaults.
8146
+ */
8130
8147
  getDefaultData() {
8131
8148
  return makeDataVersioned(this.version, this.initialDataFn());
8132
8149
  }
@@ -8147,8 +8164,14 @@
8147
8164
  }
8148
8165
  /**
8149
8166
  * Migrate versioned data from any version to the latest.
8150
- * Applies only the migrations needed (skips already-applied ones).
8151
- * If a migration fails, returns default data with a warning.
8167
+ *
8168
+ * - If data is already at latest version, returns as-is
8169
+ * - If version is in chain, applies needed migrations
8170
+ * - If version is unknown, calls recover function
8171
+ * - If migration/recovery fails, returns default data with warning
8172
+ *
8173
+ * @param versioned - Data with version tag
8174
+ * @returns Migration result with data at latest version
8152
8175
  */
8153
8176
  migrate(versioned) {
8154
8177
  const { version: fromVersion, data } = versioned;
@@ -8179,14 +8202,11 @@
8179
8202
  * Register callbacks for use in the VM.
8180
8203
  * Called by BlockModelV3.create() to set up internal callbacks.
8181
8204
  *
8182
- * All callbacks are prefixed with `__pl_` to indicate internal SDK use:
8183
- * - `__pl_data_initial`: returns initial data for new blocks
8184
- * - `__pl_data_migrate`: migrates versioned data from any version to latest
8185
- * - `__pl_storage_initial`: returns initial BlockStorage as JSON string
8205
+ * @internal
8186
8206
  */
8187
8207
  registerCallbacks() {
8188
8208
  tryRegisterCallback('__pl_data_initial', () => this.initialDataFn());
8189
- tryRegisterCallback('__pl_data_migrate', (versioned) => this.migrate(versioned));
8209
+ tryRegisterCallback('__pl_data_upgrade', (versioned) => this.migrate(versioned));
8190
8210
  tryRegisterCallback('__pl_storage_initial', () => {
8191
8211
  const { version, data } = this.getDefaultData();
8192
8212
  const storage = createBlockStorage(data, version);