@spinajs/configuration 2.0.556 → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (89) hide show
  1. package/lib/cjs/config/configuration.d.ts +1 -5
  2. package/lib/cjs/config/configuration.d.ts.map +1 -1
  3. package/lib/cjs/config/configuration.js +3 -1
  4. package/lib/cjs/config/configuration.js.map +1 -1
  5. package/lib/cjs/configuration.d.ts +24 -1
  6. package/lib/cjs/configuration.d.ts.map +1 -1
  7. package/lib/cjs/configuration.js +357 -82
  8. package/lib/cjs/configuration.js.map +1 -1
  9. package/lib/cjs/decorators.d.ts +77 -4
  10. package/lib/cjs/decorators.d.ts.map +1 -1
  11. package/lib/cjs/decorators.js +212 -11
  12. package/lib/cjs/decorators.js.map +1 -1
  13. package/lib/cjs/exception.d.ts +9 -1
  14. package/lib/cjs/exception.d.ts.map +1 -1
  15. package/lib/cjs/exception.js +2 -1
  16. package/lib/cjs/exception.js.map +1 -1
  17. package/lib/cjs/helpers.d.ts.map +1 -1
  18. package/lib/cjs/helpers.js +3 -2
  19. package/lib/cjs/helpers.js.map +1 -1
  20. package/lib/cjs/index.browser.d.ts +1 -0
  21. package/lib/cjs/index.browser.d.ts.map +1 -1
  22. package/lib/cjs/index.browser.js +4 -0
  23. package/lib/cjs/index.browser.js.map +1 -1
  24. package/lib/cjs/index.d.ts +3 -0
  25. package/lib/cjs/index.d.ts.map +1 -1
  26. package/lib/cjs/index.js +6 -0
  27. package/lib/cjs/index.js.map +1 -1
  28. package/lib/cjs/lib-dirs.d.ts +8 -0
  29. package/lib/cjs/lib-dirs.d.ts.map +1 -0
  30. package/lib/cjs/lib-dirs.js +16 -0
  31. package/lib/cjs/lib-dirs.js.map +1 -0
  32. package/lib/cjs/schemas.d.ts +20 -0
  33. package/lib/cjs/schemas.d.ts.map +1 -0
  34. package/lib/cjs/schemas.js +58 -0
  35. package/lib/cjs/schemas.js.map +1 -0
  36. package/lib/cjs/sources.d.ts +9 -3
  37. package/lib/cjs/sources.d.ts.map +1 -1
  38. package/lib/cjs/sources.js +27 -10
  39. package/lib/cjs/sources.js.map +1 -1
  40. package/lib/cjs/util.d.ts +8 -0
  41. package/lib/cjs/util.d.ts.map +1 -1
  42. package/lib/cjs/util.js +7 -1
  43. package/lib/cjs/util.js.map +1 -1
  44. package/lib/mjs/config/configuration.d.ts +1 -5
  45. package/lib/mjs/config/configuration.d.ts.map +1 -1
  46. package/lib/mjs/config/configuration.js +3 -1
  47. package/lib/mjs/config/configuration.js.map +1 -1
  48. package/lib/mjs/configuration.d.ts +24 -1
  49. package/lib/mjs/configuration.d.ts.map +1 -1
  50. package/lib/mjs/configuration.js +326 -84
  51. package/lib/mjs/configuration.js.map +1 -1
  52. package/lib/mjs/decorators.d.ts +77 -4
  53. package/lib/mjs/decorators.d.ts.map +1 -1
  54. package/lib/mjs/decorators.js +207 -12
  55. package/lib/mjs/decorators.js.map +1 -1
  56. package/lib/mjs/exception.d.ts +9 -1
  57. package/lib/mjs/exception.d.ts.map +1 -1
  58. package/lib/mjs/exception.js +2 -1
  59. package/lib/mjs/exception.js.map +1 -1
  60. package/lib/mjs/helpers.d.ts.map +1 -1
  61. package/lib/mjs/helpers.js +3 -2
  62. package/lib/mjs/helpers.js.map +1 -1
  63. package/lib/mjs/index.browser.d.ts +1 -0
  64. package/lib/mjs/index.browser.d.ts.map +1 -1
  65. package/lib/mjs/index.browser.js +1 -0
  66. package/lib/mjs/index.browser.js.map +1 -1
  67. package/lib/mjs/index.d.ts +3 -0
  68. package/lib/mjs/index.d.ts.map +1 -1
  69. package/lib/mjs/index.js +3 -0
  70. package/lib/mjs/index.js.map +1 -1
  71. package/lib/mjs/lib-dirs.d.ts +8 -0
  72. package/lib/mjs/lib-dirs.d.ts.map +1 -0
  73. package/lib/mjs/lib-dirs.js +13 -0
  74. package/lib/mjs/lib-dirs.js.map +1 -0
  75. package/lib/mjs/schemas.d.ts +20 -0
  76. package/lib/mjs/schemas.d.ts.map +1 -0
  77. package/lib/mjs/schemas.js +54 -0
  78. package/lib/mjs/schemas.js.map +1 -0
  79. package/lib/mjs/sources.d.ts +9 -3
  80. package/lib/mjs/sources.d.ts.map +1 -1
  81. package/lib/mjs/sources.js +27 -10
  82. package/lib/mjs/sources.js.map +1 -1
  83. package/lib/mjs/util.d.ts +8 -0
  84. package/lib/mjs/util.d.ts.map +1 -1
  85. package/lib/mjs/util.js +4 -0
  86. package/lib/mjs/util.js.map +1 -1
  87. package/lib/tsconfig.cjs.tsbuildinfo +1 -1
  88. package/lib/tsconfig.mjs.tsbuildinfo +1 -1
  89. package/package.json +7 -7
@@ -1,13 +1,21 @@
1
1
  import { IConfigEntryOptions } from '@spinajs/configuration-common';
2
- import { Class } from '@spinajs/di';
2
+ import { Class, IContainer } from '@spinajs/di';
3
+ export declare const CONFIGURATION_CONTAINER_KEY = "__configurationContainer__";
4
+ /** Makes the `@Config` properties of `instance`, built with `new` rather than by DI, read the Configuration of `container`. */
5
+ export declare function bindConfigurationContainer<T extends object>(instance: T, container: IContainer): T;
3
6
  /**
4
7
  * Injects configuration value into a class property.
5
8
  *
6
- * The decorated property is replaced with a lazy getter. Every read resolves the
7
- * {@link Configuration} service and calls `config.get(path, options.defaultValue)`,
9
+ * The decorated property is replaced with a lazy getter. Every read asks the
10
+ * {@link Configuration} of the container that built the instance, which must be resolved
11
+ * before the property is read, and calls `config.get(path, options.defaultValue)`,
8
12
  * so the property always reflects the current (possibly reloaded / watched) value
9
13
  * instead of a snapshot taken at construction time.
10
14
  *
15
+ * Properties are read in `resolve()` or later. During the constructor or a field initializer
16
+ * the container is not injected yet, so the root Configuration is read (as for an instance
17
+ * built with `new`).
18
+ *
11
19
  * Besides defining the getter, the decorator registers `{ path, options }` in the DI
12
20
  * container under `__configuration_property__`. Other modules listen for these
13
21
  * registrations - eg. `@spinajs/configuration-db-source` uses them to persist
@@ -82,6 +90,67 @@ import { Class } from '@spinajs/di';
82
90
  * @returns property decorator
83
91
  */
84
92
  export declare function Config(path: string, options?: IConfigEntryOptions): (target: any, key: string) => any;
93
+ export interface IAutoinjectServiceOptions {
94
+ /** Services are looked up by registration name across the container lineage, nearest container first. */
95
+ lineage: true;
96
+ /** The configured list is injected as a Map keyed by this property of each entry; the instance must carry the same value. */
97
+ keyBy: string;
98
+ }
99
+ /**
100
+ * Resolves the services named by the list at `path` in `container`: the entries,
101
+ * each `{ [keyBy], service }`, in list order. An unset path gives an empty Map.
102
+ *
103
+ * Not for classes the Configuration itself resolves (sources, protocols): it awaits that Configuration.
104
+ *
105
+ * @throws ServiceNotFound when no registration of `type` is named as an entry's service
106
+ * @throws InvalidOption when the value is not a list, a key is listed twice, or an instance's key differs from its entry's
107
+ */
108
+ export declare function resolveNamedServices<T>(container: IContainer, path: string, type: Class<T>, options: IAutoinjectServiceOptions): Promise<Map<string, T>>;
109
+ /**
110
+ * Injects what {@link resolveNamedServices} gives for `path` in the resolving container: a Map keyed by each entry's
111
+ * `keyBy`, in list order, looked up across the container lineage. Resolved when the instance is built, so an unknown
112
+ * service or a bad list rejects that resolve.
113
+ *
114
+ * @example
115
+ * ```ts
116
+ * @AutoinjectNamedServices('authn.mfa.steps', MfaStep, { lineage: true, keyBy: 'name' })
117
+ * protected Steps: Map<string, MfaStep>;
118
+ * ```
119
+ */
120
+ export declare function AutoinjectNamedServices<T>(path: string, type: Class<T>, options: IAutoinjectServiceOptions): any;
121
+ export interface INamedServiceOptions<T> {
122
+ /**
123
+ * Used when the value at `path` is unset or ''. A class must be a subclass of `type`; any other function is treated
124
+ * as a picker, which gets the registered names and returns one, or undefined when none fits.
125
+ */
126
+ default?: string | Class<T> | ((registered: readonly string[]) => string | undefined);
127
+ /** Duck check of the resolved instance (instanceof fails across cjs/mjs copies). */
128
+ is?: (instance: unknown) => boolean;
129
+ /** Undefined instead of InvalidOption when no name applies: the value is unset and there is no default, or the picker returns none. */
130
+ optional?: boolean;
131
+ }
132
+ /**
133
+ * The one service of `type` named by the value at `path` in `container`'s configuration, or by `options.default` when
134
+ * that is unset. Looked up by registration name across the container lineage, nearest container first.
135
+ * Not for classes the Configuration itself resolves (sources, protocols): it awaits that Configuration.
136
+ *
137
+ * @throws InvalidOption when the value is not a string, no name applies (unless `options.optional`), the name is not registered, or `options.is` rejects the instance
138
+ */
139
+ export declare function resolveNamedService<T>(container: IContainer, path: string, type: Class<T>, options: INamedServiceOptions<T> & {
140
+ optional: true;
141
+ }): Promise<T | undefined>;
142
+ export declare function resolveNamedService<T>(container: IContainer, path: string, type: Class<T>, options?: INamedServiceOptions<T>): Promise<T>;
143
+ /**
144
+ * Injects {@link resolveNamedService} for `path` in the resolving container, when the instance is built. With
145
+ * `optional: true` an unset `path` injects undefined.
146
+ *
147
+ * @example
148
+ * ```ts
149
+ * @AutoinjectNamedService('authn.mfa.policy.service', MfaPolicy, { default: 'DefaultMfaPolicy' })
150
+ * protected Policy: MfaPolicy;
151
+ * ```
152
+ */
153
+ export declare function AutoinjectNamedService<T>(path: string, type: Class<T>, options?: INamedServiceOptions<T>): any;
85
154
  /**
86
155
  * Inject service based on configuration.
87
156
  * Configuration could be object or string containing service
@@ -91,6 +160,10 @@ export declare function Config(path: string, options?: IConfigEntryOptions): (ta
91
160
  *
92
161
  * @param path - configuration path where service type is stored
93
162
  * @param type - if type is provided, it will override type obtain from reflection. Use it specific with arrays and maps, becouse ts reflection module cannot extract array and map type data
163
+ * @param options - `optional: true` leaves the property undefined (with a warning) when the value at `path` is empty
164
+ * @throws InvalidOperation when the value at `path` is empty and the injection is not optional
94
165
  */
95
- export declare function AutoinjectService(path: string, type?: Class<unknown>): any;
166
+ export declare function AutoinjectService(path: string, type?: Class<unknown>, options?: {
167
+ optional?: boolean;
168
+ }): any;
96
169
  //# sourceMappingURL=decorators.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"decorators.d.ts","sourceRoot":"","sources":["../../src/decorators.ts"],"names":[],"mappings":"AAEA,OAAO,EAAiB,mBAAmB,EAAE,MAAM,+BAA+B,CAAC;AACnF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O,CAAC,EAAE,oBAAoB,CAAC,CAAC,CAAC,OAUxG;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,KAAK,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC,EAAE;IAAE,QAAQ,CAAC,EAAE,OAAO,CAAA;CAAE,OAuDtG"}
@@ -1,16 +1,76 @@
1
1
  import _ from 'lodash';
2
2
  /* eslint-disable @typescript-eslint/no-explicit-any */
3
3
  import { Configuration } from '@spinajs/configuration-common';
4
- import { AddDependencyForProperty, DI } from '@spinajs/di';
4
+ import { AddDependencyForProperty, Container, DI, isFactory, isPromise, ServiceNotFound } from '@spinajs/di';
5
+ import { InvalidOperation, InvalidOption } from '@spinajs/exceptions';
5
6
  import { InternalLogger } from '@spinajs/internal-logger';
7
+ export const CONFIGURATION_CONTAINER_KEY = '__configurationContainer__';
8
+ /** Makes the `@Config` properties of `instance`, built with `new` rather than by DI, read the Configuration of `container`. */
9
+ export function bindConfigurationContainer(instance, container) {
10
+ Object.defineProperty(instance, CONFIGURATION_CONTAINER_KEY, { value: container, configurable: true, writable: true });
11
+ return instance;
12
+ }
13
+ /**
14
+ * Reads the Configuration owned by the nearest container (self or ancestor) that registers one.
15
+ * Never goes through `Container.get`'s parent walk: it matches by type name, so a same-named
16
+ * class in an ancestor would hand out the ancestor's instance.
17
+ */
18
+ function getOwnConfiguration(container) {
19
+ const owner = configurationOwner(container) ?? DI.RootContainer;
20
+ if (registersFactory(owner)) {
21
+ // A factory result is never cached, so it can only be read by resolving it.
22
+ const resolved = owner.resolve(Configuration);
23
+ if (isPromise(resolved)) {
24
+ resolved.catch(() => undefined);
25
+ return null;
26
+ }
27
+ return resolved;
28
+ }
29
+ return owner.get(Configuration, false);
30
+ }
31
+ function registersFactory(owner) {
32
+ const types = owner.getRegisteredTypes(Configuration, false) ?? [];
33
+ return isFactory(types[types.length - 1]);
34
+ }
35
+ /** The nearest container (self or ancestor) that registers a Configuration. */
36
+ function configurationOwner(container) {
37
+ let owner = container;
38
+ while (owner && !owner.Registry.ownsRegistration(Configuration)) {
39
+ owner = owner.Parent;
40
+ }
41
+ return owner;
42
+ }
43
+ /**
44
+ * {@link getOwnConfiguration}, resolving the owner's Configuration first when it is registered but not resolved yet:
45
+ * property dependencies resolve together, so `@Autoinject(Configuration)` cannot run before this. A resolve already
46
+ * in flight is shared by the container. Null only when no container in the lineage registers a Configuration.
47
+ */
48
+ async function resolveOwnConfiguration(container) {
49
+ const owner = configurationOwner(container);
50
+ // A factory result is never cached: one resolve is the only read, a second would run the factory again.
51
+ if (owner && registersFactory(owner))
52
+ return (await owner.resolve(Configuration));
53
+ const cfg = getOwnConfiguration(container);
54
+ if (cfg)
55
+ return cfg;
56
+ if (!owner)
57
+ return null;
58
+ const resolved = (await owner.resolve(Configuration));
59
+ return getOwnConfiguration(container) ?? resolved;
60
+ }
6
61
  /**
7
62
  * Injects configuration value into a class property.
8
63
  *
9
- * The decorated property is replaced with a lazy getter. Every read resolves the
10
- * {@link Configuration} service and calls `config.get(path, options.defaultValue)`,
64
+ * The decorated property is replaced with a lazy getter. Every read asks the
65
+ * {@link Configuration} of the container that built the instance, which must be resolved
66
+ * before the property is read, and calls `config.get(path, options.defaultValue)`,
11
67
  * so the property always reflects the current (possibly reloaded / watched) value
12
68
  * instead of a snapshot taken at construction time.
13
69
  *
70
+ * Properties are read in `resolve()` or later. During the constructor or a field initializer
71
+ * the container is not injected yet, so the root Configuration is read (as for an instance
72
+ * built with `new`).
73
+ *
14
74
  * Besides defining the getter, the decorator registers `{ path, options }` in the DI
15
75
  * container under `__configuration_property__`. Other modules listen for these
16
76
  * registrations - eg. `@spinajs/configuration-db-source` uses them to persist
@@ -88,17 +148,147 @@ export function Config(path, options) {
88
148
  return (target, key) => {
89
149
  // register conf, so we can expose eg. in db if config is set
90
150
  DI.register({ path, options }).asValue('__configuration_property__');
91
- const getter = () => {
92
- const config = DI.get(Configuration);
93
- return config.get(path, options ? options.defaultValue ?? undefined : undefined);
94
- };
151
+ // The container is injected, not the (async) Configuration, so the class keeps resolving synchronously.
152
+ AddDependencyForProperty((descriptor) => {
153
+ if (!descriptor.inject.some((i) => i.autoinjectKey === CONFIGURATION_CONTAINER_KEY)) {
154
+ descriptor.inject.push({ autoinject: true, autoinjectKey: CONFIGURATION_CONTAINER_KEY, inject: Container, mapFunc: undefined });
155
+ }
156
+ })(target, key);
95
157
  Object.defineProperty(target, key, {
96
- get: getter,
158
+ get() {
159
+ const container = this[CONFIGURATION_CONTAINER_KEY];
160
+ const config = container ? getOwnConfiguration(container) : DI.get(Configuration);
161
+ if (!config) {
162
+ throw new InvalidOperation(`Cannot read configuration path ${path}: the Configuration of the container is not resolved`);
163
+ }
164
+ return config.get(path, options ? options.defaultValue ?? undefined : undefined);
165
+ },
97
166
  enumerable: false,
98
167
  configurable: false,
99
168
  });
100
169
  };
101
170
  }
171
+ const q = (v) => JSON.stringify(v) ?? String(v);
172
+ /**
173
+ * Resolves the services named by the list at `path` in `container`: the entries,
174
+ * each `{ [keyBy], service }`, in list order. An unset path gives an empty Map.
175
+ *
176
+ * Not for classes the Configuration itself resolves (sources, protocols): it awaits that Configuration.
177
+ *
178
+ * @throws ServiceNotFound when no registration of `type` is named as an entry's service
179
+ * @throws InvalidOption when the value is not a list, a key is listed twice, or an instance's key differs from its entry's
180
+ */
181
+ export async function resolveNamedServices(container, path, type, options) {
182
+ const cfg = await resolveOwnConfiguration(container);
183
+ if (!cfg) {
184
+ throw new InvalidOperation(`Cannot resolve the services of ${path}: no container in the lineage registers a Configuration`);
185
+ }
186
+ const { keyBy } = options;
187
+ const entries = cfg.get(path) ?? [];
188
+ if (!Array.isArray(entries)) {
189
+ throw new InvalidOption(`${path} must be a list`);
190
+ }
191
+ const registered = container.getRegisteredNames(type);
192
+ const services = new Map();
193
+ for (const entry of entries) {
194
+ const key = entry?.[keyBy];
195
+ const service = entry?.service;
196
+ if (typeof key !== 'string' || typeof service !== 'string') {
197
+ throw new InvalidOption(`${path}: every entry needs a string ${keyBy} and service`);
198
+ }
199
+ if (services.has(key)) {
200
+ throw new InvalidOption(`${path} lists ${keyBy} ${q(key)} twice`);
201
+ }
202
+ if (!registered.includes(service)) {
203
+ throw new ServiceNotFound(`${path} entry ${q(key)}: no ${type.name} is registered as service ${q(service)}`);
204
+ }
205
+ const instance = await container.resolveNamed(type, service);
206
+ const own = instance?.[keyBy];
207
+ if (own !== key) {
208
+ const has = typeof own === 'string' ? `${keyBy} ${q(own)}` : `no ${keyBy}`;
209
+ throw new InvalidOption(`${path} entry ${q(key)} (service ${q(service)}): the service has ${has}; the entry must match it`);
210
+ }
211
+ services.set(key, instance);
212
+ }
213
+ return services;
214
+ }
215
+ /**
216
+ * Injects what {@link resolveNamedServices} gives for `path` in the resolving container: a Map keyed by each entry's
217
+ * `keyBy`, in list order, looked up across the container lineage. Resolved when the instance is built, so an unknown
218
+ * service or a bad list rejects that resolve.
219
+ *
220
+ * @example
221
+ * ```ts
222
+ * @AutoinjectNamedServices('authn.mfa.steps', MfaStep, { lineage: true, keyBy: 'name' })
223
+ * protected Steps: Map<string, MfaStep>;
224
+ * ```
225
+ */
226
+ export function AutoinjectNamedServices(path, type, options) {
227
+ return AddDependencyForProperty((descriptor, _target, propertyKey) => {
228
+ descriptor.inject.push({
229
+ autoinject: true,
230
+ autoinjectKey: propertyKey,
231
+ inject: type,
232
+ data: path,
233
+ resolveFunc: (data, container) => resolveNamedServices(container, data, type, options),
234
+ });
235
+ });
236
+ }
237
+ export async function resolveNamedService(container, path, type, options = {}) {
238
+ const cfg = await resolveOwnConfiguration(container);
239
+ if (!cfg) {
240
+ throw new InvalidOperation(`Cannot resolve the service of ${path}: no container in the lineage registers a Configuration`);
241
+ }
242
+ const registered = container.getRegisteredNames(type);
243
+ const listed = registered.map(q).join(', ') || 'none';
244
+ const value = cfg.get(path);
245
+ if (value !== undefined && value !== null && typeof value !== 'string') {
246
+ throw new InvalidOption(`${path} must be a string`);
247
+ }
248
+ let name = value === '' ? undefined : value ?? undefined;
249
+ if (name === undefined) {
250
+ const fallback = options.default;
251
+ if (fallback === undefined) {
252
+ if (options.optional)
253
+ return undefined;
254
+ throw new InvalidOption(`${path} is not set (registered: ${listed})`);
255
+ }
256
+ name = typeof fallback === 'string' ? fallback : fallback.prototype instanceof type ? fallback.name : fallback(registered);
257
+ if (name === undefined && options.optional)
258
+ return undefined;
259
+ if (name === undefined)
260
+ throw new InvalidOption(`${path} is not set and no ${type.name} is the default among those registered (${listed}); name one`);
261
+ }
262
+ if (!registered.includes(name)) {
263
+ throw new InvalidOption(`${path} ${q(name)}: no ${type.name} is registered under that name (registered: ${listed})`);
264
+ }
265
+ const instance = await container.resolveNamed(type, name);
266
+ if (options.is && !options.is(instance)) {
267
+ throw new InvalidOption(`${path} ${q(name)} is not an ${type.name}`);
268
+ }
269
+ return instance;
270
+ }
271
+ /**
272
+ * Injects {@link resolveNamedService} for `path` in the resolving container, when the instance is built. With
273
+ * `optional: true` an unset `path` injects undefined.
274
+ *
275
+ * @example
276
+ * ```ts
277
+ * @AutoinjectNamedService('authn.mfa.policy.service', MfaPolicy, { default: 'DefaultMfaPolicy' })
278
+ * protected Policy: MfaPolicy;
279
+ * ```
280
+ */
281
+ export function AutoinjectNamedService(path, type, options) {
282
+ return AddDependencyForProperty((descriptor, _target, propertyKey) => {
283
+ descriptor.inject.push({
284
+ autoinject: true,
285
+ autoinjectKey: propertyKey,
286
+ inject: type,
287
+ data: path,
288
+ resolveFunc: (data, container) => resolveNamedService(container, data, type, options),
289
+ });
290
+ });
291
+ }
102
292
  /**
103
293
  * Inject service based on configuration.
104
294
  * Configuration could be object or string containing service
@@ -108,8 +298,10 @@ export function Config(path, options) {
108
298
  *
109
299
  * @param path - configuration path where service type is stored
110
300
  * @param type - if type is provided, it will override type obtain from reflection. Use it specific with arrays and maps, becouse ts reflection module cannot extract array and map type data
301
+ * @param options - `optional: true` leaves the property undefined (with a warning) when the value at `path` is empty
302
+ * @throws InvalidOperation when the value at `path` is empty and the injection is not optional
111
303
  */
112
- export function AutoinjectService(path, type) {
304
+ export function AutoinjectService(path, type, options) {
113
305
  return AddDependencyForProperty((descriptor, target, propertyKey) => {
114
306
  const t = type ?? Reflect.getMetadata('design:type', target, propertyKey);
115
307
  descriptor.inject.push({
@@ -121,9 +313,9 @@ export function AutoinjectService(path, type) {
121
313
  return x.ServiceName || x.constructor.name;
122
314
  },
123
315
  serviceFunc: (data, container) => {
124
- const cfg = container.get(Configuration);
316
+ const cfg = getOwnConfiguration(container);
125
317
  if (!cfg) {
126
- throw new Error(`Configuration service is not registered in DI container. Cannot autoinject service for property ${propertyKey.toString()}, path: ${data}`);
318
+ throw new InvalidOperation(`Cannot autoinject service for property ${propertyKey.toString()}, path: ${String(data)}: the Configuration of the container is not resolved`);
127
319
  }
128
320
  let cfgVal;
129
321
  if (typeof data === 'string') {
@@ -133,7 +325,10 @@ export function AutoinjectService(path, type) {
133
325
  cfgVal = data;
134
326
  }
135
327
  if (!cfgVal) {
136
- InternalLogger.warn(`Configuration value for path ${data} is empty. Cannot autoinject service for property ${propertyKey.toString()}`, "Configuration");
328
+ if (!options?.optional) {
329
+ throw new InvalidOperation(`Configuration value at ${String(data)} is empty. Cannot autoinject service for property ${propertyKey.toString()}`);
330
+ }
331
+ InternalLogger.warn({ path: data, property: propertyKey.toString() }, 'Configuration value for path ${path} is empty. Cannot autoinject service for property ${property}', "Configuration");
137
332
  return undefined;
138
333
  }
139
334
  if (_.isString(cfgVal)) {
@@ -1 +1 @@
1
- {"version":3,"file":"decorators.js","sourceRoot":"","sources":["../../src/decorators.ts"],"names":[],"mappings":"AAAA,OAAO,CAAC,MAAM,QAAQ,CAAC;AACvB,uDAAuD;AACvD,OAAO,EAAE,aAAa,EAAuB,MAAM,+BAA+B,CAAC;AACnF,OAAO,EAAE,wBAAwB,EAAS,EAAE,EAAmD,MAAM,aAAa,CAAC;AACnH,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA0B,CA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AED,IAAI,CAAC,MAAM,EAAE,CAAC;oBACZ,IAAI,CAAC,OAAO,EAAE,QAAQ,EAAE,CAAC;wBACvB,MAAM,IAAI,gBAAgB,CAAC,0BAA0B,MAAM,CAAC,IAAI,CAAC,qDAAqD,WAAW,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC;oBAClJ,CAAC;oBACD,cAAc,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,QAAQ,EAAE,WAAW,CAAC,QAAQ,EAAE,EAAE,EAAE,mGAAmG,EAAE,eAAe,CAAC,CAAC;oBAC5L,OAAO,SAAS,CAAC;gBACnB,CAAC;gBAED,IAAI,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC;oBACvB,OAAO;wBACL,OAAO,EAAE,MAAM;qBAChB,CAAC;gBACJ,CAAC;gBAED,IAAI,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC;oBACtB,OAAO,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE;wBACtB,OAAO;4BACL,OAAO,EAAE,CAAC,CAAC,OAAiB;4BAC5B,OAAO,EAAE,CAAC;yBACX,CAAC;oBACJ,CAAC,CAAC,CAAC;gBACL,CAAC;gBAED,OAAO;oBACL,OAAO,EAAE,MAAM,CAAC,OAAiB;oBACjC,OAAO,EAAE,MAAM;iBAChB,CAAC;YACJ,CAAC;SACF,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC"}
@@ -1,6 +1,14 @@
1
1
  import { ErrorObject } from 'ajv';
2
+ export interface ConfigurationViolation {
3
+ /** Full configuration path of the bad value, eg. `authn.audit.sinkTimeoutMs`. */
4
+ path: string;
5
+ /** The schema checked against: its `$id`, else its `$configurationModule`. */
6
+ schema: string;
7
+ message: string;
8
+ }
2
9
  export declare class InvalidConfiguration extends Error {
3
10
  validationExceptions?: ErrorObject[] | undefined;
4
- constructor(message: string, validationExceptions?: ErrorObject[] | undefined);
11
+ violations: ConfigurationViolation[];
12
+ constructor(message: string, validationExceptions?: ErrorObject[] | undefined, violations?: ConfigurationViolation[]);
5
13
  }
6
14
  //# sourceMappingURL=exception.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"exception.d.ts","sourceRoot":"","sources":["../../src/exception.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,KAAK,CAAC;AAElC,qBAAa,oBAAqB,SAAQ,KAAK;IACT,oBAAoB,CAAC,EAAE,WAAW,EAAE;IAAxE,YAAY,OAAO,EAAE,MAAM,EAAS,oBAAoB,CAAC,EAAE,WAAW,EAAE,YAAA,EAEvE;CACF"}
1
+ {"version":3,"file":"exception.d.ts","sourceRoot":"","sources":["../../src/exception.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,KAAK,CAAC;AAElC,MAAM,WAAW,sBAAsB;IACrC,iFAAiF;IACjF,IAAI,EAAE,MAAM,CAAC;IACb,8EAA8E;IAC9E,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,qBAAa,oBAAqB,SAAQ,KAAK;IACT,oBAAoB,CAAC,EAAE,WAAW,EAAE;IAAS,UAAU,EAAE,sBAAsB,EAAE;IAArH,YAAY,OAAO,EAAE,MAAM,EAAS,oBAAoB,CAAC,EAAE,WAAW,EAAE,YAAA,EAAS,UAAU,GAAE,sBAAsB,EAAO,EAEzH;CACF"}
@@ -1,7 +1,8 @@
1
1
  export class InvalidConfiguration extends Error {
2
- constructor(message, validationExceptions) {
2
+ constructor(message, validationExceptions, violations = []) {
3
3
  super(message);
4
4
  this.validationExceptions = validationExceptions;
5
+ this.violations = violations;
5
6
  }
6
7
  }
7
8
  //# sourceMappingURL=exception.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"exception.js","sourceRoot":"","sources":["../../src/exception.ts"],"names":[],"mappings":"AAEA,MAAM,OAAO,oBAAqB,SAAQ,KAAK;IAC7C,YAAY,OAAe,EAAS,oBAAoC;QACtE,KAAK,CAAC,OAAO,CAAC,CAAC;oCADmB,oBAAoB;IAExD,CAAC;CACF"}
1
+ {"version":3,"file":"exception.js","sourceRoot":"","sources":["../../src/exception.ts"],"names":[],"mappings":"AAUA,MAAM,OAAO,oBAAqB,SAAQ,KAAK;IAC7C,YAAY,OAAe,EAAS,oBAAoC,EAAS,UAAU,GAA6B,EAAE;QACxH,KAAK,CAAC,OAAO,CAAC,CAAC;oCADmB,oBAAoB;0BAAyB,UAAU;IAE3F,CAAC;CACF"}
@@ -1 +1 @@
1
- {"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../src/helpers.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,EAAmE,MAAM,aAAa,CAAC;AAGrG;;;;;;GAMG;AACH,wBAAgB,GAAG,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,YAAY,CAAC,EAAE,CAAC,GAAG,CAAC,CAWxD;AAED;;;;;;GAMG;AACH,wBAAsB,OAAO,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,KAAK,CAAC,CAAC,CAAC,EAAE,OAAO,CAAC,EAAE,EAAE,GAAG,OAAO,CAAC,CAAC,CAAC,CAmBvF"}
1
+ {"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../src/helpers.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,EAAmE,MAAM,aAAa,CAAC;AAGrG;;;;;;GAMG;AACH,wBAAgB,GAAG,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,YAAY,CAAC,EAAE,CAAC,GAAG,CAAC,CAWxD;AAED;;;;;;GAMG;AACH,wBAAsB,OAAO,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,KAAK,CAAC,CAAC,CAAC,EAAE,OAAO,CAAC,EAAE,EAAE,GAAG,OAAO,CAAC,CAAC,CAAC,CAoBvF"}
@@ -27,9 +27,10 @@ export function cfg(path, defaultValue) {
27
27
  */
28
28
  export async function service(path, type, options) {
29
29
  // configuration errors propagate raw - only resolution errors below are wrapped
30
- const { service: serviceName } = cfg(path);
30
+ const entry = cfg(path);
31
+ const serviceName = typeof entry === 'string' ? entry : entry.service;
31
32
  try {
32
- const types = getRegisteredTypes(type);
33
+ const types = getRegisteredTypes(type) ?? [];
33
34
  const t = types.find((x) => x.name === serviceName);
34
35
  if (!t) {
35
36
  throw new ResolveException(`Service ${serviceName} is not registered for type ${type.name}`);
@@ -1 +1 @@
1
- {"version":3,"file":"helpers.js","sourceRoot":"","sources":["../../src/helpers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAC;AAC9D,OAAO,EAAsB,GAAG,EAAE,kBAAkB,EAAE,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AACrG,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,SAAS,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAElF;;;;;;GAMG;AACH,MAAM,UAAU,GAAG,CAAI,IAAY,EAAE,YAAgB;IACnD,MAAM,aAAa,GAAG,GAAG,CAAC,aAAa,CAAC,CAAC;IACzC,IAAI,CAAC,aAAa,EAAE,CAAC;QACnB,MAAM,IAAI,gBAAgB,CAAC,0FAA0F,CAAC,CAAC;IACzH,CAAC;IAED,UAAU,CAAC,UAAU,EAAE,CAAC,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;IAEvC,gFAAgF;IAChF,qEAAqE;IACrE,OAAO,UAAU,CAAC,SAAS,EAAE,EAAE,cAAc,EAAE,CAAC,CAAC,aAAa,CAAC,GAAG,CAAI,IAAI,EAAE,YAAY,CAAC,EAAE,IAAI,CAAC,CAAC;AACnG,CAAC;AAED;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,OAAO,CAAI,IAAY,EAAE,IAAc,EAAE,OAAY;IACzE,gFAAgF;IAChF,MAAM,EAAE,OAAO,EAAE,WAAW,EAA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IACrE,OAAO,UAAU,CAAC,SAAS,EAAE,EAAE,cAAc,EAAE,CAAC,CAAC,aAAa,CAAC,GAAG,CAAI,IAAI,EAAE,YAAY,CAAC,EAAE,IAAI,CAAC,CAAC;AACnG,CAAC;AAED;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,OAAO,CAAI,IAAY,EAAE,IAAc,EAAE,OAAY;IACzE,gFAAgF;IAChF,MAAM,KAAK,GAAG,GAAG,CAA+B,IAAI,CAAC,CAAC;IACtD,MAAM,WAAW,GAAG,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC;IAEtE,IAAI,CAAC;QACH,MAAM,KAAK,GAAG,kBAAkB,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC;QAC7C,MAAM,CAAC,GAAG,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,WAAW,CAAC,CAAC;QAEpD,IAAI,CAAC,CAAC,EAAE,CAAC;YACP,MAAM,IAAI,gBAAgB,CAAC,WAAW,WAAW,+BAA+B,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC;QAC/F,CAAC;QAED,OAAO,CAAC,MAAM,OAAO,CAAC,CAAyB,EAAE,OAAO,CAAC,CAAM,CAAC;IAClE,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,MAAM,IAAI,gBAAgB,CACxB,+BAA+B,IAAI,KAAM,GAAa,CAAC,OAAO,+CAA+C,EAC7G,GAAY,CACb,CAAC;IACJ,CAAC;AACH,CAAC"}
@@ -13,4 +13,5 @@ export * from './decorators.js';
13
13
  export * from './exception.js';
14
14
  export * from './fp.js';
15
15
  export * from './configuration.browser.js';
16
+ export { merge, mergeArrays } from './util-common.js';
16
17
  //# sourceMappingURL=index.browser.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.browser.d.ts","sourceRoot":"","sources":["../../src/index.browser.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,cAAc,+BAA+B,CAAC;AAC9C,cAAc,iBAAiB,CAAC;AAChC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,SAAS,CAAC;AACxB,cAAc,4BAA4B,CAAC"}
1
+ {"version":3,"file":"index.browser.d.ts","sourceRoot":"","sources":["../../src/index.browser.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,cAAc,+BAA+B,CAAC;AAC9C,cAAc,iBAAiB,CAAC;AAChC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,SAAS,CAAC;AACxB,cAAc,4BAA4B,CAAC;AAC3C,OAAO,EAAE,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC"}
@@ -13,4 +13,5 @@ export * from './decorators.js';
13
13
  export * from './exception.js';
14
14
  export * from './fp.js';
15
15
  export * from './configuration.browser.js';
16
+ export { merge, mergeArrays } from './util-common.js';
16
17
  //# sourceMappingURL=index.browser.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.browser.js","sourceRoot":"","sources":["../../src/index.browser.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,cAAc,+BAA+B,CAAC;AAC9C,cAAc,iBAAiB,CAAC;AAChC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,SAAS,CAAC;AACxB,cAAc,4BAA4B,CAAC"}
1
+ {"version":3,"file":"index.browser.js","sourceRoot":"","sources":["../../src/index.browser.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,cAAc,+BAA+B,CAAC;AAC9C,cAAc,iBAAiB,CAAC;AAChC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,SAAS,CAAC;AACxB,cAAc,4BAA4B,CAAC;AAC3C,OAAO,EAAE,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC"}
@@ -7,6 +7,9 @@ export * from './sources.js';
7
7
  export * from './decorators.js';
8
8
  export * from './configuration.js';
9
9
  export * from './exception.js';
10
+ export * from './schemas.js';
10
11
  export * from './helpers.js';
11
12
  export * from './fp.js';
13
+ export * from './lib-dirs.js';
14
+ export { merge, mergeArrays } from './util-common.js';
12
15
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,cAAc,+BAA+B,CAAC;AAC9C,cAAc,cAAc,CAAC;AAC7B,cAAc,iBAAiB,CAAC;AAChC,cAAc,oBAAoB,CAAC;AACnC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,cAAc,CAAC;AAC7B,cAAc,SAAS,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,cAAc,+BAA+B,CAAC;AAC9C,cAAc,cAAc,CAAC;AAC7B,cAAc,iBAAiB,CAAC;AAChC,cAAc,oBAAoB,CAAC;AACnC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,cAAc,CAAC;AAC7B,cAAc,cAAc,CAAC;AAC7B,cAAc,SAAS,CAAC;AACxB,cAAc,eAAe,CAAC;AAC9B,OAAO,EAAE,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC"}
package/lib/mjs/index.js CHANGED
@@ -7,6 +7,9 @@ export * from './sources.js';
7
7
  export * from './decorators.js';
8
8
  export * from './configuration.js';
9
9
  export * from './exception.js';
10
+ export * from './schemas.js';
10
11
  export * from './helpers.js';
11
12
  export * from './fp.js';
13
+ export * from './lib-dirs.js';
14
+ export { merge, mergeArrays } from './util-common.js';
12
15
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,cAAc,+BAA+B,CAAC;AAC9C,cAAc,cAAc,CAAC;AAC7B,cAAc,iBAAiB,CAAC;AAChC,cAAc,oBAAoB,CAAC;AACnC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,cAAc,CAAC;AAC7B,cAAc,SAAS,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,cAAc,+BAA+B,CAAC;AAC9C,cAAc,cAAc,CAAC;AAC7B,cAAc,iBAAiB,CAAC;AAChC,cAAc,oBAAoB,CAAC;AACnC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,cAAc,CAAC;AAC7B,cAAc,cAAc,CAAC;AAC7B,cAAc,SAAS,CAAC;AACxB,cAAc,eAAe,CAAC;AAC9B,OAAO,EAAE,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC"}
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Where `sub` of the installed package `pkg` (eg. `@spinajs/authn-token`) builds to, for its config's `system.dirs`:
3
+ * under `node_modules` of WORKSPACE_ROOT_PATH (else the working directory), then one level up for a process that runs
4
+ * from an app or build folder. The `cjs` or `mjs` build is picked by how this module was loaded, which in one app is
5
+ * how every package is.
6
+ */
7
+ export declare function packageLibDirs(pkg: string, sub: string): string[];
8
+ //# sourceMappingURL=lib-dirs.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lib-dirs.d.ts","sourceRoot":"","sources":["../../src/lib-dirs.ts"],"names":[],"mappings":"AAEA;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,EAAE,CAIjE"}
@@ -0,0 +1,13 @@
1
+ import { join, normalize, resolve } from 'path';
2
+ /**
3
+ * Where `sub` of the installed package `pkg` (eg. `@spinajs/authn-token`) builds to, for its config's `system.dirs`:
4
+ * under `node_modules` of WORKSPACE_ROOT_PATH (else the working directory), then one level up for a process that runs
5
+ * from an app or build folder. The `cjs` or `mjs` build is picked by how this module was loaded, which in one app is
6
+ * how every package is.
7
+ */
8
+ export function packageLibDirs(pkg, sub) {
9
+ const root = process.env.WORKSPACE_ROOT_PATH ?? process.cwd();
10
+ const flavour = typeof module !== 'undefined' ? 'cjs' : 'mjs';
11
+ return [resolve(normalize(join(root, 'node_modules', pkg, 'lib', flavour, sub))), resolve(normalize(join(root, '../', 'node_modules', pkg, 'lib', flavour, sub)))];
12
+ }
13
+ //# sourceMappingURL=lib-dirs.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lib-dirs.js","sourceRoot":"","sources":["../../src/lib-dirs.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AAEhD;;;;;GAKG;AACH,MAAM,UAAU,cAAc,CAAC,GAAW,EAAE,GAAW;IACrD,MAAM,IAAI,GAAG,OAAO,CAAC,GAAG,CAAC,mBAAmB,IAAI,OAAO,CAAC,GAAG,EAAE,CAAC;IAC9D,MAAM,OAAO,GAAG,OAAO,MAAM,KAAK,WAAW,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC;IAC9D,OAAO,CAAC,OAAO,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,EAAE,cAAc,EAAE,GAAG,EAAE,KAAK,EAAE,OAAO,EAAE,GAAG,CAAC,CAAC,CAAC,EAAE,OAAO,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,EAAE,KAAK,EAAE,cAAc,EAAE,GAAG,EAAE,KAAK,EAAE,OAAO,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;AACrK,CAAC"}
@@ -0,0 +1,20 @@
1
+ import { IContainer } from '@spinajs/di';
2
+ import { IConfigurationSchema } from '@spinajs/configuration-common';
3
+ /**
4
+ * Registers a configuration schema. When the Configuration that `container` reads (the one of the nearest
5
+ * container in its lineage that registers a Configuration) is already resolved, the schema is validated against
6
+ * it at once and a refused value throws InvalidConfiguration; a Configuration that is registered but not resolved
7
+ * yet applies the schema when it boots.
8
+ */
9
+ export declare function registerConfigurationSchema(schema: IConfigurationSchema, container?: IContainer): void;
10
+ /**
11
+ * Registers a schema from a module's top level, so a module loaded after the Configuration
12
+ * resolved (a directory scan, a CLI command) still gets its values checked and defaulted. A refused value does not
13
+ * fail the import, which would take down every module loaded with it: the violations are logged, and each read of
14
+ * the module throws InvalidConfiguration until it validates. A Bootstrapper that registers the same schema keeps doing
15
+ * so: DI.clearCache() drops this registration, and a module's top level runs once per process. Registered in the root
16
+ * container, the schema applies to the root Configuration and to a child one resolved later; a child Configuration
17
+ * resolved before the registration does not see it.
18
+ */
19
+ export declare function registerConfigurationSchemaAtImport(schema: IConfigurationSchema, container?: IContainer): void;
20
+ //# sourceMappingURL=schemas.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schemas.d.ts","sourceRoot":"","sources":["../../src/schemas.ts"],"names":[],"mappings":"AAAA,OAAO,EAAM,UAAU,EAAE,MAAM,aAAa,CAAC;AAC7C,OAAO,EAAiB,oBAAoB,EAAE,MAAM,+BAA+B,CAAC;AA0BpF;;;;;GAKG;AACH,wBAAgB,2BAA2B,CAAC,MAAM,EAAE,oBAAoB,EAAE,SAAS,GAAE,UAA6B,GAAG,IAAI,CAGxH;AAED;;;;;;;;GAQG;AACH,wBAAgB,mCAAmC,CAAC,MAAM,EAAE,oBAAoB,EAAE,SAAS,GAAE,UAA6B,GAAG,IAAI,CAMhI"}