import Component from "@glimmer/component"; import { PromiseState, PromiseState as PromiseState$1, RequestLoadingState, RequestLoadingState as RequestLoadingState$1, RequestState, RequestState as RequestState$1, RequestSubscription, createRequestSubscription, getPromiseState, getRequestState } from "@warp-drive-mirror/core/reactive"; import { ContentFeatures, RecoveryFeatures, RequestArgs } from "@warp-drive-mirror/core/signals/-leaked"; import { ComponentLike } from "@glint/template"; import { RequestManager, Store } from "@warp-drive-mirror/core"; import { StructuredErrorDocument } from "@warp-drive-mirror/core/types/request"; import Owner from "@ember/owner"; import { Awaitable } from "@warp-drive-mirror/core/request"; //#region src/-private/request.d.ts interface EmberRequestArgs extends RequestArgs { chrome?: ComponentLike<{ Blocks: { default: []; }; Args: { state: RequestState$1 | null; features: ContentFeatures; }; }>; } interface RequestSignature { Args: EmberRequestArgs; Blocks: { /** * The block to render when the component is idle and waiting to be given a request. * */ idle: []; /** * The block to render when the request is loading. * */ loading: [state: RequestLoadingState$1]; /** * The block to render when the request was cancelled. * */ cancelled: [error: StructuredErrorDocument, features: RecoveryFeatures]; /** * The block to render when the request failed. If this block is not provided, * the error will be rethrown. * * Thus it is required to provide an error block and proper error handling if * you do not want the error to crash the application. */ error: [error: StructuredErrorDocument, features: RecoveryFeatures]; /** * The block to render when the request succeeded. * */ content: [value: RT, features: ContentFeatures]; always: [state: RequestState$1>]; }; } /** * The `` component is a powerful tool for managing data fetching and * state in your Ember application. It provides a declarative approach to reactive * control-flow for managing requests and state in your application. * * The `` component is ideal for handling "boundaries", outside which some * state is still allowed to be unresolved and within which it MUST be resolved. * * ## Request States * * `` has five states, only one of which will be active and rendered at a time. * * - `idle`: The component is waiting to be given a request to monitor * - `loading`: The request is in progress * - `error`: The request failed * - `content`: The request succeeded * - `cancelled`: The request was cancelled * * Additionally, the `content` state has a `refresh` method that can be used to * refresh the request in the background, which is available as a sub-state of * the `content` state. * * As with the `` component, if no error block is provided and the request * rejects, the error will be thrown. Cancellation errors are swallowed instead of * rethrown if no error block or cancellation block is present. * * ```gts * import { Request } from '@warp-drive-mirror/ember'; * * * ``` * * ## Streaming Data * * The loading state exposes the download `ReadableStream` instance for consumption * * ```gts * import { Request } from '@warp-drive-mirror/ember'; * * * ``` * * ## Retry * * Cancelled and error'd requests may be retried by calling the `retry` method. * * Retry will restart the state progression, using the loading, error, cancelled, * and content blocks as appropriate. * * ## Reloading * * The `reload` method will force the request to be fully re-executed, bypassing * cache and restarting the state progression through the loading, error, and * content blocks as appropriate. * * Background reload (refresh) is a special substate of the content state that * allows you to refresh the request in the background. This is useful for when * you want to update the data in the background without blocking the UI. * * Reload and refresh are available as methods on the `content` state. * * ```gts * import { Request } from '@warp-drive-mirror/ember'; * * * ``` * * ## Advanced Reloading * * We can nest our usage of `` to handle more advanced * reloading scenarios. * * ```gts * import { Request } from '@warp-drive-mirror/ember'; * * * ``` * * ## Autorefresh * * `` supports automatic refresh and reload under certain conditions. * * - `online`: This occurs when a browser window or tab comes back to the foreground * after being backgrounded or when the network reports as being online after * having been offline. * - `interval`: This occurs when a specified amount of time has passed. * - `invalid`: This occurs when the store emits a notification that the request * has become invalid. * * You can specify when autorefresh should occur by setting the `autorefresh` arg * to `true` or a comma-separated list of the above values. * * A value of `true` is equivalent to `'online,invalid'`. * * By default, an autorefresh will only occur if the browser was backgrounded or * offline for more than 30s before coming back available. This amount of time can * be tweaked by setting the number of milliseconds via `@autorefreshThreshold`. * * This arg also controls the interval at which the request will be refreshed * if the `interval` autorefresh type is enabled. * * Finally, the behavior of the request initiated by autorefresh can be adjusted * by setting the `autorefreshBehavior` arg to `'refresh'`, `'reload'`, or `'policy'`. * * - `'refresh'`: Refresh the request in the background * - `'reload'`: Force a reload of the request * - `'policy'` (**default**): Let the store's configured CachePolicy decide whether to * reload, refresh, or do nothing. * * More advanced refresh and reload behaviors can be created by passing the reload and * refresh actions into another component. For instance, refresh could be set up on a * timer or on a websocket subscription. * * * ```gts * import { Request } from '@warp-drive-mirror/ember'; * * * ``` * * If a matching request is refreshed or reloaded by any other component, * the `Request` component will react accordingly. * * ## Deduping * * The store dedupes requests by identity. If a request is made for the same identity * from multiple `` components, even if the request is not referentially the * same, only one actual request will be made. * * @category Components * @public */ declare class Request extends Component> { /** * The store instance to use for making requests. If contexts are available, this * will be the `store` on the context, else it will be the store service. * * @internal */ _store: Store; /** * The store or request manager used to make the request, resolved from * either the `@store` arg or the consumed context/service. */ get store(): Store | RequestManager; /** * @private */ _state: RequestSubscription | null; /** * The active {@link RequestSubscription} for this component's request, * created lazily and recreated if the store changes or a `@subscription` is provided. */ get state(): RequestSubscription; /** * The chrome component to use for rendering the request. * * @private */ get Chrome(): ComponentLike<{ Blocks: { default: []; }; Args: { state: RequestState$1 | null; features: ContentFeatures; }; }>; willDestroy(): void; } //#endregion //#region src/-private/await.d.ts interface ThrowSignature { Args: { error: E; }; } /** * The `` component is used to throw an error in a template. * * That's all it does. So don't use it unless the application should * throw an error if it reaches this point in the template. * * ```gts * * ``` * * @category Components * @public */ declare class Throw extends Component> { constructor(owner: Owner, args: ThrowSignature["Args"]); } interface AwaitSignature { Args: { promise: Promise | Awaitable; }; Blocks: { pending: []; error: [error: E]; success: [value: T]; }; } /** * The `` component allow you to utilize reactive control flow * for asynchronous states in your application. * * Await is ideal for handling "boundaries", outside which some state is * still allowed to be unresolved and within which it MUST be resolved. * * ```gts * import { Await } from '@warp-drive-mirror/ember'; * * * ``` * * The `` component requires that error states are properly handled. * * If no error block is provided and the promise rejects, the error will * be thrown. * * @category Components * @public * @badge Component * @title */ declare class Await extends Component> { /** * The reactive {@link PromiseState} for the awaited promise. */ get state(): Readonly>; /** * The rejection reason, once {@link Await.state | state} has errored. */ get error(): E; /** * The resolved value, once {@link Await.state | state} has succeeded. */ get result(): T; } //#endregion export { Await, type ContentFeatures, type PromiseState, type RecoveryFeatures, Request, type RequestLoadingState, type RequestState, Throw, createRequestSubscription, getPromiseState, getRequestState }; //# sourceMappingURL=index.d.ts.map