|
29 | 29 | 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.
|
30 | 30 |
|
31 | 31 | ## New Features
|
| 32 | + |
32 | 33 | - **Root `TanStackDBError` class** - all errors inherit from a common base for unified error handling
|
33 | 34 | - **Named error classes** organized by package and functional area
|
34 | 35 | - **Type-safe error handling** using `instanceof` checks instead of string matching
|
|
40 | 41 | ### Core Package (`@tanstack/db`)
|
41 | 42 |
|
42 | 43 | Contains generic errors used across the ecosystem:
|
| 44 | + |
43 | 45 | - Collection configuration, state, and operation errors
|
44 | 46 | - Transaction lifecycle and mutation errors
|
45 | 47 | - Query building, compilation, and execution errors
|
|
48 | 50 | ### Adapter Packages
|
49 | 51 |
|
50 | 52 | Each adapter now exports its own specific error classes:
|
| 53 | + |
51 | 54 | - **`@tanstack/electric-db-collection`**: Electric-specific errors
|
52 | 55 | - **`@tanstack/trailbase-db-collection`**: TrailBase-specific errors
|
53 | 56 | - **`@tanstack/query-db-collection`**: Query collection specific errors
|
54 | 57 |
|
55 | 58 | ## Breaking Changes
|
| 59 | + |
56 | 60 | - Error handling code using string matching will need to be updated to use `instanceof` checks
|
57 | 61 | - Some error messages may have slight formatting changes
|
58 | 62 | - Adapter-specific errors now need to be imported from their respective packages
|
|
121 | 125 | ```
|
122 | 126 |
|
123 | 127 | ## Benefits
|
| 128 | + |
124 | 129 | - **Type Safety**: All errors now have specific types that can be caught with `instanceof`
|
125 | 130 | - **Unified Error Handling**: Root `TanStackDBError` class allows catching all library errors with a single check
|
126 | 131 | - **Better Package Separation**: Each adapter manages its own error types
|
|
139 | 144 | - Add comprehensive documentation for creating collection options creators ([#284](https://github.com/TanStack/db/pull/284))
|
140 | 145 |
|
141 | 146 | This adds a new documentation page `collection-options-creator.md` that provides detailed guidance for developers building collection options creators. The documentation covers:
|
| 147 | + |
142 | 148 | - Core requirements and configuration interfaces
|
143 | 149 | - Sync implementation patterns with transaction lifecycle (begin, write, commit, markReady)
|
144 | 150 | - Data parsing and type conversion using field-specific conversions
|
|
171 | 177 | - Fix iterator-based change tracking in proxy system ([#271](https://github.com/TanStack/db/pull/271))
|
172 | 178 |
|
173 | 179 | This fixes several issues with iterator-based change tracking for Maps and Sets:
|
| 180 | + |
174 | 181 | - **Map.entries()** now correctly updates actual Map entries instead of creating duplicate keys
|
175 | 182 | - **Map.values()** now tracks back to original Map keys using value-to-key mapping instead of using symbol placeholders
|
176 | 183 | - **Set iterators** now properly replace objects in Set when modified instead of creating symbol-keyed entries
|
|
181 | 188 | This brings the proxy system in line with how mature libraries like Immer handle iterator-based change tracking, using method interception rather than trying to proxy all property access.
|
182 | 189 |
|
183 | 190 | - Add explicit collection readiness detection with `isReady()` and `markReady()` ([#270](https://github.com/TanStack/db/pull/270))
|
| 191 | + |
184 | 192 | - Add `isReady()` method to check if a collection is ready for use
|
185 | 193 | - Add `onFirstReady()` method to register callbacks for when collection becomes ready
|
186 | 194 | - Add `markReady()` to SyncConfig interface for sync implementations to explicitly signal readiness
|
|
222 | 230 | ### Patch Changes
|
223 | 231 |
|
224 | 232 | - Move Collections to their own packages ([#252](https://github.com/TanStack/db/pull/252))
|
| 233 | + |
225 | 234 | - Move local-only and local-storage collections to main `@tanstack/db` package
|
226 | 235 | - Create new `@tanstack/electric-db-collection` package for Electric SQL integration
|
227 | 236 | - Create new `@tanstack/query-db-collection` package for TanStack Query integration
|
228 | 237 | - Delete `@tanstack/db-collections` package (removed from repo)
|
229 | 238 | - Update example app and documentation to use new package structure
|
230 | 239 |
|
231 | 240 | Why?
|
| 241 | + |
232 | 242 | - Better separation of concerns
|
233 | 243 | - Independent versioning for each collection type
|
234 | 244 | - Cleaner dependencies (electric collections don't need query deps, etc.)
|
|
292 | 302 | Adds automatic lifecycle management for collections to optimize resource usage.
|
293 | 303 |
|
294 | 304 | **New Features:**
|
| 305 | + |
295 | 306 | - Added `startSync` option (defaults to `false`, set to `true` to start syncing immediately)
|
296 | 307 | - Automatic garbage collection after `gcTime` (default 5 minutes) of inactivity
|
297 | 308 | - Collection status tracking: "idle" | "loading" | "ready" | "error" | "cleaned-up"
|
|
399 | 410 | - refactor the live query comparator and fix an issue with sorting with a null/undefined value in a column of non-null values ([#167](https://github.com/TanStack/db/pull/167))
|
400 | 411 |
|
401 | 412 | - A large refactor of the core `Collection` with: ([#155](https://github.com/TanStack/db/pull/155))
|
| 413 | + |
402 | 414 | - a change to not use Store internally and emit fine grade changes with `subscribeChanges` and `subscribeKeyChanges` methods.
|
403 | 415 | - changes to the `Collection` api to be more `Map` like for reads, with `get`, `has`, `size`, `entries`, `keys`, and `values`.
|
404 | 416 | - renames `config.getId` to `config.getKey` for consistency with the `Map` like api.
|
|
416 | 428 | - Expose utilities on collection instances ([#161](https://github.com/TanStack/db/pull/161))
|
417 | 429 |
|
418 | 430 | Implemented a utility exposure pattern for TanStack DB collections that allows utility functions to be passed as part of collection options and exposes them under a `.utils` namespace, with full TypeScript typing.
|
| 431 | + |
419 | 432 | - Refactored `createCollection` in packages/db/src/collection.ts to accept options with utilities directly
|
420 | 433 | - Added `utils` property to CollectionImpl
|
421 | 434 | - Added TypeScript types for utility functions and utility records
|
|
439 | 452 | When `collection.insert()`, `.update()`, or `.delete()` are called outside of an explicit transaction (i.e., not within `useOptimisticMutation`), the library now automatically creates a single-operation transaction and invokes the corresponding handler to persist the change.
|
440 | 453 |
|
441 | 454 | Key changes:
|
| 455 | + |
442 | 456 | - **`@tanstack/db`**: The `Collection` class now supports `onInsert`, `onUpdate`, and `onDelete` in its configuration. Direct calls to mutation methods will throw an error if the corresponding handler is not defined.
|
443 | 457 | - **`@tanstack/db-collections`**:
|
444 | 458 | - `queryCollectionOptions` now accepts the new handlers and will automatically `refetch` the collection's query after a handler successfully completes. This behavior can be disabled if the handler returns `{ refetch: false }`.
|
|
450 | 464 | ***
|
451 | 465 |
|
452 | 466 | The documentation and the React Todo example application have been significantly refactored to adopt the new direct persistence handler pattern as the primary way to perform mutations.
|
| 467 | + |
453 | 468 | - The `README.md` and `docs/overview.md` files have been updated to de-emphasize `useOptimisticMutation` for simple writes. They now showcase the much simpler API of calling `collection.insert()` directly and defining persistence logic in the collection's configuration.
|
454 | 469 | - The React Todo example (`examples/react/todo/src/App.tsx`) has been completely overhauled. All instances of `useOptimisticMutation` have been removed and replaced with the new `onInsert`, `onUpdate`, and `onDelete` handlers, resulting in cleaner and more concise code.
|
455 | 470 |
|
|
0 commit comments