Created
September 4, 2023 17:21
-
-
Save jokesterfr/7d9da9d405770f53cfc1150b2b022d4b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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