@classytic/mongokit 3.5.5 → 3.6.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 (26) hide show
  1. package/README.md +189 -1486
  2. package/dist/{PaginationEngine-CpsQl471.mjs → PaginationEngine-CunXkR9p.mjs} +100 -4
  3. package/dist/actions/index.d.mts +1 -1
  4. package/dist/ai/index.d.mts +1 -1
  5. package/dist/id-resolution-LZ-cCwR5.mjs +81 -0
  6. package/dist/{index-Buj7P006.d.mts → index-BSRSsRRx.d.mts} +1 -1
  7. package/dist/index.d.mts +81 -9
  8. package/dist/index.mjs +5 -5
  9. package/dist/{mongooseToJsonSchema-DpjhFfaO.mjs → mongooseToJsonSchema-8Cyu3NFJ.mjs} +50 -45
  10. package/dist/{mongooseToJsonSchema-BlDfbg_0.d.mts → mongooseToJsonSchema-D2YjHo7W.d.mts} +4 -3
  11. package/dist/pagination/PaginationEngine.d.mts +8 -1
  12. package/dist/pagination/PaginationEngine.mjs +1 -1
  13. package/dist/plugins/index.d.mts +1 -1
  14. package/dist/plugins/index.mjs +1 -1
  15. package/dist/query/primitives/coercion.d.mts +1 -1
  16. package/dist/query/primitives/coercion.mjs +4 -3
  17. package/dist/query/primitives/indexes.d.mts +1 -1
  18. package/dist/{types-CWUL0yiw.d.mts → types-DiQfDesD.d.mts} +29 -3
  19. package/dist/utils/index.d.mts +60 -3
  20. package/dist/utils/index.mjs +4 -3
  21. package/dist/{validation-chain.plugin-BCPh2UZG.mjs → validation-chain.plugin-3rr7dlw6.mjs} +308 -164
  22. package/dist/{validation-chain.plugin-Dn41aAbK.d.mts → validation-chain.plugin-COKNRAwp.d.mts} +15 -12
  23. package/package.json +2 -2
  24. /package/dist/{coercion-01tEHsKF.d.mts → coercion-B19MD38s.d.mts} +0 -0
  25. /package/dist/{field-selection-reyDRzXf.mjs → field-selection-C5o7jyyA.mjs} +0 -0
  26. /package/dist/{indexes-CiIT-Zli.d.mts → indexes-qIBCZ3mY.d.mts} +0 -0
@@ -1,2 +1,2 @@
1
- import { a as coerceHeuristic, i as coerceFieldValue, n as SchemaPathsLike, o as coerceToType, r as buildFieldTypeMap, s as normalizeMongooseType, t as FieldType } from "../../coercion-01tEHsKF.mjs";
1
+ import { a as coerceHeuristic, i as coerceFieldValue, n as SchemaPathsLike, o as coerceToType, r as buildFieldTypeMap, s as normalizeMongooseType, t as FieldType } from "../../coercion-B19MD38s.mjs";
2
2
  export { FieldType, SchemaPathsLike, buildFieldTypeMap, coerceFieldValue, coerceHeuristic, coerceToType, normalizeMongooseType };
@@ -1,3 +1,4 @@
1
+ import { n as isObjectIdInstance } from "../../id-resolution-LZ-cCwR5.mjs";
1
2
  import mongoose from "mongoose";
2
3
  //#region src/query/primitives/coercion.ts
3
4
  /**
@@ -39,10 +40,10 @@ function normalizeMongooseType(schemaType) {
39
40
  case "Number": return "number";
40
41
  case "Boolean": return "boolean";
41
42
  case "Date": return "date";
42
- case "ObjectID":
43
- case "ObjectId": return "objectid";
44
43
  case "Mixed": return "mixed";
45
- default: return null;
44
+ default:
45
+ if (isObjectIdInstance(raw)) return "objectid";
46
+ return null;
46
47
  }
47
48
  }
48
49
  /**
@@ -1,2 +1,2 @@
1
- import { n as SchemaIndexes, r as extractSchemaIndexes, t as IndexableSchema } from "../../indexes-CiIT-Zli.mjs";
1
+ import { n as SchemaIndexes, r as extractSchemaIndexes, t as IndexableSchema } from "../../indexes-qIBCZ3mY.mjs";
2
2
  export { IndexableSchema, SchemaIndexes, extractSchemaIndexes };
@@ -928,6 +928,17 @@ interface RepositoryContext {
928
928
  softDeleted?: boolean;
929
929
  /** Include soft-deleted documents in queries */
930
930
  includeDeleted?: boolean;
931
+ /**
932
+ * Caller-requested delete semantics, read by softDeletePlugin.
933
+ *
934
+ * - `undefined` (default) — plugin decides: soft if wired, hard otherwise.
935
+ * - `'hard'` — bypass soft-delete and physically remove the document.
936
+ * All policy hooks (multi-tenant scope, audit trails, cache invalidation)
937
+ * still fire; only the soft-delete interception is skipped.
938
+ * - `'soft'` — reserved. Currently treated as default since softDeletePlugin
939
+ * is the only source of soft semantics.
940
+ */
941
+ deleteMode?: 'hard' | 'soft';
931
942
  /** Skip cache for this operation */
932
943
  skipCache?: boolean;
933
944
  /** Custom TTL for this operation (seconds) */
@@ -982,7 +993,7 @@ interface RepositoryInstance {
982
993
  [key: string]: unknown;
983
994
  }
984
995
  /** Repository operation names */
985
- type RepositoryOperation = 'create' | 'createMany' | 'update' | 'updateMany' | 'delete' | 'deleteMany' | 'getById' | 'getByQuery' | 'getOne' | 'getAll' | 'findAll' | 'getOrCreate' | 'count' | 'exists' | 'distinct' | 'aggregate' | 'aggregatePaginate' | 'lookupPopulate' | 'bulkWrite';
996
+ type RepositoryOperation = 'create' | 'createMany' | 'update' | 'updateMany' | 'delete' | 'deleteMany' | 'restore' | 'getById' | 'getByQuery' | 'getOne' | 'getAll' | 'findAll' | 'getOrCreate' | 'count' | 'exists' | 'distinct' | 'aggregate' | 'aggregatePaginate' | 'lookupPopulate' | 'bulkWrite';
986
997
  /** Event lifecycle phases */
987
998
  type EventPhase = 'before' | 'after' | 'error';
988
999
  /** Repository event names (generated from template literals) */
@@ -1263,8 +1274,23 @@ interface CacheStats {
1263
1274
  }
1264
1275
  /** Cascade relation definition */
1265
1276
  interface CascadeRelation {
1266
- /** Model name to cascade delete to */
1267
- model: string;
1277
+ /**
1278
+ * Preferred: a Repository instance for the target collection. When present,
1279
+ * cascade routes deletes through `repo.delete` / `repo.deleteMany`, so the
1280
+ * target's `before:delete` / `before:deleteMany` hooks fire — meaning
1281
+ * multi-tenant scoping, audit logging, cache invalidation, and the target's
1282
+ * own soft-delete plugin (with its configured `deletedField`) all run
1283
+ * correctly. Strongly recommended for any target that has policy plugins.
1284
+ */
1285
+ repo?: RepositoryInstance;
1286
+ /**
1287
+ * Legacy: a Mongoose model name. When set without `repo`, cascade writes
1288
+ * directly via `RelatedModel.updateMany` / `RelatedModel.deleteMany`. This
1289
+ * path bypasses the target's hooks — it will NOT enforce tenant scoping,
1290
+ * fire audit events, or honor a custom `deletedField`. Only safe for
1291
+ * trivial targets with no policy plugins. Prefer `repo` for new code.
1292
+ */
1293
+ model?: string;
1268
1294
  /** Foreign key field in the related model that references the deleted document */
1269
1295
  foreignKey: string;
1270
1296
  /** Whether to use soft delete if available (default: follows parent behavior) */
@@ -1,5 +1,5 @@
1
- import { Z as PopulateSpec, pt as SortSpec, st as SelectSpec } from "../types-CWUL0yiw.mjs";
2
- import { a as isFieldUpdateAllowed, c as configureLogger, d as getFieldsForUser, f as getMongooseProjection, i as getSystemManagedFields, l as createFieldPreset, n as buildCrudSchemasFromMongooseSchema, o as validateUpdateBody, p as createError, r as getImmutableFields, s as createMemoryCache, t as buildCrudSchemasFromModel, u as filterResponseData } from "../mongooseToJsonSchema-BlDfbg_0.mjs";
1
+ import { Z as PopulateSpec, pt as SortSpec, st as SelectSpec } from "../types-DiQfDesD.mjs";
2
+ import { a as isFieldUpdateAllowed, c as configureLogger, d as getFieldsForUser, f as getMongooseProjection, i as getSystemManagedFields, l as createFieldPreset, n as buildCrudSchemasFromMongooseSchema, o as validateUpdateBody, p as createError, r as getImmutableFields, s as createMemoryCache, t as buildCrudSchemasFromModel, u as filterResponseData } from "../mongooseToJsonSchema-D2YjHo7W.mjs";
3
3
 
4
4
  //#region src/utils/cache-keys.d.ts
5
5
  /**
@@ -89,4 +89,61 @@ declare function modelPattern(prefix: string, model: string): string;
89
89
  */
90
90
  declare function listPattern(prefix: string, model: string): string;
91
91
  //#endregion
92
- export { buildCrudSchemasFromModel, buildCrudSchemasFromMongooseSchema, byIdKey, byQueryKey, configureLogger, createError, createFieldPreset, createMemoryCache, filterResponseData, getFieldsForUser, getImmutableFields, getMongooseProjection, getSystemManagedFields, isFieldUpdateAllowed, listPattern, listQueryKey, modelPattern, validateUpdateBody, versionKey };
92
+ //#region src/utils/id-resolution.d.ts
93
+ /**
94
+ * ID Resolution Primitive
95
+ *
96
+ * Pure functions for detecting a Mongoose schema's _id type and validating
97
+ * id values against it. Used by Repository.getById to decide whether to
98
+ * run ObjectId validation (for ObjectId schemas) or skip it (for String /
99
+ * Number / UUID schemas).
100
+ *
101
+ * Also usable standalone — Arc controllers, custom repositories, migration
102
+ * scripts, or test harnesses can import these directly to make the same
103
+ * decision without depending on Repository.
104
+ *
105
+ * Design: no `this`, no Model, no DB calls. Only reads `schema.paths._id.instance`.
106
+ */
107
+ /** Normalized _id type — covers the common Mongoose _id declarations */
108
+ type IdType = 'objectid' | 'string' | 'number' | 'uuid' | 'unknown';
109
+ /**
110
+ * Check if a Mongoose SchemaType `instance` string is an ObjectId variant.
111
+ * Mongoose 9.x uses `'ObjectId'`, older versions use `'ObjectID'`. This
112
+ * is the single source of truth — use it instead of inline
113
+ * `instance === 'ObjectId' || instance === 'ObjectID'` checks.
114
+ */
115
+ declare function isObjectIdInstance(instance: string | undefined): boolean;
116
+ /** Minimal structural type for schema introspection (decoupled from Mongoose version) */
117
+ interface SchemaLike {
118
+ paths?: Record<string, {
119
+ instance?: string;
120
+ }>;
121
+ }
122
+ /**
123
+ * Detect the _id path type from a Mongoose schema.
124
+ *
125
+ * Returns 'objectid' as the safe default when:
126
+ * - No schema is provided (mock models, test harnesses)
127
+ * - The schema has no `paths._id` (auto-generated ObjectId)
128
+ * - The instance string is unrecognized
129
+ *
130
+ * This safe-default means existing callers that don't set _id explicitly
131
+ * get the same ObjectId validation they always had — the behavioral change
132
+ * is strictly opt-in via schema declaration.
133
+ */
134
+ declare function getSchemaIdType(schema?: SchemaLike | null): IdType;
135
+ /**
136
+ * Validate an id value against a known _id type — WITHOUT hitting the DB.
137
+ *
138
+ * Returns `true` when the value is structurally valid for the given type.
139
+ * Returns `false` when it's definitely invalid (Repository should return
140
+ * 404 / null immediately rather than wasting a round-trip).
141
+ *
142
+ * For `'string'` and `'unknown'` types, validation is intentionally
143
+ * permissive: any truthy, non-empty value is accepted. The DB is the
144
+ * authority for whether the document exists — we only reject values that
145
+ * are structurally impossible (null, undefined, empty string).
146
+ */
147
+ declare function isValidIdForType(id: unknown, idType: IdType): boolean;
148
+ //#endregion
149
+ export { type IdType, buildCrudSchemasFromModel, buildCrudSchemasFromMongooseSchema, byIdKey, byQueryKey, configureLogger, createError, createFieldPreset, createMemoryCache, filterResponseData, getFieldsForUser, getImmutableFields, getMongooseProjection, getSchemaIdType, getSystemManagedFields, isFieldUpdateAllowed, isObjectIdInstance, isValidIdForType, listPattern, listQueryKey, modelPattern, validateUpdateBody, versionKey };
@@ -1,4 +1,5 @@
1
1
  import { r as configureLogger, t as createError } from "../error-Bpbi_NKo.mjs";
2
- import { a as byIdKey, c as listQueryKey, i as getMongooseProjection, l as modelPattern, n as filterResponseData, o as byQueryKey, r as getFieldsForUser, s as listPattern, t as createFieldPreset, u as versionKey } from "../field-selection-reyDRzXf.mjs";
3
- import { a as isFieldUpdateAllowed, i as getSystemManagedFields, n as buildCrudSchemasFromMongooseSchema, o as validateUpdateBody, r as getImmutableFields, s as createMemoryCache, t as buildCrudSchemasFromModel } from "../mongooseToJsonSchema-DpjhFfaO.mjs";
4
- export { buildCrudSchemasFromModel, buildCrudSchemasFromMongooseSchema, byIdKey, byQueryKey, configureLogger, createError, createFieldPreset, createMemoryCache, filterResponseData, getFieldsForUser, getImmutableFields, getMongooseProjection, getSystemManagedFields, isFieldUpdateAllowed, listPattern, listQueryKey, modelPattern, validateUpdateBody, versionKey };
2
+ import { n as isObjectIdInstance, r as isValidIdForType, t as getSchemaIdType } from "../id-resolution-LZ-cCwR5.mjs";
3
+ import { a as byIdKey, c as listQueryKey, i as getMongooseProjection, l as modelPattern, n as filterResponseData, o as byQueryKey, r as getFieldsForUser, s as listPattern, t as createFieldPreset, u as versionKey } from "../field-selection-C5o7jyyA.mjs";
4
+ import { a as isFieldUpdateAllowed, i as getSystemManagedFields, n as buildCrudSchemasFromMongooseSchema, o as validateUpdateBody, r as getImmutableFields, s as createMemoryCache, t as buildCrudSchemasFromModel } from "../mongooseToJsonSchema-8Cyu3NFJ.mjs";
5
+ export { buildCrudSchemasFromModel, buildCrudSchemasFromMongooseSchema, byIdKey, byQueryKey, configureLogger, createError, createFieldPreset, createMemoryCache, filterResponseData, getFieldsForUser, getImmutableFields, getMongooseProjection, getSchemaIdType, getSystemManagedFields, isFieldUpdateAllowed, isObjectIdInstance, isValidIdForType, listPattern, listQueryKey, modelPattern, validateUpdateBody, versionKey };