Skip to content

Remote functions

Remote functions

Remotes are typed server entrypoints authored as src/remotes/+<lower_snake_case>.ts. The filename is the canonical remote ID and becomes the generated api.invoke property; no registration module exists.

Definition

import { defineQueryHandler } from '@norbital-ai/pod/authoring';
import { z } from 'zod';

export default defineQueryHandler({
  schema: z.object({ site_id: z.string() }),
  handler: async ({ site_id }, api) =>
    api.db.site_visits.count({ where: { site_id: { eq: site_id } } })
});

Save this query as src/remotes/+visit_count.ts, then call it from an app through the generated client boundary:

import { api } from '$pod/client';

const count = api.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.