Skip to content

Commit 3ecdb1f

Browse files
ci: apply automated fixes
1 parent 60c1709 commit 3ecdb1f

5 files changed

Lines changed: 30 additions & 33 deletions

File tree

.changeset/deterministic-collection-ordering.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
Ensure deterministic iteration order for collections and indexes.

packages/db/src/SortedMap.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { compareKeys } from "@tanstack/db-ivm"
1+
import { compareKeys } from '@tanstack/db-ivm'
22

33
/**
44
* A Map implementation that keeps its entries sorted based on a comparator function

packages/db/src/indexes/btree-index.ts

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
1-
import { compareKeys } from "@tanstack/db-ivm"
2-
import { BTree } from "../utils/btree.js"
3-
import {
4-
defaultComparator,
5-
normalizeValue,
6-
} from "../utils/comparison.js"
7-
import { BaseIndex } from "./base-index.js"
8-
import type { CompareOptions } from "../query/builder/types.js"
9-
import type { BasicExpression } from "../query/ir.js"
10-
import type { IndexOperation } from "./base-index.js"
1+
import { compareKeys } from '@tanstack/db-ivm'
2+
import { BTree } from '../utils/btree.js'
3+
import { defaultComparator, normalizeValue } from '../utils/comparison.js'
4+
import { BaseIndex } from './base-index.js'
5+
import type { CompareOptions } from '../query/builder/types.js'
6+
import type { BasicExpression } from '../query/ir.js'
7+
import type { IndexOperation } from './base-index.js'
118

129
/**
1310
* Options for Ordered index
@@ -266,7 +263,7 @@ export class BTreeIndex<
266263
nextPair: (k?: any) => [any, any] | undefined,
267264
from?: any,
268265
filterFn?: (key: TKey) => boolean,
269-
reversed: boolean = false
266+
reversed: boolean = false,
270267
): Array<TKey> {
271268
const keysInResult: Set<TKey> = new Set()
272269
const result: Array<TKey> = []

packages/db/tests/deterministic-ordering.test.ts

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import { describe, expect, it } from "vitest"
2-
import { SortedMap } from "../src/SortedMap"
3-
import { BTreeIndex } from "../src/indexes/btree-index"
4-
import { createCollection } from "../src/collection/index.js"
5-
import { PropRef } from "../src/query/ir"
6-
import { mockSyncCollectionOptions } from "./utils"
1+
import { describe, expect, it } from 'vitest'
2+
import { SortedMap } from '../src/SortedMap'
3+
import { BTreeIndex } from '../src/indexes/btree-index'
4+
import { createCollection } from '../src/collection/index.js'
5+
import { PropRef } from '../src/query/ir'
6+
import { mockSyncCollectionOptions } from './utils'
77

88
/**
99
* These tests verify deterministic ordering behavior when values compare as equal.
@@ -19,7 +19,7 @@ describe(`Deterministic Ordering`, () => {
1919
it(`should maintain deterministic order when values are equal`, () => {
2020
// All values are the same (priority = 1), so they compare as equal
2121
const map = new SortedMap<string, { priority: number }>(
22-
(a, b) => a.priority - b.priority
22+
(a, b) => a.priority - b.priority,
2323
)
2424

2525
// Insert in "random" order
@@ -34,7 +34,7 @@ describe(`Deterministic Ordering`, () => {
3434

3535
it(`should maintain deterministic order with mixed equal and different values`, () => {
3636
const map = new SortedMap<string, { priority: number }>(
37-
(a, b) => a.priority - b.priority
37+
(a, b) => a.priority - b.priority,
3838
)
3939

4040
// Mix of equal and different priorities
@@ -51,7 +51,7 @@ describe(`Deterministic Ordering`, () => {
5151

5252
it(`should maintain deterministic order with numeric keys`, () => {
5353
const map = new SortedMap<number, { priority: number }>(
54-
(a, b) => a.priority - b.priority
54+
(a, b) => a.priority - b.priority,
5555
)
5656

5757
map.set(30, { priority: 1 })
@@ -64,7 +64,7 @@ describe(`Deterministic Ordering`, () => {
6464

6565
it(`should maintain deterministic order after updates`, () => {
6666
const map = new SortedMap<string, { priority: number }>(
67-
(a, b) => a.priority - b.priority
67+
(a, b) => a.priority - b.priority,
6868
)
6969

7070
map.set(`c`, { priority: 1 })
@@ -80,7 +80,7 @@ describe(`Deterministic Ordering`, () => {
8080

8181
it(`should maintain deterministic order after delete and re-insert`, () => {
8282
const map = new SortedMap<string, { priority: number }>(
83-
(a, b) => a.priority - b.priority
83+
(a, b) => a.priority - b.priority,
8484
)
8585

8686
map.set(`c`, { priority: 1 })
@@ -113,7 +113,7 @@ describe(`Deterministic Ordering`, () => {
113113
const index = new BTreeIndex<string>(
114114
1,
115115
new PropRef([`priority`]),
116-
`priority_index`
116+
`priority_index`,
117117
)
118118

119119
// All have same priority
@@ -130,7 +130,7 @@ describe(`Deterministic Ordering`, () => {
130130
const index = new BTreeIndex<string>(
131131
1,
132132
new PropRef([`priority`]),
133-
`priority_index`
133+
`priority_index`,
134134
)
135135

136136
index.add(`d`, { priority: 2 })
@@ -148,7 +148,7 @@ describe(`Deterministic Ordering`, () => {
148148
const index = new BTreeIndex<number>(
149149
1,
150150
new PropRef([`priority`]),
151-
`priority_index`
151+
`priority_index`,
152152
)
153153

154154
index.add(30, { priority: 1 })
@@ -163,7 +163,7 @@ describe(`Deterministic Ordering`, () => {
163163
const index = new BTreeIndex<string>(
164164
1,
165165
new PropRef([`priority`]),
166-
`priority_index`
166+
`priority_index`,
167167
)
168168

169169
index.add(`c`, { priority: 1 })
@@ -179,7 +179,7 @@ describe(`Deterministic Ordering`, () => {
179179
const index = new BTreeIndex<string>(
180180
1,
181181
new PropRef([`priority`]),
182-
`priority_index`
182+
`priority_index`,
183183
)
184184

185185
index.add(`c`, { priority: 1 })
@@ -197,7 +197,7 @@ describe(`Deterministic Ordering`, () => {
197197
const index = new BTreeIndex<string>(
198198
1,
199199
new PropRef([`priority`]),
200-
`priority_index`
200+
`priority_index`,
201201
)
202202

203203
// Add keys with different priorities

packages/powersync-db-collection/tests/powersync.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ describe(`PowerSync Integration`, () => {
113113
expect(collection.size).toBe(4)
114114
// Sort by name since keys are random UUIDs
115115
expect(
116-
collection.toArray.map((entry) => entry.name).sort()
116+
collection.toArray.map((entry) => entry.name).sort(),
117117
).deep.equals([`four`, `one`, `three`, `two`])
118118
},
119119
{ timeout: 1000 },
@@ -130,7 +130,7 @@ describe(`PowerSync Integration`, () => {
130130
expect(collection.size).toBe(3)
131131
// Sort by name since keys are random UUIDs
132132
expect(
133-
collection.toArray.map((entry) => entry.name).sort()
133+
collection.toArray.map((entry) => entry.name).sort(),
134134
).deep.equals([`four`, `one`, `three`])
135135
},
136136
{ timeout: 1000 },
@@ -148,7 +148,7 @@ describe(`PowerSync Integration`, () => {
148148
expect(collection.size).toBe(3)
149149
// Sort by name since keys are random UUIDs
150150
expect(
151-
collection.toArray.map((entry) => entry.name).sort()
151+
collection.toArray.map((entry) => entry.name).sort(),
152152
).deep.equals([`four`, `three`, `updated`])
153153
},
154154
{ timeout: 1000 },

0 commit comments

Comments
 (0)