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; adapterOptions?: object; headers?: Record; retry?: number; requestMode?: RequestMode; timeout?: number; } /** * KintoBase class. */ export default class KintoBase { 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 (default: `[]`]) * @param {Object} [options.hooks] Array (default: `[]`]) * @param {Object} [options.localFields] Array (default: `[]`]) * @return {Collection} */ collection(collName: string, options?: { adapter?: (dbName: string, options?: { dbName?: string; migrateOldData?: boolean; }) => BaseAdapter; idSchema?: IdSchema; remoteTransformers?: RemoteTransformer[]; hooks?: Hooks; localFields?: string[]; }): Collection; }