Skip to content

Commit 5c5ee14

Browse files
committed
Merge remote-tracking branch 'origin/main' into claude/project-thread-0r3khj
2 parents cbae230 + eeec88d commit 5c5ee14

22 files changed

Lines changed: 1724 additions & 74 deletions
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
---
2+
'@objectstack/objectql': patch
3+
---
4+
5+
fix(objectql)!: uninstalling a base package is refused while its paired `.custom` package is installed, naming the pair (409, the extender-refusal family) (#28408)
6+
7+
Clause-②: no (narrowing) — `SchemaRegistry.assertPackageUninstallable`, and so `uninstallPackage`, `unregisterObjectsByPackage` without `force`, the protocol's `deletePackage` and `DELETE /api/v1/packages/:id`, now refuse the uninstall of a base while the registry holds its paired customization package (`BASE.custom`), an uninstall that succeeded before; nothing is widened.
8+
Metadata-protocol: none
9+
Skills-docs: none — no file under `skills/**` teaches uninstalling a package, so every taught use stays true.
10+
11+
<!-- adr-0087: not-required (no-migration-prescription) No key of any schema is added, removed, renamed or re-shaped, and no export or type changes: a registry state that refuses an uninstall gains one more cause, answered with the existing RESOURCE_CONFLICT / 409 refusal, so there is nothing for a migration to rewrite and no tombstone. -->
12+
13+
**BREAKING** accept-set narrowing at the package uninstall (`@objectstack/objectql`, ADR-0146 D3).
14+
15+
- **Before.** A base package uninstalled while its paired customization package (`hotcrm.custom` for `hotcrm`) was installed. Every customization in the pair was stranded: nothing served it, and nothing said why.
16+
- **Now.** The uninstall is refused `409 RESOURCE_CONFLICT`, in the same refusal an extended object already gets (ADR-0029), before anything is removed. The message names the pair and opens with the way out: delete the pair first, exporting it before that to keep its customizations (`GET /api/v1/packages/PAIR/export`). When the base is also extended, one refusal names the extenders and the pair. The thrown error carries the pair as `customizationPackageId`.
17+
- **Unchanged.** Uninstalling the pair itself; a base with no installed pair; `force`, which still means not asking; a dependent that is not the base's own pair (ADR-0141 D3 still defers it). On `DELETE /api/v1/packages/:id` a base the deployment ships is still refused `422 WRITABLE_PACKAGE_REQUIRED` first.
18+
19+
**The remedy.** Export the pair if you want to keep its customizations, delete it, then uninstall the base.
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
---
2+
'@objectstack/metadata-protocol': minor
3+
'@objectstack/rest': minor
4+
'@objectstack/runtime': minor
5+
---
6+
7+
feat(metadata-protocol): one effective read — every read of a name a code package ships serves its `.custom` pair's declared override, the env-wide list and the export agree with it, and a withdrawn public form stays withdrawn (ADR-0146 D8)
8+
9+
Clause-②: yes (widening)
10+
Metadata-protocol: semantic
11+
12+
The `overrides: { package, basedOn }` declaration (ADR-0146 D2) now takes effect on the read. Under the address of a name an installed code package X ships, the item of X's paired `<X>.custom` package that declares `overrides.package = X` is the one document served:
13+
14+
- **Every read agrees.** The read naming no package, the read naming X (`?package=X`), the layered read (`code` = X's document, `overlay` = the override, `effective` = the override), the list scoped to X and the env-wide list all serve the override, under X's `_packageId`. A declaration from any package that is not X's pair is ignored, and an undeclared item of the pair stays the pair's own item.
15+
- **One predicate.** `isServedOverrideRowOf(row, basePackageId)` (new export, with its `ServedOverrideRow` type) is the one spelling of "is this stored row the served override of X's name": bound to X's pair by the row's own `package_id` (never a body stamp), of an overridable type, declaring `overrides.package = X`.
16+
- **The env-wide list joins the one read.** For a name exactly one code package ships, a same-named row bound to another package is no longer listed beside that package's item; it stays that package's own item under its own address. A package-unbound row (the overlay Setup writes) keeps winning over the code item until the migration of ADR-0146 D11. Beside a package-unbound row the declared override is served, because a save naming no package writes the override's row there.
17+
- **The per-package layer.** `ObjectStackProtocolImplementation#getMetaItemsPerPackage` (new public method) answers the list as it stood before this change: one item per package that holds a name, each package's own document. `GET /packages/:id/export` reads it, so the base's export carries the base unchanged and `GET /packages/<X>.custom/export` carries the overriding item with its `overrides` block.
18+
- **Public forms.** `GET /forms/:slug` and `POST /forms/:slug/submit` offer the forms of the effective list and judge withdrawal against that list beside the per-package layer, so a form withdrawn by any body the doors honoured before stays withdrawn: a dependent package's withdrawing row still closes the base's form, and an override cannot re-open a form the base's own document withdraws. A form that only a body no longer served offered is no longer offered (the doors only narrow).
19+
- **Orphans are reported.** A row of X's name stored in X's pair without the declaration, or in a package that depends on X, is reported by the layered read of X's name in `overlay`, with `effective` = X's document, instead of being dropped silently. A row of a package outside X's closure is not.
20+
21+
No request or response shape changes.

‎packages/metadata-protocol/src/index.ts‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,14 @@ export type { MetadataHostEngine } from './host-engine.js';
226226
export { isWritablePackage, READ_ONLY_PACKAGE_SCOPES } from './package-writability.js';
227227
export type { PackageWritabilityEngine } from './package-writability.js';
228228

229+
// [#28409, ADR-0146 D8 item 2] "Is this stored row the served override of base
230+
// X's name": the one predicate the effective read asks, exported so the flow
231+
// override, the per-package customization read and the package-less overlay
232+
// migration (ADR-0146 Rollout N-11, N-15, N-16) ask the same one. ⛔ No second
233+
// spelling.
234+
export { isServedOverrideRowOf } from './served-override.js';
235+
export type { ServedOverrideRow } from './served-override.js';
236+
229237
// [ADR-0131 D6] The `unmanaged` install mode's walled-posture refusal — the
230238
// function `importUnmanagedPackage` raises, exported so the install door
231239
// (`@objectstack/cloud-connection` install-local) answers it with the same

‎packages/metadata-protocol/src/protocol-environment-rows.ts‎

Lines changed: 54 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@
1414
* [#28238] Beside them, `packagelessContentPackage`: the package a by-name
1515
* read that names none takes its stored content from, given that address and
1616
* the code packages that ship the name. Not a moved body: the rule the two
17-
* by-name reads share.
17+
* by-name reads share. [#28409] …and `shippingPackageIds` /
18+
* `soleShippingPackage`, the code packages that ship a name, read one way by
19+
* those reads and by the env-wide list.
1820
*
1921
* A MOVE, not a redesign. Each function below is the body of the
2022
* `ObjectStackProtocolImplementation` method of the same name as it stood,
@@ -46,6 +48,7 @@ import type { StoredOverlayRow } from './item-lock.js';
4648
import { overlayMemberWhere } from './migrations/overlay-index.js';
4749
import type { ObjectStackProtocolImplementation } from './protocol.js';
4850
import { rowMatchesOverlayWhere, servedOverlayRowCandidates } from './protocol.js';
51+
import { isServedOverrideRowOf } from './served-override.js';
4952

5053
/**
5154
* The `ObjectStackProtocolImplementation` members the functions below read —
@@ -100,17 +103,19 @@ export async function findServedOverlayRow(
100103
packageId?: string | null;
101104
/** [#22877] The bundle member a by-name door's selector named; omitted, the canonical one. */
102105
member?: string;
106+
/** [#28409] The package's declared override first — see {@link servedOverlayRowCandidates}. */
107+
servedOverride?: boolean;
103108
},
104109
activeRows?: readonly StoredOverlayRow[],
105-
): Promise<{ row: any } | undefined> {
110+
): Promise<{ row: any; overrideOf?: string } | undefined> {
106111
// [#21804] The order is {@link servedOverlayRowCandidates}, the one
107112
// the list's merge takes over the rows it read: the canonical
108113
// spelling then the other, and within each, the package's
109114
// own row then the package-less row (never another package's, or a
110115
// collision would serve package B's customization for a package A
111116
// read); with no package context (legacy/runtime reader), any row.
112117
const other = PLURAL_TO_SINGULAR[args.type] ?? SINGULAR_TO_PLURAL[args.type];
113-
for (const candidate of servedOverlayRowCandidates({ packageId: args.packageId })) {
118+
for (const candidate of servedOverlayRowCandidates({ packageId: args.packageId, servedOverride: args.servedOverride })) {
114119
const type = candidate.spelling === 'canonical' ? args.type : other;
115120
if (type === undefined) continue;
116121
const where: Record<string, unknown> = {
@@ -129,7 +134,16 @@ export async function findServedOverlayRow(
129134
const row = activeRows !== undefined && args.state === 'active'
130135
? activeRows.find((stored) => rowMatchesOverlayWhere(stored, where))
131136
: await this.findEnvironmentRow('sys_metadata', { where, context: { isSystem: true } });
132-
if (row) return { row };
137+
if (!row) continue;
138+
// [#28409, ADR-0146 D8 item 2] The pair's row holds the override
139+
// candidate only when it declares the override of the address's
140+
// package ({@link isServedOverrideRowOf}, on the row's own binding and
141+
// body): an undeclared row of the pair is the pair's own item.
142+
if (candidate.overrideOf !== undefined) {
143+
if (isServedOverrideRowOf(row, candidate.overrideOf)) return { row, overrideOf: candidate.overrideOf };
144+
continue;
145+
}
146+
return { row };
133147
}
134148
return undefined;
135149
}
@@ -199,14 +213,45 @@ export function packagelessContentPackage(
199213
address: { readonly packageId: string | null; readonly candidates: readonly string[] },
200214
shipped: readonly unknown[],
201215
): string | null | undefined {
202-
const shippers = new Set<string>();
203-
for (const artifact of shipped) {
204-
const id = (artifact as { _packageId?: unknown } | null | undefined)?._packageId;
205-
if (typeof id === 'string' && id !== '' && id !== 'sys_metadata') shippers.add(id);
206-
}
216+
const shippers = shippingPackageIds(shipped);
207217
if (shippers.size === 0 || (address.packageId !== null && shippers.has(address.packageId))) {
208218
return address.packageId ?? undefined;
209219
}
210220
if (shippers.size === 1) return [...shippers][0];
211221
return address.candidates.some((id) => shippers.has(id)) ? undefined : null;
212222
}
223+
224+
/**
225+
* [#28238, #28409] The code packages `shipped` belongs to — every artifact an
226+
* installed code package registered under one name
227+
* (`ObjectStackProtocolImplementation#shippedArtifactsOf`), by its
228+
* `_packageId`, the `'sys_metadata'` sentinel left out. The candidates
229+
* {@link packagelessContentPackage} weighs for the by-name reads, and the set
230+
* the env-wide list asks for the same name ({@link soleShippingPackage}), so
231+
* the two read the code packages that ship a name one way.
232+
*/
233+
export function shippingPackageIds(shipped: readonly unknown[]): ReadonlySet<string> {
234+
const shippers = new Set<string>();
235+
for (const artifact of shipped) {
236+
const id = (artifact as { _packageId?: unknown } | null | undefined)?._packageId;
237+
if (typeof id === 'string' && id !== '' && id !== 'sys_metadata') shippers.add(id);
238+
}
239+
return shippers;
240+
}
241+
242+
/**
243+
* [#28409, ADR-0146 D8 items 1–2] The one code package that ships a name, or
244+
* `undefined` when none or several do: the case in which
245+
* {@link packagelessContentPackage} answers that package for every stored row
246+
* the name has. The env-wide list (`readFlattenedMetaItems`, naming no
247+
* package) then lists the name once, as that package's item, which is what
248+
* the by-name read naming no package serves: a row another package stored
249+
* under the name is that package's own item, served under its own address
250+
* (the read naming it, the list scoped to it), never a second item of the
251+
* name beside the base's. Several packages that ship a name keep one item
252+
* each (ADR-0048 §3.3), as the by-name read keeps its best-effort answer.
253+
*/
254+
export function soleShippingPackage(shipped: readonly unknown[]): string | undefined {
255+
const shippers = shippingPackageIds(shipped);
256+
return shippers.size === 1 ? [...shippers][0] : undefined;
257+
}

‎packages/metadata-protocol/src/protocol-package-uninstall.ts‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,14 @@ export async function deletePackage(this: Pick<PackageUninstallHost, 'deleteMeta
122122
// the same predicate (the one copy `unregisterObjectsByPackage` itself
123123
// calls) without performing the uninstall, so the refusal is thrown
124124
// here, as is, with nothing removed. The HTTP door answers it through
125-
// its `catch` around this verb: `500`, nothing changed.
125+
// its `catch` around this verb, with the refusal's own `409
126+
// RESOURCE_CONFLICT`: nothing changed.
127+
//
128+
// [#28408, ADR-0146 D3] The same question also refuses a base whose
129+
// paired customization package (`<base>.custom`) the registry holds,
130+
// naming the pair, in the same refusal; both causes ride on one throw.
131+
// It is asked here, before the store delete, for the same reason: a base
132+
// removed under its pair strands every customization the pair holds.
126133
//
127134
// The registry is reached the way the withdrawal below reaches it. A
128135
// registry that does not carry the method (an engine double, a host on

‎packages/metadata-protocol/src/protocol.read-verb-canonical-fold.test.ts‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ async function expectSpellingRefusal(run: () => Promise<unknown>) {
210210
}
211211

212212
describe('#9157 — the population, re-derived from the code rather than from the card', () => {
213-
it('every `/meta` request-boundary verb with a required `type` calls the fold — all seventeen', () => {
213+
it('every `/meta` request-boundary verb with a required `type` calls the fold — all eighteen', () => {
214214
// ⭐ The card hand-listed "nine fold, three do not". Hand-listed sets of
215215
// this shape have shipped short before, so the set is DERIVED here and
216216
// the derivation is the pin: a tenth verb arriving unfolded turns this
@@ -315,6 +315,10 @@ describe('#9157 — the population, re-derived from the code rather than from th
315315
// [#20552] The execution face of the same flattened read — an
316316
// in-process caller hands it a type spelling too.
317317
'getMetaItemsForExecution',
318+
// [#28409] The per-package layer of the same flattened read — the
319+
// form doors' withdrawal judgement and the package export hand it
320+
// a type spelling too.
321+
'getMetaItemsPerPackage',
318322
'historyMetaItem',
319323
// [#20761] The loader's-set read and the one authoring rule every
320324
// flow write door asks (below) — both take the type a caller names.

0 commit comments

Comments
 (0)