import { HasId , Encodable , Decodable , OmitId , Firestore , Transaction , WriteBatch } from './types' ; import { Context } from './context' ; import { Collection } from './collection' ; import { Query } from './query' ; import { Converter } from './converter' ; export class FirestoreSimple { context : Context ; constructor ( firestore ) { this . context = new Context ( firestore ) ; } collection < T extends HasId , S = OmitId < T > > ( { path , encode , decode } ) { const factory = new CollectionFactory < T , S > ( { context : this . context , encode , decode , } ) ; return factory . create ( path ) ; } collectionFactory < T extends HasId , S = OmitId < T > > ( { encode , decode } ) { return new CollectionFactory < T , S > ( { context : this . context , encode , decode , } ) ; } collectionGroup < T extends HasId , S = OmitId < T > > ( { collectionId , decode } ) { const query = this . context . firestore . collectionGroup ( collectionId ) ; const converter = new Converter ( { decode } ) ; return new Query < T , S > ( converter , this . context , query ) ; } async runTransaction ( updateFunction ) { return this . context . runTransaction ( updateFunction ) ; } async runBatch ( updateFunction ) { return this . context . runBatch ( updateFunction ) ; } } class CollectionFactory < T extends HasId , S = OmitId < T > > { context : Context ; encode ? : Encodable < T , S > ; decode ? : Decodable < T , S > ; constructor ( { context , encode , decode } ) { this . context = context ; this . encode = encode ; this . decode = decode ; } create ( path ) { return new Collection < T , S > ( { context : this . context , path , encode : this . encode , decode : this . decode , } ) ; } }