@powersync/service-core 0.8.8 → 0.10.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 +43 -0
- package/dist/api/RouteAPI.d.ts +67 -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 +170 -158
- package/dist/api/diagnostics.js.map +1 -1
- package/dist/api/schema.d.ts +3 -5
- package/dist/api/schema.js +14 -80
- package/dist/api/schema.js.map +1 -1
- package/dist/auth/CachedKeyCollector.js.map +1 -1
- package/dist/auth/KeySpec.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/LeakyBucket.js.map +1 -1
- package/dist/auth/RemoteJWKSCollector.d.ts +0 -2
- package/dist/auth/RemoteJWKSCollector.js.map +1 -1
- package/dist/auth/StaticSupabaseKeyCollector.d.ts +19 -0
- package/dist/auth/StaticSupabaseKeyCollector.js +28 -0
- package/dist/auth/StaticSupabaseKeyCollector.js.map +1 -0
- package/dist/auth/auth-index.d.ts +1 -1
- package/dist/auth/auth-index.js +1 -1
- package/dist/auth/auth-index.js.map +1 -1
- package/dist/db/mongo.js +5 -3
- package/dist/db/mongo.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 +90 -14
- 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/locks/MongoLocks.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/db/migrations/1727099539247-custom-write-checkpoint-index.d.ts +3 -0
- package/dist/migrations/db/migrations/1727099539247-custom-write-checkpoint-index.js +31 -0
- package/dist/migrations/db/migrations/1727099539247-custom-write-checkpoint-index.js.map +1 -0
- package/dist/migrations/executor.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/migrations/store/migration-store.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 +37 -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 +250 -0
- package/dist/replication/AbstractReplicator.js.map +1 -0
- package/dist/replication/ErrorRateLimiter.d.ts +0 -10
- 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 +51 -0
- package/dist/replication/ReplicationModule.js +68 -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 +37 -23
- package/dist/routes/configure-fastify.js +18 -18
- package/dist/routes/configure-fastify.js.map +1 -1
- package/dist/routes/configure-rsocket.d.ts +3 -4
- package/dist/routes/configure-rsocket.js +7 -4
- package/dist/routes/configure-rsocket.js.map +1 -1
- package/dist/routes/endpoints/admin.d.ts +30 -0
- package/dist/routes/endpoints/admin.js +46 -67
- package/dist/routes/endpoints/admin.js.map +1 -1
- package/dist/routes/endpoints/checkpointing.js +103 -15
- package/dist/routes/endpoints/checkpointing.js.map +1 -1
- package/dist/routes/endpoints/socket-route.js +8 -6
- 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 +0 -1
- package/dist/routes/endpoints/sync-stream.js +8 -8
- package/dist/routes/endpoints/sync-stream.js.map +1 -1
- package/dist/routes/hooks.js.map +1 -1
- package/dist/routes/route-register.js.map +1 -1
- package/dist/routes/router.d.ts +9 -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 +109 -76
- package/dist/runner/teardown.js.map +1 -1
- package/dist/storage/BucketStorage.d.ts +86 -36
- package/dist/storage/BucketStorage.js +6 -10
- package/dist/storage/BucketStorage.js.map +1 -1
- package/dist/storage/ChecksumCache.js.map +1 -1
- package/dist/storage/MongoBucketStorage.d.ts +7 -11
- package/dist/storage/MongoBucketStorage.js +48 -41
- package/dist/storage/MongoBucketStorage.js.map +1 -1
- package/dist/storage/ReplicationEventPayload.d.ts +14 -0
- package/dist/storage/ReplicationEventPayload.js +2 -0
- package/dist/storage/ReplicationEventPayload.js.map +1 -0
- 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 +12 -5
- package/dist/storage/SourceTable.js +12 -5
- package/dist/storage/SourceTable.js.map +1 -1
- package/dist/storage/StorageEngine.d.ts +28 -0
- package/dist/storage/StorageEngine.js +45 -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/WriteCheckpointAPI.d.ts +74 -0
- package/dist/storage/WriteCheckpointAPI.js +16 -0
- package/dist/storage/WriteCheckpointAPI.js.map +1 -0
- package/dist/storage/mongo/MongoBucketBatch.d.ts +24 -5
- package/dist/storage/mongo/MongoBucketBatch.js +119 -62
- package/dist/storage/mongo/MongoBucketBatch.js.map +1 -1
- package/dist/storage/mongo/MongoCompactor.js +20 -3
- package/dist/storage/mongo/MongoCompactor.js.map +1 -1
- package/dist/storage/mongo/MongoIdSequence.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 +18 -10
- package/dist/storage/mongo/MongoSyncBucketStorage.js +140 -25
- 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/MongoWriteCheckpointAPI.d.ts +20 -0
- package/dist/storage/mongo/MongoWriteCheckpointAPI.js +103 -0
- package/dist/storage/mongo/MongoWriteCheckpointAPI.js.map +1 -0
- package/dist/storage/mongo/OperationBatch.d.ts +13 -4
- package/dist/storage/mongo/OperationBatch.js +25 -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/config.d.ts +19 -0
- package/dist/storage/mongo/config.js +26 -0
- package/dist/storage/mongo/config.js.map +1 -0
- package/dist/storage/mongo/db.d.ts +3 -2
- package/dist/storage/mongo/db.js +1 -0
- package/dist/storage/mongo/db.js.map +1 -1
- package/dist/storage/mongo/models.d.ts +20 -5
- 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 +8 -2
- package/dist/storage/storage-index.js +8 -2
- package/dist/storage/storage-index.js.map +1 -1
- package/dist/sync/BroadcastIterable.d.ts +0 -1
- package/dist/sync/BroadcastIterable.js.map +1 -1
- package/dist/sync/LastValueSink.d.ts +0 -1
- package/dist/sync/LastValueSink.js.map +1 -1
- package/dist/sync/merge.d.ts +0 -1
- package/dist/sync/merge.js.map +1 -1
- package/dist/sync/safeRace.js.map +1 -1
- package/dist/sync/sync.d.ts +1 -1
- package/dist/sync/sync.js +5 -5
- package/dist/sync/sync.js.map +1 -1
- package/dist/sync/util.d.ts +0 -2
- 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/Mutex.js.map +1 -1
- package/dist/util/config/collectors/config-collector.js.map +1 -1
- package/dist/util/config/collectors/impl/base64-config-collector.js.map +1 -1
- package/dist/util/config/collectors/impl/filesystem-config-collector.js.map +1 -1
- package/dist/util/config/compound-config-collector.d.ts +9 -2
- package/dist/util/config/compound-config-collector.js +31 -23
- package/dist/util/config/compound-config-collector.js.map +1 -1
- package/dist/util/config/sync-rules/impl/base64-sync-rules-collector.js.map +1 -1
- package/dist/util/config/sync-rules/impl/filesystem-sync-rules-collector.js.map +1 -1
- package/dist/util/config/sync-rules/impl/inline-sync-rules-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 +7 -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/memory-tracking.js.map +1 -1
- package/dist/util/secs.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 -7
- package/dist/util/utils.js +36 -25
- package/dist/util/utils.js.map +1 -1
- package/package.json +8 -12
- package/src/api/RouteAPI.ts +78 -0
- package/src/api/api-index.ts +1 -0
- package/src/api/diagnostics.ts +18 -70
- package/src/api/schema.ts +18 -90
- package/src/auth/KeyStore.ts +9 -6
- package/src/auth/RemoteJWKSCollector.ts +4 -1
- package/src/auth/StaticSupabaseKeyCollector.ts +31 -0
- package/src/auth/auth-index.ts +1 -1
- package/src/db/mongo.ts +5 -3
- package/src/entry/cli-entry.ts +3 -2
- package/src/entry/commands/compact-action.ts +24 -12
- 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/db/migrations/1727099539247-custom-write-checkpoint-index.ts +37 -0
- 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 +228 -0
- package/src/replication/ErrorRateLimiter.ts +0 -44
- package/src/replication/ReplicationEngine.ts +43 -0
- package/src/replication/ReplicationModule.ts +122 -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 +26 -27
- package/src/routes/configure-rsocket.ts +13 -8
- package/src/routes/endpoints/admin.ts +72 -76
- package/src/routes/endpoints/checkpointing.ts +51 -11
- package/src/routes/endpoints/socket-route.ts +10 -6
- package/src/routes/endpoints/sync-rules.ts +41 -25
- package/src/routes/endpoints/sync-stream.ts +8 -8
- package/src/routes/router.ts +8 -3
- package/src/routes/routes-index.ts +1 -0
- package/src/runner/teardown.ts +50 -88
- package/src/storage/BucketStorage.ts +103 -41
- package/src/storage/MongoBucketStorage.ts +65 -53
- package/src/storage/ReplicationEventPayload.ts +16 -0
- package/src/storage/SourceEntity.ts +22 -0
- package/src/storage/SourceTable.ts +14 -7
- package/src/storage/StorageEngine.ts +62 -0
- package/src/storage/StorageProvider.ts +27 -0
- package/src/storage/WriteCheckpointAPI.ts +85 -0
- package/src/storage/mongo/MongoBucketBatch.ts +164 -84
- package/src/storage/mongo/MongoCompactor.ts +25 -4
- package/src/storage/mongo/MongoPersistedSyncRulesContent.ts +7 -4
- package/src/storage/mongo/MongoStorageProvider.ts +31 -0
- package/src/storage/mongo/MongoSyncBucketStorage.ts +118 -41
- package/src/storage/mongo/MongoSyncRulesLock.ts +7 -3
- package/src/storage/mongo/MongoWriteCheckpointAPI.ts +151 -0
- package/src/storage/mongo/OperationBatch.ts +28 -12
- package/src/storage/mongo/PersistedBatch.ts +10 -6
- package/src/storage/mongo/config.ts +40 -0
- package/src/storage/mongo/db.ts +4 -1
- package/src/storage/mongo/models.ts +21 -5
- package/src/storage/mongo/util.ts +48 -3
- package/src/storage/storage-index.ts +8 -2
- package/src/sync/sync.ts +7 -4
- 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 +48 -30
- package/src/util/config/sync-rules/sync-rules-provider.ts +18 -0
- package/src/util/config/types.ts +7 -5
- package/src/util/config.ts +6 -23
- package/src/util/util-index.ts +3 -6
- package/src/util/utils.ts +48 -41
- package/test/src/__snapshots__/sync.test.ts.snap +14 -14
- package/test/src/auth.test.ts +7 -7
- package/test/src/broadcast_iterable.test.ts +1 -1
- package/test/src/compacting.test.ts +50 -40
- package/test/src/data_storage.test.ts +382 -202
- package/test/src/env.ts +1 -3
- package/test/src/merge_iterable.test.ts +1 -6
- package/test/src/routes/probes.integration.test.ts +34 -30
- package/test/src/setup.ts +1 -1
- package/test/src/stream_utils.ts +42 -0
- package/test/src/sync.test.ts +115 -39
- package/test/src/util.ts +48 -51
- package/test/tsconfig.json +1 -1
- package/tsconfig.tsbuildinfo +1 -1
- package/vitest.config.ts +7 -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 -519
- 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/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 -631
- package/src/replication/WalStreamManager.ts +0 -213
- package/src/replication/WalStreamRunner.ts +0 -180
- package/src/replication/util.ts +0 -76
- 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/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,48 @@
|
|
|
1
1
|
# @powersync/service-core
|
|
2
2
|
|
|
3
|
+
## 0.10.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 35c267f: Add "supabase_jwt_secret" config option to simplify static Supabase auth.
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- 2c18ad2: Fix compact action
|
|
12
|
+
- Updated dependencies [35c267f]
|
|
13
|
+
- @powersync/service-types@0.4.0
|
|
14
|
+
|
|
15
|
+
## 0.9.0
|
|
16
|
+
|
|
17
|
+
### Minor Changes
|
|
18
|
+
|
|
19
|
+
- 57bd18b: Added ability to emit data replication events
|
|
20
|
+
- 57bd18b: Introduced alpha support for MySQL as a datasource for replication.
|
|
21
|
+
Bunch of cleanup
|
|
22
|
+
- 57bd18b: Moved Write Checkpoint APIs to SyncBucketStorage
|
|
23
|
+
- 57bd18b: - Introduced modules to the powersync service architecture
|
|
24
|
+
- Core functionality has been moved to "engine" classes. Modules can register additional functionality with these engines.
|
|
25
|
+
- The sync API functionality used by the routes has been abstracted to an interface. API routes are now managed by the RouterEngine.
|
|
26
|
+
- Replication is managed by the ReplicationEngine and new replication data sources can be registered to the engine by modules.
|
|
27
|
+
- Refactored existing Postgres replication as a module.
|
|
28
|
+
- Removed Postgres specific code from the core service packages.
|
|
29
|
+
|
|
30
|
+
### Patch Changes
|
|
31
|
+
|
|
32
|
+
- 57bd18b: Improved sync rules storage cached parsed sync rules, accommodating different parsing options where necessary.
|
|
33
|
+
- 57bd18b: Moved tag variable initialization in diagnostics route to ensure it is initialized before usage
|
|
34
|
+
- Updated dependencies [57bd18b]
|
|
35
|
+
- Updated dependencies [57bd18b]
|
|
36
|
+
- Updated dependencies [57bd18b]
|
|
37
|
+
- Updated dependencies [57bd18b]
|
|
38
|
+
- Updated dependencies [57bd18b]
|
|
39
|
+
- Updated dependencies [57bd18b]
|
|
40
|
+
- Updated dependencies [57bd18b]
|
|
41
|
+
- @powersync/lib-services-framework@0.2.0
|
|
42
|
+
- @powersync/service-sync-rules@0.21.0
|
|
43
|
+
- @powersync/service-rsocket-router@0.0.14
|
|
44
|
+
- @powersync/service-types@0.3.0
|
|
45
|
+
|
|
3
46
|
## 0.8.8
|
|
4
47
|
|
|
5
48
|
### Patch Changes
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { SqlSyncRules, TablePattern } from '@powersync/service-sync-rules';
|
|
2
|
+
import * as types from '@powersync/service-types';
|
|
3
|
+
import { ParseSyncRulesOptions, SyncRulesBucketStorage } from '../storage/BucketStorage.js';
|
|
4
|
+
export interface PatternResult {
|
|
5
|
+
schema: string;
|
|
6
|
+
pattern: string;
|
|
7
|
+
wildcard: boolean;
|
|
8
|
+
tables?: types.TableInfo[];
|
|
9
|
+
table?: types.TableInfo;
|
|
10
|
+
}
|
|
11
|
+
export interface ReplicationLagOptions {
|
|
12
|
+
bucketStorage: SyncRulesBucketStorage;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Describes all the methods currently required to service the sync API endpoints.
|
|
16
|
+
*/
|
|
17
|
+
export interface RouteAPI {
|
|
18
|
+
/**
|
|
19
|
+
* @returns basic identification of the connection
|
|
20
|
+
*/
|
|
21
|
+
getSourceConfig(): Promise<types.configFile.ResolvedDataSourceConfig>;
|
|
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
|
+
* Generates replication table information from a given pattern of tables.
|
|
29
|
+
*
|
|
30
|
+
* @param tablePatterns A set of table patterns which typically come from
|
|
31
|
+
* the tables listed in sync rules definitions.
|
|
32
|
+
*
|
|
33
|
+
* @param sqlSyncRules
|
|
34
|
+
* @returns A result of all the tables and columns which should be replicated
|
|
35
|
+
* based off the input patterns. Certain tests are executed on the
|
|
36
|
+
* tables to ensure syncing should function according to the input
|
|
37
|
+
* pattern. Debug errors and warnings are reported per table.
|
|
38
|
+
*/
|
|
39
|
+
getDebugTablesInfo(tablePatterns: TablePattern[], sqlSyncRules: SqlSyncRules): Promise<PatternResult[]>;
|
|
40
|
+
/**
|
|
41
|
+
* @returns The replication lag: that is the amount of data which has not been
|
|
42
|
+
* replicated yet, in bytes.
|
|
43
|
+
*/
|
|
44
|
+
getReplicationLag(options: ReplicationLagOptions): Promise<number | undefined>;
|
|
45
|
+
/**
|
|
46
|
+
* Get the current LSN or equivalent replication HEAD position identifier
|
|
47
|
+
*/
|
|
48
|
+
getReplicationHead(): Promise<string>;
|
|
49
|
+
/**
|
|
50
|
+
* @returns The schema for tables inside the connected database. This is typically
|
|
51
|
+
* used to validate sync rules.
|
|
52
|
+
*/
|
|
53
|
+
getConnectionSchema(): Promise<types.DatabaseSchema[]>;
|
|
54
|
+
/**
|
|
55
|
+
* Executes a query and return the result from the data source. This is currently used in the
|
|
56
|
+
* admin API which is exposed in Collide.
|
|
57
|
+
*/
|
|
58
|
+
executeQuery(query: string, params: any[]): Promise<types.internal_routes.ExecuteSqlResponse>;
|
|
59
|
+
/**
|
|
60
|
+
* Close any resources that need graceful termination.
|
|
61
|
+
*/
|
|
62
|
+
shutdown(): Promise<void>;
|
|
63
|
+
/**
|
|
64
|
+
* Get the default schema (or database) when only a table name is specified in sync rules.
|
|
65
|
+
*/
|
|
66
|
+
getParseSyncRulesOptions(): ParseSyncRulesOptions;
|
|
67
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RouteAPI.js","sourceRoot":"","sources":["../../src/api/RouteAPI.ts"],"names":[],"mappings":""}
|
package/dist/api/api-index.d.ts
CHANGED
package/dist/api/api-index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api-index.js","sourceRoot":"","sources":["../../src/api/api-index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAC;AACjC,cAAc,aAAa,CAAC"}
|
|
1
|
+
{"version":3,"file":"api-index.js","sourceRoot":"","sources":["../../src/api/api-index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAC;AACjC,cAAc,eAAe,CAAC;AAC9B,cAAc,aAAa,CAAC"}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { SyncRulesStatus } from '@powersync/service-types';
|
|
2
2
|
import * as storage from '../storage/storage-index.js';
|
|
3
|
-
import {
|
|
4
|
-
export declare function getConnectionStatus(system: CorePowerSyncSystem): Promise<ConnectionStatus | null>;
|
|
3
|
+
import { RouteAPI } from './RouteAPI.js';
|
|
5
4
|
export interface DiagnosticsOptions {
|
|
6
5
|
/**
|
|
7
6
|
* Include sync rules content in response.
|
|
@@ -18,4 +17,5 @@ export interface DiagnosticsOptions {
|
|
|
18
17
|
*/
|
|
19
18
|
check_connection: boolean;
|
|
20
19
|
}
|
|
21
|
-
export declare
|
|
20
|
+
export declare const DEFAULT_DATASOURCE_ID = "default";
|
|
21
|
+
export declare function getSyncRulesStatus(bucketStorage: storage.BucketStorageFactory, apiHandler: RouteAPI, sync_rules: storage.PersistedSyncRulesContent | null, options: DiagnosticsOptions): Promise<SyncRulesStatus | undefined>;
|
package/dist/api/diagnostics.js
CHANGED
|
@@ -1,171 +1,183 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
await util.retriedQuery(pool, `SELECT 'PowerSync connection test'`);
|
|
18
|
-
}
|
|
19
|
-
catch (e) {
|
|
20
|
-
return {
|
|
21
|
-
...base,
|
|
22
|
-
connected: false,
|
|
23
|
-
errors: [{ level: 'fatal', message: e.message }]
|
|
24
|
-
};
|
|
25
|
-
}
|
|
26
|
-
try {
|
|
27
|
-
await replication.checkSourceConfiguration(pool);
|
|
1
|
+
var __addDisposableResource = (this && this.__addDisposableResource) || function (env, value, async) {
|
|
2
|
+
if (value !== null && value !== void 0) {
|
|
3
|
+
if (typeof value !== "object" && typeof value !== "function") throw new TypeError("Object expected.");
|
|
4
|
+
var dispose, inner;
|
|
5
|
+
if (async) {
|
|
6
|
+
if (!Symbol.asyncDispose) throw new TypeError("Symbol.asyncDispose is not defined.");
|
|
7
|
+
dispose = value[Symbol.asyncDispose];
|
|
8
|
+
}
|
|
9
|
+
if (dispose === void 0) {
|
|
10
|
+
if (!Symbol.dispose) throw new TypeError("Symbol.dispose is not defined.");
|
|
11
|
+
dispose = value[Symbol.dispose];
|
|
12
|
+
if (async) inner = dispose;
|
|
13
|
+
}
|
|
14
|
+
if (typeof dispose !== "function") throw new TypeError("Object not disposable.");
|
|
15
|
+
if (inner) dispose = function() { try { inner.call(this); } catch (e) { return Promise.reject(e); } };
|
|
16
|
+
env.stack.push({ value: value, dispose: dispose, async: async });
|
|
28
17
|
}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
...base,
|
|
32
|
-
connected: true,
|
|
33
|
-
errors: [{ level: 'fatal', message: e.message }]
|
|
34
|
-
};
|
|
18
|
+
else if (async) {
|
|
19
|
+
env.stack.push({ async: true });
|
|
35
20
|
}
|
|
36
|
-
return
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
21
|
+
return value;
|
|
22
|
+
};
|
|
23
|
+
var __disposeResources = (this && this.__disposeResources) || (function (SuppressedError) {
|
|
24
|
+
return function (env) {
|
|
25
|
+
function fail(e) {
|
|
26
|
+
env.error = env.hasError ? new SuppressedError(e, env.error, "An error was suppressed during disposal.") : e;
|
|
27
|
+
env.hasError = true;
|
|
28
|
+
}
|
|
29
|
+
var r, s = 0;
|
|
30
|
+
function next() {
|
|
31
|
+
while (r = env.stack.pop()) {
|
|
32
|
+
try {
|
|
33
|
+
if (!r.async && s === 1) return s = 0, env.stack.push(r), Promise.resolve().then(next);
|
|
34
|
+
if (r.dispose) {
|
|
35
|
+
var result = r.dispose.call(r.value);
|
|
36
|
+
if (r.async) return s |= 2, Promise.resolve(result).then(next, function(e) { fail(e); return next(); });
|
|
37
|
+
}
|
|
38
|
+
else s |= 1;
|
|
39
|
+
}
|
|
40
|
+
catch (e) {
|
|
41
|
+
fail(e);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
if (s === 1) return env.hasError ? Promise.reject(env.error) : Promise.resolve();
|
|
45
|
+
if (env.hasError) throw env.error;
|
|
46
|
+
}
|
|
47
|
+
return next();
|
|
40
48
|
};
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
let persisted;
|
|
49
|
+
})(typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
50
|
+
var e = new Error(message);
|
|
51
|
+
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
52
|
+
});
|
|
53
|
+
import { logger } from '@powersync/lib-services-framework';
|
|
54
|
+
import { DEFAULT_TAG } from '@powersync/service-sync-rules';
|
|
55
|
+
export const DEFAULT_DATASOURCE_ID = 'default';
|
|
56
|
+
export async function getSyncRulesStatus(bucketStorage, apiHandler, sync_rules, options) {
|
|
57
|
+
const env_1 = { stack: [], error: void 0, hasError: false };
|
|
51
58
|
try {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
59
|
+
if (sync_rules == null) {
|
|
60
|
+
return undefined;
|
|
61
|
+
}
|
|
62
|
+
const include_content = options.include_content ?? false;
|
|
63
|
+
const live_status = options.live_status ?? false;
|
|
64
|
+
const check_connection = options.check_connection ?? false;
|
|
65
|
+
let rules;
|
|
66
|
+
let persisted;
|
|
67
|
+
try {
|
|
68
|
+
persisted = sync_rules.parsed(apiHandler.getParseSyncRulesOptions());
|
|
69
|
+
rules = persisted.sync_rules;
|
|
70
|
+
}
|
|
71
|
+
catch (e) {
|
|
72
|
+
return {
|
|
73
|
+
content: include_content ? sync_rules.sync_rules_content : undefined,
|
|
74
|
+
connections: [],
|
|
75
|
+
errors: [{ level: 'fatal', message: e.message }]
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
const sourceConfig = await apiHandler.getSourceConfig();
|
|
79
|
+
// This method can run under some situations if no connection is configured yet.
|
|
80
|
+
// It will return a default tag in such a case. This default tag is not module specific.
|
|
81
|
+
const tag = sourceConfig.tag ?? DEFAULT_TAG;
|
|
82
|
+
const systemStorage = __addDisposableResource(env_1, live_status ? bucketStorage.getInstance(sync_rules) : undefined, false);
|
|
83
|
+
const status = await systemStorage?.getStatus();
|
|
84
|
+
let replication_lag_bytes = undefined;
|
|
85
|
+
let tables_flat = [];
|
|
86
|
+
if (check_connection) {
|
|
87
|
+
const source_table_patterns = rules.getSourceTables();
|
|
88
|
+
const resolved_tables = await apiHandler.getDebugTablesInfo(source_table_patterns, rules);
|
|
89
|
+
tables_flat = resolved_tables.flatMap((info) => {
|
|
90
|
+
if (info.table) {
|
|
91
|
+
return [info.table];
|
|
92
|
+
}
|
|
93
|
+
else if (info.tables) {
|
|
94
|
+
return info.tables;
|
|
95
|
+
}
|
|
96
|
+
else {
|
|
97
|
+
return [];
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
if (systemStorage) {
|
|
101
|
+
try {
|
|
102
|
+
replication_lag_bytes = await apiHandler.getReplicationLag({
|
|
103
|
+
bucketStorage: systemStorage
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
catch (e) {
|
|
107
|
+
// Ignore
|
|
108
|
+
logger.warn(`Unable to get replication lag`, e);
|
|
99
109
|
}
|
|
100
110
|
}
|
|
101
|
-
catch (e) {
|
|
102
|
-
// Ignore
|
|
103
|
-
logger.warn(`Unable to get replication lag`, e);
|
|
104
|
-
}
|
|
105
111
|
}
|
|
112
|
+
else {
|
|
113
|
+
const source_table_patterns = rules.getSourceTables();
|
|
114
|
+
tables_flat = source_table_patterns.map((pattern) => {
|
|
115
|
+
if (pattern.isWildcard) {
|
|
116
|
+
return {
|
|
117
|
+
schema: pattern.schema,
|
|
118
|
+
name: pattern.tablePrefix,
|
|
119
|
+
pattern: pattern.isWildcard ? pattern.tablePattern : undefined,
|
|
120
|
+
data_queries: false,
|
|
121
|
+
parameter_queries: false,
|
|
122
|
+
replication_id: [],
|
|
123
|
+
errors: [{ level: 'fatal', message: 'connection failed' }]
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
else {
|
|
127
|
+
const source = {
|
|
128
|
+
connectionTag: tag,
|
|
129
|
+
schema: pattern.schema,
|
|
130
|
+
table: pattern.tablePattern
|
|
131
|
+
};
|
|
132
|
+
const syncData = rules.tableSyncsData(source);
|
|
133
|
+
const syncParameters = rules.tableSyncsParameters(source);
|
|
134
|
+
return {
|
|
135
|
+
schema: pattern.schema,
|
|
136
|
+
name: pattern.name,
|
|
137
|
+
data_queries: syncData,
|
|
138
|
+
parameter_queries: syncParameters,
|
|
139
|
+
replication_id: [],
|
|
140
|
+
errors: [{ level: 'fatal', message: 'connection failed' }]
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
const errors = tables_flat.flatMap((info) => info.errors);
|
|
146
|
+
if (sync_rules.last_fatal_error) {
|
|
147
|
+
errors.push({ level: 'fatal', message: sync_rules.last_fatal_error });
|
|
148
|
+
}
|
|
149
|
+
errors.push(...rules.errors.map((e) => {
|
|
150
|
+
return {
|
|
151
|
+
level: e.type,
|
|
152
|
+
message: e.message
|
|
153
|
+
};
|
|
154
|
+
}));
|
|
155
|
+
return {
|
|
156
|
+
content: include_content ? sync_rules.sync_rules_content : undefined,
|
|
157
|
+
connections: [
|
|
158
|
+
{
|
|
159
|
+
id: sourceConfig.id ?? DEFAULT_DATASOURCE_ID,
|
|
160
|
+
tag: tag,
|
|
161
|
+
slot_name: sync_rules.slot_name,
|
|
162
|
+
initial_replication_done: status?.snapshot_done ?? false,
|
|
163
|
+
// TODO: Rename?
|
|
164
|
+
last_lsn: status?.checkpoint_lsn ?? undefined,
|
|
165
|
+
last_checkpoint_ts: sync_rules.last_checkpoint_ts?.toISOString(),
|
|
166
|
+
last_keepalive_ts: sync_rules.last_keepalive_ts?.toISOString(),
|
|
167
|
+
replication_lag_bytes: replication_lag_bytes,
|
|
168
|
+
tables: tables_flat
|
|
169
|
+
}
|
|
170
|
+
],
|
|
171
|
+
errors: deduplicate(errors)
|
|
172
|
+
};
|
|
106
173
|
}
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
tables_flat = source_table_patterns.map((pattern) => {
|
|
111
|
-
if (pattern.isWildcard) {
|
|
112
|
-
return {
|
|
113
|
-
schema: pattern.schema,
|
|
114
|
-
name: pattern.tablePrefix,
|
|
115
|
-
pattern: pattern.isWildcard ? pattern.tablePattern : undefined,
|
|
116
|
-
data_queries: false,
|
|
117
|
-
parameter_queries: false,
|
|
118
|
-
replication_id: [],
|
|
119
|
-
errors: [{ level: 'fatal', message: 'connection failed' }]
|
|
120
|
-
};
|
|
121
|
-
}
|
|
122
|
-
else {
|
|
123
|
-
const source = {
|
|
124
|
-
connectionTag: tag,
|
|
125
|
-
schema: pattern.schema,
|
|
126
|
-
table: pattern.tablePattern
|
|
127
|
-
};
|
|
128
|
-
const syncData = rules.tableSyncsData(source);
|
|
129
|
-
const syncParameters = rules.tableSyncsParameters(source);
|
|
130
|
-
return {
|
|
131
|
-
schema: pattern.schema,
|
|
132
|
-
name: pattern.name,
|
|
133
|
-
data_queries: syncData,
|
|
134
|
-
parameter_queries: syncParameters,
|
|
135
|
-
replication_id: [],
|
|
136
|
-
errors: [{ level: 'fatal', message: 'connection failed' }]
|
|
137
|
-
};
|
|
138
|
-
}
|
|
139
|
-
});
|
|
174
|
+
catch (e_1) {
|
|
175
|
+
env_1.error = e_1;
|
|
176
|
+
env_1.hasError = true;
|
|
140
177
|
}
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
errors.push({ level: 'fatal', message: sync_rules.last_fatal_error });
|
|
178
|
+
finally {
|
|
179
|
+
__disposeResources(env_1);
|
|
144
180
|
}
|
|
145
|
-
errors.push(...rules.errors.map((e) => {
|
|
146
|
-
return {
|
|
147
|
-
level: e.type,
|
|
148
|
-
message: e.message
|
|
149
|
-
};
|
|
150
|
-
}));
|
|
151
|
-
return {
|
|
152
|
-
content: include_content ? sync_rules.sync_rules_content : undefined,
|
|
153
|
-
connections: [
|
|
154
|
-
{
|
|
155
|
-
id: system.config.connection.id,
|
|
156
|
-
tag: system.config.connection.tag ?? DEFAULT_TAG,
|
|
157
|
-
slot_name: sync_rules.slot_name,
|
|
158
|
-
initial_replication_done: status?.snapshot_done ?? false,
|
|
159
|
-
// TODO: Rename?
|
|
160
|
-
last_lsn: status?.checkpoint_lsn ?? undefined,
|
|
161
|
-
last_checkpoint_ts: sync_rules.last_checkpoint_ts?.toISOString(),
|
|
162
|
-
last_keepalive_ts: sync_rules.last_keepalive_ts?.toISOString(),
|
|
163
|
-
replication_lag_bytes: replication_lag_bytes,
|
|
164
|
-
tables: tables_flat
|
|
165
|
-
}
|
|
166
|
-
],
|
|
167
|
-
errors: deduplicate(errors)
|
|
168
|
-
};
|
|
169
181
|
}
|
|
170
182
|
function deduplicate(errors) {
|
|
171
183
|
let seen = new Set();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"diagnostics.js","sourceRoot":"","sources":["../../src/api/diagnostics.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"diagnostics.js","sourceRoot":"","sources":["../../src/api/diagnostics.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,mCAAmC,CAAC;AAC3D,OAAO,EAAE,WAAW,EAAsC,MAAM,+BAA+B,CAAC;AAyBhG,MAAM,CAAC,MAAM,qBAAqB,GAAG,SAAS,CAAC;AAE/C,MAAM,CAAC,KAAK,UAAU,kBAAkB,CACtC,aAA2C,EAC3C,UAAoB,EACpB,UAAoD,EACpD,OAA2B;;;QAE3B,IAAI,UAAU,IAAI,IA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,SAAS;YACpE,WAAW,EAAE;gBACX;oBACE,EAAE,EAAE,YAAY,CAAC,EAAE,IAAI,qBAAqB;oBAC5C,GAAG,EAAE,GAAG;oBACR,SAAS,EAAE,UAAU,CAAC,SAAS;oBAC/B,wBAAwB,EAAE,MAAM,EAAE,aAAa,IAAI,KAAK;oBACxD,gBAAgB;oBAChB,QAAQ,EAAE,MAAM,EAAE,cAAc,IAAI,SAAS;oBAC7C,kBAAkB,EAAE,UAAU,CAAC,kBAAkB,EAAE,WAAW,EAAE;oBAChE,iBAAiB,EAAE,UAAU,CAAC,iBAAiB,EAAE,WAAW,EAAE;oBAC9D,qBAAqB,EAAE,qBAAqB;oBAC5C,MAAM,EAAE,WAAW;iBACpB;aACF;YACD,MAAM,EAAE,WAAW,CAAC,MAAM,CAAC;SAC5B,CAAC;;;;;;;;;CACH;AAED,SAAS,WAAW,CAAC,MAAyD;IAC5E,IAAI,IAAI,GAAG,IAAI,GAAG,EAAU,CAAC;IAC7B,IAAI,MAAM,GAAsD,EAAE,CAAC;IACnE,KAAK,IAAI,KAAK,IAAI,MAAM,EAAE,CAAC;QACzB,MAAM,GAAG,GAAG,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;QAClC,IAAI,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC;YAClB,SAAS;QACX,CAAC;QACD,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QACd,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IACrB,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
package/dist/api/schema.d.ts
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
export declare function getConnectionsSchema(system: CorePowerSyncSystem): Promise<internal_routes.GetSchemaResponse>;
|
|
5
|
-
export declare function getConnectionSchema(db: pgwire.PgClient): Promise<DatabaseSchema[]>;
|
|
1
|
+
import { internal_routes } from '@powersync/service-types';
|
|
2
|
+
import * as api from '../api/api-index.js';
|
|
3
|
+
export declare function getConnectionsSchema(api: api.RouteAPI): Promise<internal_routes.GetSchemaResponse>;
|
package/dist/api/schema.js
CHANGED
|
@@ -1,88 +1,22 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
export async function getConnectionsSchema(api) {
|
|
2
|
+
if (!api) {
|
|
3
|
+
return {
|
|
4
|
+
connections: [],
|
|
5
|
+
defaultConnectionTag: 'default',
|
|
6
|
+
defaultSchema: ''
|
|
7
|
+
};
|
|
6
8
|
}
|
|
7
|
-
const
|
|
9
|
+
const baseConfig = await api.getSourceConfig();
|
|
8
10
|
return {
|
|
9
11
|
connections: [
|
|
10
12
|
{
|
|
11
|
-
|
|
12
|
-
tag:
|
|
13
|
-
|
|
13
|
+
id: baseConfig.id,
|
|
14
|
+
tag: baseConfig.tag,
|
|
15
|
+
schemas: await api.getConnectionSchema()
|
|
14
16
|
}
|
|
15
|
-
]
|
|
17
|
+
],
|
|
18
|
+
defaultConnectionTag: baseConfig.tag,
|
|
19
|
+
defaultSchema: api.getParseSyncRulesOptions().defaultSchema
|
|
16
20
|
};
|
|
17
21
|
}
|
|
18
|
-
export async function getConnectionSchema(db) {
|
|
19
|
-
var _a;
|
|
20
|
-
// https://github.com/Borvik/vscode-postgres/blob/88ec5ed061a0c9bced6c5d4ec122d0759c3f3247/src/language/server.ts
|
|
21
|
-
const results = await util.retriedQuery(db, `SELECT
|
|
22
|
-
tbl.schemaname,
|
|
23
|
-
tbl.tablename,
|
|
24
|
-
tbl.quoted_name,
|
|
25
|
-
json_agg(a ORDER BY attnum) as columns
|
|
26
|
-
FROM
|
|
27
|
-
(
|
|
28
|
-
SELECT
|
|
29
|
-
n.nspname as schemaname,
|
|
30
|
-
c.relname as tablename,
|
|
31
|
-
(quote_ident(n.nspname) || '.' || quote_ident(c.relname)) as quoted_name
|
|
32
|
-
FROM
|
|
33
|
-
pg_catalog.pg_class c
|
|
34
|
-
JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace
|
|
35
|
-
WHERE
|
|
36
|
-
c.relkind = 'r'
|
|
37
|
-
AND n.nspname not in ('information_schema', 'pg_catalog', 'pg_toast')
|
|
38
|
-
AND n.nspname not like 'pg_temp_%'
|
|
39
|
-
AND n.nspname not like 'pg_toast_temp_%'
|
|
40
|
-
AND c.relnatts > 0
|
|
41
|
-
AND has_schema_privilege(n.oid, 'USAGE') = true
|
|
42
|
-
AND has_table_privilege(quote_ident(n.nspname) || '.' || quote_ident(c.relname), 'SELECT, INSERT, UPDATE, DELETE, TRUNCATE, REFERENCES, TRIGGER') = true
|
|
43
|
-
) as tbl
|
|
44
|
-
LEFT JOIN (
|
|
45
|
-
SELECT
|
|
46
|
-
attrelid,
|
|
47
|
-
attname,
|
|
48
|
-
format_type(atttypid, atttypmod) as data_type,
|
|
49
|
-
(SELECT typname FROM pg_catalog.pg_type WHERE oid = atttypid) as pg_type,
|
|
50
|
-
attnum,
|
|
51
|
-
attisdropped
|
|
52
|
-
FROM
|
|
53
|
-
pg_attribute
|
|
54
|
-
) as a ON (
|
|
55
|
-
a.attrelid = tbl.quoted_name::regclass
|
|
56
|
-
AND a.attnum > 0
|
|
57
|
-
AND NOT a.attisdropped
|
|
58
|
-
AND has_column_privilege(tbl.quoted_name, a.attname, 'SELECT, INSERT, UPDATE, REFERENCES')
|
|
59
|
-
)
|
|
60
|
-
GROUP BY schemaname, tablename, quoted_name`);
|
|
61
|
-
const rows = pgwireRows(results);
|
|
62
|
-
let schemas = {};
|
|
63
|
-
for (let row of rows) {
|
|
64
|
-
const schema = (schemas[_a = row.schemaname] ?? (schemas[_a] = {
|
|
65
|
-
name: row.schemaname,
|
|
66
|
-
tables: []
|
|
67
|
-
}));
|
|
68
|
-
const table = {
|
|
69
|
-
name: row.tablename,
|
|
70
|
-
columns: []
|
|
71
|
-
};
|
|
72
|
-
schema.tables.push(table);
|
|
73
|
-
const columnInfo = JSON.parse(row.columns);
|
|
74
|
-
for (let column of columnInfo) {
|
|
75
|
-
let pg_type = column.pg_type;
|
|
76
|
-
if (pg_type.startsWith('_')) {
|
|
77
|
-
pg_type = `${pg_type.substring(1)}[]`;
|
|
78
|
-
}
|
|
79
|
-
table.columns.push({
|
|
80
|
-
name: column.attname,
|
|
81
|
-
type: column.data_type,
|
|
82
|
-
pg_type: pg_type
|
|
83
|
-
});
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
return Object.values(schemas);
|
|
87
|
-
}
|
|
88
22
|
//# sourceMappingURL=schema.js.map
|