Skip to content

Commit 4ed5f7f

Browse files
docs(runtime-services): document data.query() beside find on the services.data page (#6784)
The page's own declared Canonical source (packages/client/src/index.ts) marks data.find @deprecated pointing at data.query(), which the page never mentioned. Add query to the Methods block in the source's declaration order, record the deprecation posture with attribution to the source (the same pattern the page already uses for the QueryOptions/QueryOptionsV2 vocabulary layer), document the Partial QueryAST parameter and the shared PaginatedResult envelope, and extend the example with a query call carrying nested expand detail — the shape find itself refuses with an error that points at query. Evidence for this direction over withdrawing the tag: query exists on both ObjectStackClient.data and ScopedProjectClient.data, ships untagged in dist/index.d.ts while find ships with the tag, is served by a dedicated POST /data/:object/query route, and is the recorded product direction (#986, commit 17dca13). The docs page was the stale side. Fixes #6323 Claude-Session: https://claude.ai/code/session_01F8q5J1MQyocgtNspb15fSn Co-authored-by: Claude <noreply@anthropic.com>
1 parent 4bb6f01 commit 4ed5f7f

1 file changed

Lines changed: 47 additions & 4 deletions

File tree

content/docs/kernel/runtime-services/data-service.mdx

Lines changed: 47 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
title: services.data
3-
description: CRUD runtime helper API for records (`get`, `find`, `create`, `update`, `delete`).
3+
description: CRUD runtime helper API for records (`query`, `get`, `find`, `create`, `update`, `delete`).
44
---
55

66
# `services.data`
@@ -32,13 +32,38 @@ the code that **holds** the binding calls it, with plain arguments and no `ctx`
3232
## Methods
3333

3434
```ts
35-
services.data.get<T = any>(object: string, id: string): Promise<GetDataResult<T>>
35+
services.data.query<T = any>(object: string, query: Partial<QueryAST>): Promise<PaginatedResult<T>>
3636
services.data.find<T = any>(object: string, options?: QueryOptions | QueryOptionsV2): Promise<PaginatedResult<T>>
37+
services.data.get<T = any>(object: string, id: string): Promise<GetDataResult<T>>
3738
services.data.create<T = any>(object: string, data: Partial<T>): Promise<CreateDataResult<T>>
3839
services.data.update<T = any>(object: string, id: string, data: Partial<T>): Promise<UpdateDataResult<T>>
3940
services.data.delete(object: string, id: string): Promise<DeleteDataResult>
4041
```
4142
43+
### Two list entries, one preference
44+
45+
`query` and `find` both answer a list read with the same
46+
`{ records, total?, hasMore? }` envelope, and the Canonical source declares which
47+
of the two to prefer — the block above lists them in its declaration order.
48+
`data.query` is *"Advanced Query using ObjectStack Query Protocol"*; `data.find`
49+
carries an `@deprecated` tag in the same file: *"Use `data.query()` with standard
50+
QueryAST parameters instead. This method uses legacy parameter names."* The tag
51+
ships in the package's published type declarations, so an editor strikes `find`
52+
through at every call site and points at `query`. As with the options vocabulary
53+
below, the posture is the SDK's own, not this page's — it is recorded product
54+
direction ([#986](https://github.com/objectstack-ai/objectstack/issues/986):
55+
deprecate the legacy-parameter query entries, promote `data.query(AST)`).
56+
57+
Deprecated means "prefer `query`", not "scheduled for removal in this version":
58+
`find` remains fully functional, keeps both of its option vocabularies (see
59+
[below](#find-options-canonical-and-legacy)), and the Canonical source still
60+
names `QueryOptionsV2` *"the recommended interface for `data.find()` queries"*
61+
for callers that stay on it. The capability line between the two entries is
62+
real, though. `find` rides GET query parameters, so it has no spelling for a
63+
`search` term or for nested `expand` detail — it refuses a nested expand with an
64+
error whose own text says to use `data.query()`. `query` POSTs the full
65+
`QueryAST` as a JSON body (`POST /data/:object/query`) and carries all of it.
66+
4267
## Canonical source
4368
4469
Every sibling page in this chapter names a contract interface
@@ -60,6 +85,12 @@ key for key. A managed runtime binds `services.data` to this same shape.
6085
- `object`: short object name (for example `task`, `account`)
6186
- `id`: record ID for single-record operations
6287
- `data`: partial payload for create/update
88+
- `query` (`query`): a `Partial<QueryAST>` — the spec's query protocol shape
89+
(`packages/spec/src/data/query.zod.ts`): `where` / `fields` / `orderBy` /
90+
`limit` / `offset`, plus the AST-only clauses (`search`, `expand` with nested
91+
detail, `aggregations`, `groupBy`, `having`). The AST's own `object` key is
92+
not needed here: the server takes the target from the `object` argument (the
93+
URL path) and overwrites anything the body says
6394
- `options` (`find`): filtering, sorting and pagination — two vocabularies, one
6495
behaviour; see the table below
6596
@@ -97,7 +128,8 @@ silently rather than refused, so migrate an options object as a whole.
97128
## Returns
98129
99130
- `get`: single record payload
100-
- `find`: list payload + pagination metadata
131+
- `query`/`find`: list payload + pagination metadata — the same
132+
`PaginatedResult` envelope for both
101133
- `create`/`update`: mutated record payload
102134
- `delete`: `{ object, id, success }` — the spec's `DeleteDataResponse`. The
103135
flag is `success`, not `deleted` (#5638)
@@ -133,7 +165,18 @@ export async function recentOrdersForContact(data: DataService, contactId: strin
133165
limit: 20,
134166
});
135167

136-
return { contact, orders };
168+
// `query` — the Canonical source's preferred list entry — POSTs the same
169+
// words as a Partial<QueryAST> body, and carries the clauses `find` has no
170+
// GET spelling for. Here: per-relation `expand` detail, which `find`
171+
// refuses with an error that itself points at `query`.
172+
const { records: withContact } = await data.query<{ id: string; amount: number }>('sales_order', {
173+
where: { contact_id: contact.id },
174+
orderBy: [{ field: 'created_at', order: 'desc' }],
175+
limit: 20,
176+
expand: { contact_id: { object: 'contact', fields: ['name'] } },
177+
});
178+
179+
return { contact, orders, withContact };
137180
}
138181
```
139182

0 commit comments

Comments
 (0)