@lerianstudio/sindarian-server 1.0.0-beta.2 → 1.0.0-beta.21
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 +52 -18
- package/dist/constants/keys.d.ts +1 -0
- package/dist/constants/keys.d.ts.map +1 -1
- package/dist/constants/keys.js +2 -1
- package/dist/constants/keys.js.map +1 -1
- package/dist/controllers/decorators/body-decorator.d.ts +12 -16
- package/dist/controllers/decorators/body-decorator.d.ts.map +1 -1
- package/dist/controllers/decorators/body-decorator.js +52 -58
- package/dist/controllers/decorators/body-decorator.js.map +1 -1
- package/dist/controllers/decorators/controller-decorator.d.ts +5 -4
- package/dist/controllers/decorators/controller-decorator.d.ts.map +1 -1
- package/dist/controllers/decorators/controller-decorator.js +29 -22
- package/dist/controllers/decorators/controller-decorator.js.map +1 -1
- package/dist/controllers/decorators/param-decorator.d.ts +4 -9
- package/dist/controllers/decorators/param-decorator.d.ts.map +1 -1
- package/dist/controllers/decorators/param-decorator.js +33 -29
- package/dist/controllers/decorators/param-decorator.js.map +1 -1
- package/dist/controllers/decorators/query-decorator.d.ts +11 -15
- package/dist/controllers/decorators/query-decorator.d.ts.map +1 -1
- package/dist/controllers/decorators/query-decorator.js +24 -38
- package/dist/controllers/decorators/query-decorator.js.map +1 -1
- package/dist/controllers/decorators/request-decorator.d.ts +8 -12
- package/dist/controllers/decorators/request-decorator.d.ts.map +1 -1
- package/dist/controllers/decorators/request-decorator.js +21 -17
- package/dist/controllers/decorators/request-decorator.js.map +1 -1
- package/dist/controllers/decorators/route-decorator.d.ts +12 -1
- package/dist/controllers/decorators/route-decorator.d.ts.map +1 -1
- package/dist/controllers/decorators/route-decorator.js +24 -16
- package/dist/controllers/decorators/route-decorator.js.map +1 -1
- package/dist/dependency-injection/container.d.ts +4 -3
- package/dist/dependency-injection/container.d.ts.map +1 -1
- package/dist/dependency-injection/container.js +14 -3
- package/dist/dependency-injection/container.js.map +1 -1
- package/dist/exceptions/api-exception.d.ts +4 -7
- package/dist/exceptions/api-exception.d.ts.map +1 -1
- package/dist/exceptions/api-exception.js +8 -4
- package/dist/exceptions/api-exception.js.map +1 -1
- package/dist/exceptions/base-exception-filter.d.ts.map +1 -1
- package/dist/exceptions/base-exception-filter.js +10 -3
- package/dist/exceptions/base-exception-filter.js.map +1 -1
- package/dist/exceptions/decorators/use-filters-decorator.d.ts +12 -1
- package/dist/exceptions/decorators/use-filters-decorator.d.ts.map +1 -1
- package/dist/exceptions/decorators/use-filters-decorator.js +34 -3
- package/dist/exceptions/decorators/use-filters-decorator.js.map +1 -1
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -1
- package/dist/index.js.map +1 -1
- package/dist/interceptor/decorators/use-interceptor-decorator.d.ts +10 -3
- package/dist/interceptor/decorators/use-interceptor-decorator.d.ts.map +1 -1
- package/dist/interceptor/decorators/use-interceptor-decorator.js +60 -22
- package/dist/interceptor/decorators/use-interceptor-decorator.js.map +1 -1
- package/dist/modules/module-decorator.d.ts +2 -2
- package/dist/modules/module-decorator.d.ts.map +1 -1
- package/dist/modules/module-decorator.js +7 -13
- package/dist/modules/module-decorator.js.map +1 -1
- package/dist/pipes/decorators/index.d.ts +2 -0
- package/dist/pipes/decorators/index.d.ts.map +1 -0
- package/dist/pipes/decorators/index.js +6 -0
- package/dist/pipes/decorators/index.js.map +1 -0
- package/dist/pipes/decorators/use-pipes.d.ts +19 -0
- package/dist/pipes/decorators/use-pipes.d.ts.map +1 -0
- package/dist/pipes/decorators/use-pipes.js +118 -0
- package/dist/pipes/decorators/use-pipes.js.map +1 -0
- package/dist/pipes/index.d.ts +3 -0
- package/dist/pipes/index.d.ts.map +1 -0
- package/dist/pipes/index.js +18 -0
- package/dist/pipes/index.js.map +1 -0
- package/dist/pipes/pipe-transform.d.ts +46 -0
- package/dist/pipes/pipe-transform.d.ts.map +1 -0
- package/dist/pipes/pipe-transform.js +3 -0
- package/dist/pipes/pipe-transform.js.map +1 -0
- package/dist/server/server-factory.d.ts +25 -0
- package/dist/server/server-factory.d.ts.map +1 -1
- package/dist/server/server-factory.js +98 -33
- package/dist/server/server-factory.js.map +1 -1
- package/dist/services/http-service.d.ts +2 -2
- package/dist/services/http-service.d.ts.map +1 -1
- package/dist/services/http-service.js.map +1 -1
- package/dist/services/pipes.d.ts +2 -0
- package/dist/services/pipes.d.ts.map +1 -0
- package/dist/services/pipes.js +5 -0
- package/dist/services/pipes.js.map +1 -0
- package/dist/utils/routes/route-specificity.d.ts +40 -0
- package/dist/utils/routes/route-specificity.d.ts.map +1 -0
- package/dist/utils/routes/route-specificity.js +89 -0
- package/dist/utils/routes/route-specificity.js.map +1 -0
- package/dist/utils/url/url-match.d.ts.map +1 -1
- package/dist/utils/url/url-match.js +16 -2
- package/dist/utils/url/url-match.js.map +1 -1
- package/dist/zod/create-zod-dto.d.ts +16 -0
- package/dist/zod/create-zod-dto.d.ts.map +1 -0
- package/dist/zod/create-zod-dto.js +14 -0
- package/dist/zod/create-zod-dto.js.map +1 -0
- package/dist/zod/index.d.ts +3 -0
- package/dist/zod/index.d.ts.map +1 -0
- package/dist/zod/index.js +8 -0
- package/dist/zod/index.js.map +1 -0
- package/dist/zod/zod-validation-pipe.d.ts +5 -0
- package/dist/zod/zod-validation-pipe.d.ts.map +1 -0
- package/dist/zod/zod-validation-pipe.js +35 -0
- package/dist/zod/zod-validation-pipe.js.map +1 -0
- package/package.json +6 -2
package/README.md
CHANGED
|
@@ -4,15 +4,15 @@ A lightweight, NestJS-inspired framework designed specifically for Next.js appli
|
|
|
4
4
|
|
|
5
5
|
## ( Features
|
|
6
6
|
|
|
7
|
-
- =� **NestJS-like API** - Familiar decorators and patterns
|
|
8
|
-
- � **Next.js Optimized** - Built for serverless environments
|
|
9
|
-
- =� **Dependency Injection** - Powered by Inversify
|
|
10
|
-
- =� **Decorator-based Routing** - Clean, declarative route definitions
|
|
7
|
+
- =� **NestJS-like API** - Familiar decorators and patterns
|
|
8
|
+
- � **Next.js Optimized** - Built for serverless environments
|
|
9
|
+
- =� **Dependency Injection** - Powered by Inversify
|
|
10
|
+
- =� **Decorator-based Routing** - Clean, declarative route definitions
|
|
11
11
|
- =' **Middleware Support** - Interceptors and exception filters
|
|
12
|
-
- =� **TypeScript First** - Full type safety out of the box
|
|
13
|
-
- <� **Lightweight** - Minimal overhead for fast cold starts
|
|
12
|
+
- =� **TypeScript First** - Full type safety out of the box
|
|
13
|
+
- <� **Lightweight** - Minimal overhead for fast cold starts
|
|
14
14
|
|
|
15
|
-
## =� Quick Start
|
|
15
|
+
## =� Quick Start
|
|
16
16
|
|
|
17
17
|
### Installation
|
|
18
18
|
|
|
@@ -119,7 +119,7 @@ export async function PATCH(request: NextRequest, context: any) {
|
|
|
119
119
|
}
|
|
120
120
|
```
|
|
121
121
|
|
|
122
|
-
## =� Core Concepts
|
|
122
|
+
## =� Core Concepts
|
|
123
123
|
|
|
124
124
|
### Controllers
|
|
125
125
|
|
|
@@ -212,24 +212,41 @@ Create custom exception filters:
|
|
|
212
212
|
export class ValidationFilter implements ExceptionFilter {
|
|
213
213
|
async catch(exception: ValidationError, host: ArgumentsHost) {
|
|
214
214
|
return NextResponse.json(
|
|
215
|
-
{
|
|
215
|
+
{
|
|
216
216
|
message: 'Validation failed',
|
|
217
|
-
errors: exception.errors
|
|
217
|
+
errors: exception.errors
|
|
218
218
|
},
|
|
219
219
|
{ status: 400 }
|
|
220
220
|
)
|
|
221
221
|
}
|
|
222
222
|
}
|
|
223
223
|
|
|
224
|
-
// Apply globally
|
|
224
|
+
// Apply globally via app
|
|
225
225
|
app.useGlobalFilters(new ValidationFilter())
|
|
226
226
|
|
|
227
|
+
// Or register via module providers (supports multiple filters)
|
|
228
|
+
@Module({
|
|
229
|
+
providers: [
|
|
230
|
+
{
|
|
231
|
+
provide: APP_FILTER,
|
|
232
|
+
useClass: ValidationFilter
|
|
233
|
+
},
|
|
234
|
+
{
|
|
235
|
+
provide: APP_FILTER,
|
|
236
|
+
useClass: DatabaseErrorFilter
|
|
237
|
+
}
|
|
238
|
+
]
|
|
239
|
+
})
|
|
240
|
+
export class AppModule {}
|
|
241
|
+
|
|
227
242
|
// Or on specific controllers
|
|
228
243
|
@Controller('/users')
|
|
229
244
|
@UseFilters(ValidationFilter)
|
|
230
245
|
export class UserController extends BaseController {}
|
|
231
246
|
```
|
|
232
247
|
|
|
248
|
+
**Note**: When registering multiple filters via `APP_FILTER`, they execute in reverse order (last registered runs first), allowing more specific filters to handle exceptions before general ones.
|
|
249
|
+
|
|
233
250
|
### Interceptors
|
|
234
251
|
|
|
235
252
|
Add cross-cutting concerns with interceptors:
|
|
@@ -240,22 +257,39 @@ export class LoggingInterceptor implements Interceptor {
|
|
|
240
257
|
const start = Date.now()
|
|
241
258
|
const result = await next.handle()
|
|
242
259
|
const duration = Date.now() - start
|
|
243
|
-
|
|
260
|
+
|
|
244
261
|
console.log(`${context.getClass().name}.${context.getHandler().name} - ${duration}ms`)
|
|
245
262
|
return result
|
|
246
263
|
}
|
|
247
264
|
}
|
|
248
265
|
|
|
249
|
-
// Apply globally
|
|
266
|
+
// Apply globally via app
|
|
250
267
|
app.useGlobalInterceptors(new LoggingInterceptor())
|
|
251
268
|
|
|
269
|
+
// Or register via module providers (supports multiple interceptors)
|
|
270
|
+
@Module({
|
|
271
|
+
providers: [
|
|
272
|
+
{
|
|
273
|
+
provide: APP_INTERCEPTOR,
|
|
274
|
+
useClass: LoggingInterceptor
|
|
275
|
+
},
|
|
276
|
+
{
|
|
277
|
+
provide: APP_INTERCEPTOR,
|
|
278
|
+
useClass: TransformInterceptor
|
|
279
|
+
}
|
|
280
|
+
]
|
|
281
|
+
})
|
|
282
|
+
export class AppModule {}
|
|
283
|
+
|
|
252
284
|
// Or on specific controllers
|
|
253
285
|
@Controller('/users')
|
|
254
286
|
@UseInterceptors(LoggingInterceptor)
|
|
255
287
|
export class UserController extends BaseController {}
|
|
256
288
|
```
|
|
257
289
|
|
|
258
|
-
|
|
290
|
+
**Note**: Multiple `APP_INTERCEPTOR` and `APP_PIPE` providers are supported and execute in reverse registration order (last registered runs first).
|
|
291
|
+
|
|
292
|
+
## <� Parameter Decorators
|
|
259
293
|
|
|
260
294
|
Extract data from requests with decorators:
|
|
261
295
|
|
|
@@ -333,7 +367,7 @@ export class AuthService {
|
|
|
333
367
|
}
|
|
334
368
|
```
|
|
335
369
|
|
|
336
|
-
## =� Documentation
|
|
370
|
+
## =� Documentation
|
|
337
371
|
|
|
338
372
|
- **[Technical Guide](./TECHNICAL.md)** - Deep dive into the framework's architecture and implementation details
|
|
339
373
|
- **[API Reference](./docs/api.md)** - Complete API documentation
|
|
@@ -343,7 +377,7 @@ export class AuthService {
|
|
|
343
377
|
|
|
344
378
|
Contributions are welcome! Please read our [Contributing Guide](./CONTRIBUTING.md) for details on our code of conduct and the process for submitting pull requests.
|
|
345
379
|
|
|
346
|
-
## =� License
|
|
380
|
+
## =� License
|
|
347
381
|
|
|
348
382
|
This project is licensed under the ISC License - see the [LICENSE](./LICENSE) file for details.
|
|
349
383
|
|
|
@@ -353,7 +387,7 @@ This project is licensed under the ISC License - see the [LICENSE](./LICENSE) fi
|
|
|
353
387
|
- Built on [Inversify](https://inversify.io/) - A powerful IoC container for TypeScript
|
|
354
388
|
- Designed for [Next.js](https://nextjs.org/) - The React framework for production
|
|
355
389
|
|
|
356
|
-
## =� What's Next?
|
|
390
|
+
## =� What's Next?
|
|
357
391
|
|
|
358
392
|
- [ ] Validation pipes with Zod integration
|
|
359
393
|
- [ ] Built-in authentication guards
|
|
@@ -364,4 +398,4 @@ This project is licensed under the ISC License - see the [LICENSE](./LICENSE) fi
|
|
|
364
398
|
|
|
365
399
|
---
|
|
366
400
|
|
|
367
|
-
**Sindarian Server** - Building the future of Next.js APIs, one decorator at a time. =�
|
|
401
|
+
**Sindarian Server** - Building the future of Next.js APIs, one decorator at a time. =�
|
package/dist/constants/keys.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ export declare const CONTROLLER_KEY: unique symbol;
|
|
|
4
4
|
export declare const CATCH_KEY: unique symbol;
|
|
5
5
|
export declare const FILTER_KEY: unique symbol;
|
|
6
6
|
export declare const INTERCEPTOR_KEY: unique symbol;
|
|
7
|
+
export declare const PIPE_KEY: unique symbol;
|
|
7
8
|
export declare const ROUTE_KEY: unique symbol;
|
|
8
9
|
export declare const GET_KEY: unique symbol;
|
|
9
10
|
export declare const POST_KEY: unique symbol;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"keys.d.ts","sourceRoot":"","sources":["../../src/constants/keys.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,cAAc,eAAuB,CAAA;AAElD,eAAO,MAAM,UAAU,eAAmB,CAAA;AAC1C,eAAO,MAAM,cAAc,eAAuB,CAAA;AAClD,eAAO,MAAM,SAAS,eAAkB,CAAA;AACxC,eAAO,MAAM,UAAU,eAAmB,CAAA;AAC1C,eAAO,MAAM,eAAe,eAAwB,CAAA;
|
|
1
|
+
{"version":3,"file":"keys.d.ts","sourceRoot":"","sources":["../../src/constants/keys.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,cAAc,eAAuB,CAAA;AAElD,eAAO,MAAM,UAAU,eAAmB,CAAA;AAC1C,eAAO,MAAM,cAAc,eAAuB,CAAA;AAClD,eAAO,MAAM,SAAS,eAAkB,CAAA;AACxC,eAAO,MAAM,UAAU,eAAmB,CAAA;AAC1C,eAAO,MAAM,eAAe,eAAwB,CAAA;AACpD,eAAO,MAAM,QAAQ,eAAiB,CAAA;AAEtC,eAAO,MAAM,SAAS,eAAkB,CAAA;AACxC,eAAO,MAAM,OAAO,eAAgB,CAAA;AACpC,eAAO,MAAM,QAAQ,eAAiB,CAAA;AACtC,eAAO,MAAM,OAAO,eAAgB,CAAA;AACpC,eAAO,MAAM,SAAS,eAAkB,CAAA;AACxC,eAAO,MAAM,UAAU,eAAmB,CAAA;AAE1C,eAAO,MAAM,QAAQ,eAAiB,CAAA;AACtC,eAAO,MAAM,WAAW,eAAoB,CAAA;AAC5C,eAAO,MAAM,SAAS,eAAkB,CAAA;AACxC,eAAO,MAAM,SAAS,eAAkB,CAAA;AAExC,eAAO,MAAM,gBAAgB,gBAAgB,CAAA;AAC7C,eAAO,MAAM,eAAe,eAAe,CAAA;AAC3C,eAAO,MAAM,kBAAkB,kBAAkB,CAAA;AACjD,eAAO,MAAM,oBAAoB,oBAAoB,CAAA"}
|
package/dist/constants/keys.js
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.CONTROLLERS_PROPERTY = exports.PROVIDERS_PROPERTY = exports.MODULE_PROPERTY = exports.IMPORTS_PROPERTY = exports.QUERY_KEY = exports.PARAM_KEY = exports.REQUEST_KEY = exports.BODY_KEY = exports.DELETE_KEY = exports.PATCH_KEY = exports.PUT_KEY = exports.POST_KEY = exports.GET_KEY = exports.ROUTE_KEY = exports.INTERCEPTOR_KEY = exports.FILTER_KEY = exports.CATCH_KEY = exports.CONTROLLER_KEY = exports.MODULE_KEY = exports.INJECTABLE_KEY = void 0;
|
|
3
|
+
exports.CONTROLLERS_PROPERTY = exports.PROVIDERS_PROPERTY = exports.MODULE_PROPERTY = exports.IMPORTS_PROPERTY = exports.QUERY_KEY = exports.PARAM_KEY = exports.REQUEST_KEY = exports.BODY_KEY = exports.DELETE_KEY = exports.PATCH_KEY = exports.PUT_KEY = exports.POST_KEY = exports.GET_KEY = exports.ROUTE_KEY = exports.PIPE_KEY = exports.INTERCEPTOR_KEY = exports.FILTER_KEY = exports.CATCH_KEY = exports.CONTROLLER_KEY = exports.MODULE_KEY = exports.INJECTABLE_KEY = void 0;
|
|
4
4
|
exports.INJECTABLE_KEY = Symbol('injectable');
|
|
5
5
|
exports.MODULE_KEY = Symbol('module');
|
|
6
6
|
exports.CONTROLLER_KEY = Symbol('controller');
|
|
7
7
|
exports.CATCH_KEY = Symbol('catch');
|
|
8
8
|
exports.FILTER_KEY = Symbol('filter');
|
|
9
9
|
exports.INTERCEPTOR_KEY = Symbol('interceptor');
|
|
10
|
+
exports.PIPE_KEY = Symbol('pipe');
|
|
10
11
|
exports.ROUTE_KEY = Symbol('route');
|
|
11
12
|
exports.GET_KEY = Symbol('get');
|
|
12
13
|
exports.POST_KEY = Symbol('post');
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"keys.js","sourceRoot":"","sources":["../../src/constants/keys.ts"],"names":[],"mappings":";;;AAAa,QAAA,cAAc,GAAG,MAAM,CAAC,YAAY,CAAC,CAAA;AAErC,QAAA,UAAU,GAAG,MAAM,CAAC,QAAQ,CAAC,CAAA;AAC7B,QAAA,cAAc,GAAG,MAAM,CAAC,YAAY,CAAC,CAAA;AACrC,QAAA,SAAS,GAAG,MAAM,CAAC,OAAO,CAAC,CAAA;AAC3B,QAAA,UAAU,GAAG,MAAM,CAAC,QAAQ,CAAC,CAAA;AAC7B,QAAA,eAAe,GAAG,MAAM,CAAC,aAAa,CAAC,CAAA;
|
|
1
|
+
{"version":3,"file":"keys.js","sourceRoot":"","sources":["../../src/constants/keys.ts"],"names":[],"mappings":";;;AAAa,QAAA,cAAc,GAAG,MAAM,CAAC,YAAY,CAAC,CAAA;AAErC,QAAA,UAAU,GAAG,MAAM,CAAC,QAAQ,CAAC,CAAA;AAC7B,QAAA,cAAc,GAAG,MAAM,CAAC,YAAY,CAAC,CAAA;AACrC,QAAA,SAAS,GAAG,MAAM,CAAC,OAAO,CAAC,CAAA;AAC3B,QAAA,UAAU,GAAG,MAAM,CAAC,QAAQ,CAAC,CAAA;AAC7B,QAAA,eAAe,GAAG,MAAM,CAAC,aAAa,CAAC,CAAA;AACvC,QAAA,QAAQ,GAAG,MAAM,CAAC,MAAM,CAAC,CAAA;AAEzB,QAAA,SAAS,GAAG,MAAM,CAAC,OAAO,CAAC,CAAA;AAC3B,QAAA,OAAO,GAAG,MAAM,CAAC,KAAK,CAAC,CAAA;AACvB,QAAA,QAAQ,GAAG,MAAM,CAAC,MAAM,CAAC,CAAA;AACzB,QAAA,OAAO,GAAG,MAAM,CAAC,KAAK,CAAC,CAAA;AACvB,QAAA,SAAS,GAAG,MAAM,CAAC,OAAO,CAAC,CAAA;AAC3B,QAAA,UAAU,GAAG,MAAM,CAAC,QAAQ,CAAC,CAAA;AAE7B,QAAA,QAAQ,GAAG,MAAM,CAAC,MAAM,CAAC,CAAA;AACzB,QAAA,WAAW,GAAG,MAAM,CAAC,SAAS,CAAC,CAAA;AAC/B,QAAA,SAAS,GAAG,MAAM,CAAC,OAAO,CAAC,CAAA;AAC3B,QAAA,SAAS,GAAG,MAAM,CAAC,OAAO,CAAC,CAAA;AAE3B,QAAA,gBAAgB,GAAG,aAAa,CAAA;AAChC,QAAA,eAAe,GAAG,YAAY,CAAA;AAC9B,QAAA,kBAAkB,GAAG,eAAe,CAAA;AACpC,QAAA,oBAAoB,GAAG,iBAAiB,CAAA"}
|
|
@@ -1,24 +1,20 @@
|
|
|
1
1
|
export type BodyMetadata = {
|
|
2
|
-
propertyIndex: number;
|
|
3
|
-
schema?: () => any;
|
|
4
|
-
};
|
|
5
|
-
/**
|
|
6
|
-
* Handler to validate the body of the request.
|
|
7
|
-
*
|
|
8
|
-
* @param target - The target object.
|
|
9
|
-
* @param propertyKey - The property key.
|
|
10
|
-
* @param args - The arguments.
|
|
11
|
-
* @returns The parameter and parameter index.
|
|
12
|
-
*/
|
|
13
|
-
export declare function bodyDecoratorHandler(target: object, propertyKey: string | symbol, args: any[]): Promise<{
|
|
14
|
-
parameter: any;
|
|
15
2
|
parameterIndex: number;
|
|
16
|
-
}
|
|
3
|
+
};
|
|
4
|
+
export declare class BodyHandler {
|
|
5
|
+
private static bodyCache;
|
|
6
|
+
static getMetadata(target: object, propertyKey: string | symbol): BodyMetadata | undefined;
|
|
7
|
+
static handle(target: object, propertyKey: string | symbol, args: any[]): Promise<{
|
|
8
|
+
type: string;
|
|
9
|
+
parameter: any;
|
|
10
|
+
parameterIndex: number;
|
|
11
|
+
paramType: any;
|
|
12
|
+
} | null>;
|
|
13
|
+
}
|
|
17
14
|
/**
|
|
18
15
|
* Decorator to validate the body of the request.
|
|
19
16
|
*
|
|
20
|
-
* @param schema - The Zod schema to validate the body against.
|
|
21
17
|
* @returns A decorator function that can be used to decorate a controller method.
|
|
22
18
|
*/
|
|
23
|
-
export declare function Body(
|
|
19
|
+
export declare function Body(): (target: object, propertyKey: string | symbol, propertyIndex: number) => void;
|
|
24
20
|
//# sourceMappingURL=body-decorator.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"body-decorator.d.ts","sourceRoot":"","sources":["../../../src/controllers/decorators/body-decorator.ts"],"names":[],"mappings":"AAMA,MAAM,MAAM,YAAY,GAAG;IACzB,
|
|
1
|
+
{"version":3,"file":"body-decorator.d.ts","sourceRoot":"","sources":["../../../src/controllers/decorators/body-decorator.ts"],"names":[],"mappings":"AAMA,MAAM,MAAM,YAAY,GAAG;IACzB,cAAc,EAAE,MAAM,CAAA;CACvB,CAAA;AAED,qBAAa,WAAW;IAEtB,OAAO,CAAC,MAAM,CAAC,SAAS,CAAkC;IAE1D,MAAM,CAAC,WAAW,CAChB,MAAM,EAAE,MAAM,EACd,WAAW,EAAE,MAAM,GAAG,MAAM,GAC3B,YAAY,GAAG,SAAS;WAmBd,MAAM,CACjB,MAAM,EAAE,MAAM,EACd,WAAW,EAAE,MAAM,GAAG,MAAM,EAC5B,IAAI,EAAE,GAAG,EAAE;;;;;;CAqDd;AAED;;;;GAIG;AACH,wBAAgB,IAAI,KAEhB,QAAQ,MAAM,EACd,aAAa,MAAM,GAAG,MAAM,EAC5B,eAAe,MAAM,UAWxB"}
|
|
@@ -1,83 +1,77 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.BodyHandler = void 0;
|
|
4
4
|
exports.Body = Body;
|
|
5
5
|
const keys_1 = require("../../constants/keys");
|
|
6
6
|
const get_next_arguments_1 = require("../../utils/nextjs/get-next-arguments");
|
|
7
7
|
const api_exception_1 = require("../../exceptions/api-exception");
|
|
8
8
|
const get_form_data_1 = require("../../utils/form-data/get-form-data");
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
const
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
9
|
+
class BodyHandler {
|
|
10
|
+
static getMetadata(target, propertyKey) {
|
|
11
|
+
let metadata = Reflect.getOwnMetadata(keys_1.BODY_KEY, target, propertyKey);
|
|
12
|
+
// If not found on instance, try constructor prototype
|
|
13
|
+
if (!metadata && target.constructor) {
|
|
14
|
+
metadata = Reflect.getOwnMetadata(keys_1.BODY_KEY, target.constructor.prototype, propertyKey);
|
|
15
|
+
}
|
|
16
|
+
return metadata;
|
|
17
|
+
}
|
|
18
|
+
static async handle(target, propertyKey, args) {
|
|
19
|
+
const metadata = this.getMetadata(target, propertyKey);
|
|
20
|
+
// If the metadata is not found, return null.
|
|
21
|
+
if (metadata) {
|
|
22
|
+
// Get the route metadata to access paramTypes (check both target and prototype)
|
|
23
|
+
let routeMetadata = Reflect.getOwnMetadata(keys_1.ROUTE_KEY, target, propertyKey);
|
|
24
|
+
if (!routeMetadata && target.constructor) {
|
|
25
|
+
routeMetadata = Reflect.getOwnMetadata(keys_1.ROUTE_KEY, target.constructor.prototype, propertyKey);
|
|
26
|
+
}
|
|
27
|
+
const paramTypes = routeMetadata?.paramTypes || [];
|
|
28
|
+
const request = (0, get_next_arguments_1.getNextRequestArgument)(args);
|
|
29
|
+
// Check if body is already cached
|
|
30
|
+
let body = this.bodyCache.get(request);
|
|
31
|
+
if (!body) {
|
|
32
|
+
const contentType = request.headers.get('Content-Type');
|
|
33
|
+
try {
|
|
34
|
+
if (contentType?.includes('multipart/form-data')) {
|
|
35
|
+
body = (0, get_form_data_1.getFormData)(await request.formData());
|
|
36
|
+
}
|
|
37
|
+
else if (contentType?.includes('application/json')) {
|
|
38
|
+
body = await request.json();
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
body = await request.text();
|
|
42
|
+
}
|
|
43
|
+
// Cache the parsed body
|
|
44
|
+
this.bodyCache.set(request, body);
|
|
45
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
34
46
|
}
|
|
35
|
-
|
|
36
|
-
|
|
47
|
+
catch (error) {
|
|
48
|
+
// Handle missing or invalid body
|
|
49
|
+
throw new api_exception_1.ValidationApiException('Missing or invalid request body');
|
|
37
50
|
}
|
|
38
|
-
// Cache the parsed body
|
|
39
|
-
bodyCache.set(request, body);
|
|
40
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
41
|
-
}
|
|
42
|
-
catch (error) {
|
|
43
|
-
// Handle missing or invalid body
|
|
44
|
-
throw new api_exception_1.ValidationApiException('Missing or invalid request body');
|
|
45
51
|
}
|
|
46
|
-
}
|
|
47
|
-
// If the schema is not provided, return the body.
|
|
48
|
-
if (!metadata.schema) {
|
|
49
52
|
return {
|
|
53
|
+
type: 'body',
|
|
50
54
|
parameter: body,
|
|
51
|
-
parameterIndex: metadata.
|
|
55
|
+
parameterIndex: metadata.parameterIndex,
|
|
56
|
+
paramType: paramTypes[metadata.parameterIndex]
|
|
52
57
|
};
|
|
53
58
|
}
|
|
54
|
-
|
|
55
|
-
const resolvedSchema = metadata.schema?.();
|
|
56
|
-
const parsedBody = resolvedSchema?.safeParse(body);
|
|
57
|
-
// If the body is not valid, throw a validation error.
|
|
58
|
-
if (parsedBody && !parsedBody.success) {
|
|
59
|
-
throw new api_exception_1.ValidationApiException(`Invalid body: ${JSON.stringify(parsedBody.error.flatten().fieldErrors)}`);
|
|
60
|
-
}
|
|
61
|
-
return {
|
|
62
|
-
parameter: body,
|
|
63
|
-
parameterIndex: metadata.propertyIndex
|
|
64
|
-
};
|
|
59
|
+
return null;
|
|
65
60
|
}
|
|
66
|
-
return null;
|
|
67
61
|
}
|
|
62
|
+
exports.BodyHandler = BodyHandler;
|
|
63
|
+
// Cache to store parsed body to avoid reading it multiple times
|
|
64
|
+
BodyHandler.bodyCache = new WeakMap();
|
|
68
65
|
/**
|
|
69
66
|
* Decorator to validate the body of the request.
|
|
70
67
|
*
|
|
71
|
-
* @param schema - The Zod schema to validate the body against.
|
|
72
68
|
* @returns A decorator function that can be used to decorate a controller method.
|
|
73
69
|
*/
|
|
74
|
-
function Body(
|
|
70
|
+
function Body() {
|
|
75
71
|
return function (target, propertyKey, propertyIndex) {
|
|
76
|
-
|
|
77
|
-
propertyIndex
|
|
78
|
-
|
|
79
|
-
};
|
|
80
|
-
Reflect.defineMetadata(keys_1.BODY_KEY, metadata, target, propertyKey);
|
|
72
|
+
Reflect.defineMetadata(keys_1.BODY_KEY, {
|
|
73
|
+
parameterIndex: propertyIndex
|
|
74
|
+
}, target, propertyKey);
|
|
81
75
|
};
|
|
82
76
|
}
|
|
83
77
|
//# sourceMappingURL=body-decorator.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"body-decorator.js","sourceRoot":"","sources":["../../../src/controllers/decorators/body-decorator.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"body-decorator.js","sourceRoot":"","sources":["../../../src/controllers/decorators/body-decorator.ts"],"names":[],"mappings":"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"}
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { RouteMetadata } from './route-decorator';
|
|
2
2
|
export type ControllerMetadata = {
|
|
3
|
-
methodName: string;
|
|
4
|
-
method: HttpMethods;
|
|
5
3
|
path: string;
|
|
6
4
|
};
|
|
7
|
-
export declare
|
|
5
|
+
export declare class ControllerHandler {
|
|
6
|
+
static getMetadata(target: object): ControllerMetadata | undefined;
|
|
7
|
+
static getRoutes(target: Function): RouteMetadata[];
|
|
8
|
+
}
|
|
8
9
|
/**
|
|
9
10
|
* A class decorator that wraps all methods in the class with error handling.
|
|
10
11
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"controller-decorator.d.ts","sourceRoot":"","sources":["../../../src/controllers/decorators/controller-decorator.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"controller-decorator.d.ts","sourceRoot":"","sources":["../../../src/controllers/decorators/controller-decorator.ts"],"names":[],"mappings":"AAEA,OAAO,EAAgB,aAAa,EAAE,MAAM,mBAAmB,CAAA;AAK/D,MAAM,MAAM,kBAAkB,GAAG;IAC/B,IAAI,EAAE,MAAM,CAAA;CACb,CAAA;AAED,qBAAa,iBAAiB;IAC5B,MAAM,CAAC,WAAW,CAAC,MAAM,EAAE,MAAM,GAAG,kBAAkB,GAAG,SAAS;IAIlE,MAAM,CAAC,SAAS,CAAC,MAAM,EAAE,QAAQ,GAAG,aAAa,EAAE;CAiCpD;AAED;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,cAAc,CAIvD"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.ControllerHandler = void 0;
|
|
4
4
|
exports.Controller = Controller;
|
|
5
5
|
const inversify_1 = require("inversify");
|
|
6
6
|
const keys_1 = require("../../constants/keys");
|
|
@@ -8,31 +8,38 @@ const route_decorator_1 = require("./route-decorator");
|
|
|
8
8
|
const apply_decorators_1 = require("../../utils/apply-decorators");
|
|
9
9
|
const get_class_methods_1 = require("../../utils/class/get-class-methods");
|
|
10
10
|
const url_join_1 = require("../../utils/url/url-join");
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
const metadata = Reflect.getOwnMetadata(keys_1.CONTROLLER_KEY, target);
|
|
15
|
-
if (!metadata) {
|
|
16
|
-
console.warn(`Class ${target.name} does not have a Controller decorator`);
|
|
17
|
-
return [];
|
|
11
|
+
class ControllerHandler {
|
|
12
|
+
static getMetadata(target) {
|
|
13
|
+
return Reflect.getOwnMetadata(keys_1.CONTROLLER_KEY, target);
|
|
18
14
|
}
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
const
|
|
23
|
-
if (
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
// Add the route to the routes array
|
|
27
|
-
routes.push({
|
|
28
|
-
methodName: methodName,
|
|
29
|
-
method: routeMetadata.method,
|
|
30
|
-
path: url
|
|
31
|
-
});
|
|
15
|
+
static getRoutes(target) {
|
|
16
|
+
const routes = [];
|
|
17
|
+
const prototype = target.prototype;
|
|
18
|
+
const metadata = Reflect.getOwnMetadata(keys_1.CONTROLLER_KEY, target);
|
|
19
|
+
if (!metadata) {
|
|
20
|
+
console.warn(`Class ${target.name} does not have a Controller decorator`);
|
|
21
|
+
return [];
|
|
32
22
|
}
|
|
23
|
+
const methodNames = (0, get_class_methods_1.getClassMethods)(target);
|
|
24
|
+
// Compile all routes from the controller
|
|
25
|
+
for (const methodName of methodNames) {
|
|
26
|
+
const routeMetadata = route_decorator_1.RouteHandler.getMetadata(prototype, methodName);
|
|
27
|
+
if (routeMetadata) {
|
|
28
|
+
// Join the controller path with the route path
|
|
29
|
+
const url = (0, url_join_1.urlJoin)(metadata.path, routeMetadata.path);
|
|
30
|
+
// Add the route to the routes array
|
|
31
|
+
routes.push({
|
|
32
|
+
methodName: methodName,
|
|
33
|
+
method: routeMetadata.method,
|
|
34
|
+
path: url,
|
|
35
|
+
paramTypes: routeMetadata.paramTypes
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
return routes;
|
|
33
40
|
}
|
|
34
|
-
return routes;
|
|
35
41
|
}
|
|
42
|
+
exports.ControllerHandler = ControllerHandler;
|
|
36
43
|
/**
|
|
37
44
|
* A class decorator that wraps all methods in the class with error handling.
|
|
38
45
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"controller-decorator.js","sourceRoot":"","sources":["../../../src/controllers/decorators/controller-decorator.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"controller-decorator.js","sourceRoot":"","sources":["../../../src/controllers/decorators/controller-decorator.ts"],"names":[],"mappings":";;;AAwDA,gCAIC;AA5DD,yCAAsC;AACtC,2CAAiD;AACjD,uDAA+D;AAC/D,+DAA0D;AAC1D,uEAAiE;AACjE,mDAA8C;AAM9C,MAAa,iBAAiB;IAC5B,MAAM,CAAC,WAAW,CAAC,MAAc;QAC/B,OAAO,OAAO,CAAC,cAAc,CAAC,qBAAc,EAAE,MAAM,CAAC,CAAA;IACvD,CAAC;IAED,MAAM,CAAC,SAAS,CAAC,MAAgB;QAC/B,MAAM,MAAM,GAAoB,EAAE,CAAA;QAClC,MAAM,SAAS,GAAG,MAAM,CAAC,SAAS,CAAA;QAElC,MAAM,QAAQ,GAAG,OAAO,CAAC,cAAc,CAAC,qBAAc,EAAE,MAAM,CAAC,CAAA;QAE/D,IAAI,CAAC,QAAQ,EAAE,CAAC;YACd,OAAO,CAAC,IAAI,CAAC,SAAS,MAAM,CAAC,IAAI,uCAAuC,CAAC,CAAA;YACzE,OAAO,EAAE,CAAA;QACX,CAAC;QAED,MAAM,WAAW,GAAG,IAAA,mCAAe,EAAC,MAAM,CAAC,CAAA;QAE3C,yCAAyC;QACzC,KAAK,MAAM,UAAU,IAAI,WAAW,EAAE,CAAC;YACrC,MAAM,aAAa,GAAG,8BAAY,CAAC,WAAW,CAAC,SAAS,EAAE,UAAU,CAAC,CAAA;YAErE,IAAI,aAAa,EAAE,CAAC;gBAClB,+CAA+C;gBAC/C,MAAM,GAAG,GAAG,IAAA,kBAAO,EAAC,QAAQ,CAAC,IAAI,EAAE,aAAa,CAAC,IAAI,CAAC,CAAA;gBAEtD,oCAAoC;gBACpC,MAAM,CAAC,IAAI,CAAC;oBACV,UAAU,EAAE,UAAU;oBACtB,MAAM,EAAE,aAAa,CAAC,MAAM;oBAC5B,IAAI,EAAE,GAAG;oBACT,UAAU,EAAE,aAAa,CAAC,UAAU;iBACrC,CAAC,CAAA;YACJ,CAAC;QACH,CAAC;QAED,OAAO,MAAM,CAAA;IACf,CAAC;CACF;AAtCD,8CAsCC;AAED;;;;GAIG;AACH,SAAgB,UAAU,CAAC,IAAY;IACrC,OAAO,IAAA,kCAAe,EAAC,IAAA,sBAAU,GAAE,EAAE,UAAU,MAAgB;QAC7D,OAAO,CAAC,cAAc,CAAC,qBAAc,EAAE,EAAE,IAAI,EAAE,EAAE,MAAM,CAAC,CAAA;IAC1D,CAAC,CAAC,CAAA;AACJ,CAAC"}
|
|
@@ -2,15 +2,10 @@ export type ParamMetadata = {
|
|
|
2
2
|
name: string;
|
|
3
3
|
parameterIndex: number;
|
|
4
4
|
};
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
* @param propertyKey - The property key.
|
|
10
|
-
* @param args - The arguments.
|
|
11
|
-
* @returns The parameter and parameter index.
|
|
12
|
-
*/
|
|
13
|
-
export declare function paramDecoratorHandler(target: object, propertyKey: string | symbol, args: any[]): Promise<any>;
|
|
5
|
+
export declare class ParamHandler {
|
|
6
|
+
static getMetadata(target: object, propertyKey: string | symbol): ParamMetadata[] | undefined;
|
|
7
|
+
static handle(target: object, propertyKey: string | symbol, args: any[]): Promise<any>;
|
|
8
|
+
}
|
|
14
9
|
/**
|
|
15
10
|
* Decorator to validate the param of the request.
|
|
16
11
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"param-decorator.d.ts","sourceRoot":"","sources":["../../../src/controllers/decorators/param-decorator.ts"],"names":[],"mappings":"AAIA,MAAM,MAAM,aAAa,GAAG;IAC1B,IAAI,EAAE,MAAM,CAAA;IACZ,cAAc,EAAE,MAAM,CAAA;CACvB,CAAA;AAED
|
|
1
|
+
{"version":3,"file":"param-decorator.d.ts","sourceRoot":"","sources":["../../../src/controllers/decorators/param-decorator.ts"],"names":[],"mappings":"AAIA,MAAM,MAAM,aAAa,GAAG;IAC1B,IAAI,EAAE,MAAM,CAAA;IACZ,cAAc,EAAE,MAAM,CAAA;CACvB,CAAA;AAED,qBAAa,YAAY;IACvB,MAAM,CAAC,WAAW,CAChB,MAAM,EAAE,MAAM,EACd,WAAW,EAAE,MAAM,GAAG,MAAM,GAC3B,aAAa,EAAE,GAAG,SAAS;WAmBjB,MAAM,CACjB,MAAM,EAAE,MAAM,EACd,WAAW,EAAE,MAAM,GAAG,MAAM,EAC5B,IAAI,EAAE,GAAG,EAAE,GACV,OAAO,CAAC,GAAG,CAAC;CAmChB;AAED;;;;;GAKG;AACH,wBAAgB,KAAK,CAAC,IAAI,EAAE,MAAM,IAE9B,QAAQ,MAAM,EACd,aAAa,MAAM,GAAG,MAAM,EAC5B,gBAAgB,MAAM,UAYzB"}
|
|
@@ -1,42 +1,46 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.ParamHandler = void 0;
|
|
4
4
|
exports.Param = Param;
|
|
5
5
|
const keys_1 = require("../../constants/keys");
|
|
6
6
|
const api_exception_1 = require("../../exceptions/api-exception");
|
|
7
7
|
const get_next_arguments_1 = require("../../utils/nextjs/get-next-arguments");
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
* @returns The parameter and parameter index.
|
|
15
|
-
*/
|
|
16
|
-
async function paramDecoratorHandler(target, propertyKey, args) {
|
|
17
|
-
const metadatas = Reflect.getOwnMetadata(keys_1.PARAM_KEY, target, propertyKey);
|
|
18
|
-
// If the metadata is found, validate the param.
|
|
19
|
-
if (metadatas && metadatas.length > 0) {
|
|
20
|
-
const params = await (0, get_next_arguments_1.getNextParamArgument)(args);
|
|
21
|
-
// If params is undefined or null, all required params are missing
|
|
22
|
-
if (!params) {
|
|
23
|
-
throw new api_exception_1.ValidationApiException(`Invalid param: ${metadatas[0].name} is required`);
|
|
8
|
+
class ParamHandler {
|
|
9
|
+
static getMetadata(target, propertyKey) {
|
|
10
|
+
let metadatas = Reflect.getOwnMetadata(keys_1.PARAM_KEY, target, propertyKey);
|
|
11
|
+
// If not found on instance, try constructor prototype
|
|
12
|
+
if (!metadatas && target.constructor) {
|
|
13
|
+
metadatas = Reflect.getOwnMetadata(keys_1.PARAM_KEY, target.constructor.prototype, propertyKey);
|
|
24
14
|
}
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
15
|
+
return metadatas;
|
|
16
|
+
}
|
|
17
|
+
static async handle(target, propertyKey, args) {
|
|
18
|
+
const metadatas = this.getMetadata(target, propertyKey);
|
|
19
|
+
// If the metadata is found, validate the param.
|
|
20
|
+
if (metadatas && metadatas.length > 0) {
|
|
21
|
+
const params = await (0, get_next_arguments_1.getNextParamArgument)(args);
|
|
22
|
+
// If params is undefined or null, all required params are missing
|
|
23
|
+
if (!params) {
|
|
24
|
+
throw new api_exception_1.ValidationApiException(`Invalid param: ${metadatas[0].name} is required`);
|
|
31
25
|
}
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
26
|
+
// Validate the param.
|
|
27
|
+
return metadatas.map((metadata) => {
|
|
28
|
+
const value = params[metadata.name];
|
|
29
|
+
// If the param is not found, throw a validation error.
|
|
30
|
+
if (!value) {
|
|
31
|
+
throw new api_exception_1.ValidationApiException(`Invalid param: ${metadata.name} is required`);
|
|
32
|
+
}
|
|
33
|
+
return {
|
|
34
|
+
type: 'param',
|
|
35
|
+
parameter: value,
|
|
36
|
+
parameterIndex: metadata.parameterIndex
|
|
37
|
+
};
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
return null;
|
|
37
41
|
}
|
|
38
|
-
return null;
|
|
39
42
|
}
|
|
43
|
+
exports.ParamHandler = ParamHandler;
|
|
40
44
|
/**
|
|
41
45
|
* Decorator to validate the param of the request.
|
|
42
46
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"param-decorator.js","sourceRoot":"","sources":["../../../src/controllers/decorators/param-decorator.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"param-decorator.js","sourceRoot":"","sources":["../../../src/controllers/decorators/param-decorator.ts"],"names":[],"mappings":";;;AA+EA,sBAgBC;AA/FD,2CAA4C;AAC5C,8DAAmE;AACnE,0EAAwE;AAOxE,MAAa,YAAY;IACvB,MAAM,CAAC,WAAW,CAChB,MAAc,EACd,WAA4B;QAE5B,IAAI,SAAS,GAAgC,OAAO,CAAC,cAAc,CACjE,gBAAS,EACT,MAAM,EACN,WAAW,CACZ,CAAA;QAED,sDAAsD;QACtD,IAAI,CAAC,SAAS,IAAI,MAAM,CAAC,WAAW,EAAE,CAAC;YACrC,SAAS,GAAG,OAAO,CAAC,cAAc,CAChC,gBAAS,EACT,MAAM,CAAC,WAAW,CAAC,SAAS,EAC5B,WAAW,CACZ,CAAA;QACH,CAAC;QAED,OAAO,SAAS,CAAA;IAClB,CAAC;IAED,MAAM,CAAC,KAAK,CAAC,MAAM,CACjB,MAAc,EACd,WAA4B,EAC5B,IAAW;QAEX,MAAM,SAAS,GAAG,IAAI,CAAC,WAAW,CAAC,MAAM,EAAE,WAAW,CAAC,CAAA;QAEvD,gDAAgD;QAChD,IAAI,SAAS,IAAI,SAAS,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YACtC,MAAM,MAAM,GAA2B,MAAM,IAAA,yCAAoB,EAAC,IAAI,CAAC,CAAA;YAEvE,kEAAkE;YAClE,IAAI,CAAC,MAAM,EAAE,CAAC;gBACZ,MAAM,IAAI,sCAAsB,CAC9B,kBAAkB,SAAS,CAAC,CAAC,CAAC,CAAC,IAAI,cAAc,CAClD,CAAA;YACH,CAAC;YAED,sBAAsB;YACtB,OAAO,SAAS,CAAC,GAAG,CAAC,CAAC,QAAQ,EAAE,EAAE;gBAChC,MAAM,KAAK,GAAG,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAA;gBAEnC,uDAAuD;gBACvD,IAAI,CAAC,KAAK,EAAE,CAAC;oBACX,MAAM,IAAI,sCAAsB,CAC9B,kBAAkB,QAAQ,CAAC,IAAI,cAAc,CAC9C,CAAA;gBACH,CAAC;gBAED,OAAO;oBACL,IAAI,EAAE,OAAO;oBACb,SAAS,EAAE,KAAK;oBAChB,cAAc,EAAE,QAAQ,CAAC,cAAc;iBACxC,CAAA;YACH,CAAC,CAAC,CAAA;QACJ,CAAC;QAED,OAAO,IAAI,CAAA;IACb,CAAC;CACF;AA9DD,oCA8DC;AAED;;;;;GAKG;AACH,SAAgB,KAAK,CAAC,IAAY;IAChC,OAAO,UACL,MAAc,EACd,WAA4B,EAC5B,cAAsB;QAEtB,MAAM,cAAc,GAClB,OAAO,CAAC,cAAc,CAAC,gBAAS,EAAE,MAAM,EAAE,WAAW,CAAC,IAAI,EAAE,CAAA;QAE9D,cAAc,CAAC,IAAI,CAAC;YAClB,IAAI;YACJ,cAAc;SACf,CAAC,CAAA;QAEF,OAAO,CAAC,cAAc,CAAC,gBAAS,EAAE,cAAc,EAAE,MAAM,EAAE,WAAW,CAAC,CAAA;IACxE,CAAC,CAAA;AACH,CAAC"}
|