Skip to content

Expose utilities on collection instances - #161

Merged
KyleAMathews merged 3 commits into
mainfrom
fix-utils
Jun 11, 2025
Merged

KyleAMathews merged 3 commits into
mainfrom
fix-utils

Conversation

@KyleAMathews

@KyleAMathews KyleAMathews commented Jun 11, 2025 •

Copy link
Copy Markdown
Collaborator

Fix #159

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.

Changes

  • Refactored createCollection in packages/db/src/collection.ts to accept options with utilities directly
  • Added utils property to CollectionImpl
  • Added TypeScript types for utility functions and utility records
  • Changed Collection from a class to a type, updating all usages to use createCollection() instead
  • Updated Electric/Query implementations

Benefits

  • Utilities are now ergonomically accessible under .utils
  • Full TypeScript typing is preserved for both collection data and utilities
  • API is clean and straightforward - users can call createCollection(optionsCreator(config)) directly
  • Zero-boilerplate TypeScript pattern that infers utility types automatically

@changeset-bot

changeset-bot Bot commented Jun 11, 2025 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: e2d1433

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 5 packages
Name Type
@tanstack/db-collections Patch
@tanstack/react-db Patch
@tanstack/vue-db Patch
@tanstack/db Patch
@tanstack/db-example-react-todo Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@KyleAMathews
KyleAMathews requested a review from samwillis June 11, 2025 17:07
@pkg-pr-new

pkg-pr-new Bot commented Jun 11, 2025 •

Copy link
Copy Markdown

@tanstack/db-example-react-todo

npm i https://pkg.pr.new/@tanstack/db@161
npm i https://pkg.pr.new/@tanstack/db-collections@161
npm i https://pkg.pr.new/@tanstack/react-db@161
npm i https://pkg.pr.new/@tanstack/vue-db@161

commit: e2d1433

@samwillis samwillis left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great! :shipit:

@KyleAMathews
KyleAMathews merged commit 8b43ad3 into main Jun 11, 2025
@KyleAMathews
KyleAMathews deleted the fix-utils branch June 11, 2025 18:19
@github-actions github-actions Bot mentioned this pull request Jun 11, 2025
cursor Bot pushed a commit that referenced this pull request Jul 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add support for setting utility functions on collections

2 participants