ts-patch-mongoose 2.7.1 → 2.8.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/biome.json +1 -1
- package/dist/cjs/helpers.js +6 -6
- package/dist/cjs/helpers.js.map +1 -1
- package/dist/cjs/hooks/delete-hooks.js.map +1 -1
- package/dist/cjs/hooks/save-hooks.js.map +1 -1
- package/dist/cjs/hooks/update-hooks.js.map +1 -1
- package/dist/cjs/models/History.js +5 -5
- package/dist/cjs/models/History.js.map +1 -1
- package/dist/cjs/patch.js +4 -4
- package/dist/cjs/patch.js.map +1 -1
- package/dist/cjs/plugin.js.map +1 -1
- package/dist/cjs/types/hooks/delete-hooks.d.ts +2 -2
- package/dist/cjs/types/hooks/delete-hooks.d.ts.map +1 -1
- package/dist/cjs/types/hooks/save-hooks.d.ts +2 -2
- package/dist/cjs/types/hooks/save-hooks.d.ts.map +1 -1
- package/dist/cjs/types/hooks/update-hooks.d.ts +2 -2
- package/dist/cjs/types/hooks/update-hooks.d.ts.map +1 -1
- package/dist/cjs/types/models/History.d.ts +6 -6
- package/dist/cjs/types/models/History.d.ts.map +1 -1
- package/dist/cjs/types/patch.d.ts +12 -15
- package/dist/cjs/types/patch.d.ts.map +1 -1
- package/dist/cjs/types/plugin.d.ts +2 -2
- package/dist/cjs/types/plugin.d.ts.map +1 -1
- package/dist/cjs/types/types.d.ts +49 -0
- package/dist/cjs/types/types.d.ts.map +1 -0
- package/dist/cjs/{interfaces/IEvent.js → types.js} +1 -1
- package/dist/cjs/types.js.map +1 -0
- package/dist/esm/helpers.js +6 -6
- package/dist/esm/helpers.js.map +1 -1
- package/dist/esm/hooks/delete-hooks.js.map +1 -1
- package/dist/esm/hooks/save-hooks.js.map +1 -1
- package/dist/esm/hooks/update-hooks.js.map +1 -1
- package/dist/esm/models/History.js +2 -3
- package/dist/esm/models/History.js.map +1 -1
- package/dist/esm/patch.js +4 -4
- package/dist/esm/patch.js.map +1 -1
- package/dist/esm/plugin.js.map +1 -1
- package/dist/esm/types/hooks/delete-hooks.d.ts +2 -2
- package/dist/esm/types/hooks/delete-hooks.d.ts.map +1 -1
- package/dist/esm/types/hooks/save-hooks.d.ts +2 -2
- package/dist/esm/types/hooks/save-hooks.d.ts.map +1 -1
- package/dist/esm/types/hooks/update-hooks.d.ts +2 -2
- package/dist/esm/types/hooks/update-hooks.d.ts.map +1 -1
- package/dist/esm/types/models/History.d.ts +6 -6
- package/dist/esm/types/models/History.d.ts.map +1 -1
- package/dist/esm/types/patch.d.ts +12 -15
- package/dist/esm/types/patch.d.ts.map +1 -1
- package/dist/esm/types/plugin.d.ts +2 -2
- package/dist/esm/types/plugin.d.ts.map +1 -1
- package/dist/esm/types/types.d.ts +49 -0
- package/dist/esm/types/types.d.ts.map +1 -0
- package/dist/esm/types.js +2 -0
- package/dist/esm/types.js.map +1 -0
- package/package.json +1 -4
- package/src/helpers.ts +6 -6
- package/src/hooks/delete-hooks.ts +4 -5
- package/src/hooks/save-hooks.ts +3 -4
- package/src/hooks/update-hooks.ts +4 -5
- package/src/models/History.ts +3 -5
- package/src/patch.ts +17 -21
- package/src/plugin.ts +25 -9
- package/src/types.ts +52 -0
- package/tests/helpers.test.ts +5 -6
- package/tests/patch.test.ts +21 -26
- package/tests/plugin-event-created.test.ts +50 -51
- package/tests/plugin-event-deleted.test.ts +76 -77
- package/tests/plugin-event-updated.test.ts +65 -67
- package/tests/plugin-global.test.ts +24 -25
- package/tests/plugin-omit-all.test.ts +36 -37
- package/tests/plugin-patch-history-disabled.test.ts +36 -37
- package/tests/plugin-pre-delete.test.ts +17 -18
- package/tests/plugin-pre-save.test.ts +6 -7
- package/tests/plugin.test.ts +37 -39
- package/tests/schemas/{DescriptionSchema.ts → Description.ts} +4 -4
- package/tests/schemas/{ProductSchema.ts → Product.ts} +12 -5
- package/tests/schemas/{UserSchema.ts → User.ts} +7 -4
- package/.swcrc +0 -17
- package/dist/cjs/interfaces/IContext.js +0 -3
- package/dist/cjs/interfaces/IContext.js.map +0 -1
- package/dist/cjs/interfaces/IEvent.js.map +0 -1
- package/dist/cjs/interfaces/IHistory.js +0 -3
- package/dist/cjs/interfaces/IHistory.js.map +0 -1
- package/dist/cjs/interfaces/IHookContext.js +0 -3
- package/dist/cjs/interfaces/IHookContext.js.map +0 -1
- package/dist/cjs/interfaces/IPluginOptions.js +0 -3
- package/dist/cjs/interfaces/IPluginOptions.js.map +0 -1
- package/dist/cjs/types/interfaces/IContext.d.ts +0 -13
- package/dist/cjs/types/interfaces/IContext.d.ts.map +0 -1
- package/dist/cjs/types/interfaces/IEvent.d.ts +0 -9
- package/dist/cjs/types/interfaces/IEvent.d.ts.map +0 -1
- package/dist/cjs/types/interfaces/IHistory.d.ts +0 -16
- package/dist/cjs/types/interfaces/IHistory.d.ts.map +0 -1
- package/dist/cjs/types/interfaces/IHookContext.d.ts +0 -8
- package/dist/cjs/types/interfaces/IHookContext.d.ts.map +0 -1
- package/dist/cjs/types/interfaces/IPluginOptions.d.ts +0 -18
- package/dist/cjs/types/interfaces/IPluginOptions.d.ts.map +0 -1
- package/dist/esm/interfaces/IContext.js +0 -2
- package/dist/esm/interfaces/IContext.js.map +0 -1
- package/dist/esm/interfaces/IEvent.js +0 -2
- package/dist/esm/interfaces/IEvent.js.map +0 -1
- package/dist/esm/interfaces/IHistory.js +0 -2
- package/dist/esm/interfaces/IHistory.js.map +0 -1
- package/dist/esm/interfaces/IHookContext.js +0 -2
- package/dist/esm/interfaces/IHookContext.js.map +0 -1
- package/dist/esm/interfaces/IPluginOptions.js +0 -2
- package/dist/esm/interfaces/IPluginOptions.js.map +0 -1
- package/dist/esm/types/interfaces/IContext.d.ts +0 -13
- package/dist/esm/types/interfaces/IContext.d.ts.map +0 -1
- package/dist/esm/types/interfaces/IEvent.d.ts +0 -9
- package/dist/esm/types/interfaces/IEvent.d.ts.map +0 -1
- package/dist/esm/types/interfaces/IHistory.d.ts +0 -16
- package/dist/esm/types/interfaces/IHistory.d.ts.map +0 -1
- package/dist/esm/types/interfaces/IHookContext.d.ts +0 -8
- package/dist/esm/types/interfaces/IHookContext.d.ts.map +0 -1
- package/dist/esm/types/interfaces/IPluginOptions.d.ts +0 -18
- package/dist/esm/types/interfaces/IPluginOptions.d.ts.map +0 -1
- package/src/interfaces/IContext.ts +0 -14
- package/src/interfaces/IEvent.ts +0 -10
- package/src/interfaces/IHistory.ts +0 -17
- package/src/interfaces/IHookContext.ts +0 -6
- package/src/interfaces/IPluginOptions.ts +0 -20
- package/tests/interfaces/IDescription.ts +0 -5
- package/tests/interfaces/IProduct.ts +0 -14
- package/tests/interfaces/IUser.ts +0 -8
package/dist/esm/patch.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"patch.js","sourceRoot":"","sources":["../../src/patch.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,MAAM,iBAAiB,CAAA;AACvC,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAA;AACnD,OAAO,IAAI,MAAM,WAAW,CAAA;
|
|
1
|
+
{"version":3,"file":"patch.js","sourceRoot":"","sources":["../../src/patch.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,MAAM,iBAAiB,CAAA;AACvC,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAA;AACnD,OAAO,IAAI,MAAM,WAAW,CAAA;AAK5B,OAAO,EAAE,MAAM,MAAM,CAAA;AACrB,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAA;AAE/C,SAAS,qBAAqB,CAAI,IAAsB,EAAE,OAAwB;IAChF,OAAO,CAAC,IAAI,CAAC,oBAAoB,IAAI,CAAC,OAAO,CAAC,kBAAkB,CAAA;AAClE,CAAC;AAED,MAAM,UAAU,WAAW,CAAI,IAAsB,EAAE,GAAwB;IAC7E,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,GA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YAC5C,KAAK;YACL,IAAI;YACJ,MAAM;YACN,QAAQ;YACR,OAAO;SACR,CAAC,CAAA;IACJ,CAAC;AACH,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,WAAW,CAAI,IAAsB,EAAE,OAAwB;IACnF,MAAM,SAAS,CAAC,IAAI,EAAE,OAAO,EAAE,cAAc,EAAE,aAAa,CAAC,CAAA;AAC/D,CAAC"}
|
package/dist/esm/plugin.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.js","sourceRoot":"","sources":["../../src/plugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAA;AAChC,OAAO,EAAE,MAAM,MAAM,CAAA;AAErB,OAAO,EAAE,eAAe,EAAE,MAAM,WAAW,CAAA;AAC3C,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,SAAS,CAAA;AAClD,OAAO,EAAE,mBAAmB,EAAE,mBAAmB,EAAE,MAAM,WAAW,CAAA;AAEpE,OAAO,EAAE,qBAAqB,EAAE,MAAM,sBAAsB,CAAA;AAC5D,OAAO,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAA;AACxD,OAAO,EAAE,qBAAqB,EAAE,MAAM,sBAAsB,CAAA;
|
|
1
|
+
{"version":3,"file":"plugin.js","sourceRoot":"","sources":["../../src/plugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAA;AAChC,OAAO,EAAE,MAAM,MAAM,CAAA;AAErB,OAAO,EAAE,eAAe,EAAE,MAAM,WAAW,CAAA;AAC3C,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,SAAS,CAAA;AAClD,OAAO,EAAE,mBAAmB,EAAE,mBAAmB,EAAE,MAAM,WAAW,CAAA;AAEpE,OAAO,EAAE,qBAAqB,EAAE,MAAM,sBAAsB,CAAA;AAC5D,OAAO,EAAE,mBAAmB,EAAE,MAAM,oBAA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AC,CAAA;QAQF,MAAM,CAAC,IAAI,CAAC,MAAM,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,EAAE,KAAK;YACzD,MAAM,QAAQ,GAAG,IAAI,CAAC,QAAQ,CAAC,eAAe,CAAwB,CAAA;YACtE,MAAM,KAAK,GAAG,IAAI,CAAC,WAAuB,CAAA;YAE1C,MAAM,OAAO,GAAoB;gBAC/B,EAAE,EAAE,QAAQ;gBACZ,SAAS,EAAE,IAAI,CAAC,SAAS,IAAI,KAAK,CAAC,SAAS;gBAC5C,cAAc,EAAE,IAAI,CAAC,cAAc,IAAI,KAAK,CAAC,UAAU,CAAC,cAAc;gBACtE,WAAW,EAAE,CAAC,QAAQ,CAAC;aACxB,CAAA;YAED,MAAM,WAAW,CAAC,IAAI,EAAE,OAAO,CAAC,CAAA;QAClC,CAAC,CAAC,CAAA;IACJ,CAAC;AACH,CAAC,CAAA"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import type { Schema } from 'mongoose';
|
|
2
|
-
import type
|
|
3
|
-
export declare const deleteHooksInitialize: <T>(schema: Schema<T>, opts:
|
|
2
|
+
import type { PluginOptions } from '../types';
|
|
3
|
+
export declare const deleteHooksInitialize: <T>(schema: Schema<T>, opts: PluginOptions<T>) => void;
|
|
4
4
|
//# sourceMappingURL=delete-hooks.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"delete-hooks.d.ts","sourceRoot":"","sources":["../../../../src/hooks/delete-hooks.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAoD,MAAM,EAAE,MAAM,UAAU,CAAA;
|
|
1
|
+
{"version":3,"file":"delete-hooks.d.ts","sourceRoot":"","sources":["../../../../src/hooks/delete-hooks.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAoD,MAAM,EAAE,MAAM,UAAU,CAAA;AACxF,OAAO,KAAK,EAAe,aAAa,EAAE,MAAM,UAAU,CAAA;AAI1D,eAAO,MAAM,qBAAqB,GAAI,CAAC,UAAU,MAAM,CAAC,CAAC,CAAC,QAAQ,aAAa,CAAC,CAAC,CAAC,KAAG,IAuCpF,CAAA"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import type { Schema } from 'mongoose';
|
|
2
|
-
import type
|
|
3
|
-
export declare const saveHooksInitialize: <T>(schema: Schema<T>, opts:
|
|
2
|
+
import type { PluginOptions } from '../types';
|
|
3
|
+
export declare const saveHooksInitialize: <T>(schema: Schema<T>, opts: PluginOptions<T>) => void;
|
|
4
4
|
//# sourceMappingURL=save-hooks.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"save-hooks.d.ts","sourceRoot":"","sources":["../../../../src/hooks/save-hooks.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAA2B,MAAM,EAAE,MAAM,UAAU,CAAA;
|
|
1
|
+
{"version":3,"file":"save-hooks.d.ts","sourceRoot":"","sources":["../../../../src/hooks/save-hooks.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAA2B,MAAM,EAAE,MAAM,UAAU,CAAA;AAC/D,OAAO,KAAK,EAAgB,aAAa,EAAE,MAAM,UAAU,CAAA;AAE3D,eAAO,MAAM,mBAAmB,GAAI,CAAC,UAAU,MAAM,CAAC,CAAC,CAAC,QAAQ,aAAa,CAAC,CAAC,CAAC,KAAG,IAuBlF,CAAA"}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import type { HydratedDocument, Schema, UpdateQuery, UpdateWithAggregationPipeline } from 'mongoose';
|
|
2
|
-
import type
|
|
2
|
+
import type { PluginOptions } from '../types';
|
|
3
3
|
export declare const assignUpdate: <T>(document: HydratedDocument<T>, update: UpdateQuery<T>, commands: Record<string, unknown>[]) => HydratedDocument<T>;
|
|
4
4
|
export declare const splitUpdateAndCommands: <T>(updateQuery: UpdateWithAggregationPipeline | UpdateQuery<T> | null) => {
|
|
5
5
|
update: UpdateQuery<T>;
|
|
6
6
|
commands: Record<string, unknown>[];
|
|
7
7
|
};
|
|
8
|
-
export declare const updateHooksInitialize: <T>(schema: Schema<T>, opts:
|
|
8
|
+
export declare const updateHooksInitialize: <T>(schema: Schema<T>, opts: PluginOptions<T>) => void;
|
|
9
9
|
//# sourceMappingURL=update-hooks.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"update-hooks.d.ts","sourceRoot":"","sources":["../../../../src/hooks/update-hooks.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,gBAAgB,EAAkC,MAAM,EAAE,WAAW,EAAE,6BAA6B,EAAE,MAAM,UAAU,CAAA;
|
|
1
|
+
{"version":3,"file":"update-hooks.d.ts","sourceRoot":"","sources":["../../../../src/hooks/update-hooks.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,gBAAgB,EAAkC,MAAM,EAAE,WAAW,EAAE,6BAA6B,EAAE,MAAM,UAAU,CAAA;AACpI,OAAO,KAAK,EAAe,aAAa,EAAE,MAAM,UAAU,CAAA;AAI1D,eAAO,MAAM,YAAY,GAAI,CAAC,YAAY,gBAAgB,CAAC,CAAC,CAAC,UAAU,WAAW,CAAC,CAAC,CAAC,YAAY,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,KAAG,gBAAgB,CAAC,CAAC,CAc9I,CAAA;AAED,eAAO,MAAM,sBAAsB,GAAI,CAAC,eAAe,6BAA6B,GAAG,WAAW,CAAC,CAAC,CAAC,GAAG,IAAI,KAAG;IAAE,MAAM,EAAE,WAAW,CAAC,CAAC,CAAC,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,CAAA;CAgB3K,CAAA;AAED,eAAO,MAAM,qBAAqB,GAAI,CAAC,UAAU,MAAM,CAAC,CAAC,CAAC,QAAQ,aAAa,CAAC,CAAC,CAAC,KAAG,IA4DpF,CAAA"}
|
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
import { Schema } from 'mongoose';
|
|
2
|
-
import type
|
|
3
|
-
declare const
|
|
2
|
+
import type { History } from '../types';
|
|
3
|
+
export declare const HistorySchema: Schema<History, import("mongoose").Model<History, any, any, any, import("mongoose").Document<unknown, any, History> & History & {
|
|
4
4
|
_id: import("mongoose").Types.ObjectId;
|
|
5
5
|
} & {
|
|
6
6
|
__v: number;
|
|
7
|
-
},
|
|
7
|
+
}, any>, {}, {}, {}, {}, import("mongoose").DefaultSchemaOptions, History, import("mongoose").Document<unknown, {}, import("mongoose").FlatRecord<History>> & import("mongoose").FlatRecord<History> & {
|
|
8
8
|
_id: import("mongoose").Types.ObjectId;
|
|
9
9
|
} & {
|
|
10
10
|
__v: number;
|
|
11
|
-
}
|
|
11
|
+
}>;
|
|
12
|
+
export declare const HistoryModel: import("mongoose").Model<History, {}, {}, {}, import("mongoose").Document<unknown, {}, History> & History & {
|
|
12
13
|
_id: import("mongoose").Types.ObjectId;
|
|
13
14
|
} & {
|
|
14
15
|
__v: number;
|
|
15
|
-
}
|
|
16
|
-
export default History;
|
|
16
|
+
}, any>;
|
|
17
17
|
//# sourceMappingURL=History.d.ts.map
|
|
@@ -1 +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,
|
|
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,EAAE,OAAO,EAAE,MAAM,UAAU,CAAA;AAEvC,eAAO,MAAM,aAAa;;;;;;;;EAwCzB,CAAA;AAKD,eAAO,MAAM,YAAY;;;;OAAsD,CAAA"}
|
|
@@ -1,18 +1,15 @@
|
|
|
1
1
|
import type { HydratedDocument } from 'mongoose';
|
|
2
|
-
import type
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
export declare function
|
|
7
|
-
export declare function
|
|
8
|
-
export declare function getUser<T>(opts: IPluginOptions<T>): Promise<User | undefined>;
|
|
9
|
-
export declare function getReason<T>(opts: IPluginOptions<T>): Promise<string | undefined>;
|
|
10
|
-
export declare function getMetadata<T>(opts: IPluginOptions<T>): Promise<Metadata | undefined>;
|
|
2
|
+
import type { Metadata, PatchContext, PatchEvent, PluginOptions, User } from './types';
|
|
3
|
+
export declare function getJsonOmit<T>(opts: PluginOptions<T>, doc: HydratedDocument<T>): Partial<T>;
|
|
4
|
+
export declare function getObjectOmit<T>(opts: PluginOptions<T>, doc: HydratedDocument<T>): Partial<T>;
|
|
5
|
+
export declare function getUser<T>(opts: PluginOptions<T>): Promise<User | undefined>;
|
|
6
|
+
export declare function getReason<T>(opts: PluginOptions<T>): Promise<string | undefined>;
|
|
7
|
+
export declare function getMetadata<T>(opts: PluginOptions<T>): Promise<Metadata | undefined>;
|
|
11
8
|
export declare function getValue<T>(item: PromiseSettledResult<T>): T | undefined;
|
|
12
|
-
export declare function getData<T>(opts:
|
|
13
|
-
export declare function emitEvent<T>(context:
|
|
14
|
-
export declare function bulkPatch<T>(opts:
|
|
15
|
-
export declare function createPatch<T>(opts:
|
|
16
|
-
export declare function updatePatch<T>(opts:
|
|
17
|
-
export declare function deletePatch<T>(opts:
|
|
9
|
+
export declare function getData<T>(opts: PluginOptions<T>): Promise<[User | undefined, string | undefined, Metadata | undefined]>;
|
|
10
|
+
export declare function emitEvent<T>(context: PatchContext<T>, event: string | undefined, data: PatchEvent<T>): void;
|
|
11
|
+
export declare function bulkPatch<T>(opts: PluginOptions<T>, context: PatchContext<T>, eventKey: 'eventCreated' | 'eventDeleted', docsKey: 'createdDocs' | 'deletedDocs'): Promise<void>;
|
|
12
|
+
export declare function createPatch<T>(opts: PluginOptions<T>, context: PatchContext<T>): Promise<void>;
|
|
13
|
+
export declare function updatePatch<T>(opts: PluginOptions<T>, context: PatchContext<T>, current: HydratedDocument<T>, original: HydratedDocument<T>): Promise<void>;
|
|
14
|
+
export declare function deletePatch<T>(opts: PluginOptions<T>, context: PatchContext<T>): Promise<void>;
|
|
18
15
|
//# sourceMappingURL=patch.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"patch.d.ts","sourceRoot":"","sources":["../../../src/patch.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,gBAAgB,EAAwB,MAAM,UAAU,CAAA;
|
|
1
|
+
{"version":3,"file":"patch.d.ts","sourceRoot":"","sources":["../../../src/patch.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,gBAAgB,EAAwB,MAAM,UAAU,CAAA;AACtE,OAAO,KAAK,EAAE,QAAQ,EAAE,YAAY,EAAE,UAAU,EAAE,aAAa,EAAE,IAAI,EAAE,MAAM,SAAS,CAAA;AAStF,wBAAgB,WAAW,CAAC,CAAC,EAAE,IAAI,EAAE,aAAa,CAAC,CAAC,CAAC,EAAE,GAAG,EAAE,gBAAgB,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAQ3F;AAED,wBAAgB,aAAa,CAAC,CAAC,EAAE,IAAI,EAAE,aAAa,CAAC,CAAC,CAAC,EAAE,GAAG,EAAE,gBAAgB,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAM7F;AAED,wBAAsB,OAAO,CAAC,CAAC,EAAE,IAAI,EAAE,aAAa,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,IAAI,GAAG,SAAS,CAAC,CAKlF;AAED,wBAAsB,SAAS,CAAC,CAAC,EAAE,IAAI,EAAE,aAAa,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAKtF;AAED,wBAAsB,WAAW,CAAC,CAAC,EAAE,IAAI,EAAE,aAAa,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,QAAQ,GAAG,SAAS,CAAC,CAK1F;AAED,wBAAg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
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Schema } from 'mongoose';
|
|
2
|
-
import type
|
|
2
|
+
import type { PluginOptions } from './types';
|
|
3
3
|
export declare const patchEventEmitter: {
|
|
4
4
|
[EventEmitter.captureRejectionSymbol]?<K>(error: Error, event: string | symbol, ...args: any[]): void;
|
|
5
5
|
addListener<K>(eventName: string | symbol, listener: (...args: any[]) => void): any;
|
|
@@ -19,5 +19,5 @@ export declare const patchEventEmitter: {
|
|
|
19
19
|
eventNames(): (string | symbol)[];
|
|
20
20
|
};
|
|
21
21
|
export { setPatchHistoryTTL } from './helpers';
|
|
22
|
-
export declare const patchHistoryPlugin: <T>(schema: Schema<T>, opts:
|
|
22
|
+
export declare const patchHistoryPlugin: <T>(schema: Schema<T>, opts: PluginOptions<T>) => void;
|
|
23
23
|
//# sourceMappingURL=plugin.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../../../src/plugin.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAA2B,MAAM,EAAE,MAAM,UAAU,CAAA;
|
|
1
|
+
{"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../../../src/plugin.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAA2B,MAAM,EAAE,MAAM,UAAU,CAAA;AAC/D,OAAO,KAAK,EAAgB,aAAa,EAAE,MAAM,SAAS,CAAA;AAO1D,eAAO,MAAM,iBAAiB;;;;;;;;;;;;;;;;;CAAK,CAAA;AAEnC,OAAO,EAAE,kBAAkB,EAAE,MAAM,WAAW,CAAA;AAY9C,eAAO,MAAM,kBAAkB,GAAmB,CAAC,UAAU,MAAM,CAAC,CAAC,CAAC,QAAQ,aAAa,CAAC,CAAC,CAAC,KAAG,IA2DhG,CAAA"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import type { Operation } from 'fast-json-patch';
|
|
2
|
+
import type { HydratedDocument, Query, Types } from 'mongoose';
|
|
3
|
+
export interface History {
|
|
4
|
+
op: string;
|
|
5
|
+
modelName: string;
|
|
6
|
+
collectionName: string;
|
|
7
|
+
collectionId: Types.ObjectId;
|
|
8
|
+
version: number;
|
|
9
|
+
doc?: object;
|
|
10
|
+
user?: object;
|
|
11
|
+
reason?: string;
|
|
12
|
+
metadata?: object;
|
|
13
|
+
patch?: Operation[];
|
|
14
|
+
}
|
|
15
|
+
export interface PatchEvent<T> {
|
|
16
|
+
oldDoc?: HydratedDocument<T>;
|
|
17
|
+
doc?: HydratedDocument<T>;
|
|
18
|
+
patch?: Operation[];
|
|
19
|
+
}
|
|
20
|
+
export interface PatchContext<T> {
|
|
21
|
+
op: string;
|
|
22
|
+
modelName: string;
|
|
23
|
+
collectionName: string;
|
|
24
|
+
isNew?: boolean;
|
|
25
|
+
createdDocs?: HydratedDocument<T>[];
|
|
26
|
+
deletedDocs?: HydratedDocument<T>[];
|
|
27
|
+
ignoreEvent?: boolean;
|
|
28
|
+
ignorePatchHistory?: boolean;
|
|
29
|
+
}
|
|
30
|
+
export type HookContext<T> = Query<T, T> & {
|
|
31
|
+
op: string;
|
|
32
|
+
_context: PatchContext<T>;
|
|
33
|
+
};
|
|
34
|
+
export type User = Record<string, unknown>;
|
|
35
|
+
export type Metadata = Record<string, unknown>;
|
|
36
|
+
export interface PluginOptions<T> {
|
|
37
|
+
modelName?: string;
|
|
38
|
+
collectionName?: string;
|
|
39
|
+
eventUpdated?: string;
|
|
40
|
+
eventCreated?: string;
|
|
41
|
+
eventDeleted?: string;
|
|
42
|
+
getUser?: () => Promise<User> | User;
|
|
43
|
+
getReason?: () => Promise<string> | string;
|
|
44
|
+
getMetadata?: () => Promise<Metadata> | Metadata;
|
|
45
|
+
omit?: string[];
|
|
46
|
+
patchHistoryDisabled?: boolean;
|
|
47
|
+
preDelete?: (docs: HydratedDocument<T>[]) => Promise<void>;
|
|
48
|
+
}
|
|
49
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|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C,GAAG;IAAE,EAAE,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,YAAY,CAAC,CAAC,CAAC,CAAA;CAAE,CAAA;AAEpF,MAAM,MAAM,IAAI,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;AAE1C,MAAM,MAAM,QAAQ,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;AAE9C,MAAM,WAAW,aAAa,CAAC,CAAC;IAC9B,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,OAAO,CAAC,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAAA;IACpC,SAAS,CAAC,EAAE,MAAM,OAAO,CAAC,MAAM,CAAC,GAAG,MAAM,CAAA;IAC1C,WAAW,CAAC,EAAE,MAAM,OAAO,CAAC,QAAQ,CAAC,GAAG,QAAQ,CAAA;IAChD,IAAI,CAAC,EAAE,MAAM,EAAE,CAAA;IACf,oBAAoB,CAAC,EAAE,OAAO,CAAA;IAC9B,SAAS,CAAC,EAAE,CAAC,IAAI,EAAE,gBAAgB,CAAC,CAAC,CAAC,EAAE,KAAK,OAAO,CAAC,IAAI,CAAC,CAAA;CAC3D"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":""}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ts-patch-mongoose",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.8.0",
|
|
4
4
|
"description": "Patch history & events for mongoose models",
|
|
5
5
|
"author": "Alex Eagle",
|
|
6
6
|
"license": "MIT",
|
|
@@ -25,7 +25,6 @@
|
|
|
25
25
|
"nosql",
|
|
26
26
|
"ts",
|
|
27
27
|
"typescript",
|
|
28
|
-
"swc",
|
|
29
28
|
"patch",
|
|
30
29
|
"history",
|
|
31
30
|
"event",
|
|
@@ -43,7 +42,6 @@
|
|
|
43
42
|
"dist",
|
|
44
43
|
"src",
|
|
45
44
|
"tests",
|
|
46
|
-
".swcrc",
|
|
47
45
|
"tsconfig.json",
|
|
48
46
|
"vite.config.mts",
|
|
49
47
|
"biome.json"
|
|
@@ -89,7 +87,6 @@
|
|
|
89
87
|
"@types/node": "22.10.7",
|
|
90
88
|
"@types/semver": "7.5.8",
|
|
91
89
|
"@vitest/coverage-v8": "3.0.2",
|
|
92
|
-
"merge": "2.1.1",
|
|
93
90
|
"mongodb-memory-server": "10.1.3",
|
|
94
91
|
"mongoose": "8.9.5",
|
|
95
92
|
"open-cli": "8.0.0",
|
package/src/helpers.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import ms from 'ms'
|
|
2
2
|
|
|
3
|
-
import
|
|
3
|
+
import { HistoryModel } from './models/History'
|
|
4
4
|
|
|
5
5
|
import type { QueryOptions, ToObjectOptions } from 'mongoose'
|
|
6
6
|
|
|
@@ -16,12 +16,12 @@ export const toObjectOptions: ToObjectOptions = {
|
|
|
16
16
|
export const setPatchHistoryTTL = async (ttl: number | ms.StringValue): Promise<void> => {
|
|
17
17
|
const name = 'createdAt_1_TTL' // To avoid collision with user defined index / manually created index
|
|
18
18
|
try {
|
|
19
|
-
const indexes = await
|
|
19
|
+
const indexes = await HistoryModel.collection.indexes()
|
|
20
20
|
const existingIndex = indexes?.find((index) => index.name === name)
|
|
21
21
|
|
|
22
22
|
// Drop the index if historyTTL is not set and index exists
|
|
23
23
|
if (!ttl && existingIndex) {
|
|
24
|
-
await
|
|
24
|
+
await HistoryModel.collection.dropIndex(name)
|
|
25
25
|
return
|
|
26
26
|
}
|
|
27
27
|
|
|
@@ -29,7 +29,7 @@ export const setPatchHistoryTTL = async (ttl: number | ms.StringValue): Promise<
|
|
|
29
29
|
|
|
30
30
|
// Drop the index if historyTTL is less than 1 second and index exists
|
|
31
31
|
if (milliseconds < 1000 && existingIndex) {
|
|
32
|
-
await
|
|
32
|
+
await HistoryModel.collection.dropIndex(name)
|
|
33
33
|
return
|
|
34
34
|
}
|
|
35
35
|
|
|
@@ -42,11 +42,11 @@ export const setPatchHistoryTTL = async (ttl: number | ms.StringValue): Promise<
|
|
|
42
42
|
|
|
43
43
|
if (existingIndex) {
|
|
44
44
|
// Drop the existing index if it exists and TTL is different
|
|
45
|
-
await
|
|
45
|
+
await HistoryModel.collection.dropIndex(name)
|
|
46
46
|
}
|
|
47
47
|
|
|
48
48
|
// Create a new index with the correct TTL if it doesn't exist or if the TTL is different
|
|
49
|
-
await
|
|
49
|
+
await HistoryModel.collection.createIndex({ createdAt: 1 }, { expireAfterSeconds, name })
|
|
50
50
|
} catch (err) {
|
|
51
51
|
console.error("Couldn't create or update index for history collection", err)
|
|
52
52
|
}
|
|
@@ -4,13 +4,12 @@ import { isHookIgnored } from '../helpers'
|
|
|
4
4
|
import { deletePatch } from '../patch'
|
|
5
5
|
|
|
6
6
|
import type { HydratedDocument, Model, MongooseQueryMiddleware, Schema } from 'mongoose'
|
|
7
|
-
import type
|
|
8
|
-
import type IPluginOptions from '../interfaces/IPluginOptions'
|
|
7
|
+
import type { HookContext, PluginOptions } from '../types'
|
|
9
8
|
|
|
10
9
|
const deleteMethods = ['remove', 'findOneAndDelete', 'findOneAndRemove', 'findByIdAndDelete', 'findByIdAndRemove', 'deleteOne', 'deleteMany']
|
|
11
10
|
|
|
12
|
-
export const deleteHooksInitialize = <T>(schema: Schema<T>, opts:
|
|
13
|
-
schema.pre(deleteMethods as MongooseQueryMiddleware[], { document: false, query: true }, async function (this:
|
|
11
|
+
export const deleteHooksInitialize = <T>(schema: Schema<T>, opts: PluginOptions<T>): void => {
|
|
12
|
+
schema.pre(deleteMethods as MongooseQueryMiddleware[], { document: false, query: true }, async function (this: HookContext<T>) {
|
|
14
13
|
const options = this.getOptions()
|
|
15
14
|
if (isHookIgnored(options)) return
|
|
16
15
|
|
|
@@ -42,7 +41,7 @@ export const deleteHooksInitialize = <T>(schema: Schema<T>, opts: IPluginOptions
|
|
|
42
41
|
}
|
|
43
42
|
})
|
|
44
43
|
|
|
45
|
-
schema.post(deleteMethods as MongooseQueryMiddleware[], { document: false, query: true }, async function (this:
|
|
44
|
+
schema.post(deleteMethods as MongooseQueryMiddleware[], { document: false, query: true }, async function (this: HookContext<T>) {
|
|
46
45
|
const options = this.getOptions()
|
|
47
46
|
if (isHookIgnored(options)) return
|
|
48
47
|
|
package/src/hooks/save-hooks.ts
CHANGED
|
@@ -2,17 +2,16 @@ import { toObjectOptions } from '../helpers'
|
|
|
2
2
|
import { createPatch, updatePatch } from '../patch'
|
|
3
3
|
|
|
4
4
|
import type { HydratedDocument, Model, Schema } from 'mongoose'
|
|
5
|
-
import type
|
|
6
|
-
import type IPluginOptions from '../interfaces/IPluginOptions'
|
|
5
|
+
import type { PatchContext, PluginOptions } from '../types'
|
|
7
6
|
|
|
8
|
-
export const saveHooksInitialize = <T>(schema: Schema<T>, opts:
|
|
7
|
+
export const saveHooksInitialize = <T>(schema: Schema<T>, opts: PluginOptions<T>): void => {
|
|
9
8
|
schema.pre('save', async function () {
|
|
10
9
|
if (this.constructor.name !== 'model') return
|
|
11
10
|
|
|
12
11
|
const current = this.toObject(toObjectOptions) as HydratedDocument<T>
|
|
13
12
|
const model = this.constructor as Model<T>
|
|
14
13
|
|
|
15
|
-
const context:
|
|
14
|
+
const context: PatchContext<T> = {
|
|
16
15
|
op: this.isNew ? 'create' : 'update',
|
|
17
16
|
modelName: opts.modelName ?? model.modelName,
|
|
18
17
|
collectionName: opts.collectionName ?? model.collection.collectionName,
|
|
@@ -5,8 +5,7 @@ import { isHookIgnored, toObjectOptions } from '../helpers'
|
|
|
5
5
|
import { createPatch, updatePatch } from '../patch'
|
|
6
6
|
|
|
7
7
|
import type { HydratedDocument, Model, MongooseQueryMiddleware, Schema, UpdateQuery, UpdateWithAggregationPipeline } from 'mongoose'
|
|
8
|
-
import type
|
|
9
|
-
import type IPluginOptions from '../interfaces/IPluginOptions'
|
|
8
|
+
import type { HookContext, PluginOptions } from '../types'
|
|
10
9
|
|
|
11
10
|
const updateMethods = ['update', 'updateOne', 'replaceOne', 'updateMany', 'findOneAndUpdate', 'findOneAndReplace', 'findByIdAndUpdate']
|
|
12
11
|
|
|
@@ -44,8 +43,8 @@ export const splitUpdateAndCommands = <T>(updateQuery: UpdateWithAggregationPipe
|
|
|
44
43
|
return { update, commands }
|
|
45
44
|
}
|
|
46
45
|
|
|
47
|
-
export const updateHooksInitialize = <T>(schema: Schema<T>, opts:
|
|
48
|
-
schema.pre(updateMethods as MongooseQueryMiddleware[], async function (this:
|
|
46
|
+
export const updateHooksInitialize = <T>(schema: Schema<T>, opts: PluginOptions<T>): void => {
|
|
47
|
+
schema.pre(updateMethods as MongooseQueryMiddleware[], async function (this: HookContext<T>) {
|
|
49
48
|
const options = this.getOptions()
|
|
50
49
|
if (isHookIgnored(options)) return
|
|
51
50
|
|
|
@@ -72,7 +71,7 @@ export const updateHooksInitialize = <T>(schema: Schema<T>, opts: IPluginOptions
|
|
|
72
71
|
})
|
|
73
72
|
})
|
|
74
73
|
|
|
75
|
-
schema.post(updateMethods as MongooseQueryMiddleware[], async function (this:
|
|
74
|
+
schema.post(updateMethods as MongooseQueryMiddleware[], async function (this: HookContext<T>) {
|
|
76
75
|
const options = this.getOptions()
|
|
77
76
|
if (isHookIgnored(options)) return
|
|
78
77
|
|
package/src/models/History.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { Schema, model } from 'mongoose'
|
|
2
2
|
|
|
3
|
-
import type
|
|
3
|
+
import type { History } from '../types'
|
|
4
4
|
|
|
5
|
-
const HistorySchema = new Schema<
|
|
5
|
+
export const HistorySchema = new Schema<History>(
|
|
6
6
|
{
|
|
7
7
|
op: {
|
|
8
8
|
type: String,
|
|
@@ -47,6 +47,4 @@ const HistorySchema = new Schema<IHistory>(
|
|
|
47
47
|
HistorySchema.index({ collectionId: 1, version: -1 })
|
|
48
48
|
HistorySchema.index({ op: 1, modelName: 1, collectionName: 1, collectionId: 1, reason: 1, version: 1 })
|
|
49
49
|
|
|
50
|
-
const
|
|
51
|
-
|
|
52
|
-
export default History
|
|
50
|
+
export const HistoryModel = model<History>('History', HistorySchema, 'history')
|
package/src/patch.ts
CHANGED
|
@@ -3,20 +3,16 @@ import { chunk, isEmpty, isFunction } from 'lodash'
|
|
|
3
3
|
import omit from 'omit-deep'
|
|
4
4
|
|
|
5
5
|
import type { HydratedDocument, MongooseError, Types } from 'mongoose'
|
|
6
|
-
|
|
7
|
-
import type IContext from './interfaces/IContext'
|
|
8
|
-
import type IEvent from './interfaces/IEvent'
|
|
9
|
-
import type IPluginOptions from './interfaces/IPluginOptions'
|
|
10
|
-
import type { Metadata, User } from './interfaces/IPluginOptions'
|
|
6
|
+
import type { Metadata, PatchContext, PatchEvent, PluginOptions, User } from './types'
|
|
11
7
|
|
|
12
8
|
import em from './em'
|
|
13
|
-
import
|
|
9
|
+
import { HistoryModel } from './models/History'
|
|
14
10
|
|
|
15
|
-
function isPatchHistoryEnabled<T>(opts:
|
|
11
|
+
function isPatchHistoryEnabled<T>(opts: PluginOptions<T>, context: PatchContext<T>): boolean {
|
|
16
12
|
return !opts.patchHistoryDisabled && !context.ignorePatchHistory
|
|
17
13
|
}
|
|
18
14
|
|
|
19
|
-
export function getJsonOmit<T>(opts:
|
|
15
|
+
export function getJsonOmit<T>(opts: PluginOptions<T>, doc: HydratedDocument<T>): Partial<T> {
|
|
20
16
|
const object = JSON.parse(JSON.stringify(doc)) as Partial<T>
|
|
21
17
|
|
|
22
18
|
if (opts.omit) {
|
|
@@ -26,7 +22,7 @@ export function getJsonOmit<T>(opts: IPluginOptions<T>, doc: HydratedDocument<T>
|
|
|
26
22
|
return object
|
|
27
23
|
}
|
|
28
24
|
|
|
29
|
-
export function getObjectOmit<T>(opts:
|
|
25
|
+
export function getObjectOmit<T>(opts: PluginOptions<T>, doc: HydratedDocument<T>): Partial<T> {
|
|
30
26
|
if (opts.omit) {
|
|
31
27
|
return omit(isFunction(doc?.toObject) ? doc.toObject() : doc, opts.omit)
|
|
32
28
|
}
|
|
@@ -34,21 +30,21 @@ export function getObjectOmit<T>(opts: IPluginOptions<T>, doc: HydratedDocument<
|
|
|
34
30
|
return doc
|
|
35
31
|
}
|
|
36
32
|
|
|
37
|
-
export async function getUser<T>(opts:
|
|
33
|
+
export async function getUser<T>(opts: PluginOptions<T>): Promise<User | undefined> {
|
|
38
34
|
if (isFunction(opts.getUser)) {
|
|
39
35
|
return await opts.getUser()
|
|
40
36
|
}
|
|
41
37
|
return undefined
|
|
42
38
|
}
|
|
43
39
|
|
|
44
|
-
export async function getReason<T>(opts:
|
|
40
|
+
export async function getReason<T>(opts: PluginOptions<T>): Promise<string | undefined> {
|
|
45
41
|
if (isFunction(opts.getReason)) {
|
|
46
42
|
return await opts.getReason()
|
|
47
43
|
}
|
|
48
44
|
return undefined
|
|
49
45
|
}
|
|
50
46
|
|
|
51
|
-
export async function getMetadata<T>(opts:
|
|
47
|
+
export async function getMetadata<T>(opts: PluginOptions<T>): Promise<Metadata | undefined> {
|
|
52
48
|
if (isFunction(opts.getMetadata)) {
|
|
53
49
|
return await opts.getMetadata()
|
|
54
50
|
}
|
|
@@ -59,19 +55,19 @@ export function getValue<T>(item: PromiseSettledResult<T>): T | undefined {
|
|
|
59
55
|
return item.status === 'fulfilled' ? item.value : undefined
|
|
60
56
|
}
|
|
61
57
|
|
|
62
|
-
export async function getData<T>(opts:
|
|
58
|
+
export async function getData<T>(opts: PluginOptions<T>): Promise<[User | undefined, string | undefined, Metadata | undefined]> {
|
|
63
59
|
return Promise.allSettled([getUser(opts), getReason(opts), getMetadata(opts)]).then(([user, reason, metadata]) => {
|
|
64
60
|
return [getValue(user), getValue(reason), getValue(metadata)]
|
|
65
61
|
})
|
|
66
62
|
}
|
|
67
63
|
|
|
68
|
-
export function emitEvent<T>(context:
|
|
64
|
+
export function emitEvent<T>(context: PatchContext<T>, event: string | undefined, data: PatchEvent<T>): void {
|
|
69
65
|
if (event && !context.ignoreEvent) {
|
|
70
66
|
em.emit(event, data)
|
|
71
67
|
}
|
|
72
68
|
}
|
|
73
69
|
|
|
74
|
-
export async function bulkPatch<T>(opts:
|
|
70
|
+
export async function bulkPatch<T>(opts: PluginOptions<T>, context: PatchContext<T>, eventKey: 'eventCreated' | 'eventDeleted', docsKey: 'createdDocs' | 'deletedDocs'): Promise<void> {
|
|
75
71
|
const history = isPatchHistoryEnabled(opts, context)
|
|
76
72
|
const event = opts[eventKey]
|
|
77
73
|
const docs = context[docsKey]
|
|
@@ -108,18 +104,18 @@ export async function bulkPatch<T>(opts: IPluginOptions<T>, context: IContext<T>
|
|
|
108
104
|
}
|
|
109
105
|
|
|
110
106
|
if (history && !isEmpty(bulk)) {
|
|
111
|
-
await
|
|
107
|
+
await HistoryModel.bulkWrite(bulk, { ordered: false }).catch((error: MongooseError) => {
|
|
112
108
|
console.error(error.message)
|
|
113
109
|
})
|
|
114
110
|
}
|
|
115
111
|
}
|
|
116
112
|
}
|
|
117
113
|
|
|
118
|
-
export async function createPatch<T>(opts:
|
|
114
|
+
export async function createPatch<T>(opts: PluginOptions<T>, context: PatchContext<T>): Promise<void> {
|
|
119
115
|
await bulkPatch(opts, context, 'eventCreated', 'createdDocs')
|
|
120
116
|
}
|
|
121
117
|
|
|
122
|
-
export async function updatePatch<T>(opts:
|
|
118
|
+
export async function updatePatch<T>(opts: PluginOptions<T>, context: PatchContext<T>, current: HydratedDocument<T>, original: HydratedDocument<T>): Promise<void> {
|
|
123
119
|
const history = isPatchHistoryEnabled(opts, context)
|
|
124
120
|
|
|
125
121
|
const currentObject = getJsonOmit(opts, current)
|
|
@@ -134,7 +130,7 @@ export async function updatePatch<T>(opts: IPluginOptions<T>, context: IContext<
|
|
|
134
130
|
if (history) {
|
|
135
131
|
let version = 0
|
|
136
132
|
|
|
137
|
-
const lastHistory = await
|
|
133
|
+
const lastHistory = await HistoryModel.findOne({ collectionId: original._id as Types.ObjectId })
|
|
138
134
|
.sort('-version')
|
|
139
135
|
.exec()
|
|
140
136
|
|
|
@@ -144,7 +140,7 @@ export async function updatePatch<T>(opts: IPluginOptions<T>, context: IContext<
|
|
|
144
140
|
|
|
145
141
|
const [user, reason, metadata] = await getData(opts)
|
|
146
142
|
|
|
147
|
-
await
|
|
143
|
+
await HistoryModel.create({
|
|
148
144
|
op: context.op,
|
|
149
145
|
modelName: context.modelName,
|
|
150
146
|
collectionName: context.collectionName,
|
|
@@ -158,6 +154,6 @@ export async function updatePatch<T>(opts: IPluginOptions<T>, context: IContext<
|
|
|
158
154
|
}
|
|
159
155
|
}
|
|
160
156
|
|
|
161
|
-
export async function deletePatch<T>(opts:
|
|
157
|
+
export async function deletePatch<T>(opts: PluginOptions<T>, context: PatchContext<T>): Promise<void> {
|
|
162
158
|
await bulkPatch(opts, context, 'eventDeleted', 'deletedDocs')
|
|
163
159
|
}
|