Skip to content

Commit d0377c6

Browse files
committed
move helpers to main db package
1 parent a32b363 commit d0377c6

File tree

6 files changed

+20
-12
lines changed

6 files changed

+20
-12
lines changed

.changeset/expression-helpers-queryfn.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
---
2+
"@tanstack/db": patch
23
"@tanstack/query-db-collection": patch
34
---
45

56
Add expression helper utilities for parsing LoadSubsetOptions in queryFn.
67

7-
When using `syncMode: 'on-demand'`, query collections now provide helper functions to easily parse where clauses, orderBy, and limit predicates into your API's format:
8+
When using `syncMode: 'on-demand'`, TanStack DB now provides helper functions to easily parse where clauses, orderBy, and limit predicates into your API's format:
89

910
- `parseWhereExpression`: Parse where clauses with custom handlers for each operator
1011
- `parseOrderByExpression`: Parse order by into simple array format
@@ -15,7 +16,8 @@ When using `syncMode: 'on-demand'`, query collections now provide helper functio
1516
**Example:**
1617

1718
```typescript
18-
import { parseLoadSubsetOptions } from "@tanstack/query-db-collection"
19+
import { parseLoadSubsetOptions } from "@tanstack/db"
20+
// or from "@tanstack/query-db-collection" (re-exported for convenience)
1921

2022
queryFn: async (ctx) => {
2123
const { where, orderBy, limit } = ctx.meta.loadSubsetOptions

docs/collections/query-collection.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,7 @@ queryFn: async (ctx) => {
417417
}
418418
```
419419

420-
The `where` and `orderBy` fields are expression trees (AST - Abstract Syntax Tree) that need to be parsed. The `@tanstack/query-db-collection` package provides helper functions to make this easy.
420+
The `where` and `orderBy` fields are expression trees (AST - Abstract Syntax Tree) that need to be parsed. TanStack DB provides helper functions to make this easy.
421421

422422
### Expression Helpers
423423

@@ -427,7 +427,8 @@ import {
427427
parseOrderByExpression,
428428
extractSimpleComparisons,
429429
parseLoadSubsetOptions,
430-
} from '@tanstack/query-db-collection'
430+
} from '@tanstack/db'
431+
// Or from '@tanstack/query-db-collection' (re-exported for convenience)
431432
```
432433

433434
These helpers allow you to parse expression trees without manually traversing complex AST structures.
@@ -436,7 +437,8 @@ These helpers allow you to parse expression trees without manually traversing co
436437

437438
```typescript
438439
import { createCollection } from '@tanstack/react-db'
439-
import { queryCollectionOptions, parseLoadSubsetOptions } from '@tanstack/query-db-collection'
440+
import { queryCollectionOptions } from '@tanstack/query-db-collection'
441+
import { parseLoadSubsetOptions } from '@tanstack/db'
440442
import { QueryClient } from '@tanstack/query-core'
441443

442444
const queryClient = new QueryClient()

packages/db/src/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ export * from "./indexes/btree-index.js"
2222
export * from "./indexes/lazy-index.js"
2323
export { type IndexOptions } from "./indexes/index-options.js"
2424

25+
// Expression helpers
26+
export * from "./query/expression-helpers.js"
27+
2528
// Re-export some stuff explicitly to ensure the type & value is exported
2629
export type { Collection } from "./collection/index.js"
2730
export { IR }

packages/query-db-collection/src/expression-helpers.ts renamed to packages/db/src/query/expression-helpers.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
/**
2-
* Expression Helpers for Query Collections
2+
* Expression Helpers for TanStack DB
33
*
44
* These utilities help parse LoadSubsetOptions (where, orderBy, limit) from TanStack DB
55
* into formats suitable for your API backend. They provide a generic way to traverse
66
* expression trees without having to implement your own parser.
77
*
88
* @example
99
* ```typescript
10-
* import { parseWhereExpression, parseOrderByExpression } from '@tanstack/query-db-collection'
10+
* import { parseWhereExpression, parseOrderByExpression } from '@tanstack/db'
1111
*
1212
* queryFn: async (ctx) => {
1313
* const { limit, where, orderBy } = ctx.meta?.loadSubsetOptions ?? {}
@@ -27,7 +27,7 @@
2727
* ```
2828
*/
2929

30-
import type { IR, OperatorName } from "@tanstack/db"
30+
import type { IR, OperatorName } from "../index.js"
3131

3232
type BasicExpression<T = any> = IR.BasicExpression<T>
3333
type OrderBy = IR.OrderBy

packages/query-db-collection/tests/expression-helpers.test.ts renamed to packages/db/tests/query/expression-helpers.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ import {
77
parseOrderByExpression,
88
parseWhereExpression,
99
walkExpression,
10-
} from "../src/expression-helpers"
11-
import { Func, PropRef, Value } from "../../db/src/query/ir.js"
12-
import type { IR } from "@tanstack/db"
10+
} from "../../src/query/expression-helpers"
11+
import { Func, PropRef, Value } from "../../src/query/ir.js"
12+
import type { IR } from "../../src/index.js"
1313

1414
type OrderBy = IR.OrderBy
1515

packages/query-db-collection/src/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ export {
77

88
export * from "./errors"
99

10+
// Re-export expression helpers from @tanstack/db
1011
export {
1112
parseWhereExpression,
1213
parseOrderByExpression,
@@ -19,4 +20,4 @@ export {
1920
type SimpleComparison,
2021
type ParseWhereOptions,
2122
type ParsedOrderBy,
22-
} from "./expression-helpers"
23+
} from "@tanstack/db"

0 commit comments

Comments
 (0)