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
@@ -0,0 +1,224 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.patchHistoryPlugin = exports.patchEventEmitter = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const lodash_1 = tslib_1.__importDefault(require("lodash"));
6
+ const omit_deep_1 = tslib_1.__importDefault(require("omit-deep"));
7
+ const fast_json_patch_1 = tslib_1.__importDefault(require("fast-json-patch"));
8
+ const power_assign_1 = require("power-assign");
9
+ const em_1 = tslib_1.__importDefault(require("./em"));
10
+ const History_1 = tslib_1.__importDefault(require("./models/History"));
11
+ const options = {
12
+ document: false,
13
+ query: true
14
+ };
15
+ function getObjects(opts, current, original) {
16
+ let currentObject = JSON.parse(JSON.stringify(current));
17
+ let originalObject = JSON.parse(JSON.stringify(original));
18
+ if (opts.omit) {
19
+ currentObject = (0, omit_deep_1.default)(currentObject, opts.omit);
20
+ originalObject = (0, omit_deep_1.default)(originalObject, opts.omit);
21
+ }
22
+ return { currentObject, originalObject };
23
+ }
24
+ async function bulkPatch(opts, context) {
25
+ const chunks = lodash_1.default.chunk(context.deletedDocs, 1000);
26
+ for await (const chunk of chunks) {
27
+ const bulk = [];
28
+ for (const oldDoc of chunk) {
29
+ if (opts.eventDeleted) {
30
+ em_1.default.emit(opts.eventDeleted, { oldDoc });
31
+ }
32
+ if (!opts.patchHistoryDisabled) {
33
+ bulk.push({
34
+ insertOne: {
35
+ document: {
36
+ op: context.op,
37
+ modelName: context.modelName,
38
+ collectionName: context.collectionName,
39
+ collectionId: oldDoc._id,
40
+ doc: oldDoc,
41
+ version: 0
42
+ }
43
+ }
44
+ });
45
+ }
46
+ }
47
+ if (opts.patchHistoryDisabled)
48
+ continue;
49
+ await History_1.default.bulkWrite(bulk, { ordered: false }).catch((err) => {
50
+ console.error(err);
51
+ });
52
+ }
53
+ }
54
+ async function updatePatch(opts, context, current, original) {
55
+ const { currentObject, originalObject } = getObjects(opts, current, original);
56
+ if (lodash_1.default.isEmpty(originalObject) || lodash_1.default.isEmpty(currentObject))
57
+ return;
58
+ const patch = fast_json_patch_1.default.compare(originalObject, currentObject, true);
59
+ if (lodash_1.default.isEmpty(patch))
60
+ return;
61
+ if (opts.eventUpdated) {
62
+ em_1.default.emit(opts.eventUpdated, { oldDoc: original, doc: current, patch });
63
+ }
64
+ if (opts.patchHistoryDisabled)
65
+ return;
66
+ let version = 0;
67
+ const lastHistory = await History_1.default.findOne({ collectionId: original._id }).sort('-version').exec();
68
+ if (lastHistory && lastHistory.version >= 0) {
69
+ version = lastHistory.version + 1;
70
+ }
71
+ await History_1.default.create({
72
+ op: context.op,
73
+ modelName: context.modelName,
74
+ collectionName: context.collectionName,
75
+ collectionId: original._id,
76
+ patch,
77
+ version
78
+ });
79
+ }
80
+ async function createPatch(opts, context, current) {
81
+ if (opts.patchHistoryDisabled)
82
+ return;
83
+ await History_1.default.create({
84
+ op: context.op,
85
+ modelName: context.modelName,
86
+ collectionName: context.collectionName,
87
+ collectionId: current._id,
88
+ doc: current
89
+ });
90
+ }
91
+ exports.patchEventEmitter = em_1.default;
92
+ const patchHistoryPlugin = function plugin(schema, opts) {
93
+ schema.pre('save', async function (next) {
94
+ const current = this.toObject({ depopulate: true });
95
+ const model = this.constructor;
96
+ const context = {
97
+ op: this.isNew ? 'create' : 'update',
98
+ modelName: opts.modelName ?? model.modelName,
99
+ collectionName: opts.collectionName ?? model.collection.collectionName
100
+ };
101
+ try {
102
+ if (this.isNew) {
103
+ if (opts.eventCreated) {
104
+ em_1.default.emit(opts.eventCreated, { doc: current });
105
+ }
106
+ await createPatch(opts, context, current);
107
+ }
108
+ else {
109
+ const original = await model.findById(current._id).exec();
110
+ if (original) {
111
+ await updatePatch(opts, context, current, original);
112
+ }
113
+ }
114
+ next();
115
+ }
116
+ catch (error) {
117
+ next(error);
118
+ }
119
+ });
120
+ schema.pre(['findOneAndUpdate', 'update', 'updateOne', 'updateMany'], async function (next) {
121
+ const filter = this.getFilter();
122
+ const update = this.getUpdate();
123
+ const options = this.getOptions();
124
+ const count = await this.model.count(filter).exec();
125
+ const commands = [];
126
+ const context = {
127
+ op: this.op,
128
+ modelName: opts.modelName ?? this.model.modelName,
129
+ collectionName: opts.collectionName ?? this.model.collection.collectionName,
130
+ isNew: options.upsert && count === 0
131
+ };
132
+ this._context = context;
133
+ try {
134
+ const keys = lodash_1.default.keys(update).filter((key) => key.startsWith('$'));
135
+ if (update && !lodash_1.default.isEmpty(keys)) {
136
+ lodash_1.default.forEach(keys, (key) => {
137
+ commands.push({ [key]: update[key] });
138
+ delete update[key];
139
+ });
140
+ }
141
+ const cursor = this.model.find(filter).cursor();
142
+ await cursor.eachAsync(async (doc) => {
143
+ let current = doc.toObject({ depopulate: true });
144
+ current = (0, power_assign_1.assign)(current, update);
145
+ lodash_1.default.forEach(commands, (command) => {
146
+ try {
147
+ current = (0, power_assign_1.assign)(current, command);
148
+ }
149
+ catch (error) {
150
+ }
151
+ });
152
+ await updatePatch(opts, context, current, doc.toObject({ depopulate: true }));
153
+ });
154
+ next();
155
+ }
156
+ catch (error) {
157
+ next(error);
158
+ }
159
+ });
160
+ schema.post(['findOneAndUpdate', 'update', 'updateOne', 'updateMany'], async function () {
161
+ const update = this.getUpdate();
162
+ if (update && this._context.isNew) {
163
+ const cursor = this.model.findOne(update).cursor();
164
+ await cursor.eachAsync(async (current) => {
165
+ if (opts.eventCreated) {
166
+ em_1.default.emit(opts.eventCreated, { doc: current });
167
+ }
168
+ await createPatch(opts, this._context, current);
169
+ });
170
+ }
171
+ });
172
+ schema.pre('updateMany', options, async function (next) {
173
+ const filter = this.getFilter();
174
+ const options = this.getOptions();
175
+ const ignore = options.__ignore;
176
+ const context = {
177
+ op: this.op,
178
+ modelName: opts.modelName ?? this.model.modelName,
179
+ collectionName: opts.collectionName ?? this.model.collection.collectionName,
180
+ isNew: options.upsert
181
+ };
182
+ if (!ignore) {
183
+ const ids = await this.model.distinct('_id', filter).exec();
184
+ context.updatedIds = ids;
185
+ }
186
+ this._context = context;
187
+ next();
188
+ });
189
+ schema.post('updateMany', options, async function () {
190
+ if (this._context.updatedIds?.length)
191
+ return;
192
+ const cursor = this.model.find({ _id: { $in: this._context.updatedIds } }).cursor();
193
+ await cursor.eachAsync((current) => {
194
+ if (opts.eventUpdated) {
195
+ em_1.default.emit(opts.eventUpdated, { doc: current });
196
+ }
197
+ });
198
+ });
199
+ schema.pre(['remove', 'findOneAndDelete', 'findOneAndRemove', 'deleteOne', 'deleteMany'], options, async function (next) {
200
+ const filter = this.getFilter();
201
+ const options = this.getOptions();
202
+ const ignore = options.__ignore;
203
+ const context = {
204
+ op: this.op,
205
+ modelName: opts.modelName ?? this.model.modelName,
206
+ collectionName: opts.collectionName ?? this.model.collection.collectionName
207
+ };
208
+ if (!ignore) {
209
+ context.deletedDocs = await this.model.find(filter).exec();
210
+ if (opts.preDeleteManyCallback) {
211
+ await opts.preDeleteManyCallback(context.deletedDocs);
212
+ }
213
+ }
214
+ this._context = context;
215
+ next();
216
+ });
217
+ schema.post(['remove', 'findOneAndDelete', 'findOneAndRemove', 'deleteOne', 'deleteMany'], options, async function () {
218
+ if (lodash_1.default.isEmpty(this._context.deletedDocs))
219
+ return;
220
+ await bulkPatch(opts, this._context);
221
+ });
222
+ };
223
+ exports.patchHistoryPlugin = patchHistoryPlugin;
224
+ //# sourceMappingURL=plugin.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plugin.js","sourceRoot":"","sources":["../../src/plugin.ts"],"names":[],"mappings":";;;;AAAA,4DAAsB;AACtB,kEAA4B;AAC5B,8EAAuC;AACvC,+CAAqC;AAQrC,sDAAqB;AACrB,uEAAsC;AAEtC,MAAM,OAAO,GAAG;IACd,QAAQ,EAAE,KAAK;IACf,KAAK,EAAE,IAAI;CACZ,CAAA;AAED,SAAS,UAAU,CAAK,IAAuB,EAAE,OAA4B,EAAE,QAA6B;IAC1G,IAAI,aAAa,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,CAAe,CAAA;IACrE,IAAI,cAAc,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAe,CAAA;IAEvE,IAAI,IAAI,CAAC,IAAI,EAAE;QACb,aAAa,GAAG,IAAA,mBAAI,EAAC,aAAa,EAAE,IAAI,CAAC,IAAI,CAAC,CAAA;QAC9C,cAAc,GAAG,IAAA,mBAAI,EAAC,cAAc,EAAE,IAAI,CAAC,IAAI,CAAC,CAAA;KACjD;IAED,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,CAAA;AAC1C,CAAC;AAED,KAAK,UAAU,SAAS,CAAK,IAAuB,EAAE,OAAoB;IACxE,MAAM,MAAM,GAAG,gBAAC,CAAC,KAAK,CAAC,OAAO,CAAC,WAAW,EAAE,IAAI,CAAC,CAAA;IACjD,IAAI,KAAK,EAAE,MAAM,KAAK,IAAI,MAAM,EA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ACvG,IAAI,gBAAC,CAAC,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,WAAW,CAAC;YAAE,OAAM;QAEhD,MAAM,SAAS,CAAC,IAAI,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAA;IACtC,CAAC,CAAC,CAAA;AACJ,CAAC,CAAA;AApJY,QAAA,kBAAkB,sBAoJ9B"}
@@ -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/esm/em.js ADDED
@@ -0,0 +1,6 @@
1
+ import EventEmitter from 'events';
2
+ class PatchEventEmitter extends EventEmitter {
3
+ }
4
+ const em = new PatchEventEmitter();
5
+ export default em;
6
+ //# sourceMappingURL=em.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"em.js","sourceRoot":"","sources":["../../src/em.ts"],"names":[],"mappings":"AAAA,OAAO,YAAY,MAAM,QAAQ,CAAA;AAEjC,MAAM,iBAAkB,SAAQ,YAAY;CAAG;AAC/C,MAAM,EAAE,GAAG,IAAI,iBAAiB,EAAE,CAAA;AAElC,eAAe,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,2 @@
1
+ export {};
2
+ //# 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,2 @@
1
+ export {};
2
+ //# 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,2 @@
1
+ export {};
2
+ //# 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,2 @@
1
+ export {};
2
+ //# 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,34 @@
1
+ import { Schema, model } from 'mongoose';
2
+ const HistorySchema = new Schema({
3
+ op: {
4
+ type: String,
5
+ required: true
6
+ },
7
+ modelName: {
8
+ type: String,
9
+ required: true
10
+ },
11
+ collectionName: {
12
+ type: String,
13
+ required: true
14
+ },
15
+ collectionId: {
16
+ type: Schema.Types.ObjectId,
17
+ required: true
18
+ },
19
+ doc: {
20
+ type: Object
21
+ },
22
+ patch: {
23
+ type: Array
24
+ },
25
+ version: {
26
+ type: Number,
27
+ min: 0,
28
+ default: 0
29
+ }
30
+ }, { timestamps: true });
31
+ HistorySchema.index({ op: 1, modelName: 1, collectionName: 1, collectionId: 1, version: 1 });
32
+ const History = model('History', HistorySchema, 'history');
33
+ export default History;
34
+ //# sourceMappingURL=History.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"History.js","sourceRoot":"","sources":["../../../src/models/History.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,UAAU,CAAA;AAIxC,MAAM,aAAa,GAAG,IAAI,MAAM,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,MAAM,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,KAAK,CAAC,SAAS,EAAE,aAAa,EAAE,SAAS,CAAC,CAAA;AAE1D,eAAe,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"}