@milaboratories/pl-model-common 1.13.3 → 1.13.5

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.
@@ -235,13 +235,19 @@ export interface BinaryPartitionedDataInfoEntries<Blob> {
235
235
  parts: PColumnDataEntry<BinaryChunk<Blob>>[];
236
236
  }
237
237
 
238
+ /**
239
+ * Union type representing all possible entry-based partitioned data storage formats
240
+ */
241
+ export type PartitionedDataInfoEntries<Blob> =
242
+ | JsonPartitionedDataInfoEntries<Blob>
243
+ | BinaryPartitionedDataInfoEntries<Blob>;
244
+
238
245
  /**
239
246
  * Union type representing all possible entry-based data storage formats
240
247
  */
241
248
  export type DataInfoEntries<Blob> =
242
249
  | JsonDataInfoEntries
243
- | JsonPartitionedDataInfoEntries<Blob>
244
- | BinaryPartitionedDataInfoEntries<Blob>;
250
+ | PartitionedDataInfoEntries<Blob>;
245
251
 
246
252
  /**
247
253
  * Type guard function that checks if the given value is a valid DataInfoEntries.
@@ -280,6 +286,18 @@ export function isDataInfoEntries<Blob>(value: unknown): value is DataInfoEntrie
280
286
  }
281
287
  }
282
288
 
289
+ /**
290
+ * Type guard function that checks if the given value is a valid PartitionedDataInfoEntries.
291
+ *
292
+ * @template Blob - Type parameter representing the storage reference type
293
+ * @param value - The value to check
294
+ * @returns True if the value is a valid PartitionedDataInfoEntries, false otherwise
295
+ */
296
+ export function isPartitionedDataInfoEntries<Blob>(value: unknown): value is PartitionedDataInfoEntries<Blob> {
297
+ if (!isDataInfoEntries(value)) return false;
298
+ return value.type === 'JsonPartitioned' || value.type === 'BinaryPartitioned';
299
+ }
300
+
283
301
  /**
284
302
  * Converts DataInfo to DataInfoEntries
285
303
  *
@@ -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
@@ -40,7 +40,7 @@ export class AnchoredIdDeriver {
40
40
  * Creates a new anchor context from a set of anchor column specifications
41
41
  * @param anchors Record of anchor column specifications indexed by anchor ID
42
42
  */
43
- constructor(private readonly anchors: Record<string, PColumnSpec>) {
43
+ constructor(public readonly anchors: Record<string, PColumnSpec>) {
44
44
  const anchorEntries = Object.entries(anchors);
45
45
  anchorEntries.sort((a, b) => a[0].localeCompare(b[0]));
46
46
  for (const [anchorId, spec] of anchorEntries) {
@@ -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
  }
@@ -2,6 +2,7 @@ import type { Branded } from '../../../branding';
2
2
  import type { AnchoredPColumnId } from './selectors';
3
3
  import type { FilteredPColumnId } from './filtered_column';
4
4
  import canonicalize from 'canonicalize';
5
+ import type { PObjectId } from '../../../pool';
5
6
  /**
6
7
  * Universal column identifier optionally anchored and optionally filtered.
7
8
  */
@@ -10,7 +11,7 @@ export type UniversalPColumnId = AnchoredPColumnId | FilteredPColumnId;
10
11
  /**
11
12
  * Canonically serialized {@link UniversalPColumnId}.
12
13
  */
13
- export type SUniversalPColumnId = Branded<string, 'SUniversalPColumnId'>;
14
+ export type SUniversalPColumnId = Branded<PObjectId, 'SUniversalPColumnId', '__pl_model_brand_2__'>;
14
15
 
15
16
  /**
16
17
  * Canonically serializes a {@link UniversalPColumnId} to a string.