kinto
Version:
An Offline-First JavaScript client for Kinto.
218 lines (217 loc) • 6.79 kB
TypeScript
export declare const RE_RECORD_ID: RegExp;
/**
* Sorts records in a list according to a given ordering.
*
* @param {String} order The ordering, eg. `-last_modified`.
* @param {Array} list The collection to order.
* @return {Array}
*/
export declare function sortObjects<T extends {
[key: string]: any;
}>(order: string, list: T[]): T[];
/**
* Test if a single object matches all given filters.
*
* @param {Object} filters The filters object.
* @param {Object} entry The object to filter.
* @return {Boolean}
*/
export declare function filterObject<T extends {
[key: string]: any;
}>(filters: {
[key: string]: any;
}, entry: T): boolean;
/**
* Filters records in a list matching all given filters.
*
* @param {Object} filters The filters object.
* @param {Array} list The collection to filter.
* @return {Array}
*/
export declare function filterObjects<T extends {
[key: string]: any;
}>(filters: {
[key: string]: any;
}, list: T[]): T[];
/**
* Resolves a list of functions sequentially, which can be sync or async; in
* case of async, functions must return a promise.
*
* @param {Array} fns The list of functions.
* @param {Any} init The initial value.
* @return {Promise}
*/
export declare function waterfall(fns: ((...args: any[]) => unknown)[], init?: unknown): Promise<unknown>;
/**
* Simple deep object comparison function. This only supports comparison of
* serializable JavaScript objects.
*
* @param {Object} a The source object.
* @param {Object} b The compared object.
* @return {Boolean}
*/
export declare function deepEqual(a: any, b: any): boolean;
/**
* Return an object without the specified keys.
*
* @param {Object} obj The original object.
* @param {Array} keys The list of keys to exclude.
* @return {Object} A copy without the specified keys.
*/
export declare function omitKeys<T extends {
[key: string]: unknown;
}, K extends string>(obj: T, keys?: K[]): Omit<T, K>;
export declare function arrayEqual(a: unknown[], b: unknown[]): boolean;
export declare function transformSubObjectFilters(filtersObj: {
[key: string]: any;
}): {};
/**
* Deeply access an object's properties
* @param obj - The object whose property you want to compare
* @param key - A dot notation path to the property you want to compare
*/
export declare function getDeepKey(obj: any, key: string): unknown;
/**
* Chunks an array into n pieces.
*
* @private
* @param {Array} array
* @param {Number} n
* @return {Array}
*/
export declare function partition<T>(array: T[], n: number): T[][];
/**
* Returns a Promise always resolving after the specified amount in milliseconds.
*
* @return Promise<void>
*/
export declare function delay(ms: number): Promise<void>;
interface Entity {
id: string;
}
/**
* Always returns a resource data object from the provided argument.
*
* @private
* @param {Object|String} resource
* @return {Object}
*/
export declare function toDataBody<T extends Entity>(resource: T | string): Entity;
/**
* Transforms an object into an URL query string, stripping out any undefined
* values.
*
* @param {Object} obj
* @return {String}
*/
export declare function qsify(obj: {
[key: string]: any;
}): string;
/**
* Checks if a version is within the provided range.
*
* @param {String} version The version to check.
* @param {String} minVersion The minimum supported version (inclusive).
* @param {String} maxVersion The minimum supported version (exclusive).
* @throws {Error} If the version is outside of the provided range.
*/
export declare function checkVersion(version: string, minVersion: string, maxVersion: string): void;
type DecoratorReturn = (target: any, key: string, descriptor: TypedPropertyDescriptor<(...args: any[]) => any>) => {
configurable: boolean;
get(): (...args: any) => Promise<any>;
};
/**
* Generates a decorator function ensuring a version check is performed against
* the provided requirements before executing it.
*
* @param {String} min The required min version (inclusive).
* @param {String} max The required max version (inclusive).
* @return {Function}
*/
export declare function support(min: string, max: string): DecoratorReturn;
/**
* Generates a decorator function ensuring that the specified capabilities are
* available on the server before executing it.
*
* @param {Array<String>} capabilities The required capabilities.
* @return {Function}
*/
export declare function capable(capabilities: string[]): DecoratorReturn;
/**
* Generates a decorator function ensuring an operation is not performed from
* within a batch request.
*
* @param {String} message The error message to throw.
* @return {Function}
*/
export declare function nobatch(message: string): DecoratorReturn;
/**
* Returns true if the specified value is an object (i.e. not an array nor null).
* @param {Object} thing The value to inspect.
* @return {bool}
*/
export declare function isObject(thing: unknown): boolean;
interface TypedDataURL {
type: string;
base64: string;
[key: string]: string;
}
/**
* Parses a data url.
* @param {String} dataURL The data url.
* @return {Object}
*/
export declare function parseDataURL(dataURL: string): TypedDataURL;
/**
* Extracts file information from a data url.
* @param {String} dataURL The data url.
* @return {Object}
*/
export declare function extractFileInfo(dataURL: string): {
blob: Blob;
name: string;
};
/**
* Creates a FormData instance from a data url and an existing JSON response
* body.
* @param {String} dataURL The data url.
* @param {Object} body The response body.
* @param {Object} [options={}] The options object.
* @param {Object} [options.filename] Force attachment file name.
* @return {FormData}
*/
export declare function createFormData(dataURL: string, body: {
[key: string]: any;
}, options?: {
filename?: string;
}): FormData;
/**
* Clones an object with all its undefined keys removed.
* @private
*/
export declare function cleanUndefinedProperties(obj: {
[key: string]: any;
}): {
[key: string]: any;
};
/**
* Handle common query parameters for Kinto requests.
*
* @param {String} [path] The endpoint base path.
* @param {Array} [options.fields] Fields to limit the
* request to.
* @param {Object} [options.query={}] Additional query arguments.
*/
export declare function addEndpointOptions(path: string, options?: {
fields?: string[];
query?: {
[key: string]: string;
};
}): string;
/**
* Replace authorization header with an obscured version
*/
export declare function obscureAuthorizationHeader(headers: HeadersInit): {
[key: string]: string;
};
export {};