@squidcloud/client
Version:
A typescript implementation of the Squid client
74 lines (73 loc) • 3.33 kB
TypeScript
/** Advanced options for a Squid `executeFunction` call. */
export interface ExecuteFunctionOptions<ResultType> {
/** The name of the `@executable` function to invoke. */
functionName: string;
/** Optional caching configuration. Reuses results based on argument values. */
caching?: ExecuteFunctionCachingOptions<ResultType>;
/**
* Deduplication config for sharing results of concurrent calls with the same args.
* When set to true a default mode with 'compareArgsByReference' is used.
*/
deduplication?: ConcurrentCallDeduplicationOptions | boolean;
}
/** Defines caching behavior for `executeFunction`. */
export interface ExecuteFunctionCachingOptions<T> {
/** The caching implementation to use. */
cache: ExecuteFunctionCache<T>;
}
/** Interface for a function result cache. */
export interface ExecuteFunctionCache<ValueType> {
/** Retrieves a cached value for the given arguments. */
get(args: Array<unknown>): ExecuteFunctionCacheLookupResult<ValueType>;
/** Caches a result for the given arguments. */
set(args: Array<unknown>, value: ValueType): void;
}
/** Result object returned from a cache lookup. */
export type ExecuteFunctionCacheLookupResult<ValueType> = {
/** The cached value. */
value: ValueType;
/** Indicates that the value was found in the cache. */
found: true;
} | {
/** Indicates that the value was not found in the cache. */
found: false;
};
/** Comparator function type for evaluating argument equality. */
export type ExecuteFunctionArgsComparator = <T>(args1: Array<T>, args2: Array<T>) => boolean;
/** Comparator that checks reference equality of arguments. */
export declare const compareArgsByReference: ExecuteFunctionArgsComparator;
/** Comparator that checks argument equality using serialization. */
export declare const compareArgsBySerializedValue: ExecuteFunctionArgsComparator;
/** A single cached result of a function call. */
export interface ExecuteFunctionCachedResult<T> {
/** Arguments used for the function call. */
args: Array<unknown>;
/** The result value returned by the function. */
result: T;
/** Time (in ms) when the result was cached. */
cacheTimeMillis: number;
}
/** Options for `LastUsedValueExecuteFunctionCache`. */
interface LastUsedValueExecuteFunctionCacheOptions {
/** Argument equality comparator. */
argsComparator: ExecuteFunctionArgsComparator;
/** Validity duration in milliseconds. */
valueExpirationMillis: number;
}
/** Lightweight cache storing only the last computed result. */
export declare class LastUsedValueExecuteFunctionCache<T> implements ExecuteFunctionCache<T> {
private readonly options;
protected cachedEntry?: ExecuteFunctionCachedResult<T>;
/** Creates a new instance of `LastUsedValueExecuteFunctionCache`. */
constructor(options: Partial<LastUsedValueExecuteFunctionCacheOptions>);
/** @inheritdoc */
get(args: Array<unknown>): ExecuteFunctionCacheLookupResult<T>;
/** @inheritdoc */
set(args: Array<unknown>, value: T): void;
}
/** Configuration for deduplicating concurrent function calls. */
export interface ConcurrentCallDeduplicationOptions {
/** Comparator to determine if concurrent calls are equivalent. */
argsComparator: ExecuteFunctionArgsComparator;
}
export {};