diff --git a/.changeset/35529-spec-row-held-base-texts.md b/.changeset/35529-spec-row-held-base-texts.md new file mode 100644 index 00000000000..cc810c4e760 --- /dev/null +++ b/.changeset/35529-spec-row-held-base-texts.md @@ -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. diff --git a/packages/metadata-protocol/src/protocol-door-requests.ts b/packages/metadata-protocol/src/protocol-door-requests.ts index 54faca54e40..91b6ff87feb 100644 --- a/packages/metadata-protocol/src/protocol-door-requests.ts +++ b/packages/metadata-protocol/src/protocol-door-requests.ts @@ -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. @@ -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; @@ -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. diff --git a/packages/runtime/src/domains/meta-bare-write-doors-follow-base-34681.test.ts b/packages/runtime/src/domains/meta-bare-write-doors-follow-base-34681.test.ts index a685ea6132b..b455a40383b 100644 --- a/packages/runtime/src/domains/meta-bare-write-doors-follow-base-34681.test.ts +++ b/packages/runtime/src/domains/meta-bare-write-doors-follow-base-34681.test.ts @@ -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) => { + 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')); @@ -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) => { diff --git a/packages/spec/docs/references/api/protocol.md b/packages/spec/docs/references/api/protocol.md index f432ce63ece..20bcfd5b393 100644 --- a/packages/spec/docs/references/api/protocol.md +++ b/packages/spec/docs/references/api/protocol.md @@ -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=` 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=` 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. | --- @@ -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). | --- diff --git a/packages/spec/docs/references/api/protocol.part-2.md b/packages/spec/docs/references/api/protocol.part-2.md index ce52911e8b6..b702adf2031 100644 --- a/packages/spec/docs/references/api/protocol.part-2.md +++ b/packages/spec/docs/references/api/protocol.part-2.md @@ -613,7 +613,7 @@ The published metadata item body, opaque by ruling (1C). Shape is the item's own | **sinceSeq** | `number` | optional | Exclusive lower bound on `seq` for pagination: only events with `seq > sinceSeq` are returned. Absent means "from the beginning". | | **limit** | `number` | optional | Maximum events to return, oldest first. Forwarded to the repository unclamped and with NO default — absent means the full remaining change log. (Deliberately no declared bounds: unlike the audit twin's [1, 500] clamp, nothing on this path clamps or refuses, so declaring `.min()`/`.max()` here would refuse values the shipped verb accepts.) | | **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` | 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). | --- @@ -1099,7 +1099,7 @@ The authoring surface of a metadata write. Closed: `copilot` is an AI assistant' | **name** | `string` | ✅ | Item name — lowercase snake_case segments, optionally dot-qualified (`crm_lead`, `crm_lead.pipeline`). The promotion door enforces the same grammar as `saveMetaItem`. | | **actor** | `string` | optional | Identity recorded on the `op='publish'` history event. On the REST door this is the request's authenticated identity (one producer) — never a caller-supplied header. | | **message** | `string` | optional | Optional human-readable note recorded with the publish history event. | -| **packageId** | `string \| null` | optional | ADR-0048 — the software package the draft being promoted was listed under, when the caller has one to state (`?package=` on the REST door). Named, the publish promotes that package's draft and no other. ABSENT names no package: the publish promotes the draft a draft save that names no package writes — the draft of the one package the item's active rows are bound to, else its package-unbound draft, promoted into that package — and answers `404 NO_DRAFT` when neither exists, as the strict draft read does. For an item never published into a package it is the package-unbound draft, else the one package's draft. It is refused `409 RESOURCE_CONFLICT` when the active rows (or, with none and no package-unbound draft, the drafts) are bound to two or more packages, except 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: the read naming no package serves the base's row, and the publish promotes the base's draft into it, as naming the base does (two packages neither of which declares the other are still refused). ⚠️ `null` is NOT the same as absent: the implementation branches on the KEY BEING PRESENT, and `null` pins the lookup to the package-UNBOUND row. Spread it in conditionally; a present-and-`undefined` key coerces to `null` downstream and makes a package-bound draft unfindable — a silent `no_draft`. | +| **packageId** | `string \| null` | optional | ADR-0048 — the software package the draft being promoted was listed under, when the caller has one to state (`?package=` on the REST door). Named, the publish promotes that package's draft and no other. ABSENT names no package: the publish promotes the draft a draft save that names no package writes — the draft of the one package the item's active rows are bound to, else its package-unbound draft, promoted into that package — and answers `404 NO_DRAFT` when neither exists, as the strict draft read does. For an item never published into a package it is the package-unbound draft, else the one package's draft. It is refused `409 RESOURCE_CONFLICT` when the active rows (or, with none and no package-unbound draft, the drafts) are bound to two or more packages, except 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: the read naming no package serves the base's row, and the publish promotes the base's draft into it, as naming the base does (two packages neither of which declares the other are still refused). ⚠️ `null` is NOT the same as absent: the implementation branches on the KEY BEING PRESENT, and `null` pins the lookup to the package-UNBOUND row. Spread it in conditionally; a present-and-`undefined` key coerces to `null` downstream and makes a package-bound draft unfindable — a silent `no_draft`. | | **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. | | **parentVersion** | `string \| null` | optional | ADR-0008 optimistic-concurrency pin on the PUBLISHED layer: the version token of the active row the caller loaded and means to replace (on the REST door, the `If-Match` request header; the `/layers` read's `overlayVersion`, the plain read's `version` and a publish receipt's `version` serve it). A token that is not the current active row's at the address the promotion writes is refused 409 `METADATA_CONFLICT`, whose `currentVersion` names the active row's current token, and nothing is promoted: the draft stays pending. ⚠️ `null` is NOT the same as absent: a present `null` asserts "no active row here" (on the REST door, `If-None-Match: *`, which takes `*` alone and never beside `If-Match`), refused 409 when one exists; an ABSENT key is unpinned and promotes over whatever is live, as before. It pins the active row only — which draft is promoted is the address's, as without it; the draft's own pin is `draftVersion`. | | **draftVersion** | `string` | optional | ADR-0008 optimistic-concurrency pin on the DRAFT this publish promotes: the version token of the pending draft row the caller wrote or loaded and means to publish (on the REST door, the `draftVersion` member of the publish body, beside `message`; a draft save's receipt `version` and the draft read's `version` serve it). A token that is not the current draft row's at the address the promotion reads is refused 409 `METADATA_CONFLICT`, whose `currentVersion` names the draft's current token (`null` when no draft is pending), and nothing is promoted: a draft another writer changed after the caller wrote or read it is never published on that writer's behalf. ABSENT is unpinned and promotes whichever draft is pending, as before. It pins the draft only — the active row the promotion replaces is `parentVersion`'s (`If-Match`), and the two may be sent together: the draft is judged first, so a request stale on both is refused naming the draft's token. The address is resolved before either pin: no draft at the address while another package holds one answers `404 NO_DRAFT`, not this conflict. | diff --git a/packages/spec/docs/references/api/protocol.part-3.md b/packages/spec/docs/references/api/protocol.part-3.md index 39efa7083be..2ba9f948afe 100644 --- a/packages/spec/docs/references/api/protocol.part-3.md +++ b/packages/spec/docs/references/api/protocol.part-3.md @@ -245,7 +245,7 @@ Answer to a device registration: the device id the client keeps | **toVersion** | `integer` | ✅ | The history version whose body is restored as the new live row: a whole number of at least 1, as the history lists it. The rollback door reads this declaration and refuses anything else `400`. | | **message** | `string` | optional | Rollback note, recorded on the new history row. | | **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` | 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). | --- @@ -341,7 +341,7 @@ Answer to a device registration: the device id the client keeps | **actor** | `string` | optional | Identity recorded on the write's history event (`recorded_by`, a lookup into `sys_user`) and audit row. On the REST door this is the request's authenticated identity (one producer) — never a caller-supplied header. Absent, the event is recorded actor-less (null), deliberately not attributed to "system". | | **force** | `boolean` | optional | Destructive-change acknowledgement (`?force=true` on the REST door): skips the safety diff that refuses an `object` save whose body drops fields or narrows types the stored item still carries (409 with the findings otherwise). Only `object` saves reach that diff, so the flag is inert for every other type. Absent = the guard runs. | | **mode** | `Enum<'draft' \| 'publish'>` | optional | Per-item lifecycle (ADR-0005 drafts): `draft` stages the body as a pending draft overlay (`?mode=draft` on the REST door; the publish door promotes it later); `publish` or ABSENT writes straight to the live `active` row — the legacy default, kept so callers that predate the draft/publish split keep working. Any value other than `draft` is read as `publish`. | -| **packageId** | `string \| null` | optional | ADR-0048 — the software package to bind the saved row to (`sys_metadata.package_id`; `?package=` on the REST door, where `all` and an empty value name no package). Set when authoring inside a Studio package workspace; a named read-only base package is refused. On create the row is stamped with this id; on update an existing binding is preserved, never silently re-bound. Absent or `null` names no package. An `active` save then writes the row of the one package the item's active rows are bound to, as a save naming that package does, is refused `409 RESOURCE_CONFLICT` when they are bound to two or more, and with none writes the env-local overlay (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 save (either mode) writes the base's row or draft as a save naming the base does; two packages neither of which declares the other are still refused `409`. A `draft` save writes the draft of the one package the item's active rows are bound to (a pending change stays in the package it edits), else its package-unbound draft, adopted into that package — the draft the per-item publish naming no package promotes. For an item never published into a package it is the package-unbound draft, else the one package's draft, and with no draft at all the save creates the package-unbound draft. It is refused `409 RESOURCE_CONFLICT` when the active rows (or, with none and no package-unbound draft, the drafts) are bound to two or more packages, but for the row-held base above, as that publish is (see `PublishMetaItemRequestSchema.packageId`). An `action` is keyed by the object it binds (ADR-0150 D4): when one or more packages' active rows hold the name and none of those rows binds the object the body binds (object-less is its own key), the save writes the environment's own package-unbound row (`active`) or draft (`draft`), never a package's item. The environment keeps one package-unbound row and one package-unbound draft per action name: such a save over the environment's own row or draft bound to another object rewrites it onto the body's object, and over one bound to an object a package's active row binds (that package's customization) it is refused `409 RESOURCE_CONFLICT`; a `draft` save is refused the same way when the package-unbound row its publish would rewrite is that customization. Otherwise the address above stands, judged over every holder of the name (every enabled holder, for an `active` save), except that an `active` save is judged over the holders at the body's object only when a disabled package is one of them and another holder binds another object. The per-item publish and the draft discard naming no package act on the environment's draft so written, except that with one package holding the name, that package's own draft, when one is stored, comes first; that publish is refused `409 RESOURCE_CONFLICT` when the package-unbound row it would rewrite is a package's customization. Until the read naming no package keys an action by object, the version it serves is the package's item's, so a save carrying it as the parent is refused as a version conflict. The row written is also the one the parent-version resolution reads: an unpinned save takes its version as the parent (last-write-wins), a pinned one is judged against it, and the item read at the same scope serves it as `version`. | +| **packageId** | `string \| null` | optional | ADR-0048 — the software package to bind the saved row to (`sys_metadata.package_id`; `?package=` on the REST door, where `all` and an empty value name no package). Set when authoring inside a Studio package workspace; a named read-only base package is refused. On create the row is stamped with this id; on update an existing binding is preserved, never silently re-bound. Absent or `null` names no package. An `active` save then writes the row of the one package the item's active rows are bound to, as a save naming that package does, is refused `409 RESOURCE_CONFLICT` when they are bound to two or more, and with none writes the env-local overlay (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 save (either mode) writes the base's row or draft as a save naming the base does; two packages neither of which declares the other are still refused `409`. A `draft` save writes the draft of the one package the item's active rows are bound to (a pending change stays in the package it edits), else its package-unbound draft, adopted into that package — the draft the per-item publish naming no package promotes. For an item never published into a package it is the package-unbound draft, else the one package's draft, and with no draft at all the save creates the package-unbound draft. It is refused `409 RESOURCE_CONFLICT` when the active rows (or, with none and no package-unbound draft, the drafts) are bound to two or more packages, but for the row-held base above, as that publish is (see `PublishMetaItemRequestSchema.packageId`). An `action` is keyed by the object it binds (ADR-0150 D4): when one or more packages' active rows hold the name and none of those rows binds the object the body binds (object-less is its own key), the save writes the environment's own package-unbound row (`active`) or draft (`draft`), never a package's item. The environment keeps one package-unbound row and one package-unbound draft per action name: such a save over the environment's own row or draft bound to another object rewrites it onto the body's object, and over one bound to an object a package's active row binds (that package's customization) it is refused `409 RESOURCE_CONFLICT`; a `draft` save is refused the same way when the package-unbound row its publish would rewrite is that customization. Otherwise the address above stands, judged over every holder of the name (every enabled holder, for an `active` save), except that an `active` save is judged over the holders at the body's object only when a disabled package is one of them and another holder binds another object. The per-item publish and the draft discard naming no package act on the environment's draft so written, except that with one package holding the name, that package's own draft, when one is stored, comes first; that publish is refused `409 RESOURCE_CONFLICT` when the package-unbound row it would rewrite is a package's customization. Until the read naming no package keys an action by object, the version it serves is the package's item's, so a save carrying it as the parent is refused as a version conflict. The row written is also the one the parent-version resolution reads: an unpinned save takes its version as the parent (last-write-wins), a pinned one is judged against it, and the item read at the same scope serves it as `version`. | | **writeFace** | `Enum<'package-duplicate' \| 'meta-envelope' \| 'meta-dispatch' \| 'external-import'>` | optional | Which write door a refusal is being rendered FOR — stated by the SERVER, never by a remote caller: every door builds this request field by field and never spreads a request body into it, so there is no path for a client to smuggle a face in, and a face arriving in a wire body is simply never read. Two refusals branch on it, for different questions: the 409 destructive-change remedy names the acknowledgement mechanism that actually exists on the refusing door (`?force=true` on the REST doors; the dispatcher, the duplicate-package door and the external-table import have none), and the 422 invalid-metadata message adapts to whether a structured `issues[]` channel reaches the consumer beside it. Absent = the conservative default wording. | | **surface** | `Enum<'copilot' \| 'mcp' \| 'studio' \| 'api'>` | optional | The authoring surface this save is made through (see `MetadataAuthoringSurfaceSchema`). A draft save (`mode: 'draft'`) stamps it as `by` on every key path it changes, the entries the strict draft read serves as `draftChanges`; an active save records no per-key provenance. ABSENT stamps `api`. On the REST door and the runtime dispatcher it is the `?surface=` query parameter, which takes `studio` or `api` and refuses every other value `400 VALIDATION_ERROR`, `copilot` and `mcp` included: `copilot` is stated only by an in-process AI tool calling the save and `mcp` only by the MCP build door after it verified the client's token, never by a remote caller, so an HTTP request cannot mark its own write as the copilot's or an MCP agent's. A value outside the set in-process is refused `400 INVALID_REQUEST`, before anything is written. | | **client** | `{ id: string; name?: string }` | optional | The OAuth client this save is made by (see `MetadataAuthoringClientSchema`), stated only by the MCP build door, in-process, from the token it verified. Only with `surface: 'mcp'`: a `client` beside any other surface, or a malformed one, is refused `400 INVALID_REQUEST` before anything is written. A draft save stamps it as `client` beside `by: 'mcp'` on every key path it changes; an active save records it nowhere. No HTTP door reads it: the REST door and the dispatcher build this request member by member, so a `client` in a wire body or query is never read. | diff --git a/packages/spec/src/api/protocol.zod.ts b/packages/spec/src/api/protocol.zod.ts index dcd1de9e416..bdb9858994c 100644 --- a/packages/spec/src/api/protocol.zod.ts +++ b/packages/spec/src/api/protocol.zod.ts @@ -1278,9 +1278,10 @@ export const SaveMetaItemRequestSchema = lazySchema(() => z.object({ + 'that package does, is refused `409 RESOURCE_CONFLICT` when they are ' + 'bound to two or more, and with none writes the env-local overlay (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 save (either ' + + '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 save (either ' + 'mode) writes the base\'s row or draft as a save naming the base does; ' + 'two packages neither of which declares the other are still refused ' + '`409`. A `draft` save writes the draft of the one package ' @@ -1640,9 +1641,10 @@ export const PublishMetaItemRequestSchema = lazySchema(() => z.object({ + 'a package it is the package-unbound draft, else the one package\'s ' + 'draft. It is refused `409 RESOURCE_CONFLICT` when the active rows (or, ' + 'with none and no package-unbound draft, the drafts) are bound to two or ' - + 'more packages, except 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: the read naming no package serves the base\'s row, and ' + + 'more packages, except 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: the read ' + + 'naming no package serves the base\'s row, and ' + 'the publish promotes the base\'s draft into it, as naming the base does ' + '(two packages neither of which declares the other are still refused). ' + '⚠️ `null` is ' @@ -2554,15 +2556,22 @@ export const DeleteMetaItemRequestSchema = lazySchema(() => z.object({ + '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 ' + + '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 ' @@ -2783,9 +2792,10 @@ const HISTORY_PACKAGE_SELECTOR_DESCRIPTION = + '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 ' + + '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).';