diff --git a/.changeset/32791-stored-row-one-holder-bare-action-read.md b/.changeset/32791-stored-row-one-holder-bare-action-read.md index dab4234461b..0d24262cbe4 100644 --- a/.changeset/32791-stored-row-one-holder-bare-action-read.md +++ b/.changeset/32791-stored-row-one-holder-bare-action-read.md @@ -2,14 +2,14 @@ '@objectstack/metadata': patch --- -fix(metadata): a stored package-less row the boot pass files under the host's package is one holder of an action name, not two, when a read naming no package is judged over the loaders (ADR-0150 D4) +fix(metadata): on a host that declares its package, a stored package-less row is one holder of an action name, not two, when a read naming no package is judged over the loaders (ADR-0150 D4) Clause-②: no — the fix removes a refusal ADR-0150 D4 already denies ("A package-less row that bears a package-held name is a customization, never a second item. … it never arms beside the item it shadows (E1) and never makes the name ambiguous."), and the refusal it removes is #32560's, which has not shipped: the refusal and its removal first ship in the same release, so no released accept set widens. On a host that declares its package, after the boot priming pass and before any write that carries no package, `MetadataManager.get('action', NAME)` and `getDiagnosed` of a name one package holds beside a package-less stored row saved last go from `409 RESOURCE_CONFLICT` naming the host's package to the package-less row, that package's customization (or the environment's own item where the package binds the name to another object); beside two packages the `409` no longer names the host's package. Metadata-protocol: none — no key, value or metadata type an author writes changes; what moves is how many holders a read naming no package counts for one stored row. -On a host that declares its package (`MetadataPlugin`'s `packageId`), the boot priming pass stamps a package-less `sys_metadata` row with the host's package before it registers it, so the registry holds that row in the host's slot. A read naming no package of an action name is judged over the registry's slots and the loaders' stored slots together (#32560), and the loaders still store that row package-less: the one row was counted twice, once as the host's package and once as the environment, and the refusal named a holder that does not exist. +On a host that declares its package (`MetadataPlugin`'s `packageId`), the boot priming pass stamped a package-less `sys_metadata` row with the host's package before it registered it, so the registry held that row in the host's slot. A read naming no package of an action name is judged over the registry's slots and the loaders' stored slots together (#32560), and the loaders still store that row package-less: the one row was counted twice, once as the host's package and once as the environment, and the refusal named a holder that does not exist. -The judged view now files such a row (an item a stored-row loader, `datasource:`, handed out for no package, held in the registry slot of the package it is stamped with, whose registration replaced no item registered in memory or by code, while a loader still stores it) the way the store files a write that carries no package: in the slot of the name's one package holder, as its customization, or else in the bare slot, as the environment's own item. It keeps the write order of the registry slot it came from, and that slot is not counted beside it. +The boot priming pass now leaves such a row unstamped (#32812, whose note has the whole change), so the registry files it the way the store files a write that carries no package: in the slot of the name's one package holder, as its customization, or else in the bare slot, as the environment's own item, and it is counted once. Moved, all `action`, every read naming no package (`get` and `getDiagnosed` agree); FROM is `main` with #32676: @@ -19,12 +19,13 @@ Moved, all `action`, every read naming no package (`get` and `getDiagnosed` agre | another package | ALPHA's row on an object, a package-less row on the same object | `409` host, ALPHA, environment | the package-less row | | another package | ALPHA's row on an object, an object-less package-less row; or ALPHA's object-less row, a package-less row on an object | `409` host, ALPHA | the package-less row (the environment's own item) | | another package | ALPHA's rows on two objects (either order), a package-less row on one of them; or ALPHA's object-less row and its row on an object (either order), an object-less package-less row | `409` host, ALPHA, environment | the package-less row (written last) | -| another package | a package-less row; ALPHA's item in memory, before or after the pass | `409` host, ALPHA, environment | the package-less row | +| another package | a package-less row; ALPHA's item in memory before the pass | `409` host, ALPHA, environment | the package-less row | +| another package | a package-less row; ALPHA's item in memory after the pass | `409` host, ALPHA, environment | ALPHA's item | | another package | BETA's row and a package-less row, ALPHA's item in memory before the pass; or a package-less row, and ALPHA's and BETA's items in memory (both before the pass in either order, or ALPHA's before and BETA's after) | `409` ALPHA, host, BETA, environment | `409` ALPHA, BETA, environment | | ALPHA | a package-less row; another package's item in memory before the pass | `409` that package, ALPHA, environment | the package-less row | -Unchanged: a host that declares no package; every two-package stored composition; the package's row saved last; every read that names a package; every other type stored per `(package, name)` (their bare read reads the registry alone); a host's own item registered in memory after the pass, which is still a holder; an unstamped row the registry filed in its one holder's slot (that holder's customization); a stamped row whose registration replaced an item the host's package held in memory before the pass, which leaves that package a holder (beside a second package's row or item the read is still refused, naming both and the environment; beside none it answers the row), and a repeated priming pass keeps the overwrite mark: the pass run again on the same manager hands out a new row object, which carries the mark of the row it replaces, so these compositions answer the same after it; and the row removed from the table behind the manager, after which the host's slot is a holder again. The candidates a refusal names are a set: their order follows the judged view and is not promised. +Unchanged: a host that declares no package; every two-package stored composition; the package's row saved last; every other type stored per `(package, name)` (their bare read reads the registry alone); a host's own item registered in memory after the pass, which is still a holder; a row the registry files in its one holder's slot (that holder's customization); a row registered over an item the host's package held in memory before the pass, which leaves that package a holder (beside a second package's row or item the read is still refused, naming both and the environment; beside none it answers the row), and these compositions answer the same after the pass is run again on the same manager. The candidates a refusal names are a set: their order follows the judged view and is not promised. -Scope: this holds in the boot state. After a write that carries no package (`register` or `registerInMemory` of the name), the registry files the written body in the host's slot and the bare read names the host's package again, as on `main` (#32812). A removal naming no package is judged without this filing and is still refused naming the host's package, so in these compositions the read and the removal do not count the same holders until #32813. +Scope: with #32812 this holds after a write that carries no package (`register` or `registerInMemory` of the name) as well as in the boot state, and a removal naming no package counts the same holders as the read. A read naming a package, and the row removed from the table behind the manager, answer as #32812's note says. No first-party composition wires a `DatabaseLoader` under a host that declares its package, and none registers an `action` in memory, so no answer changes in this repository. diff --git a/.changeset/32812-boot-pass-leaves-stored-row-unstamped.md b/.changeset/32812-boot-pass-leaves-stored-row-unstamped.md new file mode 100644 index 00000000000..79fc6bdae97 --- /dev/null +++ b/.changeset/32812-boot-pass-leaves-stored-row-unstamped.md @@ -0,0 +1,31 @@ +--- +'@objectstack/metadata': patch +--- + +fix(metadata)!: the boot priming pass leaves a package-less stored row of a type stored per `(package, name)` unstamped, so the host's package is never counted as a holder of its name (ADR-0150 D4) + +Clause-②: yes (narrowing) — one face widens against the last release and the others narrow, all on a host that declares its package and wires a `DatabaseLoader`; the widening is named under the BREAKING banner below. Adds one method to the exported `MetadataManager`, `sourceLoaderProtocolOf(item)` (the protocol of the loader `loadMany` read an item from), which the pass asks. Narrows: on a host that declares its package (`MetadataPlugin`'s `packageId`) and wires a `DatabaseLoader` (or another loader of the `datasource:` protocol), a package-less stored row of `api`, `agent`, `skill`, `action`, `email_template`, `permission`, `flow`, `picklist`, `mapping` or `dataset` is no longer served as the host package's item after the boot priming pass: its body no longer carries `_packageId` set to the host's package or `_provenance: 'package'`, the metadata list filtered by the host's package (`?package=` naming it) no longer lists it, and `publishPackage`, `revertPackage` and `unregisterPackage` naming the host's package no longer take it as one of that package's items (where the host's package itself holds the name, the row is that package's customization, ADR-0150 D4, and goes with its slot as for any holder). The `409` this lifts (the bare read naming the host's package, which holds nothing, after a write that carries no package) is #32560's, which has not shipped. +Metadata-protocol: none — no key, value or metadata type an author writes changes; what moves is which package the boot pass gives a stored row that names none. + + + +**BREAKING** for a host that declares its package and stores rows that name no package for one of these ten types. Such a row is the environment's own item, or the customization of the one package that holds its name (ADR-0150 D4); it was never the host package's, but the boot pass stamped it so. To keep an item in the host's package, save it naming that package (`?package=` on the write, or the package stamped on the item `register` is given). A row whose stored body an earlier release's boot pass wrote the host's stamp into is still read as the host package's (its column is bound from that body), and is not moved. Every other type, and the host's own file items, are stamped as before. + +The one widening, a behaviour change for the same reason (ADR-0150 D4, and the answer a host that declares no package already gives): a package-less stored row of these types is no longer hidden when the host's own package is disabled, as on a host that declares no package. + +Among the readers of the stamp, these move with it (the list is not complete; every one of them reads the row as a host that declares no package does): such a row with a `protection` block is locked from `'artifact'` rather than `'package'` (`_lock` kept), an MCP skill or agent face built from it is named by its own name rather than the host's namespace, and the realtime events of the boot pass carry no package for it. A loader of stored rows is told by its `datasource:` protocol, as #32791's filing told it, so a loader that declares the protocol under a name other than `DatabaseLoader`'s is treated the same. No first-party package, app or example declares a package and wires a `DatabaseLoader`. + +Moved answers, all on such a host, each now the answer the same composition gives on a host that declares no package: + +- One package's row and a package-less row saved last (`action`): after `register` with no package, or `registerInMemory` of a package-less item, the bare `get` and `getDiagnosed` go from `409 RESOURCE_CONFLICT` naming the host's package, the holder and the environment to the written item. +- The removal naming no package, the same composition: right after the pass and after such a write, it goes from a `409` naming the host's package to removing the package-less row, for every one of the ten types (`email_template`: the holder's slot), so it names the holders the bare read names. +- The same composition, the nine unbundled types: the registry holds the package-less row in the name's bare slot, not the host's, and a read naming the holder answers its customization (the package-less row) where it answered the holder's own row. `list` names the row once, package-less, where it named it twice (its customization and, again, the host's), so a consumer that counts the holders `list` names counts one holder where it counted two. +- A read naming a package that holds nothing (the host's own, on a host declaring the holder's package; any third package, on a host declaring another): it answers the package-less row (or the item written over it), as the bare read does, where it answered nothing. The other way, the read naming the host's package goes from the package-less row to nothing where a package's item registered in memory sits beside that row, and for `email_template` beside one package's row: the host's package holds nothing there. +- A package-less row and one package's `action` item registered in memory after the pass: the bare read answers that package's item, where it answered the package-less row (the by-host difference #32752 tracked). +- The package-less row deleted from the table behind the manager: the bare read answers the registry's copy, where it was refused naming the host's package and the holder. +- `email_template`, one package's row and a package-less row: the pass files the package-less row in the holder's slot (its customization) and no longer in the host's, so the bare read after the pass is no longer refused naming the host's package. +- A package-less `action` row alone, removed with no package: the registry's stamped copy no longer outlives the row (it answered reads and `list` until a restart). + +This replaces #32791's read-time filing of the stamped row (`MetadataManager`'s record of stored package-less rows, its overwrite mark and the judged view's filing), which has nothing left to file for the boot pass and is removed; every #32791 pin marked CONTROL passes unchanged. #32791's own changeset, which ships in the same release, is corrected with this change: the filing it described is replaced by the unstamped row, a read naming a package is no longer among its unchanged answers (above), its "after the pass" cell (a package-less row, a package's item registered in memory after the pass) answers that package's item, and its scope now covers a write that carries no package and the removal. One caller the filing also covered moves back: a caller of the public `MetadataManager.loadMany` that stamps a package-less row it is handed with a package itself and registers it is now refused naming that package beside the name's holder, as after any write (no first-party caller does so). Candidate order in a refusal is not promised. + +Skills-docs: none — `skills/**` and `content/docs/**` do not teach that the boot pass gives a stored row the host's package; the migration step ships in this note and is carried into the release's upgrade notes when they are written. diff --git a/.changeset/32986-host-unregister-keeps-environment-rows.md b/.changeset/32986-host-unregister-keeps-environment-rows.md index 8288ff87fbf..5a39c00d391 100644 --- a/.changeset/32986-host-unregister-keeps-environment-rows.md +++ b/.changeset/32986-host-unregister-keeps-environment-rows.md @@ -7,7 +7,7 @@ fix(metadata): unregistering the host package keeps the environment's own object Clause-②: no — no released answer moves: `unregisterPackage` reads the `_packageId` stamp since #32198, which has not shipped, and with this change it leaves the environment's own rows the boot pass marked, as the released version does. The boot pass's stamp, and every reader of it, answer as before. Metadata-protocol: none -On a host that declares its package and stores metadata in a database, the boot pass stamps each stored row that names no package with the host's package. For a type not stored per `(package, name)` — `object`, `view`, `app`, `hook`, `dashboard` and the rest — that stamp stays, so ObjectQL still registers such an object as the host package's contribution. But `MetadataManager.unregisterPackage(host)` took the stamp as membership and deleted those rows, from memory and from the database: the environment's own items were lost when the host package was unregistered. +On a host that declares its package and stores metadata in a database, the boot pass stamps each stored row of a type not stored per `(package, name)` — `object`, `view`, `app`, `hook`, `dashboard` and the rest — that names no package with the host's package (a row of a type stored per `(package, name)` is left unstamped, #32812). That stamp stays, so ObjectQL still registers such an object as the host package's contribution. But `MetadataManager.unregisterPackage(host)` took the stamp as membership and deleted those rows, from memory and from the database: the environment's own items were lost when the host package was unregistered. `unregisterPackage` now leaves an item that a stored-row loader handed on naming no package and that names the package only by the stamp. The host's own items (a row whose stored body carries the host's stamp or names it under the legacy `package` key, an item registered for the host in memory or from files) are removed as before. Types stored per `(package, name)` are unchanged here. diff --git a/packages/metadata/src/loaders/database-loader.test.ts b/packages/metadata/src/loaders/database-loader.test.ts index dcc9be6ff8b..30a76836f51 100644 --- a/packages/metadata/src/loaders/database-loader.test.ts +++ b/packages/metadata/src/loaders/database-loader.test.ts @@ -2055,27 +2055,29 @@ describe('[#31699 R5-A] the priming pass never writes back a row it read from th }); /** - * [#32791; ADR-0150 D3/D4, regression of #32560] On a host that declares its - * package, the boot priming pass stamps a package-less stored row with the - * host's package before it registers it (`applyProtection`), so the registry - * holds that row in the host's slot. A read naming no package of an action - * name is judged over the registry and the loaders (#32560's + * [#32791, #32812; ADR-0150 D3/D4, regression of #32560] On a host that + * declares its package, the boot priming pass stamped a package-less stored + * row with the host's package before it registered it (`applyProtection`), so + * the registry held that row in the host's slot. A read naming no package of + * an action name is judged over the registry and the loaders (#32560's * `judgesLoaderSlots`), and the loaders still store the row package-less: one * row was counted twice, as the host's package and as the environment, and - * the refusal named a holder that does not exist. The judged view now files - * that row as the store files a write that carries no package - * (`packagelessWriteKeyOf`: the name's one holder's customization, else the - * environment's own item), with the write order of the slot it came from. - * Only a row stamped with its slot's package is filed so, and not one whose - * registration replaced an item registered in memory (that item's package - * holds the name: epic ruling B). + * the refusal named a holder that does not exist. #32791 corrected the count + * right after the pass; after a write that carries no package the host was + * named again (#32812). The pass now leaves a package-less stored row of a + * type stored per `(package, name)` unstamped (`unstampedStoredRow` in + * `plugin.ts`), so the registry files it where the store files any write + * that carries no package (the name's one holder's customization, else the + * environment's own item), whatever package the host declares. * - * BEFORE (`main` with #32676): each case below not marked CONTROL was refused - * naming `com.host.app`. The CONTROLs answer on that `main` as here; the two - * marked with a review finding were red on this branch at an earlier head. - * The boot state only: after a write that carries no package the host is - * named again (#32812), and a removal naming no package still names it - * (#32813). + * BEFORE (`main` before #32791, with #32676): each case below not marked + * CONTROL was refused naming `com.host.app`. The CONTROLs answer on that + * `main` as here. Where #32812 moved a #32791 pin, its comment names the + * FROM (`main` `25ee5076`) and the TO, which is the cell's answer on a host + * that declares no package. The comments and titles of the unmoved pins + * (the "stamped row", its overwrite mark, the judged view's filing, the + * earlier heads they cite) describe #32791's read-time mechanism, which + * #32812 removed; their answers hold unchanged with the row unstamped. */ describe('[#32791] a stored package-less row the boot pass files under the host\'s package is one holder of an action name, not two', () => { const ALPHA = 'com.alpha.app'; @@ -2146,11 +2148,15 @@ describe('[#32791] a stored package-less row the boot pass files under the host\ await seed('action', ALPHA, 1); await seed('action', null, 2); const m = await bootPass(HOST); - expect(registryKeys(m, 'action'), 'the pass files the row in the host\'s slot, as before').toEqual([`${HOST}\u0000helper`]); + // [#32812] FROM `main` `25ee5076`: the host's key (`com.host.app` and + // `helper` joined by a NUL), and the read naming the holder answering + // ALPHA's own row. TO: the row unstamped, filed in the name's bare slot, + // the holder's customization, as on a host that declares no package. + expect(registryKeys(m, 'action'), 'the pass leaves the row package-less').toEqual(['helper']); expect(await answer(m, 'action')).toBe('env'); const diagnosed = await m.getDiagnosed('action', 'helper'); expect([(diagnosed.data as { label?: string } | undefined)?.label, diagnosed.degraded]).toEqual(['env', false]); - expect(await answer(m, 'action', ALPHA), 'a read naming the holder, as before').toBe(ALPHA); + expect(await answer(m, 'action', ALPHA), 'a read naming the holder answers its customization').toBe('env'); expect(await answer(m, 'action', HOST), 'a read naming the host, as before').toBe('env'); }); @@ -2180,7 +2186,8 @@ describe('[#32791] a stored package-less row the boot pass files under the host\ await seed('action', ALPHA, 1, { objectName: 'account' }); await seed('action', null, 2); const m = await bootPass(HOST); - expect(registryKeys(m, 'action')).toEqual([`${HOST}\u0000helper`]); + // [#32812] FROM `main` `25ee5076`: the host's key. TO: the bare slot. + expect(registryKeys(m, 'action')).toEqual(['helper']); expect(await bareAnswers(m)).toEqual(['env', 'env']); }); @@ -2272,11 +2279,14 @@ describe('[#32791] a stored package-less row the boot pass files under the host\ /** * [#32791] A package's item registered in memory, and the package-less row - * the pass stamped with the host's package into a slot no other item held: - * the row is counted once, as the store files it beside that one holder - * (its customization). BEFORE (main): refused naming the host's package too. + * the pass registers: the row is counted once, never with the host's + * package beside it. BEFORE (main before #32791): refused naming the + * host's package too. [#32812] FROM `main` `25ee5076`, the first cell + * (ALPHA's item registered after the pass) answered the package-less row; + * TO: ALPHA's item, the answer on a host that declares no package or ALPHA + * (the by-host difference #32752 tracked is gone). */ - it('action, one package\'s item in memory beside the package-less row the pass stamped into an empty slot: the row is counted once', async () => { + it('action, one package\'s item in memory beside the package-less row the pass registers: the row is counted once, and a host that declares another package answers as one that declares none', async () => { const cells: InMemoryCell[] = [ [HOST, [[null]], [], [ALPHA]], [HOST, [[null]], [ALPHA], []], @@ -2284,7 +2294,8 @@ describe('[#32791] a stored package-less row the boot pass files under the host\ ]; const seen: unknown[] = []; for (const cell of cells) seen.push(await bareAfterPass(cell)); - expect(seen).toEqual(cells.map(() => ['env', 'env'])); + expect(seen).toEqual([[`${ALPHA} code`, `${ALPHA} code`], ['env', 'env'], ['env', 'env']]); + expect(await bareAfterPass([undefined, [[null]], [], [ALPHA]]), 'the same cell on a host that declares no package').toEqual([`${ALPHA} code`, `${ALPHA} code`]); }); it('action, two packages\' items in memory beside the package-less row the pass stamped, in either order: the bare read is refused naming both and the environment, never the host (BEFORE: the host named too)', async () => { @@ -2383,17 +2394,24 @@ describe('[#32791] a stored package-less row the boot pass files under the host\ }); /** - * [#32791, review N1] The row is counted once only while a loader still - * stores it: removed from the table behind the manager, the registry's - * slot is counted as before (after the removal main answers the same). + * [#32791, review N1; #32812] The package-less row removed from the table + * behind the manager: the registry's copy is counted as the one holder's + * customization, as on a host that declares no package. FROM `main` + * `25ee5076`: refused naming the host's package, which holds nothing, and + * ALPHA. TO: the registry's copy. */ - it('action, the package-less row removed from the table behind the manager after the pass: the row is no longer counted once, and the host\'s slot is a holder again', async () => { - await seedRows([[ALPHA], [null]]); - const m = await bootPass(HOST); - expect(await bareAnswers(m)).toEqual(['env', 'env']); - await driver.delete('sys_metadata', 'action_env_2'); - for (const loader of (m as any).loaders.values()) (loader as DatabaseLoader).invalidateAll(); - expect(await bareAnswers(m)).toEqual([REFUSED(HOST, ALPHA), REFUSED(HOST, ALPHA)]); + it('action, the package-less row removed from the table behind the manager after the pass: the host\'s package is never a holder, as on a host that declares none', async () => { + const seen: unknown[] = []; + for (const hostPackage of [HOST, undefined]) { + driver = createMockDriver(); + await seedRows([[ALPHA], [null]]); + const m = await bootPass(hostPackage); + seen.push(await bareAnswers(m)); + await driver.delete('sys_metadata', 'action_env_2'); + for (const loader of (m as any).loaders.values()) (loader as DatabaseLoader).invalidateAll(); + seen.push(await bareAnswers(m)); + } + expect(seen).toEqual([['env', 'env'], ['env', 'env'], ['env', 'env'], ['env', 'env']]); }); it('CONTROL every by-package type, one package\'s row and a package-less row: the bare read answers the row the pass registered — the package-less row saved last, the holder\'s row saved last — on a host declaring no package, the holder, or another (action\'s package-less row saved last on another host: the first case)', async () => { @@ -2429,6 +2447,190 @@ describe('[#32791] a stored package-less row the boot pass files under the host\ expect(registryKeys(m, 'action')).toEqual([`${ALPHA}\u0000helper`, `${HOST}\u0000helper`]); expect(await bareAnswers(m)).toEqual([REFUSED(ALPHA, HOST), REFUSED(ALPHA, HOST)]); }); + + /** + * [#32812] The state after the pass and a write that carries no package + * (PR #32802's TO held for the boot state only, epic ruling C). One + * package's row, a package-less row saved last, a host declaring another + * package; then `register` with no package, or `registerInMemory` of a + * package-less item, of the name. The written item is that one holder's + * customization (D4), so the bare read answers it, as before #32560. + * BEFORE (main `25ee5076`): `409` naming the host's package, which holds + * nothing, beside the holder and the environment. + */ + it('action, after the pass on a host declaring another package, a register with no package of a name one package holds: the bare read answers the written body, and getDiagnosed agrees (BEFORE: 409 naming the host, the holder and the environment)', async () => { + await seedRows([[ALPHA], [null]]); + const m = await bootPass(HOST); + await m.register('action', 'helper', { name: 'helper', label: 'written' }); + expect(await bareAnswers(m)).toEqual(['written', 'written']); + }); + + it('action, after the pass on a host declaring another package, a registerInMemory of a package-less item of a name one package holds: the bare read answers the item, and getDiagnosed agrees (BEFORE: 409 naming the host, the holder and the environment)', async () => { + await seedRows([[ALPHA], [null]]); + const m = await bootPass(HOST); + m.registerInMemory('action', 'helper', { name: 'helper', label: 'in memory' }); + expect(await bareAnswers(m)).toEqual(['in memory', 'in memory']); + }); + + /** + * [#32812, #32813's subject in this composition] The removal naming no + * package counts the holders the bare read counts: right after the pass + * and after a register with no package, on a host declaring another + * package exactly as on one declaring none. FROM `main` `25ee5076`: the + * removal right after the pass was refused naming the host's package, + * ALPHA and the environment while the bare read answered the package-less + * row (PR #32802's acceptance note). TO: it removes the package-less row, + * and the bare read then answers ALPHA's row; after the write, which the + * table took into ALPHA's row (its customization, D4), ALPHA's row answers + * the written body. + */ + it('action, one package\'s row and a package-less row saved last: the removal naming no package agrees with the bare read, on a host declaring another package as on one declaring none', async () => { + const removal = async (m: MetadataManager) => answerOf(async () => { + await m.unregister('action', 'helper'); + return { label: 'removed' }; + }); + const seen: Record = {}; + for (const hostPackage of [HOST, undefined]) { + for (const write of [false, true]) { + driver = createMockDriver(); + await seedRows([[ALPHA], [null]]); + const m = await bootPass(hostPackage); + if (write) await m.register('action', 'helper', { name: 'helper', label: 'written' }); + const before = await bareAnswers(m); + const removed = await removal(m); + seen[`${hostPackage ?? 'none'} ${write ? 'after a write' : 'after the pass'}`] = [...before, removed, ...(await bareAnswers(m))]; + } + } + expect(seen).toEqual({ + [`${HOST} after the pass`]: ['env', 'env', 'removed', ALPHA, ALPHA], + [`${HOST} after a write`]: ['written', 'written', 'removed', 'written', 'written'], + 'none after the pass': ['env', 'env', 'removed', ALPHA, ALPHA], + 'none after a write': ['written', 'written', 'removed', 'written', 'written'], + }); + }); + + /** + * [#32812] Every by-package type, the card's composition and a register + * with no package after the pass: the bare read answers the written body + * on a host declaring another package, as on one declaring none. CONTROL + * for the eight types other than `action`, whose bare read does not judge + * the loaders' slots (`judgesLoaderSlots`); `action` is the card's first + * row. + */ + it('every by-package type, one package\'s row and a package-less row saved last, then a register with no package: the bare read answers the written body on a host declaring another package or none', async () => { + const seen: unknown[] = []; + for (const type of UNBUNDLED) { + for (const hostPackage of [HOST, undefined]) { + driver = createMockDriver(); + await seed(type, ALPHA, 1); + await seed(type, null, 2); + const m = await bootPass(hostPackage); + await m.register(type, 'helper', { name: 'helper', label: 'written' }); + seen.push([type, hostPackage ?? 'none', await answer(m, type)]); + } + } + expect(seen).toEqual(UNBUNDLED.flatMap((type) => [[type, HOST, 'written'], [type, 'none', 'written']])); + }); + + /** + * [#32812] `email_template` (bundled), one package's row and a package-less + * row saved last: the pass files the package-less row in the holder's slot + * (its customization), on a host declaring another package as on one + * declaring none. FROM `main` `25ee5076`: the host's slot beside the + * holder's, and the bare read refused naming the holder and the host. + */ + it('email_template, one package\'s row and a package-less row saved last: the pass files the row in the holder\'s slot and the bare read answers it, on a host declaring another package as on one declaring none', async () => { + const seen: unknown[] = []; + for (const hostPackage of [HOST, undefined]) { + driver = createMockDriver(); + await seed('email_template', ALPHA, 1); + await seed('email_template', null, 2); + const m = await bootPass(hostPackage); + seen.push([hostPackage ?? 'none', registryKeys(m, 'email_template'), await answer(m, 'email_template')]); + } + expect(seen).toEqual([[HOST, [`${ALPHA}\u0000helper`], 'env'], ['none', [`${ALPHA}\u0000helper`], 'env']]); + }); + + /** + * [#32812, contract review r1 M1] A loader of stored rows is told by its + * protocol (`datasource:`), not by `DatabaseLoader`'s name: a loader that + * declares the protocol under another name hands out package-less rows the + * pass leaves unstamped too. FROM `main` `25ee5076`: right after the pass + * the bare read answered the package-less row (#32791's filing keyed on the + * protocol), and after a register with no package it was refused naming the + * host's package; at this PR's first head (keyed on the name) it was + * refused right after the pass as well. TO: the package-less row, then the + * written body, as through `DatabaseLoader`. + */ + it('action, the card\'s composition through a stored-row loader that declares `datasource:` under another name: the pass leaves the row unstamped, and the bare read answers it, then the written body', async () => { + await seedRows([[ALPHA], [null]]); + const plugin = new MetadataPlugin({ packageId: HOST, watch: false, config: { bootstrap: 'eager' } }); + const m = (plugin as any).manager as MetadataManager; + (m as any).loaders.clear(); + const loader = new DatabaseLoader({ driver }); + (loader as any).contract = { ...loader.contract, name: 'tenant-rows' }; + m.registerLoader(loader); + await (plugin as any)._loadFromFileSystem({ logger: { info: vi.fn(), warn: vi.fn(), error: vi.fn(), debug: vi.fn() } }); + expect(registryKeys(m, 'action')).toEqual(['helper']); + expect(await bareAnswers(m)).toEqual(['env', 'env']); + await m.register('action', 'helper', { name: 'helper', label: 'written' }); + expect(await bareAnswers(m)).toEqual(['written', 'written']); + }); + + /** + * [#32812, contract review r1 S1] The narrowing arm's own answers, on a host + * declaring another package beside one declaring none, after the pass: the + * served package-less row carries no `_packageId` or `_provenance`, `list` + * names it once, and the package-wide verbs naming the host's package do + * not take it. FROM `main` `25ee5076`: stamped with the host's package and + * `_provenance: 'package'`, listed twice beside the holder's row (its + * customization and the host's), dropped from the registry by + * `unregisterPackage` and published (its row rebound to the host's package) + * by `publishPackage`. TO: as on a host that declares no package. Whether a + * disabled host package hides the row is read by `@objectstack/core` and + * `@objectstack/runtime` off the served `_packageId`, not pinned here. + */ + it('action, one package\'s row and a package-less row saved last: the served row carries no stamp, list names it once, and unregisterPackage or publishPackage naming the host\'s package leaves it, as on a host declaring none', async () => { + const seen: Record = {}; + for (const hostPackage of [HOST, undefined]) { + const stamps = async (m: MetadataManager) => { + const item = (await m.get('action', 'helper')) as Record | undefined; + return [item?._packageId, item?._provenance]; + }; + const listed = async (m: MetadataManager) => ((await m.list('action')) as Array<{ label?: string }>).map((item) => item.label).sort(); + const tableOf = async () => ((await driver.find('sys_metadata', { where: { type: 'action' } } as never)) as Array>) + .map((row) => [row.package_id ?? null, row.version]).sort(); + driver = createMockDriver(); + await seedRows([[ALPHA], [null]]); + const m = await bootPass(hostPackage); + const before = [await stamps(m), await listed(m)]; + const published = await m.publishPackage(HOST).then((r: any) => r?.success, (e: any) => e?.code ?? 'threw'); + const afterPublish = await tableOf(); + await m.unregisterPackage(HOST); + seen[hostPackage ?? 'none'] = [...before, published, afterPublish, await bareAnswers(m), await tableOf()]; + } + expect(seen[HOST]).toEqual(seen.none); + expect(seen.none).toEqual([[undefined, undefined], ['env'], false, [[null, 2], [ALPHA, 1]], ['env', 'env'], [[null, 2], [ALPHA, 1]]]); + }); + + /** + * [#32812, contract review r1 S1] A package-less `action` row alone, + * removed with no package after the pass: nothing of it is left to read. + * FROM `main` `25ee5076`: the row deleted, the registry's copy stamped with + * the host's package left in the host's slot, answering the bare read and + * `list` until a restart. TO: as on a host that declares no package. + */ + it('action, a package-less row alone removed with no package after the pass: the bare read and list answer nothing, on a host declaring another package as on one declaring none', async () => { + const seen: unknown[] = []; + for (const hostPackage of [HOST, undefined]) { + driver = createMockDriver(); + await seedRows([[null]]); + const m = await bootPass(hostPackage); + await m.unregister('action', 'helper'); + seen.push([hostPackage ?? 'none', await answer(m, 'action'), (await m.list('action')).length, registryKeys(m, 'action')]); + } + expect(seen).toEqual([[HOST, undefined, 0, []], ['none', undefined, 0, []]]); + }); }); /** @@ -2755,6 +2957,11 @@ describe('[#32521] the boot priming pass primes every holder of a name', () => { * package-less row of a name, measured at `efd4ea3a` (before this change) * and unchanged by it: `[order, host package, DatabaseLoader.loadMany, * registry keys, bare read, read naming ALPHA, read naming HOST]`. + * [#32812] The package-less row saved last, on a host declaring ALPHA or + * another package, now answers as on a host declaring none: the pass leaves + * the row unstamped. FROM `main` `25ee5076`: host ALPHA, key ALPHA's, read + * naming HOST nothing; host HOST, key the host's, read naming ALPHA ALPHA's + * own row. TO: the bare key, every read the package-less row. */ /** * The same across two loaders, one holding ALPHA's item and the other a @@ -2768,8 +2975,8 @@ describe('[#32521] the boot priming pass primes every holder of a name', () => { ]; const ONE_HOLDER_AND_A_PACKAGELESS_ROW = [ ['package-less row saved last', 'no host package', ['env'], ['helper'], 'env', 'env', 'env'], - ['package-less row saved last', ALPHA, ['env'], [`${ALPHA}\u0000helper`], 'env', 'env', undefined], - ['package-less row saved last', HOST, ['env'], [`${HOST}\u0000helper`], 'env', ALPHA, 'env'], + ['package-less row saved last', ALPHA, ['env'], ['helper'], 'env', 'env', 'env'], + ['package-less row saved last', HOST, ['env'], ['helper'], 'env', 'env', 'env'], ['package-less row saved first', 'no host package', [ALPHA], [`${ALPHA}\u0000helper`], ALPHA, ALPHA, undefined], ['package-less row saved first', ALPHA, [ALPHA], [`${ALPHA}\u0000helper`], ALPHA, ALPHA, undefined], ['package-less row saved first', HOST, [ALPHA], [`${ALPHA}\u0000helper`], ALPHA, ALPHA, undefined], diff --git a/packages/metadata/src/metadata-manager.ts b/packages/metadata/src/metadata-manager.ts index 2fd11c33685..d48a78267ac 100644 --- a/packages/metadata/src/metadata-manager.ts +++ b/packages/metadata/src/metadata-manager.ts @@ -98,7 +98,6 @@ import { readStoreEntry, inheritStoreWriteOrder, judgesLoaderSlots, - packagelessWriteKeyOf, platformSlotsOf, recordStoreWrite, slotPackageOf, @@ -647,13 +646,6 @@ export class MetadataManager implements IMetadataService { private loaders: Map = new Map(); /** [#31699 R5-A] The loader {@link loadMany} read each item object from ({@link MetadataRegisterOptions}). */ private readonly loadedFrom = new WeakMap(); - /** - * [ADR-0150 D4, #32791] The items of a type stored per `(package, name)` - * that {@link loadMany} read from a stored-row loader (`datasource:`) held - * for no package: the environment's rows. The boot priming pass may stamp - * one with the host's package before it registers it ({@link slotViewOf}). - */ - private readonly storedPackagelessRows = new WeakSet(); /** * [#32986] The items of every OTHER type (one not stored per * `(package, name)`: `object`, `view`, `app`, `hook`, `dashboard` …) that @@ -665,13 +657,6 @@ export class MetadataManager implements IMetadataService { * ({@link isStampedEnvironmentRow}). */ private readonly storedEnvironmentRows = new WeakSet(); - /** - * [ADR-0150 D4, #32791] The {@link storedPackagelessRows} whose registration - * replaced an item no loader handed out (one registered in memory or by - * code): that item's package held the name before the row took its slot, so - * the slot is a holder, not only the row ({@link slotViewOf}). - */ - private readonly storedRowsOverOwnItems = new WeakSet(); // Protected so subclasses can access serializers if needed protected serializers: Map; protected logger: Logger; @@ -1309,13 +1294,6 @@ export class MetadataManager implements IMetadataService { const { key, replaces } = slot === undefined ? storeWriteKey(typeStore, type, name, data) : { key: slot, replaces: [] }; if (!typeStore) this.registry.set(type, (typeStore = new Map())); const existed = typeStore.has(key) || replaces.length > 0; - if (data !== null && typeof data === 'object' && this.storedPackagelessRows.has(data)) { - const before = typeStore.get(key); - // [review S3] A row that replaces a marked row (the pass run again) carries its mark. - if (before !== null && typeof before === 'object' && before !== data && (!this.loadedFrom.has(before) || this.storedRowsOverOwnItems.has(before))) { - this.storedRowsOverOwnItems.add(data); - } - } for (const replaced of replaces) typeStore.delete(replaced); typeStore.set(key, data); recordStoreWrite(typeStore, key); @@ -1485,10 +1463,7 @@ export class MetadataManager implements IMetadataService { // stores it — judged only over loaders that all answered: with one down, // the slot is read as the environment's, as before. const platformKeys = errors.length === 0 ? platformSlotsOf(this.registry.get(type), type, name, loaderStore) : undefined; - // [#32791] A read naming none counts a stored row the boot pass stamped - // with the host's package once, as the loaders store it. - const view = this.slotViewOf(type, name, loaderStore, !isPackageCaller(packageId)); - const entry = readStoreEntry(view, type, name, packageId, platformKeys); + const entry = readStoreEntry(this.slotViewOf(type, name, loaderStore), type, name, packageId, platformKeys); return entry.found ? { data: entry.data, degraded: false, errors } : { data: null, degraded: errors.length > 0, errors }; @@ -1529,71 +1504,26 @@ export class MetadataManager implements IMetadataService { * registry's slots of the name, then the loaders' stored items keyed as the * store keys them ({@link slotStoreOf}), what the registry (then an earlier * loader) holds kept over a later item of the same slot. Reads and removals - * judge a name the registry cannot answer alone over this view. - * - * [ADR-0150 D4, #32791] `asStored`, for a read naming no package: a - * registry slot of a package whose item is a stored package-less row - * ({@link storedPackagelessRows}) stamped with that same package (the boot - * pass stamps it with the host's package before it registers it), while a - * loader still stores the row, is that row, not a holder of its own. It is - * filed in the view as the store files a write that carries no package - * ({@link packagelessWriteKeyOf}: the name's one holder's customization, - * else the environment's own item) in place of the loader's copy of the - * row, and keeps the write order of the registry slot it came from, so one - * row is counted once, never as the host's package and as the environment. - * A package's own item, a host's own item that no stored row is, an - * unstamped row the registry's own write rule filed in its one holder's - * slot (that holder's customization), and a row whose registration replaced - * an item no loader handed out ({@link storedRowsOverOwnItems}: that item's - * package holds the name) keep their slots. A removal judges - * the view without `asStored`, so in that composition the read and the - * removal naming no package do not count the same holders. + * judge a name the registry cannot answer alone over this view, so they + * agree on who holds it. */ private slotViewOf( type: string, name: string, loaderStore: ReadonlyMap, - asStored = false, ): Map { const registryStore = this.registry.get(type); const view = new Map(); - const storedRows: Array<{ key: string; data: unknown }> = []; - const storedKeys = new Set(); // [#32517] Each slot's member written last first: a slot no key of which // came from the registry answers its first member (`latestMemberOf`). if (registryStore) { - for (const key of latestMembersFirst(registryStore, storeKeysNamed(registryStore, type, name))) { - const data = registryStore.get(key); - const stampedWith = slotPackageOf(key); - if ( - asStored && stampedWith !== undefined && data !== null && typeof data === 'object' - && this.storedPackagelessRows.has(data) && indexedItemPackageId(data) === stampedWith - && !this.storedRowsOverOwnItems.has(data) - ) { - const stored = storeSlotKey(type, name, undefined, data); - if (loaderStore.has(stored)) { - storedRows.push({ key, data }); - storedKeys.add(stored); - continue; - } - } - view.set(key, data); - } + for (const key of latestMembersFirst(registryStore, storeKeysNamed(registryStore, type, name))) view.set(key, registryStore.get(key)); } for (const [key, data] of loaderStore) { - if (!view.has(key) && !storedKeys.has(key)) view.set(key, data); - } - // [#32791] The row the boot pass primed, over the loader's copy of the - // slot it fills (its holder's row: the customization shadows it, D4), - // written when the registry's slot it came from was. - const aliases = new Map(); - for (const { key, data } of storedRows) { - const at = packagelessWriteKeyOf(view, type, name, data); - view.set(at, data); - aliases.set(at, key); + if (!view.has(key)) view.set(key, data); } // [#32560] "Written last" over the view is the registry's own order. - inheritStoreWriteOrder(view, registryStore, aliases); + inheritStoreWriteOrder(view, registryStore); return view; } @@ -3815,6 +3745,18 @@ export class MetadataManager implements IMetadataService { return this.loadedFrom.get(item)?.contract.name; } + /** + * [#32812] The protocol of the loader {@link loadMany} read `item` — that + * very object — from (`'datasource:'` for a loader of stored rows, + * `DatabaseLoader` or another that declares the protocol under its own + * name); `undefined` for an object it did not hand out. The boot priming + * pass asks it to keep the host's package off a package-less stored row + * (`MetadataPlugin`'s pass). + */ + sourceLoaderProtocolOf(item: object): string | undefined { + return this.loadedFrom.get(item)?.contract.protocol; + } + /** * Load multiple metadata items from loaders. * Aggregates results from all loaders. @@ -3877,11 +3819,10 @@ export class MetadataManager implements IMetadataService { results.push(item); if (item !== null && typeof item === 'object') { this.loadedFrom.set(item, loader); - // [#32791] Read here, before any caller stamps it. - if (loader.contract.protocol === 'datasource:' && indexedItemPackageId(item) === undefined) { - if (PACKAGE_SLOTTED_STORE_TYPES.has(type)) this.storedPackagelessRows.add(item); - // [#32986] Read here too, before the boot pass stamps it. - else this.storedEnvironmentRows.add(item); + // [#32986] Read here, before the boot pass stamps it. A type stored + // per `(package, name)` is not stamped on such a row (#32812). + if (loader.contract.protocol === 'datasource:' && !PACKAGE_SLOTTED_STORE_TYPES.has(type) && indexedItemPackageId(item) === undefined) { + this.storedEnvironmentRows.add(item); } } }); diff --git a/packages/metadata/src/package-slotted-store.ts b/packages/metadata/src/package-slotted-store.ts index 7b66ef824b1..bf120d33c03 100644 --- a/packages/metadata/src/package-slotted-store.ts +++ b/packages/metadata/src/package-slotted-store.ts @@ -264,15 +264,9 @@ function writtenLast(store: ReadonlyMap, keys: readonly string[ * [ADR-0150 D3, #32560] Give `view` (a store assembled from `from`'s slots and * others) `from`'s write order for the keys it took from it, so a read over * the view answers "written last" as the read over `from` does. A key `from` - * does not hold counts as written before every key it does. [#32791] A view - * key `aliases` maps to the key of `from` its item was taken from (the view - * filed that item under another key) takes that key's order. + * does not hold counts as written before every key it does. */ -export function inheritStoreWriteOrder( - view: ReadonlyMap, - from: ReadonlyMap | undefined, - aliases?: ReadonlyMap, -): void { +export function inheritStoreWriteOrder(view: ReadonlyMap, from: ReadonlyMap | undefined): void { const order = from ? writeOrder.get(from) : undefined; if (!order) return; // [#32517] A slot none of whose members came from `from` still answers its @@ -280,9 +274,8 @@ export function inheritStoreWriteOrder( inheritedViews.add(view); const inherited = new Map(); for (const key of view.keys()) { - const fromKey = aliases?.get(key) ?? key; - const at = order.get(fromKey); - if (at !== undefined && view.get(key) === from!.get(fromKey)) inherited.set(key, at); + const at = order.get(key); + if (at !== undefined && view.get(key) === from!.get(key)) inherited.set(key, at); } writeOrder.set(view, inherited); } @@ -654,41 +647,16 @@ function slottedWriteKey( const packageId = storedItemPackageId(data); return { key: keyed(packageId === undefined ? identity : slotKey(packageId, identity)), replaces: [] }; } - const packageId = storedItemPackageId(data); - if (packageId === undefined) return { key: keyed(packagelessSlotOf(store, identity)), replaces: [] }; const holders = packageSlotsOf(store, identity); + const packageId = storedItemPackageId(data); + if (packageId === undefined) { + return { key: keyed(holders.length === 1 ? slotKey(holders[0]!, identity) : identity), replaces: [] }; + } const others = holders.filter((holder) => holder !== packageId); const bare = keyed(identity); return { key: keyed(slotKey(packageId, identity)), replaces: others.length === 0 && store.has(bare) ? [bare] : [] }; } -/** - * [ADR-0150 D4] The slot a write that carries no package fills under - * `identity`: the holder's slot under a name exactly one package holds (a - * package-less row bearing a package-held name is that holder's - * customization, never a second item), else the identity's bare slot (the - * environment's own item). - */ -function packagelessSlotOf(store: ReadonlyMap, identity: string): string { - const holders = packageSlotsOf(store, identity); - return holders.length === 1 ? slotKey(holders[0]!, identity) : identity; -} - -/** - * [ADR-0150 D4, #32791] The key {@link storeWriteKey} gives `data` written to - * `store` as an item that carries no package, whatever package its body is - * stamped with now: the name's one holder's slot (its customization), else - * the identity's bare slot (the environment's own item); [#32517] a bundled - * type's member keyed under it. The manager files a stored package-less row - * the boot pass registered under the host's package by this rule when it - * judges a read naming no package over its view of the registry and the - * loaders, so the row is one holder of the name, as the loaders store it. - */ -export function packagelessWriteKeyOf(store: ReadonlyMap, type: string, name: string, data: unknown): string { - if (!PACKAGE_SLOTTED_STORE_TYPES.has(type)) return name; - return memberKeyOf(type, packagelessSlotOf(store, slotIdentityOf(type, name, data)), data); -} - /** * [#32246] {@link storeWriteKey} for a store with one slot per `(package, * name)` whatever object an action is bound to: `DatabaseLoader`'s rows, diff --git a/packages/metadata/src/plugin.ts b/packages/metadata/src/plugin.ts index 47649fc5c09..c42d084bd1e 100644 --- a/packages/metadata/src/plugin.ts +++ b/packages/metadata/src/plugin.ts @@ -14,7 +14,7 @@ import { Plugin, PluginContext } from '@objectstack/core'; import { resolveArtifactPackageOrder, artifactPackageId } from '@objectstack/core'; import { NodeMetadataManager } from './node-metadata-manager.js'; import { MemoryLoader } from './loaders/memory-loader.js'; -import { PACKAGE_SLOTTED_STORE_TYPES, bundleEntryKey, isBundledStoreType, pluralEntryKeys, storedItemPackageId } from './package-slotted-store.js'; +import { PACKAGE_SLOTTED_STORE_TYPES, bundleEntryKey, isBundledStoreType, storedItemPackageId } from './package-slotted-store.js'; import { DEFAULT_METADATA_TYPE_REGISTRY, judgeCollectionItemOwnerStamp, OWNER_STAMP_JUDGED_COLLECTIONS } from '@objectstack/spec/kernel'; import type { MetadataPluginConfig } from '@objectstack/spec/kernel'; import { applyProtection } from '@objectstack/spec/shared'; @@ -1672,7 +1672,6 @@ export class MetadataPlugin implements Plugin { // the earlier loader's item keeps the entry — the file over its // own stale seed. One loader's own items never shadow each other. const primedBy = new Map(); - const contested = contestedNames(entry.type, items); for (const item of primingOrder(entry.type, items)) { const meta = item as any; if (meta?.name) { @@ -1682,14 +1681,13 @@ export class MetadataPlugin implements Plugin { // uses, so both load paths produce identical // _packageId/_provenance state. No-op when the // option is unset or the item is already stamped. - // [#32521] Not a package-less stored row of a name - // two packages hold: it stays the environment's own - // item (`contestedNames`). The host's own file item - // of such a name is stamped as before. + // [#32521, #32812] Never a package-less stored row + // of a type stored per `(package, name)`: it stays + // the environment's own item, which the store files + // by its write rule (`unstampedStoredRow`). The + // host's own file item is stamped as before. applyProtection(meta, { - packageId: storedItemPackageId(meta) === undefined - && contested.has(meta.name) - && this.manager.sourceLoaderOf(meta) === STORED_ROW_LOADER + packageId: unstampedStoredRow(entry.type, meta, this.manager.sourceLoaderProtocolOf(meta)) ? undefined : this.options.packageId, }); @@ -1725,40 +1723,28 @@ export class MetadataPlugin implements Plugin { } } -/** The loader whose items are stored rows: `DatabaseLoader`'s `contract.name`. */ -const STORED_ROW_LOADER = 'database'; +/** The protocol of a loader whose items are stored rows: `DatabaseLoader`'s, and any loader's that declares it. */ +const STORED_ROW_PROTOCOL = 'datasource:'; /** - * [#32521; epic #31527 red lines 2 and 3, contract reviews F1 and D1] The - * names two or more packages hold among a type's items, for an unbundled type - * stored per `(package, name)`. The boot priming pass does not stamp a - * package-less STORED ROW of such a name (an item `DatabaseLoader` handed on) - * with the host's declared package: ADR-0150 D4 makes a package-less row a - * holder's customization only under a name ONE package holds, so under a name - * two hold it is the environment's own item, and that is what a read without - * the pass answers. Stamped, the store would file it into the host's slot — - * over that holder's own item when the host is one of the holders (a read - * naming it would answer the package-less body and `list` would drop its - * item), or as a third holder when it is not. The host's own file item of such - * a name is the host package's item and keeps the stamp, so its edit still - * reaches the host's slot and row over a row an earlier boot seeded from it. A - * name one package holds is not here, so its package-less row is stamped as - * before. Every other type: none. + * [#32521, #32812; epic #31527 red line 2, ADR-0150 D4] Whether the boot + * priming pass keeps the host's declared package off `item`: a package-less + * STORED ROW (an item a `datasource:` loader, `DatabaseLoader` or another of + * that protocol, handed on that names no package, as `loadMany` hands it on) + * of a type stored per `(package, name)`. Such a row is the + * environment's own item, or the customization of the one package that holds + * its name (D4), and the store files it where it files any write that carries + * no package. Stamped with the host's package, the registry filed it into the + * host's slot while the loaders still stored it package-less: the host was + * counted as a holder it is not (a third holder beside two packages, #32521; + * a second beside one, which after a package-less write named the host in + * the bare read's refusal, #32812), and the read naming the holder served + * the holder's own row over its customization. Unstamped, every read answers + * what it answers on a host that declares no package. The host's own file items, and every other + * type's items, are stamped as before. */ -function contestedNames(type: string, items: unknown[]): ReadonlySet { - if (!PACKAGE_SLOTTED_STORE_TYPES.has(type) || isBundledStoreType(type)) return new Set(); - // `pluralEntryKeys` keys a name no package or one package holds once (a - // package-less item beside one holder takes that holder's key, D4), and a - // name two or more packages hold once per holder: a name of two or more - // keys is a name two or more packages hold. - const keysOf = new Map>(); - const names = items.map((item) => (item as { name?: unknown } | null)?.name); - pluralEntryKeys(type, items.map((item, at) => ({ name: names[at], data: item }))).forEach((key, at) => { - const name = names[at]; - if (key === undefined || typeof name !== 'string') return; - keysOf.set(name, (keysOf.get(name) ?? new Set()).add(key)); - }); - return new Set([...keysOf].filter(([, keys]) => keys.size > 1).map(([name]) => name)); +function unstampedStoredRow(type: string, item: unknown, protocol: string | undefined): boolean { + return PACKAGE_SLOTTED_STORE_TYPES.has(type) && storedItemPackageId(item) === undefined && protocol === STORED_ROW_PROTOCOL; } /** @@ -1773,8 +1759,8 @@ function contestedNames(type: string, items: unknown[]): ReadonlySet { * package-less item would be filed into the first one's slot as its * customization and answer a read naming that package; registered before * them, the first one's item would take its bare slot over and `list` would - * drop it. With the host's package stamp kept off such an item - * (`contestedNames`), the registry holds what a read without the pass + * drop it. With the host's package stamp kept off a package-less stored row + * (`unstampedStoredRow`), the registry holds what a read without the pass * answers, whatever order the loaders handed the items in and whatever * package the host declares. A name one package holds * hands on one item, whose order does not move. Every other type: as handed.