@atproto/common-web package provides shared utilities and helper functions used across AT Protocol packages. All utilities are web-platform-friendly and work in browsers, Node.js, and other JavaScript runtimes.
Installation
Overview
This package contains:- TID - Timestamp Identifiers for distributed systems
- Async utilities - Promise helpers and async iteration
- Data structures - Array and object manipulation
- DID Document utilities - Working with DID documents
- IPLD utilities - Content addressing and encoding
- Retry logic - Configurable retry mechanisms
- Time utilities - Time parsing and formatting
- String utilities - String manipulation helpers
This package is designed to be a dependency of other
@atproto/* packages. Most applications should use @atproto/api instead of importing this package directly.TID (Timestamp Identifier)
TIDs are time-ordered identifiers used throughout AT Protocol for records, events, and other entities.Class: TID
(prev?: TID) => TID
Generate the next TID
(prev?: string) => string
Generate the next TID as a string
(timestamp: number, clockid: number) => TID
Create a TID from a timestamp and clock ID
(str: string) => TID
Parse a TID from a string
(str: string) => boolean
Check if a string is a valid TID
Instance Methods
Sorting
Async Utilities
retry
Retry a function with exponential backoff:() => Promise<T>
required
The async function to retry
number
Maximum number of retry attempts (default: 3)
number
Initial delay in milliseconds (default: 100)
number
Maximum delay in milliseconds (default: 5000)
(error: unknown) => boolean
Function to determine if an error is retryable (default: all errors retryable)
wait
Delay execution for a specified time:bailableWait
Create a wait that can be cancelled:Array Utilities
chunkArray
Split an array into chunks:dedupeStrs
Remove duplicate strings from an array:range
Create an array of numbers:asyncFilter
Filter array with async predicate:Object Utilities
omit
Create a shallow copy without specified keys:noUndefinedVals
Remove undefined values from an object:String Utilities
parseLanguage
Parse a language code:s32encode / s32decode
Encode/decode numbers using base-32 (sortable variant):DID Document Utilities
isValidDidDoc
Validate a DID document structure:getPdsEndpoint
Extract the PDS endpoint from a DID document:getEntryUrlFromDidDoc
Get the entry URL for a service:IPLD Utilities
cidForCbor
Generate a CID for CBOR data:verifyCidForBytes
Verify that bytes match a CID:Type Guards
check
Thecheck namespace provides type checking utilities:
Error Utilities
aggregateErrors
Combine multiple errors:isErrnoException
Check if error is a Node.js errno exception:errHasMsg
Check if error has a specific message:Binary Data Utilities
flattenUint8Arrays
Combine multiple Uint8Arrays:streamToBuffer
Convert async iterable to Uint8Array:Time Utilities
parseIntWithFallback
Parse integer with fallback:jitter
Generate random jitter:Complete Examples
Retry with Custom Logic
Batch Processing with Chunks
Working with TIDs
Stream Processing
Type Definitions
Key types exported from the package:Related Packages
- @atproto/api - High-level AT Protocol client
- @atproto/xrpc - XRPC client library
- @atproto/syntax - AT Protocol syntax utilities
- @atproto/lexicon - Lexicon schema validation
Notes
- All utilities are designed to work in web browsers and Node.js
- The package has no platform-specific dependencies
- TID generation is not cryptographically secure but provides collision resistance
- Retry logic uses exponential backoff with jitter