add triplit client

This commit is contained in:
hiperman
2026-02-25 01:03:38 -05:00
parent b48f669af4
commit 386c8042d6
+32
View File
@@ -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;