Skip to content

Commit 7467e2e

Browse files
committed
feat: census reads the declared base; docs and dogfood helper follow the App unit; changeset
Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017ihL2dM9PvPPB9BMVdhf2R
1 parent 84a1ca2 commit 7467e2e

8 files changed

Lines changed: 75 additions & 10 deletions

File tree

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
---
2+
'@objectstack/metadata-core': minor
3+
'@objectstack/metadata-protocol': minor
4+
'@objectstack/objectql': minor
5+
'@objectstack/lint': minor
6+
---
7+
8+
feat(metadata-core, metadata-protocol, objectql, lint): an App and the modules that declare it share one customization pair
9+
10+
Clause-②: no
11+
Metadata-protocol: semantic
12+
13+
The customization unit is the App (ADR-0146 D3 as amended, ruling record 6691022506). `appOf` in `@objectstack/metadata-core` now reads the installed manifests: a `type: 'app'` package is its own App; any other package's App is the installed `type: 'app'` package it declares in `manifest.dependencies`, directly or through its declared parents (where it reaches several, the one holding its namespace); a package that declares no App is its own unit; a kernel package (scope `system` / `cloud`) keeps its own answer, because no platform pair is created in this version.
14+
15+
What changes for a caller:
16+
17+
- `POST /api/v1/packages/:id/ensure-customization` asked for a module of an App answers the App's one pair, `<app id>.custom` (namespace `<app namespace>_custom`, a dependency on the App at `^<major>`): `201` on the first ask from any member, `200` after, never `422` for a package of the same App. The answer's `basePackageId` is the App. HotCRM: the App and its modules all answer `app.objectstack.hotcrm.custom`.
18+
- `422 NAMESPACE_CONFLICT` stays for the pair namespace held by a package outside the App.
19+
- A per-package pair an earlier version created for a module (`<module id>.custom`) stays installed and served: its declared overrides, list rows, translations and served-overrides census are read beside the App's pair (`pairsOf` / `isPairOf`). While it holds the App's pair namespace, the ensure door answers `409 RESOURCE_CONFLICT` naming it instead of creating the App's pair beside it (merge question 12).
20+
- A package that reaches several Apps and whose namespace picks none of them has no pair: the ensure door answers `409` (merge question 11).
21+
- The App's pair's write closure reaches every member of the App, so an override or an object extension of a module's item saved into the App's pair is admitted.
22+
- Uninstalling a module is no longer refused because the App's pair is installed; uninstalling the App still is.
23+
- `os validate`'s `namespace-no-customization-pair` warning skips a member of a delivered App: its customizations land in the App's pair.
24+
25+
TypeScript: `appOf` now answers `string | undefined` (`undefined` = no single App), and `pairOf`'s refusal union gains `no_single_app` (`PairOfRefusal`); `pairsOf` and the `AppOfRefusal` / `PairOfRefusal` types are new exports of `@objectstack/metadata-core`.

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,8 @@ capability changes only with a new version of the package that declares it. An
111111
sentence names that type's own route. What the reads then serve is in
112112
[Metadata lifecycle](/docs/concepts/metadata-lifecycle#customizing-an-installed-package-the-paired-custom-override-adr-0146).
113113
`POST /packages/hotcrm/ensure-customization` creates the pair when absent (Studio calls
114-
it on the first change); a kernel package (scope `system` or `cloud`) has no pair in this
114+
it on the first change); asked for a module that declares an App, it answers the App's one
115+
pair (`<app id>.custom`, `200` once it exists); a kernel package (scope `system` or `cloud`) has no pair in this
115116
version and answers `409 RESOURCE_CONFLICT`, though a pair an earlier version created keeps
116117
serving what it holds. `GET /packages/hotcrm/customizations` lists its overrides,
117118
extensions and switched-off items in one read, beside `contributions`: the fields (kind `field`)

‎content/docs/concepts/metadata-lifecycle.mdx‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,14 @@ later ships. See [ADR-0070](https://github.com/objectstack-ai/objectstack/blob/m
115115

116116
A customer's change to an installed base package — HotCRM, id `hotcrm` — is an item of
117117
the base's paired writable package **`hotcrm.custom`**, which depends on the base; the
118-
base's own items stay read-only. An item of the pair that bears a base item's name — for an
118+
base's own items stay read-only. **The unit is the App**: an App and every module or plugin
119+
that declares it (HotCRM's `app.objectstack.hotcrm` and its modules) share **one** pair,
120+
`<app id>.custom` (`app.objectstack.hotcrm.custom`, namespace `<app namespace>_custom`, depending on
121+
the App at `^<major>`), and the ensure door asked for any of them answers that one pair. A package that
122+
declares no App is its own unit, and a kernel package (scope `system` or `cloud`) has no pair in this
123+
version. A per-package pair an earlier version created for a module stays installed and keeps serving
124+
what it holds; while it holds the App's pair namespace, the ensure door answers `409` naming it rather
125+
than create the App's pair beside it. An item of the pair that bears a base item's name — for an
119126
`email_template`, one item per `(name, locale)`, the name **and** a locale the base ships — and
120127
declares in its body `overrides: { package: 'hotcrm', basedOn: '3.2.0' }` (the base's
121128
`manifest.id` and `manifest.version`; `basedOn` is recorded and never judged; schema:

‎content/docs/deployment/install-modes.mdx‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,9 @@ the package's paired `<package id>.custom` package
112112
([how](/docs/concepts/metadata-lifecycle#customizing-an-installed-package-the-paired-custom-override-adr-0146)).
113113
`POST /api/v1/packages/<package id>/ensure-customization` creates the pair, or
114114
answers it when it already exists, and a save naming it
115-
(`?package=<package id>.custom`) lands there:
115+
(`?package=<package id>.custom`) lands there. A module that declares its App is
116+
customized in the App's pair, `<app id>.custom`: the same door, asked for the
117+
module, answers that pair (its `packageId`), and a save names it:
116118

117119
- an item the package ships, of a type that takes an override (a `view`,
118120
`dashboard`, `flow` and the other types ADR-0146 lists), is replaced by

‎packages/metadata-protocol/src/protocol-packageless-overlay-migration.ts‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -474,9 +474,13 @@ export async function listPackagelessOverlays(
474474
// Every type a declaration applies to, not only the five the move acts on.
475475
const incompleteDeclarations: IncompleteOverrideDeclarationRow[] = [];
476476
for (const row of await environmentRowsOfTypes.call(this, OVERRIDABLE_TYPE_SPELLINGS)) {
477-
if (isUnbound(row)) continue;
478-
const base = customizationBasePackageId(row.package_id);
479-
if (base === null || !isServedOverrideRowOf(row, base, installedManifestsOfEngine(this.engine))) continue;
477+
if (isUnbound(row) || customizationBasePackageId(row.package_id) === null) continue;
478+
// [ADR-0146 D3 as amended] The base is the one the row DECLARES: an
479+
// App's pair overrides the items of every package of the App, so the
480+
// pair's own id names only the App, never the module it overrides.
481+
const declared = (bodyOf(row) as { overrides?: { package?: unknown } } | undefined)?.overrides?.package;
482+
if (typeof declared !== 'string' || !isServedOverrideRowOf(row, declared, installedManifestsOfEngine(this.engine))) continue;
483+
const base = declared;
480484
const basedOn = (bodyOf(row) as { overrides?: { basedOn?: unknown } } | undefined)?.overrides?.basedOn;
481485
if (typeof basedOn === 'string' && basedOn !== '') continue;
482486
const member = memberOf(row);

‎packages/objectql/src/protocol-packageless-overlay-migration.test.ts‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,23 @@ describe('[#28413] the census and the move', () => {
353353
expect((await census(protocol)).incompleteDeclarations).toEqual([]);
354354
});
355355

356+
it('[#29594] a module\'s override in its App\'s pair is listed under the module it declares, not the App, and completed', async () => {
357+
const { engine, protocol } = await boot();
358+
// The base as an App, and a module that declares it: their pair is the App's (ADR-0146 D3 as amended).
359+
const MODULE = `${BASE}.ops`;
360+
const TICKET_VIEW = 'showcase_ticket.default';
361+
engine.registerApp({ id: BASE, name: 'showcase', version: '1.2.0', type: 'app', namespace: 'showcase' } as any);
362+
engine.registerApp({
363+
id: MODULE, name: 'showcase-ops', version: '1.2.0', type: 'module', namespace: 'showcase',
364+
dependencies: { [BASE]: '^1.2.0' },
365+
objects: [objectOf('showcase_ticket', BASE_COLUMNS)], views: [listView('showcase_ticket', BASE_COLUMNS)],
366+
} as any);
367+
expect(((await (protocol as any).ensureCustomizationPackage({ basePackageId: MODULE })) as any).packageId).toBe(PAIR);
368+
await storeRow(engine, TICKET_VIEW, 'showcase_ticket', EDITED_COLUMNS, PAIR, 'active', { overrides: { package: MODULE } });
369+
expect((await census(protocol)).incompleteDeclarations.map((d: any) => [d.name, d.pair, d.base]))
370+
.toEqual([[TICKET_VIEW, PAIR, MODULE]]);
371+
});
372+
356373
it('…on every overridable type, not only the five overlay types (a page)', async () => {
357374
const { engine, protocol, stores } = await boot();
358375
engine.registerApp({ id: BASE, name: 'showcase', version: '1.2.0', namespace: 'showcase', pages: [pageBody(PAGE, 'Home')] } as any);

‎packages/qa/dogfood/test/customization-pair.ts‎

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,23 @@
1111
import { expect } from 'vitest';
1212
import type { VerifyStack } from '@objectstack/verify';
1313

14-
/** The `.custom` pair of a base package. */
14+
/**
15+
* The `.custom` pair of a base package that is its own customization unit —
16+
* an App, or a package that declares no App. Every base these suites
17+
* customize is one. A module's pair is its App's (ADR-0146 D3 as amended),
18+
* which only the server answers: {@link ensurePair} returns the server's
19+
* answer and asserts it is this one, so a suite that customizes a module
20+
* fails here, by name, instead of addressing a pair that does not exist.
21+
*/
1522
export const pairOf = (base: string): string => `${base}.custom`;
1623

17-
/** Ensure the base's pair exists (`201` the first time, `200` after). */
24+
/** Ensure the base's pair exists (`201` the first time, `200` after); the pair the server answers. */
1825
export async function ensurePair(stack: VerifyStack, token: string, base: string): Promise<string> {
1926
const res = await stack.apiAs(token, 'POST', `/packages/${base}/ensure-customization`);
2027
expect([200, 201], await res.clone().text()).toContain(res.status);
21-
return pairOf(base);
28+
const answered = ((await res.json()) as { data?: { packageId?: unknown } })?.data?.packageId;
29+
expect(answered, `the pair the ensure door answers for '${base}'`).toBe(pairOf(base));
30+
return answered as string;
2231
}
2332

2433
/** `path` addressed to the base's pair (`package=<base>.custom` added to its query). */

‎packages/runtime/src/domains/meta-object-extension-item.test.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -490,7 +490,7 @@ describe('[#29594] the App unit: HotCRM and three modules share one pair, and a
490490
expect(engine.registry.getObjectContributors(CASE).filter((c: any) => c.ownership === 'extend').map((c: any) => c.packageId))
491491
.toEqual([APP_PAIR]);
492492
// A record stores a value in the field.
493-
const created: any = await engine.insert(CASE, { subject: 'Outage', sla_tier__c: 'gold' }, { context: { isSystem: true } });
493+
const created: any = await engine.insert(CASE, { subject: 'Outage', sla_tier__c: 'gold', organization_id: 'org_1' }, { context: { isSystem: true } });
494494
const back: any = await engine.findOne(CASE, { where: { id: created.id }, context: { isSystem: true } });
495495
expect(back?.sla_tier__c).toBe('gold');
496496
}, 60_000);

0 commit comments

Comments
 (0)