feat(client): 类型化 data.batchTransaction() —— master-detail 保存统一走原子跨对象批量(#1604 / ADR-0034 item 4)#3271
Merged
Conversation
…ch SDK surface (#1604 / ADR-0034 item 4) master-detail 保存统一走原子 batchTransaction:给 @objectstack/client 增加 data.batchTransaction(operations)(含环境作用域镜像),类型化封装 POST {basePath}/batch 全有或全无跨对象事务端点,支持 { $ref: <opIndex> } 批内父引用。方法恒原子、不暴露 atomic 参数——非原子 per-object 批量保留在 data.batch()/createMany/updateMany,best-effort 回退只能隔离在调用方 (ObjectUI masterDetailTx)适配器里,SDK 不承载。 - 复用并 re-export spec 契约类型 CrossObjectBatchOperation/Request/Response - 单测 6 例(URL/payload、$ref 透传、双响应形态解包、discovery 路由推导、 错误整形、scoped 镜像)+ 端到端 4 例(client→hono→rest→engine 全链路, 含 BATCH_UNRESOLVED_REF 错误映射与 BATCH_NOT_ATOMIC 契约 pin) - 文档:client-sdk.mdx / http-protocol.mdx 互链;ADR-0034 §4 补状态注 (framework 侧完成,objectui 重指 masterDetailTx 为跨仓库 follow-up) Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01QCrTB7b5qFX2yyHJEGB5xa
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Contributor
📓 Docs Drift CheckThis PR changes 1 package(s): 12 hand-written doc(s) reference the affected code and may need an implementation-accuracy re-verification:
|
os-zhuang
marked this pull request as ready for review
July 19, 2026 16:10
This was referenced Jul 19, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
背景
承接 #1604 与 ADR-0034 item 4:服务端原子跨对象批量端点(
POST {basePath}/batch,单引擎事务、{ $ref: <opIndex> }批内父引用、逐对象 API 曝光鉴权)已落地,但@objectstack/clientSDK 没有对应的类型化方法——objectui 的masterDetailTx适配器要走原子路径只能手写 fetch。本 PR 补上 framework 侧缺口,让原子 batchTransaction 成为 master-detail 保存的一等公民 SDK API。改动
packages/client/src/index.ts:新增client.data.batchTransaction(operations)与环境作用域镜像client.project(id).data.batchTransaction(operations)。CrossObjectBatchOperation/Request/Response(@objectstack/spec/api)。atomic参数——类型上无法表达非原子请求(服务端对atomic:false也会 400BATCH_NOT_ATOMIC)。非原子 per-object 批量保留在data.batch()/createMany/updateMany;best-effort 回退只能隔离在调用方(ObjectUImasterDetailTx)适配器里,SDK 不承载——这是"非原子回退隔离进适配器"的类型化表达。${basePath}/batch),客户端从getRoute('data')去末段推导,兼容 discovery 覆写的自定义路由;不给ApiRoutesSchema加 key(避免 3+ 个 discovery 生产方同步、declared-but-unpopulated 路由)。client.test.ts):URL/payload、$ref透传、裸/信封双响应形态解包、discovery 路由推导、错误整形(code/httpStatus)、scoped 镜像。client.batch-transaction.test.ts,LiteKernel + Hono 真实服务):父+子$ref落库且 FK 等于父 id、scoped 路由、BATCH_UNRESOLVED_REF全链路错误映射、atomic:false→ 400BATCH_NOT_ATOMIC契约 pin。文件头注明 InMemoryDriver 事务为 passthrough,回滚原子性由engine-ambient-transaction.test.ts/rest-batch-endpoint.test.ts覆盖。content/docs/api/client-sdk.mdx增加原子跨对象批量示例并互链http-protocol.mdxBatch Operations;ADR-0034 §4 补状态注(framework 侧完成)。@objectstack/clientminor。验证
pnpm --filter @objectstack/client build✅(DTS 通过)pnpm --filter @objectstack/client test✅ 4 files / 109 tests(含新增 10 例)pnpm --filter @objectstack/rest test✅ 19 files / 323 tests(相邻回归)跨仓库 follow-up(不在本 PR)
objectui 仓库:
masterDetailTx/data-objectstack适配器改为调用client.data.batchTransaction(以$ref组 operations),删除客户端 best-effort 清理;非原子顺序回退(面向无该端点的旧服务器,按error.httpStatus === 404特性探测)只保留在该适配器内部。🤖 Generated with Claude Code
https://claude.ai/code/session_01QCrTB7b5qFX2yyHJEGB5xa
Generated by Claude Code