@platforma-sdk/model 1.68.8 → 1.70.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/columns/column_collection_builder.cjs +1 -4
- package/dist/columns/column_collection_builder.cjs.map +1 -1
- package/dist/columns/column_collection_builder.d.ts +0 -2
- package/dist/columns/column_collection_builder.d.ts.map +1 -1
- package/dist/columns/column_collection_builder.js +1 -4
- package/dist/columns/column_collection_builder.js.map +1 -1
- package/dist/columns/ctx_column_sources.cjs +5 -8
- package/dist/columns/ctx_column_sources.cjs.map +1 -1
- package/dist/columns/ctx_column_sources.d.ts +4 -7
- package/dist/columns/ctx_column_sources.d.ts.map +1 -1
- package/dist/columns/ctx_column_sources.js +5 -8
- package/dist/columns/ctx_column_sources.js.map +1 -1
- package/dist/components/PlDataTable/createPlDataTable/createPlDataTableV3.cjs +23 -44
- package/dist/components/PlDataTable/createPlDataTable/createPlDataTableV3.cjs.map +1 -1
- package/dist/components/PlDataTable/createPlDataTable/createPlDataTableV3.d.ts.map +1 -1
- package/dist/components/PlDataTable/createPlDataTable/createPlDataTableV3.js +23 -44
- package/dist/components/PlDataTable/createPlDataTable/createPlDataTableV3.js.map +1 -1
- package/dist/components/PlDataTable/createPlDataTable/discoverColumns.cjs +2 -7
- package/dist/components/PlDataTable/createPlDataTable/discoverColumns.cjs.map +1 -1
- package/dist/components/PlDataTable/createPlDataTable/discoverColumns.d.ts.map +1 -1
- package/dist/components/PlDataTable/createPlDataTable/discoverColumns.js +2 -7
- package/dist/components/PlDataTable/createPlDataTable/discoverColumns.js.map +1 -1
- package/dist/components/PlDataTable/createPlDataTable/utils.cjs +3 -18
- package/dist/components/PlDataTable/createPlDataTable/utils.cjs.map +1 -1
- package/dist/components/PlDataTable/createPlDataTable/utils.d.ts.map +1 -1
- package/dist/components/PlDataTable/createPlDataTable/utils.js +4 -19
- package/dist/components/PlDataTable/createPlDataTable/utils.js.map +1 -1
- package/dist/components/PlDataTable/labels.cjs +0 -25
- package/dist/components/PlDataTable/labels.cjs.map +1 -1
- package/dist/components/PlDataTable/labels.js +2 -26
- package/dist/components/PlDataTable/labels.js.map +1 -1
- package/dist/components/PlDatasetSelector/build_dataset_options.cjs +23 -11
- package/dist/components/PlDatasetSelector/build_dataset_options.cjs.map +1 -1
- package/dist/components/PlDatasetSelector/build_dataset_options.d.ts +9 -2
- package/dist/components/PlDatasetSelector/build_dataset_options.d.ts.map +1 -1
- package/dist/components/PlDatasetSelector/build_dataset_options.js +22 -11
- package/dist/components/PlDatasetSelector/build_dataset_options.js.map +1 -1
- package/dist/components/PlDatasetSelector/dataset_selection.cjs +20 -0
- package/dist/components/PlDatasetSelector/dataset_selection.cjs.map +1 -0
- package/dist/components/PlDatasetSelector/dataset_selection.d.ts +23 -0
- package/dist/components/PlDatasetSelector/dataset_selection.d.ts.map +1 -0
- package/dist/components/PlDatasetSelector/dataset_selection.js +19 -0
- package/dist/components/PlDatasetSelector/dataset_selection.js.map +1 -0
- package/dist/components/PlDatasetSelector/enrichment_discovery.cjs +75 -0
- package/dist/components/PlDatasetSelector/enrichment_discovery.cjs.map +1 -0
- package/dist/components/PlDatasetSelector/enrichment_discovery.js +73 -0
- package/dist/components/PlDatasetSelector/enrichment_discovery.js.map +1 -0
- package/dist/components/PlDatasetSelector/index.cjs +1 -0
- package/dist/components/PlDatasetSelector/index.d.ts +1 -0
- package/dist/components/PlDatasetSelector/index.js +1 -0
- package/dist/components/index.cjs +1 -0
- package/dist/components/index.d.ts +1 -0
- package/dist/components/index.js +1 -0
- package/dist/index.cjs +3 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.js +2 -1
- package/dist/labels/derive_distinct_tooltips.cjs +0 -3
- package/dist/labels/derive_distinct_tooltips.cjs.map +1 -1
- package/dist/labels/derive_distinct_tooltips.js +0 -3
- package/dist/labels/derive_distinct_tooltips.js.map +1 -1
- package/dist/package.cjs +1 -1
- package/dist/package.js +1 -1
- package/package.json +8 -8
- package/src/columns/column_collection_builder.ts +0 -3
- package/src/columns/ctx_column_sources.ts +6 -12
- package/src/components/PlDataTable/createPlDataTable/createPlDataTableV3.ts +3 -43
- package/src/components/PlDataTable/createPlDataTable/discoverColumns.ts +0 -10
- package/src/components/PlDataTable/createPlDataTable/utils.test.ts +5 -131
- package/src/components/PlDataTable/createPlDataTable/utils.ts +2 -26
- package/src/components/PlDatasetSelector/build_dataset_options.ts +48 -17
- package/src/components/PlDatasetSelector/dataset_selection.ts +37 -0
- package/src/components/PlDatasetSelector/enrichment_discovery.ts +111 -0
- package/src/components/PlDatasetSelector/index.ts +1 -0
- package/src/labels/derive_distinct_tooltips.test.ts +6 -16
- package/src/labels/derive_distinct_tooltips.ts +0 -3
|
@@ -110,10 +110,7 @@ var AnchoredColumnCollectionImpl = class {
|
|
|
110
110
|
const col = this.columnsMap.get(origId) ?? (0, _milaboratories_helpers.throwError)(`Column with id ${origId} not found in collection`);
|
|
111
111
|
const path = hit.path.map((step) => {
|
|
112
112
|
if (step.type !== "linker") throw new Error(`Unexpected discover-columns step type: ${step.type}`);
|
|
113
|
-
return {
|
|
114
|
-
linker: this.columnsMap.get(step.linker.columnId) ?? (0, _milaboratories_helpers.throwError)(`Linker column with id ${step.linker.columnId} not found in collection`),
|
|
115
|
-
qualifications: step.qualifications
|
|
116
|
-
};
|
|
113
|
+
return { linker: this.columnsMap.get(step.linker.columnId) ?? (0, _milaboratories_helpers.throwError)(`Linker column with id ${step.linker.columnId} not found in collection`) };
|
|
117
114
|
});
|
|
118
115
|
const variants = hit.mappingVariants.map((v) => ({
|
|
119
116
|
path,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"column_collection_builder.cjs","names":["getService","TreeNodeAccessor","ArrayColumnProvider","toColumnSnapshotProvider","convertColumnSelectorToMultiColumnSelector"],"sources":["../../src/columns/column_collection_builder.ts"],"sourcesContent":["import type {\n AxisQualification,\n DiscoverColumnsConstraints,\n DiscoverColumnsRequest,\n DiscoverColumnsResponse,\n MultiColumnSelector,\n NativePObjectId,\n PColumnSpec,\n PObjectId,\n} from \"@milaboratories/pl-model-common\";\nimport { deriveNativeId, isPColumnSpec } from \"@milaboratories/pl-model-common\";\nimport type { ColumnSelector, RelaxedColumnSelector } from \"./column_selector\";\nimport { convertColumnSelectorToMultiColumnSelector } from \"./column_selector\";\nimport { TreeNodeAccessor } from \"../render/accessor\";\nimport type { ColumnSnapshot } from \"./column_snapshot\";\nimport type { ColumnSnapshotProvider, ColumnSource } from \"./column_snapshot_provider\";\nimport { ArrayColumnProvider, toColumnSnapshotProvider } from \"./column_snapshot_provider\";\n\nimport type { PFrameSpecDriver, PoolEntry, SpecFrameHandle } from \"@milaboratories/pl-model-common\";\nimport { throwError } from \"@milaboratories/helpers\";\nimport { getService } from \"../services\";\n\n// --- FindColumnsOptions ---\n\n/** Options for plain collection findColumns. */\nexport interface FindColumnsOptions {\n /** Include columns matching these selectors. If omitted, includes all columns. */\n include?: ColumnSelector;\n /** Exclude columns matching these selectors. */\n exclude?: ColumnSelector;\n}\n\n// --- ColumnCollection ---\n\n/** Plain collection — no axis context, selector-based filtering only. */\nexport interface ColumnCollection extends Disposable {\n /** Release the underlying spec frame WASM resource. */\n dispose(): void;\n\n /** Find columns matching selectors. Returns flat list of snapshots.\n * No axis compatibility matching, no linker traversal.\n * Never returns undefined — the \"not ready\" state was absorbed by the builder. */\n findColumns(options?: FindColumnsOptions): ColumnSnapshot<PObjectId>[];\n}\n\n// --- AnchoredColumnCollection ---\n\n/** Axis-aware column collection with anchored identity derivation. */\nexport interface AnchoredColumnCollection extends Disposable {\n /** Release the underlying spec frame WASM resource. */\n dispose(): void;\n\n /** List of anchors used for discovery, with their resolved specs. */\n getAnchors(): Map<string, ColumnSnapshot<PObjectId>>;\n\n /** Axis-aware column discovery. */\n findColumns(options?: AnchoredFindColumnsOptions): ColumnMatch[];\n\n /** Variant discovery with detailed mapping info for each hit. */\n findColumnVariants(options?: AnchoredFindColumnsOptions): ColumnVariant[];\n}\n\n/** Controls axis matching behavior for anchored discovery. */\nexport type MatchingMode = \"enrichment\" | \"related\" | \"exact\";\n\n/** Options for anchored collection findColumns. */\nexport interface AnchoredFindColumnsOptions extends FindColumnsOptions {\n /** Controls axis matching behavior. Default: 'enrichment'. */\n mode?: MatchingMode;\n /** Maximum linker hops for cross-domain discovery (0 = direct only, default: 4). */\n maxHops?: number;\n}\n\n/** Result of anchored discovery — column snapshot + routing info. */\nexport interface ColumnMatch {\n /** Column snapshot with anchored SUniversalPColumnId. */\n readonly column: ColumnSnapshot<PObjectId>;\n /** Match variants — different ways (paths/qualifications) to reach this column. */\n readonly variants: MatchVariant[];\n}\n\nexport interface ColumnVariant<Id extends PObjectId = PObjectId> {\n /** Column snapshot with anchored SUniversalPColumnId. */\n readonly column: ColumnSnapshot<Id>;\n /** Full qualifications needed for integration. */\n readonly qualifications: MatchQualifications;\n /** Linker steps traversed to reach this hit; empty for direct matches. */\n readonly path: {\n linker: ColumnSnapshot<PObjectId>;\n qualifications: AxisQualification[];\n }[];\n}\n\n/** A single mapping variant describing how a hit column can be integrated. */\nexport interface MatchVariant {\n /** Full qualifications needed for integration. */\n readonly qualifications: MatchQualifications;\n /** Linker steps traversed to reach this hit; empty for direct matches. */\n readonly path: {\n linker: ColumnSnapshot<PObjectId>;\n qualifications: AxisQualification[];\n }[];\n}\n\n/** Qualifications needed for both already-integrated anchor columns and the hit column. */\nexport interface MatchQualifications {\n /** Qualifications for already-integrated anchor columns */\n readonly forQueries: Record<PObjectId, AxisQualification[]>;\n /** Qualifications for the hit column. */\n readonly forHit: AxisQualification[];\n}\n\n// --- Build options ---\n\nexport interface BuildOptions {\n allowPartialColumnList?: true;\n}\n\nexport type AnchorEntry = PObjectId | PColumnSpec | RelaxedColumnSelector;\n\nexport interface AnchoredBuildOptions extends BuildOptions {\n anchors: Record<string, AnchorEntry>;\n}\n\n// --- ColumnCollectionBuilder ---\n\n/**\n * Mutable builder that accumulates column sources, then produces\n * a ColumnCollection (plain) or AnchoredColumnCollection (with anchors).\n *\n * Each output lambda creates its own builder — a constraint of the\n * computable framework where each output tracks its own dependencies.\n */\nexport class ColumnCollectionBuilder {\n private readonly providers: ColumnSnapshotProvider[] = [];\n\n constructor(private readonly specDriver: PFrameSpecDriver = getService(\"pframeSpec\")) {}\n\n /**\n * Register a column source. Sources added first take precedence for dedup.\n * Does NOT accept undefined — if a source isn't available yet,\n * the caller should return undefined from the output lambda.\n */\n addSource(source: ColumnSource | TreeNodeAccessor): this {\n if (source instanceof TreeNodeAccessor) {\n const columns = source.getPColumns();\n if (columns) this.providers.push(new ArrayColumnProvider(columns));\n } else {\n this.providers.push(toColumnSnapshotProvider(source));\n }\n return this;\n }\n\n addSources(sources: (ColumnSource | TreeNodeAccessor)[]): this {\n for (const source of sources) {\n this.addSource(source);\n }\n return this;\n }\n\n /** Plain collection — selector-based filtering, PObjectId namespace. */\n build(): undefined | ColumnCollection;\n build(options: {\n allowPartialColumnList: true;\n }): ColumnCollection & { readonly columnListComplete: boolean };\n /** Anchored collection — axis-aware discovery, SUniversalPColumnId namespace. */\n build(\n options: AnchoredBuildOptions & { allowPartialColumnList: true },\n ): AnchoredColumnCollection & { readonly columnListComplete: boolean };\n build(options: AnchoredBuildOptions): undefined | AnchoredColumnCollection;\n build(\n options?: BuildOptions | AnchoredBuildOptions,\n ):\n | undefined\n | ColumnCollection\n | AnchoredColumnCollection\n | (ColumnCollection & { readonly columnListComplete: boolean })\n | (AnchoredColumnCollection & { readonly columnListComplete: boolean }) {\n const allowPartial = options?.allowPartialColumnList === true;\n\n // Check column list completeness\n const allComplete = this.providers.every((p) => p.isColumnListComplete());\n if (!allComplete && !allowPartial) return undefined;\n\n // Collect all columns, dedup by native ID (first source wins)\n const columns = collectColumns(this.providers);\n const hasAnchors = options !== undefined && \"anchors\" in options;\n\n if (hasAnchors) {\n return new AnchoredColumnCollectionImpl(this.specDriver, {\n anchors: options.anchors,\n columns,\n });\n } else {\n return new ColumnCollectionImpl(this.specDriver, {\n columns,\n });\n }\n }\n}\n\n// --- ColumnCollectionImpl ---\n\ninterface ColumnCollectionImplOptions {\n readonly columns: ColumnSnapshot<PObjectId>[];\n}\n\nclass ColumnCollectionImpl implements ColumnCollection, Disposable {\n private readonly columns: Map<PObjectId, ColumnSnapshot<PObjectId>>;\n private readonly specFrameEntry: PoolEntry<SpecFrameHandle>;\n\n constructor(\n private readonly specDriver: PFrameSpecDriver,\n options: ColumnCollectionImplOptions,\n ) {\n this.columns = new Map(options.columns.map((col) => [col.id, col]));\n this.specFrameEntry = this.specDriver.createSpecFrame(\n Object.fromEntries(options.columns.map((col) => [col.id, col.spec])),\n );\n }\n\n dispose(): void {\n this.specFrameEntry.unref();\n }\n\n [Symbol.dispose](): void {\n this.dispose();\n }\n\n findColumns(options?: FindColumnsOptions): ColumnSnapshot<PObjectId>[] {\n const includeColumns = options?.include ? toMultiColumnSelectors(options.include) : undefined;\n const excludeColumns = options?.exclude ? toMultiColumnSelectors(options.exclude) : undefined;\n\n const response = this.specDriver.discoverColumns(this.specFrameEntry.key, {\n includeColumns,\n excludeColumns,\n axes: [],\n maxHops: 0,\n constraints: matchingModeToConstraints(\"enrichment\"),\n });\n\n // Map hits back to snapshots\n const results = response.hits\n .map((hit) => this.columns.get(hit.hit.columnId as PObjectId))\n .filter((col): col is ColumnSnapshot<PObjectId> => col !== undefined);\n\n return results;\n }\n}\n\n// --- AnchoredColumnCollectionImpl ---\n\ninterface AnchoredColumnCollectionImplOptions extends ColumnCollectionImplOptions {\n readonly anchors: Record<string, AnchorEntry>;\n}\n\nclass AnchoredColumnCollectionImpl implements AnchoredColumnCollection, Disposable {\n private readonly anchorsMap: Map<string, ColumnSnapshot<PObjectId>>;\n private readonly columnsMap: Map<PObjectId, ColumnSnapshot<PObjectId>>;\n private readonly specFrameEntry: PoolEntry<SpecFrameHandle>;\n\n constructor(\n private readonly specDriver: PFrameSpecDriver,\n options: AnchoredColumnCollectionImplOptions,\n ) {\n // Create spec frame from all collected columns\n this.specFrameEntry = this.specDriver.createSpecFrame(\n Object.fromEntries(options.columns.map((col) => [col.id, col.spec])),\n );\n this.columnsMap = new Map(options.columns.map((col) => [col.id, col]));\n this.anchorsMap = resolveAnchorMap(\n options.anchors,\n options.columns,\n this.specDriver.discoverColumns.bind(this.specDriver, this.specFrameEntry.key),\n );\n }\n\n dispose(): void {\n this.specFrameEntry.unref();\n }\n\n [Symbol.dispose](): void {\n this.dispose();\n }\n\n getAnchors(): Map<string, ColumnSnapshot<PObjectId>> {\n return this.anchorsMap;\n }\n\n findColumns(options?: AnchoredFindColumnsOptions): ColumnMatch[] {\n const mode = options?.mode ?? \"enrichment\";\n const constraints = matchingModeToConstraints(mode);\n const includeColumns = options?.include ? toMultiColumnSelectors(options.include) : undefined;\n const excludeColumns = options?.exclude ? toMultiColumnSelectors(options.exclude) : undefined;\n const anchors = Array.from(this.anchorsMap.values());\n const response = this.specDriver.discoverColumns(this.specFrameEntry.key, {\n includeColumns,\n excludeColumns,\n constraints,\n maxHops: options?.maxHops ?? 4,\n axes: anchors.map((anchor) => ({\n axesSpec: anchor.spec.axesSpec,\n qualifications: [],\n })),\n });\n\n const byColumn = response.hits.reduce<Map<PObjectId, ColumnMatch>>((acc, hit) => {\n const origId = hit.hit.columnId as PObjectId;\n const col =\n this.columnsMap.get(origId) ??\n throwError(`Column with id ${origId} not found in collection`);\n\n const path = hit.path.map((step) => {\n if (step.type !== \"linker\") {\n throw new Error(`Unexpected discover-columns step type: ${step.type}`);\n }\n\n return {\n linker:\n this.columnsMap.get(step.linker.columnId) ??\n throwError(`Linker column with id ${step.linker.columnId} not found in collection`),\n qualifications: step.qualifications,\n };\n });\n const variants: MatchVariant[] = hit.mappingVariants.map((v) => ({\n path,\n qualifications: remapFromIdxToId(v.qualifications, anchors),\n }));\n const existing = acc.get(origId);\n return acc.set(\n origId,\n existing === undefined\n ? { column: col, variants }\n : { ...existing, variants: [...existing.variants, ...variants] },\n );\n }, new Map());\n\n return Array.from(byColumn.values());\n }\n\n findColumnVariants(options?: AnchoredFindColumnsOptions): ColumnVariant[] {\n const matches = this.findColumns(options);\n return matches.flatMap((match) =>\n match.variants.map((variant) => ({\n column: match.column,\n path: variant.path,\n qualifications: variant.qualifications,\n })),\n );\n }\n}\n\n/**\n * Collect all columns from all providers, dedup by NativePObjectId.\n * First source wins.\n */\nfunction collectColumns(providers: ColumnSnapshotProvider[]): ColumnSnapshot<PObjectId>[] {\n const seen = new Set<NativePObjectId>();\n const result: ColumnSnapshot<PObjectId>[] = [];\n\n for (const provider of providers) {\n const columns = provider.getAllColumns();\n for (const col of columns) {\n const nativeId = deriveNativeId(col.spec);\n if (seen.has(nativeId)) continue;\n seen.add(nativeId);\n result.push(col);\n }\n }\n\n return result;\n}\n\n// --- Shared snapshot helpers ---\n\n/** Normalize ColumnSelector (relaxed, single or array) to MultiColumnSelector[]. */\nfunction toMultiColumnSelectors(input: ColumnSelector): MultiColumnSelector[] {\n return convertColumnSelectorToMultiColumnSelector(input);\n}\n\n// --- Anchor resolution ---\n\n/**\n * Resolve each anchor entry to a ColumnSnapshot from the collected columns.\n * - PObjectId (string): looked up by id in the collected columns\n * - PColumnSpec: matched by deriveNativeId against collected columns\n * - RelaxedColumnSelector: resolved via discoverColumns in \"exact\" mode;\n * must match exactly one column\n * Throws on unresolved, ambiguous, or duplicated matches. Requires at least one\n * anchor to resolve.\n */\nfunction resolveAnchorMap(\n anchors: Record<string, AnchorEntry>,\n columns: ColumnSnapshot<PObjectId>[],\n discoverColumns: (request: DiscoverColumnsRequest) => DiscoverColumnsResponse,\n): Map<string, ColumnSnapshot<PObjectId>> {\n const result = new Map<string, ColumnSnapshot<PObjectId>>();\n const resovedIds = new Set<PObjectId>();\n const getDuplicateError = (key: string) =>\n `Anchor \"${key}\": selector matched a column that was already matched by another anchor; please refine the selector to match a different column`;\n\n for (const [name, anchor] of Object.entries(anchors)) {\n if (typeof anchor === \"string\") {\n const found =\n columns.find((col) => col.id === anchor) ??\n throwError(`Anchor \"${name}\": column with id \"${anchor}\" not found in sources`);\n if (resovedIds.has(found.id)) {\n throwError(getDuplicateError(name));\n }\n result.set(name, found);\n resovedIds.add(found.id);\n } else if (\"kind\" in anchor) {\n if (!isPColumnSpec(anchor)) throwError(`Anchor \"${name}\": invalid PColumnSpec`);\n const nativeId = deriveNativeId(anchor);\n const found =\n columns.find((col) => deriveNativeId(col.spec) === nativeId) ??\n throwError(`Anchor \"${name}\": no column matching spec found in sources`);\n if (resovedIds.has(found.id)) {\n throwError(getDuplicateError(name));\n }\n result.set(name, found);\n resovedIds.add(found.id);\n } else {\n const matched = discoverColumns({\n includeColumns: toMultiColumnSelectors(anchor),\n excludeColumns: undefined,\n axes: [],\n maxHops: 0,\n constraints: matchingModeToConstraints(\"exact\"),\n });\n\n if (matched.hits.length === 0) {\n throwError(`Anchor \"${name}\": no columns matched selector`);\n }\n if (matched.hits.length > 1) {\n throwError(\n `Anchor \"${name}\": selector is ambiguous and matched multiple columns; please refine the selector to match exactly one column`,\n );\n }\n if (resovedIds.has(matched.hits[0].hit.columnId as PObjectId)) {\n throwError(getDuplicateError(name));\n }\n\n const id = matched.hits[0].hit.columnId as PObjectId;\n const snap =\n columns.find((col) => col.id === id) ??\n throwError(`Anchor \"${name}\": matched column with id \"${id}\" not found in sources`);\n result.set(name, snap);\n resovedIds.add(snap.id);\n }\n }\n\n if (resovedIds.size === 0) {\n throwError(\"At least one anchor must be resolved to a valid column\");\n }\n\n return result;\n}\n\nfunction remapFromIdxToId(\n qualifications: {\n forQueries: AxisQualification[][];\n forHit: AxisQualification[];\n },\n anchors: ColumnSnapshot<PObjectId>[],\n): MatchQualifications {\n const forQueries = qualifications.forQueries.reduce<Record<PObjectId, AxisQualification[]>>(\n (acc, qs, i) => (anchors[i] ? ((acc[anchors[i].id] = qs), acc) : acc),\n {},\n );\n return { forQueries, forHit: qualifications.forHit };\n}\n\n// --- MatchingMode → DiscoverColumnsConstraints ---\n\nfunction matchingModeToConstraints(mode: MatchingMode): DiscoverColumnsConstraints {\n switch (mode) {\n case \"enrichment\":\n return {\n allowFloatingSourceAxes: true,\n allowFloatingHitAxes: false,\n allowSourceQualifications: true,\n allowHitQualifications: true,\n };\n case \"related\":\n return {\n allowFloatingSourceAxes: true,\n allowFloatingHitAxes: true,\n allowSourceQualifications: true,\n allowHitQualifications: true,\n };\n case \"exact\":\n return {\n allowFloatingSourceAxes: false,\n allowFloatingHitAxes: false,\n allowSourceQualifications: false,\n allowHitQualifications: false,\n };\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAqIA,IAAa,0BAAb,MAAqC;CACnC,YAAuD,EAAE;CAEzD,YAAY,aAAgDA,qBAAAA,WAAW,aAAa,EAAE;AAAzD,OAAA,aAAA;;;;;;;CAO7B,UAAU,QAA+C;AACvD,MAAI,kBAAkBC,iBAAAA,kBAAkB;GACtC,MAAM,UAAU,OAAO,aAAa;AACpC,OAAI,QAAS,MAAK,UAAU,KAAK,IAAIC,iCAAAA,oBAAoB,QAAQ,CAAC;QAElE,MAAK,UAAU,KAAKC,iCAAAA,yBAAyB,OAAO,CAAC;AAEvD,SAAO;;CAGT,WAAW,SAAoD;AAC7D,OAAK,MAAM,UAAU,QACnB,MAAK,UAAU,OAAO;AAExB,SAAO;;CAaT,MACE,SAMwE;EACxE,MAAM,eAAe,SAAS,2BAA2B;AAIzD,MAAI,CADgB,KAAK,UAAU,OAAO,MAAM,EAAE,sBAAsB,CAAC,IACrD,CAAC,aAAc,QAAO,KAAA;EAG1C,MAAM,UAAU,eAAe,KAAK,UAAU;AAG9C,MAFmB,YAAY,KAAA,KAAa,aAAa,QAGvD,QAAO,IAAI,6BAA6B,KAAK,YAAY;GACvD,SAAS,QAAQ;GACjB;GACD,CAAC;MAEF,QAAO,IAAI,qBAAqB,KAAK,YAAY,EAC/C,SACD,CAAC;;;AAWR,IAAM,uBAAN,MAAmE;CACjE;CACA;CAEA,YACE,YACA,SACA;AAFiB,OAAA,aAAA;AAGjB,OAAK,UAAU,IAAI,IAAI,QAAQ,QAAQ,KAAK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AO;GACL,yBAAyB;GACzB,sBAAsB;GACtB,2BAA2B;GAC3B,wBAAwB;GACzB;EACH,KAAK,UACH,QAAO;GACL,yBAAyB;GACzB,sBAAsB;GACtB,2BAA2B;GAC3B,wBAAwB;GACzB;EACH,KAAK,QACH,QAAO;GACL,yBAAyB;GACzB,sBAAsB;GACtB,2BAA2B;GAC3B,wBAAwB;GACzB"}
|
|
1
|
+
{"version":3,"file":"column_collection_builder.cjs","names":["getService","TreeNodeAccessor","ArrayColumnProvider","toColumnSnapshotProvider","convertColumnSelectorToMultiColumnSelector"],"sources":["../../src/columns/column_collection_builder.ts"],"sourcesContent":["import type {\n AxisQualification,\n DiscoverColumnsConstraints,\n DiscoverColumnsRequest,\n DiscoverColumnsResponse,\n MultiColumnSelector,\n NativePObjectId,\n PColumnSpec,\n PObjectId,\n} from \"@milaboratories/pl-model-common\";\nimport { deriveNativeId, isPColumnSpec } from \"@milaboratories/pl-model-common\";\nimport type { ColumnSelector, RelaxedColumnSelector } from \"./column_selector\";\nimport { convertColumnSelectorToMultiColumnSelector } from \"./column_selector\";\nimport { TreeNodeAccessor } from \"../render/accessor\";\nimport type { ColumnSnapshot } from \"./column_snapshot\";\nimport type { ColumnSnapshotProvider, ColumnSource } from \"./column_snapshot_provider\";\nimport { ArrayColumnProvider, toColumnSnapshotProvider } from \"./column_snapshot_provider\";\n\nimport type { PFrameSpecDriver, PoolEntry, SpecFrameHandle } from \"@milaboratories/pl-model-common\";\nimport { throwError } from \"@milaboratories/helpers\";\nimport { getService } from \"../services\";\n\n// --- FindColumnsOptions ---\n\n/** Options for plain collection findColumns. */\nexport interface FindColumnsOptions {\n /** Include columns matching these selectors. If omitted, includes all columns. */\n include?: ColumnSelector;\n /** Exclude columns matching these selectors. */\n exclude?: ColumnSelector;\n}\n\n// --- ColumnCollection ---\n\n/** Plain collection — no axis context, selector-based filtering only. */\nexport interface ColumnCollection extends Disposable {\n /** Release the underlying spec frame WASM resource. */\n dispose(): void;\n\n /** Find columns matching selectors. Returns flat list of snapshots.\n * No axis compatibility matching, no linker traversal.\n * Never returns undefined — the \"not ready\" state was absorbed by the builder. */\n findColumns(options?: FindColumnsOptions): ColumnSnapshot<PObjectId>[];\n}\n\n// --- AnchoredColumnCollection ---\n\n/** Axis-aware column collection with anchored identity derivation. */\nexport interface AnchoredColumnCollection extends Disposable {\n /** Release the underlying spec frame WASM resource. */\n dispose(): void;\n\n /** List of anchors used for discovery, with their resolved specs. */\n getAnchors(): Map<string, ColumnSnapshot<PObjectId>>;\n\n /** Axis-aware column discovery. */\n findColumns(options?: AnchoredFindColumnsOptions): ColumnMatch[];\n\n /** Variant discovery with detailed mapping info for each hit. */\n findColumnVariants(options?: AnchoredFindColumnsOptions): ColumnVariant[];\n}\n\n/** Controls axis matching behavior for anchored discovery. */\nexport type MatchingMode = \"enrichment\" | \"related\" | \"exact\";\n\n/** Options for anchored collection findColumns. */\nexport interface AnchoredFindColumnsOptions extends FindColumnsOptions {\n /** Controls axis matching behavior. Default: 'enrichment'. */\n mode?: MatchingMode;\n /** Maximum linker hops for cross-domain discovery (0 = direct only, default: 4). */\n maxHops?: number;\n}\n\n/** Result of anchored discovery — column snapshot + routing info. */\nexport interface ColumnMatch {\n /** Column snapshot with anchored SUniversalPColumnId. */\n readonly column: ColumnSnapshot<PObjectId>;\n /** Match variants — different ways (paths/qualifications) to reach this column. */\n readonly variants: MatchVariant[];\n}\n\nexport interface ColumnVariant<Id extends PObjectId = PObjectId> {\n /** Column snapshot with anchored SUniversalPColumnId. */\n readonly column: ColumnSnapshot<Id>;\n /** Full qualifications needed for integration. */\n readonly qualifications: MatchQualifications;\n /** Linker steps traversed to reach this hit; empty for direct matches. */\n readonly path: {\n linker: ColumnSnapshot<PObjectId>;\n }[];\n}\n\n/** A single mapping variant describing how a hit column can be integrated. */\nexport interface MatchVariant {\n /** Full qualifications needed for integration. */\n readonly qualifications: MatchQualifications;\n /** Linker steps traversed to reach this hit; empty for direct matches. */\n readonly path: {\n linker: ColumnSnapshot<PObjectId>;\n }[];\n}\n\n/** Qualifications needed for both already-integrated anchor columns and the hit column. */\nexport interface MatchQualifications {\n /** Qualifications for already-integrated anchor columns */\n readonly forQueries: Record<PObjectId, AxisQualification[]>;\n /** Qualifications for the hit column. */\n readonly forHit: AxisQualification[];\n}\n\n// --- Build options ---\n\nexport interface BuildOptions {\n allowPartialColumnList?: true;\n}\n\nexport type AnchorEntry = PObjectId | PColumnSpec | RelaxedColumnSelector;\n\nexport interface AnchoredBuildOptions extends BuildOptions {\n anchors: Record<string, AnchorEntry>;\n}\n\n// --- ColumnCollectionBuilder ---\n\n/**\n * Mutable builder that accumulates column sources, then produces\n * a ColumnCollection (plain) or AnchoredColumnCollection (with anchors).\n *\n * Each output lambda creates its own builder — a constraint of the\n * computable framework where each output tracks its own dependencies.\n */\nexport class ColumnCollectionBuilder {\n private readonly providers: ColumnSnapshotProvider[] = [];\n\n constructor(private readonly specDriver: PFrameSpecDriver = getService(\"pframeSpec\")) {}\n\n /**\n * Register a column source. Sources added first take precedence for dedup.\n * Does NOT accept undefined — if a source isn't available yet,\n * the caller should return undefined from the output lambda.\n */\n addSource(source: ColumnSource | TreeNodeAccessor): this {\n if (source instanceof TreeNodeAccessor) {\n const columns = source.getPColumns();\n if (columns) this.providers.push(new ArrayColumnProvider(columns));\n } else {\n this.providers.push(toColumnSnapshotProvider(source));\n }\n return this;\n }\n\n addSources(sources: (ColumnSource | TreeNodeAccessor)[]): this {\n for (const source of sources) {\n this.addSource(source);\n }\n return this;\n }\n\n /** Plain collection — selector-based filtering, PObjectId namespace. */\n build(): undefined | ColumnCollection;\n build(options: {\n allowPartialColumnList: true;\n }): ColumnCollection & { readonly columnListComplete: boolean };\n /** Anchored collection — axis-aware discovery, SUniversalPColumnId namespace. */\n build(\n options: AnchoredBuildOptions & { allowPartialColumnList: true },\n ): AnchoredColumnCollection & { readonly columnListComplete: boolean };\n build(options: AnchoredBuildOptions): undefined | AnchoredColumnCollection;\n build(\n options?: BuildOptions | AnchoredBuildOptions,\n ):\n | undefined\n | ColumnCollection\n | AnchoredColumnCollection\n | (ColumnCollection & { readonly columnListComplete: boolean })\n | (AnchoredColumnCollection & { readonly columnListComplete: boolean }) {\n const allowPartial = options?.allowPartialColumnList === true;\n\n // Check column list completeness\n const allComplete = this.providers.every((p) => p.isColumnListComplete());\n if (!allComplete && !allowPartial) return undefined;\n\n // Collect all columns, dedup by native ID (first source wins)\n const columns = collectColumns(this.providers);\n const hasAnchors = options !== undefined && \"anchors\" in options;\n\n if (hasAnchors) {\n return new AnchoredColumnCollectionImpl(this.specDriver, {\n anchors: options.anchors,\n columns,\n });\n } else {\n return new ColumnCollectionImpl(this.specDriver, {\n columns,\n });\n }\n }\n}\n\n// --- ColumnCollectionImpl ---\n\ninterface ColumnCollectionImplOptions {\n readonly columns: ColumnSnapshot<PObjectId>[];\n}\n\nclass ColumnCollectionImpl implements ColumnCollection, Disposable {\n private readonly columns: Map<PObjectId, ColumnSnapshot<PObjectId>>;\n private readonly specFrameEntry: PoolEntry<SpecFrameHandle>;\n\n constructor(\n private readonly specDriver: PFrameSpecDriver,\n options: ColumnCollectionImplOptions,\n ) {\n this.columns = new Map(options.columns.map((col) => [col.id, col]));\n this.specFrameEntry = this.specDriver.createSpecFrame(\n Object.fromEntries(options.columns.map((col) => [col.id, col.spec])),\n );\n }\n\n dispose(): void {\n this.specFrameEntry.unref();\n }\n\n [Symbol.dispose](): void {\n this.dispose();\n }\n\n findColumns(options?: FindColumnsOptions): ColumnSnapshot<PObjectId>[] {\n const includeColumns = options?.include ? toMultiColumnSelectors(options.include) : undefined;\n const excludeColumns = options?.exclude ? toMultiColumnSelectors(options.exclude) : undefined;\n\n const response = this.specDriver.discoverColumns(this.specFrameEntry.key, {\n includeColumns,\n excludeColumns,\n axes: [],\n maxHops: 0,\n constraints: matchingModeToConstraints(\"enrichment\"),\n });\n\n // Map hits back to snapshots\n const results = response.hits\n .map((hit) => this.columns.get(hit.hit.columnId as PObjectId))\n .filter((col): col is ColumnSnapshot<PObjectId> => col !== undefined);\n\n return results;\n }\n}\n\n// --- AnchoredColumnCollectionImpl ---\n\ninterface AnchoredColumnCollectionImplOptions extends ColumnCollectionImplOptions {\n readonly anchors: Record<string, AnchorEntry>;\n}\n\nclass AnchoredColumnCollectionImpl implements AnchoredColumnCollection, Disposable {\n private readonly anchorsMap: Map<string, ColumnSnapshot<PObjectId>>;\n private readonly columnsMap: Map<PObjectId, ColumnSnapshot<PObjectId>>;\n private readonly specFrameEntry: PoolEntry<SpecFrameHandle>;\n\n constructor(\n private readonly specDriver: PFrameSpecDriver,\n options: AnchoredColumnCollectionImplOptions,\n ) {\n // Create spec frame from all collected columns\n this.specFrameEntry = this.specDriver.createSpecFrame(\n Object.fromEntries(options.columns.map((col) => [col.id, col.spec])),\n );\n this.columnsMap = new Map(options.columns.map((col) => [col.id, col]));\n this.anchorsMap = resolveAnchorMap(\n options.anchors,\n options.columns,\n this.specDriver.discoverColumns.bind(this.specDriver, this.specFrameEntry.key),\n );\n }\n\n dispose(): void {\n this.specFrameEntry.unref();\n }\n\n [Symbol.dispose](): void {\n this.dispose();\n }\n\n getAnchors(): Map<string, ColumnSnapshot<PObjectId>> {\n return this.anchorsMap;\n }\n\n findColumns(options?: AnchoredFindColumnsOptions): ColumnMatch[] {\n const mode = options?.mode ?? \"enrichment\";\n const constraints = matchingModeToConstraints(mode);\n const includeColumns = options?.include ? toMultiColumnSelectors(options.include) : undefined;\n const excludeColumns = options?.exclude ? toMultiColumnSelectors(options.exclude) : undefined;\n const anchors = Array.from(this.anchorsMap.values());\n const response = this.specDriver.discoverColumns(this.specFrameEntry.key, {\n includeColumns,\n excludeColumns,\n constraints,\n maxHops: options?.maxHops ?? 4,\n axes: anchors.map((anchor) => ({\n axesSpec: anchor.spec.axesSpec,\n qualifications: [],\n })),\n });\n\n const byColumn = response.hits.reduce<Map<PObjectId, ColumnMatch>>((acc, hit) => {\n const origId = hit.hit.columnId as PObjectId;\n const col =\n this.columnsMap.get(origId) ??\n throwError(`Column with id ${origId} not found in collection`);\n\n const path = hit.path.map((step) => {\n if (step.type !== \"linker\") {\n throw new Error(`Unexpected discover-columns step type: ${step.type}`);\n }\n\n return {\n linker:\n this.columnsMap.get(step.linker.columnId) ??\n throwError(`Linker column with id ${step.linker.columnId} not found in collection`),\n };\n });\n const variants: MatchVariant[] = hit.mappingVariants.map((v) => ({\n path,\n qualifications: remapFromIdxToId(v.qualifications, anchors),\n }));\n const existing = acc.get(origId);\n return acc.set(\n origId,\n existing === undefined\n ? { column: col, variants }\n : { ...existing, variants: [...existing.variants, ...variants] },\n );\n }, new Map());\n\n return Array.from(byColumn.values());\n }\n\n findColumnVariants(options?: AnchoredFindColumnsOptions): ColumnVariant[] {\n const matches = this.findColumns(options);\n return matches.flatMap((match) =>\n match.variants.map((variant) => ({\n column: match.column,\n path: variant.path,\n qualifications: variant.qualifications,\n })),\n );\n }\n}\n\n/**\n * Collect all columns from all providers, dedup by NativePObjectId.\n * First source wins.\n */\nfunction collectColumns(providers: ColumnSnapshotProvider[]): ColumnSnapshot<PObjectId>[] {\n const seen = new Set<NativePObjectId>();\n const result: ColumnSnapshot<PObjectId>[] = [];\n\n for (const provider of providers) {\n const columns = provider.getAllColumns();\n for (const col of columns) {\n const nativeId = deriveNativeId(col.spec);\n if (seen.has(nativeId)) continue;\n seen.add(nativeId);\n result.push(col);\n }\n }\n\n return result;\n}\n\n// --- Shared snapshot helpers ---\n\n/** Normalize ColumnSelector (relaxed, single or array) to MultiColumnSelector[]. */\nfunction toMultiColumnSelectors(input: ColumnSelector): MultiColumnSelector[] {\n return convertColumnSelectorToMultiColumnSelector(input);\n}\n\n// --- Anchor resolution ---\n\n/**\n * Resolve each anchor entry to a ColumnSnapshot from the collected columns.\n * - PObjectId (string): looked up by id in the collected columns\n * - PColumnSpec: matched by deriveNativeId against collected columns\n * - RelaxedColumnSelector: resolved via discoverColumns in \"exact\" mode;\n * must match exactly one column\n * Throws on unresolved, ambiguous, or duplicated matches. Requires at least one\n * anchor to resolve.\n */\nfunction resolveAnchorMap(\n anchors: Record<string, AnchorEntry>,\n columns: ColumnSnapshot<PObjectId>[],\n discoverColumns: (request: DiscoverColumnsRequest) => DiscoverColumnsResponse,\n): Map<string, ColumnSnapshot<PObjectId>> {\n const result = new Map<string, ColumnSnapshot<PObjectId>>();\n const resovedIds = new Set<PObjectId>();\n const getDuplicateError = (key: string) =>\n `Anchor \"${key}\": selector matched a column that was already matched by another anchor; please refine the selector to match a different column`;\n\n for (const [name, anchor] of Object.entries(anchors)) {\n if (typeof anchor === \"string\") {\n const found =\n columns.find((col) => col.id === anchor) ??\n throwError(`Anchor \"${name}\": column with id \"${anchor}\" not found in sources`);\n if (resovedIds.has(found.id)) {\n throwError(getDuplicateError(name));\n }\n result.set(name, found);\n resovedIds.add(found.id);\n } else if (\"kind\" in anchor) {\n if (!isPColumnSpec(anchor)) throwError(`Anchor \"${name}\": invalid PColumnSpec`);\n const nativeId = deriveNativeId(anchor);\n const found =\n columns.find((col) => deriveNativeId(col.spec) === nativeId) ??\n throwError(`Anchor \"${name}\": no column matching spec found in sources`);\n if (resovedIds.has(found.id)) {\n throwError(getDuplicateError(name));\n }\n result.set(name, found);\n resovedIds.add(found.id);\n } else {\n const matched = discoverColumns({\n includeColumns: toMultiColumnSelectors(anchor),\n excludeColumns: undefined,\n axes: [],\n maxHops: 0,\n constraints: matchingModeToConstraints(\"exact\"),\n });\n\n if (matched.hits.length === 0) {\n throwError(`Anchor \"${name}\": no columns matched selector`);\n }\n if (matched.hits.length > 1) {\n throwError(\n `Anchor \"${name}\": selector is ambiguous and matched multiple columns; please refine the selector to match exactly one column`,\n );\n }\n if (resovedIds.has(matched.hits[0].hit.columnId as PObjectId)) {\n throwError(getDuplicateError(name));\n }\n\n const id = matched.hits[0].hit.columnId as PObjectId;\n const snap =\n columns.find((col) => col.id === id) ??\n throwError(`Anchor \"${name}\": matched column with id \"${id}\" not found in sources`);\n result.set(name, snap);\n resovedIds.add(snap.id);\n }\n }\n\n if (resovedIds.size === 0) {\n throwError(\"At least one anchor must be resolved to a valid column\");\n }\n\n return result;\n}\n\nfunction remapFromIdxToId(\n qualifications: {\n forQueries: AxisQualification[][];\n forHit: AxisQualification[];\n },\n anchors: ColumnSnapshot<PObjectId>[],\n): MatchQualifications {\n const forQueries = qualifications.forQueries.reduce<Record<PObjectId, AxisQualification[]>>(\n (acc, qs, i) => (anchors[i] ? ((acc[anchors[i].id] = qs), acc) : acc),\n {},\n );\n return { forQueries, forHit: qualifications.forHit };\n}\n\n// --- MatchingMode → DiscoverColumnsConstraints ---\n\nfunction matchingModeToConstraints(mode: MatchingMode): DiscoverColumnsConstraints {\n switch (mode) {\n case \"enrichment\":\n return {\n allowFloatingSourceAxes: true,\n allowFloatingHitAxes: false,\n allowSourceQualifications: true,\n allowHitQualifications: true,\n };\n case \"related\":\n return {\n allowFloatingSourceAxes: true,\n allowFloatingHitAxes: true,\n allowSourceQualifications: true,\n allowHitQualifications: true,\n };\n case \"exact\":\n return {\n allowFloatingSourceAxes: false,\n allowFloatingHitAxes: false,\n allowSourceQualifications: false,\n allowHitQualifications: false,\n };\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAmIA,IAAa,0BAAb,MAAqC;CACnC,YAAuD,EAAE;CAEzD,YAAY,aAAgDA,qBAAAA,WAAW,aAAa,EAAE;AAAzD,OAAA,aAAA;;;;;;;CAO7B,UAAU,QAA+C;AACvD,MAAI,kBAAkBC,iBAAAA,kBAAkB;GACtC,MAAM,UAAU,OAAO,aAAa;AACpC,OAAI,QAAS,MAAK,UAAU,KAAK,IAAIC,iCAAAA,oBAAoB,QAAQ,CAAC;QAElE,MAAK,UAAU,KAAKC,iCAAAA,yBAAyB,OAAO,CAAC;AAEvD,SAAO;;CAGT,WAAW,SAAoD;AAC7D,OAAK,MAAM,UAAU,QACnB,MAAK,UAAU,OAAO;AAExB,SAAO;;CAaT,MACE,SAMwE;EACxE,MAAM,eAAe,SAAS,2BAA2B;AAIzD,MAAI,CADg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ACrF,SAAO,IAAI,MAAM,KAAK;AACtB,aAAW,IAAI,KAAK,GAAG;;AAI3B,KAAI,WAAW,SAAS,EACtB,EAAA,GAAA,wBAAA,YAAW,yDAAyD;AAGtE,QAAO;;AAGT,SAAS,iBACP,gBAIA,SACqB;AAKrB,QAAO;EAAE,YAJU,eAAe,WAAW,QAC1C,KAAK,IAAI,MAAO,QAAQ,MAAO,IAAI,QAAQ,GAAG,MAAM,IAAK,OAAO,KACjE,EAAE,CACH;EACoB,QAAQ,eAAe;EAAQ;;AAKtD,SAAS,0BAA0B,MAAgD;AACjF,SAAQ,MAAR;EACE,KAAK,aACH,QAAO;GACL,yBAAyB;GACzB,sBAAsB;GACtB,2BAA2B;GAC3B,wBAAwB;GACzB;EACH,KAAK,UACH,QAAO;GACL,yBAAyB;GACzB,sBAAsB;GACtB,2BAA2B;GAC3B,wBAAwB;GACzB;EACH,KAAK,QACH,QAAO;GACL,yBAAyB;GACzB,sBAAsB;GACtB,2BAA2B;GAC3B,wBAAwB;GACzB"}
|
|
@@ -56,7 +56,6 @@ interface ColumnVariant<Id extends PObjectId = PObjectId> {
|
|
|
56
56
|
/** Linker steps traversed to reach this hit; empty for direct matches. */
|
|
57
57
|
readonly path: {
|
|
58
58
|
linker: ColumnSnapshot<PObjectId>;
|
|
59
|
-
qualifications: AxisQualification[];
|
|
60
59
|
}[];
|
|
61
60
|
}
|
|
62
61
|
/** A single mapping variant describing how a hit column can be integrated. */
|
|
@@ -66,7 +65,6 @@ interface MatchVariant {
|
|
|
66
65
|
/** Linker steps traversed to reach this hit; empty for direct matches. */
|
|
67
66
|
readonly path: {
|
|
68
67
|
linker: ColumnSnapshot<PObjectId>;
|
|
69
|
-
qualifications: AxisQualification[];
|
|
70
68
|
}[];
|
|
71
69
|
}
|
|
72
70
|
/** Qualifications needed for both already-integrated anchor columns and the hit column. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"column_collection_builder.d.ts","names":[],"sources":["../../src/columns/column_collection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AAW,OAAA,GAAU,YAAA,GAAe,gBAAA;EApEnB;EA4EjB,KAAA,CAAA,eAAqB,gBAAA;EACrB,KAAA,CAAM,OAAA;IACJ,sBAAA;EAAA,IACE,gBAAA;IAAA,SAA8B,kBAAA;EAAA;EAjFM;EAmFxC,KAAA,CACE,OAAA,EAAS,oBAAA;IAAyB,sBAAA;EAAA,IACjC,wBAAA;IAAA,SAAsC,kBAAA;EAAA;EACzC,KAAA,CAAM,OAAA,EAAS,oBAAA,eAAmC,wBAAA;AAAA"}
|
|
@@ -109,10 +109,7 @@ var AnchoredColumnCollectionImpl = class {
|
|
|
109
109
|
const col = this.columnsMap.get(origId) ?? throwError(`Column with id ${origId} not found in collection`);
|
|
110
110
|
const path = hit.path.map((step) => {
|
|
111
111
|
if (step.type !== "linker") throw new Error(`Unexpected discover-columns step type: ${step.type}`);
|
|
112
|
-
return {
|
|
113
|
-
linker: this.columnsMap.get(step.linker.columnId) ?? throwError(`Linker column with id ${step.linker.columnId} not found in collection`),
|
|
114
|
-
qualifications: step.qualifications
|
|
115
|
-
};
|
|
112
|
+
return { linker: this.columnsMap.get(step.linker.columnId) ?? throwError(`Linker column with id ${step.linker.columnId} not found in collection`) };
|
|
116
113
|
});
|
|
117
114
|
const variants = hit.mappingVariants.map((v) => ({
|
|
118
115
|
path,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"column_collection_builder.js","names":[],"sources":["../../src/columns/column_collection_builder.ts"],"sourcesContent":["import type {\n AxisQualification,\n DiscoverColumnsConstraints,\n DiscoverColumnsRequest,\n DiscoverColumnsResponse,\n MultiColumnSelector,\n NativePObjectId,\n PColumnSpec,\n PObjectId,\n} from \"@milaboratories/pl-model-common\";\nimport { deriveNativeId, isPColumnSpec } from \"@milaboratories/pl-model-common\";\nimport type { ColumnSelector, RelaxedColumnSelector } from \"./column_selector\";\nimport { convertColumnSelectorToMultiColumnSelector } from \"./column_selector\";\nimport { TreeNodeAccessor } from \"../render/accessor\";\nimport type { ColumnSnapshot } from \"./column_snapshot\";\nimport type { ColumnSnapshotProvider, ColumnSource } from \"./column_snapshot_provider\";\nimport { ArrayColumnProvider, toColumnSnapshotProvider } from \"./column_snapshot_provider\";\n\nimport type { PFrameSpecDriver, PoolEntry, SpecFrameHandle } from \"@milaboratories/pl-model-common\";\nimport { throwError } from \"@milaboratories/helpers\";\nimport { getService } from \"../services\";\n\n// --- FindColumnsOptions ---\n\n/** Options for plain collection findColumns. */\nexport interface FindColumnsOptions {\n /** Include columns matching these selectors. If omitted, includes all columns. */\n include?: ColumnSelector;\n /** Exclude columns matching these selectors. */\n exclude?: ColumnSelector;\n}\n\n// --- ColumnCollection ---\n\n/** Plain collection — no axis context, selector-based filtering only. */\nexport interface ColumnCollection extends Disposable {\n /** Release the underlying spec frame WASM resource. */\n dispose(): void;\n\n /** Find columns matching selectors. Returns flat list of snapshots.\n * No axis compatibility matching, no linker traversal.\n * Never returns undefined — the \"not ready\" state was absorbed by the builder. */\n findColumns(options?: FindColumnsOptions): ColumnSnapshot<PObjectId>[];\n}\n\n// --- AnchoredColumnCollection ---\n\n/** Axis-aware column collection with anchored identity derivation. */\nexport interface AnchoredColumnCollection extends Disposable {\n /** Release the underlying spec frame WASM resource. */\n dispose(): void;\n\n /** List of anchors used for discovery, with their resolved specs. */\n getAnchors(): Map<string, ColumnSnapshot<PObjectId>>;\n\n /** Axis-aware column discovery. */\n findColumns(options?: AnchoredFindColumnsOptions): ColumnMatch[];\n\n /** Variant discovery with detailed mapping info for each hit. */\n findColumnVariants(options?: AnchoredFindColumnsOptions): ColumnVariant[];\n}\n\n/** Controls axis matching behavior for anchored discovery. */\nexport type MatchingMode = \"enrichment\" | \"related\" | \"exact\";\n\n/** Options for anchored collection findColumns. */\nexport interface AnchoredFindColumnsOptions extends FindColumnsOptions {\n /** Controls axis matching behavior. Default: 'enrichment'. */\n mode?: MatchingMode;\n /** Maximum linker hops for cross-domain discovery (0 = direct only, default: 4). */\n maxHops?: number;\n}\n\n/** Result of anchored discovery — column snapshot + routing info. */\nexport interface ColumnMatch {\n /** Column snapshot with anchored SUniversalPColumnId. */\n readonly column: ColumnSnapshot<PObjectId>;\n /** Match variants — different ways (paths/qualifications) to reach this column. */\n readonly variants: MatchVariant[];\n}\n\nexport interface ColumnVariant<Id extends PObjectId = PObjectId> {\n /** Column snapshot with anchored SUniversalPColumnId. */\n readonly column: ColumnSnapshot<Id>;\n /** Full qualifications needed for integration. */\n readonly qualifications: MatchQualifications;\n /** Linker steps traversed to reach this hit; empty for direct matches. */\n readonly path: {\n linker: ColumnSnapshot<PObjectId>;\n qualifications: AxisQualification[];\n }[];\n}\n\n/** A single mapping variant describing how a hit column can be integrated. */\nexport interface MatchVariant {\n /** Full qualifications needed for integration. */\n readonly qualifications: MatchQualifications;\n /** Linker steps traversed to reach this hit; empty for direct matches. */\n readonly path: {\n linker: ColumnSnapshot<PObjectId>;\n qualifications: AxisQualification[];\n }[];\n}\n\n/** Qualifications needed for both already-integrated anchor columns and the hit column. */\nexport interface MatchQualifications {\n /** Qualifications for already-integrated anchor columns */\n readonly forQueries: Record<PObjectId, AxisQualification[]>;\n /** Qualifications for the hit column. */\n readonly forHit: AxisQualification[];\n}\n\n// --- Build options ---\n\nexport interface BuildOptions {\n allowPartialColumnList?: true;\n}\n\nexport type AnchorEntry = PObjectId | PColumnSpec | RelaxedColumnSelector;\n\nexport interface AnchoredBuildOptions extends BuildOptions {\n anchors: Record<string, AnchorEntry>;\n}\n\n// --- ColumnCollectionBuilder ---\n\n/**\n * Mutable builder that accumulates column sources, then produces\n * a ColumnCollection (plain) or AnchoredColumnCollection (with anchors).\n *\n * Each output lambda creates its own builder — a constraint of the\n * computable framework where each output tracks its own dependencies.\n */\nexport class ColumnCollectionBuilder {\n private readonly providers: ColumnSnapshotProvider[] = [];\n\n constructor(private readonly specDriver: PFrameSpecDriver = getService(\"pframeSpec\")) {}\n\n /**\n * Register a column source. Sources added first take precedence for dedup.\n * Does NOT accept undefined — if a source isn't available yet,\n * the caller should return undefined from the output lambda.\n */\n addSource(source: ColumnSource | TreeNodeAccessor): this {\n if (source instanceof TreeNodeAccessor) {\n const columns = source.getPColumns();\n if (columns) this.providers.push(new ArrayColumnProvider(columns));\n } else {\n this.providers.push(toColumnSnapshotProvider(source));\n }\n return this;\n }\n\n addSources(sources: (ColumnSource | TreeNodeAccessor)[]): this {\n for (const source of sources) {\n this.addSource(source);\n }\n return this;\n }\n\n /** Plain collection — selector-based filtering, PObjectId namespace. */\n build(): undefined | ColumnCollection;\n build(options: {\n allowPartialColumnList: true;\n }): ColumnCollection & { readonly columnListComplete: boolean };\n /** Anchored collection — axis-aware discovery, SUniversalPColumnId namespace. */\n build(\n options: AnchoredBuildOptions & { allowPartialColumnList: true },\n ): AnchoredColumnCollection & { readonly columnListComplete: boolean };\n build(options: AnchoredBuildOptions): undefined | AnchoredColumnCollection;\n build(\n options?: BuildOptions | AnchoredBuildOptions,\n ):\n | undefined\n | ColumnCollection\n | AnchoredColumnCollection\n | (ColumnCollection & { readonly columnListComplete: boolean })\n | (AnchoredColumnCollection & { readonly columnListComplete: boolean }) {\n const allowPartial = options?.allowPartialColumnList === true;\n\n // Check column list completeness\n const allComplete = this.providers.every((p) => p.isColumnListComplete());\n if (!allComplete && !allowPartial) return undefined;\n\n // Collect all columns, dedup by native ID (first source wins)\n const columns = collectColumns(this.providers);\n const hasAnchors = options !== undefined && \"anchors\" in options;\n\n if (hasAnchors) {\n return new AnchoredColumnCollectionImpl(this.specDriver, {\n anchors: options.anchors,\n columns,\n });\n } else {\n return new ColumnCollectionImpl(this.specDriver, {\n columns,\n });\n }\n }\n}\n\n// --- ColumnCollectionImpl ---\n\ninterface ColumnCollectionImplOptions {\n readonly columns: ColumnSnapshot<PObjectId>[];\n}\n\nclass ColumnCollectionImpl implements ColumnCollection, Disposable {\n private readonly columns: Map<PObjectId, ColumnSnapshot<PObjectId>>;\n private readonly specFrameEntry: PoolEntry<SpecFrameHandle>;\n\n constructor(\n private readonly specDriver: PFrameSpecDriver,\n options: ColumnCollectionImplOptions,\n ) {\n this.columns = new Map(options.columns.map((col) => [col.id, col]));\n this.specFrameEntry = this.specDriver.createSpecFrame(\n Object.fromEntries(options.columns.map((col) => [col.id, col.spec])),\n );\n }\n\n dispose(): void {\n this.specFrameEntry.unref();\n }\n\n [Symbol.dispose](): void {\n this.dispose();\n }\n\n findColumns(options?: FindColumnsOptions): ColumnSnapshot<PObjectId>[] {\n const includeColumns = options?.include ? toMultiColumnSelectors(options.include) : undefined;\n const excludeColumns = options?.exclude ? toMultiColumnSelectors(options.exclude) : undefined;\n\n const response = this.specDriver.discoverColumns(this.specFrameEntry.key, {\n includeColumns,\n excludeColumns,\n axes: [],\n maxHops: 0,\n constraints: matchingModeToConstraints(\"enrichment\"),\n });\n\n // Map hits back to snapshots\n const results = response.hits\n .map((hit) => this.columns.get(hit.hit.columnId as PObjectId))\n .filter((col): col is ColumnSnapshot<PObjectId> => col !== undefined);\n\n return results;\n }\n}\n\n// --- AnchoredColumnCollectionImpl ---\n\ninterface AnchoredColumnCollectionImplOptions extends ColumnCollectionImplOptions {\n readonly anchors: Record<string, AnchorEntry>;\n}\n\nclass AnchoredColumnCollectionImpl implements AnchoredColumnCollection, Disposable {\n private readonly anchorsMap: Map<string, ColumnSnapshot<PObjectId>>;\n private readonly columnsMap: Map<PObjectId, ColumnSnapshot<PObjectId>>;\n private readonly specFrameEntry: PoolEntry<SpecFrameHandle>;\n\n constructor(\n private readonly specDriver: PFrameSpecDriver,\n options: AnchoredColumnCollectionImplOptions,\n ) {\n // Create spec frame from all collected columns\n this.specFrameEntry = this.specDriver.createSpecFrame(\n Object.fromEntries(options.columns.map((col) => [col.id, col.spec])),\n );\n this.columnsMap = new Map(options.columns.map((col) => [col.id, col]));\n this.anchorsMap = resolveAnchorMap(\n options.anchors,\n options.columns,\n this.specDriver.discoverColumns.bind(this.specDriver, this.specFrameEntry.key),\n );\n }\n\n dispose(): void {\n this.specFrameEntry.unref();\n }\n\n [Symbol.dispose](): void {\n this.dispose();\n }\n\n getAnchors(): Map<string, ColumnSnapshot<PObjectId>> {\n return this.anchorsMap;\n }\n\n findColumns(options?: AnchoredFindColumnsOptions): ColumnMatch[] {\n const mode = options?.mode ?? \"enrichment\";\n const constraints = matchingModeToConstraints(mode);\n const includeColumns = options?.include ? toMultiColumnSelectors(options.include) : undefined;\n const excludeColumns = options?.exclude ? toMultiColumnSelectors(options.exclude) : undefined;\n const anchors = Array.from(this.anchorsMap.values());\n const response = this.specDriver.discoverColumns(this.specFrameEntry.key, {\n includeColumns,\n excludeColumns,\n constraints,\n maxHops: options?.maxHops ?? 4,\n axes: anchors.map((anchor) => ({\n axesSpec: anchor.spec.axesSpec,\n qualifications: [],\n })),\n });\n\n const byColumn = response.hits.reduce<Map<PObjectId, ColumnMatch>>((acc, hit) => {\n const origId = hit.hit.columnId as PObjectId;\n const col =\n this.columnsMap.get(origId) ??\n throwError(`Column with id ${origId} not found in collection`);\n\n const path = hit.path.map((step) => {\n if (step.type !== \"linker\") {\n throw new Error(`Unexpected discover-columns step type: ${step.type}`);\n }\n\n return {\n linker:\n this.columnsMap.get(step.linker.columnId) ??\n throwError(`Linker column with id ${step.linker.columnId} not found in collection`),\n qualifications: step.qualifications,\n };\n });\n const variants: MatchVariant[] = hit.mappingVariants.map((v) => ({\n path,\n qualifications: remapFromIdxToId(v.qualifications, anchors),\n }));\n const existing = acc.get(origId);\n return acc.set(\n origId,\n existing === undefined\n ? { column: col, variants }\n : { ...existing, variants: [...existing.variants, ...variants] },\n );\n }, new Map());\n\n return Array.from(byColumn.values());\n }\n\n findColumnVariants(options?: AnchoredFindColumnsOptions): ColumnVariant[] {\n const matches = this.findColumns(options);\n return matches.flatMap((match) =>\n match.variants.map((variant) => ({\n column: match.column,\n path: variant.path,\n qualifications: variant.qualifications,\n })),\n );\n }\n}\n\n/**\n * Collect all columns from all providers, dedup by NativePObjectId.\n * First source wins.\n */\nfunction collectColumns(providers: ColumnSnapshotProvider[]): ColumnSnapshot<PObjectId>[] {\n const seen = new Set<NativePObjectId>();\n const result: ColumnSnapshot<PObjectId>[] = [];\n\n for (const provider of providers) {\n const columns = provider.getAllColumns();\n for (const col of columns) {\n const nativeId = deriveNativeId(col.spec);\n if (seen.has(nativeId)) continue;\n seen.add(nativeId);\n result.push(col);\n }\n }\n\n return result;\n}\n\n// --- Shared snapshot helpers ---\n\n/** Normalize ColumnSelector (relaxed, single or array) to MultiColumnSelector[]. */\nfunction toMultiColumnSelectors(input: ColumnSelector): MultiColumnSelector[] {\n return convertColumnSelectorToMultiColumnSelector(input);\n}\n\n// --- Anchor resolution ---\n\n/**\n * Resolve each anchor entry to a ColumnSnapshot from the collected columns.\n * - PObjectId (string): looked up by id in the collected columns\n * - PColumnSpec: matched by deriveNativeId against collected columns\n * - RelaxedColumnSelector: resolved via discoverColumns in \"exact\" mode;\n * must match exactly one column\n * Throws on unresolved, ambiguous, or duplicated matches. Requires at least one\n * anchor to resolve.\n */\nfunction resolveAnchorMap(\n anchors: Record<string, AnchorEntry>,\n columns: ColumnSnapshot<PObjectId>[],\n discoverColumns: (request: DiscoverColumnsRequest) => DiscoverColumnsResponse,\n): Map<string, ColumnSnapshot<PObjectId>> {\n const result = new Map<string, ColumnSnapshot<PObjectId>>();\n const resovedIds = new Set<PObjectId>();\n const getDuplicateError = (key: string) =>\n `Anchor \"${key}\": selector matched a column that was already matched by another anchor; please refine the selector to match a different column`;\n\n for (const [name, anchor] of Object.entries(anchors)) {\n if (typeof anchor === \"string\") {\n const found =\n columns.find((col) => col.id === anchor) ??\n throwError(`Anchor \"${name}\": column with id \"${anchor}\" not found in sources`);\n if (resovedIds.has(found.id)) {\n throwError(getDuplicateError(name));\n }\n result.set(name, found);\n resovedIds.add(found.id);\n } else if (\"kind\" in anchor) {\n if (!isPColumnSpec(anchor)) throwError(`Anchor \"${name}\": invalid PColumnSpec`);\n const nativeId = deriveNativeId(anchor);\n const found =\n columns.find((col) => deriveNativeId(col.spec) === nativeId) ??\n throwError(`Anchor \"${name}\": no column matching spec found in sources`);\n if (resovedIds.has(found.id)) {\n throwError(getDuplicateError(name));\n }\n result.set(name, found);\n resovedIds.add(found.id);\n } else {\n const matched = discoverColumns({\n includeColumns: toMultiColumnSelectors(anchor),\n excludeColumns: undefined,\n axes: [],\n maxHops: 0,\n constraints: matchingModeToConstraints(\"exact\"),\n });\n\n if (matched.hits.length === 0) {\n throwError(`Anchor \"${name}\": no columns matched selector`);\n }\n if (matched.hits.length > 1) {\n throwError(\n `Anchor \"${name}\": selector is ambiguous and matched multiple columns; please refine the selector to match exactly one column`,\n );\n }\n if (resovedIds.has(matched.hits[0].hit.columnId as PObjectId)) {\n throwError(getDuplicateError(name));\n }\n\n const id = matched.hits[0].hit.columnId as PObjectId;\n const snap =\n columns.find((col) => col.id === id) ??\n throwError(`Anchor \"${name}\": matched column with id \"${id}\" not found in sources`);\n result.set(name, snap);\n resovedIds.add(snap.id);\n }\n }\n\n if (resovedIds.size === 0) {\n throwError(\"At least one anchor must be resolved to a valid column\");\n }\n\n return result;\n}\n\nfunction remapFromIdxToId(\n qualifications: {\n forQueries: AxisQualification[][];\n forHit: AxisQualification[];\n },\n anchors: ColumnSnapshot<PObjectId>[],\n): MatchQualifications {\n const forQueries = qualifications.forQueries.reduce<Record<PObjectId, AxisQualification[]>>(\n (acc, qs, i) => (anchors[i] ? ((acc[anchors[i].id] = qs), acc) : acc),\n {},\n );\n return { forQueries, forHit: qualifications.forHit };\n}\n\n// --- MatchingMode → DiscoverColumnsConstraints ---\n\nfunction matchingModeToConstraints(mode: MatchingMode): DiscoverColumnsConstraints {\n switch (mode) {\n case \"enrichment\":\n return {\n allowFloatingSourceAxes: true,\n allowFloatingHitAxes: false,\n allowSourceQualifications: true,\n allowHitQualifications: true,\n };\n case \"related\":\n return {\n allowFloatingSourceAxes: true,\n allowFloatingHitAxes: true,\n allowSourceQualifications: true,\n allowHitQualifications: true,\n };\n case \"exact\":\n return {\n allowFloatingSourceAxes: false,\n allowFloatingHitAxes: false,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C;AAE7D,MAAI,QAAQ,KAAK,SAAS,EACxB,YACE,WAAW,KAAK,+GACjB;AAEH,MAAI,WAAW,IAAI,QAAQ,KAAK,GAAG,IAAI,SAAsB,CAC3D,YAAW,kBAAkB,KAAK,CAAC;EAGrC,MAAM,KAAK,QAAQ,KAAK,GAAG,IAAI;EAC/B,MAAM,OACJ,QAAQ,MAAM,QAAQ,IAAI,OAAO,GAAG,IACpC,WAAW,WAAW,KAAK,6BAA6B,GAAG,wBAAwB;AACrF,SAAO,IAAI,MAAM,KAAK;AACtB,aAAW,IAAI,KAAK,GAAG;;AAI3B,KAAI,WAAW,SAAS,EACtB,YAAW,yDAAyD;AAGtE,QAAO;;AAGT,SAAS,iBACP,gBAIA,SACqB;AAKrB,QAAO;EAAE,YAJU,eAAe,WAAW,QAC1C,KAAK,IAAI,MAAO,QAAQ,MAAO,IAAI,QAAQ,GAAG,MAAM,IAAK,OAAO,KACjE,EAAE,CACH;EACoB,QAAQ,eAAe;EAAQ;;AAKtD,SAAS,0BAA0B,MAAgD;AACjF,SAAQ,MAAR;EACE,KAAK,aACH,QAAO;GACL,yBAAyB;GACzB,sBAAsB;GACtB,2BAA2B;GAC3B,wBAAwB;GACzB;EACH,KAAK,UACH,QAAO;GACL,yBAAyB;GACzB,sBAAsB;GACtB,2BAA2B;GAC3B,wBAAwB;GACzB;EACH,KAAK,QACH,QAAO;GACL,yBAAyB;GACzB,sBAAsB;GACtB,2BAA2B;GAC3B,wBAAwB;GACzB"}
|
|
1
|
+
{"version":3,"file":"column_collection_builder.js","names":[],"sources":["../../src/columns/column_collection_builder.ts"],"sourcesContent":["import type {\n AxisQualification,\n DiscoverColumnsConstraints,\n DiscoverColumnsRequest,\n DiscoverColumnsResponse,\n MultiColumnSelector,\n NativePObjectId,\n PColumnSpec,\n PObjectId,\n} from \"@milaboratories/pl-model-common\";\nimport { deriveNativeId, isPColumnSpec } from \"@milaboratories/pl-model-common\";\nimport type { ColumnSelector, RelaxedColumnSelector } from \"./column_selector\";\nimport { convertColumnSelectorToMultiColumnSelector } from \"./column_selector\";\nimport { TreeNodeAccessor } from \"../render/accessor\";\nimport type { ColumnSnapshot } from \"./column_snapshot\";\nimport type { ColumnSnapshotProvider, ColumnSource } from \"./column_snapshot_provider\";\nimport { ArrayColumnProvider, toColumnSnapshotProvider } from \"./column_snapshot_provider\";\n\nimport type { PFrameSpecDriver, PoolEntry, SpecFrameHandle } from \"@milaboratories/pl-model-common\";\nimport { throwError } from \"@milaboratories/helpers\";\nimport { getService } from \"../services\";\n\n// --- FindColumnsOptions ---\n\n/** Options for plain collection findColumns. */\nexport interface FindColumnsOptions {\n /** Include columns matching these selectors. If omitted, includes all columns. */\n include?: ColumnSelector;\n /** Exclude columns matching these selectors. */\n exclude?: ColumnSelector;\n}\n\n// --- ColumnCollection ---\n\n/** Plain collection — no axis context, selector-based filtering only. */\nexport interface ColumnCollection extends Disposable {\n /** Release the underlying spec frame WASM resource. */\n dispose(): void;\n\n /** Find columns matching selectors. Returns flat list of snapshots.\n * No axis compatibility matching, no linker traversal.\n * Never returns undefined — the \"not ready\" state was absorbed by the builder. */\n findColumns(options?: FindColumnsOptions): ColumnSnapshot<PObjectId>[];\n}\n\n// --- AnchoredColumnCollection ---\n\n/** Axis-aware column collection with anchored identity derivation. */\nexport interface AnchoredColumnCollection extends Disposable {\n /** Release the underlying spec frame WASM resource. */\n dispose(): void;\n\n /** List of anchors used for discovery, with their resolved specs. */\n getAnchors(): Map<string, ColumnSnapshot<PObjectId>>;\n\n /** Axis-aware column discovery. */\n findColumns(options?: AnchoredFindColumnsOptions): ColumnMatch[];\n\n /** Variant discovery with detailed mapping info for each hit. */\n findColumnVariants(options?: AnchoredFindColumnsOptions): ColumnVariant[];\n}\n\n/** Controls axis matching behavior for anchored discovery. */\nexport type MatchingMode = \"enrichment\" | \"related\" | \"exact\";\n\n/** Options for anchored collection findColumns. */\nexport interface AnchoredFindColumnsOptions extends FindColumnsOptions {\n /** Controls axis matching behavior. Default: 'enrichment'. */\n mode?: MatchingMode;\n /** Maximum linker hops for cross-domain discovery (0 = direct only, default: 4). */\n maxHops?: number;\n}\n\n/** Result of anchored discovery — column snapshot + routing info. */\nexport interface ColumnMatch {\n /** Column snapshot with anchored SUniversalPColumnId. */\n readonly column: ColumnSnapshot<PObjectId>;\n /** Match variants — different ways (paths/qualifications) to reach this column. */\n readonly variants: MatchVariant[];\n}\n\nexport interface ColumnVariant<Id extends PObjectId = PObjectId> {\n /** Column snapshot with anchored SUniversalPColumnId. */\n readonly column: ColumnSnapshot<Id>;\n /** Full qualifications needed for integration. */\n readonly qualifications: MatchQualifications;\n /** Linker steps traversed to reach this hit; empty for direct matches. */\n readonly path: {\n linker: ColumnSnapshot<PObjectId>;\n }[];\n}\n\n/** A single mapping variant describing how a hit column can be integrated. */\nexport interface MatchVariant {\n /** Full qualifications needed for integration. */\n readonly qualifications: MatchQualifications;\n /** Linker steps traversed to reach this hit; empty for direct matches. */\n readonly path: {\n linker: ColumnSnapshot<PObjectId>;\n }[];\n}\n\n/** Qualifications needed for both already-integrated anchor columns and the hit column. */\nexport interface MatchQualifications {\n /** Qualifications for already-integrated anchor columns */\n readonly forQueries: Record<PObjectId, AxisQualification[]>;\n /** Qualifications for the hit column. */\n readonly forHit: AxisQualification[];\n}\n\n// --- Build options ---\n\nexport interface BuildOptions {\n allowPartialColumnList?: true;\n}\n\nexport type AnchorEntry = PObjectId | PColumnSpec | RelaxedColumnSelector;\n\nexport interface AnchoredBuildOptions extends BuildOptions {\n anchors: Record<string, AnchorEntry>;\n}\n\n// --- ColumnCollectionBuilder ---\n\n/**\n * Mutable builder that accumulates column sources, then produces\n * a ColumnCollection (plain) or AnchoredColumnCollection (with anchors).\n *\n * Each output lambda creates its own builder — a constraint of the\n * computable framework where each output tracks its own dependencies.\n */\nexport class ColumnCollectionBuilder {\n private readonly providers: ColumnSnapshotProvider[] = [];\n\n constructor(private readonly specDriver: PFrameSpecDriver = getService(\"pframeSpec\")) {}\n\n /**\n * Register a column source. Sources added first take precedence for dedup.\n * Does NOT accept undefined — if a source isn't available yet,\n * the caller should return undefined from the output lambda.\n */\n addSource(source: ColumnSource | TreeNodeAccessor): this {\n if (source instanceof TreeNodeAccessor) {\n const columns = source.getPColumns();\n if (columns) this.providers.push(new ArrayColumnProvider(columns));\n } else {\n this.providers.push(toColumnSnapshotProvider(source));\n }\n return this;\n }\n\n addSources(sources: (ColumnSource | TreeNodeAccessor)[]): this {\n for (const source of sources) {\n this.addSource(source);\n }\n return this;\n }\n\n /** Plain collection — selector-based filtering, PObjectId namespace. */\n build(): undefined | ColumnCollection;\n build(options: {\n allowPartialColumnList: true;\n }): ColumnCollection & { readonly columnListComplete: boolean };\n /** Anchored collection — axis-aware discovery, SUniversalPColumnId namespace. */\n build(\n options: AnchoredBuildOptions & { allowPartialColumnList: true },\n ): AnchoredColumnCollection & { readonly columnListComplete: boolean };\n build(options: AnchoredBuildOptions): undefined | AnchoredColumnCollection;\n build(\n options?: BuildOptions | AnchoredBuildOptions,\n ):\n | undefined\n | ColumnCollection\n | AnchoredColumnCollection\n | (ColumnCollection & { readonly columnListComplete: boolean })\n | (AnchoredColumnCollection & { readonly columnListComplete: boolean }) {\n const allowPartial = options?.allowPartialColumnList === true;\n\n // Check column list completeness\n const allComplete = this.providers.every((p) => p.isColumnListComplete());\n if (!allComplete && !allowPartial) return undefined;\n\n // Collect all columns, dedup by native ID (first source wins)\n const columns = collectColumns(this.providers);\n const hasAnchors = options !== undefined && \"anchors\" in options;\n\n if (hasAnchors) {\n return new AnchoredColumnCollectionImpl(this.specDriver, {\n anchors: options.anchors,\n columns,\n });\n } else {\n return new ColumnCollectionImpl(this.specDriver, {\n columns,\n });\n }\n }\n}\n\n// --- ColumnCollectionImpl ---\n\ninterface ColumnCollectionImplOptions {\n readonly columns: ColumnSnapshot<PObjectId>[];\n}\n\nclass ColumnCollectionImpl implements ColumnCollection, Disposable {\n private readonly columns: Map<PObjectId, ColumnSnapshot<PObjectId>>;\n private readonly specFrameEntry: PoolEntry<SpecFrameHandle>;\n\n constructor(\n private readonly specDriver: PFrameSpecDriver,\n options: ColumnCollectionImplOptions,\n ) {\n this.columns = new Map(options.columns.map((col) => [col.id, col]));\n this.specFrameEntry = this.specDriver.createSpecFrame(\n Object.fromEntries(options.columns.map((col) => [col.id, col.spec])),\n );\n }\n\n dispose(): void {\n this.specFrameEntry.unref();\n }\n\n [Symbol.dispose](): void {\n this.dispose();\n }\n\n findColumns(options?: FindColumnsOptions): ColumnSnapshot<PObjectId>[] {\n const includeColumns = options?.include ? toMultiColumnSelectors(options.include) : undefined;\n const excludeColumns = options?.exclude ? toMultiColumnSelectors(options.exclude) : undefined;\n\n const response = this.specDriver.discoverColumns(this.specFrameEntry.key, {\n includeColumns,\n excludeColumns,\n axes: [],\n maxHops: 0,\n constraints: matchingModeToConstraints(\"enrichment\"),\n });\n\n // Map hits back to snapshots\n const results = response.hits\n .map((hit) => this.columns.get(hit.hit.columnId as PObjectId))\n .filter((col): col is ColumnSnapshot<PObjectId> => col !== undefined);\n\n return results;\n }\n}\n\n// --- AnchoredColumnCollectionImpl ---\n\ninterface AnchoredColumnCollectionImplOptions extends ColumnCollectionImplOptions {\n readonly anchors: Record<string, AnchorEntry>;\n}\n\nclass AnchoredColumnCollectionImpl implements AnchoredColumnCollection, Disposable {\n private readonly anchorsMap: Map<string, ColumnSnapshot<PObjectId>>;\n private readonly columnsMap: Map<PObjectId, ColumnSnapshot<PObjectId>>;\n private readonly specFrameEntry: PoolEntry<SpecFrameHandle>;\n\n constructor(\n private readonly specDriver: PFrameSpecDriver,\n options: AnchoredColumnCollectionImplOptions,\n ) {\n // Create spec frame from all collected columns\n this.specFrameEntry = this.specDriver.createSpecFrame(\n Object.fromEntries(options.columns.map((col) => [col.id, col.spec])),\n );\n this.columnsMap = new Map(options.columns.map((col) => [col.id, col]));\n this.anchorsMap = resolveAnchorMap(\n options.anchors,\n options.columns,\n this.specDriver.discoverColumns.bind(this.specDriver, this.specFrameEntry.key),\n );\n }\n\n dispose(): void {\n this.specFrameEntry.unref();\n }\n\n [Symbol.dispose](): void {\n this.dispose();\n }\n\n getAnchors(): Map<string, ColumnSnapshot<PObjectId>> {\n return this.anchorsMap;\n }\n\n findColumns(options?: AnchoredFindColumnsOptions): ColumnMatch[] {\n const mode = options?.mode ?? \"enrichment\";\n const constraints = matchingModeToConstraints(mode);\n const includeColumns = options?.include ? toMultiColumnSelectors(options.include) : undefined;\n const excludeColumns = options?.exclude ? toMultiColumnSelectors(options.exclude) : undefined;\n const anchors = Array.from(this.anchorsMap.values());\n const response = this.specDriver.discoverColumns(this.specFrameEntry.key, {\n includeColumns,\n excludeColumns,\n constraints,\n maxHops: options?.maxHops ?? 4,\n axes: anchors.map((anchor) => ({\n axesSpec: anchor.spec.axesSpec,\n qualifications: [],\n })),\n });\n\n const byColumn = response.hits.reduce<Map<PObjectId, ColumnMatch>>((acc, hit) => {\n const origId = hit.hit.columnId as PObjectId;\n const col =\n this.columnsMap.get(origId) ??\n throwError(`Column with id ${origId} not found in collection`);\n\n const path = hit.path.map((step) => {\n if (step.type !== \"linker\") {\n throw new Error(`Unexpected discover-columns step type: ${step.type}`);\n }\n\n return {\n linker:\n this.columnsMap.get(step.linker.columnId) ??\n throwError(`Linker column with id ${step.linker.columnId} not found in collection`),\n };\n });\n const variants: MatchVariant[] = hit.mappingVariants.map((v) => ({\n path,\n qualifications: remapFromIdxToId(v.qualifications, anchors),\n }));\n const existing = acc.get(origId);\n return acc.set(\n origId,\n existing === undefined\n ? { column: col, variants }\n : { ...existing, variants: [...existing.variants, ...variants] },\n );\n }, new Map());\n\n return Array.from(byColumn.values());\n }\n\n findColumnVariants(options?: AnchoredFindColumnsOptions): ColumnVariant[] {\n const matches = this.findColumns(options);\n return matches.flatMap((match) =>\n match.variants.map((variant) => ({\n column: match.column,\n path: variant.path,\n qualifications: variant.qualifications,\n })),\n );\n }\n}\n\n/**\n * Collect all columns from all providers, dedup by NativePObjectId.\n * First source wins.\n */\nfunction collectColumns(providers: ColumnSnapshotProvider[]): ColumnSnapshot<PObjectId>[] {\n const seen = new Set<NativePObjectId>();\n const result: ColumnSnapshot<PObjectId>[] = [];\n\n for (const provider of providers) {\n const columns = provider.getAllColumns();\n for (const col of columns) {\n const nativeId = deriveNativeId(col.spec);\n if (seen.has(nativeId)) continue;\n seen.add(nativeId);\n result.push(col);\n }\n }\n\n return result;\n}\n\n// --- Shared snapshot helpers ---\n\n/** Normalize ColumnSelector (relaxed, single or array) to MultiColumnSelector[]. */\nfunction toMultiColumnSelectors(input: ColumnSelector): MultiColumnSelector[] {\n return convertColumnSelectorToMultiColumnSelector(input);\n}\n\n// --- Anchor resolution ---\n\n/**\n * Resolve each anchor entry to a ColumnSnapshot from the collected columns.\n * - PObjectId (string): looked up by id in the collected columns\n * - PColumnSpec: matched by deriveNativeId against collected columns\n * - RelaxedColumnSelector: resolved via discoverColumns in \"exact\" mode;\n * must match exactly one column\n * Throws on unresolved, ambiguous, or duplicated matches. Requires at least one\n * anchor to resolve.\n */\nfunction resolveAnchorMap(\n anchors: Record<string, AnchorEntry>,\n columns: ColumnSnapshot<PObjectId>[],\n discoverColumns: (request: DiscoverColumnsRequest) => DiscoverColumnsResponse,\n): Map<string, ColumnSnapshot<PObjectId>> {\n const result = new Map<string, ColumnSnapshot<PObjectId>>();\n const resovedIds = new Set<PObjectId>();\n const getDuplicateError = (key: string) =>\n `Anchor \"${key}\": selector matched a column that was already matched by another anchor; please refine the selector to match a different column`;\n\n for (const [name, anchor] of Object.entries(anchors)) {\n if (typeof anchor === \"string\") {\n const found =\n columns.find((col) => col.id === anchor) ??\n throwError(`Anchor \"${name}\": column with id \"${anchor}\" not found in sources`);\n if (resovedIds.has(found.id)) {\n throwError(getDuplicateError(name));\n }\n result.set(name, found);\n resovedIds.add(found.id);\n } else if (\"kind\" in anchor) {\n if (!isPColumnSpec(anchor)) throwError(`Anchor \"${name}\": invalid PColumnSpec`);\n const nativeId = deriveNativeId(anchor);\n const found =\n columns.find((col) => deriveNativeId(col.spec) === nativeId) ??\n throwError(`Anchor \"${name}\": no column matching spec found in sources`);\n if (resovedIds.has(found.id)) {\n throwError(getDuplicateError(name));\n }\n result.set(name, found);\n resovedIds.add(found.id);\n } else {\n const matched = discoverColumns({\n includeColumns: toMultiColumnSelectors(anchor),\n excludeColumns: undefined,\n axes: [],\n maxHops: 0,\n constraints: matchingModeToConstraints(\"exact\"),\n });\n\n if (matched.hits.length === 0) {\n throwError(`Anchor \"${name}\": no columns matched selector`);\n }\n if (matched.hits.length > 1) {\n throwError(\n `Anchor \"${name}\": selector is ambiguous and matched multiple columns; please refine the selector to match exactly one column`,\n );\n }\n if (resovedIds.has(matched.hits[0].hit.columnId as PObjectId)) {\n throwError(getDuplicateError(name));\n }\n\n const id = matched.hits[0].hit.columnId as PObjectId;\n const snap =\n columns.find((col) => col.id === id) ??\n throwError(`Anchor \"${name}\": matched column with id \"${id}\" not found in sources`);\n result.set(name, snap);\n resovedIds.add(snap.id);\n }\n }\n\n if (resovedIds.size === 0) {\n throwError(\"At least one anchor must be resolved to a valid column\");\n }\n\n return result;\n}\n\nfunction remapFromIdxToId(\n qualifications: {\n forQueries: AxisQualification[][];\n forHit: AxisQualification[];\n },\n anchors: ColumnSnapshot<PObjectId>[],\n): MatchQualifications {\n const forQueries = qualifications.forQueries.reduce<Record<PObjectId, AxisQualification[]>>(\n (acc, qs, i) => (anchors[i] ? ((acc[anchors[i].id] = qs), acc) : acc),\n {},\n );\n return { forQueries, forHit: qualifications.forHit };\n}\n\n// --- MatchingMode → DiscoverColumnsConstraints ---\n\nfunction matchingModeToConstraints(mode: MatchingMode): DiscoverColumnsConstraints {\n switch (mode) {\n case \"enrichment\":\n return {\n allowFloatingSourceAxes: true,\n allowFloatingHitAxes: false,\n allowSourceQualifications: true,\n allowHitQualifications: true,\n };\n case \"related\":\n return {\n allowFloatingSourceAxes: true,\n allowFloatingHitAxes: true,\n allowSourceQualifications: true,\n allowHitQualifications: true,\n };\n case \"exact\":\n return {\n allowF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,KAAK,gCAAgC;AAE7D,MAAI,QAAQ,KAAK,SAAS,EACxB,YACE,WAAW,KAAK,+GACjB;AAEH,MAAI,WAAW,IAAI,QAAQ,KAAK,GAAG,IAAI,SAAsB,CAC3D,YAAW,kBAAkB,KAAK,CAAC;EAGrC,MAAM,KAAK,QAAQ,KAAK,GAAG,IAAI;EAC/B,MAAM,OACJ,QAAQ,MAAM,QAAQ,IAAI,OAAO,GAAG,IACpC,WAAW,WAAW,KAAK,6BAA6B,GAAG,wBAAwB;AACrF,SAAO,IAAI,MAAM,KAAK;AACtB,aAAW,IAAI,KAAK,GAAG;;AAI3B,KAAI,WAAW,SAAS,EACtB,YAAW,yDAAyD;AAGtE,QAAO;;AAGT,SAAS,iBACP,gBAIA,SACqB;AAKrB,QAAO;EAAE,YAJU,eAAe,WAAW,QAC1C,KAAK,IAAI,MAAO,QAAQ,MAAO,IAAI,QAAQ,GAAG,MAAM,IAAK,OAAO,KACjE,EAAE,CACH;EACoB,QAAQ,eAAe;EAAQ;;AAKtD,SAAS,0BAA0B,MAAgD;AACjF,SAAQ,MAAR;EACE,KAAK,aACH,QAAO;GACL,yBAAyB;GACzB,sBAAsB;GACtB,2BAA2B;GAC3B,wBAAwB;GACzB;EACH,KAAK,UACH,QAAO;GACL,yBAAyB;GACzB,sBAAsB;GACtB,2BAA2B;GAC3B,wBAAwB;GACzB;EACH,KAAK,QACH,QAAO;GACL,yBAAyB;GACzB,sBAAsB;GACtB,2BAA2B;GAC3B,wBAAwB;GACzB"}
|
|
@@ -3,21 +3,18 @@ const require_column_snapshot_provider = require("./column_snapshot_provider.cjs
|
|
|
3
3
|
let _milaboratories_pl_model_common = require("@milaboratories/pl-model-common");
|
|
4
4
|
//#region src/columns/ctx_column_sources.ts
|
|
5
5
|
/**
|
|
6
|
-
* Collect ColumnSnapshotProviders from
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
* - **prerun** — PFrame fields from prerun/staging results
|
|
11
|
-
*
|
|
12
|
-
* Returns an array of providers suitable for `ColumnCollectionBuilder.addSource()`.
|
|
6
|
+
* Collect ColumnSnapshotProviders from `outputs`, `prerun`, and
|
|
7
|
+
* `resultPool` in that order. Dedup keeps the first occurrence per
|
|
8
|
+
* `NativePObjectId`, so a block re-publishing its own columns keeps
|
|
9
|
+
* the `outputs`-rooted canonical id instead of the result-pool variant.
|
|
13
10
|
*/
|
|
14
11
|
function collectCtxColumnSnapshotProviders(ctx) {
|
|
15
12
|
const providers = [];
|
|
16
|
-
providers.push(new ResultPoolColumnSnapshotProvider(ctx.resultPool));
|
|
17
13
|
const outputs = ctx.outputs;
|
|
18
14
|
if (outputs) providers.push(...collectPFrameProviders(outputs));
|
|
19
15
|
const prerun = ctx.prerun;
|
|
20
16
|
if (prerun) providers.push(...collectPFrameProviders(prerun));
|
|
17
|
+
providers.push(new ResultPoolColumnSnapshotProvider(ctx.resultPool));
|
|
21
18
|
return providers;
|
|
22
19
|
}
|
|
23
20
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ctx_column_sources.cjs","names":["ResourceTypeName","OutputColumnProvider"],"sources":["../../src/columns/ctx_column_sources.ts"],"sourcesContent":["import type { PColumnSpec, PObjectId } from \"@milaboratories/pl-model-common\";\nimport { TreeNodeAccessor } from \"../render/accessor\";\nimport type { RenderCtxBase, ResultPool } from \"../render\";\nimport type { ColumnSnapshot } from \"./column_snapshot\";\nimport type { ColumnDataStatus } from \"./column_snapshot\";\nimport type { ColumnSnapshotProvider } from \"./column_snapshot_provider\";\nimport { OutputColumnProvider } from \"./column_snapshot_provider\";\nimport { ResourceTypeName } from \"@milaboratories/pl-model-common\";\nimport type { ValueOf } from \"@milaboratories/helpers\";\n\n/**\n * Collect ColumnSnapshotProviders from
|
|
1
|
+
{"version":3,"file":"ctx_column_sources.cjs","names":["ResourceTypeName","OutputColumnProvider"],"sources":["../../src/columns/ctx_column_sources.ts"],"sourcesContent":["import type { PColumnSpec, PObjectId } from \"@milaboratories/pl-model-common\";\nimport { TreeNodeAccessor } from \"../render/accessor\";\nimport type { RenderCtxBase, ResultPool } from \"../render\";\nimport type { ColumnSnapshot } from \"./column_snapshot\";\nimport type { ColumnDataStatus } from \"./column_snapshot\";\nimport type { ColumnSnapshotProvider } from \"./column_snapshot_provider\";\nimport { OutputColumnProvider } from \"./column_snapshot_provider\";\nimport { ResourceTypeName } from \"@milaboratories/pl-model-common\";\nimport type { ValueOf } from \"@milaboratories/helpers\";\n\n/**\n * Collect ColumnSnapshotProviders from `outputs`, `prerun`, and\n * `resultPool` in that order. Dedup keeps the first occurrence per\n * `NativePObjectId`, so a block re-publishing its own columns keeps\n * the `outputs`-rooted canonical id instead of the result-pool variant.\n */\nexport function collectCtxColumnSnapshotProviders(ctx: RenderCtxBase): ColumnSnapshotProvider[] {\n const providers: ColumnSnapshotProvider[] = [];\n\n const outputs = ctx.outputs;\n if (outputs) {\n providers.push(...collectPFrameProviders(outputs));\n }\n\n const prerun = ctx.prerun;\n if (prerun) {\n providers.push(...collectPFrameProviders(prerun));\n }\n\n providers.push(new ResultPoolColumnSnapshotProvider(ctx.resultPool));\n\n return providers;\n}\n\n/**\n * Adapter wrapping ResultPool into the new ColumnSnapshotProvider interface.\n *\n * - `isColumnListComplete()` always returns true — the result pool\n * is a stable snapshot within a single render cycle.\n * - Data status is derived from the underlying TreeNodeAccessor:\n * ready (getIsReadyOrError), computing, or absent (no data resource).\n */\nexport class ResultPoolColumnSnapshotProvider implements ColumnSnapshotProvider {\n constructor(private readonly pool: ResultPool) {}\n\n getAllColumns(): ColumnSnapshot<PObjectId>[] {\n const pColumns = this.pool.selectColumns(() => true);\n return pColumns.map((col) => toSnapshot(col.id, col.spec, col.data));\n }\n\n isColumnListComplete(): boolean {\n return true;\n }\n}\n\nfunction toSnapshot(\n id: PObjectId,\n spec: PColumnSpec,\n accessor: TreeNodeAccessor | undefined,\n): ColumnSnapshot<PObjectId> {\n if (accessor === undefined) {\n return { id, spec, dataStatus: \"absent\" as ColumnDataStatus, data: undefined };\n }\n const isReady = accessor.getIsReadyOrError();\n return {\n id,\n spec,\n dataStatus: (isReady ? \"ready\" : \"computing\") as ColumnDataStatus,\n data: { get: () => (isReady ? accessor : undefined) },\n };\n}\n\n/**\n * Recursively walk the output tree starting from `accessor`.\n * - If a node's resourceType is PFrame → wrap it as OutputColumnProvider.\n * - If a node's resourceType is StdMap/std/map → recurse into its output fields.\n * - Otherwise → skip (leaf of unknown type).\n */\nfunction collectPFrameProviders(accessor: TreeNodeAccessor): ColumnSnapshotProvider[] {\n const out: ColumnSnapshotProvider[] = [];\n walkTree(accessor, out);\n return out;\n}\n\nfunction walkTree(node: TreeNodeAccessor, out: ColumnSnapshotProvider[]): void {\n const typeName = node.resourceType.name as ValueOf<typeof ResourceTypeName>;\n\n if (typeName === ResourceTypeName.PFrame) {\n out.push(new OutputColumnProvider(node));\n return;\n }\n\n if (typeName === ResourceTypeName.StdMap || typeName === ResourceTypeName.StdMapSlash) {\n for (const field of node.listInputFields()) {\n const child = node.resolve(field);\n if (child) walkTree(child, out);\n }\n }\n}\n"],"mappings":";;;;;;;;;;AAgBA,SAAgB,kCAAkC,KAA8C;CAC9F,MAAM,YAAsC,EAAE;CAE9C,MAAM,UAAU,IAAI;AACpB,KAAI,QACF,WAAU,KAAK,GAAG,uBAAuB,QAAQ,CAAC;CAGpD,MAAM,SAAS,IAAI;AACnB,KAAI,OACF,WAAU,KAAK,GAAG,uBAAuB,OAAO,CAAC;AAGnD,WAAU,KAAK,IAAI,iCAAiC,IAAI,WAAW,CAAC;AAEpE,QAAO;;;;;;;;;;AAWT,IAAa,mCAAb,MAAgF;CAC9E,YAAY,MAAmC;AAAlB,OAAA,OAAA;;CAE7B,gBAA6C;AAE3C,SADiB,KAAK,KAAK,oBAAoB,KAAK,CACpC,KAAK,QAAQ,WAAW,IAAI,IAAI,IAAI,MAAM,IAAI,KAAK,CAAC;;CAGtE,uBAAgC;AAC9B,SAAO;;;AAIX,SAAS,WACP,IACA,MACA,UAC2B;AAC3B,KAAI,aAAa,KAAA,EACf,QAAO;EAAE;EAAI;EAAM,YAAY;EAA8B,MAAM,KAAA;EAAW;CAEhF,MAAM,UAAU,SAAS,mBAAmB;AAC5C,QAAO;EACL;EACA;EACA,YAAa,UAAU,UAAU;EACjC,MAAM,EAAE,WAAY,UAAU,WAAW,KAAA,GAAY;EACtD;;;;;;;;AASH,SAAS,uBAAuB,UAAsD;CACpF,MAAM,MAAgC,EAAE;AACxC,UAAS,UAAU,IAAI;AACvB,QAAO;;AAGT,SAAS,SAAS,MAAwB,KAAqC;CAC7E,MAAM,WAAW,KAAK,aAAa;AAEnC,KAAI,aAAaA,gCAAAA,iBAAiB,QAAQ;AACxC,MAAI,KAAK,IAAIC,iCAAAA,qBAAqB,KAAK,CAAC;AACxC;;AAGF,KAAI,aAAaD,gCAAAA,iBAAiB,UAAU,aAAaA,gCAAAA,iBAAiB,YACxE,MAAK,MAAM,SAAS,KAAK,iBAAiB,EAAE;EAC1C,MAAM,QAAQ,KAAK,QAAQ,MAAM;AACjC,MAAI,MAAO,UAAS,OAAO,IAAI"}
|
|
@@ -5,13 +5,10 @@ import { PObjectId } from "@milaboratories/pl-model-common";
|
|
|
5
5
|
|
|
6
6
|
//#region src/columns/ctx_column_sources.d.ts
|
|
7
7
|
/**
|
|
8
|
-
* Collect ColumnSnapshotProviders from
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
* - **prerun** — PFrame fields from prerun/staging results
|
|
13
|
-
*
|
|
14
|
-
* Returns an array of providers suitable for `ColumnCollectionBuilder.addSource()`.
|
|
8
|
+
* Collect ColumnSnapshotProviders from `outputs`, `prerun`, and
|
|
9
|
+
* `resultPool` in that order. Dedup keeps the first occurrence per
|
|
10
|
+
* `NativePObjectId`, so a block re-publishing its own columns keeps
|
|
11
|
+
* the `outputs`-rooted canonical id instead of the result-pool variant.
|
|
15
12
|
*/
|
|
16
13
|
declare function collectCtxColumnSnapshotProviders(ctx: RenderCtxBase): ColumnSnapshotProvider[];
|
|
17
14
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ctx_column_sources.d.ts","names":[],"sources":["../../src/columns/ctx_column_sources.ts"],"mappings":";;;;;;;;;
|
|
1
|
+
{"version":3,"file":"ctx_column_sources.d.ts","names":[],"sources":["../../src/columns/ctx_column_sources.ts"],"mappings":";;;;;;;;;AAgBA;;;iBAAgB,iCAAA,CAAkC,GAAA,EAAK,aAAA,GAAgB,sBAAA;;;;;;AA0BvE;;;cAAa,gCAAA,YAA4C,sBAAA;EAAA,iBAC1B,IAAA;cAAA,IAAA,EAAM,UAAA;EAEnC,aAAA,CAAA,GAAiB,cAAA,CAAe,SAAA;EAKhC,oBAAA,CAAA;AAAA"}
|
|
@@ -2,21 +2,18 @@ import { OutputColumnProvider } from "./column_snapshot_provider.js";
|
|
|
2
2
|
import { ResourceTypeName } from "@milaboratories/pl-model-common";
|
|
3
3
|
//#region src/columns/ctx_column_sources.ts
|
|
4
4
|
/**
|
|
5
|
-
* Collect ColumnSnapshotProviders from
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
* - **prerun** — PFrame fields from prerun/staging results
|
|
10
|
-
*
|
|
11
|
-
* Returns an array of providers suitable for `ColumnCollectionBuilder.addSource()`.
|
|
5
|
+
* Collect ColumnSnapshotProviders from `outputs`, `prerun`, and
|
|
6
|
+
* `resultPool` in that order. Dedup keeps the first occurrence per
|
|
7
|
+
* `NativePObjectId`, so a block re-publishing its own columns keeps
|
|
8
|
+
* the `outputs`-rooted canonical id instead of the result-pool variant.
|
|
12
9
|
*/
|
|
13
10
|
function collectCtxColumnSnapshotProviders(ctx) {
|
|
14
11
|
const providers = [];
|
|
15
|
-
providers.push(new ResultPoolColumnSnapshotProvider(ctx.resultPool));
|
|
16
12
|
const outputs = ctx.outputs;
|
|
17
13
|
if (outputs) providers.push(...collectPFrameProviders(outputs));
|
|
18
14
|
const prerun = ctx.prerun;
|
|
19
15
|
if (prerun) providers.push(...collectPFrameProviders(prerun));
|
|
16
|
+
providers.push(new ResultPoolColumnSnapshotProvider(ctx.resultPool));
|
|
20
17
|
return providers;
|
|
21
18
|
}
|
|
22
19
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ctx_column_sources.js","names":[],"sources":["../../src/columns/ctx_column_sources.ts"],"sourcesContent":["import type { PColumnSpec, PObjectId } from \"@milaboratories/pl-model-common\";\nimport { TreeNodeAccessor } from \"../render/accessor\";\nimport type { RenderCtxBase, ResultPool } from \"../render\";\nimport type { ColumnSnapshot } from \"./column_snapshot\";\nimport type { ColumnDataStatus } from \"./column_snapshot\";\nimport type { ColumnSnapshotProvider } from \"./column_snapshot_provider\";\nimport { OutputColumnProvider } from \"./column_snapshot_provider\";\nimport { ResourceTypeName } from \"@milaboratories/pl-model-common\";\nimport type { ValueOf } from \"@milaboratories/helpers\";\n\n/**\n * Collect ColumnSnapshotProviders from
|
|
1
|
+
{"version":3,"file":"ctx_column_sources.js","names":[],"sources":["../../src/columns/ctx_column_sources.ts"],"sourcesContent":["import type { PColumnSpec, PObjectId } from \"@milaboratories/pl-model-common\";\nimport { TreeNodeAccessor } from \"../render/accessor\";\nimport type { RenderCtxBase, ResultPool } from \"../render\";\nimport type { ColumnSnapshot } from \"./column_snapshot\";\nimport type { ColumnDataStatus } from \"./column_snapshot\";\nimport type { ColumnSnapshotProvider } from \"./column_snapshot_provider\";\nimport { OutputColumnProvider } from \"./column_snapshot_provider\";\nimport { ResourceTypeName } from \"@milaboratories/pl-model-common\";\nimport type { ValueOf } from \"@milaboratories/helpers\";\n\n/**\n * Collect ColumnSnapshotProviders from `outputs`, `prerun`, and\n * `resultPool` in that order. Dedup keeps the first occurrence per\n * `NativePObjectId`, so a block re-publishing its own columns keeps\n * the `outputs`-rooted canonical id instead of the result-pool variant.\n */\nexport function collectCtxColumnSnapshotProviders(ctx: RenderCtxBase): ColumnSnapshotProvider[] {\n const providers: ColumnSnapshotProvider[] = [];\n\n const outputs = ctx.outputs;\n if (outputs) {\n providers.push(...collectPFrameProviders(outputs));\n }\n\n const prerun = ctx.prerun;\n if (prerun) {\n providers.push(...collectPFrameProviders(prerun));\n }\n\n providers.push(new ResultPoolColumnSnapshotProvider(ctx.resultPool));\n\n return providers;\n}\n\n/**\n * Adapter wrapping ResultPool into the new ColumnSnapshotProvider interface.\n *\n * - `isColumnListComplete()` always returns true — the result pool\n * is a stable snapshot within a single render cycle.\n * - Data status is derived from the underlying TreeNodeAccessor:\n * ready (getIsReadyOrError), computing, or absent (no data resource).\n */\nexport class ResultPoolColumnSnapshotProvider implements ColumnSnapshotProvider {\n constructor(private readonly pool: ResultPool) {}\n\n getAllColumns(): ColumnSnapshot<PObjectId>[] {\n const pColumns = this.pool.selectColumns(() => true);\n return pColumns.map((col) => toSnapshot(col.id, col.spec, col.data));\n }\n\n isColumnListComplete(): boolean {\n return true;\n }\n}\n\nfunction toSnapshot(\n id: PObjectId,\n spec: PColumnSpec,\n accessor: TreeNodeAccessor | undefined,\n): ColumnSnapshot<PObjectId> {\n if (accessor === undefined) {\n return { id, spec, dataStatus: \"absent\" as ColumnDataStatus, data: undefined };\n }\n const isReady = accessor.getIsReadyOrError();\n return {\n id,\n spec,\n dataStatus: (isReady ? \"ready\" : \"computing\") as ColumnDataStatus,\n data: { get: () => (isReady ? accessor : undefined) },\n };\n}\n\n/**\n * Recursively walk the output tree starting from `accessor`.\n * - If a node's resourceType is PFrame → wrap it as OutputColumnProvider.\n * - If a node's resourceType is StdMap/std/map → recurse into its output fields.\n * - Otherwise → skip (leaf of unknown type).\n */\nfunction collectPFrameProviders(accessor: TreeNodeAccessor): ColumnSnapshotProvider[] {\n const out: ColumnSnapshotProvider[] = [];\n walkTree(accessor, out);\n return out;\n}\n\nfunction walkTree(node: TreeNodeAccessor, out: ColumnSnapshotProvider[]): void {\n const typeName = node.resourceType.name as ValueOf<typeof ResourceTypeName>;\n\n if (typeName === ResourceTypeName.PFrame) {\n out.push(new OutputColumnProvider(node));\n return;\n }\n\n if (typeName === ResourceTypeName.StdMap || typeName === ResourceTypeName.StdMapSlash) {\n for (const field of node.listInputFields()) {\n const child = node.resolve(field);\n if (child) walkTree(child, out);\n }\n }\n}\n"],"mappings":";;;;;;;;;AAgBA,SAAgB,kCAAkC,KAA8C;CAC9F,MAAM,YAAsC,EAAE;CAE9C,MAAM,UAAU,IAAI;AACpB,KAAI,QACF,WAAU,KAAK,GAAG,uBAAuB,QAAQ,CAAC;CAGpD,MAAM,SAAS,IAAI;AACnB,KAAI,OACF,WAAU,KAAK,GAAG,uBAAuB,OAAO,CAAC;AAGnD,WAAU,KAAK,IAAI,iCAAiC,IAAI,WAAW,CAAC;AAEpE,QAAO;;;;;;;;;;AAWT,IAAa,mCAAb,MAAgF;CAC9E,YAAY,MAAmC;AAAlB,OAAA,OAAA;;CAE7B,gBAA6C;AAE3C,SADiB,KAAK,KAAK,oBAAoB,KAAK,CACpC,KAAK,QAAQ,WAAW,IAAI,IAAI,IAAI,MAAM,IAAI,KAAK,CAAC;;CAGtE,uBAAgC;AAC9B,SAAO;;;AAIX,SAAS,WACP,IACA,MACA,UAC2B;AAC3B,KAAI,aAAa,KAAA,EACf,QAAO;EAAE;EAAI;EAAM,YAAY;EAA8B,MAAM,KAAA;EAAW;CAEhF,MAAM,UAAU,SAAS,mBAAmB;AAC5C,QAAO;EACL;EACA;EACA,YAAa,UAAU,UAAU;EACjC,MAAM,EAAE,WAAY,UAAU,WAAW,KAAA,GAAY;EACtD;;;;;;;;AASH,SAAS,uBAAuB,UAAsD;CACpF,MAAM,MAAgC,EAAE;AACxC,UAAS,UAAU,IAAI;AACvB,QAAO;;AAGT,SAAS,SAAS,MAAwB,KAAqC;CAC7E,MAAM,WAAW,KAAK,aAAa;AAEnC,KAAI,aAAa,iBAAiB,QAAQ;AACxC,MAAI,KAAK,IAAI,qBAAqB,KAAK,CAAC;AACxC;;AAGF,KAAI,aAAa,iBAAiB,UAAU,aAAa,iBAAiB,YACxE,MAAK,MAAM,SAAS,KAAK,iBAAiB,EAAE;EAC1C,MAAM,QAAQ,KAAK,QAAQ,MAAM;AACjC,MAAI,MAAO,UAAS,OAAO,IAAI"}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
require("../../../_virtual/_rolldown/runtime.cjs");
|
|
2
2
|
const require_traverse = require("../../../filters/traverse.cjs");
|
|
3
3
|
const require_state_migration = require("../state-migration.cjs");
|
|
4
|
-
const require_labels = require("../labels.cjs");
|
|
5
4
|
const require_createPTableDefV3 = require("./createPTableDefV3.cjs");
|
|
6
5
|
const require_utils = require("./utils.cjs");
|
|
7
6
|
const require_discoverColumns = require("./discoverColumns.cjs");
|
|
@@ -17,7 +16,6 @@ function createPlDataTableV3(ctx, options) {
|
|
|
17
16
|
const discovered = (0, _milaboratories_helpers.isPlainObject)(options.columns) ? require_discoverColumns.discoverTableColumnSnaphots(ctx, options.columns) : options.columns;
|
|
18
17
|
if ((0, _milaboratories_helpers.isNil)(discovered) || discovered.length === 0) return void 0;
|
|
19
18
|
const splited = splitDiscoveredColumns(discovered);
|
|
20
|
-
const labelColumns = require_labels.getMatchingLabelColumns([...splited.direct, ...splited.linked].map((v) => v.column), require_labels.getAllLabelColumns(ctx));
|
|
21
19
|
const derivedLabels = require_utils.deriveAllLabels({
|
|
22
20
|
columns: discovered.map((dc) => ({
|
|
23
21
|
id: dc.column.id,
|
|
@@ -25,7 +23,6 @@ function createPlDataTableV3(ctx, options) {
|
|
|
25
23
|
linkerPath: dc.path,
|
|
26
24
|
qualifications: dc.qualifications
|
|
27
25
|
})),
|
|
28
|
-
labelColumns,
|
|
29
26
|
deriveLabelsOptions: {
|
|
30
27
|
includeNativeLabel: true,
|
|
31
28
|
...options.labelsOptions
|
|
@@ -41,7 +38,6 @@ function createPlDataTableV3(ctx, options) {
|
|
|
41
38
|
const annotated = annotateColumnGroups({
|
|
42
39
|
pframeSpec,
|
|
43
40
|
...splited,
|
|
44
|
-
labelColumns,
|
|
45
41
|
derivedLabels,
|
|
46
42
|
derivedTooltips,
|
|
47
43
|
displayOptions: options.displayOptions
|
|
@@ -49,11 +45,7 @@ function createPlDataTableV3(ctx, options) {
|
|
|
49
45
|
const primarySnapshots = annotated.direct.filter((c) => c.isPrimary);
|
|
50
46
|
const secondarySnapshots = annotated.direct.filter((c) => !c.isPrimary);
|
|
51
47
|
if (primarySnapshots.length === 0) return void 0;
|
|
52
|
-
const columnIsAvailable = createColumnValidationById([
|
|
53
|
-
...annotated.direct.map((v) => v.column),
|
|
54
|
-
...annotated.linked.flatMap((lc) => [...lc.path.map((s) => s.linker), lc.column]),
|
|
55
|
-
...annotated.labels
|
|
56
|
-
]);
|
|
48
|
+
const columnIsAvailable = createColumnValidationById([...annotated.direct.map((v) => v.column), ...annotated.linked.flatMap((lc) => [...lc.path.map((s) => s.linker), lc.column])]);
|
|
57
49
|
const remapedDefaultFilters = remapFilterColumnIds(options.filters, discovered);
|
|
58
50
|
const filters = concatFilters(state.pTableParams.filters, state.pTableParams.defaultFilters ?? remapedDefaultFilters);
|
|
59
51
|
validateFilters(filters, columnIsAvailable);
|
|
@@ -63,7 +55,7 @@ function createPlDataTableV3(ctx, options) {
|
|
|
63
55
|
const fullDef = require_createPTableDefV3.createPTableDefV3({
|
|
64
56
|
primaryJoinType,
|
|
65
57
|
primary: primaryEntries,
|
|
66
|
-
secondary: buildSecondaryGroups(secondarySnapshots, annotated.linked
|
|
58
|
+
secondary: buildSecondaryGroups(secondarySnapshots, annotated.linked),
|
|
67
59
|
filters,
|
|
68
60
|
sorting
|
|
69
61
|
});
|
|
@@ -71,15 +63,14 @@ function createPlDataTableV3(ctx, options) {
|
|
|
71
63
|
const pframeHandle = ctx.createPFrame([
|
|
72
64
|
...annotated.direct.map((v) => resolveSnapshot(v.column)),
|
|
73
65
|
...annotated.linked.map((v) => resolveSnapshot(v.column)),
|
|
74
|
-
...annotated.labels,
|
|
75
66
|
...collectLinkerSnapshots(annotated.linked).map(resolveSnapshot)
|
|
76
67
|
]);
|
|
77
68
|
const hiddenSpecs = state.pTableParams.hiddenColIds;
|
|
78
|
-
const visible = buildVisibleColumns(annotated, computeHiddenColumns([...annotated.direct, ...annotated.linked].map((v) => v.column), sorting, filters, hiddenSpecs)
|
|
69
|
+
const visible = buildVisibleColumns(annotated, computeHiddenColumns([...annotated.direct, ...annotated.linked].map((v) => v.column), sorting, filters, hiddenSpecs));
|
|
79
70
|
const visibleDef = require_createPTableDefV3.createPTableDefV3({
|
|
80
71
|
primaryJoinType,
|
|
81
72
|
primary: primaryEntries,
|
|
82
|
-
secondary: buildSecondaryGroups(visible.direct.filter((c) => !c.isPrimary), visible.linked
|
|
73
|
+
secondary: buildSecondaryGroups(visible.direct.filter((c) => !c.isPrimary), visible.linked),
|
|
83
74
|
filters,
|
|
84
75
|
sorting
|
|
85
76
|
});
|
|
@@ -110,11 +101,10 @@ function collectLinkerSnapshots(linked) {
|
|
|
110
101
|
* column annotations via `withTableVisualAnnotations`.
|
|
111
102
|
*/
|
|
112
103
|
function annotateColumnGroups(params) {
|
|
113
|
-
const { direct, linked,
|
|
104
|
+
const { direct, linked, derivedLabels, derivedTooltips, displayOptions, pframeSpec } = params;
|
|
114
105
|
const allColumnsForRules = [
|
|
115
106
|
...direct.map((v) => v.column),
|
|
116
107
|
...linked.map((v) => v.column),
|
|
117
|
-
...labelColumns,
|
|
118
108
|
...collectLinkerSnapshots(linked)
|
|
119
109
|
];
|
|
120
110
|
const visibilityByColId = require_utils.evaluateRules(displayOptions?.visibility ?? [], allColumnsForRules, pframeSpec);
|
|
@@ -124,8 +114,7 @@ function annotateColumnGroups(params) {
|
|
|
124
114
|
linked: liftToVariantColumns(linked, (0, es_toolkit.flow)((cols) => require_utils.withHidenAxesAnnotations(cols), (cols) => require_utils.withLabelAnnotations(derivedLabels, cols), (cols) => require_utils.withInfoAnnotations(derivedTooltips, cols), (cols) => require_utils.withTableVisualAnnotations(visibilityByColId, orderByColId, cols))).map((lc) => ({
|
|
125
115
|
...lc,
|
|
126
116
|
path: annotateLinkerPath(derivedLabels, lc.path)
|
|
127
|
-
}))
|
|
128
|
-
labels: (0, es_toolkit.flow)((cols) => require_utils.withHidenAxesAnnotations(cols), (cols) => require_utils.withLabelAnnotations(derivedLabels, cols))(labelColumns)
|
|
117
|
+
}))
|
|
129
118
|
};
|
|
130
119
|
}
|
|
131
120
|
/** Lift a snapshot-array transform so it runs on the inner `column` of each variant. */
|
|
@@ -183,27 +172,20 @@ function validateSorting(sorting, isValidColumnId) {
|
|
|
183
172
|
const firstInvalid = sorting.find((s) => !isValidColumnId((0, _milaboratories_pl_model_common.canonicalizeJson)(s.column)));
|
|
184
173
|
if (firstInvalid !== void 0) throw new Error(`Invalid sorting column ${JSON.stringify(firstInvalid.column)}: column reference does not match the table columns`);
|
|
185
174
|
}
|
|
186
|
-
function buildSecondaryGroups(direct, linked
|
|
187
|
-
return [
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
})),
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
column: resolveSnapshot(lc.column),
|
|
201
|
-
qualifications: lc.qualifications.forHit
|
|
202
|
-
}],
|
|
203
|
-
primaryQualifications: lc.qualifications.forQueries
|
|
204
|
-
})),
|
|
205
|
-
...labels.map((c) => ({ entries: [{ column: c }] }))
|
|
206
|
-
];
|
|
175
|
+
function buildSecondaryGroups(direct, linked) {
|
|
176
|
+
return [...direct.map((c) => ({
|
|
177
|
+
entries: [{
|
|
178
|
+
column: resolveSnapshot(c.column),
|
|
179
|
+
qualifications: c.qualifications.forHit
|
|
180
|
+
}],
|
|
181
|
+
primaryQualifications: c.qualifications.forQueries
|
|
182
|
+
})), ...linked.map((lc) => ({
|
|
183
|
+
entries: [...lc.path.map((s) => ({ column: resolveSnapshot(s.linker) })), {
|
|
184
|
+
column: resolveSnapshot(lc.column),
|
|
185
|
+
qualifications: lc.qualifications.forHit
|
|
186
|
+
}],
|
|
187
|
+
primaryQualifications: lc.qualifications.forQueries
|
|
188
|
+
}))];
|
|
207
189
|
}
|
|
208
190
|
/** Determine which columns should be hidden based on state or optional-column defaults. */
|
|
209
191
|
function computeHiddenColumns(columns, sorting, filters, hiddenSpecs) {
|
|
@@ -223,13 +205,10 @@ function collectPreservedColumnIds(sorting, filters) {
|
|
|
223
205
|
return new Set([...sortedIds, ...filterIds]);
|
|
224
206
|
}
|
|
225
207
|
/** Filter annotated columns to only visible ones, re-matching label columns for the visible subset. */
|
|
226
|
-
function buildVisibleColumns(annotated, hiddenColumns
|
|
227
|
-
const direct = annotated.direct.filter((c) => !hiddenColumns.has(c.column.id));
|
|
228
|
-
const linked = annotated.linked.filter((c) => !hiddenColumns.has(c.column.id));
|
|
208
|
+
function buildVisibleColumns(annotated, hiddenColumns) {
|
|
229
209
|
return {
|
|
230
|
-
direct,
|
|
231
|
-
linked
|
|
232
|
-
labels: require_labels.getMatchingLabelColumns([...direct, ...linked].map((v) => v.column), originalLabelColumns)
|
|
210
|
+
direct: annotated.direct.filter((c) => !hiddenColumns.has(c.column.id)),
|
|
211
|
+
linked: annotated.linked.filter((c) => !hiddenColumns.has(c.column.id))
|
|
233
212
|
};
|
|
234
213
|
}
|
|
235
214
|
/** Resolve a ColumnSnapshot to a PColumn with lazily-evaluated data. */
|