Skip to content

Commit dff8eac

Browse files
committed
Use UTC for consistent tests
1 parent d16b5d7 commit dff8eac

File tree

3 files changed

+83
-4
lines changed

3 files changed

+83
-4
lines changed

dart/test/goldens/simple_iteration.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@
137137
"priority_status": [
138138
{
139139
"priority": 2147483647,
140-
"last_synced_at": 1740819600,
140+
"last_synced_at": 1740823200,
141141
"has_synced": true
142142
}
143143
],

dart/test/sync_test.dart

+3-3
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import 'utils/native_test_utils.dart';
1818
void syncTest(String description, void Function(FakeAsync controller) body) {
1919
return test(description, () {
2020
// Give each test the same starting time to make goldens easier to compare.
21-
fakeAsync(body, initialTime: DateTime(2025, 3, 1, 10));
21+
fakeAsync(body, initialTime: DateTime.utc(2025, 3, 1, 10));
2222
});
2323
}
2424

@@ -254,7 +254,7 @@ void _syncTests<T>({
254254
// Make sure there's only a single row in last_synced_at
255255
expect(
256256
db.select(
257-
"SELECT datetime(last_synced_at, 'localtime') AS last_synced_at FROM ps_sync_state WHERE priority = ?",
257+
"SELECT datetime(last_synced_at) AS last_synced_at FROM ps_sync_state WHERE priority = ?",
258258
[prio ?? 2147483647]),
259259
[
260260
{'last_synced_at': '2025-03-01 ${10 + i}:00:00'}
@@ -264,7 +264,7 @@ void _syncTests<T>({
264264
if (prio == null) {
265265
expect(
266266
db.select(
267-
"SELECT datetime(powersync_last_synced_at(), 'localtime') AS last_synced_at"),
267+
"SELECT datetime(powersync_last_synced_at()) AS last_synced_at"),
268268
[
269269
{'last_synced_at': '2025-03-01 ${10 + i}:00:00'}
270270
],

docs/sync.md

+79
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
## Sync interface
2+
3+
The core extension implements the state machine and necessary SQL handling to decode and apply
4+
sync line sent from a PowerSync service instance.
5+
6+
After registering the PowerSync extension, this client is available through the `powersync_control`
7+
function, which takes two arguments: A command (text), and a payload (text, blob, or null).
8+
9+
The following commands are supported:
10+
11+
1. `start`: Payload is a JSON-encoded object. This requests the client to start a sync iteration, specifying
12+
parameters.
13+
2. `stop`: No payload, requests the current sync iteration (if any) to be shut down.
14+
3. `line_text`: Payload is a serialized JSON object received from the sync service.
15+
4. `line_binary`: Payload is a BSON-encoded object received from the sync service.
16+
5. `refreshed_token`: Notify the sync client that the JWT used to authenticate to the PowerSync service has
17+
changed.
18+
- The client will emit an instruction to stop the current stream, clients should restart by sending another `start`
19+
command.
20+
6. `completed_upload`: Notify the sync implementation that all local changes have been uploaded.
21+
22+
`powersync_control` returns a JSON-encoded array of instructions for the client:
23+
24+
```typescript
25+
type Instruction = { LogLine: LogLine }
26+
| { UpdateSyncStatus: UpdateSyncStatus }
27+
| { EstablishSyncStream: EstablishSyncStream }
28+
| { FetchCredentials: FetchCredentials }
29+
// Close a connection previously started after EstablishSyncStream
30+
| { CloseSyncStream: {} }
31+
// For the Dart web client, flush the (otherwise non-durable) file system.
32+
| { FlushFileSystem: {} }
33+
// Notify clients that a checkpoint was completed. Clients can clear the
34+
// download error state in response to this.
35+
| { DidCompleteSync: {} }
36+
37+
interface LogLine {
38+
severity: 'DEBUG' | 'INFO' | 'WARNING',
39+
line: String,
40+
}
41+
42+
// Instructs client SDKs to open a connection to the sync service.
43+
interface EstablishSyncStream {
44+
request: any // The JSON-encoded StreamingSyncRequest to send to the sync service
45+
}
46+
47+
// Instructs SDKS to update the downloading state of their SyncStatus.
48+
interface UpdateSyncStatus {
49+
connected: boolean,
50+
connecting: boolean,
51+
priority_status: [],
52+
downloading: null | DownloadProgress,
53+
}
54+
55+
// Instructs SDKs to refresh credentials from the backend connector.
56+
// They don't necessary have to close the connection, a CloseSyncStream instruction
57+
// will be sent when the token has already expired.
58+
interface FetchCredentials {
59+
// Set as an option in case fetching and prefetching should be handled differently.
60+
did_expire: boolean
61+
}
62+
63+
interface SyncPriorityStatus {
64+
priority: int,
65+
last_synced_at: null | int,
66+
has_synced: null | boolean,
67+
}
68+
69+
interface DownloadProgress {
70+
buckets: Record<string, BucketProgress>
71+
}
72+
73+
interface BucketProgress {
74+
priority: int,
75+
at_last: int,
76+
since_last: int,
77+
target_count: int
78+
}
79+
```

0 commit comments

Comments
 (0)