@decaf-ts/for-nest 0.7.0 → 0.9.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/index.cjs +1 -1
- package/lib/esm/index.js +1 -1
- package/lib/types/controllers.d.cts +2 -2
- package/lib/types/controllers.d.mts +2 -2
- package/lib/types/core-module.d.cts +1 -1
- package/lib/types/core-module.d.mts +1 -1
- package/lib/types/decaf-model/DecafModelModule.d.cts +1 -1
- package/lib/types/decaf-model/DecafModelModule.d.mts +1 -1
- package/lib/types/decaf-model/FromModelController.d.cts +2 -2
- package/lib/types/decaf-model/FromModelController.d.mts +2 -2
- package/lib/types/decaf-model/decorators/ApiOperationFromModel.d.cts +1 -1
- package/lib/types/decaf-model/decorators/ApiOperationFromModel.d.mts +1 -1
- package/lib/types/decaf-model/decorators/ApiParamsFromModel.d.cts +1 -1
- package/lib/types/decaf-model/decorators/ApiParamsFromModel.d.mts +1 -1
- package/lib/types/decaf-model/decorators/DecafParams.d.cts +1 -1
- package/lib/types/decaf-model/decorators/DecafParams.d.mts +1 -1
- package/lib/types/decaf-model/decorators/index.d.cts +7 -7
- package/lib/types/decaf-model/decorators/index.d.mts +7 -7
- package/lib/types/decaf-model/decorators/utils.d.cts +1 -1
- package/lib/types/decaf-model/decorators/utils.d.mts +1 -1
- package/lib/types/decaf-model/index.d.cts +3 -3
- package/lib/types/decaf-model/index.d.mts +3 -3
- package/lib/types/decaf-model/types.d.cts +1 -1
- package/lib/types/decaf-model/types.d.mts +1 -1
- package/lib/types/decaf-model/utils.d.cts +3 -3
- package/lib/types/decaf-model/utils.d.mts +3 -3
- package/lib/types/events-module/EventsController.d.cts +3 -3
- package/lib/types/events-module/EventsController.d.mts +3 -3
- package/lib/types/events-module/index.d.cts +2 -2
- package/lib/types/events-module/index.d.mts +2 -2
- package/lib/types/factory/NestBootstraper.d.cts +2 -2
- package/lib/types/factory/NestBootstraper.d.mts +2 -2
- package/lib/types/factory/errors/index.d.cts +1 -1
- package/lib/types/factory/errors/index.d.mts +1 -1
- package/lib/types/factory/exceptions/index.d.cts +2 -2
- package/lib/types/factory/exceptions/index.d.mts +2 -2
- package/lib/types/factory/index.d.cts +4 -4
- package/lib/types/factory/index.d.mts +4 -4
- package/lib/types/factory/openapi/SwaggerBuilder.d.cts +1 -1
- package/lib/types/factory/openapi/SwaggerBuilder.d.mts +1 -1
- package/lib/types/factory/openapi/index.d.cts +2 -2
- package/lib/types/factory/openapi/index.d.mts +2 -2
- package/lib/types/index.d.cts +14 -14
- package/lib/types/index.d.mts +14 -14
- package/lib/types/interceptors/AuthInterceptor.d.cts +1 -1
- package/lib/types/interceptors/AuthInterceptor.d.mts +1 -1
- package/lib/types/interceptors/DecafRequestHandlerInterceptor.d.cts +2 -2
- package/lib/types/interceptors/DecafRequestHandlerInterceptor.d.mts +2 -2
- package/lib/types/interceptors/context.d.cts +1 -1
- package/lib/types/interceptors/context.d.mts +1 -1
- package/lib/types/interceptors/index.d.cts +3 -3
- package/lib/types/interceptors/index.d.mts +3 -3
- package/lib/types/module.d.cts +1 -1
- package/lib/types/module.d.mts +1 -1
- package/lib/types/overrides/Adapter.d.cts +1 -1
- package/lib/types/overrides/Adapter.d.mts +1 -1
- package/lib/types/overrides/index.d.cts +5 -5
- package/lib/types/overrides/index.d.mts +5 -5
- package/lib/types/ram/RamRequestTransformer.d.cts +1 -1
- package/lib/types/ram/RamRequestTransformer.d.mts +1 -1
- package/lib/types/ram/index.d.cts +1 -1
- package/lib/types/ram/index.d.mts +1 -1
- package/lib/types/request/DecafAuthHandler.d.cts +1 -1
- package/lib/types/request/DecafAuthHandler.d.mts +1 -1
- package/lib/types/request/DecafHandlerExecutor.d.cts +2 -2
- package/lib/types/request/DecafHandlerExecutor.d.mts +2 -2
- package/lib/types/request/DecafRequestContext.d.cts +1 -1
- package/lib/types/request/DecafRequestContext.d.mts +1 -1
- package/lib/types/request/DecafResponseInterceptor.d.cts +1 -1
- package/lib/types/request/DecafResponseInterceptor.d.mts +1 -1
- package/lib/types/request/index.d.cts +4 -4
- package/lib/types/request/index.d.mts +4 -4
- package/lib/types/types.d.cts +2 -2
- package/lib/types/types.d.mts +2 -2
- package/package.json +1 -1
- package/lib/types/bin/cli.d.ts +0 -1
- package/lib/types/cli-module.d.ts +0 -11
- package/lib/types/constants.d.ts +0 -15
- package/lib/types/controllers.d.ts +0 -22
- package/lib/types/core-module.d.ts +0 -17
- package/lib/types/decaf-model/DecafModelModule.d.ts +0 -9
- package/lib/types/decaf-model/FromModelController.d.ts +0 -61
- package/lib/types/decaf-model/decorators/ApiOperationFromModel.d.ts +0 -30
- package/lib/types/decaf-model/decorators/ApiParamsFromModel.d.ts +0 -13
- package/lib/types/decaf-model/decorators/DecafBody.d.ts +0 -5
- package/lib/types/decaf-model/decorators/DecafParams.d.ts +0 -9
- package/lib/types/decaf-model/decorators/decorators.d.ts +0 -29
- package/lib/types/decaf-model/decorators/index.d.ts +0 -7
- package/lib/types/decaf-model/decorators/types.d.ts +0 -23
- package/lib/types/decaf-model/decorators/utils.d.ts +0 -11
- package/lib/types/decaf-model/index.d.ts +0 -3
- package/lib/types/decaf-model/types.d.ts +0 -7
- package/lib/types/decaf-model/utils.d.ts +0 -10
- package/lib/types/decoration.d.ts +0 -1
- package/lib/types/events-module/DecafStreamModule.d.ts +0 -4
- package/lib/types/events-module/EventsController.d.ts +0 -11
- package/lib/types/events-module/constant.d.ts +0 -1
- package/lib/types/events-module/index.d.ts +0 -2
- package/lib/types/events-module/utils.d.ts +0 -1
- package/lib/types/factory/NestBootstraper.d.ts +0 -224
- package/lib/types/factory/errors/cors.d.ts +0 -4
- package/lib/types/factory/errors/index.d.ts +0 -1
- package/lib/types/factory/errors/throttling.d.ts +0 -4
- package/lib/types/factory/exceptions/DecafErrorFilter.d.ts +0 -4
- package/lib/types/factory/exceptions/decorators.d.ts +0 -2
- package/lib/types/factory/exceptions/index.d.ts +0 -2
- package/lib/types/factory/index.d.ts +0 -4
- package/lib/types/factory/openapi/DtoBuilder.d.ts +0 -25
- package/lib/types/factory/openapi/SwaggerBuilder.d.ts +0 -10
- package/lib/types/factory/openapi/SwaggerCustomUI.d.ts +0 -22
- package/lib/types/factory/openapi/constants.d.ts +0 -27
- package/lib/types/factory/openapi/index.d.ts +0 -2
- package/lib/types/index.d.ts +0 -43
- package/lib/types/interceptors/AuthInterceptor.d.ts +0 -10
- package/lib/types/interceptors/DecafRequestHandlerInterceptor.d.ts +0 -57
- package/lib/types/interceptors/context.d.ts +0 -6
- package/lib/types/interceptors/index.d.ts +0 -3
- package/lib/types/module.d.ts +0 -8
- package/lib/types/overrides/Adapter.d.ts +0 -13
- package/lib/types/overrides/ModelBuilderExtensions.d.ts +0 -8
- package/lib/types/overrides/constants.d.ts +0 -21
- package/lib/types/overrides/decoration.d.ts +0 -30
- package/lib/types/overrides/helpers.d.ts +0 -11
- package/lib/types/overrides/index.d.ts +0 -6
- package/lib/types/overrides/overrides.d.ts +0 -1
- package/lib/types/ram/RamRequestTransformer.d.ts +0 -5
- package/lib/types/ram/index.d.ts +0 -1
- package/lib/types/request/DecafAuthHandler.d.ts +0 -10
- package/lib/types/request/DecafHandlerExecutor.d.ts +0 -52
- package/lib/types/request/DecafRequestContext.d.ts +0 -11
- package/lib/types/request/DecafResponseInterceptor.d.ts +0 -8
- package/lib/types/request/index.d.ts +0 -4
- package/lib/types/types.d.ts +0 -88
- package/lib/types/utils.d.ts +0 -2
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import { DecafRequestContext } from "./DecafRequestContext";
|
|
2
|
-
import { type DecafRequestHandler } from "../types";
|
|
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
|
-
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { DecafServerCtx } from "../constants";
|
|
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
|
-
}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { NestInterceptor, ExecutionContext, CallHandler } from "@nestjs/common";
|
|
2
|
-
import { Observable } from "rxjs";
|
|
3
|
-
import { DecafRequestContext } from "./DecafRequestContext";
|
|
4
|
-
export declare class DecafResponseInterceptor implements NestInterceptor {
|
|
5
|
-
protected ctx: DecafRequestContext;
|
|
6
|
-
constructor(ctx: DecafRequestContext);
|
|
7
|
-
intercept(context: ExecutionContext, next: CallHandler): Observable<any>;
|
|
8
|
-
}
|
package/lib/types/types.d.ts
DELETED
|
@@ -1,88 +0,0 @@
|
|
|
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";
|
|
5
|
-
import { DecafRequestContext } from "./request/index";
|
|
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
|
-
}
|
package/lib/types/utils.d.ts
DELETED