sveltelean Query
Version v0.2.0

Import

import
import { laravel, formData, hasFiles } from '@svelte-lean/query/laravel';

Usage

src/lib/api/transport.ts
// src/lib/api/transport.ts
import { http } from '@svelte-lean/query/http';
import { laravel } from '@svelte-lean/query/laravel';

export const transport = http({
	base: '/',
	profile: laravel({
		// An info code: `success: false` with this code is a success.
		accept: (envelope) => envelope.code === 'ALREADY_SYNCED',
		kind: (envelope) => (envelope.code === 'ACTION_NOT_AUTHORIZED' ? 'forbidden' : undefined),
		hints: { header: 'X-Invalidate', envelope: true }
	})
});

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)
laravel (marginal)http (marginal)1681 B1548 B1900 B

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

Functions

The profile and its multipart helpers.

Exports

Runtime exports of the entry.

NameTypeDefaultDescription
# laravel (options?: LaravelOptions) => Profile–The profile; pass it to http({ profile }).
# formData (value: object, options?: FormDataOptions) => FormData–A nested object as Laravel multipart fields (bracket keys).
# hasFiles (value: unknown) => boolean–True when a File or Blob is somewhere in the value.

Options

LaravelOptions, the argument of laravel().

LaravelOptions

Every option has a default.

NameTypeDefaultDescription
# envelope booleantrueRead { success, data, message, code }.
# methodSpoof boolean | 'always'trueSend multipart PUT, PATCH and DELETE as POST with _method; 'always' JSON and body-less ones too. An endpoint's transport.methodSpoof wins.
# booleans 'digits' | 'words''digits'Multipart booleans as '1' and '0', or 'true' and 'false'.
# accept (envelope: Envelope) => boolean–Info codes: a success: false envelope that is accepted is a success.
# kind (envelope) => 'refused' | 'validation' | 'forbidden' | undefined–Classify application refusals (ACTION_NOT_AUTHORIZED as forbidden).
# hints { header?: string, envelope?: boolean }offServer-driven freshness on mutation answers: the X-Invalidate header, and invalidate and refreshed beside data.

FormDataOptions

Options of formData() and of transport.multipart.

NameTypeDefaultDescription
# booleans 'digits' | 'words''digits'How booleans are written.
# nulls 'skip' | 'empty''skip'Leave nulls out, or send an empty string.
# emptyArrays 'skip' | 'empty' | ((key) => boolean)'skip'Leave empty arrays out, or send an empty string (per key with a function).
# arrays 'indexed' | 'brackets''indexed'Keys of array items: key[0] or key[] (scalars and files; objects keep their index).

Guide

How to use it, with examples: Client setup. All entry points: Svelte Lean Query.