@powersync/service-core 0.0.2
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/.probes/.gitkeep +0 -0
- package/CHANGELOG.md +13 -0
- package/LICENSE +67 -0
- package/README.md +3 -0
- package/dist/api/api-index.d.ts +2 -0
- package/dist/api/api-index.js +3 -0
- package/dist/api/api-index.js.map +1 -0
- package/dist/api/diagnostics.d.ts +21 -0
- package/dist/api/diagnostics.js +183 -0
- package/dist/api/diagnostics.js.map +1 -0
- package/dist/api/schema.d.ts +5 -0
- package/dist/api/schema.js +88 -0
- package/dist/api/schema.js.map +1 -0
- package/dist/auth/CachedKeyCollector.d.ts +46 -0
- package/dist/auth/CachedKeyCollector.js +116 -0
- package/dist/auth/CachedKeyCollector.js.map +1 -0
- package/dist/auth/CompoundKeyCollector.d.ts +8 -0
- package/dist/auth/CompoundKeyCollector.js +23 -0
- package/dist/auth/CompoundKeyCollector.js.map +1 -0
- package/dist/auth/JwtPayload.d.ts +10 -0
- package/dist/auth/JwtPayload.js +2 -0
- package/dist/auth/JwtPayload.js.map +1 -0
- package/dist/auth/KeyCollector.d.ts +24 -0
- package/dist/auth/KeyCollector.js +2 -0
- package/dist/auth/KeyCollector.js.map +1 -0
- package/dist/auth/KeySpec.d.ts +26 -0
- package/dist/auth/KeySpec.js +49 -0
- package/dist/auth/KeySpec.js.map +1 -0
- package/dist/auth/KeyStore.d.ts +39 -0
- package/dist/auth/KeyStore.js +131 -0
- package/dist/auth/KeyStore.js.map +1 -0
- package/dist/auth/LeakyBucket.d.ts +39 -0
- package/dist/auth/LeakyBucket.js +57 -0
- package/dist/auth/LeakyBucket.js.map +1 -0
- package/dist/auth/RemoteJWKSCollector.d.ts +24 -0
- package/dist/auth/RemoteJWKSCollector.js +106 -0
- package/dist/auth/RemoteJWKSCollector.js.map +1 -0
- package/dist/auth/StaticKeyCollector.d.ts +14 -0
- package/dist/auth/StaticKeyCollector.js +19 -0
- package/dist/auth/StaticKeyCollector.js.map +1 -0
- package/dist/auth/SupabaseKeyCollector.d.ts +22 -0
- package/dist/auth/SupabaseKeyCollector.js +61 -0
- package/dist/auth/SupabaseKeyCollector.js.map +1 -0
- package/dist/auth/auth-index.d.ts +10 -0
- package/dist/auth/auth-index.js +11 -0
- package/dist/auth/auth-index.js.map +1 -0
- package/dist/db/db-index.d.ts +1 -0
- package/dist/db/db-index.js +2 -0
- package/dist/db/db-index.js.map +1 -0
- package/dist/db/mongo.d.ts +29 -0
- package/dist/db/mongo.js +65 -0
- package/dist/db/mongo.js.map +1 -0
- package/dist/entry/cli-entry.d.ts +15 -0
- package/dist/entry/cli-entry.js +36 -0
- package/dist/entry/cli-entry.js.map +1 -0
- package/dist/entry/commands/config-command.d.ts +10 -0
- package/dist/entry/commands/config-command.js +21 -0
- package/dist/entry/commands/config-command.js.map +1 -0
- package/dist/entry/commands/migrate-action.d.ts +2 -0
- package/dist/entry/commands/migrate-action.js +18 -0
- package/dist/entry/commands/migrate-action.js.map +1 -0
- package/dist/entry/commands/start-action.d.ts +3 -0
- package/dist/entry/commands/start-action.js +15 -0
- package/dist/entry/commands/start-action.js.map +1 -0
- package/dist/entry/commands/teardown-action.d.ts +2 -0
- package/dist/entry/commands/teardown-action.js +17 -0
- package/dist/entry/commands/teardown-action.js.map +1 -0
- package/dist/entry/entry-index.d.ts +5 -0
- package/dist/entry/entry-index.js +6 -0
- package/dist/entry/entry-index.js.map +1 -0
- package/dist/index.d.ts +24 -0
- package/dist/index.js +26 -0
- package/dist/index.js.map +1 -0
- package/dist/metrics/metrics.d.ts +16 -0
- package/dist/metrics/metrics.js +139 -0
- package/dist/metrics/metrics.js.map +1 -0
- package/dist/migrations/db/migrations/1684951997326-init.d.ts +3 -0
- package/dist/migrations/db/migrations/1684951997326-init.js +31 -0
- package/dist/migrations/db/migrations/1684951997326-init.js.map +1 -0
- package/dist/migrations/db/migrations/1688556755264-initial-sync-rules.d.ts +2 -0
- package/dist/migrations/db/migrations/1688556755264-initial-sync-rules.js +5 -0
- package/dist/migrations/db/migrations/1688556755264-initial-sync-rules.js.map +1 -0
- package/dist/migrations/db/migrations/1702295701188-sync-rule-state.d.ts +3 -0
- package/dist/migrations/db/migrations/1702295701188-sync-rule-state.js +54 -0
- package/dist/migrations/db/migrations/1702295701188-sync-rule-state.js.map +1 -0
- package/dist/migrations/db/migrations/1711543888062-write-checkpoint-index.d.ts +3 -0
- package/dist/migrations/db/migrations/1711543888062-write-checkpoint-index.js +27 -0
- package/dist/migrations/db/migrations/1711543888062-write-checkpoint-index.js.map +1 -0
- package/dist/migrations/db/store.d.ts +3 -0
- package/dist/migrations/db/store.js +10 -0
- package/dist/migrations/db/store.js.map +1 -0
- package/dist/migrations/migrations.d.ts +10 -0
- package/dist/migrations/migrations.js +94 -0
- package/dist/migrations/migrations.js.map +1 -0
- package/dist/replication/ErrorRateLimiter.d.ts +17 -0
- package/dist/replication/ErrorRateLimiter.js +42 -0
- package/dist/replication/ErrorRateLimiter.js.map +1 -0
- package/dist/replication/PgRelation.d.ts +16 -0
- package/dist/replication/PgRelation.js +26 -0
- package/dist/replication/PgRelation.js.map +1 -0
- package/dist/replication/WalConnection.d.ts +34 -0
- package/dist/replication/WalConnection.js +190 -0
- package/dist/replication/WalConnection.js.map +1 -0
- package/dist/replication/WalStream.d.ts +58 -0
- package/dist/replication/WalStream.js +517 -0
- package/dist/replication/WalStream.js.map +1 -0
- package/dist/replication/WalStreamManager.d.ts +30 -0
- package/dist/replication/WalStreamManager.js +199 -0
- package/dist/replication/WalStreamManager.js.map +1 -0
- package/dist/replication/WalStreamRunner.d.ts +38 -0
- package/dist/replication/WalStreamRunner.js +155 -0
- package/dist/replication/WalStreamRunner.js.map +1 -0
- package/dist/replication/replication-index.d.ts +7 -0
- package/dist/replication/replication-index.js +8 -0
- package/dist/replication/replication-index.js.map +1 -0
- package/dist/replication/util.d.ts +9 -0
- package/dist/replication/util.js +62 -0
- package/dist/replication/util.js.map +1 -0
- package/dist/routes/admin.d.ts +7 -0
- package/dist/routes/admin.js +192 -0
- package/dist/routes/admin.js.map +1 -0
- package/dist/routes/auth.d.ts +58 -0
- package/dist/routes/auth.js +182 -0
- package/dist/routes/auth.js.map +1 -0
- package/dist/routes/checkpointing.d.ts +3 -0
- package/dist/routes/checkpointing.js +30 -0
- package/dist/routes/checkpointing.js.map +1 -0
- package/dist/routes/dev.d.ts +6 -0
- package/dist/routes/dev.js +163 -0
- package/dist/routes/dev.js.map +1 -0
- package/dist/routes/route-generators.d.ts +15 -0
- package/dist/routes/route-generators.js +32 -0
- package/dist/routes/route-generators.js.map +1 -0
- package/dist/routes/router-socket.d.ts +10 -0
- package/dist/routes/router-socket.js +5 -0
- package/dist/routes/router-socket.js.map +1 -0
- package/dist/routes/router.d.ts +13 -0
- package/dist/routes/router.js +2 -0
- package/dist/routes/router.js.map +1 -0
- package/dist/routes/routes-index.d.ts +4 -0
- package/dist/routes/routes-index.js +5 -0
- package/dist/routes/routes-index.js.map +1 -0
- package/dist/routes/socket-route.d.ts +2 -0
- package/dist/routes/socket-route.js +119 -0
- package/dist/routes/socket-route.js.map +1 -0
- package/dist/routes/sync-rules.d.ts +6 -0
- package/dist/routes/sync-rules.js +182 -0
- package/dist/routes/sync-rules.js.map +1 -0
- package/dist/routes/sync-stream.d.ts +5 -0
- package/dist/routes/sync-stream.js +74 -0
- package/dist/routes/sync-stream.js.map +1 -0
- package/dist/runner/teardown.d.ts +2 -0
- package/dist/runner/teardown.js +79 -0
- package/dist/runner/teardown.js.map +1 -0
- package/dist/storage/BucketStorage.d.ts +298 -0
- package/dist/storage/BucketStorage.js +25 -0
- package/dist/storage/BucketStorage.js.map +1 -0
- package/dist/storage/MongoBucketStorage.d.ts +51 -0
- package/dist/storage/MongoBucketStorage.js +388 -0
- package/dist/storage/MongoBucketStorage.js.map +1 -0
- package/dist/storage/SourceTable.d.ts +39 -0
- package/dist/storage/SourceTable.js +50 -0
- package/dist/storage/SourceTable.js.map +1 -0
- package/dist/storage/mongo/MongoBucketBatch.d.ts +48 -0
- package/dist/storage/mongo/MongoBucketBatch.js +584 -0
- package/dist/storage/mongo/MongoBucketBatch.js.map +1 -0
- package/dist/storage/mongo/MongoIdSequence.d.ts +12 -0
- package/dist/storage/mongo/MongoIdSequence.js +21 -0
- package/dist/storage/mongo/MongoIdSequence.js.map +1 -0
- package/dist/storage/mongo/MongoPersistedSyncRules.d.ts +9 -0
- package/dist/storage/mongo/MongoPersistedSyncRules.js +9 -0
- package/dist/storage/mongo/MongoPersistedSyncRules.js.map +1 -0
- package/dist/storage/mongo/MongoPersistedSyncRulesContent.d.ts +20 -0
- package/dist/storage/mongo/MongoPersistedSyncRulesContent.js +26 -0
- package/dist/storage/mongo/MongoPersistedSyncRulesContent.js.map +1 -0
- package/dist/storage/mongo/MongoSyncBucketStorage.d.ts +27 -0
- package/dist/storage/mongo/MongoSyncBucketStorage.js +379 -0
- package/dist/storage/mongo/MongoSyncBucketStorage.js.map +1 -0
- package/dist/storage/mongo/MongoSyncRulesLock.d.ts +16 -0
- package/dist/storage/mongo/MongoSyncRulesLock.js +65 -0
- package/dist/storage/mongo/MongoSyncRulesLock.js.map +1 -0
- package/dist/storage/mongo/OperationBatch.d.ts +26 -0
- package/dist/storage/mongo/OperationBatch.js +101 -0
- package/dist/storage/mongo/OperationBatch.js.map +1 -0
- package/dist/storage/mongo/PersistedBatch.d.ts +42 -0
- package/dist/storage/mongo/PersistedBatch.js +200 -0
- package/dist/storage/mongo/PersistedBatch.js.map +1 -0
- package/dist/storage/mongo/db.d.ts +23 -0
- package/dist/storage/mongo/db.js +34 -0
- package/dist/storage/mongo/db.js.map +1 -0
- package/dist/storage/mongo/models.d.ts +137 -0
- package/dist/storage/mongo/models.js +27 -0
- package/dist/storage/mongo/models.js.map +1 -0
- package/dist/storage/mongo/util.d.ts +26 -0
- package/dist/storage/mongo/util.js +81 -0
- package/dist/storage/mongo/util.js.map +1 -0
- package/dist/storage/storage-index.d.ts +14 -0
- package/dist/storage/storage-index.js +15 -0
- package/dist/storage/storage-index.js.map +1 -0
- package/dist/sync/BroadcastIterable.d.ts +38 -0
- package/dist/sync/BroadcastIterable.js +153 -0
- package/dist/sync/BroadcastIterable.js.map +1 -0
- package/dist/sync/LastValueSink.d.ts +25 -0
- package/dist/sync/LastValueSink.js +84 -0
- package/dist/sync/LastValueSink.js.map +1 -0
- package/dist/sync/merge.d.ts +39 -0
- package/dist/sync/merge.js +175 -0
- package/dist/sync/merge.js.map +1 -0
- package/dist/sync/safeRace.d.ts +1 -0
- package/dist/sync/safeRace.js +91 -0
- package/dist/sync/safeRace.js.map +1 -0
- package/dist/sync/sync-index.d.ts +6 -0
- package/dist/sync/sync-index.js +7 -0
- package/dist/sync/sync-index.js.map +1 -0
- package/dist/sync/sync.d.ts +18 -0
- package/dist/sync/sync.js +248 -0
- package/dist/sync/sync.js.map +1 -0
- package/dist/sync/util.d.ts +26 -0
- package/dist/sync/util.js +73 -0
- package/dist/sync/util.js.map +1 -0
- package/dist/system/CorePowerSyncSystem.d.ts +18 -0
- package/dist/system/CorePowerSyncSystem.js +28 -0
- package/dist/system/CorePowerSyncSystem.js.map +1 -0
- package/dist/util/Mutex.d.ts +47 -0
- package/dist/util/Mutex.js +132 -0
- package/dist/util/Mutex.js.map +1 -0
- package/dist/util/PgManager.d.ts +24 -0
- package/dist/util/PgManager.js +55 -0
- package/dist/util/PgManager.js.map +1 -0
- package/dist/util/alerting.d.ts +4 -0
- package/dist/util/alerting.js +14 -0
- package/dist/util/alerting.js.map +1 -0
- package/dist/util/config/collectors/config-collector.d.ts +29 -0
- package/dist/util/config/collectors/config-collector.js +116 -0
- package/dist/util/config/collectors/config-collector.js.map +1 -0
- package/dist/util/config/collectors/impl/base64-config-collector.d.ts +6 -0
- package/dist/util/config/collectors/impl/base64-config-collector.js +15 -0
- package/dist/util/config/collectors/impl/base64-config-collector.js.map +1 -0
- package/dist/util/config/collectors/impl/fallback-config-collector.d.ts +11 -0
- package/dist/util/config/collectors/impl/fallback-config-collector.js +19 -0
- package/dist/util/config/collectors/impl/fallback-config-collector.js.map +1 -0
- package/dist/util/config/collectors/impl/filesystem-config-collector.d.ts +6 -0
- package/dist/util/config/collectors/impl/filesystem-config-collector.js +35 -0
- package/dist/util/config/collectors/impl/filesystem-config-collector.js.map +1 -0
- package/dist/util/config/compound-config-collector.d.ts +32 -0
- package/dist/util/config/compound-config-collector.js +126 -0
- package/dist/util/config/compound-config-collector.js.map +1 -0
- package/dist/util/config/sync-rules/impl/base64-sync-rules-collector.d.ts +7 -0
- package/dist/util/config/sync-rules/impl/base64-sync-rules-collector.js +17 -0
- package/dist/util/config/sync-rules/impl/base64-sync-rules-collector.js.map +1 -0
- package/dist/util/config/sync-rules/impl/filesystem-sync-rules-collector.d.ts +7 -0
- package/dist/util/config/sync-rules/impl/filesystem-sync-rules-collector.js +21 -0
- package/dist/util/config/sync-rules/impl/filesystem-sync-rules-collector.js.map +1 -0
- package/dist/util/config/sync-rules/impl/inline-sync-rules-collector.d.ts +7 -0
- package/dist/util/config/sync-rules/impl/inline-sync-rules-collector.js +17 -0
- package/dist/util/config/sync-rules/impl/inline-sync-rules-collector.js.map +1 -0
- package/dist/util/config/sync-rules/sync-collector.d.ts +6 -0
- package/dist/util/config/sync-rules/sync-collector.js +3 -0
- package/dist/util/config/sync-rules/sync-collector.js.map +1 -0
- package/dist/util/config/types.d.ts +53 -0
- package/dist/util/config/types.js +7 -0
- package/dist/util/config/types.js.map +1 -0
- package/dist/util/config.d.ts +7 -0
- package/dist/util/config.js +35 -0
- package/dist/util/config.js.map +1 -0
- package/dist/util/env.d.ts +10 -0
- package/dist/util/env.js +25 -0
- package/dist/util/env.js.map +1 -0
- package/dist/util/memory-tracking.d.ts +7 -0
- package/dist/util/memory-tracking.js +58 -0
- package/dist/util/memory-tracking.js.map +1 -0
- package/dist/util/migration_lib.d.ts +11 -0
- package/dist/util/migration_lib.js +64 -0
- package/dist/util/migration_lib.js.map +1 -0
- package/dist/util/pgwire_utils.d.ts +24 -0
- package/dist/util/pgwire_utils.js +117 -0
- package/dist/util/pgwire_utils.js.map +1 -0
- package/dist/util/populate_test_data.d.ts +8 -0
- package/dist/util/populate_test_data.js +65 -0
- package/dist/util/populate_test_data.js.map +1 -0
- package/dist/util/protocol-types.d.ts +178 -0
- package/dist/util/protocol-types.js +38 -0
- package/dist/util/protocol-types.js.map +1 -0
- package/dist/util/secs.d.ts +2 -0
- package/dist/util/secs.js +49 -0
- package/dist/util/secs.js.map +1 -0
- package/dist/util/util-index.d.ts +22 -0
- package/dist/util/util-index.js +23 -0
- package/dist/util/util-index.js.map +1 -0
- package/dist/util/utils.d.ts +14 -0
- package/dist/util/utils.js +75 -0
- package/dist/util/utils.js.map +1 -0
- package/package.json +55 -0
- package/src/api/api-index.ts +2 -0
- package/src/api/diagnostics.ts +221 -0
- package/src/api/schema.ts +99 -0
- package/src/auth/CachedKeyCollector.ts +132 -0
- package/src/auth/CompoundKeyCollector.ts +33 -0
- package/src/auth/JwtPayload.ts +11 -0
- package/src/auth/KeyCollector.ts +27 -0
- package/src/auth/KeySpec.ts +67 -0
- package/src/auth/KeyStore.ts +156 -0
- package/src/auth/LeakyBucket.ts +66 -0
- package/src/auth/RemoteJWKSCollector.ts +130 -0
- package/src/auth/StaticKeyCollector.ts +21 -0
- package/src/auth/SupabaseKeyCollector.ts +67 -0
- package/src/auth/auth-index.ts +10 -0
- package/src/db/db-index.ts +1 -0
- package/src/db/mongo.ts +72 -0
- package/src/entry/cli-entry.ts +41 -0
- package/src/entry/commands/config-command.ts +36 -0
- package/src/entry/commands/migrate-action.ts +25 -0
- package/src/entry/commands/start-action.ts +24 -0
- package/src/entry/commands/teardown-action.ts +23 -0
- package/src/entry/entry-index.ts +5 -0
- package/src/index.ts +37 -0
- package/src/metrics/metrics.ts +169 -0
- package/src/migrations/db/migrations/1684951997326-init.ts +33 -0
- package/src/migrations/db/migrations/1688556755264-initial-sync-rules.ts +5 -0
- package/src/migrations/db/migrations/1702295701188-sync-rule-state.ts +99 -0
- package/src/migrations/db/migrations/1711543888062-write-checkpoint-index.ts +32 -0
- package/src/migrations/db/store.ts +11 -0
- package/src/migrations/migrations.ts +122 -0
- package/src/replication/ErrorRateLimiter.ts +49 -0
- package/src/replication/PgRelation.ts +42 -0
- package/src/replication/WalConnection.ts +227 -0
- package/src/replication/WalStream.ts +626 -0
- package/src/replication/WalStreamManager.ts +214 -0
- package/src/replication/WalStreamRunner.ts +180 -0
- package/src/replication/replication-index.ts +7 -0
- package/src/replication/util.ts +76 -0
- package/src/routes/admin.ts +229 -0
- package/src/routes/auth.ts +209 -0
- package/src/routes/checkpointing.ts +38 -0
- package/src/routes/dev.ts +194 -0
- package/src/routes/route-generators.ts +39 -0
- package/src/routes/router-socket.ts +13 -0
- package/src/routes/router.ts +17 -0
- package/src/routes/routes-index.ts +5 -0
- package/src/routes/socket-route.ts +131 -0
- package/src/routes/sync-rules.ts +210 -0
- package/src/routes/sync-stream.ts +92 -0
- package/src/runner/teardown.ts +91 -0
- package/src/storage/BucketStorage.ts +386 -0
- package/src/storage/MongoBucketStorage.ts +493 -0
- package/src/storage/SourceTable.ts +60 -0
- package/src/storage/mongo/MongoBucketBatch.ts +756 -0
- package/src/storage/mongo/MongoIdSequence.ts +24 -0
- package/src/storage/mongo/MongoPersistedSyncRules.ts +16 -0
- package/src/storage/mongo/MongoPersistedSyncRulesContent.ts +47 -0
- package/src/storage/mongo/MongoSyncBucketStorage.ts +517 -0
- package/src/storage/mongo/MongoSyncRulesLock.ts +81 -0
- package/src/storage/mongo/OperationBatch.ts +115 -0
- package/src/storage/mongo/PersistedBatch.ts +245 -0
- package/src/storage/mongo/db.ts +69 -0
- package/src/storage/mongo/models.ts +157 -0
- package/src/storage/mongo/util.ts +88 -0
- package/src/storage/storage-index.ts +15 -0
- package/src/sync/BroadcastIterable.ts +161 -0
- package/src/sync/LastValueSink.ts +100 -0
- package/src/sync/merge.ts +200 -0
- package/src/sync/safeRace.ts +99 -0
- package/src/sync/sync-index.ts +6 -0
- package/src/sync/sync.ts +312 -0
- package/src/sync/util.ts +98 -0
- package/src/system/CorePowerSyncSystem.ts +43 -0
- package/src/util/Mutex.ts +159 -0
- package/src/util/PgManager.ts +64 -0
- package/src/util/alerting.ts +17 -0
- package/src/util/config/collectors/config-collector.ts +141 -0
- package/src/util/config/collectors/impl/base64-config-collector.ts +18 -0
- package/src/util/config/collectors/impl/fallback-config-collector.ts +22 -0
- package/src/util/config/collectors/impl/filesystem-config-collector.ts +41 -0
- package/src/util/config/compound-config-collector.ts +171 -0
- package/src/util/config/sync-rules/impl/base64-sync-rules-collector.ts +21 -0
- package/src/util/config/sync-rules/impl/filesystem-sync-rules-collector.ts +26 -0
- package/src/util/config/sync-rules/impl/inline-sync-rules-collector.ts +21 -0
- package/src/util/config/sync-rules/sync-collector.ts +8 -0
- package/src/util/config/types.ts +60 -0
- package/src/util/config.ts +39 -0
- package/src/util/env.ts +28 -0
- package/src/util/memory-tracking.ts +67 -0
- package/src/util/migration_lib.ts +79 -0
- package/src/util/pgwire_utils.ts +139 -0
- package/src/util/populate_test_data.ts +78 -0
- package/src/util/protocol-types.ts +223 -0
- package/src/util/secs.ts +54 -0
- package/src/util/util-index.ts +25 -0
- package/src/util/utils.ts +102 -0
- package/test/src/__snapshots__/pg_test.test.ts.snap +256 -0
- package/test/src/__snapshots__/sync.test.ts.snap +235 -0
- package/test/src/auth.test.ts +340 -0
- package/test/src/broadcast_iterable.test.ts +156 -0
- package/test/src/data_storage.test.ts +1176 -0
- package/test/src/env.ts +8 -0
- package/test/src/large_batch.test.ts +194 -0
- package/test/src/merge_iterable.test.ts +355 -0
- package/test/src/pg_test.test.ts +432 -0
- package/test/src/schema_changes.test.ts +545 -0
- package/test/src/slow_tests.test.ts +257 -0
- package/test/src/sql_functions.test.ts +254 -0
- package/test/src/sql_operators.test.ts +132 -0
- package/test/src/sync.test.ts +293 -0
- package/test/src/sync_rules.test.ts +1051 -0
- package/test/src/util.ts +67 -0
- package/test/src/validation.test.ts +63 -0
- package/test/src/wal_stream.test.ts +310 -0
- package/test/src/wal_stream_utils.ts +147 -0
- package/test/tsconfig.json +20 -0
- package/tsconfig.json +20 -0
- package/tsconfig.tsbuildinfo +1 -0
- package/vitest.config.ts +11 -0
|
@@ -0,0 +1,432 @@
|
|
|
1
|
+
import { describe, expect, test } from 'vitest';
|
|
2
|
+
import { WalStream } from '../../src/replication/WalStream.js';
|
|
3
|
+
import * as pgwire from '@powersync/service-jpgwire';
|
|
4
|
+
import { clearTestDb, connectPgPool, connectPgWire, TEST_URI } from './util.js';
|
|
5
|
+
import { constructAfterRecord } from '../../src/util/pgwire_utils.js';
|
|
6
|
+
import { SqliteRow } from '@powersync/service-sync-rules';
|
|
7
|
+
import { getConnectionSchema } from '../../src/api/schema.js';
|
|
8
|
+
|
|
9
|
+
describe('pg data types', () => {
|
|
10
|
+
async function setupTable(db: pgwire.PgClient) {
|
|
11
|
+
await clearTestDb(db);
|
|
12
|
+
await db.query(`CREATE TABLE test_data(
|
|
13
|
+
id serial primary key,
|
|
14
|
+
text text,
|
|
15
|
+
uuid uuid,
|
|
16
|
+
varchar varchar(255),
|
|
17
|
+
bool bool,
|
|
18
|
+
bytea bytea,
|
|
19
|
+
int2 int2,
|
|
20
|
+
int4 int4,
|
|
21
|
+
int8 int8,
|
|
22
|
+
float4 float4,
|
|
23
|
+
float8 float8,
|
|
24
|
+
numeric numeric, -- same as decimal
|
|
25
|
+
json json,
|
|
26
|
+
jsonb jsonb,
|
|
27
|
+
pg_lsn pg_lsn,
|
|
28
|
+
date date,
|
|
29
|
+
time time,
|
|
30
|
+
timestamp timestamp,
|
|
31
|
+
timestamptz timestamptz,
|
|
32
|
+
interval interval,
|
|
33
|
+
macaddr macaddr,
|
|
34
|
+
inet inet,
|
|
35
|
+
oid oid
|
|
36
|
+
)`);
|
|
37
|
+
|
|
38
|
+
await db.query(`DROP TABLE IF EXISTS test_data_arrays`);
|
|
39
|
+
await db.query(`CREATE TABLE test_data_arrays(
|
|
40
|
+
id serial primary key,
|
|
41
|
+
text text[],
|
|
42
|
+
uuid uuid[],
|
|
43
|
+
varchar varchar(255)[],
|
|
44
|
+
bool bool[],
|
|
45
|
+
bytea bytea[],
|
|
46
|
+
int2 int2[],
|
|
47
|
+
int4 int4[],
|
|
48
|
+
int8 int8[],
|
|
49
|
+
float4 float4[],
|
|
50
|
+
float8 float8[],
|
|
51
|
+
numeric numeric[], -- same as decimal
|
|
52
|
+
json json[],
|
|
53
|
+
jsonb jsonb[],
|
|
54
|
+
pg_lsn pg_lsn[],
|
|
55
|
+
date date[],
|
|
56
|
+
time time[],
|
|
57
|
+
timestamp timestamp[],
|
|
58
|
+
timestamptz timestamptz[],
|
|
59
|
+
interval interval[],
|
|
60
|
+
macaddr macaddr[],
|
|
61
|
+
inet inet[],
|
|
62
|
+
oid oid[],
|
|
63
|
+
multidimensional text[][] -- same as text[]
|
|
64
|
+
)`);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
async function insert(db: pgwire.PgClient) {
|
|
68
|
+
await db.query(`
|
|
69
|
+
INSERT INTO test_data(id, text, uuid, varchar, bool, bytea, int2, int4, int8, numeric, float4, float8)
|
|
70
|
+
VALUES(1, 'text', 'baeb2514-4c57-436d-b3cc-c1256211656d', 'varchar', true, 'test', 1000, 1000000, 9007199254740993, 18014398509481982123, 3.14, 314);
|
|
71
|
+
|
|
72
|
+
INSERT INTO test_data(id, json, jsonb)
|
|
73
|
+
VALUES(2, '{"test": "thing" }', '{"test": "thing" }');
|
|
74
|
+
|
|
75
|
+
INSERT INTO test_data(id, date, time, timestamp, timestamptz)
|
|
76
|
+
VALUES(3, '2023-03-06', '15:47', '2023-03-06 15:47', '2023-03-06 15:47+02');
|
|
77
|
+
|
|
78
|
+
INSERT INTO test_data(id, pg_lsn, interval, macaddr, inet, oid)
|
|
79
|
+
VALUES(4, '016/B374D848', '1 hour', '00:00:5e:00:53:af', '127.0.0.1', 1007);
|
|
80
|
+
|
|
81
|
+
INSERT INTO test_data(id, date, time, timestamp, timestamptz)
|
|
82
|
+
VALUES(5, '-infinity'::date, 'allballs'::time, '-infinity'::timestamp, '-infinity'::timestamptz);
|
|
83
|
+
|
|
84
|
+
INSERT INTO test_data(id, timestamp, timestamptz)
|
|
85
|
+
VALUES(6, 'epoch'::timestamp, 'epoch'::timestamptz);
|
|
86
|
+
|
|
87
|
+
INSERT INTO test_data(id, timestamp, timestamptz)
|
|
88
|
+
VALUES(7, 'infinity'::timestamp, 'infinity'::timestamptz);
|
|
89
|
+
`);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
async function insertArrays(db: pgwire.PgClient) {
|
|
93
|
+
await db.query(`
|
|
94
|
+
INSERT INTO test_data_arrays(id, text, uuid, varchar, bool, bytea, int2, int4, int8, numeric)
|
|
95
|
+
VALUES(1, ARRAY['text', '}te][xt{"'], '{"baeb2514-4c57-436d-b3cc-c1256211656d"}', '{"varchar"}', '{true}', '{"test"}', '{1000}', '{1000000}', '{9007199254740993}', '{18014398509481982123}');
|
|
96
|
+
|
|
97
|
+
INSERT INTO test_data_arrays(id, json, jsonb)
|
|
98
|
+
VALUES(2, ARRAY['{"test": "thing"}' :: json, '{"test": "}te][xt{"}' :: json], ARRAY['{"test": "thing", "foo": 5.0, "bignum": 18014398509481982123, "bool":true}' :: jsonb]);
|
|
99
|
+
|
|
100
|
+
INSERT INTO test_data_arrays(id, date, time, timestamp, timestamptz)
|
|
101
|
+
VALUES(3, ARRAY['2023-03-06'::date], ARRAY['15:47'::time], ARRAY['2023-03-06 15:47'::timestamp], ARRAY['2023-03-06 15:47+02'::timestamptz, '2023-03-06 15:47:00.123450+02'::timestamptz]);
|
|
102
|
+
|
|
103
|
+
INSERT INTO test_data_arrays(id, pg_lsn, interval, macaddr, inet, oid)
|
|
104
|
+
VALUES(4, ARRAY['016/B374D848'::pg_lsn], ARRAY['1 hour'::interval], ARRAY['00:00:5e:00:53:af'::macaddr], ARRAY['127.0.0.1'::inet], ARRAY[1007::oid]);
|
|
105
|
+
|
|
106
|
+
-- Empty arrays
|
|
107
|
+
INSERT INTO test_data_arrays(id, text, uuid, varchar, bool, bytea, int2, int4, int8, numeric)
|
|
108
|
+
VALUES(5, ARRAY[]::text[], ARRAY[]::uuid[], ARRAY[]::varchar[], ARRAY[]::bool[], ARRAY[]::bytea[], ARRAY[]::int2[], ARRAY[]::int4[], ARRAY[]::int8[], ARRAY[]::numeric[]);
|
|
109
|
+
|
|
110
|
+
-- Two-dimentional array
|
|
111
|
+
INSERT INTO test_data_arrays(id, multidimensional)
|
|
112
|
+
VALUES(6, ARRAY[['one', 1], ['two', 2], ['three', Null]]::TEXT[]);
|
|
113
|
+
|
|
114
|
+
-- Empty array
|
|
115
|
+
INSERT INTO test_data_arrays(id, multidimensional)
|
|
116
|
+
VALUES(7, ARRAY[[], [], []]::TEXT[]);
|
|
117
|
+
|
|
118
|
+
-- Empty array
|
|
119
|
+
INSERT INTO test_data_arrays(id, multidimensional)
|
|
120
|
+
VALUES(8, ARRAY[]::TEXT[]);
|
|
121
|
+
|
|
122
|
+
-- Array with only null
|
|
123
|
+
INSERT INTO test_data_arrays(id, multidimensional)
|
|
124
|
+
VALUES(9, ARRAY[NULL]::TEXT[]);
|
|
125
|
+
|
|
126
|
+
-- Array with 'null'
|
|
127
|
+
INSERT INTO test_data_arrays(id, multidimensional)
|
|
128
|
+
VALUES(10, ARRAY['null']::TEXT[]);
|
|
129
|
+
`);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
function checkResults(transformed: Record<string, any>[]) {
|
|
133
|
+
expect(transformed[0]).toMatchObject({
|
|
134
|
+
id: 1n,
|
|
135
|
+
text: 'text',
|
|
136
|
+
uuid: 'baeb2514-4c57-436d-b3cc-c1256211656d',
|
|
137
|
+
varchar: 'varchar',
|
|
138
|
+
bool: 1n,
|
|
139
|
+
bytea: new Uint8Array([116, 101, 115, 116]),
|
|
140
|
+
int2: 1000n,
|
|
141
|
+
int4: 1000000n,
|
|
142
|
+
int8: 9007199254740993n,
|
|
143
|
+
float4: 3.14,
|
|
144
|
+
float8: 314,
|
|
145
|
+
numeric: '18014398509481982123'
|
|
146
|
+
});
|
|
147
|
+
expect(transformed[1]).toMatchObject({
|
|
148
|
+
id: 2n,
|
|
149
|
+
json: '{"test": "thing" }', // Whitespace preserved
|
|
150
|
+
jsonb: '{"test": "thing"}' // Whitespace according to pg JSON conventions
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
expect(transformed[2]).toMatchObject({
|
|
154
|
+
id: 3n,
|
|
155
|
+
date: '2023-03-06',
|
|
156
|
+
time: '15:47:00',
|
|
157
|
+
timestamp: '2023-03-06 15:47:00',
|
|
158
|
+
timestamptz: '2023-03-06 13:47:00Z'
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
expect(transformed[3]).toMatchObject({
|
|
162
|
+
id: 4n,
|
|
163
|
+
pg_lsn: '00000016/B374D848',
|
|
164
|
+
interval: '01:00:00',
|
|
165
|
+
macaddr: '00:00:5e:00:53:af',
|
|
166
|
+
inet: '127.0.0.1',
|
|
167
|
+
oid: 1007n
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
expect(transformed[4]).toMatchObject({
|
|
171
|
+
id: 5n,
|
|
172
|
+
date: '0000-01-01',
|
|
173
|
+
time: '00:00:00',
|
|
174
|
+
timestamp: '0000-01-01 00:00:00',
|
|
175
|
+
timestamptz: '0000-01-01 00:00:00Z'
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
expect(transformed[5]).toMatchObject({
|
|
179
|
+
id: 6n,
|
|
180
|
+
timestamp: '1970-01-01 00:00:00',
|
|
181
|
+
timestamptz: '1970-01-01 00:00:00Z'
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
expect(transformed[6]).toMatchObject({
|
|
185
|
+
id: 7n,
|
|
186
|
+
timestamp: '9999-12-31 23:59:59',
|
|
187
|
+
timestamptz: '9999-12-31 23:59:59Z'
|
|
188
|
+
});
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
function checkResultArrays(transformed: Record<string, any>[]) {
|
|
192
|
+
expect(transformed[0]).toMatchObject({
|
|
193
|
+
id: 1n,
|
|
194
|
+
text: `["text","}te][xt{\\""]`,
|
|
195
|
+
uuid: '["baeb2514-4c57-436d-b3cc-c1256211656d"]',
|
|
196
|
+
varchar: '["varchar"]',
|
|
197
|
+
bool: '[1]',
|
|
198
|
+
bytea: '[null]',
|
|
199
|
+
int2: '[1000]',
|
|
200
|
+
int4: '[1000000]',
|
|
201
|
+
int8: `[9007199254740993]`,
|
|
202
|
+
numeric: `["18014398509481982123"]`
|
|
203
|
+
});
|
|
204
|
+
|
|
205
|
+
// Note: Depending on to what extent we use the original postgres value, the whitespace may change, and order may change.
|
|
206
|
+
// We do expect that decimals and big numbers are preserved.
|
|
207
|
+
expect(transformed[1]).toMatchObject({
|
|
208
|
+
id: 2n,
|
|
209
|
+
// Expected output after a serialize + parse cycle:
|
|
210
|
+
// json: `[{"test":"thing"},{"test":"}te][xt{"}]`,
|
|
211
|
+
// jsonb: `[{"foo":5.0,"bool":true,"test":"thing","bignum":18014398509481982123}]`
|
|
212
|
+
// Expected using direct PG values:
|
|
213
|
+
json: `[{"test": "thing"},{"test": "}te][xt{"}]`,
|
|
214
|
+
jsonb: `[{"foo": 5.0, "bool": true, "test": "thing", "bignum": 18014398509481982123}]`
|
|
215
|
+
});
|
|
216
|
+
|
|
217
|
+
expect(transformed[2]).toMatchObject({
|
|
218
|
+
id: 3n,
|
|
219
|
+
date: `["2023-03-06"]`,
|
|
220
|
+
time: `["15:47:00"]`,
|
|
221
|
+
timestamp: `["2023-03-06 15:47:00"]`,
|
|
222
|
+
timestamptz: `["2023-03-06 13:47:00Z","2023-03-06 13:47:00.12345Z"]`
|
|
223
|
+
});
|
|
224
|
+
|
|
225
|
+
expect(transformed[3]).toMatchObject({
|
|
226
|
+
id: 4n,
|
|
227
|
+
pg_lsn: `["00000016/B374D848"]`,
|
|
228
|
+
interval: `["01:00:00"]`,
|
|
229
|
+
macaddr: `["00:00:5e:00:53:af"]`,
|
|
230
|
+
inet: `["127.0.0.1"]`,
|
|
231
|
+
oid: `[1007]`
|
|
232
|
+
});
|
|
233
|
+
|
|
234
|
+
expect(transformed[4]).toMatchObject({
|
|
235
|
+
id: 5n,
|
|
236
|
+
text: '[]',
|
|
237
|
+
uuid: '[]',
|
|
238
|
+
varchar: '[]',
|
|
239
|
+
bool: '[]',
|
|
240
|
+
bytea: '[]',
|
|
241
|
+
int2: '[]',
|
|
242
|
+
int4: '[]',
|
|
243
|
+
int8: '[]',
|
|
244
|
+
numeric: '[]'
|
|
245
|
+
});
|
|
246
|
+
|
|
247
|
+
expect(transformed[5]).toMatchObject({
|
|
248
|
+
id: 6n,
|
|
249
|
+
multidimensional: '[["one","1"],["two","2"],["three",null]]'
|
|
250
|
+
});
|
|
251
|
+
|
|
252
|
+
expect(transformed[6]).toMatchObject({
|
|
253
|
+
id: 7n,
|
|
254
|
+
multidimensional: '[]'
|
|
255
|
+
});
|
|
256
|
+
|
|
257
|
+
expect(transformed[7]).toMatchObject({
|
|
258
|
+
id: 8n,
|
|
259
|
+
multidimensional: '[]'
|
|
260
|
+
});
|
|
261
|
+
|
|
262
|
+
expect(transformed[8]).toMatchObject({
|
|
263
|
+
id: 9n,
|
|
264
|
+
multidimensional: '[null]'
|
|
265
|
+
});
|
|
266
|
+
|
|
267
|
+
expect(transformed[9]).toMatchObject({
|
|
268
|
+
id: 10n,
|
|
269
|
+
multidimensional: '["null"]'
|
|
270
|
+
});
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
test('test direct queries', async () => {
|
|
274
|
+
const db = await connectPgPool();
|
|
275
|
+
try {
|
|
276
|
+
await setupTable(db);
|
|
277
|
+
|
|
278
|
+
await insert(db);
|
|
279
|
+
|
|
280
|
+
const transformed = [
|
|
281
|
+
...WalStream.getQueryData(pgwire.pgwireRows(await db.query(`SELECT * FROM test_data ORDER BY id`)))
|
|
282
|
+
];
|
|
283
|
+
|
|
284
|
+
checkResults(transformed);
|
|
285
|
+
} finally {
|
|
286
|
+
await db.end();
|
|
287
|
+
}
|
|
288
|
+
});
|
|
289
|
+
|
|
290
|
+
test('test direct queries - parameterized', async () => {
|
|
291
|
+
// Parameterized queries may use a different underlying protocol,
|
|
292
|
+
// so we make sure it also gets the same results.
|
|
293
|
+
const db = await connectPgPool();
|
|
294
|
+
try {
|
|
295
|
+
await setupTable(db);
|
|
296
|
+
|
|
297
|
+
await insert(db);
|
|
298
|
+
|
|
299
|
+
const transformed = [
|
|
300
|
+
...WalStream.getQueryData(
|
|
301
|
+
pgwire.pgwireRows(
|
|
302
|
+
await db.query({
|
|
303
|
+
statement: `SELECT * FROM test_data WHERE $1 ORDER BY id`,
|
|
304
|
+
params: [{ type: 'bool', value: true }]
|
|
305
|
+
})
|
|
306
|
+
)
|
|
307
|
+
)
|
|
308
|
+
];
|
|
309
|
+
|
|
310
|
+
checkResults(transformed);
|
|
311
|
+
} finally {
|
|
312
|
+
await db.end();
|
|
313
|
+
}
|
|
314
|
+
});
|
|
315
|
+
|
|
316
|
+
test('test direct queries - arrays', async () => {
|
|
317
|
+
const db = await connectPgPool();
|
|
318
|
+
try {
|
|
319
|
+
await setupTable(db);
|
|
320
|
+
|
|
321
|
+
await insertArrays(db);
|
|
322
|
+
|
|
323
|
+
const transformed = [
|
|
324
|
+
...WalStream.getQueryData(pgwire.pgwireRows(await db.query(`SELECT * FROM test_data_arrays ORDER BY id`)))
|
|
325
|
+
];
|
|
326
|
+
|
|
327
|
+
checkResultArrays(transformed);
|
|
328
|
+
} finally {
|
|
329
|
+
await db.end();
|
|
330
|
+
}
|
|
331
|
+
});
|
|
332
|
+
|
|
333
|
+
test('test replication', async () => {
|
|
334
|
+
const db = await connectPgPool();
|
|
335
|
+
try {
|
|
336
|
+
await setupTable(db);
|
|
337
|
+
|
|
338
|
+
const slotName = 'test_slot';
|
|
339
|
+
|
|
340
|
+
await db.query({
|
|
341
|
+
statement: 'SELECT pg_drop_replication_slot(slot_name) FROM pg_replication_slots WHERE slot_name = $1',
|
|
342
|
+
params: [{ type: 'varchar', value: slotName }]
|
|
343
|
+
});
|
|
344
|
+
|
|
345
|
+
await db.query({
|
|
346
|
+
statement: `SELECT slot_name, lsn FROM pg_catalog.pg_create_logical_replication_slot($1, 'pgoutput')`,
|
|
347
|
+
params: [{ type: 'varchar', value: slotName }]
|
|
348
|
+
});
|
|
349
|
+
|
|
350
|
+
await insert(db);
|
|
351
|
+
|
|
352
|
+
const pg: pgwire.PgConnection = await pgwire.pgconnect({ replication: 'database' }, TEST_URI);
|
|
353
|
+
const replicationStream = await pg.logicalReplication({
|
|
354
|
+
slot: slotName,
|
|
355
|
+
options: {
|
|
356
|
+
proto_version: '1',
|
|
357
|
+
publication_names: 'powersync'
|
|
358
|
+
}
|
|
359
|
+
});
|
|
360
|
+
|
|
361
|
+
const transformed = await getReplicationTx(replicationStream);
|
|
362
|
+
await pg.end();
|
|
363
|
+
|
|
364
|
+
checkResults(transformed);
|
|
365
|
+
} finally {
|
|
366
|
+
await db.end();
|
|
367
|
+
}
|
|
368
|
+
});
|
|
369
|
+
|
|
370
|
+
test('test replication - arrays', async () => {
|
|
371
|
+
const db = await connectPgPool();
|
|
372
|
+
try {
|
|
373
|
+
await setupTable(db);
|
|
374
|
+
|
|
375
|
+
const slotName = 'test_slot';
|
|
376
|
+
|
|
377
|
+
await db.query({
|
|
378
|
+
statement: 'SELECT pg_drop_replication_slot(slot_name) FROM pg_replication_slots WHERE slot_name = $1',
|
|
379
|
+
params: [{ type: 'varchar', value: slotName }]
|
|
380
|
+
});
|
|
381
|
+
|
|
382
|
+
await db.query({
|
|
383
|
+
statement: `SELECT slot_name, lsn FROM pg_catalog.pg_create_logical_replication_slot($1, 'pgoutput')`,
|
|
384
|
+
params: [{ type: 'varchar', value: slotName }]
|
|
385
|
+
});
|
|
386
|
+
|
|
387
|
+
await insertArrays(db);
|
|
388
|
+
|
|
389
|
+
const pg: pgwire.PgConnection = await pgwire.pgconnect({ replication: 'database' }, TEST_URI);
|
|
390
|
+
const replicationStream = await pg.logicalReplication({
|
|
391
|
+
slot: slotName,
|
|
392
|
+
options: {
|
|
393
|
+
proto_version: '1',
|
|
394
|
+
publication_names: 'powersync'
|
|
395
|
+
}
|
|
396
|
+
});
|
|
397
|
+
|
|
398
|
+
const transformed = await getReplicationTx(replicationStream);
|
|
399
|
+
await pg.end();
|
|
400
|
+
|
|
401
|
+
checkResultArrays(transformed);
|
|
402
|
+
} finally {
|
|
403
|
+
await db.end();
|
|
404
|
+
}
|
|
405
|
+
});
|
|
406
|
+
|
|
407
|
+
test('schema', async function () {
|
|
408
|
+
const db = await connectPgWire();
|
|
409
|
+
|
|
410
|
+
await setupTable(db);
|
|
411
|
+
|
|
412
|
+
const schema = await getConnectionSchema(db);
|
|
413
|
+
expect(schema).toMatchSnapshot();
|
|
414
|
+
});
|
|
415
|
+
});
|
|
416
|
+
|
|
417
|
+
/**
|
|
418
|
+
* Return all the inserts from the first transaction in the replication stream.
|
|
419
|
+
*/
|
|
420
|
+
async function getReplicationTx(replicationStream: pgwire.ReplicationStream) {
|
|
421
|
+
let transformed: SqliteRow[] = [];
|
|
422
|
+
for await (const batch of replicationStream.pgoutputDecode()) {
|
|
423
|
+
for (const msg of batch.messages) {
|
|
424
|
+
if (msg.tag == 'insert') {
|
|
425
|
+
transformed.push(constructAfterRecord(msg));
|
|
426
|
+
} else if (msg.tag == 'commit') {
|
|
427
|
+
return transformed;
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
return transformed;
|
|
432
|
+
}
|