How to use the @firebase/util.validateArgCount 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 / DataSnapshot.ts View on Github external
toJSON(): unknown {
    // Optional spacer argument is unnecessary because we're depending on recursion rather than stringifying the content
    validateArgCount('DataSnapshot.toJSON', 0, 1, arguments.length);
    return this.exportVal();
  }
github firebase / firebase-js-sdk / packages / database / src / api / Query.ts View on Github external
limitToFirst(limit: number): Query {
    validateArgCount('Query.limitToFirst', 1, 1, arguments.length);
    if (
      typeof limit !== 'number' ||
      Math.floor(limit) !== limit ||
      limit <= 0
    ) {
      throw new Error(
        'Query.limitToFirst: First argument must be a positive integer.'
      );
    }
    if (this.queryParams_.hasLimit()) {
      throw new Error(
        'Query.limitToFirst: Limit was already set (by another call to limit, ' +
          'limitToFirst, or limitToLast).'
      );
    }
github firebase / firebase-js-sdk / packages / database / src / api / onDisconnect.ts View on Github external
setWithPriority(
    value: unknown,
    priority: number | string | null,
    onComplete?: (a: Error | null) => void
  ): Promise {
    validateArgCount('OnDisconnect.setWithPriority', 2, 3, arguments.length);
    validateWritablePath('OnDisconnect.setWithPriority', this.path_);
    validateFirebaseDataArg(
      'OnDisconnect.setWithPriority',
      1,
      value,
      this.path_,
      false
    );
    validatePriority('OnDisconnect.setWithPriority', 2, priority, false);
    validateCallback('OnDisconnect.setWithPriority', 3, onComplete, true);

    const deferred = new Deferred();
    this.repo_.onDisconnectSetWithPriority(
      this.path_,
      value,
      priority,
github firebase / firebase-js-sdk / packages / database / src / api / Database.ts View on Github external
goOnline() {
    validateArgCount('database.goOnline', 0, 0, arguments.length);
    this.checkDeleted_('goOnline');
    this.repo_.resume();
  }
}
github firebase / firebase-js-sdk / packages / database / src / api / Reference.ts View on Github external
child(pathString: string | Path): Reference {
    validateArgCount('Reference.child', 1, 1, arguments.length);
    if (typeof pathString === 'number') {
      pathString = String(pathString);
    } else if (!(pathString instanceof Path)) {
      if (this.path.getFront() === null) {
        validateRootPathString('Reference.child', 1, pathString, false);
      } else {
        validatePathString('Reference.child', 1, pathString, false);
      }
    }

    return new Reference(this.repo, this.path.child(pathString));
  }
github firebase / firebase-js-sdk / packages / database / src / api / Query.ts View on Github external
isEqual(other: Query): boolean {
    validateArgCount('Query.isEqual', 1, 1, arguments.length);
    if (!(other instanceof Query)) {
      const error =
        'Query.isEqual failed: First argument must be an instance of firebase.database.Query.';
      throw new Error(error);
    }

    const sameRepo = this.repo === other.repo;
    const samePath = this.path.equals(other.path);
    const sameQueryIdentifier =
      this.queryIdentifier() === other.queryIdentifier();

    return sameRepo && samePath && sameQueryIdentifier;
  }
github firebase / firebase-js-sdk / packages / database / src / api / Reference.ts View on Github external
getParent(): Reference | null {
    validateArgCount('Reference.parent', 0, 0, arguments.length);

    const parentPath = this.path.parent();
    return parentPath === null ? null : new Reference(this.repo, parentPath);
  }
github firebase / firebase-js-sdk / packages / database / src / api / Query.ts View on Github external
equalTo(value: number | string | boolean | null, name?: string) {
    validateArgCount('Query.equalTo', 1, 2, arguments.length);
    validateFirebaseDataArg('Query.equalTo', 1, value, this.path, false);
    validateKey('Query.equalTo', 2, name, true);
    if (this.queryParams_.hasStart()) {
      throw new Error(
        'Query.equalTo: Starting point was already set (by another call to startAt or ' +
          'equalTo).'
      );
    }
    if (this.queryParams_.hasEnd()) {
      throw new Error(
        'Query.equalTo: Ending point was already set (by another call to endAt or ' +
          'equalTo).'
      );
    }
    return this.startAt(value, name).endAt(value, name);
  }
github firebase / firebase-js-sdk / packages / database / src / api / Query.ts View on Github external
orderByKey(): Query {
    validateArgCount('Query.orderByKey', 0, 0, arguments.length);
    this.validateNoPreviousOrderByCall_('Query.orderByKey');
    const newParams = this.queryParams_.orderBy(KEY_INDEX);
    Query.validateQueryEndpoints_(newParams);
    return new Query(this.repo, this.path, newParams, /*orderByCalled=*/ true);
  }
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 = {};