Skip to content

Commit 7f03f25

Browse files
ci: apply automated fixes
1 parent 3415fbb commit 7f03f25

File tree

5 files changed

+44
-44
lines changed

5 files changed

+44
-44
lines changed

.changeset/multi-column-orderby-loadsubset.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
"@tanstack/db": patch
2+
'@tanstack/db': patch
33
---
44

55
Enhanced multi-column orderBy support with lazy loading and composite cursor optimization.

packages/db-collection-e2e/src/suites/pagination.suite.ts

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ export function createPaginationTestSuite(
140140
q
141141
.from({ user: usersCollection })
142142
.orderBy(({ user }) => user.isActive, `desc`)
143-
.orderBy(({ user }) => user.age, `asc`)
143+
.orderBy(({ user }) => user.age, `asc`),
144144
)
145145

146146
await query.preload()
@@ -158,7 +158,7 @@ export function createPaginationTestSuite(
158158
if (prev.isActive !== curr.isActive) {
159159
// true (1) should come before false (0) in desc order
160160
expect(prev.isActive ? 1 : 0).toBeGreaterThanOrEqual(
161-
curr.isActive ? 1 : 0
161+
curr.isActive ? 1 : 0,
162162
)
163163
} else {
164164
// If isActive is same, age should be ascending
@@ -181,7 +181,7 @@ export function createPaginationTestSuite(
181181
.from({ user: usersCollection })
182182
.orderBy(({ user }) => user.isActive, `desc`)
183183
.orderBy(({ user }) => user.age, `asc`)
184-
.limit(10)
184+
.limit(10),
185185
)
186186

187187
await query.preload()
@@ -197,7 +197,7 @@ export function createPaginationTestSuite(
197197

198198
if (prev.isActive !== curr.isActive) {
199199
expect(prev.isActive ? 1 : 0).toBeGreaterThanOrEqual(
200-
curr.isActive ? 1 : 0
200+
curr.isActive ? 1 : 0,
201201
)
202202
} else {
203203
expect(prev.age).toBeLessThanOrEqual(curr.age)
@@ -217,7 +217,7 @@ export function createPaginationTestSuite(
217217
.from({ user: usersCollection })
218218
.orderBy(({ user }) => user.isActive, `desc`)
219219
.orderBy(({ user }) => user.age, `asc`)
220-
.limit(15)
220+
.limit(15),
221221
)
222222

223223
await query1.preload()
@@ -232,7 +232,7 @@ export function createPaginationTestSuite(
232232
.from({ user: usersCollection })
233233
.orderBy(({ user }) => user.isActive, `desc`)
234234
.orderBy(({ user }) => user.age, `asc`)
235-
.limit(30)
235+
.limit(30),
236236
)
237237

238238
await query2.preload()
@@ -253,7 +253,7 @@ export function createPaginationTestSuite(
253253

254254
if (prev.isActive !== curr.isActive) {
255255
expect(prev.isActive ? 1 : 0).toBeGreaterThanOrEqual(
256-
curr.isActive ? 1 : 0
256+
curr.isActive ? 1 : 0,
257257
)
258258
} else {
259259
expect(prev.age).toBeLessThanOrEqual(curr.age)
@@ -275,7 +275,7 @@ export function createPaginationTestSuite(
275275
.from({ user: usersCollection })
276276
.orderBy(({ user }) => user.isActive, `desc`)
277277
.orderBy(({ user }) => user.age, `asc`)
278-
.limit(50)
278+
.limit(50),
279279
)
280280

281281
await query.preload()
@@ -297,7 +297,7 @@ export function createPaginationTestSuite(
297297
} else if (foundInactive) {
298298
// Found active after inactive - this is wrong
299299
throw new Error(
300-
`Found active user after inactive user in desc order`
300+
`Found active user after inactive user in desc order`,
301301
)
302302
}
303303
}
@@ -306,15 +306,15 @@ export function createPaginationTestSuite(
306306
if (activeUsers.length > 1) {
307307
for (let i = 1; i < activeUsers.length; i++) {
308308
expect(activeUsers[i - 1]!.age).toBeLessThanOrEqual(
309-
activeUsers[i]!.age
309+
activeUsers[i]!.age,
310310
)
311311
}
312312
}
313313

314314
if (inactiveUsers.length > 1) {
315315
for (let i = 1; i < inactiveUsers.length; i++) {
316316
expect(inactiveUsers[i - 1]!.age).toBeLessThanOrEqual(
317-
inactiveUsers[i]!.age
317+
inactiveUsers[i]!.age,
318318
)
319319
}
320320
}
@@ -332,7 +332,7 @@ export function createPaginationTestSuite(
332332
.from({ post: postsCollection })
333333
.orderBy(({ post }) => post.userId, `asc`)
334334
.orderBy(({ post }) => post.viewCount, `desc`)
335-
.limit(20)
335+
.limit(20),
336336
)
337337

338338
await query.preload()
@@ -355,7 +355,7 @@ export function createPaginationTestSuite(
355355
} else {
356356
// userId decreased - this is wrong
357357
throw new Error(
358-
`userId should be ascending but ${prev.userId} > ${curr.userId}`
358+
`userId should be ascending but ${prev.userId} > ${curr.userId}`,
359359
)
360360
}
361361
}
@@ -374,7 +374,7 @@ export function createPaginationTestSuite(
374374
.orderBy(({ user }) => user.isActive, `desc`)
375375
.orderBy(({ user }) => user.age, `asc`)
376376
.orderBy(({ user }) => user.name, `asc`)
377-
.limit(25)
377+
.limit(25),
378378
)
379379

380380
await query.preload()
@@ -390,7 +390,7 @@ export function createPaginationTestSuite(
390390

391391
if (prev.isActive !== curr.isActive) {
392392
expect(prev.isActive ? 1 : 0).toBeGreaterThanOrEqual(
393-
curr.isActive ? 1 : 0
393+
curr.isActive ? 1 : 0,
394394
)
395395
} else if (prev.age !== curr.age) {
396396
expect(prev.age).toBeLessThanOrEqual(curr.age)
@@ -412,7 +412,7 @@ export function createPaginationTestSuite(
412412
.from({ user: usersCollection })
413413
.orderBy(({ user }) => user.age, `asc`)
414414
.orderBy(({ user }) => user.name, `asc`)
415-
.limit(10)
415+
.limit(10),
416416
)
417417

418418
await query.preload()
@@ -483,7 +483,7 @@ export function createPaginationTestSuite(
483483
.orderBy(({ user }) => user.age, `asc`)
484484
.orderBy(({ user }) => user.name, `asc`)
485485
.limit(10)
486-
.offset(20)
486+
.offset(20),
487487
)
488488

489489
await query.preload()
@@ -533,7 +533,7 @@ export function createPaginationTestSuite(
533533
.from({ post: postsCollection })
534534
.orderBy(({ post }) => post.userId, `asc`)
535535
.orderBy(({ post }) => post.viewCount, `desc`)
536-
.limit(10)
536+
.limit(10),
537537
)
538538

539539
await query.preload()
@@ -565,7 +565,7 @@ export function createPaginationTestSuite(
565565
expect(prev.viewCount).toBeGreaterThanOrEqual(curr.viewCount)
566566
} else {
567567
throw new Error(
568-
`userId should be ascending but ${prev.userId} > ${curr.userId}`
568+
`userId should be ascending but ${prev.userId} > ${curr.userId}`,
569569
)
570570
}
571571
}
@@ -584,7 +584,7 @@ export function createPaginationTestSuite(
584584
.from({ user: usersCollection })
585585
.orderBy(({ user }) => user.age, `asc`)
586586
.orderBy(({ user }) => user.name, `asc`)
587-
.limit(20)
587+
.limit(20),
588588
)
589589

590590
await query.preload()
@@ -654,7 +654,7 @@ export function createPaginationTestSuite(
654654
.from({ user: usersCollection })
655655
.orderBy(({ user }) => user.age, `asc`)
656656
.orderBy(({ user }) => user.name, `asc`)
657-
.limit(5)
657+
.limit(5),
658658
)
659659

660660
await query.preload()
@@ -673,7 +673,7 @@ export function createPaginationTestSuite(
673673
// when we need to load data we don't have yet. This proves loading was triggered.
674674
// If it returned `true`, it would mean data was already available (no loading needed).
675675
expect(
676-
setWindowResult === true || setWindowResult instanceof Promise
676+
setWindowResult === true || setWindowResult instanceof Promise,
677677
).toBe(true)
678678

679679
if (setWindowResult !== true) {
@@ -700,12 +700,12 @@ export function createPaginationTestSuite(
700700
if (lastItemFirstPage.age === firstItemSecondPage.age) {
701701
// Same age value, so name should be greater or equal
702702
expect(
703-
firstItemSecondPage.name.localeCompare(lastItemFirstPage.name)
703+
firstItemSecondPage.name.localeCompare(lastItemFirstPage.name),
704704
).toBeGreaterThanOrEqual(0)
705705
} else {
706706
// Different age, page 2 first should have greater or equal age
707707
expect(firstItemSecondPage.age).toBeGreaterThanOrEqual(
708-
lastItemFirstPage.age
708+
lastItemFirstPage.age,
709709
)
710710
}
711711

packages/db/src/collection/subscription.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import { ensureIndexForExpression } from "../indexes/auto-index.js"
2-
import { and, eq, gt, gte, lt, or } from "../query/builder/functions.js"
3-
import { Value } from "../query/ir.js"
4-
import { EventEmitter } from "../event-emitter.js"
1+
import { ensureIndexForExpression } from '../indexes/auto-index.js'
2+
import { and, eq, gt, gte, lt, or } from '../query/builder/functions.js'
3+
import { Value } from '../query/ir.js'
4+
import { EventEmitter } from '../event-emitter.js'
55
import {
66
createFilterFunctionFromExpression,
77
createFilteredCallback,
@@ -55,7 +55,7 @@ type CollectionSubscriptionOptions = {
5555
*/
5656
function buildCompositeCursor(
5757
orderBy: OrderBy,
58-
values: Array<unknown>
58+
values: Array<unknown>,
5959
): BasicExpression<boolean> | undefined {
6060
if (values.length === 0 || orderBy.length === 0) {
6161
return undefined
@@ -392,7 +392,7 @@ export class CollectionSubscription
392392
const keysGreaterThanMin = index.take(
393393
limit - keys.length,
394394
minValueForIndex,
395-
filterFn
395+
filterFn,
396396
)
397397
keys.push(...keysGreaterThanMin)
398398
} else {

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

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -139,15 +139,15 @@ export function processOrderBy(
139139
const followRefResult = followRef(
140140
rawQuery,
141141
firstOrderByExpression,
142-
collection
142+
collection,
143143
)
144144

145145
if (followRefResult) {
146146
followRefCollection = followRefResult.collection
147147
const fieldName = followRefResult.path[0]
148148
const compareOpts = buildCompareOptions(
149149
firstClause,
150-
followRefCollection
150+
followRefCollection,
151151
)
152152

153153
if (fieldName) {
@@ -156,14 +156,14 @@ export function processOrderBy(
156156
followRefResult.path,
157157
followRefCollection,
158158
compareOpts,
159-
compare
159+
compare,
160160
)
161161
}
162162

163163
// First column value extractor - used for index cursor
164164
firstColumnValueExtractor = compileExpression(
165165
new PropRef(followRefResult.path),
166-
true
166+
true,
167167
) as CompiledSingleRowExpression
168168

169169
index = findIndexForField(
@@ -193,7 +193,7 @@ export function processOrderBy(
193193
// Build value extractors for all columns (must all be ref expressions for multi-column)
194194
// Check if all orderBy expressions are ref types (required for multi-column extraction)
195195
const allColumnsAreRefs = orderByClause.every(
196-
(clause) => clause.expression.type === `ref`
196+
(clause) => clause.expression.type === `ref`,
197197
)
198198

199199
// Create extractors for all columns if they're all refs
@@ -207,13 +207,13 @@ export function processOrderBy(
207207
if (followResult) {
208208
return compileExpression(
209209
new PropRef(followResult.path),
210-
true
210+
true,
211211
) as CompiledSingleRowExpression
212212
}
213213
// Fallback for refs that don't follow
214214
return compileExpression(
215215
clause.expression,
216-
true
216+
true,
217217
) as CompiledSingleRowExpression
218218
})
219219
: undefined
@@ -222,7 +222,7 @@ export function processOrderBy(
222222
// This compares ALL orderBy columns for proper ordering
223223
const comparator = (
224224
a: Record<string, unknown> | null | undefined,
225-
b: Record<string, unknown> | null | undefined
225+
b: Record<string, unknown> | null | undefined,
226226
) => {
227227
if (orderByClause.length === 1) {
228228
// Single column: extract and compare
@@ -233,7 +233,7 @@ export function processOrderBy(
233233
if (allColumnExtractors) {
234234
// Multi-column with all refs: extract all values and compare
235235
const extractAll = (
236-
row: Record<string, unknown> | null | undefined
236+
row: Record<string, unknown> | null | undefined,
237237
) => {
238238
if (!row) return row
239239
return allColumnExtractors.map((extractor) => extractor(row))

packages/db/tests/query/live-query-collection.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2075,7 +2075,7 @@ describe(`createLiveQueryCollection`, () => {
20752075
q
20762076
.from({ item: baseCollection })
20772077
.orderBy(({ item }) => item.age, `asc`)
2078-
.limit(10)
2078+
.limit(10),
20792079
)
20802080

20812081
// Trigger sync which will call loadSubset
@@ -2086,7 +2086,7 @@ describe(`createLiveQueryCollection`, () => {
20862086

20872087
// Find the call that has orderBy (the limited snapshot request)
20882088
const callWithOrderBy = capturedOptions.find(
2089-
(opt) => opt.orderBy !== undefined
2089+
(opt) => opt.orderBy !== undefined,
20902090
)
20912091
expect(callWithOrderBy).toBeDefined()
20922092
expect(callWithOrderBy?.orderBy).toHaveLength(1)
@@ -2132,7 +2132,7 @@ describe(`createLiveQueryCollection`, () => {
21322132
.from({ item: baseCollection })
21332133
.orderBy(({ item }) => item.department, `asc`)
21342134
.orderBy(({ item }) => item.age, `desc`)
2135-
.limit(10)
2135+
.limit(10),
21362136
)
21372137

21382138
// Trigger sync which will call loadSubset
@@ -2143,7 +2143,7 @@ describe(`createLiveQueryCollection`, () => {
21432143

21442144
// Find the call that has orderBy with multiple columns
21452145
const callWithMultiOrderBy = capturedOptions.find(
2146-
(opt) => opt.orderBy !== undefined && opt.orderBy.length > 1
2146+
(opt) => opt.orderBy !== undefined && opt.orderBy.length > 1,
21472147
)
21482148

21492149
// Multi-column orderBy should be passed to loadSubset so the sync layer

0 commit comments

Comments
 (0)