docs(kernel): services.data 页的 Example 去掉 hook 语境混搭,并说清 Canonical source 为何是 SDK (#5944) - #5995
Merged
Merged
Conversation
…rce 为何是 SDK (#5944) 原 Example 把「hook 才有的 `ctx.input.contact_id`」和「hook 拿不到的 `services.data`」拼在一起。实测该块不是「在 hook 里跑得慢」而是根本不成立: 按 check:skill-examples 同款 tsconfig 编译,`services` 与 `ctx` 双双 TS2304 (Cannot find name),因为这两个名字在本运行时里没有任何一处同时在作用域内 —— hook 有 `ctx` 没 `services`,持有绑定的代码有 `services` 没 `ctx`。 复核 #5720 的结论在 origin/main 未变:engine.ts 四处 `hookContext` 构造点 (4796/4929/5505/6059)逐键构造 object/event/input/session/provenance/user/ api/transaction/ql,`buildSandboxContext`(runtime/src/sandbox/body-runner.ts) 同样只产 input/previous/user/session/event/object/result/api/log/crypto —— 两条路径都没有 `services` 键。 照 PR #5938 定下的模式改(取「去掉 `ctx.` 的 hook 味道」那一支): - Example 改写为**持有该绑定的代码**在调用(形状对齐 sharing-service.mdx 的 `mayEditContract(sharing: ISharingService, …)`):记录 id 作为普通入参传入, 全块无 `ctx`。顺带修掉两处误读 —— `get` 返回的是信封 `{ object, id, record }` 而非行本身(原文 `contact.id` 是撞对的),`find` 返回 `{ records, … }`。 - 新增 binding note Callout:hook 没有 `services` 键,其跨对象通道是 `ctx.api`, 并指向 examples.mdx 第 2 节(#5938 已进 os:check 真编译的那块),不在本页重复。 - 新增 `## Canonical source` 一节,答分诊点名的措辞问题:本页是全章唯一不指向 `contracts/*-service.ts` 的页,因为 spec 根本没有 `IDataService`;最近邻 `IDataEngine` 是形状不同的更低一层面(`find(objectName, query, options) : Promise<any[]>`)。故签名取 `ObjectStackClient.data`,返回体对应 spec 的 `*DataResponseSchema`(protocol.zod.ts),托管运行时按同一形状绑定。 os:check 标记:不补,且与 #5945 无关 —— 反向验证给出的是另一条硬约束。给该块 加标记后实测: content/docs/kernel/runtime-services/data-service.mdx:88:40 error TS2307: Cannot find module '@objectstack/client' or its corresponding type declarations. 仅此一条诊断。check:skill-examples 的 paths 由 `@objectstack/spec` 自己的 exports 派生,而 spec 不依赖 client,所以标记后只能改成手写 `DataService` 局部类型 —— 那样这块就只钉住它自己。此约束已写进正文,待本面有 spec 侧契约 可 import 时再补标记。本块从不触碰 `ctx.api`,故不受 #5945 裁决影响。 门禁:check:doc-authoring 362 文件干净;check:nul-bytes 5745 文件干净; check:docs-audit-scope 绿;check:skill-examples 207 块全绿(未变,本页不贡献 标记块也不产生 orphan)。Example 块单独对已构建的 @objectstack/client 声明 编译:tsc --noEmit 退出 0。MDX 以 @mdx-js/mdx 编译通过(examples.mdx / sharing-service.mdx 作阳性对照)。 Fixes #5944 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01BDmDsu2575gDxeMCxXhDE3
|
The latest updates on your projects. Learn more about Vercel for GitHub. 1 Skipped Deployment
|
This was referenced Aug 6, 2026
hotlong
marked this pull request as ready for review
August 6, 2026 14:20
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.
Fixes #5944
docs-only,单文件:
content/docs/kernel/runtime-services/data-service.mdx。前提复核(对
origin/main)前提成立,且比 issue 描述的更硬。原 Example 不是「在 hook 里会
TypeError」而是在任何语境下都不成立——按check:skill-examples同款 tsconfig 编译原块:ctx与services这两个名字在本运行时里没有任何一处同时在作用域内:hook 有ctx没services,持有绑定的代码有services没ctx。这正是该块把两个语境拼在一起的机器化证据。复核 #5720 的结论在
origin/main未变(628b028):packages/objectql/src/engine.ts四处hookContext构造点(4796 / 4929 / 5505 / 6059)逐键构造object/event/input/session/provenance/user/api/transaction/ql;packages/runtime/src/sandbox/body-runner.ts的buildSandboxContext只产input/previous/user/session/event/object/result/api/log/crypto;services键。packages/objectql/src/hook-input-shape-contract.test.ts是这批构造点的现存 pin 测试(HookContext.input的契约注释声明批量写携带input.ast,引擎从不设置它(AST 只在 opCtx 上);同一张表也未描述 #5038 后 after 事件的按行形状 #5273),未改动。改法(取 PR #5938 的第二支)
1. Example 改写为「持有该绑定的代码在调用」,形状对齐 #5938 给
sharing-service.mdx定的mayEditContract(sharing: ISharingService, …):记录 id 作为普通入参传入,全块无ctx。顺带修掉原块两处误读——get返回的是信封{ object, id, record }而不是行本身(原文contact.id是撞对的:信封的id恰好等于记录 id),find返回{ records, … }而原块拿到orders后就没再用。2. 新增 binding note Callout:hook 没有
services键,其跨对象通道是ctx.api,并指向examples.mdx第 2 节(#5938 已进os:check真编译的那块)。本页不重复那段 hook 代码——重复一份未被门看住的副本正是这一族缺陷的来源。3. 新增
## Canonical source一节,答分诊点名的措辞问题。本页是全章唯一不指向contracts/*-service.ts的页,而这个差异是真的、不是疏漏:spec 根本没有IDataService;最近邻IDataEngine(packages/spec/src/contracts/data-engine.ts)是形状不同的更低一层面——find(objectName, query, options): Promise< any[] >直打引擎,而不是本页记录的「对象名 + options」协议调用。故签名取ObjectStackClient.data,其返回体对应 spec 的GetDataResponseSchema/CreateDataResponseSchema/UpdateDataResponseSchema/DeleteDataResponseSchema(packages/spec/src/api/protocol.zod.ts),SDK 的*DataResult接口逐键镜像之;托管运行时按同一形状绑定services.data。os:check 标记:不补 —— 且与 #5945 无关
PM 交代此项取决于 #5945(
HookContext.api为z.unknown())的裁决。实测结果是另一条独立的硬约束,和 #5945 不沾边:本块从头到尾不触碰ctx.api。反向验证(先定方向再跑:预测「红,且诊断是模块解析而非类型错误」):给该块加上标记后,
仅此一条诊断,方向与预测一致。
check:skill-examples的paths由@objectstack/spec自己的exports派生,而 spec 不依赖 client,所以标记后只能把DataService改成手写局部类型——那样这块就只钉住它自己,是标准的 phantom check。此约束已如实写进正文,并说明「待本面有 spec 侧契约可 import 时再补标记」。⛔ 未改动任何类型声明文件。自验
check:doc-authoringcheck:nul-bytescheck:docs-audit-scopecheck:skill-examples@objectstack/client声明tsc --noEmit退出 0@mdx-js/mdx+ remark-gfm 通过(examples.mdx/sharing-service.mdx作阳性对照)Example 块虽然进不了
check:skill-examples(上节的模块解析约束),但它本身是真编译过的——只是那次编译得手工把@objectstack/client的 dist 声明喂进paths,门做不到这件事。Changeset
不带。docs-only,零 user-visible 运行时变更,按派发约定由验收时打
skip-changeset标签。关联:#5720 / PR #5938(同族,已定模式);#5945(
HookContext.api决策,本 PR 不受其约束也不抢跑);#5943(check:skill-examples禁块内any入参)。Generated by Claude Code