import type { AdapterRequestPriority } from './AdapterRequestContext'; import type { Luvio } from './Root'; import type { Store, StoreLink } from './interfaces/Store'; import type { NormalizedKeyMetadata } from './interfaces/queryability'; interface Params { [key: string]: string | number | boolean | string[] | number[] | boolean[] | Array> | Record | undefined | null; } export interface Headers { [name: string]: string; } interface IngestPathWithParent

{ parent: { data: P; key: string | NormalizedKeyMetadata; existing: P | undefined; }; propertyName: Exclude; } interface IngestPathNoParent { parent: null; propertyName: null; } export type IngestPath

= { fullPath: string | NormalizedKeyMetadata; ttl?: number; } & (IngestPathNoParent | IngestPathWithParent

); export type ResourceIngest = (data: any, path: IngestPath, luvio: Luvio, store: Store, timestamp: number) => StoreLink; export interface ResourceRequest { baseUri: string; basePath: string; method: LuvioRequestMethod; body: any | null | FormData; queryParams: Params; urlParams: Params; headers: Headers; priority: NetworkRequestPriority; fulfill?: (existing: ResourceRequest, incoming: ResourceRequest) => boolean; } export type NetworkRequestPriority = 'background' | 'normal' | 'high'; export type LuvioRequestMethod = 'get' | 'patch' | 'post' | 'put' | 'delete'; export declare function adapterToNetworkPriority(priority: AdapterRequestPriority | undefined): NetworkRequestPriority; export type ResourceRequestOverride = Partial>; /** * A context object that is included with any call to the network adapter. */ export interface ResourceRequestContext { requestCorrelator?: unknown; luvioRequestMethod?: LuvioRequestMethod; sourceContext?: unknown; } /** * The network adapter implementation must have the following behaviors: * - All responses should result in a resolved promise * - If the network adapter cannot reach the server then reject the promise with an Error. * - FetchResponse.body must not be frozen (must be mutable) * - If a {@link FileReference} is part of a {@link ResourceRequest} body * then the network adapter needs to swap in the real {@link File} * - If the {@link ResourceRequest} body is of type {@link FormData} then * the network adapter needs to construct a valid multipart/form-data request * before making the network call based on the namedEntries in {@link FormData} * @param resourceRequest: the resource request describing the network call * @param resourceRequestContext: optional context object provided with the resource request * @throws {Error} Could not get a response from the server. */ export type NetworkAdapter = (resourceRequest: ResourceRequest, resourceRequestContext: ResourceRequestContext) => Promise>; export declare enum HttpStatusCode { Ok = 200, Created = 201, NoContent = 204, NotModified = 304, BadRequest = 400, Unauthorized = 401, Forbidden = 403, NotFound = 404, TooManyRequests = 429, ServerError = 500, ServiceUnavailable = 503, GatewayTimeout = 504 } export interface FetchResponse { status: HttpStatusCode; body: T; statusText: string; ok: boolean; headers: Headers; } /** * A representation of a File - useful as a config input for adapters that upload * multipart/form-data. If an adapter takes in a File as a config input then the * adapter likely needs to construct {@link FormData} for the request body in its * createResourceParams method, where one of the namedEntries uses the File as its value. * * Modeled after the web API: https://developer.mozilla.org/en-US/docs/Web/API/File */ export interface File { /** * A string, containing the name of the file without path, such as "My Resume.rtf". */ name: string; /** * The number of bytes of data contained within the File. */ size: number; /** * A string, containing the media type(MIME) indicating the type of the file, * for example "image/png" for PNG images. */ type: string; /** * Gets the contents of the File as binary data contained in an ArrayBuffer. */ arrayBuffer(): Promise; } /** * A reference to a File that is managed in userland code (ie: outside the adapter). * If an adapter uses this for a config input it is likely that the injected * {@link NetworkAdapter} needs to check any outgoing {@link ResourceRequest} body * to see if a FileReference is present, and if so swap in the real File into the * request body before making the network request. It is the responsibility of * userland code to provide a network adapter that can look up a File given a * FileReference (for example, via some sort of "binary cache" service). */ export interface FileReference extends Omit { isFileReference: true; handle: string; } /** * A representation of FormData - useful when constructing POST bodies that are of * Content-Type: multipart/form-data. If an adapter uses this FormData then the injected * {@link NetworkAdapter} needs to check any outgoing {@link ResourceRequest} body * for this type and handle it appropriately. For example, a fetch-based browser network * adapter would want to turn this type into a Web FormData object by looping through * each item in namedEntries and calling append(). * * Modeled after the web API: https://developer.mozilla.org/en-US/docs/Web/API/FormData */ export interface FormData { namedEntries: { name: string; value: FormDataEntryValue; }[]; } export type FormDataEntryValue = string | File | FileReference; /** * A type guard function for determining if an unknown object is a {@link FormData} */ export declare function isFormData(obj: unknown): obj is FormData; /** * A type guard function for determining if an unknown object is a {@link FileReference} */ export declare function isFileReference(entryValue: unknown): entryValue is FileReference; export {};