Skip to content

Commit 2783ea7

Browse files
committed
docs(spec): the master-not-writable refusal and its changeset state the rule at the level of the contract
Co-authored-by: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01B2EeooonSXrANpkpgUSfFZ
1 parent 34928cb commit 2783ea7

4 files changed

Lines changed: 38 additions & 13 deletions

File tree

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
---
2+
'@objectstack/spec': minor
3+
'@objectstack/lint': patch
4+
---
5+
6+
feat(spec)!: a `controlled_by_parent` object whose one required `master_detail` is marked `readonly: true` or `system: true` is refused at parse
7+
8+
Clause-②: no (narrowing)
9+
10+
Metadata-protocol: narrowed
11+
12+
<!-- adr-0087: already-registered cbp-master-relation-tiers-retired -->
13+
14+
**BREAKING** (a declaration the parse accepted is now refused), shipped as `minor` under the 18.x convention for breaking changes, with no retirement stage.
15+
16+
ADR-0055 §1: a `controlled_by_parent` object derives its record access from exactly one required `master_detail` field. That one master must be a reference every write of a detail supplies, and a field declared `readonly: true` or `system: true` is not one an author's write supplies, so it cannot be that master. `os lint` already reported it at `error` under `relationship/master-detail-required`, but `os lint` is not a publishing door: `os validate`, `os build`, `ObjectSchema.create()`, `defineStack` and the metadata save door accepted it.
17+
18+
- **FROM:** `sharingModel: 'controlled_by_parent'` with one required `master_detail` declared `readonly: true` and/or `system: true` parses, builds and saves.
19+
- **TO:** the parse refuses it at `fields`, naming the object, the field and each flag (the message opens with "Object 'OBJECT' declares sharingModel 'controlled_by_parent' with its one required master_detail, FIELD, marked readonly: true", with each name and flag in a code span). The save door answers `422 INVALID_METADATA` with that issue and stores nothing. `ObjectSchema.create()` refuses it too, because the parse it ends in is the same rule. An objectExtensions entry that leaves the merged master flagged is refused at the extension, as before for the other shapes.
20+
- **The fix:** remove `readonly: true` and `system: true` from the master reference and declare it as an ordinary required field. If the rows must outlive their parent, the object is not a detail: give it its own `sharingModel` (`private`, `public_read` or `public_read_write`).
21+
- **Unchanged:** the runtime. The flags do not change which field the runtime resolves as the master. A flag on a second, non-required `master_detail` beside the master is still reported by `os lint` alone.
22+
23+
Data at rest still loads. A stored object in this shape registers under its `[metadata_spec_invalid]` diagnostic, and `os migrate meta --stored` lists it as a TODO under `cbp-master-relation-tiers-retired`. No conversion rewrites it: dropping the flag changes who may write the reference, which is the owner's decision.
24+
25+
`@objectstack/spec/data`: `controlledByParentMasterRefusal` returns the new shape `master-not-writable` for this object, so a producer that asks it before writing `controlled_by_parent` gets the parse's verdict. `ControlledByParentMasterShape` gains that member. `isControlledByParentMasterField` is unchanged: a flagged required `master_detail` still counts as the master, so beside a second required one the object is still refused as having two.
26+
27+
`@objectstack/lint`: the `relationship/master-detail-required` explanation (`os explain`) now says that the parse refuses every shape that leaves the object without exactly one writable required master, and that a shape on a second, non-required `master_detail` is this rule's report alone.

‎packages/spec/src/data/controlled-by-parent-master.ts‎

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,9 @@
5858
* - `master-not-writable` — exactly one required `master_detail`, declared
5959
* `readonly: true` or `system: true`. ADR-0055 §1 derives the master from a
6060
* reference every write of a detail supplies, and those two flags mark a
61-
* field record validation skips before its required check is reached (one
62-
* the platform fills, or one a write may not set), so the one master would be
63-
* required in name only. Dropping the flag is the owner's call: it changes
64-
* who may write the reference.
61+
* field an author's write does not supply (one the platform fills, or one a
62+
* write may not set), so it cannot be the one master. Dropping the flag is
63+
* the owner's call: it changes who may write the reference.
6564
*/
6665
export type ControlledByParentMasterShape =
6766
| 'several-required-masters'
@@ -146,9 +145,9 @@ export function controlledByParentMasterRefusal(
146145
`Object '${name}' declares sharingModel 'controlled_by_parent' with its one required \`master_detail\`, `
147146
+ `\`${master}\`, marked ${flags.map((f) => `\`${f}: true\``).join(' and ')}. ADR-0055 §1: since `
148147
+ '@objectstack/spec 18, a controlled-by-parent object derives its master from exactly one required '
149-
+ '`master_detail` field that every write of a detail supplies, and a `readonly` or `system` field is '
150-
+ 'one record validation skips before its required check, so this reference would be required in name '
151-
+ `only. Remove ${flags.map((f) => `\`${f}: true\``).join(' and ')} from \`${master}\` and declare the `
148+
+ '`master_detail` field that every write of a detail supplies, and a field marked `readonly` or '
149+
+ '`system` is not one an author\'s write supplies, so this reference cannot be that master. '
150+
+ `Remove ${flags.map((f) => `\`${f}: true\``).join(' and ')} from \`${master}\` and declare the `
152151
+ 'master reference as an ordinary required field; if the rows must outlive their parent, this object '
153152
+ "is not a detail: give it its own sharingModel ('private', 'public_read' or 'public_read_write').",
154153
};

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2186,9 +2186,8 @@ function refuseAttachedBlockConflicts(attachedOnRead: unknown, fields: unknown,
21862186
* [#25092, ruling 6328204856 route A] The one master must also be WRITABLE:
21872187
* a required `master_detail` declared `readonly: true` or `system: true` is
21882188
* refused at `['fields']` (shape `master-not-writable`). ADR-0055 §1 derives
2189-
* the master from a reference every write of a detail supplies, and record
2190-
* validation skips those two flags before its required check, so such a
2191-
* master is required in name only. Unlike the shapes above, the runtime still
2189+
* the master from a reference every write of a detail supplies, and a field
2190+
* carrying either flag is not one an author's write supplies. Unlike the shapes above, the runtime still
21922191
* resolves this one (the flags do not change which field is the master), so
21932192
* this half of the rule lives at the parse alone, the authoring contract, and
21942193
* the runtime is not changed by it. `os lint`'s

‎packages/spec/src/migrations/entries/semantic/18.cbp-master-relation-tiers-retired.ts‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,9 @@ export const entry: SemanticMigration = {
5050
+ 'what deleting the master does to every row, and whether an object should instead stop being '
5151
+ 'controlled by its parent is a product decision only its author can make. The same rule refuses a one '
5252
+ 'master marked `readonly: true` or `system: true`: ADR-0055 §1 derives the '
53-
+ 'master from a reference every write of a detail supplies, record validation skips those two flags before '
54-
+ 'its required check, and `os lint` alone reported them, so `os validate`, `os build` and the save door '
55-
+ 'accepted a master that was required in name only. It is not converted: dropping the flag changes who may '
53+
+ 'master from a reference every write of a detail supplies, a field carrying either flag is not one an '
54+
+ 'author\'s write supplies, and `os lint` alone reported them, so `os validate`, `os build` and the save '
55+
+ 'door accepted a master that could not be the one master. It is not converted: dropping the flag changes who may '
5656
+ 'write the reference.',
5757
acceptanceCriteria:
5858
'Every object declaring `sharingModel: \'controlled_by_parent\'` declares exactly one `master_detail` '

0 commit comments

Comments
 (0)