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
13 changes: 13 additions & 0 deletions .changeset/35529-spec-row-held-base-texts.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
'@objectstack/spec': patch
'@objectstack/metadata-protocol': patch
---

docs(spec): the row-held-base exception in the request texts names its whole cell

Clause-②: no
Metadata-protocol: none

The `packageId` descriptions of the save, draft save, per-item publish, delete and history/diff/rollback requests (`HISTORY_PACKAGE_SELECTOR_DESCRIPTION`) state when a request naming no package follows the row-held base. They now name the two conditions the server already applies and the earlier text left out: the exception holds only for a name no package ships in code (a shipped name is its shipper's, and such a request answers as before), and the base may be declared by one or more packages, not exactly one. The delete text no longer assumes a single dependent: after the base's row is removed, and where the base holds no other member of the name or the member is the canonical one, the next request naming no package is judged over the dependents' rows alone, so one dependent's row is served next and a second delete removes it, while two or more are judged by the same rule. At a named non-canonical member while the base still holds another member, the read naming no package still takes the base's address and answers `404` until the base holds a row there again, and a second delete naming no package still removes a lone dependent's row. Description text only; no schema shape, key, accepted value or server answer moves.

In `@objectstack/metadata-protocol`, the doc comments of the publish, rollback and delete request types, which ship in the built declarations, now state the same row-held-base exception beside the two-package `409`; comment text only.
19 changes: 14 additions & 5 deletions packages/metadata-protocol/src/protocol-door-requests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,10 @@ type PublishMetaItemRequest = {
* publish promotes the draft a draft save naming no package writes
* ({@link packagelessDraftAddress}), and is refused `409
* RESOURCE_CONFLICT` when the item's active rows are bound to two or
* more packages. Spread it in conditionally; never write
* more packages, except where the read naming no package serves the
* row-held base ({@link packagelessRowHeldBaseAddress}): there it
* promotes the base's draft into the base's row, as naming the base
* does. Spread it in conditionally; never write
* `packageId: maybeUndefined`, which arrives as a present-and-undefined
* key, coerces to `null` downstream, and makes a package-bound draft
* unfindable — a silent `no_draft` on the untouched path.
Expand Down Expand Up @@ -131,8 +134,11 @@ type RollbackMetaItemRequest = {
* or the package-less row its read falls back to; the version must be
* that holder's — one attributed to no package, or to the environment,
* only while it is the name's sole slot. Absent, a name two row slots
* hold, or one the bare plain read refuses, is refused `409` naming every
* holder, before anything is written; a name one holder holds restores
* hold is refused `409` naming every holder, before anything is written,
* except where the read naming no package serves the row-held base
* ({@link packagelessRowHeldBaseAddress}): there the base's slot is
* restored, as naming the base restores it. A name the bare plain read
* refuses is refused `409` the same way; a name one holder holds restores
* any of its versions, as before.
*/
packageId?: string;
Expand Down Expand Up @@ -163,8 +169,11 @@ type DeleteMetaItemRequest = {
* the delete removes that package's row and no other. Absent or `null`
* names no package: the delete removes the row of the one package the
* item's rows at its state are bound to, is refused `409
* RESOURCE_CONFLICT` when they are bound to two or more, and with none
* removes the package-unbound row ({@link packagelessAddress}).
* RESOURCE_CONFLICT` when they are bound to two or more (except where the
* read naming no package serves the row-held base,
* {@link packagelessRowHeldBaseAddress}: there it removes the base's row,
* as naming the base does), and with none removes the package-unbound
* row ({@link packagelessAddress}).
* [#23495] A draft discard naming none removes the draft a draft save
* naming none writes ({@link packagelessDraftAddress}), the one the
* per-item publish naming none promotes.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,17 @@ const layRow = (engine: ObjectQL, type: string, name: string, packageId: string
...(type === 'email_template' && metadata.locale !== 'en-US' ? { bundle_member: metadata.locale } : {}),
metadata: JSON.stringify({ name, ...metadata }),
}, { context: { isSystem: true } } as any);
// One `sys_metadata_history` version of the name, attributed to `packageId`'s slot, as a save into that package
// records it: the next environment-wide `event_seq`, as the history writer numbers it.
const layHistory = async (engine: ObjectQL, name: string, packageId: string, version: number, metadata: Record<string, unknown>) => {
const seqs = ((await engine.find('sys_metadata_history', { context: { isSystem: true } } satisfies EngineQueryOptions)) as any[])
.map((row) => Number(row.event_seq) || 0);
return engine.insert('sys_metadata_history', {
id: `hist_${name}_${version}`, event_seq: Math.max(0, ...seqs) + 1, type: 'email_template', name, version, package_id: packageId,
operation_type: 'update', metadata: JSON.stringify({ name, ...metadata }), checksum: `seeded_${name}_${version}`,
recorded_at: new Date().toISOString(), source: 'database-loader',
}, { context: { isSystem: true } } as any);
};
const layPair = async (engine: ObjectQL, name: string, base: string, dependent: string) => {
await layRow(engine, 'email_template', name, base, template('en-US', 'base en'));
await layRow(engine, 'email_template', name, dependent, template('en-US', 'addon en'));
Expand Down Expand Up @@ -274,16 +285,21 @@ describe('[#34681] the bare write doors follow the row-held base the bare read s
const name = `ro_destroy_${label}`;
await layPair(b.engine, name, A, D);
await layRow(b.engine, 'email_template', name, A, template('en-US', 'base drafted'), 'draft');
// A real version of the base's slot to restore, so the rollback is judged as a restore into the base.
await layHistory(b.engine, name, A, 1, template('en-US', 'base v1'));
const at = packageId === undefined ? {} : { packageId };
const discard = await settle(b.protocol.deleteMetaItem({ type: 'email_template', name, state: 'draft', ...at }));
const rollback = await settle(b.protocol.rollbackMetaItem({ type: 'email_template', name, toVersion: 1, ...at }));
const rolledRows = await rowsOf(b.engine, name);
const remove = await settle(b.protocol.deleteMetaItem({ type: 'email_template', name, ...at }));
seen[label] = { discard: outcome(discard), rollback: outcome(rollback), remove: outcome(remove), rows: await rowsOf(b.engine, name) };
seen[label] = { discard: outcome(discard), rollback: outcome(rollback), rolledRows, remove: outcome(remove), rows: await rowsOf(b.engine, name) };
if (label === 'bare') {
for (const answer of [discard, rollback, remove]) expect(answer.code, JSON.stringify(answer)).not.toBe('RESOURCE_CONFLICT');
}
}
expect(seen.bare, JSON.stringify(seen)).toEqual(seen.named);
// The rollback restored the seeded version into the base's row, the dependent's row untouched.
expect(seen.bare, JSON.stringify(seen)).toMatchObject({ rollback: ['resolved', true], rolledRows: [`active:${D}:addon en`, `active:${A}:base v1`] });
});

const versionedPair = async (name: string) => {
Expand Down
4 changes: 2 additions & 2 deletions packages/spec/docs/references/api/protocol.md
Original file line number Diff line number Diff line change
Expand Up @@ -788,7 +788,7 @@ A write-path strip event: caller-supplied fields legally dropped from the payloa
| **state** | `Enum<'active' \| 'draft'>` | optional | Which lifecycle row to discard: `draft` discards the pending draft overlay only (the still-active overlay, if any, keeps serving); `active` or absent resets the live row. Absent defaults to `active`. |
| **dropStorage** | `boolean` | optional | Destructive opt-in, default false: also drop the object's physical table after the metadata row is removed (`object` type + `active` state only; never `sys_` tables). Used by the "discard a previewed object" flow so a publish-to-preview leaves no orphan table. |
| **member** | `string` | optional | Bundle member selector, for a metadata type whose identity is a pair (today only `email_template`, identified by `(name, locale)`): the member this request addresses, spelled as its discriminator value (`zh-CN`). Absent, the canonical member (`en-US` for `email_template`), which is what a bare-name read answers; naming the canonical value is the same request. It is not the response translation locale, which `?locale=` and `Accept-Language` choose. Refused with 400 `VALIDATION_ERROR` on a type that has no members, and for a blank value or one longer than a stored member can be (100 characters). A well-formed member with nothing stored or shipped answers as that door answers an absent item. |
| **packageId** | `string \| null` | optional | ADR-0048 — the software package whose row this delete removes (`sys_metadata.package_id`; `?package=<id>` on the REST door, where `all` and an empty value name no package), as a save names the row it writes. Named, the delete removes that package's row and no other; a package that holds no row removes nothing. Absent or `null` names no package: the delete of the `active` row then removes the row of the one package the item's active rows are bound to, is refused `409 RESOURCE_CONFLICT` when they are bound to two or more, and with none removes the env-local row (no package stamp). Bound to two or more, one exception: a bundled type's member whose active rows a base package and a package declaring it both hold, with no package-unbound row beside them, is the row-held base's, as the read naming no package serves it, and the delete removes the base's row as naming the base does (two packages neither of which declares the other are still refused `409`). The dependent's row is then the item's only row at that address: the read naming no package serves it next, and a second delete naming no package removes it too; the base's copy comes back only by saving it again. The discard of the `draft` removes the draft a draft save naming no package writes, the one the per-item publish naming none promotes, and is refused where that publish is (see `PublishMetaItemRequestSchema.packageId`). That row is the one `parentVersion` is judged against. When another row of the item is still stored afterwards, the receipt `message` names it. |
| **packageId** | `string \| null` | optional | ADR-0048 — the software package whose row this delete removes (`sys_metadata.package_id`; `?package=<id>` on the REST door, where `all` and an empty value name no package), as a save names the row it writes. Named, the delete removes that package's row and no other; a package that holds no row removes nothing. Absent or `null` names no package: the delete of the `active` row then removes the row of the one package the item's active rows are bound to, is refused `409 RESOURCE_CONFLICT` when they are bound to two or more, and with none removes the env-local row (no package stamp). Bound to two or more, one exception: a bundled type's member of a name no package ships in code, whose active rows a base package and one or more packages declaring it hold, with no package-unbound row beside them, is the row-held base's, as the read naming no package serves it, and the delete removes the base's row as naming the base does (two packages neither of which declares the other are still refused `409`). The dependents' rows stay. Where the base holds no other member of the name, or the member is the canonical one, the next request naming no package is judged over them alone: one dependent's row is served next and a second delete naming no package removes it too, while two or more are judged by the rule above. At a named non-canonical member while the base still holds another member, the read naming no package still takes the base's address and answers `404` until the base holds a row there again, and a second delete naming no package still removes a lone dependent's row there. The base's copy comes back only by saving it again. The discard of the `draft` removes the draft a draft save naming no package writes, the one the per-item publish naming none promotes, and is refused where that publish is (see `PublishMetaItemRequestSchema.packageId`). That row is the one `parentVersion` is judged against. When another row of the item is still stored afterwards, the receipt `message` names it. |


---
Expand Down Expand Up @@ -862,7 +862,7 @@ A write-path strip event: caller-supplied fields legally dropped from the payloa
| **name** | `string` | ✅ | Item name |
| **fromVersion** | `integer` | optional | The older side's history version, a whole number as the history lists it. Absent, the nearest earlier version whose body differs from the `to` side's. A version with no history row of the item (or, with `packageId`, of that holder) is refused 404 `VERSION_NOT_FOUND`. |
| **toVersion** | `integer` | optional | The newer side's history version, a whole number as the history lists it. Absent, the active row (with `packageId`, that holder's own active row). Refused 404 `VERSION_NOT_FOUND` as `fromVersion` is. |
| **packageId** | `string` | optional | Optional package ID (`?package=` on the REST door, the `/layers` spelling) — for a type stored per (package, name), the holder whose versions to address: the slot of the row a read naming the package serves (its own row, its `.custom` pair's declared override, or the package-less row that read falls back to), else the package's own empty slot when it ships the name; a package that neither holds nor ships the name is refused 409 `not-held-by-qualifier` (ADR-0150 D3/D4). Versions attributed to no package, or to the environment, are that slot's only while it is the name's sole slot. Absent, a name two holders hold (in stored rows or in code) is refused 409 naming every holder, except where the read naming no package serves the row-held base (a bundled type's member whose active rows a base package and a package declaring it both hold, with no package-unbound row beside them): there the base's slot is addressed, as naming the base addresses it. Two packages neither of which declares the other are still refused. Refused with 400 `VALIDATION_ERROR` on a type not stored per (package, name). |
| **packageId** | `string` | optional | Optional package ID (`?package=` on the REST door, the `/layers` spelling) — for a type stored per (package, name), the holder whose versions to address: the slot of the row a read naming the package serves (its own row, its `.custom` pair's declared override, or the package-less row that read falls back to), else the package's own empty slot when it ships the name; a package that neither holds nor ships the name is refused 409 `not-held-by-qualifier` (ADR-0150 D3/D4). Versions attributed to no package, or to the environment, are that slot's only while it is the name's sole slot. Absent, a name two holders hold (in stored rows or in code) is refused 409 naming every holder, except where the read naming no package serves the row-held base (a bundled type's member of a name no package ships in code, whose active rows a base package and one or more packages declaring it hold, with no package-unbound row beside them): there the base's slot is addressed, as naming the base addresses it. Two packages neither of which declares the other are still refused. Refused with 400 `VALIDATION_ERROR` on a type not stored per (package, name). |


---
Expand Down
Loading
Loading