Skip to content

Commit 7251bdb

Browse files
os-muskclaude
andauthored
docs(drivers): scope the reference_to refusal docblocks to the authoring face (#14489)
The SQL DDL door (#11567) and the Mongo schema-sync door (#13222) each assert that `reference_to` "is a REJECTED ALIAS, not a normalised one". After the `field-reference-to-alias` conversion landed, that is true on the AUTHORING face only: stored `sys_metadata` rehydration and `os migrate meta` now NORMALISE the key. Left as written, the next reader infers "a stored `reference_to` stays verbatim forever" from a driver comment, which is false. Both docblocks now scope the original assertion to the authoring face and quote the split the conversion's own registry docblock already states, rather than inventing a parallel formulation. Two prose measurements in driver-mongodb that a later spec tightening left behind are refreshed in the same stroke: `{ type: 'lookup' }` with no `reference` and `{ type: 'lookup', reference: '' }` no longer "parse successfully" — the superRefine added on the relationship types refuses both with `custom` on the `reference` path. The shape still reaches the join-index arm, because `syncSchema(object, schema: unknown)` casts and forwards verbatim with no Zod, so no assertion changes. Comments only: no behaviour, no assertion, no public type. Card #13851. Claude-Session: https://claude.ai/code/session_0112hMx9hjJ9BgB28X97DS68 Co-authored-by: Claude <noreply@anthropic.com>
1 parent 8e9e630 commit 7251bdb

3 files changed

Lines changed: 50 additions & 15 deletions

File tree

packages/drivers/driver-mongodb/src/mongodb-13222-reference-to-refusal.test.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -228,10 +228,13 @@ describe('#13222 part (1) — driver-mongodb refuses `reference_to` at the schem
228228

229229
it('does not index a `lookup` that declares no target — `reference` is read for truth, not presence', async () => {
230230
// Measured on `FieldSchema` built from this tree: `{ type: 'lookup' }` with
231-
// no `reference`, and `{ type: 'lookup', reference: '' }`, BOTH parse
232-
// successfully — the spec's prose calls `reference` required for these
233-
// types, but the schema does not enforce it. So this is a shape an author
234-
// can really publish, not a hypothetical, and the arm has to answer for it.
231+
// no `reference`, and `{ type: 'lookup', reference: '' }`, are BOTH REFUSED
232+
// (`custom` on the `reference` path) — #13927 made the "required for these
233+
// types" in the spec's own prose enforced; both parsed successfully until
234+
// then. The shape is still not hypothetical, because it does not arrive
235+
// through Zod: `syncSchema(object, schema: unknown)` casts and forwards
236+
// verbatim, which is the seam this test calls directly, so the arm still
237+
// has to answer for it.
235238
//
236239
// It answers by declining: `idx_FIELD_lookup` exists to serve a join, and a
237240
// lookup with no declared target has no join to serve — the index would

packages/drivers/driver-mongodb/src/mongodb-schema.ts

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,14 @@ interface FieldDef {
6666
* ⚠️ Truthiness rather than `!== undefined`, and that difference is load
6767
* bearing rather than inherited. Measured on `FieldSchema` built from this
6868
* tree: `{ type: 'lookup' }` with NO `reference`, and `{ type: 'lookup',
69-
* reference: '' }`, both parse SUCCESSFULLY — the "required for these types"
70-
* in the spec's own prose is not enforced by the schema. So a lookup that
71-
* points nowhere is a shape an author can really publish, and it must not
72-
* get `idx_FIELD_lookup`: an index for a join whose target is undeclared
73-
* costs writes and buys no read. Truthiness declines exactly that shape.
69+
* reference: '' }`, are BOTH REFUSED — `custom` on the `reference` path,
70+
* since #13927 made the "required for these types" in the spec's own prose
71+
* enforced (it parsed successfully until then). The shape still reaches this
72+
* arm regardless, because metadata gets here without meeting Zod at all —
73+
* `syncSchema(object, schema: unknown)` casts and forwards verbatim — and it
74+
* must not get `idx_FIELD_lookup`: an index for a join whose target is
75+
* undeclared costs writes and buys no read. Truthiness declines exactly that
76+
* shape.
7477
*/
7578
reference?: unknown;
7679
multiple?: boolean;
@@ -110,9 +113,9 @@ interface ObjectDef {
110113
*
111114
* ## Why the DDL seam needs a door the schema already has
112115
*
113-
* `reference` is the only relationship spelling the spec declares;
114-
* `reference_to` is a REJECTED ALIAS, not a normalised one. Measured against
115-
* `@objectstack/spec` built from this tree:
116+
* `reference` is the only relationship spelling the spec declares. ON THE
117+
* AUTHORING FACE `reference_to` is a REJECTED ALIAS, not a normalised one.
118+
* Measured against `@objectstack/spec` built from this tree:
116119
*
117120
* ```
118121
* FieldSchema.safeParse({ name:'company_id', type:'lookup', reference_to:'company' })
@@ -122,6 +125,21 @@ interface ObjectDef {
122125
* these were dropped silently ..."
123126
* ```
124127
*
128+
* ⚠️ That verdict is the authoring face and only the authoring face — do NOT
129+
* read this door as "a stored `reference_to` stays verbatim forever". #13700
130+
* landed the `field-reference-to-alias` conversion (`toMajor: 18`,
131+
* `retiredFromLoadPath: true`, in `packages/spec/src/conversions/registry.ts`),
132+
* and its docblock already states the split this comment has to be read
133+
* against: the entry "covers the two paths that serve or rewrite EXISTING data
134+
* — stored rehydration and `os migrate meta`", where the key is NORMALISED to
135+
* `reference` rather than refused, while "the DDL doors above keep guarding
136+
* the third path (metadata handed straight to a driver, around both the gate
137+
* and the stored pass); they are downstream of this entry, not replaced by
138+
* it." This door is one of those DDL doors — and the third path is exactly the
139+
* one this driver sits on, since `syncSchema(object, schema: unknown)` casts
140+
* and forwards verbatim with no Zod and no stored pass. Refused when authored,
141+
* rewritten when already at rest, refused again here.
142+
*
125143
* Until this door, the driver read `reference_to` and ONLY `reference_to`, as
126144
* the gate on the field-level join index below. So one key had TWO doors with
127145
* opposite answers: the authoring door refused it, while this one silently

packages/drivers/driver-sql/src/sql-driver.ts

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1488,9 +1488,9 @@ function refuseDateBucketedGroupBy(granularity: string, bucketedHere: string[],
14881488
*
14891489
* ## Why the DDL seam needs a door the schema already has
14901490
*
1491-
* `reference` is the only relationship spelling the spec declares;
1492-
* `reference_to` is a REJECTED ALIAS, not a normalised one. Measured on
1493-
* `origin/main`:
1491+
* `reference` is the only relationship spelling the spec declares. ON THE
1492+
* AUTHORING FACE `reference_to` is a REJECTED ALIAS, not a normalised one.
1493+
* Measured on `origin/main`:
14941494
*
14951495
* ```
14961496
* FieldSchema.safeParse({ name:'parent', type:'lookup', reference_to:'p' })
@@ -1499,6 +1499,20 @@ function refuseDateBucketedGroupBy(granularity: string, bucketedHere: string[],
14991499
* Did you mean `reference_to` → `reference`?"
15001500
* ```
15011501
*
1502+
* ⚠️ That verdict is the authoring face and only the authoring face — do NOT
1503+
* read this door as "a stored `reference_to` stays verbatim forever". #13700
1504+
* landed the `field-reference-to-alias` conversion (`toMajor: 18`,
1505+
* `retiredFromLoadPath: true`, in `packages/spec/src/conversions/registry.ts`),
1506+
* and its docblock already states the split this comment has to be read
1507+
* against: the entry "covers the two paths that serve or rewrite EXISTING data
1508+
* — stored rehydration and `os migrate meta`", where the key is NORMALISED to
1509+
* `reference` rather than refused, while "the DDL doors above keep guarding
1510+
* the third path (metadata handed straight to a driver, around both the gate
1511+
* and the stored pass); they are downstream of this entry, not replaced by
1512+
* it." This door is one of those DDL doors. Refused when authored, rewritten
1513+
* when already at rest, refused again here — three paths, and this comment
1514+
* speaks for the third.
1515+
*
15021516
* Until #11567 this driver read `reference_to` and ONLY `reference_to`, as the
15031517
* gate on a `table.foreign(name).references('id')`. So one key had TWO doors
15041518
* with opposite answers: the authoring door refused it, while the DDL door

0 commit comments

Comments
 (0)