@platforma-sdk/model 1.51.9 → 1.52.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 (82) hide show
  1. package/dist/bconfig/lambdas.d.ts +26 -4
  2. package/dist/bconfig/lambdas.d.ts.map +1 -1
  3. package/dist/bconfig/v3.d.ts +4 -2
  4. package/dist/bconfig/v3.d.ts.map +1 -1
  5. package/dist/block_api_v3.d.ts +32 -0
  6. package/dist/block_api_v3.d.ts.map +1 -0
  7. package/dist/block_migrations.cjs +138 -0
  8. package/dist/block_migrations.cjs.map +1 -0
  9. package/dist/block_migrations.d.ts +79 -0
  10. package/dist/block_migrations.d.ts.map +1 -0
  11. package/dist/block_migrations.js +136 -0
  12. package/dist/block_migrations.js.map +1 -0
  13. package/dist/block_model.cjs +222 -0
  14. package/dist/block_model.cjs.map +1 -0
  15. package/dist/block_model.d.ts +132 -0
  16. package/dist/block_model.d.ts.map +1 -0
  17. package/dist/block_model.js +220 -0
  18. package/dist/block_model.js.map +1 -0
  19. package/dist/block_storage.cjs +244 -0
  20. package/dist/block_storage.cjs.map +1 -0
  21. package/dist/block_storage.d.ts +208 -0
  22. package/dist/block_storage.d.ts.map +1 -0
  23. package/dist/block_storage.js +225 -0
  24. package/dist/block_storage.js.map +1 -0
  25. package/dist/block_storage_vm.cjs +264 -0
  26. package/dist/block_storage_vm.cjs.map +1 -0
  27. package/dist/block_storage_vm.d.ts +67 -0
  28. package/dist/block_storage_vm.d.ts.map +1 -0
  29. package/dist/block_storage_vm.js +260 -0
  30. package/dist/block_storage_vm.js.map +1 -0
  31. package/dist/builder.cjs +9 -6
  32. package/dist/builder.cjs.map +1 -1
  33. package/dist/builder.d.ts +15 -30
  34. package/dist/builder.d.ts.map +1 -1
  35. package/dist/builder.js +10 -7
  36. package/dist/builder.js.map +1 -1
  37. package/dist/components/PlDataTable.cjs.map +1 -1
  38. package/dist/components/PlDataTable.d.ts +2 -2
  39. package/dist/components/PlDataTable.d.ts.map +1 -1
  40. package/dist/components/PlDataTable.js.map +1 -1
  41. package/dist/index.cjs +25 -0
  42. package/dist/index.cjs.map +1 -1
  43. package/dist/index.d.ts +3 -0
  44. package/dist/index.d.ts.map +1 -1
  45. package/dist/index.js +4 -1
  46. package/dist/index.js.map +1 -1
  47. package/dist/internal.cjs +38 -0
  48. package/dist/internal.cjs.map +1 -1
  49. package/dist/internal.d.ts +21 -0
  50. package/dist/internal.d.ts.map +1 -1
  51. package/dist/internal.js +36 -1
  52. package/dist/internal.js.map +1 -1
  53. package/dist/package.json.cjs +1 -1
  54. package/dist/package.json.js +1 -1
  55. package/dist/platforma.d.ts +18 -3
  56. package/dist/platforma.d.ts.map +1 -1
  57. package/dist/render/api.cjs +43 -16
  58. package/dist/render/api.cjs.map +1 -1
  59. package/dist/render/api.d.ts +19 -7
  60. package/dist/render/api.d.ts.map +1 -1
  61. package/dist/render/api.js +42 -17
  62. package/dist/render/api.js.map +1 -1
  63. package/dist/render/internal.cjs.map +1 -1
  64. package/dist/render/internal.d.ts +3 -1
  65. package/dist/render/internal.d.ts.map +1 -1
  66. package/dist/render/internal.js.map +1 -1
  67. package/package.json +7 -7
  68. package/src/bconfig/lambdas.ts +35 -4
  69. package/src/bconfig/v3.ts +12 -2
  70. package/src/block_api_v3.ts +49 -0
  71. package/src/block_migrations.ts +173 -0
  72. package/src/block_model.ts +440 -0
  73. package/src/block_storage.test.ts +258 -0
  74. package/src/block_storage.ts +365 -0
  75. package/src/block_storage_vm.ts +349 -0
  76. package/src/builder.ts +24 -59
  77. package/src/components/PlDataTable.ts +2 -1
  78. package/src/index.ts +3 -0
  79. package/src/internal.ts +51 -0
  80. package/src/platforma.ts +31 -5
  81. package/src/render/api.ts +52 -21
  82. package/src/render/internal.ts +3 -1
package/src/builder.ts CHANGED
@@ -1,24 +1,24 @@
1
- import type { BlockRenderingMode, BlockSection, AnyFunction, PlRef, BlockCodeKnownFeatureFlags, BlockConfigContainer, OutputWithStatus } from '@milaboratories/pl-model-common';
1
+ import type { BlockRenderingMode, BlockSection, AnyFunction, PlRef, BlockCodeKnownFeatureFlags, BlockConfigContainer } from '@milaboratories/pl-model-common';
2
2
  import type { Checked, ConfigResult, TypedConfig } from './config';
3
3
  import { getImmediate } from './config';
4
4
  import { getPlatformaInstance, isInUI, tryRegisterCallback } from './internal';
5
5
  import type { Platforma, PlatformaApiVersion, PlatformaV1, PlatformaV2 } from './platforma';
6
- import type { InferRenderFunctionReturn, RenderFunction } from './render';
7
- import { RenderCtx } from './render';
6
+ import type { InferRenderFunctionReturn, RenderFunctionLegacy } from './render';
7
+ import { RenderCtxLegacy } from './render';
8
8
  import { PlatformaSDKVersion } from './version';
9
9
  import type {
10
10
  TypedConfigOrConfigLambda,
11
11
  ConfigRenderLambda,
12
12
  StdCtxArgsOnly,
13
13
  DeriveHref,
14
- ResolveCfgType,
15
- ExtractFunctionHandleReturn,
16
14
  ConfigRenderLambdaFlags,
15
+ InferOutputsFromConfigs,
17
16
  } from './bconfig';
18
17
  import {
19
18
  downgradeCfgOrLambda,
20
19
  isConfigLambda,
21
20
  } from './bconfig';
21
+ import type { PlatformaExtended } from './platforma';
22
22
 
23
23
  type SectionsExpectedType = readonly BlockSection[];
24
24
 
@@ -27,12 +27,6 @@ type SectionsCfgChecked<Cfg extends TypedConfig, Args, UiState> = Checked<
27
27
  ConfigResult<Cfg, StdCtxArgsOnly<Args, UiState>> extends SectionsExpectedType ? true : false
28
28
  >;
29
29
 
30
- // TODO (Unused type in code)
31
- // type SectionsRFChecked<RF extends Function> = Checked<
32
- // RF,
33
- // InferRenderFunctionReturn<RF> extends SectionsExpectedType ? true : false
34
- // >;
35
-
36
30
  type InputsValidExpectedType = boolean;
37
31
 
38
32
  type InputsValidCfgChecked<Cfg extends TypedConfig, Args, UiState> = Checked<
@@ -40,12 +34,6 @@ type InputsValidCfgChecked<Cfg extends TypedConfig, Args, UiState> = Checked<
40
34
  ConfigResult<Cfg, StdCtxArgsOnly<Args, UiState>> extends InputsValidExpectedType ? true : false
41
35
  >;
42
36
 
43
- // TODO (Unused type in code)
44
- // type InputsValidRFChecked<RF extends Function> = Checked<
45
- // RF,
46
- // InferRenderFunctionReturn<RF> extends InputsValidExpectedType ? true : false
47
- // >;
48
-
49
37
  type NoOb = Record<string, never>;
50
38
 
51
39
  /** Main entry point that each block should use in it's "config" module. Don't forget
@@ -126,7 +114,7 @@ export class BlockModel<
126
114
  * workflows outputs and interact with platforma drivers
127
115
  * @param flags additional flags that may alter lambda rendering procedure
128
116
  * */
129
- public output<const Key extends string, const RF extends RenderFunction<Args, UiState>>(
117
+ public output<const Key extends string, const RF extends RenderFunctionLegacy<Args, UiState>>(
130
118
  key: Key,
131
119
  rf: RF,
132
120
  flags: ConfigRenderLambdaFlags & { withStatus: true }
@@ -144,7 +132,7 @@ export class BlockModel<
144
132
  * workflows outputs and interact with platforma drivers
145
133
  * @param flags additional flags that may alter lambda rendering procedure
146
134
  * */
147
- public output<const Key extends string, const RF extends RenderFunction<Args, UiState>>(
135
+ public output<const Key extends string, const RF extends RenderFunctionLegacy<Args, UiState>>(
148
136
  key: Key,
149
137
  rf: RF,
150
138
  flags?: ConfigRenderLambdaFlags
@@ -161,7 +149,7 @@ export class BlockModel<
161
149
  ): BlockModel<Args, OutputsCfg, UiState, Href> {
162
150
  if (typeof cfgOrRf === 'function') {
163
151
  const handle = `output#${key}`;
164
- tryRegisterCallback(handle, () => cfgOrRf(new RenderCtx()));
152
+ tryRegisterCallback(handle, () => cfgOrRf(new RenderCtxLegacy()));
165
153
  return new BlockModel({
166
154
  ...this.config,
167
155
  outputs: {
@@ -185,7 +173,7 @@ export class BlockModel<
185
173
  }
186
174
 
187
175
  /** Shortcut for {@link output} with retentive flag set to true. */
188
- public retentiveOutput<const Key extends string, const RF extends RenderFunction<Args, UiState>>(
176
+ public retentiveOutput<const Key extends string, const RF extends RenderFunctionLegacy<Args, UiState>>(
189
177
  key: Key,
190
178
  rf: RF,
191
179
  ) {
@@ -193,7 +181,7 @@ export class BlockModel<
193
181
  }
194
182
 
195
183
  /** Shortcut for {@link output} with withStatus flag set to true. */
196
- public outputWithStatus<const Key extends string, const RF extends RenderFunction<Args, UiState>>(
184
+ public outputWithStatus<const Key extends string, const RF extends RenderFunctionLegacy<Args, UiState>>(
197
185
  key: Key,
198
186
  rf: RF,
199
187
  ) {
@@ -201,7 +189,7 @@ export class BlockModel<
201
189
  }
202
190
 
203
191
  /** Shortcut for {@link output} with retentive and withStatus flags set to true. */
204
- public retentiveOutputWithStatus<const Key extends string, const RF extends RenderFunction<Args, UiState>>(
192
+ public retentiveOutputWithStatus<const Key extends string, const RF extends RenderFunctionLegacy<Args, UiState>>(
205
193
  key: Key,
206
194
  rf: RF,
207
195
  ) {
@@ -214,14 +202,14 @@ export class BlockModel<
214
202
  cfg: Cfg & InputsValidCfgChecked<Cfg, Args, UiState>
215
203
  ): BlockModel<Args, OutputsCfg, UiState, Href>;
216
204
  /** Sets custom configuration predicate on the block args at which block can be executed */
217
- public argsValid<RF extends RenderFunction<Args, UiState, boolean>>(
205
+ public argsValid<RF extends RenderFunctionLegacy<Args, UiState, boolean>>(
218
206
  rf: RF
219
207
  ): BlockModel<Args, OutputsCfg, UiState, Href>;
220
208
  public argsValid(
221
209
  cfgOrRf: TypedConfig | AnyFunction,
222
210
  ): BlockModel<Args, OutputsCfg, UiState, `/${string}`> {
223
211
  if (typeof cfgOrRf === 'function') {
224
- tryRegisterCallback('inputsValid', () => cfgOrRf(new RenderCtx()));
212
+ tryRegisterCallback('inputsValid', () => cfgOrRf(new RenderCtxLegacy()));
225
213
  return new BlockModel<Args, OutputsCfg, UiState>({
226
214
  ...this.config,
227
215
  inputsValid: {
@@ -245,7 +233,7 @@ export class BlockModel<
245
233
  /** Sets the config to generate list of section in the left block overviews panel */
246
234
  public sections<
247
235
  const Ret extends SectionsExpectedType,
248
- const RF extends RenderFunction<Args, UiState, Ret>,
236
+ const RF extends RenderFunctionLegacy<Args, UiState, Ret>,
249
237
  >(rf: RF): BlockModel<Args, OutputsCfg, UiState, DeriveHref<ReturnType<RF>>>;
250
238
  public sections<const Cfg extends TypedConfig>(
251
239
  cfg: Cfg & SectionsCfgChecked<Cfg, Args, UiState>
@@ -261,7 +249,7 @@ export class BlockModel<
261
249
  if (Array.isArray(arrOrCfgOrRf)) {
262
250
  return this.sections(getImmediate(arrOrCfgOrRf));
263
251
  } else if (typeof arrOrCfgOrRf === 'function') {
264
- tryRegisterCallback('sections', () => arrOrCfgOrRf(new RenderCtx()));
252
+ tryRegisterCallback('sections', () => arrOrCfgOrRf(new RenderCtxLegacy()));
265
253
  return new BlockModel<Args, OutputsCfg, UiState>({
266
254
  ...this.config,
267
255
  sections: {
@@ -279,9 +267,9 @@ export class BlockModel<
279
267
 
280
268
  /** Sets a rendering function to derive block title, shown for the block in the left blocks-overview panel. */
281
269
  public title(
282
- rf: RenderFunction<Args, UiState, string>,
270
+ rf: RenderFunctionLegacy<Args, UiState, string>,
283
271
  ): BlockModel<Args, OutputsCfg, UiState, Href> {
284
- tryRegisterCallback('title', () => rf(new RenderCtx()));
272
+ tryRegisterCallback('title', () => rf(new RenderCtxLegacy()));
285
273
  return new BlockModel<Args, OutputsCfg, UiState, Href>({
286
274
  ...this.config,
287
275
  title: {
@@ -292,9 +280,9 @@ export class BlockModel<
292
280
  }
293
281
 
294
282
  public subtitle(
295
- rf: RenderFunction<Args, UiState, string>,
283
+ rf: RenderFunctionLegacy<Args, UiState, string>,
296
284
  ): BlockModel<Args, OutputsCfg, UiState, Href> {
297
- tryRegisterCallback('subtitle', () => rf(new RenderCtx()));
285
+ tryRegisterCallback('subtitle', () => rf(new RenderCtxLegacy()));
298
286
  return new BlockModel<Args, OutputsCfg, UiState, Href>({
299
287
  ...this.config,
300
288
  subtitle: {
@@ -305,9 +293,9 @@ export class BlockModel<
305
293
  }
306
294
 
307
295
  public tags(
308
- rf: RenderFunction<Args, UiState, string[]>,
296
+ rf: RenderFunctionLegacy<Args, UiState, string[]>,
309
297
  ): BlockModel<Args, OutputsCfg, UiState, Href> {
310
- tryRegisterCallback('tags', () => rf(new RenderCtx()));
298
+ tryRegisterCallback('tags', () => rf(new RenderCtxLegacy()));
311
299
  return new BlockModel<Args, OutputsCfg, UiState, Href>({
312
300
  ...this.config,
313
301
  tags: {
@@ -407,7 +395,10 @@ export class BlockModel<
407
395
  if (this.config.initialArgs === undefined) throw new Error('Initial arguments not set.');
408
396
 
409
397
  const config: BlockConfigContainer = {
398
+ v4: undefined,
410
399
  v3: {
400
+ configVersion: 3,
401
+ modelAPIVersion: 1,
411
402
  sdkVersion: PlatformaSDKVersion,
412
403
  renderingMode: this.config.renderingMode,
413
404
  initialArgs: this.config.initialArgs,
@@ -452,29 +443,3 @@ export class BlockModel<
452
443
  };
453
444
  }
454
445
  }
455
-
456
- export type InferOutputType<CfgOrFH, Args, UiState> = CfgOrFH extends TypedConfig
457
- ? ResolveCfgType<CfgOrFH, Args, UiState>
458
- : CfgOrFH extends ConfigRenderLambda
459
- ? ExtractFunctionHandleReturn<CfgOrFH>
460
- : never;
461
-
462
- type InferOutputsFromConfigs<
463
- Args,
464
- OutputsCfg extends Record<string, TypedConfigOrConfigLambda>,
465
- UiState,
466
- > = {
467
- [Key in keyof OutputsCfg]:
468
- & OutputWithStatus<InferOutputType<OutputsCfg[Key], Args, UiState>>
469
- & { __unwrap: (OutputsCfg[Key] extends { withStatus: true } ? false : true) };
470
- };
471
-
472
- export type PlatformaExtended<Pl extends Platforma = Platforma> = Pl & {
473
- blockModelInfo: BlockModelInfo;
474
- };
475
-
476
- export type BlockModelInfo = {
477
- outputs: Record<string, {
478
- withStatus: boolean;
479
- }>;
480
- };
@@ -35,6 +35,7 @@ import type {
35
35
  ColumnProvider,
36
36
  PColumnDataUniversal,
37
37
  RenderCtx,
38
+ RenderCtxLegacy,
38
39
  TreeNodeAccessor,
39
40
  } from '../render';
40
41
  import {
@@ -631,7 +632,7 @@ export function isColumnOptional(spec: { annotations?: Annotation }): boolean {
631
632
  * @returns PlAgDataTableV2 table source
632
633
  */
633
634
  export function createPlDataTableV2<A, U>(
634
- ctx: RenderCtx<A, U>,
635
+ ctx: RenderCtx<A, U> | RenderCtxLegacy<A, U>,
635
636
  columns: PColumn<PColumnDataUniversal>[],
636
637
  tableState: PlDataTableStateV2 | undefined,
637
638
  ops?: CreatePlDataTableOps,
package/src/index.ts CHANGED
@@ -1,6 +1,9 @@
1
1
  export * from './block_state_patch';
2
2
  export * from './block_state_util';
3
+ export * from './block_storage';
3
4
  export * from './builder';
5
+ export { BlockModelV3 } from './block_model';
6
+ export { DataModel } from './block_migrations';
4
7
  export * from './bconfig';
5
8
  export * from './components';
6
9
  export * from './config';
package/src/internal.ts CHANGED
@@ -2,6 +2,7 @@ import type { OutputWithStatus } from '@milaboratories/pl-model-common';
2
2
  import { } from './global';
3
3
  import type { Platforma, PlatformaApiVersion } from './platforma';
4
4
  import type { FutureHandle, GlobalCfgRenderCtx } from './render/internal';
5
+ import type { ConfigRenderLambda, ConfigRenderLambdaFlags } from './bconfig';
5
6
 
6
7
  /** Utility code helping to identify whether the code is running in actual UI environment */
7
8
  export function isInUI() {
@@ -41,6 +42,56 @@ export function tryRegisterCallback(key: string, callback: (...args: any[]) => a
41
42
  return true;
42
43
  }
43
44
 
45
+ /**
46
+ * Registers a callback, replacing any existing callback with the same key.
47
+ * Use this for callbacks that have a default value but can be overridden.
48
+ *
49
+ * @param key - The callback registry key
50
+ * @param callback - The callback function to register
51
+ * @returns true if registered, false if not in render context
52
+ */
53
+ export function replaceCallback(key: string, callback: (...args: any[]) => any): boolean {
54
+ const ctx = tryGetCfgRenderCtx();
55
+ if (ctx === undefined) return false;
56
+ ctx.callbackRegistry[key] = callback;
57
+ return true;
58
+ }
59
+
60
+ //
61
+ // ConfigRenderLambda helpers
62
+ //
63
+
64
+ /** Options for creating a ConfigRenderLambda descriptor */
65
+ export type CreateLambdaOptions = ConfigRenderLambdaFlags & {
66
+ /** The callback registry key */
67
+ handle: string;
68
+ };
69
+
70
+ /** Creates a ConfigRenderLambda descriptor without registering a callback. */
71
+ export function createRenderLambda<T = unknown>(opts: CreateLambdaOptions): ConfigRenderLambda<T> {
72
+ const { handle, ...flags } = opts;
73
+ return {
74
+ __renderLambda: true,
75
+ handle,
76
+ ...flags,
77
+ } as ConfigRenderLambda<T>;
78
+ }
79
+
80
+ /** Registers a callback and returns a ConfigRenderLambda descriptor. */
81
+ export function createAndRegisterRenderLambda<T = unknown>(opts: CreateLambdaOptions & {
82
+ lambda: (...args: any[]) => any;
83
+ }, replace?: boolean): ConfigRenderLambda<T> {
84
+ const { handle, lambda, ...flags } = opts;
85
+
86
+ if (replace) {
87
+ replaceCallback(handle, lambda);
88
+ } else {
89
+ tryRegisterCallback(handle, lambda);
90
+ }
91
+
92
+ return createRenderLambda<T>({ handle, ...flags });
93
+ }
94
+
44
95
  const futureResolves = new Map<string, ((value: unknown) => void)[]>();
45
96
 
46
97
  export function registerFutureAwait(handle: FutureHandle, onResolve: (value: unknown) => void) {
package/src/platforma.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import type { BlockApiV1 } from './block_api_v1';
2
2
  import type { BlockApiV2 } from './block_api_v2';
3
- import type { BlockOutputsBase, BlockState, DriverKit, OutputWithStatus } from '@milaboratories/pl-model-common';
3
+ import type { BlockApiV3 } from './block_api_v3';
4
+ import type { BlockOutputsBase, BlockStateV3, DriverKit, OutputWithStatus } from '@milaboratories/pl-model-common';
4
5
  import type { SdkInfo } from './sdk_info';
5
6
  import type { BlockStatePatch } from './block_state_patch';
6
7
 
@@ -30,12 +31,34 @@ export interface PlatformaV2<
30
31
  readonly apiVersion: 2;
31
32
  }
32
33
 
34
+ export interface PlatformaV3<
35
+ Args = unknown,
36
+ Outputs extends Record<string, OutputWithStatus<unknown>> = Record<string, OutputWithStatus<unknown>>,
37
+ Data = unknown,
38
+ Href extends `/${string}` = `/${string}`,
39
+ > extends BlockApiV3<Args, Outputs, Data, Href>,
40
+ DriverKit {
41
+ /** Information about SDK version current platforma environment was compiled with. */
42
+ readonly sdkInfo: SdkInfo;
43
+ readonly apiVersion: 3;
44
+ }
45
+
33
46
  export type Platforma<
34
47
  Args = unknown,
35
48
  Outputs extends Record<string, OutputWithStatus<unknown>> = Record<string, OutputWithStatus<unknown>>,
36
49
  UiState = unknown,
37
50
  Href extends `/${string}` = `/${string}`,
38
- > = PlatformaV1<Args, Outputs, UiState, Href> | PlatformaV2<Args, Outputs, UiState, Href>;
51
+ > = PlatformaV1<Args, Outputs, UiState, Href> | PlatformaV2<Args, Outputs, UiState, Href> | PlatformaV3<Args, Outputs, UiState, Href>;
52
+
53
+ export type PlatformaExtended<Pl extends Platforma = Platforma> = Pl & {
54
+ blockModelInfo: BlockModelInfo;
55
+ };
56
+
57
+ export type BlockModelInfo = {
58
+ outputs: Record<string, {
59
+ withStatus: boolean;
60
+ }>;
61
+ };
39
62
 
40
63
  export type PlatformaApiVersion = Platforma['apiVersion'];
41
64
 
@@ -49,15 +72,18 @@ export type InferUiState<Pl extends Platforma> =
49
72
  ? UiState
50
73
  : never;
51
74
 
75
+ export type InferDataType<Pl extends Platforma> =
76
+ Pl extends Platforma<unknown, Record<string, OutputWithStatus<unknown>>, infer Data>
77
+ ? Data
78
+ : never;
79
+
52
80
  export type InferHrefType<Pl extends Platforma> =
53
81
  Pl extends Platforma<unknown, BlockOutputsBase, unknown, infer Href> ? Href : never;
54
82
 
55
83
  export type PlatformaFactory = (config: { sdkVersion: string }) => Platforma;
56
84
 
57
- export type InferBlockState<Pl extends Platforma> = BlockState<
58
- InferArgsType<Pl>,
85
+ export type InferBlockState<Pl extends Platforma> = BlockStateV3<
59
86
  InferOutputsType<Pl>,
60
- InferUiState<Pl>,
61
87
  InferHrefType<Pl>
62
88
  >;
63
89
 
package/src/render/api.ts CHANGED
@@ -515,33 +515,22 @@ export class ResultPool implements ColumnProvider, AxisLabelProvider {
515
515
  }
516
516
 
517
517
  /** Main entry point to the API available within model lambdas (like outputs, sections, etc..) */
518
- export class RenderCtx<Args, UiState> {
519
- private readonly ctx: GlobalCfgRenderCtx;
518
+ export abstract class RenderCtxBase<Args, Data> {
519
+ protected readonly ctx: GlobalCfgRenderCtx;
520
520
 
521
521
  constructor() {
522
522
  this.ctx = getCfgRenderCtx();
523
523
  }
524
524
 
525
- private _argsCache?: { v: Args };
526
-
527
- public get args(): Args {
528
- if (this._argsCache === undefined) {
529
- const raw = this.ctx.args;
530
- const value = typeof raw === 'function' ? raw() : raw;
531
- this._argsCache = { v: JSON.parse(value) };
532
- }
533
- return this._argsCache.v;
534
- }
535
-
536
- private _uiStateCache?: { v: UiState };
525
+ private _dataCache?: { v: Data };
537
526
 
538
- public get uiState(): UiState {
539
- if (this._uiStateCache === undefined) {
540
- const raw = this.ctx.uiState;
527
+ public get data(): Data {
528
+ if (this._dataCache === undefined) {
529
+ const raw = this.ctx.data;
541
530
  const value = typeof raw === 'function' ? raw() : raw;
542
- this._uiStateCache = { v: value ? JSON.parse(value) : ({} as UiState) };
531
+ this._dataCache = { v: value ? JSON.parse(value) : ({} as Data) };
543
532
  }
544
- return this._uiStateCache.v;
533
+ return this._dataCache.v;
545
534
  }
546
535
 
547
536
  // lazy rendering because this feature is rarely used
@@ -691,8 +680,50 @@ export class RenderCtx<Args, UiState> {
691
680
  }
692
681
  }
693
682
 
694
- export type RenderFunction<Args = unknown, UiState = unknown, Ret = unknown> = (
695
- rCtx: RenderCtx<Args, UiState>
683
+ /** Main entry point to the API available within model lambdas (like outputs, sections, etc..) for v3+ blocks */
684
+ export class RenderCtx<Args, Data> extends RenderCtxBase<Args, Data> {
685
+ private _argsCache?: { v: Args | undefined };
686
+ public get args(): Args | undefined {
687
+ if (this._argsCache === undefined) {
688
+ const raw = this.ctx.args;
689
+ const value = typeof raw === 'function' ? raw() : raw;
690
+ // args can be undefined when derivation fails (e.g., validation error in args())
691
+ this._argsCache = { v: value === undefined ? undefined : JSON.parse(value) };
692
+ }
693
+ return this._argsCache.v;
694
+ }
695
+ }
696
+
697
+ /** Render context for legacy v1/v2 blocks - provides backward compatibility */
698
+ export class RenderCtxLegacy<Args, UiState> extends RenderCtxBase<Args, UiState> {
699
+ private _argsCache?: { v: Args };
700
+ public get args(): Args {
701
+ if (this._argsCache === undefined) {
702
+ const raw = this.ctx.args;
703
+ const value = typeof raw === 'function' ? raw() : raw;
704
+ this._argsCache = { v: JSON.parse(value) };
705
+ }
706
+ return this._argsCache.v;
707
+ }
708
+
709
+ private _uiStateCache?: { v: UiState };
710
+
711
+ public get uiState(): UiState {
712
+ if (this._uiStateCache === undefined) {
713
+ const raw = this.ctx.uiState!;
714
+ const value = typeof raw === 'function' ? raw() : raw;
715
+ this._uiStateCache = { v: value ? JSON.parse(value) : ({} as UiState) };
716
+ }
717
+ return this._uiStateCache.v;
718
+ }
719
+ }
720
+
721
+ export type RenderFunction<Args = unknown, State = unknown, Ret = unknown> = (
722
+ rCtx: RenderCtx<Args, State>
723
+ ) => Ret;
724
+
725
+ export type RenderFunctionLegacy<Args = unknown, State = unknown, Ret = unknown> = (
726
+ rCtx: RenderCtxLegacy<Args, State>
696
727
  ) => Ret;
697
728
 
698
729
  export type UnwrapFutureRef<K> =
@@ -183,7 +183,9 @@ export interface GlobalCfgRenderCtx extends GlobalCfgRenderCtxMethods {
183
183
  //
184
184
 
185
185
  readonly args: string | (() => string);
186
- readonly uiState: string | (() => string);
186
+ /** @deprecated Use `data` instead. Optional for backward compatibility - falls back to `data` if not injected. */
187
+ readonly uiState?: string | (() => string);
188
+ readonly data: string | (() => string);
187
189
  readonly activeArgs: undefined | string | (() => string | undefined);
188
190
 
189
191
  // Note: strings below are used because, anyway, using strings is the only way