@lossless.org/client 1.13.0 → 1.15.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.
@@ -4,6 +4,7 @@ import { SmartdataDbCursor } from './classes.cursor.js';
4
4
  import { type ISmartdataBootstrapRecordOptions, type ISmartdataBootstrapRecordResult } from './classes.bootstraprecord.js';
5
5
  import { type ISmartdataCollectionPreparationOptions } from './classes.collectionpreparation.js';
6
6
  import { type ISmartdataStoredInspectionOptions, type ISmartdataStoredInspection, type ISmartdataStoredEvidenceInspection } from './classes.storedinspection.js';
7
+ import { type ISmartdataQueryPlan, type ISmartdataQueryPlanOptions } from './classes.queryplaninspection.js';
7
8
  import { type IManager, type ISmartdataIndexInfo, SmartdataCollection } from './classes.collection.js';
8
9
  import { SmartdataDbWatcher } from './classes.watcher.js';
9
10
  import { type TSmartdataOrdinarySession } from './classes.session.js';
@@ -61,6 +62,13 @@ export interface SvDbOptions {
61
62
  * below this persisted field.
62
63
  */
63
64
  atomicPaths?: readonly string[];
65
+ /**
66
+ * Explicit relative nested paths below this persisted field that hold
67
+ * arrays. Each one is a declared nested path exactly like an `atomicPaths`
68
+ * entry, and in addition the array operators `$push`, `$addToSet` and
69
+ * `$pull` and the grouped-totals `unwind` may target it.
70
+ */
71
+ arrayPaths?: readonly string[];
64
72
  /**
65
73
  * Declares this persisted top-level field as numeric for strict atomic
66
74
  * expression references.
@@ -260,16 +268,39 @@ export interface ISmartdataAtomicNumericExpression<T> {
260
268
  TSmartdataAtomicNumericExpressionOperand<T>
261
269
  ];
262
270
  }
263
- export interface ISmartdataGroupedTotalsOptions<T> {
271
+ /**
272
+ * A path grouped totals may group by or sum: a declared top-level field or a
273
+ * nested path declared through `@svDb({ atomicPaths })` or
274
+ * `@svDb({ arrayPaths })`.
275
+ */
276
+ export type TSmartdataGroupedTotalsPath<T> = TSmartdataAtomicDocumentPath<T>;
277
+ /**
278
+ * A path grouped totals may unwind: a declared top-level array field or a
279
+ * nested path declared through `@svDb({ arrayPaths })`.
280
+ */
281
+ export type TSmartdataGroupedTotalsUnwindPath<T> = TSmartdataAtomicArrayPath<T> | TSmartdataAtomicNestedDocumentPath<T>;
282
+ export interface ISmartdataGroupedTotalsOptions<T, TUnwind extends TSmartdataGroupedTotalsUnwindPath<T> = never> {
283
+ /**
284
+ * One or two distinct declared paths whose value combinations form the
285
+ * groups: declared top-level fields or nested paths declared through
286
+ * `@svDb({ atomicPaths })` or `@svDb({ arrayPaths })`.
287
+ */
288
+ groupBy: ReadonlyArray<TSmartdataGroupedTotalsPath<T>>;
264
289
  /**
265
- * One or two declared top-level fields whose distinct value combinations
266
- * form the groups.
290
+ * Groups by each element of one array instead of by the array: names
291
+ * exactly one `groupBy` path, which must be a declared top-level array
292
+ * field or a nested path declared through `@svDb({ arrayPaths })`. Every
293
+ * element forms its own row, so `count` counts elements and a document
294
+ * contributes its `sums` once per element; a document whose array is
295
+ * missing, null or empty contributes nothing. The `filter` still selects
296
+ * whole documents before the array is unwound.
267
297
  */
268
- groupBy: ReadonlyArray<TSmartdataDocumentPath<T>>;
298
+ unwind?: TUnwind;
269
299
  /**
270
- * Declared numeric top-level fields to sum per group.
300
+ * Declared numeric top-level fields, or declared nested paths holding
301
+ * numbers, to sum per group.
271
302
  */
272
- sums?: ReadonlyArray<TSmartdataNumericDocumentPath<T>>;
303
+ sums?: ReadonlyArray<TSmartdataNumericDocumentPath<T> | TSmartdataAtomicNestedDocumentPath<T>>;
273
304
  filter?: MongoFilter<T>;
274
305
  /**
275
306
  * Required bound on the number of returned groups (1..10000). The group
@@ -289,32 +320,41 @@ export interface ISmartdataGroupedTotalsOptions<T> {
289
320
  signal?: AbortSignal;
290
321
  session?: TSmartdataOrdinarySession;
291
322
  }
292
- export interface ISmartdataGroupedTotalsRow<T> {
323
+ export interface ISmartdataGroupedTotalsRow<T, TUnwind extends TSmartdataGroupedTotalsUnwindPath<T> = never> {
293
324
  /**
294
- * The group's key values. Documents missing a group field and documents
295
- * holding an explicit null merge into one group reported as null.
325
+ * The group's key values, keyed by the `groupBy` paths as given. Documents
326
+ * missing a group path and documents holding an explicit null merge into
327
+ * one group reported as null. An unwound top-level array reports the
328
+ * element; nested paths report the stored value untyped.
296
329
  */
297
330
  group: {
298
- [TKey in TSmartdataDocumentPath<T>]?: T[TKey] | null;
299
- };
331
+ [TKey in TSmartdataDocumentPath<T>]?: (TKey extends TUnwind ? TSmartdataAtomicArrayElement<T[TKey]> : T[TKey]) | null;
332
+ } & Partial<Record<TSmartdataAtomicNestedDocumentPath<T>, unknown>>;
300
333
  count: number;
301
- sums: Partial<Record<TSmartdataNumericDocumentPath<T>, number>>;
334
+ sums: Partial<Record<TSmartdataNumericDocumentPath<T> | TSmartdataAtomicNestedDocumentPath<T>, number>>;
302
335
  }
303
- export interface ISmartdataGroupedTotalsPage<T> {
304
- rows: Array<ISmartdataGroupedTotalsRow<T>>;
336
+ export interface ISmartdataGroupedTotalsPage<T, TUnwind extends TSmartdataGroupedTotalsUnwindPath<T> = never> {
337
+ rows: Array<ISmartdataGroupedTotalsRow<T, TUnwind>>;
305
338
  hasMore: boolean;
306
339
  }
307
340
  export type TSmartdataAtomicArrayPath<T> = {
308
341
  [TKey in TSmartdataDocumentPath<T>]: NonNullable<T[TKey]> extends ReadonlyArray<unknown> ? TKey : never;
309
342
  }[TSmartdataDocumentPath<T>];
310
343
  type TSmartdataAtomicArrayElement<TValue> = NonNullable<TValue> extends ReadonlyArray<infer TElement> ? TElement : never;
344
+ /**
345
+ * Array operators take a declared top-level array field, typed by its element,
346
+ * or a nested path below a declared field. A nested path is accepted at run
347
+ * time only when the model declares it through `@svDb({ arrayPaths })`.
348
+ */
311
349
  type TSmartdataAtomicArrayOperation<T> = Partial<{
312
350
  [TKey in TSmartdataAtomicArrayPath<T>]: TSmartdataAtomicArrayElement<T[TKey]>;
313
- }>;
314
- type TSmartdataAtomicPullScalar<TValue> = Extract<TValue, string | number | boolean | null | Date | plugins.mongodb.ObjectId | plugins.mongodb.Binary | plugins.mongodb.Decimal128 | plugins.mongodb.Long | plugins.mongodb.Int32 | plugins.mongodb.Double | plugins.mongodb.Timestamp>;
351
+ }> & Partial<Record<TSmartdataAtomicNestedDocumentPath<T>, unknown>>;
352
+ /** The scalar equality operands `$pull` accepts. */
353
+ type TSmartdataAtomicPullScalarValue = string | number | boolean | null | Date | plugins.mongodb.ObjectId | plugins.mongodb.Binary | plugins.mongodb.Decimal128 | plugins.mongodb.Long | plugins.mongodb.Int32 | plugins.mongodb.Double | plugins.mongodb.Timestamp;
354
+ type TSmartdataAtomicPullScalar<TValue> = Extract<TValue, TSmartdataAtomicPullScalarValue>;
315
355
  type TSmartdataAtomicArrayPullOperation<T> = Partial<{
316
356
  [TKey in TSmartdataAtomicArrayPath<T>]: TSmartdataAtomicPullScalar<TSmartdataAtomicArrayElement<T[TKey]>>;
317
- }>;
357
+ }> & Partial<Record<TSmartdataAtomicNestedDocumentPath<T>, TSmartdataAtomicPullScalarValue>>;
318
358
  export interface ISmartdataAtomicUpdate<T> {
319
359
  $set?: TSmartdataAtomicSet<T>;
320
360
  $unset?: Partial<Record<TSmartdataAtomicDocumentPath<T>, '' | true | 1>>;
@@ -333,19 +373,21 @@ export interface ISmartdataAtomicUpdate<T> {
333
373
  $min?: TSmartdataAtomicMonotonic<T>;
334
374
  $setOnInsert?: TSmartdataAtomicSet<T>;
335
375
  /**
336
- * Appends one element to a declared top-level array field. Modifier
337
- * documents ($each, $position, $slice, $sort) are rejected.
376
+ * Appends one element to a declared top-level array field or a nested
377
+ * path declared through `@svDb({ arrayPaths })`. Modifier documents
378
+ * ($each, $position, $slice, $sort) are rejected.
338
379
  */
339
380
  $push?: TSmartdataAtomicArrayOperation<T>;
340
381
  /**
341
- * Adds one element to a declared top-level array field unless an equal
342
- * element is already present. Modifier documents are rejected.
382
+ * Adds one element to a declared top-level array field or a declared
383
+ * nested array path unless an equal element is already present. Modifier
384
+ * documents are rejected.
343
385
  */
344
386
  $addToSet?: TSmartdataAtomicArrayOperation<T>;
345
387
  /**
346
388
  * Removes every element equal to a scalar operand from a declared
347
- * top-level array field. Operator documents, plain objects, arrays, and
348
- * regular expressions are rejected.
389
+ * top-level array field or a declared nested array path. Operator
390
+ * documents, plain objects, arrays, and regular expressions are rejected.
349
391
  */
350
392
  $pull?: TSmartdataAtomicArrayPullOperation<T>;
351
393
  }
@@ -534,6 +576,12 @@ export declare class SmartDataDbDoc<T extends TImplements, TImplements, TManager
534
576
  static inspectStoredDocuments(dbArg: SmartdataDb, optionsArg?: ISmartdataStoredInspectionOptions): Promise<ISmartdataStoredInspection>;
535
577
  /** Diagnose stored BSON with explicit ordinary validation evidence, without hydration. */
536
578
  static inspectStoredDocumentEvidence(dbArg: SmartdataDb, optionsArg?: ISmartdataStoredInspectionOptions): Promise<ISmartdataStoredEvidenceInspection>;
579
+ /**
580
+ * Explains one model query with `executionStats` on `dbArg` and returns the
581
+ * winning plan's stages and execution totals, so a consumer can prove which
582
+ * index serves the query. Read-only: nothing is created, bound or hydrated.
583
+ */
584
+ static inspectQueryPlan<T>(this: plugins.tsclass.typeFest.Class<T>, dbArg: SmartdataDb, optionsArg: ISmartdataQueryPlanOptions<T>): Promise<ISmartdataQueryPlan>;
537
585
  static createInstanceFromMongoDbNativeDoc<T>(this: plugins.tsclass.typeFest.Class<T>, mongoDbNativeDocArg: any): T;
538
586
  private static getDeclaredPersistedRoots;
539
587
  private static getDeclaredUniqueRoots;
@@ -558,7 +606,14 @@ export declare class SmartDataDbDoc<T extends TImplements, TImplements, TManager
558
606
  * guarantee at most one matching document for an equality filter.
559
607
  */
560
608
  private static getGloballyConstrainingKeySets;
609
+ /**
610
+ * Every nested path the model declares below a persisted field, through
611
+ * `@svDb({ atomicPaths })` or `@svDb({ arrayPaths })`.
612
+ */
561
613
  private static getDeclaredAtomicPaths;
614
+ /** The nested paths declared through `@svDb({ arrayPaths })` as holding arrays. */
615
+ private static getDeclaredArrayPaths;
616
+ private static readDeclaredNestedPaths;
562
617
  private static getSerializedPersistedRoots;
563
618
  private static getDeclaredQueryPaths;
564
619
  private static assertHydratedProjection;
@@ -696,19 +751,22 @@ export declare class SmartDataDbDoc<T extends TImplements, TImplements, TManager
696
751
  static atomicUpsertMany<T>(this: plugins.tsclass.typeFest.Class<T>, operationsArg: ReadonlyArray<ISmartdataAtomicUpsertManyOperation<T>>, opts?: ISmartdataAtomicUpsertManyOptions): Promise<ISmartdataAtomicUpsertManyResult>;
697
752
  /**
698
753
  * Computes bounded grouped counts and optional numeric sums server-side.
699
- * Groups by one or two declared top-level fields, always returns a `count`
700
- * per group, and sums only declared numeric fields. The `$limit` follows
701
- * the group stage without a sort, so when more groups exist than the limit
702
- * the returned subset is arbitrary. Use `getGroupedTotalsPage()` when the
703
- * caller must detect overflow. The aggregation cursor never leaves SmartData.
754
+ * Groups by one or two declared paths — top-level fields or nested paths
755
+ * declared through `@svDb({ atomicPaths })` or `@svDb({ arrayPaths })` —
756
+ * optionally by each element of one declared array (`unwind`), always
757
+ * returns a `count` per group, and sums only declared numeric paths. The
758
+ * `$limit` follows the group stage without a sort, so when more groups
759
+ * exist than the limit the returned subset is arbitrary. Use
760
+ * `getGroupedTotalsPage()` when the caller must detect overflow. The
761
+ * aggregation cursor never leaves SmartData.
704
762
  */
705
- static getGroupedTotals<T>(this: plugins.tsclass.typeFest.Class<T>, optionsArg: ISmartdataGroupedTotalsOptions<T>): Promise<Array<ISmartdataGroupedTotalsRow<T>>>;
763
+ static getGroupedTotals<T, TUnwind extends TSmartdataGroupedTotalsUnwindPath<T> = never>(this: plugins.tsclass.typeFest.Class<T>, optionsArg: ISmartdataGroupedTotalsOptions<T, TUnwind>): Promise<Array<ISmartdataGroupedTotalsRow<T, TUnwind>>>;
706
764
  /**
707
765
  * Computes the same bounded grouped totals as `getGroupedTotals()` and
708
766
  * reports whether at least one additional group exists beyond the requested
709
767
  * row limit.
710
768
  */
711
- static getGroupedTotalsPage<T>(this: plugins.tsclass.typeFest.Class<T>, optionsArg: ISmartdataGroupedTotalsOptions<T>): Promise<ISmartdataGroupedTotalsPage<T>>;
769
+ static getGroupedTotalsPage<T, TUnwind extends TSmartdataGroupedTotalsUnwindPath<T> = never>(this: plugins.tsclass.typeFest.Class<T>, optionsArg: ISmartdataGroupedTotalsOptions<T, TUnwind>): Promise<ISmartdataGroupedTotalsPage<T, TUnwind>>;
712
770
  /**
713
771
  * gets all instances as array
714
772
  * @param this