@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
package/src/block_model.ts
CHANGED
|
@@ -5,10 +5,11 @@ import type {
|
|
|
5
5
|
PlRef,
|
|
6
6
|
BlockCodeKnownFeatureFlags,
|
|
7
7
|
BlockConfigContainer,
|
|
8
|
+
BlockKindReference,
|
|
8
9
|
} from "@milaboratories/pl-model-common";
|
|
9
|
-
import { REQUIRES_PFRAMES_VERSION } from "@milaboratories/pl-model-common";
|
|
10
|
+
import { REQUIRES_PFRAMES_VERSION, formatKindRef } from "@milaboratories/pl-model-common";
|
|
10
11
|
import { getPlatformaInstance, isInUI, createAndRegisterRenderLambda } from "./internal";
|
|
11
|
-
import type { DataModel } from "./block_migrations";
|
|
12
|
+
import type { BlockKind, DataModel } from "./block_migrations";
|
|
12
13
|
import type { PlatformaV3 } from "./platforma";
|
|
13
14
|
import type { BlockDefaultUiServices } from "./services/service_resolve";
|
|
14
15
|
import { BLOCK_SERVICE_FLAGS } from "./services/block_services";
|
|
@@ -30,8 +31,11 @@ import {
|
|
|
30
31
|
getStorageDebugView,
|
|
31
32
|
migrateStorage,
|
|
32
33
|
createInitialStorage,
|
|
34
|
+
createInitialStorageFromParams,
|
|
35
|
+
validateTemplateParamsJson,
|
|
33
36
|
deriveArgsFromStorage,
|
|
34
37
|
derivePrerunArgsFromStorage,
|
|
38
|
+
deriveTemplateParamsFromStorage,
|
|
35
39
|
} from "./block_storage_callbacks";
|
|
36
40
|
import { type PluginName } from "./block_storage";
|
|
37
41
|
import type {
|
|
@@ -108,9 +112,13 @@ interface BlockModelV3Config<
|
|
|
108
112
|
Data,
|
|
109
113
|
Plugins extends Record<string, PluginRecord> = {},
|
|
110
114
|
Transfers extends Record<string, unknown> = {},
|
|
115
|
+
Params = unknown,
|
|
111
116
|
> {
|
|
112
117
|
renderingMode: BlockRenderingMode;
|
|
113
|
-
dataModel: DataModel<Data, Transfers>;
|
|
118
|
+
dataModel: DataModel<Data, Params, Transfers>;
|
|
119
|
+
/** Reference to the block kind this model implements, in `{name}@{version}` form. */
|
|
120
|
+
// @todo: use blockKind, `kind` super comman word
|
|
121
|
+
kind: BlockKindReference | undefined;
|
|
114
122
|
outputs: OutputsCfg;
|
|
115
123
|
sections: ConfigRenderLambda;
|
|
116
124
|
title: ConfigRenderLambda | undefined;
|
|
@@ -118,8 +126,17 @@ interface BlockModelV3Config<
|
|
|
118
126
|
tags: ConfigRenderLambda | undefined;
|
|
119
127
|
enrichmentTargets: ConfigRenderLambda | undefined;
|
|
120
128
|
featureFlags: BlockCodeKnownFeatureFlags;
|
|
121
|
-
|
|
122
|
-
|
|
129
|
+
deriveArgs: ((data: unknown) => unknown) | undefined;
|
|
130
|
+
derivePrerunArgs: ((data: unknown) => unknown) | undefined;
|
|
131
|
+
/** Projects block data back to this kind's params for template export. */
|
|
132
|
+
deriveTemplateParams: ((data: Data) => Params) | undefined;
|
|
133
|
+
/**
|
|
134
|
+
* The kind's runtime check for params supplied by a template. Read off the compiled
|
|
135
|
+
* kind rather than declared per block: the params contract belongs to the kind, and
|
|
136
|
+
* two blocks implementing it must not be able to disagree about what a valid params
|
|
137
|
+
* object is. Always present — a kind cannot omit it, and a block cannot omit a kind.
|
|
138
|
+
*/
|
|
139
|
+
parseInitializationParams: (value: unknown) => unknown;
|
|
123
140
|
plugins: Plugins;
|
|
124
141
|
}
|
|
125
142
|
|
|
@@ -134,9 +151,10 @@ export class BlockModelV3<
|
|
|
134
151
|
Href extends `/${string}` = "/",
|
|
135
152
|
Plugins extends Record<string, PluginRecord> = {},
|
|
136
153
|
Transfers extends Record<string, unknown> = {},
|
|
154
|
+
Params = unknown,
|
|
137
155
|
> {
|
|
138
156
|
private constructor(
|
|
139
|
-
private readonly config: BlockModelV3Config<OutputsCfg, Data, Plugins, Transfers>,
|
|
157
|
+
private readonly config: BlockModelV3Config<OutputsCfg, Data, Plugins, Transfers, Params>,
|
|
140
158
|
) {}
|
|
141
159
|
|
|
142
160
|
public static readonly FEATURE_FLAGS = {
|
|
@@ -153,27 +171,55 @@ export class BlockModelV3<
|
|
|
153
171
|
public static readonly INITIAL_BLOCK_FEATURE_FLAGS = BlockModelV3.FEATURE_FLAGS;
|
|
154
172
|
|
|
155
173
|
/**
|
|
156
|
-
* Creates a new BlockModelV3 builder
|
|
174
|
+
* Creates a new BlockModelV3 builder bound to a data model and a block kind.
|
|
175
|
+
*
|
|
176
|
+
* The `kind` argument is cross-checked against the kind handed to the
|
|
177
|
+
* builder: its `Params` type must match at compile time (via
|
|
178
|
+
* `BlockKind<Params>`), and its reference value must match at runtime. The
|
|
179
|
+
* reference is baked into the config so the published manifest can advertise
|
|
180
|
+
* which kind the block implements.
|
|
157
181
|
*
|
|
158
182
|
* @example
|
|
159
|
-
* const dataModel = new DataModelBuilder()
|
|
183
|
+
* const dataModel = new DataModelBuilder({ kind })
|
|
160
184
|
* .from<BlockData>("v1")
|
|
161
|
-
* .init(() =>
|
|
185
|
+
* .init(({ params }) => params ?? { numbers: [], labels: [] });
|
|
162
186
|
*
|
|
163
|
-
* BlockModelV3.create(dataModel)
|
|
187
|
+
* BlockModelV3.create({ dataModel, kind })
|
|
164
188
|
* .args((data) => ({ numbers: data.numbers }))
|
|
165
189
|
* .sections(() => [{ type: 'link', href: '/', label: 'Main' }])
|
|
166
190
|
* .done();
|
|
167
|
-
*
|
|
168
|
-
* @param dataModel The data model that defines initial data and migrations
|
|
169
191
|
*/
|
|
170
192
|
public static create<
|
|
171
193
|
Data extends Record<string, unknown>,
|
|
194
|
+
Params = never,
|
|
172
195
|
Transfers extends Record<string, unknown> = {},
|
|
173
|
-
>(
|
|
174
|
-
|
|
196
|
+
>(args: {
|
|
197
|
+
dataModel: DataModel<Data, Params, Transfers>;
|
|
198
|
+
kind: BlockKind<Params>;
|
|
199
|
+
}): BlockModelV3<NoOb, {}, Data, "/", {}, Transfers, Params> {
|
|
200
|
+
const { dataModel, kind } = args;
|
|
201
|
+
// Derive the on-wire reference from the compiled kind; the kind object has
|
|
202
|
+
// no reference field of its own.
|
|
203
|
+
const kindRef = formatKindRef(kind);
|
|
204
|
+
|
|
205
|
+
// Runtime guard: the kind handed to the builder must match the kind handed to
|
|
206
|
+
// create(). Nothing ties them together at the type level — they arrive as two
|
|
207
|
+
// separately-passed objects — so a mismatch is only visible here. The builder's own
|
|
208
|
+
// reference is still optional, because a PLUGIN data model is built without a kind
|
|
209
|
+
// and has none to compare.
|
|
210
|
+
if (dataModel.kindRef && dataModel.kindRef !== kindRef) {
|
|
211
|
+
throw new Error(
|
|
212
|
+
`Block kind mismatch: data model built for '${dataModel.kindRef}' but create() got '${kindRef}'`,
|
|
213
|
+
);
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
return new BlockModelV3<NoOb, {}, Data, "/", {}, Transfers, Params>({
|
|
175
217
|
renderingMode: "Heavy",
|
|
176
218
|
dataModel,
|
|
219
|
+
kind: kindRef,
|
|
220
|
+
// Read off the kind, which cannot omit it — not off the data model. The two
|
|
221
|
+
// are cross-checked above, so there is one source, not a precedence order.
|
|
222
|
+
parseInitializationParams: kind.parseInitializationParams,
|
|
177
223
|
outputs: {},
|
|
178
224
|
sections: createAndRegisterRenderLambda({ handle: "sections", lambda: () => [] }, true),
|
|
179
225
|
title: undefined,
|
|
@@ -181,8 +227,9 @@ export class BlockModelV3<
|
|
|
181
227
|
tags: undefined,
|
|
182
228
|
enrichmentTargets: undefined,
|
|
183
229
|
featureFlags: { ...BlockModelV3.FEATURE_FLAGS },
|
|
184
|
-
|
|
185
|
-
|
|
230
|
+
deriveArgs: undefined,
|
|
231
|
+
derivePrerunArgs: undefined,
|
|
232
|
+
deriveTemplateParams: undefined,
|
|
186
233
|
plugins: {},
|
|
187
234
|
});
|
|
188
235
|
}
|
|
@@ -209,7 +256,8 @@ export class BlockModelV3<
|
|
|
209
256
|
Data,
|
|
210
257
|
Href,
|
|
211
258
|
Plugins,
|
|
212
|
-
Transfers
|
|
259
|
+
Transfers,
|
|
260
|
+
Params
|
|
213
261
|
>;
|
|
214
262
|
/**
|
|
215
263
|
* Add output cell to the configuration
|
|
@@ -231,13 +279,14 @@ export class BlockModelV3<
|
|
|
231
279
|
Data,
|
|
232
280
|
Href,
|
|
233
281
|
Plugins,
|
|
234
|
-
Transfers
|
|
282
|
+
Transfers,
|
|
283
|
+
Params
|
|
235
284
|
>;
|
|
236
285
|
public output(
|
|
237
286
|
key: string,
|
|
238
287
|
cfgOrRf: RenderFunction<Args, Data, unknown>,
|
|
239
288
|
flags: ConfigRenderLambdaFlags = {},
|
|
240
|
-
): BlockModelV3<Args, OutputsCfg, Data, Href, Plugins, Transfers> {
|
|
289
|
+
): BlockModelV3<Args, OutputsCfg, Data, Href, Plugins, Transfers, Params> {
|
|
241
290
|
return new BlockModelV3({
|
|
242
291
|
...this.config,
|
|
243
292
|
outputs: {
|
|
@@ -266,7 +315,8 @@ export class BlockModelV3<
|
|
|
266
315
|
Data,
|
|
267
316
|
Href,
|
|
268
317
|
Plugins,
|
|
269
|
-
Transfers
|
|
318
|
+
Transfers,
|
|
319
|
+
Params
|
|
270
320
|
> {
|
|
271
321
|
return this.output(key, rf, { retentive: true });
|
|
272
322
|
}
|
|
@@ -294,10 +344,10 @@ export class BlockModelV3<
|
|
|
294
344
|
*/
|
|
295
345
|
public args<A>(
|
|
296
346
|
lambda: (data: Data) => A,
|
|
297
|
-
): BlockModelV3<A, OutputsCfg, Data, Href, Plugins, Transfers> {
|
|
298
|
-
return new BlockModelV3<A, OutputsCfg, Data, Href, Plugins, Transfers>({
|
|
347
|
+
): BlockModelV3<A, OutputsCfg, Data, Href, Plugins, Transfers, Params> {
|
|
348
|
+
return new BlockModelV3<A, OutputsCfg, Data, Href, Plugins, Transfers, Params>({
|
|
299
349
|
...this.config,
|
|
300
|
-
|
|
350
|
+
deriveArgs: lambda as (data: unknown) => unknown,
|
|
301
351
|
});
|
|
302
352
|
}
|
|
303
353
|
|
|
@@ -323,10 +373,47 @@ export class BlockModelV3<
|
|
|
323
373
|
*/
|
|
324
374
|
public prerunArgs(
|
|
325
375
|
fn: (data: Data) => unknown,
|
|
326
|
-
): BlockModelV3<Args, OutputsCfg, Data, Href, Plugins, Transfers> {
|
|
327
|
-
return new BlockModelV3<Args, OutputsCfg, Data, Href, Plugins, Transfers>({
|
|
376
|
+
): BlockModelV3<Args, OutputsCfg, Data, Href, Plugins, Transfers, Params> {
|
|
377
|
+
return new BlockModelV3<Args, OutputsCfg, Data, Href, Plugins, Transfers, Params>({
|
|
328
378
|
...this.config,
|
|
329
|
-
|
|
379
|
+
derivePrerunArgs: fn as (data: unknown) => unknown,
|
|
380
|
+
});
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
/**
|
|
384
|
+
* Sets the function that projects block data back to this kind's params, for
|
|
385
|
+
* exporting the project as a template.
|
|
386
|
+
*
|
|
387
|
+
* The inverse of the data model's `init`: `init` builds data from `params`, this
|
|
388
|
+
* recovers the `params` that would rebuild the current data. Return only params
|
|
389
|
+
* — runtime and derived state is dropped, and the exporter supplies the rest of
|
|
390
|
+
* the entry (`id`, `kind`), which this lambda cannot set.
|
|
391
|
+
*
|
|
392
|
+
* References are returned as ordinary `PlRef`s; the SDK rewrites them into
|
|
393
|
+
* template-local form on the way out, so a block never deals with the file
|
|
394
|
+
* representation.
|
|
395
|
+
*
|
|
396
|
+
* Required: `done()` throws without it. A block whose state cannot be reduced to
|
|
397
|
+
* params returns `{}` and says so explicitly, rather than exporting an entry with
|
|
398
|
+
* no params that silently applies as a default-initialized block.
|
|
399
|
+
*
|
|
400
|
+
* The return type is the kind's `Params`, so a block whose projection drifts
|
|
401
|
+
* from its own init contract fails to compile. Available only on a
|
|
402
|
+
* kind-carrying model — `create(dataModel)` without a kind leaves `Params` as
|
|
403
|
+
* `unknown` and this method cannot be type-checked against anything.
|
|
404
|
+
*
|
|
405
|
+
* @example
|
|
406
|
+
* BlockModelV3.create({ dataModel, kind })
|
|
407
|
+
* .args((data) => ({ numbers: data.numbers }))
|
|
408
|
+
* .templateParams((data) => ({ sources: data.sources }))
|
|
409
|
+
* .done();
|
|
410
|
+
*/
|
|
411
|
+
public templateParams(
|
|
412
|
+
fn: (data: Data) => Params,
|
|
413
|
+
): BlockModelV3<Args, OutputsCfg, Data, Href, Plugins, Transfers, Params> {
|
|
414
|
+
return new BlockModelV3<Args, OutputsCfg, Data, Href, Plugins, Transfers, Params>({
|
|
415
|
+
...this.config,
|
|
416
|
+
deriveTemplateParams: fn,
|
|
330
417
|
});
|
|
331
418
|
}
|
|
332
419
|
|
|
@@ -334,27 +421,35 @@ export class BlockModelV3<
|
|
|
334
421
|
public sections<
|
|
335
422
|
const Ret extends SectionsExpectedType,
|
|
336
423
|
const RF extends RenderFunction<Args, Data, Ret>,
|
|
337
|
-
>(
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
424
|
+
>(
|
|
425
|
+
rf: RF,
|
|
426
|
+
): BlockModelV3<Args, OutputsCfg, Data, DeriveHref<ReturnType<RF>>, Plugins, Transfers, Params> {
|
|
427
|
+
return new BlockModelV3<
|
|
428
|
+
Args,
|
|
429
|
+
OutputsCfg,
|
|
430
|
+
Data,
|
|
431
|
+
DeriveHref<ReturnType<RF>>,
|
|
432
|
+
Plugins,
|
|
433
|
+
Transfers,
|
|
434
|
+
Params
|
|
435
|
+
>({
|
|
436
|
+
...this.config,
|
|
437
|
+
// Replace the default sections callback with the user-provided one
|
|
438
|
+
sections: createAndRegisterRenderLambda(
|
|
439
|
+
{
|
|
440
|
+
handle: "sections",
|
|
441
|
+
lambda: () => rf(new BlockRenderCtx<Args, Data>()),
|
|
442
|
+
},
|
|
443
|
+
true,
|
|
444
|
+
),
|
|
445
|
+
});
|
|
351
446
|
}
|
|
352
447
|
|
|
353
448
|
/** Sets a rendering function to derive block title, shown for the block in the left blocks-overview panel. */
|
|
354
449
|
public title(
|
|
355
450
|
rf: RenderFunction<Args, Data, string>,
|
|
356
|
-
): BlockModelV3<Args, OutputsCfg, Data, Href, Plugins, Transfers> {
|
|
357
|
-
return new BlockModelV3<Args, OutputsCfg, Data, Href, Plugins, Transfers>({
|
|
451
|
+
): BlockModelV3<Args, OutputsCfg, Data, Href, Plugins, Transfers, Params> {
|
|
452
|
+
return new BlockModelV3<Args, OutputsCfg, Data, Href, Plugins, Transfers, Params>({
|
|
358
453
|
...this.config,
|
|
359
454
|
title: createAndRegisterRenderLambda({
|
|
360
455
|
handle: "title",
|
|
@@ -365,8 +460,8 @@ export class BlockModelV3<
|
|
|
365
460
|
|
|
366
461
|
public subtitle(
|
|
367
462
|
rf: RenderFunction<Args, Data, string>,
|
|
368
|
-
): BlockModelV3<Args, OutputsCfg, Data, Href, Plugins, Transfers> {
|
|
369
|
-
return new BlockModelV3<Args, OutputsCfg, Data, Href, Plugins, Transfers>({
|
|
463
|
+
): BlockModelV3<Args, OutputsCfg, Data, Href, Plugins, Transfers, Params> {
|
|
464
|
+
return new BlockModelV3<Args, OutputsCfg, Data, Href, Plugins, Transfers, Params>({
|
|
370
465
|
...this.config,
|
|
371
466
|
subtitle: createAndRegisterRenderLambda({
|
|
372
467
|
handle: "subtitle",
|
|
@@ -377,8 +472,8 @@ export class BlockModelV3<
|
|
|
377
472
|
|
|
378
473
|
public tags(
|
|
379
474
|
rf: RenderFunction<Args, Data, string[]>,
|
|
380
|
-
): BlockModelV3<Args, OutputsCfg, Data, Href, Plugins, Transfers> {
|
|
381
|
-
return new BlockModelV3<Args, OutputsCfg, Data, Href, Plugins, Transfers>({
|
|
475
|
+
): BlockModelV3<Args, OutputsCfg, Data, Href, Plugins, Transfers, Params> {
|
|
476
|
+
return new BlockModelV3<Args, OutputsCfg, Data, Href, Plugins, Transfers, Params>({
|
|
382
477
|
...this.config,
|
|
383
478
|
tags: createAndRegisterRenderLambda({
|
|
384
479
|
handle: "tags",
|
|
@@ -390,8 +485,8 @@ export class BlockModelV3<
|
|
|
390
485
|
/** Sets or overrides feature flags for the block. */
|
|
391
486
|
public withFeatureFlags(
|
|
392
487
|
flags: Partial<BlockCodeKnownFeatureFlags>,
|
|
393
|
-
): BlockModelV3<Args, OutputsCfg, Data, Href, Plugins, Transfers> {
|
|
394
|
-
return new BlockModelV3<Args, OutputsCfg, Data, Href, Plugins, Transfers>({
|
|
488
|
+
): BlockModelV3<Args, OutputsCfg, Data, Href, Plugins, Transfers, Params> {
|
|
489
|
+
return new BlockModelV3<Args, OutputsCfg, Data, Href, Plugins, Transfers, Params>({
|
|
395
490
|
...this.config,
|
|
396
491
|
featureFlags: { ...this.config.featureFlags, ...flags },
|
|
397
492
|
});
|
|
@@ -403,8 +498,8 @@ export class BlockModelV3<
|
|
|
403
498
|
*/
|
|
404
499
|
public enriches(
|
|
405
500
|
lambda: (args: Args) => PlRef[],
|
|
406
|
-
): BlockModelV3<Args, OutputsCfg, Data, Href, Plugins, Transfers> {
|
|
407
|
-
return new BlockModelV3<Args, OutputsCfg, Data, Href, Plugins, Transfers>({
|
|
501
|
+
): BlockModelV3<Args, OutputsCfg, Data, Href, Plugins, Transfers, Params> {
|
|
502
|
+
return new BlockModelV3<Args, OutputsCfg, Data, Href, Plugins, Transfers, Params>({
|
|
408
503
|
...this.config,
|
|
409
504
|
enrichmentTargets: createAndRegisterRenderLambda({
|
|
410
505
|
handle: "enrichmentTargets",
|
|
@@ -475,7 +570,8 @@ export class BlockModelV3<
|
|
|
475
570
|
PluginUiServices
|
|
476
571
|
>;
|
|
477
572
|
},
|
|
478
|
-
Omit<Transfers, PluginId
|
|
573
|
+
Omit<Transfers, PluginId>,
|
|
574
|
+
Params
|
|
479
575
|
>;
|
|
480
576
|
public plugin(
|
|
481
577
|
instance: PluginInstanceClass,
|
|
@@ -486,7 +582,8 @@ export class BlockModelV3<
|
|
|
486
582
|
Data,
|
|
487
583
|
Href,
|
|
488
584
|
Record<string, PluginRecord>,
|
|
489
|
-
Record<string, unknown
|
|
585
|
+
Record<string, unknown>,
|
|
586
|
+
Params
|
|
490
587
|
> {
|
|
491
588
|
const pluginId = instance.id;
|
|
492
589
|
const plugin = instance[CREATE_PLUGIN_MODEL]();
|
|
@@ -532,7 +629,13 @@ export class BlockModelV3<
|
|
|
532
629
|
BlockDefaultUiServices
|
|
533
630
|
>
|
|
534
631
|
> {
|
|
535
|
-
if (this.config.
|
|
632
|
+
if (this.config.deriveArgs === undefined) throw new Error("Args rendering function not set.");
|
|
633
|
+
if (this.config.deriveTemplateParams === undefined)
|
|
634
|
+
throw new Error(
|
|
635
|
+
"templateParams() not set. Every block must project its state back to its kind's params, " +
|
|
636
|
+
"so a project can be exported as a template and re-applied; a block whose state carries " +
|
|
637
|
+
"nothing worth restoring returns {}.",
|
|
638
|
+
);
|
|
536
639
|
|
|
537
640
|
const apiVersion = 3;
|
|
538
641
|
|
|
@@ -544,7 +647,13 @@ export class BlockModelV3<
|
|
|
544
647
|
pluginRegistry[handle] = plugins[handle].model.name;
|
|
545
648
|
}
|
|
546
649
|
|
|
547
|
-
const {
|
|
650
|
+
const {
|
|
651
|
+
dataModel,
|
|
652
|
+
deriveArgs,
|
|
653
|
+
derivePrerunArgs,
|
|
654
|
+
deriveTemplateParams,
|
|
655
|
+
parseInitializationParams,
|
|
656
|
+
} = this.config;
|
|
548
657
|
|
|
549
658
|
function getPlugin(handle: PluginHandle): PluginRecord {
|
|
550
659
|
const plugin = plugins[handle];
|
|
@@ -573,9 +682,23 @@ export class BlockModelV3<
|
|
|
573
682
|
createPluginData: (handle) => getPlugin(handle).model.getDefaultData(),
|
|
574
683
|
}),
|
|
575
684
|
[BlockStorageFacadeCallbacks.ArgsDerive]: (storageJson) =>
|
|
576
|
-
deriveArgsFromStorage(storageJson,
|
|
685
|
+
deriveArgsFromStorage(storageJson, deriveArgs),
|
|
577
686
|
[BlockStorageFacadeCallbacks.PrerunArgsDerive]: (storageJson) =>
|
|
578
|
-
derivePrerunArgsFromStorage(storageJson,
|
|
687
|
+
derivePrerunArgsFromStorage(storageJson, deriveArgs, derivePrerunArgs),
|
|
688
|
+
[BlockStorageFacadeCallbacks.InitializationParamsDerive]: (storageJson) =>
|
|
689
|
+
deriveTemplateParamsFromStorage(
|
|
690
|
+
storageJson,
|
|
691
|
+
deriveTemplateParams as (data: unknown) => unknown,
|
|
692
|
+
),
|
|
693
|
+
[BlockStorageFacadeCallbacks.StorageInitialFromParams]: (paramsJson, blockIdsJson) =>
|
|
694
|
+
createInitialStorageFromParams(paramsJson, blockIdsJson, {
|
|
695
|
+
getBlockDataFromParams: (params) => dataModel.getDataFromParams(params),
|
|
696
|
+
getPluginRegistry: () => pluginRegistry,
|
|
697
|
+
createPluginData: (handle) => getPlugin(handle).model.getDefaultData(),
|
|
698
|
+
parseInitializationParams,
|
|
699
|
+
}),
|
|
700
|
+
[BlockStorageFacadeCallbacks.InitializationParamsValidate]: (paramsJson) =>
|
|
701
|
+
validateTemplateParamsJson(paramsJson, parseInitializationParams),
|
|
579
702
|
});
|
|
580
703
|
|
|
581
704
|
// Register plugin input and output lambdas
|
|
@@ -620,6 +743,11 @@ export class BlockModelV3<
|
|
|
620
743
|
blockLifecycleCallbacks: { ...BlockStorageFacadeHandles },
|
|
621
744
|
},
|
|
622
745
|
|
|
746
|
+
// Block-kind identity, baked at the container level beside `code`
|
|
747
|
+
// (orthogonal to which render envelope applies). Rides into model.json
|
|
748
|
+
// via the JSON.stringify(config) in build-model.ts — no write-path change.
|
|
749
|
+
kind: this.config.kind,
|
|
750
|
+
|
|
623
751
|
// fields below are added to allow previous desktop versions read generated configs
|
|
624
752
|
sdkVersion: PlatformaSDKVersion,
|
|
625
753
|
renderingMode: this.config.renderingMode,
|
|
@@ -698,9 +826,12 @@ type _ConfigTest = Expect<
|
|
|
698
826
|
BlockModelV3Config<_TestOutputs, _TestData>,
|
|
699
827
|
{
|
|
700
828
|
renderingMode: BlockRenderingMode;
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
829
|
+
deriveArgs: ((data: unknown) => unknown) | undefined;
|
|
830
|
+
derivePrerunArgs: ((data: unknown) => unknown) | undefined;
|
|
831
|
+
deriveTemplateParams: ((data: _TestData) => unknown) | undefined;
|
|
832
|
+
parseInitializationParams: (value: unknown) => unknown;
|
|
833
|
+
dataModel: DataModel<_TestData, unknown, {}>;
|
|
834
|
+
kind: BlockKindReference | undefined;
|
|
704
835
|
outputs: _TestOutputs;
|
|
705
836
|
sections: ConfigRenderLambda;
|
|
706
837
|
title: ConfigRenderLambda | undefined;
|