6868 * `isUnlisted`). A body table (`isPrimary`) is the field groups' to place
6969 * and is kept, after the listed ones, with no tab of its own (no
7070 * `keepsTab`) unless an entry names it. Undeclared or empty: every list, as
71- * before. The three built-in tab names (`RECORD_PAGE_BUILTIN_TABS` in
71+ * before. A side list ANOTHER package brings (the child and the parent
72+ * belong to different packages, objectstack#35901) is the exception: the
73+ * declared list does not hide it; that package places it (the server
74+ * splices its `place` into `relatedLists`), and an unplaced one is kept
75+ * after the listed ones, so the page draws it at the end of the tabs.
76+ * The three built-in tab names (`RECORD_PAGE_BUILTIN_TABS` in
7277 * `@objectstack/spec/data`) name the page's own tabs, never a child list;
7378 * the synthesized page places those (`buildDefaultTabs`).
7479 * - An entry's own TITLE and COLUMNS (objectstack#35899): the object form
@@ -197,9 +202,19 @@ export interface DerivedRelatedList {
197202 * True when the parent DECLARES `relatedLists` and no entry names this side
198203 * list (objectstack#35897), so the record page shows no tab for it — present
199204 * only when the caller asked for hidden relationships
200- * ({@link DeriveRelatedListsOptions.includeHidden}), as `isHidden` is.
205+ * ({@link DeriveRelatedListsOptions.includeHidden}), as `isHidden` is. Never
206+ * on a list another package brings (objectstack#35901): that one shows.
201207 */
202208 isUnlisted ?: true ;
209+ /**
210+ * The package the child object belongs to, when it is another package than
211+ * the parent's (objectstack#35901): a list that package brings, which the
212+ * parent's `relatedLists` does not hide and the package places itself.
213+ * Present only for the authoring surface
214+ * ({@link DeriveRelatedListsOptions.includeHidden}), which shows it read-only
215+ * with its source.
216+ */
217+ fromPackage ?: string ;
203218}
204219
205220/**
@@ -261,6 +276,34 @@ interface MergedObjectLike {
261276 * records can never be read on any record page.
262277 */
263278 enable ?: { apiEnabled ?: boolean } ;
279+ /**
280+ * The package that owns the object, as the server serves it (the registry
281+ * stamps its owner's package id; `'sys_metadata'` marks a definition bound
282+ * to no package). Read to tell a child list another package brings
283+ * (objectstack#35901).
284+ */
285+ _packageId ?: unknown ;
286+ }
287+
288+ /** The package an object belongs to, or `undefined` for none (absent, empty, or bound to no package). */
289+ function packageOf ( object : MergedObjectLike | null | undefined ) : string | undefined {
290+ const id = object ?. _packageId ;
291+ return typeof id === 'string' && id !== '' && id !== NO_PACKAGE ? id : undefined ;
292+ }
293+
294+ /** The `_packageId` the server stamps on a definition bound to no package. */
295+ const NO_PACKAGE = 'sys_metadata' ;
296+
297+ /**
298+ * objectstack#35901 — does `child` come from another package than `parent`?
299+ * Both must belong to a package, and the two differ. A child of the parent's
300+ * own package, or one no package owns, is not: those stay the parent's to
301+ * list (objectstack#35897).
302+ */
303+ function isOtherPackageChild ( child : MergedObjectLike , parent : MergedObjectLike ) : boolean {
304+ const childPackage = packageOf ( child ) ;
305+ const parentPackage = packageOf ( parent ) ;
306+ return childPackage !== undefined && parentPackage !== undefined && childPackage !== parentPackage ;
264307}
265308
266309/**
@@ -429,7 +472,7 @@ export function deriveRelatedLists(
429472 // Working entries carry the FK label and the list's name so we can
430473 // disambiguate multi-FK children after the full sweep; both are stripped
431474 // from the returned descriptors.
432- type Working = DerivedRelatedList & { _fkLabel : string ; _listLabel : string } ;
475+ type Working = DerivedRelatedList & { _fkLabel : string ; _listLabel : string ; _otherPackage : boolean } ;
433476 const owned : Working [ ] = [ ] ;
434477 const referenced : Working [ ] = [ ] ;
435478
@@ -454,6 +497,8 @@ export function deriveRelatedLists(
454497 // rather than once per FK.
455498 const inheritedSort = inheritedListViewSort ( child . list ) ;
456499 const childLabel = child . label || child . name ;
500+ // objectstack#35901 — a list another package brings is not the parent's to hide.
501+ const otherPackage = isOtherPackageChild ( child , objectDef ) ;
457502 const childListLabel = ( listLabel && listLabel ( child as MergedObjectLike & { name : string } ) ) || childLabel ;
458503 for ( const [ fieldName , fieldDef ] of fieldEntries ( child . fields ) ) {
459504 if ( ! fieldDef ) continue ;
@@ -492,6 +537,8 @@ export function deriveRelatedLists(
492537 ...( hidden ? { isHidden : true as const } : { } ) ,
493538 _fkLabel : ( typeof fieldDef . label === 'string' && fieldDef . label ) || fieldName ,
494539 _listLabel : childListLabel ,
540+ _otherPackage : otherPackage ,
541+ ...( otherPackage && options ?. includeHidden ? { fromPackage : packageOf ( child ) } : { } ) ,
495542 ...( typeof fieldDef . relatedListTitle === 'string' && fieldDef . relatedListTitle
496543 ? { title : fieldDef . relatedListTitle }
497544 : { } ) ,
@@ -537,6 +584,14 @@ export function deriveRelatedLists(
537584 if ( list . isPrimary ) {
538585 const { keepsTab : _unlistedTab , ...bodyOnly } = list ;
539586 all . push ( bodyOnly ) ;
587+ } else if ( list . _otherPackage ) {
588+ // objectstack#35901 — a side list another package brings is not
589+ // hidden by the parent's list: that package places it with its object
590+ // extension's `place` (which the server splices into `relatedLists`,
591+ // so a placed one is named above); unplaced, it shows at the end of
592+ // the tabs (`arrangeDeclaredTabs`). Sales ruling 7073014077 flips the
593+ // hiding objectstack#35897 shipped (ruling 7072511859).
594+ all . push ( list ) ;
540595 } else if ( options ?. includeHidden ) all . push ( { ...list , isUnlisted : true } ) ;
541596 continue ;
542597 }
@@ -557,7 +612,7 @@ export function deriveRelatedLists(
557612 const counts : Record < string , number > = { } ;
558613 for ( const r of all ) counts [ r . childObject ] = ( counts [ r . childObject ] || 0 ) + 1 ;
559614
560- return all . map ( ( { _fkLabel, _listLabel, ...rest } ) => {
615+ return all . map ( ( { _fkLabel, _listLabel, _otherPackage , ...rest } ) => {
561616 if ( ! rest . title && counts [ rest . childObject ] > 1 ) {
562617 return { ...rest , title : `${ _listLabel } · ${ _fkLabel } ` } ;
563618 }
0 commit comments