Skip to content

Commit 6629372

Browse files
committed
feat(runtime): serve the nav contributions of the customizations read
readBaseContributions reads the navigation-contribution registry the served app's fold reads, for each app registered under the base: one entry per item with an id, the contribution's group when it names one, the disabled-package skip the fold applies, and the base and pair excluded through the shared stamp predicate. The spec nav arm drops its planned marker; docs regenerated. Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 8b347c0 commit 6629372

6 files changed

Lines changed: 107 additions & 57 deletions

File tree

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
---
2+
'@objectstack/runtime': patch
3+
'@objectstack/spec': patch
4+
---
5+
6+
feat(runtime): the customizations read serves the `nav` contributions: the navigation items other packages add to a base's apps
7+
8+
Clause-②: no
9+
Metadata-protocol: none
10+
11+
`GET /packages/:id/customizations` now lists, in `contributions`, the navigation items other installed packages add to the base's apps, each naming the package that adds them. Studio can draw those menu entries greyed with their source, as it already can for contributed fields and flows (ADR-0029 D7 as amended by ADR-0146 D3).
12+
13+
- **One entry per item.** Every item of a package's `navigationContributions` entry that declares an `id`, contributed to an app the base ships, is a `nav` entry: `{ kind: 'nav', app, group?, name, packageId }`. `group` is the group the contribution targets, when it targets one. A separator without an `id` is not an entry, and a contributed group's children ride inside it.
14+
- **The same answer the menu shows.** The entries come from the registry the served app's navigation fold reads, never a join on names. A disabled package's items are not listed, as the fold drops them, and they come back when it is enabled again. The base's own items and its `<base>.custom` pair's are not contributions, and no nav item gains a key.
15+
- **Order and counts.** The `field` and `flow` entries come first as before, then the `nav` entries by app, group (no group first), name and package. `counts.contributions` counts them all.
16+
17+
The spec's `nav` arm drops its `[PLANNED — not yet served]` marker, and the member's descriptions no longer say the kind is unserved. The schema accepts exactly what it accepted before.
18+
19+
Nothing to do for existing metadata. A client that read `contributions` and assumed only `field` and `flow` entries now also receives `nav` entries, which the declared schema already allowed.

‎content/docs/api/metadata-api.mdx‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,8 @@ never overridden; it is copied under a new name. What the reads then serve is in
110110
`POST /packages/hotcrm/ensure-customization` creates the pair when absent (Studio calls
111111
it on the first change), and `GET /packages/hotcrm/customizations` lists its overrides,
112112
extensions and switched-off items in one read, beside `contributions`: the fields (kind `field`)
113-
and flows (kind `flow`) other installed packages contribute to `hotcrm`'s objects, each entry
114-
naming its package. Its `nav` kind (a navigation item another package contributes to a
115-
`hotcrm` app) is declared and not yet served.
113+
and flows (kind `flow`) other installed packages contribute to `hotcrm`'s objects, and the
114+
navigation items (kind `nav`) they contribute to `hotcrm`'s apps, each entry naming its package.
116115

117116
**Body**: `{ type: "object", name: "account", item: { ... } }`
118117
**Response**: `{ success: true }`

‎content/docs/references/api/package-lifecycle.mdx‎

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,11 @@ declared a VERSION rollback against the live COMMIT-rollback path;
4343
`RollbackToPackageCommitResponseSchema` below is the true contract,
4444
authored after that retirement per the ruling's sequencing (3A).
4545

46-
Two members are not transcriptions but DECLARED AHEAD OF THEIR PRODUCER
47-
(ADR-0049), each describe opening `[PLANNED — not yet served]` until the
48-
change that serves it drops the marker: the `nav` arm of
49-
`GetPackageCustomizationsResponseSchema.contributions` (#27928) and
46+
One member is not a transcription but DECLARED AHEAD OF ITS PRODUCER
47+
(ADR-0049), its describe opening `[PLANNED — not yet served]` until the
48+
change that serves it drops the marker:
5049
`PackageExportManifestSchema.withheldMaps` (#28640 ruling ③A, served by
51-
#29342). Their own docblocks say what is not served yet.
50+
#29342). Its own docblock says what is not served yet.
5251

5352
<Callout type="info">
5453
**Source:** `packages/spec/src/api/package-lifecycle.zod.ts`
@@ -170,7 +169,7 @@ Per-package customization read request: the base package id, no query parameters
170169

171170
## GetPackageCustomizationsResponse
172171

173-
Per-package customization read: overrides, extensions and switched-off items of one installed base, and the fields, flows and (not yet served) navigation items other packages contribute to it.
172+
Per-package customization read: overrides, extensions and switched-off items of one installed base, and the fields, flows and navigation items other packages contribute to it.
174173

175174
### Properties
176175

@@ -180,7 +179,7 @@ Per-package customization read: overrides, extensions and switched-off items of
180179
| **overrides** | `{ type: string; name: string; member?: string; basedOn?: string; … }[]` | ✅ | Every ACTIVE item of the base's paired `<base>.custom` package that declares `overrides.package` = the base and that the effective read serves over the base's item of the same name: the rows the served-override predicate admits (a declaration from any other package, and an undeclared pair item, are not listed), minus the stored rows every read declines (a shipped flow name). Ordered by type, name and member. |
181180
| **extensions** | `{ object: string; kind: Enum<'field' \| 'validation' \| 'index'>; name?: string; fields?: string[] }[]` | ✅ | Every field, validation rule and index the paired `<base>.custom` package declares in an object extension (`objectExtensions`) of an object the base owns, one entry per member, as the extension declares it. Ordered by object, kind and name. |
182181
| **switchedOff** | `{ type: string; name: string }[]` | ✅ | Every activation-ledger row (`sys_metadata_activation`) that records the base as its package and `active: false`: the base's items this deployment switched off. Ordered by type and name. |
183-
| **contributions** | `({ kind: Enum<'field' \| 'flow'>; object: string; name: string; packageId: string } \| { kind: 'nav'; app: string; group?: string; name: string; … })[]` | ✅ | Every field, flow and navigation item another installed package contributes to the base, one entry per item and contributing package: the fields of every object extension of an object the base owns, from any package but the base and its pair; every flow registered under such a package whose trigger object the base owns (a flow of a disabled package is not served, so not listed); and, declared ahead of its producer and not yet served, every navigation item such a package contributes to an app the base owns. The entry shape is per `kind`: `object` for `field` and `flow`, `app` and an optional `group` for `nav`. Ordered: the `field` and `flow` entries first, by object, kind, name and package; then the `nav` entries, by app, group (an entry with no group first), name and package. |
182+
| **contributions** | `({ kind: Enum<'field' \| 'flow'>; object: string; name: string; packageId: string } \| { kind: 'nav'; app: string; group?: string; name: string; … })[]` | ✅ | Every field, flow and navigation item another installed package contributes to the base, one entry per item and contributing package: the fields of every object extension of an object the base owns, from any package but the base and its pair; every flow registered under such a package whose trigger object the base owns (a flow of a disabled package is not served, so not listed); and every navigation item such a package contributes to an app the base owns (a disabled package's are not listed). The entry shape is per `kind`: `object` for `field` and `flow`, `app` and an optional `group` for `nav`. Ordered: the `field` and `flow` entries first, by object, kind, name and package; then the `nav` entries, by app, group (an entry with no group first), name and package. |
184183
| **counts** | `{ overrides: integer; extensions: integer; switchedOff: integer; contributions: integer }` | ✅ | Each list's length, derived from the lists in this same answer. |
185184

186185
### Nested Shape: `GetPackageCustomizationsResponse.overrides[number]`
@@ -222,7 +221,7 @@ A field or flow another package contributes to one of the base's objects.
222221

223222
### Nested Shape: `GetPackageCustomizationsResponse.contributions[number][option 2]`
224223

225-
[PLANNED — not yet served] Declared ahead of its producer (ADR-0049): the read lists no `nav` entry yet. A navigation item another installed package contributes to an app the base owns, one entry per item of the contribution's `items` (a contributed group's children ride inside it and are not entries of their own), read from the same contribution registry the served app's navigation fold reads (ADR-0029 D7). An item that declares no `id` (a separator may omit it) has no `name` to give and is not an entry. A disabled package's contributions are not listed, as the fold drops them.
224+
A navigation item another installed package contributes to an app the base owns, one entry per item of the contribution's `items` (a contributed group's children ride inside it and are not entries of their own), read from the same contribution registry the served app's navigation fold reads (ADR-0029 D7). An item that declares no `id` (a separator may omit it) has no `name` to give and is not an entry. A disabled package's contributions are not listed, as the fold drops them.
226225

227226
| Property | Type | Required | Description |
228227
| :--- | :--- | :--- | :--- |

‎packages/runtime/src/domains/packages.ts‎

Lines changed: 56 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3251,7 +3251,8 @@ async function readPackageCustomizations(
32513251
* [#28722, ADR-0029 D7 as amended by ADR-0146 D3] The `contributions` of
32523252
* `GET /packages/:id/customizations`: every field and flow a package other than
32533253
* the base `baseId` and its pair `pairId` contributes to an object the base
3254-
* OWNS (`getObjectOwner`), each entry naming that package. Read from the two
3254+
* OWNS (`getObjectOwner`), and every navigation item such a package contributes
3255+
* to an app the base owns, each entry naming that package. Read from the three
32553256
* registries that already record the contributor, never inferred:
32563257
*
32573258
* - **field** — the object registry's `extend` contributors of the object, as
@@ -3264,27 +3265,40 @@ async function readPackageCustomizations(
32643265
* already leaves a disabled package's out), whose `start` node's
32653266
* `config.objectName` is a base-owned object, attributed to the package
32663267
* stamp the registration put on it (its `_packageId`).
3267-
*
3268-
* Both kinds ask ONE question of their stamp, {@link codePackageOf}: is it a
3268+
* - **nav** — [#27928, ruling 6566915346 letter E] the navigation-contribution
3269+
* registry (`getAppNavContributions`), the one the served app's fold
3270+
* (`applyNavContributions`) reads, for every app registered under the base
3271+
* (`listItems('app', baseId)`, which already leaves a disabled base's app
3272+
* out: nothing is served to contribute to). One entry per item of a
3273+
* contribution's `items` that declares an `id`, naming the contribution's
3274+
* `group` when it targets one; a contributed group's children ride inside
3275+
* it, as the fold folds them. A disabled package's contributions are
3276+
* skipped by the fold's own predicate (`isPackageDisabled`, #28117), so the
3277+
* list and the served navigation agree. No key is read from or written to
3278+
* any nav item.
3279+
*
3280+
* Every kind asks ONE question of its stamp, {@link codePackageOf}: is it a
32693281
* code package's ({@link isCodeArtifactBody}: not the package-less
32703282
* `sys_metadata` sentinel, not a tenant-authored body), and neither the base
32713283
* nor its pair? Only where the stamp is read differs: the contributor's
3272-
* `packageId` beside its `definition`, or the flow's own `_packageId`. An item
3273-
* authored in this environment is the environment's, not a package's, and is
3274-
* not listed, whichever kind it is.
3284+
* `packageId` beside its `definition`, the flow's own `_packageId`, or the
3285+
* nav contribution's `packageId`. An item authored in this environment is the
3286+
* environment's, not a package's, and is not listed, whichever kind it is.
32753287
*
3276-
* Ordered by object, kind, name and package.
3288+
* Ordered as the member declares: the `field` and `flow` entries first, by
3289+
* object, kind, name and package; then the `nav` entries, by app, group (an
3290+
* entry with no group first), name and package.
32773291
*/
32783292
function readBaseContributions(
32793293
baseId: string,
32803294
pairId: string | undefined,
32813295
registry: any,
32823296
): GetPackageCustomizationsResponse['contributions'] {
3283-
// The `field` and `flow` entries: the `nav` kind is declared in the spec
3284-
// ahead of this producer (#27928) and is not listed here yet (#28722).
3285-
type Contribution = Exclude<GetPackageCustomizationsResponse['contributions'][number], { kind: 'nav' }>;
3286-
const contributions: Contribution[] = [];
3287-
if (typeof registry?.getAllObjects !== 'function') return contributions;
3297+
type Contribution = GetPackageCustomizationsResponse['contributions'][number];
3298+
type ObjectContribution = Exclude<Contribution, { kind: 'nav' }>;
3299+
type NavContribution = Extract<Contribution, { kind: 'nav' }>;
3300+
const contributions: ObjectContribution[] = [];
3301+
const navs: NavContribution[] = [];
32883302
// The one stamp reading both kinds share: the package `packageId` names
32893303
// when `body` is a code package's item and the package is neither the base
32903304
// nor its pair; `undefined` otherwise.
@@ -3295,7 +3309,7 @@ function readBaseContributions(
32953309
};
32963310

32973311
const owned = new Set<string>();
3298-
for (const object of registry.getAllObjects(baseId) as Array<{ name?: unknown }>) {
3312+
for (const object of (typeof registry?.getAllObjects === 'function' ? registry.getAllObjects(baseId) : []) as Array<{ name?: unknown }>) {
32993313
const name = object?.name;
33003314
if (typeof name === 'string' && registry.getObjectOwner(name)?.packageId === baseId) owned.add(name);
33013315
}
@@ -3324,11 +3338,39 @@ function readBaseContributions(
33243338
}
33253339
}
33263340

3341+
if (typeof registry?.listItems === 'function' && typeof registry.getAppNavContributions === 'function') {
3342+
const apps = new Set<string>();
3343+
for (const app of registry.listItems('app', baseId) as Array<{ name?: unknown }>) {
3344+
if (typeof app?.name === 'string') apps.add(app.name);
3345+
}
3346+
for (const app of apps) {
3347+
for (const contribution of registry.getAppNavContributions(app) as Array<{ packageId?: unknown; group?: unknown; items?: unknown }>) {
3348+
// [#28117] The fold's own predicate, asked per read as the fold asks it.
3349+
if (typeof registry.isPackageDisabled === 'function' && registry.isPackageDisabled(contribution.packageId)) continue;
3350+
const packageId = codePackageOf(contribution.packageId, undefined);
3351+
if (packageId === undefined) continue;
3352+
// The fold targets a group only when one is named (`if (c.group)`).
3353+
const group = typeof contribution.group === 'string' && contribution.group !== '' ? contribution.group : undefined;
3354+
for (const item of Array.isArray(contribution.items) ? contribution.items : []) {
3355+
const id = (item as { id?: unknown } | null | undefined)?.id;
3356+
if (typeof id !== 'string' || id === '') continue;
3357+
navs.push({ kind: 'nav', app, ...(group !== undefined ? { group } : {}), name: id, packageId });
3358+
}
3359+
}
3360+
}
3361+
}
3362+
33273363
const kindOrder = { field: 0, flow: 1 } as const;
3328-
return contributions.sort((a, b) => a.object.localeCompare(b.object)
3364+
contributions.sort((a, b) => a.object.localeCompare(b.object)
33293365
|| kindOrder[a.kind] - kindOrder[b.kind]
33303366
|| a.name.localeCompare(b.name)
33313367
|| a.packageId.localeCompare(b.packageId));
3368+
navs.sort((a, b) => a.app.localeCompare(b.app)
3369+
|| Number(a.group !== undefined) - Number(b.group !== undefined)
3370+
|| (a.group ?? '').localeCompare(b.group ?? '')
3371+
|| a.name.localeCompare(b.name)
3372+
|| a.packageId.localeCompare(b.packageId));
3373+
return [...contributions, ...navs];
33323374
}
33333375

33343376
/**

‎packages/spec/src/api/package-lifecycle.test.ts‎

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -576,27 +576,27 @@ describe('GetPackageCustomizationsResponseSchema.contributions: the entry shape
576576
});
577577
});
578578

579-
describe('the `nav` kind of `contributions` is declared ahead of its producer (ADR-0049)', () => {
579+
describe('the `nav` kind of `contributions` is served: no planned marker is left (ADR-0049)', () => {
580580
type Described = { description?: string };
581581
const member = (GetPackageCustomizationsResponseSchema as unknown as {
582582
shape: { contributions: Described & { element: { options: Described[] } } };
583583
}).shape.contributions;
584584
const [objectArm, navArm] = member.element.options;
585585

586-
it('the nav arm\'s describe opens with the planned marker and names the ADR, never a tracker id', () => {
587-
expect(navArm.description).toMatch(/^\[PLANNED — not yet served\] /);
588-
expect(navArm.description).toContain('ADR-0049');
586+
it('the nav arm\'s describe carries no planned marker and names no tracker id', () => {
587+
expect(navArm.description).not.toMatch(/PLANNED|not yet served/);
589588
expect(navArm.description).not.toMatch(/#\d{3,}/);
590589
});
591590

592-
it('the member and the field / flow arm say the nav kind is not yet served, and the field / flow arm carries no marker', () => {
593-
expect(member.description).toContain('not yet served');
594-
expect(objectArm.description).not.toMatch(/PLANNED/);
591+
it('neither the member nor the field / flow arm says any kind is not yet served', () => {
592+
expect(member.description).not.toMatch(/PLANNED|not yet served/);
593+
expect(objectArm.description).not.toMatch(/PLANNED|not yet served/);
595594
expect(member.description).not.toMatch(/#\d{3,}/);
596595
});
597596

598-
it('the schema-level describe says the navigation items are not yet served, so serving them drops that too', () => {
599-
expect(GetPackageCustomizationsResponseSchema.description).toContain('not yet served');
597+
it('the schema-level describe no longer says the navigation items are not yet served', () => {
598+
expect(GetPackageCustomizationsResponseSchema.description).not.toContain('not yet served');
599+
expect(GetPackageCustomizationsResponseSchema.description).toContain('navigation items');
600600
});
601601

602602
it('the nav arm says an item with no id (a separator may omit it) is not an entry: `name` is required', () => {

0 commit comments

Comments
 (0)