How to use the @firebase/util.validateCallback function in @firebase/util

To help you get started, we’ve selected a few @firebase/util examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github firebase / firebase-js-sdk / packages / database / src / api / Reference.ts View on Github external
transaction(
    transactionUpdate: (a: unknown) => unknown,
    onComplete?: (a: Error | null, b: boolean, c: DataSnapshot | null) => void,
    applyLocally?: boolean
  ): Promise {
    validateArgCount('Reference.transaction', 1, 3, arguments.length);
    validateWritablePath('Reference.transaction', this.path);
    validateCallback('Reference.transaction', 1, transactionUpdate, false);
    validateCallback('Reference.transaction', 2, onComplete, true);
    // NOTE: applyLocally is an internal-only option for now.  We need to decide if we want to keep it and how
    // to expose it.
    validateBoolean('Reference.transaction', 3, applyLocally, true);

    if (this.getKey() === '.length' || this.getKey() === '.keys') {
      throw 'Reference.transaction failed: ' +
        this.getKey() +
        ' is a read-only object.';
    }

    if (applyLocally === undefined) {
      applyLocally = true;
    }

    const deferred = new Deferred();
    if (typeof onComplete === 'function') {
github firebase / firebase-js-sdk / packages / database / src / api / Query.ts View on Github external
off(
    eventType?: string,
    callback?: SnapshotCallback,
    context?: Object | null
  ): void {
    validateArgCount('Query.off', 0, 3, arguments.length);
    validateEventType('Query.off', 1, eventType || '', true);
    validateCallback('Query.off', 2, callback, true);
    validateContextObject('Query.off', 3, context, true);

    let container: EventRegistration | null = null;
    let callbacks: { [k: string]: typeof callback } | null = null;
    if (eventType === 'value') {
      const valueCallback = callback || null;
      container = new ValueEventRegistration(
        valueCallback,
        null,
        context || null
      );
    } else if (eventType) {
      if (callback) {
        callbacks = {};
        callbacks[eventType] = callback;
      }
github firebase / firebase-js-sdk / packages / database / src / api / onDisconnect.ts View on Github external
remove(onComplete?: (a: Error | null) => void): Promise {
    validateArgCount('OnDisconnect.remove', 0, 1, arguments.length);
    validateWritablePath('OnDisconnect.remove', this.path_);
    validateCallback('OnDisconnect.remove', 1, onComplete, true);
    const deferred = new Deferred();
    this.repo_.onDisconnectSet(
      this.path_,
      null,
      deferred.wrapCallback(onComplete)
    );
    return deferred.promise;
  }
github firebase / firebase-js-sdk / packages / database / src / api / onDisconnect.ts View on Github external
newObjectToMerge['' + i] = objectToMerge[i];
      }
      objectToMerge = newObjectToMerge;
      warn(
        'Passing an Array to firebase.database.onDisconnect().update() is deprecated. Use set() if you want to overwrite the ' +
          'existing data, or an Object with integer keys if you really do want to only update some of the children.'
      );
    }
    validateFirebaseMergeDataArg(
      'OnDisconnect.update',
      1,
      objectToMerge,
      this.path_,
      false
    );
    validateCallback('OnDisconnect.update', 2, onComplete, true);
    const deferred = new Deferred();
    this.repo_.onDisconnectUpdate(
      this.path_,
      objectToMerge,
      deferred.wrapCallback(onComplete)
    );
    return deferred.promise;
  }
}
github firebase / firebase-js-sdk / packages / database / src / api / Query.ts View on Github external
on(
    eventType: string,
    callback: SnapshotCallback,
    cancelCallbackOrContext?: ((a: Error) => any) | Object,
    context?: Object
  ): SnapshotCallback {
    validateArgCount('Query.on', 2, 4, arguments.length);
    validateEventType('Query.on', 1, eventType, false);
    validateCallback('Query.on', 2, callback, false);

    const ret = Query.getCancelAndContextArgs_(
      'Query.on',
      cancelCallbackOrContext,
      context
    );

    if (eventType === 'value') {
      this.onValueEvent(callback, ret.cancel, ret.context);
    } else {
      const callbacks: { [k: string]: typeof callback } = {};
      callbacks[eventType] = callback;
      this.onChildEvent(callbacks, ret.cancel, ret.context);
    }
    return callback;
  }
github firebase / firebase-js-sdk / packages / database / src / api / Reference.ts View on Github external
objectToMerge = newObjectToMerge;
      warn(
        'Passing an Array to Firebase.update() is deprecated. ' +
          'Use set() if you want to overwrite the existing data, or ' +
          'an Object with integer keys if you really do want to ' +
          'only update some of the children.'
      );
    }
    validateFirebaseMergeDataArg(
      'Reference.update',
      1,
      objectToMerge,
      this.path,
      false
    );
    validateCallback('Reference.update', 2, onComplete, true);
    const deferred = new Deferred();
    this.repo.update(
      this.path,
      objectToMerge as { [k: string]: unknown },
      deferred.wrapCallback(onComplete)
    );
    return deferred.promise;
  }
github firebase / firebase-js-sdk / packages / database / src / api / Query.ts View on Github external
off(eventType?: string, callback?: SnapshotCallback, context?: Object) {
    validateArgCount('Query.off', 0, 3, arguments.length);
    validateEventType('Query.off', 1, eventType, true);
    validateCallback('Query.off', 2, callback, true);
    validateContextObject('Query.off', 3, context, true);

    let container: EventRegistration | null = null;
    let callbacks: { [k: string]: typeof callback } | null = null;
    if (eventType === 'value') {
      const valueCallback = callback || null;
      container = new ValueEventRegistration(
        valueCallback,
        null,
        context || null
      );
    } else if (eventType) {
      if (callback) {
        callbacks = {};
        callbacks[eventType] = callback;
      }
github firebase / firebase-js-sdk / packages / database / src / api / Query.ts View on Github external
on(
    eventType: string,
    callback: SnapshotCallback,
    cancelCallbackOrContext?: ((a: Error) => any) | Object | null,
    context?: Object | null
  ): SnapshotCallback {
    validateArgCount('Query.on', 2, 4, arguments.length);
    validateEventType('Query.on', 1, eventType, false);
    validateCallback('Query.on', 2, callback, false);

    const ret = Query.getCancelAndContextArgs_(
      'Query.on',
      cancelCallbackOrContext,
      context
    );

    if (eventType === 'value') {
      this.onValueEvent(callback, ret.cancel, ret.context);
    } else {
      const callbacks: { [k: string]: typeof callback } = {};
      callbacks[eventType] = callback;
      this.onChildEvent(callbacks, ret.cancel, ret.context);
    }
    return callback;
  }
github firebase / firebase-js-sdk / packages / database / src / api / Reference.ts View on Github external
setPriority(
    priority: string | number | null,
    onComplete?: (a: Error | null) => void
  ): Promise {
    validateArgCount('Reference.setPriority', 1, 2, arguments.length);
    validateWritablePath('Reference.setPriority', this.path);
    validatePriority('Reference.setPriority', 1, priority, false);
    validateCallback('Reference.setPriority', 2, onComplete, true);

    const deferred = new Deferred();
    this.repo.setWithPriority(
      this.path.child('.priority'),
      priority,
      null,
      deferred.wrapCallback(onComplete)
    );
    return deferred.promise;
  }
github firebase / firebase-js-sdk / packages / database / src / api / Reference.ts View on Github external
set(
    newVal: unknown,
    onComplete?: (a: Error | null) => void
  ): Promise {
    validateArgCount('Reference.set', 1, 2, arguments.length);
    validateWritablePath('Reference.set', this.path);
    validateFirebaseDataArg('Reference.set', 1, newVal, this.path, false);
    validateCallback('Reference.set', 2, onComplete, true);

    const deferred = new Deferred();
    this.repo.setWithPriority(
      this.path,
      newVal,
      /*priority=*/ null,
      deferred.wrapCallback(onComplete)
    );
    return deferred.promise;
  }