@powersync/service-core 0.18.1 → 1.7.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +29 -0
- package/dist/api/RouteAPI.d.ts +1 -1
- package/dist/api/diagnostics.js +107 -169
- package/dist/api/diagnostics.js.map +1 -1
- package/dist/entry/commands/compact-action.js +10 -73
- package/dist/entry/commands/compact-action.js.map +1 -1
- package/dist/modules/AbstractModule.d.ts +1 -1
- package/dist/replication/AbstractReplicator.js +8 -76
- package/dist/replication/AbstractReplicator.js.map +1 -1
- package/dist/routes/endpoints/checkpointing.js +3 -2
- package/dist/routes/endpoints/checkpointing.js.map +1 -1
- package/dist/routes/endpoints/socket-route.js +5 -5
- package/dist/routes/endpoints/socket-route.js.map +1 -1
- package/dist/routes/endpoints/sync-stream.js +5 -5
- package/dist/routes/endpoints/sync-stream.js.map +1 -1
- package/dist/runner/teardown.js +3 -65
- package/dist/runner/teardown.js.map +1 -1
- package/dist/storage/BucketStorage.d.ts +8 -441
- package/dist/storage/BucketStorage.js +9 -10
- package/dist/storage/BucketStorage.js.map +1 -1
- package/dist/storage/BucketStorageBatch.d.ts +130 -0
- package/dist/storage/BucketStorageBatch.js +10 -0
- package/dist/storage/BucketStorageBatch.js.map +1 -0
- package/dist/storage/BucketStorageFactory.d.ts +145 -0
- package/dist/storage/BucketStorageFactory.js +2 -0
- package/dist/storage/BucketStorageFactory.js.map +1 -0
- package/dist/storage/ChecksumCache.js.map +1 -1
- package/dist/storage/PersistedSyncRulesContent.d.ts +20 -0
- package/dist/storage/PersistedSyncRulesContent.js +2 -0
- package/dist/storage/PersistedSyncRulesContent.js.map +1 -0
- package/dist/storage/ReplicationEventPayload.d.ts +1 -1
- package/dist/storage/ReplicationLock.d.ts +4 -0
- package/dist/storage/ReplicationLock.js +2 -0
- package/dist/storage/ReplicationLock.js.map +1 -0
- package/dist/storage/SourceEntity.d.ts +6 -2
- package/dist/storage/SourceTable.d.ts +2 -2
- package/dist/storage/SourceTable.js.map +1 -1
- package/dist/storage/StorageEngine.d.ts +4 -4
- package/dist/storage/StorageEngine.js +2 -2
- package/dist/storage/StorageEngine.js.map +1 -1
- package/dist/storage/StorageProvider.d.ts +4 -1
- package/dist/storage/SyncRulesBucketStorage.d.ts +207 -0
- package/dist/storage/SyncRulesBucketStorage.js +7 -0
- package/dist/storage/SyncRulesBucketStorage.js.map +1 -0
- package/dist/storage/bson.d.ts +14 -3
- package/dist/storage/bson.js +18 -2
- package/dist/storage/bson.js.map +1 -1
- package/dist/storage/storage-index.d.ts +5 -0
- package/dist/storage/storage-index.js +5 -0
- package/dist/storage/storage-index.js.map +1 -1
- package/dist/sync/BucketChecksumState.d.ts +91 -0
- package/dist/sync/BucketChecksumState.js +313 -0
- package/dist/sync/BucketChecksumState.js.map +1 -0
- package/dist/sync/sync-index.d.ts +1 -0
- package/dist/sync/sync-index.js +1 -0
- package/dist/sync/sync-index.js.map +1 -1
- package/dist/sync/sync.d.ts +7 -3
- package/dist/sync/sync.js +139 -135
- package/dist/sync/sync.js.map +1 -1
- package/dist/sync/util.d.ts +9 -0
- package/dist/sync/util.js +44 -0
- package/dist/sync/util.js.map +1 -1
- package/dist/util/checkpointing.d.ts +1 -1
- package/dist/util/checkpointing.js +15 -78
- package/dist/util/checkpointing.js.map +1 -1
- package/dist/util/protocol-types.d.ts +13 -4
- package/package.json +5 -5
- package/src/api/RouteAPI.ts +1 -1
- package/src/api/diagnostics.ts +1 -1
- package/src/entry/commands/compact-action.ts +2 -3
- package/src/modules/AbstractModule.ts +1 -1
- package/src/replication/AbstractReplicator.ts +7 -12
- package/src/routes/endpoints/checkpointing.ts +3 -3
- package/src/routes/endpoints/socket-route.ts +7 -5
- package/src/routes/endpoints/sync-stream.ts +8 -5
- package/src/runner/teardown.ts +1 -1
- package/src/storage/BucketStorage.ts +8 -550
- package/src/storage/BucketStorageBatch.ts +158 -0
- package/src/storage/BucketStorageFactory.ts +166 -0
- package/src/storage/ChecksumCache.ts +1 -0
- package/src/storage/PersistedSyncRulesContent.ts +26 -0
- package/src/storage/ReplicationEventPayload.ts +1 -1
- package/src/storage/ReplicationLock.ts +5 -0
- package/src/storage/SourceEntity.ts +6 -2
- package/src/storage/SourceTable.ts +1 -1
- package/src/storage/StorageEngine.ts +4 -4
- package/src/storage/StorageProvider.ts +4 -1
- package/src/storage/SyncRulesBucketStorage.ts +265 -0
- package/src/storage/bson.ts +22 -4
- package/src/storage/storage-index.ts +5 -0
- package/src/sync/BucketChecksumState.ts +392 -0
- package/src/sync/sync-index.ts +1 -0
- package/src/sync/sync.ts +182 -157
- package/src/sync/util.ts +54 -0
- package/src/util/checkpointing.ts +4 -6
- package/src/util/protocol-types.ts +16 -4
- package/test/src/auth.test.ts +5 -5
- package/test/src/sync/BucketChecksumState.test.ts +565 -0
- package/test/src/sync/util.test.ts +34 -0
- package/tsconfig.tsbuildinfo +1 -1
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
import { ObserverClient } from '@powersync/lib-services-framework';
|
|
2
|
+
import { SqlSyncRules, SqliteJsonRow, SqliteJsonValue } from '@powersync/service-sync-rules';
|
|
3
|
+
import * as util from '../util/util-index.js';
|
|
4
|
+
import { BucketStorageBatch, FlushedResult } from './BucketStorageBatch.js';
|
|
5
|
+
import { BucketStorageFactory } from './BucketStorageFactory.js';
|
|
6
|
+
import { ParseSyncRulesOptions } from './PersistedSyncRulesContent.js';
|
|
7
|
+
import { SourceEntityDescriptor } from './SourceEntity.js';
|
|
8
|
+
import { SourceTable } from './SourceTable.js';
|
|
9
|
+
import { SyncStorageWriteCheckpointAPI } from './WriteCheckpointAPI.js';
|
|
10
|
+
/**
|
|
11
|
+
* Storage for a specific copy of sync rules.
|
|
12
|
+
*/
|
|
13
|
+
export interface SyncRulesBucketStorage extends ObserverClient<SyncRulesBucketStorageListener>, SyncStorageWriteCheckpointAPI {
|
|
14
|
+
readonly group_id: number;
|
|
15
|
+
readonly slot_name: string;
|
|
16
|
+
readonly factory: BucketStorageFactory;
|
|
17
|
+
/**
|
|
18
|
+
* Resolve a table, keeping track of it internally.
|
|
19
|
+
*/
|
|
20
|
+
resolveTable(options: ResolveTableOptions): Promise<ResolveTableResult>;
|
|
21
|
+
/**
|
|
22
|
+
* Use this to get access to update storage data.
|
|
23
|
+
*/
|
|
24
|
+
startBatch(options: StartBatchOptions, callback: (batch: BucketStorageBatch) => Promise<void>): Promise<FlushedResult | null>;
|
|
25
|
+
getParsedSyncRules(options: ParseSyncRulesOptions): SqlSyncRules;
|
|
26
|
+
/**
|
|
27
|
+
* Terminate the sync rules.
|
|
28
|
+
*
|
|
29
|
+
* This clears the storage, and sets state to TERMINATED.
|
|
30
|
+
*
|
|
31
|
+
* Must only be called on stopped sync rules.
|
|
32
|
+
*/
|
|
33
|
+
terminate(options?: TerminateOptions): Promise<void>;
|
|
34
|
+
getStatus(): Promise<SyncRuleStatus>;
|
|
35
|
+
/**
|
|
36
|
+
* Clear the storage, without changing state.
|
|
37
|
+
*/
|
|
38
|
+
clear(): Promise<void>;
|
|
39
|
+
autoActivate(): Promise<void>;
|
|
40
|
+
/**
|
|
41
|
+
* Record a replication error.
|
|
42
|
+
*
|
|
43
|
+
* This could be a recoverable error (e.g. temporary network failure),
|
|
44
|
+
* or a permanent error (e.g. missing toast data).
|
|
45
|
+
*
|
|
46
|
+
* Errors are cleared on commit.
|
|
47
|
+
*/
|
|
48
|
+
reportError(e: any): Promise<void>;
|
|
49
|
+
compact(options?: CompactOptions): Promise<void>;
|
|
50
|
+
getCheckpoint(): Promise<ReplicationCheckpoint>;
|
|
51
|
+
/**
|
|
52
|
+
* Used to resolve "dynamic" parameter queries.
|
|
53
|
+
*/
|
|
54
|
+
getParameterSets(checkpoint: util.OpId, lookups: SqliteJsonValue[][]): Promise<SqliteJsonRow[]>;
|
|
55
|
+
getCheckpointChanges(options: GetCheckpointChangesOptions): Promise<CheckpointChanges>;
|
|
56
|
+
/**
|
|
57
|
+
* Yields the latest user write checkpoint whenever the sync checkpoint updates.
|
|
58
|
+
*
|
|
59
|
+
* The stream stops or errors if this is not the active sync rules (anymore).
|
|
60
|
+
*/
|
|
61
|
+
watchWriteCheckpoint(options: WatchWriteCheckpointOptions): AsyncIterable<StorageCheckpointUpdate>;
|
|
62
|
+
/**
|
|
63
|
+
* Get a "batch" of data for a checkpoint.
|
|
64
|
+
*
|
|
65
|
+
* The results will be split into separate SyncBucketData chunks to:
|
|
66
|
+
* 1. Separate buckets.
|
|
67
|
+
* 2. Limit the size of each individual chunk according to options.batchSizeLimitBytes.
|
|
68
|
+
*
|
|
69
|
+
* @param checkpoint the checkpoint
|
|
70
|
+
* @param dataBuckets current bucket states
|
|
71
|
+
* @param options batch size options
|
|
72
|
+
*/
|
|
73
|
+
getBucketDataBatch(checkpoint: util.OpId, dataBuckets: Map<string, string>, options?: BucketDataBatchOptions): AsyncIterable<SyncBucketDataBatch>;
|
|
74
|
+
/**
|
|
75
|
+
* Compute checksums for a given list of buckets.
|
|
76
|
+
*
|
|
77
|
+
* Returns zero checksums for any buckets not found.
|
|
78
|
+
*/
|
|
79
|
+
getChecksums(checkpoint: util.OpId, buckets: string[]): Promise<util.ChecksumMap>;
|
|
80
|
+
}
|
|
81
|
+
export interface SyncRulesBucketStorageListener {
|
|
82
|
+
batchStarted: (batch: BucketStorageBatch) => void;
|
|
83
|
+
}
|
|
84
|
+
export interface SyncRuleStatus {
|
|
85
|
+
checkpoint_lsn: string | null;
|
|
86
|
+
active: boolean;
|
|
87
|
+
snapshot_done: boolean;
|
|
88
|
+
}
|
|
89
|
+
export interface ResolveTableOptions {
|
|
90
|
+
group_id: number;
|
|
91
|
+
connection_id: number;
|
|
92
|
+
connection_tag: string;
|
|
93
|
+
entity_descriptor: SourceEntityDescriptor;
|
|
94
|
+
sync_rules: SqlSyncRules;
|
|
95
|
+
}
|
|
96
|
+
export interface ResolveTableResult {
|
|
97
|
+
table: SourceTable;
|
|
98
|
+
dropTables: SourceTable[];
|
|
99
|
+
}
|
|
100
|
+
export interface StartBatchOptions extends ParseSyncRulesOptions {
|
|
101
|
+
zeroLSN: string;
|
|
102
|
+
/**
|
|
103
|
+
* Whether or not to store a copy of the current data.
|
|
104
|
+
*
|
|
105
|
+
* This is needed if we need to apply partial updates, for example
|
|
106
|
+
* when we get TOAST values from Postgres.
|
|
107
|
+
*
|
|
108
|
+
* This is not needed when we get the full document from the source
|
|
109
|
+
* database, for example from MongoDB.
|
|
110
|
+
*/
|
|
111
|
+
storeCurrentData: boolean;
|
|
112
|
+
/**
|
|
113
|
+
* Set to true for initial replication.
|
|
114
|
+
*
|
|
115
|
+
* This will avoid creating new operations for rows previously replicated.
|
|
116
|
+
*/
|
|
117
|
+
skipExistingRows?: boolean;
|
|
118
|
+
}
|
|
119
|
+
export interface CompactOptions {
|
|
120
|
+
/**
|
|
121
|
+
* Heap memory limit for the compact process.
|
|
122
|
+
*
|
|
123
|
+
* Add around 64MB to this to determine the "--max-old-space-size" argument.
|
|
124
|
+
* Add another 80MB to get RSS usage / memory limits.
|
|
125
|
+
*/
|
|
126
|
+
memoryLimitMB?: number;
|
|
127
|
+
/**
|
|
128
|
+
* If specified, ignore any operations newer than this when compacting.
|
|
129
|
+
*
|
|
130
|
+
* This is primarily for tests, where we want to test compacting at a specific
|
|
131
|
+
* point.
|
|
132
|
+
*
|
|
133
|
+
* This can also be used to create a "safe buffer" of recent operations that should
|
|
134
|
+
* not be compacted, to avoid invalidating checkpoints in use.
|
|
135
|
+
*/
|
|
136
|
+
maxOpId?: bigint;
|
|
137
|
+
/**
|
|
138
|
+
* If specified, compact only the specific buckets.
|
|
139
|
+
*
|
|
140
|
+
* If not specified, compacts all buckets.
|
|
141
|
+
*
|
|
142
|
+
* These can be individual bucket names, or bucket definition names.
|
|
143
|
+
*/
|
|
144
|
+
compactBuckets?: string[];
|
|
145
|
+
/** Minimum of 2 */
|
|
146
|
+
clearBatchLimit?: number;
|
|
147
|
+
/** Minimum of 1 */
|
|
148
|
+
moveBatchLimit?: number;
|
|
149
|
+
/** Minimum of 1 */
|
|
150
|
+
moveBatchQueryLimit?: number;
|
|
151
|
+
}
|
|
152
|
+
export interface TerminateOptions {
|
|
153
|
+
/**
|
|
154
|
+
* If true, also clear the storage before terminating.
|
|
155
|
+
*/
|
|
156
|
+
clearStorage: boolean;
|
|
157
|
+
}
|
|
158
|
+
export interface BucketDataBatchOptions {
|
|
159
|
+
/** Limit number of documents returned. Defaults to 1000. */
|
|
160
|
+
limit?: number;
|
|
161
|
+
/**
|
|
162
|
+
* Limit size of chunks returned. Defaults to 1MB.
|
|
163
|
+
*
|
|
164
|
+
* This is a lower bound, not an upper bound. As soon as the chunk size goes over this limit,
|
|
165
|
+
* it is returned.
|
|
166
|
+
*
|
|
167
|
+
* Note that an individual data row can be close to 16MB in size, so this does not help in
|
|
168
|
+
* extreme cases.
|
|
169
|
+
*/
|
|
170
|
+
chunkLimitBytes?: number;
|
|
171
|
+
}
|
|
172
|
+
export interface SyncBucketDataBatch {
|
|
173
|
+
batch: util.SyncBucketData;
|
|
174
|
+
targetOp: bigint | null;
|
|
175
|
+
}
|
|
176
|
+
export interface ReplicationCheckpoint {
|
|
177
|
+
readonly checkpoint: util.OpId;
|
|
178
|
+
readonly lsn: string | null;
|
|
179
|
+
}
|
|
180
|
+
export interface WatchWriteCheckpointOptions {
|
|
181
|
+
/** user_id and client_id combined. */
|
|
182
|
+
user_id: string;
|
|
183
|
+
signal: AbortSignal;
|
|
184
|
+
}
|
|
185
|
+
export interface WatchFilterEvent {
|
|
186
|
+
changedDataBucket?: string;
|
|
187
|
+
changedParameterBucketDefinition?: string;
|
|
188
|
+
invalidate?: boolean;
|
|
189
|
+
}
|
|
190
|
+
export interface WriteCheckpoint {
|
|
191
|
+
base: ReplicationCheckpoint;
|
|
192
|
+
writeCheckpoint: bigint | null;
|
|
193
|
+
}
|
|
194
|
+
export interface StorageCheckpointUpdate extends WriteCheckpoint {
|
|
195
|
+
update: CheckpointChanges;
|
|
196
|
+
}
|
|
197
|
+
export interface GetCheckpointChangesOptions {
|
|
198
|
+
lastCheckpoint: util.OpId;
|
|
199
|
+
nextCheckpoint: util.OpId;
|
|
200
|
+
}
|
|
201
|
+
export interface CheckpointChanges {
|
|
202
|
+
updatedDataBuckets: string[];
|
|
203
|
+
invalidateDataBuckets: boolean;
|
|
204
|
+
updatedParameterBucketDefinitions: string[];
|
|
205
|
+
invalidateParameterBuckets: boolean;
|
|
206
|
+
}
|
|
207
|
+
export declare const CHECKPOINT_INVALIDATE_ALL: CheckpointChanges;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SyncRulesBucketStorage.js","sourceRoot":"","sources":["../../src/storage/SyncRulesBucketStorage.ts"],"names":[],"mappings":"AAmQA,MAAM,CAAC,MAAM,yBAAyB,GAAsB;IAC1D,kBAAkB,EAAE,EAAE;IACtB,qBAAqB,EAAE,IAAI;IAC3B,iCAAiC,EAAE,EAAE;IACrC,0BAA0B,EAAE,IAAI;CACjC,CAAC"}
|
package/dist/storage/bson.d.ts
CHANGED
|
@@ -1,14 +1,22 @@
|
|
|
1
1
|
import * as bson from 'bson';
|
|
2
2
|
import { SqliteJsonValue } from '@powersync/service-sync-rules';
|
|
3
|
-
import { ReplicaId } from './
|
|
3
|
+
import { ReplicaId } from './BucketStorageBatch.js';
|
|
4
4
|
type NodeBuffer = Buffer<ArrayBuffer>;
|
|
5
|
-
|
|
5
|
+
/**
|
|
6
|
+
* Use for internal (bucket storage) data, where we control each field.
|
|
7
|
+
*/
|
|
8
|
+
export declare const BSON_DESERIALIZE_INTERNAL_OPTIONS: bson.DeserializeOptions;
|
|
9
|
+
/**
|
|
10
|
+
* Use for data from external sources, which could contain arbitrary fields.
|
|
11
|
+
*/
|
|
12
|
+
export declare const BSON_DESERIALIZE_DATA_OPTIONS: bson.DeserializeOptions;
|
|
6
13
|
/**
|
|
7
14
|
* Lookup serialization must be number-agnostic. I.e. normalize numbers, instead of preserving numbers.
|
|
8
15
|
* @param lookup
|
|
9
16
|
*/
|
|
10
17
|
export declare const serializeLookupBuffer: (lookup: SqliteJsonValue[]) => NodeBuffer;
|
|
11
18
|
export declare const serializeLookup: (lookup: SqliteJsonValue[]) => bson.Binary;
|
|
19
|
+
export declare const getLookupBucketDefinitionName: (lookup: bson.Binary) => string;
|
|
12
20
|
/**
|
|
13
21
|
* True if this is a bson.UUID.
|
|
14
22
|
*
|
|
@@ -17,7 +25,10 @@ export declare const serializeLookup: (lookup: SqliteJsonValue[]) => bson.Binary
|
|
|
17
25
|
export declare const isUUID: (value: any) => value is bson.UUID;
|
|
18
26
|
export declare const serializeReplicaId: (id: ReplicaId) => NodeBuffer;
|
|
19
27
|
export declare const deserializeReplicaId: (id: Buffer) => ReplicaId;
|
|
20
|
-
|
|
28
|
+
/**
|
|
29
|
+
* Deserialize BSON - can be used for BSON containing arbitrary user data.
|
|
30
|
+
*/
|
|
31
|
+
export declare const deserializeBson: (buffer: Uint8Array) => bson.Document;
|
|
21
32
|
export declare const serializeBson: (document: any) => NodeBuffer;
|
|
22
33
|
/**
|
|
23
34
|
* Returns true if two ReplicaId values are the same (serializes to the same BSON value).
|
package/dist/storage/bson.js
CHANGED
|
@@ -1,8 +1,17 @@
|
|
|
1
1
|
import * as bson from 'bson';
|
|
2
|
-
|
|
2
|
+
/**
|
|
3
|
+
* Use for internal (bucket storage) data, where we control each field.
|
|
4
|
+
*/
|
|
5
|
+
export const BSON_DESERIALIZE_INTERNAL_OPTIONS = {
|
|
3
6
|
// use bigint instead of Long
|
|
4
7
|
useBigInt64: true
|
|
5
8
|
};
|
|
9
|
+
/**
|
|
10
|
+
* Use for data from external sources, which could contain arbitrary fields.
|
|
11
|
+
*/
|
|
12
|
+
export const BSON_DESERIALIZE_DATA_OPTIONS = {
|
|
13
|
+
useBigInt64: true
|
|
14
|
+
};
|
|
6
15
|
/**
|
|
7
16
|
* Lookup serialization must be number-agnostic. I.e. normalize numbers, instead of preserving numbers.
|
|
8
17
|
* @param lookup
|
|
@@ -21,6 +30,10 @@ export const serializeLookupBuffer = (lookup) => {
|
|
|
21
30
|
export const serializeLookup = (lookup) => {
|
|
22
31
|
return new bson.Binary(serializeLookupBuffer(lookup));
|
|
23
32
|
};
|
|
33
|
+
export const getLookupBucketDefinitionName = (lookup) => {
|
|
34
|
+
const parsed = bson.deserialize(lookup.buffer, BSON_DESERIALIZE_INTERNAL_OPTIONS).l;
|
|
35
|
+
return parsed[0];
|
|
36
|
+
};
|
|
24
37
|
/**
|
|
25
38
|
* True if this is a bson.UUID.
|
|
26
39
|
*
|
|
@@ -40,8 +53,11 @@ export const deserializeReplicaId = (id) => {
|
|
|
40
53
|
const deserialized = deserializeBson(id);
|
|
41
54
|
return deserialized.id;
|
|
42
55
|
};
|
|
56
|
+
/**
|
|
57
|
+
* Deserialize BSON - can be used for BSON containing arbitrary user data.
|
|
58
|
+
*/
|
|
43
59
|
export const deserializeBson = (buffer) => {
|
|
44
|
-
return bson.deserialize(buffer,
|
|
60
|
+
return bson.deserialize(buffer, BSON_DESERIALIZE_DATA_OPTIONS);
|
|
45
61
|
};
|
|
46
62
|
export const serializeBson = (document) => {
|
|
47
63
|
return bson.serialize(document);
|
package/dist/storage/bson.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bson.js","sourceRoot":"","sources":["../../src/storage/bson.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAO7B,MAAM,CAAC,MAAM,
|
|
1
|
+
{"version":3,"file":"bson.js","sourceRoot":"","sources":["../../src/storage/bson.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAO7B;;GAEG;AACH,MAAM,CAAC,MAAM,iCAAiC,GAA4B;IACxE,6BAA6B;IAC7B,WAAW,EAAE,IAAI;CAClB,CAAC;AAEF;;GAEG;AACH,MAAM,CAAC,MAAM,6BAA6B,GAA4B;IACpE,WAAW,EAAE,IAAI;CAClB,CAAC;AAEF;;;GAGG;AACH,MAAM,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AC;QAChE,OAAO,KAAK,CAAC;IACf,CAAC;SAAM,CAAC;QACN,iEAAiE;QACjE,OAAO,kBAAkB,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,kBAAkB,CAAC,CAAC,CAAC,CAAC,CAAC;IAC7D,CAAC;AACH,CAAC,CAAC"}
|
|
@@ -7,3 +7,8 @@ export * from './SourceTable.js';
|
|
|
7
7
|
export * from './StorageEngine.js';
|
|
8
8
|
export * from './StorageProvider.js';
|
|
9
9
|
export * from './WriteCheckpointAPI.js';
|
|
10
|
+
export * from './BucketStorageFactory.js';
|
|
11
|
+
export * from './BucketStorageBatch.js';
|
|
12
|
+
export * from './SyncRulesBucketStorage.js';
|
|
13
|
+
export * from './PersistedSyncRulesContent.js';
|
|
14
|
+
export * from './ReplicationLock.js';
|
|
@@ -7,4 +7,9 @@ export * from './SourceTable.js';
|
|
|
7
7
|
export * from './StorageEngine.js';
|
|
8
8
|
export * from './StorageProvider.js';
|
|
9
9
|
export * from './WriteCheckpointAPI.js';
|
|
10
|
+
export * from './BucketStorageFactory.js';
|
|
11
|
+
export * from './BucketStorageBatch.js';
|
|
12
|
+
export * from './SyncRulesBucketStorage.js';
|
|
13
|
+
export * from './PersistedSyncRulesContent.js';
|
|
14
|
+
export * from './ReplicationLock.js';
|
|
10
15
|
//# sourceMappingURL=storage-index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"storage-index.js","sourceRoot":"","sources":["../../src/storage/storage-index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC;AAC1B,cAAc,oBAAoB,CAAC;AACnC,cAAc,oBAAoB,CAAC;AACnC,cAAc,8BAA8B,CAAC;AAC7C,cAAc,mBAAmB,CAAC;AAClC,cAAc,kBAAkB,CAAC;AACjC,cAAc,oBAAoB,CAAC;AACnC,cAAc,sBAAsB,CAAC;AACrC,cAAc,yBAAyB,CAAC"}
|
|
1
|
+
{"version":3,"file":"storage-index.js","sourceRoot":"","sources":["../../src/storage/storage-index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC;AAC1B,cAAc,oBAAoB,CAAC;AACnC,cAAc,oBAAoB,CAAC;AACnC,cAAc,8BAA8B,CAAC;AAC7C,cAAc,mBAAmB,CAAC;AAClC,cAAc,kBAAkB,CAAC;AACjC,cAAc,oBAAoB,CAAC;AACnC,cAAc,sBAAsB,CAAC;AACrC,cAAc,yBAAyB,CAAC;AACxC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,yBAAyB,CAAC;AACxC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,gCAAgC,CAAC;AAC/C,cAAc,sBAAsB,CAAC"}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { BucketDescription, RequestParameters, SqlSyncRules } from '@powersync/service-sync-rules';
|
|
2
|
+
import * as storage from '../storage/storage-index.js';
|
|
3
|
+
import * as util from '../util/util-index.js';
|
|
4
|
+
import { BucketSyncState } from './sync.js';
|
|
5
|
+
export interface BucketChecksumStateOptions {
|
|
6
|
+
bucketStorage: BucketChecksumStateStorage;
|
|
7
|
+
syncRules: SqlSyncRules;
|
|
8
|
+
syncParams: RequestParameters;
|
|
9
|
+
initialBucketPositions?: {
|
|
10
|
+
name: string;
|
|
11
|
+
after: string;
|
|
12
|
+
}[];
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Represents the state of the checksums and data for a specific connection.
|
|
16
|
+
*
|
|
17
|
+
* Handles incrementally re-computing checkpoints.
|
|
18
|
+
*/
|
|
19
|
+
export declare class BucketChecksumState {
|
|
20
|
+
private readonly bucketStorage;
|
|
21
|
+
/**
|
|
22
|
+
* Bucket state of bucket id -> op_id.
|
|
23
|
+
* This starts with the state from the client. May contain buckets that the user do not have access to (anymore).
|
|
24
|
+
*/
|
|
25
|
+
bucketDataPositions: Map<string, BucketSyncState>;
|
|
26
|
+
/**
|
|
27
|
+
* Last checksums sent to the client. We keep this to calculate checkpoint diffs.
|
|
28
|
+
*/
|
|
29
|
+
private lastChecksums;
|
|
30
|
+
private lastWriteCheckpoint;
|
|
31
|
+
private readonly parameterState;
|
|
32
|
+
/**
|
|
33
|
+
* Keep track of buckets that need to be downloaded. This is specifically relevant when
|
|
34
|
+
* partial checkpoints are sent.
|
|
35
|
+
*/
|
|
36
|
+
private pendingBucketDownloads;
|
|
37
|
+
constructor(options: BucketChecksumStateOptions);
|
|
38
|
+
buildNextCheckpointLine(next: storage.StorageCheckpointUpdate): Promise<CheckpointLine | null>;
|
|
39
|
+
/**
|
|
40
|
+
* Get bucket positions to sync, given the list of buckets.
|
|
41
|
+
*
|
|
42
|
+
* @param bucketsToFetch List of buckets to fetch, typically from buildNextCheckpointLine, or a subset of that
|
|
43
|
+
* @returns
|
|
44
|
+
*/
|
|
45
|
+
getFilteredBucketPositions(bucketsToFetch: BucketDescription[]): Map<string, string>;
|
|
46
|
+
/**
|
|
47
|
+
* Update the position of bucket data the client has.
|
|
48
|
+
*
|
|
49
|
+
* @param bucket the bucket name
|
|
50
|
+
* @param nextAfter sync operations >= this value in the next batch
|
|
51
|
+
*/
|
|
52
|
+
updateBucketPosition(options: {
|
|
53
|
+
bucket: string;
|
|
54
|
+
nextAfter: string;
|
|
55
|
+
hasMore: boolean;
|
|
56
|
+
}): void;
|
|
57
|
+
}
|
|
58
|
+
export interface CheckpointUpdate {
|
|
59
|
+
/**
|
|
60
|
+
* All buckets forming part of the checkpoint.
|
|
61
|
+
*/
|
|
62
|
+
buckets: BucketDescription[];
|
|
63
|
+
/**
|
|
64
|
+
* If present, a set of buckets that have been updated since the last checkpoint.
|
|
65
|
+
*
|
|
66
|
+
* If null, assume that any bucket in `buckets` may have been updated.
|
|
67
|
+
*/
|
|
68
|
+
updatedBuckets: Set<string> | null;
|
|
69
|
+
}
|
|
70
|
+
export declare class BucketParameterState {
|
|
71
|
+
readonly bucketStorage: BucketChecksumStateStorage;
|
|
72
|
+
readonly syncRules: SqlSyncRules;
|
|
73
|
+
readonly syncParams: RequestParameters;
|
|
74
|
+
private readonly querier;
|
|
75
|
+
private readonly staticBuckets;
|
|
76
|
+
constructor(bucketStorage: BucketChecksumStateStorage, syncRules: SqlSyncRules, syncParams: RequestParameters);
|
|
77
|
+
getCheckpointUpdate(checkpoint: storage.StorageCheckpointUpdate): Promise<CheckpointUpdate | null>;
|
|
78
|
+
/**
|
|
79
|
+
* For static buckets, we can keep track of which buckets have been updated.
|
|
80
|
+
*/
|
|
81
|
+
private getCheckpointUpdateStatic;
|
|
82
|
+
/**
|
|
83
|
+
* For dynamic buckets, we need to re-query the list of buckets every time.
|
|
84
|
+
*/
|
|
85
|
+
private getCheckpointUpdateDynamic;
|
|
86
|
+
}
|
|
87
|
+
export interface CheckpointLine {
|
|
88
|
+
checkpointLine: util.StreamingSyncCheckpointDiff | util.StreamingSyncCheckpoint;
|
|
89
|
+
bucketsToFetch: BucketDescription[];
|
|
90
|
+
}
|
|
91
|
+
export type BucketChecksumStateStorage = Pick<storage.SyncRulesBucketStorage, 'getChecksums' | 'getParameterSets'>;
|