import admin from 'firebase-admin' ; import { FirestoreSimple } from '../src' ; process . env . GCLOUD_PROJECT = 'firestore-simple-test' ; process . env . FIRESTORE_EMULATOR_HOST = 'localhost:8080' ; admin . initializeApp ( { } ) ; const firestore = admin . firestore ( ) ; const ROOT_PATH = 'example/admin_basic' ; interface User { id : string ; name : string ; age : number ; } const main = async ( ) => { const firestoreSimple = new FirestoreSimple ( firestore ) ; const dao = firestoreSimple . collection < User > ( { path : `${ ROOT_PATH }/user` } ) ; const bobId = await dao . add ( { name : 'bob' , age : 20 } ) ; const bob = await dao . fetch ( bobId ) ; console . log ( bob ) ; if ( ! bob ) return ; await dao . set ( { id : bobId , name : 'bob' , age : 30 , } ) ; const aliceId = await dao . addOrSet ( { name : 'alice' , age : 22 } ) ; await dao . addOrSet ( { id : aliceId , name : 'alice' , age : 30 , } ) ; const alice = await dao . fetch ( aliceId ) ; console . log ( alice ) ; const deletedId = await dao . delete ( bobId ) ; console . log ( deletedId ) ; await dao . delete ( aliceId ) ; const _bulkSetBatch = await dao . bulkSet ( [ { id : '1' , name : 'foo' , age : 1 } , { id : '2' , name : 'bar' , age : 2 } , ] ) ; const users = await dao . fetchAll ( ) ; console . log ( users ) ; const fetchedByQueryUser = await dao . where ( 'age' , '>=' , 1 ) . orderBy ( 'age' ) . limit ( 1 ) . fetch ( ) ; console . log ( fetchedByQueryUser ) ; const _deletedDocBatch = await dao . bulkDelete ( users . map ( ( user ) => user . id ) ) ; } ; main ( ) ;