-
feat: Add awaitMatch utility and reduce default timeout (#402) (#499)
Adds a new
awaitMatchutility function to support custom synchronization matching logic when transaction IDs (txids) are not available. Also reduces the default timeout forawaitTxIdfrom 30 seconds to 5 seconds for faster feedback.New Features:
- New utility method:
collection.utils.awaitMatch(matchFn, timeout?)- Wait for custom match logic - Export
isChangeMessageandisControlMessagehelper functions for custom match functions - Type:
MatchFunction<T>for custom match functions
Changes:
- Default timeout for
awaitTxIdreduced from 30 seconds to 5 seconds
Example Usage:
import { isChangeMessage } from "@tanstack/electric-db-collection" const todosCollection = createCollection( electricCollectionOptions({ onInsert: async ({ transaction, collection }) => { const newItem = transaction.mutations[0].modified await api.todos.create(newItem) // Wait for sync using custom match logic await collection.utils.awaitMatch( (message) => isChangeMessage(message) && message.headers.operation === "insert" && message.value.text === newItem.text, 5000 // timeout in ms (optional, defaults to 5000) ) }, }) )
Benefits:
- Supports backends that can't provide transaction IDs
- Flexible heuristic-based matching
- Faster feedback on sync issues with reduced timeout
- New utility method:
-
Updated dependencies [
6692aad]:- @tanstack/db@0.4.7
-
prefix logs and errors with collection id, when available (#655)
-
Updated dependencies [
dd6cdf7,c30a20b]:- @tanstack/db@0.4.6
-
The awaitTxId utility now resolves transaction IDs based on snapshot-end message metadata (xmin, xmax, xip_list) in addition to explicit txid arrays, enabling matching on the initial snapshot at the start of a new shape. (#648)
-
Updated dependencies [
7556fb6]:- @tanstack/db@0.4.5
- Updated dependencies [
32f2212]:- @tanstack/db@0.4.3
-
Fix repeated renders when markReady called when the collection was already ready. This would occur after each long poll on an Electric collection. (#604)
-
Updated dependencies [
51c6bc5,248e2c6,ce7e2b2,1b832ff]:- @tanstack/db@0.4.2
- Updated dependencies [
8cd0876]:- @tanstack/db@0.4.1
-
Refactor the main Collection class into smaller classes to make it easier to maintain. (#560)
-
Updated dependencies [
2f87216,ac6250a,2f87216]:- @tanstack/db@0.4.0
-
Pull in the latest version of @electric-sql/client instead of pinning it (#572)
-
Updated dependencies [
cacfca2]:- @tanstack/db@0.3.2
- Updated dependencies [
5f51f35]:- @tanstack/db@0.3.1
-
Refactor of the types of collection config factories for better type inference. (#530)
-
Define BaseCollectionConfig interface and let all collections extend it. (#531)
-
Updated dependencies [
b03894d,3968087]:- @tanstack/db@0.2.5
-
Fixed a bug where a live query could get stuck in "loading" state, or show incomplete data, when an electric "must-refetch" message arrived before the first "up-to-date". (#532)
-
Updated dependencies [
b162556]:- @tanstack/db@0.2.3
- fix AbortController re-initialization after a collection is garbage collected (#523)
- Updated dependencies [
33515c6]:- @tanstack/db@0.2.2
- Updated dependencies [
620ebea]:- @tanstack/db@0.2.1
- Updated dependencies [
cc4c34a]:- @tanstack/db@0.1.12
- Updated dependencies [
b869f68]:- @tanstack/db@0.1.11
- Updated dependencies [
d64b4a8]:- @tanstack/db@0.1.9
-
fix the handling of an electric must-refetch message so that the truncate is handled in the same transaction as the next up-to-date, ensuring you don't get a momentary empty collection. (#460)
-
fix disabling of gc by setting
gcTime: 0on the collection options (#463) -
Updated dependencies [
1c5e206,4d20004,968602e]:- @tanstack/db@0.1.8
- bump electric version (#454)
- Updated dependencies [
ad33e9e]:- @tanstack/db@0.1.6
- Updated dependencies [
9a5a20c]:- @tanstack/db@0.1.5
-
Add must-refetch message handling to clear synced data and re-sync collection data from server. (#412)
-
Export the
AwaitTxIdFntype to ensure that building with types works correctly. (#398) -
Updated dependencies [
c90b4d8,6c1c19c,69a6d2d,6250a92,68538b4]:- @tanstack/db@0.1.4
- Updated dependencies [
0cb7699]:- @tanstack/db@0.1.3
-
Ensure that you can use optional properties in the
selectandjoinclauses of a query, and fix an issue where standard schemas were not properly carried through to live queries. (#377) -
Updated dependencies [
bb5d50e,97b595e]:- @tanstack/db@0.1.2
- 0.1 release - first beta 🎉 (#332)
- Updated dependencies [
6e8d7f6]:- @tanstack/db@0.0.33
- Updated dependencies [
e04bd12]:- @tanstack/db@0.0.32
- Updated dependencies [
3e9a36d]:- @tanstack/db@0.0.31
- Updated dependencies [
6bdde55]:- @tanstack/db@0.0.30
-
feat: Replace string-based errors with named error classes for better error handling (#297)
This comprehensive update replaces all string-based error throws throughout the TanStack DB codebase with named error classes, providing better type safety and developer experience.
- Root
TanStackDBErrorclass - all errors inherit from a common base for unified error handling - Named error classes organized by package and functional area
- Type-safe error handling using
instanceofchecks instead of string matching - Package-specific error definitions - each adapter has its own error classes
- Better IDE support with autocomplete for error types
Contains generic errors used across the ecosystem:
- Collection configuration, state, and operation errors
- Transaction lifecycle and mutation errors
- Query building, compilation, and execution errors
- Storage and serialization errors
Each adapter now exports its own specific error classes:
@tanstack/electric-db-collection: Electric-specific errors@tanstack/trailbase-db-collection: TrailBase-specific errors@tanstack/query-db-collection: Query collection specific errors
- Error handling code using string matching will need to be updated to use
instanceofchecks - Some error messages may have slight formatting changes
- Adapter-specific errors now need to be imported from their respective packages
Before:
try { collection.insert(data) } catch (error) { if (error.message.includes("already exists")) { // Handle duplicate key error } }
After:
import { DuplicateKeyError } from "@tanstack/db" try { collection.insert(data) } catch (error) { if (error instanceof DuplicateKeyError) { // Type-safe error handling } }
Before:
// Electric collection errors were imported from @tanstack/db import { ElectricInsertHandlerMustReturnTxIdError } from "@tanstack/db"
After:
// Now import from the specific adapter package import { ElectricInsertHandlerMustReturnTxIdError } from "@tanstack/electric-db-collection"
New:
import { TanStackDBError } from "@tanstack/db" try { // Any TanStack DB operation } catch (error) { if (error instanceof TanStackDBError) { // Handle all TanStack DB errors uniformly console.log("TanStack DB error:", error.message) } }
- Type Safety: All errors now have specific types that can be caught with
instanceof - Unified Error Handling: Root
TanStackDBErrorclass allows catching all library errors with a single check - Better Package Separation: Each adapter manages its own error types
- Developer Experience: Better IDE support with autocomplete for error types
- Maintainability: Error definitions are co-located with their usage
- Consistency: Uniform error handling patterns across the entire codebase
All error classes maintain the same error messages and behavior while providing better structure and package separation.
- Root
-
Updated dependencies [
ced0657,dcfef51,360b0df,608be0c,5260ee3]:- @tanstack/db@0.0.29
- Updated dependencies [
bec8620]:- @tanstack/db@0.0.27
-
Add initial release of TrailBase collection for TanStack DB. TrailBase is a blazingly fast, open-source alternative to Firebase built on Rust, SQLite, and V8. It provides type-safe REST and realtime APIs with sub-millisecond latencies, integrated authentication, and flexible access control - all in a single executable. This collection type enables seamless integration with TrailBase backends for high-performance real-time applications. (#228)
-
Updated dependencies [
09c6995]:- @tanstack/db@0.0.26
-
Add explicit collection readiness detection with
isReady()andmarkReady()(#270)- Add
isReady()method to check if a collection is ready for use - Add
onFirstReady()method to register callbacks for when collection becomes ready - Add
markReady()to SyncConfig interface for sync implementations to explicitly signal readiness - Replace
onFirstCommit()withonFirstReady()for better semantics - Update status state machine to allow
loading→readytransition for cases with no data to commit - Update all sync implementations (Electric, Query, Local-only, Local-storage) to use
markReady() - Improve error handling by allowing collections to be marked ready even when sync errors occur
This provides a more intuitive and ergonomic API for determining collection readiness, replacing the previous approach of using commits as a readiness signal.
- Add
-
Updated dependencies [
1758eda,20f810e]:- @tanstack/db@0.0.25
- Updated dependencies [
056609e]:- @tanstack/db@0.0.23
- Updated dependencies [
aeee9a1]:- @tanstack/db@0.0.22
-
Move Collections to their own packages (#252)
- Move local-only and local-storage collections to main
@tanstack/dbpackage - Create new
@tanstack/electric-db-collectionpackage for ElectricSQL integration - Create new
@tanstack/query-db-collectionpackage for TanStack Query integration - Delete
@tanstack/db-collectionspackage (removed from repo) - Update example app and documentation to use new package structure
Why?
- Better separation of concerns
- Independent versioning for each collection type
- Cleaner dependencies (electric collections don't need query deps, etc.)
- Easier to add more collection types moving forward
- Move local-only and local-storage collections to main
-
Updated dependencies [
8e23322]:- @tanstack/db@0.0.21