How to use the @firebase/util.validateContextObject 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 / Query.ts View on Github external
private static getCancelAndContextArgs_(
    fnName: string,
    cancelOrContext?: ((a: Error) => void) | Object,
    context?: Object
  ): { cancel: ((a: Error) => void) | null; context: Object | null } {
    const ret: {
      cancel: ((a: Error) => void) | null;
      context: Object | null;
    } = { cancel: null, context: null };
    if (cancelOrContext && context) {
      ret.cancel = cancelOrContext as (a: Error) => void;
      validateCallback(fnName, 3, ret.cancel, true);

      ret.context = context;
      validateContextObject(fnName, 4, ret.context, true);
    } else if (cancelOrContext) {
      // we have either a cancel callback or a context.
      if (typeof cancelOrContext === 'object' && cancelOrContext !== null) {
        // it's a context!
        ret.context = cancelOrContext;
      } else if (typeof cancelOrContext === 'function') {
        ret.cancel = cancelOrContext as (a: Error) => void;
      } else {
        throw new Error(
          errorPrefix(fnName, 3, true) +
            ' must either be a cancel callback or a context object.'
        );
      }
    }
    return ret;
  }
github firebase / firebase-js-sdk / packages / database / src / api / Query.ts View on Github external
private static getCancelAndContextArgs_(
    fnName: string,
    cancelOrContext?: ((a: Error) => void) | Object | null,
    context?: Object | null
  ): { cancel: ((a: Error) => void) | null; context: Object | null } {
    const ret: {
      cancel: ((a: Error) => void) | null;
      context: Object | null;
    } = { cancel: null, context: null };
    if (cancelOrContext && context) {
      ret.cancel = cancelOrContext as (a: Error) => void;
      validateCallback(fnName, 3, ret.cancel, true);

      ret.context = context;
      validateContextObject(fnName, 4, ret.context, true);
    } else if (cancelOrContext) {
      // we have either a cancel callback or a context.
      if (typeof cancelOrContext === 'object' && cancelOrContext !== null) {
        // it's a context!
        ret.context = cancelOrContext;
      } else if (typeof cancelOrContext === 'function') {
        ret.cancel = cancelOrContext as (a: Error) => void;
      } else {
        throw new Error(
          errorPrefix(fnName, 3, true) +
            ' must either be a cancel callback or a context object.'
        );
      }
    }
    return ret;
  }
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;
      }
      container = new ChildEventRegistration(callbacks, null, context || null);
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;
      }
      container = new ChildEventRegistration(callbacks, null, context || undefined);