@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
@@ -0,0 +1,29 @@
1
+ import { n as Repository } from "./Repository-dbbgOGjK.mjs";
2
+ import { a as methodRegistryPlugin, d as cachePlugin, f as batchOperationsPlugin, h as auditLogPlugin, i as multiTenantPlugin, m as auditTrailPlugin, n as softDeletePlugin, o as customIdPlugin, t as timestampPlugin } from "./timestamp.plugin-nG9Z1JEk.mjs";
3
+ //#region src/create-repository.ts
4
+ function isLoggerAudit(value) {
5
+ const v = value;
6
+ return typeof v.info === "function" || typeof v.warn === "function" || typeof v.error === "function" || typeof v.debug === "function";
7
+ }
8
+ /**
9
+ * Build a `Repository` from a declarative config. See module JSDoc for
10
+ * ordering guarantees and an example.
11
+ */
12
+ function createRepository(model, config = {}) {
13
+ const { tenant, softDelete, timestamps, batch, cache, audit, customId, plugins = [], pagination = {}, ...repositoryOptions } = config;
14
+ const stack = [methodRegistryPlugin()];
15
+ if (tenant) stack.push(multiTenantPlugin(tenant));
16
+ if (softDelete) stack.push(softDeletePlugin(softDelete === true ? {} : softDelete));
17
+ if (timestamps) stack.push(timestampPlugin());
18
+ if (customId) stack.push(customIdPlugin(customId));
19
+ if (cache) stack.push(cachePlugin(cache));
20
+ if (audit) stack.push(isLoggerAudit(audit) ? auditLogPlugin(audit) : auditTrailPlugin(audit));
21
+ if (batch) stack.push(batchOperationsPlugin());
22
+ stack.push(...plugins);
23
+ return new Repository(model, stack, pagination, {
24
+ pluginOrderChecks: repositoryOptions.pluginOrderChecks ?? "throw",
25
+ ...repositoryOptions
26
+ });
27
+ }
28
+ //#endregion
29
+ export { createRepository as t };
@@ -25,9 +25,10 @@ function isObjectIdInstance(instance) {
25
25
  }
26
26
  const UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
27
27
  /**
28
- * Detect the _id path type from a Mongoose schema.
28
+ * Detect an id path's type from a Mongoose schema. Defaults to the `_id`
29
+ * path; pass `field` to resolve a custom id field (Repository's `idField`).
29
30
  *
30
- * Returns 'objectid' as the safe default when:
31
+ * For `_id`, returns 'objectid' as the safe default when:
31
32
  * - No schema is provided (mock models, test harnesses)
32
33
  * - The schema has no `paths._id` (auto-generated ObjectId)
33
34
  * - The instance string is unrecognized
@@ -35,10 +36,14 @@ const UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/
35
36
  * This safe-default means existing callers that don't set _id explicitly
36
37
  * get the same ObjectId validation they always had — the behavioral change
37
38
  * is strictly opt-in via schema declaration.
39
+ *
40
+ * For a custom `field` with no resolvable path, returns 'unknown' instead —
41
+ * custom id fields carry no ObjectId convention, so validation stays
42
+ * permissive and the DB remains the authority.
38
43
  */
39
- function getSchemaIdType(schema) {
40
- const instance = schema?.paths?._id?.instance;
41
- if (!instance) return "objectid";
44
+ function getSchemaIdType(schema, field = "_id") {
45
+ const instance = schema?.paths?.[field]?.instance;
46
+ if (!instance) return field === "_id" ? "objectid" : "unknown";
42
47
  if (isObjectIdInstance(instance)) return "objectid";
43
48
  switch (instance) {
44
49
  case "String": return "string";
@@ -1,7 +1,5 @@
1
- import { B as ObjectId, Dt as LookupOptions, H as OperationOptions, I as MinMaxResult, J as PopulateSpec, T as GroupResult, Z as ReadPreferenceType, ft as UpdateManyResult, ht as UpdateWithValidationResult, i as AnyDocument, it as SelectSpec, p as CreateOptions, pt as UpdateOptions, ut as SortSpec, v as DeleteResult, w as FindOneAndUpdateOptions } from "./types-CU3SEDbD.mjs";
1
+ import { B as ObjectId, Dt as LookupOptions, H as OperationOptions, I as MinMaxResult, J as PopulateSpec, T as GroupResult, Z as ReadPreferenceType, ft as UpdateManyResult, ht as UpdateWithValidationResult, i as AnyDocument, it as SelectSpec, p as CreateOptions, pt as UpdateOptions, ut as SortSpec, v as DeleteResult, w as FindOneAndUpdateOptions } from "./types-DNFMofHy.mjs";
2
2
  import { Model, PipelineStage } from "mongoose";
3
-
4
- //#region src/actions/aggregate.d.ts
5
3
  declare namespace aggregate_d_exports {
6
4
  export { aggregate, aggregatePaginate, average, countBy, distinct, facet, groupBy, lookup, minMax, sum, unwind };
7
5
  }