import Api from "kinto-http" ; import Collection from "./collection" ; import BaseAdapter from "./adapters/base" ; import { IdSchema , RemoteTransformer , Hooks , RecordStatus , Emitter , } from "./types" ; const DEFAULT_BUCKET_NAME = "default" ; const DEFAULT_REMOTE = "http://localhost:8888/v1" ; const DEFAULT_RETRY = 1 ; 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 : KintoBaseOptions ; private _api : Api | null ; public events ? : Emitter ; /**
     * Provides a public access to the base adapter class. Users can create a
     * custom DB adapter by extending  BaseAdapter .
     *
     *  type { Object } static get adapters ( ) { return { BaseAdapter : BaseAdapter , } ; } type { Object } static get syncStrategy ( ) { return Collection . strategy ; } param { Object } options constructor ( options = { } ) { const defaults = { bucket : DEFAULT_BUCKET_NAME , remote : DEFAULT_REMOTE , retry : DEFAULT_RETRY , } ; this . _options = { ... defaults , ... options } ; if ( ! this . _options . adapter ) { throw new Error ( "No adapter provided" ) ; } this . _api = null ; type { EventEmitter } this . events = this . _options . events ; } get ApiClass ( ) : typeof Api { throw new Error ( "ApiClass() must be implemented by subclasses." ) ; } type { KintoClient } get api ( ) { const { events , headers , remote , requestMode , retry , timeout } = this . _options ; if ( ! this . _api ) { this . _api = new this . ApiClass ( remote ! , { events , headers , requestMode , retry , timeout , } ) ; } return this . _api ; } /**
     * Creates a  Collection instance. The second (optional) parameter
     * will set collection-level options like e.g. `remoteTransformers`.
     *
     *  param { String } collName param options param { Object } options . idSchema param { Object } options . remoteTransformers param { Object } options . hooks param { Object } options . localFields return { Collection } collection < C extends { id : string ; last_modified ? : number ; _status ? : RecordStatus ; } = any > ( collName , options = { } ) { if ( ! collName ) { throw new Error ( "missing collection name" ) ; } const { bucket , events , adapter , adapterOptions } = { ... this . _options , ... options , } ; const { idSchema , remoteTransformers , hooks , localFields } = options ; return new Collection < C > ( bucket ! , collName , this , { events , adapter , adapterOptions , idSchema , remoteTransformers , hooks , localFields , } ) ; } }