@classytic/mongokit 2.1.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.
@@ -1,337 +0,0 @@
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.cjs';
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 };