@milaboratories/milaboratories.pool-explorer.model 1.1.3 → 1.1.4
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.
- package/.turbo/turbo-build.log +3 -3
- package/.turbo/turbo-lint.log +1 -1
- package/.turbo/turbo-type-check.log +1 -1
- package/CHANGELOG.md +7 -0
- package/dist/bundle.js +148 -62
- package/dist/bundle.js.map +1 -1
- package/dist/model.json +1 -1
- package/package.json +6 -6
package/.turbo/turbo-build.log
CHANGED
|
@@ -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.
|
|
3
|
+
> @milaboratories/milaboratories.pool-explorer.model@1.1.4 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
|
[36m
|
|
9
9
|
[1m./src/index.ts[22m → [1mdist, dist[22m...[39m
|
|
10
|
-
[32mcreated [1mdist, dist[22m in [1m2.
|
|
10
|
+
[32mcreated [1mdist, dist[22m in [1m2.4s[22m[39m
|
|
11
11
|
[36m
|
|
12
12
|
[1m./src/index.ts[22m → [1mdist[22m...[39m
|
|
13
13
|
[1m[33m(!) Circular dependency[39m[22m
|
|
14
14
|
../../../../sdk/model/dist/components/PFrameForGraphs.js -> ../../../../sdk/model/dist/pframe_utils/columns.js -> ../../../../sdk/model/dist/components/PFrameForGraphs.js
|
|
15
|
-
[32mcreated [1mdist[22m in [1m3.
|
|
15
|
+
[32mcreated [1mdist[22m in [1m3.7s[22m[39m
|
|
16
16
|
Build completed successfully
|
package/.turbo/turbo-lint.log
CHANGED
|
@@ -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.
|
|
3
|
+
> @milaboratories/milaboratories.pool-explorer.model@1.1.4 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.
|
|
3
|
+
> @milaboratories/milaboratories.pool-explorer.model@1.1.4 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
package/dist/bundle.js
CHANGED
|
@@ -27,6 +27,11 @@
|
|
|
27
27
|
* Increment this when the storage structure itself changes (not block state migrations).
|
|
28
28
|
*/
|
|
29
29
|
const BLOCK_STORAGE_SCHEMA_VERSION = 'v1';
|
|
30
|
+
/**
|
|
31
|
+
* Default data version for new blocks without migrations.
|
|
32
|
+
* Unique identifier ensures blocks are created via DataModel API.
|
|
33
|
+
*/
|
|
34
|
+
const DATA_MODEL_DEFAULT_VERSION = '__pl_v1_d4e8f2a1__';
|
|
30
35
|
/**
|
|
31
36
|
* Type guard to check if a value is a valid BlockStorage object.
|
|
32
37
|
* Checks for the discriminator key and valid schema version.
|
|
@@ -46,16 +51,32 @@
|
|
|
46
51
|
* Creates a BlockStorage with the given initial data
|
|
47
52
|
*
|
|
48
53
|
* @param initialData - The initial data value (defaults to empty object)
|
|
49
|
-
* @param version - The initial data version (defaults to
|
|
54
|
+
* @param version - The initial data version key (defaults to DATA_MODEL_DEFAULT_VERSION)
|
|
50
55
|
* @returns A new BlockStorage instance with discriminator key
|
|
51
56
|
*/
|
|
52
|
-
function createBlockStorage(initialData = {}, version =
|
|
57
|
+
function createBlockStorage(initialData = {}, version = DATA_MODEL_DEFAULT_VERSION) {
|
|
53
58
|
return {
|
|
54
59
|
[BLOCK_STORAGE_KEY]: BLOCK_STORAGE_SCHEMA_VERSION,
|
|
55
60
|
__dataVersion: version,
|
|
56
61
|
__data: initialData,
|
|
57
62
|
};
|
|
58
63
|
}
|
|
64
|
+
/**
|
|
65
|
+
* Normalizes raw storage data to BlockStorage format.
|
|
66
|
+
* If the input is already a BlockStorage, returns it as-is.
|
|
67
|
+
* If the input is legacy format (raw state), wraps it in BlockStorage structure.
|
|
68
|
+
*
|
|
69
|
+
* @param raw - Raw storage data (may be legacy format or BlockStorage)
|
|
70
|
+
* @returns Normalized BlockStorage
|
|
71
|
+
*/
|
|
72
|
+
function normalizeBlockStorage(raw) {
|
|
73
|
+
if (isBlockStorage(raw)) {
|
|
74
|
+
const storage = raw;
|
|
75
|
+
return { ...storage, __dataVersion: String(storage.__dataVersion) };
|
|
76
|
+
}
|
|
77
|
+
// Legacy format: raw is the state directly
|
|
78
|
+
return createBlockStorage(raw);
|
|
79
|
+
}
|
|
59
80
|
// =============================================================================
|
|
60
81
|
// Data Access & Update Functions
|
|
61
82
|
// =============================================================================
|
|
@@ -7502,7 +7523,7 @@
|
|
|
7502
7523
|
}
|
|
7503
7524
|
}
|
|
7504
7525
|
|
|
7505
|
-
var version = "1.53.
|
|
7526
|
+
var version = "1.53.1";
|
|
7506
7527
|
|
|
7507
7528
|
const PlatformaSDKVersion = version;
|
|
7508
7529
|
|
|
@@ -7534,7 +7555,7 @@
|
|
|
7534
7555
|
*
|
|
7535
7556
|
* Callbacks registered by DataModel.registerCallbacks():
|
|
7536
7557
|
* - `__pl_data_initial`: () => initial data
|
|
7537
|
-
* - `
|
|
7558
|
+
* - `__pl_data_migrate`: (versioned) => DataMigrationResult
|
|
7538
7559
|
* - `__pl_storage_initial`: () => initial BlockStorage as JSON string
|
|
7539
7560
|
*
|
|
7540
7561
|
* @module block_storage_vm
|
|
@@ -7570,7 +7591,8 @@
|
|
|
7570
7591
|
}
|
|
7571
7592
|
// Check for BlockStorage format (has discriminator)
|
|
7572
7593
|
if (isBlockStorage(parsed)) {
|
|
7573
|
-
|
|
7594
|
+
const storage = normalizeBlockStorage(parsed);
|
|
7595
|
+
return { storage, data: getStorageData(storage) };
|
|
7574
7596
|
}
|
|
7575
7597
|
// Check for legacy V1/V2 format: { args, uiState }
|
|
7576
7598
|
if (isLegacyModelV1ApiFormat(parsed)) {
|
|
@@ -7635,10 +7657,10 @@
|
|
|
7635
7657
|
return getStorageDebugView(rawStorage);
|
|
7636
7658
|
});
|
|
7637
7659
|
/**
|
|
7638
|
-
* Runs storage migration using the DataModel's
|
|
7660
|
+
* Runs storage migration using the DataModel's migrate callback.
|
|
7639
7661
|
* This is the main entry point for the middle layer to trigger migrations.
|
|
7640
7662
|
*
|
|
7641
|
-
* Uses the '
|
|
7663
|
+
* Uses the '__pl_data_migrate' callback registered by DataModel.registerCallbacks() which:
|
|
7642
7664
|
* - Handles all migration logic internally
|
|
7643
7665
|
* - Returns { version, data, warning? } - warning present if reset to initial data
|
|
7644
7666
|
*
|
|
@@ -7662,26 +7684,26 @@
|
|
|
7662
7684
|
__data: data,
|
|
7663
7685
|
});
|
|
7664
7686
|
};
|
|
7665
|
-
// Get the
|
|
7666
|
-
const
|
|
7667
|
-
if (typeof
|
|
7668
|
-
return { error: '
|
|
7687
|
+
// Get the migrate callback (registered by DataModel.registerCallbacks())
|
|
7688
|
+
const migrateCallback = ctx.callbackRegistry['__pl_data_migrate'];
|
|
7689
|
+
if (typeof migrateCallback !== 'function') {
|
|
7690
|
+
return { error: '__pl_data_migrate callback not found (DataModel not registered)' };
|
|
7669
7691
|
}
|
|
7670
|
-
// Call the migrator's
|
|
7692
|
+
// Call the migrator's migrate function
|
|
7671
7693
|
let result;
|
|
7672
7694
|
try {
|
|
7673
|
-
result =
|
|
7695
|
+
result = migrateCallback({ version: currentVersion, data: currentData });
|
|
7674
7696
|
}
|
|
7675
7697
|
catch (e) {
|
|
7676
7698
|
const errorMsg = e instanceof Error ? e.message : String(e);
|
|
7677
|
-
return { error: `
|
|
7699
|
+
return { error: `migrate() threw: ${errorMsg}` };
|
|
7678
7700
|
}
|
|
7679
7701
|
// Build info message
|
|
7680
7702
|
const info = result.version === currentVersion
|
|
7681
|
-
? `No migration needed (
|
|
7703
|
+
? `No migration needed (${currentVersion})`
|
|
7682
7704
|
: result.warning
|
|
7683
|
-
? `Reset to initial data (
|
|
7684
|
-
: `Migrated
|
|
7705
|
+
? `Reset to initial data (${result.version})`
|
|
7706
|
+
: `Migrated ${currentVersion}→${result.version}`;
|
|
7685
7707
|
return {
|
|
7686
7708
|
newStorageJson: createStorageJson(result.data, result.version),
|
|
7687
7709
|
info,
|
|
@@ -7978,23 +8000,54 @@
|
|
|
7978
8000
|
}
|
|
7979
8001
|
}
|
|
7980
8002
|
|
|
8003
|
+
/** Create a DataVersioned wrapper with correct shape */
|
|
8004
|
+
function makeDataVersioned(version, data) {
|
|
8005
|
+
return { version, data };
|
|
8006
|
+
}
|
|
8007
|
+
/** Thrown by recover() to signal unrecoverable data. */
|
|
8008
|
+
class DataUnrecoverableError extends Error {
|
|
8009
|
+
name = 'DataUnrecoverableError';
|
|
8010
|
+
constructor(dataVersion) {
|
|
8011
|
+
super(`Unknown version '${dataVersion}'`);
|
|
8012
|
+
}
|
|
8013
|
+
}
|
|
8014
|
+
function isDataUnrecoverableError(error) {
|
|
8015
|
+
return error instanceof Error && error.name === 'DataUnrecoverableError';
|
|
8016
|
+
}
|
|
8017
|
+
/** Default recover function for unknown versions */
|
|
8018
|
+
const defaultRecover = (version, _data) => {
|
|
8019
|
+
throw new DataUnrecoverableError(version);
|
|
8020
|
+
};
|
|
7981
8021
|
/** Internal builder for chaining migrations */
|
|
7982
8022
|
class DataModelBuilder {
|
|
8023
|
+
versionChain;
|
|
7983
8024
|
migrationSteps;
|
|
7984
|
-
|
|
8025
|
+
recoverFn;
|
|
8026
|
+
constructor(versionChain, steps = [], recoverFn) {
|
|
8027
|
+
this.versionChain = versionChain;
|
|
7985
8028
|
this.migrationSteps = steps;
|
|
8029
|
+
this.recoverFn = recoverFn;
|
|
7986
8030
|
}
|
|
7987
|
-
/** Start a migration chain from an initial
|
|
7988
|
-
static from() {
|
|
7989
|
-
return new DataModelBuilder();
|
|
8031
|
+
/** Start a migration chain from an initial version */
|
|
8032
|
+
static from(initialVersion) {
|
|
8033
|
+
return new DataModelBuilder([initialVersion]);
|
|
7990
8034
|
}
|
|
7991
|
-
/** Add a migration step */
|
|
7992
|
-
migrate(fn) {
|
|
7993
|
-
|
|
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);
|
|
7994
8047
|
}
|
|
7995
8048
|
/** Finalize with initial data, creating the DataModel */
|
|
7996
8049
|
create(initialData, ..._) {
|
|
7997
|
-
return DataModel._fromBuilder(this.migrationSteps, initialData);
|
|
8050
|
+
return DataModel._fromBuilder(this.versionChain, this.migrationSteps, initialData, this.recoverFn);
|
|
7998
8051
|
}
|
|
7999
8052
|
}
|
|
8000
8053
|
/**
|
|
@@ -8009,37 +8062,61 @@
|
|
|
8009
8062
|
* }));
|
|
8010
8063
|
*
|
|
8011
8064
|
* // Data model with migrations
|
|
8065
|
+
* const Version = defineDataVersions({
|
|
8066
|
+
* V1: 'v1',
|
|
8067
|
+
* V2: 'v2',
|
|
8068
|
+
* V3: 'v3',
|
|
8069
|
+
* });
|
|
8070
|
+
*
|
|
8071
|
+
* type VersionedData = {
|
|
8072
|
+
* [Version.V1]: { numbers: number[] };
|
|
8073
|
+
* [Version.V2]: { numbers: number[]; labels: string[] };
|
|
8074
|
+
* [Version.V3]: { numbers: number[]; labels: string[]; description: string };
|
|
8075
|
+
* };
|
|
8076
|
+
*
|
|
8012
8077
|
* const dataModel = DataModel
|
|
8013
|
-
* .from<
|
|
8014
|
-
* .migrate((data) => ({ ...data, labels: [] }))
|
|
8015
|
-
* .migrate((data) => ({ ...data, description: '' }))
|
|
8016
|
-
* .
|
|
8078
|
+
* .from<VersionedData>(Version.V1)
|
|
8079
|
+
* .migrate(Version.V2, (data) => ({ ...data, labels: [] }))
|
|
8080
|
+
* .migrate(Version.V3, (data) => ({ ...data, description: '' }))
|
|
8081
|
+
* .recover((version, data) => {
|
|
8082
|
+
* if (version === 'legacy' && typeof data === 'object' && data !== null && 'numbers' in data) {
|
|
8083
|
+
* return { numbers: (data as { numbers: number[] }).numbers, labels: [], description: '' };
|
|
8084
|
+
* }
|
|
8085
|
+
* return defaultRecover(version, data);
|
|
8086
|
+
* })
|
|
8087
|
+
* .create(() => ({ numbers: [], labels: [], description: '' }));
|
|
8017
8088
|
*/
|
|
8018
8089
|
class DataModel {
|
|
8090
|
+
versionChain;
|
|
8019
8091
|
steps;
|
|
8020
|
-
|
|
8021
|
-
|
|
8092
|
+
initialDataFn;
|
|
8093
|
+
recoverFn;
|
|
8094
|
+
constructor(versionChain, steps, initialData, recover = defaultRecover) {
|
|
8095
|
+
if (versionChain.length === 0) {
|
|
8096
|
+
throw new Error('DataModel requires at least one version key');
|
|
8097
|
+
}
|
|
8098
|
+
this.versionChain = versionChain;
|
|
8022
8099
|
this.steps = steps;
|
|
8023
|
-
this.
|
|
8100
|
+
this.initialDataFn = initialData;
|
|
8101
|
+
this.recoverFn = recover;
|
|
8024
8102
|
}
|
|
8025
8103
|
/** Start a migration chain from an initial type */
|
|
8026
|
-
static from() {
|
|
8027
|
-
return DataModelBuilder.from();
|
|
8104
|
+
static from(initialVersion) {
|
|
8105
|
+
return DataModelBuilder.from(initialVersion);
|
|
8028
8106
|
}
|
|
8029
8107
|
/** Create a data model with just initial data (no migrations) */
|
|
8030
|
-
static create(initialData) {
|
|
8031
|
-
return new DataModel([], initialData);
|
|
8108
|
+
static create(initialData, version = DATA_MODEL_DEFAULT_VERSION) {
|
|
8109
|
+
return new DataModel([version], [], initialData);
|
|
8032
8110
|
}
|
|
8033
8111
|
/** Create from builder (internal use) */
|
|
8034
|
-
static _fromBuilder(steps, initialData) {
|
|
8035
|
-
return new DataModel(steps, initialData);
|
|
8112
|
+
static _fromBuilder(versionChain, steps, initialData, recover) {
|
|
8113
|
+
return new DataModel(versionChain, steps, initialData, recover);
|
|
8036
8114
|
}
|
|
8037
8115
|
/**
|
|
8038
|
-
* Latest version
|
|
8039
|
-
* Version 1 = initial state, each migration adds 1.
|
|
8116
|
+
* Latest version key.
|
|
8040
8117
|
*/
|
|
8041
8118
|
get version() {
|
|
8042
|
-
return this.
|
|
8119
|
+
return this.versionChain[this.versionChain.length - 1];
|
|
8043
8120
|
}
|
|
8044
8121
|
/** Number of migration steps */
|
|
8045
8122
|
get migrationCount() {
|
|
@@ -8047,43 +8124,52 @@
|
|
|
8047
8124
|
}
|
|
8048
8125
|
/** Get initial data */
|
|
8049
8126
|
initialData() {
|
|
8050
|
-
return this.
|
|
8127
|
+
return this.initialDataFn();
|
|
8051
8128
|
}
|
|
8052
8129
|
/** Get default data wrapped with current version */
|
|
8053
8130
|
getDefaultData() {
|
|
8054
|
-
return
|
|
8131
|
+
return makeDataVersioned(this.version, this.initialDataFn());
|
|
8132
|
+
}
|
|
8133
|
+
recoverFrom(data, version) {
|
|
8134
|
+
try {
|
|
8135
|
+
return { version: this.version, data: this.recoverFn(version, data) };
|
|
8136
|
+
}
|
|
8137
|
+
catch (error) {
|
|
8138
|
+
if (isDataUnrecoverableError(error)) {
|
|
8139
|
+
return { ...this.getDefaultData(), warning: error.message };
|
|
8140
|
+
}
|
|
8141
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
8142
|
+
return {
|
|
8143
|
+
...this.getDefaultData(),
|
|
8144
|
+
warning: `Recover failed for version '${version}': ${errorMessage}`,
|
|
8145
|
+
};
|
|
8146
|
+
}
|
|
8055
8147
|
}
|
|
8056
8148
|
/**
|
|
8057
|
-
*
|
|
8149
|
+
* Migrate versioned data from any version to the latest.
|
|
8058
8150
|
* Applies only the migrations needed (skips already-applied ones).
|
|
8059
8151
|
* If a migration fails, returns default data with a warning.
|
|
8060
8152
|
*/
|
|
8061
|
-
|
|
8153
|
+
migrate(versioned) {
|
|
8062
8154
|
const { version: fromVersion, data } = versioned;
|
|
8063
|
-
if (fromVersion > this.version) {
|
|
8064
|
-
throw new Error(`Cannot downgrade from version ${fromVersion} to ${this.version}`);
|
|
8065
|
-
}
|
|
8066
8155
|
if (fromVersion === this.version) {
|
|
8067
8156
|
return { version: this.version, data: data };
|
|
8068
8157
|
}
|
|
8069
|
-
|
|
8070
|
-
|
|
8071
|
-
|
|
8072
|
-
|
|
8073
|
-
const migrationsToApply = this.steps.slice(startIndex);
|
|
8158
|
+
const startIndex = this.versionChain.indexOf(fromVersion);
|
|
8159
|
+
if (startIndex < 0) {
|
|
8160
|
+
return this.recoverFrom(data, fromVersion);
|
|
8161
|
+
}
|
|
8074
8162
|
let currentData = data;
|
|
8075
|
-
for (let i =
|
|
8076
|
-
const
|
|
8077
|
-
const fromVer = stepIndex + 1;
|
|
8078
|
-
const toVer = stepIndex + 2;
|
|
8163
|
+
for (let i = startIndex; i < this.steps.length; i++) {
|
|
8164
|
+
const step = this.steps[i];
|
|
8079
8165
|
try {
|
|
8080
|
-
currentData =
|
|
8166
|
+
currentData = step.migrate(currentData);
|
|
8081
8167
|
}
|
|
8082
8168
|
catch (error) {
|
|
8083
8169
|
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
8084
8170
|
return {
|
|
8085
8171
|
...this.getDefaultData(),
|
|
8086
|
-
warning: `Migration
|
|
8172
|
+
warning: `Migration ${step.fromVersion}→${step.toVersion} failed: ${errorMessage}`,
|
|
8087
8173
|
};
|
|
8088
8174
|
}
|
|
8089
8175
|
}
|
|
@@ -8095,12 +8181,12 @@
|
|
|
8095
8181
|
*
|
|
8096
8182
|
* All callbacks are prefixed with `__pl_` to indicate internal SDK use:
|
|
8097
8183
|
* - `__pl_data_initial`: returns initial data for new blocks
|
|
8098
|
-
* - `
|
|
8184
|
+
* - `__pl_data_migrate`: migrates versioned data from any version to latest
|
|
8099
8185
|
* - `__pl_storage_initial`: returns initial BlockStorage as JSON string
|
|
8100
8186
|
*/
|
|
8101
8187
|
registerCallbacks() {
|
|
8102
|
-
tryRegisterCallback('__pl_data_initial', () => this.
|
|
8103
|
-
tryRegisterCallback('
|
|
8188
|
+
tryRegisterCallback('__pl_data_initial', () => this.initialDataFn());
|
|
8189
|
+
tryRegisterCallback('__pl_data_migrate', (versioned) => this.migrate(versioned));
|
|
8104
8190
|
tryRegisterCallback('__pl_storage_initial', () => {
|
|
8105
8191
|
const { version, data } = this.getDefaultData();
|
|
8106
8192
|
const storage = createBlockStorage(data, version);
|