@platforma-sdk/model 1.8.19 → 1.10.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 (64) hide show
  1. package/dist/bconfig/container.d.ts +46 -0
  2. package/dist/bconfig/container.d.ts.map +1 -0
  3. package/dist/bconfig/index.d.ts +7 -0
  4. package/dist/bconfig/index.d.ts.map +1 -0
  5. package/dist/bconfig/lambdas.d.ts +33 -0
  6. package/dist/bconfig/lambdas.d.ts.map +1 -0
  7. package/dist/bconfig/normalization.d.ts +13 -0
  8. package/dist/bconfig/normalization.d.ts.map +1 -0
  9. package/dist/bconfig/types.d.ts +11 -0
  10. package/dist/bconfig/types.d.ts.map +1 -0
  11. package/dist/bconfig/utils.d.ts +7 -0
  12. package/dist/bconfig/utils.d.ts.map +1 -0
  13. package/dist/bconfig/v3.d.ts +30 -0
  14. package/dist/bconfig/v3.d.ts.map +1 -0
  15. package/dist/builder.d.ts +45 -65
  16. package/dist/builder.d.ts.map +1 -1
  17. package/dist/index.d.ts +1 -0
  18. package/dist/index.d.ts.map +1 -1
  19. package/dist/index.js +1 -1
  20. package/dist/index.js.map +1 -1
  21. package/dist/index.mjs +510 -271
  22. package/dist/index.mjs.map +1 -1
  23. package/dist/internal.d.ts +3 -2
  24. package/dist/internal.d.ts.map +1 -1
  25. package/dist/platforma.d.ts +3 -2
  26. package/dist/platforma.d.ts.map +1 -1
  27. package/dist/raw_globals.d.ts.map +1 -1
  28. package/dist/render/accessor.d.ts +47 -0
  29. package/dist/render/accessor.d.ts.map +1 -1
  30. package/dist/render/api.d.ts +2 -0
  31. package/dist/render/api.d.ts.map +1 -1
  32. package/dist/render/index.d.ts +1 -0
  33. package/dist/render/index.d.ts.map +1 -1
  34. package/dist/render/internal.d.ts +4 -0
  35. package/dist/render/internal.d.ts.map +1 -1
  36. package/dist/render/traversal_ops.d.ts +5 -2
  37. package/dist/render/traversal_ops.d.ts.map +1 -1
  38. package/dist/render/util/index.d.ts +2 -0
  39. package/dist/render/util/index.d.ts.map +1 -0
  40. package/dist/render/util/resource_map.d.ts +15 -0
  41. package/dist/render/util/resource_map.d.ts.map +1 -0
  42. package/dist/version.d.ts +1 -1
  43. package/package.json +3 -3
  44. package/src/bconfig/container.ts +58 -0
  45. package/src/bconfig/index.ts +6 -0
  46. package/src/bconfig/lambdas.ts +44 -0
  47. package/src/bconfig/normalization.ts +120 -0
  48. package/src/bconfig/types.ts +18 -0
  49. package/src/bconfig/utils.ts +8 -0
  50. package/src/bconfig/v3.ts +46 -0
  51. package/src/builder.ts +165 -141
  52. package/src/global.d.ts +1 -1
  53. package/src/index.ts +1 -0
  54. package/src/internal.ts +1 -2
  55. package/src/platforma.ts +1 -2
  56. package/src/raw_globals.ts +2 -1
  57. package/src/render/accessor.ts +136 -0
  58. package/src/render/api.ts +22 -10
  59. package/src/render/index.ts +1 -0
  60. package/src/render/internal.ts +12 -0
  61. package/src/render/traversal_ops.ts +5 -2
  62. package/src/render/util/index.ts +1 -0
  63. package/src/render/util/resource_map.ts +74 -0
  64. package/src/typing.test.ts +5 -4
package/src/render/api.ts CHANGED
@@ -112,11 +112,15 @@ export class ResultPool {
112
112
  * @returns data associated with the ref
113
113
  */
114
114
  public getDataByRef(ref: Ref): PObject<TreeNodeAccessor> | undefined {
115
- // https://github.com/milaboratory/platforma/issues/100
116
- // @TODO use native pool method when available
117
- return this.getData().entries.find(
118
- (f) => f.ref.blockId === ref.blockId && f.ref.name === ref.name
119
- )?.obj;
115
+ // @TODO remove after 1 Jan 2025; forward compatibility
116
+ if (typeof this.ctx.getDataFromResultPoolByRef === 'undefined')
117
+ return this.getData().entries.find(
118
+ (f) => f.ref.blockId === ref.blockId && f.ref.name === ref.name
119
+ )?.obj;
120
+ return mapPObjectData(
121
+ this.ctx.getDataFromResultPoolByRef(ref.blockId, ref.name),
122
+ (handle) => new TreeNodeAccessor(handle)
123
+ );
120
124
  }
121
125
 
122
126
  /**
@@ -124,11 +128,12 @@ export class ResultPool {
124
128
  * @returns object spec associated with the ref
125
129
  */
126
130
  public getSpecByRef(ref: Ref): PObjectSpec | undefined {
127
- // https://github.com/milaboratory/platforma/issues/100
128
- // @TODO use native pool method when available
129
- return this.getSpecs().entries.find(
130
- (f) => f.ref.blockId === ref.blockId && f.ref.name === ref.name
131
- )?.obj;
131
+ // @TODO remove after 1 Jan 2025; forward compatibility
132
+ if (typeof this.ctx.getSpecFromResultPoolByRef === 'undefined')
133
+ return this.getSpecs().entries.find(
134
+ (f) => f.ref.blockId === ref.blockId && f.ref.name === ref.name
135
+ )?.obj;
136
+ return this.ctx.getSpecFromResultPoolByRef(ref.blockId, ref.name);
132
137
  }
133
138
 
134
139
  /**
@@ -275,9 +280,16 @@ export class RenderCtx<Args, UiState> {
275
280
  return this.ctx.createPTable(mapPTableDef(rawDef, (po) => mapPObjectData(po, (d) => d.handle)));
276
281
  }
277
282
 
283
+ /** @deprecated scheduled for removal from SDK */
278
284
  public getBlockLabel(blockId: string): string {
279
285
  return this.ctx.getBlockLabel(blockId);
280
286
  }
287
+
288
+ public getCurrentUnstableMarker(): string | undefined {
289
+ // @TODO remove after 1 Jan 2025; forward compatibility
290
+ if (typeof this.ctx.getCurrentUnstableMarker === 'undefined') return undefined;
291
+ return this.ctx.getCurrentUnstableMarker();
292
+ }
281
293
  }
282
294
 
283
295
  export type RenderFunction<Args = unknown, UiState = unknown, Ret = unknown> = (
@@ -1,5 +1,6 @@
1
1
  export * from './api';
2
2
  export * from './traversal_ops';
3
3
  export * from './accessor';
4
+ export * from './util';
4
5
  export { type ExtractFutureRefType } from './future';
5
6
  export { FutureRef } from './future';
@@ -11,6 +11,7 @@ import {
11
11
  PSpecPredicate,
12
12
  PTableDef,
13
13
  PTableHandle,
14
+ Ref,
14
15
  ResultCollection,
15
16
  ValueOrError
16
17
  } from '@milaboratories/pl-model-common';
@@ -103,6 +104,7 @@ export interface GlobalCfgRenderCtxMethods<AHandle = AccessorHandle, FHandle = F
103
104
  // Blocks
104
105
  //
105
106
 
107
+ /** @deprecated at some point will stop working and will return dummy values */
106
108
  getBlockLabel(blockId: string): string;
107
109
 
108
110
  //
@@ -117,6 +119,10 @@ export interface GlobalCfgRenderCtxMethods<AHandle = AccessorHandle, FHandle = F
117
119
 
118
120
  getSpecsFromResultPool(): ResultCollection<PObjectSpec>;
119
121
 
122
+ getSpecFromResultPoolByRef(blockId: string, exportName: string): PObjectSpec | undefined;
123
+
124
+ getDataFromResultPoolByRef(blockId: string, exportName: string): PObject<AHandle> | undefined;
125
+
120
126
  calculateOptions(predicate: PSpecPredicate): Option[];
121
127
 
122
128
  //
@@ -126,6 +132,12 @@ export interface GlobalCfgRenderCtxMethods<AHandle = AccessorHandle, FHandle = F
126
132
  createPFrame(def: PFrameDef<AHandle>): PFrameHandle;
127
133
 
128
134
  createPTable(def: PTableDef<PColumn<AHandle>>): PTableHandle;
135
+
136
+ //
137
+ // Computable
138
+ //
139
+
140
+ getCurrentUnstableMarker(): string | undefined;
129
141
  }
130
142
 
131
143
  export interface GlobalCfgRenderCtx extends GlobalCfgRenderCtxMethods {
@@ -46,8 +46,11 @@ export type GetFieldStep = CommonFieldTraverseOps & {
46
46
  errorIfFieldNotSet?: true;
47
47
 
48
48
  /**
49
- * Assert field type. Call will fail with exception if this assertion is not
50
- * fulfilled
49
+ * Assert field type.
50
+ * Call will fail with exception if this assertion is not fulfilled.
51
+ * The information about expectedFieldType is also used for stability
52
+ * calculation and field absence error generation, so it is always a good
53
+ * ide to specify it.
51
54
  * */
52
55
  assertFieldType?: FieldType;
53
56
  };
@@ -0,0 +1 @@
1
+ export * from './resource_map'
@@ -0,0 +1,74 @@
1
+ import { TreeNodeAccessor } from "../accessor";
2
+
3
+ export const ResourceMapResourceTypeName = 'PColumnData/ResourceMap';
4
+ export const ResourceMapResourcePartitionedTypeName = 'PColumnData/Partitioned/ResourceMap';
5
+
6
+ export type PColumnKey = (string | number)[];
7
+
8
+ export type PColumnResourceMapEntry<T> = {
9
+ key: PColumnKey;
10
+ value: T;
11
+ };
12
+
13
+ export type PColumnResourceMapData<T> = {
14
+ isComplete: boolean;
15
+ data: PColumnResourceMapEntry<T>[];
16
+ };
17
+
18
+ function populateResourceMapData<T>(
19
+ acc: TreeNodeAccessor | undefined,
20
+ resourceParser: (acc: TreeNodeAccessor) => T | undefined,
21
+ data: PColumnResourceMapEntry<T | undefined>[],
22
+ keyPrefix: PColumnKey = [],
23
+ addEntriesWithNoData: boolean
24
+ ): boolean {
25
+ if (acc === undefined) return false;
26
+ switch (acc.resourceType.name) {
27
+ case ResourceMapResourceTypeName: {
28
+ let isComplete = acc.getInputsLocked();
29
+ for (const keyStr of acc.listInputFields()) {
30
+ const value = acc.resolve({ field: keyStr, assertFieldType: 'Input' });
31
+ const key = [...keyPrefix, ...JSON.parse(keyStr)] as PColumnKey;
32
+ const converted = value === undefined ? undefined : resourceParser(value);
33
+ if (converted === undefined) isComplete = false;
34
+ if (converted !== undefined || addEntriesWithNoData) data.push({ key, value: converted });
35
+ }
36
+ return isComplete;
37
+ }
38
+ case ResourceMapResourcePartitionedTypeName: {
39
+ let isComplete = acc.getInputsLocked();
40
+ for (const keyStr of acc.listInputFields()) {
41
+ const value = acc.resolve({ field: keyStr, assertFieldType: 'Input' });
42
+ if (value === undefined) isComplete = false;
43
+ else {
44
+ const key = [...keyPrefix, ...JSON.parse(keyStr)] as PColumnKey;
45
+ const populateResult = populateResourceMapData(value, resourceParser, data, key, addEntriesWithNoData)
46
+ isComplete = isComplete && populateResult;
47
+ }
48
+ }
49
+ return isComplete;
50
+ }
51
+ default:
52
+ throw new Error(`Unknown resource type: ${acc.resourceType.name}`);
53
+ }
54
+ }
55
+
56
+ export function parseResourceMap<T>(
57
+ acc: TreeNodeAccessor | undefined,
58
+ resourceParser: (acc: TreeNodeAccessor) => T | undefined,
59
+ addEntriesWithNoData: false
60
+ ): PColumnResourceMapData<NonNullable<T>>;
61
+ export function parseResourceMap<T>(
62
+ acc: TreeNodeAccessor | undefined,
63
+ resourceParser: (acc: TreeNodeAccessor) => T | undefined,
64
+ addEntriesWithNoData: true
65
+ ): PColumnResourceMapData<T | undefined>;
66
+ export function parseResourceMap<T>(
67
+ acc: TreeNodeAccessor | undefined,
68
+ resourceParser: (acc: TreeNodeAccessor) => T | undefined,
69
+ addEntriesWithNoData: boolean = false
70
+ ): PColumnResourceMapData<T | undefined> {
71
+ const data: PColumnResourceMapEntry<T | undefined>[] = [];
72
+ const isComplete = populateResourceMapData(acc, resourceParser, data, [], addEntriesWithNoData);
73
+ return { isComplete, data };
74
+ }
@@ -4,7 +4,7 @@ import {
4
4
  RemoteBlobHandleAndSize,
5
5
  ValueOrErrors
6
6
  } from '@milaboratories/pl-model-common';
7
- import { BlockModel, DeriveHref, StdCtx } from './builder';
7
+ import { BlockModel } from './builder';
8
8
  import {
9
9
  Args,
10
10
  ConfigResult,
@@ -27,6 +27,7 @@ import {
27
27
  mapRecordValues
28
28
  } from './config';
29
29
  import { InferHrefType, InferOutputsType } from './platforma';
30
+ import { DeriveHref, StdCtx } from './bconfig';
30
31
 
31
32
  type AssertEqual<T, Expected> = [T] extends [Expected]
32
33
  ? [Expected] extends [T]
@@ -99,11 +100,11 @@ test('test config content', () => {
99
100
  });
100
101
 
101
102
  test('test config content', () => {
102
- const platforma = BlockModel.create<{ a: string[] }>('Heavy')
103
- .initialArgs({ a: [] })
103
+ const platforma = BlockModel.create('Heavy')
104
+ .withArgs<{ a: string[] }>({ a: [] })
105
+ .argsValid(isEmpty(getJsonField(Args, 'a')))
104
106
  .output('cell1', makeObject({ b: getJsonField(Args, 'a') }))
105
107
  .output('cell2', mapArrayValues(getJsonField(Args, 'a'), getImmediate('v1')))
106
- .inputsValid(isEmpty(getJsonField(Args, 'a')))
107
108
  .sections((r) => {
108
109
  return [
109
110
  { type: 'link', href: '/', label: 'Main' },