@navios/core 1.1.0 → 2.0.0-alpha.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (237) hide show
  1. package/CHANGELOG.md +85 -13
  2. package/README.md +69 -220
  3. package/lib/async-context-BAdt7bno.d.mts +239 -0
  4. package/lib/async-context-BAdt7bno.d.mts.map +1 -0
  5. package/lib/async-context-RsWmy2Hi.d.cts +239 -0
  6. package/lib/async-context-RsWmy2Hi.d.cts.map +1 -0
  7. package/lib/attribute-factory-BW1kgBqf.d.mts +70 -0
  8. package/lib/attribute-factory-BW1kgBqf.d.mts.map +1 -0
  9. package/lib/attribute-factory-DqN4x5XM.d.cts +70 -0
  10. package/lib/attribute-factory-DqN4x5XM.d.cts.map +1 -0
  11. package/lib/attribute-value-BNiJjxl1.mjs +225 -0
  12. package/lib/attribute-value-BNiJjxl1.mjs.map +1 -0
  13. package/lib/attribute-value-Cux5HhOL.cjs +314 -0
  14. package/lib/attribute-value-Cux5HhOL.cjs.map +1 -0
  15. package/lib/basic-execution-context-5uq2DvEA.cjs +318 -0
  16. package/lib/basic-execution-context-5uq2DvEA.cjs.map +1 -0
  17. package/lib/basic-execution-context-u1VktGoM.mjs +277 -0
  18. package/lib/basic-execution-context-u1VktGoM.mjs.map +1 -0
  19. package/lib/execution-context-BVSmLkYp.d.cts +71 -0
  20. package/lib/execution-context-BVSmLkYp.d.cts.map +1 -0
  21. package/lib/execution-context-C5F9rojO.d.mts +71 -0
  22. package/lib/execution-context-C5F9rojO.d.mts.map +1 -0
  23. package/lib/execution-context-token--cKS4cJv.cjs +270 -0
  24. package/lib/execution-context-token--cKS4cJv.cjs.map +1 -0
  25. package/lib/execution-context-token-Cb3M3Ao0.mjs +223 -0
  26. package/lib/execution-context-token-Cb3M3Ao0.mjs.map +1 -0
  27. package/lib/index.cjs +1672 -4426
  28. package/lib/index.cjs.map +1 -1
  29. package/lib/index.d.cts +842 -3
  30. package/lib/index.d.cts.map +1 -0
  31. package/lib/index.d.mts +842 -3
  32. package/lib/index.d.mts.map +1 -0
  33. package/lib/index.mjs +1559 -4221
  34. package/lib/index.mjs.map +1 -1
  35. package/lib/legacy-compat/index.cjs +72 -371
  36. package/lib/legacy-compat/index.cjs.map +1 -1
  37. package/lib/legacy-compat/index.d.cts +42 -382
  38. package/lib/legacy-compat/index.d.cts.map +1 -1
  39. package/lib/legacy-compat/index.d.mts +41 -382
  40. package/lib/legacy-compat/index.d.mts.map +1 -1
  41. package/lib/legacy-compat/index.mjs +51 -345
  42. package/lib/legacy-compat/index.mjs.map +1 -1
  43. package/lib/module-Bz83ZnJ5.cjs +173 -0
  44. package/lib/module-Bz83ZnJ5.cjs.map +1 -0
  45. package/lib/module-options-CSqQUSTm.d.mts +51 -0
  46. package/lib/module-options-CSqQUSTm.d.mts.map +1 -0
  47. package/lib/module-options-DSRBri4J.d.cts +51 -0
  48. package/lib/module-options-DSRBri4J.d.cts.map +1 -0
  49. package/lib/module-zPXwR2qp.mjs +138 -0
  50. package/lib/module-zPXwR2qp.mjs.map +1 -0
  51. package/lib/settled-within-B6gpu2XW.cjs +32 -0
  52. package/lib/settled-within-B6gpu2XW.cjs.map +1 -0
  53. package/lib/settled-within-Bc2pj8WB.mjs +21 -0
  54. package/lib/settled-within-Bc2pj8WB.mjs.map +1 -0
  55. package/lib/testing/index.cjs +74 -414
  56. package/lib/testing/index.cjs.map +1 -1
  57. package/lib/testing/index.d.cts +25 -385
  58. package/lib/testing/index.d.cts.map +1 -1
  59. package/lib/testing/index.d.mts +24 -385
  60. package/lib/testing/index.d.mts.map +1 -1
  61. package/lib/testing/index.mjs +72 -408
  62. package/lib/testing/index.mjs.map +1 -1
  63. package/lib/transport.cjs +36 -0
  64. package/lib/transport.d.cts +254 -0
  65. package/lib/transport.d.cts.map +1 -0
  66. package/lib/transport.d.mts +254 -0
  67. package/lib/transport.d.mts.map +1 -0
  68. package/lib/transport.mjs +6 -0
  69. package/package.json +37 -17
  70. package/docs/README.md +0 -316
  71. package/docs/adapters.md +0 -308
  72. package/docs/application-setup.md +0 -524
  73. package/docs/attributes.md +0 -689
  74. package/docs/controllers.md +0 -373
  75. package/docs/endpoints.md +0 -444
  76. package/docs/exceptions.md +0 -352
  77. package/docs/guards.md +0 -550
  78. package/docs/legacy-compat.md +0 -356
  79. package/docs/modules.md +0 -377
  80. package/docs/quick-start.md +0 -290
  81. package/docs/services.md +0 -427
  82. package/docs/testing.md +0 -827
  83. package/lib/index-3LcTrbxz.d.mts +0 -3804
  84. package/lib/index-3LcTrbxz.d.mts.map +0 -1
  85. package/lib/index-B14SekVb.d.cts +0 -3804
  86. package/lib/index-B14SekVb.d.cts.map +0 -1
  87. package/lib/navios.factory-CUrO_p6K.cjs +0 -4538
  88. package/lib/navios.factory-CUrO_p6K.cjs.map +0 -1
  89. package/lib/navios.factory-DjUOOVVL.mjs +0 -4151
  90. package/lib/navios.factory-DjUOOVVL.mjs.map +0 -1
  91. package/lib/tokens-BEuBMGGX.cjs +0 -193
  92. package/lib/tokens-BEuBMGGX.cjs.map +0 -1
  93. package/lib/tokens-COyNGV1I.mjs +0 -97
  94. package/lib/tokens-COyNGV1I.mjs.map +0 -1
  95. package/lib/use-guards.decorator-DLmRl2CV.mjs +0 -336
  96. package/lib/use-guards.decorator-DLmRl2CV.mjs.map +0 -1
  97. package/lib/use-guards.decorator-DhumFTk3.cjs +0 -444
  98. package/lib/use-guards.decorator-DhumFTk3.cjs.map +0 -1
  99. package/project.json +0 -66
  100. package/src/__tests__/attribute.factory.spec.mts +0 -300
  101. package/src/__tests__/config.service.spec.mts +0 -43
  102. package/src/__tests__/console-logger.service.spec.mts +0 -312
  103. package/src/__tests__/controller-resolver.spec.mts +0 -229
  104. package/src/__tests__/controller.spec.mts +0 -58
  105. package/src/__tests__/guard-runner.service.spec.mts +0 -399
  106. package/src/__tests__/logger.service.spec.mts +0 -147
  107. package/src/__tests__/responders.spec.mts +0 -340
  108. package/src/__tests__/testing-module.spec.mts +0 -459
  109. package/src/__tests__/unit-testing-module.spec.mts +0 -424
  110. package/src/attribute.factory.mts +0 -325
  111. package/src/config/config-service.interface.mts +0 -47
  112. package/src/config/config.provider.mts +0 -69
  113. package/src/config/config.service.mts +0 -176
  114. package/src/config/index.mts +0 -5
  115. package/src/config/types.mts +0 -58
  116. package/src/config/utils/helpers.mts +0 -23
  117. package/src/config/utils/index.mts +0 -1
  118. package/src/decorators/controller.decorator.mts +0 -81
  119. package/src/decorators/endpoint.decorator.mts +0 -181
  120. package/src/decorators/header.decorator.mts +0 -38
  121. package/src/decorators/http-code.decorator.mts +0 -38
  122. package/src/decorators/index.mts +0 -8
  123. package/src/decorators/module.decorator.mts +0 -106
  124. package/src/decorators/multipart.decorator.mts +0 -169
  125. package/src/decorators/stream.decorator.mts +0 -155
  126. package/src/decorators/use-guards.decorator.mts +0 -73
  127. package/src/exceptions/bad-request.exception.mts +0 -28
  128. package/src/exceptions/conflict.exception.mts +0 -31
  129. package/src/exceptions/forbidden.exception.mts +0 -30
  130. package/src/exceptions/http.exception.mts +0 -33
  131. package/src/exceptions/index.mts +0 -7
  132. package/src/exceptions/internal-server-error.exception.mts +0 -33
  133. package/src/exceptions/not-found.exception.mts +0 -33
  134. package/src/exceptions/unauthorized.exception.mts +0 -30
  135. package/src/factories/adapter.factory.mts +0 -20
  136. package/src/factories/endpoint-adapter.factory.mts +0 -21
  137. package/src/factories/http-adapter.factory.mts +0 -20
  138. package/src/factories/index.mts +0 -8
  139. package/src/factories/multipart-adapter.factory.mts +0 -21
  140. package/src/factories/reply.factory.mts +0 -21
  141. package/src/factories/request.factory.mts +0 -21
  142. package/src/factories/stream-adapter.factory.mts +0 -20
  143. package/src/factories/xml-stream-adapter.factory.mts +0 -20
  144. package/src/index.mts +0 -16
  145. package/src/interfaces/abstract-adapter.interface.mts +0 -32
  146. package/src/interfaces/abstract-execution-context.inteface.mts +0 -48
  147. package/src/interfaces/abstract-http-adapter.interface.mts +0 -79
  148. package/src/interfaces/abstract-http-cors-options.interface.mts +0 -59
  149. package/src/interfaces/abstract-http-handler-adapter.interface.mts +0 -127
  150. package/src/interfaces/abstract-http-listen-options.interface.mts +0 -4
  151. package/src/interfaces/adapter-environment.interface.mts +0 -74
  152. package/src/interfaces/can-activate.mts +0 -38
  153. package/src/interfaces/http-header.mts +0 -18
  154. package/src/interfaces/index.mts +0 -14
  155. package/src/interfaces/navios-module.mts +0 -28
  156. package/src/interfaces/plugin-context.mts +0 -104
  157. package/src/interfaces/plugin-stage.mts +0 -62
  158. package/src/interfaces/plugin.interface.mts +0 -119
  159. package/src/interfaces/staged-plugin.interface.mts +0 -209
  160. package/src/legacy-compat/__type-tests__/legacy-decorators.spec-d.mts +0 -521
  161. package/src/legacy-compat/__type-tests__/tsconfig.json +0 -15
  162. package/src/legacy-compat/attribute.factory.mts +0 -351
  163. package/src/legacy-compat/decorators/controller.decorator.mts +0 -31
  164. package/src/legacy-compat/decorators/endpoint.decorator.mts +0 -73
  165. package/src/legacy-compat/decorators/header.decorator.mts +0 -43
  166. package/src/legacy-compat/decorators/http-code.decorator.mts +0 -39
  167. package/src/legacy-compat/decorators/index.mts +0 -11
  168. package/src/legacy-compat/decorators/module.decorator.mts +0 -37
  169. package/src/legacy-compat/decorators/multipart.decorator.mts +0 -72
  170. package/src/legacy-compat/decorators/stream.decorator.mts +0 -89
  171. package/src/legacy-compat/decorators/use-guards.decorator.mts +0 -80
  172. package/src/legacy-compat/index.mts +0 -57
  173. package/src/logger/README.md +0 -3
  174. package/src/logger/console-logger.service.mts +0 -714
  175. package/src/logger/index.mts +0 -6
  176. package/src/logger/log-levels.mts +0 -21
  177. package/src/logger/logger-service.interface.mts +0 -42
  178. package/src/logger/logger.service.mts +0 -113
  179. package/src/logger/logger.tokens.mts +0 -44
  180. package/src/logger/utils/cli-colors.util.mts +0 -17
  181. package/src/logger/utils/filter-log-levelts.util.mts +0 -29
  182. package/src/logger/utils/index.mts +0 -5
  183. package/src/logger/utils/is-log-level-enabled.mts +0 -33
  184. package/src/logger/utils/is-log-level.util.mts +0 -10
  185. package/src/logger/utils/shared.utils.mts +0 -51
  186. package/src/metadata/controller.metadata.mts +0 -79
  187. package/src/metadata/handler.metadata.mts +0 -80
  188. package/src/metadata/index.mts +0 -4
  189. package/src/metadata/module.metadata.mts +0 -116
  190. package/src/metadata/navios-managed.metadata.mts +0 -42
  191. package/src/navios.application.mts +0 -678
  192. package/src/navios.environment.mts +0 -42
  193. package/src/navios.factory.mts +0 -158
  194. package/src/responders/enums/framework-error.enum.mts +0 -38
  195. package/src/responders/enums/index.mts +0 -1
  196. package/src/responders/index.mts +0 -4
  197. package/src/responders/interfaces/error-responder.interface.mts +0 -42
  198. package/src/responders/interfaces/error-response.interface.mts +0 -22
  199. package/src/responders/interfaces/index.mts +0 -3
  200. package/src/responders/interfaces/problem-details.interface.mts +0 -34
  201. package/src/responders/services/error-response-producer.service.mts +0 -143
  202. package/src/responders/services/forbidden-responder.service.mts +0 -77
  203. package/src/responders/services/index.mts +0 -5
  204. package/src/responders/services/internal-server-error-responder.service.mts +0 -57
  205. package/src/responders/services/not-found-responder.service.mts +0 -76
  206. package/src/responders/services/validation-error-responder.service.mts +0 -78
  207. package/src/responders/tokens/index.mts +0 -1
  208. package/src/responders/tokens/responder.tokens.mts +0 -84
  209. package/src/services/abstract-handler-adapter.service.mts +0 -366
  210. package/src/services/guard-runner.service.mts +0 -152
  211. package/src/services/index.mts +0 -4
  212. package/src/services/instance-resolver.service.mts +0 -177
  213. package/src/services/module-loader.service.mts +0 -255
  214. package/src/stores/index.mts +0 -1
  215. package/src/stores/request-id.store.mts +0 -85
  216. package/src/testing/index.mts +0 -3
  217. package/src/testing/testing-module.mts +0 -393
  218. package/src/testing/unit-testing-module.mts +0 -298
  219. package/src/tokens/adapter.token.mts +0 -6
  220. package/src/tokens/endpoint-adapter.token.mts +0 -8
  221. package/src/tokens/execution-context.token.mts +0 -9
  222. package/src/tokens/http-adapter.token.mts +0 -8
  223. package/src/tokens/index.mts +0 -10
  224. package/src/tokens/multipart-adapter.token.mts +0 -8
  225. package/src/tokens/navios-options.token.mts +0 -6
  226. package/src/tokens/reply.token.mts +0 -3
  227. package/src/tokens/request.token.mts +0 -3
  228. package/src/tokens/stream-adapter.token.mts +0 -8
  229. package/src/tokens/xml-stream-adapter.token.mts +0 -8
  230. package/src/utils/adapter-supports.util.mts +0 -47
  231. package/src/utils/define-plugin.mts +0 -251
  232. package/src/utils/index.mts +0 -2
  233. package/tsconfig.json +0 -21
  234. package/tsconfig.lib.json +0 -8
  235. package/tsconfig.spec.json +0 -15
  236. package/tsdown.config.mts +0 -35
  237. package/vitest.config.mts +0 -15
@@ -0,0 +1,173 @@
1
+ const require_attribute_value = require("./attribute-value-Cux5HhOL.cjs");
2
+ let _navios_di = require("@navios/di");
3
+ // src/internal/validate-now.mts
4
+ function ignore() {}
5
+ /**
6
+ * Validates `value` with a schema that has to answer at once. A schema that
7
+ * answers with a promise, or with a thenable of another kind, is an error
8
+ * with `notSynchronous` as its message, and what it rejects with later is
9
+ * handled.
10
+ * @internal
11
+ */
12
+ function validateNow(schema, value, notSynchronous) {
13
+ const result = schema["~standard"].validate(value);
14
+ if (typeof result.then === "function") {
15
+ result.then(void 0, ignore);
16
+ throw new Error(notSynchronous);
17
+ }
18
+ return result;
19
+ }
20
+ // src/attributes/attribute-factory.mts
21
+ function apply(token, value) {
22
+ const decorator = require_attribute_value.classOrMemberDecorator(`Attribute ${String(token)}`, (context) => {
23
+ require_attribute_value.classAttributes(context).set(token, value);
24
+ }, (member) => {
25
+ member.attributes.set(token, value);
26
+ });
27
+ return Object.assign(decorator, {
28
+ token,
29
+ value
30
+ });
31
+ }
32
+ function layers(source) {
33
+ const attributes = source.attributes;
34
+ if (attributes instanceof Map) return [attributes];
35
+ const route = attributes;
36
+ return [
37
+ route.handler,
38
+ route.controller,
39
+ route.module
40
+ ];
41
+ }
42
+ /**
43
+ * Creates and reads attributes: typed metadata attached to modules,
44
+ * controllers and handlers.
45
+ *
46
+ * ```ts
47
+ * export const Public = AttributeFactory.createAttribute(Symbol.for('Public'))
48
+ * export const Roles = AttributeFactory.createAttribute(Symbol.for('Roles'), z.array(z.string()))
49
+ *
50
+ * if (AttributeFactory.has(Public, ctx.handler)) return true
51
+ * const roles = AttributeFactory.get(Roles, ctx.handler) // string[] | null
52
+ * ```
53
+ */
54
+ var AttributeFactory = class {
55
+ static createAttribute(token, schema) {
56
+ const attribute = (value) => {
57
+ if (!schema) return apply(token, true);
58
+ const result = validateNow(schema, value, `[Navios] Attribute ${token.toString()} must use a schema that validates synchronously`);
59
+ if (result.issues) throw new Error(`[Navios] Invalid value for attribute ${token.toString()}: ${result.issues.map((issue) => issue.message).join("; ")}`);
60
+ return apply(token, result.value);
61
+ };
62
+ return Object.assign(attribute, schema ? {
63
+ token,
64
+ schema
65
+ } : { token });
66
+ }
67
+ static get(attribute, source) {
68
+ for (const layer of layers(source)) if (layer.has(attribute.token)) return layer.get(attribute.token);
69
+ return null;
70
+ }
71
+ static getAll(attribute, source) {
72
+ const values = [];
73
+ for (const layer of layers(source)) if (layer.has(attribute.token)) values.push(layer.get(attribute.token));
74
+ return values;
75
+ }
76
+ static has(attribute, source) {
77
+ return layers(source).some((layer) => layer.has(attribute.token));
78
+ }
79
+ };
80
+ // src/metadata/attach-classes.mts
81
+ /**
82
+ * The decorator behind `@UseGuards` and `@UseInterceptors`: adds classes to
83
+ * the list of a class or of one of its members.
84
+ * @internal
85
+ */
86
+ function attachClasses(kind, classes, name) {
87
+ return require_attribute_value.classOrMemberDecorator(`@${name}`, (context) => {
88
+ require_attribute_value.addMissing(kind === "guards" ? require_attribute_value.classGuards(context) : require_attribute_value.classInterceptors(context), classes);
89
+ }, (member) => {
90
+ require_attribute_value.addMissing(member[kind], classes);
91
+ });
92
+ }
93
+ // src/guards/use-guards.mts
94
+ /**
95
+ * Adds guards to a module, a controller or a handler. Guards run in the
96
+ * order module, controller, handler, and within one level in the order given.
97
+ *
98
+ * On a class, place it above `@Controller` / `@Module`.
99
+ */
100
+ function UseGuards(...guards) {
101
+ return attachClasses("guards", guards, "UseGuards");
102
+ }
103
+ // src/interceptors/use-interceptors.mts
104
+ /**
105
+ * Adds interceptors to a module, a controller or a handler. The first one
106
+ * given is the outermost. They run for what the guards let through, unlike the
107
+ * interceptors of the application.
108
+ *
109
+ * On a class, place it above `@Controller` / `@Module`.
110
+ */
111
+ function UseInterceptors(...interceptors) {
112
+ return attachClasses("interceptors", interceptors, "UseInterceptors");
113
+ }
114
+ // src/modules/module.mts
115
+ function defineModule(target, context, options) {
116
+ require_attribute_value.applyAttributes(require_attribute_value.defineModuleMetadata(target, context, options).attributes, options.attributes);
117
+ (0, _navios_di.registerInjectable)(target, { scope: _navios_di.InjectableScope.Singleton });
118
+ return target;
119
+ }
120
+ /**
121
+ * Marks a class as a module: a group of handlers with shared guards,
122
+ * interceptors and attributes.
123
+ */
124
+ function Module(options = {}) {
125
+ return (target, context) => {
126
+ if (context.kind !== "class") throw new Error("[Navios] @Module can only be used on classes.");
127
+ return defineModule(target, context, options);
128
+ };
129
+ }
130
+ /**
131
+ * Registers a class as a module without decorator syntax.
132
+ */
133
+ function registerModule(target, options = {}) {
134
+ return defineModule(target, { metadata: {} }, options);
135
+ }
136
+ Object.defineProperty(exports, "AttributeFactory", {
137
+ enumerable: true,
138
+ get: function() {
139
+ return AttributeFactory;
140
+ }
141
+ });
142
+ Object.defineProperty(exports, "Module", {
143
+ enumerable: true,
144
+ get: function() {
145
+ return Module;
146
+ }
147
+ });
148
+ Object.defineProperty(exports, "UseGuards", {
149
+ enumerable: true,
150
+ get: function() {
151
+ return UseGuards;
152
+ }
153
+ });
154
+ Object.defineProperty(exports, "UseInterceptors", {
155
+ enumerable: true,
156
+ get: function() {
157
+ return UseInterceptors;
158
+ }
159
+ });
160
+ Object.defineProperty(exports, "registerModule", {
161
+ enumerable: true,
162
+ get: function() {
163
+ return registerModule;
164
+ }
165
+ });
166
+ Object.defineProperty(exports, "validateNow", {
167
+ enumerable: true,
168
+ get: function() {
169
+ return validateNow;
170
+ }
171
+ });
172
+
173
+ //# sourceMappingURL=module-Bz83ZnJ5.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"module-Bz83ZnJ5.cjs","names":["classOrMemberDecorator","classAttributes","classOrMemberDecorator","addMissing","classGuards","classInterceptors","applyAttributes","defineModuleMetadata","registerInjectable","InjectableScope"],"sources":["../src/internal/validate-now.mts","../src/attributes/attribute-factory.mts","../src/metadata/attach-classes.mts","../src/guards/use-guards.mts","../src/interceptors/use-interceptors.mts","../src/modules/module.mts"],"sourcesContent":["import type { StandardSchemaIssue, StandardSchemaV1 } from '@navios/di'\n\ntype ValidationResult<Output> =\n | { readonly value: Output; readonly issues?: undefined }\n | { readonly issues: ReadonlyArray<StandardSchemaIssue> }\n\nfunction ignore(): void {}\n\n/**\n * Validates `value` with a schema that has to answer at once. A schema that\n * answers with a promise, or with a thenable of another kind, is an error\n * with `notSynchronous` as its message, and what it rejects with later is\n * handled.\n * @internal\n */\nexport function validateNow<Output>(\n schema: StandardSchemaV1<unknown, Output>,\n value: unknown,\n notSynchronous: string,\n): ValidationResult<Output> {\n const result = schema['~standard'].validate(value) as\n | ValidationResult<Output>\n | PromiseLike<unknown>\n if (typeof (result as Partial<PromiseLike<unknown>>).then === 'function') {\n ;(result as PromiseLike<unknown>).then(undefined, ignore)\n throw new Error(notSynchronous)\n }\n return result as ValidationResult<Output>\n}\n","import type { InferInput, InferOutput, StandardSchemaV1 } from '@navios/di'\n\nimport { validateNow } from '../internal/validate-now.mjs'\nimport { classAttributes } from '../metadata/class-metadata.mjs'\nimport { classOrMemberDecorator } from '../metadata/member-metadata.mjs'\n\nimport type { HandlerInfo } from '../execution/execution-context.mjs'\n\n/* eslint-disable @typescript-eslint/no-explicit-any */\n\ntype AttributeContext =\n | ClassDecoratorContext\n | ClassMethodDecoratorContext\n | ClassFieldDecoratorContext\n\n/**\n * The result of calling an attribute. It is a decorator for a module, a\n * controller, a handler method or a handler field, and it can also be passed\n * in `handler(endpoint, { attributes: [...] }, fn)`.\n */\nexport interface AttributeApplication {\n (target: any, context: AttributeContext): any\n readonly token: symbol\n readonly value: unknown\n}\n\nexport interface ClassAttribute {\n (): AttributeApplication\n readonly token: symbol\n}\n\nexport interface ClassSchemaAttribute<Schema extends StandardSchemaV1> {\n (value: InferInput<Schema>): AttributeApplication\n readonly token: symbol\n readonly schema: Schema\n}\n\nfunction apply(token: symbol, value: unknown): AttributeApplication {\n const decorator = classOrMemberDecorator(\n `Attribute ${String(token)}`,\n (context) => {\n classAttributes(context).set(token, value)\n },\n (member) => {\n member.attributes.set(token, value)\n },\n )\n return Object.assign(decorator, { token, value })\n}\n\n/**\n * What reading an attribute needs of it. An attribute of either factory, the\n * standard one or the one from `@navios/core/legacy-compat`, has this shape;\n * what calling it returns differs between the two and does not matter here.\n */\ninterface ReadableAttribute {\n readonly token: symbol\n readonly schema?: undefined\n}\n\ninterface ReadableSchemaAttribute<Schema extends StandardSchemaV1> {\n readonly token: symbol\n readonly schema: Schema\n}\n\ntype AttributeSource = HandlerInfo | { attributes: ReadonlyMap<symbol, unknown> }\n\nfunction layers(source: AttributeSource): ReadonlyMap<symbol, unknown>[] {\n const attributes = source.attributes\n if (attributes instanceof Map) {\n return [attributes]\n }\n const route = attributes as HandlerInfo['attributes']\n // Most specific first.\n return [route.handler, route.controller, route.module]\n}\n\n/**\n * Creates and reads attributes: typed metadata attached to modules,\n * controllers and handlers.\n *\n * ```ts\n * export const Public = AttributeFactory.createAttribute(Symbol.for('Public'))\n * export const Roles = AttributeFactory.createAttribute(Symbol.for('Roles'), z.array(z.string()))\n *\n * if (AttributeFactory.has(Public, ctx.handler)) return true\n * const roles = AttributeFactory.get(Roles, ctx.handler) // string[] | null\n * ```\n */\nexport class AttributeFactory {\n static createAttribute(token: symbol): ClassAttribute\n static createAttribute<Schema extends StandardSchemaV1>(\n token: symbol,\n schema: Schema,\n ): ClassSchemaAttribute<Schema>\n static createAttribute(token: symbol, schema?: StandardSchemaV1): any {\n const attribute = (value?: unknown) => {\n if (!schema) {\n return apply(token, true)\n }\n const result = validateNow(\n schema,\n value,\n `[Navios] Attribute ${token.toString()} must use a schema that validates synchronously`,\n )\n if (result.issues) {\n throw new Error(\n `[Navios] Invalid value for attribute ${token.toString()}: ${result.issues\n .map((issue) => issue.message)\n .join('; ')}`,\n )\n }\n return apply(token, result.value)\n }\n return Object.assign(attribute, schema ? { token, schema } : { token })\n }\n\n /**\n * The attribute's value for a handler: the handler's own, else the controller's,\n * else the module's. `null` when none has it.\n */\n static get(attribute: ReadableAttribute, source: AttributeSource): true | null\n static get<Schema extends StandardSchemaV1>(\n attribute: ReadableSchemaAttribute<Schema>,\n source: AttributeSource,\n ): InferOutput<Schema> | null\n static get(attribute: { token: symbol }, source: AttributeSource): unknown {\n for (const layer of layers(source)) {\n if (layer.has(attribute.token)) {\n return layer.get(attribute.token)\n }\n }\n return null\n }\n\n /**\n * Every value of the attribute for a handler, most specific first.\n */\n static getAll(attribute: ReadableAttribute, source: AttributeSource): true[]\n static getAll<Schema extends StandardSchemaV1>(\n attribute: ReadableSchemaAttribute<Schema>,\n source: AttributeSource,\n ): InferOutput<Schema>[]\n static getAll(attribute: { token: symbol }, source: AttributeSource): unknown[] {\n const values: unknown[] = []\n for (const layer of layers(source)) {\n if (layer.has(attribute.token)) {\n values.push(layer.get(attribute.token))\n }\n }\n return values\n }\n\n static has(attribute: { token: symbol }, source: AttributeSource): boolean {\n return layers(source).some((layer) => layer.has(attribute.token))\n }\n}\n","import type { ClassType } from '@navios/di'\n\nimport { addMissing, classGuards, classInterceptors } from './class-metadata.mjs'\nimport { classOrMemberDecorator } from './member-metadata.mjs'\n\n/* eslint-disable @typescript-eslint/no-explicit-any */\n\ntype AnyMemberContext =\n | ClassDecoratorContext\n | ClassMethodDecoratorContext\n | ClassFieldDecoratorContext\n\n/**\n * The decorator behind `@UseGuards` and `@UseInterceptors`: adds classes to\n * the list of a class or of one of its members.\n * @internal\n */\nexport function attachClasses(\n kind: 'guards' | 'interceptors',\n classes: ClassType[],\n name: string,\n): (target: any, context: AnyMemberContext) => any {\n return classOrMemberDecorator(\n `@${name}`,\n (context) => {\n addMissing(kind === 'guards' ? classGuards(context) : classInterceptors(context), classes)\n },\n (member) => {\n addMissing(member[kind], classes)\n },\n )\n}\n","import { attachClasses } from '../metadata/attach-classes.mjs'\n\nimport type { GuardClass } from './guard.mjs'\n\n/**\n * Adds guards to a module, a controller or a handler. Guards run in the\n * order module, controller, handler, and within one level in the order given.\n *\n * On a class, place it above `@Controller` / `@Module`.\n */\nexport function UseGuards(...guards: GuardClass[]) {\n return attachClasses('guards', guards, 'UseGuards')\n}\n","import { attachClasses } from '../metadata/attach-classes.mjs'\n\nimport type { InterceptorClass } from './interceptor.mjs'\n\n/**\n * Adds interceptors to a module, a controller or a handler. The first one\n * given is the outermost. They run for what the guards let through, unlike the\n * interceptors of the application.\n *\n * On a class, place it above `@Controller` / `@Module`.\n */\nexport function UseInterceptors(...interceptors: InterceptorClass[]) {\n return attachClasses('interceptors', interceptors, 'UseInterceptors')\n}\n","import { InjectableScope, registerInjectable } from '@navios/di'\n\nimport type { ClassType } from '@navios/di'\n\nimport { applyAttributes } from '../attributes/attribute-value.mjs'\n\nimport type { DecoratorMetadata } from '../metadata/decorator-metadata.mjs'\n\nimport { defineModuleMetadata } from './module-metadata.mjs'\n\nimport type { ModuleOptions } from './module-options.mjs'\n\nfunction defineModule<T extends ClassType>(\n target: T,\n context: { metadata?: DecoratorMetadata },\n options: ModuleOptions,\n): T {\n applyAttributes(defineModuleMetadata(target, context, options).attributes, options.attributes)\n registerInjectable(target, { scope: InjectableScope.Singleton })\n return target\n}\n\n/**\n * Marks a class as a module: a group of handlers with shared guards,\n * interceptors and attributes.\n */\nexport function Module(options: ModuleOptions = {}) {\n return <T extends ClassType>(target: T, context: ClassDecoratorContext): T => {\n if (context.kind !== 'class') {\n throw new Error('[Navios] @Module can only be used on classes.')\n }\n return defineModule(target, context, options)\n }\n}\n\n/**\n * Registers a class as a module without decorator syntax.\n */\nexport function registerModule<T extends ClassType>(target: T, options: ModuleOptions = {}): T {\n return defineModule(target, { metadata: {} }, options)\n}\n"],"mappings":"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"}
@@ -0,0 +1,51 @@
1
+ import { ClassType, Provider } from "@navios/di";
2
+ import { n as ExecutionContext } from "./execution-context-C5F9rojO.mjs";
3
+ /**
4
+ * Wraps a handler. `Ctx` is the context of the transport the interceptor is
5
+ * written for and `Result` what that transport's handlers produce; the
6
+ * defaults work on every transport.
7
+ */
8
+ interface Interceptor<Ctx extends ExecutionContext = ExecutionContext, Result = unknown> {
9
+ intercept(ctx: Ctx, next: () => Promise<Result>): Result | Promise<Result>;
10
+ }
11
+ /** A class that interceptors are made of. */
12
+ type InterceptorClass = new (...args: any[]) => Interceptor<any, any>;
13
+ /** An attribute value as returned by calling an attribute. */
14
+ type AttributeValue = {
15
+ readonly token: symbol;
16
+ readonly value: unknown;
17
+ };
18
+ /**
19
+ * Decides whether a handler may run. `Ctx` is the context of the transport
20
+ * the guard is written for; the default works on every transport.
21
+ */
22
+ interface Guard<Ctx extends ExecutionContext = ExecutionContext> {
23
+ canActivate(ctx: Ctx): boolean | Promise<boolean>;
24
+ }
25
+ /** A class that guards are made of. */
26
+ type GuardClass = new (...args: any[]) => Guard<any>;
27
+ /**
28
+ * What `@Module` accepts in every application. A transport adds its own
29
+ * options on top; `@Module` keeps an option it does not know as written, for
30
+ * the transport that reads it, and an option that no transport of the running
31
+ * application reads is ignored. One module can therefore serve several
32
+ * transports.
33
+ */
34
+ interface ModuleOptions {
35
+ imports?: ClassType[];
36
+ /** Providers for the whole application (modules do not encapsulate them). */
37
+ providers?: Provider[];
38
+ /** Guards for every handler of this module and of the modules it imports. */
39
+ guards?: GuardClass[];
40
+ /** Interceptors around the same handlers, the first one outermost. */
41
+ interceptors?: InterceptorClass[];
42
+ /**
43
+ * Attribute values for every handler of this module and of the modules it
44
+ * imports: `[Public()]`. A handler whose module is imported by several others
45
+ * has to get one value from all of them, unless it, its class or the module
46
+ * sets its own.
47
+ */
48
+ attributes?: AttributeValue[];
49
+ }
50
+ export { Interceptor as a, AttributeValue as i, Guard as n, InterceptorClass as o, GuardClass as r, ModuleOptions as t };
51
+ //# sourceMappingURL=module-options-CSqQUSTm.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"module-options-CSqQUSTm.d.mts","names":[],"sources":["../src/interceptors/interceptor.mts","../src/attributes/attribute-value.mts","../src/guards/guard.mts","../src/modules/module-options.mts"],"mappings":";;;;;;;UAOiB,YAAY,YAAY,mBAAmB,kBAAkB;EAC5E,UAAU,KAAK,KAAK,YAAY,QAAQ,UAAU,SAAS,QAAQ;;;KAMzD,2BAA2B,gBAAgB;;KCb3C;WAA4B;WAAwB;;;;;;UCK/C,MAAM,YAAY,mBAAmB;EACpD,YAAY,KAAK,gBAAgB;;;KAMvB,qBAAqB,gBAAgB;;;;;;;;UCAhC;EACf,UAAU;;EAEV,YAAY;;EAEZ,SAAS;;EAET,eAAe;;;;;;;EAOf,aAAa"}
@@ -0,0 +1,51 @@
1
+ import { ClassType, Provider } from "@navios/di";
2
+ import { n as ExecutionContext } from "./execution-context-BVSmLkYp.cjs";
3
+ /**
4
+ * Wraps a handler. `Ctx` is the context of the transport the interceptor is
5
+ * written for and `Result` what that transport's handlers produce; the
6
+ * defaults work on every transport.
7
+ */
8
+ interface Interceptor<Ctx extends ExecutionContext = ExecutionContext, Result = unknown> {
9
+ intercept(ctx: Ctx, next: () => Promise<Result>): Result | Promise<Result>;
10
+ }
11
+ /** A class that interceptors are made of. */
12
+ type InterceptorClass = new (...args: any[]) => Interceptor<any, any>;
13
+ /** An attribute value as returned by calling an attribute. */
14
+ type AttributeValue = {
15
+ readonly token: symbol;
16
+ readonly value: unknown;
17
+ };
18
+ /**
19
+ * Decides whether a handler may run. `Ctx` is the context of the transport
20
+ * the guard is written for; the default works on every transport.
21
+ */
22
+ interface Guard<Ctx extends ExecutionContext = ExecutionContext> {
23
+ canActivate(ctx: Ctx): boolean | Promise<boolean>;
24
+ }
25
+ /** A class that guards are made of. */
26
+ type GuardClass = new (...args: any[]) => Guard<any>;
27
+ /**
28
+ * What `@Module` accepts in every application. A transport adds its own
29
+ * options on top; `@Module` keeps an option it does not know as written, for
30
+ * the transport that reads it, and an option that no transport of the running
31
+ * application reads is ignored. One module can therefore serve several
32
+ * transports.
33
+ */
34
+ interface ModuleOptions {
35
+ imports?: ClassType[];
36
+ /** Providers for the whole application (modules do not encapsulate them). */
37
+ providers?: Provider[];
38
+ /** Guards for every handler of this module and of the modules it imports. */
39
+ guards?: GuardClass[];
40
+ /** Interceptors around the same handlers, the first one outermost. */
41
+ interceptors?: InterceptorClass[];
42
+ /**
43
+ * Attribute values for every handler of this module and of the modules it
44
+ * imports: `[Public()]`. A handler whose module is imported by several others
45
+ * has to get one value from all of them, unless it, its class or the module
46
+ * sets its own.
47
+ */
48
+ attributes?: AttributeValue[];
49
+ }
50
+ export { Interceptor as a, AttributeValue as i, Guard as n, InterceptorClass as o, GuardClass as r, ModuleOptions as t };
51
+ //# sourceMappingURL=module-options-DSRBri4J.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"module-options-DSRBri4J.d.cts","names":[],"sources":["../src/interceptors/interceptor.mts","../src/attributes/attribute-value.mts","../src/guards/guard.mts","../src/modules/module-options.mts"],"mappings":";;;;;;;UAOiB,YAAY,YAAY,mBAAmB,kBAAkB;EAC5E,UAAU,KAAK,KAAK,YAAY,QAAQ,UAAU,SAAS,QAAQ;;;KAMzD,2BAA2B,gBAAgB;;KCb3C;WAA4B;WAAwB;;;;;;UCK/C,MAAM,YAAY,mBAAmB;EACpD,YAAY,KAAK,gBAAgB;;;KAMvB,qBAAqB,gBAAgB;;;;;;;;UCAhC;EACf,UAAU;;EAEV,YAAY;;EAEZ,SAAS;;EAET,eAAe;;;;;;;EAOf,aAAa"}
@@ -0,0 +1,138 @@
1
+ import { d as classGuards, f as classInterceptors, l as addMissing, o as defineModuleMetadata, r as classOrMemberDecorator, t as applyAttributes, u as classAttributes } from "./attribute-value-BNiJjxl1.mjs";
2
+ import { InjectableScope, registerInjectable } from "@navios/di";
3
+ // src/internal/validate-now.mts
4
+ function ignore() {}
5
+ /**
6
+ * Validates `value` with a schema that has to answer at once. A schema that
7
+ * answers with a promise, or with a thenable of another kind, is an error
8
+ * with `notSynchronous` as its message, and what it rejects with later is
9
+ * handled.
10
+ * @internal
11
+ */
12
+ function validateNow(schema, value, notSynchronous) {
13
+ const result = schema["~standard"].validate(value);
14
+ if (typeof result.then === "function") {
15
+ result.then(void 0, ignore);
16
+ throw new Error(notSynchronous);
17
+ }
18
+ return result;
19
+ }
20
+ // src/attributes/attribute-factory.mts
21
+ function apply(token, value) {
22
+ const decorator = classOrMemberDecorator(`Attribute ${String(token)}`, (context) => {
23
+ classAttributes(context).set(token, value);
24
+ }, (member) => {
25
+ member.attributes.set(token, value);
26
+ });
27
+ return Object.assign(decorator, {
28
+ token,
29
+ value
30
+ });
31
+ }
32
+ function layers(source) {
33
+ const attributes = source.attributes;
34
+ if (attributes instanceof Map) return [attributes];
35
+ const route = attributes;
36
+ return [
37
+ route.handler,
38
+ route.controller,
39
+ route.module
40
+ ];
41
+ }
42
+ /**
43
+ * Creates and reads attributes: typed metadata attached to modules,
44
+ * controllers and handlers.
45
+ *
46
+ * ```ts
47
+ * export const Public = AttributeFactory.createAttribute(Symbol.for('Public'))
48
+ * export const Roles = AttributeFactory.createAttribute(Symbol.for('Roles'), z.array(z.string()))
49
+ *
50
+ * if (AttributeFactory.has(Public, ctx.handler)) return true
51
+ * const roles = AttributeFactory.get(Roles, ctx.handler) // string[] | null
52
+ * ```
53
+ */
54
+ var AttributeFactory = class {
55
+ static createAttribute(token, schema) {
56
+ const attribute = (value) => {
57
+ if (!schema) return apply(token, true);
58
+ const result = validateNow(schema, value, `[Navios] Attribute ${token.toString()} must use a schema that validates synchronously`);
59
+ if (result.issues) throw new Error(`[Navios] Invalid value for attribute ${token.toString()}: ${result.issues.map((issue) => issue.message).join("; ")}`);
60
+ return apply(token, result.value);
61
+ };
62
+ return Object.assign(attribute, schema ? {
63
+ token,
64
+ schema
65
+ } : { token });
66
+ }
67
+ static get(attribute, source) {
68
+ for (const layer of layers(source)) if (layer.has(attribute.token)) return layer.get(attribute.token);
69
+ return null;
70
+ }
71
+ static getAll(attribute, source) {
72
+ const values = [];
73
+ for (const layer of layers(source)) if (layer.has(attribute.token)) values.push(layer.get(attribute.token));
74
+ return values;
75
+ }
76
+ static has(attribute, source) {
77
+ return layers(source).some((layer) => layer.has(attribute.token));
78
+ }
79
+ };
80
+ // src/metadata/attach-classes.mts
81
+ /**
82
+ * The decorator behind `@UseGuards` and `@UseInterceptors`: adds classes to
83
+ * the list of a class or of one of its members.
84
+ * @internal
85
+ */
86
+ function attachClasses(kind, classes, name) {
87
+ return classOrMemberDecorator(`@${name}`, (context) => {
88
+ addMissing(kind === "guards" ? classGuards(context) : classInterceptors(context), classes);
89
+ }, (member) => {
90
+ addMissing(member[kind], classes);
91
+ });
92
+ }
93
+ // src/guards/use-guards.mts
94
+ /**
95
+ * Adds guards to a module, a controller or a handler. Guards run in the
96
+ * order module, controller, handler, and within one level in the order given.
97
+ *
98
+ * On a class, place it above `@Controller` / `@Module`.
99
+ */
100
+ function UseGuards(...guards) {
101
+ return attachClasses("guards", guards, "UseGuards");
102
+ }
103
+ // src/interceptors/use-interceptors.mts
104
+ /**
105
+ * Adds interceptors to a module, a controller or a handler. The first one
106
+ * given is the outermost. They run for what the guards let through, unlike the
107
+ * interceptors of the application.
108
+ *
109
+ * On a class, place it above `@Controller` / `@Module`.
110
+ */
111
+ function UseInterceptors(...interceptors) {
112
+ return attachClasses("interceptors", interceptors, "UseInterceptors");
113
+ }
114
+ // src/modules/module.mts
115
+ function defineModule(target, context, options) {
116
+ applyAttributes(defineModuleMetadata(target, context, options).attributes, options.attributes);
117
+ registerInjectable(target, { scope: InjectableScope.Singleton });
118
+ return target;
119
+ }
120
+ /**
121
+ * Marks a class as a module: a group of handlers with shared guards,
122
+ * interceptors and attributes.
123
+ */
124
+ function Module(options = {}) {
125
+ return (target, context) => {
126
+ if (context.kind !== "class") throw new Error("[Navios] @Module can only be used on classes.");
127
+ return defineModule(target, context, options);
128
+ };
129
+ }
130
+ /**
131
+ * Registers a class as a module without decorator syntax.
132
+ */
133
+ function registerModule(target, options = {}) {
134
+ return defineModule(target, { metadata: {} }, options);
135
+ }
136
+ export { AttributeFactory as a, UseGuards as i, registerModule as n, validateNow as o, UseInterceptors as r, Module as t };
137
+
138
+ //# sourceMappingURL=module-zPXwR2qp.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"module-zPXwR2qp.mjs","names":[],"sources":["../src/internal/validate-now.mts","../src/attributes/attribute-factory.mts","../src/metadata/attach-classes.mts","../src/guards/use-guards.mts","../src/interceptors/use-interceptors.mts","../src/modules/module.mts"],"sourcesContent":["import type { StandardSchemaIssue, StandardSchemaV1 } from '@navios/di'\n\ntype ValidationResult<Output> =\n | { readonly value: Output; readonly issues?: undefined }\n | { readonly issues: ReadonlyArray<StandardSchemaIssue> }\n\nfunction ignore(): void {}\n\n/**\n * Validates `value` with a schema that has to answer at once. A schema that\n * answers with a promise, or with a thenable of another kind, is an error\n * with `notSynchronous` as its message, and what it rejects with later is\n * handled.\n * @internal\n */\nexport function validateNow<Output>(\n schema: StandardSchemaV1<unknown, Output>,\n value: unknown,\n notSynchronous: string,\n): ValidationResult<Output> {\n const result = schema['~standard'].validate(value) as\n | ValidationResult<Output>\n | PromiseLike<unknown>\n if (typeof (result as Partial<PromiseLike<unknown>>).then === 'function') {\n ;(result as PromiseLike<unknown>).then(undefined, ignore)\n throw new Error(notSynchronous)\n }\n return result as ValidationResult<Output>\n}\n","import type { InferInput, InferOutput, StandardSchemaV1 } from '@navios/di'\n\nimport { validateNow } from '../internal/validate-now.mjs'\nimport { classAttributes } from '../metadata/class-metadata.mjs'\nimport { classOrMemberDecorator } from '../metadata/member-metadata.mjs'\n\nimport type { HandlerInfo } from '../execution/execution-context.mjs'\n\n/* eslint-disable @typescript-eslint/no-explicit-any */\n\ntype AttributeContext =\n | ClassDecoratorContext\n | ClassMethodDecoratorContext\n | ClassFieldDecoratorContext\n\n/**\n * The result of calling an attribute. It is a decorator for a module, a\n * controller, a handler method or a handler field, and it can also be passed\n * in `handler(endpoint, { attributes: [...] }, fn)`.\n */\nexport interface AttributeApplication {\n (target: any, context: AttributeContext): any\n readonly token: symbol\n readonly value: unknown\n}\n\nexport interface ClassAttribute {\n (): AttributeApplication\n readonly token: symbol\n}\n\nexport interface ClassSchemaAttribute<Schema extends StandardSchemaV1> {\n (value: InferInput<Schema>): AttributeApplication\n readonly token: symbol\n readonly schema: Schema\n}\n\nfunction apply(token: symbol, value: unknown): AttributeApplication {\n const decorator = classOrMemberDecorator(\n `Attribute ${String(token)}`,\n (context) => {\n classAttributes(context).set(token, value)\n },\n (member) => {\n member.attributes.set(token, value)\n },\n )\n return Object.assign(decorator, { token, value })\n}\n\n/**\n * What reading an attribute needs of it. An attribute of either factory, the\n * standard one or the one from `@navios/core/legacy-compat`, has this shape;\n * what calling it returns differs between the two and does not matter here.\n */\ninterface ReadableAttribute {\n readonly token: symbol\n readonly schema?: undefined\n}\n\ninterface ReadableSchemaAttribute<Schema extends StandardSchemaV1> {\n readonly token: symbol\n readonly schema: Schema\n}\n\ntype AttributeSource = HandlerInfo | { attributes: ReadonlyMap<symbol, unknown> }\n\nfunction layers(source: AttributeSource): ReadonlyMap<symbol, unknown>[] {\n const attributes = source.attributes\n if (attributes instanceof Map) {\n return [attributes]\n }\n const route = attributes as HandlerInfo['attributes']\n // Most specific first.\n return [route.handler, route.controller, route.module]\n}\n\n/**\n * Creates and reads attributes: typed metadata attached to modules,\n * controllers and handlers.\n *\n * ```ts\n * export const Public = AttributeFactory.createAttribute(Symbol.for('Public'))\n * export const Roles = AttributeFactory.createAttribute(Symbol.for('Roles'), z.array(z.string()))\n *\n * if (AttributeFactory.has(Public, ctx.handler)) return true\n * const roles = AttributeFactory.get(Roles, ctx.handler) // string[] | null\n * ```\n */\nexport class AttributeFactory {\n static createAttribute(token: symbol): ClassAttribute\n static createAttribute<Schema extends StandardSchemaV1>(\n token: symbol,\n schema: Schema,\n ): ClassSchemaAttribute<Schema>\n static createAttribute(token: symbol, schema?: StandardSchemaV1): any {\n const attribute = (value?: unknown) => {\n if (!schema) {\n return apply(token, true)\n }\n const result = validateNow(\n schema,\n value,\n `[Navios] Attribute ${token.toString()} must use a schema that validates synchronously`,\n )\n if (result.issues) {\n throw new Error(\n `[Navios] Invalid value for attribute ${token.toString()}: ${result.issues\n .map((issue) => issue.message)\n .join('; ')}`,\n )\n }\n return apply(token, result.value)\n }\n return Object.assign(attribute, schema ? { token, schema } : { token })\n }\n\n /**\n * The attribute's value for a handler: the handler's own, else the controller's,\n * else the module's. `null` when none has it.\n */\n static get(attribute: ReadableAttribute, source: AttributeSource): true | null\n static get<Schema extends StandardSchemaV1>(\n attribute: ReadableSchemaAttribute<Schema>,\n source: AttributeSource,\n ): InferOutput<Schema> | null\n static get(attribute: { token: symbol }, source: AttributeSource): unknown {\n for (const layer of layers(source)) {\n if (layer.has(attribute.token)) {\n return layer.get(attribute.token)\n }\n }\n return null\n }\n\n /**\n * Every value of the attribute for a handler, most specific first.\n */\n static getAll(attribute: ReadableAttribute, source: AttributeSource): true[]\n static getAll<Schema extends StandardSchemaV1>(\n attribute: ReadableSchemaAttribute<Schema>,\n source: AttributeSource,\n ): InferOutput<Schema>[]\n static getAll(attribute: { token: symbol }, source: AttributeSource): unknown[] {\n const values: unknown[] = []\n for (const layer of layers(source)) {\n if (layer.has(attribute.token)) {\n values.push(layer.get(attribute.token))\n }\n }\n return values\n }\n\n static has(attribute: { token: symbol }, source: AttributeSource): boolean {\n return layers(source).some((layer) => layer.has(attribute.token))\n }\n}\n","import type { ClassType } from '@navios/di'\n\nimport { addMissing, classGuards, classInterceptors } from './class-metadata.mjs'\nimport { classOrMemberDecorator } from './member-metadata.mjs'\n\n/* eslint-disable @typescript-eslint/no-explicit-any */\n\ntype AnyMemberContext =\n | ClassDecoratorContext\n | ClassMethodDecoratorContext\n | ClassFieldDecoratorContext\n\n/**\n * The decorator behind `@UseGuards` and `@UseInterceptors`: adds classes to\n * the list of a class or of one of its members.\n * @internal\n */\nexport function attachClasses(\n kind: 'guards' | 'interceptors',\n classes: ClassType[],\n name: string,\n): (target: any, context: AnyMemberContext) => any {\n return classOrMemberDecorator(\n `@${name}`,\n (context) => {\n addMissing(kind === 'guards' ? classGuards(context) : classInterceptors(context), classes)\n },\n (member) => {\n addMissing(member[kind], classes)\n },\n )\n}\n","import { attachClasses } from '../metadata/attach-classes.mjs'\n\nimport type { GuardClass } from './guard.mjs'\n\n/**\n * Adds guards to a module, a controller or a handler. Guards run in the\n * order module, controller, handler, and within one level in the order given.\n *\n * On a class, place it above `@Controller` / `@Module`.\n */\nexport function UseGuards(...guards: GuardClass[]) {\n return attachClasses('guards', guards, 'UseGuards')\n}\n","import { attachClasses } from '../metadata/attach-classes.mjs'\n\nimport type { InterceptorClass } from './interceptor.mjs'\n\n/**\n * Adds interceptors to a module, a controller or a handler. The first one\n * given is the outermost. They run for what the guards let through, unlike the\n * interceptors of the application.\n *\n * On a class, place it above `@Controller` / `@Module`.\n */\nexport function UseInterceptors(...interceptors: InterceptorClass[]) {\n return attachClasses('interceptors', interceptors, 'UseInterceptors')\n}\n","import { InjectableScope, registerInjectable } from '@navios/di'\n\nimport type { ClassType } from '@navios/di'\n\nimport { applyAttributes } from '../attributes/attribute-value.mjs'\n\nimport type { DecoratorMetadata } from '../metadata/decorator-metadata.mjs'\n\nimport { defineModuleMetadata } from './module-metadata.mjs'\n\nimport type { ModuleOptions } from './module-options.mjs'\n\nfunction defineModule<T extends ClassType>(\n target: T,\n context: { metadata?: DecoratorMetadata },\n options: ModuleOptions,\n): T {\n applyAttributes(defineModuleMetadata(target, context, options).attributes, options.attributes)\n registerInjectable(target, { scope: InjectableScope.Singleton })\n return target\n}\n\n/**\n * Marks a class as a module: a group of handlers with shared guards,\n * interceptors and attributes.\n */\nexport function Module(options: ModuleOptions = {}) {\n return <T extends ClassType>(target: T, context: ClassDecoratorContext): T => {\n if (context.kind !== 'class') {\n throw new Error('[Navios] @Module can only be used on classes.')\n }\n return defineModule(target, context, options)\n }\n}\n\n/**\n * Registers a class as a module without decorator syntax.\n */\nexport function registerModule<T extends ClassType>(target: T, options: ModuleOptions = {}): T {\n return defineModule(target, { metadata: {} }, options)\n}\n"],"mappings":"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"}
@@ -0,0 +1,32 @@
1
+ // src/transports/settled-within.mts
2
+ /** The longest delay a timer takes; a longer one fires at once. */
3
+ const MAX_DELAY_MS = 2 ** 31 - 1;
4
+ /**
5
+ * Whether `work` settles within `ms`, or within `MAX_DELAY_MS` when `ms` is
6
+ * longer. Rejects when it rejects in time; a later rejection is dropped.
7
+ */
8
+ async function settledWithin(work, ms) {
9
+ let timer;
10
+ const timeout = new Promise((resolve) => {
11
+ timer = setTimeout(resolve, Math.min(ms, MAX_DELAY_MS), false);
12
+ });
13
+ try {
14
+ return await Promise.race([Promise.resolve(work).then(() => true), timeout]);
15
+ } finally {
16
+ clearTimeout(timer);
17
+ }
18
+ }
19
+ Object.defineProperty(exports, "MAX_DELAY_MS", {
20
+ enumerable: true,
21
+ get: function() {
22
+ return MAX_DELAY_MS;
23
+ }
24
+ });
25
+ Object.defineProperty(exports, "settledWithin", {
26
+ enumerable: true,
27
+ get: function() {
28
+ return settledWithin;
29
+ }
30
+ });
31
+
32
+ //# sourceMappingURL=settled-within-B6gpu2XW.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"settled-within-B6gpu2XW.cjs","names":[],"sources":["../src/transports/settled-within.mts"],"sourcesContent":["/** The longest delay a timer takes; a longer one fires at once. */\nexport const MAX_DELAY_MS = 2 ** 31 - 1\n\n/**\n * Whether `work` settles within `ms`, or within `MAX_DELAY_MS` when `ms` is\n * longer. Rejects when it rejects in time; a later rejection is dropped.\n */\nexport async function settledWithin(work: PromiseLike<unknown>, ms: number): Promise<boolean> {\n let timer: ReturnType<typeof setTimeout> | undefined\n const timeout = new Promise<false>((resolve) => {\n timer = setTimeout(resolve, Math.min(ms, MAX_DELAY_MS), false)\n })\n try {\n return await Promise.race([Promise.resolve(work).then(() => true), timeout])\n } finally {\n clearTimeout(timer)\n }\n}\n"],"mappings":";;AACA,MAAa,eAAe,KAAK,KAAK;;;;;AAMtC,eAAsB,cAAc,MAA4B,IAA8B;CAC5F,IAAI;CACJ,MAAM,UAAU,IAAI,SAAgB,YAAY;EAC9C,QAAQ,WAAW,SAAS,KAAK,IAAI,IAAI,YAAY,GAAG,KAAK;CAC/D,CAAC;CACD,IAAI;EACF,OAAO,MAAM,QAAQ,KAAK,CAAC,QAAQ,QAAQ,IAAI,CAAC,CAAC,WAAW,IAAI,GAAG,OAAO,CAAC;CAC7E,UAAU;EACR,aAAa,KAAK;CACpB;AACF"}
@@ -0,0 +1,21 @@
1
+ // src/transports/settled-within.mts
2
+ /** The longest delay a timer takes; a longer one fires at once. */
3
+ const MAX_DELAY_MS = 2 ** 31 - 1;
4
+ /**
5
+ * Whether `work` settles within `ms`, or within `MAX_DELAY_MS` when `ms` is
6
+ * longer. Rejects when it rejects in time; a later rejection is dropped.
7
+ */
8
+ async function settledWithin(work, ms) {
9
+ let timer;
10
+ const timeout = new Promise((resolve) => {
11
+ timer = setTimeout(resolve, Math.min(ms, MAX_DELAY_MS), false);
12
+ });
13
+ try {
14
+ return await Promise.race([Promise.resolve(work).then(() => true), timeout]);
15
+ } finally {
16
+ clearTimeout(timer);
17
+ }
18
+ }
19
+ export { settledWithin as n, MAX_DELAY_MS as t };
20
+
21
+ //# sourceMappingURL=settled-within-Bc2pj8WB.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"settled-within-Bc2pj8WB.mjs","names":[],"sources":["../src/transports/settled-within.mts"],"sourcesContent":["/** The longest delay a timer takes; a longer one fires at once. */\nexport const MAX_DELAY_MS = 2 ** 31 - 1\n\n/**\n * Whether `work` settles within `ms`, or within `MAX_DELAY_MS` when `ms` is\n * longer. Rejects when it rejects in time; a later rejection is dropped.\n */\nexport async function settledWithin(work: PromiseLike<unknown>, ms: number): Promise<boolean> {\n let timer: ReturnType<typeof setTimeout> | undefined\n const timeout = new Promise<false>((resolve) => {\n timer = setTimeout(resolve, Math.min(ms, MAX_DELAY_MS), false)\n })\n try {\n return await Promise.race([Promise.resolve(work).then(() => true), timeout])\n } finally {\n clearTimeout(timer)\n }\n}\n"],"mappings":";;AACA,MAAa,eAAe,KAAK,KAAK;;;;;AAMtC,eAAsB,cAAc,MAA4B,IAA8B;CAC5F,IAAI;CACJ,MAAM,UAAU,IAAI,SAAgB,YAAY;EAC9C,QAAQ,WAAW,SAAS,KAAK,IAAI,IAAI,YAAY,GAAG,KAAK;CAC/D,CAAC;CACD,IAAI;EACF,OAAO,MAAM,QAAQ,KAAK,CAAC,QAAQ,QAAQ,IAAI,CAAC,CAAC,WAAW,IAAI,GAAG,OAAO,CAAC;CAC7E,UAAU;EACR,aAAa,KAAK;CACpB;AACF"}