feat: add toArray() for includes subqueries#1295
Conversation
🦋 Changeset detectedLatest commit: eb8ac7d The changes in this PR will be included in the next version bump. This PR includes changesets to release 12 packages
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 |
More templates
@tanstack/angular-db
@tanstack/db
@tanstack/db-ivm
@tanstack/electric-db-collection
@tanstack/offline-transactions
@tanstack/powersync-db-collection
@tanstack/query-db-collection
@tanstack/react-db
@tanstack/rxdb-db-collection
@tanstack/solid-db
@tanstack/svelte-db
@tanstack/trailbase-db-collection
@tanstack/vue-db
commit: |
|
Size Change: +440 B (+0.46%) Total Size: 96.5 kB
ℹ️ View Unchanged
|
|
Size Change: 0 B Total Size: 3.7 kB ℹ️ View Unchanged
|
260157e to
d117fea
Compare
65948a8 to
b152564
Compare
|
Review from GPT5.4: Findings
Right now I think this needs a dedicated type-level branch in the select result inference so the wrapper unwraps to the child query result array type.
The runtime coverage here is good, but there’s no A focused type test around something like |
|
This is looking very good, other than the type issue that GPT5.4 found above, the other thing we need to do is ensure there are tests that validate the reactivity model:
I believe these tests will pass, but we should have them as they are a core design feature. |
3aa7796 to
8859843
Compare
toArray() wraps an includes subquery so the parent row contains Array<T> instead of Collection<T>. When children change, the parent row is re-emitted with a fresh array snapshot. - Add ToArrayWrapper class and toArray() function - Add materializeAsArray flag to IncludesSubquery IR node - Detect ToArrayWrapper in builder, pass flag through compiler - Re-emit parent rows on child changes for toArray entries - Add SelectValue type support for ToArrayWrapper - Add tests for basic toArray, reactivity, ordering, and limits Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Make ToArrayWrapper generic so it carries the child query result type, and add a ToArrayWrapper branch in ResultTypeFromSelect to unwrap it to Array<T>. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
The toArray re-emit in flushIncludesState mutated parent items in-place before writing them through parentSyncMethods.begin/write/commit. Since commitPendingTransactions captures "previous visible state" by reading syncedData.get(key) — which returns the already-mutated object — deepEquals always returned true and suppressed the change event. Replace the sync methods pattern with direct event emission: capture a shallow copy before mutation (for previousValue), mutate in-place (so collection.get() works), and emit UPDATE events directly via the parent collection's changes manager. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Test the reactive model difference between Collection and toArray includes: - Collection includes: child change does NOT re-emit the parent row (the child Collection updates in place) - toArray includes: child change DOES re-emit the parent row (the parent row is re-emitted with the updated array snapshot) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
f491fd4 to
4c41062
Compare
Resolve conflicts to combine parent-ref-filter support (parentFilters, parentProjection) with materializeAsArray (toArray) feature from PR #1295. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Summary
toArray()wrapper that converts child Collections to plainArray<T>on parent rowsTest plan
[]🤖 Generated with Claude Code