docs: document the client in the computed field context - #634
Conversation
Available since v3.9.1 (zenstackhq/zenstack#2789). Adds an "Accessing the Client" section covering the `client` property of the computed field context, and includes it in both callback signature blocks. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
|
Someone is attempting to deploy a commit to the ZenStack Team on Vercel. A member of the Team first needs to authorize it. |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
WalkthroughComputed field callback contexts now include ChangesClient-aware computed fields
Estimated code review effort: 1 (Trivial) | ~5 minutes Merge Risk: ⚪ Minimal · up to This is a localized documentation-only change with no actionable merge-blocking risk remaining after normal checks and review. 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches 💡 1🛠️ Fix failing CI checks 💡
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Documents the
clientproperty of the computed field context, added in v3.9.1 by zenstackhq/zenstack#2789.Changes
docs/orm/computed-fields.md:<AvailableSince version="v3.9.1" />) — whatcontext.clientis, theisMineexample readingclient.$auth, and how a$setAuth()-derived client evaluates the field against its own identity while the original stays anonymous. Links to Setting Auth User for the per-request client pattern.clientadded to both callback signature blocks (ComputedFieldCallbackandParameterizedComputedFieldCallback).clientis for reading per-client state rather than awaiting queries; and a note on why the example uses asql<boolean>fragment (see below).On the
sql<boolean>fragmentThe natural way to write
isMineiseb('authorId', '=', id), but that doesn't typecheck against aBoolean @computedfield. The generated stub returnsboolean, so the callback must returnOperandExpression<boolean>, while a Kysely comparison isSqlBool(boolean | 0 | 1):So the example uses
sql<boolean>and the tip lists the alternatives that also type correctly (eb.lit(),eb.case()). Happy to switch to whichever form you consider idiomatic — or drop the tip ifSqlBoolis something you'd rather accept inOperandExpressionon the ORM side.Verification
where: { isMine: true },findUniqueon both an authed and an anonymous client.Boolean @computedfield:eb.lit()/sql<boolean>/eb.case()pass, andclient.$auth?.idnarrows tonumber | undefined.npm run buildpasses (onBrokenLinks: 'throw'), so the anchor resolves.🤖 Generated with Claude Code
Summary by CodeRabbit
$setAuth()behavior, synchronous expression requirements, and boolean typing.