Skip to content

Commit 574bc7e

Browse files
committed
feat(spec): a field marked searchable: true joins the search set when the object declares no searchableFields
resolveSearchFieldResolution's auto branch now admits every field whose own `searchable` is true, of any type except secret / password / vector (SEARCH_FLAG_EXCLUDED_TYPES) and a virtual field. A declared searchableFields stays the whole set. The $searchFields ingress gate and the lint rule read the same resolution; the lint field-meta projection now carries `searchable`, and the refusal prose that called a non-text type unscannable names the opt-in instead. Claude-Session: https://claude.ai/code/session_01ADHkmSR2TvJTmoYyVtcQv9 Co-authored-by: Claude <noreply@anthropic.com>
1 parent 2f7977c commit 574bc7e

5 files changed

Lines changed: 139 additions & 18 deletions

File tree

‎packages/lint/src/rule-explanations.ts‎

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2480,14 +2480,18 @@ const SEARCHABLE_FIELD_UNSEARCHABLE_EXPLANATION: RuleExplanation = {
24802480
covers: 'which searchableFields entries the runtime refuses',
24812481
paragraphs: [
24822482
SEARCH_FIELDS_ECHO,
2483-
// Held equal to `SEARCHABLE_TEXTUAL_TYPES` + `SEARCHABLE_ENUM_TYPES` by the rule's tests.
2483+
// Held equal to `SEARCHABLE_TEXTUAL_TYPES` + `SEARCHABLE_ENUM_TYPES`, and its flag exclusions to
2484+
// `SEARCH_FLAG_EXCLUDED_TYPES`, by the rule's tests.
24842485
'The allowed set is computed by the function the ingress and the engine consult ' +
24852486
'(`resolveSearchFieldResolution`): the object\'s declared `searchableFields` when it declares ' +
24862487
'them, otherwise the AUTO-DEFAULT set — its text-like columns (text / email / phone / url / ' +
2487-
'autonumber / textarea / markdown / select), never a system/audit column or a hidden field. A ' +
2488-
'`lookup` or `master_detail` column stores only the referenced record\'s id, so it is never a ' +
2489-
'keyword target: to search by the related record\'s title, mirror it onto a stored text field ' +
2490-
'and declare that. Declaring `searchableFields` on the object chooses its set explicitly, and a ' +
2488+
'autonumber / textarea / markdown / select), never a system/audit column or a hidden field, plus ' +
2489+
'every field the object marks `searchable: true`, of any type but `secret` / `password` / ' +
2490+
'`vector`. A `lookup` or `master_detail` column stores only the referenced record\'s id, so the ' +
2491+
'default never picks it and marking it `searchable: true` scans that id, never the title: to ' +
2492+
'search by the related record\'s title, mirror it onto a stored text field and declare that. ' +
2493+
'Declaring `searchableFields` on the object chooses its set explicitly (a field\'s own ' +
2494+
'`searchable` is then not read), and a ' +
24912495
'view then narrows that set, never widens it (ADR-0061). The verdict quotes at most three names ' +
24922496
'of a declared set.',
24932497
VIRTUAL_FIELD_STORAGE,

‎packages/lint/src/validate-searchable-fields.ts‎

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ import {
148148
isCredentialFieldType,
149149
isVirtualSearchField,
150150
SEARCH_AUTO_EXCLUDED_FIELDS,
151+
SEARCH_FLAG_EXCLUDED_TYPES,
151152
type SearchFieldMeta,
152153
} from '@objectstack/spec/data';
153154
import { recordsOf, suggestName } from './object-graph.js';
@@ -258,6 +259,10 @@ function declaredFieldTarget(obj: AnyRec): ObjectSearchTarget | null {
258259
metas[n] = {
259260
type: typeof f.type === 'string' ? f.type : undefined,
260261
hidden: f.hidden === true,
262+
// The field's own opt-in: with no `searchableFields` declared, the
263+
// runtime resolution admits a field marked `searchable: true` (ruling
264+
// record 6573569376), so a narrowing naming it is accepted there.
265+
searchable: f.searchable === true,
261266
};
262267
}
263268
if (names.size === 0) return null;
@@ -515,10 +520,19 @@ export function checkSearchableFieldList(
515520
} else if (meta?.hidden) {
516521
why = 'hidden';
517522
} else if (typeof meta?.type === 'string') {
518-
why = `of type '${meta.type}', which 'search' cannot scan`;
523+
// The runtime admits a field of any type its author marks
524+
// `searchable: true`, except the hard exclusions — so "cannot scan" is
525+
// said only of those, and every other type names the opt-in it lacks.
526+
why = SEARCH_FLAG_EXCLUDED_TYPES.has(meta.type)
527+
? `of type '${meta.type}', which 'search' never scans, even marked \`searchable: true\``
528+
: `of type '${meta.type}' and not marked \`searchable: true\``;
519529
} else {
520530
continue; // no readable type — unresolvable, not wrong (ADR-0072 D1)
521531
}
532+
// Whether the field's own opt-in would admit it — every arm above, a
533+
// system name and `hidden` included, since the flag is asked before the
534+
// auto-default's exclusions (`@objectstack/spec/data` `search-fields.ts`).
535+
const flaggable = typeof meta?.type === 'string' && !SEARCH_FLAG_EXCLUDED_TYPES.has(meta.type);
522536
findings.push({
523537
severity: 'error',
524538
rule: SEARCHABLE_FIELD_UNSEARCHABLE,
@@ -535,7 +549,10 @@ export function checkSearchableFieldList(
535549
hint: isReference
536550
? `Drop "${name}" from this view; to search by the related record's title, mirror it onto ` +
537551
`a stored text field here and declare that instead`
538-
: `Drop "${name}" from this view, or target a text-like field instead`,
552+
: flaggable
553+
? `Mark "${name}" \`searchable: true\` on "${objectName}", drop it from this view, or target ` +
554+
`a text-like field instead`
555+
: `Drop "${name}" from this view, or target a text-like field instead`,
539556
});
540557
}
541558
return findings;

‎packages/metadata-protocol/src/protocol-query-validation.ts‎

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ import type { ObjectStackProtocolImplementation } from './protocol.js';
4949
import { FILTER_LOGICAL_KEYS, ODATA_SPELLING, QUERY_PARAM_NEAR_MISS, invalidSortError, isObjectOfDisabledPackage, isPlainRecord, nearMissKey, objectPackageDisabledError, quotedQueryValue, suggestFieldName } from './protocol.js';
5050
import { objectNotFoundError, relationConditionSites } from '@objectstack/core';
5151
import { collectInternalWriteResponseFields } from './write-response-internal-fields.js';
52-
import { AggregationFunction, DateGranularity, REFERENCE_VALUE_TYPES, SEARCHABLE_ENUM_TYPES, SEARCHABLE_TEXTUAL_TYPES, SEARCH_AUTO_EXCLUDED_FIELDS, apiExposureDenialReason, canServeApiOperation, classifyDottedFilterHead, effectiveOperationsArray, isCredentialFieldType, isFilterAST, isVirtualSearchField, parseFilterAST, referenceTargetOf, resolveEffectiveApiMethods, resolveSearchFieldResolution } from '@objectstack/spec/data';
52+
import { AggregationFunction, DateGranularity, REFERENCE_VALUE_TYPES, SEARCHABLE_ENUM_TYPES, SEARCHABLE_TEXTUAL_TYPES, SEARCH_AUTO_EXCLUDED_FIELDS, SEARCH_FLAG_EXCLUDED_TYPES, apiExposureDenialReason, canServeApiOperation, classifyDottedFilterHead, effectiveOperationsArray, isCredentialFieldType, isFilterAST, isVirtualSearchField, parseFilterAST, referenceTargetOf, resolveEffectiveApiMethods, resolveSearchFieldResolution } from '@objectstack/spec/data';
5353

5454
/**
5555
* [#20802] The nested-relation spelling of a dotted relation path, as the
@@ -1026,17 +1026,31 @@ export function assertSearchFieldsAreSearchable(
10261026
+ "'search' scans — a field outside it cannot be a search target until it is added there.";
10271027
} else {
10281028
const meta = gate.fields[first];
1029+
// The field's own `searchable: true` admits it whatever its name,
1030+
// `hidden` or type, except the hard exclusions — the resolution above
1031+
// asks it before the default's own exclusions (ruling record
1032+
// 6573569376). So the reason names the opt-in the field lacks, and the
1033+
// remedy offers it wherever it would work.
1034+
const hardExcluded = !!meta && typeof meta.type === 'string' && SEARCH_FLAG_EXCLUDED_TYPES.has(meta.type);
10291035
const why = !meta || SEARCH_AUTO_EXCLUDED_FIELDS.has(first)
10301036
? 'a system/audit column, which the default never includes'
10311037
: meta.hidden
10321038
? 'hidden'
1033-
: `type '${meta.type}'`;
1039+
: hardExcluded
1040+
? `type '${meta.type}', which 'search' never scans even when marked 'searchable: true'`
1041+
: `type '${meta.type}'`;
1042+
const flaggable = !!meta && typeof meta.type === 'string' && !hardExcluded;
10341043
detail = `Field '${first}' on object '${object}' is not searchable`
10351044
+ (offenders.length > 1 ? ` (also: ${offenders.slice(1).join(', ')})` : '')
10361045
+ `. With no 'searchableFields' declared, 'search' scans the text-like columns `
1037-
+ `(${[...SEARCHABLE_TEXTUAL_TYPES, ...SEARCHABLE_ENUM_TYPES].join(' / ')}), and '${first}' is `
1046+
+ `(${[...SEARCHABLE_TEXTUAL_TYPES, ...SEARCHABLE_ENUM_TYPES].join(' / ')}) and every field `
1047+
+ `marked 'searchable: true', and '${first}' is `
10381048
+ why
1039-
+ ". Declare 'searchableFields' on the object to choose the searchable set explicitly.";
1049+
+ (flaggable ? ", not marked 'searchable: true'" : '')
1050+
+ (flaggable
1051+
? ". Mark the field 'searchable: true', or declare 'searchableFields' on the object to "
1052+
+ 'choose the searchable set explicitly.'
1053+
: ". Declare 'searchableFields' on the object to choose the searchable set explicitly.");
10401054
}
10411055
const err: any = new Error(detail);
10421056
err.code = 'INVALID_FIELD';

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

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1403,7 +1403,21 @@ export const FieldSchema = lazySchema(() => {
14031403
notNull: z.boolean().optional().describe('Emit a physical NOT NULL on the column (ADR-0113). Absent = the column stays nullable even under `required: true` — the write contract is enforced at the engine, the only sanctioned write path, not by the database. Declaring this over existing null rows is a destructive migration gated by the schema-drift ceremony. Incompatible with `requiredWhen` (a conditional contract cannot be an unconditional column constraint).'),
14041404
}).strict().optional().describe('Physical storage constraints (ADR-0113). Owns the DDL the write contract deliberately does not imply. Absent = no storage-level constraint requested.'),
14051405

1406-
searchable: z.boolean().default(false).describe('Is searchable'),
1406+
/**
1407+
* The field's own search opt-in, read by `resolveSearchFieldResolution`
1408+
* (`search-fields.ts`) on its auto branch only — ruling record 6573569376,
1409+
* letter A: honoured, not retired (ADR-0049). The `$searchFields`
1410+
* ingress allow-list is the same resolved set, so it admits what this key
1411+
* admits.
1412+
*/
1413+
searchable: z.boolean().default(false).describe(
1414+
'Search this field when its object declares no `searchableFields`. The set `search` scans, and the '
1415+
+ 'set a `$searchFields` override may name, is then the type-based default (the text-like and '
1416+
+ 'select columns) plus every field marked `searchable: true`, of any type except '
1417+
+ '`secret`, `password` and `vector`, which stay excluded (a virtual `formula` field has no stored '
1418+
+ 'column, so it is never scanned either). When the object declares `searchableFields`, that list '
1419+
+ 'is the whole search set and this flag is not read (ADR-0061).',
1420+
),
14071421
/**
14081422
* Multi-value empty representation (#9447, maintainer ruling 2026-08-18):
14091423
* an emptied multi-value lookup reads back as `[]`, never `null`. This

‎packages/spec/src/data/search-fields.ts‎

Lines changed: 78 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,18 @@
3434
*
3535
* Resolution precedence (server-side, never client-trusted):
3636
* 1. the object's declared `searchableFields` (filtered to entries that exist
37-
* AND have a stored column to scan — #6674)
38-
* 2. an auto-default: the display/name field + short-text and enum fields.
37+
* AND have a stored column to scan — #6674) — the WHOLE set when it is
38+
* non-empty; no field's own `searchable` flag is read on this branch
39+
* 2. an auto-default: the display/name field + short-text and enum fields,
40+
* plus every field marked `searchable: true` of any type except the hard
41+
* exclusions ({@link SEARCH_FLAG_EXCLUDED_TYPES}) and a virtual field.
42+
*
43+
* The flag's half of (2) is the maintainer's ruling on #29008 (ruling record
44+
* 6573569376, letter A): `FieldSchema.searchable` is honoured, not retired —
45+
* it was a declared, defaulted key that nothing read (ADR-0049), so a field
46+
* the served schema called `searchable: true` was neither scanned nor
47+
* admitted as a `$searchFields` override. ADR-0061 D2's "Field-level
48+
* `searchable` stays pruned" predates the ruling and no longer describes it.
3949
*
4050
* An explicit `$searchFields` override is then INTERSECTED with that allowed
4151
* set — it can narrow the scan, never widen it (`resolveSearchFields`).
@@ -45,6 +55,15 @@
4555
export interface SearchFieldMeta {
4656
type?: string;
4757
hidden?: boolean;
58+
/**
59+
* The field's own search opt-in (`FieldSchema.searchable`). Read on the
60+
* AUTO branch only: with no `searchableFields` declared, `true` brings the
61+
* field into the set whatever its type, except
62+
* {@link SEARCH_FLAG_EXCLUDED_TYPES} and a virtual field. `false` and absent
63+
* are one answer — the key defaults to `false`, so it can widen the
64+
* auto-default and never narrows it.
65+
*/
66+
searchable?: boolean;
4867
options?: Array<{ label?: string; value: unknown } | string> | unknown;
4968
}
5069

@@ -95,6 +114,36 @@ export const SEARCH_AUTO_EXCLUDED_TYPES: ReadonlySet<string> = new Set([
95114
*/
96115
export const SEARCH_VIRTUAL_TYPES: ReadonlySet<string> = new Set(['formula']);
97116

117+
/**
118+
* The HARD exclusions of the field-level opt-in: types a `searchable: true`
119+
* never brings into the auto-default (ruling record 6573569376, letter A).
120+
*
121+
* The flag otherwise admits a field of ANY type — a `code`, `html`, `lookup` or
122+
* `json` column is a stored value a `$icontains` scan can match, and the author
123+
* asked for it, which is the same choice a declared `searchableFields` entry
124+
* makes. These three are refused it anyway, for reasons the author cannot
125+
* waive:
126+
*
127+
* - `secret` / `password` are CREDENTIALS. The engine withholds every
128+
* credential column from the scan whatever the metadata says (ADR-0100), so
129+
* admitting one here would put a name in the #4254 ingress allow-list that
130+
* the engine never scans — the "narrower search answered with a wider one"
131+
* the ingress exists to refuse. `search-fields.test.ts` holds every credential
132+
* type (`MASKED_ON_READ_FIELD_TYPES`) inside this set, as it does for
133+
* `SEARCH_AUTO_EXCLUDED_TYPES`.
134+
* - `vector` is an embedding array: a substring match over it means nothing,
135+
* and it is the heaviest column a scan could touch.
136+
*
137+
* A virtual field ({@link isVirtualSearchField}) is kept out on top of these,
138+
* by the storage fact rather than by this set: it has no column to scan.
139+
*
140+
* Pinned to exactly these three in `search-fields.test.ts`. Exported so the
141+
* two enforcement faces that word a refusal for a flagged field (the ingress
142+
* gate and the linter) say "never, even marked" from this same set instead of
143+
* carrying their own type literal.
144+
*/
145+
export const SEARCH_FLAG_EXCLUDED_TYPES: ReadonlySet<string> = new Set(['secret', 'password', 'vector']);
146+
98147
/**
99148
* Is this field virtual — computed on read, with no stored column for `search`
100149
* to scan? The ONE judgment behind the refusal, exported so the REST ingress
@@ -124,10 +173,31 @@ export interface SearchFieldResolutionOptions {
124173
displayField?: string;
125174
}
126175

176+
/**
177+
* Does the field's own `searchable: true` bring it into the auto-default?
178+
*
179+
* Asked BEFORE the auto-default's own three exclusions (system name, hidden,
180+
* type), because it answers a different question: those say what the default
181+
* does not GUESS, and the flag is the author saying it outright — the per-field
182+
* twin of naming the field in `searchableFields`, which bypasses the same
183+
* three. What the flag cannot do is name a type the platform never scans
184+
* ({@link SEARCH_FLAG_EXCLUDED_TYPES}) or a field with no stored column
185+
* ({@link isVirtualSearchField}). An unreadable `type` is not admitted: the
186+
* hard exclusion cannot be judged without it (fail closed), and the lint
187+
* mirror's stub metadata (`{}`) for registry-injected columns stays out.
188+
*/
189+
function admittedBySearchableFlag(meta: SearchFieldMeta): boolean {
190+
return meta.searchable === true
191+
&& typeof meta.type === 'string'
192+
&& !SEARCH_FLAG_EXCLUDED_TYPES.has(meta.type)
193+
&& !isVirtualSearchField(meta);
194+
}
195+
127196
function autoDefaultFields(fields: Record<string, SearchFieldMeta>, displayField?: string): string[] {
128197
const names = Object.keys(fields).filter((f) => {
129-
if (SEARCH_AUTO_EXCLUDED_FIELDS.has(f)) return false;
130198
const meta = fields[f];
199+
if (meta && admittedBySearchableFlag(meta)) return true;
200+
if (SEARCH_AUTO_EXCLUDED_FIELDS.has(f)) return false;
131201
if (!meta || meta.hidden) return false;
132202
const t = meta.type;
133203
if (!t) return false;
@@ -196,9 +266,11 @@ function autoDefaultFields(fields: Record<string, SearchFieldMeta>, displayField
196266
* `declared` when the object's `searchableFields` (filtered to entries the
197267
* engine can actually scan) is non-empty, `auto` otherwise. The source matters
198268
* to the #4254 ingress gate because the two rejections it explains differ: a
199-
* field missing from a declared list is fixed by adding it there, while a field
200-
* the auto-default skips is excluded by its TYPE and needs `searchableFields`
201-
* declared to become a target.
269+
* field missing from a declared list is fixed by adding it there (its own
270+
* `searchable: true` is not read on that branch), while a field the
271+
* auto-default skips is excluded by its name, `hidden` or TYPE and becomes a
272+
* target by being marked `searchable: true` — unless its type is one of
273+
* {@link SEARCH_FLAG_EXCLUDED_TYPES} — or by `searchableFields` being declared.
202274
*
203275
* TWO filters run on the declared branch, and they are different claims:
204276
*

0 commit comments

Comments
 (0)