UNPKG

@angular/fire

Version:

The official library for Firebase and Angular

121 lines (120 loc) 5.17 kB
import { InjectionToken, NgZone } from '@angular/core'; import { Observable } from 'rxjs'; import { AssociatedReference, CollectionReference, DocumentReference, PersistenceSettings, QueryFn, QueryGroupFn, Settings } from './interfaces'; import { AngularFirestoreDocument } from './document/document'; import { AngularFirestoreCollection } from './collection/collection'; import { AngularFirestoreCollectionGroup } from './collection-group/collection-group'; import { FirebaseAppConfig, FirebaseOptions, ɵAngularFireSchedulers } from '@angular/fire'; import { firestore } from 'firebase/app'; import 'firebase/firestore'; /** * The value of this token determines whether or not the firestore will have persistance enabled */ export declare const ENABLE_PERSISTENCE: InjectionToken<boolean>; export declare const PERSISTENCE_SETTINGS: InjectionToken<firestore.PersistenceSettings>; export declare const SETTINGS: InjectionToken<firestore.Settings>; /** * A utility methods for associating a collection reference with * a query. * * @param collectionRef - A collection reference to query * @param queryFn - The callback to create a query * * Example: * const { query, ref } = associateQuery(docRef.collection('items'), ref => { * return ref.where('age', '<', 200); * }); */ export declare function associateQuery(collectionRef: CollectionReference, queryFn?: (ref: any) => any): AssociatedReference; /** * AngularFirestore Service * * This service is the main entry point for this feature module. It provides * an API for creating Collection and Reference services. These services can * then be used to do data updates and observable streams of the data. * * Example: * * import { Component } from '@angular/core'; * import { AngularFirestore, AngularFirestoreCollection, AngularFirestoreDocument } from '@angular/fire/firestore'; * import { Observable } from 'rxjs/Observable'; * import { from } from 'rxjs/observable'; * * @Component({ * selector: 'app-my-component', * template: ` * <h2>Items for {{ (profile | async)?.name }} * <ul> * <li *ngFor="let item of items | async">{{ item.name }}</li> * </ul> * <div class="control-input"> * <input type="text" #itemname /> * <button (click)="addItem(itemname.value)">Add Item</button> * </div> * ` * }) * export class MyComponent implements OnInit { * * // services for data operations and data streaming * private readonly itemsRef: AngularFirestoreCollection<Item>; * private readonly profileRef: AngularFirestoreDocument<Profile>; * * // observables for template * items: Observable<Item[]>; * profile: Observable<Profile>; * * // inject main service * constructor(private readonly afs: AngularFirestore) {} * * ngOnInit() { * this.itemsRef = afs.collection('items', ref => ref.where('user', '==', 'davideast').limit(10)); * this.items = this.itemsRef.valueChanges().map(snap => snap.docs.map(data => doc.data())); * // this.items = from(this.itemsRef); // you can also do this with no mapping * * this.profileRef = afs.doc('users/davideast'); * this.profile = this.profileRef.valueChanges(); * } * * addItem(name: string) { * const user = 'davideast'; * this.itemsRef.add({ name, user }); * } * } */ export declare class AngularFirestore { readonly firestore: firestore.Firestore; readonly persistenceEnabled$: Observable<boolean>; readonly schedulers: ɵAngularFireSchedulers; readonly keepUnstableUntilFirst: <T>(obs: Observable<T>) => Observable<T>; /** * Each Feature of AngularFire has a FirebaseApp injected. This way we * don't rely on the main Firebase App instance and we can create named * apps and use multiple apps. */ constructor(options: FirebaseOptions, nameOrConfig: string | FirebaseAppConfig | null | undefined, shouldEnablePersistence: boolean | null, settings: Settings | null, platformId: Object, zone: NgZone, persistenceSettings: PersistenceSettings | null); /** * Create a reference to a Firestore Collection based on a path or * CollectionReference and an optional query function to narrow the result * set. */ collection<T>(path: string, queryFn?: QueryFn): AngularFirestoreCollection<T>; collection<T>(ref: CollectionReference, queryFn?: QueryFn): AngularFirestoreCollection<T>; /** * Create a reference to a Firestore Collection Group based on a collectionId * and an optional query function to narrow the result * set. */ collectionGroup<T>(collectionId: string, queryGroupFn?: QueryGroupFn): AngularFirestoreCollectionGroup<T>; /** * Create a reference to a Firestore Document based on a path or * DocumentReference. Note that documents are not queryable because they are * simply objects. However, documents have sub-collections that return a * Collection reference and can be queried. */ doc<T>(path: string): AngularFirestoreDocument<T>; doc<T>(ref: DocumentReference): AngularFirestoreDocument<T>; /** * Returns a generated Firestore Document Id. */ createId(): string; }