exisjs 0.7.0 → 0.7.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/README.md +9 -3
- package/dist/cli/commands/build.d.ts.map +1 -1
- package/dist/cli/commands/build.js +7 -0
- package/dist/cli/commands/build.js.map +1 -1
- package/dist/cli/resolve-aliases.d.ts +12 -0
- package/dist/cli/resolve-aliases.d.ts.map +1 -1
- package/dist/cli/resolve-aliases.js +82 -14
- package/dist/cli/resolve-aliases.js.map +1 -1
- package/dist/config/config.d.ts.map +1 -1
- package/dist/config/config.js +4 -3
- package/dist/config/config.js.map +1 -1
- package/dist/config/env.d.ts.map +1 -1
- package/dist/config/env.js +3 -2
- package/dist/config/env.js.map +1 -1
- package/dist/decorators/constants.d.ts +7 -0
- package/dist/decorators/constants.d.ts.map +1 -1
- package/dist/decorators/constants.js +2 -1
- package/dist/decorators/constants.js.map +1 -1
- package/dist/decorators/core/metadata.d.ts +31 -0
- package/dist/decorators/core/metadata.d.ts.map +1 -1
- package/dist/decorators/core/metadata.js +110 -1
- package/dist/decorators/core/metadata.js.map +1 -1
- package/dist/decorators/core.d.ts +16 -2
- package/dist/decorators/core.d.ts.map +1 -1
- package/dist/decorators/core.js +22 -0
- package/dist/decorators/core.js.map +1 -1
- package/dist/decorators/middleware.d.ts +17 -7
- package/dist/decorators/middleware.d.ts.map +1 -1
- package/dist/decorators/middleware.js +111 -183
- package/dist/decorators/middleware.js.map +1 -1
- package/dist/decorators/params.d.ts +54 -12
- package/dist/decorators/params.d.ts.map +1 -1
- package/dist/decorators/params.js +40 -20
- package/dist/decorators/params.js.map +1 -1
- package/dist/decorators/routing.d.ts.map +1 -1
- package/dist/decorators/routing.js +2 -1
- package/dist/decorators/routing.js.map +1 -1
- package/dist/di/container.d.ts +5 -1
- package/dist/di/container.d.ts.map +1 -1
- package/dist/di/container.js +56 -8
- package/dist/di/container.js.map +1 -1
- package/dist/di/decorators.d.ts +30 -0
- package/dist/di/decorators.d.ts.map +1 -0
- package/dist/di/decorators.js +59 -0
- package/dist/di/decorators.js.map +1 -0
- package/dist/di/index.d.ts +1 -0
- package/dist/di/index.d.ts.map +1 -1
- package/dist/di/index.js +4 -1
- package/dist/di/index.js.map +1 -1
- package/dist/di/inject.d.ts +2 -1
- package/dist/di/inject.d.ts.map +1 -1
- package/dist/di/inject.js.map +1 -1
- package/dist/docs/content/decorators.mdx +44 -10
- package/dist/docs/content/modules.mdx +22 -1
- package/dist/docs/content/providers.mdx +33 -1
- package/dist/docs/reference/decorators.mdx +14 -3
- package/dist/docs/reference/di.mdx +35 -11
- package/dist/docs/reference/logger.mdx +100 -0
- package/dist/docs/reference/router.mdx +9 -9
- package/dist/error/errors.d.ts.map +1 -1
- package/dist/error/errors.js +3 -5
- package/dist/error/errors.js.map +1 -1
- package/dist/index.d.ts +0 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -7
- package/dist/index.js.map +1 -1
- package/dist/lib/start-server.js +8 -0
- package/dist/lib/start-server.js.map +1 -1
- package/dist/middleware/rate-limit.d.ts +0 -2
- package/dist/middleware/rate-limit.d.ts.map +1 -1
- package/dist/middleware/rate-limit.js +2 -14
- package/dist/middleware/rate-limit.js.map +1 -1
- package/dist/module/index.d.ts +2 -0
- package/dist/module/index.d.ts.map +1 -1
- package/dist/module/index.js +3 -1
- package/dist/module/index.js.map +1 -1
- package/dist/plugin/manager.d.ts +1 -1
- package/dist/plugin/manager.d.ts.map +1 -1
- package/dist/plugin/manager.js +47 -0
- package/dist/plugin/manager.js.map +1 -1
- package/dist/router/boundary.d.ts +5 -1
- package/dist/router/boundary.d.ts.map +1 -1
- package/dist/router/boundary.js.map +1 -1
- package/dist/router/controller-registrar.d.ts.map +1 -1
- package/dist/router/controller-registrar.js +33 -6
- package/dist/router/controller-registrar.js.map +1 -1
- package/dist/router/route-builder.d.ts +25 -19
- package/dist/router/route-builder.d.ts.map +1 -1
- package/dist/router/route-builder.js +2 -1
- package/dist/router/route-builder.js.map +1 -1
- package/dist/router/route-scanner.d.ts.map +1 -1
- package/dist/router/route-scanner.js +42 -23
- package/dist/router/route-scanner.js.map +1 -1
- package/dist/server/app.d.ts +1 -1
- package/dist/server/app.d.ts.map +1 -1
- package/dist/server/app.js +1 -1
- package/dist/server/app.js.map +1 -1
- package/dist/server/response.d.ts.map +1 -1
- package/dist/server/response.js +2 -1
- package/dist/server/response.js.map +1 -1
- package/dist/utils/logger.d.ts.map +1 -1
- package/dist/utils/logger.js +0 -1
- package/dist/utils/logger.js.map +1 -1
- package/package.json +1 -1
|
@@ -1,17 +1,22 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.MetadataEngine = void 0;
|
|
3
|
+
exports.Reflector = exports.CUSTOM_METADATA_STORE = exports.MetadataEngine = void 0;
|
|
4
|
+
exports.SetMetadata = SetMetadata;
|
|
4
5
|
class MetadataEngine {
|
|
5
6
|
/**
|
|
6
7
|
* Retrieves metadata from a target.
|
|
7
8
|
*/
|
|
8
9
|
static get(target, key) {
|
|
10
|
+
if (!target)
|
|
11
|
+
return undefined;
|
|
9
12
|
return target[key];
|
|
10
13
|
}
|
|
11
14
|
/**
|
|
12
15
|
* Sets metadata on a target.
|
|
13
16
|
*/
|
|
14
17
|
static set(target, key, value) {
|
|
18
|
+
if (!target)
|
|
19
|
+
return;
|
|
15
20
|
target[key] = value;
|
|
16
21
|
}
|
|
17
22
|
/**
|
|
@@ -39,4 +44,108 @@ class MetadataEngine {
|
|
|
39
44
|
}
|
|
40
45
|
}
|
|
41
46
|
exports.MetadataEngine = MetadataEngine;
|
|
47
|
+
exports.CUSTOM_METADATA_STORE = Symbol.for('exisjs:custom_metadata');
|
|
48
|
+
/**
|
|
49
|
+
* Assigns custom metadata to a class or route handler method under a specified key.
|
|
50
|
+
*
|
|
51
|
+
* Example:
|
|
52
|
+
* ```ts
|
|
53
|
+
* @SetMetadata('roles', ['admin', 'moderator'])
|
|
54
|
+
* @Get('/admin')
|
|
55
|
+
* adminDashboard() {}
|
|
56
|
+
* ```
|
|
57
|
+
*/
|
|
58
|
+
function SetMetadata(key, value) {
|
|
59
|
+
return function (target, propertyKey, descriptor) {
|
|
60
|
+
const isStandard = typeof propertyKey === 'object' &&
|
|
61
|
+
propertyKey !== null &&
|
|
62
|
+
'kind' in propertyKey;
|
|
63
|
+
let actualTarget;
|
|
64
|
+
if (isStandard) {
|
|
65
|
+
// Stage 3 decorator
|
|
66
|
+
actualTarget = target;
|
|
67
|
+
}
|
|
68
|
+
else if (descriptor && descriptor.value) {
|
|
69
|
+
// Method decorator (legacy)
|
|
70
|
+
actualTarget = descriptor.value;
|
|
71
|
+
}
|
|
72
|
+
else if (propertyKey && target[propertyKey]) {
|
|
73
|
+
// Property/Method on prototype
|
|
74
|
+
actualTarget = target[propertyKey];
|
|
75
|
+
}
|
|
76
|
+
else {
|
|
77
|
+
// Class decorator
|
|
78
|
+
actualTarget = target;
|
|
79
|
+
}
|
|
80
|
+
if (!actualTarget[exports.CUSTOM_METADATA_STORE]) {
|
|
81
|
+
actualTarget[exports.CUSTOM_METADATA_STORE] = new Map();
|
|
82
|
+
}
|
|
83
|
+
actualTarget[exports.CUSTOM_METADATA_STORE].set(key, value);
|
|
84
|
+
if (actualTarget.prototype) {
|
|
85
|
+
if (!actualTarget.prototype[exports.CUSTOM_METADATA_STORE]) {
|
|
86
|
+
actualTarget.prototype[exports.CUSTOM_METADATA_STORE] = new Map();
|
|
87
|
+
}
|
|
88
|
+
actualTarget.prototype[exports.CUSTOM_METADATA_STORE].set(key, value);
|
|
89
|
+
}
|
|
90
|
+
return target;
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Reflector helper utility to inspect and retrieve custom metadata attached via `@SetMetadata`.
|
|
95
|
+
*/
|
|
96
|
+
class Reflector {
|
|
97
|
+
/**
|
|
98
|
+
* Retrieve metadata for a specified key from a single target (class, handler, or function).
|
|
99
|
+
*/
|
|
100
|
+
static get(key, target) {
|
|
101
|
+
if (!target)
|
|
102
|
+
return undefined;
|
|
103
|
+
if (target[exports.CUSTOM_METADATA_STORE] instanceof Map) {
|
|
104
|
+
const val = target[exports.CUSTOM_METADATA_STORE].get(key);
|
|
105
|
+
if (val !== undefined)
|
|
106
|
+
return val;
|
|
107
|
+
}
|
|
108
|
+
if (target.prototype &&
|
|
109
|
+
target.prototype[exports.CUSTOM_METADATA_STORE] instanceof Map) {
|
|
110
|
+
const val = target.prototype[exports.CUSTOM_METADATA_STORE].get(key);
|
|
111
|
+
if (val !== undefined)
|
|
112
|
+
return val;
|
|
113
|
+
}
|
|
114
|
+
return undefined;
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Retrieve metadata for a specified key from an array of targets, overriding previous values.
|
|
118
|
+
* Priority is given to targets listed earlier in the array (e.g., method handler first, then class).
|
|
119
|
+
*/
|
|
120
|
+
static getAllAndOverride(key, targets) {
|
|
121
|
+
for (const target of targets) {
|
|
122
|
+
const val = this.get(key, target);
|
|
123
|
+
if (val !== undefined) {
|
|
124
|
+
return val;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
return undefined;
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Retrieve metadata for a specified key across multiple targets and merge them together.
|
|
131
|
+
* If array values, concatenates them. If object values, shallow-merges them.
|
|
132
|
+
*/
|
|
133
|
+
static getAllAndMerge(key, targets) {
|
|
134
|
+
let mergedArray;
|
|
135
|
+
let mergedObject;
|
|
136
|
+
for (const target of targets) {
|
|
137
|
+
const val = this.get(key, target);
|
|
138
|
+
if (val !== undefined) {
|
|
139
|
+
if (Array.isArray(val)) {
|
|
140
|
+
mergedArray = mergedArray ? [...mergedArray, ...val] : [...val];
|
|
141
|
+
}
|
|
142
|
+
else if (typeof val === 'object' && val !== null) {
|
|
143
|
+
mergedObject = mergedObject ? { ...mergedObject, ...val } : { ...val };
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
return (mergedArray !== undefined ? mergedArray : mergedObject);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
exports.Reflector = Reflector;
|
|
42
151
|
//# sourceMappingURL=metadata.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"metadata.js","sourceRoot":"","sources":["../../../src/decorators/core/metadata.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"metadata.js","sourceRoot":"","sources":["../../../src/decorators/core/metadata.ts"],"names":[],"mappings":";;;AA4DA,kCA+CC;AA3GD,MAAa,cAAc;IACzB;;OAEG;IACH,MAAM,CAAC,GAAG,CAAU,MAAW,EAAE,GAAoB;QACnD,IAAI,CAAC,MAAM;YAAE,OAAO,SAAS,CAAA;QAC7B,OAAO,MAAM,CAAC,GAAG,CAAC,CAAA;IACpB,CAAC;IAED;;OAEG;IACH,MAAM,CAAC,GAAG,CAAC,MAAW,EAAE,GAAoB,EAAE,KAAU;QACtD,IAAI,CAAC,MAAM;YAAE,OAAM;QACnB,MAAM,CAAC,GAAG,CAAC,GAAG,KAAK,CAAA;IACrB,CAAC;IAED;;OAEG;IACH,MAAM,CAAC,IAAI,CAAI,MAAW,EAAE,GAAoB,EAAE,YAAe;QAC/D,IAAI,MAAM,CAAC,GAAG,CAAC,KAAK,SAAS,EAAE,CAAC;YAC9B,MAAM,CAAC,GAAG,CAAC,GAAG,YAAY,CAAA;QAC5B,CAAC;QACD,OAAO,MAAM,CAAC,GAAG,CAAC,CAAA;IACpB,CAAC;IAED;;OAEG;IACH,MAAM,CAAC,IAAI,CAAC,MAAW,EAAE,GAAoB,EAAE,KAAU;QACvD,MAAM,GAAG,GAAG,IAAI,CAAC,IAAI,CAAQ,MAAM,EAAE,GAAG,EAAE,EAAE,CAAC,CAAA;QAC7C,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;IACjB,CAAC;IAED;;OAEG;IACH,MAAM,CAAC,KAAK,CACV,MAAW,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B,CAAC;IAED;;;OAGG;IACH,MAAM,CAAC,cAAc,CACnB,GAAS,EACT,OAAc;QAEd,IAAI,WAA8B,CAAA;QAClC,IAAI,YAA6C,CAAA;QAEjD,KAAK,MAAM,MAAM,IAAI,OAAO,EAAE,CAAC;YAC7B,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,CAAY,GAAG,EAAE,MAAM,CAAC,CAAA;YAC5C,IAAI,GAAG,KAAK,SAAS,EAAE,CAAC;gBACtB,IAAI,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC;oBACvB,WAAW,GAAG,WAAW,CAAC,CAAC,CAAC,CAAC,GAAG,WAAW,EAAE,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC,CAAA;gBACjE,CAAC;qBAAM,IAAI,OAAO,GAAG,KAAK,QAAQ,IAAI,GAAG,KAAK,IAAI,EAAE,CAAC;oBACnD,YAAY,GAAG,YAAY,CAAC,CAAC,CAAC,EAAE,GAAG,YAAY,EAAE,GAAG,GAAG,EAAE,CAAC,CAAC,CAAC,EAAE,GAAG,GAAG,EAAE,CAAA;gBACxE,CAAC;YACH,CAAC;QACH,CAAC;QAED,OAAO,CAAC,WAAW,KAAK,SAAS,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,YAAY,CACzC,CAAA;IACvB,CAAC;CACF;AAjED,8BAiEC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ControllerOptions, ServerConfig, BoundaryConfig } from './constants';
|
|
1
|
+
import type { ControllerOptions, ServerConfig, BoundaryConfig, ClassModuleOptions } from './constants';
|
|
2
2
|
/**
|
|
3
3
|
* Marks a class as a controller, automatically grouping its routes under the provided prefix.
|
|
4
4
|
* Uses standard ES decorators, completely avoiding reflect-metadata bloat.
|
|
@@ -17,7 +17,7 @@ import type { ControllerOptions, ServerConfig, BoundaryConfig } from './constant
|
|
|
17
17
|
export declare function Controller(prefixOrOptions?: string | ControllerOptions): any;
|
|
18
18
|
export declare const INJECTABLE_REGISTRY: Set<any>;
|
|
19
19
|
export declare function Injectable(options?: {
|
|
20
|
-
scope?: 'singleton' | 'request';
|
|
20
|
+
scope?: 'singleton' | 'request' | 'transient';
|
|
21
21
|
}): any;
|
|
22
22
|
/**
|
|
23
23
|
* Marks a class as a root Server module.
|
|
@@ -27,4 +27,18 @@ export declare function Server(options?: ServerConfig): any;
|
|
|
27
27
|
* Marks a class as a Boundary module (folder-scoped config + request pipeline).
|
|
28
28
|
*/
|
|
29
29
|
export declare function Boundary(options?: BoundaryConfig): any;
|
|
30
|
+
/**
|
|
31
|
+
* Marks a class as an OOP Module, configuring its imported modules, controllers, providers, and exports.
|
|
32
|
+
*
|
|
33
|
+
* Example:
|
|
34
|
+
* ```ts
|
|
35
|
+
* @Module({
|
|
36
|
+
* imports: [DatabaseModule],
|
|
37
|
+
* controllers: [UserController],
|
|
38
|
+
* providers: [UserService],
|
|
39
|
+
* })
|
|
40
|
+
* export class UserModule {}
|
|
41
|
+
* ```
|
|
42
|
+
*/
|
|
43
|
+
export declare function Module(options?: ClassModuleOptions): any;
|
|
30
44
|
//# sourceMappingURL=core.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"core.d.ts","sourceRoot":"","sources":["../../src/decorators/core.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"core.d.ts","sourceRoot":"","sources":["../../src/decorators/core.ts"],"names":[],"mappings":"AAiBA,OAAO,KAAK,EACV,iBAAiB,EACjB,YAAY,EACZ,cAAc,EACd,kBAAkB,EACnB,MAAM,aAAa,CAAA;AAGpB;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,UAAU,CAAC,eAAe,CAAC,EAAE,MAAM,GAAG,iBAAiB,GAAG,GAAG,CA8F5E;AAED,eAAO,MAAM,mBAAmB,UAAiB,CAAA;AAEjD,wBAAgB,UAAU,CAAC,OAAO,CAAC,EAAE;IACnC,KAAK,CAAC,EAAE,WAAW,GAAG,SAAS,GAAG,WAAW,CAAA;CAC9C,GAAG,GAAG,CAWN;AAED;;GAEG;AACH,wBAAgB,MAAM,CAAC,OAAO,CAAC,EAAE,YAAY,GAAG,GAAG,CAIlD;AAED;;GAEG;AACH,wBAAgB,QAAQ,CAAC,OAAO,CAAC,EAAE,cAAc,GAAG,GAAG,CAItD;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,MAAM,CAAC,OAAO,GAAE,kBAAuB,GAAG,GAAG,CAO5D"}
|
package/dist/decorators/core.js
CHANGED
|
@@ -5,6 +5,7 @@ exports.Controller = Controller;
|
|
|
5
5
|
exports.Injectable = Injectable;
|
|
6
6
|
exports.Server = Server;
|
|
7
7
|
exports.Boundary = Boundary;
|
|
8
|
+
exports.Module = Module;
|
|
8
9
|
const constants_1 = require("./constants");
|
|
9
10
|
const metadata_1 = require("./core/metadata");
|
|
10
11
|
/**
|
|
@@ -127,4 +128,25 @@ function Boundary(options) {
|
|
|
127
128
|
metadata_1.MetadataEngine.set(target.prototype, constants_1.BOUNDARY_CONFIG, options || {});
|
|
128
129
|
};
|
|
129
130
|
}
|
|
131
|
+
/**
|
|
132
|
+
* Marks a class as an OOP Module, configuring its imported modules, controllers, providers, and exports.
|
|
133
|
+
*
|
|
134
|
+
* Example:
|
|
135
|
+
* ```ts
|
|
136
|
+
* @Module({
|
|
137
|
+
* imports: [DatabaseModule],
|
|
138
|
+
* controllers: [UserController],
|
|
139
|
+
* providers: [UserService],
|
|
140
|
+
* })
|
|
141
|
+
* export class UserModule {}
|
|
142
|
+
* ```
|
|
143
|
+
*/
|
|
144
|
+
function Module(options = {}) {
|
|
145
|
+
return function (target, _context) {
|
|
146
|
+
metadata_1.MetadataEngine.set(target, constants_1.MODULE_METADATA, options);
|
|
147
|
+
if (target.prototype) {
|
|
148
|
+
metadata_1.MetadataEngine.set(target.prototype, constants_1.MODULE_METADATA, options);
|
|
149
|
+
}
|
|
150
|
+
};
|
|
151
|
+
}
|
|
130
152
|
//# sourceMappingURL=core.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"core.js","sourceRoot":"","sources":["../../src/decorators/core.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"core.js","sourceRoot":"","sources":["../../src/decorators/core.ts"],"names":[],"mappings":";;;AAwCA,gCA8FC;AAID,gCAaC;AAKD,wBAIC;AAKD,4BAIC;AAeD,wBAOC;AA/LD,2CAgBoB;AAOpB,8CAAgD;AAEhD;;;;;;;;;;;;;;GAcG;AACH,SAAgB,UAAU,CAAC,eAA4C;IACrE,OAAO,UAAU,MAAW,EAAE,OAA+B;QAC3D,MAAM,MAAM,GACV,OAAO,eAAe,KAAK,QAAQ;YACjC,CAAC,CAAC,eAAe;YACjB,CAAC,CAAC,eAAe,EAAE,MAAM,IAAI,EAAE,CAAA;QACnC,MAAM,IAAI,GACR,OAAO,eAAe,KAAK,QAAQ,CAAC,CAAC,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS,CAAA;QAExE,MAAM,KAAK,GAAG,MAAM,CAAC,SAAS,CAAA;QAC9B,yBAAc,CAAC,GAAG,CAAC,KAAK,EAAE,6BAAiB,EAAE,MAAM,CAAC,CAAA;QACpD,IAAI,IAAI;YAAE,yBAAc,CAAC,GAAG,CAAC,KAAK,EAAE,2BAAe,EAAE,IAAI,CAAC,CAAA;QAE1D,IAAI,OAAO,IAAI,OAAO,CAAC,QAAQ,EAAE,CAAC;YAChC,OAAO,CAAC,QAAQ,CAAC,6BAAiB,CAAC,GAAG,MAAM,CAAA;YAC5C,IAAI,IAAI;gBAAE,OAAO,CAAC,QAAQ,CAAC,2BAAe,CAAC,GAAG,IAAI,CAAA;QACpD,CAAC;QAED,yBAAc,CAAC,IAAI,CAAC,KAAK,EAAE,0BAAc,EAAE,EAAE,CAAC,CAAA;QAE9C,cAAc;QACd,MAAM,kBAAkB,GAAG,yBAAc,CAAC,GAAG,CAAC,KAAK,EAAE,+BAAmB,CAAC,CAAA;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O,UAAU,MAAW,EAAE,QAAgC;QAC5D,yBAAc,CAAC,GAAG,CAAC,MAAM,CAAC,SAAS,EAAE,yBAAa,EAAE,OAAO,IAAI,EAAE,CAAC,CAAA;IACpE,CAAC,CAAA;AACH,CAAC;AAED;;GAEG;AACH,SAAgB,QAAQ,CAAC,OAAwB;IAC/C,OAAO,UAAU,MAAW,EAAE,QAAgC;QAC5D,yBAAc,CAAC,GAAG,CAAC,MAAM,CAAC,SAAS,EAAE,2BAAe,EAAE,OAAO,IAAI,EAAE,CAAC,CAAA;IACtE,CAAC,CAAA;AACH,CAAC;AAED;;;;;;;;;;;;GAYG;AACH,SAAgB,MAAM,CAAC,UAA8B,EAAE;IACrD,OAAO,UAAU,MAAW,EAAE,QAAgC;QAC5D,yBAAc,CAAC,GAAG,CAAC,MAAM,EAAE,2BAAe,EAAE,OAAO,CAAC,CAAA;QACpD,IAAI,MAAM,CAAC,SAAS,EAAE,CAAC;YACrB,yBAAc,CAAC,GAAG,CAAC,MAAM,CAAC,SAAS,EAAE,2BAAe,EAAE,OAAO,CAAC,CAAA;QAChE,CAAC;IACH,CAAC,CAAA;AACH,CAAC"}
|
|
@@ -1,16 +1,29 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Applies middleware to a Controller class or route method.
|
|
2
|
+
* Applies middleware, guards, interceptors, or exception filters to a Controller class or route method.
|
|
3
|
+
* Unifies @Use, @UseGuards, @UseInterceptors, and @UseFilters into a single, cohesive decorator.
|
|
3
4
|
*
|
|
4
5
|
* Example:
|
|
5
|
-
*
|
|
6
6
|
* @Use(requireAuth)
|
|
7
|
+
* @Use(AdminGuard)
|
|
7
8
|
* @Get('/dashboard')
|
|
8
9
|
* getDashboard() {}
|
|
9
10
|
*
|
|
10
|
-
* @param {...any}
|
|
11
|
+
* @param {...any} items Middleware functions, Guards, Interceptors, or Filters
|
|
11
12
|
* @public
|
|
12
13
|
*/
|
|
13
|
-
export declare function Use(...
|
|
14
|
+
export declare function Use(...items: any[]): any;
|
|
15
|
+
/**
|
|
16
|
+
* @deprecated Use `@Use(...guards)` instead.
|
|
17
|
+
*/
|
|
18
|
+
export declare function UseGuards(...guards: any[]): any;
|
|
19
|
+
/**
|
|
20
|
+
* @deprecated Use `@Use(...interceptors)` instead.
|
|
21
|
+
*/
|
|
22
|
+
export declare function UseInterceptors(...interceptors: any[]): any;
|
|
23
|
+
/**
|
|
24
|
+
* @deprecated Use `@Use(...filters)` instead.
|
|
25
|
+
*/
|
|
26
|
+
export declare function UseFilters(...filters: any[]): any;
|
|
14
27
|
/**
|
|
15
28
|
* Idempotency Decorator.
|
|
16
29
|
* Caches responses based on the provided Idempotency-Key header.
|
|
@@ -21,7 +34,4 @@ export declare function Use(...middlewares: any[]): any;
|
|
|
21
34
|
* checkout() {}
|
|
22
35
|
*/
|
|
23
36
|
export declare function Idempotent(options?: import('../middleware/idempotency').IdempotentOptions): any;
|
|
24
|
-
export declare function UseGuards(...guards: any[]): any;
|
|
25
|
-
export declare function UseInterceptors(...interceptors: any[]): any;
|
|
26
|
-
export declare function UseFilters(...filters: any[]): any;
|
|
27
37
|
//# sourceMappingURL=middleware.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"middleware.d.ts","sourceRoot":"","sources":["../../src/decorators/middleware.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"middleware.d.ts","sourceRoot":"","sources":["../../src/decorators/middleware.ts"],"names":[],"mappings":"AAkCA;;;;;;;;;;;;GAYG;AACH,wBAAgB,GAAG,CAAC,GAAG,KAAK,EAAE,GAAG,EAAE,GAAG,GAAG,CAsFxC;AAED;;GAEG;AACH,wBAAgB,SAAS,CAAC,GAAG,MAAM,EAAE,GAAG,EAAE,GAAG,GAAG,CAE/C;AAED;;GAEG;AACH,wBAAgB,eAAe,CAAC,GAAG,YAAY,EAAE,GAAG,EAAE,GAAG,GAAG,CAE3D;AAED;;GAEG;AACH,wBAAgB,UAAU,CAAC,GAAG,OAAO,EAAE,GAAG,EAAE,GAAG,GAAG,CAEjD;AAED;;;;;;;;GAQG;AACH,wBAAgB,UAAU,CACxB,OAAO,GAAE,OAAO,2BAA2B,EAAE,iBAAsB,GAClE,GAAG,CA8BL"}
|
|
@@ -34,88 +34,135 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
34
34
|
})();
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
36
|
exports.Use = Use;
|
|
37
|
-
exports.Idempotent = Idempotent;
|
|
38
37
|
exports.UseGuards = UseGuards;
|
|
39
38
|
exports.UseInterceptors = UseInterceptors;
|
|
40
39
|
exports.UseFilters = UseFilters;
|
|
40
|
+
exports.Idempotent = Idempotent;
|
|
41
41
|
const constants_1 = require("./constants");
|
|
42
|
+
const metadata_1 = require("./core/metadata");
|
|
43
|
+
/**
|
|
44
|
+
* Classifies a handler item into middleware, guard, interceptor, or filter.
|
|
45
|
+
*/
|
|
46
|
+
function classifyItem(item) {
|
|
47
|
+
if (!item)
|
|
48
|
+
return 'middleware';
|
|
49
|
+
// Class instances or class prototypes
|
|
50
|
+
const proto = typeof item === 'function' ? item.prototype : item;
|
|
51
|
+
if (proto) {
|
|
52
|
+
if (typeof proto.canActivate === 'function')
|
|
53
|
+
return 'guard';
|
|
54
|
+
if (typeof proto.intercept === 'function')
|
|
55
|
+
return 'interceptor';
|
|
56
|
+
if (typeof proto.catch === 'function')
|
|
57
|
+
return 'filter';
|
|
58
|
+
}
|
|
59
|
+
// Functional duck-typing checks
|
|
60
|
+
if (typeof item === 'object') {
|
|
61
|
+
if (typeof item.canActivate === 'function')
|
|
62
|
+
return 'guard';
|
|
63
|
+
if (typeof item.intercept === 'function')
|
|
64
|
+
return 'interceptor';
|
|
65
|
+
if (typeof item.catch === 'function')
|
|
66
|
+
return 'filter';
|
|
67
|
+
}
|
|
68
|
+
return 'middleware';
|
|
69
|
+
}
|
|
42
70
|
/**
|
|
43
|
-
* Applies middleware to a Controller class or route method.
|
|
71
|
+
* Applies middleware, guards, interceptors, or exception filters to a Controller class or route method.
|
|
72
|
+
* Unifies @Use, @UseGuards, @UseInterceptors, and @UseFilters into a single, cohesive decorator.
|
|
44
73
|
*
|
|
45
74
|
* Example:
|
|
46
|
-
*
|
|
47
75
|
* @Use(requireAuth)
|
|
76
|
+
* @Use(AdminGuard)
|
|
48
77
|
* @Get('/dashboard')
|
|
49
78
|
* getDashboard() {}
|
|
50
79
|
*
|
|
51
|
-
* @param {...any}
|
|
80
|
+
* @param {...any} items Middleware functions, Guards, Interceptors, or Filters
|
|
52
81
|
* @public
|
|
53
82
|
*/
|
|
54
|
-
function Use(...
|
|
55
|
-
return function (target, contextOrPropertyKey,
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
83
|
+
function Use(...items) {
|
|
84
|
+
return function (target, contextOrPropertyKey, descriptor) {
|
|
85
|
+
const isStandard = typeof contextOrPropertyKey === 'object' && contextOrPropertyKey !== null;
|
|
86
|
+
const kind = isStandard ? contextOrPropertyKey.kind : undefined;
|
|
87
|
+
if (kind === 'class' ||
|
|
88
|
+
(!isStandard && typeof target === 'function' && !contextOrPropertyKey)) {
|
|
89
|
+
// Class-level decorator
|
|
90
|
+
const proto = target.prototype || target;
|
|
91
|
+
const classLifecycle = metadata_1.MetadataEngine.init(proto, constants_1.LIFECYCLE_METADATA_PROP, {});
|
|
92
|
+
classLifecycle._classGuards = classLifecycle._classGuards || [];
|
|
93
|
+
classLifecycle._classInterceptors =
|
|
94
|
+
classLifecycle._classInterceptors || [];
|
|
95
|
+
classLifecycle._classFilters = classLifecycle._classFilters || [];
|
|
96
|
+
const classMiddlewares = metadata_1.MetadataEngine.init(proto, constants_1.MIDDLEWARE_REGISTRY, {
|
|
97
|
+
_classMiddlewares: [],
|
|
98
|
+
});
|
|
99
|
+
if (!classMiddlewares._classMiddlewares) {
|
|
100
|
+
classMiddlewares._classMiddlewares = [];
|
|
101
|
+
}
|
|
102
|
+
for (const item of items) {
|
|
103
|
+
const type = classifyItem(item);
|
|
104
|
+
if (type === 'guard') {
|
|
105
|
+
classLifecycle._classGuards.push(item);
|
|
71
106
|
}
|
|
72
|
-
if (
|
|
73
|
-
|
|
74
|
-
target.prototype[constants_1.MIDDLEWARE_REGISTRY] = {
|
|
75
|
-
_classMiddlewares: target.prototype[constants_1.MIDDLEWARE_REGISTRY] || [],
|
|
76
|
-
};
|
|
107
|
+
else if (type === 'interceptor') {
|
|
108
|
+
classLifecycle._classInterceptors.push(item);
|
|
77
109
|
}
|
|
78
|
-
else if (
|
|
79
|
-
|
|
110
|
+
else if (type === 'filter') {
|
|
111
|
+
classLifecycle._classFilters.push(item);
|
|
112
|
+
}
|
|
113
|
+
else {
|
|
114
|
+
classMiddlewares._classMiddlewares.push(item);
|
|
80
115
|
}
|
|
81
|
-
target.prototype[constants_1.MIDDLEWARE_REGISTRY]._classMiddlewares.push(...middlewares);
|
|
82
|
-
}
|
|
83
|
-
else if (context.kind === 'method') {
|
|
84
|
-
// TS 5.0 Standard Method Decorator
|
|
85
|
-
;
|
|
86
|
-
target[constants_1.METHOD_MIDDLEWARES] =
|
|
87
|
-
target[constants_1.METHOD_MIDDLEWARES] || [];
|
|
88
|
-
target[constants_1.METHOD_MIDDLEWARES].push(...middlewares);
|
|
89
116
|
}
|
|
90
117
|
}
|
|
91
118
|
else {
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
119
|
+
// Method-level decorator
|
|
120
|
+
const fn = isStandard
|
|
121
|
+
? target
|
|
122
|
+
: descriptor
|
|
123
|
+
? descriptor.value
|
|
124
|
+
: target[contextOrPropertyKey];
|
|
125
|
+
const methodLifecycle = metadata_1.MetadataEngine.init(fn, constants_1.LIFECYCLE_METADATA_PROP, {});
|
|
126
|
+
methodLifecycle.guards = methodLifecycle.guards || [];
|
|
127
|
+
methodLifecycle.interceptors = methodLifecycle.interceptors || [];
|
|
128
|
+
methodLifecycle.filters = methodLifecycle.filters || [];
|
|
129
|
+
const methodMiddlewares = metadata_1.MetadataEngine.init(fn, constants_1.METHOD_MIDDLEWARES, []);
|
|
130
|
+
for (const item of items) {
|
|
131
|
+
const type = classifyItem(item);
|
|
132
|
+
if (type === 'guard') {
|
|
133
|
+
methodLifecycle.guards.push(item);
|
|
100
134
|
}
|
|
101
|
-
else if (
|
|
102
|
-
|
|
135
|
+
else if (type === 'interceptor') {
|
|
136
|
+
methodLifecycle.interceptors.push(item);
|
|
137
|
+
}
|
|
138
|
+
else if (type === 'filter') {
|
|
139
|
+
methodLifecycle.filters.push(item);
|
|
140
|
+
}
|
|
141
|
+
else {
|
|
142
|
+
methodMiddlewares.push(item);
|
|
103
143
|
}
|
|
104
|
-
proto[constants_1.MIDDLEWARE_REGISTRY]._classMiddlewares.push(...middlewares);
|
|
105
|
-
}
|
|
106
|
-
else {
|
|
107
|
-
// Legacy method decorator
|
|
108
|
-
const proto = target;
|
|
109
|
-
const name = contextOrPropertyKey;
|
|
110
|
-
if (!proto[constants_1.MIDDLEWARE_REGISTRY])
|
|
111
|
-
proto[constants_1.MIDDLEWARE_REGISTRY] = {};
|
|
112
|
-
if (!proto[constants_1.MIDDLEWARE_REGISTRY][name])
|
|
113
|
-
proto[constants_1.MIDDLEWARE_REGISTRY][name] = [];
|
|
114
|
-
proto[constants_1.MIDDLEWARE_REGISTRY][name].push(...middlewares);
|
|
115
144
|
}
|
|
116
145
|
}
|
|
117
146
|
};
|
|
118
147
|
}
|
|
148
|
+
/**
|
|
149
|
+
* @deprecated Use `@Use(...guards)` instead.
|
|
150
|
+
*/
|
|
151
|
+
function UseGuards(...guards) {
|
|
152
|
+
return Use(...guards);
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* @deprecated Use `@Use(...interceptors)` instead.
|
|
156
|
+
*/
|
|
157
|
+
function UseInterceptors(...interceptors) {
|
|
158
|
+
return Use(...interceptors);
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* @deprecated Use `@Use(...filters)` instead.
|
|
162
|
+
*/
|
|
163
|
+
function UseFilters(...filters) {
|
|
164
|
+
return Use(...filters);
|
|
165
|
+
}
|
|
119
166
|
/**
|
|
120
167
|
* Idempotency Decorator.
|
|
121
168
|
* Caches responses based on the provided Idempotency-Key header.
|
|
@@ -128,138 +175,19 @@ function Use(...middlewares) {
|
|
|
128
175
|
function Idempotent(options = {}) {
|
|
129
176
|
return function (target, contextOrPropertyKey, descriptor) {
|
|
130
177
|
const isStandard = typeof contextOrPropertyKey === 'object' && contextOrPropertyKey !== null;
|
|
131
|
-
const fn = isStandard
|
|
132
|
-
|
|
178
|
+
const fn = isStandard
|
|
179
|
+
? target
|
|
180
|
+
: descriptor
|
|
181
|
+
? descriptor.value
|
|
182
|
+
: target[contextOrPropertyKey];
|
|
183
|
+
const methodMiddlewares = metadata_1.MetadataEngine.init(fn, constants_1.METHOD_MIDDLEWARES, []);
|
|
133
184
|
// Defer import to avoid circular dependencies
|
|
134
185
|
const middlewareProxy = async (req, res, next) => {
|
|
135
186
|
const { Idempotent: IdempotentMiddleware } = await Promise.resolve().then(() => __importStar(require('../middleware/idempotency')));
|
|
136
187
|
const handler = IdempotentMiddleware(options);
|
|
137
188
|
return handler(req, res, next);
|
|
138
189
|
};
|
|
139
|
-
|
|
140
|
-
};
|
|
141
|
-
}
|
|
142
|
-
function UseGuards(...guards) {
|
|
143
|
-
return function (target, contextOrPropertyKey, _descriptor) {
|
|
144
|
-
if (typeof contextOrPropertyKey === 'object' &&
|
|
145
|
-
contextOrPropertyKey !== null) {
|
|
146
|
-
const context = contextOrPropertyKey;
|
|
147
|
-
if (context.kind === 'class') {
|
|
148
|
-
target.prototype[constants_1.LIFECYCLE_METADATA_PROP] =
|
|
149
|
-
target.prototype[constants_1.LIFECYCLE_METADATA_PROP] || {};
|
|
150
|
-
target.prototype[constants_1.LIFECYCLE_METADATA_PROP]._classGuards =
|
|
151
|
-
target.prototype[constants_1.LIFECYCLE_METADATA_PROP]._classGuards || [];
|
|
152
|
-
target.prototype[constants_1.LIFECYCLE_METADATA_PROP]._classGuards.push(...guards);
|
|
153
|
-
}
|
|
154
|
-
else if (context.kind === 'method') {
|
|
155
|
-
;
|
|
156
|
-
target[constants_1.LIFECYCLE_METADATA_PROP] =
|
|
157
|
-
target[constants_1.LIFECYCLE_METADATA_PROP] || {};
|
|
158
|
-
target[constants_1.LIFECYCLE_METADATA_PROP].guards =
|
|
159
|
-
target[constants_1.LIFECYCLE_METADATA_PROP].guards || [];
|
|
160
|
-
target[constants_1.LIFECYCLE_METADATA_PROP].guards.push(...guards);
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
else {
|
|
164
|
-
if (typeof target === 'function' && !contextOrPropertyKey) {
|
|
165
|
-
// Legacy class decorator
|
|
166
|
-
target.prototype[constants_1.LIFECYCLE_METADATA_PROP] =
|
|
167
|
-
target.prototype[constants_1.LIFECYCLE_METADATA_PROP] || {};
|
|
168
|
-
target.prototype[constants_1.LIFECYCLE_METADATA_PROP]._classGuards =
|
|
169
|
-
target.prototype[constants_1.LIFECYCLE_METADATA_PROP]._classGuards || [];
|
|
170
|
-
target.prototype[constants_1.LIFECYCLE_METADATA_PROP]._classGuards.push(...guards);
|
|
171
|
-
}
|
|
172
|
-
else {
|
|
173
|
-
// Legacy method decorator
|
|
174
|
-
const fn = target[contextOrPropertyKey];
|
|
175
|
-
fn[constants_1.LIFECYCLE_METADATA_PROP] = fn[constants_1.LIFECYCLE_METADATA_PROP] || {};
|
|
176
|
-
fn[constants_1.LIFECYCLE_METADATA_PROP].guards =
|
|
177
|
-
fn[constants_1.LIFECYCLE_METADATA_PROP].guards || [];
|
|
178
|
-
fn[constants_1.LIFECYCLE_METADATA_PROP].guards.push(...guards);
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
};
|
|
182
|
-
}
|
|
183
|
-
function UseInterceptors(...interceptors) {
|
|
184
|
-
return function (target, contextOrPropertyKey, _descriptor) {
|
|
185
|
-
if (typeof contextOrPropertyKey === 'object' &&
|
|
186
|
-
contextOrPropertyKey !== null) {
|
|
187
|
-
const context = contextOrPropertyKey;
|
|
188
|
-
if (context.kind === 'class') {
|
|
189
|
-
target.prototype[constants_1.LIFECYCLE_METADATA_PROP] =
|
|
190
|
-
target.prototype[constants_1.LIFECYCLE_METADATA_PROP] || {};
|
|
191
|
-
target.prototype[constants_1.LIFECYCLE_METADATA_PROP]._classInterceptors =
|
|
192
|
-
target.prototype[constants_1.LIFECYCLE_METADATA_PROP]._classInterceptors || [];
|
|
193
|
-
target.prototype[constants_1.LIFECYCLE_METADATA_PROP]._classInterceptors.push(...interceptors);
|
|
194
|
-
}
|
|
195
|
-
else if (context.kind === 'method') {
|
|
196
|
-
;
|
|
197
|
-
target[constants_1.LIFECYCLE_METADATA_PROP] =
|
|
198
|
-
target[constants_1.LIFECYCLE_METADATA_PROP] || {};
|
|
199
|
-
target[constants_1.LIFECYCLE_METADATA_PROP].interceptors =
|
|
200
|
-
target[constants_1.LIFECYCLE_METADATA_PROP].interceptors || [];
|
|
201
|
-
target[constants_1.LIFECYCLE_METADATA_PROP].interceptors.push(...interceptors);
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
else {
|
|
205
|
-
if (typeof target === 'function' && !contextOrPropertyKey) {
|
|
206
|
-
// Legacy class decorator
|
|
207
|
-
target.prototype[constants_1.LIFECYCLE_METADATA_PROP] =
|
|
208
|
-
target.prototype[constants_1.LIFECYCLE_METADATA_PROP] || {};
|
|
209
|
-
target.prototype[constants_1.LIFECYCLE_METADATA_PROP]._classInterceptors =
|
|
210
|
-
target.prototype[constants_1.LIFECYCLE_METADATA_PROP]._classInterceptors || [];
|
|
211
|
-
target.prototype[constants_1.LIFECYCLE_METADATA_PROP]._classInterceptors.push(...interceptors);
|
|
212
|
-
}
|
|
213
|
-
else {
|
|
214
|
-
// Legacy method decorator
|
|
215
|
-
const fn = target[contextOrPropertyKey];
|
|
216
|
-
fn[constants_1.LIFECYCLE_METADATA_PROP] = fn[constants_1.LIFECYCLE_METADATA_PROP] || {};
|
|
217
|
-
fn[constants_1.LIFECYCLE_METADATA_PROP].interceptors =
|
|
218
|
-
fn[constants_1.LIFECYCLE_METADATA_PROP].interceptors || [];
|
|
219
|
-
fn[constants_1.LIFECYCLE_METADATA_PROP].interceptors.push(...interceptors);
|
|
220
|
-
}
|
|
221
|
-
}
|
|
222
|
-
};
|
|
223
|
-
}
|
|
224
|
-
function UseFilters(...filters) {
|
|
225
|
-
return function (target, contextOrPropertyKey, _descriptor) {
|
|
226
|
-
if (typeof contextOrPropertyKey === 'object' &&
|
|
227
|
-
contextOrPropertyKey !== null) {
|
|
228
|
-
const context = contextOrPropertyKey;
|
|
229
|
-
if (context.kind === 'class') {
|
|
230
|
-
target.prototype[constants_1.LIFECYCLE_METADATA_PROP] =
|
|
231
|
-
target.prototype[constants_1.LIFECYCLE_METADATA_PROP] || {};
|
|
232
|
-
target.prototype[constants_1.LIFECYCLE_METADATA_PROP]._classFilters =
|
|
233
|
-
target.prototype[constants_1.LIFECYCLE_METADATA_PROP]._classFilters || [];
|
|
234
|
-
target.prototype[constants_1.LIFECYCLE_METADATA_PROP]._classFilters.push(...filters);
|
|
235
|
-
}
|
|
236
|
-
else if (context.kind === 'method') {
|
|
237
|
-
;
|
|
238
|
-
target[constants_1.LIFECYCLE_METADATA_PROP] =
|
|
239
|
-
target[constants_1.LIFECYCLE_METADATA_PROP] || {};
|
|
240
|
-
target[constants_1.LIFECYCLE_METADATA_PROP].filters =
|
|
241
|
-
target[constants_1.LIFECYCLE_METADATA_PROP].filters || [];
|
|
242
|
-
target[constants_1.LIFECYCLE_METADATA_PROP].filters.push(...filters);
|
|
243
|
-
}
|
|
244
|
-
}
|
|
245
|
-
else {
|
|
246
|
-
if (typeof target === 'function' && !contextOrPropertyKey) {
|
|
247
|
-
// Legacy class decorator
|
|
248
|
-
target.prototype[constants_1.LIFECYCLE_METADATA_PROP] =
|
|
249
|
-
target.prototype[constants_1.LIFECYCLE_METADATA_PROP] || {};
|
|
250
|
-
target.prototype[constants_1.LIFECYCLE_METADATA_PROP]._classFilters =
|
|
251
|
-
target.prototype[constants_1.LIFECYCLE_METADATA_PROP]._classFilters || [];
|
|
252
|
-
target.prototype[constants_1.LIFECYCLE_METADATA_PROP]._classFilters.push(...filters);
|
|
253
|
-
}
|
|
254
|
-
else {
|
|
255
|
-
// Legacy method decorator
|
|
256
|
-
const fn = target[contextOrPropertyKey];
|
|
257
|
-
fn[constants_1.LIFECYCLE_METADATA_PROP] = fn[constants_1.LIFECYCLE_METADATA_PROP] || {};
|
|
258
|
-
fn[constants_1.LIFECYCLE_METADATA_PROP].filters =
|
|
259
|
-
fn[constants_1.LIFECYCLE_METADATA_PROP].filters || [];
|
|
260
|
-
fn[constants_1.LIFECYCLE_METADATA_PROP].filters.push(...filters);
|
|
261
|
-
}
|
|
262
|
-
}
|
|
190
|
+
methodMiddlewares.push(middlewareProxy);
|
|
263
191
|
};
|
|
264
192
|
}
|
|
265
193
|
//# sourceMappingURL=middleware.js.map
|