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_pagination' ; interface Doc { id : string ; name : string ; order : number ; } const main = async ( ) => { const docs = [ { id : '1' , name : 'a' , order : 1 } , { id : '2' , name : 'b' , order : 2 } , { id : '3' , name : 'b' , order : 3 } , { id : '4' , name : 'c' , order : 4 } , { id : '5' , name : 'd' , order : 5 } , { id : '6' , name : 'd' , order : 6 } , { id : '7' , name : 'f' , order : 7 } , ] ; const firestoreSimple = new FirestoreSimple ( firestore ) ; const dao = firestoreSimple . collection < Doc > ( { path : `${ ROOT_PATH }/docs` } ) ; await dao . bulkSet ( docs ) ; let result ; console . log ( '--Real pagination sample--' ) ; const query = dao . orderBy ( 'name' ) . limit ( 2 ) ; result = await query . fetch ( ) ; console . log ( result ) ; const lastVisible = result [ result . length - 1 ] ; const lastVisibleSnapshot = await dao . docRef ( lastVisible . id ) . get ( ) ; result = await query . startAfter ( lastVisibleSnapshot ) . fetch ( ) ; console . log ( result ) ; console . log ( '--startAt--' ) ; result = await dao . orderBy ( 'name' ) . startAt ( 'b' ) . fetch ( ) ; console . log ( result ) ; console . log ( '--startAfter--' ) ; result = await dao . orderBy ( 'name' ) . startAfter ( 'b' ) . fetch ( ) ; console . log ( result ) ; console . log ( '--endAt--' ) ; result = await dao . orderBy ( 'name' ) . endAt ( 'd' ) . fetch ( ) ; console . log ( result ) ; console . log ( '--endBefore--' ) ; result = await dao . orderBy ( 'name' ) . endBefore ( 'd' ) . fetch ( ) ; console . log ( result ) ; console . log ( '--startAt, endBefore--' ) ; result = await dao . orderBy ( 'name' ) . startAt ( 'b' ) . endBefore ( 'f' ) . fetch ( ) ; console . log ( result ) ; console . log ( '--startAt using document snapshot--' ) ; const startSnapshot = await dao . docRef ( '4' ) . get ( ) ; result = await dao . orderBy ( 'name' ) . startAt ( startSnapshot ) . fetch ( ) ; console . log ( result ) ; console . log ( '--endAt multi values--' ) ; result = await dao . orderBy ( 'name' ) . orderBy ( 'order' ) . endAt ( 'd' , 5 ) . fetch ( ) ; console . log ( result ) ; await dao . bulkDelete ( docs . map ( ( doc ) => doc . id ) ) ; } ; main ( ) ;