@tstdl/base 0.86.0-beta6 → 0.86.0-beta8
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(...
|
|
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(...
|
|
99
|
-
|
|
98
|
+
run(...optionsFunctionsAndModules) {
|
|
99
|
+
const options = optionsFunctionsAndModules.length > 0 && (0, import_type_guards.isObject)(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(
|
|
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([
|
package/package.json
CHANGED
|
@@ -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;
|