/** * @license * Copyright Google LLC All Rights Reserved. * * Use of this source code is governed by an MIT-style license that can be * found in the LICENSE file at https://angular.dev/license */ import { Signal, ValueEqualityFn } from '../render3/reactivity/api'; import { WritableSignal } from '../render3/reactivity/signal'; import { Resource, ResourceOptions, ResourceSnapshot, ResourceStatus, ResourceStreamingLoader, ResourceStreamItem, type ResourceParamsContext, type ResourceRef, type WritableResource } from './api'; import { Injector } from '../di/injector'; import { StateKey } from '../transfer_state'; /** * Constructs a `Resource` that projects a reactive request to an asynchronous operation defined by * a loader function, which exposes the result of the loading operation via signals. * * Note that `resource` is intended for _read_ operations, not operations which perform mutations. * `resource` will cancel in-progress loads via the `AbortSignal` when destroyed or when a new * request object becomes available, which could prematurely abort mutations. * * @see [Async reactivity with resources](guide/signals/resource) * * @publicApi 22.0 */ export declare function resource(options: ResourceOptions & { defaultValue: NoInfer; }): ResourceRef; /** * Constructs a `Resource` that projects a reactive request to an asynchronous operation defined by * a loader function, which exposes the result of the loading operation via signals. * * Note that `resource` is intended for _read_ operations, not operations which perform mutations. * `resource` will cancel in-progress loads via the `AbortSignal` when destroyed or when a new * request object becomes available, which could prematurely abort mutations. * * @publicApi 22.0 * @see [Async reactivity with resources](guide/signals/resource) */ export declare function resource(options: ResourceOptions): ResourceRef; type ResourceInternalStatus = 'idle' | 'loading' | 'resolved' | 'local'; type WrappedRequest = { request?: unknown; reload: number; status?: ResourceInternalStatus; error?: Error; }; /** * Base class which implements `.value` as a `WritableSignal` by delegating `.set` and `.update`. */ declare abstract class BaseWritableResource implements WritableResource { readonly value: WritableSignal; abstract readonly status: Signal; abstract readonly error: Signal; abstract reload(): boolean; readonly isLoading: Signal; constructor(value: Signal, debugName: string | undefined); abstract set(value: T): void; private readonly isError; update(updateFn: (value: T) => T): void; private readonly isValueDefined; private _snapshot; get snapshot(): Signal>; hasValue(): this is ResourceRef>; asReadonly(): Resource; } /** * Implementation for `resource()` which uses a `linkedSignal` to manage the resource's state. */ export declare class ResourceImpl extends BaseWritableResource implements ResourceRef { private readonly loaderFn; private readonly equal; private readonly debugName; private transferCacheKey; private readonly pendingTasks; /** * The current state of the resource. Status, value, and error are derived from this. */ private readonly state; /** * Combines the current request with a reload counter which allows the resource to be reloaded on * imperative command. */ protected readonly extRequest: WritableSignal; private readonly effectRef; private pendingController; private resolvePendingTask; private destroyed; private unregisterOnDestroy; readonly status: Signal; readonly error: Signal; private readonly transferState; constructor(request: (ctx: ResourceParamsContext) => R, loaderFn: ResourceStreamingLoader, defaultValue: T, equal: ValueEqualityFn | undefined, debugName: string | undefined, injector: Injector, transferCacheKey: StateKey | undefined, getInitialStream?: (request: R) => Signal> | undefined); /** * Called either directly via `WritableResource.set` or via `.value.set()`. */ set(value: T): void; reload(): boolean; destroy(): void; private loadEffect; private abortInProgressLoad; } export declare function encapsulateResourceError(error: unknown): Error; export declare function isErrorLike(error: unknown): error is Error; export declare class ResourceValueError extends Error { constructor(error: Error); } /** * Chains the value of another resource into the params of the current resource, returning the value * of the other resource if it is available, or propagating the status to the current resource if it * is not. */ export declare function chain(resource: Resource): T; export declare const paramsContext: ResourceParamsContext; export declare function isInParamsFunction(): boolean; export declare function setInParamsFunction(value: boolean): void; export declare function invalidResourceCreationInParams(): Error; export declare function rethrowFatalErrors(error: unknown): void; export {};