ts-patch-mongoose 2.9.6 → 3.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +42 -27
- package/biome.json +2 -5
- package/dist/index.cjs +307 -93
- package/dist/index.d.cts +42 -3
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +42 -3
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +307 -93
- package/package.json +13 -19
- package/src/helpers.ts +132 -10
- package/src/hooks/delete-hooks.ts +5 -7
- package/src/hooks/update-hooks.ts +48 -34
- package/src/index.ts +4 -32
- package/src/ms.ts +66 -0
- package/src/omit-deep.ts +56 -0
- package/src/patch.ts +42 -47
- package/src/types.ts +1 -0
- package/src/version.ts +5 -4
- package/tests/em.test.ts +26 -8
- package/tests/helpers.test.ts +291 -2
- package/tests/ms.test.ts +113 -0
- package/tests/omit-deep.test.ts +235 -0
- package/tests/patch.test.ts +6 -5
- package/tests/plugin-all-features.test.ts +844 -0
- package/tests/plugin-complex-data.test.ts +2647 -0
- package/tests/plugin-event-created.test.ts +10 -10
- package/tests/plugin-event-deleted.test.ts +10 -10
- package/tests/plugin-event-updated.test.ts +9 -9
- package/tests/plugin-global.test.ts +6 -6
- package/tests/plugin-omit-all.test.ts +1 -1
- package/tests/plugin-patch-history-disabled.test.ts +1 -1
- package/tests/plugin-pre-delete.test.ts +8 -8
- package/tests/plugin-pre-save.test.ts +2 -2
- package/tests/plugin.test.ts +3 -3
- package/tsconfig.json +2 -3
- package/vite.config.mts +2 -1
- package/src/modules/omit-deep.d.ts +0 -3
package/dist/index.d.cts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { Types, Query, HydratedDocument, Schema } from 'mongoose';
|
|
2
2
|
import { Operation } from 'fast-json-patch';
|
|
3
3
|
import EventEmitter from 'node:events';
|
|
4
|
-
import ms from 'ms';
|
|
5
4
|
|
|
6
5
|
interface History {
|
|
7
6
|
op: string;
|
|
@@ -48,16 +47,56 @@ interface PluginOptions<T> {
|
|
|
48
47
|
omit?: string[];
|
|
49
48
|
patchHistoryDisabled?: boolean;
|
|
50
49
|
preDelete?: (docs: HydratedDocument<T>[]) => Promise<void>;
|
|
50
|
+
onError?: (error: Error) => void;
|
|
51
51
|
}
|
|
52
52
|
|
|
53
53
|
declare class PatchEventEmitter extends EventEmitter {
|
|
54
54
|
}
|
|
55
55
|
declare const em: PatchEventEmitter;
|
|
56
56
|
|
|
57
|
-
declare const
|
|
57
|
+
declare const UNITS: {
|
|
58
|
+
readonly milliseconds: 1;
|
|
59
|
+
readonly millisecond: 1;
|
|
60
|
+
readonly msecs: 1;
|
|
61
|
+
readonly msec: 1;
|
|
62
|
+
readonly ms: 1;
|
|
63
|
+
readonly seconds: 1000;
|
|
64
|
+
readonly second: 1000;
|
|
65
|
+
readonly secs: 1000;
|
|
66
|
+
readonly sec: 1000;
|
|
67
|
+
readonly s: 1000;
|
|
68
|
+
readonly minutes: number;
|
|
69
|
+
readonly minute: number;
|
|
70
|
+
readonly mins: number;
|
|
71
|
+
readonly min: number;
|
|
72
|
+
readonly m: number;
|
|
73
|
+
readonly hours: number;
|
|
74
|
+
readonly hour: number;
|
|
75
|
+
readonly hrs: number;
|
|
76
|
+
readonly hr: number;
|
|
77
|
+
readonly h: number;
|
|
78
|
+
readonly days: number;
|
|
79
|
+
readonly day: number;
|
|
80
|
+
readonly d: number;
|
|
81
|
+
readonly weeks: number;
|
|
82
|
+
readonly week: number;
|
|
83
|
+
readonly w: number;
|
|
84
|
+
readonly months: number;
|
|
85
|
+
readonly month: number;
|
|
86
|
+
readonly mo: number;
|
|
87
|
+
readonly years: number;
|
|
88
|
+
readonly year: number;
|
|
89
|
+
readonly yrs: number;
|
|
90
|
+
readonly yr: number;
|
|
91
|
+
readonly y: number;
|
|
92
|
+
};
|
|
93
|
+
type Unit = keyof typeof UNITS;
|
|
94
|
+
type Duration = number | `${number}` | `${number}${Unit}` | `${number} ${Unit}`;
|
|
95
|
+
|
|
96
|
+
declare const setPatchHistoryTTL: (ttl: Duration, onError?: (error: Error) => void) => Promise<void>;
|
|
58
97
|
|
|
59
98
|
declare const patchHistoryPlugin: <T>(schema: Schema<T>, opts: PluginOptions<T>) => void;
|
|
60
99
|
|
|
61
100
|
export { em as patchEventEmitter, patchHistoryPlugin, setPatchHistoryTTL };
|
|
62
|
-
export type { History, HookContext, Metadata, PatchContext, PatchEvent, PluginOptions, User };
|
|
101
|
+
export type { Duration, History, HookContext, Metadata, PatchContext, PatchEvent, PluginOptions, User };
|
|
63
102
|
//# sourceMappingURL=index.d.cts.map
|
package/dist/index.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.cts","sources":["../src/types.ts","../src/em.ts","../src/helpers.ts","../src/index.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.cts","sources":["../src/types.ts","../src/em.ts","../src/ms.ts","../src/helpers.ts","../src/index.ts"],"mappings":";;;;AAGM,UAAW,OAAO;;;;kBAIR,KAAK,CAAC,QAAQ;;;;;;YAMpB,SAAS;;AAGb,UAAW,UAAU;aAChB,gBAAgB;UACnB,gBAAgB;YACd,SAAS;;AAGb,UAAW,YAAY;;;;;kBAKb,gBAAgB;kBAChB,gBAAgB;;;;AAK1B,KAAM,WAAW,MAAM,KAAK;;cAAiC,YAAY;;AAEzE,KAAM,IAAI,GAAG,MAAM;AAEnB,KAAM,QAAQ,GAAG,MAAM;AAEvB,UAAW,aAAa;;;;;;oBAMZ,gBAAgB,QAAQ,OAAO,CAAC,IAAI,IAAI,IAAI;sBAC1C,gBAAgB,QAAQ,OAAO;wBAC7B,gBAAgB,QAAQ,OAAO,CAAC,QAAQ,IAAI,QAAQ;;;uBAGrD,gBAAgB,UAAU,OAAO;sBAClC,KAAK;;;ACjDzB,cAAM,iBAAkB,SAAQ,YAAY;;AAC5C,cAAM,EAAE,mBAA0B;;ACKlC,cAAa,KAAK;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAqCZ,KAAM,IAAI,gBAAgB,KAAK;AAE/B,KAAM,QAAQ,sCAAsC,IAAI,kBAAkB,IAAI;;AC6FpF,cAAa,kBAAkB,QAAe,QAAQ,oBAAoB,KAAK,cAAY,OAAO;;AC1HlG,cAAa,kBAAkB,cAAe,MAAM,WAAW,aAAa","names":[]}
|
package/dist/index.d.mts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { Types, Query, HydratedDocument, Schema } from 'mongoose';
|
|
2
2
|
import { Operation } from 'fast-json-patch';
|
|
3
3
|
import EventEmitter from 'node:events';
|
|
4
|
-
import ms from 'ms';
|
|
5
4
|
|
|
6
5
|
interface History {
|
|
7
6
|
op: string;
|
|
@@ -48,16 +47,56 @@ interface PluginOptions<T> {
|
|
|
48
47
|
omit?: string[];
|
|
49
48
|
patchHistoryDisabled?: boolean;
|
|
50
49
|
preDelete?: (docs: HydratedDocument<T>[]) => Promise<void>;
|
|
50
|
+
onError?: (error: Error) => void;
|
|
51
51
|
}
|
|
52
52
|
|
|
53
53
|
declare class PatchEventEmitter extends EventEmitter {
|
|
54
54
|
}
|
|
55
55
|
declare const em: PatchEventEmitter;
|
|
56
56
|
|
|
57
|
-
declare const
|
|
57
|
+
declare const UNITS: {
|
|
58
|
+
readonly milliseconds: 1;
|
|
59
|
+
readonly millisecond: 1;
|
|
60
|
+
readonly msecs: 1;
|
|
61
|
+
readonly msec: 1;
|
|
62
|
+
readonly ms: 1;
|
|
63
|
+
readonly seconds: 1000;
|
|
64
|
+
readonly second: 1000;
|
|
65
|
+
readonly secs: 1000;
|
|
66
|
+
readonly sec: 1000;
|
|
67
|
+
readonly s: 1000;
|
|
68
|
+
readonly minutes: number;
|
|
69
|
+
readonly minute: number;
|
|
70
|
+
readonly mins: number;
|
|
71
|
+
readonly min: number;
|
|
72
|
+
readonly m: number;
|
|
73
|
+
readonly hours: number;
|
|
74
|
+
readonly hour: number;
|
|
75
|
+
readonly hrs: number;
|
|
76
|
+
readonly hr: number;
|
|
77
|
+
readonly h: number;
|
|
78
|
+
readonly days: number;
|
|
79
|
+
readonly day: number;
|
|
80
|
+
readonly d: number;
|
|
81
|
+
readonly weeks: number;
|
|
82
|
+
readonly week: number;
|
|
83
|
+
readonly w: number;
|
|
84
|
+
readonly months: number;
|
|
85
|
+
readonly month: number;
|
|
86
|
+
readonly mo: number;
|
|
87
|
+
readonly years: number;
|
|
88
|
+
readonly year: number;
|
|
89
|
+
readonly yrs: number;
|
|
90
|
+
readonly yr: number;
|
|
91
|
+
readonly y: number;
|
|
92
|
+
};
|
|
93
|
+
type Unit = keyof typeof UNITS;
|
|
94
|
+
type Duration = number | `${number}` | `${number}${Unit}` | `${number} ${Unit}`;
|
|
95
|
+
|
|
96
|
+
declare const setPatchHistoryTTL: (ttl: Duration, onError?: (error: Error) => void) => Promise<void>;
|
|
58
97
|
|
|
59
98
|
declare const patchHistoryPlugin: <T>(schema: Schema<T>, opts: PluginOptions<T>) => void;
|
|
60
99
|
|
|
61
100
|
export { em as patchEventEmitter, patchHistoryPlugin, setPatchHistoryTTL };
|
|
62
|
-
export type { History, HookContext, Metadata, PatchContext, PatchEvent, PluginOptions, User };
|
|
101
|
+
export type { Duration, History, HookContext, Metadata, PatchContext, PatchEvent, PluginOptions, User };
|
|
63
102
|
//# sourceMappingURL=index.d.mts.map
|
package/dist/index.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","sources":["../src/types.ts","../src/em.ts","../src/helpers.ts","../src/index.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.mts","sources":["../src/types.ts","../src/em.ts","../src/ms.ts","../src/helpers.ts","../src/index.ts"],"mappings":";;;;AAGM,UAAW,OAAO;;;;kBAIR,KAAK,CAAC,QAAQ;;;;;;YAMpB,SAAS;;AAGb,UAAW,UAAU;aAChB,gBAAgB;UACnB,gBAAgB;YACd,SAAS;;AAGb,UAAW,YAAY;;;;;kBAKb,gBAAgB;kBAChB,gBAAgB;;;;AAK1B,KAAM,WAAW,MAAM,KAAK;;cAAiC,YAAY;;AAEzE,KAAM,IAAI,GAAG,MAAM;AAEnB,KAAM,QAAQ,GAAG,MAAM;AAEvB,UAAW,aAAa;;;;;;oBAMZ,gBAAgB,QAAQ,OAAO,CAAC,IAAI,IAAI,IAAI;sBAC1C,gBAAgB,QAAQ,OAAO;wBAC7B,gBAAgB,QAAQ,OAAO,CAAC,QAAQ,IAAI,QAAQ;;;uBAGrD,gBAAgB,UAAU,OAAO;sBAClC,KAAK;;;ACjDzB,cAAM,iBAAkB,SAAQ,YAAY;;AAC5C,cAAM,EAAE,mBAA0B;;ACKlC,cAAa,KAAK;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAqCZ,KAAM,IAAI,gBAAgB,KAAK;AAE/B,KAAM,QAAQ,sCAAsC,IAAI,kBAAkB,IAAI;;AC6FpF,cAAa,kBAAkB,QAAe,QAAQ,oBAAoB,KAAK,cAAY,OAAO;;AC1HlG,cAAa,kBAAkB,cAAe,MAAM,WAAW,aAAa","names":[]}
|