@rocicorp/zero 1.10.0-canary.0 → 1.10.0-canary.10
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/out/replicache/src/db/commit.js +1 -4
- package/out/replicache/src/db/commit.js.map +1 -1
- package/out/replicache/src/db/read.d.ts +1 -0
- package/out/replicache/src/db/read.d.ts.map +1 -1
- package/out/replicache/src/db/read.js +1 -4
- package/out/replicache/src/db/read.js.map +1 -1
- package/out/replicache/src/db/write.d.ts +2 -1
- package/out/replicache/src/db/write.d.ts.map +1 -1
- package/out/replicache/src/db/write.js +4 -51
- package/out/replicache/src/db/write.js.map +1 -1
- package/out/replicache/src/persist/clients.d.ts +1 -0
- package/out/replicache/src/persist/clients.d.ts.map +1 -1
- package/out/replicache/src/persist/clients.js +4 -31
- package/out/replicache/src/persist/clients.js.map +1 -1
- package/out/replicache/src/process-env.d.ts +28 -0
- package/out/replicache/src/process-env.d.ts.map +1 -0
- package/out/replicache/src/replicache-impl.d.ts.map +1 -1
- package/out/replicache/src/replicache-impl.js.map +1 -1
- package/out/replicache/src/scan-iterator.js +2 -14
- package/out/replicache/src/scan-iterator.js.map +1 -1
- package/out/replicache/src/subscriptions.d.ts +1 -0
- package/out/replicache/src/subscriptions.d.ts.map +1 -1
- package/out/replicache/src/subscriptions.js +2 -10
- package/out/replicache/src/subscriptions.js.map +1 -1
- package/out/replicache/src/transactions.d.ts +1 -0
- package/out/replicache/src/transactions.d.ts.map +1 -1
- package/out/replicache/src/transactions.js +2 -4
- package/out/replicache/src/transactions.js.map +1 -1
- package/out/shared/src/promise-race.d.ts +14 -0
- package/out/shared/src/promise-race.d.ts.map +1 -1
- package/out/shared/src/promise-race.js +32 -1
- package/out/shared/src/promise-race.js.map +1 -1
- package/out/z2s/src/compiler.d.ts.map +1 -1
- package/out/z2s/src/compiler.js +1 -22
- package/out/z2s/src/compiler.js.map +1 -1
- package/out/zero/package.js +3 -3
- package/out/zero/package.js.map +1 -1
- package/out/zero-cache/src/auth/write-authorizer.d.ts.map +1 -1
- package/out/zero-cache/src/auth/write-authorizer.js +8 -1
- package/out/zero-cache/src/auth/write-authorizer.js.map +1 -1
- package/out/zero-cache/src/config/normalize.d.ts +6 -0
- package/out/zero-cache/src/config/normalize.d.ts.map +1 -1
- package/out/zero-cache/src/config/normalize.js +24 -2
- package/out/zero-cache/src/config/normalize.js.map +1 -1
- package/out/zero-cache/src/config/zero-config.d.ts +65 -4
- package/out/zero-cache/src/config/zero-config.d.ts.map +1 -1
- package/out/zero-cache/src/config/zero-config.js +202 -35
- package/out/zero-cache/src/config/zero-config.js.map +1 -1
- package/out/zero-cache/src/custom/fetch.js +1 -1
- package/out/zero-cache/src/custom/fetch.js.map +1 -1
- package/out/zero-cache/src/db/delete-lite-db.js +2 -1
- package/out/zero-cache/src/db/delete-lite-db.js.map +1 -1
- package/out/zero-cache/src/db/migration-lite.d.ts.map +1 -1
- package/out/zero-cache/src/db/migration-lite.js +10 -5
- package/out/zero-cache/src/db/migration-lite.js.map +1 -1
- package/out/zero-cache/src/db/migration.d.ts.map +1 -1
- package/out/zero-cache/src/db/migration.js +4 -2
- package/out/zero-cache/src/db/migration.js.map +1 -1
- package/out/zero-cache/src/db/sqlite-corruption.d.ts +3 -2
- package/out/zero-cache/src/db/sqlite-corruption.d.ts.map +1 -1
- package/out/zero-cache/src/db/sqlite-corruption.js +13 -8
- package/out/zero-cache/src/db/sqlite-corruption.js.map +1 -1
- package/out/zero-cache/src/db/transaction-pool.d.ts +5 -15
- package/out/zero-cache/src/db/transaction-pool.d.ts.map +1 -1
- package/out/zero-cache/src/db/transaction-pool.js +8 -72
- package/out/zero-cache/src/db/transaction-pool.js.map +1 -1
- package/out/zero-cache/src/observability/metrics.d.ts +6 -1
- package/out/zero-cache/src/observability/metrics.d.ts.map +1 -1
- package/out/zero-cache/src/observability/metrics.js +20 -2
- package/out/zero-cache/src/observability/metrics.js.map +1 -1
- package/out/zero-cache/src/server/change-streamer.d.ts.map +1 -1
- package/out/zero-cache/src/server/change-streamer.js +105 -34
- package/out/zero-cache/src/server/change-streamer.js.map +1 -1
- package/out/zero-cache/src/server/main.d.ts.map +1 -1
- package/out/zero-cache/src/server/main.js +8 -18
- package/out/zero-cache/src/server/main.js.map +1 -1
- package/out/zero-cache/src/server/replicator.d.ts.map +1 -1
- package/out/zero-cache/src/server/replicator.js +48 -5
- package/out/zero-cache/src/server/replicator.js.map +1 -1
- package/out/zero-cache/src/server/runner/run-worker.js +3 -2
- package/out/zero-cache/src/server/runner/run-worker.js.map +1 -1
- package/out/zero-cache/src/server/syncer.d.ts.map +1 -1
- package/out/zero-cache/src/server/syncer.js +1 -1
- package/out/zero-cache/src/server/syncer.js.map +1 -1
- package/out/zero-cache/src/server/worker-urls.d.ts +0 -1
- package/out/zero-cache/src/server/worker-urls.d.ts.map +1 -1
- package/out/zero-cache/src/server/worker-urls.js +1 -2
- package/out/zero-cache/src/server/worker-urls.js.map +1 -1
- package/out/zero-cache/src/services/change-source/change-source.d.ts +4 -2
- package/out/zero-cache/src/services/change-source/change-source.d.ts.map +1 -1
- package/out/zero-cache/src/services/change-source/common/replica-restore.d.ts +35 -0
- package/out/zero-cache/src/services/change-source/common/replica-restore.d.ts.map +1 -0
- package/out/zero-cache/src/services/change-source/common/replica-restore.js +34 -0
- package/out/zero-cache/src/services/change-source/common/replica-restore.js.map +1 -0
- package/out/zero-cache/src/services/change-source/common/replica-schema.d.ts +2 -0
- package/out/zero-cache/src/services/change-source/common/replica-schema.d.ts.map +1 -1
- package/out/zero-cache/src/services/change-source/common/replica-schema.js +81 -3
- package/out/zero-cache/src/services/change-source/common/replica-schema.js.map +1 -1
- package/out/zero-cache/src/services/change-source/custom/change-source.d.ts +2 -6
- package/out/zero-cache/src/services/change-source/custom/change-source.d.ts.map +1 -1
- package/out/zero-cache/src/services/change-source/custom/change-source.js +14 -5
- package/out/zero-cache/src/services/change-source/custom/change-source.js.map +1 -1
- package/out/zero-cache/src/services/change-source/pg/backfill-stream.d.ts.map +1 -1
- package/out/zero-cache/src/services/change-source/pg/backfill-stream.js +22 -11
- package/out/zero-cache/src/services/change-source/pg/backfill-stream.js.map +1 -1
- package/out/zero-cache/src/services/change-source/pg/change-source.d.ts +7 -7
- package/out/zero-cache/src/services/change-source/pg/change-source.d.ts.map +1 -1
- package/out/zero-cache/src/services/change-source/pg/change-source.js +90 -31
- package/out/zero-cache/src/services/change-source/pg/change-source.js.map +1 -1
- package/out/zero-cache/src/services/change-source/pg/decommission.d.ts.map +1 -1
- package/out/zero-cache/src/services/change-source/pg/decommission.js +20 -11
- package/out/zero-cache/src/services/change-source/pg/decommission.js.map +1 -1
- package/out/zero-cache/src/services/change-source/pg/initial-sync.d.ts +9 -1
- package/out/zero-cache/src/services/change-source/pg/initial-sync.d.ts.map +1 -1
- package/out/zero-cache/src/services/change-source/pg/initial-sync.js +61 -76
- package/out/zero-cache/src/services/change-source/pg/initial-sync.js.map +1 -1
- package/out/zero-cache/src/services/change-source/pg/logical-replication/stream.d.ts +65 -2
- package/out/zero-cache/src/services/change-source/pg/logical-replication/stream.d.ts.map +1 -1
- package/out/zero-cache/src/services/change-source/pg/logical-replication/stream.js +101 -10
- package/out/zero-cache/src/services/change-source/pg/logical-replication/stream.js.map +1 -1
- package/out/zero-cache/src/services/change-source/pg/replication-slots.d.ts +27 -2
- package/out/zero-cache/src/services/change-source/pg/replication-slots.d.ts.map +1 -1
- package/out/zero-cache/src/services/change-source/pg/replication-slots.js +41 -8
- package/out/zero-cache/src/services/change-source/pg/replication-slots.js.map +1 -1
- package/out/zero-cache/src/services/change-source/pg/schema/init.d.ts +0 -5
- package/out/zero-cache/src/services/change-source/pg/schema/init.d.ts.map +1 -1
- package/out/zero-cache/src/services/change-source/pg/schema/init.js +29 -41
- package/out/zero-cache/src/services/change-source/pg/schema/init.js.map +1 -1
- package/out/zero-cache/src/services/change-source/pg/schema/shard.d.ts +35 -16
- package/out/zero-cache/src/services/change-source/pg/schema/shard.d.ts.map +1 -1
- package/out/zero-cache/src/services/change-source/pg/schema/shard.js +77 -7
- package/out/zero-cache/src/services/change-source/pg/schema/shard.js.map +1 -1
- package/out/zero-cache/src/services/change-source/protocol/current/data.d.ts +2 -1
- package/out/zero-cache/src/services/change-source/protocol/current/data.d.ts.map +1 -1
- package/out/zero-cache/src/services/change-source/protocol/current/data.js +5 -13
- package/out/zero-cache/src/services/change-source/protocol/current/data.js.map +1 -1
- package/out/zero-cache/src/services/change-source/protocol/current/downstream.d.ts +6 -3
- package/out/zero-cache/src/services/change-source/protocol/current/downstream.d.ts.map +1 -1
- package/out/zero-cache/src/services/change-source/protocol/current/schema-change-tags.d.ts +6 -0
- package/out/zero-cache/src/services/change-source/protocol/current/schema-change-tags.d.ts.map +1 -0
- package/out/zero-cache/src/services/change-source/protocol/current/schema-change-tags.js +21 -0
- package/out/zero-cache/src/services/change-source/protocol/current/schema-change-tags.js.map +1 -0
- package/out/zero-cache/src/services/change-source/protocol/current/status.d.ts +1 -0
- package/out/zero-cache/src/services/change-source/protocol/current/status.d.ts.map +1 -1
- package/out/zero-cache/src/services/change-source/protocol/current/upstream.d.ts +1 -0
- package/out/zero-cache/src/services/change-source/protocol/current/upstream.d.ts.map +1 -1
- package/out/zero-cache/src/services/change-streamer/backup-cleanup-monitor-factory.d.ts +3 -7
- package/out/zero-cache/src/services/change-streamer/backup-cleanup-monitor-factory.d.ts.map +1 -1
- package/out/zero-cache/src/services/change-streamer/backup-cleanup-monitor-factory.js +26 -10
- package/out/zero-cache/src/services/change-streamer/backup-cleanup-monitor-factory.js.map +1 -1
- package/out/zero-cache/src/services/change-streamer/backup-monitor.d.ts +15 -5
- package/out/zero-cache/src/services/change-streamer/backup-monitor.d.ts.map +1 -1
- package/out/zero-cache/src/services/change-streamer/backup-monitor.js +71 -0
- package/out/zero-cache/src/services/change-streamer/backup-monitor.js.map +1 -0
- package/out/zero-cache/src/services/change-streamer/broadcast.d.ts +68 -78
- package/out/zero-cache/src/services/change-streamer/broadcast.d.ts.map +1 -1
- package/out/zero-cache/src/services/change-streamer/broadcast.js +84 -92
- package/out/zero-cache/src/services/change-streamer/broadcast.js.map +1 -1
- package/out/zero-cache/src/services/change-streamer/change-log-codec.d.ts +19 -0
- package/out/zero-cache/src/services/change-streamer/change-log-codec.d.ts.map +1 -0
- package/out/zero-cache/src/services/change-streamer/change-log-codec.js +50 -0
- package/out/zero-cache/src/services/change-streamer/change-log-codec.js.map +1 -0
- package/out/zero-cache/src/services/change-streamer/change-log-compare-digest.d.ts +34 -0
- package/out/zero-cache/src/services/change-streamer/change-log-compare-digest.d.ts.map +1 -0
- package/out/zero-cache/src/services/change-streamer/change-log-compare-digest.js +67 -0
- package/out/zero-cache/src/services/change-streamer/change-log-compare-digest.js.map +1 -0
- package/out/zero-cache/src/services/change-streamer/change-log-initializer.d.ts +141 -0
- package/out/zero-cache/src/services/change-streamer/change-log-initializer.d.ts.map +1 -0
- package/out/zero-cache/src/services/change-streamer/change-log-initializer.js +270 -0
- package/out/zero-cache/src/services/change-streamer/change-log-initializer.js.map +1 -0
- package/out/zero-cache/src/services/change-streamer/change-log-transaction-hash.d.ts +19 -0
- package/out/zero-cache/src/services/change-streamer/change-log-transaction-hash.d.ts.map +1 -0
- package/out/zero-cache/src/services/change-streamer/change-log-transaction-hash.js +39 -0
- package/out/zero-cache/src/services/change-streamer/change-log-transaction-hash.js.map +1 -0
- package/out/zero-cache/src/services/change-streamer/change-streamer-http.d.ts +5 -8
- package/out/zero-cache/src/services/change-streamer/change-streamer-http.d.ts.map +1 -1
- package/out/zero-cache/src/services/change-streamer/change-streamer-http.js +20 -19
- package/out/zero-cache/src/services/change-streamer/change-streamer-http.js.map +1 -1
- package/out/zero-cache/src/services/change-streamer/change-streamer-service.d.ts +90 -24
- package/out/zero-cache/src/services/change-streamer/change-streamer-service.d.ts.map +1 -1
- package/out/zero-cache/src/services/change-streamer/change-streamer-service.js +456 -66
- package/out/zero-cache/src/services/change-streamer/change-streamer-service.js.map +1 -1
- package/out/zero-cache/src/services/change-streamer/change-streamer.d.ts +50 -13
- package/out/zero-cache/src/services/change-streamer/change-streamer.d.ts.map +1 -1
- package/out/zero-cache/src/services/change-streamer/change-streamer.js.map +1 -1
- package/out/zero-cache/src/services/change-streamer/error-type-enum.d.ts +8 -0
- package/out/zero-cache/src/services/change-streamer/error-type-enum.d.ts.map +1 -1
- package/out/zero-cache/src/services/change-streamer/forwarder.d.ts +14 -3
- package/out/zero-cache/src/services/change-streamer/forwarder.d.ts.map +1 -1
- package/out/zero-cache/src/services/change-streamer/forwarder.js +42 -12
- package/out/zero-cache/src/services/change-streamer/forwarder.js.map +1 -1
- package/out/zero-cache/src/services/change-streamer/{litestream3-backup-monitor.d.ts → litestream3-prometheus-poller.d.ts} +19 -45
- package/out/zero-cache/src/services/change-streamer/litestream3-prometheus-poller.d.ts.map +1 -0
- package/out/zero-cache/src/services/change-streamer/{litestream3-backup-monitor.js → litestream3-prometheus-poller.js} +68 -176
- package/out/zero-cache/src/services/change-streamer/litestream3-prometheus-poller.js.map +1 -0
- package/out/zero-cache/src/services/change-streamer/replica-poller.d.ts +15 -0
- package/out/zero-cache/src/services/change-streamer/replica-poller.d.ts.map +1 -0
- package/out/zero-cache/src/services/change-streamer/replica-poller.js +55 -0
- package/out/zero-cache/src/services/change-streamer/replica-poller.js.map +1 -0
- package/out/zero-cache/src/services/change-streamer/schema/tables.d.ts +5 -1
- package/out/zero-cache/src/services/change-streamer/schema/tables.d.ts.map +1 -1
- package/out/zero-cache/src/services/change-streamer/schema/tables.js +2 -1
- package/out/zero-cache/src/services/change-streamer/schema/tables.js.map +1 -1
- package/out/zero-cache/src/services/change-streamer/shard-sampling.d.ts +11 -0
- package/out/zero-cache/src/services/change-streamer/shard-sampling.d.ts.map +1 -0
- package/out/zero-cache/src/services/change-streamer/shard-sampling.js +19 -0
- package/out/zero-cache/src/services/change-streamer/shard-sampling.js.map +1 -0
- package/out/zero-cache/src/services/change-streamer/snapshot-reservations.d.ts +24 -0
- package/out/zero-cache/src/services/change-streamer/snapshot-reservations.d.ts.map +1 -0
- package/out/zero-cache/src/services/change-streamer/snapshot-reservations.js +119 -0
- package/out/zero-cache/src/services/change-streamer/snapshot-reservations.js.map +1 -0
- package/out/zero-cache/src/services/change-streamer/snapshot.d.ts +4 -1
- package/out/zero-cache/src/services/change-streamer/snapshot.d.ts.map +1 -1
- package/out/zero-cache/src/services/change-streamer/snapshot.js +39 -14
- package/out/zero-cache/src/services/change-streamer/snapshot.js.map +1 -1
- package/out/zero-cache/src/services/change-streamer/sqlite-change-log-catchup.d.ts +99 -0
- package/out/zero-cache/src/services/change-streamer/sqlite-change-log-catchup.d.ts.map +1 -0
- package/out/zero-cache/src/services/change-streamer/sqlite-change-log-catchup.js +344 -0
- package/out/zero-cache/src/services/change-streamer/sqlite-change-log-catchup.js.map +1 -0
- package/out/zero-cache/src/services/change-streamer/sqlite-change-log-comparator.d.ts +83 -0
- package/out/zero-cache/src/services/change-streamer/sqlite-change-log-comparator.d.ts.map +1 -0
- package/out/zero-cache/src/services/change-streamer/sqlite-change-log-comparator.js +417 -0
- package/out/zero-cache/src/services/change-streamer/sqlite-change-log-comparator.js.map +1 -0
- package/out/zero-cache/src/services/change-streamer/sqlite-change-log-purge-scheduler.d.ts +121 -0
- package/out/zero-cache/src/services/change-streamer/sqlite-change-log-purge-scheduler.d.ts.map +1 -0
- package/out/zero-cache/src/services/change-streamer/sqlite-change-log-purge-scheduler.js +391 -0
- package/out/zero-cache/src/services/change-streamer/sqlite-change-log-purge-scheduler.js.map +1 -0
- package/out/zero-cache/src/services/change-streamer/sqlite-change-log-read-router.d.ts +73 -0
- package/out/zero-cache/src/services/change-streamer/sqlite-change-log-read-router.d.ts.map +1 -0
- package/out/zero-cache/src/services/change-streamer/sqlite-change-log-read-router.js +157 -0
- package/out/zero-cache/src/services/change-streamer/sqlite-change-log-read-router.js.map +1 -0
- package/out/zero-cache/src/services/change-streamer/sqlite-change-log-reader.d.ts +62 -0
- package/out/zero-cache/src/services/change-streamer/sqlite-change-log-reader.d.ts.map +1 -0
- package/out/zero-cache/src/services/change-streamer/sqlite-change-log-reader.js +164 -0
- package/out/zero-cache/src/services/change-streamer/sqlite-change-log-reader.js.map +1 -0
- package/out/zero-cache/src/services/change-streamer/sqlite-change-log-writer.d.ts +109 -0
- package/out/zero-cache/src/services/change-streamer/sqlite-change-log-writer.d.ts.map +1 -0
- package/out/zero-cache/src/services/change-streamer/sqlite-change-log-writer.js +258 -0
- package/out/zero-cache/src/services/change-streamer/sqlite-change-log-writer.js.map +1 -0
- package/out/zero-cache/src/services/change-streamer/storer.d.ts +85 -12
- package/out/zero-cache/src/services/change-streamer/storer.d.ts.map +1 -1
- package/out/zero-cache/src/services/change-streamer/storer.js +286 -141
- package/out/zero-cache/src/services/change-streamer/storer.js.map +1 -1
- package/out/zero-cache/src/services/change-streamer/subscriber.d.ts +61 -10
- package/out/zero-cache/src/services/change-streamer/subscriber.d.ts.map +1 -1
- package/out/zero-cache/src/services/change-streamer/subscriber.js +101 -8
- package/out/zero-cache/src/services/change-streamer/subscriber.js.map +1 -1
- package/out/zero-cache/src/services/change-streamer/upstream-acker.d.ts +34 -0
- package/out/zero-cache/src/services/change-streamer/upstream-acker.d.ts.map +1 -0
- package/out/zero-cache/src/services/change-streamer/upstream-acker.js +86 -0
- package/out/zero-cache/src/services/change-streamer/upstream-acker.js.map +1 -0
- package/out/zero-cache/src/services/change-streamer/vfs-watermark-poller.d.ts +29 -0
- package/out/zero-cache/src/services/change-streamer/vfs-watermark-poller.d.ts.map +1 -0
- package/out/zero-cache/src/services/change-streamer/vfs-watermark-poller.js +154 -0
- package/out/zero-cache/src/services/change-streamer/vfs-watermark-poller.js.map +1 -0
- package/out/zero-cache/src/services/http-service.d.ts +1 -0
- package/out/zero-cache/src/services/http-service.d.ts.map +1 -1
- package/out/zero-cache/src/services/http-service.js +7 -3
- package/out/zero-cache/src/services/http-service.js.map +1 -1
- package/out/zero-cache/src/services/life-cycle.d.ts +1 -1
- package/out/zero-cache/src/services/life-cycle.d.ts.map +1 -1
- package/out/zero-cache/src/services/life-cycle.js +4 -3
- package/out/zero-cache/src/services/life-cycle.js.map +1 -1
- package/out/zero-cache/src/services/litestream/commands.d.ts +12 -11
- package/out/zero-cache/src/services/litestream/commands.d.ts.map +1 -1
- package/out/zero-cache/src/services/litestream/commands.js +115 -152
- package/out/zero-cache/src/services/litestream/commands.js.map +1 -1
- package/out/zero-cache/src/services/litestream/config-v5.yml +42 -0
- package/out/zero-cache/src/services/litestream/config.yml +3 -2
- package/out/zero-cache/src/services/litestream/metrics.d.ts +5 -4
- package/out/zero-cache/src/services/litestream/metrics.d.ts.map +1 -1
- package/out/zero-cache/src/services/litestream/metrics.js +10 -10
- package/out/zero-cache/src/services/litestream/metrics.js.map +1 -1
- package/out/zero-cache/src/services/mutagen/mutagen.d.ts.map +1 -1
- package/out/zero-cache/src/services/mutagen/mutagen.js +5 -2
- package/out/zero-cache/src/services/mutagen/mutagen.js.map +1 -1
- package/out/zero-cache/src/services/replicator/change-log-cookies.d.ts +169 -0
- package/out/zero-cache/src/services/replicator/change-log-cookies.d.ts.map +1 -0
- package/out/zero-cache/src/services/replicator/change-log-cookies.js +434 -0
- package/out/zero-cache/src/services/replicator/change-log-cookies.js.map +1 -0
- package/out/zero-cache/src/services/replicator/change-log-db.d.ts +368 -0
- package/out/zero-cache/src/services/replicator/change-log-db.d.ts.map +1 -0
- package/out/zero-cache/src/services/replicator/change-log-db.js +491 -0
- package/out/zero-cache/src/services/replicator/change-log-db.js.map +1 -0
- package/out/zero-cache/src/services/replicator/change-log-stream-writer.d.ts +55 -0
- package/out/zero-cache/src/services/replicator/change-log-stream-writer.d.ts.map +1 -0
- package/out/zero-cache/src/services/replicator/change-log-stream-writer.js +150 -0
- package/out/zero-cache/src/services/replicator/change-log-stream-writer.js.map +1 -0
- package/out/zero-cache/src/services/replicator/change-processor.d.ts +6 -0
- package/out/zero-cache/src/services/replicator/change-processor.d.ts.map +1 -1
- package/out/zero-cache/src/services/replicator/change-processor.js +70 -25
- package/out/zero-cache/src/services/replicator/change-processor.js.map +1 -1
- package/out/zero-cache/src/services/replicator/incremental-sync.d.ts +1 -1
- package/out/zero-cache/src/services/replicator/incremental-sync.d.ts.map +1 -1
- package/out/zero-cache/src/services/replicator/incremental-sync.js +19 -6
- package/out/zero-cache/src/services/replicator/incremental-sync.js.map +1 -1
- package/out/zero-cache/src/services/replicator/notifier.d.ts +0 -22
- package/out/zero-cache/src/services/replicator/notifier.d.ts.map +1 -1
- package/out/zero-cache/src/services/replicator/notifier.js +7 -1
- package/out/zero-cache/src/services/replicator/notifier.js.map +1 -1
- package/out/zero-cache/src/services/replicator/replicator.d.ts +17 -2
- package/out/zero-cache/src/services/replicator/replicator.d.ts.map +1 -1
- package/out/zero-cache/src/services/replicator/replicator.js +9 -3
- package/out/zero-cache/src/services/replicator/replicator.js.map +1 -1
- package/out/zero-cache/src/services/replicator/reporter/recorder.d.ts +27 -0
- package/out/zero-cache/src/services/replicator/reporter/recorder.d.ts.map +1 -1
- package/out/zero-cache/src/services/replicator/reporter/recorder.js +32 -0
- package/out/zero-cache/src/services/replicator/reporter/recorder.js.map +1 -1
- package/out/zero-cache/src/services/replicator/reporter/report-schema.d.ts +1 -1
- package/out/zero-cache/src/services/replicator/schema/backfilling.d.ts +119 -0
- package/out/zero-cache/src/services/replicator/schema/backfilling.d.ts.map +1 -0
- package/out/zero-cache/src/services/replicator/schema/backfilling.js +214 -0
- package/out/zero-cache/src/services/replicator/schema/backfilling.js.map +1 -0
- package/out/zero-cache/src/services/replicator/schema/change-log.d.ts +3 -3
- package/out/zero-cache/src/services/replicator/schema/column-metadata.js +1 -1
- package/out/zero-cache/src/services/replicator/schema/column-metadata.js.map +1 -1
- package/out/zero-cache/src/services/replicator/schema/replication-state.d.ts +1 -1
- package/out/zero-cache/src/services/replicator/schema/replication-state.d.ts.map +1 -1
- package/out/zero-cache/src/services/replicator/schema/replication-state.js +9 -5
- package/out/zero-cache/src/services/replicator/schema/replication-state.js.map +1 -1
- package/out/zero-cache/src/services/replicator/sqlite-change-log-observability.d.ts +132 -0
- package/out/zero-cache/src/services/replicator/sqlite-change-log-observability.d.ts.map +1 -0
- package/out/zero-cache/src/services/replicator/sqlite-change-log-observability.js +415 -0
- package/out/zero-cache/src/services/replicator/sqlite-change-log-observability.js.map +1 -0
- package/out/zero-cache/src/services/replicator/sqlite-change-log-purger.d.ts +120 -0
- package/out/zero-cache/src/services/replicator/sqlite-change-log-purger.d.ts.map +1 -0
- package/out/zero-cache/src/services/replicator/sqlite-change-log-purger.js +283 -0
- package/out/zero-cache/src/services/replicator/sqlite-change-log-purger.js.map +1 -0
- package/out/zero-cache/src/services/replicator/write-worker.js +23 -12
- package/out/zero-cache/src/services/replicator/write-worker.js.map +1 -1
- package/out/zero-cache/src/services/run-ast.d.ts.map +1 -1
- package/out/zero-cache/src/services/run-ast.js +2 -1
- package/out/zero-cache/src/services/run-ast.js.map +1 -1
- package/out/zero-cache/src/services/running-state.d.ts +1 -1
- package/out/zero-cache/src/services/running-state.d.ts.map +1 -1
- package/out/zero-cache/src/services/running-state.js +1 -0
- package/out/zero-cache/src/services/running-state.js.map +1 -1
- package/out/zero-cache/src/services/view-syncer/client-handler.d.ts +3 -2
- package/out/zero-cache/src/services/view-syncer/client-handler.d.ts.map +1 -1
- package/out/zero-cache/src/services/view-syncer/client-handler.js +25 -17
- package/out/zero-cache/src/services/view-syncer/client-handler.js.map +1 -1
- package/out/zero-cache/src/services/view-syncer/cvr-store.d.ts.map +1 -1
- package/out/zero-cache/src/services/view-syncer/cvr-store.js +14 -1
- package/out/zero-cache/src/services/view-syncer/cvr-store.js.map +1 -1
- package/out/zero-cache/src/services/view-syncer/e2e-serving-lag.d.ts +53 -0
- package/out/zero-cache/src/services/view-syncer/e2e-serving-lag.d.ts.map +1 -0
- package/out/zero-cache/src/services/view-syncer/e2e-serving-lag.js +68 -0
- package/out/zero-cache/src/services/view-syncer/e2e-serving-lag.js.map +1 -0
- package/out/zero-cache/src/services/view-syncer/pipeline-driver.d.ts.map +1 -1
- package/out/zero-cache/src/services/view-syncer/pipeline-driver.js +18 -3
- package/out/zero-cache/src/services/view-syncer/pipeline-driver.js.map +1 -1
- package/out/zero-cache/src/services/view-syncer/snapshotter.d.ts.map +1 -1
- package/out/zero-cache/src/services/view-syncer/snapshotter.js.map +1 -1
- package/out/zero-cache/src/services/view-syncer/view-syncer.d.ts +14 -4
- package/out/zero-cache/src/services/view-syncer/view-syncer.d.ts.map +1 -1
- package/out/zero-cache/src/services/view-syncer/view-syncer.js +70 -8
- package/out/zero-cache/src/services/view-syncer/view-syncer.js.map +1 -1
- package/out/zero-cache/src/types/downstream.d.ts +11 -0
- package/out/zero-cache/src/types/downstream.d.ts.map +1 -0
- package/out/zero-cache/src/types/pg.d.ts.map +1 -1
- package/out/zero-cache/src/types/pg.js +14 -4
- package/out/zero-cache/src/types/pg.js.map +1 -1
- package/out/zero-cache/src/types/poke-chunk.d.ts +18 -0
- package/out/zero-cache/src/types/poke-chunk.d.ts.map +1 -0
- package/out/zero-cache/src/types/poke-chunk.js +57 -0
- package/out/zero-cache/src/types/poke-chunk.js.map +1 -0
- package/out/zero-cache/src/types/processes.d.ts +1 -2
- package/out/zero-cache/src/types/processes.d.ts.map +1 -1
- package/out/zero-cache/src/types/processes.js +1 -28
- package/out/zero-cache/src/types/processes.js.map +1 -1
- package/out/zero-cache/src/types/streams.d.ts +16 -0
- package/out/zero-cache/src/types/streams.d.ts.map +1 -1
- package/out/zero-cache/src/types/streams.js +25 -4
- package/out/zero-cache/src/types/streams.js.map +1 -1
- package/out/zero-cache/src/types/subscription.d.ts +2 -0
- package/out/zero-cache/src/types/subscription.d.ts.map +1 -1
- package/out/zero-cache/src/types/subscription.js +6 -0
- package/out/zero-cache/src/types/subscription.js.map +1 -1
- package/out/zero-cache/src/workers/connection.d.ts +23 -4
- package/out/zero-cache/src/workers/connection.d.ts.map +1 -1
- package/out/zero-cache/src/workers/connection.js +130 -10
- package/out/zero-cache/src/workers/connection.js.map +1 -1
- package/out/zero-cache/src/workers/replicator.d.ts +25 -0
- package/out/zero-cache/src/workers/replicator.d.ts.map +1 -1
- package/out/zero-cache/src/workers/replicator.js +33 -1
- package/out/zero-cache/src/workers/replicator.js.map +1 -1
- package/out/zero-cache/src/workers/syncer.d.ts +12 -0
- package/out/zero-cache/src/workers/syncer.d.ts.map +1 -1
- package/out/zero-cache/src/workers/syncer.js +75 -0
- package/out/zero-cache/src/workers/syncer.js.map +1 -1
- package/out/zero-client/src/client/version.js +1 -1
- package/out/zero-client/src/client/zero-poke-handler.d.ts +7 -2
- package/out/zero-client/src/client/zero-poke-handler.d.ts.map +1 -1
- package/out/zero-client/src/client/zero-poke-handler.js +52 -2
- package/out/zero-client/src/client/zero-poke-handler.js.map +1 -1
- package/out/zero-client/src/client/zero.d.ts +6 -7
- package/out/zero-client/src/client/zero.d.ts.map +1 -1
- package/out/zero-client/src/client/zero.js +194 -107
- package/out/zero-client/src/client/zero.js.map +1 -1
- package/out/zero-protocol/src/down.d.ts +1 -1
- package/out/zero-protocol/src/poke.d.ts +89 -7
- package/out/zero-protocol/src/poke.d.ts.map +1 -1
- package/out/zero-protocol/src/poke.js +16 -8
- package/out/zero-protocol/src/poke.js.map +1 -1
- package/out/zero-protocol/src/protocol-version.d.ts +12 -7
- package/out/zero-protocol/src/protocol-version.d.ts.map +1 -1
- package/out/zero-protocol/src/protocol-version.js.map +1 -1
- package/out/zero-schema/src/builder/table-builder.d.ts +23 -0
- package/out/zero-schema/src/builder/table-builder.d.ts.map +1 -1
- package/out/zero-schema/src/builder/table-builder.js +18 -0
- package/out/zero-schema/src/builder/table-builder.js.map +1 -1
- package/out/zero-server/src/custom.js +10 -3
- package/out/zero-server/src/custom.js.map +1 -1
- package/out/zero-server/src/schema.d.ts +8 -0
- package/out/zero-server/src/schema.d.ts.map +1 -1
- package/out/zero-server/src/schema.js +63 -24
- package/out/zero-server/src/schema.js.map +1 -1
- package/out/zero-types/src/schema.d.ts +11 -0
- package/out/zero-types/src/schema.d.ts.map +1 -1
- package/out/zql/src/ivm/memory-source.d.ts +10 -2
- package/out/zql/src/ivm/memory-source.d.ts.map +1 -1
- package/out/zql/src/ivm/memory-source.js +14 -6
- package/out/zql/src/ivm/memory-source.js.map +1 -1
- package/out/zql/src/ivm/stream.d.ts +0 -1
- package/out/zql/src/ivm/stream.d.ts.map +1 -1
- package/out/zql/src/ivm/stream.js +1 -7
- package/out/zql/src/ivm/stream.js.map +1 -1
- package/out/zql/src/ivm/union-fan-in.d.ts +1 -1
- package/out/zql/src/ivm/union-fan-in.d.ts.map +1 -1
- package/out/zql/src/ivm/union-fan-in.js +11 -2
- package/out/zql/src/ivm/union-fan-in.js.map +1 -1
- package/out/zql/src/mutate/crud.d.ts +10 -8
- package/out/zql/src/mutate/crud.d.ts.map +1 -1
- package/out/zql/src/mutate/crud.js.map +1 -1
- package/out/zql/src/query/query-delegate-base.d.ts.map +1 -1
- package/out/zql/src/query/query-delegate-base.js +5 -1
- package/out/zql/src/query/query-delegate-base.js.map +1 -1
- package/out/zql/src/query/query-impl.d.ts +2 -2
- package/out/zql/src/query/query-impl.d.ts.map +1 -1
- package/out/zql/src/query/query-impl.js.map +1 -1
- package/out/zql/src/query/query.d.ts +83 -14
- package/out/zql/src/query/query.d.ts.map +1 -1
- package/out/zql/src/query/static-query.d.ts +1 -1
- package/out/zql/src/query/static-query.d.ts.map +1 -1
- package/out/zqlite/src/db.js +2 -2
- package/out/zqlite/src/resolve-scalar-subqueries.d.ts +15 -0
- package/out/zqlite/src/resolve-scalar-subqueries.d.ts.map +1 -1
- package/out/zqlite/src/resolve-scalar-subqueries.js +33 -14
- package/out/zqlite/src/resolve-scalar-subqueries.js.map +1 -1
- package/out/zqlite/src/sqlite-cost-model.js +5 -5
- package/out/zqlite/src/table-source.d.ts.map +1 -1
- package/out/zqlite/src/table-source.js +4 -4
- package/out/zqlite/src/table-source.js.map +1 -1
- package/package.json +3 -3
- package/out/replicache/src/db/index.js +0 -91
- package/out/replicache/src/db/index.js.map +0 -1
- package/out/replicache/src/lazy.d.ts +0 -2
- package/out/replicache/src/lazy.d.ts.map +0 -1
- package/out/replicache/src/lazy.js +0 -12
- package/out/replicache/src/lazy.js.map +0 -1
- package/out/zero-cache/src/server/backup-watermark-reader.js +0 -35
- package/out/zero-cache/src/server/backup-watermark-reader.js.map +0 -1
- package/out/zero-cache/src/services/change-streamer/litestream3-backup-monitor.d.ts.map +0 -1
- package/out/zero-cache/src/services/change-streamer/litestream3-backup-monitor.js.map +0 -1
- package/out/zero-cache/src/services/change-streamer/replica-monitor.d.ts +0 -16
- package/out/zero-cache/src/services/change-streamer/replica-monitor.d.ts.map +0 -1
- package/out/zero-cache/src/services/change-streamer/replica-monitor.js +0 -54
- package/out/zero-cache/src/services/change-streamer/replica-monitor.js.map +0 -1
- package/out/zero-cache/src/services/change-streamer/vfs-backup-monitor.d.ts +0 -25
- package/out/zero-cache/src/services/change-streamer/vfs-backup-monitor.d.ts.map +0 -1
- package/out/zero-cache/src/services/change-streamer/vfs-backup-monitor.js +0 -159
- package/out/zero-cache/src/services/change-streamer/vfs-backup-monitor.js.map +0 -1
- package/out/zero-cache/src/services/litestream/vfs-watermark-reader.d.ts +0 -44
- package/out/zero-cache/src/services/litestream/vfs-watermark-reader.d.ts.map +0 -1
- package/out/zero-cache/src/services/litestream/vfs-watermark-reader.js +0 -65
- package/out/zero-cache/src/services/litestream/vfs-watermark-reader.js.map +0 -1
- package/out/zero-cache/src/services/litestream/vfs-watermark-worker-source.d.ts +0 -11
- package/out/zero-cache/src/services/litestream/vfs-watermark-worker-source.d.ts.map +0 -1
- package/out/zero-cache/src/services/litestream/vfs-watermark-worker-source.js +0 -74
- package/out/zero-cache/src/services/litestream/vfs-watermark-worker-source.js.map +0 -1
- package/out/zero-cache/src/services/litestream/vfs-watermark-worker.d.ts +0 -42
- package/out/zero-cache/src/services/litestream/vfs-watermark-worker.d.ts.map +0 -1
- package/out/zero-cache/src/services/litestream/vfs-watermark-worker.js +0 -117
- package/out/zero-cache/src/services/litestream/vfs-watermark-worker.js.map +0 -1
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The change log's *second* job.
|
|
3
|
+
*
|
|
4
|
+
* A change log is a buffer **and** a cookie jar. The buffer catches a
|
|
5
|
+
* reconnecting subscriber up to the head; the cookie jar holds the backfill
|
|
6
|
+
* progress state that the change-streamer hands the change-source on every
|
|
7
|
+
* `startStream`, so that the change source never has to persist backfill state
|
|
8
|
+
* upstream. See `change-log-db.ts` for the buffer.
|
|
9
|
+
*
|
|
10
|
+
* There are two cookies, mirroring the two `cdc` tables the Postgres change log
|
|
11
|
+
* has always carried (`change-streamer/schema/tables.ts`):
|
|
12
|
+
*
|
|
13
|
+
* - **table metadata**, the most current {@link TableMetadata} of a table, which
|
|
14
|
+
* a {@link BackfillRequest} has to carry; and
|
|
15
|
+
* - **backfilling columns**, the opaque {@link BackfillID} of every column whose
|
|
16
|
+
* backfill has not completed.
|
|
17
|
+
*
|
|
18
|
+
* Both are a *fold over the change stream*: the cookie set is only meaningful
|
|
19
|
+
* paired with the watermark it was folded up to. {@link cookieOps} is that fold,
|
|
20
|
+
* expressed transport-free so that the Postgres change log and the SQLite change
|
|
21
|
+
* log cannot drift from each other — they must agree on all eight transitions
|
|
22
|
+
* forever, and the failure mode if they disagree is a backfill that is silently
|
|
23
|
+
* never re-requested. The two interpreters are {@link ChangeLogCookieWriter}
|
|
24
|
+
* here and `Storer.#trackBackfillMetadata()` in
|
|
25
|
+
* `change-streamer/storer.ts`.
|
|
26
|
+
*
|
|
27
|
+
* The tables live in the change-log database rather than in the replica: the
|
|
28
|
+
* replicator is a subscriber *downstream* of the change-streamer's write loop,
|
|
29
|
+
* so its state version trails the log's head, and pairing its cookies with the
|
|
30
|
+
* log's resume watermark would lose every backfill that completed in between.
|
|
31
|
+
* The replica's own copies (`_zero.tableMetadata`, `_zero.column_metadata`) are
|
|
32
|
+
* the *seed* source; these are the *working* set.
|
|
33
|
+
*/
|
|
34
|
+
import type { Database } from '../../../../zqlite/src/db.ts';
|
|
35
|
+
import type { BackfillID, Identifier, SchemaChange, TableMetadata } from '../change-source/protocol/current/data.ts';
|
|
36
|
+
import { type BackfillRequest } from '../change-source/protocol/current/upstream.ts';
|
|
37
|
+
export declare const CHANGE_LOG_TABLE_METADATA_TABLE = "_zero.changeLogTableMetadata";
|
|
38
|
+
export declare const CHANGE_LOG_BACKFILLING_TABLE = "_zero.changeLogBackfilling";
|
|
39
|
+
export declare const CREATE_CHANGE_LOG_COOKIE_SCHEMA = "\n CREATE TABLE \"_zero.changeLogTableMetadata\" (\n \"schema\" TEXT NOT NULL,\n \"table\" TEXT NOT NULL,\n \"metadata\" TEXT NOT NULL,\n PRIMARY KEY (\"schema\", \"table\")\n );\n\n CREATE TABLE \"_zero.changeLogBackfilling\" (\n \"schema\" TEXT NOT NULL,\n \"table\" TEXT NOT NULL,\n \"column\" TEXT NOT NULL,\n \"backfill\" TEXT NOT NULL,\n PRIMARY KEY (\"schema\", \"table\", \"column\")\n );\n";
|
|
40
|
+
export declare const DROP_CHANGE_LOG_COOKIE_TABLES = "\n DROP TABLE IF EXISTS \"_zero.changeLogTableMetadata\";\n DROP TABLE IF EXISTS \"_zero.changeLogBackfilling\";\n";
|
|
41
|
+
export type TableMetadataCookie = {
|
|
42
|
+
readonly schema: string;
|
|
43
|
+
readonly table: string;
|
|
44
|
+
readonly metadata: TableMetadata;
|
|
45
|
+
};
|
|
46
|
+
export type BackfillCookie = {
|
|
47
|
+
readonly schema: string;
|
|
48
|
+
readonly table: string;
|
|
49
|
+
readonly column: string;
|
|
50
|
+
readonly backfill: BackfillID;
|
|
51
|
+
};
|
|
52
|
+
/**
|
|
53
|
+
* The whole cookie set, as of the log's head. Both lists are ordered by their
|
|
54
|
+
* primary key so that two stores' sets can be compared directly.
|
|
55
|
+
*/
|
|
56
|
+
export type CookieSet = {
|
|
57
|
+
readonly tableMetadata: readonly TableMetadataCookie[];
|
|
58
|
+
readonly backfilling: readonly BackfillCookie[];
|
|
59
|
+
};
|
|
60
|
+
export declare const EMPTY_COOKIE_SET: CookieSet;
|
|
61
|
+
/**
|
|
62
|
+
* A transport-free description of a cookie mutation. This is the whole of what
|
|
63
|
+
* a {@link SchemaChange} means to the cookie jar; everything else about the
|
|
64
|
+
* change belongs to the buffer.
|
|
65
|
+
*/
|
|
66
|
+
export type CookieOp = {
|
|
67
|
+
op: 'upsert-metadata';
|
|
68
|
+
table: Identifier;
|
|
69
|
+
metadata: TableMetadata;
|
|
70
|
+
} | {
|
|
71
|
+
op: 'upsert-backfill';
|
|
72
|
+
table: Identifier;
|
|
73
|
+
column: string;
|
|
74
|
+
backfill: BackfillID;
|
|
75
|
+
} | {
|
|
76
|
+
op: 'rename-table';
|
|
77
|
+
old: Identifier;
|
|
78
|
+
new: Identifier;
|
|
79
|
+
} | {
|
|
80
|
+
op: 'drop-table';
|
|
81
|
+
table: Identifier;
|
|
82
|
+
} | {
|
|
83
|
+
op: 'rename-column';
|
|
84
|
+
table: Identifier;
|
|
85
|
+
old: string;
|
|
86
|
+
new: string;
|
|
87
|
+
} | {
|
|
88
|
+
op: 'drop-column';
|
|
89
|
+
table: Identifier;
|
|
90
|
+
column: string;
|
|
91
|
+
} | {
|
|
92
|
+
op: 'complete-backfill';
|
|
93
|
+
table: Identifier;
|
|
94
|
+
columns: readonly string[];
|
|
95
|
+
};
|
|
96
|
+
export type CookieOpTag = CookieOp['op'];
|
|
97
|
+
/**
|
|
98
|
+
* The fold, and the only place either store decides what a schema change means
|
|
99
|
+
* for the cookie set. Both interpreters are mechanical translations of what this
|
|
100
|
+
* returns, in the order it returns them.
|
|
101
|
+
*
|
|
102
|
+
* Changes that carry no cookie state — index changes, and the `create-table` /
|
|
103
|
+
* `add-column` variants whose optional `metadata` and `backfill` fields are
|
|
104
|
+
* absent — produce no ops.
|
|
105
|
+
*/
|
|
106
|
+
export declare function cookieOps(change: SchemaChange): CookieOp[];
|
|
107
|
+
/**
|
|
108
|
+
* The SQLite interpreter of {@link cookieOps}, over prepared statements on the
|
|
109
|
+
* change-log database.
|
|
110
|
+
*
|
|
111
|
+
* The statements run inside the log's transaction, in stream order, at the point
|
|
112
|
+
* the schema change is appended (see `ChangeLogStreamWriter`). That is what
|
|
113
|
+
* makes the cookie set atomic with the head — a crash cannot leave cookies ahead
|
|
114
|
+
* of or behind the rows they were folded from — and what makes an aborted
|
|
115
|
+
* transaction discard its cookies with its rows, for free.
|
|
116
|
+
*
|
|
117
|
+
* Statements are prepared against the tables as they exist now, so an instance
|
|
118
|
+
* does not survive a reconcile that drops and recreates them.
|
|
119
|
+
*/
|
|
120
|
+
export declare class ChangeLogCookieWriter {
|
|
121
|
+
#private;
|
|
122
|
+
constructor(db: Database);
|
|
123
|
+
/** Applies the change's cookie ops, returning the ops that were applied. */
|
|
124
|
+
apply(change: SchemaChange): CookieOp[];
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* The in-memory interpreter of {@link cookieOps}: the third one, and the only
|
|
128
|
+
* one that is not a store.
|
|
129
|
+
*
|
|
130
|
+
* A replica-derived cookie set is a snapshot at the replica's state version,
|
|
131
|
+
* which trails the change log's head, so it cannot be compared with a
|
|
132
|
+
* Postgres-derived set directly. This carries it forward over the schema changes
|
|
133
|
+
* the log holds in between, which turns "the two stores disagree, but they are
|
|
134
|
+
* also at different positions" into an exact equality — and makes a
|
|
135
|
+
* disagreement between any two of the three interpreters visible as an
|
|
136
|
+
* inequality that neither store would have noticed on its own.
|
|
137
|
+
*
|
|
138
|
+
* `changes` must be the log's schema changes over `(from, to]` in stream order.
|
|
139
|
+
* Anything else produces a set that belongs to no watermark.
|
|
140
|
+
*/
|
|
141
|
+
export declare function foldCookies(cookies: CookieSet, changes: Iterable<SchemaChange>): CookieSet;
|
|
142
|
+
/**
|
|
143
|
+
* Returns one {@link BackfillRequest} for each table with an active backfill.
|
|
144
|
+
* Each request contains the stored table metadata, if available.
|
|
145
|
+
*/
|
|
146
|
+
export declare function backfillRequestsFrom(cookies: CookieSet): BackfillRequest[];
|
|
147
|
+
/**
|
|
148
|
+
* Reads the whole cookie set, ordered by primary key. This is what a
|
|
149
|
+
* change-streamer would hand `startStream`, and what the Postgres-derived and
|
|
150
|
+
* replica-derived sets are compared against.
|
|
151
|
+
*/
|
|
152
|
+
export declare function readCookies(db: Database): CookieSet;
|
|
153
|
+
/**
|
|
154
|
+
* Replaces the cookie set wholesale.
|
|
155
|
+
*
|
|
156
|
+
* The cookies are unversioned point-in-time state, so a reconciliation that
|
|
157
|
+
* moves the head invalidates them: truncating the stream above `W` does not roll
|
|
158
|
+
* the cookie set back to `W`, and the truncated transactions can contain
|
|
159
|
+
* `create-table`, `add-column`, and `backfill-completed`. The caller must run
|
|
160
|
+
* this in the same transaction as the reconciliation that invalidated them.
|
|
161
|
+
*/
|
|
162
|
+
export declare function replaceCookies(db: Database, cookies: CookieSet): void;
|
|
163
|
+
/** Retained cookie rows, by table. Both are normally zero. */
|
|
164
|
+
export type CookieRowCounts = {
|
|
165
|
+
readonly tableMetadata: number;
|
|
166
|
+
readonly backfilling: number;
|
|
167
|
+
};
|
|
168
|
+
export declare function readCookieRowCounts(db: Database): CookieRowCounts;
|
|
169
|
+
//# sourceMappingURL=change-log-cookies.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"change-log-cookies.d.ts","sourceRoot":"","sources":["../../../../../../zero-cache/src/services/replicator/change-log-cookies.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AAKH,OAAO,KAAK,EAAC,QAAQ,EAAY,MAAM,8BAA8B,CAAC;AACtE,OAAO,KAAK,EACV,UAAU,EACV,UAAU,EACV,YAAY,EACZ,aAAa,EACd,MAAM,2CAA2C,CAAC;AACnD,OAAO,EAEL,KAAK,eAAe,EACrB,MAAM,+CAA+C,CAAC;AAEvD,eAAO,MAAM,+BAA+B,iCAAiC,CAAC;AAC9E,eAAO,MAAM,4BAA4B,+BAA+B,CAAC;AAQzE,eAAO,MAAM,+BAA+B,8bAe3C,CAAC;AAEF,eAAO,MAAM,6BAA6B,yHAGzC,CAAC;AAEF,MAAM,MAAM,mBAAmB,GAAG;IAChC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,QAAQ,EAAE,aAAa,CAAC;CAClC,CAAC;AAEF,MAAM,MAAM,cAAc,GAAG;IAC3B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,QAAQ,EAAE,UAAU,CAAC;CAC/B,CAAC;AAEF;;;GAGG;AACH,MAAM,MAAM,SAAS,GAAG;IACtB,QAAQ,CAAC,aAAa,EAAE,SAAS,mBAAmB,EAAE,CAAC;IACvD,QAAQ,CAAC,WAAW,EAAE,SAAS,cAAc,EAAE,CAAC;CACjD,CAAC;AAEF,eAAO,MAAM,gBAAgB,EAAE,SAG9B,CAAC;AAEF;;;;GAIG;AACH,MAAM,MAAM,QAAQ,GAChB;IAAC,EAAE,EAAE,iBAAiB,CAAC;IAAC,KAAK,EAAE,UAAU,CAAC;IAAC,QAAQ,EAAE,aAAa,CAAA;CAAC,GACnE;IACE,EAAE,EAAE,iBAAiB,CAAC;IACtB,KAAK,EAAE,UAAU,CAAC;IAClB,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,UAAU,CAAC;CACtB,GACD;IAAC,EAAE,EAAE,cAAc,CAAC;IAAC,GAAG,EAAE,UAAU,CAAC;IAAC,GAAG,EAAE,UAAU,CAAA;CAAC,GACtD;IAAC,EAAE,EAAE,YAAY,CAAC;IAAC,KAAK,EAAE,UAAU,CAAA;CAAC,GACrC;IAAC,EAAE,EAAE,eAAe,CAAC;IAAC,KAAK,EAAE,UAAU,CAAC;IAAC,GAAG,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,MAAM,CAAA;CAAC,GAClE;IAAC,EAAE,EAAE,aAAa,CAAC;IAAC,KAAK,EAAE,UAAU,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAC,GACtD;IAAC,EAAE,EAAE,mBAAmB,CAAC;IAAC,KAAK,EAAE,UAAU,CAAC;IAAC,OAAO,EAAE,SAAS,MAAM,EAAE,CAAA;CAAC,CAAC;AAE7E,MAAM,MAAM,WAAW,GAAG,QAAQ,CAAC,IAAI,CAAC,CAAC;AAEzC;;;;;;;;GAQG;AACH,wBAAgB,SAAS,CAAC,MAAM,EAAE,YAAY,GAAG,QAAQ,EAAE,CAmF1D;AAED;;;;;;;;;;;;GAYG;AACH,qBAAa,qBAAqB;;gBAUpB,EAAE,EAAE,QAAQ;IAuCxB,4EAA4E;IAC5E,KAAK,CAAC,MAAM,EAAE,YAAY,GAAG,QAAQ,EAAE;CAiFxC;AAUD;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,WAAW,CACzB,OAAO,EAAE,SAAS,EAClB,OAAO,EAAE,QAAQ,CAAC,YAAY,CAAC,GAC9B,SAAS,CA6GX;AAID;;;GAGG;AACH,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,SAAS,GAAG,eAAe,EAAE,CAuB1E;AAED;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,EAAE,EAAE,QAAQ,GAAG,SAAS,CA6BnD;AAED;;;;;;;;GAQG;AACH,wBAAgB,cAAc,CAAC,EAAE,EAAE,QAAQ,EAAE,OAAO,EAAE,SAAS,GAAG,IAAI,CAsBrE;AAED,8DAA8D;AAC9D,MAAM,MAAM,eAAe,GAAG;IAC5B,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC;IAC/B,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;CAC9B,CAAC;AAEF,wBAAgB,mBAAmB,CAAC,EAAE,EAAE,QAAQ,GAAG,eAAe,CAUjE"}
|
|
@@ -0,0 +1,434 @@
|
|
|
1
|
+
import { unreachable } from "../../../../shared/src/asserts.js";
|
|
2
|
+
import { parse, valita_exports } from "../../../../shared/src/valita.js";
|
|
3
|
+
import { BigIntJSON } from "../../../../shared/src/bigint-json.js";
|
|
4
|
+
import { backfillRequestSchema } from "../change-source/protocol/current/upstream.js";
|
|
5
|
+
//#region ../zero-cache/src/services/replicator/change-log-cookies.ts
|
|
6
|
+
/**
|
|
7
|
+
* The change log's *second* job.
|
|
8
|
+
*
|
|
9
|
+
* A change log is a buffer **and** a cookie jar. The buffer catches a
|
|
10
|
+
* reconnecting subscriber up to the head; the cookie jar holds the backfill
|
|
11
|
+
* progress state that the change-streamer hands the change-source on every
|
|
12
|
+
* `startStream`, so that the change source never has to persist backfill state
|
|
13
|
+
* upstream. See `change-log-db.ts` for the buffer.
|
|
14
|
+
*
|
|
15
|
+
* There are two cookies, mirroring the two `cdc` tables the Postgres change log
|
|
16
|
+
* has always carried (`change-streamer/schema/tables.ts`):
|
|
17
|
+
*
|
|
18
|
+
* - **table metadata**, the most current {@link TableMetadata} of a table, which
|
|
19
|
+
* a {@link BackfillRequest} has to carry; and
|
|
20
|
+
* - **backfilling columns**, the opaque {@link BackfillID} of every column whose
|
|
21
|
+
* backfill has not completed.
|
|
22
|
+
*
|
|
23
|
+
* Both are a *fold over the change stream*: the cookie set is only meaningful
|
|
24
|
+
* paired with the watermark it was folded up to. {@link cookieOps} is that fold,
|
|
25
|
+
* expressed transport-free so that the Postgres change log and the SQLite change
|
|
26
|
+
* log cannot drift from each other — they must agree on all eight transitions
|
|
27
|
+
* forever, and the failure mode if they disagree is a backfill that is silently
|
|
28
|
+
* never re-requested. The two interpreters are {@link ChangeLogCookieWriter}
|
|
29
|
+
* here and `Storer.#trackBackfillMetadata()` in
|
|
30
|
+
* `change-streamer/storer.ts`.
|
|
31
|
+
*
|
|
32
|
+
* The tables live in the change-log database rather than in the replica: the
|
|
33
|
+
* replicator is a subscriber *downstream* of the change-streamer's write loop,
|
|
34
|
+
* so its state version trails the log's head, and pairing its cookies with the
|
|
35
|
+
* log's resume watermark would lose every backfill that completed in between.
|
|
36
|
+
* The replica's own copies (`_zero.tableMetadata`, `_zero.column_metadata`) are
|
|
37
|
+
* the *seed* source; these are the *working* set.
|
|
38
|
+
*/
|
|
39
|
+
var CHANGE_LOG_TABLE_METADATA_TABLE = "_zero.changeLogTableMetadata";
|
|
40
|
+
var CHANGE_LOG_BACKFILLING_TABLE = "_zero.changeLogBackfilling";
|
|
41
|
+
var CREATE_CHANGE_LOG_COOKIE_SCHEMA = `
|
|
42
|
+
CREATE TABLE "${CHANGE_LOG_TABLE_METADATA_TABLE}" (
|
|
43
|
+
"schema" TEXT NOT NULL,
|
|
44
|
+
"table" TEXT NOT NULL,
|
|
45
|
+
"metadata" TEXT NOT NULL,
|
|
46
|
+
PRIMARY KEY ("schema", "table")
|
|
47
|
+
);
|
|
48
|
+
|
|
49
|
+
CREATE TABLE "${CHANGE_LOG_BACKFILLING_TABLE}" (
|
|
50
|
+
"schema" TEXT NOT NULL,
|
|
51
|
+
"table" TEXT NOT NULL,
|
|
52
|
+
"column" TEXT NOT NULL,
|
|
53
|
+
"backfill" TEXT NOT NULL,
|
|
54
|
+
PRIMARY KEY ("schema", "table", "column")
|
|
55
|
+
);
|
|
56
|
+
`;
|
|
57
|
+
var DROP_CHANGE_LOG_COOKIE_TABLES = `
|
|
58
|
+
DROP TABLE IF EXISTS "${CHANGE_LOG_TABLE_METADATA_TABLE}";
|
|
59
|
+
DROP TABLE IF EXISTS "${CHANGE_LOG_BACKFILLING_TABLE}";
|
|
60
|
+
`;
|
|
61
|
+
/**
|
|
62
|
+
* The fold, and the only place either store decides what a schema change means
|
|
63
|
+
* for the cookie set. Both interpreters are mechanical translations of what this
|
|
64
|
+
* returns, in the order it returns them.
|
|
65
|
+
*
|
|
66
|
+
* Changes that carry no cookie state — index changes, and the `create-table` /
|
|
67
|
+
* `add-column` variants whose optional `metadata` and `backfill` fields are
|
|
68
|
+
* absent — produce no ops.
|
|
69
|
+
*/
|
|
70
|
+
function cookieOps(change) {
|
|
71
|
+
switch (change.tag) {
|
|
72
|
+
case "update-table-metadata": return [{
|
|
73
|
+
op: "upsert-metadata",
|
|
74
|
+
table: change.table,
|
|
75
|
+
metadata: change.new
|
|
76
|
+
}];
|
|
77
|
+
case "create-table": {
|
|
78
|
+
const { spec, metadata, backfill } = change;
|
|
79
|
+
const table = {
|
|
80
|
+
schema: spec.schema,
|
|
81
|
+
name: spec.name
|
|
82
|
+
};
|
|
83
|
+
const ops = [];
|
|
84
|
+
if (metadata) ops.push({
|
|
85
|
+
op: "upsert-metadata",
|
|
86
|
+
table,
|
|
87
|
+
metadata
|
|
88
|
+
});
|
|
89
|
+
if (backfill) for (const [column, id] of Object.entries(backfill)) ops.push({
|
|
90
|
+
op: "upsert-backfill",
|
|
91
|
+
table,
|
|
92
|
+
column,
|
|
93
|
+
backfill: id
|
|
94
|
+
});
|
|
95
|
+
return ops;
|
|
96
|
+
}
|
|
97
|
+
case "rename-table": return [{
|
|
98
|
+
op: "rename-table",
|
|
99
|
+
old: change.old,
|
|
100
|
+
new: change.new
|
|
101
|
+
}];
|
|
102
|
+
case "drop-table": return [{
|
|
103
|
+
op: "drop-table",
|
|
104
|
+
table: change.id
|
|
105
|
+
}];
|
|
106
|
+
case "add-column": {
|
|
107
|
+
const { table, tableMetadata, column, backfill } = change;
|
|
108
|
+
const ops = [];
|
|
109
|
+
if (tableMetadata) ops.push({
|
|
110
|
+
op: "upsert-metadata",
|
|
111
|
+
table,
|
|
112
|
+
metadata: tableMetadata
|
|
113
|
+
});
|
|
114
|
+
if (backfill) ops.push({
|
|
115
|
+
op: "upsert-backfill",
|
|
116
|
+
table,
|
|
117
|
+
column: column.name,
|
|
118
|
+
backfill
|
|
119
|
+
});
|
|
120
|
+
return ops;
|
|
121
|
+
}
|
|
122
|
+
case "update-column": {
|
|
123
|
+
const { table, old, new: updated } = change;
|
|
124
|
+
return old.name === updated.name ? [] : [{
|
|
125
|
+
op: "rename-column",
|
|
126
|
+
table,
|
|
127
|
+
old: old.name,
|
|
128
|
+
new: updated.name
|
|
129
|
+
}];
|
|
130
|
+
}
|
|
131
|
+
case "drop-column": return [{
|
|
132
|
+
op: "drop-column",
|
|
133
|
+
table: change.table,
|
|
134
|
+
column: change.column
|
|
135
|
+
}];
|
|
136
|
+
case "backfill-completed": {
|
|
137
|
+
const { relation, columns } = change;
|
|
138
|
+
const cleared = [...relation.rowKey.columns, ...columns];
|
|
139
|
+
return cleared.length === 0 ? [] : [{
|
|
140
|
+
op: "complete-backfill",
|
|
141
|
+
table: {
|
|
142
|
+
schema: relation.schema,
|
|
143
|
+
name: relation.name
|
|
144
|
+
},
|
|
145
|
+
columns: cleared
|
|
146
|
+
}];
|
|
147
|
+
}
|
|
148
|
+
case "create-index":
|
|
149
|
+
case "drop-index": return [];
|
|
150
|
+
default: unreachable(change);
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* The SQLite interpreter of {@link cookieOps}, over prepared statements on the
|
|
155
|
+
* change-log database.
|
|
156
|
+
*
|
|
157
|
+
* The statements run inside the log's transaction, in stream order, at the point
|
|
158
|
+
* the schema change is appended (see `ChangeLogStreamWriter`). That is what
|
|
159
|
+
* makes the cookie set atomic with the head — a crash cannot leave cookies ahead
|
|
160
|
+
* of or behind the rows they were folded from — and what makes an aborted
|
|
161
|
+
* transaction discard its cookies with its rows, for free.
|
|
162
|
+
*
|
|
163
|
+
* Statements are prepared against the tables as they exist now, so an instance
|
|
164
|
+
* does not survive a reconcile that drops and recreates them.
|
|
165
|
+
*/
|
|
166
|
+
var ChangeLogCookieWriter = class {
|
|
167
|
+
#upsertMetadata;
|
|
168
|
+
#upsertBackfill;
|
|
169
|
+
#renameMetadataTable;
|
|
170
|
+
#renameBackfillTable;
|
|
171
|
+
#deleteMetadataTable;
|
|
172
|
+
#deleteBackfillTable;
|
|
173
|
+
#renameBackfillColumn;
|
|
174
|
+
#deleteBackfillColumn;
|
|
175
|
+
constructor(db) {
|
|
176
|
+
this.#upsertMetadata = db.prepare(`
|
|
177
|
+
INSERT INTO "${CHANGE_LOG_TABLE_METADATA_TABLE}"
|
|
178
|
+
("schema", "table", "metadata") VALUES (?, ?, ?)
|
|
179
|
+
ON CONFLICT ("schema", "table")
|
|
180
|
+
DO UPDATE SET "metadata" = excluded."metadata"
|
|
181
|
+
`);
|
|
182
|
+
this.#upsertBackfill = db.prepare(`
|
|
183
|
+
INSERT INTO "${CHANGE_LOG_BACKFILLING_TABLE}"
|
|
184
|
+
("schema", "table", "column", "backfill") VALUES (?, ?, ?, ?)
|
|
185
|
+
ON CONFLICT ("schema", "table", "column")
|
|
186
|
+
DO UPDATE SET "backfill" = excluded."backfill"
|
|
187
|
+
`);
|
|
188
|
+
this.#renameMetadataTable = db.prepare(`
|
|
189
|
+
UPDATE "${CHANGE_LOG_TABLE_METADATA_TABLE}"
|
|
190
|
+
SET "schema" = ?, "table" = ? WHERE "schema" = ? AND "table" = ?
|
|
191
|
+
`);
|
|
192
|
+
this.#renameBackfillTable = db.prepare(`
|
|
193
|
+
UPDATE "${CHANGE_LOG_BACKFILLING_TABLE}"
|
|
194
|
+
SET "schema" = ?, "table" = ? WHERE "schema" = ? AND "table" = ?
|
|
195
|
+
`);
|
|
196
|
+
this.#deleteMetadataTable = db.prepare(`
|
|
197
|
+
DELETE FROM "${CHANGE_LOG_TABLE_METADATA_TABLE}"
|
|
198
|
+
WHERE "schema" = ? AND "table" = ?
|
|
199
|
+
`);
|
|
200
|
+
this.#deleteBackfillTable = db.prepare(`
|
|
201
|
+
DELETE FROM "${CHANGE_LOG_BACKFILLING_TABLE}"
|
|
202
|
+
WHERE "schema" = ? AND "table" = ?
|
|
203
|
+
`);
|
|
204
|
+
this.#renameBackfillColumn = db.prepare(`
|
|
205
|
+
UPDATE "${CHANGE_LOG_BACKFILLING_TABLE}" SET "column" = ?
|
|
206
|
+
WHERE "schema" = ? AND "table" = ? AND "column" = ?
|
|
207
|
+
`);
|
|
208
|
+
this.#deleteBackfillColumn = db.prepare(`
|
|
209
|
+
DELETE FROM "${CHANGE_LOG_BACKFILLING_TABLE}"
|
|
210
|
+
WHERE "schema" = ? AND "table" = ? AND "column" = ?
|
|
211
|
+
`);
|
|
212
|
+
}
|
|
213
|
+
/** Applies the change's cookie ops, returning the ops that were applied. */
|
|
214
|
+
apply(change) {
|
|
215
|
+
const ops = cookieOps(change);
|
|
216
|
+
for (const op of ops) this.#run(op);
|
|
217
|
+
return ops;
|
|
218
|
+
}
|
|
219
|
+
#run(op) {
|
|
220
|
+
switch (op.op) {
|
|
221
|
+
case "upsert-metadata":
|
|
222
|
+
this.#upsertMetadata.run(op.table.schema, op.table.name, BigIntJSON.stringify(op.metadata));
|
|
223
|
+
break;
|
|
224
|
+
case "upsert-backfill":
|
|
225
|
+
this.#upsertBackfill.run(op.table.schema, op.table.name, op.column, BigIntJSON.stringify(op.backfill));
|
|
226
|
+
break;
|
|
227
|
+
case "rename-table":
|
|
228
|
+
this.#renameMetadataTable.run(op.new.schema, op.new.name, op.old.schema, op.old.name);
|
|
229
|
+
this.#renameBackfillTable.run(op.new.schema, op.new.name, op.old.schema, op.old.name);
|
|
230
|
+
break;
|
|
231
|
+
case "drop-table":
|
|
232
|
+
this.#deleteMetadataTable.run(op.table.schema, op.table.name);
|
|
233
|
+
this.#deleteBackfillTable.run(op.table.schema, op.table.name);
|
|
234
|
+
break;
|
|
235
|
+
case "rename-column":
|
|
236
|
+
this.#renameBackfillColumn.run(op.new, op.table.schema, op.table.name, op.old);
|
|
237
|
+
break;
|
|
238
|
+
case "drop-column":
|
|
239
|
+
this.#deleteBackfillColumn.run(op.table.schema, op.table.name, op.column);
|
|
240
|
+
break;
|
|
241
|
+
case "complete-backfill":
|
|
242
|
+
for (const column of op.columns) this.#deleteBackfillColumn.run(op.table.schema, op.table.name, column);
|
|
243
|
+
break;
|
|
244
|
+
default: unreachable(op);
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
};
|
|
248
|
+
var tableKey = (schema, table) => JSON.stringify([schema, table]);
|
|
249
|
+
var columnKey = (schema, table, column) => JSON.stringify([
|
|
250
|
+
schema,
|
|
251
|
+
table,
|
|
252
|
+
column
|
|
253
|
+
]);
|
|
254
|
+
var cmp = (a, b) => a < b ? -1 : a > b ? 1 : 0;
|
|
255
|
+
/**
|
|
256
|
+
* The in-memory interpreter of {@link cookieOps}: the third one, and the only
|
|
257
|
+
* one that is not a store.
|
|
258
|
+
*
|
|
259
|
+
* A replica-derived cookie set is a snapshot at the replica's state version,
|
|
260
|
+
* which trails the change log's head, so it cannot be compared with a
|
|
261
|
+
* Postgres-derived set directly. This carries it forward over the schema changes
|
|
262
|
+
* the log holds in between, which turns "the two stores disagree, but they are
|
|
263
|
+
* also at different positions" into an exact equality — and makes a
|
|
264
|
+
* disagreement between any two of the three interpreters visible as an
|
|
265
|
+
* inequality that neither store would have noticed on its own.
|
|
266
|
+
*
|
|
267
|
+
* `changes` must be the log's schema changes over `(from, to]` in stream order.
|
|
268
|
+
* Anything else produces a set that belongs to no watermark.
|
|
269
|
+
*/
|
|
270
|
+
function foldCookies(cookies, changes) {
|
|
271
|
+
const metadata = new Map(cookies.tableMetadata.map((c) => [tableKey(c.schema, c.table), c]));
|
|
272
|
+
const backfilling = new Map(cookies.backfilling.map((c) => [columnKey(c.schema, c.table, c.column), c]));
|
|
273
|
+
const dropColumn = ({ schema, name }, column) => backfilling.delete(columnKey(schema, name, column));
|
|
274
|
+
for (const change of changes) for (const op of cookieOps(change)) switch (op.op) {
|
|
275
|
+
case "upsert-metadata":
|
|
276
|
+
metadata.set(tableKey(op.table.schema, op.table.name), {
|
|
277
|
+
schema: op.table.schema,
|
|
278
|
+
table: op.table.name,
|
|
279
|
+
metadata: op.metadata
|
|
280
|
+
});
|
|
281
|
+
break;
|
|
282
|
+
case "upsert-backfill":
|
|
283
|
+
backfilling.set(columnKey(op.table.schema, op.table.name, op.column), {
|
|
284
|
+
schema: op.table.schema,
|
|
285
|
+
table: op.table.name,
|
|
286
|
+
column: op.column,
|
|
287
|
+
backfill: op.backfill
|
|
288
|
+
});
|
|
289
|
+
break;
|
|
290
|
+
case "rename-table": {
|
|
291
|
+
const { old, new: renamed } = op;
|
|
292
|
+
const moved = metadata.get(tableKey(old.schema, old.name));
|
|
293
|
+
if (moved) {
|
|
294
|
+
metadata.delete(tableKey(old.schema, old.name));
|
|
295
|
+
metadata.set(tableKey(renamed.schema, renamed.name), {
|
|
296
|
+
...moved,
|
|
297
|
+
schema: renamed.schema,
|
|
298
|
+
table: renamed.name
|
|
299
|
+
});
|
|
300
|
+
}
|
|
301
|
+
for (const [key, cookie] of [...backfilling]) if (cookie.schema === old.schema && cookie.table === old.name) {
|
|
302
|
+
backfilling.delete(key);
|
|
303
|
+
backfilling.set(columnKey(renamed.schema, renamed.name, cookie.column), {
|
|
304
|
+
...cookie,
|
|
305
|
+
schema: renamed.schema,
|
|
306
|
+
table: renamed.name
|
|
307
|
+
});
|
|
308
|
+
}
|
|
309
|
+
break;
|
|
310
|
+
}
|
|
311
|
+
case "drop-table": {
|
|
312
|
+
const { schema, name } = op.table;
|
|
313
|
+
metadata.delete(tableKey(schema, name));
|
|
314
|
+
for (const [key, cookie] of [...backfilling]) if (cookie.schema === schema && cookie.table === name) backfilling.delete(key);
|
|
315
|
+
break;
|
|
316
|
+
}
|
|
317
|
+
case "rename-column": {
|
|
318
|
+
const { schema, name } = op.table;
|
|
319
|
+
const moved = backfilling.get(columnKey(schema, name, op.old));
|
|
320
|
+
if (moved) {
|
|
321
|
+
backfilling.delete(columnKey(schema, name, op.old));
|
|
322
|
+
backfilling.set(columnKey(schema, name, op.new), {
|
|
323
|
+
...moved,
|
|
324
|
+
column: op.new
|
|
325
|
+
});
|
|
326
|
+
}
|
|
327
|
+
break;
|
|
328
|
+
}
|
|
329
|
+
case "drop-column":
|
|
330
|
+
dropColumn(op.table, op.column);
|
|
331
|
+
break;
|
|
332
|
+
case "complete-backfill":
|
|
333
|
+
for (const column of op.columns) dropColumn(op.table, column);
|
|
334
|
+
break;
|
|
335
|
+
default: unreachable(op);
|
|
336
|
+
}
|
|
337
|
+
return {
|
|
338
|
+
tableMetadata: [...metadata.values()].toSorted((a, b) => cmp(a.schema, b.schema) || cmp(a.table, b.table)),
|
|
339
|
+
backfilling: [...backfilling.values()].toSorted((a, b) => cmp(a.schema, b.schema) || cmp(a.table, b.table) || cmp(a.column, b.column))
|
|
340
|
+
};
|
|
341
|
+
}
|
|
342
|
+
var backfillRequestsSchema = valita_exports.array(backfillRequestSchema);
|
|
343
|
+
/**
|
|
344
|
+
* Returns one {@link BackfillRequest} for each table with an active backfill.
|
|
345
|
+
* Each request contains the stored table metadata, if available.
|
|
346
|
+
*/
|
|
347
|
+
function backfillRequestsFrom(cookies) {
|
|
348
|
+
const metadata = new Map(cookies.tableMetadata.map((c) => [tableKey(c.schema, c.table), c.metadata]));
|
|
349
|
+
const requests = [];
|
|
350
|
+
let curr;
|
|
351
|
+
for (const { schema, table, column, backfill } of cookies.backfilling) {
|
|
352
|
+
if (curr?.table.schema !== schema || curr.table.name !== table) {
|
|
353
|
+
curr = {
|
|
354
|
+
table: {
|
|
355
|
+
schema,
|
|
356
|
+
name: table,
|
|
357
|
+
metadata: metadata.get(tableKey(schema, table)) ?? null
|
|
358
|
+
},
|
|
359
|
+
columns: {}
|
|
360
|
+
};
|
|
361
|
+
requests.push(curr);
|
|
362
|
+
}
|
|
363
|
+
curr.columns[column] = backfill;
|
|
364
|
+
}
|
|
365
|
+
return parse(requests, backfillRequestsSchema);
|
|
366
|
+
}
|
|
367
|
+
/**
|
|
368
|
+
* Reads the whole cookie set, ordered by primary key. This is what a
|
|
369
|
+
* change-streamer would hand `startStream`, and what the Postgres-derived and
|
|
370
|
+
* replica-derived sets are compared against.
|
|
371
|
+
*/
|
|
372
|
+
function readCookies(db) {
|
|
373
|
+
return {
|
|
374
|
+
tableMetadata: db.prepare(`
|
|
375
|
+
SELECT "schema", "table", "metadata"
|
|
376
|
+
FROM "${CHANGE_LOG_TABLE_METADATA_TABLE}"
|
|
377
|
+
ORDER BY "schema", "table"
|
|
378
|
+
`).all().map(({ schema, table, metadata }) => ({
|
|
379
|
+
schema,
|
|
380
|
+
table,
|
|
381
|
+
metadata: BigIntJSON.parse(metadata)
|
|
382
|
+
})),
|
|
383
|
+
backfilling: db.prepare(`
|
|
384
|
+
SELECT "schema", "table", "column", "backfill"
|
|
385
|
+
FROM "${CHANGE_LOG_BACKFILLING_TABLE}"
|
|
386
|
+
ORDER BY "schema", "table", "column"
|
|
387
|
+
`).all().map(({ schema, table, column, backfill }) => ({
|
|
388
|
+
schema,
|
|
389
|
+
table,
|
|
390
|
+
column,
|
|
391
|
+
backfill: BigIntJSON.parse(backfill)
|
|
392
|
+
}))
|
|
393
|
+
};
|
|
394
|
+
}
|
|
395
|
+
/**
|
|
396
|
+
* Replaces the cookie set wholesale.
|
|
397
|
+
*
|
|
398
|
+
* The cookies are unversioned point-in-time state, so a reconciliation that
|
|
399
|
+
* moves the head invalidates them: truncating the stream above `W` does not roll
|
|
400
|
+
* the cookie set back to `W`, and the truncated transactions can contain
|
|
401
|
+
* `create-table`, `add-column`, and `backfill-completed`. The caller must run
|
|
402
|
+
* this in the same transaction as the reconciliation that invalidated them.
|
|
403
|
+
*/
|
|
404
|
+
function replaceCookies(db, cookies) {
|
|
405
|
+
db.prepare(`DELETE FROM "${CHANGE_LOG_TABLE_METADATA_TABLE}"`).run();
|
|
406
|
+
db.prepare(`DELETE FROM "${CHANGE_LOG_BACKFILLING_TABLE}"`).run();
|
|
407
|
+
if (cookies.tableMetadata.length > 0) {
|
|
408
|
+
const insert = db.prepare(`
|
|
409
|
+
INSERT INTO "${CHANGE_LOG_TABLE_METADATA_TABLE}"
|
|
410
|
+
("schema", "table", "metadata") VALUES (?, ?, ?)
|
|
411
|
+
`);
|
|
412
|
+
for (const { schema, table, metadata } of cookies.tableMetadata) insert.run(schema, table, BigIntJSON.stringify(metadata));
|
|
413
|
+
}
|
|
414
|
+
if (cookies.backfilling.length > 0) {
|
|
415
|
+
const insert = db.prepare(`
|
|
416
|
+
INSERT INTO "${CHANGE_LOG_BACKFILLING_TABLE}"
|
|
417
|
+
("schema", "table", "column", "backfill") VALUES (?, ?, ?, ?)
|
|
418
|
+
`);
|
|
419
|
+
for (const { schema, table, column, backfill } of cookies.backfilling) insert.run(schema, table, column, BigIntJSON.stringify(backfill));
|
|
420
|
+
}
|
|
421
|
+
}
|
|
422
|
+
function readCookieRowCounts(db) {
|
|
423
|
+
return db.prepare(`
|
|
424
|
+
SELECT
|
|
425
|
+
(SELECT count(*) FROM "${CHANGE_LOG_TABLE_METADATA_TABLE}")
|
|
426
|
+
AS "tableMetadata",
|
|
427
|
+
(SELECT count(*) FROM "${CHANGE_LOG_BACKFILLING_TABLE}")
|
|
428
|
+
AS "backfilling"
|
|
429
|
+
`).get();
|
|
430
|
+
}
|
|
431
|
+
//#endregion
|
|
432
|
+
export { CHANGE_LOG_BACKFILLING_TABLE, CHANGE_LOG_TABLE_METADATA_TABLE, CREATE_CHANGE_LOG_COOKIE_SCHEMA, ChangeLogCookieWriter, DROP_CHANGE_LOG_COOKIE_TABLES, backfillRequestsFrom, cookieOps, foldCookies, readCookieRowCounts, readCookies, replaceCookies };
|
|
433
|
+
|
|
434
|
+
//# sourceMappingURL=change-log-cookies.js.map
|