Skip to content

Commit f24b991

Browse files
committed
feat(spec): a read-only record_link screen field type — reference and defaultValue required, input keys refused
Claude-Session: https://claude.ai/code/session_0115tbh4XfgivQD2RpHHwdMz Co-authored-by: Claude <noreply@anthropic.com>
1 parent da99a4b commit f24b991

3 files changed

Lines changed: 221 additions & 4 deletions

File tree

‎packages/spec/src/automation/builtin-node-config.zod.ts‎

Lines changed: 83 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -801,6 +801,57 @@ export const SCREEN_FIELD_LOOKUP_REFERENCE_REQUIRED =
801801
+ "offers (e.g. `reference: 'crm_knowledge_article'`). Without it the field renders a picker with nothing to "
802802
+ 'resolve.';
803803

804+
/**
805+
* The read-only record-link member of a screen field's `type` (ruling B on the
806+
* screen-flow result screen): the field SHOWS a record the run already holds the
807+
* id of — by its display name (ADR-0079 `nameField`), as a link to the record's
808+
* page — and submits nothing.
809+
*
810+
* Named `record_link`, not `record`: a screen field's `type` borrows the object
811+
* field vocabulary (`text`, `number`, `lookup`, `file`, …), and `FieldType`
812+
* already spells `'record'` for a name-keyed map of embedded sub-objects. One
813+
* word with two meanings across one field vocabulary is the collision the
814+
* snake_case name avoids, in the shape `master_detail` already has.
815+
*/
816+
export const SCREEN_FIELD_RECORD_LINK_TYPE = 'record_link';
817+
818+
/**
819+
* What a `type: 'record_link'` screen field with no target object is told. It
820+
* names the key and what the link cannot do without it, as the lookup refusal
821+
* does. ⛔ No tracker id in this text (`check:doc-authoring`).
822+
*/
823+
export const SCREEN_FIELD_RECORD_LINK_REFERENCE_REQUIRED =
824+
"A `type: 'record_link'` screen field must declare `reference` — the name of the object the record belongs to "
825+
+ "(e.g. `reference: 'crm_account'`). Without it the field cannot name the record or link to its page.";
826+
827+
/**
828+
* What a `type: 'record_link'` screen field with no `defaultValue` is told: the
829+
* field shows the record whose id its `defaultValue` evaluates to, so without
830+
* one there is never a record to show.
831+
*/
832+
export const SCREEN_FIELD_RECORD_LINK_DEFAULT_VALUE_REQUIRED =
833+
"A `type: 'record_link'` screen field must declare `defaultValue` — the id of the record it shows, usually a CEL "
834+
+ "value envelope over a flow variable (e.g. `defaultValue: { dialect: 'cel', source: 'account_id' }`). The "
835+
+ 'field takes no input, so without it there is never a record to show.';
836+
837+
/**
838+
* The keys a `type: 'record_link'` screen field refuses, each because it
839+
* describes an INPUT and this field takes none: the resume refuses any value
840+
* under its name, so `required` could never be met, and `options`,
841+
* `placeholder`, `min` and `max` would constrain or decorate a control that is
842+
* never drawn.
843+
*/
844+
export const SCREEN_FIELD_RECORD_LINK_REFUSED_KEYS = ['required', 'options', 'placeholder', 'min', 'max'] as const;
845+
846+
/** The refusal of one {@link SCREEN_FIELD_RECORD_LINK_REFUSED_KEYS} key on a `type: 'record_link'` screen field. */
847+
export function screenFieldRecordLinkRefusedKey(key: string): string {
848+
return (
849+
`A \`type: 'record_link'\` screen field shows a record and takes no input, so it cannot declare \`${key}\`: `
850+
+ 'the run refuses any value submitted under its name. Remove the key, or use a `lookup` field to let the user '
851+
+ 'pick a record.'
852+
);
853+
}
854+
804855
/**
805856
* The sentence every refusal of two colliding screen-field options leads with.
806857
*
@@ -909,10 +960,21 @@ export const ScreenFieldConfigSchema = lazySchema(() => strictObject({
909960
* asks (#25692); a `runAs: 'system'` run's write is not judged, as no system
910961
* write is. So a wizard collects its file before the record that will own it
911962
* exists, and writes everything after its last screen.
963+
*
964+
* One member is the opposite of an input: `'record_link'`
965+
* ({@link SCREEN_FIELD_RECORD_LINK_TYPE}). It shows the `reference` record
966+
* whose id `defaultValue` evaluates to — by its display name (ADR-0079
967+
* `nameField`), as a link to the record's page — and submits nothing. Both
968+
* keys are required on it and the input keys are refused (the refinement
969+
* below); the resume refuses any value under its name, so the id it shows is
970+
* never written back into a flow variable. It is how a screen flow ends on a
971+
* result screen that links the records the run created.
912972
*/
913973
type: z.string().optional().describe(
914974
'Input type — an open widget hint (text, number, select, …); `file` renders the platform upload widget and '
915-
+ "the screen resumes with the uploaded file's id, which a later node writes into a `file` field",
975+
+ "the screen resumes with the uploaded file's id, which a later node writes into a `file` field; "
976+
+ '`record_link` shows the `reference` record whose id `defaultValue` evaluates to, by its display name, as a '
977+
+ 'link to its record page, and takes no input',
916978
),
917979
/** Whether the runner requires a value before resume. */
918980
required: z.boolean().optional().describe('Whether a value is required to submit'),
@@ -1000,7 +1062,7 @@ export const ScreenFieldConfigSchema = lazySchema(() => strictObject({
10001062
* the flow and the field), ⛔ never a D2 conversion that would have to invent
10011063
* a target.
10021064
*/
1003-
reference: z.string().optional().describe("Target object name (snake_case) whose records a `type: 'lookup'` field picks from; REQUIRED when `type` is `lookup`"),
1065+
reference: z.string().optional().describe("Target object name (snake_case) whose records a `type: 'lookup'` field picks from, or that a `type: 'record_link'` field's record belongs to; REQUIRED when `type` is `lookup` or `record_link`"),
10041066
}).superRefine((field, ctx) => {
10051067
// Two options whose values read the same as text are ONE option to every
10061068
// reader that addresses them as text — the label translation key and the
@@ -1022,6 +1084,25 @@ export const ScreenFieldConfigSchema = lazySchema(() => strictObject({
10221084
});
10231085
});
10241086
}
1087+
// The read-only record link: it shows the record whose id `defaultValue`
1088+
// evaluates to, of the `reference` object, and takes no input. Both keys it
1089+
// reads are required, and every key that describes an input is refused at
1090+
// that key — each one either could never be met (the resume refuses a value
1091+
// under this field's name, so `required` would dead-end the run) or would
1092+
// decorate a control that is never drawn.
1093+
if (field.type === SCREEN_FIELD_RECORD_LINK_TYPE) {
1094+
if (typeof field.reference !== 'string' || field.reference.trim() === '') {
1095+
ctx.addIssue({ code: 'custom', path: ['reference'], message: SCREEN_FIELD_RECORD_LINK_REFERENCE_REQUIRED });
1096+
}
1097+
if (field.defaultValue === undefined || field.defaultValue === null) {
1098+
ctx.addIssue({ code: 'custom', path: ['defaultValue'], message: SCREEN_FIELD_RECORD_LINK_DEFAULT_VALUE_REQUIRED });
1099+
}
1100+
for (const key of SCREEN_FIELD_RECORD_LINK_REFUSED_KEYS) {
1101+
if (field[key] === undefined) continue;
1102+
ctx.addIssue({ code: 'custom', path: [key], message: screenFieldRecordLinkRefusedKey(key) });
1103+
}
1104+
return;
1105+
}
10251106
// Conditional requirement, not a shape change: the key set is unchanged and
10261107
// `.shape` still enumerates twelve keys. `type` is an open widget hint, so
10271108
// this reads ONE member of it — the member whose whole meaning is "resolve
Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.
2+
3+
/**
4+
* The read-only record-link screen field (`type: 'record_link'`), ruling B on
5+
* the screen-flow result screen.
6+
*
7+
* A screen field that SHOWS a record the run holds the id of and submits
8+
* nothing. The contract is a conditional refinement over the open `type` hint:
9+
* on this member `reference` and `defaultValue` are required, and the keys that
10+
* describe an input (`required`, `options`, `placeholder`, `min`, `max`) are
11+
* refused, each at its own key. Every other member is untouched.
12+
*/
13+
14+
import { describe, expect, it } from 'vitest';
15+
16+
import {
17+
SCREEN_FIELD_RECORD_LINK_DEFAULT_VALUE_REQUIRED,
18+
SCREEN_FIELD_RECORD_LINK_REFERENCE_REQUIRED,
19+
SCREEN_FIELD_RECORD_LINK_REFUSED_KEYS,
20+
SCREEN_FIELD_RECORD_LINK_TYPE,
21+
ScreenConfigSchema,
22+
ScreenFieldConfigSchema,
23+
screenFieldRecordLinkRefusedKey,
24+
} from './builtin-node-config.zod.js';
25+
26+
const LINK = {
27+
name: 'created_account',
28+
label: 'Account',
29+
type: 'record_link',
30+
reference: 'crm_account',
31+
defaultValue: { dialect: 'cel', source: 'account_id' },
32+
} as const;
33+
34+
/** The issues a parse addressed to `key`, or `[]` when it parsed. */
35+
function issuesAt(value: unknown, key: string) {
36+
const r = ScreenFieldConfigSchema.safeParse(value);
37+
return r.success ? [] : r.error.issues.filter((i) => i.path[0] === key);
38+
}
39+
40+
describe("screen field `type: 'record_link'` — a read-only link to a record", () => {
41+
it('is spelled `record_link`, not the `record` the object field vocabulary already uses', () => {
42+
expect(SCREEN_FIELD_RECORD_LINK_TYPE).toBe('record_link');
43+
});
44+
45+
it('accepts the declared shape — a CEL envelope id, a literal id, and the presentation keys', () => {
46+
const accepted = [
47+
LINK,
48+
{ ...LINK, defaultValue: 'acc_0001' },
49+
{ ...LINK, inlineHelpText: 'Opens the account the conversion created.' },
50+
{ ...LINK, visibleWhen: 'create_opportunity == true' },
51+
];
52+
for (const value of accepted) {
53+
const r = ScreenFieldConfigSchema.safeParse(value);
54+
expect(r.success, JSON.stringify(r.success ? null : r.error.issues)).toBe(true);
55+
}
56+
});
57+
58+
it('refuses a missing or blank `reference`, addressed to the key', () => {
59+
for (const reference of [undefined, '', ' ']) {
60+
const value = { ...LINK, reference };
61+
const issues = issuesAt(value, 'reference');
62+
expect(issues.map((i) => i.message), `reference: ${JSON.stringify(reference)}`)
63+
.toEqual([SCREEN_FIELD_RECORD_LINK_REFERENCE_REQUIRED]);
64+
}
65+
});
66+
67+
it('refuses a missing or null `defaultValue`, addressed to the key', () => {
68+
const { defaultValue: _omit, ...withoutDefault } = LINK;
69+
for (const value of [withoutDefault, { ...LINK, defaultValue: null }]) {
70+
expect(issuesAt(value, 'defaultValue').map((i) => i.message))
71+
.toEqual([SCREEN_FIELD_RECORD_LINK_DEFAULT_VALUE_REQUIRED]);
72+
}
73+
});
74+
75+
it('refuses every input key at that key — `required: false` included, since the key itself is the error', () => {
76+
expect([...SCREEN_FIELD_RECORD_LINK_REFUSED_KEYS]).toEqual(['required', 'options', 'placeholder', 'min', 'max']);
77+
const values: Record<(typeof SCREEN_FIELD_RECORD_LINK_REFUSED_KEYS)[number], unknown[]> = {
78+
required: [true, false],
79+
options: [[{ value: 'a', label: 'A' }]],
80+
placeholder: ['Pick one'],
81+
min: [0],
82+
max: [10],
83+
};
84+
for (const key of SCREEN_FIELD_RECORD_LINK_REFUSED_KEYS) {
85+
for (const v of values[key]) {
86+
const issues = issuesAt({ ...LINK, [key]: v }, key);
87+
expect(issues.map((i) => i.message), `${key}: ${JSON.stringify(v)}`)
88+
.toEqual([screenFieldRecordLinkRefusedKey(key)]);
89+
expect(issues[0]!.code).toBe('custom');
90+
}
91+
}
92+
});
93+
94+
it('reports every broken rule of one field at once', () => {
95+
const r = ScreenFieldConfigSchema.safeParse({ name: 'x', type: 'record_link', required: true, placeholder: 'p' });
96+
expect(r.success).toBe(false);
97+
expect(r.error!.issues.map((i) => i.path[0]).sort()).toEqual(['defaultValue', 'placeholder', 'reference', 'required']);
98+
});
99+
100+
it('is refused through the screen node config too, at the field', () => {
101+
const r = ScreenConfigSchema.safeParse({ fields: [{ ...LINK, required: true }] });
102+
expect(r.success).toBe(false);
103+
expect(r.error!.issues.some((i) => i.path.join('.') === 'fields.0.required')).toBe(true);
104+
expect(ScreenConfigSchema.safeParse({ fields: [LINK] }).success).toBe(true);
105+
});
106+
107+
it('leaves every other widget hint alone — the input keys still parse on them', () => {
108+
for (const type of [undefined, 'text', 'number', 'select', 'record']) {
109+
const r = ScreenFieldConfigSchema.safeParse({
110+
name: 'x', ...(type ? { type } : {}), required: true, placeholder: 'p', min: 0, max: 1,
111+
options: [{ value: 'a', label: 'A' }],
112+
});
113+
expect(r.success, `type: ${String(type)}`).toBe(true);
114+
}
115+
});
116+
117+
it('prints no tracker id at the author, and names the key it refuses', () => {
118+
const texts = [
119+
SCREEN_FIELD_RECORD_LINK_REFERENCE_REQUIRED,
120+
SCREEN_FIELD_RECORD_LINK_DEFAULT_VALUE_REQUIRED,
121+
...SCREEN_FIELD_RECORD_LINK_REFUSED_KEYS.map(screenFieldRecordLinkRefusedKey),
122+
];
123+
for (const text of texts) expect(text).not.toMatch(/#\d{3,5}\b/);
124+
expect(SCREEN_FIELD_RECORD_LINK_REFERENCE_REQUIRED).toContain('`reference`');
125+
expect(SCREEN_FIELD_RECORD_LINK_DEFAULT_VALUE_REQUIRED).toContain('`defaultValue`');
126+
expect(screenFieldRecordLinkRefusedKey('min')).toContain('`min`');
127+
});
128+
});

‎packages/spec/src/contracts/automation-service.ts‎

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,12 @@ export interface ScreenFieldSpec {
279279
* `'file'` (#25801) takes the id of an uploaded `sys_file` — the client
280280
* renders the platform upload widget and answers with the id the upload
281281
* minted, never the expanded `{ id, name, url, … }` read form.
282+
*
283+
* One member is not an input at all: `'record_link'` shows the
284+
* {@link reference} record whose id {@link defaultValue} carries (served
285+
* already evaluated) by its display name, as a link to its record page.
286+
* The client submits nothing for it, and the server refuses any value sent
287+
* under its name on resume, so the id is never bound to a flow variable.
282288
*/
283289
type?: string;
284290
required?: boolean;
@@ -309,8 +315,10 @@ export interface ScreenFieldSpec {
309315
*/
310316
inlineHelpText?: string;
311317
/**
312-
* Object whose records a `type: 'lookup'` field picks from (#17306) —
313-
* `FieldSchema.reference`'s spelling.
318+
* Object whose records a `type: 'lookup'` field picks from (#17306), or
319+
* that a `type: 'record_link'` field's record belongs to —
320+
* `FieldSchema.reference`'s spelling. Required on both by
321+
* `ScreenFieldConfigSchema`.
314322
*
315323
* Optional HERE and required on the authoring side: `ScreenFieldConfigSchema`
316324
* refuses a `type: 'lookup'` field that declares no `reference` (maintainer

0 commit comments

Comments
 (0)