Registry / database / mongodb-resumetoken-decoder

mongodb-resumetoken-decoder

JSON →
library1.1.2jsnpmunverified

A utility library for decoding MongoDB change stream resume tokens into their constituent components. Current stable version is 1.1.2, with an irregular release cadence focused on maintenance. It provides a simple decode function that extracts fields such as timestamp, version, tokenType, txnOpIndex, fromInvalidate, uuid, and documentKey from a hex-encoded resume token string. It also ships as a CLI via npx. Compared to manual parsing, this library handles the binary encoding details and BSON type mapping, reducing errors and development time.

npm install mongodb-resumetoken-decoder
INSTALL
IMPORT
SIG · MONGODB-RESUMETOKE
M
mongodb-resumetoken-decoder
databasejavascriptv1.1.2
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

default
import decode from 'mongodb-resumetoken-decoder'
import { decode } from 'mongodb-resumetoken-decoder'
The package exports a single function as default export, not as named export.
default
const decode = require('mongodb-resumetoken-decoder')
const { decode } = require('mongodb-resumetoken-decoder')
In CommonJS, the module exports a function directly via module.exports.
types
import type { ResumeToken } from 'mongodb-resumetoken-decoder'
TypeScript types are shipped; use import type for compile-time only usage.
default
const decode = require('mongodb-resumetoken-decoder').default
const decode = require('mongodb-resumetoken-decoder')
When using require in TypeScript with esModuleInterop false, you need .default.

Decodes a hex-encoded MongoDB change stream resume token into its components using the default export.

import decode from 'mongodb-resumetoken-decoder'; // Example resume token from MongoDB changestream const token = '82612E8513000000012B022C0100296E5A1004A5093ABB38FE4B9EA67F01BB1A96D812463C5F6964003C5F5F5F78000004'; const decoded = decode(token); console.log(decoded); // { // timestamp: new Timestamp({ t: 1630438675, i: 1 }), // version: 1, // tokenType: 128, // txnOpIndex: 0, // fromInvalidate: false, // uuid: new UUID('a5093abb-38fe-4b9e-a67f-01bb1a96d812'), // documentKey: { _id: '___x' } // }
Debug
Known issues
gotchaThe package does not validate if the input is a valid resume token; it will throw on invalid data.
fix
Wrap the decoder in a try/catch when using user-provided tokens.
affects: >=0.0.0
breakingIn version 1.0.0, the return type changed from a plain object to an object with BSON types (Timestamp, UUID).
fix
If you rely on JSON serialization, use a replacer function for Timestamp and UUID.
affects: >=1.0.0
deprecatedThe CLI usage via npx works, but the package does not export a CLI script directly; it uses internal bin.
fix
Use npx as documented; do not count on the binary being on PATH after npm install -g.
affects: >=1.0.0
gotchaThe decode function is synchronous and may block the event loop for large tokens.
fix
Avoid using in hot paths or offload to worker threads if performance is critical.
affects: >=0.0.0
Errors
Common errors & fixes
TypeError: decode is not a function
Using named import instead of default import
fix
Use 'import decode from ...' or 'const decode = require(...)'
Uncaught Error: Invalid resume token: ...
Passing a non-hex string or malformed token
fix
Ensure the token is a full hex string from MongoDB changestream resume token.
TypeError: Cannot read properties of undefined (reading 'length')
Passing undefined or null to decode()
fix
Check that the token is defined before calling decode(token)
Upgrade
Version history
1.1.2latest on npm
Audit
Dependencies
bsonrequiredRequired for BSON types like Timestamp and UUID in the decoded output
Agent activity
2 hits · last 30 days
node
2
Resources
mongodb-resumetoken-decoder — npm install mongodb-resumetoken-decoder · libregistry