diff --git a/.changeset/36425-field-show-on-create.md b/.changeset/36425-field-show-on-create.md new file mode 100644 index 00000000000..d03f81768e2 --- /dev/null +++ b/.changeset/36425-field-show-on-create.md @@ -0,0 +1,17 @@ +--- +'@objectstack/spec': minor +'@objectstack/driver-sql': patch +'@objectstack/metadata-core': patch +--- + +feat(spec): a field can say it is not asked for when a record is created (`showOnCreate`) + +Clause-②: yes (widening) +Metadata-protocol: added +Skills-docs: follow-up #36455 + +`FieldSchema` gains `showOnCreate`, an optional boolean. Absent or `true`, the field is asked for when a record is created, as today. `false` says the business does not ask for it at creation: every create surface (the create dialog, the full-page create, an action-opened create) leaves it out, while editing, the record page and lists keep showing it, so the value is filled in after the record exists. + +- The one pair refused is `showOnCreate: false` on a `required: true` field, at the field's `showOnCreate` key, at every door that parses a field (`defineStack`, `os validate`, the metadata save): a required field is always asked for when a record is created, so the person creating it sees every value the record must have. The message names both fixes (keep the field on create, or drop `required`). A declared `defaultValue` makes no exception: the field is still asked for, with its default filled in. A `requiredWhen` field is accepted, since its gate is a predicate the parse cannot judge; the write door still refuses a create born inside it. +- No create surface reads the key yet: it is `planned` in the liveness ledger, and the Console's create surfaces read it in the change that follows. Nothing that parses today is refused, and no parsed field's output changes (the key has no default). +- `@objectstack/driver-sql` and `@objectstack/metadata-core` classify the new key in their every-field-key ledgers: `FIELD_KEY_STORAGE_CLASS` marks `showOnCreate` `presentation` (the DDL never reads it), and `FIELD_REFERENCE_POSITIONS` keeps it, since it is a boolean that names no field. Neither changes what it does with any field. diff --git a/content/docs/references/data/field.mdx b/content/docs/references/data/field.mdx index cd4a0964fae..2a8e0bcb4a0 100644 --- a/content/docs/references/data/field.mdx +++ b/content/docs/references/data/field.mdx @@ -115,6 +115,7 @@ const result = CurrencyConfigSchema.parse(data); | **conditionalFormatting** | `{ condition: string \| object; style: Record }[]` | optional | Cell formatting rules for this field — `[{ condition, style }]`, the same rule a list view's `conditionalFormatting` declares. In order, the first rule whose CEL `condition` holds applies its CSS `style` map to THIS FIELD'S CELL wherever the field renders (grid, kanban card, record page, related list, report cell); a list view's row rules style the row, and both may apply. The condition reads `value` (this field's value on the record) and `record` (the row) and no other root, e.g. P`value < 0` with `style: { color: '#b91c1c' }`; `objectstack validate` refuses a condition that does not parse or reads any other root. For presentation only — a semantic state such as a deadline's overdue is declared with `dueLike` / `settledWhen` instead. Display only: nothing on the write path reads it. | | **widget** | `string` | optional | Form widget override — names a registered field component (resolved as `field:`) to render this field instead of the `type` default. Degrades to the `type` renderer when unregistered. e.g. "object-ref", "filter-condition", "recipient-picker". | | **hidden** | `boolean` | optional (default: `false`) | Hidden from default UI | +| **showOnCreate** | `boolean` | optional | Ask for this field when a record is created. Absent or `true`: the field is on every create surface (the create dialog, the full-page create, an action-opened create). `false`: no create surface shows it; editing, the record page and lists still do, so a value is filled in after the record exists. Refused on a `required: true` field, with or without a `defaultValue`: a required field is always asked for on create. Keep the field on create, or drop `required`. A `requiredWhen` field is accepted, and its create is still refused when the predicate holds and the value is empty. | | **internal** | `boolean` | optional | Never return this field's value on the generic data path — the engine OMITS the key from `find`/`findOne` results, the 201 create body and the by-id update body, on the default projection AND when a client names the field in `?select=`. Storage, filtering and indexing are untouched, so a server-side verifier can still match on the column and a purpose-built mint route can still return the value once at creation. The read protection for ADR-0100's third credential channel (auth-subsystem one-way hashes on `text` columns). Omission, not masking: a mask signals 'a value is set', which carries no information on a `required` column. | | **readonly** | `boolean` | optional (default: `false`) | Read-only — never editable in forms, AND server-enforced on BOTH write paths: a non-system write to this field is silently dropped from the payload on UPDATE and on INSERT (a create can no longer directly seed e.g. `approval_status: "approved"`), symmetric with `readonlyWhen`. A stripped INSERT field still falls back to its `defaultValue`. Exempt from the strip on BOTH paths: `isSystem` writes (seed replay, migration). Exempt on the UPDATE path ONLY: an opt-in "historical" import (`preserveAudit`) — which admits a whitelist (the audit/timestamp family plus author-declared business `readonly` fields). On INSERT the exemption does NOT apply: a non-system create that requests `preserveAudit` still has its readonly fields stripped, and is warned loudly that the exemption is UPDATE-only — replaying archival readonly facts on create requires a system context. A normal (non-system) import is NOT system-context and still strips. | | **requiredPermissions** | `string[]` | optional | [ADR-0066 D3] Capabilities required to read/edit this field (mask on read, deny on write; AND-gate). | diff --git a/content/docs/references/data/object.mdx b/content/docs/references/data/object.mdx index f695bda288c..37aea1488e0 100644 --- a/content/docs/references/data/object.mdx +++ b/content/docs/references/data/object.mdx @@ -295,6 +295,7 @@ const result = ApiMethod.parse(data); | **conditionalFormatting** | `{ condition: string \| object; style: Record }[]` | optional | Cell formatting rules for this field — `[{ condition, style }]`, the same rule a list view's `conditionalFormatting` declares. In order, the first rule whose CEL `condition` holds applies its CSS `style` map to THIS FIELD'S CELL wherever the field renders (grid, kanban card, record page, related list, report cell); a list view's row rules style the row, and both may apply. The condition reads `value` (this field's value on the record) and `record` (the row) and no other root, e.g. P`value < 0` with `style: { color: '#b91c1c' }`; `objectstack validate` refuses a condition that does not parse or reads any other root. For presentation only — a semantic state such as a deadline's overdue is declared with `dueLike` / `settledWhen` instead. Display only: nothing on the write path reads it. | | **widget** | `string` | optional | Form widget override — names a registered field component (resolved as `field:`) to render this field instead of the `type` default. Degrades to the `type` renderer when unregistered. e.g. "object-ref", "filter-condition", "recipient-picker". | | **hidden** | `boolean` | optional (default: `false`) | Hidden from default UI | +| **showOnCreate** | `boolean` | optional | Ask for this field when a record is created. Absent or `true`: the field is on every create surface (the create dialog, the full-page create, an action-opened create). `false`: no create surface shows it; editing, the record page and lists still do, so a value is filled in after the record exists. Refused on a `required: true` field, with or without a `defaultValue`: a required field is always asked for on create. Keep the field on create, or drop `required`. A `requiredWhen` field is accepted, and its create is still refused when the predicate holds and the value is empty. | | **internal** | `boolean` | optional | Never return this field's value on the generic data path — the engine OMITS the key from `find`/`findOne` results, the 201 create body and the by-id update body, on the default projection AND when a client names the field in `?select=`. Storage, filtering and indexing are untouched, so a server-side verifier can still match on the column and a purpose-built mint route can still return the value once at creation. The read protection for ADR-0100's third credential channel (auth-subsystem one-way hashes on `text` columns). Omission, not masking: a mask signals 'a value is set', which carries no information on a `required` column. | | **readonly** | `boolean` | optional (default: `false`) | Read-only — never editable in forms, AND server-enforced on BOTH write paths: a non-system write to this field is silently dropped from the payload on UPDATE and on INSERT (a create can no longer directly seed e.g. `approval_status: "approved"`), symmetric with `readonlyWhen`. A stripped INSERT field still falls back to its `defaultValue`. Exempt from the strip on BOTH paths: `isSystem` writes (seed replay, migration). Exempt on the UPDATE path ONLY: an opt-in "historical" import (`preserveAudit`) — which admits a whitelist (the audit/timestamp family plus author-declared business `readonly` fields). On INSERT the exemption does NOT apply: a non-system create that requests `preserveAudit` still has its readonly fields stripped, and is warned loudly that the exemption is UPDATE-only — replaying archival readonly facts on create requires a system context. A normal (non-system) import is NOT system-context and still strips. | | **requiredPermissions** | `string[]` | optional | [ADR-0066 D3] Capabilities required to read/edit this field (mask on read, deny on write; AND-gate). | @@ -686,6 +687,7 @@ const result = ApiMethod.parse(data); | **conditionalFormatting** | `{ condition: string \| object; style: Record }[]` | optional | Cell formatting rules for this field — `[{ condition, style }]`, the same rule a list view's `conditionalFormatting` declares. In order, the first rule whose CEL `condition` holds applies its CSS `style` map to THIS FIELD'S CELL wherever the field renders (grid, kanban card, record page, related list, report cell); a list view's row rules style the row, and both may apply. The condition reads `value` (this field's value on the record) and `record` (the row) and no other root, e.g. P`value < 0` with `style: { color: '#b91c1c' }`; `objectstack validate` refuses a condition that does not parse or reads any other root. For presentation only — a semantic state such as a deadline's overdue is declared with `dueLike` / `settledWhen` instead. Display only: nothing on the write path reads it. | | **widget** | `string` | optional | Form widget override — names a registered field component (resolved as `field:`) to render this field instead of the `type` default. Degrades to the `type` renderer when unregistered. e.g. "object-ref", "filter-condition", "recipient-picker". | | **hidden** | `boolean` | optional (default: `false`) | Hidden from default UI | +| **showOnCreate** | `boolean` | optional | Ask for this field when a record is created. Absent or `true`: the field is on every create surface (the create dialog, the full-page create, an action-opened create). `false`: no create surface shows it; editing, the record page and lists still do, so a value is filled in after the record exists. Refused on a `required: true` field, with or without a `defaultValue`: a required field is always asked for on create. Keep the field on create, or drop `required`. A `requiredWhen` field is accepted, and its create is still refused when the predicate holds and the value is empty. | | **internal** | `boolean` | optional | Never return this field's value on the generic data path — the engine OMITS the key from `find`/`findOne` results, the 201 create body and the by-id update body, on the default projection AND when a client names the field in `?select=`. Storage, filtering and indexing are untouched, so a server-side verifier can still match on the column and a purpose-built mint route can still return the value once at creation. The read protection for ADR-0100's third credential channel (auth-subsystem one-way hashes on `text` columns). Omission, not masking: a mask signals 'a value is set', which carries no information on a `required` column. | | **readonly** | `boolean` | optional (default: `false`) | Read-only — never editable in forms, AND server-enforced on BOTH write paths: a non-system write to this field is silently dropped from the payload on UPDATE and on INSERT (a create can no longer directly seed e.g. `approval_status: "approved"`), symmetric with `readonlyWhen`. A stripped INSERT field still falls back to its `defaultValue`. Exempt from the strip on BOTH paths: `isSystem` writes (seed replay, migration). Exempt on the UPDATE path ONLY: an opt-in "historical" import (`preserveAudit`) — which admits a whitelist (the audit/timestamp family plus author-declared business `readonly` fields). On INSERT the exemption does NOT apply: a non-system create that requests `preserveAudit` still has its readonly fields stripped, and is warned loudly that the exemption is UPDATE-only — replaying archival readonly facts on create requires a system context. A normal (non-system) import is NOT system-context and still strips. | | **requiredPermissions** | `string[]` | optional | [ADR-0066 D3] Capabilities required to read/edit this field (mask on read, deny on write; AND-gate). | diff --git a/content/docs/references/system/migration.mdx b/content/docs/references/system/migration.mdx index 3827a1a5a5f..19c087dbc29 100644 --- a/content/docs/references/system/migration.mdx +++ b/content/docs/references/system/migration.mdx @@ -118,6 +118,7 @@ Add a new field to an existing object | **conditionalFormatting** | `{ condition: string \| object; style: Record }[]` | optional | Cell formatting rules for this field — `[{ condition, style }]`, the same rule a list view's `conditionalFormatting` declares. In order, the first rule whose CEL `condition` holds applies its CSS `style` map to THIS FIELD'S CELL wherever the field renders (grid, kanban card, record page, related list, report cell); a list view's row rules style the row, and both may apply. The condition reads `value` (this field's value on the record) and `record` (the row) and no other root, e.g. P`value < 0` with `style: { color: '#b91c1c' }`; `objectstack validate` refuses a condition that does not parse or reads any other root. For presentation only — a semantic state such as a deadline's overdue is declared with `dueLike` / `settledWhen` instead. Display only: nothing on the write path reads it. | | **widget** | `string` | optional | Form widget override — names a registered field component (resolved as `field:`) to render this field instead of the `type` default. Degrades to the `type` renderer when unregistered. e.g. "object-ref", "filter-condition", "recipient-picker". | | **hidden** | `boolean` | optional (default: `false`) | Hidden from default UI | +| **showOnCreate** | `boolean` | optional | Ask for this field when a record is created. Absent or `true`: the field is on every create surface (the create dialog, the full-page create, an action-opened create). `false`: no create surface shows it; editing, the record page and lists still do, so a value is filled in after the record exists. Refused on a `required: true` field, with or without a `defaultValue`: a required field is always asked for on create. Keep the field on create, or drop `required`. A `requiredWhen` field is accepted, and its create is still refused when the predicate holds and the value is empty. | | **internal** | `boolean` | optional | Never return this field's value on the generic data path — the engine OMITS the key from `find`/`findOne` results, the 201 create body and the by-id update body, on the default projection AND when a client names the field in `?select=`. Storage, filtering and indexing are untouched, so a server-side verifier can still match on the column and a purpose-built mint route can still return the value once at creation. The read protection for ADR-0100's third credential channel (auth-subsystem one-way hashes on `text` columns). Omission, not masking: a mask signals 'a value is set', which carries no information on a `required` column. | | **readonly** | `boolean` | optional (default: `false`) | Read-only — never editable in forms, AND server-enforced on BOTH write paths: a non-system write to this field is silently dropped from the payload on UPDATE and on INSERT (a create can no longer directly seed e.g. `approval_status: "approved"`), symmetric with `readonlyWhen`. A stripped INSERT field still falls back to its `defaultValue`. Exempt from the strip on BOTH paths: `isSystem` writes (seed replay, migration). Exempt on the UPDATE path ONLY: an opt-in "historical" import (`preserveAudit`) — which admits a whitelist (the audit/timestamp family plus author-declared business `readonly` fields). On INSERT the exemption does NOT apply: a non-system create that requests `preserveAudit` still has its readonly fields stripped, and is warned loudly that the exemption is UPDATE-only — replaying archival readonly facts on create requires a system context. A normal (non-system) import is NOT system-context and still strips. | | **requiredPermissions** | `string[]` | optional | [ADR-0066 D3] Capabilities required to read/edit this field (mask on read, deny on write; AND-gate). | @@ -556,6 +557,7 @@ Add a new field to an existing object | **conditionalFormatting** | `{ condition: string \| object; style: Record }[]` | optional | Cell formatting rules for this field — `[{ condition, style }]`, the same rule a list view's `conditionalFormatting` declares. In order, the first rule whose CEL `condition` holds applies its CSS `style` map to THIS FIELD'S CELL wherever the field renders (grid, kanban card, record page, related list, report cell); a list view's row rules style the row, and both may apply. The condition reads `value` (this field's value on the record) and `record` (the row) and no other root, e.g. P`value < 0` with `style: { color: '#b91c1c' }`; `objectstack validate` refuses a condition that does not parse or reads any other root. For presentation only — a semantic state such as a deadline's overdue is declared with `dueLike` / `settledWhen` instead. Display only: nothing on the write path reads it. | | **widget** | `string` | optional | Form widget override — names a registered field component (resolved as `field:`) to render this field instead of the `type` default. Degrades to the `type` renderer when unregistered. e.g. "object-ref", "filter-condition", "recipient-picker". | | **hidden** | `boolean` | optional (default: `false`) | Hidden from default UI | +| **showOnCreate** | `boolean` | optional | Ask for this field when a record is created. Absent or `true`: the field is on every create surface (the create dialog, the full-page create, an action-opened create). `false`: no create surface shows it; editing, the record page and lists still do, so a value is filled in after the record exists. Refused on a `required: true` field, with or without a `defaultValue`: a required field is always asked for on create. Keep the field on create, or drop `required`. A `requiredWhen` field is accepted, and its create is still refused when the predicate holds and the value is empty. | | **internal** | `boolean` | optional | Never return this field's value on the generic data path — the engine OMITS the key from `find`/`findOne` results, the 201 create body and the by-id update body, on the default projection AND when a client names the field in `?select=`. Storage, filtering and indexing are untouched, so a server-side verifier can still match on the column and a purpose-built mint route can still return the value once at creation. The read protection for ADR-0100's third credential channel (auth-subsystem one-way hashes on `text` columns). Omission, not masking: a mask signals 'a value is set', which carries no information on a `required` column. | | **readonly** | `boolean` | optional (default: `false`) | Read-only — never editable in forms, AND server-enforced on BOTH write paths: a non-system write to this field is silently dropped from the payload on UPDATE and on INSERT (a create can no longer directly seed e.g. `approval_status: "approved"`), symmetric with `readonlyWhen`. A stripped INSERT field still falls back to its `defaultValue`. Exempt from the strip on BOTH paths: `isSystem` writes (seed replay, migration). Exempt on the UPDATE path ONLY: an opt-in "historical" import (`preserveAudit`) — which admits a whitelist (the audit/timestamp family plus author-declared business `readonly` fields). On INSERT the exemption does NOT apply: a non-system create that requests `preserveAudit` still has its readonly fields stripped, and is warned loudly that the exemption is UPDATE-only — replaying archival readonly facts on create requires a system context. A normal (non-system) import is NOT system-context and still strips. | | **requiredPermissions** | `string[]` | optional | [ADR-0066 D3] Capabilities required to read/edit this field (mask on read, deny on write; AND-gate). | diff --git a/packages/drivers/driver-sql/src/builtin-column-collision.ts b/packages/drivers/driver-sql/src/builtin-column-collision.ts index 9f968c4e022..d6c234b06b0 100644 --- a/packages/drivers/driver-sql/src/builtin-column-collision.ts +++ b/packages/drivers/driver-sql/src/builtin-column-collision.ts @@ -117,6 +117,7 @@ export const FIELD_KEY_STORAGE_CLASS: Readonly> = group: 'presentation', widget: 'presentation', hidden: 'presentation', + showOnCreate: 'presentation', // whether a create surface asks for the field; the DDL never reads it internal: 'presentation', readonly: 'presentation', visibleWhen: 'presentation', diff --git a/packages/metadata-core/src/object-schema-fls-references.ts b/packages/metadata-core/src/object-schema-fls-references.ts index 6cd4b804ab4..6d4cac2f6df 100644 --- a/packages/metadata-core/src/object-schema-fls-references.ts +++ b/packages/metadata-core/src/object-schema-fls-references.ts @@ -630,6 +630,9 @@ export const FIELD_REFERENCE_POSITIONS: Readonly> = { // the way `unitConfig.unitField` does. unitConfig: keep, group: keep, widget: keep, hidden: keep, internal: keep, readonly: keep, + // A boolean facet: whether a create surface asks for this field (#36425); + // it names no field. + showOnCreate: keep, requiredPermissions: keep, maskingRule: keep, ackPlaintextMasking: keep, system: keep, sortable: keep, inlineHelpText: keep, placeholder: keep, externalId: keep, // A boolean facet of this date field: it declares the field a deadline diff --git a/packages/metadata-protocol/src/protocol.meta-types-degenerate-derivation.test.ts b/packages/metadata-protocol/src/protocol.meta-types-degenerate-derivation.test.ts index 85a8a7ca810..d1125f946bc 100644 --- a/packages/metadata-protocol/src/protocol.meta-types-degenerate-derivation.test.ts +++ b/packages/metadata-protocol/src/protocol.meta-types-degenerate-derivation.test.ts @@ -399,8 +399,10 @@ describe('#17501 — /meta/types serves a real schema for `action`, and moves no // that a text field holds a unit code (ADR-0158 U4, Open item 8). // [#35985] `object` 50 → 51: `color`, the palette name the console draws // the object's icon tile in. + // [#36425] `field` 84 → 85: `showOnCreate`, whether a field is asked for + // when a record is created. const CARD_PROPERTY_COUNTS: Record = { - agent: 24, app: 24, dashboard: 21, dataset: 17, field: 84, flow: 24, + agent: 24, app: 24, dashboard: 21, dataset: 17, field: 85, flow: 24, hook: 24, object: 51, page: 28, position: 14, report: 24, skill: 17, tool: 14, }; diff --git a/packages/spec/authorable-surface/data.json b/packages/spec/authorable-surface/data.json index b6baa09f6dc..4627f4ddb03 100644 --- a/packages/spec/authorable-surface/data.json +++ b/packages/spec/authorable-surface/data.json @@ -377,6 +377,7 @@ "data/Field:scale", "data/Field:searchable", "data/Field:settledWhen", + "data/Field:showOnCreate", "data/Field:sortable", "data/Field:step", "data/Field:storage", diff --git a/packages/spec/liveness/field.json b/packages/spec/liveness/field.json index 5f37d85809c..b796789896e 100644 --- a/packages/spec/liveness/field.json +++ b/packages/spec/liveness/field.json @@ -189,6 +189,12 @@ "status": "live", "note": "renderer." }, + "showOnCreate": { + "status": "planned", + "verifiedAt": "2026-11-22", + "evidence": "packages/spec/src/data/field.zod.ts#showOnCreate (the parse refuses `showOnCreate: false` beside `required: true`, at every door that parses a field)", + "note": "PLANNED, contract-first spec half of the card that retires the internal create and edit forms: the key and its parse-time refusal land first, the readers second. The readers are every create surface of the Console (the create dialog, the full-page create, an action-opened create), which leave a `showOnCreate: false` field out; editing, the record page and lists ignore it by contract. Flip to `live` on the commit that lands those readers, citing them." + }, "internal": { "status": "live", "verifiedAt": "2026-08-12", diff --git a/packages/spec/liveness/state-counts/field.md b/packages/spec/liveness/state-counts/field.md index 6c873b26ab5..b59b5382bba 100644 --- a/packages/spec/liveness/state-counts/field.md +++ b/packages/spec/liveness/state-counts/field.md @@ -12,4 +12,4 @@ committed anywhere: `check:liveness` sums the shards when it reads them. | Type | live | exp | elsewhere | dead | planned | classified | |---|---|---|---|---|---|---| -| `field` | 107 | 0 | 0 | 1 | 5 | 113 | +| `field` | 107 | 0 | 0 | 1 | 6 | 114 | diff --git a/packages/spec/src/data/field-show-on-create.test.ts b/packages/spec/src/data/field-show-on-create.test.ts new file mode 100644 index 00000000000..2bbcd690e05 --- /dev/null +++ b/packages/spec/src/data/field-show-on-create.test.ts @@ -0,0 +1,79 @@ +// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license. + +/** + * `showOnCreate` — whether a field is asked for when a record is created. + * + * The key is an authorable field key (absent = asked for), and the one pair it + * cannot form is `showOnCreate: false` beside `required: true`: a required + * field is always asked for on create, with or without a `defaultValue`. The refusal is asserted as a full `safeParse` failure + * located at `['showOnCreate']`; every control is a full `safeParse` success, + * never mere absence of `unrecognized_keys`. + */ + +import { describe, expect, it } from 'vitest'; +import { FieldSchema } from './field.zod'; +import { ObjectSchema } from './object.zod'; + +type Issue = { code: string; path: PropertyKey[]; message: string }; + +function showOnCreateIssues(result: { success: boolean; error?: { issues: Issue[] } }): Issue[] { + if (result.success) return []; + return (result.error?.issues ?? []).filter((issue) => issue.path[issue.path.length - 1] === 'showOnCreate'); +} + +describe('Field.showOnCreate', () => { + it('parses on an optional field, switched off or on, and stays absent when not authored', () => { + for (const showOnCreate of [false, true]) { + const parsed = FieldSchema.safeParse({ name: 'notes', type: 'text', showOnCreate }); + expect(parsed.success).toBe(true); + expect(parsed.success && parsed.data.showOnCreate).toBe(showOnCreate); + } + const untouched = FieldSchema.safeParse({ name: 'notes', type: 'text' }); + expect(untouched.success).toBe(true); + expect(untouched.success && 'showOnCreate' in untouched.data).toBe(false); + }); + + it('refuses `showOnCreate: false` on a `required: true` field, at the key, naming both remedies', () => { + const issues = showOnCreateIssues( + FieldSchema.safeParse({ name: 'amount', type: 'number', required: true, showOnCreate: false }), + ); + expect(issues).toHaveLength(1); + expect(issues[0].code).toBe('custom'); + expect(issues[0].message).toMatch(/^`showOnCreate: false` would leave this field off every create surface/); + }); + + it('refuses the pair when the field declares a `defaultValue` too', () => { + const issues = showOnCreateIssues( + FieldSchema.safeParse({ name: 'stage', type: 'text', required: true, defaultValue: 'new', showOnCreate: false }), + ); + expect(issues).toHaveLength(1); + }); + + it('accepts the controls beside the refused pair', () => { + const controls = [ + { name: 'amount', type: 'number', required: true, showOnCreate: true }, + { name: 'amount', type: 'number', required: true }, + { name: 'amount', type: 'number', required: false, showOnCreate: false }, + // A conditional requirement is a predicate the parse cannot judge: the + // write door still refuses a create born inside it. + { name: 'amount', type: 'number', requiredWhen: "record.stage == 'won'", showOnCreate: false }, + ]; + for (const field of controls) { + expect(FieldSchema.safeParse(field).success, JSON.stringify(field)).toBe(true); + } + }); + + it('refuses the pair through the object door too, located under the field', () => { + const result = ObjectSchema.safeParse({ + name: 'deal', + label: 'Deal', + fields: { + name: { type: 'text', label: 'Name' }, + amount: { type: 'number', label: 'Amount', required: true, showOnCreate: false }, + }, + }); + const issues = showOnCreateIssues(result as never); + expect(issues).toHaveLength(1); + expect(issues[0].path).toEqual(['fields', 'amount', 'showOnCreate']); + }); +}); diff --git a/packages/spec/src/data/field.zod.ts b/packages/spec/src/data/field.zod.ts index ef388203f56..ca1c64d9eaa 100644 --- a/packages/spec/src/data/field.zod.ts +++ b/packages/spec/src/data/field.zod.ts @@ -2885,6 +2885,24 @@ export const FieldSchema = lazySchema(() => { /** Security & Visibility */ hidden: z.boolean().default(false).describe('Hidden from default UI'), + /** + * Whether the field is asked for when a record is created (ADR-0085 §2: a + * creation-time intent of the field — which fields this business asks for + * when a record is born, not inferable from the schema — that binds every + * create surface and names none of them). Absent, as `true`: the field is + * asked for. `false`: every create surface leaves it out; editing, the + * record page and lists still show it. + * + * A `required: true` field cannot be switched off: a required field is + * always asked for on create, with or without a `defaultValue`, so the pair + * is refused here, at every door that parses a field (this schema's + * superRefine). A + * `requiredWhen` field is not refused: its gate is a predicate the parse + * cannot judge, and the write door still refuses a create born inside it. + * `liveness/field.json` carries its row. + */ + showOnCreate: z.boolean().optional().describe('Ask for this field when a record is created. Absent or `true`: the field is on every create surface (the create dialog, the full-page create, an action-opened create). `false`: no create surface shows it; editing, the record page and lists still do, so a value is filled in after the record exists. Refused on a `required: true` field, with or without a `defaultValue`: a required field is always asked for on create. Keep the field on create, or drop `required`. A `requiredWhen` field is accepted, and its create is still refused when the predicate holds and the value is empty.'), + /** * [#7728] "The declared value is never returned on the generic data path." * @@ -3205,6 +3223,25 @@ export const FieldSchema = lazySchema(() => { }); } } + // A required field is always asked for when a record is created: the + // person creating the record sees every value the record must have, so + // `showOnCreate: false` beside `required: true` is refused (#36425 item 6, + // which makes no exception). That holds with a `defaultValue` too, which + // the insert would resolve: the field is still asked for, its default + // filled in. Refused where the author can fix it, at every door that + // parses a field (`defineStack`, `os validate`, the metadata save). + if (field.showOnCreate === false && field.required === true) { + ctx.addIssue({ + code: 'custom', + path: ['showOnCreate'], + message: + '`showOnCreate: false` would leave this field off every create surface, and it is `required: true`: a ' + + 'required field is always asked for when a record is created, so the person creating it sees every value ' + + 'the record must have. Keep the field on create (delete `showOnCreate`), or drop `required`; a value ' + + 'needed only in some cases can be `requiredWhen` instead. A `defaultValue` makes no exception: the field ' + + 'is still asked for, with its default filled in.', + }); + } // [#11339] `referenceVia` declares the id half of a polymorphic pointer // pair (ADR-0052 §5) — semantics only a plain `text` column carries. On a // relationship type it contradicts the type's own single static target, and diff --git a/packages/spec/src/system/metadata-form-zod-reconciliation.test.ts b/packages/spec/src/system/metadata-form-zod-reconciliation.test.ts index 05f264f1572..893f75f7ae5 100644 --- a/packages/spec/src/system/metadata-form-zod-reconciliation.test.ts +++ b/packages/spec/src/system/metadata-form-zod-reconciliation.test.ts @@ -728,6 +728,13 @@ const LEDGER: ReadonlyArray = [ key: 'externalId', why: "graded `dead` (`liveness/field.json`): no upsert, import or seed matches on a field's `externalId`, so a control would invite an author to rely on a flag nothing reads, and `os lint` then warns on the value the form offered. The schema still parses the key, so a stored value stays valid. A seed dataset names its match field in its own `externalId`, an import mapping in its `upsertKey`", }, + { + kind: 'omit', + type: 'field', + path: ROOT_PATH, + key: 'showOnCreate', + why: "graded `planned` (`liveness/field.json`): no create surface reads it yet, so a switch offered now would be honoured nowhere (declared = enforced = shown). The row is offered, and this entry deleted, in the change that lands the create surfaces' readers", + }, // Measured, and deliberately NOT recorded: seven `view` keys with no // liveness verdict at any coordinate. `liveness/view.json` cannot hold them: