Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
_handleErrorEvent(event) {
// console.log('SyncTree.ERROR >>>', event);
const { eventRegistrationKey, registrationCancellationKey } = event.registration;
const registration = this.getRegistration(registrationCancellationKey);
if (registration) {
// build a new js error - we additionally attach
// the ref as a property for easier debugging
const error = NativeError.fromEvent(event.error, 'database');
// forward on to users .on(successCallback, cancellationCallback <-- listener
SharedEventEmitter.emit(registrationCancellationKey, error);
// remove the paired event registration - if we received a cancellation
// event then it's guaranteed that they'll be no further value events
this.removeRegistration(eventRegistrationKey);
}
}
} else {
// eslint-disable-next-line no-console
console.warn(
`Warning: A firebase.perf.HttpMetric (${this._httpMethod}: ${
this._url
}) failed to provide a httpResponseCode; this metric will not be visible on the Firebase console.`,
);
}
if (!isNull(this._requestPayloadSize)) {
metricData.requestPayloadSize = this._requestPayloadSize;
}
if (!isNull(this._responsePayloadSize)) {
metricData.responsePayloadSize = this._responsePayloadSize;
}
if (!isNull(this._responseContentType)) {
metricData.responseContentType = this._responseContentType;
}
return this.native.stopHttpMetric(this._id, metricData);
}
}
// mlkit().X(...);
export default createModuleNamespace({
statics,
version,
namespace,
nativeModuleName,
nativeEvents: false,
hasMultiAppSupport: false,
hasCustomUrlOrRegionSupport: false,
ModuleClass: FirebaseMlkitModule,
});
// import mlkit, { firebase } from '@react-native-firebase/mlkit';
// mlkit().X(...);
// firebase.mlkit().X(...);
export const firebase = getFirebaseRoot();
// mlkit().X(...);
export default createModuleNamespace({
statics,
version,
namespace,
nativeModuleName,
nativeEvents: false,
hasMultiAppSupport: false,
hasCustomUrlOrRegionSupport: false,
ModuleClass: FirebaseMlkitModule,
});
// import mlkit, { firebase } from '@react-native-firebase/mlkit';
// mlkit().X(...);
// firebase.mlkit().X(...);
export const firebase = getFirebaseRoot();
}
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]);
_handleQueryCursor(cursor, docOrField, fields) {
const modifiers = this._modifiers._copy();
if (isUndefined(docOrField)) {
throw new Error(
`firebase.firestore().collection().${cursor}(*) Expected a DocumentSnapshot or list of field values but got undefined.`,
);
}
// Handles cases where the first arg is a DocumentSnapshot
if (docOrField instanceof FirestoreDocumentSnapshot) {
if (fields.length > 0) {
throw new Error(
`firebase.firestore().collection().${cursor}(*) Too many arguments provided. Expected DocumentSnapshot or list of field values.`,
);
}
const documentSnapshot = docOrField;
if (!documentSnapshot.exists) {
onMessage(listener) {
if (!isFunction(listener)) {
throw new Error("firebase.messaging().onMessage(*) 'listener' expected a function.");
}
// TODO(salakar) rework internals as without this native module will never be ready (therefore never subscribes)
this.native;
const subscription = this.emitter.addListener('messaging_message_received', listener);
return () => subscription.remove();
}
function wrapSnapshotEventListener(task, listenerFn, unsubscribe) {
if (!isFunction(listenerFn)) {
return null;
}
return event => {
if (unsubscribe) {
setTimeout(() => unsubscribe(), 0);
} // 1 frame = 16ms, pushing to next frame
if (isFunction(listenerFn)) {
const snapshot = Object.assign({}, event);
snapshot.task = task;
snapshot.ref = task._ref;
if (snapshot.metadata) {
if (!snapshot.metadata.generation) {
snapshot.metadata.generation = '';
}
if (!snapshot.metadata.bucket) {