A platform-agnostic library for interacting with the platform's persistence layer (Supabase).
This library provides a unified interface for:
Initialize the client once at your application's entry point:
import { DB } from '@clashon/platform-persistence' // Initialize with base configuration DB.init({ supabaseUrl: 'your-supabase-url', supabaseKey: 'your-anon-key', // or service role key for backend services })
Update realtime auth token whenever new custom claims are received:
// After receiving new JWT with custom claims DB.realtimeAuth(customClaimsJwt)
This pattern is particularly useful when:
Set up subscriptions with proper error handling:
const channel = DB.subscribeToMasterRounds( userId, (payload) => { // Handle new master round console.log('New master round:', payload) }, (status, err) => { // Handle subscription status changes console.log('Subscription status:', status, err) }, )
Always clean up resources when done:
// Unsubscribe from specific channel channel.unsubscribe() // Disconnect client entirely DB.disconnect()
The following sequence diagram illustrates the matchmaking process and how the persistence library is used:
sequenceDiagram participant Player as Player (TMA) participant Backend as Platform Backend participant Supabase as Supabase DB participant Matchmaking as Matchmaking Service Matchmaking->>Supabase: SUBSCRIBE to MatchmakingRequest Note over Player: Subscribe to MasterRound updates first Player->>Supabase: SUBSCRIBE to MasterRound Note over Player: Send matchmaking request Player->>Backend: POST /matchmaking Backend->>Supabase: INSERT MatchmakingRequest Supabase-->>Backend: mr_id Backend-->>Player: mr_id Supabase-->>Matchmaking: mr Note over Matchmaking: Process requests every 30s Matchmaking->>Supabase: INSERT MasterRound (grouped players) alt MasterRound assigned Supabase-->>Player: MasterRound via subscription else Timeout (31s) Note over Player: Query assigned round on timeout Player->>Supabase: SELECT MasterRound WHERE id = mr_id Supabase-->>Player: Return assigned MasterRound end Note over Player: Continue with game setup
Platform Agnostic
Type Safety
Realtime Support
Error Handling
Initialization
Authentication
Subscriptions
Error Handling
See the examples directory for complete usage examples.
Add Package
deno add jsr:@clashon/platform-persistence
Import symbol
import * as platform_persistence from "@clashon/platform-persistence";
---- OR ----
Import directly with a jsr specifier
import * as platform_persistence from "jsr:@clashon/platform-persistence";
Add Package
npx jsr add @clashon/platform-persistence
Import symbol
import * as platform_persistence from "@clashon/platform-persistence";
Add Package
yarn dlx jsr add @clashon/platform-persistence
Import symbol
import * as platform_persistence from "@clashon/platform-persistence";
Add Package
pnpm dlx jsr add @clashon/platform-persistence
Import symbol
import * as platform_persistence from "@clashon/platform-persistence";
Add Package
bunx jsr add @clashon/platform-persistence
Import symbol
import * as platform_persistence from "@clashon/platform-persistence";