Repository navigation
Commit 0c0ede0
fix(client): subscribeData delivers data.record.restored, reading its event types from the spec (#31509)
<!-- claude-projects-attribution: {"github_login":"os-project-manager"}
-->
_Requested by **Leehom** · [project
thread](https://claude.ai/code/project/chan_01TenzsRopZj4jMbvjX8uz1X?thread=cmsg_01TenzsRopZj4jMbvjX8uz1X2kM3DQTy5XByDHKN47ZrVA)_
domain:server#5 · os-project-manager · session_01FEkQ5mbAyTfp7gbjowRA48
Fixes #31473
Clause-②: yes (widening) — `RealtimeAPI.subscribeData` now delivers
every per-record event type the spec's `DataEventType` declares, which
adds `data.record.restored` (a row restored from the recycle bin) to the
created / updated / deleted it delivered before. `subscribeBulkData`
reads `BulkDataEventType` the same way; its two types are unchanged.
Metadata-protocol: none
## 维护者速读
- **改了什么**: `@objectstack/client` 的 `subscribeData` /
`subscribeBulkData` 订阅的事件类型改为直接读 spec 的 `DataEventType` /
`BulkDataEventType` 枚举,不再手写列表;回收站恢复产生的 `data.record.restored` 因此能送达订阅者。
- **为什么改**: #31220 给 `DataEventType` 加了 `restored`,但 SDK 手写的
created/updated/deleted 列表把它过滤掉,订阅者的实时列表看不到被恢复的记录 (#31473)。
- **风险与回滚**: 只多送一种事件;按 `event.type` 分支的回调会多看到 `data.record.restored`(载荷
`after` 带恢复后的行)。客户端本就运行时依赖 `@objectstack/spec/api`,无新依赖。回滚即 revert 本 PR。
- **先看**: `packages/client/src/realtime-api.ts` 中 `subscribeData` 与
`subscribeBulkData` 的 `eventTypes`。
- **两分钟验证**: `cd packages/client && npx vitest run
src/realtime-api-data-event-types.test.ts`,预期 4 个用例全过 (在 main 上 3 个红)。
- **需要你做的**: 无,席位落地。
## What changes
- `subscribeData` asked for `['data.record.created',
'data.record.updated', 'data.record.deleted']`, written by hand.
`data.record.restored`, which ObjectQL's recycle-bin restore publishes
with the restored row in `after` and which #31220 added to
`DataEventType`, matched no subscription filter and was dropped. It now
asks for `[...DataEventType.options]`.
- `subscribeBulkData` kept the same kind of hand list
(`['data.records.updated', 'data.records.deleted']`). It now asks for
`[...BulkDataEventType.options]`; its two types are unchanged. No other
client code lists data event types.
- **Restored joins the default list rather than an opt-in.** The triage
left that to the lane. A restore is the inverse of a delete the
subscriber already receives, and the callback is typed `(event:
DataEvent) => void`, whose `type` is `DataEventType`. Delivering the
whole enum makes the subscription mean what its type says, and a list
that rebuilds itself from created / deleted needs the restore to stay
correct.
- **No new dependency.** `realtime-api.ts` already imports runtime
values (`DataEventSchema`, `BulkDataEventSchema`) from
`@objectstack/spec/api`, so the two enums come from a module the client
already loads. The published dependency set and the imported module are
unchanged.
- Changeset `31473-client-subscribe-data-restored.md`:
`@objectstack/client` patch (`Metadata-protocol: none`, ruling A).
## Tests
New `packages/client/src/realtime-api-data-event-types.test.ts`:
- ⭐ a row restored from the recycle bin reappears in the subscriber's
list: created → deleted → restored, the callback's list ends with the
row.
- ⭐ every `DataEventType` member reaches `subscribeData` (read from the
enum, so a type added later is covered without editing the test).
- every `BulkDataEventType` member reaches `subscribeBulkData` (green on
main too; it keeps the bulk list honest from here on).
- ⭐ `realtime-api.ts` spells no `data.record(s).*` type as a string
literal and reads both enums.
Red on main (2ae3e30, test file only): `Tests 3 failed | 1 passed (4)`:
```
× ⭐ a row restored from the recycle bin reappears in the subscriber's list
AssertionError: expected [] to deeply equal [ 'task_1' ]
× ⭐ every DataEventType the spec declares reaches subscribeData
AssertionError: expected [ 'data.record.created', …(2) ] to deeply equal [ 'data.record.created', …(3) ]
× ⭐ realtime-api.ts keeps no hand list of data event types
```
Ablation (`scripts/ablation-replace.mjs` on committed `ec765f5d`,
`subscribeData`'s `eventTypes: [...DataEventType.options]` put back as
the old three-item hand list): `ok mutation landed: anchor 1 -> 0, blob
444fe4c -> 5bcbff9269d0`, the same three pins red (`Tests 3 failed
| 1 passed (4)`), then `ok restored: blob == HEAD (444fe4c) and git
diff HEAD is empty`.
## Acceptance notes
- The handler's comment still says `data.field.changed` is "declared in
`DataEventType`". The enum no longer lists it. Left as is because it is
outside this card's surface. Noted, not filed.
## Verification
- Head `cba18d92`; cut from fresh origin/main `2ae3e301`, with
origin/main `7d0b47ca` merged before opening (no file overlap with this
diff; the three realtime test files re-ran green after the merge,
26/26).
- `pnpm --filter @objectstack/client test` under `os-verify-lock`:
`VERDICT command-exit 0`, Test Files 56 passed (56), Tests 716 passed
(716).
- `pnpm --filter @objectstack/client typecheck` (`tsc --noEmit` and
`check:test-typecheck`): exit 0. `eslint` on the two touched `.ts`
files: exit 0.
- Gates from `node scripts/pm/dispatch-gates.mjs --commands --repo
objectstack-ai/objectstack`: 61 derived, 61 run, all exit 0 (`--ran`: 0
NOT-MEASURED). Two first read exit 3 (`check:skill-examples`,
`check:dual-build-cjs-loads`: a prerequisite, built output missing in a
fresh worktree). After `pnpm --filter './packages/**' run build` under
the lock, both exited 0. Record:
`/mnt/project-files/pm-orders/server/31473-gates-ran.txt`.
## Human Minimum
- [x] 1. Schemas start as Zod; `packages/spec` holds no runtime logic.
(not touched)
- [x] 2. Every name I added uses the casing for its kind.
- [x] 3. No formatter ran; `pnpm lint` passes. (eslint on the two
touched `.ts` files: exit 0)
- [x] 4. One issue, one branch off an up-to-date `main`, one pull
request.
- [x] 5. A change that publishes carries a changeset, and both
declaration lines are filled in here and in the changeset.
(`.changeset/31473-client-subscribe-data-restored.md`,
`@objectstack/client` patch)
- [x] 6. `packages/spec` touched: its generated artifacts are
regenerated and committed. (not touched)
- [x] 7. No hand edits to `content/docs/references/`,
`packages/*/CHANGELOG.md` or `content/docs/releases/`.
- [x] 8. Title, body and comments are in English. (the 维护者速读 block is
the lane's required Chinese summary)
- [x] The *Before Submitting* list in CONTRIBUTING.md is done.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
https://claude.ai/code/session_01FEkQ5mbAyTfp7gbjowRA48
---
_Generated by [Claude
Code](https://claude.ai/code/session_01FEkQ5mbAyTfp7gbjowRA48)_
<!-- signed: domain:server#5 · os-project-manager ·
session_01FEkQ5mbAyTfp7gbjowRA48 -->
---------
Co-authored-by: Claude <noreply@anthropic.com>1 parent ec29753 commit 0c0ede0
3 files changed
Lines changed: 129 additions & 6 deletions
File tree
- .changeset
- packages/client/src
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 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 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
| 15 | + | |
| 16 | + | |
15 | 17 | | |
16 | 18 | | |
17 | 19 | | |
| |||
142 | 144 | | |
143 | 145 | | |
144 | 146 | | |
145 | | - | |
146 | | - | |
147 | | - | |
148 | | - | |
149 | | - | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
150 | 152 | | |
151 | 153 | | |
152 | 154 | | |
| |||
224 | 226 | | |
225 | 227 | | |
226 | 228 | | |
227 | | - | |
| 229 | + | |
| 230 | + | |
228 | 231 | | |
229 | 232 | | |
230 | 233 | | |
| |||
0 commit comments