@platforma-sdk/model 1.81.1 → 1.83.0
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/dist/bconfig/index.d.ts +2 -2
- package/dist/bconfig/lambdas.d.ts +2 -12
- package/dist/bconfig/lambdas.d.ts.map +1 -1
- package/dist/bconfig/v3.d.ts +1 -1
- package/dist/block_migrations.cjs +92 -8
- package/dist/block_migrations.cjs.map +1 -1
- package/dist/block_migrations.d.ts +121 -32
- package/dist/block_migrations.d.ts.map +1 -1
- package/dist/block_migrations.js +92 -8
- package/dist/block_migrations.js.map +1 -1
- package/dist/block_model.cjs +71 -17
- package/dist/block_model.cjs.map +1 -1
- package/dist/block_model.d.ts +58 -22
- package/dist/block_model.d.ts.map +1 -1
- package/dist/block_model.js +72 -18
- package/dist/block_model.js.map +1 -1
- package/dist/block_storage_callbacks.cjs +194 -13
- package/dist/block_storage_callbacks.cjs.map +1 -1
- package/dist/block_storage_callbacks.js +192 -15
- package/dist/block_storage_callbacks.js.map +1 -1
- package/dist/block_storage_facade.cjs +4 -1
- package/dist/block_storage_facade.cjs.map +1 -1
- package/dist/block_storage_facade.d.ts +102 -0
- package/dist/block_storage_facade.d.ts.map +1 -1
- package/dist/block_storage_facade.js +4 -1
- package/dist/block_storage_facade.js.map +1 -1
- package/dist/config/index.d.ts +2 -6
- package/dist/config/type_engine.d.ts +7 -28
- package/dist/config/type_engine.d.ts.map +1 -1
- package/dist/index.cjs +20 -60
- package/dist/index.d.ts +5 -11
- package/dist/index.js +4 -8
- package/dist/package.cjs +1 -1
- package/dist/package.js +1 -1
- package/dist/render/api.cjs +0 -22
- package/dist/render/api.cjs.map +1 -1
- package/dist/render/api.d.ts +1 -9
- package/dist/render/api.d.ts.map +1 -1
- package/dist/render/api.js +1 -22
- package/dist/render/api.js.map +1 -1
- package/dist/render/index.cjs +0 -1
- package/dist/render/index.d.ts +2 -2
- package/dist/render/index.js +2 -2
- package/package.json +10 -9
- package/src/bconfig/lambdas.ts +1 -25
- package/src/block_migrations.ts +205 -55
- package/src/block_model.ts +190 -59
- package/src/block_storage_callbacks.ts +294 -15
- package/src/block_storage_facade.ts +95 -0
- package/src/config/index.ts +0 -4
- package/src/config/type_engine.ts +6 -49
- package/src/index.ts +0 -2
- package/src/kind_reference.test.ts +134 -0
- package/src/render/api.ts +0 -32
- package/src/template_init.test.ts +413 -0
- package/src/template_params.test.ts +135 -0
- package/src/typing.test.ts +4 -143
- package/dist/block_model_legacy.cjs +0 -240
- package/dist/block_model_legacy.cjs.map +0 -1
- package/dist/block_model_legacy.d.ts +0 -115
- package/dist/block_model_legacy.d.ts.map +0 -1
- package/dist/block_model_legacy.js +0 -240
- package/dist/block_model_legacy.js.map +0 -1
- package/dist/config/actions.cjs +0 -232
- package/dist/config/actions.cjs.map +0 -1
- package/dist/config/actions.d.ts +0 -48
- package/dist/config/actions.d.ts.map +0 -1
- package/dist/config/actions.js +0 -201
- package/dist/config/actions.js.map +0 -1
- package/dist/config/actions_kinds.d.ts +0 -116
- package/dist/config/actions_kinds.d.ts.map +0 -1
- package/dist/config/index.cjs +0 -33
- package/dist/config/index.js +0 -2
- package/dist/config/model_meta.d.ts +0 -9
- package/dist/config/model_meta.d.ts.map +0 -1
- package/dist/config/type_util.d.ts +0 -14
- package/dist/config/type_util.d.ts.map +0 -1
- package/dist/ref_util.cjs +0 -21
- package/dist/ref_util.cjs.map +0 -1
- package/dist/ref_util.d.ts +0 -19
- package/dist/ref_util.d.ts.map +0 -1
- package/dist/ref_util.js +0 -20
- package/dist/ref_util.js.map +0 -1
- package/src/block_model_legacy.ts +0 -465
- package/src/config/actions.ts +0 -468
- package/src/config/actions_kinds.ts +0 -264
- package/src/config/model_meta.ts +0 -5
- package/src/config/type_util.ts +0 -25
- package/src/ref_util.ts +0 -17
|
@@ -1,8 +1,28 @@
|
|
|
1
|
+
import { BlockKindReference } from "@milaboratories/pl-model-common";
|
|
2
|
+
import { CompiledBlockKind } from "@platforma-sdk/block-kind";
|
|
3
|
+
|
|
1
4
|
//#region src/block_migrations.d.ts
|
|
2
5
|
type DataVersionKey = string;
|
|
3
6
|
type DataMigrateFn<From, To> = (prev: Readonly<From>) => To;
|
|
4
|
-
|
|
7
|
+
/**
|
|
8
|
+
* Initial-data factory. Object-arg so future inputs (services, resolved refs)
|
|
9
|
+
* can extend it without a signature break. `Params` carries the block's
|
|
10
|
+
* kind-declared params type; `never` means the block reads no params yet.
|
|
11
|
+
*/
|
|
12
|
+
type DataCreateFn<T, Params = never> = (args: {
|
|
13
|
+
params?: Params;
|
|
14
|
+
}) => T;
|
|
5
15
|
type DataRecoverFn<T> = (version: DataVersionKey, data: unknown) => T;
|
|
16
|
+
/**
|
|
17
|
+
* The compiled block-kind object a block declares — exactly the output of
|
|
18
|
+
* `defineBlockKind` from `@platforma-sdk/block-kind`, consumed type-only.
|
|
19
|
+
*
|
|
20
|
+
* The kind object carries no reference field: the `{name}@{version}` reference
|
|
21
|
+
* is derived from it internally (via `formatKindRef`) at the point the builder
|
|
22
|
+
* and `BlockModelV3.create` need it. Aliased here so `DataModelBuilder` /
|
|
23
|
+
* `create` signatures directly accept `defineBlockKind`'s output.
|
|
24
|
+
*/
|
|
25
|
+
type BlockKind<Params = never> = CompiledBlockKind<Params>;
|
|
6
26
|
/**
|
|
7
27
|
* Minimal interface that .transfer() accepts. PluginInstance implements this.
|
|
8
28
|
* Defined here to avoid circular dependency with plugin_model.ts.
|
|
@@ -52,20 +72,35 @@ type LegacyV1State<Args, UiState> = {
|
|
|
52
72
|
args: Args;
|
|
53
73
|
uiState: UiState;
|
|
54
74
|
};
|
|
55
|
-
/**
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
75
|
+
/**
|
|
76
|
+
* The kind a chain belongs to, threaded unchanged from the builder into `DataModel`.
|
|
77
|
+
*
|
|
78
|
+
* Named because every constructor in this file carries exactly this pair, and they travel
|
|
79
|
+
* together by construction: a reference with no parser could not check the params it names,
|
|
80
|
+
* and a parser with no reference would have nothing to check them against.
|
|
81
|
+
*/
|
|
82
|
+
type KindWiring = {
|
|
83
|
+
/** Reference to the block kind this data model belongs to, if declared. */kindRef?: BlockKindReference; /** The kind's runtime params check, threaded with {@link KindWiring.kindRef}. */
|
|
84
|
+
parseInitializationParams?: (value: unknown) => unknown;
|
|
85
|
+
};
|
|
86
|
+
type RecoverState = {
|
|
61
87
|
recoverFn?: (version: DataVersionKey, data: unknown) => unknown;
|
|
62
88
|
/** Index of the first step to run after recovery. Equals the number of steps
|
|
63
89
|
* present at the time recover() was called. */
|
|
64
90
|
recoverFromIndex?: number;
|
|
65
91
|
};
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
92
|
+
/** Internal state passed from builder to DataModel */
|
|
93
|
+
type BuilderState<S> = KindWiring & RecoverState & {
|
|
94
|
+
versionChain: DataVersionKey[];
|
|
95
|
+
steps: MigrationStep[];
|
|
96
|
+
transferSteps: TransferStep[];
|
|
97
|
+
/**
|
|
98
|
+
* The params type is erased to `unknown` here: the builder checks the block's
|
|
99
|
+
* factory against its kind's params, but a caller that supplies params carries them as
|
|
100
|
+
* data it did not type — parsed file content, today — and cannot state the type. The
|
|
101
|
+
* kind's own parser is what recovers it.
|
|
102
|
+
*/
|
|
103
|
+
initialDataFn: DataCreateFn<S, unknown>;
|
|
69
104
|
};
|
|
70
105
|
/**
|
|
71
106
|
* Abstract base for both migration chain types.
|
|
@@ -76,11 +111,15 @@ type RecoverState = {
|
|
|
76
111
|
*
|
|
77
112
|
* @internal
|
|
78
113
|
*/
|
|
79
|
-
declare abstract class MigrationChainBase<Current, Transfers extends Record<string, unknown> = {}> {
|
|
114
|
+
declare abstract class MigrationChainBase<Current, Transfers extends Record<string, unknown> = {}, Params = never> {
|
|
80
115
|
protected readonly versionChain: DataVersionKey[];
|
|
81
116
|
protected readonly migrationSteps: MigrationStep[];
|
|
82
117
|
protected readonly transferSteps: TransferStep[];
|
|
83
|
-
|
|
118
|
+
/** Kind reference seeded by the builder, threaded through the chain into init(). */
|
|
119
|
+
protected readonly kindRef?: BlockKindReference;
|
|
120
|
+
/** The kind's runtime params check, carried for `init()` to hand to the DataModel. */
|
|
121
|
+
protected readonly parseInitializationParams?: (value: unknown) => unknown;
|
|
122
|
+
protected constructor(state: KindWiring & {
|
|
84
123
|
versionChain: DataVersionKey[];
|
|
85
124
|
steps: MigrationStep[];
|
|
86
125
|
transferSteps?: TransferStep[];
|
|
@@ -102,7 +141,7 @@ declare abstract class MigrationChainBase<Current, Transfers extends Record<stri
|
|
|
102
141
|
* @param initialData - Factory function returning the initial state
|
|
103
142
|
* @returns Finalized DataModel instance
|
|
104
143
|
*/
|
|
105
|
-
init(initialData: DataCreateFn<Current>): DataModel<Current, Transfers>;
|
|
144
|
+
init(initialData: DataCreateFn<Current, Params>): DataModel<Current, Params, Transfers>;
|
|
106
145
|
}
|
|
107
146
|
/**
|
|
108
147
|
* Migration chain after recover() or upgradeLegacy() has been called.
|
|
@@ -113,29 +152,27 @@ declare abstract class MigrationChainBase<Current, Transfers extends Record<stri
|
|
|
113
152
|
* @typeParam Transfers - Accumulated transfer types keyed by plugin ID
|
|
114
153
|
* @internal
|
|
115
154
|
*/
|
|
116
|
-
declare class DataModelMigrationChainWithRecover<Current, Transfers extends Record<string, unknown> = {}> extends MigrationChainBase<Current, Transfers> {
|
|
155
|
+
declare class DataModelMigrationChainWithRecover<Current, Transfers extends Record<string, unknown> = {}, Params = never> extends MigrationChainBase<Current, Transfers, Params> {
|
|
117
156
|
private readonly recoverFn?;
|
|
118
157
|
private readonly recoverFromIndex?;
|
|
119
158
|
/** @internal */
|
|
120
|
-
constructor(state: {
|
|
159
|
+
constructor(state: KindWiring & RecoverState & {
|
|
121
160
|
versionChain: DataVersionKey[];
|
|
122
161
|
steps: MigrationStep[];
|
|
123
162
|
transferSteps?: TransferStep[];
|
|
124
|
-
recoverFn?: (version: DataVersionKey, data: unknown) => unknown;
|
|
125
|
-
recoverFromIndex?: number;
|
|
126
163
|
});
|
|
127
164
|
protected recoverState(): RecoverState;
|
|
128
165
|
/**
|
|
129
166
|
* Add a migration step. Same semantics as on the base chain.
|
|
130
167
|
* recover() and upgradeLegacy() are not available — one has already been called.
|
|
131
168
|
*/
|
|
132
|
-
migrate<Next>(nextVersion: string, fn: DataMigrateFn<Current, Next>): DataModelMigrationChainWithRecover<Next, Transfers>;
|
|
169
|
+
migrate<Next>(nextVersion: string, fn: DataMigrateFn<Current, Next>): DataModelMigrationChainWithRecover<Next, Transfers, Params>;
|
|
133
170
|
/**
|
|
134
171
|
* Extract data at the current chain position for seeding a new plugin.
|
|
135
172
|
* The extract function's return type must match the plugin's transfer data type.
|
|
136
173
|
* Duplicate plugin IDs are rejected at both type and runtime level.
|
|
137
174
|
*/
|
|
138
|
-
transfer<Id extends string, L>(target: TransferTarget<Id & (Id extends keyof Transfers ? never : string), L>, extract: (data: Current) => L): DataModelMigrationChainWithRecover<Current, Transfers & Record<Id, L
|
|
175
|
+
transfer<Id extends string, L>(target: TransferTarget<Id & (Id extends keyof Transfers ? never : string), L>, extract: (data: Current) => L): DataModelMigrationChainWithRecover<Current, Transfers & Record<Id, L>, Params>;
|
|
139
176
|
}
|
|
140
177
|
/**
|
|
141
178
|
* Migration chain builder.
|
|
@@ -147,13 +184,15 @@ declare class DataModelMigrationChainWithRecover<Current, Transfers extends Reco
|
|
|
147
184
|
* @typeParam Transfers - Accumulated transfer types keyed by plugin ID
|
|
148
185
|
* @internal
|
|
149
186
|
*/
|
|
150
|
-
declare class DataModelMigrationChain<Current, Transfers extends Record<string, unknown> = {}> extends MigrationChainBase<Current, Transfers> {
|
|
187
|
+
declare class DataModelMigrationChain<Current, Transfers extends Record<string, unknown> = {}, Params = never> extends MigrationChainBase<Current, Transfers, Params> {
|
|
151
188
|
/** @internal */
|
|
152
189
|
constructor({
|
|
153
190
|
versionChain,
|
|
154
191
|
steps,
|
|
155
|
-
transferSteps
|
|
156
|
-
|
|
192
|
+
transferSteps,
|
|
193
|
+
kindRef,
|
|
194
|
+
parseInitializationParams
|
|
195
|
+
}: KindWiring & {
|
|
157
196
|
versionChain: DataVersionKey[];
|
|
158
197
|
steps?: MigrationStep[];
|
|
159
198
|
transferSteps?: TransferStep[];
|
|
@@ -169,7 +208,7 @@ declare class DataModelMigrationChain<Current, Transfers extends Record<string,
|
|
|
169
208
|
* @example
|
|
170
209
|
* .migrate<BlockDataV2>("v2", (v1) => ({ ...v1, labels: [] }))
|
|
171
210
|
*/
|
|
172
|
-
migrate<Next>(nextVersion: string, fn: DataMigrateFn<Current, Next>): DataModelMigrationChain<Next, Transfers>;
|
|
211
|
+
migrate<Next>(nextVersion: string, fn: DataMigrateFn<Current, Next>): DataModelMigrationChain<Next, Transfers, Params>;
|
|
173
212
|
/**
|
|
174
213
|
* Extract data at the current chain position for seeding a new plugin.
|
|
175
214
|
* The extract function's return type must match the plugin's transfer data type.
|
|
@@ -183,7 +222,7 @@ declare class DataModelMigrationChain<Current, Transfers extends Record<string,
|
|
|
183
222
|
* .transfer(tablePlugin, (v1) => ({ state: v1.tableState }))
|
|
184
223
|
* .migrate<V2>("v2", ({ tableState: _, ...rest }) => rest)
|
|
185
224
|
*/
|
|
186
|
-
transfer<Id extends string, L>(target: TransferTarget<Id & (Id extends keyof Transfers ? never : string), L>, extract: (data: Current) => L): DataModelMigrationChain<Current, Transfers & Record<Id, L
|
|
225
|
+
transfer<Id extends string, L>(target: TransferTarget<Id & (Id extends keyof Transfers ? never : string), L>, extract: (data: Current) => L): DataModelMigrationChain<Current, Transfers & Record<Id, L>, Params>;
|
|
187
226
|
/**
|
|
188
227
|
* Set a recovery handler for unknown or legacy versions.
|
|
189
228
|
*
|
|
@@ -207,7 +246,7 @@ declare class DataModelMigrationChain<Current, Transfers extends Record<string,
|
|
|
207
246
|
* .migrate<V3>("v3", (v2) => ({ ...v2, description: "" }))
|
|
208
247
|
* .init(() => ({ count: 0, label: "", description: "" }));
|
|
209
248
|
*/
|
|
210
|
-
recover(fn: DataRecoverFn<Current>): DataModelMigrationChainWithRecover<Current, Transfers>;
|
|
249
|
+
recover(fn: DataRecoverFn<Current>): DataModelMigrationChainWithRecover<Current, Transfers, Params>;
|
|
211
250
|
}
|
|
212
251
|
/**
|
|
213
252
|
* Initial migration chain returned by `.from()`.
|
|
@@ -218,7 +257,7 @@ declare class DataModelMigrationChain<Current, Transfers extends Record<string,
|
|
|
218
257
|
* @typeParam Transfers - Accumulated transfer types keyed by plugin ID
|
|
219
258
|
* @internal
|
|
220
259
|
*/
|
|
221
|
-
declare class DataModelInitialChain<Current, Transfers extends Record<string, unknown> = {}> extends DataModelMigrationChain<Current, Transfers> {
|
|
260
|
+
declare class DataModelInitialChain<Current, Transfers extends Record<string, unknown> = {}, Params = never> extends DataModelMigrationChain<Current, Transfers, Params> {
|
|
222
261
|
/**
|
|
223
262
|
* Handle legacy V1 model state ({ args, uiState }) when upgrading a block from
|
|
224
263
|
* BlockModel V1 to BlockModelV3.
|
|
@@ -253,7 +292,7 @@ declare class DataModelInitialChain<Current, Transfers extends Record<string, un
|
|
|
253
292
|
* }))
|
|
254
293
|
* .init(() => ({ inputFile: '', threshold: 0, selectedTab: 'main' }));
|
|
255
294
|
*/
|
|
256
|
-
upgradeLegacy<Args, UiState = unknown>(fn: (legacy: LegacyV1State<Args, UiState>) => Current): DataModelMigrationChainWithRecover<Current, Transfers>;
|
|
295
|
+
upgradeLegacy<Args, UiState = unknown>(fn: (legacy: LegacyV1State<Args, UiState>) => Current): DataModelMigrationChainWithRecover<Current, Transfers, Params>;
|
|
257
296
|
}
|
|
258
297
|
/**
|
|
259
298
|
* Builder entry point for creating DataModel with type-safe migrations.
|
|
@@ -301,7 +340,20 @@ declare class DataModelInitialChain<Current, Transfers extends Record<string, un
|
|
|
301
340
|
* }))
|
|
302
341
|
* .init(() => ({ inputFile: '', selectedTab: 'main' }));
|
|
303
342
|
*/
|
|
304
|
-
declare class DataModelBuilder {
|
|
343
|
+
declare class DataModelBuilder<Params = never> {
|
|
344
|
+
#private;
|
|
345
|
+
/**
|
|
346
|
+
* @param opts.kind - The block kind this data model implements. Its reference
|
|
347
|
+
* is captured and baked into the config so the manifest can advertise which
|
|
348
|
+
* kind the block satisfies, and its `Params` type flows into `.init()`.
|
|
349
|
+
* Optional during the transition window while existing V3 blocks are
|
|
350
|
+
* migrated to kind-carrying builders; a kind-less builder simply carries no
|
|
351
|
+
* reference and the reconciler can't project it yet. Object form mirrors
|
|
352
|
+
* `BlockModelV3.create({ dataModel, kind })`.
|
|
353
|
+
*/
|
|
354
|
+
constructor(opts?: {
|
|
355
|
+
kind?: BlockKind<Params>;
|
|
356
|
+
});
|
|
305
357
|
/**
|
|
306
358
|
* Start the migration chain with the given initial data type and version key.
|
|
307
359
|
*
|
|
@@ -309,7 +361,7 @@ declare class DataModelBuilder {
|
|
|
309
361
|
* @param initialVersion - Version key string (e.g. "v1")
|
|
310
362
|
* @returns Migration chain builder
|
|
311
363
|
*/
|
|
312
|
-
from<T>(initialVersion: string): DataModelInitialChain<T>;
|
|
364
|
+
from<T>(initialVersion: string): DataModelInitialChain<T, {}, Params>;
|
|
313
365
|
}
|
|
314
366
|
/**
|
|
315
367
|
* DataModel defines the block's data structure, initial values, and migrations.
|
|
@@ -330,9 +382,12 @@ declare class DataModelBuilder {
|
|
|
330
382
|
* .migrate<V3>("v3", (v2) => ({ ...v2, description: "" }))
|
|
331
383
|
* .init(() => ({ count: 0, label: "", description: "" }));
|
|
332
384
|
*/
|
|
333
|
-
declare class DataModel<State, Transfers extends Record<string, unknown> = {}> {
|
|
385
|
+
declare class DataModel<State, Params = never, Transfers extends Record<string, unknown> = {}> {
|
|
334
386
|
/** @internal Phantom field to anchor the Transfers type parameter. */
|
|
335
387
|
readonly __transfers?: Transfers;
|
|
388
|
+
/** @internal Phantom field to anchor the Params type parameter (drives the
|
|
389
|
+
* compile-time kind cross-check in `BlockModelV3.create`). */
|
|
390
|
+
readonly __params?: Params;
|
|
336
391
|
/** Latest version key — O(1) access for the common "already current" check. */
|
|
337
392
|
private readonly latestVersion;
|
|
338
393
|
/** Maps each known version key to the index of the first step to run from it. O(1) lookup. */
|
|
@@ -342,13 +397,32 @@ declare class DataModel<State, Transfers extends Record<string, unknown> = {}> {
|
|
|
342
397
|
private readonly initialDataFn;
|
|
343
398
|
private readonly recoverFn;
|
|
344
399
|
private readonly recoverFromIndex;
|
|
400
|
+
/** Reference to the block kind this data model was built for, if any. */
|
|
401
|
+
private readonly _kindRef?;
|
|
402
|
+
/** The kind's runtime params check, if it declares one. */
|
|
403
|
+
private readonly _parseInitializationParams?;
|
|
345
404
|
private constructor();
|
|
346
405
|
/**
|
|
347
406
|
* Internal method for creating DataModel from builder.
|
|
348
407
|
* Uses Symbol key to prevent external access.
|
|
349
408
|
* @internal
|
|
350
409
|
*/
|
|
351
|
-
static [FROM_BUILDER]<S, T extends Record<string, unknown> = {}>(state: BuilderState<S>): DataModel<S, T>;
|
|
410
|
+
static [FROM_BUILDER]<S, P = never, T extends Record<string, unknown> = {}>(state: BuilderState<S>): DataModel<S, P, T>;
|
|
411
|
+
/**
|
|
412
|
+
* Reference to the block kind this data model was built for, or `undefined`
|
|
413
|
+
* for a kind-less builder. Used by `BlockModelV3.create` to cross-check that
|
|
414
|
+
* the kind handed to the builder matches the kind handed to `create`.
|
|
415
|
+
* @internal
|
|
416
|
+
*/
|
|
417
|
+
get kindRef(): BlockKindReference | undefined;
|
|
418
|
+
/**
|
|
419
|
+
* The kind's runtime params check, or `undefined` if the kind declares none (or
|
|
420
|
+
* there is no kind). Read by `BlockModelV3.done()` to register the check, and
|
|
421
|
+
* carried here rather than only on the model because `init` — the one place params
|
|
422
|
+
* are consumed — lives on this side.
|
|
423
|
+
* @internal
|
|
424
|
+
*/
|
|
425
|
+
get templateParamsParser(): ((value: unknown) => unknown) | undefined;
|
|
352
426
|
/**
|
|
353
427
|
* The latest (current) version key in the migration chain.
|
|
354
428
|
*/
|
|
@@ -362,6 +436,21 @@ declare class DataModel<State, Transfers extends Record<string, unknown> = {}> {
|
|
|
362
436
|
* Used when creating new blocks or resetting to defaults.
|
|
363
437
|
*/
|
|
364
438
|
getDefaultData(): DataVersioned<State>;
|
|
439
|
+
/**
|
|
440
|
+
* Get initial data built from params, wrapped with current version.
|
|
441
|
+
*
|
|
442
|
+
* The counterpart of {@link getDefaultData} for a block created from a template
|
|
443
|
+
* entry: the factory receives the entry's params instead of nothing. A factory
|
|
444
|
+
* that ignores its argument produces the same result as `getDefaultData`, which
|
|
445
|
+
* is why the two are separate methods rather than one optional argument — the
|
|
446
|
+
* caller decides which contract it is asking for, and a block that cannot honour
|
|
447
|
+
* params must not silently look like one that can.
|
|
448
|
+
*
|
|
449
|
+
* References inside `params` are already resolved to the target project's
|
|
450
|
+
* concrete ids by the time they get here; the factory never sees a
|
|
451
|
+
* template-local one.
|
|
452
|
+
*/
|
|
453
|
+
getDataFromParams(params: unknown): DataVersioned<State>;
|
|
365
454
|
private recoverFrom;
|
|
366
455
|
/**
|
|
367
456
|
* Migrate versioned data from any version to the latest.
|
|
@@ -384,5 +473,5 @@ declare class DataModel<State, Transfers extends Record<string, unknown> = {}> {
|
|
|
384
473
|
};
|
|
385
474
|
}
|
|
386
475
|
//#endregion
|
|
387
|
-
export { DataCreateFn, DataMigrateFn, DataModel, DataModelBuilder, DataRecoverFn, DataVersionKey, DataVersioned, LegacyV1State, TransferRecord, TransferStep, TransferTarget };
|
|
476
|
+
export { BlockKind, DataCreateFn, DataMigrateFn, DataModel, DataModelBuilder, DataRecoverFn, DataVersionKey, DataVersioned, LegacyV1State, TransferRecord, TransferStep, TransferTarget };
|
|
388
477
|
//# sourceMappingURL=block_migrations.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"block_migrations.d.ts","names":[],"sources":["../src/block_migrations.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"block_migrations.d.ts","names":[],"sources":["../src/block_migrations.ts"],"mappings":";;;;KAKY,cAAA;AAAA,KACA,aAAA,cAA2B,I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EAAA;AAAA"}
|
package/dist/block_migrations.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { DATA_MODEL_LEGACY_VERSION } from "./block_storage.js";
|
|
2
|
+
import { formatKindRef } from "@milaboratories/pl-model-common";
|
|
2
3
|
//#region src/block_migrations.ts
|
|
3
4
|
/** Create a DataVersioned wrapper with correct shape */
|
|
4
5
|
function makeVersionedData(version, data) {
|
|
@@ -47,10 +48,16 @@ var MigrationChainBase = class {
|
|
|
47
48
|
versionChain;
|
|
48
49
|
migrationSteps;
|
|
49
50
|
transferSteps;
|
|
51
|
+
/** Kind reference seeded by the builder, threaded through the chain into init(). */
|
|
52
|
+
kindRef;
|
|
53
|
+
/** The kind's runtime params check, carried for `init()` to hand to the DataModel. */
|
|
54
|
+
parseInitializationParams;
|
|
50
55
|
constructor(state) {
|
|
51
56
|
this.versionChain = state.versionChain;
|
|
52
57
|
this.migrationSteps = state.steps;
|
|
53
58
|
this.transferSteps = state.transferSteps ?? [];
|
|
59
|
+
this.kindRef = state.kindRef;
|
|
60
|
+
this.parseInitializationParams = state.parseInitializationParams;
|
|
54
61
|
}
|
|
55
62
|
/** Appends a migration step and returns the new versionChain and steps arrays. */
|
|
56
63
|
buildStep(nextVersion, fn) {
|
|
@@ -92,6 +99,8 @@ var MigrationChainBase = class {
|
|
|
92
99
|
steps: this.migrationSteps,
|
|
93
100
|
transferSteps: this.transferSteps,
|
|
94
101
|
initialDataFn: initialData,
|
|
102
|
+
kindRef: this.kindRef,
|
|
103
|
+
parseInitializationParams: this.parseInitializationParams,
|
|
95
104
|
...this.recoverState()
|
|
96
105
|
});
|
|
97
106
|
}
|
|
@@ -130,6 +139,8 @@ var DataModelMigrationChainWithRecover = class DataModelMigrationChainWithRecove
|
|
|
130
139
|
versionChain,
|
|
131
140
|
steps,
|
|
132
141
|
transferSteps: this.transferSteps,
|
|
142
|
+
kindRef: this.kindRef,
|
|
143
|
+
parseInitializationParams: this.parseInitializationParams,
|
|
133
144
|
recoverFn: this.recoverFn,
|
|
134
145
|
recoverFromIndex: this.recoverFromIndex
|
|
135
146
|
});
|
|
@@ -145,6 +156,8 @@ var DataModelMigrationChainWithRecover = class DataModelMigrationChainWithRecove
|
|
|
145
156
|
versionChain: this.versionChain,
|
|
146
157
|
steps: this.migrationSteps,
|
|
147
158
|
transferSteps,
|
|
159
|
+
kindRef: this.kindRef,
|
|
160
|
+
parseInitializationParams: this.parseInitializationParams,
|
|
148
161
|
recoverFn: this.recoverFn,
|
|
149
162
|
recoverFromIndex: this.recoverFromIndex
|
|
150
163
|
});
|
|
@@ -162,11 +175,13 @@ var DataModelMigrationChainWithRecover = class DataModelMigrationChainWithRecove
|
|
|
162
175
|
*/
|
|
163
176
|
var DataModelMigrationChain = class DataModelMigrationChain extends MigrationChainBase {
|
|
164
177
|
/** @internal */
|
|
165
|
-
constructor({ versionChain, steps = [], transferSteps = [] }) {
|
|
178
|
+
constructor({ versionChain, steps = [], transferSteps = [], kindRef, parseInitializationParams }) {
|
|
166
179
|
super({
|
|
167
180
|
versionChain,
|
|
168
181
|
steps,
|
|
169
|
-
transferSteps
|
|
182
|
+
transferSteps,
|
|
183
|
+
kindRef,
|
|
184
|
+
parseInitializationParams
|
|
170
185
|
});
|
|
171
186
|
}
|
|
172
187
|
/**
|
|
@@ -185,7 +200,9 @@ var DataModelMigrationChain = class DataModelMigrationChain extends MigrationCha
|
|
|
185
200
|
return new DataModelMigrationChain({
|
|
186
201
|
versionChain,
|
|
187
202
|
steps,
|
|
188
|
-
transferSteps: this.transferSteps
|
|
203
|
+
transferSteps: this.transferSteps,
|
|
204
|
+
kindRef: this.kindRef,
|
|
205
|
+
parseInitializationParams: this.parseInitializationParams
|
|
189
206
|
});
|
|
190
207
|
}
|
|
191
208
|
/**
|
|
@@ -206,7 +223,9 @@ var DataModelMigrationChain = class DataModelMigrationChain extends MigrationCha
|
|
|
206
223
|
return new DataModelMigrationChain({
|
|
207
224
|
versionChain: this.versionChain,
|
|
208
225
|
steps: this.migrationSteps,
|
|
209
|
-
transferSteps
|
|
226
|
+
transferSteps,
|
|
227
|
+
kindRef: this.kindRef,
|
|
228
|
+
parseInitializationParams: this.parseInitializationParams
|
|
210
229
|
});
|
|
211
230
|
}
|
|
212
231
|
/**
|
|
@@ -237,6 +256,8 @@ var DataModelMigrationChain = class DataModelMigrationChain extends MigrationCha
|
|
|
237
256
|
versionChain: this.versionChain,
|
|
238
257
|
steps: this.migrationSteps,
|
|
239
258
|
transferSteps: this.transferSteps,
|
|
259
|
+
kindRef: this.kindRef,
|
|
260
|
+
parseInitializationParams: this.parseInitializationParams,
|
|
240
261
|
recoverFn: fn,
|
|
241
262
|
recoverFromIndex: this.migrationSteps.length
|
|
242
263
|
});
|
|
@@ -299,6 +320,8 @@ var DataModelInitialChain = class extends DataModelMigrationChain {
|
|
|
299
320
|
return new DataModelMigrationChainWithRecover({
|
|
300
321
|
versionChain: [DATA_MODEL_LEGACY_VERSION, ...this.versionChain],
|
|
301
322
|
steps: [step, ...this.migrationSteps],
|
|
323
|
+
kindRef: this.kindRef,
|
|
324
|
+
parseInitializationParams: this.parseInitializationParams,
|
|
302
325
|
transferSteps: this.transferSteps.map((t) => ({
|
|
303
326
|
...t,
|
|
304
327
|
beforeStepIndex: t.beforeStepIndex + 1
|
|
@@ -353,6 +376,21 @@ var DataModelInitialChain = class extends DataModelMigrationChain {
|
|
|
353
376
|
* .init(() => ({ inputFile: '', selectedTab: 'main' }));
|
|
354
377
|
*/
|
|
355
378
|
var DataModelBuilder = class {
|
|
379
|
+
#kindRef;
|
|
380
|
+
#parseInitializationParams;
|
|
381
|
+
/**
|
|
382
|
+
* @param opts.kind - The block kind this data model implements. Its reference
|
|
383
|
+
* is captured and baked into the config so the manifest can advertise which
|
|
384
|
+
* kind the block satisfies, and its `Params` type flows into `.init()`.
|
|
385
|
+
* Optional during the transition window while existing V3 blocks are
|
|
386
|
+
* migrated to kind-carrying builders; a kind-less builder simply carries no
|
|
387
|
+
* reference and the reconciler can't project it yet. Object form mirrors
|
|
388
|
+
* `BlockModelV3.create({ dataModel, kind })`.
|
|
389
|
+
*/
|
|
390
|
+
constructor(opts) {
|
|
391
|
+
this.#kindRef = opts?.kind ? formatKindRef(opts.kind) : void 0;
|
|
392
|
+
this.#parseInitializationParams = opts?.kind?.parseInitializationParams;
|
|
393
|
+
}
|
|
356
394
|
/**
|
|
357
395
|
* Start the migration chain with the given initial data type and version key.
|
|
358
396
|
*
|
|
@@ -361,7 +399,11 @@ var DataModelBuilder = class {
|
|
|
361
399
|
* @returns Migration chain builder
|
|
362
400
|
*/
|
|
363
401
|
from(initialVersion) {
|
|
364
|
-
return new DataModelInitialChain({
|
|
402
|
+
return new DataModelInitialChain({
|
|
403
|
+
versionChain: [initialVersion],
|
|
404
|
+
kindRef: this.#kindRef,
|
|
405
|
+
parseInitializationParams: this.#parseInitializationParams
|
|
406
|
+
});
|
|
365
407
|
}
|
|
366
408
|
};
|
|
367
409
|
/**
|
|
@@ -393,13 +435,19 @@ var DataModel = class DataModel {
|
|
|
393
435
|
initialDataFn;
|
|
394
436
|
recoverFn;
|
|
395
437
|
recoverFromIndex;
|
|
396
|
-
|
|
438
|
+
/** Reference to the block kind this data model was built for, if any. */
|
|
439
|
+
_kindRef;
|
|
440
|
+
/** The kind's runtime params check, if it declares one. */
|
|
441
|
+
_parseInitializationParams;
|
|
442
|
+
constructor({ versionChain, steps, transferSteps = [], initialDataFn, kindRef, parseInitializationParams, recoverFn = defaultRecover, recoverFromIndex }) {
|
|
397
443
|
if (versionChain.length === 0) throw new Error("DataModel requires at least one version key");
|
|
398
444
|
this.latestVersion = versionChain[versionChain.length - 1];
|
|
399
445
|
this.stepsByFromVersion = new Map(versionChain.map((v, i) => [v, i]));
|
|
400
446
|
this.steps = steps;
|
|
401
447
|
this.transferSteps = transferSteps;
|
|
402
448
|
this.initialDataFn = initialDataFn;
|
|
449
|
+
this._kindRef = kindRef;
|
|
450
|
+
this._parseInitializationParams = parseInitializationParams;
|
|
403
451
|
this.recoverFn = recoverFn;
|
|
404
452
|
this.recoverFromIndex = recoverFromIndex ?? steps.length;
|
|
405
453
|
}
|
|
@@ -412,6 +460,25 @@ var DataModel = class DataModel {
|
|
|
412
460
|
return new DataModel(state);
|
|
413
461
|
}
|
|
414
462
|
/**
|
|
463
|
+
* Reference to the block kind this data model was built for, or `undefined`
|
|
464
|
+
* for a kind-less builder. Used by `BlockModelV3.create` to cross-check that
|
|
465
|
+
* the kind handed to the builder matches the kind handed to `create`.
|
|
466
|
+
* @internal
|
|
467
|
+
*/
|
|
468
|
+
get kindRef() {
|
|
469
|
+
return this._kindRef;
|
|
470
|
+
}
|
|
471
|
+
/**
|
|
472
|
+
* The kind's runtime params check, or `undefined` if the kind declares none (or
|
|
473
|
+
* there is no kind). Read by `BlockModelV3.done()` to register the check, and
|
|
474
|
+
* carried here rather than only on the model because `init` — the one place params
|
|
475
|
+
* are consumed — lives on this side.
|
|
476
|
+
* @internal
|
|
477
|
+
*/
|
|
478
|
+
get templateParamsParser() {
|
|
479
|
+
return this._parseInitializationParams;
|
|
480
|
+
}
|
|
481
|
+
/**
|
|
415
482
|
* The latest (current) version key in the migration chain.
|
|
416
483
|
*/
|
|
417
484
|
get version() {
|
|
@@ -421,14 +488,31 @@ var DataModel = class DataModel {
|
|
|
421
488
|
* Get a fresh copy of the initial data.
|
|
422
489
|
*/
|
|
423
490
|
initialData() {
|
|
424
|
-
return this.initialDataFn();
|
|
491
|
+
return this.initialDataFn({});
|
|
425
492
|
}
|
|
426
493
|
/**
|
|
427
494
|
* Get initial data wrapped with current version.
|
|
428
495
|
* Used when creating new blocks or resetting to defaults.
|
|
429
496
|
*/
|
|
430
497
|
getDefaultData() {
|
|
431
|
-
return makeVersionedData(this.latestVersion, this.initialDataFn());
|
|
498
|
+
return makeVersionedData(this.latestVersion, this.initialDataFn({}));
|
|
499
|
+
}
|
|
500
|
+
/**
|
|
501
|
+
* Get initial data built from params, wrapped with current version.
|
|
502
|
+
*
|
|
503
|
+
* The counterpart of {@link getDefaultData} for a block created from a template
|
|
504
|
+
* entry: the factory receives the entry's params instead of nothing. A factory
|
|
505
|
+
* that ignores its argument produces the same result as `getDefaultData`, which
|
|
506
|
+
* is why the two are separate methods rather than one optional argument — the
|
|
507
|
+
* caller decides which contract it is asking for, and a block that cannot honour
|
|
508
|
+
* params must not silently look like one that can.
|
|
509
|
+
*
|
|
510
|
+
* References inside `params` are already resolved to the target project's
|
|
511
|
+
* concrete ids by the time they get here; the factory never sees a
|
|
512
|
+
* template-local one.
|
|
513
|
+
*/
|
|
514
|
+
getDataFromParams(params) {
|
|
515
|
+
return makeVersionedData(this.latestVersion, this.initialDataFn({ params }));
|
|
432
516
|
}
|
|
433
517
|
recoverFrom(data, version) {
|
|
434
518
|
let currentData = this.recoverFn(version, data);
|