sveltelean Query
Version v0.2.0

Import

import
import { dehydrate, hydrate, kitInvalidate, source, sources } from '@svelte-lean/query/ssr';

Usage

src/lib/api/transport.ts
// src/lib/api/transport.ts
import { http } from '@svelte-lean/query/http';
import { source, sources } from '@svelte-lean/query/ssr';
import { getMember } from '$api/members';
import type { Member } from '$api/types';

// getMember is answered by a function (a remote function, an RPC call); the rest goes over HTTP.
export const transport = sources(
	[source(getMember, (params, signal) => readMember(Number(params.id), signal))],
	http({ base: '/' })
);

Size

Production Vite builds of a small consumer entry, Svelte external. A marginal row is the bytes the entry adds over the row it names.

BuildOvergzipbrotliBudget (gzip)
ssr (marginal)query568 B514 B700 B
ssr every export (marginal)query1287 B1178 B1500 B

Read from packages/query/artifacts/size.json. Every entry and its method: Performance.

Functions

No module state: request isolation is one client per request.

Exports

Runtime exports of the entry.

NameTypeDefaultDescription
# dehydrate (client: Client, options?: { endpoints? }) => Dehydrated–The successful entries of the client's scope whose access verdict is true, as a plain object.
# hydrate (client: Client, state: Dehydrated | Promise<Dehydrated> | null | undefined) => () => void–Apply records: each only when the entry has no value or an older one. Returns a function that drops the records not used yet.
# kitInvalidate (init: { invalidate }) => Module–Every invalidation calls SvelteKit's invalidate('slq:<Name>') and invalidate('slq:<Name>:<id>'), coalesced per microtask.
# source (endpoint, run: (params, signal) => R | Promise<R>) => Source–Pairs an endpoint with the function that answers it (a remote function, an RPC call).
# sources (list: Source[], fallback?: Transport) => Transport–A transport that answers the listed endpoints with their functions and the rest with fallback.

Types

What dehydrate() returns and what source() makes.

Dehydrated

A plain object the caller serializes (SvelteKit: devalue).

NameTypeDefaultDescription
# v 1–Format version.
# entries DehydratedEntry[]–The records.

DehydratedEntry

One committed value.

NameTypeDefaultDescription
# key string–Scope, endpoint id and canonical params (not a digest).
# value unknown–The value.
# updatedAt number–The server's commit time: freshness counts from the server fetch.
# bytes number–Approximate size.

Source

What source() returns.

NameTypeDefaultDescription
# endpoint QueryEndpoint | MutationEndpoint–The endpoint it answers.
# run (input, signal) => unknown–The function that answers it.

Guide

How to use it, with examples: Server rendering. All entry points: Svelte Lean Query.