客户端
客户端
客户端是每个应用、自动化与远程函数用于读取、写入与调用的类型化界面。它从 $bolt/client 导入,由 bolt sync 生成,因此每次调用都会对照你的集合进行类型检查。
一个客户端,三个界面
客户端通过三个界面暴露工作区能做的所有事情:
| 界面 | 用途 |
|---|---|
client.db | 读取与写入——针对本地副本的实时查询、乐观变更与离线排队 |
client.invoke | 远程函数——从 src/functions/ 发现的带类型查询与命令处理器 |
client.automations | ——后台启动已声明的自动化并观察其持久运行,或审批待决的审批 |
客户端实战
同一个客户端驱动所有应用——读取、写入与调用都经由它:
import { client } from '$bolt/client';
// Live read — against the local replica, reactive to the change feed
const sites = client.db.sites.findMany({
where: { status: { eq: 'active' } },
orderBy: { name: 'asc' },
limit: 25
});
// Declarative write — Promise<void>; completion invalidates affected live queries
await client.db.site_visits.mutate({
site_id: siteId,
visited_at: new Date()
});
client.db.site_visits.pending; // numeric in-flight count
// Remote function — typed query or command handler
const forecast = await client.invoke.holiday_feed({ year: 2026 }); 实时数据
读取是 实时查询 ,针对按策略过滤的本地副本;浏览器写入使用每个集合的声明式 mutate(values) 界面(返回 Promise<void>)和数值 pending 计数。
AI
模型访问经由 ai 设施 ——宿主绑定提供商,租户代码永远看不到凭据。
边界
- 客户端从不接触服务器端缓存 API。
- 应用无法访问私有运行时设施。
- 生成的客户端是进入工作区的唯一合规数据路径。