@tstdl/base 0.86.0-beta5 → 0.86.0-beta7

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.
@@ -5,6 +5,10 @@ import type { Module } from '../module/module.js';
5
5
  import type { FunctionModuleFunction } from '../module/modules/function.module.js';
6
6
  import type { OneOrMany, Type } from '../types.js';
7
7
  import type { ReadonlyCancellationToken } from '../utils/cancellation-token.js';
8
+ export type BootstrapFn = () => void | Promise<void>;
9
+ export type RunOptions = {
10
+ bootstrap?: BootstrapFn;
11
+ };
8
12
  export declare class Application implements Resolvable<LoggerArgument> {
9
13
  #private;
10
14
  static _instance: Application | undefined;
@@ -14,13 +18,13 @@ export declare class Application implements Resolvable<LoggerArgument> {
14
18
  static get shutdownToken(): ReadonlyCancellationToken;
15
19
  static registerModule(moduleType: Type<Module>): void;
16
20
  static registerModuleFunction(fn: FunctionModuleFunction): void;
17
- static run(...functionsAndModules: OneOrMany<FunctionModuleFunction | Type<Module>>[]): void;
21
+ static run(...functionsAndModules: [RunOptions | OneOrMany<FunctionModuleFunction | Type<Module>>, ...OneOrMany<FunctionModuleFunction | Type<Module>>[]]): void;
18
22
  static waitForShutdown(): Promise<void>;
19
23
  static shutdown(): Promise<void>;
20
24
  static requestShutdown(): void;
21
25
  registerModule(moduleType: Module | Type<Module>): void;
22
26
  registerModuleFunction(fn: FunctionModuleFunction): void;
23
- run(...functionsAndModules: OneOrMany<FunctionModuleFunction | Type<Module>>[]): void;
27
+ run(...optionsFunctionsAndModules: [RunOptions | OneOrMany<FunctionModuleFunction | Type<Module>>, ...OneOrMany<FunctionModuleFunction | Type<Module>>[]]): void;
24
28
  shutdown(): Promise<void>;
25
29
  requestShutdown(): void;
26
30
  waitForShutdown(): Promise<void>;
@@ -95,8 +95,10 @@ let Application = class Application2 {
95
95
  const module2 = new import_function_module.FunctionModule(fn);
96
96
  this.registerModule(module2);
97
97
  }
98
- run(...functionsAndModules) {
99
- void this._run(...functionsAndModules);
98
+ run(...optionsFunctionsAndModules) {
99
+ const options = optionsFunctionsAndModules.length > 0 && (0, import_type_guards.isNotFunction)(optionsFunctionsAndModules[0]) ? optionsFunctionsAndModules[0] : void 0;
100
+ const functionsAndModules = (0, import_type_guards.isUndefined)(options) ? optionsFunctionsAndModules : optionsFunctionsAndModules.slice(1);
101
+ void this._run(functionsAndModules, options);
100
102
  }
101
103
  async shutdown() {
102
104
  this.requestShutdown();
@@ -111,7 +113,7 @@ let Application = class Application2 {
111
113
  async waitForShutdown() {
112
114
  return this.#shutdownPromise;
113
115
  }
114
- async _run(...functionsAndModules) {
116
+ async _run(functionsAndModules, options = {}) {
115
117
  for (const fnOrModule of functionsAndModules.flatMap((fns) => fns)) {
116
118
  if (fnOrModule.prototype instanceof import_module_base.ModuleBase) {
117
119
  this.registerModule(fnOrModule);
@@ -119,6 +121,9 @@ let Application = class Application2 {
119
121
  this.registerModuleFunction(fnOrModule);
120
122
  }
121
123
  }
124
+ if ((0, import_type_guards.isDefined)(options.bootstrap)) {
125
+ await (0, import_inject.runInInjectionContext)(this.#injector, options.bootstrap);
126
+ }
122
127
  const modules = await (0, import_to_array.toArrayAsync)((0, import_map.mapAsync)(this.#moduleTypesAndInstances, async (instanceOrType) => (0, import_type_guards.isFunction)(instanceOrType) ? this.#injector.resolveAsync(instanceOrType) : instanceOrType));
123
128
  try {
124
129
  await Promise.race([
@@ -27,14 +27,14 @@ export declare class Injector implements AsyncDisposable {
27
27
  * @param provider provider used to resolve the token
28
28
  * @param options registration options
29
29
  */
30
- static register<T, A = any, C extends Record = Record>(token: InjectionToken<T, A>, providers: OneOrMany<Provider<T, A, C>>, options?: RegistrationOptions<T, A>): void;
30
+ static register<T, A = any, C extends Record = Record>(token: InjectionToken<T, A>, providers: OneOrMany<Provider<T, A, C>>, options?: RegistrationOptions<T, A, C>): void;
31
31
  /**
32
32
  * Globally register a provider for a token as a singleton. Alias for {@link register} with `singleton` lifecycle
33
33
  * @param token token to register
34
34
  * @param provider provider used to resolve the token
35
35
  * @param options registration options
36
36
  */
37
- static registerSingleton<T, A = any, C extends Record = Record>(token: InjectionToken<T, A>, providers: OneOrMany<Provider<T, A, C>>, options?: TypedOmit<RegistrationOptions<T, A>, 'lifecycle'>): void;
37
+ static registerSingleton<T, A = any, C extends Record = Record>(token: InjectionToken<T, A>, providers: OneOrMany<Provider<T, A, C>>, options?: TypedOmit<RegistrationOptions<T, A, C>, 'lifecycle'>): void;
38
38
  dispose(): Promise<void>;
39
39
  [disposeAsync](): Promise<void>;
40
40
  fork(name: string): Injector;
@@ -44,14 +44,14 @@ export declare class Injector implements AsyncDisposable {
44
44
  * @param provider provider used to resolve the token
45
45
  * @param options registration options
46
46
  */
47
- register<T, A = any, C extends Record = Record>(token: InjectionToken<T, A>, providers: OneOrMany<Provider<T, A, C>>, options?: RegistrationOptions<T, A>): void;
47
+ register<T, A = any, C extends Record = Record>(token: InjectionToken<T, A>, providers: OneOrMany<Provider<T, A, C>>, options?: RegistrationOptions<T, A, C>): void;
48
48
  /**
49
49
  * Register a provider for a token as a singleton. Alias for {@link register} with `singleton` lifecycle
50
50
  * @param token token to register
51
51
  * @param provider provider used to resolve the token
52
52
  * @param options registration options
53
53
  */
54
- registerSingleton<T, A = any, C extends Record = Record>(token: InjectionToken<T, A>, providers: OneOrMany<Provider<T, A, C>>, options?: TypedOmit<RegistrationOptions<T, A>, 'lifecycle'>): void;
54
+ registerSingleton<T, A = any, C extends Record = Record>(token: InjectionToken<T, A>, providers: OneOrMany<Provider<T, A, C>>, options?: TypedOmit<RegistrationOptions<T, A, C>, 'lifecycle'>): void;
55
55
  /**
56
56
  * Check if token has a registered provider
57
57
  * @param token token check
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tstdl/base",
3
- "version": "0.86.0-beta5",
3
+ "version": "0.86.0-beta7",
4
4
  "author": "Patrick Hein",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -1,4 +1,3 @@
1
- import type { Entity } from '../../database/index.js';
2
1
  import type { ClientOptions } from '@elastic/elasticsearch';
3
2
  import type { ElasticSearchIndexConfigArgument } from './config.js';
4
3
  import { ElasticSearchIndexConfig } from './config.js';
@@ -7,6 +6,5 @@ export type ElasticsearchModuleConfig = {
7
6
  logPrefix: string;
8
7
  };
9
8
  export declare const elasticsearchModuleConfig: ElasticsearchModuleConfig;
10
- export declare const ELASTIC_SEARCH_INDEX_CONFIG: import("../../injector/token.js").InjectionToken<ElasticSearchIndexConfig<Entity>, ElasticSearchIndexConfigArgument>;
9
+ export declare const ELASTIC_SEARCH_INDEX_CONFIG: import("../../injector/token.js").InjectionToken<ElasticSearchIndexConfig<import("../../database/entity.js").Entity>, ElasticSearchIndexConfigArgument>;
11
10
  export declare function configureElasticsearch(config?: Partial<ElasticsearchModuleConfig>): void;
12
- export declare function getElasticSearchIndexConfig<T extends Entity>(indexName: string): ElasticSearchIndexConfig<T>;
@@ -20,8 +20,7 @@ var module_exports = {};
20
20
  __export(module_exports, {
21
21
  ELASTIC_SEARCH_INDEX_CONFIG: () => ELASTIC_SEARCH_INDEX_CONFIG,
22
22
  configureElasticsearch: () => configureElasticsearch,
23
- elasticsearchModuleConfig: () => elasticsearchModuleConfig,
24
- getElasticSearchIndexConfig: () => getElasticSearchIndexConfig
23
+ elasticsearchModuleConfig: () => elasticsearchModuleConfig
25
24
  });
26
25
  module.exports = __toCommonJS(module_exports);
27
26
  var import_core = require("../../core.js");
@@ -60,9 +59,6 @@ import_injector.Injector.registerSingleton(import_elasticsearch.Client, {
60
59
  import_injector.Injector.registerSingleton(ELASTIC_SEARCH_INDEX_CONFIG, {
61
60
  useFactory: (argument, context) => context.resolve(import_config.ElasticSearchIndexConfig, argument)
62
61
  });
63
- function getElasticSearchIndexConfig(indexName) {
64
- return (0, import_inject.inject)(import_config.ElasticSearchIndexConfig, indexName);
65
- }
66
62
  function getUrl(node) {
67
63
  if ((0, import_type_guards.isString)(node)) {
68
64
  return node;