@platforma-sdk/model 1.96.4 → 1.97.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/block_model.cjs +93 -6
- package/dist/block_model.cjs.map +1 -1
- package/dist/block_model.d.ts +64 -2
- package/dist/block_model.d.ts.map +1 -1
- package/dist/block_model.js +95 -8
- package/dist/block_model.js.map +1 -1
- package/dist/block_storage_callbacks.cjs +46 -0
- package/dist/block_storage_callbacks.cjs.map +1 -1
- package/dist/block_storage_callbacks.js +46 -1
- package/dist/block_storage_callbacks.js.map +1 -1
- package/dist/block_storage_facade.cjs +25 -5
- package/dist/block_storage_facade.cjs.map +1 -1
- package/dist/block_storage_facade.d.ts +39 -2
- package/dist/block_storage_facade.d.ts.map +1 -1
- package/dist/block_storage_facade.js +25 -6
- package/dist/block_storage_facade.js.map +1 -1
- package/dist/filters/converters/filterToQuery.cjs.map +1 -1
- package/dist/filters/converters/filterToQuery.d.ts +6 -2
- package/dist/filters/converters/filterToQuery.d.ts.map +1 -1
- package/dist/filters/converters/filterToQuery.js.map +1 -1
- package/dist/index.cjs +1 -0
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -2
- package/dist/package.cjs +1 -1
- package/dist/package.js +1 -1
- package/package.json +2 -2
- package/src/apply_params.test.ts +330 -0
- package/src/block_model.ts +120 -4
- package/src/block_storage_callbacks.ts +74 -0
- package/src/block_storage_facade.ts +51 -4
- package/src/filters/converters/filterToQuery.ts +6 -3
package/dist/block_model.cjs
CHANGED
|
@@ -92,6 +92,7 @@ var BlockModelV3 = class BlockModelV3 {
|
|
|
92
92
|
derivePrerunArgs: void 0,
|
|
93
93
|
prerunArgsIssues: void 0,
|
|
94
94
|
deriveTemplateParams: void 0,
|
|
95
|
+
applyParams: void 0,
|
|
95
96
|
plugins: {}
|
|
96
97
|
});
|
|
97
98
|
}
|
|
@@ -231,8 +232,9 @@ var BlockModelV3 = class BlockModelV3 {
|
|
|
231
232
|
* Sets the function that projects block data back to this kind's params, for
|
|
232
233
|
* exporting the project as a template.
|
|
233
234
|
*
|
|
234
|
-
* The inverse of
|
|
235
|
-
* recovers the `params` that would rebuild the
|
|
235
|
+
* The inverse of how params become data — {@link applyParams} when the block declares it,
|
|
236
|
+
* the data model's `init` otherwise: this recovers the `params` that would rebuild the
|
|
237
|
+
* current data. Return only params
|
|
236
238
|
* — runtime and derived state is dropped, and the exporter supplies the rest of
|
|
237
239
|
* the entry (`id`, `kind`), which this lambda cannot set.
|
|
238
240
|
*
|
|
@@ -261,6 +263,72 @@ var BlockModelV3 = class BlockModelV3 {
|
|
|
261
263
|
deriveTemplateParams: fn
|
|
262
264
|
});
|
|
263
265
|
}
|
|
266
|
+
/**
|
|
267
|
+
* Sets the function that puts this kind's params onto live block data: the data the block
|
|
268
|
+
* would have, were it configured with `params`. Together with {@link templateParams} it is a
|
|
269
|
+
* pair — `templateParams` projects data onto params, `applyParams` writes params back onto data.
|
|
270
|
+
*
|
|
271
|
+
* Everything the params describe is written from `params`; everything they do not describe
|
|
272
|
+
* (files, per-item values, view state, edits made in the UI) is kept from `data`.
|
|
273
|
+
*
|
|
274
|
+
* Declaring it makes it the one way params become data. Data built from params (template
|
|
275
|
+
* apply, creation with params) is `applyParams(defaults, params)`, `defaults` being the data
|
|
276
|
+
* model's default data (its `init` called without params); a write of params onto an existing
|
|
277
|
+
* block (the MCP `set_block_params`) is `applyParams(current, params)`. Both run after the
|
|
278
|
+
* kind's parser has accepted the params. Without it, data from params is the data model's
|
|
279
|
+
* `init` called with them, as before.
|
|
280
|
+
*
|
|
281
|
+
* Params are whole, not a patch: a key absent from `params` is the kind's "unset", and
|
|
282
|
+
* `applyParams` writes that into the data rather than leaving the old value.
|
|
283
|
+
*
|
|
284
|
+
* Laws the block keeps:
|
|
285
|
+
* - `templateParams(applyParams(d, p))` equals `templateParams(applyParams(defaults, p))` for
|
|
286
|
+
* any data `d` (the projection may leave out what does not travel, such as files);
|
|
287
|
+
* - `applyParams(d, templateParams(d))` equals `d`.
|
|
288
|
+
* The middle layer checks the first on every write of params and refuses one that breaks it.
|
|
289
|
+
*
|
|
290
|
+
* A shallow spread such as `({ ...data, ...params })` is usually wrong. It overwrites whole
|
|
291
|
+
* values the params describe only in part — a list of items replaces the items in data along
|
|
292
|
+
* with their files and view state — and it leaves in place what a key absent from `params`
|
|
293
|
+
* should unset. Write each field the params describe, and match list items by their id.
|
|
294
|
+
*
|
|
295
|
+
* The parameter types are the kind's `Params` and the data model's data, so the function is
|
|
296
|
+
* checked against the same contract as {@link templateParams}.
|
|
297
|
+
*
|
|
298
|
+
* @example
|
|
299
|
+
* // Params: { samples: { id: string; label: string; threshold?: number }[] }
|
|
300
|
+
* // Data: { samples: { id; label; threshold; file?: ImportFileHandle; expanded: boolean }[];
|
|
301
|
+
* // tab: string }
|
|
302
|
+
* BlockModelV3.create({ dataModel, kind })
|
|
303
|
+
* .args((data) => ({ samples: data.samples }))
|
|
304
|
+
* .templateParams((data) => ({
|
|
305
|
+
* samples: data.samples.map(({ id, label, threshold }) => ({ id, label, threshold })),
|
|
306
|
+
* }))
|
|
307
|
+
* .applyParams((data, params) => {
|
|
308
|
+
* const current = new Map(data.samples.map((s) => [s.id, s]));
|
|
309
|
+
* return {
|
|
310
|
+
* ...data, // `tab` and anything else the params do not describe
|
|
311
|
+
* // The list is the params': a sample absent from them is removed.
|
|
312
|
+
* samples: params.samples.map((p) => {
|
|
313
|
+
* const kept = current.get(p.id); // per-sample state the params do not describe
|
|
314
|
+
* return {
|
|
315
|
+
* id: p.id,
|
|
316
|
+
* label: p.label,
|
|
317
|
+
* threshold: p.threshold ?? DEFAULT_THRESHOLD, // absent means unset, not unchanged
|
|
318
|
+
* file: kept?.file,
|
|
319
|
+
* expanded: kept?.expanded ?? false,
|
|
320
|
+
* };
|
|
321
|
+
* }),
|
|
322
|
+
* };
|
|
323
|
+
* })
|
|
324
|
+
* .done();
|
|
325
|
+
*/
|
|
326
|
+
applyParams(fn) {
|
|
327
|
+
return new BlockModelV3({
|
|
328
|
+
...this.config,
|
|
329
|
+
applyParams: fn
|
|
330
|
+
});
|
|
331
|
+
}
|
|
264
332
|
/** Sets the lambda to generate list of sections in the left block overviews panel. */
|
|
265
333
|
sections(rf) {
|
|
266
334
|
return new BlockModelV3({
|
|
@@ -362,7 +430,8 @@ var BlockModelV3 = class BlockModelV3 {
|
|
|
362
430
|
const pluginRegistry = {};
|
|
363
431
|
const pluginHandles = Object.keys(plugins);
|
|
364
432
|
for (const handle of pluginHandles) pluginRegistry[handle] = plugins[handle].model.name;
|
|
365
|
-
const { dataModel, deriveArgs, argsIssues, derivePrerunArgs, prerunArgsIssues, deriveTemplateParams, parseInitializationParams } = this.config;
|
|
433
|
+
const { dataModel, deriveArgs, argsIssues, derivePrerunArgs, prerunArgsIssues, deriveTemplateParams, applyParams, parseInitializationParams } = this.config;
|
|
434
|
+
const applyParamsErased = applyParams;
|
|
366
435
|
function getPlugin(handle) {
|
|
367
436
|
const plugin = plugins[handle];
|
|
368
437
|
if (!plugin) throw new Error(`Plugin model not found for '${handle}'`);
|
|
@@ -399,12 +468,27 @@ var BlockModelV3 = class BlockModelV3 {
|
|
|
399
468
|
}),
|
|
400
469
|
[require_block_storage_facade.BlockStorageFacadeCallbacks.InitializationParamsDerive]: (storageJson) => require_block_storage_callbacks.deriveTemplateParamsFromStorage(storageJson, deriveTemplateParams),
|
|
401
470
|
[require_block_storage_facade.BlockStorageFacadeCallbacks.StorageInitialFromParams]: (paramsJson, blockIdsJson) => require_block_storage_callbacks.createInitialStorageFromParams(paramsJson, blockIdsJson, {
|
|
402
|
-
getBlockDataFromParams: (params) =>
|
|
471
|
+
getBlockDataFromParams: (params) => {
|
|
472
|
+
if (applyParamsErased === void 0 || params === void 0) return dataModel.getDataFromParams(params);
|
|
473
|
+
const defaults = dataModel.getDefaultData();
|
|
474
|
+
return {
|
|
475
|
+
version: defaults.version,
|
|
476
|
+
data: applyParamsErased(defaults.data, params)
|
|
477
|
+
};
|
|
478
|
+
},
|
|
403
479
|
getPluginRegistry: () => pluginRegistry,
|
|
404
480
|
createPluginData: (handle) => getPlugin(handle).model.getDefaultData(),
|
|
405
481
|
parseInitializationParams
|
|
406
482
|
}),
|
|
407
|
-
[require_block_storage_facade.BlockStorageFacadeCallbacks.InitializationParamsValidate]: (paramsJson) => require_block_storage_callbacks.validateTemplateParamsJson(paramsJson, parseInitializationParams)
|
|
483
|
+
[require_block_storage_facade.BlockStorageFacadeCallbacks.InitializationParamsValidate]: (paramsJson) => require_block_storage_callbacks.validateTemplateParamsJson(paramsJson, parseInitializationParams),
|
|
484
|
+
[require_block_storage_facade.BlockStorageFacadeCallbacks.StorageApplyParams]: applyParamsErased === void 0 ? void 0 : (storageJson, paramsJson) => require_block_storage_callbacks.applyParamsToStorage(storageJson, paramsJson, {
|
|
485
|
+
dataVersion: dataModel.version,
|
|
486
|
+
applyParams: (data, params) => ({
|
|
487
|
+
version: dataModel.version,
|
|
488
|
+
data: applyParamsErased(data, params)
|
|
489
|
+
}),
|
|
490
|
+
parseInitializationParams
|
|
491
|
+
})
|
|
408
492
|
});
|
|
409
493
|
const pluginOutputs = {};
|
|
410
494
|
for (const handle of pluginHandles) {
|
|
@@ -439,7 +523,10 @@ var BlockModelV3 = class BlockModelV3 {
|
|
|
439
523
|
outputs: allOutputs,
|
|
440
524
|
enrichmentTargets: this.config.enrichmentTargets,
|
|
441
525
|
featureFlags: this.config.featureFlags,
|
|
442
|
-
blockLifecycleCallbacks: {
|
|
526
|
+
blockLifecycleCallbacks: {
|
|
527
|
+
...require_block_storage_facade.BlockStorageFacadeHandles,
|
|
528
|
+
...applyParams !== void 0 ? { [require_block_storage_facade.BlockStorageFacadeCallbacks.StorageApplyParams]: require_block_storage_facade.BlockStorageFacadeOptionalHandles[require_block_storage_facade.BlockStorageFacadeCallbacks.StorageApplyParams] } : {}
|
|
529
|
+
}
|
|
443
530
|
},
|
|
444
531
|
kind: this.config.kind,
|
|
445
532
|
sdkVersion: require_version.PlatformaSDKVersion,
|
package/dist/block_model.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"block_model.cjs","names":["REQUIRES_PFRAMES_VERSION","BLOCK_SERVICE_FLAGS","formatKindRef","createAndRegisterRenderLambda","BlockRenderCtx","CREATE_PLUGIN_MODEL","BlockStorageFacadeCallbacks","applyStorageUpdate","getStorageDebugView","migrateStorage","createInitialStorage","deriveArgsFromStorage","derivePrerunArgsFromStorage","deriveTemplateParamsFromStorage","createInitialStorageFromParams","validateTemplateParamsJson","pluginOutputKey","PluginRenderCtx","isInUI","PlatformaSDKVersion","BlockStorageFacadeHandles","downgradeCfgOrLambda","getPlatformaInstance","isConfigLambda"],"sources":["../src/block_model.ts"],"sourcesContent":["import type {\n BlockRenderingMode,\n BlockSection,\n OutputWithStatus,\n PlRef,\n BlockCodeKnownFeatureFlags,\n BlockConfigContainer,\n BlockKindReference,\n ArgsIssue,\n} from \"@milaboratories/pl-model-common\";\nimport { REQUIRES_PFRAMES_VERSION, formatKindRef } from \"@milaboratories/pl-model-common\";\nimport { getPlatformaInstance, isInUI, createAndRegisterRenderLambda } from \"./internal\";\nimport type { BlockKind, DataModel } from \"./block_migrations\";\nimport type { PlatformaV3 } from \"./platforma\";\nimport type { BlockDefaultUiServices } from \"./services/service_resolve\";\nimport { BLOCK_SERVICE_FLAGS } from \"./services/block_services\";\nimport type { InferRenderFunctionReturn, RenderFunction } from \"./render\";\nimport { BlockRenderCtx, PluginRenderCtx } from \"./render\";\nimport type {\n PluginData,\n PluginModel,\n PluginOutputs,\n PluginParams,\n PluginPublicOutputs,\n} from \"./plugin_model\";\nimport { PluginInstance as PluginInstanceClass, CREATE_PLUGIN_MODEL } from \"./plugin_model\";\nimport { type PluginHandle, pluginOutputKey } from \"./plugin_handle\";\nimport type { RenderCtxBase } from \"./render\";\nimport { PlatformaSDKVersion } from \"./version\";\nimport {\n applyStorageUpdate,\n getStorageDebugView,\n migrateStorage,\n createInitialStorage,\n createInitialStorageFromParams,\n validateTemplateParamsJson,\n deriveArgsFromStorage,\n derivePrerunArgsFromStorage,\n deriveTemplateParamsFromStorage,\n} from \"./block_storage_callbacks\";\nimport { type PluginName } from \"./block_storage\";\nimport type {\n ConfigRenderLambda,\n DeriveHref,\n ConfigRenderLambdaFlags,\n InferOutputsFromLambdas,\n} from \"./bconfig\";\nimport { downgradeCfgOrLambda, isConfigLambda } from \"./bconfig\";\nimport type { PlatformaExtended } from \"./platforma\";\nimport {\n BLOCK_STORAGE_FACADE_VERSION,\n BlockStorageFacadeCallbacks,\n BlockStorageFacadeHandles,\n registerFacadeCallbacks,\n} from \"./block_storage_facade\";\n\ntype SectionsExpectedType = readonly BlockSection[];\n\ntype NoOb = Record<string, never>;\n\n/**\n * Per-property lambdas for deriving plugin params from block render context.\n * Each property is a function that receives the block's RenderCtxBase and returns the param value.\n */\nexport type ParamsInput<Params, BArgs = unknown, BData = unknown> = {\n [K in keyof Params]: (ctx: RenderCtxBase<BArgs, BData>) => Params[K];\n};\n\n/**\n * Type-erased version of ParamsInput for internal storage.\n */\ntype ParamsInputErased = Record<string, (ctx: RenderCtxBase) => unknown>;\n\n/**\n * Merges two feature flag objects with type-aware logic:\n * - `supports*` (boolean): OR — `true` if either side is `true`\n * - `requires*` (numeric): MAX — take the higher version requirement\n */\nfunction mergeFeatureFlags(\n base: BlockCodeKnownFeatureFlags,\n override: BlockCodeKnownFeatureFlags,\n): BlockCodeKnownFeatureFlags {\n const result: Record<string, boolean | number | undefined> = { ...base };\n for (const [key, value] of Object.entries(override)) {\n if (value === undefined) continue;\n const existing = result[key];\n if (typeof value === \"boolean\") {\n result[key] = (typeof existing === \"boolean\" && existing) || value;\n } else if (typeof value === \"number\") {\n result[key] = Math.max(typeof existing === \"number\" ? existing : 0, value);\n }\n }\n return result as BlockCodeKnownFeatureFlags;\n}\n\n/**\n * Plugin record: model + param derivation lambdas.\n */\nexport type PluginRecord<\n Data extends PluginData = PluginData,\n Params extends PluginParams = undefined,\n Outputs extends PluginOutputs = PluginOutputs,\n PublicOutputs extends PluginPublicOutputs = PluginPublicOutputs,\n ModelServices = unknown,\n UiServices = unknown,\n> = {\n readonly model: PluginModel<Data, Params, Outputs, PublicOutputs, ModelServices, UiServices>;\n readonly inputs: ParamsInputErased;\n};\n\ninterface BlockModelV3Config<\n OutputsCfg extends Record<string, ConfigRenderLambda>,\n Data,\n Plugins extends Record<string, PluginRecord> = {},\n Transfers extends Record<string, unknown> = {},\n Params = unknown,\n> {\n renderingMode: BlockRenderingMode;\n dataModel: DataModel<Data, Params, Transfers>;\n /** Reference to the block kind this model implements, in `{name}@{version}` form. */\n // @todo: use blockKind, `kind` super comman word\n kind: BlockKindReference | undefined;\n outputs: OutputsCfg;\n sections: ConfigRenderLambda;\n title: ConfigRenderLambda | undefined;\n subtitle: ConfigRenderLambda | undefined;\n tags: ConfigRenderLambda | undefined;\n enrichmentTargets: ConfigRenderLambda | undefined;\n featureFlags: BlockCodeKnownFeatureFlags;\n deriveArgs: ((data: unknown) => unknown) | undefined;\n /** Finds what keeps the derived args from running; set only together with `deriveArgs`. */\n argsIssues: ((input: { args: unknown; data: unknown }) => ArgsIssue[]) | undefined;\n derivePrerunArgs: ((data: unknown) => unknown) | undefined;\n /** Finds what keeps the prerun args from staging; set only together with `derivePrerunArgs`. */\n prerunArgsIssues: ((input: { prerunArgs: unknown; data: unknown }) => ArgsIssue[]) | undefined;\n /** Projects block data back to this kind's params for template export. */\n deriveTemplateParams: ((data: Data) => Params) | undefined;\n /**\n * The kind's runtime check for params supplied by a template. Read off the compiled\n * kind rather than declared per block: the params contract belongs to the kind, and\n * two blocks implementing it must not be able to disagree about what a valid params\n * object is. Always present — a kind cannot omit it, and a block cannot omit a kind.\n */\n parseInitializationParams: (value: unknown) => unknown;\n plugins: Plugins;\n}\n\n/** Main entry point that each block should use in it's \"config\" module. Don't forget\n * to call {@link done()} at the end of configuration. Value returned by this builder must be\n * exported as constant with name \"platforma\" from the \"config\" module.\n * API version is 3 (for UI) and 2 (for model) */\nexport class BlockModelV3<\n Args,\n OutputsCfg extends Record<string, ConfigRenderLambda>,\n Data extends Record<string, unknown> = Record<string, unknown>,\n Href extends `/${string}` = \"/\",\n Plugins extends Record<string, PluginRecord> = {},\n Transfers extends Record<string, unknown> = {},\n Params = unknown,\n PrerunArgs = unknown,\n> {\n private constructor(\n private readonly config: BlockModelV3Config<OutputsCfg, Data, Plugins, Transfers, Params>,\n ) {}\n\n public static readonly FEATURE_FLAGS = {\n supportsLazyState: true,\n supportsPframeQueryRanking: true,\n supportsColumnLinks: true,\n requiresUIAPIVersion: 3,\n requiresModelAPIVersion: BLOCK_STORAGE_FACADE_VERSION,\n requiresCreatePTable: 2,\n requiresPFramesVersion: REQUIRES_PFRAMES_VERSION,\n requiresArgsIssues: true,\n ...BLOCK_SERVICE_FLAGS,\n } satisfies BlockCodeKnownFeatureFlags;\n\n /** @deprecated Use FEATURE_FLAGS */\n public static readonly INITIAL_BLOCK_FEATURE_FLAGS = BlockModelV3.FEATURE_FLAGS;\n\n /**\n * Creates a new BlockModelV3 builder bound to a data model and a block kind.\n *\n * The `kind` argument is cross-checked against the kind handed to the\n * builder: its `Params` type must match at compile time (via\n * `BlockKind<Params>`), and its reference value must match at runtime. The\n * reference is baked into the config so the published manifest can advertise\n * which kind the block implements.\n *\n * @example\n * const dataModel = new DataModelBuilder({ kind })\n * .from<BlockData>(\"v1\")\n * .init(({ params }) => params ?? { numbers: [], labels: [] });\n *\n * BlockModelV3.create({ dataModel, kind })\n * .args((data) => ({ numbers: data.numbers }))\n * .sections(() => [{ type: 'link', href: '/', label: 'Main' }])\n * .done();\n */\n public static create<\n Data extends Record<string, unknown>,\n Params = never,\n Transfers extends Record<string, unknown> = {},\n >(args: {\n dataModel: DataModel<Data, Params, Transfers>;\n kind: BlockKind<Params>;\n }): BlockModelV3<NoOb, {}, Data, \"/\", {}, Transfers, Params> {\n const { dataModel, kind } = args;\n // Derive the on-wire reference from the compiled kind; the kind object has\n // no reference field of its own.\n const kindRef = formatKindRef(kind);\n\n // Runtime guard: the kind handed to the builder must match the kind handed to\n // create(). Nothing ties them together at the type level — they arrive as two\n // separately-passed objects — so a mismatch is only visible here. The builder's own\n // reference is still optional, because a PLUGIN data model is built without a kind\n // and has none to compare.\n if (dataModel.kindRef && dataModel.kindRef !== kindRef) {\n throw new Error(\n `Block kind mismatch: data model built for '${dataModel.kindRef}' but create() got '${kindRef}'`,\n );\n }\n\n return new BlockModelV3<NoOb, {}, Data, \"/\", {}, Transfers, Params>({\n renderingMode: \"Heavy\",\n dataModel,\n kind: kindRef,\n // Read off the kind, which cannot omit it — not off the data model. The two\n // are cross-checked above, so there is one source, not a precedence order.\n parseInitializationParams: kind.parseInitializationParams,\n outputs: {},\n sections: createAndRegisterRenderLambda({ handle: \"sections\", lambda: () => [] }, true),\n title: undefined,\n subtitle: undefined,\n tags: undefined,\n enrichmentTargets: undefined,\n featureFlags: { ...BlockModelV3.FEATURE_FLAGS },\n deriveArgs: undefined,\n argsIssues: undefined,\n derivePrerunArgs: undefined,\n prerunArgsIssues: undefined,\n deriveTemplateParams: undefined,\n plugins: {},\n });\n }\n\n /**\n * Add output cell wrapped with additional status information to the configuration\n *\n * @param key output cell name, that can be later used to retrieve the rendered value\n * @param rf callback calculating output value using context, that allows to access\n * workflows outputs and interact with platforma drivers\n * @param flags additional flags that may alter lambda rendering procedure\n * */\n public output<const Key extends string, const RF extends RenderFunction<Args, Data, unknown>>(\n key: Key,\n rf: RF,\n flags: ConfigRenderLambdaFlags & { withStatus: true },\n ): BlockModelV3<\n Args,\n OutputsCfg & {\n [K in Key]: ConfigRenderLambda<InferRenderFunctionReturn<RF>> & {\n withStatus: true;\n };\n },\n Data,\n Href,\n Plugins,\n Transfers,\n Params,\n PrerunArgs\n >;\n /**\n * Add output cell to the configuration\n *\n * @param key output cell name, that can be later used to retrieve the rendered value\n * @param rf callback calculating output value using context, that allows to access\n * workflows outputs and interact with platforma drivers\n * @param flags additional flags that may alter lambda rendering procedure\n * */\n public output<const Key extends string, const RF extends RenderFunction<Args, Data, unknown>>(\n key: Key,\n rf: RF,\n flags?: ConfigRenderLambdaFlags,\n ): BlockModelV3<\n Args,\n OutputsCfg & {\n [K in Key]: ConfigRenderLambda<InferRenderFunctionReturn<RF>>;\n },\n Data,\n Href,\n Plugins,\n Transfers,\n Params,\n PrerunArgs\n >;\n public output(\n key: string,\n cfgOrRf: RenderFunction<Args, Data, unknown>,\n flags: ConfigRenderLambdaFlags = {},\n ): BlockModelV3<Args, OutputsCfg, Data, Href, Plugins, Transfers, Params, PrerunArgs> {\n return new BlockModelV3({\n ...this.config,\n outputs: {\n ...this.config.outputs,\n [key]: createAndRegisterRenderLambda({\n handle: `block-output#${key}`,\n lambda: () => cfgOrRf(new BlockRenderCtx<Args, Data>()),\n ...flags,\n }),\n },\n });\n }\n\n /** Shortcut for {@link output} with retentive flag set to true. */\n public retentiveOutput<\n const Key extends string,\n const RF extends RenderFunction<Args, Data, unknown>,\n >(\n key: Key,\n rf: RF,\n ): BlockModelV3<\n Args,\n OutputsCfg & {\n [K in Key]: ConfigRenderLambda<InferRenderFunctionReturn<RF>>;\n },\n Data,\n Href,\n Plugins,\n Transfers,\n Params,\n PrerunArgs\n > {\n return this.output(key, rf, { retentive: true });\n }\n\n /** Shortcut for {@link output} with withStatus flag set to true. */\n public outputWithStatus<\n const Key extends string,\n const RF extends RenderFunction<Args, Data, unknown>,\n >(key: Key, rf: RF) {\n return this.output(key, rf, { withStatus: true });\n }\n\n /**\n * Sets a function to derive block args from data.\n * This is called during setData to compute the args that will be used for block execution.\n *\n * Build args even from incomplete data, and say what keeps the block from running in\n * {@link argsIssues}: args that exist let the platform see what the block references\n * before it is ready to run. Throwing here still works, and means there are no args at all.\n *\n * Setting args again drops a {@link argsIssues} set before, since it checked other args.\n *\n * @example\n * .args<BlockArgs>((data) => ({ numbers: data.numbers }))\n *\n * @example\n * .args<BlockArgs>((data) => ({ numbers: data.numbers }))\n * .argsIssues(({ args }) =>\n * args.numbers.length === 0 ? [{ severity: 'error', message: 'Numbers required' }] : [],\n * )\n */\n public args<A>(\n lambda: (data: Data) => A,\n ): BlockModelV3<A, OutputsCfg, Data, Href, Plugins, Transfers, Params, PrerunArgs> {\n return new BlockModelV3<A, OutputsCfg, Data, Href, Plugins, Transfers, Params, PrerunArgs>({\n ...this.config,\n deriveArgs: lambda as (data: unknown) => unknown,\n argsIssues: undefined,\n });\n }\n\n /**\n * Sets a function that finds what keeps the block from running with the args {@link args}\n * derived (optional). It is called after `args()`, with its result and the data it was built\n * from.\n *\n * An issue of severity `\"error\"` keeps the block from running; a `\"warning\"` does not. A throw,\n * or a result that is not a list of issues, counts as one error carrying the thrown or parser\n * message. Without this function, args that `args()` returns are always runnable.\n *\n * A block without its own {@link prerunArgs} is staged with its args, and only while this\n * function finds no errors in them.\n *\n * Must be set after `.args()`, and is dropped when `.args()` is set again.\n *\n * @example\n * .args((data) => ({ dataset: data.dataset, threshold: data.threshold }))\n * .argsIssues(({ args }) => {\n * const issues: ArgsIssue[] = [];\n * if (args.dataset === undefined) issues.push({ severity: 'error', message: 'Select a dataset' });\n * if (args.threshold > 0.5) issues.push({ severity: 'warning', message: 'Threshold is high' });\n * return issues;\n * })\n */\n public argsIssues(\n fn: (input: { args: Args; data: Data }) => ArgsIssue[],\n ): BlockModelV3<Args, OutputsCfg, Data, Href, Plugins, Transfers, Params, PrerunArgs> {\n if (this.config.deriveArgs === undefined) {\n throw new Error(\"argsIssues() must be set after args(): it checks the args they derive.\");\n }\n return new BlockModelV3<Args, OutputsCfg, Data, Href, Plugins, Transfers, Params, PrerunArgs>({\n ...this.config,\n argsIssues: fn as (input: { args: unknown; data: unknown }) => ArgsIssue[],\n });\n }\n\n /**\n * Sets a function to derive pre-run args from data (optional).\n * This is called during setData to compute the args that will be used for staging/pre-run phase.\n *\n * If not defined, defaults to using the args() function result.\n * If defined, uses its return value for the staging / prerun phase.\n *\n * The staging / prerun phase runs only if currentPrerunArgs differs from the executed\n * version of prerunArgs (same comparison logic as currentArgs vs prodArgs).\n *\n * Setting prerun args again drops a {@link prerunArgsIssues} set before, since it checked other\n * args.\n *\n * @example\n * .prerunArgs((data) => ({ numbers: data.numbers }))\n *\n * @example\n * .prerunArgs((data) => {\n * // Return undefined to skip staging for this block\n * if (!data.isReady) return undefined;\n * return { numbers: data.numbers };\n * })\n */\n public prerunArgs<P>(\n fn: (data: Data) => P,\n ): BlockModelV3<Args, OutputsCfg, Data, Href, Plugins, Transfers, Params, P> {\n return new BlockModelV3<Args, OutputsCfg, Data, Href, Plugins, Transfers, Params, P>({\n ...this.config,\n derivePrerunArgs: fn as (data: unknown) => unknown,\n prerunArgsIssues: undefined,\n });\n }\n\n /**\n * Sets a function that finds what keeps the block from being staged with the args\n * {@link prerunArgs} derived (optional). It is called after `prerunArgs()`, with its result\n * and the data it was built from; not when `prerunArgs()` returned `undefined`, which skips\n * staging anyway.\n *\n * An issue of severity `\"error\"` keeps the block from being staged; a `\"warning\"` does not. A\n * throw, or a result that is not a list of issues, counts as one error carrying the thrown or\n * parser message. {@link argsIssues} is not consulted for a block with its own prerun args.\n *\n * Must be set after `.prerunArgs()`, and is dropped when `.prerunArgs()` is set again.\n *\n * @example\n * .prerunArgs((data) => ({ dataset: data.dataset }))\n * .prerunArgsIssues(({ prerunArgs }) =>\n * prerunArgs.dataset === undefined ? [{ severity: 'error', message: 'Select a dataset' }] : [],\n * )\n */\n public prerunArgsIssues(\n fn: (input: { prerunArgs: Exclude<PrerunArgs, undefined>; data: Data }) => ArgsIssue[],\n ): BlockModelV3<Args, OutputsCfg, Data, Href, Plugins, Transfers, Params, PrerunArgs> {\n if (this.config.derivePrerunArgs === undefined) {\n throw new Error(\n \"prerunArgsIssues() must be set after prerunArgs(): it checks the prerun args they derive.\",\n );\n }\n return new BlockModelV3<Args, OutputsCfg, Data, Href, Plugins, Transfers, Params, PrerunArgs>({\n ...this.config,\n prerunArgsIssues: fn as (input: { prerunArgs: unknown; data: unknown }) => ArgsIssue[],\n });\n }\n\n /**\n * Sets the function that projects block data back to this kind's params, for\n * exporting the project as a template.\n *\n * The inverse of the data model's `init`: `init` builds data from `params`, this\n * recovers the `params` that would rebuild the current data. Return only params\n * — runtime and derived state is dropped, and the exporter supplies the rest of\n * the entry (`id`, `kind`), which this lambda cannot set.\n *\n * References are returned as ordinary `PlRef`s; the SDK rewrites them into\n * template-local form on the way out, so a block never deals with the file\n * representation.\n *\n * Required: `done()` throws without it. A block whose state cannot be reduced to\n * params returns `{}` and says so explicitly, rather than exporting an entry with\n * no params that silently applies as a default-initialized block.\n *\n * The return type is the kind's `Params`, so a block whose projection drifts\n * from its own init contract fails to compile. Available only on a\n * kind-carrying model — `create(dataModel)` without a kind leaves `Params` as\n * `unknown` and this method cannot be type-checked against anything.\n *\n * @example\n * BlockModelV3.create({ dataModel, kind })\n * .args((data) => ({ numbers: data.numbers }))\n * .templateParams((data) => ({ sources: data.sources }))\n * .done();\n */\n public templateParams(\n fn: (data: Data) => Params,\n ): BlockModelV3<Args, OutputsCfg, Data, Href, Plugins, Transfers, Params, PrerunArgs> {\n return new BlockModelV3<Args, OutputsCfg, Data, Href, Plugins, Transfers, Params, PrerunArgs>({\n ...this.config,\n deriveTemplateParams: fn,\n });\n }\n\n /** Sets the lambda to generate list of sections in the left block overviews panel. */\n public sections<\n const Ret extends SectionsExpectedType,\n const RF extends RenderFunction<Args, Data, Ret>,\n >(\n rf: RF,\n ): BlockModelV3<\n Args,\n OutputsCfg,\n Data,\n DeriveHref<ReturnType<RF>>,\n Plugins,\n Transfers,\n Params,\n PrerunArgs\n > {\n return new BlockModelV3<\n Args,\n OutputsCfg,\n Data,\n DeriveHref<ReturnType<RF>>,\n Plugins,\n Transfers,\n Params,\n PrerunArgs\n >({\n ...this.config,\n // Replace the default sections callback with the user-provided one\n sections: createAndRegisterRenderLambda(\n {\n handle: \"sections\",\n lambda: () => rf(new BlockRenderCtx<Args, Data>()),\n },\n true,\n ),\n });\n }\n\n /** Sets a rendering function to derive block title, shown for the block in the left blocks-overview panel. */\n public title(\n rf: RenderFunction<Args, Data, string>,\n ): BlockModelV3<Args, OutputsCfg, Data, Href, Plugins, Transfers, Params, PrerunArgs> {\n return new BlockModelV3<Args, OutputsCfg, Data, Href, Plugins, Transfers, Params, PrerunArgs>({\n ...this.config,\n title: createAndRegisterRenderLambda({\n handle: \"title\",\n lambda: () => rf(new BlockRenderCtx<Args, Data>()),\n }),\n });\n }\n\n /**\n * Sets a rendering function to derive block subtitle, shown below the title in the left\n * blocks-overview panel. Unlike the title, it can read the result pool, so it can name the\n * inputs the block reads (e.g. through `ctx.resultPool.getPColumnSpecByRef`).\n */\n public subtitle(\n rf: RenderFunction<Args, Data, string>,\n ): BlockModelV3<Args, OutputsCfg, Data, Href, Plugins, Transfers, Params, PrerunArgs> {\n return new BlockModelV3<Args, OutputsCfg, Data, Href, Plugins, Transfers, Params, PrerunArgs>({\n ...this.config,\n subtitle: createAndRegisterRenderLambda({\n handle: \"subtitle\",\n lambda: () => rf(new BlockRenderCtx<Args, Data>()),\n }),\n });\n }\n\n public tags(\n rf: RenderFunction<Args, Data, string[]>,\n ): BlockModelV3<Args, OutputsCfg, Data, Href, Plugins, Transfers, Params, PrerunArgs> {\n return new BlockModelV3<Args, OutputsCfg, Data, Href, Plugins, Transfers, Params, PrerunArgs>({\n ...this.config,\n tags: createAndRegisterRenderLambda({\n handle: \"tags\",\n lambda: () => rf(new BlockRenderCtx<Args, Data>()),\n }),\n });\n }\n\n /** Sets or overrides feature flags for the block. */\n public withFeatureFlags(\n flags: Partial<BlockCodeKnownFeatureFlags>,\n ): BlockModelV3<Args, OutputsCfg, Data, Href, Plugins, Transfers, Params, PrerunArgs> {\n return new BlockModelV3<Args, OutputsCfg, Data, Href, Plugins, Transfers, Params, PrerunArgs>({\n ...this.config,\n featureFlags: { ...this.config.featureFlags, ...flags },\n });\n }\n\n /**\n * Defines how to derive list of upstream references this block is meant to enrich with its exports from block args.\n * Influences dependency graph construction.\n */\n public enriches(\n lambda: (args: Args) => PlRef[],\n ): BlockModelV3<Args, OutputsCfg, Data, Href, Plugins, Transfers, Params, PrerunArgs> {\n return new BlockModelV3<Args, OutputsCfg, Data, Href, Plugins, Transfers, Params, PrerunArgs>({\n ...this.config,\n enrichmentTargets: createAndRegisterRenderLambda({\n handle: \"enrichmentTargets\",\n lambda: lambda,\n }),\n });\n }\n\n /**\n * Registers a plugin instance with the block.\n * Consumes a transfer if one was defined for this plugin ID in the migration chain.\n *\n * Type checks:\n * - If Transfers[Id] exists, verifies it extends PTransferData (transfer type compatibility)\n * - If no Transfers[Id], rejects plugins with transferAt set (missing .transfer() in data model)\n * - Rejects duplicate plugin IDs (Id already in keyof Plugins)\n *\n * @param instance - PluginInstance created via factory.create({ pluginId, ... })\n * @param params - Per-property lambdas deriving plugin params from block RenderCtx\n *\n * @example\n * .plugin(mainTable, {\n * columns: (ctx) => ctx.outputs?.resolve(\"data\")?.getPColumns(),\n * sourceId: (ctx) => ctx.data.selectedSource,\n * })\n */\n public plugin<\n const PluginId extends string,\n PData extends PluginData,\n PParams extends PluginParams,\n POutputs extends PluginOutputs,\n PPublicOutputs extends PluginPublicOutputs,\n PTransferData,\n PluginModelServices,\n PluginUiServices,\n >(\n instance: PluginInstanceClass<\n PluginId &\n (PluginId extends keyof Transfers\n ? Transfers[PluginId] extends PTransferData\n ? string\n : never\n : [PTransferData] extends [never]\n ? string\n : never) &\n (PluginId extends keyof Plugins ? never : string),\n PData,\n PParams,\n POutputs,\n PPublicOutputs,\n PTransferData,\n PluginModelServices,\n PluginUiServices\n >,\n params?: ParamsInput<PParams, Args, Data>,\n ): BlockModelV3<\n Args,\n OutputsCfg,\n Data,\n Href,\n Plugins & {\n [K in PluginId]: PluginRecord<\n PData,\n PParams,\n POutputs,\n PPublicOutputs,\n PluginModelServices,\n PluginUiServices\n >;\n },\n Omit<Transfers, PluginId>,\n Params,\n PrerunArgs\n >;\n public plugin(\n instance: PluginInstanceClass,\n params?: ParamsInput<Record<string, unknown>, unknown, unknown>,\n ): BlockModelV3<\n Args,\n OutputsCfg,\n Data,\n Href,\n Record<string, PluginRecord>,\n Record<string, unknown>,\n Params,\n PrerunArgs\n > {\n const pluginId = instance.id;\n const plugin = instance[CREATE_PLUGIN_MODEL]();\n const resolvedParams = (params ?? {}) as ParamsInputErased;\n\n if (pluginId in this.config.plugins) {\n throw new Error(`Plugin '${pluginId}' already registered`);\n }\n\n const registered: PluginRecord = {\n model: plugin,\n inputs: resolvedParams,\n };\n\n return new BlockModelV3({\n ...this.config,\n plugins: {\n ...this.config.plugins,\n [pluginId]: registered,\n },\n featureFlags: mergeFeatureFlags(this.config.featureFlags, plugin.featureFlags ?? {}),\n });\n }\n\n /** Renders all provided block settings into a pre-configured platforma API\n * instance, that can be used in frontend to interact with block data, and\n * other features provided by the platforma to the block.\n *\n * Type-level check: if there are unconsumed transfers (from `.transfer()` calls\n * in the migration chain), this method requires an impossible `never` argument,\n * producing a compile error. Register all transferred plugins via `.plugin(instance)`\n * before calling `.done()`.\n */\n public done(\n ..._: keyof Transfers extends never ? [] : [never]\n ): PlatformaExtended<\n PlatformaV3<\n Data,\n Args,\n InferOutputsFromLambdas<OutputsCfg>,\n Href,\n Plugins,\n BlockDefaultUiServices\n >\n > {\n if (this.config.deriveArgs === undefined) throw new Error(\"Args rendering function not set.\");\n if (this.config.deriveTemplateParams === undefined)\n throw new Error(\n \"templateParams() not set. Every block must project its state back to its kind's params, \" +\n \"so a project can be exported as a template and re-applied; a block whose state carries \" +\n \"nothing worth restoring returns {}.\",\n );\n\n const apiVersion = 3;\n\n // Build plugin registry\n const { plugins } = this.config;\n const pluginRegistry: Record<string, PluginName> = {};\n const pluginHandles = Object.keys(plugins) as PluginHandle[];\n for (const handle of pluginHandles) {\n pluginRegistry[handle] = plugins[handle].model.name;\n }\n\n const {\n dataModel,\n deriveArgs,\n argsIssues,\n derivePrerunArgs,\n prerunArgsIssues,\n deriveTemplateParams,\n parseInitializationParams,\n } = this.config;\n\n function getPlugin(handle: PluginHandle): PluginRecord {\n const plugin = plugins[handle];\n if (!plugin) throw new Error(`Plugin model not found for '${handle}'`);\n return plugin;\n }\n\n // Register ALL facade callbacks here, with dependencies captured via closures\n registerFacadeCallbacks({\n [BlockStorageFacadeCallbacks.StorageApplyUpdate]: applyStorageUpdate,\n [BlockStorageFacadeCallbacks.StorageDebugView]: getStorageDebugView,\n [BlockStorageFacadeCallbacks.StorageMigrate]: (currentStorageJson) =>\n migrateStorage(currentStorageJson, {\n migrateBlockData: (v) => dataModel.migrate(v),\n getPluginRegistry: () => pluginRegistry,\n migratePluginData: (handle, v) => getPlugin(handle).model.dataModel.migrate(v),\n createPluginData: (handle, transfer) => {\n if (transfer) return transfer;\n return getPlugin(handle).model.getDefaultData();\n },\n }),\n [BlockStorageFacadeCallbacks.StorageInitial]: () =>\n createInitialStorage({\n getDefaultBlockData: () => dataModel.getDefaultData(),\n getPluginRegistry: () => pluginRegistry,\n createPluginData: (handle) => getPlugin(handle).model.getDefaultData(),\n }),\n [BlockStorageFacadeCallbacks.ArgsDerive]: (storageJson) =>\n deriveArgsFromStorage(storageJson, { deriveArgs, argsIssues }),\n [BlockStorageFacadeCallbacks.PrerunArgsDerive]: (storageJson) =>\n derivePrerunArgsFromStorage(storageJson, {\n deriveArgs,\n argsIssues,\n ownPrerunArgs:\n derivePrerunArgs === undefined ? undefined : { derivePrerunArgs, prerunArgsIssues },\n }),\n [BlockStorageFacadeCallbacks.InitializationParamsDerive]: (storageJson) =>\n deriveTemplateParamsFromStorage(\n storageJson,\n deriveTemplateParams as (data: unknown) => unknown,\n ),\n [BlockStorageFacadeCallbacks.StorageInitialFromParams]: (paramsJson, blockIdsJson) =>\n createInitialStorageFromParams(paramsJson, blockIdsJson, {\n getBlockDataFromParams: (params) => dataModel.getDataFromParams(params),\n getPluginRegistry: () => pluginRegistry,\n createPluginData: (handle) => getPlugin(handle).model.getDefaultData(),\n parseInitializationParams,\n }),\n [BlockStorageFacadeCallbacks.InitializationParamsValidate]: (paramsJson) =>\n validateTemplateParamsJson(paramsJson, parseInitializationParams),\n });\n\n // Register plugin input and output lambdas\n const pluginOutputs: Record<string, ConfigRenderLambda> = {};\n for (const handle of pluginHandles) {\n const { model, inputs } = plugins[handle];\n // Wrap plugin param lambdas: close over BlockRenderCtx creation\n const wrappedInputs: Record<string, () => unknown> = {};\n for (const [paramKey, paramFn] of Object.entries(inputs)) {\n wrappedInputs[paramKey] = () => paramFn(new BlockRenderCtx());\n }\n\n // Register plugin outputs (in config pack, evaluated by middle layer)\n const outputs = model.outputs as Record<string, (ctx: PluginRenderCtx) => unknown>;\n for (const [outputKey, outputFn] of Object.entries(outputs)) {\n const key = pluginOutputKey(handle, outputKey);\n pluginOutputs[key] = createAndRegisterRenderLambda({\n handle: key,\n lambda: () => outputFn(new PluginRenderCtx(handle, wrappedInputs)),\n withStatus: true,\n });\n }\n }\n const allOutputs = { ...this.config.outputs, ...pluginOutputs };\n\n globalThis.platformaApiVersion = apiVersion;\n\n if (!isInUI()) {\n const blockConfig: BlockConfigContainer = {\n v4: {\n configVersion: 4,\n modelAPIVersion: BLOCK_STORAGE_FACADE_VERSION,\n sdkVersion: PlatformaSDKVersion,\n renderingMode: this.config.renderingMode,\n sections: this.config.sections,\n title: this.config.title,\n subtitle: this.config.subtitle,\n tags: this.config.tags,\n outputs: allOutputs,\n enrichmentTargets: this.config.enrichmentTargets,\n featureFlags: this.config.featureFlags,\n blockLifecycleCallbacks: { ...BlockStorageFacadeHandles },\n },\n\n // Block-kind identity, baked at the container level beside `code`\n // (orthogonal to which render envelope applies). Rides into model.json\n // via the JSON.stringify(config) in build-model.ts — no write-path change.\n kind: this.config.kind,\n\n // fields below are added to allow previous desktop versions read generated configs\n sdkVersion: PlatformaSDKVersion,\n renderingMode: this.config.renderingMode,\n sections: this.config.sections,\n outputs: Object.fromEntries(\n Object.entries(this.config.outputs).map(([key, value]) => [\n key,\n downgradeCfgOrLambda(value),\n ]),\n ),\n };\n // we are in the configuration rendering routine, not in actual UI\n return { config: blockConfig } as any;\n // normal operation inside the UI\n } else {\n return {\n ...getPlatformaInstance({\n sdkVersion: PlatformaSDKVersion,\n apiVersion,\n }),\n blockModelInfo: {\n outputs: Object.fromEntries(\n Object.entries(allOutputs).map(([key, value]) => [\n key,\n {\n withStatus: Boolean(isConfigLambda(value) && value.withStatus),\n },\n ]),\n ),\n pluginIds: pluginHandles,\n featureFlags: this.config.featureFlags,\n pluginPublicOutputs: Object.fromEntries(\n pluginHandles.map((handle) => [handle, plugins[handle].model.publicOutputDef]),\n ),\n },\n } as any;\n }\n }\n}\n\n// Type tests for BlockModelV3\n\nexport type Expect<T extends true> = T;\n\nexport type Equal<X, Y> =\n (<T>() => T extends X ? 1 : 2) extends <T>() => T extends Y ? 1 : 2 ? true : false;\n\nexport type Merge<A, B> = {\n [K in keyof A | keyof B]: K extends keyof B ? B[K] : K extends keyof A ? A[K] : never;\n};\n\n// Helper types for testing\ntype _TestArgs = { inputFile: string; threshold: number };\ntype _TestData = { selectedTab: string };\ntype _TestOutputs = {\n result: ConfigRenderLambda<string>;\n count: ConfigRenderLambda<number>;\n};\n\n// Test: Merge type works correctly\ntype _MergeTest1 = Expect<Equal<Merge<{ a: 1 }, { b: 2 }>, { a: 1; b: 2 }>>;\ntype _MergeTest2 = Expect<Equal<Merge<{ a: 1 }, { a: 2 }>, { a: 2 }>>;\ntype _MergeTest3 = Expect<Equal<Merge<{ a: 1; b: 1 }, { b: 2; c: 3 }>, { a: 1; b: 2; c: 3 }>>;\n\n// Test: create() returns a BlockModelV3 instance\n// Note: Due to function overloads, ReturnType uses the last overload signature.\n// We verify the structure is correct using a simpler assignability test.\ntype _CreateResult = ReturnType<typeof BlockModelV3.create>;\ntype _CreateIsBlockModelV3 =\n _CreateResult extends BlockModelV3<infer _A, infer _O, infer _S> ? true : false;\ntype _CreateTest = Expect<_CreateIsBlockModelV3>;\n\n// Test: BlockModelV3Config interface structure (default generics)\ntype _ConfigTest = Expect<\n Equal<\n BlockModelV3Config<_TestOutputs, _TestData>,\n {\n renderingMode: BlockRenderingMode;\n deriveArgs: ((data: unknown) => unknown) | undefined;\n argsIssues: ((input: { args: unknown; data: unknown }) => ArgsIssue[]) | undefined;\n derivePrerunArgs: ((data: unknown) => unknown) | undefined;\n prerunArgsIssues:\n | ((input: { prerunArgs: unknown; data: unknown }) => ArgsIssue[])\n | undefined;\n deriveTemplateParams: ((data: _TestData) => unknown) | undefined;\n parseInitializationParams: (value: unknown) => unknown;\n dataModel: DataModel<_TestData, unknown, {}>;\n kind: BlockKindReference | undefined;\n outputs: _TestOutputs;\n sections: ConfigRenderLambda;\n title: ConfigRenderLambda | undefined;\n subtitle: ConfigRenderLambda | undefined;\n tags: ConfigRenderLambda | undefined;\n enrichmentTargets: ConfigRenderLambda | undefined;\n featureFlags: BlockCodeKnownFeatureFlags;\n plugins: {};\n }\n >\n>;\n\n// Test: Default Href is '/'\ntype _HrefDefaultTest =\n BlockModelV3<_TestArgs, {}, _TestData> extends BlockModelV3<_TestArgs, {}, _TestData, \"/\">\n ? true\n : false;\ntype _VerifyHrefDefault = Expect<_HrefDefaultTest>;\n\n// Test: Custom Href can be specified\ntype _CustomHref = \"/settings\" | \"/main\";\ntype _HrefCustomBuilder = BlockModelV3<_TestArgs, {}, _TestData, _CustomHref>;\ntype _HrefCustomTest =\n _HrefCustomBuilder extends BlockModelV3<_TestArgs, {}, _TestData, _CustomHref> ? true : false;\ntype _VerifyHrefCustom = Expect<_HrefCustomTest>;\n\n// Test: Output type accumulation with & intersection\ntype _OutputsAccumulation = { a: ConfigRenderLambda<string> } & {\n b: ConfigRenderLambda<number>;\n};\ntype _VerifyOutputsHaveKeys = Expect<Equal<keyof _OutputsAccumulation, \"a\" | \"b\">>;\n\n// Test: Builder with all type parameters specified compiles\ntype _FullBuilder = BlockModelV3<_TestArgs, _TestOutputs, _TestData, \"/main\">;\ntype _FullBuilderTest =\n _FullBuilder extends BlockModelV3<_TestArgs, _TestOutputs, _TestData, \"/main\"> ? true : false;\ntype _VerifyFullBuilder = Expect<_FullBuilderTest>;\n\n// Test: InferOutputsFromLambdas maps outputs correctly\ntype _InferOutputsTest = InferOutputsFromLambdas<{\n myOutput: ConfigRenderLambda<number>;\n}>;\ntype _VerifyInferOutputs = Expect<\n Equal<_InferOutputsTest, { myOutput: OutputWithStatus<number> & { __unwrap: true } }>\n>;\n"],"mappings":";;;;;;;;;;;;;;;;;;;AA8EA,SAAS,kBACP,MACA,UAC4B;CAC5B,MAAM,SAAuD,EAAE,GAAG,KAAK;CACvE,KAAK,MAAM,CAAC,KAAK,UAAU,OAAO,QAAQ,QAAQ,GAAG;EACnD,IAAI,UAAU,KAAA,GAAW;EACzB,MAAM,WAAW,OAAO;EACxB,IAAI,OAAO,UAAU,WACnB,OAAO,OAAQ,OAAO,aAAa,aAAa,YAAa;OACxD,IAAI,OAAO,UAAU,UAC1B,OAAO,OAAO,KAAK,IAAI,OAAO,aAAa,WAAW,WAAW,GAAG,KAAK;CAE7E;CACA,OAAO;AACT;;;;;AA0DA,IAAa,eAAb,MAAa,aASX;CAEmB;CADnB,YACE,QACA;EADiB,KAAA,SAAA;CAChB;CAEH,OAAuB,gBAAgB;EACrC,mBAAmB;EACnB,4BAA4B;EAC5B,qBAAqB;EACrB,sBAAsB;EACtB,yBAAA;EACA,sBAAsB;EACtB,wBAAwBA,gCAAAA;EACxB,oBAAoB;EACpB,GAAGC,uBAAAA;CACL;;CAGA,OAAuB,8BAA8B,aAAa;;;;;;;;;;;;;;;;;;;;CAqBlE,OAAc,OAIZ,MAG2D;EAC3D,MAAM,EAAE,WAAW,SAAS;EAG5B,MAAM,WAAA,GAAUC,gCAAAA,cAAAA,CAAc,IAAI;EAOlC,IAAI,UAAU,WAAW,UAAU,YAAY,SAC7C,MAAM,IAAI,MACR,8CAA8C,UAAU,QAAQ,sBAAsB,QAAQ,EAChG;EAGF,OAAO,IAAI,aAAyD;GAClE,eAAe;GACf;GACA,MAAM;GAGN,2BAA2B,KAAK;GAChC,SAAS,CAAC;GACV,U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O,YAC1B,cAAc,KAAK,WAAW,CAAC,QAAQ,QAAQ,OAAO,CAAC,MAAM,eAAe,CAAC,CAC/E;GACF;EACF;CAEJ;AACF"}
|
|
1
|
+
{"version":3,"file":"block_model.cjs","names":["REQUIRES_PFRAMES_VERSION","BLOCK_SERVICE_FLAGS","formatKindRef","createAndRegisterRenderLambda","BlockRenderCtx","CREATE_PLUGIN_MODEL","BlockStorageFacadeCallbacks","applyStorageUpdate","getStorageDebugView","migrateStorage","createInitialStorage","deriveArgsFromStorage","derivePrerunArgsFromStorage","deriveTemplateParamsFromStorage","createInitialStorageFromParams","validateTemplateParamsJson","applyParamsToStorage","pluginOutputKey","PluginRenderCtx","isInUI","PlatformaSDKVersion","BlockStorageFacadeHandles","BlockStorageFacadeOptionalHandles","downgradeCfgOrLambda","getPlatformaInstance","isConfigLambda"],"sources":["../src/block_model.ts"],"sourcesContent":["import type {\n BlockRenderingMode,\n BlockSection,\n OutputWithStatus,\n PlRef,\n BlockCodeKnownFeatureFlags,\n BlockConfigContainer,\n BlockKindReference,\n ArgsIssue,\n} from \"@milaboratories/pl-model-common\";\nimport { REQUIRES_PFRAMES_VERSION, formatKindRef } from \"@milaboratories/pl-model-common\";\nimport { getPlatformaInstance, isInUI, createAndRegisterRenderLambda } from \"./internal\";\nimport type { BlockKind, DataModel } from \"./block_migrations\";\nimport type { PlatformaV3 } from \"./platforma\";\nimport type { BlockDefaultUiServices } from \"./services/service_resolve\";\nimport { BLOCK_SERVICE_FLAGS } from \"./services/block_services\";\nimport type { InferRenderFunctionReturn, RenderFunction } from \"./render\";\nimport { BlockRenderCtx, PluginRenderCtx } from \"./render\";\nimport type {\n PluginData,\n PluginModel,\n PluginOutputs,\n PluginParams,\n PluginPublicOutputs,\n} from \"./plugin_model\";\nimport { PluginInstance as PluginInstanceClass, CREATE_PLUGIN_MODEL } from \"./plugin_model\";\nimport { type PluginHandle, pluginOutputKey } from \"./plugin_handle\";\nimport type { RenderCtxBase } from \"./render\";\nimport { PlatformaSDKVersion } from \"./version\";\nimport {\n applyStorageUpdate,\n getStorageDebugView,\n migrateStorage,\n createInitialStorage,\n createInitialStorageFromParams,\n applyParamsToStorage,\n validateTemplateParamsJson,\n deriveArgsFromStorage,\n derivePrerunArgsFromStorage,\n deriveTemplateParamsFromStorage,\n} from \"./block_storage_callbacks\";\nimport { type PluginName } from \"./block_storage\";\nimport type {\n ConfigRenderLambda,\n DeriveHref,\n ConfigRenderLambdaFlags,\n InferOutputsFromLambdas,\n} from \"./bconfig\";\nimport { downgradeCfgOrLambda, isConfigLambda } from \"./bconfig\";\nimport type { PlatformaExtended } from \"./platforma\";\nimport {\n BLOCK_STORAGE_FACADE_VERSION,\n BlockStorageFacadeCallbacks,\n BlockStorageFacadeHandles,\n BlockStorageFacadeOptionalHandles,\n registerFacadeCallbacks,\n} from \"./block_storage_facade\";\n\ntype SectionsExpectedType = readonly BlockSection[];\n\ntype NoOb = Record<string, never>;\n\n/**\n * Per-property lambdas for deriving plugin params from block render context.\n * Each property is a function that receives the block's RenderCtxBase and returns the param value.\n */\nexport type ParamsInput<Params, BArgs = unknown, BData = unknown> = {\n [K in keyof Params]: (ctx: RenderCtxBase<BArgs, BData>) => Params[K];\n};\n\n/**\n * Type-erased version of ParamsInput for internal storage.\n */\ntype ParamsInputErased = Record<string, (ctx: RenderCtxBase) => unknown>;\n\n/**\n * Merges two feature flag objects with type-aware logic:\n * - `supports*` (boolean): OR — `true` if either side is `true`\n * - `requires*` (numeric): MAX — take the higher version requirement\n */\nfunction mergeFeatureFlags(\n base: BlockCodeKnownFeatureFlags,\n override: BlockCodeKnownFeatureFlags,\n): BlockCodeKnownFeatureFlags {\n const result: Record<string, boolean | number | undefined> = { ...base };\n for (const [key, value] of Object.entries(override)) {\n if (value === undefined) continue;\n const existing = result[key];\n if (typeof value === \"boolean\") {\n result[key] = (typeof existing === \"boolean\" && existing) || value;\n } else if (typeof value === \"number\") {\n result[key] = Math.max(typeof existing === \"number\" ? existing : 0, value);\n }\n }\n return result as BlockCodeKnownFeatureFlags;\n}\n\n/**\n * Plugin record: model + param derivation lambdas.\n */\nexport type PluginRecord<\n Data extends PluginData = PluginData,\n Params extends PluginParams = undefined,\n Outputs extends PluginOutputs = PluginOutputs,\n PublicOutputs extends PluginPublicOutputs = PluginPublicOutputs,\n ModelServices = unknown,\n UiServices = unknown,\n> = {\n readonly model: PluginModel<Data, Params, Outputs, PublicOutputs, ModelServices, UiServices>;\n readonly inputs: ParamsInputErased;\n};\n\ninterface BlockModelV3Config<\n OutputsCfg extends Record<string, ConfigRenderLambda>,\n Data,\n Plugins extends Record<string, PluginRecord> = {},\n Transfers extends Record<string, unknown> = {},\n Params = unknown,\n> {\n renderingMode: BlockRenderingMode;\n dataModel: DataModel<Data, Params, Transfers>;\n /** Reference to the block kind this model implements, in `{name}@{version}` form. */\n // @todo: use blockKind, `kind` super comman word\n kind: BlockKindReference | undefined;\n outputs: OutputsCfg;\n sections: ConfigRenderLambda;\n title: ConfigRenderLambda | undefined;\n subtitle: ConfigRenderLambda | undefined;\n tags: ConfigRenderLambda | undefined;\n enrichmentTargets: ConfigRenderLambda | undefined;\n featureFlags: BlockCodeKnownFeatureFlags;\n deriveArgs: ((data: unknown) => unknown) | undefined;\n /** Finds what keeps the derived args from running; set only together with `deriveArgs`. */\n argsIssues: ((input: { args: unknown; data: unknown }) => ArgsIssue[]) | undefined;\n derivePrerunArgs: ((data: unknown) => unknown) | undefined;\n /** Finds what keeps the prerun args from staging; set only together with `derivePrerunArgs`. */\n prerunArgsIssues: ((input: { prerunArgs: unknown; data: unknown }) => ArgsIssue[]) | undefined;\n /** Projects block data back to this kind's params for template export. */\n deriveTemplateParams: ((data: Data) => Params) | undefined;\n /** Puts this kind's params onto live block data; the inverse of `deriveTemplateParams`. */\n applyParams: ((data: Data, params: Params) => Data) | undefined;\n /**\n * The kind's runtime check for params supplied by a template. Read off the compiled\n * kind rather than declared per block: the params contract belongs to the kind, and\n * two blocks implementing it must not be able to disagree about what a valid params\n * object is. Always present — a kind cannot omit it, and a block cannot omit a kind.\n */\n parseInitializationParams: (value: unknown) => unknown;\n plugins: Plugins;\n}\n\n/** Main entry point that each block should use in it's \"config\" module. Don't forget\n * to call {@link done()} at the end of configuration. Value returned by this builder must be\n * exported as constant with name \"platforma\" from the \"config\" module.\n * API version is 3 (for UI) and 2 (for model) */\nexport class BlockModelV3<\n Args,\n OutputsCfg extends Record<string, ConfigRenderLambda>,\n Data extends Record<string, unknown> = Record<string, unknown>,\n Href extends `/${string}` = \"/\",\n Plugins extends Record<string, PluginRecord> = {},\n Transfers extends Record<string, unknown> = {},\n Params = unknown,\n PrerunArgs = unknown,\n> {\n private constructor(\n private readonly config: BlockModelV3Config<OutputsCfg, Data, Plugins, Transfers, Params>,\n ) {}\n\n public static readonly FEATURE_FLAGS = {\n supportsLazyState: true,\n supportsPframeQueryRanking: true,\n supportsColumnLinks: true,\n requiresUIAPIVersion: 3,\n requiresModelAPIVersion: BLOCK_STORAGE_FACADE_VERSION,\n requiresCreatePTable: 2,\n requiresPFramesVersion: REQUIRES_PFRAMES_VERSION,\n requiresArgsIssues: true,\n ...BLOCK_SERVICE_FLAGS,\n } satisfies BlockCodeKnownFeatureFlags;\n\n /** @deprecated Use FEATURE_FLAGS */\n public static readonly INITIAL_BLOCK_FEATURE_FLAGS = BlockModelV3.FEATURE_FLAGS;\n\n /**\n * Creates a new BlockModelV3 builder bound to a data model and a block kind.\n *\n * The `kind` argument is cross-checked against the kind handed to the\n * builder: its `Params` type must match at compile time (via\n * `BlockKind<Params>`), and its reference value must match at runtime. The\n * reference is baked into the config so the published manifest can advertise\n * which kind the block implements.\n *\n * @example\n * const dataModel = new DataModelBuilder({ kind })\n * .from<BlockData>(\"v1\")\n * .init(({ params }) => params ?? { numbers: [], labels: [] });\n *\n * BlockModelV3.create({ dataModel, kind })\n * .args((data) => ({ numbers: data.numbers }))\n * .sections(() => [{ type: 'link', href: '/', label: 'Main' }])\n * .done();\n */\n public static create<\n Data extends Record<string, unknown>,\n Params = never,\n Transfers extends Record<string, unknown> = {},\n >(args: {\n dataModel: DataModel<Data, Params, Transfers>;\n kind: BlockKind<Params>;\n }): BlockModelV3<NoOb, {}, Data, \"/\", {}, Transfers, Params> {\n const { dataModel, kind } = args;\n // Derive the on-wire reference from the compiled kind; the kind object has\n // no reference field of its own.\n const kindRef = formatKindRef(kind);\n\n // Runtime guard: the kind handed to the builder must match the kind handed to\n // create(). Nothing ties them together at the type level — they arrive as two\n // separately-passed objects — so a mismatch is only visible here. The builder's own\n // reference is still optional, because a PLUGIN data model is built without a kind\n // and has none to compare.\n if (dataModel.kindRef && dataModel.kindRef !== kindRef) {\n throw new Error(\n `Block kind mismatch: data model built for '${dataModel.kindRef}' but create() got '${kindRef}'`,\n );\n }\n\n return new BlockModelV3<NoOb, {}, Data, \"/\", {}, Transfers, Params>({\n renderingMode: \"Heavy\",\n dataModel,\n kind: kindRef,\n // Read off the kind, which cannot omit it — not off the data model. The two\n // are cross-checked above, so there is one source, not a precedence order.\n parseInitializationParams: kind.parseInitializationParams,\n outputs: {},\n sections: createAndRegisterRenderLambda({ handle: \"sections\", lambda: () => [] }, true),\n title: undefined,\n subtitle: undefined,\n tags: undefined,\n enrichmentTargets: undefined,\n featureFlags: { ...BlockModelV3.FEATURE_FLAGS },\n deriveArgs: undefined,\n argsIssues: undefined,\n derivePrerunArgs: undefined,\n prerunArgsIssues: undefined,\n deriveTemplateParams: undefined,\n applyParams: undefined,\n plugins: {},\n });\n }\n\n /**\n * Add output cell wrapped with additional status information to the configuration\n *\n * @param key output cell name, that can be later used to retrieve the rendered value\n * @param rf callback calculating output value using context, that allows to access\n * workflows outputs and interact with platforma drivers\n * @param flags additional flags that may alter lambda rendering procedure\n * */\n public output<const Key extends string, const RF extends RenderFunction<Args, Data, unknown>>(\n key: Key,\n rf: RF,\n flags: ConfigRenderLambdaFlags & { withStatus: true },\n ): BlockModelV3<\n Args,\n OutputsCfg & {\n [K in Key]: ConfigRenderLambda<InferRenderFunctionReturn<RF>> & {\n withStatus: true;\n };\n },\n Data,\n Href,\n Plugins,\n Transfers,\n Params,\n PrerunArgs\n >;\n /**\n * Add output cell to the configuration\n *\n * @param key output cell name, that can be later used to retrieve the rendered value\n * @param rf callback calculating output value using context, that allows to access\n * workflows outputs and interact with platforma drivers\n * @param flags additional flags that may alter lambda rendering procedure\n * */\n public output<const Key extends string, const RF extends RenderFunction<Args, Data, unknown>>(\n key: Key,\n rf: RF,\n flags?: ConfigRenderLambdaFlags,\n ): BlockModelV3<\n Args,\n OutputsCfg & {\n [K in Key]: ConfigRenderLambda<InferRenderFunctionReturn<RF>>;\n },\n Data,\n Href,\n Plugins,\n Transfers,\n Params,\n PrerunArgs\n >;\n public output(\n key: string,\n cfgOrRf: RenderFunction<Args, Data, unknown>,\n flags: ConfigRenderLambdaFlags = {},\n ): BlockModelV3<Args, OutputsCfg, Data, Href, Plugins, Transfers, Params, PrerunArgs> {\n return new BlockModelV3({\n ...this.config,\n outputs: {\n ...this.config.outputs,\n [key]: createAndRegisterRenderLambda({\n handle: `block-output#${key}`,\n lambda: () => cfgOrRf(new BlockRenderCtx<Args, Data>()),\n ...flags,\n }),\n },\n });\n }\n\n /** Shortcut for {@link output} with retentive flag set to true. */\n public retentiveOutput<\n const Key extends string,\n const RF extends RenderFunction<Args, Data, unknown>,\n >(\n key: Key,\n rf: RF,\n ): BlockModelV3<\n Args,\n OutputsCfg & {\n [K in Key]: ConfigRenderLambda<InferRenderFunctionReturn<RF>>;\n },\n Data,\n Href,\n Plugins,\n Transfers,\n Params,\n PrerunArgs\n > {\n return this.output(key, rf, { retentive: true });\n }\n\n /** Shortcut for {@link output} with withStatus flag set to true. */\n public outputWithStatus<\n const Key extends string,\n const RF extends RenderFunction<Args, Data, unknown>,\n >(key: Key, rf: RF) {\n return this.output(key, rf, { withStatus: true });\n }\n\n /**\n * Sets a function to derive block args from data.\n * This is called during setData to compute the args that will be used for block execution.\n *\n * Build args even from incomplete data, and say what keeps the block from running in\n * {@link argsIssues}: args that exist let the platform see what the block references\n * before it is ready to run. Throwing here still works, and means there are no args at all.\n *\n * Setting args again drops a {@link argsIssues} set before, since it checked other args.\n *\n * @example\n * .args<BlockArgs>((data) => ({ numbers: data.numbers }))\n *\n * @example\n * .args<BlockArgs>((data) => ({ numbers: data.numbers }))\n * .argsIssues(({ args }) =>\n * args.numbers.length === 0 ? [{ severity: 'error', message: 'Numbers required' }] : [],\n * )\n */\n public args<A>(\n lambda: (data: Data) => A,\n ): BlockModelV3<A, OutputsCfg, Data, Href, Plugins, Transfers, Params, PrerunArgs> {\n return new BlockModelV3<A, OutputsCfg, Data, Href, Plugins, Transfers, Params, PrerunArgs>({\n ...this.config,\n deriveArgs: lambda as (data: unknown) => unknown,\n argsIssues: undefined,\n });\n }\n\n /**\n * Sets a function that finds what keeps the block from running with the args {@link args}\n * derived (optional). It is called after `args()`, with its result and the data it was built\n * from.\n *\n * An issue of severity `\"error\"` keeps the block from running; a `\"warning\"` does not. A throw,\n * or a result that is not a list of issues, counts as one error carrying the thrown or parser\n * message. Without this function, args that `args()` returns are always runnable.\n *\n * A block without its own {@link prerunArgs} is staged with its args, and only while this\n * function finds no errors in them.\n *\n * Must be set after `.args()`, and is dropped when `.args()` is set again.\n *\n * @example\n * .args((data) => ({ dataset: data.dataset, threshold: data.threshold }))\n * .argsIssues(({ args }) => {\n * const issues: ArgsIssue[] = [];\n * if (args.dataset === undefined) issues.push({ severity: 'error', message: 'Select a dataset' });\n * if (args.threshold > 0.5) issues.push({ severity: 'warning', message: 'Threshold is high' });\n * return issues;\n * })\n */\n public argsIssues(\n fn: (input: { args: Args; data: Data }) => ArgsIssue[],\n ): BlockModelV3<Args, OutputsCfg, Data, Href, Plugins, Transfers, Params, PrerunArgs> {\n if (this.config.deriveArgs === undefined) {\n throw new Error(\"argsIssues() must be set after args(): it checks the args they derive.\");\n }\n return new BlockModelV3<Args, OutputsCfg, Data, Href, Plugins, Transfers, Params, PrerunArgs>({\n ...this.config,\n argsIssues: fn as (input: { args: unknown; data: unknown }) => ArgsIssue[],\n });\n }\n\n /**\n * Sets a function to derive pre-run args from data (optional).\n * This is called during setData to compute the args that will be used for staging/pre-run phase.\n *\n * If not defined, defaults to using the args() function result.\n * If defined, uses its return value for the staging / prerun phase.\n *\n * The staging / prerun phase runs only if currentPrerunArgs differs from the executed\n * version of prerunArgs (same comparison logic as currentArgs vs prodArgs).\n *\n * Setting prerun args again drops a {@link prerunArgsIssues} set before, since it checked other\n * args.\n *\n * @example\n * .prerunArgs((data) => ({ numbers: data.numbers }))\n *\n * @example\n * .prerunArgs((data) => {\n * // Return undefined to skip staging for this block\n * if (!data.isReady) return undefined;\n * return { numbers: data.numbers };\n * })\n */\n public prerunArgs<P>(\n fn: (data: Data) => P,\n ): BlockModelV3<Args, OutputsCfg, Data, Href, Plugins, Transfers, Params, P> {\n return new BlockModelV3<Args, OutputsCfg, Data, Href, Plugins, Transfers, Params, P>({\n ...this.config,\n derivePrerunArgs: fn as (data: unknown) => unknown,\n prerunArgsIssues: undefined,\n });\n }\n\n /**\n * Sets a function that finds what keeps the block from being staged with the args\n * {@link prerunArgs} derived (optional). It is called after `prerunArgs()`, with its result\n * and the data it was built from; not when `prerunArgs()` returned `undefined`, which skips\n * staging anyway.\n *\n * An issue of severity `\"error\"` keeps the block from being staged; a `\"warning\"` does not. A\n * throw, or a result that is not a list of issues, counts as one error carrying the thrown or\n * parser message. {@link argsIssues} is not consulted for a block with its own prerun args.\n *\n * Must be set after `.prerunArgs()`, and is dropped when `.prerunArgs()` is set again.\n *\n * @example\n * .prerunArgs((data) => ({ dataset: data.dataset }))\n * .prerunArgsIssues(({ prerunArgs }) =>\n * prerunArgs.dataset === undefined ? [{ severity: 'error', message: 'Select a dataset' }] : [],\n * )\n */\n public prerunArgsIssues(\n fn: (input: { prerunArgs: Exclude<PrerunArgs, undefined>; data: Data }) => ArgsIssue[],\n ): BlockModelV3<Args, OutputsCfg, Data, Href, Plugins, Transfers, Params, PrerunArgs> {\n if (this.config.derivePrerunArgs === undefined) {\n throw new Error(\n \"prerunArgsIssues() must be set after prerunArgs(): it checks the prerun args they derive.\",\n );\n }\n return new BlockModelV3<Args, OutputsCfg, Data, Href, Plugins, Transfers, Params, PrerunArgs>({\n ...this.config,\n prerunArgsIssues: fn as (input: { prerunArgs: unknown; data: unknown }) => ArgsIssue[],\n });\n }\n\n /**\n * Sets the function that projects block data back to this kind's params, for\n * exporting the project as a template.\n *\n * The inverse of how params become data — {@link applyParams} when the block declares it,\n * the data model's `init` otherwise: this recovers the `params` that would rebuild the\n * current data. Return only params\n * — runtime and derived state is dropped, and the exporter supplies the rest of\n * the entry (`id`, `kind`), which this lambda cannot set.\n *\n * References are returned as ordinary `PlRef`s; the SDK rewrites them into\n * template-local form on the way out, so a block never deals with the file\n * representation.\n *\n * Required: `done()` throws without it. A block whose state cannot be reduced to\n * params returns `{}` and says so explicitly, rather than exporting an entry with\n * no params that silently applies as a default-initialized block.\n *\n * The return type is the kind's `Params`, so a block whose projection drifts\n * from its own init contract fails to compile. Available only on a\n * kind-carrying model — `create(dataModel)` without a kind leaves `Params` as\n * `unknown` and this method cannot be type-checked against anything.\n *\n * @example\n * BlockModelV3.create({ dataModel, kind })\n * .args((data) => ({ numbers: data.numbers }))\n * .templateParams((data) => ({ sources: data.sources }))\n * .done();\n */\n public templateParams(\n fn: (data: Data) => Params,\n ): BlockModelV3<Args, OutputsCfg, Data, Href, Plugins, Transfers, Params, PrerunArgs> {\n return new BlockModelV3<Args, OutputsCfg, Data, Href, Plugins, Transfers, Params, PrerunArgs>({\n ...this.config,\n deriveTemplateParams: fn,\n });\n }\n\n /**\n * Sets the function that puts this kind's params onto live block data: the data the block\n * would have, were it configured with `params`. Together with {@link templateParams} it is a\n * pair — `templateParams` projects data onto params, `applyParams` writes params back onto data.\n *\n * Everything the params describe is written from `params`; everything they do not describe\n * (files, per-item values, view state, edits made in the UI) is kept from `data`.\n *\n * Declaring it makes it the one way params become data. Data built from params (template\n * apply, creation with params) is `applyParams(defaults, params)`, `defaults` being the data\n * model's default data (its `init` called without params); a write of params onto an existing\n * block (the MCP `set_block_params`) is `applyParams(current, params)`. Both run after the\n * kind's parser has accepted the params. Without it, data from params is the data model's\n * `init` called with them, as before.\n *\n * Params are whole, not a patch: a key absent from `params` is the kind's \"unset\", and\n * `applyParams` writes that into the data rather than leaving the old value.\n *\n * Laws the block keeps:\n * - `templateParams(applyParams(d, p))` equals `templateParams(applyParams(defaults, p))` for\n * any data `d` (the projection may leave out what does not travel, such as files);\n * - `applyParams(d, templateParams(d))` equals `d`.\n * The middle layer checks the first on every write of params and refuses one that breaks it.\n *\n * A shallow spread such as `({ ...data, ...params })` is usually wrong. It overwrites whole\n * values the params describe only in part — a list of items replaces the items in data along\n * with their files and view state — and it leaves in place what a key absent from `params`\n * should unset. Write each field the params describe, and match list items by their id.\n *\n * The parameter types are the kind's `Params` and the data model's data, so the function is\n * checked against the same contract as {@link templateParams}.\n *\n * @example\n * // Params: { samples: { id: string; label: string; threshold?: number }[] }\n * // Data: { samples: { id; label; threshold; file?: ImportFileHandle; expanded: boolean }[];\n * // tab: string }\n * BlockModelV3.create({ dataModel, kind })\n * .args((data) => ({ samples: data.samples }))\n * .templateParams((data) => ({\n * samples: data.samples.map(({ id, label, threshold }) => ({ id, label, threshold })),\n * }))\n * .applyParams((data, params) => {\n * const current = new Map(data.samples.map((s) => [s.id, s]));\n * return {\n * ...data, // `tab` and anything else the params do not describe\n * // The list is the params': a sample absent from them is removed.\n * samples: params.samples.map((p) => {\n * const kept = current.get(p.id); // per-sample state the params do not describe\n * return {\n * id: p.id,\n * label: p.label,\n * threshold: p.threshold ?? DEFAULT_THRESHOLD, // absent means unset, not unchanged\n * file: kept?.file,\n * expanded: kept?.expanded ?? false,\n * };\n * }),\n * };\n * })\n * .done();\n */\n public applyParams(\n fn: (data: Data, params: Params) => Data,\n ): BlockModelV3<Args, OutputsCfg, Data, Href, Plugins, Transfers, Params, PrerunArgs> {\n return new BlockModelV3<Args, OutputsCfg, Data, Href, Plugins, Transfers, Params, PrerunArgs>({\n ...this.config,\n applyParams: fn,\n });\n }\n\n /** Sets the lambda to generate list of sections in the left block overviews panel. */\n public sections<\n const Ret extends SectionsExpectedType,\n const RF extends RenderFunction<Args, Data, Ret>,\n >(\n rf: RF,\n ): BlockModelV3<\n Args,\n OutputsCfg,\n Data,\n DeriveHref<ReturnType<RF>>,\n Plugins,\n Transfers,\n Params,\n PrerunArgs\n > {\n return new BlockModelV3<\n Args,\n OutputsCfg,\n Data,\n DeriveHref<ReturnType<RF>>,\n Plugins,\n Transfers,\n Params,\n PrerunArgs\n >({\n ...this.config,\n // Replace the default sections callback with the user-provided one\n sections: createAndRegisterRenderLambda(\n {\n handle: \"sections\",\n lambda: () => rf(new BlockRenderCtx<Args, Data>()),\n },\n true,\n ),\n });\n }\n\n /** Sets a rendering function to derive block title, shown for the block in the left blocks-overview panel. */\n public title(\n rf: RenderFunction<Args, Data, string>,\n ): BlockModelV3<Args, OutputsCfg, Data, Href, Plugins, Transfers, Params, PrerunArgs> {\n return new BlockModelV3<Args, OutputsCfg, Data, Href, Plugins, Transfers, Params, PrerunArgs>({\n ...this.config,\n title: createAndRegisterRenderLambda({\n handle: \"title\",\n lambda: () => rf(new BlockRenderCtx<Args, Data>()),\n }),\n });\n }\n\n /**\n * Sets a rendering function to derive block subtitle, shown below the title in the left\n * blocks-overview panel. Unlike the title, it can read the result pool, so it can name the\n * inputs the block reads (e.g. through `ctx.resultPool.getPColumnSpecByRef`).\n */\n public subtitle(\n rf: RenderFunction<Args, Data, string>,\n ): BlockModelV3<Args, OutputsCfg, Data, Href, Plugins, Transfers, Params, PrerunArgs> {\n return new BlockModelV3<Args, OutputsCfg, Data, Href, Plugins, Transfers, Params, PrerunArgs>({\n ...this.config,\n subtitle: createAndRegisterRenderLambda({\n handle: \"subtitle\",\n lambda: () => rf(new BlockRenderCtx<Args, Data>()),\n }),\n });\n }\n\n public tags(\n rf: RenderFunction<Args, Data, string[]>,\n ): BlockModelV3<Args, OutputsCfg, Data, Href, Plugins, Transfers, Params, PrerunArgs> {\n return new BlockModelV3<Args, OutputsCfg, Data, Href, Plugins, Transfers, Params, PrerunArgs>({\n ...this.config,\n tags: createAndRegisterRenderLambda({\n handle: \"tags\",\n lambda: () => rf(new BlockRenderCtx<Args, Data>()),\n }),\n });\n }\n\n /** Sets or overrides feature flags for the block. */\n public withFeatureFlags(\n flags: Partial<BlockCodeKnownFeatureFlags>,\n ): BlockModelV3<Args, OutputsCfg, Data, Href, Plugins, Transfers, Params, PrerunArgs> {\n return new BlockModelV3<Args, OutputsCfg, Data, Href, Plugins, Transfers, Params, PrerunArgs>({\n ...this.config,\n featureFlags: { ...this.config.featureFlags, ...flags },\n });\n }\n\n /**\n * Defines how to derive list of upstream references this block is meant to enrich with its exports from block args.\n * Influences dependency graph construction.\n */\n public enriches(\n lambda: (args: Args) => PlRef[],\n ): BlockModelV3<Args, OutputsCfg, Data, Href, Plugins, Transfers, Params, PrerunArgs> {\n return new BlockModelV3<Args, OutputsCfg, Data, Href, Plugins, Transfers, Params, PrerunArgs>({\n ...this.config,\n enrichmentTargets: createAndRegisterRenderLambda({\n handle: \"enrichmentTargets\",\n lambda: lambda,\n }),\n });\n }\n\n /**\n * Registers a plugin instance with the block.\n * Consumes a transfer if one was defined for this plugin ID in the migration chain.\n *\n * Type checks:\n * - If Transfers[Id] exists, verifies it extends PTransferData (transfer type compatibility)\n * - If no Transfers[Id], rejects plugins with transferAt set (missing .transfer() in data model)\n * - Rejects duplicate plugin IDs (Id already in keyof Plugins)\n *\n * @param instance - PluginInstance created via factory.create({ pluginId, ... })\n * @param params - Per-property lambdas deriving plugin params from block RenderCtx\n *\n * @example\n * .plugin(mainTable, {\n * columns: (ctx) => ctx.outputs?.resolve(\"data\")?.getPColumns(),\n * sourceId: (ctx) => ctx.data.selectedSource,\n * })\n */\n public plugin<\n const PluginId extends string,\n PData extends PluginData,\n PParams extends PluginParams,\n POutputs extends PluginOutputs,\n PPublicOutputs extends PluginPublicOutputs,\n PTransferData,\n PluginModelServices,\n PluginUiServices,\n >(\n instance: PluginInstanceClass<\n PluginId &\n (PluginId extends keyof Transfers\n ? Transfers[PluginId] extends PTransferData\n ? string\n : never\n : [PTransferData] extends [never]\n ? string\n : never) &\n (PluginId extends keyof Plugins ? never : string),\n PData,\n PParams,\n POutputs,\n PPublicOutputs,\n PTransferData,\n PluginModelServices,\n PluginUiServices\n >,\n params?: ParamsInput<PParams, Args, Data>,\n ): BlockModelV3<\n Args,\n OutputsCfg,\n Data,\n Href,\n Plugins & {\n [K in PluginId]: PluginRecord<\n PData,\n PParams,\n POutputs,\n PPublicOutputs,\n PluginModelServices,\n PluginUiServices\n >;\n },\n Omit<Transfers, PluginId>,\n Params,\n PrerunArgs\n >;\n public plugin(\n instance: PluginInstanceClass,\n params?: ParamsInput<Record<string, unknown>, unknown, unknown>,\n ): BlockModelV3<\n Args,\n OutputsCfg,\n Data,\n Href,\n Record<string, PluginRecord>,\n Record<string, unknown>,\n Params,\n PrerunArgs\n > {\n const pluginId = instance.id;\n const plugin = instance[CREATE_PLUGIN_MODEL]();\n const resolvedParams = (params ?? {}) as ParamsInputErased;\n\n if (pluginId in this.config.plugins) {\n throw new Error(`Plugin '${pluginId}' already registered`);\n }\n\n const registered: PluginRecord = {\n model: plugin,\n inputs: resolvedParams,\n };\n\n return new BlockModelV3({\n ...this.config,\n plugins: {\n ...this.config.plugins,\n [pluginId]: registered,\n },\n featureFlags: mergeFeatureFlags(this.config.featureFlags, plugin.featureFlags ?? {}),\n });\n }\n\n /** Renders all provided block settings into a pre-configured platforma API\n * instance, that can be used in frontend to interact with block data, and\n * other features provided by the platforma to the block.\n *\n * Type-level check: if there are unconsumed transfers (from `.transfer()` calls\n * in the migration chain), this method requires an impossible `never` argument,\n * producing a compile error. Register all transferred plugins via `.plugin(instance)`\n * before calling `.done()`.\n */\n public done(\n ..._: keyof Transfers extends never ? [] : [never]\n ): PlatformaExtended<\n PlatformaV3<\n Data,\n Args,\n InferOutputsFromLambdas<OutputsCfg>,\n Href,\n Plugins,\n BlockDefaultUiServices\n >\n > {\n if (this.config.deriveArgs === undefined) throw new Error(\"Args rendering function not set.\");\n if (this.config.deriveTemplateParams === undefined)\n throw new Error(\n \"templateParams() not set. Every block must project its state back to its kind's params, \" +\n \"so a project can be exported as a template and re-applied; a block whose state carries \" +\n \"nothing worth restoring returns {}.\",\n );\n\n const apiVersion = 3;\n\n // Build plugin registry\n const { plugins } = this.config;\n const pluginRegistry: Record<string, PluginName> = {};\n const pluginHandles = Object.keys(plugins) as PluginHandle[];\n for (const handle of pluginHandles) {\n pluginRegistry[handle] = plugins[handle].model.name;\n }\n\n const {\n dataModel,\n deriveArgs,\n argsIssues,\n derivePrerunArgs,\n prerunArgsIssues,\n deriveTemplateParams,\n applyParams,\n parseInitializationParams,\n } = this.config;\n\n // The block's `applyParams` with its types erased, as the callbacks hand it data and params\n // that arrive as JSON. The params have passed the kind's parser by the time it runs.\n const applyParamsErased = applyParams as\n | ((data: unknown, params: unknown) => unknown)\n | undefined;\n\n function getPlugin(handle: PluginHandle): PluginRecord {\n const plugin = plugins[handle];\n if (!plugin) throw new Error(`Plugin model not found for '${handle}'`);\n return plugin;\n }\n\n // Register ALL facade callbacks here, with dependencies captured via closures\n registerFacadeCallbacks({\n [BlockStorageFacadeCallbacks.StorageApplyUpdate]: applyStorageUpdate,\n [BlockStorageFacadeCallbacks.StorageDebugView]: getStorageDebugView,\n [BlockStorageFacadeCallbacks.StorageMigrate]: (currentStorageJson) =>\n migrateStorage(currentStorageJson, {\n migrateBlockData: (v) => dataModel.migrate(v),\n getPluginRegistry: () => pluginRegistry,\n migratePluginData: (handle, v) => getPlugin(handle).model.dataModel.migrate(v),\n createPluginData: (handle, transfer) => {\n if (transfer) return transfer;\n return getPlugin(handle).model.getDefaultData();\n },\n }),\n [BlockStorageFacadeCallbacks.StorageInitial]: () =>\n createInitialStorage({\n getDefaultBlockData: () => dataModel.getDefaultData(),\n getPluginRegistry: () => pluginRegistry,\n createPluginData: (handle) => getPlugin(handle).model.getDefaultData(),\n }),\n [BlockStorageFacadeCallbacks.ArgsDerive]: (storageJson) =>\n deriveArgsFromStorage(storageJson, { deriveArgs, argsIssues }),\n [BlockStorageFacadeCallbacks.PrerunArgsDerive]: (storageJson) =>\n derivePrerunArgsFromStorage(storageJson, {\n deriveArgs,\n argsIssues,\n ownPrerunArgs:\n derivePrerunArgs === undefined ? undefined : { derivePrerunArgs, prerunArgsIssues },\n }),\n [BlockStorageFacadeCallbacks.InitializationParamsDerive]: (storageJson) =>\n deriveTemplateParamsFromStorage(\n storageJson,\n deriveTemplateParams as (data: unknown) => unknown,\n ),\n [BlockStorageFacadeCallbacks.StorageInitialFromParams]: (paramsJson, blockIdsJson) =>\n createInitialStorageFromParams(paramsJson, blockIdsJson, {\n // With `applyParams` declared, data from params is `applyParams(defaults, params)`.\n getBlockDataFromParams: (params) => {\n if (applyParamsErased === undefined || params === undefined)\n return dataModel.getDataFromParams(params);\n const defaults = dataModel.getDefaultData();\n return {\n version: defaults.version,\n data: applyParamsErased(defaults.data, params),\n };\n },\n getPluginRegistry: () => pluginRegistry,\n createPluginData: (handle) => getPlugin(handle).model.getDefaultData(),\n parseInitializationParams,\n }),\n [BlockStorageFacadeCallbacks.InitializationParamsValidate]: (paramsJson) =>\n validateTemplateParamsJson(paramsJson, parseInitializationParams),\n // Only for a block that declares `applyParams`: the callback's absence is how the\n // middle layer knows to build data from params some other way.\n [BlockStorageFacadeCallbacks.StorageApplyParams]:\n applyParamsErased === undefined\n ? undefined\n : (storageJson, paramsJson) =>\n applyParamsToStorage(storageJson, paramsJson, {\n dataVersion: dataModel.version,\n applyParams: (data, params) => ({\n version: dataModel.version,\n data: applyParamsErased(data, params),\n }),\n parseInitializationParams,\n }),\n });\n\n // Register plugin input and output lambdas\n const pluginOutputs: Record<string, ConfigRenderLambda> = {};\n for (const handle of pluginHandles) {\n const { model, inputs } = plugins[handle];\n // Wrap plugin param lambdas: close over BlockRenderCtx creation\n const wrappedInputs: Record<string, () => unknown> = {};\n for (const [paramKey, paramFn] of Object.entries(inputs)) {\n wrappedInputs[paramKey] = () => paramFn(new BlockRenderCtx());\n }\n\n // Register plugin outputs (in config pack, evaluated by middle layer)\n const outputs = model.outputs as Record<string, (ctx: PluginRenderCtx) => unknown>;\n for (const [outputKey, outputFn] of Object.entries(outputs)) {\n const key = pluginOutputKey(handle, outputKey);\n pluginOutputs[key] = createAndRegisterRenderLambda({\n handle: key,\n lambda: () => outputFn(new PluginRenderCtx(handle, wrappedInputs)),\n withStatus: true,\n });\n }\n }\n const allOutputs = { ...this.config.outputs, ...pluginOutputs };\n\n globalThis.platformaApiVersion = apiVersion;\n\n if (!isInUI()) {\n const blockConfig: BlockConfigContainer = {\n v4: {\n configVersion: 4,\n modelAPIVersion: BLOCK_STORAGE_FACADE_VERSION,\n sdkVersion: PlatformaSDKVersion,\n renderingMode: this.config.renderingMode,\n sections: this.config.sections,\n title: this.config.title,\n subtitle: this.config.subtitle,\n tags: this.config.tags,\n outputs: allOutputs,\n enrichmentTargets: this.config.enrichmentTargets,\n featureFlags: this.config.featureFlags,\n blockLifecycleCallbacks: {\n ...BlockStorageFacadeHandles,\n ...(applyParams !== undefined\n ? {\n [BlockStorageFacadeCallbacks.StorageApplyParams]:\n BlockStorageFacadeOptionalHandles[\n BlockStorageFacadeCallbacks.StorageApplyParams\n ],\n }\n : {}),\n },\n },\n\n // Block-kind identity, baked at the container level beside `code`\n // (orthogonal to which render envelope applies). Rides into model.json\n // via the JSON.stringify(config) in build-model.ts — no write-path change.\n kind: this.config.kind,\n\n // fields below are added to allow previous desktop versions read generated configs\n sdkVersion: PlatformaSDKVersion,\n renderingMode: this.config.renderingMode,\n sections: this.config.sections,\n outputs: Object.fromEntries(\n Object.entries(this.config.outputs).map(([key, value]) => [\n key,\n downgradeCfgOrLambda(value),\n ]),\n ),\n };\n // we are in the configuration rendering routine, not in actual UI\n return { config: blockConfig } as any;\n // normal operation inside the UI\n } else {\n return {\n ...getPlatformaInstance({\n sdkVersion: PlatformaSDKVersion,\n apiVersion,\n }),\n blockModelInfo: {\n outputs: Object.fromEntries(\n Object.entries(allOutputs).map(([key, value]) => [\n key,\n {\n withStatus: Boolean(isConfigLambda(value) && value.withStatus),\n },\n ]),\n ),\n pluginIds: pluginHandles,\n featureFlags: this.config.featureFlags,\n pluginPublicOutputs: Object.fromEntries(\n pluginHandles.map((handle) => [handle, plugins[handle].model.publicOutputDef]),\n ),\n },\n } as any;\n }\n }\n}\n\n// Type tests for BlockModelV3\n\nexport type Expect<T extends true> = T;\n\nexport type Equal<X, Y> =\n (<T>() => T extends X ? 1 : 2) extends <T>() => T extends Y ? 1 : 2 ? true : false;\n\nexport type Merge<A, B> = {\n [K in keyof A | keyof B]: K extends keyof B ? B[K] : K extends keyof A ? A[K] : never;\n};\n\n// Helper types for testing\ntype _TestArgs = { inputFile: string; threshold: number };\ntype _TestData = { selectedTab: string };\ntype _TestOutputs = {\n result: ConfigRenderLambda<string>;\n count: ConfigRenderLambda<number>;\n};\n\n// Test: Merge type works correctly\ntype _MergeTest1 = Expect<Equal<Merge<{ a: 1 }, { b: 2 }>, { a: 1; b: 2 }>>;\ntype _MergeTest2 = Expect<Equal<Merge<{ a: 1 }, { a: 2 }>, { a: 2 }>>;\ntype _MergeTest3 = Expect<Equal<Merge<{ a: 1; b: 1 }, { b: 2; c: 3 }>, { a: 1; b: 2; c: 3 }>>;\n\n// Test: create() returns a BlockModelV3 instance\n// Note: Due to function overloads, ReturnType uses the last overload signature.\n// We verify the structure is correct using a simpler assignability test.\ntype _CreateResult = ReturnType<typeof BlockModelV3.create>;\ntype _CreateIsBlockModelV3 =\n _CreateResult extends BlockModelV3<infer _A, infer _O, infer _S> ? true : false;\ntype _CreateTest = Expect<_CreateIsBlockModelV3>;\n\n// Test: BlockModelV3Config interface structure (default generics)\ntype _ConfigTest = Expect<\n Equal<\n BlockModelV3Config<_TestOutputs, _TestData>,\n {\n renderingMode: BlockRenderingMode;\n deriveArgs: ((data: unknown) => unknown) | undefined;\n argsIssues: ((input: { args: unknown; data: unknown }) => ArgsIssue[]) | undefined;\n derivePrerunArgs: ((data: unknown) => unknown) | undefined;\n prerunArgsIssues:\n | ((input: { prerunArgs: unknown; data: unknown }) => ArgsIssue[])\n | undefined;\n deriveTemplateParams: ((data: _TestData) => unknown) | undefined;\n applyParams: ((data: _TestData, params: unknown) => _TestData) | undefined;\n parseInitializationParams: (value: unknown) => unknown;\n dataModel: DataModel<_TestData, unknown, {}>;\n kind: BlockKindReference | undefined;\n outputs: _TestOutputs;\n sections: ConfigRenderLambda;\n title: ConfigRenderLambda | undefined;\n subtitle: ConfigRenderLambda | undefined;\n tags: ConfigRenderLambda | undefined;\n enrichmentTargets: ConfigRenderLambda | undefined;\n featureFlags: BlockCodeKnownFeatureFlags;\n plugins: {};\n }\n >\n>;\n\n// Test: Default Href is '/'\ntype _HrefDefaultTest =\n BlockModelV3<_TestArgs, {}, _TestData> extends BlockModelV3<_TestArgs, {}, _TestData, \"/\">\n ? true\n : false;\ntype _VerifyHrefDefault = Expect<_HrefDefaultTest>;\n\n// Test: Custom Href can be specified\ntype _CustomHref = \"/settings\" | \"/main\";\ntype _HrefCustomBuilder = BlockModelV3<_TestArgs, {}, _TestData, _CustomHref>;\ntype _HrefCustomTest =\n _HrefCustomBuilder extends BlockModelV3<_TestArgs, {}, _TestData, _CustomHref> ? true : false;\ntype _VerifyHrefCustom = Expect<_HrefCustomTest>;\n\n// Test: Output type accumulation with & intersection\ntype _OutputsAccumulation = { a: ConfigRenderLambda<string> } & {\n b: ConfigRenderLambda<number>;\n};\ntype _VerifyOutputsHaveKeys = Expect<Equal<keyof _OutputsAccumulation, \"a\" | \"b\">>;\n\n// Test: Builder with all type parameters specified compiles\ntype _FullBuilder = BlockModelV3<_TestArgs, _TestOutputs, _TestData, \"/main\">;\ntype _FullBuilderTest =\n _FullBuilder extends BlockModelV3<_TestArgs, _TestOutputs, _TestData, \"/main\"> ? true : false;\ntype _VerifyFullBuilder = Expect<_FullBuilderTest>;\n\n// Test: InferOutputsFromLambdas maps outputs correctly\ntype _InferOutputsTest = InferOutputsFromLambdas<{\n myOutput: ConfigRenderLambda<number>;\n}>;\ntype _VerifyInferOutputs = Expect<\n Equal<_InferOutputsTest, { myOutput: OutputWithStatus<number> & { __unwrap: true } }>\n>;\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAgFA,SAAS,kBACP,MACA,UAC4B;CAC5B,MAAM,SAAuD,EAAE,GAAG,KAAK;CACvE,KAAK,MAAM,CAAC,KAAK,UAAU,OAAO,QAAQ,QAAQ,GAAG;EACnD,IAAI,UAAU,KAAA,GAAW;EACzB,MAAM,WAAW,OAAO;EACxB,IAAI,OAAO,UAAU,WACnB,OAAO,OAAQ,OAAO,aAAa,aAAa,YAAa;OACxD,IAAI,OAAO,UAAU,UAC1B,OAAO,OAAO,KAAK,IAAI,OAAO,aAAa,WAAW,WAAW,GAAG,KAAK;CAE7E;CACA,OAAO;AACT;;;;;AA4DA,IAAa,eAAb,MAAa,aASX;CAEmB;CADnB,YACE,QACA;EADiB,KAAA,SAAA;CAChB;CAEH,OAAuB,gBAAgB;EACrC,mBAAmB;EACnB,4BAA4B;EAC5B,qBAAqB;EACrB,sBAAsB;EACtB,yBAAA;EACA,sBAAsB;EACtB,wBAAwBA,gCAAAA;EACxB,oBAAoB;EACpB,GAAGC,uBAAAA;CACL;;CAGA,OAAuB,8BAA8B,aAAa;;;;;;;;;;;;;;;;;;;;CAqBlE,OAAc,OAIZ,MAG2D;EAC3D,MAAM,EAAE,WAAW,SAAS;EAG5B,MAAM,WAAA,GAAUC,gCAAAA,cAAAA,CAAc,IAAI;EAOlC,IAAI,UAAU,WAAW,UAAU,YAAY,SAC7C,MAAM,IAAI,MACR,8CAA8C,UAAU,QAAQ,sBAAsB,QAAQ,EAChG;EAGF,OAAO,IAAI,aAAyD;GAClE,eAAe;GACf;GACA,MAAM;GAGN,2BAA2B,KAAK;GAChC,SAAS,CAAC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;KACvB,GAAGC,6BAAAA;KACH,GAAI,gBAAgB,KAAA,IAChB,GACGf,6BAAAA,4BAA4B,qBAC3BgB,6BAAAA,kCACEhB,6BAAAA,4BAA4B,oBAElC,IACA,CAAC;IACP;GACF;GAKA,MAAM,KAAK,OAAO;GAGlB,YAAYc,gBAAAA;GACZ,eAAe,KAAK,OAAO;GAC3B,UAAU,KAAK,OAAO;GACtB,SAAS,OAAO,YACd,OAAO,QAAQ,KAAK,OAAO,OAAO,CAAC,CAAC,KAAK,CAAC,KAAK,WAAW,CACxD,KACAG,sBAAAA,qBAAqB,KAAK,CAC5B,CAAC,CACH;EAGyB,EAAE;OAG7B,OAAO;GACL,GAAGC,iBAAAA,qBAAqB;IACtB,YAAYJ,gBAAAA;IACZ;GACF,CAAC;GACD,gBAAgB;IACd,SAAS,OAAO,YACd,OAAO,QAAQ,UAAU,CAAC,CAAC,KAAK,CAAC,KAAK,WAAW,CAC/C,KACA,EACE,YAAY,QAAQK,cAAAA,eAAe,KAAK,KAAK,MAAM,UAAU,EAC/D,CACF,CAAC,CACH;IACA,WAAW;IACX,cAAc,KAAK,OAAO;IAC1B,qBAAqB,OAAO,YAC1B,cAAc,KAAK,WAAW,CAAC,QAAQ,QAAQ,OAAO,CAAC,MAAM,eAAe,CAAC,CAC/E;GACF;EACF;CAEJ;AACF"}
|
package/dist/block_model.d.ts
CHANGED
|
@@ -210,8 +210,9 @@ export declare class BlockModelV3<Args, OutputsCfg extends Record<string, Config
|
|
|
210
210
|
* Sets the function that projects block data back to this kind's params, for
|
|
211
211
|
* exporting the project as a template.
|
|
212
212
|
*
|
|
213
|
-
* The inverse of
|
|
214
|
-
* recovers the `params` that would rebuild the
|
|
213
|
+
* The inverse of how params become data — {@link applyParams} when the block declares it,
|
|
214
|
+
* the data model's `init` otherwise: this recovers the `params` that would rebuild the
|
|
215
|
+
* current data. Return only params
|
|
215
216
|
* — runtime and derived state is dropped, and the exporter supplies the rest of
|
|
216
217
|
* the entry (`id`, `kind`), which this lambda cannot set.
|
|
217
218
|
*
|
|
@@ -235,6 +236,67 @@ export declare class BlockModelV3<Args, OutputsCfg extends Record<string, Config
|
|
|
235
236
|
* .done();
|
|
236
237
|
*/
|
|
237
238
|
templateParams(fn: (data: Data) => Params): BlockModelV3<Args, OutputsCfg, Data, Href, Plugins, Transfers, Params, PrerunArgs>;
|
|
239
|
+
/**
|
|
240
|
+
* Sets the function that puts this kind's params onto live block data: the data the block
|
|
241
|
+
* would have, were it configured with `params`. Together with {@link templateParams} it is a
|
|
242
|
+
* pair — `templateParams` projects data onto params, `applyParams` writes params back onto data.
|
|
243
|
+
*
|
|
244
|
+
* Everything the params describe is written from `params`; everything they do not describe
|
|
245
|
+
* (files, per-item values, view state, edits made in the UI) is kept from `data`.
|
|
246
|
+
*
|
|
247
|
+
* Declaring it makes it the one way params become data. Data built from params (template
|
|
248
|
+
* apply, creation with params) is `applyParams(defaults, params)`, `defaults` being the data
|
|
249
|
+
* model's default data (its `init` called without params); a write of params onto an existing
|
|
250
|
+
* block (the MCP `set_block_params`) is `applyParams(current, params)`. Both run after the
|
|
251
|
+
* kind's parser has accepted the params. Without it, data from params is the data model's
|
|
252
|
+
* `init` called with them, as before.
|
|
253
|
+
*
|
|
254
|
+
* Params are whole, not a patch: a key absent from `params` is the kind's "unset", and
|
|
255
|
+
* `applyParams` writes that into the data rather than leaving the old value.
|
|
256
|
+
*
|
|
257
|
+
* Laws the block keeps:
|
|
258
|
+
* - `templateParams(applyParams(d, p))` equals `templateParams(applyParams(defaults, p))` for
|
|
259
|
+
* any data `d` (the projection may leave out what does not travel, such as files);
|
|
260
|
+
* - `applyParams(d, templateParams(d))` equals `d`.
|
|
261
|
+
* The middle layer checks the first on every write of params and refuses one that breaks it.
|
|
262
|
+
*
|
|
263
|
+
* A shallow spread such as `({ ...data, ...params })` is usually wrong. It overwrites whole
|
|
264
|
+
* values the params describe only in part — a list of items replaces the items in data along
|
|
265
|
+
* with their files and view state — and it leaves in place what a key absent from `params`
|
|
266
|
+
* should unset. Write each field the params describe, and match list items by their id.
|
|
267
|
+
*
|
|
268
|
+
* The parameter types are the kind's `Params` and the data model's data, so the function is
|
|
269
|
+
* checked against the same contract as {@link templateParams}.
|
|
270
|
+
*
|
|
271
|
+
* @example
|
|
272
|
+
* // Params: { samples: { id: string; label: string; threshold?: number }[] }
|
|
273
|
+
* // Data: { samples: { id; label; threshold; file?: ImportFileHandle; expanded: boolean }[];
|
|
274
|
+
* // tab: string }
|
|
275
|
+
* BlockModelV3.create({ dataModel, kind })
|
|
276
|
+
* .args((data) => ({ samples: data.samples }))
|
|
277
|
+
* .templateParams((data) => ({
|
|
278
|
+
* samples: data.samples.map(({ id, label, threshold }) => ({ id, label, threshold })),
|
|
279
|
+
* }))
|
|
280
|
+
* .applyParams((data, params) => {
|
|
281
|
+
* const current = new Map(data.samples.map((s) => [s.id, s]));
|
|
282
|
+
* return {
|
|
283
|
+
* ...data, // `tab` and anything else the params do not describe
|
|
284
|
+
* // The list is the params': a sample absent from them is removed.
|
|
285
|
+
* samples: params.samples.map((p) => {
|
|
286
|
+
* const kept = current.get(p.id); // per-sample state the params do not describe
|
|
287
|
+
* return {
|
|
288
|
+
* id: p.id,
|
|
289
|
+
* label: p.label,
|
|
290
|
+
* threshold: p.threshold ?? DEFAULT_THRESHOLD, // absent means unset, not unchanged
|
|
291
|
+
* file: kept?.file,
|
|
292
|
+
* expanded: kept?.expanded ?? false,
|
|
293
|
+
* };
|
|
294
|
+
* }),
|
|
295
|
+
* };
|
|
296
|
+
* })
|
|
297
|
+
* .done();
|
|
298
|
+
*/
|
|
299
|
+
applyParams(fn: (data: Data, params: Params) => Data): BlockModelV3<Args, OutputsCfg, Data, Href, Plugins, Transfers, Params, PrerunArgs>;
|
|
238
300
|
/** Sets the lambda to generate list of sections in the left block overviews panel. */
|
|
239
301
|
sections<const Ret extends SectionsExpectedType, const RF extends RenderFunction<Args, Data, Ret>>(rf: RF): BlockModelV3<Args, OutputsCfg, Data, DeriveHref<ReturnType<RF>>, Plugins, Transfers, Params, PrerunArgs>;
|
|
240
302
|
/** Sets a rendering function to derive block title, shown for the block in the left blocks-overview panel. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"block_model.d.ts","names":["PluginInstanceClass"],"sources":["../src/block_model.ts"],"mappings":";;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"block_model.d.ts","names":["PluginInstanceClass"],"sources":["../src/block_model.ts"],"mappings":";;;;;;;;;;KA0DK,gCAAgC;KAEhC,OAAO;;;;;YAMA,YAAY,QAAQ,iBAAiB,sBAC9C,WAAW,UAAU,KAAK,cAAc,OAAO,WAAW,OAAO;;;;KAM/D,oBAAoB,gBAAgB,KAAK;;;;YA2BlC,aACV,aAAa,aAAa,YAC1B,eAAe,0BACf,gBAAgB,gBAAgB,eAChC,sBAAsB,sBAAsB,qBAC5C,yBACA;WAES,OAAO,YAAY,MAAM,QAAQ,SAAS,eAAe,eAAe;WACxE,QAAQ;;;;;;qBA8CN,aACX,MACA,mBAAmB,eAAe,qBAClC,aAAa,0BAA0B,yBACvC,iCACA,gBAAgB,eAAe,oBAC/B,kBAAkB,8BAClB,kBACA;mBAGmB;UADZ;kBAIgB;;;;;;;;;;;;;;;kBAaA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;SAqBT,OACZ,aAAa,yBACb,gBACA,kBAAkB,8BAClB;IACA,WAAW,UAAU,MAAM,QAAQ;IACnC,MAAM,UAAU;MACd,aAAa,UAAU,eAAe,WAAW;;;;;;;;;EAiD9C,aAAa,0BAA0B,WAAW,eAAe,MAAM,gBAC5E,KAAK,KACL,IAAI,IACJ,OAAO;IAA4B;MAClC,aACD,MACA,gBACG,KAAK,MAAM,mBAAmB,0BAA0B;IACvD;QAGJ,MACA,MACA,SACA,WACA,QACA;;;;;;;;;EAUK,aAAa,0BAA0B,WAAW,eAAe,MAAM,gBAC5E,KAAK,KACL,IAAI,IACJ,QAAQ,0BACP,aACD,MACA,gBACG,KAAK,MAAM,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