@tsed/mongoose 7.85.1 → 7.85.2
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/lib/cjs/decorators/postHook.js.map +1 -1
- package/lib/cjs/decorators/preHook.js +21 -59
- package/lib/cjs/decorators/preHook.js.map +1 -1
- package/lib/cjs/utils/schemaOptions.js +4 -3
- package/lib/cjs/utils/schemaOptions.js.map +1 -1
- package/lib/esm/decorators/postHook.js.map +1 -1
- package/lib/esm/decorators/preHook.js +21 -59
- package/lib/esm/decorators/preHook.js.map +1 -1
- package/lib/esm/utils/schemaOptions.js +4 -3
- package/lib/esm/utils/schemaOptions.js.map +1 -1
- package/lib/types/decorators/postHook.d.ts +4 -4
- package/lib/types/decorators/preHook.d.ts +7 -5
- package/lib/types/interfaces/MongooseSchemaOptions.d.ts +8 -10
- package/lib/types/utils/schemaOptions.d.ts +2 -2
- package/lib/types-esm/decorators/postHook.d.ts +4 -4
- package/lib/types-esm/decorators/preHook.d.ts +7 -5
- package/lib/types-esm/interfaces/MongooseSchemaOptions.d.ts +8 -10
- package/lib/types-esm/utils/schemaOptions.d.ts +2 -2
- package/package.json +18 -15
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"postHook.js","sourceRoot":"","sources":["../../../src/decorators/postHook.ts"],"names":[],"mappings":";;;AAAA,qCAAkF;AAElF,gEAAwD;AAgDxD,SAAgB,QAAQ,CAAU,
|
|
1
|
+
{"version":3,"file":"postHook.js","sourceRoot":"","sources":["../../../src/decorators/postHook.ts"],"names":[],"mappings":";;;AAAA,qCAAkF;AAElF,gEAAwD;AAgDxD,SAAgB,QAAQ,CAAU,MAAuB,EAAE,GAAG,MAAa;IACzE,OAAO,CAAC,CAAC,GAAG,IAAW,EAAE,EAAE;QACzB,IAAI,OAAO,GAAwB,MAAM,CAAC,CAAC,CAAC,CAAC;QAC7C,IAAI,EAAE,GAA0B,MAAM,CAAC,CAAC,CAAC,CAAC;QAE1C,IAAI,IAAA,sBAAe,EAAC,IAAI,CAAC,KAAK,qBAAc,CAAC,UAAU,EAAE;YACvD,OAAO,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC;YACpB,EAAE,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;SACrC;QAED,IAAA,gCAAa,EAAC,IAAI,CAAC,CAAC,CAAC,EAAE;YACrB,IAAI,EAAE;gBACJ;oBACE,MAAM;oBACN,EAAE;oBACF,OAAO;iBACR;aACF;SACF,CAAC,CAAC;IACL,CAAC,CAAQ,CAAC;AACZ,CAAC;AApBD,4BAoBC"}
|
|
@@ -3,68 +3,30 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.PreHook = void 0;
|
|
4
4
|
const core_1 = require("@tsed/core");
|
|
5
5
|
const schemaOptions_js_1 = require("../utils/schemaOptions.js");
|
|
6
|
-
|
|
7
|
-
*
|
|
8
|
-
* We can simply attach a `@PreHook` decorator to your model class and
|
|
9
|
-
* define the hook function like you normally would in Mongoose.
|
|
10
|
-
*
|
|
11
|
-
* ```typescript
|
|
12
|
-
* import {Ignore, Required} from "@tsed/common";
|
|
13
|
-
* import {PreHook, Model} from "@tsed/mongoose";
|
|
14
|
-
*
|
|
15
|
-
* @Model()
|
|
16
|
-
* @PreHook("save", (car: CarModel, next) => {
|
|
17
|
-
* if (car.model === 'Tesla') {
|
|
18
|
-
* car.isFast = true;
|
|
19
|
-
* }
|
|
20
|
-
* next();
|
|
21
|
-
*})
|
|
22
|
-
* export class CarModel {
|
|
23
|
-
*
|
|
24
|
-
* @Ignore()
|
|
25
|
-
* _id: string;
|
|
26
|
-
*
|
|
27
|
-
* @Required()
|
|
28
|
-
* model: string;
|
|
29
|
-
*
|
|
30
|
-
* @Required()
|
|
31
|
-
* isFast: boolean;
|
|
32
|
-
*
|
|
33
|
-
* // or Prehook on static method
|
|
34
|
-
* @PreHook("save")
|
|
35
|
-
* static preSave(car: CarModel, next) {
|
|
36
|
-
* if (car.model === 'Tesla') {
|
|
37
|
-
* car.isFast = true;
|
|
38
|
-
* }
|
|
39
|
-
* next();
|
|
40
|
-
* }
|
|
41
|
-
* }
|
|
42
|
-
* ```
|
|
43
|
-
*
|
|
44
|
-
* This will execute the pre-save hook each time a `CarModel` document is saved.
|
|
45
|
-
*
|
|
46
|
-
* @param {string} method
|
|
47
|
-
* @param fn
|
|
48
|
-
* @param options
|
|
49
|
-
* @returns {Function}
|
|
50
|
-
* @decorator
|
|
51
|
-
* @class
|
|
52
|
-
*/
|
|
53
|
-
function PreHook(method, fn, options) {
|
|
6
|
+
function PreHook(method, ...decoratorArgs) {
|
|
54
7
|
return (...args) => {
|
|
55
8
|
if ((0, core_1.decoratorTypeOf)(args) === core_1.DecoratorTypes.METHOD_STC) {
|
|
56
|
-
|
|
57
|
-
|
|
9
|
+
(0, schemaOptions_js_1.schemaOptions)(args[0], {
|
|
10
|
+
pre: [
|
|
11
|
+
{
|
|
12
|
+
method,
|
|
13
|
+
fn: args[0][args[1]].bind(args[0]),
|
|
14
|
+
options: decoratorArgs[0]
|
|
15
|
+
}
|
|
16
|
+
]
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
else {
|
|
20
|
+
(0, schemaOptions_js_1.schemaOptions)(args[0], {
|
|
21
|
+
pre: [
|
|
22
|
+
{
|
|
23
|
+
method,
|
|
24
|
+
fn: decoratorArgs[0],
|
|
25
|
+
options: decoratorArgs[1]
|
|
26
|
+
}
|
|
27
|
+
]
|
|
28
|
+
});
|
|
58
29
|
}
|
|
59
|
-
(0, schemaOptions_js_1.schemaOptions)(args[0], {
|
|
60
|
-
pre: [
|
|
61
|
-
{
|
|
62
|
-
method,
|
|
63
|
-
fn: fn,
|
|
64
|
-
options
|
|
65
|
-
}
|
|
66
|
-
]
|
|
67
|
-
});
|
|
68
30
|
};
|
|
69
31
|
}
|
|
70
32
|
exports.PreHook = PreHook;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"preHook.js","sourceRoot":"","sources":["../../../src/decorators/preHook.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"preHook.js","sourceRoot":"","sources":["../../../src/decorators/preHook.ts"],"names":[],"mappings":";;;AAAA,qCAAkF;AAElF,gEAAwD;AAmDxD,SAAgB,OAAO,CAAU,MAAuB,EAAE,GAAG,aAAoB;IAC/E,OAAO,CAAC,GAAG,IAAW,EAAE,EAAE;QACxB,IAAI,IAAA,sBAAe,EAAC,IAAI,CAAC,KAAK,qBAAc,CAAC,UAAU,EAAE;YACvD,IAAA,gCAAa,EAAC,IAAI,CAAC,CAAC,CAAC,EAAE;gBACrB,GAAG,EAAE;oBACH;wBACE,MAAM;wBACN,EAAE,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;wBAClC,OAAO,EAAE,aAAa,CAAC,CAAC,CAAC;qBAC1B;iBACF;aACF,CAAC,CAAC;SACJ;aAAM;YACL,IAAA,gCAAa,EAAC,IAAI,CAAC,CAAC,CAAC,EAAE;gBACrB,GAAG,EAAE;oBACH;wBACE,MAAM;wBACN,EAAE,EAAE,aAAa,CAAC,CAAC,CAAC;wBACpB,OAAO,EAAE,aAAa,CAAC,CAAC,CAAC;qBAC1B;iBACF;aACF,CAAC,CAAC;SACJ;IACH,CAAC,CAAC;AACJ,CAAC;AAxBD,0BAwBC"}
|
|
@@ -28,9 +28,10 @@ function buildPreHook(fn) {
|
|
|
28
28
|
? function () {
|
|
29
29
|
return fn(this);
|
|
30
30
|
}
|
|
31
|
-
:
|
|
32
|
-
|
|
33
|
-
|
|
31
|
+
: // we need to explicitly gives args to avoid a bug with mongoose
|
|
32
|
+
function (next, arg1, arg2) {
|
|
33
|
+
return fn(this, next, arg1, arg2);
|
|
34
|
+
};
|
|
34
35
|
}
|
|
35
36
|
exports.buildPreHook = buildPreHook;
|
|
36
37
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schemaOptions.js","sourceRoot":"","sources":["../../../src/utils/schemaOptions.ts"],"names":[],"mappings":";;;AAAA,qCAA4C;AAE5C,4DAAkE;
|
|
1
|
+
{"version":3,"file":"schemaOptions.js","sourceRoot":"","sources":["../../../src/utils/schemaOptions.ts"],"names":[],"mappings":";;;AAAA,qCAA4C;AAE5C,4DAAkE;AASlE;;GAEG;AACH,SAAgB,aAAa,CAAC,MAAW,EAAE,OAA+B;IACxE,MAAM,KAAK,GAAG,YAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IAEjC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,sCAAuB,CAAC,EAAE;QACvC,KAAK,CAAC,GAAG,CAAC,sCAAuB,EAAE,EAAE,CAAC,CAAC;KACxC;IAED,IAAI,OAAO,EAAE;QACX,KAAK,CAAC,GAAG,CAAC,sCAAuB,EAAE,IAAA,gBAAS,EAAC,KAAK,CAAC,GAAG,CAAC,sCAAuB,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC;KAC5F;IAED,OAAO,KAAK,CAAC,GAAG,CAAC,sCAAuB,CAAC,CAAC;AAC5C,CAAC;AAZD,sCAYC;AAED,SAAS,WAAW,CAAC,IAAwC;IAC3D,OAAO,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,OAAO,IAAI,IAAI,CAAC,EAAE,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,MAAM,CAAC,OAAO,CAAQ,CAAC;AAC3G,CAAC;AAED;;GAEG;AACH,SAAgB,YAAY,CAAC,EAAqB;IAChD,OAAO,EAAE,CAAC,MAAM,KAAK,CAAC;QACpB,CAAC,CAAC;YACE,OAAQ,EAA2B,CAAC,IAAI,CAAC,CAAC;QAC5C,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oot":"","sources":["../../../src/decorators/postHook.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,eAAe,EAAE,cAAc,EAAwB,MAAM,YAAY,CAAC;AAElF,OAAO,EAAC,aAAa,EAAC,MAAM,2BAA2B,CAAC;AAgDxD,MAAM,UAAU,QAAQ,CAAU,
|
|
1
|
+
{"version":3,"file":"postHook.js","sourceRoot":"","sources":["../../../src/decorators/postHook.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,eAAe,EAAE,cAAc,EAAwB,MAAM,YAAY,CAAC;AAElF,OAAO,EAAC,aAAa,EAAC,MAAM,2BAA2B,CAAC;AAgDxD,MAAM,UAAU,QAAQ,CAAU,MAAuB,EAAE,GAAG,MAAa;IACzE,OAAO,CAAC,CAAC,GAAG,IAAW,EAAE,EAAE;QACzB,IAAI,OAAO,GAAwB,MAAM,CAAC,CAAC,CAAC,CAAC;QAC7C,IAAI,EAAE,GAA0B,MAAM,CAAC,CAAC,CAAC,CAAC;QAE1C,IAAI,eAAe,CAAC,IAAI,CAAC,KAAK,cAAc,CAAC,UAAU,EAAE;YACvD,OAAO,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC;YACpB,EAAE,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;SACrC;QAED,aAAa,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE;YACrB,IAAI,EAAE;gBACJ;oBACE,MAAM;oBACN,EAAE;oBACF,OAAO;iBACR;aACF;SACF,CAAC,CAAC;IACL,CAAC,CAAQ,CAAC;AACZ,CAAC"}
|
|
@@ -1,67 +1,29 @@
|
|
|
1
1
|
import { decoratorTypeOf, DecoratorTypes } from "@tsed/core";
|
|
2
2
|
import { schemaOptions } from "../utils/schemaOptions.js";
|
|
3
|
-
|
|
4
|
-
*
|
|
5
|
-
* We can simply attach a `@PreHook` decorator to your model class and
|
|
6
|
-
* define the hook function like you normally would in Mongoose.
|
|
7
|
-
*
|
|
8
|
-
* ```typescript
|
|
9
|
-
* import {Ignore, Required} from "@tsed/common";
|
|
10
|
-
* import {PreHook, Model} from "@tsed/mongoose";
|
|
11
|
-
*
|
|
12
|
-
* @Model()
|
|
13
|
-
* @PreHook("save", (car: CarModel, next) => {
|
|
14
|
-
* if (car.model === 'Tesla') {
|
|
15
|
-
* car.isFast = true;
|
|
16
|
-
* }
|
|
17
|
-
* next();
|
|
18
|
-
*})
|
|
19
|
-
* export class CarModel {
|
|
20
|
-
*
|
|
21
|
-
* @Ignore()
|
|
22
|
-
* _id: string;
|
|
23
|
-
*
|
|
24
|
-
* @Required()
|
|
25
|
-
* model: string;
|
|
26
|
-
*
|
|
27
|
-
* @Required()
|
|
28
|
-
* isFast: boolean;
|
|
29
|
-
*
|
|
30
|
-
* // or Prehook on static method
|
|
31
|
-
* @PreHook("save")
|
|
32
|
-
* static preSave(car: CarModel, next) {
|
|
33
|
-
* if (car.model === 'Tesla') {
|
|
34
|
-
* car.isFast = true;
|
|
35
|
-
* }
|
|
36
|
-
* next();
|
|
37
|
-
* }
|
|
38
|
-
* }
|
|
39
|
-
* ```
|
|
40
|
-
*
|
|
41
|
-
* This will execute the pre-save hook each time a `CarModel` document is saved.
|
|
42
|
-
*
|
|
43
|
-
* @param {string} method
|
|
44
|
-
* @param fn
|
|
45
|
-
* @param options
|
|
46
|
-
* @returns {Function}
|
|
47
|
-
* @decorator
|
|
48
|
-
* @class
|
|
49
|
-
*/
|
|
50
|
-
export function PreHook(method, fn, options) {
|
|
3
|
+
export function PreHook(method, ...decoratorArgs) {
|
|
51
4
|
return (...args) => {
|
|
52
5
|
if (decoratorTypeOf(args) === DecoratorTypes.METHOD_STC) {
|
|
53
|
-
|
|
54
|
-
|
|
6
|
+
schemaOptions(args[0], {
|
|
7
|
+
pre: [
|
|
8
|
+
{
|
|
9
|
+
method,
|
|
10
|
+
fn: args[0][args[1]].bind(args[0]),
|
|
11
|
+
options: decoratorArgs[0]
|
|
12
|
+
}
|
|
13
|
+
]
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
else {
|
|
17
|
+
schemaOptions(args[0], {
|
|
18
|
+
pre: [
|
|
19
|
+
{
|
|
20
|
+
method,
|
|
21
|
+
fn: decoratorArgs[0],
|
|
22
|
+
options: decoratorArgs[1]
|
|
23
|
+
}
|
|
24
|
+
]
|
|
25
|
+
});
|
|
55
26
|
}
|
|
56
|
-
schemaOptions(args[0], {
|
|
57
|
-
pre: [
|
|
58
|
-
{
|
|
59
|
-
method,
|
|
60
|
-
fn: fn,
|
|
61
|
-
options
|
|
62
|
-
}
|
|
63
|
-
]
|
|
64
|
-
});
|
|
65
27
|
};
|
|
66
28
|
}
|
|
67
29
|
//# sourceMappingURL=preHook.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"preHook.js","sourceRoot":"","sources":["../../../src/decorators/preHook.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,eAAe,EAAE,cAAc,
|
|
1
|
+
{"version":3,"file":"preHook.js","sourceRoot":"","sources":["../../../src/decorators/preHook.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,eAAe,EAAE,cAAc,EAAwB,MAAM,YAAY,CAAC;AAElF,OAAO,EAAC,aAAa,EAAC,MAAM,2BAA2B,CAAC;AAmDxD,MAAM,UAAU,OAAO,CAAU,MAAuB,EAAE,GAAG,aAAoB;IAC/E,OAAO,CAAC,GAAG,IAAW,EAAE,EAAE;QACxB,IAAI,eAAe,CAAC,IAAI,CAAC,KAAK,cAAc,CAAC,UAAU,EAAE;YACvD,aAAa,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE;gBACrB,GAAG,EAAE;oBACH;wBACE,MAAM;wBACN,EAAE,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;wBAClC,OAAO,EAAE,aAAa,CAAC,CAAC,CAAC;qBAC1B;iBACF;aACF,CAAC,CAAC;SACJ;aAAM;YACL,aAAa,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE;gBACrB,GAAG,EAAE;oBACH;wBACE,MAAM;wBACN,EAAE,EAAE,aAAa,CAAC,CAAC,CAAC;wBACpB,OAAO,EAAE,aAAa,CAAC,CAAC,CAAC;qBAC1B;iBACF;aACF,CAAC,CAAC;SACJ;IACH,CAAC,CAAC;AACJ,CAAC"}
|
|
@@ -24,9 +24,10 @@ export function buildPreHook(fn) {
|
|
|
24
24
|
? function () {
|
|
25
25
|
return fn(this);
|
|
26
26
|
}
|
|
27
|
-
:
|
|
28
|
-
|
|
29
|
-
|
|
27
|
+
: // we need to explicitly gives args to avoid a bug with mongoose
|
|
28
|
+
function (next, arg1, arg2) {
|
|
29
|
+
return fn(this, next, arg1, arg2);
|
|
30
|
+
};
|
|
30
31
|
}
|
|
31
32
|
/**
|
|
32
33
|
* @ignore
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schemaOptions.js","sourceRoot":"","sources":["../../../src/utils/schemaOptions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,SAAS,EAAE,KAAK,EAAC,MAAM,YAAY,CAAC;AAE5C,OAAO,EAAC,uBAAuB,EAAC,MAAM,2BAA2B,CAAC;
|
|
1
|
+
{"version":3,"file":"schemaOptions.js","sourceRoot":"","sources":["../../../src/utils/schemaOptions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,SAAS,EAAE,KAAK,EAAC,MAAM,YAAY,CAAC;AAE5C,OAAO,EAAC,uBAAuB,EAAC,MAAM,2BAA2B,CAAC;AASlE;;GAEG;AACH,MAAM,UAAU,aAAa,CAAC,MAAW,EAAE,OAA+B;IACxE,MAAM,KAAK,GAAG,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IAEjC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,uBAAuB,CAAC,EAAE;QACvC,KAAK,CA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E,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC;KAC5E;IAED,IAAI,OAAO,CAAC,GAAG,EAAE;QACf,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE;YAC3B,IAAI,GAAG;gBACL,GAAG,IAAI;gBACP,EAAE,EAAE,YAAY,CAAC,IAAI,CAAC,EAAE,CAAC;aAC1B,CAAC;YAED,MAAM,CAAC,GAAW,CAAC,GAAG,WAAW,CAAC,IAAI,CAAC,CAAC,CAAC;QAC5C,CAAC,CAAC,CAAC;KACJ;IAED,IAAI,OAAO,CAAC,IAAI,EAAE;QAChB,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE,CAAE,MAAM,CAAC,IAAY,CAAC,GAAG,WAAW,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;KAC5E;AACH,CAAC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { StaticMethodDecorator } from "@tsed/core";
|
|
2
|
-
import { MongooseHookOptions, MongoosePostHookCB } from "../interfaces/MongooseSchemaOptions.js";
|
|
2
|
+
import { MongooseHookOptions, MongooseMethods, MongoosePostHookCB } from "../interfaces/MongooseSchemaOptions.js";
|
|
3
3
|
/**
|
|
4
4
|
* We can simply attach a `@PostHook` decorator to your model class and
|
|
5
5
|
* define the hook function like you normally would in Mongoose.
|
|
@@ -43,6 +43,6 @@ import { MongooseHookOptions, MongoosePostHookCB } from "../interfaces/MongooseS
|
|
|
43
43
|
* @mongoose
|
|
44
44
|
* @class
|
|
45
45
|
*/
|
|
46
|
-
export declare function PostHook<T = any>(method:
|
|
47
|
-
export declare function PostHook<T = any>(method:
|
|
48
|
-
export declare function PostHook<T = any>(method:
|
|
46
|
+
export declare function PostHook<T = any>(method: MongooseMethods, fn: MongoosePostHookCB<T>): ClassDecorator;
|
|
47
|
+
export declare function PostHook<T = any>(method: MongooseMethods, fn: MongoosePostHookCB<T>, options: MongooseHookOptions): ClassDecorator;
|
|
48
|
+
export declare function PostHook<T = any>(method: MongooseMethods, options: MongooseHookOptions): StaticMethodDecorator;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { StaticMethodDecorator } from "@tsed/core";
|
|
2
|
+
import type { MongooseHookOptions, MongooseMethods, MongoosePreHookCB } from "../interfaces/MongooseSchemaOptions.js";
|
|
2
3
|
/**
|
|
3
4
|
*
|
|
4
5
|
* We can simply attach a `@PreHook` decorator to your model class and
|
|
@@ -39,11 +40,12 @@ import { MongooseHookOptions, MongoosePreHookCB } from "../interfaces/MongooseSc
|
|
|
39
40
|
*
|
|
40
41
|
* This will execute the pre-save hook each time a `CarModel` document is saved.
|
|
41
42
|
*
|
|
42
|
-
* @param {string} method
|
|
43
|
-
* @param fn
|
|
44
|
-
* @param options
|
|
45
43
|
* @returns {Function}
|
|
46
44
|
* @decorator
|
|
47
45
|
* @class
|
|
46
|
+
* @param method
|
|
47
|
+
* @param fn
|
|
48
|
+
* @param options
|
|
48
49
|
*/
|
|
49
|
-
export declare function PreHook<T = any>(method:
|
|
50
|
+
export declare function PreHook<T = any>(method: MongooseMethods, fn: MongoosePreHookCB<T>, options?: MongooseHookOptions): ClassDecorator;
|
|
51
|
+
export declare function PreHook<T = any>(method: MongooseMethods, options?: MongooseHookOptions): StaticMethodDecorator;
|
|
@@ -1,21 +1,19 @@
|
|
|
1
1
|
import { type IndexOptions, Schema, SchemaOptions } from "mongoose";
|
|
2
2
|
import { MongooseDocument } from "./MongooseDocument.js";
|
|
3
|
+
export type MongooseMethod = "aggregate" | "bulkWrite" | "createCollection" | "save" | "insertMany" | "estimatedDocumentCount" | "countDocuments" | "deleteMany" | "distinct" | "find" | "findOne" | "findOneAndDelete" | "findOneAndReplace" | "findOneAndUpdate" | "replaceOne" | "updateMany" | "init" | "validate";
|
|
4
|
+
export type MongooseMethods = MongooseMethod | RegExp | MongooseMethod[];
|
|
3
5
|
export type MongooseNextCB = (err?: Error) => void;
|
|
4
|
-
export
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
}
|
|
9
|
-
export type MongooseHookPromised<T = any> = (doc: T | MongooseDocument<T>) => Promise<void> | void;
|
|
10
|
-
export type MongoosePreHookCB<T = any> = ((doc: T | MongooseDocument<T>, next: MongooseNextCB) => void) | MongooseHookPromised;
|
|
11
|
-
export type MongoosePostHookCB<T = any> = ((doc: T | MongooseDocument<T>, error: Error, next: MongooseNextCB) => void) | ((doc: T | MongooseDocument<T>, error: Error) => Promise<void> | void) | ((doc: T | MongooseDocument<T>, next: MongooseNextCB) => void) | MongooseHookPromised;
|
|
6
|
+
export type MongooseHookOptions = Record<string, unknown>;
|
|
7
|
+
export type MongooseHookPromised<T = any> = (doc: T | MongooseDocument<T>) => Promise<void>;
|
|
8
|
+
export type MongoosePreHookCB<T = any> = (doc: T | MongooseDocument<T>, ...args: unknown[]) => Promise<void> | void;
|
|
9
|
+
export type MongoosePostHookCB<T = any> = (doc: T | MongooseDocument<T>, ...args: unknown[]) => Promise<void> | void;
|
|
12
10
|
export interface MongoosePreHook<T = any> {
|
|
13
|
-
method:
|
|
11
|
+
method: MongooseMethods;
|
|
14
12
|
fn: MongoosePreHookCB<T>;
|
|
15
13
|
options?: MongooseHookOptions;
|
|
16
14
|
}
|
|
17
15
|
export interface MongoosePostHook<T = any> {
|
|
18
|
-
method:
|
|
16
|
+
method: MongooseMethods;
|
|
19
17
|
fn: MongoosePostHookCB<T>;
|
|
20
18
|
options?: MongooseHookOptions;
|
|
21
19
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Schema } from "mongoose";
|
|
2
|
-
import {
|
|
2
|
+
import { MongoosePreHookCB, MongooseSchemaOptions } from "../interfaces/MongooseSchemaOptions.js";
|
|
3
3
|
/**
|
|
4
4
|
* @ignore
|
|
5
5
|
*/
|
|
@@ -7,7 +7,7 @@ export declare function schemaOptions(target: any, options?: MongooseSchemaOptio
|
|
|
7
7
|
/**
|
|
8
8
|
* @ignore
|
|
9
9
|
*/
|
|
10
|
-
export declare function buildPreHook(fn: MongoosePreHookCB): (next:
|
|
10
|
+
export declare function buildPreHook(fn: MongoosePreHookCB): (next: any, arg1: any, arg2: any) => any;
|
|
11
11
|
/**
|
|
12
12
|
* @ignore
|
|
13
13
|
*/
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { StaticMethodDecorator } from "@tsed/core";
|
|
2
|
-
import { MongooseHookOptions, MongoosePostHookCB } from "../interfaces/MongooseSchemaOptions.js";
|
|
2
|
+
import { MongooseHookOptions, MongooseMethods, MongoosePostHookCB } from "../interfaces/MongooseSchemaOptions.js";
|
|
3
3
|
/**
|
|
4
4
|
* We can simply attach a `@PostHook` decorator to your model class and
|
|
5
5
|
* define the hook function like you normally would in Mongoose.
|
|
@@ -43,6 +43,6 @@ import { MongooseHookOptions, MongoosePostHookCB } from "../interfaces/MongooseS
|
|
|
43
43
|
* @mongoose
|
|
44
44
|
* @class
|
|
45
45
|
*/
|
|
46
|
-
export declare function PostHook<T = any>(method:
|
|
47
|
-
export declare function PostHook<T = any>(method:
|
|
48
|
-
export declare function PostHook<T = any>(method:
|
|
46
|
+
export declare function PostHook<T = any>(method: MongooseMethods, fn: MongoosePostHookCB<T>): ClassDecorator;
|
|
47
|
+
export declare function PostHook<T = any>(method: MongooseMethods, fn: MongoosePostHookCB<T>, options: MongooseHookOptions): ClassDecorator;
|
|
48
|
+
export declare function PostHook<T = any>(method: MongooseMethods, options: MongooseHookOptions): StaticMethodDecorator;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { StaticMethodDecorator } from "@tsed/core";
|
|
2
|
+
import type { MongooseHookOptions, MongooseMethods, MongoosePreHookCB } from "../interfaces/MongooseSchemaOptions.js";
|
|
2
3
|
/**
|
|
3
4
|
*
|
|
4
5
|
* We can simply attach a `@PreHook` decorator to your model class and
|
|
@@ -39,11 +40,12 @@ import { MongooseHookOptions, MongoosePreHookCB } from "../interfaces/MongooseSc
|
|
|
39
40
|
*
|
|
40
41
|
* This will execute the pre-save hook each time a `CarModel` document is saved.
|
|
41
42
|
*
|
|
42
|
-
* @param {string} method
|
|
43
|
-
* @param fn
|
|
44
|
-
* @param options
|
|
45
43
|
* @returns {Function}
|
|
46
44
|
* @decorator
|
|
47
45
|
* @class
|
|
46
|
+
* @param method
|
|
47
|
+
* @param fn
|
|
48
|
+
* @param options
|
|
48
49
|
*/
|
|
49
|
-
export declare function PreHook<T = any>(method:
|
|
50
|
+
export declare function PreHook<T = any>(method: MongooseMethods, fn: MongoosePreHookCB<T>, options?: MongooseHookOptions): ClassDecorator;
|
|
51
|
+
export declare function PreHook<T = any>(method: MongooseMethods, options?: MongooseHookOptions): StaticMethodDecorator;
|
|
@@ -1,21 +1,19 @@
|
|
|
1
1
|
import { type IndexOptions, Schema, SchemaOptions } from "mongoose";
|
|
2
2
|
import { MongooseDocument } from "./MongooseDocument.js";
|
|
3
|
+
export type MongooseMethod = "aggregate" | "bulkWrite" | "createCollection" | "save" | "insertMany" | "estimatedDocumentCount" | "countDocuments" | "deleteMany" | "distinct" | "find" | "findOne" | "findOneAndDelete" | "findOneAndReplace" | "findOneAndUpdate" | "replaceOne" | "updateMany" | "init" | "validate";
|
|
4
|
+
export type MongooseMethods = MongooseMethod | RegExp | MongooseMethod[];
|
|
3
5
|
export type MongooseNextCB = (err?: Error) => void;
|
|
4
|
-
export
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
}
|
|
9
|
-
export type MongooseHookPromised<T = any> = (doc: T | MongooseDocument<T>) => Promise<void> | void;
|
|
10
|
-
export type MongoosePreHookCB<T = any> = ((doc: T | MongooseDocument<T>, next: MongooseNextCB) => void) | MongooseHookPromised;
|
|
11
|
-
export type MongoosePostHookCB<T = any> = ((doc: T | MongooseDocument<T>, error: Error, next: MongooseNextCB) => void) | ((doc: T | MongooseDocument<T>, error: Error) => Promise<void> | void) | ((doc: T | MongooseDocument<T>, next: MongooseNextCB) => void) | MongooseHookPromised;
|
|
6
|
+
export type MongooseHookOptions = Record<string, unknown>;
|
|
7
|
+
export type MongooseHookPromised<T = any> = (doc: T | MongooseDocument<T>) => Promise<void>;
|
|
8
|
+
export type MongoosePreHookCB<T = any> = (doc: T | MongooseDocument<T>, ...args: unknown[]) => Promise<void> | void;
|
|
9
|
+
export type MongoosePostHookCB<T = any> = (doc: T | MongooseDocument<T>, ...args: unknown[]) => Promise<void> | void;
|
|
12
10
|
export interface MongoosePreHook<T = any> {
|
|
13
|
-
method:
|
|
11
|
+
method: MongooseMethods;
|
|
14
12
|
fn: MongoosePreHookCB<T>;
|
|
15
13
|
options?: MongooseHookOptions;
|
|
16
14
|
}
|
|
17
15
|
export interface MongoosePostHook<T = any> {
|
|
18
|
-
method:
|
|
16
|
+
method: MongooseMethods;
|
|
19
17
|
fn: MongoosePostHookCB<T>;
|
|
20
18
|
options?: MongooseHookOptions;
|
|
21
19
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Schema } from "mongoose";
|
|
2
|
-
import {
|
|
2
|
+
import { MongoosePreHookCB, MongooseSchemaOptions } from "../interfaces/MongooseSchemaOptions.js";
|
|
3
3
|
/**
|
|
4
4
|
* @ignore
|
|
5
5
|
*/
|
|
@@ -7,7 +7,7 @@ export declare function schemaOptions(target: any, options?: MongooseSchemaOptio
|
|
|
7
7
|
/**
|
|
8
8
|
* @ignore
|
|
9
9
|
*/
|
|
10
|
-
export declare function buildPreHook(fn: MongoosePreHookCB): (next:
|
|
10
|
+
export declare function buildPreHook(fn: MongoosePreHookCB): (next: any, arg1: any, arg2: any) => any;
|
|
11
11
|
/**
|
|
12
12
|
* @ignore
|
|
13
13
|
*/
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@tsed/mongoose",
|
|
3
3
|
"description": "Mongoose package for Ts.ED framework",
|
|
4
4
|
"type": "commonjs",
|
|
5
|
-
"version": "7.85.
|
|
5
|
+
"version": "7.85.2",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"tsed",
|
|
8
8
|
"mongoose",
|
|
@@ -34,27 +34,27 @@
|
|
|
34
34
|
"tslib": "2.6.1"
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|
|
37
|
-
"@tsed/ajv": "7.85.
|
|
38
|
-
"@tsed/barrels": "7.85.
|
|
39
|
-
"@tsed/core": "7.85.
|
|
40
|
-
"@tsed/di": "7.85.
|
|
41
|
-
"@tsed/json-mapper": "7.85.
|
|
37
|
+
"@tsed/ajv": "7.85.2",
|
|
38
|
+
"@tsed/barrels": "7.85.2",
|
|
39
|
+
"@tsed/core": "7.85.2",
|
|
40
|
+
"@tsed/di": "7.85.2",
|
|
41
|
+
"@tsed/json-mapper": "7.85.2",
|
|
42
42
|
"@tsed/logger": "^6.7.8",
|
|
43
|
-
"@tsed/schema": "7.85.
|
|
44
|
-
"@tsed/testcontainers-mongo": "7.85.
|
|
45
|
-
"@tsed/typescript": "7.85.
|
|
43
|
+
"@tsed/schema": "7.85.2",
|
|
44
|
+
"@tsed/testcontainers-mongo": "7.85.2",
|
|
45
|
+
"@tsed/typescript": "7.85.2",
|
|
46
46
|
"eslint": "^8.57.0",
|
|
47
47
|
"mongoose": "6.12.7",
|
|
48
48
|
"typescript": "4.9.5",
|
|
49
49
|
"vitest": "2.0.4"
|
|
50
50
|
},
|
|
51
51
|
"peerDependencies": {
|
|
52
|
-
"@tsed/ajv": "7.85.
|
|
53
|
-
"@tsed/core": "7.85.
|
|
54
|
-
"@tsed/di": "7.85.
|
|
55
|
-
"@tsed/json-mapper": "7.85.
|
|
52
|
+
"@tsed/ajv": "7.85.2",
|
|
53
|
+
"@tsed/core": "7.85.2",
|
|
54
|
+
"@tsed/di": "7.85.2",
|
|
55
|
+
"@tsed/json-mapper": "7.85.2",
|
|
56
56
|
"@tsed/logger": "^6.7.8",
|
|
57
|
-
"@tsed/schema": "7.85.
|
|
57
|
+
"@tsed/schema": "7.85.2",
|
|
58
58
|
"mongoose": ">=6.0.0"
|
|
59
59
|
},
|
|
60
60
|
"repository": "https://github.com/tsedio/tsed",
|
|
@@ -63,5 +63,8 @@
|
|
|
63
63
|
},
|
|
64
64
|
"homepage": "https://github.com/tsedio/tsed/tree/production/packages/orm/mongoose",
|
|
65
65
|
"author": "Romain Lenzotti",
|
|
66
|
-
"license": "MIT"
|
|
66
|
+
"license": "MIT",
|
|
67
|
+
"publishConfig": {
|
|
68
|
+
"tag": "v7-latest"
|
|
69
|
+
}
|
|
67
70
|
}
|