@tstdl/base 0.85.26 → 0.86.0-beta10

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 (225) hide show
  1. package/_container/decorators.d.ts +76 -0
  2. package/_container/decorators.js +110 -0
  3. package/_container/index.d.ts +10 -0
  4. package/_container/index.js +27 -0
  5. package/_container/interfaces.d.ts +16 -0
  6. package/_container/interfaces.js +26 -0
  7. package/_container/token.d.ts +18 -0
  8. package/_container/token.js +41 -0
  9. package/api/client/client.d.ts +2 -2
  10. package/api/client/client.js +5 -3
  11. package/api/server/api-controller.d.ts +2 -2
  12. package/api/server/api-controller.js +5 -4
  13. package/api/server/api-request-token.provider.js +2 -2
  14. package/api/server/gateway.d.ts +5 -6
  15. package/api/server/gateway.js +25 -12
  16. package/api/server/module.js +4 -4
  17. package/api/server/tokens.d.ts +4 -1
  18. package/api/server/tokens.js +8 -2
  19. package/application/application.d.ts +13 -10
  20. package/application/application.js +38 -45
  21. package/authentication/client/api.client.js +3 -3
  22. package/authentication/client/authentication.service.d.ts +4 -4
  23. package/authentication/client/authentication.service.js +20 -21
  24. package/authentication/client/http-client.middleware.d.ts +3 -5
  25. package/authentication/client/http-client.middleware.js +3 -12
  26. package/authentication/client/module.d.ts +2 -1
  27. package/authentication/client/module.js +15 -7
  28. package/authentication/client/tokens.d.ts +2 -2
  29. package/authentication/client/tokens.js +5 -4
  30. package/authentication/server/authentication-api-request-token.provider.js +2 -2
  31. package/authentication/server/authentication-secret-requirements.validator.js +2 -2
  32. package/authentication/server/authentication.service.d.ts +2 -2
  33. package/authentication/server/authentication.service.js +9 -9
  34. package/authentication/server/module.d.ts +2 -1
  35. package/authentication/server/module.js +8 -7
  36. package/authentication/server/mongo/mongo-authentication-credentials.repository.d.ts +3 -3
  37. package/authentication/server/mongo/mongo-authentication-credentials.repository.js +4 -4
  38. package/authentication/server/mongo/mongo-authentication-session.repository.d.ts +3 -3
  39. package/authentication/server/mongo/mongo-authentication-session.repository.js +4 -4
  40. package/browser/browser-context-controller.d.ts +4 -4
  41. package/browser/browser-context-controller.js +15 -9
  42. package/browser/browser-controller.d.ts +12 -5
  43. package/browser/browser-controller.js +24 -10
  44. package/browser/browser.service.d.ts +12 -6
  45. package/browser/browser.service.js +13 -10
  46. package/browser/module.js +2 -2
  47. package/container/decorators.d.ts +2 -76
  48. package/container/decorators.js +12 -88
  49. package/container/index.d.ts +0 -7
  50. package/container/index.js +0 -7
  51. package/container/interfaces.d.ts +2 -16
  52. package/container/interfaces.js +3 -4
  53. package/container/token.d.ts +2 -18
  54. package/container/token.js +4 -19
  55. package/core.d.ts +4 -2
  56. package/core.js +15 -8
  57. package/database/mongo/classes.d.ts +5 -5
  58. package/database/mongo/classes.js +5 -4
  59. package/database/mongo/module.js +24 -16
  60. package/database/mongo/mongo-entity-repository.d.ts +2 -2
  61. package/database/mongo/mongo-entity-repository.js +2 -2
  62. package/disposable/async-disposer.d.ts +4 -4
  63. package/distributed-loop/distributed-loop.d.ts +3 -3
  64. package/distributed-loop/distributed-loop.js +3 -3
  65. package/distributed-loop/provider.js +2 -2
  66. package/examples/api/authentication.js +17 -10
  67. package/examples/api/basic-overview.js +4 -5
  68. package/examples/api/custom-authentication.js +9 -6
  69. package/examples/api/streaming.js +5 -5
  70. package/examples/browser/basic.js +5 -5
  71. package/examples/http/client.js +6 -4
  72. package/examples/mail/basic.js +9 -4
  73. package/examples/pdf/basic.js +9 -5
  74. package/examples/template/basic.js +8 -6
  75. package/function/log.js +1 -1
  76. package/http/client/adapters/undici-http-client.adapter.js +7 -6
  77. package/http/client/http-client-options.d.ts +0 -5
  78. package/http/client/http-client-options.js +0 -4
  79. package/http/client/http-client.d.ts +5 -8
  80. package/http/client/http-client.js +10 -7
  81. package/http/client/middleware.d.ts +6 -0
  82. package/http/client/middleware.js +16 -0
  83. package/http/client/module.d.ts +6 -1
  84. package/http/client/module.js +10 -5
  85. package/http/client/tokens.d.ts +2 -0
  86. package/http/client/tokens.js +25 -0
  87. package/http/server/node/module.js +2 -2
  88. package/http/server/node/node-http-server.d.ts +1 -4
  89. package/http/server/node/node-http-server.js +3 -7
  90. package/image-service/imgproxy/imgproxy-image-service.d.ts +6 -8
  91. package/image-service/imgproxy/imgproxy-image-service.js +17 -16
  92. package/injector/decorators.d.ts +12 -6
  93. package/injector/decorators.js +14 -0
  94. package/injector/index.d.ts +11 -0
  95. package/injector/index.js +28 -0
  96. package/injector/inject.d.ts +6 -1
  97. package/injector/inject.js +14 -2
  98. package/injector/injector.d.ts +14 -34
  99. package/injector/injector.js +91 -48
  100. package/injector/interfaces.d.ts +7 -5
  101. package/injector/provider.d.ts +19 -14
  102. package/injector/token.d.ts +10 -3
  103. package/injector/token.js +1 -1
  104. package/injector/type-info.d.ts +2 -0
  105. package/injector/types.d.ts +13 -7
  106. package/key-value-store/key-value.store.d.ts +3 -3
  107. package/key-value-store/key-value.store.js +1 -1
  108. package/key-value-store/mongo/module.js +4 -4
  109. package/key-value-store/mongo/mongo-key-value-store.provider.js +2 -2
  110. package/key-value-store/mongo/mongo-key-value.repository.d.ts +3 -3
  111. package/key-value-store/mongo/mongo-key-value.repository.js +4 -4
  112. package/key-value-store/mongo/mongo-key-value.store.js +3 -3
  113. package/key-value-store/mongo/tokens.d.ts +1 -1
  114. package/key-value-store/mongo/tokens.js +1 -1
  115. package/lock/lock.d.ts +3 -2
  116. package/lock/lock.js +1 -0
  117. package/lock/mongo/lock.js +4 -4
  118. package/lock/mongo/module.js +3 -3
  119. package/lock/mongo/mongo-lock-repository.d.ts +3 -3
  120. package/lock/mongo/mongo-lock-repository.js +3 -3
  121. package/lock/mongo/provider.js +5 -5
  122. package/lock/provider.d.ts +3 -2
  123. package/lock/provider.js +1 -0
  124. package/lock/web/module.js +3 -3
  125. package/lock/web/web-lock.js +2 -2
  126. package/lock/web/web-lock.provider.js +3 -3
  127. package/logger/console/logger.js +2 -2
  128. package/logger/logger.d.ts +3 -2
  129. package/logger/logger.js +1 -0
  130. package/mail/clients/nodemailer.mail-client.js +6 -5
  131. package/mail/mail.client.d.ts +3 -2
  132. package/mail/mail.client.js +1 -0
  133. package/mail/mail.service.js +7 -7
  134. package/mail/module.js +5 -5
  135. package/mail/repositories/mongo-mail-log.repository.d.ts +3 -3
  136. package/mail/repositories/mongo-mail-log.repository.js +3 -3
  137. package/mail/tokens.d.ts +1 -1
  138. package/mail/tokens.js +2 -2
  139. package/message-bus/broadcast-channel/broadcast-channel-message-bus-provider.js +3 -3
  140. package/message-bus/broadcast-channel/broadcast-channel-message-bus.d.ts +1 -1
  141. package/message-bus/broadcast-channel/broadcast-channel-message-bus.js +3 -3
  142. package/message-bus/broadcast-channel/module.js +3 -3
  143. package/message-bus/local/local-message-bus-provider.js +4 -4
  144. package/message-bus/local/local-message-bus.d.ts +1 -1
  145. package/message-bus/local/local-message-bus.js +3 -3
  146. package/message-bus/local/module.js +3 -3
  147. package/message-bus/message-bus.d.ts +3 -3
  148. package/message-bus/message-bus.js +1 -0
  149. package/migration/index.d.ts +1 -1
  150. package/migration/index.js +1 -1
  151. package/migration/migrator.js +4 -4
  152. package/migration/mongo/migration-state-repository.d.ts +3 -3
  153. package/migration/mongo/migration-state-repository.js +4 -4
  154. package/migration/mongo/module.js +2 -2
  155. package/module/modules/web-server.module.d.ts +5 -10
  156. package/module/modules/web-server.module.js +16 -36
  157. package/notification/notification.service.js +2 -2
  158. package/object-storage/object-storage.d.ts +3 -3
  159. package/object-storage/object-storage.js +1 -0
  160. package/object-storage/s3/s3.object-storage-provider.js +6 -5
  161. package/object-storage/s3/s3.object-storage.d.ts +2 -2
  162. package/object-storage/s3/s3.object-storage.js +4 -4
  163. package/openid-connect/cached-oidc-configuration.service.js +3 -3
  164. package/openid-connect/index.d.ts +1 -1
  165. package/openid-connect/index.js +3 -3
  166. package/openid-connect/mongo-oidc-state.repository.d.ts +3 -3
  167. package/openid-connect/mongo-oidc-state.repository.js +6 -5
  168. package/openid-connect/oidc-configuration.service.js +2 -2
  169. package/openid-connect/oidc.service.js +4 -4
  170. package/package.json +1 -1
  171. package/pdf/pdf.service.d.ts +3 -3
  172. package/pdf/pdf.service.js +5 -5
  173. package/process-shutdown.d.ts +2 -2
  174. package/process-shutdown.js +6 -8
  175. package/queue/mongo/mongo-job.repository.d.ts +3 -3
  176. package/queue/mongo/mongo-job.repository.js +4 -4
  177. package/queue/mongo/queue.js +4 -4
  178. package/queue/mongo/queue.provider.d.ts +3 -3
  179. package/queue/mongo/queue.provider.js +8 -6
  180. package/queue/queue.d.ts +3 -3
  181. package/queue/queue.js +1 -1
  182. package/search-index/elastic/config.d.ts +3 -3
  183. package/search-index/elastic/config.js +4 -3
  184. package/search-index/elastic/module.d.ts +1 -3
  185. package/search-index/elastic/module.js +21 -18
  186. package/search-index/elastic/search-index.d.ts +2 -2
  187. package/search-index/elastic/search-index.js +2 -2
  188. package/templates/module.d.ts +2 -2
  189. package/templates/module.js +12 -26
  190. package/templates/providers/file.template-provider.d.ts +3 -3
  191. package/templates/providers/file.template-provider.js +5 -4
  192. package/templates/providers/memory.template-provider.js +2 -2
  193. package/templates/renderers/handlebars.template-renderer.js +2 -2
  194. package/templates/renderers/jsx.template-renderer.js +2 -2
  195. package/templates/renderers/mjml.template-renderer.js +3 -3
  196. package/templates/renderers/string.template-renderer.js +2 -2
  197. package/templates/resolvers/file.template-resolver.d.ts +3 -3
  198. package/templates/resolvers/file.template-resolver.js +6 -5
  199. package/templates/resolvers/jsx.template-resolver.js +2 -2
  200. package/templates/resolvers/string.template-resolver.js +2 -2
  201. package/templates/template-renderer.provider.js +3 -3
  202. package/templates/template-resolver.provider.js +3 -3
  203. package/templates/template.service.js +4 -4
  204. package/templates/tokens.d.ts +2 -2
  205. package/templates/tokens.js +3 -3
  206. package/text/dynamic-text.model.js +3 -4
  207. package/text/localization.service.js +3 -3
  208. package/theme/theme-service.d.ts +1 -1
  209. package/theme/theme-service.js +7 -6
  210. package/tokens.d.ts +1 -1
  211. package/tokens.js +2 -2
  212. /package/{container → _container}/container.d.ts +0 -0
  213. /package/{container → _container}/container.js +0 -0
  214. /package/{container → _container}/provider.d.ts +0 -0
  215. /package/{container → _container}/provider.js +0 -0
  216. /package/{container → _container}/resolve-chain.d.ts +0 -0
  217. /package/{container → _container}/resolve-chain.js +0 -0
  218. /package/{container → _container}/resolve.error.d.ts +0 -0
  219. /package/{container → _container}/resolve.error.js +0 -0
  220. /package/{container → _container}/type-info.d.ts +0 -0
  221. /package/{container → _container}/type-info.js +0 -0
  222. /package/{container → _container}/types.d.ts +0 -0
  223. /package/{container → _container}/types.js +0 -0
  224. /package/{container → _container}/utils.d.ts +0 -0
  225. /package/{container → _container}/utils.js +0 -0
@@ -0,0 +1,76 @@
1
+ import type { Decorator } from '../reflection/index.js';
2
+ import type { Constructor, OneOrMany, Simplify, TypedOmit } from '../types.js';
3
+ import type { RegistrationOptions } from './container.js';
4
+ import type { Provider } from './provider.js';
5
+ import type { InjectionToken } from './token.js';
6
+ import type { ArgumentProvider, ForwardRefInjectionToken, Mapper } from './types.js';
7
+ type InjectDecorator = Decorator<'property' | 'accessor' | 'constructorParameter'>;
8
+ export type InjectableOptions<T, A> = RegistrationOptions<T> & {
9
+ /** aliases (tokens) for the class. Useful for example for circular dependencies when you can't use the class itself as a token */
10
+ alias?: OneOrMany<InjectionToken>;
11
+ /** custom provider. Useful for example if initialization is required */
12
+ provider?: Provider<T, A>;
13
+ };
14
+ export type InjectableOptionsWithoutLifecycle<T, A> = Simplify<TypedOmit<InjectableOptions<T, A>, 'lifecycle'>>;
15
+ /**
16
+ * Helper decorator to replace a class definition with an other
17
+ * can be used for example to type external classes with the {@link Injectable} interface
18
+ * @param constructor class to replace with
19
+ */
20
+ export declare function replaceClass<T>(constructor: Constructor<T>): ClassDecorator;
21
+ /**
22
+ * registers the class in the global container. Decorated class is not modified in any way
23
+ * @param options registration options
24
+ */
25
+ export declare function injectable<T = any, A = any>(options?: InjectableOptions<T, A>): ClassDecorator;
26
+ /**
27
+ * registers the class in the global container with singleton lifecycle. Decorated class is not modified in any way
28
+ * @param options registration options
29
+ */
30
+ export declare function singleton<T = any, A = any>(options?: InjectableOptionsWithoutLifecycle<T, A>): ClassDecorator;
31
+ /**
32
+ * registers the class in the global container with scoped lifecycle. Decorated class is not modified in any way
33
+ * @param options registration options
34
+ */
35
+ export declare function scoped<T = any, A = any>(lifecycle: 'resolution', options?: InjectableOptionsWithoutLifecycle<T, A>): ClassDecorator;
36
+ /**
37
+ * sets the token used to resolve the parameter
38
+ * @param token token used for resolving
39
+ * @param argument resolve argument
40
+ * @param mapperOrKey map the resolved value. If {@link PropertyKey} is provided, that property of the resolved value will be injected
41
+ */
42
+ export declare function inject<T, A>(token?: InjectionToken<T, A>, argument?: A, mapperOrKey?: Mapper<T> | keyof T): InjectDecorator;
43
+ /**
44
+ * sets the argument used for resolving the parameter
45
+ * @param argument
46
+ */
47
+ export declare function resolveArg<T>(argument: T): InjectDecorator;
48
+ /**
49
+ * sets the argument provider used for resolving the parameter
50
+ * @param argumentProvider
51
+ */
52
+ export declare function resolveArgProvider<T>(argumentProvider: ArgumentProvider<T>): InjectDecorator;
53
+ /**
54
+ * injects the argument used for resolving the class instead of resolving the parameter
55
+ * @param argument
56
+ * @param mapperOrKey map the resolved value. If {@link PropertyKey} is provided, that property of the resolved value will be injected
57
+ */
58
+ export declare function injectArg<T>(mapperOrKey?: Mapper<T> | keyof T): InjectDecorator;
59
+ /**
60
+ * sets the argument used for resolving the decorated parameter to the the argument provided for parent resolve
61
+ * @param mapper map the argument (for example to select a property instead of forwarding the whole object)
62
+ */
63
+ export declare function forwardArg(): InjectDecorator;
64
+ export declare function forwardArg<T, U>(mapper: Mapper<T, U>): InjectDecorator;
65
+ /**
66
+ * marks the argument as optional
67
+ * @param argument
68
+ */
69
+ export declare function optional(): InjectDecorator;
70
+ /**
71
+ * resolve using ForwardRef to handle circular dependencies. Resolve logic derefs all ForwardRefs which are direct properties of resolved instances automatically
72
+ * @param token token to resolve
73
+ * @param argument resolve argument
74
+ */
75
+ export declare function forwardRef<T extends object, A>(token: ForwardRefInjectionToken<T>, argument?: A): InjectDecorator;
76
+ export {};
@@ -0,0 +1,110 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var decorators_exports = {};
20
+ __export(decorators_exports, {
21
+ forwardArg: () => forwardArg,
22
+ forwardRef: () => forwardRef,
23
+ inject: () => inject,
24
+ injectArg: () => injectArg,
25
+ injectable: () => injectable,
26
+ optional: () => optional,
27
+ replaceClass: () => replaceClass,
28
+ resolveArg: () => resolveArg,
29
+ resolveArgProvider: () => resolveArgProvider,
30
+ scoped: () => scoped,
31
+ singleton: () => singleton
32
+ });
33
+ module.exports = __toCommonJS(decorators_exports);
34
+ var import_reflection = require("../reflection/index.js");
35
+ var import_array = require("../utils/array/array.js");
36
+ var import_type_guards = require("../utils/type-guards.js");
37
+ var import_container = require("./container.js");
38
+ function replaceClass(constructor) {
39
+ return (0, import_reflection.createClassDecorator)({ handler: () => constructor });
40
+ }
41
+ function injectable(options = {}) {
42
+ return (0, import_reflection.createClassDecorator)({
43
+ data: { [import_container.injectMetadataSymbol]: {} },
44
+ mergeData: true,
45
+ handler: (data) => {
46
+ const { alias: aliases, provider, ...registrationOptions } = options;
47
+ const targetProvider = provider ?? { useClass: data.constructor };
48
+ import_container.container.register(data.constructor, targetProvider, registrationOptions);
49
+ if ((0, import_type_guards.isDefined)(aliases)) {
50
+ for (const alias of (0, import_array.toArray)(aliases)) {
51
+ import_container.container.register(alias, { useToken: data.constructor }, registrationOptions);
52
+ }
53
+ }
54
+ }
55
+ });
56
+ }
57
+ function singleton(options = {}) {
58
+ return injectable({ ...options, lifecycle: "singleton" });
59
+ }
60
+ function scoped(lifecycle, options = {}) {
61
+ return injectable({ ...options, lifecycle });
62
+ }
63
+ function inject(token, argument, mapperOrKey) {
64
+ const injectMetadata = {};
65
+ if ((0, import_type_guards.isDefined)(token)) {
66
+ injectMetadata.injectToken = token;
67
+ }
68
+ if ((0, import_type_guards.isDefined)(argument)) {
69
+ injectMetadata.resolveArgumentProvider = () => argument;
70
+ }
71
+ if ((0, import_type_guards.isDefined)(mapperOrKey)) {
72
+ injectMetadata.mapper = (0, import_type_guards.isFunction)(mapperOrKey) ? mapperOrKey : (value) => value[mapperOrKey];
73
+ }
74
+ return createInjectDecorator(injectMetadata);
75
+ }
76
+ function resolveArg(argument) {
77
+ return resolveArgProvider(() => argument);
78
+ }
79
+ function resolveArgProvider(argumentProvider) {
80
+ return createInjectDecorator({ resolveArgumentProvider: argumentProvider });
81
+ }
82
+ function injectArg(mapperOrKey) {
83
+ return createInjectDecorator({
84
+ injectArgumentMapper: (0, import_type_guards.isFunction)(mapperOrKey) ? mapperOrKey : (0, import_type_guards.isDefined)(mapperOrKey) ? (value) => value[mapperOrKey] : (value) => value
85
+ });
86
+ }
87
+ function forwardArg(mapper = (value) => value) {
88
+ return createInjectDecorator({ forwardArgumentMapper: mapper });
89
+ }
90
+ function optional() {
91
+ return createInjectDecorator({ optional: true });
92
+ }
93
+ function forwardRef(token, argument) {
94
+ const injectMetadata = {
95
+ forwardRefToken: token
96
+ };
97
+ if ((0, import_type_guards.isDefined)(argument)) {
98
+ injectMetadata.resolveArgumentProvider = () => argument;
99
+ }
100
+ return createInjectDecorator(injectMetadata);
101
+ }
102
+ function createInjectDecorator(metadata) {
103
+ return (0, import_reflection.createDecorator)({
104
+ property: true,
105
+ accessor: true,
106
+ constructorParameter: true,
107
+ data: { [import_container.injectMetadataSymbol]: metadata },
108
+ mergeData: true
109
+ });
110
+ }
@@ -0,0 +1,10 @@
1
+ export * from './container.js';
2
+ export * from './decorators.js';
3
+ export * from './interfaces.js';
4
+ export * from './provider.js';
5
+ export * from './resolve-chain.js';
6
+ export * from './resolve.error.js';
7
+ export * from './token.js';
8
+ export * from './type-info.js';
9
+ export * from './types.js';
10
+ export * from './utils.js';
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __copyProps = (to, from, except, desc) => {
7
+ if (from && typeof from === "object" || typeof from === "function") {
8
+ for (let key of __getOwnPropNames(from))
9
+ if (!__hasOwnProp.call(to, key) && key !== except)
10
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
11
+ }
12
+ return to;
13
+ };
14
+ var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
15
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
16
+ var container_exports = {};
17
+ module.exports = __toCommonJS(container_exports);
18
+ __reExport(container_exports, require("./container.js"), module.exports);
19
+ __reExport(container_exports, require("./decorators.js"), module.exports);
20
+ __reExport(container_exports, require("./interfaces.js"), module.exports);
21
+ __reExport(container_exports, require("./provider.js"), module.exports);
22
+ __reExport(container_exports, require("./resolve-chain.js"), module.exports);
23
+ __reExport(container_exports, require("./resolve.error.js"), module.exports);
24
+ __reExport(container_exports, require("./token.js"), module.exports);
25
+ __reExport(container_exports, require("./type-info.js"), module.exports);
26
+ __reExport(container_exports, require("./types.js"), module.exports);
27
+ __reExport(container_exports, require("./utils.js"), module.exports);
@@ -0,0 +1,16 @@
1
+ export declare const resolveArgumentType: unique symbol;
2
+ export declare const afterResolve: unique symbol;
3
+ export type InjectableArgument<T, Fallback> = T extends Injectable<infer A> ? A : Fallback;
4
+ export interface Injectable<T = unknown> {
5
+ /**
6
+ * type of resolve argument
7
+ * @deprecated only used for type inference
8
+ */
9
+ readonly [resolveArgumentType]: T;
10
+ }
11
+ export interface AfterResolve {
12
+ /**
13
+ * called after resolve through container
14
+ */
15
+ [afterResolve](): void | Promise<void>;
16
+ }
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var interfaces_exports = {};
20
+ __export(interfaces_exports, {
21
+ afterResolve: () => afterResolve,
22
+ resolveArgumentType: () => resolveArgumentType
23
+ });
24
+ module.exports = __toCommonJS(interfaces_exports);
25
+ const resolveArgumentType = Symbol("resolveArgumentType");
26
+ const afterResolve = Symbol("after resolve");
@@ -0,0 +1,18 @@
1
+ import type { AbstractConstructor, EnumerationObject } from '../types.js';
2
+ declare const type: unique symbol;
3
+ declare const argument: unique symbol;
4
+ export type ArgumentedInjectionToken<T, A> = SimpleInjectionToken<T> & {
5
+ [argument]?: A;
6
+ };
7
+ export type SimpleInjectionToken<T> = AbstractConstructor<T> | EnumerationObject;
8
+ export type InjectionToken<T = any, A = any> = SimpleInjectionToken<T> | ArgumentedInjectionToken<T, A> | ReifyingInjectionToken<T, A>;
9
+ export declare class ReifyingInjectionToken<T = any, A = any> {
10
+ private readonly [type];
11
+ private readonly [argument];
12
+ readonly description: string;
13
+ constructor(description: string);
14
+ toString(): string;
15
+ }
16
+ export declare function injectionToken<T, A = any>(description: string): InjectionToken<T, A>;
17
+ export declare function getTokenName(token: InjectionToken | undefined): string;
18
+ export {};
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var token_exports = {};
20
+ __export(token_exports, {
21
+ ReifyingInjectionToken: () => ReifyingInjectionToken,
22
+ getTokenName: () => getTokenName,
23
+ injectionToken: () => injectionToken
24
+ });
25
+ module.exports = __toCommonJS(token_exports);
26
+ var import_type_guards = require("../utils/type-guards.js");
27
+ class ReifyingInjectionToken {
28
+ description;
29
+ constructor(description) {
30
+ this.description = description;
31
+ }
32
+ toString() {
33
+ return `InjectionToken["${this.description}"]`;
34
+ }
35
+ }
36
+ function injectionToken(description) {
37
+ return new ReifyingInjectionToken(description);
38
+ }
39
+ function getTokenName(token) {
40
+ return (0, import_type_guards.isFunction)(token) ? token.name : (0, import_type_guards.isString)(token) ? `"${token}"` : String(token);
41
+ }
@@ -1,8 +1,8 @@
1
- import type { Injectable } from '../../container/index.js';
2
1
  import type { HttpClientOptions } from '../../http/client/index.js';
3
2
  import { HttpClient } from '../../http/client/index.js';
3
+ import type { Resolvable } from '../../injector/interfaces.js';
4
4
  import type { ApiClientImplementation, ApiDefinition, ApiEndpointDefinition } from '../types.js';
5
- export type ApiClient<T extends ApiDefinition> = new (httpClient: HttpClient) => ApiClientImplementation<T> & Injectable<HttpClientOptions>;
5
+ export type ApiClient<T extends ApiDefinition> = new (httpClient: HttpClient) => ApiClientImplementation<T> & Resolvable<HttpClientOptions>;
6
6
  export type ClientOptions = {
7
7
  /**
8
8
  * url prefix
@@ -23,9 +23,11 @@ __export(client_exports, {
23
23
  httpClientSymbol: () => httpClientSymbol
24
24
  });
25
25
  module.exports = __toCommonJS(client_exports);
26
- var import_container = require("../../container/index.js");
27
26
  var import_client = require("../../http/client/index.js");
28
27
  var import_types = require("../../http/types.js");
28
+ var import_inject = require("../../injector/inject.js");
29
+ var import_injector = require("../../injector/injector.js");
30
+ var import_interfaces = require("../../injector/interfaces.js");
29
31
  var import_schema = require("../../schema/index.js");
30
32
  var import_server_sent_events = require("../../sse/server-sent-events.js");
31
33
  var import_array = require("../../utils/array/array.js");
@@ -46,12 +48,12 @@ function compileClient(definition, options = {}) {
46
48
  [httpClientSymbol];
47
49
  [apiDefinitionSymbol];
48
50
  constructor(httpClientOrOptions) {
49
- this[httpClientSymbol] = httpClientOrOptions instanceof import_client.HttpClient ? httpClientOrOptions : import_container.container.resolve(import_client.HttpClient, httpClientOrOptions);
51
+ this[httpClientSymbol] = httpClientOrOptions instanceof import_client.HttpClient ? httpClientOrOptions : (0, import_inject.inject)(import_client.HttpClient, httpClientOrOptions);
50
52
  this[apiDefinitionSymbol] = definition;
51
53
  }
52
54
  }
53
55
  }[apiName];
54
- import_container.container.registerSingleton(api, {
56
+ import_injector.Injector.registerSingleton(api, {
55
57
  useFactory: (argument, context) => {
56
58
  const httpClient = argument instanceof import_client.HttpClient ? argument : context.resolve(import_client.HttpClient, argument ?? options.defaultHttpClientOptions);
57
59
  return new api(httpClient);
@@ -1,9 +1,9 @@
1
- import type { InjectableOptionsWithoutLifecycle } from '../../container/index.js';
1
+ import type { InjectableOptionsWithoutLifecycle } from '../../injector/decorators.js';
2
2
  import type { Constructor, Type } from '../../types.js';
3
3
  import type { ApiController, ApiDefinition } from '../types.js';
4
4
  type ApiDefinitionProvider = () => ApiDefinition;
5
5
  export declare const apiControllerDefinition: unique symbol;
6
- export declare function getApiControllerDefinition(controller: Type): ApiDefinition;
6
+ export declare function getApiControllerDefinition(controller: Type | ApiController): ApiDefinition;
7
7
  export declare function isApiController(controller: Type): boolean;
8
8
  export declare function ensureApiController(controller: Type): void;
9
9
  export declare function apiController<T = Type<ApiController>, A = any>(definition: ApiDefinition | ApiDefinitionProvider, injectableOptions?: InjectableOptionsWithoutLifecycle<T, A>): ClassDecorator;
@@ -26,14 +26,15 @@ __export(api_controller_exports, {
26
26
  isApiController: () => isApiController
27
27
  });
28
28
  module.exports = __toCommonJS(api_controller_exports);
29
- var import_container = require("../../container/index.js");
29
+ var import_decorators = require("../../injector/decorators.js");
30
30
  var import_object = require("../../utils/object/object.js");
31
31
  var import_type_guards = require("../../utils/type-guards.js");
32
32
  const apiControllerDefinition = Symbol("ApiController definition");
33
33
  const registeredApiControllers = /* @__PURE__ */ new Map();
34
34
  function getApiControllerDefinition(controller) {
35
- ensureApiController(controller);
36
- const definitionOrProvider = registeredApiControllers.get(controller);
35
+ const controllerType = (0, import_type_guards.isFunction)(controller) ? controller : controller.constructor;
36
+ ensureApiController(controllerType);
37
+ const definitionOrProvider = registeredApiControllers.get(controllerType);
37
38
  if ((0, import_type_guards.isFunction)(definitionOrProvider)) {
38
39
  return definitionOrProvider();
39
40
  }
@@ -50,7 +51,7 @@ function ensureApiController(controller) {
50
51
  function apiController(definition, injectableOptions = {}) {
51
52
  function apiControllerDecorator(constructor) {
52
53
  registeredApiControllers.set(constructor, definition);
53
- (0, import_container.singleton)(injectableOptions)(constructor);
54
+ (0, import_decorators.Singleton)(injectableOptions)(constructor);
54
55
  }
55
56
  return apiControllerDecorator;
56
57
  }
@@ -22,7 +22,7 @@ __export(api_request_token_provider_exports, {
22
22
  NoopApiRequestTokenProvider: () => NoopApiRequestTokenProvider
23
23
  });
24
24
  module.exports = __toCommonJS(api_request_token_provider_exports);
25
- var import_container = require("../../container/index.js");
25
+ var import_decorators = require("../../injector/decorators.js");
26
26
  var __decorate = function(decorators, target, key, desc) {
27
27
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
28
28
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
@@ -41,5 +41,5 @@ let NoopApiRequestTokenProvider = class NoopApiRequestTokenProvider2 extends Api
41
41
  }
42
42
  };
43
43
  NoopApiRequestTokenProvider = __decorate([
44
- (0, import_container.singleton)({ alias: ApiRequestTokenProvider })
44
+ (0, import_decorators.Singleton)({ alias: ApiRequestTokenProvider })
45
45
  ], NoopApiRequestTokenProvider);
@@ -1,9 +1,9 @@
1
1
  import 'urlpattern-polyfill';
2
- import type { Injectable } from '../../container/index.js';
3
- import { resolveArgumentType } from '../../container/index.js';
4
2
  import type { HttpServerRequestContext } from '../../http/server/http-server.js';
5
3
  import type { HttpServerRequest } from '../../http/server/index.js';
6
4
  import { HttpServerResponse } from '../../http/server/index.js';
5
+ import type { Resolvable } from '../../injector/index.js';
6
+ import { resolveArgumentType } from '../../injector/index.js';
7
7
  import { Logger } from '../../logger/index.js';
8
8
  import type { Type } from '../../types.js';
9
9
  import type { AsyncMiddleware, AsyncMiddlewareNext } from '../../utils/middleware.js';
@@ -18,7 +18,7 @@ export type ApiGatewayMiddlewareContext = {
18
18
  };
19
19
  export type ApiGatewayMiddlewareNext = AsyncMiddlewareNext<HttpServerRequest, HttpServerResponse>;
20
20
  export type ApiGatewayMiddleware = AsyncMiddleware<HttpServerRequest, HttpServerResponse, ApiGatewayMiddlewareContext>;
21
- export type ApiGatewayOptions = {
21
+ export declare abstract class ApiGatewayOptions {
22
22
  /**
23
23
  * Api prefix. Pass `null` to disable prefix.
24
24
  * @default api
@@ -35,7 +35,7 @@ export type ApiGatewayOptions = {
35
35
  * @default 10 MB
36
36
  */
37
37
  defaultMaxBytes?: number;
38
- };
38
+ }
39
39
  export type GatewayEndpoint = {
40
40
  definition: ApiEndpointDefinition;
41
41
  implementation: ApiEndpointServerImplementation;
@@ -55,7 +55,7 @@ export type ApiMetadata = {
55
55
  * router for {@link ApiTransport} requests to {@link ApiImplementation}
56
56
  * @todo error handling (standardized format, serialization etc.)
57
57
  */
58
- export declare class ApiGateway implements Injectable<ApiGatewayOptions> {
58
+ export declare class ApiGateway implements Resolvable<ApiGatewayOptions> {
59
59
  private readonly requestTokenProvider;
60
60
  private readonly logger;
61
61
  private readonly prefix;
@@ -69,7 +69,6 @@ export declare class ApiGateway implements Injectable<ApiGatewayOptions> {
69
69
  constructor(requestTokenProvider: ApiRequestTokenProvider, logger: Logger, options?: ApiGatewayOptions);
70
70
  addMiddleware(middleware: ApiGatewayMiddleware): void;
71
71
  supressErrors(...errorTypes: Type<Error>[]): void;
72
- registerApiController(controller: Type): Promise<void>;
73
72
  registerApi<T extends ApiDefinition>(definition: ApiDefinition, implementation: ApiController<T>): void;
74
73
  handleHttpServerRequestContext({ request, respond, close }: HttpServerRequestContext): Promise<void>;
75
74
  getApiMetadata(resource: URL): ApiMetadata;
@@ -18,15 +18,16 @@ var __copyProps = (to, from, except, desc) => {
18
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
19
  var gateway_exports = {};
20
20
  __export(gateway_exports, {
21
- ApiGateway: () => ApiGateway
21
+ ApiGateway: () => ApiGateway,
22
+ ApiGatewayOptions: () => ApiGatewayOptions
22
23
  });
23
24
  module.exports = __toCommonJS(gateway_exports);
24
25
  var import_urlpattern_polyfill = require("urlpattern-polyfill");
25
- var import_container = require("../../container/index.js");
26
26
  var import_bad_request_error = require("../../error/bad-request.error.js");
27
27
  var import_not_found_error = require("../../error/not-found.error.js");
28
28
  var import_not_implemented_error = require("../../error/not-implemented.error.js");
29
29
  var import_server = require("../../http/server/index.js");
30
+ var import_injector = require("../../injector/index.js");
30
31
  var import_logger = require("../../logger/index.js");
31
32
  var import_schema = require("../../schema/index.js");
32
33
  var import_server_sent_events_source = require("../../sse/server-sent-events-source.js");
@@ -37,7 +38,6 @@ var import_type_guards = require("../../utils/type-guards.js");
37
38
  var import_units = require("../../utils/units.js");
38
39
  var import_types = require("../types.js");
39
40
  var import_utils = require("../utils.js");
40
- var import_api_controller = require("./api-controller.js");
41
41
  var import_api_request_token_provider = require("./api-request-token.provider.js");
42
42
  var import_error_handler = require("./error-handler.js");
43
43
  var import_middlewares = require("./middlewares/index.js");
@@ -62,6 +62,24 @@ var __param = function(paramIndex, decorator) {
62
62
  };
63
63
  };
64
64
  const defaultMaxBytes = 10 * import_units.mebibyte;
65
+ class ApiGatewayOptions {
66
+ /**
67
+ * Api prefix. Pass `null` to disable prefix.
68
+ * @default api
69
+ */
70
+ prefix;
71
+ /** Initial middlewares */
72
+ middlewares;
73
+ /** Errors to supress in log output */
74
+ supressedErrors;
75
+ /** Cors middleware options */
76
+ cors;
77
+ /**
78
+ * Maximum size of request body. Useful to prevent harmful requests.
79
+ * @default 10 MB
80
+ */
81
+ defaultMaxBytes;
82
+ }
65
83
  let ApiGateway = class ApiGateway2 {
66
84
  requestTokenProvider;
67
85
  logger;
@@ -92,11 +110,6 @@ let ApiGateway = class ApiGateway2 {
92
110
  this.supressedErrors.add(type);
93
111
  }
94
112
  }
95
- async registerApiController(controller) {
96
- const definition = (0, import_api_controller.getApiControllerDefinition)(controller);
97
- const instance = await import_container.container.resolveAsync(controller);
98
- this.registerApi(definition, instance);
99
- }
100
113
  registerApi(definition, implementation) {
101
114
  for (const [name, endpointDefinition] of (0, import_types.normalizedApiDefinitionEndpointsEntries)(definition.endpoints)) {
102
115
  const versionArray = (0, import_type_guards.isUndefined)(endpointDefinition.version) ? [1] : (0, import_array.toArray)(endpointDefinition.version);
@@ -221,10 +234,10 @@ let ApiGateway = class ApiGateway2 {
221
234
  }
222
235
  };
223
236
  ApiGateway = __decorate([
224
- (0, import_container.singleton)({
237
+ (0, import_injector.Singleton)({
225
238
  defaultArgumentProvider: (context) => context.resolve(import_tokens.API_MODULE_OPTIONS).gatewayOptions
226
239
  }),
227
- __param(1, (0, import_container.resolveArg)("ApiGateway")),
228
- __param(2, (0, import_container.injectArg)()),
229
- __metadata("design:paramtypes", [import_api_request_token_provider.ApiRequestTokenProvider, import_logger.Logger, Object])
240
+ __param(1, (0, import_injector.ResolveArg)("ApiGateway")),
241
+ __param(2, (0, import_injector.InjectArg)()),
242
+ __metadata("design:paramtypes", [import_api_request_token_provider.ApiRequestTokenProvider, import_logger.Logger, ApiGatewayOptions])
230
243
  ], ApiGateway);
@@ -22,7 +22,7 @@ __export(module_exports, {
22
22
  configureApiServer: () => configureApiServer
23
23
  });
24
24
  module.exports = __toCommonJS(module_exports);
25
- var import_container = require("../../container/index.js");
25
+ var import_injector = require("../../injector/injector.js");
26
26
  var import_type_guards = require("../../utils/type-guards.js");
27
27
  var import_api_controller = require("./api-controller.js");
28
28
  var import_api_request_token_provider = require("./api-request-token.provider.js");
@@ -34,12 +34,12 @@ function configureApiServer(options) {
34
34
  if ((0, import_type_guards.isDefined)(options.controllers)) {
35
35
  for (const controller of options.controllers) {
36
36
  (0, import_api_controller.ensureApiController)(controller);
37
+ import_injector.Injector.register(import_tokens.API_CONTROLLER, { useToken: controller }, { multi: true });
37
38
  }
38
- apiModuleOptions.controllers = options.controllers;
39
39
  }
40
40
  if ((0, import_type_guards.isDefined)(options.requestTokenProvider)) {
41
- import_container.container.registerSingleton(import_api_request_token_provider.ApiRequestTokenProvider, { useToken: options.requestTokenProvider });
41
+ import_injector.Injector.register(import_api_request_token_provider.ApiRequestTokenProvider, { useToken: options.requestTokenProvider });
42
42
  }
43
43
  apiModuleOptions.gatewayOptions = options.gatewayOptions ?? apiModuleOptions.gatewayOptions;
44
- import_container.container.register(import_tokens.API_MODULE_OPTIONS, { useValue: apiModuleOptions });
44
+ import_injector.Injector.register(import_tokens.API_MODULE_OPTIONS, { useValue: apiModuleOptions });
45
45
  }
@@ -1,2 +1,5 @@
1
+ import type { ApiController } from '../types.js';
1
2
  import type { ApiModuleOptions } from './module.js';
2
- export declare const API_MODULE_OPTIONS: import("../../container/index.js").InjectionToken<ApiModuleOptions, any>;
3
+ export declare const API_MODULE_OPTIONS: import("../../injector/token.js").InjectionToken<ApiModuleOptions, never>;
4
+ export declare const API_CONTROLLER: import("../../injector/token.js").InjectionToken<ApiController, never>;
5
+ export declare const API_CONTROLLERS: import("../../injector/token.js").InjectionToken<ApiController[], never>;
@@ -18,8 +18,14 @@ var __copyProps = (to, from, except, desc) => {
18
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
19
  var tokens_exports = {};
20
20
  __export(tokens_exports, {
21
+ API_CONTROLLER: () => API_CONTROLLER,
22
+ API_CONTROLLERS: () => API_CONTROLLERS,
21
23
  API_MODULE_OPTIONS: () => API_MODULE_OPTIONS
22
24
  });
23
25
  module.exports = __toCommonJS(tokens_exports);
24
- var import_container = require("../../container/index.js");
25
- const API_MODULE_OPTIONS = (0, import_container.injectionToken)("ApiModuleOptions");
26
+ var import_injector = require("../../injector/injector.js");
27
+ var import_token = require("../../injector/token.js");
28
+ const API_MODULE_OPTIONS = (0, import_token.injectionToken)("ApiModuleOptions");
29
+ const API_CONTROLLER = (0, import_token.injectionToken)("ApiController");
30
+ const API_CONTROLLERS = (0, import_token.injectionToken)("ApiControllers");
31
+ import_injector.Injector.register(API_CONTROLLERS, { useToken: API_CONTROLLER, resolveAll: true });
@@ -1,27 +1,30 @@
1
- import { Logger } from '../logger/index.js';
1
+ import type { Resolvable } from '../injector/interfaces.js';
2
+ import { resolveArgumentType } from '../injector/interfaces.js';
3
+ import type { LoggerArgument } from '../logger/index.js';
2
4
  import type { Module } from '../module/module.js';
3
5
  import type { FunctionModuleFunction } from '../module/modules/function.module.js';
4
6
  import type { OneOrMany, Type } from '../types.js';
5
7
  import type { ReadonlyCancellationToken } from '../utils/cancellation-token.js';
6
- export declare class Application {
7
- private static _instance;
8
+ export type BootstrapFn = () => void | Promise<void>;
9
+ export type RunOptions = {
10
+ bootstrap?: BootstrapFn;
11
+ };
12
+ export declare class Application implements Resolvable<LoggerArgument> {
13
+ #private;
14
+ static _instance: Application | undefined;
8
15
  private static get instance();
9
- private readonly logger;
10
- private readonly moduleTypesAndInstances;
11
- private readonly shutdownPromise;
12
- private readonly _shutdownToken;
16
+ readonly [resolveArgumentType]: string;
13
17
  get shutdownToken(): ReadonlyCancellationToken;
14
18
  static get shutdownToken(): ReadonlyCancellationToken;
15
- constructor(logger: Logger);
16
19
  static registerModule(moduleType: Type<Module>): void;
17
20
  static registerModuleFunction(fn: FunctionModuleFunction): void;
18
- static run(...functionsAndModules: OneOrMany<FunctionModuleFunction | Type<Module>>[]): void;
21
+ static run(...functionsAndModules: [RunOptions | OneOrMany<FunctionModuleFunction | Type<Module>>, ...OneOrMany<FunctionModuleFunction | Type<Module>>[]]): void;
19
22
  static waitForShutdown(): Promise<void>;
20
23
  static shutdown(): Promise<void>;
21
24
  static requestShutdown(): void;
22
25
  registerModule(moduleType: Module | Type<Module>): void;
23
26
  registerModuleFunction(fn: FunctionModuleFunction): void;
24
- run(...functionsAndModules: OneOrMany<FunctionModuleFunction | Type<Module>>[]): void;
27
+ run(...optionsFunctionsAndModules: [RunOptions | OneOrMany<FunctionModuleFunction | Type<Module>>, ...OneOrMany<FunctionModuleFunction | Type<Module>>[]]): void;
25
28
  shutdown(): Promise<void>;
26
29
  requestShutdown(): void;
27
30
  waitForShutdown(): Promise<void>;