From ae71b4e8eb938fb35af35b556c225f6da901a6c8 Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 15 Nov 2026 13:44:55 +0000 Subject: [PATCH 1/7] test(objectql, rest): pin a dependent package's added objectExtensions field on the packaged base and the served /meta read Co-Authored-By: Claude Claude-Session: https://claude.ai/code/session_01QsR2jVPGBoi3MCGoKbW1Hv --- .../src/protocol-packaged-object-base.test.ts | 120 +++++++++++++++++- .../src/meta-object-field-patch-i18n.test.ts | 89 +++++++++++++ 2 files changed, 207 insertions(+), 2 deletions(-) diff --git a/packages/objectql/src/protocol-packaged-object-base.test.ts b/packages/objectql/src/protocol-packaged-object-base.test.ts index 9b99e8c4052..5d60854eb56 100644 --- a/packages/objectql/src/protocol-packaged-object-base.test.ts +++ b/packages/objectql/src/protocol-packaged-object-base.test.ts @@ -259,10 +259,22 @@ describe('#27559 getPackagedObjectBase — the packaged RULE set is the owner pl expect((s.registry.getObject(OBJ) as any).label).toBe(EXTENSION_LABEL); }); - it('stays the owner declaration BY REFERENCE when no extender ships a rule', () => { + it('stays the owner declaration BY REFERENCE when no extender ships a rule or adds a field', () => { const s = makeSession(); registerPackaged(s.registry); - registerExtension(s.registry); + // An extension that relabels the object and redeclares one of the + // owner's own fields adds nothing the packaged base carries. + s.registry.registerObject( + { + name: OBJ, + label: EXTENSION_LABEL, + fields: { name: { name: 'name', type: 'text', label: 'Full Name' } }, + } as any, + EXT_PKG, + undefined, + 'extend', + 210, + ); expect(baseOf(s.protocol)).toBe(s.registry.getPackagedObjectOwner(OBJ)?.definition); }); @@ -282,3 +294,107 @@ describe('#27559 getPackagedObjectBase — the packaged RULE set is the owner pl expect(baseOf(s.protocol).validations.map((r: any) => r.message)).toEqual(['Extension says.']); }); }); + +describe('getPackagedObjectBase — a field a code extender ADDS is packaged, as the extender ships it', () => { + // A dependent package's `objectExtensions` entry adds fields the owner does + // not declare, and ships the translations of their labels and option + // labels in its own pack. The catalog translates exactly what the code + // layers ship (the #27559 sentence for rules), so the packaged + // counterpart of such a field is the extender's declaration; read off the + // owner alone, the field counted as authored after the fact and `/meta` + // served its source-language strings under every locale. + const DEP_PKG = 'com.example.carbon'; + const MARKET = { + name: 'cb_market', + type: 'select', + label: 'Market', + options: [ + { value: 'domestic', label: 'Domestic' }, + { value: 'export', label: 'Export' }, + ], + }; + + function registerDependentExtension(registry: SchemaRegistry, fields: Record, packageId = DEP_PKG) { + registry.installPackage({ id: packageId, name: packageId, version: '1.0.0' } as any, 'code'); + registry.registerObject({ name: OBJ, fields } as any, packageId, undefined, 'extend', 200); + } + + it('carries a code dependent\'s added field, label and option labels, beside the owner\'s fields', () => { + const s = makeSession(); + registerPackaged(s.registry); + registerDependentExtension(s.registry, { cb_market: MARKET }); + + const base = baseOf(s.protocol); + expect(base.fields.cb_market.label).toBe('Market'); + expect(base.fields.cb_market.options.map((o: any) => o.label)).toEqual(['Domestic', 'Export']); + expect(base.fields.name.label).toBe('Name'); + // The owner's own declaration is not mutated on the way. + expect((s.registry.getPackagedObjectOwner(OBJ)?.definition as any).fields.cb_market).toBeUndefined(); + }); + + it('keeps the OWNER\'s declaration of a field an extender redeclares, and the owner\'s scalars (#8037)', () => { + const s = makeSession(); + registerPackaged(s.registry); + s.registry.installPackage({ id: DEP_PKG, name: DEP_PKG, version: '1.0.0' } as any, 'code'); + s.registry.registerObject( + { + name: OBJ, + label: EXTENSION_LABEL, + fields: { name: { name: 'name', type: 'text', label: 'Full Name' }, cb_market: MARKET }, + } as any, + DEP_PKG, + undefined, + 'extend', + 200, + ); + + const base = baseOf(s.protocol); + expect(base.fields.name.label).toBe('Name'); + expect(base.label).toBe(PACKAGED_LABEL); + expect(base.fields.cb_market.label).toBe('Market'); + // The served object is the fold's, which the base must not follow. + expect((s.registry.getObject(OBJ) as any).fields.name.label).toBe('Full Name'); + }); + + it('does not carry a field a tenant overlay adds, and does not move under the tenant\'s rename of an extender field', () => { + const s = makeSession(); + registerPackaged(s.registry); + registerDependentExtension(s.registry, { cb_market: MARKET }); + s.registry.registerObject( + { + name: OBJ, + label: PACKAGED_LABEL, + fields: { + name: { name: 'name', type: 'text', label: 'Name' }, + cb_market: { ...MARKET, label: 'Sales Market' }, + tenant_note: { name: 'tenant_note', type: 'text', label: 'Note' }, + }, + _packageId: 'sys_metadata', _provenance: 'org', + } as any, + 'sys_metadata', + undefined, + 'overlay', + ); + + const base = baseOf(s.protocol); + expect(base.fields.tenant_note).toBeUndefined(); + expect(base.fields.cb_market.label).toBe('Market'); + }); + + it('lets a later code extender\'s declaration of an added field replace an earlier one, as the fold does', () => { + const s = makeSession(); + registerPackaged(s.registry); + registerDependentExtension(s.registry, { cb_market: MARKET }); + s.registry.installPackage({ id: 'com.example.later', name: 'later', version: '1.0.0' } as any, 'code'); + s.registry.registerObject( + { name: OBJ, fields: { cb_market: { ...MARKET, label: 'Sales Market' } } } as any, + 'com.example.later', + undefined, + 'extend', + 300, + ); + + expect(baseOf(s.protocol).fields.cb_market.label).toBe('Sales Market'); + expect((s.registry.getObject(OBJ) as any).fields.cb_market.label).toBe('Sales Market'); + }); +}); diff --git a/packages/rest/src/meta-object-field-patch-i18n.test.ts b/packages/rest/src/meta-object-field-patch-i18n.test.ts index f18bb7da386..79e523749e6 100644 --- a/packages/rest/src/meta-object-field-patch-i18n.test.ts +++ b/packages/rest/src/meta-object-field-patch-i18n.test.ts @@ -158,3 +158,92 @@ describe('a published fieldPatches label survives the served /meta exit', () => expect(todoOf(out).label).toBe('待办'); }); }); + +describe('a field a dependent package adds through objectExtensions is translated from its own pack rows', () => { + // The dependent ships `cb_market` (a select) on the base's object and the + // zh-CN rows for it; the deployment catalog deep-merges every package's + // rows, so they sit beside the owner's. Measured before the fix: the item + // and list reads served `Market` / `Domestic` / `Export` under zh-CN, + // because the packaged base (the owner alone) did not declare the field + // and every slot of it counted as authored after the fact. + const DEP_PKG = 'com.example.carbon'; + const MARKET = { + name: 'cb_market', + type: 'select', + label: 'Market', + options: [ + { value: 'domestic', label: 'Domestic' }, + { value: 'export', label: 'Export' }, + ], + }; + const DEP_ROWS: Record = { + en: { cb_market: { label: 'Market', options: { domestic: 'Domestic', export: 'Export' } } }, + 'zh-CN': { + cb_market: { label: '市场', options: { domestic: '内销', export: '出口' } }, + tenant_note: { label: '备注' }, + }, + }; + const merged: Record = structuredClone(BUNDLE); + for (const locale of Object.keys(DEP_ROWS)) Object.assign(merged[locale].objects[OBJ].fields, DEP_ROWS[locale]); + const mergedI18n = { ...i18nService, getTranslations: (locale: string) => merged[locale] }; + + function withDependent(extensionFields: Record = { cb_market: MARKET }): SchemaRegistry { + const reg = registry(false); + reg.registerObject({ name: OBJ, fields: extensionFields } as any, DEP_PKG, undefined, 'extend', 200); + return reg; + } + + function mergedSources(reg: SchemaRegistry, locale: string): MetaListTranslationSources { + return { ...sources(reg, locale), resolveI18nService: async () => mergedI18n }; + } + + const marketOf = (doc: any) => doc.fields.cb_market; + + it('the item read serves the added field\'s label and option labels translated (zh-CN)', async () => { + const reg = withDependent(); + const out: any = await translateMetaDocument(mergedSources(reg, 'zh-CN'), 'object', served(reg)); + expect(marketOf(out).label).toBe('市场'); + expect(marketOf(out).options.map((o: any) => o.label)).toEqual(['内销', '出口']); + }); + + it('the list read serves them translated too (zh-CN), and the source text in en', async () => { + const reg = withDependent(); + const zh: any = await translateMetaList(mergedSources(reg, 'zh-CN'), 'object', [served(reg)]); + expect(marketOf(zh[0]).label).toBe('市场'); + expect(marketOf(zh[0]).options.map((o: any) => o.label)).toEqual(['内销', '出口']); + const en: any = await translateMetaList(mergedSources(reg, 'en'), 'object', [served(reg)]); + expect(marketOf(en[0]).label).toBe('Market'); + }); + + it('the base package\'s own fields are translated as before', async () => { + const reg = withDependent(); + const out: any = await translateMetaDocument(mergedSources(reg, 'zh-CN'), 'object', served(reg)); + expect(out.label).toBe('任务'); + expect(titleOf(out).label).toBe('标题'); + expect(out.fields.status.options.map((o: any) => o.label)).toEqual(['待办', '已完成']); + }); + + it('a dependent that redeclares an OWNER field keeps its label: the owner stays that field\'s packaged base', async () => { + const reg = withDependent({ cb_market: MARKET, title: { name: 'title', type: 'text', label: 'Headline' } }); + const out: any = await translateMetaDocument(mergedSources(reg, 'zh-CN'), 'object', served(reg)); + expect(titleOf(out).label).toBe('Headline'); + expect(marketOf(out).label).toBe('市场'); + }); + + it('a field a tenant overlay adds stays authored after the fact and keeps its text', async () => { + const reg = withDependent(); + reg.registerObject( + { + ...owner(), + fields: { ...owner().fields, tenant_note: { name: 'tenant_note', type: 'text', label: 'Note' } }, + _packageId: 'sys_metadata', _provenance: 'org', + } as any, + 'sys_metadata', + undefined, + 'overlay', + ); + const out: any = await translateMetaDocument(mergedSources(reg, 'zh-CN'), 'object', served(reg)); + expect(out.fields.tenant_note.label).toBe('Note'); + expect(marketOf(out).label).toBe('市场'); + }); +}); From 1437b8f5e581ee2dab4ac6195dd303f066d07917 Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 15 Nov 2026 15:41:16 +0000 Subject: [PATCH 2/7] fix(objectql): the packaged object base carries the fields a code extender adds, so /meta translates a dependent package's added fields getPackagedObjectBase now also carries every field a CODE extend contributor adds under a name the owner does not declare (fold order, same filter as packagedRules). Owner-declared fields, the scalars and fieldPatches stay the owner's; tenant overlays and stored extensions add nothing. The stale spec comments that described the base as the owner alone are rewritten. Co-Authored-By: Claude Claude-Session: https://claude.ai/code/session_01QsR2jVPGBoi3MCGoKbW1Hv --- .../protocol-meta-effective-schema.test.ts | 86 +++++++++++++++++++ .../src/protocol-packaged-object-base.test.ts | 48 +++++++++++ packages/objectql/src/registry.ts | 65 ++++++++++++-- .../spec/src/system/i18n-resolver.test.ts | 6 +- packages/spec/src/system/i18n-resolver.ts | 18 +++- 5 files changed, 210 insertions(+), 13 deletions(-) diff --git a/packages/objectql/src/protocol-meta-effective-schema.test.ts b/packages/objectql/src/protocol-meta-effective-schema.test.ts index 7260e940c14..3784a0d5730 100644 --- a/packages/objectql/src/protocol-meta-effective-schema.test.ts +++ b/packages/objectql/src/protocol-meta-effective-schema.test.ts @@ -535,3 +535,89 @@ describe('[#29673] a zh-CN read echoed back is stored as its source, and publish expect(host.registry.getObject('crm_lead')).toBeDefined(); }); }); + +/** + * [#29673 door · a code dependent's added field] The save door translates its + * source against the same packaged base the read uses + * (`getPackagedObjectBase`), which now carries the fields a CODE extender adds. + * So a zh-CN read that serves such a field translated, echoed back by Studio's + * PUT, is stored as the extender's source text — with a stored row (its + * source) and without one (the packaged base is the source). Were the read and + * the door to disagree about the base, the translation would be stored as the + * tenant's own label, and served in English to every reader after it. + */ +describe('a zh-CN read of a field a code dependent adds, echoed back, is stored as its source', () => { + const MARKET = { + name: 'cb_market', + type: 'select', + label: 'Market', + options: [ + { value: 'domestic', label: 'Domestic' }, + { value: 'export', label: 'Export' }, + ], + }; + const bundle = { + 'zh-CN': { + objects: { + crm_account: { + fields: { + name: { label: '名称' }, + cb_market: { label: '市场', options: { domestic: '内销', export: '出口' } }, + }, + }, + }, + }, + }; + + /** The code layers: a base package's owner and a dependent's `objectExtensions` field. */ + function codeLayers(): SchemaRegistry { + const reg = new SchemaRegistry({ multiTenant: false }); + reg.logLevel = 'silent'; + reg.installPackage({ id: 'com.example.crm', name: 'crm', version: '1.0.0' } as any, 'code'); + reg.registerObject( + { name: 'crm_account', label: 'Account', sharingModel: 'private', fields: { name: { name: 'name', type: 'text', label: 'Name' } } } as any, + 'com.example.crm', + ); + reg.installPackage({ id: 'com.example.carbon', name: 'carbon', version: '1.0.0' } as any, 'code'); + reg.registerObject({ name: 'crm_account', fields: { cb_market: MARKET } } as any, 'com.example.carbon', undefined, 'extend', 200); + return reg; + } + + const storedOf = (host: ReturnType) => + JSON.parse(Array.from(host.rows.values()).find((r) => r.name === 'crm_account' && r.state === 'active')!.metadata); + + for (const withStoredRow of [true, false]) { + it(`stores 'Market' and its option labels, ${withStoredRow ? 'over a stored row' : 'with no stored row'}`, async () => { + const layers = codeLayers(); + const packagedBase = () => layers.getPackagedObjectBase('crm_account'); + const served: any = { ...structuredClone(layers.getObject('crm_account') as any), sharingModel: 'private' }; + for (const k of Object.keys(served)) if (k.startsWith('_')) delete served[k]; + const echo: any = translateMetadataDocument('object', structuredClone(served), bundle as any, { locale: 'zh-CN', packagedBase: packagedBase() }); + // The precondition: the read serves the dependent's field translated. + expect(echo.fields.cb_market.label).toBe('市场'); + expect(echo.fields.cb_market.options.map((o: any) => o.label)).toEqual(['内销', '出口']); + + const host = makeHost(false); + if (withStoredRow) { + await host.engine.insert('sys_metadata', { + type: 'object', name: 'crm_account', organization_id: null, package_id: null, state: 'active', + metadata: JSON.stringify({ name: 'crm_account', label: 'Account', sharingModel: 'private', fields: { name: served.fields.name, cb_market: MARKET } }), + }); + } + const protocol: any = new ObjectStackProtocolImplementation(host.engine, () => new Map([ + ['i18n', { getLocales: () => Object.keys(bundle), getTranslations: (locale: string) => (bundle as any)[locale] }], + ])); + protocol.getPackagedObjectBase = (name: string) => (name === 'crm_account' ? packagedBase() : undefined); + const saved: any = await protocol.saveMetaItem({ type: 'object', name: 'crm_account', item: echo, mode: 'publish' } as any); + + const stored = storedOf(host); + expect(stored.fields.cb_market.label).toBe('Market'); + expect(stored.fields.cb_market.options.map((o: any) => o.label)).toEqual(['Domestic', 'Export']); + expect(stored.fields.name.label).toBe('Name'); + expect((saved.advisories ?? []).map((a: any) => a.path)).toEqual(expect.arrayContaining([ + 'objects.crm_account.fields.cb_market.label', + 'objects.crm_account.fields.cb_market.options[domestic].label', + ])); + }); + } +}); diff --git a/packages/objectql/src/protocol-packaged-object-base.test.ts b/packages/objectql/src/protocol-packaged-object-base.test.ts index 5d60854eb56..5a4f10c66b1 100644 --- a/packages/objectql/src/protocol-packaged-object-base.test.ts +++ b/packages/objectql/src/protocol-packaged-object-base.test.ts @@ -381,6 +381,54 @@ describe('getPackagedObjectBase — a field a code extender ADDS is packaged, as expect(base.fields.cb_market.label).toBe('Market'); }); + it('is no longer the owner BY REFERENCE once a code extender adds a field: the shared fixture\'s `loyalty_tier` is carried', () => { + const s = makeSession(); + registerPackaged(s.registry); + registerExtension(s.registry); + const base = baseOf(s.protocol); + expect(base).not.toBe(s.registry.getPackagedObjectOwner(OBJ)?.definition); + expect(base.fields.loyalty_tier.label).toBe('Loyalty Tier'); + expect(base.label).toBe(PACKAGED_LABEL); + }); + + it('carries nothing from a stored (tenant-provenance) extension, a `.custom` pair\'s row included', () => { + const s = makeSession(); + registerPackaged(s.registry); + s.registry.registerObject( + { + name: OBJ, + fields: { region__c: { name: 'region__c', type: 'text', label: 'Region' } }, + _packageId: 'app.showcase.custom', _provenance: 'org', + } as any, + 'app.showcase.custom', + undefined, + 'extend', + 200, + ); + expect((s.registry.getObject(OBJ) as any).fields.region__c).toBeDefined(); + const base = baseOf(s.protocol); + expect(base.fields.region__c).toBeUndefined(); + expect(base).toBe(s.registry.getPackagedObjectOwner(OBJ)?.definition); + }); + + it('does not fold a code extender\'s fieldPatches into the base: the owner\'s field text stays the packaged one', () => { + const s = makeSession(); + registerPackaged(s.registry); + s.registry.installPackage({ id: DEP_PKG, name: DEP_PKG, version: '1.0.0' } as any, 'code'); + s.registry.registerObject( + { name: OBJ, fields: { cb_market: MARKET }, fieldPatches: { name: { label: 'Company Name', description: 'Patched.' } } } as any, + DEP_PKG, + undefined, + 'extend', + 200, + ); + expect((s.registry.getObject(OBJ) as any).fields.name.label).toBe('Company Name'); + const base = baseOf(s.protocol); + expect(base.fields.name.label).toBe('Name'); + expect(base.fields.name.description).toBeUndefined(); + expect(base.fields.cb_market.label).toBe('Market'); + }); + it('lets a later code extender\'s declaration of an added field replace an earlier one, as the fold does', () => { const s = makeSession(); registerPackaged(s.registry); diff --git a/packages/objectql/src/registry.ts b/packages/objectql/src/registry.ts index 2276f7dafc6..0ecc4216fdc 100644 --- a/packages/objectql/src/registry.ts +++ b/packages/objectql/src/registry.ts @@ -1021,6 +1021,39 @@ function withoutWithheldMembers(base: ServiceObject, withheld: WithheldExtension * over the base rather than re-derived from the running `merged`; `tenantRules` * ({@link SchemaRegistry.tenantRuleSettings}) is computed once for the same reason. */ +/** + * [ADR-0029 D9.2a, #27559's rule-name principle carried to field names] The + * fields the CODE `extend` contributors of an object add — every field name + * the owner does not declare — in fold order, so a later extender's + * declaration of one name replaces an earlier one's, as + * {@link mergeObjectDefinitions} does. The same filter as + * `SchemaRegistry.packagedRules`: `ownership === 'extend'` and a code artifact + * body, so a tenant overlay or a stored extension (`_provenance: 'org'`) + * contributes nothing. `fieldPatches` are not read. `undefined` when no code + * extender adds a field, or the owner's `fields` is not the canonical record. + */ +function packagedAddedFields( + owner: ServiceObject, + contributors: readonly ObjectContributor[], +): Record | undefined { + const ownFields = owner.fields as unknown; + if (ownFields !== undefined && (ownFields === null || typeof ownFields !== 'object' || Array.isArray(ownFields))) { + return undefined; + } + const declared = (ownFields ?? {}) as Record; + let added: Record | undefined; + for (const contrib of contributors) { + if (contrib.ownership !== 'extend' || !isCodeArtifactBody(contrib.definition)) continue; + const fields = contrib.definition.fields as unknown; + if (!fields || typeof fields !== 'object' || Array.isArray(fields)) continue; + for (const [name, def] of Object.entries(fields as Record)) { + if (Object.prototype.hasOwnProperty.call(declared, name)) continue; + (added ??= {})[name] = def; + } + } + return added; +} + function mergeObjectDefinitions( base: ServiceObject, extension: ObjectExtensionBody, @@ -8137,12 +8170,26 @@ export class SchemaRegistry { * `@objectstack/metadata-protocol`, `packagedRuleLookup` in this package), * so they cannot split again. * - * ⛔ ONLY `validations` widens. The scalars stay the owner's: an extension's - * `label` / `description` must keep reading as diverged from the packaged - * one, or the catalog takes back the case #8037 filed. + * The same sentence holds for a FIELD a code extender adds (a dependent + * package's `objectExtensions` field the owner does not declare): its + * packaged declaration is the extender's, because the catalog rows for it + * can only translate what that extender ships ({@link packagedAddedFields}). + * Read off the owner alone, such a field counted as authored after the fact, + * and `/meta` served its label and option labels untranslated in every + * locale while the extender's own pack carried them. + * + * ⛔ Exactly those two widen: rules by name, and field NAMES the owner does + * not declare. The scalars stay the owner's, and so does every field the + * owner declares, even one an extender redeclares; an extender's + * `fieldPatches` are never folded in. Each must keep reading as diverged from + * the packaged one, or the catalog — which translates the owner's text under + * the owner's keys — takes back the case #8037 filed. A tenant overlay and a + * stored (non-code) extension add nothing here: their fields stay authored + * after the fact. * * Returns the owner's definition BY REFERENCE when no code extender ships a - * rule, and `undefined` exactly where {@link getPackagedObjectOwner} does. + * rule or adds a field, and `undefined` exactly where + * {@link getPackagedObjectOwner} does. */ getPackagedObjectBase(name: string): ServiceObject | undefined { const owner = this.getPackagedObjectOwner(name); @@ -8154,9 +8201,13 @@ export class SchemaRegistry { const extended = contributors.some((c) => c.ownership === 'extend' && isCodeArtifactBody(c.definition) && Array.isArray(c.definition.validations) && c.definition.validations.length > 0); - if (!extended) return owner.definition; - const rules = this.packagedRules(contributors) ?? []; - return { ...owner.definition, validations: rules as ServiceObject['validations'] }; + const addedFields = packagedAddedFields(owner.definition, contributors); + if (!extended && addedFields === undefined) return owner.definition; + return { + ...owner.definition, + ...(extended ? { validations: (this.packagedRules(contributors) ?? []) as ServiceObject['validations'] } : {}), + ...(addedFields !== undefined ? { fields: { ...owner.definition.fields, ...addedFields } } : {}), + }; } /** diff --git a/packages/spec/src/system/i18n-resolver.test.ts b/packages/spec/src/system/i18n-resolver.test.ts index afc7f13110c..5ea093baf6c 100644 --- a/packages/spec/src/system/i18n-resolver.test.ts +++ b/packages/spec/src/system/i18n-resolver.test.ts @@ -4404,8 +4404,10 @@ describe('translateObject — a field\'s translated help is served on `descripti }); it('a field the packaged base does not declare counts as diverged', () => { - // An `objectExtensions` field is folded on after the owner's declaration, - // which is all the base carries. + // A field authored after the fact — a tenant overlay's, or a stored + // extension's — is absent from the packaged base. (A field a CODE + // extender adds is not this case: the serving layer's base carries it, + // `getPackagedObjectBase` in `@objectstack/objectql`.) const served = clone(PACKAGED) as any; served.fields.extra = { name: 'extra', type: 'text', label: 'Extra', description: 'Added by an extension.' }; const bundle = clone(BUNDLE) as any; diff --git a/packages/spec/src/system/i18n-resolver.ts b/packages/spec/src/system/i18n-resolver.ts index 22ab117fc82..c4468db8317 100644 --- a/packages/spec/src/system/i18n-resolver.ts +++ b/packages/spec/src/system/i18n-resolver.ts @@ -377,7 +377,12 @@ export interface TranslateDocumentOptions extends ResolveOptions { * (ADR-0029 D9.2) and before any tenant `sys_metadata` overlay. For an * object, its `validations` also carry the rules each code extender ships * (#27559), since a rule's packaged message is the message of whichever code - * layer shipped that rule name; its scalars stay the owner's. + * layer shipped that rule name, and its `fields` also carry each field a + * code extender ADDS under a name the owner does not declare, as that + * extender ships it — the catalog rows for such a field can only translate + * what its extender ships. Its scalars, every field the owner declares, and + * the owner's fields as an extension's `fieldPatches` leave them stay the + * owner's. * * Supplied by the serving layer, which is the only one that knows it; when * it is absent the translators behave exactly as they did before #8284 (the @@ -2235,8 +2240,10 @@ function packagedPart( * The packaged counterpart of one served FIELD of an object, with the same * three answers as {@link packagedPart}: `undefined` when no packaged base was * supplied, `{}` when the base is known but declares no such field (a field - * authored after the fact — an `objectExtensions` field is folded on after the - * owner's declaration the base carries), and the packaged field otherwise. + * authored after the fact — a tenant overlay's or a stored extension's; a + * field a code extender adds is carried by the base the serving layer + * supplies, see {@link TranslateDocumentOptions.packagedBase}), and the + * packaged field otherwise. * * A separate finder only because a field map is a record keyed by field name * (the canonical shape) where {@link packagedPart} walks an array; the array @@ -4921,7 +4928,10 @@ function packagedRulesByName(packagedBase: unknown): Map`) applies to them as before. A field the - * base does not declare counts as diverged on every slot, as below; the + * base does not declare counts as diverged on every slot, as below (the base + * carries the fields a code extender adds — see + * {@link TranslateDocumentOptions.packagedBase} — so this is a field a tenant + * or a stored extension authored); the * built-in system-field labels apply only where the catalog may. * The embedded `listViews` follow the VIEW translator's * application of the same rule (ADR-0029 D9.2a, as {@link translateView} From 473b5a07bdd2e68e357566b13433f6a023796ac6 Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 15 Nov 2026 16:01:19 +0000 Subject: [PATCH 3/7] chore: changeset for the packaged base carrying a code extender's added fields Co-Authored-By: Claude Claude-Session: https://claude.ai/code/session_01QsR2jVPGBoi3MCGoKbW1Hv --- .changeset/33800-extender-added-fields-translate.md | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 .changeset/33800-extender-added-fields-translate.md diff --git a/.changeset/33800-extender-added-fields-translate.md b/.changeset/33800-extender-added-fields-translate.md new file mode 100644 index 00000000000..5f7223d68fb --- /dev/null +++ b/.changeset/33800-extender-added-fields-translate.md @@ -0,0 +1,13 @@ +--- +'@objectstack/objectql': patch +'@objectstack/spec': patch +--- + +fix(objectql): a field a dependent package adds through `objectExtensions` is served translated on `/api/v1/meta/object` + +`SchemaRegistry.getPackagedObjectBase` (the packaged base that `/meta` translates an object against, and that the save door's translated-echo restore reads) now also carries each field a CODE `extend` contributor adds under a name the owner does not declare, as that extender ships it. A later extender's declaration of the same name replaces an earlier one, as in the fold. Before this change such a field counted as authored after the fact. Every non-default-locale read (`GET /api/v1/meta/object`, `GET /api/v1/meta/object/:name`, the list read, the form routes) then served its `label`, help text and option labels in the source language, even when the extender's own translation pack carried them. These reads now serve the pack's translation for those fields. A Studio save of such a read stores the source text again. Default-locale reads are unchanged. + +Unchanged: the object scalars, every field the owner declares (including one an extender redeclares), and an extender's `fieldPatches` all stay the owner's. A patched label or description still keeps its text in every language. Fields added by a tenant overlay or a stored (`_provenance: 'org'`) extension, the `.custom` pair's included, still count as authored after the fact. `@objectstack/spec` changes only in doc comments (`TranslateDocumentOptions.packagedBase` and `translateObject`). + +Clause-②: no +Metadata-protocol: none From 442a947ae6dcabeb0539ab273a0287a3948c9ca4 Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 15 Nov 2026 16:41:12 +0000 Subject: [PATCH 4/7] fix(objectql): type the packaged base's widened field record Co-Authored-By: Claude Claude-Session: https://claude.ai/code/session_01QsR2jVPGBoi3MCGoKbW1Hv --- packages/objectql/src/registry.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/objectql/src/registry.ts b/packages/objectql/src/registry.ts index 0ecc4216fdc..a84b56a9be1 100644 --- a/packages/objectql/src/registry.ts +++ b/packages/objectql/src/registry.ts @@ -8206,7 +8206,9 @@ export class SchemaRegistry { return { ...owner.definition, ...(extended ? { validations: (this.packagedRules(contributors) ?? []) as ServiceObject['validations'] } : {}), - ...(addedFields !== undefined ? { fields: { ...owner.definition.fields, ...addedFields } } : {}), + ...(addedFields !== undefined + ? { fields: { ...owner.definition.fields, ...addedFields } as ServiceObject['fields'] } + : {}), }; } From 141ca7a5eadc8e5af1ff2d2a43ea55a56cbcbf40 Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 15 Nov 2026 18:54:58 +0000 Subject: [PATCH 5/7] test(rest): pay the read gate's spec/ui load at collection in the extension i18n pins Co-Authored-By: Claude Claude-Session: https://claude.ai/code/session_01QsR2jVPGBoi3MCGoKbW1Hv --- packages/rest/src/meta-object-field-patch-i18n.test.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/rest/src/meta-object-field-patch-i18n.test.ts b/packages/rest/src/meta-object-field-patch-i18n.test.ts index 79e523749e6..923cd28bbd5 100644 --- a/packages/rest/src/meta-object-field-patch-i18n.test.ts +++ b/packages/rest/src/meta-object-field-patch-i18n.test.ts @@ -25,6 +25,8 @@ */ import { describe, it, expect } from 'vitest'; +// The read gate loads `@objectstack/spec/ui` with a dynamic import; pay that load at collection. +import '@objectstack/spec/ui'; import { SchemaRegistry } from '@objectstack/objectql'; import { translateMetaDocument, translateMetaList, type MetaListTranslationSources } from './meta-item-read-gate.js'; From e2c5196a951281e5571d55f47a1f3c3d0d525de0 Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 15 Nov 2026 23:23:32 +0000 Subject: [PATCH 6/7] fix(objectql): the packaged base skips a disabled package's added fields, as the served fold withholds them Co-Authored-By: Claude Claude-Session: https://claude.ai/code/session_01QsR2jVPGBoi3MCGoKbW1Hv --- packages/objectql/src/registry.ts | 87 +++++++++++-------- .../src/meta-object-field-patch-i18n.test.ts | 19 ++++ .../spec/src/system/i18n-resolver.test.ts | 4 +- packages/spec/src/system/i18n-resolver.ts | 12 +-- 4 files changed, 77 insertions(+), 45 deletions(-) diff --git a/packages/objectql/src/registry.ts b/packages/objectql/src/registry.ts index d2d2dd83823..3b59a0175a2 100644 --- a/packages/objectql/src/registry.ts +++ b/packages/objectql/src/registry.ts @@ -959,6 +959,45 @@ function withoutWithheldMembers(base: ServiceObject, withheld: WithheldExtension return out; } +/** + * [ADR-0029 D9.2a, #27559's rule-name principle carried to field names] The + * fields the CODE `extend` contributors of an object add — every field name + * the owner does not declare — in fold order, so a later extender's + * declaration of one name replaces an earlier one's, as + * {@link mergeObjectDefinitions} does. The same filter as + * `SchemaRegistry.packagedRules` (`ownership === 'extend'` and a code artifact + * body), so a tenant overlay and any extension of tenant provenance + * (`_provenance: 'org'`) contribute nothing, while a stored extension row + * of package provenance is a code layer and does. `contributors` is the + * caller's: {@link SchemaRegistry.getPackagedObjectBase} hands in the list + * without a disabled package's extensions, as the served fold withholds them + * ({@link SchemaRegistry.withholdDisabledExtensions}), so the base and the + * served field are the same extender's. `fieldPatches` are not read. + * `undefined` when no code extender adds a field, or the owner's `fields` is + * not the canonical record. + */ +function packagedAddedFields( + owner: ServiceObject, + contributors: readonly ObjectContributor[], +): Record | undefined { + const ownFields = owner.fields as unknown; + if (ownFields !== undefined && (ownFields === null || typeof ownFields !== 'object' || Array.isArray(ownFields))) { + return undefined; + } + const declared = (ownFields ?? {}) as Record; + let added: Record | undefined; + for (const contrib of contributors) { + if (contrib.ownership !== 'extend' || !isCodeArtifactBody(contrib.definition)) continue; + const fields = contrib.definition.fields as unknown; + if (!fields || typeof fields !== 'object' || Array.isArray(fields)) continue; + for (const [name, def] of Object.entries(fields as Record)) { + if (Object.prototype.hasOwnProperty.call(declared, name)) continue; + (added ??= {})[name] = def; + } + } + return added; +} + /** * Deep merge two ServiceObject definitions. * @@ -1021,39 +1060,6 @@ function withoutWithheldMembers(base: ServiceObject, withheld: WithheldExtension * over the base rather than re-derived from the running `merged`; `tenantRules` * ({@link SchemaRegistry.tenantRuleSettings}) is computed once for the same reason. */ -/** - * [ADR-0029 D9.2a, #27559's rule-name principle carried to field names] The - * fields the CODE `extend` contributors of an object add — every field name - * the owner does not declare — in fold order, so a later extender's - * declaration of one name replaces an earlier one's, as - * {@link mergeObjectDefinitions} does. The same filter as - * `SchemaRegistry.packagedRules`: `ownership === 'extend'` and a code artifact - * body, so a tenant overlay or a stored extension (`_provenance: 'org'`) - * contributes nothing. `fieldPatches` are not read. `undefined` when no code - * extender adds a field, or the owner's `fields` is not the canonical record. - */ -function packagedAddedFields( - owner: ServiceObject, - contributors: readonly ObjectContributor[], -): Record | undefined { - const ownFields = owner.fields as unknown; - if (ownFields !== undefined && (ownFields === null || typeof ownFields !== 'object' || Array.isArray(ownFields))) { - return undefined; - } - const declared = (ownFields ?? {}) as Record; - let added: Record | undefined; - for (const contrib of contributors) { - if (contrib.ownership !== 'extend' || !isCodeArtifactBody(contrib.definition)) continue; - const fields = contrib.definition.fields as unknown; - if (!fields || typeof fields !== 'object' || Array.isArray(fields)) continue; - for (const [name, def] of Object.entries(fields as Record)) { - if (Object.prototype.hasOwnProperty.call(declared, name)) continue; - (added ??= {})[name] = def; - } - } - return added; -} - function mergeObjectDefinitions( base: ServiceObject, extension: ObjectExtensionBody, @@ -8244,9 +8250,11 @@ export class SchemaRegistry { * owner declares, even one an extender redeclares; an extender's * `fieldPatches` are never folded in. Each must keep reading as diverged from * the packaged one, or the catalog — which translates the owner's text under - * the owner's keys — takes back the case #8037 filed. A tenant overlay and a - * stored (non-code) extension add nothing here: their fields stay authored - * after the fact. + * the owner's keys — takes back the case #8037 filed. A tenant overlay and an + * extension of tenant provenance (`_provenance: 'org'`) add nothing here: + * their fields stay authored after the fact. Nor does a disabled package's + * extension, which the served fold withholds. (The rule half, `packagedRules`, + * still reads every code extender, disabled ones included.) * * Returns the owner's definition BY REFERENCE when no code extender ships a * rule or adds a field, and `undefined` exactly where @@ -8262,7 +8270,12 @@ export class SchemaRegistry { const extended = contributors.some((c) => c.ownership === 'extend' && isCodeArtifactBody(c.definition) && Array.isArray(c.definition.validations) && c.definition.validations.length > 0); - const addedFields = packagedAddedFields(owner.definition, contributors); + // A disabled package's extension is withheld from the served fold, so it + // adds nothing the served object carries; its field is no packaged one. + const addedFields = packagedAddedFields( + owner.definition, + contributors.filter((c) => !(c.ownership === 'extend' && this.isPackageDisabled(c.packageId))), + ); if (!extended && addedFields === undefined) return owner.definition; return { ...owner.definition, diff --git a/packages/rest/src/meta-object-field-patch-i18n.test.ts b/packages/rest/src/meta-object-field-patch-i18n.test.ts index 923cd28bbd5..8d09289757a 100644 --- a/packages/rest/src/meta-object-field-patch-i18n.test.ts +++ b/packages/rest/src/meta-object-field-patch-i18n.test.ts @@ -232,6 +232,25 @@ describe('a field a dependent package adds through objectExtensions is translate expect(marketOf(out).label).toBe('市场'); }); + it('a later extender that adds the same name and is DISABLED is withheld from the base as from the fold: the enabled one\'s field is translated', async () => { + const reg = withDependent(); + reg.installPackage({ id: 'com.example.later', name: 'later', version: '1.0.0' } as any, 'code'); + reg.registerObject( + { name: OBJ, fields: { cb_market: { ...MARKET, label: 'Sales Market' } } } as any, + 'com.example.later', + undefined, + 'extend', + 300, + ); + reg.disablePackage('com.example.later'); + // The premise: the fold serves the enabled extender's declaration. + expect(marketOf(served(reg)).label).toBe('Market'); + expect((reg.getPackagedObjectBase(OBJ) as any).fields.cb_market.label).toBe('Market'); + const out: any = await translateMetaDocument(mergedSources(reg, 'zh-CN'), 'object', served(reg)); + expect(marketOf(out).label).toBe('市场'); + expect(marketOf(out).options.map((o: any) => o.label)).toEqual(['内销', '出口']); + }); + it('a field a tenant overlay adds stays authored after the fact and keeps its text', async () => { const reg = withDependent(); reg.registerObject( diff --git a/packages/spec/src/system/i18n-resolver.test.ts b/packages/spec/src/system/i18n-resolver.test.ts index 5ea093baf6c..1c930bf44e2 100644 --- a/packages/spec/src/system/i18n-resolver.test.ts +++ b/packages/spec/src/system/i18n-resolver.test.ts @@ -4404,8 +4404,8 @@ describe('translateObject — a field\'s translated help is served on `descripti }); it('a field the packaged base does not declare counts as diverged', () => { - // A field authored after the fact — a tenant overlay's, or a stored - // extension's — is absent from the packaged base. (A field a CODE + // A field authored after the fact — a tenant overlay's, or a + // tenant-provenance extension's — is absent from the packaged base. (A field a CODE // extender adds is not this case: the serving layer's base carries it, // `getPackagedObjectBase` in `@objectstack/objectql`.) const served = clone(PACKAGED) as any; diff --git a/packages/spec/src/system/i18n-resolver.ts b/packages/spec/src/system/i18n-resolver.ts index c4468db8317..f11dbbd8fb8 100644 --- a/packages/spec/src/system/i18n-resolver.ts +++ b/packages/spec/src/system/i18n-resolver.ts @@ -380,9 +380,9 @@ export interface TranslateDocumentOptions extends ResolveOptions { * layer shipped that rule name, and its `fields` also carry each field a * code extender ADDS under a name the owner does not declare, as that * extender ships it — the catalog rows for such a field can only translate - * what its extender ships. Its scalars, every field the owner declares, and - * the owner's fields as an extension's `fieldPatches` leave them stay the - * owner's. + * what its extender ships. Its scalars and every field the owner declares + * stay the owner's: an extension's `fieldPatches` are never folded in, so a + * patched owner field still reads as diverged. * * Supplied by the serving layer, which is the only one that knows it; when * it is absent the translators behave exactly as they did before #8284 (the @@ -2240,8 +2240,8 @@ function packagedPart( * The packaged counterpart of one served FIELD of an object, with the same * three answers as {@link packagedPart}: `undefined` when no packaged base was * supplied, `{}` when the base is known but declares no such field (a field - * authored after the fact — a tenant overlay's or a stored extension's; a - * field a code extender adds is carried by the base the serving layer + * authored after the fact — a tenant overlay's, or one of tenant provenance; + * a field a code extender adds is carried by the base the serving layer * supplies, see {@link TranslateDocumentOptions.packagedBase}), and the * packaged field otherwise. * @@ -4931,7 +4931,7 @@ function packagedRulesByName(packagedBase: unknown): Map Date: Sun, 15 Nov 2026 23:23:50 +0000 Subject: [PATCH 7/7] chore: changeset names the disabled-extender boundary Co-Authored-By: Claude Claude-Session: https://claude.ai/code/session_01QsR2jVPGBoi3MCGoKbW1Hv --- .changeset/33800-extender-added-fields-translate.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.changeset/33800-extender-added-fields-translate.md b/.changeset/33800-extender-added-fields-translate.md index 5f7223d68fb..8e96daf5d8a 100644 --- a/.changeset/33800-extender-added-fields-translate.md +++ b/.changeset/33800-extender-added-fields-translate.md @@ -5,9 +5,9 @@ fix(objectql): a field a dependent package adds through `objectExtensions` is served translated on `/api/v1/meta/object` -`SchemaRegistry.getPackagedObjectBase` (the packaged base that `/meta` translates an object against, and that the save door's translated-echo restore reads) now also carries each field a CODE `extend` contributor adds under a name the owner does not declare, as that extender ships it. A later extender's declaration of the same name replaces an earlier one, as in the fold. Before this change such a field counted as authored after the fact. Every non-default-locale read (`GET /api/v1/meta/object`, `GET /api/v1/meta/object/:name`, the list read, the form routes) then served its `label`, help text and option labels in the source language, even when the extender's own translation pack carried them. These reads now serve the pack's translation for those fields. A Studio save of such a read stores the source text again. Default-locale reads are unchanged. +`SchemaRegistry.getPackagedObjectBase` (the packaged base that `/meta` translates an object against, and that the save door's translated-echo restore reads) now also carries each field a CODE `extend` contributor adds under a name the owner does not declare, as that extender ships it. A later extender's declaration of the same name replaces an earlier one, as in the fold, and a disabled package's extension adds nothing, as the fold withholds it. Before this change such a field counted as authored after the fact. Every non-default-locale read (`GET /api/v1/meta/object`, `GET /api/v1/meta/object/:name`, the list read, the form routes) then served its `label`, help text and option labels in the source language, even when the extender's own translation pack carried them. These reads now serve the pack's translation for those fields. A Studio save of such a read stores the source text again. Default-locale reads are unchanged. -Unchanged: the object scalars, every field the owner declares (including one an extender redeclares), and an extender's `fieldPatches` all stay the owner's. A patched label or description still keeps its text in every language. Fields added by a tenant overlay or a stored (`_provenance: 'org'`) extension, the `.custom` pair's included, still count as authored after the fact. `@objectstack/spec` changes only in doc comments (`TranslateDocumentOptions.packagedBase` and `translateObject`). +Unchanged: the object scalars, every field the owner declares (including one an extender redeclares), and an extender's `fieldPatches` all stay the owner's. A patched label or description still keeps its text in every language. Fields added by a tenant overlay or by an extension of tenant provenance (`_provenance: 'org'`), the `.custom` pair's included, still count as authored after the fact. `@objectstack/spec` changes only in doc comments (`TranslateDocumentOptions.packagedBase` and `translateObject`). Clause-②: no Metadata-protocol: none