Skip to content

Commit 96f9915

Browse files
committed
fix(spec)!: transport select / $select and GetDataRequestSchema.select declare the projection the doors accept
QueryTransportParamsSchema.select / $select admitted a blank or comma-only string, [] and blank names, and GetDataRequestSchema.select admitted [], all of which the findData / getData doors refuse. One rule in data-engine.zod.ts now declares the door's accept set; HttpFindQueryParams and GetDataRequest read its arms instead of restating them. The POST /data/:object/query body gate parses FindDataRequestSchema, so an empty projection there is now refused at the schema (400 VALIDATION_FAILED naming query.select), as a malformed limit or count already is; the rest and runtime door pins move with it. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WGufzgm45oXexLiY5mMigQ
1 parent 8074feb commit 96f9915

9 files changed

Lines changed: 187 additions & 17 deletions

File tree

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
---
2+
'@objectstack/spec': patch
3+
---
4+
5+
fix(spec)!: `QueryTransportParamsSchema.select` / `$select` and `GetDataRequestSchema.select` declare the projection the `findData` and `getData` doors accept, instead of any string or list (#26909)
6+
7+
Clause-②: no (narrowing) — the published body-side declarations of the list door's projection (`select`, `$select`, reached through `QueryWithTransportSchema` and `FindDataRequestSchema.query`) and the by-id request's `select` refuse a value naming no field, which they admitted before. The doors already refused it with a 400; nothing is widened and no key is added, removed or renamed.
8+
Metadata-protocol: none
9+
10+
<!-- adr-0087: not-required (no-migration-prescription) No key of any schema is added, removed, renamed or re-shaped and no metadata type or stored shape moves: these are transport request declarations, never stored, and the values they stop admitting are values the Data API doors already refused. A caller names at least one field or leaves the parameter out; there is nothing for a migration to rewrite and no tombstone. -->
11+
12+
**BREAKING** accept-set narrowing of published transport declarations (`@objectstack/spec/data`, `@objectstack/spec/api`), read by the `POST /data/:object/query` body gate, codegen, the reference docs and clients.
13+
14+
- **Before.** `select` / `$select` admitted any string or list: a blank, whitespace-only or comma-only string, `[]`, and a list with a blank name. `GetDataRequestSchema.select` admitted `[]` and blank names.
15+
- **Now.** A string must name at least one field after the door's own split and trim (published as the pattern `[^\s,]`, the same rule `HttpFindQueryParamsSchema.select` states since #26817). A list must hold at least one name, and no name may be blank. `HttpFindQueryParamsSchema.select` and `GetDataRequestSchema.select` read these rules off `QueryTransportParamsSchema.select` rather than restating them.
16+
- **`POST /data/:object/query`.** That route parses its body with `FindDataRequestSchema`, so an empty `select` / `$select` is now refused at the body schema: still `400`, still before any read, but `VALIDATION_FAILED` with `fields[0].field` naming `query.select` / `query.$select`, where it was `VALIDATION_ERROR` from the list door. A list with a blank name (`["name", ""]`) is likewise `400 VALIDATION_FAILED` at the schema, where it was `400 INVALID_FIELD` (an unknown field). This is how that route already answers a malformed `limit` or `count`.
17+
- **Unchanged.** `GET /data/:object` and `GET /data/:object/:id` still answer an empty `select` with `400 VALIDATION_ERROR` naming it; a named projection (`name,email`, `["name", "email"]`, spaces and empty members between commas trimmed by the door) and an explicit `null` (a withdrawal) are accepted as before.
18+
- **Who sees it.** A caller of `POST /data/:object/query` that branches on the `VALIDATION_ERROR` code for an empty projection, code that parses a query bag with these schemas and sent an empty projection, or a generated client that trusted the wider declaration.
19+
20+
**The remedy.** Send `select` naming at least one field, or leave it out to read every column.

‎content/docs/references/api/protocol.mdx‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -920,14 +920,14 @@ Enable package response
920920
| **$top** | `integer \| string \| null` | optional | Transport spelling of `limit` (OData `$top`) — a non-negative integer, or the digits a querystring carries it as |
921921
| **$skip** | `integer \| string \| null` | optional | Transport spelling of `offset` (OData `$skip`) — a non-negative integer, or the digits a querystring carries it as |
922922
| **$orderby** | `Record<string, Enum<'asc' \| 'desc'>> \| Record<string, 1 \| -1> \| { field: string; order?: Enum<'asc' \| 'desc'> }[] \| null` | optional | Transport spelling of `orderBy` (OData `$orderby`) |
923-
| **$select** | `string \| string[] \| null` | optional | Transport spelling of `fields` (OData `$select`) |
923+
| **$select** | `string \| string[] \| null` | optional | Transport spelling of `fields` (OData `$select`) — at least one field name; a value naming no field (blank, only commas and spaces, an empty list, or a list with a blank name) is refused |
924924
| **$expand** | `string \| string[] \| Record<string, { object: string; fields?: string[]; where?: any; search?: string \| object; … }> \| null` | optional | Transport spelling of `expand` (OData `$expand`) |
925925
| **$search** | `string \| { query: string; fields?: string[]; fuzzy?: boolean; operator?: Enum<'and' \| 'or'>; … } \| null` | optional | Transport spelling of `search` (OData `$search`) |
926926
| **$searchFields** | `string \| string[] \| null` | optional | Transport spelling of `searchFields` (OData `$searchFields`) |
927927
| **$count** | `boolean \| Enum<'true' \| 'false'> \| null` | optional | Transport spelling of the response total-count flag (OData `$count`) |
928928
| **count** | `boolean \| Enum<'true' \| 'false'> \| null` | optional | Response total-count flag — only an explicit `false` skips the COUNT query |
929929
| **filter** | `[string, string, any] \| [string, string] \| [string, object, ...object[]] \| object[] \| Record<string, any> \| any \| null` | optional | Transport spelling of `where` |
930-
| **select** | `string \| string[] \| null` | optional | Transport spelling of `fields` |
930+
| **select** | `string \| string[] \| null` | optional | Transport spelling of `fields` — at least one field name; a value naming no field (blank, only commas and spaces, an empty list, or a list with a blank name) is refused |
931931
| **sort** | `Record<string, Enum<'asc' \| 'desc'>> \| Record<string, 1 \| -1> \| { field: string; order?: Enum<'asc' \| 'desc'> }[] \| null` | optional | Transport spelling of `orderBy` |
932932
| **skip** | `integer \| string \| null` | optional | Transport spelling of `offset` — a non-negative integer, or the digits a querystring carries it as |
933933
| **populate** | `string \| string[] \| null` | optional | Transport spelling of `expand` |
@@ -1038,7 +1038,7 @@ This schema accepts one of the following structures:
10381038
| :--- | :--- | :--- | :--- |
10391039
| **object** | `string` | ✅ | The object name. |
10401040
| **id** | `string` | ✅ | The unique record identifier (primary key). |
1041-
| **select** | `string[]` | optional | Fields to include in the response (allowlisted query param). |
1041+
| **select** | `string[]` | optional | Fields to include in the response (allowlisted query param) — at least one field name; an empty list, or a list with a blank name, is refused. |
10421042
| **expand** | `string[]` | optional | Lookup/master_detail field names to expand. The engine resolves these via batch $in queries, replacing foreign key IDs with full objects. |
10431043

10441044

‎content/docs/references/data/data-engine.mdx‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1307,14 +1307,14 @@ Transport spellings of the QueryAST slots — folded to canonical keys at the bo
13071307
| **$top** | `integer \| string \| null` | optional | Transport spelling of `limit` (OData `$top`) — a non-negative integer, or the digits a querystring carries it as |
13081308
| **$skip** | `integer \| string \| null` | optional | Transport spelling of `offset` (OData `$skip`) — a non-negative integer, or the digits a querystring carries it as |
13091309
| **$orderby** | `Record<string, Enum<'asc' \| 'desc'>> \| Record<string, 1 \| -1> \| { field: string; order?: Enum<'asc' \| 'desc'> }[] \| null` | optional | Transport spelling of `orderBy` (OData `$orderby`) |
1310-
| **$select** | `string \| string[] \| null` | optional | Transport spelling of `fields` (OData `$select`) |
1310+
| **$select** | `string \| string[] \| null` | optional | Transport spelling of `fields` (OData `$select`) — at least one field name; a value naming no field (blank, only commas and spaces, an empty list, or a list with a blank name) is refused |
13111311
| **$expand** | `string \| string[] \| Record<string, { object: string; fields?: string[]; where?: any; search?: string \| object; … }> \| null` | optional | Transport spelling of `expand` (OData `$expand`) |
13121312
| **$search** | `string \| { query: string; fields?: string[]; fuzzy?: boolean; operator?: Enum<'and' \| 'or'>; … } \| null` | optional | Transport spelling of `search` (OData `$search`) |
13131313
| **$searchFields** | `string \| string[] \| null` | optional | Transport spelling of `searchFields` (OData `$searchFields`) |
13141314
| **$count** | `boolean \| Enum<'true' \| 'false'> \| null` | optional | Transport spelling of the response total-count flag (OData `$count`) |
13151315
| **count** | `boolean \| Enum<'true' \| 'false'> \| null` | optional | Response total-count flag — only an explicit `false` skips the COUNT query |
13161316
| **filter** | `[string, string, any] \| [string, string] \| [string, object, ...object[]] \| object[] \| Record<string, any> \| any \| null` | optional | Transport spelling of `where` |
1317-
| **select** | `string \| string[] \| null` | optional | Transport spelling of `fields` |
1317+
| **select** | `string \| string[] \| null` | optional | Transport spelling of `fields` — at least one field name; a value naming no field (blank, only commas and spaces, an empty list, or a list with a blank name) is refused |
13181318
| **sort** | `Record<string, Enum<'asc' \| 'desc'>> \| Record<string, 1 \| -1> \| { field: string; order?: Enum<'asc' \| 'desc'> }[] \| null` | optional | Transport spelling of `orderBy` |
13191319
| **skip** | `integer \| string \| null` | optional | Transport spelling of `offset` — a non-negative integer, or the digits a querystring carries it as |
13201320
| **populate** | `string \| string[] \| null` | optional | Transport spelling of `expand` |
@@ -1385,14 +1385,14 @@ Transport spellings of the QueryAST slots — folded to canonical keys at the bo
13851385
| **$top** | `integer \| string \| null` | optional | Transport spelling of `limit` (OData `$top`) — a non-negative integer, or the digits a querystring carries it as |
13861386
| **$skip** | `integer \| string \| null` | optional | Transport spelling of `offset` (OData `$skip`) — a non-negative integer, or the digits a querystring carries it as |
13871387
| **$orderby** | `Record<string, Enum<'asc' \| 'desc'>> \| Record<string, 1 \| -1> \| { field: string; order?: Enum<'asc' \| 'desc'> }[] \| null` | optional | Transport spelling of `orderBy` (OData `$orderby`) |
1388-
| **$select** | `string \| string[] \| null` | optional | Transport spelling of `fields` (OData `$select`) |
1388+
| **$select** | `string \| string[] \| null` | optional | Transport spelling of `fields` (OData `$select`) — at least one field name; a value naming no field (blank, only commas and spaces, an empty list, or a list with a blank name) is refused |
13891389
| **$expand** | `string \| string[] \| Record<string, { object: string; fields?: string[]; where?: any; search?: string \| object; … }> \| null` | optional | Transport spelling of `expand` (OData `$expand`) |
13901390
| **$search** | `string \| { query: string; fields?: string[]; fuzzy?: boolean; operator?: Enum<'and' \| 'or'>; … } \| null` | optional | Transport spelling of `search` (OData `$search`) |
13911391
| **$searchFields** | `string \| string[] \| null` | optional | Transport spelling of `searchFields` (OData `$searchFields`) |
13921392
| **$count** | `boolean \| Enum<'true' \| 'false'> \| null` | optional | Transport spelling of the response total-count flag (OData `$count`) |
13931393
| **count** | `boolean \| Enum<'true' \| 'false'> \| null` | optional | Response total-count flag — only an explicit `false` skips the COUNT query |
13941394
| **filter** | `[string, string, any] \| [string, string] \| [string, object, ...object[]] \| object[] \| Record<string, any> \| any \| null` | optional | Transport spelling of `where` |
1395-
| **select** | `string \| string[] \| null` | optional | Transport spelling of `fields` |
1395+
| **select** | `string \| string[] \| null` | optional | Transport spelling of `fields` — at least one field name; a value naming no field (blank, only commas and spaces, an empty list, or a list with a blank name) is refused |
13961396
| **sort** | `Record<string, Enum<'asc' \| 'desc'>> \| Record<string, 1 \| -1> \| { field: string; order?: Enum<'asc' \| 'desc'> }[] \| null` | optional | Transport spelling of `orderBy` |
13971397
| **skip** | `integer \| string \| null` | optional | Transport spelling of `offset` — a non-negative integer, or the digits a querystring carries it as |
13981398
| **populate** | `string \| string[] \| null` | optional | Transport spelling of `expand` |

‎packages/rest/src/data-empty-projection-count-door.test.ts‎

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* |:--|:--|:--|
1414
* | `GET ?$select=`, `?$select=%20`, `?$select=,`, `?select=`, `?fields=` | 200, every column | 400 naming the spelling |
1515
* | `GET ?$count=maybe`, `?$count=1`, `?count=` (with `$top`) | 200, `total` reported | 400 naming the spelling |
16-
* | `POST {"select":""}`, `{"fields":[]}` | 200, every column | 400 naming the key |
16+
* | `POST {"select":""}`, `{"fields":[]}` | 200, every column | 400 naming the key (`select` at the body schema, `VALIDATION_FAILED`, since #26909) |
1717
* | `POST {"count":"maybe"}` | 400 `VALIDATION_FAILED` (the body schema) | unchanged |
1818
* | `GET /:id?select=`, `?select=,` | 200, every column | `VALIDATION_ERROR` naming `select`, at this route's 404 (it rewrote every 400, as for `?select=nope`); 400 since #26816 |
1919
* | `GET ?$select=label`, `?$count=true` / `false`, absent; `GET /:id?select=label` | 200 | unchanged |
@@ -59,11 +59,22 @@ const REFUSED_GET: ReadonlyArray<readonly [string, Record<string, string>, strin
5959

6060
/** name · the JSON body `POST /data/:object/query` receives · the key the refusal names. */
6161
const REFUSED_POST: ReadonlyArray<readonly [string, Record<string, unknown>, string]> = [
62-
['select: ""', { select: '' }, 'select'],
63-
['$select: ","', { $select: ',' }, '$select'],
6462
['fields: []', { fields: [] }, 'fields'],
6563
];
6664

65+
/**
66+
* [#26909] The body's published schema (`FindDataRequestSchema`) now declares
67+
* the projection the normalizer enforces, so these are refused where every
68+
* other malformed body is: at the schema, `400 VALIDATION_FAILED`, `fields[0]`
69+
* naming `query.<key>` (the #25269 precedent for the page window).
70+
*/
71+
const REFUSED_POST_AT_SCHEMA: ReadonlyArray<readonly [string, Record<string, unknown>, string]> = [
72+
['select: ""', { select: '' }, 'query.select'],
73+
['$select: ","', { $select: ',' }, 'query.$select'],
74+
['select: []', { select: [] }, 'query.select'],
75+
['select: ["label", ""]', { select: ['label', ''] }, 'query.select'],
76+
];
77+
6778
function createMockServer() {
6879
const noop = () => {};
6980
return { get: noop, post: noop, put: noop, delete: noop, patch: noop, use: noop, listen: async () => {}, close: async () => {} };
@@ -161,6 +172,17 @@ describe('[#26644] an empty projection and an unrecognised count flag on the Dat
161172
expect(reads.n - before, 'no read of the object — every refusal precedes the driver').toBe(0);
162173
});
163174

175+
it('POST query: `select` / `$select` naming no field is the schema door\'s 400 VALIDATION_FAILED — no read', async () => {
176+
const before = reads.n;
177+
for (const [name, body, field] of REFUSED_POST_AT_SCHEMA) {
178+
const res = await query(body);
179+
expect(res.status, `${name}: ${JSON.stringify(res.body)}`).toBe(400);
180+
expect(res.body.code, name).toBe('VALIDATION_FAILED');
181+
expect(res.body.fields?.[0]?.field, name).toBe(field);
182+
}
183+
expect(reads.n - before, 'no read of the object — every refusal precedes the driver').toBe(0);
184+
});
185+
164186
it("POST query: an unrecognised count is still the schema door's 400 VALIDATION_FAILED, unchanged", async () => {
165187
const res = await query({ limit: 2, count: 'maybe' });
166188
expect(res.status, JSON.stringify(res.body)).toBe(400);

‎packages/runtime/src/domains/data-empty-projection-count.test.ts‎

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,6 @@ describe('[#26644] the dispatcher /data doors — an empty projection and an unr
112112
['GET list ?$select=, (the card)', 'GET', '/data/inquiry', { $select: ',' }, undefined, '$select', 'names no field'],
113113
['GET list ?select= (the card)', 'GET', '/data/inquiry', { select: '' }, undefined, 'select', 'names no field'],
114114
['GET list ?$count=maybe (the card)', 'GET', '/data/inquiry', { $top: '2', $count: 'maybe' }, undefined, '$count', 'must be true or false'],
115-
['POST query {"select":""}', 'POST', '/data/inquiry/query', {}, { select: '' }, 'select', 'names no field'],
116115
['POST query {"fields":[]}', 'POST', '/data/inquiry/query', {}, { fields: [] }, 'fields', 'names no field'],
117116
['GET by id ?select=', 'GET', '/data/inquiry/r1', { select: '' }, undefined, 'select', 'names no field'],
118117
['GET by id ?select=,', 'GET', '/data/inquiry/r1', { select: ',' }, undefined, 'select', 'names no field'],
@@ -127,6 +126,28 @@ describe('[#26644] the dispatcher /data doors — an empty projection and an unr
127126
expect(reads.n - before, 'no read of the object — the refusal precedes the driver').toBe(0);
128127
});
129128

129+
// [#26909] The body's published schema (`FindDataRequestSchema`) now
130+
// declares the projection the normalizer enforces, so `select` / `$select`
131+
// naming no field is refused where every other malformed body is: at the
132+
// schema, `400 VALIDATION_FAILED` naming `query.<key>` (the #25269
133+
// precedent for the page window). Still a 400, still before any read.
134+
it.each<[string, Record<string, unknown>, string]>([
135+
['{"select":""}', { select: '' }, 'query.select'],
136+
['{"$select":","}', { $select: ',' }, 'query.$select'],
137+
['{"select":[]}', { select: [] }, 'query.select'],
138+
['{"select":["name",""]}', { select: ['name', ''] }, 'query.select'],
139+
])('POST query %s: 400 VALIDATION_FAILED naming the body key at the schema — no read', async (_name, body, field) => {
140+
const before = reads.n;
141+
142+
const answer = await ask('POST', '/data/inquiry/query', {}, body);
143+
144+
expect(answer.status, JSON.stringify(answer)).toBe(400);
145+
expect(answer.code).toBe('VALIDATION_FAILED');
146+
const fields = (answer.body?.error?.details?.fields ?? []).map((f: { field: string }) => f.field);
147+
expect(fields).toEqual([field]);
148+
expect(reads.n - before, 'no read of the object — the refusal precedes the driver').toBe(0);
149+
});
150+
130151
it('CONTROL: a named projection and a true / false / absent count answer exactly as before', async () => {
131152
const projected = await ask('GET', '/data/inquiry', { $select: 'name', $orderby: 'name' });
132153
expect(projected.status, JSON.stringify(projected)).toBe(200);

‎packages/spec/src/api/protocol.test.ts‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -612,6 +612,19 @@ describe('GetDataRequestSchema (select/expand)', () => {
612612
}
613613
});
614614

615+
// [#26909] The by-id door reads `select` through the list door's
616+
// projection rule and refuses a list naming no field; every member is then
617+
// checked against the object's fields, where a blank name is never one.
618+
it.each([[[]], [['', ' ']], [['name', '']]])('refuses select=%j — names no field', (select) => {
619+
expect(GetDataRequestSchema.safeParse({ object: 'contact', id: 'c1', select }).success).toBe(false);
620+
});
621+
622+
it.each([[['name']], [['name', 'email']]])('keeps select=%j unchanged', (select) => {
623+
const result = GetDataRequestSchema.safeParse({ object: 'contact', id: 'c1', select });
624+
expect(result.success).toBe(true);
625+
if (result.success) expect(result.data.select).toEqual(select);
626+
});
627+
615628
it('should strip unknown query parameters via strict parsing', () => {
616629
const result = GetDataRequestSchema.strict().safeParse({
617630
object: 'contact',
@@ -718,6 +731,15 @@ describe('HttpFindQueryParamsSchema', () => {
718731
if (result.success) expect(result.data.select).toBe(value);
719732
});
720733

734+
// [#26909] The body side of the same door (`FindDataRequestSchema.query`,
735+
// the `POST /data/:object/query` body) now refuses what this one refuses.
736+
it.each(['', ' ', ',', ' , ', []])('the body-side declaration refuses select=%j too', (select) => {
737+
for (const key of ['select', '$select']) {
738+
const parsed = FindDataRequestSchema.safeParse({ object: 'contact', query: { object: 'contact', [key]: select } });
739+
expect(parsed.success, key).toBe(false);
740+
}
741+
});
742+
721743
it('rejects ?distinct — the querystring spelling of the removed query.distinct', () => {
722744
const result = HttpFindQueryParamsSchema.safeParse({ distinct: true });
723745
expect(result.success).toBe(false);

0 commit comments

Comments
 (0)