import { isFullString } from 'is-what' ; import { FirestoreModuleConfig , FirestorePluginOptions } from '../CreatePlugin' ; import { isCollectionModule } from '@magnetarjs/core' ; import { throwIfInvalidFirestorePath } from './throwFns' ; export function getFirestoreDocPath ( collectionPath , docId , firestoreModuleConfig , firestorePluginOptions ) { let documentPath ; const { firestorePath } = firestoreModuleConfig ; if ( isFullString ( firestorePath ) ) { documentPath = isCollectionModule ( firestorePath ) ? [ firestorePath , docId ] . join ( '/' ) : firestorePath ; } else { const { useModulePathsForFirestore } = firestorePluginOptions ; const modulePath = [ collectionPath , docId ] . join ( '/' ) ; documentPath = ( useModulePathsForFirestore ? modulePath : firestorePath ) as string ; } throwIfInvalidFirestorePath ( documentPath , 'doc' ) ; return documentPath ; } export function getFirestoreCollectionPath ( _collectionPath , firestoreModuleConfig , firestorePluginOptions ) { let collectionPath ; const { firestorePath } = firestoreModuleConfig ; if ( isFullString ( firestorePath ) ) { collectionPath = firestorePath ; } else { const { useModulePathsForFirestore } = firestorePluginOptions ; collectionPath = ( useModulePathsForFirestore ? _collectionPath : firestorePath ) as string ; } throwIfInvalidFirestorePath ( collectionPath , 'collection' ) ; return collectionPath ; }