UNPKG

2.56 kBTypeScriptView Raw
1import { Trie } from "@wry/trie";
2import { CommonCache } from "@wry/caches";
3import { Entry } from "./entry.js";
4import type { NoInfer } from "./helpers.js";
5export { bindContext, noContext, nonReactive, setTimeout, asyncFromGen, Slot, } from "./context.js";
6export { dep, OptimisticDependencyFunction } from "./dep.js";
7export declare function defaultMakeCacheKey(...args: any[]): object;
8export { Trie as KeyTrie };
9export type OptimisticWrapperFunction<TArgs extends any[], TResult, TKeyArgs extends any[] = TArgs, TCacheKey = any> = ((...args: TArgs) => TResult) & {
10 readonly size: number;
11 options: OptionsWithCacheInstance<TArgs, TKeyArgs, TCacheKey>;
12 dirty: (...args: TKeyArgs) => void;
13 dirtyKey: (key: TCacheKey | undefined) => void;
14 peek: (...args: TKeyArgs) => TResult | undefined;
15 peekKey: (key: TCacheKey | undefined) => TResult | undefined;
16 forget: (...args: TKeyArgs) => boolean;
17 forgetKey: (key: TCacheKey | undefined) => boolean;
18 getKey: (...args: TArgs) => TCacheKey | undefined;
19 makeCacheKey: (...args: TKeyArgs) => TCacheKey | undefined;
20};
21export { CommonCache };
22export interface CommonCacheConstructor<TCacheKey, TResult, TArgs extends any[]> extends Function {
23 new <K extends TCacheKey, V extends Entry<TArgs, TResult>>(max?: number, dispose?: (value: V, key?: K) => void): CommonCache<K, V>;
24}
25export type OptimisticWrapOptions<TArgs extends any[], TKeyArgs extends any[] = TArgs, TCacheKey = any, TResult = any> = {
26 max?: number;
27 keyArgs?: (...args: TArgs) => TKeyArgs;
28 makeCacheKey?: (...args: NoInfer<TKeyArgs>) => TCacheKey | undefined;
29 normalizeResult?: (newer: TResult, older: TResult) => TResult;
30 subscribe?: (...args: TArgs) => void | (() => any);
31 cache?: CommonCache<NoInfer<TCacheKey>, Entry<NoInfer<TArgs>, NoInfer<TResult>>> | CommonCacheConstructor<NoInfer<TCacheKey>, NoInfer<TResult>, NoInfer<TArgs>>;
32};
33export interface OptionsWithCacheInstance<TArgs extends any[], TKeyArgs extends any[] = TArgs, TCacheKey = any, TResult = any> extends OptimisticWrapOptions<TArgs, TKeyArgs, TCacheKey, TResult> {
34 cache: CommonCache<NoInfer<TCacheKey>, Entry<NoInfer<TArgs>, NoInfer<TResult>>>;
35}
36export declare function wrap<TArgs extends any[], TResult, TKeyArgs extends any[] = TArgs, TCacheKey = any>(originalFunction: (...args: TArgs) => TResult, { max, keyArgs, makeCacheKey, normalizeResult, subscribe, cache: cacheOption, }?: OptimisticWrapOptions<TArgs, TKeyArgs, TCacheKey, TResult>): OptimisticWrapperFunction<TArgs, TResult, TKeyArgs, TCacheKey>;
37
\No newline at end of file