@lossless.org/client 1.16.0 → 1.17.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.
@@ -297,9 +297,23 @@ export interface ISmartdataGroupedTotalsOptions<T, TUnwind extends TSmartdataGro
297
297
  * counts elements and a document contributes its `sums` once per element;
298
298
  * a document whose array is missing, null or empty contributes nothing.
299
299
  * The `filter` still selects whole documents before the array is unwound,
300
- * and no `groupBy` or `sums` path may contain the unwound array.
300
+ * and no `groupBy` or `sums` path may contain the unwound array; use
301
+ * `elementFilter` to select elements.
301
302
  */
302
303
  unwind?: TUnwind;
304
+ /**
305
+ * Selects the unwound elements that contribute, applied after the array is
306
+ * unwound and before grouping: only an element that matches is counted and
307
+ * summed. Requires `unwind`. Every path is the unwound array itself (its
308
+ * scalar element) or a declared nested path below it
309
+ * (`lines.accountNumber` below `unwind: 'lines'`), combined through
310
+ * `$and`, `$or` and `$nor`, with the operators of atomic filters: `$eq`,
311
+ * `$ne`, `$gt`, `$gte`, `$lt`, `$lte`, `$in`, `$nin`, `$exists`, `$type`,
312
+ * `$regex` with `$options`, and `$not`. Any other path or operator is
313
+ * refused with `invalid_argument`. The document `filter` can carry the same
314
+ * condition to preselect documents through an index.
315
+ */
316
+ elementFilter?: TSmartdataGroupedTotalsElementFilter<NoInfer<TUnwind>>;
303
317
  /**
304
318
  * Declared numeric top-level fields, or declared nested paths holding
305
319
  * numbers, to sum per group.
@@ -307,12 +321,21 @@ export interface ISmartdataGroupedTotalsOptions<T, TUnwind extends TSmartdataGro
307
321
  sums?: ReadonlyArray<TSmartdataNumericDocumentPath<T> | TSmartdataAtomicNestedDocumentPath<T>>;
308
322
  filter?: MongoFilter<T>;
309
323
  /**
310
- * Required bound on the number of returned groups (1..10000). The group
311
- * stage is not sorted, so when more groups exist than the limit the
312
- * returned subset is arbitrary. Use `getGroupedTotalsPage()` when the
313
- * caller must detect overflow at the 10000-group boundary.
324
+ * Required bound on the number of returned groups (1..10000). Groups are
325
+ * ordered by their key — the `groupBy` values in the given order — and the
326
+ * first `limit` groups in that order are returned. Use
327
+ * `getGroupedTotalsPage()` to detect more groups and read them through
328
+ * `nextCursor`, or `iterateGroupedTotals()` to read every group.
314
329
  */
315
330
  limit: number;
331
+ /**
332
+ * Continues after the last group of an earlier page: the `nextCursor` that
333
+ * `getGroupedTotalsPage()` returned for the same `groupBy`, `unwind`,
334
+ * `sums`, `filter` and `elementFilter`. The page holds the groups whose key
335
+ * sorts after that group's key. A cursor that does not decode, or that
336
+ * another query shape produced, is refused with `invalid_argument`.
337
+ */
338
+ cursor?: string;
316
339
  maxTimeMS?: number;
317
340
  /**
318
341
  * Client-side deadline for the aggregation cursor up to its last reply. More
@@ -340,7 +363,23 @@ export interface ISmartdataGroupedTotalsRow<T, TUnwind extends TSmartdataGrouped
340
363
  export interface ISmartdataGroupedTotalsPage<T, TUnwind extends TSmartdataGroupedTotalsUnwindPath<T> = never> {
341
364
  rows: Array<ISmartdataGroupedTotalsRow<T, TUnwind>>;
342
365
  hasMore: boolean;
366
+ /**
367
+ * Present exactly when `hasMore` is true: pass it back as `cursor`, with the
368
+ * same query, to read the next page. Opaque; it carries the query's shape
369
+ * and the last group's key.
370
+ */
371
+ nextCursor?: string;
343
372
  }
373
+ /**
374
+ * The `elementFilter` of grouped totals: conditions on the unwound array
375
+ * `TUnwind` itself or on paths below it, in the shape of atomic filter
376
+ * conditions, combined through `$and`, `$or` and `$nor`.
377
+ */
378
+ export type TSmartdataGroupedTotalsElementFilter<TUnwind extends string> = Partial<Record<TUnwind | `${TUnwind}.${string}`, TSmartdataAtomicFilterCondition<unknown>>> & {
379
+ $and?: Array<TSmartdataGroupedTotalsElementFilter<TUnwind>>;
380
+ $or?: Array<TSmartdataGroupedTotalsElementFilter<TUnwind>>;
381
+ $nor?: Array<TSmartdataGroupedTotalsElementFilter<TUnwind>>;
382
+ };
344
383
  export type TSmartdataAtomicArrayPath<T> = {
345
384
  [TKey in TSmartdataDocumentPath<T>]: NonNullable<T[TKey]> extends ReadonlyArray<unknown> ? TKey : never;
346
385
  }[TSmartdataDocumentPath<T>];
@@ -758,20 +797,46 @@ export declare class SmartDataDbDoc<T extends TImplements, TImplements, TManager
758
797
  * Groups by one or two declared paths — top-level fields or nested paths
759
798
  * declared through `@svDb({ atomicPaths })` or `@svDb({ arrayPaths })` —
760
799
  * optionally per element of one declared array (`unwind`), whose element
761
- * fields `groupBy` and `sums` may then name, always returns a `count` per
762
- * group, and sums only declared numeric paths. The
763
- * `$limit` follows the group stage without a sort, so when more groups
764
- * exist than the limit the returned subset is arbitrary. Use
765
- * `getGroupedTotalsPage()` when the caller must detect overflow. The
766
- * aggregation cursor never leaves SmartData.
800
+ * fields `groupBy` and `sums` may then name and `elementFilter` may select,
801
+ * always returns a `count` per group, and sums only declared numeric paths.
802
+ * Rows come ordered by group key, and the first `limit` groups in that
803
+ * order are returned. Use `getGroupedTotalsPage()` when the caller must
804
+ * detect or read further groups. The aggregation cursor never leaves
805
+ * SmartData.
767
806
  */
768
807
  static getGroupedTotals<T, TUnwind extends TSmartdataGroupedTotalsUnwindPath<T> = never>(this: plugins.tsclass.typeFest.Class<T>, optionsArg: ISmartdataGroupedTotalsOptions<T, TUnwind>): Promise<Array<ISmartdataGroupedTotalsRow<T, TUnwind>>>;
769
808
  /**
770
- * Computes the same bounded grouped totals as `getGroupedTotals()` and
771
- * reports whether at least one additional group exists beyond the requested
772
- * row limit.
809
+ * Computes the same grouped totals as `getGroupedTotals()`, reports whether
810
+ * at least one further group exists beyond the requested row limit and, when
811
+ * one does, returns `nextCursor` to read the next page through `cursor`.
812
+ * Pages follow the group key order, so reading them to the end reports
813
+ * every group exactly once while the data does not change. Under concurrent
814
+ * writes every page reads the data as it is at that page's read: the cursor
815
+ * only moves forward, so no group is reported twice, but a group created
816
+ * with a key before the cursor is not reported, and totals on different
817
+ * pages can reflect different moments. A caller that needs one consistent
818
+ * view reads every page inside one transaction session, as far as the
819
+ * engine's transaction isolation provides one. Paging orders group values that are null or missing,
820
+ * numbers, strings, ObjectIds, booleans and dates; a page that returns a
821
+ * cursor or continues one refuses any other group value — an array, a
822
+ * document, a Decimal128, NaN — with `unsupported_operation` instead of
823
+ * skipping it.
773
824
  */
774
825
  static getGroupedTotalsPage<T, TUnwind extends TSmartdataGroupedTotalsUnwindPath<T> = never>(this: plugins.tsclass.typeFest.Class<T>, optionsArg: ISmartdataGroupedTotalsOptions<T, TUnwind>): Promise<ISmartdataGroupedTotalsPage<T, TUnwind>>;
826
+ /**
827
+ * Reads every group of a grouped-totals query in group key order, one page
828
+ * of `limit` groups per database round trip through
829
+ * `getGroupedTotalsPage()`, with the same exactness, ordering and
830
+ * concurrency rules. `cursor` resumes after an earlier page; `signal`,
831
+ * `timeoutMS` and `maxTimeMS` apply to each page.
832
+ */
833
+ static iterateGroupedTotals<T, TUnwind extends TSmartdataGroupedTotalsUnwindPath<T> = never>(this: plugins.tsclass.typeFest.Class<T>, optionsArg: ISmartdataGroupedTotalsOptions<T, TUnwind>): AsyncGenerator<ISmartdataGroupedTotalsRow<T, TUnwind>, void, undefined>;
834
+ /**
835
+ * Validates grouped-totals options and reads one page. `mintCursorArg` is
836
+ * false for `getGroupedTotals()`, which returns rows only and so never
837
+ * needs the next page's cursor.
838
+ */
839
+ private static readGroupedTotalsPage;
775
840
  /**
776
841
  * gets all instances as array
777
842
  * @param this