Skip to content

Commit 16ac62b

Browse files
ci: apply automated fixes
1 parent 1c2728c commit 16ac62b

4 files changed

Lines changed: 118 additions & 134 deletions

File tree

packages/db/src/query/compiler/index.ts

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
1-
import {
2-
distinct,
3-
filter,
4-
join as joinOperator,
5-
map,
6-
} from '@tanstack/db-ivm'
1+
import { distinct, filter, join as joinOperator, map } from '@tanstack/db-ivm'
72
import { optimizeQuery } from '../optimizer.js'
83
import {
94
CollectionInputNotFoundError,
@@ -203,9 +198,7 @@ export function compileQuery(
203198
)
204199

205200
// Inner join: only children whose correlation key exists in parent keys pass through
206-
const joined = childRekeyed.pipe(
207-
joinOperator(parentKeyStream, `inner`),
208-
)
201+
const joined = childRekeyed.pipe(joinOperator(parentKeyStream, `inner`))
209202

210203
// Extract: [correlationValue, [[childKey, childRow], null]] → [childKey, childRow]
211204
// Tag the row with __correlationKey for output routing
@@ -323,7 +316,9 @@ export function compileQuery(
323316
fieldName: subquery.fieldName,
324317
correlationField: subquery.correlationField,
325318
childCorrelationField: subquery.childCorrelationField,
326-
hasOrderBy: !!(subquery.query.orderBy && subquery.query.orderBy.length > 0),
319+
hasOrderBy: !!(
320+
subquery.query.orderBy && subquery.query.orderBy.length > 0
321+
),
327322
childCompilationResult: childResult,
328323
})
329324

@@ -438,7 +433,8 @@ export function compileQuery(
438433
// When in includes mode with limit/offset, use grouped ordering so that
439434
// the limit is applied per parent (per correlation key), not globally.
440435
const includesGroupKeyFn =
441-
parentKeyStream && (query.limit !== undefined || query.offset !== undefined)
436+
parentKeyStream &&
437+
(query.limit !== undefined || query.offset !== undefined)
442438
? (_key: unknown, row: unknown) =>
443439
(row as any)?.[mainSource]?.__correlationKey
444440
: undefined
@@ -479,8 +475,7 @@ export function compileQuery(
479475
sourceWhereClauses,
480476
aliasToCollectionId,
481477
aliasRemapping,
482-
includes:
483-
includesResults.length > 0 ? includesResults : undefined,
478+
includes: includesResults.length > 0 ? includesResults : undefined,
484479
}
485480
cache.set(rawQuery, compilationResult)
486481

@@ -516,8 +511,7 @@ export function compileQuery(
516511
sourceWhereClauses,
517512
aliasToCollectionId,
518513
aliasRemapping,
519-
includes:
520-
includesResults.length > 0 ? includesResults : undefined,
514+
includes: includesResults.length > 0 ? includesResults : undefined,
521515
}
522516
cache.set(rawQuery, compilationResult)
523517

packages/db/src/query/compiler/order-by.ts

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
import { groupedOrderByWithFractionalIndex, orderByWithFractionalIndex } from '@tanstack/db-ivm'
1+
import {
2+
groupedOrderByWithFractionalIndex,
3+
orderByWithFractionalIndex,
4+
} from '@tanstack/db-ivm'
25
import { defaultComparator, makeComparator } from '../../utils/comparison.js'
36
import { PropRef, followRef } from '../ir.js'
47
import { ensureIndexForField } from '../../indexes/auto-index.js'
@@ -306,17 +309,15 @@ export function processOrderBy(
306309
setWindowFn: (
307310
windowFn: (options: { offset?: number; limit?: number }) => void,
308311
) => {
309-
setWindowFn(
310-
(options) => {
311-
windowFn(options)
312-
if (orderByOptimizationInfo) {
313-
orderByOptimizationInfo.offset =
314-
options.offset ?? orderByOptimizationInfo.offset
315-
orderByOptimizationInfo.limit =
316-
options.limit ?? orderByOptimizationInfo.limit
317-
}
318-
},
319-
)
312+
setWindowFn((options) => {
313+
windowFn(options)
314+
if (orderByOptimizationInfo) {
315+
orderByOptimizationInfo.offset =
316+
options.offset ?? orderByOptimizationInfo.offset
317+
orderByOptimizationInfo.limit =
318+
options.limit ?? orderByOptimizationInfo.limit
319+
}
320+
})
320321
},
321322
}),
322323
)

packages/db/src/query/live/collection-config-builder.ts

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -731,7 +731,10 @@ export class CollectionConfigBuilder<
731731
)
732732

733733
// Set up includes output routing and child collection lifecycle
734-
const includesState = this.setupIncludesOutput(this.includesCache, syncState)
734+
const includesState = this.setupIncludesOutput(
735+
this.includesCache,
736+
syncState,
737+
)
735738

736739
// Flush pending changes and reset the accumulator.
737740
// Called at the end of each graph run to commit all accumulated changes.
@@ -829,10 +832,7 @@ export class CollectionConfigBuilder<
829832
const messages = data.getInner()
830833
syncState.messagesCount += messages.length
831834

832-
for (const [
833-
[childKey, tupleData],
834-
multiplicity,
835-
] of messages) {
835+
for (const [[childKey, tupleData], multiplicity] of messages) {
836836
const [childResult, _orderByIndex, correlationKey] =
837837
tupleData as unknown as [any, string | undefined, unknown]
838838

@@ -1346,7 +1346,14 @@ function createChildCollectionEntry(
13461346
startSync: true,
13471347
})
13481348

1349-
return { collection, get syncMethods() { return syncMethods }, resultKeys, orderByIndices }
1349+
return {
1350+
collection,
1351+
get syncMethods() {
1352+
return syncMethods
1353+
},
1354+
resultKeys,
1355+
orderByIndices,
1356+
}
13501357
}
13511358

13521359
/**
@@ -1396,10 +1403,7 @@ function flushIncludesState(
13961403

13971404
// Flush child changes: route to correct child Collections
13981405
if (state.pendingChildChanges.size > 0) {
1399-
for (const [
1400-
correlationKey,
1401-
childChanges,
1402-
] of state.pendingChildChanges) {
1406+
for (const [correlationKey, childChanges] of state.pendingChildChanges) {
14031407
// Ensure child Collection exists for this correlation key
14041408
let entry = state.childRegistry.get(correlationKey)
14051409
if (!entry) {
@@ -1509,7 +1513,7 @@ function attachChildCollectionToParent(
15091513

15101514
if (value === correlationKey) {
15111515
// Set the child Collection on this parent row
1512-
;(item)[fieldName] = childCollection
1516+
item[fieldName] = childCollection
15131517
}
15141518
}
15151519
}

packages/db/tests/query/includes.test.ts

Lines changed: 81 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -113,19 +113,17 @@ describe(`includes subqueries`, () => {
113113

114114
function buildIncludesQuery() {
115115
return createLiveQueryCollection((q) =>
116-
q
117-
.from({ p: projects })
118-
.select(({ p }) => ({
119-
id: p.id,
120-
name: p.name,
121-
issues: q
122-
.from({ i: issues })
123-
.where(({ i }) => eq(i.projectId, p.id))
124-
.select(({ i }) => ({
125-
id: i.id,
126-
title: i.title,
127-
})),
128-
})),
116+
q.from({ p: projects }).select(({ p }) => ({
117+
id: p.id,
118+
name: p.name,
119+
issues: q
120+
.from({ i: issues })
121+
.where(({ i }) => eq(i.projectId, p.id))
122+
.select(({ i }) => ({
123+
id: i.id,
124+
title: i.title,
125+
})),
126+
})),
129127
)
130128
}
131129

@@ -155,8 +153,7 @@ describe(`includes subqueries`, () => {
155153
},
156154
])
157155
})
158-
159-
})
156+
})
160157

161158
describe(`reactivity`, () => {
162159
it(`adding a child updates the parent's child collection`, async () => {
@@ -299,20 +296,18 @@ describe(`includes subqueries`, () => {
299296
describe(`ordered child queries`, () => {
300297
it(`child collection respects orderBy on the child query`, async () => {
301298
const collection = createLiveQueryCollection((q) =>
302-
q
303-
.from({ p: projects })
304-
.select(({ p }) => ({
305-
id: p.id,
306-
name: p.name,
307-
issues: q
308-
.from({ i: issues })
309-
.where(({ i }) => eq(i.projectId, p.id))
310-
.orderBy(({ i }) => i.title, `desc`)
311-
.select(({ i }) => ({
312-
id: i.id,
313-
title: i.title,
314-
})),
315-
})),
299+
q.from({ p: projects }).select(({ p }) => ({
300+
id: p.id,
301+
name: p.name,
302+
issues: q
303+
.from({ i: issues })
304+
.where(({ i }) => eq(i.projectId, p.id))
305+
.orderBy(({ i }) => i.title, `desc`)
306+
.select(({ i }) => ({
307+
id: i.id,
308+
title: i.title,
309+
})),
310+
})),
316311
)
317312

318313
await collection.preload()
@@ -338,20 +333,18 @@ describe(`includes subqueries`, () => {
338333

339334
it(`newly inserted children appear in the correct order`, async () => {
340335
const collection = createLiveQueryCollection((q) =>
341-
q
342-
.from({ p: projects })
343-
.select(({ p }) => ({
344-
id: p.id,
345-
name: p.name,
346-
issues: q
347-
.from({ i: issues })
348-
.where(({ i }) => eq(i.projectId, p.id))
349-
.orderBy(({ i }) => i.title, `asc`)
350-
.select(({ i }) => ({
351-
id: i.id,
352-
title: i.title,
353-
})),
354-
})),
336+
q.from({ p: projects }).select(({ p }) => ({
337+
id: p.id,
338+
name: p.name,
339+
issues: q
340+
.from({ i: issues })
341+
.where(({ i }) => eq(i.projectId, p.id))
342+
.orderBy(({ i }) => i.title, `asc`)
343+
.select(({ i }) => ({
344+
id: i.id,
345+
title: i.title,
346+
})),
347+
})),
355348
)
356349

357350
await collection.preload()
@@ -382,21 +375,19 @@ describe(`includes subqueries`, () => {
382375
describe(`ordered child queries with limit`, () => {
383376
it(`limits child collection to N items per parent`, async () => {
384377
const collection = createLiveQueryCollection((q) =>
385-
q
386-
.from({ p: projects })
387-
.select(({ p }) => ({
388-
id: p.id,
389-
name: p.name,
390-
issues: q
391-
.from({ i: issues })
392-
.where(({ i }) => eq(i.projectId, p.id))
393-
.orderBy(({ i }) => i.title, `asc`)
394-
.limit(1)
395-
.select(({ i }) => ({
396-
id: i.id,
397-
title: i.title,
398-
})),
399-
})),
378+
q.from({ p: projects }).select(({ p }) => ({
379+
id: p.id,
380+
name: p.name,
381+
issues: q
382+
.from({ i: issues })
383+
.where(({ i }) => eq(i.projectId, p.id))
384+
.orderBy(({ i }) => i.title, `asc`)
385+
.limit(1)
386+
.select(({ i }) => ({
387+
id: i.id,
388+
title: i.title,
389+
})),
390+
})),
400391
)
401392

402393
await collection.preload()
@@ -420,31 +411,27 @@ describe(`includes subqueries`, () => {
420411

421412
it(`inserting a child that displaces an existing one respects the limit`, async () => {
422413
const collection = createLiveQueryCollection((q) =>
423-
q
424-
.from({ p: projects })
425-
.select(({ p }) => ({
426-
id: p.id,
427-
name: p.name,
428-
issues: q
429-
.from({ i: issues })
430-
.where(({ i }) => eq(i.projectId, p.id))
431-
.orderBy(({ i }) => i.title, `asc`)
432-
.limit(1)
433-
.select(({ i }) => ({
434-
id: i.id,
435-
title: i.title,
436-
})),
437-
})),
414+
q.from({ p: projects }).select(({ p }) => ({
415+
id: p.id,
416+
name: p.name,
417+
issues: q
418+
.from({ i: issues })
419+
.where(({ i }) => eq(i.projectId, p.id))
420+
.orderBy(({ i }) => i.title, `asc`)
421+
.limit(1)
422+
.select(({ i }) => ({
423+
id: i.id,
424+
title: i.title,
425+
})),
426+
})),
438427
)
439428

440429
await collection.preload()
441430

442431
// Alpha should have exactly 1 issue (limit 1): "Bug in Alpha"
443432
const alphaIssues = [...(collection.get(1) as any).issues.toArray]
444433
expect(alphaIssues).toHaveLength(1)
445-
expect(alphaIssues).toEqual([
446-
{ id: 10, title: `Bug in Alpha` },
447-
])
434+
expect(alphaIssues).toEqual([{ id: 10, title: `Bug in Alpha` }])
448435

449436
// Insert an issue that comes before "Bug" alphabetically
450437
issues.utils.begin()
@@ -469,26 +456,24 @@ describe(`includes subqueries`, () => {
469456
describe(`nested includes`, () => {
470457
it(`supports two levels of includes`, async () => {
471458
const collection = createLiveQueryCollection((q) =>
472-
q
473-
.from({ p: projects })
474-
.select(({ p }) => ({
475-
id: p.id,
476-
name: p.name,
477-
issues: q
478-
.from({ i: issues })
479-
.where(({ i }) => eq(i.projectId, p.id))
480-
.select(({ i }) => ({
481-
id: i.id,
482-
title: i.title,
483-
comments: q
484-
.from({ c: comments })
485-
.where(({ c }) => eq(c.issueId, i.id))
486-
.select(({ c }) => ({
487-
id: c.id,
488-
body: c.body,
489-
})),
490-
})),
491-
})),
459+
q.from({ p: projects }).select(({ p }) => ({
460+
id: p.id,
461+
name: p.name,
462+
issues: q
463+
.from({ i: issues })
464+
.where(({ i }) => eq(i.projectId, p.id))
465+
.select(({ i }) => ({
466+
id: i.id,
467+
title: i.title,
468+
comments: q
469+
.from({ c: comments })
470+
.where(({ c }) => eq(c.issueId, i.id))
471+
.select(({ c }) => ({
472+
id: c.id,
473+
body: c.body,
474+
})),
475+
})),
476+
})),
492477
)
493478

494479
await collection.preload()

0 commit comments

Comments
 (0)