import { Datastore , DatastoreID , DocMetaSnapshotEvent , DocMetaSnapshotEventListener , ErrorListener , InitResult , SnapshotResult } from './Datastore' ; import { DeleteResult } from './Datastore' ; import { WriteOpts } from './Datastore' ; import { Datastores } from './Datastores' ; import { DelegatedDatastore } from './DelegatedDatastore' ; import { IEventDispatcher , SimpleReactor } from '../reactor/SimpleReactor' ; import { Logger } from 'polar-shared/src/logger/Logger' ; import { DocMetaFileRef } from './DocMetaRef' ; import { DatastoreMutation } from './DatastoreMutation' ; import { DefaultDatastoreMutation } from './DatastoreMutation' ; import { IDocInfo } from 'polar-shared/src/metadata/IDocInfo' ; import { DatastoreMutations } from './DatastoreMutations' ; const log = Logger . create ( ) ; Deprecated export class RemoteDatastore extends DelegatedDatastore { private readonly docMetaSnapshotEventDispatcher : IEventDispatcher < DocMetaSnapshotEvent > = new SimpleReactor ( ) ; public readonly id : DatastoreID ; constructor ( datastore ) { super ( datastore ) ; this . id = 'remote:' + datastore . id ; } public async snapshot ( listener ) { return Datastores . createCommittedSnapshot ( this , listener ) ; } /**
     * Init the datastore, potentially reading files of disk, the network, etc.
     */ public async init ( errorListener ? ) { await super . init ( ) ; if ( this . docMetaSnapshotEventDispatcher . size ( ) > 0 ) { this . snapshot ( async ( event ) => this . docMetaSnapshotEventDispatcher . dispatchEvent ( event ) ) . catch ( err => log . error ( err ) ) ; } return { } ; } /**
     * Delegate handle the mutations in the renderer process.
     */ public write ( fingerprint , data , docInfo , opts = { } ) { const datastoreMutation = opts . datastoreMutation || new DefaultDatastoreMutation ( ) ; opts = { ... opts , datastoreMutation : undefined } ; const writeDelegate = async ( ) => { return this . delegate . write ( fingerprint , data , docInfo , opts ) ; } ; return DatastoreMutations . handle ( ( ) => writeDelegate ( ) , datastoreMutation , ( ) => true ) ; } /**
     * Delegate handle the mutations in the renderer process.
     */ public async delete ( docMetaFileRef , datastoreMutation = new DefaultDatastoreMutation ( ) ) { const syncMutation = new DefaultDatastoreMutation < boolean > ( ) ; const result = await DatastoreMutations . handle ( ( ) => this . delegate . delete ( docMetaFileRef , syncMutation ) , datastoreMutation , ( ) => true ) ; return result ; } /**
     * An event listener to listen to the datastore while operating on both
     * the underlying datastores to discover when documents are discovered
     * without having to re-read the datastore after it's been initialized.
     */ public addDocMetaSnapshotEventListener ( docMetaSnapshotEventListener ) { this . docMetaSnapshotEventDispatcher . addEventListener ( docMetaSnapshotEventListener ) ; } }