How to use the @firebase/util.errorPrefix 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 / core / util / validation.ts View on Github external
export const validateUrl = function(
  fnName: string,
  argumentNumber: number,
  parsedUrl: { repoInfo: RepoInfo; path: Path }
) {
  // TODO = Validate server better.
  const pathString = parsedUrl.path.toString();
  if (
    !(typeof parsedUrl.repoInfo.host === 'string') ||
    parsedUrl.repoInfo.host.length === 0 ||
    (!isValidKey(parsedUrl.repoInfo.namespace) &&
      parsedUrl.repoInfo.host.split(':')[0] !== 'localhost') ||
    (pathString.length !== 0 && !isValidRootPathString(pathString))
  ) {
    throw new Error(
      errorPrefixFxn(fnName, argumentNumber, false) +
        'must be a valid firebase URL and ' +
        'the path can\'t contain ".", "#", "$", "[", or "]".'
    );
  }
};
github firebase / firebase-js-sdk / packages / database / src / api / Query.ts View on Github external
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 / core / util / validation.ts View on Github external
if (optional && priority === undefined) {
    return;
  }
  if (isInvalidJSONNumber(priority)) {
    throw new Error(
      errorPrefixFxn(fnName, argumentNumber, optional) +
        'is ' +
        priority.toString() +
        ', but must be a valid Firebase priority (a string, finite number, ' +
        'server value, or null).'
    );
  }
  // Special case to allow importing data with a .sv.
  if (!isValidPriority(priority)) {
    throw new Error(
      errorPrefixFxn(fnName, argumentNumber, optional) +
        'must be a valid Firebase priority ' +
        '(a string, finite number, server value, or null).'
    );
  }
};
github firebase / firebase-js-sdk / packages / database / src / api / Query.ts View on Github external
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 / core / util / validation.ts View on Github external
export const validateFirebaseMergeDataArg = function(
  fnName: string,
  argumentNumber: number,
  data: unknown,
  path: Path,
  optional: boolean
) {
  if (optional && data === undefined) {
    return;
  }

  const errorPrefix = errorPrefixFxn(fnName, argumentNumber, optional);

  if (!(data && typeof data === 'object') || Array.isArray(data)) {
    throw new Error(
      errorPrefix + ' must be an object containing the children to replace.'
    );
  }

  const mergePaths: Path[] = [];
  each(data, (key: string, value: unknown) => {
    const curPath = new Path(key);
    validateFirebaseData(errorPrefix, value, path.child(curPath));
    if (curPath.getBack() === '.priority') {
      if (!isValidPriority(value)) {
        throw new Error(
          errorPrefix +
            "contains an invalid value for '" +