static-injector 6.0.2 → 6.1.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 (42) hide show
  1. package/import/change_detection/scheduling/zoneless_scheduling.d.ts +1 -1
  2. package/import/core_reactivity_export_internal.d.ts +3 -4
  3. package/import/di/forward_ref.d.ts +9 -7
  4. package/import/di/inject_switch.d.ts +4 -4
  5. package/import/di/injector.d.ts +12 -17
  6. package/import/di/injector_compatibility.d.ts +24 -18
  7. package/import/di/interface/injector.d.ts +13 -17
  8. package/import/di/metadata.d.ts +7 -0
  9. package/import/di/provider_collection.d.ts +2 -42
  10. package/import/di/r3_injector.d.ts +10 -11
  11. package/import/error_handler.d.ts +5 -0
  12. package/import/errors.d.ts +11 -1
  13. package/import/index.d.ts +4 -0
  14. package/import/linker/destroy_ref.d.ts +2 -0
  15. package/import/pending_tasks.d.ts +15 -16
  16. package/import/render3/errors_di.d.ts +2 -0
  17. package/import/render3/reactivity/api.d.ts +5 -1
  18. package/import/render3/reactivity/asserts.d.ts +1 -1
  19. package/import/render3/reactivity/effect.d.ts +10 -22
  20. package/import/render3/reactivity/linked_signal.d.ts +3 -3
  21. package/import/render3/reactivity/root_effect_scheduler.d.ts +4 -1
  22. package/import/render3/reactivity/signal.d.ts +3 -1
  23. package/import/resource/api.d.ts +35 -50
  24. package/import/resource/resource.d.ts +9 -7
  25. package/index.js +464 -623
  26. package/index.js.map +4 -4
  27. package/index.mjs +458 -619
  28. package/index.mjs.map +4 -4
  29. package/package.json +2 -2
  30. package/primitives/di/index.d.ts +12 -0
  31. package/primitives/di/src/injection_token.d.ts +63 -0
  32. package/primitives/di/src/injector.d.ts +14 -0
  33. package/primitives/di/src/not_found.d.ts +28 -0
  34. package/primitives/di/src/type.d.ts +61 -0
  35. package/primitives/signals/index.d.ts +5 -4
  36. package/primitives/signals/src/computed.d.ts +1 -1
  37. package/primitives/signals/src/graph.d.ts +3 -0
  38. package/primitives/signals/src/linked_signal.d.ts +2 -29
  39. package/primitives/signals/src/signal.d.ts +8 -6
  40. package/{import/render3/reactivity/patch.d.ts → primitives/signals/src/untracked.d.ts} +3 -2
  41. package/readme.md +1 -1
  42. package/import/render3/reactivity/microtask_effect.d.ts +0 -21
@@ -5,19 +5,14 @@
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.dev/license
7
7
  */
8
- import { ReactiveNode, SIGNAL } from '@angular/core/primitives/signals';
9
- import { InjectionToken } from '../../di/injection_token';
8
+ import { ReactiveNode, SIGNAL } from '../../../primitives/signals';
10
9
  import { Injector } from '../../di/injector';
11
10
  import { ChangeDetectionScheduler } from '../../change_detection/scheduling/zoneless_scheduling';
12
11
  import { EffectScheduler, SchedulableEffect } from './root_effect_scheduler';
13
- /**
14
- * Toggle the flag on whether to use microtask effects (for testing).
15
- */
16
- export declare function setUseMicrotaskEffectsByDefault(value: boolean): boolean;
17
12
  /**
18
13
  * A global reactive effect, which can be manually destroyed.
19
14
  *
20
- * @developerPreview
15
+ * @publicApi 20.0
21
16
  */
22
17
  export interface EffectRef {
23
18
  /**
@@ -33,7 +28,7 @@ export declare class EffectRefImpl implements EffectRef {
33
28
  /**
34
29
  * Options passed to the `effect` function.
35
30
  *
36
- * @developerPreview
31
+ * @publicApi 20.0
37
32
  */
38
33
  export interface CreateEffectOptions {
39
34
  /**
@@ -48,13 +43,11 @@ export interface CreateEffectOptions {
48
43
  *
49
44
  * If this is `false` (the default) the effect will automatically register itself to be cleaned up
50
45
  * with the current `DestroyRef`.
46
+ *
47
+ * If this is `true` and you want to use the effect outside an injection context, you still
48
+ * need to provide an `Injector` to the effect.
51
49
  */
52
50
  manualCleanup?: boolean;
53
- /**
54
- * Always create a root effect (which is scheduled as a microtask) regardless of whether `effect`
55
- * is called within a component.
56
- */
57
- forceRoot?: true;
58
51
  /**
59
52
  * @deprecated no longer required, signal writes are allowed by default.
60
53
  */
@@ -69,13 +62,13 @@ export interface CreateEffectOptions {
69
62
  * before the next effect run. The cleanup function makes it possible to "cancel" any work that the
70
63
  * previous effect run might have started.
71
64
  *
72
- * @developerPreview
65
+ * @publicApi 20.0
73
66
  */
74
67
  export type EffectCleanupFn = () => void;
75
68
  /**
76
69
  * A callback passed to the effect function that makes it possible to register cleanup logic.
77
70
  *
78
- * @developerPreview
71
+ * @publicApi 20.0
79
72
  */
80
73
  export type EffectCleanupRegisterFn = (cleanupFn: EffectCleanupFn) => void;
81
74
  /**
@@ -85,7 +78,7 @@ export type EffectCleanupRegisterFn = (cleanupFn: EffectCleanupFn) => void;
85
78
  * Angular has two different kinds of effect: component effects and root effects. Component effects
86
79
  * are created when `effect()` is called from a component, directive, or within a service of a
87
80
  * component/directive. Root effects are created when `effect()` is called from outside the
88
- * component tree, such as in a root service, or when the `forceRoot` option is provided.
81
+ * component tree, such as in a root service.
89
82
  *
90
83
  * The two effect types differ in their timing. Component effects run as a component lifecycle
91
84
  * event during Angular's synchronization (change detection) process, and can safely read input
@@ -94,7 +87,7 @@ export type EffectCleanupRegisterFn = (cleanupFn: EffectCleanupFn) => void;
94
87
  *
95
88
  * `effect()` must be run in injection context, unless the `injector` option is manually specified.
96
89
  *
97
- * @developerPreview
90
+ * @publicApi 20.0
98
91
  */
99
92
  export declare function effect(effectFn: (onCleanup: EffectCleanupRegisterFn) => void, options?: CreateEffectOptions): EffectRef;
100
93
  export interface EffectNode extends ReactiveNode, SchedulableEffect {
@@ -111,11 +104,6 @@ export interface EffectNode extends ReactiveNode, SchedulableEffect {
111
104
  export interface RootEffectNode extends EffectNode {
112
105
  scheduler: EffectScheduler;
113
106
  }
114
- /**
115
- * Not public API, which guarantees `EffectScheduler` only ever comes from the application root
116
- * injector.
117
- */
118
- export declare const APP_EFFECT_SCHEDULER: InjectionToken<EffectScheduler>;
119
107
  export declare const BASE_EFFECT_NODE: Omit<EffectNode, 'fn' | 'destroy' | 'injector' | 'notifier'>;
120
108
  export declare const ROOT_EFFECT_NODE: Omit<RootEffectNode, 'fn' | 'scheduler' | 'notifier' | 'injector'>;
121
109
  export declare function createRootEffect(fn: (onCleanup: EffectCleanupRegisterFn) => void, scheduler: EffectScheduler, notifier: ChangeDetectionScheduler): RootEffectNode;
@@ -5,12 +5,12 @@
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.dev/license
7
7
  */
8
- import { WritableSignal } from './signal';
9
8
  import { ValueEqualityFn } from './api';
9
+ import { WritableSignal } from './signal';
10
10
  /**
11
11
  * Creates a writable signal whose value is initialized and reset by the linked, reactive computation.
12
12
  *
13
- * @developerPreview
13
+ * @publicApi 20.0
14
14
  */
15
15
  export declare function linkedSignal<D>(computation: () => D, options?: {
16
16
  equal?: ValueEqualityFn<NoInfer<D>>;
@@ -21,7 +21,7 @@ export declare function linkedSignal<D>(computation: () => D, options?: {
21
21
  *
22
22
  * Note: The computation is reactive, meaning the linked signal will automatically update whenever any of the signals used within the computation change.
23
23
  *
24
- * @developerPreview
24
+ * @publicApi 20.0
25
25
  */
26
26
  export declare function linkedSignal<S, D>(options: {
27
27
  source: () => S;
@@ -13,11 +13,13 @@ export interface SchedulableEffect {
13
13
  zone: {
14
14
  run<T>(fn: () => T): T;
15
15
  } | null;
16
+ dirty: boolean;
16
17
  }
17
18
  /**
18
19
  * A scheduler which manages the execution of effects.
19
20
  */
20
21
  export declare abstract class EffectScheduler {
22
+ abstract add(e: SchedulableEffect): void;
21
23
  /**
22
24
  * Schedule the given effect to be executed at a later time.
23
25
  *
@@ -38,8 +40,9 @@ export declare abstract class EffectScheduler {
38
40
  * when.
39
41
  */
40
42
  export declare class ZoneAwareEffectScheduler implements EffectScheduler {
41
- private queuedEffectCount;
43
+ private dirtyEffectCount;
42
44
  private queues;
45
+ add(handle: SchedulableEffect): void;
43
46
  schedule(handle: SchedulableEffect): void;
44
47
  remove(handle: SchedulableEffect): void;
45
48
  private enqueue;
@@ -5,12 +5,14 @@
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.dev/license
7
7
  */
8
- import { SignalGetter } from '@angular/core/primitives/signals';
8
+ import { SignalGetter } from '../../../primitives/signals';
9
9
  import { Signal, ValueEqualityFn } from './api';
10
10
  /** Symbol used distinguish `WritableSignal` from other non-writable signals and functions. */
11
11
  export declare const ɵWRITABLE_SIGNAL: unique symbol;
12
12
  /**
13
13
  * A `Signal` with a value that can be mutated via a setter interface.
14
+ *
15
+ * @publicApi 17.0
14
16
  */
15
17
  export interface WritableSignal<T> extends Signal<T> {
16
18
  [ɵWRITABLE_SIGNAL]: T;
@@ -9,44 +9,29 @@ import { Injector } from '../di/injector';
9
9
  import { Signal, ValueEqualityFn } from '../render3/reactivity/api';
10
10
  import { WritableSignal } from '../render3/reactivity/signal';
11
11
  /**
12
- * Status of a `Resource`.
12
+ * String value capturing the status of a `Resource`.
13
+ *
14
+ * Possible statuses are:
15
+ *
16
+ * `idle` - The resource has no valid request and will not perform any loading. `value()` will be
17
+ * `undefined`.
18
+ *
19
+ * `loading` - The resource is currently loading a new value as a result of a change in its reactive
20
+ * dependencies. `value()` will be `undefined`.
21
+ *
22
+ * `reloading` - The resource is currently reloading a fresh value for the same reactive
23
+ * dependencies. `value()` will continue to return the previously fetched value during the reloading
24
+ * operation.
25
+ *
26
+ * `error` - Loading failed with an error. `value()` will be `undefined`.
27
+ *
28
+ * `resolved` - Loading has completed and the resource has the value returned from the loader.
29
+ *
30
+ * `local` - The resource's value was set locally via `.set()` or `.update()`.
13
31
  *
14
32
  * @experimental
15
33
  */
16
- export declare enum ResourceStatus {
17
- /**
18
- * The resource has no valid request and will not perform any loading.
19
- *
20
- * `value()` will be `undefined`.
21
- */
22
- Idle = 0,
23
- /**
24
- * Loading failed with an error.
25
- *
26
- * `value()` will be `undefined`.
27
- */
28
- Error = 1,
29
- /**
30
- * The resource is currently loading a new value as a result of a change in its `request`.
31
- *
32
- * `value()` will be `undefined`.
33
- */
34
- Loading = 2,
35
- /**
36
- * The resource is currently reloading a fresh value for the same request.
37
- *
38
- * `value()` will continue to return the previously fetched value during the reloading operation.
39
- */
40
- Reloading = 3,
41
- /**
42
- * Loading has completed and the resource has the value returned from the loader.
43
- */
44
- Resolved = 4,
45
- /**
46
- * The resource's value was set locally via `.set()` or `.update()`.
47
- */
48
- Local = 5
49
- }
34
+ export type ResourceStatus = 'idle' | 'error' | 'loading' | 'reloading' | 'resolved' | 'local';
50
35
  /**
51
36
  * A Resource is an asynchronous dependency (for example, the results of an API call) that is
52
37
  * managed and delivered through signals.
@@ -58,7 +43,7 @@ export declare enum ResourceStatus {
58
43
  */
59
44
  export interface Resource<T> {
60
45
  /**
61
- * The current value of the `Resource`, or `undefined` if there is no current value.
46
+ * The current value of the `Resource`, or throws an error if the resource is in an error state.
62
47
  */
63
48
  readonly value: Signal<T>;
64
49
  /**
@@ -69,7 +54,7 @@ export interface Resource<T> {
69
54
  /**
70
55
  * When in the `error` state, this returns the last known error from the `Resource`.
71
56
  */
72
- readonly error: Signal<unknown>;
57
+ readonly error: Signal<Error | undefined>;
73
58
  /**
74
59
  * Whether this resource is loading a new value (or reloading the existing one).
75
60
  */
@@ -80,15 +65,6 @@ export interface Resource<T> {
80
65
  * This function is reactive.
81
66
  */
82
67
  hasValue(): this is Resource<Exclude<T, undefined>>;
83
- /**
84
- * Instructs the resource to re-load any asynchronous dependency it may have.
85
- *
86
- * Note that the resource will not enter its reloading state until the actual backend request is
87
- * made.
88
- *
89
- * @returns true if a reload was initiated, false if a reload was unnecessary or unsupported
90
- */
91
- reload(): boolean;
92
68
  }
93
69
  /**
94
70
  * A `Resource` with a mutable value.
@@ -109,6 +85,15 @@ export interface WritableResource<T> extends Resource<T> {
109
85
  */
110
86
  update(updater: (value: T) => T): void;
111
87
  asReadonly(): Resource<T>;
88
+ /**
89
+ * Instructs the resource to re-load any asynchronous dependency it may have.
90
+ *
91
+ * Note that the resource will not enter its reloading state until the actual backend request is
92
+ * made.
93
+ *
94
+ * @returns true if a reload was initiated, false if a reload was unnecessary or unsupported
95
+ */
96
+ reload(): boolean;
112
97
  }
113
98
  /**
114
99
  * A `WritableResource` created through the `resource` function.
@@ -129,7 +114,7 @@ export interface ResourceRef<T> extends WritableResource<T> {
129
114
  * @experimental
130
115
  */
131
116
  export interface ResourceLoaderParams<R> {
132
- request: Exclude<NoInfer<R>, undefined>;
117
+ params: NoInfer<Exclude<R, undefined>>;
133
118
  abortSignal: AbortSignal;
134
119
  previous: {
135
120
  status: ResourceStatus;
@@ -159,10 +144,10 @@ export interface BaseResourceOptions<T, R> {
159
144
  *
160
145
  * If a request function isn't provided, the loader won't rerun unless the resource is reloaded.
161
146
  */
162
- request?: () => R;
147
+ params?: () => R;
163
148
  /**
164
149
  * The value which will be returned from the resource when a server value is unavailable, such as
165
- * when the resource is still loading, or in an error state.
150
+ * when the resource is still loading.
166
151
  */
167
152
  defaultValue?: NoInfer<T>;
168
153
  /**
@@ -215,5 +200,5 @@ export type ResourceOptions<T, R> = PromiseResourceOptions<T, R> | StreamingReso
215
200
  export type ResourceStreamItem<T> = {
216
201
  value: T;
217
202
  } | {
218
- error: unknown;
203
+ error: Error;
219
204
  };
@@ -8,7 +8,7 @@
8
8
  import { WritableSignal } from '../render3/reactivity/signal';
9
9
  import { Signal } from '../render3/reactivity/api';
10
10
  import { ResourceOptions, ResourceStatus, WritableResource, Resource, ResourceRef, ResourceStreamingLoader } from './api';
11
- import { ValueEqualityFn } from '@angular/core/primitives/signals';
11
+ import { ValueEqualityFn } from '../../primitives/signals';
12
12
  import { Injector } from '../di/injector';
13
13
  /**
14
14
  * Constructs a `Resource` that projects a reactive request to an asynchronous operation defined by
@@ -18,7 +18,7 @@ import { Injector } from '../di/injector';
18
18
  * `resource` will cancel in-progress loads via the `AbortSignal` when destroyed or when a new
19
19
  * request object becomes available, which could prematurely abort mutations.
20
20
  *
21
- * @experimental
21
+ * @experimental 19.0
22
22
  */
23
23
  export declare function resource<T, R>(options: ResourceOptions<T, R> & {
24
24
  defaultValue: NoInfer<T>;
@@ -31,7 +31,7 @@ export declare function resource<T, R>(options: ResourceOptions<T, R> & {
31
31
  * `resource` will cancel in-progress loads via the `AbortSignal` when destroyed or when a new
32
32
  * request object becomes available, which could prematurely abort mutations.
33
33
  *
34
- * @experimental
34
+ * @experimental 19.0
35
35
  */
36
36
  export declare function resource<T, R>(options: ResourceOptions<T, R>): ResourceRef<T | undefined>;
37
37
  type WrappedRequest = {
@@ -44,10 +44,11 @@ type WrappedRequest = {
44
44
  declare abstract class BaseWritableResource<T> implements WritableResource<T> {
45
45
  readonly value: WritableSignal<T>;
46
46
  abstract readonly status: Signal<ResourceStatus>;
47
- abstract readonly error: Signal<unknown>;
47
+ abstract readonly error: Signal<Error | undefined>;
48
48
  abstract reload(): boolean;
49
49
  constructor(value: Signal<T>);
50
50
  abstract set(value: T): void;
51
+ private readonly isError;
51
52
  update(updateFn: (value: T) => T): void;
52
53
  readonly isLoading: Signal<boolean>;
53
54
  hasValue(): this is ResourceRef<Exclude<T, undefined>>;
@@ -58,7 +59,6 @@ declare abstract class BaseWritableResource<T> implements WritableResource<T> {
58
59
  */
59
60
  export declare class ResourceImpl<T, R> extends BaseWritableResource<T> implements ResourceRef<T> {
60
61
  private readonly loaderFn;
61
- private readonly defaultValue;
62
62
  private readonly equal;
63
63
  private readonly pendingTasks;
64
64
  /**
@@ -74,9 +74,10 @@ export declare class ResourceImpl<T, R> extends BaseWritableResource<T> implemen
74
74
  private pendingController;
75
75
  private resolvePendingTask;
76
76
  private destroyed;
77
- constructor(request: () => R, loaderFn: ResourceStreamingLoader<T, R>, defaultValue: T, equal: ValueEqualityFn<T> | undefined, injector: Injector);
77
+ private unregisterOnDestroy;
78
+ constructor(request: () => R, loaderFn: ResourceStreamingLoader<T, R>, defaultValue: T, equal: ValueEqualityFn<T> | undefined, injector: Injector, throwErrorsFromValue?: boolean);
78
79
  readonly status: Signal<ResourceStatus>;
79
- readonly error: Signal<unknown>;
80
+ readonly error: Signal<Error | undefined>;
80
81
  /**
81
82
  * Called either directly via `WritableResource.set` or via `.value.set()`.
82
83
  */
@@ -86,4 +87,5 @@ export declare class ResourceImpl<T, R> extends BaseWritableResource<T> implemen
86
87
  private loadEffect;
87
88
  private abortInProgressLoad;
88
89
  }
90
+ export declare function encapsulateResourceError(error: unknown): Error;
89
91
  export {};