@powersync/service-core 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.probes/.gitkeep +0 -0
- package/CHANGELOG.md +13 -0
- package/LICENSE +67 -0
- package/README.md +3 -0
- package/dist/api/api-index.d.ts +2 -0
- package/dist/api/api-index.js +3 -0
- package/dist/api/api-index.js.map +1 -0
- package/dist/api/diagnostics.d.ts +21 -0
- package/dist/api/diagnostics.js +183 -0
- package/dist/api/diagnostics.js.map +1 -0
- package/dist/api/schema.d.ts +5 -0
- package/dist/api/schema.js +88 -0
- package/dist/api/schema.js.map +1 -0
- package/dist/auth/CachedKeyCollector.d.ts +46 -0
- package/dist/auth/CachedKeyCollector.js +116 -0
- package/dist/auth/CachedKeyCollector.js.map +1 -0
- package/dist/auth/CompoundKeyCollector.d.ts +8 -0
- package/dist/auth/CompoundKeyCollector.js +23 -0
- package/dist/auth/CompoundKeyCollector.js.map +1 -0
- package/dist/auth/JwtPayload.d.ts +10 -0
- package/dist/auth/JwtPayload.js +2 -0
- package/dist/auth/JwtPayload.js.map +1 -0
- package/dist/auth/KeyCollector.d.ts +24 -0
- package/dist/auth/KeyCollector.js +2 -0
- package/dist/auth/KeyCollector.js.map +1 -0
- package/dist/auth/KeySpec.d.ts +26 -0
- package/dist/auth/KeySpec.js +49 -0
- package/dist/auth/KeySpec.js.map +1 -0
- package/dist/auth/KeyStore.d.ts +39 -0
- package/dist/auth/KeyStore.js +131 -0
- package/dist/auth/KeyStore.js.map +1 -0
- package/dist/auth/LeakyBucket.d.ts +39 -0
- package/dist/auth/LeakyBucket.js +57 -0
- package/dist/auth/LeakyBucket.js.map +1 -0
- package/dist/auth/RemoteJWKSCollector.d.ts +24 -0
- package/dist/auth/RemoteJWKSCollector.js +106 -0
- package/dist/auth/RemoteJWKSCollector.js.map +1 -0
- package/dist/auth/StaticKeyCollector.d.ts +14 -0
- package/dist/auth/StaticKeyCollector.js +19 -0
- package/dist/auth/StaticKeyCollector.js.map +1 -0
- package/dist/auth/SupabaseKeyCollector.d.ts +22 -0
- package/dist/auth/SupabaseKeyCollector.js +61 -0
- package/dist/auth/SupabaseKeyCollector.js.map +1 -0
- package/dist/auth/auth-index.d.ts +10 -0
- package/dist/auth/auth-index.js +11 -0
- package/dist/auth/auth-index.js.map +1 -0
- package/dist/db/db-index.d.ts +1 -0
- package/dist/db/db-index.js +2 -0
- package/dist/db/db-index.js.map +1 -0
- package/dist/db/mongo.d.ts +29 -0
- package/dist/db/mongo.js +65 -0
- package/dist/db/mongo.js.map +1 -0
- package/dist/entry/cli-entry.d.ts +15 -0
- package/dist/entry/cli-entry.js +36 -0
- package/dist/entry/cli-entry.js.map +1 -0
- package/dist/entry/commands/config-command.d.ts +10 -0
- package/dist/entry/commands/config-command.js +21 -0
- package/dist/entry/commands/config-command.js.map +1 -0
- package/dist/entry/commands/migrate-action.d.ts +2 -0
- package/dist/entry/commands/migrate-action.js +18 -0
- package/dist/entry/commands/migrate-action.js.map +1 -0
- package/dist/entry/commands/start-action.d.ts +3 -0
- package/dist/entry/commands/start-action.js +15 -0
- package/dist/entry/commands/start-action.js.map +1 -0
- package/dist/entry/commands/teardown-action.d.ts +2 -0
- package/dist/entry/commands/teardown-action.js +17 -0
- package/dist/entry/commands/teardown-action.js.map +1 -0
- package/dist/entry/entry-index.d.ts +5 -0
- package/dist/entry/entry-index.js +6 -0
- package/dist/entry/entry-index.js.map +1 -0
- package/dist/index.d.ts +24 -0
- package/dist/index.js +26 -0
- package/dist/index.js.map +1 -0
- package/dist/metrics/metrics.d.ts +16 -0
- package/dist/metrics/metrics.js +139 -0
- package/dist/metrics/metrics.js.map +1 -0
- package/dist/migrations/db/migrations/1684951997326-init.d.ts +3 -0
- package/dist/migrations/db/migrations/1684951997326-init.js +31 -0
- package/dist/migrations/db/migrations/1684951997326-init.js.map +1 -0
- package/dist/migrations/db/migrations/1688556755264-initial-sync-rules.d.ts +2 -0
- package/dist/migrations/db/migrations/1688556755264-initial-sync-rules.js +5 -0
- package/dist/migrations/db/migrations/1688556755264-initial-sync-rules.js.map +1 -0
- package/dist/migrations/db/migrations/1702295701188-sync-rule-state.d.ts +3 -0
- package/dist/migrations/db/migrations/1702295701188-sync-rule-state.js +54 -0
- package/dist/migrations/db/migrations/1702295701188-sync-rule-state.js.map +1 -0
- package/dist/migrations/db/migrations/1711543888062-write-checkpoint-index.d.ts +3 -0
- package/dist/migrations/db/migrations/1711543888062-write-checkpoint-index.js +27 -0
- package/dist/migrations/db/migrations/1711543888062-write-checkpoint-index.js.map +1 -0
- package/dist/migrations/db/store.d.ts +3 -0
- package/dist/migrations/db/store.js +10 -0
- package/dist/migrations/db/store.js.map +1 -0
- package/dist/migrations/migrations.d.ts +10 -0
- package/dist/migrations/migrations.js +94 -0
- package/dist/migrations/migrations.js.map +1 -0
- package/dist/replication/ErrorRateLimiter.d.ts +17 -0
- package/dist/replication/ErrorRateLimiter.js +42 -0
- package/dist/replication/ErrorRateLimiter.js.map +1 -0
- package/dist/replication/PgRelation.d.ts +16 -0
- package/dist/replication/PgRelation.js +26 -0
- package/dist/replication/PgRelation.js.map +1 -0
- package/dist/replication/WalConnection.d.ts +34 -0
- package/dist/replication/WalConnection.js +190 -0
- package/dist/replication/WalConnection.js.map +1 -0
- package/dist/replication/WalStream.d.ts +58 -0
- package/dist/replication/WalStream.js +517 -0
- package/dist/replication/WalStream.js.map +1 -0
- package/dist/replication/WalStreamManager.d.ts +30 -0
- package/dist/replication/WalStreamManager.js +199 -0
- package/dist/replication/WalStreamManager.js.map +1 -0
- package/dist/replication/WalStreamRunner.d.ts +38 -0
- package/dist/replication/WalStreamRunner.js +155 -0
- package/dist/replication/WalStreamRunner.js.map +1 -0
- package/dist/replication/replication-index.d.ts +7 -0
- package/dist/replication/replication-index.js +8 -0
- package/dist/replication/replication-index.js.map +1 -0
- package/dist/replication/util.d.ts +9 -0
- package/dist/replication/util.js +62 -0
- package/dist/replication/util.js.map +1 -0
- package/dist/routes/admin.d.ts +7 -0
- package/dist/routes/admin.js +192 -0
- package/dist/routes/admin.js.map +1 -0
- package/dist/routes/auth.d.ts +58 -0
- package/dist/routes/auth.js +182 -0
- package/dist/routes/auth.js.map +1 -0
- package/dist/routes/checkpointing.d.ts +3 -0
- package/dist/routes/checkpointing.js +30 -0
- package/dist/routes/checkpointing.js.map +1 -0
- package/dist/routes/dev.d.ts +6 -0
- package/dist/routes/dev.js +163 -0
- package/dist/routes/dev.js.map +1 -0
- package/dist/routes/route-generators.d.ts +15 -0
- package/dist/routes/route-generators.js +32 -0
- package/dist/routes/route-generators.js.map +1 -0
- package/dist/routes/router-socket.d.ts +10 -0
- package/dist/routes/router-socket.js +5 -0
- package/dist/routes/router-socket.js.map +1 -0
- package/dist/routes/router.d.ts +13 -0
- package/dist/routes/router.js +2 -0
- package/dist/routes/router.js.map +1 -0
- package/dist/routes/routes-index.d.ts +4 -0
- package/dist/routes/routes-index.js +5 -0
- package/dist/routes/routes-index.js.map +1 -0
- package/dist/routes/socket-route.d.ts +2 -0
- package/dist/routes/socket-route.js +119 -0
- package/dist/routes/socket-route.js.map +1 -0
- package/dist/routes/sync-rules.d.ts +6 -0
- package/dist/routes/sync-rules.js +182 -0
- package/dist/routes/sync-rules.js.map +1 -0
- package/dist/routes/sync-stream.d.ts +5 -0
- package/dist/routes/sync-stream.js +74 -0
- package/dist/routes/sync-stream.js.map +1 -0
- package/dist/runner/teardown.d.ts +2 -0
- package/dist/runner/teardown.js +79 -0
- package/dist/runner/teardown.js.map +1 -0
- package/dist/storage/BucketStorage.d.ts +298 -0
- package/dist/storage/BucketStorage.js +25 -0
- package/dist/storage/BucketStorage.js.map +1 -0
- package/dist/storage/MongoBucketStorage.d.ts +51 -0
- package/dist/storage/MongoBucketStorage.js +388 -0
- package/dist/storage/MongoBucketStorage.js.map +1 -0
- package/dist/storage/SourceTable.d.ts +39 -0
- package/dist/storage/SourceTable.js +50 -0
- package/dist/storage/SourceTable.js.map +1 -0
- package/dist/storage/mongo/MongoBucketBatch.d.ts +48 -0
- package/dist/storage/mongo/MongoBucketBatch.js +584 -0
- package/dist/storage/mongo/MongoBucketBatch.js.map +1 -0
- package/dist/storage/mongo/MongoIdSequence.d.ts +12 -0
- package/dist/storage/mongo/MongoIdSequence.js +21 -0
- package/dist/storage/mongo/MongoIdSequence.js.map +1 -0
- package/dist/storage/mongo/MongoPersistedSyncRules.d.ts +9 -0
- package/dist/storage/mongo/MongoPersistedSyncRules.js +9 -0
- package/dist/storage/mongo/MongoPersistedSyncRules.js.map +1 -0
- package/dist/storage/mongo/MongoPersistedSyncRulesContent.d.ts +20 -0
- package/dist/storage/mongo/MongoPersistedSyncRulesContent.js +26 -0
- package/dist/storage/mongo/MongoPersistedSyncRulesContent.js.map +1 -0
- package/dist/storage/mongo/MongoSyncBucketStorage.d.ts +27 -0
- package/dist/storage/mongo/MongoSyncBucketStorage.js +379 -0
- package/dist/storage/mongo/MongoSyncBucketStorage.js.map +1 -0
- package/dist/storage/mongo/MongoSyncRulesLock.d.ts +16 -0
- package/dist/storage/mongo/MongoSyncRulesLock.js +65 -0
- package/dist/storage/mongo/MongoSyncRulesLock.js.map +1 -0
- package/dist/storage/mongo/OperationBatch.d.ts +26 -0
- package/dist/storage/mongo/OperationBatch.js +101 -0
- package/dist/storage/mongo/OperationBatch.js.map +1 -0
- package/dist/storage/mongo/PersistedBatch.d.ts +42 -0
- package/dist/storage/mongo/PersistedBatch.js +200 -0
- package/dist/storage/mongo/PersistedBatch.js.map +1 -0
- package/dist/storage/mongo/db.d.ts +23 -0
- package/dist/storage/mongo/db.js +34 -0
- package/dist/storage/mongo/db.js.map +1 -0
- package/dist/storage/mongo/models.d.ts +137 -0
- package/dist/storage/mongo/models.js +27 -0
- package/dist/storage/mongo/models.js.map +1 -0
- package/dist/storage/mongo/util.d.ts +26 -0
- package/dist/storage/mongo/util.js +81 -0
- package/dist/storage/mongo/util.js.map +1 -0
- package/dist/storage/storage-index.d.ts +14 -0
- package/dist/storage/storage-index.js +15 -0
- package/dist/storage/storage-index.js.map +1 -0
- package/dist/sync/BroadcastIterable.d.ts +38 -0
- package/dist/sync/BroadcastIterable.js +153 -0
- package/dist/sync/BroadcastIterable.js.map +1 -0
- package/dist/sync/LastValueSink.d.ts +25 -0
- package/dist/sync/LastValueSink.js +84 -0
- package/dist/sync/LastValueSink.js.map +1 -0
- package/dist/sync/merge.d.ts +39 -0
- package/dist/sync/merge.js +175 -0
- package/dist/sync/merge.js.map +1 -0
- package/dist/sync/safeRace.d.ts +1 -0
- package/dist/sync/safeRace.js +91 -0
- package/dist/sync/safeRace.js.map +1 -0
- package/dist/sync/sync-index.d.ts +6 -0
- package/dist/sync/sync-index.js +7 -0
- package/dist/sync/sync-index.js.map +1 -0
- package/dist/sync/sync.d.ts +18 -0
- package/dist/sync/sync.js +248 -0
- package/dist/sync/sync.js.map +1 -0
- package/dist/sync/util.d.ts +26 -0
- package/dist/sync/util.js +73 -0
- package/dist/sync/util.js.map +1 -0
- package/dist/system/CorePowerSyncSystem.d.ts +18 -0
- package/dist/system/CorePowerSyncSystem.js +28 -0
- package/dist/system/CorePowerSyncSystem.js.map +1 -0
- package/dist/util/Mutex.d.ts +47 -0
- package/dist/util/Mutex.js +132 -0
- package/dist/util/Mutex.js.map +1 -0
- package/dist/util/PgManager.d.ts +24 -0
- package/dist/util/PgManager.js +55 -0
- package/dist/util/PgManager.js.map +1 -0
- package/dist/util/alerting.d.ts +4 -0
- package/dist/util/alerting.js +14 -0
- package/dist/util/alerting.js.map +1 -0
- package/dist/util/config/collectors/config-collector.d.ts +29 -0
- package/dist/util/config/collectors/config-collector.js +116 -0
- package/dist/util/config/collectors/config-collector.js.map +1 -0
- package/dist/util/config/collectors/impl/base64-config-collector.d.ts +6 -0
- package/dist/util/config/collectors/impl/base64-config-collector.js +15 -0
- package/dist/util/config/collectors/impl/base64-config-collector.js.map +1 -0
- package/dist/util/config/collectors/impl/fallback-config-collector.d.ts +11 -0
- package/dist/util/config/collectors/impl/fallback-config-collector.js +19 -0
- package/dist/util/config/collectors/impl/fallback-config-collector.js.map +1 -0
- package/dist/util/config/collectors/impl/filesystem-config-collector.d.ts +6 -0
- package/dist/util/config/collectors/impl/filesystem-config-collector.js +35 -0
- package/dist/util/config/collectors/impl/filesystem-config-collector.js.map +1 -0
- package/dist/util/config/compound-config-collector.d.ts +32 -0
- package/dist/util/config/compound-config-collector.js +126 -0
- package/dist/util/config/compound-config-collector.js.map +1 -0
- package/dist/util/config/sync-rules/impl/base64-sync-rules-collector.d.ts +7 -0
- package/dist/util/config/sync-rules/impl/base64-sync-rules-collector.js +17 -0
- package/dist/util/config/sync-rules/impl/base64-sync-rules-collector.js.map +1 -0
- package/dist/util/config/sync-rules/impl/filesystem-sync-rules-collector.d.ts +7 -0
- package/dist/util/config/sync-rules/impl/filesystem-sync-rules-collector.js +21 -0
- package/dist/util/config/sync-rules/impl/filesystem-sync-rules-collector.js.map +1 -0
- package/dist/util/config/sync-rules/impl/inline-sync-rules-collector.d.ts +7 -0
- package/dist/util/config/sync-rules/impl/inline-sync-rules-collector.js +17 -0
- package/dist/util/config/sync-rules/impl/inline-sync-rules-collector.js.map +1 -0
- package/dist/util/config/sync-rules/sync-collector.d.ts +6 -0
- package/dist/util/config/sync-rules/sync-collector.js +3 -0
- package/dist/util/config/sync-rules/sync-collector.js.map +1 -0
- package/dist/util/config/types.d.ts +53 -0
- package/dist/util/config/types.js +7 -0
- package/dist/util/config/types.js.map +1 -0
- package/dist/util/config.d.ts +7 -0
- package/dist/util/config.js +35 -0
- package/dist/util/config.js.map +1 -0
- package/dist/util/env.d.ts +10 -0
- package/dist/util/env.js +25 -0
- package/dist/util/env.js.map +1 -0
- package/dist/util/memory-tracking.d.ts +7 -0
- package/dist/util/memory-tracking.js +58 -0
- package/dist/util/memory-tracking.js.map +1 -0
- package/dist/util/migration_lib.d.ts +11 -0
- package/dist/util/migration_lib.js +64 -0
- package/dist/util/migration_lib.js.map +1 -0
- package/dist/util/pgwire_utils.d.ts +24 -0
- package/dist/util/pgwire_utils.js +117 -0
- package/dist/util/pgwire_utils.js.map +1 -0
- package/dist/util/populate_test_data.d.ts +8 -0
- package/dist/util/populate_test_data.js +65 -0
- package/dist/util/populate_test_data.js.map +1 -0
- package/dist/util/protocol-types.d.ts +178 -0
- package/dist/util/protocol-types.js +38 -0
- package/dist/util/protocol-types.js.map +1 -0
- package/dist/util/secs.d.ts +2 -0
- package/dist/util/secs.js +49 -0
- package/dist/util/secs.js.map +1 -0
- package/dist/util/util-index.d.ts +22 -0
- package/dist/util/util-index.js +23 -0
- package/dist/util/util-index.js.map +1 -0
- package/dist/util/utils.d.ts +14 -0
- package/dist/util/utils.js +75 -0
- package/dist/util/utils.js.map +1 -0
- package/package.json +55 -0
- package/src/api/api-index.ts +2 -0
- package/src/api/diagnostics.ts +221 -0
- package/src/api/schema.ts +99 -0
- package/src/auth/CachedKeyCollector.ts +132 -0
- package/src/auth/CompoundKeyCollector.ts +33 -0
- package/src/auth/JwtPayload.ts +11 -0
- package/src/auth/KeyCollector.ts +27 -0
- package/src/auth/KeySpec.ts +67 -0
- package/src/auth/KeyStore.ts +156 -0
- package/src/auth/LeakyBucket.ts +66 -0
- package/src/auth/RemoteJWKSCollector.ts +130 -0
- package/src/auth/StaticKeyCollector.ts +21 -0
- package/src/auth/SupabaseKeyCollector.ts +67 -0
- package/src/auth/auth-index.ts +10 -0
- package/src/db/db-index.ts +1 -0
- package/src/db/mongo.ts +72 -0
- package/src/entry/cli-entry.ts +41 -0
- package/src/entry/commands/config-command.ts +36 -0
- package/src/entry/commands/migrate-action.ts +25 -0
- package/src/entry/commands/start-action.ts +24 -0
- package/src/entry/commands/teardown-action.ts +23 -0
- package/src/entry/entry-index.ts +5 -0
- package/src/index.ts +37 -0
- package/src/metrics/metrics.ts +169 -0
- package/src/migrations/db/migrations/1684951997326-init.ts +33 -0
- package/src/migrations/db/migrations/1688556755264-initial-sync-rules.ts +5 -0
- package/src/migrations/db/migrations/1702295701188-sync-rule-state.ts +99 -0
- package/src/migrations/db/migrations/1711543888062-write-checkpoint-index.ts +32 -0
- package/src/migrations/db/store.ts +11 -0
- package/src/migrations/migrations.ts +122 -0
- package/src/replication/ErrorRateLimiter.ts +49 -0
- package/src/replication/PgRelation.ts +42 -0
- package/src/replication/WalConnection.ts +227 -0
- package/src/replication/WalStream.ts +626 -0
- package/src/replication/WalStreamManager.ts +214 -0
- package/src/replication/WalStreamRunner.ts +180 -0
- package/src/replication/replication-index.ts +7 -0
- package/src/replication/util.ts +76 -0
- package/src/routes/admin.ts +229 -0
- package/src/routes/auth.ts +209 -0
- package/src/routes/checkpointing.ts +38 -0
- package/src/routes/dev.ts +194 -0
- package/src/routes/route-generators.ts +39 -0
- package/src/routes/router-socket.ts +13 -0
- package/src/routes/router.ts +17 -0
- package/src/routes/routes-index.ts +5 -0
- package/src/routes/socket-route.ts +131 -0
- package/src/routes/sync-rules.ts +210 -0
- package/src/routes/sync-stream.ts +92 -0
- package/src/runner/teardown.ts +91 -0
- package/src/storage/BucketStorage.ts +386 -0
- package/src/storage/MongoBucketStorage.ts +493 -0
- package/src/storage/SourceTable.ts +60 -0
- package/src/storage/mongo/MongoBucketBatch.ts +756 -0
- package/src/storage/mongo/MongoIdSequence.ts +24 -0
- package/src/storage/mongo/MongoPersistedSyncRules.ts +16 -0
- package/src/storage/mongo/MongoPersistedSyncRulesContent.ts +47 -0
- package/src/storage/mongo/MongoSyncBucketStorage.ts +517 -0
- package/src/storage/mongo/MongoSyncRulesLock.ts +81 -0
- package/src/storage/mongo/OperationBatch.ts +115 -0
- package/src/storage/mongo/PersistedBatch.ts +245 -0
- package/src/storage/mongo/db.ts +69 -0
- package/src/storage/mongo/models.ts +157 -0
- package/src/storage/mongo/util.ts +88 -0
- package/src/storage/storage-index.ts +15 -0
- package/src/sync/BroadcastIterable.ts +161 -0
- package/src/sync/LastValueSink.ts +100 -0
- package/src/sync/merge.ts +200 -0
- package/src/sync/safeRace.ts +99 -0
- package/src/sync/sync-index.ts +6 -0
- package/src/sync/sync.ts +312 -0
- package/src/sync/util.ts +98 -0
- package/src/system/CorePowerSyncSystem.ts +43 -0
- package/src/util/Mutex.ts +159 -0
- package/src/util/PgManager.ts +64 -0
- package/src/util/alerting.ts +17 -0
- package/src/util/config/collectors/config-collector.ts +141 -0
- package/src/util/config/collectors/impl/base64-config-collector.ts +18 -0
- package/src/util/config/collectors/impl/fallback-config-collector.ts +22 -0
- package/src/util/config/collectors/impl/filesystem-config-collector.ts +41 -0
- package/src/util/config/compound-config-collector.ts +171 -0
- package/src/util/config/sync-rules/impl/base64-sync-rules-collector.ts +21 -0
- package/src/util/config/sync-rules/impl/filesystem-sync-rules-collector.ts +26 -0
- package/src/util/config/sync-rules/impl/inline-sync-rules-collector.ts +21 -0
- package/src/util/config/sync-rules/sync-collector.ts +8 -0
- package/src/util/config/types.ts +60 -0
- package/src/util/config.ts +39 -0
- package/src/util/env.ts +28 -0
- package/src/util/memory-tracking.ts +67 -0
- package/src/util/migration_lib.ts +79 -0
- package/src/util/pgwire_utils.ts +139 -0
- package/src/util/populate_test_data.ts +78 -0
- package/src/util/protocol-types.ts +223 -0
- package/src/util/secs.ts +54 -0
- package/src/util/util-index.ts +25 -0
- package/src/util/utils.ts +102 -0
- package/test/src/__snapshots__/pg_test.test.ts.snap +256 -0
- package/test/src/__snapshots__/sync.test.ts.snap +235 -0
- package/test/src/auth.test.ts +340 -0
- package/test/src/broadcast_iterable.test.ts +156 -0
- package/test/src/data_storage.test.ts +1176 -0
- package/test/src/env.ts +8 -0
- package/test/src/large_batch.test.ts +194 -0
- package/test/src/merge_iterable.test.ts +355 -0
- package/test/src/pg_test.test.ts +432 -0
- package/test/src/schema_changes.test.ts +545 -0
- package/test/src/slow_tests.test.ts +257 -0
- package/test/src/sql_functions.test.ts +254 -0
- package/test/src/sql_operators.test.ts +132 -0
- package/test/src/sync.test.ts +293 -0
- package/test/src/sync_rules.test.ts +1051 -0
- package/test/src/util.ts +67 -0
- package/test/src/validation.test.ts +63 -0
- package/test/src/wal_stream.test.ts +310 -0
- package/test/src/wal_stream_utils.ts +147 -0
- package/test/tsconfig.json +20 -0
- package/tsconfig.json +20 -0
- package/tsconfig.tsbuildinfo +1 -0
- package/vitest.config.ts +11 -0
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import * as bson from 'bson';
|
|
2
|
+
import * as crypto from 'crypto';
|
|
3
|
+
/**
|
|
4
|
+
* Lookup serialization must be number-agnostic. I.e. normalize numbers, instead of preserving numbers.
|
|
5
|
+
* @param lookup
|
|
6
|
+
*/
|
|
7
|
+
export function serializeLookup(lookup) {
|
|
8
|
+
const normalized = lookup.map((value) => {
|
|
9
|
+
if (typeof value == 'number' && Number.isInteger(value)) {
|
|
10
|
+
return BigInt(value);
|
|
11
|
+
}
|
|
12
|
+
else {
|
|
13
|
+
return value;
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
return new bson.Binary(bson.serialize({ l: normalized }));
|
|
17
|
+
}
|
|
18
|
+
export function idPrefixFilter(prefix, rest) {
|
|
19
|
+
let filter = {
|
|
20
|
+
$gte: {
|
|
21
|
+
...prefix
|
|
22
|
+
},
|
|
23
|
+
$lt: {
|
|
24
|
+
...prefix
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
for (let key of rest) {
|
|
28
|
+
filter.$gte[key] = new bson.MinKey();
|
|
29
|
+
filter.$lt[key] = new bson.MaxKey();
|
|
30
|
+
}
|
|
31
|
+
return filter;
|
|
32
|
+
}
|
|
33
|
+
export function generateSlotName(prefix, sync_rules_id) {
|
|
34
|
+
const slot_suffix = crypto.randomBytes(2).toString('hex');
|
|
35
|
+
return `${prefix}${sync_rules_id}_${slot_suffix}`;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Read a single batch of data from a cursor, then close it.
|
|
39
|
+
*
|
|
40
|
+
* We do our best to avoid MongoDB fetching any more data than this single batch.
|
|
41
|
+
*
|
|
42
|
+
* This is similar to using `singleBatch: true` in find options.
|
|
43
|
+
* However, that makes `has_more` detection very difficult, since the cursor is always closed
|
|
44
|
+
* after the first batch. Instead, we do a workaround to only fetch a single batch below.
|
|
45
|
+
*
|
|
46
|
+
* For this to be effective, set batchSize = limit in the find command.
|
|
47
|
+
*/
|
|
48
|
+
export async function readSingleBatch(cursor) {
|
|
49
|
+
try {
|
|
50
|
+
let data;
|
|
51
|
+
let hasMore = true;
|
|
52
|
+
// Let MongoDB load the first batch of data
|
|
53
|
+
const hasAny = await cursor.hasNext();
|
|
54
|
+
// Now it's in memory, and we can read it
|
|
55
|
+
data = cursor.readBufferedDocuments();
|
|
56
|
+
if (!hasAny || cursor.id?.isZero()) {
|
|
57
|
+
// A zero id means the cursor is exhaused.
|
|
58
|
+
// No results (hasAny == false) means even this batch doesn't have data.
|
|
59
|
+
// This should similar results as `await cursor.hasNext()`, but without
|
|
60
|
+
// actually fetching the next batch.
|
|
61
|
+
//
|
|
62
|
+
// Note that it is safe (but slightly inefficient) to return `hasMore: true`
|
|
63
|
+
// without there being more data, as long as the next batch
|
|
64
|
+
// will return `hasMore: false`.
|
|
65
|
+
hasMore = false;
|
|
66
|
+
}
|
|
67
|
+
return { data, hasMore };
|
|
68
|
+
}
|
|
69
|
+
finally {
|
|
70
|
+
// Match the from the cursor iterator logic here:
|
|
71
|
+
// https://github.com/mongodb/node-mongodb-native/blob/e02534e7d1c627bf50b85ca39f5995dbf165ad44/src/cursor/abstract_cursor.ts#L327-L331
|
|
72
|
+
if (!cursor.closed) {
|
|
73
|
+
await cursor.close();
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
export const BSON_DESERIALIZE_OPTIONS = {
|
|
78
|
+
// use bigint instead of long
|
|
79
|
+
useBigInt64: true
|
|
80
|
+
};
|
|
81
|
+
//# sourceMappingURL=util.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"util.js","sourceRoot":"","sources":["../../../src/storage/mongo/util.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,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eAAe,CAAI,MAA2B;IAClE,IAAI,CAAC;QACH,IAAI,IAAS,CAAC;QACd,IAAI,OAAO,GAAG,IAAI,CAAC;QACnB,2CAA2C;QAC3C,MAAM,MAAM,GAAG,MAAM,MAAM,CAAC,OAAO,EAAE,CAAC;QACtC,yCAAyC;QACzC,IAAI,GAAG,MAAM,CAAC,qBAAqB,EAAE,CAAC;QACtC,IAAI,CAAC,MAAM,IAAI,MAAM,CAAC,EAAE,EAAE,MAAM,EAAE,EAAE,CAAC;YACnC,0CAA0C;YAC1C,wEAAwE;YACxE,uEAAuE;YACvE,oCAAoC;YACpC,EAAE;YACF,4EAA4E;YAC5E,2DAA2D;YAC3D,gCAAgC;YAChC,OAAO,GAAG,KAAK,CAAC;QAClB,CAAC;QACD,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC;IAC3B,CAAC;YAAS,CAAC;QACT,iDAAiD;QACjD,uIAAuI;QACvI,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC;YACnB,MAAM,MAAM,CAAC,KAAK,EAAE,CAAC;QACvB,CAAC;IACH,CAAC;AACH,CAAC;AAED,MAAM,CAAC,MAAM,wBAAwB,GAA4B;IAC/D,6BAA6B;IAC7B,WAAW,EAAE,IAAI;CAClB,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export * from './SourceTable.js';
|
|
2
|
+
export * from './MongoBucketStorage.js';
|
|
3
|
+
export * from './BucketStorage.js';
|
|
4
|
+
export * from './mongo/db.js';
|
|
5
|
+
export * from './mongo/models.js';
|
|
6
|
+
export * from './mongo/MongoBucketBatch.js';
|
|
7
|
+
export * from './mongo/MongoIdSequence.js';
|
|
8
|
+
export * from './mongo/MongoPersistedSyncRules.js';
|
|
9
|
+
export * from './mongo/MongoPersistedSyncRulesContent.js';
|
|
10
|
+
export * from './mongo/MongoSyncBucketStorage.js';
|
|
11
|
+
export * from './mongo/MongoSyncRulesLock.js';
|
|
12
|
+
export * from './mongo/OperationBatch.js';
|
|
13
|
+
export * from './mongo/PersistedBatch.js';
|
|
14
|
+
export * from './mongo/util.js';
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export * from './SourceTable.js';
|
|
2
|
+
export * from './MongoBucketStorage.js';
|
|
3
|
+
export * from './BucketStorage.js';
|
|
4
|
+
export * from './mongo/db.js';
|
|
5
|
+
export * from './mongo/models.js';
|
|
6
|
+
export * from './mongo/MongoBucketBatch.js';
|
|
7
|
+
export * from './mongo/MongoIdSequence.js';
|
|
8
|
+
export * from './mongo/MongoPersistedSyncRules.js';
|
|
9
|
+
export * from './mongo/MongoPersistedSyncRulesContent.js';
|
|
10
|
+
export * from './mongo/MongoSyncBucketStorage.js';
|
|
11
|
+
export * from './mongo/MongoSyncRulesLock.js';
|
|
12
|
+
export * from './mongo/OperationBatch.js';
|
|
13
|
+
export * from './mongo/PersistedBatch.js';
|
|
14
|
+
export * from './mongo/util.js';
|
|
15
|
+
//# sourceMappingURL=storage-index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"storage-index.js","sourceRoot":"","sources":["../../src/storage/storage-index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAC;AACjC,cAAc,yBAAyB,CAAC;AACxC,cAAc,oBAAoB,CAAC;AAEnC,cAAc,eAAe,CAAC;AAC9B,cAAc,mBAAmB,CAAC;AAClC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,4BAA4B,CAAC;AAC3C,cAAc,oCAAoC,CAAC;AACnD,cAAc,2CAA2C,CAAC;AAC1D,cAAc,mCAAmC,CAAC;AAClD,cAAc,+BAA+B,CAAC;AAC9C,cAAc,2BAA2B,CAAC;AAC1C,cAAc,2BAA2B,CAAC;AAC1C,cAAc,iBAAiB,CAAC"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/// <reference types="node" resolution-mode="require"/>
|
|
2
|
+
export type IterableSource<T> = (signal: AbortSignal) => AsyncIterable<T>;
|
|
3
|
+
/**
|
|
4
|
+
* Loosely based on Dart's broadcast streams:
|
|
5
|
+
* https://api.flutter.dev/flutter/dart-async/StreamController/StreamController.broadcast.html
|
|
6
|
+
*
|
|
7
|
+
* 1. Exposes an AsyncIterable interface.
|
|
8
|
+
* 2. Allows multiple concurrent subscribers.
|
|
9
|
+
* 3. Any new subscriber gets new events as they are published.
|
|
10
|
+
* 4. The source iterable is only created once there are subscribers.
|
|
11
|
+
*
|
|
12
|
+
* One notable difference: The last value is buffered and immediately returned for any new subscribers.
|
|
13
|
+
*
|
|
14
|
+
* When all subscribers are stopped, this source iterable is stopped.
|
|
15
|
+
*
|
|
16
|
+
* Any error on the source is passed on to all subscribers. This generally stops all
|
|
17
|
+
* subscribers. Once a new subscriber is then added, a new source is started.
|
|
18
|
+
*
|
|
19
|
+
* Slow subscribers will skip events.
|
|
20
|
+
*
|
|
21
|
+
* Implementation note: It is possible to do this using:
|
|
22
|
+
* 1. rxjs `share` for multicasting and auto-starting + stopping the source.
|
|
23
|
+
* 2. rxjs `BehaviorSubject` to keep the last value.
|
|
24
|
+
* 3. Use `LastValueSink` to convert to an AsyncIterable.
|
|
25
|
+
*/
|
|
26
|
+
export declare class BroadcastIterable<T> implements AsyncIterable<T> {
|
|
27
|
+
private source;
|
|
28
|
+
private last;
|
|
29
|
+
private subscribers;
|
|
30
|
+
private abortController;
|
|
31
|
+
constructor(source: IterableSource<T>);
|
|
32
|
+
private start;
|
|
33
|
+
private loop;
|
|
34
|
+
private removeSink;
|
|
35
|
+
private addSink;
|
|
36
|
+
[Symbol.asyncIterator](signal?: AbortSignal): AsyncIterator<T>;
|
|
37
|
+
get active(): boolean;
|
|
38
|
+
}
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import { AbortError } from 'ix/aborterror.js';
|
|
2
|
+
import { LastValueSink } from './LastValueSink.js';
|
|
3
|
+
/**
|
|
4
|
+
* Loosely based on Dart's broadcast streams:
|
|
5
|
+
* https://api.flutter.dev/flutter/dart-async/StreamController/StreamController.broadcast.html
|
|
6
|
+
*
|
|
7
|
+
* 1. Exposes an AsyncIterable interface.
|
|
8
|
+
* 2. Allows multiple concurrent subscribers.
|
|
9
|
+
* 3. Any new subscriber gets new events as they are published.
|
|
10
|
+
* 4. The source iterable is only created once there are subscribers.
|
|
11
|
+
*
|
|
12
|
+
* One notable difference: The last value is buffered and immediately returned for any new subscribers.
|
|
13
|
+
*
|
|
14
|
+
* When all subscribers are stopped, this source iterable is stopped.
|
|
15
|
+
*
|
|
16
|
+
* Any error on the source is passed on to all subscribers. This generally stops all
|
|
17
|
+
* subscribers. Once a new subscriber is then added, a new source is started.
|
|
18
|
+
*
|
|
19
|
+
* Slow subscribers will skip events.
|
|
20
|
+
*
|
|
21
|
+
* Implementation note: It is possible to do this using:
|
|
22
|
+
* 1. rxjs `share` for multicasting and auto-starting + stopping the source.
|
|
23
|
+
* 2. rxjs `BehaviorSubject` to keep the last value.
|
|
24
|
+
* 3. Use `LastValueSink` to convert to an AsyncIterable.
|
|
25
|
+
*/
|
|
26
|
+
export class BroadcastIterable {
|
|
27
|
+
constructor(source) {
|
|
28
|
+
this.source = source;
|
|
29
|
+
this.last = undefined;
|
|
30
|
+
this.subscribers = undefined;
|
|
31
|
+
this.abortController = undefined;
|
|
32
|
+
}
|
|
33
|
+
start(sink) {
|
|
34
|
+
const abortController = new AbortController();
|
|
35
|
+
const listeners = new Set();
|
|
36
|
+
listeners.add(sink);
|
|
37
|
+
this.abortController = abortController;
|
|
38
|
+
this.subscribers = listeners;
|
|
39
|
+
this.loop(abortController, listeners);
|
|
40
|
+
}
|
|
41
|
+
async loop(abortController, sinks) {
|
|
42
|
+
try {
|
|
43
|
+
for await (let doc of this.source(abortController.signal)) {
|
|
44
|
+
if (abortController.signal.aborted || sinks.size == 0) {
|
|
45
|
+
throw new AbortError();
|
|
46
|
+
}
|
|
47
|
+
this.last = doc;
|
|
48
|
+
for (let sink of sinks) {
|
|
49
|
+
sink.next(doc);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
// End of stream
|
|
53
|
+
for (let sink of sinks) {
|
|
54
|
+
sink.complete();
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
catch (e) {
|
|
58
|
+
// Just in case the error is not from the source
|
|
59
|
+
abortController.abort();
|
|
60
|
+
for (let listener of sinks) {
|
|
61
|
+
listener.error(e);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
finally {
|
|
65
|
+
// Clear state, so that a new subscription may be started
|
|
66
|
+
if (this.subscribers === sinks) {
|
|
67
|
+
this.subscribers = undefined;
|
|
68
|
+
this.abortController = undefined;
|
|
69
|
+
this.last = undefined;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
removeSink(listener) {
|
|
74
|
+
this.subscribers?.delete(listener);
|
|
75
|
+
if (this.subscribers?.size == 0) {
|
|
76
|
+
// This is not immediate - there may be a delay until it is fully stopped,
|
|
77
|
+
// depending on the underlying source.
|
|
78
|
+
this.abortController?.abort();
|
|
79
|
+
this.last = undefined;
|
|
80
|
+
this.subscribers = undefined;
|
|
81
|
+
this.abortController = undefined;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
addSink(listener) {
|
|
85
|
+
if (this.subscribers == null) {
|
|
86
|
+
this.start(listener);
|
|
87
|
+
}
|
|
88
|
+
else {
|
|
89
|
+
this.subscribers.add(listener);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
async *[Symbol.asyncIterator](signal) {
|
|
93
|
+
const sink = new LastValueSink(this.last);
|
|
94
|
+
this.addSink(sink);
|
|
95
|
+
try {
|
|
96
|
+
yield* sink.withSignal(signal);
|
|
97
|
+
}
|
|
98
|
+
finally {
|
|
99
|
+
this.removeSink(sink);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
get active() {
|
|
103
|
+
return this.subscribers != null;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
// For reference, this is an alternative implementation using rxjs.
|
|
107
|
+
// It still relies on LastValueSink.
|
|
108
|
+
//
|
|
109
|
+
// import { BehaviorSubject, Observable, filter, from, share } from 'rxjs';
|
|
110
|
+
//
|
|
111
|
+
// export class RxBroadcastIterable<T> implements AsyncIterable<T> {
|
|
112
|
+
// private observable: Observable<T>;
|
|
113
|
+
//
|
|
114
|
+
// constructor(source: IterableSource<T>) {
|
|
115
|
+
// const obsSource = new Observable<T>((subscriber) => {
|
|
116
|
+
// const controller = new AbortController();
|
|
117
|
+
// const s = source(controller.signal);
|
|
118
|
+
// const inner = from(s);
|
|
119
|
+
// const subscription = inner.subscribe(subscriber);
|
|
120
|
+
// subscription.add({
|
|
121
|
+
// unsubscribe() {
|
|
122
|
+
// controller.abort();
|
|
123
|
+
// }
|
|
124
|
+
// });
|
|
125
|
+
// return subscription;
|
|
126
|
+
// });
|
|
127
|
+
//
|
|
128
|
+
// const obs = obsSource.pipe(
|
|
129
|
+
// share({ connector: () => new BehaviorSubject(undefined as T) }),
|
|
130
|
+
// filter((v) => v != undefined)
|
|
131
|
+
// );
|
|
132
|
+
// this.observable = obs;
|
|
133
|
+
// }
|
|
134
|
+
//
|
|
135
|
+
// async *[Symbol.asyncIterator](signal?: AbortSignal): AsyncIterator<T> {
|
|
136
|
+
// if (signal?.aborted) {
|
|
137
|
+
// return;
|
|
138
|
+
// }
|
|
139
|
+
// const sink = new LastValueSink<T>(undefined);
|
|
140
|
+
// const subscription = this.observable.subscribe(sink);
|
|
141
|
+
//
|
|
142
|
+
// try {
|
|
143
|
+
// yield* sink.withSignal(signal);
|
|
144
|
+
// } finally {
|
|
145
|
+
// subscription.unsubscribe();
|
|
146
|
+
// }
|
|
147
|
+
// }
|
|
148
|
+
//
|
|
149
|
+
// get active() {
|
|
150
|
+
// return false;
|
|
151
|
+
// }
|
|
152
|
+
// }
|
|
153
|
+
//# sourceMappingURL=BroadcastIterable.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BroadcastIterable.js","sourceRoot":"","sources":["../../src/sync/Broadc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CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAC1C,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;QACnB,IAAI,CAAC;YACH,KAAK,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC;QACjC,CAAC;gBAAS,CAAC;YACT,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC;QACxB,CAAC;IACH,CAAC;IAED,IAAI,MAAM;QACR,OAAO,IAAI,CAAC,WAAW,IAAI,IAAI,CAAC;IAClC,CAAC;CACF;AAED,mEAAmE;AACnE,oCAAoC;AACpC,EAAE;AACF,2EAA2E;AAC3E,EAAE;AACF,oEAAoE;AACpE,uCAAuC;AACvC,EAAE;AACF,6CAA6C;AAC7C,4DAA4D;AAC5D,kDAAkD;AAClD,6CAA6C;AAC7C,+BAA+B;AAC/B,0DAA0D;AAC1D,2BAA2B;AAC3B,0BAA0B;AAC1B,gCAAgC;AAChC,YAAY;AACZ,YAAY;AACZ,6BAA6B;AAC7B,UAAU;AACV,EAAE;AACF,kCAAkC;AAClC,yEAAyE;AACzE,sCAAsC;AACtC,SAAS;AACT,6BAA6B;AAC7B,MAAM;AACN,EAAE;AACF,4EAA4E;AAC5E,6BAA6B;AAC7B,gBAAgB;AAChB,QAAQ;AACR,oDAAoD;AACpD,4DAA4D;AAC5D,EAAE;AACF,YAAY;AACZ,wCAAwC;AACxC,kBAAkB;AAClB,oCAAoC;AACpC,QAAQ;AACR,MAAM;AACN,EAAE;AACF,mBAAmB;AACnB,oBAAoB;AACpB,MAAM;AACN,IAAI"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/// <reference types="node" resolution-mode="require"/>
|
|
2
|
+
/**
|
|
3
|
+
* An AsyncIterable that allows pushing values.
|
|
4
|
+
*
|
|
5
|
+
* If the consumer is slower than the source, only the last value is buffered.
|
|
6
|
+
*
|
|
7
|
+
* Similar to ix AsyncSink, except that we only keep the last value.
|
|
8
|
+
*/
|
|
9
|
+
export declare class LastValueSink<T> implements AsyncIterable<T> {
|
|
10
|
+
buffer: NextResult<T> | undefined;
|
|
11
|
+
nextResolve: undefined | (() => void);
|
|
12
|
+
constructor(initial: T | undefined);
|
|
13
|
+
next(value: T): void;
|
|
14
|
+
complete(): void;
|
|
15
|
+
error(e: any): void;
|
|
16
|
+
private push;
|
|
17
|
+
withSignal(signal?: AbortSignal): AsyncIterable<T>;
|
|
18
|
+
[Symbol.asyncIterator](): AsyncIterator<T>;
|
|
19
|
+
}
|
|
20
|
+
interface NextResult<T> {
|
|
21
|
+
value: T | undefined;
|
|
22
|
+
done: boolean;
|
|
23
|
+
error: any;
|
|
24
|
+
}
|
|
25
|
+
export {};
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { AbortError } from 'ix/aborterror.js';
|
|
2
|
+
/**
|
|
3
|
+
* An AsyncIterable that allows pushing values.
|
|
4
|
+
*
|
|
5
|
+
* If the consumer is slower than the source, only the last value is buffered.
|
|
6
|
+
*
|
|
7
|
+
* Similar to ix AsyncSink, except that we only keep the last value.
|
|
8
|
+
*/
|
|
9
|
+
export class LastValueSink {
|
|
10
|
+
constructor(initial) {
|
|
11
|
+
if (initial != null) {
|
|
12
|
+
this.buffer = { value: initial, done: false, error: undefined };
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
next(value) {
|
|
16
|
+
this.push({
|
|
17
|
+
value,
|
|
18
|
+
done: false,
|
|
19
|
+
error: undefined
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
complete() {
|
|
23
|
+
this.push({
|
|
24
|
+
value: undefined,
|
|
25
|
+
done: true,
|
|
26
|
+
error: undefined
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
error(e) {
|
|
30
|
+
this.push({
|
|
31
|
+
value: undefined,
|
|
32
|
+
done: true,
|
|
33
|
+
error: e
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
push(r) {
|
|
37
|
+
if (this.buffer?.done) {
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
this.buffer = r;
|
|
41
|
+
this.nextResolve?.();
|
|
42
|
+
}
|
|
43
|
+
async *withSignal(signal) {
|
|
44
|
+
if (!signal) {
|
|
45
|
+
yield* this;
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
if (signal?.aborted) {
|
|
49
|
+
throw new AbortError();
|
|
50
|
+
}
|
|
51
|
+
const onAbort = () => {
|
|
52
|
+
this.error(new AbortError());
|
|
53
|
+
};
|
|
54
|
+
signal?.addEventListener('abort', onAbort);
|
|
55
|
+
try {
|
|
56
|
+
yield* this;
|
|
57
|
+
}
|
|
58
|
+
finally {
|
|
59
|
+
signal?.removeEventListener('abort', onAbort);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
async *[Symbol.asyncIterator]() {
|
|
63
|
+
while (true) {
|
|
64
|
+
if (this.buffer == null) {
|
|
65
|
+
const promise = new Promise((resolve) => {
|
|
66
|
+
this.nextResolve = resolve;
|
|
67
|
+
});
|
|
68
|
+
await promise;
|
|
69
|
+
}
|
|
70
|
+
const n = this.buffer;
|
|
71
|
+
this.buffer = undefined;
|
|
72
|
+
if (n.error) {
|
|
73
|
+
throw n.error;
|
|
74
|
+
}
|
|
75
|
+
else if (n.done) {
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
else {
|
|
79
|
+
yield n.value;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
//# sourceMappingURL=LastValueSink.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"LastValueSink.js","sourceRoot":"","sources":["../../src/sync/LastValueSink.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAE9C;;;;;;GAMG;AACH,MAAM,OAAO,aAAa;IAIxB,YAAY,OAAsB;QAChC,IAAI,OAAO,IAAI,IAAI,EAAE,CAAC;YACpB,IAAI,CAAC,MA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,EAAE,mBAAmB,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;QAChD,CAAC;IACH,CAAC;IAED,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,aAAa,CAAC;QAC3B,OAAO,IAAI,EAAE,CAAC;YACZ,IAAI,IAAI,CAAC,MAAM,IAAI,IAAI,EAAE,CAAC;gBACxB,MAAM,OAAO,GAAG,IAAI,OAAO,CAAO,CAAC,OAAO,EAAE,EAAE;oBAC5C,IAAI,CAAC,WAAW,GAAG,OAAO,CAAC;gBAC7B,CAAC,CAAC,CAAC;gBACH,MAAM,OAAO,CAAC;YAChB,CAAC;YACD,MAAM,CAAC,GAAG,IAAI,CAAC,MAAO,CAAC;YACvB,IAAI,CAAC,MAAM,GAAG,SAAS,CAAC;YAExB,IAAI,CAAC,CAAC,KAAK,EAAE,CAAC;gBACZ,MAAM,CAAC,CAAC,KAAK,CAAC;YAChB,CAAC;iBAAM,IAAI,CAAC,CAAC,IAAI,EAAE,CAAC;gBAClB,OAAO;YACT,CAAC;iBAAM,CAAC;gBACN,MAAM,CAAC,CAAC,KAAM,CAAC;YACjB,CAAC;QACH,CAAC;IACH,CAAC;CACF"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/// <reference types="node" resolution-mode="require"/>
|
|
2
|
+
import { AsyncIterableX } from 'ix/asynciterable/index.js';
|
|
3
|
+
/**
|
|
4
|
+
* Merge multiple source AsyncIterables into one output AsyncIterable.
|
|
5
|
+
*
|
|
6
|
+
* The results from all iterables are interleaved.
|
|
7
|
+
*
|
|
8
|
+
* When any iterable is done, the output stops.
|
|
9
|
+
*
|
|
10
|
+
* @param source The source AsyncIterables.
|
|
11
|
+
* @param signal Optional signal to abort iteration.
|
|
12
|
+
* @returns The merged AsyncIterable.
|
|
13
|
+
*/
|
|
14
|
+
export declare function mergeAsyncIterables<T>(source: AsyncIterable<T>[], signal?: AbortSignal): AsyncIterable<T>;
|
|
15
|
+
export declare function mergeAsyncIterablesNew<T>(source: AsyncIterable<T>[], signal?: AbortSignal): AsyncIterable<T>;
|
|
16
|
+
export declare function mergeAsyncIterablesOld<T>(source: AsyncIterable<T>[], signal?: AbortSignal): AsyncIterable<T>;
|
|
17
|
+
/**
|
|
18
|
+
* Loosely based on IxJS merge, but with some changes:
|
|
19
|
+
* 1. Fix an issue with uncaught errors.
|
|
20
|
+
* Partially fixed: https://github.com/ReactiveX/IxJS/pull/354
|
|
21
|
+
* Essentially, we only want to call next() on inner iterators when next() is called on the outer one.
|
|
22
|
+
* 2. Call return() on all inner iterators when the outer one returns.
|
|
23
|
+
* 3. Returning when the first iterator returns.
|
|
24
|
+
*
|
|
25
|
+
* https://github.com/ReactiveX/IxJS/blob/f07b7ef4095120f1ef21a4023030c75b36335cd1/src/asynciterable/merge.ts
|
|
26
|
+
*/
|
|
27
|
+
export declare class FixedMergeAsyncIterable<T> extends AsyncIterableX<T> {
|
|
28
|
+
private _source;
|
|
29
|
+
private _race;
|
|
30
|
+
/**
|
|
31
|
+
*
|
|
32
|
+
* @param source
|
|
33
|
+
* @param options Specify `race: true` to stop the iterator when any inner one returns, instead of waiting for all.
|
|
34
|
+
*/
|
|
35
|
+
constructor(source: AsyncIterable<T>[], options?: {
|
|
36
|
+
race?: boolean;
|
|
37
|
+
});
|
|
38
|
+
[Symbol.asyncIterator](signal?: AbortSignal): AsyncIterator<T>;
|
|
39
|
+
}
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
import { throwIfAborted } from 'ix/aborterror.js';
|
|
2
|
+
import { AsyncIterableX } from 'ix/asynciterable/index.js';
|
|
3
|
+
import { wrapWithAbort } from 'ix/asynciterable/operators/withabort.js';
|
|
4
|
+
import { safeRace } from './safeRace.js';
|
|
5
|
+
/**
|
|
6
|
+
* Merge multiple source AsyncIterables into one output AsyncIterable.
|
|
7
|
+
*
|
|
8
|
+
* The results from all iterables are interleaved.
|
|
9
|
+
*
|
|
10
|
+
* When any iterable is done, the output stops.
|
|
11
|
+
*
|
|
12
|
+
* @param source The source AsyncIterables.
|
|
13
|
+
* @param signal Optional signal to abort iteration.
|
|
14
|
+
* @returns The merged AsyncIterable.
|
|
15
|
+
*/
|
|
16
|
+
export function mergeAsyncIterables(source, signal) {
|
|
17
|
+
return mergeAsyncIterablesNew(source, signal);
|
|
18
|
+
// return mergeAsyncIterablesOld(source, signal);
|
|
19
|
+
}
|
|
20
|
+
export function mergeAsyncIterablesNew(source, signal) {
|
|
21
|
+
return new MergedAsyncIterable(source, signal);
|
|
22
|
+
}
|
|
23
|
+
export function mergeAsyncIterablesOld(source, signal) {
|
|
24
|
+
return wrapWithAbort(new FixedMergeAsyncIterable(source, { race: true }), signal);
|
|
25
|
+
}
|
|
26
|
+
const NEVER_PROMISE = new Promise(() => { });
|
|
27
|
+
function wrapPromiseWithIndex(promise, index) {
|
|
28
|
+
return promise.then((value) => ({ value, index }));
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Re-implementation of FixedMergeAsyncIterable, without using async generators.
|
|
32
|
+
*
|
|
33
|
+
* The functionality should be the same in most cases.
|
|
34
|
+
*/
|
|
35
|
+
class MergedAsyncIterable {
|
|
36
|
+
constructor(source, signal) {
|
|
37
|
+
this._source = source;
|
|
38
|
+
this._signal = signal;
|
|
39
|
+
}
|
|
40
|
+
[Symbol.asyncIterator]() {
|
|
41
|
+
const signal = this._signal;
|
|
42
|
+
throwIfAborted(signal);
|
|
43
|
+
const length = this._source.length;
|
|
44
|
+
const iterators = new Array(length);
|
|
45
|
+
const nexts = new Array(length);
|
|
46
|
+
for (let i = 0; i < length; i++) {
|
|
47
|
+
const iterator = wrapWithAbort(this._source[i], signal)[Symbol.asyncIterator]();
|
|
48
|
+
iterators[i] = iterator;
|
|
49
|
+
nexts[i] = null;
|
|
50
|
+
}
|
|
51
|
+
const returnIterators = async (_value) => {
|
|
52
|
+
for (let iter of iterators) {
|
|
53
|
+
// Do not wait for return() to complete, since it may block
|
|
54
|
+
iter.return?.();
|
|
55
|
+
}
|
|
56
|
+
return { value: undefined, done: true };
|
|
57
|
+
};
|
|
58
|
+
return {
|
|
59
|
+
next: async () => {
|
|
60
|
+
for (let i = 0; i < length; i++) {
|
|
61
|
+
if (nexts[i] == null) {
|
|
62
|
+
nexts[i] = wrapPromiseWithIndex(iterators[i].next(), i);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
try {
|
|
66
|
+
// IMPORTANT! safeRace here acts like Promise.race, but avoids major memory leaks.
|
|
67
|
+
const { value: { done, value }, index } = (await safeRace(nexts));
|
|
68
|
+
if (done) {
|
|
69
|
+
// One of the source iterators is done - return them all
|
|
70
|
+
await returnIterators();
|
|
71
|
+
return {
|
|
72
|
+
value: undefined,
|
|
73
|
+
done: true
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
else {
|
|
77
|
+
// Consume the result, which will cause the next one to be requested on the
|
|
78
|
+
// next iteration.
|
|
79
|
+
nexts[index] = null;
|
|
80
|
+
return {
|
|
81
|
+
value: value,
|
|
82
|
+
done: false
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
catch (e) {
|
|
87
|
+
// One of the source iterators raised an error - return all others
|
|
88
|
+
// and propagate the error
|
|
89
|
+
await returnIterators();
|
|
90
|
+
throw e;
|
|
91
|
+
}
|
|
92
|
+
},
|
|
93
|
+
return: () => {
|
|
94
|
+
return returnIterators();
|
|
95
|
+
},
|
|
96
|
+
throw: async (e) => {
|
|
97
|
+
for (let iter of iterators) {
|
|
98
|
+
// Do not wait for throw() to complete, since it may block
|
|
99
|
+
iter.throw?.(e);
|
|
100
|
+
}
|
|
101
|
+
throw e;
|
|
102
|
+
}
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Loosely based on IxJS merge, but with some changes:
|
|
108
|
+
* 1. Fix an issue with uncaught errors.
|
|
109
|
+
* Partially fixed: https://github.com/ReactiveX/IxJS/pull/354
|
|
110
|
+
* Essentially, we only want to call next() on inner iterators when next() is called on the outer one.
|
|
111
|
+
* 2. Call return() on all inner iterators when the outer one returns.
|
|
112
|
+
* 3. Returning when the first iterator returns.
|
|
113
|
+
*
|
|
114
|
+
* https://github.com/ReactiveX/IxJS/blob/f07b7ef4095120f1ef21a4023030c75b36335cd1/src/asynciterable/merge.ts
|
|
115
|
+
*/
|
|
116
|
+
export class FixedMergeAsyncIterable extends AsyncIterableX {
|
|
117
|
+
/**
|
|
118
|
+
*
|
|
119
|
+
* @param source
|
|
120
|
+
* @param options Specify `race: true` to stop the iterator when any inner one returns, instead of waiting for all.
|
|
121
|
+
*/
|
|
122
|
+
constructor(source, options) {
|
|
123
|
+
super();
|
|
124
|
+
this._source = source;
|
|
125
|
+
this._race = options?.race ?? false;
|
|
126
|
+
}
|
|
127
|
+
async *[Symbol.asyncIterator](signal) {
|
|
128
|
+
throwIfAborted(signal);
|
|
129
|
+
const length = this._source.length;
|
|
130
|
+
const iterators = new Array(length);
|
|
131
|
+
const nexts = new Array(length);
|
|
132
|
+
let active = length;
|
|
133
|
+
for (let i = 0; i < length; i++) {
|
|
134
|
+
const iterator = wrapWithAbort(this._source[i], signal)[Symbol.asyncIterator]();
|
|
135
|
+
iterators[i] = iterator;
|
|
136
|
+
nexts[i] = wrapPromiseWithIndex(iterator.next(), i);
|
|
137
|
+
}
|
|
138
|
+
try {
|
|
139
|
+
while (active > 0) {
|
|
140
|
+
// IMPORTANT! safeRace here acts like Promise.race, but avoids major memory leaks.
|
|
141
|
+
const { value: { done, value }, index } = await safeRace(nexts);
|
|
142
|
+
if (done) {
|
|
143
|
+
nexts[index] = NEVER_PROMISE;
|
|
144
|
+
active--;
|
|
145
|
+
if (this._race) {
|
|
146
|
+
break;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
else {
|
|
150
|
+
const iterator$ = iterators[index];
|
|
151
|
+
nexts[index] = NEVER_PROMISE;
|
|
152
|
+
try {
|
|
153
|
+
yield value;
|
|
154
|
+
}
|
|
155
|
+
catch (e) {
|
|
156
|
+
// iter.throw() was called on the merged iterator
|
|
157
|
+
// Propagate the error to the source iterators
|
|
158
|
+
for (let iter of iterators) {
|
|
159
|
+
iter.throw?.(e);
|
|
160
|
+
}
|
|
161
|
+
throw e;
|
|
162
|
+
}
|
|
163
|
+
nexts[index] = wrapPromiseWithIndex(iterator$.next(), index);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
finally {
|
|
168
|
+
for (let iter of iterators) {
|
|
169
|
+
// This may be an early return - return all inner iterators
|
|
170
|
+
iter.return?.();
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
//# sourceMappingURL=merge.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"merge.js","sourceRoot":"","sources":["../../src/sync/merge.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAC3D,OAAO,EAAE,aAAa,EAAE,MAAM,yCAAyC,CAAC;AACxE,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAEzC;;;;;;;;;;GAUG;AACH,MAAM,UAAU,mBAAmB,CAAI,MAA0B,EAAE,MAAoB;IACrF,OAAO,sBAAsB,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC9C,iDAAiD;AACnD,CAAC;AAED,MAAM,UAAU,sBAAsB,CAAI,MAA0B,EAAE,MAAoB;IACxF,OAAO,IAAI,mBAAmB,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;AACjD,CAAC;AAED,MAAM,UAAU,sBAAsB,CAAI,MAA0B,EAAE,MAAoB;IACxF,OAAO,aAAa,CAAC,IAAI,uBAAuB,CAAC,MAAM,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,EAAE,MAAM,CAAC,CAAC;AACpF,CAAC;AAED,MAAM,aAAa,GAAG,IAA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