How to use the @firebase/util.safeGet 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 / snap / IndexMap.ts View on Github external
(indexedChildren: SortedMap, indexName: string) => {
        const index = safeGet(this.indexSet_, indexName);
        assert(index, 'Missing index implementation for ' + indexName);
        if (indexedChildren === fallbackObject) {
          // Check to see if we need to index everything
          if (index.isDefinedOn(namedNode.node)) {
            // We need to build this index
            const childList = [];
            const iter = existingChildren.getIterator(NamedNode.Wrap);
            let next = iter.getNext();
            while (next) {
              if (next.name !== namedNode.name) {
                childList.push(next);
              }
              next = iter.getNext();
            }
            childList.push(namedNode);
            return buildChildSet(childList, index.getCompare());
github firebase / firebase-js-sdk / packages / database / src / core / util / validation.ts View on Github external
if (!objectContainsKey) {
    if (optional) {
      return;
    } else {
      throw new Error(
        errorPrefixFxn(fnName, argumentNumber, optional) +
          'must contain the key "' +
          key +
          '"'
      );
    }
  }

  if (optType) {
    // eslint-disable-next-line @typescript-eslint/no-explicit-any
    const val = safeGet(obj as any, key);
    if (
      (optType === 'number' && !(typeof val === 'number')) ||
      (optType === 'string' && !(typeof val === 'string')) ||
      (optType === 'boolean' && !(typeof val === 'boolean')) ||
      (optType === 'function' && !(typeof val === 'function')) ||
      (optType === 'object' && !(typeof val === 'object') && val)
    ) {
      if (optional) {
        throw new Error(
          errorPrefixFxn(fnName, argumentNumber, optional) +
            'contains invalid value for key "' +
            key +
            '" (must be of type "' +
            optType +
            '")'
        );
github firebase / firebase-js-sdk / packages / database / src / core / Repo_transaction.ts View on Github external
const nodeQueue = queueNode.getValue() || [];
    nodeQueue.push(transaction);

    queueNode.setValue(nodeQueue);

    // Update visibleData and raise events
    // Note: We intentionally raise events after updating all of our transaction state, since the user could
    // start new transactions from the event callbacks.
    let priorityForNode;
    if (
      typeof newVal === 'object' &&
      newVal !== null &&
      contains(newVal, '.priority')
    ) {
      // eslint-disable-next-line @typescript-eslint/no-explicit-any
      priorityForNode = safeGet(newVal as any, '.priority');
      assert(
        isValidPriority(priorityForNode),
        'Invalid priority returned by transaction. ' +
          'Priority must be a valid string, finite number, server value, or null.'
      );
    } else {
      const currentNode =
        this.serverSyncTree_.calcCompleteEventCache(path) ||
        ChildrenNode.EMPTY_NODE;
      priorityForNode = currentNode.getPriority().val();
    }
    priorityForNode /** @type {null|number|string} */ = priorityForNode;

    const serverValues = this.generateServerValues();
    const newNodeUnresolved = nodeFromJSON(newVal, priorityForNode);
    const newNode = resolveDeferredValueSnapshot(
github firebase / firebase-js-sdk / packages / database / src / core / RepoManager.ts View on Github external
deleteRepo(repo: Repo) {
    const appRepos = safeGet(this.repos_, repo.app.name);
    // This should never happen...
    if (!appRepos || safeGet(appRepos, repo.repoInfo_.toURLString()) !== repo) {
      fatal(
        `Database ${repo.app.name}(${repo.repoInfo_}) has already been deleted.`
      );
    }
    repo.interrupt();
    delete appRepos[repo.repoInfo_.toURLString()];
  }
github firebase / user-privacy / functions / node_modules / @firebase / database / dist / esm / src / core / RepoManager.js View on Github external
RepoManager.prototype.deleteRepo = function (repo) {
        var appRepos = safeGet(this.repos_, repo.app.name);
        // This should never happen...
        if (!appRepos || safeGet(appRepos, repo.repoInfo_.toURLString()) !== repo) {
            fatal("Database " + repo.app.name + "(" + repo.repoInfo_ + ") has already been deleted.");
        }
        repo.interrupt();
        delete appRepos[repo.repoInfo_.toURLString()];
    };
    /**
github firebase / firebase-js-sdk / packages / database / src / core / util / Tree.ts View on Github external
subTree(pathObj: string | Path): Tree {
    // TODO: Require pathObj to be Path?
    let path = pathObj instanceof Path ? pathObj : new Path(pathObj);
    let child = this as Tree,
      next = path.getFront();
    while (next !== null) {
      const childNode = safeGet(child.node_.children, next) || new TreeNode();
      child = new Tree(next, child, childNode);
      path = path.popFront();
      next = path.getFront();
    }

    return child;
  }
github firebase / user-privacy / functions / node_modules / @firebase / database / dist / cjs / src / core / RepoManager.js View on Github external
RepoManager.prototype.createRepo = function (repoInfo, app) {
        var appRepos = util_1.safeGet(this.repos_, app.name);
        if (!appRepos) {
            appRepos = {};
            this.repos_[app.name] = appRepos;
        }
        var repo = util_1.safeGet(appRepos, repoInfo.toURLString());
        if (repo) {
            util_2.fatal('Database initialized multiple times. Please make sure the format of the database URL matches with each database() call.');
        }
        repo = new Repo_1.Repo(repoInfo, this.useRestClient_, app);
        appRepos[repoInfo.toURLString()] = repo;
        return repo;
    };
    /**
github firebase / firebase-js-sdk / packages / database / src / core / PersistentConnection.ts View on Github external
private static warnOnListenWarnings_(payload: any, query: Query) {
    if (payload && typeof payload === 'object' && contains(payload, 'w')) {
      const warnings = safeGet(payload, 'w');
      if (Array.isArray(warnings) && ~warnings.indexOf('no_index')) {
        const indexSpec =
          '".indexOn": "' +
          query
            .getQueryParams()
            .getIndex()
            .toString() +
          '"';
        const indexPath = query.path.toString();
        warn(
          `Using an unspecified index. Your data will be downloaded and ` +
            `filtered on the client. Consider adding ${indexSpec} at ` +
            `${indexPath} to your security rules for better performance.`
        );
      }
    }
github firebase / firebase-js-sdk / packages / database / src / core / RepoManager.ts View on Github external
createRepo(
    repoInfo: RepoInfo,
    app: FirebaseApp,
    authProvider: Provider
  ): Repo {
    let appRepos = safeGet(this.repos_, app.name);

    if (!appRepos) {
      appRepos = {};
      this.repos_[app.name] = appRepos;
    }

    let repo = safeGet(appRepos, repoInfo.toURLString());
    if (repo) {
      fatal(
        'Database initialized multiple times. Please make sure the format of the database URL matches with each database() call.'
      );
    }
    repo = new Repo(repoInfo, this.useRestClient_, app, authProvider);
    appRepos[repoInfo.toURLString()] = repo;

    return repo;
  }
github firebase / user-privacy / functions / node_modules / @firebase / database / dist / esm / src / core / RepoManager.js View on Github external
RepoManager.prototype.createRepo = function (repoInfo, app) {
        var appRepos = safeGet(this.repos_, app.name);
        if (!appRepos) {
            appRepos = {};
            this.repos_[app.name] = appRepos;
        }
        var repo = safeGet(appRepos, repoInfo.toURLString());
        if (repo) {
            fatal('Database initialized multiple times. Please make sure the format of the database URL matches with each database() call.');
        }
        repo = new Repo(repoInfo, this.useRestClient_, app);
        appRepos[repoInfo.toURLString()] = repo;
        return repo;
    };
    /**