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
25 changes: 25 additions & 0 deletions .changeset/32606-declared-row-not-moved-to-addition.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
---
'@objectstack/metadata-protocol': minor
---

fix(metadata-protocol)!: a row of an App's `.custom` pair declared for a package that still ships the name is never served at a bundle addition's address as its own item (ADR-0150 D4, #32606)

Clause-②: no
Metadata-protocol: semantic
Skills-docs: none — `skills/**` and `content/docs/**` teach a declared override served at the package it declares and a tenant's edit following an item that moved between an App's packages (#31593); neither teaches a row declared for one package served at another that still ships nothing of the row's member, so no taught sentence moves.

<!-- adr-0087: registered declared-row-not-moved-to-addition -->

**BREAKING** for a reader of a bundle addition's member: an App `A` with module packages X and Z, Z depending on A and X; X ships `welcome` in `en-US`, Z ships only `fr-FR` (a bundle addition to X's template), and `A.custom` stores a `fr-FR` row declaring `overrides: { package: X }`.

The moved-edit rule (#31593, `isMovedOverrideRowOf` / `isMovedBaseRowOf`) serves a row that declares, or is bound to, a former owner of an item at the package that ships the item now. It asked whether the former owner still ships the item at the MEMBER's grain, so X (which ships `en-US`, not `fr-FR`) read as a package that no longer ships it, and Z took the row as its own moved edit. The rule now asks the former owner at the NAME's grain, as its own header states ("the old owner must not ship the name"): X still holds `welcome`, so the row stays X's alone.

**Every moved answer, before → after.** Both registration orders (Z installed first, the row stored first). First-party count 0: no first-party App stores a pair row declaring one module at a locale another module adds.

- `GET /meta/email_template/welcome?package=Z&member=fr-FR`: the row declared for X, stamped Z, `_diagnostics.valid: false` → Z's own `fr-FR`, which is what the registry answers at Z (`getPackageScopedItem`).
- `GET /meta/email_template?package=Z` (Z's list) and the execution list a send resolved to Z reads (`getMetaItemsForExecution`): the row declared for X → Z's own `fr-FR`. A send resolved to Z sent X's customization of a member Z ships.
- `listServedOverrides({ packageId: Z })` (the customizations read): the same row is no longer listed under Z.

**Not moved.** X's address, X's list and X's execution list serve the row declared for X, as before. `?package=A.custom` serves it. The read naming no package keeps its 409 naming both holders. A former owner that ships nothing of the name any more still hands its edit to the package that ships it now (#31593's flat → composed and composed → flat moves, and a member that moved together with its whole bundle), pinned as a CONTROL in both orders.

The fix for a reader: read the row at the package it declares (`?package=X`). To customize Z's own member, save a row declaring Z.
10 changes: 10 additions & 0 deletions .changeset/32606-declared-row-semantic-entry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
'@objectstack/spec': patch
---

docs(spec): the protocol upgrade guide names what a bundle addition's address and lists answer for an App pair row declared for a package that still ships the name: the addition's own member (ADR-0150 D4, #32606)

Clause-②: no
Metadata-protocol: none

The semantic entry `declared-row-not-moved-to-addition` (`packages/spec/src/migrations/entries/semantic/18.declared-row-not-moved-to-addition.ts`) registers the change `.changeset/32606-declared-row-not-moved-to-addition.md` declares (ADR-0087, `adr-0087: registered`): no automatic rewrite, since every stored row keeps its shape and its binding. It adds no key and no export.
10 changes: 7 additions & 3 deletions packages/metadata-protocol/src/protocol-environment-rows.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ import { overlayMemberWhere } from './migrations/overlay-index.js';
import type { ObjectStackProtocolImplementation } from './protocol.js';
import { rowMatchesOverlayWhere, servedOverlayRowCandidates } from './protocol.js';
import { holdsServedOverlayCandidate } from './protocol-overlay-merge.js';
import type { ShipsName } from './suite-moved-overlay.js';
import { installedManifestsOfEngine } from './installed-manifests.js';

/**
Expand Down Expand Up @@ -122,10 +123,13 @@ export async function findServedOverlayRow(
const installed = installedManifestsOfEngine(this.engine);
// [#31593] The code packages that ship the item, read once, when a
// moved edit of it can be a candidate (`suite-moved-overlay.ts`).
// [#32606] Two grains: the item (its member) for the address's package,
// the name (any member) for the former owner ({@link ShipsName}).
let shippers: ReadonlySet<string> | undefined;
const ships = (packageId: string): boolean => {
shippers ??= shippingPackageIds(this.shippedArtifactsOf(args.type, args.name, undefined, args.member));
return shippers.has(packageId);
let nameShippers: ReadonlySet<string> | undefined;
const ships: ShipsName = {
item: (packageId) => (shippers ??= shippingPackageIds(this.shippedArtifactsOf(args.type, args.name, undefined, args.member))).has(packageId),
name: (packageId) => (nameShippers ??= shippingPackageIds(this.shippedArtifactsOf(args.type, args.name))).has(packageId),
};
for (const candidate of servedOverlayRowCandidates({ packageId: args.packageId, servedOverride: args.servedOverride, installed, ships })) {
const type = candidate.spelling === 'canonical' ? args.type : other;
Expand Down
9 changes: 7 additions & 2 deletions packages/metadata-protocol/src/protocol-meta-list-reads.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,11 @@ export async function readFlattenedMetaItems(host: Pick<ProtocolHost, 'artifactL
// the list's membership stays the items the package ships. A stand-in
// no layer seated is recorded here and dropped after the last merge.
const unseated = packageId ? new WeakSet<object>() : undefined;
// [#32606] A moved edit's former owner is asked whether it ships any
// member of the name over the registry the list serves, not over the
// merge's base items, which a scoped list draws from one package alone.
const shipsName = (name: string, shipper: string): boolean =>
shippingPackageIds(host.shippedArtifactsOf(request.type, name)).has(shipper);
try {
// [#21442] The row set this read consults — the overlay cache
// included — is {@link readActiveOverlayRows}, and each row is
Expand Down Expand Up @@ -294,7 +299,7 @@ export async function readFlattenedMetaItems(host: Pick<ProtocolHost, 'artifactL
return host.foldObjectExtendersFromRegistry(
request.type, (data as { name?: unknown } | null)?.name, data, onlyExtensionsOf,
);
}, unseated, { servedOverride, installed });
}, unseated, { servedOverride, installed, shipsName });

// [#13407] Expand any aggregated `defineView` container this
// READ just merged in, INLINE into this response's own `items`
Expand Down Expand Up @@ -602,7 +607,7 @@ export async function readFlattenedMetaItems(host: Pick<ProtocolHost, 'artifactL
items = mergePackageAwareOverlay(request.type, items, drafts, (data) => {
if (data && typeof data === 'object') (data as any)._draft = true;
return data;
}, unseated, { servedOverride, installed });
}, unseated, { servedOverride, installed, shipsName });
}
} catch (error) {
// [#5532] Same rule as the active-overlay read above. Serving
Expand Down
53 changes: 48 additions & 5 deletions packages/metadata-protocol/src/protocol-overlay-merge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,14 @@ export function mergePackageAwareOverlay(
* ({@link servedOverlayRowCandidates}).
*/
readonly installed: InstalledManifestLookup;
/**
* [#32606] Whether `packageId` ships any member of `name` in the
* registry the list serves, the grain a moved edit's former owner
* is asked at ({@link ShipsName}). The merge also reads its own
* base items; a list scoped to one package names this, since the
* former owner's items are not among its base items.
*/
readonly shipsName?: (name: string, packageId: string) => boolean;
} = {},
): unknown[] {
// Per-SLOT, layer-ordered contributions; `pkg: undefined` = package-less.
Expand All @@ -397,13 +405,43 @@ export function mergePackageAwareOverlay(
const disc = itemDiscriminator(type, item);
return disc === undefined ? String(name) : `${String(name)}\u0000${disc}`;
};
const push = (slot: string, pkg: string | undefined, item: any, stored?: StoredRowPlace, standIn?: boolean) => {
// [#32606] The name each slot is of, so a slot's name grain reads its
// sibling members' slots too.
const slotName = new Map<string, string>();
const slotOfList = new WeakMap<readonly Contribution[], string>();
const push = (slot: string, pkg: string | undefined, item: any, stored?: StoredRowPlace, standIn?: boolean, name?: unknown) => {
let list = buckets.get(slot);
if (!list) { buckets.set(slot, (list = [])); order.push(slot); }
if (!list) { buckets.set(slot, (list = [])); order.push(slot); slotOfList.set(list, slot); }
if (typeof name === 'string' && !slotName.has(slot)) slotName.set(slot, name);
const c: Contribution = stored ? { pkg, item, stored } : { pkg, item };
if (standIn) c.standIn = true;
list.push(c);
};
// [#32606] The code packages that ship any member of the name `list`'s
// slot is of: the lower-layer contributions of every slot of that name,
// read once after every contribution is in.
let byName: Map<string, Set<string>> | undefined;
const nameShippersOf = (list: readonly Contribution[]): ReadonlySet<string> => {
if (byName === undefined) {
byName = new Map();
for (const [slot, l] of buckets) {
const name = slotName.get(slot);
if (name === undefined) continue;
const set = byName.get(name) ?? new Set<string>();
for (const c of l) if (c.stored === undefined && !c.standIn && c.pkg !== undefined) set.add(c.pkg);
byName.set(name, set);
}
}
const name = slotName.get(slotOfList.get(list) ?? '');
return (name === undefined ? undefined : byName.get(name)) ?? new Set();
};
// …and the caller's reading of the registry, for a list whose base items
// are one package's alone (a list scoped to the package): the former
// owner's members are not among them.
const nameShippedBy = (list: readonly Contribution[], packageId: string): boolean => {
const name = slotName.get(slotOfList.get(list) ?? '');
return name !== undefined && options.installed !== undefined && options.shipsName?.(name, packageId) === true;
};
// [#21804] The stored row the served-row resolution picks for package
// `real` among a slot's contributions: the first candidate of
// {@link servedOverlayRowCandidates} that one of the rows sits at.
Expand All @@ -418,7 +456,12 @@ export function mergePackageAwareOverlay(
const shippers = new Set(list
.filter((c) => c.stored === undefined && !c.standIn && c.pkg !== undefined)
.map((c) => c.pkg as string));
const ships = (packageId: string): boolean => shippers.has(packageId);
// [#32606] …and the code packages that ship ANY member of the slot's
// name, the grain a former owner is asked at ({@link ShipsName}).
const ships: ShipsName = {
item: (packageId) => shippers.has(packageId),
name: (packageId) => nameShippersOf(list).has(packageId) || nameShippedBy(list, packageId),
};
for (const candidate of servedOverlayRowCandidates(options.installed !== undefined
? { packageId: real, servedOverride: options.servedOverride, installed: options.installed, ships }
: { packageId: real })) {
Expand Down Expand Up @@ -448,7 +491,7 @@ export function mergePackageAwareOverlay(
const itemName = listSlotNameOf(canonicalType, item);
if (itemName !== undefined) {
push(slotOf(item, itemName), (item._packageId ?? undefined) as string | undefined, item,
undefined, unseated?.has(item));
undefined, unseated?.has(item), itemName);
}
}
for (const { data, packageId, stored, standIn } of records) {
Expand Down Expand Up @@ -486,7 +529,7 @@ export function mergePackageAwareOverlay(
// package's slot below. A record that is not a stored row (a caller's
// item, slotted by its own `_packageId`) enters as it is.
const bound = stored ? withRowBinding(body, packageId) : body;
push(slot, packageId, transform ? transform(bound, prev) : bound, stored, standIn);
push(slot, packageId, transform ? transform(bound, prev) : bound, stored, standIn, bodyName);
}

const out: unknown[] = [];
Expand Down
12 changes: 9 additions & 3 deletions packages/metadata-protocol/src/protocol-served-overrides.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ import { storedRowDocument } from './item-lock.js';
import type { ObjectStackProtocolImplementation } from './protocol.js';
import { holdsServedOverlayCandidate, servedOverlayRowCandidates } from './protocol-overlay-merge.js';
import { shippingPackageIds } from './protocol-environment-rows.js';
import { isMovedOverrideRowOf } from './suite-moved-overlay.js';
import { isMovedOverrideRowOf, type ShipsName } from './suite-moved-overlay.js';
import { installedManifestsOfEngine } from './installed-manifests.js';

/** The class members {@link listServedOverrides} reads, typed as the class declares them. */
Expand Down Expand Up @@ -160,9 +160,15 @@ export async function listServedOverrides(
// The code packages that ship the item, read once per item and only
// when a moved edit is in question (the by-name read's own reading).
let shippers: ReadonlySet<string> | undefined;
let nameShippers: ReadonlySet<string> | undefined;
const shippersOf = (): ReadonlySet<string> =>
(shippers ??= shippingPackageIds(this.shippedArtifactsOf(type, name, undefined, member)));
const ships = (packageId: string): boolean => shippersOf().has(packageId);
// [#32606] The item's grain for the address's package, the name's for
// a former owner (`ShipsName`).
const ships: ShipsName = {
item: (packageId) => shippersOf().has(packageId),
name: (packageId) => (nameShippers ??= shippingPackageIds(this.shippedArtifactsOf(type, name))).has(packageId),
};
let served: any;
for (const candidate of servedOverlayRowCandidates({ packageId: base, servedOverride: true, installed, ships })) {
// Only the pair's candidates: the base's own row, the
Expand All @@ -176,7 +182,7 @@ export async function listServedOverrides(
// A declared override the base no longer ships, which a package
// shipping the item now holds as its moved edit, is that
// package's: listed there, never also here.
if (candidate.moved === undefined && !ships(base)
if (candidate.moved === undefined && !ships.item(base)
&& [...shippersOf()].some((now) => now !== base && isMovedOverrideRowOf(served, now, installed, ships))) {
served = undefined;
}
Expand Down
31 changes: 25 additions & 6 deletions packages/metadata-protocol/src/suite-moved-overlay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,28 @@ import { storedRowDocument } from './item-lock.js';
import { isServedOverrideRowOf, type ServedOverrideRow } from './served-override.js';

/**
* Whether a code package ships the item being read (its type, name and
* bundle member) in the registry the read serves: the caller's reading,
* from the shipped artifacts it already weighs for the address.
* Which code packages ship the item being read, in the registry the read
* serves: the caller's reading, from the shipped artifacts it already weighs
* for the address. Two grains, because the two packages a move names are
* asked different questions:
*
* - `item`: whether a package ships the item itself (its type, name and
* bundle member). The address's package must, to be the item's owner now.
* - `name`: whether a package ships ANY member of the name. [#32606] The
* former owner is asked at this grain: a package that still ships the name
* still holds it (ADR-0150 D3), so a row declaring it, or bound to it, is
* that package's own edit, served at its address (an added member's
* declared override, #28802), never another package's moved edit as well.
* Asked at the member's grain, a bundle addition that ships only the
* member (`fr-FR` beside the former owner's `en-US`) took the row as its
* own: one row served at two packages' addresses (red line 2).
*
* For a type that is not a bundle the two answer alike.
*/
export type ShipsName = (packageId: string) => boolean;
export interface ShipsName {
readonly item: (packageId: string) => boolean;
readonly name: (packageId: string) => boolean;
}

/** The row's body as a plain object, or `undefined` when it is not one. */
function documentOf(row: ServedOverrideRow): Record<string, unknown> | undefined {
Expand Down Expand Up @@ -120,6 +137,7 @@ function ofOneApp(a: string, b: string, installed: InstalledManifestLookup): boo
* | row (in `app.custom`) declares | base | installed | ships | answer |
* |:--|:--|:--|:--|:--|
* | `app` | `app.service` | both, `app.service` declares `app` | `app.service` only | `true` (flat → composed) |
* | `X` (a module), member `fr-FR` | `Z` (a bundle addition of `X`'s name) | both | `Z` ships `fr-FR`, `X` ships `en-US` | `false` — `X` still ships the name (#32606) |
* | `app.service` | `app` | `app` only | `app` | `true` (composed → flat) |
* | `app` | `app` | — | — | `false` — `isServedOverrideRowOf`'s own row |
* | `app` | `app.service` | both | both | `false` — `app` still ships it |
Expand All @@ -139,7 +157,7 @@ export function isMovedOverrideRowOf(
if (declaration === null || typeof declaration !== 'object' || Array.isArray(declaration)) return false;
const former = (declaration as { package?: unknown }).package;
if (typeof former !== 'string' || former === '' || former === base) return false;
if (!ships(base) || ships(former)) return false;
if (!ships.item(base) || ships.name(former)) return false;
if (installed(former) !== undefined && !ofOneApp(former, base, installed)) return false;
// THE predicate, asked of the row as if its declaration named `base`.
const asBase = { ...body, overrides: { ...(declaration as object), package: base } };
Expand All @@ -157,6 +175,7 @@ export function isMovedOverrideRowOf(
* |:--|:--|:--|:--|
* | `app` (installed) | `app.service` (declares `app`) | `app.service` only | `true` |
* | `app` | `app.service` | both | `false` — `app` still ships it |
* | `X`, member `fr-FR` | `Z` (ships `fr-FR`; `X` ships `en-US`) | `Z` at the member, both at the name | `false` — `X` still ships the name (#32606) |
* | `partner.ext` (installed, its own App) | `app.service` | `app.service` | `false` — another App |
* | `app.old` (not installed) | `app` | `app` | `false` — no install record names its App |
* | `app.custom` | `app.service` | `app.service` | `false` — a pair's row is {@link isMovedOverrideRowOf}'s |
Expand All @@ -172,7 +191,7 @@ export function isMovedBaseRowOf(
const former = row.package_id;
if (typeof former !== 'string' || former === '' || former === base || isCustomizationPackage(former)) return false;
if (!overridableType(row.type)) return false;
if (!ships(base) || ships(former)) return false;
if (!ships.item(base) || ships.name(former)) return false;
if (!ofOneApp(former, base, installed)) return false;
const body = documentOf(row);
return body !== undefined && !('overrides' in body);
Expand Down
Loading
Loading