@tstdl/base 0.92.167 → 0.93.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 (317) hide show
  1. package/application/application.d.ts +12 -18
  2. package/application/application.js +48 -69
  3. package/application/index.d.ts +1 -5
  4. package/application/index.js +1 -5
  5. package/application/providers.d.ts +10 -0
  6. package/application/providers.js +54 -0
  7. package/audit/audit.model.d.ts +15 -0
  8. package/audit/audit.model.js +73 -0
  9. package/audit/auditor.d.ts +42 -0
  10. package/audit/auditor.js +111 -0
  11. package/audit/index.d.ts +3 -0
  12. package/audit/index.js +3 -0
  13. package/audit/types.d.ts +22 -0
  14. package/audit/types.js +19 -0
  15. package/authentication/client/authentication.service.d.ts +1 -3
  16. package/authentication/client/authentication.service.js +4 -5
  17. package/browser/browser-context-controller.d.ts +2 -4
  18. package/browser/browser-context-controller.js +5 -6
  19. package/browser/browser-controller.d.ts +2 -4
  20. package/browser/browser-controller.js +3 -4
  21. package/browser/browser.service.d.ts +1 -3
  22. package/browser/browser.service.js +1 -2
  23. package/browser/page-controller.d.ts +2 -4
  24. package/browser/page-controller.js +7 -8
  25. package/browser/utils.js +3 -3
  26. package/cancellation/token.d.ts +104 -41
  27. package/cancellation/token.js +125 -54
  28. package/core.d.ts +1 -13
  29. package/core.js +1 -46
  30. package/disposable/disposable.d.ts +0 -8
  31. package/disposable/disposable.js +1 -3
  32. package/disposable/index.d.ts +0 -6
  33. package/disposable/index.js +0 -6
  34. package/disposable/using.d.ts +0 -1
  35. package/disposable/using.js +2 -3
  36. package/distributed-loop/distributed-loop.js +2 -2
  37. package/errors/utils.js +4 -1
  38. package/examples/api/authentication.js +11 -5
  39. package/examples/api/basic-overview.js +17 -12
  40. package/examples/api/custom-authentication.js +13 -7
  41. package/examples/api/streaming.js +15 -12
  42. package/examples/browser/basic.js +6 -3
  43. package/examples/document-management/main.js +6 -3
  44. package/examples/http/client.js +7 -3
  45. package/examples/mail/basic.js +9 -7
  46. package/examples/pdf/basic.js +8 -6
  47. package/examples/template/basic.js +7 -5
  48. package/http/client/http-client-request.d.ts +1 -2
  49. package/http/client/http-client-request.js +1 -2
  50. package/http/server/http-server.d.ts +1 -3
  51. package/http/server/http-server.js +0 -1
  52. package/http/server/node/node-http-server.d.ts +1 -2
  53. package/http/server/node/node-http-server.js +1 -2
  54. package/import.js +1 -1
  55. package/injector/injector.d.ts +1 -1
  56. package/injector/types.d.ts +3 -4
  57. package/lock/lock.d.ts +40 -21
  58. package/lock/lock.js +74 -1
  59. package/lock/postgres/drizzle/0000_busy_tattoo.sql +7 -0
  60. package/lock/postgres/drizzle/meta/0000_snapshot.json +65 -0
  61. package/lock/postgres/drizzle/meta/_journal.json +13 -0
  62. package/lock/postgres/drizzle.config.js +11 -0
  63. package/lock/postgres/index.d.ts +2 -0
  64. package/lock/postgres/index.js +2 -0
  65. package/lock/postgres/lock.d.ts +14 -0
  66. package/lock/postgres/lock.js +127 -0
  67. package/lock/postgres/models/index.d.ts +2 -0
  68. package/lock/postgres/models/index.js +2 -0
  69. package/lock/postgres/models/lock.model.d.ts +7 -0
  70. package/{examples/orm/user.model.js → lock/postgres/models/lock.model.js} +22 -30
  71. package/lock/postgres/models/schemas.d.ts +3 -0
  72. package/lock/postgres/models/schemas.js +4 -0
  73. package/lock/postgres/module.d.ts +6 -0
  74. package/lock/postgres/module.js +26 -0
  75. package/lock/postgres/provider.d.ts +6 -0
  76. package/lock/postgres/provider.js +29 -0
  77. package/lock/provider.d.ts +12 -2
  78. package/lock/provider.js +24 -1
  79. package/lock/web/web-lock.d.ts +4 -3
  80. package/lock/web/web-lock.js +49 -42
  81. package/lock/web/web-lock.provider.d.ts +0 -3
  82. package/lock/web/web-lock.provider.js +5 -22
  83. package/logger/formatter.d.ts +13 -0
  84. package/logger/formatter.js +3 -0
  85. package/logger/formatters/index.d.ts +2 -0
  86. package/logger/formatters/index.js +2 -0
  87. package/logger/formatters/json.d.ts +5 -0
  88. package/logger/formatters/json.js +33 -0
  89. package/logger/formatters/pretty-print.d.ts +5 -0
  90. package/logger/formatters/pretty-print.js +55 -0
  91. package/logger/index.d.ts +5 -2
  92. package/logger/index.js +5 -2
  93. package/logger/level.d.ts +10 -8
  94. package/logger/level.js +9 -9
  95. package/logger/logger.d.ts +21 -30
  96. package/logger/logger.js +98 -26
  97. package/logger/manager.d.ts +20 -0
  98. package/logger/manager.js +86 -0
  99. package/logger/tokens.d.ts +1 -1
  100. package/logger/tokens.js +1 -1
  101. package/logger/transport.d.ts +14 -0
  102. package/logger/transport.js +16 -0
  103. package/logger/transports/console.d.ts +14 -0
  104. package/logger/transports/console.js +36 -0
  105. package/logger/transports/index.d.ts +1 -0
  106. package/logger/transports/index.js +1 -0
  107. package/mail/clients/nodemailer.mail-client.d.ts +0 -1
  108. package/mail/clients/nodemailer.mail-client.js +9 -7
  109. package/message-bus/local/local-message-bus.js +2 -2
  110. package/message-bus/message-bus-base.d.ts +2 -3
  111. package/message-bus/message-bus-base.js +5 -6
  112. package/message-bus/message-bus.d.ts +1 -2
  113. package/message-bus/message-bus.js +1 -2
  114. package/module/index.d.ts +0 -2
  115. package/module/index.js +0 -2
  116. package/module/module.d.ts +17 -18
  117. package/module/module.js +47 -12
  118. package/module/modules/function.module.d.ts +6 -6
  119. package/module/modules/function.module.js +25 -9
  120. package/module/modules/web-server.module.d.ts +2 -10
  121. package/module/modules/web-server.module.js +3 -11
  122. package/openid-connect/index.d.ts +0 -2
  123. package/openid-connect/index.js +0 -2
  124. package/openid-connect/oidc-state.model.d.ts +4 -5
  125. package/openid-connect/oidc-state.model.js +51 -1
  126. package/openid-connect/oidc.service-model.d.ts +1 -1
  127. package/openid-connect/oidc.service.d.ts +2 -6
  128. package/openid-connect/oidc.service.js +24 -37
  129. package/orm/decorators.d.ts +10 -1
  130. package/orm/decorators.js +8 -0
  131. package/orm/server/repository.d.ts +3 -1
  132. package/orm/server/repository.js +32 -3
  133. package/package.json +19 -29
  134. package/pdf/pdf.service.js +9 -9
  135. package/pool/pool.d.ts +1 -3
  136. package/pool/pool.js +3 -4
  137. package/queue/postgres/job.model.d.ts +1 -2
  138. package/queue/postgres/job.model.js +1 -2
  139. package/queue/postgres/module.js +1 -1
  140. package/threading/thread-pool.d.ts +1 -3
  141. package/threading/thread-pool.js +7 -8
  142. package/utils/format-error.d.ts +7 -0
  143. package/utils/format-error.js +59 -17
  144. package/utils/function/memoize.d.ts +22 -7
  145. package/utils/function/memoize.js +82 -23
  146. package/utils/index.d.ts +1 -0
  147. package/utils/index.js +1 -0
  148. package/utils/object/dereference.d.ts +51 -19
  149. package/utils/object/dereference.js +52 -43
  150. package/utils/timing.js +2 -2
  151. package/utils/try-chain.d.ts +22 -0
  152. package/utils/try-chain.js +46 -0
  153. package/database/entity-repository.d.ts +0 -50
  154. package/database/entity-repository.js +0 -3
  155. package/database/entity.d.ts +0 -7
  156. package/database/entity.js +0 -1
  157. package/database/id.d.ts +0 -1
  158. package/database/id.js +0 -9
  159. package/database/index.d.ts +0 -11
  160. package/database/index.js +0 -11
  161. package/database/module.d.ts +0 -8
  162. package/database/module.js +0 -11
  163. package/database/mongo/classes.d.ts +0 -21
  164. package/database/mongo/classes.js +0 -26
  165. package/database/mongo/index.d.ts +0 -15
  166. package/database/mongo/index.js +0 -15
  167. package/database/mongo/model/document.d.ts +0 -29
  168. package/database/mongo/model/document.js +0 -63
  169. package/database/mongo/model/index.d.ts +0 -1
  170. package/database/mongo/model/index.js +0 -1
  171. package/database/mongo/module.d.ts +0 -8
  172. package/database/mongo/module.js +0 -68
  173. package/database/mongo/mongo-base.repository.d.ts +0 -103
  174. package/database/mongo/mongo-base.repository.js +0 -263
  175. package/database/mongo/mongo-bulk.d.ts +0 -35
  176. package/database/mongo/mongo-bulk.js +0 -90
  177. package/database/mongo/mongo-entity-repository.d.ts +0 -98
  178. package/database/mongo/mongo-entity-repository.js +0 -278
  179. package/database/mongo/operations.d.ts +0 -10
  180. package/database/mongo/operations.js +0 -54
  181. package/database/mongo/query-converter.d.ts +0 -6
  182. package/database/mongo/query-converter.js +0 -83
  183. package/database/mongo/simple-entity-repository.d.ts +0 -7
  184. package/database/mongo/simple-entity-repository.js +0 -6
  185. package/database/mongo/types.d.ts +0 -50
  186. package/database/mongo/types.js +0 -3
  187. package/database/query.d.ts +0 -121
  188. package/database/query.js +0 -7
  189. package/database/utils.d.ts +0 -2
  190. package/database/utils.js +0 -3
  191. package/disposable/async-disposer.d.ts +0 -35
  192. package/disposable/async-disposer.js +0 -125
  193. package/examples/orm/drizzle.config.js +0 -6
  194. package/examples/orm/schemas.d.ts +0 -3
  195. package/examples/orm/schemas.js +0 -4
  196. package/examples/orm/test.d.ts +0 -1
  197. package/examples/orm/test.js +0 -11
  198. package/examples/orm/user.model.d.ts +0 -13
  199. package/key-value-store/mongo/index.d.ts +0 -6
  200. package/key-value-store/mongo/index.js +0 -6
  201. package/key-value-store/mongo/module.d.ts +0 -8
  202. package/key-value-store/mongo/module.js +0 -18
  203. package/key-value-store/mongo/mongo-key-value-store.provider.d.ts +0 -8
  204. package/key-value-store/mongo/mongo-key-value-store.provider.js +0 -26
  205. package/key-value-store/mongo/mongo-key-value.model.d.ts +0 -7
  206. package/key-value-store/mongo/mongo-key-value.model.js +0 -1
  207. package/key-value-store/mongo/mongo-key-value.repository.d.ts +0 -10
  208. package/key-value-store/mongo/mongo-key-value.repository.js +0 -31
  209. package/key-value-store/mongo/mongo-key-value.store.d.ts +0 -15
  210. package/key-value-store/mongo/mongo-key-value.store.js +0 -82
  211. package/key-value-store/mongo/tokens.d.ts +0 -3
  212. package/key-value-store/mongo/tokens.js +0 -2
  213. package/lock/mongo/index.d.ts +0 -5
  214. package/lock/mongo/index.js +0 -5
  215. package/lock/mongo/lock.d.ts +0 -14
  216. package/lock/mongo/lock.js +0 -125
  217. package/lock/mongo/model.d.ts +0 -6
  218. package/lock/mongo/model.js +0 -1
  219. package/lock/mongo/module.d.ts +0 -12
  220. package/lock/mongo/module.js +0 -20
  221. package/lock/mongo/mongo-lock-repository.d.ts +0 -14
  222. package/lock/mongo/mongo-lock-repository.js +0 -67
  223. package/lock/mongo/provider.d.ts +0 -8
  224. package/lock/mongo/provider.js +0 -36
  225. package/logger/console/index.d.ts +0 -1
  226. package/logger/console/index.js +0 -1
  227. package/logger/console/logger.d.ts +0 -11
  228. package/logger/console/logger.js +0 -64
  229. package/logger/noop/index.d.ts +0 -1
  230. package/logger/noop/index.js +0 -1
  231. package/logger/noop/logger.d.ts +0 -9
  232. package/logger/noop/logger.js +0 -21
  233. package/migration/index.d.ts +0 -9
  234. package/migration/index.js +0 -9
  235. package/migration/migration-state-repository.d.ts +0 -4
  236. package/migration/migration-state-repository.js +0 -3
  237. package/migration/migration-state.d.ts +0 -6
  238. package/migration/migration-state.js +0 -1
  239. package/migration/migrator.d.ts +0 -23
  240. package/migration/migrator.js +0 -76
  241. package/migration/mongo/index.d.ts +0 -2
  242. package/migration/mongo/index.js +0 -2
  243. package/migration/mongo/migration-state-repository.d.ts +0 -11
  244. package/migration/mongo/migration-state-repository.js +0 -32
  245. package/migration/mongo/module.d.ts +0 -12
  246. package/migration/mongo/module.js +0 -17
  247. package/module/module-base.d.ts +0 -18
  248. package/module/module-base.js +0 -40
  249. package/module/module-metric-reporter.d.ts +0 -29
  250. package/module/module-metric-reporter.js +0 -62
  251. package/openid-connect/mongo-oidc-state.repository.d.ts +0 -21
  252. package/openid-connect/mongo-oidc-state.repository.js +0 -52
  253. package/openid-connect/oidc-state.repository.d.ts +0 -4
  254. package/openid-connect/oidc-state.repository.js +0 -3
  255. package/process-shutdown.d.ts +0 -9
  256. package/process-shutdown.js +0 -65
  257. package/queue/mongo/index.d.ts +0 -4
  258. package/queue/mongo/index.js +0 -4
  259. package/queue/mongo/job.d.ts +0 -12
  260. package/queue/mongo/job.js +0 -1
  261. package/queue/mongo/mongo-job.repository.d.ts +0 -13
  262. package/queue/mongo/mongo-job.repository.js +0 -54
  263. package/queue/mongo/queue.d.ts +0 -38
  264. package/queue/mongo/queue.js +0 -266
  265. package/queue/mongo/queue.provider.d.ts +0 -18
  266. package/queue/mongo/queue.provider.js +0 -38
  267. package/search-index/elastic/config.d.ts +0 -8
  268. package/search-index/elastic/config.js +0 -26
  269. package/search-index/elastic/index.d.ts +0 -8
  270. package/search-index/elastic/index.js +0 -8
  271. package/search-index/elastic/keyword-rewriter.d.ts +0 -8
  272. package/search-index/elastic/keyword-rewriter.js +0 -18
  273. package/search-index/elastic/model/elastic-query.d.ts +0 -16
  274. package/search-index/elastic/model/elastic-query.js +0 -1
  275. package/search-index/elastic/model/index-mapping.d.ts +0 -26
  276. package/search-index/elastic/model/index-mapping.js +0 -4
  277. package/search-index/elastic/model/index.d.ts +0 -3
  278. package/search-index/elastic/model/index.js +0 -3
  279. package/search-index/elastic/model/sort.d.ts +0 -8
  280. package/search-index/elastic/model/sort.js +0 -1
  281. package/search-index/elastic/module.d.ts +0 -10
  282. package/search-index/elastic/module.js +0 -49
  283. package/search-index/elastic/query-builder/boolean-query-builder.d.ts +0 -11
  284. package/search-index/elastic/query-builder/boolean-query-builder.js +0 -52
  285. package/search-index/elastic/query-builder/index.d.ts +0 -1
  286. package/search-index/elastic/query-builder/index.js +0 -1
  287. package/search-index/elastic/query-converter.d.ts +0 -9
  288. package/search-index/elastic/query-converter.js +0 -183
  289. package/search-index/elastic/search-index.d.ts +0 -30
  290. package/search-index/elastic/search-index.js +0 -144
  291. package/search-index/elastic/sort-converter.d.ts +0 -4
  292. package/search-index/elastic/sort-converter.js +0 -14
  293. package/search-index/elastic/types.d.ts +0 -5
  294. package/search-index/elastic/types.js +0 -1
  295. package/search-index/error.d.ts +0 -10
  296. package/search-index/error.js +0 -14
  297. package/search-index/index.d.ts +0 -3
  298. package/search-index/index.js +0 -3
  299. package/search-index/memory/index.d.ts +0 -1
  300. package/search-index/memory/index.js +0 -1
  301. package/search-index/memory/memory-search-index.d.ts +0 -19
  302. package/search-index/memory/memory-search-index.js +0 -144
  303. package/search-index/search-index.d.ts +0 -46
  304. package/search-index/search-index.js +0 -31
  305. package/search-index/search-result.d.ts +0 -12
  306. package/search-index/search-result.js +0 -1
  307. package/theme/adapters/css-adapter.d.ts +0 -5
  308. package/theme/adapters/css-adapter.js +0 -29
  309. package/theme/adapters/index.d.ts +0 -2
  310. package/theme/adapters/index.js +0 -2
  311. package/theme/adapters/tailwind-adapter.d.ts +0 -18
  312. package/theme/adapters/tailwind-adapter.js +0 -32
  313. package/theme/index.d.ts +0 -1
  314. package/theme/index.js +0 -1
  315. package/theme/theme-service.d.ts +0 -43
  316. package/theme/theme-service.js +0 -128
  317. /package/{examples/orm → lock/postgres}/drizzle.config.d.ts +0 -0
@@ -1,30 +1,24 @@
1
- import type { CancellationSignal } from '../cancellation/token.js';
1
+ import { CancellationSignal } from '../cancellation/token.js';
2
+ import { type ProvidersItem } from '../injector/injector.js';
2
3
  import type { Resolvable, resolveArgumentType } from '../injector/interfaces.js';
3
4
  import type { LoggerArgument } from '../logger/index.js';
4
- import type { Module } from '../module/module.js';
5
- import type { FunctionModuleFunction } from '../module/modules/function.module.js';
5
+ import { Module } from '../module/index.js';
6
6
  import type { OneOrMany, Type } from '../types/index.js';
7
- export type BootstrapFn = () => void | Promise<void>;
8
- export type RunOptions = {
9
- bootstrap?: OneOrMany<BootstrapFn>;
10
- };
7
+ export type InitializerFn = () => void | Promise<void>;
8
+ export type DestructorFn = () => void | Promise<void>;
9
+ export declare const APPLICATION_MODULE: import("../injector/token.js").InjectionToken<Module, never>;
10
+ export declare const APPLICATION_INITIALIZER: import("../injector/token.js").InjectionToken<InitializerFn, never>;
11
+ export declare const APPLICATION_DESTRUCTOR: import("../injector/token.js").InjectionToken<DestructorFn, never>;
11
12
  export type ApplicationArgument = LoggerArgument;
12
13
  export declare class Application implements Resolvable<ApplicationArgument> {
13
14
  #private;
14
- static _instance: Application | undefined;
15
- private static get instance();
16
15
  readonly [resolveArgumentType]: string;
16
+ static create(name: string, providers?: OneOrMany<ProvidersItem>[]): Application;
17
+ static run(name: string, providers?: OneOrMany<ProvidersItem>[]): Application;
17
18
  get shutdownSignal(): CancellationSignal;
18
- static get shutdownSignal(): CancellationSignal;
19
- static registerModule(moduleType: Type<Module>): void;
20
- static registerModuleFunction(fn: FunctionModuleFunction): void;
21
- static run(...functionsAndModules: [RunOptions | OneOrMany<FunctionModuleFunction | Type<Module>>, ...OneOrMany<FunctionModuleFunction | Type<Module>>[]]): void;
22
- static waitForShutdown(): Promise<void>;
23
- static shutdown(): Promise<void>;
24
- static requestShutdown(): void;
25
19
  registerModule(moduleType: Module | Type<Module>): void;
26
- registerModuleFunction(fn: FunctionModuleFunction): void;
27
- run(...optionsFunctionsAndModules: [RunOptions | OneOrMany<FunctionModuleFunction | Type<Module>>, ...OneOrMany<FunctionModuleFunction | Type<Module>>[]]): void;
20
+ run(): void;
21
+ runAndWait(): Promise<void>;
28
22
  shutdown(): Promise<void>;
29
23
  requestShutdown(): void;
30
24
  waitForShutdown(): Promise<void>;
@@ -5,75 +5,54 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
5
5
  return c > 3 && r && Object.defineProperty(target, key, r), r;
6
6
  };
7
7
  var Application_1;
8
- import { getGlobalInjector } from '../core.js';
8
+ import { CancellationSignal, CancellationToken } from '../cancellation/token.js';
9
9
  import { Singleton } from '../injector/decorators.js';
10
- import { inject, injectArgument, runInInjectionContext } from '../injector/inject.js';
10
+ import { inject, injectAll, injectArgument, runInInjectionContext } from '../injector/inject.js';
11
11
  import { Injector } from '../injector/injector.js';
12
+ import { injectionToken } from '../injector/token.js';
12
13
  import { Logger } from '../logger/index.js';
13
- import { ModuleBase } from '../module/module-base.js';
14
- import { ModuleState } from '../module/module.js';
15
- import { FunctionModule } from '../module/modules/function.module.js';
16
- import { getShutdownSignal, getShutdownToken } from '../process-shutdown.js';
14
+ import { Module, ModuleState } from '../module/index.js';
17
15
  import { DeferredPromise } from '../promise/deferred-promise.js';
18
- import { toArray } from '../utils/array/array.js';
19
16
  import { mapAsync } from '../utils/async-iterable-helpers/map.js';
20
17
  import { toArrayAsync } from '../utils/async-iterable-helpers/to-array.js';
21
- import { isDefined, isFunction, isObject, isUndefined } from '../utils/type-guards.js';
22
- let Application = class Application {
23
- static { Application_1 = this; }
24
- static _instance;
25
- static get instance() {
26
- if (isUndefined(this._instance)) {
27
- this._instance = getGlobalInjector().resolve(Application_1, 'App');
28
- // @ts-expect-error readonly
29
- this._instance.#shutdownToken = getShutdownToken();
30
- }
31
- return this._instance;
32
- }
18
+ import { isDefined, isFunction } from '../utils/type-guards.js';
19
+ export const APPLICATION_MODULE = injectionToken('ApplicationModule');
20
+ export const APPLICATION_INITIALIZER = injectionToken('ApplicationInitializer');
21
+ export const APPLICATION_DESTRUCTOR = injectionToken('ApplicationDestructor');
22
+ let Application = Application_1 = class Application {
33
23
  #name = injectArgument(this);
34
- #injector = inject(Injector).fork(`${this.#name}Injector`);
35
- #logger = this.#injector.resolve(Logger, this.#name);
36
- #moduleTypesAndInstances = new Set();
24
+ #injector = inject(Injector);
25
+ #logger = inject(Logger, this.#name);
26
+ #moduleTypesAndInstances = new Set(injectAll(APPLICATION_MODULE, undefined, { optional: true }));
37
27
  #shutdownPromise = new DeferredPromise();
38
- #shutdownToken = getShutdownSignal().createChild();
39
- get shutdownSignal() {
40
- return this.#shutdownToken.signal;
41
- }
42
- static get shutdownSignal() {
43
- return Application_1.instance.shutdownSignal;
44
- }
45
- static registerModule(moduleType) {
46
- Application_1.instance.registerModule(moduleType);
47
- }
48
- static registerModuleFunction(fn) {
49
- Application_1.instance.registerModuleFunction(fn);
50
- }
51
- static run(...functionsAndModules) {
52
- Application_1.instance.run(...functionsAndModules);
53
- }
54
- static async waitForShutdown() {
55
- return Application_1.instance.waitForShutdown();
28
+ #shutdownToken = inject(CancellationSignal, undefined, { optional: true })?.createChild() ?? new CancellationToken();
29
+ static create(name, providers = []) {
30
+ const injector = new Injector(`${name}Injector`);
31
+ for (const providersItem of providers.flat()) {
32
+ injector.register(providersItem.provide, providersItem, { multi: providersItem.multi });
33
+ }
34
+ return injector.resolve(Application_1, name);
56
35
  }
57
- static async shutdown() {
58
- await Application_1.instance.shutdown();
36
+ static run(name, providers = []) {
37
+ const app = Application_1.create(name, providers);
38
+ app.run();
39
+ return app;
59
40
  }
60
- static requestShutdown() {
61
- Application_1.instance.requestShutdown();
41
+ get shutdownSignal() {
42
+ return this.#shutdownToken.signal;
62
43
  }
63
44
  registerModule(moduleType) {
64
45
  this.#moduleTypesAndInstances.add(moduleType);
65
46
  }
66
- registerModuleFunction(fn) {
67
- const module = new FunctionModule(fn);
68
- this.registerModule(module);
69
- }
70
- run(...optionsFunctionsAndModules) {
47
+ run() {
71
48
  if (this.#shutdownToken.isSet) {
72
49
  throw new Error('Application was shut down.');
73
50
  }
74
- const options = ((optionsFunctionsAndModules.length > 0) && isObject(optionsFunctionsAndModules[0])) ? optionsFunctionsAndModules[0] : undefined;
75
- const functionsAndModules = (isUndefined(options) ? optionsFunctionsAndModules : optionsFunctionsAndModules.slice(1));
76
- void this._run(functionsAndModules, options);
51
+ void this._run();
52
+ }
53
+ async runAndWait() {
54
+ this.run();
55
+ await this.waitForShutdown();
77
56
  }
78
57
  async shutdown() {
79
58
  this.requestShutdown();
@@ -86,28 +65,19 @@ let Application = class Application {
86
65
  this.#shutdownToken.set();
87
66
  }
88
67
  async waitForShutdown() {
89
- return this.#shutdownPromise;
68
+ await this.#shutdownPromise;
90
69
  }
91
- async _run(functionsAndModules, options = {}) {
70
+ async _run() {
92
71
  let modules;
93
72
  try {
94
- for (const fnOrModule of functionsAndModules.flatMap((fns) => fns)) {
95
- if (fnOrModule.prototype instanceof ModuleBase) {
96
- this.registerModule(fnOrModule);
97
- }
98
- else {
99
- this.registerModuleFunction(fnOrModule);
100
- }
73
+ const initializers = await this.#injector.resolveAllAsync(APPLICATION_INITIALIZER, undefined, { optional: true });
74
+ for (const initializer of initializers) {
75
+ await runInInjectionContext(this.#injector, initializer);
101
76
  }
102
- if (isDefined(options.bootstrap)) {
103
- for (const fn of toArray(options.bootstrap)) {
104
- await runInInjectionContext(this.#injector, fn);
105
- }
106
- }
107
- modules = await toArrayAsync(mapAsync(this.#moduleTypesAndInstances, async (instanceOrType) => (isFunction(instanceOrType) ? this.#injector.resolveAsync(instanceOrType) : instanceOrType)));
77
+ modules = await toArrayAsync(mapAsync(this.#moduleTypesAndInstances, async (instanceOrType) => (isFunction(instanceOrType) ? await this.#injector.resolveAsync(instanceOrType) : instanceOrType)));
108
78
  await Promise.race([
109
79
  this.runModules(modules),
110
- this.shutdownSignal
80
+ this.shutdownSignal,
111
81
  ]);
112
82
  }
113
83
  catch (error) {
@@ -119,6 +89,15 @@ let Application = class Application {
119
89
  if (isDefined(modules)) {
120
90
  await this.stopModules(modules);
121
91
  }
92
+ const destructors = await this.#injector.resolveAllAsync(APPLICATION_DESTRUCTOR, undefined, { optional: true });
93
+ for (const destructor of destructors) {
94
+ try {
95
+ await runInInjectionContext(this.#injector, destructor);
96
+ }
97
+ catch (error) {
98
+ this.#logger.error(error, { message: 'An error occurred during application destruction.' });
99
+ }
100
+ }
122
101
  await this.#injector.dispose();
123
102
  this.#logger.info('Bye');
124
103
  }
@@ -128,7 +107,7 @@ let Application = class Application {
128
107
  const promises = modules.map(async (module) => {
129
108
  try {
130
109
  this.#logger.info(`Starting module ${module.name}`);
131
- await runInInjectionContext(this.#injector, async () => module.run());
110
+ await runInInjectionContext(this.#injector, async () => await module.run());
132
111
  this.#logger.info(`Module ${module.name} stopped.`);
133
112
  }
134
113
  catch (error) {
@@ -1,6 +1,2 @@
1
- /**
2
- * Start application modules and shutting down the app
3
- *
4
- * @module Application
5
- */
6
1
  export * from './application.js';
2
+ export * from './providers.js';
@@ -1,6 +1,2 @@
1
- /**
2
- * Start application modules and shutting down the app
3
- *
4
- * @module Application
5
- */
6
1
  export * from './application.js';
2
+ export * from './providers.js';
@@ -0,0 +1,10 @@
1
+ import { CancellationSignal } from '../cancellation/index.js';
2
+ import { type ProvidersItem } from '../injector/index.js';
3
+ import { Module, type FunctionModuleFunction } from '../module/index.js';
4
+ import type { OneOrMany, Type } from '../types/index.js';
5
+ import { type DestructorFn, type InitializerFn } from './application.js';
6
+ export declare function provideModules(...functionsAndModules: OneOrMany<FunctionModuleFunction | Type<Module>>[]): ProvidersItem[];
7
+ export declare function provideInitializer(fn: InitializerFn): ProvidersItem;
8
+ export declare function provideDestructor(fn: DestructorFn): ProvidersItem;
9
+ export declare function provideShutdownSignal(signal: CancellationSignal): ProvidersItem;
10
+ export declare function provideSignalHandler(): ProvidersItem;
@@ -0,0 +1,54 @@
1
+ import { CancellationSignal } from '../cancellation/index.js';
2
+ import { inject } from '../injector/index.js';
3
+ import { Logger } from '../logger/index.js';
4
+ import { FunctionModule, Module } from '../module/index.js';
5
+ import { isFunction } from '../utils/type-guards.js';
6
+ import { typeExtends } from '../utils/type/index.js';
7
+ import { Application, APPLICATION_DESTRUCTOR, APPLICATION_INITIALIZER, APPLICATION_MODULE } from './application.js';
8
+ const quitSignals = ['SIGTERM', 'SIGINT', 'SIGHUP', 'SIGBREAK'];
9
+ const quitEvents = ['uncaughtException', 'unhandledRejection', 'rejectionHandled'];
10
+ export function provideModules(...functionsAndModules) {
11
+ return functionsAndModules.flat().map((fnOrModule) => {
12
+ if (typeExtends(fnOrModule, Module)) {
13
+ return { provide: APPLICATION_MODULE, useValue: fnOrModule, multi: true };
14
+ }
15
+ else if (isFunction(fnOrModule)) {
16
+ return { provide: APPLICATION_MODULE, useToken: FunctionModule, defaultArgument: fnOrModule, multi: true };
17
+ }
18
+ else {
19
+ throw new TypeError('Invalid module or function provided to provideModules');
20
+ }
21
+ });
22
+ }
23
+ export function provideInitializer(fn) {
24
+ return { provide: APPLICATION_INITIALIZER, useValue: fn, multi: true };
25
+ }
26
+ export function provideDestructor(fn) {
27
+ return { provide: APPLICATION_DESTRUCTOR, useValue: fn, multi: true };
28
+ }
29
+ export function provideShutdownSignal(signal) {
30
+ return { provide: CancellationSignal, useValue: signal };
31
+ }
32
+ export function provideSignalHandler() {
33
+ let signalCounter = 0;
34
+ return provideInitializer(() => {
35
+ const application = inject(Application);
36
+ const logger = inject(Logger);
37
+ for (const event of quitEvents) {
38
+ process.on(event, (...args) => {
39
+ logger.error(`QuitEvent occurred: ${event}`, { details: args });
40
+ application.requestShutdown();
41
+ });
42
+ }
43
+ for (const quitSignal of quitSignals) {
44
+ process.on(quitSignal, (signal) => {
45
+ logger.info(`${signal} received, quitting.`);
46
+ application.requestShutdown();
47
+ if (++signalCounter > 1) {
48
+ logger.warn('Forcefully quitting due to multiple signals...');
49
+ setTimeout(() => process.exit(1), 1);
50
+ }
51
+ });
52
+ }
53
+ });
54
+ }
@@ -0,0 +1,15 @@
1
+ import { EntityWithoutMetadata, Json, Timestamp, Uuid } from '../orm/index.js';
2
+ import { ActorType, AuditOutcome, AuditSeverity } from './types.js';
3
+ export declare class AuditEvent extends EntityWithoutMetadata {
4
+ timestamp: Timestamp;
5
+ correlationId?: Uuid;
6
+ module: string;
7
+ action: string;
8
+ outcome: AuditOutcome;
9
+ severity: AuditSeverity;
10
+ actorId: string;
11
+ actorType: ActorType;
12
+ targetId: string;
13
+ targetType: string;
14
+ details?: Json<unknown>;
15
+ }
@@ -0,0 +1,73 @@
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
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
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
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
+ import { EntityWithoutMetadata, Json, Table, Timestamp, Uuid } from '../orm/index.js';
11
+ import { Enumeration, StringProperty } from '../schema/index.js';
12
+ import { ActorType, AuditOutcome, AuditSeverity } from './types.js';
13
+ let AuditEvent = class AuditEvent extends EntityWithoutMetadata {
14
+ timestamp;
15
+ correlationId;
16
+ module;
17
+ action;
18
+ outcome;
19
+ severity;
20
+ actorId;
21
+ actorType;
22
+ targetId;
23
+ targetType;
24
+ details;
25
+ };
26
+ __decorate([
27
+ Timestamp(),
28
+ __metadata("design:type", Number)
29
+ ], AuditEvent.prototype, "timestamp", void 0);
30
+ __decorate([
31
+ Uuid({ nullable: true }),
32
+ __metadata("design:type", String)
33
+ ], AuditEvent.prototype, "correlationId", void 0);
34
+ __decorate([
35
+ StringProperty(),
36
+ __metadata("design:type", String)
37
+ ], AuditEvent.prototype, "module", void 0);
38
+ __decorate([
39
+ StringProperty(),
40
+ __metadata("design:type", String)
41
+ ], AuditEvent.prototype, "action", void 0);
42
+ __decorate([
43
+ Enumeration(AuditOutcome),
44
+ __metadata("design:type", String)
45
+ ], AuditEvent.prototype, "outcome", void 0);
46
+ __decorate([
47
+ Enumeration(AuditSeverity),
48
+ __metadata("design:type", String)
49
+ ], AuditEvent.prototype, "severity", void 0);
50
+ __decorate([
51
+ StringProperty(),
52
+ __metadata("design:type", String)
53
+ ], AuditEvent.prototype, "actorId", void 0);
54
+ __decorate([
55
+ Enumeration(ActorType),
56
+ __metadata("design:type", String)
57
+ ], AuditEvent.prototype, "actorType", void 0);
58
+ __decorate([
59
+ StringProperty(),
60
+ __metadata("design:type", String)
61
+ ], AuditEvent.prototype, "targetId", void 0);
62
+ __decorate([
63
+ StringProperty(),
64
+ __metadata("design:type", String)
65
+ ], AuditEvent.prototype, "targetType", void 0);
66
+ __decorate([
67
+ Json({ nullable: true }),
68
+ __metadata("design:type", Object)
69
+ ], AuditEvent.prototype, "details", void 0);
70
+ AuditEvent = __decorate([
71
+ Table({ name: 'event' })
72
+ ], AuditEvent);
73
+ export { AuditEvent };
@@ -0,0 +1,42 @@
1
+ import { type Resolvable, type resolveArgumentType } from '../injector/index.js';
2
+ import type { UndefinableJsonObject } from '../types/index.js';
3
+ import type { ActorType } from './types.js';
4
+ import { AuditOutcome, AuditSeverity } from './types.js';
5
+ export type AuditPayload = Partial<{
6
+ correlationId?: string;
7
+ outcome?: AuditOutcome;
8
+ severity?: AuditSeverity;
9
+ actorId?: string;
10
+ actorType?: ActorType;
11
+ targetId?: string;
12
+ targetType?: string;
13
+ details?: UndefinableJsonObject;
14
+ }>;
15
+ export type AuditorArgument = string | string[] | {
16
+ module?: string | string[];
17
+ context?: Partial<AuditPayload>;
18
+ };
19
+ export declare class Auditor implements Resolvable<AuditorArgument> {
20
+ #private;
21
+ readonly module: string[];
22
+ readonly context: Partial<Partial<{
23
+ correlationId?: string;
24
+ outcome?: AuditOutcome;
25
+ severity?: AuditSeverity;
26
+ actorId?: string;
27
+ actorType?: ActorType;
28
+ targetId?: string;
29
+ targetType?: string;
30
+ details?: UndefinableJsonObject;
31
+ }>>;
32
+ get moduleString(): string;
33
+ readonly [resolveArgumentType]: AuditorArgument;
34
+ fork(subModule: string | string[]): Auditor;
35
+ with(context: Partial<AuditPayload>): Auditor;
36
+ withCorrelation(): Auditor;
37
+ log(action: string, data?: AuditPayload): Promise<void>;
38
+ info(action: string, data: AuditPayload): Promise<void>;
39
+ warn(action: string, data: AuditPayload): Promise<void>;
40
+ error(action: string, data: AuditPayload): Promise<void>;
41
+ critical(action: string, data: AuditPayload): Promise<void>;
42
+ }
@@ -0,0 +1,111 @@
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
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
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
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
+ var Auditor_1;
11
+ import { createContextProvider } from '../context/index.js';
12
+ import { Injectable, injectArgument } from '../injector/index.js';
13
+ import { injectRepository } from '../orm/server/index.js';
14
+ import { TRANSACTION_TIMESTAMP } from '../orm/sqls.js';
15
+ import { toArray } from '../utils/array/index.js';
16
+ import { Memoize } from '../utils/function/memoize.js';
17
+ import { filterUndefinedFromRecord, objectKeys } from '../utils/object/object.js';
18
+ import { assertDefinedPass, isArray, isNotArray, isObject, isString } from '../utils/type-guards.js';
19
+ import { AuditEvent } from './audit.model.js';
20
+ import { AuditOutcome, AuditSeverity } from './types.js';
21
+ const { runInAuditorCreationContext, getCurrentAuditorCreationContext, isInAuditorCreationContext } = createContextProvider('AuditorCreation');
22
+ let Auditor = Auditor_1 = class Auditor {
23
+ #repository = injectRepository(AuditEvent);
24
+ #argument = isInAuditorCreationContext() ? injectArgument(this, { optional: true }) : undefined;
25
+ #creationContext = getCurrentAuditorCreationContext();
26
+ module = this.#creationContext?.module ?? moduleFromArgument(this.#argument);
27
+ context = this.#creationContext?.context ?? ((isObject(this.#argument) && isNotArray(this.#argument)) ? (this.#argument.context ?? {}) : {});
28
+ get moduleString() {
29
+ return this.module.join('.');
30
+ }
31
+ fork(subModule) {
32
+ return runInAuditorCreationContext({
33
+ module: [...this.module, ...toArray(subModule)],
34
+ context: this.context,
35
+ }, () => new Auditor_1());
36
+ }
37
+ with(context) {
38
+ return runInAuditorCreationContext({
39
+ module: this.module,
40
+ context: { ...this.context, ...context, details: { ...this.context.details, ...context.details } },
41
+ }, () => new Auditor_1());
42
+ }
43
+ withCorrelation() {
44
+ return this.with({ correlationId: this.context.correlationId ?? crypto.randomUUID() });
45
+ }
46
+ async log(action, data) {
47
+ const mergedData = { ...this.context, ...data, details: filterUndefinedFromRecord({ ...this.context.details, ...data?.details }) };
48
+ await this.#repository.insert({
49
+ timestamp: TRANSACTION_TIMESTAMP,
50
+ correlationId: mergedData.correlationId,
51
+ module: this.moduleString,
52
+ action: action,
53
+ outcome: assertDefinedPass(mergedData.outcome, 'Audit outcome is required'),
54
+ severity: assertDefinedPass(mergedData.severity, 'Audit severity is required'),
55
+ actorId: assertDefinedPass(mergedData.actorId, 'Audit actorId is required'),
56
+ actorType: assertDefinedPass(mergedData.actorType, 'Audit actorType is required'),
57
+ targetId: assertDefinedPass(mergedData.targetId, 'Audit targetId is required'),
58
+ targetType: assertDefinedPass(mergedData.targetType, 'Audit targetType is required'),
59
+ details: (objectKeys(mergedData.details).length > 0) ? mergedData.details : undefined,
60
+ });
61
+ }
62
+ async info(action, data) {
63
+ await this.log(action, {
64
+ ...data,
65
+ severity: AuditSeverity.Info,
66
+ outcome: data.outcome ?? AuditOutcome.Success,
67
+ });
68
+ }
69
+ async warn(action, data) {
70
+ await this.log(action, {
71
+ ...data,
72
+ severity: AuditSeverity.Warn,
73
+ outcome: data.outcome ?? AuditOutcome.Failure,
74
+ });
75
+ }
76
+ async error(action, data) {
77
+ await this.log(action, {
78
+ ...data,
79
+ severity: AuditSeverity.Error,
80
+ outcome: data.outcome ?? AuditOutcome.Failure,
81
+ });
82
+ }
83
+ async critical(action, data) {
84
+ await this.log(action, {
85
+ ...data,
86
+ severity: AuditSeverity.Critical,
87
+ outcome: data.outcome ?? AuditOutcome.Failure,
88
+ });
89
+ }
90
+ };
91
+ __decorate([
92
+ Memoize(),
93
+ __metadata("design:type", String),
94
+ __metadata("design:paramtypes", [])
95
+ ], Auditor.prototype, "moduleString", null);
96
+ Auditor = Auditor_1 = __decorate([
97
+ Injectable()
98
+ ], Auditor);
99
+ export { Auditor };
100
+ function moduleFromArgument(argument) {
101
+ if (isString(argument)) {
102
+ return [argument];
103
+ }
104
+ if (isArray(argument)) {
105
+ return argument;
106
+ }
107
+ if (isObject(argument)) {
108
+ return moduleFromArgument(argument.module);
109
+ }
110
+ return [];
111
+ }
@@ -0,0 +1,3 @@
1
+ export * from './auditor.js';
2
+ export * from './audit.model.js';
3
+ export * from './types.js';
package/audit/index.js ADDED
@@ -0,0 +1,3 @@
1
+ export * from './auditor.js';
2
+ export * from './audit.model.js';
3
+ export * from './types.js';
@@ -0,0 +1,22 @@
1
+ import { type EnumType } from '../enumeration/index.js';
2
+ export declare const AuditSeverity: {
3
+ readonly Info: "info";
4
+ readonly Warn: "warn";
5
+ readonly Error: "error";
6
+ readonly Critical: "critical";
7
+ };
8
+ export type AuditSeverity = EnumType<typeof AuditSeverity>;
9
+ export declare const AuditOutcome: {
10
+ readonly Pending: "pending";
11
+ readonly Success: "success";
12
+ readonly Cancelled: "cancelled";
13
+ readonly Failure: "failure";
14
+ readonly Denied: "denied";
15
+ };
16
+ export type AuditOutcome = EnumType<typeof AuditOutcome>;
17
+ export declare const ActorType: {
18
+ readonly User: "user";
19
+ readonly System: "system";
20
+ readonly ApiKey: "api-key";
21
+ };
22
+ export type ActorType = EnumType<typeof ActorType>;
package/audit/types.js ADDED
@@ -0,0 +1,19 @@
1
+ import { defineEnum } from '../enumeration/index.js';
2
+ export const AuditSeverity = defineEnum('AuditSeverity', {
3
+ Info: 'info',
4
+ Warn: 'warn',
5
+ Error: 'error',
6
+ Critical: 'critical',
7
+ });
8
+ export const AuditOutcome = defineEnum('AuditOutcome', {
9
+ Pending: 'pending',
10
+ Success: 'success',
11
+ Cancelled: 'cancelled',
12
+ Failure: 'failure',
13
+ Denied: 'denied',
14
+ });
15
+ export const ActorType = defineEnum('ActorType', {
16
+ User: 'user',
17
+ System: 'system',
18
+ ApiKey: 'api-key',
19
+ });
@@ -1,5 +1,3 @@
1
- import type { AsyncDisposable } from '../../disposable/index.js';
2
- import { disposeAsync } from '../../disposable/index.js';
3
1
  import type { AfterResolve } from '../../injector/index.js';
4
2
  import { afterResolve } from '../../injector/index.js';
5
3
  import type { Record } from '../../types/index.js';
@@ -95,7 +93,7 @@ export declare class AuthenticationClientService<AdditionalTokenPayload extends
95
93
  */
96
94
  initialize(): void;
97
95
  /** @internal */
98
- [disposeAsync](): Promise<void>;
96
+ [Symbol.asyncDispose](): Promise<void>;
99
97
  /**
100
98
  * Disposes the service.
101
99
  * Stops refresh loop and completes subjects.
@@ -9,7 +9,6 @@ var __metadata = (this && this.__metadata) || function (k, v) {
9
9
  };
10
10
  import { Subject, filter, firstValueFrom, race, timer } from 'rxjs';
11
11
  import { CancellationToken } from '../../cancellation/token.js';
12
- import { disposeAsync } from '../../disposable/index.js';
13
12
  import { BadRequestError } from '../../errors/bad-request.error.js';
14
13
  import { ForbiddenError } from '../../errors/forbidden.error.js';
15
14
  import { InvalidTokenError } from '../../errors/invalid-token.error.js';
@@ -162,7 +161,7 @@ let AuthenticationClientService = class AuthenticationClientService {
162
161
  void this.refreshLoop();
163
162
  }
164
163
  /** @internal */
165
- async [disposeAsync]() {
164
+ async [Symbol.asyncDispose]() {
166
165
  await this.dispose();
167
166
  }
168
167
  /**
@@ -254,7 +253,7 @@ let AuthenticationClientService = class AuthenticationClientService {
254
253
  if (this.impersonated()) {
255
254
  throw new Error('Already impersonating. Please unimpersonate first.');
256
255
  }
257
- await this.lock.use(lockTimeout, true, async () => {
256
+ await this.lock.use(lockTimeout, async () => {
258
257
  this.impersonatorAuthenticationData = this.authenticationData;
259
258
  this.authenticationData = data;
260
259
  try {
@@ -275,7 +274,7 @@ let AuthenticationClientService = class AuthenticationClientService {
275
274
  * @param data Additional authentication data. If not provided, the data from before impersonation is used.
276
275
  */
277
276
  async unimpersonate(data) {
278
- await this.lock.use(lockTimeout, true, async () => {
277
+ await this.lock.use(lockTimeout, async () => {
279
278
  const newData = data ?? this.impersonatorAuthenticationData;
280
279
  try {
281
280
  const token = await this.client.unimpersonate({ data: newData });
@@ -334,7 +333,7 @@ let AuthenticationClientService = class AuthenticationClientService {
334
333
  while (this.disposeToken.isUnset) {
335
334
  try {
336
335
  // Use a non-blocking lock to ensure only one tab/instance runs the refresh logic at a time.
337
- await this.lock.use(0, false, async () => await this.refreshLoopIteration());
336
+ await this.lock.tryUse(undefined, async () => await this.refreshLoopIteration());
338
337
  // Calculate delay until the next refresh check.
339
338
  // The buffer ensures we refresh *before* the token actually expires.
340
339
  const delay = ((this.token()?.exp ?? 0) - this.estimatedServerTimestampSeconds() - refreshBufferSeconds) * millisecondsPerSecond;