Skip to content
This repository was archived by the owner on Nov 4, 2026. It is now read-only.

Commit 18d7b48

Browse files
feat(types): form fields declare scale and currencyConfig by spec reference; M3 class (ii) reads 0 (objectui#11070 round 13) (#11972)
Part of #11070 (round 13) Clause-②: yes — widens: the strict authoring face (`StrictAnyComponentSchema`) now accepts `form` `fields[].scale` and `fields[].currencyConfig`, which it refused with `unrecognized_keys`; narrows: the tolerant face (`safeValidateSchema`), which stripped both keys unjudged, now refuses a value the spec's `FieldSchema` refuses for either key, and refuses `scale` on a `currency` entry (`custom` at `scale`, the spec's own refusal) on both faces. Round 13 of objectui#11070, claim `6060489789`, session `https://claude.ai/code/session_01DBZ9bntPZ7VKyQNtJeNsgw`. This round executes the seat's answers A, B and C (ACCEPT `6060086777`) for the three class (ii) pairs round 12's M3 re-run left. **On this head, M3 class (ii) reads 0 corpus pairs, so the card's executable acceptance holds.** The 32 pairs that remain are the class (i) pairs round 12 already listed, unchanged. ## M3 re-run: base `a835c314`, head `5f049697` The instrument is round 12's, rebuilt as a scratch script and not committed. It copies `scripts/measure-strict-authoring-face.mjs` unchanged up to its first corpus run (`const catalog = loadCatalog();`), except that `REPO_ROOT` comes from the environment. On top of that it adds the JSON half of M2's population: every tracked `.json` outside the three corpora, 195 files, holding 1 node document. The YAML half holds none: 45 tracked YAML files, 0 with a root `type:`, against 41 with a root `name:` as the lit control. Each node document is judged by `StrictAnyComponentSchema` and `AnyComponentSchema` from the built `packages/types/dist/zod`. Refused keys are read with PR objectui#11069's own `findUndeclaredKeys`, copied from its head `a11f73347d` with the types stripped. Each key is attributed to its nearest node by the measure script's schema-guided walk, with node paths kept. zod 4.6.5; `@object-ui/types` built at each end. **The base reproduces round 12's head reading exactly**: 623 node documents, 58 refused, 35 pairs, 54 occurrences, 40 strict-only. | corpus | node documents | refused, base → head | strict-only, base → head | red today, base → head | refused naming no key | | --- | --: | --: | --: | --: | --: | | catalog | 432 | 28 → 23 | 16 → 11 | 12 → 12 | 12 | | docs | 184 | 27 → 26 | 13 → 13 | 14 → 13 | 8 | | authored | 6 | 2 → 2 | 1 → 1 | 1 → 1 | 0 | | M2 JSON (`examples/hello-world/schema.json`) | 1 | 1 → 1 | 1 → 1 | 0 → 0 | 0 | | **total** | **623** | **58 → 52** | **31 → 26** | **27 → 26** | **20** | | class | pairs, base → head | occurrences | strict-only | | --- | --: | --: | --: | | (i) undeclared, no read site found | 32 → 32 | 48 → 48 | 35 → 35 | | (ii) a renderer reads it, no schema declares it | **3 → 0** | 6 → 0 | 5 → 0 | | (iii) the TS type names it, the zod mirror omits it | 0 → 0 | 0 | 0 | - The three pairs that left are `form` · `fields[].scale` (3), `form` · `fields[].currency` (2) and `action:button` · `properties.endpoint` (1, red on both faces). - The six documents left the refused set: five catalog documents and the guide's fence. The fence was red on both faces, which is why "red today" drops by one. - No pair appeared. - The 32 remaining pairs are round 12's class (i) list, name for name: `button` · `action` / `content` / `fullWidth`, `card` · five keys, `form` · `submitButton` / `title` / four `fields[]` keys, and so on. - Class (iii) stays 0. The `UnmirroredDeclared` ledger in `zod-mirror-parity.test.ts` names none of the 32. ## A. `fields[].scale`, declared by reference, with the spec's one cross-key rule `FormField.scale` is `SpecField['scale']`, and `FormFieldSchema.scale` is `stripImportedDefaults(SpecFieldSchema).shape.scale`. The readers are the `number` widget (`numberField?.scale`), the `percent` widget (through `resolveFieldScale`), and the `formula` and `summary` widgets (through `formatNumberFieldValue`). **H2, the cross-key rule, decided by measurement: the face carries it.** - `@object-ui/types`' `@objectstack/spec` is 17.7.0. Its `FieldSchema` refuses `scale` on `currency` (code `custom`, at `scale`), for `scale: 2` and `scale: 0` alike. It accepts `scale` on `number`, `percent` and even `text`. `currency` is the one type it excludes. - The `currency` widget does not read `scale`. Measured through the real `SchemaRenderer` on a fixed-USD entry: with `scale` absent, `0` and `4`, the read-only face draws `$1,234.50` and the edit face's step is `0.01` each time. Lit control, a `number` entry with the same three: `1,234.5` / `1235` / `1,234.5000`, step `any` / `1` / `0.0001`. - At base, the shipped strict face refused a currency entry carrying `scale` (as an undeclared key). A bare `.shape.scale` declaration would therefore have newly accepted exactly the document the spec refuses and nothing reads. - So the superRefine carries that one rule: `type === 'currency' && scale !== undefined` gives `custom` at `scale`. It is keyed as the spec keys it, and its text is the spec's own (`CURRENCY_FIELD_SCALE_REFUSAL`). The spec exports neither the rule nor its text, so the pin asserts both: the spec still refuses that entry, and objectui's message equals the spec's issue message. A spec release that drops or rewords the rule reds the pin. ⛔ No new local rule: nothing is refused that the spec admits. - **Width, stated.** The spec's other cross-key rules on members this face already takes by reference are not carried, as before. These are `rows` (multiline types), `minLength` / `maxLength` (bounded string types) and `multiple`. They key on the spec's field-type sets, and this face's `type` is a widget id: the spec's `FieldSchema` refuses `type: 'input'` itself (`invalid_value` at `type`), while the built-in input branch honours `minLength` on it. The spec's own inline form field (the `object-form` row) also takes `rows`, `minLength` and `maxLength` off `FieldSchema.shape` flat, without the rules. The currency rule keys on `type` only, so an entry drawn as currency through `widget` alone is not judged by it. ## B. `fields[].currency` is runtime-only; the two documents move to `currencyConfig` `fields-currency/euro-currency.json` and `usd-currency.json` now write `currencyConfig: { currencyMode: 'fixed', defaultCurrency: 'EUR' | 'USD' }` instead of `currency`. `currency` stays undeclared, and the strict face still refuses it by name (pinned). **One premise was falsified on the way, and the route was completed by the round's own pattern.** The ACCEPT's B sends the documents to `currencyConfig`, "which the spec declares". The spec declares it, but **objectui's form-field face did not**. Base probe on the built dist: the strict face refused `fields.0.currencyConfig` with `unrecognized_keys`, and the tolerant face stripped it. Moving the documents alone would have traded `form` · `fields[].currency` for `form` · `fields[].currencyConfig`, which is still class (ii) because `resolveFieldCurrency` reads it. So `currencyConfig` is declared on both faces by reference too: `SpecField['currencyConfig']` and `stripImportedDefaults(SpecFieldSchema).shape.currencyConfig`. That needs no spec change. It also means B widens the strict face, which the claim's last line did not expect ("B and C correct documents and widen nothing"); the Clause-② line above states it. The imported-defaults boundary keeps the spec config's defaults (`dynamic`, `CNY`) out of a parsed document (pinned: `currencyConfig: {}` stays `{}`). **H3 held**, through the real `SchemaRenderer`, form renderer and `@object-ui/fields` registration: | document | before (`currency`) | after (`currencyConfig`, fixed) | markup | | --- | --- | --- | --- | | `euro-currency` | `€`, step `0.01` | `€`, step `0.01` | identical apart from React `useId` values (1080 = 1080 bytes) | | `usd-currency` | `$`, step `0.01` | `$`, step `0.01` | identical apart from React `useId` values (1066 = 1066 bytes) | | lit control: the same entry with neither key | — | no symbol, no `pl-8` padding | differs | The permanent pin (`examples/schema-catalog/test/fields-scale-currency-config-11070.test.tsx`) holds the after column. It has two controls: `dynamic` mode draws no symbol, and `JPY` draws `¥` with step `1`. It does not pin the before column, because limb 1's future is a separate question. ## C. The guide's `action:button` example names its endpoint `target` In `content/docs/guide/schema-rendering.md`, the "Reference actions in schemas" fence now writes `"target": "/api/action"` instead of `endpoint`. The sentence below it now reads that an `api` action's endpoint is its `target`, with the verb in `method`, and that the spec's `action:button` row refuses `endpoint` and names `target` in its place. Its half on `api` is unchanged and still true: no action renderer forwards `api`. The core runner's `executeAPI` resolves `api || endpoint || target`, so `target` alone reaches it. The taught shape is pinned on both faces, and `endpoint` in the bag stays refused on both. ## Hypotheses - **H1 held.** - `scale` sits in the three catalog documents. - The fourth hit, `plugin-timeline/gantt-style-timeline.json`, is a `timeline` node's own top-level `scale: "month"` (the Gantt axis bucket, which the timeline schema declares). It is a different key in a different block, and M3 refuses nothing there. - `currency` sits in the two currency documents. - The `endpoint` sits in the "Reference actions in schemas" fence and in the sentence "the endpoint key is `endpoint`". - **H2:** decided by measurement as above. The face carries the spec's one currency rule with the spec's text, and the width is stated in the changeset. - **H3 held** as above. Its unstated half fell: that the objectui face accepted `currencyConfig`. ## Tests, reverse verification, ablations Heavy runs went through the verify lock with `NODE_OPTIONS=--max-old-space-size=4096` and `--maxWorkers=2`. The subjects resolve from source through the root vitest alias, so no leg needs a `dist` rebuild. M3 reads the dist, which was built at each end. - **Pins.** `strict-face-read-keys-11070.test.ts` gains the round-13 rows: - `scale` and `currencyConfig` parse on the strict face, and a misspelled sibling is refused by name; - both keep their values on the tolerant face, with no default written in; - seven value rows are refused on both faces (a non-integer, negative, over-100 or string `scale`; an unknown `currencyMode`; a 4-letter `defaultCurrency`; the removed `currencyConfig.precision`); - `scale` on a currency entry is refused at `scale` with the spec's text, with two controls; - `fields[].currency` stays refused by name; - the guide's `action:button` shape parses, and `endpoint` stays refused; - type level: both members are the spec's exactly, and not `any`. `form-field-zod-coverage.test.ts` adds the two keys to its declared set. The new catalog test is described under B. - **Predictions were written before any leg** (head `5f049697`). Every leg ran on committed code. Each restore was proven by blob equal to HEAD and an empty `git diff HEAD`. - **R0**, `form.ts` and `form.zod.ts` at base under this head's pins. Predicted 17 red (pin 11, coverage 1, catalog 5) and 3 `tsc` errors, all in the pin. Observed `Tests 17 failed | 135 passed (152)` and 3 `error TS2344`, all in the pin. - **A1**, the zod `scale` member deleted through objectstack's `scripts/ablation-replace.mjs` (anchor 1 → 0, blob `8056f03b` → `c397dd27`). Predicted 11 red and at least 2 `tsc` errors. Observed `Tests 11 failed | 141 passed (152)`. `type-check` stopped at its first project with 1 error (`form.zod.ts`, `field.scale`). Its test project, run alone under the same mutation, shows 2: that one, and `zod-mirror-parity`'s ledger naming `form.zod.ts#FormFieldSchema`. - **A2**, the zod `currencyConfig` member deleted (blob `8056f03b` → `6febb5ab`). Predicted 9 red and at least 1 `tsc` error. Observed `Tests 9 failed | 143 passed (152)` and 1 (the parity ledger). - **A3**, the currency rule disarmed (`if (false)`, blob `8056f03b` → `f05fc4dd`). Predicted 1 red and 0 `tsc`. Observed `Tests 1 failed | 151 passed (152)` and 0. - **A4**, the TS `scale` member deleted (blob `9c210d73` → `80d35122`). Predicted 0 red and at least 3 `tsc` errors. Observed `Tests 152 passed (152)` and 4: 2 in the pin, plus 2 in the parity ledgers (one naming `form.zod.ts#FormFieldSchema`, one naming `scale`). - **Union at the final head `5f049697`:** `pnpm exec vitest run --maxWorkers=2 packages/types/ packages/fields/ examples/schema-catalog/ scripts/__tests__/` gave `Test Files 824 passed | 3 skipped (827)` and `Tests 21333 passed | 9 skipped (21342)`. - **Type-check:** `pnpm --filter @object-ui/types type-check` (script line `@object-ui/types@17.7.0 type-check` echoed; its `tsconfig.test.json` lists both edited pins) and `pnpm --filter @object-ui/example-schema-catalog type-check` (echoed; its test project lists the new test). Both exit 0, with 0 `error TS`. ## Gates at `5f049697` objectui has no `dispatch-gates`, so this set is the brief's list plus what the diff touches, derived by hand from the root `package.json`. All exit 0: - **The brief's list:** - `check:skill-examples` and `check:doc-snippets` ("784 of 784 block(s) judged, 0 failed"), after building the snippet gate's `--build-filter` closure (turbo: "35 successful, 35 total"); - `check:doc-types`, `check:doc-examples` (122 blocks, 87 failing as their ledger rows declare), `check:doc-fences` and `check:doc-example-ids`; - `check:spec-symbols`, and `check:component-surface-parity` (report-only; no row names either new key); - `check-changeset-presence` (4 published source files, 1 changeset), `check:changeset-claims` and `check:pending-changeset-literals`; - `check:new-line-citations` ("0 new citation(s)") and `check:control-bytes`. - **Derived from the diff:** `docs:check-links`, `check:designer-field-key-parity`, `check:handler-key-reads`, `check:test-path-roots`, `check:prompt-keys`, `check:action-forward-parity`, `check:vi-mock-specifiers`, `changeset:check`, and `check-governed-queue-guard --test` over the 9 paths (NOT GOVERNED). - **Narrowed lint**, over the 5 changed `.ts`/`.tsx` files with the root `eslint.config.js` and `--no-inline-config`: 1. The population is its `**/*.{ts,tsx}` blocks. 2. `--format json` lists 5 files, with 0 errors and 9 warnings. All 9 are `no-explicit-any` in `form.ts`, and the same 9 read at base through `--stdin`. The other three existing files read 0/0 at base. 3. Invariance: no `parserOptions.project` or `projectService`, and no `eslint-rules/` rule reads the filesystem, so the diff cannot move an untouched file's verdict. NOT MEASURED: - `pnpm check` (the CLI self-check `lint.yml` runs). Reason: it needs the built CLI. It exits non-zero only on unreadable JSON, and both edited JSON documents parse. - Repository-wide `pnpm lint` and `pnpm test`. Reason: CI-owned. - CI on this PR. Reason: opened with this report; convergence is the seat's. ## Acceptance notes - **The card's executable acceptance holds on this head**: M3 class (ii) reads 0 corpus pairs. The 32 class (i) pairs remain, a source-read grade, carried by objectui#5250 slice B. - **B widened the strict face by `currencyConfig`**, which the claim's file surface allowed (`form.ts` / `form.zod.ts`) but its Clause-② note did not expect. The reason is above: the moved documents need it to parse. - **The tolerant face narrows** on a malformed `scale` / `currencyConfig` and on `scale` on a currency entry. The changeset states this as BREAKING. No corpus document writes either malformed shape: M3's red-today count moves only by the guide's fence. - **Not this round's, read but not changed.** `CurrencyFieldMetadata` (the field-metadata type) still declares `currency`. `content/docs/fields/currency.mdx` teaches it in a `ts` fence, beside the two catalog examples that now write `currencyConfig`. Both are limb 1 of `resolveFieldCurrency`, which the ACCEPT keeps as a separate question. Noted, not filed. - PR objectui#11069 (parked) edits a different section of the same guide (the validation doors), so no textual overlap is expected. - The M3 scratch instrument and the probes are not committed. --- _Generated by [Claude Code](https://claude.ai/code/session_01DBZ9bntPZ7VKyQNtJeNsgw)_ Co-authored-by: Claude <noreply@anthropic.com>
1 parent a920d8c commit 18d7b48

9 files changed

Lines changed: 322 additions & 7 deletions

File tree

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
---
2+
'@object-ui/types': minor
3+
---
4+
5+
A form field declares `scale` and `currencyConfig` on both faces, by reference to `@objectstack/spec`'s `FieldSchema`, so the strict authoring face accepts the decimal places and the fixed currency the field widgets read (objectui#11070).
6+
7+
A hand-authored `form` hands each field widget the `fields[]` entry itself as its metadata carrier. The `number`, `percent`, `formula` and `summary` widgets read `scale` off it, and the `currency` widget reads `currencyConfig` through `resolveFieldCurrency`. Both keys always drew; only the declarations were missing. Each is now the spec member itself, value checks included.
8+
9+
- **TypeScript.** `FormField` gains `scale?: SpecField['scale']` and `currencyConfig?: SpecField['currencyConfig']`. Both used to fall to the index signature's `any`. A typed literal with a value of the wrong type (a string `scale`, a `currencyMode` outside `fixed` / `dynamic`) is now a compile error.
10+
- **zod (`@object-ui/types/zod`).** WIDENS on the strict authoring face (`StrictAnyComponentSchema`): `fields[].scale` and `fields[].currencyConfig` used to be refused with `unrecognized_keys`, and now parse. NARROWS on the tolerant face (`safeValidateSchema`), where both keys used to be stripped unjudged: a `scale` that is not a whole number from 0 to 100 is now refused, and so is a `currencyConfig` the spec refuses (a `currencyMode` outside `fixed` / `dynamic`, a `defaultCurrency` that is not three characters, or a member the spec's config does not declare, such as the removed `precision`). The values are now kept. No spec default (`dynamic`, `CNY`) is written into the document.
11+
- **`scale` on a `currency` field is refused, on both faces.** The spec's `FieldSchema` refuses it there (objectstack-ai/objectstack#19629): an amount's decimal places are its currency's ISO 4217 minor unit. The `currency` widget never read it. The rule is keyed on `type`, as the spec keys it, and the refusal is the spec's own text. This is the only one of the spec's cross-key rules this face carries. The others (`rows`, `minLength` / `maxLength`, `multiple`) key on the spec's field-type sets, and a form field's `type` is a widget id (`input`, `select`, …) those sets do not hold.
12+
- **Not declared: `currency` on a form field.** The spec's `FieldSchema` refuses it as a field key, so the strict face still refuses it. `resolveFieldCurrency` still reads it at runtime. Declare a fixed currency as `currencyConfig: { currencyMode: 'fixed', defaultCurrency: 'EUR' }`.
13+
14+
BREAKING (`@object-ui/types`), for a document whose form field carries a `scale` or a `currencyConfig` the spec refuses, or a `scale` on a `currency` field: it no longer validates on the tolerant face. Fix the value, or delete `scale` from the `currency` field. (The bump is `minor` by this repo's release model: objectui's major follows the `@objectstack` family major, and its own breaking changes ship as `minor` with the breaking semantics stated here.)
15+
16+
**Clause-②: yes (widening)**: both keys widen the strict face, and their spec value checks, plus the spec's `currency` rule on `scale`, narrow the tolerant face.

‎content/docs/guide/schema-rendering.md‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ written flat on the node:
320320
"name": "call_api",
321321
"label": "Click Me",
322322
"actionType": "api",
323-
"endpoint": "/api/action",
323+
"target": "/api/action",
324324
"method": "POST"
325325
}
326326
}
@@ -334,8 +334,9 @@ throws on the first click: "Expected `onClick` listener to be a function, instea
334334
value of `object` type." The execution type is `actionType`, and the built-in vocabulary
335335
is `script` | `url` | `modal` | `flow` | `api` | `form` (plus objectui's `navigation`
336336
alias) — anything else must be a handler your host registered on `ActionProvider`. `ajax`
337-
is neither. And the endpoint key is `endpoint`, with `method`; `api` is not a key any
338-
action renderer forwards.
337+
is neither. And an `api` action's endpoint is its `target`, with the verb in `method`: the
338+
spec's `action:button` row refuses `endpoint` and names `target` in its place, and `api` is
339+
not a key any action renderer forwards.
339340

340341
## Performance Optimization
341342

‎examples/schema-catalog/src/schemas/fields-currency/euro-currency.json‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@
88
"label": "Price (EUR)",
99
"type": "currency",
1010
"placeholder": "€0.00",
11-
"currency": "EUR"
11+
"currencyConfig": {
12+
"currencyMode": "fixed",
13+
"defaultCurrency": "EUR"
14+
}
1215
}
1316
]
1417
}

‎examples/schema-catalog/src/schemas/fields-currency/usd-currency.json‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@
88
"label": "Amount",
99
"type": "currency",
1010
"placeholder": "$0.00",
11-
"currency": "USD"
11+
"currencyConfig": {
12+
"currencyMode": "fixed",
13+
"defaultCurrency": "USD"
14+
}
1215
}
1316
]
1417
}
Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
/**
2+
* ObjectUI
3+
* Copyright (c) 2024-present ObjectStack Inc.
4+
*
5+
* This source code is licensed under the MIT license found in the
6+
* LICENSE file in the root directory of this source tree.
7+
*/
8+
9+
/**
10+
* The `scale` and currency catalog examples parse on the strict authoring
11+
* face, and the currency examples declare their currency the spec's way —
12+
* objectui#11070 round 13.
13+
*
14+
* At the round's base `StrictAnyComponentSchema` refused all five documents
15+
* below by name, although the widget each one renders reads the key:
16+
*
17+
* - the three `scale` documents, because the form-field face did not declare
18+
* `scale`. It now carries `@objectstack/spec`'s `FieldSchema.scale` by
19+
* reference (the faces are pinned in
20+
* `packages/types/src/__tests__/strict-face-read-keys-11070.test.ts`; what
21+
* each document renders is pinned by `fields-number-scale-11413` and
22+
* `fields-percent-scale-11255` beside this file);
23+
* - the two currency documents, because they wrote `currency: 'EUR'` /
24+
* `'USD'` on the field, which the spec's `FieldSchema` refuses as a field
25+
* key. The seat's ruling keeps that read runtime-only and moves the
26+
* documents to the spec's declaration, `currencyConfig: { currencyMode:
27+
* 'fixed', defaultCurrency }`, which `resolveFieldCurrency` reads.
28+
*
29+
* The currency block is driven through the real `SchemaRenderer`, the real
30+
* form renderer and the real `@object-ui/fields` registration: the symbol the
31+
* widget draws, and the input step the currency's minor unit sets. Its two
32+
* controls show the declaration is what decides both. In `dynamic` mode the
33+
* same entry draws no symbol, because that mode reads the tenant default and
34+
* none is set here. With `JPY` it draws ¥ and steps by whole yen.
35+
*
36+
* Module-scope import of `@object-ui/fields`, not `beforeAll` (AGENTS.md
37+
* §测试纪律): the widgets sit behind `React.lazy`, so paying the import here
38+
* keeps the lazy factories out of every test timeout budget.
39+
*/
40+
import { describe, it, expect } from 'vitest';
41+
import React from 'react';
42+
import { render, waitFor } from '@testing-library/react';
43+
import '@object-ui/components';
44+
import '@object-ui/fields';
45+
import { SchemaRenderer } from '@object-ui/react';
46+
import { StrictAnyComponentSchema } from '@object-ui/types/zod';
47+
import { getExample } from '../src/index.js';
48+
49+
interface CurrencyConfig {
50+
currencyMode?: string;
51+
defaultCurrency?: string;
52+
}
53+
interface FieldEntry {
54+
name: string;
55+
type: string;
56+
scale?: number;
57+
currency?: string;
58+
currencyConfig?: CurrencyConfig;
59+
}
60+
interface FormNode {
61+
type: 'form';
62+
fields: FieldEntry[];
63+
[key: string]: unknown;
64+
}
65+
66+
const ROUND_13_DOCUMENTS = [
67+
'fields-number/with-decimal-places',
68+
'fields-percent/required-percent',
69+
'fields-percent/with-decimal-places',
70+
'fields-currency/euro-currency',
71+
'fields-currency/usd-currency',
72+
] as const;
73+
74+
/** Every strict-face issue as `code path: message`, so a red run says what broke. */
75+
function strictIssues(schema: unknown): string[] {
76+
const result = StrictAnyComponentSchema.safeParse(schema);
77+
return result.success
78+
? []
79+
: result.error.issues.map((i) => `${i.code} ${i.path.map(String).join('.')}: ${i.message}`);
80+
}
81+
82+
/** A deep copy of a catalog form: the control cases below edit their own. */
83+
function example(id: string): FormNode {
84+
return JSON.parse(JSON.stringify(getExample(id).schema)) as FormNode;
85+
}
86+
87+
/** The symbol drawn beside the input ('' when none) and the input's `step`. */
88+
async function currencyInput(schema: FormNode): Promise<{ symbol: string; step: string | null }> {
89+
const { container } = render(<SchemaRenderer schema={schema as never} />);
90+
const selector = `[data-field="${schema.fields[0].name}"] input[type="number"]`;
91+
// `waitFor`: the widget is a `React.lazy` boundary, so the FormItem's input
92+
// is absent until the chunk resolves.
93+
await waitFor(() => expect(container.querySelector(selector)).toBeTruthy());
94+
const input = container.querySelector(selector) as HTMLInputElement;
95+
return {
96+
symbol: input.parentElement?.querySelector('span')?.textContent ?? '',
97+
step: input.getAttribute('step'),
98+
};
99+
}
100+
101+
describe('the round-13 catalog documents parse on the strict authoring face (objectui#11070)', () => {
102+
it.each(ROUND_13_DOCUMENTS)('%s parses on the strict face', (id) => {
103+
expect(strictIssues(getExample(id).schema)).toEqual([]);
104+
});
105+
});
106+
107+
describe('the currency catalog examples declare their currency as `currencyConfig` (objectui#11070)', () => {
108+
const CASES = [
109+
['fields-currency/euro-currency', 'EUR', '€'],
110+
['fields-currency/usd-currency', 'USD', '$'],
111+
] as const;
112+
113+
it.each(CASES)('%s declares a fixed %s and draws %s', async (id, code, symbol) => {
114+
const schema = example(id);
115+
const [field] = schema.fields;
116+
expect(field.currencyConfig).toEqual({ currencyMode: 'fixed', defaultCurrency: code });
117+
expect(field).not.toHaveProperty('currency');
118+
119+
// Two decimals: the minor unit of both EUR and USD.
120+
expect(await currencyInput(schema)).toEqual({ symbol, step: '0.01' });
121+
});
122+
123+
it('CONTROL: in `dynamic` mode the same entry draws no symbol, because that mode does not read `defaultCurrency`', async () => {
124+
const schema = example('fields-currency/euro-currency');
125+
schema.fields[0].currencyConfig = { currencyMode: 'dynamic', defaultCurrency: 'EUR' };
126+
expect((await currencyInput(schema)).symbol).toBe('');
127+
});
128+
129+
it('CONTROL: the declared code is read, not a constant: `JPY` draws ¥ and steps by whole yen', async () => {
130+
const schema = example('fields-currency/euro-currency');
131+
schema.fields[0].currencyConfig = { currencyMode: 'fixed', defaultCurrency: 'JPY' };
132+
expect(await currencyInput(schema)).toEqual({ symbol: '¥', step: '1' });
133+
});
134+
});

‎packages/types/src/__tests__/form-field-zod-coverage.test.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,10 @@ const DECLARED_KEYS = [
8787
'reference',
8888
'min',
8989
'max',
90+
// objectui#11070 round 13 — the decimal places the number-family widgets
91+
// read, and the currency widget's fixed-currency declaration, by reference.
92+
'scale',
93+
'currencyConfig',
9094
'minLength',
9195
'maxLength',
9296
'pattern',

0 commit comments

Comments
 (0)