diff --git a/.changeset/33385-disabled-holders-env-404.md b/.changeset/33385-disabled-holders-env-404.md new file mode 100644 index 00000000000..3834406a278 --- /dev/null +++ b/.changeset/33385-disabled-holders-env-404.md @@ -0,0 +1,25 @@ +--- +'@objectstack/metadata-protocol': patch +'@objectstack/rest': patch +'@objectstack/runtime': patch +--- + +fix(metadata-protocol,rest,runtime)!: a name only disabled packages hold answers 404 at `_env`, and an environment customization of such a name is hidden until a holder is enabled again (ADR-0150 D3, D4) + +Clause-②: no (narrowing) +Metadata-protocol: none +Skills-docs: updated here — content/docs/data-modeling/import-mappings.mdx (no `skills/**` file teaches an `_env` answer) + + + +**BREAKING** for a read of an environment customization of a name whose every holding package is disabled. Such a customization is a row saved without a package, for a name an installed package holds. It belongs to that package (ADR-0150 D4), and a disabled package holds no name (ADR-0150 D3). + +- **The read that names no package (`GET /meta/:type/:name`, and the execution read).** When every package holding the name is disabled, this read now answers as if the customization were not saved: `404`, where it served the row. That includes a translation the package never shipped, such as an email template's `fr-FR` that only the environment wrote. A customization at a member the package ships was already hidden. +- **The list and the execution list (`GET /meta/:type`).** They now leave out the same customization, so they agree with the read of the name: while every package holding the name is disabled, neither list carries any item of it. Enable a holder again and both list it again. +- **A save or delete naming no package while every holder is disabled.** A save at a member the package never ships is accepted and kept, as before, but it is now hidden from the reads above until a holder is enabled again. A delete of it still removes the row. A save at a member the package ships is still refused `403 NOT_OVERRIDABLE`. +- **`GET /meta/:type/_env/:name`.** When every package holding the name is disabled, the environment address now answers `404`, as for a name no package holds, on both the REST server and the runtime dispatcher. It used to refuse `409 RESOURCE_CONFLICT` naming the disabled packages. It still refuses `409` in three cases: an enabled package holds the name; a package holds it through a saved metadata row that the read of the name serves; or the read carries `?state=draft`, `?preview=draft` or `?layers=`, which read other rows than the plain read. That `409` names only the disabled package the registry holds the name for, as before; it does not name an enabled package that holds the name through a saved row. On a composition whose metadata engine has no package-scoped resolver for the type (its registry lacks the by-name reads), `_env` of a name only disabled packages hold now answers `501 NOT_IMPLEMENTED`, the refusal of a read that engine cannot judge, where it answered `409`. Refusal to refusal; no production composition lacks those reads. +- **The import door's `mappingName: "_env/NAME"`.** The same move, as `GET /meta/mapping/_env/NAME` answers it: `404 MAPPING_NOT_FOUND`, naming no package, where it was refused `409` naming the disabled package. + +**Not moved.** With an enabled holder, every answer is unchanged. That includes an enabled package that holds the name only through a saved row the registry has not read yet: the customization is still served and listed, whether the list or the read of the name comes first. A customization of a name no installed package holds is the environment's own item and is still served. + +**No migration.** Nothing is deleted or rewritten. Enable the package again and the customization is served again, unchanged. The fix for a caller who needs the row while the package is disabled is to re-enable the package. diff --git a/content/docs/data-modeling/import-mappings.mdx b/content/docs/data-modeling/import-mappings.mdx index 497a43bf706..bbe84e562f6 100644 --- a/content/docs/data-modeling/import-mappings.mdx +++ b/content/docs/data-modeling/import-mappings.mdx @@ -94,7 +94,10 @@ address `GET /api/v1/meta/mapping//` reads, and the import door the same way (ADR-0150 D5). The import applies exactly that holder's mapping. When that namespace, or the environment, holds no mapping of the name and a package does, the import is refused with the `409 RESOURCE_CONFLICT` that read answers, naming every holder, -and no row is written. A first segment that is neither `_env` nor an installed namespace +and no row is written. A disabled package holds no name: when every package that holds the +name is disabled, `"_env/"` answers `404 MAPPING_NOT_FOUND`, naming no package, as +`GET /api/v1/meta/mapping/_env/` answers `404`. Enable a holder again and the address +is refused with the `409` naming it, as before. A first segment that is neither `_env` nor an installed namespace is no address: the whole string is read as the name, which no mapping has, so the import answers `404 MAPPING_NOT_FOUND`. Two limits come with the metadata read's address. Where two packages that share a namespace (`base`, `system`, `sys`) both hold the name, the @@ -274,8 +277,8 @@ These are whole-request failures — nothing is written, and there is no per-row | Status | `code` | Cause | |:---|:---|:---| -| 404 | `MAPPING_NOT_FOUND` | No mapping artifact is registered under that name. | -| 409 | `RESOURCE_CONFLICT` | Two or more packages hold a mapping under that name, and the environment holds none; or a qualified `mappingName` (`/`, `_env/`) names a holder that holds no mapping of that name while another does. The error names every holder. | +| 404 | `MAPPING_NOT_FOUND` | No mapping artifact is registered under that name, or every package that holds it is disabled. | +| 409 | `RESOURCE_CONFLICT` | Two or more packages hold a mapping under that name, and the environment holds none; or a qualified `mappingName` (`/`, `_env/`) names a holder that holds no mapping of that name while another, enabled, package does. The error names every holder. | | 400 | `MAPPING_TARGET_MISMATCH` | The artifact's `targetObject` is not the object in the URL. | | 400 | `MAPPING_FORMAT_UNSUPPORTED` | The artifact declares `sourceFormat: 'xml'` or `'sql'`; the endpoint accepts csv, json and xlsx payloads only. | | 400 | `MAPPING_FORMAT_MISMATCH` | The declared `sourceFormat` contradicts the payload actually sent. A `csv` mapping does apply to an `xlsx` payload — those rows are tabular in the same way — but a `json` mapping does not. | diff --git a/packages/metadata-protocol/src/protocol-exact-qualifier.ts b/packages/metadata-protocol/src/protocol-exact-qualifier.ts index 9ea5a2e29f5..6cdec6f37dd 100644 --- a/packages/metadata-protocol/src/protocol-exact-qualifier.ts +++ b/packages/metadata-protocol/src/protocol-exact-qualifier.ts @@ -946,6 +946,8 @@ export function resolveMetaItemAddress( * environment does not hold and a package does is refused * (`not-held-by-qualifier`, `callerPackageId: null`); otherwise the read is a * caller with no package, which E8's resolver answers environment-first. + * [#33385] A name only disabled packages hold is refused with a mark the + * doors read ({@link DISABLED_HOLDERS_ONLY_REFUSAL}). * Types outside the covered set keep the bare read, as `?package=` does for * them. * @@ -972,8 +974,10 @@ export function admitEnvironmentQualifier( } // [#32183, epic ruling R4-B2] The served holders, or every holder when no // package serves the name: a name only disabled packages hold is refused - // naming them, as before, never read as a caller with no package (that - // read can reach a disabled holder's customization pair row). + // naming them here, never admitted on the registry's word alone. The + // registry does not see a package holding the name only through a stored + // row it has not hydrated, so a read admitted here could serve that + // package's row at the environment's address. const served = registry.packageScopedHoldersOf(request.type, request.name) ?? []; const holders = served.length > 0 ? served @@ -982,6 +986,11 @@ export function admitEnvironmentQualifier( refuseUnjudgeableByNameRead(host, request, { kind: 'environment' }); return; } + // [#33385, #32183 row 17] …but marked ({@link DISABLED_HOLDERS_ONLY_REFUSAL}), + // once the read it would admit is judgeable: each door then asks the read + // naming no package, which judges the stored rows too, and answers the + // name as no package's (its 404) when that read withholds it. + if (served.length === 0) refuseUnjudgeableByNameRead(host, request, { kind: 'environment' }); const candidates: PackageScopedHolder[] = holders.map((holder) => ({ kind: 'package' as const, packageId: holder })); const base = { status: 'refused' as const, @@ -991,5 +1000,28 @@ export function admitEnvironmentQualifier( callerPackageId: null, candidates, }; - throw new PackageScopedNameRefusedError({ ...base, message: packageScopedRefusalMessage(base) }); + const error = new PackageScopedNameRefusedError({ ...base, message: packageScopedRefusalMessage(base) }); + if (served.length === 0) Object.defineProperty(error, DISABLED_HOLDERS_ONLY_REFUSAL, { value: true }); + throw error; } + +/** + * [#33385, #32183 row 17 (ruling R4-B2 on PR #32497)] The marker + * {@link admitEnvironmentQualifier} sets on its refusal of a name only + * disabled packages hold, a registered symbol (so every copy of this package + * reads the same key, and no envelope serializes it). The `_env` doors of + * `RestServer` and the runtime dispatcher read it by the same `Symbol.for` + * key (`RestServer` reaches the protocol only as a service, as with the item + * face's `storedRowHoldersRefusal` marker), and answer it in two steps, + * because only an asynchronous read sees a package that holds the name + * through a stored row alone: + * + * - the read naming no package (`getMetaItem`) withholds the name (no item): + * no package serves it, a disabled package holds no name, and the item face + * withholds every customization of its holders (the pair's row, #32814; a + * package-less row of their key, #33401). The door admits `_env` and its + * read answers 404, naming no package; + * - that read serves an item, or refuses: a package holds the name through + * its stored row, so the refusal stands, as before. + */ +const DISABLED_HOLDERS_ONLY_REFUSAL: unique symbol = Symbol.for('objectstack.metadata-protocol.disabledHoldersOnlyRefusal') as never; diff --git a/packages/metadata-protocol/src/protocol-meta-item-face.ts b/packages/metadata-protocol/src/protocol-meta-item-face.ts index f6bac9b63a7..599e5b5cd19 100644 --- a/packages/metadata-protocol/src/protocol-meta-item-face.ts +++ b/packages/metadata-protocol/src/protocol-meta-item-face.ts @@ -122,6 +122,94 @@ function isHoldersPairRow(engine: unknown, type: string, name: string, item: unk return every.some((holder) => pairsOf(holder, installed).includes(stamp)); } +/** + * [#33401, ADR-0150 D4] The package a package-less row (stamped with no + * package, `''` or the `sys_metadata` sentinel) that the read naming no + * package reached is withheld with: the holder whose key the row customizes, + * when every holder of that key is disabled. Seat ruling 6882483833 on + * #32814: a package-less row whose key (`(type, name)`; `(object, name)` for + * an `action`) an installed package holds is that holder's overlay, owned + * over every holder, disabled included (epic ruling 6816940784 on #31699), so + * with every holder disabled the read answers as if no row were stored. The + * member is not part of the key: a locale the holder never shipped is still + * its customization. + * + * The key's holders are the registry's one owner rule + * (`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}). + * 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). + */ +function packagelessRowWithheldHolder(registry: any, type: string, name: string, item: unknown): string | undefined { + const stamp = (item as { _packageId?: unknown } | null | undefined)?._packageId; + if (stamp !== undefined && stamp !== null && stamp !== '' && stamp !== 'sys_metadata') return undefined; + if (typeof registry?.overlayRowBinding !== 'function' || typeof registry?.isPackageDisabled !== 'function') return undefined; + 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; + return disabledOnlyHolderOf(registry, type, name); +} + +/** + * [#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 + * package that the reads do not decline (`declinesStoredRow`) and that is no + * holder's customization pair row (a pair row is that holder's item, never a + * holder of its own). The registry's owner rule does not see such a row + * until it is hydrated, so {@link packagelessRowWithheldHolder} alone would + * withhold a package-less row while an enabled package holds the name, and + * the answer would follow hydration order. + */ +function enabledRowHolds( + host: Pick, + type: string, name: string, + rows: ReadonlyArray>[number]>, +): boolean { + const registry: any = host.engine?.registry; + const every: readonly string[] = registry?.packageScopedHoldersOf?.(type, name, null, { includeDisabledPackages: true }) ?? []; + const installed = installedManifestsOfEngine(host.engine); + return rows.some((row) => { + const bound = typeof row.package_id === 'string' && row.package_id !== '' && row.package_id !== 'sys_metadata' + ? row.package_id : undefined; + return bound !== undefined && registry?.isPackageDisabled?.(bound) !== true + && !host.declinesStoredRow(type, name, row) + && !every.some((holder) => pairsOf(holder, installed).includes(bound)); + }); +} + +/** + * [#33401] The holder a package-less `item` of `(type, name)` is withheld + * with ({@link packagelessRowWithheldHolder}), unless an enabled package + * holds the name through a stored active row ({@link enabledRowHolds}, + * review#2 S5): then the answer is `main`'s, whichever order the rows were + * hydrated in. `rows` are the item's active rows when the caller already + * read them; otherwise they are read here, only once the registry would + * withhold the item. The read naming no package and the list naming no + * package (`protocol-meta-list-reads.ts`) both ask this, so the list carries + * no row the by-name read withholds. + */ +export async function packagelessRowWithheld( + host: Pick, + type: string, name: string, item: unknown, + rows?: ReadonlyArray>[number]>, +): Promise { + const holder = packagelessRowWithheldHolder(host.engine?.registry, type, name, item); + if (holder === undefined) return undefined; + let active: ReadonlyArray>[number]> | undefined = rows; + if (active === undefined) { + try { + active = await host.readItemActiveRows(type, name); + } catch (error) { + host.rethrowUnlessMetadataStoreUnprovisioned(error, 'sys_metadata'); + active = []; + } + } + return enabledRowHolds(host, type, name, active) ? undefined : holder; +} + /** * [#32183] The package whose stack a read naming no package takes, for a * name a disabled package also holds: the one holder ADR-0150 D3 resolves @@ -523,6 +611,11 @@ export async function readMetaItemFace( // name's holders too, as it does when it reached nothing: a pair row of a // name only disabled packages hold is their withheld item, the answer the // same read gives with no row stored. + // [#33401] …and so does a package-less row of a key whose every holder is + // disabled ({@link packagelessRowWithheld}): that holder's customization, + // withheld with it; the environment's own item is served, and so is the + // row while an enabled package holds the name through a stored row + // (review#2 S5), judged over the active rows read above. const withheldHolder = request.type === 'object' || request.type === 'package' ? undefined : (request.packageId ? disabledExactAddressHolder(this, { type: request.type, name: request.name, packageId: request.packageId }) : undefined) @@ -531,7 +624,12 @@ export async function readMetaItemFace( ? !isStoredUnder(answer.item, request.packageId) : isHoldersPairRow(this.engine, request.type, request.name, answer.item)) ? disabledOnlyHolderOf(this.engine?.registry, request.type, request.name) - : undefined); + : undefined) + ?? (request.packageId || answer?.item == null + ? undefined + : await packagelessRowWithheld(this, request.type, request.name, answer.item, + activeRows !== undefined && activeRows.type === request.type && activeRows.name === request.name + ? activeRows.rows : undefined)); if (withheldHolder === undefined && (request.type === 'object' || request.type === 'package' || (!withheldAction && !isItemOfDisabledPackage(this.engine?.registry, answer?.item)))) { return answer; diff --git a/packages/metadata-protocol/src/protocol-meta-list-reads.ts b/packages/metadata-protocol/src/protocol-meta-list-reads.ts index 523b698988f..8be8dda9805 100644 --- a/packages/metadata-protocol/src/protocol-meta-list-reads.ts +++ b/packages/metadata-protocol/src/protocol-meta-list-reads.ts @@ -49,6 +49,7 @@ import { storedEntryRow } from './protocol-stored-overlay-types.js'; import { viewIdentityPatch } from './protocol-view-normalization.js'; import { isServedOverrideRowOf, type ServedOverrideRow } from './served-override.js'; import { installedManifestsOfEngine } from './installed-manifests.js'; +import { packagelessRowWithheld } from './protocol-meta-item-face.js'; import { declinesPackageLessRowAt, disabledExactAddressHolder, @@ -161,7 +162,7 @@ function disabledHolderListing( } /** The body of `ObjectStackProtocolImplementation#readFlattenedMetaItems`; the method's docblock there is its contract. */ -export async function readFlattenedMetaItems(host: Pick, request: { type: string; packageId?: string; names?: readonly string[]; previewDrafts?: boolean }, +export async function readFlattenedMetaItems(host: Pick, request: { type: string; packageId?: string; names?: readonly string[]; previewDrafts?: boolean }, audience: 'served' | 'execution', layer: 'effective' | 'per-package' = 'effective',) { const { packageId } = request; @@ -952,6 +953,22 @@ export async function readFlattenedMetaItems(host: Pick