Skip to content

Commit 45ef94e

Browse files
feat(spec): the paired .custom package declares an installed object's field-group and tab arrangement (#36517)
<!-- claude-projects-attribution: {"github_login":"os-steve"} --> _Requested by **Steve** · [project thread](https://claude.ai/code/project/chan_01FdL1XeUyvVNxLreh3F4Qi9?thread=cmsg_01FdL1XeUyvVNxLreh3F4Qi9JpRoUZGqtwqMU5k7b4C58D)_ Fixes #36498 Clause-②: yes (widening) Metadata-protocol: added Skills-docs: follow-up #36541 ## 维护者速读 - 环境管理员可以给已安装软件包里的对象整体重排记录页:把原厂字段挪到别的分组、调换分组顺序、调换或隐藏子表页签;不写这份排布,页面和以前完全一样。 - 属于「记录页标签与分组」专题的第三层(原始软件包、继承软件包之后的环境管理员覆盖),让客户不改原厂包也能按自己的习惯排页面。 - 排错了只影响这一个对象的记录页、表单和预览的摆放,数据不受影响,但把没有默认值的必填字段藏起来会让用户在表单里建不了记录;删掉这份排布或停用环境定制包,页面立刻回到原厂加扩展包的样子。 - 审批这次公开配置格式的新增:对象扩展多了两项只有环境定制包能写的排布设置。 ## What changes The record page is arranged in three layers. The package that owns an object declares `fieldGroups` and `relatedLists`; a package that extends it places what it brings with `place`; this PR adds the third: the object extension of the paired `.custom` package may declare the whole arrangement, over both. **Spec keys touched** (`packages/spec/src/data/object.zod.ts`, `related-list-entry.ts`, `field-customization.ts`, `kernel/metadata-read-decorations.ts`): | Key | Change | |:---|:---| | `ObjectExtensionSchema.fieldGroups` | New. An array of `ObjectFieldGroupSchema`, the shape an object's `fieldGroups` takes; keys unique. Was refused at parse with a prescription naming `place`. | | `ObjectExtensionSchema.relatedLists` | New. An array of `ObjectExtensionRelatedListEntrySchema`: a bare name (a child, a relationship, or one of the three built-in tab names) or `{ list, label?, columns?, hidden? }`. Was refused at parse the same way. | | `ObjectExtensionRelatedListEntryObjectSchema.hidden` | New, on this entry only. `RelatedListEntryObjectSchema` (an object's own entry) still refuses `hidden`, now with a sentence saying where it belongs. | | `METADATA_READ_DECORATIONS` | `_relatedListsArrangement` added: derived on read, stripped on write, never authorable. | | `BASE_FIELD_DISPLAY_WHITELIST` | Unchanged (see `hidden`, below). | New exports: `CUSTOM_ARRANGEMENT_KEYS`, `extensionArrangementKeys`, `relatedListEntryHidden`, `relatedListNameCovers`, `RELATED_LISTS_ARRANGEMENT_DECORATION`, `RelatedListsArrangement`, `readRelatedListsArrangement`, the two entry schemas and their types. **Who may write them.** The schema admits the keys on any extension, because a parse does not know the writing package. The writer is judged where the package is known, by one judge (`judgeExtensionArrangement`, `packages/metadata-protocol/src/protocol-extension-arrangement.ts`) on the `__c` precedent's predicate (`isCustomizationPackage`), at the same doors as the `__c` reservation: - save, publish and restore of an `object_extension` item (`objectExtensionItemRefusal`): `VALIDATION_ERROR` / 400, one issue per key; - `os validate` and `os build` (`findExtensionArrangementRefusals`, in the validate/build parity roster); - marketplace install (`marketplace-install-local-plugin.ts`): `VALIDATION_ERROR` / 422 with `details.refusals`. Each refusal names the key, the object and the package and prescribes `place` with an example entry. An extension that reaches the registry past those doors is skipped by the fold and named in the boot log. **Which `.custom` package is served.** The doors judge by the suffix; the fold decides by role. It serves only the object's own pair: the `.custom` package of the App the object belongs to, asked of `pairsOf` over the installed manifests (`packages/metadata-core/src/customization-pair-lookup.ts`, the list `isPairOf` tests against). That list is the App's pair first and then, while one is installed, a per-package pair an earlier version created. A `.custom` writer outside the list is skipped and named in the boot log, alone or beside the pair. Where both listed pairs write one key, the App's pair is served and the other is named. Fold order decides nothing (ADR-0146 D2). **The merge** (`packages/objectql/src/registry-custom-arrangement.ts`, wired into `foldExtendersOntoDefinition` after `applyExtensionPlacements`): the owner's arrangement, then every extension's `place`, then the `.custom` key replaces the result, whole. A key the extension does not write keeps the result of the first two steps. Nothing is merged entry by entry. - Fields: a field no group lists is not dropped; it shows after the last group. A group that lists `fields` shows exactly its list, so a field of the owner or of another extension that no list names loses a `group` naming such a group, and a listed field's own `group` follows the group that lists it. The served object still passes an object parse. - Tabs: the served `relatedLists` is the arrangement's shown entries, then the entries of the list it replaced that it does not name (before a trailing approvals / activity-stream run). `{ list, hidden: true }` hides that list, whichever package brings it. What a served `relatedLists` cannot say travels in the `_relatedListsArrangement` read decoration (`{ packageId, hidden, unlisted }`), stamped on the served by-name read and the served object list, not on the execution face. Where the arrangement hides every tab of a declared list, the served list is empty and `unlisted: 'hidden'` beside it says it is still a declared list. - Removing a key, or uninstalling or disabling the `.custom` package, serves the first two steps again. Nothing is stored in the base or in another package. **The record page** (`ui/packages/app-shell/src/utils/deriveRelatedLists.ts`, `ui/packages/plugin-detail/src/synth/buildDefaultPageSchema.ts`): both readers read the decoration through `readRelatedListsArrangement`. A list the environment hides is not derived; where the arrangement replaced the automatic tab list, a list no entry names still shows after the listed ones, and so does the attachments tab. An empty served list beside `unlisted: 'hidden'` is read as a declared list that names nothing, so a list the owner hid by leaving it out stays hidden. With no decoration served, both answer exactly as before; each reader's suite ends with a block that pins that against literal values. **`hidden` on a field did not enter `BASE_FIELD_DISPLAY_WHITELIST`.** The whitelist's admission test is "display only: never changes what is stored, validated or computed". `FieldSchema.hidden` fails it on three counts: a hidden field is left out of the search companion column (the stored value changes), a form's required check skips it (`required && hidden !== true`, the validation verdict changes), and default search and export columns drop it. So the whitelist is not widened. The explicit arrangement form is a `.custom` field group whose `visibleWhen` is false: `{ key: 'off_page', label: 'Not shown', fields: ['fax'], visibleWhen: 'false' }` keeps a vendor field off the record page and the forms. Two limits, now stated in the key's description, the whitelist's doc comment, the docs page and the changeset: - It is presentation only, not access control: the field stays readable and writable through the API. - It is not for a `required` field that has no default: the create form no longer shows the field while the save still requires it, so the form cannot be submitted. **The per-user tab order still layers on top.** The console keeps each reader's tab order and hidden tabs as a diff over the host's default order (`ui/packages/plugin-detail/src/synth/relatedArrangement.ts`), and the default order is `deriveRelatedLists` over the served object. The environment layer is in the served object, so the reader's order is laid over it unchanged. A list the environment hides is not derived, so a reader's saved arrangement cannot bring it back. **Docs and changeset**: `content/docs/data-modeling/object-extensions.mdx` gains "Arranging the whole record page"; `.changeset/36498-custom-package-arrangement.md` (`minor` on the eight packages moved). The changeset no longer says a non-`.custom` writer is refused on every path: where no door judges it, the key is not applied and the boot log names it. ## Tests The acceptance bullets of the card are reproduced over a base + extension package + `.custom` fixture (`com.vendor.crm`, `com.acme.tax`, `com.vendor.crm.custom`, object `crm_lead`), and the App pair over two installed packages in the HotCRM shape (an App `com.hotcrm` and a module of it, `com.hotcrm.sales`, that owns the object); HotCRM itself is not edited. | Suite | What it pins | |:---|:---| | `packages/objectql/src/registry-custom-arrangement.test.ts` | A base field moved to another group and two groups swapped; an unlisted base field after the last group, in both membership spellings; an extension package's placed field not in the arrangement still shows, last; two tabs swapped and one hidden; an unlisted tab shows last; every tab of a declared list hidden (the owner lists two of its three lists, the arrangement hides both; and the one-entry case): the served list is empty and the read says `unlisted: 'hidden'`; only `relatedLists` written keeps the groups of the first two steps; removing both keys, uninstalling and disabling the pair each restore; a non-`.custom` writer is skipped with a boot-log line naming `place`; a `.custom` package that is not the object's pair is skipped and named, beside the pair and alone; an object a module owns with two `.custom` writers, in both fold orders: the App's pair is served and the other named; an installed per-package pair is read, and comes second to the App's pair; re-fold idempotence. The layout is asserted through `deriveFieldGroupLayout`, the derivation the record page, the forms and the preview share. | | `packages/objectql/src/protocol-custom-arrangement.test.ts` | Through the real protocol and engine: the pair's save is admitted; the by-name and list reads serve the arrangement and the decoration; the execution face is undecorated; a writable non-`.custom` package's save is refused once (`VALIDATION_ERROR` / 400, `place` named), nothing stored; re-saving without the keys and disabling the pair restore. | | `packages/metadata-protocol/src/protocol-extension-arrangement.test.ts` | The judge and the publish-door refusal, with the `.custom` control. | | `packages/cli/test/validate-build-extension-arrangement.test.ts`, `packages/cli/src/utils/extension-arrangement.test.ts` | `os validate` and `os build` each refuse once and name `place`; the `.custom` control passes; the parity roster row. | | `packages/cloud-connection/src/marketplace-install-local-extension-arrangement.test.ts` | Install refuses once (422, `details.refusals`), nothing installed; the `.custom` control installs. | | `packages/spec/src/data/object-extension-arrangement.test.ts`, `object-extension-place.test.ts` | The two keys' shapes and refusals, `hidden` accepted on the extension entry only, the contradiction and `place`-beside-arrangement refusals, the whitelist unchanged. | | `ui/packages/app-shell/src/utils/__tests__/deriveRelatedLists.customArrangement-36498.test.ts`, `ui/packages/plugin-detail/src/synth/__tests__/buildDefaultPageSchema.customArrangement-36498.test.ts` | The reader: hidden lists, unlisted-shown, an empty served list beside `unlisted: 'hidden'` (the list the owner left out stays hidden; without the decoration the empty list reads as before), and the pin that nothing moves with no decoration served. | Readings at head `7052770cd`, this round (the review's three should-fix items). The first round's readings are in the first `os-dev-report` comment on the card. <details> <summary>Scoped suites</summary> At head `7052770cd`, tree clean, each run outside the shared verification lock, one at a time. - `pnpm --filter @objectstack/objectql exec vitest run --maxWorkers=2 src/registry-custom-arrangement.test.ts src/protocol-custom-arrangement.test.ts src/registry-extension-placement.test.ts`: exit 0, `Test Files 3 passed (3)`, `Tests 73 passed (73)`. The fold suite alone: `Tests 33 passed (33)`. - `pnpm --filter @objectstack/spec exec vitest run --maxWorkers=2 src/data/object-extension-arrangement.test.ts src/data/field-customization.test.ts src/data/related-list-entry.test.ts`: exit 0, `Test Files 3 passed (3)`, `Tests 158 passed (158)`. - `pnpm --filter @object-ui/app-shell exec vitest run --root ../.. --maxWorkers=2 packages/app-shell/src/utils/__tests__/deriveRelatedLists.customArrangement-36498.test.ts`: exit 0, `Tests 21 passed (21)`. - `pnpm --filter @object-ui/plugin-detail exec vitest run --root ../.. --maxWorkers=2 packages/plugin-detail/src/synth/__tests__/buildDefaultPageSchema.customArrangement-36498.test.ts`: exit 0, `Tests 10 passed (10)`. - `pnpm --dir ui exec vitest run --maxWorkers=2 scripts/`: exit 0, `Test Files 172 passed | 2 skipped (174)`, `Tests 5127 passed | 2 skipped (5129)`. - Before them: `pnpm --filter @objectstack/spec run check:generated --fix` rebuilt the spec and regenerated `content/docs/references/data/object.mdx` (the two descriptions), exit 0; the objectql dependency closure and objectql were built, exit 0. </details> <details> <summary>Ablation: each changed behaviour broken once, the suite turns red, the file restored</summary> Each leg goes through `node scripts/ablation-replace.mjs`: the anchor must hit once, the tool prints the blob before and after, the suite runs, the file is restored. After each leg the file's blob equals the one at `HEAD` and `git diff HEAD` is empty. All six ran at `7052770cd`. No build step is in a leg: each suite imports the mutated file from source. - Fold, the whole step switched off (`if (writers.size === 0)` to `>= 0`): `Tests 27 failed | 6 passed (33)`. - Fold, the pair test switched off (`if (!pairs.includes(packageId))` to a condition that never holds): `Tests 4 failed | 29 passed (33)`. The four: the `.custom` package that is not the pair, the module-owned object in both fold orders, and the `.custom` id named after the module. - Tab reader, the decoration not read (`readRelatedListsArrangement(objectDef)` to `(undefined)`): `Tests 11 failed | 10 passed (21)`. - Tab reader, the empty-list reading switched off (`unlisted === 'hidden'` to a value never served): `Tests 2 failed | 19 passed (21)`. The two are the new empty-list cases. - Page synthesis, the decoration not read: `Tests 3 failed | 7 passed (10)`. - Page synthesis, the empty-list reading switched off (`entries.length === 0 && unlistedTabs !== 'hidden'` to `entries.length === 0`): `Tests 1 failed | 9 passed (10)`. The one is the new empty-list case. - The door-judge leg of the first round was not re-run: no file it reads changed. </details> <details> <summary>Gates</summary> - `node scripts/pm/dispatch-gates.mjs --commands` at `7052770cd`: 131 commands derived from the branch's 46 changed paths. - 125 answered exit 0, run one at a time outside the lock. Among them the ratchets this round's files move: `pnpm check:facade-delegation-only` (`registry.ts` stays at its line ceiling: the one host line added is paid for by folding a doc line into a trailing comment), `pnpm check:registry-log-declared`, `pnpm check:test-source-alias`, `pnpm check:nul-bytes`, and the spec family (`check:generated`, `check:docs`, `check:api-surface`, `check:authorable-surface`, `check:export-origins`, `check:liveness`). - NOT MEASURED locally: `check:skill-examples`, `check:dual-build-cjs-loads`, `check:i18n`, `check:i18n-coverage`, `check:i18n-walk-parity`, reason: each answered exit 3, PREREQUISITE NOT MET. The worktree was rebuilt for this round with the spec and the objectql closure only, and these read the built output of the CLI and of other packages. The check-runs on this head are their reading. - The UI scripts suite is derived as `pnpm --dir ui exec vitest run scripts/`; it was run with `--maxWorkers=2` added (the bare spelling was killed for memory in the first round) and is counted under the scoped suites. - `node scripts/pm/dispatch-gates.mjs --ran`: `Run reconciliation — 131 derived, 125 run, 5 NOT-MEASURED, 1 UNRUN`; the one is the UI scripts suite under its derived spelling. - `node scripts/check-platform-checklist.mjs --changed-from origin/main`: exit 0, `7 anchored file(s) in the change set, 54 anchor(s) judged, 0 lost`. - Check-runs on `7052770cd`: 70 runs, 61 success, 9 skipped (opt-in, queue and schedule-only jobs), 0 failed. Test Core 10 of 10, Test UI 16 of 16, the Lint lanes, the Type Check lanes, Build Core, Check Changeset, Spec property liveness and Governed Surface Queue Guard are success. </details> ## Acceptance notes - **Contract review, first record: three should-fix items, each answered on this head.** - Hiding every tab of a declared list revealed the lists the owner hid. Answered in the readers' reading of the decoration, not in the served shape: the fold still serves an empty list, and `unlisted: 'hidden'` beside it now reads as a declared list that names nothing. This was the smaller change: the decoration's shape and the fold's output are as they were, and the documented rule (a list the owner hides by leaving it out stays hidden until the arrangement names it) now holds in the empty case too. Pinned in the fold suite and in both reader suites. - The choice among `.custom` writers did not know the App pair. The fold now asks `pairsOf`, never `isCustomizationPairOf`; the arm that served the writer folded last is gone. One call made here: an installed per-package pair of an earlier version is admitted, second to the App's pair, because the lookup module prescribes `isPairOf` / `pairsOf` for every read that serves a package's customizations. - The recipe for keeping a base field off the page now states its two limits in the four published places. - **Carriers of what this PR does not do:** - Item 6 of the card, the ADR-0146 D10 note: the row on #36086. An implementation PR does not edit `docs/adr/**`; the sentences this change puts out of step and their replacement wording are in the report. - The skills guide for the two keys: #36541. - Hiding a built-in tab (attachments, approvals, the activity stream) of an installed object from the environment's layer is not possible as built: `hidden` is for relationship entries, and an unlisted built-in tab shows. A separate finding, which the seat files. - Three paths where a non-`.custom` writer's key is only skipped with a boot-log line, where `main` refused it at parse: a code-defined stack that boots without `os validate` or `os build`; a stack that names no package id, which `os validate` passes; and package duplicate and orphan adoption. Nothing is applied on any of them. A follow-up, not a change on this head. - The save and install doors could also refuse a `.custom` writer that is not the object's pair: they can read the installed manifests, which the CLI door cannot. As built they judge by the suffix, and the fold skips such a writer with a boot-log line. A follow-up. - Editor UI for these keys: the follow-up card, not this PR. Studio shows the merged result because it reads the served object. - **Calls that stand as built:** - Fields: "replaced whole" is read for both membership spellings, so an unlisted field always lands after the last group, never inside a group its owner had named. - Tabs: a list the object's owner hides by leaving it out of its own `relatedLists` stays hidden until the arrangement names it; "unlisted shows last" applies to the tabs the first two steps showed. - A `place` entry beside the arrangement key that replaces it, in one extension, is refused at parse. - A name in a `.custom` arrangement that the object does not have (a field in a group's list, a tab entry) is not judged at `defineStack`, `os validate` or install. The layout derivation and the tab reader skip a name nothing answers to, as they do for an object's own arrangement, so a vendor upgrade that removes a field does not make the environment's next save fail. - **Overlap**: an open draft PR edits another region of `packages/spec/src/data/object.zod.ts` (field history defaults); the later lander merges main. - **Size**: 3,566 changed lines, over the 3000 changed-line human-merge threshold, so it lands as a Tier H surface does. ## Verification Read first, by risk: 1. `packages/objectql/src/registry-custom-arrangement.ts`, two hunks. `servedWriter`: a writer is admitted when its package is a `.custom` package and is in `pairsOf` of the object's owner, and the served one is chosen by its position in that list; this decides whose arrangement an installed object shows. The field hunk under `// ── fieldGroups`: it rewrites or removes a field's own `group` on the served copy (never on a stored body) so that a listing group shows exactly its list; this decides where an unlisted field lands. 2. `packages/spec/src/data/object.zod.ts`, the `ObjectExtensionSchema` hunk: the two `guidance` refusals are removed and the keys are admitted on every extension; the writer is refused at the doors instead. Check that every door a package's extension passes is listed above, and the two key descriptions against what the fold does. 3. `ui/packages/app-shell/src/utils/deriveRelatedLists.ts`, the `naming` line and the final loop: an empty served list beside `unlisted: 'hidden'` becomes an empty naming map, so the loop takes the declared arm and shows only what is named or brought by another package. `hiddenByArrangement` runs before the `!naming` early exit. All of it is inert when `readRelatedListsArrangement` answers `undefined`. Two-minute check, one command: ``` pnpm --filter @objectstack/objectql exec vitest run --maxWorkers=2 src/registry-custom-arrangement.test.ts ``` Expected: 33 cases pass; the case titles read as the card's acceptance bullets and the review's three items. 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01ADHkmRY38EZf38Yy3zthbY <!-- signed: repo:objectstack#2 · os-steve · session_01ADHkmRY38EZf38Yy3zthbY --> --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent f644321 commit 45ef94e

46 files changed

Lines changed: 3485 additions & 81 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
---
2+
'@objectstack/spec': minor
3+
'@objectstack/objectql': minor
4+
'@objectstack/metadata-protocol': minor
5+
'@objectstack/cli': minor
6+
'@objectstack/cloud-connection': minor
7+
'@objectstack/lint': minor
8+
'@object-ui/app-shell': minor
9+
'@object-ui/plugin-detail': minor
10+
---
11+
12+
feat(spec): a base's paired `.custom` package declares an installed object's whole field-group and tab arrangement (`fieldGroups`, `relatedLists` on its object extension)
13+
14+
Clause-②: yes (widening)
15+
Metadata-protocol: added
16+
17+
The record page is arranged in three layers. The package that owns an object declares its `fieldGroups` and `relatedLists`; a package that extends it places what it brings with `place`; and now the environment, in the base's paired `.custom` package, may declare the whole arrangement over both:
18+
19+
```ts
20+
objectExtensions: [{
21+
extend: 'crm_lead',
22+
fields: { region__c: { type: 'text', label: 'Region' } },
23+
// The whole field arrangement: the two groups swapped, `status` moved.
24+
fieldGroups: [
25+
{ key: 'contact', label: 'Contact', fields: ['email', 'phone', 'status'] },
26+
{ key: 'basic', label: 'Basics', fields: ['name', 'company', 'region__c'] },
27+
],
28+
// The whole tab list: events before tasks, the notes tab hidden.
29+
relatedLists: ['crm_event', 'crm_task', { list: 'crm_note', hidden: true }],
30+
}],
31+
```
32+
33+
- **Two new keys on an object extension, written only by a `.custom` package.** `fieldGroups` takes the shape an object's `fieldGroups` takes and may list any field the object has, whoever declares it; a group's `relatedList` may place any body table. `relatedLists` takes an object's entry shape (a bare name, the three built-in tab names, or `{ list, label?, columns? }`) plus `hidden`.
34+
- **Each key replaces, whole.** The registry applies it last: the owner's arrangement, then every extension's `place`, then the `.custom` key in place of the result. Nothing is merged entry by entry. A key the extension does not write keeps the owner's arrangement with the placements, so writing only `relatedLists` leaves the field groups as they were.
35+
- **A field the arrangement does not list is not dropped.** It shows after the last group, whichever group its owner or another extension had put it in. A group that lists `fields` shows exactly its list.
36+
- **A tab the arrangement does not name still shows, after the listed ones.** This is the reverse of an object's own `relatedLists`, where leaving a list out hides it. Hiding is written: `{ list: 'crm_note', hidden: true }` hides that list's tab, whichever package brings it. `hidden` is accepted only here; an object's own `relatedLists` refuses it and says where it belongs. A list the owner hides by leaving it out of its own `relatedLists` stays hidden until the arrangement names it. The built-in tabs keep their own rules and are not hidden here.
37+
- **A package that is not a `.custom` package writing either key is refused**, once at each door: saving or publishing the extension, `os validate` and `os build`, and installing the package (`VALIDATION_ERROR`; 400 at save and publish, 422 at install). Each refusal names the key, the object and the package and prescribes `place`. An extension that reaches the registry past those doors is not applied, and the boot log says so. Within one extension, a `place` entry beside the arrangement key that would replace it is refused at parse.
38+
- **Only the object's own pair is served.** The pair is the `.custom` package of the App the object belongs to: for an object a module of an App owns, the App's pair. A `.custom` package an earlier version created for the module itself is still read while it is installed; where both write a key, the App's pair is served. The choice is by role, never by load order. What any other `.custom` package writes under these keys is not refused at the doors; the registry does not apply it, alone or beside the pair, and the boot log names the package and the object.
39+
- **One merge, every reader.** The record page, the forms, the preview and Studio read the served object, so they show one arrangement. Removing a key, or uninstalling or disabling the `.custom` package, serves the owner's arrangement with the placements again.
40+
- **Served reads say what the reader cannot derive.** Where a `.custom` package writes `relatedLists`, the served object carries the read decoration `_relatedListsArrangement` (`{ packageId, hidden, unlisted }`): the lists the environment hides, and whether an unlisted list shows. The record page's tab reader and the default page synthesis read it; with no decoration served they answer exactly as before. A reader's own tab order (kept per user) is still laid over this list, and a tab the environment hides is not offered to them.
41+
- **A group the arrangement brings is a translation anchor.** `os validate`'s translation-reference rule reads an extension's `fieldGroups` too, so a bundle's `_sections` key for a group the `.custom` arrangement declares is not reported as naming nothing.
42+
- **`hidden` on a field is not a display property a `fieldPatches` entry may set.** A hidden field is also left out of the search index and out of a form's required check, so the display whitelist is not widened. To keep a vendor field off the record page and the forms, list it in a group whose `visibleWhen` is false. That is presentation only, not access control: the field stays readable and writable through the API. Do not use it for a `required` field that has no default: the create form no longer shows the field while the save still requires it, so the form cannot be submitted.
43+
44+
What to check in an app: nothing changes until a `.custom` package writes one of the two keys. A package other than a `.custom` one that wrote `fieldGroups` or `relatedLists` on an extension was refused at parse. It is now refused by the save, publish, install, `os validate` and `os build` doors, with the same prescription. Where none of those doors judges it (for example a code-defined stack that boots without `os validate` or `os build`, or a stack that names no package id), the key is not applied and the boot log names it, where the parse refused it before.

‎content/docs/data-modeling/object-extensions.mdx‎

Lines changed: 89 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ check that spelling first.
7070
| `pluralLabel` | Same as `label`. |
7171
| `description` | Same as `label`. |
7272
| `place` | **Applied once, after every extension's fields are merged.** Says where the fields, groups and child lists this extension brings go on the target — [below](#placing-what-you-bring). |
73+
| `fieldGroups`, `relatedLists` | **Only in a base's paired `.custom` package. Each replaces, whole.** The complete field arrangement and the complete tab list of the target, applied last — [below](#arranging-the-whole-record-page). In any other package they are refused, and `place` is the key to use. |
7374
| `priority` | Not merged — it *orders* the merge. `0`–`999`, default `200`. |
7475

7576
Added fields are ordinary fields, so everything on the
@@ -78,17 +79,19 @@ Added fields are ordinary fields, so everything on the
7879

7980
### What an extension may **not** contribute
8081

81-
The merge carries the nine keys above and nothing else. These five are not
82+
The merge carries the keys above and nothing else. The first three below are not
8283
"unsupported yet" — there is no slot for them to arrive through, and the schema rejects
83-
each one by name with the alternative to use instead:
84+
each one by name with the alternative to use instead. The last two are the paired
85+
`.custom` package's alone: in any other package the save, publish and install doors,
86+
`os validate` and `os build` refuse them, naming `place`:
8487

8588
| Key you might reach for | Declare this instead |
8689
|:---|:---|
8790
| `actions` | A top-level action with `objectName: '<target>'` in the same stack — it stays in the stack's top-level `actions`, and the engine's schema registry attaches it to the target object wherever the object is served, whichever package registers first; a target no loaded package registers fails the boot |
8891
| `hooks` | A top-level hook in the stack that defines the target object — a hook follows the ownership of its object, and `defineStack()` refuses a top-level hook bound to an object the stack does not define, an extended one included |
8992
| `listViews` | A top-level `view` in the stack that defines the target object — `defineStack()` refuses a top-level `view` whose `list` or `form` data source is an object the stack does not define, an extended one included |
90-
| `fieldGroups` | A `place` entry: `{ group: { key, label }, after: '<group>' }` adds a group of your own, and `{ field, group, after: '<field>' }` puts a field of yours into one of the target's groups — [below](#placing-what-you-bring) |
91-
| `relatedLists` | A `place` entry `{ list, after: '<tab>' }` for a child object of your own package that points at the target — [below](#placing-what-you-bring). The target's own tab list stays its owner's |
93+
| `fieldGroups` (outside a `.custom` package) | A `place` entry: `{ group: { key, label }, after: '<group>' }` adds a group of your own, and `{ field, group, after: '<field>' }` puts a field of yours into one of the target's groups — [below](#placing-what-you-bring) |
94+
| `relatedLists` (outside a `.custom` package) | A `place` entry `{ list, after: '<tab>' }` for a child object of your own package that points at the target — [below](#placing-what-you-bring). The target's own tab list stays its owner's, and the environment's |
9295

9396
The same holds for any other key: the extension schema is strict, so an unknown key
9497
fails at authoring time with a prescription rather than being dropped in silence.
@@ -272,6 +275,8 @@ D10). The object is extended, never replaced:
272275
pair on first use.
273276
- **An object takes no `overrides` declaration.** Declaring one on an object is refused,
274277
naming the extension as the route.
278+
- **The pair may arrange the whole record page.** Its extension, and no other package's,
279+
writes `fieldGroups` and `relatedLists` — [below](#arranging-the-whole-record-page).
275280

276281
{/* os:check */}
277282
```typescript
@@ -295,6 +300,86 @@ export default defineStack({
295300
});
296301
```
297302

303+
### Arranging the whole record page
304+
305+
A record page is arranged in three layers, and each has its own way to say where things go:
306+
307+
| Layer | What it writes | Scope |
308+
|:---|:---|:---|
309+
| The package that owns the object | `fieldGroups` and `relatedLists` on the object | The whole arrangement |
310+
| A package that extends it | `place` on its extension | Only the fields, groups and child lists it brings |
311+
| The environment, in the base's paired `.custom` package | `fieldGroups` and `relatedLists` on its extension | The whole arrangement, over both layers above |
312+
313+
So on an installed object the customer may move a vendor field to another group, reorder
314+
the groups, and reorder or hide tabs, without touching the vendor's package:
315+
316+
{/* os:check */}
317+
```typescript
318+
import { defineObjectExtension, Field } from '@objectstack/spec/data';
319+
320+
export const LeadPageExtension = defineObjectExtension({
321+
extend: 'crm_lead',
322+
fields: { region__c: Field.text({ label: 'Region' }) },
323+
// The whole field arrangement: the two groups swapped, `status` moved to `contact`.
324+
fieldGroups: [
325+
{ key: 'contact', label: 'Contact', fields: ['email', 'phone', 'status'] },
326+
{ key: 'basic', label: 'Basics', fields: ['name', 'company', 'region__c'] },
327+
],
328+
// The whole tab list: events before tasks, the notes tab hidden.
329+
relatedLists: ['crm_event', 'crm_task', { list: 'crm_note', hidden: true }],
330+
});
331+
```
332+
333+
Both keys take the shape an object declares them in ([field groups](/docs/data-modeling/objects),
334+
`relatedLists`), and a group may list any field the object has, whoever declares it: the
335+
vendor's, another package's extension's, the pair's own `__c` fields. A group's
336+
`relatedList` may place any body table.
337+
338+
- **Each key replaces, whole.** Written, `fieldGroups` replaces the groups the owner
339+
declares and the other extensions' `place` entries add to; `relatedLists` replaces the
340+
tab list the same way. Nothing is merged entry by entry. A key the extension does not
341+
write keeps the owner's arrangement with the placements, so writing only `relatedLists`
342+
leaves the field groups alone.
343+
- **A field the arrangement does not list is never dropped.** It shows after the last
344+
group, whatever group its owner or another extension had put it in: a field a later
345+
version of the base adds, or one a package installed later brings, appears there until
346+
the arrangement lists it. A group that lists `fields` shows exactly its list.
347+
- **A tab the arrangement does not name still shows, after the listed ones.** That is the
348+
reverse of an object's own `relatedLists`, where leaving a list out hides it. Hiding is
349+
written: `{ list: 'crm_note', hidden: true }` hides that list's tab, whichever package
350+
brings the list, and a bare child name hides every list of that child. `hidden` is
351+
accepted only here; an object's own `relatedLists` refuses it. A list the object's owner
352+
hides by leaving it out of its own `relatedLists` stays hidden until the arrangement
353+
names it. The three built-in tabs are written as their bare names and keep their own
354+
rules; they are not hidden here.
355+
- **A reader's own tab order comes on top.** Each person's dragged order and hidden tabs
356+
(kept per user) are laid over this list, as they are over an object's. A tab the
357+
environment hides is not offered to them.
358+
- **Taking it away restores the page.** Remove a key, or uninstall or disable the pair,
359+
and the owner's arrangement with the placements is served again. Nothing is rewritten in
360+
the base or in another package.
361+
- **Only the pair writes these keys.** In a package that is not a `.custom` package they
362+
are refused at save and publish, by `os validate` and `os build`, and at install, with
363+
the prescription to use `place`. Within one extension, a `place` entry beside the key
364+
that would replace it is refused too: list the item in the arrangement instead.
365+
- **The pair is the App's.** An object's pair is the `.custom` package of the App the
366+
object belongs to: for an object a module of an App owns, that is the App's pair. A
367+
`.custom` package an earlier version created for the module itself is still read while
368+
it is installed; where both write a key, the App's pair is served. What any other
369+
`.custom` package writes under these keys is not refused at those doors; it is not
370+
applied, alone or beside the pair, and the boot log names the package and the object.
371+
- **Hiding a field is written in the arrangement.** `hidden` is not a display property a
372+
`fieldPatches` entry may set: a hidden field is also left out of the search index and
373+
out of a form's required check, so it is more than display. To keep a vendor field off
374+
the record page and the forms, list it in a group whose `visibleWhen` is false:
375+
`{ key: 'off_page', label: 'Not shown', fields: ['fax'], visibleWhen: 'false' }`.
376+
Two limits:
377+
- **It is presentation only, not access control.** The field stays readable and writable
378+
through the API.
379+
- **Do not use it for a `required` field that has no default.** The create form no
380+
longer shows the field while the save still requires it, so the form cannot be
381+
submitted: the save is refused naming a field the user cannot see.
382+
298383
---
299384

300385
## Merge order and conflicts

0 commit comments

Comments
 (0)