@decaf-ts/for-nest 0.1.3 → 0.1.4

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.
Files changed (72) hide show
  1. package/README.md +1 -1
  2. package/dist/for-nest.cjs +1 -1
  3. package/dist/for-nest.cjs.map +1 -1
  4. package/dist/for-nest.js +1 -1
  5. package/dist/for-nest.js.map +1 -1
  6. package/lib/constants.cjs +3 -1
  7. package/lib/constants.d.ts +2 -0
  8. package/lib/constants.js.map +1 -1
  9. package/lib/decaf-model/DecafModelModule.cjs +22 -3
  10. package/lib/decaf-model/DecafModelModule.d.ts +3 -2
  11. package/lib/decaf-model/DecafModelModule.js.map +1 -1
  12. package/lib/decaf-model/FromModelController.cjs +69 -16
  13. package/lib/decaf-model/FromModelController.d.ts +49 -0
  14. package/lib/decaf-model/FromModelController.js.map +1 -1
  15. package/lib/esm/constants.d.ts +2 -0
  16. package/lib/esm/constants.js +2 -0
  17. package/lib/esm/constants.js.map +1 -1
  18. package/lib/esm/decaf-model/DecafModelModule.d.ts +3 -2
  19. package/lib/esm/decaf-model/DecafModelModule.js +22 -3
  20. package/lib/esm/decaf-model/DecafModelModule.js.map +1 -1
  21. package/lib/esm/decaf-model/FromModelController.d.ts +49 -0
  22. package/lib/esm/decaf-model/FromModelController.js +69 -16
  23. package/lib/esm/decaf-model/FromModelController.js.map +1 -1
  24. package/lib/esm/index.d.ts +2 -1
  25. package/lib/esm/index.js +2 -1
  26. package/lib/esm/index.js.map +1 -1
  27. package/lib/esm/interceptors/DecafRequestHandlerInterceptor.d.ts +53 -0
  28. package/lib/esm/interceptors/DecafRequestHandlerInterceptor.js +73 -0
  29. package/lib/esm/interceptors/DecafRequestHandlerInterceptor.js.map +1 -0
  30. package/lib/esm/interceptors/index.d.ts +1 -0
  31. package/lib/esm/interceptors/index.js +2 -0
  32. package/lib/esm/interceptors/index.js.map +1 -0
  33. package/lib/esm/module.js +1 -1
  34. package/lib/esm/module.js.map +1 -1
  35. package/lib/esm/request/DecafHandlerExecutor.d.ts +52 -0
  36. package/lib/esm/request/DecafHandlerExecutor.js +77 -0
  37. package/lib/esm/request/DecafHandlerExecutor.js.map +1 -0
  38. package/lib/esm/request/DecafRequestContext.d.ts +26 -0
  39. package/lib/esm/request/DecafRequestContext.js +44 -0
  40. package/lib/esm/request/DecafRequestContext.js.map +1 -0
  41. package/lib/esm/request/index.d.ts +2 -0
  42. package/lib/esm/request/index.js +3 -0
  43. package/lib/esm/request/index.js.map +1 -0
  44. package/lib/esm/types.d.ts +9 -0
  45. package/lib/index.cjs +2 -1
  46. package/lib/index.d.ts +2 -1
  47. package/lib/index.js.map +1 -1
  48. package/lib/interceptors/DecafRequestHandlerInterceptor.cjs +76 -0
  49. package/lib/interceptors/DecafRequestHandlerInterceptor.d.ts +53 -0
  50. package/lib/interceptors/DecafRequestHandlerInterceptor.js.map +1 -0
  51. package/lib/interceptors/index.cjs +18 -0
  52. package/lib/interceptors/index.d.ts +1 -0
  53. package/lib/interceptors/index.js.map +1 -0
  54. package/lib/module.cjs +1 -1
  55. package/lib/module.js.map +1 -1
  56. package/lib/request/DecafHandlerExecutor.cjs +80 -0
  57. package/lib/request/DecafHandlerExecutor.d.ts +52 -0
  58. package/lib/request/DecafHandlerExecutor.js.map +1 -0
  59. package/lib/request/DecafRequestContext.cjs +47 -0
  60. package/lib/request/DecafRequestContext.d.ts +26 -0
  61. package/lib/request/DecafRequestContext.js.map +1 -0
  62. package/lib/request/index.cjs +19 -0
  63. package/lib/request/index.d.ts +2 -0
  64. package/lib/request/index.js.map +1 -0
  65. package/lib/types.d.ts +9 -0
  66. package/package.json +1 -1
  67. package/lib/RepoFactory.cjs +0 -27
  68. package/lib/RepoFactory.d.ts +0 -6
  69. package/lib/RepoFactory.js.map +0 -1
  70. package/lib/esm/RepoFactory.d.ts +0 -6
  71. package/lib/esm/RepoFactory.js +0 -24
  72. package/lib/esm/RepoFactory.js.map +0 -1
@@ -0,0 +1,52 @@
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): Promise<void>;
52
+ }
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DecafHandlerExecutor.js","sourceRoot":"","sources":["../../src/request/DecafHandlerExecutor.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2CAA2D;AAC3D,mEAA4D;AAE5D,kDAA8C;AAE9C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2CG;AAEI,IAAM,oBAAoB,GAA1B,MAAM,oBAAoB;IAC/B,YAC2C,QAA+B,EACvD,OAA4B;QADJ,aAAQ,GAAR,QAAQ,CAAuB;QACvD,YAAO,GAAP,OAAO,CAAqB;IAC5C,CAAC;IAEJ,KAAK,CAAC,IAAI,CAAC,GAAY;QACrB,KAAK,MAAM,OAAO,IAAI,IAAI,CAAC,QAAQ,EAAE,CAAC;YACpC,MAAM,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC;QAC1C,CAAC;IACH,CAAC;CACF,CAAA;AAXY,oDAAoB;+BAApB,oBAAoB;IADhC,IAAA,mBAAU,EAAC,EAAE,KAAK,EAAE,cAAK,CAAC,OAAO,EAAE,CAAC;IAGhC,WAAA,IAAA,eAAM,EAAC,0BAAc,CAAC,CAAA;4CACG,yCAAmB;GAHpC,oBAAoB,CAWhC"}
@@ -0,0 +1,47 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.DecafRequestContext = void 0;
10
+ const common_1 = require("@nestjs/common");
11
+ /**
12
+ * @description
13
+ * Request-scoped context used to store arbitrary values for the duration of a single request.
14
+ *
15
+ * @summary
16
+ * The {@link DecafRequestContext} class provides an isolated per-request key-value cache,
17
+ * enabling services and controllers to share state or metadata without relying on global
18
+ * or static variables. Keys may be strings or symbols, and cached values may hold any
19
+ * serializable or non-serializable object.
20
+ *
21
+ * @class DecafRequestContext
22
+ *
23
+ * @example
24
+ * ```ts
25
+ * // Saving a value in the request context:
26
+ * context.set("tenantId", "abc123");
27
+ *
28
+ * // Retrieving it later in the request lifecycle:
29
+ * const tenantId = context.get<string>("tenantId");
30
+ * ```
31
+ */
32
+ let DecafRequestContext = class DecafRequestContext {
33
+ constructor() {
34
+ this.cache = new Map();
35
+ }
36
+ set(key, value) {
37
+ this.cache.set(key, value);
38
+ }
39
+ get(key) {
40
+ return this.cache.get(key);
41
+ }
42
+ };
43
+ exports.DecafRequestContext = DecafRequestContext;
44
+ exports.DecafRequestContext = DecafRequestContext = __decorate([
45
+ (0, common_1.Injectable)({ scope: common_1.Scope.REQUEST })
46
+ ], DecafRequestContext);
47
+ //# sourceMappingURL=DecafRequestContext.js.map
@@ -0,0 +1,26 @@
1
+ /**
2
+ * @description
3
+ * Request-scoped context used to store arbitrary values for the duration of a single request.
4
+ *
5
+ * @summary
6
+ * The {@link DecafRequestContext} class provides an isolated per-request key-value cache,
7
+ * enabling services and controllers to share state or metadata without relying on global
8
+ * or static variables. Keys may be strings or symbols, and cached values may hold any
9
+ * serializable or non-serializable object.
10
+ *
11
+ * @class DecafRequestContext
12
+ *
13
+ * @example
14
+ * ```ts
15
+ * // Saving a value in the request context:
16
+ * context.set("tenantId", "abc123");
17
+ *
18
+ * // Retrieving it later in the request lifecycle:
19
+ * const tenantId = context.get<string>("tenantId");
20
+ * ```
21
+ */
22
+ export declare class DecafRequestContext {
23
+ private cache;
24
+ set(key: string | symbol, value: any): void;
25
+ get<T = any>(key: string | symbol): T | undefined;
26
+ }
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DecafRequestContext.js","sourceRoot":"","sources":["../../src/request/DecafRequestContext.ts"],"names":[],"mappings":";;;;;;;;;AAAA,2CAAmD;AAEnD;;;;;;;;;;;;;;;;;;;;GAoBG;AAEI,IAAM,mBAAmB,GAAzB,MAAM,mBAAmB;IAAzB;QACG,UAAK,GAAG,IAAI,GAAG,EAAwB,CAAC;IASlD,CAAC;IAPC,GAAG,CAAC,GAAoB,EAAE,KAAU;QAClC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;IAC7B,CAAC;IAED,GAAG,CAAU,GAAoB;QAC/B,OAAO,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IAC7B,CAAC;CACF,CAAA;AAVY,kDAAmB;8BAAnB,mBAAmB;IAD/B,IAAA,mBAAU,EAAC,EAAE,KAAK,EAAE,cAAK,CAAC,OAAO,EAAE,CAAC;GACxB,mBAAmB,CAU/B"}
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./DecafRequestContext.cjs"), exports);
18
+ __exportStar(require("./DecafHandlerExecutor.cjs"), exports);
19
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,2 @@
1
+ export * from "./DecafRequestContext";
2
+ export * from "./DecafHandlerExecutor";
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/request/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,4DAAsC;AACtC,6DAAuC"}
package/lib/types.d.ts CHANGED
@@ -1,5 +1,13 @@
1
1
  import { Adapter } from "@decaf-ts/core";
2
2
  import { Constructor } from "@decaf-ts/decoration";
3
+ import { Type } from "@nestjs/common";
4
+ export interface RequestContextAccessor {
5
+ set(key: string | symbol, value: any): void;
6
+ get<T = any>(key: string | symbol): T | undefined;
7
+ }
8
+ export interface DecafRequestHandler {
9
+ handle(context: RequestContextAccessor, req: Request): Promise<void>;
10
+ }
3
11
  /**
4
12
  * @publicApi
5
13
  */
@@ -8,4 +16,5 @@ export type DecafModuleOptions<CONF = any, A extends Adapter<CONF, any, any, any
8
16
  conf: CONF;
9
17
  alias?: string;
10
18
  autoControllers: boolean;
19
+ handlers?: Type<DecafRequestHandler>[];
11
20
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@decaf-ts/for-nest",
3
- "version": "0.1.3",
3
+ "version": "0.1.4",
4
4
  "description": "NestJS decaf integration",
5
5
  "type": "module",
6
6
  "exports": {
@@ -1,27 +0,0 @@
1
- "use strict";
2
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
- return c > 3 && r && Object.defineProperty(target, key, r), r;
7
- };
8
- Object.defineProperty(exports, "__esModule", { value: true });
9
- exports.RepoFactory = void 0;
10
- const decorator_validation_1 = require("@decaf-ts/decorator-validation");
11
- const db_decorators_1 = require("@decaf-ts/db-decorators");
12
- const core_1 = require("@decaf-ts/core");
13
- const common_1 = require("@nestjs/common");
14
- let RepoFactory = class RepoFactory {
15
- for(model) {
16
- model = typeof model === "string" ? decorator_validation_1.Model.get(model) : model;
17
- if (!model) {
18
- throw new db_decorators_1.InternalError(`Failed to find repository for ${model}`);
19
- }
20
- return core_1.Repository.forModel(model);
21
- }
22
- };
23
- exports.RepoFactory = RepoFactory;
24
- exports.RepoFactory = RepoFactory = __decorate([
25
- (0, common_1.Injectable)()
26
- ], RepoFactory);
27
- //# sourceMappingURL=RepoFactory.js.map
@@ -1,6 +0,0 @@
1
- import { Model } from "@decaf-ts/decorator-validation";
2
- import { Repo } from "@decaf-ts/core";
3
- import { Constructor } from "@decaf-ts/decoration";
4
- export declare class RepoFactory {
5
- for<M extends Model>(model: string | Constructor<M>): Repo<M>;
6
- }
@@ -1 +0,0 @@
1
- {"version":3,"file":"RepoFactory.js","sourceRoot":"","sources":["../src/RepoFactory.ts"],"names":[],"mappings":";;;;;;;;;AAAA,yEAAuD;AACvD,2DAAwD;AACxD,yCAAkD;AAElD,2CAA4C;AAGrC,IAAM,WAAW,GAAjB,MAAM,WAAW;IACtB,GAAG,CAAkB,KAA8B;QACjD,KAAK,GAAG,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAE,4BAAK,CAAC,GAAG,CAAC,KAAK,CAAS,CAAC,CAAC,CAAC,KAAK,CAAC;QACtE,IAAI,CAAC,KAAK,EAAE,CAAC;YACX,MAAM,IAAI,6BAAa,CAAC,iCAAiC,KAAK,EAAE,CAAC,CAAC;QACpE,CAAC;QACD,OAAO,iBAAU,CAAC,QAAQ,CAAC,KAAuB,CAAC,CAAC;IACtD,CAAC;CACF,CAAA;AARY,kCAAW;sBAAX,WAAW;IADvB,IAAA,mBAAU,GAAE;GACA,WAAW,CAQvB"}
@@ -1,6 +0,0 @@
1
- import { Model } from "@decaf-ts/decorator-validation";
2
- import { Repo } from "@decaf-ts/core";
3
- import { Constructor } from "@decaf-ts/decoration";
4
- export declare class RepoFactory {
5
- for<M extends Model>(model: string | Constructor<M>): Repo<M>;
6
- }
@@ -1,24 +0,0 @@
1
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
- return c > 3 && r && Object.defineProperty(target, key, r), r;
6
- };
7
- import { Model } from "@decaf-ts/decorator-validation";
8
- import { InternalError } from "@decaf-ts/db-decorators";
9
- import { Repository } from "@decaf-ts/core";
10
- import { Injectable } from "@nestjs/common";
11
- let RepoFactory = class RepoFactory {
12
- for(model) {
13
- model = typeof model === "string" ? Model.get(model) : model;
14
- if (!model) {
15
- throw new InternalError(`Failed to find repository for ${model}`);
16
- }
17
- return Repository.forModel(model);
18
- }
19
- };
20
- RepoFactory = __decorate([
21
- Injectable()
22
- ], RepoFactory);
23
- export { RepoFactory };
24
- //# sourceMappingURL=RepoFactory.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"RepoFactory.js","sourceRoot":"","sources":["../../src/RepoFactory.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,gCAAgC,CAAC;AACvD,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AACxD,OAAO,EAAQ,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAElD,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAGrC,IAAM,WAAW,GAAjB,MAAM,WAAW;IACtB,GAAG,CAAkB,KAA8B;QACjD,KAAK,GAAG,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAE,KAAK,CAAC,GAAG,CAAC,KAAK,CAAS,CAAC,CAAC,CAAC,KAAK,CAAC;QACtE,IAAI,CAAC,KAAK,EAAE,CAAC;YACX,MAAM,IAAI,aAAa,CAAC,iCAAiC,KAAK,EAAE,CAAC,CAAC;QACpE,CAAC;QACD,OAAO,UAAU,CAAC,QAAQ,CAAC,KAAuB,CAAC,CAAC;IACtD,CAAC;CACF,CAAA;AARY,WAAW;IADvB,UAAU,EAAE;GACA,WAAW,CAQvB"}