Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions .changeset/38924-own-field-rows-beside-modify-all.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
---
'@objectstack/spec': patch
'@objectstack/cli': patch
'@objectstack/metadata-protocol': patch
---

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

Clause-②: yes (widening)
Metadata-protocol: none

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.

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.

`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:

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

`--json` carries the same list under `ownFieldRowNarrowing` (`set`, `at`, `object`, `field`, `protocol18`, `protocol19`, `choice`); no other key changes.

`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.
10 changes: 10 additions & 0 deletions packages/cli/src/commands/migrate/meta.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import {
import { bootSchemaStack } from '../../utils/schema-migrate.js';
import { buildDataMigrationPlugins } from '../../utils/data-migration-plugins.js';
import { absentTableReads } from '../../utils/absent-table-reads.js';
import { ownFieldRowNarrowingSites, printOwnFieldRowNarrowing, type OwnFieldRowNarrowingSite } from '../../utils/own-field-row-narrowing.js';
import type { StoredMigrationReport } from '@objectstack/metadata-protocol';
import { OCCUPANCY_HINT, probeMigrationTarget } from '../../utils/migrate-occupancy-gate.js';
import { describeOccupancy, JOURNAL_MODE_SWITCH_NOTE } from '../../utils/sqlite-occupancy.js';
Expand Down Expand Up @@ -1056,6 +1057,8 @@ export interface MigrationReport {
elapsed: string;
/** The per-site edits the protocol-19 form move left ({@link formMoveSites}); absent or empty when none. */
formMoveSites?: readonly FormMoveSite[];
/** The own field rows beside Modify All protocol 19 narrows ({@link ownFieldRowNarrowingSites}); absent or empty when none. */
ownFieldRowNarrowing?: readonly OwnFieldRowNarrowingSite[];
/** The committed access matrix's drift `os build` will report, and whose sources it is about; absent when none. */
accessMatrix?: { drift: AccessMatrixDrift; subject: AccessMatrixDriftSubject };
}
Expand Down Expand Up @@ -1301,6 +1304,8 @@ export function printMigrationReport(report: MigrationReport): void {
if (result.applied.length > 0) printAppliedEdits(result, report.write !== undefined);
// ②b The sites the protocol-19 form move left in place or owes an edit.
printFormMoveSites(report.formMoveSites ?? []);
// ②c The own field rows beside Modify All the `viewAllFields: true` above does not keep.
printOwnFieldRowNarrowing(report.ownFieldRowNarrowing ?? []);

// Per-hop checkpoints.
if (report.step) {
Expand Down Expand Up @@ -1555,6 +1560,8 @@ export default class MigrateMeta extends Command {
const result = applyMetaMigrationsToPackages(normalized, fromMajor, toMajor);
// [ADR-0159, #37112] The per-site edits the protocol-19 form move leaves.
const formSites = formMoveSites(normalized, fromMajor, toMajor);
// The own field rows beside Modify All that protocol 19 narrows (named, never rewritten).
const ownRowSites = ownFieldRowNarrowingSites(normalized, fromMajor, toMajor);

// Prove the migrated stack is schema-valid — the "generated, provably valid
// diff" the consumer agent reviews (ADR-0087 D3/D5).
Expand Down Expand Up @@ -1618,6 +1625,8 @@ export default class MigrateMeta extends Command {
// Only when the run crosses into protocol 19 and the form move
// left a site: without one the payload is what it always was.
...(formSites.length > 0 ? { formMoveSites: formSites } : {}),
// Only when the run crosses into protocol 19 and an own field row narrows.
...(ownRowSites.length > 0 ? { ownFieldRowNarrowing: ownRowSites } : {}),
hops: flags.step
? result.hops.map((h) => ({
toMajor: h.toMajor,
Expand Down Expand Up @@ -1676,6 +1685,7 @@ export default class MigrateMeta extends Command {
...(range ? { range } : {}),
elapsed: timer.display(),
formMoveSites: formSites,
ownFieldRowNarrowing: ownRowSites,
...(matrixDrift
? {
accessMatrix: {
Expand Down
120 changes: 120 additions & 0 deletions packages/cli/src/utils/own-field-row-narrowing.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.

/**
* `os migrate meta --from N` — the own field rows beside Modify All that the
* protocol-19 field-axis split narrows although the chain writes
* `viewAllFields: true` beside the bit (ruling of record 6912661484, step 3).
*
* The edit line the chain prints for such an entry is right: the bit keeps the
* reads Modify All cast on every field the set's own rows leave alone. What it
* cannot keep is Modify All's vote OVER the set's own rows: up to protocol 18 a
* set with Modify All on `contact` and its own `'contact.salary':
* { readable: false }` row read and edited `salary`; from 19 that row binds
* and the field is hidden from the set's holders. Validate and build stay
* green either way, so without a line naming the row the upgrade takes the
* field away silently. The predicate is the spec's
* ({@link ownFieldRowsBesideModifyAll}), shared with the `--stored` review
* list; this module only walks a source stack for it and prints it.
*/

import chalk from 'chalk';
import {
ALL_CONVERSIONS,
ownFieldRowsBesideModifyAll,
type OwnFieldRowBesideModifyAll,
type OwnFieldRowProtocol18Outcome,
type OwnFieldRowProtocol19Outcome,
} from '@objectstack/spec';
import { applyMetaMigrations } from '@objectstack/spec/migrations';

/** The conversion whose rewritten entries the list is read beside. */
const CONVERSION_ID = 'permission-view-all-fields-beside-record-bypass';

/** One narrowed own field row of one source permission set. */
export interface OwnFieldRowNarrowingSite extends OwnFieldRowBesideModifyAll {
/** The permission set's `name`. */
set: string;
/** Where the set sits in the stack the chain replays: `permissions[0]`, or `packages[1].manifest.permissions[0]`. */
at: string;
}

function isPlainRecord(value: unknown): value is Record<string, unknown> {
return value !== null && typeof value === 'object' && !Array.isArray(value);
}

/**
* Every narrowed own field row of the stack's permission sets, read over the
* stack as it enters the conversion's hop (the chain replayed up to the major
* below it first, where `--from` is lower), and over each
* `packages[].manifest` body of an assembled stack the same way. Empty when the
* run does not cross into the conversion's major.
*/
export function ownFieldRowNarrowingSites(
stack: Record<string, unknown>,
fromMajor: number,
toMajor: number,
): OwnFieldRowNarrowingSite[] {
const conversion = ALL_CONVERSIONS.find((c) => c.id === CONVERSION_ID);
if (!conversion) return [];
const major = conversion.toMajor;
if (!(fromMajor < major && toMajor >= major)) return [];

const bodies: Array<{ prefix: string; body: Record<string, unknown> }> = [{ prefix: '', body: stack }];
if (Array.isArray(stack.packages)) {
stack.packages.forEach((entry, i) => {
if (isPlainRecord(entry) && isPlainRecord(entry.manifest)) bodies.push({ prefix: `packages[${i}].manifest.`, body: entry.manifest });
});
}

const sites: OwnFieldRowNarrowingSite[] = [];
for (const { prefix, body } of bodies) {
const entering = fromMajor < major - 1 ? applyMetaMigrations(body, fromMajor, major - 1).stack : body;
const sets = (entering as { permissions?: unknown }).permissions;
if (!Array.isArray(sets)) continue;
sets.forEach((set, i) => {
if (!isPlainRecord(set)) return;
for (const row of ownFieldRowsBesideModifyAll(set)) {
sites.push({ set: String(set.name ?? ''), at: `${prefix}permissions[${i}]`, ...row });
}
});
}
return sites;
}

const PROTOCOL_18: Record<OwnFieldRowProtocol18Outcome, string> = {
'read-and-edit': 'read and edit (Modify All voted over the set\'s own row)',
};

const PROTOCOL_19: Record<OwnFieldRowProtocol19Outcome, string> = {
hidden: 'hidden, no read and no edit (the set\'s own `readable: false` row binds)',
'read-only': 'read only (the set\'s own row binds, and it grants no edit)',
'read-only-where-when-matches':
'read, and locked on the rows the row\'s `when` matches (elsewhere the row votes nothing and the field '
+ 'follows the other sets and the object grant)',
'edit-only-where-when-matches':
'read, and this set votes the edit only on the rows the row\'s `when` matches (elsewhere the field follows '
+ 'the other sets and the object grant, and another set\'s lock is no longer out-voted)',
};

/**
* Group ②c — the narrowed own field rows, after the applied edits and the form
* move sites, before the semantic notices: each names the set, the entry, the
* row, the protocol-18 and protocol-19 answer through that set, and the choice.
*/
export function printOwnFieldRowNarrowing(sites: readonly OwnFieldRowNarrowingSite[]): void {
if (sites.length === 0) return;
console.log(chalk.bold(chalk.yellow(
` ${sites.length} own field row(s) beside Modify All that protocol 19 narrows — `
+ 'the `viewAllFields: true` written beside the bit does not keep them:',
)));
for (const site of sites) {
console.log(
` ${chalk.yellow('⚠')} permission set '${site.set}' (${site.at}), objects entry '${site.object}', `
+ `field row '${site.field}'`,
);
console.log(chalk.dim(` protocol 18: ${PROTOCOL_18[site.protocol18]}`));
console.log(chalk.dim(` protocol 19: ${PROTOCOL_19[site.protocol19]}`));
console.log(chalk.dim(` choice: ${site.choice}`));
}
console.log('');
}
Loading
Loading