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/34452-same-name-writes-and-hydration.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 writes, the restart and the action doors that name no package give the answer the read names

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

<!-- adr-0087: registered bare-write-beside-disabled-row-refused-naming-shippers, hydrated-doc-row-wears-no-holder-envelope, environment-action-on-another-object-answers-first, package-less-action-row-judged-at-its-key -->

**BREAKING** for a caller that writes or reads a shared name without naming a package, shipped as `patch`: no key an author writes changes (`Metadata-protocol: none`). Four doors that name no package answered by save or registration order, or disagreed with the read of the same name; each now gives the read's answer. Naming the package (`?package=ID`, or `packageId` in process) writes or reads that package's item exactly as before.

- **A bare write beside a disabled package's row** (#34346). Two enabled packages ship the name and its stored rows are bound to a disabled package and to one shipper, with no package-less row of the name. FROM the bare publish save answering 200 and writing that shipper's row, and the bare draft save and delete refusing naming that shipper and the disabled package, TO all three refusing `409 RESOURCE_CONFLICT` naming the two shippers, as the bare read does, never the disabled package, and writing or removing nothing.
- **A doc row hydrated after a restart beside two holders, a disabled one counted** (#34417, ruling 6942962369). FROM the row wearing the first registered holder's envelope, so `?package=FIRST` served the environment's row and every read naming no package refused 409, TO every read naming no package serving the environment's row and `?package=FIRST` serving that holder's own doc.
- **The environment's own action on another object** (#33904, ADR-0150 D4). A package holds an action name on one object (or object-less) and the environment stores its own package-less action of the name on another. FROM the plain read, `/layers` and `/published` naming no package serving the package's action, the merged list naming only it, and the bare delete removing the package's row, TO those reads serving the environment's action, the list naming both, and the bare delete removing the environment's row.
- **The merged action list where a package binds the object** (#33904, ADR-0150 D4). The list now slots an action at its `(package, objectName, name)` key wherever a package's action of the name binds the object, object-less being a key of its own. Three cells move with no environment-own action. Two packages hold the name on two objects and a package-less row is stored on one: FROM the row listed under both packages and the second package's own action dropped, TO the row listed under its object's package and the second package's own action listed. A list scoped to a package whose action is bound to one object, beside the environment's row on another: FROM that package's slot serving the environment's row, TO its own action. A platform action of the name (no package, no stored row) on one object, or object-less, beside a package's action on another object, or object-less: FROM the platform action dropped, TO both listed. Where no package holds the name, the list slots by name as before.
- **A package-less action row beside an enabled and a disabled holder on its object** (#34258). FROM the read naming no package answering 404 when the disabled holder registered first, TO 200 serving the row as the enabled holder's customization in both orders. And where every holder on the row's object is disabled while an enabled package holds the name on another object: FROM 200 serving the row (the name, not the key, was judged, and it had an enabled holder) TO 404, as a key whose every holder is disabled answers with no other holder of the name.

The registry's heal for a package-less overlay row whose every holder is disabled (#33127) now keeps it recorded with no holder, so enabling one holder rebuilds it under that holder's envelope; no door's answer moves.

The fix for a caller that relied on the old answer: name the package it means. `os migrate meta --from 18` lists the four entries.
29 changes: 22 additions & 7 deletions packages/metadata-protocol/src/protocol-artifact-lookup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,22 +84,37 @@ export function lookupArtifactItem(
// no envelope. A package-less item's holder is the ONE package whose own
// artifact is bound to the item's owner key; none, or two, and no
// artifact answers (an ambiguity is not guessed).
if (artifact !== undefined && boundObjectOf(artifact) === owner.object) return artifact;
if (currentPackageId) return undefined;
if (currentPackageId) return artifact !== undefined && boundObjectOf(artifact) === owner.object ? artifact : undefined;
const registry = (this.engine as any)?.registry;
if (typeof registry?.packageScopedHoldersOf !== 'function') return undefined;
// [#34258] With no package named, the by-name answer is the FIRST
// registered holder's artifact, so it is that answer only when no other
// package's artifact is bound to the key (below): two holders at the key,
// one disabled, wore the disabled one's envelope when it registered
// first, and the read withheld the environment's row with it.
const boundToKey = artifact !== undefined && boundObjectOf(artifact) === owner.object ? artifact : undefined;
if (typeof registry?.packageScopedHoldersOf !== 'function') return boundToKey;
let holders: unknown;
try {
holders = registry.packageScopedHoldersOf(singular, name, null, { includeDisabledPackages: true });
} catch {
return undefined;
return boundToKey;
}
const owners: unknown[] = [];
const owners: Array<{ _packageId?: unknown }> = [];
for (const packageId of new Set(Array.isArray(holders) ? holders : [])) {
const own = lookupArtifactItemByName.call(this, type, name, packageId, member) as { _packageId?: unknown } | undefined;
if (own?._packageId === packageId && boundObjectOf(own) === owner.object) owners.push(own);
if (own !== undefined && own._packageId === packageId && boundObjectOf(own) === owner.object) owners.push(own);
}
return owners.length === 1 ? owners[0] : undefined;
if (owners.length === 1) return owners[0];
// [#34258, #32354, ADR-0150 D3] …and of two or more, a disabled package
// holds no name: the ONE enabled package whose own artifact is bound to
// the key lends the envelope, as with the disabled holder absent. Two
// enabled, or none, and the answer is the one before #34258: the first
// holder's artifact when it is bound to the key (the bare read refuses two
// enabled holders before any envelope), else none.
const enabled = typeof registry.isPackageDisabled === 'function'
? owners.filter((own) => registry.isPackageDisabled(own._packageId) !== true)
: [];
return enabled.length === 1 ? enabled[0] : boundToKey;
}

/** The artifact {@link lookupArtifactItem} answers by name alone, as it did before #33456. */
Expand Down
29 changes: 25 additions & 4 deletions packages/metadata-protocol/src/protocol-diff-delete-load.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import { applyOldShapeFormRowRemovals, healOldShapeFormRowRemovals, type OldShap
import { overlayMemberWhere } from './migrations/overlay-index.js';
import {
historyRowsOfMember,
holdsEnvironmentOwnAction,
isVersionOf,
packagelessAddressAmbiguityRefusal,
versionNotFoundError,
Expand Down Expand Up @@ -67,7 +68,7 @@ import { withRefusalAudit } from './protocol-refusal-audit.js';
import { captureStoredExpressionChange, fillStoredExpressionChange } from './protocol-stored-expression-fill.js';
import type { RuntimeAuthoringIssue } from './runtime-authoring-gate.js';
import type { ProtocolHost } from './protocol-host.js';
import { packagelessHolderRefusal, packagelessRowHeldBaseAddress } from './protocol-save.js';
import { disabledRowHoldersRefusal, packagelessHolderRefusal, packagelessRowHeldBaseAddress } from './protocol-save.js';
import { isPlatformRecordRow } from '@objectstack/metadata';
import { retireOverlayCacheOnRollback } from './meta-overlay-cache.js';

Expand Down Expand Up @@ -729,7 +730,11 @@ export class ProtocolDiffDeleteLoadFacet {
if (draftAddress?.kind === 'ambiguous') {
const base = await packagelessRowHeldBaseAddress(host, singularTypeForRepo, request.name, member);
if (base === undefined) {
addressRefusal = packagelessAddressAmbiguityRefusal(
// [#34346] …naming the holders the read counts where a
// row is bound to a disabled package ({@link disabledRowHoldersRefusal}).
addressRefusal = disabledRowHoldersRefusal(
host, 'delete', request.type, singularTypeForRepo, request.name, member, draftAddress.candidates,
) ?? packagelessAddressAmbiguityRefusal(
'delete', request.type, request.name, draftAddress.candidates,
);
throw addressRefusal;
Expand All @@ -743,7 +748,13 @@ export class ProtocolDiffDeleteLoadFacet {
if (request.packageId == null && draftAddress === undefined && rowsAtAddress.candidates.length > 1) {
const base = await packagelessRowHeldBaseAddress(host, singularTypeForRepo, request.name, member);
if (base === undefined) {
addressRefusal = packagelessAddressAmbiguityRefusal(
// [#34346, ADR-0150 D3/D5] Rows bound to a disabled
// package too are refused naming the holders the read
// naming no package counts, never the disabled one
// ({@link disabledRowHoldersRefusal}).
addressRefusal = disabledRowHoldersRefusal(
host, 'delete', request.type, singularTypeForRepo, request.name, member, rowsAtAddress.candidates,
) ?? packagelessAddressAmbiguityRefusal(
'delete', request.type, request.name, rowsAtAddress.candidates,
);
throw addressRefusal;
Expand Down Expand Up @@ -790,8 +801,18 @@ export class ProtocolDiffDeleteLoadFacet {
throw addressRefusal;
}
}
// [#33904, ADR-0150 D4, ruling 6942962369] A delete naming no
// package of an action whose package-unbound row is the
// environment's own item, on an object no package's row binds
// ({@link holdsEnvironmentOwnAction}), removes that row: the
// environment's own item answers first, as on the read naming
// no package. It removed the one package's row the rows are
// bound to, on another object, and left the environment's.
const environmentAction = request.packageId == null && targetState === 'active' && rowsAtAddress.unbound
&& singularTypeForRepo === 'action' && rowsAtAddress.candidates.length > 0
&& holdsEnvironmentOwnAction(singularTypeForRepo, await host.readItemActiveRows(singularTypeForRepo, request.name));
const packageId: string | null = request.packageId
?? (draftAddress !== undefined ? draftAddress.key : rowsAtAddress.packageId);
?? (environmentAction ? null : draftAddress !== undefined ? draftAddress.key : rowsAtAddress.packageId);
// [ADR-0150 D2, #34401] Whether a code-shipped item sits under
// THIS address, which the two receipts below claim: a package's
// own permission set beside sets other namespaces' packages ship
Expand Down
17 changes: 15 additions & 2 deletions packages/metadata-protocol/src/protocol-lock-version-gates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@

import type { ObjectStackProtocolImplementation, MetadataAuditEntry } from './protocol.js';
import { canonicalMetaType } from './protocol.js';
import { SysMetadataRepository, actionHeldOnlyOnOtherObjects, unboundItemDraftAddress } from './sys-metadata-repository.js';
import { SysMetadataRepository, actionHeldOnlyOnOtherObjects, holdsEnvironmentOwnAction, unboundItemDraftAddress } from './sys-metadata-repository.js';
import { packagelessContentPackage } from './protocol-environment-rows.js';
import { resolveItemLockLazily } from './item-lock.js';
import { ConflictError } from '@objectstack/metadata-core';
Expand Down Expand Up @@ -440,9 +440,22 @@ export async function readVersionToken(

/** The body of `ObjectStackProtocolImplementation#packagelessReadAddress`; the method's docblock there is its contract. */
export async function packagelessReadAddress(
this: Pick<LockVersionGateHost, 'packagelessAddress' | 'shippedArtifactsOf'>,
this: Pick<LockVersionGateHost, 'packagelessAddress' | 'readItemActiveRows' | 'rethrowUnlessMetadataStoreUnprovisioned' | 'shippedArtifactsOf'>,
type: string, name: string, member?: string): Promise<string | null | undefined> {
const singular = PLURAL_TO_SINGULAR[type] ?? type;
// [#33904, ADR-0150 D4, ruling 6942962369] The environment's own action
// ({@link holdsEnvironmentOwnAction}) is the package-unbound row: the
// layered read's `effective` and `/published` serve it, as the plain read
// does, never the one package the rows are bound to on another object.
if (singular === 'action') {
let activeRows: Awaited<ReturnType<LockVersionGateHost['readItemActiveRows']>> = [];
try {
activeRows = await this.readItemActiveRows(singular, name);
} catch (error) {
this.rethrowUnlessMetadataStoreUnprovisioned(error, 'sys_metadata');
}
if (holdsEnvironmentOwnAction(singular, activeRows)) return null;
}
return packagelessContentPackage(await this.packagelessAddress(singular, name, member), this.shippedArtifactsOf(singular, name));
}

Expand Down
31 changes: 30 additions & 1 deletion packages/metadata-protocol/src/protocol-meta-item-face.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ import { packageDependencyClosure, pairsOf, type PackageClosureRegistry } from '
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 { boundObjectOf } from '@objectstack/metadata/stored-item-package';
import { RELATED_LISTS_ARRANGEMENT_DECORATION, type RelatedListsArrangement } from '@objectstack/spec/data';
import { overlayMemberValue, overlayMemberWhere } from './migrations/overlay-index.js';
import { isServedOverrideRowOf } from './served-override.js';
Expand Down Expand Up @@ -139,7 +140,9 @@ function isHoldersPairRow(engine: unknown, type: string, name: string, item: unk
* (`overlayRowBinding`, every holder counted): `null` is the environment's
* own item (D3 (a), no holder at its key, a same-name action on another
* object included), served; one holder is withheld when it is disabled; two
* or more are judged as the name's holders are ({@link disabledOnlyHolderOf}).
* or more are judged as the name's holders are ({@link disabledOnlyHolderOf}),
* except for an `action`, whose two or more are judged at its key
* ({@link actionKeyHoldersOf}).
* The row itself is untouched, so it is served again on re-enable.
* `undefined` when the item is not such a row, or the registry cannot bind
* one (optional-called: such a registry hides nothing more).
Expand All @@ -151,9 +154,35 @@ function packagelessRowWithheldHolder(registry: any, type: string, name: string,
const holder: unknown = registry.overlayRowBinding(type, name, item, { includeDisabledPackages: true });
if (holder === null) return undefined;
if (typeof holder === 'string') return registry.isPackageDisabled(holder) === true ? holder : undefined;
// [#34258, ADR-0150 D4] An action's key is `(object, name)`: two or more
// holders at the row's key are judged at that key, never at the name's,
// so a key whose every holder is disabled withholds the row although an
// enabled package holds the name on another object, and an enabled
// holder at the key keeps it served.
if (type === 'action') {
const atKey = actionKeyHoldersOf(registry, name, item);
return atKey.length > 0 && atKey.every((id) => registry.isPackageDisabled(id) === true) ? atKey[0] : undefined;
}
return disabledOnlyHolderOf(registry, type, name);
}

/**
* [#34258, ADR-0150 D4] The packages holding the action `name` at the key of
* `item` (its object, object-less its own key): every holder of the name, a
* disabled one included, whose own artifact is bound to `item`'s object, in
* the registry's holder order. The grain the registry's owner rule
* (`overlayRowBinding`) binds a package-less action row at.
*/
function actionKeyHoldersOf(registry: any, name: string, item: unknown): string[] {
if (typeof registry?.packageScopedHoldersOf !== 'function' || typeof registry?.getArtifactItem !== 'function') return [];
const object = boundObjectOf(item);
const every: readonly string[] = registry.packageScopedHoldersOf('action', name, null, { includeDisabledPackages: true }) ?? [];
return every.filter((id) => {
const own = registry.getArtifactItem('action', name, id) as { _packageId?: unknown } | undefined;
return own?._packageId === id && boundObjectOf(own) === object;
});
}

/**
* [#33401, review#2 S5] Whether an enabled package holds `(type, name)`
* through a stored active row the reads serve: a row bound to an enabled
Expand Down
14 changes: 11 additions & 3 deletions packages/metadata-protocol/src/protocol-meta-item-reads.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ import {
} from './protocol-package-bindings.js';
import type { ServedOverrideRow } from './served-override.js';
import { withServedRowChangedAt } from './served-row-changed-at.js';
import { canonicalIsoInstant } from './sys-metadata-repository.js';
import { canonicalIsoInstant, holdsEnvironmentOwnAction } from './sys-metadata-repository.js';

/**
* [ADR-0150 D3, #32244] The package-scoped refusal `error` carries — the
Expand Down Expand Up @@ -1033,18 +1033,26 @@ export async function readMetaItem(host: Pick<ProtocolHost, 'artifactLockLayerAt
// The package-less binding ({@link packagelessReadAddress}'s), selected
// from those rows; the `version` below ({@link readVersionToken})
// takes the same binding instead of reading it again.
const packagelessAddressed = readState === 'active' && !request.packageId
const packagelessRows = readState === 'active' && !request.packageId
? await host.packagelessAddress(
PLURAL_TO_SINGULAR[request.type] ?? request.type, request.name, member, 'active', activeRows,
)
: undefined;
// [#33904, ADR-0150 D4, ruling 6942962369] …except that the
// environment's own action, a package-unbound row on an object no
// package's row binds ({@link holdsEnvironmentOwnAction}), is a second
// item of the name, never a package's customization: the read naming no
// package serves it, and its `version`, where it served the one package
// the rows are bound to.
const environmentAction = packagelessRows !== undefined && holdsEnvironmentOwnAction(request.type, activeRows ?? []);
const packagelessAddressed = environmentAction ? { ...packagelessRows, packageId: null } : packagelessRows;
const packagelessBinding = packagelessAddressed?.packageId;
// [#28238] The content, though, is {@link packagelessContentPackage}'s:
// the code package that ships the name is a candidate too, so a row
// another package stored under the name is not served for it.
// [#32662] A pair address admitted at the one base whose stored row holds
// the name serves that base's stored content ({@link admitExactQualifier}).
const contentPackageId = exactAddress?.storedRowBase ?? (request.packageId || (packagelessAddressed
const contentPackageId = exactAddress?.storedRowBase ?? (request.packageId || (environmentAction ? null : packagelessAddressed
? packagelessContentPackage(packagelessAddressed, host.shippedArtifactsOf(request.type, request.name))
: undefined));

Expand Down
Loading
Loading