@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,436 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import { BucketChecksum, OpId } from '@/util/protocol-types.js';
|
|
3
|
+
import * as crypto from 'node:crypto';
|
|
4
|
+
import { addBucketChecksums } from '@/util/util-index.js';
|
|
5
|
+
import { ChecksumCache, FetchChecksums, FetchPartialBucketChecksum } from '@/storage/ChecksumCache.js';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Create a deterministic BucketChecksum based on the bucket name and checkpoint for testing purposes.
|
|
9
|
+
*/
|
|
10
|
+
function testHash(bucket: string, checkpoint: OpId) {
|
|
11
|
+
const key = `${checkpoint}/${bucket}`;
|
|
12
|
+
const hash = crypto.createHash('sha256').update(key).digest().readInt32LE(0);
|
|
13
|
+
return hash;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
function testPartialHash(request: FetchPartialBucketChecksum): BucketChecksum {
|
|
17
|
+
if (request.start) {
|
|
18
|
+
const a = testHash(request.bucket, request.start);
|
|
19
|
+
const b = testHash(request.bucket, request.end);
|
|
20
|
+
return addBucketChecksums(
|
|
21
|
+
{
|
|
22
|
+
bucket: request.bucket,
|
|
23
|
+
checksum: b,
|
|
24
|
+
count: Number(request.end)
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
// Subtract a
|
|
28
|
+
bucket: request.bucket,
|
|
29
|
+
checksum: -a,
|
|
30
|
+
count: -Number(request.start)
|
|
31
|
+
}
|
|
32
|
+
);
|
|
33
|
+
} else {
|
|
34
|
+
return {
|
|
35
|
+
bucket: request.bucket,
|
|
36
|
+
checksum: testHash(request.bucket, request.end),
|
|
37
|
+
count: Number(request.end)
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const TEST_123 = {
|
|
43
|
+
bucket: 'test',
|
|
44
|
+
count: 123,
|
|
45
|
+
checksum: 1104081737
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
const TEST_1234 = {
|
|
49
|
+
bucket: 'test',
|
|
50
|
+
count: 1234,
|
|
51
|
+
checksum: -1593864957
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
const TEST2_123 = {
|
|
55
|
+
bucket: 'test2',
|
|
56
|
+
count: 123,
|
|
57
|
+
checksum: 1741377449
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
const TEST3_123 = {
|
|
61
|
+
bucket: 'test3',
|
|
62
|
+
count: 123,
|
|
63
|
+
checksum: -2085080402
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
function fetchTestChecksums(batch: FetchPartialBucketChecksum[]) {
|
|
67
|
+
return new Map(
|
|
68
|
+
batch.map((v) => {
|
|
69
|
+
return [v.bucket, testPartialHash(v)];
|
|
70
|
+
})
|
|
71
|
+
);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
describe('checksum cache', function () {
|
|
75
|
+
const factory = (fetch: FetchChecksums) => {
|
|
76
|
+
return new ChecksumCache({ fetchChecksums: fetch });
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
it('should handle a sequential lookups (a)', async function () {
|
|
80
|
+
let lookups: FetchPartialBucketChecksum[][] = [];
|
|
81
|
+
const cache = factory(async (batch) => {
|
|
82
|
+
lookups.push(batch);
|
|
83
|
+
return fetchTestChecksums(batch);
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
expect(await cache.getChecksums('123', ['test'])).toEqual([TEST_123]);
|
|
87
|
+
|
|
88
|
+
expect(await cache.getChecksums('1234', ['test'])).toEqual([TEST_1234]);
|
|
89
|
+
|
|
90
|
+
expect(await cache.getChecksums('123', ['test2'])).toEqual([TEST2_123]);
|
|
91
|
+
|
|
92
|
+
expect(lookups).toEqual([
|
|
93
|
+
[{ bucket: 'test', end: '123' }],
|
|
94
|
+
// This should use the previous lookup
|
|
95
|
+
[{ bucket: 'test', start: '123', end: '1234' }],
|
|
96
|
+
[{ bucket: 'test2', end: '123' }]
|
|
97
|
+
]);
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
it('should handle a sequential lookups (b)', async function () {
|
|
101
|
+
// Reverse order of the above
|
|
102
|
+
let lookups: FetchPartialBucketChecksum[][] = [];
|
|
103
|
+
const cache = factory(async (batch) => {
|
|
104
|
+
lookups.push(batch);
|
|
105
|
+
return fetchTestChecksums(batch);
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
expect(await cache.getChecksums('123', ['test2'])).toEqual([TEST2_123]);
|
|
109
|
+
|
|
110
|
+
expect(await cache.getChecksums('1234', ['test'])).toEqual([TEST_1234]);
|
|
111
|
+
|
|
112
|
+
expect(await cache.getChecksums('123', ['test'])).toEqual([TEST_123]);
|
|
113
|
+
|
|
114
|
+
expect(lookups).toEqual([
|
|
115
|
+
// With this order, there is no option for a partial lookup
|
|
116
|
+
[{ bucket: 'test2', end: '123' }],
|
|
117
|
+
[{ bucket: 'test', end: '1234' }],
|
|
118
|
+
[{ bucket: 'test', end: '123' }]
|
|
119
|
+
]);
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
it('should handle a concurrent lookups (a)', async function () {
|
|
123
|
+
let lookups: FetchPartialBucketChecksum[][] = [];
|
|
124
|
+
const cache = factory(async (batch) => {
|
|
125
|
+
lookups.push(batch);
|
|
126
|
+
return fetchTestChecksums(batch);
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
const p1 = cache.getChecksums('123', ['test']);
|
|
130
|
+
const p2 = cache.getChecksums('1234', ['test']);
|
|
131
|
+
const p3 = cache.getChecksums('123', ['test2']);
|
|
132
|
+
|
|
133
|
+
expect(await p1).toEqual([TEST_123]);
|
|
134
|
+
expect(await p2).toEqual([TEST_1234]);
|
|
135
|
+
expect(await p3).toEqual([TEST2_123]);
|
|
136
|
+
|
|
137
|
+
// Concurrent requests, so we can't do a partial lookup for 123 -> 1234
|
|
138
|
+
expect(lookups).toEqual([
|
|
139
|
+
[{ bucket: 'test', end: '123' }],
|
|
140
|
+
[{ bucket: 'test', end: '1234' }],
|
|
141
|
+
[{ bucket: 'test2', end: '123' }]
|
|
142
|
+
]);
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
it('should handle a concurrent lookups (b)', async function () {
|
|
146
|
+
let lookups: FetchPartialBucketChecksum[][] = [];
|
|
147
|
+
const cache = factory(async (batch) => {
|
|
148
|
+
lookups.push(batch);
|
|
149
|
+
return fetchTestChecksums(batch);
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
const p1 = cache.getChecksums('123', ['test']);
|
|
153
|
+
const p2 = cache.getChecksums('123', ['test']);
|
|
154
|
+
|
|
155
|
+
expect(await p1).toEqual([TEST_123]);
|
|
156
|
+
|
|
157
|
+
expect(await p2).toEqual([TEST_123]);
|
|
158
|
+
|
|
159
|
+
// The lookup should be deduplicated, even though it's in progress
|
|
160
|
+
expect(lookups).toEqual([[{ bucket: 'test', end: '123' }]]);
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
it('should handle serial + concurrent lookups', async function () {
|
|
164
|
+
let lookups: FetchPartialBucketChecksum[][] = [];
|
|
165
|
+
const cache = factory(async (batch) => {
|
|
166
|
+
lookups.push(batch);
|
|
167
|
+
return fetchTestChecksums(batch);
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
expect(await cache.getChecksums('123', ['test'])).toEqual([TEST_123]);
|
|
171
|
+
|
|
172
|
+
const p2 = cache.getChecksums('1234', ['test']);
|
|
173
|
+
const p3 = cache.getChecksums('1234', ['test']);
|
|
174
|
+
|
|
175
|
+
expect(await p2).toEqual([TEST_1234]);
|
|
176
|
+
expect(await p3).toEqual([TEST_1234]);
|
|
177
|
+
|
|
178
|
+
expect(lookups).toEqual([
|
|
179
|
+
[{ bucket: 'test', end: '123' }],
|
|
180
|
+
// This lookup is deduplicated
|
|
181
|
+
[{ bucket: 'test', start: '123', end: '1234' }]
|
|
182
|
+
]);
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
it('should handle multiple buckets', async function () {
|
|
186
|
+
let lookups: FetchPartialBucketChecksum[][] = [];
|
|
187
|
+
const cache = factory(async (batch) => {
|
|
188
|
+
lookups.push(batch);
|
|
189
|
+
return fetchTestChecksums(batch);
|
|
190
|
+
});
|
|
191
|
+
|
|
192
|
+
expect(await cache.getChecksums('123', ['test', 'test2'])).toEqual([TEST_123, TEST2_123]);
|
|
193
|
+
|
|
194
|
+
expect(lookups).toEqual([
|
|
195
|
+
[
|
|
196
|
+
// Both lookups in the same request
|
|
197
|
+
{ bucket: 'test', end: '123' },
|
|
198
|
+
{ bucket: 'test2', end: '123' }
|
|
199
|
+
]
|
|
200
|
+
]);
|
|
201
|
+
});
|
|
202
|
+
|
|
203
|
+
it('should handle multiple buckets with partial caching (a)', async function () {
|
|
204
|
+
let lookups: FetchPartialBucketChecksum[][] = [];
|
|
205
|
+
const cache = factory(async (batch) => {
|
|
206
|
+
lookups.push(batch);
|
|
207
|
+
return fetchTestChecksums(batch);
|
|
208
|
+
});
|
|
209
|
+
|
|
210
|
+
expect(await cache.getChecksums('123', ['test'])).toEqual([TEST_123]);
|
|
211
|
+
expect(await cache.getChecksums('123', ['test', 'test2'])).toEqual([TEST_123, TEST2_123]);
|
|
212
|
+
|
|
213
|
+
expect(lookups).toEqual([
|
|
214
|
+
// Request 1
|
|
215
|
+
[{ bucket: 'test', end: '123' }],
|
|
216
|
+
// Request 2
|
|
217
|
+
[{ bucket: 'test2', end: '123' }]
|
|
218
|
+
]);
|
|
219
|
+
});
|
|
220
|
+
|
|
221
|
+
it('should handle multiple buckets with partial caching (b)', async function () {
|
|
222
|
+
let lookups: FetchPartialBucketChecksum[][] = [];
|
|
223
|
+
const cache = factory(async (batch) => {
|
|
224
|
+
lookups.push(batch);
|
|
225
|
+
return fetchTestChecksums(batch);
|
|
226
|
+
});
|
|
227
|
+
|
|
228
|
+
const a = cache.getChecksums('123', ['test', 'test2']);
|
|
229
|
+
const b = cache.getChecksums('123', ['test2', 'test3']);
|
|
230
|
+
|
|
231
|
+
expect(await a).toEqual([TEST_123, TEST2_123]);
|
|
232
|
+
expect(await b).toEqual([TEST2_123, TEST3_123]);
|
|
233
|
+
|
|
234
|
+
expect(lookups).toEqual([
|
|
235
|
+
// Request A
|
|
236
|
+
[
|
|
237
|
+
{ bucket: 'test', end: '123' },
|
|
238
|
+
{ bucket: 'test2', end: '123' }
|
|
239
|
+
],
|
|
240
|
+
// Request B (re-uses the checksum for test2 from request a)
|
|
241
|
+
[{ bucket: 'test3', end: '123' }]
|
|
242
|
+
]);
|
|
243
|
+
});
|
|
244
|
+
|
|
245
|
+
it('should handle out-of-order requests', async function () {
|
|
246
|
+
let lookups: FetchPartialBucketChecksum[][] = [];
|
|
247
|
+
const cache = factory(async (batch) => {
|
|
248
|
+
lookups.push(batch);
|
|
249
|
+
return fetchTestChecksums(batch);
|
|
250
|
+
});
|
|
251
|
+
|
|
252
|
+
expect(await cache.getChecksums('123', ['test'])).toEqual([TEST_123]);
|
|
253
|
+
|
|
254
|
+
expect(await cache.getChecksums('125', ['test'])).toEqual([
|
|
255
|
+
{
|
|
256
|
+
bucket: 'test',
|
|
257
|
+
checksum: -1865121912,
|
|
258
|
+
count: 125
|
|
259
|
+
}
|
|
260
|
+
]);
|
|
261
|
+
|
|
262
|
+
expect(await cache.getChecksums('124', ['test'])).toEqual([
|
|
263
|
+
{
|
|
264
|
+
bucket: 'test',
|
|
265
|
+
checksum: 1887460431,
|
|
266
|
+
count: 124
|
|
267
|
+
}
|
|
268
|
+
]);
|
|
269
|
+
expect(lookups).toEqual([
|
|
270
|
+
[{ bucket: 'test', end: '123' }],
|
|
271
|
+
[{ bucket: 'test', start: '123', end: '125' }],
|
|
272
|
+
[{ bucket: 'test', start: '123', end: '124' }]
|
|
273
|
+
]);
|
|
274
|
+
});
|
|
275
|
+
|
|
276
|
+
it('should handle errors', async function () {
|
|
277
|
+
let lookups: FetchPartialBucketChecksum[][] = [];
|
|
278
|
+
const TEST_ERROR = new Error('Simulated error');
|
|
279
|
+
const cache = factory(async (batch) => {
|
|
280
|
+
lookups.push(batch);
|
|
281
|
+
if (lookups.length == 1) {
|
|
282
|
+
throw new Error('Simulated error');
|
|
283
|
+
}
|
|
284
|
+
return fetchTestChecksums(batch);
|
|
285
|
+
});
|
|
286
|
+
|
|
287
|
+
const a = cache.getChecksums('123', ['test', 'test2']);
|
|
288
|
+
const b = cache.getChecksums('123', ['test2', 'test3']);
|
|
289
|
+
|
|
290
|
+
await expect(a).rejects.toEqual(TEST_ERROR);
|
|
291
|
+
await expect(b).rejects.toEqual(TEST_ERROR);
|
|
292
|
+
|
|
293
|
+
const a2 = cache.getChecksums('123', ['test', 'test2']);
|
|
294
|
+
const b2 = cache.getChecksums('123', ['test2', 'test3']);
|
|
295
|
+
|
|
296
|
+
expect(await a2).toEqual([TEST_123, TEST2_123]);
|
|
297
|
+
expect(await b2).toEqual([TEST2_123, TEST3_123]);
|
|
298
|
+
|
|
299
|
+
expect(lookups).toEqual([
|
|
300
|
+
// Request A (fails)
|
|
301
|
+
[
|
|
302
|
+
{ bucket: 'test', end: '123' },
|
|
303
|
+
{ bucket: 'test2', end: '123' }
|
|
304
|
+
],
|
|
305
|
+
// Request B (re-uses the checksum for test2 from request a)
|
|
306
|
+
// Even thought the full request fails, this batch succeeds
|
|
307
|
+
[{ bucket: 'test3', end: '123' }],
|
|
308
|
+
// Retry request A
|
|
309
|
+
[
|
|
310
|
+
{ bucket: 'test', end: '123' },
|
|
311
|
+
{ bucket: 'test2', end: '123' }
|
|
312
|
+
]
|
|
313
|
+
]);
|
|
314
|
+
});
|
|
315
|
+
|
|
316
|
+
it('should handle missing checksums (a)', async function () {
|
|
317
|
+
let lookups: FetchPartialBucketChecksum[][] = [];
|
|
318
|
+
const cache = factory(async (batch) => {
|
|
319
|
+
lookups.push(batch);
|
|
320
|
+
return fetchTestChecksums(batch.filter((b) => b.bucket != 'test'));
|
|
321
|
+
});
|
|
322
|
+
|
|
323
|
+
expect(await cache.getChecksums('123', ['test'])).toEqual([{ bucket: 'test', checksum: 0, count: 0 }]);
|
|
324
|
+
expect(await cache.getChecksums('123', ['test', 'test2'])).toEqual([
|
|
325
|
+
{ bucket: 'test', checksum: 0, count: 0 },
|
|
326
|
+
TEST2_123
|
|
327
|
+
]);
|
|
328
|
+
});
|
|
329
|
+
|
|
330
|
+
it('should handle missing checksums (b)', async function () {
|
|
331
|
+
let lookups: FetchPartialBucketChecksum[][] = [];
|
|
332
|
+
const cache = factory(async (batch) => {
|
|
333
|
+
lookups.push(batch);
|
|
334
|
+
return fetchTestChecksums(batch.filter((b) => b.bucket != 'test' || b.end != '123'));
|
|
335
|
+
});
|
|
336
|
+
|
|
337
|
+
expect(await cache.getChecksums('123', ['test'])).toEqual([{ bucket: 'test', checksum: 0, count: 0 }]);
|
|
338
|
+
expect(await cache.getChecksums('1234', ['test'])).toEqual([
|
|
339
|
+
{
|
|
340
|
+
bucket: 'test',
|
|
341
|
+
checksum: 1597020602,
|
|
342
|
+
count: 1111
|
|
343
|
+
}
|
|
344
|
+
]);
|
|
345
|
+
|
|
346
|
+
expect(lookups).toEqual([[{ bucket: 'test', end: '123' }], [{ bucket: 'test', start: '123', end: '1234' }]]);
|
|
347
|
+
});
|
|
348
|
+
|
|
349
|
+
it('should use maxSize', async function () {
|
|
350
|
+
let lookups: FetchPartialBucketChecksum[][] = [];
|
|
351
|
+
const cache = new ChecksumCache({
|
|
352
|
+
fetchChecksums: async (batch) => {
|
|
353
|
+
lookups.push(batch);
|
|
354
|
+
return fetchTestChecksums(batch);
|
|
355
|
+
},
|
|
356
|
+
maxSize: 2
|
|
357
|
+
});
|
|
358
|
+
|
|
359
|
+
expect(await cache.getChecksums('123', ['test'])).toEqual([TEST_123]);
|
|
360
|
+
expect(await cache.getChecksums('124', ['test'])).toEqual([
|
|
361
|
+
{
|
|
362
|
+
bucket: 'test',
|
|
363
|
+
checksum: 1887460431,
|
|
364
|
+
count: 124
|
|
365
|
+
}
|
|
366
|
+
]);
|
|
367
|
+
|
|
368
|
+
expect(await cache.getChecksums('125', ['test'])).toEqual([
|
|
369
|
+
{
|
|
370
|
+
bucket: 'test',
|
|
371
|
+
checksum: -1865121912,
|
|
372
|
+
count: 125
|
|
373
|
+
}
|
|
374
|
+
]);
|
|
375
|
+
expect(await cache.getChecksums('126', ['test'])).toEqual([
|
|
376
|
+
{
|
|
377
|
+
bucket: 'test',
|
|
378
|
+
checksum: -1720007310,
|
|
379
|
+
count: 126
|
|
380
|
+
}
|
|
381
|
+
]);
|
|
382
|
+
expect(await cache.getChecksums('124', ['test'])).toEqual([
|
|
383
|
+
{
|
|
384
|
+
bucket: 'test',
|
|
385
|
+
checksum: 1887460431,
|
|
386
|
+
count: 124
|
|
387
|
+
}
|
|
388
|
+
]);
|
|
389
|
+
expect(await cache.getChecksums('123', ['test'])).toEqual([TEST_123]);
|
|
390
|
+
|
|
391
|
+
expect(lookups).toEqual([
|
|
392
|
+
[{ bucket: 'test', end: '123' }],
|
|
393
|
+
[{ bucket: 'test', start: '123', end: '124' }],
|
|
394
|
+
[{ bucket: 'test', start: '124', end: '125' }],
|
|
395
|
+
[{ bucket: 'test', start: '125', end: '126' }],
|
|
396
|
+
[{ bucket: 'test', end: '124' }],
|
|
397
|
+
[{ bucket: 'test', end: '123' }]
|
|
398
|
+
]);
|
|
399
|
+
});
|
|
400
|
+
|
|
401
|
+
it('should handle concurrent requests greater than cache size', async function () {
|
|
402
|
+
// This will not be cached efficiently, but we test that we don't get errors at least.
|
|
403
|
+
let lookups: FetchPartialBucketChecksum[][] = [];
|
|
404
|
+
const cache = new ChecksumCache({
|
|
405
|
+
fetchChecksums: async (batch) => {
|
|
406
|
+
lookups.push(batch);
|
|
407
|
+
return fetchTestChecksums(batch);
|
|
408
|
+
},
|
|
409
|
+
maxSize: 2
|
|
410
|
+
});
|
|
411
|
+
|
|
412
|
+
const p3 = cache.getChecksums('123', ['test3']);
|
|
413
|
+
const p4 = cache.getChecksums('123', ['test4']);
|
|
414
|
+
const p1 = cache.getChecksums('123', ['test']);
|
|
415
|
+
const p2 = cache.getChecksums('123', ['test2']);
|
|
416
|
+
|
|
417
|
+
expect(await p1).toEqual([TEST_123]);
|
|
418
|
+
expect(await p2).toEqual([TEST2_123]);
|
|
419
|
+
expect(await p3).toEqual([TEST3_123]);
|
|
420
|
+
expect(await p4).toEqual([
|
|
421
|
+
{
|
|
422
|
+
bucket: 'test4',
|
|
423
|
+
checksum: 1004797863,
|
|
424
|
+
count: 123
|
|
425
|
+
}
|
|
426
|
+
]);
|
|
427
|
+
|
|
428
|
+
// The lookup should be deduplicated, even though it's in progress
|
|
429
|
+
expect(lookups).toEqual([
|
|
430
|
+
[{ bucket: 'test3', end: '123' }],
|
|
431
|
+
[{ bucket: 'test4', end: '123' }],
|
|
432
|
+
[{ bucket: 'test', end: '123' }],
|
|
433
|
+
[{ bucket: 'test2', end: '123' }]
|
|
434
|
+
]);
|
|
435
|
+
});
|
|
436
|
+
});
|