Skip to content

Commit 28eb299

Browse files
committed
fix(spec): keep the hook-body capability table out of the strictness block's way
check:docs failed on the previous commit (inside the "TypeScript Type Check" job — tsc itself was clean). The regenerated reference page had REPLACED the whole capability-token table in content/docs/references/data/hook-body.mdx with one line: "Keys `ExpressionBodySchema` declares (drift-guarded by ...)". build-docs.ts takes the FIRST JSDoc in a module as that page's blurb. Putting the strictness constants — which carry `/** … */` per the approval.zod.ts house style — above `HookBodyCapability` handed its documentation slot to a private constant, silently deleting the `api.read` / `api.write` / `api.transaction` / `crypto.*` / `log` reference table authors actually read. Moved the block below `HookBodyCapability` and left a placement note so the next person adding a documented constant to this file does not rediscover it. Regenerating now leaves content/docs/references untouched; check:docs passes. The other two files were never at risk — their first JSDoc sits above the imports, so the inserted block could not take the slot. That is also why only this one page moved. Verified: check:docs green, full spec suite 7136 green. Refs #4001 Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0147tNF4Snk7Ry1KGt4a5PY4
1 parent af6afda commit 28eb299

1 file changed

Lines changed: 35 additions & 29 deletions

File tree

packages/spec/src/data/hook-body.zod.ts

Lines changed: 35 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,35 @@
33
import { z } from 'zod';
44
import { strictUnknownKeyError } from '../shared/suggestions.zod';
55

6+
/**
7+
* Capability tokens a script body may request.
8+
*
9+
* The runtime sandbox enforces these — if a body uses a `ctx` API that requires
10+
* a capability it did not declare, the call throws at invocation time.
11+
*
12+
* - `api.read` — `ctx.api.object(...).find / findOne / count / aggregate`
13+
* - `api.write` — `ctx.api.object(...).insert / update / delete`
14+
* - `api.transaction` — `ctx.api.transaction(async () => { … })` — runs the
15+
* callback's `ctx.api` writes/reads inside one driver transaction, committed
16+
* on return and rolled back if the callback throws. Requires `api.write`
17+
* alongside it to be useful (the transaction body still needs write access).
18+
* - `crypto.uuid` — `ctx.crypto.randomUUID()`
19+
* - `crypto.hash` — `ctx.crypto.hash(algo, data)`
20+
* - `log` — `ctx.log.info / warn / error`
21+
*
22+
* `http.fetch` is intentionally absent — outbound calls go through Connector
23+
* recipes (separate spec) so they remain auditable and replayable.
24+
*/
25+
export const HookBodyCapability = z.enum([
26+
'api.read',
27+
'api.write',
28+
'api.transaction',
29+
'crypto.uuid',
30+
'crypto.hash',
31+
'log',
32+
]);
33+
export type HookBodyCapability = z.infer<typeof HookBodyCapability>;
34+
635
/*
736
* ── Unknown-key strictness (#4001 data step) ────────────────────────────────
837
*
@@ -21,6 +50,12 @@ import { strictUnknownKeyError } from '../shared/suggestions.zod';
2150
* The L1 schema additionally PRESCRIBES the L2-only keys rather than guessing a
2251
* rename: `capabilities` on an `expression` body is not a typo, it is a
2352
* misunderstanding of which level owns the key.
53+
*
54+
* Placement note: this block sits AFTER `HookBodyCapability` on purpose.
55+
* build-docs.ts takes the file's FIRST JSDoc as the reference page's module
56+
* blurb, so a `/** … *\/` comment above the capability enum silently replaced
57+
* the whole capability-token table in content/docs/references/data/hook-body.mdx.
58+
* Keep declarations that carry JSDoc below the first exported symbol here.
2459
*/
2560

2661
/** Keys {@link ExpressionBodySchema} declares (drift-guarded by hook-body.test.ts). */
@@ -65,35 +100,6 @@ const scriptBodyUnknownKeyError = strictUnknownKeyError({
65100
+ 'limits or grants that were written.',
66101
});
67102

68-
/**
69-
* Capability tokens a script body may request.
70-
*
71-
* The runtime sandbox enforces these — if a body uses a `ctx` API that requires
72-
* a capability it did not declare, the call throws at invocation time.
73-
*
74-
* - `api.read` — `ctx.api.object(...).find / findOne / count / aggregate`
75-
* - `api.write` — `ctx.api.object(...).insert / update / delete`
76-
* - `api.transaction` — `ctx.api.transaction(async () => { … })` — runs the
77-
* callback's `ctx.api` writes/reads inside one driver transaction, committed
78-
* on return and rolled back if the callback throws. Requires `api.write`
79-
* alongside it to be useful (the transaction body still needs write access).
80-
* - `crypto.uuid` — `ctx.crypto.randomUUID()`
81-
* - `crypto.hash` — `ctx.crypto.hash(algo, data)`
82-
* - `log` — `ctx.log.info / warn / error`
83-
*
84-
* `http.fetch` is intentionally absent — outbound calls go through Connector
85-
* recipes (separate spec) so they remain auditable and replayable.
86-
*/
87-
export const HookBodyCapability = z.enum([
88-
'api.read',
89-
'api.write',
90-
'api.transaction',
91-
'crypto.uuid',
92-
'crypto.hash',
93-
'log',
94-
]);
95-
export type HookBodyCapability = z.infer<typeof HookBodyCapability>;
96-
97103
/**
98104
* L1 — Pure expression body.
99105
*

0 commit comments

Comments
 (0)