@powersync/service-core 1.12.0 → 1.13.0
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 +30 -0
- package/dist/api/RouteAPI.d.ts +1 -5
- package/dist/api/diagnostics.js +1 -1
- package/dist/api/diagnostics.js.map +1 -1
- package/dist/entry/cli-entry.js +2 -2
- package/dist/entry/cli-entry.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/metrics/open-telemetry/OpenTelemetryMetricsFactory.d.ts +1 -1
- package/dist/metrics/open-telemetry/OpenTelemetryMetricsFactory.js.map +1 -1
- package/dist/replication/AbstractReplicationJob.d.ts +4 -0
- package/dist/replication/AbstractReplicationJob.js.map +1 -1
- package/dist/replication/AbstractReplicator.d.ts +25 -1
- package/dist/replication/AbstractReplicator.js +53 -3
- package/dist/replication/AbstractReplicator.js.map +1 -1
- package/dist/replication/RelationCache.d.ts +9 -0
- package/dist/replication/RelationCache.js +20 -0
- package/dist/replication/RelationCache.js.map +1 -0
- package/dist/replication/replication-index.d.ts +1 -0
- package/dist/replication/replication-index.js +1 -0
- package/dist/replication/replication-index.js.map +1 -1
- package/dist/replication/replication-metrics.js +6 -0
- package/dist/replication/replication-metrics.js.map +1 -1
- package/dist/routes/endpoints/admin.js +2 -0
- package/dist/routes/endpoints/admin.js.map +1 -1
- package/dist/routes/endpoints/sync-rules.js +6 -6
- package/dist/routes/endpoints/sync-rules.js.map +1 -1
- package/dist/storage/BucketStorageBatch.d.ts +21 -3
- package/dist/storage/BucketStorageBatch.js +2 -1
- package/dist/storage/BucketStorageBatch.js.map +1 -1
- package/dist/storage/PersistedSyncRulesContent.d.ts +5 -0
- package/dist/storage/SourceTable.d.ts +17 -1
- package/dist/storage/SourceTable.js +28 -0
- package/dist/storage/SourceTable.js.map +1 -1
- package/dist/storage/StorageEngine.d.ts +3 -2
- package/dist/storage/StorageEngine.js +3 -0
- package/dist/storage/StorageEngine.js.map +1 -1
- package/dist/storage/StorageProvider.d.ts +2 -0
- package/dist/storage/SyncRulesBucketStorage.d.ts +18 -6
- package/dist/storage/SyncRulesBucketStorage.js.map +1 -1
- package/dist/storage/WriteCheckpointAPI.d.ts +0 -26
- package/dist/storage/WriteCheckpointAPI.js.map +1 -1
- package/dist/storage/bson.js +4 -1
- package/dist/storage/bson.js.map +1 -1
- package/dist/streams/BroadcastIterable.d.ts +1 -1
- package/dist/streams/streams-index.d.ts +0 -1
- package/dist/streams/streams-index.js +0 -1
- package/dist/streams/streams-index.js.map +1 -1
- package/dist/sync/BucketChecksumState.js +2 -2
- package/dist/sync/BucketChecksumState.js.map +1 -1
- package/dist/sync/sync.js +2 -2
- package/dist/sync/sync.js.map +1 -1
- package/dist/system/ServiceContext.js +6 -0
- package/dist/system/ServiceContext.js.map +1 -1
- package/dist/util/protocol-types.d.ts +9 -9
- package/dist/util/protocol-types.js.map +1 -1
- package/dist/util/utils.d.ts +1 -1
- package/package.json +5 -5
- package/src/api/RouteAPI.ts +1 -6
- package/src/api/diagnostics.ts +1 -1
- package/src/entry/cli-entry.ts +2 -2
- package/src/index.ts +2 -0
- package/src/metrics/open-telemetry/OpenTelemetryMetricsFactory.ts +3 -3
- package/src/replication/AbstractReplicationJob.ts +5 -0
- package/src/replication/AbstractReplicator.ts +56 -3
- package/src/replication/RelationCache.ts +25 -0
- package/src/replication/replication-index.ts +1 -0
- package/src/replication/replication-metrics.ts +7 -0
- package/src/routes/endpoints/admin.ts +2 -0
- package/src/routes/endpoints/sync-rules.ts +6 -6
- package/src/storage/BucketStorageBatch.ts +26 -4
- package/src/storage/PersistedSyncRulesContent.ts +6 -0
- package/src/storage/SourceTable.ts +44 -1
- package/src/storage/StorageEngine.ts +6 -2
- package/src/storage/StorageProvider.ts +3 -0
- package/src/storage/SyncRulesBucketStorage.ts +22 -6
- package/src/storage/WriteCheckpointAPI.ts +0 -30
- package/src/storage/bson.ts +4 -1
- package/src/streams/BroadcastIterable.ts +1 -1
- package/src/streams/streams-index.ts +0 -1
- package/src/sync/BucketChecksumState.ts +2 -2
- package/src/sync/sync.ts +3 -3
- package/src/system/ServiceContext.ts +6 -0
- package/src/util/protocol-types.ts +15 -10
- package/tsconfig.tsbuildinfo +1 -1
- package/dist/streams/Demultiplexer.d.ts +0 -52
- package/dist/streams/Demultiplexer.js +0 -128
- package/dist/streams/Demultiplexer.js.map +0 -1
- package/src/streams/Demultiplexer.ts +0 -165
- package/test/src/demultiplexer.test.ts +0 -205
package/src/sync/sync.ts
CHANGED
|
@@ -93,7 +93,7 @@ async function* streamResponseInner(
|
|
|
93
93
|
): AsyncGenerator<util.StreamingSyncLine | string | null> {
|
|
94
94
|
const { raw_data, binary_data } = params;
|
|
95
95
|
|
|
96
|
-
const checkpointUserId = util.checkpointUserId(syncParams.
|
|
96
|
+
const checkpointUserId = util.checkpointUserId(syncParams.tokenParameters.user_id as string, params.client_id);
|
|
97
97
|
|
|
98
98
|
const checksumState = new BucketChecksumState({
|
|
99
99
|
syncContext,
|
|
@@ -228,7 +228,7 @@ async function* streamResponseInner(
|
|
|
228
228
|
onRowsSent: markOperationsSent,
|
|
229
229
|
abort_connection: signal,
|
|
230
230
|
abort_batch: abortCheckpointSignal,
|
|
231
|
-
user_id: syncParams.
|
|
231
|
+
user_id: syncParams.userId,
|
|
232
232
|
// Passing null here will emit a full sync complete message at the end. If we pass a priority, we'll emit a partial
|
|
233
233
|
// sync complete message instead.
|
|
234
234
|
forPriority: !isLast ? priority : null,
|
|
@@ -440,7 +440,7 @@ async function* bucketDataBatch(request: BucketDataRequest): AsyncGenerator<Buck
|
|
|
440
440
|
}
|
|
441
441
|
}
|
|
442
442
|
|
|
443
|
-
function transformLegacyResponse(bucketData: util.SyncBucketData):
|
|
443
|
+
function transformLegacyResponse(bucketData: util.SyncBucketData): util.SyncBucketData<util.ProtocolOplogData> {
|
|
444
444
|
return {
|
|
445
445
|
...bucketData,
|
|
446
446
|
data: bucketData.data.map((entry) => {
|
|
@@ -59,6 +59,12 @@ export class ServiceContextContainer implements ServiceContext {
|
|
|
59
59
|
this.storageEngine = new storage.StorageEngine({
|
|
60
60
|
configuration
|
|
61
61
|
});
|
|
62
|
+
this.storageEngine.registerListener({
|
|
63
|
+
storageFatalError: (error) => {
|
|
64
|
+
// Propagate the error to the lifecycle engine
|
|
65
|
+
this.lifeCycleEngine.stopWithError(error);
|
|
66
|
+
}
|
|
67
|
+
});
|
|
62
68
|
|
|
63
69
|
this.lifeCycleEngine.withLifecycle(this.storageEngine, {
|
|
64
70
|
start: (storageEngine) => storageEngine.start(),
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import * as t from 'ts-codec';
|
|
2
|
-
import { BucketDescription, BucketPriority,
|
|
2
|
+
import { BucketDescription, BucketPriority, SqliteJsonRow } from '@powersync/service-sync-rules';
|
|
3
|
+
import { JsonContainer } from '@powersync/service-jsonbig';
|
|
3
4
|
|
|
4
5
|
export const BucketRequest = t.object({
|
|
5
6
|
name: t.string,
|
|
@@ -65,7 +66,7 @@ export interface StreamingSyncCheckpointDiff {
|
|
|
65
66
|
}
|
|
66
67
|
|
|
67
68
|
export interface StreamingSyncData {
|
|
68
|
-
data: SyncBucketData
|
|
69
|
+
data: SyncBucketData<ProtocolOplogData>;
|
|
69
70
|
}
|
|
70
71
|
|
|
71
72
|
export interface StreamingSyncCheckpointComplete {
|
|
@@ -109,13 +110,9 @@ export interface BucketState {
|
|
|
109
110
|
op_id: string;
|
|
110
111
|
}
|
|
111
112
|
|
|
112
|
-
export interface
|
|
113
|
-
buckets: SyncBucketData[];
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
export interface SyncBucketData {
|
|
113
|
+
export interface SyncBucketData<Data extends ProtocolOplogData = StoredOplogData> {
|
|
117
114
|
bucket: string;
|
|
118
|
-
data: OplogEntry[];
|
|
115
|
+
data: OplogEntry<Data>[];
|
|
119
116
|
/**
|
|
120
117
|
* True if there _could_ be more data for this bucket, and another request must be made.
|
|
121
118
|
*/
|
|
@@ -130,12 +127,20 @@ export interface SyncBucketData {
|
|
|
130
127
|
next_after: ProtocolOpId;
|
|
131
128
|
}
|
|
132
129
|
|
|
133
|
-
export
|
|
130
|
+
export type StoredOplogData = string | null;
|
|
131
|
+
|
|
132
|
+
// Note: When clients have both raw_data and binary_data disabled (this only affects legacy
|
|
133
|
+
// clients), data is actually a `Record<string, SqliteJsonValue>`. Oplog entries are always
|
|
134
|
+
// stored as a serialized (JSON) string so that they don't have to be parsed in the sync service,
|
|
135
|
+
// this representation only exists on the way out for legacy clients.
|
|
136
|
+
export type ProtocolOplogData = SqliteJsonRow | JsonContainer | StoredOplogData;
|
|
137
|
+
|
|
138
|
+
export interface OplogEntry<Data extends ProtocolOplogData = StoredOplogData> {
|
|
134
139
|
op_id: ProtocolOpId;
|
|
135
140
|
op: 'PUT' | 'REMOVE' | 'MOVE' | 'CLEAR';
|
|
136
141
|
object_type?: string;
|
|
137
142
|
object_id?: string;
|
|
138
|
-
data?:
|
|
143
|
+
data?: Data;
|
|
139
144
|
checksum: number | bigint;
|
|
140
145
|
subkey?: string;
|
|
141
146
|
}
|