Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
set(value, onComplete) {
if (isUndefined(value)) {
throw new Error("firebase.database().ref().set(*) 'value' must be defined.");
}
if (!isUndefined(onComplete) && !isFunction(onComplete)) {
throw new Error(
"firebase.database().ref().set(_, *) 'onComplete' must be a function if provided.",
);
}
return promiseWithOptionalCallback(this._database.native.set(this.path, { value }), onComplete);
}
throw new Error("firebase.database().ref().setWithPriority(*) 'newVal' must be defined.");
}
if (!isNumber(newPriority) && !isString(newPriority) && !isNull(newPriority)) {
throw new Error(
"firebase.database().ref().setWithPriority(_, *) 'newPriority' must be a number, string or null value.",
);
}
if (!isUndefined(onComplete) && !isFunction(onComplete)) {
throw new Error(
"firebase.database().ref().setWithPriority(_, _, *) 'onComplete' must be a function if provided.",
);
}
return promiseWithOptionalCallback(
this._database.native.setWithPriority(this.path, {
value: newVal,
priority: newPriority,
}),
onComplete,
);
}
remove(onComplete) {
if (!isUndefined(onComplete) && !isFunction(onComplete)) {
throw new Error(
"firebase.database().ref().remove(*) 'onComplete' must be a function if provided.",
);
}
return promiseWithOptionalCallback(this._database.native.remove(this.path), onComplete);
}
set(value, onComplete) {
if (isUndefined(value)) {
throw new Error("firebase.database().ref().value(*) 'value' must be defined.");
}
if (!isUndefined(onComplete) && !isFunction(onComplete)) {
throw new Error(
"firebase.database().ref().onDisconnect().set(_, *) 'onComplete' must be a function if provided.",
);
}
return promiseWithOptionalCallback(
this._ref._database.native.onDisconnectSet(this._ref.path, { value }),
onComplete,
);
}
setPriority(priority, onComplete) {
if (!isNumber(priority) && !isString(priority) && !isNull(priority)) {
throw new Error(
"firebase.database().ref().setPriority(*) 'priority' must be a number, string or null value.",
);
}
if (!isUndefined(onComplete) && !isFunction(onComplete)) {
throw new Error(
"firebase.database().ref().setPriority(_, *) 'onComplete' must be a function if provided.",
);
}
return promiseWithOptionalCallback(
this._database.native.setPriority(this.path, { priority }),
onComplete,
);
}
cancel(onComplete) {
if (!isUndefined(onComplete) && !isFunction(onComplete)) {
throw new Error(
"firebase.database().ref().onDisconnect().cancel(*) 'onComplete' must be a function if provided.",
);
}
return promiseWithOptionalCallback(
this._ref._database.native.onDisconnectCancel(this._ref.path),
onComplete,
);
}
const keys = Object.keys(values);
for (let i = 0; i < keys.length; i++) {
if (!isValidPath(keys[i])) {
throw new Error(
'firebase.database().onDisconnect().update(*) \'values\' contains an invalid path. Paths must be non-empty strings and can\'t contain ".", "#", "$", "[", or "]"',
);
}
}
if (!isUndefined(onComplete) && !isFunction(onComplete)) {
throw new Error(
"firebase.database().ref().onDisconnect().update(_, *) 'onComplete' must be a function if provided.",
);
}
return promiseWithOptionalCallback(
this._ref._database.native.onDisconnectUpdate(this._ref.path, { values }),
onComplete,
);
}
}
throw new Error("firebase.database().ref().setWithPriority(*) 'value' must be defined.");
}
if (!isNumber(priority) && !isString(priority) && !isNull(priority)) {
throw new Error(
"firebase.database().ref().onDisconnect().setWithPriority(_, *) 'priority' must be a number, string or null value.",
);
}
if (!isUndefined(onComplete) && !isFunction(onComplete)) {
throw new Error(
"firebase.database().ref().onDisconnect().setWithPriority(_, _, *) 'onComplete' must be a function if provided.",
);
}
return promiseWithOptionalCallback(
this._ref._database.native.onDisconnectSetWithPriority(this._ref.path, { value, priority }),
onComplete,
);
}
const keys = Object.keys(values);
for (let i = 0; i < keys.length; i++) {
if (!isValidPath(keys[i])) {
throw new Error(
'firebase.database().update(*) \'values\' contains an invalid path. Paths must be non-empty strings and can\'t contain ".", "#", "$", "[", or "]"',
);
}
}
if (!isUndefined(onComplete) && !isFunction(onComplete)) {
throw new Error(
"firebase.database().ref().update(_, *) 'onComplete' must be a function if provided.",
);
}
return promiseWithOptionalCallback(
this._database.native.update(this.path, { values }),
onComplete,
);
}
remove(onComplete) {
if (!isUndefined(onComplete) && !isFunction(onComplete)) {
throw new Error(
"firebase.database().ref().onDisconnect().remove(*) 'onComplete' must be a function if provided.",
);
}
return promiseWithOptionalCallback(
this._ref._database.native.onDisconnectRemove(this._ref.path),
onComplete,
);
}