11---
22title : 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 >>
3636services .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 >>
3738services .data .create <T = any >(object : string , data : Partial <T >): Promise <CreateDataResult <T >>
3839services .data .update <T = any >(object : string , id : string , data : Partial <T >): Promise <UpdateDataResult <T >>
3940services .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
4469Every 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