Skip to content
Draft
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
19 changes: 19 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,19 @@
---
'@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 the item's canonical member as a stored row, an authored package that declares the base holds a stored row of another 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.

**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).
81 changes: 71 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,11 @@ 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.
let followedBase: string | undefined;
if (draftAddress?.kind === 'ambiguous') {
if (draftAddress !== undefined && (draftAddress.kind === 'ambiguous' || draftAddress.into !== null)) {
const base = await packagelessRowHeldBaseAddress(
host, singularType, request.name, itemDiscriminator(singularType, request.item),
);
Expand Down Expand Up @@ -3247,18 +3259,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 +3307,48 @@ 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, 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=`.
*
* `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, and every cell that judgment
* declines.
*
* FROM (`main` a73edb3cd7): the bare draft save wrote the dependent's draft
* there 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' || address.into === null) 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