@platforma-sdk/model 1.81.1 → 1.83.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (89) hide show
  1. package/dist/bconfig/index.d.ts +2 -2
  2. package/dist/bconfig/lambdas.d.ts +2 -12
  3. package/dist/bconfig/lambdas.d.ts.map +1 -1
  4. package/dist/bconfig/v3.d.ts +1 -1
  5. package/dist/block_migrations.cjs +92 -8
  6. package/dist/block_migrations.cjs.map +1 -1
  7. package/dist/block_migrations.d.ts +121 -32
  8. package/dist/block_migrations.d.ts.map +1 -1
  9. package/dist/block_migrations.js +92 -8
  10. package/dist/block_migrations.js.map +1 -1
  11. package/dist/block_model.cjs +71 -17
  12. package/dist/block_model.cjs.map +1 -1
  13. package/dist/block_model.d.ts +58 -22
  14. package/dist/block_model.d.ts.map +1 -1
  15. package/dist/block_model.js +72 -18
  16. package/dist/block_model.js.map +1 -1
  17. package/dist/block_storage_callbacks.cjs +194 -13
  18. package/dist/block_storage_callbacks.cjs.map +1 -1
  19. package/dist/block_storage_callbacks.js +192 -15
  20. package/dist/block_storage_callbacks.js.map +1 -1
  21. package/dist/block_storage_facade.cjs +4 -1
  22. package/dist/block_storage_facade.cjs.map +1 -1
  23. package/dist/block_storage_facade.d.ts +102 -0
  24. package/dist/block_storage_facade.d.ts.map +1 -1
  25. package/dist/block_storage_facade.js +4 -1
  26. package/dist/block_storage_facade.js.map +1 -1
  27. package/dist/config/index.d.ts +2 -6
  28. package/dist/config/type_engine.d.ts +7 -28
  29. package/dist/config/type_engine.d.ts.map +1 -1
  30. package/dist/index.cjs +20 -60
  31. package/dist/index.d.ts +5 -11
  32. package/dist/index.js +4 -8
  33. package/dist/package.cjs +1 -1
  34. package/dist/package.js +1 -1
  35. package/dist/render/api.cjs +0 -22
  36. package/dist/render/api.cjs.map +1 -1
  37. package/dist/render/api.d.ts +1 -9
  38. package/dist/render/api.d.ts.map +1 -1
  39. package/dist/render/api.js +1 -22
  40. package/dist/render/api.js.map +1 -1
  41. package/dist/render/index.cjs +0 -1
  42. package/dist/render/index.d.ts +2 -2
  43. package/dist/render/index.js +2 -2
  44. package/package.json +10 -9
  45. package/src/bconfig/lambdas.ts +1 -25
  46. package/src/block_migrations.ts +205 -55
  47. package/src/block_model.ts +190 -59
  48. package/src/block_storage_callbacks.ts +294 -15
  49. package/src/block_storage_facade.ts +95 -0
  50. package/src/config/index.ts +0 -4
  51. package/src/config/type_engine.ts +6 -49
  52. package/src/index.ts +0 -2
  53. package/src/kind_reference.test.ts +134 -0
  54. package/src/render/api.ts +0 -32
  55. package/src/template_init.test.ts +413 -0
  56. package/src/template_params.test.ts +135 -0
  57. package/src/typing.test.ts +4 -143
  58. package/dist/block_model_legacy.cjs +0 -240
  59. package/dist/block_model_legacy.cjs.map +0 -1
  60. package/dist/block_model_legacy.d.ts +0 -115
  61. package/dist/block_model_legacy.d.ts.map +0 -1
  62. package/dist/block_model_legacy.js +0 -240
  63. package/dist/block_model_legacy.js.map +0 -1
  64. package/dist/config/actions.cjs +0 -232
  65. package/dist/config/actions.cjs.map +0 -1
  66. package/dist/config/actions.d.ts +0 -48
  67. package/dist/config/actions.d.ts.map +0 -1
  68. package/dist/config/actions.js +0 -201
  69. package/dist/config/actions.js.map +0 -1
  70. package/dist/config/actions_kinds.d.ts +0 -116
  71. package/dist/config/actions_kinds.d.ts.map +0 -1
  72. package/dist/config/index.cjs +0 -33
  73. package/dist/config/index.js +0 -2
  74. package/dist/config/model_meta.d.ts +0 -9
  75. package/dist/config/model_meta.d.ts.map +0 -1
  76. package/dist/config/type_util.d.ts +0 -14
  77. package/dist/config/type_util.d.ts.map +0 -1
  78. package/dist/ref_util.cjs +0 -21
  79. package/dist/ref_util.cjs.map +0 -1
  80. package/dist/ref_util.d.ts +0 -19
  81. package/dist/ref_util.d.ts.map +0 -1
  82. package/dist/ref_util.js +0 -20
  83. package/dist/ref_util.js.map +0 -1
  84. package/src/block_model_legacy.ts +0 -465
  85. package/src/config/actions.ts +0 -468
  86. package/src/config/actions_kinds.ts +0 -264
  87. package/src/config/model_meta.ts +0 -5
  88. package/src/config/type_util.ts +0 -25
  89. package/src/ref_util.ts +0 -17
@@ -1,465 +0,0 @@
1
- import type {
2
- BlockRenderingMode,
3
- BlockSection,
4
- AnyFunction,
5
- PlRef,
6
- BlockCodeKnownFeatureFlags,
7
- BlockConfigContainer,
8
- } from "@milaboratories/pl-model-common";
9
- import { REQUIRES_PFRAMES_VERSION } from "@milaboratories/pl-model-common";
10
- import type { Checked, ConfigResult, TypedConfig } from "./config";
11
- import { getImmediate } from "./config";
12
- import { getPlatformaInstance, isInUI, tryRegisterCallback } from "./internal";
13
- import type { Platforma, PlatformaApiVersion, PlatformaV1, PlatformaV2 } from "./platforma";
14
- import type { InferRenderFunctionReturn, RenderFunctionLegacy } from "./render";
15
- import { RenderCtxLegacy } from "./render";
16
- import { PlatformaSDKVersion } from "./version";
17
- import type {
18
- TypedConfigOrConfigLambda,
19
- ConfigRenderLambda,
20
- StdCtxArgsOnly,
21
- DeriveHref,
22
- ConfigRenderLambdaFlags,
23
- InferOutputsFromConfigs,
24
- } from "./bconfig";
25
- import { downgradeCfgOrLambda, isConfigLambda } from "./bconfig";
26
- import type { PlatformaExtended } from "./platforma";
27
-
28
- type SectionsExpectedType = readonly BlockSection[];
29
-
30
- type SectionsCfgChecked<Cfg extends TypedConfig, Args, UiState> = Checked<
31
- Cfg,
32
- ConfigResult<Cfg, StdCtxArgsOnly<Args, UiState>> extends SectionsExpectedType ? true : false
33
- >;
34
-
35
- type InputsValidExpectedType = boolean;
36
-
37
- type InputsValidCfgChecked<Cfg extends TypedConfig, Args, UiState> = Checked<
38
- Cfg,
39
- ConfigResult<Cfg, StdCtxArgsOnly<Args, UiState>> extends InputsValidExpectedType ? true : false
40
- >;
41
-
42
- type NoOb = Record<string, never>;
43
-
44
- /** Main entry point that each block should use in it's "config" module. Don't forget
45
- * to call {@link done()} at the end of configuration. Value returned by this builder must be
46
- * exported as constant with name "platforma" from the "config" module. */
47
- export class BlockModel<
48
- Args,
49
- OutputsCfg extends Record<string, TypedConfigOrConfigLambda>,
50
- UiState,
51
- Href extends `/${string}` = "/",
52
- > {
53
- private constructor(
54
- private config: {
55
- readonly renderingMode: BlockRenderingMode;
56
- readonly initialArgs?: Args;
57
- readonly initialUiState: UiState;
58
- readonly outputs: OutputsCfg;
59
- readonly inputsValid: TypedConfigOrConfigLambda;
60
- readonly sections: TypedConfigOrConfigLambda;
61
- readonly title?: ConfigRenderLambda;
62
- readonly subtitle?: ConfigRenderLambda;
63
- readonly tags?: ConfigRenderLambda;
64
- readonly enrichmentTargets?: ConfigRenderLambda;
65
- readonly featureFlags: BlockCodeKnownFeatureFlags;
66
- },
67
- ) {}
68
-
69
- public static get INITIAL_BLOCK_FEATURE_FLAGS(): BlockCodeKnownFeatureFlags {
70
- return {
71
- supportsLazyState: true,
72
- supportsPframeQueryRanking: true,
73
- requiresUIAPIVersion: 1,
74
- requiresModelAPIVersion: 1,
75
- requiresCreatePTable: 2,
76
- requiresPFramesVersion: REQUIRES_PFRAMES_VERSION,
77
- };
78
- }
79
-
80
- /** Initiates configuration builder */
81
- public static create(renderingMode: BlockRenderingMode): BlockModel<NoOb, {}, NoOb>;
82
- /** Initiates configuration builder */
83
- public static create(): BlockModel<NoOb, {}, NoOb>;
84
- /**
85
- * Initiates configuration builder
86
- * @deprecated use create method without generic parameter
87
- */
88
- public static create<Args>(renderingMode: BlockRenderingMode): BlockModel<Args, {}, NoOb>;
89
- /**
90
- * Initiates configuration builder
91
- * @deprecated use create method without generic parameter
92
- */
93
- public static create<Args>(): BlockModel<Args, {}, NoOb>;
94
- public static create(renderingMode: BlockRenderingMode = "Heavy"): BlockModel<NoOb, {}, NoOb> {
95
- return new BlockModel<NoOb, {}, NoOb>({
96
- renderingMode,
97
- initialUiState: {},
98
- outputs: {},
99
- inputsValid: getImmediate(true),
100
- sections: getImmediate([]),
101
- featureFlags: BlockModel.INITIAL_BLOCK_FEATURE_FLAGS,
102
- });
103
- }
104
-
105
- /**
106
- * Add output cell to the configuration
107
- *
108
- * @param key output cell name, that can be later used to retrieve the rendered value
109
- * @param cfg configuration describing how to render cell value from the blocks
110
- * workflow outputs
111
- * @deprecated use lambda-based API
112
- * */
113
- public output<const Key extends string, const Cfg extends TypedConfig>(
114
- key: Key,
115
- cfg: Cfg,
116
- ): BlockModel<Args, OutputsCfg & { [K in Key]: Cfg }, UiState, Href>;
117
- /**
118
- * Add output cell wrapped with additional status information to the configuration
119
- *
120
- * @param key output cell name, that can be later used to retrieve the rendered value
121
- * @param rf callback calculating output value using context, that allows to access
122
- * workflows outputs and interact with platforma drivers
123
- * @param flags additional flags that may alter lambda rendering procedure
124
- * */
125
- public output<const Key extends string, const RF extends RenderFunctionLegacy<Args, UiState>>(
126
- key: Key,
127
- rf: RF,
128
- flags: ConfigRenderLambdaFlags & { withStatus: true },
129
- ): BlockModel<
130
- Args,
131
- OutputsCfg & {
132
- [K in Key]: ConfigRenderLambda<InferRenderFunctionReturn<RF>> & { withStatus: true };
133
- },
134
- UiState,
135
- Href
136
- >;
137
- /**
138
- * Add output cell to the configuration
139
- *
140
- * @param key output cell name, that can be later used to retrieve the rendered value
141
- * @param rf callback calculating output value using context, that allows to access
142
- * workflows outputs and interact with platforma drivers
143
- * @param flags additional flags that may alter lambda rendering procedure
144
- * */
145
- public output<const Key extends string, const RF extends RenderFunctionLegacy<Args, UiState>>(
146
- key: Key,
147
- rf: RF,
148
- flags?: ConfigRenderLambdaFlags,
149
- ): BlockModel<
150
- Args,
151
- OutputsCfg & { [K in Key]: ConfigRenderLambda<InferRenderFunctionReturn<RF>> },
152
- UiState,
153
- Href
154
- >;
155
- public output(
156
- key: string,
157
- cfgOrRf: TypedConfig | AnyFunction,
158
- flags: ConfigRenderLambdaFlags = {},
159
- ): BlockModel<Args, OutputsCfg, UiState, Href> {
160
- if (typeof cfgOrRf === "function") {
161
- const handle = `output#${key}`;
162
- tryRegisterCallback(handle, () => cfgOrRf(new RenderCtxLegacy()));
163
- return new BlockModel({
164
- ...this.config,
165
- outputs: {
166
- ...this.config.outputs,
167
- [key]: {
168
- __renderLambda: true,
169
- handle,
170
- ...flags,
171
- },
172
- },
173
- });
174
- } else {
175
- return new BlockModel({
176
- ...this.config,
177
- outputs: {
178
- ...this.config.outputs,
179
- [key]: cfgOrRf,
180
- },
181
- });
182
- }
183
- }
184
-
185
- /** Shortcut for {@link output} with retentive flag set to true. */
186
- public retentiveOutput<
187
- const Key extends string,
188
- const RF extends RenderFunctionLegacy<Args, UiState>,
189
- >(key: Key, rf: RF) {
190
- return this.output(key, rf, { retentive: true });
191
- }
192
-
193
- /** Shortcut for {@link output} with withStatus flag set to true. */
194
- public outputWithStatus<
195
- const Key extends string,
196
- const RF extends RenderFunctionLegacy<Args, UiState>,
197
- >(key: Key, rf: RF) {
198
- return this.output(key, rf, { withStatus: true });
199
- }
200
-
201
- /** Shortcut for {@link output} with retentive and withStatus flags set to true. */
202
- public retentiveOutputWithStatus<
203
- const Key extends string,
204
- const RF extends RenderFunctionLegacy<Args, UiState>,
205
- >(key: Key, rf: RF) {
206
- return this.output(key, rf, { retentive: true, withStatus: true });
207
- }
208
-
209
- /** Sets custom configuration predicate on the block args at which block can be executed
210
- * @deprecated use lambda-based API */
211
- public argsValid<Cfg extends TypedConfig>(
212
- cfg: Cfg & InputsValidCfgChecked<Cfg, Args, UiState>,
213
- ): BlockModel<Args, OutputsCfg, UiState, Href>;
214
- /** Sets custom configuration predicate on the block args at which block can be executed */
215
- public argsValid<RF extends RenderFunctionLegacy<Args, UiState, boolean>>(
216
- rf: RF,
217
- ): BlockModel<Args, OutputsCfg, UiState, Href>;
218
- public argsValid(
219
- cfgOrRf: TypedConfig | AnyFunction,
220
- ): BlockModel<Args, OutputsCfg, UiState, `/${string}`> {
221
- if (typeof cfgOrRf === "function") {
222
- tryRegisterCallback("inputsValid", () => cfgOrRf(new RenderCtxLegacy()));
223
- return new BlockModel<Args, OutputsCfg, UiState>({
224
- ...this.config,
225
- inputsValid: {
226
- __renderLambda: true,
227
- handle: "inputsValid",
228
- },
229
- });
230
- } else {
231
- return new BlockModel<Args, OutputsCfg, UiState>({
232
- ...this.config,
233
- inputsValid: cfgOrRf,
234
- });
235
- }
236
- }
237
-
238
- /** Sets the config to generate list of section in the left block overviews panel
239
- * @deprecated use lambda-based API */
240
- public sections<const S extends SectionsExpectedType>(
241
- rf: S,
242
- ): BlockModel<Args, OutputsCfg, UiState, DeriveHref<S>>;
243
- /** Sets the config to generate list of section in the left block overviews panel */
244
- public sections<
245
- const Ret extends SectionsExpectedType,
246
- const RF extends RenderFunctionLegacy<Args, UiState, Ret>,
247
- >(rf: RF): BlockModel<Args, OutputsCfg, UiState, DeriveHref<ReturnType<RF>>>;
248
- public sections<const Cfg extends TypedConfig>(
249
- cfg: Cfg & SectionsCfgChecked<Cfg, Args, UiState>,
250
- ): BlockModel<
251
- Args,
252
- OutputsCfg,
253
- UiState,
254
- DeriveHref<ConfigResult<Cfg, StdCtxArgsOnly<Args, UiState>>>
255
- >;
256
- public sections(
257
- arrOrCfgOrRf: SectionsExpectedType | TypedConfig | AnyFunction,
258
- ): BlockModel<Args, OutputsCfg, UiState, `/${string}`> {
259
- if (Array.isArray(arrOrCfgOrRf)) {
260
- return this.sections(getImmediate(arrOrCfgOrRf));
261
- } else if (typeof arrOrCfgOrRf === "function") {
262
- tryRegisterCallback("sections", () => arrOrCfgOrRf(new RenderCtxLegacy()));
263
- return new BlockModel<Args, OutputsCfg, UiState>({
264
- ...this.config,
265
- sections: {
266
- __renderLambda: true,
267
- handle: "sections",
268
- },
269
- });
270
- } else {
271
- return new BlockModel<Args, OutputsCfg, UiState>({
272
- ...this.config,
273
- sections: arrOrCfgOrRf as TypedConfig,
274
- });
275
- }
276
- }
277
-
278
- /** Sets a rendering function to derive block title, shown for the block in the left blocks-overview panel. */
279
- public title(
280
- rf: RenderFunctionLegacy<Args, UiState, string>,
281
- ): BlockModel<Args, OutputsCfg, UiState, Href> {
282
- tryRegisterCallback("title", () => rf(new RenderCtxLegacy()));
283
- return new BlockModel<Args, OutputsCfg, UiState, Href>({
284
- ...this.config,
285
- title: {
286
- __renderLambda: true,
287
- handle: "title",
288
- },
289
- });
290
- }
291
-
292
- public subtitle(
293
- rf: RenderFunctionLegacy<Args, UiState, string>,
294
- ): BlockModel<Args, OutputsCfg, UiState, Href> {
295
- tryRegisterCallback("subtitle", () => rf(new RenderCtxLegacy()));
296
- return new BlockModel<Args, OutputsCfg, UiState, Href>({
297
- ...this.config,
298
- subtitle: {
299
- __renderLambda: true,
300
- handle: "subtitle",
301
- },
302
- });
303
- }
304
-
305
- public tags(
306
- rf: RenderFunctionLegacy<Args, UiState, string[]>,
307
- ): BlockModel<Args, OutputsCfg, UiState, Href> {
308
- tryRegisterCallback("tags", () => rf(new RenderCtxLegacy()));
309
- return new BlockModel<Args, OutputsCfg, UiState, Href>({
310
- ...this.config,
311
- tags: {
312
- __renderLambda: true,
313
- handle: "tags",
314
- },
315
- });
316
- }
317
-
318
- /**
319
- * Sets initial args for the block, this value must be specified.
320
- * @deprecated use {@link withArgs}
321
- * */
322
- public initialArgs(value: Args): BlockModel<Args, OutputsCfg, UiState, Href> {
323
- return this.withArgs(value);
324
- }
325
-
326
- /** Sets initial args for the block, this value must be specified. */
327
- public withArgs<Args>(initialArgs: Args): BlockModel<Args, OutputsCfg, UiState, Href> {
328
- return new BlockModel<Args, OutputsCfg, UiState, Href>({
329
- ...this.config,
330
- initialArgs,
331
- });
332
- }
333
-
334
- /** Defines type and sets initial value for block UiState. */
335
- public withUiState<UiState>(
336
- initialUiState: UiState,
337
- ): BlockModel<Args, OutputsCfg, UiState, Href> {
338
- return new BlockModel<Args, OutputsCfg, UiState, Href>({
339
- ...this.config,
340
- initialUiState,
341
- });
342
- }
343
-
344
- /** Sets or overrides feature flags for the block. */
345
- public withFeatureFlags(
346
- flags: Partial<BlockCodeKnownFeatureFlags>,
347
- ): BlockModel<Args, OutputsCfg, UiState, Href> {
348
- return new BlockModel<Args, OutputsCfg, UiState, Href>({
349
- ...this.config,
350
- featureFlags: {
351
- ...this.config.featureFlags,
352
- ...flags,
353
- },
354
- });
355
- }
356
-
357
- /**
358
- * Defines how to derive list of upstream references this block is meant to enrich with its exports from block args.
359
- * Influences dependency graph construction.
360
- */
361
- public enriches(lambda: (args: Args) => PlRef[]): BlockModel<Args, OutputsCfg, UiState, Href> {
362
- tryRegisterCallback("enrichmentTargets", lambda);
363
- return new BlockModel<Args, OutputsCfg, UiState, Href>({
364
- ...this.config,
365
- enrichmentTargets: {
366
- __renderLambda: true,
367
- handle: "enrichmentTargets",
368
- },
369
- });
370
- }
371
-
372
- public done(
373
- apiVersion?: 1,
374
- ): PlatformaExtended<
375
- PlatformaV1<Args, InferOutputsFromConfigs<Args, OutputsCfg, UiState>, UiState, Href>
376
- >;
377
-
378
- public done(
379
- apiVersion: 2,
380
- ): PlatformaExtended<
381
- PlatformaV2<Args, InferOutputsFromConfigs<Args, OutputsCfg, UiState>, UiState, Href>
382
- >;
383
-
384
- /** Renders all provided block settings into a pre-configured platforma API
385
- * instance, that can be used in frontend to interact with block state, and
386
- * other features provided by the platforma to the block. */
387
- public done(
388
- apiVersion: PlatformaApiVersion = 1,
389
- ): PlatformaExtended<
390
- Platforma<Args, InferOutputsFromConfigs<Args, OutputsCfg, UiState>, UiState, Href>
391
- > {
392
- return this.withFeatureFlags({
393
- ...this.config.featureFlags,
394
- requiresUIAPIVersion: apiVersion,
395
- }).#done();
396
- }
397
-
398
- #done(): PlatformaExtended<
399
- Platforma<Args, InferOutputsFromConfigs<Args, OutputsCfg, UiState>, UiState, Href>
400
- > {
401
- if (this.config.initialArgs === undefined) throw new Error("Initial arguments not set.");
402
-
403
- const config: BlockConfigContainer = {
404
- v4: undefined,
405
- v3: {
406
- configVersion: 3,
407
- modelAPIVersion: 1,
408
- sdkVersion: PlatformaSDKVersion,
409
- renderingMode: this.config.renderingMode,
410
- initialArgs: this.config.initialArgs,
411
- initialUiState: this.config.initialUiState,
412
- inputsValid: this.config.inputsValid,
413
- sections: this.config.sections,
414
- title: this.config.title,
415
- subtitle: this.config.subtitle,
416
- tags: this.config.tags,
417
- outputs: this.config.outputs,
418
- enrichmentTargets: this.config.enrichmentTargets,
419
- featureFlags: this.config.featureFlags,
420
- },
421
-
422
- // fields below are added to allow previous desktop versions read generated configs
423
- sdkVersion: PlatformaSDKVersion,
424
- renderingMode: this.config.renderingMode,
425
- initialArgs: this.config.initialArgs,
426
- inputsValid: downgradeCfgOrLambda(this.config.inputsValid),
427
- sections: downgradeCfgOrLambda(this.config.sections),
428
- outputs: Object.fromEntries(
429
- Object.entries(this.config.outputs).map(([key, value]) => [
430
- key,
431
- downgradeCfgOrLambda(value),
432
- ]),
433
- ),
434
- };
435
-
436
- globalThis.platformaApiVersion = this.config.featureFlags
437
- .requiresUIAPIVersion as PlatformaApiVersion;
438
-
439
- if (!isInUI()) {
440
- // we are in the configuration rendering routine, not in actual UI
441
- return { config } as any;
442
- } else {
443
- // normal operation inside the UI
444
- return {
445
- ...getPlatformaInstance({
446
- sdkVersion: PlatformaSDKVersion,
447
- apiVersion: platformaApiVersion,
448
- }),
449
- blockModelInfo: {
450
- outputs: Object.fromEntries(
451
- Object.entries(this.config.outputs).map(([key, value]) => [
452
- key,
453
- {
454
- withStatus: Boolean(isConfigLambda(value) && value.withStatus),
455
- },
456
- ]),
457
- ),
458
- pluginIds: [],
459
- featureFlags: this.config.featureFlags,
460
- pluginPublicOutputs: {},
461
- },
462
- };
463
- }
464
- }
465
- }