Skip to content

Commit 794bcd8

Browse files
committed
fix(spec)!: HttpFindQueryParamsSchema declares the count and select values the list door accepts
count reads the door's accept set from QueryTransportParamsSchema.shape.count and parses 'false' as false; select must name at least one field. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WGufzh5dnFHGxFUBugn12b
1 parent 4b59358 commit 794bcd8

4 files changed

Lines changed: 65 additions & 5 deletions

File tree

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
---
2+
'@objectstack/spec': patch
3+
---
4+
5+
fix(spec)!: `HttpFindQueryParamsSchema` declares the `count` and `select` values the list door accepts, instead of a coerced boolean and any string (#26817)
6+
7+
Clause-②: no (narrowing) — the published `GET /data/:object` querystring declaration refuses a `count` other than true or false and a `select` naming no field, which it admitted before. The door already refused both 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: two querystring values the declaration admitted, and the Data API list door already refused, are now refused by the declaration too. A caller drops the parameter or sends a well-formed value; there is nothing for a migration to rewrite and no tombstone. -->
11+
12+
**BREAKING** accept-set narrowing of a published transport declaration (`@objectstack/spec/api`), read by codegen, the reference docs and clients; it has no runtime reader.
13+
14+
- **Before.** `count` was `z.coerce.boolean()`: the string `'false'` parsed as `true`, and `'maybe'`, `'1'` or a blank value parsed as a boolean. `select` was any string, so a blank or comma-only value was admitted.
15+
- **Now.** `count` is the door's own accept set, read from `QueryTransportParamsSchema.shape.count` (the boolean, or the strings `'true'` and `'false'`) and parsed to the boolean it means: `'false'` is `false`. `select` must name at least one field: a value that is blank, whitespace-only or only commas and spaces is refused, published as the pattern `[^\s,]`. Both match what the list door answers with `400 VALIDATION_ERROR`.
16+
- **Unchanged.** Every other parameter, `count: true` / `false`, and a named projection (`name,email`, spaces and empty members between commas trimmed by the door as before).
17+
- **Who sees it.** Code that parses a querystring bag with this schema and relied on the coercion, or a generated client that trusted the wider declaration.
18+
19+
**The remedy.** Send `count` as `true` or `false` (or leave it out), and `select` naming at least one field (or leave it out to read every column).

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2042,15 +2042,15 @@ The published metadata item body, opaque by ruling (1C). Shape is the item's own
20422042
| :--- | :--- | :--- | :--- |
20432043
| **filter** | `string` | optional | JSON-encoded filter expression (canonical, singular). |
20442044
| **filters** | `string` | optional | JSON-encoded filter expression (deprecated plural alias). |
2045-
| **select** | `string` | optional | Comma-separated list of fields to retrieve. |
2045+
| **select** | `string` | optional | Comma-separated list of fields to retrieve — at least one field name; a value naming no field (blank, or only commas and spaces) is refused. |
20462046
| **sort** | `string` | optional | Sort expression (e.g. "name asc,created_at desc" or "-created_at"). |
20472047
| **orderBy** | `string` | optional | Alias for sort (OData compatibility). |
20482048
| **top** | `integer \| string` | optional | Max records to return (limit) — a non-negative integer. |
20492049
| **skip** | `integer \| string` | optional | Records to skip (offset) — a non-negative integer. |
20502050
| **expand** | `string` | optional | Comma-separated list of lookup/master_detail field names to expand. Resolved to populate array and passed to the engine for batch $in expansion. |
20512051
| **search** | `string` | optional | Full-text search query. |
20522052
| **distinct** | `never` | optional | [REMOVED] `query.distinct` was removed in @objectstack/spec 17 (ADR-0049 / ADR-0078) — no driver ever rendered SELECT DISTINCT; the flag's only observable effect was MIS-WIRED: the REST list path treated a distinct query as not countable and silently degraded `total`/`hasMore` to a page-local estimate while still returning duplicate rows. Delete the key; `QueryBuilder.distinct()` was removed with it, and the count suppression is gone (`total` is truthful again). For unique values of one column use the SQL/memory drivers' `distinct(object, field)` door; for unique combinations, `groupBy`; for a deduplicated count, the `count_distinct` aggregation. |
2053-
| **count** | `boolean` | optional | Include total count in response. |
2053+
| **count** | `boolean \| Enum<'true' \| 'false'>` | optional | Include the total count in the response — `true` or `false`; any other value is refused. |
20542054

20552055

20562056
---

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

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -692,6 +692,32 @@ describe('HttpFindQueryParamsSchema', () => {
692692
expect(result.success).toBe(true);
693693
});
694694

695+
// [#26817] The list door's accept set for `count` and `select` — not
696+
// `z.coerce.boolean()` (which read `'false'` as `true` and admitted
697+
// `'maybe'`) and not any string (which admitted a blank projection).
698+
it.each([['true', true], ['false', false], [true, true], [false, false]])(
699+
'reads count=%j as %j',
700+
(value, expected) => {
701+
const result = HttpFindQueryParamsSchema.safeParse({ count: value });
702+
expect(result.success).toBe(true);
703+
if (result.success) expect(result.data.count).toBe(expected);
704+
},
705+
);
706+
707+
it.each(['maybe', '1', '0', '', 'TRUE', 1, null])('refuses count=%j — neither true nor false', (value) => {
708+
expect(HttpFindQueryParamsSchema.safeParse({ count: value }).success).toBe(false);
709+
});
710+
711+
it.each(['', ' ', ',', ' , ,', '\t'])('refuses select=%j — names no field', (value) => {
712+
expect(HttpFindQueryParamsSchema.safeParse({ select: value }).success).toBe(false);
713+
});
714+
715+
it.each(['name', 'name,email', ' name , email ', 'name,,email'])('keeps select=%j — names a field', (value) => {
716+
const result = HttpFindQueryParamsSchema.safeParse({ select: value });
717+
expect(result.success).toBe(true);
718+
if (result.success) expect(result.data.select).toBe(value);
719+
});
720+
695721
it('rejects ?distinct — the querystring spelling of the removed query.distinct', () => {
696722
const result = HttpFindQueryParamsSchema.safeParse({ distinct: true });
697723
expect(result.success).toBe(false);

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

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import { retiredKey } from '../shared/retired-key';
1818
// through it, so `api/UpdateAiConversationRequest.json` states it.
1919
import { requiredOneOf } from '../shared/refinement-projection';
2020
import { MetadataItemNameSchema } from '../shared/identifiers.zod';
21-
import { DroppedFieldsEventSchema, QueryPageWindowParamSchema, QueryWithTransportSchema, ValidationAdvisoryEventSchema } from '../data/data-engine.zod';
21+
import { DroppedFieldsEventSchema, QueryPageWindowParamSchema, QueryTransportParamsSchema, QueryWithTransportSchema, ValidationAdvisoryEventSchema } from '../data/data-engine.zod';
2222
import {
2323
AnalyticsQueryRequestSchema,
2424
AnalyticsResultResponseSchema,
@@ -2369,7 +2369,14 @@ export const HttpFindQueryParamsSchema = lazySchema(() => z.object({
23692369
filter: z.string().optional().describe('JSON-encoded filter expression (canonical, singular).'),
23702370
/** @deprecated Use `filter` (singular). Accepted for backward compatibility. */
23712371
filters: z.string().optional().describe('JSON-encoded filter expression (deprecated plural alias).'),
2372-
select: z.string().optional().describe('Comma-separated list of fields to retrieve.'),
2372+
// [#26817] The projection the list door reads: it splits on commas, trims
2373+
// each member and refuses a value naming no field (blank, whitespace-only,
2374+
// commas only) with a 400. `[^\s,]` is that rule as a pattern — `\s` is the
2375+
// set `trim()` strips — so the published JSON Schema states it too.
2376+
select: z.string().regex(/[^\s,]/, 'Name at least one field').optional().describe(
2377+
'Comma-separated list of fields to retrieve — at least one field name; a value naming no field '
2378+
+ '(blank, or only commas and spaces) is refused.'
2379+
),
23732380
sort: z.string().optional().describe('Sort expression (e.g. "name asc,created_at desc" or "-created_at").'),
23742381
orderBy: z.string().optional().describe('Alias for sort (OData compatibility).'),
23752382
// [#25269] The page window the list door enforces, not `z.coerce.number()`,
@@ -2384,7 +2391,15 @@ export const HttpFindQueryParamsSchema = lazySchema(() => z.object({
23842391
search: z.string().optional().describe('Full-text search query.'),
23852392
/** `?distinct` — REMOVED (#4286): the querystring spelling of `query.distinct`, same tombstone. */
23862393
distinct: retiredKey(QUERY_DISTINCT_REMOVED),
2387-
count: z.coerce.boolean().optional().describe('Include total count in response.'),
2394+
// [#26817] The door's accept set, read from the one declaration the door
2395+
// parses (`QueryTransportParamsSchema.count`, which `findData` checks) and
2396+
// lowered to the boolean it means — not `z.coerce.boolean()`, which read
2397+
// `'false'` as `true` and admitted `'maybe'` that the door refuses with a 400.
2398+
// A querystring carries no `null`, so the nullable arm is unwrapped.
2399+
count: QueryTransportParamsSchema.shape.count.unwrap().unwrap()
2400+
.transform((flag) => flag === true || flag === 'true')
2401+
.optional()
2402+
.describe('Include the total count in the response — `true` or `false`; any other value is refused.'),
23882403
}));
23892404

23902405
/**

0 commit comments

Comments
 (0)