Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .changeset/36887-meta-types-response-schema.md
Original file line number Diff line number Diff line change
@@ -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`.
6 changes: 5 additions & 1 deletion content/docs/references/api/protocol.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
Expand All @@ -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<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. |
| **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<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. |


---
Expand Down
Original file line number Diff line number Diff line change
@@ -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<string, unknown>, opts?: Record<string, unknown>) {
assertEngineUpdateDispatch(data, opts);
return { id: null };
},
async delete(_t: string, opts?: Record<string, unknown>) {
assertEngineDeleteDispatch(opts);
return { deleted: 1 };
},
async count() { return 0; },
async transaction(fn: (ctx: unknown) => Promise<unknown>) { 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<any> {
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<string, any>(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);
});
});
1 change: 1 addition & 0 deletions packages/spec/api-surface/api.json
Original file line number Diff line number Diff line change
Expand Up @@ -547,6 +547,7 @@
"GetMetaTypesRequest (type)",
"GetMetaTypesRequestSchema (const)",
"GetMetaTypesResponse (type)",
"GetMetaTypesResponseParsed (type)",
"GetMetaTypesResponseSchema (const)",
"GetNotificationPreferencesRequest (type)",
"GetNotificationPreferencesRequestSchema (const)",
Expand Down
20 changes: 18 additions & 2 deletions packages/spec/dropped-refinements.baseline.json
Original file line number Diff line number Diff line change
Expand Up @@ -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
},
Expand Down Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions packages/spec/export-origins/api.json
Original file line number Diff line number Diff line change
Expand Up @@ -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)",
Expand Down
9 changes: 8 additions & 1 deletion packages/spec/src/api/protocol.zod.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down Expand Up @@ -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'),
Expand All @@ -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)'),
}));

Expand Down Expand Up @@ -4912,6 +4917,8 @@ export type GetDiscoveryRequest = z.input<typeof GetDiscoveryRequestSchema>;
export type GetDiscoveryResponse = z.input<typeof GetDiscoveryResponseSchema>;
export type GetMetaTypesRequest = z.input<typeof GetMetaTypesRequestSchema>;
export type GetMetaTypesResponse = z.input<typeof GetMetaTypesResponseSchema>;
/** Post-parse shape of {@link GetMetaTypesResponse} — defaults applied, transforms run (ADR-0122). */
export type GetMetaTypesResponseParsed = z.infer<typeof GetMetaTypesResponseSchema>;
export type GetMetaItemsRequest = z.input<typeof GetMetaItemsRequestSchema>;
export type FlowRegistrationRefusal = z.input<typeof FlowRegistrationRefusalSchema>;
export type FlowRegistration = z.input<typeof FlowRegistrationSchema>;
Expand Down
Loading
Loading