@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/plugins/index.d.ts
CHANGED
|
@@ -1,88 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
export
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
// Soft Delete Plugin
|
|
14
|
-
export interface SoftDeleteOptions {
|
|
15
|
-
deletedField?: string;
|
|
16
|
-
deletedByField?: string;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export function softDeletePlugin(options?: SoftDeleteOptions): Plugin;
|
|
20
|
-
|
|
21
|
-
// Timestamp Plugin
|
|
22
|
-
export interface TimestampOptions {
|
|
23
|
-
createdAtField?: string;
|
|
24
|
-
updatedAtField?: string;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
export function timestampPlugin(options?: TimestampOptions): Plugin;
|
|
28
|
-
|
|
29
|
-
// Audit Log Plugin
|
|
30
|
-
export interface Logger {
|
|
31
|
-
info(message: string, meta?: any): void;
|
|
32
|
-
error(message: string, meta?: any): void;
|
|
33
|
-
warn(message: string, meta?: any): void;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
export function auditLogPlugin(logger: Logger): Plugin;
|
|
37
|
-
|
|
38
|
-
// Validation Chain Plugin
|
|
39
|
-
export interface Validator {
|
|
40
|
-
name: string;
|
|
41
|
-
operations?: string[];
|
|
42
|
-
validate(context: RepositoryContext, repo: Repository<any>): void | Promise<void>;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
export interface ValidationChainOptions {
|
|
46
|
-
stopOnFirstError?: boolean;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
export function validationChainPlugin(
|
|
50
|
-
validators: Validator[],
|
|
51
|
-
options?: ValidationChainOptions
|
|
52
|
-
): Plugin;
|
|
53
|
-
|
|
54
|
-
// Validator helpers
|
|
55
|
-
export function blockIf(
|
|
56
|
-
name: string,
|
|
57
|
-
operations: string[],
|
|
58
|
-
condition: (context: RepositoryContext) => boolean,
|
|
59
|
-
errorMessage: string
|
|
60
|
-
): Validator;
|
|
61
|
-
|
|
62
|
-
export function requireField(field: string, operations?: string[]): Validator;
|
|
63
|
-
|
|
64
|
-
export function autoInject(
|
|
65
|
-
field: string,
|
|
66
|
-
getter: (context: RepositoryContext) => any,
|
|
67
|
-
operations?: string[]
|
|
68
|
-
): Validator;
|
|
69
|
-
|
|
70
|
-
export function immutableField(field: string): Validator;
|
|
71
|
-
|
|
72
|
-
export function uniqueField(field: string, errorMessage?: string): Validator;
|
|
73
|
-
|
|
74
|
-
// Method Registry Plugin
|
|
75
|
-
export function methodRegistryPlugin(): Plugin;
|
|
76
|
-
|
|
77
|
-
// Mongo Operations Plugin
|
|
78
|
-
export function mongoOperationsPlugin(): Plugin;
|
|
79
|
-
|
|
80
|
-
// Batch Operations Plugin
|
|
81
|
-
export function batchOperationsPlugin(): Plugin;
|
|
82
|
-
|
|
83
|
-
// Aggregate Helpers Plugin
|
|
84
|
-
export function aggregateHelpersPlugin(): Plugin;
|
|
85
|
-
|
|
86
|
-
// Subdocument Plugin
|
|
87
|
-
export function subdocumentPlugin(): Plugin;
|
|
88
|
-
|
|
1
|
+
export { fieldFilterPlugin } from "./field-filter.plugin.js";
|
|
2
|
+
export { timestampPlugin } from "./timestamp.plugin.js";
|
|
3
|
+
export { auditLogPlugin } from "./audit-log.plugin.js";
|
|
4
|
+
export { softDeletePlugin } from "./soft-delete.plugin.js";
|
|
5
|
+
export { methodRegistryPlugin } from "./method-registry.plugin.js";
|
|
6
|
+
export { mongoOperationsPlugin } from "./mongo-operations.plugin.js";
|
|
7
|
+
export { batchOperationsPlugin } from "./batch-operations.plugin.js";
|
|
8
|
+
export { aggregateHelpersPlugin } from "./aggregate-helpers.plugin.js";
|
|
9
|
+
export { subdocumentPlugin } from "./subdocument.plugin.js";
|
|
10
|
+
export { validationChainPlugin, blockIf, requireField, autoInject, immutableField, uniqueField } from "./validation-chain.plugin.js";
|
|
11
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/plugins/index.js"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"method-registry.plugin.d.ts","sourceRoot":"","sources":["../../src/plugins/method-registry.plugin.js"],"names":[],"mappings":"AAkDO,4CAuFL"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mongo-operations.plugin.d.ts","sourceRoot":"","sources":["../../src/plugins/mongo-operations.plugin.js"],"names":[],"mappings":"AA0DO,6CAgQL;;uBAzTW,OAAO,aAAa,EAAE,QAAQ"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"soft-delete.plugin.d.ts","sourceRoot":"","sources":["../../src/plugins/soft-delete.plugin.js"],"names":[],"mappings":"AAAO;;;EA2CL"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"subdocument.plugin.d.ts","sourceRoot":"","sources":["../../src/plugins/subdocument.plugin.js"],"names":[],"mappings":"AAOO;;;EAwDL"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"timestamp.plugin.d.ts","sourceRoot":"","sources":["../../src/plugins/timestamp.plugin.js"],"names":[],"mappings":"AAAO;;;EAgBL"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
export function validationChainPlugin(validators?: any[], options?: {}): {
|
|
2
|
+
name: string;
|
|
3
|
+
apply(repo: any): void;
|
|
4
|
+
};
|
|
5
|
+
export function blockIf(name: string, operations: string[], condition: Function, errorMessage: string): {
|
|
6
|
+
name: string;
|
|
7
|
+
operations: string[];
|
|
8
|
+
validate: (context: any) => void;
|
|
9
|
+
};
|
|
10
|
+
export function requireField(field: any, operations?: string[]): {
|
|
11
|
+
name: string;
|
|
12
|
+
operations: string[];
|
|
13
|
+
validate: (context: any) => void;
|
|
14
|
+
};
|
|
15
|
+
export function autoInject(field: any, getter: any, operations?: string[]): {
|
|
16
|
+
name: string;
|
|
17
|
+
operations: string[];
|
|
18
|
+
validate: (context: any) => void;
|
|
19
|
+
};
|
|
20
|
+
export function immutableField(field: any): {
|
|
21
|
+
name: string;
|
|
22
|
+
operations: string[];
|
|
23
|
+
validate: (context: any) => void;
|
|
24
|
+
};
|
|
25
|
+
export function uniqueField(field: any, errorMessage: any): {
|
|
26
|
+
name: string;
|
|
27
|
+
operations: string[];
|
|
28
|
+
validate: (context: any, repo: any) => Promise<void>;
|
|
29
|
+
};
|
|
30
|
+
export default validationChainPlugin;
|
|
31
|
+
//# sourceMappingURL=validation-chain.plugin.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validation-chain.plugin.d.ts","sourceRoot":"","sources":["../../src/plugins/validation-chain.plugin.js"],"names":[],"mappings":"AAEO;;;EAsEN;AAUM,8BANI,MAAM,cACN,MAAM,EAAE,qCAER,MAAM;;;;EAWf;AAEK;;;;EAQL;AAEK;;;;EAWL;AAEK;;;;EAQL;AAEK;;;;EAiBL"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Creates an error with HTTP status code
|
|
3
|
+
*
|
|
4
|
+
* @param {number} status - HTTP status code
|
|
5
|
+
* @param {string} message - Error message
|
|
6
|
+
* @returns {Error & {status: number}} Error with status property
|
|
7
|
+
*/
|
|
8
|
+
export function createError(status: number, message: string): Error & {
|
|
9
|
+
status: number;
|
|
10
|
+
};
|
|
11
|
+
//# sourceMappingURL=error.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"error.d.ts","sourceRoot":"","sources":["../../src/utils/error.js"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,oCAJW,MAAM,WACN,MAAM,GACJ,KAAK,GAAG;IAAC,MAAM,EAAE,MAAM,CAAA;CAAC,CAMpC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export function getFieldsForUser(user: any, preset: {
|
|
2
|
+
public: string[];
|
|
3
|
+
authenticated: string[];
|
|
4
|
+
admin: string[];
|
|
5
|
+
}): string[];
|
|
6
|
+
export function getMongooseProjection(user: any, preset: any): string;
|
|
7
|
+
export function filterResponseData(data: any | any[], preset: any, user?: any): any | any[];
|
|
8
|
+
export function createFieldPreset(config: any): any;
|
|
9
|
+
//# sourceMappingURL=field-selection.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"field-selection.d.ts","sourceRoot":"","sources":["../../src/utils/field-selection.js"],"names":[],"mappings":"AA+BO,oDALJ;IAAyB,MAAM,EAAvB,MAAM,EAAE;IACS,aAAa,EAA9B,MAAM,EAAE;IACS,KAAK,EAAtB,MAAM,EAAE;CAChB,GAAU,MAAM,EAAE,CAuBpB;AAaM,+DANM,MAAM,CASlB;AAsBM,yCAVI,WAAY,4BAGV,WAAY,CAiBxB;AAiDM,oDAMN"}
|
package/types/utils/index.d.ts
CHANGED
|
@@ -1,24 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
export interface User {
|
|
4
|
-
roles?: string | string[];
|
|
5
|
-
[key: string]: any;
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
// Field Selection utilities
|
|
9
|
-
export function getFieldsForUser(user: User | null, preset: FieldPreset): string[];
|
|
10
|
-
|
|
11
|
-
export function getMongooseProjection(user: User | null, preset: FieldPreset): string;
|
|
12
|
-
|
|
13
|
-
export function filterResponseData<T>(
|
|
14
|
-
data: T | T[],
|
|
15
|
-
preset: FieldPreset,
|
|
16
|
-
user?: User | null
|
|
17
|
-
): T | T[];
|
|
18
|
-
|
|
19
|
-
export function createFieldPreset(config: {
|
|
20
|
-
public?: string[];
|
|
21
|
-
authenticated?: string[];
|
|
22
|
-
admin?: string[];
|
|
23
|
-
}): FieldPreset;
|
|
24
|
-
|
|
1
|
+
export { getFieldsForUser, getMongooseProjection, filterResponseData, createFieldPreset } from "./field-selection.js";
|
|
2
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.js"],"names":[],"mappings":""}
|