Skip to content

Commit a6f469a

Browse files
committed
refactor: the resolved-picklist-options mark lives in metadata-core, outside the lean objectql/core boundary
Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01FEkQ5nFWpcGdLrSDAf6vS9
1 parent 3e83c8d commit a6f469a

8 files changed

Lines changed: 103 additions & 45 deletions

File tree

‎.changeset/26886-picklist-diagnostics-authored-shape.md‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
---
2+
'@objectstack/metadata-core': patch
23
'@objectstack/metadata-protocol': patch
34
'@objectstack/objectql': patch
45
---
@@ -12,4 +13,4 @@ A select field that names a shared list (`picklist: 'industry'`) is served with
1213

1314
- **The rule stands.** A field that authors both `picklist` and `options` is still reported, with the same message and severity, at `fields.NAME.options`.
1415
- **What `/meta` serves is unchanged.** A picklist-bound field is still served with `picklist` and the resolved `options`.
15-
- **How the two are told apart.** The picklist resolution marks the options array it derives; `@objectstack/metadata-protocol` exports `markResolvedPicklistOptions` and `isResolvedPicklistOptions`, and the diagnostics leave a marked array out of the judgement. The mark is not part of any response or stored row.
16+
- **How the two are told apart.** The picklist resolution marks the options array it derives; `@objectstack/metadata-core` exports `markResolvedPicklistOptions` and `isResolvedPicklistOptions`, and the diagnostics leave a marked array out of the judgement. The mark is not part of any response or stored row.

‎packages/metadata-core/src/index.ts‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,3 +133,9 @@ export * from './object-field-type.js';
133133
// `view` write in `@objectstack/metadata-protocol`; both read this one rule, so
134134
// a form withdrawn by either declared switch is withdrawn everywhere.
135135
export * from './anonymous-form-intake.js';
136+
137+
// [#26886] The mark on an `options` array resolved from a shared picklist,
138+
// shared by the resolution (`@objectstack/objectql`'s lean core closure) and the
139+
// load-time diagnostics (`@objectstack/metadata-protocol`), so the diagnostics
140+
// judge a field as its author wrote it.
141+
export * from './resolved-picklist-options.js';
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.
2+
3+
/**
4+
* #26886 — the mark on options resolved from a shared picklist rides the array
5+
* itself and nothing else: never a JSON key, never on a copy. A copy reads as
6+
* authored, so a reader of it reports a diagnostic rather than missing one.
7+
*/
8+
import { describe, expect, it } from 'vitest';
9+
import { isResolvedPicklistOptions, markResolvedPicklistOptions } from './resolved-picklist-options.js';
10+
11+
describe('resolved picklist options mark', () => {
12+
it('marks the array it is given, in place, and only that array', () => {
13+
const options = [{ label: 'Tech', value: 'tech' }];
14+
expect(markResolvedPicklistOptions(options)).toBe(options);
15+
expect(isResolvedPicklistOptions(options)).toBe(true);
16+
expect(isResolvedPicklistOptions(markResolvedPicklistOptions(options))).toBe(true);
17+
expect(isResolvedPicklistOptions([{ label: 'Tech', value: 'tech' }])).toBe(false);
18+
expect(isResolvedPicklistOptions(undefined)).toBe(false);
19+
});
20+
21+
it('is invisible to JSON and to key enumeration', () => {
22+
const options = markResolvedPicklistOptions([{ label: 'Tech', value: 'tech' }]);
23+
expect(JSON.stringify({ options })).toBe('{"options":[{"label":"Tech","value":"tech"}]}');
24+
expect(Object.keys(options)).toEqual(['0']);
25+
expect(Object.getOwnPropertySymbols(options).map((s) => Object.getOwnPropertyDescriptor(options, s)?.enumerable)).toEqual([false]);
26+
});
27+
28+
it('does not survive a copy of the array', () => {
29+
const options = markResolvedPicklistOptions([{ label: 'Tech', value: 'tech' }]);
30+
expect(isResolvedPicklistOptions(options.map((o) => ({ ...o })))).toBe(false);
31+
expect(isResolvedPicklistOptions([...options])).toBe(false);
32+
expect(isResolvedPicklistOptions(JSON.parse(JSON.stringify(options)))).toBe(false);
33+
});
34+
35+
it('survives a copy of the field that holds it', () => {
36+
const field = { picklist: 'industry', options: markResolvedPicklistOptions([{ label: 'Tech', value: 'tech' }]) };
37+
expect(isResolvedPicklistOptions({ ...field }.options)).toBe(true);
38+
});
39+
});
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.
2+
3+
/**
4+
* [#26886] The mark on an `options` array the runtime RESOLVED from a shared
5+
* picklist, as opposed to one an author wrote on the field.
6+
*
7+
* A field authors `picklist: '<name>'` and no `options`; every object read
8+
* serves it with the list's options written beside `picklist` (the registry's
9+
* picklist resolution in `@objectstack/objectql`). The load-time diagnostics in
10+
* `@objectstack/metadata-protocol` judge what the author wrote, so the field
11+
* schema's rule refusing `picklist` and `options` together must not read the
12+
* copy the runtime wrote. The resolution marks the array it derived and the
13+
* diagnostics leave only a marked array out.
14+
*
15+
* Here because both sides need the one spelling: the diagnostics live in
16+
* `@objectstack/metadata-protocol`, which `@objectstack/objectql` depends on,
17+
* and the resolution sits in the lean `@objectstack/objectql/core` closure,
18+
* which must not import `@objectstack/metadata-protocol` (ADR-0076 D2). Both
19+
* already declare this package.
20+
*
21+
* The mark is a non-enumerable property, so no response, stored row or JSON
22+
* key ever carries it, and it is keyed with `Symbol.for` so every loaded copy
23+
* of a package reads the one mark. A copy of the array (`.map`, a spread, a
24+
* JSON round trip) does not carry it: whoever reads the copy sees authored
25+
* options, so the failure direction is a reported diagnostic, never a missed one.
26+
*/
27+
28+
const RESOLVED_PICKLIST_OPTIONS = Symbol.for('@objectstack/metadata-core:resolved-picklist-options');
29+
30+
/**
31+
* Mark an `options` array as resolved from a shared picklist rather than
32+
* authored on the field. Returns the same array.
33+
*/
34+
export function markResolvedPicklistOptions<T extends object>(options: T): T {
35+
if (!Object.prototype.hasOwnProperty.call(options, RESOLVED_PICKLIST_OPTIONS)) {
36+
Object.defineProperty(options, RESOLVED_PICKLIST_OPTIONS, { value: true });
37+
}
38+
return options;
39+
}
40+
41+
/** `true` when `options` is an array {@link markResolvedPicklistOptions} marked. */
42+
export function isResolvedPicklistOptions(options: unknown): boolean {
43+
return Array.isArray(options)
44+
&& (options as unknown as Record<symbol, unknown>)[RESOLVED_PICKLIST_OPTIONS] === true;
45+
}

‎packages/metadata-protocol/src/index.ts‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,8 +164,6 @@ export {
164164
computeViewReferenceDiagnostics,
165165
decorateMetadataItem,
166166
decorateMetadataItems,
167-
isResolvedPicklistOptions,
168-
markResolvedPicklistOptions,
169167
} from './metadata-diagnostics.js';
170168
export type { MetadataDiagnostics } from './metadata-diagnostics.js';
171169

‎packages/metadata-protocol/src/metadata-diagnostics.resolved-picklist-options.test.ts‎

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,8 @@
2020
* unmarked one with the same JSON are two verdicts.
2121
*/
2222
import { describe, expect, it } from 'vitest';
23-
import {
24-
computeMetadataDiagnostics,
25-
decorateMetadataItem,
26-
isResolvedPicklistOptions,
27-
markResolvedPicklistOptions,
28-
} from './metadata-diagnostics.js';
23+
import { markResolvedPicklistOptions } from '@objectstack/metadata-core';
24+
import { computeMetadataDiagnostics, decorateMetadataItem } from './metadata-diagnostics.js';
2925

3026
const BOTH_KEYS = '`picklist` and `options` cannot both be declared';
3127

@@ -82,12 +78,4 @@ describe('diagnostics — options resolved from a shared picklist', () => {
8278
expect(JSON.parse(JSON.stringify(served.fields.industry))).toEqual(industry(authored()));
8379
expect(Object.keys(served.fields.industry.options)).toEqual(['0']);
8480
});
85-
86-
it('a copy of a marked array is unmarked: the failure direction is the old error, never a missed one', () => {
87-
const options = resolved();
88-
expect(isResolvedPicklistOptions(options)).toBe(true);
89-
expect(isResolvedPicklistOptions(options.map((o) => ({ ...o })))).toBe(false);
90-
expect(isResolvedPicklistOptions(JSON.parse(JSON.stringify(options)))).toBe(false);
91-
expect(isResolvedPicklistOptions([...options])).toBe(false);
92-
});
9381
});

‎packages/metadata-protocol/src/metadata-diagnostics.ts‎

Lines changed: 8 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ import { redactMetadataItem } from './metadata-redaction.js';
4141
// runtime gate's own answer, so the publish verdict below is re-spelled
4242
// against the same prefix the gate wrote it with.
4343
import { stackKeyForType } from '@objectstack/lint/runtime';
44+
// [#26886] The resolution's mark on options it derived from a shared picklist.
45+
import { isResolvedPicklistOptions } from '@objectstack/metadata-core';
4446
import type { RuntimeAuthoringIssue } from '@objectstack/spec/api';
4547

4648
/**
@@ -187,33 +189,12 @@ function copyDiagnostics(verdict: MetadataDiagnostics): MetadataDiagnostics {
187189
// every picklist-bound field of every app.
188190
//
189191
// The resolution therefore MARKS the options array it derived
190-
// ({@link markResolvedPicklistOptions}), and only a marked array is left out
191-
// here. A field that authored its own `options` beside `picklist` arrives
192-
// unmarked and is still flagged, with the same message and severity. The mark
193-
// is a non-enumerable property, so no response, stored row or memo key ever
194-
// carries it, and it is keyed with `Symbol.for` so every loaded copy of this
195-
// package reads the one mark. A copy of the array (`.map`, a JSON round trip)
196-
// drops it, and the field is then judged with its `options`: the failure
197-
// direction is the old false error, never a missed one.
198-
199-
const RESOLVED_PICKLIST_OPTIONS = Symbol.for('@objectstack/metadata-protocol:resolved-picklist-options');
200-
201-
/**
202-
* Mark an `options` array as resolved from a shared picklist rather than
203-
* authored on the field. Returns the same array.
204-
*/
205-
export function markResolvedPicklistOptions<T extends object>(options: T): T {
206-
if (!Object.prototype.hasOwnProperty.call(options, RESOLVED_PICKLIST_OPTIONS)) {
207-
Object.defineProperty(options, RESOLVED_PICKLIST_OPTIONS, { value: true });
208-
}
209-
return options;
210-
}
211-
212-
/** `true` when `options` is an array {@link markResolvedPicklistOptions} marked. */
213-
export function isResolvedPicklistOptions(options: unknown): boolean {
214-
return Array.isArray(options)
215-
&& (options as unknown as Record<symbol, unknown>)[RESOLVED_PICKLIST_OPTIONS] === true;
216-
}
192+
// (`markResolvedPicklistOptions`, `@objectstack/metadata-core`), and only a
193+
// marked array is left out here. A field that authored its own `options`
194+
// beside `picklist` arrives unmarked and is still flagged, with the same
195+
// message and severity. The mark is a non-enumerable property, so it is no
196+
// part of the memo key either: the key is the content of the candidate the
197+
// mark has already shaped.
217198

218199
function withoutResolvedOptions(field: unknown): unknown {
219200
if (!field || typeof field !== 'object') return field;

‎packages/objectql/src/picklist-resolution.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
// The mark that tells the load-time diagnostics these options were resolved
3535
// here, not authored: they judge what the author wrote, and the field schema
3636
// refuses `picklist` and `options` together.
37-
import { isResolvedPicklistOptions, markResolvedPicklistOptions } from '@objectstack/metadata-protocol';
37+
import { isResolvedPicklistOptions, markResolvedPicklistOptions } from '@objectstack/metadata-core';
3838

3939
/** One option, as `SelectOptionSchema` declares it (only `value` is read here). */
4040
export interface PicklistOptionLike {

0 commit comments

Comments
 (0)