@decaf-ts/for-nest 0.5.0 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/cjs/bin/cli.cjs +3 -2
- package/lib/cjs/bin/cli.cjs.map +1 -0
- package/lib/cjs/cli-module.cjs +2 -1
- package/lib/cjs/cli-module.cjs.map +1 -0
- package/lib/cjs/constants.cjs +1 -0
- package/lib/cjs/constants.cjs.map +1 -0
- package/lib/cjs/controllers.cjs +3 -2
- package/lib/cjs/controllers.cjs.map +1 -0
- package/lib/cjs/core-module.cjs +31 -25
- package/lib/cjs/core-module.cjs.map +1 -0
- package/lib/cjs/decaf-model/DecafModelModule.cjs +11 -6
- package/lib/cjs/decaf-model/DecafModelModule.cjs.map +1 -0
- package/lib/cjs/decaf-model/FromModelController.cjs +69 -63
- package/lib/cjs/decaf-model/FromModelController.cjs.map +1 -0
- package/lib/cjs/decaf-model/decorators/ApiOperationFromModel.cjs +1 -0
- package/lib/cjs/decaf-model/decorators/ApiOperationFromModel.cjs.map +1 -0
- package/lib/cjs/decaf-model/decorators/ApiParamsFromModel.cjs +1 -0
- package/lib/cjs/decaf-model/decorators/ApiParamsFromModel.cjs.map +1 -0
- package/lib/cjs/decaf-model/decorators/DecafBody.cjs +1 -0
- package/lib/cjs/decaf-model/decorators/DecafBody.cjs.map +1 -0
- package/lib/cjs/decaf-model/decorators/DecafParams.cjs +1 -0
- package/lib/cjs/decaf-model/decorators/DecafParams.cjs.map +1 -0
- package/lib/cjs/decaf-model/decorators/decorators.cjs +5 -4
- package/lib/cjs/decaf-model/decorators/decorators.cjs.map +1 -0
- package/lib/cjs/decaf-model/decorators/index.cjs +1 -0
- package/lib/cjs/decaf-model/decorators/index.cjs.map +1 -0
- package/lib/cjs/decaf-model/decorators/types.cjs +1 -0
- package/lib/cjs/decaf-model/decorators/types.cjs.map +1 -0
- package/lib/cjs/decaf-model/decorators/utils.cjs +1 -0
- package/lib/cjs/decaf-model/decorators/utils.cjs.map +1 -0
- package/lib/cjs/decaf-model/index.cjs +1 -0
- package/lib/cjs/decaf-model/index.cjs.map +1 -0
- package/lib/cjs/decaf-model/types.cjs +1 -0
- package/lib/cjs/decaf-model/types.cjs.map +1 -0
- package/lib/cjs/decaf-model/utils.cjs +5 -4
- package/lib/cjs/decaf-model/utils.cjs.map +1 -0
- package/lib/cjs/decoration.cjs +15 -14
- package/lib/cjs/decoration.cjs.map +1 -0
- package/lib/cjs/events-module/DecafStreamModule.cjs +15 -10
- package/lib/cjs/events-module/DecafStreamModule.cjs.map +1 -0
- package/lib/cjs/events-module/EventsController.cjs +20 -14
- package/lib/cjs/events-module/EventsController.cjs.map +1 -0
- package/lib/cjs/events-module/constant.cjs +1 -0
- package/lib/cjs/events-module/constant.cjs.map +1 -0
- package/lib/cjs/events-module/index.cjs +1 -0
- package/lib/cjs/events-module/index.cjs.map +1 -0
- package/lib/cjs/events-module/utils.cjs +1 -0
- package/lib/cjs/events-module/utils.cjs.map +1 -0
- package/lib/cjs/factory/NestBootstraper.cjs +7 -6
- package/lib/cjs/factory/NestBootstraper.cjs.map +1 -0
- package/lib/cjs/factory/errors/cors.cjs +1 -0
- package/lib/cjs/factory/errors/cors.cjs.map +1 -0
- package/lib/cjs/factory/errors/index.cjs +1 -0
- package/lib/cjs/factory/errors/index.cjs.map +1 -0
- package/lib/cjs/factory/errors/throttling.cjs +1 -0
- package/lib/cjs/factory/errors/throttling.cjs.map +1 -0
- package/lib/cjs/factory/exceptions/DecafErrorFilter.cjs +11 -6
- package/lib/cjs/factory/exceptions/DecafErrorFilter.cjs.map +1 -0
- package/lib/cjs/factory/exceptions/decorators.cjs +5 -4
- package/lib/cjs/factory/exceptions/decorators.cjs.map +1 -0
- package/lib/cjs/factory/exceptions/index.cjs +1 -0
- package/lib/cjs/factory/exceptions/index.cjs.map +1 -0
- package/lib/cjs/factory/index.cjs +1 -0
- package/lib/cjs/factory/index.cjs.map +1 -0
- package/lib/cjs/factory/openapi/DtoBuilder.cjs +8 -7
- package/lib/cjs/factory/openapi/DtoBuilder.cjs.map +1 -0
- package/lib/cjs/factory/openapi/SwaggerBuilder.cjs +7 -6
- package/lib/cjs/factory/openapi/SwaggerBuilder.cjs.map +1 -0
- package/lib/cjs/factory/openapi/SwaggerCustomUI.cjs +3 -2
- package/lib/cjs/factory/openapi/SwaggerCustomUI.cjs.map +1 -0
- package/lib/cjs/factory/openapi/constants.cjs +1 -0
- package/lib/cjs/factory/openapi/constants.cjs.map +1 -0
- package/lib/cjs/factory/openapi/index.cjs +1 -0
- package/lib/cjs/factory/openapi/index.cjs.map +1 -0
- package/lib/cjs/index.cjs +18 -17
- package/lib/cjs/index.cjs.map +1 -0
- package/lib/cjs/interceptors/AuthInterceptor.cjs +16 -10
- package/lib/cjs/interceptors/AuthInterceptor.cjs.map +1 -0
- package/lib/cjs/interceptors/DecafRequestHandlerInterceptor.cjs +14 -8
- package/lib/cjs/interceptors/DecafRequestHandlerInterceptor.cjs.map +1 -0
- package/lib/cjs/interceptors/context.cjs +1 -0
- package/lib/cjs/interceptors/context.cjs.map +1 -0
- package/lib/cjs/interceptors/index.cjs +1 -0
- package/lib/cjs/interceptors/index.cjs.map +1 -0
- package/lib/cjs/module.cjs +16 -11
- package/lib/cjs/module.cjs.map +1 -0
- package/lib/cjs/overrides/Adapter.cjs +1 -0
- package/lib/cjs/overrides/Adapter.cjs.map +1 -0
- package/lib/cjs/overrides/ModelBuilderExtensions.cjs +3 -2
- package/lib/cjs/overrides/ModelBuilderExtensions.cjs.map +1 -0
- package/lib/cjs/overrides/constants.cjs +1 -0
- package/lib/cjs/overrides/constants.cjs.map +1 -0
- package/lib/cjs/overrides/decoration.cjs +8 -7
- package/lib/cjs/overrides/decoration.cjs.map +1 -0
- package/lib/cjs/overrides/helpers.cjs +8 -7
- package/lib/cjs/overrides/helpers.cjs.map +1 -0
- package/lib/cjs/overrides/index.cjs +1 -0
- package/lib/cjs/overrides/index.cjs.map +1 -0
- package/lib/cjs/overrides/overrides.cjs +1 -0
- package/lib/cjs/overrides/overrides.cjs.map +1 -0
- package/lib/cjs/ram/RamRequestTransformer.cjs +1 -0
- package/lib/cjs/ram/RamRequestTransformer.cjs.map +1 -0
- package/lib/cjs/ram/index.cjs +1 -0
- package/lib/cjs/ram/index.cjs.map +1 -0
- package/lib/cjs/request/DecafAuthHandler.cjs +1 -0
- package/lib/cjs/request/DecafAuthHandler.cjs.map +1 -0
- package/lib/cjs/request/DecafHandlerExecutor.cjs +16 -10
- package/lib/cjs/request/DecafHandlerExecutor.cjs.map +1 -0
- package/lib/cjs/request/DecafRequestContext.cjs +12 -6
- package/lib/cjs/request/DecafRequestContext.cjs.map +1 -0
- package/lib/cjs/request/DecafResponseInterceptor.cjs +13 -7
- package/lib/cjs/request/DecafResponseInterceptor.cjs.map +1 -0
- package/lib/cjs/request/index.cjs +1 -0
- package/lib/cjs/request/index.cjs.map +1 -0
- package/lib/cjs/types.cjs +1 -0
- package/lib/cjs/types.cjs.map +1 -0
- package/lib/cjs/utils.cjs +1 -0
- package/lib/cjs/utils.cjs.map +1 -0
- package/lib/esm/index.js +1 -1
- package/lib/types/bin/cli.d.cts +1 -0
- package/lib/types/bin/cli.d.mts +1 -0
- package/lib/types/cli-module.d.cts +11 -0
- package/lib/types/cli-module.d.mts +11 -0
- package/lib/types/constants.d.cts +15 -0
- package/lib/types/constants.d.mts +15 -0
- package/lib/types/controllers.d.cts +22 -0
- package/lib/types/controllers.d.mts +22 -0
- package/lib/types/core-module.d.cts +17 -0
- package/lib/types/core-module.d.mts +17 -0
- package/lib/types/decaf-model/DecafModelModule.d.cts +9 -0
- package/lib/types/decaf-model/DecafModelModule.d.mts +9 -0
- package/lib/types/decaf-model/FromModelController.d.cts +61 -0
- package/lib/types/decaf-model/FromModelController.d.mts +61 -0
- package/lib/types/decaf-model/decorators/ApiOperationFromModel.d.cts +30 -0
- package/lib/types/decaf-model/decorators/ApiOperationFromModel.d.mts +30 -0
- package/lib/types/decaf-model/decorators/ApiParamsFromModel.d.cts +13 -0
- package/lib/types/decaf-model/decorators/ApiParamsFromModel.d.mts +13 -0
- package/lib/types/decaf-model/decorators/DecafBody.d.cts +5 -0
- package/lib/types/decaf-model/decorators/DecafBody.d.mts +5 -0
- package/lib/types/decaf-model/decorators/DecafParams.d.cts +9 -0
- package/lib/types/decaf-model/decorators/DecafParams.d.mts +9 -0
- package/lib/types/decaf-model/decorators/decorators.d.cts +29 -0
- package/lib/types/decaf-model/decorators/decorators.d.mts +29 -0
- package/lib/types/decaf-model/decorators/index.d.cts +7 -0
- package/lib/types/decaf-model/decorators/index.d.mts +7 -0
- package/lib/types/decaf-model/decorators/types.d.cts +23 -0
- package/lib/types/decaf-model/decorators/types.d.mts +23 -0
- package/lib/types/decaf-model/decorators/utils.d.cts +11 -0
- package/lib/types/decaf-model/decorators/utils.d.mts +11 -0
- package/lib/types/decaf-model/index.d.cts +3 -0
- package/lib/types/decaf-model/index.d.mts +3 -0
- package/lib/types/decaf-model/types.d.cts +7 -0
- package/lib/types/decaf-model/types.d.mts +7 -0
- package/lib/types/decaf-model/utils.d.cts +10 -0
- package/lib/types/decaf-model/utils.d.mts +10 -0
- package/lib/types/decoration.d.cts +1 -0
- package/lib/types/decoration.d.mts +1 -0
- package/lib/types/events-module/DecafStreamModule.d.cts +4 -0
- package/lib/types/events-module/DecafStreamModule.d.mts +4 -0
- package/lib/types/events-module/EventsController.d.cts +11 -0
- package/lib/types/events-module/EventsController.d.mts +11 -0
- package/lib/types/events-module/constant.d.cts +1 -0
- package/lib/types/events-module/constant.d.mts +1 -0
- package/lib/types/events-module/index.d.cts +2 -0
- package/lib/types/events-module/index.d.mts +2 -0
- package/lib/types/events-module/utils.d.cts +1 -0
- package/lib/types/events-module/utils.d.mts +1 -0
- package/lib/types/factory/NestBootstraper.d.cts +224 -0
- package/lib/types/factory/NestBootstraper.d.mts +224 -0
- package/lib/types/factory/errors/cors.d.cts +4 -0
- package/lib/types/factory/errors/cors.d.mts +4 -0
- package/lib/types/factory/errors/index.d.cts +1 -0
- package/lib/types/factory/errors/index.d.mts +1 -0
- package/lib/types/factory/errors/throttling.d.cts +4 -0
- package/lib/types/factory/errors/throttling.d.mts +4 -0
- package/lib/types/factory/exceptions/DecafErrorFilter.d.cts +4 -0
- package/lib/types/factory/exceptions/DecafErrorFilter.d.mts +4 -0
- package/lib/types/factory/exceptions/decorators.d.cts +2 -0
- package/lib/types/factory/exceptions/decorators.d.mts +2 -0
- package/lib/types/factory/exceptions/index.d.cts +2 -0
- package/lib/types/factory/exceptions/index.d.mts +2 -0
- package/lib/types/factory/index.d.cts +4 -0
- package/lib/types/factory/index.d.mts +4 -0
- package/lib/types/factory/openapi/DtoBuilder.d.cts +25 -0
- package/lib/types/factory/openapi/DtoBuilder.d.mts +25 -0
- package/lib/types/factory/openapi/SwaggerBuilder.d.cts +10 -0
- package/lib/types/factory/openapi/SwaggerBuilder.d.mts +10 -0
- package/lib/types/factory/openapi/SwaggerCustomUI.d.cts +22 -0
- package/lib/types/factory/openapi/SwaggerCustomUI.d.mts +22 -0
- package/lib/types/factory/openapi/constants.d.cts +27 -0
- package/lib/types/factory/openapi/constants.d.mts +27 -0
- package/lib/types/factory/openapi/index.d.cts +2 -0
- package/lib/types/factory/openapi/index.d.mts +2 -0
- package/lib/types/index.d.cts +43 -0
- package/lib/types/index.d.mts +43 -0
- package/lib/types/index.d.ts +1 -1
- package/lib/types/interceptors/AuthInterceptor.d.cts +10 -0
- package/lib/types/interceptors/AuthInterceptor.d.mts +10 -0
- package/lib/types/interceptors/DecafRequestHandlerInterceptor.d.cts +57 -0
- package/lib/types/interceptors/DecafRequestHandlerInterceptor.d.mts +57 -0
- package/lib/types/interceptors/context.d.cts +6 -0
- package/lib/types/interceptors/context.d.mts +6 -0
- package/lib/types/interceptors/index.d.cts +3 -0
- package/lib/types/interceptors/index.d.mts +3 -0
- package/lib/types/module.d.cts +8 -0
- package/lib/types/module.d.mts +8 -0
- package/lib/types/overrides/Adapter.d.cts +13 -0
- package/lib/types/overrides/Adapter.d.mts +13 -0
- package/lib/types/overrides/ModelBuilderExtensions.d.cts +8 -0
- package/lib/types/overrides/ModelBuilderExtensions.d.mts +8 -0
- package/lib/types/overrides/constants.d.cts +21 -0
- package/lib/types/overrides/constants.d.mts +21 -0
- package/lib/types/overrides/decoration.d.cts +30 -0
- package/lib/types/overrides/decoration.d.mts +30 -0
- package/lib/types/overrides/helpers.d.cts +11 -0
- package/lib/types/overrides/helpers.d.mts +11 -0
- package/lib/types/overrides/index.d.cts +6 -0
- package/lib/types/overrides/index.d.mts +6 -0
- package/lib/types/overrides/overrides.d.cts +1 -0
- package/lib/types/overrides/overrides.d.mts +1 -0
- package/lib/types/ram/RamRequestTransformer.d.cts +5 -0
- package/lib/types/ram/RamRequestTransformer.d.mts +5 -0
- package/lib/types/ram/index.d.cts +1 -0
- package/lib/types/ram/index.d.mts +1 -0
- package/lib/types/request/DecafAuthHandler.d.cts +10 -0
- package/lib/types/request/DecafAuthHandler.d.mts +10 -0
- package/lib/types/request/DecafHandlerExecutor.d.cts +52 -0
- package/lib/types/request/DecafHandlerExecutor.d.mts +52 -0
- package/lib/types/request/DecafRequestContext.d.cts +11 -0
- package/lib/types/request/DecafRequestContext.d.mts +11 -0
- package/lib/types/request/DecafResponseInterceptor.d.cts +8 -0
- package/lib/types/request/DecafResponseInterceptor.d.mts +8 -0
- package/lib/types/request/index.d.cts +4 -0
- package/lib/types/request/index.d.mts +4 -0
- package/lib/types/types.d.cts +88 -0
- package/lib/types/types.d.mts +88 -0
- package/lib/types/utils.d.cts +2 -0
- package/lib/types/utils.d.mts +2 -0
- package/package.json +21 -11
- package/lib/cjs/bin/cli.js.map +0 -1
- package/lib/cjs/cli-module.js.map +0 -1
- package/lib/cjs/constants.js.map +0 -1
- package/lib/cjs/controllers.js.map +0 -1
- package/lib/cjs/core-module.js.map +0 -1
- package/lib/cjs/decaf-model/DecafModelModule.js.map +0 -1
- package/lib/cjs/decaf-model/FromModelController.js.map +0 -1
- package/lib/cjs/decaf-model/decorators/ApiOperationFromModel.js.map +0 -1
- package/lib/cjs/decaf-model/decorators/ApiParamsFromModel.js.map +0 -1
- package/lib/cjs/decaf-model/decorators/DecafBody.js.map +0 -1
- package/lib/cjs/decaf-model/decorators/DecafParams.js.map +0 -1
- package/lib/cjs/decaf-model/decorators/decorators.js.map +0 -1
- package/lib/cjs/decaf-model/decorators/index.js.map +0 -1
- package/lib/cjs/decaf-model/decorators/types.js.map +0 -1
- package/lib/cjs/decaf-model/decorators/utils.js.map +0 -1
- package/lib/cjs/decaf-model/index.js.map +0 -1
- package/lib/cjs/decaf-model/types.js.map +0 -1
- package/lib/cjs/decaf-model/utils.js.map +0 -1
- package/lib/cjs/decoration.js.map +0 -1
- package/lib/cjs/events-module/DecafStreamModule.js.map +0 -1
- package/lib/cjs/events-module/EventsController.js.map +0 -1
- package/lib/cjs/events-module/constant.js.map +0 -1
- package/lib/cjs/events-module/index.js.map +0 -1
- package/lib/cjs/events-module/utils.js.map +0 -1
- package/lib/cjs/factory/NestBootstraper.js.map +0 -1
- package/lib/cjs/factory/errors/cors.js.map +0 -1
- package/lib/cjs/factory/errors/index.js.map +0 -1
- package/lib/cjs/factory/errors/throttling.js.map +0 -1
- package/lib/cjs/factory/exceptions/DecafErrorFilter.js.map +0 -1
- package/lib/cjs/factory/exceptions/decorators.js.map +0 -1
- package/lib/cjs/factory/exceptions/index.js.map +0 -1
- package/lib/cjs/factory/index.js.map +0 -1
- package/lib/cjs/factory/openapi/DtoBuilder.js.map +0 -1
- package/lib/cjs/factory/openapi/SwaggerBuilder.js.map +0 -1
- package/lib/cjs/factory/openapi/SwaggerCustomUI.js.map +0 -1
- package/lib/cjs/factory/openapi/constants.js.map +0 -1
- package/lib/cjs/factory/openapi/index.js.map +0 -1
- package/lib/cjs/index.js.map +0 -1
- package/lib/cjs/interceptors/AuthInterceptor.js.map +0 -1
- package/lib/cjs/interceptors/DecafRequestHandlerInterceptor.js.map +0 -1
- package/lib/cjs/interceptors/context.js.map +0 -1
- package/lib/cjs/interceptors/index.js.map +0 -1
- package/lib/cjs/module.js.map +0 -1
- package/lib/cjs/overrides/Adapter.js.map +0 -1
- package/lib/cjs/overrides/ModelBuilderExtensions.js.map +0 -1
- package/lib/cjs/overrides/constants.js.map +0 -1
- package/lib/cjs/overrides/decoration.js.map +0 -1
- package/lib/cjs/overrides/helpers.js.map +0 -1
- package/lib/cjs/overrides/index.js.map +0 -1
- package/lib/cjs/overrides/overrides.js.map +0 -1
- package/lib/cjs/ram/RamRequestTransformer.js.map +0 -1
- package/lib/cjs/ram/index.js.map +0 -1
- package/lib/cjs/request/DecafAuthHandler.js.map +0 -1
- package/lib/cjs/request/DecafHandlerExecutor.js.map +0 -1
- package/lib/cjs/request/DecafRequestContext.js.map +0 -1
- package/lib/cjs/request/DecafResponseInterceptor.js.map +0 -1
- package/lib/cjs/request/index.js.map +0 -1
- package/lib/cjs/types.js.map +0 -1
- package/lib/cjs/utils.js.map +0 -1
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { CallHandler, ExecutionContext, NestInterceptor } from "@nestjs/common";
|
|
2
|
+
import { DecafHandlerExecutor, DecafRequestContext } from "../request/index.js";
|
|
3
|
+
import { DecafServerCtx } from "../constants.js";
|
|
4
|
+
import "../overrides";
|
|
5
|
+
/**
|
|
6
|
+
* @description
|
|
7
|
+
* Interceptor responsible for executing all registered Decaf request handlers
|
|
8
|
+
* before the controller method is invoked.
|
|
9
|
+
*
|
|
10
|
+
* @summary
|
|
11
|
+
* The {@link DecafRequestHandlerInterceptor} integrates the Decaf request-handling pipeline
|
|
12
|
+
* into NestJS' interceptor mechanism. Before passing execution to the next handler in the
|
|
13
|
+
* NestJS chain, it delegates request processing to the {@link DecafHandlerExecutor}, which
|
|
14
|
+
* sequentially runs all registered {@link DecafRequestHandler} instances. This allows
|
|
15
|
+
* behaviors such as authentication, logging, tenant resolution, or metadata enrichment
|
|
16
|
+
* to occur prior to controller execution.
|
|
17
|
+
*
|
|
18
|
+
* @class DecafRequestHandlerInterceptor
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```ts
|
|
22
|
+
* // Apply globally:
|
|
23
|
+
* app.useGlobalInterceptors(new DecafRequestHandlerInterceptor(executor));
|
|
24
|
+
*
|
|
25
|
+
* // Or in a module:
|
|
26
|
+
* @Module({
|
|
27
|
+
* providers: [
|
|
28
|
+
* DecafHandlerExecutor,
|
|
29
|
+
* {
|
|
30
|
+
* provide: APP_INTERCEPTOR,
|
|
31
|
+
* useClass: DecafRequestHandlerInterceptor,
|
|
32
|
+
* },
|
|
33
|
+
* ],
|
|
34
|
+
* })
|
|
35
|
+
* export class AppModule {}
|
|
36
|
+
* ```
|
|
37
|
+
*
|
|
38
|
+
* @mermaid
|
|
39
|
+
* sequenceDiagram
|
|
40
|
+
* participant Client
|
|
41
|
+
* participant Interceptor
|
|
42
|
+
* participant Executor
|
|
43
|
+
* participant Controller
|
|
44
|
+
*
|
|
45
|
+
* Client->>Interceptor: HTTP Request
|
|
46
|
+
* Interceptor->>Executor: exec(request)
|
|
47
|
+
* Executor-->>Interceptor: handlers completed
|
|
48
|
+
* Interceptor->>Controller: next.handle()
|
|
49
|
+
* Controller-->>Client: Response
|
|
50
|
+
*/
|
|
51
|
+
export declare class DecafRequestHandlerInterceptor implements NestInterceptor {
|
|
52
|
+
protected readonly requestContext: DecafRequestContext;
|
|
53
|
+
protected readonly executor: DecafHandlerExecutor;
|
|
54
|
+
constructor(requestContext: DecafRequestContext, executor: DecafHandlerExecutor);
|
|
55
|
+
protected contextualize(req: any): Promise<DecafServerCtx>;
|
|
56
|
+
intercept(context: ExecutionContext, next: CallHandler): Promise<import("rxjs").Observable<any>>;
|
|
57
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { DecafServerCtx } from "../constants.cjs";
|
|
2
|
+
import { FlagsOf } from "@decaf-ts/core";
|
|
3
|
+
export declare abstract class RequestToContextTransformer<C extends DecafServerCtx> {
|
|
4
|
+
abstract from(req: any, ...args: any[]): Promise<FlagsOf<C>>;
|
|
5
|
+
}
|
|
6
|
+
export declare function requestToContextTransformer(flavour: string): (original: any) => any;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { DecafServerCtx } from "../constants.js";
|
|
2
|
+
import { FlagsOf } from "@decaf-ts/core";
|
|
3
|
+
export declare abstract class RequestToContextTransformer<C extends DecafServerCtx> {
|
|
4
|
+
abstract from(req: any, ...args: any[]): Promise<FlagsOf<C>>;
|
|
5
|
+
}
|
|
6
|
+
export declare function requestToContextTransformer(flavour: string): (original: any) => any;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import "@decaf-ts/core";
|
|
2
|
+
import type { Constructor } from "@decaf-ts/decoration";
|
|
3
|
+
import { RequestToContextTransformer } from "../interceptors/context.cjs";
|
|
4
|
+
import { ContextOf } from "@decaf-ts/core";
|
|
5
|
+
declare module "@decaf-ts/core" {
|
|
6
|
+
namespace Adapter {
|
|
7
|
+
function transformerFor<A extends Adapter<any, any, any, any>>(adapter: A | string): Constructor<RequestToContextTransformer<ContextOf<A>>> | RequestToContextTransformer<ContextOf<A>>;
|
|
8
|
+
function flavoursToTransform(): string[] | undefined;
|
|
9
|
+
}
|
|
10
|
+
interface Context {
|
|
11
|
+
toResponse<RES = any>(res: RES): RES;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import "@decaf-ts/core";
|
|
2
|
+
import type { Constructor } from "@decaf-ts/decoration";
|
|
3
|
+
import { RequestToContextTransformer } from "../interceptors/context.js";
|
|
4
|
+
import { ContextOf } from "@decaf-ts/core";
|
|
5
|
+
declare module "@decaf-ts/core" {
|
|
6
|
+
namespace Adapter {
|
|
7
|
+
function transformerFor<A extends Adapter<any, any, any, any>>(adapter: A | string): Constructor<RequestToContextTransformer<ContextOf<A>>> | RequestToContextTransformer<ContextOf<A>>;
|
|
8
|
+
function flavoursToTransform(): string[] | undefined;
|
|
9
|
+
}
|
|
10
|
+
interface Context {
|
|
11
|
+
toResponse<RES = any>(res: RES): RES;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import "@decaf-ts/decorator-validation";
|
|
2
|
+
import { Constructor } from "@decaf-ts/decoration";
|
|
3
|
+
declare module "@decaf-ts/decorator-validation" {
|
|
4
|
+
interface ModelBuilder<M> {
|
|
5
|
+
Auth(model: string | Constructor): ModelBuilder<M>;
|
|
6
|
+
decorateClass(decorator: ClassDecorator): ModelBuilder<M>;
|
|
7
|
+
}
|
|
8
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import "@decaf-ts/decorator-validation";
|
|
2
|
+
import { Constructor } from "@decaf-ts/decoration";
|
|
3
|
+
declare module "@decaf-ts/decorator-validation" {
|
|
4
|
+
interface ModelBuilder<M> {
|
|
5
|
+
Auth(model: string | Constructor): ModelBuilder<M>;
|
|
6
|
+
decorateClass(decorator: ClassDecorator): ModelBuilder<M>;
|
|
7
|
+
}
|
|
8
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export declare const DECORATORS_PREFIX = "swagger";
|
|
2
|
+
export declare const DECORATORS: {
|
|
3
|
+
API_OPERATION: string;
|
|
4
|
+
API_RESPONSE: string;
|
|
5
|
+
API_PRODUCES: string;
|
|
6
|
+
API_CONSUMES: string;
|
|
7
|
+
API_TAGS: string;
|
|
8
|
+
API_CALLBACKS: string;
|
|
9
|
+
API_PARAMETERS: string;
|
|
10
|
+
API_HEADERS: string;
|
|
11
|
+
API_MODEL_PROPERTIES: string;
|
|
12
|
+
API_MODEL_PROPERTIES_ARRAY: string;
|
|
13
|
+
API_SECURITY: string;
|
|
14
|
+
API_EXCLUDE_ENDPOINT: string;
|
|
15
|
+
API_EXCLUDE_CONTROLLER: string;
|
|
16
|
+
API_EXTRA_MODELS: string;
|
|
17
|
+
API_EXTENSION: string;
|
|
18
|
+
API_SCHEMA: string;
|
|
19
|
+
API_DEFAULT_GETTER: string;
|
|
20
|
+
API_LINK: string;
|
|
21
|
+
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export declare const DECORATORS_PREFIX = "swagger";
|
|
2
|
+
export declare const DECORATORS: {
|
|
3
|
+
API_OPERATION: string;
|
|
4
|
+
API_RESPONSE: string;
|
|
5
|
+
API_PRODUCES: string;
|
|
6
|
+
API_CONSUMES: string;
|
|
7
|
+
API_TAGS: string;
|
|
8
|
+
API_CALLBACKS: string;
|
|
9
|
+
API_PARAMETERS: string;
|
|
10
|
+
API_HEADERS: string;
|
|
11
|
+
API_MODEL_PROPERTIES: string;
|
|
12
|
+
API_MODEL_PROPERTIES_ARRAY: string;
|
|
13
|
+
API_SECURITY: string;
|
|
14
|
+
API_EXCLUDE_ENDPOINT: string;
|
|
15
|
+
API_EXCLUDE_CONTROLLER: string;
|
|
16
|
+
API_EXTRA_MODELS: string;
|
|
17
|
+
API_EXTENSION: string;
|
|
18
|
+
API_SCHEMA: string;
|
|
19
|
+
API_DEFAULT_GETTER: string;
|
|
20
|
+
API_LINK: string;
|
|
21
|
+
};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { Type } from "@nestjs/common";
|
|
2
|
+
import type { EnumSchemaAttributes } from "@nestjs/swagger/dist/interfaces/enum-schema-attributes.interface";
|
|
3
|
+
import type { SchemaObjectMetadata } from "@nestjs/swagger/dist/interfaces/schema-object-metadata.interface";
|
|
4
|
+
import { type SwaggerEnumType } from "@nestjs/swagger/dist/types/swagger-enum.type";
|
|
5
|
+
export declare const isUndefined: (obj: any) => obj is undefined;
|
|
6
|
+
export declare function getEnumValues(enumType: SwaggerEnumType | (() => SwaggerEnumType)): string[] | number[];
|
|
7
|
+
export declare function getEnumType(values: (string | number)[]): "string" | "number";
|
|
8
|
+
export declare function createPropertyDecorator<T extends Record<string, any> = any>(metakey: string, metadata: T, overrideExisting?: boolean): PropertyDecorator;
|
|
9
|
+
export type ApiPropertyCommonOptions = SchemaObjectMetadata & {
|
|
10
|
+
"x-enumNames"?: string[];
|
|
11
|
+
/**
|
|
12
|
+
* Lazy function returning the type for which the decorated property
|
|
13
|
+
* can be used as an id
|
|
14
|
+
*
|
|
15
|
+
* Use together with @ApiDefaultGetter on the getter route of the type
|
|
16
|
+
* to generate OpenAPI link objects
|
|
17
|
+
*
|
|
18
|
+
* @see [Swagger link objects](https://swagger.io/docs/specification/links/)
|
|
19
|
+
*/
|
|
20
|
+
link?: () => Type<unknown> | Function;
|
|
21
|
+
};
|
|
22
|
+
export type ApiPropertyOptions = ApiPropertyCommonOptions | (ApiPropertyCommonOptions & {
|
|
23
|
+
enumName: string;
|
|
24
|
+
enumSchema?: EnumSchemaAttributes;
|
|
25
|
+
});
|
|
26
|
+
/**
|
|
27
|
+
* @publicApi
|
|
28
|
+
*/
|
|
29
|
+
export declare function ApiProperty(options?: ApiPropertyOptions): PropertyDecorator;
|
|
30
|
+
export declare function createApiPropertyDecorator(options?: ApiPropertyOptions, overrideExisting?: boolean): PropertyDecorator;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { Type } from "@nestjs/common";
|
|
2
|
+
import type { EnumSchemaAttributes } from "@nestjs/swagger/dist/interfaces/enum-schema-attributes.interface";
|
|
3
|
+
import type { SchemaObjectMetadata } from "@nestjs/swagger/dist/interfaces/schema-object-metadata.interface";
|
|
4
|
+
import { type SwaggerEnumType } from "@nestjs/swagger/dist/types/swagger-enum.type";
|
|
5
|
+
export declare const isUndefined: (obj: any) => obj is undefined;
|
|
6
|
+
export declare function getEnumValues(enumType: SwaggerEnumType | (() => SwaggerEnumType)): string[] | number[];
|
|
7
|
+
export declare function getEnumType(values: (string | number)[]): "string" | "number";
|
|
8
|
+
export declare function createPropertyDecorator<T extends Record<string, any> = any>(metakey: string, metadata: T, overrideExisting?: boolean): PropertyDecorator;
|
|
9
|
+
export type ApiPropertyCommonOptions = SchemaObjectMetadata & {
|
|
10
|
+
"x-enumNames"?: string[];
|
|
11
|
+
/**
|
|
12
|
+
* Lazy function returning the type for which the decorated property
|
|
13
|
+
* can be used as an id
|
|
14
|
+
*
|
|
15
|
+
* Use together with @ApiDefaultGetter on the getter route of the type
|
|
16
|
+
* to generate OpenAPI link objects
|
|
17
|
+
*
|
|
18
|
+
* @see [Swagger link objects](https://swagger.io/docs/specification/links/)
|
|
19
|
+
*/
|
|
20
|
+
link?: () => Type<unknown> | Function;
|
|
21
|
+
};
|
|
22
|
+
export type ApiPropertyOptions = ApiPropertyCommonOptions | (ApiPropertyCommonOptions & {
|
|
23
|
+
enumName: string;
|
|
24
|
+
enumSchema?: EnumSchemaAttributes;
|
|
25
|
+
});
|
|
26
|
+
/**
|
|
27
|
+
* @publicApi
|
|
28
|
+
*/
|
|
29
|
+
export declare function ApiProperty(options?: ApiPropertyOptions): PropertyDecorator;
|
|
30
|
+
export declare function createApiPropertyDecorator(options?: ApiPropertyOptions, overrideExisting?: boolean): PropertyDecorator;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export declare const isConstructor: (val: any) => boolean;
|
|
2
|
+
export declare const METADATA_FACTORY_NAME = "_OPENAPI_METADATA_FACTORY";
|
|
3
|
+
export declare const METHOD_METADATA = "method";
|
|
4
|
+
export declare function createMethodDecorator<T = any>(metakey: string, metadata: T, { overrideExisting }?: {
|
|
5
|
+
overrideExisting: boolean;
|
|
6
|
+
}): MethodDecorator;
|
|
7
|
+
export declare function createClassDecorator<T extends Array<any> = any>(metakey: string, metadata?: T): ClassDecorator;
|
|
8
|
+
export declare function createPropertyDecorator<T extends Record<string, any> = any>(metakey: string, metadata: T, overrideExisting?: boolean): PropertyDecorator;
|
|
9
|
+
export declare function createMixedDecorator<T = any>(metakey: string, metadata: T): MethodDecorator & ClassDecorator;
|
|
10
|
+
export declare function createParamDecorator<T extends Record<string, any> = any>(metadata: T, initial: Partial<T>): MethodDecorator & ClassDecorator;
|
|
11
|
+
export declare function getTypeIsArrayTuple(input: Function | [Function] | undefined | string | Record<string, any>, isArrayFlag: boolean): [Function | undefined, boolean];
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export declare const isConstructor: (val: any) => boolean;
|
|
2
|
+
export declare const METADATA_FACTORY_NAME = "_OPENAPI_METADATA_FACTORY";
|
|
3
|
+
export declare const METHOD_METADATA = "method";
|
|
4
|
+
export declare function createMethodDecorator<T = any>(metakey: string, metadata: T, { overrideExisting }?: {
|
|
5
|
+
overrideExisting: boolean;
|
|
6
|
+
}): MethodDecorator;
|
|
7
|
+
export declare function createClassDecorator<T extends Array<any> = any>(metakey: string, metadata?: T): ClassDecorator;
|
|
8
|
+
export declare function createPropertyDecorator<T extends Record<string, any> = any>(metakey: string, metadata: T, overrideExisting?: boolean): PropertyDecorator;
|
|
9
|
+
export declare function createMixedDecorator<T = any>(metakey: string, metadata: T): MethodDecorator & ClassDecorator;
|
|
10
|
+
export declare function createParamDecorator<T extends Record<string, any> = any>(metadata: T, initial: Partial<T>): MethodDecorator & ClassDecorator;
|
|
11
|
+
export declare function getTypeIsArrayTuple(input: Function | [Function] | undefined | string | Record<string, any>, isArrayFlag: boolean): [Function | undefined, boolean];
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./RamRequestTransformer.cjs";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./RamRequestTransformer.js";
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { ExecutionContext } from "@nestjs/common";
|
|
2
|
+
import { AuthHandler } from "../types.cjs";
|
|
3
|
+
export declare class DecafAuthHandler implements AuthHandler {
|
|
4
|
+
protected parseRequest(req: any): string;
|
|
5
|
+
authorize(ctx: ExecutionContext, resource: string): Promise<void>;
|
|
6
|
+
}
|
|
7
|
+
export declare class DecafRoleAuthHandler extends DecafAuthHandler {
|
|
8
|
+
constructor();
|
|
9
|
+
authorize(ctx: ExecutionContext, resource: string): Promise<any>;
|
|
10
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { ExecutionContext } from "@nestjs/common";
|
|
2
|
+
import { AuthHandler } from "../types.js";
|
|
3
|
+
export declare class DecafAuthHandler implements AuthHandler {
|
|
4
|
+
protected parseRequest(req: any): string;
|
|
5
|
+
authorize(ctx: ExecutionContext, resource: string): Promise<void>;
|
|
6
|
+
}
|
|
7
|
+
export declare class DecafRoleAuthHandler extends DecafAuthHandler {
|
|
8
|
+
constructor();
|
|
9
|
+
authorize(ctx: ExecutionContext, resource: string): Promise<any>;
|
|
10
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { DecafRequestContext } from "./DecafRequestContext.cjs";
|
|
2
|
+
import { type DecafRequestHandler } from "../types.cjs";
|
|
3
|
+
/**
|
|
4
|
+
* @description
|
|
5
|
+
* Executes all registered {@link DecafRequestHandler} instances for the current request,
|
|
6
|
+
* providing them with a shared {@link DecafRequestContext}.
|
|
7
|
+
*
|
|
8
|
+
* @summary
|
|
9
|
+
* The {@link DecafHandlerExecutor} class is responsible for orchestrating and executing
|
|
10
|
+
* a sequence of request handlers. Each handler receives the same request-scoped context,
|
|
11
|
+
* allowing coordinated processing such as authentication, metadata extraction, auditing,
|
|
12
|
+
* and custom pipeline behavior. Handlers are injected via the {@link DECAF_HANDLERS} token,
|
|
13
|
+
* ensuring extensibility and loose coupling.
|
|
14
|
+
*
|
|
15
|
+
* @class DecafHandlerExecutor
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```ts
|
|
19
|
+
* // Example handler:
|
|
20
|
+
* class AuthHandler implements DecafRequestHandler {
|
|
21
|
+
* async handle(context: DecafRequestContext, req: Request) {
|
|
22
|
+
* const token = req.headers["authorization"];
|
|
23
|
+
* const result = MyService.doSomething(token);
|
|
24
|
+
* context.set("my-key", result);
|
|
25
|
+
* }
|
|
26
|
+
* }
|
|
27
|
+
*
|
|
28
|
+
* // Executor usage in a request:
|
|
29
|
+
* await executor.exec(request);
|
|
30
|
+
* // All handlers will run in sequence
|
|
31
|
+
* ```
|
|
32
|
+
*
|
|
33
|
+
* @mermaid
|
|
34
|
+
* sequenceDiagram
|
|
35
|
+
* participant Client
|
|
36
|
+
* participant Executor
|
|
37
|
+
* participant HandlerA
|
|
38
|
+
* participant HandlerB
|
|
39
|
+
*
|
|
40
|
+
* Client->>Executor: exec(req)
|
|
41
|
+
* Executor->>HandlerA: handle(context, req)
|
|
42
|
+
* HandlerA-->>Executor: completed
|
|
43
|
+
* Executor->>HandlerB: handle(context, req)
|
|
44
|
+
* HandlerB-->>Executor: completed
|
|
45
|
+
* Executor-->>Client: processing finished
|
|
46
|
+
*/
|
|
47
|
+
export declare class DecafHandlerExecutor {
|
|
48
|
+
private readonly handlers;
|
|
49
|
+
private readonly context;
|
|
50
|
+
constructor(handlers: DecafRequestHandler[], context: DecafRequestContext);
|
|
51
|
+
exec(req: Request, res: Response): Promise<void>;
|
|
52
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { DecafRequestContext } from "./DecafRequestContext.js";
|
|
2
|
+
import { type DecafRequestHandler } from "../types.js";
|
|
3
|
+
/**
|
|
4
|
+
* @description
|
|
5
|
+
* Executes all registered {@link DecafRequestHandler} instances for the current request,
|
|
6
|
+
* providing them with a shared {@link DecafRequestContext}.
|
|
7
|
+
*
|
|
8
|
+
* @summary
|
|
9
|
+
* The {@link DecafHandlerExecutor} class is responsible for orchestrating and executing
|
|
10
|
+
* a sequence of request handlers. Each handler receives the same request-scoped context,
|
|
11
|
+
* allowing coordinated processing such as authentication, metadata extraction, auditing,
|
|
12
|
+
* and custom pipeline behavior. Handlers are injected via the {@link DECAF_HANDLERS} token,
|
|
13
|
+
* ensuring extensibility and loose coupling.
|
|
14
|
+
*
|
|
15
|
+
* @class DecafHandlerExecutor
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```ts
|
|
19
|
+
* // Example handler:
|
|
20
|
+
* class AuthHandler implements DecafRequestHandler {
|
|
21
|
+
* async handle(context: DecafRequestContext, req: Request) {
|
|
22
|
+
* const token = req.headers["authorization"];
|
|
23
|
+
* const result = MyService.doSomething(token);
|
|
24
|
+
* context.set("my-key", result);
|
|
25
|
+
* }
|
|
26
|
+
* }
|
|
27
|
+
*
|
|
28
|
+
* // Executor usage in a request:
|
|
29
|
+
* await executor.exec(request);
|
|
30
|
+
* // All handlers will run in sequence
|
|
31
|
+
* ```
|
|
32
|
+
*
|
|
33
|
+
* @mermaid
|
|
34
|
+
* sequenceDiagram
|
|
35
|
+
* participant Client
|
|
36
|
+
* participant Executor
|
|
37
|
+
* participant HandlerA
|
|
38
|
+
* participant HandlerB
|
|
39
|
+
*
|
|
40
|
+
* Client->>Executor: exec(req)
|
|
41
|
+
* Executor->>HandlerA: handle(context, req)
|
|
42
|
+
* HandlerA-->>Executor: completed
|
|
43
|
+
* Executor->>HandlerB: handle(context, req)
|
|
44
|
+
* HandlerB-->>Executor: completed
|
|
45
|
+
* Executor-->>Client: processing finished
|
|
46
|
+
*/
|
|
47
|
+
export declare class DecafHandlerExecutor {
|
|
48
|
+
private readonly handlers;
|
|
49
|
+
private readonly context;
|
|
50
|
+
constructor(handlers: DecafRequestHandler[], context: DecafRequestContext);
|
|
51
|
+
exec(req: Request, res: Response): Promise<void>;
|
|
52
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { DecafServerCtx } from "../constants.cjs";
|
|
2
|
+
export declare class DecafRequestContext<C extends DecafServerCtx = DecafServerCtx> {
|
|
3
|
+
private readonly req;
|
|
4
|
+
private _ctx?;
|
|
5
|
+
uuid: string | Promise<string>;
|
|
6
|
+
constructor(req: Request);
|
|
7
|
+
get request(): Record<string | symbol, any>;
|
|
8
|
+
put(record: Record<any, any>): void;
|
|
9
|
+
applyCtx(ctx: C): void;
|
|
10
|
+
get ctx(): C;
|
|
11
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { DecafServerCtx } from "../constants.js";
|
|
2
|
+
export declare class DecafRequestContext<C extends DecafServerCtx = DecafServerCtx> {
|
|
3
|
+
private readonly req;
|
|
4
|
+
private _ctx?;
|
|
5
|
+
uuid: string | Promise<string>;
|
|
6
|
+
constructor(req: Request);
|
|
7
|
+
get request(): Record<string | symbol, any>;
|
|
8
|
+
put(record: Record<any, any>): void;
|
|
9
|
+
applyCtx(ctx: C): void;
|
|
10
|
+
get ctx(): C;
|
|
11
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { NestInterceptor, ExecutionContext, CallHandler } from "@nestjs/common";
|
|
2
|
+
import { Observable } from "rxjs";
|
|
3
|
+
import { DecafRequestContext } from "./DecafRequestContext.cjs";
|
|
4
|
+
export declare class DecafResponseInterceptor implements NestInterceptor {
|
|
5
|
+
protected ctx: DecafRequestContext;
|
|
6
|
+
constructor(ctx: DecafRequestContext);
|
|
7
|
+
intercept(context: ExecutionContext, next: CallHandler): Observable<any>;
|
|
8
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { NestInterceptor, ExecutionContext, CallHandler } from "@nestjs/common";
|
|
2
|
+
import { Observable } from "rxjs";
|
|
3
|
+
import { DecafRequestContext } from "./DecafRequestContext.js";
|
|
4
|
+
export declare class DecafResponseInterceptor implements NestInterceptor {
|
|
5
|
+
protected ctx: DecafRequestContext;
|
|
6
|
+
constructor(ctx: DecafRequestContext);
|
|
7
|
+
intercept(context: ExecutionContext, next: CallHandler): Observable<any>;
|
|
8
|
+
}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { Adapter, ConfigOf, ContextOf } from "@decaf-ts/core";
|
|
2
|
+
import { Constructor } from "@decaf-ts/decoration";
|
|
3
|
+
import { ExecutionContext, Type } from "@nestjs/common";
|
|
4
|
+
import { RequestToContextTransformer } from "./interceptors/context.cjs";
|
|
5
|
+
import { DecafRequestContext } from "./request/index.cjs";
|
|
6
|
+
export interface DecafRequestHandler<C extends DecafRequestContext = DecafRequestContext> {
|
|
7
|
+
handle(context: C, req: Request, res: Response): Promise<void>;
|
|
8
|
+
}
|
|
9
|
+
export interface ObserverEventsOptions {
|
|
10
|
+
/**
|
|
11
|
+
* Enables or disables SSE stream events globally
|
|
12
|
+
*/
|
|
13
|
+
enableObserverEvents?: boolean;
|
|
14
|
+
/**
|
|
15
|
+
* List of adapter flavours that will emit stream events
|
|
16
|
+
* If omitted, all registered flavours may be used
|
|
17
|
+
*/
|
|
18
|
+
observerFlavours?: any[];
|
|
19
|
+
/**
|
|
20
|
+
* SSE endpoint path
|
|
21
|
+
* @default "/events"
|
|
22
|
+
*/
|
|
23
|
+
observerApiPath?: string;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* @publicApi
|
|
27
|
+
*/
|
|
28
|
+
export type DecafModuleOptions<CONF = any, A extends Adapter<CONF, any, any, any> = Adapter<CONF, any, any, any>> = {
|
|
29
|
+
conf: [
|
|
30
|
+
Constructor<A>,
|
|
31
|
+
ConfigOf<A>,
|
|
32
|
+
...args: any[] | [
|
|
33
|
+
...any[],
|
|
34
|
+
(RequestToContextTransformer<ContextOf<A>> | Constructor<RequestToContextTransformer<ContextOf<A>>>)
|
|
35
|
+
]
|
|
36
|
+
][];
|
|
37
|
+
alias?: string;
|
|
38
|
+
autoControllers: boolean;
|
|
39
|
+
autoServices?: boolean;
|
|
40
|
+
observerOptions?: ObserverEventsOptions;
|
|
41
|
+
aggregations?: boolean;
|
|
42
|
+
handlers?: Type<DecafRequestHandler>[];
|
|
43
|
+
initialization?: () => Promise<void>;
|
|
44
|
+
};
|
|
45
|
+
/**
|
|
46
|
+
* Abstraction used by the {@link AuthInterceptor} to authorize decaf models.
|
|
47
|
+
*
|
|
48
|
+
* // costumauthHandler.ts
|
|
49
|
+
*
|
|
50
|
+
* @example
|
|
51
|
+
* export class CustomAuthHandler implements AuthHandler {
|
|
52
|
+
* async authorize(ctx: ExecutionContext, resource: string) {
|
|
53
|
+
* const req = ctx.switchToHttp().getRequest();
|
|
54
|
+
* const userRole = req.headers.authorization?.split(" ")[1] as string;
|
|
55
|
+
* if (!userRole) throw new AuthorizationError("Unauthenticated");
|
|
56
|
+
* const roles = Metadata.get(Model.get(resource)!, AuthRole);
|
|
57
|
+
* if (!roles.includes(userRole)) {
|
|
58
|
+
* throw new AuthorizationError("Unauthorized");
|
|
59
|
+
* }
|
|
60
|
+
* }
|
|
61
|
+
* }
|
|
62
|
+
*
|
|
63
|
+
* // auth.module.ts
|
|
64
|
+
*
|
|
65
|
+
* @Global()
|
|
66
|
+
* @Module({
|
|
67
|
+
* providers: [
|
|
68
|
+
* AuthInterceptor,
|
|
69
|
+
* CustomAuthHandler,
|
|
70
|
+
* {
|
|
71
|
+
* provide: AUTH_HANDLER,
|
|
72
|
+
* useClass: CustomAuthHandler, //swap this to use another provider
|
|
73
|
+
* },
|
|
74
|
+
* ],
|
|
75
|
+
* exports: [AUTH_HANDLER, AuthInterceptor],
|
|
76
|
+
* })
|
|
77
|
+
* export class AuthModule {}
|
|
78
|
+
*/
|
|
79
|
+
export interface AuthHandler {
|
|
80
|
+
/**
|
|
81
|
+
* Inspect the request context and ensure the caller can access the model.
|
|
82
|
+
* Implementations should throw an {@link AuthorizationError} on denial.
|
|
83
|
+
*
|
|
84
|
+
* @param ctx - Nest execution context that exposes the request/response.
|
|
85
|
+
* @param model - Model name or constructor being accessed.
|
|
86
|
+
*/
|
|
87
|
+
authorize(ctx: ExecutionContext, model: string | Constructor): Promise<void> | void;
|
|
88
|
+
}
|