ts-patch-mongoose 1.0.1

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 (95) hide show
  1. package/.eslintignore +4 -0
  2. package/.eslintrc +91 -0
  3. package/.swcrc +21 -0
  4. package/LICENSE +21 -0
  5. package/README.md +66 -0
  6. package/dist/cjs/em.d.ts +7 -0
  7. package/dist/cjs/em.d.ts.map +1 -0
  8. package/dist/cjs/em.js +9 -0
  9. package/dist/cjs/em.js.map +1 -0
  10. package/dist/cjs/interfaces/IContext.d.ts +12 -0
  11. package/dist/cjs/interfaces/IContext.d.ts.map +1 -0
  12. package/dist/cjs/interfaces/IContext.js +3 -0
  13. package/dist/cjs/interfaces/IContext.js.map +1 -0
  14. package/dist/cjs/interfaces/IHistory.d.ts +13 -0
  15. package/dist/cjs/interfaces/IHistory.d.ts.map +1 -0
  16. package/dist/cjs/interfaces/IHistory.js +3 -0
  17. package/dist/cjs/interfaces/IHistory.js.map +1 -0
  18. package/dist/cjs/interfaces/IHookContext.d.ts +8 -0
  19. package/dist/cjs/interfaces/IHookContext.d.ts.map +1 -0
  20. package/dist/cjs/interfaces/IHookContext.js +3 -0
  21. package/dist/cjs/interfaces/IHookContext.js.map +1 -0
  22. package/dist/cjs/interfaces/IPluginOptions.d.ts +13 -0
  23. package/dist/cjs/interfaces/IPluginOptions.d.ts.map +1 -0
  24. package/dist/cjs/interfaces/IPluginOptions.js +3 -0
  25. package/dist/cjs/interfaces/IPluginOptions.js.map +1 -0
  26. package/dist/cjs/models/History.d.ts +29 -0
  27. package/dist/cjs/models/History.d.ts.map +1 -0
  28. package/dist/cjs/models/History.js +36 -0
  29. package/dist/cjs/models/History.js.map +1 -0
  30. package/dist/cjs/plugin.d.ts +45 -0
  31. package/dist/cjs/plugin.d.ts.map +1 -0
  32. package/dist/cjs/plugin.js +224 -0
  33. package/dist/cjs/plugin.js.map +1 -0
  34. package/dist/esm/em.d.ts +7 -0
  35. package/dist/esm/em.d.ts.map +1 -0
  36. package/dist/esm/em.js +6 -0
  37. package/dist/esm/em.js.map +1 -0
  38. package/dist/esm/interfaces/IContext.d.ts +12 -0
  39. package/dist/esm/interfaces/IContext.d.ts.map +1 -0
  40. package/dist/esm/interfaces/IContext.js +2 -0
  41. package/dist/esm/interfaces/IContext.js.map +1 -0
  42. package/dist/esm/interfaces/IHistory.d.ts +13 -0
  43. package/dist/esm/interfaces/IHistory.d.ts.map +1 -0
  44. package/dist/esm/interfaces/IHistory.js +2 -0
  45. package/dist/esm/interfaces/IHistory.js.map +1 -0
  46. package/dist/esm/interfaces/IHookContext.d.ts +8 -0
  47. package/dist/esm/interfaces/IHookContext.d.ts.map +1 -0
  48. package/dist/esm/interfaces/IHookContext.js +2 -0
  49. package/dist/esm/interfaces/IHookContext.js.map +1 -0
  50. package/dist/esm/interfaces/IPluginOptions.d.ts +13 -0
  51. package/dist/esm/interfaces/IPluginOptions.d.ts.map +1 -0
  52. package/dist/esm/interfaces/IPluginOptions.js +2 -0
  53. package/dist/esm/interfaces/IPluginOptions.js.map +1 -0
  54. package/dist/esm/models/History.d.ts +29 -0
  55. package/dist/esm/models/History.d.ts.map +1 -0
  56. package/dist/esm/models/History.js +34 -0
  57. package/dist/esm/models/History.js.map +1 -0
  58. package/dist/esm/plugin.d.ts +45 -0
  59. package/dist/esm/plugin.d.ts.map +1 -0
  60. package/dist/esm/plugin.js +219 -0
  61. package/dist/esm/plugin.js.map +1 -0
  62. package/dist/types/em.d.ts +7 -0
  63. package/dist/types/em.d.ts.map +1 -0
  64. package/dist/types/interfaces/IContext.d.ts +12 -0
  65. package/dist/types/interfaces/IContext.d.ts.map +1 -0
  66. package/dist/types/interfaces/IHistory.d.ts +13 -0
  67. package/dist/types/interfaces/IHistory.d.ts.map +1 -0
  68. package/dist/types/interfaces/IHookContext.d.ts +8 -0
  69. package/dist/types/interfaces/IHookContext.d.ts.map +1 -0
  70. package/dist/types/interfaces/IPluginOptions.d.ts +13 -0
  71. package/dist/types/interfaces/IPluginOptions.d.ts.map +1 -0
  72. package/dist/types/models/History.d.ts +29 -0
  73. package/dist/types/models/History.d.ts.map +1 -0
  74. package/dist/types/plugin.d.ts +45 -0
  75. package/dist/types/plugin.d.ts.map +1 -0
  76. package/jest-mongodb-config.ts +10 -0
  77. package/jest.config.ts +35 -0
  78. package/package.json +101 -0
  79. package/src/em.ts +6 -0
  80. package/src/interfaces/IContext.ts +13 -0
  81. package/src/interfaces/IHistory.ts +14 -0
  82. package/src/interfaces/IHookContext.ts +6 -0
  83. package/src/interfaces/IPluginOptions.ts +14 -0
  84. package/src/models/History.ts +39 -0
  85. package/src/modules/omit-deep.d.ts +3 -0
  86. package/src/modules/power-assign.d.ts +3 -0
  87. package/src/plugin.ts +267 -0
  88. package/tests/constants/events.ts +3 -0
  89. package/tests/em.test.ts +16 -0
  90. package/tests/interfaces/IUser.ts +8 -0
  91. package/tests/models/User.ts +29 -0
  92. package/tests/mongose.test.ts +28 -0
  93. package/tests/plugin.test.ts +243 -0
  94. package/tests/utils/filesystem.ts +13 -0
  95. package/tsconfig.json +44 -0
package/.eslintignore ADDED
@@ -0,0 +1,4 @@
1
+ node_modules
2
+ dist
3
+ coverage
4
+ .env
package/.eslintrc ADDED
@@ -0,0 +1,91 @@
1
+ {
2
+ "root": true,
3
+ "env": {
4
+ "commonjs": true,
5
+ "es2021": true,
6
+ "node": true,
7
+ "jest": true
8
+ },
9
+ "parser": "@typescript-eslint/parser",
10
+ "plugins": [
11
+ "@typescript-eslint",
12
+ "jest",
13
+ "jest-formatting"
14
+ ],
15
+ "extends": [
16
+ "standard",
17
+ "eslint:recommended",
18
+ "plugin:@typescript-eslint/eslint-recommended",
19
+ "plugin:@typescript-eslint/recommended"
20
+ ],
21
+ "globals": {
22
+ "Atomics": "readonly",
23
+ "SharedArrayBuffer": "readonly"
24
+ },
25
+ "parserOptions": {
26
+ "ecmaVersion": 2021,
27
+ "sourceType": "module"
28
+ },
29
+ "rules": {
30
+ "@typescript-eslint/array-type": "error",
31
+ "@typescript-eslint/consistent-type-imports": "error",
32
+ "@typescript-eslint/method-signature-style": "error",
33
+ "@typescript-eslint/consistent-indexed-object-style": "error",
34
+ "@typescript-eslint/sort-type-union-intersection-members": "error",
35
+ "indent": [
36
+ "error",
37
+ 2
38
+ ],
39
+ "arrow-parens": [
40
+ "error"
41
+ ],
42
+ "linebreak-style": [
43
+ "error",
44
+ "unix"
45
+ ],
46
+ "quotes": [
47
+ "error",
48
+ "single"
49
+ ],
50
+ "semi": [
51
+ "error",
52
+ "never"
53
+ ]
54
+ },
55
+ "overrides": [
56
+ {
57
+ "files": [
58
+ "tests/**/*.test.ts"
59
+ ],
60
+ "extends": [
61
+ "plugin:jest/style",
62
+ "plugin:jest/recommended",
63
+ "plugin:jest-formatting/recommended"
64
+ ]
65
+ },
66
+ {
67
+ "parserOptions": {
68
+ "project": [
69
+ "tsconfig.json"
70
+ ]
71
+ },
72
+ "files": [
73
+ "src/**/*.ts"
74
+ ],
75
+ "extends": [
76
+ "plugin:@typescript-eslint/recommended-requiring-type-checking",
77
+ "plugin:@typescript-eslint/strict"
78
+ ],
79
+ "rules": {
80
+ "@typescript-eslint/consistent-type-exports": "error",
81
+ "@typescript-eslint/explicit-function-return-type": "error",
82
+ "@typescript-eslint/explicit-module-boundary-types": "error",
83
+ "@typescript-eslint/member-ordering": "error",
84
+ "@typescript-eslint/typedef": "error",
85
+ "@typescript-eslint/prefer-enum-initializers": "error",
86
+ "@typescript-eslint/require-array-sort-compare": "error",
87
+ "@typescript-eslint/no-redundant-type-constituents": "error"
88
+ }
89
+ }
90
+ ]
91
+ }
package/.swcrc ADDED
@@ -0,0 +1,21 @@
1
+ {
2
+ "jsc": {
3
+ "parser": {
4
+ "syntax": "typescript",
5
+ "decorators": true,
6
+ "dynamicImport": true
7
+ },
8
+ "target": "es2021",
9
+ "keepClassNames": true,
10
+ "loose": true
11
+ },
12
+ "env": {
13
+ "targets": {
14
+ "node": 16
15
+ }
16
+ },
17
+ "module": {
18
+ "type": "commonjs"
19
+ },
20
+ "sourceMaps": true
21
+ }
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2022 Alex Eagle
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,66 @@
1
+ # ts-patch-mongoose
2
+
3
+ Patch history & events for mongoose models
4
+
5
+ [![npm](https://img.shields.io/npm/v/ts-patch-mongoose)](https://www.npmjs.com/package/ts-patch-mongoose)
6
+ [![npm](https://img.shields.io/npm/dt/ts-patch-mongoose)](https://www.npmjs.com/package/ts-patch-mongoose)
7
+ [![GitHub](https://img.shields.io/github/license/ilovepixelart/ts-patch-mongoose)](https://github.com/ilovepixelart/ts-patch-mongoose/blob/main/LICENSE)
8
+ \
9
+ [![Coverage](https://sonarcloud.io/api/project_badges/measure?project=ilovepixelart_ts-patch-mongoose&metric=coverage)](https://sonarcloud.io/summary/new_code?id=ilovepixelart_ts-patch-mongoose)
10
+ [![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=ilovepixelart_ts-patch-mongoose&metric=alert_status)](https://sonarcloud.io/summary/new_code?id=ilovepixelart_ts-patch-mongoose)
11
+ \
12
+ [![Reliability Rating](https://sonarcloud.io/api/project_badges/measure?project=ilovepixelart_ts-patch-mongoose&metric=reliability_rating)](https://sonarcloud.io/summary/new_code?id=ilovepixelart_ts-patch-mongoose)
13
+ [![Maintainability Rating](https://sonarcloud.io/api/project_badges/measure?project=ilovepixelart_ts-patch-mongoose&metric=sqale_rating)](https://sonarcloud.io/summary/new_code?id=ilovepixelart_ts-patch-mongoose)
14
+ [![Security Rating](https://sonarcloud.io/api/project_badges/measure?project=ilovepixelart_ts-patch-mongoose&metric=security_rating)](https://sonarcloud.io/summary/new_code?id=ilovepixelart_ts-patch-mongoose)
15
+
16
+ [![npm](https://nodei.co/npm/ts-patch-mongoose.png)](https://www.npmjs.com/package/ts-patch-mongoose)
17
+
18
+ ## Installation
19
+
20
+ ```bash
21
+ npm install ts-patch-mongoose
22
+ ```
23
+
24
+ ## Usage example of plugin
25
+
26
+ ```typescript
27
+ import { Schema, model } from 'mongoose'
28
+
29
+ import type IUser from '../interfaces/IUser'
30
+
31
+ import { patchHistoryPlugin } from 'ts-patch-mongoose'
32
+
33
+ import { USER_CREATED_EVENT, USER_DELETED_EVENT, USER_UPDATED_EVENT } from '../constants/events'
34
+
35
+ const UserSchema = new Schema<IUser>({
36
+ name: {
37
+ type: String,
38
+ required: true
39
+ },
40
+ role: {
41
+ type: String,
42
+ required: true
43
+ }
44
+ }, { timestamps: true })
45
+
46
+ UserSchema.plugin(patchHistoryPlugin, {
47
+ eventCreated: USER_CREATED_EVENT,
48
+ eventUpdated: USER_UPDATED_EVENT,
49
+ eventDeleted: USER_DELETED_EVENT,
50
+ omit: ['__v', 'role', 'createdAt', 'updatedAt']
51
+ })
52
+
53
+ const User = model('User', UserSchema)
54
+
55
+ export default User
56
+ ```
57
+
58
+ ## Somewhere in your code you can subscribe to events
59
+
60
+ ```typescript
61
+ import { patchEventEmitter } from 'ts-patch-mongoose'
62
+
63
+ patchEventEmitter.on(USER_CREATED_EVENT, ({ doc }) => {
64
+ console.log('User created', doc)
65
+ })
66
+ ```
@@ -0,0 +1,7 @@
1
+ /// <reference types="node" />
2
+ import EventEmitter from 'events';
3
+ declare class PatchEventEmitter extends EventEmitter {
4
+ }
5
+ declare const em: PatchEventEmitter;
6
+ export default em;
7
+ //# sourceMappingURL=em.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"em.d.ts","sourceRoot":"","sources":["../../src/em.ts"],"names":[],"mappings":";AAAA,OAAO,YAAY,MAAM,QAAQ,CAAA;AAEjC,cAAM,iBAAkB,SAAQ,YAAY;CAAG;AAC/C,QAAA,MAAM,EAAE,mBAA0B,CAAA;AAElC,eAAe,EAAE,CAAA"}
package/dist/cjs/em.js ADDED
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ const events_1 = tslib_1.__importDefault(require("events"));
5
+ class PatchEventEmitter extends events_1.default {
6
+ }
7
+ const em = new PatchEventEmitter();
8
+ exports.default = em;
9
+ //# sourceMappingURL=em.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"em.js","sourceRoot":"","sources":["../../src/em.ts"],"names":[],"mappings":";;;AAAA,4DAAiC;AAEjC,MAAM,iBAAkB,SAAQ,gBAAY;CAAG;AAC/C,MAAM,EAAE,GAAG,IAAI,iBAAiB,EAAE,CAAA;AAElC,kBAAe,EAAE,CAAA"}
@@ -0,0 +1,12 @@
1
+ import type { HydratedDocument, Types } from 'mongoose';
2
+ interface IContext<T> {
3
+ op: string;
4
+ modelName: string;
5
+ collectionName: string;
6
+ isNew?: boolean;
7
+ oldDoc?: HydratedDocument<T>;
8
+ deletedDocs?: HydratedDocument<T>[];
9
+ updatedIds?: Types.ObjectId[];
10
+ }
11
+ export default IContext;
12
+ //# sourceMappingURL=IContext.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"IContext.d.ts","sourceRoot":"","sources":["../../../src/interfaces/IContext.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,KAAK,EAAE,MAAM,UAAU,CAAA;AAEvD,UAAU,QAAQ,CAAC,CAAC;IAClB,EAAE,EAAE,MAAM,CAAA;IACV,SAAS,EAAE,MAAM,CAAA;IACjB,cAAc,EAAE,MAAM,CAAA;IACtB,KAAK,CAAC,EAAE,OAAO,CAAA;IACf,MAAM,CAAC,EAAE,gBAAgB,CAAC,CAAC,CAAC,CAAA;IAC5B,WAAW,CAAC,EAAE,gBAAgB,CAAC,CAAC,CAAC,EAAE,CAAA;IACnC,UAAU,CAAC,EAAE,KAAK,CAAC,QAAQ,EAAE,CAAA;CAC9B;AAED,eAAe,QAAQ,CAAA"}
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=IContext.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"IContext.js","sourceRoot":"","sources":["../../../src/interfaces/IContext.ts"],"names":[],"mappings":""}
@@ -0,0 +1,13 @@
1
+ import type { Types } from 'mongoose';
2
+ import type { Operation } from 'fast-json-patch';
3
+ interface IHistory {
4
+ op: string;
5
+ modelName: string;
6
+ collectionName: string;
7
+ collectionId: Types.ObjectId;
8
+ version: number;
9
+ doc?: object;
10
+ patch?: Operation[];
11
+ }
12
+ export default IHistory;
13
+ //# sourceMappingURL=IHistory.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"IHistory.d.ts","sourceRoot":"","sources":["../../../src/interfaces/IHistory.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,UAAU,CAAA;AACrC,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAA;AAEhD,UAAU,QAAQ;IAChB,EAAE,EAAE,MAAM,CAAA;IACV,SAAS,EAAE,MAAM,CAAC;IAClB,cAAc,EAAE,MAAM,CAAA;IACtB,YAAY,EAAE,KAAK,CAAC,QAAQ,CAAA;IAC5B,OAAO,EAAE,MAAM,CAAA;IACf,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ,KAAK,CAAC,EAAE,SAAS,EAAE,CAAA;CACpB;AAED,eAAe,QAAQ,CAAA"}
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=IHistory.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"IHistory.js","sourceRoot":"","sources":["../../../src/interfaces/IHistory.ts"],"names":[],"mappings":""}
@@ -0,0 +1,8 @@
1
+ import type { Query } from 'mongoose';
2
+ import type IContext from './IContext';
3
+ type IHookContext<T> = Query<T, T> & {
4
+ op: string;
5
+ _context: IContext<T>;
6
+ };
7
+ export default IHookContext;
8
+ //# sourceMappingURL=IHookContext.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"IHookContext.d.ts","sourceRoot":"","sources":["../../../src/interfaces/IHookContext.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,UAAU,CAAA;AACrC,OAAO,KAAK,QAAQ,MAAM,YAAY,CAAA;AAEtC,KAAK,YAAY,CAAC,CAAC,IAAI,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG;IAAE,EAAE,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAA;CAAE,CAAA;AAE1E,eAAe,YAAY,CAAA"}
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=IHookContext.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"IHookContext.js","sourceRoot":"","sources":["../../../src/interfaces/IHookContext.ts"],"names":[],"mappings":""}
@@ -0,0 +1,13 @@
1
+ import type { HydratedDocument } from 'mongoose';
2
+ interface IPluginOptions<T> {
3
+ modelName?: string;
4
+ collectionName?: string;
5
+ eventUpdated?: string;
6
+ eventCreated?: string;
7
+ eventDeleted?: string;
8
+ patchHistoryDisabled?: boolean;
9
+ preDeleteManyCallback?: (docs: HydratedDocument<T>[]) => Promise<void>;
10
+ omit?: string[];
11
+ }
12
+ export default IPluginOptions;
13
+ //# sourceMappingURL=IPluginOptions.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"IPluginOptions.d.ts","sourceRoot":"","sources":["../../../src/interfaces/IPluginOptions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAA;AAEhD,UAAU,cAAc,CAAC,CAAC;IACxB,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,oBAAoB,CAAC,EAAE,OAAO,CAAA;IAC9B,qBAAqB,CAAC,EAAE,CAAC,IAAI,EAAE,gBAAgB,CAAC,CAAC,CAAC,EAAE,KAAK,OAAO,CAAC,IAAI,CAAC,CAAA;IACtE,IAAI,CAAC,EAAE,MAAM,EAAE,CAAA;CAChB;AAED,eAAe,cAAc,CAAA"}
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=IPluginOptions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"IPluginOptions.js","sourceRoot":"","sources":["../../../src/interfaces/IPluginOptions.ts"],"names":[],"mappings":""}
@@ -0,0 +1,29 @@
1
+ /// <reference types="mongoose/types/aggregate" />
2
+ /// <reference types="mongoose/types/callback" />
3
+ /// <reference types="mongoose/types/collection" />
4
+ /// <reference types="mongoose/types/connection" />
5
+ /// <reference types="mongoose/types/cursor" />
6
+ /// <reference types="mongoose/types/document" />
7
+ /// <reference types="mongoose/types/error" />
8
+ /// <reference types="mongoose/types/expressions" />
9
+ /// <reference types="mongoose/types/helpers" />
10
+ /// <reference types="mongoose/types/middlewares" />
11
+ /// <reference types="mongoose/types/indexes" />
12
+ /// <reference types="mongoose/types/models" />
13
+ /// <reference types="mongoose/types/mongooseoptions" />
14
+ /// <reference types="mongoose/types/pipelinestage" />
15
+ /// <reference types="mongoose/types/populate" />
16
+ /// <reference types="mongoose/types/query" />
17
+ /// <reference types="mongoose/types/schemaoptions" />
18
+ /// <reference types="mongoose/types/schematypes" />
19
+ /// <reference types="mongoose/types/session" />
20
+ /// <reference types="mongoose/types/types" />
21
+ /// <reference types="mongoose/types/utility" />
22
+ /// <reference types="mongoose/types/validation" />
23
+ /// <reference types="mongoose/types/virtuals" />
24
+ /// <reference types="mongoose/types/inferschematype" />
25
+ import { Schema } from 'mongoose';
26
+ import type IHistory from '../interfaces/IHistory';
27
+ declare const History: import("mongoose").Model<IHistory, {}, {}, {}, Schema<IHistory, import("mongoose").Model<IHistory, any, any, any, any>, {}, {}, {}, {}, import("mongoose").DefaultSchemaOptions, IHistory>>;
28
+ export default History;
29
+ //# sourceMappingURL=History.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"History.d.ts","sourceRoot":"","sources":["../../../src/models/History.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAAA,OAAO,EAAE,MAAM,EAAS,MAAM,UAAU,CAAA;AAExC,OAAO,KAAK,QAAQ,MAAM,wBAAwB,CAAA;AAkClD,QAAA,MAAM,OAAO,6LAA6C,CAAA;AAE1D,eAAe,OAAO,CAAA"}
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const mongoose_1 = require("mongoose");
4
+ const HistorySchema = new mongoose_1.Schema({
5
+ op: {
6
+ type: String,
7
+ required: true
8
+ },
9
+ modelName: {
10
+ type: String,
11
+ required: true
12
+ },
13
+ collectionName: {
14
+ type: String,
15
+ required: true
16
+ },
17
+ collectionId: {
18
+ type: mongoose_1.Schema.Types.ObjectId,
19
+ required: true
20
+ },
21
+ doc: {
22
+ type: Object
23
+ },
24
+ patch: {
25
+ type: Array
26
+ },
27
+ version: {
28
+ type: Number,
29
+ min: 0,
30
+ default: 0
31
+ }
32
+ }, { timestamps: true });
33
+ HistorySchema.index({ op: 1, modelName: 1, collectionName: 1, collectionId: 1, version: 1 });
34
+ const History = (0, mongoose_1.model)('History', HistorySchema, 'history');
35
+ exports.default = History;
36
+ //# sourceMappingURL=History.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"History.js","sourceRoot":"","sources":["../../../src/models/History.ts"],"names":[],"mappings":";;AAAA,uCAAwC;AAIxC,MAAM,aAAa,GAAG,IAAI,iBAAM,CAAW;IACzC,EAAE,EAAE;QACF,IAAI,EAAE,MAAM;QACZ,QAAQ,EAAE,IAAI;KACf;IACD,SAAS,EAAE;QACT,IAAI,EAAE,MAAM;QACZ,QAAQ,EAAE,IAAI;KACf;IACD,cAAc,EAAE;QACd,IAAI,EAAE,MAAM;QACZ,QAAQ,EAAE,IAAI;KACf;IACD,YAAY,EAAE;QACZ,IAAI,EAAE,iBAAM,CAAC,KAAK,CAAC,QAAQ;QAC3B,QAAQ,EAAE,IAAI;KACf;IACD,GAAG,EAAE;QACH,IAAI,EAAE,MAAM;KACb;IACD,KAAK,EAAE;QACL,IAAI,EAAE,KAAK;KACZ;IACD,OAAO,EAAE;QACP,IAAI,EAAE,MAAM;QACZ,GAAG,EAAE,CAAC;QACN,OAAO,EAAE,CAAC;KACX;CACF,EAAE,EAAE,UAAU,EAAE,IAAI,EAAE,CAAC,CAAA;AAExB,aAAa,CAAC,KAAK,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,SAAS,EAAE,CAAC,EAAE,cAAc,EAAE,CAAC,EAAE,YAAY,EAAE,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,CAAC,CAAA;AAE5F,MAAM,OAAO,GAAG,IAAA,gBAAK,EAAC,SAAS,EAAE,aAAa,EAAE,SAAS,CAAC,CAAA;AAE1D,kBAAe,OAAO,CAAA"}
@@ -0,0 +1,45 @@
1
+ /// <reference types="mongoose/types/aggregate" />
2
+ /// <reference types="mongoose/types/callback" />
3
+ /// <reference types="mongoose/types/collection" />
4
+ /// <reference types="mongoose/types/connection" />
5
+ /// <reference types="mongoose/types/cursor" />
6
+ /// <reference types="mongoose/types/document" />
7
+ /// <reference types="mongoose/types/error" />
8
+ /// <reference types="mongoose/types/expressions" />
9
+ /// <reference types="mongoose/types/helpers" />
10
+ /// <reference types="mongoose/types/middlewares" />
11
+ /// <reference types="mongoose/types/indexes" />
12
+ /// <reference types="mongoose/types/models" />
13
+ /// <reference types="mongoose/types/mongooseoptions" />
14
+ /// <reference types="mongoose/types/pipelinestage" />
15
+ /// <reference types="mongoose/types/populate" />
16
+ /// <reference types="mongoose/types/query" />
17
+ /// <reference types="mongoose/types/schemaoptions" />
18
+ /// <reference types="mongoose/types/schematypes" />
19
+ /// <reference types="mongoose/types/session" />
20
+ /// <reference types="mongoose/types/types" />
21
+ /// <reference types="mongoose/types/utility" />
22
+ /// <reference types="mongoose/types/validation" />
23
+ /// <reference types="mongoose/types/virtuals" />
24
+ /// <reference types="mongoose/types/inferschematype" />
25
+ import type { Model, Schema } from 'mongoose';
26
+ import type IPluginOptions from './interfaces/IPluginOptions';
27
+ export declare const patchEventEmitter: {
28
+ addListener(eventName: string | symbol, listener: (...args: any[]) => void): any;
29
+ on(eventName: string | symbol, listener: (...args: any[]) => void): any;
30
+ once(eventName: string | symbol, listener: (...args: any[]) => void): any;
31
+ removeListener(eventName: string | symbol, listener: (...args: any[]) => void): any;
32
+ off(eventName: string | symbol, listener: (...args: any[]) => void): any;
33
+ removeAllListeners(event?: string | symbol | undefined): any;
34
+ setMaxListeners(n: number): any;
35
+ getMaxListeners(): number;
36
+ listeners(eventName: string | symbol): Function[];
37
+ rawListeners(eventName: string | symbol): Function[];
38
+ emit(eventName: string | symbol, ...args: any[]): boolean;
39
+ listenerCount(eventName: string | symbol): number;
40
+ prependListener(eventName: string | symbol, listener: (...args: any[]) => void): any;
41
+ prependOnceListener(eventName: string | symbol, listener: (...args: any[]) => void): any;
42
+ eventNames(): (string | symbol)[];
43
+ };
44
+ export declare const patchHistoryPlugin: <T>(schema: Schema<T, Model<T, any, any, any, any>, {}, {}, {}, {}, import("mongoose").DefaultSchemaOptions, import("mongoose").ObtainDocumentType<any, T, import("mongoose").DefaultSchemaOptions>>, opts: IPluginOptions<T>) => void;
45
+ //# sourceMappingURL=plugin.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../../src/plugin.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAKA,OAAO,KAAK,EAAmC,KAAK,EAAiB,MAAM,EAAS,MAAM,UAAU,CAAA;AAEpG,OAAO,KAAK,cAAc,MAAM,6BAA6B,CAAA;AAuG7D,eAAO,MAAM,iBAAiB;;;;;;;;;;;;;;;;CAAK,CAAA;AAQnC,eAAO,MAAM,kBAAkB,oOAAoE,IAoJlG,CAAA"}