Skip to content

Commit d9ae50b

Browse files
committed
feat(metadata-protocol,objectql): an object extension is an authorable item of a writable package
`object_extension` joins the metadata type registry. A writable package saves, publishes, restores and deletes one through the existing /meta doors; the gate refuses an unbound write, the registry's extend refusals, a name other than the target, an unknown or out-of-closure target and a `.custom` field without `__c`. Every stored-row sync registers the whole parsed body as the package's 'extend' contributor and delete/uninstall withdraw it. The package export carries the rows as `objectExtensions` and no longer exports an extended object as the package's own. Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 7a48bf7 commit d9ae50b

15 files changed

Lines changed: 967 additions & 19 deletions

File tree

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
---
2+
"@objectstack/spec": minor
3+
"@objectstack/lint": minor
4+
"@objectstack/objectql": minor
5+
"@objectstack/metadata-protocol": minor
6+
"@objectstack/runtime": minor
7+
---
8+
9+
feat(metadata-protocol,objectql): an object extension is an item of a writable package — saved, published and exported through the existing doors
10+
11+
Clause-②: yes (widening)
12+
Metadata-protocol: added
13+
14+
A package can now add fields and rules to an object another package defines by saving an `object_extension` item through `/api/v1/meta`, the same way it saves any other item. This is what Studio's add-field on a base object writes (ADR-0146 D10): an extension in the base's paired `<base>.custom` package, its fields suffixed `__c`, the base untouched.
15+
16+
- **The type** (`@objectstack/spec/kernel`). `object_extension` joins `MetadataTypeSchema` and the metadata type registry. Its body is `ObjectExtensionSchema` as it stands: it carries `extend` and no `name`. The row is filed under the target object's name, one extension per package per target. `OVERRIDE_TYPE_CLASSIFICATION` lists it as `excluded`: an extension adds to its target, it never replaces a base item, so it never carries `overrides`. That disposition does not close the type to a `.custom` pair.
17+
- **The doors.** Draft, publish, history restore and delete are the doors every item uses. The save, publish and restore doors refuse, with `VALIDATION_ERROR` / 400 and an issue path: a write bound to no package; `defaultRowScope` or `membershipKeys` in the body (the registry's own sentences); a row filed under a name other than its `extend`; an unregistered target; a target outside the package's dependency closure (with the closure prescription the other save doors print); and a `.custom` field without the `__c` suffix (the existing `__c` judge). A body the schema refuses answers 422 `INVALID_METADATA` with the schema's issues. No error code is added.
18+
- **The registry** (`@objectstack/objectql`). A published row registers its whole parsed body as the package's `'extend'` contributor (`SchemaRegistry.registerObjectExtension`), so its fields, validations and indexes appear on every read of the object, and a publish adds the column to the target's table. Every stored-row sync re-registers it (boot, write-through, read hydration), and deleting the row or uninstalling the package withdraws it (`SchemaRegistry.withdrawObjectExtension`). What a manifest's `objectExtensions` register is unchanged.
19+
- **The export** (`@objectstack/runtime`). `GET /packages/:id/export` carries each of the package's extension items as an `objectExtensions` entry that re-installs. A package's `objects` are now only the objects it owns: an object the package extends is no longer exported as an `'own'` object, which re-install refused with `ObjectOwnershipConflictError`.
20+
- **`@objectstack/lint/runtime`** exports `closureDependencyRemedy`, the closure prescription the save doors print.
21+
22+
Two costs, both on purpose: `/meta/types` serves no JSON schema for `object_extension`, and a draft carries no `_diagnostics` badge, because the type is not bound in `BUILTIN_METADATA_TYPE_SCHEMAS` (that map requires the ADR-0010 envelope, which would change the schema a manifest's `objectExtensions` parse with).

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -642,7 +642,7 @@ Metadata query with filtering, sorting, and pagination
642642

643643
| Property | Type | Required | Description |
644644
| :--- | :--- | :--- | :--- |
645-
| **types** | `Enum<'object' \| 'field' \| 'hook' \| 'seed' \| 'mapping' \| 'picklist' \| 'view' \| 'page' \| 'dashboard' \| 'app' \| 'action' \| 'report' \| 'dataset' \| 'flow' \| 'job' \| 'datasource' \| 'external_catalog' \| 'translation' \| 'api' \| 'email_template' \| 'doc' \| 'book' \| 'permission' \| 'position' \| 'capability' \| 'sharing_rule' \| 'queue' \| 'assignment_rule' \| 'agent' \| 'tool' \| 'skill'>[]` | optional | Filter by metadata types |
645+
| **types** | `Enum<'object' \| 'object_extension' \| 'field' \| 'hook' \| 'seed' \| 'mapping' \| 'picklist' \| 'view' \| 'page' \| 'dashboard' \| 'app' \| 'action' \| 'report' \| 'dataset' \| 'flow' \| 'job' \| 'datasource' \| 'external_catalog' \| 'translation' \| 'api' \| 'email_template' \| 'doc' \| 'book' \| 'permission' \| 'position' \| 'capability' \| 'sharing_rule' \| 'queue' \| 'assignment_rule' \| 'agent' \| 'tool' \| 'skill'>[]` | optional | Filter by metadata types |
646646
| **namespaces** | `string[]` | optional | Filter by namespaces |
647647
| **packageId** | `string` | optional | Filter by owning package |
648648
| **search** | `string` | optional | Full-text search query |
@@ -709,14 +709,15 @@ Metadata query with filtering, sorting, and pagination
709709

710710
| Property | Type | Required | Description |
711711
| :--- | :--- | :--- | :--- |
712-
| **type** | `Enum<'object' \| 'field' \| 'hook' \| 'seed' \| 'mapping' \| 'picklist' \| 'view' \| 'page' \| 'dashboard' \| 'app' \| 'action' \| 'report' \| 'dataset' \| 'flow' \| 'job' \| … +16 more>` | ✅ | Metadata type |
712+
| **type** | `Enum<'object' \| 'object_extension' \| 'field' \| 'hook' \| 'seed' \| 'mapping' \| 'picklist' \| 'view' \| 'page' \| 'dashboard' \| 'app' \| 'action' \| 'report' \| 'dataset' \| … +18 more>` | ✅ | Metadata type |
713713
| **name** | `string` | ✅ | Item name (snake_case) |
714714
| **data** | `Record<string, any>` | ✅ | Metadata payload |
715715
| **namespace** | `string` | optional | Optional namespace |
716716

717717
### Allowed Values: `MetadataRegisterRequest.type`
718718

719719
* `object`
720+
* `object_extension`
720721
* `field`
721722
* `hook`
722723
* `seed`

‎content/docs/references/kernel/metadata-plugin.mdx‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ const result = MetadataBulkResultSchema.parse(data);
179179

180180
| Property | Type | Required | Description |
181181
| :--- | :--- | :--- | :--- |
182-
| **types** | `Enum<'object' \| 'field' \| 'hook' \| 'seed' \| 'mapping' \| 'picklist' \| 'view' \| 'page' \| 'dashboard' \| 'app' \| 'action' \| 'report' \| 'dataset' \| 'flow' \| 'job' \| 'datasource' \| 'external_catalog' \| 'translation' \| 'api' \| 'email_template' \| 'doc' \| 'book' \| 'permission' \| 'position' \| 'capability' \| 'sharing_rule' \| 'queue' \| 'assignment_rule' \| 'agent' \| 'tool' \| 'skill'>[]` | optional | Filter by metadata types |
182+
| **types** | `Enum<'object' \| 'object_extension' \| 'field' \| 'hook' \| 'seed' \| 'mapping' \| 'picklist' \| 'view' \| 'page' \| 'dashboard' \| 'app' \| 'action' \| 'report' \| 'dataset' \| 'flow' \| 'job' \| 'datasource' \| 'external_catalog' \| 'translation' \| 'api' \| 'email_template' \| 'doc' \| 'book' \| 'permission' \| 'position' \| 'capability' \| 'sharing_rule' \| 'queue' \| 'assignment_rule' \| 'agent' \| 'tool' \| 'skill'>[]` | optional | Filter by metadata types |
183183
| **namespaces** | `string[]` | optional | Filter by namespaces |
184184
| **packageId** | `string` | optional | Filter by owning package |
185185
| **search** | `string` | optional | Full-text search query |
@@ -226,6 +226,7 @@ const result = MetadataBulkResultSchema.parse(data);
226226
### Allowed Values
227227

228228
* `object`
229+
* `object_extension`
229230
* `field`
230231
* `hook`
231232
* `seed`
@@ -266,7 +267,7 @@ const result = MetadataBulkResultSchema.parse(data);
266267

267268
| Property | Type | Required | Description |
268269
| :--- | :--- | :--- | :--- |
269-
| **type** | `Enum<'object' \| 'field' \| 'hook' \| 'seed' \| 'mapping' \| 'picklist' \| 'view' \| 'page' \| 'dashboard' \| 'app' \| 'action' \| 'report' \| 'dataset' \| 'flow' \| 'job' \| … +16 more>` | ✅ | Metadata type identifier |
270+
| **type** | `Enum<'object' \| 'object_extension' \| 'field' \| 'hook' \| 'seed' \| 'mapping' \| 'picklist' \| 'view' \| 'page' \| 'dashboard' \| 'app' \| 'action' \| 'report' \| 'dataset' \| … +18 more>` | ✅ | Metadata type identifier |
270271
| **label** | `string` | ✅ | Display label for the metadata type |
271272
| **description** | `string` | optional | Description of the metadata type |
272273
| **filePatterns** | `string[]` | ✅ | Glob patterns to discover files of this type |
@@ -283,6 +284,7 @@ const result = MetadataBulkResultSchema.parse(data);
283284
### Allowed Values: `MetadataTypeRegistryEntry.type`
284285

285286
* `object`
287+
* `object_extension`
286288
* `field`
287289
* `hook`
288290
* `seed`

‎examples/app-showcase/src/coverage.ts‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,15 @@ export const KIND_COVERAGE: Record<MetadataType, KindCoverage> = {
5757
notes:
5858
'Also carries the validation-rule surface: rules are authored inline via object `validations` (the `validation` KIND was retired in #4509 — ADR-0088 — because a standalone rule had no way to name the object it validated). Every declared rule type is write-path enforced (rule-validator dispatches all of state_machine/script/cross_field/format/json_schema/conditional — ADR-0020 "no silent no-ops", closing the #1475 gap) and each is demonstrated: state_machine (task/project), script+cross_field (project), format/json_schema/conditional (account). Field-level requiredWhen/readonlyWhen are likewise enforced and demonstrated on invoice.',
5959
},
60+
// [#28574] A registry kind since an extension became an authorable item of a
61+
// writable package. The showcase's own extension is the code half (the stack's
62+
// `objectExtensions`, also tracked in STACK_COLLECTION_COVERAGE); the runtime
63+
// half is `PUT /api/v1/meta/object_extension/<target>?package=<pkg>`.
64+
object_extension: {
65+
status: 'demonstrated',
66+
files: ['src/data/extensions/account.extension.ts'],
67+
notes: 'Authored in code as an `objectExtensions` entry; the same body is an `object_extension` item when a writable package saves it through `/api/v1/meta`.',
68+
},
6069
field: {
6170
status: 'demonstrated',
6271
files: ['src/data/objects/field-zoo.object.ts'],

‎packages/lint/src/runtime.ts‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,11 @@ export {
7070
runtimeGatedTypes,
7171
stackKeyForType,
7272
} from './runtime-gate.js';
73+
// [#28574] The closure prescription the save doors print, for a door outside
74+
// this package that judges an object name under a package closure (the
75+
// `object_extension` item gate in `@objectstack/metadata-protocol`), so the
76+
// sentence is not spelled a second time.
77+
export { closureDependencyRemedy } from './object-graph.js';
7378
export type {
7479
RuntimeGateResult,
7580
RuntimePackageScope,

‎packages/metadata-protocol/src/protocol-authoring-gate.ts‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ export interface AuthoringGateHost {
7979
objectNamespacePrefixViolation: ObjectStackProtocolImplementation['objectNamespacePrefixViolation'];
8080
hierarchyResolverMounted: ObjectStackProtocolImplementation['hierarchyResolverMounted'];
8181
isArtifactBacked: ObjectStackProtocolImplementation['isArtifactBacked'];
82+
objectExtensionItemRefusal: ObjectStackProtocolImplementation['objectExtensionItemRefusal'];
8283
orgWallEnforced: ObjectStackProtocolImplementation['orgWallEnforced'];
8384
permissionSetNameCollisionRefusal: ObjectStackProtocolImplementation['permissionSetNameCollisionRefusal'];
8485
refuseRestoredBodyTheSaveDoorRefuses: ObjectStackProtocolImplementation['refuseRestoredBodyTheSaveDoorRefuses'];
@@ -101,7 +102,7 @@ export function restoredBodyDerivation(
101102

102103
/** The body of `ObjectStackProtocolImplementation#restoredBodyWriter`; the method's docblock there is its contract. */
103104
export function restoredBodyWriter(
104-
this: Pick<AuthoringGateHost, 'refuseRestoredBodyTheSaveDoorRefuses' | 'restoredBodyDerivation'>,
105+
this: Pick<AuthoringGateHost, 'objectExtensionItemRefusal' | 'refuseRestoredBodyTheSaveDoorRefuses' | 'restoredBodyDerivation'>,
105106
type: string, name: string, binding: string | null, source: string): (historyBody: unknown) => Promise<unknown> {
106107
const derive = this.restoredBodyDerivation(type);
107108
return async (historyBody) => {
@@ -112,6 +113,9 @@ export function restoredBodyWriter(
112113
// [ADR-0146 D10, #28564] The `__c` reservation, on the same binding.
113114
const suffixRefusal = objectBodyExtensionFieldSuffixRefusal(type, historyBody, name, binding);
114115
if (suffixRefusal) throw suffixRefusal;
116+
// [#28574] An `object_extension` version against its address, on the same binding.
117+
const extensionRefusal = this.objectExtensionItemRefusal(type, historyBody, name, binding);
118+
if (extensionRefusal) throw extensionRefusal;
115119
await this.refuseRestoredBodyTheSaveDoorRefuses(type, name, historyBody, binding, source);
116120
return derive ? derive(historyBody) : historyBody;
117121
};

0 commit comments

Comments
 (0)