@rocicorp/zero 0.10.2025010800 → 0.10.2025011400
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/README.md +32 -0
- package/out/advanced.js +1 -1
- package/out/{chunk-Y6OVFUGE.js → chunk-I5GSZARI.js} +1 -7
- package/out/{chunk-Y6OVFUGE.js.map → chunk-I5GSZARI.js.map} +1 -1
- package/out/{chunk-PPRTDNXA.js → chunk-TS7IMB6J.js} +785 -1660
- package/out/chunk-TS7IMB6J.js.map +7 -0
- package/out/react.js +1 -1
- package/out/react.js.map +1 -1
- package/out/replicache/src/btree/node.d.ts +5 -3
- package/out/replicache/src/btree/node.d.ts.map +1 -1
- package/out/replicache/src/btree/read.d.ts +4 -1
- package/out/replicache/src/btree/read.d.ts.map +1 -1
- package/out/replicache/src/btree/write.d.ts +4 -1
- package/out/replicache/src/btree/write.d.ts.map +1 -1
- package/out/replicache/src/dag/key-type-enum.d.ts +0 -1
- package/out/replicache/src/dag/key-type-enum.d.ts.map +1 -1
- package/out/replicache/src/db/commit.d.ts +12 -35
- package/out/replicache/src/db/commit.d.ts.map +1 -1
- package/out/replicache/src/db/index-operation-enum.d.ts +0 -1
- package/out/replicache/src/db/index-operation-enum.d.ts.map +1 -1
- package/out/replicache/src/db/index.d.ts +4 -1
- package/out/replicache/src/db/index.d.ts.map +1 -1
- package/out/replicache/src/db/meta-type-enum.d.ts +0 -7
- package/out/replicache/src/db/meta-type-enum.d.ts.map +1 -1
- package/out/replicache/src/db/read.d.ts +4 -1
- package/out/replicache/src/db/read.d.ts.map +1 -1
- package/out/replicache/src/db/rebase.d.ts +5 -2
- package/out/replicache/src/db/rebase.d.ts.map +1 -1
- package/out/replicache/src/db/write.d.ts +8 -6
- package/out/replicache/src/db/write.d.ts.map +1 -1
- package/out/replicache/src/format-version-enum.d.ts +0 -2
- package/out/replicache/src/format-version-enum.d.ts.map +1 -1
- package/out/replicache/src/format-version.d.ts +4 -1
- package/out/replicache/src/format-version.d.ts.map +1 -1
- package/out/replicache/src/get-default-puller.d.ts +1 -3
- package/out/replicache/src/get-default-puller.d.ts.map +1 -1
- package/out/replicache/src/invoke-kind-enum.d.ts +0 -1
- package/out/replicache/src/invoke-kind-enum.d.ts.map +1 -1
- package/out/replicache/src/mod.d.ts +5 -5
- package/out/replicache/src/mod.d.ts.map +1 -1
- package/out/replicache/src/mutation-recovery.d.ts +1 -2
- package/out/replicache/src/mutation-recovery.d.ts.map +1 -1
- package/out/replicache/src/persist/clients.d.ts +3 -1
- package/out/replicache/src/persist/clients.d.ts.map +1 -1
- package/out/replicache/src/persist/persist.d.ts +4 -1
- package/out/replicache/src/persist/persist.d.ts.map +1 -1
- package/out/replicache/src/persist/refresh.d.ts +4 -1
- package/out/replicache/src/persist/refresh.d.ts.map +1 -1
- package/out/replicache/src/puller.d.ts +2 -20
- package/out/replicache/src/puller.d.ts.map +1 -1
- package/out/replicache/src/replicache-impl.d.ts +1 -2
- package/out/replicache/src/replicache-impl.d.ts.map +1 -1
- package/out/replicache/src/subscriptions.d.ts +5 -3
- package/out/replicache/src/subscriptions.d.ts.map +1 -1
- package/out/replicache/src/sync/diff.d.ts +4 -1
- package/out/replicache/src/sync/diff.d.ts.map +1 -1
- package/out/replicache/src/sync/handle-pull-response-result-type-enum.d.ts +0 -1
- package/out/replicache/src/sync/handle-pull-response-result-type-enum.d.ts.map +1 -1
- package/out/replicache/src/sync/pull.d.ts +7 -33
- package/out/replicache/src/sync/pull.d.ts.map +1 -1
- package/out/replicache/src/sync/push.d.ts +3 -30
- package/out/replicache/src/sync/push.d.ts.map +1 -1
- package/out/shared/src/enum.d.ts +37 -0
- package/out/shared/src/enum.d.ts.map +1 -0
- package/out/shared/src/enum.js +2 -0
- package/out/shared/src/enum.js.map +1 -0
- package/out/shared/src/options.d.ts.map +1 -1
- package/out/shared/src/options.js +15 -7
- package/out/shared/src/options.js.map +1 -1
- package/out/solid.js +30 -36
- package/out/solid.js.map +3 -3
- package/out/zero/src/change-protocol.d.ts +2 -0
- package/out/zero/src/change-protocol.d.ts.map +1 -0
- package/out/zero/src/change-protocol.js +2 -0
- package/out/zero/src/change-protocol.js.map +1 -0
- package/out/zero-cache/src/config/zero-config.d.ts +30 -4
- package/out/zero-cache/src/config/zero-config.d.ts.map +1 -1
- package/out/zero-cache/src/config/zero-config.js +31 -15
- package/out/zero-cache/src/config/zero-config.js.map +1 -1
- package/out/zero-cache/src/db/mode-enum.d.ts +5 -0
- package/out/zero-cache/src/db/mode-enum.d.ts.map +1 -0
- package/out/zero-cache/src/db/mode-enum.js +3 -0
- package/out/zero-cache/src/db/mode-enum.js.map +1 -0
- package/out/zero-cache/src/db/pg-to-lite.d.ts.map +1 -1
- package/out/zero-cache/src/db/pg-to-lite.js +2 -1
- package/out/zero-cache/src/db/pg-to-lite.js.map +1 -1
- package/out/zero-cache/src/db/postgres-type-class-enum.d.ts +15 -0
- package/out/zero-cache/src/db/postgres-type-class-enum.d.ts.map +1 -0
- package/out/zero-cache/src/db/postgres-type-class-enum.js +10 -0
- package/out/zero-cache/src/db/postgres-type-class-enum.js.map +1 -0
- package/out/zero-cache/src/db/specs.d.ts +7 -16
- package/out/zero-cache/src/db/specs.d.ts.map +1 -1
- package/out/zero-cache/src/db/specs.js +1 -11
- package/out/zero-cache/src/db/specs.js.map +1 -1
- package/out/zero-cache/src/db/transaction-pool.d.ts +3 -4
- package/out/zero-cache/src/db/transaction-pool.d.ts.map +1 -1
- package/out/zero-cache/src/db/transaction-pool.js +1 -5
- package/out/zero-cache/src/db/transaction-pool.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 +2 -6
- package/out/zero-cache/src/server/change-streamer.js.map +1 -1
- package/out/zero-cache/src/server/life-cycle.d.ts +3 -2
- package/out/zero-cache/src/server/life-cycle.d.ts.map +1 -1
- package/out/zero-cache/src/server/life-cycle.js +15 -12
- package/out/zero-cache/src/server/life-cycle.js.map +1 -1
- package/out/zero-cache/src/server/main.d.ts.map +1 -1
- package/out/zero-cache/src/server/main.js +25 -16
- package/out/zero-cache/src/server/main.js.map +1 -1
- package/out/zero-cache/src/server/multi/config.d.ts +20 -3
- package/out/zero-cache/src/server/multi/config.d.ts.map +1 -1
- package/out/zero-cache/src/server/multi/config.js +10 -2
- package/out/zero-cache/src/server/multi/config.js.map +1 -1
- package/out/zero-cache/src/server/multi/main.d.ts.map +1 -1
- package/out/zero-cache/src/server/multi/main.js +9 -3
- package/out/zero-cache/src/server/multi/main.js.map +1 -1
- package/out/zero-cache/src/services/{change-streamer → change-source}/pg/change-source.d.ts +2 -2
- package/out/zero-cache/src/services/change-source/pg/change-source.d.ts.map +1 -0
- package/out/zero-cache/src/services/{change-streamer → change-source}/pg/change-source.js +18 -49
- package/out/zero-cache/src/services/change-source/pg/change-source.js.map +1 -0
- package/out/zero-cache/src/services/change-source/pg/initial-sync.d.ts.map +1 -0
- package/out/zero-cache/src/services/{change-streamer → change-source}/pg/initial-sync.js +7 -8
- package/out/zero-cache/src/services/change-source/pg/initial-sync.js.map +1 -0
- package/out/zero-cache/src/services/{change-streamer → change-source}/pg/lsn.d.ts +1 -1
- package/out/zero-cache/src/services/change-source/pg/lsn.d.ts.map +1 -0
- package/out/zero-cache/src/services/change-source/pg/lsn.js.map +1 -0
- package/out/zero-cache/src/services/{change-streamer → change-source}/pg/schema/ddl.d.ts +15 -15
- package/out/zero-cache/src/services/change-source/pg/schema/ddl.d.ts.map +1 -0
- package/out/zero-cache/src/services/change-source/pg/schema/ddl.js.map +1 -0
- package/out/zero-cache/src/services/change-source/pg/schema/init.d.ts.map +1 -0
- package/out/zero-cache/src/services/{change-streamer → change-source}/pg/schema/init.js +1 -1
- package/out/zero-cache/src/services/change-source/pg/schema/init.js.map +1 -0
- package/out/zero-cache/src/services/{change-streamer → change-source}/pg/schema/published.d.ts +6 -6
- package/out/zero-cache/src/services/change-source/pg/schema/published.d.ts.map +1 -0
- package/out/zero-cache/src/services/change-source/pg/schema/published.js.map +1 -0
- package/out/zero-cache/src/services/{change-streamer → change-source}/pg/schema/shard.d.ts +1 -1
- package/out/zero-cache/src/services/change-source/pg/schema/shard.d.ts.map +1 -0
- package/out/zero-cache/src/services/change-source/pg/schema/shard.js.map +1 -0
- package/out/zero-cache/src/services/change-source/pg/schema/validation.d.ts.map +1 -0
- package/out/zero-cache/src/services/change-source/pg/schema/validation.js.map +1 -0
- package/out/zero-cache/src/services/change-source/pg/shard-config.d.ts.map +1 -0
- package/out/zero-cache/src/services/change-source/pg/shard-config.js.map +1 -0
- package/out/zero-cache/src/services/change-source/pg/sync-schema.d.ts.map +1 -0
- package/out/zero-cache/src/services/{change-streamer → change-source}/pg/sync-schema.js +7 -6
- package/out/zero-cache/src/services/change-source/pg/sync-schema.js.map +1 -0
- package/out/zero-cache/src/services/change-source/protocol/current/control.d.ts +19 -0
- package/out/zero-cache/src/services/change-source/protocol/current/control.d.ts.map +1 -0
- package/out/zero-cache/src/services/change-source/protocol/current/control.js +17 -0
- package/out/zero-cache/src/services/change-source/protocol/current/control.js.map +1 -0
- package/out/zero-cache/src/services/{change-streamer/schema/change.d.ts → change-source/protocol/current/data.d.ts} +28 -23
- package/out/zero-cache/src/services/change-source/protocol/current/data.d.ts.map +1 -0
- package/out/zero-cache/src/services/{change-streamer/schema/change.js → change-source/protocol/current/data.js} +9 -4
- package/out/zero-cache/src/services/change-source/protocol/current/data.js.map +1 -0
- package/out/zero-cache/src/services/change-source/protocol/current/downstream.d.ts +475 -0
- package/out/zero-cache/src/services/change-source/protocol/current/downstream.d.ts.map +1 -0
- package/out/zero-cache/src/services/change-source/protocol/current/downstream.js +23 -0
- package/out/zero-cache/src/services/change-source/protocol/current/downstream.js.map +1 -0
- package/out/zero-cache/src/services/change-source/protocol/current/mod.d.ts +6 -0
- package/out/zero-cache/src/services/change-source/protocol/current/mod.d.ts.map +1 -0
- package/out/zero-cache/src/services/change-source/protocol/current/mod.js +6 -0
- package/out/zero-cache/src/services/change-source/protocol/current/mod.js.map +1 -0
- package/out/zero-cache/src/services/change-source/protocol/current/path.d.ts +20 -0
- package/out/zero-cache/src/services/change-source/protocol/current/path.d.ts.map +1 -0
- package/out/zero-cache/src/services/change-source/protocol/current/path.js +20 -0
- package/out/zero-cache/src/services/change-source/protocol/current/path.js.map +1 -0
- package/out/zero-cache/src/services/change-source/protocol/current/upstream.d.ts +17 -0
- package/out/zero-cache/src/services/change-source/protocol/current/upstream.d.ts.map +1 -0
- package/out/zero-cache/src/services/change-source/protocol/current/upstream.js +12 -0
- package/out/zero-cache/src/services/change-source/protocol/current/upstream.js.map +1 -0
- package/out/zero-cache/src/services/change-source/protocol/mod.d.ts +2 -0
- package/out/zero-cache/src/services/change-source/protocol/mod.d.ts.map +1 -0
- package/out/zero-cache/src/services/change-source/protocol/mod.js +5 -0
- package/out/zero-cache/src/services/change-source/protocol/mod.js.map +1 -0
- package/out/zero-cache/src/services/change-streamer/change-streamer-service.d.ts +3 -159
- 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 +22 -22
- 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 +7 -319
- 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 +3 -18
- 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 +9 -0
- package/out/zero-cache/src/services/change-streamer/error-type-enum.d.ts.map +1 -0
- package/out/zero-cache/src/services/change-streamer/error-type-enum.js +6 -0
- package/out/zero-cache/src/services/change-streamer/error-type-enum.js.map +1 -0
- package/out/zero-cache/src/services/change-streamer/schema/tables.d.ts +1 -1
- package/out/zero-cache/src/services/change-streamer/schema/tables.d.ts.map +1 -1
- package/out/zero-cache/src/services/change-streamer/storer.d.ts +1 -1
- package/out/zero-cache/src/services/change-streamer/storer.d.ts.map +1 -1
- package/out/zero-cache/src/services/change-streamer/storer.js +7 -25
- package/out/zero-cache/src/services/change-streamer/storer.js.map +1 -1
- package/out/zero-cache/src/services/change-streamer/subscriber.d.ts +5 -1
- package/out/zero-cache/src/services/change-streamer/subscriber.d.ts.map +1 -1
- package/out/zero-cache/src/services/change-streamer/subscriber.js +2 -1
- package/out/zero-cache/src/services/change-streamer/subscriber.js.map +1 -1
- package/out/zero-cache/src/services/litestream/commands.d.ts +8 -0
- package/out/zero-cache/src/services/litestream/commands.d.ts.map +1 -0
- package/out/zero-cache/src/services/litestream/commands.js +61 -0
- package/out/zero-cache/src/services/litestream/commands.js.map +1 -0
- package/out/zero-cache/src/services/litestream/config.yml +7 -0
- package/out/zero-cache/src/services/mutagen/mutagen.d.ts +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 -4
- package/out/zero-cache/src/services/mutagen/mutagen.js.map +1 -1
- package/out/zero-cache/src/services/replicator/incremental-sync.d.ts +3 -2
- package/out/zero-cache/src/services/replicator/incremental-sync.d.ts.map +1 -1
- package/out/zero-cache/src/services/replicator/incremental-sync.js +17 -49
- package/out/zero-cache/src/services/replicator/incremental-sync.js.map +1 -1
- package/out/zero-cache/src/services/replicator/schema/replication-state.d.ts +3 -4
- 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 +15 -20
- package/out/zero-cache/src/services/replicator/schema/replication-state.js.map +1 -1
- package/out/zero-cache/src/services/running-state.d.ts +7 -0
- package/out/zero-cache/src/services/running-state.d.ts.map +1 -1
- package/out/zero-cache/src/services/running-state.js +8 -1
- package/out/zero-cache/src/services/running-state.js.map +1 -1
- package/out/zero-cache/src/services/view-syncer/client-handler.js +1 -1
- 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 +3 -2
- package/out/zero-cache/src/services/view-syncer/cvr-store.js.map +1 -1
- package/out/zero-cache/src/services/view-syncer/cvr.d.ts.map +1 -1
- package/out/zero-cache/src/services/view-syncer/cvr.js +4 -3
- package/out/zero-cache/src/services/view-syncer/cvr.js.map +1 -1
- 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 +4 -2
- package/out/zero-cache/src/services/view-syncer/pipeline-driver.js.map +1 -1
- package/out/zero-cache/src/services/view-syncer/snapshotter.js +3 -3
- 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.map +1 -1
- package/out/zero-cache/src/services/view-syncer/view-syncer.js +6 -5
- package/out/zero-cache/src/services/view-syncer/view-syncer.js.map +1 -1
- package/out/zero-cache/src/types/error-for-client.d.ts +2 -2
- package/out/zero-cache/src/types/pg.js +2 -2
- package/out/zero-cache/src/types/pg.js.map +1 -1
- package/out/zero-cache/src/types/processes.d.ts +4 -2
- package/out/zero-cache/src/types/processes.d.ts.map +1 -1
- package/out/zero-cache/src/types/processes.js.map +1 -1
- package/out/zero-cache/src/types/schema-versions.js +1 -1
- package/out/zero-cache/src/types/schema-versions.js.map +1 -1
- package/out/zero-cache/src/workers/connection.d.ts.map +1 -1
- package/out/zero-cache/src/workers/connection.js +2 -1
- package/out/zero-cache/src/workers/connection.js.map +1 -1
- package/out/zero-cache/src/workers/syncer.js +1 -1
- package/out/zero-cache/src/workers/syncer.js.map +1 -1
- package/out/zero-client/src/client/connection-state-enum.d.ts +7 -0
- package/out/zero-client/src/client/connection-state-enum.d.ts.map +1 -0
- package/out/zero-client/src/client/metric-name-enum.d.ts +13 -0
- package/out/zero-client/src/client/metric-name-enum.d.ts.map +1 -0
- package/out/zero-client/src/client/metrics.d.ts +2 -9
- package/out/zero-client/src/client/metrics.d.ts.map +1 -1
- package/out/zero-client/src/client/ping-result-enum.d.ts +5 -0
- package/out/zero-client/src/client/ping-result-enum.d.ts.map +1 -0
- package/out/zero-client/src/client/server-error.d.ts +4 -1
- package/out/zero-client/src/client/server-error.d.ts.map +1 -1
- package/out/zero-client/src/client/zero.d.ts +4 -5
- package/out/zero-client/src/client/zero.d.ts.map +1 -1
- package/out/zero-protocol/src/error-kind-enum.d.ts +31 -0
- package/out/zero-protocol/src/error-kind-enum.d.ts.map +1 -0
- package/out/zero-protocol/src/error-kind-enum.js +20 -0
- package/out/zero-protocol/src/error-kind-enum.js.map +1 -0
- package/out/zero-protocol/src/error.d.ts +4 -21
- package/out/zero-protocol/src/error.d.ts.map +1 -1
- package/out/zero-protocol/src/error.js +1 -21
- package/out/zero-protocol/src/error.js.map +1 -1
- package/out/zero-protocol/src/mutation-type-enum.d.ts +5 -0
- package/out/zero-protocol/src/mutation-type-enum.d.ts.map +1 -0
- package/out/zero-protocol/src/mutation-type-enum.js +4 -0
- package/out/zero-protocol/src/mutation-type-enum.js.map +1 -0
- package/out/zero-protocol/src/push.d.ts +8 -12
- package/out/zero-protocol/src/push.d.ts.map +1 -1
- package/out/zero-protocol/src/push.js +1 -5
- package/out/zero-protocol/src/push.js.map +1 -1
- package/out/zero-protocol/src/up.d.ts +2 -2
- package/out/zero-schema/src/normalize-table-schema.d.ts +4 -3
- package/out/zero-schema/src/normalize-table-schema.d.ts.map +1 -1
- package/out/zero-schema/src/normalize-table-schema.js +27 -23
- package/out/zero-schema/src/normalize-table-schema.js.map +1 -1
- package/out/zero-schema/src/normalized-schema.d.ts.map +1 -1
- package/out/zero-schema/src/normalized-schema.js +19 -2
- package/out/zero-schema/src/normalized-schema.js.map +1 -1
- package/out/zero-schema/src/schema.d.ts +1 -1
- package/out/zero-schema/src/schema.d.ts.map +1 -1
- package/out/zero-schema/src/schema.js +5 -4
- package/out/zero-schema/src/schema.js.map +1 -1
- package/out/zero-solid/src/solid-view.d.ts +4 -1
- package/out/zero-solid/src/solid-view.d.ts.map +1 -1
- package/out/zero-solid/src/use-query.d.ts +4 -7
- package/out/zero-solid/src/use-query.d.ts.map +1 -1
- package/out/zero.js +2 -2
- package/package.json +9 -5
- package/out/chunk-PPRTDNXA.js.map +0 -7
- package/out/zero-cache/src/services/change-streamer/pg/change-source.d.ts.map +0 -1
- package/out/zero-cache/src/services/change-streamer/pg/change-source.js.map +0 -1
- package/out/zero-cache/src/services/change-streamer/pg/initial-sync.d.ts.map +0 -1
- package/out/zero-cache/src/services/change-streamer/pg/initial-sync.js.map +0 -1
- package/out/zero-cache/src/services/change-streamer/pg/lsn.d.ts.map +0 -1
- package/out/zero-cache/src/services/change-streamer/pg/lsn.js.map +0 -1
- package/out/zero-cache/src/services/change-streamer/pg/schema/ddl.d.ts.map +0 -1
- package/out/zero-cache/src/services/change-streamer/pg/schema/ddl.js.map +0 -1
- package/out/zero-cache/src/services/change-streamer/pg/schema/init.d.ts.map +0 -1
- package/out/zero-cache/src/services/change-streamer/pg/schema/init.js.map +0 -1
- package/out/zero-cache/src/services/change-streamer/pg/schema/published.d.ts.map +0 -1
- package/out/zero-cache/src/services/change-streamer/pg/schema/published.js.map +0 -1
- package/out/zero-cache/src/services/change-streamer/pg/schema/shard.d.ts.map +0 -1
- package/out/zero-cache/src/services/change-streamer/pg/schema/shard.js.map +0 -1
- package/out/zero-cache/src/services/change-streamer/pg/schema/validation.d.ts.map +0 -1
- package/out/zero-cache/src/services/change-streamer/pg/schema/validation.js.map +0 -1
- package/out/zero-cache/src/services/change-streamer/pg/shard-config.d.ts.map +0 -1
- package/out/zero-cache/src/services/change-streamer/pg/shard-config.js.map +0 -1
- package/out/zero-cache/src/services/change-streamer/pg/sync-schema.d.ts.map +0 -1
- package/out/zero-cache/src/services/change-streamer/pg/sync-schema.js.map +0 -1
- package/out/zero-cache/src/services/change-streamer/schema/change.d.ts.map +0 -1
- package/out/zero-cache/src/services/change-streamer/schema/change.js.map +0 -1
- /package/out/zero-cache/src/services/{change-streamer → change-source}/pg/initial-sync.d.ts +0 -0
- /package/out/zero-cache/src/services/{change-streamer → change-source}/pg/lsn.js +0 -0
- /package/out/zero-cache/src/services/{change-streamer → change-source}/pg/schema/ddl.js +0 -0
- /package/out/zero-cache/src/services/{change-streamer → change-source}/pg/schema/init.d.ts +0 -0
- /package/out/zero-cache/src/services/{change-streamer → change-source}/pg/schema/published.js +0 -0
- /package/out/zero-cache/src/services/{change-streamer → change-source}/pg/schema/shard.js +0 -0
- /package/out/zero-cache/src/services/{change-streamer → change-source}/pg/schema/validation.d.ts +0 -0
- /package/out/zero-cache/src/services/{change-streamer → change-source}/pg/schema/validation.js +0 -0
- /package/out/zero-cache/src/services/{change-streamer → change-source}/pg/shard-config.d.ts +0 -0
- /package/out/zero-cache/src/services/{change-streamer → change-source}/pg/shard-config.js +0 -0
- /package/out/zero-cache/src/services/{change-streamer → change-source}/pg/sync-schema.d.ts +0 -0
|
@@ -7,19 +7,53 @@ import {
|
|
|
7
7
|
assertArray,
|
|
8
8
|
assertBoolean,
|
|
9
9
|
assertNotNull,
|
|
10
|
-
assertNotUndefined,
|
|
11
10
|
assertNumber,
|
|
12
11
|
assertObject,
|
|
13
12
|
assertString,
|
|
14
13
|
must,
|
|
15
14
|
throwInvalidType,
|
|
16
15
|
unreachable
|
|
17
|
-
} from "./chunk-
|
|
16
|
+
} from "./chunk-I5GSZARI.js";
|
|
18
17
|
import {
|
|
19
18
|
__export,
|
|
20
19
|
__reExport
|
|
21
20
|
} from "./chunk-F5QR3K72.js";
|
|
22
21
|
|
|
22
|
+
// ../replicache/src/call-default-fetch.ts
|
|
23
|
+
async function callDefaultFetch(url, auth, requestID, requestBody) {
|
|
24
|
+
const init = {
|
|
25
|
+
headers: {
|
|
26
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
27
|
+
"Content-type": "application/json",
|
|
28
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
29
|
+
"Authorization": auth,
|
|
30
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
31
|
+
"X-Replicache-RequestID": requestID
|
|
32
|
+
},
|
|
33
|
+
body: JSON.stringify(requestBody),
|
|
34
|
+
method: "POST"
|
|
35
|
+
};
|
|
36
|
+
const request = new Request(url, init);
|
|
37
|
+
const response = await fetch(request);
|
|
38
|
+
const httpStatusCode = response.status;
|
|
39
|
+
if (httpStatusCode !== 200) {
|
|
40
|
+
return [
|
|
41
|
+
void 0,
|
|
42
|
+
{
|
|
43
|
+
httpStatusCode,
|
|
44
|
+
errorMessage: await response.text()
|
|
45
|
+
}
|
|
46
|
+
];
|
|
47
|
+
}
|
|
48
|
+
return [
|
|
49
|
+
response,
|
|
50
|
+
{
|
|
51
|
+
httpStatusCode,
|
|
52
|
+
errorMessage: ""
|
|
53
|
+
}
|
|
54
|
+
];
|
|
55
|
+
}
|
|
56
|
+
|
|
23
57
|
// ../shared/src/config.ts
|
|
24
58
|
var isProd = process.env.NODE_ENV === "production";
|
|
25
59
|
|
|
@@ -163,41 +197,6 @@ function isJSONArray(v2, path2) {
|
|
|
163
197
|
return true;
|
|
164
198
|
}
|
|
165
199
|
|
|
166
|
-
// ../replicache/src/call-default-fetch.ts
|
|
167
|
-
async function callDefaultFetch(url, auth, requestID, requestBody) {
|
|
168
|
-
const init = {
|
|
169
|
-
headers: {
|
|
170
|
-
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
171
|
-
"Content-type": "application/json",
|
|
172
|
-
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
173
|
-
"Authorization": auth,
|
|
174
|
-
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
175
|
-
"X-Replicache-RequestID": requestID
|
|
176
|
-
},
|
|
177
|
-
body: JSON.stringify(requestBody),
|
|
178
|
-
method: "POST"
|
|
179
|
-
};
|
|
180
|
-
const request = new Request(url, init);
|
|
181
|
-
const response = await fetch(request);
|
|
182
|
-
const httpStatusCode = response.status;
|
|
183
|
-
if (httpStatusCode !== 200) {
|
|
184
|
-
return [
|
|
185
|
-
void 0,
|
|
186
|
-
{
|
|
187
|
-
httpStatusCode,
|
|
188
|
-
errorMessage: await response.text()
|
|
189
|
-
}
|
|
190
|
-
];
|
|
191
|
-
}
|
|
192
|
-
return [
|
|
193
|
-
response,
|
|
194
|
-
{
|
|
195
|
-
httpStatusCode,
|
|
196
|
-
errorMessage: ""
|
|
197
|
-
}
|
|
198
|
-
];
|
|
199
|
-
}
|
|
200
|
-
|
|
201
200
|
// ../shared/src/string-compare.ts
|
|
202
201
|
function stringCompare(a, b) {
|
|
203
202
|
if (a === b) {
|
|
@@ -341,18 +340,6 @@ var defaultPullers = /* @__PURE__ */ new WeakSet();
|
|
|
341
340
|
function isDefaultPuller(puller) {
|
|
342
341
|
return defaultPullers.has(puller);
|
|
343
342
|
}
|
|
344
|
-
function assertPullResponseV0(v2) {
|
|
345
|
-
assertObject(v2);
|
|
346
|
-
if (isClientStateNotFoundResponse(v2) || isVersionNotSupportedResponse(v2)) {
|
|
347
|
-
return;
|
|
348
|
-
}
|
|
349
|
-
const v22 = v2;
|
|
350
|
-
if (v22.cookie !== void 0) {
|
|
351
|
-
assertJSONValue(v22.cookie);
|
|
352
|
-
}
|
|
353
|
-
assertNumber(v22.lastMutationID);
|
|
354
|
-
assertPatchOperations(v22.patch);
|
|
355
|
-
}
|
|
356
343
|
function assertPullResponseV1(v2) {
|
|
357
344
|
assertObject(v2);
|
|
358
345
|
if (isClientStateNotFoundResponse(v2) || isVersionNotSupportedResponse(v2)) {
|
|
@@ -379,13 +366,6 @@ function assertPullerResultV1(v2) {
|
|
|
379
366
|
assertPullResponseV1(v2.response);
|
|
380
367
|
}
|
|
381
368
|
}
|
|
382
|
-
function assertPullerResultV0(v2) {
|
|
383
|
-
assertObject(v2);
|
|
384
|
-
assertHTTPRequestInfo(v2.httpRequestInfo);
|
|
385
|
-
if (v2.response !== void 0) {
|
|
386
|
-
assertPullResponseV0(v2.response);
|
|
387
|
-
}
|
|
388
|
-
}
|
|
389
369
|
|
|
390
370
|
// ../replicache/src/kv/idb-store.ts
|
|
391
371
|
import { resolver } from "@rocicorp/resolver";
|
|
@@ -746,7 +726,6 @@ function rejectIfClosed(tx) {
|
|
|
746
726
|
}
|
|
747
727
|
|
|
748
728
|
// ../replicache/src/format-version-enum.ts
|
|
749
|
-
var SDD = 4;
|
|
750
729
|
var DD31 = 5;
|
|
751
730
|
var V6 = 6;
|
|
752
731
|
var V7 = 7;
|
|
@@ -1469,9 +1448,6 @@ function createChunk(data, refs, chunkHasher) {
|
|
|
1469
1448
|
const hash2 = chunkHasher();
|
|
1470
1449
|
return new Chunk(hash2, data, refs);
|
|
1471
1450
|
}
|
|
1472
|
-
function throwChunkHasher() {
|
|
1473
|
-
throw new Error("unexpected call to compute chunk hash");
|
|
1474
|
-
}
|
|
1475
1451
|
|
|
1476
1452
|
// ../shared/src/random-uint64.ts
|
|
1477
1453
|
function randomUint64() {
|
|
@@ -2537,31 +2513,19 @@ var WriteImpl3 = class extends ReadImpl3 {
|
|
|
2537
2513
|
};
|
|
2538
2514
|
|
|
2539
2515
|
// ../replicache/src/db/meta-type-enum.ts
|
|
2540
|
-
var IndexChangeSDD = 1;
|
|
2541
|
-
var LocalSDD = 2;
|
|
2542
|
-
var SnapshotSDD = 3;
|
|
2543
2516
|
var LocalDD31 = 4;
|
|
2544
2517
|
var SnapshotDD31 = 5;
|
|
2545
2518
|
|
|
2546
2519
|
// ../replicache/src/db/commit.ts
|
|
2547
2520
|
var DEFAULT_HEAD_NAME = "main";
|
|
2548
|
-
function commitIsLocalSDD(commit) {
|
|
2549
|
-
return isLocalMetaSDD(commit.meta);
|
|
2550
|
-
}
|
|
2551
2521
|
function commitIsLocalDD31(commit) {
|
|
2552
2522
|
return isLocalMetaDD31(commit.meta);
|
|
2553
2523
|
}
|
|
2554
2524
|
function commitIsLocal(commit) {
|
|
2555
|
-
return commitIsLocalDD31(commit)
|
|
2556
|
-
}
|
|
2557
|
-
function commitIsSnapshotDD31(commit) {
|
|
2558
|
-
return isSnapshotMetaDD31(commit.meta);
|
|
2559
|
-
}
|
|
2560
|
-
function commitIsSnapshotSDD(commit) {
|
|
2561
|
-
return isSnapshotMetaSDD(commit.meta);
|
|
2525
|
+
return commitIsLocalDD31(commit);
|
|
2562
2526
|
}
|
|
2563
2527
|
function commitIsSnapshot(commit) {
|
|
2564
|
-
return
|
|
2528
|
+
return isSnapshotMetaDD31(commit.meta);
|
|
2565
2529
|
}
|
|
2566
2530
|
var Commit = class {
|
|
2567
2531
|
chunk;
|
|
@@ -2586,14 +2550,8 @@ var Commit = class {
|
|
|
2586
2550
|
};
|
|
2587
2551
|
async function getMutationID(clientID, dagRead, meta) {
|
|
2588
2552
|
switch (meta.type) {
|
|
2589
|
-
case IndexChangeSDD:
|
|
2590
|
-
return meta.lastMutationID;
|
|
2591
|
-
case SnapshotSDD:
|
|
2592
|
-
return meta.lastMutationID;
|
|
2593
2553
|
case SnapshotDD31:
|
|
2594
2554
|
return meta.lastMutationIDs[clientID] ?? 0;
|
|
2595
|
-
case LocalSDD:
|
|
2596
|
-
return meta.mutationID;
|
|
2597
2555
|
case LocalDD31: {
|
|
2598
2556
|
if (meta.clientID === clientID) {
|
|
2599
2557
|
return meta.mutationID;
|
|
@@ -2666,11 +2624,8 @@ async function baseSnapshotFromCommit(commit, dagRead) {
|
|
|
2666
2624
|
}
|
|
2667
2625
|
function snapshotMetaParts(c, clientID) {
|
|
2668
2626
|
const m = c.meta;
|
|
2669
|
-
|
|
2670
|
-
|
|
2671
|
-
return [lmid, m.cookieJSON];
|
|
2672
|
-
}
|
|
2673
|
-
return [m.lastMutationID, m.cookieJSON];
|
|
2627
|
+
const lmid = m.lastMutationIDs[clientID] ?? 0;
|
|
2628
|
+
return [lmid, m.cookieJSON];
|
|
2674
2629
|
}
|
|
2675
2630
|
function compareCookiesForSnapshots(a, b) {
|
|
2676
2631
|
return compareCookies(a.meta.cookieJSON, b.meta.cookieJSON);
|
|
@@ -2698,10 +2653,8 @@ async function commitFromHead(name, dagRead) {
|
|
|
2698
2653
|
const hash2 = await mustGetHeadHash(name, dagRead);
|
|
2699
2654
|
return commitFromHash(hash2, dagRead);
|
|
2700
2655
|
}
|
|
2701
|
-
function
|
|
2702
|
-
|
|
2703
|
-
}
|
|
2704
|
-
function assertLocalMetaSDD(v2) {
|
|
2656
|
+
function assertLocalMetaDD31(v2) {
|
|
2657
|
+
assertString(v2.clientID);
|
|
2705
2658
|
assertNumber(v2.mutationID);
|
|
2706
2659
|
assertString(v2.mutatorName);
|
|
2707
2660
|
if (!v2.mutatorName) {
|
|
@@ -2713,28 +2666,14 @@ function assertLocalMetaSDD(v2) {
|
|
|
2713
2666
|
}
|
|
2714
2667
|
assertNumber(v2.timestamp);
|
|
2715
2668
|
}
|
|
2716
|
-
function assertLocalMetaDD31(v2) {
|
|
2717
|
-
assertString(v2.clientID);
|
|
2718
|
-
assertLocalMetaSDD(v2);
|
|
2719
|
-
}
|
|
2720
2669
|
function isLocalMetaDD31(meta) {
|
|
2721
2670
|
return meta.type === LocalDD31;
|
|
2722
2671
|
}
|
|
2723
|
-
function
|
|
2724
|
-
return meta.type === LocalSDD;
|
|
2725
|
-
}
|
|
2726
|
-
function assertSnapshotMetaBase(v2) {
|
|
2672
|
+
function assertSnapshotMetaDD31(v2) {
|
|
2727
2673
|
if (v2.basisHash !== null) {
|
|
2728
2674
|
assertHash(v2.basisHash);
|
|
2729
2675
|
}
|
|
2730
2676
|
assertJSONValue(v2.cookieJSON);
|
|
2731
|
-
}
|
|
2732
|
-
function assertSnapshotMetaSDD(v2) {
|
|
2733
|
-
assertSnapshotMetaBase(v2);
|
|
2734
|
-
assertNumber(v2.lastMutationID);
|
|
2735
|
-
}
|
|
2736
|
-
function assertSnapshotMetaDD31(v2) {
|
|
2737
|
-
assertSnapshotMetaBase(v2);
|
|
2738
2677
|
assertLastMutationIDs(v2.lastMutationIDs);
|
|
2739
2678
|
}
|
|
2740
2679
|
function assertLastMutationIDs(v2) {
|
|
@@ -2749,9 +2688,6 @@ function assertSnapshotCommitDD31(c) {
|
|
|
2749
2688
|
function isSnapshotMetaDD31(meta) {
|
|
2750
2689
|
return meta.type === SnapshotDD31;
|
|
2751
2690
|
}
|
|
2752
|
-
function isSnapshotMetaSDD(meta) {
|
|
2753
|
-
return meta.type === SnapshotSDD;
|
|
2754
|
-
}
|
|
2755
2691
|
function assertMeta(v2) {
|
|
2756
2692
|
assertObject(v2);
|
|
2757
2693
|
assertDeepFrozen(v2);
|
|
@@ -2760,18 +2696,9 @@ function assertMeta(v2) {
|
|
|
2760
2696
|
}
|
|
2761
2697
|
assertNumber(v2.type);
|
|
2762
2698
|
switch (v2.type) {
|
|
2763
|
-
case IndexChangeSDD:
|
|
2764
|
-
assertIndexChangeMeta(v2);
|
|
2765
|
-
break;
|
|
2766
|
-
case LocalSDD:
|
|
2767
|
-
assertLocalMetaSDD(v2);
|
|
2768
|
-
break;
|
|
2769
2699
|
case LocalDD31:
|
|
2770
2700
|
assertLocalMetaDD31(v2);
|
|
2771
2701
|
break;
|
|
2772
|
-
case SnapshotSDD:
|
|
2773
|
-
assertSnapshotMetaSDD(v2);
|
|
2774
|
-
break;
|
|
2775
2702
|
case SnapshotDD31:
|
|
2776
2703
|
assertSnapshotMetaDD31(v2);
|
|
2777
2704
|
break;
|
|
@@ -2813,21 +2740,6 @@ function assertIndexRecords(v2) {
|
|
|
2813
2740
|
assertIndexRecord(ir);
|
|
2814
2741
|
}
|
|
2815
2742
|
}
|
|
2816
|
-
function newLocalSDD(createChunk2, basisHash, mutationID, mutatorName, mutatorArgsJSON, originalHash, valueHash, indexes, timestamp) {
|
|
2817
|
-
const meta = {
|
|
2818
|
-
type: LocalSDD,
|
|
2819
|
-
basisHash,
|
|
2820
|
-
mutationID,
|
|
2821
|
-
mutatorName,
|
|
2822
|
-
mutatorArgsJSON,
|
|
2823
|
-
originalHash,
|
|
2824
|
-
timestamp
|
|
2825
|
-
};
|
|
2826
|
-
return commitFromCommitData(
|
|
2827
|
-
createChunk2,
|
|
2828
|
-
makeCommitData(meta, valueHash, indexes)
|
|
2829
|
-
);
|
|
2830
|
-
}
|
|
2831
2743
|
function newLocalDD31(createChunk2, basisHash, baseSnapshotHash, mutationID, mutatorName, mutatorArgsJSON, originalHash, valueHash, indexes, timestamp, clientID) {
|
|
2832
2744
|
const meta = {
|
|
2833
2745
|
type: LocalDD31,
|
|
@@ -2845,18 +2757,6 @@ function newLocalDD31(createChunk2, basisHash, baseSnapshotHash, mutationID, mut
|
|
|
2845
2757
|
makeCommitData(meta, valueHash, indexes)
|
|
2846
2758
|
);
|
|
2847
2759
|
}
|
|
2848
|
-
function newSnapshotSDD(createChunk2, basisHash, lastMutationID, cookieJSON, valueHash, indexes) {
|
|
2849
|
-
return commitFromCommitData(
|
|
2850
|
-
createChunk2,
|
|
2851
|
-
newSnapshotCommitDataSDD(
|
|
2852
|
-
basisHash,
|
|
2853
|
-
lastMutationID,
|
|
2854
|
-
cookieJSON,
|
|
2855
|
-
valueHash,
|
|
2856
|
-
indexes
|
|
2857
|
-
)
|
|
2858
|
-
);
|
|
2859
|
-
}
|
|
2860
2760
|
function newSnapshotDD31(createChunk2, basisHash, lastMutationIDs, cookieJSON, valueHash, indexes) {
|
|
2861
2761
|
return commitFromCommitData(
|
|
2862
2762
|
createChunk2,
|
|
@@ -2869,15 +2769,6 @@ function newSnapshotDD31(createChunk2, basisHash, lastMutationIDs, cookieJSON, v
|
|
|
2869
2769
|
)
|
|
2870
2770
|
);
|
|
2871
2771
|
}
|
|
2872
|
-
function newSnapshotCommitDataSDD(basisHash, lastMutationID, cookieJSON, valueHash, indexes) {
|
|
2873
|
-
const meta = {
|
|
2874
|
-
type: SnapshotSDD,
|
|
2875
|
-
basisHash,
|
|
2876
|
-
lastMutationID,
|
|
2877
|
-
cookieJSON
|
|
2878
|
-
};
|
|
2879
|
-
return makeCommitData(meta, valueHash, indexes);
|
|
2880
|
-
}
|
|
2881
2772
|
function newSnapshotCommitDataDD31(basisHash, lastMutationIDs, cookieJSON, valueHash, indexes) {
|
|
2882
2773
|
const meta = {
|
|
2883
2774
|
type: SnapshotDD31,
|
|
@@ -2887,17 +2778,6 @@ function newSnapshotCommitDataDD31(basisHash, lastMutationIDs, cookieJSON, value
|
|
|
2887
2778
|
};
|
|
2888
2779
|
return makeCommitData(meta, valueHash, indexes);
|
|
2889
2780
|
}
|
|
2890
|
-
function newIndexChange(createChunk2, basisHash, lastMutationID, valueHash, indexes) {
|
|
2891
|
-
const meta = {
|
|
2892
|
-
type: IndexChangeSDD,
|
|
2893
|
-
basisHash,
|
|
2894
|
-
lastMutationID
|
|
2895
|
-
};
|
|
2896
|
-
return commitFromCommitData(
|
|
2897
|
-
createChunk2,
|
|
2898
|
-
makeCommitData(meta, valueHash, indexes)
|
|
2899
|
-
);
|
|
2900
|
-
}
|
|
2901
2781
|
function fromChunk(chunk) {
|
|
2902
2782
|
validateChunk(chunk);
|
|
2903
2783
|
return new Commit(chunk);
|
|
@@ -2910,14 +2790,9 @@ function getRefs(data) {
|
|
|
2910
2790
|
refs.add(data.valueHash);
|
|
2911
2791
|
const { meta } = data;
|
|
2912
2792
|
switch (meta.type) {
|
|
2913
|
-
case IndexChangeSDD:
|
|
2914
|
-
meta.basisHash && refs.add(meta.basisHash);
|
|
2915
|
-
break;
|
|
2916
|
-
case LocalSDD:
|
|
2917
2793
|
case LocalDD31:
|
|
2918
2794
|
meta.basisHash && refs.add(meta.basisHash);
|
|
2919
2795
|
break;
|
|
2920
|
-
case SnapshotSDD:
|
|
2921
2796
|
case SnapshotDD31:
|
|
2922
2797
|
break;
|
|
2923
2798
|
default:
|
|
@@ -4452,9 +4327,6 @@ var Write = class extends Read {
|
|
|
4452
4327
|
* comparison as well as returned in `get`.
|
|
4453
4328
|
*/
|
|
4454
4329
|
async put(lc, key, value) {
|
|
4455
|
-
if (this.#meta.type === IndexChangeSDD) {
|
|
4456
|
-
throw new Error("Not allowed");
|
|
4457
|
-
}
|
|
4458
4330
|
const oldVal = lazy(() => this.map.get(key));
|
|
4459
4331
|
await updateIndexes(lc, this.indexes, key, oldVal, value);
|
|
4460
4332
|
await this.map.put(key, value);
|
|
@@ -4463,9 +4335,6 @@ var Write = class extends Read {
|
|
|
4463
4335
|
return getMutationID(this.#clientID, this.#dagWrite, this.#meta);
|
|
4464
4336
|
}
|
|
4465
4337
|
async del(lc, key) {
|
|
4466
|
-
if (this.#meta.type === IndexChangeSDD) {
|
|
4467
|
-
throw new Error("Not allowed");
|
|
4468
|
-
}
|
|
4469
4338
|
const oldVal = lazy(() => this.map.get(key));
|
|
4470
4339
|
if (oldVal !== void 0) {
|
|
4471
4340
|
await updateIndexes(lc, this.indexes, key, oldVal, void 0);
|
|
@@ -4473,9 +4342,6 @@ var Write = class extends Read {
|
|
|
4473
4342
|
return this.map.del(key);
|
|
4474
4343
|
}
|
|
4475
4344
|
async clear() {
|
|
4476
|
-
if (this.#meta.type === IndexChangeSDD) {
|
|
4477
|
-
throw new Error("Not allowed");
|
|
4478
|
-
}
|
|
4479
4345
|
await this.map.clear();
|
|
4480
4346
|
const ps = [];
|
|
4481
4347
|
for (const idx of this.indexes.values()) {
|
|
@@ -4497,28 +4363,6 @@ var Write = class extends Read {
|
|
|
4497
4363
|
let commit;
|
|
4498
4364
|
const meta = this.#meta;
|
|
4499
4365
|
switch (meta.type) {
|
|
4500
|
-
case LocalSDD: {
|
|
4501
|
-
const {
|
|
4502
|
-
basisHash,
|
|
4503
|
-
mutationID,
|
|
4504
|
-
mutatorName,
|
|
4505
|
-
mutatorArgsJSON,
|
|
4506
|
-
originalHash,
|
|
4507
|
-
timestamp
|
|
4508
|
-
} = meta;
|
|
4509
|
-
commit = newLocalSDD(
|
|
4510
|
-
this.#dagWrite.createChunk,
|
|
4511
|
-
basisHash,
|
|
4512
|
-
mutationID,
|
|
4513
|
-
mutatorName,
|
|
4514
|
-
mutatorArgsJSON,
|
|
4515
|
-
originalHash,
|
|
4516
|
-
valueHash,
|
|
4517
|
-
indexRecords,
|
|
4518
|
-
timestamp
|
|
4519
|
-
);
|
|
4520
|
-
break;
|
|
4521
|
-
}
|
|
4522
4366
|
case LocalDD31: {
|
|
4523
4367
|
assert(this.#formatVersion >= DD31);
|
|
4524
4368
|
const {
|
|
@@ -4544,19 +4388,6 @@ var Write = class extends Read {
|
|
|
4544
4388
|
);
|
|
4545
4389
|
break;
|
|
4546
4390
|
}
|
|
4547
|
-
case SnapshotSDD: {
|
|
4548
|
-
assert(this.#formatVersion <= SDD);
|
|
4549
|
-
const { basisHash, lastMutationID, cookieJSON } = meta;
|
|
4550
|
-
commit = newSnapshotSDD(
|
|
4551
|
-
this.#dagWrite.createChunk,
|
|
4552
|
-
basisHash,
|
|
4553
|
-
lastMutationID,
|
|
4554
|
-
cookieJSON,
|
|
4555
|
-
valueHash,
|
|
4556
|
-
indexRecords
|
|
4557
|
-
);
|
|
4558
|
-
break;
|
|
4559
|
-
}
|
|
4560
4391
|
case SnapshotDD31: {
|
|
4561
4392
|
assert(this.#formatVersion > DD31);
|
|
4562
4393
|
const { basisHash, lastMutationIDs, cookieJSON } = meta;
|
|
@@ -4570,28 +4401,6 @@ var Write = class extends Read {
|
|
|
4570
4401
|
);
|
|
4571
4402
|
break;
|
|
4572
4403
|
}
|
|
4573
|
-
case IndexChangeSDD: {
|
|
4574
|
-
const { basisHash, lastMutationID } = meta;
|
|
4575
|
-
if (this.#basis !== void 0) {
|
|
4576
|
-
if (await this.#basis.getMutationID(
|
|
4577
|
-
this.#clientID,
|
|
4578
|
-
this.#dagWrite
|
|
4579
|
-
) !== lastMutationID) {
|
|
4580
|
-
throw new Error("Index change must not change mutationID");
|
|
4581
|
-
}
|
|
4582
|
-
if (this.#basis.valueHash !== valueHash) {
|
|
4583
|
-
throw new Error("Index change must not change valueHash");
|
|
4584
|
-
}
|
|
4585
|
-
}
|
|
4586
|
-
commit = newIndexChange(
|
|
4587
|
-
this.#dagWrite.createChunk,
|
|
4588
|
-
basisHash,
|
|
4589
|
-
lastMutationID,
|
|
4590
|
-
valueHash,
|
|
4591
|
-
indexRecords
|
|
4592
|
-
);
|
|
4593
|
-
break;
|
|
4594
|
-
}
|
|
4595
4404
|
}
|
|
4596
4405
|
await this.#dagWrite.putChunk(commit.chunk);
|
|
4597
4406
|
return commit;
|
|
@@ -4666,11 +4475,12 @@ async function newWriteLocal(basisHash, mutatorName, mutatorArgsJSON, originalHa
|
|
|
4666
4475
|
const bTreeWrite = new BTreeWrite(dagWrite, formatVersion, basis.valueHash);
|
|
4667
4476
|
const mutationID = await basis.getNextMutationID(clientID, dagWrite);
|
|
4668
4477
|
const indexes = readIndexesForWrite(basis, dagWrite, formatVersion);
|
|
4478
|
+
assert(formatVersion >= DD31);
|
|
4669
4479
|
return new Write(
|
|
4670
4480
|
dagWrite,
|
|
4671
4481
|
bTreeWrite,
|
|
4672
4482
|
basis,
|
|
4673
|
-
|
|
4483
|
+
{
|
|
4674
4484
|
type: LocalDD31,
|
|
4675
4485
|
basisHash,
|
|
4676
4486
|
baseSnapshotHash: await baseSnapshotHashFromHash(basisHash, dagWrite),
|
|
@@ -4680,34 +4490,12 @@ async function newWriteLocal(basisHash, mutatorName, mutatorArgsJSON, originalHa
|
|
|
4680
4490
|
originalHash,
|
|
4681
4491
|
timestamp,
|
|
4682
4492
|
clientID
|
|
4683
|
-
} : {
|
|
4684
|
-
type: LocalSDD,
|
|
4685
|
-
basisHash,
|
|
4686
|
-
mutatorName,
|
|
4687
|
-
mutatorArgsJSON,
|
|
4688
|
-
mutationID,
|
|
4689
|
-
originalHash,
|
|
4690
|
-
timestamp
|
|
4691
4493
|
},
|
|
4692
4494
|
indexes,
|
|
4693
4495
|
clientID,
|
|
4694
4496
|
formatVersion
|
|
4695
4497
|
);
|
|
4696
4498
|
}
|
|
4697
|
-
async function newWriteSnapshotSDD(basisHash, lastMutationID, cookieJSON, dagWrite, indexes, clientID, formatVersion) {
|
|
4698
|
-
assert(formatVersion <= SDD);
|
|
4699
|
-
const basis = await commitFromHash(basisHash, dagWrite);
|
|
4700
|
-
const bTreeWrite = new BTreeWrite(dagWrite, formatVersion, basis.valueHash);
|
|
4701
|
-
return new Write(
|
|
4702
|
-
dagWrite,
|
|
4703
|
-
bTreeWrite,
|
|
4704
|
-
basis,
|
|
4705
|
-
{ basisHash, type: SnapshotSDD, lastMutationID, cookieJSON },
|
|
4706
|
-
indexes,
|
|
4707
|
-
clientID,
|
|
4708
|
-
formatVersion
|
|
4709
|
-
);
|
|
4710
|
-
}
|
|
4711
4499
|
async function newWriteSnapshotDD31(basisHash, lastMutationIDs, cookieJSON, dagWrite, clientID, formatVersion) {
|
|
4712
4500
|
const basis = await commitFromHash(basisHash, dagWrite);
|
|
4713
4501
|
const bTreeWrite = new BTreeWrite(dagWrite, formatVersion, basis.valueHash);
|
|
@@ -4910,14 +4698,6 @@ function createLogContext(logLevel = "info", logSinks = [consoleLogSink], contex
|
|
|
4910
4698
|
return new LogContext(logLevel, context, logSink);
|
|
4911
4699
|
}
|
|
4912
4700
|
|
|
4913
|
-
// ../replicache/src/format-version.ts
|
|
4914
|
-
function parseReplicacheFormatVersion(v2) {
|
|
4915
|
-
if (v2 !== (v2 | 0) || v2 < SDD || v2 > Latest) {
|
|
4916
|
-
throw new Error(`Unsupported format version: ${v2}`);
|
|
4917
|
-
}
|
|
4918
|
-
return v2;
|
|
4919
|
-
}
|
|
4920
|
-
|
|
4921
4701
|
// ../replicache/src/index-defs.ts
|
|
4922
4702
|
var indexDefinitionSchema = readonlyObject({
|
|
4923
4703
|
prefix: valita_exports.string().optional(),
|
|
@@ -5111,9 +4891,13 @@ async function disableClientGroup(clientGroupID, dagWrite) {
|
|
|
5111
4891
|
await setClientGroup(clientGroupID, disabledClientGroup, dagWrite);
|
|
5112
4892
|
}
|
|
5113
4893
|
|
|
5114
|
-
// ../replicache/src/
|
|
5115
|
-
|
|
5116
|
-
|
|
4894
|
+
// ../replicache/src/to-error.ts
|
|
4895
|
+
function toError(e) {
|
|
4896
|
+
if (e instanceof Error) {
|
|
4897
|
+
return e;
|
|
4898
|
+
}
|
|
4899
|
+
return new Error(String(e));
|
|
4900
|
+
}
|
|
5117
4901
|
|
|
5118
4902
|
// ../replicache/src/with-transactions.ts
|
|
5119
4903
|
function withRead(store, fn) {
|
|
@@ -5138,404 +4922,10 @@ async function using(x, fn) {
|
|
|
5138
4922
|
}
|
|
5139
4923
|
}
|
|
5140
4924
|
|
|
5141
|
-
// ../replicache/src/
|
|
5142
|
-
|
|
5143
|
-
|
|
5144
|
-
|
|
5145
|
-
const low = randomUint64();
|
|
5146
|
-
const combined = high << 64n | low;
|
|
5147
|
-
return combined.toString(32).slice(-length).padStart(length, "0");
|
|
5148
|
-
}
|
|
5149
|
-
|
|
5150
|
-
// ../replicache/src/persist/clients.ts
|
|
5151
|
-
var clientV4Schema = readonlyObject({
|
|
5152
|
-
/**
|
|
5153
|
-
* A UNIX timestamp in milliseconds updated by the client once a minute
|
|
5154
|
-
* while it is active and every time the client persists its state to
|
|
5155
|
-
* the perdag.
|
|
5156
|
-
* Should only be updated by the client represented by this structure.
|
|
5157
|
-
*/
|
|
5158
|
-
heartbeatTimestampMs: valita_exports.number(),
|
|
5159
|
-
/**
|
|
5160
|
-
* The hash of the commit in the perdag this client last persisted.
|
|
5161
|
-
* Should only be updated by the client represented by this structure.
|
|
5162
|
-
*/
|
|
5163
|
-
headHash: hashSchema,
|
|
5164
|
-
/**
|
|
5165
|
-
* The mutationID of the commit at headHash (mutationID if it is a
|
|
5166
|
-
* local commit, lastMutationID if it is an index change or snapshot commit).
|
|
5167
|
-
* Should only be updated by the client represented by this structure.
|
|
5168
|
-
* Read by other clients to determine if there are unacknowledged pending
|
|
5169
|
-
* mutations for them to push on behalf of the client represented by this
|
|
5170
|
-
* structure.
|
|
5171
|
-
* This is redundant with information in the commit graph at headHash,
|
|
5172
|
-
* but allows other clients to determine if there are unacknowledged pending
|
|
5173
|
-
* mutations without having to load the commit graph at headHash.
|
|
5174
|
-
*/
|
|
5175
|
-
mutationID: valita_exports.number(),
|
|
5176
|
-
/**
|
|
5177
|
-
* The highest lastMutationID received from the server for this client.
|
|
5178
|
-
*
|
|
5179
|
-
* Should be updated by the client represented by this structure whenever
|
|
5180
|
-
* it persists its state to the perdag.
|
|
5181
|
-
* Read by other clients to determine if there are unacknowledged pending
|
|
5182
|
-
* mutations for them to push on behalf of the client represented by this
|
|
5183
|
-
* structure, and *updated* by other clients upon successfully pushing
|
|
5184
|
-
* pending mutations to avoid redundant pushes of those mutations.
|
|
5185
|
-
*
|
|
5186
|
-
* Note: This will be the same as the lastMutationID of the base snapshot of
|
|
5187
|
-
* the commit graph at headHash when written by the client represented by this
|
|
5188
|
-
* structure. However, when written by another client pushing pending
|
|
5189
|
-
* mutations on this client's behalf it will be different. This is because
|
|
5190
|
-
* the other client does not update the commit graph (it is unsafe to update
|
|
5191
|
-
* another client's commit graph).
|
|
5192
|
-
*/
|
|
5193
|
-
lastServerAckdMutationID: valita_exports.number()
|
|
5194
|
-
});
|
|
5195
|
-
var clientV5Schema = readonlyObject({
|
|
5196
|
-
heartbeatTimestampMs: valita_exports.number(),
|
|
5197
|
-
headHash: hashSchema,
|
|
5198
|
-
/**
|
|
5199
|
-
* The hash of a commit we are in the middle of refreshing into this client's
|
|
5200
|
-
* memdag.
|
|
5201
|
-
*/
|
|
5202
|
-
tempRefreshHash: hashSchema.nullable(),
|
|
5203
|
-
/**
|
|
5204
|
-
* ID of this client's perdag client group. This needs to be sent in pull
|
|
5205
|
-
* request (to enable syncing all last mutation ids in the client group).
|
|
5206
|
-
*/
|
|
5207
|
-
clientGroupID: clientGroupIDSchema
|
|
5208
|
-
});
|
|
5209
|
-
var clientV6Schema = readonlyObject({
|
|
5210
|
-
heartbeatTimestampMs: valita_exports.number(),
|
|
5211
|
-
/**
|
|
5212
|
-
* A set of hashes, which contains:
|
|
5213
|
-
* 1. The hash of the last commit this client refreshed from its client group
|
|
5214
|
-
* (this is the commit it bootstrapped from until it completes its first
|
|
5215
|
-
* refresh).
|
|
5216
|
-
* 2. One or more hashes that were added to retain chunks of a commit while it
|
|
5217
|
-
* was being refreshed into this client's memdag. (This can be one or more
|
|
5218
|
-
* because refresh's cleanup step is a separate transaction and can fail).
|
|
5219
|
-
* Upon refresh completing and successfully running its clean up step, this
|
|
5220
|
-
* set will contain a single hash: the hash of the last commit this client
|
|
5221
|
-
* refreshed.
|
|
5222
|
-
*/
|
|
5223
|
-
refreshHashes: readonlyArray(hashSchema),
|
|
5224
|
-
/**
|
|
5225
|
-
* The hash of the last snapshot commit persisted by this client to this
|
|
5226
|
-
* client's client group, or null if has never persisted a snapshot.
|
|
5227
|
-
*/
|
|
5228
|
-
persistHash: hashSchema.nullable(),
|
|
5229
|
-
/**
|
|
5230
|
-
* ID of this client's perdag client group. This needs to be sent in pull
|
|
5231
|
-
* request (to enable syncing all last mutation ids in the client group).
|
|
5232
|
-
*/
|
|
5233
|
-
clientGroupID: clientGroupIDSchema
|
|
5234
|
-
});
|
|
5235
|
-
function isClientV6(client) {
|
|
5236
|
-
return client.refreshHashes !== void 0;
|
|
5237
|
-
}
|
|
5238
|
-
function isClientV5(client) {
|
|
5239
|
-
return client.clientGroupID !== void 0;
|
|
5240
|
-
}
|
|
5241
|
-
var CLIENTS_HEAD_NAME = "clients";
|
|
5242
|
-
var clientSchema = valita_exports.union(
|
|
5243
|
-
clientV4Schema,
|
|
5244
|
-
clientV5Schema,
|
|
5245
|
-
clientV6Schema
|
|
5246
|
-
);
|
|
5247
|
-
function assertClient(value) {
|
|
5248
|
-
assert2(value, clientSchema);
|
|
5249
|
-
}
|
|
5250
|
-
function assertClientV4(value) {
|
|
5251
|
-
assert2(value, clientV4Schema);
|
|
5252
|
-
}
|
|
5253
|
-
function assertClientV6(value) {
|
|
5254
|
-
assert2(value, clientV6Schema);
|
|
5255
|
-
}
|
|
5256
|
-
function chunkDataToClientMap(chunkData) {
|
|
5257
|
-
assertObject(chunkData);
|
|
5258
|
-
const clients = /* @__PURE__ */ new Map();
|
|
5259
|
-
for (const key in chunkData) {
|
|
5260
|
-
if (hasOwn(chunkData, key)) {
|
|
5261
|
-
const value = chunkData[key];
|
|
5262
|
-
if (value !== void 0) {
|
|
5263
|
-
assertClient(value);
|
|
5264
|
-
clients.set(key, value);
|
|
5265
|
-
}
|
|
5266
|
-
}
|
|
5267
|
-
}
|
|
5268
|
-
return clients;
|
|
5269
|
-
}
|
|
5270
|
-
function clientMapToChunkData(clients, dagWrite) {
|
|
5271
|
-
for (const client of clients.values()) {
|
|
5272
|
-
if (isClientV6(client)) {
|
|
5273
|
-
client.refreshHashes.forEach(dagWrite.assertValidHash);
|
|
5274
|
-
if (client.persistHash) {
|
|
5275
|
-
dagWrite.assertValidHash(client.persistHash);
|
|
5276
|
-
}
|
|
5277
|
-
} else {
|
|
5278
|
-
dagWrite.assertValidHash(client.headHash);
|
|
5279
|
-
if (isClientV5(client) && client.tempRefreshHash) {
|
|
5280
|
-
dagWrite.assertValidHash(client.tempRefreshHash);
|
|
5281
|
-
}
|
|
5282
|
-
}
|
|
5283
|
-
}
|
|
5284
|
-
return deepFreeze(Object.fromEntries(clients));
|
|
5285
|
-
}
|
|
5286
|
-
async function getClients(dagRead) {
|
|
5287
|
-
const hash2 = await dagRead.getHead(CLIENTS_HEAD_NAME);
|
|
5288
|
-
return getClientsAtHash(hash2, dagRead);
|
|
5289
|
-
}
|
|
5290
|
-
async function getClientsAtHash(hash2, dagRead) {
|
|
5291
|
-
if (!hash2) {
|
|
5292
|
-
return /* @__PURE__ */ new Map();
|
|
5293
|
-
}
|
|
5294
|
-
const chunk = await dagRead.getChunk(hash2);
|
|
5295
|
-
return chunkDataToClientMap(chunk?.data);
|
|
5296
|
-
}
|
|
5297
|
-
var ClientStateNotFoundError = class extends Error {
|
|
5298
|
-
name = "ClientStateNotFoundError";
|
|
5299
|
-
id;
|
|
5300
|
-
constructor(id) {
|
|
5301
|
-
super(`Client state not found, id: ${id}`);
|
|
5302
|
-
this.id = id;
|
|
5303
|
-
}
|
|
5304
|
-
};
|
|
5305
|
-
async function assertHasClientState(id, dagRead) {
|
|
5306
|
-
if (!await hasClientState(id, dagRead)) {
|
|
5307
|
-
throw new ClientStateNotFoundError(id);
|
|
5308
|
-
}
|
|
5309
|
-
}
|
|
5310
|
-
async function hasClientState(id, dagRead) {
|
|
5311
|
-
return !!await getClient(id, dagRead);
|
|
5312
|
-
}
|
|
5313
|
-
async function getClient(id, dagRead) {
|
|
5314
|
-
const clients = await getClients(dagRead);
|
|
5315
|
-
return clients.get(id);
|
|
5316
|
-
}
|
|
5317
|
-
async function mustGetClient(id, dagRead) {
|
|
5318
|
-
const client = await getClient(id, dagRead);
|
|
5319
|
-
if (!client) {
|
|
5320
|
-
throw new ClientStateNotFoundError(id);
|
|
5321
|
-
}
|
|
5322
|
-
return client;
|
|
5323
|
-
}
|
|
5324
|
-
function initClientV6(newClientID, lc, perdag, mutatorNames, indexes, formatVersion, enableClientGroupForking) {
|
|
5325
|
-
return withWriteNoImplicitCommit(perdag, async (dagWrite) => {
|
|
5326
|
-
async function setClientsAndClientGroupAndCommit(basisHash, cookieJSON, valueHash2, indexRecords2) {
|
|
5327
|
-
const newSnapshotData = newSnapshotCommitDataDD31(
|
|
5328
|
-
basisHash,
|
|
5329
|
-
{},
|
|
5330
|
-
cookieJSON,
|
|
5331
|
-
valueHash2,
|
|
5332
|
-
indexRecords2
|
|
5333
|
-
);
|
|
5334
|
-
const chunk = dagWrite.createChunk(
|
|
5335
|
-
newSnapshotData,
|
|
5336
|
-
getRefs(newSnapshotData)
|
|
5337
|
-
);
|
|
5338
|
-
const newClientGroupID = makeClientID();
|
|
5339
|
-
const newClient = {
|
|
5340
|
-
heartbeatTimestampMs: Date.now(),
|
|
5341
|
-
refreshHashes: [chunk.hash],
|
|
5342
|
-
persistHash: null,
|
|
5343
|
-
clientGroupID: newClientGroupID
|
|
5344
|
-
};
|
|
5345
|
-
const newClients = new Map(clients).set(newClientID, newClient);
|
|
5346
|
-
const clientGroup = {
|
|
5347
|
-
headHash: chunk.hash,
|
|
5348
|
-
mutatorNames,
|
|
5349
|
-
indexes,
|
|
5350
|
-
mutationIDs: {},
|
|
5351
|
-
lastServerAckdMutationIDs: {},
|
|
5352
|
-
disabled: false
|
|
5353
|
-
};
|
|
5354
|
-
await Promise.all([
|
|
5355
|
-
dagWrite.putChunk(chunk),
|
|
5356
|
-
setClients(newClients, dagWrite),
|
|
5357
|
-
setClientGroup(newClientGroupID, clientGroup, dagWrite)
|
|
5358
|
-
]);
|
|
5359
|
-
await dagWrite.commit();
|
|
5360
|
-
return [newClient, chunk.hash, newClients, true];
|
|
5361
|
-
}
|
|
5362
|
-
const clients = await getClients(dagWrite);
|
|
5363
|
-
const res = await findMatchingClient(dagWrite, mutatorNames, indexes);
|
|
5364
|
-
if (res.type === FIND_MATCHING_CLIENT_TYPE_HEAD) {
|
|
5365
|
-
const { clientGroupID, headHash } = res;
|
|
5366
|
-
const newClient = {
|
|
5367
|
-
clientGroupID,
|
|
5368
|
-
refreshHashes: [headHash],
|
|
5369
|
-
heartbeatTimestampMs: Date.now(),
|
|
5370
|
-
persistHash: null
|
|
5371
|
-
};
|
|
5372
|
-
const newClients = new Map(clients).set(newClientID, newClient);
|
|
5373
|
-
await setClients(newClients, dagWrite);
|
|
5374
|
-
await dagWrite.commit();
|
|
5375
|
-
return [newClient, headHash, newClients, false];
|
|
5376
|
-
}
|
|
5377
|
-
if (!enableClientGroupForking || res.type === FIND_MATCHING_CLIENT_TYPE_NEW) {
|
|
5378
|
-
const emptyBTreeChunk = dagWrite.createChunk(emptyDataNode, []);
|
|
5379
|
-
await dagWrite.putChunk(emptyBTreeChunk);
|
|
5380
|
-
const indexRecords2 = [];
|
|
5381
|
-
for (const [name, indexDefinition] of Object.entries(indexes)) {
|
|
5382
|
-
const chunkIndexDefinition = toChunkIndexDefinition(
|
|
5383
|
-
name,
|
|
5384
|
-
indexDefinition
|
|
5385
|
-
);
|
|
5386
|
-
indexRecords2.push({
|
|
5387
|
-
definition: chunkIndexDefinition,
|
|
5388
|
-
valueHash: emptyBTreeChunk.hash
|
|
5389
|
-
});
|
|
5390
|
-
}
|
|
5391
|
-
return setClientsAndClientGroupAndCommit(
|
|
5392
|
-
null,
|
|
5393
|
-
null,
|
|
5394
|
-
emptyBTreeChunk.hash,
|
|
5395
|
-
indexRecords2
|
|
5396
|
-
);
|
|
5397
|
-
}
|
|
5398
|
-
assert(res.type === FIND_MATCHING_CLIENT_TYPE_FORK);
|
|
5399
|
-
const { snapshot } = res;
|
|
5400
|
-
const indexRecords = [];
|
|
5401
|
-
const { valueHash, indexes: oldIndexes } = snapshot;
|
|
5402
|
-
const map = new BTreeRead(dagWrite, formatVersion, valueHash);
|
|
5403
|
-
for (const [name, indexDefinition] of Object.entries(indexes)) {
|
|
5404
|
-
const { prefix = "", jsonPointer, allowEmpty = false } = indexDefinition;
|
|
5405
|
-
const chunkIndexDefinition = {
|
|
5406
|
-
name,
|
|
5407
|
-
keyPrefix: prefix,
|
|
5408
|
-
jsonPointer,
|
|
5409
|
-
allowEmpty
|
|
5410
|
-
};
|
|
5411
|
-
const oldIndex = findMatchingOldIndex(oldIndexes, chunkIndexDefinition);
|
|
5412
|
-
if (oldIndex) {
|
|
5413
|
-
indexRecords.push({
|
|
5414
|
-
definition: chunkIndexDefinition,
|
|
5415
|
-
valueHash: oldIndex.valueHash
|
|
5416
|
-
});
|
|
5417
|
-
} else {
|
|
5418
|
-
const indexBTree = await createIndexBTree(
|
|
5419
|
-
lc,
|
|
5420
|
-
dagWrite,
|
|
5421
|
-
map,
|
|
5422
|
-
prefix,
|
|
5423
|
-
jsonPointer,
|
|
5424
|
-
allowEmpty,
|
|
5425
|
-
formatVersion
|
|
5426
|
-
);
|
|
5427
|
-
indexRecords.push({
|
|
5428
|
-
definition: chunkIndexDefinition,
|
|
5429
|
-
valueHash: await indexBTree.flush()
|
|
5430
|
-
});
|
|
5431
|
-
}
|
|
5432
|
-
}
|
|
5433
|
-
return setClientsAndClientGroupAndCommit(
|
|
5434
|
-
snapshot.meta.basisHash,
|
|
5435
|
-
snapshot.meta.cookieJSON,
|
|
5436
|
-
snapshot.valueHash,
|
|
5437
|
-
indexRecords
|
|
5438
|
-
);
|
|
5439
|
-
});
|
|
5440
|
-
}
|
|
5441
|
-
function findMatchingOldIndex(oldIndexes, chunkIndexDefinition) {
|
|
5442
|
-
return oldIndexes.find(
|
|
5443
|
-
(index) => chunkIndexDefinitionEqualIgnoreName(index.definition, chunkIndexDefinition)
|
|
5444
|
-
);
|
|
5445
|
-
}
|
|
5446
|
-
var FIND_MATCHING_CLIENT_TYPE_NEW = 0;
|
|
5447
|
-
var FIND_MATCHING_CLIENT_TYPE_FORK = 1;
|
|
5448
|
-
var FIND_MATCHING_CLIENT_TYPE_HEAD = 2;
|
|
5449
|
-
async function findMatchingClient(dagRead, mutatorNames, indexes) {
|
|
5450
|
-
let newestCookie;
|
|
5451
|
-
let bestSnapshot;
|
|
5452
|
-
const mutatorNamesSet = new Set(mutatorNames);
|
|
5453
|
-
const clientGroups = await getClientGroups(dagRead);
|
|
5454
|
-
for (const [clientGroupID, clientGroup] of clientGroups) {
|
|
5455
|
-
if (!clientGroup.disabled && mutatorNamesEqual(mutatorNamesSet, clientGroup.mutatorNames) && indexDefinitionsEqual(indexes, clientGroup.indexes)) {
|
|
5456
|
-
return {
|
|
5457
|
-
type: FIND_MATCHING_CLIENT_TYPE_HEAD,
|
|
5458
|
-
clientGroupID,
|
|
5459
|
-
headHash: clientGroup.headHash
|
|
5460
|
-
};
|
|
5461
|
-
}
|
|
5462
|
-
const clientGroupSnapshotCommit = await baseSnapshotFromHash(
|
|
5463
|
-
clientGroup.headHash,
|
|
5464
|
-
dagRead
|
|
5465
|
-
);
|
|
5466
|
-
assertSnapshotCommitDD31(clientGroupSnapshotCommit);
|
|
5467
|
-
const { cookieJSON } = clientGroupSnapshotCommit.meta;
|
|
5468
|
-
if (newestCookie === void 0 || compareCookies(cookieJSON, newestCookie) > 0) {
|
|
5469
|
-
newestCookie = cookieJSON;
|
|
5470
|
-
bestSnapshot = clientGroupSnapshotCommit;
|
|
5471
|
-
}
|
|
5472
|
-
}
|
|
5473
|
-
if (bestSnapshot) {
|
|
5474
|
-
return {
|
|
5475
|
-
type: FIND_MATCHING_CLIENT_TYPE_FORK,
|
|
5476
|
-
snapshot: bestSnapshot
|
|
5477
|
-
};
|
|
5478
|
-
}
|
|
5479
|
-
return { type: FIND_MATCHING_CLIENT_TYPE_NEW };
|
|
5480
|
-
}
|
|
5481
|
-
function getRefsForClients(clients) {
|
|
5482
|
-
const refs = /* @__PURE__ */ new Set();
|
|
5483
|
-
for (const client of clients.values()) {
|
|
5484
|
-
if (isClientV6(client)) {
|
|
5485
|
-
for (const hash2 of client.refreshHashes) {
|
|
5486
|
-
refs.add(hash2);
|
|
5487
|
-
}
|
|
5488
|
-
if (client.persistHash) {
|
|
5489
|
-
refs.add(client.persistHash);
|
|
5490
|
-
}
|
|
5491
|
-
} else {
|
|
5492
|
-
refs.add(client.headHash);
|
|
5493
|
-
if (isClientV5(client) && client.tempRefreshHash) {
|
|
5494
|
-
refs.add(client.tempRefreshHash);
|
|
5495
|
-
}
|
|
5496
|
-
}
|
|
5497
|
-
}
|
|
5498
|
-
return toRefs(refs);
|
|
5499
|
-
}
|
|
5500
|
-
async function getClientGroupForClient(clientID, read) {
|
|
5501
|
-
const clientGroupID = await getClientGroupIDForClient(clientID, read);
|
|
5502
|
-
if (!clientGroupID) {
|
|
5503
|
-
return void 0;
|
|
5504
|
-
}
|
|
5505
|
-
return getClientGroup(clientGroupID, read);
|
|
5506
|
-
}
|
|
5507
|
-
async function getClientGroupIDForClient(clientID, read) {
|
|
5508
|
-
const client = await getClient(clientID, read);
|
|
5509
|
-
if (!client || !isClientV5(client)) {
|
|
5510
|
-
return void 0;
|
|
5511
|
-
}
|
|
5512
|
-
return client.clientGroupID;
|
|
5513
|
-
}
|
|
5514
|
-
async function setClient(clientID, client, dagWrite) {
|
|
5515
|
-
const clients = await getClients(dagWrite);
|
|
5516
|
-
const newClients = new Map(clients).set(clientID, client);
|
|
5517
|
-
return setClients(newClients, dagWrite);
|
|
5518
|
-
}
|
|
5519
|
-
async function setClients(clients, dagWrite) {
|
|
5520
|
-
const chunkData = clientMapToChunkData(clients, dagWrite);
|
|
5521
|
-
const chunk = dagWrite.createChunk(chunkData, getRefsForClients(clients));
|
|
5522
|
-
await dagWrite.putChunk(chunk);
|
|
5523
|
-
await dagWrite.setHead(CLIENTS_HEAD_NAME, chunk.hash);
|
|
5524
|
-
return chunk.hash;
|
|
5525
|
-
}
|
|
5526
|
-
|
|
5527
|
-
// ../replicache/src/to-error.ts
|
|
5528
|
-
function toError(e) {
|
|
5529
|
-
if (e instanceof Error) {
|
|
5530
|
-
return e;
|
|
5531
|
-
}
|
|
5532
|
-
return new Error(String(e));
|
|
5533
|
-
}
|
|
5534
|
-
|
|
5535
|
-
// ../replicache/src/sync/handle-pull-response-result-type-enum.ts
|
|
5536
|
-
var Applied = 0;
|
|
5537
|
-
var NoOp = 1;
|
|
5538
|
-
var CookieMismatch = 2;
|
|
4925
|
+
// ../replicache/src/sync/handle-pull-response-result-type-enum.ts
|
|
4926
|
+
var Applied = 0;
|
|
4927
|
+
var NoOp = 1;
|
|
4928
|
+
var CookieMismatch = 2;
|
|
5539
4929
|
|
|
5540
4930
|
// ../replicache/src/sync/patch.ts
|
|
5541
4931
|
async function apply(lc, dbWrite, patch) {
|
|
@@ -5593,67 +4983,7 @@ var PullError = class extends Error {
|
|
|
5593
4983
|
var SYNC_HEAD_NAME = "sync";
|
|
5594
4984
|
|
|
5595
4985
|
// ../replicache/src/sync/pull.ts
|
|
5596
|
-
var PULL_VERSION_SDD = 0;
|
|
5597
4986
|
var PULL_VERSION_DD31 = 1;
|
|
5598
|
-
function isPullRequestV1(pr) {
|
|
5599
|
-
return pr.pullVersion === PULL_VERSION_DD31;
|
|
5600
|
-
}
|
|
5601
|
-
async function beginPullV0(profileID, clientID, schemaVersion, puller, requestID, store, formatVersion, lc, createSyncBranch = true) {
|
|
5602
|
-
const [lastMutationID, baseCookie] = await withRead(store, async (dagRead) => {
|
|
5603
|
-
const mainHeadHash = await dagRead.getHead(DEFAULT_HEAD_NAME);
|
|
5604
|
-
if (!mainHeadHash) {
|
|
5605
|
-
throw new Error("Internal no main head found");
|
|
5606
|
-
}
|
|
5607
|
-
const baseSnapshot = await baseSnapshotFromHash(mainHeadHash, dagRead);
|
|
5608
|
-
const baseSnapshotMeta = baseSnapshot.meta;
|
|
5609
|
-
const baseCookie2 = baseSnapshotMeta.cookieJSON;
|
|
5610
|
-
const lastMutationID2 = await baseSnapshot.getMutationID(clientID, dagRead);
|
|
5611
|
-
return [lastMutationID2, baseCookie2];
|
|
5612
|
-
});
|
|
5613
|
-
const pullReq = {
|
|
5614
|
-
profileID,
|
|
5615
|
-
clientID,
|
|
5616
|
-
cookie: baseCookie,
|
|
5617
|
-
lastMutationID,
|
|
5618
|
-
pullVersion: PULL_VERSION_SDD,
|
|
5619
|
-
schemaVersion
|
|
5620
|
-
};
|
|
5621
|
-
const { response, httpRequestInfo } = await callPuller(
|
|
5622
|
-
lc,
|
|
5623
|
-
puller,
|
|
5624
|
-
pullReq,
|
|
5625
|
-
requestID
|
|
5626
|
-
);
|
|
5627
|
-
if (!response) {
|
|
5628
|
-
return {
|
|
5629
|
-
httpRequestInfo,
|
|
5630
|
-
syncHead: emptyHash
|
|
5631
|
-
};
|
|
5632
|
-
}
|
|
5633
|
-
if (!createSyncBranch || isErrorResponse(response)) {
|
|
5634
|
-
return {
|
|
5635
|
-
httpRequestInfo,
|
|
5636
|
-
pullResponse: response,
|
|
5637
|
-
syncHead: emptyHash
|
|
5638
|
-
};
|
|
5639
|
-
}
|
|
5640
|
-
const result = await handlePullResponseV0(
|
|
5641
|
-
lc,
|
|
5642
|
-
store,
|
|
5643
|
-
baseCookie,
|
|
5644
|
-
response,
|
|
5645
|
-
clientID,
|
|
5646
|
-
formatVersion
|
|
5647
|
-
);
|
|
5648
|
-
if (result.type === CookieMismatch) {
|
|
5649
|
-
throw new Error("Overlapping sync");
|
|
5650
|
-
}
|
|
5651
|
-
return {
|
|
5652
|
-
httpRequestInfo,
|
|
5653
|
-
pullResponse: response,
|
|
5654
|
-
syncHead: result.type === Applied ? result.syncHead : emptyHash
|
|
5655
|
-
};
|
|
5656
|
-
}
|
|
5657
4987
|
async function beginPullV1(profileID, clientID, clientGroupID, schemaVersion, puller, requestID, store, formatVersion, lc, createSyncBranch = true) {
|
|
5658
4988
|
const baseCookie = await withRead(store, async (dagRead) => {
|
|
5659
4989
|
const mainHeadHash = await dagRead.getHead(DEFAULT_HEAD_NAME);
|
|
@@ -5720,104 +5050,12 @@ async function callPuller(lc, puller, pullReq, requestID) {
|
|
|
5720
5050
|
throw new PullError(toError(e));
|
|
5721
5051
|
}
|
|
5722
5052
|
try {
|
|
5723
|
-
|
|
5724
|
-
assertPullerResultV1(pullerResult);
|
|
5725
|
-
} else {
|
|
5726
|
-
assertPullerResultV0(pullerResult);
|
|
5727
|
-
}
|
|
5053
|
+
assertPullerResultV1(pullerResult);
|
|
5728
5054
|
return pullerResult;
|
|
5729
5055
|
} catch (e) {
|
|
5730
5056
|
throw new ReportError("Invalid puller result", toError(e));
|
|
5731
5057
|
}
|
|
5732
5058
|
}
|
|
5733
|
-
function handlePullResponseV0(lc, store, expectedBaseCookie, response, clientID, formatVersion) {
|
|
5734
|
-
return withWriteNoImplicitCommit(store, async (dagWrite) => {
|
|
5735
|
-
assert(formatVersion <= SDD);
|
|
5736
|
-
const dagRead = dagWrite;
|
|
5737
|
-
const mainHead = await dagRead.getHead(DEFAULT_HEAD_NAME);
|
|
5738
|
-
if (mainHead === void 0) {
|
|
5739
|
-
throw new Error("Main head disappeared");
|
|
5740
|
-
}
|
|
5741
|
-
const baseSnapshot = await baseSnapshotFromHash(mainHead, dagRead);
|
|
5742
|
-
const [baseLastMutationID, baseCookie] = snapshotMetaParts(
|
|
5743
|
-
baseSnapshot,
|
|
5744
|
-
clientID
|
|
5745
|
-
);
|
|
5746
|
-
if (!deepEqual(expectedBaseCookie, baseCookie)) {
|
|
5747
|
-
return {
|
|
5748
|
-
type: CookieMismatch
|
|
5749
|
-
};
|
|
5750
|
-
}
|
|
5751
|
-
if (response.lastMutationID < baseLastMutationID) {
|
|
5752
|
-
throw new Error(
|
|
5753
|
-
badOrderMessage(
|
|
5754
|
-
`lastMutationID`,
|
|
5755
|
-
String(response.lastMutationID),
|
|
5756
|
-
String(baseLastMutationID)
|
|
5757
|
-
)
|
|
5758
|
-
);
|
|
5759
|
-
}
|
|
5760
|
-
const frozenCookie = deepFreeze(response.cookie ?? null);
|
|
5761
|
-
if (deepEqual(frozenCookie, baseCookie)) {
|
|
5762
|
-
if (response.patch.length > 0) {
|
|
5763
|
-
lc.error?.(
|
|
5764
|
-
`handlePullResponse: cookie ${JSON.stringify(
|
|
5765
|
-
baseCookie
|
|
5766
|
-
)} did not change, but patch is not empty`
|
|
5767
|
-
);
|
|
5768
|
-
}
|
|
5769
|
-
if (response.lastMutationID !== baseLastMutationID) {
|
|
5770
|
-
lc.error?.(
|
|
5771
|
-
`handlePullResponse: cookie ${JSON.stringify(
|
|
5772
|
-
baseCookie
|
|
5773
|
-
)} did not change, but lastMutationID did change`
|
|
5774
|
-
);
|
|
5775
|
-
}
|
|
5776
|
-
return {
|
|
5777
|
-
type: NoOp
|
|
5778
|
-
};
|
|
5779
|
-
}
|
|
5780
|
-
const chain = await commitChain(mainHead, dagRead);
|
|
5781
|
-
let lastIntegrated;
|
|
5782
|
-
for (const commit of chain) {
|
|
5783
|
-
if (await commit.getMutationID(clientID, dagRead) <= response.lastMutationID) {
|
|
5784
|
-
lastIntegrated = commit;
|
|
5785
|
-
break;
|
|
5786
|
-
}
|
|
5787
|
-
}
|
|
5788
|
-
if (!lastIntegrated) {
|
|
5789
|
-
throw new Error("Internal invalid chain");
|
|
5790
|
-
}
|
|
5791
|
-
const dbWrite = await newWriteSnapshotSDD(
|
|
5792
|
-
baseSnapshot.chunk.hash,
|
|
5793
|
-
response.lastMutationID,
|
|
5794
|
-
frozenCookie,
|
|
5795
|
-
dagWrite,
|
|
5796
|
-
readIndexesForWrite(lastIntegrated, dagWrite, formatVersion),
|
|
5797
|
-
clientID,
|
|
5798
|
-
formatVersion
|
|
5799
|
-
);
|
|
5800
|
-
await apply(lc, dbWrite, response.patch);
|
|
5801
|
-
const lastIntegratedMap = new BTreeRead(
|
|
5802
|
-
dagRead,
|
|
5803
|
-
formatVersion,
|
|
5804
|
-
lastIntegrated.valueHash
|
|
5805
|
-
);
|
|
5806
|
-
for await (const change of dbWrite.map.diff(lastIntegratedMap)) {
|
|
5807
|
-
await updateIndexes(
|
|
5808
|
-
lc,
|
|
5809
|
-
dbWrite.indexes,
|
|
5810
|
-
change.key,
|
|
5811
|
-
() => Promise.resolve(change.oldValue),
|
|
5812
|
-
change.newValue
|
|
5813
|
-
);
|
|
5814
|
-
}
|
|
5815
|
-
return {
|
|
5816
|
-
type: Applied,
|
|
5817
|
-
syncHead: await dbWrite.commit(SYNC_HEAD_NAME)
|
|
5818
|
-
};
|
|
5819
|
-
});
|
|
5820
|
-
}
|
|
5821
5059
|
function badOrderMessage(name, receivedValue, lastSnapshotValue) {
|
|
5822
5060
|
return `Received ${name} ${receivedValue} is < than last snapshot ${name} ${lastSnapshotValue}; ignoring client view`;
|
|
5823
5061
|
}
|
|
@@ -5934,9 +5172,8 @@ function maybeEndPull(store, lc, expectedSyncHead, clientID, diffConfig, formatV
|
|
|
5934
5172
|
const localMutations2 = await localMutations(mainHeadHash, dagRead);
|
|
5935
5173
|
for (const commit of localMutations2) {
|
|
5936
5174
|
let cid = clientID;
|
|
5937
|
-
|
|
5938
|
-
|
|
5939
|
-
}
|
|
5175
|
+
assert(commitIsLocalDD31(commit));
|
|
5176
|
+
cid = commit.meta.clientID;
|
|
5940
5177
|
if (await commit.getMutationID(cid, dagRead) > await syncHead.getMutationID(cid, dagRead)) {
|
|
5941
5178
|
pending.push(commit);
|
|
5942
5179
|
}
|
|
@@ -6071,15 +5308,12 @@ var PushError = class extends Error {
|
|
|
6071
5308
|
}
|
|
6072
5309
|
};
|
|
6073
5310
|
|
|
5311
|
+
// ../replicache/src/sync/ids.ts
|
|
5312
|
+
var clientGroupIDSchema = valita_exports.string();
|
|
5313
|
+
var clientIDSchema = valita_exports.string();
|
|
5314
|
+
|
|
6074
5315
|
// ../replicache/src/sync/push.ts
|
|
6075
|
-
var PUSH_VERSION_SDD = 0;
|
|
6076
5316
|
var PUSH_VERSION_DD31 = 1;
|
|
6077
|
-
var mutationV0Schema = readonlyObject({
|
|
6078
|
-
id: valita_exports.number(),
|
|
6079
|
-
name: valita_exports.string(),
|
|
6080
|
-
args: jsonSchema,
|
|
6081
|
-
timestamp: valita_exports.number()
|
|
6082
|
-
});
|
|
6083
5317
|
var mutationV1Schema = readonlyObject({
|
|
6084
5318
|
id: valita_exports.number(),
|
|
6085
5319
|
name: valita_exports.string(),
|
|
@@ -6087,13 +5321,6 @@ var mutationV1Schema = readonlyObject({
|
|
|
6087
5321
|
timestamp: valita_exports.number(),
|
|
6088
5322
|
clientID: clientIDSchema
|
|
6089
5323
|
});
|
|
6090
|
-
var pushRequestV0Schema = valita_exports.object({
|
|
6091
|
-
pushVersion: valita_exports.literal(0),
|
|
6092
|
-
schemaVersion: valita_exports.string(),
|
|
6093
|
-
profileID: valita_exports.string(),
|
|
6094
|
-
clientID: clientIDSchema,
|
|
6095
|
-
mutations: valita_exports.array(mutationV0Schema)
|
|
6096
|
-
});
|
|
6097
5324
|
var pushRequestV1Schema = valita_exports.object({
|
|
6098
5325
|
pushVersion: valita_exports.literal(1),
|
|
6099
5326
|
schemaVersion: valita_exports.string(),
|
|
@@ -6101,14 +5328,6 @@ var pushRequestV1Schema = valita_exports.object({
|
|
|
6101
5328
|
clientGroupID: clientGroupIDSchema,
|
|
6102
5329
|
mutations: valita_exports.array(mutationV1Schema)
|
|
6103
5330
|
});
|
|
6104
|
-
function convertSDD(lm) {
|
|
6105
|
-
return {
|
|
6106
|
-
id: lm.mutationID,
|
|
6107
|
-
name: lm.mutatorName,
|
|
6108
|
-
args: lm.mutatorArgsJSON,
|
|
6109
|
-
timestamp: lm.timestamp
|
|
6110
|
-
};
|
|
6111
|
-
}
|
|
6112
5331
|
function convertDD31(lm) {
|
|
6113
5332
|
return {
|
|
6114
5333
|
id: lm.mutationID,
|
|
@@ -6118,7 +5337,7 @@ function convertDD31(lm) {
|
|
|
6118
5337
|
clientID: lm.clientID
|
|
6119
5338
|
};
|
|
6120
5339
|
}
|
|
6121
|
-
async function push(requestID, store, lc, profileID, clientGroupID,
|
|
5340
|
+
async function push(requestID, store, lc, profileID, clientGroupID, _clientID, pusher, schemaVersion, pushVersion) {
|
|
6122
5341
|
const pending = await withRead(store, async (dagRead) => {
|
|
6123
5342
|
const mainHeadHash = await dagRead.getHead(DEFAULT_HEAD_NAME);
|
|
6124
5343
|
if (!mainHeadHash) {
|
|
@@ -6130,43 +5349,23 @@ async function push(requestID, store, lc, profileID, clientGroupID, clientID, pu
|
|
|
6130
5349
|
return void 0;
|
|
6131
5350
|
}
|
|
6132
5351
|
pending.reverse();
|
|
6133
|
-
|
|
6134
|
-
|
|
6135
|
-
|
|
6136
|
-
|
|
6137
|
-
|
|
6138
|
-
|
|
6139
|
-
|
|
6140
|
-
throw new Error("Internal non local pending commit");
|
|
6141
|
-
}
|
|
6142
|
-
}
|
|
6143
|
-
assert(clientGroupID);
|
|
6144
|
-
const r = {
|
|
6145
|
-
profileID,
|
|
6146
|
-
clientGroupID,
|
|
6147
|
-
mutations: pushMutations,
|
|
6148
|
-
pushVersion: PUSH_VERSION_DD31,
|
|
6149
|
-
schemaVersion
|
|
6150
|
-
};
|
|
6151
|
-
pushReq = r;
|
|
6152
|
-
} else {
|
|
6153
|
-
assert(pushVersion === PUSH_VERSION_SDD);
|
|
6154
|
-
const pushMutations = [];
|
|
6155
|
-
for (const commit of pending) {
|
|
6156
|
-
if (commitIsLocalSDD(commit)) {
|
|
6157
|
-
pushMutations.push(convertSDD(commit.meta));
|
|
6158
|
-
} else {
|
|
6159
|
-
throw new Error("Internal non local pending commit");
|
|
6160
|
-
}
|
|
5352
|
+
assert(pushVersion === PUSH_VERSION_DD31);
|
|
5353
|
+
const pushMutations = [];
|
|
5354
|
+
for (const commit of pending) {
|
|
5355
|
+
if (commitIsLocalDD31(commit)) {
|
|
5356
|
+
pushMutations.push(convertDD31(commit.meta));
|
|
5357
|
+
} else {
|
|
5358
|
+
throw new Error("Internal non local pending commit");
|
|
6161
5359
|
}
|
|
6162
|
-
pushReq = {
|
|
6163
|
-
profileID,
|
|
6164
|
-
clientID,
|
|
6165
|
-
mutations: pushMutations,
|
|
6166
|
-
pushVersion: PUSH_VERSION_SDD,
|
|
6167
|
-
schemaVersion
|
|
6168
|
-
};
|
|
6169
5360
|
}
|
|
5361
|
+
assert(clientGroupID);
|
|
5362
|
+
const pushReq = {
|
|
5363
|
+
profileID,
|
|
5364
|
+
clientGroupID,
|
|
5365
|
+
mutations: pushMutations,
|
|
5366
|
+
pushVersion: PUSH_VERSION_DD31,
|
|
5367
|
+
schemaVersion
|
|
5368
|
+
};
|
|
6170
5369
|
lc.debug?.("Starting push...");
|
|
6171
5370
|
const pushStart = Date.now();
|
|
6172
5371
|
const pusherResult = await callPusher(pusher, pushReq, requestID);
|
|
@@ -6190,711 +5389,532 @@ async function callPusher(pusher, body, requestID) {
|
|
|
6190
5389
|
|
|
6191
5390
|
// ../replicache/src/mutation-recovery.ts
|
|
6192
5391
|
var MUTATION_RECOVERY_LAZY_STORE_SOURCE_CHUNK_CACHE_SIZE_LIMIT = 10 * 2 ** 20;
|
|
6193
|
-
|
|
6194
|
-
|
|
6195
|
-
|
|
6196
|
-
|
|
6197
|
-
|
|
5392
|
+
|
|
5393
|
+
// ../replicache/src/broadcast-channel.ts
|
|
5394
|
+
var NoopBroadcastChannel = class {
|
|
5395
|
+
name;
|
|
5396
|
+
onmessage = null;
|
|
5397
|
+
onmessageerror = null;
|
|
5398
|
+
constructor(name) {
|
|
5399
|
+
this.name = name;
|
|
6198
5400
|
}
|
|
6199
|
-
|
|
6200
|
-
|
|
6201
|
-
|
|
6202
|
-
|
|
6203
|
-
|
|
6204
|
-
|
|
6205
|
-
|
|
6206
|
-
|
|
6207
|
-
|
|
6208
|
-
|
|
6209
|
-
|
|
6210
|
-
|
|
6211
|
-
|
|
6212
|
-
|
|
6213
|
-
|
|
6214
|
-
|
|
6215
|
-
|
|
6216
|
-
|
|
6217
|
-
|
|
6218
|
-
|
|
6219
|
-
|
|
6220
|
-
|
|
6221
|
-
|
|
6222
|
-
|
|
6223
|
-
|
|
6224
|
-
|
|
6225
|
-
|
|
6226
|
-
|
|
6227
|
-
|
|
6228
|
-
|
|
6229
|
-
|
|
6230
|
-
|
|
6231
|
-
|
|
5401
|
+
addEventListener() {
|
|
5402
|
+
}
|
|
5403
|
+
removeEventListener() {
|
|
5404
|
+
}
|
|
5405
|
+
dispatchEvent() {
|
|
5406
|
+
return false;
|
|
5407
|
+
}
|
|
5408
|
+
close() {
|
|
5409
|
+
}
|
|
5410
|
+
postMessage() {
|
|
5411
|
+
}
|
|
5412
|
+
};
|
|
5413
|
+
var bc = typeof BroadcastChannel === "undefined" ? NoopBroadcastChannel : BroadcastChannel;
|
|
5414
|
+
|
|
5415
|
+
// ../replicache/src/new-client-channel.ts
|
|
5416
|
+
function makeChannelNameV0(replicacheName) {
|
|
5417
|
+
return `replicache-new-client-group:${replicacheName}`;
|
|
5418
|
+
}
|
|
5419
|
+
function makeChannelNameV1(replicacheName) {
|
|
5420
|
+
return `replicache-new-client-group-v1:${replicacheName}`;
|
|
5421
|
+
}
|
|
5422
|
+
function isNewClientChannelMessageV1(message) {
|
|
5423
|
+
return typeof message === "object" && typeof message.clientGroupID === "string" && typeof message.idbName === "string";
|
|
5424
|
+
}
|
|
5425
|
+
function initNewClientChannel(replicacheName, idbName, signal, clientGroupID, isNewClientGroup, onUpdateNeeded, perdag) {
|
|
5426
|
+
if (signal.aborted) {
|
|
5427
|
+
return;
|
|
5428
|
+
}
|
|
5429
|
+
const channelV1 = new bc(makeChannelNameV1(replicacheName));
|
|
5430
|
+
if (isNewClientGroup) {
|
|
5431
|
+
channelV1.postMessage({ clientGroupID, idbName });
|
|
5432
|
+
const channelV0 = new bc(makeChannelNameV0(replicacheName));
|
|
5433
|
+
channelV0.postMessage([clientGroupID]);
|
|
5434
|
+
channelV0.close();
|
|
5435
|
+
}
|
|
5436
|
+
channelV1.onmessage = async (e) => {
|
|
5437
|
+
const { data } = e;
|
|
5438
|
+
if (isNewClientChannelMessageV1(data)) {
|
|
5439
|
+
const { clientGroupID: newClientGroupID, idbName: newClientIDBName } = data;
|
|
5440
|
+
if (newClientGroupID !== clientGroupID) {
|
|
5441
|
+
if (newClientIDBName === idbName) {
|
|
5442
|
+
const updateNeeded = await withRead(
|
|
5443
|
+
perdag,
|
|
5444
|
+
async (perdagRead) => await getClientGroup(newClientGroupID, perdagRead) !== void 0
|
|
5445
|
+
);
|
|
5446
|
+
if (updateNeeded) {
|
|
5447
|
+
onUpdateNeeded();
|
|
6232
5448
|
}
|
|
5449
|
+
} else {
|
|
5450
|
+
onUpdateNeeded();
|
|
5451
|
+
return;
|
|
6233
5452
|
}
|
|
6234
5453
|
}
|
|
6235
|
-
} catch (e) {
|
|
6236
|
-
logMutationRecoveryError(e, lc, stepDescription, delegate);
|
|
6237
|
-
} finally {
|
|
6238
|
-
lc.debug?.("End:", stepDescription);
|
|
6239
|
-
this.#recoveringMutations = false;
|
|
6240
5454
|
}
|
|
6241
|
-
|
|
6242
|
-
}
|
|
6243
|
-
};
|
|
6244
|
-
function logMutationRecoveryError(e, lc, stepDescription, closedDelegate) {
|
|
6245
|
-
if (closedDelegate.closed) {
|
|
6246
|
-
lc.debug?.(
|
|
6247
|
-
`Mutation recovery error likely due to close during:
|
|
6248
|
-
${stepDescription}
|
|
6249
|
-
Error:
|
|
6250
|
-
`,
|
|
6251
|
-
e
|
|
6252
|
-
);
|
|
6253
|
-
} else {
|
|
6254
|
-
lc.error?.(
|
|
6255
|
-
`Mutation recovery error during:
|
|
6256
|
-
${stepDescription}
|
|
6257
|
-
Error:
|
|
6258
|
-
`,
|
|
6259
|
-
e
|
|
6260
|
-
);
|
|
6261
|
-
}
|
|
5455
|
+
};
|
|
5456
|
+
signal.addEventListener("abort", () => channelV1.close(), { once: true });
|
|
6262
5457
|
}
|
|
6263
|
-
|
|
6264
|
-
|
|
6265
|
-
|
|
6266
|
-
|
|
6267
|
-
|
|
6268
|
-
|
|
6269
|
-
|
|
6270
|
-
|
|
6271
|
-
|
|
6272
|
-
|
|
6273
|
-
|
|
6274
|
-
|
|
6275
|
-
|
|
6276
|
-
return;
|
|
6277
|
-
}
|
|
6278
|
-
if (client.lastServerAckdMutationID >= client.mutationID) {
|
|
6279
|
-
return;
|
|
5458
|
+
|
|
5459
|
+
// ../replicache/src/on-persist-channel.ts
|
|
5460
|
+
function makeChannelName(replicacheName) {
|
|
5461
|
+
return `replicache-on-persist:${replicacheName}`;
|
|
5462
|
+
}
|
|
5463
|
+
function assertPersistInfo(value) {
|
|
5464
|
+
assertObject(value);
|
|
5465
|
+
assertString(value.clientGroupID);
|
|
5466
|
+
assertString(value.clientID);
|
|
5467
|
+
}
|
|
5468
|
+
function initOnPersistChannel(replicacheName, signal, handlePersist) {
|
|
5469
|
+
if (signal.aborted) {
|
|
5470
|
+
return () => void 0;
|
|
6280
5471
|
}
|
|
6281
|
-
const
|
|
6282
|
-
|
|
6283
|
-
|
|
6284
|
-
|
|
6285
|
-
|
|
6286
|
-
|
|
6287
|
-
|
|
6288
|
-
|
|
6289
|
-
|
|
6290
|
-
|
|
6291
|
-
|
|
6292
|
-
|
|
6293
|
-
);
|
|
6294
|
-
if (isPushDisabled()) {
|
|
6295
|
-
lc.debug?.(
|
|
6296
|
-
`Cannot recover mutations for client ${clientID} because push is disabled.`
|
|
6297
|
-
);
|
|
6298
|
-
return;
|
|
6299
|
-
}
|
|
6300
|
-
const { pusher } = delegate;
|
|
6301
|
-
const pushDescription = "recoveringMutationsPush";
|
|
6302
|
-
const pushSucceeded = await wrapInOnlineCheck(async () => {
|
|
6303
|
-
const { result: pusherResult } = await wrapInReauthRetries(
|
|
6304
|
-
async (requestID, requestLc) => {
|
|
6305
|
-
assertNotUndefined(lazyDagForOtherClient);
|
|
6306
|
-
const pusherResult2 = await push(
|
|
6307
|
-
requestID,
|
|
6308
|
-
lazyDagForOtherClient,
|
|
6309
|
-
requestLc,
|
|
6310
|
-
await delegate.profileID,
|
|
6311
|
-
void 0,
|
|
6312
|
-
clientID,
|
|
6313
|
-
pusher,
|
|
6314
|
-
database.schemaVersion,
|
|
6315
|
-
PUSH_VERSION_SDD
|
|
6316
|
-
);
|
|
6317
|
-
return {
|
|
6318
|
-
result: pusherResult2,
|
|
6319
|
-
httpRequestInfo: pusherResult2?.httpRequestInfo
|
|
6320
|
-
};
|
|
6321
|
-
},
|
|
6322
|
-
pushDescription,
|
|
6323
|
-
lc
|
|
6324
|
-
);
|
|
6325
|
-
return !!pusherResult && pusherResult.httpRequestInfo.httpStatusCode === 200;
|
|
6326
|
-
}, pushDescription);
|
|
6327
|
-
if (!pushSucceeded) {
|
|
6328
|
-
lc.debug?.(
|
|
6329
|
-
`Failed to recover mutations for client ${clientID} due to a push error.`
|
|
6330
|
-
);
|
|
6331
|
-
return;
|
|
6332
|
-
}
|
|
6333
|
-
if (isPullDisabled()) {
|
|
6334
|
-
lc.debug?.(
|
|
6335
|
-
`Cannot confirm mutations were recovered for client ${clientID} because pull is disabled.`
|
|
6336
|
-
);
|
|
6337
|
-
return;
|
|
6338
|
-
}
|
|
6339
|
-
const { puller } = delegate;
|
|
6340
|
-
const pullDescription = "recoveringMutationsPull";
|
|
6341
|
-
let pullResponse;
|
|
6342
|
-
const pullSucceeded = await wrapInOnlineCheck(async () => {
|
|
6343
|
-
const { result: beginPullResponse } = await wrapInReauthRetries(
|
|
6344
|
-
async (requestID, requestLc) => {
|
|
6345
|
-
const beginPullResponse2 = await beginPullV0(
|
|
6346
|
-
await delegate.profileID,
|
|
6347
|
-
clientID,
|
|
6348
|
-
database.schemaVersion,
|
|
6349
|
-
puller,
|
|
6350
|
-
requestID,
|
|
6351
|
-
lazyDagForOtherClient,
|
|
6352
|
-
formatVersion,
|
|
6353
|
-
requestLc,
|
|
6354
|
-
false
|
|
6355
|
-
);
|
|
6356
|
-
return {
|
|
6357
|
-
result: beginPullResponse2,
|
|
6358
|
-
httpRequestInfo: beginPullResponse2.httpRequestInfo
|
|
6359
|
-
};
|
|
6360
|
-
},
|
|
6361
|
-
pullDescription,
|
|
6362
|
-
lc
|
|
6363
|
-
);
|
|
6364
|
-
({ pullResponse } = beginPullResponse);
|
|
6365
|
-
return !!pullResponse && beginPullResponse.httpRequestInfo.httpStatusCode === 200;
|
|
6366
|
-
}, pullDescription);
|
|
6367
|
-
if (!pullSucceeded) {
|
|
6368
|
-
lc.debug?.(
|
|
6369
|
-
`Failed to recover mutations for client ${clientID} due to a pull error.`
|
|
6370
|
-
);
|
|
5472
|
+
const channel = new bc(makeChannelName(replicacheName));
|
|
5473
|
+
channel.onmessage = (e) => {
|
|
5474
|
+
const { data } = e;
|
|
5475
|
+
assertPersistInfo(data);
|
|
5476
|
+
handlePersist({
|
|
5477
|
+
clientGroupID: data.clientGroupID,
|
|
5478
|
+
clientID: data.clientID
|
|
5479
|
+
});
|
|
5480
|
+
};
|
|
5481
|
+
signal.addEventListener("abort", () => channel.close(), { once: true });
|
|
5482
|
+
return (persistInfo) => {
|
|
5483
|
+
if (signal.aborted) {
|
|
6371
5484
|
return;
|
|
6372
5485
|
}
|
|
6373
|
-
|
|
6374
|
-
|
|
6375
|
-
|
|
6376
|
-
|
|
6377
|
-
|
|
6378
|
-
|
|
6379
|
-
|
|
6380
|
-
|
|
6381
|
-
|
|
6382
|
-
|
|
6383
|
-
|
|
6384
|
-
|
|
6385
|
-
|
|
6386
|
-
|
|
6387
|
-
|
|
6388
|
-
|
|
6389
|
-
|
|
6390
|
-
|
|
5486
|
+
channel.postMessage(persistInfo);
|
|
5487
|
+
handlePersist(persistInfo);
|
|
5488
|
+
};
|
|
5489
|
+
}
|
|
5490
|
+
|
|
5491
|
+
// ../replicache/src/pending-mutations.ts
|
|
5492
|
+
async function pendingMutationsForAPI(dagRead) {
|
|
5493
|
+
const mainHeadHash = await mustGetHeadHash(DEFAULT_HEAD_NAME, dagRead);
|
|
5494
|
+
const pending = await localMutationsDD31(mainHeadHash, dagRead);
|
|
5495
|
+
return pending.map((p) => ({
|
|
5496
|
+
id: p.meta.mutationID,
|
|
5497
|
+
name: p.meta.mutatorName,
|
|
5498
|
+
args: p.meta.mutatorArgsJSON,
|
|
5499
|
+
clientID: p.meta.clientID
|
|
5500
|
+
})).reverse();
|
|
5501
|
+
}
|
|
5502
|
+
|
|
5503
|
+
// ../replicache/src/bg-interval.ts
|
|
5504
|
+
function initBgIntervalProcess(processName, process2, delayMs, lc, signal) {
|
|
5505
|
+
void runBgIntervalProcess(processName, process2, delayMs, lc, signal);
|
|
5506
|
+
}
|
|
5507
|
+
async function runBgIntervalProcess(processName, process2, delayMs, lc, signal) {
|
|
5508
|
+
if (signal.aborted) {
|
|
5509
|
+
return;
|
|
5510
|
+
}
|
|
5511
|
+
lc = lc.withContext("bgIntervalProcess", processName);
|
|
5512
|
+
lc.debug?.("Starting");
|
|
5513
|
+
while (!signal.aborted) {
|
|
5514
|
+
try {
|
|
5515
|
+
await sleep(delayMs(), signal);
|
|
5516
|
+
} catch (e) {
|
|
5517
|
+
if (!(e instanceof AbortError)) {
|
|
5518
|
+
throw e;
|
|
6391
5519
|
}
|
|
6392
5520
|
}
|
|
6393
|
-
|
|
6394
|
-
|
|
6395
|
-
|
|
6396
|
-
|
|
6397
|
-
|
|
5521
|
+
if (!signal.aborted) {
|
|
5522
|
+
lc.debug?.("Running");
|
|
5523
|
+
try {
|
|
5524
|
+
await process2();
|
|
5525
|
+
} catch (e) {
|
|
5526
|
+
if (signal.aborted) {
|
|
5527
|
+
lc.debug?.("Error running most likely due to close.", e);
|
|
5528
|
+
} else {
|
|
5529
|
+
lc.error?.("Error running.", e);
|
|
5530
|
+
}
|
|
6398
5531
|
}
|
|
6399
|
-
|
|
6400
|
-
const setNewClients = async (newClients2) => {
|
|
6401
|
-
await setClients(newClients2, dagWrite);
|
|
6402
|
-
return newClients2;
|
|
6403
|
-
};
|
|
6404
|
-
if (isClientStateNotFoundResponse(pullResponse) || // Even though SDD did not have VersionNotSupported we can still get
|
|
6405
|
-
// this if the server was upgraded to handle this. It seems better to
|
|
6406
|
-
// delete the client at this point.
|
|
6407
|
-
isVersionNotSupportedResponse(pullResponse)) {
|
|
6408
|
-
const newClients2 = new Map(clients);
|
|
6409
|
-
newClients2.delete(clientID);
|
|
6410
|
-
return setNewClients(newClients2);
|
|
6411
|
-
}
|
|
6412
|
-
assert(pullResponse);
|
|
6413
|
-
if (clientToUpdate.lastServerAckdMutationID >= pullResponse.lastMutationID) {
|
|
6414
|
-
return clients;
|
|
6415
|
-
}
|
|
6416
|
-
const newClients = new Map(clients).set(clientID, {
|
|
6417
|
-
...clientToUpdate,
|
|
6418
|
-
lastServerAckdMutationID: pullResponse.lastMutationID
|
|
6419
|
-
});
|
|
6420
|
-
return setNewClients(newClients);
|
|
6421
|
-
});
|
|
6422
|
-
} catch (e) {
|
|
6423
|
-
logMutationRecoveryError(e, lc, stepDescription, delegate);
|
|
6424
|
-
} finally {
|
|
6425
|
-
await lazyDagForOtherClient.close();
|
|
6426
|
-
lc.debug?.("End:", stepDescription);
|
|
5532
|
+
}
|
|
6427
5533
|
}
|
|
6428
|
-
|
|
5534
|
+
lc.debug?.("Stopping");
|
|
6429
5535
|
}
|
|
6430
|
-
|
|
6431
|
-
|
|
6432
|
-
|
|
6433
|
-
|
|
6434
|
-
|
|
6435
|
-
|
|
6436
|
-
|
|
6437
|
-
|
|
6438
|
-
|
|
6439
|
-
|
|
6440
|
-
|
|
6441
|
-
|
|
6442
|
-
|
|
5536
|
+
|
|
5537
|
+
// ../replicache/src/persist/make-client-id.ts
|
|
5538
|
+
function makeClientID() {
|
|
5539
|
+
const length = 18;
|
|
5540
|
+
const high = randomUint64();
|
|
5541
|
+
const low = randomUint64();
|
|
5542
|
+
const combined = high << 64n | low;
|
|
5543
|
+
return combined.toString(32).slice(-length).padStart(length, "0");
|
|
5544
|
+
}
|
|
5545
|
+
|
|
5546
|
+
// ../replicache/src/persist/clients.ts
|
|
5547
|
+
var clientV4Schema = readonlyObject({
|
|
5548
|
+
/**
|
|
5549
|
+
* A UNIX timestamp in milliseconds updated by the client once a minute
|
|
5550
|
+
* while it is active and every time the client persists its state to
|
|
5551
|
+
* the perdag.
|
|
5552
|
+
* Should only be updated by the client represented by this structure.
|
|
5553
|
+
*/
|
|
5554
|
+
heartbeatTimestampMs: valita_exports.number(),
|
|
5555
|
+
/**
|
|
5556
|
+
* The hash of the commit in the perdag this client last persisted.
|
|
5557
|
+
* Should only be updated by the client represented by this structure.
|
|
5558
|
+
*/
|
|
5559
|
+
headHash: hashSchema,
|
|
5560
|
+
/**
|
|
5561
|
+
* The mutationID of the commit at headHash (mutationID if it is a
|
|
5562
|
+
* local commit, lastMutationID if it is an index change or snapshot commit).
|
|
5563
|
+
* Should only be updated by the client represented by this structure.
|
|
5564
|
+
* Read by other clients to determine if there are unacknowledged pending
|
|
5565
|
+
* mutations for them to push on behalf of the client represented by this
|
|
5566
|
+
* structure.
|
|
5567
|
+
* This is redundant with information in the commit graph at headHash,
|
|
5568
|
+
* but allows other clients to determine if there are unacknowledged pending
|
|
5569
|
+
* mutations without having to load the commit graph at headHash.
|
|
5570
|
+
*/
|
|
5571
|
+
mutationID: valita_exports.number(),
|
|
5572
|
+
/**
|
|
5573
|
+
* The highest lastMutationID received from the server for this client.
|
|
5574
|
+
*
|
|
5575
|
+
* Should be updated by the client represented by this structure whenever
|
|
5576
|
+
* it persists its state to the perdag.
|
|
5577
|
+
* Read by other clients to determine if there are unacknowledged pending
|
|
5578
|
+
* mutations for them to push on behalf of the client represented by this
|
|
5579
|
+
* structure, and *updated* by other clients upon successfully pushing
|
|
5580
|
+
* pending mutations to avoid redundant pushes of those mutations.
|
|
5581
|
+
*
|
|
5582
|
+
* Note: This will be the same as the lastMutationID of the base snapshot of
|
|
5583
|
+
* the commit graph at headHash when written by the client represented by this
|
|
5584
|
+
* structure. However, when written by another client pushing pending
|
|
5585
|
+
* mutations on this client's behalf it will be different. This is because
|
|
5586
|
+
* the other client does not update the commit graph (it is unsafe to update
|
|
5587
|
+
* another client's commit graph).
|
|
5588
|
+
*/
|
|
5589
|
+
lastServerAckdMutationID: valita_exports.number()
|
|
5590
|
+
});
|
|
5591
|
+
var clientV5Schema = readonlyObject({
|
|
5592
|
+
heartbeatTimestampMs: valita_exports.number(),
|
|
5593
|
+
headHash: hashSchema,
|
|
5594
|
+
/**
|
|
5595
|
+
* The hash of a commit we are in the middle of refreshing into this client's
|
|
5596
|
+
* memdag.
|
|
5597
|
+
*/
|
|
5598
|
+
tempRefreshHash: hashSchema.nullable(),
|
|
5599
|
+
/**
|
|
5600
|
+
* ID of this client's perdag client group. This needs to be sent in pull
|
|
5601
|
+
* request (to enable syncing all last mutation ids in the client group).
|
|
5602
|
+
*/
|
|
5603
|
+
clientGroupID: clientGroupIDSchema
|
|
5604
|
+
});
|
|
5605
|
+
var clientV6Schema = readonlyObject({
|
|
5606
|
+
heartbeatTimestampMs: valita_exports.number(),
|
|
5607
|
+
/**
|
|
5608
|
+
* A set of hashes, which contains:
|
|
5609
|
+
* 1. The hash of the last commit this client refreshed from its client group
|
|
5610
|
+
* (this is the commit it bootstrapped from until it completes its first
|
|
5611
|
+
* refresh).
|
|
5612
|
+
* 2. One or more hashes that were added to retain chunks of a commit while it
|
|
5613
|
+
* was being refreshed into this client's memdag. (This can be one or more
|
|
5614
|
+
* because refresh's cleanup step is a separate transaction and can fail).
|
|
5615
|
+
* Upon refresh completing and successfully running its clean up step, this
|
|
5616
|
+
* set will contain a single hash: the hash of the last commit this client
|
|
5617
|
+
* refreshed.
|
|
5618
|
+
*/
|
|
5619
|
+
refreshHashes: readonlyArray(hashSchema),
|
|
5620
|
+
/**
|
|
5621
|
+
* The hash of the last snapshot commit persisted by this client to this
|
|
5622
|
+
* client's client group, or null if has never persisted a snapshot.
|
|
5623
|
+
*/
|
|
5624
|
+
persistHash: hashSchema.nullable(),
|
|
5625
|
+
/**
|
|
5626
|
+
* ID of this client's perdag client group. This needs to be sent in pull
|
|
5627
|
+
* request (to enable syncing all last mutation ids in the client group).
|
|
5628
|
+
*/
|
|
5629
|
+
clientGroupID: clientGroupIDSchema
|
|
5630
|
+
});
|
|
5631
|
+
function isClientV6(client) {
|
|
5632
|
+
return client.refreshHashes !== void 0;
|
|
5633
|
+
}
|
|
5634
|
+
function isClientV5(client) {
|
|
5635
|
+
return client.clientGroupID !== void 0;
|
|
5636
|
+
}
|
|
5637
|
+
var CLIENTS_HEAD_NAME = "clients";
|
|
5638
|
+
var clientSchema = valita_exports.union(
|
|
5639
|
+
clientV4Schema,
|
|
5640
|
+
clientV5Schema,
|
|
5641
|
+
clientV6Schema
|
|
5642
|
+
);
|
|
5643
|
+
function assertClient(value) {
|
|
5644
|
+
assert2(value, clientSchema);
|
|
6443
5645
|
}
|
|
6444
|
-
function
|
|
6445
|
-
|
|
6446
|
-
return recoverMutationsFromPerdagDD31(database, options, perdag);
|
|
6447
|
-
}
|
|
6448
|
-
return recoverMutationsFromPerdagSDD(
|
|
6449
|
-
database,
|
|
6450
|
-
options,
|
|
6451
|
-
perdag,
|
|
6452
|
-
preReadClientMap
|
|
6453
|
-
);
|
|
5646
|
+
function assertClientV6(value) {
|
|
5647
|
+
assert2(value, clientV6Schema);
|
|
6454
5648
|
}
|
|
6455
|
-
|
|
6456
|
-
|
|
6457
|
-
const
|
|
6458
|
-
|
|
6459
|
-
|
|
6460
|
-
|
|
6461
|
-
|
|
6462
|
-
|
|
6463
|
-
|
|
6464
|
-
let newClientMap;
|
|
6465
|
-
for (const [clientID, client] of clientMap) {
|
|
6466
|
-
if (delegate.closed) {
|
|
6467
|
-
lc.debug?.("Exiting early due to close:", stepDescription);
|
|
6468
|
-
return;
|
|
6469
|
-
}
|
|
6470
|
-
if (!clientIDsVisited.has(clientID)) {
|
|
6471
|
-
clientIDsVisited.add(clientID);
|
|
6472
|
-
newClientMap = await recoverMutationsOfClientV4(
|
|
6473
|
-
client,
|
|
6474
|
-
clientID,
|
|
6475
|
-
perdag,
|
|
6476
|
-
database,
|
|
6477
|
-
options,
|
|
6478
|
-
formatVersion
|
|
6479
|
-
);
|
|
6480
|
-
if (newClientMap) {
|
|
6481
|
-
break;
|
|
6482
|
-
}
|
|
6483
|
-
}
|
|
5649
|
+
function chunkDataToClientMap(chunkData) {
|
|
5650
|
+
assertObject(chunkData);
|
|
5651
|
+
const clients = /* @__PURE__ */ new Map();
|
|
5652
|
+
for (const key in chunkData) {
|
|
5653
|
+
if (hasOwn(chunkData, key)) {
|
|
5654
|
+
const value = chunkData[key];
|
|
5655
|
+
if (value !== void 0) {
|
|
5656
|
+
assertClient(value);
|
|
5657
|
+
clients.set(key, value);
|
|
6484
5658
|
}
|
|
6485
|
-
clientMap = newClientMap;
|
|
6486
5659
|
}
|
|
6487
|
-
} catch (e) {
|
|
6488
|
-
logMutationRecoveryError(e, lc, stepDescription, delegate);
|
|
6489
5660
|
}
|
|
6490
|
-
|
|
5661
|
+
return clients;
|
|
6491
5662
|
}
|
|
6492
|
-
|
|
6493
|
-
const
|
|
6494
|
-
|
|
6495
|
-
|
|
6496
|
-
|
|
6497
|
-
|
|
6498
|
-
|
|
6499
|
-
|
|
6500
|
-
(
|
|
6501
|
-
|
|
6502
|
-
|
|
6503
|
-
while (clientGroups) {
|
|
6504
|
-
let newClientGroups;
|
|
6505
|
-
for (const [clientGroupID, clientGroup] of clientGroups) {
|
|
6506
|
-
if (delegate.closed) {
|
|
6507
|
-
lc.debug?.("Exiting early due to close:", stepDescription);
|
|
6508
|
-
return;
|
|
6509
|
-
}
|
|
6510
|
-
if (!clientGroupIDsVisited.has(clientGroupID)) {
|
|
6511
|
-
clientGroupIDsVisited.add(clientGroupID);
|
|
6512
|
-
newClientGroups = await recoverMutationsOfClientGroupDD31(
|
|
6513
|
-
clientGroup,
|
|
6514
|
-
clientGroupID,
|
|
6515
|
-
perdag,
|
|
6516
|
-
database,
|
|
6517
|
-
options,
|
|
6518
|
-
formatVersion
|
|
6519
|
-
);
|
|
6520
|
-
if (newClientGroups) {
|
|
6521
|
-
break;
|
|
6522
|
-
}
|
|
6523
|
-
}
|
|
5663
|
+
function clientMapToChunkData(clients, dagWrite) {
|
|
5664
|
+
for (const client of clients.values()) {
|
|
5665
|
+
if (isClientV6(client)) {
|
|
5666
|
+
client.refreshHashes.forEach(dagWrite.assertValidHash);
|
|
5667
|
+
if (client.persistHash) {
|
|
5668
|
+
dagWrite.assertValidHash(client.persistHash);
|
|
5669
|
+
}
|
|
5670
|
+
} else {
|
|
5671
|
+
dagWrite.assertValidHash(client.headHash);
|
|
5672
|
+
if (isClientV5(client) && client.tempRefreshHash) {
|
|
5673
|
+
dagWrite.assertValidHash(client.tempRefreshHash);
|
|
6524
5674
|
}
|
|
6525
|
-
clientGroups = newClientGroups;
|
|
6526
5675
|
}
|
|
6527
|
-
} catch (e) {
|
|
6528
|
-
logMutationRecoveryError(e, lc, stepDescription, delegate);
|
|
6529
5676
|
}
|
|
6530
|
-
|
|
5677
|
+
return deepFreeze(Object.fromEntries(clients));
|
|
6531
5678
|
}
|
|
6532
|
-
function
|
|
6533
|
-
|
|
5679
|
+
async function getClients(dagRead) {
|
|
5680
|
+
const hash2 = await dagRead.getHead(CLIENTS_HEAD_NAME);
|
|
5681
|
+
return getClientsAtHash(hash2, dagRead);
|
|
6534
5682
|
}
|
|
6535
|
-
async function
|
|
6536
|
-
if (
|
|
6537
|
-
|
|
6538
|
-
`Client group ${selfClientGroupID} cannot recover mutations for client group ${clientGroupID}. The client group is unknown on the server. Marking it as disabled.`
|
|
6539
|
-
);
|
|
6540
|
-
} else if (isVersionNotSupportedResponse(response)) {
|
|
6541
|
-
lc.debug?.(
|
|
6542
|
-
`Client group ${selfClientGroupID} cannot recover mutations for client group ${clientGroupID}. The client group's version is not supported on the server. versionType: ${response.versionType}. Marking it as disabled.`
|
|
6543
|
-
);
|
|
5683
|
+
async function getClientsAtHash(hash2, dagRead) {
|
|
5684
|
+
if (!hash2) {
|
|
5685
|
+
return /* @__PURE__ */ new Map();
|
|
6544
5686
|
}
|
|
6545
|
-
await
|
|
6546
|
-
|
|
6547
|
-
(perdagWrite) => disableClientGroup(clientGroupID, perdagWrite)
|
|
6548
|
-
);
|
|
5687
|
+
const chunk = await dagRead.getChunk(hash2);
|
|
5688
|
+
return chunkDataToClientMap(chunk?.data);
|
|
6549
5689
|
}
|
|
6550
|
-
|
|
6551
|
-
|
|
6552
|
-
|
|
6553
|
-
|
|
6554
|
-
|
|
6555
|
-
|
|
6556
|
-
wrapInReauthRetries,
|
|
6557
|
-
isPushDisabled,
|
|
6558
|
-
isPullDisabled,
|
|
6559
|
-
clientGroupIDPromise
|
|
6560
|
-
} = options;
|
|
6561
|
-
const selfClientGroupID = await clientGroupIDPromise;
|
|
6562
|
-
assertNotUndefined(selfClientGroupID);
|
|
6563
|
-
if (selfClientGroupID === clientGroupID) {
|
|
6564
|
-
return;
|
|
6565
|
-
}
|
|
6566
|
-
let clientID;
|
|
6567
|
-
let allAckd = true;
|
|
6568
|
-
for (const [cid, mutationID] of Object.entries(clientGroup.mutationIDs)) {
|
|
6569
|
-
if (!clientGroup.lastServerAckdMutationIDs[cid] || clientGroup.lastServerAckdMutationIDs[cid] < mutationID) {
|
|
6570
|
-
clientID = cid;
|
|
6571
|
-
allAckd = false;
|
|
6572
|
-
break;
|
|
6573
|
-
}
|
|
5690
|
+
var ClientStateNotFoundError = class extends Error {
|
|
5691
|
+
name = "ClientStateNotFoundError";
|
|
5692
|
+
id;
|
|
5693
|
+
constructor(id) {
|
|
5694
|
+
super(`Client state not found, id: ${id}`);
|
|
5695
|
+
this.id = id;
|
|
6574
5696
|
}
|
|
6575
|
-
|
|
6576
|
-
|
|
5697
|
+
};
|
|
5698
|
+
async function assertHasClientState(id, dagRead) {
|
|
5699
|
+
if (!await hasClientState(id, dagRead)) {
|
|
5700
|
+
throw new ClientStateNotFoundError(id);
|
|
6577
5701
|
}
|
|
6578
|
-
|
|
6579
|
-
|
|
6580
|
-
|
|
6581
|
-
|
|
6582
|
-
|
|
5702
|
+
}
|
|
5703
|
+
async function hasClientState(id, dagRead) {
|
|
5704
|
+
return !!await getClient(id, dagRead);
|
|
5705
|
+
}
|
|
5706
|
+
async function getClient(id, dagRead) {
|
|
5707
|
+
const clients = await getClients(dagRead);
|
|
5708
|
+
return clients.get(id);
|
|
5709
|
+
}
|
|
5710
|
+
async function mustGetClient(id, dagRead) {
|
|
5711
|
+
const client = await getClient(id, dagRead);
|
|
5712
|
+
if (!client) {
|
|
5713
|
+
throw new ClientStateNotFoundError(id);
|
|
6583
5714
|
}
|
|
6584
|
-
|
|
6585
|
-
|
|
6586
|
-
|
|
6587
|
-
|
|
6588
|
-
|
|
6589
|
-
|
|
6590
|
-
|
|
6591
|
-
|
|
6592
|
-
|
|
6593
|
-
|
|
6594
|
-
|
|
6595
|
-
(write) => write.setHead(DEFAULT_HEAD_NAME, clientGroup.headHash)
|
|
6596
|
-
);
|
|
6597
|
-
if (isPushDisabled()) {
|
|
6598
|
-
lc.debug?.(
|
|
6599
|
-
`Cannot recover mutations for client group ${clientGroupID} because push is disabled.`
|
|
5715
|
+
return client;
|
|
5716
|
+
}
|
|
5717
|
+
function initClientV6(newClientID, lc, perdag, mutatorNames, indexes, formatVersion, enableClientGroupForking) {
|
|
5718
|
+
return withWriteNoImplicitCommit(perdag, async (dagWrite) => {
|
|
5719
|
+
async function setClientsAndClientGroupAndCommit(basisHash, cookieJSON, valueHash2, indexRecords2) {
|
|
5720
|
+
const newSnapshotData = newSnapshotCommitDataDD31(
|
|
5721
|
+
basisHash,
|
|
5722
|
+
{},
|
|
5723
|
+
cookieJSON,
|
|
5724
|
+
valueHash2,
|
|
5725
|
+
indexRecords2
|
|
6600
5726
|
);
|
|
6601
|
-
|
|
6602
|
-
|
|
6603
|
-
|
|
6604
|
-
const pushDescription = "recoveringMutationsPush";
|
|
6605
|
-
const pushSucceeded = await wrapInOnlineCheck(async () => {
|
|
6606
|
-
const { result: pusherResult } = await wrapInReauthRetries(
|
|
6607
|
-
async (requestID, requestLc) => {
|
|
6608
|
-
assert(clientID);
|
|
6609
|
-
assert(lazyDagForOtherClientGroup);
|
|
6610
|
-
const pusherResult2 = await push(
|
|
6611
|
-
requestID,
|
|
6612
|
-
lazyDagForOtherClientGroup,
|
|
6613
|
-
requestLc,
|
|
6614
|
-
await delegate.profileID,
|
|
6615
|
-
clientGroupID,
|
|
6616
|
-
// TODO(DD31): clientID is not needed in DD31. It is currently kept for debugging purpose.
|
|
6617
|
-
clientID,
|
|
6618
|
-
pusher,
|
|
6619
|
-
database.schemaVersion,
|
|
6620
|
-
PUSH_VERSION_DD31
|
|
6621
|
-
);
|
|
6622
|
-
return {
|
|
6623
|
-
result: pusherResult2,
|
|
6624
|
-
httpRequestInfo: pusherResult2?.httpRequestInfo
|
|
6625
|
-
};
|
|
6626
|
-
},
|
|
6627
|
-
pushDescription,
|
|
6628
|
-
lc
|
|
5727
|
+
const chunk = dagWrite.createChunk(
|
|
5728
|
+
newSnapshotData,
|
|
5729
|
+
getRefs(newSnapshotData)
|
|
6629
5730
|
);
|
|
6630
|
-
|
|
6631
|
-
|
|
6632
|
-
|
|
6633
|
-
|
|
6634
|
-
|
|
6635
|
-
|
|
6636
|
-
|
|
6637
|
-
|
|
6638
|
-
|
|
6639
|
-
|
|
6640
|
-
|
|
5731
|
+
const newClientGroupID = makeClientID();
|
|
5732
|
+
const newClient = {
|
|
5733
|
+
heartbeatTimestampMs: Date.now(),
|
|
5734
|
+
refreshHashes: [chunk.hash],
|
|
5735
|
+
persistHash: null,
|
|
5736
|
+
clientGroupID: newClientGroupID
|
|
5737
|
+
};
|
|
5738
|
+
const newClients = new Map(clients).set(newClientID, newClient);
|
|
5739
|
+
const clientGroup = {
|
|
5740
|
+
headHash: chunk.hash,
|
|
5741
|
+
mutatorNames,
|
|
5742
|
+
indexes,
|
|
5743
|
+
mutationIDs: {},
|
|
5744
|
+
lastServerAckdMutationIDs: {},
|
|
5745
|
+
disabled: false
|
|
5746
|
+
};
|
|
5747
|
+
await Promise.all([
|
|
5748
|
+
dagWrite.putChunk(chunk),
|
|
5749
|
+
setClients(newClients, dagWrite),
|
|
5750
|
+
setClientGroup(newClientGroupID, clientGroup, dagWrite)
|
|
5751
|
+
]);
|
|
5752
|
+
await dagWrite.commit();
|
|
5753
|
+
return [newClient, chunk.hash, newClients, true];
|
|
5754
|
+
}
|
|
5755
|
+
const clients = await getClients(dagWrite);
|
|
5756
|
+
const res = await findMatchingClient(dagWrite, mutatorNames, indexes);
|
|
5757
|
+
if (res.type === FIND_MATCHING_CLIENT_TYPE_HEAD) {
|
|
5758
|
+
const { clientGroupID, headHash } = res;
|
|
5759
|
+
const newClient = {
|
|
5760
|
+
clientGroupID,
|
|
5761
|
+
refreshHashes: [headHash],
|
|
5762
|
+
heartbeatTimestampMs: Date.now(),
|
|
5763
|
+
persistHash: null
|
|
5764
|
+
};
|
|
5765
|
+
const newClients = new Map(clients).set(newClientID, newClient);
|
|
5766
|
+
await setClients(newClients, dagWrite);
|
|
5767
|
+
await dagWrite.commit();
|
|
5768
|
+
return [newClient, headHash, newClients, false];
|
|
5769
|
+
}
|
|
5770
|
+
if (!enableClientGroupForking || res.type === FIND_MATCHING_CLIENT_TYPE_NEW) {
|
|
5771
|
+
const emptyBTreeChunk = dagWrite.createChunk(emptyDataNode, []);
|
|
5772
|
+
await dagWrite.putChunk(emptyBTreeChunk);
|
|
5773
|
+
const indexRecords2 = [];
|
|
5774
|
+
for (const [name, indexDefinition] of Object.entries(indexes)) {
|
|
5775
|
+
const chunkIndexDefinition = toChunkIndexDefinition(
|
|
5776
|
+
name,
|
|
5777
|
+
indexDefinition
|
|
6641
5778
|
);
|
|
6642
|
-
|
|
5779
|
+
indexRecords2.push({
|
|
5780
|
+
definition: chunkIndexDefinition,
|
|
5781
|
+
valueHash: emptyBTreeChunk.hash
|
|
5782
|
+
});
|
|
6643
5783
|
}
|
|
6644
|
-
return
|
|
6645
|
-
|
|
6646
|
-
|
|
6647
|
-
|
|
6648
|
-
|
|
6649
|
-
);
|
|
6650
|
-
return;
|
|
6651
|
-
}
|
|
6652
|
-
if (isPullDisabled()) {
|
|
6653
|
-
lc.debug?.(
|
|
6654
|
-
`Cannot confirm mutations were recovered for client ${clientGroupID} because pull is disabled.`
|
|
5784
|
+
return setClientsAndClientGroupAndCommit(
|
|
5785
|
+
null,
|
|
5786
|
+
null,
|
|
5787
|
+
emptyBTreeChunk.hash,
|
|
5788
|
+
indexRecords2
|
|
6655
5789
|
);
|
|
6656
|
-
return;
|
|
6657
5790
|
}
|
|
6658
|
-
|
|
6659
|
-
const
|
|
6660
|
-
|
|
6661
|
-
const
|
|
6662
|
-
|
|
6663
|
-
|
|
6664
|
-
|
|
6665
|
-
|
|
6666
|
-
|
|
6667
|
-
|
|
6668
|
-
|
|
6669
|
-
|
|
6670
|
-
|
|
6671
|
-
|
|
6672
|
-
|
|
6673
|
-
|
|
6674
|
-
|
|
6675
|
-
|
|
6676
|
-
|
|
6677
|
-
|
|
6678
|
-
|
|
6679
|
-
httpRequestInfo: beginPullResponse2.httpRequestInfo
|
|
6680
|
-
};
|
|
6681
|
-
},
|
|
6682
|
-
pullDescription,
|
|
6683
|
-
lc
|
|
6684
|
-
);
|
|
6685
|
-
const { pullResponse } = beginPullResponse;
|
|
6686
|
-
if (isResponseThatShouldDisableClientGroup(pullResponse)) {
|
|
6687
|
-
await disableClientGroup2(
|
|
5791
|
+
assert(res.type === FIND_MATCHING_CLIENT_TYPE_FORK);
|
|
5792
|
+
const { snapshot } = res;
|
|
5793
|
+
const indexRecords = [];
|
|
5794
|
+
const { valueHash, indexes: oldIndexes } = snapshot;
|
|
5795
|
+
const map = new BTreeRead(dagWrite, formatVersion, valueHash);
|
|
5796
|
+
for (const [name, indexDefinition] of Object.entries(indexes)) {
|
|
5797
|
+
const { prefix = "", jsonPointer, allowEmpty = false } = indexDefinition;
|
|
5798
|
+
const chunkIndexDefinition = {
|
|
5799
|
+
name,
|
|
5800
|
+
keyPrefix: prefix,
|
|
5801
|
+
jsonPointer,
|
|
5802
|
+
allowEmpty
|
|
5803
|
+
};
|
|
5804
|
+
const oldIndex = findMatchingOldIndex(oldIndexes, chunkIndexDefinition);
|
|
5805
|
+
if (oldIndex) {
|
|
5806
|
+
indexRecords.push({
|
|
5807
|
+
definition: chunkIndexDefinition,
|
|
5808
|
+
valueHash: oldIndex.valueHash
|
|
5809
|
+
});
|
|
5810
|
+
} else {
|
|
5811
|
+
const indexBTree = await createIndexBTree(
|
|
6688
5812
|
lc,
|
|
6689
|
-
|
|
6690
|
-
|
|
6691
|
-
|
|
6692
|
-
|
|
5813
|
+
dagWrite,
|
|
5814
|
+
map,
|
|
5815
|
+
prefix,
|
|
5816
|
+
jsonPointer,
|
|
5817
|
+
allowEmpty,
|
|
5818
|
+
formatVersion
|
|
6693
5819
|
);
|
|
6694
|
-
|
|
6695
|
-
|
|
6696
|
-
|
|
6697
|
-
|
|
5820
|
+
indexRecords.push({
|
|
5821
|
+
definition: chunkIndexDefinition,
|
|
5822
|
+
valueHash: await indexBTree.flush()
|
|
5823
|
+
});
|
|
6698
5824
|
}
|
|
6699
|
-
okPullResponse = pullResponse;
|
|
6700
|
-
return true;
|
|
6701
|
-
}, pullDescription);
|
|
6702
|
-
if (!pullSucceeded) {
|
|
6703
|
-
lc.debug?.(
|
|
6704
|
-
`Failed to recover mutations for client ${clientGroupID} due to a pull error.`
|
|
6705
|
-
);
|
|
6706
|
-
return;
|
|
6707
5825
|
}
|
|
6708
|
-
|
|
6709
|
-
|
|
6710
|
-
|
|
6711
|
-
|
|
6712
|
-
|
|
6713
|
-
|
|
6714
|
-
|
|
6715
|
-
|
|
5826
|
+
return setClientsAndClientGroupAndCommit(
|
|
5827
|
+
snapshot.meta.basisHash,
|
|
5828
|
+
snapshot.meta.cookieJSON,
|
|
5829
|
+
snapshot.valueHash,
|
|
5830
|
+
indexRecords
|
|
5831
|
+
);
|
|
5832
|
+
});
|
|
5833
|
+
}
|
|
5834
|
+
function findMatchingOldIndex(oldIndexes, chunkIndexDefinition) {
|
|
5835
|
+
return oldIndexes.find(
|
|
5836
|
+
(index) => chunkIndexDefinitionEqualIgnoreName(index.definition, chunkIndexDefinition)
|
|
5837
|
+
);
|
|
5838
|
+
}
|
|
5839
|
+
var FIND_MATCHING_CLIENT_TYPE_NEW = 0;
|
|
5840
|
+
var FIND_MATCHING_CLIENT_TYPE_FORK = 1;
|
|
5841
|
+
var FIND_MATCHING_CLIENT_TYPE_HEAD = 2;
|
|
5842
|
+
async function findMatchingClient(dagRead, mutatorNames, indexes) {
|
|
5843
|
+
let newestCookie;
|
|
5844
|
+
let bestSnapshot;
|
|
5845
|
+
const mutatorNamesSet = new Set(mutatorNames);
|
|
5846
|
+
const clientGroups = await getClientGroups(dagRead);
|
|
5847
|
+
for (const [clientGroupID, clientGroup] of clientGroups) {
|
|
5848
|
+
if (!clientGroup.disabled && mutatorNamesEqual(mutatorNamesSet, clientGroup.mutatorNames) && indexDefinitionsEqual(indexes, clientGroup.indexes)) {
|
|
5849
|
+
return {
|
|
5850
|
+
type: FIND_MATCHING_CLIENT_TYPE_HEAD,
|
|
5851
|
+
clientGroupID,
|
|
5852
|
+
headHash: clientGroup.headHash
|
|
5853
|
+
};
|
|
5854
|
+
}
|
|
5855
|
+
const clientGroupSnapshotCommit = await baseSnapshotFromHash(
|
|
5856
|
+
clientGroup.headHash,
|
|
5857
|
+
dagRead
|
|
6716
5858
|
);
|
|
6717
|
-
|
|
6718
|
-
|
|
6719
|
-
|
|
6720
|
-
|
|
6721
|
-
|
|
6722
|
-
|
|
6723
|
-
assert(okPullResponse);
|
|
6724
|
-
const lastServerAckdMutationIDsUpdates = {};
|
|
6725
|
-
let anyMutationIDsUpdated = false;
|
|
6726
|
-
for (const [clientID2, lastMutationIDChange] of Object.entries(
|
|
6727
|
-
okPullResponse.lastMutationIDChanges
|
|
6728
|
-
)) {
|
|
6729
|
-
if ((clientGroupToUpdate.lastServerAckdMutationIDs[clientID2] ?? 0) < lastMutationIDChange) {
|
|
6730
|
-
lastServerAckdMutationIDsUpdates[clientID2] = lastMutationIDChange;
|
|
6731
|
-
anyMutationIDsUpdated = true;
|
|
6732
|
-
}
|
|
6733
|
-
}
|
|
6734
|
-
if (!anyMutationIDsUpdated) {
|
|
6735
|
-
return clientGroups;
|
|
6736
|
-
}
|
|
6737
|
-
const newClientGroups = new Map(clientGroups).set(clientGroupID, {
|
|
6738
|
-
...clientGroupToUpdate,
|
|
6739
|
-
lastServerAckdMutationIDs: {
|
|
6740
|
-
...clientGroupToUpdate.lastServerAckdMutationIDs,
|
|
6741
|
-
...lastServerAckdMutationIDsUpdates
|
|
6742
|
-
}
|
|
6743
|
-
});
|
|
6744
|
-
await setClientGroups(newClientGroups, dagWrite);
|
|
6745
|
-
return newClientGroups;
|
|
6746
|
-
});
|
|
6747
|
-
} catch (e) {
|
|
6748
|
-
logMutationRecoveryError(e, lc, stepDescription, delegate);
|
|
6749
|
-
} finally {
|
|
6750
|
-
await lazyDagForOtherClientGroup.close();
|
|
6751
|
-
lc.debug?.("End:", stepDescription);
|
|
6752
|
-
}
|
|
6753
|
-
return;
|
|
6754
|
-
}
|
|
6755
|
-
|
|
6756
|
-
// ../replicache/src/broadcast-channel.ts
|
|
6757
|
-
var NoopBroadcastChannel = class {
|
|
6758
|
-
name;
|
|
6759
|
-
onmessage = null;
|
|
6760
|
-
onmessageerror = null;
|
|
6761
|
-
constructor(name) {
|
|
6762
|
-
this.name = name;
|
|
6763
|
-
}
|
|
6764
|
-
addEventListener() {
|
|
6765
|
-
}
|
|
6766
|
-
removeEventListener() {
|
|
6767
|
-
}
|
|
6768
|
-
dispatchEvent() {
|
|
6769
|
-
return false;
|
|
6770
|
-
}
|
|
6771
|
-
close() {
|
|
5859
|
+
assertSnapshotCommitDD31(clientGroupSnapshotCommit);
|
|
5860
|
+
const { cookieJSON } = clientGroupSnapshotCommit.meta;
|
|
5861
|
+
if (newestCookie === void 0 || compareCookies(cookieJSON, newestCookie) > 0) {
|
|
5862
|
+
newestCookie = cookieJSON;
|
|
5863
|
+
bestSnapshot = clientGroupSnapshotCommit;
|
|
5864
|
+
}
|
|
6772
5865
|
}
|
|
6773
|
-
|
|
5866
|
+
if (bestSnapshot) {
|
|
5867
|
+
return {
|
|
5868
|
+
type: FIND_MATCHING_CLIENT_TYPE_FORK,
|
|
5869
|
+
snapshot: bestSnapshot
|
|
5870
|
+
};
|
|
6774
5871
|
}
|
|
6775
|
-
};
|
|
6776
|
-
var bc = typeof BroadcastChannel === "undefined" ? NoopBroadcastChannel : BroadcastChannel;
|
|
6777
|
-
|
|
6778
|
-
// ../replicache/src/new-client-channel.ts
|
|
6779
|
-
function makeChannelNameV0(replicacheName) {
|
|
6780
|
-
return `replicache-new-client-group:${replicacheName}`;
|
|
6781
|
-
}
|
|
6782
|
-
function makeChannelNameV1(replicacheName) {
|
|
6783
|
-
return `replicache-new-client-group-v1:${replicacheName}`;
|
|
6784
|
-
}
|
|
6785
|
-
function isNewClientChannelMessageV1(message) {
|
|
6786
|
-
return typeof message === "object" && typeof message.clientGroupID === "string" && typeof message.idbName === "string";
|
|
5872
|
+
return { type: FIND_MATCHING_CLIENT_TYPE_NEW };
|
|
6787
5873
|
}
|
|
6788
|
-
function
|
|
6789
|
-
|
|
6790
|
-
|
|
6791
|
-
|
|
6792
|
-
|
|
6793
|
-
|
|
6794
|
-
|
|
6795
|
-
|
|
6796
|
-
|
|
6797
|
-
|
|
6798
|
-
|
|
6799
|
-
|
|
6800
|
-
|
|
6801
|
-
|
|
6802
|
-
const { clientGroupID: newClientGroupID, idbName: newClientIDBName } = data;
|
|
6803
|
-
if (newClientGroupID !== clientGroupID) {
|
|
6804
|
-
if (newClientIDBName === idbName) {
|
|
6805
|
-
const updateNeeded = await withRead(
|
|
6806
|
-
perdag,
|
|
6807
|
-
async (perdagRead) => await getClientGroup(newClientGroupID, perdagRead) !== void 0
|
|
6808
|
-
);
|
|
6809
|
-
if (updateNeeded) {
|
|
6810
|
-
onUpdateNeeded();
|
|
6811
|
-
}
|
|
6812
|
-
} else {
|
|
6813
|
-
onUpdateNeeded();
|
|
6814
|
-
return;
|
|
6815
|
-
}
|
|
5874
|
+
function getRefsForClients(clients) {
|
|
5875
|
+
const refs = /* @__PURE__ */ new Set();
|
|
5876
|
+
for (const client of clients.values()) {
|
|
5877
|
+
if (isClientV6(client)) {
|
|
5878
|
+
for (const hash2 of client.refreshHashes) {
|
|
5879
|
+
refs.add(hash2);
|
|
5880
|
+
}
|
|
5881
|
+
if (client.persistHash) {
|
|
5882
|
+
refs.add(client.persistHash);
|
|
5883
|
+
}
|
|
5884
|
+
} else {
|
|
5885
|
+
refs.add(client.headHash);
|
|
5886
|
+
if (isClientV5(client) && client.tempRefreshHash) {
|
|
5887
|
+
refs.add(client.tempRefreshHash);
|
|
6816
5888
|
}
|
|
6817
5889
|
}
|
|
6818
|
-
}
|
|
6819
|
-
|
|
6820
|
-
}
|
|
6821
|
-
|
|
6822
|
-
// ../replicache/src/on-persist-channel.ts
|
|
6823
|
-
function makeChannelName(replicacheName) {
|
|
6824
|
-
return `replicache-on-persist:${replicacheName}`;
|
|
6825
|
-
}
|
|
6826
|
-
function assertPersistInfo(value) {
|
|
6827
|
-
assertObject(value);
|
|
6828
|
-
assertString(value.clientGroupID);
|
|
6829
|
-
assertString(value.clientID);
|
|
5890
|
+
}
|
|
5891
|
+
return toRefs(refs);
|
|
6830
5892
|
}
|
|
6831
|
-
function
|
|
6832
|
-
|
|
6833
|
-
|
|
5893
|
+
async function getClientGroupForClient(clientID, read) {
|
|
5894
|
+
const clientGroupID = await getClientGroupIDForClient(clientID, read);
|
|
5895
|
+
if (!clientGroupID) {
|
|
5896
|
+
return void 0;
|
|
6834
5897
|
}
|
|
6835
|
-
|
|
6836
|
-
channel.onmessage = (e) => {
|
|
6837
|
-
const { data } = e;
|
|
6838
|
-
assertPersistInfo(data);
|
|
6839
|
-
handlePersist({
|
|
6840
|
-
clientGroupID: data.clientGroupID,
|
|
6841
|
-
clientID: data.clientID
|
|
6842
|
-
});
|
|
6843
|
-
};
|
|
6844
|
-
signal.addEventListener("abort", () => channel.close(), { once: true });
|
|
6845
|
-
return (persistInfo) => {
|
|
6846
|
-
if (signal.aborted) {
|
|
6847
|
-
return;
|
|
6848
|
-
}
|
|
6849
|
-
channel.postMessage(persistInfo);
|
|
6850
|
-
handlePersist(persistInfo);
|
|
6851
|
-
};
|
|
5898
|
+
return getClientGroup(clientGroupID, read);
|
|
6852
5899
|
}
|
|
6853
|
-
|
|
6854
|
-
|
|
6855
|
-
|
|
6856
|
-
|
|
6857
|
-
|
|
6858
|
-
return
|
|
6859
|
-
id: p.meta.mutationID,
|
|
6860
|
-
name: p.meta.mutatorName,
|
|
6861
|
-
args: p.meta.mutatorArgsJSON,
|
|
6862
|
-
clientID: p.meta.clientID
|
|
6863
|
-
})).reverse();
|
|
5900
|
+
async function getClientGroupIDForClient(clientID, read) {
|
|
5901
|
+
const client = await getClient(clientID, read);
|
|
5902
|
+
if (!client || !isClientV5(client)) {
|
|
5903
|
+
return void 0;
|
|
5904
|
+
}
|
|
5905
|
+
return client.clientGroupID;
|
|
6864
5906
|
}
|
|
6865
|
-
|
|
6866
|
-
|
|
6867
|
-
|
|
6868
|
-
|
|
5907
|
+
async function setClient(clientID, client, dagWrite) {
|
|
5908
|
+
const clients = await getClients(dagWrite);
|
|
5909
|
+
const newClients = new Map(clients).set(clientID, client);
|
|
5910
|
+
return setClients(newClients, dagWrite);
|
|
6869
5911
|
}
|
|
6870
|
-
async function
|
|
6871
|
-
|
|
6872
|
-
|
|
6873
|
-
|
|
6874
|
-
|
|
6875
|
-
|
|
6876
|
-
while (!signal.aborted) {
|
|
6877
|
-
try {
|
|
6878
|
-
await sleep(delayMs(), signal);
|
|
6879
|
-
} catch (e) {
|
|
6880
|
-
if (!(e instanceof AbortError)) {
|
|
6881
|
-
throw e;
|
|
6882
|
-
}
|
|
6883
|
-
}
|
|
6884
|
-
if (!signal.aborted) {
|
|
6885
|
-
lc.debug?.("Running");
|
|
6886
|
-
try {
|
|
6887
|
-
await process2();
|
|
6888
|
-
} catch (e) {
|
|
6889
|
-
if (signal.aborted) {
|
|
6890
|
-
lc.debug?.("Error running most likely due to close.", e);
|
|
6891
|
-
} else {
|
|
6892
|
-
lc.error?.("Error running.", e);
|
|
6893
|
-
}
|
|
6894
|
-
}
|
|
6895
|
-
}
|
|
6896
|
-
}
|
|
6897
|
-
lc.debug?.("Stopping");
|
|
5912
|
+
async function setClients(clients, dagWrite) {
|
|
5913
|
+
const chunkData = clientMapToChunkData(clients, dagWrite);
|
|
5914
|
+
const chunk = dagWrite.createChunk(chunkData, getRefsForClients(clients));
|
|
5915
|
+
await dagWrite.putChunk(chunk);
|
|
5916
|
+
await dagWrite.setHead(CLIENTS_HEAD_NAME, chunk.hash);
|
|
5917
|
+
return chunk.hash;
|
|
6898
5918
|
}
|
|
6899
5919
|
|
|
6900
5920
|
// ../replicache/src/persist/client-gc.ts
|
|
@@ -8396,16 +7416,18 @@ var ReplicacheImpl = class {
|
|
|
8396
7416
|
this.#profileIDPromise = profileIDResolver.promise;
|
|
8397
7417
|
const clientGroupIDResolver = resolver6();
|
|
8398
7418
|
this.#clientGroupIDPromise = clientGroupIDResolver.promise;
|
|
8399
|
-
|
|
8400
|
-
|
|
8401
|
-
|
|
8402
|
-
|
|
8403
|
-
|
|
8404
|
-
|
|
8405
|
-
|
|
8406
|
-
|
|
8407
|
-
|
|
8408
|
-
|
|
7419
|
+
if (false) {
|
|
7420
|
+
this.#mutationRecovery = new MutationRecovery({
|
|
7421
|
+
delegate: this,
|
|
7422
|
+
lc: this.#lc,
|
|
7423
|
+
enableMutationRecovery,
|
|
7424
|
+
wrapInOnlineCheck: this.#wrapInOnlineCheck.bind(this),
|
|
7425
|
+
wrapInReauthRetries: this.#wrapInReauthRetries.bind(this),
|
|
7426
|
+
isPullDisabled: this.#isPullDisabled.bind(this),
|
|
7427
|
+
isPushDisabled: this.#isPushDisabled.bind(this),
|
|
7428
|
+
clientGroupIDPromise: this.#clientGroupIDPromise
|
|
7429
|
+
});
|
|
7430
|
+
}
|
|
8409
7431
|
this.#onPersist = initOnPersistChannel(
|
|
8410
7432
|
this.name,
|
|
8411
7433
|
this.#closeAbortController.signal,
|
|
@@ -8427,7 +7449,7 @@ var ReplicacheImpl = class {
|
|
|
8427
7449
|
await closingInstances.get(this.name);
|
|
8428
7450
|
await this.#idbDatabases.getProfileID().then(profileIDResolver);
|
|
8429
7451
|
await this.#idbDatabases.putDatabase(this.#idbDatabase);
|
|
8430
|
-
const [client, headHash,
|
|
7452
|
+
const [client, headHash, , isNewClientGroup] = await initClientV6(
|
|
8431
7453
|
clientID,
|
|
8432
7454
|
this.#lc,
|
|
8433
7455
|
this.perdag,
|
|
@@ -8492,7 +7514,7 @@ var ReplicacheImpl = class {
|
|
|
8492
7514
|
RECOVER_MUTATIONS_INTERVAL_MS,
|
|
8493
7515
|
signal
|
|
8494
7516
|
);
|
|
8495
|
-
void this.recoverMutations(
|
|
7517
|
+
void this.recoverMutations();
|
|
8496
7518
|
getBrowserGlobal("document")?.addEventListener(
|
|
8497
7519
|
"visibilitychange",
|
|
8498
7520
|
this.#onVisibilityChange
|
|
@@ -9209,19 +8231,20 @@ var ReplicacheImpl = class {
|
|
|
9209
8231
|
}
|
|
9210
8232
|
return ex;
|
|
9211
8233
|
}
|
|
9212
|
-
recoverMutations(
|
|
9213
|
-
const result = this.#mutationRecovery.recoverMutations(
|
|
9214
|
-
preReadClientMap,
|
|
9215
|
-
this.#ready,
|
|
9216
|
-
this.perdag,
|
|
9217
|
-
this.#idbDatabase,
|
|
9218
|
-
this.#idbDatabases,
|
|
9219
|
-
this.#kvStoreProvider.create
|
|
9220
|
-
);
|
|
8234
|
+
recoverMutations() {
|
|
9221
8235
|
if (false) {
|
|
9222
|
-
|
|
8236
|
+
const result = this.#mutationRecovery.recoverMutations(
|
|
8237
|
+
this.#ready,
|
|
8238
|
+
this.perdag,
|
|
8239
|
+
this.#idbDatabase,
|
|
8240
|
+
this.#idbDatabases,
|
|
8241
|
+
this.#kvStoreProvider.create
|
|
8242
|
+
);
|
|
8243
|
+
if (false) {
|
|
8244
|
+
void this.onRecoverMutations(result);
|
|
8245
|
+
}
|
|
8246
|
+
return result;
|
|
9223
8247
|
}
|
|
9224
|
-
return result;
|
|
9225
8248
|
}
|
|
9226
8249
|
/**
|
|
9227
8250
|
* List of pending mutations. The order of this is from oldest to newest.
|
|
@@ -9365,32 +8388,37 @@ var NormalizedTableSchema = class {
|
|
|
9365
8388
|
primaryKey;
|
|
9366
8389
|
columns;
|
|
9367
8390
|
relationships;
|
|
9368
|
-
constructor(tableSchema, tableSchemaCache) {
|
|
8391
|
+
constructor(tableSchema, tableSchemaCache, assertFieldRelation) {
|
|
9369
8392
|
this.tableName = tableSchema.tableName;
|
|
9370
8393
|
const primaryKey = normalizePrimaryKey(tableSchema.primaryKey);
|
|
9371
8394
|
this.primaryKey = primaryKey;
|
|
9372
8395
|
this.columns = normalizeColumns(tableSchema.columns, primaryKey);
|
|
9373
8396
|
tableSchemaCache.set(tableSchema, this);
|
|
9374
8397
|
this.relationships = normalizeRelationships(
|
|
8398
|
+
this.tableName,
|
|
9375
8399
|
tableSchema.relationships,
|
|
9376
|
-
tableSchemaCache
|
|
8400
|
+
tableSchemaCache,
|
|
8401
|
+
assertFieldRelation
|
|
9377
8402
|
);
|
|
9378
8403
|
}
|
|
9379
8404
|
};
|
|
8405
|
+
var noop3 = () => {
|
|
8406
|
+
};
|
|
9380
8407
|
function normalizeTableSchema(tableSchema) {
|
|
9381
8408
|
return normalizeTableSchemaWithCache(
|
|
9382
8409
|
tableSchema,
|
|
9383
8410
|
tableSchema.tableName,
|
|
9384
|
-
/* @__PURE__ */ new Map()
|
|
8411
|
+
/* @__PURE__ */ new Map(),
|
|
8412
|
+
noop3
|
|
9385
8413
|
);
|
|
9386
8414
|
}
|
|
9387
|
-
function normalizeTableSchemaWithCache(tableSchema,
|
|
8415
|
+
function normalizeTableSchemaWithCache(tableSchema, expectedTableName, tableSchemaCache, assertFieldRelation) {
|
|
9388
8416
|
if (tableSchema instanceof NormalizedTableSchema) {
|
|
9389
8417
|
return tableSchema;
|
|
9390
8418
|
}
|
|
9391
8419
|
assert(
|
|
9392
|
-
tableSchema.tableName ===
|
|
9393
|
-
`Table name mismatch: "${tableSchema.tableName}" !== "${
|
|
8420
|
+
tableSchema.tableName === expectedTableName,
|
|
8421
|
+
`Table name mismatch: "${tableSchema.tableName}" !== "${expectedTableName}"`
|
|
9394
8422
|
);
|
|
9395
8423
|
let normalizedTableSchema = tableSchemaCache.get(tableSchema);
|
|
9396
8424
|
if (normalizedTableSchema) {
|
|
@@ -9398,7 +8426,8 @@ function normalizeTableSchemaWithCache(tableSchema, expectedName, tableSchemaCac
|
|
|
9398
8426
|
}
|
|
9399
8427
|
normalizedTableSchema = new NormalizedTableSchema(
|
|
9400
8428
|
tableSchema,
|
|
9401
|
-
tableSchemaCache
|
|
8429
|
+
tableSchemaCache,
|
|
8430
|
+
assertFieldRelation
|
|
9402
8431
|
);
|
|
9403
8432
|
return normalizedTableSchema;
|
|
9404
8433
|
}
|
|
@@ -9443,50 +8472,86 @@ function normalizeColumn(value) {
|
|
|
9443
8472
|
optional: value.optional ?? false
|
|
9444
8473
|
};
|
|
9445
8474
|
}
|
|
9446
|
-
function normalizeRelationships(relationships, tableSchemaCache) {
|
|
8475
|
+
function normalizeRelationships(tableName, relationships, tableSchemaCache, assertFieldRelation) {
|
|
9447
8476
|
const rv = {};
|
|
9448
8477
|
if (relationships) {
|
|
9449
|
-
for (const [
|
|
9450
|
-
|
|
8478
|
+
for (const [relationshipName, relationship] of sortedEntries(
|
|
8479
|
+
relationships
|
|
8480
|
+
)) {
|
|
8481
|
+
rv[relationshipName] = normalizeRelationship(
|
|
8482
|
+
tableName,
|
|
8483
|
+
relationshipName,
|
|
8484
|
+
relationship,
|
|
8485
|
+
tableSchemaCache,
|
|
8486
|
+
assertFieldRelation
|
|
8487
|
+
);
|
|
9451
8488
|
}
|
|
9452
8489
|
}
|
|
9453
8490
|
return rv;
|
|
9454
8491
|
}
|
|
9455
|
-
function normalizeRelationship(relationship, tableSchemaCache) {
|
|
8492
|
+
function normalizeRelationship(tableName, relationshipName, relationship, tableSchemaCache, assertFieldRelation) {
|
|
9456
8493
|
if (isFieldRelationship(relationship)) {
|
|
9457
|
-
return normalizeFieldRelationship(
|
|
8494
|
+
return normalizeFieldRelationship(
|
|
8495
|
+
tableName,
|
|
8496
|
+
relationshipName,
|
|
8497
|
+
relationship,
|
|
8498
|
+
tableSchemaCache,
|
|
8499
|
+
assertFieldRelation
|
|
8500
|
+
);
|
|
9458
8501
|
}
|
|
9459
|
-
return normalizeJunctionRelationship(
|
|
8502
|
+
return normalizeJunctionRelationship(
|
|
8503
|
+
tableName,
|
|
8504
|
+
relationshipName,
|
|
8505
|
+
relationship,
|
|
8506
|
+
tableSchemaCache,
|
|
8507
|
+
assertFieldRelation
|
|
8508
|
+
);
|
|
9460
8509
|
}
|
|
9461
|
-
function normalizeFieldRelationship(relationship, tableSchemaCache) {
|
|
8510
|
+
function normalizeFieldRelationship(tableName, relationshipName, relationship, tableSchemaCache, assertFieldRelation) {
|
|
9462
8511
|
const sourceField = normalizeFieldName(relationship.sourceField);
|
|
9463
8512
|
const destField = normalizeFieldName(relationship.destField);
|
|
9464
8513
|
assert(
|
|
9465
8514
|
sourceField.length === destField.length,
|
|
9466
8515
|
"Source and destination fields must have the same length"
|
|
9467
8516
|
);
|
|
9468
|
-
|
|
8517
|
+
const destSchema = normalizeLazyTableSchema(
|
|
8518
|
+
relationship.destSchema,
|
|
8519
|
+
tableSchemaCache,
|
|
8520
|
+
assertFieldRelation
|
|
8521
|
+
);
|
|
8522
|
+
const normalized = {
|
|
9469
8523
|
sourceField,
|
|
9470
8524
|
destField,
|
|
9471
|
-
destSchema
|
|
9472
|
-
relationship.destSchema,
|
|
9473
|
-
tableSchemaCache
|
|
9474
|
-
)
|
|
8525
|
+
destSchema
|
|
9475
8526
|
};
|
|
8527
|
+
assertFieldRelation(tableName, relationshipName, normalized);
|
|
8528
|
+
return normalized;
|
|
9476
8529
|
}
|
|
9477
|
-
function normalizeJunctionRelationship(relationship, tableSchemaCache) {
|
|
9478
|
-
|
|
9479
|
-
|
|
9480
|
-
|
|
9481
|
-
|
|
8530
|
+
function normalizeJunctionRelationship(tableName, relationshipName, relationship, tableSchemaCache, assertFieldRelation) {
|
|
8531
|
+
const first2 = normalizeFieldRelationship(
|
|
8532
|
+
tableName,
|
|
8533
|
+
relationshipName,
|
|
8534
|
+
relationship[0],
|
|
8535
|
+
tableSchemaCache,
|
|
8536
|
+
assertFieldRelation
|
|
8537
|
+
);
|
|
8538
|
+
const second = normalizeFieldRelationship(
|
|
8539
|
+
first2.destSchema.tableName,
|
|
8540
|
+
relationshipName,
|
|
8541
|
+
relationship[1],
|
|
8542
|
+
tableSchemaCache,
|
|
8543
|
+
assertFieldRelation
|
|
8544
|
+
);
|
|
8545
|
+
return [first2, second];
|
|
9482
8546
|
}
|
|
9483
|
-
function normalizeLazyTableSchema(tableSchema, buildCache) {
|
|
8547
|
+
function normalizeLazyTableSchema(tableSchema, buildCache, assertFieldRelation) {
|
|
9484
8548
|
const tableSchemaInstance = typeof tableSchema === "function" ? tableSchema() : tableSchema;
|
|
9485
8549
|
return normalizeTableSchemaWithCache(
|
|
9486
8550
|
tableSchemaInstance,
|
|
9487
8551
|
tableSchemaInstance.tableName,
|
|
9488
8552
|
// Don't care about name here.
|
|
9489
|
-
buildCache
|
|
8553
|
+
buildCache,
|
|
8554
|
+
assertFieldRelation
|
|
9490
8555
|
);
|
|
9491
8556
|
}
|
|
9492
8557
|
function normalizeFieldName(sourceField) {
|
|
@@ -9498,18 +8563,29 @@ function normalizeFieldName(sourceField) {
|
|
|
9498
8563
|
}
|
|
9499
8564
|
function normalizeTables(tables) {
|
|
9500
8565
|
const result = {};
|
|
8566
|
+
const assertFieldRelation = (tableName) => tableName in tables;
|
|
9501
8567
|
for (const [name, table] of sortedEntries(tables)) {
|
|
9502
|
-
result[name] = normalizeTableSchemaWithCache(
|
|
8568
|
+
result[name] = normalizeTableSchemaWithCache(
|
|
8569
|
+
table,
|
|
8570
|
+
name,
|
|
8571
|
+
/* @__PURE__ */ new Map(),
|
|
8572
|
+
assertFieldRelation
|
|
8573
|
+
);
|
|
9503
8574
|
}
|
|
9504
8575
|
return result;
|
|
9505
8576
|
}
|
|
9506
8577
|
|
|
9507
8578
|
// ../zero-schema/src/normalized-schema.ts
|
|
8579
|
+
var normalizedCache = /* @__PURE__ */ new WeakMap();
|
|
9508
8580
|
function normalizeSchema(schema) {
|
|
9509
8581
|
if (schema instanceof NormalizedSchema) {
|
|
9510
8582
|
return schema;
|
|
9511
8583
|
}
|
|
9512
|
-
|
|
8584
|
+
let s;
|
|
8585
|
+
if (!(s = normalizedCache.get(schema))) {
|
|
8586
|
+
normalizedCache.set(schema, s = new NormalizedSchema(schema));
|
|
8587
|
+
}
|
|
8588
|
+
return s;
|
|
9513
8589
|
}
|
|
9514
8590
|
var NormalizedSchema = class {
|
|
9515
8591
|
version;
|
|
@@ -9522,8 +8598,30 @@ var NormalizedSchema = class {
|
|
|
9522
8598
|
function normalizeTables2(tables) {
|
|
9523
8599
|
const rv = {};
|
|
9524
8600
|
const tableSchemaCache = /* @__PURE__ */ new Map();
|
|
8601
|
+
function assertFieldRelation(tableName, relationShipName, relation) {
|
|
8602
|
+
const destTableName = relation.destSchema.tableName;
|
|
8603
|
+
assert(
|
|
8604
|
+
destTableName in tables,
|
|
8605
|
+
`Relationship "${tableName}"."${relationShipName}" destination "${destTableName}" is missing in schema`
|
|
8606
|
+
);
|
|
8607
|
+
assertColumns(relation.sourceField, tables[tableName]);
|
|
8608
|
+
assertColumns(relation.destField, tables[destTableName]);
|
|
8609
|
+
}
|
|
8610
|
+
function assertColumns(columnNames, table) {
|
|
8611
|
+
for (const columnName of columnNames) {
|
|
8612
|
+
assert(
|
|
8613
|
+
columnName in table.columns,
|
|
8614
|
+
`Column "${columnName}" is missing in table "${table.tableName}"`
|
|
8615
|
+
);
|
|
8616
|
+
}
|
|
8617
|
+
}
|
|
9525
8618
|
for (const [name, table] of sortedEntries(tables)) {
|
|
9526
|
-
rv[name] = normalizeTableSchemaWithCache(
|
|
8619
|
+
rv[name] = normalizeTableSchemaWithCache(
|
|
8620
|
+
table,
|
|
8621
|
+
name,
|
|
8622
|
+
tableSchemaCache,
|
|
8623
|
+
assertFieldRelation
|
|
8624
|
+
);
|
|
9527
8625
|
}
|
|
9528
8626
|
return rv;
|
|
9529
8627
|
}
|
|
@@ -12432,12 +11530,7 @@ var preMutationRowRef = baseTracker("preMutationRow");
|
|
|
12432
11530
|
|
|
12433
11531
|
// ../zero-schema/src/schema.ts
|
|
12434
11532
|
function createSchema(schema) {
|
|
12435
|
-
|
|
12436
|
-
assert(
|
|
12437
|
-
tableName === table.tableName,
|
|
12438
|
-
`createSchema tableName mismatch, expected ${tableName} === ${table.tableName}`
|
|
12439
|
-
);
|
|
12440
|
-
}
|
|
11533
|
+
normalizeSchema(schema);
|
|
12441
11534
|
return schema;
|
|
12442
11535
|
}
|
|
12443
11536
|
|
|
@@ -12450,6 +11543,23 @@ function escapeLike(val) {
|
|
|
12450
11543
|
import { LogContext as LogContext4 } from "@rocicorp/logger";
|
|
12451
11544
|
import { resolver as resolver8 } from "@rocicorp/resolver";
|
|
12452
11545
|
|
|
11546
|
+
// ../zero-protocol/src/error-kind-enum.ts
|
|
11547
|
+
var AuthInvalidated = "AuthInvalidated";
|
|
11548
|
+
var ClientNotFound = "ClientNotFound";
|
|
11549
|
+
var InvalidConnectionRequest = "InvalidConnectionRequest";
|
|
11550
|
+
var InvalidConnectionRequestBaseCookie = "InvalidConnectionRequestBaseCookie";
|
|
11551
|
+
var InvalidConnectionRequestLastMutationID = "InvalidConnectionRequestLastMutationID";
|
|
11552
|
+
var InvalidConnectionRequestClientDeleted = "InvalidConnectionRequestClientDeleted";
|
|
11553
|
+
var InvalidMessage = "InvalidMessage";
|
|
11554
|
+
var InvalidPush = "InvalidPush";
|
|
11555
|
+
var MutationFailed = "MutationFailed";
|
|
11556
|
+
var MutationRateLimited = "MutationRateLimited";
|
|
11557
|
+
var Unauthorized = "Unauthorized";
|
|
11558
|
+
var VersionNotSupported = "VersionNotSupported";
|
|
11559
|
+
var SchemaVersionNotSupported = "SchemaVersionNotSupported";
|
|
11560
|
+
var ServerOverloaded = "ServerOverloaded";
|
|
11561
|
+
var Internal = "Internal";
|
|
11562
|
+
|
|
12453
11563
|
// ../zero-protocol/src/queries-patch.ts
|
|
12454
11564
|
var putOpSchema = valita_exports.object({
|
|
12455
11565
|
op: valita_exports.literal("put"),
|
|
@@ -12516,27 +11626,27 @@ function encodeSecProtocols(initConnectionMessage, authToken) {
|
|
|
12516
11626
|
|
|
12517
11627
|
// ../zero-protocol/src/error.ts
|
|
12518
11628
|
var errorKindSchema = valita_exports.union(
|
|
12519
|
-
valita_exports.literal(
|
|
12520
|
-
valita_exports.literal(
|
|
12521
|
-
valita_exports.literal(
|
|
12522
|
-
valita_exports.literal(
|
|
12523
|
-
valita_exports.literal(
|
|
12524
|
-
valita_exports.literal(
|
|
12525
|
-
valita_exports.literal(
|
|
12526
|
-
valita_exports.literal(
|
|
12527
|
-
valita_exports.literal(
|
|
12528
|
-
valita_exports.literal(
|
|
12529
|
-
valita_exports.literal(
|
|
12530
|
-
valita_exports.literal(
|
|
12531
|
-
valita_exports.literal(
|
|
12532
|
-
valita_exports.literal(
|
|
11629
|
+
valita_exports.literal(AuthInvalidated),
|
|
11630
|
+
valita_exports.literal(ClientNotFound),
|
|
11631
|
+
valita_exports.literal(InvalidConnectionRequest),
|
|
11632
|
+
valita_exports.literal(InvalidConnectionRequestBaseCookie),
|
|
11633
|
+
valita_exports.literal(InvalidConnectionRequestLastMutationID),
|
|
11634
|
+
valita_exports.literal(InvalidConnectionRequestClientDeleted),
|
|
11635
|
+
valita_exports.literal(InvalidMessage),
|
|
11636
|
+
valita_exports.literal(InvalidPush),
|
|
11637
|
+
valita_exports.literal(MutationRateLimited),
|
|
11638
|
+
valita_exports.literal(MutationFailed),
|
|
11639
|
+
valita_exports.literal(Unauthorized),
|
|
11640
|
+
valita_exports.literal(VersionNotSupported),
|
|
11641
|
+
valita_exports.literal(SchemaVersionNotSupported),
|
|
11642
|
+
valita_exports.literal(Internal)
|
|
12533
11643
|
);
|
|
12534
11644
|
var basicErrorBodySchema = valita_exports.object({
|
|
12535
11645
|
kind: errorKindSchema,
|
|
12536
11646
|
message: valita_exports.string()
|
|
12537
11647
|
});
|
|
12538
11648
|
var serverOverloadedBodySchema = valita_exports.object({
|
|
12539
|
-
kind: valita_exports.literal(
|
|
11649
|
+
kind: valita_exports.literal(ServerOverloaded),
|
|
12540
11650
|
message: valita_exports.string(),
|
|
12541
11651
|
minBackoffMs: valita_exports.number().optional()
|
|
12542
11652
|
});
|
|
@@ -12696,6 +11806,10 @@ var downstreamSchema = valita_exports.union(
|
|
|
12696
11806
|
var pingBodySchema = valita_exports.object({});
|
|
12697
11807
|
var pingMessageSchema = valita_exports.tuple([valita_exports.literal("ping"), pingBodySchema]);
|
|
12698
11808
|
|
|
11809
|
+
// ../zero-protocol/src/mutation-type-enum.ts
|
|
11810
|
+
var CRUD = "crud";
|
|
11811
|
+
var Custom = "custom";
|
|
11812
|
+
|
|
12699
11813
|
// ../zero-protocol/src/push.ts
|
|
12700
11814
|
var CRUD_MUTATION_NAME = "_zero_crud";
|
|
12701
11815
|
var insertOpSchema = valita_exports.object({
|
|
@@ -12735,7 +11849,7 @@ var crudArgSchema = valita_exports.object({
|
|
|
12735
11849
|
});
|
|
12736
11850
|
var crudArgsSchema = valita_exports.tuple([crudArgSchema]);
|
|
12737
11851
|
var crudMutationSchema = valita_exports.object({
|
|
12738
|
-
type: valita_exports.literal(
|
|
11852
|
+
type: valita_exports.literal(CRUD),
|
|
12739
11853
|
id: valita_exports.number(),
|
|
12740
11854
|
clientID: valita_exports.string(),
|
|
12741
11855
|
name: valita_exports.literal(CRUD_MUTATION_NAME),
|
|
@@ -12743,7 +11857,7 @@ var crudMutationSchema = valita_exports.object({
|
|
|
12743
11857
|
timestamp: valita_exports.number()
|
|
12744
11858
|
});
|
|
12745
11859
|
var customMutationSchema = valita_exports.object({
|
|
12746
|
-
type: valita_exports.literal(
|
|
11860
|
+
type: valita_exports.literal(Custom),
|
|
12747
11861
|
id: valita_exports.number(),
|
|
12748
11862
|
clientID: valita_exports.string(),
|
|
12749
11863
|
name: valita_exports.string(),
|
|
@@ -12808,6 +11922,11 @@ function send(ws, data) {
|
|
|
12808
11922
|
ws.send(JSON.stringify(data));
|
|
12809
11923
|
}
|
|
12810
11924
|
|
|
11925
|
+
// ../zero-client/src/client/connection-state-enum.ts
|
|
11926
|
+
var Disconnected = 0;
|
|
11927
|
+
var Connecting = 1;
|
|
11928
|
+
var Connected = 2;
|
|
11929
|
+
|
|
12811
11930
|
// ../btree/b+tree.ts
|
|
12812
11931
|
function defaultComparator(a, b) {
|
|
12813
11932
|
if (Number.isFinite(a) && Number.isFinite(b)) {
|
|
@@ -15478,7 +14597,7 @@ function makeMessage(message, context, logLevel) {
|
|
|
15478
14597
|
}
|
|
15479
14598
|
|
|
15480
14599
|
// ../zero-client/src/client/version.ts
|
|
15481
|
-
var version2 = "0.10.
|
|
14600
|
+
var version2 = "0.10.2025011400+efc861";
|
|
15482
14601
|
|
|
15483
14602
|
// ../zero-client/src/client/log-options.ts
|
|
15484
14603
|
var LevelFilterLogSink = class {
|
|
@@ -15534,6 +14653,14 @@ function createLogOptions(options, createDatadogLogSink = (options2) => new Data
|
|
|
15534
14653
|
};
|
|
15535
14654
|
}
|
|
15536
14655
|
|
|
14656
|
+
// ../zero-client/src/client/metric-name-enum.ts
|
|
14657
|
+
var TimeToConnectMs = "time_to_connect_ms";
|
|
14658
|
+
var LastConnectError = "last_connect_error";
|
|
14659
|
+
var TimeToConnectMsV2 = "time_to_connect_ms_v2";
|
|
14660
|
+
var LastConnectErrorV2 = "last_connect_error_v2";
|
|
14661
|
+
var TotalTimeToConnectMs = "total_time_to_connect_ms";
|
|
14662
|
+
var NotConnected = "not_connected";
|
|
14663
|
+
|
|
15537
14664
|
// ../zero-client/src/client/metrics.ts
|
|
15538
14665
|
var DID_NOT_CONNECT_VALUE = 100 * 1e3;
|
|
15539
14666
|
var REPORT_INTERVAL_MS = 5e3;
|
|
@@ -15585,7 +14712,7 @@ var MetricManager = class {
|
|
|
15585
14712
|
// be encapsulated with the ConnectionState. This will probably happen as part
|
|
15586
14713
|
// of https://github.com/rocicorp/reflect-server/issues/255.
|
|
15587
14714
|
timeToConnectMs = this.#register(
|
|
15588
|
-
new Gauge(
|
|
14715
|
+
new Gauge(TimeToConnectMs)
|
|
15589
14716
|
);
|
|
15590
14717
|
// lastConnectError records the last error that occurred when connecting,
|
|
15591
14718
|
// if any. It is cleared when connecting successfully or when reported, so this
|
|
@@ -15593,28 +14720,28 @@ var MetricManager = class {
|
|
|
15593
14720
|
// we are still not connected.
|
|
15594
14721
|
lastConnectError = this.#register(
|
|
15595
14722
|
new State(
|
|
15596
|
-
|
|
14723
|
+
LastConnectError,
|
|
15597
14724
|
true
|
|
15598
14725
|
// clearOnFlush
|
|
15599
14726
|
)
|
|
15600
14727
|
);
|
|
15601
14728
|
// notConnected records the reason why the client is not currently connected.
|
|
15602
14729
|
// It is cleared when the client successfully connects.
|
|
15603
|
-
#notConnected = this.#register(new State(
|
|
14730
|
+
#notConnected = this.#register(new State(NotConnected));
|
|
15604
14731
|
// The time from the call to connect() to receiving the 'connected' ws message
|
|
15605
14732
|
// for the current connection. Cleared when the client is not connected.
|
|
15606
14733
|
// TODO: Not actually currently cleared on disconnect untill there is a
|
|
15607
14734
|
// connect error, or client reports disconnected and waiting for visible.
|
|
15608
14735
|
// Should have a value iff _notConnected has no value.
|
|
15609
14736
|
#timeToConnectMsV2 = this.#register(
|
|
15610
|
-
new Gauge(
|
|
14737
|
+
new Gauge(TimeToConnectMsV2)
|
|
15611
14738
|
);
|
|
15612
14739
|
// lastConnectErrorV2 records the last error that occurred when connecting,
|
|
15613
14740
|
// if any. It is cleared when the client successfully connects or
|
|
15614
14741
|
// stops trying to connect due to being hidden.
|
|
15615
14742
|
// Should have a value iff notConnected state is NotConnectedReason.Error.
|
|
15616
14743
|
#lastConnectErrorV2 = this.#register(
|
|
15617
|
-
new State(
|
|
14744
|
+
new State(LastConnectErrorV2)
|
|
15618
14745
|
);
|
|
15619
14746
|
// The total time it took to connect across retries for the current
|
|
15620
14747
|
// connection. Cleared when the client is not connected.
|
|
@@ -15623,7 +14750,7 @@ var MetricManager = class {
|
|
|
15623
14750
|
// See Zero.#totalToConnectStart for details of how this total is computed.
|
|
15624
14751
|
// Should have a value iff _notConnected has no value.
|
|
15625
14752
|
#totalTimeToConnectMs = this.#register(
|
|
15626
|
-
new Gauge(
|
|
14753
|
+
new Gauge(TotalTimeToConnectMs)
|
|
15627
14754
|
);
|
|
15628
14755
|
#setNotConnectedReason(reason) {
|
|
15629
14756
|
this.#notConnected.set(reason);
|
|
@@ -15764,6 +14891,10 @@ var State = class {
|
|
|
15764
14891
|
}
|
|
15765
14892
|
};
|
|
15766
14893
|
|
|
14894
|
+
// ../zero-client/src/client/ping-result-enum.ts
|
|
14895
|
+
var TimedOut = 0;
|
|
14896
|
+
var Success = 1;
|
|
14897
|
+
|
|
15767
14898
|
// ../zero-client/src/client/query-manager.ts
|
|
15768
14899
|
var QueryManager = class {
|
|
15769
14900
|
#clientID;
|
|
@@ -16018,10 +15149,10 @@ function isAuthError(ex) {
|
|
|
16018
15149
|
return isServerError(ex) && isAuthErrorKind(ex.kind);
|
|
16019
15150
|
}
|
|
16020
15151
|
function isAuthErrorKind(kind) {
|
|
16021
|
-
return kind ===
|
|
15152
|
+
return kind === AuthInvalidated || kind === Unauthorized;
|
|
16022
15153
|
}
|
|
16023
15154
|
function isServerOverloadedError(ex) {
|
|
16024
|
-
return isServerError(ex) && ex.errorBody.kind ===
|
|
15155
|
+
return isServerError(ex) && ex.errorBody.kind === ServerOverloaded ? ex.errorBody : void 0;
|
|
16025
15156
|
}
|
|
16026
15157
|
|
|
16027
15158
|
// ../zero-client/src/client/server-option.ts
|
|
@@ -16457,7 +15588,7 @@ var Zero = class {
|
|
|
16457
15588
|
#closeAbortController = new AbortController();
|
|
16458
15589
|
#visibilityWatcher;
|
|
16459
15590
|
// We use an accessor pair to allow the subclass to override the setter.
|
|
16460
|
-
#connectionState =
|
|
15591
|
+
#connectionState = Disconnected;
|
|
16461
15592
|
#setConnectionState(state) {
|
|
16462
15593
|
if (state === this.#connectionState) {
|
|
16463
15594
|
return;
|
|
@@ -16643,7 +15774,7 @@ var Zero = class {
|
|
|
16643
15774
|
}
|
|
16644
15775
|
}
|
|
16645
15776
|
#sendChangeDesiredQueries(msg) {
|
|
16646
|
-
if (this.#socket && this.#connectionState ===
|
|
15777
|
+
if (this.#socket && this.#connectionState === Connected) {
|
|
16647
15778
|
send(this.#socket, msg);
|
|
16648
15779
|
}
|
|
16649
15780
|
}
|
|
@@ -16740,7 +15871,7 @@ var Zero = class {
|
|
|
16740
15871
|
*/
|
|
16741
15872
|
close() {
|
|
16742
15873
|
const lc = this.#lc.withContext("close");
|
|
16743
|
-
if (this.#connectionState !==
|
|
15874
|
+
if (this.#connectionState !== Disconnected) {
|
|
16744
15875
|
this.#disconnect(lc, {
|
|
16745
15876
|
client: "ClientClosed"
|
|
16746
15877
|
});
|
|
@@ -16821,7 +15952,7 @@ var Zero = class {
|
|
|
16821
15952
|
// An error on the connection is fatal for the connection.
|
|
16822
15953
|
async #handleErrorMessage(lc, downMessage) {
|
|
16823
15954
|
const [, { kind, message }] = downMessage;
|
|
16824
|
-
if (kind ===
|
|
15955
|
+
if (kind === MutationRateLimited) {
|
|
16825
15956
|
this.#lastMutationIDSent = NULL_LAST_MUTATION_ID_SENT;
|
|
16826
15957
|
lc.error?.("Mutation rate limited", { message });
|
|
16827
15958
|
return;
|
|
@@ -16832,15 +15963,15 @@ var Zero = class {
|
|
|
16832
15963
|
lc.debug?.("Rejecting connect resolver due to error", error);
|
|
16833
15964
|
this.#connectResolver.reject(error);
|
|
16834
15965
|
this.#disconnect(lc, { server: kind });
|
|
16835
|
-
if (kind ===
|
|
15966
|
+
if (kind === VersionNotSupported) {
|
|
16836
15967
|
this.#onUpdateNeeded?.({ type: kind }, message);
|
|
16837
|
-
} else if (kind ===
|
|
15968
|
+
} else if (kind === SchemaVersionNotSupported) {
|
|
16838
15969
|
await this.#rep.disableClientGroup();
|
|
16839
15970
|
this.#onUpdateNeeded?.({ type: "SchemaVersionNotSupported" }, message);
|
|
16840
|
-
} else if (kind ===
|
|
15971
|
+
} else if (kind === ClientNotFound) {
|
|
16841
15972
|
await this.#rep.disableClientGroup();
|
|
16842
15973
|
this.#onClientStateNotFound?.(onClientStateNotFoundServerReason(message));
|
|
16843
|
-
} else if (kind ===
|
|
15974
|
+
} else if (kind === InvalidConnectionRequestLastMutationID || kind === InvalidConnectionRequestBaseCookie) {
|
|
16844
15975
|
await dropDatabase(this.#rep.idbName);
|
|
16845
15976
|
reloadWithReason(lc, this.#reload, serverAheadReloadReason(kind));
|
|
16846
15977
|
}
|
|
@@ -16911,7 +16042,7 @@ var Zero = class {
|
|
|
16911
16042
|
]);
|
|
16912
16043
|
}
|
|
16913
16044
|
this.#initConnectionQueries = void 0;
|
|
16914
|
-
this.#setConnectionState(
|
|
16045
|
+
this.#setConnectionState(Connected);
|
|
16915
16046
|
this.#connectResolver.resolve();
|
|
16916
16047
|
}
|
|
16917
16048
|
/**
|
|
@@ -16932,11 +16063,11 @@ var Zero = class {
|
|
|
16932
16063
|
*/
|
|
16933
16064
|
async #connect(l) {
|
|
16934
16065
|
assert(this.#server);
|
|
16935
|
-
assert(this.#connectionState ===
|
|
16066
|
+
assert(this.#connectionState === Disconnected);
|
|
16936
16067
|
const wsid = nanoid();
|
|
16937
16068
|
l = addWebSocketIDToLogContext(wsid, l);
|
|
16938
16069
|
l.info?.("Connecting...", { navigatorOnline: localNavigator?.onLine });
|
|
16939
|
-
this.#setConnectionState(
|
|
16070
|
+
this.#setConnectionState(Connecting);
|
|
16940
16071
|
assert(this.#connectStart === void 0);
|
|
16941
16072
|
const now = Date.now();
|
|
16942
16073
|
this.#connectStart = now;
|
|
@@ -17001,7 +16132,7 @@ var Zero = class {
|
|
|
17001
16132
|
}
|
|
17002
16133
|
}
|
|
17003
16134
|
#disconnect(l, reason) {
|
|
17004
|
-
if (this.#connectionState ===
|
|
16135
|
+
if (this.#connectionState === Connecting) {
|
|
17005
16136
|
this.#connectErrorCount++;
|
|
17006
16137
|
}
|
|
17007
16138
|
l.info?.("disconnecting", {
|
|
@@ -17016,7 +16147,7 @@ var Zero = class {
|
|
|
17016
16147
|
connectErrorCount: this.#connectErrorCount
|
|
17017
16148
|
});
|
|
17018
16149
|
switch (this.#connectionState) {
|
|
17019
|
-
case
|
|
16150
|
+
case Connected: {
|
|
17020
16151
|
if (this.#connectStart !== void 0) {
|
|
17021
16152
|
l.error?.(
|
|
17022
16153
|
"disconnect() called while connected but connect start time is defined. This should not happen."
|
|
@@ -17024,7 +16155,7 @@ var Zero = class {
|
|
|
17024
16155
|
}
|
|
17025
16156
|
break;
|
|
17026
16157
|
}
|
|
17027
|
-
case
|
|
16158
|
+
case Connecting: {
|
|
17028
16159
|
this.#metrics.lastConnectError.set(getLastConnectErrorValue(reason));
|
|
17029
16160
|
this.#metrics.timeToConnectMs.set(DID_NOT_CONNECT_VALUE);
|
|
17030
16161
|
this.#metrics.setConnectError(reason);
|
|
@@ -17040,14 +16171,14 @@ var Zero = class {
|
|
|
17040
16171
|
}
|
|
17041
16172
|
break;
|
|
17042
16173
|
}
|
|
17043
|
-
case
|
|
16174
|
+
case Disconnected:
|
|
17044
16175
|
l.error?.("disconnect() called while disconnected");
|
|
17045
16176
|
break;
|
|
17046
16177
|
}
|
|
17047
16178
|
this.#socketResolver = resolver8();
|
|
17048
16179
|
l.debug?.("Creating new connect resolver");
|
|
17049
16180
|
this.#connectResolver = resolver8();
|
|
17050
|
-
this.#setConnectionState(
|
|
16181
|
+
this.#setConnectionState(Disconnected);
|
|
17051
16182
|
this.#messageCount = 0;
|
|
17052
16183
|
this.#connectStart = void 0;
|
|
17053
16184
|
this.#connectedAt = 0;
|
|
@@ -17081,9 +16212,9 @@ var Zero = class {
|
|
|
17081
16212
|
const lc = this.#lc;
|
|
17082
16213
|
lc.info?.(
|
|
17083
16214
|
"poke error, disconnecting?",
|
|
17084
|
-
this.#connectionState !==
|
|
16215
|
+
this.#connectionState !== Disconnected
|
|
17085
16216
|
);
|
|
17086
|
-
if (this.#connectionState !==
|
|
16217
|
+
if (this.#connectionState !== Disconnected) {
|
|
17087
16218
|
this.#disconnect(lc, {
|
|
17088
16219
|
client: "UnexpectedBaseCookie"
|
|
17089
16220
|
});
|
|
@@ -17124,14 +16255,14 @@ var Zero = class {
|
|
|
17124
16255
|
const m = req.mutations[i];
|
|
17125
16256
|
const timestamp = now - Math.round(performance.now() - m.timestamp);
|
|
17126
16257
|
const zeroM = m.name === CRUD_MUTATION_NAME ? {
|
|
17127
|
-
type:
|
|
16258
|
+
type: CRUD,
|
|
17128
16259
|
timestamp,
|
|
17129
16260
|
id: m.id,
|
|
17130
16261
|
clientID: m.clientID,
|
|
17131
16262
|
name: m.name,
|
|
17132
16263
|
args: [m.args]
|
|
17133
16264
|
} : {
|
|
17134
|
-
type:
|
|
16265
|
+
type: Custom,
|
|
17135
16266
|
timestamp,
|
|
17136
16267
|
id: m.id,
|
|
17137
16268
|
clientID: m.clientID,
|
|
@@ -17195,7 +16326,7 @@ var Zero = class {
|
|
|
17195
16326
|
backoffMs = RUN_LOOP_INTERVAL_MS;
|
|
17196
16327
|
try {
|
|
17197
16328
|
switch (this.#connectionState) {
|
|
17198
|
-
case
|
|
16329
|
+
case Disconnected: {
|
|
17199
16330
|
if (this.#visibilityWatcher.visibilityState === "hidden") {
|
|
17200
16331
|
this.#metrics.setDisconnectedWaitingForVisible();
|
|
17201
16332
|
this.#totalToConnectStart = void 0;
|
|
@@ -17219,11 +16350,11 @@ var Zero = class {
|
|
|
17219
16350
|
this.#setOnline(true);
|
|
17220
16351
|
break;
|
|
17221
16352
|
}
|
|
17222
|
-
case
|
|
16353
|
+
case Connecting:
|
|
17223
16354
|
lc.error?.("unreachable");
|
|
17224
16355
|
gotError = true;
|
|
17225
16356
|
break;
|
|
17226
|
-
case
|
|
16357
|
+
case Connected: {
|
|
17227
16358
|
const controller = new AbortController();
|
|
17228
16359
|
this.#abortPingTimeout = () => controller.abort();
|
|
17229
16360
|
const [pingTimeoutPromise, pingTimeoutAborted] = sleepWithAbort(
|
|
@@ -17231,11 +16362,8 @@ var Zero = class {
|
|
|
17231
16362
|
controller.signal
|
|
17232
16363
|
);
|
|
17233
16364
|
this.#rejectMessageError = resolver8();
|
|
17234
|
-
|
|
17235
|
-
|
|
17236
|
-
RaceCases2[RaceCases2["Ping"] = 0] = "Ping";
|
|
17237
|
-
RaceCases2[RaceCases2["Hidden"] = 2] = "Hidden";
|
|
17238
|
-
})(RaceCases || (RaceCases = {}));
|
|
16365
|
+
const PING = 0;
|
|
16366
|
+
const HIDDEN = 2;
|
|
17239
16367
|
const raceResult = await promiseRace([
|
|
17240
16368
|
pingTimeoutPromise,
|
|
17241
16369
|
pingTimeoutAborted,
|
|
@@ -17248,17 +16376,17 @@ var Zero = class {
|
|
|
17248
16376
|
break;
|
|
17249
16377
|
}
|
|
17250
16378
|
switch (raceResult) {
|
|
17251
|
-
case
|
|
16379
|
+
case PING: {
|
|
17252
16380
|
const pingResult = await this.#ping(
|
|
17253
16381
|
lc,
|
|
17254
16382
|
this.#rejectMessageError.promise
|
|
17255
16383
|
);
|
|
17256
|
-
if (pingResult ===
|
|
16384
|
+
if (pingResult === TimedOut) {
|
|
17257
16385
|
gotError = true;
|
|
17258
16386
|
}
|
|
17259
16387
|
break;
|
|
17260
16388
|
}
|
|
17261
|
-
case
|
|
16389
|
+
case HIDDEN:
|
|
17262
16390
|
this.#disconnect(lc, {
|
|
17263
16391
|
client: "Hidden"
|
|
17264
16392
|
});
|
|
@@ -17269,7 +16397,7 @@ var Zero = class {
|
|
|
17269
16397
|
}
|
|
17270
16398
|
}
|
|
17271
16399
|
} catch (ex) {
|
|
17272
|
-
if (this.#connectionState !==
|
|
16400
|
+
if (this.#connectionState !== Connected) {
|
|
17273
16401
|
lc.error?.("Failed to connect", ex, {
|
|
17274
16402
|
lmid: this.#lastMutationIDReceived,
|
|
17275
16403
|
baseCookie: this.#connectCookie
|
|
@@ -17338,20 +16466,17 @@ var Zero = class {
|
|
|
17338
16466
|
const pullResponseResolver = resolver8();
|
|
17339
16467
|
this.#pendingPullsByRequestID.set(requestID, pullResponseResolver);
|
|
17340
16468
|
try {
|
|
17341
|
-
|
|
17342
|
-
|
|
17343
|
-
RaceCases2[RaceCases2["Timeout"] = 0] = "Timeout";
|
|
17344
|
-
RaceCases2[RaceCases2["Response"] = 1] = "Response";
|
|
17345
|
-
})(RaceCases || (RaceCases = {}));
|
|
16469
|
+
const TIMEOUT = 0;
|
|
16470
|
+
const RESPONSE = 1;
|
|
17346
16471
|
const raceResult = await promiseRace([
|
|
17347
16472
|
sleep(PULL_TIMEOUT_MS),
|
|
17348
16473
|
pullResponseResolver.promise
|
|
17349
16474
|
]);
|
|
17350
16475
|
switch (raceResult) {
|
|
17351
|
-
case
|
|
16476
|
+
case TIMEOUT:
|
|
17352
16477
|
lc.debug?.("Mutation recovery pull timed out");
|
|
17353
16478
|
throw new Error("Pull timed out");
|
|
17354
|
-
case
|
|
16479
|
+
case RESPONSE: {
|
|
17355
16480
|
lc.debug?.("Returning mutation recovery pull response");
|
|
17356
16481
|
const response = await pullResponseResolver.promise;
|
|
17357
16482
|
return {
|
|
@@ -17413,10 +16538,10 @@ var Zero = class {
|
|
|
17413
16538
|
this.#disconnect(l, {
|
|
17414
16539
|
client: "PingTimeout"
|
|
17415
16540
|
});
|
|
17416
|
-
return
|
|
16541
|
+
return TimedOut;
|
|
17417
16542
|
}
|
|
17418
16543
|
l.debug?.("ping succeeded in", delta, "ms");
|
|
17419
|
-
return
|
|
16544
|
+
return Success;
|
|
17420
16545
|
}
|
|
17421
16546
|
// Sends a set of metrics to the server. Throws unless the server
|
|
17422
16547
|
// returns 200.
|
|
@@ -17509,4 +16634,4 @@ export {
|
|
|
17509
16634
|
escapeLike,
|
|
17510
16635
|
Zero
|
|
17511
16636
|
};
|
|
17512
|
-
//# sourceMappingURL=chunk-
|
|
16637
|
+
//# sourceMappingURL=chunk-TS7IMB6J.js.map
|