Skip to content

Commit 26f4e6d

Browse files
fix(objectql)!: refuse a currency path to no code field, and a record roll-up over an unfollowed amount, at a single-object save (#32368)
<!-- claude-projects-attribution: {"github_login":"os-support-ai"} --> _Requested by **Yibo Wang** · [project thread](https://claude.ai/code/project/chan_01BVUyyPie8gHwoPM18iABwB?thread=cmsg_01BVUyyPie8gHwoPM18iABwBUCxUdnFKS2gzgxGonxxHKW)_ Fixes #32312 Clause-②: yes (narrowing): after the cold boot, a published single-object save through `PUT /meta/object/:name` or the runtime `/meta` dispatcher, and a per-item publish (`POST /meta/object/:name/publish`), of a record-mode amount whose `currencyField` path `PARENT_FIELD.CODE_FIELD` names no ISO 4217 code field on the `master_detail` parent (or of a parent without the code field a registered child follows), of a `summary` declaring `currencyMode: 'record'` over a child amount that follows no record, or of an ADR-0144 D6 roll-up over a child amount in its own record currency, was answered `200` / `published` and is now refused `INVALID_METADATA` / 422 with nothing stored or promoted; nothing else moves for the follow pair. Metadata-protocol: none Skills-docs: none — `skills/**` teaches no `PARENT_FIELD.CODE_FIELD` path and no `record` roll-up: its two `currencyMode: 'record'` hits at 898c2f4 are a sibling code field (`objectstack-data/rules/field-types.md`) and a dataset measure (`objectstack-ui/rules/dashboards.md`); the save-time rule is stated in `content/docs/data-modeling/currency.mdx` in this diff. > [!WARNING] > **BREAKING** — accept-set narrowing at three metadata doors, on a running server only: `PUT /meta/object/:name` (published), the runtime `/meta` dispatcher (published) and `POST /meta/object/:name/publish` now answer `422 INVALID_METADATA` and store or promote nothing for a currency path to no code field, a `record` roll-up over an amount that follows nothing, and (newly at these doors) D6's roll-up over an own-currency amount. The boot, `registerApp` (install, reload), draft saves, batch writers and a package publish do not move for the follow pair. ## 维护者速读 - **改了什么**:服务器启动完成后,三个元数据入口(`PUT /meta/object/:name` 发布保存、运行时 `/meta` 分发器的发布保存、单项发布 `POST /meta/object/:name/publish`)会拒绝两类"货币对不上"的声明,回 422、不落库/不发布:子对象金额跟随 `父.币种字段`,但父对象上没有这个字段或它不是 ISO 4217 币种字段;以及声明 `currencyMode: 'record'` 的汇总字段,其子金额不跟随任何记录的币种。报错与 `defineStack` 一字不差(共用 `@objectstack/spec/data` 的同一模块)。D6 已有的同类拒绝在这三个入口也改为 422(以前是存下、回 200、只记日志)。 - **为什么改**:以前这类声明保存成功,作者要到录入数据时才在每一笔子金额上撞到 `ERR_CURRENCY_CODE_REQUIRED`,或汇总被贴上并非其币种的父记录币种;单项发布更是回"已发布"却没注册。 - **风险与回滚**:跟随门只在调用方显式要求时才问(`againstRegistry`,且仅在冷启动封存后生效);`registerObject` 本身从不问,所以启动、水合、包安装与重载、草稿保存、批量写入、整包发布对这对声明的行为与 main 完全一致。回滚 = revert 本 PR。批量路径注册失败只记日志的老问题由 #32369 跟进。 - **先看**:`packages/metadata-protocol/src/registry-question.ts`(哪些入口会问,集中登记)、`packages/objectql/src/registry.ts`(`objectRegistrationRefusal` 的 `againstRegistry` 与跟随门的唯一调用点)、`packages/objectql/src/record-currency-aggregate-door.ts`(`recordCurrencyFollowRefusal`,两端判定)、`packages/spec/src/data/record-currency-path.ts`(共享文案与谓词)。 - **两分钟验证**:`pnpm --filter @objectstack/objectql exec vitest run src/record-currency-guards.test.ts -t 'follow door'`,预期 11 个用例全绿;真实启动:`packages/qa/dogfood/test/record-currency-follow-save-door.dogfood.test.ts` 8 个用例全绿。 - **需要你做的**:无,席位落地。 ## What changes **The door.** `recordCurrencyFollowRefusal` stands in `record-currency-aggregate-door.ts` beside the ADR-0144 D6 roll-up half (`recordCurrencySummaryRefusal`), with the same pair discipline: a pair is judged at whichever save completes it, and a pair with an end not registered yet is no verdict. - (a) A record-mode amount whose `currencyField` is `VIA.CODE` (segment 1 stays the spec object door's) and whose segment 2 names no field of the `master_detail` target, or a field that is not an `iso_4217_currency` code field, is refused. At the child's save with the parent registered, and at the parent's save (or re-save) with a following child registered; the message then leads with `'PARENT' does not hold the code a registered amount follows.` A code field the parent gets from a registered `objectExtensions` entry of an enabled package counts (a disabled package's is withheld at both ends, as the served fold withholds it). - (c) A `summary` declaring `currencyMode: 'record'` that rolls up `sum` / `avg` / `min` / `max` of a child field following no record (a `fixed` amount, a `dynamic` one, a plain number) is refused, at either end. A child amount in its own record currency, or following another record or through another relation, was already D6's refusal; that arm is pinned, not re-judged. - An `extend` body holds only the fields it adds, so only its own roll-ups are judged. A parent known only through extensions has no owner and `getObject` returns nothing for it, so it is no verdict, as `defineStack` skips it. - The answer is `INVALID_METADATA` / 422 (`RecordCurrencyFollowRefusedError`, `objectName` + `fieldName` naming the refused declaration), the D6 half's envelope. No new error code. **Opt-in (seat ruling on contract review 6782495106).** The follow door is asked only from `SchemaRegistry.objectRegistrationRefusal(…, { againstRegistry: true })`, and the option is honoured only once the cold boot has sealed the registry (`bareNameHoldersAreSealed`, set at `kernel:bootstrapped`). `registerObject` never asks it. Under the option the pre-flight also asks D6's door (it is otherwise body-only, #29673). The callers that pass it, enumerated in `packages/metadata-protocol/src/registry-question.ts`: - `saveMetaItem` in publish mode on face `meta-envelope` (`PUT /meta/:type/:name`) or `meta-dispatch` (the runtime `/meta` dispatcher) — `saveRegistryQuestion`; - the per-item publish `POST /meta/:type/:name/publish`, through `promoteDraftForPublish`, whose request now requires `registryQuestion` (`PROMOTION_REGISTRY_QUESTION`: `item-publish` asks against the registry, `package-publish` body-only), so a new producer must state its choice to compile. `REGISTRY_QUESTION_PRODUCERS` records every request-carrying `saveMetaItem` and `promoteDraftForPublish` call in a package's `src/**` (13 `saveMetaItem` and 2 `promoteDraftForPublish` calls), each with its question and why, exported from `@objectstack/metadata-protocol`; the census `packages/runtime/src/metadata-registry-question-producers.test.ts` fails when a call is added, removed or moved without a row. Why opt-in and post-seal, under AGENTS.md's startup-registry rule and #29673: a multi-registration unit registers in an order that can still complete a pair. The boot hydrates `sys_metadata` rows in no particular order, and every `registerApp` (cold boot, a post-seal install through the `manifest` service, a reload) registers a package's `objects` (`engine-registration.ts` step 2) before its `objectExtensions` (step 2b), so a child whose parent's code field comes from the package's own extension would be refused by a verdict the same unit then contradicts (F1). The batch writers write rows in their own order and only log a registration refusal. A single save or per-item publish has no sibling and answers its author, so it is the one place the question is both right and heard. This is a **ruled deviation** from the order's "at `registerObject`". **One builder.** The (a) messages, the (c) head and its unfollowed reason, and the code-field predicate moved from private helpers of `collectRecordCurrencyPathErrors` into `packages/spec/src/data/record-currency-path.ts` (`isRecordCurrencyCodeField`, `recordCurrencyFollowedCodeError`, `recordCurrencyRecordRollupError`, `recordCurrencyUnfollowedRollupError`), exported from `@objectstack/spec/data` beside the `controlled-by-parent-master` precedent. The stack check calls them; its findings and words are unchanged. No schema key moves; `api-surface` and `export-origins` regenerated (+4 functions, +2 interfaces). **FROM → TO** (sealed kernel): | door | FROM | TO | |---|---|---| | `PUT /meta/object/:name`, published (`meta-envelope`) | follow pair: `200`, stored, registered (refused at data entry); D6 pair: `200`, stored, `console.warn`, unregistered | `422 INVALID_METADATA`, nothing stored | | runtime `/meta` dispatcher, published (`meta-dispatch`) | same | `422 INVALID_METADATA`, nothing stored (same pre-flight line; read, not driven live) | | `POST /meta/object/:name/publish` (per-item) | follow pair: `published`, registered; D6 pair: `published`, `console.warn`, new object unregistered or old definition kept | `422 INVALID_METADATA`, nothing promoted; published row and registered object unchanged | | boot, hydration, `registerApp` (install, reload), draft save, batch writers, `publishPackageDrafts`, direct `registerObject` | — | unchanged for the follow pair; D6 unchanged | **Docs.** `content/docs/data-modeling/currency.mdx` states the save- and publish-time refusals, that a draft is judged at its publish, and that boot and package install are not judged this way. ## Tests `packages/objectql/src/record-currency-guards.test.ts`, top-level `describe` "the follow door", 11 cases. A `save()` helper models the metadata doors: `objectRegistrationRefusal(…, { againstRegistry: true })`, then `registerObject` only when it passes. 1. child path to a missing field → 422, message byte-equal to `defineStack`'s finding for the same pair; 2. child path to a non-code field → 422, byte-equal to `defineStack`; 3. parent saving after the child without the code field, and parent re-saving with it demoted to plain `text` → 422; the registered parent stays as it was; 4. `record` roll-up over a `fixed` and over a plain-number child amount → 422, both orders, byte-equal to `defineStack`; 5. `record` roll-up over a child amount in its own record currency → D6's `RecordCurrencySummaryRefusedError`, sealed and unsealed, at `registerObject` and at `save()`; 6. CONTROL: a correct path and the roll-up through that `master_detail` save in either order; a currency-less summary over a plain number saves; 7. CONTROL: a code field supplied by a registered extension counts, for the child's save and the owner's re-save; 8. F3: a disabled package's extension supplies no code field at either end (child save and parent re-save both refused); re-enabled, the parent saves; 9. `registerObject` never asks the follow door on a sealed registry (child to `invoice.title` and parent without its code both register), nor does the body-only pre-flight; 10. CONTROL (F1): a post-seal `registerApp` whose own `objectExtensions` supplies the parent's code field installs, the object and the extension's field registered; 11. cold boot: an unsealed registry admits even a `save()` naming the option. Beside D6's #29673 pin: the `againstRegistry` option changes nothing unsealed; sealed, the batch question returns `null` and the single-save question returns D6's refusal and registers nothing. `packages/runtime/src/metadata-registry-question-producers.test.ts` (3 cases, the runtime's `repo` tier, `heldBy` every `packages/**/*.ts` in `scripts/cross-package-test-inputs.mjs`): the producer census over every package's non-test `src/**/*.ts`, the by-face producers' faces and the two promotion producers' stated questions, `saveRegistryQuestion`'s truth table. It reads the table through the package's public export (as the other repo-tier census tests read `@objectstack/objectql` and `@objectstack/rest`), so the runtime's test type-check program keeps its `rootDir`. **Live, on a booted, sealed stack** (`packages/qa/dogfood/test/record-currency-follow-save-door.dogfood.test.ts`, 8 cases, `Tests 8 passed (8)`, tests 3.87 s): through `PUT /meta/object`, a child following `invoice.title` (no code) and `invoice.currency` (no field), a `record` roll-up over a `fixed` child amount, and D6's roll-up over an own-currency child amount each answer `422`, `code: INVALID_METADATA`, the door's message, then `GET` `404` and nothing registered; CONTROL: a child following `invoice.currency_code` saves `200` and registers. Through the per-item publish: a published, registered child following `invoice.currency_code` gets a draft repointed at `invoice.title` (saved `200`; the re-point is a destructive change, acknowledged with `force`), `POST …/publish` answers `422 INVALID_METADATA`, and the published row and the registered object still follow `invoice.currency_code`; a NEW object's bad draft saves `200`, its publish answers `422`, and nothing is published or registered. <details><summary>RED on main (pins 1-4, first round)</summary> Main's `registry.ts` and `record-currency-aggregate-door.ts` put back with `git restore --source=origin/main` (tree only), the test file kept: `Tests 4 failed | 4 passed | 47 skipped (55)`, the four refusal cases `expected { code: undefined, … } to deeply equal { code: 'INVALID_METADATA', … }`. Restored; `git diff HEAD` empty. </details> <details><summary>Ablations (scripts/ablation-replace.mjs, each restored to HEAD by blob, <code>git diff HEAD</code> empty)</summary> Head `fe6f55f7` for A5-A8: - A5, the opt-in dropped (`if (opts.againstRegistry === true && this.bareNameHoldersAreSealed) {` → `if (this.bareNameHoldersAreSealed) {`, `registry.ts`): pin 9 and the F1 CONTROL red, `Tests 2 failed | 9 passed | 48 skipped (59)`; blob `1e2970a4` → `5aafe6ff`, restored `1e2970a4`. - A6, F3 dropped (`… && !this.isPackageDisabled(c.packageId));` → `…);`): pin 8 red, `Tests 1 failed | 10 passed | 48 skipped (59)`; blob `1e2970a4` → `8cca4054`, restored. - A7, the per-item publish's question dropped (`againstRegistry: request.registryQuestion === 'against-registry',` → `againstRegistry: false,`, `protocol-history-and-publish.ts`), `metadata-protocol` rebuilt inside the ablation, live pin: both publish cases red, `expected 200 to be 422` with `"success":true … "Published draft — type=object, name=rcf_pub_line"`, `Tests 2 failed | 6 passed (8)`; blob `acdcf89a` → `05f9d429`, restored; dist rebuilt after (`registryQuestion === "against-registry"` present once in `dist/index.js`). - A8, the save's question dropped (`{ againstRegistry: saveRegistryQuestion(…) === 'against-registry' },` → `{ againstRegistry: false },`, `protocol-save.ts`), dist rebuilt inside (hit 1 in `index.js` and `index.cjs`): the four `PUT` refusal cases red, `expected 200 to be 422` with `"Saved object 'rcf_bad_line' (env-wide, state=active)"`, `Tests 4 failed | 4 passed (8)`; blob `6b68dbac` → `2189ef51`, restored. First round (head `4ff7e7f7`, the door itself, still valid as the door's logic is unchanged): A1 the door dropped → pins 1-4 red; A3 the parent's extension fields dropped → pin 7 red. </details> ## Acceptance notes 1. **Which doors hear the refusal, and which do not ask** (measured on a sealed dogfood stack where stated): | door | question | follow pair, bad | D6 pair | |---|---|---|---| | `PUT /meta/object/:name`, published (`meta-envelope`) | against registry | `422`, nothing stored (live) | `422`, nothing stored (live) | | runtime `/meta` dispatcher, published (`meta-dispatch`) | against registry | `422` (same line, read) | `422` (read) | | `POST /meta/object/:name/publish` | against registry | `422`, nothing promoted (live) | `422` (same line) | | draft save (`?mode=draft`) | body-only | `200`; judged at its publish (live) | same | | `publishPackageDrafts` | body-only | registers as on main (read) | refused at the write-through registration, `console.warn`, as on main (read) | | package duplicate, unmanaged import, external import, faceless internal callers (migration passes, CLI ownership) | body-only | registers as on main | `success: true`, stored, `console.warn`, unregistered (measured, as on main) | | `registerApp` (install, reload), boot, hydration | none | registers as on main (pin 10) | as on main | The batch and publish-batch relay of registry-dependent refusals is #32369 (the seat extends it with `publishPackageDrafts` and `registerApp`); the follow door joins those units once they relay. 2. **Boot census.** Boot paths that reach `registerObject`: artifact/manifest objects (`engine-registration.ts`, a throw stops the boot), manifest `objectExtensions` (after the package's objects), `sys_metadata` rows (`loadMetaFromDb`, per-row `catch` + `console.error`), overlay rows (same loop), hot reload (`ingestReloadedObjects`, caught). None asks the follow door, and the option is honoured only after the seal, so every boot registers what it registered on main. No shipped object uses a path `currencyField` or a summary `currencyConfig` (`git grep` over `examples/`, `packages/platform-objects`, `packages/plugins`, `packages/services`: 0 hits at 898c2f4). `os validate`: `examples/app-showcase` exit 0 (28 warnings, none currency), `examples/app-crm` exit 0 (4 warnings, none currency). 3. **A pair registered before the seal** with a bad follow is not judged until one end is saved or published again; then, as D6, a save of the parent is refused until the child or the parent's code field is fixed, including a save that changes something else. 4. **Not mirrored at runtime:** stack (b), an admitted roll-up through the followed `master_detail` that does not declare `currencyMode: 'record'` naming the parent's code field. Not in the card; it under-labels rather than mislabels. 5. A host whose kernel withholds the boot-phase hooks never seals, so there the option is never honoured (the bare-name doors share that posture). 6. Follow-ups filed by the seat: #32369 (batch, package publish and `registerApp` relay); one p3 card for N3 (`SaveMetaItemRequestSchema.writeFace`'s description, outside this diff) and N5 (the parent-end scan cost per single save). ## Verification All on head `ee2468e8` (origin/main merged at the seat's request, clean, no PR file among the 165 it brings in) unless stated. - **dogfood_battery**: `pnpm --filter @objectstack/dogfood test` under `os-verify-lock` on `ee2468e8`, after rebuilding every package the merge touched (`turbo run build`, 40 tasks, exit 0): `Test Files 450 passed | 3 skipped (453)`, `Tests 3771 passed | 42 skipped (3813)`, `VERDICT command-exit 0` (28m23s). The new live pin is inside it (8/8). The same battery was green on the pre-merge head `3c3ae617` (3771 passed). - **Gates** (`dispatch-gates --ran`): `138 derived, 138 run, 0 NOT-MEASURED, 0 UNRUN`, all exit 0, every one of the 138 run on `ee2468e8` (a container restart split the loop: 109 before it, the other 29 after, same tree). - `pnpm --filter @objectstack/spec run check:generated` exit 0 on `ee2468e8` (`api-surface` / `export-origins` regenerated in this diff). - Suites (pre-merge head): `@objectstack/objectql` `585 files / 12192 passed`; `@objectstack/metadata-protocol` `22663 passed | 29 skipped`; `record-currency-guards.test.ts` `59 passed`. Runtime census `3 passed` on `ee2468e8` (main changed `packages/runtime/src/domains/automation.ts`, which holds a census row; the count is unchanged). - Type check: `@objectstack/metadata-protocol` `tsc --noEmit` 0; `@objectstack/runtime` `check:test-typecheck` OK (27 files / 185 errors held by the ledger, unchanged). - `eslint` on every changed source file: 0. `os validate`: `examples/app-showcase` and `examples/app-crm` exit 0 (no currency warnings). - CI on `ee2468e8`: 58 success, 10 skipped (opt-in / label-gated lanes), 0 failed; mergeable, `clean`. CI fixes since the contract review's `24ae708d` (no change to the door or the opt-in): the census moved from metadata-protocol to the runtime's `repo` tier with `heldBy` (cross-package-test-inputs), the opt-in test gained the module-top `@objectstack/lint` import (test-source-alias), the census walk is paid once at collection (Test Core timeout, 6.4 s to 0.7 s), and the census reads the table through the `@objectstack/metadata-protocol` export instead of a source path (runtime test type-check, TS6059). --- _Generated by [Claude Code](https://claude.ai/code/session_01WGufzfg6ANtjV1U3Zvstgg)_ 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01WGufzfg6ANtjV1U3Zvstgg <!-- signed: domain:server#2 · os-support-ai · session_01WGufzfg6ANtjV1U3Zvstgg --> --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent 0bc0774 commit 26f4e6d

22 files changed

Lines changed: 1144 additions & 75 deletions
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
---
2+
'@objectstack/objectql': patch
3+
'@objectstack/metadata-protocol': patch
4+
'@objectstack/spec': patch
5+
---
6+
7+
fix(objectql)!: a single-object save or publish is refused when a record-mode amount follows no code field on its parent, or a `record` roll-up reads an amount that follows nothing
8+
9+
Clause-②: yes (narrowing) — after the cold boot, a published single-object save through `PUT /meta/object/:name` or the runtime `/meta` dispatcher, and a per-item publish (`POST /meta/object/:name/publish`), of a record-mode amount whose `currencyField` path `PARENT_FIELD.CODE_FIELD` names no ISO 4217 code field on the `master_detail` parent (or of a parent without the code field a registered child follows), of a `summary` declaring `currencyMode: 'record'` over a child amount that follows no record, or of an ADR-0144 D6 roll-up over a child amount in its own record currency, was answered `200` / `published` and is now refused `INVALID_METADATA` / 422 with nothing stored or promoted; nothing else moves for the follow pair.
10+
Metadata-protocol: none
11+
12+
<!-- adr-0087: not-required (no-migration-prescription) No key of any schema is added, removed, renamed or re-shaped. The refusal is the registry's existing INVALID_METADATA for a body it refuses, judged only at a single save or publish after the cold boot, so a stored row boots exactly as before and there is nothing for a migration to rewrite and no tombstone. -->
13+
14+
**BREAKING** accept-set narrowing at the metadata save and per-item publish doors' registry pre-flight (`saveMetaItem`, `publishMetaItem`, `@objectstack/metadata-protocol`; the question is `SchemaRegistry.objectRegistrationRefusal`'s `againstRegistry`, `@objectstack/objectql`).
15+
16+
`defineStack` already refused both shapes when a stack declares both objects. A save of one object, with the other end already registered, did not: a child amount following `invoice.currency` (no such field on `invoice`) or `invoice.title` (a field that holds no code) was admitted, and every write of the amount was then refused `ERR_CURRENCY_CODE_REQUIRED` at data entry or labelled with whatever the field held. A `summary` declaring `currencyMode: 'record'` over a `fixed` or plain-number child field was admitted, and showed the total in the parent's currency though no child amount was in it.
17+
18+
Now, once the server has finished booting, each is refused `INVALID_METADATA` / 422 (`RecordCurrencyFollowRefusedError`), whichever object is saved second, with the message `defineStack` prints: the two messages and the code-field predicate are one module of `@objectstack/spec/data` (`isRecordCurrencyCodeField`, `recordCurrencyFollowedCodeError`, `recordCurrencyRecordRollupError`, `recordCurrencyUnfollowedRollupError`), read by both doors. A parent saved without the code field a registered child follows is refused the same way. A code field the parent gets from a registered `objectExtensions` entry of an enabled package counts.
19+
20+
Where the refusal is heard: only at a door that makes one body live and answers its author. A published save through `PUT /meta/object/:name` (`meta-envelope`) or the runtime `/meta` dispatcher (`meta-dispatch`), and the per-item publish `POST /meta/object/:name/publish`, ask the registry with `againstRegistry` before anything is stored or promoted, so this door and D6's answer `422` there. Before, that pre-flight judged the body alone: a save stored the row and answered `200`, a publish promoted the draft and answered `published`, and the registration refusal was only logged, leaving the object unregistered (new) or with its old definition (re-saved). D6's roll-up over a child amount in its own record currency is therefore also refused at those doors now, where it was stored and logged. The faces and doors are enumerated in `registry-question.ts` (`@objectstack/metadata-protocol`), with a pin over every `saveMetaItem` and `promoteDraftForPublish` call.
21+
22+
What does not move for the follow pair: `registerObject` itself never asks the follow door, so the boot, hydration, `registerApp` (install and reload, whose `objectExtensions` register after its `objects`), a draft save, the batch writers (package duplicate, unmanaged import, external import, the stored-object migration passes) and a package publish (`publishPackageDrafts`) register it exactly as before. D6's door is unchanged at those paths (refused at registration, logged where the caller only logs; #32369 tracks relaying those).
23+
24+
What an author does: name a code field of the parent in the path's second segment (a `text` field declaring `valueDomain: 'iso_4217_currency'`; the message lists the candidates), and declare `currencyMode: 'record'` on a roll-up only when its child amounts follow the parent through the `master_detail` it rolls up (else delete `currencyConfig`, or declare `fixed`). For a D6 refusal, use `function: 'count'`.
25+
26+
What does not change: the boot registers every stored or packaged object it registered before (the option is honoured only after `kernel:bootstrapped`), and the stack check's findings and words are unchanged.

‎content/docs/data-modeling/currency.mdx‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,18 @@ message:
100100
| `currencyField` names a field that is not `text` | same | Point at a `text` field. |
101101
| `currencyField` names a `text` field without `valueDomain: 'iso_4217_currency'` | same | Add `valueDomain: 'iso_4217_currency'` to that field. |
102102

103+
A `master_detail` child may follow its parent's currency instead, with the two-segment path
104+
`currencyField: 'PARENT_FIELD.CODE_FIELD'`. The object alone judges the first segment. The
105+
second names a field of the parent, so it is judged where both objects are known:
106+
`defineStack` refuses a path whose second segment is no field of the parent, or a field that
107+
does not hold an ISO 4217 code. On a running server, saving one of the two objects through
108+
the metadata API (`PUT /meta/object/:name`), or publishing its draft
109+
(`POST /meta/object/:name/publish`), with the other already registered is refused with
110+
**`INVALID_METADATA` / 422** and the same message, whichever is saved second, and nothing
111+
is stored or published; a parent saved without the code field a registered child follows
112+
is refused the same way. A draft is judged when it is published. Objects registered while
113+
the server boots, or by a package install, are not judged this way.
114+
103115
### Writing a record
104116

105117
When a record-mode amount holds a value, its code field must hold a code in the same
@@ -219,6 +231,13 @@ that column. A `count` column never carries `currencyField`. See the
219231
422**. A roll-up stores one number with no currency, so child rows in different
220232
currencies would be added together. Use `function: 'count'`. The pair is judged at
221233
whichever registration completes it, the parent's or the child's.
234+
- **A `summary` declaring `currencyMode: 'record'`** is admitted only for a roll-up through
235+
the `master_detail` its child amounts follow (`PARENT_FIELD.CODE_FIELD`), and names the
236+
parent's own code field. One whose child amount follows no record (a `fixed` amount, a
237+
`dynamic` one, a plain number) totals in no currency the parent holds: `defineStack`
238+
refuses it, and on a running server a save or publish through the metadata API refuses
239+
it with **`INVALID_METADATA` / 422** and the same message, whichever object is saved
240+
second.
222241
- **A dataset measure that declares `currency` over a record-mode amount** is refused at
223242
compile with **`DATASET_INVALID` / 400**, and so is a `currency` on a derived measure that
224243
sums record-mode amounts. One code cannot label amounts in several currencies: delete

‎packages/metadata-protocol/src/index.ts‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,17 @@ export {
2929
collectInternalWriteResponseFields,
3030
} from './write-response-internal-fields.js';
3131
export { createMetadataProtocolPlugin, assembleMetadataProtocol, shouldRunPlatformMigrations } from './plugin.js';
32+
// [ADR-0144 D2 and D6, amended] Which metadata doors ask the registry the
33+
// question that reads its other objects, in one place: exported so the
34+
// runtime's repo-tier census can pin every producer against it.
35+
export {
36+
AGAINST_REGISTRY_SAVE_FACES,
37+
PROMOTION_REGISTRY_QUESTION,
38+
REGISTRY_QUESTION_PRODUCERS,
39+
saveRegistryQuestion,
40+
type RegistryQuestion,
41+
type RegistryQuestionProducer,
42+
} from './registry-question.js';
3243
export type { MetadataProtocolPluginOptions, AssembleMetadataProtocolOptions } from './plugin.js';
3344
// [#20312] The service key a host registers its SDUI component manifest under, read by the save door per publish.
3445
export { SDUI_MANIFEST_SERVICE } from './runtime-authoring-gate.js';

‎packages/metadata-protocol/src/protocol-discovery-and-bases.ts‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -988,7 +988,14 @@ export class ProtocolDiscoveryAndBasesFacet {
988988
* a registry that cannot answer the question (a partial double).
989989
*/
990990
static objectRegistrationRefusal(host: Pick<ProtocolHost, 'engine'>, body: unknown,
991-
layer: ReturnType<ObjectStackProtocolImplementation['classifyObjectContribution']>,): Error | null {
991+
layer: ReturnType<ObjectStackProtocolImplementation['classifyObjectContribution']>,
992+
/**
993+
* [ADR-0144 D2 and D6, amended] A single save that makes the body
994+
* live at once: the registry also asks the doors that read its
995+
* other objects, once its cold boot has sealed it
996+
* (`SchemaRegistry.objectRegistrationRefusal`'s `againstRegistry`).
997+
*/
998+
options: { againstRegistry?: boolean } = {},): Error | null {
992999
if (layer.kind === 'mismatch') return null;
9931000
const registry = host.engine?.registry as { objectRegistrationRefusal?: (...args: unknown[]) => Error | null } | undefined;
9941001
if (typeof registry?.objectRegistrationRefusal !== 'function') return null;
@@ -997,6 +1004,7 @@ export class ProtocolDiscoveryAndBasesFacet {
9971004
{ ...(body as Record<string, unknown>), _provenance: 'org' },
9981005
layer.packageId,
9991006
layer.kind,
1007+
{ againstRegistry: options.againstRegistry === true },
10001008
);
10011009
}
10021010

‎packages/metadata-protocol/src/protocol-history-and-publish.ts‎

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ import type { ProtocolHost } from './protocol-host.js';
5757
import type { SeedAppliedLandedParsed } from '@objectstack/spec/api';
5858
// [#29985 codemod] `ObjectStackProtocolImplementation` here is `ObjectStackProtocolImplementationStatics` (imported AS the class): forwarders to its statics (#30147).
5959
import { ObjectStackProtocolImplementationStatics as ObjectStackProtocolImplementation } from './protocol.js';
60+
import { PROMOTION_REGISTRY_QUESTION, type RegistryQuestion } from './registry-question.js';
6061

6162
export class ProtocolHistoryAndPublishFacet {
6263
/** The body of `ObjectStackProtocolImplementation#historyMetaItem`; the method's docblock there is its contract. */
@@ -375,7 +376,7 @@ export class ProtocolHistoryAndPublishFacet {
375376
// site has no transaction of its own, so recording it in the `catch` is
376377
// where it always effectively landed; what changed is that the helper no
377378
// longer assumes that on behalf of the batch route too.
378-
const { singularType, advisories, result } = await host.promoteDraftForPublish({ ...request, member })
379+
const { singularType, advisories, result } = await host.promoteDraftForPublish({ ...request, member, registryQuestion: PROMOTION_REGISTRY_QUESTION['item-publish'] })
379380
.catch(async (err: unknown) => {
380381
await host.recordPendingDenialAudit(err);
381382
throw err;
@@ -547,6 +548,14 @@ export class ProtocolHistoryAndPublishFacet {
547548
* all address it, so the body judged is the body that goes live.
548549
*/
549550
member?: string;
551+
/**
552+
* [ADR-0144 D2 and D6, amended] The registry question this
553+
* promotion asks before the row goes live, stated by every producer
554+
* ({@link PROMOTION_REGISTRY_QUESTION}, `registry-question.ts`): the
555+
* per-item publish asks against the registry, a package publish
556+
* body-only.
557+
*/
558+
registryQuestion: RegistryQuestion;
550559
}): Promise<{
551560
singularType: string;
552561
/**
@@ -733,7 +742,15 @@ export class ProtocolHistoryAndPublishFacet {
733742
// writes, the per-item publish answers the registry's own envelope
734743
// and a batch publish aborts on it into `failed[]` as on the
735744
// refusals below (ADR-0067 D2). See {@link objectRegistrationRefusal}.
736-
const registration = host.objectRegistrationRefusal(draftForGate.body, layer);
745+
//
746+
// [ADR-0144 D2 and D6, amended] The per-item publish has no
747+
// sibling, so it also asks the doors that read the registry's
748+
// other objects (#29673's batch reason does not reach it); a
749+
// package publish keeps the body-only question
750+
// (`registry-question.ts`).
751+
const registration = host.objectRegistrationRefusal(draftForGate.body, layer, {
752+
againstRegistry: request.registryQuestion === 'against-registry',
753+
});
737754
if (registration) throw registration;
738755
}
739756

@@ -1802,6 +1819,7 @@ export class ProtocolHistoryAndPublishFacet {
18021819
if (draft?.body) seedBodies.push(draft.body);
18031820
}
18041821
const { singularType, advisories, result } = await this.promoteDraftForPublish({
1822+
registryQuestion: PROMOTION_REGISTRY_QUESTION['package-publish'],
18051823
// [#8908] The stored spelling, FOLDED — this route's
18061824
// boundary, the analogue of `canonicalizeMetaRequestType`
18071825
// on the six `/meta` entry points. Every row that

‎packages/metadata-protocol/src/protocol-save.ts‎

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ import { withRefusalAudit } from './protocol-refusal-audit.js';
8181
import type { MutationProjectionOutcome } from './protocol-mutation-events.js';
8282
import type { ProtocolHost } from './protocol-host.js';
8383
import type { ObjectStackProtocolImplementation } from './protocol.js';
84+
import { saveRegistryQuestion } from './registry-question.js';
8485

8586
export class ProtocolSaveFacet {
8687
/**
@@ -1481,8 +1482,23 @@ export class ProtocolSaveFacet {
14811482
// The body is the one this save stores: the read's injected
14821483
// columns already came off it above. See
14831484
// {@link objectRegistrationRefusal}.
1485+
//
1486+
// [ADR-0144 D2 and D6, amended] A published save through the
1487+
// `/meta` doors (`meta-envelope`, `meta-dispatch`) is one object
1488+
// made live at once, so it also asks the doors that read the
1489+
// registry's other objects (the record-currency roll-up and
1490+
// follow doors), on a sealed registry: refused there, the row
1491+
// was stored, answered `200` and left unregistered. A draft is
1492+
// judged when it is published (the per-item publish asks the
1493+
// same), and the batch faces (duplicate, imports, migration
1494+
// passes) save in an order a later sibling can still complete,
1495+
// so they keep the body-only question (#29673's reason). The
1496+
// faces and producers are enumerated in `registry-question.ts`.
14841497
if (objectRegistrationLayer) {
1485-
const registration = host.objectRegistrationRefusal(request.item, objectRegistrationLayer);
1498+
const registration = host.objectRegistrationRefusal(
1499+
request.item, objectRegistrationLayer,
1500+
{ againstRegistry: saveRegistryQuestion({ mode, writeFace: request.writeFace }) === 'against-registry' },
1501+
);
14861502
if (registration) throw registration;
14871503
}
14881504
if (singularType === 'view') {

‎packages/metadata-protocol/src/protocol.platform-store-system-opt-in.test.ts‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@
2727
*/
2828

2929
import { describe, expect, it } from 'vitest';
30+
// The protocol loads `@objectstack/lint` through a function-body
31+
// `import()` (`metadata-diagnostics.ts`). Paid here, at collection, so no
32+
// case's `testTimeout` window pays that first load
33+
// (`scripts/check-test-source-alias.mjs`, "The source reach").
34+
import '@objectstack/lint';
3035
import { assertEngineDeleteDispatch, assertEngineUpdateDispatch, assertEngineFindOnePredicate } from '@objectstack/metadata-core';
3136
import { ObjectStackProtocolImplementation } from './protocol.js';
3237
import { SysMetadataRepository } from './sys-metadata-repository.js';
@@ -360,7 +365,7 @@ describe('[#21908] the deny round — the platform-store calls still reaching th
360365
await protocol.publishMetaItem({ type: 'view', name: 'proj_task_grid' });
361366
});
362367
await expectSystemOptIn(calls, 'promoteDraftForPublish', () =>
363-
protocol.promoteDraftForPublish({ type: 'view', name: 'proj_task_grid' }).catch(() => undefined));
368+
protocol.promoteDraftForPublish({ type: 'view', name: 'proj_task_grid', registryQuestion: 'body-only' }).catch(() => undefined));
364369
});
365370

366371
it('the readers behind the history, audit, diff and commit doors', async () => {

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -618,6 +618,7 @@ import { ProtocolRegistryHydrationFacet } from './protocol-registry-hydration.js
618618
import { ProtocolSaveFacet } from './protocol-save.js';
619619
// [#29985 codemod] History, publish, drafts, publish backfill: the members below delegate to its facet, `ProtocolHistoryAndPublishFacet`.
620620
import { ProtocolHistoryAndPublishFacet } from './protocol-history-and-publish.js';
621+
import type { RegistryQuestion } from './registry-question.js';
621622
// [#29985 codemod] Package revert, duplicate, import, orphans, commits, revertCommit, rollback: the members below delegate to its facet, `ProtocolPackageCommitsFacet`.
622623
import { ProtocolPackageCommitsFacet } from './protocol-package-commits.js';
623624
// [#29985 codemod] Diff, deleteMetaItem, loadMetaFromDb, load reports, findReferencesToMeta: the members below delegate to its facet, `ProtocolDiffDeleteLoadFacet`.
@@ -3153,9 +3154,10 @@ export class ObjectStackProtocolImplementation implements
31533154
private objectRegistrationRefusal(
31543155
body: unknown,
31553156
layer: ReturnType<ObjectStackProtocolImplementation['classifyObjectContribution']>,
3157+
options: { againstRegistry?: boolean } = {},
31563158
): Error | null {
31573159
// [#29985 codemod] The body moved to `protocol-discovery-and-bases.ts`; it reaches this class through `protocol-host.ts`.
3158-
return ProtocolDiscoveryAndBasesFacet.objectRegistrationRefusal(protocolHost(this), body, layer);
3160+
return ProtocolDiscoveryAndBasesFacet.objectRegistrationRefusal(protocolHost(this), body, layer, options);
31593161
}
31603162

31613163
/** Docblock and body: {@link ProtocolDiscoveryAndBasesFacet.restoreTranslatedObjectEchoes} in `protocol-discovery-and-bases.ts` [#29985 codemod]. */
@@ -9669,6 +9671,8 @@ export class ObjectStackProtocolImplementation implements
96699671
* all address it, so the body judged is the body that goes live.
96709672
*/
96719673
member?: string;
9674+
/** The registry question this promotion asks (`registry-question.ts`). */
9675+
registryQuestion: RegistryQuestion;
96729676
}): Promise<{
96739677
singularType: string;
96749678
/**

0 commit comments

Comments
 (0)