@tstdl/base 0.87.5 → 0.87.7

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.
@@ -1,14 +1,8 @@
1
- import type { Observable } from 'rxjs';
2
- import type { ApiClient } from '../../api/client/index.js';
3
1
  import type { AsyncDisposable } from '../../disposable/index.js';
4
2
  import { disposeAsync } from '../../disposable/index.js';
5
3
  import type { AfterResolve } from '../../injector/index.js';
6
4
  import { afterResolve } from '../../injector/index.js';
7
- import { Lock } from '../../lock/index.js';
8
- import { Logger } from '../../logger/index.js';
9
- import { MessageBus } from '../../message-bus/index.js';
10
5
  import type { Record } from '../../types.js';
11
- import type { AuthenticationApiDefinition } from '../authentication.api.js';
12
6
  import type { SecretCheckResult, TokenPayload } from '../models/index.js';
13
7
  export declare class AuthenticationService<AdditionalTokenPayload extends Record = Record, AuthenticationData = any> implements AfterResolve, AsyncDisposable {
14
8
  private readonly client;
@@ -19,27 +13,27 @@ export declare class AuthenticationService<AdditionalTokenPayload extends Record
19
13
  private readonly refreshLock;
20
14
  private readonly logger;
21
15
  private readonly disposeToken;
22
- readonly error$: Observable<Error>;
16
+ readonly error$: import("rxjs").Observable<Error>;
23
17
  readonly token: import("../../signals/api.js").WritableSignal<TokenPayload<AdditionalTokenPayload> | undefined>;
24
18
  readonly isLoggedIn: import("../../signals/api.js").Signal<boolean>;
25
19
  readonly subject: import("../../signals/api.js").Signal<string | undefined>;
26
20
  readonly sessionId: import("../../signals/api.js").Signal<string | undefined>;
27
- readonly token$: Observable<TokenPayload<AdditionalTokenPayload> | undefined>;
28
- readonly definedToken$: Observable<Exclude<TokenPayload<AdditionalTokenPayload>, void | undefined>>;
29
- readonly validToken$: Observable<Exclude<TokenPayload<AdditionalTokenPayload>, void | undefined>>;
30
- readonly subject$: Observable<string | undefined>;
31
- readonly definedSubject$: Observable<string>;
32
- readonly sessionId$: Observable<string | undefined>;
33
- readonly definedSessionId$: Observable<string>;
34
- readonly isLoggedIn$: Observable<boolean>;
35
- readonly loggedOut$: Observable<void>;
21
+ readonly token$: import("rxjs").Observable<TokenPayload<AdditionalTokenPayload> | undefined>;
22
+ readonly definedToken$: import("rxjs").Observable<Exclude<TokenPayload<AdditionalTokenPayload>, void | undefined>>;
23
+ readonly validToken$: import("rxjs").Observable<Exclude<TokenPayload<AdditionalTokenPayload>, void | undefined>>;
24
+ readonly subject$: import("rxjs").Observable<string | undefined>;
25
+ readonly definedSubject$: import("rxjs").Observable<string>;
26
+ readonly sessionId$: import("rxjs").Observable<string | undefined>;
27
+ readonly definedSessionId$: import("rxjs").Observable<string>;
28
+ readonly isLoggedIn$: import("rxjs").Observable<boolean>;
29
+ readonly loggedOut$: import("rxjs").Observable<void>;
36
30
  private get authenticationData();
37
31
  private set authenticationData(value);
38
32
  get definedToken(): TokenPayload<AdditionalTokenPayload>;
39
33
  get definedSubject(): string;
40
34
  get definedSessionId(): string;
41
35
  get hasValidToken(): boolean;
42
- constructor(client: InstanceType<ApiClient<AuthenticationApiDefinition<TokenPayload<AdditionalTokenPayload>, AuthenticationData>>>, tokenUpdateBus: MessageBus<TokenPayload<AdditionalTokenPayload> | undefined>, loggedOutBus: MessageBus<void>, refreshLock: Lock | undefined, initialAuthenticationData: AuthenticationData | undefined, logger: Logger);
36
+ constructor(initialAuthenticationData: AuthenticationData | undefined);
43
37
  [afterResolve](): void;
44
38
  initialize(): void;
45
39
  [disposeAsync](): Promise<void>;
@@ -63,17 +63,16 @@ const authenticationDataStorageKey = "AuthenticationService:authentication-data"
63
63
  const tokenUpdateBusName = "AuthenticationService:tokenUpdate";
64
64
  const loggedOutBusName = "AuthenticationService:loggedOut";
65
65
  const refreshLockResource = "AuthenticationService:refresh";
66
- const localStorage = globalThis.localStorage;
67
66
  let AuthenticationService = class AuthenticationService2 {
68
- client;
69
- errorSubject;
70
- tokenUpdateBus;
71
- loggedOutBus;
72
- forceRefreshToken;
73
- refreshLock;
74
- logger;
75
- disposeToken;
76
- error$;
67
+ client = (0, import_injector.inject)(import_tokens.AUTHENTICATION_API_CLIENT);
68
+ errorSubject = new import_rxjs.Subject();
69
+ tokenUpdateBus = (0, import_injector.inject)(import_message_bus.MessageBus, tokenUpdateBusName);
70
+ loggedOutBus = (0, import_injector.inject)(import_message_bus.MessageBus, loggedOutBusName);
71
+ forceRefreshToken = new import_token.CancellationToken();
72
+ refreshLock = (0, import_injector.inject)(import_lock.Lock, refreshLockResource, { optional: true });
73
+ logger = (0, import_injector.inject)(import_logger.Logger, "AuthenticationService");
74
+ disposeToken = new import_token.CancellationToken();
75
+ error$ = this.errorSubject.asObservable();
77
76
  token = (0, import_api.signal)(void 0);
78
77
  isLoggedIn = (0, import_api.computed)(() => (0, import_type_guards.isDefined)(this.token()));
79
78
  subject = (0, import_api.computed)(() => this.token()?.subject);
@@ -86,21 +85,17 @@ let AuthenticationService = class AuthenticationService2 {
86
85
  sessionId$ = (0, import_api.toObservable)(this.sessionId);
87
86
  definedSessionId$ = this.sessionId$.pipe((0, import_rxjs.filter)(import_type_guards.isDefined));
88
87
  isLoggedIn$ = (0, import_api.toObservable)(this.isLoggedIn);
89
- loggedOut$;
88
+ loggedOut$ = this.loggedOutBus.allMessages$;
90
89
  get authenticationData() {
91
- try {
92
- const data = localStorage?.getItem(authenticationDataStorageKey);
93
- return (0, import_type_guards.isNullOrUndefined)(data) ? void 0 : JSON.parse(data);
94
- } catch {
95
- return void 0;
96
- }
90
+ const data = localStorage.getItem(authenticationDataStorageKey);
91
+ return (0, import_type_guards.isNullOrUndefined)(data) ? void 0 : JSON.parse(data);
97
92
  }
98
93
  set authenticationData(data) {
99
94
  if ((0, import_type_guards.isUndefined)(data)) {
100
- localStorage?.removeItem(authenticationDataStorageKey);
95
+ localStorage.removeItem(authenticationDataStorageKey);
101
96
  } else {
102
97
  const json = JSON.stringify(data);
103
- localStorage?.setItem(authenticationDataStorageKey, json);
98
+ localStorage.setItem(authenticationDataStorageKey, json);
104
99
  }
105
100
  }
106
101
  get definedToken() {
@@ -115,20 +110,10 @@ let AuthenticationService = class AuthenticationService2 {
115
110
  get hasValidToken() {
116
111
  return (this.token()?.exp ?? 0) > (0, import_date_time.currentTimestampSeconds)();
117
112
  }
118
- constructor(client, tokenUpdateBus, loggedOutBus, refreshLock, initialAuthenticationData, logger) {
119
- this.client = client;
120
- this.tokenUpdateBus = tokenUpdateBus;
121
- this.loggedOutBus = loggedOutBus;
122
- this.refreshLock = refreshLock;
123
- this.logger = logger;
113
+ constructor(initialAuthenticationData) {
124
114
  if ((0, import_type_guards.isUndefined)(this.authenticationData)) {
125
115
  this.authenticationData = initialAuthenticationData;
126
116
  }
127
- this.disposeToken = new import_token.CancellationToken();
128
- this.errorSubject = new import_rxjs.Subject();
129
- this.forceRefreshToken = new import_token.CancellationToken();
130
- this.error$ = this.errorSubject.asObservable();
131
- this.loggedOut$ = loggedOutBus.allMessages$;
132
117
  }
133
118
  [import_injector.afterResolve]() {
134
119
  this.initialize();
@@ -144,6 +129,7 @@ let AuthenticationService = class AuthenticationService2 {
144
129
  async dispose() {
145
130
  this.disposeToken.set();
146
131
  this.errorSubject.complete();
132
+ await this.loggedOutBus.dispose();
147
133
  await this.tokenUpdateBus.dispose();
148
134
  }
149
135
  setAdditionalData(data) {
@@ -161,7 +147,7 @@ let AuthenticationService = class AuthenticationService2 {
161
147
  await Promise.race([
162
148
  this.client.endSession(),
163
149
  (0, import_timing.timeout)(150)
164
- ]).catch((error) => console.error(error));
150
+ ]).catch((error) => this.logger.error(error));
165
151
  } finally {
166
152
  this.setNewToken(void 0);
167
153
  this.loggedOutBus.publishAndForget();
@@ -195,14 +181,11 @@ let AuthenticationService = class AuthenticationService2 {
195
181
  return this.client.checkSecret({ secret });
196
182
  }
197
183
  saveToken(token) {
198
- if ((0, import_type_guards.isUndefined)(globalThis.localStorage)) {
199
- return;
200
- }
201
184
  if ((0, import_type_guards.isNullOrUndefined)(token)) {
202
- localStorage?.removeItem(tokenStorageKey);
185
+ localStorage.removeItem(tokenStorageKey);
203
186
  } else {
204
187
  const serialized = JSON.stringify(token);
205
- localStorage?.setItem(tokenStorageKey, serialized);
188
+ localStorage.setItem(tokenStorageKey, serialized);
206
189
  }
207
190
  }
208
191
  loadToken() {
@@ -252,20 +235,7 @@ let AuthenticationService = class AuthenticationService2 {
252
235
  };
253
236
  AuthenticationService = __decorate([
254
237
  (0, import_injector.Singleton)(),
255
- __param(0, (0, import_injector.Inject)(import_tokens.AUTHENTICATION_API_CLIENT)),
256
- __param(1, (0, import_injector.ResolveArg)(tokenUpdateBusName)),
257
- __param(2, (0, import_injector.ResolveArg)(loggedOutBusName)),
258
- __param(3, (0, import_injector.Inject)(import_lock.Lock, refreshLockResource)),
259
- __param(3, (0, import_injector.Optional)()),
260
- __param(4, (0, import_injector.Inject)(import_tokens.INITIAL_AUTHENTICATION_DATA)),
261
- __param(4, (0, import_injector.Optional)()),
262
- __param(5, (0, import_injector.ResolveArg)("AuthenticationService")),
263
- __metadata("design:paramtypes", [
264
- void 0,
265
- import_message_bus.MessageBus,
266
- import_message_bus.MessageBus,
267
- Object,
268
- Object,
269
- import_logger.Logger
270
- ])
238
+ __param(0, (0, import_injector.Inject)(import_tokens.INITIAL_AUTHENTICATION_DATA)),
239
+ __param(0, (0, import_injector.Optional)()),
240
+ __metadata("design:paramtypes", [Object])
271
241
  ], AuthenticationService);
@@ -1,3 +1,4 @@
1
1
  import type { HttpClientMiddleware } from '../../http/client/middleware.js';
2
+ import type { ValueOrAsyncProvider } from '../../utils/value-or-provider.js';
2
3
  import type { AuthenticationService } from './authentication.service.js';
3
- export declare function waitForAuthenticationCredentialsMiddleware(authenticationService: AuthenticationService): HttpClientMiddleware;
4
+ export declare function waitForAuthenticationCredentialsMiddleware(authenticationServiceOrProvider: ValueOrAsyncProvider<AuthenticationService>): HttpClientMiddleware;
@@ -22,11 +22,14 @@ __export(http_client_middleware_exports, {
22
22
  });
23
23
  module.exports = __toCommonJS(http_client_middleware_exports);
24
24
  var import_rxjs = require("rxjs");
25
+ var import_value_or_provider = require("../../utils/value-or-provider.js");
25
26
  var import_authentication_api = require("../authentication.api.js");
26
- function waitForAuthenticationCredentialsMiddleware(authenticationService) {
27
+ function waitForAuthenticationCredentialsMiddleware(authenticationServiceOrProvider) {
28
+ const getAuthenticationService = (0, import_value_or_provider.cacheAsyncValueOrProvider)(authenticationServiceOrProvider);
27
29
  async function waitForAuthenticationCredentialsMiddleware2(request, next, context) {
28
30
  const endpoint = context?.endpoint;
29
31
  if (endpoint?.credentials == true && endpoint.data?.[import_authentication_api.dontWaitForValidToken] != true) {
32
+ const authenticationService = await getAuthenticationService();
30
33
  while (!authenticationService.hasValidToken) {
31
34
  await (0, import_rxjs.firstValueFrom)(authenticationService.validToken$);
32
35
  }
@@ -1 +1 @@
1
- export {};
1
+ import '../../polyfills.js';
@@ -1,4 +1,5 @@
1
1
  "use strict";
2
+ var import_polyfills = require("../../polyfills.js");
2
3
  var import_server = require("../../api/server/index.js");
3
4
  var import_application = require("../../application/application.js");
4
5
  var import_api_client = require("../../authentication/client/api.client.js");
@@ -15,15 +16,6 @@ var import_web_server_module = require("../../module/modules/web-server.module.j
15
16
  var import_configure = require("../../signals/implementation/configure.js");
16
17
  var import_timing = require("../../utils/timing.js");
17
18
  var import_undici = require("undici");
18
- (0, import_configure.configureDefaultSignalsImplementation)();
19
- (0, import_server2.configureAuthenticationServer)({
20
- serviceOptions: { secret: "djp0fq23576aq" },
21
- credentialsRepository: import_mongo_authentication_credentials_repository.MongoAuthenticationCredentialsRepository,
22
- sessionRepository: import_mongo_authentication_session_repository.MongoAuthenticationSessionRepository
23
- });
24
- (0, import_mongo_authentication_credentials_repository.configureMongoAuthenticationCredentialsRepository)({ collection: "credentials" });
25
- (0, import_mongo_authentication_session_repository.configureMongoAuthenticationSessionRepository)({ collection: "sessions" });
26
- (0, import_module3.configureLocalMessageBus)();
27
19
  async function serverTest() {
28
20
  const authenticationService = await (0, import_inject.injectAsync)(import_server2.AuthenticationService);
29
21
  await authenticationService.setCredentials("foobar", "mysuperdupersecret-fvhc54w");
@@ -44,7 +36,16 @@ async function test() {
44
36
  ]);
45
37
  await import_application.Application.shutdown();
46
38
  }
47
- function main() {
39
+ function bootstrap() {
40
+ (0, import_configure.configureDefaultSignalsImplementation)();
41
+ (0, import_server2.configureAuthenticationServer)({
42
+ serviceOptions: { secret: "djp0fq23576aq" },
43
+ credentialsRepository: import_mongo_authentication_credentials_repository.MongoAuthenticationCredentialsRepository,
44
+ sessionRepository: import_mongo_authentication_session_repository.MongoAuthenticationSessionRepository
45
+ });
46
+ (0, import_mongo_authentication_credentials_repository.configureMongoAuthenticationCredentialsRepository)({ collection: "credentials" });
47
+ (0, import_mongo_authentication_session_repository.configureMongoAuthenticationSessionRepository)({ collection: "sessions" });
48
+ (0, import_module3.configureLocalMessageBus)();
48
49
  (0, import_client.configureAuthenticationClient)({
49
50
  authenticationApiClient: import_api_client.AuthenticationApiClient
50
51
  });
@@ -53,4 +54,4 @@ function main() {
53
54
  (0, import_undici_http_client_adapter.configureUndiciHttpClientAdapter)({ dispatcher: new import_undici.Agent({ keepAliveMaxTimeout: 1 }) });
54
55
  (0, import_module.configureHttpClient)({ baseUrl: "http://localhost:8000" });
55
56
  }
56
- import_application.Application.run(main, test, import_web_server_module.WebServerModule);
57
+ import_application.Application.run({ bootstrap }, import_web_server_module.WebServerModule, test);
@@ -1 +1 @@
1
- export {};
1
+ import '../../polyfills.js';
@@ -1,4 +1,5 @@
1
1
  "use strict";
2
+ var import_polyfills = require("../../polyfills.js");
2
3
  var import_server = require("../../api/server/index.js");
3
4
  var import_application = require("../../application/application.js");
4
5
  var import_client = require("../../authentication/client/index.js");
@@ -17,6 +18,8 @@ var import_module4 = require("../../message-bus/local/module.js");
17
18
  var import_modules = require("../../module/modules/index.js");
18
19
  var import_schema = require("../../schema/index.js");
19
20
  var import_configure = require("../../signals/implementation/configure.js");
21
+ var import_first = require("../../utils/iterable-helpers/first.js");
22
+ var import_skip = require("../../utils/iterable-helpers/skip.js");
20
23
  var import_timing = require("../../utils/timing.js");
21
24
  var import_undici = require("undici");
22
25
  var __decorate = function(decorators, target, key, desc) {
@@ -33,6 +36,28 @@ var __metadata = function(k, v) {
33
36
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function")
34
37
  return Reflect.metadata(k, v);
35
38
  };
39
+ class LocalStoragePolyfill {
40
+ #storage = /* @__PURE__ */ new Map();
41
+ get length() {
42
+ return this.#storage.size;
43
+ }
44
+ clear() {
45
+ throw new Error("Method not implemented.");
46
+ }
47
+ getItem(key) {
48
+ return this.#storage.get(key) ?? null;
49
+ }
50
+ key(index) {
51
+ return (0, import_first.first)((0, import_skip.skip)(this.#storage, index))[0];
52
+ }
53
+ removeItem(key) {
54
+ this.#storage.delete(key);
55
+ }
56
+ setItem(key, value) {
57
+ this.#storage.set(key, value);
58
+ }
59
+ }
60
+ globalThis.localStorage = new LocalStoragePolyfill();
36
61
  class CustomTokenPaylod {
37
62
  deviceRegistrationId;
38
63
  }
@@ -47,6 +72,7 @@ __decorate([
47
72
  (0, import_schema.Property)(),
48
73
  __metadata("design:type", String)
49
74
  ], AuthenticationData.prototype, "deviceId", void 0);
75
+ const CustomAuthenticationApiClient = (0, import_client.getAuthenticationApiClient)(CustomTokenPaylod, AuthenticationData);
50
76
  let CustomTokenPayloadProvider = class CustomTokenPayloadProvider2 extends import_authentication_token_payload_provider.AuthenticationTokenPayloadProvider {
51
77
  getTokenPayload(_subject, authenticationData) {
52
78
  return { deviceRegistrationId: `registration:${authenticationData.deviceId}` };
@@ -55,37 +81,43 @@ let CustomTokenPayloadProvider = class CustomTokenPayloadProvider2 extends impor
55
81
  CustomTokenPayloadProvider = __decorate([
56
82
  (0, import_decorators.Singleton)()
57
83
  ], CustomTokenPayloadProvider);
58
- (0, import_module.configureAuthenticationServer)({
59
- serviceOptions: { secret: "djp0fq23576aq" },
60
- credentialsRepository: import_mongo_authentication_credentials_repository.MongoAuthenticationCredentialsRepository,
61
- sessionRepository: import_mongo_authentication_session_repository.MongoAuthenticationSessionRepository,
62
- tokenPayloadProvider: CustomTokenPayloadProvider
63
- });
64
- (0, import_mongo_authentication_credentials_repository.configureMongoAuthenticationCredentialsRepository)({ collection: "credentials" });
65
- (0, import_mongo_authentication_session_repository.configureMongoAuthenticationSessionRepository)({ collection: "sessions" });
66
- const CustomAuthenticationApiClient = (0, import_client.getAuthenticationApiClient)(CustomTokenPaylod, AuthenticationData);
67
- (0, import_client.configureAuthenticationClient)({
68
- authenticationApiClient: CustomAuthenticationApiClient
69
- });
70
- (0, import_module4.configureLocalMessageBus)();
71
84
  async function serverTest() {
72
85
  const authenticationService = await (0, import_inject.injectAsync)(import_authentication_service.AuthenticationService);
73
- await authenticationService.setCredentials("foobar", "supersecret");
86
+ await authenticationService.setCredentials("foobar", "supersecret-dupidupudoo9275");
74
87
  }
75
88
  async function clientTest() {
76
89
  const authenticationService = (0, import_inject.inject)(import_client.AuthenticationService);
77
- await (0, import_timing.timeout)(250);
90
+ await (0, import_timing.timeout)(1500);
78
91
  authenticationService.initialize();
79
- await authenticationService.login("foobar", "supersecret", { deviceId: "my-device" });
92
+ await authenticationService.login("foobar", "supersecret-dupidupudoo9275");
80
93
  authenticationService.token$.subscribe((token) => console.log({ token }));
81
94
  import_application.Application.requestShutdown();
82
95
  }
83
- function main() {
96
+ async function test() {
97
+ await Promise.all([
98
+ serverTest(),
99
+ clientTest()
100
+ ]);
101
+ await import_application.Application.shutdown();
102
+ }
103
+ function bootstrap() {
84
104
  (0, import_configure.configureDefaultSignalsImplementation)();
105
+ (0, import_module.configureAuthenticationServer)({
106
+ serviceOptions: { secret: "djp0fq23576aq" },
107
+ credentialsRepository: import_mongo_authentication_credentials_repository.MongoAuthenticationCredentialsRepository,
108
+ sessionRepository: import_mongo_authentication_session_repository.MongoAuthenticationSessionRepository,
109
+ tokenPayloadProvider: CustomTokenPayloadProvider
110
+ });
111
+ (0, import_mongo_authentication_credentials_repository.configureMongoAuthenticationCredentialsRepository)({ collection: "credentials" });
112
+ (0, import_mongo_authentication_session_repository.configureMongoAuthenticationSessionRepository)({ collection: "sessions" });
113
+ (0, import_module4.configureLocalMessageBus)();
114
+ (0, import_client.configureAuthenticationClient)({
115
+ authenticationApiClient: CustomAuthenticationApiClient,
116
+ initialAuthenticationData: { deviceId: "my-device" }
117
+ });
85
118
  (0, import_module3.configureNodeHttpServer)();
86
119
  (0, import_server.configureApiServer)({ controllers: [import_authentication_api_controller.AuthenticationApiController] });
87
120
  (0, import_undici_http_client_adapter.configureUndiciHttpClientAdapter)({ dispatcher: new import_undici.Agent({ keepAliveMaxTimeout: 1 }) });
88
121
  (0, import_module2.configureHttpClient)({ baseUrl: "http://localhost:8000" });
89
- import_application.Application.run(import_modules.WebServerModule, serverTest, clientTest);
90
122
  }
91
- main();
123
+ import_application.Application.run({ bootstrap }, import_modules.WebServerModule, test);
@@ -2,7 +2,7 @@ import { resolveArgumentType } from '../../injector/index.js';
2
2
  import type { Resolvable } from '../../injector/interfaces.js';
3
3
  import type { OneOrMany, UndefinableJson } from '../../types.js';
4
4
  import type { HttpMethod, HttpValue } from '../types.js';
5
- import type { HttpClientOptions } from './http-client-options.js';
5
+ import { HttpClientOptions } from './http-client-options.js';
6
6
  import type { HttpClientRequestOptions } from './http-client-request.js';
7
7
  import { HttpClientRequest } from './http-client-request.js';
8
8
  import type { HttpClientResponse } from './http-client-response.js';
@@ -34,6 +34,7 @@ var import_url_builder = require("../../utils/url-builder.js");
34
34
  var import_http_headers = require("../http-headers.js");
35
35
  var import_http_error = require("../http.error.js");
36
36
  var import_types = require("../types.js");
37
+ var import_http_client_options = require("./http-client-options.js");
37
38
  var import_http_client_request = require("./http-client-request.js");
38
39
  var import_http_client_adapter = require("./http-client.adapter.js");
39
40
  var import_tokens = require("./tokens.js");
@@ -53,11 +54,11 @@ var __metadata = function(k, v) {
53
54
  };
54
55
  let HttpClient = class HttpClient2 {
55
56
  adapter = (0, import_injector.inject)(import_http_client_adapter.HttpClientAdapter);
56
- middleware = (0, import_injector.inject)(import_tokens.HTTP_CLIENT_MIDDLEWARES);
57
+ middleware = (0, import_injector.injectAll)(import_tokens.HTTP_CLIENT_MIDDLEWARE, void 0, { optional: true });
57
58
  headers = new import_http_headers.HttpHeaders();
58
59
  internalMiddleware;
59
60
  callHandler;
60
- options = (0, import_injector.injectArgument)(this, { optional: true }) ?? {};
61
+ options = (0, import_injector.injectArgument)(this, { optional: true }) ?? (0, import_injector.inject)(import_http_client_options.HttpClientOptions, void 0, { optional: true }) ?? {};
61
62
  constructor() {
62
63
  this.internalMiddleware = [
63
64
  getBuildRequestUrlMiddleware(this.options.baseUrl),
@@ -1,3 +1,2 @@
1
1
  import type { HttpClientMiddleware } from './middleware.js';
2
2
  export declare const HTTP_CLIENT_MIDDLEWARE: import("../../injector/token.js").InjectionToken<HttpClientMiddleware, never>;
3
- export declare const HTTP_CLIENT_MIDDLEWARES: import("../../injector/token.js").InjectionToken<HttpClientMiddleware[], never>;
@@ -18,12 +18,8 @@ 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
- HTTP_CLIENT_MIDDLEWARE: () => HTTP_CLIENT_MIDDLEWARE,
22
- HTTP_CLIENT_MIDDLEWARES: () => HTTP_CLIENT_MIDDLEWARES
21
+ HTTP_CLIENT_MIDDLEWARE: () => HTTP_CLIENT_MIDDLEWARE
23
22
  });
24
23
  module.exports = __toCommonJS(tokens_exports);
25
- var import_injector = require("../../injector/injector.js");
26
24
  var import_token = require("../../injector/token.js");
27
25
  const HTTP_CLIENT_MIDDLEWARE = (0, import_token.injectionToken)("HttpClientMiddleware");
28
- const HTTP_CLIENT_MIDDLEWARES = (0, import_token.injectionToken)("HttpClientMiddlewares");
29
- import_injector.Injector.register(HTTP_CLIENT_MIDDLEWARES, { useToken: HTTP_CLIENT_MIDDLEWARE, resolveAll: true });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tstdl/base",
3
- "version": "0.87.5",
3
+ "version": "0.87.7",
4
4
  "author": "Patrick Hein",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -1,3 +1,8 @@
1
- export type ValueOrProvider<T> = T extends () => any ? never : T | (() => T);
2
- export type ResolvedValueOrProvider<T extends ValueOrProvider<any>> = T extends ValueOrProvider<infer U> ? U : never;
1
+ export type Provider<T> = () => T;
2
+ export type AsyncProvider<T> = () => (T | Promise<T>);
3
+ export type ValueOrProvider<T> = T extends (() => any) ? never : (T | Provider<T>);
4
+ export type ValueOrAsyncProvider<T> = T extends (() => any) ? never : (T | Provider<T> | AsyncProvider<T>);
5
+ export type ResolvedValueOrProvider<T extends ValueOrAsyncProvider<any>> = T extends ValueOrAsyncProvider<infer U> ? U : never;
3
6
  export declare function resolveValueOrProvider<T>(valueOrProvider: ValueOrProvider<T>): T;
7
+ export declare function resolveAsyncValueOrProvider<T>(valueOrProvider: ValueOrAsyncProvider<T>): Promise<T>;
8
+ export declare function cacheAsyncValueOrProvider<T>(provider: ValueOrAsyncProvider<T>): () => (T | Promise<T>);
@@ -18,6 +18,8 @@ var __copyProps = (to, from, except, desc) => {
18
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
19
  var value_or_provider_exports = {};
20
20
  __export(value_or_provider_exports, {
21
+ cacheAsyncValueOrProvider: () => cacheAsyncValueOrProvider,
22
+ resolveAsyncValueOrProvider: () => resolveAsyncValueOrProvider,
21
23
  resolveValueOrProvider: () => resolveValueOrProvider
22
24
  });
23
25
  module.exports = __toCommonJS(value_or_provider_exports);
@@ -28,3 +30,18 @@ function resolveValueOrProvider(valueOrProvider) {
28
30
  }
29
31
  return valueOrProvider;
30
32
  }
33
+ async function resolveAsyncValueOrProvider(valueOrProvider) {
34
+ if ((0, import_type_guards.isFunction)(valueOrProvider)) {
35
+ return valueOrProvider();
36
+ }
37
+ return valueOrProvider;
38
+ }
39
+ function cacheAsyncValueOrProvider(provider) {
40
+ let getValue = async () => {
41
+ const valuePromise = resolveAsyncValueOrProvider(provider);
42
+ getValue = async () => valuePromise;
43
+ void valuePromise.then((resolvedValue) => getValue = () => resolvedValue);
44
+ return valuePromise;
45
+ };
46
+ return () => getValue();
47
+ }