Skip to content

Commit 880d343

Browse files
os-zhuangclaude
andauthored
fix(spec): 参考文档生成器按 typeof 决定字面量是否加引号,数值字面量不再被记成字符串 (#5729) (#6127)
* fix(spec): 参考文档生成器按 typeof 决定字面量是否加引号 (#5729) `formatType()` 的两个字面量分支无条件给每个值套上 `'…'`,数值字面量因此 被写成字符串字面量。`FormSection.columns` 声明为 `z.union([z.enum(['1','2','3','4']), z.literal(1) … z.literal(4)])`, `ui/view.mdx` 却渲染成 `Enum<'1' | '2' | '3' | '4'> | '1' | '2' | '3' | '4'` —— 后半段那四个数值字面量与前半段的字符串完全无法区分,页面因此宣称这个键 只收字符串,而 schema 同时接受 `2` 和 `'2'`。 参考页是 AI 作者的权威输入(ADR-0033),字面量联合又是「照抄拼写」的表面: 页面上的引号会被原样抄进 metadata。#5611 已经付过代价——它的 `RecordDetailsProps.sections[].columns` 本打算写成数值字面量联合,照生成的 参考写是硬解析错误,PR 里被迫退回 `z.number().int().min(1).max(4)`。生成器 在反向定义契约。 引号改为按**值**判断而非按节点判断:JSON Schema 逐值声明成员类型,`enum` 可以混装(`z.nativeEnum({A: 1})` 就产出数值 `enum`)。字符串保留引号, `number`/`boolean` 裸渲染,`null` 渲染为关键字。 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_014wsZeReNTqiceBfLb5Pyf5 * chore(docs): 重新生成参考文档 —— 非字符串字面量去掉引号 (#5729) `pnpm --filter @objectstack/spec gen:schema && gen:docs` 的产物,无手工编辑。 8 个页面 / 11 行,方向单一:18 处非字符串字面量去掉引号,没有任何字符串 字面量失去引号(逐行机检,详见 PR 正文)。 - api/dispatcher, api/errors —— `success: 'false'` → `false` - data/data-engine —— `sort: Record<string, '1' | '-1'>` → `Record<string, 1 | -1>` - data/driver-nosql —— `projection: Record<string, '0' | '1'>` → `Record<string, 0 | 1>` - data/object —— `systemFields` / `stageField` 的 `'false'` → `false` - security/explain —— `version: '1'` → `1` - ui/dashboard —— `filterBindings` 的 `'false'` → `false` - ui/view —— `columns: … | '1' | '2' | '3' | '4'` → `… | 1 | 2 | 3 | 4` 页面上所有 `Enum<'a' | 'b'>` 形态的字符串枚举一律未变。 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_014wsZeReNTqiceBfLb5Pyf5 --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent 877545c commit 880d343

11 files changed

Lines changed: 237 additions & 13 deletions

File tree

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
---
2+
"@objectstack/spec": patch
3+
---
4+
5+
fix(spec): the reference generator quotes a literal by its `typeof`, so numeric literals stop being written down as strings (#5729)
6+
7+
`formatType()`'s two literal branches wrapped every value in `'…'` without
8+
looking at its type — `prop.enum.map(e => `'${e}'`)` and
9+
`return `'${prop.const}'`` — so a **numeric** literal union was printed as a
10+
**string** one. `FormSection.columns` is the specimen the issue was filed from:
11+
it is declared
12+
13+
```ts
14+
z.union([z.enum(['1', '2', '3', '4']), z.literal(1), z.literal(2), z.literal(3), z.literal(4)])
15+
```
16+
17+
and `content/docs/references/ui/view.mdx` rendered it as
18+
`Enum<'1' | '2' | '3' | '4'> | '1' | '2' | '3' | '4'`, where the second half is
19+
those four `z.literal(<number>)` variants. The two halves came out
20+
indistinguishable, so the page claimed the key takes strings only — while the
21+
schema accepts both `2` and `'2'`.
22+
23+
For these pages that is a contract error, not a typo. They are the authoritative
24+
input for an AI author (ADR-0033), and a literal union is a copy-the-spelling
25+
surface: whatever quoting the page shows is what gets written. #5611 paid for it
26+
directly — its `RecordDetailsProps.sections[].columns` was meant to be a numeric
27+
literal union, the generated reference said strings, and the PR abandoned the
28+
shape for `z.number().int().min(1).max(4)` to escape the contradiction. The
29+
generator was defining the contract backwards.
30+
31+
Quoting is now decided per **value**, not per node, because JSON Schema states
32+
member types per value and an `enum` may mix them (`z.nativeEnum({ A: 1 })`
33+
emits a numeric `enum`): strings stay quoted, `number`/`boolean` render bare,
34+
and `null` renders as the keyword.
35+
36+
Eight reference pages change, 11 lines, and in one direction only — quotes are
37+
removed from 18 non-string literals and no string literal loses its:
38+
`api/dispatcher`, `api/errors` (`success: false`), `data/data-engine`
39+
(`sort: Record< string, 1 | -1 >`), `data/driver-nosql` (`projection:
40+
Record< string, 0 | 1 >`), `data/object` (`systemFields` / `stageField: false`),
41+
`security/explain` (`version: 1`), `ui/dashboard` (`filterBindings`) and
42+
`ui/view` (`columns: … | 1 | 2 | 3 | 4`). Every `Enum<'a' | 'b'>` on those
43+
pages is untouched.

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ Route-resolution failure mode emitted in `error.code`
7878

7979
| Property | Type | Required | Description |
8080
| :--- | :--- | :--- | :--- |
81-
| **success** | `'false'` | ✅ | |
81+
| **success** | `false` | ✅ | |
8282
| **error** | `{ code: string; message: string; httpStatus?: integer; route?: string; … }` | ✅ | |
8383

8484

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ const result = EnhancedApiErrorSchema.parse(data);
8787

8888
| Property | Type | Required | Description |
8989
| :--- | :--- | :--- | :--- |
90-
| **success** | `'false'` | ✅ | Always false for error responses |
90+
| **success** | `false` | ✅ | Always false for error responses |
9191
| **error** | `{ code: Enum<'VALIDATION_ERROR' \| 'INVALID_FIELD' \| 'MISSING_REQUIRED_FIELD' \| 'INVALID_FORMAT' \| 'VALUE_TOO_LONG' \| 'VALUE_TOO_SHORT' \| 'VALUE_OUT_OF_RANGE' \| 'INVALID_REFERENCE' \| 'DUPLICATE_VALUE' \| 'INVALID_QUERY' \| 'INVALID_FILTER' \| 'INVALID_SORT' \| 'MAX_RECORDS_EXCEEDED' \| 'UNAUTHENTICATED' \| 'INVALID_CREDENTIALS' \| 'EXPIRED_TOKEN' \| 'INVALID_TOKEN' \| 'SESSION_EXPIRED' \| 'MFA_REQUIRED' \| 'EMAIL_NOT_VERIFIED' \| 'PERMISSION_DENIED' \| 'INSUFFICIENT_PRIVILEGES' \| 'FIELD_NOT_ACCESSIBLE' \| 'RECORD_NOT_ACCESSIBLE' \| 'LICENSE_REQUIRED' \| 'IP_RESTRICTED' \| 'TIME_RESTRICTED' \| 'RESOURCE_NOT_FOUND' \| 'OBJECT_NOT_FOUND' \| 'RECORD_NOT_FOUND' \| 'FIELD_NOT_FOUND' \| 'ENDPOINT_NOT_FOUND' \| 'RESOURCE_CONFLICT' \| 'CONCURRENT_MODIFICATION' \| 'DELETE_RESTRICTED' \| 'DUPLICATE_RECORD' \| 'LOCK_CONFLICT' \| 'METHOD_NOT_ALLOWED' \| 'PRECONDITION_REQUIRED' \| 'RATE_LIMIT_EXCEEDED' \| 'QUOTA_EXCEEDED' \| 'CONCURRENT_LIMIT_EXCEEDED' \| 'INTERNAL_ERROR' \| 'DATABASE_ERROR' \| 'TIMEOUT' \| 'SERVICE_UNAVAILABLE' \| 'NOT_IMPLEMENTED' \| 'EXTERNAL_SERVICE_ERROR' \| 'INTEGRATION_ERROR' \| 'WEBHOOK_DELIVERY_FAILED' \| 'BATCH_PARTIAL_FAILURE' \| 'BATCH_COMPLETE_FAILURE' \| 'TRANSACTION_FAILED'>; message: string; category?: Enum<'validation' \| 'authentication' \| 'authorization' \| 'not_found' \| 'conflict' \| 'rate_limit' \| 'server' \| 'external' \| 'maintenance'>; httpStatus?: number; … }` | ✅ | Error details |
9292
| **meta** | `{ timestamp?: string; requestId?: string; traceId?: string }` | optional | Response metadata |
9393

‎content/docs/references/data/data-engine.mdx‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ Query options for IDataEngine.find() operations
230230
| **context** | `{ userId?: string; actor?: string; attributedUserId?: string; email?: string; … }` | optional | |
231231
| **filter** | `Record<string, any> \| any` | optional | Data Engine query filter conditions |
232232
| **select** | `string[]` | optional | |
233-
| **sort** | `Record<string, Enum<'asc' \| 'desc'>> \| Record<string, '1' \| '-1'> \| { field: string; order: Enum<'asc' \| 'desc'> }[]` | optional | Sort order definition |
233+
| **sort** | `Record<string, Enum<'asc' \| 'desc'>> \| Record<string, 1 \| -1> \| { field: string; order: Enum<'asc' \| 'desc'> }[]` | optional | Sort order definition |
234234
| **limit** | `integer` | optional | |
235235
| **skip** | `integer` | optional | |
236236
| **top** | `integer` | optional | |
@@ -382,7 +382,7 @@ Type: `Record<string, Enum<'asc' | 'desc'>>`
382382

383383
#### Option 2
384384

385-
Type: `Record<string, '1' | '-1'>`
385+
Type: `Record<string, 1 | -1>`
386386

387387
---
388388

‎content/docs/references/data/driver-nosql.mdx‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ const result = AggregationPipelineSchema.parse(data);
3333
| :--- | :--- | :--- | :--- |
3434
| **collection** | `string` | ✅ | Collection/table name |
3535
| **stages** | `{ operator: string; options: Record<string, any> }[]` | ✅ | Aggregation pipeline stages |
36-
| **options** | `{ consistency?: Enum<'all' \| 'quorum' \| 'one' \| 'local_quorum' \| 'each_quorum' \| 'eventual'>; readFromSecondary?: boolean; projection?: Record<string, '0' \| '1'>; timeout?: integer; … }` | optional | Query options |
36+
| **options** | `{ consistency?: Enum<'all' \| 'quorum' \| 'one' \| 'local_quorum' \| 'each_quorum' \| 'eventual'>; readFromSecondary?: boolean; projection?: Record<string, 0 \| 1>; timeout?: integer; … }` | optional | Query options |
3737

3838

3939
---
@@ -203,7 +203,7 @@ const result = AggregationPipelineSchema.parse(data);
203203
| :--- | :--- | :--- | :--- |
204204
| **consistency** | `Enum<'all' \| 'quorum' \| 'one' \| 'local_quorum' \| 'each_quorum' \| 'eventual'>` | optional | Consistency level override |
205205
| **readFromSecondary** | `boolean` | optional | Allow reading from secondary replicas |
206-
| **projection** | `Record<string, '0' \| '1'>` | optional | Field projection |
206+
| **projection** | `Record<string, 0 \| 1>` | optional | Field projection |
207207
| **timeout** | `integer` | optional | Query timeout (ms) |
208208
| **useCursor** | `boolean` | optional | Use cursor instead of loading all results |
209209
| **batchSize** | `integer` | optional | Cursor batch size |

‎content/docs/references/data/object.mdx‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ const result = ApiMethod.parse(data);
118118
| **managedBy** | `Enum<'platform' \| 'config' \| 'system-data' \| 'engine-owned' \| 'append-only' \| 'better-auth'>` | optional | Lifecycle bucket — platform (user CRUD) \| config (admin authored) \| system-data (platform-defined schema, admin/user-writable data) \| engine-owned (engine owns the lifecycle, no user writes) \| append-only (audit) \| better-auth (identity). UI clients honour the resolved affordance matrix. |
119119
| **ownership** | `Enum<'user' \| 'org' \| 'none'>` | optional | Record-ownership model: user (default — injects reassignable owner_id) \| org \| none (no per-record owner, skips owner_id). Distinct from the package own/extend contribution kind. |
120120
| **userActions** | `{ create?: boolean; import?: boolean; edit?: boolean \| { enabled?: boolean; visibleWhen?: string \| { dialect: Enum<'cel' \| 'cron' \| 'template'>; source?: string; ast?: any; meta?: object }; disabledWhen?: string \| { dialect: Enum<'cel' \| 'cron' \| 'template'>; source?: string; ast?: any; meta?: object } }; delete?: boolean \| { enabled?: boolean; visibleWhen?: string \| { dialect: Enum<'cel' \| 'cron' \| 'template'>; source?: string; ast?: any; meta?: object }; disabledWhen?: string \| { dialect: Enum<'cel' \| 'cron' \| 'template'>; source?: string; ast?: any; meta?: object } }; … }` | optional | Per-object override of the resolved CRUD affordance matrix. |
121-
| **systemFields** | `'false' \| { tenant?: boolean; audit?: boolean }` | optional | Opt out of, or selectively disable, registry-level system-field auto-injection. |
121+
| **systemFields** | `false \| { tenant?: boolean; audit?: boolean }` | optional | Opt out of, or selectively disable, registry-level system-field auto-injection. |
122122
| **datasource** | `string` | optional | Target Datasource ID. "default" is the primary DB. |
123123
| **external** | `{ remoteName?: string; remoteSchema?: string; writable?: boolean; columnMap?: Record<string, string>; … }` | optional | Remote table binding for federated (external) objects. |
124124
| **fields** | `Record<string, { name?: string; label?: string; type: Enum<'text' \| 'textarea' \| 'email' \| 'url' \| 'phone' \| 'password' \| 'secret' \| 'markdown' \| 'html' \| 'richtext' \| 'number' \| 'currency' \| 'percent' \| 'date' \| 'datetime' \| 'time' \| 'boolean' \| 'toggle' \| 'select' \| 'multiselect' \| 'radio' \| 'checkboxes' \| 'lookup' \| 'master_detail' \| 'tree' \| 'user' \| 'image' \| 'file' \| 'avatar' \| 'video' \| 'audio' \| 'formula' \| 'summary' \| 'autonumber' \| 'composite' \| 'repeater' \| 'record' \| 'location' \| 'address' \| 'code' \| 'json' \| 'color' \| 'rating' \| 'slider' \| 'signature' \| 'qrcode' \| 'progress' \| 'tags' \| 'vector'>; description?: string; … }>` | ✅ | Field definitions map. Keys must be snake_case identifiers. |
@@ -135,7 +135,7 @@ const result = ApiMethod.parse(data);
135135
| **displayNameField** | `string` | optional | [DEPRECATED → nameField] Field to use as the record display name (e.g., "name", "title"). Accepted as an alias for nameField. |
136136
| **titleFormat** | `string \| { dialect: Enum<'cel' \| 'cron' \| 'template'>; source?: string; ast?: any; meta?: object }` | optional | [DEPRECATED → nameField (ADR-0079)] Render-only title template; the server cannot return or query it, and an explicit nameField now takes precedence. Migrate a single-field title to nameField, a composite to a formula field designated as nameField. |
137137
| **highlightFields** | `string[]` | optional | [ADR-0085] Ordered most-important fields; first entry wins where only one fits. Drives default columns, cards, previews, detail highlight strip. Renamed from compactLayout. |
138-
| **stageField** | `string \| 'false'` | optional | [ADR-0085] Lifecycle stage field (linear/ordered), or false to declare the status field non-linear and suppress stage heuristics. Absent = heuristic detection allowed. |
138+
| **stageField** | `string \| false` | optional | [ADR-0085] Lifecycle stage field (linear/ordered), or false to declare the status field non-linear and suppress stage heuristics. Absent = heuristic detection allowed. |
139139
| **listViews** | `Record<string, { name?: string; label?: string; type?: Enum<'grid' \| 'kanban' \| 'gallery' \| 'calendar' \| 'timeline' \| 'gantt' \| 'map' \| 'chart' \| 'tree'>; data?: { provider: 'object'; object: string } \| { provider: 'api'; read?: object; write?: object } \| { provider: 'value'; items: any[] } \| { provider: 'schema'; schemaId: string; schema?: Record<string, any> }; … }>` | optional | Built-in named list views (segmented tabs) shipped with the object schema — "views" mode, dropdown userFilters allowed, no page-only tabs (ADR-0047) |
140140
| **searchableFields** | `string[]` | optional | Fields the `$search` query matches against (ADR-0061). Canonical default for the record picker, list quick-search and global search; views may narrow it. When unset, search auto-defaults to the name/title field plus short-text fields. |
141141
| **enable** | `{ trackHistory?: boolean; searchable?: boolean; apiEnabled?: boolean; apiMethods?: Enum<'get' \| 'list' \| 'create' \| 'update' \| 'delete' \| 'bulk'>[]; … }` | optional | Enabled system features modules |

‎content/docs/references/security/explain.mdx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ const result = AccessMatrixSchema.parse(data);
7171

7272
| Property | Type | Required | Description |
7373
| :--- | :--- | :--- | :--- |
74-
| **version** | `'1'` | ✅ | |
74+
| **version** | `1` | ✅ | |
7575
| **entries** | `{ permissionSet: string; object: string; create: boolean; read: boolean; … }[]` | ✅ | |
7676

7777

‎content/docs/references/ui/dashboard.mdx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ Dashboard header action
108108
| **values** | `string[]` | ✅ | Measure names — Y (at least one) |
109109
| **layout** | `{ x: number; y: number; w: number; h: number }` | optional | Grid layout position (auto-flowed when omitted) |
110110
| **options** | `{ dateGranularity?: Enum<'day' \| 'week' \| 'month' \| 'quarter' \| 'year'>; sortBy?: string; sortOrder?: Enum<'asc' \| 'desc'>; limit?: integer; … } & Record<string, any>` | optional | Widget specific configuration |
111-
| **filterBindings** | `Record<string, string \| 'false'>` | optional | Per-widget dashboard-filter bindings: filter name → this widget's field, or false to opt out |
111+
| **filterBindings** | `Record<string, string \| false>` | optional | Per-widget dashboard-filter bindings: filter name → this widget's field, or false to opt out |
112112
| **suppressWarnings** | `string[]` | optional | Build diagnostic rule ids suppressed on this widget |
113113
| **responsive** | `never` | optional | [REMOVED] `dashboard.widgets[].responsive` was removed in @objectstack/spec 17.0.0 (#4876, ADR-0049 D2) — no renderer ever read it, so per-widget breakpoint overrides were never applied: the value parsed, validated, and then did nothing. The dashboard grid reflows by its own layout rules (`columns` + `gap` on the dashboard, the `layout` box on each widget). Delete the key. The shared `ResponsiveConfig` shape is NOT gone — it stays live on `page.components[].responsive`, which objectui `useResponsiveConfig` really does read; move the layout there if you need breakpoint behaviour today. Run `os migrate meta --from 16` to rewrite it automatically. |
114114
| **aria** | `never` | optional | [REMOVED] `dashboard.widgets[].aria` was removed in @objectstack/spec 17.0.0 (#5010, ADR-0049 D2) — no renderer ever applied it, so ARIA attributes declared on a widget silently did not reach the DOM: the key promised accessibility compliance it did not deliver. This is the same removal the dashboard-level `aria` got in 17.0.0 (#3896). Delete the key. The dashboard renderer emits its own `aria-*` attributes for the widget grid; author a `title` (and `description`) on the widget instead — those ARE what the renderer labels the card with. The shared `AriaProps` shape is NOT gone: it stays live on `app.aria` and `page.components[].aria`. Run `os migrate meta --from 16` to rewrite it automatically. |

‎content/docs/references/ui/view.mdx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ Column footer summary configuration
181181
| **collapsed** | `boolean` | optional | |
182182
| **visibleWhen** | `string \| { dialect: Enum<'cel' \| 'cron' \| 'template'>; source?: string; ast?: any; meta?: object }` | optional | Visibility predicate (CEL) — section shown only when TRUE. Root: `record`+`current_user` (runtime forms) or `data` (metadata forms). |
183183
| **visibleOn** | `string \| { dialect: Enum<'cel' \| 'cron' \| 'template'>; source?: string; ast?: any; meta?: object }` | optional | [DEPRECATED → `visibleWhen`] Visibility predicate (CEL). Hides the whole section when false. Normalized to `visibleWhen` at parse. |
184-
| **columns** | `Enum<'1' \| '2' \| '3' \| '4'> \| '1' \| '2' \| '3' \| '4'` | optional | |
184+
| **columns** | `Enum<'1' \| '2' \| '3' \| '4'> \| 1 \| 2 \| 3 \| 4` | optional | |
185185
| **pane** | `Enum<'primary' \| 'secondary'>` | optional | Split pane this section renders in (split forms only; a parse error elsewhere). Omitted → first section 'primary', others 'secondary'. |
186186
| **fields** | `(string \| { field: string; type?: Enum<'text' \| 'textarea' \| 'email' \| 'url' \| 'phone' \| 'password' \| 'secret' \| 'markdown' \| 'html' \| 'richtext' \| 'number' \| 'currency' \| 'percent' \| 'date' \| 'datetime' \| 'time' \| 'boolean' \| 'toggle' \| 'select' \| 'multiselect' \| 'radio' \| 'checkboxes' \| 'lookup' \| 'master_detail' \| 'tree' \| 'user' \| 'image' \| 'file' \| 'avatar' \| 'video' \| 'audio' \| 'formula' \| 'summary' \| 'autonumber' \| 'composite' \| 'repeater' \| 'record' \| 'location' \| 'address' \| 'code' \| 'json' \| 'color' \| 'rating' \| 'slider' \| 'signature' \| 'qrcode' \| 'progress' \| 'tags' \| 'vector'>; options?: { label: string; value: string; color?: string; default?: boolean; … }[]; reference?: string; … })[]` | ✅ | |
187187

0 commit comments

Comments
 (0)