1 line
31 KiB
Text
1 line
31 KiB
Text
|
{"version":3,"file":"angular-fire-compat-database.js","sources":["../../../src/compat/database/utils.ts","../../../src/compat/database/observable/fromRef.ts","../../../src/compat/database/list/changes.ts","../../../src/compat/database/list/utils.ts","../../../src/compat/database/list/snapshot-changes.ts","../../../src/compat/database/list/state-changes.ts","../../../src/compat/database/list/audit-trail.ts","../../../src/compat/database/list/data-operation.ts","../../../src/compat/database/list/remove.ts","../../../src/compat/database/list/create-reference.ts","../../../src/compat/database/object/snapshot-changes.ts","../../../src/compat/database/object/create-reference.ts","../../../src/compat/database/database.ts","../../../src/compat/database/database.module.ts","../../../src/compat/database/angular-fire-compat-database.ts"],"sourcesContent":["import { DatabaseReference, FirebaseOperation, FirebaseOperationCases, PathReference } from './interfaces';\nimport firebase from 'firebase/compat/app';\n\nexport function isString(value: any): boolean {\n return typeof value === 'string';\n}\n\nexport function isFirebaseDataSnapshot(value: any): boolean {\n return typeof value.exportVal === 'function';\n}\n\nexport function isNil(obj: any): boolean {\n return obj === undefined || obj === null;\n}\n\nexport function isFirebaseRef(value: any): boolean {\n return typeof value.set === 'function';\n}\n\n/**\n * Returns a database reference given a Firebase App and an\n * absolute or relative path.\n * @param database - Firebase Database\n * @param pathRef - Database path, relative or absolute\n */\nexport function getRef(database: firebase.database.Database, pathRef: PathReference): DatabaseReference {\n // if a db ref was passed in, just return it\n return isFirebaseRef(pathRef) ? pathRef as DatabaseReference\n : database.ref(pathRef as string);\n}\n\nexport function checkOperationCases(item: FirebaseOperation, cases: FirebaseOperationCases): Promise<void> {\n if (isString(item)) {\n return cases.stringCase();\n } else if (isFirebaseRef(item)) {\n return cases.firebaseCase();\n } else if (isFirebaseDataSnapshot(item)) {\n return cases.snapshotCase();\n }\n throw new Error(`Expects a string, snapshot, or reference. Got: ${typeof item}`);\n}\n","import { AngularFireAction, DatabaseQuery, DatabaseSnapshot, ListenEvent } from '../interfaces';\nimport { asyncScheduler, Observable, SchedulerLike } from 'rxjs';\nimport { map, share } from 'rxjs/operators';\n\ninterface SnapshotPrevKey<T> {\n snapshot: DatabaseSnapshot<T>;\n prevKey: string | null | undefined;\n}\n\n/**\n * Create an observable from a Database Reference or Database Query.\n * @param ref Database Reference\n * @param event Listen event type ('value', 'added', 'changed', 'removed', 'moved')\n * @param listenType 'on' or 'once'\n * @param scheduler - Rxjs scheduler\n */\nexport function fromRef<T>(ref: DatabaseQuery,\n event: ListenEvent,\n listenType = 'on',\n scheduler: SchedulerLike = asyncScheduler\n): Observable<AngularFireAction<DatabaseSnapshot<T>>> {\n return new Observable<SnapshotPrevKey<T>>(subscriber => {\n let fn: any | null = null;\n fn = ref[listenType](event, (snapshot, prevKey) => {\n scheduler.schedule(() => {\n subscriber.next({ snapshot, prevKey });\n });\n if (listenType === 'once') {\n scheduler.schedule(() => subscriber.complete());\n }\n }, err => {\n scheduler.schedule(() => subscriber.error(err));\n });\n\n if (listenType === 'on') {\n return {\n unsubscribe() {\n if (fn != null) {\n ref.off(event, fn);\n }\n }\n };\n } else {\n return {\n unsubscribe() {\n }\n };\n }\n }).pipe(\n map(payload => {\n const { snapshot, prevKey } = payload;\n let key: string | null = null;\n if (snapshot.exists()) {\n key = snapshot.key;\n }\n return { type: event, payload: snapshot, prevKey, key }
|