@platforma-sdk/model 1.89.0 → 1.90.2
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/columns/columns_collection.cjs +18 -0
- package/dist/columns/columns_collection.cjs.map +1 -1
- package/dist/columns/columns_collection.d.ts +21 -1
- package/dist/columns/columns_collection.d.ts.map +1 -1
- package/dist/columns/columns_collection.js +18 -0
- package/dist/columns/columns_collection.js.map +1 -1
- package/dist/columns/index.d.ts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/package.cjs +1 -1
- package/dist/package.js +1 -1
- package/dist/render/util/column_collection.cjs +4 -1
- package/dist/render/util/column_collection.cjs.map +1 -1
- package/dist/render/util/column_collection.d.ts.map +1 -1
- package/dist/render/util/column_collection.js +4 -1
- package/dist/render/util/column_collection.js.map +1 -1
- package/package.json +7 -7
- package/src/columns/__test_helpers__/collection_driver.ts +3 -0
- package/src/columns/columns_collection.test.ts +47 -0
- package/src/columns/columns_collection.ts +33 -0
- package/src/render/util/column_collection.test.ts +72 -0
- package/src/render/util/column_collection.ts +8 -1
|
@@ -66,6 +66,24 @@ var ColumnsCollectionImpl = class ColumnsCollectionImpl {
|
|
|
66
66
|
filter(options) {
|
|
67
67
|
return new ColumnsCollectionImpl(this.driver.filter(this.handle, options), this.driver);
|
|
68
68
|
}
|
|
69
|
+
/**
|
|
70
|
+
* Finds the roots the given columns hang off: the columns that, used as
|
|
71
|
+
* `anchors` of {@link discover}, would reach them. One entry per root, leaf
|
|
72
|
+
* and linker path; entries whose columns are not yet resolvable are skipped.
|
|
73
|
+
*/
|
|
74
|
+
discoverRoots(options) {
|
|
75
|
+
return this.driver.discoverRoots(this.handle, options).flatMap((ids) => {
|
|
76
|
+
const root = require_index.ColumnRecipe(ids.root);
|
|
77
|
+
const leaf = require_index.ColumnRecipe(ids.leaf);
|
|
78
|
+
const path = ids.path.map((id) => require_index.ColumnRecipe(id)).filter((c) => !(0, es_toolkit.isNil)(c));
|
|
79
|
+
if ((0, es_toolkit.isNil)(root) || (0, es_toolkit.isNil)(leaf) || path.length !== ids.path.length) return [];
|
|
80
|
+
return [{
|
|
81
|
+
root,
|
|
82
|
+
leaf,
|
|
83
|
+
path
|
|
84
|
+
}];
|
|
85
|
+
});
|
|
86
|
+
}
|
|
69
87
|
};
|
|
70
88
|
function toSerializedSources(source, ctx) {
|
|
71
89
|
if (source === "result_pool") return [{ kind: "result_pool" }];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"columns_collection.cjs","names":["getService","ColumnRecipe","isNil","TreeNodeAccessor","isColumnProvider","getCfgRenderCtx","MainAccessorName","StagingAccessorName"],"sources":["../../src/columns/columns_collection.ts"],"sourcesContent":["import type {\n CollectionHandle,\n ColumnUniversalId,\n ColumnsCollectionDriverModel,\n ColumnsDiscoverOptions,\n ColumnsFilterOptions,\n SerializedColumnsSource,\n} from \"@milaboratories/pl-model-common\";\nimport type { GlobalCfgRenderCtx } from \"../render/internal\";\nimport { MainAccessorName, StagingAccessorName } from \"../render/internal\";\nimport type { ColumnsSource } from \"./column_providers\";\nimport { isColumnProvider } from \"./column_providers\";\nimport { TreeNodeAccessor } from \"../render/accessor\";\nimport { getService } from \"../services/get_services\";\nimport { getCfgRenderCtx } from \"../internal\";\nimport { ColumnRecipe } from \"./column_recipes\";\nimport { isNil } from \"es-toolkit\";\n\nexport interface ColumnsCollectionDeps {\n /** Render ctx used both for service resolution and for default ctx sources. */\n readonly ctx?: GlobalCfgRenderCtx;\n /** Override the resolved `columnsCollection` service — primarily for tests. */\n readonly driver?: ColumnsCollectionDriverModel;\n}\n\n/**\n * Shorthand literals accepted inside `ColumnsCollection`'s `sources`\n * array, expanded against the active render ctx:\n *\n * - `\"result_pool\"` – fan-out into the host's upstream-block result pool.\n * - `\"current_block\"` – main outputs + prerun (staging) accessors of the\n * current block, when present.\n */\nexport type ColumnsSourceShorthand = \"result_pool\" | \"current_block\";\n\n/**\n * Build a {@link ColumnsCollection} from sandbox-side source descriptors.\n * Resolves the `columnsCollection` driver (either from `deps.driver` or via\n * `getService(\"columnsCollection\")`) and asks the host to mint a fresh\n * handle covering the supplied sources. Pass `sources === undefined` to\n * fall back to the active render ctx (main outputs + prerun + result pool).\n *\n * `sources` accepts {@link ColumnsSourceShorthand} string literals\n * (`\"result_pool\"`, `\"current_block\"`) for the common ctx-derived sources.\n */\nexport function ColumnsCollection(\n sources?: (ColumnsCollection | ColumnsSource | ColumnsSourceShorthand)[],\n deps?: ColumnsCollectionDeps,\n): ColumnsCollection {\n const driver = deps?.driver ?? getService(\"columnsCollection\", { ctx: deps?.ctx });\n const serialized: SerializedColumnsSource[] = sources\n ? sources.flatMap((s) => toSerializedSources(s, deps?.ctx))\n : defaultCtxSources(deps?.ctx);\n return new ColumnsCollectionImpl(driver.create(serialized), driver);\n}\n\nexport function isColumnsCollection(value: unknown): value is ColumnsCollection {\n return value instanceof ColumnsCollectionImpl;\n}\n\n/**\n * Sandbox proxy over the host-side `ColumnsCollection` driver. The driver\n * owns all column-set state; this object only carries an opaque\n * {@link CollectionHandle} plus a reference to the driver service.\n *\n * Construct via {@link ColumnsCollection} — the bare constructor is a\n * trivial `(handle, driver)` pair so that `addSource` / `discover` / `filter`\n * can rebind a freshly-minted handle without going through source\n * serialisation again.\n *\n * Every method returning a `ColumnsCollection` mints a fresh handle on the\n * host — the host VM bridge pins it to the active render ctx, so the sandbox\n * never has to manage refcounts.\n */\nexport class ColumnsCollectionImpl {\n constructor(\n public readonly handle: CollectionHandle,\n private readonly driver: ColumnsCollectionDriverModel,\n ) {}\n\n isEmpty(): boolean {\n return this.driver.isEmpty(this.handle);\n }\n\n isFinal(): boolean {\n return this.driver.isFinal(this.handle);\n }\n\n getColumnIds(): ColumnUniversalId[] {\n return this.driver.getColumns(this.handle);\n }\n\n getColumns(): ColumnRecipe[] {\n return this.getColumnIds()\n .map((id) => ColumnRecipe(id))\n .filter((c): c is ColumnRecipe => !isNil(c));\n }\n\n addSource(source: ColumnsSource | ColumnsCollection): ColumnsCollection {\n return new ColumnsCollectionImpl(\n this.driver.addSource(this.handle, toSerializedSources(source)),\n this.driver,\n );\n }\n\n discover(options: ColumnsDiscoverOptions): ColumnsCollection {\n return new ColumnsCollectionImpl(this.driver.discover(this.handle, options), this.driver);\n }\n\n filter(options: ColumnsFilterOptions): ColumnsCollection {\n return new ColumnsCollectionImpl(this.driver.filter(this.handle, options), this.driver);\n }\n}\n\n/** Public type alias — value of the same name is the factory function above. */\nexport type ColumnsCollection = ColumnsCollectionImpl;\n\nfunction toSerializedSources(\n source: ColumnsCollection | ColumnsSource | ColumnsSourceShorthand,\n ctx?: GlobalCfgRenderCtx,\n): SerializedColumnsSource[] {\n if (source === \"result_pool\") {\n return [{ kind: \"result_pool\" }];\n }\n if (source === \"current_block\") {\n return currentBlockSources(ctx);\n }\n if (source instanceof ColumnsCollectionImpl) {\n return [{ kind: \"collection\", handle: source.handle }];\n }\n if (source instanceof TreeNodeAccessor) {\n return [{ kind: \"accessor\", accessor: source.handle, path: source.resolvePath }];\n }\n if (isColumnArray(source)) {\n return [{ kind: \"ids\", ids: source.columns.map((c) => c.id), isFinal: source.isFinal }];\n }\n if (isColumnProvider(source)) {\n return [{ kind: \"ids\", ids: source.getColumns().map((c) => c.id), isFinal: source.isFinal() }];\n }\n throw new Error(\"ColumnsCollection: unrecognised ColumnsSource shape\");\n}\n\nfunction isColumnArray(source: unknown): source is {\n columns: ReadonlyArray<{ id: ColumnUniversalId; spec?: unknown; data?: unknown }>;\n isFinal: boolean;\n} {\n if (typeof source !== \"object\" || source === null) return false;\n const s = source as { columns?: unknown; isFinal?: unknown };\n return Array.isArray(s.columns) && typeof s.isFinal === \"boolean\";\n}\n\nfunction currentBlockSources(ctx?: GlobalCfgRenderCtx): SerializedColumnsSource[] {\n const renderCtx = ctx ?? getCfgRenderCtx();\n const sources: SerializedColumnsSource[] = [];\n\n const outputs = renderCtx.getAccessorHandleByName(MainAccessorName);\n if (outputs !== undefined) {\n sources.push({ kind: \"accessor\", accessor: outputs, path: [MainAccessorName] });\n }\n const prerun = renderCtx.getAccessorHandleByName(StagingAccessorName);\n if (prerun !== undefined) {\n sources.push({ kind: \"accessor\", accessor: prerun, path: [StagingAccessorName] });\n }\n\n return sources;\n}\n\nfunction defaultCtxSources(ctx?: GlobalCfgRenderCtx): SerializedColumnsSource[] {\n return [...currentBlockSources(ctx), { kind: \"result_pool\" }];\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AA6CA,SAAgB,kBACd,SACA,MACmB;CACnB,MAAM,SAAS,MAAM,UAAUA,qBAAAA,WAAW,qBAAqB,EAAE,KAAK,MAAM,IAAI,CAAC;CACjF,MAAM,aAAwC,UAC1C,QAAQ,SAAS,MAAM,oBAAoB,GAAG,MAAM,GAAG,CAAC,IACxD,kBAAkB,MAAM,GAAG;CAC/B,OAAO,IAAI,sBAAsB,OAAO,OAAO,UAAU,GAAG,MAAM;AACpE;AAEA,SAAgB,oBAAoB,OAA4C;CAC9E,OAAO,iBAAiB;AAC1B;;;;;;;;;;;;;;;AAgBA,IAAa,wBAAb,MAAa,sBAAsB;CAEf;CACC;CAFnB,YACE,QACA,QACA;EAFgB,KAAA,SAAA;EACC,KAAA,SAAA;CAChB;CAEH,UAAmB;EACjB,OAAO,KAAK,OAAO,QAAQ,KAAK,MAAM;CACxC;CAEA,UAAmB;EACjB,OAAO,KAAK,OAAO,QAAQ,KAAK,MAAM;CACxC;CAEA,eAAoC;EAClC,OAAO,KAAK,OAAO,WAAW,KAAK,MAAM;CAC3C;CAEA,aAA6B;EAC3B,OAAO,KAAK,aAAa,CAAC,CACvB,KAAK,OAAOC,cAAAA,aAAa,EAAE,CAAC,CAAC,CAC7B,QAAQ,MAAyB,EAAA,GAACC,WAAAA,MAAAA,CAAM,CAAC,CAAC;CAC/C;CAEA,UAAU,QAA8D;EACtE,OAAO,IAAI,sBACT,KAAK,OAAO,UAAU,KAAK,QAAQ,oBAAoB,MAAM,CAAC,GAC9D,KAAK,MACP;CAC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AQ,KAAK;EAAE,MAAM;EAAY,UAAU;EAAS,MAAM,CAACA,mBAAAA,gBAAgB;CAAE,CAAC;CAEhF,MAAM,SAAS,UAAU,wBAAwBC,mBAAAA,mBAAmB;CACpE,IAAI,WAAW,KAAA,GACb,QAAQ,KAAK;EAAE,MAAM;EAAY,UAAU;EAAQ,MAAM,CAACA,mBAAAA,mBAAmB;CAAE,CAAC;CAGlF,OAAO;AACT;AAEA,SAAS,kBAAkB,KAAqD;CAC9E,OAAO,CAAC,GAAG,oBAAoB,GAAG,GAAG,EAAE,MAAM,cAAc,CAAC;AAC9D"}
|
|
1
|
+
{"version":3,"file":"columns_collection.cjs","names":["getService","ColumnRecipe","isNil","TreeNodeAccessor","isColumnProvider","getCfgRenderCtx","MainAccessorName","StagingAccessorName"],"sources":["../../src/columns/columns_collection.ts"],"sourcesContent":["import type {\n CollectionHandle,\n ColumnUniversalId,\n ColumnsCollectionDriverModel,\n ColumnsDiscoverOptions,\n ColumnsFilterOptions,\n DiscoverRootsOptions,\n SerializedColumnsSource,\n} from \"@milaboratories/pl-model-common\";\nimport type { GlobalCfgRenderCtx } from \"../render/internal\";\nimport { MainAccessorName, StagingAccessorName } from \"../render/internal\";\nimport type { ColumnsSource } from \"./column_providers\";\nimport { isColumnProvider } from \"./column_providers\";\nimport { TreeNodeAccessor } from \"../render/accessor\";\nimport { getService } from \"../services/get_services\";\nimport { getCfgRenderCtx } from \"../internal\";\nimport { ColumnRecipe } from \"./column_recipes\";\nimport { isNil } from \"es-toolkit\";\n\nexport interface ColumnsCollectionDeps {\n /** Render ctx used both for service resolution and for default ctx sources. */\n readonly ctx?: GlobalCfgRenderCtx;\n /** Override the resolved `columnsCollection` service — primarily for tests. */\n readonly driver?: ColumnsCollectionDriverModel;\n}\n\n/**\n * Shorthand literals accepted inside `ColumnsCollection`'s `sources`\n * array, expanded against the active render ctx:\n *\n * - `\"result_pool\"` – fan-out into the host's upstream-block result pool.\n * - `\"current_block\"` – main outputs + prerun (staging) accessors of the\n * current block, when present.\n */\nexport type ColumnsSourceShorthand = \"result_pool\" | \"current_block\";\n\n/**\n * Build a {@link ColumnsCollection} from sandbox-side source descriptors.\n * Resolves the `columnsCollection` driver (either from `deps.driver` or via\n * `getService(\"columnsCollection\")`) and asks the host to mint a fresh\n * handle covering the supplied sources. Pass `sources === undefined` to\n * fall back to the active render ctx (main outputs + prerun + result pool).\n *\n * `sources` accepts {@link ColumnsSourceShorthand} string literals\n * (`\"result_pool\"`, `\"current_block\"`) for the common ctx-derived sources.\n */\nexport function ColumnsCollection(\n sources?: (ColumnsCollection | ColumnsSource | ColumnsSourceShorthand)[],\n deps?: ColumnsCollectionDeps,\n): ColumnsCollection {\n const driver = deps?.driver ?? getService(\"columnsCollection\", { ctx: deps?.ctx });\n const serialized: SerializedColumnsSource[] = sources\n ? sources.flatMap((s) => toSerializedSources(s, deps?.ctx))\n : defaultCtxSources(deps?.ctx);\n return new ColumnsCollectionImpl(driver.create(serialized), driver);\n}\n\nexport function isColumnsCollection(value: unknown): value is ColumnsCollection {\n return value instanceof ColumnsCollectionImpl;\n}\n\n/**\n * A root found by {@link ColumnsCollectionImpl.discoverRoots}: `leaf` is the\n * requested column exactly as `discover({ anchors: { r: root } })` would\n * return it — carrying the linker `path` and qualifications — so the table is\n * built from `root` as the anchor plus `leaf`.\n */\nexport interface DiscoveredRoot {\n /** The column the leaf hangs off. */\n readonly root: ColumnRecipe;\n /** The requested column, discovered from the root. */\n readonly leaf: ColumnRecipe;\n /** Linker columns from the root to the leaf; empty when they join directly. */\n readonly path: ColumnRecipe[];\n}\n\n/**\n * Sandbox proxy over the host-side `ColumnsCollection` driver. The driver\n * owns all column-set state; this object only carries an opaque\n * {@link CollectionHandle} plus a reference to the driver service.\n *\n * Construct via {@link ColumnsCollection} — the bare constructor is a\n * trivial `(handle, driver)` pair so that `addSource` / `discover` / `filter`\n * can rebind a freshly-minted handle without going through source\n * serialisation again.\n *\n * Every method returning a `ColumnsCollection` mints a fresh handle on the\n * host — the host VM bridge pins it to the active render ctx, so the sandbox\n * never has to manage refcounts.\n */\nexport class ColumnsCollectionImpl {\n constructor(\n public readonly handle: CollectionHandle,\n private readonly driver: ColumnsCollectionDriverModel,\n ) {}\n\n isEmpty(): boolean {\n return this.driver.isEmpty(this.handle);\n }\n\n isFinal(): boolean {\n return this.driver.isFinal(this.handle);\n }\n\n getColumnIds(): ColumnUniversalId[] {\n return this.driver.getColumns(this.handle);\n }\n\n getColumns(): ColumnRecipe[] {\n return this.getColumnIds()\n .map((id) => ColumnRecipe(id))\n .filter((c): c is ColumnRecipe => !isNil(c));\n }\n\n addSource(source: ColumnsSource | ColumnsCollection): ColumnsCollection {\n return new ColumnsCollectionImpl(\n this.driver.addSource(this.handle, toSerializedSources(source)),\n this.driver,\n );\n }\n\n discover(options: ColumnsDiscoverOptions): ColumnsCollection {\n return new ColumnsCollectionImpl(this.driver.discover(this.handle, options), this.driver);\n }\n\n filter(options: ColumnsFilterOptions): ColumnsCollection {\n return new ColumnsCollectionImpl(this.driver.filter(this.handle, options), this.driver);\n }\n\n /**\n * Finds the roots the given columns hang off: the columns that, used as\n * `anchors` of {@link discover}, would reach them. One entry per root, leaf\n * and linker path; entries whose columns are not yet resolvable are skipped.\n */\n discoverRoots(options: DiscoverRootsOptions): DiscoveredRoot[] {\n return this.driver.discoverRoots(this.handle, options).flatMap((ids) => {\n const root = ColumnRecipe(ids.root);\n const leaf = ColumnRecipe(ids.leaf);\n const path = ids.path\n .map((id) => ColumnRecipe(id))\n .filter((c): c is ColumnRecipe => !isNil(c));\n if (isNil(root) || isNil(leaf) || path.length !== ids.path.length) return [];\n return [{ root, leaf, path }];\n });\n }\n}\n\n/** Public type alias — value of the same name is the factory function above. */\nexport type ColumnsCollection = ColumnsCollectionImpl;\n\nfunction toSerializedSources(\n source: ColumnsCollection | ColumnsSource | ColumnsSourceShorthand,\n ctx?: GlobalCfgRenderCtx,\n): SerializedColumnsSource[] {\n if (source === \"result_pool\") {\n return [{ kind: \"result_pool\" }];\n }\n if (source === \"current_block\") {\n return currentBlockSources(ctx);\n }\n if (source instanceof ColumnsCollectionImpl) {\n return [{ kind: \"collection\", handle: source.handle }];\n }\n if (source instanceof TreeNodeAccessor) {\n return [{ kind: \"accessor\", accessor: source.handle, path: source.resolvePath }];\n }\n if (isColumnArray(source)) {\n return [{ kind: \"ids\", ids: source.columns.map((c) => c.id), isFinal: source.isFinal }];\n }\n if (isColumnProvider(source)) {\n return [{ kind: \"ids\", ids: source.getColumns().map((c) => c.id), isFinal: source.isFinal() }];\n }\n throw new Error(\"ColumnsCollection: unrecognised ColumnsSource shape\");\n}\n\nfunction isColumnArray(source: unknown): source is {\n columns: ReadonlyArray<{ id: ColumnUniversalId; spec?: unknown; data?: unknown }>;\n isFinal: boolean;\n} {\n if (typeof source !== \"object\" || source === null) return false;\n const s = source as { columns?: unknown; isFinal?: unknown };\n return Array.isArray(s.columns) && typeof s.isFinal === \"boolean\";\n}\n\nfunction currentBlockSources(ctx?: GlobalCfgRenderCtx): SerializedColumnsSource[] {\n const renderCtx = ctx ?? getCfgRenderCtx();\n const sources: SerializedColumnsSource[] = [];\n\n const outputs = renderCtx.getAccessorHandleByName(MainAccessorName);\n if (outputs !== undefined) {\n sources.push({ kind: \"accessor\", accessor: outputs, path: [MainAccessorName] });\n }\n const prerun = renderCtx.getAccessorHandleByName(StagingAccessorName);\n if (prerun !== undefined) {\n sources.push({ kind: \"accessor\", accessor: prerun, path: [StagingAccessorName] });\n }\n\n return sources;\n}\n\nfunction defaultCtxSources(ctx?: GlobalCfgRenderCtx): SerializedColumnsSource[] {\n return [...currentBlockSources(ctx), { kind: \"result_pool\" }];\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AA8CA,SAAgB,kBACd,SACA,MACmB;CACnB,MAAM,SAAS,MAAM,UAAUA,qBAAAA,WAAW,qBAAqB,EAAE,KAAK,MAAM,IAAI,CAAC;CACjF,MAAM,aAAwC,UAC1C,QAAQ,SAAS,MAAM,oBAAoB,GAAG,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,UAAU,wBAAwBC,mBAAAA,gBAAgB;CAClE,IAAI,YAAY,KAAA,GACd,QAAQ,KAAK;EAAE,MAAM;EAAY,UAAU;EAAS,MAAM,CAACA,mBAAAA,gBAAgB;CAAE,CAAC;CAEhF,MAAM,SAAS,UAAU,wBAAwBC,mBAAAA,mBAAmB;CACpE,IAAI,WAAW,KAAA,GACb,QAAQ,KAAK;EAAE,MAAM;EAAY,UAAU;EAAQ,MAAM,CAACA,mBAAAA,mBAAmB;CAAE,CAAC;CAGlF,OAAO;AACT;AAEA,SAAS,kBAAkB,KAAqD;CAC9E,OAAO,CAAC,GAAG,oBAAoB,GAAG,GAAG,EAAE,MAAM,cAAc,CAAC;AAC9D"}
|
|
@@ -2,7 +2,7 @@ import { GlobalCfgRenderCtx } from "../render/internal.js";
|
|
|
2
2
|
import { ColumnRecipe } from "./column_recipes/index.js";
|
|
3
3
|
import { ColumnsSource } from "./column_providers/types.js";
|
|
4
4
|
import "./column_providers/index.js";
|
|
5
|
-
import { CollectionHandle, ColumnUniversalId, ColumnsCollectionDriverModel, ColumnsDiscoverOptions, ColumnsFilterOptions } from "@milaboratories/pl-model-common";
|
|
5
|
+
import { CollectionHandle, ColumnUniversalId, ColumnsCollectionDriverModel, ColumnsDiscoverOptions, ColumnsFilterOptions, DiscoverRootsOptions } from "@milaboratories/pl-model-common";
|
|
6
6
|
export interface ColumnsCollectionDeps {
|
|
7
7
|
/** Render ctx used both for service resolution and for default ctx sources. */
|
|
8
8
|
readonly ctx?: GlobalCfgRenderCtx;
|
|
@@ -30,6 +30,20 @@ export type ColumnsSourceShorthand = "result_pool" | "current_block";
|
|
|
30
30
|
*/
|
|
31
31
|
export declare function ColumnsCollection(sources?: (ColumnsCollection | ColumnsSource | ColumnsSourceShorthand)[], deps?: ColumnsCollectionDeps): ColumnsCollection;
|
|
32
32
|
export declare function isColumnsCollection(value: unknown): value is ColumnsCollection;
|
|
33
|
+
/**
|
|
34
|
+
* A root found by {@link ColumnsCollectionImpl.discoverRoots}: `leaf` is the
|
|
35
|
+
* requested column exactly as `discover({ anchors: { r: root } })` would
|
|
36
|
+
* return it — carrying the linker `path` and qualifications — so the table is
|
|
37
|
+
* built from `root` as the anchor plus `leaf`.
|
|
38
|
+
*/
|
|
39
|
+
export interface DiscoveredRoot {
|
|
40
|
+
/** The column the leaf hangs off. */
|
|
41
|
+
readonly root: ColumnRecipe;
|
|
42
|
+
/** The requested column, discovered from the root. */
|
|
43
|
+
readonly leaf: ColumnRecipe;
|
|
44
|
+
/** Linker columns from the root to the leaf; empty when they join directly. */
|
|
45
|
+
readonly path: ColumnRecipe[];
|
|
46
|
+
}
|
|
33
47
|
/**
|
|
34
48
|
* Sandbox proxy over the host-side `ColumnsCollection` driver. The driver
|
|
35
49
|
* owns all column-set state; this object only carries an opaque
|
|
@@ -55,6 +69,12 @@ export declare class ColumnsCollectionImpl {
|
|
|
55
69
|
addSource(source: ColumnsSource | ColumnsCollection): ColumnsCollection;
|
|
56
70
|
discover(options: ColumnsDiscoverOptions): ColumnsCollection;
|
|
57
71
|
filter(options: ColumnsFilterOptions): ColumnsCollection;
|
|
72
|
+
/**
|
|
73
|
+
* Finds the roots the given columns hang off: the columns that, used as
|
|
74
|
+
* `anchors` of {@link discover}, would reach them. One entry per root, leaf
|
|
75
|
+
* and linker path; entries whose columns are not yet resolvable are skipped.
|
|
76
|
+
*/
|
|
77
|
+
discoverRoots(options: DiscoverRootsOptions): DiscoveredRoot[];
|
|
58
78
|
}
|
|
59
79
|
/** Public type alias — value of the same name is the factory function above. */
|
|
60
80
|
export type ColumnsCollection = ColumnsCollectionImpl;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"columns_collection.d.ts","names":[],"sources":["../../src/columns/columns_collection.ts"],"mappings":";;;;;
|
|
1
|
+
{"version":3,"file":"columns_collection.d.ts","names":[],"sources":["../../src/columns/columns_collection.ts"],"mappings":";;;;;iBAmBiB;;WAEN,MAAM;;WAEN,SAAS;;;;;;;;;;YAWR;;;;;;;;;;;wBAYI,kBACd,WAAW,oBAAoB,gBAAgB,2BAC/C,OAAO,wBACN;wBAQa,oBAAoB,iBAAiB,SAAS;;;;;;;iBAU7C;;WAEN,MAAM;;WAEN,MAAM;;WAEN,MAAM;;;;;;;;;;;;;;;;qBAiBJ;WAEO,QAAQ;mBACP;EAFnB,YACkB,QAAQ,kBACP,QAAQ;EAG3B;EAIA;EAIA,gBAAgB;EAIhB,cAAc;EAMd,UAAU,QAAQ,gBAAgB,oBAAoB;EAOtD,SAAS,SAAS,yBAAyB;EAI3C,OAAO,SAAS,uBAAuB;;;;;;EASvC,cAAc,SAAS,uBAAuB;;;YAcpC,oBAAoB"}
|
|
@@ -66,6 +66,24 @@ var ColumnsCollectionImpl = class ColumnsCollectionImpl {
|
|
|
66
66
|
filter(options) {
|
|
67
67
|
return new ColumnsCollectionImpl(this.driver.filter(this.handle, options), this.driver);
|
|
68
68
|
}
|
|
69
|
+
/**
|
|
70
|
+
* Finds the roots the given columns hang off: the columns that, used as
|
|
71
|
+
* `anchors` of {@link discover}, would reach them. One entry per root, leaf
|
|
72
|
+
* and linker path; entries whose columns are not yet resolvable are skipped.
|
|
73
|
+
*/
|
|
74
|
+
discoverRoots(options) {
|
|
75
|
+
return this.driver.discoverRoots(this.handle, options).flatMap((ids) => {
|
|
76
|
+
const root = ColumnRecipe(ids.root);
|
|
77
|
+
const leaf = ColumnRecipe(ids.leaf);
|
|
78
|
+
const path = ids.path.map((id) => ColumnRecipe(id)).filter((c) => !isNil(c));
|
|
79
|
+
if (isNil(root) || isNil(leaf) || path.length !== ids.path.length) return [];
|
|
80
|
+
return [{
|
|
81
|
+
root,
|
|
82
|
+
leaf,
|
|
83
|
+
path
|
|
84
|
+
}];
|
|
85
|
+
});
|
|
86
|
+
}
|
|
69
87
|
};
|
|
70
88
|
function toSerializedSources(source, ctx) {
|
|
71
89
|
if (source === "result_pool") return [{ kind: "result_pool" }];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"columns_collection.js","names":[],"sources":["../../src/columns/columns_collection.ts"],"sourcesContent":["import type {\n CollectionHandle,\n ColumnUniversalId,\n ColumnsCollectionDriverModel,\n ColumnsDiscoverOptions,\n ColumnsFilterOptions,\n SerializedColumnsSource,\n} from \"@milaboratories/pl-model-common\";\nimport type { GlobalCfgRenderCtx } from \"../render/internal\";\nimport { MainAccessorName, StagingAccessorName } from \"../render/internal\";\nimport type { ColumnsSource } from \"./column_providers\";\nimport { isColumnProvider } from \"./column_providers\";\nimport { TreeNodeAccessor } from \"../render/accessor\";\nimport { getService } from \"../services/get_services\";\nimport { getCfgRenderCtx } from \"../internal\";\nimport { ColumnRecipe } from \"./column_recipes\";\nimport { isNil } from \"es-toolkit\";\n\nexport interface ColumnsCollectionDeps {\n /** Render ctx used both for service resolution and for default ctx sources. */\n readonly ctx?: GlobalCfgRenderCtx;\n /** Override the resolved `columnsCollection` service — primarily for tests. */\n readonly driver?: ColumnsCollectionDriverModel;\n}\n\n/**\n * Shorthand literals accepted inside `ColumnsCollection`'s `sources`\n * array, expanded against the active render ctx:\n *\n * - `\"result_pool\"` – fan-out into the host's upstream-block result pool.\n * - `\"current_block\"` – main outputs + prerun (staging) accessors of the\n * current block, when present.\n */\nexport type ColumnsSourceShorthand = \"result_pool\" | \"current_block\";\n\n/**\n * Build a {@link ColumnsCollection} from sandbox-side source descriptors.\n * Resolves the `columnsCollection` driver (either from `deps.driver` or via\n * `getService(\"columnsCollection\")`) and asks the host to mint a fresh\n * handle covering the supplied sources. Pass `sources === undefined` to\n * fall back to the active render ctx (main outputs + prerun + result pool).\n *\n * `sources` accepts {@link ColumnsSourceShorthand} string literals\n * (`\"result_pool\"`, `\"current_block\"`) for the common ctx-derived sources.\n */\nexport function ColumnsCollection(\n sources?: (ColumnsCollection | ColumnsSource | ColumnsSourceShorthand)[],\n deps?: ColumnsCollectionDeps,\n): ColumnsCollection {\n const driver = deps?.driver ?? getService(\"columnsCollection\", { ctx: deps?.ctx });\n const serialized: SerializedColumnsSource[] = sources\n ? sources.flatMap((s) => toSerializedSources(s, deps?.ctx))\n : defaultCtxSources(deps?.ctx);\n return new ColumnsCollectionImpl(driver.create(serialized), driver);\n}\n\nexport function isColumnsCollection(value: unknown): value is ColumnsCollection {\n return value instanceof ColumnsCollectionImpl;\n}\n\n/**\n * Sandbox proxy over the host-side `ColumnsCollection` driver. The driver\n * owns all column-set state; this object only carries an opaque\n * {@link CollectionHandle} plus a reference to the driver service.\n *\n * Construct via {@link ColumnsCollection} — the bare constructor is a\n * trivial `(handle, driver)` pair so that `addSource` / `discover` / `filter`\n * can rebind a freshly-minted handle without going through source\n * serialisation again.\n *\n * Every method returning a `ColumnsCollection` mints a fresh handle on the\n * host — the host VM bridge pins it to the active render ctx, so the sandbox\n * never has to manage refcounts.\n */\nexport class ColumnsCollectionImpl {\n constructor(\n public readonly handle: CollectionHandle,\n private readonly driver: ColumnsCollectionDriverModel,\n ) {}\n\n isEmpty(): boolean {\n return this.driver.isEmpty(this.handle);\n }\n\n isFinal(): boolean {\n return this.driver.isFinal(this.handle);\n }\n\n getColumnIds(): ColumnUniversalId[] {\n return this.driver.getColumns(this.handle);\n }\n\n getColumns(): ColumnRecipe[] {\n return this.getColumnIds()\n .map((id) => ColumnRecipe(id))\n .filter((c): c is ColumnRecipe => !isNil(c));\n }\n\n addSource(source: ColumnsSource | ColumnsCollection): ColumnsCollection {\n return new ColumnsCollectionImpl(\n this.driver.addSource(this.handle, toSerializedSources(source)),\n this.driver,\n );\n }\n\n discover(options: ColumnsDiscoverOptions): ColumnsCollection {\n return new ColumnsCollectionImpl(this.driver.discover(this.handle, options), this.driver);\n }\n\n filter(options: ColumnsFilterOptions): ColumnsCollection {\n return new ColumnsCollectionImpl(this.driver.filter(this.handle, options), this.driver);\n }\n}\n\n/** Public type alias — value of the same name is the factory function above. */\nexport type ColumnsCollection = ColumnsCollectionImpl;\n\nfunction toSerializedSources(\n source: ColumnsCollection | ColumnsSource | ColumnsSourceShorthand,\n ctx?: GlobalCfgRenderCtx,\n): SerializedColumnsSource[] {\n if (source === \"result_pool\") {\n return [{ kind: \"result_pool\" }];\n }\n if (source === \"current_block\") {\n return currentBlockSources(ctx);\n }\n if (source instanceof ColumnsCollectionImpl) {\n return [{ kind: \"collection\", handle: source.handle }];\n }\n if (source instanceof TreeNodeAccessor) {\n return [{ kind: \"accessor\", accessor: source.handle, path: source.resolvePath }];\n }\n if (isColumnArray(source)) {\n return [{ kind: \"ids\", ids: source.columns.map((c) => c.id), isFinal: source.isFinal }];\n }\n if (isColumnProvider(source)) {\n return [{ kind: \"ids\", ids: source.getColumns().map((c) => c.id), isFinal: source.isFinal() }];\n }\n throw new Error(\"ColumnsCollection: unrecognised ColumnsSource shape\");\n}\n\nfunction isColumnArray(source: unknown): source is {\n columns: ReadonlyArray<{ id: ColumnUniversalId; spec?: unknown; data?: unknown }>;\n isFinal: boolean;\n} {\n if (typeof source !== \"object\" || source === null) return false;\n const s = source as { columns?: unknown; isFinal?: unknown };\n return Array.isArray(s.columns) && typeof s.isFinal === \"boolean\";\n}\n\nfunction currentBlockSources(ctx?: GlobalCfgRenderCtx): SerializedColumnsSource[] {\n const renderCtx = ctx ?? getCfgRenderCtx();\n const sources: SerializedColumnsSource[] = [];\n\n const outputs = renderCtx.getAccessorHandleByName(MainAccessorName);\n if (outputs !== undefined) {\n sources.push({ kind: \"accessor\", accessor: outputs, path: [MainAccessorName] });\n }\n const prerun = renderCtx.getAccessorHandleByName(StagingAccessorName);\n if (prerun !== undefined) {\n sources.push({ kind: \"accessor\", accessor: prerun, path: [StagingAccessorName] });\n }\n\n return sources;\n}\n\nfunction defaultCtxSources(ctx?: GlobalCfgRenderCtx): SerializedColumnsSource[] {\n return [...currentBlockSources(ctx), { kind: \"result_pool\" }];\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AA6CA,SAAgB,kBACd,SACA,MACmB;CACnB,MAAM,SAAS,MAAM,UAAU,WAAW,qBAAqB,EAAE,KAAK,MAAM,IAAI,CAAC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O,CAAC;CAEvD,IAAI,kBAAkB,kBACpB,OAAO,CAAC;EAAE,MAAM;EAAY,UAAU,OAAO;EAAQ,MAAM,OAAO;CAAY,CAAC;CAEjF,IAAI,cAAc,MAAM,GACtB,OAAO,CAAC;EAAE,MAAM;EAAO,KAAK,OAAO,QAAQ,KAAK,MAAM,EAAE,EAAE;EAAG,SAAS,OAAO;CAAQ,CAAC;CAExF,IAAI,iBAAiB,MAAM,GACzB,OAAO,CAAC;EAAE,MAAM;EAAO,KAAK,OAAO,WAAW,CAAC,CAAC,KAAK,MAAM,EAAE,EAAE;EAAG,SAAS,OAAO,QAAQ;CAAE,CAAC;CAE/F,MAAM,IAAI,MAAM,qDAAqD;AACvE;AAEA,SAAS,cAAc,QAGrB;CACA,IAAI,OAAO,WAAW,YAAY,WAAW,MAAM,OAAO;CAC1D,MAAM,IAAI;CACV,OAAO,MAAM,QAAQ,EAAE,OAAO,KAAK,OAAO,EAAE,YAAY;AAC1D;AAEA,SAAS,oBAAoB,KAAqD;CAChF,MAAM,YAAY,OAAO,gBAAgB;CACzC,MAAM,UAAqC,CAAC;CAE5C,MAAM,UAAU,UAAU,wBAAwB,gBAAgB;CAClE,IAAI,YAAY,KAAA,GACd,QAAQ,KAAK;EAAE,MAAM;EAAY,UAAU;EAAS,MAAM,CAAC,gBAAgB;CAAE,CAAC;CAEhF,MAAM,SAAS,UAAU,wBAAwB,mBAAmB;CACpE,IAAI,WAAW,KAAA,GACb,QAAQ,KAAK;EAAE,MAAM;EAAY,UAAU;EAAQ,MAAM,CAAC,mBAAmB;CAAE,CAAC;CAGlF,OAAO;AACT;AAEA,SAAS,kBAAkB,KAAqD;CAC9E,OAAO,CAAC,GAAG,oBAAoB,GAAG,GAAG,EAAE,MAAM,cAAc,CAAC;AAC9D"}
|
|
1
|
+
{"version":3,"file":"columns_collection.js","names":[],"sources":["../../src/columns/columns_collection.ts"],"sourcesContent":["import type {\n CollectionHandle,\n ColumnUniversalId,\n ColumnsCollectionDriverModel,\n ColumnsDiscoverOptions,\n ColumnsFilterOptions,\n DiscoverRootsOptions,\n SerializedColumnsSource,\n} from \"@milaboratories/pl-model-common\";\nimport type { GlobalCfgRenderCtx } from \"../render/internal\";\nimport { MainAccessorName, StagingAccessorName } from \"../render/internal\";\nimport type { ColumnsSource } from \"./column_providers\";\nimport { isColumnProvider } from \"./column_providers\";\nimport { TreeNodeAccessor } from \"../render/accessor\";\nimport { getService } from \"../services/get_services\";\nimport { getCfgRenderCtx } from \"../internal\";\nimport { ColumnRecipe } from \"./column_recipes\";\nimport { isNil } from \"es-toolkit\";\n\nexport interface ColumnsCollectionDeps {\n /** Render ctx used both for service resolution and for default ctx sources. */\n readonly ctx?: GlobalCfgRenderCtx;\n /** Override the resolved `columnsCollection` service — primarily for tests. */\n readonly driver?: ColumnsCollectionDriverModel;\n}\n\n/**\n * Shorthand literals accepted inside `ColumnsCollection`'s `sources`\n * array, expanded against the active render ctx:\n *\n * - `\"result_pool\"` – fan-out into the host's upstream-block result pool.\n * - `\"current_block\"` – main outputs + prerun (staging) accessors of the\n * current block, when present.\n */\nexport type ColumnsSourceShorthand = \"result_pool\" | \"current_block\";\n\n/**\n * Build a {@link ColumnsCollection} from sandbox-side source descriptors.\n * Resolves the `columnsCollection` driver (either from `deps.driver` or via\n * `getService(\"columnsCollection\")`) and asks the host to mint a fresh\n * handle covering the supplied sources. Pass `sources === undefined` to\n * fall back to the active render ctx (main outputs + prerun + result pool).\n *\n * `sources` accepts {@link ColumnsSourceShorthand} string literals\n * (`\"result_pool\"`, `\"current_block\"`) for the common ctx-derived sources.\n */\nexport function ColumnsCollection(\n sources?: (ColumnsCollection | ColumnsSource | ColumnsSourceShorthand)[],\n deps?: ColumnsCollectionDeps,\n): ColumnsCollection {\n const driver = deps?.driver ?? getService(\"columnsCollection\", { ctx: deps?.ctx });\n const serialized: SerializedColumnsSource[] = sources\n ? sources.flatMap((s) => toSerializedSources(s, deps?.ctx))\n : defaultCtxSources(deps?.ctx);\n return new ColumnsCollectionImpl(driver.create(serialized), driver);\n}\n\nexport function isColumnsCollection(value: unknown): value is ColumnsCollection {\n return value instanceof ColumnsCollectionImpl;\n}\n\n/**\n * A root found by {@link ColumnsCollectionImpl.discoverRoots}: `leaf` is the\n * requested column exactly as `discover({ anchors: { r: root } })` would\n * return it — carrying the linker `path` and qualifications — so the table is\n * built from `root` as the anchor plus `leaf`.\n */\nexport interface DiscoveredRoot {\n /** The column the leaf hangs off. */\n readonly root: ColumnRecipe;\n /** The requested column, discovered from the root. */\n readonly leaf: ColumnRecipe;\n /** Linker columns from the root to the leaf; empty when they join directly. */\n readonly path: ColumnRecipe[];\n}\n\n/**\n * Sandbox proxy over the host-side `ColumnsCollection` driver. The driver\n * owns all column-set state; this object only carries an opaque\n * {@link CollectionHandle} plus a reference to the driver service.\n *\n * Construct via {@link ColumnsCollection} — the bare constructor is a\n * trivial `(handle, driver)` pair so that `addSource` / `discover` / `filter`\n * can rebind a freshly-minted handle without going through source\n * serialisation again.\n *\n * Every method returning a `ColumnsCollection` mints a fresh handle on the\n * host — the host VM bridge pins it to the active render ctx, so the sandbox\n * never has to manage refcounts.\n */\nexport class ColumnsCollectionImpl {\n constructor(\n public readonly handle: CollectionHandle,\n private readonly driver: ColumnsCollectionDriverModel,\n ) {}\n\n isEmpty(): boolean {\n return this.driver.isEmpty(this.handle);\n }\n\n isFinal(): boolean {\n return this.driver.isFinal(this.handle);\n }\n\n getColumnIds(): ColumnUniversalId[] {\n return this.driver.getColumns(this.handle);\n }\n\n getColumns(): ColumnRecipe[] {\n return this.getColumnIds()\n .map((id) => ColumnRecipe(id))\n .filter((c): c is ColumnRecipe => !isNil(c));\n }\n\n addSource(source: ColumnsSource | ColumnsCollection): ColumnsCollection {\n return new ColumnsCollectionImpl(\n this.driver.addSource(this.handle, toSerializedSources(source)),\n this.driver,\n );\n }\n\n discover(options: ColumnsDiscoverOptions): ColumnsCollection {\n return new ColumnsCollectionImpl(this.driver.discover(this.handle, options), this.driver);\n }\n\n filter(options: ColumnsFilterOptions): ColumnsCollection {\n return new ColumnsCollectionImpl(this.driver.filter(this.handle, options), this.driver);\n }\n\n /**\n * Finds the roots the given columns hang off: the columns that, used as\n * `anchors` of {@link discover}, would reach them. One entry per root, leaf\n * and linker path; entries whose columns are not yet resolvable are skipped.\n */\n discoverRoots(options: DiscoverRootsOptions): DiscoveredRoot[] {\n return this.driver.discoverRoots(this.handle, options).flatMap((ids) => {\n const root = ColumnRecipe(ids.root);\n const leaf = ColumnRecipe(ids.leaf);\n const path = ids.path\n .map((id) => ColumnRecipe(id))\n .filter((c): c is ColumnRecipe => !isNil(c));\n if (isNil(root) || isNil(leaf) || path.length !== ids.path.length) return [];\n return [{ root, leaf, path }];\n });\n }\n}\n\n/** Public type alias — value of the same name is the factory function above. */\nexport type ColumnsCollection = ColumnsCollectionImpl;\n\nfunction toSerializedSources(\n source: ColumnsCollection | ColumnsSource | ColumnsSourceShorthand,\n ctx?: GlobalCfgRenderCtx,\n): SerializedColumnsSource[] {\n if (source === \"result_pool\") {\n return [{ kind: \"result_pool\" }];\n }\n if (source === \"current_block\") {\n return currentBlockSources(ctx);\n }\n if (source instanceof ColumnsCollectionImpl) {\n return [{ kind: \"collection\", handle: source.handle }];\n }\n if (source instanceof TreeNodeAccessor) {\n return [{ kind: \"accessor\", accessor: source.handle, path: source.resolvePath }];\n }\n if (isColumnArray(source)) {\n return [{ kind: \"ids\", ids: source.columns.map((c) => c.id), isFinal: source.isFinal }];\n }\n if (isColumnProvider(source)) {\n return [{ kind: \"ids\", ids: source.getColumns().map((c) => c.id), isFinal: source.isFinal() }];\n }\n throw new Error(\"ColumnsCollection: unrecognised ColumnsSource shape\");\n}\n\nfunction isColumnArray(source: unknown): source is {\n columns: ReadonlyArray<{ id: ColumnUniversalId; spec?: unknown; data?: unknown }>;\n isFinal: boolean;\n} {\n if (typeof source !== \"object\" || source === null) return false;\n const s = source as { columns?: unknown; isFinal?: unknown };\n return Array.isArray(s.columns) && typeof s.isFinal === \"boolean\";\n}\n\nfunction currentBlockSources(ctx?: GlobalCfgRenderCtx): SerializedColumnsSource[] {\n const renderCtx = ctx ?? getCfgRenderCtx();\n const sources: SerializedColumnsSource[] = [];\n\n const outputs = renderCtx.getAccessorHandleByName(MainAccessorName);\n if (outputs !== undefined) {\n sources.push({ kind: \"accessor\", accessor: outputs, path: [MainAccessorName] });\n }\n const prerun = renderCtx.getAccessorHandleByName(StagingAccessorName);\n if (prerun !== undefined) {\n sources.push({ kind: \"accessor\", accessor: prerun, path: [StagingAccessorName] });\n }\n\n return sources;\n}\n\nfunction defaultCtxSources(ctx?: GlobalCfgRenderCtx): SerializedColumnsSource[] {\n return [...currentBlockSources(ctx), { kind: \"result_pool\" }];\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AA8CA,SAAgB,kBACd,SACA,MACmB;CACnB,MAAM,SAAS,MAAM,UAAU,WAAW,qBAAqB,EAAE,KAAK,MAAM,IAAI,CAAC;CACjF,MAAM,aAAwC,UAC1C,QAAQ,SAAS,MAAM,oBAAoB,GAAG,MAAM,GAAG,CAAC,IACxD,kBAAkB,MAAM,GAAG;CAC/B,OAAO,IAAI,sBAAsB,OAAO,OAAO,UAAU,GAAG,MAAM;AACpE;AAEA,SAAgB,oBAAoB,OAA4C;CAC9E,OAAO,iBAAiB;AAC1B;;;;;;;;;;;;;;;AA+BA,IAAa,wBAAb,MAAa,sBAAsB;CAEf;CACC;CAFnB,YACE,QACA,QACA;EAFgB,KAAA,SAAA;EACC,KAAA,SAAA;CAChB;CAEH,UAAmB;EACjB,OAAO,KAAK,OAAO,QAAQ,KAAK,MAAM;CACxC;CAEA,UAAmB;EACjB,OAAO,KAAK,OAAO,QAAQ,KAAK,MAAM;CACxC;CAEA,eAAoC;EAClC,OAAO,KAAK,OAAO,WAAW,KAAK,MAAM;CAC3C;CAEA,aAA6B;EAC3B,OAAO,KAAK,aAAa,CAAC,CACvB,KAAK,OAAO,aAAa,EAAE,CAAC,CAAC,CAC7B,QAAQ,MAAyB,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AE,EAAE;EAAG,SAAS,OAAO;CAAQ,CAAC;CAExF,IAAI,iBAAiB,MAAM,GACzB,OAAO,CAAC;EAAE,MAAM;EAAO,KAAK,OAAO,WAAW,CAAC,CAAC,KAAK,MAAM,EAAE,EAAE;EAAG,SAAS,OAAO,QAAQ;CAAE,CAAC;CAE/F,MAAM,IAAI,MAAM,qDAAqD;AACvE;AAEA,SAAS,cAAc,QAGrB;CACA,IAAI,OAAO,WAAW,YAAY,WAAW,MAAM,OAAO;CAC1D,MAAM,IAAI;CACV,OAAO,MAAM,QAAQ,EAAE,OAAO,KAAK,OAAO,EAAE,YAAY;AAC1D;AAEA,SAAS,oBAAoB,KAAqD;CAChF,MAAM,YAAY,OAAO,gBAAgB;CACzC,MAAM,UAAqC,CAAC;CAE5C,MAAM,UAAU,UAAU,wBAAwB,gBAAgB;CAClE,IAAI,YAAY,KAAA,GACd,QAAQ,KAAK;EAAE,MAAM;EAAY,UAAU;EAAS,MAAM,CAAC,gBAAgB;CAAE,CAAC;CAEhF,MAAM,SAAS,UAAU,wBAAwB,mBAAmB;CACpE,IAAI,WAAW,KAAA,GACb,QAAQ,KAAK;EAAE,MAAM;EAAY,UAAU;EAAQ,MAAM,CAAC,mBAAmB;CAAE,CAAC;CAGlF,OAAO;AACT;AAEA,SAAS,kBAAkB,KAAqD;CAC9E,OAAO,CAAC,GAAG,oBAAoB,GAAG,GAAG,EAAE,MAAM,cAAc,CAAC;AAC9D"}
|
package/dist/columns/index.d.ts
CHANGED
|
@@ -9,9 +9,9 @@ import { AccessorColumnsProvider, AccessorColumnsProviderImpl, ArrayColumnsProvi
|
|
|
9
9
|
import { ColumnsSource } from "./column_providers/types.js";
|
|
10
10
|
import { _ctxProvidersCache, getCtxProviders, isColumnProvider, toColumnProvider } from "./column_providers/index.js";
|
|
11
11
|
import { SplitAxis, SplitByAxesOpts, splitByAxes } from "./split_by_axes.js";
|
|
12
|
-
import { ColumnsCollection, ColumnsCollectionDeps, ColumnsCollectionImpl, ColumnsSourceShorthand, isColumnsCollection } from "./columns_collection.js";
|
|
12
|
+
import { ColumnsCollection, ColumnsCollectionDeps, ColumnsCollectionImpl, ColumnsSourceShorthand, DiscoveredRoot, isColumnsCollection } from "./columns_collection.js";
|
|
13
13
|
import { deriveAxisValuesLabels } from "./derive_axis_values_labels.js";
|
|
14
14
|
import { ColumnOption, collectLinkerColumns, collectLinkerIds, createPeerLinkFinder, deriveColumnOptions, deriveRecipeOptions, hasColumnData, hasReachableData, hasSingleDataColumn, hitQualifications, isLeafColumn, queriesQualifications } from "./utils.js";
|
|
15
15
|
import { DatasetAxes, collectDatasetAxes, describePeerLinks, findPeerLinks, getResultPoolDatasetAxes, peerLinkedLast } from "./peer_links.js";
|
|
16
16
|
import { ColumnValueOption, ColumnValueOptionsColumn, ColumnValueOptionsModel, createColumnValueOptions, deriveColumnValueOptions, deriveLabelledColumnValueOptions } from "./column_values.js";
|
|
17
|
-
export { AccessorColumnsProvider, AccessorColumnsProviderImpl, ArrayColumnsProvider, Column, ColumnData, ColumnDiscoveredRecipe, type ColumnFieldStatus, ColumnFilteredRecipe, ColumnOption, ColumnOverriddenRecipe, ColumnRecipe, type ColumnRecipeId, type ColumnResolutionStatus, ColumnSource, ColumnValueOption, ColumnValueOptionsColumn, ColumnValueOptionsModel, ColumnsCollection, ColumnsCollectionDeps, ColumnsCollectionImpl, ColumnsProvider, ColumnsSource, ColumnsSourceShorthand, DataColumn, DataColumnId, DataColumnImpl, DataColumnRecipe, DataColumnSource, DatasetAxes, ResultPoolColumnsProvider, ResultPoolColumnsProviderImpl, type SpecQuery, SplitAxis, SplitByAxesOpts, _ctxProvidersCache, collectDatasetAxes, collectLinkerColumns, collectLinkerIds, createColumnValueOptions, createPeerLinkFinder, deriveAxisValuesLabels, deriveColumnOptions, deriveColumnValueOptions, deriveLabelledColumnValueOptions, deriveRecipeOptions, describePeerLinks, findPeerLinks, getCtxProviders, getResultPoolDatasetAxes, hasColumnData, hasReachableData, hasSingleDataColumn, hitQualifications, isColumn, isColumnProvider, isColumnsCollection, isDataColumn, isLeafColumn, peerLinkedLast, queriesQualifications, splitByAxes, toColumnProvider };
|
|
17
|
+
export { AccessorColumnsProvider, AccessorColumnsProviderImpl, ArrayColumnsProvider, Column, ColumnData, ColumnDiscoveredRecipe, type ColumnFieldStatus, ColumnFilteredRecipe, ColumnOption, ColumnOverriddenRecipe, ColumnRecipe, type ColumnRecipeId, type ColumnResolutionStatus, ColumnSource, ColumnValueOption, ColumnValueOptionsColumn, ColumnValueOptionsModel, ColumnsCollection, ColumnsCollectionDeps, ColumnsCollectionImpl, ColumnsProvider, ColumnsSource, ColumnsSourceShorthand, DataColumn, DataColumnId, DataColumnImpl, DataColumnRecipe, DataColumnSource, DatasetAxes, DiscoveredRoot, ResultPoolColumnsProvider, ResultPoolColumnsProviderImpl, type SpecQuery, SplitAxis, SplitByAxesOpts, _ctxProvidersCache, collectDatasetAxes, collectLinkerColumns, collectLinkerIds, createColumnValueOptions, createPeerLinkFinder, deriveAxisValuesLabels, deriveColumnOptions, deriveColumnValueOptions, deriveLabelledColumnValueOptions, deriveRecipeOptions, describePeerLinks, findPeerLinks, getCtxProviders, getResultPoolDatasetAxes, hasColumnData, hasReachableData, hasSingleDataColumn, hitQualifications, isColumn, isColumnProvider, isColumnsCollection, isDataColumn, isLeafColumn, peerLinkedLast, queriesQualifications, splitByAxes, toColumnProvider };
|
package/dist/index.d.ts
CHANGED
|
@@ -56,7 +56,7 @@ import { AccessorColumnsProvider, AccessorColumnsProviderImpl, ArrayColumnsProvi
|
|
|
56
56
|
import { ColumnsSource } from "./columns/column_providers/types.js";
|
|
57
57
|
import { _ctxProvidersCache, getCtxProviders, isColumnProvider, toColumnProvider } from "./columns/column_providers/index.js";
|
|
58
58
|
import { SplitAxis, SplitByAxesOpts, splitByAxes } from "./columns/split_by_axes.js";
|
|
59
|
-
import { ColumnsCollection, ColumnsCollectionDeps, ColumnsCollectionImpl, ColumnsSourceShorthand, isColumnsCollection } from "./columns/columns_collection.js";
|
|
59
|
+
import { ColumnsCollection, ColumnsCollectionDeps, ColumnsCollectionImpl, ColumnsSourceShorthand, DiscoveredRoot, isColumnsCollection } from "./columns/columns_collection.js";
|
|
60
60
|
import { deriveAxisValuesLabels } from "./columns/derive_axis_values_labels.js";
|
|
61
61
|
import { ColumnOption, collectLinkerColumns, collectLinkerIds, createPeerLinkFinder, deriveColumnOptions, deriveRecipeOptions, hasColumnData, hasReachableData, hasSingleDataColumn, hitQualifications, isLeafColumn, queriesQualifications } from "./columns/utils.js";
|
|
62
62
|
import { DatasetAxes, collectDatasetAxes, describePeerLinks, findPeerLinks, getResultPoolDatasetAxes, peerLinkedLast } from "./columns/peer_links.js";
|
|
@@ -88,4 +88,4 @@ import "./services/index.js";
|
|
|
88
88
|
import { getEnvironmentValue } from "./env_value.js";
|
|
89
89
|
export * from "@milaboratories/pl-model-common";
|
|
90
90
|
export * from "@milaboratories/pl-error-like";
|
|
91
|
-
export { AccessorColumnsProvider, AccessorColumnsProviderImpl, type AccessorHandle, AndFilter, AnnotationFilter, AnnotationMode, AnnotationScript, AnnotationScript2, AnnotationScriptUi, AnnotationSpec, AnnotationSpecUi, AnnotationStep, AnnotationStepUi, AnyForm, ArrayColumnsProvider, type AxesVault, AxisLabelProvider, BLOCK_SERVICE_FLAGS, BLOCK_STORAGE_FACADE_VERSION, BlockApiV1, BlockApiV2, BlockConfig, BlockConfigV3, BlockConfigV4, BlockDefaultModelServices, BlockDefaultUiServices, BlockModelInfo, BlockModelV3, BlockRenderCtx, BlockServiceFlags, BlockStatePatch, type BlockStorage, BlockStorageFacade, BlockStorageFacadeCallbacks, BlockStorageFacadeHandles, type BlockStorageSchemaVersion, BuildDatasetOptions, CancelSubscription, Cfg, CfgAnd, CfgBlobContent, CfgBlobContentAsJson, CfgBlobContentAsString, CfgDownloadedBlobContent, CfgExtractArchiveAndGetURL, CfgFlatten, CfgGetFromCtx, CfgGetJsonField, CfgGetResourceField, CfgImmediate, CfgImportProgress, CfgIsEmpty, CfgIsolate, CfgLastLogs, CfgLogHandle, CfgMakeArray, CfgMakeObject, CfgMapArrayValues, CfgMapRecordValues, CfgMapResourceFields, CfgNot, CfgOnDemandBlobContent, CfgOr, CfgProgressLog, CfgProgressLogWithInfo, CfgResourceValueAsJson, Column, ColumnData, ColumnDiscoveredRecipe, type ColumnFieldStatus, ColumnFilteredRecipe, ColumnOption, type ColumnOrderRule, ColumnOverriddenRecipe, ColumnProvider, ColumnRecipe, type ColumnRecipeId, type ColumnResolutionStatus, ColumnSource, ColumnValueOption, ColumnValueOptionsColumn, ColumnValueOptionsModel, type ColumnVisibilityRule, ColumnsCollection, ColumnsCollectionDeps, ColumnsCollectionImpl, type ColumnsDisplayOptions, ColumnsProvider, type ColumnsSelectorConfig, ColumnsSource, ColumnsSourceShorthand, CommonFieldTraverseOps, CommonTraversalOps, ConfigRenderLambda, ConfigRenderLambdaFlags, CurrentSdkInfo, DataColumn, DataColumnId, DataColumnImpl, DataColumnRecipe, DataColumnSource, DataModel, DataModelBuilder, DatasetAxes, DatasetOption, DatasetSelection, DeriveHref, DeriveLabelsFormatters, DeriveLabelsOptions, Entry, ExpressionSpec, ExtractFunctionHandleReturn, type ExtractFutureRefType, FieldTraversalStep, FieldType, FilterMatchOptions, type FilterSpec, type FilterSpecLeaf, type FilterSpecNode, type FilterSpecOfType, type FilterSpecType, FilterSpecUi, FilterUi, FilterUiOfType, FilterUiType, FindFilterColumnsOptions, FormField, FutureRef, GetFieldStep, InferArgsType, InferBlockState, InferBlockStatePatch, InferDataType, InferFactoryData, InferFactoryModelServices, InferFactoryOutputs, InferFactoryParams, InferFactoryUiServices, InferHrefType, InferOutputsFromLambdas, InferOutputsType, InferPluginData, InferPluginHandle, InferPluginNames, InferPluginUiEntries, InferRenderFunctionReturn, InferUiState, IsNA, internal_d_exports as JsRenderInternal, type DeriveLabelsOptions as LabelDerivationOps, LinkerStep, Log10, MainAccessorName, type MigrateBlockStorageConfig, type MigrationFailure, type MigrationResult, type MigrationSuccess, type ModelServices, type MutateStoragePayload, NotFilter, NumericalComparisonFilter, OptionalPlResourceEntry, OrFilter, OutputError, PColumnCollection, type PColumnDataUniversal, PColumnEntryUniversal, PColumnEntryWithLabel, PColumnKeyList, PColumnPredicate, PColumnResourceMapData, PColumnResourceMapEntry, PColumnUniversal, PColumnWithLabel, PFrameImpl, PTableKey, type PTableParamsV2, type ParamsInput, Patch, PatternFilter, PatternPredicate, PatternPredicateContainSubsequence, PatternPredicateEquals, type PlDataTableAxisMeta, type PlDataTableColumnMeta, type PlDataTableColumnsMeta, type PlDataTableFilterMeta, type PlDataTableFilterSpecLeaf, type PlDataTableFilters, type PlDataTableFiltersWithMeta, type PlDataTableGridStateCore, type PlDataTableModel, type PlDataTableSheet, type PlDataTableSheetState, type PlDataTableStateV2, type PlDataTableStateV2CacheEntry, type PlDataTableStateV2Normalized, PlMultiSequenceAlignmentColorSchemeOption, PlMultiSequenceAlignmentModel, PlMultiSequenceAlignmentSettings, PlMultiSequenceAlignmentWidget, PlResourceEntry, PlSelectionModel, type PlTableColumnIdJson, Platforma, PlatformaApiVersion, PlatformaExtended, PlatformaFactory, PlatformaSDKVersion, PlatformaV1, PlatformaV2, PlatformaV3, type PluginConfig, type PluginData, PluginDataModel, PluginDataModelBuilder, type PluginDataModelVersions, type PluginFactory, PluginFactoryLike, PluginHandle, PluginInstance, PluginModel, type PluginName, type PluginOutputs, type PluginParams, type PluginPublicOutputs, type PluginRecord, type PluginRegistry, PluginRenderCtx, PresentColumnValueOptionsModel, type PublicOutputFieldDef, QueryColumnId, QueryColumnIdAxis, QueryColumnIdColumn, RT_BINARY_PARTITIONED, RT_BINARY_SUPER_PARTITIONED, RT_JSON_PARTITIONED, RT_JSON_SUPER_PARTITIONED, RT_PARQUET_PARTITIONED, RT_PARQUET_SUPER_PARTITIONED, RT_RESOURCE_MAP, RT_RESOURCE_MAP_PARTITIONED, RenderCtx, RenderCtxBase, RenderFunction, ResolveModelServices, ResolveUiServices, ResourceTraversalOps, ResourceType, ResultPool, ResultPoolColumnsProvider, ResultPoolColumnsProviderImpl, SdkInfo, ServiceProxy, SimplifiedPColumnSpec, SimplifiedUniversalPColumnEntry, SortedCumulativeSum, type Entry as SpecExtractorResult, type SpecQuery, SplitAxis, SplitByAxesOpts, StagingAccessorName, StdCtx, StdCtxArgsOnly, TooltipEntry, type Trace, type TraceEntry, TransformedColumn, TreeNodeAccessor, TypeField, TypeFieldRecord, TypeForm, TypeToLiteral, TypedConfig, TypedConfigOrConfigLambda, TypedConfigOrString, type UiServices, Unionize, UniversalColumnOption, UnwrapFutureRef, ValueRank, type VersionedData, _ctxProvidersCache, allPColumnsReady, blockServiceNames, buildDatasetOptions, buildRefMap, buildServices, collectDatasetAxes, collectLinkerColumns, collectLinkerIds, compileAnnotationScript, compileFilter, compileFilters, convertFilterSpecsToExpressionSpecs, convertFilterUiToExpressionImpl, convertFilterUiToExpressions, convertOrParsePColumnData, createBlockStorage, createColumnValueOptions, createDatasetSelection, createDefaultPTableParams, createPFrameForGraphs, createPeerLinkFinder, createPlDataTable, type createPlDataTableOptionsV3, createPlDataTableSheet, createPlDataTableStateV2, createPlDataTableV2, createPlDataTableV3, createPlSelectionModel, createRowSelectionColumn, createServiceProxy, deriveAxisValuesLabels, deriveColumnOptions, deriveColumnValueOptions, deriveDataFromStorage, deriveDistinctLabels, deriveDistinctTooltips, deriveLabelledColumnValueOptions, deriveLabels, deriveRecipeOptions, describePeerLinks, discoverTableColumns as discoverTableColumnSnaphots, distillFilterSpec, downgradeCfgOrLambda, enrichCompatible, extractConfig, filterDataInfoEntries, filterMatchesToOptions, filterSpecToSpecQueryExpr, finalizePColumnData, findFilterColumns, findPeerLinks, getAllRelatedColumns, getAvailableWithLinkersAxes, getAxisUniqueValues, getColumnOrAxisValueLabelsId, getColumnSpecById, getColumnUniqueValues, getColumnsFull, getCtxProviders, getEffectiveVisibility, getEnvironmentValue, getNumberOfRows, getOrderPriority, getPartitionKeysList, getPlatformaApiVersion, getPluginData, getRawPlatformaInstance, getRelatedColumns, getRequestColumnsFromSelectedSources, getResultPoolDatasetAxes, getService, getSingleColumnData, getStorageData, getUniqueAxisValuesWithLabels, getUniquePartitionKeys, getUniqueSourceValuesWithLabels, hasColumnData, hasReachableData, hasSingleDataColumn, hitQualifications, ifDef, isBlockStorage, isColumn, isColumnHidden, isColumnOptional, isColumnProvider, isColumnsCollection, isConfigLambda, isDataColumn, isDatasetSelection, isHiddenFromGraphColumn, isHiddenFromUIColumn, isLeafColumn, isPColumnReady, isPluginOutputKey, migrateBlockStorage, normalizeBlockStorage, parsePColumnData, parseResourceMap, peerLinkedLast, pluginOutputKey, pluginOutputPrefix, queriesQualifications, readColumnValueOptions, readOutput, registerFacadeCallbacks, splitByAxes, toColumnProvider, unreachable, updateStorageData, upgradePlDataTableStateV2, wrapOutputs };
|
|
91
|
+
export { AccessorColumnsProvider, AccessorColumnsProviderImpl, type AccessorHandle, AndFilter, AnnotationFilter, AnnotationMode, AnnotationScript, AnnotationScript2, AnnotationScriptUi, AnnotationSpec, AnnotationSpecUi, AnnotationStep, AnnotationStepUi, AnyForm, ArrayColumnsProvider, type AxesVault, AxisLabelProvider, BLOCK_SERVICE_FLAGS, BLOCK_STORAGE_FACADE_VERSION, BlockApiV1, BlockApiV2, BlockConfig, BlockConfigV3, BlockConfigV4, BlockDefaultModelServices, BlockDefaultUiServices, BlockModelInfo, BlockModelV3, BlockRenderCtx, BlockServiceFlags, BlockStatePatch, type BlockStorage, BlockStorageFacade, BlockStorageFacadeCallbacks, BlockStorageFacadeHandles, type BlockStorageSchemaVersion, BuildDatasetOptions, CancelSubscription, Cfg, CfgAnd, CfgBlobContent, CfgBlobContentAsJson, CfgBlobContentAsString, CfgDownloadedBlobContent, CfgExtractArchiveAndGetURL, CfgFlatten, CfgGetFromCtx, CfgGetJsonField, CfgGetResourceField, CfgImmediate, CfgImportProgress, CfgIsEmpty, CfgIsolate, CfgLastLogs, CfgLogHandle, CfgMakeArray, CfgMakeObject, CfgMapArrayValues, CfgMapRecordValues, CfgMapResourceFields, CfgNot, CfgOnDemandBlobContent, CfgOr, CfgProgressLog, CfgProgressLogWithInfo, CfgResourceValueAsJson, Column, ColumnData, ColumnDiscoveredRecipe, type ColumnFieldStatus, ColumnFilteredRecipe, ColumnOption, type ColumnOrderRule, ColumnOverriddenRecipe, ColumnProvider, ColumnRecipe, type ColumnRecipeId, type ColumnResolutionStatus, ColumnSource, ColumnValueOption, ColumnValueOptionsColumn, ColumnValueOptionsModel, type ColumnVisibilityRule, ColumnsCollection, ColumnsCollectionDeps, ColumnsCollectionImpl, type ColumnsDisplayOptions, ColumnsProvider, type ColumnsSelectorConfig, ColumnsSource, ColumnsSourceShorthand, CommonFieldTraverseOps, CommonTraversalOps, ConfigRenderLambda, ConfigRenderLambdaFlags, CurrentSdkInfo, DataColumn, DataColumnId, DataColumnImpl, DataColumnRecipe, DataColumnSource, DataModel, DataModelBuilder, DatasetAxes, DatasetOption, DatasetSelection, DeriveHref, DeriveLabelsFormatters, DeriveLabelsOptions, DiscoveredRoot, Entry, ExpressionSpec, ExtractFunctionHandleReturn, type ExtractFutureRefType, FieldTraversalStep, FieldType, FilterMatchOptions, type FilterSpec, type FilterSpecLeaf, type FilterSpecNode, type FilterSpecOfType, type FilterSpecType, FilterSpecUi, FilterUi, FilterUiOfType, FilterUiType, FindFilterColumnsOptions, FormField, FutureRef, GetFieldStep, InferArgsType, InferBlockState, InferBlockStatePatch, InferDataType, InferFactoryData, InferFactoryModelServices, InferFactoryOutputs, InferFactoryParams, InferFactoryUiServices, InferHrefType, InferOutputsFromLambdas, InferOutputsType, InferPluginData, InferPluginHandle, InferPluginNames, InferPluginUiEntries, InferRenderFunctionReturn, InferUiState, IsNA, internal_d_exports as JsRenderInternal, type DeriveLabelsOptions as LabelDerivationOps, LinkerStep, Log10, MainAccessorName, type MigrateBlockStorageConfig, type MigrationFailure, type MigrationResult, type MigrationSuccess, type ModelServices, type MutateStoragePayload, NotFilter, NumericalComparisonFilter, OptionalPlResourceEntry, OrFilter, OutputError, PColumnCollection, type PColumnDataUniversal, PColumnEntryUniversal, PColumnEntryWithLabel, PColumnKeyList, PColumnPredicate, PColumnResourceMapData, PColumnResourceMapEntry, PColumnUniversal, PColumnWithLabel, PFrameImpl, PTableKey, type PTableParamsV2, type ParamsInput, Patch, PatternFilter, PatternPredicate, PatternPredicateContainSubsequence, PatternPredicateEquals, type PlDataTableAxisMeta, type PlDataTableColumnMeta, type PlDataTableColumnsMeta, type PlDataTableFilterMeta, type PlDataTableFilterSpecLeaf, type PlDataTableFilters, type PlDataTableFiltersWithMeta, type PlDataTableGridStateCore, type PlDataTableModel, type PlDataTableSheet, type PlDataTableSheetState, type PlDataTableStateV2, type PlDataTableStateV2CacheEntry, type PlDataTableStateV2Normalized, PlMultiSequenceAlignmentColorSchemeOption, PlMultiSequenceAlignmentModel, PlMultiSequenceAlignmentSettings, PlMultiSequenceAlignmentWidget, PlResourceEntry, PlSelectionModel, type PlTableColumnIdJson, Platforma, PlatformaApiVersion, PlatformaExtended, PlatformaFactory, PlatformaSDKVersion, PlatformaV1, PlatformaV2, PlatformaV3, type PluginConfig, type PluginData, PluginDataModel, PluginDataModelBuilder, type PluginDataModelVersions, type PluginFactory, PluginFactoryLike, PluginHandle, PluginInstance, PluginModel, type PluginName, type PluginOutputs, type PluginParams, type PluginPublicOutputs, type PluginRecord, type PluginRegistry, PluginRenderCtx, PresentColumnValueOptionsModel, type PublicOutputFieldDef, QueryColumnId, QueryColumnIdAxis, QueryColumnIdColumn, RT_BINARY_PARTITIONED, RT_BINARY_SUPER_PARTITIONED, RT_JSON_PARTITIONED, RT_JSON_SUPER_PARTITIONED, RT_PARQUET_PARTITIONED, RT_PARQUET_SUPER_PARTITIONED, RT_RESOURCE_MAP, RT_RESOURCE_MAP_PARTITIONED, RenderCtx, RenderCtxBase, RenderFunction, ResolveModelServices, ResolveUiServices, ResourceTraversalOps, ResourceType, ResultPool, ResultPoolColumnsProvider, ResultPoolColumnsProviderImpl, SdkInfo, ServiceProxy, SimplifiedPColumnSpec, SimplifiedUniversalPColumnEntry, SortedCumulativeSum, type Entry as SpecExtractorResult, type SpecQuery, SplitAxis, SplitByAxesOpts, StagingAccessorName, StdCtx, StdCtxArgsOnly, TooltipEntry, type Trace, type TraceEntry, TransformedColumn, TreeNodeAccessor, TypeField, TypeFieldRecord, TypeForm, TypeToLiteral, TypedConfig, TypedConfigOrConfigLambda, TypedConfigOrString, type UiServices, Unionize, UniversalColumnOption, UnwrapFutureRef, ValueRank, type VersionedData, _ctxProvidersCache, allPColumnsReady, blockServiceNames, buildDatasetOptions, buildRefMap, buildServices, collectDatasetAxes, collectLinkerColumns, collectLinkerIds, compileAnnotationScript, compileFilter, compileFilters, convertFilterSpecsToExpressionSpecs, convertFilterUiToExpressionImpl, convertFilterUiToExpressions, convertOrParsePColumnData, createBlockStorage, createColumnValueOptions, createDatasetSelection, createDefaultPTableParams, createPFrameForGraphs, createPeerLinkFinder, createPlDataTable, type createPlDataTableOptionsV3, createPlDataTableSheet, createPlDataTableStateV2, createPlDataTableV2, createPlDataTableV3, createPlSelectionModel, createRowSelectionColumn, createServiceProxy, deriveAxisValuesLabels, deriveColumnOptions, deriveColumnValueOptions, deriveDataFromStorage, deriveDistinctLabels, deriveDistinctTooltips, deriveLabelledColumnValueOptions, deriveLabels, deriveRecipeOptions, describePeerLinks, discoverTableColumns as discoverTableColumnSnaphots, distillFilterSpec, downgradeCfgOrLambda, enrichCompatible, extractConfig, filterDataInfoEntries, filterMatchesToOptions, filterSpecToSpecQueryExpr, finalizePColumnData, findFilterColumns, findPeerLinks, getAllRelatedColumns, getAvailableWithLinkersAxes, getAxisUniqueValues, getColumnOrAxisValueLabelsId, getColumnSpecById, getColumnUniqueValues, getColumnsFull, getCtxProviders, getEffectiveVisibility, getEnvironmentValue, getNumberOfRows, getOrderPriority, getPartitionKeysList, getPlatformaApiVersion, getPluginData, getRawPlatformaInstance, getRelatedColumns, getRequestColumnsFromSelectedSources, getResultPoolDatasetAxes, getService, getSingleColumnData, getStorageData, getUniqueAxisValuesWithLabels, getUniquePartitionKeys, getUniqueSourceValuesWithLabels, hasColumnData, hasReachableData, hasSingleDataColumn, hitQualifications, ifDef, isBlockStorage, isColumn, isColumnHidden, isColumnOptional, isColumnProvider, isColumnsCollection, isConfigLambda, isDataColumn, isDatasetSelection, isHiddenFromGraphColumn, isHiddenFromUIColumn, isLeafColumn, isPColumnReady, isPluginOutputKey, migrateBlockStorage, normalizeBlockStorage, parsePColumnData, parseResourceMap, peerLinkedLast, pluginOutputKey, pluginOutputPrefix, queriesQualifications, readColumnValueOptions, readOutput, registerFacadeCallbacks, splitByAxes, toColumnProvider, unreachable, updateStorageData, upgradePlDataTableStateV2, wrapOutputs };
|
package/dist/package.cjs
CHANGED
package/dist/package.js
CHANGED
|
@@ -124,11 +124,14 @@ var PColumnCollection = class {
|
|
|
124
124
|
const selectedColumns = [];
|
|
125
125
|
for (const provider of this.providers) {
|
|
126
126
|
const providerColumns = provider.selectColumns(currentSelector);
|
|
127
|
+
const providerIds = /* @__PURE__ */ new Set();
|
|
127
128
|
for (const col of providerColumns) {
|
|
128
129
|
if (excludePredicate(col.spec)) continue;
|
|
129
|
-
if (
|
|
130
|
+
if (providerIds.has(col.id)) throw new Error(`Duplicate column id ${col.id} in provider ${provider.constructor.name}`);
|
|
131
|
+
providerIds.add(col.id);
|
|
130
132
|
const nativeId = (0, _milaboratories_pl_model_common.deriveNativeId)(col.spec);
|
|
131
133
|
if (selectedNativeIds.has(nativeId)) continue;
|
|
134
|
+
if (selectedIds.has(col.id)) throw new Error(`Column id ${col.id} in provider ${provider.constructor.name} is already taken by a different column of another provider`);
|
|
132
135
|
selectedIds.add(col.id);
|
|
133
136
|
selectedNativeIds.add(nativeId);
|
|
134
137
|
selectedColumns.push(col);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"column_collection.cjs","names":["legacyColumnSelectorsToPredicate","canonicalizeAxisId","resolveAnchors","deriveNativeId","isPColumnSpec","convertOrParsePColumnData","isPartitionedDataInfoEntries","getUniquePartitionKeys","getAxisId","deriveLabels","Annotation","entriesToDataInfo","filterDataInfoEntries","isLinkerColumn","LinkerMap","getColumnIdAndSpec","matchAxisId"],"sources":["../../../src/render/util/column_collection.ts"],"sourcesContent":["import type {\n AnchoredIdDeriver,\n AnchoredPColumnSelector,\n AxisFilterByIdx,\n AxisFilterValue,\n AxisId,\n NativePObjectId,\n PartitionedDataInfoEntries,\n PColumn,\n PColumnSelector,\n PColumnSpec,\n PColumnValues,\n PObjectId,\n ResolveAnchorsOptions,\n SUniversalPColumnId,\n} from \"@milaboratories/pl-model-common\";\nimport {\n Annotation,\n canonicalizeAxisId,\n deriveNativeId,\n entriesToDataInfo,\n getAxisId,\n getColumnIdAndSpec,\n isLinkerColumn,\n isPartitionedDataInfoEntries,\n isPColumnSpec,\n legacyColumnSelectorsToPredicate,\n LinkerMap,\n matchAxisId,\n resolveAnchors,\n} from \"@milaboratories/pl-model-common\";\nimport canonicalize from \"canonicalize\";\nimport type { Optional } from \"utility-types\";\nimport type { TreeNodeAccessor } from \"../accessor\";\nimport type { PColumnDataUniversal } from \"../internal\";\nimport { filterDataInfoEntries } from \"./axis_filtering\";\nimport type { LabelDerivationOps } from \"./label\";\nimport { deriveLabels } from \"./label\";\nimport { convertOrParsePColumnData, getUniquePartitionKeys } from \"./pcolumn_data\";\nimport type { APColumnSelectorWithSplit, PColumnSelectorWithSplit } from \"./split_selectors\";\n\nfunction isPColumnValues(value: unknown): value is PColumnValues {\n if (!Array.isArray(value)) return false;\n if (value.length === 0) return true;\n const first = value[0];\n return typeof first === \"object\" && first !== null && \"key\" in first && \"val\" in first;\n}\n\nexport interface ColumnProvider {\n selectColumns(\n selectors: ((spec: PColumnSpec) => boolean) | PColumnSelector | PColumnSelector[],\n ): PColumn<PColumnDataUniversal | undefined>[];\n}\n\nexport interface AxisLabelProvider {\n findLabels(axis: AxisId): Record<string | number, string> | undefined;\n}\n\n/**\n * A simple implementation of {@link ColumnProvider} backed by a pre-defined array of columns.\n */\nclass ArrayColumnsProvider implements ColumnProvider {\n constructor(private readonly columns: PColumn<PColumnDataUniversal | undefined>[]) {}\n\n selectColumns(\n selectors: ((spec: PColumnSpec) => boolean) | PColumnSelector | PColumnSelector[],\n ): PColumn<PColumnDataUniversal | undefined>[] {\n const predicate =\n typeof selectors === \"function\" ? selectors : legacyColumnSelectorsToPredicate(selectors);\n // Filter based on spec, ignoring data type for now\n return this.columns.filter((column): column is PColumn<PColumnDataUniversal | undefined> =>\n predicate(column.spec),\n );\n }\n}\n\n/** Lazy calculates the data, returns undefined if data is not ready. */\nexport type PColumnWithLabel<T> = PColumn<T> & {\n label: string;\n};\n\n/** Universal column is a column that uses a universal column id, and always have label. */\nexport type PColumnUniversal<T> = PColumnWithLabel<T> & {\n id: SUniversalPColumnId;\n};\n\n/** @deprecated Use PColumnWithLabel instead. */\nexport type PColumnEntryWithLabel = PColumn<undefined | PColumnDataUniversal> & {\n label: string;\n};\n\n/** @deprecated Use PColumnUniversal instead. */\nexport type PColumnEntryUniversal = PColumnEntryWithLabel & {\n id: SUniversalPColumnId;\n};\n\n// Helper types similar to those in api.ts\ntype AxisFilterInfo = {\n axisIdx: number;\n axisId: AxisId;\n value: AxisFilterValue;\n label: string;\n};\n\n// Intermediate representation for columns requiring splitting\ntype IntermediateSplitEntry = {\n type: \"split\";\n originalColumn: PColumn<PColumnDataUniversal | undefined>;\n spec: PColumnSpec;\n /** With splitting axes removed */\n adjustedSpec: PColumnSpec;\n dataEntries: PartitionedDataInfoEntries<TreeNodeAccessor>;\n axisFilters: AxisFilterInfo[];\n};\n\n// Intermediate representation for columns NOT requiring splitting\ntype IntermediateDirectEntry = {\n type: \"direct\";\n originalColumn: PColumn<PColumnDataUniversal | undefined>;\n spec: PColumnSpec;\n /** The same as `spec` */\n adjustedSpec: PColumnSpec;\n};\n\n// Union type for intermediate processing\ntype IntermediateColumnEntry = IntermediateSplitEntry | IntermediateDirectEntry;\n\nfunction splitFiltersToExtraTrace(splitFilters?: AxisFilterInfo[]) {\n if (splitFilters === undefined) return undefined;\n return splitFilters.map((filter) => ({\n type: `split:${canonicalizeAxisId(filter.axisId)}`,\n label: filter.label,\n importance: 1_000_000, // High importance for split filters in labels\n }));\n}\n\nfunction splitFiltersToAxisFilter(splitFilters?: AxisFilterInfo[]): AxisFilterByIdx[] | undefined {\n if (!splitFilters) return undefined;\n return splitFilters.map((filter): AxisFilterByIdx => [filter.axisIdx, filter.value]);\n}\n\nfunction fallbackIdDeriver(originalId: PObjectId, axisFilters?: AxisFilterByIdx[]): PObjectId {\n if (!axisFilters || axisFilters.length === 0) return originalId;\n const filtersToCanonicalize = [...axisFilters].sort((a, b) => a[0] - b[0]);\n return canonicalize({ id: originalId, axisFilters: filtersToCanonicalize })! as PObjectId;\n}\n\n/** Checks if a selector object uses any anchor properties */\nfunction hasAnchors(selector: unknown): selector is AnchoredPColumnSelector {\n if (!selector || typeof selector !== \"object\") return false;\n const potentialAnchored = selector as Record<string, any>;\n const hasAnchorValues = (obj: unknown) =>\n obj &&\n typeof obj === \"object\" &&\n Object.values(obj).some((v: unknown) => typeof v === \"object\" && v !== null && \"anchor\" in v);\n const domainHasAnchors = hasAnchorValues(potentialAnchored[\"domain\"]);\n const contextDomainHasAnchors = hasAnchorValues(potentialAnchored[\"contextDomain\"]);\n const axesHaveAnchors =\n potentialAnchored[\"axes\"] &&\n Array.isArray(potentialAnchored[\"axes\"]) &&\n potentialAnchored[\"axes\"].some(\n (a: unknown) => typeof a === \"object\" && a !== null && \"anchor\" in a,\n );\n return (\n !!potentialAnchored[\"domainAnchor\"] ||\n !!potentialAnchored[\"contextDomainAnchor\"] ||\n domainHasAnchors ||\n contextDomainHasAnchors ||\n axesHaveAnchors\n );\n}\n\n/**\n * Derives the indices of axes marked for splitting based on the selector.\n * Throws an error if splitting is requested alongside `partialAxesMatch`.\n */\nfunction getSplitAxisIndices(\n selector: APColumnSelectorWithSplit | ((spec: PColumnSpec) => boolean),\n): number[] {\n if (typeof selector !== \"object\" || !(\"axes\" in selector) || selector.axes === undefined) {\n return []; // No axes specified or not an object selector, no splitting\n }\n\n const splitIndices = selector.axes\n .map((axis, index) =>\n typeof axis === \"object\" && \"split\" in axis && axis.split === true ? index : -1,\n )\n .filter((index) => index !== -1);\n\n if (splitIndices.length > 0 && selector.partialAxesMatch !== undefined) {\n throw new Error(\"Axis splitting is not supported when `partialAxesMatch` is defined.\");\n }\n\n splitIndices.sort((a, b) => a - b);\n return splitIndices;\n}\n\ntype UniversalPColumnOptsNoDeriver = {\n /** If provided, columns matching the provided selectors will be excluded from the result. */\n exclude?: AnchoredPColumnSelector | AnchoredPColumnSelector[];\n labelOps?: LabelDerivationOps;\n /** If true, incomplete data will cause the column to be skipped instead of returning undefined for the whole request. */\n dontWaitAllData?: boolean;\n /**\n * If true, the derived label will override the 'pl7.app/label' annotation\n * in the resulting PColumnSpec. It also forces `includeNativeLabel` in `labelOps` to true,\n * unless `labelOps.includeNativeLabel` is explicitly set to false.\n * Default value in getUniversalEntries is false, in getColumns it is true.\n */\n overrideLabelAnnotation?: boolean;\n /** If true, resulting columns will be enriched by other columns considering linker columns. Default is false. */\n enrichByLinkers?: boolean;\n};\n\ntype UniversalPColumnOpts = UniversalPColumnOptsNoDeriver & {\n anchorCtx: AnchoredIdDeriver;\n} & ResolveAnchorsOptions;\n\nexport class PColumnCollection {\n private readonly defaultProviderStore: PColumn<PColumnDataUniversal | undefined>[] = [];\n private readonly providers: ColumnProvider[] = [\n new ArrayColumnsProvider(this.defaultProviderStore),\n ];\n private readonly axisLabelProviders: AxisLabelProvider[] = [];\n\n constructor() {}\n\n public addColumnProvider(provider: ColumnProvider): this {\n this.providers.push(provider);\n return this;\n }\n\n public addAxisLabelProvider(provider: AxisLabelProvider): this {\n this.axisLabelProviders.push(provider);\n return this;\n }\n\n public addColumns(columns: PColumn<PColumnDataUniversal | undefined>[]): this {\n this.defaultProviderStore.push(...columns);\n return this;\n }\n\n public addColumn(column: PColumn<PColumnDataUniversal | undefined>): this {\n this.defaultProviderStore.push(column);\n return this;\n }\n\n /** Fetches labels for a given axis from the registered providers */\n private findLabels(axis: AxisId): Record<string | number, string> | undefined {\n for (const provider of this.axisLabelProviders) {\n const labels = provider.findLabels(axis);\n if (labels) return labels; // First provider wins\n }\n return undefined;\n }\n\n // Overload signatures updated to return PColumnEntry types\n public getUniversalEntries(\n predicateOrSelectors:\n | ((spec: PColumnSpec) => boolean)\n | APColumnSelectorWithSplit\n | APColumnSelectorWithSplit[],\n opts: UniversalPColumnOpts,\n ): PColumnEntryUniversal[] | undefined;\n public getUniversalEntries(\n predicateOrSelectors:\n | ((spec: PColumnSpec) => boolean)\n | PColumnSelectorWithSplit\n | PColumnSelectorWithSplit[],\n opts?: UniversalPColumnOptsNoDeriver,\n ): PColumnEntryWithLabel[] | undefined;\n public getUniversalEntries(\n predicateOrSelectors:\n | ((spec: PColumnSpec) => boolean)\n | APColumnSelectorWithSplit\n | APColumnSelectorWithSplit[],\n opts?: Optional<UniversalPColumnOpts, \"anchorCtx\">,\n ): (PColumnEntryWithLabel | PColumnEntryUniversal)[] | undefined {\n const {\n anchorCtx,\n labelOps: rawLabelOps,\n dontWaitAllData = false,\n overrideLabelAnnotation = false,\n exclude,\n enrichByLinkers = false,\n } = opts ?? {};\n\n const labelOps: LabelDerivationOps = {\n ...(overrideLabelAnnotation && rawLabelOps?.includeNativeLabel !== false\n ? { includeNativeLabel: true }\n : {}),\n ...rawLabelOps,\n };\n\n let excludePredicate: (spec: PColumnSpec) => boolean = () => false;\n if (exclude) {\n const excludePredicartes = (Array.isArray(exclude) ? exclude : [exclude]).map((selector) => {\n if (hasAnchors(selector)) {\n if (!anchorCtx)\n throw new Error(\n \"Anchored selectors in exclude require an AnchoredIdDeriver to be provided in options.\",\n );\n return legacyColumnSelectorsToPredicate(\n resolveAnchors(anchorCtx.anchors, selector, opts),\n );\n } else return legacyColumnSelectorsToPredicate(selector);\n });\n excludePredicate = (spec) => excludePredicartes.some((predicate) => predicate(spec));\n }\n\n const selectorsArray =\n typeof predicateOrSelectors === \"function\"\n ? [predicateOrSelectors]\n : Array.isArray(predicateOrSelectors)\n ? predicateOrSelectors\n : [predicateOrSelectors];\n\n const intermediateResults: IntermediateColumnEntry[] = [];\n const selectedNativeIds = new Set<NativePObjectId>();\n\n for (const rawSelector of selectorsArray) {\n const usesAnchors = hasAnchors(rawSelector);\n\n let currentSelector: PColumnSelectorWithSplit | ((spec: PColumnSpec) => boolean);\n if (usesAnchors) {\n if (!anchorCtx)\n throw new Error(\n \"Anchored selectors require an AnchoredIdDeriver to be provided in options.\",\n );\n currentSelector = resolveAnchors(\n anchorCtx.anchors,\n rawSelector as AnchoredPColumnSelector,\n opts,\n );\n } else\n currentSelector = rawSelector as\n | PColumnSelectorWithSplit\n | ((spec: PColumnSpec) => boolean);\n\n const selectedIds = new Set<PObjectId>();\n const selectedColumns: PColumn<PColumnDataUniversal | undefined>[] = [];\n for (const provider of this.providers) {\n const providerColumns = provider.selectColumns(currentSelector);\n for (const col of providerColumns) {\n if (excludePredicate(col.spec)) continue;\n if (selectedIds.has(col.id))\n throw new Error(\n `Duplicate column id ${col.id} in provider ${provider.constructor.name}`,\n );\n const nativeId = deriveNativeId(col.spec);\n if (selectedNativeIds.has(nativeId)) continue;\n selectedIds.add(col.id);\n selectedNativeIds.add(nativeId);\n selectedColumns.push(col);\n }\n }\n\n if (selectedColumns.length === 0) continue;\n\n const splitAxisIdxs = getSplitAxisIndices(rawSelector);\n const needsSplitting = splitAxisIdxs.length > 0;\n\n for (const column of selectedColumns) {\n if (!isPColumnSpec(column.spec)) continue;\n\n const originalSpec = column.spec;\n\n if (needsSplitting) {\n if (isPColumnValues(column.data))\n throw new Error(\n `Splitting is not supported for PColumns with PColumnValues data format. Column id: ${column.id}`,\n );\n const dataEntries = convertOrParsePColumnData(column.data);\n\n if (!dataEntries) {\n if (dontWaitAllData) continue;\n return undefined;\n }\n\n if (!isPartitionedDataInfoEntries(dataEntries))\n throw new Error(\n `Splitting requires Partitioned DataInfoEntries, but parsing resulted in ${dataEntries.type} for column ${column.id}`,\n );\n\n const uniqueKeys = getUniquePartitionKeys(dataEntries);\n\n const maxSplitIdx = splitAxisIdxs[splitAxisIdxs.length - 1];\n if (maxSplitIdx >= dataEntries.partitionKeyLength)\n throw new Error(\n `Not enough partition keys (${dataEntries.partitionKeyLength}) for requested split axes (max index ${maxSplitIdx}) in column ${originalSpec.name}`,\n );\n\n const axesLabels: (Record<string | number, string> | undefined)[] = splitAxisIdxs.map(\n (idx) => this.findLabels(getAxisId(originalSpec.axesSpec[idx])),\n );\n\n const keyCombinations: (string | number)[][] = [];\n const generateCombinations = (currentCombo: (string | number)[], sAxisIdx: number) => {\n if (sAxisIdx >= splitAxisIdxs.length) {\n keyCombinations.push([...currentCombo]);\n if (keyCombinations.length > 10000)\n throw new Error(\"Too many key combinations, aborting.\");\n return;\n }\n const axisIdx = splitAxisIdxs[sAxisIdx];\n if (axisIdx >= uniqueKeys.length)\n throw new Error(\n `Axis index ${axisIdx} out of bounds for unique keys array (length ${uniqueKeys.length}) during split key generation for column ${column.id}`,\n );\n const axisValues = uniqueKeys[axisIdx];\n if (!axisValues || axisValues.length === 0) {\n keyCombinations.length = 0; // No combinations possible if one axis has no keys\n return;\n }\n for (const val of axisValues) {\n currentCombo.push(val);\n generateCombinations(currentCombo, sAxisIdx + 1);\n currentCombo.pop();\n }\n };\n\n generateCombinations([], 0);\n\n if (keyCombinations.length === 0) continue;\n\n const newAxesSpec = [...originalSpec.axesSpec];\n const splitAxisOriginalIdxs = splitAxisIdxs.map((idx) => idx); // Keep original indices for axisId lookup\n // Remove axes in reverse order to maintain correct indices during removal\n for (let i = splitAxisIdxs.length - 1; i >= 0; i--) {\n newAxesSpec.splice(splitAxisIdxs[i], 1);\n }\n const adjustedSpec = { ...originalSpec, axesSpec: newAxesSpec };\n\n for (const keyCombo of keyCombinations) {\n const splitFilters: AxisFilterInfo[] = keyCombo.map((value, sAxisIdx) => {\n const axisIdx = splitAxisOriginalIdxs[sAxisIdx]; // Use original index for lookup\n const axisId = getAxisId(originalSpec.axesSpec[axisIdx]);\n const axisLabelMap = axesLabels[sAxisIdx];\n const label = axisLabelMap?.[value] ?? String(value);\n return { axisIdx, axisId, value: value as AxisFilterValue, label };\n });\n\n intermediateResults.push({\n type: \"split\",\n originalColumn: column,\n spec: originalSpec,\n adjustedSpec,\n dataEntries,\n axisFilters: splitFilters,\n });\n }\n } else {\n intermediateResults.push({\n type: \"direct\",\n originalColumn: column,\n spec: originalSpec,\n adjustedSpec: originalSpec,\n });\n }\n }\n }\n\n if (intermediateResults.length === 0) return [];\n\n const labeledResults = deriveLabels(\n intermediateResults,\n (entry) => ({\n spec: entry.spec,\n extraTrace:\n entry.type === \"split\" ? splitFiltersToExtraTrace(entry.axisFilters) : undefined,\n }),\n labelOps,\n );\n\n const result: (PColumnEntryWithLabel | PColumnEntryUniversal)[] = [];\n\n for (const { value: entry, label } of labeledResults) {\n const { originalColumn, spec: originalSpec } = entry;\n\n const axisFilters = entry.type === \"split\" ? entry.axisFilters : undefined;\n const axisFiltersTuple = splitFiltersToAxisFilter(axisFilters);\n\n let finalId: SUniversalPColumnId | PObjectId;\n if (anchorCtx) finalId = anchorCtx.deriveS(originalSpec, axisFiltersTuple);\n else finalId = fallbackIdDeriver(originalColumn.id, axisFiltersTuple);\n\n let finalSpec = { ...entry.adjustedSpec };\n\n if (overrideLabelAnnotation) {\n finalSpec = {\n ...finalSpec,\n annotations: {\n ...finalSpec.annotations,\n [Annotation.Label]: label,\n } satisfies Annotation,\n };\n }\n\n result.push({\n id: finalId as PObjectId,\n spec: finalSpec,\n get data() {\n return entry.type === \"split\"\n ? entriesToDataInfo(filterDataInfoEntries(entry.dataEntries, axisFiltersTuple!))\n : entry.originalColumn.data;\n },\n label: label,\n });\n }\n\n const ids = new Set(result.map((entry) => entry.id));\n\n if (enrichByLinkers && anchorCtx) {\n const linkers = result.filter((entry) => isLinkerColumn(entry.spec));\n if (linkers.length === 0) {\n return result;\n }\n\n const anchorAxes = Object.values(anchorCtx.anchors).flatMap((anchor) => anchor.axesSpec);\n const linkerMap = LinkerMap.fromColumns(linkers.map(getColumnIdAndSpec));\n\n // loose way of matching\n function matchAxisIdFn(linkerKeyId: AxisId, sourceAxisId: AxisId): boolean {\n return matchAxisId(linkerKeyId, sourceAxisId) || matchAxisId(sourceAxisId, linkerKeyId);\n }\n // search all axes that can be reached by linkers from anchor axes; anchor axes are not in this list;\n const availableByLinkersAxes = linkerMap.getReachableByLinkersAxesFromAxes(\n anchorAxes,\n matchAxisIdFn,\n );\n\n // search all columns that includes at least one of additional axes;\n const availableByLinkersColumns = this.getUniversalEntries(\n (spec) =>\n !isLinkerColumn(spec) &&\n spec.axesSpec.some((columnAxisSpec) => {\n const columnAxisId = getAxisId(columnAxisSpec);\n return availableByLinkersAxes.some((axis) =>\n matchAxisIdFn(getAxisId(axis), columnAxisId),\n );\n }),\n { anchorCtx, labelOps, dontWaitAllData, overrideLabelAnnotation, exclude },\n );\n if (availableByLinkersColumns) {\n result.push(...availableByLinkersColumns.filter((entry) => !ids.has(entry.id)));\n }\n }\n\n return result;\n }\n\n public getColumns(\n predicateOrSelectors:\n | ((spec: PColumnSpec) => boolean)\n | APColumnSelectorWithSplit\n | APColumnSelectorWithSplit[],\n opts: UniversalPColumnOpts,\n ): PColumn<undefined | PColumnDataUniversal>[] | undefined;\n public getColumns(\n predicateOrSelectors:\n | ((spec: PColumnSpec) => boolean)\n | PColumnSelectorWithSplit\n | PColumnSelectorWithSplit[],\n opts?: UniversalPColumnOptsNoDeriver,\n ): PColumn<undefined | PColumnDataUniversal>[] | undefined;\n public getColumns(\n predicateOrSelectors:\n | ((spec: PColumnSpec) => boolean)\n | APColumnSelectorWithSplit\n | APColumnSelectorWithSplit[],\n opts?: Optional<UniversalPColumnOpts, \"anchorCtx\">,\n ): PColumn<undefined | PColumnDataUniversal>[] | undefined {\n const entries = this.getUniversalEntries(predicateOrSelectors, {\n overrideLabelAnnotation: true, // default for getColumns\n ...opts,\n } as UniversalPColumnOpts);\n if (!entries) return undefined;\n\n const columns: PColumn<undefined | PColumnDataUniversal>[] = [];\n for (const entry of entries) {\n const data = entry.data;\n if (!data) {\n if (opts?.dontWaitAllData) continue;\n return undefined;\n }\n columns.push({\n id: entry.id,\n spec: entry.spec,\n data,\n });\n }\n\n return columns;\n }\n}\n"],"mappings":";;;;;;;;AAyCA,SAAS,gBAAgB,OAAwC;CAC/D,IAAI,CAAC,MAAM,QAAQ,KAAK,GAAG,OAAO;CAClC,IAAI,MAAM,WAAW,GAAG,OAAO;CAC/B,MAAM,QAAQ,MAAM;CACpB,OAAO,OAAO,UAAU,YAAY,UAAU,QAAQ,SAAS,SAAS,SAAS;AACnF;;;;AAeA,IAAM,uBAAN,MAAqD;CACtB;CAA7B,YAAY,SAAuE;EAAtD,KAAA,UAAA;CAAuD;CAEpF,cACE,WAC6C;EAC7C,MAAM,YACJ,OAAO,cAAc,aAAa,aAAA,GAAYA,gCAAAA,iCAAAA,CAAiC,SAAS;EAE1F,OAAO,KAAK,QAAQ,QAAQ,WAC1B,UAAU,OAAO,IAAI,CACvB;CACF;AACF;AAqDA,SAAS,yBAAyB,cAAiC;CACjE,IAAI,iBAAiB,KAAA,GAAW,OAAO,KAAA;CACvC,OAAO,aAAa,KAAK,YAAY;EACnC,MAAM,UAAA,GAASC,gCAAAA,mBAAAA,CAAmB,OAAO,MAAM;EAC/C,OAAO,OAAO;EACd,YAAY;CACd,EAAE;AACJ;AAEA,SAAS,yBAAyB,cAAgE;CAChG,IAAI,CAAC,cAAc,OAAO,KAAA;CAC1B,OAAO,aAAa,KAAK,WAA4B,CAAC,OAAO,SAAS,OAAO,KAAK,CAAC;AACrF;AAEA,SAAS,kBAAkB,YAAuB,aAA4C;CAC5F,IAAI,CAAC,eAAe,YAAY,WAAW,GAAG,OAAO;CACrD,MAAM,wBAAwB,CAAC,GAAG,WAAW,CAAC,CAAC,MAAM,GAAG,MAAM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CAAC,MAAM;IACT,IAAI,MAAM,iBAAiB;IAC3B;GACF;GACA,QAAQ,KAAK;IACX,IAAI,MAAM;IACV,MAAM,MAAM;IACZ;GACF,CAAC;EACH;EAEA,OAAO;CACT;AACF"}
|
|
1
|
+
{"version":3,"file":"column_collection.cjs","names":["legacyColumnSelectorsToPredicate","canonicalizeAxisId","resolveAnchors","deriveNativeId","isPColumnSpec","convertOrParsePColumnData","isPartitionedDataInfoEntries","getUniquePartitionKeys","getAxisId","deriveLabels","Annotation","entriesToDataInfo","filterDataInfoEntries","isLinkerColumn","LinkerMap","getColumnIdAndSpec","matchAxisId"],"sources":["../../../src/render/util/column_collection.ts"],"sourcesContent":["import type {\n AnchoredIdDeriver,\n AnchoredPColumnSelector,\n AxisFilterByIdx,\n AxisFilterValue,\n AxisId,\n NativePObjectId,\n PartitionedDataInfoEntries,\n PColumn,\n PColumnSelector,\n PColumnSpec,\n PColumnValues,\n PObjectId,\n ResolveAnchorsOptions,\n SUniversalPColumnId,\n} from \"@milaboratories/pl-model-common\";\nimport {\n Annotation,\n canonicalizeAxisId,\n deriveNativeId,\n entriesToDataInfo,\n getAxisId,\n getColumnIdAndSpec,\n isLinkerColumn,\n isPartitionedDataInfoEntries,\n isPColumnSpec,\n legacyColumnSelectorsToPredicate,\n LinkerMap,\n matchAxisId,\n resolveAnchors,\n} from \"@milaboratories/pl-model-common\";\nimport canonicalize from \"canonicalize\";\nimport type { Optional } from \"utility-types\";\nimport type { TreeNodeAccessor } from \"../accessor\";\nimport type { PColumnDataUniversal } from \"../internal\";\nimport { filterDataInfoEntries } from \"./axis_filtering\";\nimport type { LabelDerivationOps } from \"./label\";\nimport { deriveLabels } from \"./label\";\nimport { convertOrParsePColumnData, getUniquePartitionKeys } from \"./pcolumn_data\";\nimport type { APColumnSelectorWithSplit, PColumnSelectorWithSplit } from \"./split_selectors\";\n\nfunction isPColumnValues(value: unknown): value is PColumnValues {\n if (!Array.isArray(value)) return false;\n if (value.length === 0) return true;\n const first = value[0];\n return typeof first === \"object\" && first !== null && \"key\" in first && \"val\" in first;\n}\n\nexport interface ColumnProvider {\n selectColumns(\n selectors: ((spec: PColumnSpec) => boolean) | PColumnSelector | PColumnSelector[],\n ): PColumn<PColumnDataUniversal | undefined>[];\n}\n\nexport interface AxisLabelProvider {\n findLabels(axis: AxisId): Record<string | number, string> | undefined;\n}\n\n/**\n * A simple implementation of {@link ColumnProvider} backed by a pre-defined array of columns.\n */\nclass ArrayColumnsProvider implements ColumnProvider {\n constructor(private readonly columns: PColumn<PColumnDataUniversal | undefined>[]) {}\n\n selectColumns(\n selectors: ((spec: PColumnSpec) => boolean) | PColumnSelector | PColumnSelector[],\n ): PColumn<PColumnDataUniversal | undefined>[] {\n const predicate =\n typeof selectors === \"function\" ? selectors : legacyColumnSelectorsToPredicate(selectors);\n // Filter based on spec, ignoring data type for now\n return this.columns.filter((column): column is PColumn<PColumnDataUniversal | undefined> =>\n predicate(column.spec),\n );\n }\n}\n\n/** Lazy calculates the data, returns undefined if data is not ready. */\nexport type PColumnWithLabel<T> = PColumn<T> & {\n label: string;\n};\n\n/** Universal column is a column that uses a universal column id, and always have label. */\nexport type PColumnUniversal<T> = PColumnWithLabel<T> & {\n id: SUniversalPColumnId;\n};\n\n/** @deprecated Use PColumnWithLabel instead. */\nexport type PColumnEntryWithLabel = PColumn<undefined | PColumnDataUniversal> & {\n label: string;\n};\n\n/** @deprecated Use PColumnUniversal instead. */\nexport type PColumnEntryUniversal = PColumnEntryWithLabel & {\n id: SUniversalPColumnId;\n};\n\n// Helper types similar to those in api.ts\ntype AxisFilterInfo = {\n axisIdx: number;\n axisId: AxisId;\n value: AxisFilterValue;\n label: string;\n};\n\n// Intermediate representation for columns requiring splitting\ntype IntermediateSplitEntry = {\n type: \"split\";\n originalColumn: PColumn<PColumnDataUniversal | undefined>;\n spec: PColumnSpec;\n /** With splitting axes removed */\n adjustedSpec: PColumnSpec;\n dataEntries: PartitionedDataInfoEntries<TreeNodeAccessor>;\n axisFilters: AxisFilterInfo[];\n};\n\n// Intermediate representation for columns NOT requiring splitting\ntype IntermediateDirectEntry = {\n type: \"direct\";\n originalColumn: PColumn<PColumnDataUniversal | undefined>;\n spec: PColumnSpec;\n /** The same as `spec` */\n adjustedSpec: PColumnSpec;\n};\n\n// Union type for intermediate processing\ntype IntermediateColumnEntry = IntermediateSplitEntry | IntermediateDirectEntry;\n\nfunction splitFiltersToExtraTrace(splitFilters?: AxisFilterInfo[]) {\n if (splitFilters === undefined) return undefined;\n return splitFilters.map((filter) => ({\n type: `split:${canonicalizeAxisId(filter.axisId)}`,\n label: filter.label,\n importance: 1_000_000, // High importance for split filters in labels\n }));\n}\n\nfunction splitFiltersToAxisFilter(splitFilters?: AxisFilterInfo[]): AxisFilterByIdx[] | undefined {\n if (!splitFilters) return undefined;\n return splitFilters.map((filter): AxisFilterByIdx => [filter.axisIdx, filter.value]);\n}\n\nfunction fallbackIdDeriver(originalId: PObjectId, axisFilters?: AxisFilterByIdx[]): PObjectId {\n if (!axisFilters || axisFilters.length === 0) return originalId;\n const filtersToCanonicalize = [...axisFilters].sort((a, b) => a[0] - b[0]);\n return canonicalize({ id: originalId, axisFilters: filtersToCanonicalize })! as PObjectId;\n}\n\n/** Checks if a selector object uses any anchor properties */\nfunction hasAnchors(selector: unknown): selector is AnchoredPColumnSelector {\n if (!selector || typeof selector !== \"object\") return false;\n const potentialAnchored = selector as Record<string, any>;\n const hasAnchorValues = (obj: unknown) =>\n obj &&\n typeof obj === \"object\" &&\n Object.values(obj).some((v: unknown) => typeof v === \"object\" && v !== null && \"anchor\" in v);\n const domainHasAnchors = hasAnchorValues(potentialAnchored[\"domain\"]);\n const contextDomainHasAnchors = hasAnchorValues(potentialAnchored[\"contextDomain\"]);\n const axesHaveAnchors =\n potentialAnchored[\"axes\"] &&\n Array.isArray(potentialAnchored[\"axes\"]) &&\n potentialAnchored[\"axes\"].some(\n (a: unknown) => typeof a === \"object\" && a !== null && \"anchor\" in a,\n );\n return (\n !!potentialAnchored[\"domainAnchor\"] ||\n !!potentialAnchored[\"contextDomainAnchor\"] ||\n domainHasAnchors ||\n contextDomainHasAnchors ||\n axesHaveAnchors\n );\n}\n\n/**\n * Derives the indices of axes marked for splitting based on the selector.\n * Throws an error if splitting is requested alongside `partialAxesMatch`.\n */\nfunction getSplitAxisIndices(\n selector: APColumnSelectorWithSplit | ((spec: PColumnSpec) => boolean),\n): number[] {\n if (typeof selector !== \"object\" || !(\"axes\" in selector) || selector.axes === undefined) {\n return []; // No axes specified or not an object selector, no splitting\n }\n\n const splitIndices = selector.axes\n .map((axis, index) =>\n typeof axis === \"object\" && \"split\" in axis && axis.split === true ? index : -1,\n )\n .filter((index) => index !== -1);\n\n if (splitIndices.length > 0 && selector.partialAxesMatch !== undefined) {\n throw new Error(\"Axis splitting is not supported when `partialAxesMatch` is defined.\");\n }\n\n splitIndices.sort((a, b) => a - b);\n return splitIndices;\n}\n\ntype UniversalPColumnOptsNoDeriver = {\n /** If provided, columns matching the provided selectors will be excluded from the result. */\n exclude?: AnchoredPColumnSelector | AnchoredPColumnSelector[];\n labelOps?: LabelDerivationOps;\n /** If true, incomplete data will cause the column to be skipped instead of returning undefined for the whole request. */\n dontWaitAllData?: boolean;\n /**\n * If true, the derived label will override the 'pl7.app/label' annotation\n * in the resulting PColumnSpec. It also forces `includeNativeLabel` in `labelOps` to true,\n * unless `labelOps.includeNativeLabel` is explicitly set to false.\n * Default value in getUniversalEntries is false, in getColumns it is true.\n */\n overrideLabelAnnotation?: boolean;\n /** If true, resulting columns will be enriched by other columns considering linker columns. Default is false. */\n enrichByLinkers?: boolean;\n};\n\ntype UniversalPColumnOpts = UniversalPColumnOptsNoDeriver & {\n anchorCtx: AnchoredIdDeriver;\n} & ResolveAnchorsOptions;\n\nexport class PColumnCollection {\n private readonly defaultProviderStore: PColumn<PColumnDataUniversal | undefined>[] = [];\n private readonly providers: ColumnProvider[] = [\n new ArrayColumnsProvider(this.defaultProviderStore),\n ];\n private readonly axisLabelProviders: AxisLabelProvider[] = [];\n\n constructor() {}\n\n public addColumnProvider(provider: ColumnProvider): this {\n this.providers.push(provider);\n return this;\n }\n\n public addAxisLabelProvider(provider: AxisLabelProvider): this {\n this.axisLabelProviders.push(provider);\n return this;\n }\n\n public addColumns(columns: PColumn<PColumnDataUniversal | undefined>[]): this {\n this.defaultProviderStore.push(...columns);\n return this;\n }\n\n public addColumn(column: PColumn<PColumnDataUniversal | undefined>): this {\n this.defaultProviderStore.push(column);\n return this;\n }\n\n /** Fetches labels for a given axis from the registered providers */\n private findLabels(axis: AxisId): Record<string | number, string> | undefined {\n for (const provider of this.axisLabelProviders) {\n const labels = provider.findLabels(axis);\n if (labels) return labels; // First provider wins\n }\n return undefined;\n }\n\n // Overload signatures updated to return PColumnEntry types\n public getUniversalEntries(\n predicateOrSelectors:\n | ((spec: PColumnSpec) => boolean)\n | APColumnSelectorWithSplit\n | APColumnSelectorWithSplit[],\n opts: UniversalPColumnOpts,\n ): PColumnEntryUniversal[] | undefined;\n public getUniversalEntries(\n predicateOrSelectors:\n | ((spec: PColumnSpec) => boolean)\n | PColumnSelectorWithSplit\n | PColumnSelectorWithSplit[],\n opts?: UniversalPColumnOptsNoDeriver,\n ): PColumnEntryWithLabel[] | undefined;\n public getUniversalEntries(\n predicateOrSelectors:\n | ((spec: PColumnSpec) => boolean)\n | APColumnSelectorWithSplit\n | APColumnSelectorWithSplit[],\n opts?: Optional<UniversalPColumnOpts, \"anchorCtx\">,\n ): (PColumnEntryWithLabel | PColumnEntryUniversal)[] | undefined {\n const {\n anchorCtx,\n labelOps: rawLabelOps,\n dontWaitAllData = false,\n overrideLabelAnnotation = false,\n exclude,\n enrichByLinkers = false,\n } = opts ?? {};\n\n const labelOps: LabelDerivationOps = {\n ...(overrideLabelAnnotation && rawLabelOps?.includeNativeLabel !== false\n ? { includeNativeLabel: true }\n : {}),\n ...rawLabelOps,\n };\n\n let excludePredicate: (spec: PColumnSpec) => boolean = () => false;\n if (exclude) {\n const excludePredicartes = (Array.isArray(exclude) ? exclude : [exclude]).map((selector) => {\n if (hasAnchors(selector)) {\n if (!anchorCtx)\n throw new Error(\n \"Anchored selectors in exclude require an AnchoredIdDeriver to be provided in options.\",\n );\n return legacyColumnSelectorsToPredicate(\n resolveAnchors(anchorCtx.anchors, selector, opts),\n );\n } else return legacyColumnSelectorsToPredicate(selector);\n });\n excludePredicate = (spec) => excludePredicartes.some((predicate) => predicate(spec));\n }\n\n const selectorsArray =\n typeof predicateOrSelectors === \"function\"\n ? [predicateOrSelectors]\n : Array.isArray(predicateOrSelectors)\n ? predicateOrSelectors\n : [predicateOrSelectors];\n\n const intermediateResults: IntermediateColumnEntry[] = [];\n const selectedNativeIds = new Set<NativePObjectId>();\n\n for (const rawSelector of selectorsArray) {\n const usesAnchors = hasAnchors(rawSelector);\n\n let currentSelector: PColumnSelectorWithSplit | ((spec: PColumnSpec) => boolean);\n if (usesAnchors) {\n if (!anchorCtx)\n throw new Error(\n \"Anchored selectors require an AnchoredIdDeriver to be provided in options.\",\n );\n currentSelector = resolveAnchors(\n anchorCtx.anchors,\n rawSelector as AnchoredPColumnSelector,\n opts,\n );\n } else\n currentSelector = rawSelector as\n | PColumnSelectorWithSplit\n | ((spec: PColumnSpec) => boolean);\n\n const selectedIds = new Set<PObjectId>();\n const selectedColumns: PColumn<PColumnDataUniversal | undefined>[] = [];\n for (const provider of this.providers) {\n const providerColumns = provider.selectColumns(currentSelector);\n const providerIds = new Set<PObjectId>();\n for (const col of providerColumns) {\n if (excludePredicate(col.spec)) continue;\n if (providerIds.has(col.id))\n throw new Error(\n `Duplicate column id ${col.id} in provider ${provider.constructor.name}`,\n );\n providerIds.add(col.id);\n // The same column offered by several providers is taken once, from the first of them.\n const nativeId = deriveNativeId(col.spec);\n if (selectedNativeIds.has(nativeId)) continue;\n if (selectedIds.has(col.id))\n throw new Error(\n `Column id ${col.id} in provider ${provider.constructor.name} is already taken by a different column of another provider`,\n );\n selectedIds.add(col.id);\n selectedNativeIds.add(nativeId);\n selectedColumns.push(col);\n }\n }\n\n if (selectedColumns.length === 0) continue;\n\n const splitAxisIdxs = getSplitAxisIndices(rawSelector);\n const needsSplitting = splitAxisIdxs.length > 0;\n\n for (const column of selectedColumns) {\n if (!isPColumnSpec(column.spec)) continue;\n\n const originalSpec = column.spec;\n\n if (needsSplitting) {\n if (isPColumnValues(column.data))\n throw new Error(\n `Splitting is not supported for PColumns with PColumnValues data format. Column id: ${column.id}`,\n );\n const dataEntries = convertOrParsePColumnData(column.data);\n\n if (!dataEntries) {\n if (dontWaitAllData) continue;\n return undefined;\n }\n\n if (!isPartitionedDataInfoEntries(dataEntries))\n throw new Error(\n `Splitting requires Partitioned DataInfoEntries, but parsing resulted in ${dataEntries.type} for column ${column.id}`,\n );\n\n const uniqueKeys = getUniquePartitionKeys(dataEntries);\n\n const maxSplitIdx = splitAxisIdxs[splitAxisIdxs.length - 1];\n if (maxSplitIdx >= dataEntries.partitionKeyLength)\n throw new Error(\n `Not enough partition keys (${dataEntries.partitionKeyLength}) for requested split axes (max index ${maxSplitIdx}) in column ${originalSpec.name}`,\n );\n\n const axesLabels: (Record<string | number, string> | undefined)[] = splitAxisIdxs.map(\n (idx) => this.findLabels(getAxisId(originalSpec.axesSpec[idx])),\n );\n\n const keyCombinations: (string | number)[][] = [];\n const generateCombinations = (currentCombo: (string | number)[], sAxisIdx: number) => {\n if (sAxisIdx >= splitAxisIdxs.length) {\n keyCombinations.push([...currentCombo]);\n if (keyCombinations.length > 10000)\n throw new Error(\"Too many key combinations, aborting.\");\n return;\n }\n const axisIdx = splitAxisIdxs[sAxisIdx];\n if (axisIdx >= uniqueKeys.length)\n throw new Error(\n `Axis index ${axisIdx} out of bounds for unique keys array (length ${uniqueKeys.length}) during split key generation for column ${column.id}`,\n );\n const axisValues = uniqueKeys[axisIdx];\n if (!axisValues || axisValues.length === 0) {\n keyCombinations.length = 0; // No combinations possible if one axis has no keys\n return;\n }\n for (const val of axisValues) {\n currentCombo.push(val);\n generateCombinations(currentCombo, sAxisIdx + 1);\n currentCombo.pop();\n }\n };\n\n generateCombinations([], 0);\n\n if (keyCombinations.length === 0) continue;\n\n const newAxesSpec = [...originalSpec.axesSpec];\n const splitAxisOriginalIdxs = splitAxisIdxs.map((idx) => idx); // Keep original indices for axisId lookup\n // Remove axes in reverse order to maintain correct indices during removal\n for (let i = splitAxisIdxs.length - 1; i >= 0; i--) {\n newAxesSpec.splice(splitAxisIdxs[i], 1);\n }\n const adjustedSpec = { ...originalSpec, axesSpec: newAxesSpec };\n\n for (const keyCombo of keyCombinations) {\n const splitFilters: AxisFilterInfo[] = keyCombo.map((value, sAxisIdx) => {\n const axisIdx = splitAxisOriginalIdxs[sAxisIdx]; // Use original index for lookup\n const axisId = getAxisId(originalSpec.axesSpec[axisIdx]);\n const axisLabelMap = axesLabels[sAxisIdx];\n const label = axisLabelMap?.[value] ?? String(value);\n return { axisIdx, axisId, value: value as AxisFilterValue, label };\n });\n\n intermediateResults.push({\n type: \"split\",\n originalColumn: column,\n spec: originalSpec,\n adjustedSpec,\n dataEntries,\n axisFilters: splitFilters,\n });\n }\n } else {\n intermediateResults.push({\n type: \"direct\",\n originalColumn: column,\n spec: originalSpec,\n adjustedSpec: originalSpec,\n });\n }\n }\n }\n\n if (intermediateResults.length === 0) return [];\n\n const labeledResults = deriveLabels(\n intermediateResults,\n (entry) => ({\n spec: entry.spec,\n extraTrace:\n entry.type === \"split\" ? splitFiltersToExtraTrace(entry.axisFilters) : undefined,\n }),\n labelOps,\n );\n\n const result: (PColumnEntryWithLabel | PColumnEntryUniversal)[] = [];\n\n for (const { value: entry, label } of labeledResults) {\n const { originalColumn, spec: originalSpec } = entry;\n\n const axisFilters = entry.type === \"split\" ? entry.axisFilters : undefined;\n const axisFiltersTuple = splitFiltersToAxisFilter(axisFilters);\n\n let finalId: SUniversalPColumnId | PObjectId;\n if (anchorCtx) finalId = anchorCtx.deriveS(originalSpec, axisFiltersTuple);\n else finalId = fallbackIdDeriver(originalColumn.id, axisFiltersTuple);\n\n let finalSpec = { ...entry.adjustedSpec };\n\n if (overrideLabelAnnotation) {\n finalSpec = {\n ...finalSpec,\n annotations: {\n ...finalSpec.annotations,\n [Annotation.Label]: label,\n } satisfies Annotation,\n };\n }\n\n result.push({\n id: finalId as PObjectId,\n spec: finalSpec,\n get data() {\n return entry.type === \"split\"\n ? entriesToDataInfo(filterDataInfoEntries(entry.dataEntries, axisFiltersTuple!))\n : entry.originalColumn.data;\n },\n label: label,\n });\n }\n\n const ids = new Set(result.map((entry) => entry.id));\n\n if (enrichByLinkers && anchorCtx) {\n const linkers = result.filter((entry) => isLinkerColumn(entry.spec));\n if (linkers.length === 0) {\n return result;\n }\n\n const anchorAxes = Object.values(anchorCtx.anchors).flatMap((anchor) => anchor.axesSpec);\n const linkerMap = LinkerMap.fromColumns(linkers.map(getColumnIdAndSpec));\n\n // loose way of matching\n function matchAxisIdFn(linkerKeyId: AxisId, sourceAxisId: AxisId): boolean {\n return matchAxisId(linkerKeyId, sourceAxisId) || matchAxisId(sourceAxisId, linkerKeyId);\n }\n // search all axes that can be reached by linkers from anchor axes; anchor axes are not in this list;\n const availableByLinkersAxes = linkerMap.getReachableByLinkersAxesFromAxes(\n anchorAxes,\n matchAxisIdFn,\n );\n\n // search all columns that includes at least one of additional axes;\n const availableByLinkersColumns = this.getUniversalEntries(\n (spec) =>\n !isLinkerColumn(spec) &&\n spec.axesSpec.some((columnAxisSpec) => {\n const columnAxisId = getAxisId(columnAxisSpec);\n return availableByLinkersAxes.some((axis) =>\n matchAxisIdFn(getAxisId(axis), columnAxisId),\n );\n }),\n { anchorCtx, labelOps, dontWaitAllData, overrideLabelAnnotation, exclude },\n );\n if (availableByLinkersColumns) {\n result.push(...availableByLinkersColumns.filter((entry) => !ids.has(entry.id)));\n }\n }\n\n return result;\n }\n\n public getColumns(\n predicateOrSelectors:\n | ((spec: PColumnSpec) => boolean)\n | APColumnSelectorWithSplit\n | APColumnSelectorWithSplit[],\n opts: UniversalPColumnOpts,\n ): PColumn<undefined | PColumnDataUniversal>[] | undefined;\n public getColumns(\n predicateOrSelectors:\n | ((spec: PColumnSpec) => boolean)\n | PColumnSelectorWithSplit\n | PColumnSelectorWithSplit[],\n opts?: UniversalPColumnOptsNoDeriver,\n ): PColumn<undefined | PColumnDataUniversal>[] | undefined;\n public getColumns(\n predicateOrSelectors:\n | ((spec: PColumnSpec) => boolean)\n | APColumnSelectorWithSplit\n | APColumnSelectorWithSplit[],\n opts?: Optional<UniversalPColumnOpts, \"anchorCtx\">,\n ): PColumn<undefined | PColumnDataUniversal>[] | undefined {\n const entries = this.getUniversalEntries(predicateOrSelectors, {\n overrideLabelAnnotation: true, // default for getColumns\n ...opts,\n } as UniversalPColumnOpts);\n if (!entries) return undefined;\n\n const columns: PColumn<undefined | PColumnDataUniversal>[] = [];\n for (const entry of entries) {\n const data = entry.data;\n if (!data) {\n if (opts?.dontWaitAllData) continue;\n return undefined;\n }\n columns.push({\n id: entry.id,\n spec: entry.spec,\n data,\n });\n }\n\n return columns;\n }\n}\n"],"mappings":";;;;;;;;AAyCA,SAAS,gBAAgB,OAAwC;CAC/D,IAAI,CAAC,MAAM,QAAQ,KAAK,GAAG,OAAO;CAClC,IAAI,MAAM,WAAW,GAAG,OAAO;CAC/B,MAAM,QAAQ,MAAM;CACpB,OAAO,OAAO,UAAU,YAAY,UAAU,QAAQ,SAAS,SAAS,SAAS;AACnF;;;;AAeA,IAAM,uBAAN,MAAqD;CACtB;CAA7B,YAAY,SAAuE;EAAtD,KAAA,UAAA;CAAuD;CAEpF,cACE,WAC6C;EAC7C,MAAM,YACJ,OAAO,cAAc,aAAa,aAAA,GAAYA,gCAAAA,iCAAAA,CAAiC,SAAS;EAE1F,OAAO,KAAK,QAAQ,QAAQ,WAC1B,UAAU,OAAO,IAAI,CACvB;CACF;AACF;AAqDA,SAAS,yBAAyB,cAAiC;CACjE,IAAI,iBAAiB,KAAA,GAAW,OAAO,KAAA;CACvC,OAAO,aAAa,KAAK,YAAY;EACnC,MA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AM,gBAAA,GAAeL,gCAAAA,UAAAA,CAAU,cAAc;IAC7C,OAAO,uBAAuB,MAAM,SAClC,eAAA,GAAcA,gCAAAA,UAAAA,CAAU,IAAI,GAAG,YAAY,CAC7C;GACF,CAAC,GACH;IAAE;IAAW;IAAU;IAAiB;IAAyB;GAAQ,CAC3E;GACA,IAAI,2BACF,OAAO,KAAK,GAAG,0BAA0B,QAAQ,UAAU,CAAC,IAAI,IAAI,MAAM,EAAE,CAAC,CAAC;EAElF;EAEA,OAAO;CACT;CAgBA,WACE,sBAIA,MACyD;EACzD,MAAM,UAAU,KAAK,oBAAoB,sBAAsB;GAC7D,yBAAyB;GACzB,GAAG;EACL,CAAyB;EACzB,IAAI,CAAC,SAAS,OAAO,KAAA;EAErB,MAAM,UAAuD,CAAC;EAC9D,KAAK,MAAM,SAAS,SAAS;GAC3B,MAAM,OAAO,MAAM;GACnB,IAAI,CAAC,MAAM;IACT,IAAI,MAAM,iBAAiB;IAC3B;GACF;GACA,QAAQ,KAAK;IACX,IAAI,MAAM;IACV,MAAM,MAAM;IACZ;GACF,CAAC;EACH;EAEA,OAAO;CACT;AACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"column_collection.d.ts","names":["LabelDerivationOps"],"sources":["../../../src/render/util/column_collection.ts"],"mappings":";;;;;iBAgDiB;EACf,cACE,aAAa,MAAM,2BAA2B,kBAAkB,oBAC/D,QAAQ;;iBAGI;EACf,WAAW,MAAM,SAAS;;;YAsBhB,iBAAiB,KAAK,QAAQ;EACxC;;;YAIU,iBAAiB,KAAK,iBAAiB;EACjD,IAAI;;;YAIM,wBAAwB,oBAAoB;EACtD;;;YAIU,wBAAwB;EAClC,IAAI;;KAwGD;;EAEH,UAAU,0BAA0B;EACpC,WAAWA;;EAEX;;;;;;;EAOA;;EAEA;;KAGG,uBAAuB;EAC1B,WAAW;IACT;qBAES;mBACM;mBACA;mBAGA;EAEjB;EAEO,kBAAkB,UAAU;EAK5B,qBAAqB,UAAU;EAK/B,WAAW,SAAS,QAAQ;EAK5B,UAAU,QAAQ,QAAQ;;UAMzB;EASD,oBACL,wBACM,MAAM,2BACR,4BACA,6BACJ,MAAM,uBACL;EACI,oBACL,wBACM,MAAM,2BACR,2BACA,4BACJ,OAAO,gCACN;
|
|
1
|
+
{"version":3,"file":"column_collection.d.ts","names":["LabelDerivationOps"],"sources":["../../../src/render/util/column_collection.ts"],"mappings":";;;;;iBAgDiB;EACf,cACE,aAAa,MAAM,2BAA2B,kBAAkB,oBAC/D,QAAQ;;iBAGI;EACf,WAAW,MAAM,SAAS;;;YAsBhB,iBAAiB,KAAK,QAAQ;EACxC;;;YAIU,iBAAiB,KAAK,iBAAiB;EACjD,IAAI;;;YAIM,wBAAwB,oBAAoB;EACtD;;;YAIU,wBAAwB;EAClC,IAAI;;KAwGD;;EAEH,UAAU,0BAA0B;EACpC,WAAWA;;EAEX;;;;;;;EAOA;;EAEA;;KAGG,uBAAuB;EAC1B,WAAW;IACT;qBAES;mBACM;mBACA;mBAGA;EAEjB;EAEO,kBAAkB,UAAU;EAK5B,qBAAqB,UAAU;EAK/B,WAAW,SAAS,QAAQ;EAK5B,UAAU,QAAQ,QAAQ;;UAMzB;EASD,oBACL,wBACM,MAAM,2BACR,4BACA,6BACJ,MAAM,uBACL;EACI,oBACL,wBACM,MAAM,2BACR,2BACA,4BACJ,OAAO,gCACN;EAgSI,WACL,wBACM,MAAM,2BACR,4BACA,6BACJ,MAAM,uBACL,oBAAoB;EAChB,WACL,wBACM,MAAM,2BACR,2BACA,4BACJ,OAAO,gCACN,oBAAoB"}
|
|
@@ -122,11 +122,14 @@ var PColumnCollection = class {
|
|
|
122
122
|
const selectedColumns = [];
|
|
123
123
|
for (const provider of this.providers) {
|
|
124
124
|
const providerColumns = provider.selectColumns(currentSelector);
|
|
125
|
+
const providerIds = /* @__PURE__ */ new Set();
|
|
125
126
|
for (const col of providerColumns) {
|
|
126
127
|
if (excludePredicate(col.spec)) continue;
|
|
127
|
-
if (
|
|
128
|
+
if (providerIds.has(col.id)) throw new Error(`Duplicate column id ${col.id} in provider ${provider.constructor.name}`);
|
|
129
|
+
providerIds.add(col.id);
|
|
128
130
|
const nativeId = deriveNativeId(col.spec);
|
|
129
131
|
if (selectedNativeIds.has(nativeId)) continue;
|
|
132
|
+
if (selectedIds.has(col.id)) throw new Error(`Column id ${col.id} in provider ${provider.constructor.name} is already taken by a different column of another provider`);
|
|
130
133
|
selectedIds.add(col.id);
|
|
131
134
|
selectedNativeIds.add(nativeId);
|
|
132
135
|
selectedColumns.push(col);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"column_collection.js","names":[],"sources":["../../../src/render/util/column_collection.ts"],"sourcesContent":["import type {\n AnchoredIdDeriver,\n AnchoredPColumnSelector,\n AxisFilterByIdx,\n AxisFilterValue,\n AxisId,\n NativePObjectId,\n PartitionedDataInfoEntries,\n PColumn,\n PColumnSelector,\n PColumnSpec,\n PColumnValues,\n PObjectId,\n ResolveAnchorsOptions,\n SUniversalPColumnId,\n} from \"@milaboratories/pl-model-common\";\nimport {\n Annotation,\n canonicalizeAxisId,\n deriveNativeId,\n entriesToDataInfo,\n getAxisId,\n getColumnIdAndSpec,\n isLinkerColumn,\n isPartitionedDataInfoEntries,\n isPColumnSpec,\n legacyColumnSelectorsToPredicate,\n LinkerMap,\n matchAxisId,\n resolveAnchors,\n} from \"@milaboratories/pl-model-common\";\nimport canonicalize from \"canonicalize\";\nimport type { Optional } from \"utility-types\";\nimport type { TreeNodeAccessor } from \"../accessor\";\nimport type { PColumnDataUniversal } from \"../internal\";\nimport { filterDataInfoEntries } from \"./axis_filtering\";\nimport type { LabelDerivationOps } from \"./label\";\nimport { deriveLabels } from \"./label\";\nimport { convertOrParsePColumnData, getUniquePartitionKeys } from \"./pcolumn_data\";\nimport type { APColumnSelectorWithSplit, PColumnSelectorWithSplit } from \"./split_selectors\";\n\nfunction isPColumnValues(value: unknown): value is PColumnValues {\n if (!Array.isArray(value)) return false;\n if (value.length === 0) return true;\n const first = value[0];\n return typeof first === \"object\" && first !== null && \"key\" in first && \"val\" in first;\n}\n\nexport interface ColumnProvider {\n selectColumns(\n selectors: ((spec: PColumnSpec) => boolean) | PColumnSelector | PColumnSelector[],\n ): PColumn<PColumnDataUniversal | undefined>[];\n}\n\nexport interface AxisLabelProvider {\n findLabels(axis: AxisId): Record<string | number, string> | undefined;\n}\n\n/**\n * A simple implementation of {@link ColumnProvider} backed by a pre-defined array of columns.\n */\nclass ArrayColumnsProvider implements ColumnProvider {\n constructor(private readonly columns: PColumn<PColumnDataUniversal | undefined>[]) {}\n\n selectColumns(\n selectors: ((spec: PColumnSpec) => boolean) | PColumnSelector | PColumnSelector[],\n ): PColumn<PColumnDataUniversal | undefined>[] {\n const predicate =\n typeof selectors === \"function\" ? selectors : legacyColumnSelectorsToPredicate(selectors);\n // Filter based on spec, ignoring data type for now\n return this.columns.filter((column): column is PColumn<PColumnDataUniversal | undefined> =>\n predicate(column.spec),\n );\n }\n}\n\n/** Lazy calculates the data, returns undefined if data is not ready. */\nexport type PColumnWithLabel<T> = PColumn<T> & {\n label: string;\n};\n\n/** Universal column is a column that uses a universal column id, and always have label. */\nexport type PColumnUniversal<T> = PColumnWithLabel<T> & {\n id: SUniversalPColumnId;\n};\n\n/** @deprecated Use PColumnWithLabel instead. */\nexport type PColumnEntryWithLabel = PColumn<undefined | PColumnDataUniversal> & {\n label: string;\n};\n\n/** @deprecated Use PColumnUniversal instead. */\nexport type PColumnEntryUniversal = PColumnEntryWithLabel & {\n id: SUniversalPColumnId;\n};\n\n// Helper types similar to those in api.ts\ntype AxisFilterInfo = {\n axisIdx: number;\n axisId: AxisId;\n value: AxisFilterValue;\n label: string;\n};\n\n// Intermediate representation for columns requiring splitting\ntype IntermediateSplitEntry = {\n type: \"split\";\n originalColumn: PColumn<PColumnDataUniversal | undefined>;\n spec: PColumnSpec;\n /** With splitting axes removed */\n adjustedSpec: PColumnSpec;\n dataEntries: PartitionedDataInfoEntries<TreeNodeAccessor>;\n axisFilters: AxisFilterInfo[];\n};\n\n// Intermediate representation for columns NOT requiring splitting\ntype IntermediateDirectEntry = {\n type: \"direct\";\n originalColumn: PColumn<PColumnDataUniversal | undefined>;\n spec: PColumnSpec;\n /** The same as `spec` */\n adjustedSpec: PColumnSpec;\n};\n\n// Union type for intermediate processing\ntype IntermediateColumnEntry = IntermediateSplitEntry | IntermediateDirectEntry;\n\nfunction splitFiltersToExtraTrace(splitFilters?: AxisFilterInfo[]) {\n if (splitFilters === undefined) return undefined;\n return splitFilters.map((filter) => ({\n type: `split:${canonicalizeAxisId(filter.axisId)}`,\n label: filter.label,\n importance: 1_000_000, // High importance for split filters in labels\n }));\n}\n\nfunction splitFiltersToAxisFilter(splitFilters?: AxisFilterInfo[]): AxisFilterByIdx[] | undefined {\n if (!splitFilters) return undefined;\n return splitFilters.map((filter): AxisFilterByIdx => [filter.axisIdx, filter.value]);\n}\n\nfunction fallbackIdDeriver(originalId: PObjectId, axisFilters?: AxisFilterByIdx[]): PObjectId {\n if (!axisFilters || axisFilters.length === 0) return originalId;\n const filtersToCanonicalize = [...axisFilters].sort((a, b) => a[0] - b[0]);\n return canonicalize({ id: originalId, axisFilters: filtersToCanonicalize })! as PObjectId;\n}\n\n/** Checks if a selector object uses any anchor properties */\nfunction hasAnchors(selector: unknown): selector is AnchoredPColumnSelector {\n if (!selector || typeof selector !== \"object\") return false;\n const potentialAnchored = selector as Record<string, any>;\n const hasAnchorValues = (obj: unknown) =>\n obj &&\n typeof obj === \"object\" &&\n Object.values(obj).some((v: unknown) => typeof v === \"object\" && v !== null && \"anchor\" in v);\n const domainHasAnchors = hasAnchorValues(potentialAnchored[\"domain\"]);\n const contextDomainHasAnchors = hasAnchorValues(potentialAnchored[\"contextDomain\"]);\n const axesHaveAnchors =\n potentialAnchored[\"axes\"] &&\n Array.isArray(potentialAnchored[\"axes\"]) &&\n potentialAnchored[\"axes\"].some(\n (a: unknown) => typeof a === \"object\" && a !== null && \"anchor\" in a,\n );\n return (\n !!potentialAnchored[\"domainAnchor\"] ||\n !!potentialAnchored[\"contextDomainAnchor\"] ||\n domainHasAnchors ||\n contextDomainHasAnchors ||\n axesHaveAnchors\n );\n}\n\n/**\n * Derives the indices of axes marked for splitting based on the selector.\n * Throws an error if splitting is requested alongside `partialAxesMatch`.\n */\nfunction getSplitAxisIndices(\n selector: APColumnSelectorWithSplit | ((spec: PColumnSpec) => boolean),\n): number[] {\n if (typeof selector !== \"object\" || !(\"axes\" in selector) || selector.axes === undefined) {\n return []; // No axes specified or not an object selector, no splitting\n }\n\n const splitIndices = selector.axes\n .map((axis, index) =>\n typeof axis === \"object\" && \"split\" in axis && axis.split === true ? index : -1,\n )\n .filter((index) => index !== -1);\n\n if (splitIndices.length > 0 && selector.partialAxesMatch !== undefined) {\n throw new Error(\"Axis splitting is not supported when `partialAxesMatch` is defined.\");\n }\n\n splitIndices.sort((a, b) => a - b);\n return splitIndices;\n}\n\ntype UniversalPColumnOptsNoDeriver = {\n /** If provided, columns matching the provided selectors will be excluded from the result. */\n exclude?: AnchoredPColumnSelector | AnchoredPColumnSelector[];\n labelOps?: LabelDerivationOps;\n /** If true, incomplete data will cause the column to be skipped instead of returning undefined for the whole request. */\n dontWaitAllData?: boolean;\n /**\n * If true, the derived label will override the 'pl7.app/label' annotation\n * in the resulting PColumnSpec. It also forces `includeNativeLabel` in `labelOps` to true,\n * unless `labelOps.includeNativeLabel` is explicitly set to false.\n * Default value in getUniversalEntries is false, in getColumns it is true.\n */\n overrideLabelAnnotation?: boolean;\n /** If true, resulting columns will be enriched by other columns considering linker columns. Default is false. */\n enrichByLinkers?: boolean;\n};\n\ntype UniversalPColumnOpts = UniversalPColumnOptsNoDeriver & {\n anchorCtx: AnchoredIdDeriver;\n} & ResolveAnchorsOptions;\n\nexport class PColumnCollection {\n private readonly defaultProviderStore: PColumn<PColumnDataUniversal | undefined>[] = [];\n private readonly providers: ColumnProvider[] = [\n new ArrayColumnsProvider(this.defaultProviderStore),\n ];\n private readonly axisLabelProviders: AxisLabelProvider[] = [];\n\n constructor() {}\n\n public addColumnProvider(provider: ColumnProvider): this {\n this.providers.push(provider);\n return this;\n }\n\n public addAxisLabelProvider(provider: AxisLabelProvider): this {\n this.axisLabelProviders.push(provider);\n return this;\n }\n\n public addColumns(columns: PColumn<PColumnDataUniversal | undefined>[]): this {\n this.defaultProviderStore.push(...columns);\n return this;\n }\n\n public addColumn(column: PColumn<PColumnDataUniversal | undefined>): this {\n this.defaultProviderStore.push(column);\n return this;\n }\n\n /** Fetches labels for a given axis from the registered providers */\n private findLabels(axis: AxisId): Record<string | number, string> | undefined {\n for (const provider of this.axisLabelProviders) {\n const labels = provider.findLabels(axis);\n if (labels) return labels; // First provider wins\n }\n return undefined;\n }\n\n // Overload signatures updated to return PColumnEntry types\n public getUniversalEntries(\n predicateOrSelectors:\n | ((spec: PColumnSpec) => boolean)\n | APColumnSelectorWithSplit\n | APColumnSelectorWithSplit[],\n opts: UniversalPColumnOpts,\n ): PColumnEntryUniversal[] | undefined;\n public getUniversalEntries(\n predicateOrSelectors:\n | ((spec: PColumnSpec) => boolean)\n | PColumnSelectorWithSplit\n | PColumnSelectorWithSplit[],\n opts?: UniversalPColumnOptsNoDeriver,\n ): PColumnEntryWithLabel[] | undefined;\n public getUniversalEntries(\n predicateOrSelectors:\n | ((spec: PColumnSpec) => boolean)\n | APColumnSelectorWithSplit\n | APColumnSelectorWithSplit[],\n opts?: Optional<UniversalPColumnOpts, \"anchorCtx\">,\n ): (PColumnEntryWithLabel | PColumnEntryUniversal)[] | undefined {\n const {\n anchorCtx,\n labelOps: rawLabelOps,\n dontWaitAllData = false,\n overrideLabelAnnotation = false,\n exclude,\n enrichByLinkers = false,\n } = opts ?? {};\n\n const labelOps: LabelDerivationOps = {\n ...(overrideLabelAnnotation && rawLabelOps?.includeNativeLabel !== false\n ? { includeNativeLabel: true }\n : {}),\n ...rawLabelOps,\n };\n\n let excludePredicate: (spec: PColumnSpec) => boolean = () => false;\n if (exclude) {\n const excludePredicartes = (Array.isArray(exclude) ? exclude : [exclude]).map((selector) => {\n if (hasAnchors(selector)) {\n if (!anchorCtx)\n throw new Error(\n \"Anchored selectors in exclude require an AnchoredIdDeriver to be provided in options.\",\n );\n return legacyColumnSelectorsToPredicate(\n resolveAnchors(anchorCtx.anchors, selector, opts),\n );\n } else return legacyColumnSelectorsToPredicate(selector);\n });\n excludePredicate = (spec) => excludePredicartes.some((predicate) => predicate(spec));\n }\n\n const selectorsArray =\n typeof predicateOrSelectors === \"function\"\n ? [predicateOrSelectors]\n : Array.isArray(predicateOrSelectors)\n ? predicateOrSelectors\n : [predicateOrSelectors];\n\n const intermediateResults: IntermediateColumnEntry[] = [];\n const selectedNativeIds = new Set<NativePObjectId>();\n\n for (const rawSelector of selectorsArray) {\n const usesAnchors = hasAnchors(rawSelector);\n\n let currentSelector: PColumnSelectorWithSplit | ((spec: PColumnSpec) => boolean);\n if (usesAnchors) {\n if (!anchorCtx)\n throw new Error(\n \"Anchored selectors require an AnchoredIdDeriver to be provided in options.\",\n );\n currentSelector = resolveAnchors(\n anchorCtx.anchors,\n rawSelector as AnchoredPColumnSelector,\n opts,\n );\n } else\n currentSelector = rawSelector as\n | PColumnSelectorWithSplit\n | ((spec: PColumnSpec) => boolean);\n\n const selectedIds = new Set<PObjectId>();\n const selectedColumns: PColumn<PColumnDataUniversal | undefined>[] = [];\n for (const provider of this.providers) {\n const providerColumns = provider.selectColumns(currentSelector);\n for (const col of providerColumns) {\n if (excludePredicate(col.spec)) continue;\n if (selectedIds.has(col.id))\n throw new Error(\n `Duplicate column id ${col.id} in provider ${provider.constructor.name}`,\n );\n const nativeId = deriveNativeId(col.spec);\n if (selectedNativeIds.has(nativeId)) continue;\n selectedIds.add(col.id);\n selectedNativeIds.add(nativeId);\n selectedColumns.push(col);\n }\n }\n\n if (selectedColumns.length === 0) continue;\n\n const splitAxisIdxs = getSplitAxisIndices(rawSelector);\n const needsSplitting = splitAxisIdxs.length > 0;\n\n for (const column of selectedColumns) {\n if (!isPColumnSpec(column.spec)) continue;\n\n const originalSpec = column.spec;\n\n if (needsSplitting) {\n if (isPColumnValues(column.data))\n throw new Error(\n `Splitting is not supported for PColumns with PColumnValues data format. Column id: ${column.id}`,\n );\n const dataEntries = convertOrParsePColumnData(column.data);\n\n if (!dataEntries) {\n if (dontWaitAllData) continue;\n return undefined;\n }\n\n if (!isPartitionedDataInfoEntries(dataEntries))\n throw new Error(\n `Splitting requires Partitioned DataInfoEntries, but parsing resulted in ${dataEntries.type} for column ${column.id}`,\n );\n\n const uniqueKeys = getUniquePartitionKeys(dataEntries);\n\n const maxSplitIdx = splitAxisIdxs[splitAxisIdxs.length - 1];\n if (maxSplitIdx >= dataEntries.partitionKeyLength)\n throw new Error(\n `Not enough partition keys (${dataEntries.partitionKeyLength}) for requested split axes (max index ${maxSplitIdx}) in column ${originalSpec.name}`,\n );\n\n const axesLabels: (Record<string | number, string> | undefined)[] = splitAxisIdxs.map(\n (idx) => this.findLabels(getAxisId(originalSpec.axesSpec[idx])),\n );\n\n const keyCombinations: (string | number)[][] = [];\n const generateCombinations = (currentCombo: (string | number)[], sAxisIdx: number) => {\n if (sAxisIdx >= splitAxisIdxs.length) {\n keyCombinations.push([...currentCombo]);\n if (keyCombinations.length > 10000)\n throw new Error(\"Too many key combinations, aborting.\");\n return;\n }\n const axisIdx = splitAxisIdxs[sAxisIdx];\n if (axisIdx >= uniqueKeys.length)\n throw new Error(\n `Axis index ${axisIdx} out of bounds for unique keys array (length ${uniqueKeys.length}) during split key generation for column ${column.id}`,\n );\n const axisValues = uniqueKeys[axisIdx];\n if (!axisValues || axisValues.length === 0) {\n keyCombinations.length = 0; // No combinations possible if one axis has no keys\n return;\n }\n for (const val of axisValues) {\n currentCombo.push(val);\n generateCombinations(currentCombo, sAxisIdx + 1);\n currentCombo.pop();\n }\n };\n\n generateCombinations([], 0);\n\n if (keyCombinations.length === 0) continue;\n\n const newAxesSpec = [...originalSpec.axesSpec];\n const splitAxisOriginalIdxs = splitAxisIdxs.map((idx) => idx); // Keep original indices for axisId lookup\n // Remove axes in reverse order to maintain correct indices during removal\n for (let i = splitAxisIdxs.length - 1; i >= 0; i--) {\n newAxesSpec.splice(splitAxisIdxs[i], 1);\n }\n const adjustedSpec = { ...originalSpec, axesSpec: newAxesSpec };\n\n for (const keyCombo of keyCombinations) {\n const splitFilters: AxisFilterInfo[] = keyCombo.map((value, sAxisIdx) => {\n const axisIdx = splitAxisOriginalIdxs[sAxisIdx]; // Use original index for lookup\n const axisId = getAxisId(originalSpec.axesSpec[axisIdx]);\n const axisLabelMap = axesLabels[sAxisIdx];\n const label = axisLabelMap?.[value] ?? String(value);\n return { axisIdx, axisId, value: value as AxisFilterValue, label };\n });\n\n intermediateResults.push({\n type: \"split\",\n originalColumn: column,\n spec: originalSpec,\n adjustedSpec,\n dataEntries,\n axisFilters: splitFilters,\n });\n }\n } else {\n intermediateResults.push({\n type: \"direct\",\n originalColumn: column,\n spec: originalSpec,\n adjustedSpec: originalSpec,\n });\n }\n }\n }\n\n if (intermediateResults.length === 0) return [];\n\n const labeledResults = deriveLabels(\n intermediateResults,\n (entry) => ({\n spec: entry.spec,\n extraTrace:\n entry.type === \"split\" ? splitFiltersToExtraTrace(entry.axisFilters) : undefined,\n }),\n labelOps,\n );\n\n const result: (PColumnEntryWithLabel | PColumnEntryUniversal)[] = [];\n\n for (const { value: entry, label } of labeledResults) {\n const { originalColumn, spec: originalSpec } = entry;\n\n const axisFilters = entry.type === \"split\" ? entry.axisFilters : undefined;\n const axisFiltersTuple = splitFiltersToAxisFilter(axisFilters);\n\n let finalId: SUniversalPColumnId | PObjectId;\n if (anchorCtx) finalId = anchorCtx.deriveS(originalSpec, axisFiltersTuple);\n else finalId = fallbackIdDeriver(originalColumn.id, axisFiltersTuple);\n\n let finalSpec = { ...entry.adjustedSpec };\n\n if (overrideLabelAnnotation) {\n finalSpec = {\n ...finalSpec,\n annotations: {\n ...finalSpec.annotations,\n [Annotation.Label]: label,\n } satisfies Annotation,\n };\n }\n\n result.push({\n id: finalId as PObjectId,\n spec: finalSpec,\n get data() {\n return entry.type === \"split\"\n ? entriesToDataInfo(filterDataInfoEntries(entry.dataEntries, axisFiltersTuple!))\n : entry.originalColumn.data;\n },\n label: label,\n });\n }\n\n const ids = new Set(result.map((entry) => entry.id));\n\n if (enrichByLinkers && anchorCtx) {\n const linkers = result.filter((entry) => isLinkerColumn(entry.spec));\n if (linkers.length === 0) {\n return result;\n }\n\n const anchorAxes = Object.values(anchorCtx.anchors).flatMap((anchor) => anchor.axesSpec);\n const linkerMap = LinkerMap.fromColumns(linkers.map(getColumnIdAndSpec));\n\n // loose way of matching\n function matchAxisIdFn(linkerKeyId: AxisId, sourceAxisId: AxisId): boolean {\n return matchAxisId(linkerKeyId, sourceAxisId) || matchAxisId(sourceAxisId, linkerKeyId);\n }\n // search all axes that can be reached by linkers from anchor axes; anchor axes are not in this list;\n const availableByLinkersAxes = linkerMap.getReachableByLinkersAxesFromAxes(\n anchorAxes,\n matchAxisIdFn,\n );\n\n // search all columns that includes at least one of additional axes;\n const availableByLinkersColumns = this.getUniversalEntries(\n (spec) =>\n !isLinkerColumn(spec) &&\n spec.axesSpec.some((columnAxisSpec) => {\n const columnAxisId = getAxisId(columnAxisSpec);\n return availableByLinkersAxes.some((axis) =>\n matchAxisIdFn(getAxisId(axis), columnAxisId),\n );\n }),\n { anchorCtx, labelOps, dontWaitAllData, overrideLabelAnnotation, exclude },\n );\n if (availableByLinkersColumns) {\n result.push(...availableByLinkersColumns.filter((entry) => !ids.has(entry.id)));\n }\n }\n\n return result;\n }\n\n public getColumns(\n predicateOrSelectors:\n | ((spec: PColumnSpec) => boolean)\n | APColumnSelectorWithSplit\n | APColumnSelectorWithSplit[],\n opts: UniversalPColumnOpts,\n ): PColumn<undefined | PColumnDataUniversal>[] | undefined;\n public getColumns(\n predicateOrSelectors:\n | ((spec: PColumnSpec) => boolean)\n | PColumnSelectorWithSplit\n | PColumnSelectorWithSplit[],\n opts?: UniversalPColumnOptsNoDeriver,\n ): PColumn<undefined | PColumnDataUniversal>[] | undefined;\n public getColumns(\n predicateOrSelectors:\n | ((spec: PColumnSpec) => boolean)\n | APColumnSelectorWithSplit\n | APColumnSelectorWithSplit[],\n opts?: Optional<UniversalPColumnOpts, \"anchorCtx\">,\n ): PColumn<undefined | PColumnDataUniversal>[] | undefined {\n const entries = this.getUniversalEntries(predicateOrSelectors, {\n overrideLabelAnnotation: true, // default for getColumns\n ...opts,\n } as UniversalPColumnOpts);\n if (!entries) return undefined;\n\n const columns: PColumn<undefined | PColumnDataUniversal>[] = [];\n for (const entry of entries) {\n const data = entry.data;\n if (!data) {\n if (opts?.dontWaitAllData) continue;\n return undefined;\n }\n columns.push({\n id: entry.id,\n spec: entry.spec,\n data,\n });\n }\n\n return columns;\n }\n}\n"],"mappings":";;;;;;AAyCA,SAAS,gBAAgB,OAAwC;CAC/D,IAAI,CAAC,MAAM,QAAQ,KAAK,GAAG,OAAO;CAClC,IAAI,MAAM,WAAW,GAAG,OAAO;CAC/B,MAAM,QAAQ,MAAM;CACpB,OAAO,OAAO,UAAU,YAAY,UAAU,QAAQ,SAAS,SAAS,SAAS;AACnF;;;;AAeA,IAAM,uBAAN,MAAqD;CACtB;CAA7B,YAAY,SAAuE;EAAtD,KAAA,UAAA;CAAuD;CAEpF,cACE,WAC6C;EAC7C,MAAM,YACJ,OAAO,cAAc,aAAa,YAAY,iCAAiC,SAAS;EAE1F,OAAO,KAAK,QAAQ,QAAQ,WAC1B,UAAU,OAAO,IAAI,CACvB;CACF;AACF;AAqDA,SAAS,yBAAyB,cAAiC;CACjE,IAAI,iBAAiB,KAAA,GAAW,OAAO,KAAA;CACvC,OAAO,aAAa,KAAK,YAAY;EACnC,MAAM,SAAS,mBAAmB,OAAO,MAAM;EAC/C,OAAO,OAAO;EACd,YAAY;CACd,EAAE;AACJ;AAEA,SAAS,yBAAyB,cAAgE;CAChG,IAAI,CAAC,cAAc,OAAO,KAAA;CAC1B,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IAAI,mBAAmB,WAAW;GAChC,MAAM,UAAU,OAAO,QAAQ,UAAU,eAAe,MAAM,IAAI,CAAC;GACnE,IAAI,QAAQ,WAAW,GACrB,OAAO;GAGT,MAAM,aAAa,OAAO,OAAO,UAAU,OAAO,CAAC,CAAC,SAAS,WAAW,OAAO,QAAQ;GACvF,MAAM,YAAY,UAAU,YAAY,QAAQ,IAAI,kBAAkB,CAAC;GAGvE,SAAS,cAAc,aAAqB,cAA+B;IACzE,OAAO,YAAY,aAAa,YAAY,KAAK,YAAY,cAAc,WAAW;GACxF;GAEA,MAAM,yBAAyB,UAAU,kCACvC,YACA,aACF;GAGA,MAAM,4BAA4B,KAAK,qBACpC,SACC,CAAC,eAAe,IAAI,KACpB,KAAK,SAAS,MAAM,mBAAmB;IACrC,MAAM,eAAe,UAAU,cAAc;IAC7C,OAAO,uBAAuB,MAAM,SAClC,cAAc,UAAU,IAAI,GAAG,YAAY,CAC7C;GACF,CAAC,GACH;IAAE;IAAW;IAAU;IAAiB;IAAyB;GAAQ,CAC3E;GACA,IAAI,2BACF,OAAO,KAAK,GAAG,0BAA0B,QAAQ,UAAU,CAAC,IAAI,IAAI,MAAM,EAAE,CAAC,CAAC;EAElF;EAEA,OAAO;CACT;CAgBA,WACE,sBAIA,MACyD;EACzD,MAAM,UAAU,KAAK,oBAAoB,sBAAsB;GAC7D,yBAAyB;GACzB,GAAG;EACL,CAAyB;EACzB,IAAI,CAAC,SAAS,OAAO,KAAA;EAErB,MAAM,UAAuD,CAAC;EAC9D,KAAK,MAAM,SAAS,SAAS;GAC3B,MAAM,OAAO,MAAM;GACnB,IAAI,CAAC,MAAM;IACT,IAAI,MAAM,iBAAiB;IAC3B;GACF;GACA,QAAQ,KAAK;IACX,IAAI,MAAM;IACV,MAAM,MAAM;IACZ;GACF,CAAC;EACH;EAEA,OAAO;CACT;AACF"}
|
|
1
|
+
{"version":3,"file":"column_collection.js","names":[],"sources":["../../../src/render/util/column_collection.ts"],"sourcesContent":["import type {\n AnchoredIdDeriver,\n AnchoredPColumnSelector,\n AxisFilterByIdx,\n AxisFilterValue,\n AxisId,\n NativePObjectId,\n PartitionedDataInfoEntries,\n PColumn,\n PColumnSelector,\n PColumnSpec,\n PColumnValues,\n PObjectId,\n ResolveAnchorsOptions,\n SUniversalPColumnId,\n} from \"@milaboratories/pl-model-common\";\nimport {\n Annotation,\n canonicalizeAxisId,\n deriveNativeId,\n entriesToDataInfo,\n getAxisId,\n getColumnIdAndSpec,\n isLinkerColumn,\n isPartitionedDataInfoEntries,\n isPColumnSpec,\n legacyColumnSelectorsToPredicate,\n LinkerMap,\n matchAxisId,\n resolveAnchors,\n} from \"@milaboratories/pl-model-common\";\nimport canonicalize from \"canonicalize\";\nimport type { Optional } from \"utility-types\";\nimport type { TreeNodeAccessor } from \"../accessor\";\nimport type { PColumnDataUniversal } from \"../internal\";\nimport { filterDataInfoEntries } from \"./axis_filtering\";\nimport type { LabelDerivationOps } from \"./label\";\nimport { deriveLabels } from \"./label\";\nimport { convertOrParsePColumnData, getUniquePartitionKeys } from \"./pcolumn_data\";\nimport type { APColumnSelectorWithSplit, PColumnSelectorWithSplit } from \"./split_selectors\";\n\nfunction isPColumnValues(value: unknown): value is PColumnValues {\n if (!Array.isArray(value)) return false;\n if (value.length === 0) return true;\n const first = value[0];\n return typeof first === \"object\" && first !== null && \"key\" in first && \"val\" in first;\n}\n\nexport interface ColumnProvider {\n selectColumns(\n selectors: ((spec: PColumnSpec) => boolean) | PColumnSelector | PColumnSelector[],\n ): PColumn<PColumnDataUniversal | undefined>[];\n}\n\nexport interface AxisLabelProvider {\n findLabels(axis: AxisId): Record<string | number, string> | undefined;\n}\n\n/**\n * A simple implementation of {@link ColumnProvider} backed by a pre-defined array of columns.\n */\nclass ArrayColumnsProvider implements ColumnProvider {\n constructor(private readonly columns: PColumn<PColumnDataUniversal | undefined>[]) {}\n\n selectColumns(\n selectors: ((spec: PColumnSpec) => boolean) | PColumnSelector | PColumnSelector[],\n ): PColumn<PColumnDataUniversal | undefined>[] {\n const predicate =\n typeof selectors === \"function\" ? selectors : legacyColumnSelectorsToPredicate(selectors);\n // Filter based on spec, ignoring data type for now\n return this.columns.filter((column): column is PColumn<PColumnDataUniversal | undefined> =>\n predicate(column.spec),\n );\n }\n}\n\n/** Lazy calculates the data, returns undefined if data is not ready. */\nexport type PColumnWithLabel<T> = PColumn<T> & {\n label: string;\n};\n\n/** Universal column is a column that uses a universal column id, and always have label. */\nexport type PColumnUniversal<T> = PColumnWithLabel<T> & {\n id: SUniversalPColumnId;\n};\n\n/** @deprecated Use PColumnWithLabel instead. */\nexport type PColumnEntryWithLabel = PColumn<undefined | PColumnDataUniversal> & {\n label: string;\n};\n\n/** @deprecated Use PColumnUniversal instead. */\nexport type PColumnEntryUniversal = PColumnEntryWithLabel & {\n id: SUniversalPColumnId;\n};\n\n// Helper types similar to those in api.ts\ntype AxisFilterInfo = {\n axisIdx: number;\n axisId: AxisId;\n value: AxisFilterValue;\n label: string;\n};\n\n// Intermediate representation for columns requiring splitting\ntype IntermediateSplitEntry = {\n type: \"split\";\n originalColumn: PColumn<PColumnDataUniversal | undefined>;\n spec: PColumnSpec;\n /** With splitting axes removed */\n adjustedSpec: PColumnSpec;\n dataEntries: PartitionedDataInfoEntries<TreeNodeAccessor>;\n axisFilters: AxisFilterInfo[];\n};\n\n// Intermediate representation for columns NOT requiring splitting\ntype IntermediateDirectEntry = {\n type: \"direct\";\n originalColumn: PColumn<PColumnDataUniversal | undefined>;\n spec: PColumnSpec;\n /** The same as `spec` */\n adjustedSpec: PColumnSpec;\n};\n\n// Union type for intermediate processing\ntype IntermediateColumnEntry = IntermediateSplitEntry | IntermediateDirectEntry;\n\nfunction splitFiltersToExtraTrace(splitFilters?: AxisFilterInfo[]) {\n if (splitFilters === undefined) return undefined;\n return splitFilters.map((filter) => ({\n type: `split:${canonicalizeAxisId(filter.axisId)}`,\n label: filter.label,\n importance: 1_000_000, // High importance for split filters in labels\n }));\n}\n\nfunction splitFiltersToAxisFilter(splitFilters?: AxisFilterInfo[]): AxisFilterByIdx[] | undefined {\n if (!splitFilters) return undefined;\n return splitFilters.map((filter): AxisFilterByIdx => [filter.axisIdx, filter.value]);\n}\n\nfunction fallbackIdDeriver(originalId: PObjectId, axisFilters?: AxisFilterByIdx[]): PObjectId {\n if (!axisFilters || axisFilters.length === 0) return originalId;\n const filtersToCanonicalize = [...axisFilters].sort((a, b) => a[0] - b[0]);\n return canonicalize({ id: originalId, axisFilters: filtersToCanonicalize })! as PObjectId;\n}\n\n/** Checks if a selector object uses any anchor properties */\nfunction hasAnchors(selector: unknown): selector is AnchoredPColumnSelector {\n if (!selector || typeof selector !== \"object\") return false;\n const potentialAnchored = selector as Record<string, any>;\n const hasAnchorValues = (obj: unknown) =>\n obj &&\n typeof obj === \"object\" &&\n Object.values(obj).some((v: unknown) => typeof v === \"object\" && v !== null && \"anchor\" in v);\n const domainHasAnchors = hasAnchorValues(potentialAnchored[\"domain\"]);\n const contextDomainHasAnchors = hasAnchorValues(potentialAnchored[\"contextDomain\"]);\n const axesHaveAnchors =\n potentialAnchored[\"axes\"] &&\n Array.isArray(potentialAnchored[\"axes\"]) &&\n potentialAnchored[\"axes\"].some(\n (a: unknown) => typeof a === \"object\" && a !== null && \"anchor\" in a,\n );\n return (\n !!potentialAnchored[\"domainAnchor\"] ||\n !!potentialAnchored[\"contextDomainAnchor\"] ||\n domainHasAnchors ||\n contextDomainHasAnchors ||\n axesHaveAnchors\n );\n}\n\n/**\n * Derives the indices of axes marked for splitting based on the selector.\n * Throws an error if splitting is requested alongside `partialAxesMatch`.\n */\nfunction getSplitAxisIndices(\n selector: APColumnSelectorWithSplit | ((spec: PColumnSpec) => boolean),\n): number[] {\n if (typeof selector !== \"object\" || !(\"axes\" in selector) || selector.axes === undefined) {\n return []; // No axes specified or not an object selector, no splitting\n }\n\n const splitIndices = selector.axes\n .map((axis, index) =>\n typeof axis === \"object\" && \"split\" in axis && axis.split === true ? index : -1,\n )\n .filter((index) => index !== -1);\n\n if (splitIndices.length > 0 && selector.partialAxesMatch !== undefined) {\n throw new Error(\"Axis splitting is not supported when `partialAxesMatch` is defined.\");\n }\n\n splitIndices.sort((a, b) => a - b);\n return splitIndices;\n}\n\ntype UniversalPColumnOptsNoDeriver = {\n /** If provided, columns matching the provided selectors will be excluded from the result. */\n exclude?: AnchoredPColumnSelector | AnchoredPColumnSelector[];\n labelOps?: LabelDerivationOps;\n /** If true, incomplete data will cause the column to be skipped instead of returning undefined for the whole request. */\n dontWaitAllData?: boolean;\n /**\n * If true, the derived label will override the 'pl7.app/label' annotation\n * in the resulting PColumnSpec. It also forces `includeNativeLabel` in `labelOps` to true,\n * unless `labelOps.includeNativeLabel` is explicitly set to false.\n * Default value in getUniversalEntries is false, in getColumns it is true.\n */\n overrideLabelAnnotation?: boolean;\n /** If true, resulting columns will be enriched by other columns considering linker columns. Default is false. */\n enrichByLinkers?: boolean;\n};\n\ntype UniversalPColumnOpts = UniversalPColumnOptsNoDeriver & {\n anchorCtx: AnchoredIdDeriver;\n} & ResolveAnchorsOptions;\n\nexport class PColumnCollection {\n private readonly defaultProviderStore: PColumn<PColumnDataUniversal | undefined>[] = [];\n private readonly providers: ColumnProvider[] = [\n new ArrayColumnsProvider(this.defaultProviderStore),\n ];\n private readonly axisLabelProviders: AxisLabelProvider[] = [];\n\n constructor() {}\n\n public addColumnProvider(provider: ColumnProvider): this {\n this.providers.push(provider);\n return this;\n }\n\n public addAxisLabelProvider(provider: AxisLabelProvider): this {\n this.axisLabelProviders.push(provider);\n return this;\n }\n\n public addColumns(columns: PColumn<PColumnDataUniversal | undefined>[]): this {\n this.defaultProviderStore.push(...columns);\n return this;\n }\n\n public addColumn(column: PColumn<PColumnDataUniversal | undefined>): this {\n this.defaultProviderStore.push(column);\n return this;\n }\n\n /** Fetches labels for a given axis from the registered providers */\n private findLabels(axis: AxisId): Record<string | number, string> | undefined {\n for (const provider of this.axisLabelProviders) {\n const labels = provider.findLabels(axis);\n if (labels) return labels; // First provider wins\n }\n return undefined;\n }\n\n // Overload signatures updated to return PColumnEntry types\n public getUniversalEntries(\n predicateOrSelectors:\n | ((spec: PColumnSpec) => boolean)\n | APColumnSelectorWithSplit\n | APColumnSelectorWithSplit[],\n opts: UniversalPColumnOpts,\n ): PColumnEntryUniversal[] | undefined;\n public getUniversalEntries(\n predicateOrSelectors:\n | ((spec: PColumnSpec) => boolean)\n | PColumnSelectorWithSplit\n | PColumnSelectorWithSplit[],\n opts?: UniversalPColumnOptsNoDeriver,\n ): PColumnEntryWithLabel[] | undefined;\n public getUniversalEntries(\n predicateOrSelectors:\n | ((spec: PColumnSpec) => boolean)\n | APColumnSelectorWithSplit\n | APColumnSelectorWithSplit[],\n opts?: Optional<UniversalPColumnOpts, \"anchorCtx\">,\n ): (PColumnEntryWithLabel | PColumnEntryUniversal)[] | undefined {\n const {\n anchorCtx,\n labelOps: rawLabelOps,\n dontWaitAllData = false,\n overrideLabelAnnotation = false,\n exclude,\n enrichByLinkers = false,\n } = opts ?? {};\n\n const labelOps: LabelDerivationOps = {\n ...(overrideLabelAnnotation && rawLabelOps?.includeNativeLabel !== false\n ? { includeNativeLabel: true }\n : {}),\n ...rawLabelOps,\n };\n\n let excludePredicate: (spec: PColumnSpec) => boolean = () => false;\n if (exclude) {\n const excludePredicartes = (Array.isArray(exclude) ? exclude : [exclude]).map((selector) => {\n if (hasAnchors(selector)) {\n if (!anchorCtx)\n throw new Error(\n \"Anchored selectors in exclude require an AnchoredIdDeriver to be provided in options.\",\n );\n return legacyColumnSelectorsToPredicate(\n resolveAnchors(anchorCtx.anchors, selector, opts),\n );\n } else return legacyColumnSelectorsToPredicate(selector);\n });\n excludePredicate = (spec) => excludePredicartes.some((predicate) => predicate(spec));\n }\n\n const selectorsArray =\n typeof predicateOrSelectors === \"function\"\n ? [predicateOrSelectors]\n : Array.isArray(predicateOrSelectors)\n ? predicateOrSelectors\n : [predicateOrSelectors];\n\n const intermediateResults: IntermediateColumnEntry[] = [];\n const selectedNativeIds = new Set<NativePObjectId>();\n\n for (const rawSelector of selectorsArray) {\n const usesAnchors = hasAnchors(rawSelector);\n\n let currentSelector: PColumnSelectorWithSplit | ((spec: PColumnSpec) => boolean);\n if (usesAnchors) {\n if (!anchorCtx)\n throw new Error(\n \"Anchored selectors require an AnchoredIdDeriver to be provided in options.\",\n );\n currentSelector = resolveAnchors(\n anchorCtx.anchors,\n rawSelector as AnchoredPColumnSelector,\n opts,\n );\n } else\n currentSelector = rawSelector as\n | PColumnSelectorWithSplit\n | ((spec: PColumnSpec) => boolean);\n\n const selectedIds = new Set<PObjectId>();\n const selectedColumns: PColumn<PColumnDataUniversal | undefined>[] = [];\n for (const provider of this.providers) {\n const providerColumns = provider.selectColumns(currentSelector);\n const providerIds = new Set<PObjectId>();\n for (const col of providerColumns) {\n if (excludePredicate(col.spec)) continue;\n if (providerIds.has(col.id))\n throw new Error(\n `Duplicate column id ${col.id} in provider ${provider.constructor.name}`,\n );\n providerIds.add(col.id);\n // The same column offered by several providers is taken once, from the first of them.\n const nativeId = deriveNativeId(col.spec);\n if (selectedNativeIds.has(nativeId)) continue;\n if (selectedIds.has(col.id))\n throw new Error(\n `Column id ${col.id} in provider ${provider.constructor.name} is already taken by a different column of another provider`,\n );\n selectedIds.add(col.id);\n selectedNativeIds.add(nativeId);\n selectedColumns.push(col);\n }\n }\n\n if (selectedColumns.length === 0) continue;\n\n const splitAxisIdxs = getSplitAxisIndices(rawSelector);\n const needsSplitting = splitAxisIdxs.length > 0;\n\n for (const column of selectedColumns) {\n if (!isPColumnSpec(column.spec)) continue;\n\n const originalSpec = column.spec;\n\n if (needsSplitting) {\n if (isPColumnValues(column.data))\n throw new Error(\n `Splitting is not supported for PColumns with PColumnValues data format. Column id: ${column.id}`,\n );\n const dataEntries = convertOrParsePColumnData(column.data);\n\n if (!dataEntries) {\n if (dontWaitAllData) continue;\n return undefined;\n }\n\n if (!isPartitionedDataInfoEntries(dataEntries))\n throw new Error(\n `Splitting requires Partitioned DataInfoEntries, but parsing resulted in ${dataEntries.type} for column ${column.id}`,\n );\n\n const uniqueKeys = getUniquePartitionKeys(dataEntries);\n\n const maxSplitIdx = splitAxisIdxs[splitAxisIdxs.length - 1];\n if (maxSplitIdx >= dataEntries.partitionKeyLength)\n throw new Error(\n `Not enough partition keys (${dataEntries.partitionKeyLength}) for requested split axes (max index ${maxSplitIdx}) in column ${originalSpec.name}`,\n );\n\n const axesLabels: (Record<string | number, string> | undefined)[] = splitAxisIdxs.map(\n (idx) => this.findLabels(getAxisId(originalSpec.axesSpec[idx])),\n );\n\n const keyCombinations: (string | number)[][] = [];\n const generateCombinations = (currentCombo: (string | number)[], sAxisIdx: number) => {\n if (sAxisIdx >= splitAxisIdxs.length) {\n keyCombinations.push([...currentCombo]);\n if (keyCombinations.length > 10000)\n throw new Error(\"Too many key combinations, aborting.\");\n return;\n }\n const axisIdx = splitAxisIdxs[sAxisIdx];\n if (axisIdx >= uniqueKeys.length)\n throw new Error(\n `Axis index ${axisIdx} out of bounds for unique keys array (length ${uniqueKeys.length}) during split key generation for column ${column.id}`,\n );\n const axisValues = uniqueKeys[axisIdx];\n if (!axisValues || axisValues.length === 0) {\n keyCombinations.length = 0; // No combinations possible if one axis has no keys\n return;\n }\n for (const val of axisValues) {\n currentCombo.push(val);\n generateCombinations(currentCombo, sAxisIdx + 1);\n currentCombo.pop();\n }\n };\n\n generateCombinations([], 0);\n\n if (keyCombinations.length === 0) continue;\n\n const newAxesSpec = [...originalSpec.axesSpec];\n const splitAxisOriginalIdxs = splitAxisIdxs.map((idx) => idx); // Keep original indices for axisId lookup\n // Remove axes in reverse order to maintain correct indices during removal\n for (let i = splitAxisIdxs.length - 1; i >= 0; i--) {\n newAxesSpec.splice(splitAxisIdxs[i], 1);\n }\n const adjustedSpec = { ...originalSpec, axesSpec: newAxesSpec };\n\n for (const keyCombo of keyCombinations) {\n const splitFilters: AxisFilterInfo[] = keyCombo.map((value, sAxisIdx) => {\n const axisIdx = splitAxisOriginalIdxs[sAxisIdx]; // Use original index for lookup\n const axisId = getAxisId(originalSpec.axesSpec[axisIdx]);\n const axisLabelMap = axesLabels[sAxisIdx];\n const label = axisLabelMap?.[value] ?? String(value);\n return { axisIdx, axisId, value: value as AxisFilterValue, label };\n });\n\n intermediateResults.push({\n type: \"split\",\n originalColumn: column,\n spec: originalSpec,\n adjustedSpec,\n dataEntries,\n axisFilters: splitFilters,\n });\n }\n } else {\n intermediateResults.push({\n type: \"direct\",\n originalColumn: column,\n spec: originalSpec,\n adjustedSpec: originalSpec,\n });\n }\n }\n }\n\n if (intermediateResults.length === 0) return [];\n\n const labeledResults = deriveLabels(\n intermediateResults,\n (entry) => ({\n spec: entry.spec,\n extraTrace:\n entry.type === \"split\" ? splitFiltersToExtraTrace(entry.axisFilters) : undefined,\n }),\n labelOps,\n );\n\n const result: (PColumnEntryWithLabel | PColumnEntryUniversal)[] = [];\n\n for (const { value: entry, label } of labeledResults) {\n const { originalColumn, spec: originalSpec } = entry;\n\n const axisFilters = entry.type === \"split\" ? entry.axisFilters : undefined;\n const axisFiltersTuple = splitFiltersToAxisFilter(axisFilters);\n\n let finalId: SUniversalPColumnId | PObjectId;\n if (anchorCtx) finalId = anchorCtx.deriveS(originalSpec, axisFiltersTuple);\n else finalId = fallbackIdDeriver(originalColumn.id, axisFiltersTuple);\n\n let finalSpec = { ...entry.adjustedSpec };\n\n if (overrideLabelAnnotation) {\n finalSpec = {\n ...finalSpec,\n annotations: {\n ...finalSpec.annotations,\n [Annotation.Label]: label,\n } satisfies Annotation,\n };\n }\n\n result.push({\n id: finalId as PObjectId,\n spec: finalSpec,\n get data() {\n return entry.type === \"split\"\n ? entriesToDataInfo(filterDataInfoEntries(entry.dataEntries, axisFiltersTuple!))\n : entry.originalColumn.data;\n },\n label: label,\n });\n }\n\n const ids = new Set(result.map((entry) => entry.id));\n\n if (enrichByLinkers && anchorCtx) {\n const linkers = result.filter((entry) => isLinkerColumn(entry.spec));\n if (linkers.length === 0) {\n return result;\n }\n\n const anchorAxes = Object.values(anchorCtx.anchors).flatMap((anchor) => anchor.axesSpec);\n const linkerMap = LinkerMap.fromColumns(linkers.map(getColumnIdAndSpec));\n\n // loose way of matching\n function matchAxisIdFn(linkerKeyId: AxisId, sourceAxisId: AxisId): boolean {\n return matchAxisId(linkerKeyId, sourceAxisId) || matchAxisId(sourceAxisId, linkerKeyId);\n }\n // search all axes that can be reached by linkers from anchor axes; anchor axes are not in this list;\n const availableByLinkersAxes = linkerMap.getReachableByLinkersAxesFromAxes(\n anchorAxes,\n matchAxisIdFn,\n );\n\n // search all columns that includes at least one of additional axes;\n const availableByLinkersColumns = this.getUniversalEntries(\n (spec) =>\n !isLinkerColumn(spec) &&\n spec.axesSpec.some((columnAxisSpec) => {\n const columnAxisId = getAxisId(columnAxisSpec);\n return availableByLinkersAxes.some((axis) =>\n matchAxisIdFn(getAxisId(axis), columnAxisId),\n );\n }),\n { anchorCtx, labelOps, dontWaitAllData, overrideLabelAnnotation, exclude },\n );\n if (availableByLinkersColumns) {\n result.push(...availableByLinkersColumns.filter((entry) => !ids.has(entry.id)));\n }\n }\n\n return result;\n }\n\n public getColumns(\n predicateOrSelectors:\n | ((spec: PColumnSpec) => boolean)\n | APColumnSelectorWithSplit\n | APColumnSelectorWithSplit[],\n opts: UniversalPColumnOpts,\n ): PColumn<undefined | PColumnDataUniversal>[] | undefined;\n public getColumns(\n predicateOrSelectors:\n | ((spec: PColumnSpec) => boolean)\n | PColumnSelectorWithSplit\n | PColumnSelectorWithSplit[],\n opts?: UniversalPColumnOptsNoDeriver,\n ): PColumn<undefined | PColumnDataUniversal>[] | undefined;\n public getColumns(\n predicateOrSelectors:\n | ((spec: PColumnSpec) => boolean)\n | APColumnSelectorWithSplit\n | APColumnSelectorWithSplit[],\n opts?: Optional<UniversalPColumnOpts, \"anchorCtx\">,\n ): PColumn<undefined | PColumnDataUniversal>[] | undefined {\n const entries = this.getUniversalEntries(predicateOrSelectors, {\n overrideLabelAnnotation: true, // default for getColumns\n ...opts,\n } as UniversalPColumnOpts);\n if (!entries) return undefined;\n\n const columns: PColumn<undefined | PColumnDataUniversal>[] = [];\n for (const entry of entries) {\n const data = entry.data;\n if (!data) {\n if (opts?.dontWaitAllData) continue;\n return undefined;\n }\n columns.push({\n id: entry.id,\n spec: entry.spec,\n data,\n });\n }\n\n return columns;\n }\n}\n"],"mappings":";;;;;;AAyCA,SAAS,gBAAgB,OAAwC;CAC/D,IAAI,CAAC,MAAM,QAAQ,KAAK,GAAG,OAAO;CAClC,IAAI,MAAM,WAAW,GAAG,OAAO;CAC/B,MAAM,QAAQ,MAAM;CACpB,OAAO,OAAO,UAAU,YAAY,UAAU,QAAQ,SAAS,SAAS,SAAS;AACnF;;;;AAeA,IAAM,uBAAN,MAAqD;CACtB;CAA7B,YAAY,SAAuE;EAAtD,KAAA,UAAA;CAAuD;CAEpF,cACE,WAC6C;EAC7C,MAAM,YACJ,OAAO,cAAc,aAAa,YAAY,iCAAiC,SAAS;EAE1F,OAAO,KAAK,QAAQ,QAAQ,WAC1B,UAAU,OAAO,IAAI,CACvB;CACF;AACF;AAqDA,SAAS,yBAAyB,cAAiC;CACjE,IAAI,iBAAiB,KAAA,GAAW,OAAO,KAAA;CACvC,OAAO,aAAa,KAAK,YAAY;EACnC,MAAM,SAAS,mBAAmB,OAAO,MAAM;EAC/C,OAAO,OAAO;EACd,YAAY;CACd,EAAE;AACJ;AAEA,SAAS,yBAAyB,cAAgE;CAChG,IAAI,CAAC,cAAc,OAAO,KAAA;CAC1B,OAAO,aAAa,KAAK,WAA4B,CAAC,OAAO,SAAS,OAAO,KAAK,CAAC;AACrF;AAEA,SAAS,kBAAkB,YAAuB,aAA4C;CAC5F,IAAI,CAAC,eAAe,YAAY,WAAW,GAAG,OAAO;CACrD,MAAM,wBAAwB,CAAC,GAAG,WAAW,CAAC,CAAC,MAAM,GAAG,MAAM,EAAE,KAAK,EAAE,EAAE;CACzE,OAAO,aAAa;EAAE,IAAI;EAAY,aAAa;CAAsB,CAAC;AAC5E;;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OAAO,OAAO,UAAU,OAAO,CAAC,CAAC,SAAS,WAAW,OAAO,QAAQ;GACvF,MAAM,YAAY,UAAU,YAAY,QAAQ,IAAI,kBAAkB,CAAC;GAGvE,SAAS,cAAc,aAAqB,cAA+B;IACzE,OAAO,YAAY,aAAa,YAAY,KAAK,YAAY,cAAc,WAAW;GACxF;GAEA,MAAM,yBAAyB,UAAU,kCACvC,YACA,aACF;GAGA,MAAM,4BAA4B,KAAK,qBACpC,SACC,CAAC,eAAe,IAAI,KACpB,KAAK,SAAS,MAAM,mBAAmB;IACrC,MAAM,eAAe,UAAU,cAAc;IAC7C,OAAO,uBAAuB,MAAM,SAClC,cAAc,UAAU,IAAI,GAAG,YAAY,CAC7C;GACF,CAAC,GACH;IAAE;IAAW;IAAU;IAAiB;IAAyB;GAAQ,CAC3E;GACA,IAAI,2BACF,OAAO,KAAK,GAAG,0BAA0B,QAAQ,UAAU,CAAC,IAAI,IAAI,MAAM,EAAE,CAAC,CAAC;EAElF;EAEA,OAAO;CACT;CAgBA,WACE,sBAIA,MACyD;EACzD,MAAM,UAAU,KAAK,oBAAoB,sBAAsB;GAC7D,yBAAyB;GACzB,GAAG;EACL,CAAyB;EACzB,IAAI,CAAC,SAAS,OAAO,KAAA;EAErB,MAAM,UAAuD,CAAC;EAC9D,KAAK,MAAM,SAAS,SAAS;GAC3B,MAAM,OAAO,MAAM;GACnB,IAAI,CAAC,MAAM;IACT,IAAI,MAAM,iBAAiB;IAC3B;GACF;GACA,QAAQ,KAAK;IACX,IAAI,MAAM;IACV,MAAM,MAAM;IACZ;GACF,CAAC;EACH;EAEA,OAAO;CACT;AACF"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@platforma-sdk/model",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.90.2",
|
|
4
4
|
"description": "Platforma.bio SDK / Block Model",
|
|
5
5
|
"files": [
|
|
6
6
|
"./dist/**/*",
|
|
@@ -27,9 +27,9 @@
|
|
|
27
27
|
"dependencies": {
|
|
28
28
|
"@milaboratories/helpers": "1.14.7",
|
|
29
29
|
"@milaboratories/pl-error-like": "1.12.11",
|
|
30
|
-
"@milaboratories/pl-model-common": "1.
|
|
31
|
-
"@milaboratories/pl-model-middle-layer": "1.
|
|
32
|
-
"@milaboratories/ptabler-expression-js": "1.2.
|
|
30
|
+
"@milaboratories/pl-model-common": "1.56.0",
|
|
31
|
+
"@milaboratories/pl-model-middle-layer": "1.40.0",
|
|
32
|
+
"@milaboratories/ptabler-expression-js": "1.2.50",
|
|
33
33
|
"canonicalize": "~2.1.0",
|
|
34
34
|
"es-toolkit": "^1.39.10",
|
|
35
35
|
"fast-json-patch": "^3.1.1",
|
|
@@ -39,9 +39,9 @@
|
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
41
|
"@milaboratories/build-configs": "2.0.3",
|
|
42
|
-
"@milaboratories/columns-collection-driver": "0.
|
|
43
|
-
"@milaboratories/pf-driver": "1.9.
|
|
44
|
-
"@milaboratories/pf-spec-driver": "1.
|
|
42
|
+
"@milaboratories/columns-collection-driver": "0.3.0",
|
|
43
|
+
"@milaboratories/pf-driver": "1.9.18",
|
|
44
|
+
"@milaboratories/pf-spec-driver": "1.6.0",
|
|
45
45
|
"@milaboratories/ts-builder": "1.8.0",
|
|
46
46
|
"@milaboratories/ts-configs": "1.4.1",
|
|
47
47
|
"@platforma-sdk/block-kind": "1.1.1",
|
|
@@ -56,12 +56,14 @@ const COLUMNS_COLLECTION_METHODS: ReadonlyArray<string> = [
|
|
|
56
56
|
"addSource",
|
|
57
57
|
"discover",
|
|
58
58
|
"filter",
|
|
59
|
+
"discoverRoots",
|
|
59
60
|
];
|
|
60
61
|
|
|
61
62
|
const PFRAME_SPEC_METHODS: ReadonlyArray<string> = [
|
|
62
63
|
"createSpecFrame",
|
|
63
64
|
"listColumns",
|
|
64
65
|
"discoverColumns",
|
|
66
|
+
"discoverRoots",
|
|
65
67
|
"deleteColumn",
|
|
66
68
|
"evaluateQuery",
|
|
67
69
|
"buildQuery",
|
|
@@ -93,6 +95,7 @@ export function createTestCollectionDriver(): TestCollectionDriverHandle {
|
|
|
93
95
|
addSource: (h, srcs) => impl.addSource(h, srcs, bindings).key,
|
|
94
96
|
discover: (h, o) => impl.discover(h, o, bindings).key,
|
|
95
97
|
filter: (h, o) => impl.filter(h, o, bindings).key,
|
|
98
|
+
discoverRoots: (h, o) => impl.discoverRoots(h, o, bindings),
|
|
96
99
|
};
|
|
97
100
|
|
|
98
101
|
let installedCtx: GlobalCfgRenderCtx | undefined;
|
|
@@ -201,3 +201,50 @@ describe("ColumnsCollection.filter", () => {
|
|
|
201
201
|
expect(ids).toEqual([c1.id, c2.id]);
|
|
202
202
|
});
|
|
203
203
|
});
|
|
204
|
+
|
|
205
|
+
describe("ColumnsCollection.discoverRoots", () => {
|
|
206
|
+
const cellAxis: AxisSpec = { name: "cell", type: "Int" };
|
|
207
|
+
const sampleAxis: AxisSpec = { name: "sample", type: "Long" };
|
|
208
|
+
const linkerSpec: PColumnSpec = {
|
|
209
|
+
...spec("cellToSample", [cellAxis, sampleAxis]),
|
|
210
|
+
annotations: { "pl7.app/isLinkerColumn": "true" },
|
|
211
|
+
};
|
|
212
|
+
|
|
213
|
+
const cellData = { id: gid("cellData"), spec: spec("cellData", [cellAxis]) };
|
|
214
|
+
const linker = { id: gid("cellToSample"), spec: linkerSpec };
|
|
215
|
+
const sampleData = { id: gid("sampleData"), spec: spec("sampleData", [sampleAxis]) };
|
|
216
|
+
|
|
217
|
+
beforeEach(() => handle.installAmbientCtx());
|
|
218
|
+
afterEach(() => handle.uninstallAmbientCtx());
|
|
219
|
+
|
|
220
|
+
test("finds the column the given one hangs off, with the linker path", () => {
|
|
221
|
+
const found = makeCollection([cellData, linker, sampleData]).discoverRoots({
|
|
222
|
+
leaves: [cellData.id],
|
|
223
|
+
maxHops: 1,
|
|
224
|
+
});
|
|
225
|
+
|
|
226
|
+
expect(found.map((r) => r.root.id)).toEqual([sampleData.id]);
|
|
227
|
+
expect(found[0]?.path.map((c) => c.id)).toEqual([linker.id]);
|
|
228
|
+
});
|
|
229
|
+
|
|
230
|
+
test("the leaf is what discover anchored on the root returns", () => {
|
|
231
|
+
const collection = makeCollection([cellData, linker, sampleData]);
|
|
232
|
+
const [found] = collection.discoverRoots({ leaves: [cellData.id], maxHops: 1 });
|
|
233
|
+
|
|
234
|
+
const discovered = collection
|
|
235
|
+
.discover({ anchors: { r: sampleData.id }, maxHops: 1 })
|
|
236
|
+
.getColumnIds();
|
|
237
|
+
|
|
238
|
+
expect(found).toBeDefined();
|
|
239
|
+
expect(discovered).toContain(found?.leaf.id);
|
|
240
|
+
});
|
|
241
|
+
|
|
242
|
+
test("a column at the top of the hierarchy has no roots", () => {
|
|
243
|
+
const found = makeCollection([cellData, linker, sampleData]).discoverRoots({
|
|
244
|
+
leaves: [sampleData.id],
|
|
245
|
+
maxHops: 1,
|
|
246
|
+
});
|
|
247
|
+
|
|
248
|
+
expect(found).toEqual([]);
|
|
249
|
+
});
|
|
250
|
+
});
|
|
@@ -4,6 +4,7 @@ import type {
|
|
|
4
4
|
ColumnsCollectionDriverModel,
|
|
5
5
|
ColumnsDiscoverOptions,
|
|
6
6
|
ColumnsFilterOptions,
|
|
7
|
+
DiscoverRootsOptions,
|
|
7
8
|
SerializedColumnsSource,
|
|
8
9
|
} from "@milaboratories/pl-model-common";
|
|
9
10
|
import type { GlobalCfgRenderCtx } from "../render/internal";
|
|
@@ -58,6 +59,21 @@ export function isColumnsCollection(value: unknown): value is ColumnsCollection
|
|
|
58
59
|
return value instanceof ColumnsCollectionImpl;
|
|
59
60
|
}
|
|
60
61
|
|
|
62
|
+
/**
|
|
63
|
+
* A root found by {@link ColumnsCollectionImpl.discoverRoots}: `leaf` is the
|
|
64
|
+
* requested column exactly as `discover({ anchors: { r: root } })` would
|
|
65
|
+
* return it — carrying the linker `path` and qualifications — so the table is
|
|
66
|
+
* built from `root` as the anchor plus `leaf`.
|
|
67
|
+
*/
|
|
68
|
+
export interface DiscoveredRoot {
|
|
69
|
+
/** The column the leaf hangs off. */
|
|
70
|
+
readonly root: ColumnRecipe;
|
|
71
|
+
/** The requested column, discovered from the root. */
|
|
72
|
+
readonly leaf: ColumnRecipe;
|
|
73
|
+
/** Linker columns from the root to the leaf; empty when they join directly. */
|
|
74
|
+
readonly path: ColumnRecipe[];
|
|
75
|
+
}
|
|
76
|
+
|
|
61
77
|
/**
|
|
62
78
|
* Sandbox proxy over the host-side `ColumnsCollection` driver. The driver
|
|
63
79
|
* owns all column-set state; this object only carries an opaque
|
|
@@ -110,6 +126,23 @@ export class ColumnsCollectionImpl {
|
|
|
110
126
|
filter(options: ColumnsFilterOptions): ColumnsCollection {
|
|
111
127
|
return new ColumnsCollectionImpl(this.driver.filter(this.handle, options), this.driver);
|
|
112
128
|
}
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* Finds the roots the given columns hang off: the columns that, used as
|
|
132
|
+
* `anchors` of {@link discover}, would reach them. One entry per root, leaf
|
|
133
|
+
* and linker path; entries whose columns are not yet resolvable are skipped.
|
|
134
|
+
*/
|
|
135
|
+
discoverRoots(options: DiscoverRootsOptions): DiscoveredRoot[] {
|
|
136
|
+
return this.driver.discoverRoots(this.handle, options).flatMap((ids) => {
|
|
137
|
+
const root = ColumnRecipe(ids.root);
|
|
138
|
+
const leaf = ColumnRecipe(ids.leaf);
|
|
139
|
+
const path = ids.path
|
|
140
|
+
.map((id) => ColumnRecipe(id))
|
|
141
|
+
.filter((c): c is ColumnRecipe => !isNil(c));
|
|
142
|
+
if (isNil(root) || isNil(leaf) || path.length !== ids.path.length) return [];
|
|
143
|
+
return [{ root, leaf, path }];
|
|
144
|
+
});
|
|
145
|
+
}
|
|
113
146
|
}
|
|
114
147
|
|
|
115
148
|
/** Public type alias — value of the same name is the factory function above. */
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
PColumn,
|
|
3
|
+
PColumnSpec,
|
|
4
|
+
PColumnValues,
|
|
5
|
+
PObjectId,
|
|
6
|
+
} from "@milaboratories/pl-model-common";
|
|
7
|
+
import { expect, test } from "vitest";
|
|
8
|
+
import type { PColumnDataUniversal } from "../internal";
|
|
9
|
+
import { PColumnCollection, type ColumnProvider } from "./column_collection";
|
|
10
|
+
|
|
11
|
+
test("a column offered by two providers under one id is taken once, from the first provider", () => {
|
|
12
|
+
const fromBlock = column("pool-sequence", "sequence", [{ key: ["f1"], val: "block" }]);
|
|
13
|
+
const fromPool = column("pool-sequence", "sequence", [{ key: ["f1"], val: "pool" }]);
|
|
14
|
+
|
|
15
|
+
const columns = new PColumnCollection()
|
|
16
|
+
.addColumnProvider(provider([fromPool]))
|
|
17
|
+
.addColumns([column("own-result", "result"), fromBlock])
|
|
18
|
+
.getColumns(() => true);
|
|
19
|
+
|
|
20
|
+
expect(columns?.map((c) => c.id)).toEqual(["own-result", "pool-sequence"]);
|
|
21
|
+
expect(columns?.[1].data).toBe(fromBlock.data);
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
test("a column offered by two providers under different ids is taken once, from the first provider", () => {
|
|
25
|
+
const columns = new PColumnCollection()
|
|
26
|
+
.addColumnProvider(provider([column("pool-sequence", "sequence")]))
|
|
27
|
+
.addColumns([column("block-sequence", "sequence")])
|
|
28
|
+
.getColumns(() => true);
|
|
29
|
+
|
|
30
|
+
expect(columns?.map((c) => c.id)).toEqual(["block-sequence"]);
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
test("one provider offering two columns under one id is an error", () => {
|
|
34
|
+
const collection = new PColumnCollection().addColumnProvider(
|
|
35
|
+
provider([column("pool-sequence", "sequence"), column("pool-sequence", "sequence")]),
|
|
36
|
+
);
|
|
37
|
+
|
|
38
|
+
expect(() => collection.getColumns(() => true)).toThrow(/Duplicate column id pool-sequence/);
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
test("two providers offering different columns under one id is an error", () => {
|
|
42
|
+
const collection = new PColumnCollection()
|
|
43
|
+
.addColumnProvider(provider([column("shared-id", "sequence")]))
|
|
44
|
+
.addColumns([column("shared-id", "result")]);
|
|
45
|
+
|
|
46
|
+
expect(() => collection.getColumns(() => true)).toThrow(
|
|
47
|
+
/Column id shared-id .* is already taken by a different column/,
|
|
48
|
+
);
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
// Internals
|
|
52
|
+
|
|
53
|
+
type Column = PColumn<PColumnDataUniversal | undefined>;
|
|
54
|
+
|
|
55
|
+
function column(id: string, name: string, data: PColumnValues = []): Column {
|
|
56
|
+
const spec: PColumnSpec = {
|
|
57
|
+
kind: "PColumn",
|
|
58
|
+
name,
|
|
59
|
+
valueType: "String",
|
|
60
|
+
axesSpec: [{ name: "feature", type: "String" }],
|
|
61
|
+
};
|
|
62
|
+
return { id: id as PObjectId, spec, data };
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function provider(columns: Column[]): ColumnProvider {
|
|
66
|
+
return {
|
|
67
|
+
selectColumns: (selectors) => {
|
|
68
|
+
if (typeof selectors !== "function") throw new Error("Only predicates are used here");
|
|
69
|
+
return columns.filter((c) => selectors(c.spec));
|
|
70
|
+
},
|
|
71
|
+
};
|
|
72
|
+
}
|
|
@@ -341,14 +341,21 @@ export class PColumnCollection {
|
|
|
341
341
|
const selectedColumns: PColumn<PColumnDataUniversal | undefined>[] = [];
|
|
342
342
|
for (const provider of this.providers) {
|
|
343
343
|
const providerColumns = provider.selectColumns(currentSelector);
|
|
344
|
+
const providerIds = new Set<PObjectId>();
|
|
344
345
|
for (const col of providerColumns) {
|
|
345
346
|
if (excludePredicate(col.spec)) continue;
|
|
346
|
-
if (
|
|
347
|
+
if (providerIds.has(col.id))
|
|
347
348
|
throw new Error(
|
|
348
349
|
`Duplicate column id ${col.id} in provider ${provider.constructor.name}`,
|
|
349
350
|
);
|
|
351
|
+
providerIds.add(col.id);
|
|
352
|
+
// The same column offered by several providers is taken once, from the first of them.
|
|
350
353
|
const nativeId = deriveNativeId(col.spec);
|
|
351
354
|
if (selectedNativeIds.has(nativeId)) continue;
|
|
355
|
+
if (selectedIds.has(col.id))
|
|
356
|
+
throw new Error(
|
|
357
|
+
`Column id ${col.id} in provider ${provider.constructor.name} is already taken by a different column of another provider`,
|
|
358
|
+
);
|
|
352
359
|
selectedIds.add(col.id);
|
|
353
360
|
selectedNativeIds.add(nativeId);
|
|
354
361
|
selectedColumns.push(col);
|