-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathBucketStorageAdapter.cs
More file actions
132 lines (103 loc) · 3.38 KB
/
BucketStorageAdapter.cs
File metadata and controls
132 lines (103 loc) · 3.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
namespace PowerSync.Common.Client.Sync.Bucket;
using System;
using System.Threading.Tasks;
using PowerSync.Common.DB.Crud;
using PowerSync.Common.Utils;
using Newtonsoft.Json;
public static class PowerSyncControlCommand
{
public const string PROCESS_TEXT_LINE = "line_text";
public const string PROCESS_BSON_LINE = "line_binary";
public const string STOP = "stop";
public const string START = "start";
public const string NOTIFY_TOKEN_REFRESHED = "refreshed_token";
public const string NOTIFY_CRUD_UPLOAD_COMPLETED = "completed_upload";
public const string UPDATE_SUBSCRIPTIONS = "update_subscriptions";
}
public class Checkpoint
{
[JsonProperty("last_op_id")]
public string LastOpId { get; set; } = null!;
[JsonProperty("buckets")]
public BucketChecksum[] Buckets { get; set; } = [];
[JsonProperty("write_checkpoint")]
public string? WriteCheckpoint { get; set; } = null;
}
public class BucketState
{
[JsonProperty("bucket")]
public string Bucket { get; set; } = null!;
[JsonProperty("op_id")]
public string OpId { get; set; } = null!;
}
public class SyncLocalDatabaseResult
{
[JsonProperty("ready")]
public bool Ready { get; set; }
[JsonProperty("checkpointValid")]
public bool CheckpointValid { get; set; }
[JsonProperty("checkpointFailures")]
public string[]? CheckpointFailures { get; set; }
public override bool Equals(object? obj)
{
if (obj is not SyncLocalDatabaseResult other) return false;
return JsonConvert.SerializeObject(this) == JsonConvert.SerializeObject(other);
}
public override int GetHashCode()
{
return JsonConvert.SerializeObject(this).GetHashCode();
}
}
public class BucketChecksum
{
[JsonProperty("bucket")]
public string Bucket { get; set; } = null!;
[JsonProperty("checksum")]
public long Checksum { get; set; }
/// <summary>
/// Count of operations - informational only.
/// </summary>
[JsonProperty("count")]
public int? Count { get; set; }
}
public static class PSInternalTable
{
public static readonly string DATA = "ps_data";
public static readonly string CRUD = "ps_crud";
public static readonly string BUCKETS = "ps_buckets";
public static readonly string OPLOG = "ps_oplog";
public static readonly string UNTYPED = "ps_untyped";
}
public class BucketStorageEvent
{
public bool CrudUpdate { get; set; }
}
public interface IBucketStorageAdapter : IEventStream<BucketStorageEvent>
{
Task Init();
Task SaveSyncData(SyncDataBatch batch);
Task RemoveBuckets(string[] buckets);
Task SetTargetCheckpoint(Checkpoint checkpoint);
void StartSession();
Task<BucketState[]> GetBucketStates();
Task<SyncLocalDatabaseResult> SyncLocalDatabase(Checkpoint checkpoint);
Task<CrudEntry?> NextCrudItem();
Task<bool> HasCrud();
Task<CrudBatch?> GetCrudBatch(int limit = 100);
Task<bool> HasCompletedSync();
Task<bool> UpdateLocalTarget(Func<Task<string>> callback);
/// <summary>
/// Exposed for tests only.
/// </summary>
Task AutoCompact();
Task ForceCompact();
string GetMaxOpId();
/// <summary>
/// Get a unique client ID.
/// </summary>
Task<string> GetClientId();
/// <summary>
/// Invokes the `powersync_control` function for the sync client.
/// </summary>
Task<string> Control(string op, object? payload);
}