import type { Firestore } from 'firebase/firestore' ; import { PluginInstance , MagnetarPlugin , WhereClause , OrderByClause , Limit } from '@magnetarjs/core' ; import { insertActionFactory } from './actions/insert' ; import { writeActionFactory } from './actions/mergeAssignReplace' ; import { deletePropActionFactory } from './actions/deleteProp' ; import { deleteActionFactory } from './actions/delete' ; import { fetchActionFactory } from './actions/fetch' ; import { streamActionFactory } from './actions/stream' ; import { revertActionFactory } from './actions/revert' ; import { batchSyncFactory } from './helpers/batchSync' ; export interface FirestorePluginOptions { example db : Firestore ; /**
     * When this is true, the "modulePath" will be used as firestorePath to sync the data to. Eg. `collection('todos')` will sync data to `todos` on firestore. When this is false (default) the firestorePath must be provided like so: `collection('todos', { firestorePath: 'myTodos' })`
     */ useModulePathsForFirestore ? : boolean ; /**
     * Defaults to 1000ms. The amount of milliseconds before an action is synced to Firestore. Every time a consecutive action is triggered the debounce will reset.
     */ syncDebounceMs ? : number ; /**
     * Logs extra information in the developer console every time it interacts with the server.
     *
     * Be sure to disable this on production!
     */ debug ? : boolean ; } export interface FirestoreModuleConfig { firestorePath ? : string ; where ? : WhereClause [ ] ; orderBy ? : OrderByClause [ ] ; limit ? : Limit ; syncDebounceMs ? : number ; } function firestorePluginOptionsWithDefaults ( firestorePluginOptions ) { return { syncDebounceMs : 1000 , useModulePathsForFirestore : true , debug : false , ... firestorePluginOptions , } ; } example export const CreatePlugin = ( firestorePluginOptions ) : PluginInstance => { const pluginOptions = firestorePluginOptionsWithDefaults ( firestorePluginOptions ) ; const batchSync = batchSyncFactory ( pluginOptions ) ; const fetch = fetchActionFactory ( pluginOptions ) ; const stream = streamActionFactory ( pluginOptions ) ; const insert = insertActionFactory ( batchSync , pluginOptions ) ; const _merge = writeActionFactory ( batchSync , pluginOptions , 'merge' ) ; const assign = writeActionFactory ( batchSync , pluginOptions , 'assign' ) ; const replace = writeActionFactory ( batchSync , pluginOptions , 'replace' ) ; const deleteProp = deletePropActionFactory ( batchSync , pluginOptions ) ; const _delete = deleteActionFactory ( batchSync , pluginOptions ) ; const actions = { fetch , stream , insert , merge : _merge , assign , replace , deleteProp , delete : _delete , } ; const revert = revertActionFactory ( actions , pluginOptions ) ; const instance = { revert , actions , syncPendingWrites : batchSync . forceSyncEarly , } ; return instance ; } ;