@classytic/mongokit 1.0.2 → 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.
- package/README.md +562 -155
- package/package.json +17 -10
- package/src/Repository.js +296 -225
- package/src/actions/aggregate.js +266 -191
- package/src/actions/create.js +47 -47
- package/src/actions/delete.js +88 -88
- package/src/actions/index.js +11 -11
- package/src/actions/read.js +176 -144
- package/src/actions/update.js +144 -144
- package/src/hooks/lifecycle.js +146 -146
- package/src/index.js +71 -60
- package/src/pagination/PaginationEngine.js +348 -0
- package/src/pagination/utils/cursor.js +119 -0
- package/src/pagination/utils/filter.js +42 -0
- package/src/pagination/utils/limits.js +82 -0
- package/src/pagination/utils/sort.js +101 -0
- package/src/plugins/aggregate-helpers.plugin.js +71 -71
- package/src/plugins/audit-log.plugin.js +60 -60
- package/src/plugins/batch-operations.plugin.js +66 -66
- package/src/plugins/field-filter.plugin.js +27 -27
- package/src/plugins/index.js +19 -19
- package/src/plugins/method-registry.plugin.js +140 -140
- package/src/plugins/mongo-operations.plugin.js +317 -313
- package/src/plugins/soft-delete.plugin.js +46 -46
- package/src/plugins/subdocument.plugin.js +66 -66
- package/src/plugins/timestamp.plugin.js +19 -19
- package/src/plugins/validation-chain.plugin.js +145 -145
- package/src/types.d.ts +87 -0
- package/src/utils/error.js +12 -0
- package/src/utils/field-selection.js +156 -156
- package/src/utils/index.js +12 -12
- package/types/Repository.d.ts +95 -0
- package/types/Repository.d.ts.map +1 -0
- package/types/actions/aggregate.d.ts +112 -0
- package/types/actions/aggregate.d.ts.map +1 -0
- package/types/actions/create.d.ts +21 -0
- package/types/actions/create.d.ts.map +1 -0
- package/types/actions/delete.d.ts +37 -0
- package/types/actions/delete.d.ts.map +1 -0
- package/types/actions/index.d.ts +6 -121
- package/types/actions/index.d.ts.map +1 -0
- package/types/actions/read.d.ts +135 -0
- package/types/actions/read.d.ts.map +1 -0
- package/types/actions/update.d.ts +58 -0
- package/types/actions/update.d.ts.map +1 -0
- package/types/hooks/lifecycle.d.ts +44 -0
- package/types/hooks/lifecycle.d.ts.map +1 -0
- package/types/index.d.ts +25 -104
- package/types/index.d.ts.map +1 -0
- package/types/pagination/PaginationEngine.d.ts +386 -0
- package/types/pagination/PaginationEngine.d.ts.map +1 -0
- package/types/pagination/utils/cursor.d.ts +40 -0
- package/types/pagination/utils/cursor.d.ts.map +1 -0
- package/types/pagination/utils/filter.d.ts +28 -0
- package/types/pagination/utils/filter.d.ts.map +1 -0
- package/types/pagination/utils/limits.d.ts +64 -0
- package/types/pagination/utils/limits.d.ts.map +1 -0
- package/types/pagination/utils/sort.d.ts +41 -0
- package/types/pagination/utils/sort.d.ts.map +1 -0
- package/types/plugins/aggregate-helpers.plugin.d.ts +6 -0
- package/types/plugins/aggregate-helpers.plugin.d.ts.map +1 -0
- package/types/plugins/audit-log.plugin.d.ts +6 -0
- package/types/plugins/audit-log.plugin.d.ts.map +1 -0
- package/types/plugins/batch-operations.plugin.d.ts +6 -0
- package/types/plugins/batch-operations.plugin.d.ts.map +1 -0
- package/types/plugins/field-filter.plugin.d.ts +6 -0
- package/types/plugins/field-filter.plugin.d.ts.map +1 -0
- package/types/plugins/index.d.ts +11 -88
- package/types/plugins/index.d.ts.map +1 -0
- package/types/plugins/method-registry.plugin.d.ts +3 -0
- package/types/plugins/method-registry.plugin.d.ts.map +1 -0
- package/types/plugins/mongo-operations.plugin.d.ts +4 -0
- package/types/plugins/mongo-operations.plugin.d.ts.map +1 -0
- package/types/plugins/soft-delete.plugin.d.ts +6 -0
- package/types/plugins/soft-delete.plugin.d.ts.map +1 -0
- package/types/plugins/subdocument.plugin.d.ts +6 -0
- package/types/plugins/subdocument.plugin.d.ts.map +1 -0
- package/types/plugins/timestamp.plugin.d.ts +6 -0
- package/types/plugins/timestamp.plugin.d.ts.map +1 -0
- package/types/plugins/validation-chain.plugin.d.ts +31 -0
- package/types/plugins/validation-chain.plugin.d.ts.map +1 -0
- package/types/utils/error.d.ts +11 -0
- package/types/utils/error.d.ts.map +1 -0
- package/types/utils/field-selection.d.ts +9 -0
- package/types/utils/field-selection.d.ts.map +1 -0
- package/types/utils/index.d.ts +2 -24
- package/types/utils/index.d.ts.map +1 -0
package/types/actions/index.d.ts
CHANGED
|
@@ -1,121 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
type QueryFilterV8<T> = import('mongoose').FilterQuery<T>;
|
|
8
|
-
type CompatibleQueryFilter<T> = QueryFilterV9<T> | QueryFilterV8<T>;
|
|
9
|
-
|
|
10
|
-
export interface ActionOptions {
|
|
11
|
-
session?: ClientSession;
|
|
12
|
-
updatePipeline?: boolean;
|
|
13
|
-
[key: string]: any;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
// Create actions
|
|
17
|
-
export function create<T extends Document>(
|
|
18
|
-
Model: Model<T>,
|
|
19
|
-
data: Partial<T>,
|
|
20
|
-
options?: ActionOptions
|
|
21
|
-
): Promise<T>;
|
|
22
|
-
|
|
23
|
-
export function createMany<T extends Document>(
|
|
24
|
-
Model: Model<T>,
|
|
25
|
-
dataArray: Partial<T>[],
|
|
26
|
-
options?: ActionOptions
|
|
27
|
-
): Promise<T[]>;
|
|
28
|
-
|
|
29
|
-
export function createDefault<T extends Document>(
|
|
30
|
-
Model: Model<T>,
|
|
31
|
-
overrides?: Partial<T>,
|
|
32
|
-
options?: ActionOptions
|
|
33
|
-
): Promise<T>;
|
|
34
|
-
|
|
35
|
-
export function upsert<T extends Document>(
|
|
36
|
-
Model: Model<T>,
|
|
37
|
-
query: CompatibleQueryFilter<T>,
|
|
38
|
-
data: Partial<T>,
|
|
39
|
-
options?: ActionOptions
|
|
40
|
-
): Promise<T>;
|
|
41
|
-
|
|
42
|
-
// Read actions
|
|
43
|
-
export function getById<T extends Document>(
|
|
44
|
-
Model: Model<T>,
|
|
45
|
-
id: string,
|
|
46
|
-
options?: ActionOptions
|
|
47
|
-
): Promise<T | null>;
|
|
48
|
-
|
|
49
|
-
export function getByQuery<T extends Document>(
|
|
50
|
-
Model: Model<T>,
|
|
51
|
-
query: CompatibleQueryFilter<T>,
|
|
52
|
-
options?: ActionOptions
|
|
53
|
-
): Promise<T | null>;
|
|
54
|
-
|
|
55
|
-
export function getOrCreate<T extends Document>(
|
|
56
|
-
Model: Model<T>,
|
|
57
|
-
query: CompatibleQueryFilter<T>,
|
|
58
|
-
createData: Partial<T>,
|
|
59
|
-
options?: ActionOptions
|
|
60
|
-
): Promise<T>;
|
|
61
|
-
|
|
62
|
-
export function count<T extends Document>(
|
|
63
|
-
Model: Model<T>,
|
|
64
|
-
query?: CompatibleQueryFilter<T>,
|
|
65
|
-
options?: ActionOptions
|
|
66
|
-
): Promise<number>;
|
|
67
|
-
|
|
68
|
-
export function exists<T extends Document>(
|
|
69
|
-
Model: Model<T>,
|
|
70
|
-
query: CompatibleQueryFilter<T>,
|
|
71
|
-
options?: ActionOptions
|
|
72
|
-
): Promise<boolean>;
|
|
73
|
-
|
|
74
|
-
// Update actions
|
|
75
|
-
export function update<T extends Document>(
|
|
76
|
-
Model: Model<T>,
|
|
77
|
-
id: string,
|
|
78
|
-
data: UpdateQuery<T>,
|
|
79
|
-
options?: ActionOptions
|
|
80
|
-
): Promise<T | null>;
|
|
81
|
-
|
|
82
|
-
export function updateMany<T extends Document>(
|
|
83
|
-
Model: Model<T>,
|
|
84
|
-
query: CompatibleQueryFilter<T>,
|
|
85
|
-
data: UpdateQuery<T>,
|
|
86
|
-
options?: ActionOptions
|
|
87
|
-
): Promise<any>;
|
|
88
|
-
|
|
89
|
-
// Delete actions
|
|
90
|
-
export function deleteById<T extends Document>(
|
|
91
|
-
Model: Model<T>,
|
|
92
|
-
id: string,
|
|
93
|
-
options?: ActionOptions
|
|
94
|
-
): Promise<T | null>;
|
|
95
|
-
|
|
96
|
-
export function deleteMany<T extends Document>(
|
|
97
|
-
Model: Model<T>,
|
|
98
|
-
query: CompatibleQueryFilter<T>,
|
|
99
|
-
options?: ActionOptions
|
|
100
|
-
): Promise<any>;
|
|
101
|
-
|
|
102
|
-
// Aggregate actions
|
|
103
|
-
export function aggregate<T extends Document>(
|
|
104
|
-
Model: Model<T>,
|
|
105
|
-
pipeline: any[],
|
|
106
|
-
options?: ActionOptions
|
|
107
|
-
): Promise<any[]>;
|
|
108
|
-
|
|
109
|
-
export function aggregatePaginate<T extends Document>(
|
|
110
|
-
Model: Model<T>,
|
|
111
|
-
pipeline: any[],
|
|
112
|
-
options?: ActionOptions
|
|
113
|
-
): Promise<any>;
|
|
114
|
-
|
|
115
|
-
export function distinct<T extends Document>(
|
|
116
|
-
Model: Model<T>,
|
|
117
|
-
field: string,
|
|
118
|
-
query?: CompatibleQueryFilter<T>,
|
|
119
|
-
options?: ActionOptions
|
|
120
|
-
): Promise<any[]>;
|
|
121
|
-
|
|
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,104 +1,25 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
export
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
export
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
filters?: Record<string, any>;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
export interface RepositoryContext {
|
|
30
|
-
operation: string;
|
|
31
|
-
model: string;
|
|
32
|
-
data?: any;
|
|
33
|
-
dataArray?: any[];
|
|
34
|
-
id?: string;
|
|
35
|
-
query?: any;
|
|
36
|
-
queryParams?: QueryParams;
|
|
37
|
-
context?: any;
|
|
38
|
-
user?: any;
|
|
39
|
-
organizationId?: string;
|
|
40
|
-
[key: string]: any;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
export type EventListener = (data: any) => void | Promise<void>;
|
|
44
|
-
|
|
45
|
-
export interface Plugin {
|
|
46
|
-
name: string;
|
|
47
|
-
apply(repository: Repository<any>): void;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
export type PluginFactory = (options?: any) => Plugin;
|
|
51
|
-
|
|
52
|
-
export class Repository<T extends Document> {
|
|
53
|
-
Model: Model<T>;
|
|
54
|
-
model: string;
|
|
55
|
-
protected _hooks: Map<string, EventListener[]>;
|
|
56
|
-
|
|
57
|
-
constructor(Model: Model<T>, plugins?: (Plugin | PluginFactory)[]);
|
|
58
|
-
|
|
59
|
-
// Plugin system
|
|
60
|
-
use(plugin: Plugin | PluginFactory): this;
|
|
61
|
-
on(event: string, listener: EventListener): this;
|
|
62
|
-
emit(event: string, data: any): void;
|
|
63
|
-
|
|
64
|
-
// CRUD operations
|
|
65
|
-
create(data: Partial<T>, options?: RepositoryOptions): Promise<T>;
|
|
66
|
-
createMany(dataArray: Partial<T>[], options?: RepositoryOptions): Promise<T[]>;
|
|
67
|
-
|
|
68
|
-
getById(id: string, options?: RepositoryOptions): Promise<T | null>;
|
|
69
|
-
getByQuery(query: CompatibleQueryFilter<T>, options?: RepositoryOptions): Promise<T | null>;
|
|
70
|
-
getAll(queryParams?: QueryParams, options?: RepositoryOptions): Promise<PaginateResult<T>>;
|
|
71
|
-
getOrCreate(query: CompatibleQueryFilter<T>, createData: Partial<T>, options?: RepositoryOptions): Promise<T>;
|
|
72
|
-
|
|
73
|
-
count(query?: CompatibleQueryFilter<T>, options?: RepositoryOptions): Promise<number>;
|
|
74
|
-
exists(query: CompatibleQueryFilter<T>, options?: RepositoryOptions): Promise<boolean>;
|
|
75
|
-
|
|
76
|
-
update(id: string, data: UpdateQuery<T>, options?: RepositoryOptions): Promise<T | null>;
|
|
77
|
-
delete(id: string, options?: RepositoryOptions): Promise<T | null>;
|
|
78
|
-
|
|
79
|
-
// Aggregation
|
|
80
|
-
aggregate(pipeline: any[], options?: AggregateOptions): Promise<any[]>;
|
|
81
|
-
aggregatePaginate(pipeline: any[], options?: PaginateOptions): Promise<any>;
|
|
82
|
-
distinct(field: string, query?: CompatibleQueryFilter<T>, options?: RepositoryOptions): Promise<any[]>;
|
|
83
|
-
|
|
84
|
-
// Transaction support
|
|
85
|
-
withTransaction<R>(callback: (session: ClientSession) => Promise<R>): Promise<R>;
|
|
86
|
-
|
|
87
|
-
// Internal methods
|
|
88
|
-
protected _executeQuery(buildQuery: (model: Model<T>) => Promise<any>): Promise<any>;
|
|
89
|
-
protected _buildContext(operation: string, options: any): Promise<RepositoryContext>;
|
|
90
|
-
protected _parseSort(sort: string | object): object;
|
|
91
|
-
protected _parsePopulate(populate: string | string[] | any): any[];
|
|
92
|
-
protected _handleError(error: any): Error;
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
export function createRepository<T extends Document>(
|
|
96
|
-
Model: Model<T>,
|
|
97
|
-
plugins?: (Plugin | PluginFactory)[]
|
|
98
|
-
): Repository<T>;
|
|
99
|
-
|
|
100
|
-
// Plugin exports
|
|
101
|
-
export * from './plugins/index.js';
|
|
102
|
-
export * from './utils/index.js';
|
|
103
|
-
export * as actions from './actions/index.js';
|
|
104
|
-
|
|
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"}
|