abstracted-firebase
Advanced tools
Comparing version 0.16.5 to 0.16.6
import { SerializedQuery } from "serialized-query"; | ||
import { FirebaseDatabase, DataSnapshot, EventType } from "@firebase/database-types"; | ||
import { FirebaseDatabase, DataSnapshot, EventType, Reference } from "@firebase/database-types"; | ||
import { IFirebaseConfig, IEmitter, IMockLoadingState, IFirebaseWatchHandler, IPathSetter } from "./types"; | ||
@@ -44,3 +44,3 @@ declare type Mock = import("firemock").Mock; | ||
/** Get a DB reference for a given path in Firebase */ | ||
ref(path?: string): import("@firebase/database-types").Reference | import("firemock").Reference<any>; | ||
ref(path?: string): Reference; | ||
readonly isMockDb: boolean; | ||
@@ -77,3 +77,3 @@ readonly mock: Mock; | ||
callback(cb: (err: any, pathSetters: IPathSetter<any>[]) => void): void; | ||
execute(): Promise<{}>; | ||
execute(): Promise<void>; | ||
}; | ||
@@ -80,0 +80,0 @@ /** update, non-destructively, at a given path in the database */ |
@@ -121,3 +121,3 @@ "use strict"; | ||
if (!this._mock) { | ||
const e = new Error(`Attempting to use mock getter but _mock is not set!`); | ||
const e = new Error(`Attempting to reference mock() on DB but _mock is not set [ mocking: ${this._mocking} ]!`); | ||
e.name = "AbstractedFirebase::NotAllowed"; | ||
@@ -135,10 +135,3 @@ throw e; | ||
// MOCKING | ||
if (this._mockLoadingState === "loaded") { | ||
return; | ||
} | ||
const timeout = new Date().getTime() + exports.MOCK_LOADING_TIMEOUT; | ||
while (this._mockLoadingState === "loading" && new Date().getTime() < timeout) { | ||
await common_types_1.wait(1); | ||
} | ||
return; | ||
await this.getFireMock(); | ||
} | ||
@@ -258,23 +251,18 @@ else { | ||
async execute() { | ||
return new Promise((resolve, reject) => { | ||
const updateHash = {}; | ||
const fullyQualifiedPaths = mps.map(i => (Object.assign({}, i, { path: [api._basePath, i.path].join("/").replace(/[\/]{2,3}/g, "/") }))); | ||
fullyQualifiedPaths.map(item => { | ||
updateHash[item.path] = item.value; | ||
}); | ||
return ref() | ||
.update(updateHash) | ||
.then(() => { | ||
if (callback) { | ||
callback(null, mps); | ||
resolve(); | ||
} | ||
}) | ||
.catch((e) => { | ||
if (callback) { | ||
callback(e, mps); | ||
} | ||
reject(e); | ||
}); | ||
const updateHash = {}; | ||
const fullyQualifiedPaths = mps.map(i => (Object.assign({}, i, { path: [api._basePath, i.path].join("/").replace(/[\/]{2,3}/g, "/") }))); | ||
fullyQualifiedPaths.map(item => { | ||
updateHash[item.path] = item.value; | ||
}); | ||
try { | ||
await ref().update(updateHash); | ||
if (callback) { | ||
await callback(null, mps); | ||
} | ||
} | ||
catch (e) { | ||
if (callback) { | ||
await callback(e, mps); | ||
} | ||
} | ||
} | ||
@@ -295,3 +283,5 @@ }; | ||
} | ||
handleError_1.handleError(e, "update", { path, value }); | ||
else { | ||
handleError_1.handleError(e, "update", { path, value }); | ||
} | ||
} | ||
@@ -298,0 +288,0 @@ } |
import { SerializedQuery } from "serialized-query"; | ||
import { FirebaseDatabase, DataSnapshot, EventType } from "@firebase/database-types"; | ||
import { FirebaseDatabase, DataSnapshot, EventType, Reference } from "@firebase/database-types"; | ||
import { IFirebaseConfig, IEmitter, IMockLoadingState, IFirebaseWatchHandler, IPathSetter } from "./types"; | ||
@@ -44,3 +44,3 @@ declare type Mock = import("firemock").Mock; | ||
/** Get a DB reference for a given path in Firebase */ | ||
ref(path?: string): import("@firebase/database-types").Reference | import("firemock").Reference<any>; | ||
ref(path?: string): Reference; | ||
readonly isMockDb: boolean; | ||
@@ -77,3 +77,3 @@ readonly mock: Mock; | ||
callback(cb: (err: any, pathSetters: IPathSetter<any>[]) => void): void; | ||
execute(): Promise<{}>; | ||
execute(): Promise<void>; | ||
}; | ||
@@ -80,0 +80,0 @@ /** update, non-destructively, at a given path in the database */ |
@@ -119,3 +119,3 @@ // tslint:disable:no-implicit-dependencies | ||
if (!this._mock) { | ||
const e = new Error(`Attempting to use mock getter but _mock is not set!`); | ||
const e = new Error(`Attempting to reference mock() on DB but _mock is not set [ mocking: ${this._mocking} ]!`); | ||
e.name = "AbstractedFirebase::NotAllowed"; | ||
@@ -133,10 +133,3 @@ throw e; | ||
// MOCKING | ||
if (this._mockLoadingState === "loaded") { | ||
return; | ||
} | ||
const timeout = new Date().getTime() + MOCK_LOADING_TIMEOUT; | ||
while (this._mockLoadingState === "loading" && new Date().getTime() < timeout) { | ||
await wait(1); | ||
} | ||
return; | ||
await this.getFireMock(); | ||
} | ||
@@ -256,23 +249,18 @@ else { | ||
async execute() { | ||
return new Promise((resolve, reject) => { | ||
const updateHash = {}; | ||
const fullyQualifiedPaths = mps.map(i => (Object.assign({}, i, { path: [api._basePath, i.path].join("/").replace(/[\/]{2,3}/g, "/") }))); | ||
fullyQualifiedPaths.map(item => { | ||
updateHash[item.path] = item.value; | ||
}); | ||
return ref() | ||
.update(updateHash) | ||
.then(() => { | ||
if (callback) { | ||
callback(null, mps); | ||
resolve(); | ||
} | ||
}) | ||
.catch((e) => { | ||
if (callback) { | ||
callback(e, mps); | ||
} | ||
reject(e); | ||
}); | ||
const updateHash = {}; | ||
const fullyQualifiedPaths = mps.map(i => (Object.assign({}, i, { path: [api._basePath, i.path].join("/").replace(/[\/]{2,3}/g, "/") }))); | ||
fullyQualifiedPaths.map(item => { | ||
updateHash[item.path] = item.value; | ||
}); | ||
try { | ||
await ref().update(updateHash); | ||
if (callback) { | ||
await callback(null, mps); | ||
} | ||
} | ||
catch (e) { | ||
if (callback) { | ||
await callback(e, mps); | ||
} | ||
} | ||
} | ||
@@ -293,3 +281,5 @@ }; | ||
} | ||
handleError(e, "update", { path, value }); | ||
else { | ||
handleError(e, "update", { path, value }); | ||
} | ||
} | ||
@@ -296,0 +286,0 @@ } |
import { SerializedQuery } from "serialized-query"; | ||
import { FirebaseDatabase, DataSnapshot, EventType } from "@firebase/database-types"; | ||
import { FirebaseDatabase, DataSnapshot, EventType, Reference } from "@firebase/database-types"; | ||
import { IFirebaseConfig, IEmitter, IMockLoadingState, IFirebaseWatchHandler, IPathSetter } from "./types"; | ||
@@ -44,3 +44,3 @@ declare type Mock = import("firemock").Mock; | ||
/** Get a DB reference for a given path in Firebase */ | ||
ref(path?: string): import("@firebase/database-types").Reference | import("firemock").Reference<any>; | ||
ref(path?: string): Reference; | ||
readonly isMockDb: boolean; | ||
@@ -77,3 +77,3 @@ readonly mock: Mock; | ||
callback(cb: (err: any, pathSetters: IPathSetter<any>[]) => void): void; | ||
execute(): Promise<{}>; | ||
execute(): Promise<void>; | ||
}; | ||
@@ -80,0 +80,0 @@ /** update, non-destructively, at a given path in the database */ |
@@ -131,3 +131,3 @@ (function (factory) { | ||
if (!this._mock) { | ||
const e = new Error(`Attempting to use mock getter but _mock is not set!`); | ||
const e = new Error(`Attempting to reference mock() on DB but _mock is not set [ mocking: ${this._mocking} ]!`); | ||
e.name = "AbstractedFirebase::NotAllowed"; | ||
@@ -145,10 +145,3 @@ throw e; | ||
// MOCKING | ||
if (this._mockLoadingState === "loaded") { | ||
return; | ||
} | ||
const timeout = new Date().getTime() + exports.MOCK_LOADING_TIMEOUT; | ||
while (this._mockLoadingState === "loading" && new Date().getTime() < timeout) { | ||
await common_types_1.wait(1); | ||
} | ||
return; | ||
await this.getFireMock(); | ||
} | ||
@@ -268,23 +261,18 @@ else { | ||
async execute() { | ||
return new Promise((resolve, reject) => { | ||
const updateHash = {}; | ||
const fullyQualifiedPaths = mps.map(i => (Object.assign({}, i, { path: [api._basePath, i.path].join("/").replace(/[\/]{2,3}/g, "/") }))); | ||
fullyQualifiedPaths.map(item => { | ||
updateHash[item.path] = item.value; | ||
}); | ||
return ref() | ||
.update(updateHash) | ||
.then(() => { | ||
if (callback) { | ||
callback(null, mps); | ||
resolve(); | ||
} | ||
}) | ||
.catch((e) => { | ||
if (callback) { | ||
callback(e, mps); | ||
} | ||
reject(e); | ||
}); | ||
const updateHash = {}; | ||
const fullyQualifiedPaths = mps.map(i => (Object.assign({}, i, { path: [api._basePath, i.path].join("/").replace(/[\/]{2,3}/g, "/") }))); | ||
fullyQualifiedPaths.map(item => { | ||
updateHash[item.path] = item.value; | ||
}); | ||
try { | ||
await ref().update(updateHash); | ||
if (callback) { | ||
await callback(null, mps); | ||
} | ||
} | ||
catch (e) { | ||
if (callback) { | ||
await callback(e, mps); | ||
} | ||
} | ||
} | ||
@@ -305,3 +293,5 @@ }; | ||
} | ||
handleError_1.handleError(e, "update", { path, value }); | ||
else { | ||
handleError_1.handleError(e, "update", { path, value }); | ||
} | ||
} | ||
@@ -308,0 +298,0 @@ } |
{ | ||
"name": "abstracted-firebase", | ||
"version": "0.16.5", | ||
"version": "0.16.6", | ||
"description": "Core functional library supporting 'abstracted-admin' and 'abstracted-client'", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
101891
2338