export function _refWithOptions()

in src/providers/database.ts [127:164]


export function _refWithOptions(
  path: string,
  options: DeploymentOptions
): RefBuilder {
  const resourceGetter = () => {
    const normalized = normalizePath(path);
    const databaseURL = firebaseConfig().databaseURL;
    if (!databaseURL) {
      throw new Error(
        'Missing expected firebase config value databaseURL, ' +
          'config is actually' +
          JSON.stringify(firebaseConfig()) +
          '\n If you are unit testing, please set process.env.FIREBASE_CONFIG'
      );
    }

    let instance;
    const prodMatch = databaseURL.match(databaseURLRegex);
    if (prodMatch) {
      instance = prodMatch[1];
    } else {
      const emulatorMatch = databaseURL.match(emulatorDatabaseURLRegex);
      if (emulatorMatch) {
        instance = emulatorMatch[1];
      }
    }

    if (!instance) {
      throw new Error(
        'Invalid value for config firebase.databaseURL: ' + databaseURL
      );
    }

    return `projects/_/instances/${instance}/refs/${normalized}`;
  };

  return new RefBuilder(apps(), resourceGetter, options);
}