Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions .changeset/36498-custom-package-arrangement.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
---
'@objectstack/spec': minor
'@objectstack/objectql': minor
'@objectstack/metadata-protocol': minor
'@objectstack/cli': minor
'@objectstack/cloud-connection': minor
'@objectstack/lint': minor
'@object-ui/app-shell': minor
'@object-ui/plugin-detail': minor
---

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)

Clause-②: yes (widening)
Metadata-protocol: added

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:

```ts
objectExtensions: [{
extend: 'crm_lead',
fields: { region__c: { type: 'text', label: 'Region' } },
// The whole field arrangement: the two groups swapped, `status` moved.
fieldGroups: [
{ key: 'contact', label: 'Contact', fields: ['email', 'phone', 'status'] },
{ key: 'basic', label: 'Basics', fields: ['name', 'company', 'region__c'] },
],
// The whole tab list: events before tasks, the notes tab hidden.
relatedLists: ['crm_event', 'crm_task', { list: 'crm_note', hidden: true }],
}],
```

- **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`.
- **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.
- **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.
- **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.
- **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.
- **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.
- **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.
- **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.
- **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.
- **`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.

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.
93 changes: 89 additions & 4 deletions content/docs/data-modeling/object-extensions.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ check that spelling first.
| `pluralLabel` | Same as `label`. |
| `description` | Same as `label`. |
| `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). |
| `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. |
| `priority` | Not merged — it *orders* the merge. `0`–`999`, default `200`. |

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

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

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

| Key you might reach for | Declare this instead |
|:---|:---|
| `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 |
| `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 |
| `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 |
| `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) |
| `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 |
| `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) |
| `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 |

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

{/* os:check */}
```typescript
Expand All @@ -295,6 +300,86 @@ export default defineStack({
});
```

### Arranging the whole record page

A record page is arranged in three layers, and each has its own way to say where things go:

| Layer | What it writes | Scope |
|:---|:---|:---|
| The package that owns the object | `fieldGroups` and `relatedLists` on the object | The whole arrangement |
| A package that extends it | `place` on its extension | Only the fields, groups and child lists it brings |
| The environment, in the base's paired `.custom` package | `fieldGroups` and `relatedLists` on its extension | The whole arrangement, over both layers above |

So on an installed object the customer may move a vendor field to another group, reorder
the groups, and reorder or hide tabs, without touching the vendor's package:

{/* os:check */}
```typescript
import { defineObjectExtension, Field } from '@objectstack/spec/data';

export const LeadPageExtension = defineObjectExtension({
extend: 'crm_lead',
fields: { region__c: Field.text({ label: 'Region' }) },
// The whole field arrangement: the two groups swapped, `status` moved to `contact`.
fieldGroups: [
{ key: 'contact', label: 'Contact', fields: ['email', 'phone', 'status'] },
{ key: 'basic', label: 'Basics', fields: ['name', 'company', 'region__c'] },
],
// The whole tab list: events before tasks, the notes tab hidden.
relatedLists: ['crm_event', 'crm_task', { list: 'crm_note', hidden: true }],
});
```

Both keys take the shape an object declares them in ([field groups](/docs/data-modeling/objects),
`relatedLists`), and a group may list any field the object has, whoever declares it: the
vendor's, another package's extension's, the pair's own `__c` fields. A group's
`relatedList` may place any body table.

- **Each key replaces, whole.** Written, `fieldGroups` replaces the groups the owner
declares and the other extensions' `place` entries add to; `relatedLists` replaces the
tab list the same way. 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 alone.
- **A field the arrangement does not list is never dropped.** It shows after the last
group, whatever group its owner or another extension had put it in: a field a later
version of the base adds, or one a package installed later brings, appears there until
the arrangement lists it. A group that lists `fields` shows exactly its list.
- **A tab the arrangement does not name still shows, after the listed ones.** That 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 the list, and a bare child name hides every list of that child. `hidden` is
accepted only here; an object's own `relatedLists` refuses it. A list the object's owner
hides by leaving it out of its own `relatedLists` stays hidden until the arrangement
names it. The three built-in tabs are written as their bare names and keep their own
rules; they are not hidden here.
- **A reader's own tab order comes on top.** Each person's dragged order and hidden tabs
(kept per user) are laid over this list, as they are over an object's. A tab the
environment hides is not offered to them.
- **Taking it away restores the page.** Remove a key, or uninstall or disable the pair,
and the owner's arrangement with the placements is served again. Nothing is rewritten in
the base or in another package.
- **Only the pair writes these keys.** In a package that is not a `.custom` package they
are refused at save and publish, by `os validate` and `os build`, and at install, with
the prescription to use `place`. Within one extension, a `place` entry beside the key
that would replace it is refused too: list the item in the arrangement instead.
- **The pair is the App's.** An object's pair is the `.custom` package of the App the
object belongs to: for an object a module of an App owns, that is 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. What any other
`.custom` package writes under these keys is not refused at those doors; it is not
applied, alone or beside the pair, and the boot log names the package and the object.
- **Hiding a field is written in the arrangement.** `hidden` 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 it is more than display. To keep a vendor field off
the record page and the forms, list it in a group whose `visibleWhen` is false:
`{ key: 'off_page', label: 'Not shown', fields: ['fax'], visibleWhen: 'false' }`.
Two limits:
- **It 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: the save is refused naming a field the user cannot see.

---

## Merge order and conflicts
Expand Down
Loading
Loading