@classytic/mongokit 1.0.1 → 2.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 (87) hide show
  1. package/README.md +564 -157
  2. package/package.json +20 -12
  3. package/src/Repository.js +296 -225
  4. package/src/actions/aggregate.js +266 -191
  5. package/src/actions/create.js +59 -58
  6. package/src/actions/delete.js +88 -88
  7. package/src/actions/index.js +11 -11
  8. package/src/actions/read.js +188 -155
  9. package/src/actions/update.js +176 -172
  10. package/src/hooks/lifecycle.js +146 -146
  11. package/src/index.js +71 -60
  12. package/src/pagination/PaginationEngine.js +348 -0
  13. package/src/pagination/utils/cursor.js +119 -0
  14. package/src/pagination/utils/filter.js +42 -0
  15. package/src/pagination/utils/limits.js +82 -0
  16. package/src/pagination/utils/sort.js +101 -0
  17. package/src/plugins/aggregate-helpers.plugin.js +71 -71
  18. package/src/plugins/audit-log.plugin.js +60 -60
  19. package/src/plugins/batch-operations.plugin.js +66 -66
  20. package/src/plugins/field-filter.plugin.js +27 -27
  21. package/src/plugins/index.js +19 -19
  22. package/src/plugins/method-registry.plugin.js +140 -140
  23. package/src/plugins/mongo-operations.plugin.js +317 -313
  24. package/src/plugins/soft-delete.plugin.js +46 -46
  25. package/src/plugins/subdocument.plugin.js +66 -66
  26. package/src/plugins/timestamp.plugin.js +19 -19
  27. package/src/plugins/validation-chain.plugin.js +145 -145
  28. package/src/types.d.ts +87 -0
  29. package/src/utils/error.js +12 -0
  30. package/src/utils/field-selection.js +156 -156
  31. package/src/utils/index.js +12 -12
  32. package/types/Repository.d.ts +95 -0
  33. package/types/Repository.d.ts.map +1 -0
  34. package/types/actions/aggregate.d.ts +112 -0
  35. package/types/actions/aggregate.d.ts.map +1 -0
  36. package/types/actions/create.d.ts +21 -0
  37. package/types/actions/create.d.ts.map +1 -0
  38. package/types/actions/delete.d.ts +37 -0
  39. package/types/actions/delete.d.ts.map +1 -0
  40. package/types/actions/index.d.ts +6 -113
  41. package/types/actions/index.d.ts.map +1 -0
  42. package/types/actions/read.d.ts +135 -0
  43. package/types/actions/read.d.ts.map +1 -0
  44. package/types/actions/update.d.ts +58 -0
  45. package/types/actions/update.d.ts.map +1 -0
  46. package/types/hooks/lifecycle.d.ts +44 -0
  47. package/types/hooks/lifecycle.d.ts.map +1 -0
  48. package/types/index.d.ts +25 -96
  49. package/types/index.d.ts.map +1 -0
  50. package/types/pagination/PaginationEngine.d.ts +386 -0
  51. package/types/pagination/PaginationEngine.d.ts.map +1 -0
  52. package/types/pagination/utils/cursor.d.ts +40 -0
  53. package/types/pagination/utils/cursor.d.ts.map +1 -0
  54. package/types/pagination/utils/filter.d.ts +28 -0
  55. package/types/pagination/utils/filter.d.ts.map +1 -0
  56. package/types/pagination/utils/limits.d.ts +64 -0
  57. package/types/pagination/utils/limits.d.ts.map +1 -0
  58. package/types/pagination/utils/sort.d.ts +41 -0
  59. package/types/pagination/utils/sort.d.ts.map +1 -0
  60. package/types/plugins/aggregate-helpers.plugin.d.ts +6 -0
  61. package/types/plugins/aggregate-helpers.plugin.d.ts.map +1 -0
  62. package/types/plugins/audit-log.plugin.d.ts +6 -0
  63. package/types/plugins/audit-log.plugin.d.ts.map +1 -0
  64. package/types/plugins/batch-operations.plugin.d.ts +6 -0
  65. package/types/plugins/batch-operations.plugin.d.ts.map +1 -0
  66. package/types/plugins/field-filter.plugin.d.ts +6 -0
  67. package/types/plugins/field-filter.plugin.d.ts.map +1 -0
  68. package/types/plugins/index.d.ts +11 -88
  69. package/types/plugins/index.d.ts.map +1 -0
  70. package/types/plugins/method-registry.plugin.d.ts +3 -0
  71. package/types/plugins/method-registry.plugin.d.ts.map +1 -0
  72. package/types/plugins/mongo-operations.plugin.d.ts +4 -0
  73. package/types/plugins/mongo-operations.plugin.d.ts.map +1 -0
  74. package/types/plugins/soft-delete.plugin.d.ts +6 -0
  75. package/types/plugins/soft-delete.plugin.d.ts.map +1 -0
  76. package/types/plugins/subdocument.plugin.d.ts +6 -0
  77. package/types/plugins/subdocument.plugin.d.ts.map +1 -0
  78. package/types/plugins/timestamp.plugin.d.ts +6 -0
  79. package/types/plugins/timestamp.plugin.d.ts.map +1 -0
  80. package/types/plugins/validation-chain.plugin.d.ts +31 -0
  81. package/types/plugins/validation-chain.plugin.d.ts.map +1 -0
  82. package/types/utils/error.d.ts +11 -0
  83. package/types/utils/error.d.ts.map +1 -0
  84. package/types/utils/field-selection.d.ts +9 -0
  85. package/types/utils/field-selection.d.ts.map +1 -0
  86. package/types/utils/index.d.ts +2 -24
  87. package/types/utils/index.d.ts.map +1 -0
@@ -1,113 +1,6 @@
1
- import { Model, Document, FilterQuery, UpdateQuery, ClientSession } from 'mongoose';
2
-
3
- export interface ActionOptions {
4
- session?: ClientSession;
5
- [key: string]: any;
6
- }
7
-
8
- // Create actions
9
- export function create<T extends Document>(
10
- Model: Model<T>,
11
- data: Partial<T>,
12
- options?: ActionOptions
13
- ): Promise<T>;
14
-
15
- export function createMany<T extends Document>(
16
- Model: Model<T>,
17
- dataArray: Partial<T>[],
18
- options?: ActionOptions
19
- ): Promise<T[]>;
20
-
21
- export function createDefault<T extends Document>(
22
- Model: Model<T>,
23
- overrides?: Partial<T>,
24
- options?: ActionOptions
25
- ): Promise<T>;
26
-
27
- export function upsert<T extends Document>(
28
- Model: Model<T>,
29
- query: FilterQuery<T>,
30
- data: Partial<T>,
31
- options?: ActionOptions
32
- ): Promise<T>;
33
-
34
- // Read actions
35
- export function getById<T extends Document>(
36
- Model: Model<T>,
37
- id: string,
38
- options?: ActionOptions
39
- ): Promise<T | null>;
40
-
41
- export function getByQuery<T extends Document>(
42
- Model: Model<T>,
43
- query: FilterQuery<T>,
44
- options?: ActionOptions
45
- ): Promise<T | null>;
46
-
47
- export function getOrCreate<T extends Document>(
48
- Model: Model<T>,
49
- query: FilterQuery<T>,
50
- createData: Partial<T>,
51
- options?: ActionOptions
52
- ): Promise<T>;
53
-
54
- export function count<T extends Document>(
55
- Model: Model<T>,
56
- query?: FilterQuery<T>,
57
- options?: ActionOptions
58
- ): Promise<number>;
59
-
60
- export function exists<T extends Document>(
61
- Model: Model<T>,
62
- query: FilterQuery<T>,
63
- options?: ActionOptions
64
- ): Promise<boolean>;
65
-
66
- // Update actions
67
- export function update<T extends Document>(
68
- Model: Model<T>,
69
- id: string,
70
- data: UpdateQuery<T>,
71
- options?: ActionOptions
72
- ): Promise<T | null>;
73
-
74
- export function updateMany<T extends Document>(
75
- Model: Model<T>,
76
- query: FilterQuery<T>,
77
- data: UpdateQuery<T>,
78
- options?: ActionOptions
79
- ): Promise<any>;
80
-
81
- // Delete actions
82
- export function deleteById<T extends Document>(
83
- Model: Model<T>,
84
- id: string,
85
- options?: ActionOptions
86
- ): Promise<T | null>;
87
-
88
- export function deleteMany<T extends Document>(
89
- Model: Model<T>,
90
- query: FilterQuery<T>,
91
- options?: ActionOptions
92
- ): Promise<any>;
93
-
94
- // Aggregate actions
95
- export function aggregate<T extends Document>(
96
- Model: Model<T>,
97
- pipeline: any[],
98
- options?: ActionOptions
99
- ): Promise<any[]>;
100
-
101
- export function aggregatePaginate<T extends Document>(
102
- Model: Model<T>,
103
- pipeline: any[],
104
- options?: ActionOptions
105
- ): Promise<any>;
106
-
107
- export function distinct<T extends Document>(
108
- Model: Model<T>,
109
- field: string,
110
- query?: FilterQuery<T>,
111
- options?: ActionOptions
112
- ): Promise<any[]>;
113
-
1
+ export * as create from "./create.js";
2
+ export * as read from "./read.js";
3
+ export * as update from "./update.js";
4
+ export * as deleteActions from "./delete.js";
5
+ export * as aggregate from "./aggregate.js";
6
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/actions/index.js"],"names":[],"mappings":""}
@@ -0,0 +1,135 @@
1
+ /**
2
+ * @typedef {import('mongoose').Model} Model
3
+ * @typedef {import('mongoose').PopulateOptions} PopulateOptions
4
+ * @typedef {import('mongoose').ClientSession} ClientSession
5
+ */
6
+ /**
7
+ * Get document by ID
8
+ *
9
+ * @param {Model} Model - Mongoose model
10
+ * @param {string} id - Document ID
11
+ * @param {Object} [options={}] - Query options
12
+ * @param {string|string[]} [options.select] - Fields to select
13
+ * @param {string|string[]|PopulateOptions|PopulateOptions[]} [options.populate] - Fields to populate
14
+ * @param {boolean} [options.lean] - Return plain JavaScript object
15
+ * @param {ClientSession} [options.session] - MongoDB session
16
+ * @param {boolean} [options.throwOnNotFound=true] - Throw error if not found
17
+ * @returns {Promise<any>} Document or null
18
+ * @throws {Error} If document not found and throwOnNotFound is true
19
+ */
20
+ export function getById(Model: Model, id: string, options?: {
21
+ select?: string | string[];
22
+ populate?: string | string[] | PopulateOptions | PopulateOptions[];
23
+ lean?: boolean;
24
+ session?: ClientSession;
25
+ throwOnNotFound?: boolean;
26
+ }): Promise<any>;
27
+ /**
28
+ * Get document by query
29
+ *
30
+ * @param {Model} Model - Mongoose model
31
+ * @param {Record<string, any>} query - MongoDB query
32
+ * @param {Object} [options={}] - Query options
33
+ * @param {string|string[]} [options.select] - Fields to select
34
+ * @param {string|string[]|PopulateOptions|PopulateOptions[]} [options.populate] - Fields to populate
35
+ * @param {boolean} [options.lean] - Return plain JavaScript object
36
+ * @param {ClientSession} [options.session] - MongoDB session
37
+ * @param {boolean} [options.throwOnNotFound=true] - Throw error if not found
38
+ * @returns {Promise<any>} Document or null
39
+ * @throws {Error} If document not found and throwOnNotFound is true
40
+ */
41
+ export function getByQuery(Model: Model, query: Record<string, any>, options?: {
42
+ select?: string | string[];
43
+ populate?: string | string[] | PopulateOptions | PopulateOptions[];
44
+ lean?: boolean;
45
+ session?: ClientSession;
46
+ throwOnNotFound?: boolean;
47
+ }): Promise<any>;
48
+ /**
49
+ * Get document by query without throwing (returns null if not found)
50
+ *
51
+ * @param {Model} Model - Mongoose model
52
+ * @param {Record<string, any>} query - MongoDB query
53
+ * @param {Object} [options={}] - Query options
54
+ * @param {string|string[]} [options.select] - Fields to select
55
+ * @param {string|string[]|PopulateOptions|PopulateOptions[]} [options.populate] - Fields to populate
56
+ * @param {boolean} [options.lean] - Return plain JavaScript object
57
+ * @param {ClientSession} [options.session] - MongoDB session
58
+ * @returns {Promise<any|null>} Document or null
59
+ */
60
+ export function tryGetByQuery(Model: Model, query: Record<string, any>, options?: {
61
+ select?: string | string[];
62
+ populate?: string | string[] | PopulateOptions | PopulateOptions[];
63
+ lean?: boolean;
64
+ session?: ClientSession;
65
+ }): Promise<any | null>;
66
+ /**
67
+ * Get all documents (basic query without pagination)
68
+ * For pagination, use Repository.paginate() or Repository.stream()
69
+ *
70
+ * @param {Model} Model - Mongoose model
71
+ * @param {Record<string, any>} [query={}] - MongoDB query
72
+ * @param {Object} [options={}] - Query options
73
+ * @param {string|string[]} [options.select] - Fields to select
74
+ * @param {string|string[]|PopulateOptions|PopulateOptions[]} [options.populate] - Fields to populate
75
+ * @param {Record<string, 1|-1>} [options.sort] - Sort specification
76
+ * @param {number} [options.limit] - Maximum documents to return
77
+ * @param {number} [options.skip] - Documents to skip
78
+ * @param {boolean} [options.lean=true] - Return plain JavaScript objects
79
+ * @param {ClientSession} [options.session] - MongoDB session
80
+ * @returns {Promise<any[]>} Array of documents
81
+ */
82
+ export function getAll(Model: Model, query?: Record<string, any>, options?: {
83
+ select?: string | string[];
84
+ populate?: string | string[] | PopulateOptions | PopulateOptions[];
85
+ sort?: Record<string, 1 | -1>;
86
+ limit?: number;
87
+ skip?: number;
88
+ lean?: boolean;
89
+ session?: ClientSession;
90
+ }): Promise<any[]>;
91
+ /**
92
+ * Get or create document (upsert)
93
+ *
94
+ * @param {Model} Model - Mongoose model
95
+ * @param {Record<string, any>} query - Query to find document
96
+ * @param {Record<string, any>} createData - Data to insert if not found
97
+ * @param {Object} [options={}] - Query options
98
+ * @param {ClientSession} [options.session] - MongoDB session
99
+ * @param {boolean} [options.updatePipeline] - Use update pipeline
100
+ * @returns {Promise<any>} Created or found document
101
+ */
102
+ export function getOrCreate(Model: Model, query: Record<string, any>, createData: Record<string, any>, options?: {
103
+ session?: ClientSession;
104
+ updatePipeline?: boolean;
105
+ }): Promise<any>;
106
+ /**
107
+ * Count documents matching query
108
+ *
109
+ * @param {Model} Model - Mongoose model
110
+ * @param {Record<string, any>} [query={}] - MongoDB query
111
+ * @param {Object} [options={}] - Query options
112
+ * @param {ClientSession} [options.session] - MongoDB session
113
+ * @returns {Promise<number>} Document count
114
+ */
115
+ export function count(Model: Model, query?: Record<string, any>, options?: {
116
+ session?: ClientSession;
117
+ }): Promise<number>;
118
+ /**
119
+ * Check if document exists
120
+ *
121
+ * @param {Model} Model - Mongoose model
122
+ * @param {Record<string, any>} query - MongoDB query
123
+ * @param {Object} [options={}] - Query options
124
+ * @param {ClientSession} [options.session] - MongoDB session
125
+ * @returns {Promise<{_id: any} | null>} Document ID if exists, null otherwise
126
+ */
127
+ export function exists(Model: Model, query: Record<string, any>, options?: {
128
+ session?: ClientSession;
129
+ }): Promise<{
130
+ _id: any;
131
+ } | null>;
132
+ export type Model = import("mongoose").Model<any, any, any, any, any, any, any>;
133
+ export type PopulateOptions = import("mongoose").PopulateOptions;
134
+ export type ClientSession = import("mongoose").ClientSession;
135
+ //# sourceMappingURL=read.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"read.d.ts","sourceRoot":"","sources":["../../src/actions/read.js"],"names":[],"mappings":"AAOA;;;;GAIG;AAEH;;;;;;;;;;;;;GAaG;AACH,+BAXW,KAAK,MACL,MAAM,YAEd;IAAkC,MAAM,GAAhC,MAAM,GAAC,MAAM,EAAE;IAC6C,QAAQ,GAApE,MAAM,GAAC,MAAM,EAAE,GAAC,eAAe,GAAC,eAAe,EAAE;IAC/B,IAAI,GAAtB,OAAO;IACiB,OAAO,GAA/B,aAAa;IACK,eAAe,GAAjC,OAAO;CACf,GAAU,OAAO,CAAC,GAAG,CAAC,CAiBxB;AAED;;;;;;;;;;;;;GAaG;AACH,kCAXW,KAAK,SACL,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,YAE3B;IAAkC,MAAM,GAAhC,MAAM,GAAC,MAAM,EAAE;IAC6C,QAAQ,GAApE,MAAM,GAAC,MAAM,EAAE,GAAC,eAAe,GAAC,eAAe,EAAE;IAC/B,IAAI,GAAtB,OAAO;IACiB,OAAO,GAA/B,aAAa;IACK,eAAe,GAAjC,OAAO;CACf,GAAU,OAAO,CAAC,GAAG,CAAC,CAiBxB;AAED;;;;;;;;;;;GAWG;AACH,qCATW,KAAK,SACL,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,YAE3B;IAAkC,MAAM,GAAhC,MAAM,GAAC,MAAM,EAAE;IAC6C,QAAQ,GAApE,MAAM,GAAC,MAAM,EAAE,GAAC,eAAe,GAAC,eAAe,EAAE;IAC/B,IAAI,GAAtB,OAAO;IACiB,OAAO,GAA/B,aAAa;CACrB,GAAU,OAAO,CAAC,GAAG,GAAC,IAAI,CAAC,CAI7B;AAED;;;;;;;;;;;;;;;GAeG;AACH,8BAZW,KAAK,UACL,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,YAE3B;IAAkC,MAAM,GAAhC,MAAM,GAAC,MAAM,EAAE;IAC6C,QAAQ,GAApE,MAAM,GAAC,MAAM,EAAE,GAAC,eAAe,GAAC,eAAe,EAAE;IAClB,IAAI,GAAnC,MAAM,CAAC,MAAM,EAAE,CAAC,GAAC,CAAC,CAAC,CAAC;IACH,KAAK,GAAtB,MAAM;IACW,IAAI,GAArB,MAAM;IACY,IAAI,GAAtB,OAAO;IACiB,OAAO,GAA/B,aAAa;CACrB,GAAU,OAAO,CAAC,GAAG,EAAE,CAAC,CAe1B;AAED;;;;;;;;;;GAUG;AACH,mCARW,KAAK,SACL,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,cACnB,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,YAE3B;IAAgC,OAAO,GAA/B,aAAa;IACK,cAAc,GAAhC,OAAO;CACf,GAAU,OAAO,CAAC,GAAG,CAAC,CAcxB;AAED;;;;;;;;GAQG;AACH,6BANW,KAAK,UACL,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,YAE3B;IAAgC,OAAO,GAA/B,aAAa;CACrB,GAAU,OAAO,CAAC,MAAM,CAAC,CAI3B;AAED;;;;;;;;GAQG;AACH,8BANW,KAAK,SACL,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,YAE3B;IAAgC,OAAO,GAA/B,aAAa;CACrB,GAAU,OAAO,CAAC;IAAC,GAAG,EAAE,GAAG,CAAA;CAAC,GAAG,IAAI,CAAC,CAItC;;8BAhKY,OAAO,UAAU,EAAE,eAAe;4BAClC,OAAO,UAAU,EAAE,aAAa"}
@@ -0,0 +1,58 @@
1
+ /**
2
+ * Update by ID
3
+ */
4
+ export function update(Model: any, id: any, data: any, options?: {}): Promise<any>;
5
+ /**
6
+ * Update with query constraints (optimized)
7
+ * Returns null if constraints not met (not an error)
8
+ */
9
+ export function updateWithConstraints(Model: any, id: any, data: any, constraints?: {}, options?: {}): Promise<any>;
10
+ /**
11
+ * Update with validation (smart optimization)
12
+ * 1-query on success, 2-queries for detailed errors
13
+ */
14
+ export function updateWithValidation(Model: any, id: any, data: any, validationOptions?: {}, options?: {}): Promise<{
15
+ success: boolean;
16
+ data: any;
17
+ error?: undefined;
18
+ } | {
19
+ success: boolean;
20
+ error: {
21
+ code: number;
22
+ message: string;
23
+ violations?: undefined;
24
+ };
25
+ data?: undefined;
26
+ } | {
27
+ success: boolean;
28
+ error: {
29
+ code: number;
30
+ message: any;
31
+ violations: any;
32
+ };
33
+ data?: undefined;
34
+ }>;
35
+ /**
36
+ * Update many documents
37
+ */
38
+ export function updateMany(Model: any, query: any, data: any, options?: {}): Promise<{
39
+ matchedCount: any;
40
+ modifiedCount: any;
41
+ }>;
42
+ /**
43
+ * Update by query
44
+ */
45
+ export function updateByQuery(Model: any, query: any, data: any, options?: {}): Promise<any>;
46
+ /**
47
+ * Increment field
48
+ */
49
+ export function increment(Model: any, id: any, field: any, value?: number, options?: {}): Promise<any>;
50
+ /**
51
+ * Push to array
52
+ */
53
+ export function pushToArray(Model: any, id: any, field: any, value: any, options?: {}): Promise<any>;
54
+ /**
55
+ * Pull from array
56
+ */
57
+ export function pullFromArray(Model: any, id: any, field: any, value: any, options?: {}): Promise<any>;
58
+ //# sourceMappingURL=update.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"update.d.ts","sourceRoot":"","sources":["../../src/actions/update.js"],"names":[],"mappings":"AAOA;;GAEG;AACH,mFAgBC;AAED;;;GAGG;AACH,oHAcC;AAED;;;GAGG;AACH;;;;;;;;;;;;;;;;;;;;GAoDC;AAED;;GAEG;AACH;;;GAWC;AAED;;GAEG;AACH,6FAgBC;AAED;;GAEG;AACH,uGAEC;AAED;;GAEG;AACH,qGAEC;AAED;;GAEG;AACH,uGAEC"}
@@ -0,0 +1,44 @@
1
+ export class RepositoryLifecycle extends EventEmitter<[never]> {
2
+ constructor();
3
+ hooks: Map<any, any>;
4
+ /**
5
+ * Register hook
6
+ */
7
+ on(event: any, handler: any): this;
8
+ /**
9
+ * Execute hooks before action
10
+ */
11
+ runBeforeHooks(action: any, context: any): Promise<void>;
12
+ /**
13
+ * Execute hooks after action
14
+ */
15
+ runAfterHooks(action: any, context: any, result: any): Promise<void>;
16
+ /**
17
+ * Execute hooks on error
18
+ */
19
+ runErrorHooks(action: any, context: any, error: any): Promise<void>;
20
+ }
21
+ export namespace hooks {
22
+ function autoTimestamp(): {
23
+ 'before:create': (context: any) => void;
24
+ 'before:update': (context: any) => void;
25
+ };
26
+ function autoUser(userField?: string): {
27
+ 'before:create': (context: any) => void;
28
+ };
29
+ function autoOrganization(orgField?: string): {
30
+ 'before:create': (context: any) => void;
31
+ };
32
+ function auditLog(logger: any): {
33
+ 'after:create': (context: any, result: any) => void;
34
+ 'after:update': (context: any, result: any) => void;
35
+ 'after:delete': (context: any, result: any) => void;
36
+ };
37
+ function cacheInvalidation(cache: any): {
38
+ 'after:create': (context: any, result: any) => Promise<void>;
39
+ 'after:update': (context: any, result: any) => Promise<void>;
40
+ 'after:delete': (context: any) => Promise<void>;
41
+ };
42
+ }
43
+ import { EventEmitter } from 'events';
44
+ //# sourceMappingURL=lifecycle.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lifecycle.d.ts","sourceRoot":"","sources":["../../src/hooks/lifecycle.js"],"names":[],"mappings":"AAOA;IACE,cAGC;IADC,qBAAsB;IAGxB;;OAEG;IACH,mCAMC;IAED;;OAEG;IACH,yDAQC;IAED;;OAEG;IACH,qEAQC;IAED;;OAEG;IACH,oEAQC;CACF;;IASgB;;;MAQb;IAKQ;;MAMR;IAKgB;;MAMhB;IAKQ;;;;MAqBR;IAKiB;;;;MAWjB;;6BA1IyB,QAAQ"}
package/types/index.d.ts CHANGED
@@ -1,96 +1,25 @@
1
- import { Model, Document, ClientSession, PaginateOptions, PaginateResult, FilterQuery, UpdateQuery, AggregateOptions } from 'mongoose';
2
-
3
- export interface RepositoryOptions {
4
- session?: ClientSession;
5
- populate?: string | string[] | any;
6
- select?: string | any;
7
- lean?: boolean;
8
- throwOnNotFound?: boolean;
9
- }
10
-
11
- export interface QueryParams {
12
- pagination?: {
13
- page: number;
14
- limit: number;
15
- };
16
- search?: string;
17
- sort?: string;
18
- filters?: Record<string, any>;
19
- }
20
-
21
- export interface RepositoryContext {
22
- operation: string;
23
- model: string;
24
- data?: any;
25
- dataArray?: any[];
26
- id?: string;
27
- query?: any;
28
- queryParams?: QueryParams;
29
- context?: any;
30
- user?: any;
31
- organizationId?: string;
32
- [key: string]: any;
33
- }
34
-
35
- export type EventListener = (data: any) => void | Promise<void>;
36
-
37
- export interface Plugin {
38
- name: string;
39
- apply(repository: Repository<any>): void;
40
- }
41
-
42
- export type PluginFactory = (options?: any) => Plugin;
43
-
44
- export class Repository<T extends Document> {
45
- Model: Model<T>;
46
- model: string;
47
- protected _hooks: Map<string, EventListener[]>;
48
-
49
- constructor(Model: Model<T>, plugins?: (Plugin | PluginFactory)[]);
50
-
51
- // Plugin system
52
- use(plugin: Plugin | PluginFactory): this;
53
- on(event: string, listener: EventListener): this;
54
- emit(event: string, data: any): void;
55
-
56
- // CRUD operations
57
- create(data: Partial<T>, options?: RepositoryOptions): Promise<T>;
58
- createMany(dataArray: Partial<T>[], options?: RepositoryOptions): Promise<T[]>;
59
-
60
- getById(id: string, options?: RepositoryOptions): Promise<T | null>;
61
- getByQuery(query: FilterQuery<T>, options?: RepositoryOptions): Promise<T | null>;
62
- getAll(queryParams?: QueryParams, options?: RepositoryOptions): Promise<PaginateResult<T>>;
63
- getOrCreate(query: FilterQuery<T>, createData: Partial<T>, options?: RepositoryOptions): Promise<T>;
64
-
65
- count(query?: FilterQuery<T>, options?: RepositoryOptions): Promise<number>;
66
- exists(query: FilterQuery<T>, options?: RepositoryOptions): Promise<boolean>;
67
-
68
- update(id: string, data: UpdateQuery<T>, options?: RepositoryOptions): Promise<T | null>;
69
- delete(id: string, options?: RepositoryOptions): Promise<T | null>;
70
-
71
- // Aggregation
72
- aggregate(pipeline: any[], options?: AggregateOptions): Promise<any[]>;
73
- aggregatePaginate(pipeline: any[], options?: PaginateOptions): Promise<any>;
74
- distinct(field: string, query?: FilterQuery<T>, options?: RepositoryOptions): Promise<any[]>;
75
-
76
- // Transaction support
77
- withTransaction<R>(callback: (session: ClientSession) => Promise<R>): Promise<R>;
78
-
79
- // Internal methods
80
- protected _executeQuery(buildQuery: (model: Model<T>) => Promise<any>): Promise<any>;
81
- protected _buildContext(operation: string, options: any): Promise<RepositoryContext>;
82
- protected _parseSort(sort: string | object): object;
83
- protected _parsePopulate(populate: string | string[] | any): any[];
84
- protected _handleError(error: any): Error;
85
- }
86
-
87
- export function createRepository<T extends Document>(
88
- Model: Model<T>,
89
- plugins?: (Plugin | PluginFactory)[]
90
- ): Repository<T>;
91
-
92
- // Plugin exports
93
- export * from './plugins/index.js';
94
- export * from './utils/index.js';
95
- export * as actions from './actions/index.js';
96
-
1
+ export { Repository } from "./Repository.js";
2
+ export { PaginationEngine } from "./pagination/PaginationEngine.js";
3
+ export { fieldFilterPlugin } from "./plugins/field-filter.plugin.js";
4
+ export { timestampPlugin } from "./plugins/timestamp.plugin.js";
5
+ export { auditLogPlugin } from "./plugins/audit-log.plugin.js";
6
+ export { softDeletePlugin } from "./plugins/soft-delete.plugin.js";
7
+ export { methodRegistryPlugin } from "./plugins/method-registry.plugin.js";
8
+ export { mongoOperationsPlugin } from "./plugins/mongo-operations.plugin.js";
9
+ export { batchOperationsPlugin } from "./plugins/batch-operations.plugin.js";
10
+ export { aggregateHelpersPlugin } from "./plugins/aggregate-helpers.plugin.js";
11
+ export { subdocumentPlugin } from "./plugins/subdocument.plugin.js";
12
+ export * as actions from "./actions/index.js";
13
+ export function createRepository(Model: any, plugins?: any[]): Repository;
14
+ export default Repository;
15
+ export type PaginationConfig = import("./pagination/PaginationEngine.js").PaginationConfig;
16
+ export type OffsetPaginationOptions = import("./pagination/PaginationEngine.js").OffsetPaginationOptions;
17
+ export type KeysetPaginationOptions = import("./pagination/PaginationEngine.js").KeysetPaginationOptions;
18
+ export type AggregatePaginationOptions = import("./pagination/PaginationEngine.js").AggregatePaginationOptions;
19
+ export type OffsetPaginationResult = import("./pagination/PaginationEngine.js").OffsetPaginationResult;
20
+ export type KeysetPaginationResult = import("./pagination/PaginationEngine.js").KeysetPaginationResult;
21
+ export type AggregatePaginationResult = import("./pagination/PaginationEngine.js").AggregatePaginationResult;
22
+ import { Repository } from './Repository.js';
23
+ export { validationChainPlugin, blockIf, requireField, autoInject, immutableField, uniqueField } from "./plugins/validation-chain.plugin.js";
24
+ export { getFieldsForUser, getMongooseProjection, filterResponseData, createFieldPreset } from "./utils/field-selection.js";
25
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.js"],"names":[],"mappings":";;;;;;;;;;;;AAkEO,0EAEN;;+BA7CY,OAAO,kCAAkC,EAAE,gBAAgB;sCAC3D,OAAO,kCAAkC,EAAE,uBAAuB;sCAClE,OAAO,kCAAkC,EAAE,uBAAuB;yCAClE,OAAO,kCAAkC,EAAE,0BAA0B;qCACrE,OAAO,kCAAkC,EAAE,sBAAsB;qCACjE,OAAO,kCAAkC,EAAE,sBAAsB;wCACjE,OAAO,kCAAkC,EAAE,yBAAyB;2BAmCtD,iBAAiB"}