Point-in-Time Recovery
⚠️ Available starting with v10.6.0
Firestore allows you to recover document versions from the past. The feature is called point-in-time recovery. It’s useful when you accidentally delete or modify a document and want to restore it to the previous state.
Typesaurus provides an adapter that allows you to use this feature with your Typesaurus database without losing type-information. To start using it, install @typesaurus/recovery
package:
npm install --save @typesaurus/recovery
The package exposes a single method — recover
. It accepts Date
, timestamp number
, or ISO string
and requests to recover for the given time:
import { recover } from "@typesaurus/recovery";import { subDays } from "date-fns";
// Recover the user doc from 1 day ago:await recover(subDays(new Date(), 1), db.users.get(userId));// => Doc<User> | null
The recover
function accepts all reading methods:
// Recover user with their comments and posts:const [user, comments, posts] = await recover(yesterday, [ db.users.get(userId), db.users(userId).comments.all(), db.posts.query(($) => $.field("author").eq(userId)),]);
The method returns values from the corresponding reading methods.
Available reading methods:
It also supports collection groups:
import { groups } from "typesaurus/groups";
// Get all user commentsawait recover( yesterday, groups(db).comments.query(($) => $.field("author").eq(userId)),);