diff --git a/.changeset/36887-meta-types-response-schema.md b/.changeset/36887-meta-types-response-schema.md new file mode 100644 index 00000000000..c4b9277e762 --- /dev/null +++ b/.changeset/36887-meta-types-response-schema.md @@ -0,0 +1,10 @@ +--- +'@objectstack/spec': minor +--- + +fix(spec): `GetMetaTypesResponseSchema` declares every member `GET /meta/types` serves on an entry + +Clause-②: yes (widening: the published response schema declares four members the route already serves) +Metadata-protocol: added + +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`. diff --git a/content/docs/references/api/protocol.mdx b/content/docs/references/api/protocol.mdx index e9f768ed44a..0c56ce40067 100644 --- a/content/docs/references/api/protocol.mdx +++ b/content/docs/references/api/protocol.mdx @@ -1696,13 +1696,14 @@ One changed key path of the pending draft, and the last write that changed it. | Property | Type | Required | Description | | :--- | :--- | :--- | :--- | | **types** | `string[]` | ✅ | Available metadata type names (e.g., "object", "plugin", "view") | -| **entries** | `{ type: string; label: string; description?: string; filePatterns: string[]; … }[]` | optional | Enriched per-type registry entries (Phase 3a) | +| **entries** | `{ type: string; schemaId: string; label: string; description?: string; … }[]` | optional | Enriched per-type registry entries (Phase 3a) | ### Nested Shape: `GetMetaTypesResponse.entries[number]` | Property | Type | Required | Description | | :--- | :--- | :--- | :--- | | **type** | `string` | ✅ | Singular type identifier | +| **schemaId** | `string` | ✅ | Same value as `type`: the id the type's `schema`, `form` and `list` are bound to | | **label** | `string` | ✅ | Human-readable label | | **description** | `string` | optional | Brief description | | **filePatterns** | `string[]` | ✅ | Glob patterns used to discover artifacts of this type | @@ -1715,7 +1716,10 @@ One changed key path of the pending draft, and the last write that changed it. | **domain** | `Enum<'data' \| 'ui' \| 'automation' \| 'system' \| 'security' \| 'ai'>` | ✅ | Protocol domain | | **overrideSource** | `Enum<'registry' \| 'env'>` | ✅ | Whether allowEnvironmentOverlay comes from the static registry or is elevated by the OS_METADATA_WRITABLE environment variable | | **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. | +| **schema** | `Record` | 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. | +| **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. | | **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. | +| **actions** | `{ name: string; label: string \| Record; description?: string \| object \| string \| Record; 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. | --- diff --git a/packages/metadata-protocol/src/protocol.meta-types-response-schema-36887.test.ts b/packages/metadata-protocol/src/protocol.meta-types-response-schema-36887.test.ts new file mode 100644 index 00000000000..dd58466e93a --- /dev/null +++ b/packages/metadata-protocol/src/protocol.meta-types-response-schema-36887.test.ts @@ -0,0 +1,124 @@ +// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license. + +/** + * objectstack#36887 — the published wire schema of `GET /meta/types` + * (`GetMetaTypesResponseSchema`) declares every member `getMetaTypes()` + * serves on an entry. + * + * A real answer, sent through JSON as the wire sends it, is parsed with the + * schema. `z.object` strips a key it does not declare, so "every served key + * survives the parse" is the strict reading: a member the server sends and the + * schema omits shows up as a missing key. Both arms of the listing are read — + * registry types and a plugin type with no registry entry — and a type with a + * plugin-registered action, so `actions` is on the wire. + * + * Controls: the same check reports a served key the schema does not declare, + * and a malformed `form` is refused, so neither pin passes vacuously. + */ +import { describe, expect, it } from 'vitest'; +// `./protocol.js` reaches `import('@objectstack/lint')`; pay its first load at +// collection, never inside a clocked case. +import '@objectstack/lint'; +import { + assertEngineDeleteDispatch, + assertEngineUpdateDispatch, + assertEngineFindOnePredicate, + type EngineFindOneQueryInput, +} from '@objectstack/metadata-core'; +import { DEFAULT_METADATA_TYPE_REGISTRY, registerMetadataTypeActions } from '@objectstack/spec/kernel'; +import { GetMetaTypesResponseSchema } from '@objectstack/spec/api'; +import { ObjectStackProtocolImplementation } from './protocol.js'; + +/** Every registry type, plus `webhook`: a plugin kind with no registry entry, served by the synthesised arm. */ +const SERVED_TYPES = [...new Set(DEFAULT_METADATA_TYPE_REGISTRY.map((e) => e.type)), 'webhook']; + +function makeProtocol() { + const engine: any = { + async findOne(object: string, query?: EngineFindOneQueryInput) { + assertEngineFindOnePredicate(object, query); return null; + }, + async find() { return []; }, + async insert() { return { id: 'unused' }; }, + async update(_t: string, data: Record, opts?: Record) { + assertEngineUpdateDispatch(data, opts); + return { id: null }; + }, + async delete(_t: string, opts?: Record) { + assertEngineDeleteDispatch(opts); + return { deleted: 1 }; + }, + async count() { return 0; }, + async transaction(fn: (ctx: unknown) => Promise) { return fn(undefined); }, + async execute() { return {}; }, + async getObjectSchema() { return undefined; }, + registry: { + getRegisteredTypes: () => [...SERVED_TYPES], + registerItem: () => {}, + registerObject: () => {}, + unregisterItem: () => {}, + listItems: () => [], + getItem: () => undefined, + getArtifactItem: () => undefined, + }, + }; + return new ObjectStackProtocolImplementation(engine, () => new Map(), undefined) as any; +} + +registerMetadataTypeActions('datasource', [ + { + name: 'test_connection', + label: 'Test connection', + type: 'api', + target: '/api/v1/datasources/${ctx.recordId}/test', + } as any, +]); + +/** The answer as a client receives it: through JSON, so an `undefined` member is absent. */ +async function wireAnswer(): Promise { + return JSON.parse(JSON.stringify(await makeProtocol().getMetaTypes())); +} + +/** `type.key` for every member a served entry carries and the parsed entry lost. */ +function undeclaredMembers(wire: any, parsed: any): string[] { + const lost: string[] = []; + wire.entries.forEach((entry: any, i: number) => { + for (const key of Object.keys(entry)) { + if (!Object.prototype.hasOwnProperty.call(parsed.entries[i], key)) lost.push(`${entry.type}.${key}`); + } + }); + return lost; +} + +describe('GetMetaTypesResponseSchema declares what GET /meta/types serves (objectstack#36887)', () => { + it('a real answer parses, and no served member is stripped', async () => { + const wire = await wireAnswer(); + const result = GetMetaTypesResponseSchema.safeParse(wire); + expect(result.success, JSON.stringify(result.error?.issues?.slice(0, 3))).toBe(true); + expect(undeclaredMembers(wire, result.data)).toEqual([]); + }); + + it('the members the card names are on the wire, so the parse above read them', async () => { + const { entries } = await wireAnswer(); + const byType = new Map(entries.map((e: any) => [e.type, e])); + expect(byType.get('webhook'), 'the synthesised arm is served').toBeDefined(); + expect(entries.every((e: any) => e.schemaId === e.type)).toBe(true); + expect(entries.filter((e: any) => e.schema !== undefined).length).toBeGreaterThan(0); + expect(byType.get('hook').form.sections.length).toBeGreaterThan(0); + expect(byType.get('hook').list.columns.length).toBeGreaterThan(0); + expect(byType.get('datasource').actions.map((a: any) => a.name)).toContain('test_connection'); + }); + + it('control — a served member the schema does not declare is reported', async () => { + const wire = await wireAnswer(); + wire.entries[0].notDeclared = true; + const parsed = GetMetaTypesResponseSchema.parse(wire); + expect(undeclaredMembers(wire, parsed)).toEqual([`${wire.entries[0].type}.notDeclared`]); + }); + + it('control — a malformed form is refused, so `form` is typed, not `unknown`', async () => { + const wire = await wireAnswer(); + const hook = wire.entries.find((e: any) => e.type === 'hook'); + hook.form = { ...hook.form, sections: 'not a list' }; + expect(GetMetaTypesResponseSchema.safeParse(wire).success).toBe(false); + }); +}); diff --git a/packages/spec/api-surface/api.json b/packages/spec/api-surface/api.json index 9cd4209fd06..2fcf3aa790d 100644 --- a/packages/spec/api-surface/api.json +++ b/packages/spec/api-surface/api.json @@ -547,6 +547,7 @@ "GetMetaTypesRequest (type)", "GetMetaTypesRequestSchema (const)", "GetMetaTypesResponse (type)", + "GetMetaTypesResponseParsed (type)", "GetMetaTypesResponseSchema (const)", "GetNotificationPreferencesRequest (type)", "GetNotificationPreferencesRequestSchema (const)", diff --git a/packages/spec/dropped-refinements.baseline.json b/packages/spec/dropped-refinements.baseline.json index dfb4351621a..f6b4e2116f5 100644 --- a/packages/spec/dropped-refinements.baseline.json +++ b/packages/spec/dropped-refinements.baseline.json @@ -2,8 +2,8 @@ "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.", "measured": { "zod": "4.4.3", - "publishedSchemasWithDroppedRefinements": 274, - "droppedRefinementSites": 1171, + "publishedSchemasWithDroppedRefinements": 275, + "droppedRefinementSites": 1183, "refinementSitesThatDidProject": 728, "refinementSitesWithNoJsonFormToCompare": 0 }, @@ -387,6 +387,22 @@ "data.options[1].manifest.views.element.list.timeline.groupByField" ] }, + "api/GetMetaTypesResponse": { + "sites": [ + "entries.element.actions.element.in", + "entries.element.actions.element.in.ai.outputSchema", + "entries.element.actions.element.in.onSuccess", + "entries.element.actions.element.in.params.element.in", + "entries.element.actions.element.in.preflight.fields.element", + "entries.element.actions.element.in.refusals.valueType", + "entries.element.actions.element.in.resultDialog.fields.element", + "entries.element.actions.element.in.texts.valueType", + "entries.element.form", + "entries.element.form.sections.element", + "entries.element.form.subforms.element.columns.element", + "entries.element.form.submitBehavior.options[1].url" + ] + }, "api/GetObjectPermissionsResponse": { "sites": [ "fieldPermissions.valueType", diff --git a/packages/spec/export-origins/api.json b/packages/spec/export-origins/api.json index dc220eb046e..58ca252dd03 100644 --- a/packages/spec/export-origins/api.json +++ b/packages/spec/export-origins/api.json @@ -527,6 +527,7 @@ "GetMetaTypesRequest": "src/api/protocol.zod.ts#GetMetaTypesRequest (type)", "GetMetaTypesRequestSchema": "src/api/protocol.zod.ts#GetMetaTypesRequestSchema (const)", "GetMetaTypesResponse": "src/api/protocol.zod.ts#GetMetaTypesResponse (type)", + "GetMetaTypesResponseParsed": "src/api/protocol.zod.ts#GetMetaTypesResponseParsed (type)", "GetMetaTypesResponseSchema": "src/api/protocol.zod.ts#GetMetaTypesResponseSchema (const)", "GetNotificationPreferencesRequest": "src/api/protocol.zod.ts#GetNotificationPreferencesRequest (type)", "GetNotificationPreferencesRequestSchema": "src/api/protocol.zod.ts#GetNotificationPreferencesRequestSchema (const)", diff --git a/packages/spec/src/api/protocol.zod.ts b/packages/spec/src/api/protocol.zod.ts index 849d23d1217..9bc296e7e59 100644 --- a/packages/spec/src/api/protocol.zod.ts +++ b/packages/spec/src/api/protocol.zod.ts @@ -1,7 +1,8 @@ // Copyright (c) 2025 ObjectStack. Licensed under the Apache-2.0 license. import { z } from 'zod'; -import { MetadataListViewSchema, ViewSchema } from '../ui/view.zod'; +import { FormViewSchema, MetadataListViewSchema, ViewSchema } from '../ui/view.zod'; +import { ActionSchema } from '../ui/action.zod'; import { I18nLabelSchema } from '../ui/i18n.zod'; import { DiscoverySchema } from './discovery.zod'; import { @@ -211,6 +212,7 @@ export const GetMetaTypesResponseSchema = lazySchema(() => z.object({ types: z.array(z.string()).describe('Available metadata type names (e.g., "object", "plugin", "view")'), entries: z.array(z.object({ type: z.string().describe('Singular type identifier'), + schemaId: z.string().describe('Same value as `type`: the id the type\'s `schema`, `form` and `list` are bound to'), label: z.string().describe('Human-readable label'), description: z.string().optional().describe('Brief description'), 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({ domain: z.enum(['data', 'ui', 'automation', 'system', 'security', 'ai']).describe('Protocol domain'), overrideSource: z.enum(['registry', 'env']).describe('Whether allowEnvironmentOverlay comes from the static registry or is elevated by the OS_METADATA_WRITABLE environment variable'), 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.'), + 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.'), + 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.'), 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.'), + 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.'), })).optional().describe('Enriched per-type registry entries (Phase 3a)'), })); @@ -4912,6 +4917,8 @@ export type GetDiscoveryRequest = z.input; export type GetDiscoveryResponse = z.input; export type GetMetaTypesRequest = z.input; export type GetMetaTypesResponse = z.input; +/** Post-parse shape of {@link GetMetaTypesResponse} — defaults applied, transforms run (ADR-0122). */ +export type GetMetaTypesResponseParsed = z.infer; export type GetMetaItemsRequest = z.input; export type FlowRegistrationRefusal = z.input; export type FlowRegistration = z.input; diff --git a/packages/spec/src/type-alias-convention.pin.test.ts b/packages/spec/src/type-alias-convention.pin.test.ts index 3802b31db0f..03c9ad09537 100644 --- a/packages/spec/src/type-alias-convention.pin.test.ts +++ b/packages/spec/src/type-alias-convention.pin.test.ts @@ -306,7 +306,7 @@ import type * as M205 from './ai/object-query-source.zod.js'; import type * as M207 from './api/ai-answer.zod.js'; // --------------------------------------------------------------------------- -// 888 isomorphic aliases: `z.input` === `z.infer`, so no `XParsed` is declared. +// 887 isomorphic aliases: `z.input` === `z.infer`, so no `XParsed` is declared. // // That number is machine-checked, not hand-kept. The runtime companion at the // bottom of this file recomputes the pin count from the source and asserts that @@ -664,7 +664,6 @@ export type Iso_api_protocol__GetMetaItemResponseSchema = Assert, z.infer< typeof M28.GetMetaItemsRequestSchema > >>; export type Iso_api_protocol__GetMetaItemsResponseSchema = Assert, z.infer< typeof M28.GetMetaItemsResponseSchema > >>; export type Iso_api_protocol__GetMetaTypesRequestSchema = Assert, z.infer< typeof M28.GetMetaTypesRequestSchema > >>; -export type Iso_api_protocol__GetMetaTypesResponseSchema = Assert, z.infer< typeof M28.GetMetaTypesResponseSchema > >>; export type Iso_api_protocol__GetNotificationPreferencesRequestSchema = Assert, z.infer< typeof M28.GetNotificationPreferencesRequestSchema > >>; export type Iso_api_protocol__GetObjectPermissionsRequestSchema = Assert, z.infer< typeof M28.GetObjectPermissionsRequestSchema > >>; export type Iso_api_protocol__GetPresenceRequestSchema = Assert, z.infer< typeof M28.GetPresenceRequestSchema > >>; @@ -1867,7 +1866,7 @@ describe('ADR-0122 type-alias convention', () => { // this title and the section header above the pin list — are now asserted // against the recomputed count below, so neither can go stale without a red // test naming it. - it('still declares all 888 isomorphic pins', () => { + it('still declares all 887 isomorphic pins', () => { // The truth of each pin is proved by tsc, not here — an `Assert>` // that stops holding is a compile error with the alias named. What tsc // cannot notice is a pin that was DELETED: removing the assertion removes @@ -2987,7 +2986,12 @@ describe('ADR-0122 type-alias convention', () => { // Iso_data_object__ObjectExtensionListPlacementSchema). +2 added. Their // group sibling nests `ObjectFieldGroupSchema`, which has a parsed shape, // so it takes `ObjectExtensionGroupPlacementParsed` instead. - expect(pins).toHaveLength(888); + // 888 -> 887 is #36887: `GetMetaTypesResponseSchema` (`api/protocol.zod.ts`) + // now declares each entry's `form` (`FormViewSchema`) and `actions` + // (`ActionSchema`), both of which carry defaults, so the response gained a + // parsed shape and takes `GetMetaTypesResponseParsed` instead + // (Iso_api_protocol__GetMetaTypesResponseSchema removed). -1. + expect(pins).toHaveLength(887); // The count is stated in PROSE twice as well — this case's title and the // section header above the pin list — and until commit c6b05c76a nothing read either diff --git a/scripts/engine-double-contract.pinned.json b/scripts/engine-double-contract.pinned.json index 27475b530e1..f84aa8842ea 100644 --- a/scripts/engine-double-contract.pinned.json +++ b/scripts/engine-double-contract.pinned.json @@ -1426,6 +1426,21 @@ "verb": "update", "pinned": 1 }, + { + "file": "packages/metadata-protocol/src/protocol.meta-types-response-schema-36887.test.ts", + "verb": "delete", + "pinned": 1 + }, + { + "file": "packages/metadata-protocol/src/protocol.meta-types-response-schema-36887.test.ts", + "verb": "findOne", + "pinned": 1 + }, + { + "file": "packages/metadata-protocol/src/protocol.meta-types-response-schema-36887.test.ts", + "verb": "update", + "pinned": 1 + }, { "file": "packages/metadata-protocol/src/protocol.meta-types-unauthorable-columns.test.ts", "verb": "delete",