@tstdl/base 0.90.52 → 0.90.54

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.
@@ -2,7 +2,7 @@ import type { HttpClientOptions } from '../../http/client/index.js';
2
2
  import { HttpClient } from '../../http/client/index.js';
3
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> & Resolvable<HttpClientOptions>;
5
+ export type ApiClient<T extends ApiDefinition> = new (httpClientOrOptions?: HttpClient | HttpClientOptions) => ApiClientImplementation<T> & Resolvable<HttpClient | HttpClientOptions>;
6
6
  export type ClientOptions = {
7
7
  /**
8
8
  * url prefix
@@ -4,11 +4,7 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
4
4
  else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
5
  return c > 3 && r && Object.defineProperty(target, key, r), r;
6
6
  };
7
- var __metadata = (this && this.__metadata) || function (k, v) {
8
- if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
9
- };
10
7
  import { compileClient } from '../../api/client/index.js';
11
- import { HttpClient } from '../../http/client/http-client.js';
12
8
  import { ReplaceClass, Singleton } from '../../injector/index.js';
13
9
  import { emptyObjectSchema } from '../../schema/schemas/object.js';
14
10
  import { unknown } from '../../schema/schemas/unknown.js';
@@ -16,13 +12,9 @@ import { getAuthenticationApiDefinition } from '../authentication.api.js';
16
12
  export function getAuthenticationApiClient(additionalTokenPayloadSchema, authenticationDataSchema, additionalInitSecretResetData) {
17
13
  const definition = getAuthenticationApiDefinition(additionalTokenPayloadSchema, authenticationDataSchema, additionalInitSecretResetData);
18
14
  let AuthenticationApiClient = class AuthenticationApiClient extends compileClient(definition) {
19
- constructor(httpClient) {
20
- super(httpClient);
21
- }
22
15
  };
23
16
  AuthenticationApiClient = __decorate([
24
- Singleton(),
25
- __metadata("design:paramtypes", [HttpClient])
17
+ Singleton()
26
18
  ], AuthenticationApiClient);
27
19
  return AuthenticationApiClient;
28
20
  }
@@ -1,3 +1,4 @@
1
+ import type { ResolveManyItem, ResolveManyReturnType } from './injector.js';
1
2
  import { Injector } from './injector.js';
2
3
  import type { Resolvable, ResolveArgument } from './interfaces.js';
3
4
  import type { InjectionToken } from './token.js';
@@ -11,17 +12,13 @@ export type InjectionContext = {
11
12
  argument: unknown;
12
13
  inject<T, A>(token: InjectionToken<T, A>, argument?: ResolveArgument<T, A>, options?: InjectOptions<T, A>): T;
13
14
  injectAll<T, A>(token: InjectionToken<T, A>, argument?: ResolveArgument<T, A>, options?: InjectOptions<T, A>): T[];
15
+ injectMany<T extends InjectManyItem<any, any>[]>(...tokens: T): InjectManyReturnType<T>;
14
16
  injectAsync<T, A>(token: InjectionToken<T, A>, argument?: ResolveArgument<T, A>, options?: InjectOptions<T, A>): Promise<T>;
15
17
  injectAllAsync<T, A>(token: InjectionToken<T, A>, argument?: ResolveArgument<T, A>, options?: InjectOptions<T, A>): Promise<T[]>;
18
+ injectManyAsync<T extends InjectManyItem<any, any>[]>(...tokens: T): Promise<InjectManyReturnType<T>>;
16
19
  };
17
- export type InjectManyArrayItem<T, A> = [token: InjectionToken<T, A>, argument?: ResolveArgument<T, A>, options?: InjectOptions<T, A>];
18
- export type InjectManyItem<T, A> = InjectionToken<T, A> | InjectManyArrayItem<T, A>;
19
- export type InjectManyItemReturnType<T extends InjectManyItem<any, any>> = T extends InjectManyItem<infer U, any> ? U | (T extends (InjectManyArrayItem<any, any> & [any, any, {
20
- optional: true;
21
- }]) ? undefined : never) : never;
22
- export type InjectManyReturnType<T extends InjectManyItem<any, any>[]> = {
23
- [I in keyof T]: InjectManyItemReturnType<T[I]>;
24
- };
20
+ export type InjectManyItem<T, A> = ResolveManyItem<T, A>;
21
+ export type InjectManyReturnType<T extends InjectManyItem<any, any>[]> = ResolveManyReturnType<T>;
25
22
  /**
26
23
  * Resolves a token using the {@link Injector} of the current injection context
27
24
  *
@@ -82,8 +79,8 @@ export declare function injectAllAsync<T, A>(token: InjectionToken<T, A>, argume
82
79
  export declare function injectArgument<T, R>(_this?: Resolvable<T>, options?: InjectArgumentOptions & {
83
80
  optional: R;
84
81
  }): T | (R extends true ? undefined : never);
85
- export declare function getCurrentInjectionContext(required: true): InjectionContext;
86
- export declare function getCurrentInjectionContext(required?: boolean): InjectionContext | null;
82
+ export declare function getCurrentInjectionContext(debugFn: Function, required: true): InjectionContext;
83
+ export declare function getCurrentInjectionContext(debugFn: Function, required?: boolean): InjectionContext | null;
87
84
  export declare function getCurrentInjector(required: true): Injector;
88
85
  export declare function getCurrentInjector(required?: boolean): Injector | null;
89
86
  export declare function setCurrentInjectionContext(context: InjectionContext | null): InjectionContext | null;
@@ -1,11 +1,8 @@
1
- import { mapAsync } from '../utils/async-iterable-helpers/map.js';
2
- import { toArrayAsync } from '../utils/async-iterable-helpers/to-array.js';
3
- import { assertDefined, isArray, isNotNull } from '../utils/type-guards.js';
1
+ import { assertDefined, isNotNull } from '../utils/type-guards.js';
4
2
  import { Injector } from './injector.js';
5
3
  let currentInjectionContext = null;
6
4
  export function inject(token, argument, options) {
7
- assertInInjectionContext(inject);
8
- return currentInjectionContext.inject(token, argument, options);
5
+ return getCurrentInjectionContext(inject, true).inject(token, argument, options);
9
6
  }
10
7
  /**
11
8
  * Resolves tokens using the {@link Injector} of the current injection context
@@ -13,12 +10,10 @@ export function inject(token, argument, options) {
13
10
  * @param token tokens to resolve
14
11
  */
15
12
  export function injectMany(...tokens) {
16
- assertInInjectionContext(inject);
17
- return tokens.map((item) => (isArray(item) ? currentInjectionContext.inject(item[0], item[1], item[2]) : currentInjectionContext.inject(item)));
13
+ return getCurrentInjectionContext(injectMany, true).injectMany(...tokens);
18
14
  }
19
15
  export async function injectAsync(token, argument, options) {
20
- assertInInjectionContext(inject);
21
- return currentInjectionContext.injectAsync(token, argument, options);
16
+ return getCurrentInjectionContext(injectAsync, true).injectAsync(token, argument, options);
22
17
  }
23
18
  /**
24
19
  * Resolves tokens using the {@link Injector} of the current injection context
@@ -26,8 +21,7 @@ export async function injectAsync(token, argument, options) {
26
21
  * @param token tokens to resolve
27
22
  */
28
23
  export async function injectManyAsync(...tokens) {
29
- assertInInjectionContext(inject);
30
- return toArrayAsync(mapAsync(tokens, async (item) => (isArray(item) ? currentInjectionContext.injectAsync(item[0], item[1], item[2]) : currentInjectionContext.injectAsync(item))));
24
+ return getCurrentInjectionContext(injectManyAsync, true).injectManyAsync(...tokens);
31
25
  }
32
26
  /**
33
27
  * Resolves a token using the {@link Injector} of the current injection context
@@ -37,8 +31,7 @@ export async function injectManyAsync(...tokens) {
37
31
  * @param options resolve options
38
32
  */
39
33
  export function injectAll(token, argument, options) {
40
- assertInInjectionContext(injectAll);
41
- return currentInjectionContext.injectAll(token, argument, options);
34
+ return getCurrentInjectionContext(injectAll, true).injectAll(token, argument, options);
42
35
  }
43
36
  /**
44
37
  * Resolves a token using the {@link Injector} of the current injection context
@@ -48,8 +41,7 @@ export function injectAll(token, argument, options) {
48
41
  * @param options resolve options
49
42
  */
50
43
  export async function injectAllAsync(token, argument, options) {
51
- assertInInjectionContext(injectAll);
52
- return currentInjectionContext.injectAllAsync(token, argument, options);
44
+ return getCurrentInjectionContext(injectAllAsync, true).injectAllAsync(token, argument, options);
53
45
  }
54
46
  /**
55
47
  * Injects the resolve argument from the current resolution
@@ -57,21 +49,20 @@ export async function injectAllAsync(token, argument, options) {
57
49
  * @returns
58
50
  */
59
51
  export function injectArgument(_this, options) {
60
- assertInInjectionContext(injectArgument);
61
- const argument = currentInjectionContext.argument;
52
+ const argument = getCurrentInjectionContext(injectArgument, true).argument;
62
53
  if (options?.optional != true) {
63
54
  assertDefined(argument, 'No resolve argument available in current injection context.');
64
55
  }
65
56
  return argument;
66
57
  }
67
- export function getCurrentInjectionContext(required = false) {
58
+ export function getCurrentInjectionContext(debugFn, required = false) {
68
59
  if (required) {
69
- assertInInjectionContext(getCurrentInjector);
60
+ assertInInjectionContext(debugFn);
70
61
  }
71
62
  return currentInjectionContext;
72
63
  }
73
64
  export function getCurrentInjector(required = false) {
74
- return getCurrentInjectionContext(required)?.injector ?? null;
65
+ return getCurrentInjectionContext(getCurrentInjector, required)?.injector ?? null;
75
66
  }
76
67
  export function setCurrentInjectionContext(context) {
77
68
  const previous = currentInjectionContext;
@@ -92,8 +83,10 @@ export function runInInjectionContext(injectorOrContext, fn) {
92
83
  argument: undefined,
93
84
  inject(token, argument, options) { return injectorOrContext.resolve(token, argument, options); },
94
85
  injectAll(token, argument, options) { return injectorOrContext.resolveAll(token, argument, options); },
86
+ injectMany(...tokens) { return injectorOrContext.resolveMany(...tokens); },
95
87
  async injectAsync(token, argument, options) { return injectorOrContext.resolveAsync(token, argument, options); },
96
- async injectAllAsync(token, argument, options) { return injectorOrContext.resolveAllAsync(token, argument, options); }
88
+ async injectAllAsync(token, argument, options) { return injectorOrContext.resolveAllAsync(token, argument, options); },
89
+ async injectManyAsync(...tokens) { return injectorOrContext.resolveManyAsync(...tokens); },
97
90
  }
98
91
  : injectorOrContext;
99
92
  const previousContext = setCurrentInjectionContext(context);
@@ -1,5 +1,6 @@
1
1
  import type { AsyncDisposable } from '../disposable/disposable.js';
2
2
  import type { OneOrMany, Record, TypedOmit } from '../types.js';
3
+ import type { InjectOptions } from './inject.js';
3
4
  import type { ResolveArgument } from './interfaces.js';
4
5
  import { type Provider } from './provider.js';
5
6
  import { type InjectionToken } from './token.js';
@@ -16,6 +17,14 @@ export type GetRegistrationOptions = {
16
17
  skipSelf?: boolean;
17
18
  onlySelf?: boolean;
18
19
  };
20
+ export type ResolveManyArrayItem<T, A> = [token: InjectionToken<T, A>, argument?: ResolveArgument<T, A>, options?: InjectOptions<T, A>];
21
+ export type ResolveManyItem<T, A> = InjectionToken<T, A> | ResolveManyArrayItem<T, A>;
22
+ export type ResolveManyItemReturnType<T extends ResolveManyItem<any, any>> = T extends ResolveManyItem<infer U, any> ? U | (T extends (ResolveManyArrayItem<any, any> & [any, any, {
23
+ optional: true;
24
+ }]) ? undefined : never) : never;
25
+ export type ResolveManyReturnType<T extends ResolveManyItem<any, any>[]> = {
26
+ [I in keyof T]: ResolveManyItemReturnType<T[I]>;
27
+ };
19
28
  export type AddDisposeHandler = (handler: Disposable | AsyncDisposable | (() => any)) => void;
20
29
  export declare class Injector implements AsyncDisposable {
21
30
  #private;
@@ -73,11 +82,13 @@ export declare class Injector implements AsyncDisposable {
73
82
  }): T | undefined;
74
83
  resolve<T, A>(token: InjectionToken<T, A>, argument?: ResolveArgument<T, A>, options?: ResolveOptions<T, A>): T;
75
84
  resolveAll<T, A>(token: InjectionToken<T, A>, argument?: ResolveArgument<T, A>, options?: ResolveOptions<T, A>): T[];
85
+ resolveMany<T extends ResolveManyItem<any, any>[]>(...tokens: T): ResolveManyReturnType<T>;
76
86
  resolveAsync<T, A>(token: InjectionToken<T, A>, argument: ResolveArgument<T, A>, options: ResolveOptions<T, A> & {
77
87
  optional: true;
78
88
  }): Promise<T | undefined>;
79
89
  resolveAsync<T, A>(token: InjectionToken<T, A>, argument?: ResolveArgument<T, A>, options?: ResolveOptions<T, A>): Promise<T>;
80
90
  resolveAllAsync<T, A>(token: InjectionToken<T, A>, argument?: ResolveArgument<T, A>, options?: ResolveOptions<T, A>): Promise<T[]>;
91
+ resolveManyAsync<T extends ResolveManyItem<any, any>[]>(...tokens: T): Promise<ResolveManyReturnType<T>>;
81
92
  private _resolve;
82
93
  private _resolveAll;
83
94
  private _resolveRegistration;
@@ -166,6 +166,15 @@ export class Injector {
166
166
  context.$done.resolve();
167
167
  return values;
168
168
  }
169
+ resolveMany(...tokens) {
170
+ const context = newInternalResolveContext();
171
+ const values = tokens.map((token) => (isArray(token)
172
+ ? this._resolve(token[0], token[1], token[2] ?? {}, context, ResolveChain.startWith(token[0]))
173
+ : this._resolve(token, undefined, {}, context, ResolveChain.startWith(token))));
174
+ postProcess(context);
175
+ context.$done.resolve();
176
+ return values;
177
+ }
169
178
  async resolveAsync(token, argument, options = {}) {
170
179
  const context = newInternalResolveContext();
171
180
  const value = this._resolve(token, argument, options, context, ResolveChain.startWith(token));
@@ -180,6 +189,15 @@ export class Injector {
180
189
  context.$done.resolve();
181
190
  return values;
182
191
  }
192
+ async resolveManyAsync(...tokens) {
193
+ const context = newInternalResolveContext();
194
+ const values = tokens.map((token) => (isArray(token)
195
+ ? this._resolve(token[0], token[1], token[2] ?? {}, context, ResolveChain.startWith(token[0]))
196
+ : this._resolve(token, undefined, {}, context, ResolveChain.startWith(token))));
197
+ await postProcessAsync(context);
198
+ context.$done.resolve();
199
+ return values;
200
+ }
183
201
  _resolve(token, argument, options, context, chain) {
184
202
  this.assertNotDisposed();
185
203
  if (isDefined(options.forwardRef) && (options.forwardRef != false)) {
@@ -237,7 +255,7 @@ export class Injector {
237
255
  const previousInjectionContext = setCurrentInjectionContext(injectionContext);
238
256
  const resolutionTag = Symbol(); // eslint-disable-line symbol-description
239
257
  try {
240
- const token = registration.token;
258
+ const { token } = registration;
241
259
  const resolutionScoped = registration.options.lifecycle == 'resolution';
242
260
  const injectorScoped = registration.options.lifecycle == 'injector';
243
261
  const singletonScoped = registration.options.lifecycle == 'singleton';
@@ -280,7 +298,7 @@ export class Injector {
280
298
  _resolveProvider(resolutionTag, registration, resolveArgument, options, context, injectionContext, chain) {
281
299
  try {
282
300
  setResolving(registration.token, context, chain);
283
- const provider = registration.provider;
301
+ const { provider } = registration;
284
302
  let result;
285
303
  if (isClassProvider(provider)) {
286
304
  const typeMetadata = reflectionRegistry.getMetadata(provider.useClass);
@@ -343,7 +361,7 @@ export class Injector {
343
361
  return injectMetadata.injectArgumentMapper(resolveArgument);
344
362
  }
345
363
  const parameterResolveArgument = injectMetadata.forwardArgumentMapper?.(resolveArgument) ?? injectMetadata.resolveArgumentProvider?.(this.getResolveContext(resolutionTag, context, getChain(injectToken)));
346
- const forwardRef = injectMetadata.forwardRef;
364
+ const { forwardRef } = injectMetadata;
347
365
  if (isDefined(forwardRef)) {
348
366
  context.forwardRefQueue.add(() => {
349
367
  const forwardToken = isFunction(forwardRef) ? forwardRef() : isBoolean(forwardRef) ? injectToken : forwardRef;
@@ -401,8 +419,10 @@ export class Injector {
401
419
  argument: resolveArgument,
402
420
  inject: (token, argument, options) => this.resolveInjection(token, argument, options ?? {}, resolveContext, injectIndex++, chain),
403
421
  injectAll: (token, argument, options) => this.resolveInjectionAll(token, argument, options ?? {}, resolveContext, injectIndex++, chain),
422
+ injectMany: (...tokens) => this.resolveMany(...tokens),
404
423
  injectAsync: async (token, argument, options) => this.resolveInjectionAsync(token, argument, options ?? {}, resolveContext, injectIndex++, chain),
405
- injectAllAsync: async (token, argument, options) => this.resolveInjectionAllAsync(token, argument, options ?? {}, resolveContext, injectIndex++, chain)
424
+ injectAllAsync: async (token, argument, options) => this.resolveInjectionAllAsync(token, argument, options ?? {}, resolveContext, injectIndex++, chain),
425
+ injectManyAsync: async (...tokens) => this.resolveManyAsync(...tokens)
406
426
  };
407
427
  return context;
408
428
  }
@@ -2,7 +2,7 @@ import { CustomError } from '../errors/custom.error.js';
2
2
  import { isDefined } from '../utils/type-guards.js';
3
3
  export class ResolveError extends CustomError {
4
4
  constructor(message, chain, cause) {
5
- const causeMessage = isDefined(cause) ? `\n cause: ${cause?.message}` : '';
5
+ const causeMessage = isDefined(cause) ? `\n cause: ${cause.message}` : '';
6
6
  super({
7
7
  message: `${message}${causeMessage}\n chain: ${chain.format(15)}`,
8
8
  cause,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tstdl/base",
3
- "version": "0.90.52",
3
+ "version": "0.90.54",
4
4
  "author": "Patrick Hein",
5
5
  "publishConfig": {
6
6
  "access": "public"