@platforma-sdk/model 1.57.2 → 1.58.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 (85) hide show
  1. package/dist/block_model.cjs +17 -13
  2. package/dist/block_model.cjs.map +1 -1
  3. package/dist/block_model.d.ts +4 -4
  4. package/dist/block_model.d.ts.map +1 -1
  5. package/dist/block_model.js +17 -13
  6. package/dist/block_model.js.map +1 -1
  7. package/dist/block_model_legacy.cjs +1 -0
  8. package/dist/block_model_legacy.cjs.map +1 -1
  9. package/dist/block_model_legacy.d.ts.map +1 -1
  10. package/dist/block_model_legacy.js +1 -0
  11. package/dist/block_model_legacy.js.map +1 -1
  12. package/dist/block_storage.cjs +18 -14
  13. package/dist/block_storage.cjs.map +1 -1
  14. package/dist/block_storage.d.ts +14 -10
  15. package/dist/block_storage.d.ts.map +1 -1
  16. package/dist/block_storage.js +18 -14
  17. package/dist/block_storage.js.map +1 -1
  18. package/dist/block_storage_callbacks.cjs +3 -3
  19. package/dist/block_storage_callbacks.cjs.map +1 -1
  20. package/dist/block_storage_callbacks.d.ts +4 -3
  21. package/dist/block_storage_callbacks.d.ts.map +1 -1
  22. package/dist/block_storage_callbacks.js +3 -3
  23. package/dist/block_storage_callbacks.js.map +1 -1
  24. package/dist/components/PFrameForGraphs.cjs +0 -117
  25. package/dist/components/PFrameForGraphs.cjs.map +1 -1
  26. package/dist/components/PFrameForGraphs.d.ts +3 -5
  27. package/dist/components/PFrameForGraphs.d.ts.map +1 -1
  28. package/dist/components/PFrameForGraphs.js +2 -117
  29. package/dist/components/PFrameForGraphs.js.map +1 -1
  30. package/dist/index.cjs +7 -2
  31. package/dist/index.cjs.map +1 -1
  32. package/dist/index.d.ts +2 -1
  33. package/dist/index.d.ts.map +1 -1
  34. package/dist/index.js +3 -1
  35. package/dist/index.js.map +1 -1
  36. package/dist/package.json.cjs +1 -1
  37. package/dist/package.json.js +1 -1
  38. package/dist/pframe_utils/axes.cjs +131 -0
  39. package/dist/pframe_utils/axes.cjs.map +1 -0
  40. package/dist/pframe_utils/axes.d.ts +15 -0
  41. package/dist/pframe_utils/axes.d.ts.map +1 -0
  42. package/dist/pframe_utils/axes.js +128 -0
  43. package/dist/pframe_utils/axes.js.map +1 -0
  44. package/dist/pframe_utils/columns.cjs +4 -8
  45. package/dist/pframe_utils/columns.cjs.map +1 -1
  46. package/dist/pframe_utils/columns.js +1 -5
  47. package/dist/pframe_utils/columns.js.map +1 -1
  48. package/dist/pframe_utils/index.cjs +0 -3
  49. package/dist/pframe_utils/index.cjs.map +1 -1
  50. package/dist/pframe_utils/index.js +0 -3
  51. package/dist/pframe_utils/index.js.map +1 -1
  52. package/dist/platforma.d.ts +12 -2
  53. package/dist/platforma.d.ts.map +1 -1
  54. package/dist/plugin_handle.cjs +29 -0
  55. package/dist/plugin_handle.cjs.map +1 -0
  56. package/dist/plugin_handle.d.ts +51 -0
  57. package/dist/plugin_handle.d.ts.map +1 -0
  58. package/dist/plugin_handle.js +25 -0
  59. package/dist/plugin_handle.js.map +1 -0
  60. package/dist/plugin_model.cjs +27 -27
  61. package/dist/plugin_model.cjs.map +1 -1
  62. package/dist/plugin_model.d.ts +41 -33
  63. package/dist/plugin_model.d.ts.map +1 -1
  64. package/dist/plugin_model.js +27 -27
  65. package/dist/plugin_model.js.map +1 -1
  66. package/dist/render/api.cjs +9 -5
  67. package/dist/render/api.cjs.map +1 -1
  68. package/dist/render/api.d.ts +11 -5
  69. package/dist/render/api.d.ts.map +1 -1
  70. package/dist/render/api.js +9 -5
  71. package/dist/render/api.js.map +1 -1
  72. package/package.json +5 -5
  73. package/src/block_model.ts +33 -19
  74. package/src/block_model_legacy.ts +1 -0
  75. package/src/block_storage.test.ts +3 -2
  76. package/src/block_storage.ts +30 -22
  77. package/src/block_storage_callbacks.ts +8 -7
  78. package/src/components/PFrameForGraphs.ts +4 -167
  79. package/src/index.ts +2 -1
  80. package/src/pframe_utils/axes.ts +175 -0
  81. package/src/pframe_utils/columns.ts +2 -2
  82. package/src/platforma.ts +17 -2
  83. package/src/plugin_handle.ts +85 -0
  84. package/src/plugin_model.ts +118 -56
  85. package/src/render/api.ts +21 -11
@@ -6,12 +6,14 @@ import type {
6
6
  BlockCodeKnownFeatureFlags,
7
7
  BlockConfigContainer,
8
8
  } from "@milaboratories/pl-model-common";
9
+ import { mergeFeatureFlags } from "@milaboratories/pl-model-common";
9
10
  import { getPlatformaInstance, isInUI, createAndRegisterRenderLambda } from "./internal";
10
11
  import type { DataModel } from "./block_migrations";
11
12
  import type { PlatformaV3 } from "./platforma";
12
13
  import type { InferRenderFunctionReturn, RenderFunction } from "./render";
13
14
  import { BlockRenderCtx, PluginRenderCtx } from "./render";
14
- import type { PluginModel } from "./plugin_model";
15
+ import type { PluginData, PluginModel, PluginOutputs, PluginParams } from "./plugin_model";
16
+ import { type PluginHandle, pluginOutputKey } from "./plugin_handle";
15
17
  import type { RenderCtxBase } from "./render";
16
18
  import { PlatformaSDKVersion } from "./version";
17
19
  import {
@@ -59,7 +61,11 @@ type ParamsInputErased = Record<string, (ctx: RenderCtxBase) => unknown>;
59
61
  * Registered plugin: model + param derivation lambdas.
60
62
  * Type parameters are carried by PluginModel generic.
61
63
  */
62
- export type PluginInstance<Data = unknown, Params = unknown, Outputs = unknown> = {
64
+ export type PluginInstance<
65
+ Data extends PluginData = PluginData,
66
+ Params extends PluginParams = undefined,
67
+ Outputs extends PluginOutputs = PluginOutputs,
68
+ > = {
63
69
  readonly model: PluginModel<Data, Params, Outputs>;
64
70
  readonly inputs: ParamsInputErased;
65
71
  };
@@ -125,7 +131,6 @@ export class BlockModelV3<
125
131
  renderingMode: "Heavy",
126
132
  dataModel,
127
133
  outputs: {},
128
- // Register default sections callback (returns empty array)
129
134
  sections: createAndRegisterRenderLambda({ handle: "sections", lambda: () => [] }, true),
130
135
  title: undefined,
131
136
  subtitle: undefined,
@@ -372,23 +377,28 @@ export class BlockModelV3<
372
377
  * sourceId: (ctx) => ctx.data.selectedSource,
373
378
  * })
374
379
  */
375
- public plugin<const PluginId extends string, PluginData, PluginParams, PluginOutputs>(
380
+ public plugin<
381
+ const PluginId extends string,
382
+ PData extends PluginData,
383
+ PParams extends PluginParams,
384
+ POutputs extends PluginOutputs,
385
+ >(
376
386
  pluginId: PluginId,
377
- plugin: PluginModel<PluginData, PluginParams, PluginOutputs>,
378
- params?: ParamsInput<PluginParams, Args, Data>,
387
+ plugin: PluginModel<PData, PParams, POutputs>,
388
+ params?: ParamsInput<PParams, Args, Data>,
379
389
  ): BlockModelV3<
380
390
  Args,
381
391
  OutputsCfg,
382
392
  Data,
383
393
  Href,
384
- Plugins & { [K in PluginId]: PluginInstance<PluginData, PluginParams, PluginOutputs> }
394
+ Plugins & { [K in PluginId]: PluginInstance<PData, PParams, POutputs> }
385
395
  > {
386
396
  // Validate pluginId uniqueness
387
397
  if (pluginId in this.config.plugins) {
388
398
  throw new Error(`Plugin '${pluginId}' already registered`);
389
399
  }
390
400
 
391
- const instance: PluginInstance<PluginData, PluginParams, PluginOutputs> = {
401
+ const instance: PluginInstance<PData, PParams, POutputs> = {
392
402
  model: plugin,
393
403
  inputs: (params ?? {}) as ParamsInputErased,
394
404
  };
@@ -399,6 +409,7 @@ export class BlockModelV3<
399
409
  ...this.config.plugins,
400
410
  [pluginId]: instance,
401
411
  },
412
+ featureFlags: mergeFeatureFlags(this.config.featureFlags, plugin.featureFlags ?? {}),
402
413
  });
403
414
  }
404
415
 
@@ -423,15 +434,16 @@ export class BlockModelV3<
423
434
  // Build plugin registry
424
435
  const { plugins } = this.config;
425
436
  const pluginRegistry: Record<string, PluginName> = {};
426
- for (const [pluginId, { model }] of Object.entries(plugins)) {
427
- pluginRegistry[pluginId] = model.name;
437
+ const pluginHandles = Object.keys(plugins) as PluginHandle[];
438
+ for (const handle of pluginHandles) {
439
+ pluginRegistry[handle] = plugins[handle].model.name;
428
440
  }
429
441
 
430
442
  const { dataModel, argsFunction, prerunArgsFunction } = this.config;
431
443
 
432
- function getPlugin(pluginId: string): PluginInstance {
433
- const plugin = plugins[pluginId];
434
- if (!plugin) throw new Error(`Plugin model not found for '${pluginId}'`);
444
+ function getPlugin(handle: PluginHandle): PluginInstance {
445
+ const plugin = plugins[handle];
446
+ if (!plugin) throw new Error(`Plugin model not found for '${handle}'`);
435
447
  return plugin;
436
448
  }
437
449
 
@@ -443,14 +455,14 @@ export class BlockModelV3<
443
455
  migrateStorage(currentStorageJson, {
444
456
  migrateBlockData: (v) => dataModel.migrate(v),
445
457
  getPluginRegistry: () => pluginRegistry,
446
- migratePluginData: (pluginId, v) => getPlugin(pluginId).model.dataModel.migrate(v),
447
- createPluginData: (pluginId) => getPlugin(pluginId).model.dataModel.getDefaultData(),
458
+ migratePluginData: (handle, v) => getPlugin(handle).model.dataModel.migrate(v),
459
+ createPluginData: (handle) => getPlugin(handle).model.dataModel.getDefaultData(),
448
460
  }),
449
461
  [BlockStorageFacadeCallbacks.StorageInitial]: () =>
450
462
  createInitialStorage({
451
463
  getDefaultBlockData: () => dataModel.getDefaultData(),
452
464
  getPluginRegistry: () => pluginRegistry,
453
- createPluginData: (pluginId) => getPlugin(pluginId).model.dataModel.getDefaultData(),
465
+ createPluginData: (handle) => getPlugin(handle).model.dataModel.getDefaultData(),
454
466
  }),
455
467
  [BlockStorageFacadeCallbacks.ArgsDerive]: (storageJson) =>
456
468
  deriveArgsFromStorage(storageJson, argsFunction),
@@ -460,7 +472,8 @@ export class BlockModelV3<
460
472
 
461
473
  // Register plugin input and output lambdas
462
474
  const pluginOutputs: Record<string, ConfigRenderLambda> = {};
463
- for (const [pluginId, { model, inputs }] of Object.entries(plugins)) {
475
+ for (const handle of pluginHandles) {
476
+ const { model, inputs } = plugins[handle];
464
477
  // Wrap plugin param lambdas: close over BlockRenderCtx creation
465
478
  const wrappedInputs: Record<string, () => unknown> = {};
466
479
  for (const [paramKey, paramFn] of Object.entries(inputs)) {
@@ -470,10 +483,10 @@ export class BlockModelV3<
470
483
  // Register plugin outputs (in config pack, evaluated by middle layer)
471
484
  const outputs = model.outputs as Record<string, (ctx: PluginRenderCtx) => unknown>;
472
485
  for (const [outputKey, outputFn] of Object.entries(outputs)) {
473
- const key = `plugin-output#${pluginId}#${outputKey}`;
486
+ const key = pluginOutputKey(handle, outputKey);
474
487
  pluginOutputs[key] = createAndRegisterRenderLambda({
475
488
  handle: key,
476
- lambda: () => outputFn(new PluginRenderCtx(pluginId, wrappedInputs)),
489
+ lambda: () => outputFn(new PluginRenderCtx(handle, wrappedInputs)),
477
490
  });
478
491
  }
479
492
  }
@@ -528,6 +541,7 @@ export class BlockModelV3<
528
541
  },
529
542
  ]),
530
543
  ),
544
+ pluginIds: pluginHandles,
531
545
  },
532
546
  } as any;
533
547
  }
@@ -452,6 +452,7 @@ export class BlockModel<
452
452
  },
453
453
  ]),
454
454
  ),
455
+ pluginIds: [],
455
456
  },
456
457
  };
457
458
  }
@@ -14,6 +14,7 @@ import {
14
14
  type PluginName,
15
15
  type PluginRegistry,
16
16
  } from "./block_storage";
17
+ import type { PluginHandle } from "./plugin_handle";
17
18
 
18
19
  describe("BlockStorage", () => {
19
20
  describe("BLOCK_STORAGE_KEY and BLOCK_STORAGE_SCHEMA_VERSION", () => {
@@ -215,11 +216,11 @@ describe("BlockStorage", () => {
215
216
  pluginId: "chart1",
216
217
  value: { type: "bar" },
217
218
  });
218
- expect(getPluginData(storage, "chart1")).toEqual({ type: "bar" });
219
+ expect(getPluginData(storage, "chart1" as PluginHandle)).toEqual({ type: "bar" });
219
220
  });
220
221
 
221
222
  it("getPluginData should throw for missing plugin", () => {
222
- expect(() => getPluginData(baseStorage, "nonexistent")).toThrow(
223
+ expect(() => getPluginData(baseStorage, "nonexistent" as PluginHandle)).toThrow(
223
224
  "Plugin 'nonexistent' not found in block storage",
224
225
  );
225
226
  });
@@ -11,6 +11,7 @@
11
11
 
12
12
  import type { Branded } from "@milaboratories/pl-model-common";
13
13
  import type { DataMigrationResult, DataVersioned } from "./block_migrations";
14
+ import type { PluginHandle, PluginFactoryLike, InferFactoryData } from "./plugin_handle";
14
15
 
15
16
  // =============================================================================
16
17
  // Core Types
@@ -50,7 +51,7 @@ export type PluginName = Branded<string, "PluginName">;
50
51
  * Plugin registry - maps pluginId (unique within a block) to pluginName (globally unique plugin type).
51
52
  * Using a Record highlights that pluginIds must be unique within a block.
52
53
  */
53
- export type PluginRegistry = Record<string, PluginName>;
54
+ export type PluginRegistry = Record<PluginHandle, PluginName>;
54
55
 
55
56
  /**
56
57
  * Versioned data - used for both block data and plugin data
@@ -75,8 +76,8 @@ export type BlockStorage<TState = unknown> = {
75
76
  readonly [BLOCK_STORAGE_KEY]: BlockStorageSchemaVersion;
76
77
  /** Registry of plugins: pluginId -> pluginName */
77
78
  __pluginRegistry?: PluginRegistry;
78
- /** Plugin-specific data, keyed by pluginId */
79
- __plugins?: Record<string, VersionedData<unknown>>;
79
+ /** Plugin-specific data, keyed by plugin handle */
80
+ __plugins?: Record<PluginHandle, VersionedData<unknown>>;
80
81
  } & VersionedData<TState>;
81
82
 
82
83
  /**
@@ -176,7 +177,7 @@ export function deriveDataFromStorage<TData = unknown>(rawStorage: unknown): TDa
176
177
  /** Payload for storage mutation operations. SDK defines specific operations. */
177
178
  export type MutateStoragePayload<T = unknown> =
178
179
  | { operation: "update-block-data"; value: T }
179
- | { operation: "update-plugin-data"; pluginId: string; value: unknown };
180
+ | { operation: "update-plugin-data"; pluginId: PluginHandle; value: unknown };
180
181
 
181
182
  /**
182
183
  * Updates the data in BlockStorage (immutable)
@@ -261,13 +262,13 @@ export interface MigrateBlockStorageConfig {
261
262
  migrateBlockData: (versioned: DataVersioned<unknown>) => DataMigrationResult<unknown>;
262
263
  /** Migrate each plugin's data. Return undefined to remove the plugin. */
263
264
  migratePluginData: (
264
- pluginId: string,
265
+ handle: PluginHandle,
265
266
  versioned: DataVersioned<unknown>,
266
267
  ) => DataMigrationResult<unknown> | undefined;
267
268
  /** The new plugin registry after migration (pluginId -> pluginName) */
268
269
  newPluginRegistry: PluginRegistry;
269
270
  /** Factory to create initial data for new plugins */
270
- createPluginData: (pluginId: string) => DataVersioned<unknown>;
271
+ createPluginData: (handle: PluginHandle) => DataVersioned<unknown>;
271
272
  }
272
273
 
273
274
  /**
@@ -334,33 +335,34 @@ export function migrateBlockStorage(
334
335
  // Step 2: Migrate plugins
335
336
  const oldPlugins = storage.__plugins ?? {};
336
337
  const oldRegistry = storage.__pluginRegistry ?? {};
337
- const newPlugins: Record<string, VersionedData<unknown>> = {};
338
+ const newPlugins: Record<PluginHandle, VersionedData<unknown>> = {};
338
339
 
339
- for (const [pluginId, pluginName] of Object.entries(newPluginRegistry)) {
340
- const existingEntry = oldPlugins[pluginId];
341
- const existingName = oldRegistry[pluginId];
340
+ for (const [key, pluginName] of Object.entries(newPluginRegistry)) {
341
+ const handle = key as PluginHandle;
342
+ const existingEntry = oldPlugins[handle];
343
+ const existingName = oldRegistry[handle];
342
344
 
343
345
  try {
344
346
  if (existingEntry && existingName === pluginName) {
345
347
  // Plugin exists with same type - migrate its data
346
- const migrated = migratePluginData(pluginId, {
348
+ const migrated = migratePluginData(handle, {
347
349
  version: existingEntry.__dataVersion,
348
350
  data: existingEntry.__data,
349
351
  });
350
352
  if (migrated) {
351
- newPlugins[pluginId] = { __dataVersion: migrated.version, __data: migrated.data };
353
+ newPlugins[handle] = { __dataVersion: migrated.version, __data: migrated.data };
352
354
  }
353
355
  // If undefined returned, plugin is intentionally removed
354
356
  } else {
355
357
  // New plugin or type changed - create with initial data
356
- const initial = createPluginData(pluginId);
357
- newPlugins[pluginId] = { __dataVersion: initial.version, __data: initial.data };
358
+ const initial = createPluginData(handle);
359
+ newPlugins[handle] = { __dataVersion: initial.version, __data: initial.data };
358
360
  }
359
361
  } catch (error) {
360
362
  return {
361
363
  success: false,
362
364
  error: error instanceof Error ? error.message : String(error),
363
- failedAt: pluginId,
365
+ failedAt: handle,
364
366
  };
365
367
  }
366
368
  }
@@ -384,14 +386,20 @@ export function migrateBlockStorage(
384
386
  * Gets plugin-specific data from block storage.
385
387
  * Accepts raw storage (any format) and normalizes internally.
386
388
  *
389
+ * When called with a typed PluginHandle<F>, the return type is automatically
390
+ * inferred from the factory's phantom `__types.data` field.
391
+ *
387
392
  * @param rawStorage - Raw block storage (may be legacy format or BlockStorage)
388
- * @param pluginId - The plugin instance id
389
- * @returns The plugin data
390
- * @throws If pluginId is not found in storage
393
+ * @param handle - The plugin handle (branded plugin instance id)
394
+ * @returns The plugin data, typed via factory inference
395
+ * @throws If plugin is not found in storage
391
396
  */
392
- export function getPluginData<TData = unknown>(rawStorage: unknown, pluginId: string): TData {
397
+ export function getPluginData<F extends PluginFactoryLike>(
398
+ rawStorage: unknown,
399
+ handle: PluginHandle<F>,
400
+ ): InferFactoryData<F> {
393
401
  const storage = normalizeBlockStorage(rawStorage);
394
- const pluginEntry = storage.__plugins?.[pluginId];
395
- if (!pluginEntry) throw new Error(`Plugin '${pluginId}' not found in block storage`);
396
- return pluginEntry.__data as TData;
402
+ const pluginEntry = storage.__plugins?.[handle];
403
+ if (!pluginEntry) throw new Error(`Plugin '${handle}' not found in block storage`);
404
+ return pluginEntry.__data as InferFactoryData<F>;
397
405
  }
@@ -24,6 +24,7 @@ import {
24
24
  normalizeBlockStorage,
25
25
  updateStorageData,
26
26
  } from "./block_storage";
27
+ import type { PluginHandle } from "./plugin_handle";
27
28
 
28
29
  import { stringifyJson, type StringifiedJson } from "@milaboratories/pl-model-common";
29
30
  import type { DataMigrationResult, DataVersioned } from "./block_migrations";
@@ -37,17 +38,17 @@ export interface MigrationHooks {
37
38
  migrateBlockData: (versioned: DataVersioned<unknown>) => DataMigrationResult<unknown>;
38
39
  getPluginRegistry: () => PluginRegistry;
39
40
  migratePluginData: (
40
- pluginId: string,
41
+ handle: PluginHandle,
41
42
  versioned: DataVersioned<unknown>,
42
43
  ) => DataMigrationResult<unknown> | undefined;
43
- createPluginData: (pluginId: string) => DataVersioned<unknown>;
44
+ createPluginData: (handle: PluginHandle) => DataVersioned<unknown>;
44
45
  }
45
46
 
46
47
  /** Dependencies for initial storage creation */
47
48
  export interface InitialStorageHooks {
48
49
  getDefaultBlockData: () => DataVersioned<unknown>;
49
50
  getPluginRegistry: () => PluginRegistry;
50
- createPluginData: (pluginId: string) => DataVersioned<unknown>;
51
+ createPluginData: (handle: PluginHandle) => DataVersioned<unknown>;
51
52
  }
52
53
 
53
54
  /**
@@ -233,10 +234,10 @@ export function createInitialStorage(hooks: InitialStorageHooks): StringifiedJso
233
234
  const blockDefault = hooks.getDefaultBlockData();
234
235
  const pluginRegistry = hooks.getPluginRegistry();
235
236
 
236
- const plugins: Record<string, VersionedData<unknown>> = {};
237
- for (const pluginId of Object.keys(pluginRegistry)) {
238
- const initial = hooks.createPluginData(pluginId);
239
- plugins[pluginId] = { __dataVersion: initial.version, __data: initial.data };
237
+ const plugins: Record<PluginHandle, VersionedData<unknown>> = {};
238
+ for (const handle of Object.keys(pluginRegistry) as PluginHandle[]) {
239
+ const initial = hooks.createPluginData(handle);
240
+ plugins[handle] = { __dataVersion: initial.version, __data: initial.data };
240
241
  }
241
242
 
242
243
  const storage: BlockStorage = {
@@ -1,55 +1,9 @@
1
- import type {
2
- AxisId,
3
- AxisSpecNormalized,
4
- CanonicalizedJson,
5
- PColumn,
6
- PColumnSpec,
7
- PFrameHandle,
8
- PObjectId,
9
- } from "@milaboratories/pl-model-common";
10
- import {
11
- Annotation,
12
- canonicalizeJson,
13
- getAxisId,
14
- getColumnIdAndSpec,
15
- LinkerMap,
16
- matchAxisId,
17
- readAnnotation,
18
- readAnnotationJson,
19
- stringifyJson,
20
- } from "@milaboratories/pl-model-common";
1
+ import type { PColumn, PColumnSpec, PFrameHandle } from "@milaboratories/pl-model-common";
2
+ import { Annotation, readAnnotationJson } from "@milaboratories/pl-model-common";
21
3
  import type { PColumnDataUniversal, RenderCtxBase } from "../render";
22
4
  import { getAllRelatedColumns, getRelatedColumns } from "../pframe_utils/columns";
23
-
24
- /** Create id for column copy with added keys in axes domains */
25
- const colId = (id: PObjectId, domains: (Record<string, string> | undefined)[]) => {
26
- let wid = id.toString();
27
- domains?.forEach((domain) => {
28
- if (domain) {
29
- for (const [k, v] of Object.entries(domain)) {
30
- wid += k;
31
- wid += v;
32
- }
33
- }
34
- });
35
- return wid;
36
- };
37
-
38
- /** All combinations with 1 key from each list */
39
- function getKeysCombinations(idsLists: AxisId[][]) {
40
- if (!idsLists.length) {
41
- return [];
42
- }
43
- let result: AxisId[][] = [[]];
44
- idsLists.forEach((list) => {
45
- const nextResult: AxisId[][] = [];
46
- list.forEach((key) => {
47
- nextResult.push(...result.map((resultItem) => [...resultItem, key]));
48
- });
49
- result = nextResult;
50
- });
51
- return result;
52
- }
5
+ export type { AxesVault } from "../pframe_utils/axes";
6
+ export { enrichCompatible, getAvailableWithLinkersAxes } from "../pframe_utils/axes";
53
7
 
54
8
  export function isHiddenFromGraphColumn(column: PColumnSpec): boolean {
55
9
  return !!readAnnotationJson(column, Annotation.HideDataFromGraphs);
@@ -59,123 +13,6 @@ export function isHiddenFromUIColumn(column: PColumnSpec): boolean {
59
13
  return !!readAnnotationJson(column, Annotation.HideDataFromUi);
60
14
  }
61
15
 
62
- export type AxesVault = Map<CanonicalizedJson<AxisId>, AxisSpecNormalized>;
63
-
64
- export function getAvailableWithLinkersAxes(
65
- linkerColumns: PColumn<PColumnDataUniversal>[],
66
- blockAxes: AxesVault,
67
- ): AxesVault {
68
- const linkerMap = LinkerMap.fromColumns(linkerColumns.map(getColumnIdAndSpec));
69
- const availableAxes = linkerMap.getReachableByLinkersAxesFromAxesNormalized(
70
- [...blockAxes.values()],
71
- (linkerKeyId, sourceAxisId) => matchAxisId(sourceAxisId, linkerKeyId),
72
- );
73
-
74
- return new Map(
75
- availableAxes.map((axisSpec) => {
76
- const id = getAxisId(axisSpec);
77
- return [canonicalizeJson(id), axisSpec];
78
- }),
79
- );
80
- }
81
- /** Add columns with fully compatible axes created from partial compatible ones */
82
- export function enrichCompatible<T extends Omit<PColumn<PColumnDataUniversal>, "data">>(
83
- blockAxes: AxesVault,
84
- columns: T[],
85
- ): T[] {
86
- return columns.flatMap((column) => getAdditionalColumnsForColumn(blockAxes, column));
87
- }
88
-
89
- function getAdditionalColumnsForColumn<T extends Omit<PColumn<PColumnDataUniversal>, "data">>(
90
- blockAxes: AxesVault,
91
- column: T,
92
- ): T[] {
93
- const columnAxesIds = column.spec.axesSpec.map(getAxisId);
94
-
95
- if (columnAxesIds.every((id) => blockAxes.has(canonicalizeJson(id)))) {
96
- return [column]; // the column is compatible with its own domains without modifications
97
- }
98
-
99
- // options with different possible domains for every axis of secondary column
100
- const secondaryIdsOptions = columnAxesIds.map((id) => {
101
- const result = [];
102
- for (const [_, mainId] of blockAxes) {
103
- if (matchAxisId(mainId, id) && !matchAxisId(id, mainId)) {
104
- result.push(mainId);
105
- }
106
- }
107
- return result;
108
- });
109
- // all possible combinations of axes with added domains
110
- const secondaryIdsVariants = getKeysCombinations(secondaryIdsOptions);
111
-
112
- // sets of added to column domain fields
113
- const allAddedDomainValues = new Set<string>();
114
- const addedNotToAllVariantsDomainValues = new Set<string>();
115
- const addedByVariantsDomainValues = secondaryIdsVariants.map((idsList) => {
116
- const addedSet = new Set<string>();
117
- idsList.map((axisId, idx) => {
118
- const d1 = column.spec.axesSpec[idx].domain;
119
- const d2 = axisId.domain;
120
- Object.entries(d2 ?? {}).forEach(([key, value]) => {
121
- if (d1?.[key] === undefined) {
122
- const item = JSON.stringify([key, value]);
123
- addedSet.add(item);
124
- allAddedDomainValues.add(item);
125
- }
126
- });
127
- return {
128
- ...axisId,
129
- annotations: column.spec.axesSpec[idx].annotations,
130
- };
131
- });
132
- return addedSet;
133
- });
134
- [...allAddedDomainValues].forEach((addedPart) => {
135
- if (addedByVariantsDomainValues.some((s) => !s.has(addedPart))) {
136
- addedNotToAllVariantsDomainValues.add(addedPart);
137
- }
138
- });
139
-
140
- const additionalColumns = secondaryIdsVariants.map((idsList, idx) => {
141
- const id = colId(
142
- column.id,
143
- idsList.map((id) => id.domain),
144
- );
145
-
146
- const label = readAnnotation(column.spec, Annotation.Label) ?? "";
147
- const labelDomainPart = [...addedByVariantsDomainValues[idx]]
148
- .filter((str) => addedNotToAllVariantsDomainValues.has(str))
149
- .sort()
150
- .map((v) => JSON.parse(v)?.[1]) // use in labels only domain values, but sort them by key to save the same order in all column variants
151
- .join(" / ");
152
-
153
- const annotations: Annotation = {
154
- ...column.spec.annotations,
155
- [Annotation.Graph.IsVirtual]: stringifyJson(true),
156
- };
157
- if (label || labelDomainPart) {
158
- annotations[Annotation.Label] =
159
- label && labelDomainPart ? label + " / " + labelDomainPart : label + labelDomainPart;
160
- }
161
-
162
- return {
163
- ...column,
164
- id: id as PObjectId,
165
- spec: {
166
- ...column.spec,
167
- axesSpec: idsList.map((axisId, idx) => ({
168
- ...axisId,
169
- annotations: column.spec.axesSpec[idx].annotations,
170
- })),
171
- annotations,
172
- },
173
- };
174
- });
175
-
176
- return [column, ...additionalColumns];
177
- }
178
-
179
16
  /**
180
17
  The aim of createPFrameForGraphs: to create pframe with block’s columns and all compatible columns from result pool
181
18
  (including linker columns and all label columns).
package/src/index.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  export * from "./block_state_patch";
2
2
  export * from "./block_state_util";
3
+ export * from "./plugin_handle";
3
4
  export * from "./block_storage";
4
5
  export * from "./block_storage_facade";
5
6
  export * from "./block_model_legacy";
@@ -14,7 +15,7 @@ export {
14
15
  makeDataVersioned,
15
16
  } from "./block_migrations";
16
17
  export type { LegacyV1State } from "./block_migrations";
17
- export { PluginModel } from "./plugin_model";
18
+ export * from "./plugin_model";
18
19
  export * from "./bconfig";
19
20
  export * from "./components";
20
21
  export * from "./config";