Skip to content

Instantly share code, notes, and snippets.

@jokesterfr
Created September 4, 2023 17:21
Show Gist options
  • Save jokesterfr/7d9da9d405770f53cfc1150b2b022d4b to your computer and use it in GitHub Desktop.
Save jokesterfr/7d9da9d405770f53cfc1150b2b022d4b to your computer and use it in GitHub Desktop.
#!/usr/bin/env node
const { EventStoreDBClient, BACKWARDS, END } = require("@eventstore/db-client");
require("dotenv").config();
const eventStoreClient = EventStoreDBClient.connectionString(
process.env.EVENTSTORE_CONNECTION_STRING
);
const isBusinessStream = (event) =>
event.event.streamId.split("$").length === 1;
main = async () => {
console.log("Looking for checkpoint...");
const events = await eventStoreClient.readAll({
fromRevision: END,
resolveLinkTos: true,
maxCount: 10_000,
});
for await (const event of events) {
if (event?.event) {
if (isBusinessStream(event)) {
/*
* We use ResolvedEvent.OriginalPosition to store how far in the $all stream we have read so far,
* and store it in order to resume reading from that point of $all stream.
*/
console.log(event.event.metadata.$originalPosition);
process.exit(0);
}
}
}
};
main();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment