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
14 changes: 14 additions & 0 deletions .changeset/34681-bare-write-doors-follow-base.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
'@objectstack/metadata-protocol': patch
---

fix(metadata-protocol): the save, delete, publish, draft, history, diff and rollback doors naming no package write and read the base's row where the read naming no package serves it

Clause-②: yes (widening)
Metadata-protocol: none

A bundled item (an email template's locale, for example) that no package ships in code can be stored as a row by a base package and, at the same member, by a package that declares that base. The read naming no package already serves the base's row there. The write doors naming no package now resolve the same address: the save (publish and draft mode), the per-item publish, the delete and the draft discard act on the base's row or draft, and the history, the diff and the rollback read and restore the base's own versions, as the same request naming the base (`?package=` on the REST door, `packageId` in process) does. The base is judged as named: bound to an id no installed package has, the save in either mode is refused `422 WRITABLE_PACKAGE_REQUIRED`. (The per-item publish naming no package still states no package to the runtime authoring gate, as every publish naming no package does.) Before, each was refused `409 RESOURCE_CONFLICT` naming both packages, so an item that opened fine could not be saved.

The dependent package's row stays where it is and is still read and written at its own `?package=`. Where the base is read-only, the save, the delete, the draft discard and the rollback now answer what naming the base answers (for the save, `422 WRITABLE_PACKAGE_REQUIRED` naming the base) instead of the `409`. After a delete naming no package removes the base's row, the read naming no package serves the dependent's row, and the delete's receipt names it as still stored; a second delete naming no package removes the dependent's row too, and the base's copy comes back only by saving it again. The rollback's receipt now names the package of the row it restored, as the delete's receipt does.

Unchanged: two packages holding the member with neither declaring the other, a package-less row beside the holders, and a type with no members are still refused `409` naming every holder.
10 changes: 10 additions & 0 deletions .changeset/34681-spec-bare-doors-follow-base.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
'@objectstack/spec': patch
---

docs(spec): the request texts state that a request naming no package follows the row-held base

Clause-②: yes (widening)
Metadata-protocol: none

The `packageId` descriptions of the save, draft save, per-item publish, delete and history/diff/rollback requests (`HISTORY_PACKAGE_SELECTOR_DESCRIPTION`) said a request naming no package is refused `409 RESOURCE_CONFLICT` wherever an item's active rows are bound to two or more packages. They now state the exception the server answers: a bundled type's member that a base package and a package declaring it both hold, with no package-unbound row beside them, is the row-held base's, as the read naming no package serves it, and the request addresses the base's row, draft or versions as naming the base does. Two packages neither of which declares the other are still refused `409`. The delete text states the consequence: the dependent's row is served next, a second delete naming no package removes it too, and the base's copy comes back only by saving it again. Description text only; no schema shape, key or accepted value moves.
12 changes: 6 additions & 6 deletions content/docs/references/api/protocol.mdx

Large diffs are not rendered by default.

40 changes: 28 additions & 12 deletions packages/metadata-protocol/src/protocol-diff-delete-load.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,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 } from './protocol-save.js';
import { packagelessHolderRefusal, packagelessRowHeldBaseAddress } from './protocol-save.js';

/**
* [#33308] The row slot a `sys_metadata` row is: its bound package, or `null`
Expand All @@ -79,7 +79,7 @@ function rowSlotOf(row: { package_id?: unknown }): string | null {

export class ProtocolDiffDeleteLoadFacet {
/** The body of `ObjectStackProtocolImplementation#diffMetaItem`; the method's docblock there is its contract. */
static async diffMetaItem(host: Pick<ProtocolHost, 'diffMetaItem' | 'engine' | 'findEnvironmentRow' | 'findEnvironmentRows' | 'findServedOverlayRow' | 'packagelessAddress' | 'resolveRowlessExpandedView' | 'rethrowUnlessMetadataStoreUnprovisioned' | 'shippedArtifactsOf'>, request: {
static async diffMetaItem(host: Pick<ProtocolHost, 'declinesStoredRow' | 'diffMetaItem' | 'engine' | 'findEnvironmentRow' | 'findEnvironmentRows' | 'findServedOverlayRow' | 'packagelessAddress' | 'readItemActiveRows' | 'resolveRowlessExpandedView' | 'rethrowUnlessMetadataStoreUnprovisioned' | 'shippedArtifactsOf'>, request: {
type: string;
name: string;
fromVersion?: number;
Expand Down Expand Up @@ -454,7 +454,7 @@ export class ProtocolDiffDeleteLoadFacet {
}

/** [#28355] The body of {@link deleteMetaItem} before its refusal audit; that method's docblock is the contract. */
static async deleteMetaItemUnaudited(host: Pick<ProtocolHost, 'assertLockAllowsDelete' | 'dropObjectStorage' | 'dropStorageRemainingRowsRefusal' | 'emitMetadataMutation' | 'engine' | 'environmentId' | 'findEnvironmentRow' | 'getOverlayRepo' | 'isArtifactBacked' | 'isOverlayAllowed' | 'isRuntimeCreateAllowed' | 'metadataConflictRefusal' | 'originGatedRemovalRefusal' | 'packagedArtifactOwner' | 'packagedBaseRefusal' | 'packagelessAddress' | 'packagelessDraftAddress' | 'packagelessOverlayWriteRefusal' | 'recordMetadataAudit' | 'recordOptimisticConflictAudit' | 'refuseOrganizationScopedWrite' | 'refusePackagedBaseRemoval' | 'registryAllowsOverlay' | 'restoreArtifactRegistryView' | 'runMutationProjector' | 'shippedArtifactsOf' | 'shouldDropStorage' | 'storedParentForToken'>, request: DeleteMetaItemRequest): Promise<{
static async deleteMetaItemUnaudited(host: Pick<ProtocolHost, 'assertLockAllowsDelete' | 'declinesStoredRow' | 'dropObjectStorage' | 'dropStorageRemainingRowsRefusal' | 'emitMetadataMutation' | 'engine' | 'environmentId' | 'findEnvironmentRow' | 'getOverlayRepo' | 'isArtifactBacked' | 'isOverlayAllowed' | 'isRuntimeCreateAllowed' | 'metadataConflictRefusal' | 'originGatedRemovalRefusal' | 'packagedArtifactOwner' | 'packagedBaseRefusal' | 'packagelessAddress' | 'packagelessDraftAddress' | 'packagelessOverlayWriteRefusal' | 'readItemActiveRows' | 'recordMetadataAudit' | 'recordOptimisticConflictAudit' | 'refuseOrganizationScopedWrite' | 'refusePackagedBaseRemoval' | 'registryAllowsOverlay' | 'restoreArtifactRegistryView' | 'rethrowUnlessMetadataStoreUnprovisioned' | 'runMutationProjector' | 'shippedArtifactsOf' | 'shouldDropStorage' | 'storedParentForToken'>, request: DeleteMetaItemRequest): Promise<{
success: boolean;
message?: string;
reset?: boolean;
Expand Down Expand Up @@ -713,23 +713,39 @@ export class ProtocolDiffDeleteLoadFacet {
// door orders it. The rows read here are also what the receipt
// below tells the truth about: what is still stored, and so
// still served, once this row is gone.
const draftAddress = request.packageId == null && targetState === 'draft'
//
// [#34681] …except where the read naming no package serves the
// row-held base of rows bound to two or more packages
// ({@link packagelessRowHeldBaseAddress}): the delete and the
// draft discard remove the base's row or draft, as the request
// naming that base does, and the dependents' rows stay (the
// receipt below names them).
let draftAddress = request.packageId == null && targetState === 'draft'
? await host.packagelessDraftAddress(singularTypeForRepo, request.name, member)
: undefined;
if (draftAddress?.kind === 'ambiguous') {
addressRefusal = packagelessAddressAmbiguityRefusal(
'delete', request.type, request.name, draftAddress.candidates,
);
throw addressRefusal;
const base = await packagelessRowHeldBaseAddress(host, singularTypeForRepo, request.name, member);
if (base === undefined) {
addressRefusal = packagelessAddressAmbiguityRefusal(
'delete', request.type, request.name, draftAddress.candidates,
);
throw addressRefusal;
}
request = { ...request, packageId: base };
draftAddress = undefined;
}
const rowsAtAddress = draftAddress?.drafts ?? await host.packagelessAddress(
singularTypeForRepo, request.name, member, targetState,
);
if (request.packageId == null && draftAddress === undefined && rowsAtAddress.candidates.length > 1) {
addressRefusal = packagelessAddressAmbiguityRefusal(
'delete', request.type, request.name, rowsAtAddress.candidates,
);
throw addressRefusal;
const base = await packagelessRowHeldBaseAddress(host, singularTypeForRepo, request.name, member);
if (base === undefined) {
addressRefusal = packagelessAddressAmbiguityRefusal(
'delete', request.type, request.name, rowsAtAddress.candidates,
);
throw addressRefusal;
}
request = { ...request, packageId: base };
}
// [ADR-0150 D3/D5, red line 2, ruling A] …and the holders the
// read naming no package counts, as the save door asks them
Expand Down
20 changes: 16 additions & 4 deletions packages/metadata-protocol/src/protocol-history-and-publish.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ import type { MutationProjectionOutcome } from './protocol-mutation-events.js';
import { PREFLIGHT_AUDIT_CODE, withPendingAudit } from './protocol-audit-entry.js';
import type { PublishMetaItemRequest } from './protocol-door-requests.js';
import { withRefusalAudit } from './protocol-refusal-audit.js';
import { environmentActionPublishSlotRefusal } from './protocol-save.js';
import { environmentActionPublishSlotRefusal, packagelessRowHeldBaseAddress } from './protocol-save.js';
import { overlayMemberWhere } from './migrations/overlay-index.js';
import { isMissingTableError } from '@objectstack/metadata/errors';
import { readPublishBackfillRequest } from './protocol-publish-backfill-request.js';
Expand Down Expand Up @@ -202,7 +202,7 @@ async function undoLandedPromotions(host: Pick<ProtocolHost, 'engine' | 'isArtif

export class ProtocolHistoryAndPublishFacet {
/** The body of `ObjectStackProtocolImplementation#historyMetaItem`; the method's docblock there is its contract. */
static async historyMetaItem(host: Pick<ProtocolHost, 'engine' | 'findServedOverlayRow' | 'getOverlayRepo' | 'historyMetaItem' | 'isOverlayAllowed' | 'isRuntimeCreateAllowed' | 'packagelessAddress' | 'resolveRowlessExpandedView' | 'shippedArtifactsOf' | 'storedHashDigest'>, request: {
static async historyMetaItem(host: Pick<ProtocolHost, 'declinesStoredRow' | 'engine' | 'findServedOverlayRow' | 'getOverlayRepo' | 'historyMetaItem' | 'isOverlayAllowed' | 'isRuntimeCreateAllowed' | 'packagelessAddress' | 'readItemActiveRows' | 'resolveRowlessExpandedView' | 'rethrowUnlessMetadataStoreUnprovisioned' | 'shippedArtifactsOf' | 'storedHashDigest'>, request: {
type: string;
name: string;
sinceSeq?: number;
Expand Down Expand Up @@ -278,6 +278,8 @@ export class ProtocolHistoryAndPublishFacet {
// holders' rows hold is refused naming both when no package is named,
// and `?package=` reads that holder's versions alone. A name one slot
// holds, named bare, reads its whole log as before.
// [#34681] A row-held base's name, named bare, reads that base's
// versions, as `?package=` naming it does ({@link historySlotOf}).
const slot = await historySlotOf(host, {
type: singularType, name: request.name, ...memberOption(member),
...(request.packageId !== undefined ? { packageId: request.packageId } : {}),
Expand Down Expand Up @@ -671,7 +673,7 @@ export class ProtocolHistoryAndPublishFacet {
* `recordPendingDenialAudit`, rethrow. Skip it and the refusal is silent
* again — the pre-#7748 state, not merely a worse one.
*/
static async promoteDraftForPublish(host: Pick<ProtocolHost, 'anonymousElevatedFlowRefusal' | 'assertRuntimeAuthoringRules' | 'classifyObjectContribution' | 'credentialChannelFor' | 'defaultRecordPageSaveRefusal' | 'engine' | 'ensureOverlayIndex' | 'externalBindingSaveRefusal' | 'getOverlayRepo' | 'isArtifactBacked' | 'isOverlayAllowed' | 'isRuntimeCreateAllowed' | 'isSealedManagedItem' | 'lockWriteRefusal' | 'metadataConflictRefusal' | 'namedBaseOverlayWriteRefusal' | 'objectExtensionItemRefusal' | 'objectNamespaceObjectNameClash' | 'objectNamespacePrefixViolation' | 'objectRegistrationRefusal' | 'optimisticConflictAuditEntry' | 'overlayPackageMismatchError' | 'overrideWriteVerdict' | 'packagelessAddress' | 'packagelessDraftAddress' | 'permissionSetNameCollisionRefusal' | 'readItemActiveRows' | 'resolveSduiManifest' | 'seedExternalIdSaveRefusal' | 'uninstalledNamedBaseRefusal' | 'unknownDatasourceSaveRefusal' | 'unknownGrantObjectSaveRefusal' | 'unknownPicklistBindingSaveRefusal'>, request: {
static async promoteDraftForPublish(host: Pick<ProtocolHost, 'anonymousElevatedFlowRefusal' | 'assertRuntimeAuthoringRules' | 'classifyObjectContribution' | 'credentialChannelFor' | 'declinesStoredRow' | 'defaultRecordPageSaveRefusal' | 'engine' | 'ensureOverlayIndex' | 'externalBindingSaveRefusal' | 'getOverlayRepo' | 'isArtifactBacked' | 'isOverlayAllowed' | 'isRuntimeCreateAllowed' | 'isSealedManagedItem' | 'lockWriteRefusal' | 'metadataConflictRefusal' | 'namedBaseOverlayWriteRefusal' | 'objectExtensionItemRefusal' | 'objectNamespaceObjectNameClash' | 'objectNamespacePrefixViolation' | 'objectRegistrationRefusal' | 'optimisticConflictAuditEntry' | 'overlayPackageMismatchError' | 'overrideWriteVerdict' | 'packagelessAddress' | 'packagelessDraftAddress' | 'permissionSetNameCollisionRefusal' | 'readItemActiveRows' | 'resolveSduiManifest' | 'rethrowUnlessMetadataStoreUnprovisioned' | 'seedExternalIdSaveRefusal' | 'shippedArtifactsOf' | 'uninstalledNamedBaseRefusal' | 'unknownDatasourceSaveRefusal' | 'unknownGrantObjectSaveRefusal' | 'unknownPicklistBindingSaveRefusal'>, request: {
type: string; name: string; actor?: string; message?: string;
/**
* [#8907] ADR-0048 — the package binding of the draft being promoted,
Expand Down Expand Up @@ -834,7 +836,17 @@ export class ProtocolHistoryAndPublishFacet {
// is the 503 the lock read raised before this read moved above it
// ({@link packagelessAddress} discriminates both).
const address = await host.packagelessDraftAddress(singularType, request.name, request.member);
if (address.kind === 'ambiguous') {
// [#34681] Active rows bound to two or more packages where the read
// naming no package serves the row-held base: the base's draft, as
// the publish naming that base promotes it
// ({@link packagelessRowHeldBaseAddress}).
const base = address.kind === 'ambiguous'
? await packagelessRowHeldBaseAddress(host, singularType, request.name, request.member)
: undefined;
if (base !== undefined) {
draftKey = base;
promoteInto = base;
} else if (address.kind === 'ambiguous') {
draftKey = null;
promoteInto = null;
addressRefusal = packagelessAddressAmbiguityRefusal('publish', request.type, request.name, address.candidates);
Expand Down
24 changes: 19 additions & 5 deletions packages/metadata-protocol/src/protocol-history-slots.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@
* by more than one row slot — two packages', or a package's beside the
* package-less row — is refused `409` naming every holder
* (`ambiguous-in-environment`), before any row is read or written: nothing
* picks one (ADR-0150 D3, epic red line 2). So is a name the bare plain
* picks one (ADR-0150 D3, epic red line 2), except where the bare read
* serves the row-held base (#34441 cell 2): there the door addresses the
* base's slot, as naming the base does (#34681,
* `packagelessRowHeldBaseAddress`). So is a name the bare plain
* read refuses (ADR-0150 D5: a holder in code counts, so two packages
* shipping the name are two holders while only one has saved a row): the
* registry's resolver (`resolveItem`, the one the plain read asks) throws
Expand Down Expand Up @@ -58,6 +61,7 @@ import type { ProtocolHost } from './protocol-host.js';
import { memberOption } from './protocol-bundle-members.js';
import { shippingPackageIds } from './protocol-environment-rows.js';
import type { HistoryVersionOwner } from './sys-metadata-repository.js';
import { packagelessRowHeldBaseAddress } from './protocol-save.js';

/** What {@link historySlotOf} answers for a door of a by-package type. */
export interface HistorySlot {
Expand Down Expand Up @@ -153,21 +157,31 @@ function refuseWhereBareReadRefuses(host: Pick<ProtocolHost, 'engine'>, type: st
* before.
* @throws a `400 VALIDATION_ERROR` for `?package=` on a type not stored per
* `(package, name)`.
* [#34681, epic ruling 6781691009] A bare request of a name whose rows at the
* member the read naming no package serves at the row-held base
* ({@link packagelessRowHeldBaseAddress}) addresses that base's slot, as the
* same request naming it does: the history, diff and rollback naming no
* package read and restore the base's versions, never another holder's.
*
* @throws {PackageScopedNameRefusedError} `ambiguous-in-environment` for a
* bare request of a name two or more row slots hold, or the bare plain
* read's own refusal; `not-held-by-qualifier` for a package that neither
* bare request of a name two or more row slots hold (other than a row-held
* base's, above), or the bare plain read's own refusal; `not-held-by-qualifier` for a package that neither
* holds a row of the name nor ships it, while another slot holds one.
*/
export async function historySlotOf(
host: Pick<ProtocolHost, 'engine' | 'findServedOverlayRow' | 'packagelessAddress' | 'shippedArtifactsOf'>,
host: Pick<ProtocolHost, 'declinesStoredRow' | 'engine' | 'findServedOverlayRow' | 'packagelessAddress' | 'readItemActiveRows' | 'rethrowUnlessMetadataStoreUnprovisioned' | 'shippedArtifactsOf'>,
request: { type: string; name: string; member?: string; packageId?: string },
): Promise<HistorySlot | undefined> {
const { type, name, member, packageId } = request;
refusePackageSelectorOutsideSlottedTypes(type, packageId);
if (!PACKAGE_SLOTTED_STORE_TYPES.has(type)) return undefined;
const slots = await rowSlotsOf(host, type, name, member);
if (packageId === undefined) {
if (slots.length > 1) throw slotRefusal(type, name, 'ambiguous-in-environment', null, slots);
if (slots.length > 1) {
const base = await packagelessRowHeldBaseAddress(host, type, name, member);
if (base !== undefined) return historySlotOf(host, { ...request, packageId: base });
throw slotRefusal(type, name, 'ambiguous-in-environment', null, slots);
}
refuseWhereBareReadRefuses(host, type, name, member);
if (slots.length === 0) return undefined;
return { owner: { packageId: slots[0] ?? null, sole: true }, addressed: false, held: true };
Expand Down
Loading
Loading