@powersync/service-core 0.0.0-dev-20240718134716 → 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 +89 -6
- 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 +4 -2
- package/dist/entry/cli-entry.js.map +1 -1
- package/dist/entry/commands/compact-action.d.ts +2 -0
- package/dist/entry/commands/compact-action.js +52 -0
- package/dist/entry/commands/compact-action.js.map +1 -0
- 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/entry/entry-index.d.ts +1 -0
- package/dist/entry/entry-index.js +1 -0
- package/dist/entry/entry-index.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 +6 -5
- package/dist/metrics/Metrics.js +53 -10
- 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 +737 -0
- package/dist/routes/configure-fastify.js +57 -0
- package/dist/routes/configure-fastify.js.map +1 -0
- package/dist/routes/configure-rsocket.d.ts +13 -0
- package/dist/routes/configure-rsocket.js +47 -0
- package/dist/routes/configure-rsocket.js.map +1 -0
- 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 +46 -39
- 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 +17 -13
- package/dist/routes/endpoints/sync-stream.js.map +1 -1
- package/dist/routes/route-register.d.ts +1 -1
- package/dist/routes/route-register.js +1 -1
- package/dist/routes/route-register.js.map +1 -1
- package/dist/routes/router-socket.d.ts +5 -4
- package/dist/routes/router-socket.js +2 -1
- package/dist/routes/router-socket.js.map +1 -1
- package/dist/routes/router.d.ts +7 -2
- package/dist/routes/router.js.map +1 -1
- package/dist/routes/routes-index.d.ts +3 -0
- package/dist/routes/routes-index.js +3 -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 +61 -20
- 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.d.ts +40 -0
- package/dist/storage/mongo/MongoCompactor.js +293 -0
- package/dist/storage/mongo/MongoCompactor.js.map +1 -0
- 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 +9 -7
- package/dist/storage/mongo/MongoSyncBucketStorage.js +43 -28
- 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 +17 -7
- package/dist/storage/mongo/models.js.map +1 -1
- package/dist/storage/mongo/util.d.ts +14 -0
- package/dist/storage/mongo/util.js +70 -0
- 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/RequestTracker.js +2 -3
- package/dist/sync/RequestTracker.js.map +1 -1
- 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 +2 -1
- package/dist/sync/sync.js +56 -17
- package/dist/sync/sync.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/collectors/config-collector.d.ts +12 -0
- package/dist/util/config/collectors/config-collector.js +43 -0
- package/dist/util/config/collectors/config-collector.js.map +1 -1
- package/dist/util/config/compound-config-collector.d.ts +10 -29
- package/dist/util/config/compound-config-collector.js +28 -84
- 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 +7 -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 +4 -2
- package/src/entry/commands/compact-action.ts +57 -0
- package/src/entry/commands/migrate-action.ts +5 -8
- package/src/entry/commands/teardown-action.ts +2 -2
- package/src/entry/entry-index.ts +1 -0
- package/src/index.ts +5 -2
- package/src/metrics/Metrics.ts +70 -15
- 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 +101 -0
- package/src/routes/configure-rsocket.ts +60 -0
- 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 +50 -42
- package/src/routes/endpoints/sync-rules.ts +41 -25
- package/src/routes/endpoints/sync-stream.ts +17 -13
- package/src/routes/route-register.ts +2 -2
- package/src/routes/router-socket.ts +6 -5
- package/src/routes/router.ts +7 -2
- package/src/routes/routes-index.ts +3 -0
- package/src/runner/teardown.ts +50 -88
- package/src/storage/BucketStorage.ts +74 -26
- 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 +372 -0
- package/src/storage/mongo/MongoPersistedSyncRulesContent.ts +3 -3
- package/src/storage/mongo/MongoStorageProvider.ts +31 -0
- package/src/storage/mongo/MongoSyncBucketStorage.ts +64 -34
- 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 +17 -7
- package/src/storage/mongo/util.ts +71 -1
- package/src/storage/storage-index.ts +5 -2
- package/src/sync/RequestTracker.ts +3 -3
- package/src/sync/sync-index.ts +1 -0
- package/src/sync/sync.ts +66 -17
- package/src/system/ServiceContext.ts +68 -0
- package/src/system/system-index.ts +1 -1
- package/src/util/config/collectors/config-collector.ts +48 -0
- package/src/util/config/compound-config-collector.ts +45 -110
- 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 +90 -5
- package/test/src/auth.test.ts +7 -7
- package/test/src/broadcast_iterable.test.ts +1 -1
- package/test/src/bucket_validation.test.ts +142 -0
- package/test/src/bucket_validation.ts +116 -0
- package/test/src/checksum_cache.test.ts +3 -3
- package/test/src/compacting.test.ts +216 -0
- package/test/src/data_storage.test.ts +275 -204
- 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 +209 -48
- package/test/src/util.ts +110 -55
- 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 -517
- 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 -628
- 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 -296
- package/test/src/validation.test.ts +0 -63
- package/test/src/wal_stream.test.ts +0 -314
- package/test/src/wal_stream_utils.ts +0 -147
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { SyncRulesConfig } from '../types.js';
|
|
2
|
+
export interface SyncRulesProvider {
|
|
3
|
+
get(): Promise<string | undefined>;
|
|
4
|
+
}
|
|
5
|
+
export declare class ConfigurationFileSyncRulesProvider implements SyncRulesProvider {
|
|
6
|
+
private config;
|
|
7
|
+
constructor(config: SyncRulesConfig);
|
|
8
|
+
get(): Promise<string | undefined>;
|
|
9
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import fs from 'fs/promises';
|
|
2
|
+
export class ConfigurationFileSyncRulesProvider {
|
|
3
|
+
constructor(config) {
|
|
4
|
+
this.config = config;
|
|
5
|
+
}
|
|
6
|
+
async get() {
|
|
7
|
+
if (this.config.content) {
|
|
8
|
+
return this.config.content;
|
|
9
|
+
}
|
|
10
|
+
else if (this.config.path) {
|
|
11
|
+
return await fs.readFile(this.config.path, 'utf-8');
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=sync-rules-provider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sync-rules-provider.js","sourceRoot":"","sources":["../../../../src/util/config/sync-rules/sync-rules-provider.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,aAAa,CAAC;AAM7B,MAAM,OAAO,kCAAkC;IAC7C,YAAoB,MAAuB;QAAvB,WAAM,GAAN,MAAM,CAAiB;IAAG,CAAC;IAE/C,KAAK,CAAC,GAAG;QACP,IAAI,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE;YACvB,OAAO,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC;SAC5B;aAAM,IAAI,IAAI,CAAC,MAAM,CAAC,IAAI,EAAE;YAC3B,OAAO,MAAM,EAAE,CAAC,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;SACrD;IACH,CAAC;CACF"}
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { configFile } from '@powersync/service-types';
|
|
2
|
+
import { PowerSyncConfig } from '@powersync/service-types/src/config/PowerSyncConfig.js';
|
|
3
|
+
import { CompoundKeyCollector } from '../../auth/CompoundKeyCollector.js';
|
|
2
4
|
import { KeySpec } from '../../auth/KeySpec.js';
|
|
3
5
|
import { KeyStore } from '../../auth/KeyStore.js';
|
|
4
6
|
export declare enum ServiceRunner {
|
|
@@ -15,14 +17,14 @@ export type MigrationContext = {
|
|
|
15
17
|
runner_config: RunnerConfig;
|
|
16
18
|
};
|
|
17
19
|
export type Runner = (config: RunnerConfig) => Promise<void>;
|
|
18
|
-
export type ResolvedConnection = configFile.PostgresConnection & NormalizedPostgresConnection;
|
|
19
20
|
export type SyncRulesConfig = {
|
|
20
21
|
present: boolean;
|
|
21
22
|
content?: string;
|
|
22
23
|
path?: string;
|
|
23
24
|
};
|
|
24
25
|
export type ResolvedPowerSyncConfig = {
|
|
25
|
-
|
|
26
|
+
base_config: PowerSyncConfig;
|
|
27
|
+
connections?: configFile.DataSourceConfig[];
|
|
26
28
|
storage: configFile.StorageConfig;
|
|
27
29
|
dev: {
|
|
28
30
|
demo_auth: boolean;
|
|
@@ -34,7 +36,7 @@ export type ResolvedPowerSyncConfig = {
|
|
|
34
36
|
*/
|
|
35
37
|
dev_key?: KeySpec;
|
|
36
38
|
};
|
|
37
|
-
client_keystore: KeyStore
|
|
39
|
+
client_keystore: KeyStore<CompoundKeyCollector>;
|
|
38
40
|
/**
|
|
39
41
|
* Keystore for development tokens.
|
|
40
42
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/util/config/types.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/util/config/types.ts"],"names":[],"mappings":"AAMA,MAAM,CAAN,IAAY,aAIX;AAJD,WAAY,aAAa;IACvB,oCAAmB,CAAA;IACnB,4BAAW,CAAA;IACX,8BAAa,CAAA;AACf,CAAC,EAJW,aAAa,KAAb,aAAa,QAIxB"}
|
package/dist/util/config.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ResolvedPowerSyncConfig, RunnerConfig } from './config/types.js';
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
3
|
+
* Loads the resolved config using the registered config collector
|
|
4
4
|
*/
|
|
5
|
-
export declare function
|
|
6
|
-
export declare function loadConfig(runnerConfig?: RunnerConfig): Promise<ResolvedPowerSyncConfig>;
|
|
5
|
+
export declare function loadConfig(runnerConfig: RunnerConfig): Promise<ResolvedPowerSyncConfig>;
|
|
7
6
|
export declare function loadSyncRules(config: ResolvedPowerSyncConfig): Promise<string | undefined>;
|
package/dist/util/config.js
CHANGED
|
@@ -1,26 +1,11 @@
|
|
|
1
1
|
import * as fs from 'fs/promises';
|
|
2
|
-
import {
|
|
3
|
-
import { CompoundConfigCollector } from './
|
|
2
|
+
import { container } from '@powersync/lib-services-framework';
|
|
3
|
+
import { CompoundConfigCollector } from './util-index.js';
|
|
4
4
|
/**
|
|
5
|
-
*
|
|
5
|
+
* Loads the resolved config using the registered config collector
|
|
6
6
|
*/
|
|
7
|
-
export function
|
|
8
|
-
|
|
9
|
-
throw new Error('Not supported');
|
|
10
|
-
}
|
|
11
|
-
const uri = new URL(baseUri(options));
|
|
12
|
-
uri.username = options.username;
|
|
13
|
-
uri.password = options.password;
|
|
14
|
-
if (options.sslmode != 'disable') {
|
|
15
|
-
// verify-full is tricky to actually use on a client, since they won't have the cert
|
|
16
|
-
// Just use "require" by default
|
|
17
|
-
// uri.searchParams.set('sslmode', options.sslmode);
|
|
18
|
-
uri.searchParams.set('sslmode', 'require');
|
|
19
|
-
}
|
|
20
|
-
return uri.toString();
|
|
21
|
-
}
|
|
22
|
-
export function loadConfig(runnerConfig = {}) {
|
|
23
|
-
const collector = new CompoundConfigCollector();
|
|
7
|
+
export async function loadConfig(runnerConfig) {
|
|
8
|
+
const collector = container.getImplementation(CompoundConfigCollector);
|
|
24
9
|
return collector.collectConfig(runnerConfig);
|
|
25
10
|
}
|
|
26
11
|
export async function loadSyncRules(config) {
|
package/dist/util/config.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.js","sourceRoot":"","sources":["../../src/util/config.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../../src/util/config.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,aAAa,CAAC;AAElC,OAAO,EAAE,SAAS,EAAE,MAAM,mCAAmC,CAAC;AAE9D,OAAO,EAAE,uBAAuB,EAAE,MAAM,iBAAiB,CAAC;AAE1D;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,UAAU,CAAC,YAA0B;IACzD,MAAM,SAAS,GAAG,SAAS,CAAC,iBAAiB,CAAC,uBAAuB,CAAC,CAAC;IACvE,OAAO,SAAS,CAAC,aAAa,CAAC,YAAY,CAAC,CAAC;AAC/C,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,aAAa,CAAC,MAA+B;IACjE,MAAM,UAAU,GAAG,MAAM,CAAC,UAAU,CAAC;IACrC,IAAI,UAAU,CAAC,OAAO,EAAE;QACtB,OAAO,UAAU,CAAC,OAAO,CAAC;KAC3B;SAAM,IAAI,UAAU,CAAC,IAAI,EAAE;QAC1B,OAAO,MAAM,EAAE,CAAC,QAAQ,CAAC,UAAU,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;KACpD;AACH,CAAC"}
|
|
@@ -80,6 +80,10 @@ export declare const StreamingSyncRequest: t.ObjectCodec<{
|
|
|
80
80
|
* Client parameters to be passed to the sync rules.
|
|
81
81
|
*/
|
|
82
82
|
parameters: t.OptionalCodec<t.Codec<Record<string, any>, Record<string, any>, string, t.CodecProps>>;
|
|
83
|
+
/**
|
|
84
|
+
* Unique client id.
|
|
85
|
+
*/
|
|
86
|
+
client_id: t.OptionalCodec<t.Codec<string, string, string, t.CodecProps>>;
|
|
83
87
|
}>;
|
|
84
88
|
export type StreamingSyncRequest = t.Decoded<typeof StreamingSyncRequest>;
|
|
85
89
|
export interface StreamingSyncCheckpoint {
|
|
@@ -30,7 +30,11 @@ export const StreamingSyncRequest = t.object({
|
|
|
30
30
|
/**
|
|
31
31
|
* Client parameters to be passed to the sync rules.
|
|
32
32
|
*/
|
|
33
|
-
parameters: t.record(t.any).optional()
|
|
33
|
+
parameters: t.record(t.any).optional(),
|
|
34
|
+
/**
|
|
35
|
+
* Unique client id.
|
|
36
|
+
*/
|
|
37
|
+
client_id: t.string.optional()
|
|
34
38
|
});
|
|
35
39
|
export function isContinueCheckpointRequest(request) {
|
|
36
40
|
return (Array.isArray(request.buckets) &&
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"protocol-types.js","sourceRoot":"","sources":["../../src/util/protocol-types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,UAAU,CAAC;AAwD9B,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,CAAC,MAAM,CAAC;IACpC,IAAI,EAAE,CAAC,CAAC,MAAM;IAEd;;OAEG;IACH,KAAK,EAAE,CAAC,CAAC,MAAM;CAChB,CAAC,CAAC;AAIH,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAAC,CAAC,MAAM,CAAC;IAC3C;;OAEG;IACH,OAAO,EAAE,CAAC,CAAC,KAAK,CAAC,aAAa,CAAC,CAAC,QAAQ,EAAE;IAE1C;;OAEG;IACH,IAAI,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,QAAQ,EAAE;IAElC;;OAEG;IACH,gBAAgB,EAAE,CAAC,CAAC,OAAO,CAAC,QAAQ,EAAE;IAEtC;;OAEG;IACH,QAAQ,EAAE,CAAC,CAAC,OAAO,CAAC,QAAQ,EAAE;IAE9B;;OAEG;IACH,WAAW,EAAE,CAAC,CAAC,OAAO,CAAC,QAAQ,EAAE;IAEjC;;OAEG;IACH,UAAU,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,QAAQ,EAAE;
|
|
1
|
+
{"version":3,"file":"protocol-types.js","sourceRoot":"","sources":["../../src/util/protocol-types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,UAAU,CAAC;AAwD9B,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,CAAC,MAAM,CAAC;IACpC,IAAI,EAAE,CAAC,CAAC,MAAM;IAEd;;OAEG;IACH,KAAK,EAAE,CAAC,CAAC,MAAM;CAChB,CAAC,CAAC;AAIH,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAAC,CAAC,MAAM,CAAC;IAC3C;;OAEG;IACH,OAAO,EAAE,CAAC,CAAC,KAAK,CAAC,aAAa,CAAC,CAAC,QAAQ,EAAE;IAE1C;;OAEG;IACH,IAAI,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,QAAQ,EAAE;IAElC;;OAEG;IACH,gBAAgB,EAAE,CAAC,CAAC,OAAO,CAAC,QAAQ,EAAE;IAEtC;;OAEG;IACH,QAAQ,EAAE,CAAC,CAAC,OAAO,CAAC,QAAQ,EAAE;IAE9B;;OAEG;IACH,WAAW,EAAE,CAAC,CAAC,OAAO,CAAC,QAAQ,EAAE;IAEjC;;OAEG;IACH,UAAU,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,QAAQ,EAAE;IAEtC;;OAEG;IACH,SAAS,EAAE,CAAC,CAAC,MAAM,CAAC,QAAQ,EAAE;CAC/B,CAAC,CAAC;AAgGH,MAAM,UAAU,2BAA2B,CAAC,OAAoB;IAC9D,OAAO,CACL,KAAK,CAAC,OAAO,CAAE,OAAqC,CAAC,OAAO,CAAC;QAC7D,OAAQ,OAAqC,CAAC,gBAAgB,IAAI,QAAQ,CAC3E,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,0BAA0B,CAAC,OAAoB;IAC7D,OAAO,OAAQ,OAAoC,CAAC,kBAAkB,IAAI,QAAQ,CAAC;AACrF,CAAC"}
|
|
@@ -1,22 +1,19 @@
|
|
|
1
1
|
export * from './alerting.js';
|
|
2
2
|
export * from './env.js';
|
|
3
3
|
export * from './memory-tracking.js';
|
|
4
|
-
export * from './migration_lib.js';
|
|
5
4
|
export * from './Mutex.js';
|
|
6
|
-
export * from './PgManager.js';
|
|
7
|
-
export * from './pgwire_utils.js';
|
|
8
|
-
export * from './populate_test_data.js';
|
|
9
5
|
export * from './protocol-types.js';
|
|
10
6
|
export * from './secs.js';
|
|
11
7
|
export * from './utils.js';
|
|
12
8
|
export * from './config.js';
|
|
13
|
-
export * from './config/types.js';
|
|
14
9
|
export * from './config/compound-config-collector.js';
|
|
10
|
+
export * from './config/types.js';
|
|
15
11
|
export * from './config/collectors/config-collector.js';
|
|
16
12
|
export * from './config/collectors/impl/base64-config-collector.js';
|
|
17
13
|
export * from './config/collectors/impl/fallback-config-collector.js';
|
|
18
14
|
export * from './config/collectors/impl/filesystem-config-collector.js';
|
|
19
|
-
export * from './config/sync-rules/sync-collector.js';
|
|
20
15
|
export * from './config/sync-rules/impl/base64-sync-rules-collector.js';
|
|
21
16
|
export * from './config/sync-rules/impl/filesystem-sync-rules-collector.js';
|
|
22
17
|
export * from './config/sync-rules/impl/inline-sync-rules-collector.js';
|
|
18
|
+
export * from './config/sync-rules/sync-collector.js';
|
|
19
|
+
export * from './config/sync-rules/sync-rules-provider.js';
|
package/dist/util/util-index.js
CHANGED
|
@@ -1,23 +1,20 @@
|
|
|
1
1
|
export * from './alerting.js';
|
|
2
2
|
export * from './env.js';
|
|
3
3
|
export * from './memory-tracking.js';
|
|
4
|
-
export * from './migration_lib.js';
|
|
5
4
|
export * from './Mutex.js';
|
|
6
|
-
export * from './PgManager.js';
|
|
7
|
-
export * from './pgwire_utils.js';
|
|
8
|
-
export * from './populate_test_data.js';
|
|
9
5
|
export * from './protocol-types.js';
|
|
10
6
|
export * from './secs.js';
|
|
11
7
|
export * from './utils.js';
|
|
12
8
|
export * from './config.js';
|
|
13
|
-
export * from './config/types.js';
|
|
14
9
|
export * from './config/compound-config-collector.js';
|
|
10
|
+
export * from './config/types.js';
|
|
15
11
|
export * from './config/collectors/config-collector.js';
|
|
16
12
|
export * from './config/collectors/impl/base64-config-collector.js';
|
|
17
13
|
export * from './config/collectors/impl/fallback-config-collector.js';
|
|
18
14
|
export * from './config/collectors/impl/filesystem-config-collector.js';
|
|
19
|
-
export * from './config/sync-rules/sync-collector.js';
|
|
20
15
|
export * from './config/sync-rules/impl/base64-sync-rules-collector.js';
|
|
21
16
|
export * from './config/sync-rules/impl/filesystem-sync-rules-collector.js';
|
|
22
17
|
export * from './config/sync-rules/impl/inline-sync-rules-collector.js';
|
|
18
|
+
export * from './config/sync-rules/sync-collector.js';
|
|
19
|
+
export * from './config/sync-rules/sync-rules-provider.js';
|
|
23
20
|
//# sourceMappingURL=util-index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"util-index.js","sourceRoot":"","sources":["../../src/util/util-index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,cAAc,UAAU,CAAC;AACzB,cAAc,sBAAsB,CAAC;AACrC,cAAc,
|
|
1
|
+
{"version":3,"file":"util-index.js","sourceRoot":"","sources":["../../src/util/util-index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,cAAc,UAAU,CAAC;AACzB,cAAc,sBAAsB,CAAC;AACrC,cAAc,YAAY,CAAC;AAC3B,cAAc,qBAAqB,CAAC;AACpC,cAAc,WAAW,CAAC;AAC1B,cAAc,YAAY,CAAC;AAE3B,cAAc,aAAa,CAAC;AAC5B,cAAc,uCAAuC,CAAC;AACtD,cAAc,mBAAmB,CAAC;AAElC,cAAc,yCAAyC,CAAC;AACxD,cAAc,qDAAqD,CAAC;AACpE,cAAc,uDAAuD,CAAC;AACtE,cAAc,yDAAyD,CAAC;AAExE,cAAc,yDAAyD,CAAC;AACxE,cAAc,6DAA6D,CAAC;AAC5E,cAAc,yDAAyD,CAAC;AACxE,cAAc,uCAAuC,CAAC;AACtD,cAAc,4CAA4C,CAAC"}
|
package/dist/util/utils.d.ts
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
|
-
import * as
|
|
2
|
-
import * as
|
|
1
|
+
import * as sync_rules from '@powersync/service-sync-rules';
|
|
2
|
+
import * as bson from 'bson';
|
|
3
3
|
import { BucketChecksum, OpId } from './protocol-types.js';
|
|
4
|
+
import * as storage from '../storage/storage-index.js';
|
|
4
5
|
export type ChecksumMap = Map<string, BucketChecksum>;
|
|
6
|
+
export declare const ID_NAMESPACE = "a396dd91-09fc-4017-a28d-3df722f651e9";
|
|
7
|
+
export declare function escapeIdentifier(identifier: string): string;
|
|
5
8
|
export declare function hashData(type: string, id: string, data: string): number;
|
|
6
9
|
export declare function hashDelete(sourceKey: string): number;
|
|
7
10
|
export declare function timestampToOpId(ts: bigint): OpId;
|
|
@@ -11,7 +14,8 @@ export declare function checksumsDiff(previous: ChecksumMap, current: ChecksumMa
|
|
|
11
14
|
};
|
|
12
15
|
export declare function addChecksums(a: number, b: number): number;
|
|
13
16
|
export declare function addBucketChecksums(a: BucketChecksum, b: BucketChecksum | null): BucketChecksum;
|
|
14
|
-
export declare function
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
export declare function
|
|
17
|
+
export declare function getUuidReplicaIdentityBson(tuple: sync_rules.ToastableSqliteRow, columns: storage.ColumnDescriptor[]): bson.UUID;
|
|
18
|
+
export declare function uuidForRowBson(row: sync_rules.SqliteRow): bson.UUID;
|
|
19
|
+
export declare function hasToastedValues(row: sync_rules.ToastableSqliteRow): boolean;
|
|
20
|
+
export declare function isCompleteRow(row: sync_rules.ToastableSqliteRow): row is sync_rules.SqliteRow;
|
|
21
|
+
export declare function checkpointUserId(user_id: string | undefined, client_id: string | undefined): string;
|
package/dist/util/utils.js
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
|
+
import * as bson from 'bson';
|
|
1
2
|
import crypto from 'crypto';
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
import * as uuid from 'uuid';
|
|
4
|
+
export const ID_NAMESPACE = 'a396dd91-09fc-4017-a28d-3df722f651e9';
|
|
5
|
+
export function escapeIdentifier(identifier) {
|
|
6
|
+
return `"${identifier.replace(/"/g, '""').replace(/\./g, '"."')}"`;
|
|
7
|
+
}
|
|
5
8
|
export function hashData(type, id, data) {
|
|
6
9
|
const hash = crypto.createHash('sha256');
|
|
7
10
|
hash.update(`put.${type}.${id}.${data}`);
|
|
@@ -63,30 +66,47 @@ export function addBucketChecksums(a, b) {
|
|
|
63
66
|
};
|
|
64
67
|
}
|
|
65
68
|
}
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
69
|
+
function getRawReplicaIdentity(tuple, columns) {
|
|
70
|
+
let result = {};
|
|
71
|
+
for (let column of columns) {
|
|
72
|
+
const name = column.name;
|
|
73
|
+
result[name] = tuple[name];
|
|
74
|
+
}
|
|
75
|
+
return result;
|
|
76
|
+
}
|
|
77
|
+
export function getUuidReplicaIdentityBson(tuple, columns) {
|
|
78
|
+
if (columns.length == 0) {
|
|
79
|
+
// REPLICA IDENTITY NOTHING - generate random id
|
|
80
|
+
return new bson.UUID(uuid.v4());
|
|
81
|
+
}
|
|
82
|
+
const rawIdentity = getRawReplicaIdentity(tuple, columns);
|
|
83
|
+
return uuidForRowBson(rawIdentity);
|
|
84
|
+
}
|
|
85
|
+
export function uuidForRowBson(row) {
|
|
86
|
+
// Important: This must not change, since it will affect how ids are generated.
|
|
87
|
+
// Use BSON so that it's a well-defined format without encoding ambiguities.
|
|
88
|
+
const repr = bson.serialize(row);
|
|
89
|
+
const buffer = Buffer.alloc(16);
|
|
90
|
+
return new bson.UUID(uuid.v5(repr, ID_NAMESPACE, buffer));
|
|
91
|
+
}
|
|
92
|
+
export function hasToastedValues(row) {
|
|
93
|
+
for (let key in row) {
|
|
94
|
+
if (typeof row[key] == 'undefined') {
|
|
95
|
+
return true;
|
|
81
96
|
}
|
|
82
|
-
await new Promise((resolve) => setTimeout(resolve, 30));
|
|
83
97
|
}
|
|
84
|
-
|
|
98
|
+
return false;
|
|
99
|
+
}
|
|
100
|
+
export function isCompleteRow(row) {
|
|
101
|
+
return !hasToastedValues(row);
|
|
85
102
|
}
|
|
86
|
-
export
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
103
|
+
export function checkpointUserId(user_id, client_id) {
|
|
104
|
+
if (user_id == null) {
|
|
105
|
+
throw new Error('user_id is required');
|
|
106
|
+
}
|
|
107
|
+
if (client_id == null) {
|
|
108
|
+
return user_id;
|
|
109
|
+
}
|
|
110
|
+
return `${user_id}/${client_id}`;
|
|
91
111
|
}
|
|
92
112
|
//# sourceMappingURL=utils.js.map
|
package/dist/util/utils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/util/utils.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/util/utils.ts"],"names":[],"mappings":"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"}
|
package/package.json
CHANGED
|
@@ -5,14 +5,16 @@
|
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
7
7
|
},
|
|
8
|
-
"version": "0.0.0-dev-
|
|
8
|
+
"version": "0.0.0-dev-20240918082156",
|
|
9
9
|
"main": "dist/index.js",
|
|
10
10
|
"license": "FSL-1.1-Apache-2.0",
|
|
11
11
|
"type": "module",
|
|
12
12
|
"dependencies": {
|
|
13
13
|
"@js-sdsl/ordered-set": "^4.4.2",
|
|
14
14
|
"@opentelemetry/api": "~1.8.0",
|
|
15
|
+
"@opentelemetry/exporter-metrics-otlp-http": "^0.51.1",
|
|
15
16
|
"@opentelemetry/exporter-prometheus": "^0.51.1",
|
|
17
|
+
"@opentelemetry/resources": "^1.24.1",
|
|
16
18
|
"@opentelemetry/sdk-metrics": "1.24.1",
|
|
17
19
|
"async": "^3.2.4",
|
|
18
20
|
"async-mutex": "^0.5.0",
|
|
@@ -26,17 +28,15 @@
|
|
|
26
28
|
"lru-cache": "^10.2.2",
|
|
27
29
|
"mongodb": "^6.7.0",
|
|
28
30
|
"node-fetch": "^3.3.2",
|
|
29
|
-
"pgwire": "github:kagis/pgwire#f1cb95f9a0f42a612bb5a6b67bb2eb793fc5fc87",
|
|
30
31
|
"ts-codec": "^1.2.2",
|
|
31
32
|
"uuid": "^9.0.1",
|
|
32
33
|
"winston": "^3.13.0",
|
|
33
34
|
"yaml": "^2.3.2",
|
|
34
|
-
"@powersync/lib-services-framework": "0.0.0-dev-
|
|
35
|
-
"@powersync/service-jpgwire": "0.17.13",
|
|
35
|
+
"@powersync/lib-services-framework": "0.0.0-dev-20240918082156",
|
|
36
36
|
"@powersync/service-jsonbig": "0.17.10",
|
|
37
|
-
"@powersync/service-rsocket-router": "0.0.0-dev-
|
|
38
|
-
"@powersync/service-sync-rules": "0.
|
|
39
|
-
"@powersync/service-types": "0.
|
|
37
|
+
"@powersync/service-rsocket-router": "0.0.0-dev-20240918082156",
|
|
38
|
+
"@powersync/service-sync-rules": "0.0.0-dev-20240918082156",
|
|
39
|
+
"@powersync/service-types": "0.0.0-dev-20240918082156"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
42
|
"@types/async": "^3.2.24",
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { SqlSyncRules, TablePattern } from '@powersync/service-sync-rules';
|
|
2
|
+
import * as types from '@powersync/service-types';
|
|
3
|
+
import { ParseSyncRulesOptions } from '../storage/BucketStorage.js';
|
|
4
|
+
|
|
5
|
+
export interface PatternResult {
|
|
6
|
+
schema: string;
|
|
7
|
+
pattern: string;
|
|
8
|
+
wildcard: boolean;
|
|
9
|
+
tables?: types.TableInfo[];
|
|
10
|
+
table?: types.TableInfo;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Describes all the methods currently required to service the sync API endpoints.
|
|
15
|
+
*/
|
|
16
|
+
export interface RouteAPI {
|
|
17
|
+
/**
|
|
18
|
+
* @returns basic identification of the connection
|
|
19
|
+
*/
|
|
20
|
+
getSourceConfig(): Promise<types.configFile.DataSourceConfig>;
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Checks the current connection status of the data source.
|
|
24
|
+
* This is usually some test query to verify the source can be reached.
|
|
25
|
+
*/
|
|
26
|
+
getConnectionStatus(): Promise<types.ConnectionStatusV2>;
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Generates replication table information from a given pattern of tables.
|
|
30
|
+
*
|
|
31
|
+
* @param tablePatterns A set of table patterns which typically come from
|
|
32
|
+
* the tables listed in sync rules definitions.
|
|
33
|
+
*
|
|
34
|
+
* @param sqlSyncRules
|
|
35
|
+
* @returns A result of all the tables and columns which should be replicated
|
|
36
|
+
* based off the input patterns. Certain tests are executed on the
|
|
37
|
+
* tables to ensure syncing should function according to the input
|
|
38
|
+
* pattern. Debug errors and warnings are reported per table.
|
|
39
|
+
*/
|
|
40
|
+
getDebugTablesInfo(tablePatterns: TablePattern[], sqlSyncRules: SqlSyncRules): Promise<PatternResult[]>;
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* @returns The replication lag: that is the amount of data which has not been
|
|
44
|
+
* replicated yet, in bytes.
|
|
45
|
+
* @param {string} syncRulesId An identifier representing which set of sync rules the lag is required for.
|
|
46
|
+
*/
|
|
47
|
+
getReplicationLag(syncRulesId: string): Promise<number>;
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Get the current LSN or equivalent replication HEAD position identifier
|
|
51
|
+
*/
|
|
52
|
+
getReplicationHead(): Promise<string>;
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* @returns The schema for tables inside the connected database. This is typically
|
|
56
|
+
* used to validate sync rules.
|
|
57
|
+
* Side Note: https://github.com/powersync-ja/powersync-service/blob/33bbb8c0ab1c48555956593f427fc674a8f15768/packages/types/src/definitions.ts#L100
|
|
58
|
+
* contains `pg_type` which we might need to deprecate and add another generic
|
|
59
|
+
* type field - or just use this field as the connection specific type.
|
|
60
|
+
*/
|
|
61
|
+
getConnectionSchema(): Promise<types.DatabaseSchema[]>;
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Executes a query and return the result from the data source. This is currently used in the
|
|
65
|
+
* admin API which is exposed in Collide.
|
|
66
|
+
*/
|
|
67
|
+
executeQuery(query: string, params: any[]): Promise<types.internal_routes.ExecuteSqlResponse>;
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Close any resources that need graceful termination.
|
|
71
|
+
*/
|
|
72
|
+
shutdown(): Promise<void>;
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Get the default schema (or database) when only a table name is specified in sync rules.
|
|
76
|
+
*/
|
|
77
|
+
getParseSyncRulesOptions(): ParseSyncRulesOptions;
|
|
78
|
+
}
|
package/src/api/api-index.ts
CHANGED
package/src/api/diagnostics.ts
CHANGED
|
@@ -1,51 +1,9 @@
|
|
|
1
|
+
import { logger } from '@powersync/lib-services-framework';
|
|
1
2
|
import { DEFAULT_TAG, SourceTableInterface, SqlSyncRules } from '@powersync/service-sync-rules';
|
|
2
|
-
import {
|
|
3
|
-
import { ConnectionStatus, SyncRulesStatus, TableInfo, baseUri } from '@powersync/service-types';
|
|
3
|
+
import { SyncRulesStatus, TableInfo } from '@powersync/service-types';
|
|
4
4
|
|
|
5
|
-
import * as replication from '../replication/replication-index.js';
|
|
6
5
|
import * as storage from '../storage/storage-index.js';
|
|
7
|
-
import
|
|
8
|
-
|
|
9
|
-
import { CorePowerSyncSystem } from '../system/CorePowerSyncSystem.js';
|
|
10
|
-
import { logger } from '@powersync/lib-services-framework';
|
|
11
|
-
|
|
12
|
-
export async function getConnectionStatus(system: CorePowerSyncSystem): Promise<ConnectionStatus | null> {
|
|
13
|
-
if (system.pgwire_pool == null) {
|
|
14
|
-
return null;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
const pool = system.requirePgPool();
|
|
18
|
-
|
|
19
|
-
const base = {
|
|
20
|
-
id: system.config.connection!.id,
|
|
21
|
-
postgres_uri: baseUri(system.config.connection!)
|
|
22
|
-
};
|
|
23
|
-
try {
|
|
24
|
-
await util.retriedQuery(pool, `SELECT 'PowerSync connection test'`);
|
|
25
|
-
} catch (e) {
|
|
26
|
-
return {
|
|
27
|
-
...base,
|
|
28
|
-
connected: false,
|
|
29
|
-
errors: [{ level: 'fatal', message: e.message }]
|
|
30
|
-
};
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
try {
|
|
34
|
-
await replication.checkSourceConfiguration(pool);
|
|
35
|
-
} catch (e) {
|
|
36
|
-
return {
|
|
37
|
-
...base,
|
|
38
|
-
connected: true,
|
|
39
|
-
errors: [{ level: 'fatal', message: e.message }]
|
|
40
|
-
};
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
return {
|
|
44
|
-
...base,
|
|
45
|
-
connected: true,
|
|
46
|
-
errors: []
|
|
47
|
-
};
|
|
48
|
-
}
|
|
6
|
+
import { RouteAPI } from './RouteAPI.js';
|
|
49
7
|
|
|
50
8
|
export interface DiagnosticsOptions {
|
|
51
9
|
/**
|
|
@@ -66,9 +24,12 @@ export interface DiagnosticsOptions {
|
|
|
66
24
|
check_connection: boolean;
|
|
67
25
|
}
|
|
68
26
|
|
|
27
|
+
export const DEFAULT_DATASOURCE_ID = 'default';
|
|
28
|
+
|
|
69
29
|
export async function getSyncRulesStatus(
|
|
30
|
+
bucketStorage: storage.BucketStorageFactory,
|
|
31
|
+
apiHandler: RouteAPI,
|
|
70
32
|
sync_rules: storage.PersistedSyncRulesContent | null,
|
|
71
|
-
system: CorePowerSyncSystem,
|
|
72
33
|
options: DiagnosticsOptions
|
|
73
34
|
): Promise<SyncRulesStatus | undefined> {
|
|
74
35
|
if (sync_rules == null) {
|
|
@@ -82,7 +43,7 @@ export async function getSyncRulesStatus(
|
|
|
82
43
|
let rules: SqlSyncRules;
|
|
83
44
|
let persisted: storage.PersistedSyncRules;
|
|
84
45
|
try {
|
|
85
|
-
persisted = sync_rules.parsed();
|
|
46
|
+
persisted = sync_rules.parsed(apiHandler.getParseSyncRulesOptions());
|
|
86
47
|
rules = persisted.sync_rules;
|
|
87
48
|
} catch (e) {
|
|
88
49
|
return {
|
|
@@ -92,21 +53,15 @@ export async function getSyncRulesStatus(
|
|
|
92
53
|
};
|
|
93
54
|
}
|
|
94
55
|
|
|
95
|
-
const systemStorage = live_status ?
|
|
56
|
+
const systemStorage = live_status ? bucketStorage.getInstance(sync_rules) : undefined;
|
|
96
57
|
const status = await systemStorage?.getStatus();
|
|
97
58
|
let replication_lag_bytes: number | undefined = undefined;
|
|
98
59
|
|
|
99
60
|
let tables_flat: TableInfo[] = [];
|
|
100
61
|
|
|
101
62
|
if (check_connection) {
|
|
102
|
-
const pool = system.requirePgPool();
|
|
103
|
-
|
|
104
63
|
const source_table_patterns = rules.getSourceTables();
|
|
105
|
-
const
|
|
106
|
-
db: pool,
|
|
107
|
-
sync_rules: rules
|
|
108
|
-
});
|
|
109
|
-
const resolved_tables = await wc.getDebugTablesInfo(source_table_patterns);
|
|
64
|
+
const resolved_tables = await apiHandler.getDebugTablesInfo(source_table_patterns, rules);
|
|
110
65
|
tables_flat = resolved_tables.flatMap((info) => {
|
|
111
66
|
if (info.table) {
|
|
112
67
|
return [info.table];
|
|
@@ -119,19 +74,7 @@ export async function getSyncRulesStatus(
|
|
|
119
74
|
|
|
120
75
|
if (systemStorage) {
|
|
121
76
|
try {
|
|
122
|
-
|
|
123
|
-
statement: `SELECT
|
|
124
|
-
slot_name,
|
|
125
|
-
confirmed_flush_lsn,
|
|
126
|
-
pg_current_wal_lsn(),
|
|
127
|
-
(pg_current_wal_lsn() - confirmed_flush_lsn) AS lsn_distance
|
|
128
|
-
FROM pg_replication_slots WHERE slot_name = $1 LIMIT 1;`,
|
|
129
|
-
params: [{ type: 'varchar', value: systemStorage!.slot_name }]
|
|
130
|
-
});
|
|
131
|
-
const [row] = pgwireRows(results);
|
|
132
|
-
if (row) {
|
|
133
|
-
replication_lag_bytes = Number(row.lsn_distance);
|
|
134
|
-
}
|
|
77
|
+
replication_lag_bytes = await apiHandler.getReplicationLag(systemStorage.slot_name);
|
|
135
78
|
} catch (e) {
|
|
136
79
|
// Ignore
|
|
137
80
|
logger.warn(`Unable to get replication lag`, e);
|
|
@@ -139,7 +82,6 @@ export async function getSyncRulesStatus(
|
|
|
139
82
|
}
|
|
140
83
|
} else {
|
|
141
84
|
const source_table_patterns = rules.getSourceTables();
|
|
142
|
-
const tag = system.config.connection!.tag ?? DEFAULT_TAG;
|
|
143
85
|
|
|
144
86
|
tables_flat = source_table_patterns.map((pattern): TableInfo => {
|
|
145
87
|
if (pattern.isWildcard) {
|
|
@@ -186,12 +128,15 @@ export async function getSyncRulesStatus(
|
|
|
186
128
|
})
|
|
187
129
|
);
|
|
188
130
|
|
|
131
|
+
const sourceConfig = await apiHandler.getSourceConfig();
|
|
132
|
+
const tag = sourceConfig.tag ?? DEFAULT_TAG;
|
|
133
|
+
|
|
189
134
|
return {
|
|
190
135
|
content: include_content ? sync_rules.sync_rules_content : undefined,
|
|
191
136
|
connections: [
|
|
192
137
|
{
|
|
193
|
-
id:
|
|
194
|
-
tag:
|
|
138
|
+
id: sourceConfig.id ?? DEFAULT_DATASOURCE_ID,
|
|
139
|
+
tag: sourceConfig.tag ?? DEFAULT_TAG,
|
|
195
140
|
slot_name: sync_rules.slot_name,
|
|
196
141
|
initial_replication_done: status?.snapshot_done ?? false,
|
|
197
142
|
// TODO: Rename?
|