用途:SvelteKit Remote Functions 是一份针对 SvelteKit 远程函数的指导技能,用于在 .remote.ts 文件中编写 command()、query()、form() 等模式。文件命名规则为使用 *.remote.ts 作为远程函数文件。
主要能力与选择:一次性动作使用 command(),重复读取使用 query(),表单使用 form()。示例:在 actions.remote.ts 中导入 { command } from '$app/server' 与 valibot,用 command(v.object({ id: v.string() }), async ({ id }) => { ... }) 定义 delete_user,并在客户端以 await delete_user({ id: '123' }) 调用。
使用方式与限制:远程函数在浏览器调用时于服务端执行;参数与返回值必须可 JSON 序列化;模式校验通过 StandardSchemaV1(Valibot/Zod);可用 getRequestEvent() 访问 cookies/headers;查询会被缓存,需用 .refresh() 获取新数据;不要把 .remote 文件放在 src/lib/server/ 下,否则无法工作。资料中提供 references/remote-functions.md 作为完整模式指南。最后验证日期为 2025-12-19。
适用场景:需要为 SvelteKit 项目设计安全的服务端调用、数据读取与表单处理的开发者。具体安装命令与收费信息暂未提供。