π 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 assetLocalSyncLog/setLocalDeleteLogare 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
| Field | Type | Description |
|---|---|---|
lastSyncedAt | string | Highest updated_at pulled for this table. |
lastCreatedAt | string | Highest created_at pulled. |
lastDeletedAt | string | Highest deleted_at pulled (for soft-deletes). |
filterNamespace | string | Optional 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_markstable. - 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.