Skip to Content
ReferenceCore TypesBootstrapResult

BootstrapResult

Return type from bootstrap fetch (initial snapshot from server).

Import

import type { BootstrapResult } from '@gluonic/client'

Type Definition

Exact definition from implementation:

export type BootstrapResult = { sid: number rows: WireRow[] }

Fields

sid

sid: number

Description: Sync ID of the snapshot (highest sync ID in snapshot)

Purpose: Client stores this as lastSyncId after bootstrap

Example: 1000, 5432

rows

rows: WireRow[]

Description: Complete array of all synced data

Format: Array of WireRow objects

Example:

[ { t: 'user', id: 'user-1', v: 1, p: { name: 'Alice' } }, { t: 'task', id: 'task-1', v: 2, p: { title: 'Task 1', done: false } }, { t: 'task', id: 'task-2', v: 1, p: { title: 'Task 2', done: true } } ]

Complete Example

const bootstrapResult: BootstrapResult = { sid: 1000, rows: [ { t: 'user', id: 'alice', v: 5, p: { name: 'Alice', email: 'alice@example.com', createdAt: 1699564800000 } }, { t: 'task', id: 'task-123', v: 3, p: { title: 'Implement feature', done: false, assigneeId: 'alice', createdAt: 1699564900000 } } ] }

Usage

In DownsyncAdapter

import type { DownsyncAdapter, BootstrapResult } from '@gluonic/client' const downsyncAdapter: DownsyncAdapter = { async fetchBootstrap(token, onUnauthenticated): Promise<BootstrapResult> { const response = await fetch('/sync/v1/bootstrap', { headers: { 'Authorization': `Bearer ${token}` } }) if (response.status === 401) { await onUnauthenticated() throw new Error('Unauthenticated') } return await response.json() // Returns BootstrapResult }, async fetchDelta(since, token, onUnauthenticated) { // ... } }

In Store Bootstrap

async bootstrap() { if (downsyncAdapter.fetchBootstrap && lastSyncId <= 0) { // Fetch complete snapshot const snapshot: BootstrapResult = await downsyncAdapter.fetchBootstrap( token, onUnauthenticated ) // Apply all rows to pool and storage await store.applyMany(snapshot.rows, { persist: true }) // Store sync ID await storage.setLastSyncId(snapshot.sid) this.lastSyncId = snapshot.sid } }

Server Response Format

Server endpoint returns BootstrapResult:

GET /sync/v1/bootstrap Authorization: Bearer <token> Response: { "sid": 1000, "rows": [ { "t": "user", "id": "alice", "v": 5, "p": { "name": "Alice" } }, { "t": "task", "id": "task-1", "v": 2, "p": { "title": "Task" } } ] }

Bootstrap Process

Complete bootstrap flow:

// 1. Client checks if bootstrap needed if (lastSyncId === 0) { // 2. Fetch snapshot from server const snapshot: BootstrapResult = await fetchBootstrap(token) // 3. Apply all rows to local storage for (const row of snapshot.rows) { await storage.putRow(row) } // 4. Apply all rows to pool (reactive) for (const row of snapshot.rows) { store.pool.upsert(row) } // 5. Store sync ID await storage.setLastSyncId(snapshot.sid) // 6. Client is now at sync ID 1000 // 7. Future syncs use delta (fetchDelta(1000, token)) }

Performance

Snapshot Size

Bootstrap transfers all data once:

// Small org: 100 models × 1KB = 100KB // Medium org: 10,000 models × 1KB = 10MB // Large org: 100,000 models × 1KB = 100MB // After bootstrap, only deltas (tiny)

Compression

Compress large snapshots:

const snapshot: BootstrapResult = await fetchBootstrap(token) // Server can gzip response: 100MB → 10MB ✓

See Also

Last updated on