@ddd-ts-kit/http 0.90.0 → 0.91.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.
Files changed (202) hide show
  1. package/README.fr.md +222 -2
  2. package/README.md +217 -1
  3. package/dist/error/refusal-codes-by-status.d.ts +11 -0
  4. package/dist/error/refusal-codes-by-status.d.ts.map +1 -0
  5. package/dist/error/refusal-codes-by-status.js +48 -0
  6. package/dist/error/refusal-codes-by-status.js.map +1 -0
  7. package/dist/nest/controllers/arguments-of.d.ts +7 -0
  8. package/dist/nest/controllers/arguments-of.d.ts.map +1 -0
  9. package/dist/nest/controllers/arguments-of.js +21 -0
  10. package/dist/nest/controllers/arguments-of.js.map +1 -0
  11. package/dist/nest/controllers/assert-not-routed-by-nest.d.ts +8 -0
  12. package/dist/nest/controllers/assert-not-routed-by-nest.d.ts.map +1 -0
  13. package/dist/nest/controllers/assert-not-routed-by-nest.js +19 -0
  14. package/dist/nest/controllers/assert-not-routed-by-nest.js.map +1 -0
  15. package/dist/nest/controllers/controllers-binder.d.ts +6 -0
  16. package/dist/nest/controllers/controllers-binder.d.ts.map +1 -0
  17. package/dist/nest/controllers/controllers-binder.js +5 -0
  18. package/dist/nest/controllers/controllers-binder.js.map +1 -0
  19. package/dist/nest/controllers/controllers-module-options.d.ts +8 -0
  20. package/dist/nest/controllers/controllers-module-options.d.ts.map +1 -0
  21. package/dist/nest/controllers/controllers-module-options.js +2 -0
  22. package/dist/nest/controllers/controllers-module-options.js.map +1 -0
  23. package/dist/nest/controllers/create-controllers-module.d.ts +10 -0
  24. package/dist/nest/controllers/create-controllers-module.d.ts.map +1 -0
  25. package/dist/nest/controllers/create-controllers-module.js +28 -0
  26. package/dist/nest/controllers/create-controllers-module.js.map +1 -0
  27. package/dist/nest/controllers/current-actor.d.ts +6 -0
  28. package/dist/nest/controllers/current-actor.d.ts.map +1 -0
  29. package/dist/nest/controllers/current-actor.js +9 -0
  30. package/dist/nest/controllers/current-actor.js.map +1 -0
  31. package/dist/nest/controllers/dto-type.d.ts +3 -0
  32. package/dist/nest/controllers/dto-type.d.ts.map +1 -0
  33. package/dist/nest/controllers/dto-type.js +2 -0
  34. package/dist/nest/controllers/dto-type.js.map +1 -0
  35. package/dist/nest/controllers/injected-parameter.d.ts +4 -0
  36. package/dist/nest/controllers/injected-parameter.d.ts.map +1 -0
  37. package/dist/nest/controllers/injected-parameter.js +17 -0
  38. package/dist/nest/controllers/injected-parameter.js.map +1 -0
  39. package/dist/nest/controllers/is-nest-controller.d.ts +4 -0
  40. package/dist/nest/controllers/is-nest-controller.d.ts.map +1 -0
  41. package/dist/nest/controllers/is-nest-controller.js +7 -0
  42. package/dist/nest/controllers/is-nest-controller.js.map +1 -0
  43. package/dist/nest/controllers/keyed-schema.d.ts +8 -0
  44. package/dist/nest/controllers/keyed-schema.d.ts.map +1 -0
  45. package/dist/nest/controllers/keyed-schema.js +33 -0
  46. package/dist/nest/controllers/keyed-schema.js.map +1 -0
  47. package/dist/nest/controllers/kit-route-spec.d.ts +47 -0
  48. package/dist/nest/controllers/kit-route-spec.d.ts.map +1 -0
  49. package/dist/nest/controllers/kit-route-spec.js +2 -0
  50. package/dist/nest/controllers/kit-route-spec.js.map +1 -0
  51. package/dist/nest/controllers/kit-route.d.ts +18 -0
  52. package/dist/nest/controllers/kit-route.d.ts.map +1 -0
  53. package/dist/nest/controllers/kit-route.js +29 -0
  54. package/dist/nest/controllers/kit-route.js.map +1 -0
  55. package/dist/nest/controllers/kit-routes-options.d.ts +15 -0
  56. package/dist/nest/controllers/kit-routes-options.d.ts.map +1 -0
  57. package/dist/nest/controllers/kit-routes-options.js +2 -0
  58. package/dist/nest/controllers/kit-routes-options.js.map +1 -0
  59. package/dist/nest/controllers/kit-routes.d.ts +5 -0
  60. package/dist/nest/controllers/kit-routes.d.ts.map +1 -0
  61. package/dist/nest/controllers/kit-routes.js +8 -0
  62. package/dist/nest/controllers/kit-routes.js.map +1 -0
  63. package/dist/nest/controllers/nest-controller-class.d.ts +3 -0
  64. package/dist/nest/controllers/nest-controller-class.d.ts.map +1 -0
  65. package/dist/nest/controllers/nest-controller-class.js +2 -0
  66. package/dist/nest/controllers/nest-controller-class.js.map +1 -0
  67. package/dist/nest/controllers/nest-controller-route.d.ts +6 -0
  68. package/dist/nest/controllers/nest-controller-route.d.ts.map +1 -0
  69. package/dist/nest/controllers/nest-controller-route.js +12 -0
  70. package/dist/nest/controllers/nest-controller-route.js.map +1 -0
  71. package/dist/nest/controllers/nest-controller-routes-options.d.ts +14 -0
  72. package/dist/nest/controllers/nest-controller-routes-options.d.ts.map +1 -0
  73. package/dist/nest/controllers/nest-controller-routes-options.js +2 -0
  74. package/dist/nest/controllers/nest-controller-routes-options.js.map +1 -0
  75. package/dist/nest/controllers/nest-controller-routes.d.ts +12 -0
  76. package/dist/nest/controllers/nest-controller-routes.d.ts.map +1 -0
  77. package/dist/nest/controllers/nest-controller-routes.js +142 -0
  78. package/dist/nest/controllers/nest-controller-routes.js.map +1 -0
  79. package/dist/nest/controllers/nest-controllers-options.d.ts +7 -0
  80. package/dist/nest/controllers/nest-controllers-options.d.ts.map +1 -0
  81. package/dist/nest/controllers/nest-controllers-options.js +2 -0
  82. package/dist/nest/controllers/nest-controllers-options.js.map +1 -0
  83. package/dist/nest/controllers/nest-controllers.d.ts +21 -0
  84. package/dist/nest/controllers/nest-controllers.d.ts.map +1 -0
  85. package/dist/nest/controllers/nest-controllers.js +31 -0
  86. package/dist/nest/controllers/nest-controllers.js.map +1 -0
  87. package/dist/nest/controllers/nest-method.d.ts +17 -0
  88. package/dist/nest/controllers/nest-method.d.ts.map +1 -0
  89. package/dist/nest/controllers/nest-method.js +2 -0
  90. package/dist/nest/controllers/nest-method.js.map +1 -0
  91. package/dist/nest/controllers/nest-parameter.d.ts +10 -0
  92. package/dist/nest/controllers/nest-parameter.d.ts.map +1 -0
  93. package/dist/nest/controllers/nest-parameter.js +2 -0
  94. package/dist/nest/controllers/nest-parameter.js.map +1 -0
  95. package/dist/nest/controllers/nest-route-metadata.d.ts +22 -0
  96. package/dist/nest/controllers/nest-route-metadata.d.ts.map +1 -0
  97. package/dist/nest/controllers/nest-route-metadata.js +121 -0
  98. package/dist/nest/controllers/nest-route-metadata.js.map +1 -0
  99. package/dist/nest/controllers/nest-route-methods.d.ts +4 -0
  100. package/dist/nest/controllers/nest-route-methods.d.ts.map +1 -0
  101. package/dist/nest/controllers/nest-route-methods.js +12 -0
  102. package/dist/nest/controllers/nest-route-methods.js.map +1 -0
  103. package/dist/nest/controllers/nest-routes-registry.d.ts +18 -0
  104. package/dist/nest/controllers/nest-routes-registry.d.ts.map +1 -0
  105. package/dist/nest/controllers/nest-routes-registry.js +23 -0
  106. package/dist/nest/controllers/nest-routes-registry.js.map +1 -0
  107. package/dist/nest/controllers/prototype-of.d.ts +4 -0
  108. package/dist/nest/controllers/prototype-of.d.ts.map +1 -0
  109. package/dist/nest/controllers/prototype-of.js +10 -0
  110. package/dist/nest/controllers/prototype-of.js.map +1 -0
  111. package/dist/nest/controllers/provide-controllers.d.ts +12 -0
  112. package/dist/nest/controllers/provide-controllers.d.ts.map +1 -0
  113. package/dist/nest/controllers/provide-controllers.js +33 -0
  114. package/dist/nest/controllers/provide-controllers.js.map +1 -0
  115. package/dist/nest/controllers/reflected-metadata.d.ts +3 -0
  116. package/dist/nest/controllers/reflected-metadata.d.ts.map +1 -0
  117. package/dist/nest/controllers/reflected-metadata.js +11 -0
  118. package/dist/nest/controllers/reflected-metadata.js.map +1 -0
  119. package/dist/nest/controllers/request-schemas-of.d.ts +13 -0
  120. package/dist/nest/controllers/request-schemas-of.d.ts.map +1 -0
  121. package/dist/nest/controllers/request-schemas-of.js +49 -0
  122. package/dist/nest/controllers/request-schemas-of.js.map +1 -0
  123. package/dist/nest/controllers/route-context.d.ts +3 -0
  124. package/dist/nest/controllers/route-context.d.ts.map +1 -0
  125. package/dist/nest/controllers/route-context.js +6 -0
  126. package/dist/nest/controllers/route-context.js.map +1 -0
  127. package/dist/nest/controllers/schema-of.d.ts +6 -0
  128. package/dist/nest/controllers/schema-of.d.ts.map +1 -0
  129. package/dist/nest/controllers/schema-of.js +12 -0
  130. package/dist/nest/controllers/schema-of.js.map +1 -0
  131. package/dist/nest/controllers/summary-of.d.ts +3 -0
  132. package/dist/nest/controllers/summary-of.d.ts.map +1 -0
  133. package/dist/nest/controllers/summary-of.js +6 -0
  134. package/dist/nest/controllers/summary-of.js.map +1 -0
  135. package/dist/nest/controllers/with-answers.d.ts +10 -0
  136. package/dist/nest/controllers/with-answers.d.ts.map +1 -0
  137. package/dist/nest/controllers/with-answers.js +11 -0
  138. package/dist/nest/controllers/with-answers.js.map +1 -0
  139. package/dist/nest.d.ts +18 -0
  140. package/dist/nest.d.ts.map +1 -1
  141. package/dist/nest.js +11 -0
  142. package/dist/nest.js.map +1 -1
  143. package/dist/openapi/responses.d.ts.map +1 -1
  144. package/dist/openapi/responses.js +2 -41
  145. package/dist/openapi/responses.js.map +1 -1
  146. package/dist/orpc/orpc-protocol.d.ts +7 -0
  147. package/dist/orpc/orpc-protocol.d.ts.map +1 -0
  148. package/dist/orpc/orpc-protocol.js +13 -0
  149. package/dist/orpc/orpc-protocol.js.map +1 -0
  150. package/dist/orpc/orpc-router.d.ts +22 -0
  151. package/dist/orpc/orpc-router.d.ts.map +1 -0
  152. package/dist/orpc/orpc-router.js +43 -0
  153. package/dist/orpc/orpc-router.js.map +1 -0
  154. package/dist/orpc.d.ts +4 -0
  155. package/dist/orpc.d.ts.map +1 -0
  156. package/dist/orpc.js +2 -0
  157. package/dist/orpc.js.map +1 -0
  158. package/dist/pipeline/primed.d.ts +2 -1
  159. package/dist/pipeline/primed.d.ts.map +1 -1
  160. package/dist/pipeline/primed.js +14 -11
  161. package/dist/pipeline/primed.js.map +1 -1
  162. package/dist/rpc/rpc-answer.d.ts +18 -0
  163. package/dist/rpc/rpc-answer.d.ts.map +1 -0
  164. package/dist/rpc/rpc-answer.js +61 -0
  165. package/dist/rpc/rpc-answer.js.map +1 -0
  166. package/dist/rpc/rpc-context.d.ts +15 -0
  167. package/dist/rpc/rpc-context.d.ts.map +1 -0
  168. package/dist/rpc/rpc-context.js +2 -0
  169. package/dist/rpc/rpc-context.js.map +1 -0
  170. package/dist/rpc/rpc-input.d.ts +11 -0
  171. package/dist/rpc/rpc-input.d.ts.map +1 -0
  172. package/dist/rpc/rpc-input.js +2 -0
  173. package/dist/rpc/rpc-input.js.map +1 -0
  174. package/dist/rpc/rpc-refusal.d.ts +14 -0
  175. package/dist/rpc/rpc-refusal.d.ts.map +1 -0
  176. package/dist/rpc/rpc-refusal.js +2 -0
  177. package/dist/rpc/rpc-refusal.js.map +1 -0
  178. package/dist/rpc/rpc-request.d.ts +9 -0
  179. package/dist/rpc/rpc-request.d.ts.map +1 -0
  180. package/dist/rpc/rpc-request.js +28 -0
  181. package/dist/rpc/rpc-request.js.map +1 -0
  182. package/dist/trpc/route-refusal.d.ts +8 -0
  183. package/dist/trpc/route-refusal.d.ts.map +1 -0
  184. package/dist/trpc/route-refusal.js +10 -0
  185. package/dist/trpc/route-refusal.js.map +1 -0
  186. package/dist/trpc/trpc-error-shape.d.ts +17 -0
  187. package/dist/trpc/trpc-error-shape.d.ts.map +1 -0
  188. package/dist/trpc/trpc-error-shape.js +2 -0
  189. package/dist/trpc/trpc-error-shape.js.map +1 -0
  190. package/dist/trpc/trpc-protocol.d.ts +8 -0
  191. package/dist/trpc/trpc-protocol.d.ts.map +1 -0
  192. package/dist/trpc/trpc-protocol.js +43 -0
  193. package/dist/trpc/trpc-protocol.js.map +1 -0
  194. package/dist/trpc/trpc-router.d.ts +38 -0
  195. package/dist/trpc/trpc-router.d.ts.map +1 -0
  196. package/dist/trpc/trpc-router.js +44 -0
  197. package/dist/trpc/trpc-router.js.map +1 -0
  198. package/dist/trpc.d.ts +5 -0
  199. package/dist/trpc.d.ts.map +1 -0
  200. package/dist/trpc.js +2 -0
  201. package/dist/trpc.js.map +1 -0
  202. package/package.json +30 -7
@@ -0,0 +1,142 @@
1
+ import { DeclarationError } from '@ddd-ts-kit/kernel/declarations';
2
+ import { controllerRoutes } from '../../controller/controller-routes.js';
3
+ import { presentationRegistry } from '../../controller/presentation-registry.js';
4
+ import { argumentsOf } from './arguments-of.js';
5
+ import { isNestController } from './is-nest-controller.js';
6
+ import { nestRouteMetadata } from './nest-route-metadata.js';
7
+ import { nestRouteMethods } from './nest-route-methods.js';
8
+ import { nestRoutesRegistry } from './nest-routes-registry.js';
9
+ import { prototypeOf } from './prototype-of.js';
10
+ import { requestSchemasOf } from './request-schemas-of.js';
11
+ import { schemaOf } from './schema-of.js';
12
+ import { summaryOf } from './summary-of.js';
13
+ /**
14
+ * The routes of Nest controllers whose methods carry `@KitRoute`, for any adapter of the kit and
15
+ * for the contract generator: each method becomes one route of the kit, its method, path,
16
+ * parameters and status read from Nest's decorators, the rest from `@KitRoute` and `@KitRoutes`.
17
+ * It is served as every controller of the kit is, guards, validation and problem documents
18
+ * included; the instance that answers is the one Nest's container builds (`instanceOf`).
19
+ */
20
+ export function nestControllerRoutes(controllers, options = {}) {
21
+ const entries = controllers.flatMap((controller) => routesOf(controller, options));
22
+ return controllerRoutes(entries, {
23
+ ...(options.resolve === undefined ? {} : { resolve: options.resolve }),
24
+ ...(options.security === undefined ? {} : { security: options.security }),
25
+ });
26
+ }
27
+ function routesOf(controller, options) {
28
+ if (!isNestController(controller)) {
29
+ throw new DeclarationError(`${controller.name} is served as a Nest controller and carries no @Controller of Nest.`);
30
+ }
31
+ const prototype = prototypeOf(controller);
32
+ const declared = nestRoutesRegistry().routes.get(prototype) ?? new Map();
33
+ const names = [...new Set([...nestRouteMethods(controller), ...declared.keys()])];
34
+ if (names.length === 0) {
35
+ throw new DeclarationError(`${controller.name} is served by the kit and no method carries a route decorator of Nest.`);
36
+ }
37
+ const answering = lazyInstance(controller, options);
38
+ const injected = nestRoutesRegistry().injected.get(prototype);
39
+ return names.map((name) => {
40
+ const written = declared.get(name) ?? {};
41
+ const method = {
42
+ controller,
43
+ name,
44
+ where: `${controller.name}.${name}`,
45
+ spec: { ...written, operationId: written.operationId ?? name, summary: written.summary ?? summaryOf(name) },
46
+ read: nestRouteMetadata(controller, name),
47
+ injected: injected?.get(name) ?? new Map(),
48
+ };
49
+ return synthetic(method, specOf(method, options), answering);
50
+ });
51
+ }
52
+ /**
53
+ * One controller of the kit per method: a class of its own, registered with its declaration, whose
54
+ * `handle` calls the method with what its parameters ask for.
55
+ */
56
+ function synthetic(method, spec, answering) {
57
+ const { where, name } = method;
58
+ class Answer {
59
+ async handle(request) {
60
+ const instance = answering();
61
+ const handler = Reflect.get(instance, name);
62
+ if (typeof handler !== 'function') {
63
+ throw new DeclarationError(`What Nest built for ${method.controller.name} has no method ${name}.`);
64
+ }
65
+ const answer = await Reflect.apply(handler, instance, argumentsOf(method, request));
66
+ if (answer !== undefined && spec.response.body === undefined) {
67
+ throw new DeclarationError(`${where} returned a value and @KitRoute declares no response.body: the kit would answer it empty. Declare the body the route answers, or return nothing.`);
68
+ }
69
+ return answer;
70
+ }
71
+ }
72
+ // The messages of the kit name the controller of a route by its class.
73
+ Object.defineProperty(Answer, 'name', { value: where });
74
+ presentationRegistry().controllers.set(Answer, spec);
75
+ return new Answer();
76
+ }
77
+ /** The declaration of the controller of the kit: Nest's method, path and status, the rest of @KitRoute over @KitRoutes. */
78
+ function specOf(method, options) {
79
+ const { read, spec } = method;
80
+ const shared = nestRoutesRegistry().controllers.get(method.controller) ?? {};
81
+ const { response = {}, request, guards = [], tags = [], errors = [], ...declared } = spec;
82
+ return {
83
+ ...declared,
84
+ ...requestSchemasOf(method, options),
85
+ ...(shared.group === undefined ? {} : { group: shared.group }),
86
+ method: read.method,
87
+ path: `/${read.path}`,
88
+ tags: [...(shared.tags ?? []), ...tags],
89
+ guards: [...(shared.guards ?? []), ...guards],
90
+ errors: [...(shared.errors ?? []), ...errors],
91
+ response: responseOf(method, response, options),
92
+ };
93
+ }
94
+ function responseOf(method, response, options) {
95
+ const { where, read } = method;
96
+ const status = response.status ?? read.httpCode ?? (read.method === 'POST' ? 201 : 200);
97
+ const body = bodyOf(method, response);
98
+ return {
99
+ status,
100
+ ...(response.description === undefined ? {} : { description: response.description }),
101
+ ...(body === undefined ? {} : { body: schemaOf(where, body, options) }),
102
+ };
103
+ }
104
+ /**
105
+ * The body the route answers: the one `@KitRoute` declares, else the one its signature names as
106
+ * `ddd-ts-kit` read it (`withAnswers`). A method TypeScript recorded as answering a value with
107
+ * neither is refused, never answered empty.
108
+ */
109
+ function bodyOf(method, response) {
110
+ const signed = nestRoutesRegistry().answers.get(method.controller)?.get(method.name);
111
+ const body = response.body ?? signed ?? undefined;
112
+ if (body === undefined && signed !== null && answersAValue(method.read.returnType)) {
113
+ throw new DeclarationError(`${method.where} returns ${describedType(method.read.returnType)} and @KitRoute declares no response.body: the kit would answer it empty. Declare the body the route answers, or return nothing.`);
114
+ }
115
+ return body;
116
+ }
117
+ /**
118
+ * Whether the type TypeScript recorded says the method answers something: `void` is recorded as
119
+ * nothing, and a `Promise` says nothing of what it holds, which the call then checks.
120
+ */
121
+ function answersAValue(returnType) {
122
+ return returnType !== undefined && returnType !== Promise;
123
+ }
124
+ function describedType(returnType) {
125
+ return typeof returnType === 'function' && returnType.name !== '' ? returnType.name : 'a value';
126
+ }
127
+ /** The instance Nest's container built, asked once at the first call. */
128
+ function lazyInstance(controller, options) {
129
+ let instance;
130
+ return () => {
131
+ instance ??= built(controller, options);
132
+ return instance;
133
+ };
134
+ }
135
+ function built(controller, options) {
136
+ const instance = options.instanceOf?.(controller);
137
+ if (typeof instance !== 'object' || instance === null) {
138
+ throw new DeclarationError(`${controller.name} is called and nothing builds it: serve it through createControllersModule, or give instanceOf.`);
139
+ }
140
+ return instance;
141
+ }
142
+ //# sourceMappingURL=nest-controller-routes.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"nest-controller-routes.js","sourceRoot":"","sources":["../../../src/nest/controllers/nest-controller-routes.ts"],"names":[],"mappings":"AACA,OAA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,KAAK,SAAS,IAAI,UAAU,KAAK,OAAO,CAAC;AAC5D,CAAC;AAED,SAAS,aAAa,CAAC,UAAmB;IACxC,OAAO,OAAO,UAAU,KAAK,UAAU,IAAI,UAAU,CAAC,IAAI,KAAK,EAAE,CAAC,CAAC,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC;AAClG,CAAC;AAED,yEAAyE;AACzE,SAAS,YAAY,CAAC,UAA+B,EAAE,OAAoC;IACzF,IAAI,QAA4B,CAAC;IAEjC,OAAO,GAAG,EAAE;QACV,QAAQ,KAAK,KAAK,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC;QAExC,OAAO,QAAQ,CAAC;IAClB,CAAC,CAAC;AACJ,CAAC;AAED,SAAS,KAAK,CAAC,UAA+B,EAAE,OAAoC;IAClF,MAAM,QAAQ,GAAG,OAAO,CAAC,UAAU,EAAE,CAAC,UAAU,CAAC,CAAC;IAElD,IAAI,OAAO,QAAQ,KAAK,QAAQ,IAAI,QAAQ,KAAK,IAAI,EAAE,CAAC;QACtD,MAAM,IAAI,gBAAgB,CACxB,GAAG,UAAU,CAAC,IAAI,iGAAiG,CACpH,CAAC;IACJ,CAAC;IAED,OAAO,QAAQ,CAAC;AAClB,CAAC"}
@@ -0,0 +1,7 @@
1
+ import type { Provider } from '@nestjs/common';
2
+ import type { NestControllerRoutesOptions } from './nest-controller-routes-options.js';
3
+ export interface NestControllersOptions extends Pick<NestControllerRoutesOptions, 'schemaOfClass' | 'security'> {
4
+ /** What the controllers inject, as Nest providers: the buses of the application, `{ provide: CommandBus, useValue: commands }`. */
5
+ readonly providers?: readonly Provider[];
6
+ }
7
+ //# sourceMappingURL=nest-controllers-options.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"nest-controllers-options.d.ts","sourceRoot":"","sources":["../../../src/nest/controllers/nest-controllers-options.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC/C,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,kCAAkC,CAAC;AAEpF,MAAM,WAAW,sBAAuB,SAAQ,IAAI,CAAC,2BAA2B,EAAE,eAAe,GAAG,UAAU,CAAC;IAC7G,mIAAmI;IACnI,QAAQ,CAAC,SAAS,CAAC,EAAE,SAAS,QAAQ,EAAE,CAAC;CAC1C"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=nest-controllers-options.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"nest-controllers-options.js","sourceRoot":"","sources":["../../../src/nest/controllers/nest-controllers-options.ts"],"names":[],"mappings":""}
@@ -0,0 +1,21 @@
1
+ import type { Provider, Type } from '@nestjs/common';
2
+ import type { ModuleRef } from '@nestjs/core';
3
+ import type { Route } from '../../route/route.js';
4
+ import type { NestControllersOptions } from './nest-controllers-options.js';
5
+ /** The Nest controllers of an application, their routes built now and their instances built by Nest at its start. */
6
+ export interface NestControllers {
7
+ readonly controllers: readonly Type<unknown>[];
8
+ readonly providers: readonly Provider[];
9
+ /** For the server, the contract and the procedures, as every route of the application. */
10
+ readonly routes: readonly Route[];
11
+ /** Hands the routes the instances Nest's container built: `provideControllers` calls it at the start. */
12
+ bind(references: ModuleRef): void;
13
+ }
14
+ /**
15
+ * The routes of Nest controllers, built before Nest starts, for an application that composes its
16
+ * routes itself: they join its other routes, and `provideControllers` lets Nest build each
17
+ * controller with what it injects. A guard a route names is a value here (`Authenticated`,
18
+ * `HasRole(...)`): one given as a class is built by `createControllersModule`.
19
+ */
20
+ export declare function nestControllers(controllers: readonly Type<unknown>[], options?: NestControllersOptions): NestControllers;
21
+ //# sourceMappingURL=nest-controllers.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"nest-controllers.d.ts","sourceRoot":"","sources":["../../../src/nest/controllers/nest-controllers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,gBAAgB,CAAC;AACrD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAE9C,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAC/C,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,4BAA4B,CAAC;AAGzE,qHAAqH;AACrH,MAAM,WAAW,eAAe;IAC9B,QAAQ,CAAC,WAAW,EAAE,SAAS,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC;IAC/C,QAAQ,CAAC,SAAS,EAAE,SAAS,QAAQ,EAAE,CAAC;IACxC,0FAA0F;IAC1F,QAAQ,CAAC,MAAM,EAAE,SAAS,KAAK,EAAE,CAAC;IAClC,yGAAyG;IACzG,IAAI,CAAC,UAAU,EAAE,SAAS,GAAG,IAAI,CAAC;CACnC;AAED;;;;;GAKG;AACH,wBAAgB,eAAe,CAC7B,WAAW,EAAE,SAAS,IAAI,CAAC,OAAO,CAAC,EAAE,EACrC,OAAO,GAAE,sBAA2B,GACnC,eAAe,CA0BjB"}
@@ -0,0 +1,31 @@
1
+ import { DeclarationError } from '@ddd-ts-kit/kernel/declarations';
2
+ import { nestControllerRoutes } from './nest-controller-routes.js';
3
+ /**
4
+ * The routes of Nest controllers, built before Nest starts, for an application that composes its
5
+ * routes itself: they join its other routes, and `provideControllers` lets Nest build each
6
+ * controller with what it injects. A guard a route names is a value here (`Authenticated`,
7
+ * `HasRole(...)`): one given as a class is built by `createControllersModule`.
8
+ */
9
+ export function nestControllers(controllers, options = {}) {
10
+ const { providers = [], schemaOfClass, security } = options;
11
+ let references;
12
+ const routes = nestControllerRoutes(controllers, {
13
+ instanceOf: (controller) => {
14
+ if (references === undefined) {
15
+ throw new DeclarationError(`${controller.name} is called before Nest started: give the controllers to provideControllers in the Nest application.`);
16
+ }
17
+ return references.get(controller, { strict: false });
18
+ },
19
+ ...(schemaOfClass === undefined ? {} : { schemaOfClass }),
20
+ ...(security === undefined ? {} : { security }),
21
+ });
22
+ return {
23
+ controllers,
24
+ providers,
25
+ routes,
26
+ bind: (built) => {
27
+ references = built;
28
+ },
29
+ };
30
+ }
31
+ //# sourceMappingURL=nest-controllers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"nest-controllers.js","sourceRoot":"","sources":["../../../src/nest/controllers/nest-controllers.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,gBAAgB,EAAE,MAAM,iCAAiC,CAAC;AAGnE,OAAO,EAAE,oBAAoB,EAAE,MAAM,0BAA0B,CAAC;AAYhE;;;;;GAKG;AACH,MAAM,UAAU,eAAe,CAC7B,WAAqC,EACrC,OAAO,GAA2B,EAAE;IAEpC,MAAM,EAAE,SAAS,GAAG,EAAE,EAAE,aAAa,EAAE,QAAQ,EAAE,GAAG,OAAO,CAAC;IAC5D,IAAI,UAAiC,CAAC;IAEtC,MAAM,MAAM,GAAG,oBAAoB,CAAC,WAAW,EAAE;QAC/C,UAAU,EAAE,CAAC,UAAU,EAAE,EAAE;YACzB,IAAI,UAAU,KAAK,SAAS,EAAE,CAAC;gBAC7B,MAAM,IAAI,gBAAgB,CACxB,GAAG,UAAU,CAAC,IAAI,qGAAqG,CACxH,CAAC;YACJ,CAAC;YAED,OAAO,UAAU,CAAC,GAAG,CAAC,UAAU,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,CAAC;QACvD,CAAC;QACD,GAAG,CAAC,aAAa,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,aAAa,EAAE,CAAC;QACzD,GAAG,CAAC,QAAQ,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,QAAQ,EAAE,CAAC;KAChD,CAAC,CAAC;IAEH,OAAO;QACL,WAAW;QACX,SAAS;QACT,MAAM;QACN,IAAI,EAAE,CAAC,KAAK,EAAE,EAAE;YACd,UAAU,GAAG,KAAK,CAAC;QACrB,CAAC;KACF,CAAC;AACJ,CAAC"}
@@ -0,0 +1,17 @@
1
+ import type { KitRouteSpec } from './kit-route-spec.js';
2
+ import type { NestControllerClass } from './nest-controller-class.js';
3
+ import type { NestRouteMetadata } from './nest-route-metadata.js';
4
+ import type { Injected } from './nest-routes-registry.js';
5
+ /** One method of a Nest controller the kit serves: what Nest's decorators say, and what the kit's say. */
6
+ export interface NestMethod {
7
+ readonly controller: NestControllerClass;
8
+ readonly name: string;
9
+ /** `InvoicesController.issue`, for the messages. */
10
+ readonly where: string;
11
+ /** What @KitRoute says, its name and its summary given when it said none. */
12
+ readonly spec: KitRouteSpec & Required<Pick<KitRouteSpec, 'operationId' | 'summary'>>;
13
+ readonly read: NestRouteMetadata;
14
+ /** By index, what a parameter decorator of the kit asks for. */
15
+ readonly injected: ReadonlyMap<number, Injected>;
16
+ }
17
+ //# sourceMappingURL=nest-method.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"nest-method.d.ts","sourceRoot":"","sources":["../../../src/nest/controllers/nest-method.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AACrD,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAC;AACnE,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAC/D,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AAEvD,0GAA0G;AAC1G,MAAM,WAAW,UAAU;IACzB,QAAQ,CAAC,UAAU,EAAE,mBAAmB,CAAC;IACzC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,oDAAoD;IACpD,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,6EAA6E;IAC7E,QAAQ,CAAC,IAAI,EAAE,YAAY,GAAG,QAAQ,CAAC,IAAI,CAAC,YAAY,EAAE,aAAa,GAAG,SAAS,CAAC,CAAC,CAAC;IACtF,QAAQ,CAAC,IAAI,EAAE,iBAAiB,CAAC;IACjC,gEAAgE;IAChE,QAAQ,CAAC,QAAQ,EAAE,WAAW,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;CAClD"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=nest-method.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"nest-method.js","sourceRoot":"","sources":["../../../src/nest/controllers/nest-method.ts"],"names":[],"mappings":""}
@@ -0,0 +1,10 @@
1
+ /** One parameter of a method of a Nest controller, read from Nest's `@Body`, `@Query`, `@Param` or `@Headers`. */
2
+ export interface NestParameter {
3
+ readonly index: number;
4
+ readonly source: 'body' | 'query' | 'params' | 'headers';
5
+ /** The name it reads, as `@Param('invoiceId')` gives it; left out, the whole part. */
6
+ readonly key?: string;
7
+ /** The class TypeScript recorded for it, with `emitDecoratorMetadata`. */
8
+ readonly type: unknown;
9
+ }
10
+ //# sourceMappingURL=nest-parameter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"nest-parameter.d.ts","sourceRoot":"","sources":["../../../src/nest/controllers/nest-parameter.ts"],"names":[],"mappings":"AAAA,kHAAkH;AAClH,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,GAAG,QAAQ,GAAG,SAAS,CAAC;IACzD,sFAAsF;IACtF,QAAQ,CAAC,GAAG,CAAC,EAAE,MAAM,CAAC;IACtB,0EAA0E;IAC1E,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC;CACxB"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=nest-parameter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"nest-parameter.js","sourceRoot":"","sources":["../../../src/nest/controllers/nest-parameter.ts"],"names":[],"mappings":""}
@@ -0,0 +1,22 @@
1
+ import type { HttpMethod } from '../../route/http-method.js';
2
+ import type { NestControllerClass } from './nest-controller-class.js';
3
+ import type { NestParameter } from './nest-parameter.js';
4
+ /**
5
+ * What the decorators of Nest wrote on a controller and its methods, read in this file alone. The
6
+ * keys are those `@nestjs/common/constants` exports, which Nest's own router reads; their shape is
7
+ * checked on each read, so that a release of Nest that changes it stops the start with a message
8
+ * instead of serving a route read wrong (`test/nest-metadata-contract.spec.ts` holds it on the
9
+ * installed Nest).
10
+ */
11
+ export interface NestRouteMetadata {
12
+ readonly method: HttpMethod;
13
+ /** The path of the controller and of the method, as Nest joins them: `invoices/:invoiceId/issue`. */
14
+ readonly path: string;
15
+ readonly httpCode: number | undefined;
16
+ readonly parameters: readonly NestParameter[];
17
+ /** What TypeScript recorded the method returns, with `emitDecoratorMetadata`: `undefined` for `void` or without it. */
18
+ readonly returnType: unknown;
19
+ }
20
+ /** The route Nest's decorators declare on one method of a controller. */
21
+ export declare function nestRouteMetadata(controller: NestControllerClass, method: string): NestRouteMetadata;
22
+ //# sourceMappingURL=nest-route-metadata.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"nest-route-metadata.d.ts","sourceRoot":"","sources":["../../../src/nest/controllers/nest-route-metadata.ts"],"names":[],"mappings":"AAmBA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAI1D,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAC;AACnE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAEtD;;;;;;GAMG;AACH,MAAM,WAAW,iBAAiB;IAChC,QAAQ,CAAC,MAAM,EAAE,UAAU,CAAC;IAC5B,qGAAqG;IACrG,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,QAAQ,EAAE,MAAM,GAAG,SAAS,CAAC;IACtC,QAAQ,CAAC,UAAU,EAAE,SAAS,aAAa,EAAE,CAAC;IAC9C,uHAAuH;IACvH,QAAQ,CAAC,UAAU,EAAE,OAAO,CAAC;CAC9B;AAmCD,yEAAyE;AACzE,wBAAgB,iBAAiB,CAAC,UAAU,EAAE,mBAAmB,EAAE,MAAM,EAAE,MAAM,GAAG,iBAAiB,CAmBpG"}
@@ -0,0 +1,121 @@
1
+ import { DeclarationError } from '@ddd-ts-kit/kernel/declarations';
2
+ import { RequestMethod } from '@nestjs/common';
3
+ import { EXCEPTION_FILTERS_METADATA, GUARDS_METADATA, HEADERS_METADATA, HTTP_CODE_METADATA, INTERCEPTORS_METADATA, METHOD_METADATA, PARAMTYPES_METADATA, PATH_METADATA, PIPES_METADATA, REDIRECT_METADATA, RENDER_METADATA, ROUTE_ARGS_METADATA, SSE_METADATA, VERSION_METADATA, } from '@nestjs/common/constants';
4
+ import { RouteParamtypes } from '@nestjs/common/enums/route-paramtypes.enum';
5
+ import { isRecord } from '../../support/is-record.js';
6
+ import { prototypeOf } from './prototype-of.js';
7
+ import { reflectedMetadata as metadata } from './reflected-metadata.js';
8
+ /** Written by TypeScript itself under `emitDecoratorMetadata`, next to `design:paramtypes`. */
9
+ const RETURN_TYPE_METADATA = 'design:returntype';
10
+ const METHODS = new Map([
11
+ [RequestMethod.GET, 'GET'],
12
+ [RequestMethod.POST, 'POST'],
13
+ [RequestMethod.PUT, 'PUT'],
14
+ [RequestMethod.PATCH, 'PATCH'],
15
+ [RequestMethod.DELETE, 'DELETE'],
16
+ [RequestMethod.HEAD, 'HEAD'],
17
+ [RequestMethod.OPTIONS, 'OPTIONS'],
18
+ ]);
19
+ const SOURCES = new Map([
20
+ [RouteParamtypes.BODY, 'body'],
21
+ [RouteParamtypes.QUERY, 'query'],
22
+ [RouteParamtypes.PARAM, 'params'],
23
+ [RouteParamtypes.HEADERS, 'headers'],
24
+ ]);
25
+ /** Nest features the pipeline of the kit does not run: a route that declares one would silently lose it. */
26
+ const NOT_RUN = [
27
+ [GUARDS_METADATA, '@UseGuards: name the guards of the kit in `guards` of @KitRoute or @KitRoutes'],
28
+ [PIPES_METADATA, '@UsePipes: the schemas of the route validate its input'],
29
+ [INTERCEPTORS_METADATA, '@UseInterceptors: a bus middleware or an aspect does that work'],
30
+ [EXCEPTION_FILTERS_METADATA, '@UseFilters: the error mapper answers every refusal'],
31
+ [HEADERS_METADATA, '@Header: a route of the kit declares its answer, its cache headers in `cache`'],
32
+ [REDIRECT_METADATA, '@Redirect'],
33
+ [RENDER_METADATA, '@Render'],
34
+ [SSE_METADATA, '@Sse'],
35
+ [VERSION_METADATA, '@Version: give the version in the path'],
36
+ ];
37
+ /** The route Nest's decorators declare on one method of a controller. */
38
+ export function nestRouteMetadata(controller, method) {
39
+ const where = `${controller.name}.${method}`;
40
+ const handler = Reflect.get(prototypeOf(controller), method);
41
+ if (typeof handler !== 'function') {
42
+ throw new DeclarationError(`${where} carries @KitRoute and is no method.`);
43
+ }
44
+ assertNothingNotRun(where, [controller, handler]);
45
+ return {
46
+ method: methodOf(where, metadata(METHOD_METADATA, handler)),
47
+ path: [pathOf(where, metadata(PATH_METADATA, controller)), pathOf(where, metadata(PATH_METADATA, handler))]
48
+ .filter((part) => part !== '')
49
+ .join('/'),
50
+ httpCode: httpCodeOf(where, metadata(HTTP_CODE_METADATA, handler)),
51
+ parameters: parametersOf(where, controller, method),
52
+ returnType: metadata(RETURN_TYPE_METADATA, prototypeOf(controller), method),
53
+ };
54
+ }
55
+ function assertNothingNotRun(where, targets) {
56
+ for (const [key, feature] of NOT_RUN) {
57
+ const declared = targets.map((target) => metadata(key, target));
58
+ if (declared.some((value) => value !== undefined && !(Array.isArray(value) && value.length === 0))) {
59
+ throw new DeclarationError(`${where} declares ${feature}. The kit serves the route through its own pipeline, where Nest's does not run.`);
60
+ }
61
+ }
62
+ }
63
+ function methodOf(where, value) {
64
+ const method = typeof value === 'number' ? METHODS.get(value) : undefined;
65
+ if (method === undefined) {
66
+ throw new DeclarationError(`${where} carries @KitRoute and no @Get, @Post, @Put, @Patch, @Delete, @Head or @Options of Nest that the kit reads.`);
67
+ }
68
+ return method;
69
+ }
70
+ function pathOf(where, value) {
71
+ if (value === undefined) {
72
+ return '';
73
+ }
74
+ if (typeof value !== 'string') {
75
+ throw new DeclarationError(`${where}: a route of the kit has one path, and Nest declares several.`);
76
+ }
77
+ return value.replace(/^\/+|\/+$/g, '');
78
+ }
79
+ function httpCodeOf(where, value) {
80
+ if (value === undefined || (typeof value === 'number' && Number.isInteger(value))) {
81
+ return value;
82
+ }
83
+ throw new DeclarationError(`${where}: @HttpCode of Nest holds no status.`);
84
+ }
85
+ function parametersOf(where, controller, method) {
86
+ const written = metadata(ROUTE_ARGS_METADATA, controller, method) ?? {};
87
+ const types = metadata(PARAMTYPES_METADATA, prototypeOf(controller), method);
88
+ if (!isRecord(written)) {
89
+ throw new DeclarationError(`${where}: the parameters Nest declares are not read as the kit expects them.`);
90
+ }
91
+ return Object.entries(written).map(([slot, argument]) => parameterOf({ where, types }, slot, argument));
92
+ }
93
+ /** One entry `<type>:<index>` of what Nest's parameter decorators write: `{ index, data, pipes }`. */
94
+ function parameterOf({ where, types }, slot, argument) {
95
+ const type = Number(slot.split(':')[0]);
96
+ const { index, data } = writtenArgument(where, slot, argument);
97
+ const source = SOURCES.get(type);
98
+ if (source === undefined) {
99
+ throw new DeclarationError(`${where}: parameter ${String(index)} is @${RouteParamtypes[type] ?? slot} of Nest; a route of the kit reads @Body, @Query, @Param and @Headers, @CurrentActor and @RouteContext.`);
100
+ }
101
+ return { index, source, ...(data === undefined ? {} : { key: data }), type: typeAt(types, index) };
102
+ }
103
+ /** What one parameter decorator of Nest wrote, checked: its index, the name it reads, and no pipe. */
104
+ function writtenArgument(where, slot, argument) {
105
+ if (!isRecord(argument) || typeof argument['index'] !== 'number') {
106
+ throw new DeclarationError(`${where}: the parameter ${slot} Nest declares is not read as the kit expects it.`);
107
+ }
108
+ const { index, data, pipes } = argument;
109
+ if (Array.isArray(pipes) && pipes.length > 0) {
110
+ throw new DeclarationError(`${where}: parameter ${String(index)} has pipes of Nest, which the kit does not run.`);
111
+ }
112
+ if (data !== undefined && typeof data !== 'string') {
113
+ throw new DeclarationError(`${where}: parameter ${String(index)} is read by something else than a name.`);
114
+ }
115
+ return data === undefined ? { index } : { index, data };
116
+ }
117
+ /** The class TypeScript recorded for a parameter, when it was compiled with `emitDecoratorMetadata`. */
118
+ function typeAt(types, index) {
119
+ return Array.isArray(types) ? types[index] : undefined;
120
+ }
121
+ //# sourceMappingURL=nest-route-metadata.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"nest-route-metadata.js","sourceRoot":"","sources":["../../../src/nest/controllers/nest-route-metadata.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,iCAAiC,CAAC;AACnE,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAC/C,OAAO,EACL,0BAA0B,EAC1B,eAAe,EACf,gBAAgB,EAChB,kBAAkB,EAClB,qBAAqB,EACrB,eAAe,EACf,mBAAmB,EACnB,aAAa,EACb,cAAc,EACd,iBAAiB,EACjB,eAAe,EACf,mBAAmB,EACnB,YAAY,EACZ,gBAAgB,GACjB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,eAAe,EAAE,MAAM,4CAA4C,CAAC;AAE7E,OAAO,EAAE,QAAQ,EAAE,MAAM,yBAAyB,CAAC;AACnD,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC7C,OAAO,EAAE,iBAAiB,IAAI,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAqBrE,+FAA+F;AAC/F,MAAM,oBAAoB,GAAG,mBAAmB,CAAC;AAEjD,MAAM,OAAO,GAAoC,IAAI,GAAG,CAAC;IACvD,CAAC,aAAa,CAAC,GAAG,EAAE,KAAK,CAAC;IAC1B,CAAC,aAAa,CAAC,IAAI,EAAE,MAAM,CAAC;IAC5B,CAAC,aAAa,CAAC,GAAG,EAAE,KAAK,CAAC;IAC1B,CAAC,aAAa,CAAC,KAAK,EAAE,OAAO,CAAC;IAC9B,CAAC,aAAa,CAAC,MAAM,EAAE,QAAQ,CAAC;IAChC,CAAC,aAAa,CAAC,IAAI,EAAE,MAAM,CAAC;IAC5B,CAAC,aAA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,CAAC;IACjH,CAAC;IAED,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,QAAQ,CAAC;IAExC,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,KAAK,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAC7C,MAAM,IAAI,gBAAgB,CAAC,GAAG,KAAK,eAAe,MAAM,CAAC,KAAK,CAAC,iDAAiD,CAAC,CAAC;IACpH,CAAC;IAED,IAAI,IAAI,KAAK,SAAS,IAAI,OAAO,IAAI,KAAK,QAAQ,EAAE,CAAC;QACnD,MAAM,IAAI,gBAAgB,CAAC,GAAG,KAAK,eAAe,MAAM,CAAC,KAAK,CAAC,yCAAyC,CAAC,CAAC;IAC5G,CAAC;IAED,OAAO,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;AAC1D,CAAC;AAED,wGAAwG;AACxG,SAAS,MAAM,CAAC,KAAc,EAAE,KAAa;IAC3C,OAAO,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;AACzD,CAAC"}
@@ -0,0 +1,4 @@
1
+ import type { NestControllerClass } from './nest-controller-class.js';
2
+ /** The methods of a controller that carry a route decorator of Nest (`@Get`, `@Post`...), in the order of the class. */
3
+ export declare function nestRouteMethods(controller: NestControllerClass): string[];
4
+ //# sourceMappingURL=nest-route-methods.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"nest-route-methods.d.ts","sourceRoot":"","sources":["../../../src/nest/controllers/nest-route-methods.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAC;AAInE,wHAAwH;AACxH,wBAAgB,gBAAgB,CAAC,UAAU,EAAE,mBAAmB,GAAG,MAAM,EAAE,CAQ1E"}
@@ -0,0 +1,12 @@
1
+ import { METHOD_METADATA } from '@nestjs/common/constants';
2
+ import { prototypeOf } from './prototype-of.js';
3
+ import { reflectedMetadata } from './reflected-metadata.js';
4
+ /** The methods of a controller that carry a route decorator of Nest (`@Get`, `@Post`...), in the order of the class. */
5
+ export function nestRouteMethods(controller) {
6
+ const prototype = prototypeOf(controller);
7
+ return Object.getOwnPropertyNames(prototype).filter((name) => {
8
+ const member = name === 'constructor' ? undefined : Reflect.get(prototype, name);
9
+ return typeof member === 'function' && reflectedMetadata(METHOD_METADATA, member) !== undefined;
10
+ });
11
+ }
12
+ //# sourceMappingURL=nest-route-methods.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"nest-route-methods.js","sourceRoot":"","sources":["../../../src/nest/controllers/nest-route-methods.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAE3D,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC7C,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAEzD,wHAAwH;AACxH,MAAM,UAAU,gBAAgB,CAAC,UAA+B;IAC9D,MAAM,SAAS,GAAG,WAAW,CAAC,UAAU,CAAC,CAAC;IAE1C,OAAO,MAAM,CAAC,mBAAmB,CAAC,SAAS,CAAC,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE;QAC3D,MAAM,MAAM,GAAY,IAAI,KAAK,aAAa,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,SAAS,EAAE,IAAI,CAAC,CAAC;QAE1F,OAAO,OAAO,MAAM,KAAK,UAAU,IAAI,iBAAiB,CAAC,eAAe,EAAE,MAAM,CAAC,KAAK,SAAS,CAAC;IAClG,CAAC,CAAC,CAAC;AACL,CAAC"}
@@ -0,0 +1,18 @@
1
+ import type { Schema } from '@ddd-ts-kit/validation';
2
+ import type { DtoType } from './dto-type.js';
3
+ import type { KitRouteSpec } from './kit-route-spec.js';
4
+ import type { KitRoutesOptions } from './kit-routes-options.js';
5
+ /** What a parameter decorator of the kit asks for: the caller, or the context of the request. */
6
+ export type Injected = 'actor' | 'context';
7
+ export interface NestRoutesRegistry {
8
+ /** By prototype of a controller, the routes of its methods. */
9
+ readonly routes: WeakMap<object, Map<string, KitRouteSpec>>;
10
+ /** By controller class, what its routes share. */
11
+ readonly controllers: WeakMap<object, KitRoutesOptions>;
12
+ /** By prototype, method and index, what the kit hands a parameter. */
13
+ readonly injected: WeakMap<object, Map<string, Map<number, Injected>>>;
14
+ /** By controller class and method, the body read from its signature by `ddd-ts-kit`; `null` when it answers none. */
15
+ readonly answers: WeakMap<object, ReadonlyMap<string, Schema<unknown> | DtoType | null>>;
16
+ }
17
+ export declare function nestRoutesRegistry(): NestRoutesRegistry;
18
+ //# sourceMappingURL=nest-routes-registry.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"nest-routes-registry.d.ts","sourceRoot":"","sources":["../../../src/nest/controllers/nest-routes-registry.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAC;AACrD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAC1C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AACrD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAE7D,iGAAiG;AACjG,MAAM,MAAM,QAAQ,GAAG,OAAO,GAAG,SAAS,CAAC;AAE3C,MAAM,WAAW,kBAAkB;IACjC,+DAA+D;IAC/D,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC,MAAM,EAAE,GAAG,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC,CAAC;IAC5D,kDAAkD;IAClD,QAAQ,CAAC,WAAW,EAAE,OAAO,CAAC,MAAM,EAAE,gBAAgB,CAAC,CAAC;IACxD,sEAAsE;IACtE,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAC,MAAM,EAAE,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAC;IACvE,qHAAqH;IACrH,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC,MAAM,EAAE,WAAW,CAAC,MAAM,EAAE,MAAM,CAAC,OAAO,CAAC,GAAG,OAAO,GAAG,IAAI,CAAC,CAAC,CAAC;CAC1F;AAKD,wBAAgB,kBAAkB,IAAI,kBAAkB,CAiBvD"}
@@ -0,0 +1,23 @@
1
+ /* One registry per process, whatever the number of copies of this package it loaded, as the registry of the presentation. */
2
+ const REGISTRY = Symbol.for('@ddd-ts-kit/http/nest-controllers/v2');
3
+ export function nestRoutesRegistry() {
4
+ const existing = Reflect.get(globalThis, REGISTRY);
5
+ if (isRegistry(existing)) {
6
+ return existing;
7
+ }
8
+ const created = {
9
+ routes: new WeakMap(),
10
+ controllers: new WeakMap(),
11
+ injected: new WeakMap(),
12
+ answers: new WeakMap(),
13
+ };
14
+ Reflect.set(globalThis, REGISTRY, created);
15
+ return created;
16
+ }
17
+ function isRegistry(value) {
18
+ if (typeof value !== 'object' || value === null) {
19
+ return false;
20
+ }
21
+ return ['routes', 'controllers', 'injected', 'answers'].every((key) => Reflect.get(value, key) instanceof WeakMap);
22
+ }
23
+ //# sourceMappingURL=nest-routes-registry.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"nest-routes-registry.js","sourceRoot":"","sources":["../../../src/nest/controllers/nest-routes-registry.ts"],"names":[],"mappings":"AAmBA,6HAA6H;AAC7H,MAAM,QAAQ,GAAG,MAAM,CAAC,GAAG,CAAC,sCAAsC,CAAC,CAAC;AAEpE,MAAM,UAAU,kBAAkB;IAChC,MAAM,QAAQ,GAAY,OAAO,CAAC,GAAG,CAAC,UAAU,EAAE,QAAQ,CAAC,CAAC;IAE5D,IAAI,UAAU,CAAC,QAAQ,CAAC,EAAE,CAAC;QACzB,OAAO,QAAQ,CAAC;IAClB,CAAC;IAED,MAAM,OAAO,GAAuB;QAClC,MAAM,EAAE,IAAI,OAAO,EAAE;QACrB,WAAW,EAAE,IAAI,OAAO,EAAE;QAC1B,QAAQ,EAAE,IAAI,OAAO,EAAE;QACvB,OAAO,EAAE,IAAI,OAAO,EAAE;KACvB,CAAC;IAEF,OAAO,CAAC,GAAG,CAAC,UAAU,EAAE,QAAQ,EAAE,OAAO,CAAC,CAAC;IAE3C,OAAO,OAAO,CAAC;AACjB,CAAC;AAED,SAAS,UAAU,CAAC,KAAc;IAChC,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,EAAE,CAAC;QAChD,OAAO,KAAK,CAAC;IACf,CAAC;IAED,OAAO,CAAC,QAAQ,EAAE,aAAa,EAAE,UAAU,EAAE,SAAS,CAAC,CAAC,KAAK,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC,KAAK,EAAE,GAAG,CAAC,YAAY,OAAO,CAAC,CAAC;AACrH,CAAC"}
@@ -0,0 +1,4 @@
1
+ import type { NestControllerClass } from './nest-controller-class.js';
2
+ /** Where the decorators of the methods of a controller wrote: its prototype. */
3
+ export declare function prototypeOf(controller: NestControllerClass): object;
4
+ //# sourceMappingURL=prototype-of.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"prototype-of.d.ts","sourceRoot":"","sources":["../../../src/nest/controllers/prototype-of.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAC;AAEnE,gFAAgF;AAChF,wBAAgB,WAAW,CAAC,UAAU,EAAE,mBAAmB,GAAG,MAAM,CAQnE"}
@@ -0,0 +1,10 @@
1
+ import { DeclarationError } from '@ddd-ts-kit/kernel/declarations';
2
+ /** Where the decorators of the methods of a controller wrote: its prototype. */
3
+ export function prototypeOf(controller) {
4
+ const prototype = controller.prototype;
5
+ if (typeof prototype !== 'object' || prototype === null) {
6
+ throw new DeclarationError(`${controller.name} has no prototype: it is no class.`);
7
+ }
8
+ return prototype;
9
+ }
10
+ //# sourceMappingURL=prototype-of.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"prototype-of.js","sourceRoot":"","sources":["../../../src/nest/controllers/prototype-of.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,iCAAiC,CAAC;AAGnE,gFAAgF;AAChF,MAAM,UAAU,WAAW,CAAC,UAA+B;IACzD,MAAM,SAAS,GAAY,UAAU,CAAC,SAAS,CAAC;IAEhD,IAAI,OAAO,SAAS,KAAK,QAAQ,IAAI,SAAS,KAAK,IAAI,EAAE,CAAC;QACxD,MAAM,IAAI,gBAAgB,CAAC,GAAG,UAAU,CAAC,IAAI,oCAAoC,CAAC,CAAC;IACrF,CAAC;IAED,OAAO,SAAS,CAAC;AACnB,CAAC"}
@@ -0,0 +1,12 @@
1
+ import type { DynamicModule, ModuleMetadata } from '@nestjs/common';
2
+ import type { NestControllers } from './nest-controllers.js';
3
+ /**
4
+ * The Nest module that builds the controllers `nestControllers` read, with what they inject, and
5
+ * hands their routes the instances at the start. It mounts nothing: the routes are mounted with the
6
+ * other routes of the application. A controller also among the `controllers` of a Nest module
7
+ * stops the start.
8
+ */
9
+ export declare function provideControllers(served: NestControllers, options?: {
10
+ readonly imports?: ModuleMetadata['imports'];
11
+ }): DynamicModule;
12
+ //# sourceMappingURL=provide-controllers.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"provide-controllers.d.ts","sourceRoot":"","sources":["../../../src/nest/controllers/provide-controllers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAIpE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAE1D;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAChC,MAAM,EAAE,eAAe,EACvB,OAAO,GAAE;IAAE,QAAQ,CAAC,OAAO,CAAC,EAAE,cAAc,CAAC,SAAS,CAAC,CAAA;CAAO,GAC7D,aAAa,CAsBf"}
@@ -0,0 +1,33 @@
1
+ import { ModuleRef, ModulesContainer } from '@nestjs/core';
2
+ import { assertNotRoutedByNest } from './assert-not-routed-by-nest.js';
3
+ import { ControllersBinder } from './controllers-binder.js';
4
+ /**
5
+ * The Nest module that builds the controllers `nestControllers` read, with what they inject, and
6
+ * hands their routes the instances at the start. It mounts nothing: the routes are mounted with the
7
+ * other routes of the application. A controller also among the `controllers` of a Nest module
8
+ * stops the start.
9
+ */
10
+ export function provideControllers(served, options = {}) {
11
+ // One class per call: Nest identifies a module by its class.
12
+ class ControllersModule {
13
+ }
14
+ return {
15
+ module: ControllersModule,
16
+ imports: options.imports ?? [],
17
+ providers: [
18
+ ...served.controllers,
19
+ ...served.providers,
20
+ {
21
+ provide: ControllersBinder,
22
+ inject: [ModuleRef, ModulesContainer],
23
+ useFactory: (references, modules) => ({
24
+ onModuleInit() {
25
+ assertNotRoutedByNest(modules);
26
+ served.bind(references);
27
+ },
28
+ }),
29
+ },
30
+ ],
31
+ };
32
+ }
33
+ //# sourceMappingURL=provide-controllers.js.map