exisjs 0.7.0 → 0.7.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +9 -3
- 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/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/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.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 +10 -11
- 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
|
@@ -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
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"middleware.js","sourceRoot":"","sources":["../../src/decorators/middleware.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"middleware.js","sourceRoot":"","sources":["../../src/decorators/middleware.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+CA,kBAsFC;AAKD,8BAEC;AAKD,0CAEC;AAKD,gCAEC;AAWD,gCAgCC;AArMD,2CAIoB;AACpB,8CAAgD;AAEhD;;GAEG;AACH,SAAS,YAAY,CACnB,IAAS;IAET,IAAI,CAAC,IAAI;QAAE,OAAO,YAAY,CAAA;IAE9B,sCAAsC;IACtC,MAAM,KAAK,GAAG,OAAO,IAAI,KAAK,UAAU,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,CAAA;IAEhE,IAAI,KAAK,EAA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AU,CACxB,UAAiE,EAAE;IAEnE,OAAO,UACL,MAAW,EACX,oBAA4C,EAC5C,UAAqC;QAErC,MAAM,UAAU,GACd,OAAO,oBAAoB,KAAK,QAAQ,IAAI,oBAAoB,KAAK,IAAI,CAAA;QAC3E,MAAM,EAAE,GAAG,UAAU;YACnB,CAAC,CAAC,MAAM;YACR,CAAC,CAAC,UAAU;gBACV,CAAC,CAAC,UAAU,CAAC,KAAK;gBAClB,CAAC,CAAC,MAAM,CAAC,oBAAoB,CAAC,CAAA;QAElC,MAAM,iBAAiB,GAAG,yBAAc,CAAC,IAAI,CAC3C,EAAE,EACF,8BAAkB,EAClB,EAAE,CACH,CAAA;QAED,8CAA8C;QAC9C,MAAM,eAAe,GAAG,KAAK,EAAE,GAAQ,EAAE,GAAQ,EAAE,IAAS,EAAE,EAAE;YAC9D,MAAM,EAAE,UAAU,EAAE,oBAAoB,EAAE,GACxC,wDAAa,2BAA2B,GAAC,CAAA;YAC3C,MAAM,OAAO,GAAG,oBAAoB,CAAC,OAAO,CAAC,CAAA;YAC7C,OAAO,OAAO,CAAC,GAAG,EAAE,GAAG,EAAE,IAAI,CAAC,CAAA;QAChC,CAAC,CAAA;QAED,iBAAiB,CAAC,IAAI,CAAC,eAAe,CAAC,CAAA;IACzC,CAAC,CAAA;AACH,CAAC"}
|
|
@@ -1,18 +1,60 @@
|
|
|
1
1
|
import type { RouteSchema } from '../types';
|
|
2
|
-
export
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
2
|
+
export interface CustomParamExecutionContext {
|
|
3
|
+
req: any;
|
|
4
|
+
res: any;
|
|
5
|
+
next: any;
|
|
6
|
+
app: any;
|
|
7
|
+
state: Record<string, any>;
|
|
8
|
+
switchToHttp: () => {
|
|
9
|
+
getRequest: () => any;
|
|
10
|
+
getResponse: () => any;
|
|
11
|
+
getNext: () => any;
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
export type CustomParamFactory<TData = any, TResult = any> = (data: TData, ctx: CustomParamExecutionContext) => TResult;
|
|
15
|
+
/**
|
|
16
|
+
* Creates a custom route parameter decorator.
|
|
17
|
+
*
|
|
18
|
+
* Example:
|
|
19
|
+
* ```ts
|
|
20
|
+
* export const CurrentUser = createParamDecorator(
|
|
21
|
+
* (data: string | undefined, ctx) => {
|
|
22
|
+
* const req = ctx.req
|
|
23
|
+
* return data ? req.user?.[data] : req.user
|
|
24
|
+
* }
|
|
25
|
+
* )
|
|
26
|
+
*
|
|
27
|
+
* // Usage in controller:
|
|
28
|
+
* @Get('/profile')
|
|
29
|
+
* getProfile(@CurrentUser() user: any, @CurrentUser('id') id: string) {}
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
export declare function createParamDecorator<TData = any>(factory: CustomParamFactory<TData>): (data?: TData, ...pipes: any[]) => ParameterDecorator;
|
|
33
|
+
export declare function createParamDecorator(type: string, nameOrPipe?: string | any, ...pipes: any[]): ParameterDecorator;
|
|
34
|
+
export declare const Param: (nameOrPipe?: string | any, ...pipes: any[]) => ParameterDecorator;
|
|
35
|
+
export declare const Body: (nameOrPipe?: string | any, ...pipes: any[]) => ParameterDecorator;
|
|
36
|
+
export declare const Headers: (nameOrPipe?: string | any, ...pipes: any[]) => ParameterDecorator;
|
|
37
|
+
export declare const HostParam: (nameOrPipe?: string | any, ...pipes: any[]) => ParameterDecorator;
|
|
38
|
+
export declare const Req: () => ParameterDecorator;
|
|
39
|
+
export declare const Socket: () => ParameterDecorator;
|
|
40
|
+
export declare const Stream: () => ParameterDecorator;
|
|
41
|
+
export declare const Session: () => ParameterDecorator;
|
|
42
|
+
export declare const Next: () => ParameterDecorator;
|
|
43
|
+
export declare const Ip: () => ParameterDecorator;
|
|
44
|
+
export declare const UploadedFile: (nameOrPipe?: string | any, ...pipes: any[]) => ParameterDecorator;
|
|
45
|
+
export declare const UploadedFiles: (nameOrPipe?: string | any, ...pipes: any[]) => ParameterDecorator;
|
|
14
46
|
export declare const Res: (options?: {
|
|
15
47
|
passthrough?: boolean;
|
|
16
48
|
}) => any;
|
|
49
|
+
/**
|
|
50
|
+
* Injects a query parameter from the URL query string.
|
|
51
|
+
*
|
|
52
|
+
* Example:
|
|
53
|
+
* ```ts
|
|
54
|
+
* @Get('/search')
|
|
55
|
+
* search(@QueryParam('q') q: string) { return { q }; }
|
|
56
|
+
* ```
|
|
57
|
+
*/
|
|
58
|
+
export declare const QueryParam: (nameOrPipe?: string | any, ...pipes: any[]) => ParameterDecorator;
|
|
17
59
|
export declare function Query(pathOrName?: string | any, schemaOrPipe?: RouteSchema<any, any, any, any> | any, ...pipes: any[]): any;
|
|
18
60
|
//# sourceMappingURL=params.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"params.d.ts","sourceRoot":"","sources":["../../src/decorators/params.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,UAAU,CAAA;
|
|
1
|
+
{"version":3,"file":"params.d.ts","sourceRoot":"","sources":["../../src/decorators/params.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,UAAU,CAAA;AAS3C,MAAM,WAAW,2BAA2B;IAC1C,GAAG,EAAE,GAAG,CAAA;IACR,GAAG,EAAE,GAAG,CAAA;IACR,IAAI,EAAE,GAAG,CAAA;IACT,GAAG,EAAE,GAAG,CAAA;IACR,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;IAC1B,YAAY,EAAE,MAAM;QAClB,UAAU,EAAE,MAAM,GAAG,CAAA;QACrB,WAAW,EAAE,MAAM,GAAG,CAAA;QACtB,OAAO,EAAE,MAAM,GAAG,CAAA;KACnB,CAAA;CACF;AAED,MAAM,MAAM,kBAAkB,CAAC,KAAK,GAAG,GAAG,EAAE,OAAO,GAAG,GAAG,IAAI,CAC3D,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BACX,CAAA;AAE7D,eAAO,MAAM,GAAG,GAAI,UAAU;IAAE,WAAW,CAAC,EAAE,OAAO,CAAA;CAAE,KAAG,GAazD,CAAA;AAED;;;;;;;;GAQG;AACH,eAAO,MAAM,UAAU,GAAI,aAAa,MAAM,GAAG,GAAG,EAAE,GAAG,OAAO,GAAG,EAAE,uBAChB,CAAA;AAErD,wBAAgB,KAAK,CACnB,UAAU,CAAC,EAAE,MAAM,GAAG,GAAG,EACzB,YAAY,CAAC,EAAE,WAAW,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,GAAG,GAAG,EACpD,GAAG,KAAK,EAAE,GAAG,EAAE,GACd,GAAG,CAwCL"}
|
|
@@ -1,10 +1,34 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Res = exports.UploadedFiles = exports.UploadedFile = exports.Ip = exports.Next = exports.Session = exports.Stream = exports.Socket = exports.Req = exports.HostParam = exports.Headers = exports.Body = exports.Param = void 0;
|
|
3
|
+
exports.QueryParam = exports.Res = exports.UploadedFiles = exports.UploadedFile = exports.Ip = exports.Next = exports.Session = exports.Stream = exports.Socket = exports.Req = exports.HostParam = exports.Headers = exports.Body = exports.Param = void 0;
|
|
4
|
+
exports.createParamDecorator = createParamDecorator;
|
|
4
5
|
exports.Query = Query;
|
|
5
6
|
const constants_1 = require("./constants");
|
|
6
7
|
const metadata_1 = require("./core/metadata");
|
|
7
|
-
function createParamDecorator(
|
|
8
|
+
function createParamDecorator(typeOrFactory, nameOrPipe, ...pipes) {
|
|
9
|
+
if (typeof typeOrFactory === 'function') {
|
|
10
|
+
const factory = typeOrFactory;
|
|
11
|
+
return function (dataOrPipe, ...customPipes) {
|
|
12
|
+
return function (target, propertyKey, parameterIndex) {
|
|
13
|
+
const isPipe = typeof dataOrPipe === 'function' ||
|
|
14
|
+
(typeof dataOrPipe === 'object' &&
|
|
15
|
+
dataOrPipe !== null &&
|
|
16
|
+
(typeof dataOrPipe.transform === 'function' ||
|
|
17
|
+
typeof dataOrPipe.parse === 'function'));
|
|
18
|
+
const data = isPipe ? undefined : dataOrPipe;
|
|
19
|
+
const allPipes = isPipe ? [dataOrPipe, ...customPipes] : customPipes;
|
|
20
|
+
const fn = target[propertyKey];
|
|
21
|
+
const paramMeta = metadata_1.MetadataEngine.init(fn, constants_1.PARAM_METADATA_PROP, []);
|
|
22
|
+
paramMeta[parameterIndex] = {
|
|
23
|
+
type: 'customParam',
|
|
24
|
+
name: data,
|
|
25
|
+
customFactory: factory,
|
|
26
|
+
pipes: allPipes,
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
const type = typeOrFactory;
|
|
8
32
|
return function (target, propertyKey, parameterIndex) {
|
|
9
33
|
const isPipe = typeof nameOrPipe === 'function' ||
|
|
10
34
|
(typeof nameOrPipe === 'object' && nameOrPipe !== null);
|
|
@@ -15,11 +39,12 @@ function createParamDecorator(type, nameOrPipe, ...pipes) {
|
|
|
15
39
|
paramMeta[parameterIndex] = { type, name, pipes: allPipes };
|
|
16
40
|
};
|
|
17
41
|
}
|
|
42
|
+
const logger_1 = require("../logger");
|
|
18
43
|
const Param = (nameOrPipe, ...pipes) => createParamDecorator('param', nameOrPipe, ...pipes);
|
|
19
44
|
exports.Param = Param;
|
|
20
45
|
const Body = (nameOrPipe, ...pipes) => {
|
|
21
46
|
if (nameOrPipe === undefined && pipes.length === 0) {
|
|
22
|
-
|
|
47
|
+
logger_1.logger.warn(`@Body() decorator used without a validation schema or pipe. It is highly recommended to validate incoming payloads.`);
|
|
23
48
|
}
|
|
24
49
|
return createParamDecorator('body', nameOrPipe, ...pipes);
|
|
25
50
|
};
|
|
@@ -54,28 +79,23 @@ const Res = (options) => {
|
|
|
54
79
|
};
|
|
55
80
|
};
|
|
56
81
|
exports.Res = Res;
|
|
82
|
+
/**
|
|
83
|
+
* Injects a query parameter from the URL query string.
|
|
84
|
+
*
|
|
85
|
+
* Example:
|
|
86
|
+
* ```ts
|
|
87
|
+
* @Get('/search')
|
|
88
|
+
* search(@QueryParam('q') q: string) { return { q }; }
|
|
89
|
+
* ```
|
|
90
|
+
*/
|
|
91
|
+
const QueryParam = (nameOrPipe, ...pipes) => createParamDecorator('query', nameOrPipe, ...pipes);
|
|
92
|
+
exports.QueryParam = QueryParam;
|
|
57
93
|
function Query(pathOrName, schemaOrPipe, ...pipes) {
|
|
58
94
|
return function (target, contextOrPropertyKey, descriptorOrIndex) {
|
|
59
95
|
const isParam = typeof descriptorOrIndex === 'number' ||
|
|
60
96
|
(contextOrPropertyKey && contextOrPropertyKey.kind === 'parameter');
|
|
61
97
|
if (isParam) {
|
|
62
|
-
|
|
63
|
-
(typeof pathOrName === 'object' && pathOrName !== null);
|
|
64
|
-
const name = isPipe ? undefined : pathOrName;
|
|
65
|
-
const pipesArray = isPipe ? [pathOrName] : [];
|
|
66
|
-
if (schemaOrPipe &&
|
|
67
|
-
(typeof schemaOrPipe === 'function' || typeof schemaOrPipe === 'object')) {
|
|
68
|
-
pipesArray.push(schemaOrPipe);
|
|
69
|
-
}
|
|
70
|
-
pipesArray.push(...pipes);
|
|
71
|
-
const parameterIndex = descriptorOrIndex;
|
|
72
|
-
const fn = target[contextOrPropertyKey];
|
|
73
|
-
const paramMeta = metadata_1.MetadataEngine.init(fn, constants_1.PARAM_METADATA_PROP, []);
|
|
74
|
-
paramMeta[parameterIndex] = {
|
|
75
|
-
type: 'query',
|
|
76
|
-
name,
|
|
77
|
-
pipes: pipesArray,
|
|
78
|
-
};
|
|
98
|
+
return (0, exports.QueryParam)(pathOrName, schemaOrPipe, ...pipes)(target, contextOrPropertyKey, descriptorOrIndex);
|
|
79
99
|
}
|
|
80
100
|
else {
|
|
81
101
|
const path = pathOrName || '';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"params.js","sourceRoot":"","sources":["../../src/decorators/params.ts"],"names":[],"mappings":";;;
|
|
1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,MAAM,EAAE,sBAAU,EAAE;oBACrC,MAAM,EAAE,OAAO;oBACf,IAAI;oBACJ,MAAM,EAAE,YAAY;iBACrB,CAAC,CAAA;YACJ,CAAC;iBAAM,CAAC;gBACN,MAAM,KAAK,GAAG,OAAO,MAAM,KAAK,UAAU,CAAC,CAAC,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC,CAAC,MAAM,CAAA;gBACtE,MAAM,IAAI,GAAG,oBAAoB,IAAI,iBAAiB,EAAE,IAAI,CAAA;gBAC5D,yBAAc,CAAC,IAAI,CAAC,KAAK,EAAE,0BAAc,EAAE;oBACzC,MAAM,EAAE,OAAO;oBACf,IAAI;oBACJ,MAAM,EAAE,YAAY;oBACpB,WAAW,EAAE,IAAI;iBAClB,CAAC,CAAA;YACJ,CAAC;QACH,CAAC;IACH,CAAC,CAAA;AACH,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"routing.d.ts","sourceRoot":"","sources":["../../src/decorators/routing.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,UAAU,CAAA;
|
|
1
|
+
{"version":3,"file":"routing.d.ts","sourceRoot":"","sources":["../../src/decorators/routing.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,UAAU,CAAA;AAKvD,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,UAAU,IACrC,aAAS,EAAE,SAAS,WAAW,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,KAAG,GAAG,CAoC3E;AAED;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,GAAG,2BAlDuB,WAAW,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,KAAG,GAkD1B,CAAA;AAE/C;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,IAAI,2BAhEsB,WAAW,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,KAAG,GAgExB,CAAA;AACjD,eAAO,MAAM,GAAG,2BAjEuB,WAAW,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,KAAG,GAiE1B,CAAA;AAC/C,eAAO,MAAM,KAAK,2BAlEqB,WAAW,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,KAAG,GAkEtB,CAAA;AACnD,eAAO,MAAM,MAAM,2BAnEoB,WAAW,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,KAAG,GAmEpB,CAAA;AACrD,eAAO,MAAM,OAAO,2BApEmB,WAAW,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,KAAG,GAoElB,CAAA;AACvD,eAAO,MAAM,IAAI,2BArEsB,WAAW,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,KAAG,GAqExB,CAAA;AACjD,eAAO,MAAM,GAAG,2BAtEuB,WAAW,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,KAAG,GAsE1B,CAAA;AAC/C,eAAO,MAAM,OAAO,2BAvEmB,WAAW,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,KAAG,GAuElB,CAAA;AACvD,eAAO,MAAM,KAAK,2BAxEqB,WAAW,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,KAAG,GAwEtB,CAAA"}
|
|
@@ -4,10 +4,11 @@ exports.Trace = exports.Connect = exports.All = exports.Head = exports.Options =
|
|
|
4
4
|
exports.createMethodDecorator = createMethodDecorator;
|
|
5
5
|
const constants_1 = require("./constants");
|
|
6
6
|
const metadata_1 = require("./core/metadata");
|
|
7
|
+
const logger_1 = require("../logger");
|
|
7
8
|
function createMethodDecorator(method) {
|
|
8
9
|
return function (path = '', schema) {
|
|
9
10
|
if (method === 'GET' && schema?.body) {
|
|
10
|
-
|
|
11
|
+
logger_1.logger.warn(`GET route '${path}' defines a body schema, but GET requests cannot have bodies.`);
|
|
11
12
|
}
|
|
12
13
|
return function (target, contextOrPropertyKey, descriptor) {
|
|
13
14
|
if (typeof contextOrPropertyKey === 'object' &&
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"routing.js","sourceRoot":"","sources":["../../src/decorators/routing.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"routing.js","sourceRoot":"","sources":["../../src/decorators/routing.ts"],"names":[],"mappings":";;;AAKA,sDAqCC;AAzCD,2CAAwD;AACxD,8CAAgD;AAChD,sCAAkC;AAElC,SAAgB,qBAAqB,CAAC,MAAkB;IACtD,OAAO,UAAU,IAAI,GAAG,EAAE,EAAE,MAAwC;QAClE,IAAI,MAAM,KAAK,KAAK,IAAI,MAAM,EAAE,IAAI,EAAE,CAAC;YACrC,eAAM,CAAC,IAAI,CACT,cAAc,IAAI,+DAA+D,CAClF,CAAA;QACH,CAAC;QAED,OAAO,UACL,MAAW,EACX,oBAA4C,EAC5C,UAAqC;YAErC,IACE,OAAO,oBAAoB,KAAK,QAAQ;gBACxC,oBAAoB,KAAK,IAAI;gBAC7B,MAAM,IAAI,oBAAoB,EAC9B,CAAC;gBACD,mCAAmC;gBACnC,yBAAc,CAAC,GAAG,CAAC,MAAM,EAAE,sBAAU,EAAE;oBACrC,MAAM;oBACN,IAAI;oBACJ,MAAM;iBACP,CAAC,CAAA;YACJ,CAAC;iBAAM,CAAC;gBACN,yCAAyC;gBACzC,MAAM,KAAK,GAAG,OAAO,MAAM,KAAK,UAAU,CAAC,CAAC,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC,CAAC,MAAM,CAAA;gBACtE,MAAM,IAAI,GAAG,oBAAoB,IAAI,UAAU,EAAE,IAAI,CAAA;gBACrD,yBAAc,CAAC,IAAI,CAAC,KAAK,EAAE,0BAAc,EAAE;oBACzC,MAAM;oBACN,IAAI;oB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