kinto
Version:
An Offline-First JavaScript client for Kinto.
104 lines (103 loc) • 3.64 kB
TypeScript
import Api from "./http";
import Collection from "./collection";
import BaseAdapter from "./adapters/base";
import { IdSchema, RemoteTransformer, Hooks, RecordStatus, Emitter } from "./types";
export interface KintoBaseOptions {
remote?: string;
bucket?: string;
events?: Emitter;
adapter?: (dbName: string, options?: {
dbName?: string;
migrateOldData?: boolean;
}) => BaseAdapter<any>;
adapterOptions?: object;
headers?: Record<string, string>;
retry?: number;
requestMode?: RequestMode;
timeout?: number;
}
/**
* KintoBase class.
*/
export default class KintoBase<B extends {
id: string;
last_modified?: number;
_status?: RecordStatus;
}> {
private _options;
private _api;
events?: Emitter;
/**
* Provides a public access to the base adapter class. Users can create a
* custom DB adapter by extending {@link BaseAdapter}.
*
* @type {Object}
*/
static get adapters(): {
BaseAdapter: typeof BaseAdapter;
};
/**
* Synchronization strategies. Available strategies are:
*
* - `MANUAL`: Conflicts will be reported in a dedicated array.
* - `SERVER_WINS`: Conflicts are resolved using remote data.
* - `CLIENT_WINS`: Conflicts are resolved using local data.
*
* @type {Object}
*/
static get syncStrategy(): {
CLIENT_WINS: string;
SERVER_WINS: string;
PULL_ONLY: string;
MANUAL: string;
};
/**
* Constructor.
*
* Options:
* - `{String}` `remote` The server URL to use.
* - `{String}` `bucket` The collection bucket name.
* - `{EventEmitter}` `events` Events handler.
* - `{BaseAdapter}` `adapter` The base DB adapter class.
* - `{Object}` `adapterOptions` Options given to the adapter.
* - `{Object}` `headers` The HTTP headers to use.
* - `{Object}` `retry` Number of retries when the server fails to process the request (default: `1`)
* - `{String}` `requestMode` The HTTP CORS mode to use.
* - `{Number}` `timeout` The requests timeout in ms (default: `5000`).
*
* @param {Object} options The options object.
*/
constructor(options?: KintoBaseOptions);
get ApiClass(): typeof Api;
/**
* The kinto HTTP client instance.
* @type {KintoClient}
*/
get api(): Api;
/**
* Creates a {@link Collection} instance. The second (optional) parameter
* will set collection-level options like e.g. `remoteTransformers`.
*
* @param {String} collName The collection name.
* @param {Object} [options={}] Extra options or override client's options.
* @param {Object} [options.idSchema] IdSchema instance (default: UUID)
* @param {Object} [options.remoteTransformers] Array<RemoteTransformer> (default: `[]`])
* @param {Object} [options.hooks] Array<Hook> (default: `[]`])
* @param {Object} [options.localFields] Array<Field> (default: `[]`])
* @return {Collection}
*/
collection<C extends {
id: string;
last_modified?: number;
_status?: RecordStatus;
} = any>(collName: string, options?: {
adapter?: (dbName: string, options?: {
dbName?: string;
migrateOldData?: boolean;
}) => BaseAdapter<C>;
idSchema?: IdSchema;
remoteTransformers?: RemoteTransformer[];
hooks?: Hooks<C>;
localFields?: string[];
}): Collection<C>;
}