Repository navigation
Commit 6e0b16a
feat(objectql,metadata-protocol,rest,spec): the object read names the objects a delete can cascade into (#28451)
domain:server#2 · os-project-manager · session_0186vfjHHMsRXC9EUT9hTFMo
<!-- claude-projects-attribution: {"github_login":"os-project-manager"}
-->
_Requested by **Leehom** · [project
thread](https://claude.ai/code/project/chan_01TenzsRopZj4jMbvjX8uz1X?thread=cmsg_01TenzsRopZj4jMbvjX8uz1XBu9BsFDDrJayyDodXhfHC4)_
Part of #28001 (the server half of ruling B; the ui half, the delete
confirmations that read this key, is its own `domain:ui` card, blocked
by this PR).
Clause-②: yes (widening) — a new optional key served beside the object
read (`cascadeDeleteObjects`, both item doors and the app bundle's
object entries), a new optional `IObjectQLEngine` member and a new
public `ObjectQL` method. Nothing is refused that ran before.
Metadata-protocol: added — the served key `cascadeDeleteObjects` moves
the `api` authorable-surface shard
(`packages/spec/authorable-surface/api.json`), which
`scripts/check-changeset-no-major.mjs` reads as an added protocol key;
`@objectstack/spec` is graded `minor` (the #27842 / #27964 shape).
Nothing an author can write moves: the key is served beside `item`,
never inside it, and has no authorable spelling.
Skills-docs: none — a served-only key; no `skills/**` text names
`cascadeDeleteObjects` or `disabledActions`.
## 维护者速读
- **改了什么**:`GET /api/v1/meta/object/:name`(缓存默认门与非缓存门,以及 app bundle
里每个对象条目)在 `item` 旁边多返回一个
`cascadeDeleteObjects`:删除这个对象的一条记录时会被级联一起删掉的对象名列表(主从子对象默认算,lookup/tree
只有声明 `deleteBehavior: 'cascade'` 才算,孙辈对象也算,`restrict` / `set_null`
不算)。列表由引擎 `ObjectQL.getCascadeDeleteObjects`
给出,它和删除流程共用同一个「哪些关系会级联」的扫描函数。
- **为什么改**:#28001 裁决
B:删除确认框要加一行说明「这还会删掉哪些子对象」,列表必须来自服务端、不能在前端复制一份引擎规则;服务端这一半先落。HotCRM
里删一条线索会悄悄删掉它的活动成员记录。
-
**风险与回滚**:只加不减;删除本身行为不变(现有级联删除测试照旧绿)。只读注册表、不读任何行,所以不会泄露记录或数量;只给对象名、不给字段名(字段可能被另一对象的
ADR-0106 掩码隐藏)。缓存门把列表折进 ETag,后注册的级联对象会让 ETag 变。回滚即 revert。
-
**先看**:`packages/objectql/src/engine-delete-cascade.ts`(`cascadeRelationsInto`
抽出与
`collectCascadeDeleteObjects`);`packages/metadata-protocol/src/protocol.ts`(`resolveCascadeDeleteObjects`
与 `getMetaItemCached` 的 304
退让);`packages/rest/src/meta-item-read-routes.ts`(ETag 折叠)。
- **两分钟验证**:`pnpm --filter @objectstack/objectql exec vitest run
src/engine-cascade-delete-objects.test.ts` → 7 passed,其中 `cd_parent` 答
`['cd_child', 'cd_grandchild']`,restrict / set_null 兄弟不在列。
- **需要你做的**:无,席位落地(触及 `packages/spec/**`,席位先做合约评审)。
## What changes
### The shape, measured and chosen
- **Object-level, not record-level.** The confirmation names child
*objects*. `ObjectQL.getCascadeDeleteObjects(object)` reads the registry
and no row, so it says what a delete MAY remove, never which records or
how many. `inspectCascadeDelete` (record-level, reads as SYSTEM with no
organization) is untouched and is not exposed anywhere.
- **Transitive, the walk's own closure.** Breadth-first from the object
through every relation whose resolved behaviour is `cascade`, each
object named once at the first depth that reaches it and expanded once,
so a cycle (a self-cascading `tree`, two objects cascading into each
other) terminates. The object itself is named only when a cascading
relation leads back to it.
- **One rule.** The collection walk's scan of "which relations cascade
into this object" (`cascadingInto` inside `collectCascadeDeleteSet`) is
lifted out unedited as `cascadeRelationsInto`, and both
`collectCascadeDeleteSet` and the new `collectCascadeDeleteObjects` call
it. It reads `cascadeRelationBehavior(target, child, fieldName, fdef)
=== 'cascade'`, the predicate the delete runs. No copy of the rule lives
in rest, runtime, metadata-protocol or spec.
- **Where it is served: beside the object item read, on
`disabledActions`' (#27842 / #28044) terms.** The console's grid and
record page read `GET /meta/object/:name`
(`ObjectStackAdapter.getObjectSchema`) or the app bundle's object
entries, so a key on that answer needs no second request; a new read
route would add a route-ledger row and a second round trip. Precisely as
`disabledActions` does:
- the protocol reads the engine's optional
`IObjectQLEngine.getCascadeDeleteObjects` through the kernel's service
table by name (`objectql`), per call, and imports no engine;
- served face only: absent on the execution face and on a draft read;
absent on the list read (`GET /meta/object`), since the confirmations
read the item;
- absent where no engine answered (no engine, an engine without the
member, an object the registry does not hold), `[]` where the engine
answered that nothing cascades;
- on the cached default door too: `getMetaItemCached` carries it beside
`data` and stands its own 304 down for a read that carries it; the REST
door folds the served list into the object read's ETag, so an unchanged
object with an unchanged cascade revalidates to 304, and an object
registered later that cascades into it moves the ETag. An object no
engine answered for keeps its old validator byte for byte.
- The app bundle's object entries are item answers (`getMetaItem`
through `createMetaItemAnswer`), so they carry the key with no change to
the bundle route.
- **Object names, not fields.** The order's hypothesis was one entry per
object with the field carrying the edge. Measured: a field of another
object can be withheld from this caller by that object's ADR-0106 mask
(D1 removes an unreadable field whole, its existence included), while an
object read withholds no object (`createMetaItemReadGate`'s `object` arm
prunes only `listViews`; measured on this tree, a member with no nav
reach to `secret_deal` is answered `200` on `GET
/meta/object/secret_deal`). Serving field names would disclose masked
fields; serving object names discloses nothing an object read does not.
One entry per object also absorbs an object reached by two fields. The
ui half shows object labels, which the client resolves from names; no
translated text is served.
- **Typed in spec.** `GetMetaItemResponseSchema` and
`GetMetaItemCachedResponseSchema` gain the optional
`cascadeDeleteObjects: string[]`, documented beside `disabledActions`.
`IObjectQLEngine` gains the optional
`getCascadeDeleteObjects?(objectName): string[] | undefined`.
### Files
- `packages/objectql/src/engine-delete-cascade.ts`:
`cascadeRelationsInto` (lifted from `collectCascadeDeleteSet`),
`collectCascadeDeleteObjects`.
- `packages/objectql/src/engine.ts`: public `getCascadeDeleteObjects`.
- `packages/spec/src/contracts/objectql-engine.ts`,
`packages/spec/src/api/protocol.zod.ts`: the member and the key.
- `packages/metadata-protocol/src/protocol.ts`:
`resolveCascadeDeleteObjects`, the item read's envelope,
`getMetaItemCached`.
- `packages/rest/src/meta-item-read-routes.ts`: the cached arm carries
it and folds it into the ETag.
- `content/docs/references/api/protocol.mdx`, `app-bundle.mdx`:
regenerated (`gen:docs`).
- Tests: `packages/objectql/src/engine-cascade-delete-objects.test.ts`,
`packages/metadata-protocol/src/protocol.object-cascade-delete-objects.test.ts`,
`packages/rest/src/meta-object-cached-cascade-delete-objects.test.ts`, a
`[#28001]` block in `packages/rest/src/meta-app-bundle-routes.test.ts`
and in `packages/spec/src/api/meta-item-response-shapes.test.ts`.
- `.changeset/28001-cascade-delete-objects-beside-item.md`: `minor` for
spec; `patch` for objectql, metadata-protocol, rest.
## Tests
- **Red first** (production sources restored to `origin/main`
`4bc077d2`, objectql and metadata-protocol `dist/` rebuilt from them,
tests kept): `engine-cascade-delete-objects.test.ts` 7/7 failed;
`protocol.object-cascade-delete-objects.test.ts` 5 failed, 4 passed (the
four controls: no key without an engine, other types, execution face,
the list); `meta-object-cached-cascade-delete-objects.test.ts` 3 failed,
3 passed (the no-key control and the unchanged-validator 304 controls);
`meta-item-response-shapes.test.ts` 4 failed, 28 passed. The restore
leg's `git diff HEAD` was empty.
- **Green** on head: the fixture `cd_parent` ← `cd_child`
(master_detail, default cascade) ← `cd_grandchild` (lookup,
`deleteBehavior: 'cascade'`), with a `restrict` sibling (`cd_pin`), a
`set_null` sibling (`cd_tag`) and a default-`set_null` lookup on the
child (`cd_note`): `cd_parent` answers `['cd_child', 'cd_grandchild']`,
`cd_child` answers `['cd_grandchild']`; the self-cascading `cd_folder`
answers `['cd_folder']`; `cd_loner` answers `[]`; an unknown object
`undefined`. The real protocol over the real engine serves the same list
on both doors, `[]` for `cd_loner`, nothing on the execution face, and
an object registered later that cascades into `cd_loner` is on the next
read.
- **Agreement with the delete:** a real `delete()` of a `cd_parent`
record empties exactly `cd_child` and `cd_grandchild`, leaves the
`set_null` holders standing, and equals the served list.
- **Ablation** (`scripts/ablation-replace.mjs`, src-resolved suite,
restore proven `blob == HEAD`, `git diff HEAD` empty): replacing
`cascadeRelationsInto.call(this, target, objects)` in
`collectCascadeDeleteObjects` with a hand-written lookup-only filter
(`type === 'lookup' && deleteBehavior === 'cascade'`) reds the
master_detail case (`expected [] to deeply equal [ 'cd_child',
'cd_grandchild' ]`) and the self-cascading tree case, while
`engine-cascade-delete.test.ts` (the delete itself) stays green. The
protocol-door rows of that run read a stale base `dist/` from the red
leg and are not counted.
- **Controls:** the delete is unchanged
(`engine-cascade-delete.test.ts`,
`engine-inspect-cascade-delete.test.ts` green); an object with no
cascading children answers `[]`; no engine answer serves no key and
keeps the old ETag.
## Acceptance notes
- ~~`Metadata-protocol: none` with `patch` everywhere~~ [Edit by the
seat: the contract review (6546633648) ruled option B. The changeset
gate refuses `none` whenever an authorable-surface shard moves, so head
7f3638c declares `Metadata-protocol: added` and grades
`@objectstack/spec` `minor`, as the `disabledActions` precedent did.]
- The list read (`GET /meta/object`) does not carry the key. The
confirmations read the item; adding it to the list is a widening with no
reader yet.
- Order-of-reach is the walk's breadth-first order; the ui half may sort
by label.
## Verification
Local runs. The package suites and the first 88 derived gates ran on
`81f57815`; the last commit, `8bfac916`, adds only the engine-double
ledger pin, after which `check:engine-double-contract` and the 30
families it added to the derivation ran on `8bfac916`:
- `pnpm --filter @objectstack/objectql run test` exit 0, 9836 passed;
`typecheck` exit 0.
- `pnpm --filter @objectstack/metadata-protocol run test` exit 0, 21881
passed, 26 skipped; `typecheck` exit 0.
- `pnpm --filter @objectstack/rest run test` exit 0, 6870 passed, 332
skipped; `typecheck` exit 0.
- `pnpm --filter @objectstack/spec run test` exit 0, 22834 passed, 1
todo; `typecheck` exit 0.
- `@objectstack/runtime`
`src/domains/meta-list-projection-parity.test.ts` and
`src/domains/meta*`: 29 files, 1425 passed.
- `pnpm --filter @objectstack/spec check:generated`: `check:docs` stale
before `gen:docs`, regenerated and committed; the other 13 artifacts up
to date.
- Derived gates (`node scripts/pm/dispatch-gates.mjs --commands --repo
objectstack-ai/objectstack`): reconciled with `--ran`, `118 derived
famil(ies) accounted for — 117 run, 1 NOT-MEASURED`. Every run family
exit 0, after two fixes in this PR: `check:engine-double-contract` first
answered exit 1 (`RETAINED [findOne]` for the new metadata-protocol
double: new coverage the ledger must learn), fixed by `node
scripts/check-engine-double-contract.mjs --write`
(`scripts/engine-double-contract.pinned.json`, +1 row) and re-run exit
0; `check-plugin-teardown-shape.mjs --self-test` first answered exit 3
on the shallow clone and exit 0 after fetching its positive-control
commit.
- NOT MEASURED: `pnpm check:dual-build-cjs-loads` (exit 3, PREREQUISITE
NOT MET: it needs every package's `dist/`, this worktree built only the
touched closures). CI runs it.
- `pnpm exec eslint --no-inline-config packages/objectql
packages/metadata-protocol packages/rest packages/spec`: exit 0.
- Dogfood battery: not run (no `!` in the title, no `(narrowing)` arm).
`test:repo` projects: declared to CI (Test Core).
---
_Generated by [Claude
Code](https://claude.ai/code/session_01FEkQ5pEcJ17rvFVfE3NXzN)_
---------
Co-authored-by: Claude <noreply@anthropic.com>1 parent 36436fa commit 6e0b16a
16 files changed
Lines changed: 950 additions & 24 deletions
File tree
- .changeset
- content/docs/references/api
- packages
- metadata-protocol/src
- objectql/src
- rest/src
- spec
- authorable-surface
- src
- api
- contracts
- scripts
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1335 | 1335 | | |
1336 | 1336 | | |
1337 | 1337 | | |
| 1338 | + | |
1338 | 1339 | | |
1339 | 1340 | | |
1340 | 1341 | | |
| |||
1462 | 1463 | | |
1463 | 1464 | | |
1464 | 1465 | | |
| 1466 | + | |
1465 | 1467 | | |
1466 | 1468 | | |
1467 | 1469 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
0 commit comments