@powersync/service-core 0.0.0-dev-20240620165206
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 +82 -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 +25 -0
- package/dist/index.js +28 -0
- package/dist/index.js.map +1 -0
- package/dist/locks/LockManager.d.ts +10 -0
- package/dist/locks/LockManager.js +7 -0
- package/dist/locks/LockManager.js.map +1 -0
- package/dist/locks/MongoLocks.d.ts +36 -0
- package/dist/locks/MongoLocks.js +81 -0
- package/dist/locks/MongoLocks.js.map +1 -0
- package/dist/locks/locks-index.d.ts +2 -0
- package/dist/locks/locks-index.js +3 -0
- package/dist/locks/locks-index.js.map +1 -0
- package/dist/metrics/Metrics.d.ts +30 -0
- package/dist/metrics/Metrics.js +176 -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/definitions.d.ts +18 -0
- package/dist/migrations/definitions.js +6 -0
- package/dist/migrations/definitions.js.map +1 -0
- package/dist/migrations/executor.d.ts +16 -0
- package/dist/migrations/executor.js +64 -0
- package/dist/migrations/executor.js.map +1 -0
- package/dist/migrations/migrations-index.d.ts +3 -0
- package/dist/migrations/migrations-index.js +4 -0
- package/dist/migrations/migrations-index.js.map +1 -0
- package/dist/migrations/migrations.d.ts +10 -0
- package/dist/migrations/migrations.js +90 -0
- package/dist/migrations/migrations.js.map +1 -0
- package/dist/migrations/store/migration-store.d.ts +11 -0
- package/dist/migrations/store/migration-store.js +46 -0
- package/dist/migrations/store/migration-store.js.map +1 -0
- package/dist/replication/ErrorRateLimiter.d.ts +17 -0
- package/dist/replication/ErrorRateLimiter.js +43 -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 +57 -0
- package/dist/replication/WalStream.js +515 -0
- package/dist/replication/WalStream.js.map +1 -0
- package/dist/replication/WalStreamManager.d.ts +30 -0
- package/dist/replication/WalStreamManager.js +198 -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/auth.d.ts +56 -0
- package/dist/routes/auth.js +182 -0
- package/dist/routes/auth.js.map +1 -0
- package/dist/routes/endpoints/admin.d.ts +1011 -0
- package/dist/routes/endpoints/admin.js +207 -0
- package/dist/routes/endpoints/admin.js.map +1 -0
- package/dist/routes/endpoints/checkpointing.d.ts +76 -0
- package/dist/routes/endpoints/checkpointing.js +36 -0
- package/dist/routes/endpoints/checkpointing.js.map +1 -0
- package/dist/routes/endpoints/dev.d.ts +312 -0
- package/dist/routes/endpoints/dev.js +172 -0
- package/dist/routes/endpoints/dev.js.map +1 -0
- package/dist/routes/endpoints/route-endpoints-index.d.ts +6 -0
- package/dist/routes/endpoints/route-endpoints-index.js +7 -0
- package/dist/routes/endpoints/route-endpoints-index.js.map +1 -0
- package/dist/routes/endpoints/socket-route.d.ts +2 -0
- package/dist/routes/endpoints/socket-route.js +119 -0
- package/dist/routes/endpoints/socket-route.js.map +1 -0
- package/dist/routes/endpoints/sync-rules.d.ts +174 -0
- package/dist/routes/endpoints/sync-rules.js +202 -0
- package/dist/routes/endpoints/sync-rules.js.map +1 -0
- package/dist/routes/endpoints/sync-stream.d.ts +132 -0
- package/dist/routes/endpoints/sync-stream.js +83 -0
- package/dist/routes/endpoints/sync-stream.js.map +1 -0
- package/dist/routes/hooks.d.ts +10 -0
- package/dist/routes/hooks.js +32 -0
- package/dist/routes/hooks.js.map +1 -0
- package/dist/routes/route-register.d.ts +10 -0
- package/dist/routes/route-register.js +87 -0
- package/dist/routes/route-register.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 +26 -0
- package/dist/routes/router.js +7 -0
- package/dist/routes/router.js.map +1 -0
- package/dist/routes/routes-index.d.ts +6 -0
- package/dist/routes/routes-index.js +7 -0
- package/dist/routes/routes-index.js.map +1 -0
- package/dist/runner/teardown.d.ts +2 -0
- package/dist/runner/teardown.js +94 -0
- package/dist/runner/teardown.js.map +1 -0
- package/dist/storage/BucketStorage.d.ts +307 -0
- package/dist/storage/BucketStorage.js +25 -0
- package/dist/storage/BucketStorage.js.map +1 -0
- package/dist/storage/ChecksumCache.d.ts +50 -0
- package/dist/storage/ChecksumCache.js +234 -0
- package/dist/storage/ChecksumCache.js.map +1 -0
- package/dist/storage/MongoBucketStorage.d.ts +52 -0
- package/dist/storage/MongoBucketStorage.js +409 -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 +581 -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 +29 -0
- package/dist/storage/mongo/MongoSyncBucketStorage.js +391 -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 +46 -0
- package/dist/storage/mongo/PersistedBatch.js +213 -0
- package/dist/storage/mongo/PersistedBatch.js.map +1 -0
- package/dist/storage/mongo/db.d.ts +26 -0
- package/dist/storage/mongo/db.js +35 -0
- package/dist/storage/mongo/db.js.map +1 -0
- package/dist/storage/mongo/models.d.ts +140 -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 +259 -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 +23 -0
- package/dist/system/CorePowerSyncSystem.js +52 -0
- package/dist/system/CorePowerSyncSystem.js.map +1 -0
- package/dist/system/system-index.d.ts +1 -0
- package/dist/system/system-index.js +2 -0
- package/dist/system/system-index.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 +2 -0
- package/dist/util/alerting.js +8 -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 +37 -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 +130 -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 +57 -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 +9 -0
- package/dist/util/env.js +26 -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 +182 -0
- package/dist/util/protocol-types.js +42 -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 +17 -0
- package/dist/util/utils.js +92 -0
- package/dist/util/utils.js.map +1 -0
- package/package.json +59 -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 +40 -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 +40 -0
- package/src/locks/LockManager.ts +16 -0
- package/src/locks/MongoLocks.ts +142 -0
- package/src/locks/locks-index.ts +2 -0
- package/src/metrics/Metrics.ts +265 -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/definitions.ts +21 -0
- package/src/migrations/executor.ts +87 -0
- package/src/migrations/migrations-index.ts +3 -0
- package/src/migrations/migrations.ts +118 -0
- package/src/migrations/store/migration-store.ts +63 -0
- package/src/replication/ErrorRateLimiter.ts +50 -0
- package/src/replication/PgRelation.ts +42 -0
- package/src/replication/WalConnection.ts +227 -0
- package/src/replication/WalStream.ts +624 -0
- package/src/replication/WalStreamManager.ts +213 -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/auth.ts +215 -0
- package/src/routes/endpoints/admin.ts +237 -0
- package/src/routes/endpoints/checkpointing.ts +41 -0
- package/src/routes/endpoints/dev.ts +199 -0
- package/src/routes/endpoints/route-endpoints-index.ts +6 -0
- package/src/routes/endpoints/socket-route.ts +135 -0
- package/src/routes/endpoints/sync-rules.ts +227 -0
- package/src/routes/endpoints/sync-stream.ts +101 -0
- package/src/routes/hooks.ts +46 -0
- package/src/routes/route-register.ts +104 -0
- package/src/routes/router-socket.ts +13 -0
- package/src/routes/router.ts +46 -0
- package/src/routes/routes-index.ts +6 -0
- package/src/runner/teardown.ts +108 -0
- package/src/storage/BucketStorage.ts +396 -0
- package/src/storage/ChecksumCache.ts +294 -0
- package/src/storage/MongoBucketStorage.ts +519 -0
- package/src/storage/SourceTable.ts +60 -0
- package/src/storage/mongo/MongoBucketBatch.ts +752 -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 +533 -0
- package/src/storage/mongo/MongoSyncRulesLock.ts +81 -0
- package/src/storage/mongo/OperationBatch.ts +115 -0
- package/src/storage/mongo/PersistedBatch.ts +268 -0
- package/src/storage/mongo/db.ts +73 -0
- package/src/storage/mongo/models.ts +162 -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 +319 -0
- package/src/sync/util.ts +98 -0
- package/src/system/CorePowerSyncSystem.ts +64 -0
- package/src/system/system-index.ts +1 -0
- package/src/util/Mutex.ts +159 -0
- package/src/util/PgManager.ts +64 -0
- package/src/util/alerting.ts +9 -0
- package/src/util/config/collectors/config-collector.ts +143 -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 +43 -0
- package/src/util/config/compound-config-collector.ts +176 -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 +66 -0
- package/src/util/config.ts +39 -0
- package/src/util/env.ts +30 -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 +228 -0
- package/src/util/secs.ts +54 -0
- package/src/util/util-index.ts +25 -0
- package/src/util/utils.ts +122 -0
- package/test/src/__snapshots__/pg_test.test.ts.snap +256 -0
- package/test/src/__snapshots__/sync.test.ts.snap +247 -0
- package/test/src/auth.test.ts +342 -0
- package/test/src/broadcast_iterable.test.ts +156 -0
- package/test/src/checksum_cache.test.ts +436 -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 +450 -0
- package/test/src/schema_changes.test.ts +545 -0
- package/test/src/setup.ts +7 -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 +1053 -0
- package/test/src/util.ts +76 -0
- package/test/src/validation.test.ts +63 -0
- package/test/src/wal_stream.test.ts +319 -0
- package/test/src/wal_stream_utils.ts +147 -0
- package/test/tsconfig.json +20 -0
- package/tsconfig.json +31 -0
- package/tsconfig.tsbuildinfo +1 -0
- package/vitest.config.ts +9 -0
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export * as auth from './auth.js';
|
|
2
|
+
export * as endpoints from './endpoints/route-endpoints-index.js';
|
|
3
|
+
export * as hooks from './hooks.js';
|
|
4
|
+
export * from './route-register.js';
|
|
5
|
+
export * from './router-socket.js';
|
|
6
|
+
export * from './router.js';
|
|
7
|
+
//# sourceMappingURL=routes-index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"routes-index.js","sourceRoot":"","sources":["../../src/routes/routes-index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAClC,OAAO,KAAK,SAAS,MAAM,sCAAsC,CAAC;AAClE,OAAO,KAAK,KAAK,MAAM,YAAY,CAAC;AACpC,cAAc,qBAAqB,CAAC;AACpC,cAAc,oBAAoB,CAAC;AACnC,cAAc,aAAa,CAAC"}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
// Script to tear down the data when deleting an instance.
|
|
2
|
+
// This deletes:
|
|
3
|
+
// 1. The replication slots on the source postgres instance (if available).
|
|
4
|
+
// 2. The mongo database.
|
|
5
|
+
import * as timers from 'timers/promises';
|
|
6
|
+
import * as db from '../db/db-index.js';
|
|
7
|
+
import * as storage from '../storage/storage-index.js';
|
|
8
|
+
import * as utils from '../util/util-index.js';
|
|
9
|
+
import * as replication from '../replication/replication-index.js';
|
|
10
|
+
import { logger } from '@powersync/lib-services-framework';
|
|
11
|
+
/**
|
|
12
|
+
* Attempt to terminate a single sync rules instance.
|
|
13
|
+
*
|
|
14
|
+
* This may fail with a lock error.
|
|
15
|
+
*/
|
|
16
|
+
async function terminateReplicator(storageFactory, connection, syncRules) {
|
|
17
|
+
// The lock may still be active if the current replication instance
|
|
18
|
+
// hasn't stopped yet.
|
|
19
|
+
const lock = await syncRules.lock();
|
|
20
|
+
try {
|
|
21
|
+
const parsed = syncRules.parsed();
|
|
22
|
+
const storage = storageFactory.getInstance(parsed);
|
|
23
|
+
const stream = new replication.WalStreamRunner({
|
|
24
|
+
factory: storageFactory,
|
|
25
|
+
storage: storage,
|
|
26
|
+
source_db: connection,
|
|
27
|
+
lock
|
|
28
|
+
});
|
|
29
|
+
logger.info(`Terminating replication slot ${stream.slot_name}`);
|
|
30
|
+
await stream.terminate();
|
|
31
|
+
logger.info(`Terminated replication slot ${stream.slot_name}`);
|
|
32
|
+
}
|
|
33
|
+
finally {
|
|
34
|
+
await lock.release();
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Terminate all replicating sync rules, deleting the replication slots.
|
|
39
|
+
*
|
|
40
|
+
* Retries lock and other errors for up to two minutes.
|
|
41
|
+
*
|
|
42
|
+
* This is a best-effot attempt. In some cases it may not be possible to delete the replication
|
|
43
|
+
* slot, such as when the postgres instance is unreachable.
|
|
44
|
+
*/
|
|
45
|
+
async function terminateReplicators(storageFactory, connection) {
|
|
46
|
+
const start = Date.now();
|
|
47
|
+
while (Date.now() - start < 12000) {
|
|
48
|
+
let retry = false;
|
|
49
|
+
const replicationRules = await storageFactory.getReplicatingSyncRules();
|
|
50
|
+
for (let syncRules of replicationRules) {
|
|
51
|
+
try {
|
|
52
|
+
await terminateReplicator(storageFactory, connection, syncRules);
|
|
53
|
+
}
|
|
54
|
+
catch (e) {
|
|
55
|
+
retry = true;
|
|
56
|
+
console.error(e);
|
|
57
|
+
logger.warn(`Failed to terminate ${syncRules.slot_name}`, e);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
if (!retry) {
|
|
61
|
+
break;
|
|
62
|
+
}
|
|
63
|
+
await timers.setTimeout(5000);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
export async function teardown(runnerConfig) {
|
|
67
|
+
const config = await utils.loadConfig(runnerConfig);
|
|
68
|
+
const mongoDB = storage.createPowerSyncMongo(config.storage);
|
|
69
|
+
try {
|
|
70
|
+
logger.info(`Waiting for auth`);
|
|
71
|
+
await db.mongo.waitForAuth(mongoDB.db);
|
|
72
|
+
const bucketStorage = new storage.MongoBucketStorage(mongoDB, { slot_name_prefix: config.slot_name_prefix });
|
|
73
|
+
const connection = config.connection;
|
|
74
|
+
logger.info(`Terminating replication slots`);
|
|
75
|
+
if (connection) {
|
|
76
|
+
await terminateReplicators(bucketStorage, connection);
|
|
77
|
+
}
|
|
78
|
+
const database = mongoDB.db;
|
|
79
|
+
logger.info(`Dropping database ${database.namespace}`);
|
|
80
|
+
await database.dropDatabase();
|
|
81
|
+
logger.info(`Done`);
|
|
82
|
+
await mongoDB.client.close();
|
|
83
|
+
// If there was an error connecting to postgress, the process may stay open indefinitely.
|
|
84
|
+
// This forces an exit.
|
|
85
|
+
// We do not consider those errors a teardown failure.
|
|
86
|
+
process.exit(0);
|
|
87
|
+
}
|
|
88
|
+
catch (e) {
|
|
89
|
+
logger.error(`Teardown failure`, e);
|
|
90
|
+
await mongoDB.client.close();
|
|
91
|
+
process.exit(1);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
//# sourceMappingURL=teardown.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"teardown.js","sourceRoot":"","sources":["../../src/runner/teardown.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1,307 @@
|
|
|
1
|
+
/// <reference types="node" resolution-mode="require"/>
|
|
2
|
+
import { EvaluatedParameters, EvaluatedRow, SqlSyncRules, SqliteJsonRow, SqliteJsonValue, SqliteRow, ToastableSqliteRow } from '@powersync/service-sync-rules';
|
|
3
|
+
import * as replication from '../replication/replication-index.js';
|
|
4
|
+
import * as util from '../util/util-index.js';
|
|
5
|
+
import { SourceTable } from './SourceTable.js';
|
|
6
|
+
export interface BucketStorageFactory {
|
|
7
|
+
/**
|
|
8
|
+
* Update sync rules from configuration, if changed.
|
|
9
|
+
*/
|
|
10
|
+
configureSyncRules(sync_rules: string, options?: {
|
|
11
|
+
lock?: boolean;
|
|
12
|
+
}): Promise<{
|
|
13
|
+
updated: boolean;
|
|
14
|
+
persisted_sync_rules?: PersistedSyncRulesContent;
|
|
15
|
+
lock?: ReplicationLock;
|
|
16
|
+
}>;
|
|
17
|
+
/**
|
|
18
|
+
* Get a storage instance to query sync data for specific sync rules.
|
|
19
|
+
*/
|
|
20
|
+
getInstance(options: PersistedSyncRules): SyncRulesBucketStorage;
|
|
21
|
+
/**
|
|
22
|
+
* Deploy new sync rules.
|
|
23
|
+
*/
|
|
24
|
+
updateSyncRules(options: UpdateSyncRulesOptions): Promise<PersistedSyncRulesContent>;
|
|
25
|
+
/**
|
|
26
|
+
* Indicate that a slot was removed, and we should re-sync by creating
|
|
27
|
+
* a new sync rules instance.
|
|
28
|
+
*
|
|
29
|
+
* This is roughly the same as deploying a new version of the current sync
|
|
30
|
+
* rules, but also accounts for cases where the current sync rules are not
|
|
31
|
+
* the latest ones.
|
|
32
|
+
*
|
|
33
|
+
* Replication should be restarted after this.
|
|
34
|
+
*
|
|
35
|
+
* @param slot_name The removed slot
|
|
36
|
+
*/
|
|
37
|
+
slotRemoved(slot_name: string): Promise<void>;
|
|
38
|
+
/**
|
|
39
|
+
* Get the sync rules used for querying.
|
|
40
|
+
*/
|
|
41
|
+
getActiveSyncRules(): Promise<PersistedSyncRules | null>;
|
|
42
|
+
/**
|
|
43
|
+
* Get the sync rules used for querying.
|
|
44
|
+
*/
|
|
45
|
+
getActiveSyncRulesContent(): Promise<PersistedSyncRulesContent | null>;
|
|
46
|
+
/**
|
|
47
|
+
* Get the sync rules that will be active next once done with initial replicatino.
|
|
48
|
+
*/
|
|
49
|
+
getNextSyncRules(): Promise<PersistedSyncRules | null>;
|
|
50
|
+
/**
|
|
51
|
+
* Get the sync rules that will be active next once done with initial replicatino.
|
|
52
|
+
*/
|
|
53
|
+
getNextSyncRulesContent(): Promise<PersistedSyncRulesContent | null>;
|
|
54
|
+
/**
|
|
55
|
+
* Get all sync rules currently replicating. Typically this is the "active" and "next" sync rules.
|
|
56
|
+
*/
|
|
57
|
+
getReplicatingSyncRules(): Promise<PersistedSyncRulesContent[]>;
|
|
58
|
+
/**
|
|
59
|
+
* Get all sync rules stopped but not terminated yet.
|
|
60
|
+
*/
|
|
61
|
+
getStoppedSyncRules(): Promise<PersistedSyncRulesContent[]>;
|
|
62
|
+
/**
|
|
63
|
+
* Same as:
|
|
64
|
+
* getInstance(await getActiveSyncRules()).getCheckpoint().
|
|
65
|
+
*/
|
|
66
|
+
getActiveCheckpoint(): Promise<ActiveCheckpoint>;
|
|
67
|
+
createWriteCheckpoint(user_id: string, lsns: Record<string, string>): Promise<bigint>;
|
|
68
|
+
lastWriteCheckpoint(user_id: string, lsn: string): Promise<bigint | null>;
|
|
69
|
+
watchWriteCheckpoint(user_id: string, signal: AbortSignal): AsyncIterable<WriteCheckpoint>;
|
|
70
|
+
/**
|
|
71
|
+
* Get storage size of active sync rules.
|
|
72
|
+
*/
|
|
73
|
+
getStorageMetrics(): Promise<StorageMetrics>;
|
|
74
|
+
/**
|
|
75
|
+
* Get the unique identifier for this instance of Powersync
|
|
76
|
+
*/
|
|
77
|
+
getPowerSyncInstanceId(): Promise<string>;
|
|
78
|
+
}
|
|
79
|
+
export interface WriteCheckpoint {
|
|
80
|
+
base: ActiveCheckpoint;
|
|
81
|
+
writeCheckpoint: bigint | null;
|
|
82
|
+
}
|
|
83
|
+
export interface ActiveCheckpoint {
|
|
84
|
+
readonly checkpoint: util.OpId;
|
|
85
|
+
readonly lsn: string;
|
|
86
|
+
hasSyncRules(): boolean;
|
|
87
|
+
getBucketStorage(): Promise<SyncRulesBucketStorage | null>;
|
|
88
|
+
}
|
|
89
|
+
export interface StorageMetrics {
|
|
90
|
+
/**
|
|
91
|
+
* Size of operations (bucket_data)
|
|
92
|
+
*/
|
|
93
|
+
operations_size_bytes: number;
|
|
94
|
+
/**
|
|
95
|
+
* Size of parameter storage.
|
|
96
|
+
*
|
|
97
|
+
* Replication storage -> raw data as received from Postgres.
|
|
98
|
+
*/
|
|
99
|
+
parameters_size_bytes: number;
|
|
100
|
+
/**
|
|
101
|
+
* Size of current_data.
|
|
102
|
+
*/
|
|
103
|
+
replication_size_bytes: number;
|
|
104
|
+
}
|
|
105
|
+
export interface PersistedSyncRulesContent {
|
|
106
|
+
readonly id: number;
|
|
107
|
+
readonly sync_rules_content: string;
|
|
108
|
+
readonly slot_name: string;
|
|
109
|
+
readonly last_fatal_error?: string | null;
|
|
110
|
+
readonly last_keepalive_ts?: Date | null;
|
|
111
|
+
readonly last_checkpoint_ts?: Date | null;
|
|
112
|
+
parsed(): PersistedSyncRules;
|
|
113
|
+
lock(): Promise<ReplicationLock>;
|
|
114
|
+
}
|
|
115
|
+
export interface ReplicationLock {
|
|
116
|
+
sync_rules_id: number;
|
|
117
|
+
release(): Promise<void>;
|
|
118
|
+
}
|
|
119
|
+
export interface PersistedSyncRules {
|
|
120
|
+
readonly id: number;
|
|
121
|
+
readonly sync_rules: SqlSyncRules;
|
|
122
|
+
readonly slot_name: string;
|
|
123
|
+
}
|
|
124
|
+
export declare class DefaultPersistedSyncRules implements PersistedSyncRules {
|
|
125
|
+
readonly id: number;
|
|
126
|
+
readonly sync_rules: SqlSyncRules;
|
|
127
|
+
readonly checkpoint_lsn: string | null;
|
|
128
|
+
constructor(id: number, sync_rules: SqlSyncRules, checkpoint_lsn: string | null);
|
|
129
|
+
get slot_name(): string;
|
|
130
|
+
}
|
|
131
|
+
export interface UpdateSyncRulesOptions {
|
|
132
|
+
content: string;
|
|
133
|
+
lock?: boolean;
|
|
134
|
+
}
|
|
135
|
+
export interface SyncRulesBucketStorageOptions {
|
|
136
|
+
sync_rules: SqlSyncRules;
|
|
137
|
+
group_id: number;
|
|
138
|
+
}
|
|
139
|
+
export declare const DEFAULT_DOCUMENT_BATCH_LIMIT = 1000;
|
|
140
|
+
export declare const DEFAULT_DOCUMENT_CHUNK_LIMIT_BYTES: number;
|
|
141
|
+
export interface BucketDataBatchOptions {
|
|
142
|
+
/** Limit number of documents returned. Defaults to 1000. */
|
|
143
|
+
limit?: number;
|
|
144
|
+
/**
|
|
145
|
+
* Limit size of chunks returned. Defaults to 1MB.
|
|
146
|
+
*
|
|
147
|
+
* This is a lower bound, not an upper bound. As soon as the chunk size goes over this limit,
|
|
148
|
+
* it is returned.
|
|
149
|
+
*
|
|
150
|
+
* Note that an individual data row can be close to 16MB in size, so this does not help in
|
|
151
|
+
* extreme cases.
|
|
152
|
+
*/
|
|
153
|
+
chunkLimitBytes?: number;
|
|
154
|
+
}
|
|
155
|
+
export interface SyncRulesBucketStorage {
|
|
156
|
+
readonly sync_rules: SqlSyncRules;
|
|
157
|
+
readonly group_id: number;
|
|
158
|
+
readonly slot_name: string;
|
|
159
|
+
readonly factory: BucketStorageFactory;
|
|
160
|
+
resolveTable(options: ResolveTableOptions): Promise<ResolveTableResult>;
|
|
161
|
+
startBatch(options: {}, callback: (batch: BucketStorageBatch) => Promise<void>): Promise<FlushedResult | null>;
|
|
162
|
+
getCheckpoint(): Promise<{
|
|
163
|
+
checkpoint: util.OpId;
|
|
164
|
+
lsn: string;
|
|
165
|
+
}>;
|
|
166
|
+
getParameterSets(checkpoint: util.OpId, lookups: SqliteJsonValue[][]): Promise<SqliteJsonRow[]>;
|
|
167
|
+
/**
|
|
168
|
+
* Get a "batch" of data for a checkpoint.
|
|
169
|
+
*
|
|
170
|
+
* The results will be split into separate SyncBucketData chunks to:
|
|
171
|
+
* 1. Separate buckets.
|
|
172
|
+
* 2. Limit the size of each individual chunk according to options.batchSizeLimitBytes.
|
|
173
|
+
*
|
|
174
|
+
* @param checkpoint the checkpoint
|
|
175
|
+
* @param dataBuckets current bucket states
|
|
176
|
+
* @param options batch size options
|
|
177
|
+
*/
|
|
178
|
+
getBucketDataBatch(checkpoint: util.OpId, dataBuckets: Map<string, string>, options?: BucketDataBatchOptions): AsyncIterable<util.SyncBucketData>;
|
|
179
|
+
/**
|
|
180
|
+
* Compute checksums for a given list of buckets.
|
|
181
|
+
*
|
|
182
|
+
* Returns zero checksums for any buckets not found.
|
|
183
|
+
*/
|
|
184
|
+
getChecksums(checkpoint: util.OpId, buckets: string[]): Promise<util.ChecksumMap>;
|
|
185
|
+
/**
|
|
186
|
+
* Terminate the sync rules.
|
|
187
|
+
*
|
|
188
|
+
* This clears the storage, and sets state to TERMINATED.
|
|
189
|
+
*
|
|
190
|
+
* Must only be called on stopped sync rules.
|
|
191
|
+
*/
|
|
192
|
+
terminate(): Promise<void>;
|
|
193
|
+
getStatus(): Promise<SyncRuleStatus>;
|
|
194
|
+
/**
|
|
195
|
+
* Clear the storage, without changing state.
|
|
196
|
+
*/
|
|
197
|
+
clear(): Promise<void>;
|
|
198
|
+
setSnapshotDone(lsn: string): Promise<void>;
|
|
199
|
+
autoActivate(): Promise<void>;
|
|
200
|
+
/**
|
|
201
|
+
* Record a replication error.
|
|
202
|
+
*
|
|
203
|
+
* This could be a recoverable error (e.g. temporary network failure),
|
|
204
|
+
* or a permanent error (e.g. missing toast data).
|
|
205
|
+
*
|
|
206
|
+
* Errors are cleared on commit.
|
|
207
|
+
*/
|
|
208
|
+
reportError(e: any): Promise<void>;
|
|
209
|
+
}
|
|
210
|
+
export interface SyncRuleStatus {
|
|
211
|
+
checkpoint_lsn: string | null;
|
|
212
|
+
active: boolean;
|
|
213
|
+
snapshot_done: boolean;
|
|
214
|
+
}
|
|
215
|
+
export interface ResolveTableOptions {
|
|
216
|
+
group_id: number;
|
|
217
|
+
connection_id: number;
|
|
218
|
+
connection_tag: string;
|
|
219
|
+
relation: replication.PgRelation;
|
|
220
|
+
sync_rules: SqlSyncRules;
|
|
221
|
+
}
|
|
222
|
+
export interface ResolveTableResult {
|
|
223
|
+
table: SourceTable;
|
|
224
|
+
dropTables: SourceTable[];
|
|
225
|
+
}
|
|
226
|
+
export interface FlushedResult {
|
|
227
|
+
flushed_op: string;
|
|
228
|
+
}
|
|
229
|
+
export interface BucketStorageBatch {
|
|
230
|
+
/**
|
|
231
|
+
* Save an op, and potentially flush.
|
|
232
|
+
*
|
|
233
|
+
* This can be an insert, update or delete op.
|
|
234
|
+
*/
|
|
235
|
+
save(record: SaveOptions): Promise<FlushedResult | null>;
|
|
236
|
+
/**
|
|
237
|
+
* Replicate a truncate op - deletes all data in the specified tables.
|
|
238
|
+
*/
|
|
239
|
+
truncate(sourceTables: SourceTable[]): Promise<FlushedResult | null>;
|
|
240
|
+
/**
|
|
241
|
+
* Drop one or more tables.
|
|
242
|
+
*
|
|
243
|
+
* This is the same as truncate, but additionally removes the SourceTable record.
|
|
244
|
+
*/
|
|
245
|
+
drop(sourceTables: SourceTable[]): Promise<FlushedResult | null>;
|
|
246
|
+
/**
|
|
247
|
+
* Explicitly flush all pending changes in the batch.
|
|
248
|
+
*
|
|
249
|
+
* This does not create a new checkpoint until `commit()` is called. This means it's
|
|
250
|
+
* safe to flush multiple times in the middle of a large transaction.
|
|
251
|
+
*
|
|
252
|
+
* @returns null if there are no changes to flush.
|
|
253
|
+
*/
|
|
254
|
+
flush(): Promise<FlushedResult | null>;
|
|
255
|
+
/**
|
|
256
|
+
* Flush and commit any saved ops. This creates a new checkpoint.
|
|
257
|
+
*
|
|
258
|
+
* Only call this after a transaction.
|
|
259
|
+
*/
|
|
260
|
+
commit(lsn: string): Promise<boolean>;
|
|
261
|
+
/**
|
|
262
|
+
* Advance the checkpoint LSN position, without any associated op.
|
|
263
|
+
*
|
|
264
|
+
* This must only be called when not inside a transaction.
|
|
265
|
+
*
|
|
266
|
+
* @returns true if the checkpoint was advanced, false if this was a no-op
|
|
267
|
+
*/
|
|
268
|
+
keepalive(lsn: string): Promise<boolean>;
|
|
269
|
+
markSnapshotDone(tables: SourceTable[], no_checkpoint_before_lsn: string): Promise<SourceTable[]>;
|
|
270
|
+
}
|
|
271
|
+
export interface SaveParameterData {
|
|
272
|
+
sourceTable: SourceTable;
|
|
273
|
+
/** UUID */
|
|
274
|
+
sourceKey: string;
|
|
275
|
+
evaluated: EvaluatedParameters[];
|
|
276
|
+
}
|
|
277
|
+
export interface SaveBucketData {
|
|
278
|
+
sourceTable: SourceTable;
|
|
279
|
+
/** UUID */
|
|
280
|
+
sourceKey: string;
|
|
281
|
+
evaluated: EvaluatedRow[];
|
|
282
|
+
}
|
|
283
|
+
export type SaveOptions = SaveInsert | SaveUpdate | SaveDelete;
|
|
284
|
+
export interface SaveInsert {
|
|
285
|
+
tag: 'insert';
|
|
286
|
+
sourceTable: SourceTable;
|
|
287
|
+
before?: undefined;
|
|
288
|
+
after: SqliteRow;
|
|
289
|
+
}
|
|
290
|
+
export interface SaveUpdate {
|
|
291
|
+
tag: 'update';
|
|
292
|
+
sourceTable: SourceTable;
|
|
293
|
+
before?: SqliteRow;
|
|
294
|
+
/**
|
|
295
|
+
* A null value means null column.
|
|
296
|
+
*
|
|
297
|
+
* An undefined value means it's a TOAST value - must be copied from another record.
|
|
298
|
+
*/
|
|
299
|
+
after: ToastableSqliteRow;
|
|
300
|
+
}
|
|
301
|
+
export interface SaveDelete {
|
|
302
|
+
tag: 'delete';
|
|
303
|
+
sourceTable: SourceTable;
|
|
304
|
+
before: SqliteRow;
|
|
305
|
+
after?: undefined;
|
|
306
|
+
}
|
|
307
|
+
export declare function mergeToast(record: ToastableSqliteRow, persisted: ToastableSqliteRow): ToastableSqliteRow;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export class DefaultPersistedSyncRules {
|
|
2
|
+
constructor(id, sync_rules, checkpoint_lsn) {
|
|
3
|
+
this.id = id;
|
|
4
|
+
this.sync_rules = sync_rules;
|
|
5
|
+
this.checkpoint_lsn = checkpoint_lsn;
|
|
6
|
+
}
|
|
7
|
+
get slot_name() {
|
|
8
|
+
return `powersync_${this.id}`;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
export const DEFAULT_DOCUMENT_BATCH_LIMIT = 1000;
|
|
12
|
+
export const DEFAULT_DOCUMENT_CHUNK_LIMIT_BYTES = 1 * 1024 * 1024;
|
|
13
|
+
export function mergeToast(record, persisted) {
|
|
14
|
+
const newRecord = {};
|
|
15
|
+
for (let key in record) {
|
|
16
|
+
if (typeof record[key] == 'undefined') {
|
|
17
|
+
newRecord[key] = persisted[key];
|
|
18
|
+
}
|
|
19
|
+
else {
|
|
20
|
+
newRecord[key] = record[key];
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
return newRecord;
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=BucketStorage.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BucketStorage.js","sourceRoot":"","sources":["../../src/storage/BucketStorage.ts"],"names":[],"mappings":"AA+JA,MAAM,OAAO,yBAAyB;IAGpC,YAA4B,EAAU,EAAkB,UAAwB,EAAE,cAA6B;QAAnF,OAAE,GAAF,EAAE,CAAQ;QAAkB,eAAU,GAAV,UAAU,CAAc;QAC9E,IAAI,CAAC,cAAc,GAAG,cAAc,CAAC;IACvC,CAAC;IAED,IAAI,SAAS;QACX,OAAO,aAAa,IAAI,CAAC,EAAE,EAAE,CAAC;IAChC,CAAC;CACF;AAYD,MAAM,CAAC,MAAM,4BAA4B,GAAG,IAAI,CAAC;AACjD,MAAM,CAAC,MAAM,kCAAkC,GAAG,CAAC,GAAG,IAAI,GAAG,IAAI,CAAC;AA2MlE,MAAM,UAAU,UAAU,CAAC,MAA0B,EAAE,SAA6B;IAClF,MAAM,SAAS,GAAuB,EAAE,CAAC;IACzC,KAAK,IAAI,GAAG,IAAI,MAAM,EAAE;QACtB,IAAI,OAAO,MAAM,CAAC,GAAG,CAAC,IAAI,WAAW,EAAE;YACrC,SAAS,CAAC,GAAG,CAAC,GAAG,SAAS,CAAC,GAAG,CAAC,CAAC;SACjC;aAAM;YACL,SAAS,CAAC,GAAG,CAAC,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC;SAC9B;KACF;IACD,OAAO,SAAS,CAAC;AACnB,CAAC"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { BucketChecksum, OpId } from '../util/protocol-types.js';
|
|
2
|
+
import { ChecksumMap } from '../util/utils.js';
|
|
3
|
+
export interface FetchPartialBucketChecksum {
|
|
4
|
+
bucket: string;
|
|
5
|
+
start?: OpId;
|
|
6
|
+
end: OpId;
|
|
7
|
+
}
|
|
8
|
+
export type FetchChecksums = (batch: FetchPartialBucketChecksum[]) => Promise<ChecksumMap>;
|
|
9
|
+
export interface ChecksumCacheOptions {
|
|
10
|
+
/**
|
|
11
|
+
* Upstream checksum implementation.
|
|
12
|
+
*
|
|
13
|
+
* This fetches a batch of either entire bucket checksums, or a partial range.
|
|
14
|
+
*/
|
|
15
|
+
fetchChecksums: FetchChecksums;
|
|
16
|
+
/**
|
|
17
|
+
* Maximum number of cached checksums.
|
|
18
|
+
*/
|
|
19
|
+
maxSize?: number;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Implement a LRU cache for checksum requests. Each (bucket, checkpoint) request is cached separately,
|
|
23
|
+
* while the lookups occur in batches.
|
|
24
|
+
*
|
|
25
|
+
* For each bucket, we keep a separate OrderedSet of cached checkpoints.
|
|
26
|
+
* This allows us to do incrementally update checksums by using the last cached checksum for the same bucket.
|
|
27
|
+
*
|
|
28
|
+
* We use the LRUCache fetchMethod to deduplicate in-progress requests.
|
|
29
|
+
*/
|
|
30
|
+
export declare class ChecksumCache {
|
|
31
|
+
/**
|
|
32
|
+
* The primary checksum cache, with key of `${checkpoint}/${bucket}`.
|
|
33
|
+
*/
|
|
34
|
+
private cache;
|
|
35
|
+
/**
|
|
36
|
+
* For each bucket, an ordered set of cached checkpoints.
|
|
37
|
+
*/
|
|
38
|
+
private bucketCheckpoints;
|
|
39
|
+
private fetchChecksums;
|
|
40
|
+
constructor(options: ChecksumCacheOptions);
|
|
41
|
+
getChecksums(checkpoint: OpId, buckets: string[]): Promise<BucketChecksum[]>;
|
|
42
|
+
/**
|
|
43
|
+
* Get bucket checksums for a checkpoint.
|
|
44
|
+
*
|
|
45
|
+
* Any checksums not found upstream are returned as zero checksums.
|
|
46
|
+
*
|
|
47
|
+
* @returns a Map with exactly one entry for each bucket requested
|
|
48
|
+
*/
|
|
49
|
+
getChecksumMap(checkpoint: OpId, buckets: string[]): Promise<ChecksumMap>;
|
|
50
|
+
}
|