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
23 changes: 23 additions & 0 deletions .changeset/33210-packageless-row-two-holders.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
---
'@objectstack/metadata-protocol': patch
'@objectstack/spec': patch
---

fix(metadata-protocol)!: the bare item read refuses a package-less row beside two packages' rows, and reads a row-held base at its dependent's added member (ADR-0150 D3, red line 2)

Clause-②: no (narrowing)
Metadata-protocol: none
Skills-docs: none — `skills/objectstack-platform/SKILL.md` (the ADR-0146 paragraph) and `content/docs/concepts/metadata-lifecycle.mdx` teach that a locale a dependent adds under a base's name is served only under its own `?package=`, and that the read naming no package answers `404` for it. Both sentences were true only for a base that ships the name, and are now true for a row-held base too, at a dependent's named locale other than the canonical one, however many dependents each add one. Nothing in `skills/**` or `content/docs/**` teaches what the read naming no package answers for a package-less row beside two packages' rows. No taught sentence moves.

<!-- adr-0087: registered row-held-base-addition-bare-read-at-base, two-row-holders-bare-read-refused -->

**BREAKING**: two answers of the `/meta` item read that names no package move from served to refused. Name the package (`?package=`) to read the row, as before.

**Every moved answer, before → after.** Both transports (`RestServer` and the runtime `HttpDispatcher`), every save order, both registration orders, and on the runtime dispatcher before and after a reboot. First-party count 0: no first-party app stores either shape.

- **A package-less row beside two packages' rows of a name no package ships** (packages E and F each store a row of `dash`, and a package-less row of `dash` is stored too). The plain read `GET /meta/dashboard/dash`, `GET /meta/dashboard/dash/published` and the execution read move FROM the row stored first (E's, F's or the package-less one) TO `409 RESOURCE_CONFLICT` naming E and F in `details.candidates`. `GET /meta/dashboard/dash/layers` already refused it, and still does with the package-less writes' sentence. The package-less row is never served in their place: it is a customization of a name it cannot say whose (red line 2). After a reboot, the registry's environment item of such a name is the bare slot's entry, the row hydrated last. With rows bound to two or more packages beside it, that entry no longer counts as the environment's own item.
- **A member that only a dependent's addition holds, over a base that holds the name only as stored rows** (base A stores `welcome` in `en-US`, dependent D, which declares A, stores `fr-FR`, and no package ships `welcome`). `GET /meta/email_template/welcome?member=fr-FR`, `GET /meta/email_template/welcome/layers?member=fr-FR` and the execution read at `fr-FR` move FROM D's row (200) TO `404 RESOURCE_NOT_FOUND`. That is the answer the same reads already gave when A ships `welcome`: a bundle addition holds no name, so the read takes the base's address, which holds no `fr-FR`. Each dependent is judged against its own declared dependencies, so with a second dependent D2 storing `de-DE` the reads at `fr-FR` and at `de-DE` both answer `404`, in either registration order. A dependent that also stores a member the base stores (D storing `en-US` as well as `fr-FR`) is still an addition, as the registry judges it (a member held only as stored rows is no clash), so its `fr-FR` answers `404` too.

**Not moved.** One package's row beside a package-less row is that package's, served on every bare door in both save orders, before and after a reboot. Each exact address (`?package=E`, `?package=F`, `?package=D&member=fr-FR`) serves its own row. The base's own member (`?member=en-US`) is the base's; where the dependent stores it too over a row-held base, the read there refuses naming both, as before. The read naming no member (the canonical member, `GET /meta/email_template/welcome` and `/published`) is not moved, even where a dependent stores the canonical member over a row-held base that holds only another one. A name with a disabled holder keeps its own judgment (#32354), and a package-less row beside a disabled holder leaves the read as it was (that shape, with the plain read following save order while `/layers` refuses, is #34440). The canonical member of a shipped base that holds only another member answers differently before and after a restart (#34441); this change does not move it. The writes do not move: in the first shape the save naming no package was already refused `409 RESOURCE_CONFLICT` naming E and F, writing nothing, and still is, so it now agrees with the read. A save that edits a package-unbound row while the read refuses is another shape, two enabled packages that ship the name with no package's row stored (#34348, decision open); this change does not move it either.

The ADR-0087 entry `row-held-base-addition-bare-read-at-base` registers the second move. The first is the narrowing `two-row-holders-bare-read-refused` already registers: two or more enabled packages hold the name only as stored rows. That entry's `reason` now says how the holders are judged: by the packages the rows are bound to at the member read, with the registry's holders only helping recognise a customization pair.
159 changes: 149 additions & 10 deletions packages/metadata-protocol/src/protocol-meta-item-face.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ import type { ObjectStackProtocolImplementation } from './protocol.js';
import { shippingPackageIds } from './protocol-environment-rows.js';
import { bundleMemberDiscriminator, resolveBundleMemberSelector } from './protocol-bundle-members.js';
import { installedManifestsOfEngine } from './installed-manifests.js';
import { pairsOf } from '@objectstack/metadata-core';
import { packageDependencyClosure, pairsOf, type PackageClosureRegistry } from '@objectstack/metadata-core';
import { disabledExactAddressHolder } from './protocol-exact-qualifier.js';
import type { PrereadActiveRows } from './protocol-meta-item-reads.js';
import { PLURAL_TO_SINGULAR } from '@objectstack/spec/shared';
import { overlayMemberWhere } from './migrations/overlay-index.js';
import { overlayMemberValue, overlayMemberWhere } from './migrations/overlay-index.js';
import { isServedOverrideRowOf } from './served-override.js';
import {
isActionWithheldByDisabledPackage,
Expand Down Expand Up @@ -274,7 +274,12 @@ const SERVED_HOLDER_JUDGED_ELSEWHERE: ReadonlySet<string> = new Set(['object', '
* it: {@link servedHolderAddressOf} and `packagelessContentPackage` judge
* it), and when no package-less row and no
* environment item is stored (a customization of no one holder, judged as
* before). Then the holders are the registry's served holders and the
* before). [#33210] On the item face (`options.refuseWithoutDisabled`) a
* package-less row, or the registry's environment item, beside rows bound to
* two or more packages with no disabled package among them is judged with
* those rows instead ({@link storedRowHoldersRefusal}), so it is refused
* naming them; beside one holder, none, or a disabled holder the read is left
* as it was. Then the holders are the registry's served holders and the
* packages the active rows are bound to, less every disabled package:
*
* - one → `{ kind: 'served' }`, read at its address, as the registry's
Expand Down Expand Up @@ -332,9 +337,9 @@ export async function servedRowHolderOf(
return undefined;
}
if ([...shippingPackageIds(host.shippedArtifactsOf(type, name, undefined, member))].some((id) => !disabled(id))) return undefined;
if (typeof registry.getEnvironmentScopedItem === 'function' && registry.getEnvironmentScopedItem(type, name, member) !== undefined) {
return undefined;
}
const environmentItem = typeof registry.getEnvironmentScopedItem === 'function'
&& registry.getEnvironmentScopedItem(type, name, member) !== undefined;
if (environmentItem && options.refuseWithoutDisabled !== true) return undefined;
// The item's active rows, read once: every row binds a holder, and only
// the rows the reads serve make a served one (S4). An unprovisioned store
// holds no row.
Expand All @@ -346,10 +351,21 @@ export async function servedRowHolderOf(
activeRows = [];
}
const rows = await host.packagelessAddress(type, name, member, 'active', activeRows);
if (rows.unbound) return undefined;
// [#33210, ADR-0150 D3] The registry's environment item of a name no
// package ships is the bare slot's entry, the row hydrated last: after a
// reboot that is the package-less row whenever it was saved last. Beside
// rows bound to two or more packages it is no environment item but a
// customization of a name it cannot say whose, judged with them below, so
// the answer follows no save order. Otherwise the environment's own item
// leaves the read as it was.
if (environmentItem && !(rows.unbound && rows.candidates.length > 1)) return undefined;
const every: readonly string[] = registry.packageScopedHoldersOf(type, name, null, { includeDisabledPackages: true }) ?? [];
const anyDisabled = [...every, ...rows.candidates].some(disabled);
// [#33210] The no-disabled arm judges a package-less row itself
// ({@link storedRowHoldersRefusal}); beside a disabled holder it leaves
// the read as it was.
if (!anyDisabled) return options.refuseWithoutDisabled === true ? storedRowHoldersRefusal(host, type, name, member, every, activeRows, rows.candidates) : undefined;
if (rows.unbound) return undefined;
const installed = installedManifestsOfEngine(host.engine);
const pairRow = (row: { package_id?: unknown }): boolean =>
typeof row.package_id === 'string' && every.some((holder) => pairsOf(holder, installed).includes(row.package_id as string));
Expand Down Expand Up @@ -406,7 +422,13 @@ const STORED_ROW_HOLDERS_REFUSAL: unique symbol = Symbol.for('objectstack.metada
* ({@link ObjectStackProtocolImplementation.declinesStoredRow}) and a row of a
* customization pair of another package the rows or the registry name
* (`pairsOf`), which is that package's customization, never a holder of its
* own. An unbound package-less row among them leaves the read as it was.
* own.
*
* [#33210, ADR-0150 red line 2] A package-less row among them is no holder
* and no tie-break: beside two or more holders the read is refused naming
* them, as `/layers` refuses the same rows (`packagelessLayeredReadRefusal`),
* where it served a row by store order; beside one holder or none it leaves
* the read as it was.
*/
async function storedRowHoldersRefusal(
host: ServedRowHost,
Expand All @@ -423,7 +445,13 @@ async function storedRowHoldersRefusal(
&& known.some((holder) => holder !== row.package_id && pairsOf(holder, installed).includes(row.package_id as string));
const holding = await host.packagelessAddress(type, name, member, 'active', activeRows.filter((row) =>
!host.declinesStoredRow(type, name, row) && !pairOfAnother(row)));
if (holding.unbound) return undefined;
// [#33210, ADR-0150 red line 2] A package-less row beside two or more
// holders is a customization of a name it cannot say whose (the
// registry binds it to no package): reading past it still leaves those
// holders, so it is refused naming them below, as `/layers` refuses it,
// and never served in their place. Beside one holder or none it leaves
// the read as it was.
if (holding.unbound && holding.candidates.length < 2) return undefined;
// [#32662 scope note (b), ADR-0150 D3] One holder whose rows are its own
// and its customization pair's: the read is that holder's, at its address,
// as `/published` reads it, so the layer served is its own row in both
Expand Down Expand Up @@ -572,6 +600,111 @@ export async function declaredMemberOverrideAddressOf(
: undefined;
}

/**
* [#33210 (c), ADR-0150 D3, #28802 R2] The address a read naming no package
* takes for a bundle member that only a dependent's ADDITION holds, over a
* base that holds the name only as stored rows: that base. The read then
* answers the base's member, which it does not hold (404), as it does when the
* base ships the name, where `packagelessContentPackage` reads the shipper.
* `undefined` leaves the read as it was.
*
* Measured on `main` 66f6638fa4, on a booted kernel, before and after a
* reboot. Base A holds `welcome` in `en-US`, and dependent D, which declares
* A, holds `fr-FR`. When A ships `en-US`, the plain read, `/layers` and the
* execution face at `fr-FR` answered 404. When A holds `en-US` only as a
* stored row, all three served D's row. In both, the registry named A the
* name's one holder (a bundle addition holds no name). The two differed only
* in the grain the base was read at: the shippers at the name, the rows'
* bindings at the member.
*
* Judged at the rows' grain, as the registry judges an addition
* (`isBundleAddition`, read by `packageScopedHoldersOf`). Every active row at
* the member is bound to a package, and none is declined
* ({@link ObjectStackProtocolImplementation.declinesStoredRow}). Each package
* holding members of the name as active rows is judged against its OWN
* declared dependency closure: it is an addition when some other row-holding
* package B is in that closure and it is not in B's. [#33210 contract review
* S2] A member both hold is no clash here: the registry counts a clash only
* at a member either package ships in code (`codeMembersOf`, #33127), and
* this arm runs only for a name no package ships, so a member two packages
* hold only as stored rows never clashes. A dependent that also stores a
* member the base stores (D's `en-US` and `fr-FR` over A's `en-US`) stays an
* addition, as the registry names A the one holder there; the read at the
* shared member is left to the rows' own judgment (A holds a row there). The
* base is the one row-holding package that is no addition;
* the read is moved only when there is exactly one, it holds no row at the
* member, and no package at the member is a customization pair of another
* row-holding package (`pairsOf`: a pair's added member is served on its
* base's address already, #28802 ruling A). So a second dependent adding a
* member of its own (D1 `fr-FR`, D2 `de-DE` over A's `en-US`) leaves A the
* base at each dependent's member, as the registry names A the one holder
* whichever packages are installed, and a dependent of a dependent is an
* addition to it. The arm applies only to a bundled type the registry reads
* by package, for a name no package ships (a shipped name is the shipper's
* already), at a named member other than the canonical one, with no
* environment item at the member and no disabled package among the
* row-holding packages (the served-holder judgment above reads those).
*/
export async function rowHeldBaseAddressOf(
host: ServedRowHost,
type: string, name: string, member: string | undefined,
): Promise<string | undefined> {
const registry: any = host.engine?.registry;
if (typeof registry?.readsByPackage !== 'function' || registry.readsByPackage(type) !== true) return undefined;
const singular = PLURAL_TO_SINGULAR[type] ?? type;
// [#33210 contract review S1] A NAMED non-canonical member only.
// `overlayMemberValue` answers null for the canonical member, named or
// not, and the read naming no member addresses it (reachable without
// `?member=` and from `/published`). That mirror is left as it was: with
// a shipped base holding only another member, its answers move across a
// reboot and the read naming no member serves the base's other member,
// so there is no one shipped answer to align it with.
if (typeof overlayMemberValue(singular, member) !== 'string') return undefined;
if (shippingPackageIds(host.shippedArtifactsOf(type, name)).size > 0) return undefined;
if (typeof registry.getEnvironmentScopedItem === 'function' && registry.getEnvironmentScopedItem(type, name, member) !== undefined) {
return undefined;
}
let activeRows: Awaited<ReturnType<ServedRowHost['readItemActiveRows']>>;
try {
activeRows = await host.readItemActiveRows(type, name);
} catch (error) {
host.rethrowUnlessMetadataStoreUnprovisioned(error, 'sys_metadata');
activeRows = [];
}
const rows = activeRows.filter((row) => rowMatchesOverlayWhere(row, { type: singular, name, state: 'active' }));
const memberWhere = { type: singular, name, state: 'active', ...overlayMemberWhere(singular, member) };
const atMember = rows.filter((row) => rowMatchesOverlayWhere(row, memberWhere));
const packageOf = (row: { package_id?: unknown }): string | undefined =>
typeof row.package_id === 'string' && row.package_id !== '' ? row.package_id : undefined;
if (atMember.length === 0 || atMember.some((row) => packageOf(row) === undefined || host.declinesStoredRow(type, name, row))) {
return undefined;
}
const holders = [...new Set(rows
.filter((row) => !host.declinesStoredRow(type, name, row))
.map(packageOf)
.filter((id): id is string => id !== undefined))];
if (typeof registry.isPackageDisabled === 'function' && holders.some((id) => registry.isPackageDisabled(id) === true)) {
return undefined;
}
const closure = (id: string): readonly string[] => packageDependencyClosure(id, registry as PackageClosureRegistry)?.dependencies ?? [];
// [#33210 contract review M1] Each package against its own closure, as
// `isBundleAddition` judges it: an addition to ANY other holder it
// declares, never to one base every package must share. [S2] No member
// clashes: no package ships the name here, and the registry's clash is
// a member shipped in code (`codeMembersOf`), never one held only as
// stored rows.
const isAdditionTo = (id: string, other: string): boolean => other !== id
&& closure(id).includes(other) && !closure(other).includes(id);
const bases = holders.filter((id) => !holders.some((other) => isAdditionTo(id, other)));
if (bases.length !== 1) return undefined;
const [base] = bases;
const additions = new Set(atMember.map((row) => packageOf(row)!));
if (additions.has(base)) return undefined;
const installed = installedManifestsOfEngine(host.engine);
const isPairOfAHolder = (id: string): boolean => holders.some((other) => other !== id && pairsOf(other, installed).includes(id));
return [...additions].some(isPairOfAHolder) ? undefined : base;
}

/** The body of `ObjectStackProtocolImplementation#readMetaItemFace`; the method's docblock there is its contract. */
export async function readMetaItemFace(
this: Pick<MetaItemFaceHost, 'readMetaItem'> & ServedRowHost,
Expand Down Expand Up @@ -612,10 +745,16 @@ export async function readMetaItemFace(
// [#32849] …and a member whose one shipper's declared override is stored
// is read at that shipper ({@link declaredMemberOverrideAddressOf}).
const member = request.packageId ? undefined : resolveBundleMemberSelector(request.type, request.member);
// [#33210 (c)] …and a member only a dependent's addition holds, over a
// base holding the name only as stored rows, is read at that base
// ({@link rowHeldBaseAddressOf}), as it is when the base ships the name.
const servedAddress = request.packageId
? undefined
: await servedAddressOf(judgeHost, request.type, request.name, member, { refuseWithoutDisabled: true })
?? (request.state === 'draft' ? undefined : await declaredMemberOverrideAddressOf(judgeHost, request.type, request.name, member));
?? (request.state === 'draft'
? undefined
: await declaredMemberOverrideAddressOf(judgeHost, request.type, request.name, member)
?? await rowHeldBaseAddressOf(judgeHost, request.type, request.name, member));
const answer = await this.readMetaItem(servedAddress === undefined ? request : { ...request, packageId: servedAddress }, { face, ...(activeRows !== undefined ? { activeRows } : {}) });
// [#28877] The served read of an `action` also withholds one that launches
// into a disabled package, as the served list does.
Expand Down
Loading
Loading