@tstdl/base 0.89.4 → 0.89.6

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.
@@ -7,9 +7,10 @@ import type { FunctionModuleFunction } from '../module/modules/function.module.j
7
7
  import type { OneOrMany, Type } from '../types.js';
8
8
  export type BootstrapFn = () => void | Promise<void>;
9
9
  export type RunOptions = {
10
- bootstrap?: BootstrapFn;
10
+ bootstrap?: OneOrMany<BootstrapFn>;
11
11
  };
12
- export declare class Application implements Resolvable<LoggerArgument> {
12
+ export type ApplicationArgument = LoggerArgument;
13
+ export declare class Application implements Resolvable<ApplicationArgument> {
13
14
  #private;
14
15
  static _instance: Application | undefined;
15
16
  private static get instance();
@@ -16,6 +16,7 @@ import { ModuleState } from '../module/module.js';
16
16
  import { FunctionModule } from '../module/modules/function.module.js';
17
17
  import { getShutdownSignal, getShutdownToken } from '../process-shutdown.js';
18
18
  import { DeferredPromise } from '../promise/deferred-promise.js';
19
+ import { toArray } from '../utils/array/array.js';
19
20
  import { mapAsync } from '../utils/async-iterable-helpers/map.js';
20
21
  import { toArrayAsync } from '../utils/async-iterable-helpers/to-array.js';
21
22
  import { isDefined, isFunction, isObject, isUndefined } from '../utils/type-guards.js';
@@ -68,6 +69,9 @@ let Application = class Application {
68
69
  this.registerModule(module);
69
70
  }
70
71
  run(...optionsFunctionsAndModules) {
72
+ if (this.#shutdownToken.isSet) {
73
+ throw new Error('Application was shut down.');
74
+ }
71
75
  const options = ((optionsFunctionsAndModules.length > 0) && isObject(optionsFunctionsAndModules[0])) ? optionsFunctionsAndModules[0] : undefined;
72
76
  const functionsAndModules = (isUndefined(options) ? optionsFunctionsAndModules : optionsFunctionsAndModules.slice(1));
73
77
  void this._run(functionsAndModules, options);
@@ -95,7 +99,9 @@ let Application = class Application {
95
99
  }
96
100
  }
97
101
  if (isDefined(options.bootstrap)) {
98
- await runInInjectionContext(this.#injector, options.bootstrap);
102
+ for (const fn of toArray(options.bootstrap)) {
103
+ await runInInjectionContext(this.#injector, fn);
104
+ }
99
105
  }
100
106
  const modules = await toArrayAsync(mapAsync(this.#moduleTypesAndInstances, async (instanceOrType) => (isFunction(instanceOrType) ? this.#injector.resolveAsync(instanceOrType) : instanceOrType)));
101
107
  try {
@@ -13,6 +13,6 @@ export function configureMongoKeyValueStore(keyValueRepositoryConfig, register =
13
13
  Injector.register(DEFAULT_KEY_VALUE_REPOSITORY_CONFIG, { useValue: keyValueRepositoryConfig });
14
14
  if (register) {
15
15
  Injector.registerSingleton(KeyValueStoreProvider, { useToken: MongoKeyValueStoreProvider });
16
- Injector.registerSingleton(KeyValueStore, { useToken: MongoKeyValueStore, defaultArgument: '' });
16
+ Injector.registerSingleton(KeyValueStore, { useToken: MongoKeyValueStore });
17
17
  }
18
18
  }
@@ -7,15 +7,12 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
7
7
  var __metadata = (this && this.__metadata) || function (k, v) {
8
8
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
9
9
  };
10
- var __param = (this && this.__param) || function (paramIndex, decorator) {
11
- return function (target, key) { decorator(target, key, paramIndex); }
12
- };
13
10
  import { getNewId } from '../../database/index.js';
14
- import { InjectArg, Singleton } from '../../injector/index.js';
15
- import { KeyValueStore } from '../../key-value-store/index.js';
11
+ import { Singleton } from '../../injector/index.js';
12
+ import { KeyValueStore, MongoKeyValueStoreProvider } from '../../key-value-store/index.js';
16
13
  import { currentTimestamp } from '../../utils/date-time.js';
17
14
  import { objectEntries } from '../../utils/object/object.js';
18
- import { assertStringPass, isUndefined } from '../../utils/type-guards.js';
15
+ import { assertString, isUndefined } from '../../utils/type-guards.js';
19
16
  import { MongoKeyValueRepository } from './mongo-key-value.repository.js';
20
17
  let MongoKeyValueStore = class MongoKeyValueStore extends KeyValueStore {
21
18
  keyValueRepository;
@@ -61,8 +58,15 @@ let MongoKeyValueStore = class MongoKeyValueStore extends KeyValueStore {
61
58
  }
62
59
  };
63
60
  MongoKeyValueStore = __decorate([
64
- Singleton(),
65
- __param(1, InjectArg((argument) => assertStringPass(argument, 'key-value store argument missing (module)'))),
61
+ Singleton({
62
+ provider: {
63
+ useFactory: (argument, context) => {
64
+ const provider = context.resolve(MongoKeyValueStoreProvider);
65
+ assertString(argument, 'Missing or invalid argument (KV-Store module)');
66
+ return provider.get(argument);
67
+ }
68
+ }
69
+ }),
66
70
  __metadata("design:paramtypes", [MongoKeyValueRepository, String])
67
71
  ], MongoKeyValueStore);
68
72
  export { MongoKeyValueStore };
@@ -10,7 +10,7 @@ import { inject, injectArgument } from '../../injector/inject.js';
10
10
  import { Injector } from '../../injector/injector.js';
11
11
  import { LockProvider } from '../../lock/index.js';
12
12
  import { Logger } from '../../logger/index.js';
13
- import { assertDefinedPass } from '../../utils/type-guards.js';
13
+ import { assertDefinedPass, isDefined } from '../../utils/type-guards.js';
14
14
  import { MongoLock } from './lock.js';
15
15
  import { mongoLockModuleConfig } from './module.js';
16
16
  import { MongoLockRepository } from './mongo-lock-repository.js';
@@ -18,7 +18,7 @@ let MongoLockProvider = MongoLockProvider_1 = class MongoLockProvider extends Lo
18
18
  #injector = inject(Injector);
19
19
  #lockRepository = inject(MongoLockRepository, assertDefinedPass(mongoLockModuleConfig.lockEntityRepositoryConfig, 'mongo lock module not configured'));
20
20
  #logger = inject(Logger, 'MongoLock');
21
- #prefix = injectArgument(this);
21
+ #prefix = injectArgument(this, { optional: true });
22
22
  prefix(prefix) {
23
23
  return this.#injector.resolve(MongoLockProvider_1, this.getResourceString(prefix));
24
24
  }
@@ -26,7 +26,7 @@ let MongoLockProvider = MongoLockProvider_1 = class MongoLockProvider extends Lo
26
26
  return new MongoLock(this.#lockRepository, this.getResourceString(resource), this.#logger);
27
27
  }
28
28
  getResourceString(resource) {
29
- const prefixDivider = (this.#prefix.length > 0) ? ':' : '';
29
+ const prefixDivider = (isDefined(this.#prefix) && (this.#prefix.length > 0)) ? ':' : '';
30
30
  return `${this.#prefix}${prefixDivider}${resource}`;
31
31
  }
32
32
  };
@@ -55,7 +55,9 @@ let WebServerModule = class WebServerModule extends ModuleBase {
55
55
  }
56
56
  };
57
57
  WebServerModule = __decorate([
58
- Singleton({ defaultArgumentProvider: () => webServerModuleConfiguration }),
58
+ Singleton({
59
+ defaultArgumentProvider: () => webServerModuleConfiguration
60
+ }),
59
61
  __metadata("design:paramtypes", [])
60
62
  ], WebServerModule);
61
63
  export { WebServerModule };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tstdl/base",
3
- "version": "0.89.4",
3
+ "version": "0.89.6",
4
4
  "author": "Patrick Hein",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -130,7 +130,7 @@
130
130
  "typescript": "5.2"
131
131
  },
132
132
  "peerDependencies": {
133
- "@elastic/elasticsearch": "^8.9",
133
+ "@elastic/elasticsearch": "^8.10",
134
134
  "@koa/router": "^12.0",
135
135
  "@tstdl/angular": "^0.89",
136
136
  "@zxcvbn-ts/core": "^3.0",
@@ -146,7 +146,7 @@
146
146
  "mongodb": "^6.1",
147
147
  "nodemailer": "^6.9",
148
148
  "playwright": "^1.38",
149
- "preact": "^10.17",
149
+ "preact": "^10.18",
150
150
  "preact-render-to-string": "^6.2",
151
151
  "undici": "^5.25",
152
152
  "urlpattern-polyfill": "^9.0"