From 386c8042d6c587e4d487364fb953d9afef04124a Mon Sep 17 00:00:00 2001 From: hiperman Date: Wed, 25 Feb 2026 01:03:38 -0500 Subject: [PATCH] add triplit client --- src/lib/triplit/client.ts | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 src/lib/triplit/client.ts diff --git a/src/lib/triplit/client.ts b/src/lib/triplit/client.ts new file mode 100644 index 0000000..7d613b4 --- /dev/null +++ b/src/lib/triplit/client.ts @@ -0,0 +1,32 @@ +import { TriplitClient } from '@triplit/client'; +import { schema } from './schema'; +import { + PUBLIC_TRIPLIT_SERVER_URL, + PUBLIC_TRIPLIT_TOKEN, +} from '$env/static/public'; +import { browser } from '$app/environment'; + +// The TriplitClient has 4 main options +// - storage: The storage engine you want to use. This can be +// 'memory' or 'indexeddb'. +// - schema: The schema you defined for your app, which +// will be used to generate types for client methods +// and handle local database operations +// - serverUrl: The URL of your Triplit server +// - token: The token you got from the Triplit dashboard +// +// Without the serverUrl or token, the client will operate in +// offline mode + +export const triplit = new TriplitClient({ + storage: browser ? 'indexeddb' : 'memory', + schema, + serverUrl: PUBLIC_TRIPLIT_SERVER_URL, + token: PUBLIC_TRIPLIT_TOKEN, + autoConnect: browser, + // Ensure offline-first behavior + syncSchema: false, // Don't wait for schema sync to read local data +}); +// @ts-expect-error +if (typeof window !== 'undefined') window.triplit = triplit; +export const Query = triplit.query;