Skip to content

Instantly share code, notes, and snippets.

View sillvva's full-sized avatar

Matt DeKok sillvva

View GitHub Profile
@sillvva
sillvva / factories.svelte.ts
Last active December 16, 2025 21:39
Remote form factory
import { beforeNavigate } from "$app/navigation";
import { page } from "$app/state";
import { debounce, deepEqual } from "@sillvva/utils";
import type { StandardSchemaV1 } from "@standard-schema/spec";
import type { RemoteForm, RemoteFormFields, RemoteFormInput, RemoteFormIssue } from "@sveltejs/kit";
import { onMount, tick, untrack } from "svelte";
import { toast } from "svelte-sonner";
import { v7 } from "uuid";
import { unknownErrorMessage } from "./util";
@sillvva
sillvva / input.svelte
Last active November 26, 2025 15:04
Bindable input
<script lang="ts" generics="V extends RemoteFormFieldValue">
import type { RemoteFormField, RemoteFormFieldValue } from "@sveltejs/kit";
import type { HTMLInputAttributes } from "svelte/elements";
import FieldMessage from "./field-message.svelte";
import InputWrapper from "./input-wrapper.svelte";
type InputTypeMap =
| {
type?: "text";
field: RemoteFormField<string>;
export default {
meta: {
type: "problem",
docs: {
description:
"Enforce that exports in .remote.ts files use query(), command(), or form(), and only allow type exports",
category: "Best Practices",
recommended: true
},
messages: {
@sillvva
sillvva / enforce-guarded-functions.js
Last active November 15, 2025 14:16
eslint: enforce guarded remote functions
export default {
meta: {
type: "problem",
docs: {
description:
"Enforce that exports in .remote.ts files use guardedQuery(), guardedCommand(), or guardedForm(), and only allow type exports",
category: "Best Practices",
recommended: true
},
messages: {
@sillvva
sillvva / guardFn.ts
Last active October 30, 2025 21:27
Guarded Remote Functions
import { command, form, getRequestEvent, query } from "$app/server";
import type { StandardSchemaV1 } from "@standard-schema/spec";
import {
redirect,
type Invalid,
type RemoteCommand,
type RemoteFormFactory,
type RemoteFormInput,
type RemoteQueryFunction,
type RequestEvent
@sillvva
sillvva / input.svelte
Last active October 17, 2025 18:52
Input Component for Remote Forms
<script lang="ts" generics="V extends RemoteFormFieldValue">
import type { RemoteFormField, RemoteFormFieldType, RemoteFormFieldValue } from "@sveltejs/kit";
import type { HTMLInputAttributes } from "svelte/elements";
type Props = {
label?: string;
field: RemoteFormField<V>;
description?: string;
warning?: string;
hidden?: boolean;
@sillvva
sillvva / +page.svelte
Last active October 1, 2025 07:52
Remote Functions + Superforms
<script lang="ts">
import Breadcrumbs from "$lib/components/Breadcrumbs.svelte";
import Control from "$lib/components/forms/Control.svelte";
import Input from "$lib/components/forms/Input.svelte";
import Submit from "$lib/components/forms/Submit.svelte";
import SuperForm from "$lib/components/forms/SuperForm.svelte";
import { valibotForm } from "$lib/factories.svelte.js";
import DMsAPI from "$lib/remote/dms";
import { dungeonMasterSchema } from "$lib/schemas";
@sillvva
sillvva / standard-codec.ts
Last active September 4, 2025 02:33
StandardSchemaV1 Codec
import type { StandardSchemaV1 } from "@standard-schema/spec";
type Context<TType> = {
parsed: TType;
issues: StandardSchemaV1.Issue[];
};
// Transform functions interface
interface CodecTransforms<TInputIn, TInputOut, TOutputIn, TOutputOut> {
decode: (input: TInputIn, context?: Context<TInputOut>) => TOutputIn; // forward transform (input -> output)
@sillvva
sillvva / effectkit.ts
Last active August 7, 2025 20:01
Effect + Sveltekit
import { dev } from "$app/environment";
import { getRequestEvent } from "$app/server";
import { privateEnv } from "$lib/env/private";
import type { AppLogSchema, UserId } from "$lib/schemas";
import { db, runQuery } from "$lib/server/db";
import { appLogs } from "$lib/server/db/schema";
import { removeTrace } from "$lib/util";
import { isInstanceOfClass } from "@sillvva/utils";
import { error, isHttpError, isRedirect, type NumericRange } from "@sveltejs/kit";
import { Cause, Effect, Exit, HashMap, Layer, Logger } from "effect";
@sillvva
sillvva / builders.ts
Created September 21, 2023 15:04
Websocket Wrapper with Svelte 5 Runes
export default function createSocket<T>(
url: string | URL,
options?: {
name?: string;
protocols?: string | string[];
onOpen?: (event: Event) => void;
onError?: (error: Event) => void;
onMessage?: (data: T, requests: T[], event: Event) => void;
}
) {