abstracted-firebase
Advanced tools
Comparing version 0.4.8 to 0.5.0
import { SerializedQuery } from "serialized-query"; | ||
import { Mock } from "firemock"; | ||
import { rtdb } from "firebase-api-surface"; | ||
export interface IPathSetter<T = any> { | ||
path: string; | ||
value: T; | ||
} | ||
export declare type FirebaseEvent = "child_added" | "child_removed" | "child_changed" | "child_moved" | "value"; | ||
@@ -38,3 +42,10 @@ export declare enum FirebaseBoolean { | ||
set<T = T>(path: string, value: T): Promise<void>; | ||
update<T = T>(path: string, value: Partial<T>): Promise<any>; | ||
multiPathSet(): { | ||
basePath: string; | ||
add<X = any>(pathValue: IPathSetter<X>): any; | ||
readonly paths: string[]; | ||
callback(cb: (err: any, pathSetters: IPathSetter<any>[]) => void): void; | ||
execute(): Promise<any>; | ||
}; | ||
update<T = any>(path: string, value: Partial<T>): Promise<any>; | ||
remove<T = T>(path: string, ignoreMissing?: boolean): Promise<void>; | ||
@@ -41,0 +52,0 @@ getSnapshot(path: string | SerializedQuery): Promise<rtdb.IDataSnapshot>; |
@@ -96,2 +96,53 @@ "use strict"; | ||
} | ||
multiPathSet() { | ||
const mps = []; | ||
const ref = this.ref.bind(this); | ||
let callback; | ||
const api = { | ||
basePath: "/", | ||
add(pathValue) { | ||
const exists = new Set(api.paths); | ||
if (pathValue.path.indexOf("/") === -1) { | ||
pathValue.path = "/" + pathValue.path; | ||
} | ||
if (exists.has(pathValue.path)) { | ||
const e = new Error(`You have attempted to add the path "${pathValue.path}" twice.`); | ||
e.code = "duplicate-path"; | ||
throw e; | ||
} | ||
mps.push(pathValue); | ||
return api; | ||
}, | ||
get paths() { | ||
return mps.map(i => i.path); | ||
}, | ||
callback(cb) { | ||
callback = cb; | ||
return; | ||
}, | ||
execute() { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const updateHash = {}; | ||
mps.map(item => { | ||
updateHash[item.path] = item.value; | ||
}); | ||
return ref(api.basePath) | ||
.update(updateHash) | ||
.then(() => { | ||
if (callback) { | ||
callback(null, mps); | ||
return; | ||
} | ||
}) | ||
.catch((e) => { | ||
if (callback) { | ||
callback(e, mps); | ||
} | ||
throw e; | ||
}); | ||
}); | ||
} | ||
}; | ||
return api; | ||
} | ||
update(path, value) { | ||
@@ -98,0 +149,0 @@ return __awaiter(this, void 0, void 0, function* () { |
{ | ||
"name": "abstracted-firebase", | ||
"version": "0.4.8", | ||
"version": "0.5.0", | ||
"description": "Core library supporting 'abstracted-admin' and 'abstracted-client' libraries", | ||
@@ -47,2 +47,3 @@ "license": "MIT", | ||
"@types/rimraf": "^2.0.1", | ||
"abstracted-admin": "^0.9.5", | ||
"async-shelljs": "^0.1.2", | ||
@@ -49,0 +50,0 @@ "chai": "^4.1.0", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
17029
344
25