@tstdl/base 0.86.0-beta9 → 0.86.1

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 (55) hide show
  1. package/application/application.js +0 -1
  2. package/browser/browser-context-controller.d.ts +2 -2
  3. package/browser/browser-context-controller.js +6 -7
  4. package/browser/browser-controller.js +6 -7
  5. package/core.d.ts +2 -4
  6. package/core.js +2 -9
  7. package/database/mongo/module.js +8 -8
  8. package/disposable/async-disposer.d.ts +8 -7
  9. package/disposable/async-disposer.js +49 -23
  10. package/disposable/disposable.d.ts +5 -4
  11. package/disposable/disposable.js +9 -5
  12. package/injector/injector.d.ts +5 -2
  13. package/injector/injector.js +59 -23
  14. package/injector/interfaces.d.ts +4 -3
  15. package/injector/provider.d.ts +12 -12
  16. package/injector/resolve.error.d.ts +1 -1
  17. package/injector/types.d.ts +16 -7
  18. package/logger/console/logger.js +2 -2
  19. package/module/modules/web-server.module.js +0 -2
  20. package/object-storage/object-storage-provider.d.ts +1 -1
  21. package/object-storage/s3/s3.object-storage-provider.d.ts +1 -6
  22. package/object-storage/s3/s3.object-storage-provider.js +2 -12
  23. package/object-storage/s3/s3.object-storage.js +4 -1
  24. package/package.json +7 -6
  25. package/polyfills.d.ts +159 -0
  26. package/polyfills.js +2 -0
  27. package/queue/mongo/mongo-job.repository.js +3 -4
  28. package/search-index/elastic/module.js +4 -4
  29. package/tsconfig.json +1 -1
  30. package/utils/cancellation-token.d.ts +19 -17
  31. package/utils/cancellation-token.js +20 -19
  32. package/_container/container.d.ts +0 -99
  33. package/_container/container.js +0 -443
  34. package/_container/decorators.d.ts +0 -76
  35. package/_container/decorators.js +0 -110
  36. package/_container/index.d.ts +0 -10
  37. package/_container/index.js +0 -27
  38. package/_container/interfaces.d.ts +0 -16
  39. package/_container/interfaces.js +0 -26
  40. package/_container/provider.d.ts +0 -35
  41. package/_container/provider.js +0 -60
  42. package/_container/resolve-chain.d.ts +0 -27
  43. package/_container/resolve-chain.js +0 -105
  44. package/_container/resolve.error.d.ts +0 -5
  45. package/_container/resolve.error.js +0 -36
  46. package/_container/token.d.ts +0 -18
  47. package/_container/token.js +0 -41
  48. package/_container/type-info.d.ts +0 -18
  49. package/_container/type-info.js +0 -16
  50. package/_container/types.d.ts +0 -9
  51. package/_container/types.js +0 -16
  52. package/_container/utils.d.ts +0 -3
  53. package/_container/utils.js +0 -44
  54. package/global-this.d.ts +0 -1
  55. package/global-this.js +0 -37
@@ -1,23 +1,23 @@
1
1
  import type { Constructor, Record, TypedOmit } from '../types.js';
2
2
  import type { ResolveArgument } from './interfaces.js';
3
3
  import type { InjectionToken } from './token.js';
4
- import type { ResolveContext } from './types.js';
5
- export type Factory<T, A = any, C extends Record = Record> = (argument: ResolveArgument<T, A>, context: ResolveContext<C>) => T;
4
+ import type { AfterResolveContext, ResolveContext } from './types.js';
5
+ export type Factory<T, A = any, D extends Record = Record> = (argument: ResolveArgument<T, A>, context: ResolveContext<D>) => T;
6
6
  export type ProviderWithArgument<T, A> = {
7
7
  defaultArgument?: ResolveArgument<T, A>;
8
8
  defaultArgumentProvider?: () => ResolveArgument<T, A>;
9
9
  };
10
- export type ProviderWithInitializer<T, A, C extends Record> = {
11
- afterResolve?: (value: T, argument: A, context: C) => void | Promise<void>;
10
+ export type ProviderWithInitializer<T, A, D extends Record> = {
11
+ afterResolve?: (value: T, argument: A, context: AfterResolveContext<D>) => void | Promise<void>;
12
12
  };
13
- export type Provider<T = any, A = any, C extends Record = Record> = ClassProvider<T, A, C> | ValueProvider<T> | TokenProvider<T, A, C> | FactoryProvider<T, A, C>;
14
- export type ClassProvider<T = any, A = any, C extends Record = Record> = ProviderWithArgument<T, A> & ProviderWithInitializer<T, A, C> & {
13
+ export type Provider<T = any, A = any, D extends Record = Record> = ClassProvider<T, A, D> | ValueProvider<T> | TokenProvider<T, A, D> | FactoryProvider<T, A, D>;
14
+ export type ClassProvider<T = any, A = any, D extends Record = Record> = ProviderWithArgument<T, A> & ProviderWithInitializer<T, A, D> & {
15
15
  useClass: Constructor<T>;
16
16
  };
17
17
  export type ValueProvider<T = any> = {
18
18
  useValue: T;
19
19
  };
20
- export type TokenProvider<T = any, A = any, C extends Record = Record> = ProviderWithArgument<T, A> & ProviderWithInitializer<T, A, C> & ({
20
+ export type TokenProvider<T = any, A = any, D extends Record = Record> = ProviderWithArgument<T, A> & ProviderWithInitializer<T, A, D> & ({
21
21
  useToken: InjectionToken<T, A>;
22
22
  useTokenProvider?: undefined;
23
23
  } | {
@@ -29,13 +29,13 @@ export type TokenProvider<T = any, A = any, C extends Record = Record> = Provide
29
29
  */
30
30
  resolveAll?: boolean;
31
31
  };
32
- export type FactoryProvider<T = any, A = unknown, C extends Record = Record> = ProviderWithArgument<T, A> & ProviderWithInitializer<T, A, C> & {
33
- useFactory: Factory<T, A, C>;
32
+ export type FactoryProvider<T = any, A = unknown, D extends Record = Record> = ProviderWithArgument<T, A> & ProviderWithInitializer<T, A, D> & {
33
+ useFactory: Factory<T, A, D>;
34
34
  };
35
- export declare function classProvider<T, A, C extends Record>(constructor: Constructor<T>, options?: TypedOmit<ClassProvider<T, A, C>, 'useClass'>): ClassProvider<T, A, C>;
35
+ export declare function classProvider<T, A, D extends Record>(constructor: Constructor<T>, options?: TypedOmit<ClassProvider<T, A, D>, 'useClass'>): ClassProvider<T, A, D>;
36
36
  export declare function valueProvider<T>(value: T, options?: TypedOmit<ValueProvider<T>, 'useValue'>): ValueProvider<T>;
37
- export declare function tokenProvider<T, A, C extends Record>(token: InjectionToken<T, A>, options?: TypedOmit<TokenProvider<T, A, C>, 'useToken' | 'useTokenProvider'>): TokenProvider<T>;
38
- export declare function factoryProvider<T, A, C extends Record>(factory: Factory<T, A, C>, options?: TypedOmit<FactoryProvider<T, A, C>, 'useFactory'>): FactoryProvider<T, A, C>;
37
+ export declare function tokenProvider<T, A, D extends Record>(token: InjectionToken<T, A>, options?: TypedOmit<TokenProvider<T, A, D>, 'useToken' | 'useTokenProvider'>): TokenProvider<T>;
38
+ export declare function factoryProvider<T, A, D extends Record>(factory: Factory<T, A, D>, options?: TypedOmit<FactoryProvider<T, A, D>, 'useFactory'>): FactoryProvider<T, A, D>;
39
39
  export declare function isClassProvider<T, A>(value: Provider<T, A>): value is ClassProvider<T, A>;
40
40
  export declare function isClassProvider<T, A>(value: unknown): value is ClassProvider<T, A>;
41
41
  export declare function isValueProvider<T>(value: Provider<T>): value is ValueProvider<T>;
@@ -1,5 +1,5 @@
1
1
  import { CustomError } from '../error/custom.error.js';
2
- import { ResolveChain } from './resolve-chain.js';
2
+ import type { ResolveChain } from './resolve-chain.js';
3
3
  export declare class ResolveError extends CustomError {
4
4
  constructor(message: string, chain: ResolveChain, cause?: Error);
5
5
  }
@@ -1,5 +1,6 @@
1
1
  import type { AsyncDisposeHandler } from '../disposable/async-disposer.js';
2
2
  import type { Record } from '../types.js';
3
+ import type { ReadonlyCancellationToken } from '../utils/cancellation-token.js';
3
4
  import type { Injector } from './injector.js';
4
5
  import type { ResolveArgument } from './interfaces.js';
5
6
  import type { InjectionToken } from './token.js';
@@ -10,12 +11,18 @@ import type { InjectionToken } from './token.js';
10
11
  * singleton: one resolution at injector where token is registered
11
12
  */
12
13
  export type Lifecycle = 'transient' | 'resolution' | 'injector' | 'singleton';
13
- export type ResolveContext<C extends Record> = Pick<Injector, 'resolve' | 'resolveAll'> & {
14
- context: ResolutionContext<C>;
14
+ export type ResolveContext<D extends Record> = Pick<Injector, 'resolve' | 'resolveAll'> & {
15
+ readonly data: ResolveContextData<D>;
16
+ readonly cancellationToken: ReadonlyCancellationToken;
17
+ addDisposeHandler(handler: AsyncDisposeHandler): void;
18
+ };
19
+ export type AfterResolveContext<D extends Record> = {
20
+ readonly data: ResolveContextData<D>;
21
+ readonly cancellationToken: ReadonlyCancellationToken;
15
22
  addDisposeHandler(handler: AsyncDisposeHandler): void;
16
23
  };
17
24
  export type Mapper<T = any, U = unknown> = (value: T) => U;
18
- export type ArgumentProvider<T = unknown, C extends Record = Record> = (context: ResolveContext<C>) => T;
25
+ export type ArgumentProvider<T = unknown, D extends Record = Record> = (context: ResolveContext<D>) => T;
19
26
  export type ForwardRefInjectionToken<T = any, A = any> = Exclude<InjectionToken<T, A>, Function> | (() => InjectionToken<T, A>);
20
27
  export type ResolveOptions = {
21
28
  optional?: boolean;
@@ -25,13 +32,13 @@ export type ResolveOptions = {
25
32
  /**
26
33
  * data to store between different stages like resolve and afterResolve
27
34
  */
28
- export type ResolutionContext<T extends Record> = T;
29
- export type RegistrationOptions<T, A = unknown, C extends Record = Record> = {
35
+ export type ResolveContextData<T extends Record> = T;
36
+ export type RegistrationOptions<T, A = unknown, D extends Record = Record> = {
30
37
  lifecycle?: Lifecycle;
31
38
  /** Default resolve argument used when neither token nor explicit resolve argument is provided */
32
39
  defaultArgument?: ResolveArgument<T, A>;
33
40
  /** Default resolve argument used when neither token nor explicit resolve argument is provided */
34
- defaultArgumentProvider?: ArgumentProvider<ResolveArgument<T, A>, C>;
41
+ defaultArgumentProvider?: ArgumentProvider<ResolveArgument<T, A>, D>;
35
42
  /**
36
43
  * Value to distinguish scoped and singleton instances based on argument
37
44
  * by default it uses strict equality (===) on the original argument,
@@ -43,7 +50,9 @@ export type RegistrationOptions<T, A = unknown, C extends Record = Record> = {
43
50
  */
44
51
  argumentIdentityProvider?: Mapper<ResolveArgument<T, A>>;
45
52
  /** Function which gets called after a resolve */
46
- afterResolve?: (instance: T, argument: ResolveArgument<T, A>, context: ResolutionContext<C>) => any;
53
+ afterResolve?: (instance: T, argument: ResolveArgument<T, A>, context: AfterResolveContext<D>) => any;
47
54
  /** Whether multiple values can be resolved or not (used with {@link Injector.resolveAll}). If false, previous registrations are removed */
48
55
  multi?: boolean;
56
+ /** custom metadata */
57
+ metadata?: Record;
49
58
  };
@@ -79,9 +79,9 @@ ConsoleLogger = ConsoleLogger_1 = __decorate([
79
79
  provider: {
80
80
  useFactory: (argument, context) => {
81
81
  if ((0, import_type_guards.isObject)(argument)) {
82
- return new ConsoleLogger_1(argument.level ?? context.resolve(import_level.LogLevel), argument.module, argument.prefix);
82
+ return new ConsoleLogger(argument.level ?? context.resolve(import_level.LogLevel), argument.module, argument.prefix);
83
83
  }
84
- return new ConsoleLogger_1(context.resolve(import_level.LogLevel), argument, void 0);
84
+ return new ConsoleLogger(context.resolve(import_level.LogLevel), argument, void 0);
85
85
  }
86
86
  }
87
87
  }),
@@ -24,7 +24,6 @@ __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");
28
27
  var import_disposable = require("../../disposable/disposable.js");
29
28
  var import_http_server = require("../../http/server/http-server.js");
30
29
  var import_decorators = require("../../injector/decorators.js");
@@ -87,7 +86,6 @@ let WebServerModule = class WebServerModule2 extends import_module_base.ModuleBa
87
86
  };
88
87
  WebServerModule = __decorate([
89
88
  (0, import_decorators.Singleton)({ defaultArgumentProvider: () => webServerModuleConfiguration }),
90
- (0, import_log.Log)(),
91
89
  __metadata("design:paramtypes", [])
92
90
  ], WebServerModule);
93
91
  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 | Promise<T>;
7
+ abstract get(module: string): T;
8
8
  }
@@ -17,10 +17,6 @@ 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;
24
20
  /**
25
21
  * s3 access key
26
22
  */
@@ -34,9 +30,8 @@ export declare const bucketPerModule: unique symbol;
34
30
  export declare class S3ObjectStorageProvider extends ObjectStorageProvider<S3ObjectStorage> {
35
31
  private readonly client;
36
32
  private readonly bucket;
37
- private readonly createBucket;
38
33
  constructor(config: S3ObjectStorageProviderConfig);
39
- get(module: string): Promise<S3ObjectStorage>;
34
+ get(module: string): S3ObjectStorage;
40
35
  }
41
36
  /**
42
37
  * configure s3 object storage provider
@@ -61,10 +61,6 @@ 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;
68
64
  /**
69
65
  * s3 access key
70
66
  */
@@ -78,14 +74,12 @@ const bucketPerModule = Symbol("bucket per module");
78
74
  let S3ObjectStorageProvider = class S3ObjectStorageProvider2 extends import_object_storage.ObjectStorageProvider {
79
75
  client;
80
76
  bucket;
81
- createBucket;
82
77
  constructor(config) {
83
78
  super();
84
79
  const { hostname, port, protocol } = new URL(config.endpoint);
85
80
  if ((0, import_type_guards.isDefined)(config.bucket) && config.bucketPerModule == true) {
86
81
  throw new Error("bucket and bucketPerModule is mutually exclusive");
87
82
  }
88
- this.createBucket = config.autoCreateBucket ?? false;
89
83
  this.client = new import_minio.Client({
90
84
  endPoint: hostname,
91
85
  port: port.length > 0 ? parseInt(port, 10) : void 0,
@@ -95,14 +89,10 @@ let S3ObjectStorageProvider = class S3ObjectStorageProvider2 extends import_obje
95
89
  });
96
90
  this.bucket = (0, import_type_guards.assertDefinedPass)(config.bucketPerModule == true ? true : config.bucket, "either bucket or bucketPerModule must be specified");
97
91
  }
98
- async get(module2) {
92
+ get(module2) {
99
93
  const bucket = this.bucket == true ? module2 : (0, import_type_guards.assertStringPass)(this.bucket);
100
94
  const prefix = this.bucket == true ? "" : module2 == "" ? "" : `${module2}/`;
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;
95
+ return new import_s3_object_storage.S3ObjectStorage(this.client, bucket, module2, prefix);
106
96
  }
107
97
  };
108
98
  S3ObjectStorageProvider = __decorate([
@@ -152,7 +152,10 @@ let S3ObjectStorage = class S3ObjectStorage2 extends import_object_storage.Objec
152
152
  S3ObjectStorage = __decorate([
153
153
  (0, import_decorators.Singleton)({
154
154
  provider: {
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)"))
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
+ }
156
159
  }
157
160
  }),
158
161
  __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-beta9",
3
+ "version": "0.86.1",
4
4
  "author": "Patrick Hein",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -20,10 +20,11 @@
20
20
  "tsc-alias:watch": "tsc-alias --watch"
21
21
  },
22
22
  "dependencies": {
23
+ "disposablestack": "^1.1.1",
23
24
  "luxon": "^3.4",
24
25
  "reflect-metadata": "^0.1",
25
26
  "rxjs": "^7.8",
26
- "type-fest": "^4.2"
27
+ "type-fest": "^4.3"
27
28
  },
28
29
  "devDependencies": {
29
30
  "@types/chroma-js": "2.4",
@@ -37,17 +38,17 @@
37
38
  "@typescript-eslint/parser": "6.4",
38
39
  "concurrently": "8.2",
39
40
  "esbuild": "0.19",
40
- "eslint": "8.47",
41
+ "eslint": "8.48",
41
42
  "eslint-import-resolver-typescript": "3.6",
42
43
  "eslint-plugin-import": "2.28",
43
44
  "tsc-alias": "1.8",
44
- "typedoc": "0.24",
45
- "typescript": "5.1"
45
+ "typedoc": "0.25",
46
+ "typescript": "5.2"
46
47
  },
47
48
  "peerDependencies": {
48
49
  "@elastic/elasticsearch": "^8.9",
49
50
  "@koa/router": "^12.0",
50
- "@tstdl/angular": "^0.85",
51
+ "@tstdl/angular": "^0.86",
51
52
  "@zxcvbn-ts/core": "^3.0",
52
53
  "@zxcvbn-ts/language-common": "^3.0",
53
54
  "@zxcvbn-ts/language-de": "^3.0",
package/polyfills.d.ts ADDED
@@ -0,0 +1,159 @@
1
+ import 'disposablestack/auto';
2
+ declare global {
3
+ interface SymbolConstructor {
4
+ /**
5
+ * A method that is used to release resources held by an object. Called by the semantics of the `using` statement.
6
+ */
7
+ readonly dispose: unique symbol;
8
+ /**
9
+ * A method that is used to asynchronously release resources held by an object. Called by the semantics of the `await using` statement.
10
+ */
11
+ readonly asyncDispose: unique symbol;
12
+ }
13
+ interface Disposable {
14
+ [Symbol.dispose](): void;
15
+ }
16
+ interface AsyncDisposable {
17
+ [Symbol.asyncDispose](): PromiseLike<void>;
18
+ }
19
+ interface SuppressedError extends Error {
20
+ error: any;
21
+ suppressed: any;
22
+ }
23
+ interface SuppressedErrorConstructor extends ErrorConstructor {
24
+ new (error: any, suppressed: any, message?: string): SuppressedError;
25
+ (error: any, suppressed: any, message?: string): SuppressedError;
26
+ readonly prototype: SuppressedError;
27
+ }
28
+ var SuppressedError: SuppressedErrorConstructor;
29
+ interface DisposableStack {
30
+ /**
31
+ * Returns a value indicating whether this stack has been disposed.
32
+ */
33
+ readonly disposed: boolean;
34
+ /**
35
+ * Disposes each resource in the stack in the reverse order that they were added.
36
+ */
37
+ dispose(): void;
38
+ /**
39
+ * Adds a disposable resource to the stack, returning the resource.
40
+ * @param value The resource to add. `null` and `undefined` will not be added, but will be returned.
41
+ * @returns The provided {@link value}.
42
+ */
43
+ use<T extends Disposable | null | undefined>(value: T): T;
44
+ /**
45
+ * Adds a value and associated disposal callback as a resource to the stack.
46
+ * @param value The value to add.
47
+ * @param onDispose The callback to use in place of a `[Symbol.dispose]()` method. Will be invoked with `value`
48
+ * as the first parameter.
49
+ * @returns The provided {@link value}.
50
+ */
51
+ adopt<T>(value: T, onDispose: (value: T) => void): T;
52
+ /**
53
+ * Adds a callback to be invoked when the stack is disposed.
54
+ */
55
+ defer(onDispose: () => void): void;
56
+ /**
57
+ * Move all resources out of this stack and into a new `DisposableStack`, and marks this stack as disposed.
58
+ * @example
59
+ * ```ts
60
+ * class C {
61
+ * #res1: Disposable;
62
+ * #res2: Disposable;
63
+ * #disposables: DisposableStack;
64
+ * constructor() {
65
+ * // stack will be disposed when exiting constructor for any reason
66
+ * using stack = new DisposableStack();
67
+ *
68
+ * // get first resource
69
+ * this.#res1 = stack.use(getResource1());
70
+ *
71
+ * // get second resource. If this fails, both `stack` and `#res1` will be disposed.
72
+ * this.#res2 = stack.use(getResource2());
73
+ *
74
+ * // all operations succeeded, move resources out of `stack` so that they aren't disposed
75
+ * // when constructor exits
76
+ * this.#disposables = stack.move();
77
+ * }
78
+ *
79
+ * [Symbol.dispose]() {
80
+ * this.#disposables.dispose();
81
+ * }
82
+ * }
83
+ * ```
84
+ */
85
+ move(): DisposableStack;
86
+ [Symbol.dispose](): void;
87
+ readonly [Symbol.toStringTag]: string;
88
+ }
89
+ interface DisposableStackConstructor {
90
+ new (): DisposableStack;
91
+ readonly prototype: DisposableStack;
92
+ }
93
+ var DisposableStack: DisposableStackConstructor;
94
+ interface AsyncDisposableStack {
95
+ /**
96
+ * Returns a value indicating whether this stack has been disposed.
97
+ */
98
+ readonly disposed: boolean;
99
+ /**
100
+ * Disposes each resource in the stack in the reverse order that they were added.
101
+ */
102
+ disposeAsync(): Promise<void>;
103
+ /**
104
+ * Adds a disposable resource to the stack, returning the resource.
105
+ * @param value The resource to add. `null` and `undefined` will not be added, but will be returned.
106
+ * @returns The provided {@link value}.
107
+ */
108
+ use<T extends AsyncDisposable | Disposable | null | undefined>(value: T): T;
109
+ /**
110
+ * Adds a value and associated disposal callback as a resource to the stack.
111
+ * @param value The value to add.
112
+ * @param onDisposeAsync The callback to use in place of a `[Symbol.asyncDispose]()` method. Will be invoked with `value`
113
+ * as the first parameter.
114
+ * @returns The provided {@link value}.
115
+ */
116
+ adopt<T>(value: T, onDisposeAsync: (value: T) => PromiseLike<void> | void): T;
117
+ /**
118
+ * Adds a callback to be invoked when the stack is disposed.
119
+ */
120
+ defer(onDisposeAsync: () => PromiseLike<void> | void): void;
121
+ /**
122
+ * Move all resources out of this stack and into a new `DisposableStack`, and marks this stack as disposed.
123
+ * @example
124
+ * ```ts
125
+ * class C {
126
+ * #res1: Disposable;
127
+ * #res2: Disposable;
128
+ * #disposables: DisposableStack;
129
+ * constructor() {
130
+ * // stack will be disposed when exiting constructor for any reason
131
+ * using stack = new DisposableStack();
132
+ *
133
+ * // get first resource
134
+ * this.#res1 = stack.use(getResource1());
135
+ *
136
+ * // get second resource. If this fails, both `stack` and `#res1` will be disposed.
137
+ * this.#res2 = stack.use(getResource2());
138
+ *
139
+ * // all operations succeeded, move resources out of `stack` so that they aren't disposed
140
+ * // when constructor exits
141
+ * this.#disposables = stack.move();
142
+ * }
143
+ *
144
+ * [Symbol.dispose]() {
145
+ * this.#disposables.dispose();
146
+ * }
147
+ * }
148
+ * ```
149
+ */
150
+ move(): AsyncDisposableStack;
151
+ [Symbol.asyncDispose](): Promise<void>;
152
+ readonly [Symbol.toStringTag]: string;
153
+ }
154
+ interface AsyncDisposableStackConstructor {
155
+ new (): AsyncDisposableStack;
156
+ readonly prototype: AsyncDisposableStack;
157
+ }
158
+ var AsyncDisposableStack: AsyncDisposableStackConstructor;
159
+ }
package/polyfills.js ADDED
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ var import_auto = require("disposablestack/auto");
@@ -45,7 +45,6 @@ var __param = function(paramIndex, decorator) {
45
45
  decorator(target, key, paramIndex);
46
46
  };
47
47
  };
48
- var MongoJobRepository_1;
49
48
  const indexes = [
50
49
  { key: { queue: 1, jobId: 1 }, unique: true },
51
50
  { key: { queue: 1, priority: 1, enqueueTimestamp: 1, lastDequeueTimestamp: 1, tries: 1 } },
@@ -53,7 +52,7 @@ const indexes = [
53
52
  { key: { queue: 1, batch: 1 } },
54
53
  { key: { queue: 1, tries: 1 } }
55
54
  ];
56
- let MongoJobRepository = MongoJobRepository_1 = class MongoJobRepository2 extends import_mongo.MongoEntityRepository {
55
+ let MongoJobRepository = class MongoJobRepository2 extends import_mongo.MongoEntityRepository {
57
56
  constructor(collection, logger) {
58
57
  super(collection, import_mongo.noopTransformer, { indexes, logger });
59
58
  }
@@ -72,9 +71,9 @@ let MongoJobRepository = MongoJobRepository_1 = class MongoJobRepository2 extend
72
71
  await bulk.execute(false);
73
72
  }
74
73
  };
75
- MongoJobRepository = MongoJobRepository_1 = __decorate([
74
+ MongoJobRepository = __decorate([
76
75
  (0, import_injector.Singleton)(),
77
76
  __param(0, (0, import_injector.ForwardArg)()),
78
- __param(1, (0, import_injector.ResolveArg)(MongoJobRepository_1.name)),
77
+ __param(1, (0, import_injector.ResolveArg)(MongoJobRepository.name)),
79
78
  __metadata("design:paramtypes", [import_mongo.Collection, import_logger.Logger])
80
79
  ], MongoJobRepository);
@@ -43,14 +43,14 @@ function configureElasticsearch(config = {}) {
43
43
  import_injector.Injector.registerSingleton(import_elasticsearch.Client, {
44
44
  useFactory: (argument, context) => {
45
45
  (0, import_type_guards.assertDefined)(argument, "missing elasticsearch client options");
46
- context.context.logger = (0, import_inject.inject)(import_logger.Logger, elasticsearchModuleConfig.logPrefix);
46
+ context.data.logger = (0, import_inject.inject)(import_logger.Logger, elasticsearchModuleConfig.logPrefix);
47
47
  const client = new import_elasticsearch.Client(argument);
48
- context.addDisposeHandler(async () => client.close().then(() => context.context.logger.info("closed connection")));
48
+ context.addDisposeHandler(async () => client.close().then(() => context.data.logger.info("closed connection")));
49
49
  return client;
50
50
  },
51
- async afterResolve(client, options, context) {
51
+ async afterResolve(client, options, { cancellationToken, data: { logger } }) {
52
52
  const url = getUrl(options.node ?? options.nodes);
53
- await (0, import_core.connect)(`elasticsearch (${url})`, async () => client.ping().then((alive) => (0, import_type_guards.assert)(alive, "failed to connect")), context.logger);
53
+ await (0, import_core.connect)(`elasticsearch (${url})`, async () => client.ping().then((alive) => (0, import_type_guards.assert)(alive, "failed to connect")), logger, cancellationToken);
54
54
  },
55
55
  defaultArgumentProvider() {
56
56
  return elasticsearchModuleConfig.defaultOptions;
package/tsconfig.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "compileOnSave": false,
3
3
  "compilerOptions": {
4
- "module": "esnext",
4
+ "module": "nodenext",
5
5
  "moduleResolution": "nodenext",
6
6
  "lib": ["esnext", "dom"],
7
7
  "target": "es2022",
@@ -1,4 +1,4 @@
1
- import type { Observable, Observer, Subscribable, Subscription } from 'rxjs';
1
+ import type { Observable, Observer, Subscribable, Subscription, Unsubscribable } from 'rxjs';
2
2
  export type ConnectConfig = {
3
3
  /**
4
4
  * Propagate parent set to child.
@@ -31,59 +31,61 @@ export type ConnectConfig = {
31
31
  */
32
32
  once?: boolean;
33
33
  };
34
- export interface ReadonlyCancellationToken extends PromiseLike<void>, Subscribable<void> {
34
+ export declare abstract class ReadonlyCancellationToken implements PromiseLike<void>, Subscribable<void> {
35
35
  /**
36
36
  * Returns whether this token set.
37
37
  */
38
- readonly isSet: boolean;
38
+ abstract readonly isSet: boolean;
39
39
  /**
40
40
  * Returns whether this token unset.
41
41
  */
42
- readonly isUnset: boolean;
42
+ abstract readonly isUnset: boolean;
43
43
  /**
44
44
  * Observable which emits the current state and every state change.
45
45
  */
46
- readonly state$: Observable<boolean>;
46
+ abstract readonly state$: Observable<boolean>;
47
47
  /**
48
48
  * Observable which emits when this token is set.
49
49
  */
50
- readonly set$: Observable<void>;
50
+ abstract readonly set$: Observable<void>;
51
51
  /**
52
52
  * Observable which emits when this token is unset.
53
53
  */
54
- readonly unset$: Observable<void>;
54
+ abstract readonly unset$: Observable<void>;
55
55
  /**
56
56
  * Returns a promise which is resolved when this token is set.
57
57
  */
58
- readonly $set: Promise<void>;
58
+ abstract readonly $set: Promise<void>;
59
59
  /**
60
60
  * Returns a promise which is resolved when this token is unset.
61
61
  */
62
- readonly $unset: Promise<void>;
62
+ abstract readonly $unset: Promise<void>;
63
63
  /**
64
64
  * Returns a promise which is resolved when this token changes its state.
65
65
  */
66
- readonly $state: Promise<boolean>;
66
+ abstract readonly $state: Promise<boolean>;
67
67
  /**
68
68
  * Returns an AbortSignal.
69
69
  */
70
- asAbortSignal(): AbortSignal;
70
+ abstract asAbortSignal(): AbortSignal;
71
71
  /**
72
72
  * Create a new token and connect it to this instance.
73
73
  * @see {@link connect}
74
74
  */
75
- createChild(config?: ConnectConfig): CancellationToken;
75
+ abstract createChild(config?: ConnectConfig): CancellationToken;
76
76
  /**
77
77
  * Propagate events from this instance to the `child`. Events from the `child` are *not* propagated to this instance.
78
78
  * @param child child to connect
79
79
  */
80
- connect(child: CancellationToken, config?: ConnectConfig): void;
80
+ abstract connect(child: CancellationToken, config?: ConnectConfig): void;
81
+ abstract subscribe(observer: Partial<Observer<void>>): Unsubscribable;
82
+ abstract then<TResult>(onfulfilled?: ((value: void) => TResult | PromiseLike<TResult>) | undefined | null): Promise<TResult>;
81
83
  }
82
- export declare class CancellationToken implements ReadonlyCancellationToken {
83
- private readonly stateSubject;
84
+ export declare class CancellationToken extends ReadonlyCancellationToken {
85
+ #private;
84
86
  readonly state$: Observable<boolean>;
85
- readonly set$: Observable<void>;
86
- readonly unset$: Observable<void>;
87
+ readonly set$: Observable<undefined>;
88
+ readonly unset$: Observable<undefined>;
87
89
  get isSet(): boolean;
88
90
  get isUnset(): boolean;
89
91
  get $set(): Promise<void>;