Skip to content

Remote functions

Remote functions

Remotes 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 remote 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.query.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 computation
  • defineCommandHandler — imperative work that may mutate data

Prefer collection hooks for mutation side effects and automations for scheduled or event-driven background work. Remotes are for server computation with a typed request/response contract.