Skip to main content

πŸ“š Sync Log Utilities

Supastash tracks created_at, updated_at, and deleted_at checkpoints per table and per filter key.
Use these helpers to inspect or update that metadata.

πŸ’‘ These are the supported APIs in newer releases.
Legacy helpers such as setLocalSyncLog / setLocalDeleteLog are deprecated.


Functions​

🧹 clearLocalSyncLog(tableName: string)​

Clears the stored sync log for a single table.

await clearLocalSyncLog("users");

πŸ”„ clearAllLocalSyncLog()​

Drops the entire sync-status table and recreates it.

await clearAllLocalSyncLog();

⚠️ This removes sync checkpoints for all tables.


πŸ“₯ getSyncLog(tableName: string)​

Returns the stored sync status for one table.

const log = await getSyncLog("users");

/*
{
table_name: "users",
last_synced_at: "2024-06-01T10:00:00.000Z",
last_created_at: "2024-06-01T10:00:00.000Z",
last_deleted_at: "2024-06-01T10:00:00.000Z",
filter_key: "abc123",
filter_json: "[...]",
updated_at: "2024-06-01T10:00:00.000Z"
}
*/

Returns null if the table has no entry.


✍️ setSyncLog(table: string, filters: RealtimeFilter[] \| undefined, opts)​

Writes (or updates) sync metadata for a table.

await setSyncLog("users", undefined, {
lastSyncedAt: new Date().toISOString(),
lastCreatedAt: new Date().toISOString(),
lastDeletedAt: null, // optional
});

Options

FieldTypeDescription
lastSyncedAtstringHighest updated_at pulled for this table.
lastCreatedAtstringHighest created_at pulled.
lastDeletedAtstringHighest deleted_at pulled (for soft-deletes).
filterNamespacestringOptional namespace to separate different filter sets.

When you supply filters, a filter key is computed and stored along with the timestamps.


πŸ” resetSyncLog(table: string, filters?: RealtimeFilter[], scope?: "all" \| "last_synced_at" \| "last_created_at" \| "last_deleted_at")​

Resets one or more timestamps for a table.

// Reset everything for "users"
await resetSyncLog("users", undefined, "all");

// Only reset "last_deleted_at"
await resetSyncLog("users", undefined, "last_deleted_at");

scope can be:

  • "all" (default) – resets created, updated, and deleted checkpoints.
  • "last_synced_at" – resets only the β€œupdated” timestamp.
  • "last_created_at" – resets only the β€œcreated” timestamp.
  • "last_deleted_at" – resets only the β€œdeleted” timestamp.

πŸ—‘ clearSyncLog(table: string, filters?: RealtimeFilter[])​

Removes the sync status row for a table + filter key.

await clearSyncLog("users");

If you pass filters, only that key is cleared.
If no filters are provided, all rows for the table are removed.


Usage Notes​

  • These helpers manage rows in the internal supastash_sync_marks table.
  • They are safe to call on demand (e.g., to reset a table during testing).
  • For production sync flows, you normally won’t touch these directlyβ€”Supastash updates them automatically after pulls/pushes.