@@ -471,7 +471,7 @@ import { refuseUnmintableMetaType } from './protocol-unmintable-meta-type.js';
471471// [#25467 cut 33] The deployment's SDUI component manifest, and the load-time page `requires` report against it.
472472import { reportPageRequiresAbsentAtLoad, resolveSduiManifest } from './protocol-sdui-manifest.js';
473473// [#25467 cut 35] The environment's own `sys_metadata` rows: the family read, the one-row read, the served row and the package-less address.
474- import { findEnvironmentRow, findEnvironmentRows, findServedOverlayRow, packagelessAddress, packagelessContentPackage, soleShippingPackage } from './protocol-environment-rows.js';
474+ import { baseAddressServesMember, findEnvironmentRow, findEnvironmentRows, findServedOverlayRow, packagelessAddress, packagelessContentPackage, shippingPackageIds , soleShippingPackage } from './protocol-environment-rows.js';
475475// [#25467 cut 35] The stored rows of a collection, folded over the registered ones.
476476import { foldStoredCollection } from './protocol-stored-collection-fold.js';
477477// [#25467 cut 35] The environment-wide package uninstall verb.
@@ -10492,6 +10492,24 @@ export class ObjectStackProtocolImplementation implements
1049210492 // MetadataService not available or doesn't support this type
1049310493 }
1049410494
10495+ // [#28802, #28390 ruling A] …except, for a bundle the package ships
10496+ // (`ITEM_KEY_DISCRIMINATORS`), its pair's row at a member the package
10497+ // does not ship: the pair's own added member, which the package's
10498+ // address serves beside the package's members
10499+ // ({@link baseServesBundleMember}), as the env-wide list below does.
10500+ if (unseated && servedOverride && packageId && ITEM_KEY_DISCRIMINATORS[request.type] !== undefined) {
10501+ const pairOfList = customizationPackageId(packageId);
10502+ const typeShipping = this.shippingPackagesOf(request.type);
10503+ for (const it of items as any[]) {
10504+ if (!(it && typeof it === 'object' && unseated.has(it))) continue;
10505+ if (!pairOfList.ok || boundPackageOf(it._packageId) !== pairOfList.value || typeof it.name !== 'string') continue;
10506+ if (this.shipsBundleName(request.type, it.name, packageId, typeShipping)
10507+ && this.baseServesBundleMember(request.type, it.name, packageId, it, typeShipping)) {
10508+ unseated.delete(it);
10509+ }
10510+ }
10511+ }
10512+
1049510513 // [#21817] A stand-in no layer seated is a package-less row of an item
1049610514 // the package does not ship: it is not in the package's list.
1049710515 if (unseated) {
@@ -10524,8 +10542,16 @@ export class ObjectStackProtocolImplementation implements
1052410542 // every item of a name no package or several packages ship (ADR-0048
1052510543 // §3.3). The `package` type is never narrowed: its items are the
1052610544 // packages themselves.
10545+ //
10546+ // [#28802, #28390 ruling A] A bundle's name (`ITEM_KEY_DISCRIMINATORS`)
10547+ // is narrowed at MEMBER grain: the sole shipper's list also keeps its
10548+ // pair's own added members, a member the base does not ship
10549+ // ({@link baseServesBundleMember}), so a locale the customer adds in
10550+ // `.custom` is listed and executed (the email loader reads this list).
10551+ // A dependent's member under the name is still dropped here.
1052710552 if (servedOverride && !packageId && request.type !== 'package') {
1052810553 const typeShipping = this.shippingPackagesOf(request.type);
10554+ const isBundle = ITEM_KEY_DISCRIMINATORS[request.type] !== undefined;
1052910555 const soleShipperOf = new Map<string, string | undefined>();
1053010556 items = (items as any[]).filter((it) => {
1053110557 const itemName = it?.name;
@@ -10535,7 +10561,8 @@ export class ObjectStackProtocolImplementation implements
1053510561 soleShipperOf.set(itemName, soleShippingPackage(this.shippedArtifactsOf(request.type, itemName, typeShipping)));
1053610562 }
1053710563 const soleShipper = soleShipperOf.get(itemName);
10538- return soleShipper === undefined || soleShipper === bound;
10564+ if (soleShipper === undefined || soleShipper === bound) return true;
10565+ return isBundle && this.baseServesBundleMember(request.type, itemName, soleShipper, it, typeShipping);
1053910566 });
1054010567 }
1054110568
@@ -11486,6 +11513,18 @@ export class ObjectStackProtocolImplementation implements
1148611513 ...(readState === 'active' ? { servedOverride: true } : {}),
1148711514 }, activeRows);
1148811515 let record = served?.row;
11516+ // [#28802, #28390 ruling A] A member of a bundle the address's
11517+ // package ships and does not ship at that member: the pair's own
11518+ // added member is the address's, served from the pair's row under
11519+ // the pair's binding (a dependent's member never is).
11520+ if (!record && readState === 'active' && wantedMember !== undefined && typeof contentPackageId === 'string') {
11521+ const pairOfAddition = this.pairOfAddedMember(request.type, request.name, contentPackageId, wantedMember);
11522+ if (pairOfAddition !== undefined) {
11523+ record = (await this.findServedOverlayRow({
11524+ type: request.type, name: request.name, state: readState, packageId: pairOfAddition, ...memberOption(member),
11525+ }, activeRows))?.row;
11526+ }
11527+ }
1148911528 // [#23715] Two or more packages and no package-unbound draft: the
1149011529 // best-effort first match ADR-0048 §3.3 states, as before, served
1149111530 // with `version: null` (no row at the address the save naming none
@@ -11711,6 +11750,15 @@ export class ObjectStackProtocolImplementation implements
1171111750 if (this.isStoredFlowEntryOfShippedName(request.type, item)) {
1171211751 item = this.lookupArtifactItem(request.type, request.name, request.packageId);
1171311752 }
11753+ // [#28802, #28390 ruling A] A bundle member on a base's address
11754+ // (the package named, else the one whose content a read naming
11755+ // none serves) is one that address serves: the registry's last
11756+ // tier, the first composite match across packages (ADR-0048 §3.3),
11757+ // no longer answers a dependent's member under the base's name.
11758+ const memberAddress = request.packageId || (typeof contentPackageId === 'string' ? contentPackageId : undefined);
11759+ if (item !== undefined && wantedMember !== undefined && memberAddress !== undefined) {
11760+ item = this.registryMemberServedAt(request.type, request.name, memberAddress, item, member);
11761+ }
1171411762 }
1171511763
1171611764 // [#5840] The MetadataService half of the #5532 rule, and the last
@@ -17325,6 +17373,59 @@ export class ObjectStackProtocolImplementation implements
1732517373 return shippedArtifactsOf.call(host, type, name, shipping, member);
1732617374 }
1732717375
17376+ /** [#28802] Whether `base` is a code package that ships the bundle's name `name`, any member. */
17377+ private shipsBundleName(type: string, name: string, base: string, shipping: ShippingPackages): boolean {
17378+ return shippingPackageIds(this.shippedArtifactsOf(type, name, shipping)).has(base);
17379+ }
17380+
17381+ /**
17382+ * [#28802, ADR-0146 D2, #28390 ruling A] Whether the address of `base`, a
17383+ * code package that ships the bundle's name `name` (a type in
17384+ * `ITEM_KEY_DISCRIMINATORS`), serves `item`, a member of that name: by
17385+ * {@link baseAddressServesMember}, given whether `base` ships the member
17386+ * `item` is. The one member-grain answer the env-wide list, the list
17387+ * scoped to `base` and the by-name reads give.
17388+ */
17389+ private baseServesBundleMember(type: string, name: string, base: string, item: unknown, shipping: ShippingPackages): boolean {
17390+ const member = itemDiscriminator(canonicalMetaType(type), item);
17391+ const baseShipsMember = shippingPackageIds(this.shippedArtifactsOf(type, name, shipping, member)).has(base);
17392+ return baseAddressServesMember(base, boundPackageOf((item as { _packageId?: unknown } | null | undefined)?._packageId), baseShipsMember);
17393+ }
17394+
17395+ /**
17396+ * [#28802, #28390 ruling A] The pair of `base` when the bundle member
17397+ * `member` (its discriminator value) of the name `name` is one only the
17398+ * pair can add on `base`'s address: `base` ships the name and not that
17399+ * member. Else `undefined`, and the by-name read serves as before.
17400+ */
17401+ private pairOfAddedMember(type: string, name: string, base: string, member: string): string | undefined {
17402+ const shipping = this.shippingPackagesOf(type);
17403+ if (!this.shipsBundleName(type, name, base, shipping)) return undefined;
17404+ if (shippingPackageIds(this.shippedArtifactsOf(type, name, shipping, member)).has(base)) return undefined;
17405+ const pair = customizationPackageId(base);
17406+ return pair.ok ? pair.value : undefined;
17407+ }
17408+
17409+ /**
17410+ * [#28802] The registry's answer `item` for a bundle member read on the
17411+ * address of `base`, when that address serves it
17412+ * ({@link baseServesBundleMember}); else, for a read that named no
17413+ * member, the base's own member its artifact answers canonical-first,
17414+ * and otherwise nothing. An address that ships no member of the name is
17415+ * no base of it: `item` as before.
17416+ */
17417+ private registryMemberServedAt(type: string, name: string, base: string, item: unknown, member: string | undefined): unknown {
17418+ const shipping = this.shippingPackagesOf(type);
17419+ if (!this.shipsBundleName(type, name, base, shipping)) return item;
17420+ if (this.baseServesBundleMember(type, name, base, item, shipping)) return item;
17421+ if (member !== undefined) return undefined;
17422+ const own = this.shippedArtifactsOf(type, name, shipping)
17423+ .find((artifact) => (artifact as { _packageId?: unknown } | null)?._packageId === base);
17424+ if (own === undefined) return undefined;
17425+ const candidate = this.engine.registry.getItem(type, name, base, itemDiscriminator(canonicalMetaType(type), own));
17426+ return candidate !== undefined && this.baseServesBundleMember(type, name, base, candidate, shipping) ? candidate : undefined;
17427+ }
17428+
1732817429 /**
1732917430 * [#21803] The packages that can ship an item of `type`, read off the
1733017431 * registry's own listings:
0 commit comments