@milaboratories/pl-model-common 1.19.6 → 1.19.8
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/author_marker.d.ts +0 -1
- package/dist/base32_encode.cjs +56 -0
- package/dist/base32_encode.cjs.map +1 -0
- package/dist/base32_encode.d.ts +0 -1
- package/dist/base32_encode.js +54 -0
- package/dist/base32_encode.js.map +1 -0
- package/dist/block_state.d.ts +0 -1
- package/dist/bmodel/block_config.cjs +15 -0
- package/dist/bmodel/block_config.cjs.map +1 -0
- package/dist/bmodel/block_config.d.ts +0 -1
- package/dist/bmodel/block_config.js +13 -0
- package/dist/bmodel/block_config.js.map +1 -0
- package/dist/bmodel/code.d.ts +0 -1
- package/dist/bmodel/container.d.ts +0 -1
- package/dist/bmodel/index.d.ts +0 -1
- package/dist/bmodel/normalization.cjs +86 -0
- package/dist/bmodel/normalization.cjs.map +1 -0
- package/dist/bmodel/normalization.d.ts +0 -1
- package/dist/bmodel/normalization.js +84 -0
- package/dist/bmodel/normalization.js.map +1 -0
- package/dist/bmodel/types.d.ts +0 -1
- package/dist/branding.d.ts +0 -1
- package/dist/common_types.d.ts +0 -1
- package/dist/driver_kit.d.ts +0 -1
- package/dist/drivers/blob.cjs +27 -0
- package/dist/drivers/blob.cjs.map +1 -0
- package/dist/drivers/blob.d.ts +0 -1
- package/dist/drivers/blob.js +23 -0
- package/dist/drivers/blob.js.map +1 -0
- package/dist/drivers/index.d.ts +0 -1
- package/dist/drivers/interfaces.d.ts +0 -1
- package/dist/drivers/log.cjs +9 -0
- package/dist/drivers/log.cjs.map +1 -0
- package/dist/drivers/log.d.ts +0 -1
- package/dist/drivers/log.js +7 -0
- package/dist/drivers/log.js.map +1 -0
- package/dist/drivers/ls.cjs +39 -0
- package/dist/drivers/ls.cjs.map +1 -0
- package/dist/drivers/ls.d.ts +0 -1
- package/dist/drivers/ls.js +34 -0
- package/dist/drivers/ls.js.map +1 -0
- package/dist/drivers/pframe/column_filter.d.ts +0 -1
- package/dist/drivers/pframe/data_info.cjs +275 -0
- package/dist/drivers/pframe/data_info.cjs.map +1 -0
- package/dist/drivers/pframe/data_info.d.ts +0 -1
- package/dist/drivers/pframe/data_info.js +266 -0
- package/dist/drivers/pframe/data_info.js.map +1 -0
- package/dist/drivers/pframe/data_types.cjs +91 -0
- package/dist/drivers/pframe/data_types.cjs.map +1 -0
- package/dist/drivers/pframe/data_types.d.ts +0 -1
- package/dist/drivers/pframe/data_types.js +83 -0
- package/dist/drivers/pframe/data_types.js.map +1 -0
- package/dist/drivers/pframe/driver.d.ts +0 -1
- package/dist/drivers/pframe/find_columns.d.ts +0 -1
- package/dist/drivers/pframe/index.d.ts +0 -1
- package/dist/drivers/pframe/linker_columns.cjs +218 -0
- package/dist/drivers/pframe/linker_columns.cjs.map +1 -0
- package/dist/drivers/pframe/linker_columns.d.ts +0 -1
- package/dist/drivers/pframe/linker_columns.js +216 -0
- package/dist/drivers/pframe/linker_columns.js.map +1 -0
- package/dist/drivers/pframe/pframe.d.ts +0 -1
- package/dist/drivers/pframe/spec/anchored.cjs +234 -0
- package/dist/drivers/pframe/spec/anchored.cjs.map +1 -0
- package/dist/drivers/pframe/spec/anchored.d.ts +0 -1
- package/dist/drivers/pframe/spec/anchored.js +231 -0
- package/dist/drivers/pframe/spec/anchored.js.map +1 -0
- package/dist/drivers/pframe/spec/filtered_column.cjs +13 -0
- package/dist/drivers/pframe/spec/filtered_column.cjs.map +1 -0
- package/dist/drivers/pframe/spec/filtered_column.d.ts +0 -1
- package/dist/drivers/pframe/spec/filtered_column.js +11 -0
- package/dist/drivers/pframe/spec/filtered_column.js.map +1 -0
- package/dist/drivers/pframe/spec/ids.cjs +24 -0
- package/dist/drivers/pframe/spec/ids.cjs.map +1 -0
- package/dist/drivers/pframe/spec/ids.d.ts +0 -1
- package/dist/drivers/pframe/spec/ids.js +21 -0
- package/dist/drivers/pframe/spec/ids.js.map +1 -0
- package/dist/drivers/pframe/spec/index.d.ts +0 -1
- package/dist/drivers/pframe/spec/native_id.cjs +20 -0
- package/dist/drivers/pframe/spec/native_id.cjs.map +1 -0
- package/dist/drivers/pframe/spec/native_id.d.ts +0 -1
- package/dist/drivers/pframe/spec/native_id.js +18 -0
- package/dist/drivers/pframe/spec/native_id.js.map +1 -0
- package/dist/drivers/pframe/spec/selectors.cjs +120 -0
- package/dist/drivers/pframe/spec/selectors.cjs.map +1 -0
- package/dist/drivers/pframe/spec/selectors.d.ts +0 -1
- package/dist/drivers/pframe/spec/selectors.js +116 -0
- package/dist/drivers/pframe/spec/selectors.js.map +1 -0
- package/dist/drivers/pframe/spec/spec.cjs +361 -0
- package/dist/drivers/pframe/spec/spec.cjs.map +1 -0
- package/dist/drivers/pframe/spec/spec.d.ts +0 -1
- package/dist/drivers/pframe/spec/spec.js +332 -0
- package/dist/drivers/pframe/spec/spec.js.map +1 -0
- package/dist/drivers/pframe/table.d.ts +0 -1
- package/dist/drivers/pframe/table_calculate.cjs +43 -0
- package/dist/drivers/pframe/table_calculate.cjs.map +1 -0
- package/dist/drivers/pframe/table_calculate.d.ts +0 -1
- package/dist/drivers/pframe/table_calculate.js +40 -0
- package/dist/drivers/pframe/table_calculate.js.map +1 -0
- package/dist/drivers/pframe/table_common.cjs +19 -0
- package/dist/drivers/pframe/table_common.cjs.map +1 -0
- package/dist/drivers/pframe/table_common.d.ts +0 -1
- package/dist/drivers/pframe/table_common.js +17 -0
- package/dist/drivers/pframe/table_common.js.map +1 -0
- package/dist/drivers/pframe/type_util.d.ts +0 -1
- package/dist/drivers/pframe/unique_values.d.ts +0 -1
- package/dist/drivers/upload.d.ts +0 -1
- package/dist/drivers/urls.cjs +14 -0
- package/dist/drivers/urls.cjs.map +1 -0
- package/dist/drivers/urls.d.ts +0 -1
- package/dist/drivers/urls.js +11 -0
- package/dist/drivers/urls.js.map +1 -0
- package/dist/errors.cjs +141 -0
- package/dist/errors.cjs.map +1 -0
- package/dist/errors.d.ts +0 -1
- package/dist/errors.js +121 -0
- package/dist/errors.js.map +1 -0
- package/dist/flags/block_flags.cjs +8 -0
- package/dist/flags/block_flags.cjs.map +1 -0
- package/dist/flags/block_flags.d.ts +0 -1
- package/dist/flags/block_flags.js +5 -0
- package/dist/flags/block_flags.js.map +1 -0
- package/dist/flags/flag_utils.cjs +100 -0
- package/dist/flags/flag_utils.cjs.map +1 -0
- package/dist/flags/flag_utils.d.ts +0 -1
- package/dist/flags/flag_utils.js +94 -0
- package/dist/flags/flag_utils.js.map +1 -0
- package/dist/flags/index.d.ts +0 -1
- package/dist/flags/type_utils.d.ts +0 -1
- package/dist/index.cjs +151 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +10 -12
- package/dist/index.js +27 -1
- package/dist/index.js.map +1 -1
- package/dist/json.cjs +18 -0
- package/dist/json.cjs.map +1 -0
- package/dist/json.d.ts +0 -1
- package/dist/json.js +14 -0
- package/dist/json.js.map +1 -0
- package/dist/navigation.cjs +6 -0
- package/dist/navigation.cjs.map +1 -0
- package/dist/navigation.d.ts +0 -1
- package/dist/navigation.js +4 -0
- package/dist/navigation.js.map +1 -0
- package/dist/plid.cjs +37 -0
- package/dist/plid.cjs.map +1 -0
- package/dist/plid.d.ts +0 -1
- package/dist/plid.js +30 -0
- package/dist/plid.js.map +1 -0
- package/dist/pool/entry.d.ts +0 -1
- package/dist/pool/index.d.ts +0 -1
- package/dist/pool/query.cjs +49 -0
- package/dist/pool/query.cjs.map +1 -0
- package/dist/pool/query.d.ts +0 -1
- package/dist/pool/query.js +47 -0
- package/dist/pool/query.js.map +1 -0
- package/dist/pool/spec.cjs +67 -0
- package/dist/pool/spec.cjs.map +1 -0
- package/dist/pool/spec.d.ts +0 -1
- package/dist/pool/spec.js +59 -0
- package/dist/pool/spec.js.map +1 -0
- package/dist/ref.cjs +88 -0
- package/dist/ref.cjs.map +1 -0
- package/dist/ref.d.ts +0 -1
- package/dist/ref.js +82 -0
- package/dist/ref.js.map +1 -0
- package/dist/utag.d.ts +0 -1
- package/dist/util.cjs +8 -0
- package/dist/util.cjs.map +1 -0
- package/dist/util.d.ts +0 -1
- package/dist/util.js +6 -0
- package/dist/util.js.map +1 -0
- package/dist/value_or_error.cjs +8 -0
- package/dist/value_or_error.cjs.map +1 -0
- package/dist/value_or_error.d.ts +0 -1
- package/dist/value_or_error.js +6 -0
- package/dist/value_or_error.js.map +1 -0
- package/package.json +12 -10
- package/src/drivers/pframe/linker_columns.test.ts +48 -0
- package/src/drivers/pframe/linker_columns.ts +14 -7
- package/src/index.ts +10 -11
- package/dist/author_marker.d.ts.map +0 -1
- package/dist/base32_encode.d.ts.map +0 -1
- package/dist/block_state.d.ts.map +0 -1
- package/dist/bmodel/block_config.d.ts.map +0 -1
- package/dist/bmodel/code.d.ts.map +0 -1
- package/dist/bmodel/container.d.ts.map +0 -1
- package/dist/bmodel/index.d.ts.map +0 -1
- package/dist/bmodel/normalization.d.ts.map +0 -1
- package/dist/bmodel/types.d.ts.map +0 -1
- package/dist/branding.d.ts.map +0 -1
- package/dist/common_types.d.ts.map +0 -1
- package/dist/driver_kit.d.ts.map +0 -1
- package/dist/drivers/blob.d.ts.map +0 -1
- package/dist/drivers/index.d.ts.map +0 -1
- package/dist/drivers/interfaces.d.ts.map +0 -1
- package/dist/drivers/log.d.ts.map +0 -1
- package/dist/drivers/ls.d.ts.map +0 -1
- package/dist/drivers/pframe/column_filter.d.ts.map +0 -1
- package/dist/drivers/pframe/data_info.d.ts.map +0 -1
- package/dist/drivers/pframe/data_types.d.ts.map +0 -1
- package/dist/drivers/pframe/driver.d.ts.map +0 -1
- package/dist/drivers/pframe/find_columns.d.ts.map +0 -1
- package/dist/drivers/pframe/index.d.ts.map +0 -1
- package/dist/drivers/pframe/linker_columns.d.ts.map +0 -1
- package/dist/drivers/pframe/pframe.d.ts.map +0 -1
- package/dist/drivers/pframe/spec/anchored.d.ts.map +0 -1
- package/dist/drivers/pframe/spec/filtered_column.d.ts.map +0 -1
- package/dist/drivers/pframe/spec/ids.d.ts.map +0 -1
- package/dist/drivers/pframe/spec/index.d.ts.map +0 -1
- package/dist/drivers/pframe/spec/native_id.d.ts.map +0 -1
- package/dist/drivers/pframe/spec/selectors.d.ts.map +0 -1
- package/dist/drivers/pframe/spec/spec.d.ts.map +0 -1
- package/dist/drivers/pframe/table.d.ts.map +0 -1
- package/dist/drivers/pframe/table_calculate.d.ts.map +0 -1
- package/dist/drivers/pframe/table_common.d.ts.map +0 -1
- package/dist/drivers/pframe/type_util.d.ts.map +0 -1
- package/dist/drivers/pframe/unique_values.d.ts.map +0 -1
- package/dist/drivers/upload.d.ts.map +0 -1
- package/dist/drivers/urls.d.ts.map +0 -1
- package/dist/errors.d.ts.map +0 -1
- package/dist/flags/block_flags.d.ts.map +0 -1
- package/dist/flags/flag_utils.d.ts.map +0 -1
- package/dist/flags/index.d.ts.map +0 -1
- package/dist/flags/type_utils.d.ts.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/index.mjs +0 -1582
- package/dist/index.mjs.map +0 -1
- package/dist/json.d.ts.map +0 -1
- package/dist/navigation.d.ts.map +0 -1
- package/dist/plid.d.ts.map +0 -1
- package/dist/pool/entry.d.ts.map +0 -1
- package/dist/pool/index.d.ts.map +0 -1
- package/dist/pool/query.d.ts.map +0 -1
- package/dist/pool/spec.d.ts.map +0 -1
- package/dist/ref.d.ts.map +0 -1
- package/dist/utag.d.ts.map +0 -1
- package/dist/util.d.ts.map +0 -1
- package/dist/value_or_error.d.ts.map +0 -1
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var canonicalize = require('canonicalize');
|
|
4
|
+
var ids = require('./ids.cjs');
|
|
5
|
+
var spec = require('./spec.cjs');
|
|
6
|
+
|
|
7
|
+
//
|
|
8
|
+
// Helper functions
|
|
9
|
+
//
|
|
10
|
+
function axisKey(axis) {
|
|
11
|
+
return canonicalize(spec.getAxisId(axis));
|
|
12
|
+
}
|
|
13
|
+
function domainKey(key, value) {
|
|
14
|
+
return JSON.stringify([key, value]);
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Context for resolving and generating anchored references to columns and axes
|
|
18
|
+
* Maintains maps of known domain values and axes that can be referenced by anchors
|
|
19
|
+
*/
|
|
20
|
+
class AnchoredIdDeriver {
|
|
21
|
+
anchors;
|
|
22
|
+
domains = new Map();
|
|
23
|
+
axes = new Map();
|
|
24
|
+
/**
|
|
25
|
+
* Domain packs are used to group domain keys that can be anchored to the same anchor
|
|
26
|
+
* This is used to optimize the lookup of domain anchors
|
|
27
|
+
*/
|
|
28
|
+
domainPacks = [];
|
|
29
|
+
/**
|
|
30
|
+
* Maps domain packs to anchors
|
|
31
|
+
*/
|
|
32
|
+
domainPackToAnchor = new Map();
|
|
33
|
+
/**
|
|
34
|
+
* Creates a new anchor context from a set of anchor column specifications
|
|
35
|
+
* @param anchors Record of anchor column specifications indexed by anchor ID
|
|
36
|
+
*/
|
|
37
|
+
constructor(anchors) {
|
|
38
|
+
this.anchors = anchors;
|
|
39
|
+
const anchorEntries = Object.entries(anchors);
|
|
40
|
+
anchorEntries.sort((a, b) => a[0].localeCompare(b[0]));
|
|
41
|
+
for (const [anchorId, spec] of anchorEntries) {
|
|
42
|
+
for (let axisIdx = 0; axisIdx < spec.axesSpec.length; axisIdx++) {
|
|
43
|
+
const axis = spec.axesSpec[axisIdx];
|
|
44
|
+
const key = axisKey(axis);
|
|
45
|
+
this.axes.set(key, { anchor: anchorId, idx: axisIdx });
|
|
46
|
+
}
|
|
47
|
+
if (spec.domain !== undefined) {
|
|
48
|
+
const domainEntries = Object.entries(spec.domain);
|
|
49
|
+
domainEntries.sort((a, b) => a[0].localeCompare(b[0]));
|
|
50
|
+
this.domainPackToAnchor.set(JSON.stringify(domainEntries), anchorId);
|
|
51
|
+
this.domainPacks.push(domainEntries.map(([dKey]) => dKey));
|
|
52
|
+
for (const [dKey, dValue] of domainEntries) {
|
|
53
|
+
const key = domainKey(dKey, dValue);
|
|
54
|
+
this.domains.set(key, anchorId);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Implementation of derive method
|
|
61
|
+
*/
|
|
62
|
+
derive(spec$1, axisFilters) {
|
|
63
|
+
const result = {
|
|
64
|
+
name: spec$1.name,
|
|
65
|
+
axes: [],
|
|
66
|
+
};
|
|
67
|
+
let skipDomains = undefined;
|
|
68
|
+
if (spec$1.domain !== undefined) {
|
|
69
|
+
outer: for (const domainPack of this.domainPacks) {
|
|
70
|
+
const dAnchor = [];
|
|
71
|
+
for (const domainKey of domainPack) {
|
|
72
|
+
const dValue = spec$1.domain[domainKey];
|
|
73
|
+
if (dValue !== undefined)
|
|
74
|
+
dAnchor.push([domainKey, dValue]);
|
|
75
|
+
else
|
|
76
|
+
break outer;
|
|
77
|
+
}
|
|
78
|
+
const domainAnchor = this.domainPackToAnchor.get(JSON.stringify(dAnchor));
|
|
79
|
+
if (domainAnchor !== undefined) {
|
|
80
|
+
result.domainAnchor = domainAnchor;
|
|
81
|
+
skipDomains = new Set(domainPack);
|
|
82
|
+
break;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
for (const [dKey, dValue] of Object.entries(spec$1.domain ?? {})) {
|
|
87
|
+
if (skipDomains !== undefined && skipDomains.has(dKey))
|
|
88
|
+
continue;
|
|
89
|
+
const key = domainKey(dKey, dValue);
|
|
90
|
+
const anchorId = this.domains.get(key);
|
|
91
|
+
result.domain ??= {};
|
|
92
|
+
result.domain[dKey] = anchorId ? { anchor: anchorId } : dValue;
|
|
93
|
+
}
|
|
94
|
+
result.axes = spec$1.axesSpec.map((axis) => {
|
|
95
|
+
const key = axisKey(axis);
|
|
96
|
+
const anchorAxisRef = this.axes.get(key);
|
|
97
|
+
if (anchorAxisRef === undefined)
|
|
98
|
+
return spec.getAxisId(axis);
|
|
99
|
+
else
|
|
100
|
+
return anchorAxisRef;
|
|
101
|
+
});
|
|
102
|
+
// If no axis filters are provided, return the anchored ID as is
|
|
103
|
+
if (!axisFilters || axisFilters.length === 0) {
|
|
104
|
+
return result;
|
|
105
|
+
}
|
|
106
|
+
// Process axis filters and create a sliced column ID
|
|
107
|
+
const resolvedFilters = [];
|
|
108
|
+
for (const filter of axisFilters) {
|
|
109
|
+
const [axisIdOrIndex, value] = filter;
|
|
110
|
+
// If it's already a numeric index, validate it
|
|
111
|
+
if (typeof axisIdOrIndex === 'number') {
|
|
112
|
+
if (axisIdOrIndex < 0 || axisIdOrIndex >= spec$1.axesSpec.length) {
|
|
113
|
+
throw new Error(`Axis index ${axisIdOrIndex} is out of bounds (0-${spec$1.axesSpec.length - 1})`);
|
|
114
|
+
}
|
|
115
|
+
resolvedFilters.push([axisIdOrIndex, value]);
|
|
116
|
+
}
|
|
117
|
+
else {
|
|
118
|
+
// If it's a string (axis name), resolve it to an index
|
|
119
|
+
const axisIndex = spec$1.axesSpec.findIndex((axis) => axis.name === axisIdOrIndex);
|
|
120
|
+
if (axisIndex === -1) {
|
|
121
|
+
throw new Error(`Axis with name "${axisIdOrIndex}" not found in the column specification`);
|
|
122
|
+
}
|
|
123
|
+
resolvedFilters.push([axisIndex, value]);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
// Sort filters by axis index to ensure consistency
|
|
127
|
+
resolvedFilters.sort((a, b) => a[0] - b[0]);
|
|
128
|
+
return {
|
|
129
|
+
source: result,
|
|
130
|
+
axisFilters: resolvedFilters,
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Derives a canonicalized string representation of an anchored column identifier, can be used as a unique identifier for the column
|
|
135
|
+
* @param spec Column specification to anchor
|
|
136
|
+
* @param axisFilters Optional axis filters to apply to the column
|
|
137
|
+
* @returns A canonicalized string representation of the anchored column identifier
|
|
138
|
+
*/
|
|
139
|
+
deriveS(spec, axisFilters) {
|
|
140
|
+
return ids.stringifyColumnId(this.derive(spec, axisFilters));
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Resolves anchored references in a column matcher to create a non-anchored matcher.
|
|
145
|
+
* Doing an opposite operation to {@link AnchorIdDeriver.derive()}.
|
|
146
|
+
*
|
|
147
|
+
* @param anchors - Record of anchor column specifications indexed by anchor id
|
|
148
|
+
* @param matcher - An anchored column matcher (or id, which is subtype of it) containing references that need to be resolved
|
|
149
|
+
* @param options - Options for resolving anchors
|
|
150
|
+
* @returns A non-anchored column matcher with all references resolved to actual values
|
|
151
|
+
*/
|
|
152
|
+
function resolveAnchors(anchors, matcher, options) {
|
|
153
|
+
const result = { ...matcher };
|
|
154
|
+
const ignoreMissingDomains = options?.ignoreMissingDomains ?? false;
|
|
155
|
+
if (result.domainAnchor !== undefined) {
|
|
156
|
+
const anchorSpec = anchors[result.domainAnchor];
|
|
157
|
+
if (!anchorSpec)
|
|
158
|
+
throw new Error(`Anchor "${result.domainAnchor}" not found`);
|
|
159
|
+
const anchorDomains = anchorSpec.domain || {};
|
|
160
|
+
result.domain = { ...anchorDomains, ...result.domain };
|
|
161
|
+
delete result.domainAnchor;
|
|
162
|
+
}
|
|
163
|
+
if (result.domain) {
|
|
164
|
+
const resolvedDomain = {};
|
|
165
|
+
for (const [key, value] of Object.entries(result.domain)) {
|
|
166
|
+
if (typeof value === 'string') {
|
|
167
|
+
resolvedDomain[key] = value;
|
|
168
|
+
}
|
|
169
|
+
else {
|
|
170
|
+
// It's an AnchorDomainRef
|
|
171
|
+
const anchorSpec = anchors[value.anchor];
|
|
172
|
+
if (!anchorSpec)
|
|
173
|
+
throw new Error(`Anchor "${value.anchor}" not found for domain key "${key}"`);
|
|
174
|
+
if (!anchorSpec.domain || anchorSpec.domain[key] === undefined) {
|
|
175
|
+
if (!ignoreMissingDomains)
|
|
176
|
+
throw new Error(`Domain key "${key}" not found in anchor "${value.anchor}"`);
|
|
177
|
+
continue;
|
|
178
|
+
}
|
|
179
|
+
resolvedDomain[key] = anchorSpec.domain[key];
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
result.domain = resolvedDomain;
|
|
183
|
+
}
|
|
184
|
+
if (result.axes)
|
|
185
|
+
result.axes = result.axes.map((axis) => resolveAxisReference(anchors, axis));
|
|
186
|
+
return result;
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* Resolves an anchored axis reference to a concrete AxisId
|
|
190
|
+
*/
|
|
191
|
+
function resolveAxisReference(anchors, axisRef) {
|
|
192
|
+
if (!isAnchorAxisRef(axisRef))
|
|
193
|
+
return axisRef;
|
|
194
|
+
// It's an anchored reference
|
|
195
|
+
const anchorId = axisRef.anchor;
|
|
196
|
+
const anchorSpec = anchors[anchorId];
|
|
197
|
+
if (!anchorSpec)
|
|
198
|
+
throw new Error(`Anchor "${anchorId}" not found for axis reference`);
|
|
199
|
+
if ('idx' in axisRef) {
|
|
200
|
+
// AnchorAxisRefByIdx
|
|
201
|
+
if (axisRef.idx < 0 || axisRef.idx >= anchorSpec.axesSpec.length)
|
|
202
|
+
throw new Error(`Axis index ${axisRef.idx} out of bounds for anchor "${anchorId}"`);
|
|
203
|
+
return anchorSpec.axesSpec[axisRef.idx];
|
|
204
|
+
}
|
|
205
|
+
else if ('name' in axisRef) {
|
|
206
|
+
// AnchorAxisRefByName
|
|
207
|
+
const matches = anchorSpec.axesSpec.filter((axis) => axis.name === axisRef.name);
|
|
208
|
+
if (matches.length > 1)
|
|
209
|
+
throw new Error(`Multiple axes with name "${axisRef.name}" found in anchor "${anchorId}"`);
|
|
210
|
+
if (matches.length === 0)
|
|
211
|
+
throw new Error(`Axis with name "${axisRef.name}" not found in anchor "${anchorId}"`);
|
|
212
|
+
return matches[0];
|
|
213
|
+
}
|
|
214
|
+
else if ('id' in axisRef) {
|
|
215
|
+
// AnchorAxisRefByMatcher
|
|
216
|
+
const matches = anchorSpec.axesSpec.filter((axis) => spec.matchAxisId(axisRef.id, spec.getAxisId(axis)));
|
|
217
|
+
if (matches.length > 1)
|
|
218
|
+
throw new Error(`Multiple matching axes found for matcher in anchor "${anchorId}"`);
|
|
219
|
+
if (matches.length === 0)
|
|
220
|
+
throw new Error(`No matching axis found for matcher in anchor "${anchorId}"`);
|
|
221
|
+
return matches[0];
|
|
222
|
+
}
|
|
223
|
+
throw new Error(`Unsupported axis reference type`);
|
|
224
|
+
}
|
|
225
|
+
/**
|
|
226
|
+
* Type guard to check if a value is an anchored axis reference
|
|
227
|
+
*/
|
|
228
|
+
function isAnchorAxisRef(value) {
|
|
229
|
+
return typeof value === 'object' && 'anchor' in value;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
exports.AnchoredIdDeriver = AnchoredIdDeriver;
|
|
233
|
+
exports.resolveAnchors = resolveAnchors;
|
|
234
|
+
//# sourceMappingURL=anchored.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"anchored.cjs","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 { AAxisSelector, AnchorAxisRef, AnchorAxisRefByIdx, AnchoredPColumnId, AnchoredPColumnSelector, AxisSelector, PColumnSelector } 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 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 /**\n * Maps domain packs to anchors\n */\n private readonly domainPackToAnchor = 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 }\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:\n 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)\n dAnchor.push([domainKey, dValue]);\n else\n 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))\n 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 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(`Axis index ${axisIdOrIndex} is out of bounds (0-${spec.axesSpec.length - 1})`);\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(`Axis with name \"${axisIdOrIndex}\" not found in the column specification`);\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(anchors: Record<string, PColumnSpec>, matcher: AnchoredPColumnSelector, options?: ResolveAnchorsOptions): 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)\n 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.axes)\n 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(anchors: Record<string, PColumnSpec>, axisRef: AAxisSelector): AxisSelector {\n if (!isAnchorAxisRef(axisRef))\n return axisRef;\n\n // It's an anchored reference\n const anchorId = axisRef.anchor;\n const anchorSpec = anchors[anchorId];\n if (!anchorSpec)\n 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"],"names":["getAxisId","spec","stringifyColumnId","matchAxisId"],"mappings":";;;;;;AAQA;AACA;AACA;AAEA,SAAS,OAAO,CAAC,IAAY,EAAA;AAC3B,IAAA,OAAO,YAAY,CAACA,cAAS,CAAC,IAAI,CAAC,CAAE;AACvC;AAEA,SAAS,SAAS,CAAC,GAAW,EAAE,KAAa,EAAA;IAC3C,OAAO,IAAI,CAAC,SAAS,CAAC,CAAC,GAAG,EAAE,KAAK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C,CAAA,yBAAA,EAA4B,OAAO,CAAC,IAAI,CAAA,mBAAA,EAAsB,QAAQ,CAAA,CAAA,CAAG,CAAC;AAC5F,QAAA,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC;YACtB,MAAM,IAAI,KAAK,CAAC,CAAA,gBAAA,EAAmB,OAAO,CAAC,IAAI,CAAA,uBAAA,EAA0B,QAAQ,CAAA,CAAA,CAAG,CAAC;AACvF,QAAA,OAAO,OAAO,CAAC,CAAC,CAAC;IACnB;AAAO,SAAA,IAAI,IAAI,IAAI,OAAO,EAAE;;QAE1B,MAAM,OAAO,GAAG,UAAU,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,IAAI,KAAKC,gBAAW,CAAC,OAAO,CAAC,EAAE,EAAEH,cAAS,CAAC,IAAI,CAAC,CAAC,CAAC;AAC9F,QAAA,IAAI,OAAO,CAAC,MAAM,GAAG,CAAC;AACpB,YAAA,MAAM,IAAI,KAAK,CAAC,uDAAuD,QAAQ,CAAA,CAAA,CAAG,CAAC;AACrF,QAAA,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC;AACtB,YAAA,MAAM,IAAI,KAAK,CAAC,iDAAiD,QAAQ,CAAA,CAAA,CAAG,CAAC;AAC/E,QAAA,OAAO,OAAO,CAAC,CAAC,CAAC;IACnB;AAEA,IAAA,MAAM,IAAI,KAAK,CAAC,CAAA,+BAAA,CAAiC,CAAC;AACpD;AAEA;;AAEG;AACH,SAAS,eAAe,CAAC,KAAoB,EAAA;IAC3C,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,QAAQ,IAAI,KAAK;AACvD;;;;;"}
|
|
@@ -65,4 +65,3 @@ export type ResolveAnchorsOptions = {
|
|
|
65
65
|
* @returns A non-anchored column matcher with all references resolved to actual values
|
|
66
66
|
*/
|
|
67
67
|
export declare function resolveAnchors(anchors: Record<string, PColumnSpec>, matcher: AnchoredPColumnSelector, options?: ResolveAnchorsOptions): PColumnSelector;
|
|
68
|
-
//# sourceMappingURL=anchored.d.ts.map
|
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
import canonicalize from 'canonicalize';
|
|
2
|
+
import { stringifyColumnId } from './ids.js';
|
|
3
|
+
import { getAxisId, matchAxisId } from './spec.js';
|
|
4
|
+
|
|
5
|
+
//
|
|
6
|
+
// Helper functions
|
|
7
|
+
//
|
|
8
|
+
function axisKey(axis) {
|
|
9
|
+
return canonicalize(getAxisId(axis));
|
|
10
|
+
}
|
|
11
|
+
function domainKey(key, value) {
|
|
12
|
+
return JSON.stringify([key, value]);
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Context for resolving and generating anchored references to columns and axes
|
|
16
|
+
* Maintains maps of known domain values and axes that can be referenced by anchors
|
|
17
|
+
*/
|
|
18
|
+
class AnchoredIdDeriver {
|
|
19
|
+
anchors;
|
|
20
|
+
domains = new Map();
|
|
21
|
+
axes = new Map();
|
|
22
|
+
/**
|
|
23
|
+
* Domain packs are used to group domain keys that can be anchored to the same anchor
|
|
24
|
+
* This is used to optimize the lookup of domain anchors
|
|
25
|
+
*/
|
|
26
|
+
domainPacks = [];
|
|
27
|
+
/**
|
|
28
|
+
* Maps domain packs to anchors
|
|
29
|
+
*/
|
|
30
|
+
domainPackToAnchor = new Map();
|
|
31
|
+
/**
|
|
32
|
+
* Creates a new anchor context from a set of anchor column specifications
|
|
33
|
+
* @param anchors Record of anchor column specifications indexed by anchor ID
|
|
34
|
+
*/
|
|
35
|
+
constructor(anchors) {
|
|
36
|
+
this.anchors = anchors;
|
|
37
|
+
const anchorEntries = Object.entries(anchors);
|
|
38
|
+
anchorEntries.sort((a, b) => a[0].localeCompare(b[0]));
|
|
39
|
+
for (const [anchorId, spec] of anchorEntries) {
|
|
40
|
+
for (let axisIdx = 0; axisIdx < spec.axesSpec.length; axisIdx++) {
|
|
41
|
+
const axis = spec.axesSpec[axisIdx];
|
|
42
|
+
const key = axisKey(axis);
|
|
43
|
+
this.axes.set(key, { anchor: anchorId, idx: axisIdx });
|
|
44
|
+
}
|
|
45
|
+
if (spec.domain !== undefined) {
|
|
46
|
+
const domainEntries = Object.entries(spec.domain);
|
|
47
|
+
domainEntries.sort((a, b) => a[0].localeCompare(b[0]));
|
|
48
|
+
this.domainPackToAnchor.set(JSON.stringify(domainEntries), anchorId);
|
|
49
|
+
this.domainPacks.push(domainEntries.map(([dKey]) => dKey));
|
|
50
|
+
for (const [dKey, dValue] of domainEntries) {
|
|
51
|
+
const key = domainKey(dKey, dValue);
|
|
52
|
+
this.domains.set(key, anchorId);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Implementation of derive method
|
|
59
|
+
*/
|
|
60
|
+
derive(spec, axisFilters) {
|
|
61
|
+
const result = {
|
|
62
|
+
name: spec.name,
|
|
63
|
+
axes: [],
|
|
64
|
+
};
|
|
65
|
+
let skipDomains = undefined;
|
|
66
|
+
if (spec.domain !== undefined) {
|
|
67
|
+
outer: for (const domainPack of this.domainPacks) {
|
|
68
|
+
const dAnchor = [];
|
|
69
|
+
for (const domainKey of domainPack) {
|
|
70
|
+
const dValue = spec.domain[domainKey];
|
|
71
|
+
if (dValue !== undefined)
|
|
72
|
+
dAnchor.push([domainKey, dValue]);
|
|
73
|
+
else
|
|
74
|
+
break outer;
|
|
75
|
+
}
|
|
76
|
+
const domainAnchor = this.domainPackToAnchor.get(JSON.stringify(dAnchor));
|
|
77
|
+
if (domainAnchor !== undefined) {
|
|
78
|
+
result.domainAnchor = domainAnchor;
|
|
79
|
+
skipDomains = new Set(domainPack);
|
|
80
|
+
break;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
for (const [dKey, dValue] of Object.entries(spec.domain ?? {})) {
|
|
85
|
+
if (skipDomains !== undefined && skipDomains.has(dKey))
|
|
86
|
+
continue;
|
|
87
|
+
const key = domainKey(dKey, dValue);
|
|
88
|
+
const anchorId = this.domains.get(key);
|
|
89
|
+
result.domain ??= {};
|
|
90
|
+
result.domain[dKey] = anchorId ? { anchor: anchorId } : dValue;
|
|
91
|
+
}
|
|
92
|
+
result.axes = spec.axesSpec.map((axis) => {
|
|
93
|
+
const key = axisKey(axis);
|
|
94
|
+
const anchorAxisRef = this.axes.get(key);
|
|
95
|
+
if (anchorAxisRef === undefined)
|
|
96
|
+
return getAxisId(axis);
|
|
97
|
+
else
|
|
98
|
+
return anchorAxisRef;
|
|
99
|
+
});
|
|
100
|
+
// If no axis filters are provided, return the anchored ID as is
|
|
101
|
+
if (!axisFilters || axisFilters.length === 0) {
|
|
102
|
+
return result;
|
|
103
|
+
}
|
|
104
|
+
// Process axis filters and create a sliced column ID
|
|
105
|
+
const resolvedFilters = [];
|
|
106
|
+
for (const filter of axisFilters) {
|
|
107
|
+
const [axisIdOrIndex, value] = filter;
|
|
108
|
+
// If it's already a numeric index, validate it
|
|
109
|
+
if (typeof axisIdOrIndex === 'number') {
|
|
110
|
+
if (axisIdOrIndex < 0 || axisIdOrIndex >= spec.axesSpec.length) {
|
|
111
|
+
throw new Error(`Axis index ${axisIdOrIndex} is out of bounds (0-${spec.axesSpec.length - 1})`);
|
|
112
|
+
}
|
|
113
|
+
resolvedFilters.push([axisIdOrIndex, value]);
|
|
114
|
+
}
|
|
115
|
+
else {
|
|
116
|
+
// If it's a string (axis name), resolve it to an index
|
|
117
|
+
const axisIndex = spec.axesSpec.findIndex((axis) => axis.name === axisIdOrIndex);
|
|
118
|
+
if (axisIndex === -1) {
|
|
119
|
+
throw new Error(`Axis with name "${axisIdOrIndex}" not found in the column specification`);
|
|
120
|
+
}
|
|
121
|
+
resolvedFilters.push([axisIndex, value]);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
// Sort filters by axis index to ensure consistency
|
|
125
|
+
resolvedFilters.sort((a, b) => a[0] - b[0]);
|
|
126
|
+
return {
|
|
127
|
+
source: result,
|
|
128
|
+
axisFilters: resolvedFilters,
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Derives a canonicalized string representation of an anchored column identifier, can be used as a unique identifier for the column
|
|
133
|
+
* @param spec Column specification to anchor
|
|
134
|
+
* @param axisFilters Optional axis filters to apply to the column
|
|
135
|
+
* @returns A canonicalized string representation of the anchored column identifier
|
|
136
|
+
*/
|
|
137
|
+
deriveS(spec, axisFilters) {
|
|
138
|
+
return stringifyColumnId(this.derive(spec, axisFilters));
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Resolves anchored references in a column matcher to create a non-anchored matcher.
|
|
143
|
+
* Doing an opposite operation to {@link AnchorIdDeriver.derive()}.
|
|
144
|
+
*
|
|
145
|
+
* @param anchors - Record of anchor column specifications indexed by anchor id
|
|
146
|
+
* @param matcher - An anchored column matcher (or id, which is subtype of it) containing references that need to be resolved
|
|
147
|
+
* @param options - Options for resolving anchors
|
|
148
|
+
* @returns A non-anchored column matcher with all references resolved to actual values
|
|
149
|
+
*/
|
|
150
|
+
function resolveAnchors(anchors, matcher, options) {
|
|
151
|
+
const result = { ...matcher };
|
|
152
|
+
const ignoreMissingDomains = options?.ignoreMissingDomains ?? false;
|
|
153
|
+
if (result.domainAnchor !== undefined) {
|
|
154
|
+
const anchorSpec = anchors[result.domainAnchor];
|
|
155
|
+
if (!anchorSpec)
|
|
156
|
+
throw new Error(`Anchor "${result.domainAnchor}" not found`);
|
|
157
|
+
const anchorDomains = anchorSpec.domain || {};
|
|
158
|
+
result.domain = { ...anchorDomains, ...result.domain };
|
|
159
|
+
delete result.domainAnchor;
|
|
160
|
+
}
|
|
161
|
+
if (result.domain) {
|
|
162
|
+
const resolvedDomain = {};
|
|
163
|
+
for (const [key, value] of Object.entries(result.domain)) {
|
|
164
|
+
if (typeof value === 'string') {
|
|
165
|
+
resolvedDomain[key] = value;
|
|
166
|
+
}
|
|
167
|
+
else {
|
|
168
|
+
// It's an AnchorDomainRef
|
|
169
|
+
const anchorSpec = anchors[value.anchor];
|
|
170
|
+
if (!anchorSpec)
|
|
171
|
+
throw new Error(`Anchor "${value.anchor}" not found for domain key "${key}"`);
|
|
172
|
+
if (!anchorSpec.domain || anchorSpec.domain[key] === undefined) {
|
|
173
|
+
if (!ignoreMissingDomains)
|
|
174
|
+
throw new Error(`Domain key "${key}" not found in anchor "${value.anchor}"`);
|
|
175
|
+
continue;
|
|
176
|
+
}
|
|
177
|
+
resolvedDomain[key] = anchorSpec.domain[key];
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
result.domain = resolvedDomain;
|
|
181
|
+
}
|
|
182
|
+
if (result.axes)
|
|
183
|
+
result.axes = result.axes.map((axis) => resolveAxisReference(anchors, axis));
|
|
184
|
+
return result;
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* Resolves an anchored axis reference to a concrete AxisId
|
|
188
|
+
*/
|
|
189
|
+
function resolveAxisReference(anchors, axisRef) {
|
|
190
|
+
if (!isAnchorAxisRef(axisRef))
|
|
191
|
+
return axisRef;
|
|
192
|
+
// It's an anchored reference
|
|
193
|
+
const anchorId = axisRef.anchor;
|
|
194
|
+
const anchorSpec = anchors[anchorId];
|
|
195
|
+
if (!anchorSpec)
|
|
196
|
+
throw new Error(`Anchor "${anchorId}" not found for axis reference`);
|
|
197
|
+
if ('idx' in axisRef) {
|
|
198
|
+
// AnchorAxisRefByIdx
|
|
199
|
+
if (axisRef.idx < 0 || axisRef.idx >= anchorSpec.axesSpec.length)
|
|
200
|
+
throw new Error(`Axis index ${axisRef.idx} out of bounds for anchor "${anchorId}"`);
|
|
201
|
+
return anchorSpec.axesSpec[axisRef.idx];
|
|
202
|
+
}
|
|
203
|
+
else if ('name' in axisRef) {
|
|
204
|
+
// AnchorAxisRefByName
|
|
205
|
+
const matches = anchorSpec.axesSpec.filter((axis) => axis.name === axisRef.name);
|
|
206
|
+
if (matches.length > 1)
|
|
207
|
+
throw new Error(`Multiple axes with name "${axisRef.name}" found in anchor "${anchorId}"`);
|
|
208
|
+
if (matches.length === 0)
|
|
209
|
+
throw new Error(`Axis with name "${axisRef.name}" not found in anchor "${anchorId}"`);
|
|
210
|
+
return matches[0];
|
|
211
|
+
}
|
|
212
|
+
else if ('id' in axisRef) {
|
|
213
|
+
// AnchorAxisRefByMatcher
|
|
214
|
+
const matches = anchorSpec.axesSpec.filter((axis) => matchAxisId(axisRef.id, getAxisId(axis)));
|
|
215
|
+
if (matches.length > 1)
|
|
216
|
+
throw new Error(`Multiple matching axes found for matcher in anchor "${anchorId}"`);
|
|
217
|
+
if (matches.length === 0)
|
|
218
|
+
throw new Error(`No matching axis found for matcher in anchor "${anchorId}"`);
|
|
219
|
+
return matches[0];
|
|
220
|
+
}
|
|
221
|
+
throw new Error(`Unsupported axis reference type`);
|
|
222
|
+
}
|
|
223
|
+
/**
|
|
224
|
+
* Type guard to check if a value is an anchored axis reference
|
|
225
|
+
*/
|
|
226
|
+
function isAnchorAxisRef(value) {
|
|
227
|
+
return typeof value === 'object' && 'anchor' in value;
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
export { AnchoredIdDeriver, resolveAnchors };
|
|
231
|
+
//# sourceMappingURL=anchored.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"anchored.js","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 { AAxisSelector, AnchorAxisRef, AnchorAxisRefByIdx, AnchoredPColumnId, AnchoredPColumnSelector, AxisSelector, PColumnSelector } 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 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 /**\n * Maps domain packs to anchors\n */\n private readonly domainPackToAnchor = 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 }\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:\n 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)\n dAnchor.push([domainKey, dValue]);\n else\n 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))\n 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 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(`Axis index ${axisIdOrIndex} is out of bounds (0-${spec.axesSpec.length - 1})`);\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(`Axis with name \"${axisIdOrIndex}\" not found in the column specification`);\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(anchors: Record<string, PColumnSpec>, matcher: AnchoredPColumnSelector, options?: ResolveAnchorsOptions): 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)\n 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.axes)\n 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(anchors: Record<string, PColumnSpec>, axisRef: AAxisSelector): AxisSelector {\n if (!isAnchorAxisRef(axisRef))\n return axisRef;\n\n // It's an anchored reference\n const anchorId = axisRef.anchor;\n const anchorSpec = anchors[anchorId];\n if (!anchorSpec)\n 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"],"names":[],"mappings":";;;;AAQA;AACA;AACA;AAEA,SAAS,OA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|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Checks if a given value is a FilteredPColumn
|
|
5
|
+
* @param id - The value to check
|
|
6
|
+
* @returns True if the value is a FilteredPColumn, false otherwise
|
|
7
|
+
*/
|
|
8
|
+
function isFilteredPColumn(id) {
|
|
9
|
+
return typeof id === 'object' && id !== null && 'source' in id && 'axisFilters' in id;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
exports.isFilteredPColumn = isFilteredPColumn;
|
|
13
|
+
//# sourceMappingURL=filtered_column.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"filtered_column.cjs","sources":["../../../../src/drivers/pframe/spec/filtered_column.ts"],"sourcesContent":["import type { AnchoredPColumnId } from './selectors';\n\n/** Value of an axis filter */\nexport type AxisFilterValue = number | string;\n\n/** Axis filter by index */\nexport type AxisFilterByIdx = [number, AxisFilterValue];\n\n/** Axis filter by name */\nexport type AxisFilterByName = [string, AxisFilterValue];\n\n/** Axis filter */\nexport type AxisFilter = AxisFilterByIdx | AxisFilterByName;\n\n/**\n * Identifies a column derived from a CanonicalPColumnId by fixing values on certain axes,\n * thus effectively reducing the dimensionality of the original column.\n */\nexport type FilteredPColumn<CID = AnchoredPColumnId, AFI = AxisFilter> = {\n /** The original column identifier */\n source: CID;\n\n /**\n * List of fixed axes and their corresponding values.\n * Each entry fixes one axis to a specific value, creating a slice of the multidimensional data.\n * This effectively reduces the dimensionality by one for each fixed axis.\n * Ordered by the axis index in canonical case.\n */\n axisFilters: AFI[];\n};\n\nexport type FilteredPColumnId = FilteredPColumn<AnchoredPColumnId, AxisFilterByIdx>;\n\n/**\n * Checks if a given value is a FilteredPColumn\n * @param id - The value to check\n * @returns True if the value is a FilteredPColumn, false otherwise\n */\nexport function isFilteredPColumn(id: unknown): id is FilteredPColumn {\n return typeof id === 'object' && id !== null && 'source' in id && 'axisFilters' in id;\n}\n"],"names":[],"mappings":";;AAiCA;;;;AAIG;AACG,SAAU,iBAAiB,CAAC,EAAW,EAAA;AAC3C,IAAA,OAAO,OAAO,EAAE,KAAK,QAAQ,IAAI,EAAE,KAAK,IAAI,IAAI,QAAQ,IAAI,EAAE,IAAI,aAAa,IAAI,EAAE;AACvF;;;;"}
|
|
@@ -29,4 +29,3 @@ export type FilteredPColumnId = FilteredPColumn<AnchoredPColumnId, AxisFilterByI
|
|
|
29
29
|
* @returns True if the value is a FilteredPColumn, false otherwise
|
|
30
30
|
*/
|
|
31
31
|
export declare function isFilteredPColumn(id: unknown): id is FilteredPColumn;
|
|
32
|
-
//# sourceMappingURL=filtered_column.d.ts.map
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Checks if a given value is a FilteredPColumn
|
|
3
|
+
* @param id - The value to check
|
|
4
|
+
* @returns True if the value is a FilteredPColumn, false otherwise
|
|
5
|
+
*/
|
|
6
|
+
function isFilteredPColumn(id) {
|
|
7
|
+
return typeof id === 'object' && id !== null && 'source' in id && 'axisFilters' in id;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export { isFilteredPColumn };
|
|
11
|
+
//# sourceMappingURL=filtered_column.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"filtered_column.js","sources":["../../../../src/drivers/pframe/spec/filtered_column.ts"],"sourcesContent":["import type { AnchoredPColumnId } from './selectors';\n\n/** Value of an axis filter */\nexport type AxisFilterValue = number | string;\n\n/** Axis filter by index */\nexport type AxisFilterByIdx = [number, AxisFilterValue];\n\n/** Axis filter by name */\nexport type AxisFilterByName = [string, AxisFilterValue];\n\n/** Axis filter */\nexport type AxisFilter = AxisFilterByIdx | AxisFilterByName;\n\n/**\n * Identifies a column derived from a CanonicalPColumnId by fixing values on certain axes,\n * thus effectively reducing the dimensionality of the original column.\n */\nexport type FilteredPColumn<CID = AnchoredPColumnId, AFI = AxisFilter> = {\n /** The original column identifier */\n source: CID;\n\n /**\n * List of fixed axes and their corresponding values.\n * Each entry fixes one axis to a specific value, creating a slice of the multidimensional data.\n * This effectively reduces the dimensionality by one for each fixed axis.\n * Ordered by the axis index in canonical case.\n */\n axisFilters: AFI[];\n};\n\nexport type FilteredPColumnId = FilteredPColumn<AnchoredPColumnId, AxisFilterByIdx>;\n\n/**\n * Checks if a given value is a FilteredPColumn\n * @param id - The value to check\n * @returns True if the value is a FilteredPColumn, false otherwise\n */\nexport function isFilteredPColumn(id: unknown): id is FilteredPColumn {\n return typeof id === 'object' && id !== null && 'source' in id && 'axisFilters' in id;\n}\n"],"names":[],"mappings":"AAiCA;;;;AAIG;AACG,SAAU,iBAAiB,CAAC,EAAW,EAAA;AAC3C,IAAA,OAAO,OAAO,EAAE,KAAK,QAAQ,IAAI,EAAE,KAAK,IAAI,IAAI,QAAQ,IAAI,EAAE,IAAI,aAAa,IAAI,EAAE;AACvF;;;;"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var canonicalize = require('canonicalize');
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Canonically serializes a {@link UniversalPColumnId} to a string.
|
|
7
|
+
* @param id - The column identifier to serialize
|
|
8
|
+
* @returns The canonically serialized string
|
|
9
|
+
*/
|
|
10
|
+
function stringifyColumnId(id) {
|
|
11
|
+
return canonicalize(id);
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Parses a canonically serialized {@link UniversalPColumnId} from a string.
|
|
15
|
+
* @param str - The string to parse
|
|
16
|
+
* @returns The parsed column identifier
|
|
17
|
+
*/
|
|
18
|
+
function parseColumnId(str) {
|
|
19
|
+
return JSON.parse(str);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
exports.parseColumnId = parseColumnId;
|
|
23
|
+
exports.stringifyColumnId = stringifyColumnId;
|
|
24
|
+
//# sourceMappingURL=ids.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ids.cjs","sources":["../../../../src/drivers/pframe/spec/ids.ts"],"sourcesContent":["import type { Branded } from '../../../branding';\nimport type { AnchoredPColumnId } from './selectors';\nimport type { FilteredPColumnId } from './filtered_column';\nimport canonicalize from 'canonicalize';\nimport type { PObjectId } from '../../../pool';\n/**\n * Universal column identifier optionally anchored and optionally filtered.\n */\nexport type UniversalPColumnId = AnchoredPColumnId | FilteredPColumnId;\n\n/**\n * Canonically serialized {@link UniversalPColumnId}.\n */\nexport type SUniversalPColumnId = Branded<PObjectId, 'SUniversalPColumnId', '__pl_model_brand_2__'>;\n\n/**\n * Canonically serializes a {@link UniversalPColumnId} to a string.\n * @param id - The column identifier to serialize\n * @returns The canonically serialized string\n */\nexport function stringifyColumnId(id: UniversalPColumnId): SUniversalPColumnId {\n return canonicalize(id)! as SUniversalPColumnId;\n}\n\n/**\n * Parses a canonically serialized {@link UniversalPColumnId} from a string.\n * @param str - The string to parse\n * @returns The parsed column identifier\n */\nexport function parseColumnId(str: SUniversalPColumnId): UniversalPColumnId {\n return JSON.parse(str) as UniversalPColumnId;\n}\n"],"names":[],"mappings":";;;;AAeA;;;;AAIG;AACG,SAAU,iBAAiB,CAAC,EAAsB,EAAA;AACtD,IAAA,OAAO,YAAY,CAAC,EAAE,CAAyB;AACjD;AAEA;;;;AAIG;AACG,SAAU,aAAa,CAAC,GAAwB,EAAA;AACpD,IAAA,OAAO,IAAI,CAAC,KAAK,CAAC,GAAG,CAAuB;AAC9C;;;;;"}
|