Remote functions
Remote functions
Functions are typed server entrypoints — the way an app asks the server for something a live query or a mutation cannot express. They are authored as src/functions/+<lower_snake_case>.ts ; the filename is the canonical function ID and becomes the generated client.invoke property. No registration module exists.
Definition
import { defineQueryHandler } from '@norbital-ai/bolt/authoring';
import { Effect, Schema } from 'effect';
export default defineQueryHandler({
description: 'Counts the visits recorded against one site.',
schema: Schema.Struct({ site_id: Schema.String }),
handler: ({ site_id }, api) =>
Effect.gen(function* () {
return yield* api.db.site_visits.count({
where: { site_id: { eq: site_id } }
});
})
}); Save this query as src/functions/+visit_count.ts , then call it from an app through the generated client boundary:
import { client } from '$bolt/client';
const count = client.invoke.visit_count({ site_id: selectedSite }); Queries and commands
defineQueryHandler— reactive, read-only server computationdefineCommandHandler— imperative work that may mutate data
Prefer the collection write contract for mutation invariants and automations for scheduled or event-driven background work. Functions are for server computation with a typed request/response contract.
Who may call them
A signed-in session or a host system signature may call invoke.<name>. Dispatch does not require a separate invoke:<name> policy grant. The handler still runs as the caller, so every collection, file, and approval check inside the function is the caller’s policy.