@tstdl/base 0.88.6 → 0.89.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 (120) hide show
  1. package/api/index.d.ts +7 -3
  2. package/api/index.js +7 -3
  3. package/application/index.d.ts +5 -0
  4. package/application/index.js +5 -0
  5. package/authentication/client/authentication.service.d.ts +1 -1
  6. package/authentication/client/authentication.service.js +4 -4
  7. package/authentication/client/http-client.middleware.d.ts +2 -2
  8. package/authentication/client/module.d.ts +2 -2
  9. package/authentication/client/module.js +2 -2
  10. package/authentication/index.d.ts +7 -0
  11. package/authentication/index.js +7 -0
  12. package/browser/index.d.ts +5 -0
  13. package/browser/index.js +5 -0
  14. package/cancellation/index.d.ts +4 -0
  15. package/cancellation/index.js +4 -0
  16. package/collections/index.d.ts +5 -0
  17. package/collections/index.js +5 -0
  18. package/cookie/index.d.ts +5 -0
  19. package/cookie/index.js +5 -0
  20. package/data-structures/index.d.ts +5 -0
  21. package/data-structures/index.js +5 -0
  22. package/database/index.d.ts +5 -0
  23. package/database/index.js +5 -0
  24. package/database/mongo/index.d.ts +5 -0
  25. package/database/mongo/index.js +5 -0
  26. package/database/mongo/module.js +1 -1
  27. package/decorators/index.d.ts +5 -0
  28. package/decorators/index.js +5 -0
  29. package/disposable/index.d.ts +5 -0
  30. package/disposable/index.js +5 -0
  31. package/distributed-loop/index.d.ts +5 -0
  32. package/distributed-loop/index.js +5 -0
  33. package/enumerable/index.d.ts +5 -0
  34. package/enumerable/index.js +5 -0
  35. package/error/index.d.ts +5 -0
  36. package/error/index.js +5 -0
  37. package/examples/api/authentication.js +1 -1
  38. package/examples/api/custom-authentication.js +1 -1
  39. package/function/index.d.ts +5 -0
  40. package/function/index.js +5 -0
  41. package/http/client/index.d.ts +1 -0
  42. package/http/client/index.js +1 -0
  43. package/http/index.d.ts +6 -0
  44. package/http/index.js +6 -0
  45. package/http/server/index.d.ts +2 -1
  46. package/http/server/index.js +2 -1
  47. package/image-service/index.d.ts +6 -0
  48. package/image-service/index.js +6 -0
  49. package/index.d.ts +5 -0
  50. package/index.js +5 -0
  51. package/injector/index.d.ts +5 -0
  52. package/injector/index.js +5 -0
  53. package/json-path/index.d.ts +5 -0
  54. package/json-path/index.js +5 -0
  55. package/key-value-store/index.d.ts +6 -0
  56. package/key-value-store/index.js +6 -0
  57. package/lock/index.d.ts +7 -0
  58. package/lock/index.js +7 -0
  59. package/lock/mongo/lock.d.ts +1 -2
  60. package/lock/mongo/lock.js +9 -9
  61. package/lock/mongo/provider.d.ts +3 -7
  62. package/lock/mongo/provider.js +14 -24
  63. package/logger/index.d.ts +7 -0
  64. package/logger/index.js +7 -0
  65. package/mail/index.d.ts +6 -1
  66. package/mail/index.js +6 -1
  67. package/mail/repositories/index.d.ts +2 -1
  68. package/mail/repositories/index.js +2 -1
  69. package/memory/index.d.ts +5 -0
  70. package/memory/index.js +5 -0
  71. package/message-bus/index.d.ts +7 -0
  72. package/message-bus/index.js +7 -0
  73. package/migration/index.d.ts +6 -0
  74. package/migration/index.js +6 -0
  75. package/module/index.d.ts +6 -0
  76. package/module/index.js +6 -0
  77. package/object-storage/index.d.ts +8 -2
  78. package/object-storage/index.js +8 -2
  79. package/openid-connect/index.d.ts +5 -0
  80. package/openid-connect/index.js +5 -0
  81. package/package.json +6 -24
  82. package/password/index.d.ts +5 -0
  83. package/password/index.js +5 -0
  84. package/pdf/pdf.service.d.ts +5 -0
  85. package/pdf/pdf.service.js +5 -0
  86. package/pool/index.d.ts +5 -0
  87. package/pool/index.js +5 -0
  88. package/promise/cancelable-promise.d.ts +10 -2
  89. package/promise/cancelable-promise.js +23 -19
  90. package/promise/custom-promise.d.ts +6 -0
  91. package/promise/custom-promise.js +14 -0
  92. package/promise/deferred-promise.d.ts +3 -3
  93. package/promise/deferred-promise.js +5 -8
  94. package/promise/index.d.ts +6 -0
  95. package/promise/index.js +6 -0
  96. package/promise/lazy-promise.d.ts +6 -6
  97. package/promise/lazy-promise.js +23 -15
  98. package/promise/types.d.ts +3 -0
  99. package/promise/types.js +1 -0
  100. package/signals/implementation/graph.d.ts +2 -15
  101. package/signals/implementation/graph.js +6 -1
  102. package/signals/implementation/to-observable.d.ts +1 -1
  103. package/signals/implementation/to-observable.js +1 -1
  104. package/signals/implementation/watch.d.ts +6 -0
  105. package/signals/implementation/watch.js +25 -2
  106. package/signals/index.d.ts +1 -0
  107. package/signals/index.js +1 -0
  108. package/signals/to-observable-2.d.ts +8 -0
  109. package/signals/to-observable-2.js +9 -0
  110. package/signals/to-signal-2.d.ts +4 -1
  111. package/utils/type-guards.d.ts +6 -0
  112. package/utils/type-guards.js +7 -0
  113. package/container/decorators.d.ts +0 -2
  114. package/container/decorators.js +0 -1
  115. package/container/index.d.ts +0 -3
  116. package/container/index.js +0 -3
  117. package/container/interfaces.d.ts +0 -2
  118. package/container/interfaces.js +0 -1
  119. package/container/token.d.ts +0 -2
  120. package/container/token.js +0 -1
@@ -1,11 +1,11 @@
1
- type PromiseExecutor<T> = (resolve: (value: T | PromiseLike<T>) => void, reject: (reason?: any) => void) => void;
2
- export declare class LazyPromise<T> implements Promise<T> {
3
- static readonly [Symbol.species]: PromiseConstructor;
4
- private readonly backingPromise;
1
+ import { CustomPromise } from './custom-promise.js';
2
+ import type { PromiseExecutor } from './types.js';
3
+ export declare class LazyPromise<T> extends CustomPromise<T> {
4
+ #private;
5
5
  readonly [Symbol.toStringTag] = "LazyPromise";
6
- constructor(executorOrPromiseProvider: () => (Promise<T> | PromiseExecutor<T>));
6
+ constructor(executorOrPromiseProvider: PromiseExecutor<T> | (() => PromiseLike<T>));
7
7
  then<TResult1 = T, TResult2 = never>(onfulfilled?: ((value: T) => TResult1 | PromiseLike<TResult1>) | null | undefined, onrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | null | undefined): Promise<TResult1 | TResult2>;
8
8
  catch<TResult = never>(onrejected?: ((reason: any) => TResult | PromiseLike<TResult>) | null | undefined): Promise<T | TResult>;
9
9
  finally(onfinally?: (() => void) | null | undefined): Promise<T>;
10
+ private execute;
10
11
  }
11
- export {};
@@ -1,25 +1,33 @@
1
- import { lazyProperty } from '../utils/object/lazy-property.js';
2
- import { isPromise } from '../utils/type-guards.js';
3
- export class LazyPromise {
4
- static [Symbol.species] = Promise;
5
- backingPromise;
1
+ import { isPromiseLike } from '../utils/type-guards.js';
2
+ import { CustomPromise } from './custom-promise.js';
3
+ export class LazyPromise extends CustomPromise {
4
+ #executed = false;
5
+ #executorOrPromiseProvider;
6
6
  [Symbol.toStringTag] = 'LazyPromise';
7
7
  constructor(executorOrPromiseProvider) {
8
- lazyProperty(this, 'backingPromise', async () => {
9
- const providedValue = executorOrPromiseProvider();
10
- if (isPromise(providedValue)) {
11
- return providedValue;
12
- }
13
- return new Promise(providedValue);
14
- });
8
+ super();
9
+ this.#executorOrPromiseProvider = executorOrPromiseProvider;
15
10
  }
16
11
  async then(onfulfilled, onrejected) {
17
- return this.backingPromise.then(onfulfilled, onrejected);
12
+ this.execute();
13
+ return super.then(onfulfilled, onrejected);
18
14
  }
19
15
  async catch(onrejected) {
20
- return this.backingPromise.catch(onrejected);
16
+ this.execute();
17
+ return super.catch(onrejected);
21
18
  }
22
19
  async finally(onfinally) {
23
- return this.backingPromise.finally(onfinally);
20
+ this.execute();
21
+ return super.finally(onfinally);
22
+ }
23
+ execute() {
24
+ if (this.#executed) {
25
+ return;
26
+ }
27
+ this.#executed = true;
28
+ const result = this.#executorOrPromiseProvider(this.resolve, this.reject);
29
+ if (isPromiseLike(result)) {
30
+ this.resolve(result);
31
+ }
24
32
  }
25
33
  }
@@ -0,0 +1,3 @@
1
+ export type PromiseExecutor<T> = ConstructorParameters<typeof Promise<T>>[0];
2
+ export type PromiseResolveFunction<T> = (value: T | PromiseLike<T>) => void;
3
+ export type PromiseRejectFunction = (reason?: any) => void;
@@ -0,0 +1 @@
1
+ export {};
@@ -9,21 +9,8 @@ type Version = number & {
9
9
  __brand: 'Version';
10
10
  };
11
11
  export declare function setActiveConsumer(consumer: ReactiveNode | null): ReactiveNode | null;
12
- export declare const REACTIVE_NODE: {
13
- version: Version;
14
- dirty: boolean;
15
- producerNode: undefined;
16
- producerLastReadVersion: undefined;
17
- producerIndexOfThis: undefined;
18
- nextProducerIndex: number;
19
- liveConsumerNode: undefined;
20
- liveConsumerIndexOfThis: undefined;
21
- consumerAllowSignalWrites: boolean;
22
- consumerIsAlwaysLive: boolean;
23
- producerMustRecompute: () => boolean;
24
- producerRecomputeValue: () => void;
25
- consumerMarkedDirty: () => void;
26
- };
12
+ export declare function isInNotificationPhase(): boolean;
13
+ export declare const REACTIVE_NODE: ReactiveNode;
27
14
  /**
28
15
  * A producer and/or consumer which participates in the reactive graph.
29
16
  *
@@ -17,6 +17,9 @@ export function setActiveConsumer(consumer) {
17
17
  activeConsumer = consumer;
18
18
  return prev;
19
19
  }
20
+ export function isInNotificationPhase() {
21
+ return inNotificationPhase;
22
+ }
20
23
  export const REACTIVE_NODE = {
21
24
  version: 0,
22
25
  dirty: false,
@@ -153,7 +156,9 @@ export function consumerAfterComputation(node, prevConsumer) {
153
156
  }
154
157
  }
155
158
  // Truncate the producer tracking arrays.
156
- for (let i = node.nextProducerIndex; i < node.producerNode.length; i++) {
159
+ // Perf note: this is essentially truncating the length to `node.nextProducerIndex`, but
160
+ // benchmarking has shown that individual pop operations are faster.
161
+ while (node.producerNode.length > node.nextProducerIndex) {
157
162
  node.producerNode.pop();
158
163
  node.producerLastReadVersion.pop();
159
164
  node.producerIndexOfThis.pop();
@@ -1,7 +1,7 @@
1
1
  import { Observable } from 'rxjs';
2
2
  import type { Signal } from './api.js';
3
3
  /**
4
- * Exposes the value of an Angular `Signal` as an RxJS `Observable`.
4
+ * Exposes the value of an `Signal` as an RxJS `Observable`.
5
5
  *
6
6
  * The signal's value will be propagated into the `Observable`'s subscribers using an `effect`.
7
7
  */
@@ -2,7 +2,7 @@ import { Observable } from 'rxjs';
2
2
  import { effect } from './effect.js';
3
3
  import { untracked } from './untracked.js';
4
4
  /**
5
- * Exposes the value of an Angular `Signal` as an RxJS `Observable`.
5
+ * Exposes the value of an `Signal` as an RxJS `Observable`.
6
6
  *
7
7
  * The signal's value will be propagated into the `Observable`'s subscribers using an `effect`.
8
8
  */
@@ -24,5 +24,11 @@ export interface Watch {
24
24
  */
25
25
  run(): void;
26
26
  cleanup(): void;
27
+ /**
28
+ * Destroy the watcher:
29
+ * - disconnect it from the reactive graph;
30
+ * - mark it as destroyed so subsequent run and notify operations are noop.
31
+ */
32
+ destroy(): void;
27
33
  }
28
34
  export declare function watch(fn: (onCleanup: WatchCleanupRegisterFn) => void, schedule: (watch: Watch) => void, allowSignalWrites: boolean): Watch;
@@ -5,7 +5,7 @@
5
5
  * Use of this source code is governed by an MIT-style license that can be
6
6
  * found in the LICENSE file at https://angular.io/license
7
7
  */
8
- import { consumerAfterComputation, consumerBeforeComputation, consumerMarkDirty, consumerPollProducersForChange, REACTIVE_NODE } from './graph.js';
8
+ import { consumerAfterComputation, consumerBeforeComputation, consumerDestroy, consumerMarkDirty, consumerPollProducersForChange, isInNotificationPhase, REACTIVE_NODE } from './graph.js';
9
9
  export function watch(fn, schedule, allowSignalWrites) {
10
10
  const node = Object.create(WATCH_NODE);
11
11
  if (allowSignalWrites) {
@@ -16,7 +16,27 @@ export function watch(fn, schedule, allowSignalWrites) {
16
16
  const registerOnCleanup = (cleanupFn) => {
17
17
  node.cleanupFn = cleanupFn;
18
18
  };
19
+ function isWatchNodeDestroyed(node) {
20
+ return node.fn === null && node.schedule === null;
21
+ }
22
+ function destroyWatchNode(node) {
23
+ if (!isWatchNodeDestroyed(node)) {
24
+ consumerDestroy(node); // disconnect watcher from the reactive graph
25
+ node.cleanupFn();
26
+ // nullify references to the integration functions to mark node as destroyed
27
+ node.fn = null;
28
+ node.schedule = null;
29
+ node.cleanupFn = NOOP_CLEANUP_FN;
30
+ }
31
+ }
19
32
  const run = () => {
33
+ if (node.fn === null) {
34
+ // trying to run a destroyed watch is noop
35
+ return;
36
+ }
37
+ if (isInNotificationPhase()) {
38
+ throw new Error(`Schedulers cannot synchronously execute watches while scheduling.`);
39
+ }
20
40
  node.dirty = false;
21
41
  if (node.hasRun && !consumerPollProducersForChange(node)) {
22
42
  return;
@@ -36,6 +56,7 @@ export function watch(fn, schedule, allowSignalWrites) {
36
56
  notify: () => consumerMarkDirty(node),
37
57
  run,
38
58
  cleanup: () => node.cleanupFn(),
59
+ destroy: () => destroyWatchNode(node),
39
60
  };
40
61
  return node.ref;
41
62
  }
@@ -45,7 +66,9 @@ const WATCH_NODE = {
45
66
  consumerIsAlwaysLive: true,
46
67
  consumerAllowSignalWrites: false,
47
68
  consumerMarkedDirty: (node) => {
48
- node.schedule(node.ref);
69
+ if (node.schedule !== null) {
70
+ node.schedule(node.ref);
71
+ }
49
72
  },
50
73
  hasRun: false,
51
74
  cleanupFn: NOOP_CLEANUP_FN,
@@ -4,6 +4,7 @@ export * from './effect-with-dependencies.js';
4
4
  export * from './lazylize.js';
5
5
  export * from './pipe.js';
6
6
  export * from './switch-map.js';
7
+ export * from './to-observable-2.js';
7
8
  export * from './to-signal-2.js';
8
9
  export * from './types.js';
9
10
  export * from './untracked-operator.js';
package/signals/index.js CHANGED
@@ -4,6 +4,7 @@ export * from './effect-with-dependencies.js';
4
4
  export * from './lazylize.js';
5
5
  export * from './pipe.js';
6
6
  export * from './switch-map.js';
7
+ export * from './to-observable-2.js';
7
8
  export * from './to-signal-2.js';
8
9
  export * from './types.js';
9
10
  export * from './untracked-operator.js';
@@ -0,0 +1,8 @@
1
+ import type { Observable } from 'rxjs';
2
+ import type { Signal } from './api.js';
3
+ /**
4
+ * Exposes the value of an `Signal` as an RxJS `Observable`.
5
+ *
6
+ * The signal's value will be propagated into the `Observable`'s subscribers using an `effect`.
7
+ */
8
+ export declare function toObservable2<T>(source: Signal<T>): Observable<T>;
@@ -0,0 +1,9 @@
1
+ import { toObservable } from './implementation/to-observable.js';
2
+ /**
3
+ * Exposes the value of an `Signal` as an RxJS `Observable`.
4
+ *
5
+ * The signal's value will be propagated into the `Observable`'s subscribers using an `effect`.
6
+ */
7
+ export function toObservable2(source) {
8
+ return toObservable(source);
9
+ }
@@ -5,7 +5,10 @@ export type ToSignal2Options<T> = ToSignalOptions<T> & {
5
5
  /** defer subscription until signal is used */
6
6
  lazy?: boolean;
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
+ /**
9
+ * 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.
10
+ * Subscription to observable is cleaned up using finalization (garbage collection) of the signal.
11
+ */
9
12
  export declare function toSignal2<T>(source: ToSignalInput<T>): Signal<T | undefined>;
10
13
  export declare function toSignal2<T>(source: ToSignalInput<T>, options: ToSignal2Options<undefined> & {
11
14
  requireSync: true;
@@ -252,6 +252,12 @@ export declare const assertPromise: AssertFunction<Promise<any>>;
252
252
  export declare const assertNotPromise: AssertNotFunction<Promise<any>>;
253
253
  export declare const assertPromisePass: AssertPassFunction<Promise<any>>;
254
254
  export declare const assertNotPromisePass: AssertNotPassFunction<Promise<any>>;
255
+ export declare const isPromiseLike: IsFunction<PromiseLike<any>>;
256
+ export declare const isNotPromiseLike: IsNotFunction<PromiseLike<any>>;
257
+ export declare const assertPromiseLike: AssertFunction<PromiseLike<any>>;
258
+ export declare const assertNotPromiseLike: AssertNotFunction<PromiseLike<any>>;
259
+ export declare const assertPromiseLikePass: AssertPassFunction<PromiseLike<any>>;
260
+ export declare const assertNotPromiseLikePass: AssertNotPassFunction<PromiseLike<any>>;
255
261
  export declare const isError: IsFunction<Error>;
256
262
  export declare const isNotError: IsNotFunction<Error>;
257
263
  export declare const assertError: AssertFunction<Error>;
@@ -313,6 +313,13 @@ export const assertPromise = promiseGuards.assertPromise;
313
313
  export const assertNotPromise = promiseGuards.assertNotPromise;
314
314
  export const assertPromisePass = promiseGuards.assertPromisePass;
315
315
  export const assertNotPromisePass = promiseGuards.assertNotPromisePass;
316
+ const promiseLikeGuards = createGuards('PromiseLike', (value) => isPromise(value) || ((((typeof value == 'object') && (value != null)) || isFunction(value)) && ((typeof value.then) == 'function')));
317
+ export const isPromiseLike = promiseLikeGuards.isPromiseLike;
318
+ export const isNotPromiseLike = promiseLikeGuards.isNotPromiseLike;
319
+ export const assertPromiseLike = promiseLikeGuards.assertPromiseLike;
320
+ export const assertNotPromiseLike = promiseLikeGuards.assertNotPromiseLike;
321
+ export const assertPromiseLikePass = promiseLikeGuards.assertPromiseLikePass;
322
+ export const assertNotPromiseLikePass = promiseLikeGuards.assertNotPromiseLikePass;
316
323
  const errorGuards = createInstanceGuards('error', Error);
317
324
  export const isError = errorGuards.isError;
318
325
  export const isNotError = errorGuards.isNotError;
@@ -1,2 +0,0 @@
1
- export { ForwardArg as forwardArg, ForwardRef as forwardRef, Inject as inject, InjectArg as injectArg, Injectable as injectable, Optional as optional, ReplaceClass as replaceClass, ResolveArg as resolveArg, ResolveArgProvider as resolveArgProvider, Scoped as scoped, Singleton as singleton } from '../injector/decorators.js';
2
- export type { InjectableOptionsWithoutLifecycle } from '../injector/decorators.js';
@@ -1 +0,0 @@
1
- export { ForwardArg as forwardArg, ForwardRef as forwardRef, Inject as inject, InjectArg as injectArg, Injectable as injectable, Optional as optional, ReplaceClass as replaceClass, ResolveArg as resolveArg, ResolveArgProvider as resolveArgProvider, Scoped as scoped, Singleton as singleton } from '../injector/decorators.js';
@@ -1,3 +0,0 @@
1
- export * from './decorators.js';
2
- export * from './interfaces.js';
3
- export * from './token.js';
@@ -1,3 +0,0 @@
1
- export * from './decorators.js';
2
- export * from './interfaces.js';
3
- export * from './token.js';
@@ -1,2 +0,0 @@
1
- export { afterResolve, resolveArgumentType } from '../injector/interfaces.js';
2
- export type { AfterResolve, Resolvable as Injectable, ResolveArgument as InjectableArgument } from '../injector/interfaces.js';
@@ -1 +0,0 @@
1
- export { afterResolve, resolveArgumentType } from '../injector/interfaces.js';
@@ -1,2 +0,0 @@
1
- export { ReifyingInjectionToken, getTokenName, injectionToken } from '../injector/token.js';
2
- export type { ArgumentedInjectionToken, InjectionToken, SimpleInjectionToken } from '../injector/token.js';
@@ -1 +0,0 @@
1
- export { ReifyingInjectionToken, getTokenName, injectionToken } from '../injector/token.js';