Skip to content

Commit 4f9a3f8

Browse files
fix(spec): GetMetaTypesResponseSchema declares every member /meta/types serves (#36948)
<!-- claude-projects-attribution: {"github_login":"os-support-ai"} --> _Requested by **Yibo Wang** · [project thread](https://claude.ai/code/project/chan_01BVUyyPie8gHwoPM18iABwB?thread=cmsg_01BVUyyPie8gHwoPM18iABwBDErTg6aA1Xze24mDcUfseY)_ Fixes #36887 The published wire schema of `GET /meta/types` now declares every member the route serves on an entry. It follows #36881, which declared `list`, and is independent of #36926 (#36860 part b), which touches the listing's translation, not this schema. Clause-②: yes (widening: the published response schema declares four members the route already serves) Metadata-protocol: added Skills-docs: none — the declared members are Studio display data the spec registry and plugins produce, not something a metadata author writes; `skills/objectstack-ui/SKILL.md:34` names `entries[].schema` only and stays true ## 维护者速读 - 对外发布的类型列表响应格式现在写全了服务器一直在返回的字段(schema、form、actions、schemaId),按这份格式写客户端的人终于能看到它们;服务器返回的内容一点没变。 - 属于工作室元数据列表标准化的收尾(#36860 的配套卡)。 - 影响按发布的协议类型写客户端或生成代码的开发者,最终用户看不到变化;合并后可直接撤回。 - 无需你决定。 ## What changes - **`GetMetaTypesResponseSchema` (`@objectstack/spec`, `api/protocol.zod.ts`).** Each entry now declares: - `schemaId`: a string, the same value as `type`. - `schema`: a JSON Schema record. It is optional, because a type with neither a spec schema nor a hand-crafted one serves none. - `form`: a `FormView` (`FormViewSchema`, strict). It is optional, because a type with no declared form serves none. - `actions`: `Action[]` (`ActionSchema`). It is optional, absent when the type has none. The card names `schema` and `form`. The same row also serves `schemaId` and `actions`, which were undeclared too. The card's Expected line ("declares every member the route serves") and its strict test cover them, so they are declared here as well (stated in the claim, 7127426588). - **A parsed shape.** `form` and `actions` carry defaults, so the response's input and output types now differ. Following ADR-0122, `GetMetaTypesResponseParsed` is declared next to the bare alias, and its isomorphism pin leaves `type-alias-convention.pin.test.ts` (888 → 887, with a receipt line). - **Generated artifacts.** The `api` shards of `api-surface` and `export-origins` and the protocol reference page are regenerated. `dropped-refinements.baseline.json` declares the 12 refinement sites the response now reaches through `FormViewSchema` and `ActionSchema`, which the build printed (275 schemas, 1,183 sites). Those refinements are correct runtime rules that the published JSON Schema cannot express, as for every other schema that embeds these two. - Nothing the server sends changes. ## Tests - `packages/metadata-protocol/src/protocol.meta-types-response-schema-36887.test.ts` (new). It takes a real `getMetaTypes()` answer through JSON, as the wire sends it, and covers every registry type plus `webhook` (the synthesised arm), with a plugin-registered `datasource` action. - The answer parses, and no served member is stripped, which is the strict reading, since `z.object` drops an undeclared key. - A second case checks that the members the card names are actually on the wire, so the parse read them. - Controls: a served key the schema does not declare is reported, and a malformed `form` is refused (so `form` is typed, not `unknown`). - 4 passed. On the spec dist from before this change, the strict case reported 82 stripped members (`agent.schemaId`, `agent.schema`, `agent.form`, …). - `packages/spec` `src/api` + the alias pin file: 65 files, 2,123 passed. ## Acceptance notes - `schema` and `form` are declared with their real shapes: `form` reuses `FormViewSchema`, and `schema` is a JSON Schema object, for which the spec has no narrower schema. - `@objectstack/metadata-protocol` changes only a test and the engine-double ledger, so the changeset names `@objectstack/spec` alone (`minor`, as `added` requires). - Overlap: `node scripts/pm/overlap-check.mjs` reads clean against `main` and open PRs. ## Verification Read first, by risk: 1. `packages/spec/src/api/protocol.zod.ts`: the four new members, and the `optional` on `schema` and `form` (both can be absent at runtime). 2. `packages/spec/dropped-refinements.baseline.json`: the 12 declared sites and the header counts. Two-minute check: `pnpm --filter @objectstack/metadata-protocol exec vitest run src/protocol.meta-types-response-schema-36887.test.ts`. Expect 4 passed. <details><summary>Gates on ce27cea</summary> - `node scripts/pm/dispatch-gates.mjs --ran`: 121 derived, 121 run, 0 NOT-MEASURED, all exit 0. `check:engine-double-contract` first failed on the new test's engine doubles and passed after `--write` (the ledger commit). That commit's `scripts/` path derived 7 more families, all run and green. - `pnpm --filter @objectstack/spec check:generated --fix` regenerated the 3 stale artifacts and re-checked them green. The alias pin's type error was fixed the ADR-0122 way (a `Parsed` alias, with the pin removed). - `check-governed-merges --branch HEAD`: NOT governed, 183 changed lines (+175 / −8). - `tsc --noEmit` is clean for `@objectstack/metadata-protocol`. </details> 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01WGufzg7mFFG5b13DcQ93kf <!-- signed: repo:objectstack#3 · os-support-ai · session_01WGufzg7mFFG5b13DcQ93kf --> --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent 0212714 commit 4f9a3f8

9 files changed

Lines changed: 190 additions & 8 deletions

File tree

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
'@objectstack/spec': minor
3+
---
4+
5+
fix(spec): `GetMetaTypesResponseSchema` declares every member `GET /meta/types` serves on an entry
6+
7+
Clause-②: yes (widening: the published response schema declares four members the route already serves)
8+
Metadata-protocol: added
9+
10+
Each `/meta/types` entry has always carried `schemaId`, `schema` (the type's JSON Schema), `form` (its Studio editor layout) and, when the type has any, `actions`, but the wire schema declared none of them, so a typed client and the published JSON Schema could not see them. They are declared now: `schemaId` as a string, `schema` as a JSON Schema record, `form` as a `FormView` and `actions` as `Action[]`, each optional except `schemaId`, as the route serves them. Nothing the server sends changes. Because `form` and `actions` carry defaults, the response now has a parsed shape, named `GetMetaTypesResponseParsed`.

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1697,13 +1697,14 @@ One changed key path of the pending draft, and the last write that changed it.
16971697
| Property | Type | Required | Description |
16981698
| :--- | :--- | :--- | :--- |
16991699
| **types** | `string[]` | ✅ | Available metadata type names (e.g., "object", "plugin", "view") |
1700-
| **entries** | `{ type: string; label: string; description?: string; filePatterns: string[]; … }[]` | optional | Enriched per-type registry entries (Phase 3a) |
1700+
| **entries** | `{ type: string; schemaId: string; label: string; description?: string; … }[]` | optional | Enriched per-type registry entries (Phase 3a) |
17011701

17021702
### Nested Shape: `GetMetaTypesResponse.entries[number]`
17031703

17041704
| Property | Type | Required | Description |
17051705
| :--- | :--- | :--- | :--- |
17061706
| **type** | `string` | ✅ | Singular type identifier |
1707+
| **schemaId** | `string` | ✅ | Same value as `type`: the id the type's `schema`, `form` and `list` are bound to |
17071708
| **label** | `string` | ✅ | Human-readable label |
17081709
| **description** | `string` | optional | Brief description |
17091710
| **filePatterns** | `string[]` | ✅ | Glob patterns used to discover artifacts of this type |
@@ -1716,7 +1717,10 @@ One changed key path of the pending draft, and the last write that changed it.
17161717
| **domain** | `Enum<'data' \| 'ui' \| 'automation' \| 'system' \| 'security' \| 'ai'>` | ✅ | Protocol domain |
17171718
| **overrideSource** | `Enum<'registry' \| 'env'>` | ✅ | Whether allowEnvironmentOverlay comes from the static registry or is elevated by the OS_METADATA_WRITABLE environment variable |
17181719
| **createSeed** | `any` | optional | Authoritative minimal valid create seed for this type — Studio/CLI/API derive create defaults from it (single source of truth in @objectstack/spec). Absent for canvas-create types whose shape is built interactively. |
1720+
| **schema** | `Record<string, any>` | optional | JSON Schema of the type, derived from its spec schema, for the generic metadata editor. Absent for a type with neither a spec schema nor a hand-crafted one. |
1721+
| **form** | `{ type?: Enum<'simple' \| 'tabbed' \| 'wizard'>; layout?: Enum<'vertical' \| 'horizontal'>; columns?: integer; title?: string; … }` | optional | Form layout of the type's Studio editor, labels in the request locale. Absent for a type with no declared form, which Studio edits from `schema` alone. |
17191722
| **list** | `{ data?: object \| object \| object; columns: object[] }` | optional | Studio list layout of this type: the columns its metadata list shows, each naming a key of the type schema, headers in the request locale. Absent for a type with no declared list, which Studio lists by name, label and description. |
1723+
| **actions** | `{ name: string; label: string \| Record<string, string>; description?: string \| object \| string \| Record<string, string>; objectName?: string; … }[]` | optional | Type-level actions on a definition of this type (e.g. a datasource "Test connection"): the registry's declarative actions merged with plugin-registered ones. Absent when there are none. |
17201724

17211725

17221726
---
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.
2+
3+
/**
4+
* objectstack#36887 — the published wire schema of `GET /meta/types`
5+
* (`GetMetaTypesResponseSchema`) declares every member `getMetaTypes()`
6+
* serves on an entry.
7+
*
8+
* A real answer, sent through JSON as the wire sends it, is parsed with the
9+
* schema. `z.object` strips a key it does not declare, so "every served key
10+
* survives the parse" is the strict reading: a member the server sends and the
11+
* schema omits shows up as a missing key. Both arms of the listing are read —
12+
* registry types and a plugin type with no registry entry — and a type with a
13+
* plugin-registered action, so `actions` is on the wire.
14+
*
15+
* Controls: the same check reports a served key the schema does not declare,
16+
* and a malformed `form` is refused, so neither pin passes vacuously.
17+
*/
18+
import { describe, expect, it } from 'vitest';
19+
// `./protocol.js` reaches `import('@objectstack/lint')`; pay its first load at
20+
// collection, never inside a clocked case.
21+
import '@objectstack/lint';
22+
import {
23+
assertEngineDeleteDispatch,
24+
assertEngineUpdateDispatch,
25+
assertEngineFindOnePredicate,
26+
type EngineFindOneQueryInput,
27+
} from '@objectstack/metadata-core';
28+
import { DEFAULT_METADATA_TYPE_REGISTRY, registerMetadataTypeActions } from '@objectstack/spec/kernel';
29+
import { GetMetaTypesResponseSchema } from '@objectstack/spec/api';
30+
import { ObjectStackProtocolImplementation } from './protocol.js';
31+
32+
/** Every registry type, plus `webhook`: a plugin kind with no registry entry, served by the synthesised arm. */
33+
const SERVED_TYPES = [...new Set(DEFAULT_METADATA_TYPE_REGISTRY.map((e) => e.type)), 'webhook'];
34+
35+
function makeProtocol() {
36+
const engine: any = {
37+
async findOne(object: string, query?: EngineFindOneQueryInput) {
38+
assertEngineFindOnePredicate(object, query); return null;
39+
},
40+
async find() { return []; },
41+
async insert() { return { id: 'unused' }; },
42+
async update(_t: string, data: Record<string, unknown>, opts?: Record<string, unknown>) {
43+
assertEngineUpdateDispatch(data, opts);
44+
return { id: null };
45+
},
46+
async delete(_t: string, opts?: Record<string, unknown>) {
47+
assertEngineDeleteDispatch(opts);
48+
return { deleted: 1 };
49+
},
50+
async count() { return 0; },
51+
async transaction(fn: (ctx: unknown) => Promise<unknown>) { return fn(undefined); },
52+
async execute() { return {}; },
53+
async getObjectSchema() { return undefined; },
54+
registry: {
55+
getRegisteredTypes: () => [...SERVED_TYPES],
56+
registerItem: () => {},
57+
registerObject: () => {},
58+
unregisterItem: () => {},
59+
listItems: () => [],
60+
getItem: () => undefined,
61+
getArtifactItem: () => undefined,
62+
},
63+
};
64+
return new ObjectStackProtocolImplementation(engine, () => new Map(), undefined) as any;
65+
}
66+
67+
registerMetadataTypeActions('datasource', [
68+
{
69+
name: 'test_connection',
70+
label: 'Test connection',
71+
type: 'api',
72+
target: '/api/v1/datasources/${ctx.recordId}/test',
73+
} as any,
74+
]);
75+
76+
/** The answer as a client receives it: through JSON, so an `undefined` member is absent. */
77+
async function wireAnswer(): Promise<any> {
78+
return JSON.parse(JSON.stringify(await makeProtocol().getMetaTypes()));
79+
}
80+
81+
/** `type.key` for every member a served entry carries and the parsed entry lost. */
82+
function undeclaredMembers(wire: any, parsed: any): string[] {
83+
const lost: string[] = [];
84+
wire.entries.forEach((entry: any, i: number) => {
85+
for (const key of Object.keys(entry)) {
86+
if (!Object.prototype.hasOwnProperty.call(parsed.entries[i], key)) lost.push(`${entry.type}.${key}`);
87+
}
88+
});
89+
return lost;
90+
}
91+
92+
describe('GetMetaTypesResponseSchema declares what GET /meta/types serves (objectstack#36887)', () => {
93+
it('a real answer parses, and no served member is stripped', async () => {
94+
const wire = await wireAnswer();
95+
const result = GetMetaTypesResponseSchema.safeParse(wire);
96+
expect(result.success, JSON.stringify(result.error?.issues?.slice(0, 3))).toBe(true);
97+
expect(undeclaredMembers(wire, result.data)).toEqual([]);
98+
});
99+
100+
it('the members the card names are on the wire, so the parse above read them', async () => {
101+
const { entries } = await wireAnswer();
102+
const byType = new Map<string, any>(entries.map((e: any) => [e.type, e]));
103+
expect(byType.get('webhook'), 'the synthesised arm is served').toBeDefined();
104+
expect(entries.every((e: any) => e.schemaId === e.type)).toBe(true);
105+
expect(entries.filter((e: any) => e.schema !== undefined).length).toBeGreaterThan(0);
106+
expect(byType.get('hook').form.sections.length).toBeGreaterThan(0);
107+
expect(byType.get('hook').list.columns.length).toBeGreaterThan(0);
108+
expect(byType.get('datasource').actions.map((a: any) => a.name)).toContain('test_connection');
109+
});
110+
111+
it('control — a served member the schema does not declare is reported', async () => {
112+
const wire = await wireAnswer();
113+
wire.entries[0].notDeclared = true;
114+
const parsed = GetMetaTypesResponseSchema.parse(wire);
115+
expect(undeclaredMembers(wire, parsed)).toEqual([`${wire.entries[0].type}.notDeclared`]);
116+
});
117+
118+
it('control — a malformed form is refused, so `form` is typed, not `unknown`', async () => {
119+
const wire = await wireAnswer();
120+
const hook = wire.entries.find((e: any) => e.type === 'hook');
121+
hook.form = { ...hook.form, sections: 'not a list' };
122+
expect(GetMetaTypesResponseSchema.safeParse(wire).success).toBe(false);
123+
});
124+
});

‎packages/spec/api-surface/api.json‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -547,6 +547,7 @@
547547
"GetMetaTypesRequest (type)",
548548
"GetMetaTypesRequestSchema (const)",
549549
"GetMetaTypesResponse (type)",
550+
"GetMetaTypesResponseParsed (type)",
550551
"GetMetaTypesResponseSchema (const)",
551552
"GetNotificationPreferencesRequest (type)",
552553
"GetNotificationPreferencesRequestSchema (const)",

‎packages/spec/dropped-refinements.baseline.json‎

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
"description": "Shrink-only ledger of every PUBLISHED JSON Schema that is STILL WIDER than the Zod type it was generated from, because a rule written as `.refine()` reaches the runtime and not the file (#18670). `z.toJSONSchema()` has no arm for a `custom` check: a plain record, the same record with a `.refine()`, and the same record with an ABORTING `.refine()` all project byte-identically (measured on zod 4.4.3, the version packages/spec resolves). So a document one of these files ACCEPTS can still be refused at parse time, and an author -- or an AI -- validating against packages/spec/json-schema/** finds out a release later. Each `sites` path is a position under that schema at which a refinement is dropped; the same paths are written onto the artifact itself as `x-dropped-refinements`. Item 2 closed the first patterns: a refinement DECLARED through the closed list in src/shared/refinement-projection.ts is emitted into the published file, reads `projected` rather than `dropped`, and its row LEAVES this ledger in the same PR -- which is why the ledger shrinks and never grows on a repair. Every refinement outside that closed list stays here, and adding an arm to the list is a public-contract decision, not a refactor. Hand-edited on purpose and with no `gen:` script: a generator would let a new gap be admitted by running a command instead of by a decision, which is the silence this ledger exists to end. Adding, removing or moving a site fails packages/spec/scripts/build-schemas.ts until the line moves with it, and the failure prints the corrected entry in full. ⛔ Do not delete or weaken a refinement to shorten this file -- the runtime rule is correct; it is the projection that is silent, and the remedy is to teach the closed list a NAMED pattern, never to drop the rule.",
33
"measured": {
44
"zod": "4.4.3",
5-
"publishedSchemasWithDroppedRefinements": 274,
6-
"droppedRefinementSites": 1171,
5+
"publishedSchemasWithDroppedRefinements": 275,
6+
"droppedRefinementSites": 1183,
77
"refinementSitesThatDidProject": 728,
88
"refinementSitesWithNoJsonFormToCompare": 0
99
},
@@ -387,6 +387,22 @@
387387
"data.options[1].manifest.views.element.list.timeline.groupByField"
388388
]
389389
},
390+
"api/GetMetaTypesResponse": {
391+
"sites": [
392+
"entries.element.actions.element.in",
393+
"entries.element.actions.element.in.ai.outputSchema",
394+
"entries.element.actions.element.in.onSuccess",
395+
"entries.element.actions.element.in.params.element.in",
396+
"entries.element.actions.element.in.preflight.fields.element",
397+
"entries.element.actions.element.in.refusals.valueType",
398+
"entries.element.actions.element.in.resultDialog.fields.element",
399+
"entries.element.actions.element.in.texts.valueType",
400+
"entries.element.form",
401+
"entries.element.form.sections.element",
402+
"entries.element.form.subforms.element.columns.element",
403+
"entries.element.form.submitBehavior.options[1].url"
404+
]
405+
},
390406
"api/GetObjectPermissionsResponse": {
391407
"sites": [
392408
"fieldPermissions.valueType",

‎packages/spec/export-origins/api.json‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -527,6 +527,7 @@
527527
"GetMetaTypesRequest": "src/api/protocol.zod.ts#GetMetaTypesRequest (type)",
528528
"GetMetaTypesRequestSchema": "src/api/protocol.zod.ts#GetMetaTypesRequestSchema (const)",
529529
"GetMetaTypesResponse": "src/api/protocol.zod.ts#GetMetaTypesResponse (type)",
530+
"GetMetaTypesResponseParsed": "src/api/protocol.zod.ts#GetMetaTypesResponseParsed (type)",
530531
"GetMetaTypesResponseSchema": "src/api/protocol.zod.ts#GetMetaTypesResponseSchema (const)",
531532
"GetNotificationPreferencesRequest": "src/api/protocol.zod.ts#GetNotificationPreferencesRequest (type)",
532533
"GetNotificationPreferencesRequestSchema": "src/api/protocol.zod.ts#GetNotificationPreferencesRequestSchema (const)",

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
// Copyright (c) 2025 ObjectStack. Licensed under the Apache-2.0 license.
22

33
import { z } from 'zod';
4-
import { MetadataListViewSchema, ViewSchema } from '../ui/view.zod';
4+
import { FormViewSchema, MetadataListViewSchema, ViewSchema } from '../ui/view.zod';
5+
import { ActionSchema } from '../ui/action.zod';
56
import { I18nLabelSchema } from '../ui/i18n.zod';
67
import { DiscoverySchema } from './discovery.zod';
78
import {
@@ -211,6 +212,7 @@ export const GetMetaTypesResponseSchema = lazySchema(() => z.object({
211212
types: z.array(z.string()).describe('Available metadata type names (e.g., "object", "plugin", "view")'),
212213
entries: z.array(z.object({
213214
type: z.string().describe('Singular type identifier'),
215+
schemaId: z.string().describe('Same value as `type`: the id the type\'s `schema`, `form` and `list` are bound to'),
214216
label: z.string().describe('Human-readable label'),
215217
description: z.string().optional().describe('Brief description'),
216218
filePatterns: z.array(z.string()).describe('Glob patterns used to discover artifacts of this type'),
@@ -223,7 +225,10 @@ export const GetMetaTypesResponseSchema = lazySchema(() => z.object({
223225
domain: z.enum(['data', 'ui', 'automation', 'system', 'security', 'ai']).describe('Protocol domain'),
224226
overrideSource: z.enum(['registry', 'env']).describe('Whether allowEnvironmentOverlay comes from the static registry or is elevated by the OS_METADATA_WRITABLE environment variable'),
225227
createSeed: z.unknown().optional().describe('Authoritative minimal valid create seed for this type — Studio/CLI/API derive create defaults from it (single source of truth in @objectstack/spec). Absent for canvas-create types whose shape is built interactively.'),
228+
schema: z.record(z.string(), z.unknown()).optional().describe('JSON Schema of the type, derived from its spec schema, for the generic metadata editor. Absent for a type with neither a spec schema nor a hand-crafted one.'),
229+
form: FormViewSchema.optional().describe('Form layout of the type\'s Studio editor, labels in the request locale. Absent for a type with no declared form, which Studio edits from `schema` alone.'),
226230
list: MetadataListViewSchema.optional().describe('Studio list layout of this type: the columns its metadata list shows, each naming a key of the type schema, headers in the request locale. Absent for a type with no declared list, which Studio lists by name, label and description.'),
231+
actions: z.array(ActionSchema).optional().describe('Type-level actions on a definition of this type (e.g. a datasource "Test connection"): the registry\'s declarative actions merged with plugin-registered ones. Absent when there are none.'),
227232
})).optional().describe('Enriched per-type registry entries (Phase 3a)'),
228233
}));
229234

@@ -4934,6 +4939,8 @@ export type GetDiscoveryRequest = z.input<typeof GetDiscoveryRequestSchema>;
49344939
export type GetDiscoveryResponse = z.input<typeof GetDiscoveryResponseSchema>;
49354940
export type GetMetaTypesRequest = z.input<typeof GetMetaTypesRequestSchema>;
49364941
export type GetMetaTypesResponse = z.input<typeof GetMetaTypesResponseSchema>;
4942+
/** Post-parse shape of {@link GetMetaTypesResponse} — defaults applied, transforms run (ADR-0122). */
4943+
export type GetMetaTypesResponseParsed = z.infer<typeof GetMetaTypesResponseSchema>;
49374944
export type GetMetaItemsRequest = z.input<typeof GetMetaItemsRequestSchema>;
49384945
export type FlowRegistrationRefusal = z.input<typeof FlowRegistrationRefusalSchema>;
49394946
export type FlowRegistration = z.input<typeof FlowRegistrationSchema>;

0 commit comments

Comments
 (0)