Skip to content

Commit 93663e6

Browse files
committed
refactor(sql-orm-client): drop OrderByItem re-export, keep reverse() as the API
Re-exporting OrderByItem (and Direction) from the ORM client singled out two AST types out of the whole alphabet that otherwise lives only in @prisma-next/sql-relational-core/ast. .reverse() being an instance method is enough: integrations call it on the item the orderBy selector already returns, so no value-level import of OrderByItem is needed. Move the public-shape type test to relational-core (OrderByItem.reverse() returns OrderByItem; readable dir/expr) next to the runtime round-trip test; drop the now-redundant sql-orm-client tests; reword the README pagination note to use .reverse() inline. TML-2596 Signed-off-by: Alexey Orlenko's AI Agent <robot@aqrln.net>
1 parent e1b6dc2 commit 93663e6

4 files changed

Lines changed: 11 additions & 44 deletions

File tree

packages/3-extensions/sql-orm-client/test/order-by-item.types.test-d.ts renamed to packages/2-sql/4-lanes/relational-core/test/ast/order.types.test-d.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
import type { AnyExpression } from '@prisma-next/sql-relational-core/ast';
21
import { expectTypeOf, test } from 'vitest';
3-
import type { Direction, OrderByItem } from '../src/exports';
2+
import type { AnyExpression, Direction, OrderByItem } from '../../src/ast/types';
43

54
test('OrderByItem.reverse() returns an OrderByItem', () => {
65
expectTypeOf<OrderByItem['reverse']>().toEqualTypeOf<() => OrderByItem>();

packages/3-extensions/sql-orm-client/README.md

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -64,26 +64,25 @@ const posts = await db.Post
6464
`.orderBy(...)` accepts model-accessor callbacks that return `OrderByItem`s via the column's `.asc()` / `.desc()` helpers:
6565

6666
```ts
67-
const posts = await db.Post
67+
// Forward page (newest first).
68+
const firstPage = await db.Post
6869
.orderBy((post) => post.createdAt.desc())
6970
.take(10)
7071
.all();
7172
```
7273

73-
Integrations that own pagination — Relay-style backward cursor pagination, REST list endpoints — need to flip the user's sort order. `OrderByItem` (and its `Direction`) is re-exported from this package and exposes `.reverse()`, which returns a new frozen item with the direction flipped and the expression unchanged. Call it inside the `orderBy` selector to invert a user-supplied sort for a backward page:
74+
Integrations that own pagination — Relay-style backward cursor pagination, REST list endpoints — need to flip the user's sort order. Each `OrderByItem` exposes `.reverse()`, which returns a new frozen item with the direction flipped and the expression unchanged. Call it on the item the selector returns to build the backward page (then re-reverse the returned rows in application code):
7475

7576
```ts
76-
import type { ModelAccessor, OrderByItem } from '@prisma-next/sql-orm-client';
77-
78-
type OrderSelector = (post: ModelAccessor<typeof contract, 'Post'>) => OrderByItem;
79-
80-
const forward: OrderSelector = (post) => post.createdAt.desc();
81-
// Backward page: reverse the user's order, fetch, then re-reverse the rows in JS.
82-
const backward: OrderSelector = (post) => forward(post).reverse();
83-
84-
const page = await db.Post.orderBy(backward).take(10).all();
77+
// Backward page: same sort, flipped.
78+
const lastPage = await db.Post
79+
.orderBy((post) => post.createdAt.desc().reverse())
80+
.take(10)
81+
.all();
8582
```
8683

84+
An integration that wraps a user-supplied order selector flips it the same way — `(post) => userSelector(post).reverse()` — without having to inspect the opaque `OrderByItem`.
85+
8786
## Codec Roundtrip
8887

8988
The runtime always awaits codec query-time methods, but rows yielded to user code carry **plain field values** — no `Promise`-typed fields ever reach `.first()` / `.all()` / streaming consumers, regardless of whether a column's codec is sync or async. This is true for both one-shot and streaming usage:

packages/3-extensions/sql-orm-client/src/exports/index.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
export type { Direction } from '@prisma-next/sql-relational-core/ast';
2-
export { OrderByItem } from '@prisma-next/sql-relational-core/ast';
31
export { Collection } from '../collection';
42
export { all, and, not, or } from '../filters';
53
export { GroupedCollection } from '../grouped-collection';

packages/3-extensions/sql-orm-client/test/order-by-item.test.ts

Lines changed: 0 additions & 29 deletions
This file was deleted.

0 commit comments

Comments
 (0)