@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,61 @@
|
|
|
1
|
+
import * as jose from 'jose';
|
|
2
|
+
import { connectPgWirePool, pgwireRows } from '@powersync/service-jpgwire';
|
|
3
|
+
import { KeySpec } from './KeySpec.js';
|
|
4
|
+
import { retriedQuery } from '../util/pgwire_utils.js';
|
|
5
|
+
/**
|
|
6
|
+
* Fetches key from the Supabase database.
|
|
7
|
+
*
|
|
8
|
+
* Unfortunately, despite the JWTs containing a kid, we have no way to lookup that kid
|
|
9
|
+
* before receiving a valid token.
|
|
10
|
+
*/
|
|
11
|
+
export class SupabaseKeyCollector {
|
|
12
|
+
constructor(connection) {
|
|
13
|
+
this.keyOptions = {
|
|
14
|
+
requiresAudience: ['authenticated'],
|
|
15
|
+
maxLifetimeSeconds: 86400 * 7 + 1200 // 1 week + 20 minutes margin
|
|
16
|
+
};
|
|
17
|
+
this.pool = connectPgWirePool(connection, {
|
|
18
|
+
// To avoid overloading the source database with open connections,
|
|
19
|
+
// limit to a single connection, and close the connection shortly
|
|
20
|
+
// after using it.
|
|
21
|
+
idleTimeout: 5000,
|
|
22
|
+
maxSize: 1
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
async getKeys() {
|
|
26
|
+
let row;
|
|
27
|
+
try {
|
|
28
|
+
const rows = pgwireRows(await retriedQuery(this.pool, `SELECT current_setting('app.settings.jwt_secret') as jwt_secret`));
|
|
29
|
+
row = rows[0];
|
|
30
|
+
}
|
|
31
|
+
catch (e) {
|
|
32
|
+
if (e.message?.includes('unrecognized configuration parameter')) {
|
|
33
|
+
throw new jose.errors.JOSEError(`Generate a new JWT secret on Supabase. Cause: ${e.message}`);
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
36
|
+
throw e;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
const secret = row?.jwt_secret;
|
|
40
|
+
if (secret == null) {
|
|
41
|
+
return {
|
|
42
|
+
keys: [],
|
|
43
|
+
errors: [new jose.errors.JWKSNoMatchingKey()]
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
const key = {
|
|
48
|
+
kty: 'oct',
|
|
49
|
+
alg: 'HS256',
|
|
50
|
+
// While the secret is valid base64, the base64-encoded form is the secret value.
|
|
51
|
+
k: Buffer.from(secret, 'utf8').toString('base64url')
|
|
52
|
+
};
|
|
53
|
+
const imported = await KeySpec.importKey(key, this.keyOptions);
|
|
54
|
+
return {
|
|
55
|
+
keys: [imported],
|
|
56
|
+
errors: []
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
//# sourceMappingURL=SupabaseKeyCollector.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SupabaseKeyCollector.js","sourceRoot":"","sources":["../../src/auth/SupabaseKeyCollector.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAE7B,OAAO,EAAE,iBAAiB,EAAE,UAAU,EAAE,MAAM,4BAA4B,CAAC;AAE3E,OAAO,EAAc,OAAO,EAAE,MAAM,cAAc,CAAC;AACnD,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AAGvD;;;;;GAKG;AACH,MAAM,OAAO,oBAAoB;IAQ/B,YAAY,UAA8B;QALlC,eAAU,GAAe;YAC/B,gBAAgB,EAAE,CAAC,eAAe,CAAC;YACnC,kBAAkB,EAAE,KAAK,GAAG,CAAC,GAAG,IAAI,CAAC,6BAA6B;SACnE,CAAC;QAGA,IAAI,CAAC,IAAI,GAAG,iBAAiB,CAAC,UAAU,EAAE;YACxC,kEAAkE;YAClE,iEAAiE;YACjE,kBAAkB;YAClB,WAAW,EAAE,IAAK;YAClB,OAAO,EAAE,CAAC;SACX,CAAC,CAAC;IACL,CAAC;IAED,KAAK,CAAC,OAAO;QACX,IAAI,GAA2B,CAAC;QAChC,IAAI;YACF,MAAM,IAAI,GAAG,UAAU,CACrB,MAAM,YAAY,CAAC,IAAI,CAAC,IAAI,EAAE,iEAAiE,CAAC,CACjG,CAAC;YACF,GAAG,GAAG,IAAI,CAAC,CAAC,CAAQ,CAAC;SACtB;QAAC,OAAO,CAAC,EAAE;YACV,IAAI,CAAC,CAAC,OAAO,EAAE,QAAQ,CAAC,sCAAsC,CAAC,EAAE;gBAC/D,MAAM,IAAI,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,iDAAiD,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC;aAC/F;iBAAM;gBACL,MAAM,CAAC,CAAC;aACT;SACF;QACD,MAAM,MAAM,GAAG,GAAG,EAAE,UAAgC,CAAC;QACrD,IAAI,MAAM,IAAI,IAAI,EAAE;YAClB,OAAO;gBACL,IAAI,EAAE,EAAE;gBACR,MAAM,EAAE,CAAC,IAAI,IAAI,CAAC,MAAM,CAAC,iBAAiB,EAAE,CAAC;aAC9C,CAAC;SACH;aAAM;YACL,MAAM,GAAG,GAAa;gBACpB,GAAG,EAAE,KAAK;gBACV,GAAG,EAAE,OAAO;gBACZ,iFAAiF;gBACjF,CAAC,EAAE,MAAM,CAAC,IAAI,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,QAAQ,CAAC,WAAW,CAAC;aACrD,CAAC;YACF,MAAM,QAAQ,GAAG,MAAM,OAAO,CAAC,SAAS,CAAC,GAAG,EAAE,IAAI,CAAC,UAAU,CAAC,CAAC;YAC/D,OAAO;gBACL,IAAI,EAAE,CAAC,QAAQ,CAAC;gBAChB,MAAM,EAAE,EAAE;aACX,CAAC;SACH;IACH,CAAC;CACF"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export * from './CachedKeyCollector.js';
|
|
2
|
+
export * from './CompoundKeyCollector.js';
|
|
3
|
+
export * from './JwtPayload.js';
|
|
4
|
+
export * from './KeyCollector.js';
|
|
5
|
+
export * from './KeySpec.js';
|
|
6
|
+
export * from './KeyStore.js';
|
|
7
|
+
export * from './LeakyBucket.js';
|
|
8
|
+
export * from './RemoteJWKSCollector.js';
|
|
9
|
+
export * from './StaticKeyCollector.js';
|
|
10
|
+
export * from './SupabaseKeyCollector.js';
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export * from './CachedKeyCollector.js';
|
|
2
|
+
export * from './CompoundKeyCollector.js';
|
|
3
|
+
export * from './JwtPayload.js';
|
|
4
|
+
export * from './KeyCollector.js';
|
|
5
|
+
export * from './KeySpec.js';
|
|
6
|
+
export * from './KeyStore.js';
|
|
7
|
+
export * from './LeakyBucket.js';
|
|
8
|
+
export * from './RemoteJWKSCollector.js';
|
|
9
|
+
export * from './StaticKeyCollector.js';
|
|
10
|
+
export * from './SupabaseKeyCollector.js';
|
|
11
|
+
//# sourceMappingURL=auth-index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth-index.js","sourceRoot":"","sources":["../../src/auth/auth-index.ts"],"names":[],"mappings":"AAAA,cAAc,yBAAyB,CAAC;AACxC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,iBAAiB,CAAC;AAChC,cAAc,mBAAmB,CAAC;AAClC,cAAc,cAAc,CAAC;AAC7B,cAAc,eAAe,CAAC;AAC9B,cAAc,kBAAkB,CAAC;AACjC,cAAc,0BAA0B,CAAC;AACzC,cAAc,yBAAyB,CAAC;AACxC,cAAc,2BAA2B,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * as mongo from './mongo.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"db-index.js","sourceRoot":"","sources":["../../src/db/db-index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,YAAY,CAAC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import * as mongo from 'mongodb';
|
|
2
|
+
import { configFile } from '@powersync/service-types';
|
|
3
|
+
/**
|
|
4
|
+
* Time for new connection to timeout.
|
|
5
|
+
*/
|
|
6
|
+
export declare const MONGO_CONNECT_TIMEOUT_MS = 10000;
|
|
7
|
+
/**
|
|
8
|
+
* Time for individual requests to timeout the socket.
|
|
9
|
+
*/
|
|
10
|
+
export declare const MONGO_SOCKET_TIMEOUT_MS = 60000;
|
|
11
|
+
/**
|
|
12
|
+
* Time for individual requests to timeout the operation.
|
|
13
|
+
*
|
|
14
|
+
* This is time spent on the cursor, not total time.
|
|
15
|
+
*
|
|
16
|
+
* Must be less than MONGO_SOCKET_TIMEOUT_MS to ensure proper error handling.
|
|
17
|
+
*/
|
|
18
|
+
export declare const MONGO_OPERATION_TIMEOUT_MS = 30000;
|
|
19
|
+
export declare function createMongoClient(config: configFile.PowerSyncConfig['storage']): mongo.MongoClient;
|
|
20
|
+
/**
|
|
21
|
+
* Wait up to a minute for authentication errors to resolve.
|
|
22
|
+
*
|
|
23
|
+
* There can be a delay between an Atlas user being created, and that user being
|
|
24
|
+
* available on the database cluster. This works around it.
|
|
25
|
+
*
|
|
26
|
+
* This is specifically relevant for migrations and teardown - other parts of the stack
|
|
27
|
+
* can generate handle these failures and just retry or restart.
|
|
28
|
+
*/
|
|
29
|
+
export declare function waitForAuth(db: mongo.Db): Promise<void>;
|
package/dist/db/mongo.js
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import * as mongo from 'mongodb';
|
|
2
|
+
import * as timers from 'timers/promises';
|
|
3
|
+
/**
|
|
4
|
+
* Time for new connection to timeout.
|
|
5
|
+
*/
|
|
6
|
+
export const MONGO_CONNECT_TIMEOUT_MS = 10000;
|
|
7
|
+
/**
|
|
8
|
+
* Time for individual requests to timeout the socket.
|
|
9
|
+
*/
|
|
10
|
+
export const MONGO_SOCKET_TIMEOUT_MS = 60000;
|
|
11
|
+
/**
|
|
12
|
+
* Time for individual requests to timeout the operation.
|
|
13
|
+
*
|
|
14
|
+
* This is time spent on the cursor, not total time.
|
|
15
|
+
*
|
|
16
|
+
* Must be less than MONGO_SOCKET_TIMEOUT_MS to ensure proper error handling.
|
|
17
|
+
*/
|
|
18
|
+
export const MONGO_OPERATION_TIMEOUT_MS = 30000;
|
|
19
|
+
export function createMongoClient(config) {
|
|
20
|
+
return new mongo.MongoClient(config.uri, {
|
|
21
|
+
auth: {
|
|
22
|
+
username: config.username,
|
|
23
|
+
password: config.password
|
|
24
|
+
},
|
|
25
|
+
// Time for connection to timeout
|
|
26
|
+
connectTimeoutMS: MONGO_CONNECT_TIMEOUT_MS,
|
|
27
|
+
// Time for individual requests to timeout
|
|
28
|
+
socketTimeoutMS: MONGO_SOCKET_TIMEOUT_MS,
|
|
29
|
+
// How long to wait for new primary selection
|
|
30
|
+
serverSelectionTimeoutMS: 30000,
|
|
31
|
+
// Avoid too many connections:
|
|
32
|
+
// 1. It can overwhelm the source database.
|
|
33
|
+
// 2. Processing too many queries in parallel can cause the process to run out of memory.
|
|
34
|
+
maxPoolSize: 8,
|
|
35
|
+
maxConnecting: 3,
|
|
36
|
+
maxIdleTimeMS: 60000
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Wait up to a minute for authentication errors to resolve.
|
|
41
|
+
*
|
|
42
|
+
* There can be a delay between an Atlas user being created, and that user being
|
|
43
|
+
* available on the database cluster. This works around it.
|
|
44
|
+
*
|
|
45
|
+
* This is specifically relevant for migrations and teardown - other parts of the stack
|
|
46
|
+
* can generate handle these failures and just retry or restart.
|
|
47
|
+
*/
|
|
48
|
+
export async function waitForAuth(db) {
|
|
49
|
+
const start = Date.now();
|
|
50
|
+
while (Date.now() - start < 60000) {
|
|
51
|
+
try {
|
|
52
|
+
await db.command({ ping: 1 });
|
|
53
|
+
// Success
|
|
54
|
+
break;
|
|
55
|
+
}
|
|
56
|
+
catch (e) {
|
|
57
|
+
if (e.codeName == 'AuthenticationFailed') {
|
|
58
|
+
await timers.setTimeout(1000);
|
|
59
|
+
continue;
|
|
60
|
+
}
|
|
61
|
+
throw e;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
//# sourceMappingURL=mongo.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mongo.js","sourceRoot":"","sources":["../../src/db/mongo.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,SAAS,CAAC;AACjC,OAAO,KAAK,MAAM,MAAM,iBAAiB,CAAC;AAI1C;;GAEG;AACH,MAAM,CAAC,MAAM,wBAAwB,GAAG,KAAM,CAAC;AAE/C;;GAEG;AACH,MAAM,CAAC,MAAM,uBAAuB,GAAG,KAAM,CAAC;AAE9C;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,0BAA0B,GAAG,KAAM,CAAC;AAEjD,MAAM,UAAU,iBAAiB,CAAC,MAA6C;IAC7E,OAAO,IAAI,KAAK,CAAC,WAAW,CAAC,MAAM,CAAC,GAAG,EAAE;QACvC,IAAI,EAAE;YACJ,QAAQ,EAAE,MAAM,CAAC,QAAQ;YACzB,QAAQ,EAAE,MAAM,CAAC,QAAQ;SAC1B;QACD,iCAAiC;QACjC,gBAAgB,EAAE,wBAAwB;QAC1C,0CAA0C;QAC1C,eAAe,EAAE,uBAAuB;QACxC,6CAA6C;QAC7C,wBAAwB,EAAE,KAAM;QAEhC,8BAA8B;QAC9B,2CAA2C;QAC3C,yFAAyF;QACzF,WAAW,EAAE,CAAC;QAEd,aAAa,EAAE,CAAC;QAChB,aAAa,EAAE,KAAM;KACtB,CAAC,CAAC;AACL,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,CAAC,KAAK,UAAU,WAAW,CAAC,EAAY;IAC5C,MAAM,KAAK,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;IACzB,OAAO,IAAI,CAAC,GAAG,EAAE,GAAG,KAAK,GAAG,KAAM,EAAE;QAClC,IAAI;YACF,MAAM,EAAE,CAAC,OAAO,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,CAAC,CAAC;YAC9B,UAAU;YACV,MAAM;SACP;QAAC,OAAO,CAAC,EAAE;YACV,IAAI,CAAC,CAAC,QAAQ,IAAI,sBAAsB,EAAE;gBACxC,MAAM,MAAM,CAAC,UAAU,CAAC,IAAK,CAAC,CAAC;gBAC/B,SAAS;aACV;YACD,MAAM,CAAC,CAAC;SACT;KACF;AACH,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Command } from 'commander';
|
|
2
|
+
import * as utils from '../util/util-index.js';
|
|
3
|
+
/**
|
|
4
|
+
* Generates a Commander program which serves as the entry point
|
|
5
|
+
* for the PowerSync service.
|
|
6
|
+
* This registers standard actions for teardown and migrations.
|
|
7
|
+
* Optionally registers the start command handlers.
|
|
8
|
+
*/
|
|
9
|
+
export declare function generateEntryProgram(startHandlers?: Record<utils.ServiceRunner, utils.Runner>): {
|
|
10
|
+
program: Command;
|
|
11
|
+
/**
|
|
12
|
+
* Executes the main program. Ends the NodeJS process if an exception was caught.
|
|
13
|
+
*/
|
|
14
|
+
execute: () => Promise<void>;
|
|
15
|
+
};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { Command } from 'commander';
|
|
2
|
+
import { registerMigrationAction } from './commands/migrate-action.js';
|
|
3
|
+
import { registerTearDownAction } from './commands/teardown-action.js';
|
|
4
|
+
import { registerStartAction } from './entry-index.js';
|
|
5
|
+
import { logger } from '@powersync/lib-services-framework';
|
|
6
|
+
/**
|
|
7
|
+
* Generates a Commander program which serves as the entry point
|
|
8
|
+
* for the PowerSync service.
|
|
9
|
+
* This registers standard actions for teardown and migrations.
|
|
10
|
+
* Optionally registers the start command handlers.
|
|
11
|
+
*/
|
|
12
|
+
export function generateEntryProgram(startHandlers) {
|
|
13
|
+
const entryProgram = new Command();
|
|
14
|
+
entryProgram.name('powersync-runner').description('CLI to initiate a PowerSync service runner');
|
|
15
|
+
registerTearDownAction(entryProgram);
|
|
16
|
+
registerMigrationAction(entryProgram);
|
|
17
|
+
if (startHandlers) {
|
|
18
|
+
registerStartAction(entryProgram, startHandlers);
|
|
19
|
+
}
|
|
20
|
+
return {
|
|
21
|
+
program: entryProgram,
|
|
22
|
+
/**
|
|
23
|
+
* Executes the main program. Ends the NodeJS process if an exception was caught.
|
|
24
|
+
*/
|
|
25
|
+
execute: async function runProgram() {
|
|
26
|
+
try {
|
|
27
|
+
await entryProgram.parseAsync();
|
|
28
|
+
}
|
|
29
|
+
catch (e) {
|
|
30
|
+
logger.error('Fatal error', e);
|
|
31
|
+
process.exit(1);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
//# sourceMappingURL=cli-entry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli-entry.js","sourceRoot":"","sources":["../../src/entry/cli-entry.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAGpC,OAAO,EAAE,uBAAuB,EAAE,MAAM,8BAA8B,CAAC;AACvE,OAAO,EAAE,sBAAsB,EAAE,MAAM,+BAA+B,CAAC;AACvE,OAAO,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AACvD,OAAO,EAAE,MAAM,EAAE,MAAM,mCAAmC,CAAC;AAE3D;;;;;GAKG;AACH,MAAM,UAAU,oBAAoB,CAAC,aAAyD;IAC5F,MAAM,YAAY,GAAG,IAAI,OAAO,EAAE,CAAC;IACnC,YAAY,CAAC,IAAI,CAAC,kBAAkB,CAAC,CAAC,WAAW,CAAC,4CAA4C,CAAC,CAAC;IAEhG,sBAAsB,CAAC,YAAY,CAAC,CAAC;IACrC,uBAAuB,CAAC,YAAY,CAAC,CAAC;IAEtC,IAAI,aAAa,EAAE;QACjB,mBAAmB,CAAC,YAAY,EAAE,aAAa,CAAC,CAAC;KAClD;IAED,OAAO;QACL,OAAO,EAAE,YAAY;QACrB;;WAEG;QACH,OAAO,EAAE,KAAK,UAAU,UAAU;YAChC,IAAI;gBACF,MAAM,YAAY,CAAC,UAAU,EAAE,CAAC;aACjC;YAAC,OAAO,CAAC,EAAE;gBACV,MAAM,CAAC,KAAK,CAAC,aAAa,EAAE,CAAC,CAAC,CAAC;gBAC/B,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;aACjB;QACH,CAAC;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Command } from 'commander';
|
|
2
|
+
import * as util from '../../util/util-index.js';
|
|
3
|
+
/**
|
|
4
|
+
* Wraps a Command with the standard config options
|
|
5
|
+
*/
|
|
6
|
+
export declare function wrapConfigCommand(command: Command): Command;
|
|
7
|
+
/**
|
|
8
|
+
* Extracts runner configuration params from Command options.
|
|
9
|
+
*/
|
|
10
|
+
export declare function extractRunnerOptions(options: any): util.RunnerConfig;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import * as util from '../../util/util-index.js';
|
|
2
|
+
/**
|
|
3
|
+
* Wraps a Command with the standard config options
|
|
4
|
+
*/
|
|
5
|
+
export function wrapConfigCommand(command) {
|
|
6
|
+
return command
|
|
7
|
+
.option(`-c, --config-path [path]`, 'Path (inside container) to YAML config file. Defaults to process.env.POWERSYNC_CONFIG_PATH', util.env.POWERSYNC_CONFIG_PATH)
|
|
8
|
+
.option(`-c64, --config-base64 [base64]`, 'Base64 encoded YAML or JSON config file. Defaults to process.env.POWERSYNC_CONFIG_B64', util.env.POWERSYNC_CONFIG_B64)
|
|
9
|
+
.option(`-sync64, --sync-base64 [base64]`, 'Base64 encoded YAML Sync Rules. Defaults to process.env.POWERSYNC_SYNC_RULES_B64', util.env.POWERSYNC_SYNC_RULES_B64);
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Extracts runner configuration params from Command options.
|
|
13
|
+
*/
|
|
14
|
+
export function extractRunnerOptions(options) {
|
|
15
|
+
return {
|
|
16
|
+
config_path: options.configPath,
|
|
17
|
+
config_base64: options.configBase64,
|
|
18
|
+
sync_rules_base64: options.syncBase64
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=config-command.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config-command.js","sourceRoot":"","sources":["../../../src/entry/commands/config-command.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,IAAI,MAAM,0BAA0B,CAAC;AAEjD;;GAEG;AACH,MAAM,UAAU,iBAAiB,CAAC,OAAgB;IAChD,OAAO,OAAO;SACX,MAAM,CACL,0BAA0B,EAC1B,4FAA4F,EAC5F,IAAI,CAAC,GAAG,CAAC,qBAAqB,CAC/B;SACA,MAAM,CACL,gCAAgC,EAChC,uFAAuF,EACvF,IAAI,CAAC,GAAG,CAAC,oBAAoB,CAC9B;SACA,MAAM,CACL,iCAAiC,EACjC,kFAAkF,EAClF,IAAI,CAAC,GAAG,CAAC,wBAAwB,CAClC,CAAC;AACN,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,oBAAoB,CAAC,OAAY;IAC/C,OAAO;QACL,WAAW,EAAE,OAAO,CAAC,UAAU;QAC/B,aAAa,EAAE,OAAO,CAAC,YAAY;QACnC,iBAAiB,EAAE,OAAO,CAAC,UAAU;KACtC,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { extractRunnerOptions, wrapConfigCommand } from './config-command.js';
|
|
2
|
+
import { migrate } from '../../migrations/migrations.js';
|
|
3
|
+
const COMMAND_NAME = 'migrate';
|
|
4
|
+
export function registerMigrationAction(program) {
|
|
5
|
+
const migrationCommand = program.command(COMMAND_NAME);
|
|
6
|
+
wrapConfigCommand(migrationCommand);
|
|
7
|
+
return migrationCommand
|
|
8
|
+
.description('Run migrations')
|
|
9
|
+
.argument('<direction>', 'Migration direction. `up` or `down`')
|
|
10
|
+
.action(async (direction, options) => {
|
|
11
|
+
const runnerConfig = extractRunnerOptions(options);
|
|
12
|
+
await migrate({
|
|
13
|
+
direction,
|
|
14
|
+
runner_config: runnerConfig
|
|
15
|
+
});
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=migrate-action.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"migrate-action.js","sourceRoot":"","sources":["../../../src/entry/commands/migrate-action.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,oBAAoB,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAC9E,OAAO,EAAE,OAAO,EAAE,MAAM,gCAAgC,CAAC;AAGzD,MAAM,YAAY,GAAG,SAAS,CAAC;AAE/B,MAAM,UAAU,uBAAuB,CAAC,OAAgB;IACtD,MAAM,gBAAgB,GAAG,OAAO,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC;IAEvD,iBAAiB,CAAC,gBAAgB,CAAC,CAAC;IAEpC,OAAO,gBAAgB;SACpB,WAAW,CAAC,gBAAgB,CAAC;SAC7B,QAAQ,CAAC,aAAa,EAAE,qCAAqC,CAAC;SAC9D,MAAM,CAAC,KAAK,EAAE,SAAoB,EAAE,OAAO,EAAE,EAAE;QAC9C,MAAM,YAAY,GAAG,oBAAoB,CAAC,OAAO,CAAC,CAAC;QAEnD,MAAM,OAAO,CAAC;YACZ,SAAS;YACT,aAAa,EAAE,YAAY;SAC5B,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACP,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import * as utils from '../../util/util-index.js';
|
|
2
|
+
import { extractRunnerOptions, wrapConfigCommand } from './config-command.js';
|
|
3
|
+
const COMMAND_NAME = 'start';
|
|
4
|
+
export function registerStartAction(program, handlers) {
|
|
5
|
+
const startCommand = program.command(COMMAND_NAME);
|
|
6
|
+
wrapConfigCommand(startCommand);
|
|
7
|
+
return startCommand
|
|
8
|
+
.description('Starts a PowerSync service runner.')
|
|
9
|
+
.option(`-r, --runner-type [${Object.values(utils.ServiceRunner).join('|')}]`, 'Type of runner to start. Defaults to unified runner.', utils.env.PS_RUNNER_TYPE)
|
|
10
|
+
.action(async (options) => {
|
|
11
|
+
const runner = handlers[options.runnerType];
|
|
12
|
+
await runner(extractRunnerOptions(options));
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=start-action.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"start-action.js","sourceRoot":"","sources":["../../../src/entry/commands/start-action.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,KAAK,MAAM,0BAA0B,CAAC;AAClD,OAAO,EAAE,oBAAoB,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAE9E,MAAM,YAAY,GAAG,OAAO,CAAC;AAE7B,MAAM,UAAU,mBAAmB,CAAC,OAAgB,EAAE,QAAmD;IACvG,MAAM,YAAY,GAAG,OAAO,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC;IAEnD,iBAAiB,CAAC,YAAY,CAAC,CAAC;IAEhC,OAAO,YAAY;SAChB,WAAW,CAAC,oCAAoC,CAAC;SACjD,MAAM,CACL,sBAAsB,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,aAAa,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,EACrE,sDAAsD,EACtD,KAAK,CAAC,GAAG,CAAC,cAAc,CACzB;SACA,MAAM,CAAC,KAAK,EAAE,OAAO,EAAE,EAAE;QACxB,MAAM,MAAM,GAAG,QAAQ,CAAC,OAAO,CAAC,UAAiC,CAAC,CAAC;QACnE,MAAM,MAAM,CAAC,oBAAoB,CAAC,OAAO,CAAC,CAAC,CAAC;IAC9C,CAAC,CAAC,CAAC;AACP,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { extractRunnerOptions, wrapConfigCommand } from './config-command.js';
|
|
2
|
+
import { teardown } from '../../runner/teardown.js';
|
|
3
|
+
const COMMAND_NAME = 'teardown';
|
|
4
|
+
export function registerTearDownAction(program) {
|
|
5
|
+
const teardownCommand = program.command(COMMAND_NAME);
|
|
6
|
+
wrapConfigCommand(teardownCommand);
|
|
7
|
+
return teardownCommand
|
|
8
|
+
.argument('[ack]', 'Type `TEARDOWN` to confirm teardown should occur')
|
|
9
|
+
.description('Terminate all replicating sync rules, deleting the replication slots')
|
|
10
|
+
.action(async (ack, options) => {
|
|
11
|
+
if (ack !== 'TEARDOWN') {
|
|
12
|
+
throw new Error('TEARDOWN was not acknowledged.');
|
|
13
|
+
}
|
|
14
|
+
await teardown(extractRunnerOptions(options));
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=teardown-action.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"teardown-action.js","sourceRoot":"","sources":["../../../src/entry/commands/teardown-action.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,oBAAoB,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAC9E,OAAO,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AAEpD,MAAM,YAAY,GAAG,UAAU,CAAC;AAEhC,MAAM,UAAU,sBAAsB,CAAC,OAAgB;IACrD,MAAM,eAAe,GAAG,OAAO,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC;IAEtD,iBAAiB,CAAC,eAAe,CAAC,CAAC;IAEnC,OAAO,eAAe;SACnB,QAAQ,CAAC,OAAO,EAAE,kDAAkD,CAAC;SACrE,WAAW,CAAC,sEAAsE,CAAC;SACnF,MAAM,CAAC,KAAK,EAAE,GAAG,EAAE,OAAO,EAAE,EAAE;QAC7B,IAAI,GAAG,KAAK,UAAU,EAAE;YACtB,MAAM,IAAI,KAAK,CAAC,gCAAgC,CAAC,CAAC;SACnD;QAED,MAAM,QAAQ,CAAC,oBAAoB,CAAC,OAAO,CAAC,CAAC,CAAC;IAChD,CAAC,CAAC,CAAC;AACP,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"entry-index.js","sourceRoot":"","sources":["../../src/entry/entry-index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,8BAA8B,CAAC;AAC7C,cAAc,8BAA8B,CAAC;AAC7C,cAAc,4BAA4B,CAAC;AAC3C,cAAc,+BAA+B,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export * from './api/api-index.js';
|
|
2
|
+
export * as api from './api/api-index.js';
|
|
3
|
+
export * from './auth/auth-index.js';
|
|
4
|
+
export * as auth from './auth/auth-index.js';
|
|
5
|
+
export * from './db/db-index.js';
|
|
6
|
+
export * as db from './db/db-index.js';
|
|
7
|
+
export * from './entry/entry-index.js';
|
|
8
|
+
export * as entry from './entry/entry-index.js';
|
|
9
|
+
export * as framework from '@powersync/lib-services-framework';
|
|
10
|
+
export * from './metrics/Metrics.js';
|
|
11
|
+
export * as metrics from './metrics/Metrics.js';
|
|
12
|
+
export * from './migrations/migrations.js';
|
|
13
|
+
export * as migrations from './migrations/migrations-index.js';
|
|
14
|
+
export * from './replication/replication-index.js';
|
|
15
|
+
export * as replication from './replication/replication-index.js';
|
|
16
|
+
export * from './routes/routes-index.js';
|
|
17
|
+
export * as routes from './routes/routes-index.js';
|
|
18
|
+
export * from './storage/storage-index.js';
|
|
19
|
+
export * as storage from './storage/storage-index.js';
|
|
20
|
+
export * from './sync/sync-index.js';
|
|
21
|
+
export * as sync from './sync/sync-index.js';
|
|
22
|
+
export * from './system/CorePowerSyncSystem.js';
|
|
23
|
+
export * as system from './system/system-index.js';
|
|
24
|
+
export * from './util/util-index.js';
|
|
25
|
+
export * as utils from './util/util-index.js';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
// Provides global and namespaced exports
|
|
2
|
+
export * from './api/api-index.js';
|
|
3
|
+
export * as api from './api/api-index.js';
|
|
4
|
+
export * from './auth/auth-index.js';
|
|
5
|
+
export * as auth from './auth/auth-index.js';
|
|
6
|
+
export * from './db/db-index.js';
|
|
7
|
+
export * as db from './db/db-index.js';
|
|
8
|
+
export * from './entry/entry-index.js';
|
|
9
|
+
export * as entry from './entry/entry-index.js';
|
|
10
|
+
// Re-export framework for easy use of Container API
|
|
11
|
+
export * as framework from '@powersync/lib-services-framework';
|
|
12
|
+
export * from './metrics/Metrics.js';
|
|
13
|
+
export * as metrics from './metrics/Metrics.js';
|
|
14
|
+
export * from './migrations/migrations.js';
|
|
15
|
+
export * as migrations from './migrations/migrations-index.js';
|
|
16
|
+
export * from './replication/replication-index.js';
|
|
17
|
+
export * as replication from './replication/replication-index.js';
|
|
18
|
+
export * from './routes/routes-index.js';
|
|
19
|
+
export * as routes from './routes/routes-index.js';
|
|
20
|
+
export * from './storage/storage-index.js';
|
|
21
|
+
export * as storage from './storage/storage-index.js';
|
|
22
|
+
export * from './sync/sync-index.js';
|
|
23
|
+
export * as sync from './sync/sync-index.js';
|
|
24
|
+
export * from './system/CorePowerSyncSystem.js';
|
|
25
|
+
export * as system from './system/system-index.js';
|
|
26
|
+
export * from './util/util-index.js';
|
|
27
|
+
export * as utils from './util/util-index.js';
|
|
28
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,yCAAyC;AAEzC,cAAc,oBAAoB,CAAC;AACnC,OAAO,KAAK,GAAG,MAAM,oBAAoB,CAAC;AAE1C,cAAc,sBAAsB,CAAC;AACrC,OAAO,KAAK,IAAI,MAAM,sBAAsB,CAAC;AAE7C,cAAc,kBAAkB,CAAC;AACjC,OAAO,KAAK,EAAE,MAAM,kBAAkB,CAAC;AAEvC,cAAc,wBAAwB,CAAC;AACvC,OAAO,KAAK,KAAK,MAAM,wBAAwB,CAAC;AAEhD,oDAAoD;AACpD,OAAO,KAAK,SAAS,MAAM,mCAAmC,CAAC;AAE/D,cAAc,sBAAsB,CAAC;AACrC,OAAO,KAAK,OAAO,MAAM,sBAAsB,CAAC;AAEhD,cAAc,4BAA4B,CAAC;AAC3C,OAAO,KAAK,UAAU,MAAM,kCAAkC,CAAC;AAE/D,cAAc,oCAAoC,CAAC;AACnD,OAAO,KAAK,WAAW,MAAM,oCAAoC,CAAC;AAElE,cAAc,0BAA0B,CAAC;AACzC,OAAO,KAAK,MAAM,MAAM,0BAA0B,CAAC;AAEnD,cAAc,4BAA4B,CAAC;AAC3C,OAAO,KAAK,OAAO,MAAM,4BAA4B,CAAC;AAEtD,cAAc,sBAAsB,CAAC;AACrC,OAAO,KAAK,IAAI,MAAM,sBAAsB,CAAC;AAE7C,cAAc,iCAAiC,CAAC;AAChD,OAAO,KAAK,MAAM,MAAM,0BAA0B,CAAC;AAEnD,cAAc,sBAAsB,CAAC;AACrC,OAAO,KAAK,KAAK,MAAM,sBAAsB,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import * as bson from 'bson';
|
|
2
|
+
export declare class LockActiveError extends Error {
|
|
3
|
+
constructor();
|
|
4
|
+
}
|
|
5
|
+
export type LockManager = {
|
|
6
|
+
acquire: () => Promise<bson.ObjectId | null>;
|
|
7
|
+
refresh: (lock_id: bson.ObjectId) => Promise<void>;
|
|
8
|
+
release: (lock_id: bson.ObjectId) => Promise<void>;
|
|
9
|
+
lock: (handler: (refresh: () => Promise<void>) => Promise<void>) => Promise<void>;
|
|
10
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"LockManager.js","sourceRoot":"","sources":["../../src/locks/LockManager.ts"],"names":[],"mappings":"AAEA,MAAM,OAAO,eAAgB,SAAQ,KAAK;IACxC;QACE,KAAK,CAAC,wBAAwB,CAAC,CAAC;QAChC,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC;IACpC,CAAC;CACF"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import * as mongo from 'mongodb';
|
|
2
|
+
import * as bson from 'bson';
|
|
3
|
+
import { LockManager } from './LockManager.js';
|
|
4
|
+
/**
|
|
5
|
+
* Lock Document Schema
|
|
6
|
+
*/
|
|
7
|
+
export type Lock = {
|
|
8
|
+
name: string;
|
|
9
|
+
active_lock?: {
|
|
10
|
+
lock_id: bson.ObjectId;
|
|
11
|
+
ts: Date;
|
|
12
|
+
};
|
|
13
|
+
};
|
|
14
|
+
export type Collection = mongo.Collection<Lock>;
|
|
15
|
+
export type AcquireLockParams = {
|
|
16
|
+
/**
|
|
17
|
+
* Name of the process/user trying to acquire the lock.
|
|
18
|
+
*/
|
|
19
|
+
name: string;
|
|
20
|
+
/**
|
|
21
|
+
* The TTL of the lock (ms). Default: 60000 ms (1 min)
|
|
22
|
+
*/
|
|
23
|
+
timeout?: number;
|
|
24
|
+
};
|
|
25
|
+
export declare const releaseLock: (collection: Collection, lock_id: bson.ObjectId) => Promise<void>;
|
|
26
|
+
export type CreateLockManagerParams = {
|
|
27
|
+
/**
|
|
28
|
+
* Name of the process/user trying to acquire the lock.
|
|
29
|
+
*/
|
|
30
|
+
name: string;
|
|
31
|
+
/**
|
|
32
|
+
* The TTL for each lock (ms). Default: 60000 ms (1 min)
|
|
33
|
+
*/
|
|
34
|
+
timeout?: number;
|
|
35
|
+
};
|
|
36
|
+
export declare const createMongoLockManager: (collection: Collection, params: CreateLockManagerParams) => LockManager;
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import * as bson from 'bson';
|
|
2
|
+
import { LockActiveError } from './LockManager.js';
|
|
3
|
+
const DEFAULT_LOCK_TIMEOUT = 60 * 1000; // 1 minute
|
|
4
|
+
const acquireLock = async (collection, params) => {
|
|
5
|
+
const now = new Date();
|
|
6
|
+
const lock_timeout = params.timeout ?? DEFAULT_LOCK_TIMEOUT;
|
|
7
|
+
const lock_id = new bson.ObjectId();
|
|
8
|
+
await collection.updateOne({
|
|
9
|
+
name: params.name
|
|
10
|
+
}, {
|
|
11
|
+
$setOnInsert: {
|
|
12
|
+
name: params.name
|
|
13
|
+
}
|
|
14
|
+
}, {
|
|
15
|
+
upsert: true
|
|
16
|
+
});
|
|
17
|
+
const expired_ts = now.getTime() - lock_timeout;
|
|
18
|
+
const res = await collection.updateOne({
|
|
19
|
+
$and: [
|
|
20
|
+
{ name: params.name },
|
|
21
|
+
{
|
|
22
|
+
$or: [{ active_lock: { $exists: false } }, { 'active_lock.ts': { $lte: new Date(expired_ts) } }]
|
|
23
|
+
}
|
|
24
|
+
]
|
|
25
|
+
}, {
|
|
26
|
+
$set: {
|
|
27
|
+
active_lock: {
|
|
28
|
+
lock_id: lock_id,
|
|
29
|
+
ts: now
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
if (res.modifiedCount === 0) {
|
|
34
|
+
return null;
|
|
35
|
+
}
|
|
36
|
+
return lock_id;
|
|
37
|
+
};
|
|
38
|
+
const refreshLock = async (collection, lock_id) => {
|
|
39
|
+
const res = await collection.updateOne({
|
|
40
|
+
'active_lock.lock_id': lock_id
|
|
41
|
+
}, {
|
|
42
|
+
$set: {
|
|
43
|
+
'active_lock.ts': new Date()
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
if (res.modifiedCount === 0) {
|
|
47
|
+
throw new Error('Lock not found, could not refresh');
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
export const releaseLock = async (collection, lock_id) => {
|
|
51
|
+
const res = await collection.updateOne({
|
|
52
|
+
'active_lock.lock_id': lock_id
|
|
53
|
+
}, {
|
|
54
|
+
$unset: {
|
|
55
|
+
active_lock: true
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
if (res.modifiedCount === 0) {
|
|
59
|
+
throw new Error('Lock not found, could not release');
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
export const createMongoLockManager = (collection, params) => {
|
|
63
|
+
return {
|
|
64
|
+
acquire: () => acquireLock(collection, params),
|
|
65
|
+
refresh: (lock_id) => refreshLock(collection, lock_id),
|
|
66
|
+
release: (lock_id) => releaseLock(collection, lock_id),
|
|
67
|
+
lock: async (handler) => {
|
|
68
|
+
const lock_id = await acquireLock(collection, params);
|
|
69
|
+
if (!lock_id) {
|
|
70
|
+
throw new LockActiveError();
|
|
71
|
+
}
|
|
72
|
+
try {
|
|
73
|
+
await handler(() => refreshLock(collection, lock_id));
|
|
74
|
+
}
|
|
75
|
+
finally {
|
|
76
|
+
await releaseLock(collection, lock_id);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
};
|
|
81
|
+
//# sourceMappingURL=MongoLocks.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MongoLocks.js","sourceRoot":"","sources":["../../src/locks/MongoLocks.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAC7B,OAAO,EAAE,eAAe,EAAe,MAAM,kBAAkB,CAAC;AA0BhE,MAAM,oBAAoB,GAAG,EAAE,GAAG,IAAI,CAAC,CAAC,WAAW;AAEnD,MAAM,WAAW,GAAG,KAAK,EAAE,UAAsB,EAAE,MAAyB,EAAE,EAAE;IAC9E,MAAM,GAAG,GAAG,IAAI,IAAI,EAAE,CAAC;IACvB,MAAM,YAAY,GAAG,MAAM,CAAC,OAAO,IAAI,oBAAoB,CAAC;IAC5D,MAAM,OAAO,GAAG,IAAI,IAAI,CAAC,QAAQ,EAAE,CAAC;IAEpC,MAAM,UAAU,CAAC,SAAS,CACxB;QACE,IAAI,EAAE,MAAM,CAAC,IAAI;KAClB,EACD;QACE,YAAY,EAAE;YACZ,IAAI,EAAE,MAAM,CAAC,IAAI;SAClB;KACF,EACD;QACE,MAAM,EAAE,IAAI;KACb,CACF,CAAC;IAEF,MAAM,UAAU,GAAG,GAAG,CAAC,OAAO,EAAE,GAAG,YAAY,CAAC;IAEhD,MAAM,GAAG,GAAG,MAAM,UAAU,CAAC,SAAS,CACpC;QACE,IAAI,EAAE;YACJ,EAAE,IAAI,EAAE,MAAM,CAAC,IAAI,EAAE;YACrB;gBACE,GAAG,EAAE,CAAC,EAAE,WAAW,EAAE,EAAE,OAAO,EAAE,KAAK,EAAE,EAAE,EAAE,EAAE,gBAAgB,EAAE,EAAE,IAAI,EAAE,IAAI,IAAI,CAAC,UAAU,CAAC,EAAE,EAAE,CAAC;aACjG;SACF;KACF,EACD;QACE,IAAI,EAAE;YACJ,WAAW,EAAE;gBACX,OAAO,EAAE,OAAO;gBAChB,EAAE,EAAE,GAAG;aACR;SACF;KACF,CACF,CAAC;IAEF,IAAI,GAAG,CAAC,aAAa,KAAK,CAAC,EAAE;QAC3B,OAAO,IAAI,CAAC;KACb;IAED,OAAO,OAAO,CAAC;AACjB,CAAC,CAAC;AAEF,MAAM,WAAW,GAAG,KAAK,EAAE,UAAsB,EAAE,OAAsB,EAAE,EAAE;IAC3E,MAAM,GAAG,GAAG,MAAM,UAAU,CAAC,SAAS,CACpC;QACE,qBAAqB,EAAE,OAAO;KAC/B,EACD;QACE,IAAI,EAAE;YACJ,gBAAgB,EAAE,IAAI,IAAI,EAAE;SAC7B;KACF,CACF,CAAC;IAEF,IAAI,GAAG,CAAC,aAAa,KAAK,CAAC,EAAE;QAC3B,MAAM,IAAI,KAAK,CAAC,mCAAmC,CAAC,CAAC;KACtD;AACH,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,WAAW,GAAG,KAAK,EAAE,UAAsB,EAAE,OAAsB,EAAE,EAAE;IAClF,MAAM,GAAG,GAAG,MAAM,UAAU,CAAC,SAAS,CACpC;QACE,qBAAqB,EAAE,OAAO;KAC/B,EACD;QACE,MAAM,EAAE;YACN,WAAW,EAAE,IAAI;SAClB;KACF,CACF,CAAC;IAEF,IAAI,GAAG,CAAC,aAAa,KAAK,CAAC,EAAE;QAC3B,MAAM,IAAI,KAAK,CAAC,mCAAmC,CAAC,CAAC;KACtD;AACH,CAAC,CAAC;AAaF,MAAM,CAAC,MAAM,sBAAsB,GAAG,CAAC,UAAsB,EAAE,MAA+B,EAAe,EAAE;IAC7G,OAAO;QACL,OAAO,EAAE,GAAG,EAAE,CAAC,WAAW,CAAC,UAAU,EAAE,MAAM,CAAC;QAC9C,OAAO,EAAE,CAAC,OAAsB,EAAE,EAAE,CAAC,WAAW,CAAC,UAAU,EAAE,OAAO,CAAC;QACrE,OAAO,EAAE,CAAC,OAAsB,EAAE,EAAE,CAAC,WAAW,CAAC,UAAU,EAAE,OAAO,CAAC;QAErE,IAAI,EAAE,KAAK,EAAE,OAAO,EAAE,EAAE;YACtB,MAAM,OAAO,GAAG,MAAM,WAAW,CAAC,UAAU,EAAE,MAAM,CAAC,CAAC;YACtD,IAAI,CAAC,OAAO,EAAE;gBACZ,MAAM,IAAI,eAAe,EAAE,CAAC;aAC7B;YAED,IAAI;gBACF,MAAM,OAAO,CAAC,GAAG,EAAE,CAAC,WAAW,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC,CAAC;aACvD;oBAAS;gBACR,MAAM,WAAW,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC;aACxC;QACH,CAAC;KACF,CAAC;AACJ,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"locks-index.js","sourceRoot":"","sources":["../../src/locks/locks-index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAC;AACjC,cAAc,iBAAiB,CAAC"}
|