|
34 | 34 | * |
35 | 35 | * Resolution precedence (server-side, never client-trusted): |
36 | 36 | * 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. |
39 | 49 | * |
40 | 50 | * An explicit `$searchFields` override is then INTERSECTED with that allowed |
41 | 51 | * set — it can narrow the scan, never widen it (`resolveSearchFields`). |
|
45 | 55 | export interface SearchFieldMeta { |
46 | 56 | type?: string; |
47 | 57 | 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; |
48 | 67 | options?: Array<{ label?: string; value: unknown } | string> | unknown; |
49 | 68 | } |
50 | 69 |
|
@@ -95,6 +114,36 @@ export const SEARCH_AUTO_EXCLUDED_TYPES: ReadonlySet<string> = new Set([ |
95 | 114 | */ |
96 | 115 | export const SEARCH_VIRTUAL_TYPES: ReadonlySet<string> = new Set(['formula']); |
97 | 116 |
|
| 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 | + |
98 | 147 | /** |
99 | 148 | * Is this field virtual — computed on read, with no stored column for `search` |
100 | 149 | * to scan? The ONE judgment behind the refusal, exported so the REST ingress |
@@ -124,10 +173,31 @@ export interface SearchFieldResolutionOptions { |
124 | 173 | displayField?: string; |
125 | 174 | } |
126 | 175 |
|
| 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 | + |
127 | 196 | function autoDefaultFields(fields: Record<string, SearchFieldMeta>, displayField?: string): string[] { |
128 | 197 | const names = Object.keys(fields).filter((f) => { |
129 | | - if (SEARCH_AUTO_EXCLUDED_FIELDS.has(f)) return false; |
130 | 198 | const meta = fields[f]; |
| 199 | + if (meta && admittedBySearchableFlag(meta)) return true; |
| 200 | + if (SEARCH_AUTO_EXCLUDED_FIELDS.has(f)) return false; |
131 | 201 | if (!meta || meta.hidden) return false; |
132 | 202 | const t = meta.type; |
133 | 203 | if (!t) return false; |
@@ -196,9 +266,11 @@ function autoDefaultFields(fields: Record<string, SearchFieldMeta>, displayField |
196 | 266 | * `declared` when the object's `searchableFields` (filtered to entries the |
197 | 267 | * engine can actually scan) is non-empty, `auto` otherwise. The source matters |
198 | 268 | * 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. |
202 | 274 | * |
203 | 275 | * TWO filters run on the declared branch, and they are different claims: |
204 | 276 | * |
|
0 commit comments