@classytic/mongokit 2.0.0 → 3.0.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 (105) hide show
  1. package/README.md +221 -7
  2. package/dist/actions/index.d.ts +3 -0
  3. package/dist/actions/index.js +473 -0
  4. package/dist/actions/index.js.map +1 -0
  5. package/dist/index-CgOJ2pqz.d.ts +337 -0
  6. package/dist/index.d.ts +239 -0
  7. package/dist/index.js +2108 -0
  8. package/dist/index.js.map +1 -0
  9. package/dist/memory-cache-DG2oSSbx.d.ts +142 -0
  10. package/dist/pagination/PaginationEngine.d.ts +117 -0
  11. package/dist/pagination/PaginationEngine.js +369 -0
  12. package/dist/pagination/PaginationEngine.js.map +1 -0
  13. package/dist/plugins/index.d.ts +275 -0
  14. package/dist/plugins/index.js +857 -0
  15. package/dist/plugins/index.js.map +1 -0
  16. package/dist/types-Nxhmi1aI.d.ts +510 -0
  17. package/dist/utils/index.d.ts +189 -0
  18. package/dist/utils/index.js +643 -0
  19. package/dist/utils/index.js.map +1 -0
  20. package/package.json +38 -21
  21. package/src/Repository.js +0 -296
  22. package/src/actions/aggregate.js +0 -266
  23. package/src/actions/create.js +0 -59
  24. package/src/actions/delete.js +0 -88
  25. package/src/actions/index.js +0 -11
  26. package/src/actions/read.js +0 -188
  27. package/src/actions/update.js +0 -176
  28. package/src/hooks/lifecycle.js +0 -146
  29. package/src/index.js +0 -71
  30. package/src/pagination/PaginationEngine.js +0 -348
  31. package/src/pagination/utils/cursor.js +0 -119
  32. package/src/pagination/utils/filter.js +0 -42
  33. package/src/pagination/utils/limits.js +0 -82
  34. package/src/pagination/utils/sort.js +0 -101
  35. package/src/plugins/aggregate-helpers.plugin.js +0 -71
  36. package/src/plugins/audit-log.plugin.js +0 -60
  37. package/src/plugins/batch-operations.plugin.js +0 -66
  38. package/src/plugins/field-filter.plugin.js +0 -27
  39. package/src/plugins/index.js +0 -19
  40. package/src/plugins/method-registry.plugin.js +0 -140
  41. package/src/plugins/mongo-operations.plugin.js +0 -317
  42. package/src/plugins/soft-delete.plugin.js +0 -46
  43. package/src/plugins/subdocument.plugin.js +0 -66
  44. package/src/plugins/timestamp.plugin.js +0 -19
  45. package/src/plugins/validation-chain.plugin.js +0 -145
  46. package/src/types.d.ts +0 -87
  47. package/src/utils/error.js +0 -12
  48. package/src/utils/field-selection.js +0 -156
  49. package/src/utils/index.js +0 -12
  50. package/types/Repository.d.ts +0 -95
  51. package/types/Repository.d.ts.map +0 -1
  52. package/types/actions/aggregate.d.ts +0 -112
  53. package/types/actions/aggregate.d.ts.map +0 -1
  54. package/types/actions/create.d.ts +0 -21
  55. package/types/actions/create.d.ts.map +0 -1
  56. package/types/actions/delete.d.ts +0 -37
  57. package/types/actions/delete.d.ts.map +0 -1
  58. package/types/actions/index.d.ts +0 -6
  59. package/types/actions/index.d.ts.map +0 -1
  60. package/types/actions/read.d.ts +0 -135
  61. package/types/actions/read.d.ts.map +0 -1
  62. package/types/actions/update.d.ts +0 -58
  63. package/types/actions/update.d.ts.map +0 -1
  64. package/types/hooks/lifecycle.d.ts +0 -44
  65. package/types/hooks/lifecycle.d.ts.map +0 -1
  66. package/types/index.d.ts +0 -25
  67. package/types/index.d.ts.map +0 -1
  68. package/types/pagination/PaginationEngine.d.ts +0 -386
  69. package/types/pagination/PaginationEngine.d.ts.map +0 -1
  70. package/types/pagination/utils/cursor.d.ts +0 -40
  71. package/types/pagination/utils/cursor.d.ts.map +0 -1
  72. package/types/pagination/utils/filter.d.ts +0 -28
  73. package/types/pagination/utils/filter.d.ts.map +0 -1
  74. package/types/pagination/utils/limits.d.ts +0 -64
  75. package/types/pagination/utils/limits.d.ts.map +0 -1
  76. package/types/pagination/utils/sort.d.ts +0 -41
  77. package/types/pagination/utils/sort.d.ts.map +0 -1
  78. package/types/plugins/aggregate-helpers.plugin.d.ts +0 -6
  79. package/types/plugins/aggregate-helpers.plugin.d.ts.map +0 -1
  80. package/types/plugins/audit-log.plugin.d.ts +0 -6
  81. package/types/plugins/audit-log.plugin.d.ts.map +0 -1
  82. package/types/plugins/batch-operations.plugin.d.ts +0 -6
  83. package/types/plugins/batch-operations.plugin.d.ts.map +0 -1
  84. package/types/plugins/field-filter.plugin.d.ts +0 -6
  85. package/types/plugins/field-filter.plugin.d.ts.map +0 -1
  86. package/types/plugins/index.d.ts +0 -11
  87. package/types/plugins/index.d.ts.map +0 -1
  88. package/types/plugins/method-registry.plugin.d.ts +0 -3
  89. package/types/plugins/method-registry.plugin.d.ts.map +0 -1
  90. package/types/plugins/mongo-operations.plugin.d.ts +0 -4
  91. package/types/plugins/mongo-operations.plugin.d.ts.map +0 -1
  92. package/types/plugins/soft-delete.plugin.d.ts +0 -6
  93. package/types/plugins/soft-delete.plugin.d.ts.map +0 -1
  94. package/types/plugins/subdocument.plugin.d.ts +0 -6
  95. package/types/plugins/subdocument.plugin.d.ts.map +0 -1
  96. package/types/plugins/timestamp.plugin.d.ts +0 -6
  97. package/types/plugins/timestamp.plugin.d.ts.map +0 -1
  98. package/types/plugins/validation-chain.plugin.d.ts +0 -31
  99. package/types/plugins/validation-chain.plugin.d.ts.map +0 -1
  100. package/types/utils/error.d.ts +0 -11
  101. package/types/utils/error.d.ts.map +0 -1
  102. package/types/utils/field-selection.d.ts +0 -9
  103. package/types/utils/field-selection.d.ts.map +0 -1
  104. package/types/utils/index.d.ts +0 -2
  105. package/types/utils/index.d.ts.map +0 -1
@@ -0,0 +1,337 @@
1
+ import { Model, ClientSession, PipelineStage } from 'mongoose';
2
+ import { A as AnyDocument, C as CreateOptions, l as OperationOptions, S as SelectSpec, f as PopulateSpec, g as SortSpec, U as UpdateOptions, n as UpdateWithValidationResult, m as UpdateManyResult, D as DeleteResult, I as GroupResult, G as LookupOptions, M as MinMaxResult } from './types-Nxhmi1aI.js';
3
+
4
+ /**
5
+ * Create Actions
6
+ * Pure functions for document creation
7
+ */
8
+
9
+ /**
10
+ * Create single document
11
+ */
12
+ declare function create<TDoc = AnyDocument>(Model: Model<TDoc>, data: Record<string, unknown>, options?: CreateOptions): Promise<TDoc>;
13
+ /**
14
+ * Create multiple documents
15
+ */
16
+ declare function createMany<TDoc = AnyDocument>(Model: Model<TDoc>, dataArray: Record<string, unknown>[], options?: CreateOptions): Promise<TDoc[]>;
17
+ /**
18
+ * Create with defaults (useful for initialization)
19
+ */
20
+ declare function createDefault<TDoc = AnyDocument>(Model: Model<TDoc>, overrides?: Record<string, unknown>, options?: CreateOptions): Promise<TDoc>;
21
+ /**
22
+ * Upsert (create or update)
23
+ */
24
+ declare function upsert<TDoc = AnyDocument>(Model: Model<TDoc>, query: Record<string, unknown>, data: Record<string, unknown>, options?: {
25
+ session?: ClientSession;
26
+ updatePipeline?: boolean;
27
+ }): Promise<TDoc | null>;
28
+
29
+ declare const create$1_create: typeof create;
30
+ declare const create$1_createDefault: typeof createDefault;
31
+ declare const create$1_createMany: typeof createMany;
32
+ declare const create$1_upsert: typeof upsert;
33
+ declare namespace create$1 {
34
+ export { create$1_create as create, create$1_createDefault as createDefault, create$1_createMany as createMany, create$1_upsert as upsert };
35
+ }
36
+
37
+ /**
38
+ * Read Actions
39
+ * Pure functions for document retrieval
40
+ */
41
+
42
+ /**
43
+ * Get document by ID
44
+ *
45
+ * @param Model - Mongoose model
46
+ * @param id - Document ID
47
+ * @param options - Query options
48
+ * @returns Document or null
49
+ * @throws Error if document not found and throwOnNotFound is true
50
+ */
51
+ declare function getById<TDoc = AnyDocument>(Model: Model<TDoc>, id: string, options?: OperationOptions): Promise<TDoc | null>;
52
+ /**
53
+ * Get document by query
54
+ *
55
+ * @param Model - Mongoose model
56
+ * @param query - MongoDB query
57
+ * @param options - Query options
58
+ * @returns Document or null
59
+ * @throws Error if document not found and throwOnNotFound is true
60
+ */
61
+ declare function getByQuery<TDoc = AnyDocument>(Model: Model<TDoc>, query: Record<string, unknown>, options?: OperationOptions): Promise<TDoc | null>;
62
+ /**
63
+ * Get document by query without throwing (returns null if not found)
64
+ */
65
+ declare function tryGetByQuery<TDoc = AnyDocument>(Model: Model<TDoc>, query: Record<string, unknown>, options?: Omit<OperationOptions, 'throwOnNotFound'>): Promise<TDoc | null>;
66
+ /**
67
+ * Get all documents (basic query without pagination)
68
+ * For pagination, use Repository.paginate() or Repository.stream()
69
+ */
70
+ declare function getAll<TDoc = AnyDocument>(Model: Model<TDoc>, query?: Record<string, unknown>, options?: {
71
+ select?: SelectSpec;
72
+ populate?: PopulateSpec;
73
+ sort?: SortSpec;
74
+ limit?: number;
75
+ skip?: number;
76
+ lean?: boolean;
77
+ session?: ClientSession;
78
+ }): Promise<TDoc[]>;
79
+ /**
80
+ * Get or create document (upsert)
81
+ */
82
+ declare function getOrCreate<TDoc = AnyDocument>(Model: Model<TDoc>, query: Record<string, unknown>, createData: Record<string, unknown>, options?: {
83
+ session?: ClientSession;
84
+ updatePipeline?: boolean;
85
+ }): Promise<TDoc | null>;
86
+ /**
87
+ * Count documents matching query
88
+ */
89
+ declare function count(Model: Model<any>, query?: Record<string, unknown>, options?: {
90
+ session?: ClientSession;
91
+ }): Promise<number>;
92
+ /**
93
+ * Check if document exists
94
+ */
95
+ declare function exists(Model: Model<any>, query: Record<string, unknown>, options?: {
96
+ session?: ClientSession;
97
+ }): Promise<{
98
+ _id: unknown;
99
+ } | null>;
100
+
101
+ declare const read_count: typeof count;
102
+ declare const read_exists: typeof exists;
103
+ declare const read_getAll: typeof getAll;
104
+ declare const read_getById: typeof getById;
105
+ declare const read_getByQuery: typeof getByQuery;
106
+ declare const read_getOrCreate: typeof getOrCreate;
107
+ declare const read_tryGetByQuery: typeof tryGetByQuery;
108
+ declare namespace read {
109
+ export { read_count as count, read_exists as exists, read_getAll as getAll, read_getById as getById, read_getByQuery as getByQuery, read_getOrCreate as getOrCreate, read_tryGetByQuery as tryGetByQuery };
110
+ }
111
+
112
+ /**
113
+ * Update Actions
114
+ * Pure functions for document updates with optimizations
115
+ */
116
+
117
+ /**
118
+ * Update by ID
119
+ */
120
+ declare function update<TDoc = AnyDocument>(Model: Model<TDoc>, id: string, data: Record<string, unknown>, options?: UpdateOptions): Promise<TDoc>;
121
+ /**
122
+ * Update with query constraints (optimized)
123
+ * Returns null if constraints not met (not an error)
124
+ */
125
+ declare function updateWithConstraints<TDoc = AnyDocument>(Model: Model<TDoc>, id: string, data: Record<string, unknown>, constraints?: Record<string, unknown>, options?: UpdateOptions): Promise<TDoc | null>;
126
+ /**
127
+ * Validation options for smart update
128
+ */
129
+ interface ValidationOptions {
130
+ buildConstraints?: (data: Record<string, unknown>) => Record<string, unknown>;
131
+ validateUpdate?: (existing: Record<string, unknown>, data: Record<string, unknown>) => {
132
+ valid: boolean;
133
+ message?: string;
134
+ violations?: Array<{
135
+ field: string;
136
+ reason: string;
137
+ }>;
138
+ };
139
+ }
140
+ /**
141
+ * Update with validation (smart optimization)
142
+ * 1-query on success, 2-queries for detailed errors
143
+ */
144
+ declare function updateWithValidation<TDoc = AnyDocument>(Model: Model<TDoc>, id: string, data: Record<string, unknown>, validationOptions?: ValidationOptions, options?: UpdateOptions): Promise<UpdateWithValidationResult<TDoc>>;
145
+ /**
146
+ * Update many documents
147
+ */
148
+ declare function updateMany(Model: Model<unknown>, query: Record<string, unknown>, data: Record<string, unknown>, options?: {
149
+ session?: ClientSession;
150
+ updatePipeline?: boolean;
151
+ }): Promise<UpdateManyResult>;
152
+ /**
153
+ * Update by query
154
+ */
155
+ declare function updateByQuery<TDoc = AnyDocument>(Model: Model<TDoc>, query: Record<string, unknown>, data: Record<string, unknown>, options?: UpdateOptions): Promise<TDoc | null>;
156
+ /**
157
+ * Increment field
158
+ */
159
+ declare function increment<TDoc = AnyDocument>(Model: Model<TDoc>, id: string, field: string, value?: number, options?: UpdateOptions): Promise<TDoc>;
160
+ /**
161
+ * Push to array
162
+ */
163
+ declare function pushToArray<TDoc = AnyDocument>(Model: Model<TDoc>, id: string, field: string, value: unknown, options?: UpdateOptions): Promise<TDoc>;
164
+ /**
165
+ * Pull from array
166
+ */
167
+ declare function pullFromArray<TDoc = AnyDocument>(Model: Model<TDoc>, id: string, field: string, value: unknown, options?: UpdateOptions): Promise<TDoc>;
168
+
169
+ declare const update$1_increment: typeof increment;
170
+ declare const update$1_pullFromArray: typeof pullFromArray;
171
+ declare const update$1_pushToArray: typeof pushToArray;
172
+ declare const update$1_update: typeof update;
173
+ declare const update$1_updateByQuery: typeof updateByQuery;
174
+ declare const update$1_updateMany: typeof updateMany;
175
+ declare const update$1_updateWithConstraints: typeof updateWithConstraints;
176
+ declare const update$1_updateWithValidation: typeof updateWithValidation;
177
+ declare namespace update$1 {
178
+ export { update$1_increment as increment, update$1_pullFromArray as pullFromArray, update$1_pushToArray as pushToArray, update$1_update as update, update$1_updateByQuery as updateByQuery, update$1_updateMany as updateMany, update$1_updateWithConstraints as updateWithConstraints, update$1_updateWithValidation as updateWithValidation };
179
+ }
180
+
181
+ /**
182
+ * Delete Actions
183
+ * Pure functions for document deletion
184
+ */
185
+
186
+ /**
187
+ * Delete by ID
188
+ */
189
+ declare function deleteById(Model: Model<any>, id: string, options?: {
190
+ session?: ClientSession;
191
+ }): Promise<DeleteResult>;
192
+ /**
193
+ * Delete many documents
194
+ */
195
+ declare function deleteMany(Model: Model<any>, query: Record<string, unknown>, options?: {
196
+ session?: ClientSession;
197
+ }): Promise<DeleteResult>;
198
+ /**
199
+ * Delete by query
200
+ */
201
+ declare function deleteByQuery(Model: Model<any>, query: Record<string, unknown>, options?: {
202
+ session?: ClientSession;
203
+ throwOnNotFound?: boolean;
204
+ }): Promise<DeleteResult>;
205
+ /**
206
+ * Soft delete (set deleted flag)
207
+ */
208
+ declare function softDelete<TDoc = AnyDocument>(Model: Model<TDoc>, id: string, options?: {
209
+ session?: ClientSession;
210
+ userId?: string;
211
+ }): Promise<DeleteResult>;
212
+ /**
213
+ * Restore soft deleted document
214
+ */
215
+ declare function restore<TDoc = AnyDocument>(Model: Model<TDoc>, id: string, options?: {
216
+ session?: ClientSession;
217
+ }): Promise<DeleteResult>;
218
+
219
+ declare const _delete_deleteById: typeof deleteById;
220
+ declare const _delete_deleteByQuery: typeof deleteByQuery;
221
+ declare const _delete_deleteMany: typeof deleteMany;
222
+ declare const _delete_restore: typeof restore;
223
+ declare const _delete_softDelete: typeof softDelete;
224
+ declare namespace _delete {
225
+ export { _delete_deleteById as deleteById, _delete_deleteByQuery as deleteByQuery, _delete_deleteMany as deleteMany, _delete_restore as restore, _delete_softDelete as softDelete };
226
+ }
227
+
228
+ /**
229
+ * Aggregate Actions
230
+ * MongoDB aggregation pipeline operations
231
+ */
232
+
233
+ /**
234
+ * Execute aggregation pipeline
235
+ */
236
+ declare function aggregate<TResult = unknown>(Model: Model<any>, pipeline: PipelineStage[], options?: {
237
+ session?: ClientSession;
238
+ }): Promise<TResult[]>;
239
+ /**
240
+ * Aggregate with pagination using native MongoDB $facet
241
+ * WARNING: $facet results must be <16MB. For larger results (limit >1000),
242
+ * consider using Repository.aggregatePaginate() or splitting into separate queries.
243
+ */
244
+ declare function aggregatePaginate<TDoc = AnyDocument>(Model: Model<TDoc>, pipeline: PipelineStage[], options?: {
245
+ page?: number;
246
+ limit?: number;
247
+ session?: ClientSession;
248
+ }): Promise<{
249
+ docs: TDoc[];
250
+ total: number;
251
+ page: number;
252
+ limit: number;
253
+ pages: number;
254
+ hasNext: boolean;
255
+ hasPrev: boolean;
256
+ }>;
257
+ /**
258
+ * Group documents by field value
259
+ */
260
+ declare function groupBy(Model: Model<any>, field: string, options?: {
261
+ limit?: number;
262
+ session?: ClientSession;
263
+ }): Promise<GroupResult[]>;
264
+ /**
265
+ * Count by field values
266
+ */
267
+ declare function countBy(Model: Model<any>, field: string, query?: Record<string, unknown>, options?: {
268
+ session?: ClientSession;
269
+ }): Promise<GroupResult[]>;
270
+ /**
271
+ * Lookup (join) with another collection
272
+ */
273
+ declare function lookup<TDoc = AnyDocument>(Model: Model<TDoc>, lookupOptions: LookupOptions): Promise<TDoc[]>;
274
+ /**
275
+ * Unwind array field
276
+ */
277
+ declare function unwind<TDoc = AnyDocument>(Model: Model<TDoc>, field: string, options?: {
278
+ preserveEmpty?: boolean;
279
+ session?: ClientSession;
280
+ }): Promise<TDoc[]>;
281
+ /**
282
+ * Facet search (multiple aggregations in one query)
283
+ */
284
+ declare function facet<TResult = Record<string, unknown[]>>(Model: Model<any>, facets: Record<string, PipelineStage[]>, options?: {
285
+ session?: ClientSession;
286
+ }): Promise<TResult[]>;
287
+ /**
288
+ * Get distinct values
289
+ */
290
+ declare function distinct<T = unknown>(Model: Model<any>, field: string, query?: Record<string, unknown>, options?: {
291
+ session?: ClientSession;
292
+ }): Promise<T[]>;
293
+ /**
294
+ * Calculate sum
295
+ */
296
+ declare function sum(Model: Model<any>, field: string, query?: Record<string, unknown>, options?: {
297
+ session?: ClientSession;
298
+ }): Promise<number>;
299
+ /**
300
+ * Calculate average
301
+ */
302
+ declare function average(Model: Model<any>, field: string, query?: Record<string, unknown>, options?: {
303
+ session?: ClientSession;
304
+ }): Promise<number>;
305
+ /**
306
+ * Min/Max
307
+ */
308
+ declare function minMax(Model: Model<any>, field: string, query?: Record<string, unknown>, options?: {
309
+ session?: ClientSession;
310
+ }): Promise<MinMaxResult>;
311
+
312
+ declare const aggregate$1_aggregate: typeof aggregate;
313
+ declare const aggregate$1_aggregatePaginate: typeof aggregatePaginate;
314
+ declare const aggregate$1_average: typeof average;
315
+ declare const aggregate$1_countBy: typeof countBy;
316
+ declare const aggregate$1_distinct: typeof distinct;
317
+ declare const aggregate$1_facet: typeof facet;
318
+ declare const aggregate$1_groupBy: typeof groupBy;
319
+ declare const aggregate$1_lookup: typeof lookup;
320
+ declare const aggregate$1_minMax: typeof minMax;
321
+ declare const aggregate$1_sum: typeof sum;
322
+ declare const aggregate$1_unwind: typeof unwind;
323
+ declare namespace aggregate$1 {
324
+ export { aggregate$1_aggregate as aggregate, aggregate$1_aggregatePaginate as aggregatePaginate, aggregate$1_average as average, aggregate$1_countBy as countBy, aggregate$1_distinct as distinct, aggregate$1_facet as facet, aggregate$1_groupBy as groupBy, aggregate$1_lookup as lookup, aggregate$1_minMax as minMax, aggregate$1_sum as sum, aggregate$1_unwind as unwind };
325
+ }
326
+
327
+ /**
328
+ * Repository Actions
329
+ * Modular, composable data access operations
330
+ */
331
+
332
+ declare const index_read: typeof read;
333
+ declare namespace index {
334
+ export { aggregate$1 as aggregate, create$1 as create, _delete as deleteActions, index_read as read, update$1 as update };
335
+ }
336
+
337
+ export { _delete as _, aggregate$1 as a, create$1 as c, index as i, read as r, update$1 as u };
@@ -0,0 +1,239 @@
1
+ import { A as AnyDocument, e as PluginType, P as PaginationConfig, S as SelectSpec, f as PopulateSpec, g as SortSpec, a as OffsetPaginationResult, b as KeysetPaginationResult, d as AggregatePaginationResult, R as RepositoryContext, H as HttpError } from './types-Nxhmi1aI.js';
2
+ export { c as AggregatePaginationOptions, i as AnyModel, N as CacheAdapter, T as CacheOperationOptions, Q as CacheOptions, W as CacheStats, C as CreateOptions, w as CrudSchemas, x as DecodedCursor, D as DeleteResult, E as EventPayload, F as FieldPreset, u as FieldRules, I as GroupResult, J as JsonSchema, K as KeysetPaginationOptions, L as Logger, G as LookupOptions, M as MinMaxResult, h as ObjectId, O as OffsetPaginationOptions, l as OperationOptions, k as PaginationResult, t as ParsedQuery, p as Plugin, q as PluginFunction, s as RepositoryEvent, r as RepositoryInstance, v as SchemaBuilderOptions, B as SoftDeleteOptions, j as SortDirection, m as UpdateManyResult, U as UpdateOptions, n as UpdateWithValidationResult, o as UserContext, z as ValidationChainOptions, V as ValidationResult, y as ValidatorDefinition } from './types-Nxhmi1aI.js';
3
+ import * as mongoose from 'mongoose';
4
+ import { Model, ClientSession, PipelineStage, PopulateOptions } from 'mongoose';
5
+ import { PaginationEngine } from './pagination/PaginationEngine.js';
6
+ export { aggregateHelpersPlugin, auditLogPlugin, autoInject, batchOperationsPlugin, blockIf, cachePlugin, fieldFilterPlugin, immutableField, methodRegistryPlugin, mongoOperationsPlugin, requireField, softDeletePlugin, subdocumentPlugin, timestampPlugin, uniqueField, validationChainPlugin } from './plugins/index.js';
7
+ export { b as createError, c as createFieldPreset, d as createMemoryCache, f as filterResponseData, g as getFieldsForUser, a as getMongooseProjection } from './memory-cache-DG2oSSbx.js';
8
+ export { i as actions } from './index-CgOJ2pqz.js';
9
+
10
+ /**
11
+ * Repository Pattern - Data Access Layer
12
+ *
13
+ * Event-driven, plugin-based abstraction for MongoDB operations
14
+ * Inspired by Meta & Stripe's repository patterns
15
+ *
16
+ * @example
17
+ * ```typescript
18
+ * const userRepo = new Repository(UserModel, [
19
+ * timestampPlugin(),
20
+ * softDeletePlugin(),
21
+ * ]);
22
+ *
23
+ * // Create
24
+ * const user = await userRepo.create({ name: 'John', email: 'john@example.com' });
25
+ *
26
+ * // Read with pagination
27
+ * const users = await userRepo.getAll({ page: 1, limit: 20, filters: { status: 'active' } });
28
+ *
29
+ * // Update
30
+ * const updated = await userRepo.update(user._id, { name: 'John Doe' });
31
+ *
32
+ * // Delete
33
+ * await userRepo.delete(user._id);
34
+ * ```
35
+ */
36
+
37
+ type HookListener = (data: any) => void | Promise<void>;
38
+ /**
39
+ * Production-grade repository for MongoDB
40
+ * Event-driven, plugin-based, with smart pagination
41
+ */
42
+ declare class Repository<TDoc = AnyDocument> {
43
+ readonly Model: Model<TDoc>;
44
+ readonly model: string;
45
+ readonly _hooks: Map<string, HookListener[]>;
46
+ readonly _pagination: PaginationEngine<TDoc>;
47
+ [key: string]: unknown;
48
+ constructor(Model: Model<TDoc>, plugins?: PluginType[], paginationConfig?: PaginationConfig);
49
+ /**
50
+ * Register a plugin
51
+ */
52
+ use(plugin: PluginType): this;
53
+ /**
54
+ * Register event listener
55
+ */
56
+ on(event: string, listener: HookListener): this;
57
+ /**
58
+ * Emit event
59
+ */
60
+ emit(event: string, data: unknown): void;
61
+ /**
62
+ * Create single document
63
+ */
64
+ create(data: Record<string, unknown>, options?: {
65
+ session?: ClientSession;
66
+ }): Promise<TDoc>;
67
+ /**
68
+ * Create multiple documents
69
+ */
70
+ createMany(dataArray: Record<string, unknown>[], options?: {
71
+ session?: ClientSession;
72
+ ordered?: boolean;
73
+ }): Promise<TDoc[]>;
74
+ /**
75
+ * Get document by ID
76
+ */
77
+ getById(id: string, options?: {
78
+ select?: SelectSpec;
79
+ populate?: PopulateSpec;
80
+ lean?: boolean;
81
+ session?: ClientSession;
82
+ throwOnNotFound?: boolean;
83
+ skipCache?: boolean;
84
+ cacheTtl?: number;
85
+ }): Promise<TDoc | null>;
86
+ /**
87
+ * Get single document by query
88
+ */
89
+ getByQuery(query: Record<string, unknown>, options?: {
90
+ select?: SelectSpec;
91
+ populate?: PopulateSpec;
92
+ lean?: boolean;
93
+ session?: ClientSession;
94
+ throwOnNotFound?: boolean;
95
+ skipCache?: boolean;
96
+ cacheTtl?: number;
97
+ }): Promise<TDoc | null>;
98
+ /**
99
+ * Unified pagination - auto-detects offset vs keyset based on params
100
+ *
101
+ * Auto-detection logic:
102
+ * - If params has 'cursor' or 'after' → uses keyset pagination (stream)
103
+ * - If params has 'pagination' or 'page' → uses offset pagination (paginate)
104
+ * - Else → defaults to offset pagination with page=1
105
+ *
106
+ * @example
107
+ * // Offset pagination (page-based)
108
+ * await repo.getAll({ page: 1, limit: 50, filters: { status: 'active' } });
109
+ * await repo.getAll({ pagination: { page: 2, limit: 20 } });
110
+ *
111
+ * // Keyset pagination (cursor-based)
112
+ * await repo.getAll({ cursor: 'eyJ2Ij...', limit: 50 });
113
+ * await repo.getAll({ after: 'eyJ2Ij...', sort: { createdAt: -1 } });
114
+ *
115
+ * // Simple query (defaults to page 1)
116
+ * await repo.getAll({ filters: { status: 'active' } });
117
+ *
118
+ * // Skip cache for fresh data
119
+ * await repo.getAll({ filters: { status: 'active' } }, { skipCache: true });
120
+ */
121
+ getAll(params?: {
122
+ filters?: Record<string, unknown>;
123
+ sort?: SortSpec | string;
124
+ cursor?: string;
125
+ after?: string;
126
+ page?: number;
127
+ pagination?: {
128
+ page?: number;
129
+ limit?: number;
130
+ };
131
+ limit?: number;
132
+ search?: string;
133
+ }, options?: {
134
+ select?: SelectSpec;
135
+ populate?: PopulateSpec;
136
+ lean?: boolean;
137
+ session?: ClientSession;
138
+ skipCache?: boolean;
139
+ cacheTtl?: number;
140
+ }): Promise<OffsetPaginationResult<TDoc> | KeysetPaginationResult<TDoc>>;
141
+ /**
142
+ * Get or create document
143
+ */
144
+ getOrCreate(query: Record<string, unknown>, createData: Record<string, unknown>, options?: {
145
+ session?: ClientSession;
146
+ }): Promise<TDoc | null>;
147
+ /**
148
+ * Count documents
149
+ */
150
+ count(query?: Record<string, unknown>, options?: {
151
+ session?: ClientSession;
152
+ }): Promise<number>;
153
+ /**
154
+ * Check if document exists
155
+ */
156
+ exists(query: Record<string, unknown>, options?: {
157
+ session?: ClientSession;
158
+ }): Promise<{
159
+ _id: unknown;
160
+ } | null>;
161
+ /**
162
+ * Update document by ID
163
+ */
164
+ update(id: string, data: Record<string, unknown>, options?: {
165
+ select?: SelectSpec;
166
+ populate?: PopulateSpec;
167
+ lean?: boolean;
168
+ session?: ClientSession;
169
+ }): Promise<TDoc>;
170
+ /**
171
+ * Delete document by ID
172
+ */
173
+ delete(id: string, options?: {
174
+ session?: ClientSession;
175
+ }): Promise<{
176
+ success: boolean;
177
+ message: string;
178
+ }>;
179
+ /**
180
+ * Execute aggregation pipeline
181
+ */
182
+ aggregate<TResult = unknown>(pipeline: PipelineStage[], options?: {
183
+ session?: ClientSession;
184
+ }): Promise<TResult[]>;
185
+ /**
186
+ * Aggregate pipeline with pagination
187
+ * Best for: Complex queries, grouping, joins
188
+ */
189
+ aggregatePaginate(options?: {
190
+ pipeline?: PipelineStage[];
191
+ page?: number;
192
+ limit?: number;
193
+ session?: ClientSession;
194
+ }): Promise<AggregatePaginationResult<TDoc>>;
195
+ /**
196
+ * Get distinct values
197
+ */
198
+ distinct<T = unknown>(field: string, query?: Record<string, unknown>, options?: {
199
+ session?: ClientSession;
200
+ }): Promise<T[]>;
201
+ /**
202
+ * Execute callback within a transaction
203
+ */
204
+ withTransaction<T>(callback: (session: ClientSession) => Promise<T>): Promise<T>;
205
+ /**
206
+ * Execute custom query with event emission
207
+ */
208
+ _executeQuery<T>(buildQuery: (Model: Model<TDoc>) => Promise<T>): Promise<T>;
209
+ /**
210
+ * Build operation context and run before hooks
211
+ */
212
+ _buildContext(operation: string, options: Record<string, unknown>): Promise<RepositoryContext>;
213
+ /**
214
+ * Parse sort string or object
215
+ */
216
+ _parseSort(sort: SortSpec | string | undefined): SortSpec;
217
+ /**
218
+ * Parse populate specification
219
+ */
220
+ _parsePopulate(populate: PopulateSpec | undefined): string[] | PopulateOptions[];
221
+ /**
222
+ * Handle errors with proper HTTP status codes
223
+ */
224
+ _handleError(error: Error): HttpError;
225
+ }
226
+
227
+ /**
228
+ * Factory function to create a repository instance
229
+ *
230
+ * @param Model - Mongoose model
231
+ * @param plugins - Array of plugins to apply
232
+ * @returns Repository instance
233
+ *
234
+ * @example
235
+ * const userRepo = createRepository(UserModel, [timestampPlugin()]);
236
+ */
237
+ declare function createRepository<TDoc>(Model: mongoose.Model<TDoc>, plugins?: PluginType[]): Repository<TDoc>;
238
+
239
+ export { AggregatePaginationResult, AnyDocument, HttpError, KeysetPaginationResult, OffsetPaginationResult, PaginationConfig, PaginationEngine, PluginType, PopulateSpec, Repository, RepositoryContext, SelectSpec, SortSpec, createRepository, Repository as default };