Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
}
if (!isUndefined(successCallBack) && !isFunction(successCallBack)) {
throw new Error("firebase.database().ref().once(_, *) 'successCallBack' must be a function.");
}
if (
!isUndefined(failureCallbackOrContext) &&
(!isObject(failureCallbackOrContext) && !isFunction(failureCallbackOrContext))
) {
throw new Error(
"firebase.database().ref().once(_, _, *) 'failureCallbackOrContext' must be a function or context.",
);
}
if (!isUndefined(context) && !isObject(context)) {
throw new Error(
"firebase.database().ref().once(_, _, _, *) 'context' must be a context object.",
);
}
const modifiers = this._modifiers.toArray();
return this._database.native
.once(this.path, modifiers, eventType)
.then(result => {
let dataSnapshot;
let previousChildName;
// Child based events return a previousChildName
if (eventType === 'value') {
dataSnapshot = new DatabaseDataSnapshot(this.ref, result);
return DatabaseSyncTree.removeListenersForRegistrations(
DatabaseSyncTree.getRegistrationsByPath(this.path),
);
}
if (!isUndefined(eventType) && !eventTypes.includes(eventType)) {
throw new Error(
`firebase.database().ref().off(*) 'eventType' must be one of ${eventTypes.join(', ')}.`,
);
}
if (!isUndefined(callback) && !isFunction(callback)) {
throw new Error("firebase.database().ref().off(_, *) 'callback' must be a function.");
}
if (!isUndefined(context) && !isObject(context)) {
throw new Error("firebase.database().ref().off(_, _, *) 'context' must be an object.");
}
// Firebase Docs:
// Note that if on() was called
// multiple times with the same eventType and callback, the callback will be called
// multiple times for each event, and off() must be called multiple times to
// remove the callback.
// Remove only a single registration
if (eventType && callback) {
const registration = DatabaseSyncTree.getOneByPathEventListener(
this.path,
eventType,
callback,
);
if (isNumber(value)) {
return getTypeMapInt('number', value);
}
if (isString(value)) {
if (value === '') {
return getTypeMapInt('stringEmpty');
}
return getTypeMapInt('string', value);
}
if (isArray(value)) {
return getTypeMapInt('array', buildNativeArray(value));
}
if (isObject(value)) {
if (value instanceof FirestoreDocumentReference) {
return getTypeMapInt('reference', value.path);
}
if (value instanceof FirestoreGeoPoint) {
return getTypeMapInt('geopoint', [value.latitude, value.longitude]);
}
// Handle Date objects are Timestamps as per web sdk
if (isDate(value)) {
const timestamp = FirestoreTimestamp.fromDate(value);
return getTypeMapInt('timestamp', [timestamp.seconds, timestamp.nanoseconds]);
}
if (value instanceof FirestoreTimestamp) {
return getTypeMapInt('timestamp', [value.seconds, value.nanoseconds]);
export default function visionFaceDetectorOptions(faceDetectorOptions) {
const out = {
classificationMode: VisionFaceDetectorClassificationMode.NO_CLASSIFICATIONS,
contourMode: VisionFaceDetectorContourMode.NO_CONTOURS,
landmarkMode: VisionFaceDetectorLandmarkMode.NO_LANDMARKS,
minFaceSize: 0.1,
performanceMode: VisionFaceDetectorPerformanceMode.FAST,
};
if (isUndefined(faceDetectorOptions)) {
return out;
}
if (!isObject(faceDetectorOptions)) {
throw new Error("'faceDetectorOptions' expected an object value.");
}
if (faceDetectorOptions.classificationMode) {
if (
faceDetectorOptions.classificationMode !==
VisionFaceDetectorClassificationMode.NO_CLASSIFICATIONS &&
faceDetectorOptions.classificationMode !==
VisionFaceDetectorClassificationMode.ALL_CLASSIFICATIONS
) {
throw new Error(
"'faceDetectorOptions.classificationMode' invalid classification mode. Expected VisionFaceDetectorClassificationMode.NO_CLASSIFICATIONS or VisionFaceDetectorClassificationMode.ALL_CLASSIFICATIONS.",
);
}
out.classificationMode = faceDetectorOptions.classificationMode;
/**
* .onSnapshot(SnapshotListenOptions, Function);
*/
if (isFunction(args[2])) {
/**
* .onSnapshot(SnapshotListenOptions, (snapshot) => {}, (error) => {});
*/
onNext = args[1];
onError = args[2];
} else {
/**
* .onSnapshot(SnapshotListenOptions, (s, e) => {};
*/
callback = args[1];
}
} else if (isObject(args[1])) {
/**
* .onSnapshot(SnapshotListenOptions, { complete: () => {}, error: (e) => {}, next: (snapshot) => {} });
*/
if (isFunction(args[1].error)) {
onError = args[1].error;
}
if (isFunction(args[1].next)) {
onNext = args[1].next;
}
}
}
if (hasOwnProperty(snapshotListenOptions, 'includeMetadataChanges')) {
if (!isBoolean(snapshotListenOptions.includeMetadataChanges)) {
throw new Error("'options' SnapshotOptions.includeMetadataChanges must be a boolean value.");
}
throw new Error("snapshot().child(*) 'path' must be a string value");
}
let value = deepGet(this._snapshot.value, path);
if (value === undefined) {
value = null;
}
const childRef = this._ref.child(path);
return new DatabaseDataSnapshot(childRef, {
value,
key: childRef.key,
exists: value !== null,
childKeys: isObject(value) ? Object.keys(value) : [],
});
}
export default function buildSocial(socialParameters) {
if (!isObject(socialParameters)) {
throw new Error("'dynamicLinksParams.social' must be an object.");
}
const params = {};
if (socialParameters.descriptionText) {
if (!isString(socialParameters.descriptionText)) {
throw new Error("'dynamicLinksParams.social.descriptionText' must be a string.");
}
params.descriptionText = socialParameters.descriptionText;
}
if (socialParameters.imageUrl) {
if (!isString(socialParameters.imageUrl)) {
throw new Error("'dynamicLinksParams.social.imageUrl' must be a string.");
if (!hasOwnProperty(remoteMessage, 'ttl')) {
out.ttl = 3600;
} else {
if (!isNumber(remoteMessage.ttl)) {
throw new Error("'remoteMessage.ttl' expected a number value");
}
if (remoteMessage.ttl < 0 || !isInteger(remoteMessage.ttl)) {
throw new Error("'remoteMessage.ttl' expected a positive integer value");
}
out.ttl = remoteMessage.ttl;
}
if (!remoteMessage.data) {
out.data = {};
} else if (!isObject(remoteMessage.data)) {
throw new Error("'remoteMessage.data' expected an object value");
} else {
out.data = remoteMessage.data;
}
if (remoteMessage.collapseKey) {
if (!isString(remoteMessage.collapseKey)) {
throw new Error("'remoteMessage.collapseKey' expected a string value");
}
out.collapseKey = remoteMessage.collapseKey;
}
if (remoteMessage.messageType) {
if (!isString(remoteMessage.messageType)) {
throw new Error("'remoteMessage.messageType' expected a string value");
}
logJoinGroup(object) {
if (!isObject(object)) {
throw new Error(
'firebase.analytics().logJoinGroup(*): The supplied arg must be an object of key/values.',
);
}
return this.logEvent(
'join_group',
validateStruct(object, structs.JoinGroup, 'firebase.analytics().logJoinGroup(*):'),
);
}
function validateIdentifyLanguageArgs(text, options, methodName) {
if (!isString(text)) {
throw new Error(
`firebase.naturalLanguage().${methodName}(*, _) 'text' must be a string value.`,
);
}
if (!isObject(options)) {
throw new Error(
`firebase.naturalLanguage().${methodName}(_, *) 'options' must be an object or undefined.`,
);
}
if (
!isUndefined(options.confidenceThreshold) &&
(!isNumber(options.confidenceThreshold) ||
options.confidenceThreshold < 0 ||
options.confidenceThreshold > 1)
) {
throw new Error(
`firebase.naturalLanguage().${methodName}(_, *) 'options.confidenceThreshold' must be a float value between 0 and 1.`,
);
}
}