@milaboratories/pl-model-common 1.13.4 → 1.13.6

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.
@@ -1,11 +1,11 @@
1
1
  import canonicalize from 'canonicalize';
2
- import type { AxisId, PColumnSpec } from './spec';
3
- import { getAxisId, matchAxisId } from './spec';
4
- import type { AAxisSelector, AnchorAxisRef, AnchorAxisRefByIdx, AnchoredPColumnId, AnchoredPColumnSelector, AxisSelector, PColumnSelector } from './selectors';
5
- import type { AxisFilter } from './filtered_column';
6
2
  import type { PValue } from '../data_types';
3
+ import type { AxisFilter } from './filtered_column';
7
4
  import type { SUniversalPColumnId, UniversalPColumnId } from './ids';
8
5
  import { stringifyColumnId } from './ids';
6
+ import type { AAxisSelector, AnchorAxisRef, AnchorAxisRefByIdx, AnchoredPColumnId, AnchoredPColumnSelector, AxisSelector, PColumnSelector } from './selectors';
7
+ import type { AxisId, PColumnSpec } from './spec';
8
+ import { getAxisId, matchAxisId } from './spec';
9
9
 
10
10
  //
11
11
  // Helper functions
@@ -121,7 +121,8 @@ export class AnchoredIdDeriver {
121
121
  result.axes = spec.axesSpec.map((axis) => {
122
122
  const key = axisKey(axis);
123
123
  const anchorAxisRef = this.axes.get(key);
124
- return anchorAxisRef ?? axis;
124
+ if (anchorAxisRef === undefined) return getAxisId(axis);
125
+ else return anchorAxisRef;
125
126
  });
126
127
 
127
128
  // If no axis filters are provided, return the anchored ID as is
@@ -171,16 +172,29 @@ export class AnchoredIdDeriver {
171
172
  }
172
173
  }
173
174
 
175
+ /**
176
+ * Options for the resolveAnchors function
177
+ */
178
+ export type ResolveAnchorsOptions = {
179
+ /**
180
+ * If true, missing domain keys in anchors will be ignored.
181
+ * If false (default), an error will be thrown.
182
+ */
183
+ ignoreMissingDomains?: boolean;
184
+ };
185
+
174
186
  /**
175
187
  * Resolves anchored references in a column matcher to create a non-anchored matcher.
176
188
  * Doing an opposite operation to {@link AnchorIdDeriver.derive()}.
177
189
  *
178
190
  * @param anchors - Record of anchor column specifications indexed by anchor id
179
191
  * @param matcher - An anchored column matcher (or id, which is subtype of it) containing references that need to be resolved
192
+ * @param options - Options for resolving anchors
180
193
  * @returns A non-anchored column matcher with all references resolved to actual values
181
194
  */
182
- export function resolveAnchors(anchors: Record<string, PColumnSpec>, matcher: AnchoredPColumnSelector): PColumnSelector {
195
+ export function resolveAnchors(anchors: Record<string, PColumnSpec>, matcher: AnchoredPColumnSelector, options?: ResolveAnchorsOptions): PColumnSelector {
183
196
  const result = { ...matcher };
197
+ const ignoreMissingDomains = options?.ignoreMissingDomains ?? false;
184
198
 
185
199
  if (result.domainAnchor !== undefined) {
186
200
  const anchorSpec = anchors[result.domainAnchor];
@@ -203,8 +217,11 @@ export function resolveAnchors(anchors: Record<string, PColumnSpec>, matcher: An
203
217
  if (!anchorSpec)
204
218
  throw new Error(`Anchor "${value.anchor}" not found for domain key "${key}"`);
205
219
 
206
- if (!anchorSpec.domain || anchorSpec.domain[key] === undefined)
207
- throw new Error(`Domain key "${key}" not found in anchor "${value.anchor}"`);
220
+ if (!anchorSpec.domain || anchorSpec.domain[key] === undefined) {
221
+ if (!ignoreMissingDomains)
222
+ throw new Error(`Domain key "${key}" not found in anchor "${value.anchor}"`);
223
+ continue;
224
+ }
208
225
 
209
226
  resolvedDomain[key] = anchorSpec.domain[key];
210
227
  }
@@ -119,6 +119,14 @@ export interface PColumnIdAndSpec {
119
119
  readonly spec: PColumnSpec;
120
120
  }
121
121
 
122
+ /** Get column id and spec from a column */
123
+ export function getColumnIdAndSpec<Data>(column: PColumn<Data>): PColumnIdAndSpec {
124
+ return {
125
+ columnId: column.id,
126
+ spec: column.spec,
127
+ };
128
+ }
129
+
122
130
  /** Information returned by {@link PFrame.listColumns} method */
123
131
  export interface PColumnInfo extends PColumnIdAndSpec {
124
132
  /** True if data was associated with this PColumn */