import type { Selector } from '../Select'; import type { FetchResponse } from '../network'; import type { NormalizedKeyMetadata } from './queryability'; import type { StoreKeySet } from '../store/StoreKeySet'; export declare enum SnapshotState { Fulfilled = "Fulfilled", Unfulfilled = "Unfulfilled", Error = "Error", Pending = "Pending", Stale = "Stale" } export interface SnapshotRefresh { config: unknown; resolve: (config: unknown) => Promise>; } interface BaseSnapshot { recordId: string | NormalizedKeyMetadata; variables: Variables; seenRecords: StoreKeySet; select: Selector; refresh?: SnapshotRefresh; } export interface PendingSnapshot extends BaseSnapshot { state: SnapshotState.Pending; data: Data | undefined; } export interface FulfilledSnapshot extends BaseSnapshot { state: SnapshotState.Fulfilled; data: Data; } export interface StaleSnapshot extends BaseSnapshot { state: SnapshotState.Stale; data: Data; } export interface UnfulfilledSnapshot extends BaseSnapshot { state: SnapshotState.Unfulfilled; data: Data | undefined; missingPaths: StoreKeySet; missingLinks: StoreKeySet; } /** * A FetchResponse that is considered an error (ie: it will be part of an ErrorSnapshot) */ export type FetchErrorResponse = FetchResponse & { errorType: 'fetchResponse'; }; /** * A FetchResponse that is considered an error according to custom adapter logic */ export type AdapterErrorResponse = { errorType: 'adapterError'; error: T; }; /** * An Error where the network adapter failed to get a response from the server. */ export type NetworkAdapterErrorResponse = Error & { errorType: 'networkAdapterError'; }; /** * ErrorResponse is either a server response, or a network adapter error if * we have no response from the server. The "errorType" property is the discriminator * to determine which type of response it is. */ export type ErrorResponse = FetchErrorResponse | AdapterErrorResponse | NetworkAdapterErrorResponse; export interface ErrorSnapshot { state: SnapshotState.Error; error: ErrorResponse; data: undefined; refresh?: SnapshotRefresh; } export type DataSnapshot = FulfilledSnapshot | UnfulfilledSnapshot | StaleSnapshot | PendingSnapshot; /** * Snapshots that can be returned to userland. * These are the snapshot states that return true from luvio.snapshotAvailable() */ export type AvailableSnapshot = FulfilledSnapshot | StaleSnapshot | ErrorSnapshot; export type UnAvailableSnapshot = Exclude, AvailableSnapshot>; export type Snapshot = DataSnapshot | ErrorSnapshot; export {};