@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.
Files changed (87) hide show
  1. package/README.md +562 -155
  2. package/package.json +17 -10
  3. package/src/Repository.js +296 -225
  4. package/src/actions/aggregate.js +266 -191
  5. package/src/actions/create.js +47 -47
  6. package/src/actions/delete.js +88 -88
  7. package/src/actions/index.js +11 -11
  8. package/src/actions/read.js +176 -144
  9. package/src/actions/update.js +144 -144
  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 -121
  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 -104
  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,88 +1,11 @@
1
- import { Plugin, PluginFactory, Repository, RepositoryContext } from '../index.js';
2
- import { Document } from 'mongoose';
3
-
4
- // Field Filter Plugin
5
- export interface FieldPreset {
6
- public?: string[];
7
- authenticated?: string[];
8
- admin?: string[];
9
- }
10
-
11
- export function fieldFilterPlugin(fieldPreset: FieldPreset): Plugin;
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,3 @@
1
+ export function methodRegistryPlugin(): any;
2
+ export default methodRegistryPlugin;
3
+ //# sourceMappingURL=method-registry.plugin.d.ts.map
@@ -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,4 @@
1
+ export function mongoOperationsPlugin(): any;
2
+ export default mongoOperationsPlugin;
3
+ export type ObjectId = import("../types.js").ObjectId;
4
+ //# sourceMappingURL=mongo-operations.plugin.d.ts.map
@@ -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,6 @@
1
+ export function softDeletePlugin(options?: {}): {
2
+ name: string;
3
+ apply(repo: any): void;
4
+ };
5
+ export default softDeletePlugin;
6
+ //# sourceMappingURL=soft-delete.plugin.d.ts.map
@@ -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,6 @@
1
+ export function subdocumentPlugin(): {
2
+ name: string;
3
+ apply(repo: any): void;
4
+ };
5
+ export default subdocumentPlugin;
6
+ //# sourceMappingURL=subdocument.plugin.d.ts.map
@@ -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,6 @@
1
+ export function timestampPlugin(): {
2
+ name: string;
3
+ apply(repo: any): void;
4
+ };
5
+ export default timestampPlugin;
6
+ //# sourceMappingURL=timestamp.plugin.d.ts.map
@@ -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"}
@@ -1,24 +1,2 @@
1
- import { FieldPreset } from '../plugins/index.js';
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":""}