@platforma-sdk/model 1.51.9 → 1.52.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bconfig/lambdas.d.ts +26 -4
- package/dist/bconfig/lambdas.d.ts.map +1 -1
- package/dist/bconfig/v3.d.ts +4 -2
- package/dist/bconfig/v3.d.ts.map +1 -1
- package/dist/block_api_v3.d.ts +32 -0
- package/dist/block_api_v3.d.ts.map +1 -0
- package/dist/block_migrations.cjs +138 -0
- package/dist/block_migrations.cjs.map +1 -0
- package/dist/block_migrations.d.ts +79 -0
- package/dist/block_migrations.d.ts.map +1 -0
- package/dist/block_migrations.js +136 -0
- package/dist/block_migrations.js.map +1 -0
- package/dist/block_model.cjs +222 -0
- package/dist/block_model.cjs.map +1 -0
- package/dist/block_model.d.ts +132 -0
- package/dist/block_model.d.ts.map +1 -0
- package/dist/block_model.js +220 -0
- package/dist/block_model.js.map +1 -0
- package/dist/block_storage.cjs +244 -0
- package/dist/block_storage.cjs.map +1 -0
- package/dist/block_storage.d.ts +208 -0
- package/dist/block_storage.d.ts.map +1 -0
- package/dist/block_storage.js +225 -0
- package/dist/block_storage.js.map +1 -0
- package/dist/block_storage_vm.cjs +264 -0
- package/dist/block_storage_vm.cjs.map +1 -0
- package/dist/block_storage_vm.d.ts +67 -0
- package/dist/block_storage_vm.d.ts.map +1 -0
- package/dist/block_storage_vm.js +260 -0
- package/dist/block_storage_vm.js.map +1 -0
- package/dist/builder.cjs +9 -6
- package/dist/builder.cjs.map +1 -1
- package/dist/builder.d.ts +15 -30
- package/dist/builder.d.ts.map +1 -1
- package/dist/builder.js +10 -7
- package/dist/builder.js.map +1 -1
- package/dist/components/PFrameForGraphs.cjs.map +1 -1
- package/dist/components/PFrameForGraphs.d.ts +2 -2
- package/dist/components/PFrameForGraphs.d.ts.map +1 -1
- package/dist/components/PFrameForGraphs.js.map +1 -1
- package/dist/components/PlDataTable.cjs.map +1 -1
- package/dist/components/PlDataTable.d.ts +3 -3
- package/dist/components/PlDataTable.d.ts.map +1 -1
- package/dist/components/PlDataTable.js.map +1 -1
- package/dist/index.cjs +25 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -1
- package/dist/index.js.map +1 -1
- package/dist/internal.cjs +38 -0
- package/dist/internal.cjs.map +1 -1
- package/dist/internal.d.ts +21 -0
- package/dist/internal.d.ts.map +1 -1
- package/dist/internal.js +36 -1
- package/dist/internal.js.map +1 -1
- package/dist/package.json.cjs +1 -1
- package/dist/package.json.js +1 -1
- package/dist/pframe_utils/columns.cjs.map +1 -1
- package/dist/pframe_utils/columns.d.ts +3 -3
- package/dist/pframe_utils/columns.d.ts.map +1 -1
- package/dist/pframe_utils/columns.js.map +1 -1
- package/dist/platforma.d.ts +18 -3
- package/dist/platforma.d.ts.map +1 -1
- package/dist/render/api.cjs +43 -16
- package/dist/render/api.cjs.map +1 -1
- package/dist/render/api.d.ts +19 -7
- package/dist/render/api.d.ts.map +1 -1
- package/dist/render/api.js +42 -17
- package/dist/render/api.js.map +1 -1
- package/dist/render/internal.cjs.map +1 -1
- package/dist/render/internal.d.ts +3 -1
- package/dist/render/internal.d.ts.map +1 -1
- package/dist/render/internal.js.map +1 -1
- package/package.json +7 -7
- package/src/bconfig/lambdas.ts +35 -4
- package/src/bconfig/v3.ts +12 -2
- package/src/block_api_v3.ts +49 -0
- package/src/block_migrations.ts +173 -0
- package/src/block_model.ts +440 -0
- package/src/block_storage.test.ts +258 -0
- package/src/block_storage.ts +365 -0
- package/src/block_storage_vm.ts +349 -0
- package/src/builder.ts +24 -59
- package/src/components/PFrameForGraphs.ts +2 -2
- package/src/components/PlDataTable.ts +3 -3
- package/src/index.ts +3 -0
- package/src/internal.ts +51 -0
- package/src/pframe_utils/columns.ts +3 -3
- package/src/platforma.ts +31 -5
- package/src/render/api.ts +52 -21
- package/src/render/internal.ts +3 -1
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var internal = require('./internal.cjs');
|
|
4
|
+
var api = require('./render/api.cjs');
|
|
5
|
+
require('@milaboratories/pl-model-common');
|
|
6
|
+
require('./render/util/label.cjs');
|
|
7
|
+
require('canonicalize');
|
|
8
|
+
var version = require('./version.cjs');
|
|
9
|
+
require('./block_storage_vm.cjs');
|
|
10
|
+
var normalization = require('./bconfig/normalization.cjs');
|
|
11
|
+
var types = require('./bconfig/types.cjs');
|
|
12
|
+
|
|
13
|
+
/** Main entry point that each block should use in it's "config" module. Don't forget
|
|
14
|
+
* to call {@link done()} at the end of configuration. Value returned by this builder must be
|
|
15
|
+
* exported as constant with name "platforma" from the "config" module.
|
|
16
|
+
* API version is 3 (for UI) and 2 (for model) */
|
|
17
|
+
class BlockModelV3 {
|
|
18
|
+
config;
|
|
19
|
+
constructor(config) {
|
|
20
|
+
this.config = config;
|
|
21
|
+
}
|
|
22
|
+
static INITIAL_BLOCK_FEATURE_FLAGS = {
|
|
23
|
+
supportsLazyState: true,
|
|
24
|
+
requiresUIAPIVersion: 3,
|
|
25
|
+
requiresModelAPIVersion: 2,
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* Creates a new BlockModelV3 builder with the specified data model and options.
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* const dataModel = DataModel.create<BlockData>(() => ({ numbers: [], labels: [] }));
|
|
32
|
+
* BlockModelV3.create({ dataModel })
|
|
33
|
+
* .args((data) => ({ numbers: data.numbers }))
|
|
34
|
+
* .sections(() => [{ type: 'link', href: '/', label: 'Main' }])
|
|
35
|
+
* .done();
|
|
36
|
+
*
|
|
37
|
+
* @param options Configuration options including required data model
|
|
38
|
+
*/
|
|
39
|
+
static create(options) {
|
|
40
|
+
const { dataModel, renderingMode = 'Heavy' } = options;
|
|
41
|
+
// Register data model callbacks for VM use (initialData and upgrade)
|
|
42
|
+
dataModel.registerCallbacks();
|
|
43
|
+
return new BlockModelV3({
|
|
44
|
+
renderingMode,
|
|
45
|
+
dataModel,
|
|
46
|
+
outputs: {},
|
|
47
|
+
// Register default sections callback (returns empty array)
|
|
48
|
+
sections: internal.createAndRegisterRenderLambda({ handle: 'sections', lambda: () => [] }, true),
|
|
49
|
+
title: undefined,
|
|
50
|
+
subtitle: undefined,
|
|
51
|
+
tags: undefined,
|
|
52
|
+
enrichmentTargets: undefined,
|
|
53
|
+
featureFlags: { ...BlockModelV3.INITIAL_BLOCK_FEATURE_FLAGS },
|
|
54
|
+
args: undefined,
|
|
55
|
+
prerunArgs: undefined,
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
output(key, cfgOrRf, flags = {}) {
|
|
59
|
+
return new BlockModelV3({
|
|
60
|
+
...this.config,
|
|
61
|
+
outputs: {
|
|
62
|
+
...this.config.outputs,
|
|
63
|
+
[key]: internal.createAndRegisterRenderLambda({ handle: `output#${key}`, lambda: () => cfgOrRf(new api.RenderCtx()), ...flags }),
|
|
64
|
+
},
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
/** Shortcut for {@link output} with retentive flag set to true. */
|
|
68
|
+
retentiveOutput(key, rf) {
|
|
69
|
+
return this.output(key, rf, { retentive: true });
|
|
70
|
+
}
|
|
71
|
+
/** Shortcut for {@link output} with withStatus flag set to true. */
|
|
72
|
+
outputWithStatus(key, rf) {
|
|
73
|
+
return this.output(key, rf, { withStatus: true });
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Sets a function to derive block args from data.
|
|
77
|
+
* This is called during setData to compute the args that will be used for block execution.
|
|
78
|
+
*
|
|
79
|
+
* @example
|
|
80
|
+
* .args<BlockArgs>((data) => ({ numbers: data.numbers }))
|
|
81
|
+
*
|
|
82
|
+
* @example
|
|
83
|
+
* .args<BlockArgs>((data) => {
|
|
84
|
+
* if (data.numbers.length === 0) throw new Error('Numbers required'); // block not ready
|
|
85
|
+
* return { numbers: data.numbers };
|
|
86
|
+
* })
|
|
87
|
+
*/
|
|
88
|
+
args(lambda) {
|
|
89
|
+
return new BlockModelV3({
|
|
90
|
+
...this.config,
|
|
91
|
+
args: internal.createAndRegisterRenderLambda({ handle: 'args', lambda }),
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Sets a function to derive pre-run args from data (optional).
|
|
96
|
+
* This is called during setData to compute the args that will be used for staging/pre-run phase.
|
|
97
|
+
*
|
|
98
|
+
* If not defined, defaults to using the args() function result.
|
|
99
|
+
* If defined, uses its return value for the staging / prerun phase.
|
|
100
|
+
*
|
|
101
|
+
* The staging / prerun phase runs only if currentPrerunArgs differs from the executed
|
|
102
|
+
* version of prerunArgs (same comparison logic as currentArgs vs prodArgs).
|
|
103
|
+
*
|
|
104
|
+
* @example
|
|
105
|
+
* .prerunArgs((data) => ({ numbers: data.numbers }))
|
|
106
|
+
*
|
|
107
|
+
* @example
|
|
108
|
+
* .prerunArgs((data) => {
|
|
109
|
+
* // Return undefined to skip staging for this block
|
|
110
|
+
* if (!data.isReady) return undefined;
|
|
111
|
+
* return { numbers: data.numbers };
|
|
112
|
+
* })
|
|
113
|
+
*/
|
|
114
|
+
prerunArgs(fn) {
|
|
115
|
+
return new BlockModelV3({
|
|
116
|
+
...this.config,
|
|
117
|
+
prerunArgs: internal.createAndRegisterRenderLambda({ handle: 'prerunArgs', lambda: fn }),
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
/** Sets the lambda to generate list of sections in the left block overviews panel. */
|
|
121
|
+
sections(rf) {
|
|
122
|
+
return new BlockModelV3({
|
|
123
|
+
...this.config,
|
|
124
|
+
// Replace the default sections callback with the user-provided one
|
|
125
|
+
sections: internal.createAndRegisterRenderLambda({ handle: 'sections', lambda: () => rf(new api.RenderCtx()) }, true),
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
/** Sets a rendering function to derive block title, shown for the block in the left blocks-overview panel. */
|
|
129
|
+
title(rf) {
|
|
130
|
+
return new BlockModelV3({
|
|
131
|
+
...this.config,
|
|
132
|
+
title: internal.createAndRegisterRenderLambda({ handle: 'title', lambda: () => rf(new api.RenderCtx()) }),
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
subtitle(rf) {
|
|
136
|
+
return new BlockModelV3({
|
|
137
|
+
...this.config,
|
|
138
|
+
subtitle: internal.createAndRegisterRenderLambda({ handle: 'subtitle', lambda: () => rf(new api.RenderCtx()) }),
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
tags(rf) {
|
|
142
|
+
return new BlockModelV3({
|
|
143
|
+
...this.config,
|
|
144
|
+
tags: internal.createAndRegisterRenderLambda({ handle: 'tags', lambda: () => rf(new api.RenderCtx()) }),
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
/** Sets or overrides feature flags for the block. */
|
|
148
|
+
withFeatureFlags(flags) {
|
|
149
|
+
return new BlockModelV3({
|
|
150
|
+
...this.config,
|
|
151
|
+
featureFlags: { ...this.config.featureFlags, ...flags },
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* Defines how to derive list of upstream references this block is meant to enrich with its exports from block args.
|
|
156
|
+
* Influences dependency graph construction.
|
|
157
|
+
*/
|
|
158
|
+
enriches(lambda) {
|
|
159
|
+
return new BlockModelV3({
|
|
160
|
+
...this.config,
|
|
161
|
+
enrichmentTargets: internal.createAndRegisterRenderLambda({ handle: 'enrichmentTargets', lambda: lambda }),
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
/** Renders all provided block settings into a pre-configured platforma API
|
|
165
|
+
* instance, that can be used in frontend to interact with block data, and
|
|
166
|
+
* other features provided by the platforma to the block. */
|
|
167
|
+
done() {
|
|
168
|
+
return this.withFeatureFlags({
|
|
169
|
+
...this.config.featureFlags,
|
|
170
|
+
})._done();
|
|
171
|
+
}
|
|
172
|
+
_done() {
|
|
173
|
+
if (this.config.args === undefined)
|
|
174
|
+
throw new Error('Args rendering function not set.');
|
|
175
|
+
const apiVersion = 3;
|
|
176
|
+
const migrationCount = this.config.dataModel.migrationCount;
|
|
177
|
+
const blockConfig = {
|
|
178
|
+
v4: {
|
|
179
|
+
configVersion: 4,
|
|
180
|
+
modelAPIVersion: 2,
|
|
181
|
+
sdkVersion: version.PlatformaSDKVersion,
|
|
182
|
+
renderingMode: this.config.renderingMode,
|
|
183
|
+
args: this.config.args,
|
|
184
|
+
prerunArgs: this.config.prerunArgs,
|
|
185
|
+
// Reference to __pl_data_initial callback registered by DataModel
|
|
186
|
+
initialData: internal.createRenderLambda({ handle: '__pl_data_initial' }),
|
|
187
|
+
sections: this.config.sections,
|
|
188
|
+
title: this.config.title,
|
|
189
|
+
outputs: this.config.outputs,
|
|
190
|
+
enrichmentTargets: this.config.enrichmentTargets,
|
|
191
|
+
featureFlags: this.config.featureFlags,
|
|
192
|
+
// Generate migration descriptors (indices for metadata)
|
|
193
|
+
migrations: migrationCount > 0
|
|
194
|
+
? Array.from({ length: migrationCount }, (_, i) => ({ index: i }))
|
|
195
|
+
: undefined,
|
|
196
|
+
},
|
|
197
|
+
// fields below are added to allow previous desktop versions read generated configs
|
|
198
|
+
sdkVersion: version.PlatformaSDKVersion,
|
|
199
|
+
renderingMode: this.config.renderingMode,
|
|
200
|
+
sections: this.config.sections,
|
|
201
|
+
outputs: Object.fromEntries(Object.entries(this.config.outputs).map(([key, value]) => [key, normalization.downgradeCfgOrLambda(value)])),
|
|
202
|
+
};
|
|
203
|
+
globalThis.platformaApiVersion = apiVersion;
|
|
204
|
+
if (!internal.isInUI())
|
|
205
|
+
// we are in the configuration rendering routine, not in actual UI
|
|
206
|
+
return { config: blockConfig };
|
|
207
|
+
// normal operation inside the UI
|
|
208
|
+
else
|
|
209
|
+
return {
|
|
210
|
+
...internal.getPlatformaInstance({ sdkVersion: version.PlatformaSDKVersion, apiVersion }),
|
|
211
|
+
blockModelInfo: {
|
|
212
|
+
outputs: Object.fromEntries(Object.entries(this.config.outputs)
|
|
213
|
+
.map(([key, value]) => [key, {
|
|
214
|
+
withStatus: Boolean(types.isConfigLambda(value) && value.withStatus),
|
|
215
|
+
}])),
|
|
216
|
+
},
|
|
217
|
+
};
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
exports.BlockModelV3 = BlockModelV3;
|
|
222
|
+
//# sourceMappingURL=block_model.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"block_model.cjs","sources":["../src/block_model.ts"],"sourcesContent":["import type {\n BlockRenderingMode,\n BlockSection,\n OutputWithStatus,\n PlRef,\n BlockCodeKnownFeatureFlags,\n BlockConfigContainer,\n} from '@milaboratories/pl-model-common';\nimport { getPlatformaInstance, isInUI, createAndRegisterRenderLambda, createRenderLambda } from './internal';\nimport type { DataModel } from './block_migrations';\nimport type { PlatformaV3 } from './platforma';\nimport type { InferRenderFunctionReturn, RenderFunction } from './render';\nimport { RenderCtx } from './render';\nimport { PlatformaSDKVersion } from './version';\n// Import storage VM integration (side-effect: registers internal callbacks)\nimport './block_storage_vm';\nimport type {\n ConfigRenderLambda,\n DeriveHref,\n ConfigRenderLambdaFlags,\n InferOutputsFromLambdas,\n} from './bconfig';\nimport {\n downgradeCfgOrLambda,\n isConfigLambda,\n} from './bconfig';\nimport type { PlatformaExtended } from './platforma';\n\ntype SectionsExpectedType = readonly BlockSection[];\n\ntype NoOb = Record<string, never>;\n\ninterface BlockModelV3Config<\n Args,\n OutputsCfg extends Record<string, ConfigRenderLambda>,\n Data,\n> {\n renderingMode: BlockRenderingMode;\n dataModel: DataModel<Data>;\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 args: ConfigRenderLambda<Args> | undefined;\n prerunArgs: ConfigRenderLambda<unknown> | undefined;\n}\n\n/** Options for creating a BlockModelV3 */\nexport interface BlockModelV3Options<Data extends Record<string, unknown>> {\n /** The data model that defines initial data and migrations */\n dataModel: DataModel<Data>;\n /** Rendering mode for the block (default: 'Heavy') */\n renderingMode?: BlockRenderingMode;\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> {\n private constructor(\n private readonly config: BlockModelV3Config<Args, OutputsCfg, Data>,\n ) {}\n\n public static readonly INITIAL_BLOCK_FEATURE_FLAGS: BlockCodeKnownFeatureFlags = {\n supportsLazyState: true,\n requiresUIAPIVersion: 3,\n requiresModelAPIVersion: 2,\n };\n\n /**\n * Creates a new BlockModelV3 builder with the specified data model and options.\n *\n * @example\n * const dataModel = DataModel.create<BlockData>(() => ({ numbers: [], labels: [] }));\n * BlockModelV3.create({ dataModel })\n * .args((data) => ({ numbers: data.numbers }))\n * .sections(() => [{ type: 'link', href: '/', label: 'Main' }])\n * .done();\n *\n * @param options Configuration options including required data model\n */\n public static create<Data extends Record<string, unknown>>(\n options: BlockModelV3Options<Data>,\n ): BlockModelV3<NoOb, {}, Data> {\n const { dataModel, renderingMode = 'Heavy' } = options;\n\n // Register data model callbacks for VM use (initialData and upgrade)\n dataModel.registerCallbacks();\n\n return new BlockModelV3<NoOb, {}, Data>({\n renderingMode,\n dataModel,\n outputs: {},\n // Register default sections callback (returns empty array)\n sections: createAndRegisterRenderLambda({ handle: 'sections', lambda: () => [] }, true),\n title: undefined,\n subtitle: undefined,\n tags: undefined,\n enrichmentTargets: undefined,\n featureFlags: { ...BlockModelV3.INITIAL_BLOCK_FEATURE_FLAGS },\n args: undefined,\n prerunArgs: undefined,\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>>(\n key: Key,\n rf: RF,\n flags: ConfigRenderLambdaFlags & { withStatus: true }\n ): BlockModelV3<\n Args,\n OutputsCfg & { [K in Key]: ConfigRenderLambda<InferRenderFunctionReturn<RF>> & { withStatus: true } },\n Data,\n Href\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>>(\n key: Key,\n rf: RF,\n flags?: ConfigRenderLambdaFlags\n ): BlockModelV3<\n Args,\n OutputsCfg & { [K in Key]: ConfigRenderLambda<InferRenderFunctionReturn<RF>> },\n Data,\n Href\n >;\n public output(\n key: string,\n cfgOrRf: RenderFunction<Args, Data>,\n flags: ConfigRenderLambdaFlags = {},\n ): BlockModelV3<Args, OutputsCfg, Data, Href> {\n return new BlockModelV3({\n ...this.config,\n outputs: {\n ...this.config.outputs,\n [key]: createAndRegisterRenderLambda({ handle: `output#${key}`, lambda: () => cfgOrRf(new RenderCtx()), ...flags }),\n },\n });\n }\n\n /** Shortcut for {@link output} with retentive flag set to true. */\n public retentiveOutput<const Key extends string, const RF extends RenderFunction<Args, Data>>(\n key: Key,\n rf: RF,\n ): BlockModelV3<\n Args,\n OutputsCfg & { [K in Key]: ConfigRenderLambda<InferRenderFunctionReturn<RF>> },\n Data,\n Href\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<const Key extends string, const RF extends RenderFunction<Args, Data>>(\n key: Key,\n rf: RF,\n ) {\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 * @example\n * .args<BlockArgs>((data) => ({ numbers: data.numbers }))\n *\n * @example\n * .args<BlockArgs>((data) => {\n * if (data.numbers.length === 0) throw new Error('Numbers required'); // block not ready\n * return { numbers: data.numbers };\n * })\n */\n public args<Args>(lambda: (data: Data) => Args): BlockModelV3<Args, OutputsCfg, Data, Href> {\n return new BlockModelV3<Args, OutputsCfg, Data, Href>({\n ...this.config,\n args: createAndRegisterRenderLambda<Args>({ handle: 'args', lambda }),\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 * @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(fn: (data: Data) => unknown): BlockModelV3<Args, OutputsCfg, Data, Href> {\n return new BlockModelV3<Args, OutputsCfg, Data, Href>({\n ...this.config,\n prerunArgs: createAndRegisterRenderLambda({ handle: 'prerunArgs', lambda: 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 >(rf: RF): BlockModelV3<Args, OutputsCfg, Data, DeriveHref<ReturnType<RF>>> {\n return new BlockModelV3<Args, OutputsCfg, Data, DeriveHref<ReturnType<RF>>>({\n ...this.config,\n // Replace the default sections callback with the user-provided one\n sections: createAndRegisterRenderLambda({ handle: 'sections', lambda: () => rf(new RenderCtx()) }, true),\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> {\n return new BlockModelV3<Args, OutputsCfg, Data, Href>({\n ...this.config,\n title: createAndRegisterRenderLambda({ handle: 'title', lambda: () => rf(new RenderCtx()) }),\n });\n }\n\n public subtitle(\n rf: RenderFunction<Args, Data, string>,\n ): BlockModelV3<Args, OutputsCfg, Data, Href> {\n return new BlockModelV3<Args, OutputsCfg, Data, Href>({\n ...this.config,\n subtitle: createAndRegisterRenderLambda({ handle: 'subtitle', lambda: () => rf(new RenderCtx()) }),\n });\n }\n\n public tags(\n rf: RenderFunction<Args, Data, string[]>,\n ): BlockModelV3<Args, OutputsCfg, Data, Href> {\n return new BlockModelV3<Args, OutputsCfg, Data, Href>({\n ...this.config,\n tags: createAndRegisterRenderLambda({ handle: 'tags', lambda: () => rf(new RenderCtx()) }),\n });\n }\n\n /** Sets or overrides feature flags for the block. */\n public withFeatureFlags(flags: Partial<BlockCodeKnownFeatureFlags>): BlockModelV3<Args, OutputsCfg, Data, Href> {\n return new BlockModelV3<Args, OutputsCfg, Data, Href>({\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> {\n return new BlockModelV3<Args, OutputsCfg, Data, Href>({\n ...this.config,\n enrichmentTargets: createAndRegisterRenderLambda({ handle: 'enrichmentTargets', lambda: lambda }),\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 public done(): PlatformaExtended<PlatformaV3<\n Args,\n InferOutputsFromLambdas<OutputsCfg>,\n Data,\n Href\n >> {\n return this.withFeatureFlags({\n ...this.config.featureFlags,\n })._done();\n }\n\n public _done(): PlatformaExtended<PlatformaV3<\n Args,\n InferOutputsFromLambdas<OutputsCfg>,\n Data,\n Href\n >> {\n if (this.config.args === undefined) throw new Error('Args rendering function not set.');\n\n const apiVersion = 3;\n\n const migrationCount = this.config.dataModel.migrationCount;\n\n const blockConfig: BlockConfigContainer = {\n v4: {\n configVersion: 4,\n modelAPIVersion: 2,\n sdkVersion: PlatformaSDKVersion,\n renderingMode: this.config.renderingMode,\n args: this.config.args,\n prerunArgs: this.config.prerunArgs,\n // Reference to __pl_data_initial callback registered by DataModel\n initialData: createRenderLambda({ handle: '__pl_data_initial' }),\n sections: this.config.sections,\n title: this.config.title,\n outputs: this.config.outputs,\n enrichmentTargets: this.config.enrichmentTargets,\n featureFlags: this.config.featureFlags,\n // Generate migration descriptors (indices for metadata)\n migrations: migrationCount > 0\n ? Array.from({ length: migrationCount }, (_, i) => ({ index: i }))\n : undefined,\n },\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]) => [key, downgradeCfgOrLambda(value)]),\n ),\n };\n\n globalThis.platformaApiVersion = apiVersion;\n\n if (!isInUI())\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 return {\n ...getPlatformaInstance({ sdkVersion: PlatformaSDKVersion, apiVersion }),\n blockModelInfo: {\n outputs: Object.fromEntries(\n Object.entries(this.config.outputs)\n .map(([key, value]) => [key, {\n withStatus: Boolean(isConfigLambda(value) && value.withStatus),\n }]),\n ),\n },\n } as any;\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 = { result: ConfigRenderLambda<string>; count: ConfigRenderLambda<number> };\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 = _CreateResult extends BlockModelV3<infer _A, infer _O, infer _S> ? true : false;\ntype _CreateTest = Expect<_CreateIsBlockModelV3>;\n\n// Test: BlockModelV3Config interface structure\ntype _ConfigTest = Expect<Equal<\n BlockModelV3Config<_TestArgs, _TestOutputs, _TestData>,\n {\n renderingMode: BlockRenderingMode;\n args: ConfigRenderLambda<_TestArgs> | undefined;\n prerunArgs: ConfigRenderLambda<unknown> | undefined;\n dataModel: DataModel<_TestData>;\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 }\n>>;\n\n// Test: Default Href is '/'\ntype _HrefDefaultTest = BlockModelV3<_TestArgs, {}, _TestData> extends BlockModelV3<_TestArgs, {}, _TestData, '/'> ? true : 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 = _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> } & { b: ConfigRenderLambda<number> };\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 = _FullBuilder extends BlockModelV3<_TestArgs, _TestOutputs, _TestData, '/main'> ? true : false;\ntype _VerifyFullBuilder = Expect<_FullBuilderTest>;\n\n// Test: InferOutputsFromLambdas maps outputs correctly\ntype _InferOutputsTest = InferOutputsFromLambdas<{ myOutput: ConfigRenderLambda<number> }>;\ntype _VerifyInferOutputs = Expect<Equal<\n _InferOutputsTest,\n { myOutput: OutputWithStatus<number> & { __unwrap: true } }\n>>;\n"],"names":["createAndRegisterRenderLambda","RenderCtx","PlatformaSDKVersion","createRenderLambda","downgradeCfgOrLambda","isInUI","getPlatformaInstance","isConfigLambda"],"mappings":";;;;;;;;;;;;AA0DA;;;AAGiD;MACpC,YAAY,CAAA;AAOJ,IAAA,MAAA;AADnB,IAAA,WAAA,CACmB,MAAkD,EAAA;QAAlD,IAAA,CAAA,MAAM,GAAN,MAAM;IACtB;IAEI,OAAgB,2BAA2B,GAA+B;AAC/E,QAAA,iBAAiB,EAAE,IAAI;AACvB,QAAA,oBAAoB,EAAE,CAAC;AACvB,QAAA,uBAAuB,EAAE,CAAC;KAC3B;AAED;;;;;;;;;;;AAWG;IACI,OAAO,MAAM,CAClB,OAAkC,EAAA;QAElC,MAAM,EAAE,SAAS,EAAE,aAAa,GAAG,OAAO,EAAE,GAAG,OAAO;;QAGtD,SAAS,CAAC,iBAAiB,EAAE;QAE7B,OAAO,IAAI,YAAY,CAAiB;YACtC,aAAa;YACb,SAAS;AACT,YAAA,OAAO,EAAE,EAAE;;AAEX,YAAA,QAAQ,EAAEA,sCAA6B,CAAC,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM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,WAAW,CACzB,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,OAAO;AAC/B,yBAAA,GAAG,CAAC,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,KAAK,CAAC,GAAG,EAAE;4BAC3B,UAAU,EAAE,OAAO,CAACK,oBAAc,CAAC,KAAK,CAAC,IAAI,KAAK,CAAC,UAAU,CAAC;AAC/D,yBAAA,CAAC,CAAC,CACN;AACF,iBAAA;aACK;IACV;;;;;"}
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import type { BlockRenderingMode, BlockSection, PlRef, BlockCodeKnownFeatureFlags } from '@milaboratories/pl-model-common';
|
|
2
|
+
import type { DataModel } from './block_migrations';
|
|
3
|
+
import type { PlatformaV3 } from './platforma';
|
|
4
|
+
import type { InferRenderFunctionReturn, RenderFunction } from './render';
|
|
5
|
+
import './block_storage_vm';
|
|
6
|
+
import type { ConfigRenderLambda, DeriveHref, ConfigRenderLambdaFlags, InferOutputsFromLambdas } from './bconfig';
|
|
7
|
+
import type { PlatformaExtended } from './platforma';
|
|
8
|
+
type SectionsExpectedType = readonly BlockSection[];
|
|
9
|
+
type NoOb = Record<string, never>;
|
|
10
|
+
/** Options for creating a BlockModelV3 */
|
|
11
|
+
export interface BlockModelV3Options<Data extends Record<string, unknown>> {
|
|
12
|
+
/** The data model that defines initial data and migrations */
|
|
13
|
+
dataModel: DataModel<Data>;
|
|
14
|
+
/** Rendering mode for the block (default: 'Heavy') */
|
|
15
|
+
renderingMode?: BlockRenderingMode;
|
|
16
|
+
}
|
|
17
|
+
/** Main entry point that each block should use in it's "config" module. Don't forget
|
|
18
|
+
* to call {@link done()} at the end of configuration. Value returned by this builder must be
|
|
19
|
+
* exported as constant with name "platforma" from the "config" module.
|
|
20
|
+
* API version is 3 (for UI) and 2 (for model) */
|
|
21
|
+
export declare class BlockModelV3<Args, OutputsCfg extends Record<string, ConfigRenderLambda>, Data extends Record<string, unknown> = Record<string, unknown>, Href extends `/${string}` = '/'> {
|
|
22
|
+
private readonly config;
|
|
23
|
+
private constructor();
|
|
24
|
+
static readonly INITIAL_BLOCK_FEATURE_FLAGS: BlockCodeKnownFeatureFlags;
|
|
25
|
+
/**
|
|
26
|
+
* Creates a new BlockModelV3 builder with the specified data model and options.
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* const dataModel = DataModel.create<BlockData>(() => ({ numbers: [], labels: [] }));
|
|
30
|
+
* BlockModelV3.create({ dataModel })
|
|
31
|
+
* .args((data) => ({ numbers: data.numbers }))
|
|
32
|
+
* .sections(() => [{ type: 'link', href: '/', label: 'Main' }])
|
|
33
|
+
* .done();
|
|
34
|
+
*
|
|
35
|
+
* @param options Configuration options including required data model
|
|
36
|
+
*/
|
|
37
|
+
static create<Data extends Record<string, unknown>>(options: BlockModelV3Options<Data>): BlockModelV3<NoOb, {}, Data>;
|
|
38
|
+
/**
|
|
39
|
+
* Add output cell wrapped with additional status information to the configuration
|
|
40
|
+
*
|
|
41
|
+
* @param key output cell name, that can be later used to retrieve the rendered value
|
|
42
|
+
* @param rf callback calculating output value using context, that allows to access
|
|
43
|
+
* workflows outputs and interact with platforma drivers
|
|
44
|
+
* @param flags additional flags that may alter lambda rendering procedure
|
|
45
|
+
* */
|
|
46
|
+
output<const Key extends string, const RF extends RenderFunction<Args, Data>>(key: Key, rf: RF, flags: ConfigRenderLambdaFlags & {
|
|
47
|
+
withStatus: true;
|
|
48
|
+
}): BlockModelV3<Args, OutputsCfg & {
|
|
49
|
+
[K in Key]: ConfigRenderLambda<InferRenderFunctionReturn<RF>> & {
|
|
50
|
+
withStatus: true;
|
|
51
|
+
};
|
|
52
|
+
}, Data, Href>;
|
|
53
|
+
/**
|
|
54
|
+
* Add output cell to the configuration
|
|
55
|
+
*
|
|
56
|
+
* @param key output cell name, that can be later used to retrieve the rendered value
|
|
57
|
+
* @param rf callback calculating output value using context, that allows to access
|
|
58
|
+
* workflows outputs and interact with platforma drivers
|
|
59
|
+
* @param flags additional flags that may alter lambda rendering procedure
|
|
60
|
+
* */
|
|
61
|
+
output<const Key extends string, const RF extends RenderFunction<Args, Data>>(key: Key, rf: RF, flags?: ConfigRenderLambdaFlags): BlockModelV3<Args, OutputsCfg & {
|
|
62
|
+
[K in Key]: ConfigRenderLambda<InferRenderFunctionReturn<RF>>;
|
|
63
|
+
}, Data, Href>;
|
|
64
|
+
/** Shortcut for {@link output} with retentive flag set to true. */
|
|
65
|
+
retentiveOutput<const Key extends string, const RF extends RenderFunction<Args, Data>>(key: Key, rf: RF): BlockModelV3<Args, OutputsCfg & {
|
|
66
|
+
[K in Key]: ConfigRenderLambda<InferRenderFunctionReturn<RF>>;
|
|
67
|
+
}, Data, Href>;
|
|
68
|
+
/** Shortcut for {@link output} with withStatus flag set to true. */
|
|
69
|
+
outputWithStatus<const Key extends string, const RF extends RenderFunction<Args, Data>>(key: Key, rf: RF): BlockModelV3<Args, OutputsCfg & { [K in Key]: ConfigRenderLambda<InferRenderFunctionReturn<RF>> & {
|
|
70
|
+
withStatus: true;
|
|
71
|
+
}; }, Data, Href>;
|
|
72
|
+
/**
|
|
73
|
+
* Sets a function to derive block args from data.
|
|
74
|
+
* This is called during setData to compute the args that will be used for block execution.
|
|
75
|
+
*
|
|
76
|
+
* @example
|
|
77
|
+
* .args<BlockArgs>((data) => ({ numbers: data.numbers }))
|
|
78
|
+
*
|
|
79
|
+
* @example
|
|
80
|
+
* .args<BlockArgs>((data) => {
|
|
81
|
+
* if (data.numbers.length === 0) throw new Error('Numbers required'); // block not ready
|
|
82
|
+
* return { numbers: data.numbers };
|
|
83
|
+
* })
|
|
84
|
+
*/
|
|
85
|
+
args<Args>(lambda: (data: Data) => Args): BlockModelV3<Args, OutputsCfg, Data, Href>;
|
|
86
|
+
/**
|
|
87
|
+
* Sets a function to derive pre-run args from data (optional).
|
|
88
|
+
* This is called during setData to compute the args that will be used for staging/pre-run phase.
|
|
89
|
+
*
|
|
90
|
+
* If not defined, defaults to using the args() function result.
|
|
91
|
+
* If defined, uses its return value for the staging / prerun phase.
|
|
92
|
+
*
|
|
93
|
+
* The staging / prerun phase runs only if currentPrerunArgs differs from the executed
|
|
94
|
+
* version of prerunArgs (same comparison logic as currentArgs vs prodArgs).
|
|
95
|
+
*
|
|
96
|
+
* @example
|
|
97
|
+
* .prerunArgs((data) => ({ numbers: data.numbers }))
|
|
98
|
+
*
|
|
99
|
+
* @example
|
|
100
|
+
* .prerunArgs((data) => {
|
|
101
|
+
* // Return undefined to skip staging for this block
|
|
102
|
+
* if (!data.isReady) return undefined;
|
|
103
|
+
* return { numbers: data.numbers };
|
|
104
|
+
* })
|
|
105
|
+
*/
|
|
106
|
+
prerunArgs(fn: (data: Data) => unknown): BlockModelV3<Args, OutputsCfg, Data, Href>;
|
|
107
|
+
/** Sets the lambda to generate list of sections in the left block overviews panel. */
|
|
108
|
+
sections<const Ret extends SectionsExpectedType, const RF extends RenderFunction<Args, Data, Ret>>(rf: RF): BlockModelV3<Args, OutputsCfg, Data, DeriveHref<ReturnType<RF>>>;
|
|
109
|
+
/** Sets a rendering function to derive block title, shown for the block in the left blocks-overview panel. */
|
|
110
|
+
title(rf: RenderFunction<Args, Data, string>): BlockModelV3<Args, OutputsCfg, Data, Href>;
|
|
111
|
+
subtitle(rf: RenderFunction<Args, Data, string>): BlockModelV3<Args, OutputsCfg, Data, Href>;
|
|
112
|
+
tags(rf: RenderFunction<Args, Data, string[]>): BlockModelV3<Args, OutputsCfg, Data, Href>;
|
|
113
|
+
/** Sets or overrides feature flags for the block. */
|
|
114
|
+
withFeatureFlags(flags: Partial<BlockCodeKnownFeatureFlags>): BlockModelV3<Args, OutputsCfg, Data, Href>;
|
|
115
|
+
/**
|
|
116
|
+
* Defines how to derive list of upstream references this block is meant to enrich with its exports from block args.
|
|
117
|
+
* Influences dependency graph construction.
|
|
118
|
+
*/
|
|
119
|
+
enriches(lambda: (args: Args) => PlRef[]): BlockModelV3<Args, OutputsCfg, Data, Href>;
|
|
120
|
+
/** Renders all provided block settings into a pre-configured platforma API
|
|
121
|
+
* instance, that can be used in frontend to interact with block data, and
|
|
122
|
+
* other features provided by the platforma to the block. */
|
|
123
|
+
done(): PlatformaExtended<PlatformaV3<Args, InferOutputsFromLambdas<OutputsCfg>, Data, Href>>;
|
|
124
|
+
_done(): PlatformaExtended<PlatformaV3<Args, InferOutputsFromLambdas<OutputsCfg>, Data, Href>>;
|
|
125
|
+
}
|
|
126
|
+
export type Expect<T extends true> = T;
|
|
127
|
+
export type Equal<X, Y> = (<T>() => T extends X ? 1 : 2) extends (<T>() => T extends Y ? 1 : 2) ? true : false;
|
|
128
|
+
export type Merge<A, B> = {
|
|
129
|
+
[K in keyof A | keyof B]: K extends keyof B ? B[K] : K extends keyof A ? A[K] : never;
|
|
130
|
+
};
|
|
131
|
+
export {};
|
|
132
|
+
//# sourceMappingURL=block_model.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"block_model.d.ts","sourceRoot":"","sources":["../src/block_model.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,kBAAkB,EAClB,YAAY,EAEZ,KAAK,EACL,0BAA0B,EAE3B,MAAM,iCAAiC,CAAC;AAEzC,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AACpD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,KAAK,EAAE,yBAAyB,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAI1E,OAAO,oBAAoB,CAAC;AAC5B,OAAO,KAAK,EACV,kBAAkB,EAClB,UAAU,EACV,uBAAuB,EACvB,uBAAuB,EACxB,MAAM,WAAW,CAAC;AAKnB,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAErD,KAAK,oBAAoB,GAAG,SAAS,YAAY,EAAE,CAAC;AAEpD,KAAK,IAAI,GAAG,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;AAoBlC,0CAA0C;AAC1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CAuDH;AAID,MAAM,MAAM,MAAM,CAAC,CAAC,SAAS,IAAI,IAAI,CAAC,CAAC;AAEvC,MAAM,MAAM,KAAK,CAAC,CAAC,EAAE,CAAC,IACpB,CAAC,CAAC,CAAC,OAAO,CAAC,SAAS,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,OAAO,CAAC,SAAS,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,GAAG,IAAI,GAAG,KAAK,CAAC;AAEvF,MAAM,MAAM,KAAK,CAAC,CAAC,EAAE,CAAC,IAAI;KACvB,CAAC,IAAI,MAAM,CAAC,GAAG,MAAM,CAAC,GAAG,CAAC,SAAS,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,SAAS,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,KAAK;CACtF,CAAC"}
|
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
import { createAndRegisterRenderLambda, createRenderLambda, isInUI, getPlatformaInstance } from './internal.js';
|
|
2
|
+
import { RenderCtx } from './render/api.js';
|
|
3
|
+
import '@milaboratories/pl-model-common';
|
|
4
|
+
import './render/util/label.js';
|
|
5
|
+
import 'canonicalize';
|
|
6
|
+
import { PlatformaSDKVersion } from './version.js';
|
|
7
|
+
import './block_storage_vm.js';
|
|
8
|
+
import { downgradeCfgOrLambda } from './bconfig/normalization.js';
|
|
9
|
+
import { isConfigLambda } from './bconfig/types.js';
|
|
10
|
+
|
|
11
|
+
/** Main entry point that each block should use in it's "config" module. Don't forget
|
|
12
|
+
* to call {@link done()} at the end of configuration. Value returned by this builder must be
|
|
13
|
+
* exported as constant with name "platforma" from the "config" module.
|
|
14
|
+
* API version is 3 (for UI) and 2 (for model) */
|
|
15
|
+
class BlockModelV3 {
|
|
16
|
+
config;
|
|
17
|
+
constructor(config) {
|
|
18
|
+
this.config = config;
|
|
19
|
+
}
|
|
20
|
+
static INITIAL_BLOCK_FEATURE_FLAGS = {
|
|
21
|
+
supportsLazyState: true,
|
|
22
|
+
requiresUIAPIVersion: 3,
|
|
23
|
+
requiresModelAPIVersion: 2,
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* Creates a new BlockModelV3 builder with the specified data model and options.
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* const dataModel = DataModel.create<BlockData>(() => ({ numbers: [], labels: [] }));
|
|
30
|
+
* BlockModelV3.create({ dataModel })
|
|
31
|
+
* .args((data) => ({ numbers: data.numbers }))
|
|
32
|
+
* .sections(() => [{ type: 'link', href: '/', label: 'Main' }])
|
|
33
|
+
* .done();
|
|
34
|
+
*
|
|
35
|
+
* @param options Configuration options including required data model
|
|
36
|
+
*/
|
|
37
|
+
static create(options) {
|
|
38
|
+
const { dataModel, renderingMode = 'Heavy' } = options;
|
|
39
|
+
// Register data model callbacks for VM use (initialData and upgrade)
|
|
40
|
+
dataModel.registerCallbacks();
|
|
41
|
+
return new BlockModelV3({
|
|
42
|
+
renderingMode,
|
|
43
|
+
dataModel,
|
|
44
|
+
outputs: {},
|
|
45
|
+
// Register default sections callback (returns empty array)
|
|
46
|
+
sections: createAndRegisterRenderLambda({ handle: 'sections', lambda: () => [] }, true),
|
|
47
|
+
title: undefined,
|
|
48
|
+
subtitle: undefined,
|
|
49
|
+
tags: undefined,
|
|
50
|
+
enrichmentTargets: undefined,
|
|
51
|
+
featureFlags: { ...BlockModelV3.INITIAL_BLOCK_FEATURE_FLAGS },
|
|
52
|
+
args: undefined,
|
|
53
|
+
prerunArgs: undefined,
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
output(key, cfgOrRf, flags = {}) {
|
|
57
|
+
return new BlockModelV3({
|
|
58
|
+
...this.config,
|
|
59
|
+
outputs: {
|
|
60
|
+
...this.config.outputs,
|
|
61
|
+
[key]: createAndRegisterRenderLambda({ handle: `output#${key}`, lambda: () => cfgOrRf(new RenderCtx()), ...flags }),
|
|
62
|
+
},
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
/** Shortcut for {@link output} with retentive flag set to true. */
|
|
66
|
+
retentiveOutput(key, rf) {
|
|
67
|
+
return this.output(key, rf, { retentive: true });
|
|
68
|
+
}
|
|
69
|
+
/** Shortcut for {@link output} with withStatus flag set to true. */
|
|
70
|
+
outputWithStatus(key, rf) {
|
|
71
|
+
return this.output(key, rf, { withStatus: true });
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Sets a function to derive block args from data.
|
|
75
|
+
* This is called during setData to compute the args that will be used for block execution.
|
|
76
|
+
*
|
|
77
|
+
* @example
|
|
78
|
+
* .args<BlockArgs>((data) => ({ numbers: data.numbers }))
|
|
79
|
+
*
|
|
80
|
+
* @example
|
|
81
|
+
* .args<BlockArgs>((data) => {
|
|
82
|
+
* if (data.numbers.length === 0) throw new Error('Numbers required'); // block not ready
|
|
83
|
+
* return { numbers: data.numbers };
|
|
84
|
+
* })
|
|
85
|
+
*/
|
|
86
|
+
args(lambda) {
|
|
87
|
+
return new BlockModelV3({
|
|
88
|
+
...this.config,
|
|
89
|
+
args: createAndRegisterRenderLambda({ handle: 'args', lambda }),
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Sets a function to derive pre-run args from data (optional).
|
|
94
|
+
* This is called during setData to compute the args that will be used for staging/pre-run phase.
|
|
95
|
+
*
|
|
96
|
+
* If not defined, defaults to using the args() function result.
|
|
97
|
+
* If defined, uses its return value for the staging / prerun phase.
|
|
98
|
+
*
|
|
99
|
+
* The staging / prerun phase runs only if currentPrerunArgs differs from the executed
|
|
100
|
+
* version of prerunArgs (same comparison logic as currentArgs vs prodArgs).
|
|
101
|
+
*
|
|
102
|
+
* @example
|
|
103
|
+
* .prerunArgs((data) => ({ numbers: data.numbers }))
|
|
104
|
+
*
|
|
105
|
+
* @example
|
|
106
|
+
* .prerunArgs((data) => {
|
|
107
|
+
* // Return undefined to skip staging for this block
|
|
108
|
+
* if (!data.isReady) return undefined;
|
|
109
|
+
* return { numbers: data.numbers };
|
|
110
|
+
* })
|
|
111
|
+
*/
|
|
112
|
+
prerunArgs(fn) {
|
|
113
|
+
return new BlockModelV3({
|
|
114
|
+
...this.config,
|
|
115
|
+
prerunArgs: createAndRegisterRenderLambda({ handle: 'prerunArgs', lambda: fn }),
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
/** Sets the lambda to generate list of sections in the left block overviews panel. */
|
|
119
|
+
sections(rf) {
|
|
120
|
+
return new BlockModelV3({
|
|
121
|
+
...this.config,
|
|
122
|
+
// Replace the default sections callback with the user-provided one
|
|
123
|
+
sections: createAndRegisterRenderLambda({ handle: 'sections', lambda: () => rf(new RenderCtx()) }, true),
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
/** Sets a rendering function to derive block title, shown for the block in the left blocks-overview panel. */
|
|
127
|
+
title(rf) {
|
|
128
|
+
return new BlockModelV3({
|
|
129
|
+
...this.config,
|
|
130
|
+
title: createAndRegisterRenderLambda({ handle: 'title', lambda: () => rf(new RenderCtx()) }),
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
subtitle(rf) {
|
|
134
|
+
return new BlockModelV3({
|
|
135
|
+
...this.config,
|
|
136
|
+
subtitle: createAndRegisterRenderLambda({ handle: 'subtitle', lambda: () => rf(new RenderCtx()) }),
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
tags(rf) {
|
|
140
|
+
return new BlockModelV3({
|
|
141
|
+
...this.config,
|
|
142
|
+
tags: createAndRegisterRenderLambda({ handle: 'tags', lambda: () => rf(new RenderCtx()) }),
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
/** Sets or overrides feature flags for the block. */
|
|
146
|
+
withFeatureFlags(flags) {
|
|
147
|
+
return new BlockModelV3({
|
|
148
|
+
...this.config,
|
|
149
|
+
featureFlags: { ...this.config.featureFlags, ...flags },
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Defines how to derive list of upstream references this block is meant to enrich with its exports from block args.
|
|
154
|
+
* Influences dependency graph construction.
|
|
155
|
+
*/
|
|
156
|
+
enriches(lambda) {
|
|
157
|
+
return new BlockModelV3({
|
|
158
|
+
...this.config,
|
|
159
|
+
enrichmentTargets: createAndRegisterRenderLambda({ handle: 'enrichmentTargets', lambda: lambda }),
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
/** Renders all provided block settings into a pre-configured platforma API
|
|
163
|
+
* instance, that can be used in frontend to interact with block data, and
|
|
164
|
+
* other features provided by the platforma to the block. */
|
|
165
|
+
done() {
|
|
166
|
+
return this.withFeatureFlags({
|
|
167
|
+
...this.config.featureFlags,
|
|
168
|
+
})._done();
|
|
169
|
+
}
|
|
170
|
+
_done() {
|
|
171
|
+
if (this.config.args === undefined)
|
|
172
|
+
throw new Error('Args rendering function not set.');
|
|
173
|
+
const apiVersion = 3;
|
|
174
|
+
const migrationCount = this.config.dataModel.migrationCount;
|
|
175
|
+
const blockConfig = {
|
|
176
|
+
v4: {
|
|
177
|
+
configVersion: 4,
|
|
178
|
+
modelAPIVersion: 2,
|
|
179
|
+
sdkVersion: PlatformaSDKVersion,
|
|
180
|
+
renderingMode: this.config.renderingMode,
|
|
181
|
+
args: this.config.args,
|
|
182
|
+
prerunArgs: this.config.prerunArgs,
|
|
183
|
+
// Reference to __pl_data_initial callback registered by DataModel
|
|
184
|
+
initialData: createRenderLambda({ handle: '__pl_data_initial' }),
|
|
185
|
+
sections: this.config.sections,
|
|
186
|
+
title: this.config.title,
|
|
187
|
+
outputs: this.config.outputs,
|
|
188
|
+
enrichmentTargets: this.config.enrichmentTargets,
|
|
189
|
+
featureFlags: this.config.featureFlags,
|
|
190
|
+
// Generate migration descriptors (indices for metadata)
|
|
191
|
+
migrations: migrationCount > 0
|
|
192
|
+
? Array.from({ length: migrationCount }, (_, i) => ({ index: i }))
|
|
193
|
+
: undefined,
|
|
194
|
+
},
|
|
195
|
+
// fields below are added to allow previous desktop versions read generated configs
|
|
196
|
+
sdkVersion: PlatformaSDKVersion,
|
|
197
|
+
renderingMode: this.config.renderingMode,
|
|
198
|
+
sections: this.config.sections,
|
|
199
|
+
outputs: Object.fromEntries(Object.entries(this.config.outputs).map(([key, value]) => [key, downgradeCfgOrLambda(value)])),
|
|
200
|
+
};
|
|
201
|
+
globalThis.platformaApiVersion = apiVersion;
|
|
202
|
+
if (!isInUI())
|
|
203
|
+
// we are in the configuration rendering routine, not in actual UI
|
|
204
|
+
return { config: blockConfig };
|
|
205
|
+
// normal operation inside the UI
|
|
206
|
+
else
|
|
207
|
+
return {
|
|
208
|
+
...getPlatformaInstance({ sdkVersion: PlatformaSDKVersion, apiVersion }),
|
|
209
|
+
blockModelInfo: {
|
|
210
|
+
outputs: Object.fromEntries(Object.entries(this.config.outputs)
|
|
211
|
+
.map(([key, value]) => [key, {
|
|
212
|
+
withStatus: Boolean(isConfigLambda(value) && value.withStatus),
|
|
213
|
+
}])),
|
|
214
|
+
},
|
|
215
|
+
};
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
export { BlockModelV3 };
|
|
220
|
+
//# sourceMappingURL=block_model.js.map
|