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
28 changes: 28 additions & 0 deletions .changeset/33593-extension-follow-judged-as-served.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
---
'@objectstack/objectql': minor
'@objectstack/metadata-protocol': minor
'@objectstack/spec': minor
---

feat(objectql)!: a record-mode amount an object extension adds is judged against its object as served, so a bad follow pair is refused at the run that completes it

Clause-②: yes (narrowing)
Metadata-protocol: narrowed

<!-- adr-0087: registered record-currency-follow-extension-judged-as-served -->

**BREAKING** for an `objectExtensions` entry (or a stored `object_extension` item) that adds a record-mode amount (`currencyConfig.currencyMode: 'record'`, `currencyField: 'MASTER_DETAIL.CODE'`) whose parent field holds no ISO 4217 code, does not exist, or is reached through the extension's own new master_detail. The record-currency follow door (ADR-0144 D2 and D6, amended) asked an `extend` layer about its own roll-ups only and returned before the following-amount half, so such an amount was admitted and served; every write of it was then refused `ERR_CURRENCY_CODE_REQUIRED`, and the next no-change upgrade of the parent's owner was refused over the extension's field. Every object layer is now judged as its object served with the layer in its slot: the base, every enabled extension, and the incoming body. It is also BREAKING for a roll-up author: a published single save of an `object_extension` item that adds a `sum` / `avg` / `min` / `max` roll-up D6 refuses, or adds a record-mode amount a registered parent's such roll-up reads, is now refused 422 where it was stored (the last line below).

The fix: name in the second segment of `currencyField` a field of the master_detail target that declares `valueDomain: 'iso_4217_currency'` (the refusal lists the candidates), or install the package that supplies that field before the extension, or in the same artifact. For a roll-up D6 refuses: roll up through the master_detail the amount follows (`summaryOperations.relationshipField`, on the parent it follows), use `function: 'count'`, or roll up a stored home-currency amount field of the child instead; the refusal says which applies.

What moves (each line FROM → TO). The first four lines hold at the end of an install / upgrade / reload run, in the batch writer, and on a published single save of an `object_extension` item; the others name their askers:

- an extension-only package adding an amount that follows a parent field holding no code, a missing field, or a field reached through its own new master_detail: FROM admitted (served) TO refused 422 `INVALID_METADATA`, naming the child object and the amount; nothing of the install stays.
- the other registration order, the extension registered first (no verdict while nothing owns the extended object) and the owner after it: the owner's install FROM admitted TO refused 422 over the extension's amount.
- an extension following a code field another extension supplies: refused when that supplier is not installed or is disabled; admitted when it is installed and enabled, or arrives in the same artifact.
- a parent upgrade that removes or de-codes a field an extension's amount follows: still refused 422; the sentence now names the extension's package and field.
- at the end of a run ONLY (an install, upgrade or reload): a no-change upgrade of the parent's owner, the child's owner or the extension's package over a pair a cold boot admitted, or an upgrade that only adds an unrelated code field to the parent: FROM refused 422 TO installed. A run is not refused over a pair it leaves as it found it (the pair is compared, not the refusal sentence: for a following amount, the object and field declaring it, the pointer, and the object the pointer's master_detail reaches; for a roll-up, the object and field declaring it and the child object and field it reads). An upgrade of the child's owner that re-points the master_detail onto another parent lacking the code makes a new pair and is still refused 422, as before. The same re-point upgrade of an extension package (its own master_detail, pointer string unchanged) moves FROM installed (`main` never asked an extension layer's following half) TO refused 422.
- on a published single save of an `object_extension` item and in the batch writer (a package publish, a duplicate, an import), which judge a layer against its slot left empty: re-publishing an UNCHANGED extension whose amount a cold boot admitted over a bad parent field: FROM saved (single save answered 200, the batch writer saved the row in its own result; the extension's following half was never asked) TO refused 422. An own object body re-published unchanged over such a pair was already refused there, and still is.
- a published single save of an `object_extension` item on a `/meta` face now also meets D6's roll-up door (`recordCurrencySummaryRefusal`), as the batch writer's extension row already did, in both directions: an extension adding a `sum` / `avg` / `min` / `max` roll-up of a child amount, or adding an amount a registered parent's such roll-up reads, where that child amount is declared `currencyMode: 'record'` (in each row's own currency, or following a parent's code but not read on that parent through the master_detail it follows): FROM stored and answered 200 (its registration then failed with a `console.warn` only) TO refused 422 `INVALID_METADATA`, nothing stored.

Unchanged: the same amount in an own object body is refused 422, and so is a package that owns the parent and extends the child in one install; an extension of an object no package owns is no verdict; the cold boot is not asked. No stored-row migration or heal ships with this change.
18 changes: 18 additions & 0 deletions packages/metadata-protocol/src/protocol-save.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ import type { MutationProjectionOutcome } from './protocol-mutation-events.js';
import type { ProtocolHost } from './protocol-host.js';
import type { ObjectStackProtocolImplementation } from './protocol.js';
import { saveRegistryQuestion } from './registry-question.js';
import { OBJECT_EXTENSION_TYPE, registrableObjectExtension } from './protocol-object-extension-item.js';
import { BatchRowHealError, canJudgeBatchObjects, isBatchObjectType, readActiveBatchRow, settleBatchObjectRows, undoBatchRowWrite, undoOutcomeForLog, type WrittenBatchRow } from './batch-object-registration.js';

export class ProtocolSaveFacet {
Expand Down Expand Up @@ -1253,6 +1254,23 @@ export class ProtocolSaveFacet {
await host.saveWriteBinding(singularType, request, mode),
);
if (extensionRefusal) throw extensionRefusal;
// [ADR-0144 D2 and D6, amended; #33593 ruling R1] …and, published
// on a face that makes the one body live at once, the follow door
// the same face asks of an `object` body: the extension judged as
// its object will be served, with this body in its package's
// slot. The registry answers no verdict for an object nothing
// serves yet, and none before the cold boot sealed it.
const registry = host.engine?.registry as { objectRegistrationRefusal?: (schema: unknown, packageId: string | undefined, ownership: string, options: { againstRegistry?: boolean }) => Error | null } | undefined;
if (singularType === OBJECT_EXTENSION_TYPE
&& saveRegistryQuestion({ mode, writeFace: request.writeFace }) === 'against-registry'
&& typeof registry?.objectRegistrationRefusal === 'function') {
const binding = await host.saveWriteBinding(singularType, request, mode);
if (binding) {
const { extend, priority: _priority, ...contribution } = registrableObjectExtension(request.item);
const followRefusal = registry.objectRegistrationRefusal({ ...contribution, name: extend }, binding, 'extend', { againstRegistry: true });
if (followRefusal) throw followRefusal;
}
}
}
// [harden] …and a permission set whose NAME another owner already
// holds, with `NAMESPACE_CONFLICT` / 422: a set's name is its
Expand Down
13 changes: 10 additions & 3 deletions packages/metadata-protocol/src/registry-question.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@
* makes one body live and relays the refusal to its author asks it; on a
* sealed registry it then also asks the record-currency doors that read other
* objects (D6's roll-up half, and the follow door), so a refused body is
* answered `422 INVALID_METADATA` and nothing is stored or promoted.
* answered `422 INVALID_METADATA` and nothing is stored or promoted. An
* `object_extension` item published on the same faces asks both
* record-currency doors too — D6's roll-up half (the roll-ups it adds, and a
* registered parent's roll-up over an amount it adds), and the follow door
* of the extension judged as its object will be served.
*
* The follow door is not that save's alone. `registerObject` never asks it —
* a unit registers in an order a later member can still complete — so each
Expand All @@ -27,8 +31,11 @@
* outermost run (`SchemaRegistry.restoringOnRefusal`). It calls neither
* callee below, so it is no producer in
* {@link REGISTRY_QUESTION_PRODUCERS}.
* An `extend` layer is asked only of its own roll-ups (the door's `partial`
* rule), by whichever asker registers it.
* An `extend` layer is judged like any other layer, by whichever asker
* registers it: as its object will be served, with every enabled extension
* and the layer in its slot, in both directions — the amounts and roll-ups
* the layer adds against their other ends, and the registered amounts and
* roll-ups whose other end is that object.
*
* Every other producer (a draft save, the batch writers, a package publish)
* keeps the body-only question per row. A batch that makes object rows live
Expand Down
Loading
Loading