Skip to content

Commit 621212a

Browse files
committed
fix(rest): refuse ?names= on the package list, whose items are keyed by id; retire the stale TSDoc paragraph
Contract review 6672872746 should-fix items, per the seat's ruling: the package list refuses ?names= with a located 400 on both transports (pinned, ablated), the GetMetaItemsRequestSchema TSDoc says the member is served, the describe and http-protocol.mdx name the package exception, and the changeset spells Clause-② canonically. Co-authored-by: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016WV4cyaiN5dg5cw1zSyihP
1 parent 5f55d49 commit 621212a

7 files changed

Lines changed: 74 additions & 13 deletions

File tree

‎.changeset/29236-meta-list-names-filter.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@
88

99
feat(rest)!: the metadata list reads several items by name in one request (`?names=a,b,c`), and refuses a query parameter it does not read
1010

11-
Clause-②: yes (narrowing + widening) — `GET /api/v1/meta/:type` (and its environment-scoped twin, on both the REST server and the runtime dispatcher) declares its closed query-parameter set, `package`, `preview`, `object`, `include`, `id`, `names` and `locale`, and refuses any other name with `400 VALIDATION_ERROR`, where it ignored it and answered the whole list with `200`. The widening half: `?names=a,b,c` narrows every type's list to the items of those names, `@objectstack/client`'s `meta.getItems(type, { names })` sends it, and `@objectstack/rest` exports three new names, the list's query decision that both transports ask: `META_LIST_QUERY_PARAMS`, `metaListQueryRefusal` and `metaListNames`. Ruling 6580261740 assigns both halves to this one server change.
11+
Clause-②: yes (narrowing) — `GET /api/v1/meta/:type` (and its environment-scoped twin, on both the REST server and the runtime dispatcher) declares its closed query-parameter set, `package`, `preview`, `object`, `include`, `id`, `names` and `locale`, and refuses any other name with `400 VALIDATION_ERROR`, where it ignored it and answered the whole list with `200`. The widening half: `?names=a,b,c` narrows every type's list but `package`'s to the items of those names, `@objectstack/client`'s `meta.getItems(type, { names })` sends it, and `@objectstack/rest` exports three new names, the list's query decision that both transports ask: `META_LIST_QUERY_PARAMS`, `metaListQueryRefusal` and `metaListNames`. Ruling 6580261740 assigns both halves to this one server change.
1212
Metadata-protocol: none
1313

1414
<!-- adr-0087: not-required (no-migration-prescription) No key of any schema is added, removed, renamed or re-shaped: `GetMetaItemsRequestSchema.names` was already declared, and only its description loses the planned marker. What moves is the list route's answer to a query-string name it never read, and nothing at rest records that answer, so there is nothing for a migration to rewrite. -->
1515

16-
**The batch by-names read.** `GET /api/v1/meta/:type?names=a,b,c` answers only the items of those names, among the items the list would answer without it, on every metadata type. One comma-separated value, as the data routes spell `fields`; each name is trimmed and repeats count once. A name that matches no item is simply absent from the answer (no `404`). The names are handed to the store read (`GetMetaItemsRequest.names`), so `@objectstack/metadata-protocol`'s `getMetaItems` filters before it computes locks, governance and diagnostics, and the list's per-caller gate, object field mask and translation run on the named items only. A value that names no item (`?names=`, `?names=,`) is refused with `400 VALIDATION_ERROR` rather than read as every item; leave the key out to list every item. A repeated `?names=` is refused like the list's other single-valued parameters. Before, `?names=` was ignored, so a client that needed several objects paid one by-name request for each.
16+
**The batch by-names read.** `GET /api/v1/meta/:type?names=a,b,c` answers only the items of those names, among the items the list would answer without it, on every metadata type except `package`, whose items are keyed by id and carry no `name`: the `package` list refuses `?names=` with `400 VALIDATION_ERROR`. One comma-separated value, as the data routes spell `fields`; each name is trimmed and repeats count once. A name that matches no item is simply absent from the answer (no `404`). The names are handed to the store read (`GetMetaItemsRequest.names`), so `@objectstack/metadata-protocol`'s `getMetaItems` filters before it computes locks, governance and diagnostics, and the list's per-caller gate, object field mask and translation run on the named items only. A value that names no item (`?names=`, `?names=,`) is refused with `400 VALIDATION_ERROR` rather than read as every item; leave the key out to list every item. A repeated `?names=` is refused like the list's other single-valued parameters. Before, `?names=` was ignored, so a client that needed several objects paid one by-name request for each.
1717

1818
**BREAKING** accept-set narrowing at the metadata list (`@objectstack/rest`, `@objectstack/runtime`): a query parameter the list does not read is refused instead of ignored.
1919

‎content/docs/protocol/kernel/http-protocol.mdx‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -971,7 +971,9 @@ To read several items of one type in a single request, name them:
971971
`GET /api/v1/meta/object?names=account,contact` answers only those items, among
972972
the ones the caller may see. The value is one comma-separated list; a name that
973973
matches no item is simply absent from `items`, and an empty value (`?names=`) is
974-
refused with `400 VALIDATION_ERROR`. The list reads a closed set of query
974+
refused with `400 VALIDATION_ERROR`. `?names=` works on every type except
975+
`package`, whose items are keyed by id rather than name; the `package` list
976+
refuses it with `400 VALIDATION_ERROR`. The list reads a closed set of query
975977
parameters (`package`, `preview`, `object`, `include`, `id`, `names` and
976978
`locale`) and refuses any other name with `400 VALIDATION_ERROR` instead of
977979
ignoring it.

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1517,7 +1517,7 @@ One changed key path of the pending draft, and the last write that changed it.
15171517
| :--- | :--- | :--- | :--- |
15181518
| **type** | `string` | ✅ | Metadata type name (e.g., "object", "plugin") |
15191519
| **packageId** | `string` | optional | Optional package ID to filter items by |
1520-
| **names** | `string[]` | optional | Item names to narrow the list to: only the named items of the type are answered, among those the list would answer without it. Sent over HTTP as one comma-separated value (`?names=a,b,c`). A name that matches no item is simply absent from the answer (no 404). An empty value is refused with 400 rather than read as every item; leave the key out to list every item. |
1520+
| **names** | `string[]` | optional | Item names to narrow the list to: only the named items of the type are answered, among those the list would answer without it. Served on every type except `package`, whose items are keyed by id; the `package` list refuses it with 400. Sent over HTTP as one comma-separated value (`?names=a,b,c`). A name that matches no item is simply absent from the answer (no 404). An empty value is refused with 400 rather than read as every item; leave the key out to list every item. |
15211521
| **previewDrafts** | `boolean` | optional | Draft-visibility switch (ADR-0033 draft-overlay preview): when true, pending `state='draft'` rows are overlaid on the active list — draft wins on name collision, draft-only items appear, and each overlaid item is tagged `_draft: true` so UIs can badge the preview. Absent/false = published world only. Declaration ≠ authorization: this member only switches which rows are read, and ADR-0106 masking is unaffected — callers without draft-preview authorization are refused upstream (admin-gated), not by this schema. |
15221522

15231523

‎packages/rest/src/meta-item-read-gate.ts‎

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2433,7 +2433,7 @@ export interface MetaItemQueryRefusal {
24332433
readonly status: 400;
24342434
readonly code: 'VALIDATION_ERROR';
24352435
readonly message: string;
2436-
readonly rule: 'unknown-parameter' | 'repeated-parameter' | 'layered-member' | 'bracketed-parameter';
2436+
readonly rule: 'unknown-parameter' | 'repeated-parameter' | 'layered-member' | 'bracketed-parameter' | 'names-on-package';
24372437
}
24382438

24392439
/**
@@ -2660,11 +2660,25 @@ export function metaListUnknownParamRefusal(metaType: string, query: unknown): M
26602660
if (!bracketedKeyJudgedByList(metaType, key)) judged[key] = true;
26612661
}
26622662
const message = unknownQueryParamRefusalMessage(judged, META_LIST_QUERY_PARAMS);
2663-
return message === undefined
2664-
? undefined
2665-
: { status: 400, code: 'VALIDATION_ERROR', message, rule: 'unknown-parameter' };
2663+
if (message !== undefined) return { status: 400, code: 'VALIDATION_ERROR', message, rule: 'unknown-parameter' };
2664+
if (metaType === 'package' && Object.prototype.hasOwnProperty.call(query, 'names')) {
2665+
return { status: 400, code: 'VALIDATION_ERROR', message: NAMES_ON_PACKAGE_LIST_MESSAGE, rule: 'names-on-package' };
2666+
}
2667+
return undefined;
26662668
}
26672669

2670+
/**
2671+
* [#29236, contract review 6672872746] `?names=` on the `package` list. A
2672+
* `package` list item is keyed by its id (`manifest.id`) and carries no
2673+
* `name`, so a names filter there could never match and would answer `200 []`
2674+
* for every value: the silent zero the list's closed set exists to remove. It
2675+
* is refused instead, on both transports, before any read. Matching packages
2676+
* by id is a different behaviour and not served here.
2677+
*/
2678+
export const NAMES_ON_PACKAGE_LIST_MESSAGE =
2679+
"Query parameter 'names' is not served on the 'package' list: package items are keyed by id, not by name, "
2680+
+ 'so no name could match. The list was not served. Leave the parameter out to list every package you can see.';
2681+
26682682
/**
26692683
* [#29236, ruling 6580261740 letter A] THE reading of `?names=` on the
26702684
* `/meta/:type` list, for both transports and the chain: ONE comma-separated

‎packages/rest/src/meta-query-arity-doors.test.ts‎

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import { describe, it, expect, vi } from 'vitest';
2323
import {
2424
META_LIST_QUERY_PARAMS,
2525
META_QUERY_ARITY_DOORS,
26+
NAMES_ON_PACKAGE_LIST_MESSAGE,
2627
metaListQueryRefusal,
2728
metaQueryArityRefusal,
2829
type MetaQueryArityDoor,
@@ -350,4 +351,37 @@ describe('[#29236] the list\'s closed query set — recognition before arity', (
350351
expect(app.status).toBe(400);
351352
expect(JSON.stringify(app.body)).toContain("Query parameter 'id[]' names no app");
352353
});
354+
355+
// [contract review 6672872746] A `package` list item is keyed by id and carries no `name`, so
356+
// `?names=` there could only ever answer `200 []`. It is refused instead, before any read.
357+
it('refuses `?names=` on the `package` list with its own located sentence', () => {
358+
expect(NAMES_ON_PACKAGE_LIST_MESSAGE).toBe(
359+
"Query parameter 'names' is not served on the 'package' list: package items are keyed by id, not by name, "
360+
+ 'so no name could match. The list was not served. Leave the parameter out to list every package you can see.',
361+
);
362+
for (const names of ['crm', 'crm,helpdesk', '', ['a', 'b']]) {
363+
expect(metaListQueryRefusal('package', { names })).toEqual({
364+
status: 400, code: 'VALIDATION_ERROR', message: NAMES_ON_PACKAGE_LIST_MESSAGE, rule: 'names-on-package',
365+
});
366+
}
367+
// An undeclared key on the `package` list keeps the recognition sentence, which outranks it.
368+
expect(metaListQueryRefusal('package', { names: 'crm', zeta: '1' })?.message).toBe(unknownListParam('zeta'));
369+
// Controls: the `package` list without `names`, and `names` on every other type.
370+
expect(metaListQueryRefusal('package', {})).toBeUndefined();
371+
expect(metaListQueryRefusal('package', { preview: 'draft' })).toBeUndefined();
372+
for (const type of ['object', 'app', 'view', 'flow']) expect(metaListQueryRefusal(type, { names: 'crm' })).toBeUndefined();
373+
});
374+
375+
it('RestServer: `?names=` on `/meta/package` answers the nested 400 before any protocol read', async () => {
376+
const { protocol, status, body } = await driveList('package', { names: 'com.acme.crm' });
377+
expect({ status, body }).toEqual({
378+
status: 400, body: { error: { code: 'VALIDATION_ERROR', message: NAMES_ON_PACKAGE_LIST_MESSAGE } },
379+
});
380+
expect(protocol.getMetaItems).not.toHaveBeenCalled();
381+
// Control: the same door without `names` reaches the protocol read (this double declares no
382+
// `package` type, so what answers then is the type check, not the names refusal).
383+
const control = await driveList('package', {});
384+
expect(JSON.stringify(control.body)).not.toContain('keyed by id');
385+
expect(control.protocol.getMetaTypes).toHaveBeenCalled();
386+
});
353387
});

‎packages/runtime/src/domains/dispatcher-query-arity.test.ts‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,16 @@ describe('[#23214] /meta — the four arity doors, over the list both transports
228228
expect(localised.protocol.getMetaItems.mock.calls[0][0]).not.toHaveProperty('names');
229229
});
230230

231+
it('refuses `?names=` on the `package` list (its items are keyed by id) before the protocol read', async () => {
232+
for (const path of ['/meta/package']) {
233+
const { dispatcher, protocol } = boot();
234+
const answer = await get(dispatcher, path, { names: 'com.acme' });
235+
expect({ path, status: answer.status, code: answer.body?.error?.code }).toEqual({ path, status: 400, code: 'VALIDATION_ERROR' });
236+
expect(answer.body?.error?.message).toMatch(/^Query parameter 'names' is not served on the 'package' list: package items are keyed by id/);
237+
expect(protocol.getMetaItems).not.toHaveBeenCalled();
238+
}
239+
});
240+
231241
it('refuses an EMPTY `names` with 400 VALIDATION_ERROR before the protocol read', async () => {
232242
const { dispatcher, protocol } = boot();
233243
const answer = await get(dispatcher, '/meta/view', { names: '' });

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -259,10 +259,10 @@ export const GetMetaTypesResponseSchema = lazySchema(() => z.object({
259259
* empty list. A minimum, not a refinement, so the published JSON Schema
260260
* states it.
261261
*
262-
* **Declared ahead of its producer.** No list door reads `names` yet, so its
263-
* describe opens `[PLANNED — not yet served]`; the server PR on #29236 drops
264-
* the marker in the change that serves the member (the pin is in
265-
* `protocol.test.ts`).
262+
* **Served.** Both list doors (the REST server's and the runtime
263+
* dispatcher's `GET /meta/:type`) read `?names=` and push it down here (#29236),
264+
* on every type except `package`: a `package` list item is keyed by its id and
265+
* carries no `name`, so the `package` list refuses `?names=` with `400`.
266266
*/
267267
export const GetMetaItemsRequestSchema = lazySchema(() => z.object({
268268
type: z.string().describe('Metadata type name (e.g., "object", "plugin")'),
@@ -272,7 +272,8 @@ export const GetMetaItemsRequestSchema = lazySchema(() => z.object({
272272
.optional()
273273
.describe(
274274
'Item names to narrow the list to: only the named items of the type '
275-
+ 'are answered, among those the list would answer without it. Sent over HTTP as one '
275+
+ 'are answered, among those the list would answer without it. Served on every type except '
276+
+ '`package`, whose items are keyed by id; the `package` list refuses it with 400. Sent over HTTP as one '
276277
+ 'comma-separated value (`?names=a,b,c`). A name that matches no item is simply absent from the '
277278
+ 'answer (no 404). An empty value is refused with 400 rather than read as every item; leave the '
278279
+ 'key out to list every item.',

0 commit comments

Comments
 (0)