You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

58 lines
2.0 KiB

import FMCStore from "./store.js";
declare const origFetch: typeof fetch;
/**
* A runtime interface with the required subset of built-in runtime functions
* needed for fech-mock-cache, e.g. `env`, `sha256`, `fs`, `path`, `cwd`.
*/
export interface Runtime {
name: string;
env: Record<string, string | undefined>;
sha256(input: string, length?: number): Promise<string>;
fs: {
readFile(path: string): Promise<string>;
writeFile(path: string, content: string): Promise<void>;
mkdir(path: string, options: {
recursive?: boolean;
}): Promise<string | undefined | void>;
};
path: {
join(...paths: string[]): string;
};
cwd: () => string;
}
/**
* Options to control the behaviour of the `fetch()` calls.
* Can be passed with experimental fetch._once(options).
*/
export interface FetchCacheOptions {
id?: string;
}
/**
* Function signature for the created `fetch` / `fetchCache` function.
* Used to make sure the runtime implementation is compliant.
*/
export interface FetchCache {
(urlOrRequest: string | Request | URL | undefined, options: RequestInit | undefined): Promise<Response>;
runtime: Runtime;
_options?: FetchCacheOptions | FetchCacheOptions[];
_store?: FMCStore;
_once: (options: FetchCacheOptions) => void;
}
/**
* Options for `createFetchCache`. `Store` is required. `runtime` is
* generally passed automatically by each runtime entry point. `fetch`
* is optional and defaults to the built-in `fetch` as available at
* module load time.
*/
export interface CreateFetchCacheOptions {
runtime: Runtime;
Store?: typeof FMCStore | [typeof FMCStore, Record<string, unknown>];
fetch?: typeof origFetch;
}
/**
* Creates a new caching fetch implementation. Generally not used directly,
* instead use the same named function provided by the various run-time entry
* points.
*/
export default function createCachingMock({ Store, fetch, runtime, }: CreateFetchCacheOptions): FetchCache;
export {};