@powersync/service-core 0.0.0-dev-20240725112650 → 0.0.0-dev-20240918082156
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 +80 -2
- package/dist/api/RouteAPI.d.ts +68 -0
- package/dist/api/RouteAPI.js +2 -0
- package/dist/api/RouteAPI.js.map +1 -0
- package/dist/api/api-index.d.ts +1 -0
- package/dist/api/api-index.js +1 -0
- package/dist/api/api-index.js.map +1 -1
- package/dist/api/diagnostics.d.ts +4 -4
- package/dist/api/diagnostics.js +11 -65
- package/dist/api/diagnostics.js.map +1 -1
- package/dist/api/schema.d.ts +3 -5
- package/dist/api/schema.js +9 -79
- package/dist/api/schema.js.map +1 -1
- package/dist/auth/KeyStore.d.ts +7 -4
- package/dist/auth/KeyStore.js +1 -1
- package/dist/auth/KeyStore.js.map +1 -1
- package/dist/auth/auth-index.d.ts +0 -1
- package/dist/auth/auth-index.js +0 -1
- package/dist/auth/auth-index.js.map +1 -1
- package/dist/entry/cli-entry.js +3 -2
- package/dist/entry/cli-entry.js.map +1 -1
- package/dist/entry/commands/compact-action.js +12 -8
- package/dist/entry/commands/compact-action.js.map +1 -1
- package/dist/entry/commands/migrate-action.js +4 -5
- package/dist/entry/commands/migrate-action.js.map +1 -1
- package/dist/entry/commands/teardown-action.js +2 -2
- package/dist/entry/commands/teardown-action.js.map +1 -1
- package/dist/index.d.ts +4 -2
- package/dist/index.js +4 -2
- package/dist/index.js.map +1 -1
- package/dist/metrics/Metrics.d.ts +2 -2
- package/dist/metrics/Metrics.js +5 -13
- package/dist/metrics/Metrics.js.map +1 -1
- package/dist/migrations/db/migrations/1684951997326-init.d.ts +2 -2
- package/dist/migrations/db/migrations/1684951997326-init.js +4 -2
- package/dist/migrations/db/migrations/1684951997326-init.js.map +1 -1
- package/dist/migrations/db/migrations/1702295701188-sync-rule-state.d.ts +2 -2
- package/dist/migrations/db/migrations/1702295701188-sync-rule-state.js +4 -2
- package/dist/migrations/db/migrations/1702295701188-sync-rule-state.js.map +1 -1
- package/dist/migrations/db/migrations/1711543888062-write-checkpoint-index.d.ts +2 -2
- package/dist/migrations/db/migrations/1711543888062-write-checkpoint-index.js +4 -2
- package/dist/migrations/db/migrations/1711543888062-write-checkpoint-index.js.map +1 -1
- package/dist/migrations/migrations.d.ts +8 -0
- package/dist/migrations/migrations.js +19 -7
- package/dist/migrations/migrations.js.map +1 -1
- package/dist/modules/AbstractModule.d.ts +26 -0
- package/dist/modules/AbstractModule.js +11 -0
- package/dist/modules/AbstractModule.js.map +1 -0
- package/dist/modules/ModuleManager.d.ts +11 -0
- package/dist/modules/ModuleManager.js +32 -0
- package/dist/modules/ModuleManager.js.map +1 -0
- package/dist/modules/modules-index.d.ts +2 -0
- package/dist/modules/modules-index.js +3 -0
- package/dist/modules/modules-index.js.map +1 -0
- package/dist/replication/AbstractReplicationJob.d.ts +38 -0
- package/dist/replication/AbstractReplicationJob.js +51 -0
- package/dist/replication/AbstractReplicationJob.js.map +1 -0
- package/dist/replication/AbstractReplicator.d.ts +53 -0
- package/dist/replication/AbstractReplicator.js +187 -0
- package/dist/replication/AbstractReplicator.js.map +1 -0
- package/dist/replication/ErrorRateLimiter.d.ts +0 -9
- package/dist/replication/ErrorRateLimiter.js +1 -42
- package/dist/replication/ErrorRateLimiter.js.map +1 -1
- package/dist/replication/ReplicationEngine.d.ts +18 -0
- package/dist/replication/ReplicationEngine.js +41 -0
- package/dist/replication/ReplicationEngine.js.map +1 -0
- package/dist/replication/ReplicationModule.d.ts +39 -0
- package/dist/replication/ReplicationModule.js +65 -0
- package/dist/replication/ReplicationModule.js.map +1 -0
- package/dist/replication/replication-index.d.ts +4 -6
- package/dist/replication/replication-index.js +4 -6
- package/dist/replication/replication-index.js.map +1 -1
- package/dist/routes/RouterEngine.d.ts +42 -0
- package/dist/routes/RouterEngine.js +80 -0
- package/dist/routes/RouterEngine.js.map +1 -0
- package/dist/routes/auth.d.ts +2 -2
- package/dist/routes/auth.js +11 -11
- package/dist/routes/auth.js.map +1 -1
- package/dist/routes/configure-fastify.d.ts +30 -176
- package/dist/routes/configure-fastify.js +10 -11
- package/dist/routes/configure-fastify.js.map +1 -1
- package/dist/routes/configure-rsocket.d.ts +3 -3
- package/dist/routes/configure-rsocket.js +6 -5
- package/dist/routes/configure-rsocket.js.map +1 -1
- package/dist/routes/endpoints/admin.d.ts +0 -34
- package/dist/routes/endpoints/admin.js +48 -89
- package/dist/routes/endpoints/admin.js.map +1 -1
- package/dist/routes/endpoints/checkpointing.d.ts +56 -16
- package/dist/routes/endpoints/checkpointing.js +33 -12
- package/dist/routes/endpoints/checkpointing.js.map +1 -1
- package/dist/routes/endpoints/route-endpoints-index.d.ts +0 -1
- package/dist/routes/endpoints/route-endpoints-index.js +0 -1
- package/dist/routes/endpoints/route-endpoints-index.js.map +1 -1
- package/dist/routes/endpoints/socket-route.js +40 -25
- package/dist/routes/endpoints/socket-route.js.map +1 -1
- package/dist/routes/endpoints/sync-rules.d.ts +1 -1
- package/dist/routes/endpoints/sync-rules.js +32 -23
- package/dist/routes/endpoints/sync-rules.js.map +1 -1
- package/dist/routes/endpoints/sync-stream.d.ts +10 -0
- package/dist/routes/endpoints/sync-stream.js +13 -8
- package/dist/routes/endpoints/sync-stream.js.map +1 -1
- package/dist/routes/router-socket.d.ts +1 -0
- package/dist/routes/router-socket.js +2 -1
- package/dist/routes/router-socket.js.map +1 -1
- package/dist/routes/router.d.ts +6 -2
- package/dist/routes/router.js.map +1 -1
- package/dist/routes/routes-index.d.ts +1 -0
- package/dist/routes/routes-index.js +1 -0
- package/dist/routes/routes-index.js.map +1 -1
- package/dist/runner/teardown.js +47 -76
- package/dist/runner/teardown.js.map +1 -1
- package/dist/storage/BucketStorage.d.ts +30 -19
- package/dist/storage/BucketStorage.js +0 -10
- package/dist/storage/BucketStorage.js.map +1 -1
- package/dist/storage/MongoBucketStorage.d.ts +4 -4
- package/dist/storage/MongoBucketStorage.js +19 -24
- package/dist/storage/MongoBucketStorage.js.map +1 -1
- package/dist/storage/SourceEntity.d.ts +20 -0
- package/dist/storage/SourceEntity.js +2 -0
- package/dist/storage/SourceEntity.js.map +1 -0
- package/dist/storage/SourceTable.d.ts +4 -5
- package/dist/storage/SourceTable.js +3 -4
- package/dist/storage/SourceTable.js.map +1 -1
- package/dist/storage/StorageEngine.d.ts +24 -0
- package/dist/storage/StorageEngine.js +43 -0
- package/dist/storage/StorageEngine.js.map +1 -0
- package/dist/storage/StorageProvider.d.ts +21 -0
- package/dist/storage/StorageProvider.js +2 -0
- package/dist/storage/StorageProvider.js.map +1 -0
- package/dist/storage/mongo/MongoBucketBatch.d.ts +1 -1
- package/dist/storage/mongo/MongoBucketBatch.js +6 -7
- package/dist/storage/mongo/MongoBucketBatch.js.map +1 -1
- package/dist/storage/mongo/MongoCompactor.js +2 -1
- package/dist/storage/mongo/MongoCompactor.js.map +1 -1
- package/dist/storage/mongo/MongoPersistedSyncRulesContent.d.ts +2 -2
- package/dist/storage/mongo/MongoPersistedSyncRulesContent.js +2 -2
- package/dist/storage/mongo/MongoPersistedSyncRulesContent.js.map +1 -1
- package/dist/storage/mongo/MongoStorageProvider.d.ts +5 -0
- package/dist/storage/mongo/MongoStorageProvider.js +26 -0
- package/dist/storage/mongo/MongoStorageProvider.js.map +1 -0
- package/dist/storage/mongo/MongoSyncBucketStorage.d.ts +7 -6
- package/dist/storage/mongo/MongoSyncBucketStorage.js +24 -15
- package/dist/storage/mongo/MongoSyncBucketStorage.js.map +1 -1
- package/dist/storage/mongo/MongoSyncRulesLock.js +1 -1
- package/dist/storage/mongo/MongoSyncRulesLock.js.map +1 -1
- package/dist/storage/mongo/OperationBatch.d.ts +7 -3
- package/dist/storage/mongo/OperationBatch.js +16 -7
- package/dist/storage/mongo/OperationBatch.js.map +1 -1
- package/dist/storage/mongo/PersistedBatch.d.ts +3 -3
- package/dist/storage/mongo/PersistedBatch.js +2 -2
- package/dist/storage/mongo/PersistedBatch.js.map +1 -1
- package/dist/storage/mongo/models.d.ts +13 -4
- package/dist/storage/mongo/models.js.map +1 -1
- package/dist/storage/mongo/util.d.ts +12 -1
- package/dist/storage/mongo/util.js +50 -2
- package/dist/storage/mongo/util.js.map +1 -1
- package/dist/storage/storage-index.d.ts +5 -2
- package/dist/storage/storage-index.js +5 -2
- package/dist/storage/storage-index.js.map +1 -1
- package/dist/sync/sync.d.ts +2 -1
- package/dist/sync/sync.js +36 -10
- package/dist/sync/sync.js.map +1 -1
- package/dist/sync/util.js.map +1 -1
- package/dist/system/ServiceContext.d.ts +37 -0
- package/dist/system/ServiceContext.js +48 -0
- package/dist/system/ServiceContext.js.map +1 -0
- package/dist/system/system-index.d.ts +1 -1
- package/dist/system/system-index.js +1 -1
- package/dist/system/system-index.js.map +1 -1
- package/dist/util/config/compound-config-collector.d.ts +9 -2
- package/dist/util/config/compound-config-collector.js +14 -23
- package/dist/util/config/compound-config-collector.js.map +1 -1
- package/dist/util/config/sync-rules/sync-rules-provider.d.ts +9 -0
- package/dist/util/config/sync-rules/sync-rules-provider.js +15 -0
- package/dist/util/config/sync-rules/sync-rules-provider.js.map +1 -0
- package/dist/util/config/types.d.ts +6 -4
- package/dist/util/config/types.js.map +1 -1
- package/dist/util/config.d.ts +3 -4
- package/dist/util/config.js +5 -20
- package/dist/util/config.js.map +1 -1
- package/dist/util/protocol-types.d.ts +4 -0
- package/dist/util/protocol-types.js +5 -1
- package/dist/util/protocol-types.js.map +1 -1
- package/dist/util/util-index.d.ts +3 -6
- package/dist/util/util-index.js +3 -6
- package/dist/util/util-index.js.map +1 -1
- package/dist/util/utils.d.ts +10 -6
- package/dist/util/utils.js +45 -25
- package/dist/util/utils.js.map +1 -1
- package/package.json +5 -7
- package/src/api/RouteAPI.ts +78 -0
- package/src/api/api-index.ts +1 -0
- package/src/api/diagnostics.ts +16 -71
- package/src/api/schema.ts +13 -89
- package/src/auth/KeyStore.ts +9 -6
- package/src/auth/auth-index.ts +0 -1
- package/src/entry/cli-entry.ts +3 -2
- package/src/entry/commands/compact-action.ts +12 -9
- package/src/entry/commands/migrate-action.ts +5 -8
- package/src/entry/commands/teardown-action.ts +2 -2
- package/src/index.ts +5 -2
- package/src/metrics/Metrics.ts +6 -16
- package/src/migrations/db/migrations/1684951997326-init.ts +9 -4
- package/src/migrations/db/migrations/1702295701188-sync-rule-state.ts +7 -4
- package/src/migrations/db/migrations/1711543888062-write-checkpoint-index.ts +6 -4
- package/src/migrations/migrations.ts +24 -8
- package/src/modules/AbstractModule.ts +37 -0
- package/src/modules/ModuleManager.ts +34 -0
- package/src/modules/modules-index.ts +2 -0
- package/src/replication/AbstractReplicationJob.ts +79 -0
- package/src/replication/AbstractReplicator.ts +227 -0
- package/src/replication/ErrorRateLimiter.ts +0 -44
- package/src/replication/ReplicationEngine.ts +43 -0
- package/src/replication/ReplicationModule.ts +101 -0
- package/src/replication/replication-index.ts +4 -6
- package/src/routes/RouterEngine.ts +120 -0
- package/src/routes/auth.ts +21 -12
- package/src/routes/configure-fastify.ts +13 -14
- package/src/routes/configure-rsocket.ts +9 -8
- package/src/routes/endpoints/admin.ts +74 -100
- package/src/routes/endpoints/checkpointing.ts +46 -12
- package/src/routes/endpoints/route-endpoints-index.ts +0 -1
- package/src/routes/endpoints/socket-route.ts +44 -27
- package/src/routes/endpoints/sync-rules.ts +41 -25
- package/src/routes/endpoints/sync-stream.ts +13 -8
- package/src/routes/router-socket.ts +2 -1
- package/src/routes/router.ts +6 -3
- package/src/routes/routes-index.ts +1 -0
- package/src/runner/teardown.ts +50 -88
- package/src/storage/BucketStorage.ts +38 -25
- package/src/storage/MongoBucketStorage.ts +23 -26
- package/src/storage/SourceEntity.ts +22 -0
- package/src/storage/SourceTable.ts +4 -6
- package/src/storage/StorageEngine.ts +55 -0
- package/src/storage/StorageProvider.ts +27 -0
- package/src/storage/mongo/MongoBucketBatch.ts +8 -8
- package/src/storage/mongo/MongoCompactor.ts +2 -1
- package/src/storage/mongo/MongoPersistedSyncRulesContent.ts +3 -3
- package/src/storage/mongo/MongoStorageProvider.ts +31 -0
- package/src/storage/mongo/MongoSyncBucketStorage.ts +39 -20
- package/src/storage/mongo/MongoSyncRulesLock.ts +1 -1
- package/src/storage/mongo/OperationBatch.ts +18 -11
- package/src/storage/mongo/PersistedBatch.ts +6 -5
- package/src/storage/mongo/models.ts +13 -4
- package/src/storage/mongo/util.ts +49 -4
- package/src/storage/storage-index.ts +5 -2
- package/src/sync/sync.ts +46 -11
- package/src/sync/util.ts +0 -1
- package/src/system/ServiceContext.ts +68 -0
- package/src/system/system-index.ts +1 -1
- package/src/util/config/compound-config-collector.ts +30 -31
- package/src/util/config/sync-rules/sync-rules-provider.ts +18 -0
- package/src/util/config/types.ts +6 -5
- package/src/util/config.ts +6 -23
- package/src/util/protocol-types.ts +6 -1
- package/src/util/util-index.ts +3 -6
- package/src/util/utils.ts +55 -39
- package/test/src/__snapshots__/sync.test.ts.snap +7 -7
- package/test/src/auth.test.ts +7 -7
- package/test/src/broadcast_iterable.test.ts +1 -1
- package/test/src/checksum_cache.test.ts +3 -3
- package/test/src/compacting.test.ts +26 -17
- package/test/src/data_storage.test.ts +258 -146
- package/test/src/env.ts +1 -3
- package/test/src/merge_iterable.test.ts +1 -6
- package/test/src/setup.ts +1 -1
- package/test/src/stream_utils.ts +42 -0
- package/test/src/sync.test.ts +52 -31
- package/test/src/util.ts +48 -51
- package/test/tsconfig.json +1 -1
- package/tsconfig.tsbuildinfo +1 -1
- package/dist/auth/SupabaseKeyCollector.d.ts +0 -22
- package/dist/auth/SupabaseKeyCollector.js +0 -61
- package/dist/auth/SupabaseKeyCollector.js.map +0 -1
- package/dist/replication/PgRelation.d.ts +0 -16
- package/dist/replication/PgRelation.js +0 -26
- package/dist/replication/PgRelation.js.map +0 -1
- package/dist/replication/WalConnection.d.ts +0 -34
- package/dist/replication/WalConnection.js +0 -190
- package/dist/replication/WalConnection.js.map +0 -1
- package/dist/replication/WalStream.d.ts +0 -57
- package/dist/replication/WalStream.js +0 -515
- package/dist/replication/WalStream.js.map +0 -1
- package/dist/replication/WalStreamManager.d.ts +0 -30
- package/dist/replication/WalStreamManager.js +0 -198
- package/dist/replication/WalStreamManager.js.map +0 -1
- package/dist/replication/WalStreamRunner.d.ts +0 -38
- package/dist/replication/WalStreamRunner.js +0 -155
- package/dist/replication/WalStreamRunner.js.map +0 -1
- package/dist/replication/util.d.ts +0 -9
- package/dist/replication/util.js +0 -62
- package/dist/replication/util.js.map +0 -1
- package/dist/routes/endpoints/dev.d.ts +0 -312
- package/dist/routes/endpoints/dev.js +0 -172
- package/dist/routes/endpoints/dev.js.map +0 -1
- package/dist/system/CorePowerSyncSystem.d.ts +0 -23
- package/dist/system/CorePowerSyncSystem.js +0 -52
- package/dist/system/CorePowerSyncSystem.js.map +0 -1
- package/dist/util/PgManager.d.ts +0 -24
- package/dist/util/PgManager.js +0 -55
- package/dist/util/PgManager.js.map +0 -1
- package/dist/util/migration_lib.d.ts +0 -11
- package/dist/util/migration_lib.js +0 -64
- package/dist/util/migration_lib.js.map +0 -1
- package/dist/util/pgwire_utils.d.ts +0 -24
- package/dist/util/pgwire_utils.js +0 -117
- package/dist/util/pgwire_utils.js.map +0 -1
- package/dist/util/populate_test_data.d.ts +0 -8
- package/dist/util/populate_test_data.js +0 -65
- package/dist/util/populate_test_data.js.map +0 -1
- package/src/auth/SupabaseKeyCollector.ts +0 -67
- package/src/replication/PgRelation.ts +0 -42
- package/src/replication/WalConnection.ts +0 -227
- package/src/replication/WalStream.ts +0 -624
- package/src/replication/WalStreamManager.ts +0 -213
- package/src/replication/WalStreamRunner.ts +0 -180
- package/src/replication/util.ts +0 -76
- package/src/routes/endpoints/dev.ts +0 -199
- package/src/system/CorePowerSyncSystem.ts +0 -64
- package/src/util/PgManager.ts +0 -64
- package/src/util/migration_lib.ts +0 -79
- package/src/util/pgwire_utils.ts +0 -139
- package/src/util/populate_test_data.ts +0 -78
- package/test/src/__snapshots__/pg_test.test.ts.snap +0 -256
- package/test/src/large_batch.test.ts +0 -194
- package/test/src/pg_test.test.ts +0 -450
- package/test/src/schema_changes.test.ts +0 -545
- package/test/src/slow_tests.test.ts +0 -338
- package/test/src/validation.test.ts +0 -63
- package/test/src/wal_stream.test.ts +0 -319
- package/test/src/wal_stream_utils.ts +0 -156
package/test/src/env.ts
CHANGED
|
@@ -2,7 +2,5 @@ import { utils } from '@powersync/lib-services-framework';
|
|
|
2
2
|
|
|
3
3
|
export const env = utils.collectEnvironmentVariables({
|
|
4
4
|
MONGO_TEST_URL: utils.type.string.default('mongodb://localhost:27017/powersync_test'),
|
|
5
|
-
|
|
6
|
-
CI: utils.type.boolean.default('false'),
|
|
7
|
-
SLOW_TESTS: utils.type.boolean.default('false')
|
|
5
|
+
CI: utils.type.boolean.default('false')
|
|
8
6
|
});
|
|
@@ -1,11 +1,6 @@
|
|
|
1
|
+
import { mergeAsyncIterablesNew, mergeAsyncIterablesOld } from '@/sync/merge.js';
|
|
1
2
|
import * as timers from 'timers/promises';
|
|
2
3
|
import { describe, expect, test } from 'vitest';
|
|
3
|
-
import {
|
|
4
|
-
FixedMergeAsyncIterable,
|
|
5
|
-
mergeAsyncIterables,
|
|
6
|
-
mergeAsyncIterablesNew,
|
|
7
|
-
mergeAsyncIterablesOld
|
|
8
|
-
} from '../../src/sync/merge.js';
|
|
9
4
|
|
|
10
5
|
type MergeIteratorFunction = <T>(source: AsyncIterable<T>[]) => AsyncIterable<T>;
|
|
11
6
|
|
package/test/src/setup.ts
CHANGED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { OplogEntry } from '@/util/protocol-types.js';
|
|
2
|
+
import { JSONBig } from '@powersync/service-jsonbig';
|
|
3
|
+
|
|
4
|
+
export function putOp(table: string, data: Record<string, any>): Partial<OplogEntry> {
|
|
5
|
+
return {
|
|
6
|
+
op: 'PUT',
|
|
7
|
+
object_type: table,
|
|
8
|
+
object_id: data.id,
|
|
9
|
+
data: JSONBig.stringify(data)
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function removeOp(table: string, id: string): Partial<OplogEntry> {
|
|
14
|
+
return {
|
|
15
|
+
op: 'REMOVE',
|
|
16
|
+
object_type: table,
|
|
17
|
+
object_id: id
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function compareIds(a: OplogEntry, b: OplogEntry) {
|
|
22
|
+
return a.object_id!.localeCompare(b.object_id!);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export async function oneFromAsync<T>(source: Iterable<T> | AsyncIterable<T>): Promise<T> {
|
|
26
|
+
const items: T[] = [];
|
|
27
|
+
for await (const item of source) {
|
|
28
|
+
items.push(item);
|
|
29
|
+
}
|
|
30
|
+
if (items.length != 1) {
|
|
31
|
+
throw new Error(`One item expected, got: ${items.length}`);
|
|
32
|
+
}
|
|
33
|
+
return items[0];
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export async function fromAsync<T>(source: Iterable<T> | AsyncIterable<T>): Promise<T[]> {
|
|
37
|
+
const items: T[] = [];
|
|
38
|
+
for await (const item of source) {
|
|
39
|
+
items.push(item);
|
|
40
|
+
}
|
|
41
|
+
return items;
|
|
42
|
+
}
|
package/test/src/sync.test.ts
CHANGED
|
@@ -1,13 +1,19 @@
|
|
|
1
1
|
import { RequestTracker } from '@/sync/RequestTracker.js';
|
|
2
|
+
import { streamResponse } from '@/sync/sync.js';
|
|
2
3
|
import { StreamingSyncLine } from '@/util/protocol-types.js';
|
|
3
|
-
import { lsnMakeComparable } from '@powersync/service-jpgwire';
|
|
4
4
|
import { JSONBig } from '@powersync/service-jsonbig';
|
|
5
5
|
import { RequestParameters } from '@powersync/service-sync-rules';
|
|
6
6
|
import * as timers from 'timers/promises';
|
|
7
7
|
import { describe, expect, test } from 'vitest';
|
|
8
|
-
import {
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
import {
|
|
9
|
+
BATCH_OPTIONS,
|
|
10
|
+
makeTestTable,
|
|
11
|
+
MONGO_STORAGE_FACTORY,
|
|
12
|
+
PARSE_OPTIONS,
|
|
13
|
+
StorageFactory,
|
|
14
|
+
ZERO_LSN
|
|
15
|
+
} from './util.js';
|
|
16
|
+
import { ParseSyncRulesOptions, StartBatchOptions } from '@/storage/BucketStorage.js';
|
|
11
17
|
|
|
12
18
|
describe('sync - mongodb', function () {
|
|
13
19
|
defineTests(MONGO_STORAGE_FACTORY);
|
|
@@ -32,18 +38,19 @@ function defineTests(factory: StorageFactory) {
|
|
|
32
38
|
content: BASIC_SYNC_RULES
|
|
33
39
|
});
|
|
34
40
|
|
|
35
|
-
const storage = await f.getInstance(syncRules
|
|
41
|
+
const storage = await f.getInstance(syncRules);
|
|
36
42
|
await storage.setSnapshotDone(ZERO_LSN);
|
|
37
43
|
await storage.autoActivate();
|
|
38
44
|
|
|
39
|
-
const result = await storage.startBatch(
|
|
45
|
+
const result = await storage.startBatch(BATCH_OPTIONS, async (batch) => {
|
|
40
46
|
await batch.save({
|
|
41
47
|
sourceTable: TEST_TABLE,
|
|
42
48
|
tag: 'insert',
|
|
43
49
|
after: {
|
|
44
50
|
id: 't1',
|
|
45
51
|
description: 'Test 1'
|
|
46
|
-
}
|
|
52
|
+
},
|
|
53
|
+
afterReplicaId: 't1'
|
|
47
54
|
});
|
|
48
55
|
|
|
49
56
|
await batch.save({
|
|
@@ -52,10 +59,11 @@ function defineTests(factory: StorageFactory) {
|
|
|
52
59
|
after: {
|
|
53
60
|
id: 't2',
|
|
54
61
|
description: 'Test 2'
|
|
55
|
-
}
|
|
62
|
+
},
|
|
63
|
+
afterReplicaId: 't2'
|
|
56
64
|
});
|
|
57
65
|
|
|
58
|
-
await batch.commit(
|
|
66
|
+
await batch.commit('0/1');
|
|
59
67
|
});
|
|
60
68
|
|
|
61
69
|
const stream = streamResponse({
|
|
@@ -65,6 +73,7 @@ function defineTests(factory: StorageFactory) {
|
|
|
65
73
|
include_checksum: true,
|
|
66
74
|
raw_data: true
|
|
67
75
|
},
|
|
76
|
+
parseOptions: PARSE_OPTIONS,
|
|
68
77
|
tracker,
|
|
69
78
|
syncParams: new RequestParameters({ sub: '' }, {}),
|
|
70
79
|
token: { exp: Date.now() / 1000 + 10 } as any
|
|
@@ -81,11 +90,11 @@ function defineTests(factory: StorageFactory) {
|
|
|
81
90
|
content: BASIC_SYNC_RULES
|
|
82
91
|
});
|
|
83
92
|
|
|
84
|
-
const storage = await f.getInstance(syncRules
|
|
93
|
+
const storage = await f.getInstance(syncRules);
|
|
85
94
|
await storage.setSnapshotDone(ZERO_LSN);
|
|
86
95
|
await storage.autoActivate();
|
|
87
96
|
|
|
88
|
-
const result = await storage.startBatch(
|
|
97
|
+
const result = await storage.startBatch(BATCH_OPTIONS, async (batch) => {
|
|
89
98
|
await batch.save({
|
|
90
99
|
sourceTable: TEST_TABLE,
|
|
91
100
|
tag: 'insert',
|
|
@@ -93,10 +102,11 @@ function defineTests(factory: StorageFactory) {
|
|
|
93
102
|
id: 't1',
|
|
94
103
|
description: 'Test\n"string"',
|
|
95
104
|
large_num: 12345678901234567890n
|
|
96
|
-
}
|
|
105
|
+
},
|
|
106
|
+
afterReplicaId: 't1'
|
|
97
107
|
});
|
|
98
108
|
|
|
99
|
-
await batch.commit(
|
|
109
|
+
await batch.commit('0/1');
|
|
100
110
|
});
|
|
101
111
|
|
|
102
112
|
const stream = streamResponse({
|
|
@@ -106,6 +116,7 @@ function defineTests(factory: StorageFactory) {
|
|
|
106
116
|
include_checksum: true,
|
|
107
117
|
raw_data: false
|
|
108
118
|
},
|
|
119
|
+
parseOptions: PARSE_OPTIONS,
|
|
109
120
|
tracker,
|
|
110
121
|
syncParams: new RequestParameters({ sub: '' }, {}),
|
|
111
122
|
token: { exp: Date.now() / 1000 + 10 } as any
|
|
@@ -124,7 +135,7 @@ function defineTests(factory: StorageFactory) {
|
|
|
124
135
|
content: BASIC_SYNC_RULES
|
|
125
136
|
});
|
|
126
137
|
|
|
127
|
-
const storage = await f.getInstance(syncRules
|
|
138
|
+
const storage = await f.getInstance(syncRules);
|
|
128
139
|
await storage.setSnapshotDone(ZERO_LSN);
|
|
129
140
|
await storage.autoActivate();
|
|
130
141
|
|
|
@@ -135,6 +146,7 @@ function defineTests(factory: StorageFactory) {
|
|
|
135
146
|
include_checksum: true,
|
|
136
147
|
raw_data: true
|
|
137
148
|
},
|
|
149
|
+
parseOptions: PARSE_OPTIONS,
|
|
138
150
|
tracker,
|
|
139
151
|
syncParams: new RequestParameters({ sub: '' }, {}),
|
|
140
152
|
token: { exp: 0 } as any
|
|
@@ -151,7 +163,7 @@ function defineTests(factory: StorageFactory) {
|
|
|
151
163
|
content: BASIC_SYNC_RULES
|
|
152
164
|
});
|
|
153
165
|
|
|
154
|
-
const storage = await f.getInstance(syncRules
|
|
166
|
+
const storage = await f.getInstance(syncRules);
|
|
155
167
|
await storage.setSnapshotDone(ZERO_LSN);
|
|
156
168
|
await storage.autoActivate();
|
|
157
169
|
|
|
@@ -162,6 +174,7 @@ function defineTests(factory: StorageFactory) {
|
|
|
162
174
|
include_checksum: true,
|
|
163
175
|
raw_data: true
|
|
164
176
|
},
|
|
177
|
+
parseOptions: PARSE_OPTIONS,
|
|
165
178
|
tracker,
|
|
166
179
|
syncParams: new RequestParameters({ sub: '' }, {}),
|
|
167
180
|
token: { exp: Date.now() / 1000 + 10 } as any
|
|
@@ -170,32 +183,34 @@ function defineTests(factory: StorageFactory) {
|
|
|
170
183
|
|
|
171
184
|
expect(await getCheckpointLines(iter)).toMatchSnapshot();
|
|
172
185
|
|
|
173
|
-
await storage.startBatch(
|
|
186
|
+
await storage.startBatch(BATCH_OPTIONS, async (batch) => {
|
|
174
187
|
await batch.save({
|
|
175
188
|
sourceTable: TEST_TABLE,
|
|
176
189
|
tag: 'insert',
|
|
177
190
|
after: {
|
|
178
191
|
id: 't1',
|
|
179
192
|
description: 'Test 1'
|
|
180
|
-
}
|
|
193
|
+
},
|
|
194
|
+
afterReplicaId: 't1'
|
|
181
195
|
});
|
|
182
196
|
|
|
183
|
-
await batch.commit(
|
|
197
|
+
await batch.commit('0/1');
|
|
184
198
|
});
|
|
185
199
|
|
|
186
200
|
expect(await getCheckpointLines(iter)).toMatchSnapshot();
|
|
187
201
|
|
|
188
|
-
await storage.startBatch(
|
|
202
|
+
await storage.startBatch(BATCH_OPTIONS, async (batch) => {
|
|
189
203
|
await batch.save({
|
|
190
204
|
sourceTable: TEST_TABLE,
|
|
191
205
|
tag: 'insert',
|
|
192
206
|
after: {
|
|
193
207
|
id: 't2',
|
|
194
208
|
description: 'Test 2'
|
|
195
|
-
}
|
|
209
|
+
},
|
|
210
|
+
afterReplicaId: 't2'
|
|
196
211
|
});
|
|
197
212
|
|
|
198
|
-
await batch.commit(
|
|
213
|
+
await batch.commit('0/2');
|
|
199
214
|
});
|
|
200
215
|
|
|
201
216
|
expect(await getCheckpointLines(iter)).toMatchSnapshot();
|
|
@@ -210,7 +225,7 @@ function defineTests(factory: StorageFactory) {
|
|
|
210
225
|
content: BASIC_SYNC_RULES
|
|
211
226
|
});
|
|
212
227
|
|
|
213
|
-
const storage = await f.getInstance(syncRules
|
|
228
|
+
const storage = await f.getInstance(syncRules);
|
|
214
229
|
await storage.setSnapshotDone(ZERO_LSN);
|
|
215
230
|
await storage.autoActivate();
|
|
216
231
|
|
|
@@ -223,6 +238,7 @@ function defineTests(factory: StorageFactory) {
|
|
|
223
238
|
include_checksum: true,
|
|
224
239
|
raw_data: true
|
|
225
240
|
},
|
|
241
|
+
parseOptions: PARSE_OPTIONS,
|
|
226
242
|
tracker,
|
|
227
243
|
syncParams: new RequestParameters({ sub: '' }, {}),
|
|
228
244
|
token: { exp: exp } as any
|
|
@@ -248,18 +264,19 @@ function defineTests(factory: StorageFactory) {
|
|
|
248
264
|
content: BASIC_SYNC_RULES
|
|
249
265
|
});
|
|
250
266
|
|
|
251
|
-
const storage = await f.getInstance(syncRules
|
|
267
|
+
const storage = await f.getInstance(syncRules);
|
|
252
268
|
await storage.setSnapshotDone(ZERO_LSN);
|
|
253
269
|
await storage.autoActivate();
|
|
254
270
|
|
|
255
|
-
await storage.startBatch(
|
|
271
|
+
await storage.startBatch(BATCH_OPTIONS, async (batch) => {
|
|
256
272
|
await batch.save({
|
|
257
273
|
sourceTable: TEST_TABLE,
|
|
258
274
|
tag: 'insert',
|
|
259
275
|
after: {
|
|
260
276
|
id: 't1',
|
|
261
277
|
description: 'Test 1'
|
|
262
|
-
}
|
|
278
|
+
},
|
|
279
|
+
afterReplicaId: 't1'
|
|
263
280
|
});
|
|
264
281
|
|
|
265
282
|
await batch.save({
|
|
@@ -268,10 +285,11 @@ function defineTests(factory: StorageFactory) {
|
|
|
268
285
|
after: {
|
|
269
286
|
id: 't2',
|
|
270
287
|
description: 'Test 2'
|
|
271
|
-
}
|
|
288
|
+
},
|
|
289
|
+
afterReplicaId: 't2'
|
|
272
290
|
});
|
|
273
291
|
|
|
274
|
-
await batch.commit(
|
|
292
|
+
await batch.commit('0/1');
|
|
275
293
|
});
|
|
276
294
|
|
|
277
295
|
const stream = streamResponse({
|
|
@@ -281,6 +299,7 @@ function defineTests(factory: StorageFactory) {
|
|
|
281
299
|
include_checksum: true,
|
|
282
300
|
raw_data: true
|
|
283
301
|
},
|
|
302
|
+
parseOptions: PARSE_OPTIONS,
|
|
284
303
|
tracker,
|
|
285
304
|
syncParams: new RequestParameters({ sub: '' }, {}),
|
|
286
305
|
token: { exp: Date.now() / 1000 + 10 } as any
|
|
@@ -300,14 +319,15 @@ function defineTests(factory: StorageFactory) {
|
|
|
300
319
|
// Now we save additional data AND compact before continuing.
|
|
301
320
|
// This invalidates the checkpoint we've received above.
|
|
302
321
|
|
|
303
|
-
await storage.startBatch(
|
|
322
|
+
await storage.startBatch(BATCH_OPTIONS, async (batch) => {
|
|
304
323
|
await batch.save({
|
|
305
324
|
sourceTable: TEST_TABLE,
|
|
306
325
|
tag: 'update',
|
|
307
326
|
after: {
|
|
308
327
|
id: 't1',
|
|
309
328
|
description: 'Test 1b'
|
|
310
|
-
}
|
|
329
|
+
},
|
|
330
|
+
afterReplicaId: 't1'
|
|
311
331
|
});
|
|
312
332
|
|
|
313
333
|
await batch.save({
|
|
@@ -316,10 +336,11 @@ function defineTests(factory: StorageFactory) {
|
|
|
316
336
|
after: {
|
|
317
337
|
id: 't2',
|
|
318
338
|
description: 'Test 2b'
|
|
319
|
-
}
|
|
339
|
+
},
|
|
340
|
+
afterReplicaId: 't2'
|
|
320
341
|
});
|
|
321
342
|
|
|
322
|
-
await batch.commit(
|
|
343
|
+
await batch.commit('0/2');
|
|
323
344
|
});
|
|
324
345
|
|
|
325
346
|
await storage.compact();
|
package/test/src/util.ts
CHANGED
|
@@ -1,16 +1,21 @@
|
|
|
1
|
-
import * as pgwire from '@powersync/service-jpgwire';
|
|
2
|
-
import { normalizeConnection } from '@powersync/service-types';
|
|
3
|
-
import * as mongo from 'mongodb';
|
|
4
|
-
import { BucketStorageFactory, SyncBucketDataBatch } from '../../src/storage/BucketStorage.js';
|
|
5
|
-
import { MongoBucketStorage } from '../../src/storage/MongoBucketStorage.js';
|
|
6
|
-
import { PowerSyncMongo } from '../../src/storage/mongo/db.js';
|
|
7
|
-
import { escapeIdentifier } from '../../src/util/pgwire_utils.js';
|
|
8
|
-
import { env } from './env.js';
|
|
9
1
|
import { Metrics } from '@/metrics/Metrics.js';
|
|
10
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
BucketStorageFactory,
|
|
4
|
+
ParseSyncRulesOptions,
|
|
5
|
+
PersistedSyncRulesContent,
|
|
6
|
+
StartBatchOptions,
|
|
7
|
+
SyncBucketDataBatch
|
|
8
|
+
} from '@/storage/BucketStorage.js';
|
|
9
|
+
import { MongoBucketStorage } from '@/storage/MongoBucketStorage.js';
|
|
11
10
|
import { SourceTable } from '@/storage/SourceTable.js';
|
|
12
|
-
import
|
|
11
|
+
import { PowerSyncMongo } from '@/storage/mongo/db.js';
|
|
13
12
|
import { SyncBucketData } from '@/util/protocol-types.js';
|
|
13
|
+
import { getUuidReplicaIdentityBson, hashData } from '@/util/utils.js';
|
|
14
|
+
import * as bson from 'bson';
|
|
15
|
+
import * as mongo from 'mongodb';
|
|
16
|
+
import { env } from './env.js';
|
|
17
|
+
import { SqlSyncRules } from '@powersync/service-sync-rules';
|
|
18
|
+
import { ReplicaId } from '@/storage/storage-index.js';
|
|
14
19
|
|
|
15
20
|
// The metrics need to be initialised before they can be used
|
|
16
21
|
await Metrics.initialise({
|
|
@@ -20,8 +25,6 @@ await Metrics.initialise({
|
|
|
20
25
|
});
|
|
21
26
|
Metrics.getInstance().resetCounters();
|
|
22
27
|
|
|
23
|
-
export const TEST_URI = env.PG_TEST_URL;
|
|
24
|
-
|
|
25
28
|
export type StorageFactory = () => Promise<BucketStorageFactory>;
|
|
26
29
|
|
|
27
30
|
export const MONGO_STORAGE_FACTORY: StorageFactory = async () => {
|
|
@@ -30,45 +33,33 @@ export const MONGO_STORAGE_FACTORY: StorageFactory = async () => {
|
|
|
30
33
|
return new MongoBucketStorage(db, { slot_name_prefix: 'test_' });
|
|
31
34
|
};
|
|
32
35
|
|
|
33
|
-
export
|
|
34
|
-
await db.query(
|
|
35
|
-
"select pg_drop_replication_slot(slot_name) from pg_replication_slots where active = false and slot_name like 'test_%'"
|
|
36
|
-
);
|
|
36
|
+
export const ZERO_LSN = '0/0';
|
|
37
37
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
} catch (e) {
|
|
42
|
-
// Ignore
|
|
43
|
-
}
|
|
38
|
+
export const PARSE_OPTIONS: ParseSyncRulesOptions = {
|
|
39
|
+
defaultSchema: 'public'
|
|
40
|
+
};
|
|
44
41
|
|
|
45
|
-
|
|
42
|
+
export const BATCH_OPTIONS: StartBatchOptions = {
|
|
43
|
+
...PARSE_OPTIONS,
|
|
44
|
+
zeroLSN: ZERO_LSN
|
|
45
|
+
};
|
|
46
46
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
47
|
+
export function testRules(content: string): PersistedSyncRulesContent {
|
|
48
|
+
return {
|
|
49
|
+
id: 1,
|
|
50
|
+
sync_rules_content: content,
|
|
51
|
+
slot_name: 'test',
|
|
52
|
+
parsed(options) {
|
|
53
|
+
return {
|
|
54
|
+
id: 1,
|
|
55
|
+
sync_rules: SqlSyncRules.fromYaml(content, PARSE_OPTIONS),
|
|
56
|
+
slot_name: 'test'
|
|
57
|
+
};
|
|
58
|
+
},
|
|
59
|
+
lock() {
|
|
60
|
+
throw new Error('Not implemented');
|
|
54
61
|
}
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
export const TEST_CONNECTION_OPTIONS = normalizeConnection({
|
|
59
|
-
type: 'postgresql',
|
|
60
|
-
uri: TEST_URI,
|
|
61
|
-
sslmode: 'disable'
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
export async function connectPgWire(type?: 'replication' | 'standard') {
|
|
65
|
-
const db = await pgwire.connectPgWire(TEST_CONNECTION_OPTIONS, { type });
|
|
66
|
-
return db;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
export function connectPgPool() {
|
|
70
|
-
const db = pgwire.connectPgWirePool(TEST_CONNECTION_OPTIONS);
|
|
71
|
-
return db;
|
|
62
|
+
};
|
|
72
63
|
}
|
|
73
64
|
|
|
74
65
|
export async function connectMongo() {
|
|
@@ -79,8 +70,7 @@ export async function connectMongo() {
|
|
|
79
70
|
socketTimeoutMS: env.CI ? 15_000 : 5_000,
|
|
80
71
|
serverSelectionTimeoutMS: env.CI ? 15_000 : 2_500
|
|
81
72
|
});
|
|
82
|
-
|
|
83
|
-
return db;
|
|
73
|
+
return new PowerSyncMongo(client);
|
|
84
74
|
}
|
|
85
75
|
|
|
86
76
|
export function makeTestTable(name: string, columns?: string[] | undefined) {
|
|
@@ -90,9 +80,9 @@ export function makeTestTable(name: string, columns?: string[] | undefined) {
|
|
|
90
80
|
id,
|
|
91
81
|
SourceTable.DEFAULT_TAG,
|
|
92
82
|
relId,
|
|
93
|
-
|
|
83
|
+
'public',
|
|
94
84
|
name,
|
|
95
|
-
(columns ?? ['id']).map((column) => ({ name: column,
|
|
85
|
+
(columns ?? ['id']).map((column) => ({ name: column, type: 'VARCHAR', typeId: 25 })),
|
|
96
86
|
true
|
|
97
87
|
);
|
|
98
88
|
}
|
|
@@ -138,3 +128,10 @@ function getFirst(batch: SyncBucketData[] | SyncBucketDataBatch[] | SyncBucketDa
|
|
|
138
128
|
return first as SyncBucketData;
|
|
139
129
|
}
|
|
140
130
|
}
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* Replica id in the old Postgres format, for backwards-compatible tests.
|
|
134
|
+
*/
|
|
135
|
+
export function rid(id: string): bson.UUID {
|
|
136
|
+
return getUuidReplicaIdentityBson({ id: id }, [{ name: 'id', type: 'VARCHAR', typeId: 25 }]);
|
|
137
|
+
}
|