@tstdl/base 0.86.0-beta11 → 0.86.0-beta3

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,10 +5,6 @@ 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
- };
12
8
  export declare class Application implements Resolvable<LoggerArgument> {
13
9
  #private;
14
10
  static _instance: Application | undefined;
@@ -18,13 +14,13 @@ export declare class Application implements Resolvable<LoggerArgument> {
18
14
  static get shutdownToken(): ReadonlyCancellationToken;
19
15
  static registerModule(moduleType: Type<Module>): void;
20
16
  static registerModuleFunction(fn: FunctionModuleFunction): void;
21
- static run(...functionsAndModules: [RunOptions | OneOrMany<FunctionModuleFunction | Type<Module>>, ...OneOrMany<FunctionModuleFunction | Type<Module>>[]]): void;
17
+ static run(...functionsAndModules: OneOrMany<FunctionModuleFunction | Type<Module>>[]): void;
22
18
  static waitForShutdown(): Promise<void>;
23
19
  static shutdown(): Promise<void>;
24
20
  static requestShutdown(): void;
25
21
  registerModule(moduleType: Module | Type<Module>): void;
26
22
  registerModuleFunction(fn: FunctionModuleFunction): void;
27
- run(...optionsFunctionsAndModules: [RunOptions | OneOrMany<FunctionModuleFunction | Type<Module>>, ...OneOrMany<FunctionModuleFunction | Type<Module>>[]]): void;
23
+ run(...functionsAndModules: OneOrMany<FunctionModuleFunction | Type<Module>>[]): void;
28
24
  shutdown(): Promise<void>;
29
25
  requestShutdown(): void;
30
26
  waitForShutdown(): Promise<void>;
@@ -95,10 +95,8 @@ let Application = class Application2 {
95
95
  const module2 = new import_function_module.FunctionModule(fn);
96
96
  this.registerModule(module2);
97
97
  }
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);
98
+ run(...functionsAndModules) {
99
+ void this._run(...functionsAndModules);
102
100
  }
103
101
  async shutdown() {
104
102
  this.requestShutdown();
@@ -113,7 +111,7 @@ let Application = class Application2 {
113
111
  async waitForShutdown() {
114
112
  return this.#shutdownPromise;
115
113
  }
116
- async _run(functionsAndModules, options = {}) {
114
+ async _run(...functionsAndModules) {
117
115
  for (const fnOrModule of functionsAndModules.flatMap((fns) => fns)) {
118
116
  if (fnOrModule.prototype instanceof import_module_base.ModuleBase) {
119
117
  this.registerModule(fnOrModule);
@@ -121,9 +119,6 @@ let Application = class Application2 {
121
119
  this.registerModuleFunction(fnOrModule);
122
120
  }
123
121
  }
124
- if ((0, import_type_guards.isDefined)(options.bootstrap)) {
125
- await (0, import_inject.runInInjectionContext)(this.#injector, options.bootstrap);
126
- }
127
122
  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));
128
123
  try {
129
124
  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, C>): 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>): 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, C>, '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>, '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, C>): void;
47
+ register<T, A = any, C extends Record = Record>(token: InjectionToken<T, A>, providers: OneOrMany<Provider<T, A, C>>, options?: RegistrationOptions<T, A>): 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, C>, '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>, 'lifecycle'>): void;
55
55
  /**
56
56
  * Check if token has a registered provider
57
57
  * @param token token check
@@ -237,7 +237,7 @@ class Injector {
237
237
  return registration.resolutions.get(argumentIdentity);
238
238
  }
239
239
  const value = this._resolveProvider(resolutionTag, registration, resolveArgument, options, context, injectionContext, chain);
240
- const resolution = { tag: resolutionTag, registration, value, argument: injectionContext.argument, chain };
240
+ const resolution = { tag: resolutionTag, registration, value, argument, chain };
241
241
  context.resolutions.push(resolution);
242
242
  if (resolutionScoped) {
243
243
  context.resolutionScopedResolutions.setFlat(token, argumentIdentity, resolution);
@@ -478,7 +478,7 @@ function throwOnPromise(value, type, chain) {
478
478
  }
479
479
  }
480
480
  function checkOverflow(chain, context) {
481
- if (chain.length > 100 || ++context.resolves > 7500) {
481
+ if (chain.length > 750 || ++context.resolves > 750) {
482
482
  throw new import_resolve_error.ResolveError("Resolve stack overflow. This can happen on circular dependencies with transient lifecycles and self reference. Use scoped or singleton lifecycle or forwardRef instead.", chain);
483
483
  }
484
484
  }
@@ -24,6 +24,7 @@ __export(web_server_module_exports, {
24
24
  });
25
25
  module.exports = __toCommonJS(web_server_module_exports);
26
26
  var import_server = require("../../api/server/index.js");
27
+ var import_log = require("../../decorators/log.js");
27
28
  var import_disposable = require("../../disposable/disposable.js");
28
29
  var import_http_server = require("../../http/server/http-server.js");
29
30
  var import_decorators = require("../../injector/decorators.js");
@@ -86,6 +87,7 @@ let WebServerModule = class WebServerModule2 extends import_module_base.ModuleBa
86
87
  };
87
88
  WebServerModule = __decorate([
88
89
  (0, import_decorators.Singleton)({ defaultArgumentProvider: () => webServerModuleConfiguration }),
90
+ (0, import_log.Log)(),
89
91
  __metadata("design:paramtypes", [])
90
92
  ], WebServerModule);
91
93
  function configureWebServerModule(config) {
@@ -4,5 +4,5 @@ export declare abstract class ObjectStorageProvider<T extends ObjectStorage = Ob
4
4
  * get an object storage instance
5
5
  * @param module name for object container (module) to store objects in. Can be used to isolate objects like profile pictures and log files
6
6
  */
7
- abstract get(module: string): T;
7
+ abstract get(module: string): T | Promise<T>;
8
8
  }
@@ -17,6 +17,10 @@ export declare class S3ObjectStorageProviderConfig {
17
17
  * mutually exclusive with bucket
18
18
  */
19
19
  bucketPerModule?: boolean;
20
+ /**
21
+ * create bucket for requested storage module if it does not exist
22
+ */
23
+ autoCreateBucket?: boolean;
20
24
  /**
21
25
  * s3 access key
22
26
  */
@@ -30,8 +34,9 @@ export declare const bucketPerModule: unique symbol;
30
34
  export declare class S3ObjectStorageProvider extends ObjectStorageProvider<S3ObjectStorage> {
31
35
  private readonly client;
32
36
  private readonly bucket;
37
+ private readonly createBucket;
33
38
  constructor(config: S3ObjectStorageProviderConfig);
34
- get(module: string): S3ObjectStorage;
39
+ get(module: string): Promise<S3ObjectStorage>;
35
40
  }
36
41
  /**
37
42
  * configure s3 object storage provider
@@ -61,6 +61,10 @@ class S3ObjectStorageProviderConfig {
61
61
  * mutually exclusive with bucket
62
62
  */
63
63
  bucketPerModule;
64
+ /**
65
+ * create bucket for requested storage module if it does not exist
66
+ */
67
+ autoCreateBucket;
64
68
  /**
65
69
  * s3 access key
66
70
  */
@@ -74,12 +78,14 @@ const bucketPerModule = Symbol("bucket per module");
74
78
  let S3ObjectStorageProvider = class S3ObjectStorageProvider2 extends import_object_storage.ObjectStorageProvider {
75
79
  client;
76
80
  bucket;
81
+ createBucket;
77
82
  constructor(config) {
78
83
  super();
79
84
  const { hostname, port, protocol } = new URL(config.endpoint);
80
85
  if ((0, import_type_guards.isDefined)(config.bucket) && config.bucketPerModule == true) {
81
86
  throw new Error("bucket and bucketPerModule is mutually exclusive");
82
87
  }
88
+ this.createBucket = config.autoCreateBucket ?? false;
83
89
  this.client = new import_minio.Client({
84
90
  endPoint: hostname,
85
91
  port: port.length > 0 ? parseInt(port, 10) : void 0,
@@ -89,10 +95,14 @@ let S3ObjectStorageProvider = class S3ObjectStorageProvider2 extends import_obje
89
95
  });
90
96
  this.bucket = (0, import_type_guards.assertDefinedPass)(config.bucketPerModule == true ? true : config.bucket, "either bucket or bucketPerModule must be specified");
91
97
  }
92
- get(module2) {
98
+ async get(module2) {
93
99
  const bucket = this.bucket == true ? module2 : (0, import_type_guards.assertStringPass)(this.bucket);
94
100
  const prefix = this.bucket == true ? "" : module2 == "" ? "" : `${module2}/`;
95
- return new import_s3_object_storage.S3ObjectStorage(this.client, bucket, module2, prefix);
101
+ const objectStorage = new import_s3_object_storage.S3ObjectStorage(this.client, bucket, module2, prefix);
102
+ if (this.createBucket) {
103
+ await objectStorage.ensureBucketExists();
104
+ }
105
+ return objectStorage;
96
106
  }
97
107
  };
98
108
  S3ObjectStorageProvider = __decorate([
@@ -152,10 +152,7 @@ let S3ObjectStorage = class S3ObjectStorage2 extends import_object_storage.Objec
152
152
  S3ObjectStorage = __decorate([
153
153
  (0, import_decorators.Singleton)({
154
154
  provider: {
155
- useFactory: (argument, context) => context.resolve(import_s3_object_storage_provider.S3ObjectStorageProvider).get((0, import_type_guards.assertStringPass)(argument, "resolve argument must be a string (object storage module)")),
156
- async afterResolve(value) {
157
- await value.ensureBucketExists();
158
- }
155
+ useFactory: async (argument, context) => context.resolve(import_s3_object_storage_provider.S3ObjectStorageProvider).get((0, import_type_guards.assertStringPass)(argument, "resolve argument must be a string (object storage module)"))
159
156
  }
160
157
  }),
161
158
  __metadata("design:paramtypes", [import_minio.Client, String, String, String])
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tstdl/base",
3
- "version": "0.86.0-beta11",
3
+ "version": "0.86.0-beta3",
4
4
  "author": "Patrick Hein",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -47,7 +47,7 @@
47
47
  "peerDependencies": {
48
48
  "@elastic/elasticsearch": "^8.9",
49
49
  "@koa/router": "^12.0",
50
- "@tstdl/angular": "^0.85",
50
+ "@tstdl/angular": "^0.86-beta1",
51
51
  "@zxcvbn-ts/core": "^3.0",
52
52
  "@zxcvbn-ts/language-common": "^3.0",
53
53
  "@zxcvbn-ts/language-de": "^3.0",
@@ -1,3 +1,4 @@
1
+ import type { Entity } from '../../database/index.js';
1
2
  import type { ClientOptions } from '@elastic/elasticsearch';
2
3
  import type { ElasticSearchIndexConfigArgument } from './config.js';
3
4
  import { ElasticSearchIndexConfig } from './config.js';
@@ -6,5 +7,6 @@ export type ElasticsearchModuleConfig = {
6
7
  logPrefix: string;
7
8
  };
8
9
  export declare const elasticsearchModuleConfig: ElasticsearchModuleConfig;
9
- export declare const ELASTIC_SEARCH_INDEX_CONFIG: import("../../injector/token.js").InjectionToken<ElasticSearchIndexConfig<import("../../database/entity.js").Entity>, ElasticSearchIndexConfigArgument>;
10
+ export declare const ELASTIC_SEARCH_INDEX_CONFIG: import("../../injector/token.js").InjectionToken<ElasticSearchIndexConfig<Entity>, ElasticSearchIndexConfigArgument>;
10
11
  export declare function configureElasticsearch(config?: Partial<ElasticsearchModuleConfig>): void;
12
+ export declare function getElasticSearchIndexConfig<T extends Entity>(indexName: string): ElasticSearchIndexConfig<T>;
@@ -20,7 +20,8 @@ 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
23
+ elasticsearchModuleConfig: () => elasticsearchModuleConfig,
24
+ getElasticSearchIndexConfig: () => getElasticSearchIndexConfig
24
25
  });
25
26
  module.exports = __toCommonJS(module_exports);
26
27
  var import_core = require("../../core.js");
@@ -59,6 +60,9 @@ import_injector.Injector.registerSingleton(import_elasticsearch.Client, {
59
60
  import_injector.Injector.registerSingleton(ELASTIC_SEARCH_INDEX_CONFIG, {
60
61
  useFactory: (argument, context) => context.resolve(import_config.ElasticSearchIndexConfig, argument)
61
62
  });
63
+ function getElasticSearchIndexConfig(indexName) {
64
+ return (0, import_inject.inject)(import_config.ElasticSearchIndexConfig, indexName);
65
+ }
62
66
  function getUrl(node) {
63
67
  if ((0, import_type_guards.isString)(node)) {
64
68
  return node;
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes