@classytic/mongokit 3.18.0 → 3.20.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 (49) hide show
  1. package/README.md +66 -0
  2. package/dist/{PaginationEngine-BcvaXBQ-.mjs → PaginationEngine-BT1ywu9k.mjs} +327 -6
  3. package/dist/PaginationEngine-DYpOD2wY.d.mts +102 -0
  4. package/dist/{Repository-B01VW_fU.mjs → Repository-dbbgOGjK.mjs} +85 -11
  5. package/dist/actions/index.d.mts +1 -1
  6. package/dist/actions/index.mjs +2 -2
  7. package/dist/adapter/index.d.mts +10 -2
  8. package/dist/adapter/index.mjs +1 -1
  9. package/dist/{adapter-DYEMkLwK.mjs → adapter-CW1EL0fF.mjs} +10 -1
  10. package/dist/ai/index.d.mts +1 -2
  11. package/dist/ai/index.mjs +3 -2
  12. package/dist/better-auth/index.d.mts +0 -1
  13. package/dist/better-auth/index.mjs +2 -2
  14. package/dist/create-repository-0TkQhcv-.d.mts +1757 -0
  15. package/dist/create-repository-CJATiAKX.mjs +29 -0
  16. package/dist/{id-resolution-CnN0YA8t.mjs → id-resolution-P2OzcyRl.mjs} +10 -5
  17. package/dist/{index-fi91ycQc.d.mts → index-Cg3SWugF.d.mts} +1 -3
  18. package/dist/index.d.mts +11 -1666
  19. package/dist/index.mjs +51 -37
  20. package/dist/lock/index.d.mts +0 -1
  21. package/dist/{mongooseToJsonSchema-BdQJU39w.d.mts → mongooseToJsonSchema-D2CyAMIC.d.mts} +9 -5
  22. package/dist/{mongooseToJsonSchema-CBEQmeEa.mjs → mongooseToJsonSchema-khdzVo8x.mjs} +1 -1
  23. package/dist/multi-tenant.plugin-CTsWz0XK.d.mts +486 -0
  24. package/dist/pagination/PaginationEngine.d.mts +1 -102
  25. package/dist/pagination/PaginationEngine.mjs +1 -1
  26. package/dist/plugins/index.d.mts +3 -3
  27. package/dist/plugins/index.mjs +2 -1
  28. package/dist/query/primitives/coercion.d.mts +1 -1
  29. package/dist/query/primitives/coercion.mjs +1 -1
  30. package/dist/query/primitives/geo.d.mts +1 -1
  31. package/dist/query/primitives/indexes.d.mts +1 -1
  32. package/dist/testkit/index.d.mts +128 -0
  33. package/dist/testkit/index.mjs +139 -0
  34. package/dist/{validation-chain.plugin-DJtC0KJ-.mjs → timestamp.plugin-nG9Z1JEk.mjs} +5 -1056
  35. package/dist/{types-CU3SEDbD.d.mts → types-DNFMofHy.d.mts} +51 -22
  36. package/dist/{update-CvCMv5Cl.mjs → update-1Lq9OMD2.mjs} +5 -5
  37. package/dist/utils/index.d.mts +1 -1
  38. package/dist/utils/index.mjs +5 -5
  39. package/dist/validation-chain.plugin-Dn_wZYLA.mjs +1056 -0
  40. package/dist/{validation-chain.plugin-BpMfy18N.d.mts → validation-chain.plugin-buy3uvyk.d.mts} +2 -487
  41. package/package.json +16 -7
  42. package/dist/cursor-_SbWVAn-.mjs +0 -254
  43. package/dist/sort-Ca1BPfvE.mjs +0 -72
  44. /package/dist/{coercion-TRMmR49h.d.mts → coercion-BjdPX3YF.d.mts} +0 -0
  45. /package/dist/{error-BTeepSNL.mjs → error-BuByZwKU.mjs} +0 -0
  46. /package/dist/{field-selection-CQW3WBiK.mjs → field-selection-FSQFLpsU.mjs} +0 -0
  47. /package/dist/{indexes-CgOF7Wjd.d.mts → indexes-DIjMpYES.d.mts} +0 -0
  48. /package/dist/{logger-B8wf-Mtb.mjs → logger-K7dPmu2U.mjs} +0 -0
  49. /package/dist/{chunk-CfYAbeIz.mjs → rolldown-runtime-D7D4PA-g.mjs} +0 -0
@@ -1,16 +1,9 @@
1
- import * as _$_classytic_repo_core_repository0 from "@classytic/repo-core/repository";
2
1
  import { DeleteManyResult, DeleteResult, LookupPopulateResult, RepositoryBase, UpdateManyResult } from "@classytic/repo-core/repository";
3
- import * as _$mongoose from "mongoose";
4
2
  import { Document, Model, PipelineStage, PopulateOptions, Types } from "mongoose";
5
- import * as _$_classytic_repo_core_filter0 from "@classytic/repo-core/filter";
6
3
  import { Filter } from "@classytic/repo-core/filter";
7
- import * as _$_classytic_repo_core_cache0 from "@classytic/repo-core/cache";
8
- import * as _$_classytic_repo_core_schema0 from "@classytic/repo-core/schema";
9
4
  import { ValidationResult } from "@classytic/repo-core/schema";
10
- import * as _$_classytic_repo_core_events0 from "@classytic/repo-core/events";
11
5
  import { AnyPaginationResult, OffsetPaginationResult } from "@classytic/repo-core/pagination";
12
6
  import { HttpError } from "@classytic/repo-core/errors";
13
-
14
7
  //#region src/query/LookupBuilder.d.ts
15
8
  interface LookupOptions {
16
9
  /** Collection to join with */
@@ -172,6 +165,42 @@ declare class LookupBuilder {
172
165
  */
173
166
  private static _sanitizeDeep;
174
167
  }
168
+ /**
169
+ * Performance Guidelines for $lookup at Scale:
170
+ *
171
+ * 1. **Index Requirements** (Critical for millions of records):
172
+ * - localField should be indexed on source collection
173
+ * - foreignField should be indexed on target collection (unique index preferred)
174
+ *
175
+ * Example:
176
+ * ```typescript
177
+ * // Employee collection
178
+ * employeeSchema.index({ departmentSlug: 1 });
179
+ *
180
+ * // Department collection
181
+ * departmentSchema.index({ slug: 1 }, { unique: true });
182
+ * ```
183
+ *
184
+ * 2. **Query Performance**:
185
+ * - With proper indexes: O(log n) per lookup
186
+ * - Without indexes: O(n * m) - AVOID THIS!
187
+ * - Use explain() to verify index usage: IXSCAN (good) vs COLLSCAN (bad)
188
+ *
189
+ * 3. **Pipeline Optimization**:
190
+ * - Place $match stages as early as possible
191
+ * - Use $project to reduce field size before lookups
192
+ * - Limit joined results with pipeline: [{ $match: {...} }, { $limit: n }]
193
+ *
194
+ * 4. **Memory Considerations**:
195
+ * - Each lookup creates a new field in memory
196
+ * - Use $project after lookup to remove unnecessary fields
197
+ * - Consider allowDiskUse: true for very large datasets
198
+ *
199
+ * 5. **Alternative Approaches**:
200
+ * - For 1:1 relationships with high read frequency: Consider storing ObjectId + slug
201
+ * - For read-heavy workloads: Consider caching or materialized views
202
+ * - For real-time dashboards: Consider separate aggregation collections
203
+ */
175
204
  //#endregion
176
205
  //#region src/types/controller.types.d.ts
177
206
  /**
@@ -561,20 +590,20 @@ type RequiredBy<T, K extends keyof T> = Omit<T, K> & Required<Pick<T, K>>;
561
590
  * @example
562
591
  * type StringFields = KeysOfType<User, string>; // 'name' | 'email'
563
592
  */
564
- type KeysOfType<T, V> = { [K in keyof T]: T[K] extends V ? K : never }[keyof T];
593
+ type KeysOfType<T, V> = { [K in keyof T]: T[K] extends V ? K : never; }[keyof T];
565
594
  /**
566
595
  * Deep partial - makes all nested properties optional
567
596
  */
568
- type DeepPartial<T> = T extends object ? { [P in keyof T]?: DeepPartial<T[P]> } : T;
597
+ type DeepPartial<T> = T extends object ? { [P in keyof T]?: DeepPartial<T[P]>; } : T;
569
598
  /**
570
599
  * Strict object type - prevents excess properties
571
600
  * Use with `satisfies` for compile-time validation
572
601
  */
573
- type Strict<T> = T & { [K in Exclude<string, keyof T>]?: never };
602
+ type Strict<T> = T & { [K in Exclude<string, keyof T>]?: never; };
574
603
  /**
575
604
  * NonNullable fields extractor
576
605
  */
577
- type NonNullableFields<T> = { [K in keyof T]: NonNullable<T[K]> };
606
+ type NonNullableFields<T> = { [K in keyof T]: NonNullable<T[K]>; };
578
607
  /**
579
608
  * Create/Update input types from document
580
609
  */
@@ -869,20 +898,20 @@ interface RepositoryOptions {
869
898
  * structured `validationErrors`. Validator output replaces the
870
899
  * payload, so schema-declared coercions/defaults flow into the write.
871
900
  */
872
- schema?: _$_classytic_repo_core_schema0.StandardSchemaV1;
901
+ schema?: import('@classytic/repo-core/schema').StandardSchemaV1;
873
902
  /**
874
903
  * Standard Schema validator for `update` payloads. Separate slot
875
904
  * because updates are partial — derive one explicitly (e.g.
876
905
  * `schema.partial()` in Zod).
877
906
  */
878
- updateSchema?: _$_classytic_repo_core_schema0.StandardSchemaV1;
907
+ updateSchema?: import('@classytic/repo-core/schema').StandardSchemaV1;
879
908
  /**
880
909
  * Domain-event emission. Pass any arc / `@classytic/primitives`-
881
910
  * compatible transport and every mutating op publishes
882
911
  * `<resource>.<verb>` events (`user.created`, `user.updated`, ...).
883
912
  * Omit and the wiring is inert. See `@classytic/repo-core/events`.
884
913
  */
885
- events?: _$_classytic_repo_core_events0.RepositoryEventsOptions;
914
+ events?: import('@classytic/repo-core/events').RepositoryEventsOptions;
886
915
  }
887
916
  /** Pagination configuration */
888
917
  interface PaginationConfig {
@@ -1105,7 +1134,7 @@ interface OperationOptions extends ReadOptions {
1105
1134
  */
1106
1135
  interface CacheableOptions extends OperationOptions {
1107
1136
  /** Per-call cache override forwarded to the unified cache plugin. */
1108
- cache?: _$_classytic_repo_core_cache0.CacheOptions;
1137
+ cache?: import('@classytic/repo-core/cache').CacheOptions;
1109
1138
  }
1110
1139
  /** withTransaction options */
1111
1140
  interface WithTransactionOptions {
@@ -1114,7 +1143,7 @@ interface WithTransactionOptions {
1114
1143
  /** Optional hook to observe fallback triggers */
1115
1144
  onFallback?: (error: Error) => void;
1116
1145
  /** MongoDB transaction options (readConcern, writeConcern, readPreference, maxCommitTimeMS) */
1117
- transactionOptions?: _$mongoose.mongo.TransactionOptions;
1146
+ transactionOptions?: import('mongoose').mongo.TransactionOptions;
1118
1147
  }
1119
1148
  /** Create operation options */
1120
1149
  interface CreateOptions extends SessionOptions {
@@ -1200,13 +1229,13 @@ interface LookupPopulateOptions<TBase = unknown> {
1200
1229
  * controllers produce when typed against `StandardRepo<TDoc>`), or
1201
1230
  * a plain `Record<string, unknown>` for ad-hoc callers.
1202
1231
  */
1203
- filters?: _$_classytic_repo_core_filter0.Filter | (Partial<TBase> & Record<string, unknown>) | Record<string, unknown>;
1232
+ filters?: import('@classytic/repo-core/filter').Filter | (Partial<TBase> & Record<string, unknown>) | Record<string, unknown>;
1204
1233
  /**
1205
1234
  * Portable `LookupSpec[]` (cross-kit) or mongokit-native
1206
1235
  * `LookupOptions[]` (with `pipeline` / `let` / `sanitize`). The
1207
1236
  * portable shape is a structural subset, so callers can mix.
1208
1237
  */
1209
- lookups: readonly _$_classytic_repo_core_repository0.LookupSpec[] | LookupOptions[];
1238
+ lookups: readonly import('@classytic/repo-core/repository').LookupSpec[] | LookupOptions[];
1210
1239
  /** Sort specification */
1211
1240
  sort?: SortSpec | string;
1212
1241
  /** Page number (offset mode, 1-indexed) */
@@ -1338,7 +1367,7 @@ interface RepositoryContext {
1338
1367
  * `options.cache` onto the context so the plugin's `before:<op>`
1339
1368
  * hook can read it.
1340
1369
  */
1341
- cache?: _$_classytic_repo_core_cache0.CacheOptions;
1370
+ cache?: import('@classytic/repo-core/cache').CacheOptions;
1342
1371
  /** Whether result was served from cache (internal — set by cache plugin) */
1343
1372
  _cacheHit?: boolean;
1344
1373
  /** Cached result (internal — set by cache plugin) */
@@ -1440,7 +1469,7 @@ type EventHandlers<TDoc = unknown> = { [K in RepositoryEvent]?: K extends `befor
1440
1469
  error: Error;
1441
1470
  }) => void | Promise<void> : (payload: {
1442
1471
  context: RepositoryContext;
1443
- }) => void | Promise<void> };
1472
+ }) => void | Promise<void>; };
1444
1473
  /** Event payload */
1445
1474
  interface EventPayload {
1446
1475
  context: RepositoryContext;
@@ -1584,7 +1613,7 @@ interface MinMaxResult {
1584
1613
  */
1585
1614
  interface CacheOperationOptions {
1586
1615
  /** Per-call cache override forwarded to the unified cache plugin. */
1587
- cache?: _$_classytic_repo_core_cache0.CacheOptions;
1616
+ cache?: import('@classytic/repo-core/cache').CacheOptions;
1588
1617
  }
1589
1618
  /** Cascade relation definition */
1590
1619
  interface CascadeRelation {
@@ -1721,7 +1750,7 @@ type AllPluginMethods<TDoc> = {
1721
1750
  * `CacheEngine` plus convenience invalidation helpers. `undefined` when
1722
1751
  * no cache plugin is wired.
1723
1752
  */
1724
- cache?: _$_classytic_repo_core_cache0.RepositoryCacheHandle;
1753
+ cache?: import('@classytic/repo-core/cache').RepositoryCacheHandle;
1725
1754
  };
1726
1755
  /**
1727
1756
  * Helper type to add all plugin methods to a repository class
@@ -1,6 +1,6 @@
1
- import { t as __exportAll } from "./chunk-CfYAbeIz.mjs";
2
- import { n as warn } from "./logger-B8wf-Mtb.mjs";
3
- import { t as createError } from "./error-BTeepSNL.mjs";
1
+ import { t as __exportAll } from "./rolldown-runtime-D7D4PA-g.mjs";
2
+ import { n as warn } from "./logger-K7dPmu2U.mjs";
3
+ import { t as createError } from "./error-BuByZwKU.mjs";
4
4
  import { isFilter } from "@classytic/repo-core/filter";
5
5
  //#region src/filter/compile.ts
6
6
  /**
@@ -21,7 +21,7 @@ import { isFilter } from "@classytic/repo-core/filter";
21
21
  * handles them"). This set covers every operator the arc aggregation
22
22
  * guard accepts in `parseDateRange` and `hasFilterOnField`.
23
23
  */
24
- const SHORTHAND_OPS = new Set([
24
+ const SHORTHAND_OPS = /* @__PURE__ */ new Set([
25
25
  "eq",
26
26
  "ne",
27
27
  "gt",
@@ -35,7 +35,7 @@ const SHORTHAND_OPS = new Set([
35
35
  "mod"
36
36
  ]);
37
37
  /** Range operators whose string values should be coerced to Date. */
38
- const RANGE_OPS = new Set([
38
+ const RANGE_OPS = /* @__PURE__ */ new Set([
39
39
  "gt",
40
40
  "gte",
41
41
  "lt",
@@ -1,2 +1,2 @@
1
- import { a as IdType, c as isObjectIdInstance, d as filterResponseData, f as getFieldsForUser, i as configureLogger, l as isValidIdForType, m as createError, n as buildCrudSchemasFromMongooseSchema, o as getSchemaIdType, p as getMongooseProjection, r as createMemoryCache, t as buildCrudSchemasFromModel, u as createFieldPreset } from "../mongooseToJsonSchema-BdQJU39w.mjs";
1
+ import { a as IdType, c as isObjectIdInstance, d as filterResponseData, f as getFieldsForUser, i as configureLogger, l as isValidIdForType, m as createError, n as buildCrudSchemasFromMongooseSchema, o as getSchemaIdType, p as getMongooseProjection, r as createMemoryCache, t as buildCrudSchemasFromModel, u as createFieldPreset } from "../mongooseToJsonSchema-D2CyAMIC.mjs";
2
2
  export { type IdType, buildCrudSchemasFromModel, buildCrudSchemasFromMongooseSchema, configureLogger, createError, createFieldPreset, createMemoryCache, filterResponseData, getFieldsForUser, getMongooseProjection, getSchemaIdType, isObjectIdInstance, isValidIdForType };
@@ -1,6 +1,6 @@
1
- import { i as isValidIdForType, r as isObjectIdInstance, t as getSchemaIdType } from "../id-resolution-CnN0YA8t.mjs";
2
- import { t as configureLogger } from "../logger-B8wf-Mtb.mjs";
3
- import { t as createError } from "../error-BTeepSNL.mjs";
4
- import { i as getMongooseProjection, n as filterResponseData, r as getFieldsForUser, t as createFieldPreset } from "../field-selection-CQW3WBiK.mjs";
5
- import { n as buildCrudSchemasFromMongooseSchema, r as createMemoryCache, t as buildCrudSchemasFromModel } from "../mongooseToJsonSchema-CBEQmeEa.mjs";
1
+ import { i as isValidIdForType, r as isObjectIdInstance, t as getSchemaIdType } from "../id-resolution-P2OzcyRl.mjs";
2
+ import { t as configureLogger } from "../logger-K7dPmu2U.mjs";
3
+ import { t as createError } from "../error-BuByZwKU.mjs";
4
+ import { i as getMongooseProjection, n as filterResponseData, r as getFieldsForUser, t as createFieldPreset } from "../field-selection-FSQFLpsU.mjs";
5
+ import { n as buildCrudSchemasFromMongooseSchema, r as createMemoryCache, t as buildCrudSchemasFromModel } from "../mongooseToJsonSchema-khdzVo8x.mjs";
6
6
  export { buildCrudSchemasFromModel, buildCrudSchemasFromMongooseSchema, configureLogger, createError, createFieldPreset, createMemoryCache, filterResponseData, getFieldsForUser, getMongooseProjection, getSchemaIdType, isObjectIdInstance, isValidIdForType };