Skip to content

Commit 00fc5eb

Browse files
hotlongclaude
andauthored
docs(kernel): services.data 的 Parameters 补上 canonical QueryOptionsV2 词汇 (#6002) (#6324)
Methods 一节写明 find 接受 QueryOptions | QueryOptionsV2,但 Parameters 只列 legacy 那套(top/skip/filter/sort/select)。canonical source packages/client/src/index.ts 的自述正好相反:QueryOptions 带 @deprecated、 "require translation to QueryAST";QueryOptionsV2 是 "the recommended interface for data.find() queries"。本页因此把 SDK 自称推荐的词汇整个略过。 Parameters 改为并列两套并点明推荐关系(canonical where/fields/orderBy/limit/ offset,legacy filter/select/sort/top/skip 仍受支持、运行时翻译),Example 同批 换用 canonical 词汇。推荐关系由 JSDoc 写死,不是本 PR 的取舍。 Claude-Session: https://claude.ai/code/session_01BDmDsu2575gDxeMCxXhDE3 Co-authored-by: Claude <noreply@anthropic.com>
1 parent 5b103d6 commit 00fc5eb

1 file changed

Lines changed: 38 additions & 5 deletions

File tree

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

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,39 @@ key for key. A managed runtime binds `services.data` to this same shape.
6060
- `object`: short object name (for example `task`, `account`)
6161
- `id`: record ID for single-record operations
6262
- `data`: partial payload for create/update
63-
- `options` (`find`): filters, sorting, pagination (`top`, `skip`, `filter`, `sort`, `select`)
63+
- `options` (`find`): filtering, sorting and pagination — two vocabularies, one
64+
behaviour; see the table below
65+
66+
### `find` options: canonical and legacy
67+
68+
The signature above accepts `QueryOptions | QueryOptionsV2`, and the Canonical source
69+
declares which of the two to write. `QueryOptionsV2` is *"canonical query options using
70+
Spec protocol field names … the recommended interface for `data.find()` queries"*, while
71+
`QueryOptions` carries an `@deprecated` tag in the same file describing *"legacy parameter
72+
names … that require translation to QueryAST"*, with the instruction to *"prefer QueryAST
73+
fields directly"*. Both interfaces are declared in `packages/client/src/index.ts`, so the
74+
recommendation is the SDK's own, not this page's.
75+
76+
| Canonical (`QueryOptionsV2`) | Legacy (`QueryOptions`) | Clause |
77+
|:---|:---|:---|
78+
| `where` | `filter` | filter conditions (`WHERE`) |
79+
| `fields` | `select` | field selection (`SELECT`) |
80+
| `orderBy` | `sort` | sort definition (`ORDER BY`) |
81+
| `limit` | `top` | maximum records (`LIMIT`) |
82+
| `offset` | `skip` | records skipped (`OFFSET`) |
83+
84+
**Write the left column.** Those are the QueryAST and protocol field names, so the same
85+
words carry from here down through `data.query()` into the query layer — one translation
86+
step fewer to hold in your head.
87+
88+
**The right column still works.** Nothing refuses it: `find` recognises a canonical
89+
options object and normalizes it into exactly the transport parameters the legacy names
90+
produce, so the two columns are equivalent, not merely similar. Deprecated here means
91+
"prefer the other spelling", not "scheduled for removal in this version".
92+
93+
**Use one column per call.** `find` reads either the canonical names or the legacy ones
94+
for a given options object, never a blend — a key from the other column is dropped
95+
silently rather than refused, so migrate an options object as a whole.
6496
6597
## Returns
6698
@@ -93,11 +125,12 @@ export async function recentOrdersForContact(data: DataService, contactId: strin
93125
// `get` resolves the response envelope `{ object, id, record }` — the row is `record`.
94126
const { record: contact } = await data.get<{ id: string; name: string }>('contact', contactId);
95127

96-
// `find` resolves `{ records, total?, hasMore? }`.
128+
// `find` resolves `{ records, total?, hasMore? }`. The options are the canonical
129+
// `QueryOptionsV2` vocabulary — `where` / `orderBy` / `limit`, not `filter` / `sort` / `top`.
97130
const { records: orders } = await data.find<{ id: string; amount: number }>('sales_order', {
98-
filter: { contact_id: contact.id },
99-
sort: [{ field: 'created_at', order: 'desc' }],
100-
top: 20,
131+
where: { contact_id: contact.id },
132+
orderBy: [{ field: 'created_at', order: 'desc' }],
133+
limit: 20,
101134
});
102135

103136
return { contact, orders };

0 commit comments

Comments
 (0)