@classytic/mongokit 3.38.1 → 3.40.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.
Files changed (51) hide show
  1. package/dist/{PaginationEngine-CBS1XGzp.d.mts → PaginationEngine-D-P19Y9m.d.mts} +34 -9
  2. package/dist/PaginationEngine-Dvl8jcRY.mjs +1198 -0
  3. package/dist/{Repository-Ck5x43wF.mjs → Repository-BMgPSkqZ.mjs} +672 -655
  4. package/dist/{Repository-BdSkQ8vc.d.mts → Repository-CR8Y9g2E.d.mts} +106 -34
  5. package/dist/actions/index.d.mts +1 -1
  6. package/dist/actions/index.mjs +1 -1
  7. package/dist/adapter/index.d.mts +21 -0
  8. package/dist/adapter/index.mjs +1 -1
  9. package/dist/{adapter-Bfqz8yHE.mjs → adapter-BrVfPFSW.mjs} +45 -1
  10. package/dist/ai/index.d.mts +1 -1
  11. package/dist/better-auth/index.mjs +2 -2
  12. package/dist/{create-repository-B5EulQ31.mjs → create-repository-BzBUMvd1.mjs} +3 -3
  13. package/dist/{create-repository-BU4x9Kb0.d.mts → create-repository-CAle1MSU.d.mts} +5 -5
  14. package/dist/idempotency/index.d.mts +23 -0
  15. package/dist/idempotency/index.mjs +134 -0
  16. package/dist/{index-DKEql4cL.d.mts → index-CmjNyulu.d.mts} +67 -8
  17. package/dist/index.d.mts +125 -35
  18. package/dist/index.mjs +286 -676
  19. package/dist/indexes/verify-indexes.d.mts +14 -1
  20. package/dist/indexes/verify-indexes.mjs +54 -7
  21. package/dist/{method-registry.plugin-DblM7V6j.mjs → method-registry.plugin-C63pGn1d.mjs} +54 -4
  22. package/dist/{multi-tenant.plugin-BwSvTirB.d.mts → multi-tenant.plugin-CBgCo9im.d.mts} +77 -5
  23. package/dist/{operations-DZodvjC-.d.mts → operations-CrRIoc8Z.d.mts} +22 -7
  24. package/dist/outbox/index.d.mts +1 -1
  25. package/dist/outbox/index.mjs +7 -5
  26. package/dist/pagination/PaginationEngine.d.mts +1 -1
  27. package/dist/pagination/PaginationEngine.mjs +1 -1
  28. package/dist/pagination/utils/limits.d.mts +1 -1
  29. package/dist/pagination/utils/limits.mjs +22 -1
  30. package/dist/pagination-BpIv2bdS.d.mts +364 -0
  31. package/dist/{plugin-options-DXnlKM3B.d.mts → plugin-options-Zk46lD6F.d.mts} +16 -2
  32. package/dist/plugins/index.d.mts +8 -3
  33. package/dist/plugins/index.mjs +99 -26
  34. package/dist/{repository-H_ffGgpE.d.mts → repository-odl03582.d.mts} +50 -6
  35. package/dist/sync/index.d.mts +40 -0
  36. package/dist/sync/index.mjs +334 -0
  37. package/dist/tenant/index.d.mts +89 -0
  38. package/dist/tenant/index.mjs +96 -0
  39. package/dist/testkit/index.d.mts +2 -2
  40. package/dist/testkit/index.mjs +1 -1
  41. package/dist/{timestamp.plugin-CBQukQzV.mjs → timestamp.plugin-DF0gJB6p.mjs} +116 -9
  42. package/dist/{to-plain-Dyz_qvuo.d.mts → to-plain-k7SjNlSS.d.mts} +2 -2
  43. package/dist/transaction-B5L9glO0.mjs +533 -0
  44. package/dist/{update-jSXp3nu3.mjs → update-DG0fCwRJ.mjs} +293 -83
  45. package/dist/utils/index.d.mts +1 -1
  46. package/dist/{validation-chain.plugin-DhNyxNCw.mjs → validation-chain.plugin-BLY2gLEk.mjs} +192 -279
  47. package/dist/{validation-chain.plugin-yQRob3Av.d.mts → validation-chain.plugin-DYp9E7K2.d.mts} +26 -20
  48. package/package.json +17 -4
  49. package/dist/PaginationEngine-BX9o_-4R.mjs +0 -735
  50. package/dist/core-62oo3N1C.d.mts +0 -50
  51. package/dist/pagination-jSUdrACK.d.mts +0 -158
@@ -1,5 +1,4 @@
1
- import { t as AnyDocument } from "./core-62oo3N1C.mjs";
2
- import { c as PaginationConfig, o as KeysetPaginationOptions, s as OffsetPaginationOptions, t as AggregatePaginationOptions } from "./pagination-jSUdrACK.mjs";
1
+ import { c as MongokitPageExtras, f as CursorSecret, i as CountStrategy, l as OffsetPaginationOptions, p as AnyDocument, s as KeysetPaginationOptions, t as AggregatePaginationOptions, u as PaginationConfig } from "./pagination-BpIv2bdS.mjs";
3
2
  import { Model } from "mongoose";
4
3
  import { AggregatePaginationResult, KeysetPaginationResult, OffsetPaginationResult } from "@classytic/repo-core/pagination";
5
4
  //#region src/pagination/PaginationEngine.d.ts
@@ -15,6 +14,10 @@ interface ResolvedPaginationConfig {
15
14
  minCursorVersion: number;
16
15
  strictKeysetSortFields: string[] | undefined;
17
16
  useEstimatedCount: boolean;
17
+ defaultCountStrategy: CountStrategy;
18
+ defaultCountLimit: number;
19
+ cursorSecret: CursorSecret | undefined;
20
+ defaultMode: 'offset' | 'keyset' | undefined;
18
21
  }
19
22
  /**
20
23
  * Production-grade pagination engine for MongoDB
@@ -54,11 +57,21 @@ declare class PaginationEngine<TDoc = AnyDocument> {
54
57
  * });
55
58
  * console.log(result.data, result.total, result.hasNext);
56
59
  */
57
- paginate(options?: OffsetPaginationOptions): Promise<OffsetPaginationResult<TDoc>>;
60
+ paginate(options?: OffsetPaginationOptions): Promise<OffsetPaginationResult<TDoc, MongokitPageExtras>>;
58
61
  /**
59
- * Keyset (cursor-based) pagination for high-performance streaming
60
- * Best for large datasets, infinite scroll, real-time feeds
61
- * O(1) performance - consistent speed regardless of position
62
+ * Keyset (cursor-based) pagination for high-performance streaming.
63
+ * Best for large datasets, infinite scroll, real-time feeds.
64
+ *
65
+ * **Constant cost per page — but ONLY with an index that covers the whole
66
+ * sort, tiebreaker included.** Keyset removes `skip(n)`; it does not by
67
+ * itself remove a sort. `validateKeysetSort` appends `_id` to every sort, so
68
+ * an index stopping at the primary field leaves Mongo to order the ties
69
+ * itself: a blocking `SORT` over every row the filter matches, paid again on
70
+ * every page. Measured at 20,000 documents examined to return 20, against 20
71
+ * with the tiebreaker in the index.
72
+ *
73
+ * The dev-time warning below names the index to declare. Read it as a
74
+ * correctness requirement for the performance claim, not as advice.
62
75
  *
63
76
  * @param options - Pagination options (sort is required)
64
77
  * @returns Pagination result with next cursor
@@ -79,9 +92,21 @@ declare class PaginationEngine<TDoc = AnyDocument> {
79
92
  */
80
93
  stream(options: KeysetPaginationOptions): Promise<KeysetPaginationResult<TDoc>>;
81
94
  /**
82
- * Aggregate pipeline with pagination
83
- * Best for complex queries requiring aggregation stages
84
- * Uses $facet to combine results and count in single query
95
+ * Aggregate pipeline with pagination.
96
+ *
97
+ * Runs the page and the count as TWO pipelines, concurrently — not one
98
+ * `$facet`. `$facet` bundles every returned document and the count into a
99
+ * SINGLE output document, and no stage may exceed the 16MB BSON limit, so a
100
+ * page of large documents fails outright with `BSONObjectTooLarge` rather
101
+ * than paginating. `$facet` also cannot use an index for the stages inside
102
+ * it, so splitting is frequently the faster plan as well.
103
+ *
104
+ * The cost is that the two halves are separate reads and a concurrent write
105
+ * can land between them, so `total` may disagree with `data` by a document.
106
+ * That is already true of the offset path (`paginate` runs find and count
107
+ * through one `Promise.all`) — this makes aggregate consistent with it, and
108
+ * a count that is one row stale is a far smaller defect than a page that
109
+ * cannot be fetched at all. `countStrategy: 'none'` runs ONE pipeline.
85
110
  *
86
111
  * @param options - Aggregation options
87
112
  * @returns Pagination result with total count