How to use the firebase-tools.firestore function in firebase-tools

To help you get started, we’ve selected a few firebase-tools 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 jsayol / FireSQL / tools / test-data / test-setup.ts View on Github external
await firebaseTools.deploy({
      project,
      token,
      cwd: resolvePath(__dirname, '../../config')
    });

    // Firestore calls grpc.load() which has been deprecated and we
    // get an ugly warning on screen. This mutes it temporarily.
    const unmute = muteDeprecationWarning();

    const firestore = firebase.initializeApp(config).firestore();
    firestore.settings({ timestampsInSnapshots: true });
    const rootRef = firestore.doc('/');

    task = showTask('Deleting "shops" collection');
    await firebaseTools.firestore.delete('/shops', {
      project,
      yes: true,
      recursive: true
    });

    task = showTask('Loading test data into "shops" collection');
    await loadTestDataset(rootRef, loadJSONFile(
      './data.json'
    ) as TestCollection[]);

    unmute();
    task.done();
    return;
  })
  .then((result?: boolean) => {
github firebase / snippets-node / firestore / solution-deletes / functions / index.js View on Github external
if (!(context.auth && context.auth.token && context.auth.token.admin)) {
      throw new functions.https.HttpsError(
        'permission-denied',
        'Must be an administrative user to initiate delete.'
      );
    }

    const path = data.path;
    console.log(
      `User ${context.auth.uid} has requested to delete path ${path}`
    );

    // Run a recursive delete on the given document or collection path.
    // The 'token' must be set in the functions config, and can be generated
    // at the command line by running 'firebase login:ci'.
    return firebase_tools.firestore
      .delete(path, {
        project: process.env.GCLOUD_PROJECT,
        recursive: true,
        yes: true,
        token: functions.config().fb.token
      })
      .then(() => {
        return {
          path: path 
        };
      });
  });
  // [END recursive_delete_function]
github firebase / extensions / delete-user-data / functions / src / index.ts View on Github external
try {
      const isRecursive = config.firestoreDeleteMode === 'recursive';

      if (!isRecursive) {
        const firestore = admin.firestore();
        logs.firestorePathDeleting(path, false);

        // Wrapping in transaction to allow for automatic retries (#48)
        await firestore.runTransaction((transaction => {
          transaction.delete(firestore.doc(path));
          return Promise.resolve();
        }));
        logs.firestorePathDeleted(path, false);
      } else {
        logs.firestorePathDeleting(path, true);
        await firebase_tools.firestore.delete(path, {
          project: process.env.PROJECT_ID,
          recursive: true,
          yes: true, // auto-confirmation
        });
        logs.firestorePathDeleted(path, true);
      }
    } catch (err) {
      logs.firestorePathError(path, err);
    }
  });
github firebase / extensions / firestore-recursive-delete / functions / index.js View on Github external
if (!data.path) {
    throw new functions.https.HttpsError(
      "invalid-argument",
      "Must specify a 'path' argument."
    );
  }

  console.log(
    `[fsdelete] User ${context.auth.uid} has requested to delete path ${
      data.path
    }`
  );

  const deletePath = data.path;
  try {
    await tools.firestore.delete(deletePath, {
      project: process.env.PROJECT_ID,
      recursive: true,
      yes: true,
    });
    console.log("[fsdelete] Delete success");
    return {
      path: deletePath,
    };
  } catch (e) {
    console.warn("[fsdelete] Delete failure", e);
    throw new functions.https.HttpsError("unknown", JSON.stringify(e));
  }
});
github firebase / extensions / delete-user-data / functions / lib / index.js View on Github external
const promises = paths.map((path) => __awaiter(void 0, void 0, void 0, function* () {
        try {
            const isRecursive = config_1.default.firestoreDeleteMode === 'recursive';
            if (!isRecursive) {
                logs.firestorePathDeleting(path, false);
                yield admin
                    .firestore()
                    .doc(path)
                    .delete();
                logs.firestorePathDeleted(path, false);
            }
            else {
                logs.firestorePathDeleting(path, true);
                yield firebase_tools.firestore.delete(path, {
                    project: process.env.PROJECT_ID,
                    recursive: true,
                    yes: true,
                });
                logs.firestorePathDeleted(path, true);
            }
        }
        catch (err) {
            logs.firestorePathError(path, err);
        }
    }));
    yield Promise.all(promises);
github firebase / extensions / firestore-recursive-delete / functions / src / index.ts View on Github external
exports.fsdelete = functions.https.onCall(async (data, context) => {
  logs.start();

  const { auth } = context;
  assertions.userIsAuthenticated(auth);

  const { token, uid } = auth;
  assertions.userHasClaim(token);

  const { path: deletePath } = data;
  assertions.pathExists(deletePath);

  logs.deletePath(uid, deletePath);

  try {
    await tools.firestore.delete(deletePath, {
      project: process.env.PROJECT_ID,
      recursive: true,
      yes: true,
    });
    logs.success(deletePath);
    return {
      path: deletePath,
    };
  } catch (err) {
    logs.error(deletePath, err);
    throw httpErrors.unknown(err);
  }
});