Skip to content

Commit 5af956f

Browse files
fix(objectql)!: a bare doc read refuses a name two enabled packages hold, naming both (#34036)
<!-- claude-projects-attribution: {"github_login":"zhuangjianguo"} --> _Requested by **Steedos** · [project thread](https://claude.ai/code/project/chan_018ETKaNwMZCNRYD7D8Q9Ubb?thread=cmsg_018ETKaNwMZCNRYD7D8Q9UbbBePzY6g11h3hyWk5ud4vWy)_ Fixes #33264 Clause-②: no (narrowing) — narrowed: a by-name read of a doc that names no package (`GET /meta/doc/NAME` and the doors that read through it, `MetadataFacade.get`/`getEntry`), of a name two or more enabled packages hold, moves from one holder's body, picked by registration order, to `409 RESOURCE_CONFLICT` naming every holder. Unchanged: one holder, a read that names the package, the environment's own item. Metadata-protocol: none Skills-docs: none — `content/docs/api/client-sdk.mdx` (the `/meta` 409 section) already teaches that an ambiguous bare read answers `409 RESOURCE_CONFLICT` listing the holders; this PR makes the doc read honour it. The `?package=` remedy for a doc on a composed artifact server is tracked in #34040 / #34041. Follow-ups named by ruling 6893582352: #34069 (domain:skills, ADR-0048 status line) and #34070 (domain:ui, Console `/docs/NAME` candidates on a 409). Composed-rig pins (review N2/N6) are carried by #34040 (acceptance item 4). ## 维护者速读 - 改了什么:两个启用的包都带同名帮助文档(doc)时,不指明包的按名读取(REST `/meta/doc/名字` 与进程内 `MetadataFacade.get`)不再按注册顺序随便给一份,而是回 409 并列出所有持有包。 - 为什么改:落实裁决 6893582352(选项 A「拒绝并列出候选」):有歧义就报出来,不猜;与已经拒绝的裸保存、删除、发布、分层读取对齐。 - 风险与回滚:只影响「两个及以上启用包同名 doc」这一情形,一方实测零存量;单持有者、指明包的读取、环境自己的 doc 都不变。回滚即还原本 PR。 - 先看:`packages/objectql/src/registry.ts` 的 `readBareDoc`(判定本身);`packages/metadata-protocol/src/protocol-meta-item-reads.ts` 的 `refuseAmbiguousBareDocRead` 调用点(在任何层读取之前);`packages/objectql/src/package-scoped-e8-readers.test.ts` 末尾新增的 describe。 - 两分钟验证:`pnpm --filter @objectstack/objectql exec vitest run src/package-scoped-e8-readers.test.ts -t ruling`,预期 7 个用例(按两种注册顺序展开共 12 个)全部通过。 - 需要你做的:按 Clause-② 收窄面安排一次契约复审(contract review)。 ## What changes The ruling on #33264 (comment 6893582352, option A) chose: a context-free read of a `doc` name held by two or more enabled packages answers `409 RESOURCE_CONFLICT` naming every holder, at the REST door and the in-process facade. `doc` stays in ADR-0150 D1 bucket 1; no address form changes. - `packages/objectql/src/registry.ts`: `SchemaRegistry.resolveItem('doc', name)` with no caller package goes through a new private `readBareDoc`. It counts the served holders with `packageScopedHoldersOf` (a disabled package holds no name) and throws `PackageScopedNameRefusedError` (`ambiguous-in-environment`, the same refusal the package-scoped types give) when two or more hold the name. A package-less bare-slot entry (the environment's own item) answers first, as `getItem` served it. With one enabled holder beside a disabled one, it answers the enabled holder's item; otherwise it is `getItem`, unchanged. `MetadataFacade.get` / `getEntry` / `exists` already read through `resolveItem`. - `packages/metadata-protocol/src/protocol-meta-item-reads.ts`: `readMetaItem` asks that judge (`refuseAmbiguousBareDocRead`) before any layer is read, for a read naming no package of type `doc`. It is a judge only: when the registry answers, the read's layers run exactly as before. Seam: both. Measured on a composed server (below), the REST bare read never reached the registry for this answer: the metadata service keeps a doc by name alone and answered the package registered LAST. So a registry-only judge would have missed the REST door, and a protocol-only judge would have missed the facade. The judge lives once, in the registry; the protocol only asks it. | Read | FROM (origin/main) | TO (this PR) | |:---|:---|:---| | `GET /meta/doc/NAME`, two enabled holders (composed server: dispatcher and RestServer; `/layers` and `/published` too) | `200`, the holder registered last | `409 RESOURCE_CONFLICT`, both holders named | | `MetadataFacade.get('doc', NAME)` / `getEntry`, two enabled holders | the holder registered first | `409 RESOURCE_CONFLICT` (`PackageScopedNameRefusedError`), both named | | `MetadataFacade.exists('doc', NAME)`, two enabled holders | `true` | `true` (unchanged) | | one holder; `?package=`; a package caller; the environment's own item | as before | as before | | `MetadataFacade.get`, two holders, one disabled | the first registered (may be the disabled one's) | the enabled holder's | | `GET /meta/doc/NAME`, two holders, one disabled | `404` when the disabled one registered last, else the enabled one's | unchanged | ## Tests New top-level describe in the shared harness `packages/objectql/src/package-scoped-e8-readers.test.ts` (real `SchemaRegistry`, real `ObjectStackProtocolImplementation`, real `MetadataFacade`), every two-holder pin in both registration orders. Refusal pins assert `code` `RESOURCE_CONFLICT`, `status` `409`, the reason and each holder named. - FROM one holder's body TO 409: the protocol read on both faces, the facade (`get`, `getEntry`) and the registry refuse; `exists` stays `true`. - FROM the service's copy TO 409: with a metadata service that keeps the doc registered last, the read is refused before that layer is read. - A package-less row only the store holds is no exemption: the read's layers do not serve such a row for a `doc` (measured), so exempting it would reopen the registration-order pick. - CONTROLs: one holder at every reader; the exact address and the package caller read their own holder in both orders; a disabled package holds no name (the facade serves the enabled one, re-enabled it refuses again); the environment's own item answers first beside two holders. Ablation, each leg through `scripts/ablation-replace.mjs` (anchor 1 to 0, blob moved, restored blob equal to HEAD and `git diff HEAD` empty), pins run with `-t ruling`: <details><summary>Four legs, each red, each restored</summary> - A, the registry refusal never fires (`served.length >= 2` to `>= 99`): 7 failed, 5 passed. Red: both FROM pins in both orders, the disabled-holder CONTROL (it asserts the refusal on re-enable) and the store-only-row pin. - B, the protocol never asks the judge (`request.type === 'doc'` to `'docABLATED'` in `readMetaItem`; `metadata-protocol` rebuilt, `ablation-dist-preflight.mjs` found the marker in `dist/`): 5 failed, 7 passed, each `the read refuses: expected undefined to be an instance of PackageScopedNameRefusedError`. Restored, rebuilt, preflight `--absent` passes on all 24 built files and the tree. - C, a disabled package counts as a holder (`includeDisabledPackages: true`): 2 failed (the disabled-holder CONTROL, both orders). - D, the environment's own item no longer answers first: 2 failed (the environment CONTROL, both orders). </details> ## Acceptance notes - Reading of the ruling's "the environment's own saved row still answers first": the row answers first where the registry holds it (the package-less bare slot that hydration and the save write). A row only the store holds is not served by the read's layers for a `doc` (step 1 does not adopt it, measured on the composed server and on the harness), so it is not an exemption: exempting it measured `200` with the holder registered last. Named in the report. - Out of this PR, measured on origin/main on the composed server and unchanged here: `GET /meta/doc/NAME?package=com.qa.alpha` answers the OTHER package's doc (the one the metadata service kept); and with one holder disabled and registered last, the bare read, `/layers` and `/published` answer `404` although an enabled package holds the name. Both are in the report for the seat. - Owed elsewhere, per the ruling: the ADR-0048 status-line edit (a `domain:skills` card) and the Console `/docs/NAME` display of the candidates on a 409 (a UI-lane follow-up). ## Verification All readings at head `e4b68eb2b` (this branch with `origin/main` merged at `db1dde9f`), objectstack-ai/objectstack. <details><summary>Composed server: the mechanism, measured before and after</summary> A throwaway rig (not committed) booted the way a compiled artifact composes: `MetadataPlugin` artifact door plus `AppPlugin` over one artifact whose two package bodies (`com.qa.alpha`, `com.qa.beta`) each ship doc `shared_doc`; both transports (`HttpDispatcher.dispatch` and `RestServer`'s registered handler), both registration orders. - origin/main `1e65a389`: the metadata service holds the doc registered LAST; the registry's `getItem` answers the one registered first. The bare read, `/layers` and `/published` all answered `200` with the LAST registered holder's doc, in both orders. So the PM hypothesis H1 (the REST read ends at the registry's first composite) is refuted for this door, and H2 (one judge at the registry covers both doors) holds only because the protocol now asks that judge before any layer. - this head: the bare read, `/layers` and `/published` answer `409 RESOURCE_CONFLICT` on both transports, in both orders. One holder disabled: identical to main on every door (`404` when the disabled one registered last, the enabled one's doc otherwise). A package-less `sys_metadata` row only the store holds: `409` (with an exemption it answered `200` with the last registered holder's doc, because the read's layers do not serve such a row for a doc). </details> <details><summary>Suites, typecheck, gates, dogfood</summary> - `pnpm --filter @objectstack/objectql test`: 596 files, 13165 tests passed. `typecheck`: exit 0. - `pnpm --filter @objectstack/metadata-protocol test`: 341 files passed, 9 skipped; 22894 tests passed. `typecheck`: exit 0. - `pnpm --filter @objectstack/runtime test`: 605 files, 10958 tests passed (19 skipped). - `pnpm --filter @objectstack/rest test`: 412 files, 8442 tests passed (332 skipped). - `pnpm check:type-check-debt`: exit 0. `pnpm lint`: exit 0. - `dispatch-gates.mjs --commands`: 72 derived; 70 run, each exit 0; `check:type-check-debt` run under the lock (exit 0); `check:dual-build-cjs-loads` left to CI. - Changeset and body gates: `check-adr-0087-registration` (1 declared-breaking changeset, disposition present), `check-changeset-no-major` (reads `no (narrowing)` / `none` at `patch`), `check-empty-changeset`, `check-closing-keyword-parity`, `check-partof-closing-keyword`: each exit 0. - Dogfood battery (narrowing arm), `pnpm --filter @objectstack/dogfood test` under the verify lock after the closure build: Test Files 467 passed, 3 skipped (470); Tests 3959 passed, 42 skipped. VERDICT command-exit 0. </details> 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01QsR2jUcj2x2Wr4UErwBi12 <!-- signed: domain:server#5 · zhuangjianguo · session_01QsR2jUcj2x2Wr4UErwBi12 --> --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent 6844e6b commit 5af956f

4 files changed

Lines changed: 169 additions & 1 deletion

File tree

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
---
2+
'@objectstack/objectql': patch
3+
'@objectstack/metadata-protocol': patch
4+
---
5+
6+
fix(objectql)!: a by-name read of a doc that names no package refuses a name two enabled packages hold, naming both
7+
8+
Clause-②: no (narrowing) — narrowed: a by-name read of a doc that names no package (`GET /meta/doc/NAME` and the doors that read through it, `MetadataFacade.get`/`getEntry`), of a name two or more enabled packages hold, moves from one holder's body, picked by registration order, to `409 RESOURCE_CONFLICT` naming every holder. Unchanged: one holder, a read that names the package, the environment's own item.
9+
Metadata-protocol: none
10+
11+
<!-- adr-0087: not-required (no-migration-prescription) no key of any schema is added, removed, renamed or re-shaped and no stored row changes shape: what moves is the answer a by-name doc read gives when two packages ship the name, so there is nothing for a migration to rewrite and no tombstone -->
12+
13+
**BREAKING** for a caller that reads a doc by its name alone while two enabled packages ship that name: it now gets `409 RESOURCE_CONFLICT` naming the packages, where it got one of them. The fix: name the package (`?package=PACKAGE_ID` on the REST door, the package id in process). A doc name one package ships reads as before.
14+
15+
A read of a `doc` by its name alone (`GET /api/v1/meta/doc/NAME`, the doors that read through it, and `MetadataFacade.get('doc', name)` / `getEntry`) answered one holder's doc when two packages ship the same name: the registry's first-registered copy, or on a composed server the metadata service's copy, which is the package registered last. It now answers `409 RESOURCE_CONFLICT` (`ambiguous-in-environment`), naming every enabled package that holds the name, in either registration order. `MetadataFacade.exists` answers `true` for such a name.
16+
17+
Unchanged: a doc name one package holds reads as before; a read that names the package (`?package=` on the REST door, a package caller in process) is not changed; the environment's own doc of the name, as the server holds it, still answers first. A disabled package holds no name: beside one enabled holder the read is not refused, and the facade serves the enabled holder's doc. `doc` keeps its global literal name and its addressing (ADR-0150 D1 bucket 1).
18+
19+
What moves, for a doc name two enabled packages ship: the answer was `200` with one holder's doc, chosen by registration order; it is `409 RESOURCE_CONFLICT` naming each holder. No metadata, no stored row and no export changes, so there is nothing to rewrite: a caller that wants one of the docs names its package.

‎packages/metadata-protocol/src/protocol-meta-item-reads.ts‎

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,30 @@ export async function judgeBareActionRead(
313313
return undefined;
314314
}
315315

316+
/**
317+
* [ADR-0150 D1 bucket 1, ruling 6893582352 option A] The bare by-name read of
318+
* a `doc` (`GET /meta/doc/NAME`, both faces, and the doors that read through
319+
* it), judged before any layer is read by the registry's own read of it
320+
* (`resolveItem` naming no package, which `MetadataFacade.get` asks too): a
321+
* name two or more enabled packages hold is refused naming every holder
322+
* (`409 RESOURCE_CONFLICT`). It served one holder by registration order: the
323+
* MetadataService's copy (kept by name alone, the holder registered last) or
324+
* the registry's first composite.
325+
*
326+
* Judge only: any answer the registry gives leaves the read to its layers,
327+
* exactly as before. The environment's own item answers first where the
328+
* registry holds it (its package-less bare slot: a hydrated or saved row);
329+
* a package-less row only the store holds is no exemption, because the
330+
* layers below do not serve it for a `doc` and would answer a holder by
331+
* registration order again.
332+
*
333+
* @throws {PackageScopedNameRefusedError} two or more enabled package holders.
334+
*/
335+
export function refuseAmbiguousBareDocRead(host: Pick<ProtocolHost, 'engine'>, name: string, member: string | undefined): void {
336+
const registry = host.engine?.registry as { resolveItem?(type: string, name: string, caller: null, member?: string): unknown } | undefined;
337+
if (typeof registry?.resolveItem === 'function') registry.resolveItem('doc', name, null, member);
338+
}
339+
316340
/**
317341
* [ADR-0150 D3, #32365] Does the MetadataService's answer to a bare action
318342
* read agree with the judged answer ({@link judgeBareActionRead})? The
@@ -601,6 +625,11 @@ export async function readMetaItem(host: Pick<ProtocolHost, 'artifactLockLayerAt
601625
}
602626
bareActionAnswer = await judgeBareActionRead(host, request.name, objectLessRefused, opts.face);
603627
}
628+
// [ADR-0150 D1 bucket 1, ruling 6893582352 option A] A `doc` name two or
629+
// more enabled packages hold is refused here when the read names no
630+
// package, naming each, before any layer is read; the environment's own
631+
// item still answers first ({@link refuseAmbiguousBareDocRead}).
632+
if (!request.packageId && request.type === 'doc') refuseAmbiguousBareDocRead(host, request.name, member);
604633
const packagelessScopedRead: { item: unknown } | undefined =
605634
!request.packageId && typeof registry?.readsByPackage === 'function' && registry.readsByPackage(request.type)
606635
? { item: registry.resolveItem(request.type, request.name, null, member) }

‎packages/objectql/src/package-scoped-e8-readers.test.ts‎

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -639,3 +639,79 @@ describe('#32183 — a disabled package holds no name at the library readers', (
639639
expect((thrown as Error).message).not.toContain(B);
640640
});
641641
});
642+
643+
describe('[ruling 6893582352] doc (ADR-0150 D1 bucket 1): a bare read of a name two enabled packages hold is refused', () => {
644+
// Both registration orders of every two-holder pin: the answer it replaced
645+
// was a registration-order pick (the registry's first composite here; the
646+
// MetadataService's copy, the holder registered last, on a composed door).
647+
const ORDERS = [['alpha first', [A, B]], ['beta first', [B, A]]] as const;
648+
const shipDoc = (name: string, packageId: string) => registry.registerItem(
649+
'doc', { name, label: `${packageId.split('.').pop()} doc`, content: `# ${packageId}` }, 'name' as never, packageId);
650+
/** A MetadataService that keeps a doc by name alone: the holder registered last. */
651+
const serviceKeepingLast = (order: readonly string[], name: string) => {
652+
const last = order[order.length - 1]!;
653+
const copy = { name, label: `${last.split('.').pop()} doc`, content: `# ${last}`, _packageId: last };
654+
return new Map<string, any>([['metadata', { get: async (type: string, n: string) => (type === 'doc' && n === name ? copy : undefined) }]]);
655+
};
656+
657+
it.each(ORDERS)('[FROM one holder\'s body TO 409] the protocol read (both faces), the facade and the registry refuse naming both (%s)', async (_order, order) => {
658+
for (const id of order) shipDoc('shared_doc', id);
659+
await expectRefusal(() => protocol.getMetaItem({ type: 'doc', name: 'shared_doc' }), 'ambiguous-in-environment', [A, B]);
660+
await expectRefusal(() => protocol.getMetaItemForExecution({ type: 'doc', name: 'shared_doc' }), 'ambiguous-in-environment', [A, B]);
661+
await expectRefusal(() => facade.get('doc', 'shared_doc'), 'ambiguous-in-environment', [A, B]);
662+
await expectRefusal(() => facade.getEntry('doc', 'shared_doc'), 'ambiguous-in-environment', [A, B]);
663+
await expectRefusal(() => registry.resolveItem('doc', 'shared_doc'), 'ambiguous-in-environment', [A, B]);
664+
expect(await facade.exists('doc', 'shared_doc')).toBe(true);
665+
});
666+
667+
it.each(ORDERS)('[FROM the service\'s copy TO 409] refused before the MetadataService layer is read (%s)', async (_order, order) => {
668+
for (const id of order) shipDoc('shared_doc', id);
669+
const composed = new ObjectStackProtocolImplementation((protocol as unknown as { engine: never }).engine, () => serviceKeepingLast(order, 'shared_doc'));
670+
await expectRefusal(() => composed.getMetaItem({ type: 'doc', name: 'shared_doc' }), 'ambiguous-in-environment', [A, B]);
671+
});
672+
673+
it('CONTROL — one holder is served exactly as before, at every reader', async () => {
674+
shipDoc('solo_doc', A);
675+
expect(labelOf((await protocol.getMetaItem({ type: 'doc', name: 'solo_doc' }))?.item)).toBe('alpha doc');
676+
expect(labelOf((await protocol.getMetaItemForExecution({ type: 'doc', name: 'solo_doc' }))?.item)).toBe('alpha doc');
677+
expect(labelOf(await facade.get('doc', 'solo_doc'))).toBe('alpha doc');
678+
expect(labelOf(registry.resolveItem('doc', 'solo_doc'))).toBe('alpha doc');
679+
});
680+
681+
it.each(ORDERS)('CONTROL — the exact address and a package caller read their own holder\'s doc (%s)', async (_order, order) => {
682+
for (const id of order) shipDoc('shared_doc', id);
683+
for (const id of [A, B]) {
684+
const tagOf = `${id.split('.').pop()} doc`;
685+
expect(labelOf((await protocol.getMetaItem({ type: 'doc', name: 'shared_doc', packageId: id }))?.item)).toBe(tagOf);
686+
expect(labelOf(await facade.get('doc', 'shared_doc', id))).toBe(tagOf);
687+
expect(labelOf(registry.resolveItem('doc', 'shared_doc', id))).toBe(tagOf);
688+
}
689+
});
690+
691+
it.each(ORDERS)('CONTROL — a disabled package holds no name: the enabled holder is not refused, and the facade serves it (%s)', async (_order, order) => {
692+
for (const id of order) shipDoc('shared_doc', id);
693+
registry.disablePackage(B);
694+
expect(labelOf(await facade.get('doc', 'shared_doc'))).toBe('alpha doc');
695+
expect(labelOf(registry.resolveItem('doc', 'shared_doc'))).toBe('alpha doc');
696+
const read = await protocol.getMetaItem({ type: 'doc', name: 'shared_doc' });
697+
expect(JSON.stringify(read?.item ?? null)).not.toContain('beta doc');
698+
registry.enablePackage(B);
699+
await expectRefusal(() => facade.get('doc', 'shared_doc'), 'ambiguous-in-environment', [A, B]);
700+
});
701+
702+
it.each(ORDERS)('CONTROL — the environment\'s own item answers first beside two holders (%s)', async (_order, order) => {
703+
for (const id of order) shipDoc('shared_doc', id);
704+
registry.registerItem('doc', { name: 'shared_doc', label: 'env doc', content: '# env', _provenance: 'org' }, 'name' as never);
705+
expect(labelOf(await facade.get('doc', 'shared_doc'))).toBe('env doc');
706+
expect(labelOf((await protocol.getMetaItem({ type: 'doc', name: 'shared_doc' }))?.item)).toBe('env doc');
707+
});
708+
709+
it('a package-less row only the store holds is no exemption: its layers would not serve it, so the read is still refused', async () => {
710+
for (const id of [A, B]) shipDoc('shared_doc', id);
711+
const row = { type: 'doc', name: 'shared_doc', state: 'active', package_id: null, metadata: JSON.stringify({ name: 'shared_doc', label: 'saved doc', content: '# saved' }) };
712+
const engine = (protocol as unknown as { engine: { find: ReturnType<typeof vi.fn> } }).engine;
713+
engine.find.mockImplementation(async (object: string, query: { where?: Record<string, unknown> }) =>
714+
(object === 'sys_metadata' && query?.where?.name === 'shared_doc' ? [row] : []));
715+
await expectRefusal(() => protocol.getMetaItem({ type: 'doc', name: 'shared_doc' }), 'ambiguous-in-environment', [A, B]);
716+
});
717+
});

‎packages/objectql/src/registry.ts‎

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ import { applyProtection } from '@objectstack/spec/shared';
7272
// (`id || name`). The install gate's co-ownership set must name packages by the
7373
// same string the artifact loader ordered them by, or a co-owner would be
7474
// admitted — or refused — under a key nothing else in the path uses.
75-
import { artifactPackageId, declaredDependencyIds, PackageScopedNameRefusedError, permissionSetHoldersMeet, resolvePackageScopedHolders, type SecurityCatalogType } from '@objectstack/core';
75+
import { artifactPackageId, declaredDependencyIds, PackageScopedNameRefusedError, packageScopedRefusalMessage, permissionSetHoldersMeet, resolvePackageScopedHolders, type PackageScopedResolvableType, type SecurityCatalogType } from '@objectstack/core';
7676
// One name, one holder for positions, permission sets and capabilities — the
7777
// rule, the holders and the one place a declaration is read from (module doc).
7878
import {
@@ -10096,10 +10096,54 @@ export class SchemaRegistry {
1009610096
* caller may not reach.
1009710097
*/
1009810098
resolveItem<T>(type: string, name: string, callerPackageId?: string | null, member?: string): T | undefined {
10099+
if (type === 'doc' && !callerPackageId) return this.readBareDoc<T>(name, member);
1009910100
if (!isPackageScopedReadType(type)) return this.getItem<T>(type, name, callerPackageId ?? undefined, member);
1010010101
return readPackageScopedItem<T>(this, { type, name, callerPackageId, member });
1010110102
}
1010210103

10104+
/**
10105+
* [ADR-0150 D1 bucket 1, ruling 6893582352 option A] The by-name read of a
10106+
* `doc` that names no package. `doc` keeps its literal global name and its
10107+
* addressing (bucket 1); what changes is the context-free read's answer
10108+
* when two or more ENABLED packages hold the name: a `409
10109+
* RESOURCE_CONFLICT` naming every holder (`ambiguous-in-environment`), in
10110+
* place of {@link getItem}'s first composite, which is a registration-order
10111+
* pick (ADR-0146 D8; the bare save, delete, publish and layered read refuse
10112+
* the same address already).
10113+
*
10114+
* Unchanged: one holder; a package-less bare-slot entry (the environment's
10115+
* own item) answers first, as {@link getItem} serves it; a disabled package
10116+
* holds no name ({@link packageScopedHoldersOf}), so beside one enabled
10117+
* holder the read serves that holder's item, never the disabled one's.
10118+
* `MetadataFacade.get` serves this answer; the protocol's by-name read asks
10119+
* it before any layer for its refusal only (`protocol-meta-item-reads.ts`).
10120+
*
10121+
* @throws {PackageScopedNameRefusedError} two or more enabled holders.
10122+
*/
10123+
private readBareDoc<T>(name: string, member?: string): T | undefined {
10124+
const bare = this.metadata.get('doc')?.get(name) as { _packageId?: unknown } | undefined;
10125+
const stamp = bare?._packageId;
10126+
if (bare !== undefined && (typeof stamp !== 'string' || stamp === '' || stamp === 'sys_metadata')) {
10127+
return this.getItem<T>('doc', name, undefined, member);
10128+
}
10129+
const served = this.packageScopedHoldersOf('doc', name);
10130+
if (served.length >= 2) {
10131+
const base: Omit<PackageScopedRefusal, 'message'> = {
10132+
status: 'refused',
10133+
reason: 'ambiguous-in-environment',
10134+
type: 'doc' as PackageScopedResolvableType,
10135+
name,
10136+
callerPackageId: null,
10137+
candidates: served.map((packageId) => ({ kind: 'package' as const, packageId })),
10138+
};
10139+
throw new PackageScopedNameRefusedError({ ...base, message: packageScopedRefusalMessage(base) });
10140+
}
10141+
if (served.length === 1 && this.packageScopedHoldersOf('doc', name, null, { includeDisabledPackages: true }).length > 1) {
10142+
return this.getPackageScopedItem<T>('doc', name, served[0], member);
10143+
}
10144+
return this.getItem<T>('doc', name, undefined, member);
10145+
}
10146+
1010310147
/**
1010410148
* [ADR-0150 D5, #31697] The by-name read of an action that names no package
1010510149
* and no object (`GET /meta/action/NAME`): when the object-less holders of

0 commit comments

Comments
 (0)