export function useMissingDocuments()

in src/components/Firestore/FirestoreEmulatedApiProvider.tsx [136:169]


export function useMissingDocuments(
  collection: firebase.firestore.CollectionReference
): MissingDocument[] {
  const { baseUrl } = useFirestoreRestApi();
  const encodedPath = encodePath(collection.path);
  const url = `${baseUrl}/documents/${encodedPath}?mask.fieldPaths=_none_&pageSize=300&showMissing=true`;

  const { data } = useRequest<{
    documents: { name: string; createTime?: string }[];
  }>(
    url,
    {
      method: 'GET',
    },
    {
      refreshInterval: 10_000,
    }
  );

  return (
    data?.documents
      ?.filter((d) => !d.createTime)
      .map((d) => {
        const match = DOCUMENT_PATH_RE.exec(d.name);
        if (!match) {
          throw new Error(
            `Document path "${d.name}" returned by API does not match regex.`
          );
        }
        const [, , , path] = match;
        return { path };
      }) || []
  );
}