static-injector 6.4.0 → 7.0.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 (52) hide show
  1. package/import/application/application_tokens.d.ts +58 -0
  2. package/import/application/stability_debug.d.ts +13 -0
  3. package/import/authoring/output/output_ref.d.ts +37 -0
  4. package/import/change_detection/scheduling/zoneless_scheduling.d.ts +0 -7
  5. package/import/core_reactivity_export_internal.d.ts +1 -1
  6. package/import/defer/idle_service.d.ts +42 -0
  7. package/import/di/create_injector.d.ts +2 -2
  8. package/import/di/forward_ref.d.ts +2 -2
  9. package/import/di/index.d.ts +4 -0
  10. package/import/di/inject_async.d.ts +91 -0
  11. package/import/di/injectable.d.ts +7 -1
  12. package/import/di/injection_token.d.ts +7 -0
  13. package/import/di/injector.d.ts +1 -1
  14. package/import/di/injector_compatibility.d.ts +0 -1
  15. package/import/di/interface/defs.d.ts +2 -2
  16. package/import/di/interface/provider.d.ts +0 -15
  17. package/import/document.d.ts +18 -0
  18. package/import/errors.d.ts +13 -9
  19. package/import/event_emitter.d.ts +101 -0
  20. package/import/hydration/cache.d.ts +14 -0
  21. package/import/index.d.ts +16 -0
  22. package/import/linker.d.ts +1 -0
  23. package/import/pending_tasks.d.ts +1 -24
  24. package/import/pending_tasks_internal.d.ts +31 -0
  25. package/import/render3/debug/injector_profiler.d.ts +10 -4
  26. package/import/render3/debug/special_providers.d.ts +17 -0
  27. package/import/render3/reactivity/api.d.ts +15 -0
  28. package/import/render3/reactivity/asserts.d.ts +1 -0
  29. package/import/render3/reactivity/effect.d.ts +3 -1
  30. package/import/render3/reactivity/root_effect_scheduler.d.ts +1 -1
  31. package/import/render3/reactivity/signal.d.ts +0 -4
  32. package/import/render3/util/stringify_utils.d.ts +1 -1
  33. package/import/resource/api.d.ts +101 -15
  34. package/import/resource/debounce.d.ts +21 -0
  35. package/import/resource/from_snapshots.d.ts +16 -0
  36. package/import/resource/index.d.ts +2 -0
  37. package/import/resource/resource.d.ts +32 -8
  38. package/import/transfer_state.d.ts +89 -0
  39. package/import/util/default_export.d.ts +24 -0
  40. package/import/util/promise_with_resolvers.d.ts +38 -0
  41. package/import/zone/ng_zone.d.ts +261 -0
  42. package/index.js +875 -196
  43. package/index.js.map +4 -4
  44. package/index.mjs +858 -190
  45. package/index.mjs.map +4 -4
  46. package/package.json +2 -2
  47. package/primitives/signals/index.d.ts +1 -1
  48. package/primitives/signals/src/formatter.d.ts +2 -1
  49. package/primitives/signals/src/graph.d.ts +8 -1
  50. package/primitives/signals/src/linked_signal.d.ts +1 -1
  51. package/readme.md +1 -1
  52. /package/import/{interface → change_detection}/lifecycle_hooks.d.ts +0 -0
@@ -0,0 +1,31 @@
1
+ /**
2
+ * @license
3
+ * Copyright Google LLC All Rights Reserved.
4
+ *
5
+ * Use of this source code is governed by an MIT-style license that can be
6
+ * found in the LICENSE file at https://angular.dev/license
7
+ */
8
+ import { Observable } from 'rxjs';
9
+ import { OnDestroy } from './change_detection/lifecycle_hooks';
10
+ /**
11
+ * Internal implementation of the pending tasks service.
12
+ */
13
+ export declare class PendingTasksInternal implements OnDestroy {
14
+ private taskId;
15
+ private pendingTasks;
16
+ private destroyed;
17
+ private pendingTask;
18
+ private debugTaskTracker;
19
+ get hasPendingTasks(): boolean;
20
+ /**
21
+ * In case the service is about to be destroyed, return a self-completing observable.
22
+ * Otherwise, return the observable that emits the current state of pending tasks.
23
+ */
24
+ get hasPendingTasksObservable(): Observable<boolean>;
25
+ add(): number;
26
+ has(taskId: number): boolean;
27
+ remove(taskId: number): void;
28
+ ngOnDestroy(): void;
29
+ /** @nocollapse */
30
+ static ɵprov: import("./di/interface/defs").ɵɵInjectableDeclaration<PendingTasksInternal>;
31
+ }
@@ -10,7 +10,7 @@ import type { Injector } from '../../di/injector';
10
10
  import { InternalInjectFlags } from '../../di/interface/injector';
11
11
  import type { SingleProvider } from '../../di/provider_collection';
12
12
  import { Type } from '../../interface/type';
13
- import type { EffectRef } from '../reactivity/effect';
13
+ import type { EffectRefImpl } from '../reactivity/effect';
14
14
  /**
15
15
  * An enum describing the types of events that can be emitted from the injector profiler
16
16
  */
@@ -31,10 +31,14 @@ export declare const enum InjectorProfilerEventType {
31
31
  * Emits when an effect is created.
32
32
  */
33
33
  EffectCreated = 3,
34
+ /**
35
+ * Emits when an after render effect phase is created.
36
+ */
37
+ AfterRenderEffectPhaseCreated = 4,
34
38
  /**
35
39
  * Emits when an Angular DI system is about to create an instance corresponding to a given token.
36
40
  */
37
- InjectorToCreateInstanceEvent = 4
41
+ InjectorToCreateInstanceEvent = 5
38
42
  }
39
43
  /**
40
44
  * An object that defines an injection context for the injector profiler.
@@ -51,10 +55,12 @@ export interface ProviderConfiguredEvent {
51
55
  }
52
56
  export interface EffectCreatedEvent {
53
57
  }
58
+ export interface AfterRenderEffectPhaseCreatedEvent {
59
+ }
54
60
  /**
55
61
  * An object representing an event that is emitted through the injector profiler
56
62
  */
57
- export type InjectorProfilerEvent = InjectedServiceEvent | InjectorToCreateInstanceEvent | InjectorCreatedInstanceEvent | ProviderConfiguredEvent | EffectCreatedEvent;
63
+ export type InjectorProfilerEvent = InjectedServiceEvent | InjectorToCreateInstanceEvent | InjectorCreatedInstanceEvent | ProviderConfiguredEvent | EffectCreatedEvent | AfterRenderEffectPhaseCreatedEvent;
58
64
  /**
59
65
  * An object that contains information about a provider that has been configured
60
66
  *
@@ -129,5 +135,5 @@ export declare function emitInstanceCreatedByInjectorEvent(instance: unknown): v
129
135
  * @param flags the flags that the token was injected with
130
136
  */
131
137
  export declare function emitInjectEvent(token: Type<unknown>, value: unknown, flags: InternalInjectFlags): void;
132
- export declare function emitEffectCreatedEvent(effect: EffectRef): void;
138
+ export declare function emitEffectCreatedEvent(effect: EffectRefImpl): void;
133
139
  export declare function runInInjectorProfilerContext(injector: Injector, token: Type<unknown>, callback: () => void): void;
@@ -0,0 +1,17 @@
1
+ /**
2
+ * @license
3
+ * Copyright Google LLC All Rights Reserved.
4
+ *
5
+ * Use of this source code is governed by an MIT-style license that can be
6
+ * found in the LICENSE file at https://angular.dev/license
7
+ */
8
+ /**
9
+ * Registers a class as a special provider for debug tooling.
10
+ *
11
+ * @param clazz The class to register
12
+ */
13
+ export declare function registerSpecialProvider(clazz: any): void;
14
+ /**
15
+ * Gets all special providers that have been registered.
16
+ */
17
+ export declare function getAllSpecialProviders(): ReadonlySet<any>;
@@ -6,6 +6,7 @@
6
6
  * found in the LICENSE file at https://angular.dev/license
7
7
  */
8
8
  import { SIGNAL } from '../../../primitives/signals';
9
+ import type { WritableSignal } from './signal';
9
10
  /**
10
11
  * A reactive value which notifies consumers of any changes.
11
12
  *
@@ -14,6 +15,8 @@ import { SIGNAL } from '../../../primitives/signals';
14
15
  *
15
16
  * Ordinary values can be turned into `Signal`s with the `signal` function.
16
17
  *
18
+ * @see [What are signals?](guide/signals#what-are-signals)
19
+ *
17
20
  * @publicApi 17.0
18
21
  */
19
22
  export type Signal<T> = (() => T) & {
@@ -22,12 +25,24 @@ export type Signal<T> = (() => T) & {
22
25
  /**
23
26
  * Checks if the given `value` is a reactive `Signal`.
24
27
  *
28
+ * @see [Type checking signals](guide/signals#type-checking-signals)
29
+ *
25
30
  * @publicApi 17.0
26
31
  */
27
32
  export declare function isSignal(value: unknown): value is Signal<unknown>;
28
33
  /**
29
34
  * A comparison function which can determine if two values are equal.
30
35
  *
36
+ * @see [Signal equality functions](guide/signals#signal-equality-functions)
37
+ *
31
38
  * @publicApi 17.0
32
39
  */
33
40
  export type ValueEqualityFn<T> = (a: T, b: T) => boolean;
41
+ /**
42
+ * Checks if the given `value` is a writeable signal.
43
+ *
44
+ * @see [Type checking signals](guide/signals#type-checking-signals)
45
+ *
46
+ * @publicApi 21.1
47
+ */
48
+ export declare function isWritableSignal(value: unknown): value is WritableSignal<unknown>;
@@ -10,6 +10,7 @@
10
10
  * to disallow certain code from running inside a reactive context (see {@link /api/core/rxjs-interop/toSignal toSignal})
11
11
  *
12
12
  * @param debugFn a reference to the function making the assertion (used for the error message).
13
+ * @see [Asserts the reactive context](guide/signals#asserts-the-reactive-context)
13
14
  *
14
15
  * @publicApi
15
16
  */
@@ -13,6 +13,8 @@ import { EffectScheduler, SchedulableEffect } from './root_effect_scheduler';
13
13
  * A global reactive effect, which can be manually destroyed.
14
14
  *
15
15
  * @publicApi 20.0
16
+ *
17
+ * @see [Destroying effects](guide/signals/effect#destroying-effects)
16
18
  */
17
19
  export interface EffectRef {
18
20
  /**
@@ -100,7 +102,7 @@ export interface EffectNode extends BaseEffectNode, SchedulableEffect {
100
102
  cleanupFns: EffectCleanupFn[] | undefined;
101
103
  injector: Injector;
102
104
  notifier: ChangeDetectionScheduler;
103
- onDestroyFn: () => void;
105
+ onDestroyFns: (() => void)[] | null;
104
106
  }
105
107
  export interface RootEffectNode extends EffectNode {
106
108
  scheduler: EffectScheduler;
@@ -33,7 +33,7 @@ export declare abstract class EffectScheduler {
33
33
  /** Remove a scheduled effect */
34
34
  abstract remove(e: SchedulableEffect): void;
35
35
  /** @nocollapse */
36
- static ɵprov: unknown;
36
+ static ɵprov: import("../../di/interface/defs").ɵɵInjectableDeclaration<ZoneAwareEffectScheduler>;
37
37
  }
38
38
  /**
39
39
  * A wrapper around `ZoneAwareQueueingScheduler` that schedules flushing via the microtask queue
@@ -58,7 +58,3 @@ export interface CreateSignalOptions<T> {
58
58
  */
59
59
  export declare function signal<T>(initialValue: T, options?: CreateSignalOptions<T>): WritableSignal<T>;
60
60
  export declare function signalAsReadonlyFn<T>(this: SignalGetter<T>): Signal<T>;
61
- /**
62
- * Checks if the given `value` is a writeable signal.
63
- */
64
- export declare function isWritableSignal(value: unknown): value is WritableSignal<unknown>;
@@ -11,7 +11,7 @@
11
11
  * be extra careful not to introduce megamorphic reads in it.
12
12
  * Check `core/test/render3/perf/render_stringify` for benchmarks and alternate implementations.
13
13
  */
14
- export declare function renderStringify(value: any): string;
14
+ export declare function renderStringify(value: unknown): string;
15
15
  /**
16
16
  * Used to stringify a value so that it can be displayed in an error message.
17
17
  *
@@ -8,6 +8,37 @@
8
8
  import { Injector } from '../di/injector';
9
9
  import { Signal, ValueEqualityFn } from '../render3/reactivity/api';
10
10
  import { WritableSignal } from '../render3/reactivity/signal';
11
+ /** Error thrown when a `Resource` dependency of another resource errors. */
12
+ export declare class ResourceDependencyError extends Error {
13
+ /** The dependency that errored. */
14
+ readonly dependency: Resource<unknown>;
15
+ constructor(dependency: Resource<unknown>);
16
+ }
17
+ /**
18
+ * Special status codes that can be thrown from a resource's `params` or `request` function to
19
+ * indicate that the resource should transition to that status.
20
+ */
21
+ export declare class ResourceParamsStatus extends Error {
22
+ private readonly _brand;
23
+ private constructor();
24
+ /** Status code that transitions the resource to `idle` status. */
25
+ static readonly IDLE: ResourceParamsStatus;
26
+ /** Status code that transitions the resource to `loading` status. */
27
+ static readonly LOADING: ResourceParamsStatus;
28
+ }
29
+ /**
30
+ * Context received by a resource's `params` or `request` function.
31
+ *
32
+ * @see [Chaining resources](guide/signals/resource#chaining-resources)
33
+ */
34
+ export interface ResourceParamsContext {
35
+ /**
36
+ * Chains the current params off of the value of another resource, returning the value
37
+ * of the other resource if it is available, or propagating the status to the current resource by
38
+ * throwing the appropriate status code if the value is not available.
39
+ */
40
+ readonly chain: <T>(resource: Resource<T>) => T;
41
+ }
11
42
  /**
12
43
  * String value capturing the status of a `Resource`.
13
44
  *
@@ -29,7 +60,7 @@ import { WritableSignal } from '../render3/reactivity/signal';
29
60
  *
30
61
  * `local` - The resource's value was set locally via `.set()` or `.update()`.
31
62
  *
32
- * @experimental
63
+ * @publicApi 22.0
33
64
  */
34
65
  export type ResourceStatus = 'idle' | 'error' | 'loading' | 'reloading' | 'resolved' | 'local';
35
66
  /**
@@ -39,7 +70,7 @@ export type ResourceStatus = 'idle' | 'error' | 'loading' | 'reloading' | 'resol
39
70
  * The usual way of creating a `Resource` is through the `resource` function, but various other APIs
40
71
  * may present `Resource` instances to describe their own concepts.
41
72
  *
42
- * @experimental
73
+ * @publicApi 22.0
43
74
  */
44
75
  export interface Resource<T> {
45
76
  /**
@@ -59,6 +90,10 @@ export interface Resource<T> {
59
90
  * Whether this resource is loading a new value (or reloading the existing one).
60
91
  */
61
92
  readonly isLoading: Signal<boolean>;
93
+ /**
94
+ * The current state of this resource, represented as a `ResourceSnapshot`.
95
+ */
96
+ readonly snapshot: Signal<ResourceSnapshot<T>>;
62
97
  /**
63
98
  * Whether this resource has a valid current value.
64
99
  *
@@ -72,7 +107,7 @@ export interface Resource<T> {
72
107
  *
73
108
  * Overwriting the value of a resource sets it to the 'local' state.
74
109
  *
75
- * @experimental
110
+ * @publicApi 22.0
76
111
  */
77
112
  export interface WritableResource<T> extends Resource<T> {
78
113
  readonly value: WritableSignal<T>;
@@ -100,7 +135,7 @@ export interface WritableResource<T> extends Resource<T> {
100
135
  /**
101
136
  * A `WritableResource` created through the `resource` function.
102
137
  *
103
- * @experimental
138
+ * @publicApi 22.0
104
139
  */
105
140
  export interface ResourceRef<T> extends WritableResource<T> {
106
141
  hasValue(this: T extends undefined ? this : never): this is ResourceRef<Exclude<T, undefined>>;
@@ -114,7 +149,7 @@ export interface ResourceRef<T> extends WritableResource<T> {
114
149
  * Parameter to a `ResourceLoader` which gives the request and other options for the current loading
115
150
  * operation.
116
151
  *
117
- * @experimental
152
+ * @publicApi 22.0
118
153
  */
119
154
  export interface ResourceLoaderParams<R> {
120
155
  params: NoInfer<Exclude<R, undefined>>;
@@ -126,19 +161,19 @@ export interface ResourceLoaderParams<R> {
126
161
  /**
127
162
  * Loading function for a `Resource`.
128
163
  *
129
- * @experimental
164
+ * @publicApi 22.0
130
165
  */
131
166
  export type ResourceLoader<T, R> = (param: ResourceLoaderParams<R>) => PromiseLike<T>;
132
167
  /**
133
168
  * Streaming loader for a `Resource`.
134
169
  *
135
- * @experimental
170
+ * @publicApi 22.0
136
171
  */
137
- export type ResourceStreamingLoader<T, R> = (param: ResourceLoaderParams<R>) => PromiseLike<Signal<ResourceStreamItem<T>>>;
172
+ export type ResourceStreamingLoader<T, R> = (param: ResourceLoaderParams<R>) => Signal<ResourceStreamItem<T>> | PromiseLike<Signal<ResourceStreamItem<T>>> | undefined;
138
173
  /**
139
174
  * Options to the `resource` function, for creating a resource.
140
175
  *
141
- * @experimental
176
+ * @publicApi 22.0
142
177
  */
143
178
  export interface BaseResourceOptions<T, R> {
144
179
  /**
@@ -147,7 +182,7 @@ export interface BaseResourceOptions<T, R> {
147
182
  *
148
183
  * If a params function isn't provided, the loader won't rerun unless the resource is reloaded.
149
184
  */
150
- params?: () => R;
185
+ params?: (ctx: ResourceParamsContext) => R;
151
186
  /**
152
187
  * The value which will be returned from the resource when a server value is unavailable, such as
153
188
  * when the resource is still loading.
@@ -161,11 +196,16 @@ export interface BaseResourceOptions<T, R> {
161
196
  * Overrides the `Injector` used by `resource`.
162
197
  */
163
198
  injector?: Injector;
199
+ /**
200
+ * Identifier used to cache the resource data in the `TransferState` during server-side rendering and to retrieve it on the client side.
201
+ * This value value needs to be identical for both the client and server.
202
+ */
203
+ id?: string;
164
204
  }
165
205
  /**
166
206
  * Options to the `resource` function, for creating a resource.
167
207
  *
168
- * @experimental
208
+ * @publicApi 22.0
169
209
  */
170
210
  export interface PromiseResourceOptions<T, R> extends BaseResourceOptions<T, R> {
171
211
  /**
@@ -180,7 +220,7 @@ export interface PromiseResourceOptions<T, R> extends BaseResourceOptions<T, R>
180
220
  /**
181
221
  * Options to the `resource` function, for creating a resource.
182
222
  *
183
- * @experimental
223
+ * @publicApi 22.0
184
224
  */
185
225
  export interface StreamingResourceOptions<T, R> extends BaseResourceOptions<T, R> {
186
226
  /**
@@ -194,14 +234,60 @@ export interface StreamingResourceOptions<T, R> extends BaseResourceOptions<T, R
194
234
  loader?: never;
195
235
  }
196
236
  /**
197
- * @experimental
237
+ * @publicApi 22.0
198
238
  */
199
- export type ResourceOptions<T, R> = PromiseResourceOptions<T, R> | StreamingResourceOptions<T, R>;
239
+ export type ResourceOptions<T, R> = (PromiseResourceOptions<T, R> | StreamingResourceOptions<T, R>) & {
240
+ /**
241
+ * A debug name for the reactive node. Used in Angular DevTools to identify the node.
242
+ */
243
+ debugName?: string;
244
+ };
200
245
  /**
201
- * @experimental
246
+ * @publicApi 22.0
202
247
  */
203
248
  export type ResourceStreamItem<T> = {
204
249
  value: T;
205
250
  } | {
206
251
  error: Error;
207
252
  };
253
+ /**
254
+ * An explicit representation of a resource's state.
255
+ *
256
+ * @publicApi 22.0
257
+ * @see [Resource composition with snapshots](guide/signals/resource#resource-composition-with-snapshots)
258
+ */
259
+ export type ResourceSnapshot<T> = {
260
+ readonly status: 'idle';
261
+ readonly value: T;
262
+ } | {
263
+ readonly status: 'loading' | 'reloading';
264
+ readonly value: T;
265
+ } | {
266
+ readonly status: 'resolved' | 'local';
267
+ readonly value: T;
268
+ } | {
269
+ readonly status: 'error';
270
+ readonly error: Error;
271
+ };
272
+ /**
273
+ * Options for `debounced`.
274
+ *
275
+ * @see [Debouncing signals with `debounced`](guide/signals/debounced)
276
+ *
277
+ * @experimental 22.0
278
+ */
279
+ export interface DebouncedOptions<T> {
280
+ /** The `Injector` to use for the debounced resource. */
281
+ injector?: Injector;
282
+ /** The equality function to use for comparing values. */
283
+ equal?: ValueEqualityFn<T>;
284
+ }
285
+ /**
286
+ * Represents the wait condition for item debouncing.
287
+ * Can be a number of milliseconds or a function that returns a Promise.
288
+ *
289
+ * @see [Debouncing signals with `debounced`](guide/signals/debounced)
290
+ *
291
+ * @experimental 22.0
292
+ */
293
+ export type DebounceTimer<T> = number | ((value: T, lastValue: ResourceSnapshot<T>) => Promise<void> | void);
@@ -0,0 +1,21 @@
1
+ /**
2
+ * @license
3
+ * Copyright Google LLC All Rights Reserved.
4
+ *
5
+ * Use of this source code is governed by an MIT-style license that can be
6
+ * found in the LICENSE file at https://angular.dev/license
7
+ */
8
+ import { Resource, type DebounceTimer, type DebouncedOptions } from './api';
9
+ /**
10
+ * Creates a resource representing a debounced version of the source signal.
11
+ *
12
+ * @param source The source signal to debounce.
13
+ * @param wait The amount of time to wait before calling the source signal, or a function that
14
+ * returns a promise that resolves when the debounced value should be updated.
15
+ * @param options The options to use for the debounced signal.
16
+ * @returns A resource representing the debounced signal.
17
+ * @experimental 22.0
18
+ *
19
+ * @see [Debouncing signals with `debounced`](guide/signals/debounced)
20
+ */
21
+ export declare function debounced<T>(source: () => T, wait: NoInfer<DebounceTimer<T>>, options?: NoInfer<DebouncedOptions<T>>): Resource<T>;
@@ -0,0 +1,16 @@
1
+ /**
2
+ * @license
3
+ * Copyright Google LLC All Rights Reserved.
4
+ *
5
+ * Use of this source code is governed by an MIT-style license that can be
6
+ * found in the LICENSE file at https://angular.dev/license
7
+ */
8
+ import { Resource, ResourceSnapshot } from './api';
9
+ /**
10
+ * Creates a `Resource` driven by a source of `ResourceSnapshot`s.
11
+ *
12
+ * @see [Resource composition with snapshots](guide/signals/resource#resource-composition-with-snapshots)
13
+ *
14
+ * @experimental
15
+ */
16
+ export declare function resourceFromSnapshots<T>(source: () => ResourceSnapshot<T>): Resource<T>;
@@ -6,4 +6,6 @@
6
6
  * found in the LICENSE file at https://angular.dev/license
7
7
  */
8
8
  export * from './api';
9
+ export { debounced } from './debounce';
10
+ export { resourceFromSnapshots } from './from_snapshots';
9
11
  export { resource } from './resource';
@@ -5,10 +5,11 @@
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 '../render3/reactivity/signal';
9
8
  import { Signal, ValueEqualityFn } from '../render3/reactivity/api';
10
- import { ResourceOptions, ResourceStatus, WritableResource, Resource, ResourceRef, ResourceStreamingLoader } from './api';
9
+ import { WritableSignal } from '../render3/reactivity/signal';
10
+ import { Resource, ResourceOptions, ResourceSnapshot, ResourceStatus, ResourceStreamingLoader, ResourceStreamItem, type ResourceParamsContext, type ResourceRef, type WritableResource } from './api';
11
11
  import { Injector } from '../di/injector';
12
+ import { StateKey } from '../transfer_state';
12
13
  /**
13
14
  * Constructs a `Resource` that projects a reactive request to an asynchronous operation defined by
14
15
  * a loader function, which exposes the result of the loading operation via signals.
@@ -19,7 +20,7 @@ import { Injector } from '../di/injector';
19
20
  *
20
21
  * @see [Async reactivity with resources](guide/signals/resource)
21
22
  *
22
- * @experimental 19.0
23
+ * @publicApi 22.0
23
24
  */
24
25
  export declare function resource<T, R>(options: ResourceOptions<T, R> & {
25
26
  defaultValue: NoInfer<T>;
@@ -32,13 +33,16 @@ export declare function resource<T, R>(options: ResourceOptions<T, R> & {
32
33
  * `resource` will cancel in-progress loads via the `AbortSignal` when destroyed or when a new
33
34
  * request object becomes available, which could prematurely abort mutations.
34
35
  *
35
- * @experimental 19.0
36
+ * @publicApi 22.0
36
37
  * @see [Async reactivity with resources](guide/signals/resource)
37
38
  */
38
39
  export declare function resource<T, R>(options: ResourceOptions<T, R>): ResourceRef<T | undefined>;
40
+ type ResourceInternalStatus = 'idle' | 'loading' | 'resolved' | 'local';
39
41
  type WrappedRequest = {
40
- request: unknown;
42
+ request?: unknown;
41
43
  reload: number;
44
+ status?: ResourceInternalStatus;
45
+ error?: Error;
42
46
  };
43
47
  /**
44
48
  * Base class which implements `.value` as a `WritableSignal` by delegating `.set` and `.update`.
@@ -48,12 +52,14 @@ declare abstract class BaseWritableResource<T> implements WritableResource<T> {
48
52
  abstract readonly status: Signal<ResourceStatus>;
49
53
  abstract readonly error: Signal<Error | undefined>;
50
54
  abstract reload(): boolean;
51
- constructor(value: Signal<T>);
55
+ readonly isLoading: Signal<boolean>;
56
+ constructor(value: Signal<T>, debugName: string | undefined);
52
57
  abstract set(value: T): void;
53
58
  private readonly isError;
54
59
  update(updateFn: (value: T) => T): void;
55
- readonly isLoading: Signal<boolean>;
56
60
  private readonly isValueDefined;
61
+ private _snapshot;
62
+ get snapshot(): Signal<ResourceSnapshot<T>>;
57
63
  hasValue(): this is ResourceRef<Exclude<T, undefined>>;
58
64
  asReadonly(): Resource<T>;
59
65
  }
@@ -63,6 +69,8 @@ declare abstract class BaseWritableResource<T> implements WritableResource<T> {
63
69
  export declare class ResourceImpl<T, R> extends BaseWritableResource<T> implements ResourceRef<T> {
64
70
  private readonly loaderFn;
65
71
  private readonly equal;
72
+ private readonly debugName;
73
+ private transferCacheKey;
66
74
  private readonly pendingTasks;
67
75
  /**
68
76
  * The current state of the resource. Status, value, and error are derived from this.
@@ -78,9 +86,10 @@ export declare class ResourceImpl<T, R> extends BaseWritableResource<T> implemen
78
86
  private resolvePendingTask;
79
87
  private destroyed;
80
88
  private unregisterOnDestroy;
81
- constructor(request: () => R, loaderFn: ResourceStreamingLoader<T, R>, defaultValue: T, equal: ValueEqualityFn<T> | undefined, injector: Injector);
82
89
  readonly status: Signal<ResourceStatus>;
83
90
  readonly error: Signal<Error | undefined>;
91
+ private readonly transferState;
92
+ constructor(request: (ctx: ResourceParamsContext) => R, loaderFn: ResourceStreamingLoader<T, R>, defaultValue: T, equal: ValueEqualityFn<T> | undefined, debugName: string | undefined, injector: Injector, transferCacheKey: StateKey<T> | undefined, getInitialStream?: (request: R) => Signal<ResourceStreamItem<T>> | undefined);
84
93
  /**
85
94
  * Called either directly via `WritableResource.set` or via `.value.set()`.
86
95
  */
@@ -91,4 +100,19 @@ export declare class ResourceImpl<T, R> extends BaseWritableResource<T> implemen
91
100
  private abortInProgressLoad;
92
101
  }
93
102
  export declare function encapsulateResourceError(error: unknown): Error;
103
+ export declare function isErrorLike(error: unknown): error is Error;
104
+ export declare class ResourceValueError extends Error {
105
+ constructor(error: Error);
106
+ }
107
+ /**
108
+ * Chains the value of another resource into the params of the current resource, returning the value
109
+ * of the other resource if it is available, or propagating the status to the current resource if it
110
+ * is not.
111
+ */
112
+ export declare function chain<T>(resource: Resource<T>): T;
113
+ export declare const paramsContext: ResourceParamsContext;
114
+ export declare function isInParamsFunction(): boolean;
115
+ export declare function setInParamsFunction(value: boolean): void;
116
+ export declare function invalidResourceCreationInParams(): Error;
117
+ export declare function rethrowFatalErrors(error: unknown): void;
94
118
  export {};
@@ -0,0 +1,89 @@
1
+ /**
2
+ * @license
3
+ * Copyright Google LLC All Rights Reserved.
4
+ *
5
+ * Use of this source code is governed by an MIT-style license that can be
6
+ * found in the LICENSE file at https://angular.dev/license
7
+ */
8
+ /**
9
+ * A type-safe key to use with `TransferState`.
10
+ *
11
+ * Example:
12
+ *
13
+ * ```ts
14
+ * const COUNTER_KEY = makeStateKey<number>('counter');
15
+ * let value = 10;
16
+ *
17
+ * transferState.set(COUNTER_KEY, value);
18
+ * ```
19
+ *
20
+ * @publicApi
21
+ */
22
+ export type StateKey<T> = string & {
23
+ __not_a_string: never;
24
+ __value_type?: T;
25
+ };
26
+ /**
27
+ * Create a `StateKey<T>` that can be used to store value of type T with `TransferState`.
28
+ *
29
+ * Example:
30
+ *
31
+ * ```ts
32
+ * const COUNTER_KEY = makeStateKey<number>('counter');
33
+ * let value = 10;
34
+ *
35
+ * transferState.set(COUNTER_KEY, value);
36
+ * ```
37
+ *
38
+ * @publicApi
39
+ */
40
+ export declare function makeStateKey<T = void>(key: string): StateKey<T>;
41
+ /**
42
+ * A key value store that is transferred from the application on the server side to the application
43
+ * on the client side.
44
+ *
45
+ * The `TransferState` is available as an injectable token.
46
+ * On the client, just inject this token using DI and use it, it will be lazily initialized.
47
+ * On the server it's already included if `renderApplication` function is used. Otherwise, import
48
+ * the `ServerTransferStateModule` module to make the `TransferState` available.
49
+ *
50
+ * The values in the store are serialized/deserialized using JSON.stringify/JSON.parse. So only
51
+ * boolean, number, string, null and non-class objects will be serialized and deserialized in a
52
+ * non-lossy manner.
53
+ *
54
+ * @publicApi
55
+ */
56
+ export declare class TransferState {
57
+ /** @nocollapse */
58
+ static ɵprov: import("./di/interface/defs").ɵɵInjectableDeclaration<TransferState>;
59
+ private onSerializeCallbacks;
60
+ /**
61
+ * Get the value corresponding to a key. Return `defaultValue` if key is not found.
62
+ */
63
+ get<T>(key: StateKey<T>, defaultValue: T): T;
64
+ /**
65
+ * Set the value corresponding to a key.
66
+ */
67
+ set<T>(key: StateKey<T>, value: T): void;
68
+ /**
69
+ * Remove a key from the store.
70
+ */
71
+ remove<T>(key: StateKey<T>): void;
72
+ /**
73
+ * Test whether a key exists in the store.
74
+ */
75
+ hasKey<T>(key: StateKey<T>): boolean;
76
+ /**
77
+ * Indicates whether the state is empty.
78
+ */
79
+ get isEmpty(): boolean;
80
+ /**
81
+ * Register a callback to provide the value for a key when `toJson` is called.
82
+ */
83
+ onSerialize<T>(key: StateKey<T>, callback: () => T): void;
84
+ /**
85
+ * Serialize the current state of the store to JSON.
86
+ */
87
+ toJson(): string;
88
+ }
89
+ export declare function retrieveTransferredState(doc: Document, appId: string): Record<string, unknown | undefined>;
@@ -0,0 +1,24 @@
1
+ /**
2
+ * @license
3
+ * Copyright Google LLC All Rights Reserved.
4
+ *
5
+ * Use of this source code is governed by an MIT-style license that can be
6
+ * found in the LICENSE file at https://angular.dev/license
7
+ */
8
+ /**
9
+ * An ES Module object with a default export of the given type.
10
+ *
11
+ * @see {@link injectAsync}
12
+ * @see [Route#loadComponent](/api/router/Route#loadComponent)
13
+ * @see [LoadChildrenCallback](/api/router/LoadChildrenCallback)
14
+ *
15
+ * @publicApi
16
+ */
17
+ export interface DefaultExport<T> {
18
+ /**
19
+ * Default exports are bound under the name `"default"`, per the ES Module spec:
20
+ * https://tc39.es/ecma262/#table-export-forms-mapping-to-exportentry-records
21
+ */
22
+ default: T;
23
+ }
24
+ export declare function maybeUnwrapDefaultExport<T>(input: T | DefaultExport<T>): T;