@tstdl/base 0.93.138 → 0.93.140

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 (138) hide show
  1. package/README.md +166 -0
  2. package/ai/genkit/multi-region.plugin.js +5 -3
  3. package/ai/genkit/tests/multi-region.test.d.ts +1 -0
  4. package/ai/genkit/tests/multi-region.test.js +5 -2
  5. package/ai/parser/parser.js +2 -2
  6. package/ai/prompts/build.js +1 -0
  7. package/ai/prompts/instructions-formatter.d.ts +15 -2
  8. package/ai/prompts/instructions-formatter.js +36 -31
  9. package/ai/prompts/prompt-builder.js +5 -5
  10. package/ai/prompts/steering.d.ts +3 -2
  11. package/ai/prompts/steering.js +3 -1
  12. package/ai/tests/instructions-formatter.test.js +1 -0
  13. package/api/README.md +403 -0
  14. package/api/client/client.js +7 -13
  15. package/api/client/tests/api-client.test.js +10 -10
  16. package/api/default-error-handlers.js +1 -1
  17. package/api/response.d.ts +2 -2
  18. package/api/response.js +22 -33
  19. package/api/server/api-controller.d.ts +1 -1
  20. package/api/server/api-controller.js +3 -3
  21. package/api/server/api-request-token.provider.d.ts +1 -0
  22. package/api/server/api-request-token.provider.js +1 -0
  23. package/api/server/middlewares/allowed-methods.middleware.js +2 -1
  24. package/api/server/middlewares/content-type.middleware.js +2 -1
  25. package/api/types.d.ts +3 -2
  26. package/application/README.md +240 -0
  27. package/application/application.js +2 -2
  28. package/audit/README.md +267 -0
  29. package/authentication/README.md +288 -0
  30. package/authentication/client/authentication.service.d.ts +12 -11
  31. package/authentication/client/authentication.service.js +21 -21
  32. package/authentication/client/http-client.middleware.js +2 -2
  33. package/authentication/tests/authentication.client-error-handling.test.js +2 -1
  34. package/authentication/tests/authentication.client-service-refresh.test.js +5 -3
  35. package/browser/README.md +401 -0
  36. package/cancellation/README.md +156 -0
  37. package/cancellation/tests/coverage.test.d.ts +1 -0
  38. package/cancellation/tests/coverage.test.js +49 -0
  39. package/cancellation/tests/leak.test.d.ts +1 -0
  40. package/cancellation/tests/leak.test.js +35 -0
  41. package/cancellation/tests/token.test.d.ts +1 -0
  42. package/cancellation/tests/token.test.js +136 -0
  43. package/cancellation/token.d.ts +53 -177
  44. package/cancellation/token.js +132 -201
  45. package/context/README.md +174 -0
  46. package/cookie/README.md +161 -0
  47. package/css/README.md +157 -0
  48. package/data-structures/README.md +320 -0
  49. package/decorators/README.md +140 -0
  50. package/distributed-loop/README.md +231 -0
  51. package/distributed-loop/distributed-loop.js +1 -1
  52. package/document-management/README.md +403 -0
  53. package/document-management/server/services/document-management.service.js +9 -7
  54. package/document-management/tests/document-management-core.test.js +2 -7
  55. package/document-management/tests/document-management.api.test.js +6 -7
  56. package/document-management/tests/document-statistics.service.test.js +11 -12
  57. package/document-management/tests/document.service.test.js +3 -3
  58. package/document-management/tests/enum-helpers.test.js +2 -3
  59. package/dom/README.md +213 -0
  60. package/enumerable/README.md +259 -0
  61. package/enumeration/README.md +121 -0
  62. package/errors/README.md +267 -0
  63. package/file/README.md +191 -0
  64. package/formats/README.md +210 -0
  65. package/function/README.md +144 -0
  66. package/http/README.md +318 -0
  67. package/http/client/adapters/undici.adapter.js +1 -1
  68. package/http/client/http-client-request.d.ts +6 -5
  69. package/http/client/http-client-request.js +8 -9
  70. package/http/server/node/node-http-server.js +1 -2
  71. package/image-service/README.md +137 -0
  72. package/injector/README.md +491 -0
  73. package/injector/injector.d.ts +1 -0
  74. package/injector/injector.js +17 -5
  75. package/injector/tests/leak.test.d.ts +1 -0
  76. package/injector/tests/leak.test.js +45 -0
  77. package/intl/README.md +113 -0
  78. package/json-path/README.md +182 -0
  79. package/jsx/README.md +154 -0
  80. package/key-value-store/README.md +191 -0
  81. package/lock/README.md +249 -0
  82. package/lock/web/web-lock.js +119 -47
  83. package/logger/README.md +287 -0
  84. package/mail/README.md +256 -0
  85. package/memory/README.md +144 -0
  86. package/message-bus/README.md +244 -0
  87. package/message-bus/message-bus-base.js +1 -1
  88. package/module/README.md +182 -0
  89. package/module/module.d.ts +1 -1
  90. package/module/module.js +77 -17
  91. package/module/modules/web-server.module.js +1 -1
  92. package/notification/tests/notification-type.service.test.js +24 -15
  93. package/object-storage/README.md +300 -0
  94. package/openid-connect/README.md +274 -0
  95. package/orm/README.md +423 -0
  96. package/package.json +8 -6
  97. package/password/README.md +164 -0
  98. package/pdf/README.md +246 -0
  99. package/polyfills.js +1 -0
  100. package/pool/README.md +198 -0
  101. package/process/README.md +237 -0
  102. package/promise/README.md +252 -0
  103. package/promise/cancelable-promise.js +1 -1
  104. package/random/README.md +193 -0
  105. package/reflection/README.md +305 -0
  106. package/rpc/README.md +386 -0
  107. package/rxjs-utils/README.md +262 -0
  108. package/schema/README.md +342 -0
  109. package/serializer/README.md +342 -0
  110. package/signals/implementation/README.md +134 -0
  111. package/sse/README.md +278 -0
  112. package/task-queue/README.md +300 -0
  113. package/task-queue/postgres/task-queue.d.ts +2 -1
  114. package/task-queue/postgres/task-queue.js +32 -2
  115. package/task-queue/task-context.js +1 -1
  116. package/task-queue/task-queue.d.ts +17 -0
  117. package/task-queue/task-queue.js +103 -44
  118. package/task-queue/tests/complex.test.js +4 -4
  119. package/task-queue/tests/dependencies.test.js +4 -2
  120. package/task-queue/tests/queue.test.js +111 -0
  121. package/task-queue/tests/worker.test.js +21 -13
  122. package/templates/README.md +287 -0
  123. package/testing/README.md +157 -0
  124. package/text/README.md +346 -0
  125. package/threading/README.md +238 -0
  126. package/types/README.md +311 -0
  127. package/utils/README.md +322 -0
  128. package/utils/async-iterable-helpers/observable-iterable.d.ts +1 -1
  129. package/utils/async-iterable-helpers/observable-iterable.js +4 -8
  130. package/utils/async-iterable-helpers/take-until.js +4 -4
  131. package/utils/backoff.js +89 -30
  132. package/utils/retry-with-backoff.js +1 -1
  133. package/utils/timer.d.ts +1 -1
  134. package/utils/timer.js +5 -7
  135. package/utils/timing.d.ts +1 -1
  136. package/utils/timing.js +2 -4
  137. package/utils/z-base32.d.ts +1 -0
  138. package/utils/z-base32.js +1 -0
@@ -1,4 +1,4 @@
1
- import { firstValueFrom, map, race } from 'rxjs';
1
+ import { firstValueFrom, from, map, race } from 'rxjs';
2
2
  import { isAsyncIterable } from './is-async-iterable.js';
3
3
  export function takeUntilAsync(iterable, cancellationSignal) {
4
4
  return isAsyncIterable(iterable)
@@ -20,7 +20,7 @@ async function* sync(iterable, cancellationSignal) {
20
20
  }
21
21
  async function* async(iterable, cancellationSignal) {
22
22
  const iterator = iterable[Symbol.asyncIterator]();
23
- const cancel$ = cancellationSignal.set$.pipe(map(() => ({ done: true, value: undefined }))); // eslint-disable-line @typescript-eslint/no-unsafe-argument
23
+ const cancel$ = from(cancellationSignal).pipe(map(() => ({ done: true, value: undefined })));
24
24
  try {
25
25
  while (true) {
26
26
  const result = await firstValueFrom(race([iterator.next(), cancel$]));
@@ -31,10 +31,10 @@ async function* async(iterable, cancellationSignal) {
31
31
  }
32
32
  }
33
33
  catch (error) {
34
- (iterator.throw ?? iterator.return)?.(error);
34
+ await (iterator.throw ?? iterator.return)?.(error);
35
35
  }
36
36
  finally {
37
- iterator.return?.();
37
+ await iterator.return?.();
38
38
  }
39
39
  return undefined;
40
40
  }
package/utils/backoff.js CHANGED
@@ -1,3 +1,55 @@
1
+ var __addDisposableResource = (this && this.__addDisposableResource) || function (env, value, async) {
2
+ if (value !== null && value !== void 0) {
3
+ if (typeof value !== "object" && typeof value !== "function") throw new TypeError("Object expected.");
4
+ var dispose, inner;
5
+ if (async) {
6
+ if (!Symbol.asyncDispose) throw new TypeError("Symbol.asyncDispose is not defined.");
7
+ dispose = value[Symbol.asyncDispose];
8
+ }
9
+ if (dispose === void 0) {
10
+ if (!Symbol.dispose) throw new TypeError("Symbol.dispose is not defined.");
11
+ dispose = value[Symbol.dispose];
12
+ if (async) inner = dispose;
13
+ }
14
+ if (typeof dispose !== "function") throw new TypeError("Object not disposable.");
15
+ if (inner) dispose = function() { try { inner.call(this); } catch (e) { return Promise.reject(e); } };
16
+ env.stack.push({ value: value, dispose: dispose, async: async });
17
+ }
18
+ else if (async) {
19
+ env.stack.push({ async: true });
20
+ }
21
+ return value;
22
+ };
23
+ var __disposeResources = (this && this.__disposeResources) || (function (SuppressedError) {
24
+ return function (env) {
25
+ function fail(e) {
26
+ env.error = env.hasError ? new SuppressedError(e, env.error, "An error was suppressed during disposal.") : e;
27
+ env.hasError = true;
28
+ }
29
+ var r, s = 0;
30
+ function next() {
31
+ while (r = env.stack.pop()) {
32
+ try {
33
+ if (!r.async && s === 1) return s = 0, env.stack.push(r), Promise.resolve().then(next);
34
+ if (r.dispose) {
35
+ var result = r.dispose.call(r.value);
36
+ if (r.async) return s |= 2, Promise.resolve(result).then(next, function(e) { fail(e); return next(); });
37
+ }
38
+ else s |= 1;
39
+ }
40
+ catch (e) {
41
+ fail(e);
42
+ }
43
+ }
44
+ if (s === 1) return env.hasError ? Promise.reject(env.error) : Promise.resolve();
45
+ if (env.hasError) throw env.error;
46
+ }
47
+ return next();
48
+ };
49
+ })(typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
50
+ var e = new Error(message);
51
+ return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
52
+ });
1
53
  import { CancellationToken } from '../cancellation/token.js';
2
54
  import { NEVER } from 'rxjs';
3
55
  import { randomFloat } from './math.js';
@@ -109,37 +161,44 @@ export async function autoBackoffLoop(loopFunction, options = {}) {
109
161
  * @param options Additional options for backoff configuration and cancellation.
110
162
  */
111
163
  export async function backoffLoop(loopFunction, options = {}) {
112
- const { cancellationSignal, ...backoffOptions } = options;
113
- const backoffHelper = new BackoffHelper(backoffOptions);
114
- const loopToken = new CancellationToken();
115
- let shouldBackoff = false;
116
- let customBackoffDelay;
117
- if (isDefined(cancellationSignal)) {
118
- loopToken.inherit(cancellationSignal, { set: true, unset: false, complete: false, error: false });
119
- }
120
- const controller = {
121
- backoff: (delay) => {
122
- shouldBackoff = true;
123
- customBackoffDelay = delay;
124
- },
125
- break: () => loopToken.set(),
126
- };
127
- while (loopToken.isUnset) {
128
- await loopFunction(controller, loopToken.signal, backoffHelper.status);
129
- // Exit immediately if the loop function requested a break.
130
- if (loopToken.isSet) {
131
- return;
132
- }
133
- if (shouldBackoff) {
134
- shouldBackoff = false;
135
- const delay = customBackoffDelay ?? backoffHelper.getNextDelay();
136
- await cancelableTimeout(delay, loopToken.signal);
137
- }
138
- else {
139
- // If an iteration completes successfully without a backoff request, reset the delay.
140
- backoffHelper.reset();
164
+ const env_1 = { stack: [], error: void 0, hasError: false };
165
+ try {
166
+ const { cancellationSignal, ...backoffOptions } = options;
167
+ const backoffHelper = new BackoffHelper(backoffOptions);
168
+ const loopToken = __addDisposableResource(env_1, new CancellationToken(cancellationSignal), false);
169
+ let shouldBackoff = false;
170
+ let customBackoffDelay;
171
+ const controller = {
172
+ backoff: (delay) => {
173
+ shouldBackoff = true;
174
+ customBackoffDelay = delay;
175
+ },
176
+ break: () => loopToken.set(),
177
+ };
178
+ while (loopToken.isUnset) {
179
+ await loopFunction(controller, loopToken, backoffHelper.status);
180
+ // Exit immediately if the loop function requested a break.
181
+ if (loopToken.isSet) {
182
+ return;
183
+ }
184
+ if (shouldBackoff) {
185
+ shouldBackoff = false;
186
+ const delay = customBackoffDelay ?? backoffHelper.getNextDelay();
187
+ await cancelableTimeout(delay, loopToken);
188
+ }
189
+ else {
190
+ // If an iteration completes successfully without a backoff request, reset the delay.
191
+ backoffHelper.reset();
192
+ }
141
193
  }
142
194
  }
195
+ catch (e_1) {
196
+ env_1.error = e_1;
197
+ env_1.hasError = true;
198
+ }
199
+ finally {
200
+ __disposeResources(env_1);
201
+ }
143
202
  }
144
203
  /**
145
204
  * Creates an async generator that yields a callback to trigger a backoff.
@@ -182,7 +241,7 @@ export async function* backoffGenerator(options = {}) {
182
241
  const continueToken = backoffOptions?.continueToken;
183
242
  if (isDefined(continueToken)) {
184
243
  timeoutSignal = isDefined(cancellationSignal)
185
- ? cancellationSignal.createChild().inherit(continueToken)
244
+ ? cancellationSignal.inherit(continueToken)
186
245
  : continueToken;
187
246
  }
188
247
  };
@@ -15,7 +15,7 @@ export async function retryWithBackoff(func, options = {}) {
15
15
  await backoffLoop(async (controller, loopSignal, status) => {
16
16
  try {
17
17
  const attemptSignal = isDefined(signal)
18
- ? signal.createChild().inherit(loopSignal)
18
+ ? signal.inherit(loopSignal)
19
19
  : loopSignal;
20
20
  if (isDefined(timeout)) {
21
21
  result = await withTimeout(timeout, async () => await func(attemptSignal));
package/utils/timer.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  export declare class Timer {
2
2
  private elapsedNanoseconds;
3
- private begin?;
3
+ private begin;
4
4
  constructor(start?: boolean);
5
5
  static startNew(): Timer;
6
6
  static measure(func: () => any): number;
package/utils/timer.js CHANGED
@@ -1,3 +1,4 @@
1
+ import { isDefined, isUndefined } from './type-guards.js';
1
2
  const nsPerSec = 1e9;
2
3
  const nsPerMs = 1e6;
3
4
  const nsPerUs = 1e3;
@@ -41,12 +42,10 @@ export class Timer {
41
42
  return timer.milliseconds;
42
43
  }
43
44
  start() {
44
- if (this.begin == undefined) {
45
- this.begin = getBegin();
46
- }
45
+ this.begin ??= getBegin();
47
46
  }
48
47
  stop() {
49
- if (this.begin != undefined) {
48
+ if (isDefined(this.begin)) {
50
49
  const nanoseconds = this.read();
51
50
  this.elapsedNanoseconds += nanoseconds;
52
51
  this.begin = undefined;
@@ -61,8 +60,7 @@ export class Timer {
61
60
  this.elapsedNanoseconds = 0;
62
61
  }
63
62
  get nanoseconds() {
64
- const result = this.elapsedNanoseconds + this.read();
65
- return result;
63
+ return this.elapsedNanoseconds + this.read();
66
64
  }
67
65
  get microseconds() {
68
66
  return this.nanoseconds / nsPerUs;
@@ -74,7 +72,7 @@ export class Timer {
74
72
  return this.nanoseconds / nsPerSec;
75
73
  }
76
74
  read() {
77
- if (this.begin == undefined) {
75
+ if (isUndefined(this.begin)) {
78
76
  return 0;
79
77
  }
80
78
  const result = getDuration(this.begin);
package/utils/timing.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { type Observable } from 'rxjs';
2
- import { CancellationSignal } from '../cancellation/token.js';
2
+ import type { CancellationSignal } from '../cancellation/token.js';
3
3
  import { type ValueOrProvider } from './value-or-provider.js';
4
4
  /** Timeout for specified duration */
5
5
  export declare function timeout(milliseconds?: number, options?: {
package/utils/timing.js CHANGED
@@ -1,5 +1,4 @@
1
- import { firstValueFrom, map, race, timer } from 'rxjs';
2
- import { CancellationSignal } from '../cancellation/token.js';
1
+ import { firstValueFrom, from, map, race, timer } from 'rxjs';
3
2
  import { TimeoutError } from '../errors/timeout.error.js';
4
3
  import { _throw } from './throw.js';
5
4
  import { resolveValueOrProvider } from './value-or-provider.js';
@@ -21,10 +20,9 @@ export async function timeoutUntil(timestamp) {
21
20
  }
22
21
  /** Timeout for specified duration */
23
22
  export async function cancelableTimeout(milliseconds, cancelSignal) {
24
- const observable = (cancelSignal instanceof CancellationSignal) ? cancelSignal.set$ : cancelSignal;
25
23
  return await firstValueFrom(race([
26
24
  timer(milliseconds).pipe(map(() => 'timeout')),
27
- observable.pipe(map(() => 'canceled')),
25
+ from(cancelSignal).pipe(map(() => 'canceled')),
28
26
  ]));
29
27
  }
30
28
  /** Timeout until specified time */
@@ -1,3 +1,4 @@
1
+ /** biome-ignore-all lint/suspicious/noBitwiseOperators: ok */
1
2
  import type { BinaryData } from '../types/index.js';
2
3
  export declare function zBase32Encode(buffer: BinaryData): string;
3
4
  export declare function zBase32Decode(input: string): Uint8Array<ArrayBuffer>;
package/utils/z-base32.js CHANGED
@@ -1,3 +1,4 @@
1
+ /** biome-ignore-all lint/suspicious/noBitwiseOperators: ok */
1
2
  import { Alphabet } from './alphabet.js';
2
3
  import { toUint8Array } from './binary.js';
3
4
  import { assertDefined } from './type-guards.js';