Skip to content

Latest commit

 

History

History
524 lines (330 loc) · 20.8 KB

File metadata and controls

524 lines (330 loc) · 20.8 KB

@tanstack/electric-db-collection

0.1.32

Patch Changes

0.1.31

Patch Changes

  • feat: Add awaitMatch utility and reduce default timeout (#402) (#499)

    Adds a new awaitMatch utility function to support custom synchronization matching logic when transaction IDs (txids) are not available. Also reduces the default timeout for awaitTxId from 30 seconds to 5 seconds for faster feedback.

    New Features:

    • New utility method: collection.utils.awaitMatch(matchFn, timeout?) - Wait for custom match logic
    • Export isChangeMessage and isControlMessage helper functions for custom match functions
    • Type: MatchFunction<T> for custom match functions

    Changes:

    • Default timeout for awaitTxId reduced 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
  • Updated dependencies [6692aad]:

    • @tanstack/db@0.4.7

0.1.30

Patch Changes

  • prefix logs and errors with collection id, when available (#655)

  • Updated dependencies [dd6cdf7, c30a20b]:

    • @tanstack/db@0.4.6

0.1.29

Patch Changes

  • 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

0.1.28

Patch Changes

0.1.27

Patch Changes

  • Updated dependencies [32f2212]:
    • @tanstack/db@0.4.3

0.1.26

Patch Changes

  • 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

0.1.25

Patch Changes

  • Updated dependencies [8cd0876]:
    • @tanstack/db@0.4.1

0.1.24

Patch Changes

  • 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

0.1.23

Patch Changes

  • Pull in the latest version of @electric-sql/client instead of pinning it (#572)

  • Updated dependencies [cacfca2]:

    • @tanstack/db@0.3.2

0.1.22

Patch Changes

  • Updated dependencies [5f51f35]:
    • @tanstack/db@0.3.1

0.1.21

Patch Changes

0.1.20

Patch Changes

  • 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

0.1.19

Patch Changes

0.1.18

Patch Changes

  • 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

0.1.17

Patch Changes

  • fix AbortController re-initialization after a collection is garbage collected (#523)

0.1.16

Patch Changes

  • Updated dependencies [33515c6]:
    • @tanstack/db@0.2.2

0.1.15

Patch Changes

  • Updated dependencies [620ebea]:
    • @tanstack/db@0.2.1

0.1.14

Patch Changes

0.1.13

Patch Changes

  • Updated dependencies [cc4c34a]:
    • @tanstack/db@0.1.12

0.1.12

Patch Changes

  • Updated dependencies [b869f68]:
    • @tanstack/db@0.1.11

0.1.11

Patch Changes

0.1.10

Patch Changes

  • Updated dependencies [d64b4a8]:
    • @tanstack/db@0.1.9

0.1.9

Patch Changes

  • 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: 0 on the collection options (#463)

  • Updated dependencies [1c5e206, 4d20004, 968602e]:

    • @tanstack/db@0.1.8

0.1.8

Patch Changes

  • bump electric version (#454)

0.1.7

Patch Changes

0.1.6

Patch Changes

  • Updated dependencies [ad33e9e]:
    • @tanstack/db@0.1.6

0.1.5

Patch Changes

  • Updated dependencies [9a5a20c]:
    • @tanstack/db@0.1.5

0.1.4

Patch Changes

  • Add must-refetch message handling to clear synced data and re-sync collection data from server. (#412)

  • Export the AwaitTxIdFn type to ensure that building with types works correctly. (#398)

  • Updated dependencies [c90b4d8, 6c1c19c, 69a6d2d, 6250a92, 68538b4]:

    • @tanstack/db@0.1.4

0.1.3

Patch Changes

  • Updated dependencies [0cb7699]:
    • @tanstack/db@0.1.3

0.1.2

Patch Changes

  • Ensure that you can use optional properties in the select and join clauses 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.1

Patch Changes

0.1.0

Minor Changes

  • 0.1 release - first beta 🎉 (#332)

Patch Changes

0.0.15

Patch Changes

  • Updated dependencies [6e8d7f6]:
    • @tanstack/db@0.0.33

0.0.14

Patch Changes

  • Updated dependencies [e04bd12]:
    • @tanstack/db@0.0.32

0.0.13

Patch Changes

  • Updated dependencies [3e9a36d]:
    • @tanstack/db@0.0.31

0.0.12

Patch Changes

  • Updated dependencies [6bdde55]:
    • @tanstack/db@0.0.30

0.0.11

Patch Changes

  • 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.

    New Features

    • Root TanStackDBError class - 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 instanceof checks instead of string matching
    • Package-specific error definitions - each adapter has its own error classes
    • Better IDE support with autocomplete for error types

    Package Structure

    Core Package (@tanstack/db)

    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

    Adapter Packages

    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

    Breaking Changes

    • Error handling code using string matching will need to be updated to use instanceof checks
    • Some error messages may have slight formatting changes
    • Adapter-specific errors now need to be imported from their respective packages

    Migration Guide

    Core DB Errors

    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
      }
    }

    Adapter-Specific Errors

    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"

    Unified Error Handling

    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)
      }
    }

    Benefits

    • Type Safety: All errors now have specific types that can be caught with instanceof
    • Unified Error Handling: Root TanStackDBError class 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.

  • Updated dependencies [ced0657, dcfef51, 360b0df, 608be0c, 5260ee3]:

    • @tanstack/db@0.0.29

0.0.10

Patch Changes

0.0.9

Patch Changes

  • Updated dependencies [bec8620]:
    • @tanstack/db@0.0.27

0.0.8

Patch Changes

  • 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

0.0.7

Patch Changes

  • Add explicit collection readiness detection with isReady() and markReady() (#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() with onFirstReady() for better semantics
    • Update status state machine to allow loadingready transition 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.

  • Updated dependencies [1758eda, 20f810e]:

    • @tanstack/db@0.0.25

0.0.6

Patch Changes

0.0.5

Patch Changes

  • Updated dependencies [056609e]:
    • @tanstack/db@0.0.23

0.0.4

Patch Changes

  • Updated dependencies [aeee9a1]:
    • @tanstack/db@0.0.22

0.0.3

Patch Changes

  • Move Collections to their own packages (#252)

    • Move local-only and local-storage collections to main @tanstack/db package
    • Create new @tanstack/electric-db-collection package for ElectricSQL integration
    • Create new @tanstack/query-db-collection package for TanStack Query integration
    • Delete @tanstack/db-collections package (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
  • Updated dependencies [8e23322]:

    • @tanstack/db@0.0.21