Skip to content

Commit e659f7c

Browse files
committed
fix(spec,cli,metadata-protocol): a row-conditioned lock is its own outcome, and the step-19 text names only the rows it lists
A row with a when and no editable: true locks only the rows the condition matches, so it is read-only-where-when-matches; every choice now leads to the one row shape the list never names. The step-19 sentence says the list covers the entries the run writes viewAllFields beside. Wildcard field keys are not listed, the stored line's choice no longer names viewAllFields, the element type of ownFieldRows is exported, and the changeset declares the widening. Claude-Session: https://claude.ai/code/session_01QSeKYko9cFNzePK9vaCkYe Co-authored-by: Claude <noreply@anthropic.com>
1 parent 60ea167 commit e659f7c

8 files changed

Lines changed: 101 additions & 22 deletions

File tree

‎.changeset/38924-own-field-rows-beside-modify-all.md‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,23 @@
66

77
fix(cli): `os migrate meta --from 18` names each own field row beside Modify All that protocol 19 narrows
88

9-
Clause-②: no
9+
Clause-②: yes (widening)
1010
Metadata-protocol: none
1111

12+
Widened: `@objectstack/spec` exports `ownFieldRowsBesideModifyAll` and the types `OwnFieldRowBesideModifyAll`, `OwnFieldRowProtocol18Outcome` and `OwnFieldRowProtocol19Outcome`; `os migrate meta --from N --json` gains the key `ownFieldRowNarrowing`, present only when the list is not empty; `StoredViewAllFieldsReview` (`os migrate meta --stored --json`) gains the optional member `ownFieldRows`, and `@objectstack/metadata-protocol` exports its element type `StoredOwnFieldRow`. Nothing a metadata author writes changes.
13+
1214
The upgrade text no longer says that the `viewAllFields: true` written beside View All or Modify All keeps every field read. It keeps the field reads the bits cast, except a field the set's own `readable: false` row hides beside Modify All, and it keeps no edit Modify All cast. The protocol-19 behaviour itself is unchanged.
1315

14-
`os migrate meta --from 18` now lists each own field row beside Modify All whose answer changes on protocol 19: the permission set, the `objects` entry, the field row, what the set's holders got on 18 (read and edit), what they get on 19 (hidden, read only, or edit only on the rows the row's `when` matches), and the choice: change the row to keep the protocol-18 answer, or accept the narrowing. Example, for a set with View All and Modify All on `contact` and its own `'contact.salary': { readable: false }` row:
16+
`os migrate meta --from 18` now lists each own field row beside a Modify All bit that the run writes `viewAllFields: true` beside, where the row's answer changes on protocol 19. Each line names the permission set, the `objects` entry and the field row; what the set's holders got on protocol 18 (read and edit: Modify All voted over the set's own rows); what they get on 19 through that set (`hidden`, `read-only`, `read-only-where-when-matches` for a row-conditioned lock, or `edit-only-where-when-matches` for a row-conditioned edit); and the choice: change the row to keep the protocol-18 answer, or accept the narrowing. Following the choice takes the row off the list. A set that already carries `viewAllFields` beside the bit (a source the edit was applied to) is not listed; review its own rows beside Modify All by hand. Example, for a set with View All and Modify All on `contact` and its own `'contact.salary': { readable: false }` row:
1517

1618
```text
1719
1 own field row(s) beside Modify All that protocol 19 narrows — the `viewAllFields: true` written beside the bit does not keep them:
1820
⚠ permission set 'hr_manager' (permissions[0]), objects entry 'contact', field row 'contact.salary'
1921
protocol 18: read and edit (Modify All voted over the set's own row)
2022
protocol 19: hidden, no read and no edit (the set's own `readable: false` row binds)
21-
choice: to keep the protocol-18 read and edit, change the row to `readable: true, editable: true` (...); otherwise accept the narrowing.
23+
choice: to keep the protocol-18 read and edit, change the row to `readable: true, editable: true`; otherwise accept the narrowing.
2224
```
2325

24-
`--json` carries the same list under the new key `ownFieldRowNarrowing` (`set`, `at`, `object`, `field`, `protocol18`, `protocol19`, `choice`), present only when the list is not empty; no other key changes.
25-
26-
`os migrate meta --stored` names the same rows of a stored permission set under its entry in the View All Fields review list, and its `--json` entries carry them as `ownFieldRows`, present only when there is one. View All alone is never listed: a set's own row already bound beside its own View All on 18.
26+
`--json` carries the same list under `ownFieldRowNarrowing` (`set`, `at`, `object`, `field`, `protocol18`, `protocol19`, `choice`); no other key changes.
2727

28-
`@objectstack/spec` exports the predicate both commands read, `ownFieldRowsBesideModifyAll`, beside the conversion layer.
28+
`os migrate meta --stored` names the same rows of a stored permission set under its entry in the View All Fields review list, and its `--json` entries carry them as `ownFieldRows`. View All alone is never listed: on 18.6.0 a set's own row already bound beside its own View All. Protocol 18 here means 18.6.0, the release the card measured.

‎packages/cli/src/utils/own-field-row-narrowing.ts‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,12 @@ const PROTOCOL_18: Record<OwnFieldRowProtocol18Outcome, string> = {
8888
const PROTOCOL_19: Record<OwnFieldRowProtocol19Outcome, string> = {
8989
hidden: 'hidden, no read and no edit (the set\'s own `readable: false` row binds)',
9090
'read-only': 'read only (the set\'s own row binds, and it grants no edit)',
91-
'edit-only-where-when-matches': 'read, and edit only on the rows the row\'s `when` matches',
91+
'read-only-where-when-matches':
92+
'read, and locked on the rows the row\'s `when` matches (elsewhere the row votes nothing and the field '
93+
+ 'follows the other sets and the object grant)',
94+
'edit-only-where-when-matches':
95+
'read, and this set votes the edit only on the rows the row\'s `when` matches (elsewhere the field follows '
96+
+ 'the other sets and the object grant, and another set\'s lock is no longer out-voted)',
9297
};
9398

9499
/**

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,7 @@ export type {
263263
StoredMigrationTodo,
264264
StoredViewAllFieldsReview,
265265
} from './stored-migration.js';
266+
export type { StoredOwnFieldRow } from './stored-own-field-rows.js';
266267

267268
export {
268269
computeMetadataDiagnostics,

‎packages/metadata-protocol/src/stored-own-field-rows.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ export function storedOwnFieldRows(body: unknown, object: string): { ownFieldRow
3737
const PROTOCOL_19: Record<StoredOwnFieldRow['protocol19'], string> = {
3838
hidden: 'hidden, no read and no edit',
3939
'read-only': 'read only',
40-
'edit-only-where-when-matches': 'read, and edit only on the rows its `when` matches',
40+
'read-only-where-when-matches': 'read, and locked on the rows its `when` matches',
41+
'edit-only-where-when-matches': 'read, and this set votes the edit only on the rows its `when` matches',
4142
};
4243

4344
/** The lines naming one review entry's narrowed own field rows, nested under the entry's line. */

‎packages/spec/src/conversions/entries/19/permission-view-all-fields-beside-record-bypass.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ import { isDict } from '../shared.js';
2828
* Every `objects` entry of every permission set, the `'*'` entry included,
2929
* that carries `viewAllRecords: true` or `modifyAllRecords: true` and has no
3030
* `viewAllFields` key gets `viewAllFields: true`, so a source written while the
31-
* bits read every field keeps every read they cast. An entry whose author
31+
* bits read every field keeps the reads they cast, except the two losses
32+
* listed below. An entry whose author
3233
* already wrote `viewAllFields` — either value — has spoken and is left alone,
3334
* which is also what makes a second replay a no-op.
3435
*

‎packages/spec/src/conversions/own-field-rows-beside-modify-all.test.ts‎

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,48 @@ describe('ownFieldRowsBesideModifyAll', () => {
4545
]);
4646
});
4747

48+
it('names a row-conditioned lock (a `when`, no editable: true) as a lock on the matching rows only, not read-only', () => {
49+
const rows = ownFieldRowsBesideModifyAll({
50+
name: 'deal_desk',
51+
objects: { deal: { allowRead: true, allowEdit: true, modifyAllRecords: true } },
52+
fields: { 'deal.amount': { readable: true, when: 'stage in ["approved"]' } },
53+
});
54+
expect(rows.map((r) => [r.field, r.protocol19])).toEqual([['deal.amount', 'read-only-where-when-matches']]);
55+
});
56+
57+
it('each choice leads to a row the list no longer names, so the next run is quiet', () => {
58+
// The row each choice spells, by outcome: the one shape 19 answers as 18 did.
59+
const followed: Record<string, Record<string, unknown>> = {
60+
hidden: { readable: true, editable: true },
61+
'read-only': { readable: true, editable: true },
62+
'read-only-where-when-matches': { readable: true, editable: true },
63+
'edit-only-where-when-matches': { readable: true, editable: true },
64+
};
65+
const before = {
66+
'contact.a': { readable: false },
67+
'contact.b': { readable: true },
68+
'contact.c': { readable: true, when: 'status == "open"' },
69+
'contact.d': { readable: true, editable: true, when: 'status == "open"' },
70+
};
71+
const listed = ownFieldRowsBesideModifyAll({ name: 'x', objects: { contact: MODIFY_ALL }, fields: before });
72+
expect(listed.map((r) => r.protocol19)).toEqual([
73+
'hidden', 'read-only', 'read-only-where-when-matches', 'edit-only-where-when-matches',
74+
]);
75+
for (const row of listed) {
76+
expect(row.choice).toMatch(/`readable: true, editable: true`|add `editable: true`|remove the row's `when`/);
77+
}
78+
const after = Object.fromEntries(listed.map((r) => [r.field, followed[r.protocol19]]));
79+
expect(ownFieldRowsBesideModifyAll({ name: 'x', objects: { contact: MODIFY_ALL }, fields: after })).toEqual([]);
80+
});
81+
82+
it('never lists a `*.FIELD` row: no merge reads a wildcard field key', () => {
83+
expect(ownFieldRowsBesideModifyAll({
84+
name: 'ops_admin',
85+
objects: { '*': MODIFY_ALL },
86+
fields: { '*.salary': { readable: false } },
87+
})).toEqual([]);
88+
});
89+
4890
it('reads a row of an object the set does not name against its `*` entry', () => {
4991
const rows = ownFieldRowsBesideModifyAll({
5092
name: 'ops_admin',

‎packages/spec/src/conversions/own-field-rows-beside-modify-all.ts‎

Lines changed: 34 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,27 @@
1919
* field, and its holders get, through this set:
2020
*
2121
* - `readable: false`: no read and no edit (`hidden`);
22-
* - `readable` true, no `editable: true` (an omitted `editable` is `false`):
23-
* the read only (`read-only`);
24-
* - `editable: true` beside a `when`: the edit on the rows the condition
25-
* matches only (`edit-only-where-when-matches`);
22+
* - `readable` true, no `editable: true` (an omitted `editable` is `false`)
23+
* and no `when`: the read only, on every row (`read-only`);
24+
* - `readable` true, no `editable: true`, beside a `when`: a lock on the
25+
* rows the condition matches only (`read-only-where-when-matches`). The
26+
* read vote is row-blind, but the entry votes nothing on a row its `when`
27+
* does not match (`fieldPermissionVote` answers `null`), so there the field
28+
* answers as it did on 18 when no other set names it;
29+
* - `editable: true` beside a `when`: this set's edit vote on the rows the
30+
* condition matches only (`edit-only-where-when-matches`). On the other rows
31+
* the entry is absent and the field follows the other sets and the object
32+
* grant; what changes is the row-blind reading of the set's lock and the
33+
* answer beside another set's lock, which Modify All out-voted on 18;
2634
* - `editable: true` and no `when`: what protocol 18 gave — not listed.
2735
*
36+
* Each `choice` names the row that answers as protocol 18 did, which this
37+
* list never names, so following the choice takes the row off the list.
38+
*
39+
* A row keyed `'*.FIELD'` is never listed: no merge reads a wildcard field
40+
* key (field rows have no wildcard, ruling of record 6912661484), so it is
41+
* inert on both sides of the split.
42+
*
2843
* View All (`viewAllRecords`) alone is not this shape: up to 18 the set's own
2944
* row already beat its own View All (ADR-0066 D2 ⑧, note of 2026-11-15), and
3045
* View All never voted an edit, so its own rows give the same answer on both
@@ -56,7 +71,11 @@ import { permissionViewAllFieldsBesideRecordBypass } from './entries/19/permissi
5671
export type OwnFieldRowProtocol18Outcome = 'read-and-edit';
5772

5873
/** What a holder of the set reads and edits on the field through this set on protocol 19. */
59-
export type OwnFieldRowProtocol19Outcome = 'hidden' | 'read-only' | 'edit-only-where-when-matches';
74+
export type OwnFieldRowProtocol19Outcome =
75+
| 'hidden'
76+
| 'read-only'
77+
| 'read-only-where-when-matches'
78+
| 'edit-only-where-when-matches';
6079

6180
/** One own field row beside Modify All whose answer protocol 19 narrows. */
6281
export interface OwnFieldRowBesideModifyAll {
@@ -70,13 +89,17 @@ export interface OwnFieldRowBesideModifyAll {
7089
choice: string;
7190
}
7291

92+
// Every choice leads to `readable: true, editable: true` with no `when`, the
93+
// one row shape this list never names, so a run after following it is quiet.
7394
const CHOICE: Record<OwnFieldRowProtocol19Outcome, string> = {
7495
hidden:
75-
'to keep the protocol-18 read and edit, change the row to `readable: true, editable: true` (deleting it '
76-
+ 'restores the read through `viewAllFields`, and the edit only where no set names the field); '
96+
'to keep the protocol-18 read and edit, change the row to `readable: true, editable: true`; '
7797
+ 'otherwise accept the narrowing.',
7898
'read-only':
7999
'to keep the protocol-18 edit, add `editable: true` to the row; otherwise accept the narrowing.',
100+
'read-only-where-when-matches':
101+
'to keep the protocol-18 edit on every row, change the row to `readable: true, editable: true` with no '
102+
+ '`when`; otherwise accept the narrowing.',
80103
'edit-only-where-when-matches':
81104
'to keep the protocol-18 edit on every row, remove the row\'s `when`; otherwise accept the narrowing.',
82105
};
@@ -88,8 +111,9 @@ function isDict(value: unknown): value is Record<string, unknown> {
88111
/** The narrowed outcome of one own row beside Modify All, or `undefined` when 19 answers as 18 did. */
89112
function narrowedOutcome(row: Record<string, unknown>): OwnFieldRowProtocol19Outcome | undefined {
90113
if (row.readable === false) return 'hidden';
91-
if (row.editable !== true) return 'read-only';
92-
if (typeof row.when === 'string' && row.when.trim() !== '') return 'edit-only-where-when-matches';
114+
const conditioned = typeof row.when === 'string' && row.when.trim() !== '';
115+
if (row.editable !== true) return conditioned ? 'read-only-where-when-matches' : 'read-only';
116+
if (conditioned) return 'edit-only-where-when-matches';
93117
return undefined;
94118
}
95119

@@ -125,6 +149,7 @@ export function ownFieldRowsBesideModifyAll(set: unknown): OwnFieldRowBesideModi
125149
const dot = field.indexOf('.');
126150
if (dot <= 0 || !isDict(row)) continue;
127151
const objectName = field.slice(0, dot);
152+
if (objectName === '*') continue; // no merge reads a wildcard field key
128153
const covering = objects[objectName] ? objectName : '*';
129154
const entry = objects[covering];
130155
if (!rewritten.has(covering) || !isDict(entry) || entry.modifyAllRecords !== true) continue;

‎packages/spec/src/migrations/entries/semantic/19.permission-view-all-modify-all-cast-no-field-vote.ts‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,12 @@ export const entry: SemanticMigration = {
5555
+ 'such bit (the D2 conversion `permission-view-all-fields-beside-record-bypass`), which keeps the field '
5656
+ 'reads the bits cast, except a field the set\'s own `readable: false` row hides beside its Modify All: that '
5757
+ 'row now binds. It keeps no edit Modify All cast. The same command, with or without `--write`, names each '
58-
+ 'own field row beside Modify All that now hides its field, makes it read-only or limits its edit to the '
58+
+ 'own field row beside a Modify All bit it writes `viewAllFields: true` beside in that run, where the row '
59+
+ 'now hides its field, locks it (on every row or on the rows its `when` matches) or limits its edit to the '
5960
+ 'rows its `when` matches, with its protocol-18 and protocol-19 answer and the choice: change the row to '
60-
+ 'keep the protocol-18 answer, or accept the narrowing. The conversion replays only there: it is a default flip, '
61+
+ 'keep the protocol-18 answer, or accept the narrowing. It names no row beside an entry that already '
62+
+ 'carries `viewAllFields` (a source the edit was applied to, by `--write` or by hand): review those rows '
63+
+ 'against the criteria below. The conversion replays only there: it is a default flip, '
6164
+ 'retired from the load path, so the authoring funnel skips it, and the artifact-ingestion door and every '
6265
+ 'stored-row read (`applyConversionsToStoredItem`) refuse it by id.\n\n'
6366
+ 'STORED permission sets (Studio-saved, in `sys_metadata`): they are NOT rewritten on upgrade and are '
@@ -88,6 +91,7 @@ export const entry: SemanticMigration = {
8891
+ '`security-cross-set-field-reopen` on a field one set hides that another set\'s `viewAllFields` '
8992
+ 're-opens, so a bit added where the hide was meant is visible there.',
9093
// The edits this entry judges: every `viewAllFields: true` that conversion
91-
// writes keeps a read; the criteria above say when to delete it instead.
94+
// writes keeps the reads the bit cast but a field the set's own row hides
95+
// beside Modify All; the criteria above say when to delete it instead.
9296
conversionIds: ['permission-view-all-fields-beside-record-bypass'],
9397
};

0 commit comments

Comments
 (0)