@riktajs/core 0.1.0 → 0.2.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 +96 -161
- package/dist/core/constants.d.ts +4 -0
- package/dist/core/constants.d.ts.map +1 -1
- package/dist/core/constants.js +5 -1
- package/dist/core/constants.js.map +1 -1
- package/dist/core/decorators/controller.decorator.d.ts.map +1 -1
- package/dist/core/decorators/controller.decorator.js +1 -0
- package/dist/core/decorators/controller.decorator.js.map +1 -1
- package/dist/core/decorators/param.decorator.d.ts +111 -11
- package/dist/core/decorators/param.decorator.d.ts.map +1 -1
- package/dist/core/decorators/param.decorator.js +87 -8
- package/dist/core/decorators/param.decorator.js.map +1 -1
- package/dist/core/exceptions/index.d.ts +1 -0
- package/dist/core/exceptions/index.d.ts.map +1 -1
- package/dist/core/exceptions/index.js +4 -1
- package/dist/core/exceptions/index.js.map +1 -1
- package/dist/core/exceptions/validation.exception.d.ts +60 -0
- package/dist/core/exceptions/validation.exception.d.ts.map +1 -0
- package/dist/core/exceptions/validation.exception.js +71 -0
- package/dist/core/exceptions/validation.exception.js.map +1 -0
- package/dist/core/guards/can-activate.interface.d.ts +77 -0
- package/dist/core/guards/can-activate.interface.d.ts.map +1 -0
- package/dist/core/guards/can-activate.interface.js +3 -0
- package/dist/core/guards/can-activate.interface.js.map +1 -0
- package/dist/core/guards/execution-context.d.ts +72 -0
- package/dist/core/guards/execution-context.d.ts.map +1 -0
- package/dist/core/guards/execution-context.js +37 -0
- package/dist/core/guards/execution-context.js.map +1 -0
- package/dist/core/guards/index.d.ts +4 -0
- package/dist/core/guards/index.d.ts.map +1 -0
- package/dist/core/guards/index.js +10 -0
- package/dist/core/guards/index.js.map +1 -0
- package/dist/core/guards/use-guards.decorator.d.ts +82 -0
- package/dist/core/guards/use-guards.decorator.d.ts.map +1 -0
- package/dist/core/guards/use-guards.decorator.js +104 -0
- package/dist/core/guards/use-guards.decorator.js.map +1 -0
- package/dist/core/index.d.ts +3 -0
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/index.js +7 -0
- package/dist/core/index.js.map +1 -1
- package/dist/core/router/router.d.ts +9 -1
- package/dist/core/router/router.d.ts.map +1 -1
- package/dist/core/router/router.js +68 -5
- package/dist/core/router/router.js.map +1 -1
- package/package.json +3 -2
|
@@ -4,69 +4,148 @@ exports.Context = exports.Ctx = exports.Reply = exports.Res = exports.Request =
|
|
|
4
4
|
require("reflect-metadata");
|
|
5
5
|
const constants_1 = require("../constants");
|
|
6
6
|
/**
|
|
7
|
-
*
|
|
7
|
+
* Type guard to check if a value is a Zod schema
|
|
8
|
+
* Uses duck typing to detect Zod schemas without importing the full library
|
|
9
|
+
*/
|
|
10
|
+
function isZodType(value) {
|
|
11
|
+
return (value !== null &&
|
|
12
|
+
typeof value === 'object' &&
|
|
13
|
+
'_def' in value &&
|
|
14
|
+
'safeParse' in value &&
|
|
15
|
+
typeof value.safeParse === 'function');
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Creates a type-safe parameter decorator factory with Zod schema support
|
|
19
|
+
*
|
|
20
|
+
* Supports three overloads:
|
|
21
|
+
* 1. @Decorator() - Inject the full value
|
|
22
|
+
* 2. @Decorator('key') - Inject a specific property by key
|
|
23
|
+
* 3. @Decorator(zodSchema) - Inject with validation and type inference
|
|
8
24
|
*/
|
|
9
25
|
function createParamDecorator(type) {
|
|
10
|
-
|
|
26
|
+
function decorator(keyOrSchema) {
|
|
11
27
|
return (target, propertyKey, parameterIndex) => {
|
|
12
28
|
if (propertyKey === undefined)
|
|
13
29
|
return;
|
|
14
30
|
// Get existing params or initialize empty array
|
|
15
31
|
const existingParams = Reflect.getMetadata(constants_1.PARAM_METADATA, target.constructor, propertyKey) ?? [];
|
|
16
|
-
//
|
|
17
|
-
|
|
32
|
+
// Determine if we have a key string or a Zod schema
|
|
33
|
+
const isSchema = isZodType(keyOrSchema);
|
|
34
|
+
// Build metadata object
|
|
35
|
+
const metadata = {
|
|
18
36
|
index: parameterIndex,
|
|
19
37
|
type,
|
|
20
|
-
key,
|
|
21
|
-
|
|
38
|
+
key: isSchema ? undefined : keyOrSchema,
|
|
39
|
+
zodSchema: isSchema ? keyOrSchema : undefined,
|
|
40
|
+
};
|
|
41
|
+
// Add this param
|
|
42
|
+
existingParams.push(metadata);
|
|
22
43
|
// Store updated params
|
|
23
44
|
Reflect.defineMetadata(constants_1.PARAM_METADATA, existingParams, target.constructor, propertyKey);
|
|
24
45
|
};
|
|
25
|
-
}
|
|
46
|
+
}
|
|
47
|
+
return decorator;
|
|
26
48
|
}
|
|
27
49
|
/**
|
|
28
50
|
* @Body() decorator - Injects the request body
|
|
29
51
|
*
|
|
52
|
+
* Supports three modes:
|
|
53
|
+
* 1. `@Body()` - Inject the entire request body
|
|
54
|
+
* 2. `@Body('propertyName')` - Inject a specific property from the body
|
|
55
|
+
* 3. `@Body(zodSchema)` - Validate and inject with type inference
|
|
56
|
+
*
|
|
30
57
|
* @example
|
|
31
58
|
* ```typescript
|
|
59
|
+
* // Inject entire body (untyped)
|
|
32
60
|
* @Post('/users')
|
|
33
|
-
* createUser(@Body(
|
|
61
|
+
* createUser(@Body() data: unknown) { return data; }
|
|
34
62
|
*
|
|
63
|
+
* // Inject specific property
|
|
35
64
|
* @Post('/users')
|
|
36
65
|
* createUser(@Body('name') name: string) { return { name }; }
|
|
66
|
+
*
|
|
67
|
+
* // Validate with Zod schema (type-safe!)
|
|
68
|
+
* const CreateUserSchema = z.object({ name: z.string(), email: z.string().email() });
|
|
69
|
+
* @Post('/users')
|
|
70
|
+
* createUser(@Body(CreateUserSchema) data: z.infer<typeof CreateUserSchema>) {
|
|
71
|
+
* // data is fully typed as { name: string; email: string }
|
|
72
|
+
* return data;
|
|
73
|
+
* }
|
|
37
74
|
* ```
|
|
38
75
|
*/
|
|
39
76
|
exports.Body = createParamDecorator(constants_1.ParamType.BODY);
|
|
40
77
|
/**
|
|
41
78
|
* @Query() decorator - Injects query parameters
|
|
42
79
|
*
|
|
80
|
+
* Supports three modes:
|
|
81
|
+
* 1. `@Query()` - Inject all query parameters
|
|
82
|
+
* 2. `@Query('paramName')` - Inject a specific query parameter
|
|
83
|
+
* 3. `@Query(zodSchema)` - Validate and inject with type inference
|
|
84
|
+
*
|
|
43
85
|
* @example
|
|
44
86
|
* ```typescript
|
|
87
|
+
* // Inject specific query param
|
|
45
88
|
* @Get('/users')
|
|
46
89
|
* getUsers(@Query('page') page: string) { return { page }; }
|
|
47
90
|
*
|
|
91
|
+
* // Inject all query params
|
|
48
92
|
* @Get('/users')
|
|
49
93
|
* getUsers(@Query() query: Record<string, unknown>) { return query; }
|
|
94
|
+
*
|
|
95
|
+
* // Validate with Zod schema
|
|
96
|
+
* const PaginationSchema = z.object({ page: z.coerce.number(), limit: z.coerce.number() });
|
|
97
|
+
* @Get('/users')
|
|
98
|
+
* getUsers(@Query(PaginationSchema) query: z.infer<typeof PaginationSchema>) {
|
|
99
|
+
* // query is { page: number; limit: number }
|
|
100
|
+
* return query;
|
|
101
|
+
* }
|
|
50
102
|
* ```
|
|
51
103
|
*/
|
|
52
104
|
exports.Query = createParamDecorator(constants_1.ParamType.QUERY);
|
|
53
105
|
/**
|
|
54
106
|
* @Param() decorator - Injects route parameters
|
|
55
107
|
*
|
|
108
|
+
* Supports three modes:
|
|
109
|
+
* 1. `@Param()` - Inject all route parameters
|
|
110
|
+
* 2. `@Param('paramName')` - Inject a specific route parameter
|
|
111
|
+
* 3. `@Param(zodSchema)` - Validate and inject with type inference
|
|
112
|
+
*
|
|
56
113
|
* @example
|
|
57
114
|
* ```typescript
|
|
115
|
+
* // Inject specific param
|
|
58
116
|
* @Get('/users/:id')
|
|
59
117
|
* getUser(@Param('id') id: string) { return { id }; }
|
|
118
|
+
*
|
|
119
|
+
* // Validate with Zod schema
|
|
120
|
+
* const IdSchema = z.object({ id: z.string().uuid() });
|
|
121
|
+
* @Get('/users/:id')
|
|
122
|
+
* getUser(@Param(IdSchema) params: z.infer<typeof IdSchema>) {
|
|
123
|
+
* // params.id is validated as UUID
|
|
124
|
+
* return params;
|
|
125
|
+
* }
|
|
60
126
|
* ```
|
|
61
127
|
*/
|
|
62
128
|
exports.Param = createParamDecorator(constants_1.ParamType.PARAM);
|
|
63
129
|
/**
|
|
64
130
|
* @Headers() decorator - Injects request headers
|
|
65
131
|
*
|
|
132
|
+
* Supports three modes:
|
|
133
|
+
* 1. `@Headers()` - Inject all headers
|
|
134
|
+
* 2. `@Headers('headerName')` - Inject a specific header
|
|
135
|
+
* 3. `@Headers(zodSchema)` - Validate and inject with type inference
|
|
136
|
+
*
|
|
66
137
|
* @example
|
|
67
138
|
* ```typescript
|
|
139
|
+
* // Inject specific header
|
|
68
140
|
* @Get('/protected')
|
|
69
141
|
* getData(@Headers('authorization') auth: string) { return { auth }; }
|
|
142
|
+
*
|
|
143
|
+
* // Validate with Zod schema
|
|
144
|
+
* const AuthHeadersSchema = z.object({ authorization: z.string().startsWith('Bearer ') });
|
|
145
|
+
* @Get('/protected')
|
|
146
|
+
* getData(@Headers(AuthHeadersSchema) headers: z.infer<typeof AuthHeadersSchema>) {
|
|
147
|
+
* return headers;
|
|
148
|
+
* }
|
|
70
149
|
* ```
|
|
71
150
|
*/
|
|
72
151
|
exports.Headers = createParamDecorator(constants_1.ParamType.HEADERS);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"param.decorator.js","sourceRoot":"","sources":["../../../src/core/decorators/param.decorator.ts"],"names":[],"mappings":";;;AAAA,4BAA0B;
|
|
1
|
+
{"version":3,"file":"param.decorator.js","sourceRoot":"","sources":["../../../src/core/decorators/param.decorator.ts"],"names":[],"mappings":";;;AAAA,4BAA0B;AAE1B,4CAAyD;AAazD;;;GAGG;AACH,SAAS,SAAS,CAAC,KAAc;IAC/B,OAAO,CACL,KAAK,KAAK,IAAI;QACd,OAAO,KAAK,KAAK,QAAQ;QACzB,MAAM,IAAI,KAAK;QACf,WAAW,IAAI,KAAK;QACpB,OAAQ,KAAgC,CAAC,SAAS,KAAK,UAAU,CAClE,CAAC;AACJ,CAAC;AAED;;;;;;;GAOG;AACH,SAAS,oBAAoB,CAAC,IAAe;IAK3C,SAAS,SAAS,CAAI,WAAiC;QACrD,OAAO,CAAC,MAAc,EAAE,WAAwC,EAAE,cAAsB,EAAE,EAAE;YAC1F,IAAI,WAAW,KAAK,SAAS;gBAAE,OAAO;YAEtC,gDAAgD;YAChD,MAAM,cAAc,GAClB,OAAO,CAAC,WAAW,CAAC,0BAAc,EAAE,MAAM,CAAC,WAAW,EAAE,WAAW,CAAC,IAAI,EAAE,CAAC;YAE7E,oDAAoD;YACpD,MAAM,QAAQ,GAAG,SAAS,CAAC,WAAW,CAAC,CAAC;YAExC,wBAAwB;YACxB,MAAM,QAAQ,GAAkB;gBAC9B,KAAK,EAAE,cAAc;gBACrB,IAAI;gBACJ,GAAG,EAAE,QAAQ,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,WAAW;gBACvC,SAAS,EAAE,QAAQ,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,SAAS;aAC9C,CAAC;YAEF,iBAAiB;YACjB,cAAc,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;YAE9B,uBAAuB;YACvB,OAAO,CAAC,cAAc,CAAC,0BAAc,EAAE,cAAc,EAAE,MAAM,CAAC,WAAW,EAAE,WAAW,CAAC,CAAC;QAC1F,CAAC,CAAC;IACJ,CAAC;IAED,OAAO,SAAS,CAAC;AACnB,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACU,QAAA,IAAI,GAAG,oBAAoB,CAAC,qBAAS,CAAC,IAAI,CAAC,CAAC;AAEzD;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACU,QAAA,KAAK,GAAG,oBAAoB,CAAC,qBAAS,CAAC,KAAK,CAAC,CAAC;AAE3D;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACU,QAAA,KAAK,GAAG,oBAAoB,CAAC,qBAAS,CAAC,KAAK,CAAC,CAAC;AAE3D;;;;;;;;;;;;;;;;;;;;;GAqBG;AACU,QAAA,OAAO,GAAG,oBAAoB,CAAC,qBAAS,CAAC,OAAO,CAAC,CAAC;AAE/D;;GAEG;AACU,QAAA,GAAG,GAAG,oBAAoB,CAAC,qBAAS,CAAC,OAAO,CAAC,CAAC;AAC9C,QAAA,OAAO,GAAG,WAAG,CAAC;AAE3B;;GAEG;AACU,QAAA,GAAG,GAAG,oBAAoB,CAAC,qBAAS,CAAC,KAAK,CAAC,CAAC;AAC5C,QAAA,KAAK,GAAG,WAAG,CAAC;AAEzB;;GAEG;AACU,QAAA,GAAG,GAAG,oBAAoB,CAAC,qBAAS,CAAC,OAAO,CAAC,CAAC;AAC9C,QAAA,OAAO,GAAG,WAAG,CAAC"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export { HttpException, HttpExceptionBody, HttpExceptionResponse } from './http-exception';
|
|
2
|
+
export { ValidationException, ValidationErrorDetails } from './validation.exception';
|
|
2
3
|
export { BadRequestException, UnauthorizedException, ForbiddenException, NotFoundException, MethodNotAllowedException, NotAcceptableException, RequestTimeoutException, ConflictException, GoneException, PayloadTooLargeException, UnsupportedMediaTypeException, UnprocessableEntityException, TooManyRequestsException, InternalServerErrorException, NotImplementedException, BadGatewayException, ServiceUnavailableException, GatewayTimeoutException, } from './exceptions';
|
|
3
4
|
export { ExceptionFilter, ExceptionContext, ErrorResponse, GlobalExceptionFilter, GlobalExceptionFilterOptions, createExceptionHandler, } from './exception-filter';
|
|
4
5
|
export { Catch, CatchMetadata, CATCH_METADATA, getCatchMetadata } from './catch.decorator';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/core/exceptions/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,iBAAiB,EAAE,qBAAqB,EAAE,MAAM,kBAAkB,CAAC;AAG3F,OAAO,EAEL,mBAAmB,EACnB,qBAAqB,EACrB,kBAAkB,EAClB,iBAAiB,EACjB,yBAAyB,EACzB,sBAAsB,EACtB,uBAAuB,EACvB,iBAAiB,EACjB,aAAa,EACb,wBAAwB,EACxB,6BAA6B,EAC7B,4BAA4B,EAC5B,wBAAwB,EAExB,4BAA4B,EAC5B,uBAAuB,EACvB,mBAAmB,EACnB,2BAA2B,EAC3B,uBAAuB,GACxB,MAAM,cAAc,CAAC;AAGtB,OAAO,EACL,eAAe,EACf,gBAAgB,EAChB,aAAa,EACb,qBAAqB,EACrB,4BAA4B,EAC5B,sBAAsB,GACvB,MAAM,oBAAoB,CAAC;AAG5B,OAAO,EAAE,KAAK,EAAE,aAAa,EAAE,cAAc,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/core/exceptions/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,iBAAiB,EAAE,qBAAqB,EAAE,MAAM,kBAAkB,CAAC;AAG3F,OAAO,EAAE,mBAAmB,EAAE,sBAAsB,EAAE,MAAM,wBAAwB,CAAC;AAGrF,OAAO,EAEL,mBAAmB,EACnB,qBAAqB,EACrB,kBAAkB,EAClB,iBAAiB,EACjB,yBAAyB,EACzB,sBAAsB,EACtB,uBAAuB,EACvB,iBAAiB,EACjB,aAAa,EACb,wBAAwB,EACxB,6BAA6B,EAC7B,4BAA4B,EAC5B,wBAAwB,EAExB,4BAA4B,EAC5B,uBAAuB,EACvB,mBAAmB,EACnB,2BAA2B,EAC3B,uBAAuB,GACxB,MAAM,cAAc,CAAC;AAGtB,OAAO,EACL,eAAe,EACf,gBAAgB,EAChB,aAAa,EACb,qBAAqB,EACrB,4BAA4B,EAC5B,sBAAsB,GACvB,MAAM,oBAAoB,CAAC;AAG5B,OAAO,EAAE,KAAK,EAAE,aAAa,EAAE,cAAc,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC"}
|
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getCatchMetadata = exports.CATCH_METADATA = exports.Catch = exports.createExceptionHandler = exports.GlobalExceptionFilter = exports.GatewayTimeoutException = exports.ServiceUnavailableException = exports.BadGatewayException = exports.NotImplementedException = exports.InternalServerErrorException = exports.TooManyRequestsException = exports.UnprocessableEntityException = exports.UnsupportedMediaTypeException = exports.PayloadTooLargeException = exports.GoneException = exports.ConflictException = exports.RequestTimeoutException = exports.NotAcceptableException = exports.MethodNotAllowedException = exports.NotFoundException = exports.ForbiddenException = exports.UnauthorizedException = exports.BadRequestException = exports.HttpException = void 0;
|
|
3
|
+
exports.getCatchMetadata = exports.CATCH_METADATA = exports.Catch = exports.createExceptionHandler = exports.GlobalExceptionFilter = exports.GatewayTimeoutException = exports.ServiceUnavailableException = exports.BadGatewayException = exports.NotImplementedException = exports.InternalServerErrorException = exports.TooManyRequestsException = exports.UnprocessableEntityException = exports.UnsupportedMediaTypeException = exports.PayloadTooLargeException = exports.GoneException = exports.ConflictException = exports.RequestTimeoutException = exports.NotAcceptableException = exports.MethodNotAllowedException = exports.NotFoundException = exports.ForbiddenException = exports.UnauthorizedException = exports.BadRequestException = exports.ValidationException = exports.HttpException = void 0;
|
|
4
4
|
// HTTP Exception
|
|
5
5
|
var http_exception_1 = require("./http-exception");
|
|
6
6
|
Object.defineProperty(exports, "HttpException", { enumerable: true, get: function () { return http_exception_1.HttpException; } });
|
|
7
|
+
// Validation Exception (Zod)
|
|
8
|
+
var validation_exception_1 = require("./validation.exception");
|
|
9
|
+
Object.defineProperty(exports, "ValidationException", { enumerable: true, get: function () { return validation_exception_1.ValidationException; } });
|
|
7
10
|
// Specific Exceptions
|
|
8
11
|
var exceptions_1 = require("./exceptions");
|
|
9
12
|
// 4xx Client Errors
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/core/exceptions/index.ts"],"names":[],"mappings":";;;AAAA,iBAAiB;AACjB,mDAA2F;AAAlF,+GAAA,aAAa,OAAA;AAEtB,sBAAsB;AACtB,2CAqBsB;AApBpB,oBAAoB;AACpB,iHAAA,mBAAmB,OAAA;AACnB,mHAAA,qBAAqB,OAAA;AACrB,gHAAA,kBAAkB,OAAA;AAClB,+GAAA,iBAAiB,OAAA;AACjB,uHAAA,yBAAyB,OAAA;AACzB,oHAAA,sBAAsB,OAAA;AACtB,qHAAA,uBAAuB,OAAA;AACvB,+GAAA,iBAAiB,OAAA;AACjB,2GAAA,aAAa,OAAA;AACb,sHAAA,wBAAwB,OAAA;AACxB,2HAAA,6BAA6B,OAAA;AAC7B,0HAAA,4BAA4B,OAAA;AAC5B,sHAAA,wBAAwB,OAAA;AACxB,oBAAoB;AACpB,0HAAA,4BAA4B,OAAA;AAC5B,qHAAA,uBAAuB,OAAA;AACvB,iHAAA,mBAAmB,OAAA;AACnB,yHAAA,2BAA2B,OAAA;AAC3B,qHAAA,uBAAuB,OAAA;AAGzB,mBAAmB;AACnB,uDAO4B;AAH1B,yHAAA,qBAAqB,OAAA;AAErB,0HAAA,sBAAsB,OAAA;AAGxB,kBAAkB;AAClB,qDAA2F;AAAlF,wGAAA,KAAK,OAAA;AAAiB,iHAAA,cAAc,OAAA;AAAE,mHAAA,gBAAgB,OAAA"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/core/exceptions/index.ts"],"names":[],"mappings":";;;AAAA,iBAAiB;AACjB,mDAA2F;AAAlF,+GAAA,aAAa,OAAA;AAEtB,6BAA6B;AAC7B,+DAAqF;AAA5E,2HAAA,mBAAmB,OAAA;AAE5B,sBAAsB;AACtB,2CAqBsB;AApBpB,oBAAoB;AACpB,iHAAA,mBAAmB,OAAA;AACnB,mHAAA,qBAAqB,OAAA;AACrB,gHAAA,kBAAkB,OAAA;AAClB,+GAAA,iBAAiB,OAAA;AACjB,uHAAA,yBAAyB,OAAA;AACzB,oHAAA,sBAAsB,OAAA;AACtB,qHAAA,uBAAuB,OAAA;AACvB,+GAAA,iBAAiB,OAAA;AACjB,2GAAA,aAAa,OAAA;AACb,sHAAA,wBAAwB,OAAA;AACxB,2HAAA,6BAA6B,OAAA;AAC7B,0HAAA,4BAA4B,OAAA;AAC5B,sHAAA,wBAAwB,OAAA;AACxB,oBAAoB;AACpB,0HAAA,4BAA4B,OAAA;AAC5B,qHAAA,uBAAuB,OAAA;AACvB,iHAAA,mBAAmB,OAAA;AACnB,yHAAA,2BAA2B,OAAA;AAC3B,qHAAA,uBAAuB,OAAA;AAGzB,mBAAmB;AACnB,uDAO4B;AAH1B,yHAAA,qBAAqB,OAAA;AAErB,0HAAA,sBAAsB,OAAA;AAGxB,kBAAkB;AAClB,qDAA2F;AAAlF,wGAAA,KAAK,OAAA;AAAiB,iHAAA,cAAc,OAAA;AAAE,mHAAA,gBAAgB,OAAA"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import type { ZodError } from 'zod';
|
|
2
|
+
import { HttpException } from './http-exception';
|
|
3
|
+
/**
|
|
4
|
+
* Structured validation error details
|
|
5
|
+
*/
|
|
6
|
+
export interface ValidationErrorDetails {
|
|
7
|
+
/** The field path where the error occurred */
|
|
8
|
+
path: (string | number)[];
|
|
9
|
+
/** Human-readable error message */
|
|
10
|
+
message: string;
|
|
11
|
+
/** Zod error code */
|
|
12
|
+
code: string;
|
|
13
|
+
/** Expected type/value (if applicable) */
|
|
14
|
+
expected?: string;
|
|
15
|
+
/** Received type/value (if applicable) */
|
|
16
|
+
received?: string;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Validation Exception
|
|
20
|
+
*
|
|
21
|
+
* Thrown when request validation fails using Zod schemas.
|
|
22
|
+
* Provides detailed error information for each validation issue.
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* ```typescript
|
|
26
|
+
* // The framework throws this automatically when @Body(schema) validation fails
|
|
27
|
+
* // But you can also throw it manually:
|
|
28
|
+
*
|
|
29
|
+
* const result = MySchema.safeParse(data);
|
|
30
|
+
* if (!result.success) {
|
|
31
|
+
* throw new ValidationException(result.error);
|
|
32
|
+
* }
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
35
|
+
export declare class ValidationException extends HttpException {
|
|
36
|
+
/**
|
|
37
|
+
* The original Zod error object
|
|
38
|
+
*/
|
|
39
|
+
readonly zodError: ZodError;
|
|
40
|
+
/**
|
|
41
|
+
* Structured validation error details
|
|
42
|
+
*/
|
|
43
|
+
readonly errors: ValidationErrorDetails[];
|
|
44
|
+
constructor(zodError: ZodError, message?: string);
|
|
45
|
+
/**
|
|
46
|
+
* Get formatted errors for client response
|
|
47
|
+
*/
|
|
48
|
+
getValidationErrors(): ValidationErrorDetails[];
|
|
49
|
+
/**
|
|
50
|
+
* Get the flattened Zod error format
|
|
51
|
+
*/
|
|
52
|
+
getFlattenedErrors(): import("zod").typeToFlattenedError<any, string>;
|
|
53
|
+
/**
|
|
54
|
+
* Get the formatted Zod error
|
|
55
|
+
*/
|
|
56
|
+
getFormattedErrors(): {
|
|
57
|
+
_errors: string[];
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
//# sourceMappingURL=validation.exception.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validation.exception.d.ts","sourceRoot":"","sources":["../../../src/core/exceptions/validation.exception.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAY,MAAM,KAAK,CAAC;AAC9C,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAEjD;;GAEG;AACH,MAAM,WAAW,sBAAsB;IACrC,8CAA8C;IAC9C,IAAI,EAAE,CAAC,MAAM,GAAG,MAAM,CAAC,EAAE,CAAC;IAC1B,mCAAmC;IACnC,OAAO,EAAE,MAAM,CAAC;IAChB,qBAAqB;IACrB,IAAI,EAAE,MAAM,CAAC;IACb,0CAA0C;IAC1C,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,0CAA0C;IAC1C,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,qBAAa,mBAAoB,SAAQ,aAAa;IACpD;;OAEG;IACH,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAC;IAE5B;;OAEG;IACH,QAAQ,CAAC,MAAM,EAAE,sBAAsB,EAAE,CAAC;gBAE9B,QAAQ,EAAE,QAAQ,EAAE,OAAO,GAAE,MAA4B;IA0BrE;;OAEG;IACH,mBAAmB,IAAI,sBAAsB,EAAE;IAI/C;;OAEG;IACH,kBAAkB;IAIlB;;OAEG;IACH,kBAAkB;;;CAGnB"}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ValidationException = void 0;
|
|
4
|
+
const http_exception_1 = require("./http-exception");
|
|
5
|
+
/**
|
|
6
|
+
* Validation Exception
|
|
7
|
+
*
|
|
8
|
+
* Thrown when request validation fails using Zod schemas.
|
|
9
|
+
* Provides detailed error information for each validation issue.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```typescript
|
|
13
|
+
* // The framework throws this automatically when @Body(schema) validation fails
|
|
14
|
+
* // But you can also throw it manually:
|
|
15
|
+
*
|
|
16
|
+
* const result = MySchema.safeParse(data);
|
|
17
|
+
* if (!result.success) {
|
|
18
|
+
* throw new ValidationException(result.error);
|
|
19
|
+
* }
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
class ValidationException extends http_exception_1.HttpException {
|
|
23
|
+
/**
|
|
24
|
+
* The original Zod error object
|
|
25
|
+
*/
|
|
26
|
+
zodError;
|
|
27
|
+
/**
|
|
28
|
+
* Structured validation error details
|
|
29
|
+
*/
|
|
30
|
+
errors;
|
|
31
|
+
constructor(zodError, message = 'Validation failed') {
|
|
32
|
+
// Transform Zod issues to structured format
|
|
33
|
+
const errors = zodError.issues.map((issue) => ({
|
|
34
|
+
path: issue.path,
|
|
35
|
+
message: issue.message,
|
|
36
|
+
code: issue.code,
|
|
37
|
+
...(('expected' in issue) ? { expected: String(issue.expected) } : {}),
|
|
38
|
+
...(('received' in issue) ? { received: String(issue.received) } : {}),
|
|
39
|
+
}));
|
|
40
|
+
super({
|
|
41
|
+
message,
|
|
42
|
+
error: 'Validation Error',
|
|
43
|
+
details: {
|
|
44
|
+
errors,
|
|
45
|
+
errorCount: errors.length,
|
|
46
|
+
},
|
|
47
|
+
}, 400);
|
|
48
|
+
this.zodError = zodError;
|
|
49
|
+
this.errors = errors;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Get formatted errors for client response
|
|
53
|
+
*/
|
|
54
|
+
getValidationErrors() {
|
|
55
|
+
return this.errors;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Get the flattened Zod error format
|
|
59
|
+
*/
|
|
60
|
+
getFlattenedErrors() {
|
|
61
|
+
return this.zodError.flatten();
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Get the formatted Zod error
|
|
65
|
+
*/
|
|
66
|
+
getFormattedErrors() {
|
|
67
|
+
return this.zodError.format();
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
exports.ValidationException = ValidationException;
|
|
71
|
+
//# sourceMappingURL=validation.exception.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validation.exception.js","sourceRoot":"","sources":["../../../src/core/exceptions/validation.exception.ts"],"names":[],"mappings":";;;AACA,qDAAiD;AAkBjD;;;;;;;;;;;;;;;;GAgBG;AACH,MAAa,mBAAoB,SAAQ,8BAAa;IACpD;;OAEG;IACM,QAAQ,CAAW;IAE5B;;OAEG;IACM,MAAM,CAA2B;IAE1C,YAAY,QAAkB,EAAE,UAAkB,mBAAmB;QACnE,4CAA4C;QAC5C,MAAM,MAAM,GAAG,QAAQ,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,KAAe,EAA0B,EAAE,CAAC,CAAC;YAC/E,IAAI,EAAE,KAAK,CAAC,IAAI;YAChB,OAAO,EAAE,KAAK,CAAC,OAAO;YACtB,IAAI,EAAE,KAAK,CAAC,IAAI;YAChB,GAAG,CAAC,CAAC,UAAU,IAAI,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,QAAQ,EAAE,MAAM,CAAC,KAAK,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;YACtE,GAAG,CAAC,CAAC,UAAU,IAAI,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,QAAQ,EAAE,MAAM,CAAC,KAAK,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;SACvE,CAAC,CAAC,CAAC;QAEJ,KAAK,CACH;YACE,OAAO;YACP,KAAK,EAAE,kBAAkB;YACzB,OAAO,EAAE;gBACP,MAAM;gBACN,UAAU,EAAE,MAAM,CAAC,MAAM;aAC1B;SACF,EACD,GAAG,CACJ,CAAC;QAEF,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACzB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACvB,CAAC;IAED;;OAEG;IACH,mBAAmB;QACjB,OAAO,IAAI,CAAC,MAAM,CAAC;IACrB,CAAC;IAED;;OAEG;IACH,kBAAkB;QAChB,OAAO,IAAI,CAAC,QAAQ,CAAC,OAAO,EAAE,CAAC;IACjC,CAAC;IAED;;OAEG;IACH,kBAAkB;QAChB,OAAO,IAAI,CAAC,QAAQ,CAAC,MAAM,EAAE,CAAC;IAChC,CAAC;CACF;AAzDD,kDAyDC"}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import type { ExecutionContext } from './execution-context';
|
|
2
|
+
/**
|
|
3
|
+
* CanActivate Interface
|
|
4
|
+
*
|
|
5
|
+
* Guards implementing this interface determine whether a given
|
|
6
|
+
* request is allowed to be handled by the route handler.
|
|
7
|
+
*
|
|
8
|
+
* Guards are executed BEFORE the route handler. If any guard
|
|
9
|
+
* returns `false`, the request is rejected with a 403 Forbidden.
|
|
10
|
+
*
|
|
11
|
+
* @example Basic authentication guard
|
|
12
|
+
* ```typescript
|
|
13
|
+
* import { Injectable } from '@riktajs/core';
|
|
14
|
+
* import type { CanActivate, ExecutionContext } from '@riktajs/core';
|
|
15
|
+
*
|
|
16
|
+
* @Injectable()
|
|
17
|
+
* export class AuthGuard implements CanActivate {
|
|
18
|
+
* canActivate(context: ExecutionContext): boolean {
|
|
19
|
+
* const request = context.getRequest();
|
|
20
|
+
* return !!request.headers.authorization;
|
|
21
|
+
* }
|
|
22
|
+
* }
|
|
23
|
+
* ```
|
|
24
|
+
*
|
|
25
|
+
* @example Async guard with service injection
|
|
26
|
+
* ```typescript
|
|
27
|
+
* @Injectable()
|
|
28
|
+
* export class JwtGuard implements CanActivate {
|
|
29
|
+
* constructor(private authService: AuthService) {}
|
|
30
|
+
*
|
|
31
|
+
* async canActivate(context: ExecutionContext): Promise<boolean> {
|
|
32
|
+
* const request = context.getRequest();
|
|
33
|
+
* const token = request.headers.authorization?.replace('Bearer ', '');
|
|
34
|
+
*
|
|
35
|
+
* if (!token) return false;
|
|
36
|
+
*
|
|
37
|
+
* try {
|
|
38
|
+
* const user = await this.authService.verifyToken(token);
|
|
39
|
+
* request.user = user;
|
|
40
|
+
* return true;
|
|
41
|
+
* } catch {
|
|
42
|
+
* return false;
|
|
43
|
+
* }
|
|
44
|
+
* }
|
|
45
|
+
* }
|
|
46
|
+
* ```
|
|
47
|
+
*
|
|
48
|
+
* @example Role-based guard
|
|
49
|
+
* ```typescript
|
|
50
|
+
* @Injectable()
|
|
51
|
+
* export class RolesGuard implements CanActivate {
|
|
52
|
+
* canActivate(context: ExecutionContext): boolean {
|
|
53
|
+
* const request = context.getRequest();
|
|
54
|
+
* const user = request.user;
|
|
55
|
+
* const requiredRoles = context.getMetadata<string[]>('roles');
|
|
56
|
+
*
|
|
57
|
+
* if (!requiredRoles || requiredRoles.length === 0) {
|
|
58
|
+
* return true;
|
|
59
|
+
* }
|
|
60
|
+
*
|
|
61
|
+
* return requiredRoles.some(role => user?.roles?.includes(role));
|
|
62
|
+
* }
|
|
63
|
+
* }
|
|
64
|
+
* ```
|
|
65
|
+
*/
|
|
66
|
+
export interface CanActivate {
|
|
67
|
+
/**
|
|
68
|
+
* Determines whether the request can proceed to the handler.
|
|
69
|
+
*
|
|
70
|
+
* @param context - The execution context containing request/reply
|
|
71
|
+
* @returns `true` to allow access, `false` to deny (throws 403)
|
|
72
|
+
*
|
|
73
|
+
* Can be synchronous or return a Promise for async operations.
|
|
74
|
+
*/
|
|
75
|
+
canActivate(context: ExecutionContext): boolean | Promise<boolean>;
|
|
76
|
+
}
|
|
77
|
+
//# sourceMappingURL=can-activate.interface.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"can-activate.interface.d.ts","sourceRoot":"","sources":["../../../src/core/guards/can-activate.interface.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAE5D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+DG;AACH,MAAM,WAAW,WAAW;IAC1B;;;;;;;OAOG;IACH,WAAW,CAAC,OAAO,EAAE,gBAAgB,GAAG,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;CACpE"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"can-activate.interface.js","sourceRoot":"","sources":["../../../src/core/guards/can-activate.interface.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import type { FastifyRequest, FastifyReply } from 'fastify';
|
|
2
|
+
import type { Constructor } from '../types';
|
|
3
|
+
/**
|
|
4
|
+
* ExecutionContext Interface
|
|
5
|
+
*
|
|
6
|
+
* Provides access to the current request context, including
|
|
7
|
+
* request/reply objects and handler metadata. Used by guards
|
|
8
|
+
* to make authorization decisions.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```typescript
|
|
12
|
+
* @Injectable()
|
|
13
|
+
* class AuthGuard implements CanActivate {
|
|
14
|
+
* async canActivate(context: ExecutionContext): Promise<boolean> {
|
|
15
|
+
* const request = context.getRequest();
|
|
16
|
+
* const authHeader = request.headers.authorization;
|
|
17
|
+
* return !!authHeader;
|
|
18
|
+
* }
|
|
19
|
+
* }
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
export interface ExecutionContext {
|
|
23
|
+
/**
|
|
24
|
+
* Get the Fastify request object
|
|
25
|
+
*
|
|
26
|
+
* @returns The current request instance
|
|
27
|
+
*/
|
|
28
|
+
getRequest<T = FastifyRequest>(): T;
|
|
29
|
+
/**
|
|
30
|
+
* Get the Fastify reply object
|
|
31
|
+
*
|
|
32
|
+
* @returns The current reply instance
|
|
33
|
+
*/
|
|
34
|
+
getReply<T = FastifyReply>(): T;
|
|
35
|
+
/**
|
|
36
|
+
* Get the controller class that handles the route
|
|
37
|
+
*
|
|
38
|
+
* @returns The controller constructor
|
|
39
|
+
*/
|
|
40
|
+
getClass(): Constructor;
|
|
41
|
+
/**
|
|
42
|
+
* Get the handler method name
|
|
43
|
+
*
|
|
44
|
+
* @returns The method name being invoked
|
|
45
|
+
*/
|
|
46
|
+
getHandler(): string | symbol;
|
|
47
|
+
/**
|
|
48
|
+
* Get handler metadata by key
|
|
49
|
+
*
|
|
50
|
+
* @param key - Metadata key to retrieve
|
|
51
|
+
* @returns The metadata value if found
|
|
52
|
+
*/
|
|
53
|
+
getMetadata<T = unknown>(key: string | symbol): T | undefined;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Default ExecutionContext implementation
|
|
57
|
+
*
|
|
58
|
+
* @internal
|
|
59
|
+
*/
|
|
60
|
+
export declare class ExecutionContextImpl implements ExecutionContext {
|
|
61
|
+
private readonly request;
|
|
62
|
+
private readonly reply;
|
|
63
|
+
private readonly controllerClass;
|
|
64
|
+
private readonly handlerName;
|
|
65
|
+
constructor(request: FastifyRequest, reply: FastifyReply, controllerClass: Constructor, handlerName: string | symbol);
|
|
66
|
+
getRequest<T = FastifyRequest>(): T;
|
|
67
|
+
getReply<T = FastifyReply>(): T;
|
|
68
|
+
getClass(): Constructor;
|
|
69
|
+
getHandler(): string | symbol;
|
|
70
|
+
getMetadata<T = unknown>(key: string | symbol): T | undefined;
|
|
71
|
+
}
|
|
72
|
+
//# sourceMappingURL=execution-context.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"execution-context.d.ts","sourceRoot":"","sources":["../../../src/core/guards/execution-context.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAC5D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAE5C;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,WAAW,gBAAgB;IAC/B;;;;OAIG;IACH,UAAU,CAAC,CAAC,GAAG,cAAc,KAAK,CAAC,CAAC;IAEpC;;;;OAIG;IACH,QAAQ,CAAC,CAAC,GAAG,YAAY,KAAK,CAAC,CAAC;IAEhC;;;;OAIG;IACH,QAAQ,IAAI,WAAW,CAAC;IAExB;;;;OAIG;IACH,UAAU,IAAI,MAAM,GAAG,MAAM,CAAC;IAE9B;;;;;OAKG;IACH,WAAW,CAAC,CAAC,GAAG,OAAO,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,CAAC,GAAG,SAAS,CAAC;CAC/D;AAED;;;;GAIG;AACH,qBAAa,oBAAqB,YAAW,gBAAgB;IAEzD,OAAO,CAAC,QAAQ,CAAC,OAAO;IACxB,OAAO,CAAC,QAAQ,CAAC,KAAK;IACtB,OAAO,CAAC,QAAQ,CAAC,eAAe;IAChC,OAAO,CAAC,QAAQ,CAAC,WAAW;gBAHX,OAAO,EAAE,cAAc,EACvB,KAAK,EAAE,YAAY,EACnB,eAAe,EAAE,WAAW,EAC5B,WAAW,EAAE,MAAM,GAAG,MAAM;IAG/C,UAAU,CAAC,CAAC,GAAG,cAAc,KAAK,CAAC;IAInC,QAAQ,CAAC,CAAC,GAAG,YAAY,KAAK,CAAC;IAI/B,QAAQ,IAAI,WAAW;IAIvB,UAAU,IAAI,MAAM,GAAG,MAAM;IAI7B,WAAW,CAAC,CAAC,GAAG,OAAO,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,CAAC,GAAG,SAAS;CAG9D"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ExecutionContextImpl = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Default ExecutionContext implementation
|
|
6
|
+
*
|
|
7
|
+
* @internal
|
|
8
|
+
*/
|
|
9
|
+
class ExecutionContextImpl {
|
|
10
|
+
request;
|
|
11
|
+
reply;
|
|
12
|
+
controllerClass;
|
|
13
|
+
handlerName;
|
|
14
|
+
constructor(request, reply, controllerClass, handlerName) {
|
|
15
|
+
this.request = request;
|
|
16
|
+
this.reply = reply;
|
|
17
|
+
this.controllerClass = controllerClass;
|
|
18
|
+
this.handlerName = handlerName;
|
|
19
|
+
}
|
|
20
|
+
getRequest() {
|
|
21
|
+
return this.request;
|
|
22
|
+
}
|
|
23
|
+
getReply() {
|
|
24
|
+
return this.reply;
|
|
25
|
+
}
|
|
26
|
+
getClass() {
|
|
27
|
+
return this.controllerClass;
|
|
28
|
+
}
|
|
29
|
+
getHandler() {
|
|
30
|
+
return this.handlerName;
|
|
31
|
+
}
|
|
32
|
+
getMetadata(key) {
|
|
33
|
+
return Reflect.getMetadata(key, this.controllerClass, this.handlerName);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
exports.ExecutionContextImpl = ExecutionContextImpl;
|
|
37
|
+
//# sourceMappingURL=execution-context.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"execution-context.js","sourceRoot":"","sources":["../../../src/core/guards/execution-context.ts"],"names":[],"mappings":";;;AA4DA;;;;GAIG;AACH,MAAa,oBAAoB;IAEZ;IACA;IACA;IACA;IAJnB,YACmB,OAAuB,EACvB,KAAmB,EACnB,eAA4B,EAC5B,WAA4B;QAH5B,YAAO,GAAP,OAAO,CAAgB;QACvB,UAAK,GAAL,KAAK,CAAc;QACnB,oBAAe,GAAf,eAAe,CAAa;QAC5B,gBAAW,GAAX,WAAW,CAAiB;IAC5C,CAAC;IAEJ,UAAU;QACR,OAAO,IAAI,CAAC,OAAY,CAAC;IAC3B,CAAC;IAED,QAAQ;QACN,OAAO,IAAI,CAAC,KAAU,CAAC;IACzB,CAAC;IAED,QAAQ;QACN,OAAO,IAAI,CAAC,eAAe,CAAC;IAC9B,CAAC;IAED,UAAU;QACR,OAAO,IAAI,CAAC,WAAW,CAAC;IAC1B,CAAC;IAED,WAAW,CAAc,GAAoB;QAC3C,OAAO,OAAO,CAAC,WAAW,CAAC,GAAG,EAAE,IAAI,CAAC,eAAe,EAAE,IAAI,CAAC,WAAqB,CAAkB,CAAC;IACrG,CAAC;CACF;AA3BD,oDA2BC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/core/guards/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AACvD,OAAO,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAG7E,OAAO,EAAE,SAAS,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getGuardsMetadata = exports.UseGuards = exports.ExecutionContextImpl = void 0;
|
|
4
|
+
var execution_context_1 = require("./execution-context");
|
|
5
|
+
Object.defineProperty(exports, "ExecutionContextImpl", { enumerable: true, get: function () { return execution_context_1.ExecutionContextImpl; } });
|
|
6
|
+
// UseGuards decorator
|
|
7
|
+
var use_guards_decorator_1 = require("./use-guards.decorator");
|
|
8
|
+
Object.defineProperty(exports, "UseGuards", { enumerable: true, get: function () { return use_guards_decorator_1.UseGuards; } });
|
|
9
|
+
Object.defineProperty(exports, "getGuardsMetadata", { enumerable: true, get: function () { return use_guards_decorator_1.getGuardsMetadata; } });
|
|
10
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/core/guards/index.ts"],"names":[],"mappings":";;;AAEA,yDAA6E;AAAlD,yHAAA,oBAAoB,OAAA;AAE/C,sBAAsB;AACtB,+DAAsE;AAA7D,iHAAA,SAAS,OAAA;AAAE,yHAAA,iBAAiB,OAAA"}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import 'reflect-metadata';
|
|
2
|
+
import type { Constructor } from '../types';
|
|
3
|
+
import type { CanActivate } from './can-activate.interface';
|
|
4
|
+
/**
|
|
5
|
+
* Type for guard constructors
|
|
6
|
+
*/
|
|
7
|
+
export type GuardClass = Constructor<CanActivate>;
|
|
8
|
+
/**
|
|
9
|
+
* @UseGuards() Decorator
|
|
10
|
+
*
|
|
11
|
+
* Applies one or more guards to a controller or route handler.
|
|
12
|
+
* Guards are executed in order before the handler runs.
|
|
13
|
+
*
|
|
14
|
+
* Guards are resolved from the DI container, so they can have
|
|
15
|
+
* injected dependencies. Make sure guards are decorated with @Injectable().
|
|
16
|
+
*
|
|
17
|
+
* @param guards - Guard classes to apply
|
|
18
|
+
*
|
|
19
|
+
* @example Apply guard to entire controller
|
|
20
|
+
* ```typescript
|
|
21
|
+
* @Controller('/admin')
|
|
22
|
+
* @UseGuards(AuthGuard)
|
|
23
|
+
* class AdminController {
|
|
24
|
+
* @Get('/dashboard')
|
|
25
|
+
* getDashboard() {
|
|
26
|
+
* return { message: 'Admin dashboard' };
|
|
27
|
+
* }
|
|
28
|
+
* }
|
|
29
|
+
* ```
|
|
30
|
+
*
|
|
31
|
+
* @example Apply guard to specific route
|
|
32
|
+
* ```typescript
|
|
33
|
+
* @Controller('/users')
|
|
34
|
+
* class UserController {
|
|
35
|
+
* @Get()
|
|
36
|
+
* findAll() {
|
|
37
|
+
* return []; // Public route
|
|
38
|
+
* }
|
|
39
|
+
*
|
|
40
|
+
* @Post()
|
|
41
|
+
* @UseGuards(AuthGuard)
|
|
42
|
+
* create() {
|
|
43
|
+
* return {}; // Protected route
|
|
44
|
+
* }
|
|
45
|
+
* }
|
|
46
|
+
* ```
|
|
47
|
+
*
|
|
48
|
+
* @example Multiple guards (AND logic - all must pass)
|
|
49
|
+
* ```typescript
|
|
50
|
+
* @Controller('/admin')
|
|
51
|
+
* @UseGuards(AuthGuard, RolesGuard)
|
|
52
|
+
* class AdminController {
|
|
53
|
+
* // User must be authenticated AND have correct role
|
|
54
|
+
* }
|
|
55
|
+
* ```
|
|
56
|
+
*
|
|
57
|
+
* @example Combined controller and method guards
|
|
58
|
+
* ```typescript
|
|
59
|
+
* @Controller('/api')
|
|
60
|
+
* @UseGuards(AuthGuard) // Applied to all routes
|
|
61
|
+
* class ApiController {
|
|
62
|
+
* @Get('/public')
|
|
63
|
+
* // Only AuthGuard runs
|
|
64
|
+
* getPublic() {}
|
|
65
|
+
*
|
|
66
|
+
* @Post('/admin')
|
|
67
|
+
* @UseGuards(AdminGuard) // Additional guard
|
|
68
|
+
* // Both AuthGuard AND AdminGuard run
|
|
69
|
+
* adminAction() {}
|
|
70
|
+
* }
|
|
71
|
+
* ```
|
|
72
|
+
*/
|
|
73
|
+
export declare function UseGuards(...guards: GuardClass[]): ClassDecorator & MethodDecorator;
|
|
74
|
+
/**
|
|
75
|
+
* Get guards metadata from a controller class and/or method
|
|
76
|
+
*
|
|
77
|
+
* @param target - Controller class
|
|
78
|
+
* @param propertyKey - Method name (optional)
|
|
79
|
+
* @returns Combined array of guard classes (controller + method)
|
|
80
|
+
*/
|
|
81
|
+
export declare function getGuardsMetadata(target: Constructor, propertyKey?: string | symbol): GuardClass[];
|
|
82
|
+
//# sourceMappingURL=use-guards.decorator.d.ts.map
|