@tstdl/base 0.86.0 → 0.87.0

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 (81) hide show
  1. package/application/application.d.ts +3 -3
  2. package/application/application.js +9 -10
  3. package/authentication/client/authentication.service.js +3 -3
  4. package/browser/browser-context-controller.d.ts +2 -2
  5. package/browser/browser-context-controller.js +6 -7
  6. package/browser/browser-controller.js +6 -7
  7. package/cancellation/index.d.ts +1 -0
  8. package/{global-this.js → cancellation/index.js} +4 -23
  9. package/{utils/cancellation-token.d.ts → cancellation/token.d.ts} +31 -37
  10. package/{utils/cancellation-token.js → cancellation/token.js} +100 -55
  11. package/core.d.ts +6 -5
  12. package/core.js +12 -13
  13. package/data-structures/circular-buffer.d.ts +4 -4
  14. package/data-structures/circular-buffer.js +10 -10
  15. package/database/mongo/module.js +8 -8
  16. package/disposable/async-disposer.d.ts +12 -11
  17. package/disposable/async-disposer.js +53 -27
  18. package/disposable/disposable.d.ts +5 -4
  19. package/disposable/disposable.js +9 -5
  20. package/distributed-loop/distributed-loop.d.ts +4 -4
  21. package/distributed-loop/distributed-loop.js +6 -6
  22. package/enumerable/async-enumerable.d.ts +2 -2
  23. package/enumerable/async-enumerable.js +2 -2
  24. package/enumerable/enumerable.d.ts +2 -2
  25. package/enumerable/enumerable.js +2 -2
  26. package/examples/api/streaming.js +3 -3
  27. package/http/client/adapters/undici-http-client.adapter.js +1 -1
  28. package/http/client/http-client-request.d.ts +5 -5
  29. package/http/client/http-client-request.js +9 -9
  30. package/http/server/node/node-http-server.js +2 -2
  31. package/injector/injector.d.ts +5 -2
  32. package/injector/injector.js +59 -23
  33. package/injector/interfaces.d.ts +4 -3
  34. package/injector/provider.d.ts +12 -12
  35. package/injector/resolve.error.d.ts +1 -1
  36. package/injector/types.d.ts +16 -7
  37. package/lock/mongo/lock.js +2 -2
  38. package/lock/web/web-lock.js +2 -2
  39. package/logger/console/logger.js +2 -2
  40. package/message-bus/message-bus-base.d.ts +2 -2
  41. package/message-bus/message-bus-base.js +2 -2
  42. package/migration/migrator.js +2 -2
  43. package/module/module-base.d.ts +3 -3
  44. package/module/module-base.js +2 -2
  45. package/module/module-metric-reporter.d.ts +2 -2
  46. package/module/module-metric-reporter.js +3 -3
  47. package/module/modules/function.module.d.ts +4 -4
  48. package/module/modules/function.module.js +2 -2
  49. package/module/modules/web-server.module.d.ts +2 -2
  50. package/module/modules/web-server.module.js +2 -2
  51. package/package.json +9 -8
  52. package/polyfills.d.ts +159 -0
  53. package/polyfills.js +2 -0
  54. package/process-shutdown.d.ts +4 -2
  55. package/process-shutdown.js +15 -5
  56. package/queue/mongo/mongo-job.repository.js +3 -4
  57. package/queue/mongo/queue.d.ts +5 -5
  58. package/queue/mongo/queue.js +7 -7
  59. package/queue/queue.d.ts +3 -3
  60. package/search-index/elastic/module.js +4 -4
  61. package/signals/to-signal-2.d.ts +6 -4
  62. package/tsconfig.json +1 -1
  63. package/utils/async-iterable-helpers/buffer.js +2 -2
  64. package/utils/async-iterable-helpers/observable-iterable.js +3 -3
  65. package/utils/async-iterable-helpers/take-until.d.ts +2 -2
  66. package/utils/async-iterable-helpers/take-until.js +7 -7
  67. package/utils/backoff.d.ts +7 -7
  68. package/utils/backoff.js +7 -7
  69. package/utils/event-loop.d.ts +2 -2
  70. package/utils/event-loop.js +2 -2
  71. package/utils/feedable-async-iterable.js +3 -3
  72. package/utils/index.d.ts +0 -1
  73. package/utils/index.js +0 -1
  74. package/utils/iterable-helpers/take-until.d.ts +2 -2
  75. package/utils/iterable-helpers/take-until.js +2 -2
  76. package/utils/patch-worker.d.ts +1 -1
  77. package/utils/patch-worker.js +2 -2
  78. package/utils/periodic-reporter.js +2 -2
  79. package/utils/timing.d.ts +3 -3
  80. package/utils/timing.js +5 -5
  81. package/global-this.d.ts +0 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tstdl/base",
3
- "version": "0.86.0",
3
+ "version": "0.87.0",
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",
@@ -33,21 +34,21 @@
33
34
  "@types/mjml": "4.7",
34
35
  "@types/node": "20",
35
36
  "@types/nodemailer": "6.4",
36
- "@typescript-eslint/eslint-plugin": "6.4",
37
- "@typescript-eslint/parser": "6.4",
37
+ "@typescript-eslint/eslint-plugin": "6.5",
38
+ "@typescript-eslint/parser": "6.5",
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.86",
51
+ "@tstdl/angular": "^0.87",
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");
@@ -1,6 +1,8 @@
1
+ import type { CancellationSignal } from './cancellation/index.js';
2
+ import { CancellationToken } from './cancellation/index.js';
1
3
  import type { Logger } from './logger/index.js';
2
- import { CancellationToken } from './utils/cancellation-token.js';
3
- export declare const shutdownToken: CancellationToken;
4
+ export declare function getShutdownToken(): CancellationToken;
5
+ export declare function getShutdownSignal(): CancellationSignal;
4
6
  export declare function setProcessShutdownLogger(shutdownLogger: Logger): void;
5
7
  export declare function requestShutdown(exitCode?: number): void;
6
8
  export declare function forceShutdown(exitCode?: number): void;
@@ -19,17 +19,27 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
19
19
  var process_shutdown_exports = {};
20
20
  __export(process_shutdown_exports, {
21
21
  forceShutdown: () => forceShutdown,
22
+ getShutdownSignal: () => getShutdownSignal,
23
+ getShutdownToken: () => getShutdownToken,
22
24
  initializeSignals: () => initializeSignals,
23
25
  requestShutdown: () => requestShutdown,
24
- setProcessShutdownLogger: () => setProcessShutdownLogger,
25
- shutdownToken: () => shutdownToken
26
+ setProcessShutdownLogger: () => setProcessShutdownLogger
26
27
  });
27
28
  module.exports = __toCommonJS(process_shutdown_exports);
28
- var import_cancellation_token = require("./utils/cancellation-token.js");
29
+ var import_cancellation = require("./cancellation/index.js");
29
30
  var import_type_guards = require("./utils/type-guards.js");
30
31
  const quitSignals = ["SIGTERM", "SIGINT", "SIGHUP", "SIGBREAK"];
31
32
  const quitEvents = ["uncaughtException", "unhandledRejection", "rejectionHandled"];
32
- const shutdownToken = new import_cancellation_token.CancellationToken();
33
+ let shutdownToken;
34
+ function getShutdownToken() {
35
+ if ((0, import_type_guards.isUndefined)(shutdownToken)) {
36
+ shutdownToken = new import_cancellation.CancellationToken();
37
+ }
38
+ return shutdownToken;
39
+ }
40
+ function getShutdownSignal() {
41
+ return getShutdownToken().signal;
42
+ }
33
43
  let logger;
34
44
  function setProcessShutdownLogger(shutdownLogger) {
35
45
  logger = shutdownLogger;
@@ -40,7 +50,7 @@ function requestShutdown(exitCode = 1) {
40
50
  return;
41
51
  }
42
52
  shutdownRequested = true;
43
- shutdownToken.set();
53
+ getShutdownToken().set();
44
54
  const timeout = setTimeout(() => {
45
55
  logger.warn("forcefully quitting after 20 seconds...");
46
56
  setTimeout(() => process.exit(exitCode), 1);
@@ -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);
@@ -1,8 +1,8 @@
1
+ import type { CancellationSignal } from '../../cancellation/index.js';
1
2
  import { Lock } from '../../lock/index.js';
2
3
  import { MessageBusProvider } from '../../message-bus/index.js';
3
- import type { EnqueueManyItem, EnqueueOptions, Job, JobTag, QueueConfig } from '../../queue/index.js';
4
- import { Queue } from '../../queue/index.js';
5
- import type { ReadonlyCancellationToken } from '../../utils/cancellation-token.js';
4
+ import type { EnqueueManyItem, EnqueueOptions, Job, JobTag } from '../../queue/index.js';
5
+ import { Queue, type QueueConfig } from '../../queue/index.js';
6
6
  import { MongoJobRepository } from './mongo-job.repository.js';
7
7
  export declare class MongoQueue<T = unknown> extends Queue<T> {
8
8
  private readonly repository;
@@ -27,6 +27,6 @@ export declare class MongoQueue<T = unknown> extends Queue<T> {
27
27
  dequeueMany(count: number): Promise<Job<T>[]>;
28
28
  acknowledge(job: Job<T>): Promise<void>;
29
29
  acknowledgeMany(jobs: Job<T>[]): Promise<void>;
30
- getConsumer(cancellationToken: ReadonlyCancellationToken): AsyncIterableIterator<Job<T>>;
31
- getBatchConsumer(size: number, cancellationToken: ReadonlyCancellationToken): AsyncIterableIterator<Job<T>[]>;
30
+ getConsumer(cancellationSignal: CancellationSignal): AsyncIterableIterator<Job<T>>;
31
+ getBatchConsumer(size: number, cancellationSignal: CancellationSignal): AsyncIterableIterator<Job<T>[]>;
32
32
  }
@@ -21,6 +21,7 @@ __export(queue_exports, {
21
21
  MongoQueue: () => MongoQueue
22
22
  });
23
23
  module.exports = __toCommonJS(queue_exports);
24
+ var import_cancellation = require("../../cancellation/index.js");
24
25
  var import_id = require("../../database/id.js");
25
26
  var import_decorators = require("../../injector/decorators.js");
26
27
  var import_lock = require("../../lock/index.js");
@@ -28,7 +29,6 @@ var import_message_bus = require("../../message-bus/index.js");
28
29
  var import_queue = require("../../queue/index.js");
29
30
  var import_alphabet = require("../../utils/alphabet.js");
30
31
  var import_backoff = require("../../utils/backoff.js");
31
- var import_cancellation_token = require("../../utils/cancellation-token.js");
32
32
  var import_date_time = require("../../utils/date-time.js");
33
33
  var import_property_name = require("../../utils/object/property-name.js");
34
34
  var import_random = require("../../utils/random.js");
@@ -215,9 +215,9 @@ let MongoQueue = class MongoQueue2 extends import_queue.Queue {
215
215
  const jobIds = jobs.map((job) => job.id);
216
216
  return this.cancelMany(jobIds);
217
217
  }
218
- async *getConsumer(cancellationToken) {
219
- const continueToken = import_cancellation_token.CancellationToken.from(this.messageBus.allMessages$);
220
- for await (const backoff of (0, import_backoff.backoffGenerator)(backoffOptions, cancellationToken)) {
218
+ async *getConsumer(cancellationSignal) {
219
+ const continueToken = import_cancellation.CancellationToken.from(this.messageBus.allMessages$);
220
+ for await (const backoff of (0, import_backoff.backoffGenerator)(backoffOptions, cancellationSignal)) {
221
221
  const job = await this.dequeue();
222
222
  if (job != void 0) {
223
223
  yield job;
@@ -227,9 +227,9 @@ let MongoQueue = class MongoQueue2 extends import_queue.Queue {
227
227
  }
228
228
  continueToken.complete();
229
229
  }
230
- async *getBatchConsumer(size, cancellationToken) {
231
- const continueToken = import_cancellation_token.CancellationToken.from(this.messageBus.allMessages$);
232
- for await (const backoff of (0, import_backoff.backoffGenerator)(backoffOptions, cancellationToken)) {
230
+ async *getBatchConsumer(size, cancellationSignal) {
231
+ const continueToken = import_cancellation.CancellationToken.from(this.messageBus.allMessages$);
232
+ for await (const backoff of (0, import_backoff.backoffGenerator)(backoffOptions, cancellationSignal)) {
233
233
  const jobs = await this.dequeueMany(size);
234
234
  if (jobs.length > 0) {
235
235
  yield jobs;
package/queue/queue.d.ts CHANGED
@@ -1,6 +1,6 @@
1
+ import type { CancellationSignal } from '../cancellation/token.js';
1
2
  import type { Resolvable } from '../injector/interfaces.js';
2
3
  import { resolveArgumentType } from '../injector/interfaces.js';
3
- import type { ReadonlyCancellationToken } from '../utils/cancellation-token.js';
4
4
  import { QueueEnqueueBatch } from './enqueue-batch.js';
5
5
  export type JobTag = string | number | null;
6
6
  export type Job<T> = {
@@ -53,6 +53,6 @@ export declare abstract class Queue<T> implements Resolvable<QueueArgument> {
53
53
  abstract dequeueMany(count: number): Promise<Job<T>[]>;
54
54
  abstract acknowledge(job: Job<T>): Promise<void>;
55
55
  abstract acknowledgeMany(jobs: Job<T>[]): Promise<void>;
56
- abstract getConsumer(cancellationToken: ReadonlyCancellationToken): AsyncIterableIterator<Job<T>>;
57
- abstract getBatchConsumer(size: number, cancellationToken: ReadonlyCancellationToken): AsyncIterableIterator<Job<T>[]>;
56
+ abstract getConsumer(cancellationSignal: CancellationSignal): AsyncIterableIterator<Job<T>>;
57
+ abstract getBatchConsumer(size: number, cancellationSignal: CancellationSignal): AsyncIterableIterator<Job<T>[]>;
58
58
  }
@@ -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, { cancellationSignal, 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, cancellationSignal);
54
54
  },
55
55
  defaultArgumentProvider() {
56
56
  return elasticsearchModuleConfig.defaultOptions;
@@ -1,14 +1,16 @@
1
- import type { Subscribable } from 'rxjs';
1
+ import type { Observable, Subscribable } from 'rxjs';
2
2
  import type { Signal, ToSignalOptions } from './api.js';
3
+ type ToSignalInput<T> = Observable<T> | Subscribable<T>;
3
4
  export type ToSignal2Options<T> = ToSignalOptions<T> & {
4
5
  /** defer subscription until signal is used */
5
6
  lazy?: boolean;
6
7
  };
7
8
  /** like `toSignal`, except that it uses untracked internal operations (required for some scenarios, but might be less safe in terms of bugs catching) and has the ability to subscribe lazily */
8
- export declare function toSignal2<T>(source: Subscribable<T>): Signal<T | undefined>;
9
- export declare function toSignal2<T>(source: Subscribable<T>, options: ToSignal2Options<undefined> & {
9
+ export declare function toSignal2<T>(source: ToSignalInput<T>): Signal<T | undefined>;
10
+ export declare function toSignal2<T>(source: ToSignalInput<T>, options: ToSignal2Options<undefined> & {
10
11
  requireSync: true;
11
12
  }): Signal<T>;
12
- export declare function toSignal2<T, const I = undefined>(source: Subscribable<T>, options: ToSignal2Options<I> & {
13
+ export declare function toSignal2<T, const I = undefined>(source: ToSignalInput<T>, options: ToSignal2Options<I> & {
13
14
  requireSync?: false;
14
15
  }): Signal<T | I>;
16
+ export {};
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",
@@ -21,13 +21,13 @@ __export(buffer_exports, {
21
21
  bufferAsync: () => bufferAsync
22
22
  });
23
23
  module.exports = __toCommonJS(buffer_exports);
24
+ var import_token = require("../../cancellation/token.js");
24
25
  var import_circular_buffer = require("../../data-structures/circular-buffer.js");
25
- var import_cancellation_token = require("../cancellation-token.js");
26
26
  var import_object = require("../object/object.js");
27
27
  var import_take_until = require("./take-until.js");
28
28
  async function* bufferAsync(iterable, size) {
29
29
  const buffer = new import_circular_buffer.CircularBuffer(Math.max(1, size));
30
- const consumerEndedToken = new import_cancellation_token.CancellationToken();
30
+ const consumerEndedToken = new import_token.CancellationToken();
31
31
  let consumerHasError = false;
32
32
  let consumerError;
33
33
  void (async () => {
@@ -21,13 +21,13 @@ __export(observable_iterable_exports, {
21
21
  observableAsyncIterable: () => observableAsyncIterable
22
22
  });
23
23
  module.exports = __toCommonJS(observable_iterable_exports);
24
+ var import_token = require("../../cancellation/token.js");
24
25
  var import_rxjs = require("rxjs");
25
26
  var import_observable_array = require("../../collections/observable/observable-array.js");
26
- var import_cancellation_token = require("../cancellation-token.js");
27
27
  async function* observableAsyncIterable(observable) {
28
28
  const buffer = new import_observable_array.ObservableArray();
29
- const completeToken = new import_cancellation_token.CancellationToken();
30
- const errorToken = new import_cancellation_token.CancellationToken();
29
+ const completeToken = new import_token.CancellationToken();
30
+ const errorToken = new import_token.CancellationToken();
31
31
  let error;
32
32
  const subscription = observable.subscribe({
33
33
  next: (value) => buffer.add(value),
@@ -1,3 +1,3 @@
1
+ import type { CancellationSignal } from '../../cancellation/token.js';
1
2
  import type { AnyIterable } from '../any-iterable-iterator.js';
2
- import type { ReadonlyCancellationToken } from '../cancellation-token.js';
3
- export declare function takeUntilAsync<T>(iterable: AnyIterable<T>, cancellationToken: ReadonlyCancellationToken): AsyncIterableIterator<T>;
3
+ export declare function takeUntilAsync<T>(iterable: AnyIterable<T>, cancellationSignal: CancellationSignal): AsyncIterableIterator<T>;
@@ -23,23 +23,23 @@ __export(take_until_exports, {
23
23
  module.exports = __toCommonJS(take_until_exports);
24
24
  var import_rxjs = require("rxjs");
25
25
  var import_is_async_iterable = require("./is-async-iterable.js");
26
- function takeUntilAsync(iterable, cancellationToken) {
27
- return (0, import_is_async_iterable.isAsyncIterable)(iterable) ? async(iterable, cancellationToken) : sync(iterable, cancellationToken);
26
+ function takeUntilAsync(iterable, cancellationSignal) {
27
+ return (0, import_is_async_iterable.isAsyncIterable)(iterable) ? async(iterable, cancellationSignal) : sync(iterable, cancellationSignal);
28
28
  }
29
- async function* sync(iterable, cancellationToken) {
30
- if (cancellationToken.isSet) {
29
+ async function* sync(iterable, cancellationSignal) {
30
+ if (cancellationSignal.isSet) {
31
31
  return;
32
32
  }
33
33
  for (const item of iterable) {
34
34
  yield item;
35
- if (cancellationToken.isSet) {
35
+ if (cancellationSignal.isSet) {
36
36
  break;
37
37
  }
38
38
  }
39
39
  }
40
- async function* async(iterable, cancellationToken) {
40
+ async function* async(iterable, cancellationSignal) {
41
41
  const iterator = iterable[Symbol.asyncIterator]();
42
- const cancel$ = cancellationToken.set$.pipe((0, import_rxjs.map)(() => ({ done: true, value: void 0 })));
42
+ const cancel$ = cancellationSignal.set$.pipe((0, import_rxjs.map)(() => ({ done: true, value: void 0 })));
43
43
  try {
44
44
  while (true) {
45
45
  const result = await (0, import_rxjs.firstValueFrom)((0, import_rxjs.race)([iterator.next(), cancel$]));
@@ -1,5 +1,5 @@
1
- import type { ReadonlyCancellationToken } from './cancellation-token.js';
2
- import { CancellationToken } from './cancellation-token.js';
1
+ import type { CancellationSignal } from '../cancellation/token.js';
2
+ import { CancellationToken } from '../cancellation/token.js';
3
3
  export type BackoffStrategy = 'linear' | 'exponential';
4
4
  export type BackoffOptions = {
5
5
  /**
@@ -51,22 +51,22 @@ export declare class BackoffHelper {
51
51
  * @param loopFunction function to call
52
52
  */
53
53
  export declare function autoBackoffLoop(options: BackoffOptions, loopFunction: BackoffLoopFunction, extras?: {
54
- cancellationToken?: ReadonlyCancellationToken;
54
+ cancellationSignal?: CancellationSignal;
55
55
  errorHandler?: (error: Error) => void;
56
56
  }): Promise<void>;
57
57
  /**
58
58
  * runs a function until token is set or controller returns.
59
59
  * @param options backoff options
60
- * @param cancellationToken token to cancel loop
60
+ * @param cancellationToken signal to cancel loop
61
61
  * @param loopFunction function to call
62
62
  */
63
63
  export declare function backoffLoop(options: BackoffOptions, loopFunction: BackoffLoopFunction, extras?: {
64
- cancellationToken?: ReadonlyCancellationToken;
64
+ cancellationSignal?: CancellationSignal;
65
65
  }): Promise<void>;
66
66
  /**
67
67
  * generates endless function which, when called, backs off next iteration
68
68
  * @param options backoff options
69
- * @param cancellationToken token to cancel loop
69
+ * @param cancellationSignal signal to cancel loop
70
70
  * @example
71
71
  * for await (const backoff of backoffGenerator(options, token)) {
72
72
  * if (iWantToBackoff) {
@@ -74,4 +74,4 @@ export declare function backoffLoop(options: BackoffOptions, loopFunction: Backo
74
74
  * }
75
75
  * }
76
76
  */
77
- export declare function backoffGenerator(options: BackoffOptions, cancellationToken: ReadonlyCancellationToken): AsyncIterableIterator<BackoffGeneratorYield>;
77
+ export declare function backoffGenerator(options: BackoffOptions, cancellationSignal: CancellationSignal): AsyncIterableIterator<BackoffGeneratorYield>;
package/utils/backoff.js CHANGED
@@ -24,7 +24,7 @@ __export(backoff_exports, {
24
24
  backoffLoop: () => backoffLoop
25
25
  });
26
26
  module.exports = __toCommonJS(backoff_exports);
27
- var import_cancellation_token = require("./cancellation-token.js");
27
+ var import_token = require("../cancellation/token.js");
28
28
  var import_noop = require("./noop.js");
29
29
  var import_timing = require("./timing.js");
30
30
  var import_type_guards = require("./type-guards.js");
@@ -58,11 +58,11 @@ async function autoBackoffLoop(options, loopFunction, extras) {
58
58
  errorHandler(error);
59
59
  controller.backoff();
60
60
  }
61
- }, { cancellationToken: extras?.cancellationToken });
61
+ }, { cancellationSignal: extras?.cancellationSignal });
62
62
  }
63
63
  async function backoffLoop(options, loopFunction, extras) {
64
64
  const backoffHelper = new BackoffHelper(options);
65
- const loopCancellationToken = extras?.cancellationToken?.createChild({ unset: false, complete: false }) ?? new import_cancellation_token.CancellationToken();
65
+ const loopCancellationToken = extras?.cancellationSignal?.createChild({ unset: false, complete: false }) ?? new import_token.CancellationToken();
66
66
  let backoff = false;
67
67
  const controller = {
68
68
  backoff: () => backoff = true,
@@ -82,15 +82,15 @@ async function backoffLoop(options, loopFunction, extras) {
82
82
  }
83
83
  }
84
84
  }
85
- async function* backoffGenerator(options, cancellationToken) {
85
+ async function* backoffGenerator(options, cancellationSignal) {
86
86
  const backoffHelper = new BackoffHelper(options);
87
- while (cancellationToken.isUnset) {
87
+ while (cancellationSignal.isUnset) {
88
88
  let backoff = false;
89
- let timeoutToken = cancellationToken;
89
+ let timeoutToken = cancellationSignal;
90
90
  const backoffFunction = (continueToken) => {
91
91
  backoff = true;
92
92
  if ((0, import_type_guards.isDefined)(continueToken)) {
93
- timeoutToken = cancellationToken.createChild().inherit(continueToken);
93
+ timeoutToken = cancellationSignal.createChild().inherit(continueToken);
94
94
  }
95
95
  };
96
96
  yield backoffFunction;
@@ -1,4 +1,4 @@
1
+ import type { CancellationSignal } from '../cancellation/token.js';
1
2
  import type { Logger } from '../logger/index.js';
2
- import type { ReadonlyCancellationToken } from './cancellation-token.js';
3
3
  export declare function measureEventLoopDelay(): Promise<number>;
4
- export declare function runEventLoopWatcher(logger: Logger, cancellationToken: ReadonlyCancellationToken): void;
4
+ export declare function runEventLoopWatcher(logger: Logger, cancellationSignal: CancellationSignal): void;
@@ -34,9 +34,9 @@ async function measureEventLoopDelay() {
34
34
  });
35
35
  });
36
36
  }
37
- function runEventLoopWatcher(logger, cancellationToken) {
37
+ function runEventLoopWatcher(logger, cancellationSignal) {
38
38
  const sampler = new import_periodic_sampler.PeriodicSampler(measureEventLoopDelay, 50);
39
39
  sampler.watch(0, 100, import_periodic_sampler.AggregationMode.ThirdQuartile).subscribe((delay) => logger.debug(`eventloop: ${(0, import_format.formatDuration)(delay, 2)}`));
40
40
  sampler.start();
41
- cancellationToken.then(async () => sampler.stop());
41
+ cancellationSignal.then(async () => sampler.stop());
42
42
  }
@@ -21,9 +21,9 @@ __export(feedable_async_iterable_exports, {
21
21
  FeedableAsyncIterable: () => FeedableAsyncIterable
22
22
  });
23
23
  module.exports = __toCommonJS(feedable_async_iterable_exports);
24
- var import_circular_buffer = require("../data-structures/circular-buffer.js");
25
24
  var import_rxjs = require("rxjs");
26
- var import_cancellation_token = require("./cancellation-token.js");
25
+ var import_token = require("../cancellation/token.js");
26
+ var import_circular_buffer = require("../data-structures/circular-buffer.js");
27
27
  class FeedableAsyncIterable {
28
28
  readSubject;
29
29
  closedToken;
@@ -42,7 +42,7 @@ class FeedableAsyncIterable {
42
42
  }
43
43
  constructor() {
44
44
  this.readSubject = new import_rxjs.Subject();
45
- this.closedToken = new import_cancellation_token.CancellationToken();
45
+ this.closedToken = new import_token.CancellationToken();
46
46
  this.buffer = new import_circular_buffer.CircularBuffer();
47
47
  }
48
48
  feed(item) {
package/utils/index.d.ts CHANGED
@@ -6,7 +6,6 @@ export * from './base64.js';
6
6
  export * from './benchmark.js';
7
7
  export * from './binary-search.js';
8
8
  export * from './binary.js';
9
- export * from './cancellation-token.js';
10
9
  export * from './clone.js';
11
10
  export * from './comparison.js';
12
11
  export * from './date-time.js';