UNPKG

@rocketmakers/api-swr

Version:

Rocketmakers front-end library for parsing a generated Typescript API client into a set of configurable React hooks for fetching and mutating data.

22 lines (21 loc) 1.34 kB
/** * Utility functions for caching. * -------------------------------------- * These functions are designed to facilitate param driven caching */ import { CacheKey } from '../@types/global'; /** * Concatenates a cache key string from an array of string arguments. * @param {...(string | undefined)} args - An array of string arguments. * @returns {string} - The concatenated cache key string. */ export declare const cacheKeyConcat: (...args: Array<string | undefined>) => string; /** * Returns the final concatenated cache key for an API call by unwrapping the defined cache key. * NOTE: If any of the cache key params are falsy, this function will return undefined so that the API call is held back until all the cache key params are ready * @param {string} [endpointId] - The ID of the API endpoint. * @param {CacheKey<TArgs>} [cacheKey] - The cache key, which can be a string, an array of strings, or a function that receives the params and returns the built cache key. * @param {TArgs} [params] - The parameters for the API call. * @returns {string|undefined} - The final concatenated cache key, or undefined if the cache key params are not all present. */ export declare const readCacheKey: <TArgs>(endpointId?: string, cacheKey?: CacheKey<TArgs> | undefined, params?: Partial<TArgs> | undefined) => string | undefined;