@milaboratories/pl-model-common 1.26.1 → 1.28.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/drivers/index.d.ts +2 -1
- package/dist/drivers/index.js +1 -1
- package/dist/drivers/pframe/index.d.ts +1 -1
- package/dist/drivers/pframe/index.js +1 -1
- package/dist/drivers/pframe/spec/anchored.cjs.map +1 -1
- package/dist/drivers/pframe/spec/anchored.js.map +1 -1
- package/dist/drivers/pframe/spec/index.d.ts +1 -1
- package/dist/drivers/pframe/spec/index.js +1 -1
- package/dist/drivers/pframe/spec/selectors.cjs +2 -2
- package/dist/drivers/pframe/spec/selectors.cjs.map +1 -1
- package/dist/drivers/pframe/spec/selectors.d.ts +12 -6
- package/dist/drivers/pframe/spec/selectors.js +2 -2
- package/dist/drivers/pframe/spec/selectors.js.map +1 -1
- package/dist/drivers/pspec.d.ts +137 -0
- package/dist/index.cjs +4 -1
- package/dist/index.d.ts +4 -2
- package/dist/index.js +3 -2
- package/dist/resource_types.cjs +53 -0
- package/dist/resource_types.cjs.map +1 -0
- package/dist/resource_types.d.ts +50 -0
- package/dist/resource_types.js +51 -0
- package/dist/resource_types.js.map +1 -0
- package/package.json +5 -4
- package/src/common_types.ts +0 -1
- package/src/drivers/index.ts +1 -0
- package/src/drivers/pframe/spec/anchored.ts +2 -2
- package/src/drivers/pframe/spec/selectors.ts +11 -5
- package/src/drivers/pframe/type_util.ts +0 -1
- package/src/drivers/pspec.ts +155 -0
- package/src/index.ts +1 -0
- package/src/resource_types.ts +47 -0
package/dist/drivers/index.d.ts
CHANGED
|
@@ -6,7 +6,7 @@ import { AnyLogHandle, LiveLogHandle, LogsDriver, ProgressLogWithInfo, ReadyLogH
|
|
|
6
6
|
import { Annotation, AnnotationJson, AxesId, AxesSpec, AxisId, AxisSpec, AxisSpecNormalized, AxisTree, AxisValueType, ColumnValueType, Domain, DomainJson, Metadata, MetadataJson, PAxisName, PColumn, PColumnIdAndSpec, PColumnInfo, PColumnLazy, PColumnName, PColumnSpec, PColumnSpecId, PDataColumnSpec, PUniversalColumnSpec, ValueType, canonicalizeAxisId, canonicalizeAxisWithParents, getArrayFromAxisTree, getAxesId, getAxesTree, getAxisId, getColumnIdAndSpec, getDenormalizedAxesList, getNormalizedAxesList, getPColumnSpecId, getSetFromAxisTree, getTypeFromPColumnOrAxisSpec, isAxisId, isLabelColumn, isLinkerColumn, matchAxisId, readAnnotation, readAnnotationJson, readAnnotationJsonOrThrow, readDomain, readDomainJson, readDomainJsonOrThrow, readMetadata, readMetadataJson, readMetadataJsonOrThrow } from "./pframe/spec/spec.js";
|
|
7
7
|
import { ColumnFilter } from "./pframe/column_filter.js";
|
|
8
8
|
import { BinaryChunk, BinaryPartitionedDataInfo, BinaryPartitionedDataInfoEntries, DataInfo, DataInfoEntries, JsonDataInfo, JsonDataInfoEntries, JsonPartitionedDataInfo, JsonPartitionedDataInfoEntries, PColumnDataEntry, PColumnKey, PColumnValue, PColumnValues, PColumnValuesEntry, ParquetChunk, ParquetChunkMapping, ParquetChunkMappingAxis, ParquetChunkMappingColumn, ParquetChunkMetadata, ParquetChunkStats, ParquetPartitionedDataInfo, ParquetPartitionedDataInfoEntries, PartitionedDataInfoEntries, dataInfoToEntries, entriesToDataInfo, isDataInfo, isDataInfoEntries, isPartitionedDataInfoEntries, mapDataInfo, mapDataInfoEntries, visitDataInfo } from "./pframe/data_info.js";
|
|
9
|
-
import { AAxisSelector, ADomain, AnchorAxisIdOrRefBasic, AnchorAxisRef, AnchorAxisRefByIdx, AnchorAxisRefByMatcher, AnchorAxisRefByName, AnchorDomainRef, AnchoredColumnMatchStrategy, AnchoredPColumnId, AnchoredPColumnSelector,
|
|
9
|
+
import { AAxisSelector, ADomain, AnchorAxisIdOrRefBasic, AnchorAxisRef, AnchorAxisRefByIdx, AnchorAxisRefByMatcher, AnchorAxisRefByName, AnchorDomainRef, AnchoredColumnMatchStrategy, AnchoredPColumnId, AnchoredPColumnSelector, LegacyAxisSelector, PColumnSelector, SingleAxisSelector, isAnchoredPColumnId, legacyColumnSelectorsToPredicate, matchAxis, matchPColumn } from "./pframe/spec/selectors.js";
|
|
10
10
|
import { AxisFilter, AxisFilterByIdx, AxisFilterByName, AxisFilterValue, FilteredPColumn, FilteredPColumnId, isFilteredPColumn } from "./pframe/spec/filtered_column.js";
|
|
11
11
|
import { SUniversalPColumnId, UniversalPColumnId, parseColumnId, stringifyColumnId } from "./pframe/spec/ids.js";
|
|
12
12
|
import { FilterSpec, FilterSpecLeaf, FilterSpecNode, FilterSpecOfType, FilterSpecType, InferFilterSpecCommonLeaf, InferFilterSpecCommonNode, InferFilterSpecLeaf, InferFilterSpecLeafColumn, RootFilterSpec } from "./pframe/filter_spec.js";
|
|
@@ -26,4 +26,5 @@ import { PFrameDriver, PFrameHandle, PTableHandle } from "./pframe/driver.js";
|
|
|
26
26
|
import { CompositeLinkerMap, LinkerMap } from "./pframe/linker_columns.js";
|
|
27
27
|
import "./pframe/index.js";
|
|
28
28
|
import { FileRange, ImportFileHandle, ImportFileHandleIndex, ImportFileHandleUpload, ListFilesResult, LocalImportFileHandle, LsDriver, LsEntry, OpenDialogFilter, OpenDialogOps, OpenMultipleFilesResponse, OpenSingleFileResponse, StorageEntry, StorageHandle, StorageHandleLocal, StorageHandleRemote, getFileNameFromHandle, getFilePathFromHandle, isImportFileHandleIndex, isImportFileHandleUpload } from "./ls.js";
|
|
29
|
+
import { AxisQualification, ColumnAxesWithQualifications, DiscoverColumnsConstraints, DiscoverColumnsLinkerStep, DiscoverColumnsMappingVariant, DiscoverColumnsRequest, DiscoverColumnsResponse, DiscoverColumnsResponseHit, DiscoverColumnsResponseQualifications, DiscoverColumnsStepInfo, MatcherMap, MultiAxisSelector, MultiColumnSelector, PSpecDriver, SpecFrameHandle, StringMatcher } from "./pspec.js";
|
|
29
30
|
import { ChunkedStreamReader, ChunkedStreamReaderOptions, ErrorHandlerStatus } from "./ChunkedStreamReader.js";
|
package/dist/drivers/index.js
CHANGED
|
@@ -11,7 +11,7 @@ import { getPTableColumnId } from "./pframe/table_common.js";
|
|
|
11
11
|
import { parseColumnId, stringifyColumnId } from "./pframe/spec/ids.js";
|
|
12
12
|
import { AnchoredIdDeriver, resolveAnchors } from "./pframe/spec/anchored.js";
|
|
13
13
|
import { isFilteredPColumn } from "./pframe/spec/filtered_column.js";
|
|
14
|
-
import { isAnchoredPColumnId, matchAxis, matchPColumn
|
|
14
|
+
import { isAnchoredPColumnId, legacyColumnSelectorsToPredicate, matchAxis, matchPColumn } from "./pframe/spec/selectors.js";
|
|
15
15
|
import { deriveNativeId } from "./pframe/spec/native_id.js";
|
|
16
16
|
import { LinkerMap } from "./pframe/linker_columns.js";
|
|
17
17
|
import "./pframe/index.js";
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Annotation, AnnotationJson, AxesId, AxesSpec, AxisId, AxisSpec, AxisSpecNormalized, AxisTree, AxisValueType, ColumnValueType, Domain, DomainJson, Metadata, MetadataJson, PAxisName, PColumn, PColumnIdAndSpec, PColumnInfo, PColumnLazy, PColumnName, PColumnSpec, PColumnSpecId, PDataColumnSpec, PUniversalColumnSpec, ValueType, canonicalizeAxisId, canonicalizeAxisWithParents, getArrayFromAxisTree, getAxesId, getAxesTree, getAxisId, getColumnIdAndSpec, getDenormalizedAxesList, getNormalizedAxesList, getPColumnSpecId, getSetFromAxisTree, getTypeFromPColumnOrAxisSpec, isAxisId, isLabelColumn, isLinkerColumn, matchAxisId, readAnnotation, readAnnotationJson, readAnnotationJsonOrThrow, readDomain, readDomainJson, readDomainJsonOrThrow, readMetadata, readMetadataJson, readMetadataJsonOrThrow } from "./spec/spec.js";
|
|
2
2
|
import { ColumnFilter } from "./column_filter.js";
|
|
3
3
|
import { BinaryChunk, BinaryPartitionedDataInfo, BinaryPartitionedDataInfoEntries, DataInfo, DataInfoEntries, JsonDataInfo, JsonDataInfoEntries, JsonPartitionedDataInfo, JsonPartitionedDataInfoEntries, PColumnDataEntry, PColumnKey, PColumnValue, PColumnValues, PColumnValuesEntry, ParquetChunk, ParquetChunkMapping, ParquetChunkMappingAxis, ParquetChunkMappingColumn, ParquetChunkMetadata, ParquetChunkStats, ParquetPartitionedDataInfo, ParquetPartitionedDataInfoEntries, PartitionedDataInfoEntries, dataInfoToEntries, entriesToDataInfo, isDataInfo, isDataInfoEntries, isPartitionedDataInfoEntries, mapDataInfo, mapDataInfoEntries, visitDataInfo } from "./data_info.js";
|
|
4
|
-
import { AAxisSelector, ADomain, AnchorAxisIdOrRefBasic, AnchorAxisRef, AnchorAxisRefByIdx, AnchorAxisRefByMatcher, AnchorAxisRefByName, AnchorDomainRef, AnchoredColumnMatchStrategy, AnchoredPColumnId, AnchoredPColumnSelector,
|
|
4
|
+
import { AAxisSelector, ADomain, AnchorAxisIdOrRefBasic, AnchorAxisRef, AnchorAxisRefByIdx, AnchorAxisRefByMatcher, AnchorAxisRefByName, AnchorDomainRef, AnchoredColumnMatchStrategy, AnchoredPColumnId, AnchoredPColumnSelector, LegacyAxisSelector, PColumnSelector, SingleAxisSelector, isAnchoredPColumnId, legacyColumnSelectorsToPredicate, matchAxis, matchPColumn } from "./spec/selectors.js";
|
|
5
5
|
import { AxisFilter, AxisFilterByIdx, AxisFilterByName, AxisFilterValue, FilteredPColumn, FilteredPColumnId, isFilteredPColumn } from "./spec/filtered_column.js";
|
|
6
6
|
import { SUniversalPColumnId, UniversalPColumnId, parseColumnId, stringifyColumnId } from "./spec/ids.js";
|
|
7
7
|
import { FilterSpec, FilterSpecLeaf, FilterSpecNode, FilterSpecOfType, FilterSpecType, InferFilterSpecCommonLeaf, InferFilterSpecCommonNode, InferFilterSpecLeaf, InferFilterSpecLeafColumn, RootFilterSpec } from "./filter_spec.js";
|
|
@@ -8,7 +8,7 @@ import { getPTableColumnId } from "./table_common.js";
|
|
|
8
8
|
import { parseColumnId, stringifyColumnId } from "./spec/ids.js";
|
|
9
9
|
import { AnchoredIdDeriver, resolveAnchors } from "./spec/anchored.js";
|
|
10
10
|
import { isFilteredPColumn } from "./spec/filtered_column.js";
|
|
11
|
-
import { isAnchoredPColumnId, matchAxis, matchPColumn
|
|
11
|
+
import { isAnchoredPColumnId, legacyColumnSelectorsToPredicate, matchAxis, matchPColumn } from "./spec/selectors.js";
|
|
12
12
|
import { deriveNativeId } from "./spec/native_id.js";
|
|
13
13
|
import "./spec/index.js";
|
|
14
14
|
import "./driver.js";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"anchored.cjs","names":["getAxisId","stringifyColumnId","matchAxisId"],"sources":["../../../../src/drivers/pframe/spec/anchored.ts"],"sourcesContent":["import canonicalize from \"canonicalize\";\nimport type { AxisFilter, AxisFilterValue } from \"./filtered_column\";\nimport type { SUniversalPColumnId, UniversalPColumnId } from \"./ids\";\nimport { stringifyColumnId } from \"./ids\";\nimport type {\n AAxisSelector,\n AnchorAxisRef,\n AnchorAxisRefByIdx,\n AnchoredPColumnId,\n AnchoredPColumnSelector,\n AxisSelector,\n PColumnSelector,\n} from \"./selectors\";\nimport type { AxisId, PColumnSpec } from \"./spec\";\nimport { getAxisId, matchAxisId } from \"./spec\";\n\n//\n// Helper functions\n//\n\nfunction axisKey(axis: AxisId): string {\n return canonicalize(getAxisId(axis))!;\n}\n\nfunction domainKey(key: string, value: string): string {\n return JSON.stringify([key, value]);\n}\n\n/**\n * Context for resolving and generating anchored references to columns and axes\n * Maintains maps of known domain values and axes that can be referenced by anchors\n */\nexport class AnchoredIdDeriver {\n private readonly domains = new Map<string, string>();\n private readonly contextDomains = new Map<string, string>();\n private readonly axes = new Map<string, AnchorAxisRefByIdx>();\n /**\n * Domain packs are used to group domain keys that can be anchored to the same anchor\n * This is used to optimize the lookup of domain anchors\n */\n private readonly domainPacks: string[][] = [];\n private readonly contextDomainPacks: string[][] = [];\n /**\n * Maps domain packs to anchors\n */\n private readonly domainPackToAnchor = new Map<string, string>();\n private readonly contextDomainPackToAnchor = new Map<string, string>();\n\n /**\n * Creates a new anchor context from a set of anchor column specifications\n * @param anchors Record of anchor column specifications indexed by anchor ID\n */\n constructor(public readonly anchors: Record<string, PColumnSpec>) {\n const anchorEntries = Object.entries(anchors);\n anchorEntries.sort((a, b) => a[0].localeCompare(b[0]));\n for (const [anchorId, spec] of anchorEntries) {\n for (let axisIdx = 0; axisIdx < spec.axesSpec.length; axisIdx++) {\n const axis = spec.axesSpec[axisIdx];\n const key = axisKey(axis);\n this.axes.set(key, { anchor: anchorId, idx: axisIdx });\n }\n if (spec.domain !== undefined) {\n const domainEntries = Object.entries(spec.domain);\n domainEntries.sort((a, b) => a[0].localeCompare(b[0]));\n\n this.domainPackToAnchor.set(JSON.stringify(domainEntries), anchorId);\n this.domainPacks.push(domainEntries.map(([dKey]) => dKey));\n\n for (const [dKey, dValue] of domainEntries) {\n const key = domainKey(dKey, dValue);\n this.domains.set(key, anchorId);\n }\n }\n if (spec.contextDomain !== undefined) {\n const contextDomainEntries = Object.entries(spec.contextDomain);\n contextDomainEntries.sort((a, b) => a[0].localeCompare(b[0]));\n\n this.contextDomainPackToAnchor.set(JSON.stringify(contextDomainEntries), anchorId);\n this.contextDomainPacks.push(contextDomainEntries.map(([dKey]) => dKey));\n\n for (const [dKey, dValue] of contextDomainEntries) {\n const key = domainKey(dKey, dValue);\n this.contextDomains.set(key, anchorId);\n }\n }\n }\n }\n\n /**\n * Derives an anchored column identifier from a column specification\n * @param spec Column specification to anchor\n * @returns An anchored column identifier that can be used to identify columns similar to the input specification\n */\n derive(spec: PColumnSpec): AnchoredPColumnId;\n\n /**\n * Derives an anchored column identifier from a column specification\n * @param spec Column specification to anchor\n * @param axisFilters Axis filters to apply to the column\n * @returns An anchored and sliced column identifier that can be used to identify columns similar to the input specification\n */\n derive(spec: PColumnSpec, axisFilters?: AxisFilter[]): UniversalPColumnId;\n\n /**\n * Implementation of derive method\n */\n derive(spec: PColumnSpec, axisFilters?: AxisFilter[]): UniversalPColumnId {\n const result: AnchoredPColumnId = {\n name: spec.name,\n axes: [],\n };\n\n let skipDomains: Set<string> | undefined = undefined;\n if (spec.domain !== undefined) {\n outer: for (const domainPack of this.domainPacks) {\n const dAnchor: string[][] = [];\n for (const domainKey of domainPack) {\n const dValue = spec.domain[domainKey];\n if (dValue !== undefined) dAnchor.push([domainKey, dValue]);\n else break outer;\n }\n const domainAnchor = this.domainPackToAnchor.get(JSON.stringify(dAnchor));\n if (domainAnchor !== undefined) {\n result.domainAnchor = domainAnchor;\n skipDomains = new Set(domainPack);\n break;\n }\n }\n }\n\n for (const [dKey, dValue] of Object.entries(spec.domain ?? {})) {\n if (skipDomains !== undefined && skipDomains.has(dKey)) continue;\n const key = domainKey(dKey, dValue);\n const anchorId = this.domains.get(key);\n result.domain ??= {};\n result.domain[dKey] = anchorId ? { anchor: anchorId } : dValue;\n }\n\n let skipContextDomains: Set<string> | undefined = undefined;\n if (spec.contextDomain !== undefined) {\n outer: for (const contextDomainPack of this.contextDomainPacks) {\n const dAnchor: string[][] = [];\n for (const domainKey of contextDomainPack) {\n const dValue = spec.contextDomain[domainKey];\n if (dValue !== undefined) dAnchor.push([domainKey, dValue]);\n else break outer;\n }\n const contextDomainAnchor = this.contextDomainPackToAnchor.get(JSON.stringify(dAnchor));\n if (contextDomainAnchor !== undefined) {\n result.contextDomainAnchor = contextDomainAnchor;\n skipContextDomains = new Set(contextDomainPack);\n break;\n }\n }\n }\n\n for (const [dKey, dValue] of Object.entries(spec.contextDomain ?? {})) {\n if (skipContextDomains !== undefined && skipContextDomains.has(dKey)) continue;\n const key = domainKey(dKey, dValue);\n const anchorId = this.contextDomains.get(key);\n result.contextDomain ??= {};\n result.contextDomain[dKey] = anchorId ? { anchor: anchorId } : dValue;\n }\n\n result.axes = spec.axesSpec.map((axis) => {\n const key = axisKey(axis);\n const anchorAxisRef = this.axes.get(key);\n if (anchorAxisRef === undefined) return getAxisId(axis);\n else return anchorAxisRef;\n });\n\n // If no axis filters are provided, return the anchored ID as is\n if (!axisFilters || axisFilters.length === 0) {\n return result;\n }\n\n // Process axis filters and create a sliced column ID\n const resolvedFilters: [number, AxisFilterValue][] = [];\n\n for (const filter of axisFilters) {\n const [axisIdOrIndex, value] = filter;\n\n // If it's already a numeric index, validate it\n if (typeof axisIdOrIndex === \"number\") {\n if (axisIdOrIndex < 0 || axisIdOrIndex >= spec.axesSpec.length) {\n throw new Error(\n `Axis index ${axisIdOrIndex} is out of bounds (0-${spec.axesSpec.length - 1})`,\n );\n }\n resolvedFilters.push([axisIdOrIndex, value]);\n } else {\n // If it's a string (axis name), resolve it to an index\n const axisIndex = spec.axesSpec.findIndex((axis) => axis.name === axisIdOrIndex);\n if (axisIndex === -1) {\n throw new Error(\n `Axis with name \"${axisIdOrIndex}\" not found in the column specification`,\n );\n }\n resolvedFilters.push([axisIndex, value]);\n }\n }\n\n // Sort filters by axis index to ensure consistency\n resolvedFilters.sort((a, b) => a[0] - b[0]);\n\n return {\n source: result,\n axisFilters: resolvedFilters,\n };\n }\n\n /**\n * Derives a canonicalized string representation of an anchored column identifier, can be used as a unique identifier for the column\n * @param spec Column specification to anchor\n * @param axisFilters Optional axis filters to apply to the column\n * @returns A canonicalized string representation of the anchored column identifier\n */\n deriveS(spec: PColumnSpec, axisFilters?: AxisFilter[]): SUniversalPColumnId {\n return stringifyColumnId(this.derive(spec, axisFilters));\n }\n}\n\n/**\n * Options for the resolveAnchors function\n */\nexport type ResolveAnchorsOptions = {\n /**\n * If true, missing domain keys in anchors will be ignored.\n * If false (default), an error will be thrown.\n */\n ignoreMissingDomains?: boolean;\n};\n\n/**\n * Resolves anchored references in a column matcher to create a non-anchored matcher.\n * Doing an opposite operation to {@link AnchorIdDeriver.derive()}.\n *\n * @param anchors - Record of anchor column specifications indexed by anchor id\n * @param matcher - An anchored column matcher (or id, which is subtype of it) containing references that need to be resolved\n * @param options - Options for resolving anchors\n * @returns A non-anchored column matcher with all references resolved to actual values\n */\nexport function resolveAnchors(\n anchors: Record<string, PColumnSpec>,\n matcher: AnchoredPColumnSelector,\n options?: ResolveAnchorsOptions,\n): PColumnSelector {\n const result = { ...matcher };\n const ignoreMissingDomains = options?.ignoreMissingDomains ?? false;\n\n if (result.domainAnchor !== undefined) {\n const anchorSpec = anchors[result.domainAnchor];\n if (!anchorSpec) throw new Error(`Anchor \"${result.domainAnchor}\" not found`);\n\n const anchorDomains = anchorSpec.domain || {};\n result.domain = { ...anchorDomains, ...result.domain };\n delete result.domainAnchor;\n }\n\n if (result.domain) {\n const resolvedDomain: Record<string, string> = {};\n for (const [key, value] of Object.entries(result.domain)) {\n if (typeof value === \"string\") {\n resolvedDomain[key] = value;\n } else {\n // It's an AnchorDomainRef\n const anchorSpec = anchors[value.anchor];\n if (!anchorSpec)\n throw new Error(`Anchor \"${value.anchor}\" not found for domain key \"${key}\"`);\n\n if (!anchorSpec.domain || anchorSpec.domain[key] === undefined) {\n if (!ignoreMissingDomains)\n throw new Error(`Domain key \"${key}\" not found in anchor \"${value.anchor}\"`);\n continue;\n }\n\n resolvedDomain[key] = anchorSpec.domain[key];\n }\n }\n result.domain = resolvedDomain;\n }\n\n if (result.contextDomainAnchor !== undefined) {\n const anchorSpec = anchors[result.contextDomainAnchor];\n if (!anchorSpec) throw new Error(`Anchor \"${result.contextDomainAnchor}\" not found`);\n\n const anchorContextDomains = anchorSpec.contextDomain || {};\n result.contextDomain = { ...anchorContextDomains, ...result.contextDomain };\n delete result.contextDomainAnchor;\n }\n\n if (result.contextDomain) {\n const resolvedContextDomain: Record<string, string> = {};\n for (const [key, value] of Object.entries(result.contextDomain)) {\n if (typeof value === \"string\") {\n resolvedContextDomain[key] = value;\n } else {\n // It's an AnchorDomainRef\n const anchorSpec = anchors[value.anchor];\n if (!anchorSpec)\n throw new Error(`Anchor \"${value.anchor}\" not found for contextDomain key \"${key}\"`);\n\n if (!anchorSpec.contextDomain || anchorSpec.contextDomain[key] === undefined) {\n if (!ignoreMissingDomains)\n throw new Error(`Context domain key \"${key}\" not found in anchor \"${value.anchor}\"`);\n continue;\n }\n\n resolvedContextDomain[key] = anchorSpec.contextDomain[key];\n }\n }\n result.contextDomain = resolvedContextDomain;\n }\n\n if (result.axes) result.axes = result.axes.map((axis) => resolveAxisReference(anchors, axis));\n\n return result as PColumnSelector;\n}\n\n/**\n * Resolves an anchored axis reference to a concrete AxisId\n */\nfunction resolveAxisReference(\n anchors: Record<string, PColumnSpec>,\n axisRef: AAxisSelector,\n): AxisSelector {\n if (!isAnchorAxisRef(axisRef)) return axisRef;\n\n // It's an anchored reference\n const anchorId = axisRef.anchor;\n const anchorSpec = anchors[anchorId];\n if (!anchorSpec) throw new Error(`Anchor \"${anchorId}\" not found for axis reference`);\n\n if (\"idx\" in axisRef) {\n // AnchorAxisRefByIdx\n if (axisRef.idx < 0 || axisRef.idx >= anchorSpec.axesSpec.length)\n throw new Error(`Axis index ${axisRef.idx} out of bounds for anchor \"${anchorId}\"`);\n return anchorSpec.axesSpec[axisRef.idx];\n } else if (\"name\" in axisRef) {\n // AnchorAxisRefByName\n const matches = anchorSpec.axesSpec.filter((axis) => axis.name === axisRef.name);\n if (matches.length > 1)\n throw new Error(`Multiple axes with name \"${axisRef.name}\" found in anchor \"${anchorId}\"`);\n if (matches.length === 0)\n throw new Error(`Axis with name \"${axisRef.name}\" not found in anchor \"${anchorId}\"`);\n return matches[0];\n } else if (\"id\" in axisRef) {\n // AnchorAxisRefByMatcher\n const matches = anchorSpec.axesSpec.filter((axis) => matchAxisId(axisRef.id, getAxisId(axis)));\n if (matches.length > 1)\n throw new Error(`Multiple matching axes found for matcher in anchor \"${anchorId}\"`);\n if (matches.length === 0)\n throw new Error(`No matching axis found for matcher in anchor \"${anchorId}\"`);\n return matches[0];\n }\n\n throw new Error(`Unsupported axis reference type`);\n}\n\n/**\n * Type guard to check if a value is an anchored axis reference\n */\nfunction isAnchorAxisRef(value: AAxisSelector): value is AnchorAxisRef {\n return typeof value === \"object\" && \"anchor\" in value;\n}\n"],"mappings":";;;;;;;AAoBA,SAAS,QAAQ,MAAsB;AACrC,kCAAoBA,uBAAU,KAAK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AK,yBAAyB,SAAS,GAAG;AACvF,SAAO,QAAQ;YACN,QAAQ,SAAS;EAE1B,MAAM,UAAU,WAAW,SAAS,QAAQ,SAASC,yBAAY,QAAQ,IAAIF,uBAAU,KAAK,CAAC,CAAC;AAC9F,MAAI,QAAQ,SAAS,EACnB,OAAM,IAAI,MAAM,uDAAuD,SAAS,GAAG;AACrF,MAAI,QAAQ,WAAW,EACrB,OAAM,IAAI,MAAM,iDAAiD,SAAS,GAAG;AAC/E,SAAO,QAAQ;;AAGjB,OAAM,IAAI,MAAM,kCAAkC;;;;;AAMpD,SAAS,gBAAgB,OAA8C;AACrE,QAAO,OAAO,UAAU,YAAY,YAAY"}
|
|
1
|
+
{"version":3,"file":"anchored.cjs","names":["getAxisId","stringifyColumnId","matchAxisId"],"sources":["../../../../src/drivers/pframe/spec/anchored.ts"],"sourcesContent":["import canonicalize from \"canonicalize\";\nimport type { AxisFilter, AxisFilterValue } from \"./filtered_column\";\nimport type { SUniversalPColumnId, UniversalPColumnId } from \"./ids\";\nimport { stringifyColumnId } from \"./ids\";\nimport type {\n AAxisSelector,\n AnchorAxisRef,\n AnchorAxisRefByIdx,\n AnchoredPColumnId,\n AnchoredPColumnSelector,\n LegacyAxisSelector,\n PColumnSelector,\n} from \"./selectors\";\nimport type { AxisId, PColumnSpec } from \"./spec\";\nimport { getAxisId, matchAxisId } from \"./spec\";\n\n//\n// Helper functions\n//\n\nfunction axisKey(axis: AxisId): string {\n return canonicalize(getAxisId(axis))!;\n}\n\nfunction domainKey(key: string, value: string): string {\n return JSON.stringify([key, value]);\n}\n\n/**\n * Context for resolving and generating anchored references to columns and axes\n * Maintains maps of known domain values and axes that can be referenced by anchors\n */\nexport class AnchoredIdDeriver {\n private readonly domains = new Map<string, string>();\n private readonly contextDomains = new Map<string, string>();\n private readonly axes = new Map<string, AnchorAxisRefByIdx>();\n /**\n * Domain packs are used to group domain keys that can be anchored to the same anchor\n * This is used to optimize the lookup of domain anchors\n */\n private readonly domainPacks: string[][] = [];\n private readonly contextDomainPacks: string[][] = [];\n /**\n * Maps domain packs to anchors\n */\n private readonly domainPackToAnchor = new Map<string, string>();\n private readonly contextDomainPackToAnchor = new Map<string, string>();\n\n /**\n * Creates a new anchor context from a set of anchor column specifications\n * @param anchors Record of anchor column specifications indexed by anchor ID\n */\n constructor(public readonly anchors: Record<string, PColumnSpec>) {\n const anchorEntries = Object.entries(anchors);\n anchorEntries.sort((a, b) => a[0].localeCompare(b[0]));\n for (const [anchorId, spec] of anchorEntries) {\n for (let axisIdx = 0; axisIdx < spec.axesSpec.length; axisIdx++) {\n const axis = spec.axesSpec[axisIdx];\n const key = axisKey(axis);\n this.axes.set(key, { anchor: anchorId, idx: axisIdx });\n }\n if (spec.domain !== undefined) {\n const domainEntries = Object.entries(spec.domain);\n domainEntries.sort((a, b) => a[0].localeCompare(b[0]));\n\n this.domainPackToAnchor.set(JSON.stringify(domainEntries), anchorId);\n this.domainPacks.push(domainEntries.map(([dKey]) => dKey));\n\n for (const [dKey, dValue] of domainEntries) {\n const key = domainKey(dKey, dValue);\n this.domains.set(key, anchorId);\n }\n }\n if (spec.contextDomain !== undefined) {\n const contextDomainEntries = Object.entries(spec.contextDomain);\n contextDomainEntries.sort((a, b) => a[0].localeCompare(b[0]));\n\n this.contextDomainPackToAnchor.set(JSON.stringify(contextDomainEntries), anchorId);\n this.contextDomainPacks.push(contextDomainEntries.map(([dKey]) => dKey));\n\n for (const [dKey, dValue] of contextDomainEntries) {\n const key = domainKey(dKey, dValue);\n this.contextDomains.set(key, anchorId);\n }\n }\n }\n }\n\n /**\n * Derives an anchored column identifier from a column specification\n * @param spec Column specification to anchor\n * @returns An anchored column identifier that can be used to identify columns similar to the input specification\n */\n derive(spec: PColumnSpec): AnchoredPColumnId;\n\n /**\n * Derives an anchored column identifier from a column specification\n * @param spec Column specification to anchor\n * @param axisFilters Axis filters to apply to the column\n * @returns An anchored and sliced column identifier that can be used to identify columns similar to the input specification\n */\n derive(spec: PColumnSpec, axisFilters?: AxisFilter[]): UniversalPColumnId;\n\n /**\n * Implementation of derive method\n */\n derive(spec: PColumnSpec, axisFilters?: AxisFilter[]): UniversalPColumnId {\n const result: AnchoredPColumnId = {\n name: spec.name,\n axes: [],\n };\n\n let skipDomains: Set<string> | undefined = undefined;\n if (spec.domain !== undefined) {\n outer: for (const domainPack of this.domainPacks) {\n const dAnchor: string[][] = [];\n for (const domainKey of domainPack) {\n const dValue = spec.domain[domainKey];\n if (dValue !== undefined) dAnchor.push([domainKey, dValue]);\n else break outer;\n }\n const domainAnchor = this.domainPackToAnchor.get(JSON.stringify(dAnchor));\n if (domainAnchor !== undefined) {\n result.domainAnchor = domainAnchor;\n skipDomains = new Set(domainPack);\n break;\n }\n }\n }\n\n for (const [dKey, dValue] of Object.entries(spec.domain ?? {})) {\n if (skipDomains !== undefined && skipDomains.has(dKey)) continue;\n const key = domainKey(dKey, dValue);\n const anchorId = this.domains.get(key);\n result.domain ??= {};\n result.domain[dKey] = anchorId ? { anchor: anchorId } : dValue;\n }\n\n let skipContextDomains: Set<string> | undefined = undefined;\n if (spec.contextDomain !== undefined) {\n outer: for (const contextDomainPack of this.contextDomainPacks) {\n const dAnchor: string[][] = [];\n for (const domainKey of contextDomainPack) {\n const dValue = spec.contextDomain[domainKey];\n if (dValue !== undefined) dAnchor.push([domainKey, dValue]);\n else break outer;\n }\n const contextDomainAnchor = this.contextDomainPackToAnchor.get(JSON.stringify(dAnchor));\n if (contextDomainAnchor !== undefined) {\n result.contextDomainAnchor = contextDomainAnchor;\n skipContextDomains = new Set(contextDomainPack);\n break;\n }\n }\n }\n\n for (const [dKey, dValue] of Object.entries(spec.contextDomain ?? {})) {\n if (skipContextDomains !== undefined && skipContextDomains.has(dKey)) continue;\n const key = domainKey(dKey, dValue);\n const anchorId = this.contextDomains.get(key);\n result.contextDomain ??= {};\n result.contextDomain[dKey] = anchorId ? { anchor: anchorId } : dValue;\n }\n\n result.axes = spec.axesSpec.map((axis) => {\n const key = axisKey(axis);\n const anchorAxisRef = this.axes.get(key);\n if (anchorAxisRef === undefined) return getAxisId(axis);\n else return anchorAxisRef;\n });\n\n // If no axis filters are provided, return the anchored ID as is\n if (!axisFilters || axisFilters.length === 0) {\n return result;\n }\n\n // Process axis filters and create a sliced column ID\n const resolvedFilters: [number, AxisFilterValue][] = [];\n\n for (const filter of axisFilters) {\n const [axisIdOrIndex, value] = filter;\n\n // If it's already a numeric index, validate it\n if (typeof axisIdOrIndex === \"number\") {\n if (axisIdOrIndex < 0 || axisIdOrIndex >= spec.axesSpec.length) {\n throw new Error(\n `Axis index ${axisIdOrIndex} is out of bounds (0-${spec.axesSpec.length - 1})`,\n );\n }\n resolvedFilters.push([axisIdOrIndex, value]);\n } else {\n // If it's a string (axis name), resolve it to an index\n const axisIndex = spec.axesSpec.findIndex((axis) => axis.name === axisIdOrIndex);\n if (axisIndex === -1) {\n throw new Error(\n `Axis with name \"${axisIdOrIndex}\" not found in the column specification`,\n );\n }\n resolvedFilters.push([axisIndex, value]);\n }\n }\n\n // Sort filters by axis index to ensure consistency\n resolvedFilters.sort((a, b) => a[0] - b[0]);\n\n return {\n source: result,\n axisFilters: resolvedFilters,\n };\n }\n\n /**\n * Derives a canonicalized string representation of an anchored column identifier, can be used as a unique identifier for the column\n * @param spec Column specification to anchor\n * @param axisFilters Optional axis filters to apply to the column\n * @returns A canonicalized string representation of the anchored column identifier\n */\n deriveS(spec: PColumnSpec, axisFilters?: AxisFilter[]): SUniversalPColumnId {\n return stringifyColumnId(this.derive(spec, axisFilters));\n }\n}\n\n/**\n * Options for the resolveAnchors function\n */\nexport type ResolveAnchorsOptions = {\n /**\n * If true, missing domain keys in anchors will be ignored.\n * If false (default), an error will be thrown.\n */\n ignoreMissingDomains?: boolean;\n};\n\n/**\n * Resolves anchored references in a column matcher to create a non-anchored matcher.\n * Doing an opposite operation to {@link AnchorIdDeriver.derive()}.\n *\n * @param anchors - Record of anchor column specifications indexed by anchor id\n * @param matcher - An anchored column matcher (or id, which is subtype of it) containing references that need to be resolved\n * @param options - Options for resolving anchors\n * @returns A non-anchored column matcher with all references resolved to actual values\n */\nexport function resolveAnchors(\n anchors: Record<string, PColumnSpec>,\n matcher: AnchoredPColumnSelector,\n options?: ResolveAnchorsOptions,\n): PColumnSelector {\n const result = { ...matcher };\n const ignoreMissingDomains = options?.ignoreMissingDomains ?? false;\n\n if (result.domainAnchor !== undefined) {\n const anchorSpec = anchors[result.domainAnchor];\n if (!anchorSpec) throw new Error(`Anchor \"${result.domainAnchor}\" not found`);\n\n const anchorDomains = anchorSpec.domain || {};\n result.domain = { ...anchorDomains, ...result.domain };\n delete result.domainAnchor;\n }\n\n if (result.domain) {\n const resolvedDomain: Record<string, string> = {};\n for (const [key, value] of Object.entries(result.domain)) {\n if (typeof value === \"string\") {\n resolvedDomain[key] = value;\n } else {\n // It's an AnchorDomainRef\n const anchorSpec = anchors[value.anchor];\n if (!anchorSpec)\n throw new Error(`Anchor \"${value.anchor}\" not found for domain key \"${key}\"`);\n\n if (!anchorSpec.domain || anchorSpec.domain[key] === undefined) {\n if (!ignoreMissingDomains)\n throw new Error(`Domain key \"${key}\" not found in anchor \"${value.anchor}\"`);\n continue;\n }\n\n resolvedDomain[key] = anchorSpec.domain[key];\n }\n }\n result.domain = resolvedDomain;\n }\n\n if (result.contextDomainAnchor !== undefined) {\n const anchorSpec = anchors[result.contextDomainAnchor];\n if (!anchorSpec) throw new Error(`Anchor \"${result.contextDomainAnchor}\" not found`);\n\n const anchorContextDomains = anchorSpec.contextDomain || {};\n result.contextDomain = { ...anchorContextDomains, ...result.contextDomain };\n delete result.contextDomainAnchor;\n }\n\n if (result.contextDomain) {\n const resolvedContextDomain: Record<string, string> = {};\n for (const [key, value] of Object.entries(result.contextDomain)) {\n if (typeof value === \"string\") {\n resolvedContextDomain[key] = value;\n } else {\n // It's an AnchorDomainRef\n const anchorSpec = anchors[value.anchor];\n if (!anchorSpec)\n throw new Error(`Anchor \"${value.anchor}\" not found for contextDomain key \"${key}\"`);\n\n if (!anchorSpec.contextDomain || anchorSpec.contextDomain[key] === undefined) {\n if (!ignoreMissingDomains)\n throw new Error(`Context domain key \"${key}\" not found in anchor \"${value.anchor}\"`);\n continue;\n }\n\n resolvedContextDomain[key] = anchorSpec.contextDomain[key];\n }\n }\n result.contextDomain = resolvedContextDomain;\n }\n\n if (result.axes) result.axes = result.axes.map((axis) => resolveAxisReference(anchors, axis));\n\n return result as PColumnSelector;\n}\n\n/**\n * Resolves an anchored axis reference to a concrete AxisId\n */\nfunction resolveAxisReference(\n anchors: Record<string, PColumnSpec>,\n axisRef: AAxisSelector,\n): LegacyAxisSelector {\n if (!isAnchorAxisRef(axisRef)) return axisRef;\n\n // It's an anchored reference\n const anchorId = axisRef.anchor;\n const anchorSpec = anchors[anchorId];\n if (!anchorSpec) throw new Error(`Anchor \"${anchorId}\" not found for axis reference`);\n\n if (\"idx\" in axisRef) {\n // AnchorAxisRefByIdx\n if (axisRef.idx < 0 || axisRef.idx >= anchorSpec.axesSpec.length)\n throw new Error(`Axis index ${axisRef.idx} out of bounds for anchor \"${anchorId}\"`);\n return anchorSpec.axesSpec[axisRef.idx];\n } else if (\"name\" in axisRef) {\n // AnchorAxisRefByName\n const matches = anchorSpec.axesSpec.filter((axis) => axis.name === axisRef.name);\n if (matches.length > 1)\n throw new Error(`Multiple axes with name \"${axisRef.name}\" found in anchor \"${anchorId}\"`);\n if (matches.length === 0)\n throw new Error(`Axis with name \"${axisRef.name}\" not found in anchor \"${anchorId}\"`);\n return matches[0];\n } else if (\"id\" in axisRef) {\n // AnchorAxisRefByMatcher\n const matches = anchorSpec.axesSpec.filter((axis) => matchAxisId(axisRef.id, getAxisId(axis)));\n if (matches.length > 1)\n throw new Error(`Multiple matching axes found for matcher in anchor \"${anchorId}\"`);\n if (matches.length === 0)\n throw new Error(`No matching axis found for matcher in anchor \"${anchorId}\"`);\n return matches[0];\n }\n\n throw new Error(`Unsupported axis reference type`);\n}\n\n/**\n * Type guard to check if a value is an anchored axis reference\n */\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MAAI,QAAQ,SAAS,EACnB,OAAM,IAAI,MAAM,4BAA4B,QAAQ,KAAK,qBAAqB,SAAS,GAAG;AAC5F,MAAI,QAAQ,WAAW,EACrB,OAAM,IAAI,MAAM,mBAAmB,QAAQ,KAAK,yBAAyB,SAAS,GAAG;AACvF,SAAO,QAAQ;YACN,QAAQ,SAAS;EAE1B,MAAM,UAAU,WAAW,SAAS,QAAQ,SAASC,yBAAY,QAAQ,IAAIF,uBAAU,KAAK,CAAC,CAAC;AAC9F,MAAI,QAAQ,SAAS,EACnB,OAAM,IAAI,MAAM,uDAAuD,SAAS,GAAG;AACrF,MAAI,QAAQ,WAAW,EACrB,OAAM,IAAI,MAAM,iDAAiD,SAAS,GAAG;AAC/E,SAAO,QAAQ;;AAGjB,OAAM,IAAI,MAAM,kCAAkC;;;;;AAMpD,SAAS,gBAAgB,OAA8C;AACrE,QAAO,OAAO,UAAU,YAAY,YAAY"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"anchored.js","names":[],"sources":["../../../../src/drivers/pframe/spec/anchored.ts"],"sourcesContent":["import canonicalize from \"canonicalize\";\nimport type { AxisFilter, AxisFilterValue } from \"./filtered_column\";\nimport type { SUniversalPColumnId, UniversalPColumnId } from \"./ids\";\nimport { stringifyColumnId } from \"./ids\";\nimport type {\n AAxisSelector,\n AnchorAxisRef,\n AnchorAxisRefByIdx,\n AnchoredPColumnId,\n AnchoredPColumnSelector,\n AxisSelector,\n PColumnSelector,\n} from \"./selectors\";\nimport type { AxisId, PColumnSpec } from \"./spec\";\nimport { getAxisId, matchAxisId } from \"./spec\";\n\n//\n// Helper functions\n//\n\nfunction axisKey(axis: AxisId): string {\n return canonicalize(getAxisId(axis))!;\n}\n\nfunction domainKey(key: string, value: string): string {\n return JSON.stringify([key, value]);\n}\n\n/**\n * Context for resolving and generating anchored references to columns and axes\n * Maintains maps of known domain values and axes that can be referenced by anchors\n */\nexport class AnchoredIdDeriver {\n private readonly domains = new Map<string, string>();\n private readonly contextDomains = new Map<string, string>();\n private readonly axes = new Map<string, AnchorAxisRefByIdx>();\n /**\n * Domain packs are used to group domain keys that can be anchored to the same anchor\n * This is used to optimize the lookup of domain anchors\n */\n private readonly domainPacks: string[][] = [];\n private readonly contextDomainPacks: string[][] = [];\n /**\n * Maps domain packs to anchors\n */\n private readonly domainPackToAnchor = new Map<string, string>();\n private readonly contextDomainPackToAnchor = new Map<string, string>();\n\n /**\n * Creates a new anchor context from a set of anchor column specifications\n * @param anchors Record of anchor column specifications indexed by anchor ID\n */\n constructor(public readonly anchors: Record<string, PColumnSpec>) {\n const anchorEntries = Object.entries(anchors);\n anchorEntries.sort((a, b) => a[0].localeCompare(b[0]));\n for (const [anchorId, spec] of anchorEntries) {\n for (let axisIdx = 0; axisIdx < spec.axesSpec.length; axisIdx++) {\n const axis = spec.axesSpec[axisIdx];\n const key = axisKey(axis);\n this.axes.set(key, { anchor: anchorId, idx: axisIdx });\n }\n if (spec.domain !== undefined) {\n const domainEntries = Object.entries(spec.domain);\n domainEntries.sort((a, b) => a[0].localeCompare(b[0]));\n\n this.domainPackToAnchor.set(JSON.stringify(domainEntries), anchorId);\n this.domainPacks.push(domainEntries.map(([dKey]) => dKey));\n\n for (const [dKey, dValue] of domainEntries) {\n const key = domainKey(dKey, dValue);\n this.domains.set(key, anchorId);\n }\n }\n if (spec.contextDomain !== undefined) {\n const contextDomainEntries = Object.entries(spec.contextDomain);\n contextDomainEntries.sort((a, b) => a[0].localeCompare(b[0]));\n\n this.contextDomainPackToAnchor.set(JSON.stringify(contextDomainEntries), anchorId);\n this.contextDomainPacks.push(contextDomainEntries.map(([dKey]) => dKey));\n\n for (const [dKey, dValue] of contextDomainEntries) {\n const key = domainKey(dKey, dValue);\n this.contextDomains.set(key, anchorId);\n }\n }\n }\n }\n\n /**\n * Derives an anchored column identifier from a column specification\n * @param spec Column specification to anchor\n * @returns An anchored column identifier that can be used to identify columns similar to the input specification\n */\n derive(spec: PColumnSpec): AnchoredPColumnId;\n\n /**\n * Derives an anchored column identifier from a column specification\n * @param spec Column specification to anchor\n * @param axisFilters Axis filters to apply to the column\n * @returns An anchored and sliced column identifier that can be used to identify columns similar to the input specification\n */\n derive(spec: PColumnSpec, axisFilters?: AxisFilter[]): UniversalPColumnId;\n\n /**\n * Implementation of derive method\n */\n derive(spec: PColumnSpec, axisFilters?: AxisFilter[]): UniversalPColumnId {\n const result: AnchoredPColumnId = {\n name: spec.name,\n axes: [],\n };\n\n let skipDomains: Set<string> | undefined = undefined;\n if (spec.domain !== undefined) {\n outer: for (const domainPack of this.domainPacks) {\n const dAnchor: string[][] = [];\n for (const domainKey of domainPack) {\n const dValue = spec.domain[domainKey];\n if (dValue !== undefined) dAnchor.push([domainKey, dValue]);\n else break outer;\n }\n const domainAnchor = this.domainPackToAnchor.get(JSON.stringify(dAnchor));\n if (domainAnchor !== undefined) {\n result.domainAnchor = domainAnchor;\n skipDomains = new Set(domainPack);\n break;\n }\n }\n }\n\n for (const [dKey, dValue] of Object.entries(spec.domain ?? {})) {\n if (skipDomains !== undefined && skipDomains.has(dKey)) continue;\n const key = domainKey(dKey, dValue);\n const anchorId = this.domains.get(key);\n result.domain ??= {};\n result.domain[dKey] = anchorId ? { anchor: anchorId } : dValue;\n }\n\n let skipContextDomains: Set<string> | undefined = undefined;\n if (spec.contextDomain !== undefined) {\n outer: for (const contextDomainPack of this.contextDomainPacks) {\n const dAnchor: string[][] = [];\n for (const domainKey of contextDomainPack) {\n const dValue = spec.contextDomain[domainKey];\n if (dValue !== undefined) dAnchor.push([domainKey, dValue]);\n else break outer;\n }\n const contextDomainAnchor = this.contextDomainPackToAnchor.get(JSON.stringify(dAnchor));\n if (contextDomainAnchor !== undefined) {\n result.contextDomainAnchor = contextDomainAnchor;\n skipContextDomains = new Set(contextDomainPack);\n break;\n }\n }\n }\n\n for (const [dKey, dValue] of Object.entries(spec.contextDomain ?? {})) {\n if (skipContextDomains !== undefined && skipContextDomains.has(dKey)) continue;\n const key = domainKey(dKey, dValue);\n const anchorId = this.contextDomains.get(key);\n result.contextDomain ??= {};\n result.contextDomain[dKey] = anchorId ? { anchor: anchorId } : dValue;\n }\n\n result.axes = spec.axesSpec.map((axis) => {\n const key = axisKey(axis);\n const anchorAxisRef = this.axes.get(key);\n if (anchorAxisRef === undefined) return getAxisId(axis);\n else return anchorAxisRef;\n });\n\n // If no axis filters are provided, return the anchored ID as is\n if (!axisFilters || axisFilters.length === 0) {\n return result;\n }\n\n // Process axis filters and create a sliced column ID\n const resolvedFilters: [number, AxisFilterValue][] = [];\n\n for (const filter of axisFilters) {\n const [axisIdOrIndex, value] = filter;\n\n // If it's already a numeric index, validate it\n if (typeof axisIdOrIndex === \"number\") {\n if (axisIdOrIndex < 0 || axisIdOrIndex >= spec.axesSpec.length) {\n throw new Error(\n `Axis index ${axisIdOrIndex} is out of bounds (0-${spec.axesSpec.length - 1})`,\n );\n }\n resolvedFilters.push([axisIdOrIndex, value]);\n } else {\n // If it's a string (axis name), resolve it to an index\n const axisIndex = spec.axesSpec.findIndex((axis) => axis.name === axisIdOrIndex);\n if (axisIndex === -1) {\n throw new Error(\n `Axis with name \"${axisIdOrIndex}\" not found in the column specification`,\n );\n }\n resolvedFilters.push([axisIndex, value]);\n }\n }\n\n // Sort filters by axis index to ensure consistency\n resolvedFilters.sort((a, b) => a[0] - b[0]);\n\n return {\n source: result,\n axisFilters: resolvedFilters,\n };\n }\n\n /**\n * Derives a canonicalized string representation of an anchored column identifier, can be used as a unique identifier for the column\n * @param spec Column specification to anchor\n * @param axisFilters Optional axis filters to apply to the column\n * @returns A canonicalized string representation of the anchored column identifier\n */\n deriveS(spec: PColumnSpec, axisFilters?: AxisFilter[]): SUniversalPColumnId {\n return stringifyColumnId(this.derive(spec, axisFilters));\n }\n}\n\n/**\n * Options for the resolveAnchors function\n */\nexport type ResolveAnchorsOptions = {\n /**\n * If true, missing domain keys in anchors will be ignored.\n * If false (default), an error will be thrown.\n */\n ignoreMissingDomains?: boolean;\n};\n\n/**\n * Resolves anchored references in a column matcher to create a non-anchored matcher.\n * Doing an opposite operation to {@link AnchorIdDeriver.derive()}.\n *\n * @param anchors - Record of anchor column specifications indexed by anchor id\n * @param matcher - An anchored column matcher (or id, which is subtype of it) containing references that need to be resolved\n * @param options - Options for resolving anchors\n * @returns A non-anchored column matcher with all references resolved to actual values\n */\nexport function resolveAnchors(\n anchors: Record<string, PColumnSpec>,\n matcher: AnchoredPColumnSelector,\n options?: ResolveAnchorsOptions,\n): PColumnSelector {\n const result = { ...matcher };\n const ignoreMissingDomains = options?.ignoreMissingDomains ?? false;\n\n if (result.domainAnchor !== undefined) {\n const anchorSpec = anchors[result.domainAnchor];\n if (!anchorSpec) throw new Error(`Anchor \"${result.domainAnchor}\" not found`);\n\n const anchorDomains = anchorSpec.domain || {};\n result.domain = { ...anchorDomains, ...result.domain };\n delete result.domainAnchor;\n }\n\n if (result.domain) {\n const resolvedDomain: Record<string, string> = {};\n for (const [key, value] of Object.entries(result.domain)) {\n if (typeof value === \"string\") {\n resolvedDomain[key] = value;\n } else {\n // It's an AnchorDomainRef\n const anchorSpec = anchors[value.anchor];\n if (!anchorSpec)\n throw new Error(`Anchor \"${value.anchor}\" not found for domain key \"${key}\"`);\n\n if (!anchorSpec.domain || anchorSpec.domain[key] === undefined) {\n if (!ignoreMissingDomains)\n throw new Error(`Domain key \"${key}\" not found in anchor \"${value.anchor}\"`);\n continue;\n }\n\n resolvedDomain[key] = anchorSpec.domain[key];\n }\n }\n result.domain = resolvedDomain;\n }\n\n if (result.contextDomainAnchor !== undefined) {\n const anchorSpec = anchors[result.contextDomainAnchor];\n if (!anchorSpec) throw new Error(`Anchor \"${result.contextDomainAnchor}\" not found`);\n\n const anchorContextDomains = anchorSpec.contextDomain || {};\n result.contextDomain = { ...anchorContextDomains, ...result.contextDomain };\n delete result.contextDomainAnchor;\n }\n\n if (result.contextDomain) {\n const resolvedContextDomain: Record<string, string> = {};\n for (const [key, value] of Object.entries(result.contextDomain)) {\n if (typeof value === \"string\") {\n resolvedContextDomain[key] = value;\n } else {\n // It's an AnchorDomainRef\n const anchorSpec = anchors[value.anchor];\n if (!anchorSpec)\n throw new Error(`Anchor \"${value.anchor}\" not found for contextDomain key \"${key}\"`);\n\n if (!anchorSpec.contextDomain || anchorSpec.contextDomain[key] === undefined) {\n if (!ignoreMissingDomains)\n throw new Error(`Context domain key \"${key}\" not found in anchor \"${value.anchor}\"`);\n continue;\n }\n\n resolvedContextDomain[key] = anchorSpec.contextDomain[key];\n }\n }\n result.contextDomain = resolvedContextDomain;\n }\n\n if (result.axes) result.axes = result.axes.map((axis) => resolveAxisReference(anchors, axis));\n\n return result as PColumnSelector;\n}\n\n/**\n * Resolves an anchored axis reference to a concrete AxisId\n */\nfunction resolveAxisReference(\n anchors: Record<string, PColumnSpec>,\n axisRef: AAxisSelector,\n): AxisSelector {\n if (!isAnchorAxisRef(axisRef)) return axisRef;\n\n // It's an anchored reference\n const anchorId = axisRef.anchor;\n const anchorSpec = anchors[anchorId];\n if (!anchorSpec) throw new Error(`Anchor \"${anchorId}\" not found for axis reference`);\n\n if (\"idx\" in axisRef) {\n // AnchorAxisRefByIdx\n if (axisRef.idx < 0 || axisRef.idx >= anchorSpec.axesSpec.length)\n throw new Error(`Axis index ${axisRef.idx} out of bounds for anchor \"${anchorId}\"`);\n return anchorSpec.axesSpec[axisRef.idx];\n } else if (\"name\" in axisRef) {\n // AnchorAxisRefByName\n const matches = anchorSpec.axesSpec.filter((axis) => axis.name === axisRef.name);\n if (matches.length > 1)\n throw new Error(`Multiple axes with name \"${axisRef.name}\" found in anchor \"${anchorId}\"`);\n if (matches.length === 0)\n throw new Error(`Axis with name \"${axisRef.name}\" not found in anchor \"${anchorId}\"`);\n return matches[0];\n } else if (\"id\" in axisRef) {\n // AnchorAxisRefByMatcher\n const matches = anchorSpec.axesSpec.filter((axis) => matchAxisId(axisRef.id, getAxisId(axis)));\n if (matches.length > 1)\n throw new Error(`Multiple matching axes found for matcher in anchor \"${anchorId}\"`);\n if (matches.length === 0)\n throw new Error(`No matching axis found for matcher in anchor \"${anchorId}\"`);\n return matches[0];\n }\n\n throw new Error(`Unsupported axis reference type`);\n}\n\n/**\n * Type guard to check if a value is an anchored axis reference\n */\nfunction isAnchorAxisRef(value: AAxisSelector): value is AnchorAxisRef {\n return typeof value === \"object\" && \"anchor\" in value;\n}\n"],"mappings":";;;;;AAoBA,SAAS,QAAQ,MAAsB;AACrC,QAAO,aAAa,UAAU,KAAK,CAAC;;AAGtC,SAAS,UAAU,KAAa,OAAuB;AACrD,QAAO,KAAK,UAAU,CAAC,KAAK,MAAM,CAAC;;;;;;AAOrC,IAAa,oBAAb,MAA+B;CAC7B,AAAiB,0BAAU,IAAI,KAAqB;CACpD,AAAiB,iCAAiB,IAAI,KAAqB;CAC3D,AAAiB,uBAAO,IAAI,KAAiC;;;;;CAK7D,AAAiB,cAA0B,EAAE;CAC7C,AAAiB,qBAAiC,EAAE;;;;CAIpD,AAAiB,qCAAqB,IAAI,KAAqB;CAC/D,AAAiB,4CAA4B,IAAI,KAAqB;;;;;CAMtE,YAAY,AAAgB,SAAsC;EAAtC;EAC1B,MAAM,gBAAgB,OAAO,QAAQ,QAAQ;AAC7C,gBAAc,MAAM,GAAG,MAAM,EAAE,GAAG,cAAc,EAAE,GAAG,CAAC;AACtD,OAAK,MAAM,CAAC,UAAU,SAAS,eAAe;AAC5C,QAAK,IAAI,UAAU,GAAG,UAAU,KAAK,SAAS,QAAQ,WAAW;IAC/D,MAAM,OAAO,KAAK,SAAS;IAC3B,MAAM,MAAM,QAAQ,KAAK;AACzB,SAAK,KAAK,IAAI,KAAK;KAAE,QAAQ;KAAU,KAAK;KAAS,CAAC;;AAExD,OAAI,KAAK,WAAW,QAAW;IAC7B,MAAM,gBAAgB,OAAO,QAAQ,KAAK,OAAO;AACjD,kBAAc,MAAM,GAAG,MAAM,EAAE,GAAG,cAAc,EAAE,GAAG,CAAC;AAEtD,SAAK,mBAAmB,IAAI,KAAK,UAAU,cAAc,EA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AG;AACrF,SAAO,WAAW,SAAS,QAAQ;YAC1B,UAAU,SAAS;EAE5B,MAAM,UAAU,WAAW,SAAS,QAAQ,SAAS,KAAK,SAAS,QAAQ,KAAK;AAChF,MAAI,QAAQ,SAAS,EACnB,OAAM,IAAI,MAAM,4BAA4B,QAAQ,KAAK,qBAAqB,SAAS,GAAG;AAC5F,MAAI,QAAQ,WAAW,EACrB,OAAM,IAAI,MAAM,mBAAmB,QAAQ,KAAK,yBAAyB,SAAS,GAAG;AACvF,SAAO,QAAQ;YACN,QAAQ,SAAS;EAE1B,MAAM,UAAU,WAAW,SAAS,QAAQ,SAAS,YAAY,QAAQ,IAAI,UAAU,KAAK,CAAC,CAAC;AAC9F,MAAI,QAAQ,SAAS,EACnB,OAAM,IAAI,MAAM,uDAAuD,SAAS,GAAG;AACrF,MAAI,QAAQ,WAAW,EACrB,OAAM,IAAI,MAAM,iDAAiD,SAAS,GAAG;AAC/E,SAAO,QAAQ;;AAGjB,OAAM,IAAI,MAAM,kCAAkC;;;;;AAMpD,SAAS,gBAAgB,OAA8C;AACrE,QAAO,OAAO,UAAU,YAAY,YAAY"}
|
|
1
|
+
{"version":3,"file":"anchored.js","names":[],"sources":["../../../../src/drivers/pframe/spec/anchored.ts"],"sourcesContent":["import canonicalize from \"canonicalize\";\nimport type { AxisFilter, AxisFilterValue } from \"./filtered_column\";\nimport type { SUniversalPColumnId, UniversalPColumnId } from \"./ids\";\nimport { stringifyColumnId } from \"./ids\";\nimport type {\n AAxisSelector,\n AnchorAxisRef,\n AnchorAxisRefByIdx,\n AnchoredPColumnId,\n AnchoredPColumnSelector,\n LegacyAxisSelector,\n PColumnSelector,\n} from \"./selectors\";\nimport type { AxisId, PColumnSpec } from \"./spec\";\nimport { getAxisId, matchAxisId } from \"./spec\";\n\n//\n// Helper functions\n//\n\nfunction axisKey(axis: AxisId): string {\n return canonicalize(getAxisId(axis))!;\n}\n\nfunction domainKey(key: string, value: string): string {\n return JSON.stringify([key, value]);\n}\n\n/**\n * Context for resolving and generating anchored references to columns and axes\n * Maintains maps of known domain values and axes that can be referenced by anchors\n */\nexport class AnchoredIdDeriver {\n private readonly domains = new Map<string, string>();\n private readonly contextDomains = new Map<string, string>();\n private readonly axes = new Map<string, AnchorAxisRefByIdx>();\n /**\n * Domain packs are used to group domain keys that can be anchored to the same anchor\n * This is used to optimize the lookup of domain anchors\n */\n private readonly domainPacks: string[][] = [];\n private readonly contextDomainPacks: string[][] = [];\n /**\n * Maps domain packs to anchors\n */\n private readonly domainPackToAnchor = new Map<string, string>();\n private readonly contextDomainPackToAnchor = new Map<string, string>();\n\n /**\n * Creates a new anchor context from a set of anchor column specifications\n * @param anchors Record of anchor column specifications indexed by anchor ID\n */\n constructor(public readonly anchors: Record<string, PColumnSpec>) {\n const anchorEntries = Object.entries(anchors);\n anchorEntries.sort((a, b) => a[0].localeCompare(b[0]));\n for (const [anchorId, spec] of anchorEntries) {\n for (let axisIdx = 0; axisIdx < spec.axesSpec.length; axisIdx++) {\n const axis = spec.axesSpec[axisIdx];\n const key = axisKey(axis);\n this.axes.set(key, { anchor: anchorId, idx: axisIdx });\n }\n if (spec.domain !== undefined) {\n const domainEntries = Object.entries(spec.domain);\n domainEntries.sort((a, b) => a[0].localeCompare(b[0]));\n\n this.domainPackToAnchor.set(JSON.stringify(domainEntries), anchorId);\n this.domainPacks.push(domainEntries.map(([dKey]) => dKey));\n\n for (const [dKey, dValue] of domainEntries) {\n const key = domainKey(dKey, dValue);\n this.domains.set(key, anchorId);\n }\n }\n if (spec.contextDomain !== undefined) {\n const contextDomainEntries = Object.entries(spec.contextDomain);\n contextDomainEntries.sort((a, b) => a[0].localeCompare(b[0]));\n\n this.contextDomainPackToAnchor.set(JSON.stringify(contextDomainEntries), anchorId);\n this.contextDomainPacks.push(contextDomainEntries.map(([dKey]) => dKey));\n\n for (const [dKey, dValue] of contextDomainEntries) {\n const key = domainKey(dKey, dValue);\n this.contextDomains.set(key, anchorId);\n }\n }\n }\n }\n\n /**\n * Derives an anchored column identifier from a column specification\n * @param spec Column specification to anchor\n * @returns An anchored column identifier that can be used to identify columns similar to the input specification\n */\n derive(spec: PColumnSpec): AnchoredPColumnId;\n\n /**\n * Derives an anchored column identifier from a column specification\n * @param spec Column specification to anchor\n * @param axisFilters Axis filters to apply to the column\n * @returns An anchored and sliced column identifier that can be used to identify columns similar to the input specification\n */\n derive(spec: PColumnSpec, axisFilters?: AxisFilter[]): UniversalPColumnId;\n\n /**\n * Implementation of derive method\n */\n derive(spec: PColumnSpec, axisFilters?: AxisFilter[]): UniversalPColumnId {\n const result: AnchoredPColumnId = {\n name: spec.name,\n axes: [],\n };\n\n let skipDomains: Set<string> | undefined = undefined;\n if (spec.domain !== undefined) {\n outer: for (const domainPack of this.domainPacks) {\n const dAnchor: string[][] = [];\n for (const domainKey of domainPack) {\n const dValue = spec.domain[domainKey];\n if (dValue !== undefined) dAnchor.push([domainKey, dValue]);\n else break outer;\n }\n const domainAnchor = this.domainPackToAnchor.get(JSON.stringify(dAnchor));\n if (domainAnchor !== undefined) {\n result.domainAnchor = domainAnchor;\n skipDomains = new Set(domainPack);\n break;\n }\n }\n }\n\n for (const [dKey, dValue] of Object.entries(spec.domain ?? {})) {\n if (skipDomains !== undefined && skipDomains.has(dKey)) continue;\n const key = domainKey(dKey, dValue);\n const anchorId = this.domains.get(key);\n result.domain ??= {};\n result.domain[dKey] = anchorId ? { anchor: anchorId } : dValue;\n }\n\n let skipContextDomains: Set<string> | undefined = undefined;\n if (spec.contextDomain !== undefined) {\n outer: for (const contextDomainPack of this.contextDomainPacks) {\n const dAnchor: string[][] = [];\n for (const domainKey of contextDomainPack) {\n const dValue = spec.contextDomain[domainKey];\n if (dValue !== undefined) dAnchor.push([domainKey, dValue]);\n else break outer;\n }\n const contextDomainAnchor = this.contextDomainPackToAnchor.get(JSON.stringify(dAnchor));\n if (contextDomainAnchor !== undefined) {\n result.contextDomainAnchor = contextDomainAnchor;\n skipContextDomains = new Set(contextDomainPack);\n break;\n }\n }\n }\n\n for (const [dKey, dValue] of Object.entries(spec.contextDomain ?? {})) {\n if (skipContextDomains !== undefined && skipContextDomains.has(dKey)) continue;\n const key = domainKey(dKey, dValue);\n const anchorId = this.contextDomains.get(key);\n result.contextDomain ??= {};\n result.contextDomain[dKey] = anchorId ? { anchor: anchorId } : dValue;\n }\n\n result.axes = spec.axesSpec.map((axis) => {\n const key = axisKey(axis);\n const anchorAxisRef = this.axes.get(key);\n if (anchorAxisRef === undefined) return getAxisId(axis);\n else return anchorAxisRef;\n });\n\n // If no axis filters are provided, return the anchored ID as is\n if (!axisFilters || axisFilters.length === 0) {\n return result;\n }\n\n // Process axis filters and create a sliced column ID\n const resolvedFilters: [number, AxisFilterValue][] = [];\n\n for (const filter of axisFilters) {\n const [axisIdOrIndex, value] = filter;\n\n // If it's already a numeric index, validate it\n if (typeof axisIdOrIndex === \"number\") {\n if (axisIdOrIndex < 0 || axisIdOrIndex >= spec.axesSpec.length) {\n throw new Error(\n `Axis index ${axisIdOrIndex} is out of bounds (0-${spec.axesSpec.length - 1})`,\n );\n }\n resolvedFilters.push([axisIdOrIndex, value]);\n } else {\n // If it's a string (axis name), resolve it to an index\n const axisIndex = spec.axesSpec.findIndex((axis) => axis.name === axisIdOrIndex);\n if (axisIndex === -1) {\n throw new Error(\n `Axis with name \"${axisIdOrIndex}\" not found in the column specification`,\n );\n }\n resolvedFilters.push([axisIndex, value]);\n }\n }\n\n // Sort filters by axis index to ensure consistency\n resolvedFilters.sort((a, b) => a[0] - b[0]);\n\n return {\n source: result,\n axisFilters: resolvedFilters,\n };\n }\n\n /**\n * Derives a canonicalized string representation of an anchored column identifier, can be used as a unique identifier for the column\n * @param spec Column specification to anchor\n * @param axisFilters Optional axis filters to apply to the column\n * @returns A canonicalized string representation of the anchored column identifier\n */\n deriveS(spec: PColumnSpec, axisFilters?: AxisFilter[]): SUniversalPColumnId {\n return stringifyColumnId(this.derive(spec, axisFilters));\n }\n}\n\n/**\n * Options for the resolveAnchors function\n */\nexport type ResolveAnchorsOptions = {\n /**\n * If true, missing domain keys in anchors will be ignored.\n * If false (default), an error will be thrown.\n */\n ignoreMissingDomains?: boolean;\n};\n\n/**\n * Resolves anchored references in a column matcher to create a non-anchored matcher.\n * Doing an opposite operation to {@link AnchorIdDeriver.derive()}.\n *\n * @param anchors - Record of anchor column specifications indexed by anchor id\n * @param matcher - An anchored column matcher (or id, which is subtype of it) containing references that need to be resolved\n * @param options - Options for resolving anchors\n * @returns A non-anchored column matcher with all references resolved to actual values\n */\nexport function resolveAnchors(\n anchors: Record<string, PColumnSpec>,\n matcher: AnchoredPColumnSelector,\n options?: ResolveAnchorsOptions,\n): PColumnSelector {\n const result = { ...matcher };\n const ignoreMissingDomains = options?.ignoreMissingDomains ?? false;\n\n if (result.domainAnchor !== undefined) {\n const anchorSpec = anchors[result.domainAnchor];\n if (!anchorSpec) throw new Error(`Anchor \"${result.domainAnchor}\" not found`);\n\n const anchorDomains = anchorSpec.domain || {};\n result.domain = { ...anchorDomains, ...result.domain };\n delete result.domainAnchor;\n }\n\n if (result.domain) {\n const resolvedDomain: Record<string, string> = {};\n for (const [key, value] of Object.entries(result.domain)) {\n if (typeof value === \"string\") {\n resolvedDomain[key] = value;\n } else {\n // It's an AnchorDomainRef\n const anchorSpec = anchors[value.anchor];\n if (!anchorSpec)\n throw new Error(`Anchor \"${value.anchor}\" not found for domain key \"${key}\"`);\n\n if (!anchorSpec.domain || anchorSpec.domain[key] === undefined) {\n if (!ignoreMissingDomains)\n throw new Error(`Domain key \"${key}\" not found in anchor \"${value.anchor}\"`);\n continue;\n }\n\n resolvedDomain[key] = anchorSpec.domain[key];\n }\n }\n result.domain = resolvedDomain;\n }\n\n if (result.contextDomainAnchor !== undefined) {\n const anchorSpec = anchors[result.contextDomainAnchor];\n if (!anchorSpec) throw new Error(`Anchor \"${result.contextDomainAnchor}\" not found`);\n\n const anchorContextDomains = anchorSpec.contextDomain || {};\n result.contextDomain = { ...anchorContextDomains, ...result.contextDomain };\n delete result.contextDomainAnchor;\n }\n\n if (result.contextDomain) {\n const resolvedContextDomain: Record<string, string> = {};\n for (const [key, value] of Object.entries(result.contextDomain)) {\n if (typeof value === \"string\") {\n resolvedContextDomain[key] = value;\n } else {\n // It's an AnchorDomainRef\n const anchorSpec = anchors[value.anchor];\n if (!anchorSpec)\n throw new Error(`Anchor \"${value.anchor}\" not found for contextDomain key \"${key}\"`);\n\n if (!anchorSpec.contextDomain || anchorSpec.contextDomain[key] === undefined) {\n if (!ignoreMissingDomains)\n throw new Error(`Context domain key \"${key}\" not found in anchor \"${value.anchor}\"`);\n continue;\n }\n\n resolvedContextDomain[key] = anchorSpec.contextDomain[key];\n }\n }\n result.contextDomain = resolvedContextDomain;\n }\n\n if (result.axes) result.axes = result.axes.map((axis) => resolveAxisReference(anchors, axis));\n\n return result as PColumnSelector;\n}\n\n/**\n * Resolves an anchored axis reference to a concrete AxisId\n */\nfunction resolveAxisReference(\n anchors: Record<string, PColumnSpec>,\n axisRef: AAxisSelector,\n): LegacyAxisSelector {\n if (!isAnchorAxisRef(axisRef)) return axisRef;\n\n // It's an anchored reference\n const anchorId = axisRef.anchor;\n const anchorSpec = anchors[anchorId];\n if (!anchorSpec) throw new Error(`Anchor \"${anchorId}\" not found for axis reference`);\n\n if (\"idx\" in axisRef) {\n // AnchorAxisRefByIdx\n if (axisRef.idx < 0 || axisRef.idx >= anchorSpec.axesSpec.length)\n throw new Error(`Axis index ${axisRef.idx} out of bounds for anchor \"${anchorId}\"`);\n return anchorSpec.axesSpec[axisRef.idx];\n } else if (\"name\" in axisRef) {\n // AnchorAxisRefByName\n const matches = anchorSpec.axesSpec.filter((axis) => axis.name === axisRef.name);\n if (matches.length > 1)\n throw new Error(`Multiple axes with name \"${axisRef.name}\" found in anchor \"${anchorId}\"`);\n if (matches.length === 0)\n throw new Error(`Axis with name \"${axisRef.name}\" not found in anchor \"${anchorId}\"`);\n return matches[0];\n } else if (\"id\" in axisRef) {\n // AnchorAxisRefByMatcher\n const matches = anchorSpec.axesSpec.filter((axis) => matchAxisId(axisRef.id, getAxisId(axis)));\n if (matches.length > 1)\n throw new Error(`Multiple matching axes found for matcher in anchor \"${anchorId}\"`);\n if (matches.length === 0)\n throw new Error(`No matching axis found for matcher in anchor \"${anchorId}\"`);\n return matches[0];\n }\n\n throw new Error(`Unsupported axis reference type`);\n}\n\n/**\n * Type guard to check if a value is an anchored axis reference\n */\nfunction isAnchorAxisRef(value: AAxisSelector): value is AnchorAxisRef {\n return typeof value === \"object\" && \"anchor\" in value;\n}\n"],"mappings":";;;;;AAoBA,SAAS,QAAQ,MAAsB;AACrC,QAAO,aAAa,UAAU,KAAK,CAAC;;AAGtC,SAAS,UAAU,KAAa,OAAuB;AACrD,QAAO,KAAK,UAAU,CAAC,KAAK,MAAM,CAAC;;;;;;AAOrC,IAAa,oBAAb,MAA+B;CAC7B,AAAiB,0BAAU,IAAI,KAAqB;CACpD,AAAiB,iCAAiB,IAAI,KAAqB;CAC3D,AAAiB,uBAAO,IAAI,KAAiC;;;;;CAK7D,AAAiB,cAA0B,EAAE;CAC7C,AAAiB,qBAAiC,EAAE;;;;CAIpD,AAAiB,qCAAqB,IAAI,KAAqB;CAC/D,AAAiB,4CAA4B,IAAI,KAAqB;;;;;CAMtE,YAAY,AAAgB,SAAsC;EAAtC;EAC1B,MAAM,gBAAgB,OAAO,QAAQ,QAAQ;AAC7C,gBAAc,MAAM,GAAG,MAAM,EAAE,GAAG,cAAc,EAAE,GAAG,CAAC;AACtD,OAAK,MAAM,CAAC,UAAU,SAAS,eAAe;AAC5C,QAAK,IAAI,UAAU,GAAG,UAAU,KAAK,SAAS,QAAQ,WAAW;IAC/D,MAAM,OAAO,KAAK,SAAS;IAC3B,MAAM,MAAM,QAAQ,KAAK;AACzB,SAAK,KAAK,IAAI,KAAK;KAAE,QAAQ;KAAU,KAAK;KAAS,CAAC;;AAExD,OAAI,KAAK,WAAW,QAAW;IAC7B,MAAM,gBAAgB,OAAO,QAAQ,KAAK,OAAO;A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AEpB,MAAI,QAAQ,MAAM,KAAK,QAAQ,OAAO,WAAW,SAAS,OACxD,OAAM,IAAI,MAAM,cAAc,QAAQ,IAAI,6BAA6B,SAAS,GAAG;AACrF,SAAO,WAAW,SAAS,QAAQ;YAC1B,UAAU,SAAS;EAE5B,MAAM,UAAU,WAAW,SAAS,QAAQ,SAAS,KAAK,SAAS,QAAQ,KAAK;AAChF,MAAI,QAAQ,SAAS,EACnB,OAAM,IAAI,MAAM,4BAA4B,QAAQ,KAAK,qBAAqB,SAAS,GAAG;AAC5F,MAAI,QAAQ,WAAW,EACrB,OAAM,IAAI,MAAM,mBAAmB,QAAQ,KAAK,yBAAyB,SAAS,GAAG;AACvF,SAAO,QAAQ;YACN,QAAQ,SAAS;EAE1B,MAAM,UAAU,WAAW,SAAS,QAAQ,SAAS,YAAY,QAAQ,IAAI,UAAU,KAAK,CAAC,CAAC;AAC9F,MAAI,QAAQ,SAAS,EACnB,OAAM,IAAI,MAAM,uDAAuD,SAAS,GAAG;AACrF,MAAI,QAAQ,WAAW,EACrB,OAAM,IAAI,MAAM,iDAAiD,SAAS,GAAG;AAC/E,SAAO,QAAQ;;AAGjB,OAAM,IAAI,MAAM,kCAAkC;;;;;AAMpD,SAAS,gBAAgB,OAA8C;AACrE,QAAO,OAAO,UAAU,YAAY,YAAY"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Annotation, AnnotationJson, AxesId, AxesSpec, AxisId, AxisSpec, AxisSpecNormalized, AxisTree, AxisValueType, ColumnValueType, Domain, DomainJson, Metadata, MetadataJson, PAxisName, PColumn, PColumnIdAndSpec, PColumnInfo, PColumnLazy, PColumnName, PColumnSpec, PColumnSpecId, PDataColumnSpec, PUniversalColumnSpec, ValueType, canonicalizeAxisId, canonicalizeAxisWithParents, getArrayFromAxisTree, getAxesId, getAxesTree, getAxisId, getColumnIdAndSpec, getDenormalizedAxesList, getNormalizedAxesList, getPColumnSpecId, getSetFromAxisTree, getTypeFromPColumnOrAxisSpec, isAxisId, isLabelColumn, isLinkerColumn, matchAxisId, readAnnotation, readAnnotationJson, readAnnotationJsonOrThrow, readDomain, readDomainJson, readDomainJsonOrThrow, readMetadata, readMetadataJson, readMetadataJsonOrThrow } from "./spec.js";
|
|
2
|
-
import { AAxisSelector, ADomain, AnchorAxisIdOrRefBasic, AnchorAxisRef, AnchorAxisRefByIdx, AnchorAxisRefByMatcher, AnchorAxisRefByName, AnchorDomainRef, AnchoredColumnMatchStrategy, AnchoredPColumnId, AnchoredPColumnSelector,
|
|
2
|
+
import { AAxisSelector, ADomain, AnchorAxisIdOrRefBasic, AnchorAxisRef, AnchorAxisRefByIdx, AnchorAxisRefByMatcher, AnchorAxisRefByName, AnchorDomainRef, AnchoredColumnMatchStrategy, AnchoredPColumnId, AnchoredPColumnSelector, LegacyAxisSelector, PColumnSelector, SingleAxisSelector, isAnchoredPColumnId, legacyColumnSelectorsToPredicate, matchAxis, matchPColumn } from "./selectors.js";
|
|
3
3
|
import { AxisFilter, AxisFilterByIdx, AxisFilterByName, AxisFilterValue, FilteredPColumn, FilteredPColumnId, isFilteredPColumn } from "./filtered_column.js";
|
|
4
4
|
import { SUniversalPColumnId, UniversalPColumnId, parseColumnId, stringifyColumnId } from "./ids.js";
|
|
5
5
|
import { AnchoredIdDeriver, ResolveAnchorsOptions, resolveAnchors } from "./anchored.js";
|
|
@@ -2,5 +2,5 @@ import { Annotation, AnnotationJson, Domain, DomainJson, PAxisName, PColumnName,
|
|
|
2
2
|
import { parseColumnId, stringifyColumnId } from "./ids.js";
|
|
3
3
|
import { AnchoredIdDeriver, resolveAnchors } from "./anchored.js";
|
|
4
4
|
import { isFilteredPColumn } from "./filtered_column.js";
|
|
5
|
-
import { isAnchoredPColumnId, matchAxis, matchPColumn
|
|
5
|
+
import { isAnchoredPColumnId, legacyColumnSelectorsToPredicate, matchAxis, matchPColumn } from "./selectors.js";
|
|
6
6
|
import { deriveNativeId } from "./native_id.js";
|
|
@@ -85,14 +85,14 @@ function matchPColumn(pcolumn, selector) {
|
|
|
85
85
|
* or an array of PColumnSelectors, or a single PColumnSelector
|
|
86
86
|
* @returns A function that takes a PColumnSpec and returns a boolean
|
|
87
87
|
*/
|
|
88
|
-
function
|
|
88
|
+
function legacyColumnSelectorsToPredicate(predicateOrSelectors) {
|
|
89
89
|
if (Array.isArray(predicateOrSelectors)) return (spec) => predicateOrSelectors.some((selector) => require_spec$1.isPColumnSpec(spec) && matchPColumn(spec, selector));
|
|
90
90
|
else return (spec) => require_spec$1.isPColumnSpec(spec) && matchPColumn(spec, predicateOrSelectors);
|
|
91
91
|
}
|
|
92
92
|
|
|
93
93
|
//#endregion
|
|
94
94
|
exports.isAnchoredPColumnId = isAnchoredPColumnId;
|
|
95
|
+
exports.legacyColumnSelectorsToPredicate = legacyColumnSelectorsToPredicate;
|
|
95
96
|
exports.matchAxis = matchAxis;
|
|
96
97
|
exports.matchPColumn = matchPColumn;
|
|
97
|
-
exports.selectorsToPredicate = selectorsToPredicate;
|
|
98
98
|
//# sourceMappingURL=selectors.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"selectors.cjs","names":["getAxisId","isPColumnSpec"],"sources":["../../../../src/drivers/pframe/spec/selectors.ts"],"sourcesContent":["import { isPColumnSpec, type PObjectSpec } from \"../../../pool\";\nimport type { AxisId, AxisValueType, Domain, PColumnSpec, ValueType } from \"./spec\";\nimport { getAxisId } from \"./spec\";\n\n/**\n * Defines a pattern for matching axes within the PFrame data model.\n *\n * AxisSelector provides a flexible way to identify axes based on their\n * properties. All fields are optional, allowing for partial matching.\n * When multiple properties are specified, all must match for an axis\n * to be selected (logical AND).\n *\n * This interface is used in various selection and matching operations\n * throughout the PFrame system, such as column queries and axis lookups.\n */\nexport interface AxisSelector {\n /**\n * Optional value type to match against.\n * When specified, only axes with this exact type will match.\n * Can be a single type or an array of types to match against any of them.\n * Valid types include: 'Int', 'Long', 'Float', 'Double', 'String', 'Bytes'.\n */\n type?: ValueType | ValueType[];\n\n /**\n * Optional name to match against.\n * When specified, only axes with this exact name will match.\n */\n name?: string;\n\n /**\n * Optional domain key-value pairs to match against.\n * Domains provide additional context to uniquely identify an axis beyond its name and type.\n * When specified, an axis will match only if it contains all the key-value pairs defined here.\n * An axis with additional domain entries not present in this selector will still match.\n */\n domain?: Record<string, string>;\n\n /**\n * Optional context domain key-value pairs to match against.\n * Context domains are matched by kinship rules (subset/superset/overlap) rather than exact equality.\n * When specified, an axis will match only if it contains all the key-value pairs defined here.\n */\n contextDomain?: Record<string, string>;\n}\n\n/** Single axis selector */\nexport interface SingleAxisSelector {\n /** Axis name (required) */\n name: string;\n /** Axis type (optional) */\n type?: AxisValueType;\n /** Domain requirements (optional) */\n domain?: Domain;\n /** Parent axes requirements (optional) */\n parentAxes?: SingleAxisSelector[];\n}\n\n/**\n * Reference to an axis by its numerical index within the anchor column's axes array\n * Format: [anchorId, axisIndex]\n */\nexport type AnchorAxisRefByIdx = { anchor: string; idx: number };\n\n/**\n * Reference to an axis by its name within the anchor column\n * Format: [anchorId, axisName]\n */\nexport type AnchorAxisRefByName = { anchor: string; name: string };\n\n/**\n * Reference to an axis using an AxisId matcher within the anchor\n * Format: [anchorId, axisMatcher]\n */\nexport type AnchorAxisRefByMatcher = { anchor: string; id: AxisId };\n\n/**\n * Basic anchor axis reference that can be either by index or a direct AxisId\n */\nexport type AnchorAxisIdOrRefBasic = AnchorAxisRefByIdx | AxisId;\n\n/** Union of all possible ways to reference an axis in an anchored context */\nexport type AnchorAxisRef = AnchorAxisRefByIdx | AnchorAxisRefByName | AnchorAxisRefByMatcher;\n\n/** Reference to a domain value through an anchor */\nexport type AnchorDomainRef = { anchor: string };\n\n/**\n * Domain value that can be either a direct string value or a reference to a domain through an anchor\n * Used to establish domain context that can be resolved relative to other anchored columns\n */\nexport type ADomain = string | AnchorDomainRef;\n/**\n * Axis identifier that can be either a direct AxisId or a reference to an axis through an anchor\n * Allows referring to axes in a way that can be resolved in different contexts\n */\nexport type AAxisSelector = AxisSelector | AnchorAxisRef;\n\n/**\n * Match resolution strategy for PColumns\n * Specifies how to handle when multiple columns match the criteria\n * (default is \"expectSingle\")\n */\nexport type AnchoredColumnMatchStrategy = \"expectSingle\" | \"expectMultiple\" | \"takeFirst\";\n\n/**\n * Matcher for PColumns in an anchored context\n * Supports partial matching on axes, allowing for flexible column discovery\n */\nexport interface AnchoredPColumnSelector {\n /** Optional name of the column to match; can't be used together with namePattern */\n name?: string;\n /** Optional regexp pattern for column name matching; can't be used together with name */\n namePattern?: string;\n /** Optional value type to match. If an array is provided, matches if the column's type is any of the specified types */\n type?: ValueType | ValueType[];\n /** If specified, the domain values must be anchored to this anchor */\n domainAnchor?: string;\n /** Optional domain values to match, can include anchored references, if domainAnchor is specified,\n * interpreted as additional domains to domain from the anchor */\n domain?: Record<string, ADomain>;\n /** If specified, the context domain values must be anchored to this anchor */\n contextDomainAnchor?: string;\n /** Optional context domain values to match, can include anchored references, if contextDomainAnchor is specified,\n * interpreted as additional context domains to context domain from the anchor */\n contextDomain?: Record<string, ADomain>;\n /** Optional axes to match, can include anchored references */\n axes?: AAxisSelector[];\n /** When true, allows matching if only a subset of axes match */\n partialAxesMatch?: boolean;\n /** Optional annotations to match with exact values */\n annotations?: Record<string, string>;\n /** Optional annotation patterns to match with regex patterns */\n annotationPatterns?: Record<string, string>;\n /** Match resolution strategy, default is \"expectSingle\" */\n matchStrategy?: AnchoredColumnMatchStrategy;\n}\n\n/**\n * Matcher for PColumns in a non-anchored context\n */\nexport interface PColumnSelector extends AnchoredPColumnSelector {\n domainAnchor?: never;\n domain?: Record<string, string>;\n contextDomainAnchor?: never;\n contextDomain?: Record<string, string>;\n axes?: AxisSelector[];\n}\n\n/**\n * Strict identifier for PColumns in an anchored context\n * Unlike APColumnMatcher, this requires exact matches on domain and axes\n */\nexport interface AnchoredPColumnId extends AnchoredPColumnSelector {\n /** Name is required for exact column identification */\n name: string;\n /** No namePattern in ID */\n namePattern?: never;\n /** Type is not used in exact column identification */\n type?: never;\n /** Full axes specification using only basic references */\n axes: AnchorAxisIdOrRefBasic[];\n /** Partial axes matching is not allowed for exact identification */\n partialAxesMatch?: never;\n /** Annotations are not used in exact column identification */\n annotations?: never;\n /** Annotation patterns are not used in exact column identification */\n annotationPatterns?: never;\n /** \"Id\" implies single match strategy */\n matchStrategy?: never;\n}\n\n/**\n * Checks if a given value is an anchored column identifier\n * @param id - The value to check\n * @returns True if the value is an anchored column identifier, false otherwise\n */\nexport function isAnchoredPColumnId(id: unknown): id is AnchoredPColumnId {\n // basic check, can be extended if needed\n return typeof id === \"object\" && id !== null && \"name\" in id && \"axes\" in id;\n}\n\n/**\n * Determines if an axis ID matches an axis selector.\n *\n * @param selector - The selector with criteria to match against\n * @param axis - The AxisId to check against the selector\n * @returns true if the AxisId matches all specified criteria in the selector, false otherwise\n */\nexport function matchAxis(selector: AxisSelector, axis: AxisId): boolean {\n // Match name if specified\n if (selector.name !== undefined && selector.name !== axis.name) return false;\n\n // Match type if specified\n if (selector.type !== undefined) {\n if (Array.isArray(selector.type)) {\n if (!selector.type.includes(axis.type)) return false;\n } else if (selector.type !== axis.type) {\n return false;\n }\n }\n\n // Match domain if specified - using existing logic from matchAxisId\n if (selector.domain !== undefined) {\n const axisDomain = axis.domain || {};\n for (const [key, value] of Object.entries(selector.domain))\n if (axisDomain[key] !== value) return false;\n }\n\n // Match contextDomain if specified\n if (selector.contextDomain !== undefined) {\n const axisContextDomain = axis.contextDomain || {};\n for (const [key, value] of Object.entries(selector.contextDomain))\n if (axisContextDomain[key] !== value) return false;\n }\n\n return true;\n}\n\n/**\n * Determines if a given PColumnSpec matches a selector.\n *\n * @param pcolumn - The PColumnSpec to check against the selector\n * @param selector - The selector criteria to match against\n * @returns true if the PColumnSpec matches all criteria in the selector, false otherwise\n */\nexport function matchPColumn(pcolumn: PColumnSpec, selector: PColumnSelector): boolean {\n // Match name if specified\n if (selector.name !== undefined && pcolumn.name !== selector.name) return false;\n\n // Match name pattern if specified\n if (selector.namePattern !== undefined && !new RegExp(selector.namePattern).test(pcolumn.name))\n return false;\n\n // Match type if specified\n if (selector.type !== undefined) {\n if (Array.isArray(selector.type)) {\n if (!selector.type.includes(pcolumn.valueType)) return false;\n } else if (selector.type !== pcolumn.valueType) {\n return false;\n }\n }\n\n // Match domain if specified\n if (selector.domain !== undefined) {\n const columnDomain = pcolumn.domain || {};\n for (const [key, value] of Object.entries(selector.domain))\n if (columnDomain[key] !== value) return false;\n }\n\n // Match contextDomain if specified\n if (selector.contextDomain !== undefined) {\n const columnContextDomain = pcolumn.contextDomain || {};\n for (const [key, value] of Object.entries(selector.contextDomain))\n if (columnContextDomain[key] !== value) return false;\n }\n\n // Match axes if specified\n if (selector.axes !== undefined) {\n const pcolumnAxes = pcolumn.axesSpec.map(getAxisId);\n\n if (selector.partialAxesMatch) {\n // For partial matching, all selector axes must match at least one column axis\n for (const selectorAxis of selector.axes)\n if (!pcolumnAxes.some((columnAxis) => matchAxis(selectorAxis, columnAxis))) return false;\n } else {\n // For exact matching, column must have the same number of axes and all must match\n if (pcolumnAxes.length !== selector.axes.length) return false;\n\n // Each selector axis must match a corresponding column axis\n for (let i = 0; i < selector.axes.length; i++)\n if (!matchAxis(selector.axes[i], pcolumnAxes[i])) return false;\n }\n }\n\n // Match annotations if specified\n if (selector.annotations !== undefined) {\n const columnAnnotations = pcolumn.annotations || {};\n for (const [key, value] of Object.entries(selector.annotations))\n if (columnAnnotations[key] !== value) return false;\n }\n\n // Match annotation patterns if specified\n if (selector.annotationPatterns !== undefined) {\n const columnAnnotations = pcolumn.annotations || {};\n for (const [key, pattern] of Object.entries(selector.annotationPatterns)) {\n const value = columnAnnotations[key];\n if (value === undefined || !new RegExp(pattern).test(value)) return false;\n }\n }\n\n return true;\n}\n\n/**\n * Convert a predicate or array of selectors to a single predicate function\n * @param predicateOrSelectors - Either a function that takes a PColumnSpec and returns a boolean,\n * or an array of PColumnSelectors, or a single PColumnSelector\n * @returns A function that takes a PColumnSpec and returns a boolean\n */\nexport function selectorsToPredicate(\n predicateOrSelectors: PColumnSelector | PColumnSelector[],\n): (spec: PObjectSpec) => boolean {\n if (Array.isArray(predicateOrSelectors))\n return (spec) =>\n predicateOrSelectors.some((selector) => isPColumnSpec(spec) && matchPColumn(spec, selector));\n else return (spec) => isPColumnSpec(spec) && matchPColumn(spec, predicateOrSelectors);\n}\n"],"mappings":";;;;;;;;;AAiLA,SAAgB,oBAAoB,IAAsC;AAExE,QAAO,OAAO,OAAO,YAAY,OAAO,QAAQ,UAAU,MAAM,UAAU;;;;;;;;;AAU5E,SAAgB,UAAU,UAAwB,MAAuB;AAEvE,KAAI,SAAS,SAAS,UAAa,SAAS,SAAS,KAAK,KAAM,QAAO;AAGvE,KAAI,SAAS,SAAS,QACpB;MAAI,MAAM,QAAQ,SAAS,KAAK,EAC9B;OAAI,CAAC,SAAS,KAAK,SAAS,KAAK,KAAK,CAAE,QAAO;aACtC,SAAS,SAAS,KAAK,KAChC,QAAO;;AAKX,KAAI,SAAS,WAAW,QAAW;EACjC,MAAM,aAAa,KAAK,UAAU,EAAE;AACpC,OAAK,MAAM,CAAC,KAAK,UAAU,OAAO,QAAQ,SAAS,OAAO,CACxD,KAAI,WAAW,SAAS,MAAO,QAAO;;AAI1C,KAAI,SAAS,kBAAkB,QAAW;EACxC,MAAM,oBAAoB,KAAK,iBAAiB,EAAE;AAClD,OAAK,MAAM,CAAC,KAAK,UAAU,OAAO,QAAQ,SAAS,cAAc,CAC/D,KAAI,kBAAkB,SAAS,MAAO,QAAO;;AAGjD,QAAO;;;;;;;;;AAUT,SAAgB,aAAa,SAAsB,UAAoC;AAErF,KAAI,SAAS,SAAS,UAAa,QAAQ,SAAS,SAAS,KAAM,QAAO;AAG1E,KAAI,SAAS,gBAAgB,UAAa,CAAC,IAAI,OAAO,SAAS,YAAY,CAAC,KAAK,QAAQ,KAAK,CAC5F,QAAO;AAGT,KAAI,SAAS,SAAS,QACpB;MAAI,MAAM,QAAQ,SAAS,KAAK,EAC9B;OAAI,CAA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,QAAO;;;AAIxE,QAAO;;;;;;;;AAST,SAAgB,qBACd,sBACgC;AAChC,KAAI,MAAM,QAAQ,qBAAqB,CACrC,SAAQ,SACN,qBAAqB,MAAM,aAAaC,6BAAc,KAAK,IAAI,aAAa,MAAM,SAAS,CAAC;KAC3F,SAAQ,SAASA,6BAAc,KAAK,IAAI,aAAa,MAAM,qBAAqB"}
|
|
1
|
+
{"version":3,"file":"selectors.cjs","names":["getAxisId","isPColumnSpec"],"sources":["../../../../src/drivers/pframe/spec/selectors.ts"],"sourcesContent":["import { isPColumnSpec, type PObjectSpec } from \"../../../pool\";\nimport type { AxisId, AxisValueType, Domain, PColumnSpec, ValueType } from \"./spec\";\nimport { getAxisId } from \"./spec\";\n\n/**\n * Defines a pattern for matching axes within the PFrame data model.\n *\n * AxisSelector provides a flexible way to identify axes based on their\n * properties. All fields are optional, allowing for partial matching.\n * When multiple properties are specified, all must match for an axis\n * to be selected (logical AND).\n *\n * This interface is used in various selection and matching operations\n * throughout the PFrame system, such as column queries and axis lookups.\n *\n * @deprecated This selector is part of the legacy column matching API.\n * The new Columns API (see sdk/model/src/columns/) now handles column and axis\n * selection via {@link AxisSelector} and {@link ColumnSelector}, providing\n * stricter matching semantics (StringMatcher-based) and a unified approach\n * to working with columns, including domain and annotation matching.\n */\nexport interface LegacyAxisSelector {\n /**\n * Optional value type to match against.\n * When specified, only axes with this exact type will match.\n * Can be a single type or an array of types to match against any of them.\n * Valid types include: 'Int', 'Long', 'Float', 'Double', 'String', 'Bytes'.\n */\n type?: ValueType | ValueType[];\n\n /**\n * Optional name to match against.\n * When specified, only axes with this exact name will match.\n */\n name?: string;\n\n /**\n * Optional domain key-value pairs to match against.\n * Domains provide additional context to uniquely identify an axis beyond its name and type.\n * When specified, an axis will match only if it contains all the key-value pairs defined here.\n * An axis with additional domain entries not present in this selector will still match.\n */\n domain?: Record<string, string>;\n\n /**\n * Optional context domain key-value pairs to match against.\n * Context domains are matched by kinship rules (subset/superset/overlap) rather than exact equality.\n * When specified, an axis will match only if it contains all the key-value pairs defined here.\n */\n contextDomain?: Record<string, string>;\n}\n\n/** Single axis selector */\nexport interface SingleAxisSelector {\n /** Axis name (required) */\n name: string;\n /** Axis type (optional) */\n type?: AxisValueType;\n /** Domain requirements (optional) */\n domain?: Domain;\n /** Parent axes requirements (optional) */\n parentAxes?: SingleAxisSelector[];\n}\n\n/**\n * Reference to an axis by its numerical index within the anchor column's axes array\n * Format: [anchorId, axisIndex]\n */\nexport type AnchorAxisRefByIdx = { anchor: string; idx: number };\n\n/**\n * Reference to an axis by its name within the anchor column\n * Format: [anchorId, axisName]\n */\nexport type AnchorAxisRefByName = { anchor: string; name: string };\n\n/**\n * Reference to an axis using an AxisId matcher within the anchor\n * Format: [anchorId, axisMatcher]\n */\nexport type AnchorAxisRefByMatcher = { anchor: string; id: AxisId };\n\n/**\n * Basic anchor axis reference that can be either by index or a direct AxisId\n */\nexport type AnchorAxisIdOrRefBasic = AnchorAxisRefByIdx | AxisId;\n\n/** Union of all possible ways to reference an axis in an anchored context */\nexport type AnchorAxisRef = AnchorAxisRefByIdx | AnchorAxisRefByName | AnchorAxisRefByMatcher;\n\n/** Reference to a domain value through an anchor */\nexport type AnchorDomainRef = { anchor: string };\n\n/**\n * Domain value that can be either a direct string value or a reference to a domain through an anchor\n * Used to establish domain context that can be resolved relative to other anchored columns\n */\nexport type ADomain = string | AnchorDomainRef;\n/**\n * Axis identifier that can be either a direct AxisId or a reference to an axis through an anchor\n * Allows referring to axes in a way that can be resolved in different contexts\n */\nexport type AAxisSelector = LegacyAxisSelector | AnchorAxisRef;\n\n/**\n * Match resolution strategy for PColumns\n * Specifies how to handle when multiple columns match the criteria\n * (default is \"expectSingle\")\n */\nexport type AnchoredColumnMatchStrategy = \"expectSingle\" | \"expectMultiple\" | \"takeFirst\";\n\n/**\n * Matcher for PColumns in an anchored context\n * Supports partial matching on axes, allowing for flexible column discovery\n */\nexport interface AnchoredPColumnSelector {\n /** Optional name of the column to match; can't be used together with namePattern */\n name?: string;\n /** Optional regexp pattern for column name matching; can't be used together with name */\n namePattern?: string;\n /** Optional value type to match. If an array is provided, matches if the column's type is any of the specified types */\n type?: ValueType | ValueType[];\n /** If specified, the domain values must be anchored to this anchor */\n domainAnchor?: string;\n /** Optional domain values to match, can include anchored references, if domainAnchor is specified,\n * interpreted as additional domains to domain from the anchor */\n domain?: Record<string, ADomain>;\n /** If specified, the context domain values must be anchored to this anchor */\n contextDomainAnchor?: string;\n /** Optional context domain values to match, can include anchored references, if contextDomainAnchor is specified,\n * interpreted as additional context domains to context domain from the anchor */\n contextDomain?: Record<string, ADomain>;\n /** Optional axes to match, can include anchored references */\n axes?: AAxisSelector[];\n /** When true, allows matching if only a subset of axes match */\n partialAxesMatch?: boolean;\n /** Optional annotations to match with exact values */\n annotations?: Record<string, string>;\n /** Optional annotation patterns to match with regex patterns */\n annotationPatterns?: Record<string, string>;\n /** Match resolution strategy, default is \"expectSingle\" */\n matchStrategy?: AnchoredColumnMatchStrategy;\n}\n\n/**\n * Matcher for PColumns in a non-anchored context\n */\nexport interface PColumnSelector extends AnchoredPColumnSelector {\n domainAnchor?: never;\n domain?: Record<string, string>;\n contextDomainAnchor?: never;\n contextDomain?: Record<string, string>;\n axes?: LegacyAxisSelector[];\n}\n\n/**\n * Strict identifier for PColumns in an anchored context\n * Unlike APColumnMatcher, this requires exact matches on domain and axes\n */\nexport interface AnchoredPColumnId extends AnchoredPColumnSelector {\n /** Name is required for exact column identification */\n name: string;\n /** No namePattern in ID */\n namePattern?: never;\n /** Type is not used in exact column identification */\n type?: never;\n /** Full axes specification using only basic references */\n axes: AnchorAxisIdOrRefBasic[];\n /** Partial axes matching is not allowed for exact identification */\n partialAxesMatch?: never;\n /** Annotations are not used in exact column identification */\n annotations?: never;\n /** Annotation patterns are not used in exact column identification */\n annotationPatterns?: never;\n /** \"Id\" implies single match strategy */\n matchStrategy?: never;\n}\n\n/**\n * Checks if a given value is an anchored column identifier\n * @param id - The value to check\n * @returns True if the value is an anchored column identifier, false otherwise\n */\nexport function isAnchoredPColumnId(id: unknown): id is AnchoredPColumnId {\n // basic check, can be extended if needed\n return typeof id === \"object\" && id !== null && \"name\" in id && \"axes\" in id;\n}\n\n/**\n * Determines if an axis ID matches an axis selector.\n *\n * @param selector - The selector with criteria to match against\n * @param axis - The AxisId to check against the selector\n * @returns true if the AxisId matches all specified criteria in the selector, false otherwise\n */\nexport function matchAxis(selector: LegacyAxisSelector, axis: AxisId): boolean {\n // Match name if specified\n if (selector.name !== undefined && selector.name !== axis.name) return false;\n\n // Match type if specified\n if (selector.type !== undefined) {\n if (Array.isArray(selector.type)) {\n if (!selector.type.includes(axis.type)) return false;\n } else if (selector.type !== axis.type) {\n return false;\n }\n }\n\n // Match domain if specified - using existing logic from matchAxisId\n if (selector.domain !== undefined) {\n const axisDomain = axis.domain || {};\n for (const [key, value] of Object.entries(selector.domain))\n if (axisDomain[key] !== value) return false;\n }\n\n // Match contextDomain if specified\n if (selector.contextDomain !== undefined) {\n const axisContextDomain = axis.contextDomain || {};\n for (const [key, value] of Object.entries(selector.contextDomain))\n if (axisContextDomain[key] !== value) return false;\n }\n\n return true;\n}\n\n/**\n * Determines if a given PColumnSpec matches a selector.\n *\n * @param pcolumn - The PColumnSpec to check against the selector\n * @param selector - The selector criteria to match against\n * @returns true if the PColumnSpec matches all criteria in the selector, false otherwise\n */\nexport function matchPColumn(pcolumn: PColumnSpec, selector: PColumnSelector): boolean {\n // Match name if specified\n if (selector.name !== undefined && pcolumn.name !== selector.name) return false;\n\n // Match name pattern if specified\n if (selector.namePattern !== undefined && !new RegExp(selector.namePattern).test(pcolumn.name))\n return false;\n\n // Match type if specified\n if (selector.type !== undefined) {\n if (Array.isArray(selector.type)) {\n if (!selector.type.includes(pcolumn.valueType)) return false;\n } else if (selector.type !== pcolumn.valueType) {\n return false;\n }\n }\n\n // Match domain if specified\n if (selector.domain !== undefined) {\n const columnDomain = pcolumn.domain || {};\n for (const [key, value] of Object.entries(selector.domain))\n if (columnDomain[key] !== value) return false;\n }\n\n // Match contextDomain if specified\n if (selector.contextDomain !== undefined) {\n const columnContextDomain = pcolumn.contextDomain || {};\n for (const [key, value] of Object.entries(selector.contextDomain))\n if (columnContextDomain[key] !== value) return false;\n }\n\n // Match axes if specified\n if (selector.axes !== undefined) {\n const pcolumnAxes = pcolumn.axesSpec.map(getAxisId);\n\n if (selector.partialAxesMatch) {\n // For partial matching, all selector axes must match at least one column axis\n for (const selectorAxis of selector.axes)\n if (!pcolumnAxes.some((columnAxis) => matchAxis(selectorAxis, columnAxis))) return false;\n } else {\n // For exact matching, column must have the same number of axes and all must match\n if (pcolumnAxes.length !== selector.axes.length) return false;\n\n // Each selector axis must match a corresponding column axis\n for (let i = 0; i < selector.axes.length; i++)\n if (!matchAxis(selector.axes[i], pcolumnAxes[i])) return false;\n }\n }\n\n // Match annotations if specified\n if (selector.annotations !== undefined) {\n const columnAnnotations = pcolumn.annotations || {};\n for (const [key, value] of Object.entries(selector.annotations))\n if (columnAnnotations[key] !== value) return false;\n }\n\n // Match annotation patterns if specified\n if (selector.annotationPatterns !== undefined) {\n const columnAnnotations = pcolumn.annotations || {};\n for (const [key, pattern] of Object.entries(selector.annotationPatterns)) {\n const value = columnAnnotations[key];\n if (value === undefined || !new RegExp(pattern).test(value)) return false;\n }\n }\n\n return true;\n}\n\n/**\n * Convert a predicate or array of selectors to a single predicate function\n * @param predicateOrSelectors - Either a function that takes a PColumnSpec and returns a boolean,\n * or an array of PColumnSelectors, or a single PColumnSelector\n * @returns A function that takes a PColumnSpec and returns a boolean\n */\nexport function legacyColumnSelectorsToPredicate(\n predicateOrSelectors: PColumnSelector | PColumnSelector[],\n): (spec: PObjectSpec) => boolean {\n if (Array.isArray(predicateOrSelectors))\n return (spec) =>\n predicateOrSelectors.some((selector) => isPColumnSpec(spec) && matchPColumn(spec, selector));\n else return (spec) => isPColumnSpec(spec) && matchPColumn(spec, predicateOrSelectors);\n}\n"],"mappings":";;;;;;;;;AAuLA,SAA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-13,8 +13,14 @@ import { AxisId, AxisValueType, Domain, PColumnSpec, ValueType } from "./spec.js
|
|
|
13
13
|
*
|
|
14
14
|
* This interface is used in various selection and matching operations
|
|
15
15
|
* throughout the PFrame system, such as column queries and axis lookups.
|
|
16
|
+
*
|
|
17
|
+
* @deprecated This selector is part of the legacy column matching API.
|
|
18
|
+
* The new Columns API (see sdk/model/src/columns/) now handles column and axis
|
|
19
|
+
* selection via {@link AxisSelector} and {@link ColumnSelector}, providing
|
|
20
|
+
* stricter matching semantics (StringMatcher-based) and a unified approach
|
|
21
|
+
* to working with columns, including domain and annotation matching.
|
|
16
22
|
*/
|
|
17
|
-
interface
|
|
23
|
+
interface LegacyAxisSelector {
|
|
18
24
|
/**
|
|
19
25
|
* Optional value type to match against.
|
|
20
26
|
* When specified, only axes with this exact type will match.
|
|
@@ -95,7 +101,7 @@ type ADomain = string | AnchorDomainRef;
|
|
|
95
101
|
* Axis identifier that can be either a direct AxisId or a reference to an axis through an anchor
|
|
96
102
|
* Allows referring to axes in a way that can be resolved in different contexts
|
|
97
103
|
*/
|
|
98
|
-
type AAxisSelector =
|
|
104
|
+
type AAxisSelector = LegacyAxisSelector | AnchorAxisRef;
|
|
99
105
|
/**
|
|
100
106
|
* Match resolution strategy for PColumns
|
|
101
107
|
* Specifies how to handle when multiple columns match the criteria
|
|
@@ -142,7 +148,7 @@ interface PColumnSelector extends AnchoredPColumnSelector {
|
|
|
142
148
|
domain?: Record<string, string>;
|
|
143
149
|
contextDomainAnchor?: never;
|
|
144
150
|
contextDomain?: Record<string, string>;
|
|
145
|
-
axes?:
|
|
151
|
+
axes?: LegacyAxisSelector[];
|
|
146
152
|
}
|
|
147
153
|
/**
|
|
148
154
|
* Strict identifier for PColumns in an anchored context
|
|
@@ -179,7 +185,7 @@ declare function isAnchoredPColumnId(id: unknown): id is AnchoredPColumnId;
|
|
|
179
185
|
* @param axis - The AxisId to check against the selector
|
|
180
186
|
* @returns true if the AxisId matches all specified criteria in the selector, false otherwise
|
|
181
187
|
*/
|
|
182
|
-
declare function matchAxis(selector:
|
|
188
|
+
declare function matchAxis(selector: LegacyAxisSelector, axis: AxisId): boolean;
|
|
183
189
|
/**
|
|
184
190
|
* Determines if a given PColumnSpec matches a selector.
|
|
185
191
|
*
|
|
@@ -194,7 +200,7 @@ declare function matchPColumn(pcolumn: PColumnSpec, selector: PColumnSelector):
|
|
|
194
200
|
* or an array of PColumnSelectors, or a single PColumnSelector
|
|
195
201
|
* @returns A function that takes a PColumnSpec and returns a boolean
|
|
196
202
|
*/
|
|
197
|
-
declare function
|
|
203
|
+
declare function legacyColumnSelectorsToPredicate(predicateOrSelectors: PColumnSelector | PColumnSelector[]): (spec: PObjectSpec) => boolean;
|
|
198
204
|
//#endregion
|
|
199
|
-
export { AAxisSelector, ADomain, AnchorAxisIdOrRefBasic, AnchorAxisRef, AnchorAxisRefByIdx, AnchorAxisRefByMatcher, AnchorAxisRefByName, AnchorDomainRef, AnchoredColumnMatchStrategy, AnchoredPColumnId, AnchoredPColumnSelector,
|
|
205
|
+
export { AAxisSelector, ADomain, AnchorAxisIdOrRefBasic, AnchorAxisRef, AnchorAxisRefByIdx, AnchorAxisRefByMatcher, AnchorAxisRefByName, AnchorDomainRef, AnchoredColumnMatchStrategy, AnchoredPColumnId, AnchoredPColumnSelector, LegacyAxisSelector, PColumnSelector, SingleAxisSelector, isAnchoredPColumnId, legacyColumnSelectorsToPredicate, matchAxis, matchPColumn };
|
|
200
206
|
//# sourceMappingURL=selectors.d.ts.map
|
|
@@ -85,11 +85,11 @@ function matchPColumn(pcolumn, selector) {
|
|
|
85
85
|
* or an array of PColumnSelectors, or a single PColumnSelector
|
|
86
86
|
* @returns A function that takes a PColumnSpec and returns a boolean
|
|
87
87
|
*/
|
|
88
|
-
function
|
|
88
|
+
function legacyColumnSelectorsToPredicate(predicateOrSelectors) {
|
|
89
89
|
if (Array.isArray(predicateOrSelectors)) return (spec) => predicateOrSelectors.some((selector) => isPColumnSpec(spec) && matchPColumn(spec, selector));
|
|
90
90
|
else return (spec) => isPColumnSpec(spec) && matchPColumn(spec, predicateOrSelectors);
|
|
91
91
|
}
|
|
92
92
|
|
|
93
93
|
//#endregion
|
|
94
|
-
export { isAnchoredPColumnId, matchAxis, matchPColumn
|
|
94
|
+
export { isAnchoredPColumnId, legacyColumnSelectorsToPredicate, matchAxis, matchPColumn };
|
|
95
95
|
//# sourceMappingURL=selectors.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"selectors.js","names":[],"sources":["../../../../src/drivers/pframe/spec/selectors.ts"],"sourcesContent":["import { isPColumnSpec, type PObjectSpec } from \"../../../pool\";\nimport type { AxisId, AxisValueType, Domain, PColumnSpec, ValueType } from \"./spec\";\nimport { getAxisId } from \"./spec\";\n\n/**\n * Defines a pattern for matching axes within the PFrame data model.\n *\n * AxisSelector provides a flexible way to identify axes based on their\n * properties. All fields are optional, allowing for partial matching.\n * When multiple properties are specified, all must match for an axis\n * to be selected (logical AND).\n *\n * This interface is used in various selection and matching operations\n * throughout the PFrame system, such as column queries and axis lookups.\n */\nexport interface AxisSelector {\n /**\n * Optional value type to match against.\n * When specified, only axes with this exact type will match.\n * Can be a single type or an array of types to match against any of them.\n * Valid types include: 'Int', 'Long', 'Float', 'Double', 'String', 'Bytes'.\n */\n type?: ValueType | ValueType[];\n\n /**\n * Optional name to match against.\n * When specified, only axes with this exact name will match.\n */\n name?: string;\n\n /**\n * Optional domain key-value pairs to match against.\n * Domains provide additional context to uniquely identify an axis beyond its name and type.\n * When specified, an axis will match only if it contains all the key-value pairs defined here.\n * An axis with additional domain entries not present in this selector will still match.\n */\n domain?: Record<string, string>;\n\n /**\n * Optional context domain key-value pairs to match against.\n * Context domains are matched by kinship rules (subset/superset/overlap) rather than exact equality.\n * When specified, an axis will match only if it contains all the key-value pairs defined here.\n */\n contextDomain?: Record<string, string>;\n}\n\n/** Single axis selector */\nexport interface SingleAxisSelector {\n /** Axis name (required) */\n name: string;\n /** Axis type (optional) */\n type?: AxisValueType;\n /** Domain requirements (optional) */\n domain?: Domain;\n /** Parent axes requirements (optional) */\n parentAxes?: SingleAxisSelector[];\n}\n\n/**\n * Reference to an axis by its numerical index within the anchor column's axes array\n * Format: [anchorId, axisIndex]\n */\nexport type AnchorAxisRefByIdx = { anchor: string; idx: number };\n\n/**\n * Reference to an axis by its name within the anchor column\n * Format: [anchorId, axisName]\n */\nexport type AnchorAxisRefByName = { anchor: string; name: string };\n\n/**\n * Reference to an axis using an AxisId matcher within the anchor\n * Format: [anchorId, axisMatcher]\n */\nexport type AnchorAxisRefByMatcher = { anchor: string; id: AxisId };\n\n/**\n * Basic anchor axis reference that can be either by index or a direct AxisId\n */\nexport type AnchorAxisIdOrRefBasic = AnchorAxisRefByIdx | AxisId;\n\n/** Union of all possible ways to reference an axis in an anchored context */\nexport type AnchorAxisRef = AnchorAxisRefByIdx | AnchorAxisRefByName | AnchorAxisRefByMatcher;\n\n/** Reference to a domain value through an anchor */\nexport type AnchorDomainRef = { anchor: string };\n\n/**\n * Domain value that can be either a direct string value or a reference to a domain through an anchor\n * Used to establish domain context that can be resolved relative to other anchored columns\n */\nexport type ADomain = string | AnchorDomainRef;\n/**\n * Axis identifier that can be either a direct AxisId or a reference to an axis through an anchor\n * Allows referring to axes in a way that can be resolved in different contexts\n */\nexport type AAxisSelector = AxisSelector | AnchorAxisRef;\n\n/**\n * Match resolution strategy for PColumns\n * Specifies how to handle when multiple columns match the criteria\n * (default is \"expectSingle\")\n */\nexport type AnchoredColumnMatchStrategy = \"expectSingle\" | \"expectMultiple\" | \"takeFirst\";\n\n/**\n * Matcher for PColumns in an anchored context\n * Supports partial matching on axes, allowing for flexible column discovery\n */\nexport interface AnchoredPColumnSelector {\n /** Optional name of the column to match; can't be used together with namePattern */\n name?: string;\n /** Optional regexp pattern for column name matching; can't be used together with name */\n namePattern?: string;\n /** Optional value type to match. If an array is provided, matches if the column's type is any of the specified types */\n type?: ValueType | ValueType[];\n /** If specified, the domain values must be anchored to this anchor */\n domainAnchor?: string;\n /** Optional domain values to match, can include anchored references, if domainAnchor is specified,\n * interpreted as additional domains to domain from the anchor */\n domain?: Record<string, ADomain>;\n /** If specified, the context domain values must be anchored to this anchor */\n contextDomainAnchor?: string;\n /** Optional context domain values to match, can include anchored references, if contextDomainAnchor is specified,\n * interpreted as additional context domains to context domain from the anchor */\n contextDomain?: Record<string, ADomain>;\n /** Optional axes to match, can include anchored references */\n axes?: AAxisSelector[];\n /** When true, allows matching if only a subset of axes match */\n partialAxesMatch?: boolean;\n /** Optional annotations to match with exact values */\n annotations?: Record<string, string>;\n /** Optional annotation patterns to match with regex patterns */\n annotationPatterns?: Record<string, string>;\n /** Match resolution strategy, default is \"expectSingle\" */\n matchStrategy?: AnchoredColumnMatchStrategy;\n}\n\n/**\n * Matcher for PColumns in a non-anchored context\n */\nexport interface PColumnSelector extends AnchoredPColumnSelector {\n domainAnchor?: never;\n domain?: Record<string, string>;\n contextDomainAnchor?: never;\n contextDomain?: Record<string, string>;\n axes?: AxisSelector[];\n}\n\n/**\n * Strict identifier for PColumns in an anchored context\n * Unlike APColumnMatcher, this requires exact matches on domain and axes\n */\nexport interface AnchoredPColumnId extends AnchoredPColumnSelector {\n /** Name is required for exact column identification */\n name: string;\n /** No namePattern in ID */\n namePattern?: never;\n /** Type is not used in exact column identification */\n type?: never;\n /** Full axes specification using only basic references */\n axes: AnchorAxisIdOrRefBasic[];\n /** Partial axes matching is not allowed for exact identification */\n partialAxesMatch?: never;\n /** Annotations are not used in exact column identification */\n annotations?: never;\n /** Annotation patterns are not used in exact column identification */\n annotationPatterns?: never;\n /** \"Id\" implies single match strategy */\n matchStrategy?: never;\n}\n\n/**\n * Checks if a given value is an anchored column identifier\n * @param id - The value to check\n * @returns True if the value is an anchored column identifier, false otherwise\n */\nexport function isAnchoredPColumnId(id: unknown): id is AnchoredPColumnId {\n // basic check, can be extended if needed\n return typeof id === \"object\" && id !== null && \"name\" in id && \"axes\" in id;\n}\n\n/**\n * Determines if an axis ID matches an axis selector.\n *\n * @param selector - The selector with criteria to match against\n * @param axis - The AxisId to check against the selector\n * @returns true if the AxisId matches all specified criteria in the selector, false otherwise\n */\nexport function matchAxis(selector: AxisSelector, axis: AxisId): boolean {\n // Match name if specified\n if (selector.name !== undefined && selector.name !== axis.name) return false;\n\n // Match type if specified\n if (selector.type !== undefined) {\n if (Array.isArray(selector.type)) {\n if (!selector.type.includes(axis.type)) return false;\n } else if (selector.type !== axis.type) {\n return false;\n }\n }\n\n // Match domain if specified - using existing logic from matchAxisId\n if (selector.domain !== undefined) {\n const axisDomain = axis.domain || {};\n for (const [key, value] of Object.entries(selector.domain))\n if (axisDomain[key] !== value) return false;\n }\n\n // Match contextDomain if specified\n if (selector.contextDomain !== undefined) {\n const axisContextDomain = axis.contextDomain || {};\n for (const [key, value] of Object.entries(selector.contextDomain))\n if (axisContextDomain[key] !== value) return false;\n }\n\n return true;\n}\n\n/**\n * Determines if a given PColumnSpec matches a selector.\n *\n * @param pcolumn - The PColumnSpec to check against the selector\n * @param selector - The selector criteria to match against\n * @returns true if the PColumnSpec matches all criteria in the selector, false otherwise\n */\nexport function matchPColumn(pcolumn: PColumnSpec, selector: PColumnSelector): boolean {\n // Match name if specified\n if (selector.name !== undefined && pcolumn.name !== selector.name) return false;\n\n // Match name pattern if specified\n if (selector.namePattern !== undefined && !new RegExp(selector.namePattern).test(pcolumn.name))\n return false;\n\n // Match type if specified\n if (selector.type !== undefined) {\n if (Array.isArray(selector.type)) {\n if (!selector.type.includes(pcolumn.valueType)) return false;\n } else if (selector.type !== pcolumn.valueType) {\n return false;\n }\n }\n\n // Match domain if specified\n if (selector.domain !== undefined) {\n const columnDomain = pcolumn.domain || {};\n for (const [key, value] of Object.entries(selector.domain))\n if (columnDomain[key] !== value) return false;\n }\n\n // Match contextDomain if specified\n if (selector.contextDomain !== undefined) {\n const columnContextDomain = pcolumn.contextDomain || {};\n for (const [key, value] of Object.entries(selector.contextDomain))\n if (columnContextDomain[key] !== value) return false;\n }\n\n // Match axes if specified\n if (selector.axes !== undefined) {\n const pcolumnAxes = pcolumn.axesSpec.map(getAxisId);\n\n if (selector.partialAxesMatch) {\n // For partial matching, all selector axes must match at least one column axis\n for (const selectorAxis of selector.axes)\n if (!pcolumnAxes.some((columnAxis) => matchAxis(selectorAxis, columnAxis))) return false;\n } else {\n // For exact matching, column must have the same number of axes and all must match\n if (pcolumnAxes.length !== selector.axes.length) return false;\n\n // Each selector axis must match a corresponding column axis\n for (let i = 0; i < selector.axes.length; i++)\n if (!matchAxis(selector.axes[i], pcolumnAxes[i])) return false;\n }\n }\n\n // Match annotations if specified\n if (selector.annotations !== undefined) {\n const columnAnnotations = pcolumn.annotations || {};\n for (const [key, value] of Object.entries(selector.annotations))\n if (columnAnnotations[key] !== value) return false;\n }\n\n // Match annotation patterns if specified\n if (selector.annotationPatterns !== undefined) {\n const columnAnnotations = pcolumn.annotations || {};\n for (const [key, pattern] of Object.entries(selector.annotationPatterns)) {\n const value = columnAnnotations[key];\n if (value === undefined || !new RegExp(pattern).test(value)) return false;\n }\n }\n\n return true;\n}\n\n/**\n * Convert a predicate or array of selectors to a single predicate function\n * @param predicateOrSelectors - Either a function that takes a PColumnSpec and returns a boolean,\n * or an array of PColumnSelectors, or a single PColumnSelector\n * @returns A function that takes a PColumnSpec and returns a boolean\n */\nexport function selectorsToPredicate(\n predicateOrSelectors: PColumnSelector | PColumnSelector[],\n): (spec: PObjectSpec) => boolean {\n if (Array.isArray(predicateOrSelectors))\n return (spec) =>\n predicateOrSelectors.some((selector) => isPColumnSpec(spec) && matchPColumn(spec, selector));\n else return (spec) => isPColumnSpec(spec) && matchPColumn(spec, predicateOrSelectors);\n}\n"],"mappings":";;;;;;;;;AAiLA,SAAgB,oBAAoB,IAAsC;AAExE,QAAO,OAAO,OAAO,YAAY,OAAO,QAAQ,UAAU,MAAM,UAAU;;;;;;;;;AAU5E,SAAgB,UAAU,UAAwB,MAAuB;AAEvE,KAAI,SAAS,SAAS,UAAa,SAA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AAoB,SAAS,MAAO,QAAO;;AAInD,KAAI,SAAS,SAAS,QAAW;EAC/B,MAAM,cAAc,QAAQ,SAAS,IAAI,UAAU;AAEnD,MAAI,SAAS,kBAEX;QAAK,MAAM,gBAAgB,SAAS,KAClC,KAAI,CAAC,YAAY,MAAM,eAAe,UAAU,cAAc,WAAW,CAAC,CAAE,QAAO;SAChF;AAEL,OAAI,YAAY,WAAW,SAAS,KAAK,OAAQ,QAAO;AAGxD,QAAK,IAAI,IAAI,GAAG,IAAI,SAAS,KAAK,QAAQ,IACxC,KAAI,CAAC,UAAU,SAAS,KAAK,IAAI,YAAY,GAAG,CAAE,QAAO;;;AAK/D,KAAI,SAAS,gBAAgB,QAAW;EACtC,MAAM,oBAAoB,QAAQ,eAAe,EAAE;AACnD,OAAK,MAAM,CAAC,KAAK,UAAU,OAAO,QAAQ,SAAS,YAAY,CAC7D,KAAI,kBAAkB,SAAS,MAAO,QAAO;;AAIjD,KAAI,SAAS,uBAAuB,QAAW;EAC7C,MAAM,oBAAoB,QAAQ,eAAe,EAAE;AACnD,OAAK,MAAM,CAAC,KAAK,YAAY,OAAO,QAAQ,SAAS,mBAAmB,EAAE;GACxE,MAAM,QAAQ,kBAAkB;AAChC,OAAI,UAAU,UAAa,CAAC,IAAI,OAAO,QAAQ,CAAC,KAAK,MAAM,CAAE,QAAO;;;AAIxE,QAAO;;;;;;;;AAST,SAAgB,qBACd,sBACgC;AAChC,KAAI,MAAM,QAAQ,qBAAqB,CACrC,SAAQ,SACN,qBAAqB,MAAM,aAAa,cAAc,KAAK,IAAI,aAAa,MAAM,SAAS,CAAC;KAC3F,SAAQ,SAAS,cAAc,KAAK,IAAI,aAAa,MAAM,qBAAqB"}
|
|
1
|
+
{"version":3,"file":"selectors.js","names":[],"sources":["../../../../src/drivers/pframe/spec/selectors.ts"],"sourcesContent":["import { isPColumnSpec, type PObjectSpec } from \"../../../pool\";\nimport type { AxisId, AxisValueType, Domain, PColumnSpec, ValueType } from \"./spec\";\nimport { getAxisId } from \"./spec\";\n\n/**\n * Defines a pattern for matching axes within the PFrame data model.\n *\n * AxisSelector provides a flexible way to identify axes based on their\n * properties. All fields are optional, allowing for partial matching.\n * When multiple properties are specified, all must match for an axis\n * to be selected (logical AND).\n *\n * This interface is used in various selection and matching operations\n * throughout the PFrame system, such as column queries and axis lookups.\n *\n * @deprecated This selector is part of the legacy column matching API.\n * The new Columns API (see sdk/model/src/columns/) now handles column and axis\n * selection via {@link AxisSelector} and {@link ColumnSelector}, providing\n * stricter matching semantics (StringMatcher-based) and a unified approach\n * to working with columns, including domain and annotation matching.\n */\nexport interface LegacyAxisSelector {\n /**\n * Optional value type to match against.\n * When specified, only axes with this exact type will match.\n * Can be a single type or an array of types to match against any of them.\n * Valid types include: 'Int', 'Long', 'Float', 'Double', 'String', 'Bytes'.\n */\n type?: ValueType | ValueType[];\n\n /**\n * Optional name to match against.\n * When specified, only axes with this exact name will match.\n */\n name?: string;\n\n /**\n * Optional domain key-value pairs to match against.\n * Domains provide additional context to uniquely identify an axis beyond its name and type.\n * When specified, an axis will match only if it contains all the key-value pairs defined here.\n * An axis with additional domain entries not present in this selector will still match.\n */\n domain?: Record<string, string>;\n\n /**\n * Optional context domain key-value pairs to match against.\n * Context domains are matched by kinship rules (subset/superset/overlap) rather than exact equality.\n * When specified, an axis will match only if it contains all the key-value pairs defined here.\n */\n contextDomain?: Record<string, string>;\n}\n\n/** Single axis selector */\nexport interface SingleAxisSelector {\n /** Axis name (required) */\n name: string;\n /** Axis type (optional) */\n type?: AxisValueType;\n /** Domain requirements (optional) */\n domain?: Domain;\n /** Parent axes requirements (optional) */\n parentAxes?: SingleAxisSelector[];\n}\n\n/**\n * Reference to an axis by its numerical index within the anchor column's axes array\n * Format: [anchorId, axisIndex]\n */\nexport type AnchorAxisRefByIdx = { anchor: string; idx: number };\n\n/**\n * Reference to an axis by its name within the anchor column\n * Format: [anchorId, axisName]\n */\nexport type AnchorAxisRefByName = { anchor: string; name: string };\n\n/**\n * Reference to an axis using an AxisId matcher within the anchor\n * Format: [anchorId, axisMatcher]\n */\nexport type AnchorAxisRefByMatcher = { anchor: string; id: AxisId };\n\n/**\n * Basic anchor axis reference that can be either by index or a direct AxisId\n */\nexport type AnchorAxisIdOrRefBasic = AnchorAxisRefByIdx | AxisId;\n\n/** Union of all possible ways to reference an axis in an anchored context */\nexport type AnchorAxisRef = AnchorAxisRefByIdx | AnchorAxisRefByName | AnchorAxisRefByMatcher;\n\n/** Reference to a domain value through an anchor */\nexport type AnchorDomainRef = { anchor: string };\n\n/**\n * Domain value that can be either a direct string value or a reference to a domain through an anchor\n * Used to establish domain context that can be resolved relative to other anchored columns\n */\nexport type ADomain = string | AnchorDomainRef;\n/**\n * Axis identifier that can be either a direct AxisId or a reference to an axis through an anchor\n * Allows referring to axes in a way that can be resolved in different contexts\n */\nexport type AAxisSelector = LegacyAxisSelector | AnchorAxisRef;\n\n/**\n * Match resolution strategy for PColumns\n * Specifies how to handle when multiple columns match the criteria\n * (default is \"expectSingle\")\n */\nexport type AnchoredColumnMatchStrategy = \"expectSingle\" | \"expectMultiple\" | \"takeFirst\";\n\n/**\n * Matcher for PColumns in an anchored context\n * Supports partial matching on axes, allowing for flexible column discovery\n */\nexport interface AnchoredPColumnSelector {\n /** Optional name of the column to match; can't be used together with namePattern */\n name?: string;\n /** Optional regexp pattern for column name matching; can't be used together with name */\n namePattern?: string;\n /** Optional value type to match. If an array is provided, matches if the column's type is any of the specified types */\n type?: ValueType | ValueType[];\n /** If specified, the domain values must be anchored to this anchor */\n domainAnchor?: string;\n /** Optional domain values to match, can include anchored references, if domainAnchor is specified,\n * interpreted as additional domains to domain from the anchor */\n domain?: Record<string, ADomain>;\n /** If specified, the context domain values must be anchored to this anchor */\n contextDomainAnchor?: string;\n /** Optional context domain values to match, can include anchored references, if contextDomainAnchor is specified,\n * interpreted as additional context domains to context domain from the anchor */\n contextDomain?: Record<string, ADomain>;\n /** Optional axes to match, can include anchored references */\n axes?: AAxisSelector[];\n /** When true, allows matching if only a subset of axes match */\n partialAxesMatch?: boolean;\n /** Optional annotations to match with exact values */\n annotations?: Record<string, string>;\n /** Optional annotation patterns to match with regex patterns */\n annotationPatterns?: Record<string, string>;\n /** Match resolution strategy, default is \"expectSingle\" */\n matchStrategy?: AnchoredColumnMatchStrategy;\n}\n\n/**\n * Matcher for PColumns in a non-anchored context\n */\nexport interface PColumnSelector extends AnchoredPColumnSelector {\n domainAnchor?: never;\n domain?: Record<string, string>;\n contextDomainAnchor?: never;\n contextDomain?: Record<string, string>;\n axes?: LegacyAxisSelector[];\n}\n\n/**\n * Strict identifier for PColumns in an anchored context\n * Unlike APColumnMatcher, this requires exact matches on domain and axes\n */\nexport interface AnchoredPColumnId extends AnchoredPColumnSelector {\n /** Name is required for exact column identification */\n name: string;\n /** No namePattern in ID */\n namePattern?: never;\n /** Type is not used in exact column identification */\n type?: never;\n /** Full axes specification using only basic references */\n axes: AnchorAxisIdOrRefBasic[];\n /** Partial axes matching is not allowed for exact identification */\n partialAxesMatch?: never;\n /** Annotations are not used in exact column identification */\n annotations?: never;\n /** Annotation patterns are not used in exact column identification */\n annotationPatterns?: never;\n /** \"Id\" implies single match strategy */\n matchStrategy?: never;\n}\n\n/**\n * Checks if a given value is an anchored column identifier\n * @param id - The value to check\n * @returns True if the value is an anchored column identifier, false otherwise\n */\nexport function isAnchoredPColumnId(id: unknown): id is AnchoredPColumnId {\n // basic check, can be extended if needed\n return typeof id === \"object\" && id !== null && \"name\" in id && \"axes\" in id;\n}\n\n/**\n * Determines if an axis ID matches an axis selector.\n *\n * @param selector - The selector with criteria to match against\n * @param axis - The AxisId to check against the selector\n * @returns true if the AxisId matches all specified criteria in the selector, false otherwise\n */\nexport function matchAxis(selector: LegacyAxisSelector, axis: AxisId): boolean {\n // Match name if specified\n if (selector.name !== undefined && selector.name !== axis.name) return false;\n\n // Match type if specified\n if (selector.type !== undefined) {\n if (Array.isArray(selector.type)) {\n if (!selector.type.includes(axis.type)) return false;\n } else if (selector.type !== axis.type) {\n return false;\n }\n }\n\n // Match domain if specified - using existing logic from matchAxisId\n if (selector.domain !== undefined) {\n const axisDomain = axis.domain || {};\n for (const [key, value] of Object.entries(selector.domain))\n if (axisDomain[key] !== value) return false;\n }\n\n // Match contextDomain if specified\n if (selector.contextDomain !== undefined) {\n const axisContextDomain = axis.contextDomain || {};\n for (const [key, value] of Object.entries(selector.contextDomain))\n if (axisContextDomain[key] !== value) return false;\n }\n\n return true;\n}\n\n/**\n * Determines if a given PColumnSpec matches a selector.\n *\n * @param pcolumn - The PColumnSpec to check against the selector\n * @param selector - The selector criteria to match against\n * @returns true if the PColumnSpec matches all criteria in the selector, false otherwise\n */\nexport function matchPColumn(pcolumn: PColumnSpec, selector: PColumnSelector): boolean {\n // Match name if specified\n if (selector.name !== undefined && pcolumn.name !== selector.name) return false;\n\n // Match name pattern if specified\n if (selector.namePattern !== undefined && !new RegExp(selector.namePattern).test(pcolumn.name))\n return false;\n\n // Match type if specified\n if (selector.type !== undefined) {\n if (Array.isArray(selector.type)) {\n if (!selector.type.includes(pcolumn.valueType)) return false;\n } else if (selector.type !== pcolumn.valueType) {\n return false;\n }\n }\n\n // Match domain if specified\n if (selector.domain !== undefined) {\n const columnDomain = pcolumn.domain || {};\n for (const [key, value] of Object.entries(selector.domain))\n if (columnDomain[key] !== value) return false;\n }\n\n // Match contextDomain if specified\n if (selector.contextDomain !== undefined) {\n const columnContextDomain = pcolumn.contextDomain || {};\n for (const [key, value] of Object.entries(selector.contextDomain))\n if (columnContextDomain[key] !== value) return false;\n }\n\n // Match axes if specified\n if (selector.axes !== undefined) {\n const pcolumnAxes = pcolumn.axesSpec.map(getAxisId);\n\n if (selector.partialAxesMatch) {\n // For partial matching, all selector axes must match at least one column axis\n for (const selectorAxis of selector.axes)\n if (!pcolumnAxes.some((columnAxis) => matchAxis(selectorAxis, columnAxis))) return false;\n } else {\n // For exact matching, column must have the same number of axes and all must match\n if (pcolumnAxes.length !== selector.axes.length) return false;\n\n // Each selector axis must match a corresponding column axis\n for (let i = 0; i < selector.axes.length; i++)\n if (!matchAxis(selector.axes[i], pcolumnAxes[i])) return false;\n }\n }\n\n // Match annotations if specified\n if (selector.annotations !== undefined) {\n const columnAnnotations = pcolumn.annotations || {};\n for (const [key, value] of Object.entries(selector.annotations))\n if (columnAnnotations[key] !== value) return false;\n }\n\n // Match annotation patterns if specified\n if (selector.annotationPatterns !== undefined) {\n const columnAnnotations = pcolumn.annotations || {};\n for (const [key, pattern] of Object.entries(selector.annotationPatterns)) {\n const value = columnAnnotations[key];\n if (value === undefined || !new RegExp(pattern).test(value)) return false;\n }\n }\n\n return true;\n}\n\n/**\n * Convert a predicate or array of selectors to a single predicate function\n * @param predicateOrSelectors - Either a function that takes a PColumnSpec and returns a boolean,\n * or an array of PColumnSelectors, or a single PColumnSelector\n * @returns A function that takes a PColumnSpec and returns a boolean\n */\nexport function legacyColumnSelectorsToPredicate(\n predicateOrSelectors: PColumnSelector | PColumnSelector[],\n): (spec: PObjectSpec) => boolean {\n if (Array.isArray(predicateOrSelectors))\n return (spec) =>\n predicateOrSelectors.some((selector) => isPColumnSpec(spec) && matchPColumn(spec, selector));\n else return (spec) => isPColumnSpec(spec) && matchPColumn(spec, predicateOrSelectors);\n}\n"],"mappings":";;;;;;;;;AAuLA,SAAgB,oBAAoB,IAAsC;AAExE,QAAO,OAAO,OAAO,YAAY,OAAO,QAAQ,UAAU,MAAM,UAAU;;;;;;;;;AAU5E,SAAgB,UAAU,UAA8B,MAAuB;AAE7E,KAAI,SAAS,SAAS,UAAa,SAAS,SAAS,KAAK,KAAM,QAAO;AAGvE,KAAI,SAAS,SAAS,QACpB;MAAI,MAAM,QAAQ,SAAS,KAAK,EAC9B;OAAI,CAAC,SAAS,KAAK,SAAS,KAAK,KAAK,CAAE,QAAO;aACtC,SAAS,SAAS,KAAK,KAChC,QAAO;;AAKX,KAAI,SAAS,WAAW,QAAW;EACjC,MAAM,aAAa,KAAK,UAAU,EAAE;AACpC,OAAK,MAAM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