Skip to content

Commit ed082e3

Browse files
committed
spec(data): name the served name-only reference value and the display name it carries
The referenceNameVisible describe now names the ADR-0079 display name the engine resolves (nameField, else displayNameField, else the derived title field) and every case objectql serves the Record # floor in. The served { id, name, readRefused: true } gets a closed ReferenceNameOnlyValueSchema, joined into the expanded lookup value union, and the engine's ReferenceNameOnlyValue type now derives from it. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01JQwxbahxR9HAJnTs7UKhmn
1 parent 81cd9eb commit ed082e3

6 files changed

Lines changed: 115 additions & 31 deletions

File tree

‎packages/objectql/src/engine-reference-name-visible.ts‎

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -65,23 +65,15 @@
6565
*/
6666

6767
import { isTitleEligible, resolveDisplayField, resolveRecordDisplayName } from '@objectstack/spec/data';
68+
// The value a `referenceNameVisible` reference is served as when the reader
69+
// was refused its target. Derived from the spec's `ReferenceNameOnlyValueSchema`,
70+
// which owns the shape; the engine never declares its own copy.
71+
import type { ReferenceNameOnlyValue } from '@objectstack/spec/data';
6872
import type { ExecutionContext } from '@objectstack/spec/kernel';
6973
import { withoutOperationPrivateKeys } from '@objectstack/core';
7074
import type { ObjectQL } from './engine.js';
7175
import { isReadRefusal } from './engine-file-reference-hydration.js';
7276

73-
/**
74-
* The value a `referenceNameVisible` reference is served as when the reader
75-
* was refused its target: the id the referencing row holds, the target's
76-
* resolved display name, and the refusal said in-band. Read-only by
77-
* construction: the stored form of a reference is the bare id alone.
78-
*/
79-
export interface ReferenceNameOnlyValue {
80-
id: string;
81-
name: string;
82-
readRefused: true;
83-
}
84-
8577
/**
8678
* The `ObjectQL` members {@link serveReferenceNames} reads, every one of them
8779
* and no other, each typed AS the class member. See the module header of

‎packages/spec/scripts/strictness-ledger.test.ts‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,9 +130,10 @@ describe('site counting reads the AST, not the source text', () => {
130130
// from `field.zod.ts`. As with the chart count above, the number is
131131
// incidental — the assertion that carries the meaning is the idiom read.
132132
// 3 → 4 at #22593, which ADDED `FileRefusedValueSchema` (a strictObject
133-
// site) — the count is still incidental.
133+
// site) — the count is still incidental. 4 → 5 at #29579, which ADDED
134+
// `ReferenceNameOnlyValueSchema` (a strictObject site).
134135
const fv = analyzeSites(at('data/field-value.zod.ts'));
135-
expect(fv).toHaveLength(4);
136+
expect(fv).toHaveLength(5);
136137
expect(fv.find((s) => s.name === 'FileValueSchema')?.idiom).toBe('z.looseObject');
137138
});
138139
});

‎packages/spec/src/data/field-value.test.ts‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import {
3232
referenceCarrierOf,
3333
LocationValueSchema,
3434
FileRefusedValueSchema,
35+
ReferenceNameOnlyValueSchema,
3536
} from './field-value.zod';
3637
import { findClosestMatches } from '../shared/suggestions.zod';
3738

@@ -313,6 +314,27 @@ describe('valueSchemaFor — stored form (field-zoo reality)', () => {
313314
ok({ type: 'lookup' }, 'acc_1', 'expanded'); // unresolvable ids stay ids
314315
});
315316

317+
it('a reader refused the target of a referenceNameVisible field reads the NAMED name-only value', () => {
318+
// The served `{ id, name, readRefused: true }`, per element on a multi-value field.
319+
for (const type of ['lookup', 'user']) {
320+
ok({ type }, { id: 'acc_1', name: 'Acme', readRefused: true }, 'expanded');
321+
}
322+
ok({ type: 'lookup', multiple: true }, [{ id: 'acc_1', name: 'Record #acc_1', readRefused: true }, 'acc_2'], 'expanded');
323+
// Closed on its own: the marker is a literal `true`, the id is a record id,
324+
// the name is present, and nothing else of the target rides on it.
325+
const parse = (v: unknown) => ReferenceNameOnlyValueSchema.safeParse(v);
326+
expect(parse({ id: 'acc_1', name: 'Acme', readRefused: true }).success).toBe(true);
327+
expect(parse({ id: 'acc_1', name: 'Acme', readRefused: false }).success).toBe(false);
328+
expect(parse({ id: 'acc_1', readRefused: true }).success).toBe(false);
329+
expect(parse({ id: 'acc_1', name: '', readRefused: true }).success).toBe(false);
330+
expect(parse({ id: '{"id":"acc_1"}', name: 'Acme', readRefused: true }).success).toBe(false);
331+
const widened = parse({ id: 'acc_1', name: 'Acme', readRefused: true, owner: 'usr_1' });
332+
expect(widened.success).toBe(false);
333+
expect(widened.error?.issues.map((i) => i.code)).toContain('unrecognized_keys');
334+
// Read-only: the STORED form stays the bare id alone.
335+
bad({ type: 'lookup' }, { id: 'acc_1', name: 'Acme', readRefused: true });
336+
});
337+
316338
it('a SERIALIZED embedded record is not an id, in either form', () => {
317339
// The shape the ADR-0104 D1 scan's own header names — "a `lookup` holding
318340
// an expanded record object" — as it actually reaches a SQL deployment: as

‎packages/spec/src/data/field-value.zod.ts‎

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -685,6 +685,51 @@ export const ReferenceIdValueSchema = lazySchema(() =>
685685
);
686686
export type ReferenceIdValue = z.input<typeof ReferenceIdValueSchema>;
687687

688+
/**
689+
* Reference value served to a reader REFUSED the record it points at, on a
690+
* `lookup` or `user` field that declares `referenceNameVisible` — an
691+
* `expanded` read form, beside the still-bare id and the expanded record.
692+
*
693+
* `$expand` on such a field answers a target the reader may not read (the
694+
* object's read gate or its row scope refuses it) with the id the referencing
695+
* record holds, the target's ADR-0079 display name, and `readRefused: true`,
696+
* per element on a `multiple: true` field. `name` is what
697+
* `resolveRecordDisplayName` answers for the target (its `nameField`, else its
698+
* `displayNameField`, else the derived title field), or the `Record #` floor
699+
* with the id where a field-level rule on that field holds — the field's own
700+
* `referenceNameVisible` description lists those cases. The marker is the
701+
* refusal said in-band, the `metadataRefused` precedent of
702+
* {@link FileRefusedValueSchema}: a renderer tells this value from a target
703+
* the reader expanded with a narrow projection, shows the name as text and
704+
* links nothing.
705+
*
706+
* Read-only by construction: the STORED form is {@link ReferenceIdValueSchema}
707+
* alone, so this object is never a value a record write accepts. Closed, so
708+
* nothing else of the target can ride on it. The expanded union keeps its open
709+
* record member, so naming this shape accepts nothing that was refused before.
710+
*/
711+
export const ReferenceNameOnlyValueSchema = lazySchema(() => strictObject(
712+
{
713+
surface: 'this name-only reference value',
714+
// Customer-facing text: no issue ids (the anchors are in the JSDoc above).
715+
history: 'A name-only reference value is served by the platform and never written: it carries the '
716+
+ 'id the record holds, the referenced record\'s display name and the refusal marker, nothing else.',
717+
},
718+
{
719+
id: ReferenceIdValueSchema.describe('The id of the referenced record, as the referencing record holds it'),
720+
name: z.string().min(1).describe(
721+
'The referenced record\'s display name (its object\'s `nameField`, else `displayNameField`, else the '
722+
+ 'derived title field), or the `Record #` floor with the id where a field-level rule on that field holds',
723+
),
724+
readRefused: z.literal(true).describe(
725+
'The reader was refused the referenced record (the object\'s read gate or its row scope): only its '
726+
+ 'id and display name are served, and the name links nothing. Distinct from an expanded record and '
727+
+ 'from a bare id.',
728+
),
729+
},
730+
));
731+
export type ReferenceNameOnlyValue = z.input<typeof ReferenceNameOnlyValueSchema>;
732+
688733
function optionCodes(def: ValueShapeFieldDef): string[] {
689734
if (!Array.isArray(def.options)) return [];
690735
return def.options.map((o) => (typeof o === 'object' && o !== null ? String(o.value) : String(o)));
@@ -722,8 +767,11 @@ export function valueSchemaFor(def: ValueShapeFieldDef, form: ValueForm = 'store
722767
// Expanded form: `$expand` replaces the id in place with the related
723768
// record object (objectql engine `expandRelatedRecords`). The record's
724769
// own shape is that object's contract, not this field's — hence open.
770+
// A reader refused the target on a `referenceNameVisible` field is
771+
// served the named name-only value instead; the open member already
772+
// accepted it, so naming it changes no verdict.
725773
return form === 'expanded'
726-
? z.union([ReferenceIdValueSchema, z.record(z.string(), z.unknown())])
774+
? z.union([ReferenceIdValueSchema, ReferenceNameOnlyValueSchema, z.record(z.string(), z.unknown())])
727775
: ReferenceIdValueSchema;
728776
}
729777
if (FILE_REFERENCE_TYPES.has(t)) {

‎packages/spec/src/data/field.zod.ts‎

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1733,19 +1733,28 @@ export const FieldSchema = lazySchema(() => {
17331733
* Declared per referencing field by the application author, never on the
17341734
* target object: the application decides whose names its own pages reveal.
17351735
* `true` declares that a principal who can read the record carrying this
1736-
* field MAY see, for the record this field points at, its display name (the
1737-
* target object's `nameField` value, ADR-0079) and its id, even when that
1738-
* principal cannot read the target record. Nothing else of the target:
1736+
* field MAY see, for the record this field points at, its display name and
1737+
* its id, even when that principal cannot read the target record. The name
1738+
* is the ADR-0079 D4 display name `resolveRecordDisplayName` answers: the
1739+
* target object's `nameField`, else its `displayNameField`, else the derived
1740+
* title field. The served value is `ReferenceNameOnlyValueSchema`
1741+
* (`field-value.zod.ts`). Nothing else of the target:
17391742
* `$expand` on this field MUST return the same name and id only, the field's
17401743
* own `displayField` MUST NOT widen what is shown, and the renderer shows the
17411744
* name as text with no link to the target record. A principal who can read
17421745
* the target is served exactly what it is served without the key.
17431746
*
17441747
* The key lifts the RECORD-level refusal only. A field-level rule on the
1745-
* name field itself still holds: when the reader's field-level security
1746-
* keeps that field from it, the field declares a `maskingRule`, or it is a
1747-
* formula reading through another reference, the name served is the
1748-
* ADR-0079 floor (`Record #` and the id).
1748+
* name field itself still holds, and the engine reads that field only where
1749+
* it computes nothing the security layer owns. The name served is the
1750+
* ADR-0079 floor (`Record #` and the id) in five cases (objectql's
1751+
* `servableNameField`): the reader's field-level security keeps
1752+
* that field from it; the field declares a `maskingRule`; it is a formula
1753+
* reading through another reference; an explicit `nameField` (or
1754+
* `displayNameField`) points at a column that is neither title-typed nor
1755+
* `autonumber`; or no field-level answer can be had for the reader. A
1756+
* target with no resolvable or no non-empty name reads as the same floor,
1757+
* as it does for every reader.
17491758
*
17501759
* Absent or `false` keeps the restricted-reference posture: a lookup whose
17511760
* target the reader cannot read shows no name. Valid on `lookup` and on
@@ -1755,14 +1764,18 @@ export const FieldSchema = lazySchema(() => {
17551764
referenceNameVisible: z.boolean().optional().describe(
17561765
'Declared name exposure (`lookup` and `user` fields only). TRUE declares that a principal who can '
17571766
+ 'read the record carrying this field may see the referenced record\'s display name (the target '
1758-
+ 'object\'s `nameField` value) and id even when that principal cannot read the referenced record. '
1759-
+ 'Served on `$expand`: a target the reader is refused (the object\'s read gate or its row scope) '
1760-
+ 'answers `{ id, name, readRefused: true }`, per element on a multi-value field; an unexpanded read '
1767+
+ 'object\'s `nameField`, else its `displayNameField`, else the derived title field) and id even when '
1768+
+ 'that principal cannot read the referenced record. Served on `$expand`: a target the reader is refused '
1769+
+ '(the object\'s read gate or its row scope) answers `{ id, name, readRefused: true }` '
1770+
+ '(`ReferenceNameOnlyValueSchema`), per element on a multi-value field; an unexpanded read '
17611771
+ 'answers the stored id, as for every reader. Nothing else of the target: `$expand` on this field '
17621772
+ 'returns the same name and id only, the field\'s `displayField` does not widen it, and the name '
1763-
+ 'renders as text with no link to the target. A field-level rule on the name field still holds: '
1764-
+ 'when the reader may not read that field, it is masked, or it is a formula reading through another '
1765-
+ 'reference, the name is the `Record #` floor with the id. A principal who can read the target is '
1773+
+ 'renders as text with no link to the target. A field-level rule on the name field still holds, and '
1774+
+ 'the name field is read only where nothing the security layer owns must be computed: the name is the '
1775+
+ '`Record #` floor with the id when the reader may not read that field, it declares a `maskingRule`, '
1776+
+ 'it is a formula reading through another reference, an explicit `nameField` points at a column that '
1777+
+ 'is neither title-typed nor autonumber, or no field-level answer can be had for the reader. A target '
1778+
+ 'with no resolvable or no non-empty name reads as the same floor. A principal who can read the target is '
17661779
+ 'served exactly what it is served without the key. Absent or false keeps the restricted-reference '
17671780
+ 'posture for a target the reader cannot read. Declared on the referencing field only; there is no '
17681781
+ 'target-object switch. Refused on any other type.'

‎packages/spec/src/type-alias-convention.pin.test.ts‎

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ import type * as M197 from './api/push-delivery.zod.js';
289289
import type * as M198 from './system/push-device.zod.js';
290290

291291
// ---------------------------------------------------------------------------
292-
// 818 isomorphic aliases: `z.input` === `z.infer`, so no `XParsed` is declared.
292+
// 819 isomorphic aliases: `z.input` === `z.infer`, so no `XParsed` is declared.
293293
//
294294
// That number is machine-checked, not hand-kept. The runtime companion at the
295295
// bottom of this file recomputes the pin count from the source and asserts that
@@ -885,6 +885,7 @@ export type Iso_data_fieldValue__FileValueSchema = Assert<Eq< z.input< typeof M1
885885
export type Iso_data_fieldValue__InstantValueSchema = Assert<Eq< z.input< typeof M178.InstantValueSchema >, z.infer< typeof M178.InstantValueSchema > >>;
886886
export type Iso_data_fieldValue__LocationValueSchema = Assert<Eq< z.input< typeof M178.LocationValueSchema >, z.infer< typeof M178.LocationValueSchema > >>;
887887
export type Iso_data_fieldValue__ReferenceIdValueSchema = Assert<Eq< z.input< typeof M178.ReferenceIdValueSchema >, z.infer< typeof M178.ReferenceIdValueSchema > >>;
888+
export type Iso_data_fieldValue__ReferenceNameOnlyValueSchema = Assert<Eq< z.input< typeof M178.ReferenceNameOnlyValueSchema >, z.infer< typeof M178.ReferenceNameOnlyValueSchema > >>;
888889

889890
// data/field.zod.ts
890891
// #8993 partial masking (`FieldMaskingKeepSchema`): keepHead/keepTail are plain
@@ -1762,7 +1763,7 @@ describe('ADR-0122 type-alias convention', () => {
17621763
// this title and the section header above the pin list — are now asserted
17631764
// against the recomputed count below, so neither can go stale without a red
17641765
// test naming it.
1765-
it('still declares all 818 isomorphic pins', () => {
1766+
it('still declares all 819 isomorphic pins', () => {
17661767
// The truth of each pin is proved by tsc, not here — an `Assert<Eq<...>>`
17671768
// that stops holding is a compile error with the alias named. What tsc
17681769
// cannot notice is a pin that was DELETED: removing the assertion removes
@@ -2752,7 +2753,14 @@ describe('ADR-0122 type-alias convention', () => {
27522753
// required and optional strings, enums, a boolean and ISO instants, no
27532754
// default and no transform (Iso_system_pushDevice__UserDeviceSchema).
27542755
// +1 added.
2755-
expect(pins).toHaveLength(818);
2756+
// 818 -> 819 is #29579: the new exported `ReferenceNameOnlyValueSchema`
2757+
// (the expanded read form a reader refused the target of a
2758+
// `referenceNameVisible` field is served) is a closed
2759+
// `{ id, name, readRefused: true }` with no default and no transform in
2760+
// its tree, so it is pinned here
2761+
// (Iso_data_fieldValue__ReferenceNameOnlyValueSchema) rather than given a
2762+
// `ReferenceNameOnlyValueParsed` synonym. +1 added.
2763+
expect(pins).toHaveLength(819);
27562764

27572765
// The count is stated in PROSE twice as well — this case's title and the
27582766
// section header above the pin list — and until commit c6b05c76a nothing read either

0 commit comments

Comments
 (0)