Skip to content

Commit c53513b

Browse files
committed
fix(metadata-protocol): the layered read on a base's address answers an email template locale its .custom pair adds with the pair's layer
`GET /meta/email_template/<name>/layers` naming the base or no package answered 404 for a locale the base does not ship and its `.custom` pair adds, while the by-name read, the base's lists and `sendTemplate` serve it since #28802. The layered read now takes the pair's row as its overlay through `findPairAddedMemberRow`, the one read the by-name read shares (PR #28828's `pairOfAddedMember` predicate). A dependent's added locale stays 404 there; non-bundle types are unchanged. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01FEkQ5m2Ryfx2Wubuz716mw
1 parent 1920e48 commit c53513b

4 files changed

Lines changed: 140 additions & 8 deletions

File tree

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
'@objectstack/metadata-protocol': patch
3+
---
4+
5+
fix(metadata-protocol): the layered read on a base's address answers an email template locale added in the base's `.custom` pair with the pair's layer (#28830)
6+
7+
Clause-②: yes (widening)
8+
Metadata-protocol: none
9+
10+
`GET /meta/email_template/<name>/layers?package=<base>&member=<locale>` (and the same read naming no package) answered `404` for a locale the base does not ship and its `.custom` pair adds, while the by-name read, the base's lists and `sendTemplate` serve that locale since #28802. It now answers the pair's row as the `overlay` and `effective` layers (`code: null`, the base ships no such locale), from the one read the by-name read uses. Another package's added locale stays `404` there and answers under the read naming that package; the base's own locales, the pair's declared overrides and every type whose identity is its name alone are unchanged.

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

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11518,12 +11518,7 @@ export class ObjectStackProtocolImplementation implements
1151811518
// added member is the address's, served from the pair's row under
1151911519
// the pair's binding (a dependent's member never is).
1152011520
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-
}
11521+
record = await this.findPairAddedMemberRow(request.type, request.name, contentPackageId, member, wantedMember, activeRows);
1152711522
}
1152811523
// [#23715] Two or more packages and no package-unbound draft: the
1152911524
// best-effort first match ADR-0048 §3.3 states, as before, served
@@ -12223,14 +12218,21 @@ export class ObjectStackProtocolImplementation implements
1222312218
// then the `.custom` item, `code` the base's document and
1222412219
// `effective` the override (the base's document stays reachable
1222512220
// here, ADR-0146 "Decided here" item 5).
12226-
const served = await this.findServedOverlayRow({
12221+
let served: { row: any; overrideOf?: string } | undefined = await this.findServedOverlayRow({
1222712222
type: request.type,
1222812223
name: request.name,
1222912224
state: 'active',
1223012225
...(contentPackageId !== undefined ? { packageId: contentPackageId } : {}),
1223112226
...memberOption(member),
1223212227
servedOverride: true,
1223312228
});
12229+
// [#28830, #28390 ruling A] The pair's own added member is the
12230+
// overlay on the base's address, as the by-name read serves it
12231+
// ({@link findPairAddedMemberRow}); another package's never is.
12232+
if (!served && wantedMember !== undefined && typeof contentPackageId === 'string') {
12233+
const row = await this.findPairAddedMemberRow(request.type, request.name, contentPackageId, member, wantedMember);
12234+
if (row) served = { row };
12235+
}
1223412236
overlayLockLayer = await this.overlayLockLayerAt({
1223512237
type: request.type,
1223612238
name: request.name,
@@ -17406,6 +17408,24 @@ export class ObjectStackProtocolImplementation implements
1740617408
return pair.ok ? pair.value : undefined;
1740717409
}
1740817410

17411+
/**
17412+
* [#28802, #28830] The pair's own stored row at the bundle member `member`
17413+
* (`wantedMember` its discriminator value) of the name `name`, when only
17414+
* the pair can add that member on `base`'s address
17415+
* ({@link pairOfAddedMember}); else `undefined`. The one read of it the
17416+
* by-name read and the layered read share.
17417+
*/
17418+
private async findPairAddedMemberRow(
17419+
type: string, name: string, base: string, member: string | undefined, wantedMember: string,
17420+
activeRows?: readonly StoredOverlayRow[],
17421+
): Promise<any> {
17422+
const pairOfAddition = this.pairOfAddedMember(type, name, base, wantedMember);
17423+
if (pairOfAddition === undefined) return undefined;
17424+
return (await this.findServedOverlayRow({
17425+
type, name, state: 'active', packageId: pairOfAddition, ...memberOption(member),
17426+
}, activeRows))?.row;
17427+
}
17428+
1740917429
/**
1741017430
* [#28802] The registry's answer `item` for a bundle member read on the
1741117431
* address of `base`, when that address serves it

‎packages/objectql/src/protocol-bundle-member-base-address.test.ts‎

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,3 +345,72 @@ describe('[#28802] a bundle member on the base\'s address, at member grain', ()
345345
expect(await executing(protocol, NAME)).toEqual([['en-US', BASE, 'Override EN'], PAIR_FR]);
346346
});
347347
});
348+
349+
/** The layered read: `{ code, overlay, effective }` subjects (or view columns), or `404` when no layer answers. */
350+
const layersOf = async (protocol: ObjectStackProtocolImplementation, type: string, name: string, member?: string, packageId?: string) => {
351+
try {
352+
const res: any = await (protocol as any).getMetaItemLayered({
353+
type, name, ...(member ? { member } : {}), ...(packageId ? { packageId } : {}),
354+
});
355+
const pick = (item: any) => (item === null || item === undefined
356+
? null
357+
: type === 'view'
358+
? (item?.config?.columns ?? item?.columns ?? []).map((c: any) => c?.field ?? c)
359+
: [item.subject, item.locale]);
360+
// The protocol answers no layer at all as three nulls; the `/layers` door turns that into 404.
361+
if (res.code == null && res.overlay == null && res.effective == null) return 404;
362+
return { code: pick(res.code), overlay: pick(res.overlay), effective: pick(res.effective) };
363+
} catch (error: any) {
364+
if (error?.status === 404) return 404;
365+
throw error;
366+
}
367+
};
368+
369+
describe('[#28830] the layered read on the base\'s address, at member grain', () => {
370+
it('the pair\'s own added member answers with the pair\'s layer, naming the base and naming no package', async () => {
371+
const { protocol } = await boot();
372+
await install(protocol, PAIR);
373+
await publishInto(protocol, PAIR, NAME, 'fr-FR', 'Pair FR');
374+
375+
const PAIR_LAYERS = { code: null, overlay: ['Pair FR', 'fr-FR'], effective: ['Pair FR', 'fr-FR'] };
376+
expect(await layersOf(protocol, TYPE, NAME, 'fr-FR', BASE)).toEqual(PAIR_LAYERS);
377+
expect(await layersOf(protocol, TYPE, NAME, 'fr-FR')).toEqual(PAIR_LAYERS);
378+
// Unchanged: the pair's own address, and the base's member.
379+
expect(await layersOf(protocol, TYPE, NAME, 'fr-FR', PAIR)).toEqual(PAIR_LAYERS);
380+
expect(await layersOf(protocol, TYPE, NAME, 'en-US', BASE))
381+
.toEqual({ code: ['Base EN', 'en-US'], overlay: null, effective: ['Base EN', 'en-US'] });
382+
});
383+
384+
it('a dependent\'s added member stays 404 on the base\'s layered read and answers under the dependent', async () => {
385+
const { protocol } = await boot();
386+
await install(protocol, DEPENDENT);
387+
await publishInto(protocol, DEPENDENT, NAME, 'fr-FR', 'Dependent FR');
388+
389+
expect(await layersOf(protocol, TYPE, NAME, 'fr-FR', BASE)).toBe(404);
390+
expect(await layersOf(protocol, TYPE, NAME, 'fr-FR')).toBe(404);
391+
expect(await layersOf(protocol, TYPE, NAME, 'fr-FR', DEPENDENT))
392+
.toEqual({ code: null, overlay: ['Dependent FR', 'fr-FR'], effective: ['Dependent FR', 'fr-FR'] });
393+
});
394+
395+
it('with a dependent\'s member at the same locale, the base\'s layered read answers the pair\'s', async () => {
396+
const { protocol } = await boot();
397+
await install(protocol, PAIR);
398+
await install(protocol, DEPENDENT);
399+
await publishInto(protocol, PAIR, NAME, 'fr-FR', 'Pair FR');
400+
await publishInto(protocol, DEPENDENT, NAME, 'fr-FR', 'Dependent FR');
401+
402+
expect(await layersOf(protocol, TYPE, NAME, 'fr-FR', BASE))
403+
.toEqual({ code: null, overlay: ['Pair FR', 'fr-FR'], effective: ['Pair FR', 'fr-FR'] });
404+
});
405+
406+
it('control: a declared override of the base\'s member, and a non-bundle type, answer as before', async () => {
407+
const { protocol } = await boot();
408+
await install(protocol, PAIR);
409+
await publishInto(protocol, PAIR, NAME, 'en-US', 'Override EN', { overrides: { package: BASE, basedOn: '1.0.0' } });
410+
411+
expect(await layersOf(protocol, TYPE, NAME, 'en-US', BASE))
412+
.toEqual({ code: ['Base EN', 'en-US'], overlay: ['Override EN', 'en-US'], effective: ['Override EN', 'en-US'] });
413+
expect(await layersOf(protocol, 'view', VIEW, undefined, BASE))
414+
.toEqual({ code: BASE_COLUMNS, overlay: null, effective: BASE_COLUMNS });
415+
});
416+
});

‎packages/qa/dogfood/test/email-template-dependent-unshipped-locale-read.dogfood.test.ts‎

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,14 @@ function showcaseRig() {
7575
const item = (doc?.item ?? doc) as Record<string, unknown>;
7676
return { status: read.status, subject: item.subject, locale: item.locale, _packageId: item._packageId };
7777
};
78+
/** `GET /meta/email_template/:name/layers` at one member — the subjects of `code`, `overlay` and `effective`, or the status. */
79+
const layers = async (member: string, pkg?: string) => {
80+
const read = await call('GET', `/meta/email_template/${NAME}/layers?member=${member}${pkg ? `&package=${pkg}` : ''}`);
81+
if (read.status !== 200) return { status: read.status };
82+
const doc = read.json?.data ?? read.json;
83+
const subject = (layer: any) => (layer === null || layer === undefined ? null : layer.subject);
84+
return { status: 200, code: subject(doc?.code), overlay: subject(doc?.overlay), effective: subject(doc?.effective) };
85+
};
7886
const rowsOf = (items: any[]) => items
7987
.filter((i) => i?.name === NAME)
8088
.map((i) => [i.locale, i._packageId, i.subject])
@@ -133,7 +141,7 @@ function showcaseRig() {
133141
const doc = read.json?.data ?? read.json?.item ?? read.json;
134142
rig.shipped = doc?.item ?? doc;
135143
};
136-
return { rig, boot, byName, listed, executing, rendered, body, saveInto, publishInto, createDependent, ensurePair };
144+
return { rig, boot, byName, layers, listed, executing, rendered, body, saveInto, publishInto, createDependent, ensurePair };
137145
}
138146

139147
const BASE_EN = { status: 200, subject: SHIPPED_SUBJECT, locale: 'en-US', _packageId: BASE };
@@ -179,6 +187,16 @@ describe('[#28802] a dependent\'s email template locale the base does not ship s
179187
expect(await r.byName('en-US')).toEqual(BASE_EN);
180188
});
181189

190+
it('[#28830] the layered read naming the base or no package stays 404 for the dependent\'s `fr-FR`; naming the dependent it answers', async () => {
191+
expect(await r.layers('fr-FR', BASE)).toEqual({ status: 404 });
192+
expect(await r.layers('fr-FR')).toEqual({ status: 404 });
193+
expect(await r.layers('fr-FR', DEPENDENT))
194+
.toEqual({ status: 200, code: null, overlay: DEPENDENT_SUBJECT, effective: DEPENDENT_SUBJECT });
195+
// Control: the base's own member.
196+
expect(await r.layers('en-US', BASE))
197+
.toEqual({ status: 200, code: SHIPPED_SUBJECT, overlay: null, effective: SHIPPED_SUBJECT });
198+
});
199+
182200
it('the env-wide, base-scoped and executing lists leave the dependent\'s `fr-FR` out, so a `fr-FR` send renders the base\'s `en-US`', async () => {
183201
expect(await r.listed()).toEqual([BASE_EN_ROW]);
184202
expect(await r.listed(BASE)).toEqual([BASE_EN_ROW]);
@@ -195,6 +213,9 @@ describe('[#28802] a dependent\'s email template locale the base does not ship s
195213
expect(await r.byName('en-US')).toEqual(OVERRIDE_EN);
196214
expect(await r.listed()).toEqual([['en-US', BASE, OVERRIDE_SUBJECT]]);
197215
expect(await r.rendered('en-US')).toBe('Override: T');
216+
expect(await r.layers('en-US', BASE))
217+
.toEqual({ status: 200, code: SHIPPED_SUBJECT, overlay: OVERRIDE_SUBJECT, effective: OVERRIDE_SUBJECT });
218+
expect(await r.layers('fr-FR', BASE)).toEqual({ status: 404 });
198219

199220
expect(await r.byName('fr-FR', BASE)).toEqual({ status: 404 });
200221
expect(await r.byName('fr-FR')).toEqual({ status: 404 });
@@ -223,6 +244,16 @@ describe('[#28802] the pair\'s own email template locale the base does not ship
223244
expect(await r.byName('en-US')).toEqual(BASE_EN);
224245
});
225246

247+
it('[#28830] the layered read naming the base or no package answers the pair\'s `fr-FR` layer, as the other reads serve it', async () => {
248+
const PAIR_LAYERS = { status: 200, code: null, overlay: PAIR_SUBJECT, effective: PAIR_SUBJECT };
249+
expect(await r.layers('fr-FR', BASE)).toEqual(PAIR_LAYERS);
250+
expect(await r.layers('fr-FR')).toEqual(PAIR_LAYERS);
251+
// Unchanged: the pair's own address, and the base's member.
252+
expect(await r.layers('fr-FR', PAIR)).toEqual(PAIR_LAYERS);
253+
expect(await r.layers('en-US', BASE))
254+
.toEqual({ status: 200, code: SHIPPED_SUBJECT, overlay: null, effective: SHIPPED_SUBJECT });
255+
});
256+
226257
it('the env-wide, base-scoped and executing lists carry the pair\'s `fr-FR` beside the base\'s `en-US`, so a `fr-FR` send renders it', async () => {
227258
expect(await r.listed()).toEqual([BASE_EN_ROW, PAIR_FR_ROW]);
228259
expect(await r.listed(BASE)).toEqual([BASE_EN_ROW, PAIR_FR_ROW]);
@@ -240,6 +271,8 @@ describe('[#28802] the pair\'s own email template locale the base does not ship
240271
expect(await r.byName('fr-FR', DEPENDENT)).toEqual(DEPENDENT_FR);
241272
expect(await r.byName('fr-FR', BASE)).toEqual(PAIR_FR);
242273
expect(await r.byName('fr-FR')).toEqual(PAIR_FR);
274+
expect(await r.layers('fr-FR', BASE))
275+
.toEqual({ status: 200, code: null, overlay: PAIR_SUBJECT, effective: PAIR_SUBJECT });
243276
expect(await r.listed()).toEqual([BASE_EN_ROW, PAIR_FR_ROW]);
244277
expect(await r.listed(BASE)).toEqual([BASE_EN_ROW, PAIR_FR_ROW]);
245278
expect(await r.executing()).toEqual([BASE_EN_ROW, PAIR_FR_ROW]);

0 commit comments

Comments
 (0)