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
19 changes: 19 additions & 0 deletions .changeset/38753-disabled-holder-counts-nothing.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---
'@objectstack/metadata-protocol': patch
'@objectstack/rest': patch
'@objectstack/runtime': patch
---

fix(metadata-protocol): a disabled package counts for nothing at the environment address, the delete naming no package and the read beside a package-less row

Clause-②: no
Metadata-protocol: none

A disabled package holds no name and is never named (ADR-0150 D3). Three doors still counted one.

- **`GET /api/v1/meta/TYPE/_env/NAME`** (the plain read, `?layers=true`, `?state=draft`, `?preview=draft`, and the `_env/NAME` spelling of an import's `mappingName`), for a name the registry knows only through a disabled package while an enabled package holds it through a stored row or draft the registry has not loaded: the answer was `409 RESOURCE_CONFLICT` naming the disabled package. It is now `409 RESOURCE_CONFLICT` naming the enabled package whose row or draft the read that names no package serves (`details.candidates`), and never that row. Where that read answers 404, `_env` still answers 404.
- **`DELETE` naming no package, and the draft discard naming no package**, of an item whose stored rows are bound to a disabled package and to the one enabled package that ships the name: the answer was `409 RESOURCE_CONFLICT` naming both. Each now removes the enabled package's row or draft, as the same request with `?package=` naming it does, and leaves the disabled package's rows as they are. With two or more enabled holders the refusal still names exactly them.
- **The receipt of `DELETE` and of the draft discard**, bare or naming the enabled package, beside a disabled package's rows: it said the item "still carries another overlay: its row bound to package 'D' remains", naming the disabled package, and for a name only a disabled package ships in code it said "reset to artifact default". A disabled package's row is no remaining overlay and its code is no artifact default: the receipt now reads as it does without the disabled package ("reset to artifact default" where the enabled package ships the name, "it no longer exists" where no enabled package does). Repeating the bare delete or discard once the enabled package's row or draft is gone answered by removing the DISABLED package's row or draft (a customization hidden with it); it now answers the no-op receipt at the enabled package's address and leaves the disabled package's rows stored. A `dropStorage` delete still counts every stored row.
- **The read that names no package** (`GET /api/v1/meta/TYPE/NAME`, `/layers`, `/published`), of a name a disabled package ships in code only, beside one enabled package's stored row and a package-less row: the answer was 404. It now serves the enabled package's row, as it does when the disabled package does not ship the name.

Not changed here: the draft save naming no package of the second case still answers `409` naming both packages. To write the enabled package's draft now, name it: `?package=PACKAGE`.
64 changes: 52 additions & 12 deletions packages/metadata-protocol/src/protocol-diff-delete-load.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ import { captureStoredExpressionChange, fillStoredExpressionChange } from './pro
import type { RuntimeAuthoringIssue } from './runtime-authoring-gate.js';
import type { ProtocolHost } from './protocol-host.js';
import { disabledRowHoldersRefusal, packagelessHolderRefusal, packagelessRowHeldBaseAddress } from './protocol-save.js';
import { countedRowHolders, shippedByCountedPackage, soleEnabledRowHolder } from './protocol-enabled-holders.js';
import { isPlatformRecordRow } from '@objectstack/metadata';
import { retireOverlayCacheOnRollback } from './meta-overlay-cache.js';

Expand Down Expand Up @@ -728,7 +729,9 @@ export class ProtocolDiffDeleteLoadFacet {
? await host.packagelessDraftAddress(singularTypeForRepo, request.name, member)
: undefined;
if (draftAddress?.kind === 'ambiguous') {
const base = await packagelessRowHeldBaseAddress(host, singularTypeForRepo, request.name, member);
// [#38753] …or the one enabled holder beside a disabled package's draft ({@link soleEnabledRowHolder}).
const base = await packagelessRowHeldBaseAddress(host, singularTypeForRepo, request.name, member)
?? soleEnabledRowHolder(host, singularTypeForRepo, request.name, member, draftAddress.candidates);
if (base === undefined) {
// [#34346] …naming the holders the read counts where a
// row is bound to a disabled package ({@link disabledRowHoldersRefusal}).
Expand All @@ -741,12 +744,26 @@ export class ProtocolDiffDeleteLoadFacet {
}
request = { ...request, packageId: base };
draftAddress = undefined;
} else if (draftAddress !== undefined && draftAddress.into !== null && !draftAddress.drafts.unbound) {
// [#38753 (folded delete-receipt finding), #32354] …and
// the draft address of active rows bound to a package that
// counts for nothing (a disabled one), beside the one
// enabled holder the read naming no package serves: the
// discard acts at that holder's address, as without the
// disabled package, never at the disabled package's draft.
const base = soleEnabledRowHolder(host, singularTypeForRepo, request.name, member, [draftAddress.into]);
if (base !== undefined) {
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) {
const base = await packagelessRowHeldBaseAddress(host, singularTypeForRepo, request.name, member);
// [#38753] …or the one enabled holder beside a disabled package's row ({@link soleEnabledRowHolder}).
const base = await packagelessRowHeldBaseAddress(host, singularTypeForRepo, request.name, member)
?? soleEnabledRowHolder(host, singularTypeForRepo, request.name, member, rowsAtAddress.candidates);
if (base === undefined) {
// [#34346, ADR-0150 D3/D5] Rows bound to a disabled
// package too are refused naming the holders the read
Expand All @@ -760,6 +777,16 @@ export class ProtocolDiffDeleteLoadFacet {
throw addressRefusal;
}
request = { ...request, packageId: base };
} else if (request.packageId == null && draftAddress === undefined && rowsAtAddress.candidates.length === 1 && !rowsAtAddress.unbound) {
// [#38753 (folded delete-receipt finding), #32354] …and
// rows bound to ONE package that counts for nothing (a
// disabled one), beside the one enabled holder the read
// naming no package serves: the delete acts at that
// holder's address, as without the disabled package. FROM
// (`main` 645e6b15): it removed the disabled package's
// row, a customization hidden with it.
const base = soleEnabledRowHolder(host, singularTypeForRepo, request.name, member, rowsAtAddress.candidates);
if (base !== undefined) 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 Expand Up @@ -818,8 +845,18 @@ export class ProtocolDiffDeleteLoadFacet {
// own permission set beside sets other namespaces' packages ship
// has none ({@link isOwnPermissionSetWrite}, the verdict its save
// reads), so removing it removes the set, never resets one.
//
// [#38753 (folded delete-receipt finding), #32354] …nor does a
// name only disabled packages ship ({@link shippedByCountedPackage}).
const shippedUnderAddress = artifactBacked
&& !isOwnPermissionSetWrite(host.engine, singularTypeForRepo, request.name, packageId);
&& !isOwnPermissionSetWrite(host.engine, singularTypeForRepo, request.name, packageId)
&& shippedByCountedPackage(host, singularTypeForRepo, request.name, member);
// [#38753 (folded delete-receipt finding), #32354] The rows the
// receipts below say remain: a disabled package's row (or its
// pair's) is stored but served by no read, so it is never named
// there ({@link countedRowHolders}). The table drop still counts
// every stored row.
const countedCandidates = countedRowHolders(host, singularTypeForRepo, request.name, rowsAtAddress.candidates);
// Probe first — "no overlay exists" is a success/no-op, not
// a conflict. The repo would otherwise throw ConflictError.
const current = await repo.get(ref, { state: targetState, packageId, ...memberOption(member) });
Expand Down Expand Up @@ -851,25 +888,25 @@ export class ProtocolDiffDeleteLoadFacet {
?? (draftAddress?.kind === 'none' && draftAddress.into !== null && rowsAtAddress.unbound
? draftAddress.into
: null);
if (!current && receiptPackageId != null && (rowsAtAddress.candidates.length > 0 || rowsAtAddress.unbound)) {
if (!current && receiptPackageId != null && (countedCandidates.length > 0 || rowsAtAddress.unbound)) {
return {
success: true,
reset: false,
message: targetState === 'draft'
? `No pending draft of ${request.type}/${request.name} is bound to package '${receiptPackageId}', so nothing was discarded: ${remainingRowsPhrase(rowsAtAddress.candidates, rowsAtAddress.unbound, 'draft')}.`
: `No row of ${request.type}/${request.name} is bound to package '${receiptPackageId}', so nothing was deleted: ${remainingRowsPhrase(rowsAtAddress.candidates, rowsAtAddress.unbound, 'row')}.`,
? `No pending draft of ${request.type}/${request.name} is bound to package '${receiptPackageId}', so nothing was discarded: ${remainingRowsPhrase(countedCandidates, rowsAtAddress.unbound, 'draft')}.`
: `No row of ${request.type}/${request.name} is bound to package '${receiptPackageId}', so nothing was deleted: ${remainingRowsPhrase(countedCandidates, rowsAtAddress.unbound, 'row')}.`,
};
}
// [#23495] …and a draft discard naming no package, of an item
// bound to a package that holds no draft at that package's
// address while other packages' drafts are stored: nothing is
// discarded, and the receipt names what remains rather than
// claiming no draft exists.
if (!current && draftAddress?.kind === 'none' && draftAddress.into !== null && rowsAtAddress.candidates.length > 0) {
if (!current && draftAddress?.kind === 'none' && draftAddress.into !== null && countedCandidates.length > 0) {
return {
success: true,
reset: false,
message: `No pending draft of ${request.type}/${request.name} is bound to package '${draftAddress.into}', the package its published rows are bound to and the draft a discard that names no package removes, so nothing was discarded: ${remainingRowsPhrase(rowsAtAddress.candidates, rowsAtAddress.unbound, 'draft')}.`,
message: `No pending draft of ${request.type}/${request.name} is bound to package '${draftAddress.into}', the package its published rows are bound to and the draft a discard that names no package removes, so nothing was discarded: ${remainingRowsPhrase(countedCandidates, rowsAtAddress.unbound, 'draft')}.`,
};
}
if (!current) {
Expand Down Expand Up @@ -915,6 +952,9 @@ export class ProtocolDiffDeleteLoadFacet {
const remainingPackages = rowsAtAddress.candidates.filter((id) => id !== packageId);
const unboundRemains = rowsAtAddress.unbound && packageId !== null;
const remains = remainingPackages.length > 0 || unboundRemains;
// [#38753 (folded delete-receipt finding)] …and what the receipt says remains.
const remainingCounted = countedCandidates.filter((id) => id !== packageId);
const countedRemains = remainingCounted.length > 0 || unboundRemains;
// [#23415] The table drop, decided ONCE, before anything is
// written: an object's table goes only with its last stored
// row. A `dropStorage` delete that would leave another row of
Expand Down Expand Up @@ -1113,11 +1153,11 @@ export class ProtocolDiffDeleteLoadFacet {
message: (request.state === 'draft')
? `Draft discarded${deletedPackage} — ${request.type}/${request.name}. [seq=${result.seq}]`
: shippedUnderAddress
? (remains
? `Customization overlay deleted${deletedPackage} — ${request.type}/${request.name} still carries another overlay: ${remainingRowsPhrase(remainingPackages, unboundRemains, 'row')}. [seq=${result.seq}]`
? (countedRemains
? `Customization overlay deleted${deletedPackage} — ${request.type}/${request.name} still carries another overlay: ${remainingRowsPhrase(remainingCounted, unboundRemains, 'row')}. [seq=${result.seq}]`
: `Customization overlay deleted${deletedPackage} — ${request.type}/${request.name} reset to artifact default. [seq=${result.seq}]`)
: (remains
? `Deleted ${singularTypeForRepo} '${request.name}'${deletedPackage}, and it still exists: ${remainingRowsPhrase(remainingPackages, unboundRemains, 'row')}. [seq=${result.seq}]`
: (countedRemains
? `Deleted ${singularTypeForRepo} '${request.name}'${deletedPackage}, and it still exists: ${remainingRowsPhrase(remainingCounted, unboundRemains, 'row')}. [seq=${result.seq}]`
: `Deleted ${singularTypeForRepo} '${request.name}'${deletedPackage} — it no longer exists. [seq=${result.seq}]`),
};
} catch (err: any) {
Expand Down
Loading
Loading