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
21 changes: 21 additions & 0 deletions .changeset/35524-bare-save-follows-base-dependent-member.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
---
'@objectstack/metadata-protocol': patch
---

fix(metadata-protocol)!: a save naming no package, at a bundle member only a dependent package holds, writes the base package's row the read naming no package addresses

Clause-②: no (narrowing)
Metadata-protocol: none

<!-- adr-0087: not-required (no-migration-prescription) No key of any schema is added, removed, renamed or re-shaped, and no export changes shape. What moves is which stored row a save, draft read, per-item publish or draft discard that names no package addresses at one cell; no stored row, registry key or authored value is rewritten, so there is nothing for a migration to change and no tombstone. -->

**BREAKING** for a caller that saves, publishes or discards a bundled type's item (today `email_template`) without naming a package, where an authored base package holds a stored row of the item at some member (its canonical member, or another one such as `de-DE`), an authored package that declares the base holds a stored row of another, non-canonical member (for example `fr-FR`), and the base holds no row of that member. The read naming no package already takes the base's address at that member and answers `404`.

- FROM: the save naming no package (REST `PUT` and in process, `active` mode) rewrote the dependent's row at that member, and the read naming no package then still answered `404` (or `409 RESOURCE_CONFLICT` where the rows had been stored after boot). The `draft` save wrote the dependent's draft; the draft read, per-item publish and draft discard naming no package read, promoted or removed the dependent's draft.
- TO: the save naming no package writes the base's row (or, in `draft` mode, the base's draft) at that member, exactly as the same save naming the base (`?package=BASE`, `packageId: BASE`) does; the dependent's row is left byte-unchanged, and the next read naming no package serves the saved content (`200`). The draft read, per-item publish and draft discard naming no package act on the base's draft there. With only the dependent's draft stored at that member, the per-item publish naming no package answers `404 NO_DRAFT` naming that draft, and the draft discard naming no package discards nothing and says which draft remains, as the same requests naming the base answer.
- FROM, a package-unbound draft stored at that member (as a `draft` save naming no package writes it while no package holds the member) with no draft of the dependent beside it: the draft read naming no package served that draft, the per-item publish naming no package promoted it into the dependent's row, the draft discard naming no package removed it, and the `draft` save naming no package adopted it into the dependent's draft, after which the draft doors naming no package still acted on it.
- TO, at that sub-cell: the `draft` save naming no package writes the base's draft beside the package-unbound one and leaves the package-unbound draft untouched, as the save naming the base does; the draft read naming no package then reads back what was saved; the per-item publish naming no package promotes the base's draft into the base's row; a second `draft` save naming no package updates the base's draft (no second draft). With no base draft stored, the per-item publish naming no package answers `404 NO_DRAFT` and the draft discard naming no package discards nothing and names the package-unbound draft as still stored, exactly as the same requests naming the base answer. With no base draft stored, the draft read naming no package still serves the package-unbound draft, as the draft read naming the base does; once the base's draft is saved, both read the base's draft.

**Not moved.** The canonical member (a base and its dependent both holding it, or only the dependent holding it), two packages neither of which declares the other, a base that ships the name in code, and the delete, history, diff and rollback naming no package at this member.

The fix for a caller: to change the dependent's row or draft at that member, name the dependent (`?package=DEPENDENT` on the REST door, `packageId` in process).
22 changes: 19 additions & 3 deletions packages/metadata-protocol/src/protocol-diff-delete-load.ts
Original file line number Diff line number Diff line change
Expand Up @@ -789,13 +789,29 @@ export class ProtocolDiffDeleteLoadFacet {
// below nor its "already at artifact default" / "nothing to
// delete" claim holds. A delete naming none never lands here:
// it addresses a row the read above found.
if (!current && request.packageId != null && (rowsAtAddress.candidates.length > 0 || rowsAtAddress.unbound)) {
//
// [#35524, epic ruling 6781691009, contract review S2 option
// (b)] …and a draft discard naming no package at the row-held
// base's draft address over a stored package-unbound draft
// ({@link packagelessRowHeldBaseDraftAddress}): it addresses the
// base's draft, as the discard naming the base does, so with no
// base draft it answers that discard's receipt, naming the
// package-unbound draft still stored, never "No pending draft"
// while one is. Only that address is `none` with a
// package-unbound draft stored: `packagelessDraftAddress` makes
// a stored package-unbound draft the address itself (`draft`,
// key `null`) wherever it does not move to a base.
const receiptPackageId = request.packageId
?? (draftAddress?.kind === 'none' && draftAddress.into !== null && rowsAtAddress.unbound
? draftAddress.into
: null);
if (!current && receiptPackageId != null && (rowsAtAddress.candidates.length > 0 || rowsAtAddress.unbound)) {
return {
success: true,
reset: false,
message: targetState === 'draft'
? `No pending draft of ${request.type}/${request.name} is bound to package '${request.packageId}', so nothing was discarded: ${remainingRowsPhrase(rowsAtAddress.candidates, rowsAtAddress.unbound, 'draft')}.`
: `No row of ${request.type}/${request.name} is bound to package '${request.packageId}', so nothing was deleted: ${remainingRowsPhrase(rowsAtAddress.candidates, rowsAtAddress.unbound, 'row')}.`,
? `No pending draft of ${request.type}/${request.name} is bound to package '${receiptPackageId}', so nothing was discarded: ${remainingRowsPhrase(rowsAtAddress.candidates, rowsAtAddress.unbound, 'draft')}.`
: `No row of ${request.type}/${request.name} is bound to package '${receiptPackageId}', so nothing was deleted: ${remainingRowsPhrase(rowsAtAddress.candidates, rowsAtAddress.unbound, 'row')}.`,
};
}
// [#23495] …and a draft discard naming no package, of an item
Expand Down
125 changes: 115 additions & 10 deletions packages/metadata-protocol/src/protocol-save.ts
Original file line number Diff line number Diff line change
Expand Up @@ -869,7 +869,16 @@ export class ProtocolSaveFacet {
host, 'save', request.type, writeType, request.name, itemDiscriminator(writeType, request.item), address,
);
if (holderRefusal) throw holderRefusal;
if (address.packageId !== null) request = { ...request, packageId: address.packageId };
// [#35524] …and a named non-canonical member only a dependent
// holds, where the read naming no package takes the row-held
// base's address: the base's row, as the save naming the base
// writes it ({@link packagelessRowHeldBaseAddress}), never the
// dependent's row the read does not serve there.
const base = address.candidates.length === 1
? await packagelessRowHeldBaseAddress(host, writeType, request.name, member)
: undefined;
const resolved = base ?? address.packageId;
if (resolved !== null) request = { ...request, packageId: resolved };
}
}

Expand Down Expand Up @@ -901,8 +910,17 @@ export class ProtocolSaveFacet {
// draft save's inherited package (the named-base rule and the late
// override re-judgment): the base is judged exactly as the save
// naming it is, an id no installed package has refused `422`.
// [#35524] …and the same where the active rows at the member are bound
// to the one dependent whose addition the read naming no package does
// not serve (it takes the base's address there): the base's draft,
// also over a stored package-unbound draft there (epic ruling
// 6781691009, contract review S2 option (b)). The named base is passed
// down, so the repository's orphan-draft adoption (a save naming no
// package) does not run: the package-unbound draft stays untouched, as
// the save naming the base leaves it, and the draft the next bare
// draft read, publish and discard reach is the one written here.
let followedBase: string | undefined;
if (draftAddress?.kind === 'ambiguous') {
if (draftAddress !== undefined && (draftAddress.kind === 'ambiguous' || draftAddressFollowsRowHeldBase(draftAddress))) {
const base = await packagelessRowHeldBaseAddress(
host, singularType, request.name, itemDiscriminator(singularType, request.item),
);
Expand Down Expand Up @@ -3247,18 +3265,28 @@ export function disabledHoldersOnlyRefusal(
* that base does, and every dependent's row stays where it is, read and
* written at its own `?package=`.
*
* Asked only where those doors would refuse naming two or more packages, and
* answered over the item's ACTIVE rows at `member`, as the read judges them:
* Asked where those doors would refuse naming two or more packages, and
* [#35524] by the save (publish and draft mode) and the draft doors'
* address ({@link packagelessRowHeldBaseDraftAddress}) where the rows are
* bound to one package; answered over the item's ACTIVE rows at `member`, as
* the read judges them:
*
* - the base, when two or more packages hold a row there, none of them
* package-less (#33210: a package-less row beside them is a customization
* of no one holder, and the refusal stands), and one is the row-held base;
* - `undefined` otherwise, and the door refuses as before: a type with no
* - [#35524] the base, when one dependent holds the only row there, at a
* named non-canonical member the base holds no row of: the read takes the
* base's address there (and answers 404 until the base holds a row), so
* the bare save writes the base's row or draft, as the save naming the
* base does, and the next bare read serves it. The canonical member stays
* the dependent's, as the read serves it (#33210 contract review S1);
* - `undefined` otherwise, and the door answers as before: a type with no
* members (#34441 contract review M1: no bundle additions), a name a
* package ships, holders with no base relation, a disabled holder (the
* served-holder judgment's), and a member the base holds no row of (the
* read takes the base's address there and answers 404; that cell is not
* moved here).
* served-holder judgment's), and, of the one-holder cell, the base's own
* row. The bare delete, history, diff and rollback ask only with two or
* more holders, so at the one-holder cell they still act on the
* dependent's row.
*
* FROM (`main` 8596c80eda): each of those doors refused `409
* RESOURCE_CONFLICT` naming the base and the dependent while the read
Expand All @@ -3285,9 +3313,86 @@ export async function packagelessRowHeldBaseAddress(
return undefined;
}
const address = await host.packagelessAddress(singular, name, member, 'active', activeRows);
if (address.candidates.length < 2 || address.unbound) return undefined;
if (address.candidates.length === 0 || address.unbound) return undefined;
const base = await rowHeldBaseAddressOf(host, singular, name, member, activeRows);
return base !== undefined && address.candidates.includes(base) ? base : undefined;
if (base === undefined) return undefined;
// [#35524] Two or more holders at the member: the base is one of them. One
// holder: a dependent's addition the base holds no row of, where the read
// takes the base's address (`rowHeldBaseAddressOf`'s S1-guarded arm).
return address.candidates.includes(base) === address.candidates.length > 1 ? base : undefined;
}

/**
* [#35524] Whether a non-ambiguous draft address naming no package is one the
* row-held base's address may replace ({@link packagelessRowHeldBaseAddress}):
* bound to a package by the active rows (`into !== null`), whatever draft it
* names, the dependent's or [contract review S2 option (b)] the
* package-unbound one (`key === null`). Epic ruling 6781691009, "a write
* resolves its address exactly as the read at the same address resolves it":
* the read naming no package takes the base's address at that member however
* the drafts there are stored, so the draft save and the other draft doors
* take it too. Keeping the package-unbound draft's own address there (the
* contract review S1 option (a) this replaces) let the bare draft save adopt
* that draft into the dependent, after which the bare draft read missed the
* draft just saved. The one predicate the draft doors' address
* ({@link packagelessRowHeldBaseDraftAddress}) and the draft save's follow
* ask, so they cannot part.
*/
export function draftAddressFollowsRowHeldBase(address: { into: string | null }): boolean {
return address.into !== null;
}

/**
* [#35524, epic ruling 6781691009, #34348 ruling (b)] THE DRAFT ADDRESS the
* draft doors naming no package take (the draft save, the strict draft read,
* the per-item publish and the draft discard, through
* `packagelessDraftAddress`), at a named non-canonical member whose active
* rows are bound to one dependent only, where the read naming no package
* takes the row-held base's address ({@link packagelessRowHeldBaseAddress}):
* that base's draft, promoted into the base's row, as the same request naming
* the base addresses it. So the draft a bare draft save writes there is the
* draft the bare draft read, publish and discard act on, and the dependent's
* draft is read, published and discarded at its own `?package=`.
*
* [#35524 contract review S2 option (b), epic ruling 6781691009] That
* includes a PACKAGE-UNBOUND draft stored at the member (`key === null`: no
* draft of the dependent beside it, as a bare draft save at the member writes
* it while no package holds that member): the address is still the base's
* (`none` until the base holds a draft there), because the read naming no
* package takes the base's address there however the drafts are stored. So
* the bare draft save writes the base's draft (the package-unbound draft is
* left untouched, as the save naming the base leaves it), the bare draft read
* reads back what it saved, the bare per-item publish promotes the base's
* draft, and the bare draft discard with no base draft answers as the discard
* naming the base does, naming the remaining package-unbound draft
* (`protocol-diff-delete-load.ts`). With no base draft there, the bare draft
* read still serves the package-unbound draft, as the draft read naming the
* base does, while the bare publish and discard leave it stored, as the
* requests naming the base do.
*
* `pending` (the draft address the stored rows give) itself otherwise: an
* ambiguous address (the doors ask {@link packagelessRowHeldBaseAddress} for
* it themselves, #34681), an address not bound to a package by the active
* rows ({@link draftAddressFollowsRowHeldBase}), and every cell that judgment
* declines.
*
* FROM (`main` a73edb3cd7): the bare draft save wrote the dependent's draft
* there (or adopted a stored package-unbound draft into the dependent) and
* the bare publish promoted it into the dependent's row, while the bare read
* at the member answered 404 (the base's address).
*/
export async function packagelessRowHeldBaseDraftAddress(
host: Pick<ProtocolHost, 'declinesStoredRow' | 'engine' | 'packagelessAddress' | 'readItemActiveRows' | 'rethrowUnlessMetadataStoreUnprovisioned' | 'shippedArtifactsOf'>,
type: string,
name: string,
member: string | undefined,
pending: ReturnType<ProtocolHost['packagelessDraftAddress']>,
): Promise<Awaited<ReturnType<ProtocolHost['packagelessDraftAddress']>>> {
const address = await pending;
if (address.kind === 'ambiguous' || !draftAddressFollowsRowHeldBase(address)) return address;
const base = await packagelessRowHeldBaseAddress(host, type, name, member);
if (base === undefined) return address;
return { kind: address.drafts.candidates.includes(base) ? 'draft' : 'none', key: base, into: base, drafts: address.drafts };
}

/**
Expand Down
9 changes: 7 additions & 2 deletions packages/metadata-protocol/src/protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -619,7 +619,7 @@ import { ProtocolWriteGatesTables } from './protocol-write-gates-tables.js';
import { ProtocolRegistryHydrationFacet, type ObjectRegistryRefusal, type RegistryHealStop, type RegistryWriteThroughRequest } from './protocol-registry-hydration.js';
import type { HealPackageBinding } from './protocol-heal-binding.js';
// [#29985 codemod] Save refusals, saveMetaItem, saveConflict, migrateStoredMetadata: the members below delegate to its facet, `ProtocolSaveFacet`.
import { ProtocolSaveFacet } from './protocol-save.js';
import { ProtocolSaveFacet, packagelessRowHeldBaseDraftAddress } from './protocol-save.js';
// [#29985 codemod] History, publish, drafts, publish backfill: the members below delegate to its facet, `ProtocolHistoryAndPublishFacet`.
import { ProtocolHistoryAndPublishFacet } from './protocol-history-and-publish.js';
import type { RegistryQuestion } from './registry-question.js';
Expand Down Expand Up @@ -7976,7 +7976,12 @@ export class ObjectStackProtocolImplementation implements
getOverlayRepo: (...a) => this.getOverlayRepo(...a),
readItemActiveRows: (...a) => this.readItemActiveRows(...a),
};
return packagelessDraftAddress.call(host, type, name, member, body);
// [#35524] …at the draft address the read naming no package takes
// there: the row-held base's, where the member's active rows are
// bound to one dependent only ({@link packagelessRowHeldBaseDraftAddress}).
return packagelessRowHeldBaseDraftAddress(
protocolHost(this), type, name, member, packagelessDraftAddress.call(host, type, name, member, body),
);
}

/**
Expand Down
Loading
Loading