@rocicorp/zero 0.26.1 → 0.26.2-canary.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/out/_virtual/_@oxc-project_runtime@0.115.0/helpers/usingCtx.js +57 -0
- package/out/_virtual/_rolldown/runtime.js +27 -0
- package/out/analyze-query/src/bin-analyze.js +195 -283
- package/out/analyze-query/src/bin-analyze.js.map +1 -1
- package/out/analyze-query/src/bin-transform.js +35 -40
- package/out/analyze-query/src/bin-transform.js.map +1 -1
- package/out/analyze-query/src/explain-queries.js +11 -13
- package/out/analyze-query/src/explain-queries.js.map +1 -1
- package/out/analyze-query/src/run-ast.js +68 -103
- package/out/analyze-query/src/run-ast.js.map +1 -1
- package/out/ast-to-zql/src/ast-to-zql.js +105 -153
- package/out/ast-to-zql/src/ast-to-zql.js.map +1 -1
- package/out/ast-to-zql/src/bin.js +57 -62
- package/out/ast-to-zql/src/bin.js.map +1 -1
- package/out/ast-to-zql/src/format.js +14 -13
- package/out/ast-to-zql/src/format.js.map +1 -1
- package/out/datadog/src/datadog-log-sink.js +148 -213
- package/out/datadog/src/datadog-log-sink.js.map +1 -1
- package/out/otel/src/enabled.js +9 -11
- package/out/otel/src/enabled.js.map +1 -1
- package/out/otel/src/log-options.js +25 -35
- package/out/otel/src/log-options.js.map +1 -1
- package/out/otel/src/maybe-time.js +13 -14
- package/out/otel/src/maybe-time.js.map +1 -1
- package/out/otel/src/span.js +23 -26
- package/out/otel/src/span.js.map +1 -1
- package/out/otel/src/test-log-config.js +11 -10
- package/out/otel/src/test-log-config.js.map +1 -1
- package/out/otel/src/version.js +6 -5
- package/out/otel/src/version.js.map +1 -1
- package/out/replicache/src/async-iterable-to-array.js +8 -9
- package/out/replicache/src/async-iterable-to-array.js.map +1 -1
- package/out/replicache/src/bg-interval.js +28 -35
- package/out/replicache/src/bg-interval.js.map +1 -1
- package/out/replicache/src/btree/diff.js +6 -5
- package/out/replicache/src/btree/diff.js.map +1 -1
- package/out/replicache/src/btree/node.js +281 -372
- package/out/replicache/src/btree/node.js.map +1 -1
- package/out/replicache/src/btree/read.js +155 -256
- package/out/replicache/src/btree/read.js.map +1 -1
- package/out/replicache/src/btree/splice.js +60 -80
- package/out/replicache/src/btree/splice.js.map +1 -1
- package/out/replicache/src/btree/write.js +134 -158
- package/out/replicache/src/btree/write.js.map +1 -1
- package/out/replicache/src/call-default-fetch.js +28 -32
- package/out/replicache/src/call-default-fetch.js.map +1 -1
- package/out/replicache/src/config.js +2 -0
- package/out/replicache/src/connection-loop-delegates.js +31 -33
- package/out/replicache/src/connection-loop-delegates.js.map +1 -1
- package/out/replicache/src/connection-loop.js +174 -240
- package/out/replicache/src/connection-loop.js.map +1 -1
- package/out/replicache/src/cookies.js +22 -32
- package/out/replicache/src/cookies.js.map +1 -1
- package/out/replicache/src/dag/chunk.js +44 -50
- package/out/replicache/src/dag/chunk.js.map +1 -1
- package/out/replicache/src/dag/gc.js +94 -114
- package/out/replicache/src/dag/gc.js.map +1 -1
- package/out/replicache/src/dag/key.js +9 -11
- package/out/replicache/src/dag/key.js.map +1 -1
- package/out/replicache/src/dag/lazy-store.js +458 -510
- package/out/replicache/src/dag/lazy-store.js.map +1 -1
- package/out/replicache/src/dag/store-impl.js +147 -178
- package/out/replicache/src/dag/store-impl.js.map +1 -1
- package/out/replicache/src/dag/store.js +19 -22
- package/out/replicache/src/dag/store.js.map +1 -1
- package/out/replicache/src/dag/visitor.js +23 -21
- package/out/replicache/src/dag/visitor.js.map +1 -1
- package/out/replicache/src/db/commit.js +209 -283
- package/out/replicache/src/db/commit.js.map +1 -1
- package/out/replicache/src/db/index.js +79 -122
- package/out/replicache/src/db/index.js.map +1 -1
- package/out/replicache/src/db/read.js +44 -60
- package/out/replicache/src/db/read.js.map +1 -1
- package/out/replicache/src/db/rebase.js +22 -77
- package/out/replicache/src/db/rebase.js.map +1 -1
- package/out/replicache/src/db/write.js +162 -296
- package/out/replicache/src/db/write.js.map +1 -1
- package/out/replicache/src/deleted-clients.js +59 -87
- package/out/replicache/src/deleted-clients.js.map +1 -1
- package/out/replicache/src/error-responses.js +18 -26
- package/out/replicache/src/error-responses.js.map +1 -1
- package/out/replicache/src/expo-sqlite.js +2 -0
- package/out/replicache/src/frozen-json.js +74 -108
- package/out/replicache/src/frozen-json.js.map +1 -1
- package/out/replicache/src/get-default-puller.js +34 -46
- package/out/replicache/src/get-default-puller.js.map +1 -1
- package/out/replicache/src/get-default-pusher.js +25 -33
- package/out/replicache/src/get-default-pusher.js.map +1 -1
- package/out/replicache/src/get-kv-store-provider.js +18 -20
- package/out/replicache/src/get-kv-store-provider.js.map +1 -1
- package/out/replicache/src/hash.js +29 -29
- package/out/replicache/src/hash.js.map +1 -1
- package/out/replicache/src/http-request-info.js +9 -8
- package/out/replicache/src/http-request-info.js.map +1 -1
- package/out/replicache/src/impl.js +2 -0
- package/out/replicache/src/index-defs.js +17 -28
- package/out/replicache/src/index-defs.js.map +1 -1
- package/out/replicache/src/kv/expo-sqlite/store.js +52 -50
- package/out/replicache/src/kv/expo-sqlite/store.js.map +1 -1
- package/out/replicache/src/kv/idb-store-with-mem-fallback.js +71 -68
- package/out/replicache/src/kv/idb-store-with-mem-fallback.js.map +1 -1
- package/out/replicache/src/kv/idb-store.js +144 -168
- package/out/replicache/src/kv/idb-store.js.map +1 -1
- package/out/replicache/src/kv/mem-store.js +57 -45
- package/out/replicache/src/kv/mem-store.js.map +1 -1
- package/out/replicache/src/kv/op-sqlite/store.js +56 -62
- package/out/replicache/src/kv/op-sqlite/store.js.map +1 -1
- package/out/replicache/src/kv/op-sqlite/types.d.ts.map +1 -1
- package/out/replicache/src/kv/op-sqlite/types.js +7 -6
- package/out/replicache/src/kv/op-sqlite/types.js.map +1 -1
- package/out/replicache/src/kv/read-impl.js +26 -25
- package/out/replicache/src/kv/read-impl.js.map +1 -1
- package/out/replicache/src/kv/sqlite-store.js +194 -207
- package/out/replicache/src/kv/sqlite-store.js.map +1 -1
- package/out/replicache/src/kv/throw-if-closed.js +12 -19
- package/out/replicache/src/kv/throw-if-closed.js.map +1 -1
- package/out/replicache/src/kv/write-impl-base.js +44 -56
- package/out/replicache/src/kv/write-impl-base.js.map +1 -1
- package/out/replicache/src/kv/write-impl.js +22 -26
- package/out/replicache/src/kv/write-impl.js.map +1 -1
- package/out/replicache/src/lazy.js +10 -11
- package/out/replicache/src/lazy.js.map +1 -1
- package/out/replicache/src/log-options.js +14 -7
- package/out/replicache/src/log-options.js.map +1 -1
- package/out/replicache/src/make-idb-name.js +14 -9
- package/out/replicache/src/make-idb-name.js.map +1 -1
- package/out/replicache/src/mutation-recovery.js +12 -0
- package/out/replicache/src/mutation-recovery.js.map +1 -0
- package/out/replicache/src/new-client-channel.js +34 -42
- package/out/replicache/src/new-client-channel.js.map +1 -1
- package/out/replicache/src/on-persist-channel.js +26 -29
- package/out/replicache/src/on-persist-channel.js.map +1 -1
- package/out/replicache/src/op-sqlite.js +2 -0
- package/out/replicache/src/patch-operation.js +27 -36
- package/out/replicache/src/patch-operation.js.map +1 -1
- package/out/replicache/src/pending-mutations.js +14 -12
- package/out/replicache/src/pending-mutations.js.map +1 -1
- package/out/replicache/src/persist/client-gc.js +36 -51
- package/out/replicache/src/persist/client-gc.js.map +1 -1
- package/out/replicache/src/persist/client-group-gc.js +29 -36
- package/out/replicache/src/persist/client-group-gc.js.map +1 -1
- package/out/replicache/src/persist/client-groups.js +80 -154
- package/out/replicache/src/persist/client-groups.js.map +1 -1
- package/out/replicache/src/persist/clients.js +212 -307
- package/out/replicache/src/persist/clients.js.map +1 -1
- package/out/replicache/src/persist/collect-idb-databases.js +109 -171
- package/out/replicache/src/persist/collect-idb-databases.js.map +1 -1
- package/out/replicache/src/persist/gather-mem-only-visitor.js +23 -24
- package/out/replicache/src/persist/gather-mem-only-visitor.js.map +1 -1
- package/out/replicache/src/persist/gather-not-cached-visitor.js +35 -33
- package/out/replicache/src/persist/gather-not-cached-visitor.js.map +1 -1
- package/out/replicache/src/persist/heartbeat.js +31 -41
- package/out/replicache/src/persist/heartbeat.js.map +1 -1
- package/out/replicache/src/persist/idb-databases-store-db-name.js +9 -12
- package/out/replicache/src/persist/idb-databases-store-db-name.js.map +1 -1
- package/out/replicache/src/persist/idb-databases-store.js +78 -97
- package/out/replicache/src/persist/idb-databases-store.js.map +1 -1
- package/out/replicache/src/persist/make-client-id.js +13 -9
- package/out/replicache/src/persist/make-client-id.js.map +1 -1
- package/out/replicache/src/persist/persist.js +113 -174
- package/out/replicache/src/persist/persist.js.map +1 -1
- package/out/replicache/src/persist/refresh.js +94 -183
- package/out/replicache/src/persist/refresh.js.map +1 -1
- package/out/replicache/src/process-scheduler.js +122 -143
- package/out/replicache/src/process-scheduler.js.map +1 -1
- package/out/replicache/src/pusher.js +21 -26
- package/out/replicache/src/pusher.js.map +1 -1
- package/out/replicache/src/replicache-impl.js +844 -1184
- package/out/replicache/src/replicache-impl.js.map +1 -1
- package/out/replicache/src/report-error.js +9 -6
- package/out/replicache/src/report-error.js.map +1 -1
- package/out/replicache/src/request-idle.js +13 -11
- package/out/replicache/src/request-idle.js.map +1 -1
- package/out/replicache/src/scan-iterator.d.ts.map +1 -1
- package/out/replicache/src/scan-iterator.js +108 -135
- package/out/replicache/src/scan-iterator.js.map +1 -1
- package/out/replicache/src/scan-options.js +33 -39
- package/out/replicache/src/scan-options.js.map +1 -1
- package/out/replicache/src/set-interval-with-signal.js +11 -10
- package/out/replicache/src/set-interval-with-signal.js.map +1 -1
- package/out/replicache/src/sqlite.js +2 -0
- package/out/replicache/src/subscriptions.js +222 -338
- package/out/replicache/src/subscriptions.js.map +1 -1
- package/out/replicache/src/sync/diff.js +52 -65
- package/out/replicache/src/sync/diff.js.map +1 -1
- package/out/replicache/src/sync/ids.js +8 -9
- package/out/replicache/src/sync/ids.js.map +1 -1
- package/out/replicache/src/sync/patch.js +34 -45
- package/out/replicache/src/sync/patch.js.map +1 -1
- package/out/replicache/src/sync/pull-error.js +15 -15
- package/out/replicache/src/sync/pull-error.js.map +1 -1
- package/out/replicache/src/sync/pull.js +145 -283
- package/out/replicache/src/sync/pull.js.map +1 -1
- package/out/replicache/src/sync/push.js +64 -79
- package/out/replicache/src/sync/push.js.map +1 -1
- package/out/replicache/src/sync/request-id.js +23 -15
- package/out/replicache/src/sync/request-id.js.map +1 -1
- package/out/replicache/src/sync/sync-head-name.js +6 -5
- package/out/replicache/src/sync/sync-head-name.js.map +1 -1
- package/out/replicache/src/to-error.js +7 -8
- package/out/replicache/src/to-error.js.map +1 -1
- package/out/replicache/src/transaction-closed-error.js +15 -15
- package/out/replicache/src/transaction-closed-error.js.map +1 -1
- package/out/replicache/src/transactions.js +120 -140
- package/out/replicache/src/transactions.js.map +1 -1
- package/out/replicache/src/version.js +9 -5
- package/out/replicache/src/version.js.map +1 -1
- package/out/replicache/src/with-transactions.js +23 -20
- package/out/replicache/src/with-transactions.js.map +1 -1
- package/out/shared/src/abort-error.js +7 -6
- package/out/shared/src/abort-error.js.map +1 -1
- package/out/shared/src/arrays.js +35 -42
- package/out/shared/src/arrays.js.map +1 -1
- package/out/shared/src/asserts.js +21 -45
- package/out/shared/src/asserts.js.map +1 -1
- package/out/shared/src/bigint-json.js +42 -38
- package/out/shared/src/bigint-json.js.map +1 -1
- package/out/shared/src/binary-search.js +27 -18
- package/out/shared/src/binary-search.js.map +1 -1
- package/out/shared/src/broadcast-channel.js +20 -23
- package/out/shared/src/broadcast-channel.js.map +1 -1
- package/out/shared/src/browser-env.js +11 -17
- package/out/shared/src/browser-env.js.map +1 -1
- package/out/shared/src/btree-set.js +419 -481
- package/out/shared/src/btree-set.js.map +1 -1
- package/out/shared/src/cache.js +43 -36
- package/out/shared/src/cache.js.map +1 -1
- package/out/shared/src/centroid.js +24 -26
- package/out/shared/src/centroid.js.map +1 -1
- package/out/shared/src/config.js +6 -6
- package/out/shared/src/config.js.map +1 -1
- package/out/shared/src/custom-key-map.js +54 -58
- package/out/shared/src/custom-key-map.js.map +1 -1
- package/out/shared/src/custom-key-set.js +53 -51
- package/out/shared/src/custom-key-set.js.map +1 -1
- package/out/shared/src/deep-clone.js +30 -41
- package/out/shared/src/deep-clone.js.map +1 -1
- package/out/shared/src/deep-merge.js +25 -24
- package/out/shared/src/deep-merge.js.map +1 -1
- package/out/shared/src/document-visible.js +63 -70
- package/out/shared/src/document-visible.js.map +1 -1
- package/out/shared/src/dotenv.js +7 -3
- package/out/shared/src/dotenv.js.map +1 -1
- package/out/shared/src/error.js +43 -64
- package/out/shared/src/error.js.map +1 -1
- package/out/shared/src/has-own.js +6 -5
- package/out/shared/src/has-own.js.map +1 -1
- package/out/shared/src/hash.js +15 -14
- package/out/shared/src/hash.js.map +1 -1
- package/out/shared/src/iterables.js +34 -47
- package/out/shared/src/iterables.js.map +1 -1
- package/out/shared/src/json-schema.js +25 -30
- package/out/shared/src/json-schema.js.map +1 -1
- package/out/shared/src/json.js +90 -129
- package/out/shared/src/json.js.map +1 -1
- package/out/shared/src/logging-test-utils.js +9 -11
- package/out/shared/src/logging-test-utils.js.map +1 -1
- package/out/shared/src/logging.js +75 -95
- package/out/shared/src/logging.js.map +1 -1
- package/out/shared/src/must.js +7 -8
- package/out/shared/src/must.js.map +1 -1
- package/out/shared/src/navigator.js +6 -5
- package/out/shared/src/navigator.js.map +1 -1
- package/out/shared/src/object-traversal.js +23 -23
- package/out/shared/src/object-traversal.js.map +1 -1
- package/out/shared/src/objects.js +15 -18
- package/out/shared/src/objects.js.map +1 -1
- package/out/shared/src/options.js +225 -302
- package/out/shared/src/options.js.map +1 -1
- package/out/shared/src/parse-big-int.js +12 -11
- package/out/shared/src/parse-big-int.js.map +1 -1
- package/out/shared/src/promise-race.js +21 -17
- package/out/shared/src/promise-race.js.map +1 -1
- package/out/shared/src/queue.js +124 -124
- package/out/shared/src/queue.js.map +1 -1
- package/out/shared/src/rand.js +13 -7
- package/out/shared/src/rand.js.map +1 -1
- package/out/shared/src/random-uint64.js +8 -7
- package/out/shared/src/random-uint64.js.map +1 -1
- package/out/shared/src/random-values.js +8 -11
- package/out/shared/src/random-values.js.map +1 -1
- package/out/shared/src/record-proxy.js +68 -57
- package/out/shared/src/record-proxy.js.map +1 -1
- package/out/shared/src/resolved-promises.js +9 -11
- package/out/shared/src/resolved-promises.js.map +1 -1
- package/out/shared/src/sentinels.js +9 -12
- package/out/shared/src/sentinels.js.map +1 -1
- package/out/shared/src/set-utils.js +41 -63
- package/out/shared/src/set-utils.js.map +1 -1
- package/out/shared/src/size-of-value.js +55 -51
- package/out/shared/src/size-of-value.js.map +1 -1
- package/out/shared/src/sleep.js +50 -45
- package/out/shared/src/sleep.js.map +1 -1
- package/out/shared/src/string-compare.js +8 -11
- package/out/shared/src/string-compare.js.map +1 -1
- package/out/shared/src/subscribable.js +34 -33
- package/out/shared/src/subscribable.js.map +1 -1
- package/out/shared/src/tdigest-schema.js +11 -7
- package/out/shared/src/tdigest-schema.js.map +1 -1
- package/out/shared/src/tdigest.js +197 -270
- package/out/shared/src/tdigest.js.map +1 -1
- package/out/shared/src/valita.js +145 -174
- package/out/shared/src/valita.js.map +1 -1
- package/out/z2s/src/compiler.d.ts.map +1 -1
- package/out/z2s/src/compiler.js +238 -468
- package/out/z2s/src/compiler.js.map +1 -1
- package/out/z2s/src/sql.d.ts +0 -1
- package/out/z2s/src/sql.d.ts.map +1 -1
- package/out/z2s/src/sql.js +149 -194
- package/out/z2s/src/sql.js.map +1 -1
- package/out/zero/package.js +194 -0
- package/out/zero/package.js.map +1 -0
- package/out/zero/src/adapters/drizzle.js +1 -6
- package/out/zero/src/adapters/pg.js +1 -6
- package/out/zero/src/adapters/postgresjs.js +1 -6
- package/out/zero/src/adapters/prisma.js +1 -5
- package/out/zero/src/analyze-query.js +1 -1
- package/out/zero/src/ast-to-zql.js +1 -1
- package/out/zero/src/bindings.js +6 -21
- package/out/zero/src/build-schema.js +5 -1
- package/out/zero/src/build-schema.js.map +1 -1
- package/out/zero/src/change-protocol/v0.js +3 -5
- package/out/zero/src/cli.js +2 -2
- package/out/zero/src/deploy-permissions.js +1 -1
- package/out/zero/src/expo-sqlite.js +2 -4
- package/out/zero/src/op-sqlite.js +2 -4
- package/out/zero/src/pg.js +2 -20
- package/out/zero/src/react-native.js +16 -12
- package/out/zero/src/react-native.js.map +1 -1
- package/out/zero/src/react.js +3 -12
- package/out/zero/src/server/runner/main.js +2 -0
- package/out/zero/src/server.js +2 -17
- package/out/zero/src/solid.js +3 -12
- package/out/zero/src/sqlite.js +2 -6
- package/out/zero/src/transform-query.js +1 -1
- package/out/zero/src/zero-cache-dev.js +124 -151
- package/out/zero/src/zero-cache-dev.js.map +1 -1
- package/out/zero/src/zero-out.js +9 -6
- package/out/zero/src/zero-out.js.map +1 -1
- package/out/zero/src/zero.js +6 -55
- package/out/zero/src/zqlite.js +2 -7
- package/out/zero-cache/src/auth/auth.js +138 -172
- package/out/zero-cache/src/auth/auth.js.map +1 -1
- package/out/zero-cache/src/auth/jwt.js +25 -33
- package/out/zero-cache/src/auth/jwt.js.map +1 -1
- package/out/zero-cache/src/auth/load-permissions.js +54 -62
- package/out/zero-cache/src/auth/load-permissions.js.map +1 -1
- package/out/zero-cache/src/auth/read-authorizer.js +70 -80
- package/out/zero-cache/src/auth/read-authorizer.js.map +1 -1
- package/out/zero-cache/src/auth/write-authorizer.js +284 -432
- package/out/zero-cache/src/auth/write-authorizer.js.map +1 -1
- package/out/zero-cache/src/config/network.js +31 -45
- package/out/zero-cache/src/config/network.js.map +1 -1
- package/out/zero-cache/src/config/normalize.js +81 -83
- package/out/zero-cache/src/config/normalize.js.map +1 -1
- package/out/zero-cache/src/config/server-context.js +32 -29
- package/out/zero-cache/src/config/server-context.js.map +1 -1
- package/out/zero-cache/src/config/zero-config.js +753 -833
- package/out/zero-cache/src/config/zero-config.js.map +1 -1
- package/out/zero-cache/src/custom/fetch.js +183 -230
- package/out/zero-cache/src/custom/fetch.js.map +1 -1
- package/out/zero-cache/src/custom-queries/transform-query.js +93 -99
- package/out/zero-cache/src/custom-queries/transform-query.js.map +1 -1
- package/out/zero-cache/src/db/create.js +27 -29
- package/out/zero-cache/src/db/create.js.map +1 -1
- package/out/zero-cache/src/db/delete-lite-db.js +11 -7
- package/out/zero-cache/src/db/delete-lite-db.js.map +1 -1
- package/out/zero-cache/src/db/lite-tables.js +118 -158
- package/out/zero-cache/src/db/lite-tables.js.map +1 -1
- package/out/zero-cache/src/db/migration-lite.js +110 -178
- package/out/zero-cache/src/db/migration-lite.js.map +1 -1
- package/out/zero-cache/src/db/migration.js +82 -151
- package/out/zero-cache/src/db/migration.js.map +1 -1
- package/out/zero-cache/src/db/mode-enum.js +8 -9
- package/out/zero-cache/src/db/mode-enum.js.map +1 -1
- package/out/zero-cache/src/db/pg-copy.js +56 -54
- package/out/zero-cache/src/db/pg-copy.js.map +1 -1
- package/out/zero-cache/src/db/pg-to-lite.js +74 -110
- package/out/zero-cache/src/db/pg-to-lite.js.map +1 -1
- package/out/zero-cache/src/db/pg-type-parser.js +19 -36
- package/out/zero-cache/src/db/pg-type-parser.js.map +1 -1
- package/out/zero-cache/src/db/run-transaction.js +19 -20
- package/out/zero-cache/src/db/run-transaction.js.map +1 -1
- package/out/zero-cache/src/db/specs.js +42 -78
- package/out/zero-cache/src/db/specs.js.map +1 -1
- package/out/zero-cache/src/db/statements.js +52 -59
- package/out/zero-cache/src/db/statements.js.map +1 -1
- package/out/zero-cache/src/db/transaction-pool.js +376 -400
- package/out/zero-cache/src/db/transaction-pool.js.map +1 -1
- package/out/zero-cache/src/db/warmup.js +13 -24
- package/out/zero-cache/src/db/warmup.js.map +1 -1
- package/out/zero-cache/src/observability/events.js +89 -99
- package/out/zero-cache/src/observability/events.js.map +1 -1
- package/out/zero-cache/src/observability/metrics.js +30 -54
- package/out/zero-cache/src/observability/metrics.js.map +1 -1
- package/out/zero-cache/src/scripts/decommission.js +42 -47
- package/out/zero-cache/src/scripts/decommission.js.map +1 -1
- package/out/zero-cache/src/scripts/deploy-permissions.js +106 -144
- package/out/zero-cache/src/scripts/deploy-permissions.js.map +1 -1
- package/out/zero-cache/src/scripts/permissions.js +86 -107
- package/out/zero-cache/src/scripts/permissions.js.map +1 -1
- package/out/zero-cache/src/server/anonymous-otel-start.js +306 -440
- package/out/zero-cache/src/server/anonymous-otel-start.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 +57 -130
- package/out/zero-cache/src/server/change-streamer.js.map +1 -1
- package/out/zero-cache/src/server/inspector-delegate.js +89 -100
- package/out/zero-cache/src/server/inspector-delegate.js.map +1 -1
- package/out/zero-cache/src/server/logging.js +18 -26
- package/out/zero-cache/src/server/logging.js.map +1 -1
- package/out/zero-cache/src/server/main.js +85 -142
- package/out/zero-cache/src/server/main.js.map +1 -1
- package/out/zero-cache/src/server/mutator.js +16 -13
- package/out/zero-cache/src/server/mutator.js.map +1 -1
- package/out/zero-cache/src/server/otel-diag-logger.js +42 -49
- package/out/zero-cache/src/server/otel-diag-logger.js.map +1 -1
- package/out/zero-cache/src/server/otel-log-sink.js +34 -44
- package/out/zero-cache/src/server/otel-log-sink.js.map +1 -1
- package/out/zero-cache/src/server/otel-start.js +43 -51
- package/out/zero-cache/src/server/otel-start.js.map +1 -1
- package/out/zero-cache/src/server/priority-op.js +27 -25
- package/out/zero-cache/src/server/priority-op.js.map +1 -1
- package/out/zero-cache/src/server/reaper.js +32 -43
- package/out/zero-cache/src/server/reaper.js.map +1 -1
- package/out/zero-cache/src/server/replicator.d.ts.map +1 -1
- package/out/zero-cache/src/server/replicator.js +41 -57
- package/out/zero-cache/src/server/replicator.js.map +1 -1
- package/out/zero-cache/src/server/runner/main.js +7 -8
- package/out/zero-cache/src/server/runner/main.js.map +1 -1
- package/out/zero-cache/src/server/runner/run-worker.js +56 -52
- package/out/zero-cache/src/server/runner/run-worker.js.map +1 -1
- package/out/zero-cache/src/server/runner/runtime.js +26 -32
- package/out/zero-cache/src/server/runner/runtime.js.map +1 -1
- package/out/zero-cache/src/server/runner/zero-dispatcher.js +22 -27
- package/out/zero-cache/src/server/runner/zero-dispatcher.js.map +1 -1
- package/out/zero-cache/src/server/syncer.js +79 -148
- package/out/zero-cache/src/server/syncer.js.map +1 -1
- package/out/zero-cache/src/server/worker-dispatcher.js +84 -113
- package/out/zero-cache/src/server/worker-dispatcher.js.map +1 -1
- package/out/zero-cache/src/server/worker-urls.d.ts +2 -1
- package/out/zero-cache/src/server/worker-urls.d.ts.map +1 -1
- package/out/zero-cache/src/server/worker-urls.js +14 -18
- package/out/zero-cache/src/server/worker-urls.js.map +1 -1
- package/out/zero-cache/src/server/write-worker.js +2 -0
- package/out/zero-cache/src/services/analyze.js +61 -130
- package/out/zero-cache/src/services/analyze.js.map +1 -1
- package/out/zero-cache/src/services/change-source/common/backfill-manager.js +420 -419
- package/out/zero-cache/src/services/change-source/common/backfill-manager.js.map +1 -1
- package/out/zero-cache/src/services/change-source/common/change-stream-multiplexer.js +111 -114
- package/out/zero-cache/src/services/change-source/common/change-stream-multiplexer.js.map +1 -1
- package/out/zero-cache/src/services/change-source/common/replica-schema.js +80 -148
- package/out/zero-cache/src/services/change-source/common/replica-schema.js.map +1 -1
- package/out/zero-cache/src/services/change-source/custom/change-source.js +154 -216
- package/out/zero-cache/src/services/change-source/custom/change-source.js.map +1 -1
- package/out/zero-cache/src/services/change-source/pg/backfill-metadata.js +11 -14
- package/out/zero-cache/src/services/change-source/pg/backfill-metadata.js.map +1 -1
- package/out/zero-cache/src/services/change-source/pg/backfill-stream.js +168 -212
- package/out/zero-cache/src/services/change-source/pg/backfill-stream.js.map +1 -1
- package/out/zero-cache/src/services/change-source/pg/change-source.js +672 -892
- package/out/zero-cache/src/services/change-source/pg/change-source.js.map +1 -1
- package/out/zero-cache/src/services/change-source/pg/decommission.js +19 -23
- package/out/zero-cache/src/services/change-source/pg/decommission.js.map +1 -1
- package/out/zero-cache/src/services/change-source/pg/initial-sync.js +258 -411
- package/out/zero-cache/src/services/change-source/pg/initial-sync.js.map +1 -1
- package/out/zero-cache/src/services/change-source/pg/logical-replication/binary-reader.js +59 -65
- package/out/zero-cache/src/services/change-source/pg/logical-replication/binary-reader.js.map +1 -1
- package/out/zero-cache/src/services/change-source/pg/logical-replication/pgoutput-parser.js +218 -247
- package/out/zero-cache/src/services/change-source/pg/logical-replication/pgoutput-parser.js.map +1 -1
- package/out/zero-cache/src/services/change-source/pg/logical-replication/stream.js +100 -142
- package/out/zero-cache/src/services/change-source/pg/logical-replication/stream.js.map +1 -1
- package/out/zero-cache/src/services/change-source/pg/lsn.js +17 -19
- package/out/zero-cache/src/services/change-source/pg/lsn.js.map +1 -1
- package/out/zero-cache/src/services/change-source/pg/schema/ddl.js +88 -98
- package/out/zero-cache/src/services/change-source/pg/schema/ddl.js.map +1 -1
- package/out/zero-cache/src/services/change-source/pg/schema/init.js +96 -177
- package/out/zero-cache/src/services/change-source/pg/schema/init.js.map +1 -1
- package/out/zero-cache/src/services/change-source/pg/schema/published.js +69 -107
- package/out/zero-cache/src/services/change-source/pg/schema/published.js.map +1 -1
- package/out/zero-cache/src/services/change-source/pg/schema/shard.js +151 -212
- package/out/zero-cache/src/services/change-source/pg/schema/shard.js.map +1 -1
- package/out/zero-cache/src/services/change-source/pg/schema/validation.js +22 -53
- package/out/zero-cache/src/services/change-source/pg/schema/validation.js.map +1 -1
- package/out/zero-cache/src/services/change-source/protocol/current/control.js +24 -12
- package/out/zero-cache/src/services/change-source/protocol/current/control.js.map +1 -1
- package/out/zero-cache/src/services/change-source/protocol/current/data.js +180 -290
- package/out/zero-cache/src/services/change-source/protocol/current/data.js.map +1 -1
- package/out/zero-cache/src/services/change-source/protocol/current/downstream.js +21 -33
- package/out/zero-cache/src/services/change-source/protocol/current/downstream.js.map +1 -1
- package/out/zero-cache/src/services/change-source/protocol/current/json.js +7 -18
- package/out/zero-cache/src/services/change-source/protocol/current/json.js.map +1 -1
- package/out/zero-cache/src/services/change-source/protocol/current/path.js +24 -5
- package/out/zero-cache/src/services/change-source/protocol/current/path.js.map +1 -1
- package/out/zero-cache/src/services/change-source/protocol/current/status.js +25 -19
- package/out/zero-cache/src/services/change-source/protocol/current/status.js.map +1 -1
- package/out/zero-cache/src/services/change-source/protocol/current/upstream.js +24 -16
- package/out/zero-cache/src/services/change-source/protocol/current/upstream.js.map +1 -1
- package/out/zero-cache/src/services/change-source/protocol/current.js +51 -46
- package/out/zero-cache/src/services/change-source/protocol/current.js.map +1 -1
- package/out/zero-cache/src/services/change-source/protocol/mod.js +2 -0
- package/out/zero-cache/src/services/change-streamer/backup-monitor.js +165 -171
- package/out/zero-cache/src/services/change-streamer/backup-monitor.js.map +1 -1
- package/out/zero-cache/src/services/change-streamer/broadcast.js +163 -169
- package/out/zero-cache/src/services/change-streamer/broadcast.js.map +1 -1
- package/out/zero-cache/src/services/change-streamer/change-streamer-http.js +154 -221
- package/out/zero-cache/src/services/change-streamer/change-streamer-http.js.map +1 -1
- package/out/zero-cache/src/services/change-streamer/change-streamer-service.d.ts.map +1 -1
- package/out/zero-cache/src/services/change-streamer/change-streamer-service.js +340 -299
- 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.js +17 -24
- package/out/zero-cache/src/services/change-streamer/change-streamer.js.map +1 -1
- package/out/zero-cache/src/services/change-streamer/forwarder.js +84 -103
- package/out/zero-cache/src/services/change-streamer/forwarder.js.map +1 -1
- package/out/zero-cache/src/services/change-streamer/replica-monitor.js +49 -43
- package/out/zero-cache/src/services/change-streamer/replica-monitor.js.map +1 -1
- package/out/zero-cache/src/services/change-streamer/schema/init.js +61 -89
- package/out/zero-cache/src/services/change-streamer/schema/init.js.map +1 -1
- package/out/zero-cache/src/services/change-streamer/schema/tables.d.ts +20 -1
- package/out/zero-cache/src/services/change-streamer/schema/tables.d.ts.map +1 -1
- package/out/zero-cache/src/services/change-streamer/schema/tables.js +131 -109
- package/out/zero-cache/src/services/change-streamer/schema/tables.js.map +1 -1
- package/out/zero-cache/src/services/change-streamer/snapshot.js +26 -28
- package/out/zero-cache/src/services/change-streamer/snapshot.js.map +1 -1
- package/out/zero-cache/src/services/change-streamer/storer.js +434 -513
- package/out/zero-cache/src/services/change-streamer/storer.js.map +1 -1
- package/out/zero-cache/src/services/change-streamer/subscriber.js +142 -155
- package/out/zero-cache/src/services/change-streamer/subscriber.js.map +1 -1
- package/out/zero-cache/src/services/heapz.js +18 -20
- package/out/zero-cache/src/services/heapz.js.map +1 -1
- package/out/zero-cache/src/services/http-service.js +59 -57
- package/out/zero-cache/src/services/http-service.js.map +1 -1
- package/out/zero-cache/src/services/life-cycle.js +182 -214
- package/out/zero-cache/src/services/life-cycle.js.map +1 -1
- package/out/zero-cache/src/services/limiter/sliding-window-limiter.js +102 -81
- package/out/zero-cache/src/services/limiter/sliding-window-limiter.js.map +1 -1
- package/out/zero-cache/src/services/litestream/commands.js +144 -205
- package/out/zero-cache/src/services/litestream/commands.js.map +1 -1
- package/out/zero-cache/src/services/mutagen/error.js +10 -14
- package/out/zero-cache/src/services/mutagen/error.js.map +1 -1
- package/out/zero-cache/src/services/mutagen/mutagen.js +166 -264
- package/out/zero-cache/src/services/mutagen/mutagen.js.map +1 -1
- package/out/zero-cache/src/services/mutagen/pusher.js +372 -487
- package/out/zero-cache/src/services/mutagen/pusher.js.map +1 -1
- package/out/zero-cache/src/services/replicator/change-processor.js +483 -592
- package/out/zero-cache/src/services/replicator/change-processor.js.map +1 -1
- package/out/zero-cache/src/services/replicator/incremental-sync.d.ts +4 -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 +118 -143
- package/out/zero-cache/src/services/replicator/incremental-sync.js.map +1 -1
- package/out/zero-cache/src/services/replicator/notifier.js +52 -28
- package/out/zero-cache/src/services/replicator/notifier.js.map +1 -1
- package/out/zero-cache/src/services/replicator/replication-status.js +105 -128
- package/out/zero-cache/src/services/replicator/replication-status.js.map +1 -1
- package/out/zero-cache/src/services/replicator/replicator.d.ts +2 -1
- package/out/zero-cache/src/services/replicator/replicator.d.ts.map +1 -1
- package/out/zero-cache/src/services/replicator/replicator.js +32 -34
- package/out/zero-cache/src/services/replicator/replicator.js.map +1 -1
- package/out/zero-cache/src/services/replicator/schema/change-log.js +101 -133
- package/out/zero-cache/src/services/replicator/schema/change-log.js.map +1 -1
- package/out/zero-cache/src/services/replicator/schema/column-metadata.js +145 -174
- package/out/zero-cache/src/services/replicator/schema/column-metadata.js.map +1 -1
- package/out/zero-cache/src/services/replicator/schema/constants.js +11 -5
- package/out/zero-cache/src/services/replicator/schema/constants.js.map +1 -1
- package/out/zero-cache/src/services/replicator/schema/replication-state.js +56 -107
- package/out/zero-cache/src/services/replicator/schema/replication-state.js.map +1 -1
- package/out/zero-cache/src/services/replicator/schema/table-metadata.js +81 -66
- package/out/zero-cache/src/services/replicator/schema/table-metadata.js.map +1 -1
- package/out/zero-cache/src/services/replicator/write-worker-client.d.ts +69 -0
- package/out/zero-cache/src/services/replicator/write-worker-client.d.ts.map +1 -0
- package/out/zero-cache/src/services/replicator/write-worker-client.js +96 -0
- package/out/zero-cache/src/services/replicator/write-worker-client.js.map +1 -0
- package/out/zero-cache/src/services/replicator/write-worker.js +68 -0
- package/out/zero-cache/src/services/replicator/write-worker.js.map +1 -0
- package/out/zero-cache/src/services/run-ast.js +79 -120
- package/out/zero-cache/src/services/run-ast.js.map +1 -1
- package/out/zero-cache/src/services/runner.js +39 -41
- package/out/zero-cache/src/services/runner.js.map +1 -1
- package/out/zero-cache/src/services/running-state.js +129 -134
- package/out/zero-cache/src/services/running-state.js.map +1 -1
- package/out/zero-cache/src/services/statz.js +139 -200
- package/out/zero-cache/src/services/statz.js.map +1 -1
- package/out/zero-cache/src/services/view-syncer/active-users-gauge.js +46 -49
- package/out/zero-cache/src/services/view-syncer/active-users-gauge.js.map +1 -1
- package/out/zero-cache/src/services/view-syncer/client-handler.js +257 -299
- package/out/zero-cache/src/services/view-syncer/client-handler.js.map +1 -1
- package/out/zero-cache/src/services/view-syncer/client-schema.js +52 -82
- package/out/zero-cache/src/services/view-syncer/client-schema.js.map +1 -1
- package/out/zero-cache/src/services/view-syncer/cvr-purger.js +85 -107
- package/out/zero-cache/src/services/view-syncer/cvr-purger.js.map +1 -1
- package/out/zero-cache/src/services/view-syncer/cvr-store.js +604 -757
- package/out/zero-cache/src/services/view-syncer/cvr-store.js.map +1 -1
- package/out/zero-cache/src/services/view-syncer/cvr.js +631 -739
- package/out/zero-cache/src/services/view-syncer/cvr.js.map +1 -1
- package/out/zero-cache/src/services/view-syncer/drain-coordinator.js +60 -40
- package/out/zero-cache/src/services/view-syncer/drain-coordinator.js.map +1 -1
- package/out/zero-cache/src/services/view-syncer/inspect-handler.js +95 -178
- package/out/zero-cache/src/services/view-syncer/inspect-handler.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 +571 -722
- package/out/zero-cache/src/services/view-syncer/pipeline-driver.js.map +1 -1
- package/out/zero-cache/src/services/view-syncer/row-record-cache.d.ts.map +1 -1
- package/out/zero-cache/src/services/view-syncer/row-record-cache.js +246 -257
- package/out/zero-cache/src/services/view-syncer/row-record-cache.js.map +1 -1
- package/out/zero-cache/src/services/view-syncer/schema/cvr.js +59 -45
- package/out/zero-cache/src/services/view-syncer/schema/cvr.js.map +1 -1
- package/out/zero-cache/src/services/view-syncer/schema/init.js +121 -189
- package/out/zero-cache/src/services/view-syncer/schema/init.js.map +1 -1
- package/out/zero-cache/src/services/view-syncer/schema/types.js +138 -263
- package/out/zero-cache/src/services/view-syncer/schema/types.js.map +1 -1
- package/out/zero-cache/src/services/view-syncer/snapshotter.js +322 -335
- package/out/zero-cache/src/services/view-syncer/snapshotter.js.map +1 -1
- package/out/zero-cache/src/services/view-syncer/tracer.js +7 -6
- package/out/zero-cache/src/services/view-syncer/tracer.js.map +1 -1
- package/out/zero-cache/src/services/view-syncer/ttl-clock.js +9 -11
- package/out/zero-cache/src/services/view-syncer/ttl-clock.js.map +1 -1
- package/out/zero-cache/src/services/view-syncer/view-syncer.js +1067 -1603
- package/out/zero-cache/src/services/view-syncer/view-syncer.js.map +1 -1
- package/out/zero-cache/src/types/error-with-level.js +19 -25
- package/out/zero-cache/src/types/error-with-level.js.map +1 -1
- package/out/zero-cache/src/types/http.js +17 -26
- package/out/zero-cache/src/types/http.js.map +1 -1
- package/out/zero-cache/src/types/lexi-version.js +28 -42
- package/out/zero-cache/src/types/lexi-version.js.map +1 -1
- package/out/zero-cache/src/types/lite.js +101 -121
- package/out/zero-cache/src/types/lite.js.map +1 -1
- package/out/zero-cache/src/types/names.js +6 -5
- package/out/zero-cache/src/types/names.js.map +1 -1
- package/out/zero-cache/src/types/pg-data-type.d.ts +1 -0
- package/out/zero-cache/src/types/pg-data-type.d.ts.map +1 -1
- package/out/zero-cache/src/types/pg-data-type.js +58 -73
- package/out/zero-cache/src/types/pg-data-type.js.map +1 -1
- package/out/zero-cache/src/types/pg-types.js +12 -19
- package/out/zero-cache/src/types/pg-types.js.map +1 -1
- package/out/zero-cache/src/types/pg.js +144 -218
- package/out/zero-cache/src/types/pg.js.map +1 -1
- package/out/zero-cache/src/types/processes.js +95 -90
- package/out/zero-cache/src/types/processes.js.map +1 -1
- package/out/zero-cache/src/types/profiler.js +32 -27
- package/out/zero-cache/src/types/profiler.js.map +1 -1
- package/out/zero-cache/src/types/row-key.js +42 -30
- package/out/zero-cache/src/types/row-key.js.map +1 -1
- package/out/zero-cache/src/types/shards.js +36 -45
- package/out/zero-cache/src/types/shards.js.map +1 -1
- package/out/zero-cache/src/types/sql.js +20 -9
- package/out/zero-cache/src/types/sql.js.map +1 -1
- package/out/zero-cache/src/types/state-version.js +17 -23
- package/out/zero-cache/src/types/state-version.js.map +1 -1
- package/out/zero-cache/src/types/streams.js +234 -270
- package/out/zero-cache/src/types/streams.js.map +1 -1
- package/out/zero-cache/src/types/strings.js +10 -13
- package/out/zero-cache/src/types/strings.js.map +1 -1
- package/out/zero-cache/src/types/subscription.js +266 -226
- package/out/zero-cache/src/types/subscription.js.map +1 -1
- package/out/zero-cache/src/types/url-params.js +30 -39
- package/out/zero-cache/src/types/url-params.js.map +1 -1
- package/out/zero-cache/src/types/websocket-handoff.js +62 -75
- package/out/zero-cache/src/types/websocket-handoff.js.map +1 -1
- package/out/zero-cache/src/types/ws.js +43 -53
- package/out/zero-cache/src/types/ws.js.map +1 -1
- package/out/zero-cache/src/workers/connect-params.js +42 -43
- package/out/zero-cache/src/workers/connect-params.js.map +1 -1
- package/out/zero-cache/src/workers/connection.js +213 -282
- package/out/zero-cache/src/workers/connection.js.map +1 -1
- package/out/zero-cache/src/workers/mutator.js +22 -21
- package/out/zero-cache/src/workers/mutator.js.map +1 -1
- package/out/zero-cache/src/workers/replicator.d.ts +7 -0
- package/out/zero-cache/src/workers/replicator.d.ts.map +1 -1
- package/out/zero-cache/src/workers/replicator.js +92 -97
- package/out/zero-cache/src/workers/replicator.js.map +1 -1
- package/out/zero-cache/src/workers/syncer-ws-message-handler.js +121 -203
- package/out/zero-cache/src/workers/syncer-ws-message-handler.js.map +1 -1
- package/out/zero-cache/src/workers/syncer.js +147 -201
- package/out/zero-cache/src/workers/syncer.js.map +1 -1
- package/out/zero-client/src/client/active-clients-manager.js +178 -187
- package/out/zero-client/src/client/active-clients-manager.js.map +1 -1
- package/out/zero-client/src/client/bindings.js +11 -0
- package/out/zero-client/src/client/client-error-kind-enum.js +18 -29
- package/out/zero-client/src/client/client-error-kind-enum.js.map +1 -1
- package/out/zero-client/src/client/connection-manager.js +291 -346
- package/out/zero-client/src/client/connection-manager.js.map +1 -1
- package/out/zero-client/src/client/connection-status-enum.js +20 -15
- package/out/zero-client/src/client/connection-status-enum.js.map +1 -1
- package/out/zero-client/src/client/connection.js +92 -110
- package/out/zero-client/src/client/connection.js.map +1 -1
- package/out/zero-client/src/client/context.js +84 -100
- package/out/zero-client/src/client/context.js.map +1 -1
- package/out/zero-client/src/client/crud-impl.js +56 -88
- package/out/zero-client/src/client/crud-impl.js.map +1 -1
- package/out/zero-client/src/client/crud.js +127 -129
- package/out/zero-client/src/client/crud.js.map +1 -1
- package/out/zero-client/src/client/custom.d.ts.map +1 -1
- package/out/zero-client/src/client/custom.js +50 -74
- package/out/zero-client/src/client/custom.js.map +1 -1
- package/out/zero-client/src/client/delete-clients-manager.js +72 -93
- package/out/zero-client/src/client/delete-clients-manager.js.map +1 -1
- package/out/zero-client/src/client/enable-analytics.js +8 -16
- package/out/zero-client/src/client/enable-analytics.js.map +1 -1
- package/out/zero-client/src/client/error.js +118 -133
- package/out/zero-client/src/client/error.js.map +1 -1
- package/out/zero-client/src/client/http-string.js +7 -7
- package/out/zero-client/src/client/http-string.js.map +1 -1
- package/out/zero-client/src/client/inspector/client-group.js +21 -26
- package/out/zero-client/src/client/inspector/client-group.js.map +1 -1
- package/out/zero-client/src/client/inspector/client.js +23 -26
- package/out/zero-client/src/client/inspector/client.js.map +1 -1
- package/out/zero-client/src/client/inspector/html-dialog-prompt.js +72 -73
- package/out/zero-client/src/client/inspector/html-dialog-prompt.js.map +1 -1
- package/out/zero-client/src/client/inspector/inspector.js +46 -51
- package/out/zero-client/src/client/inspector/inspector.js.map +1 -1
- package/out/zero-client/src/client/inspector/lazy-inspector.js +132 -192
- package/out/zero-client/src/client/inspector/lazy-inspector.js.map +1 -1
- package/out/zero-client/src/client/inspector/query.js +72 -77
- package/out/zero-client/src/client/inspector/query.js.map +1 -1
- package/out/zero-client/src/client/ivm-branch.js +118 -145
- package/out/zero-client/src/client/ivm-branch.js.map +1 -1
- package/out/zero-client/src/client/keys.js +15 -31
- package/out/zero-client/src/client/keys.js.map +1 -1
- package/out/zero-client/src/client/log-options.js +43 -57
- package/out/zero-client/src/client/log-options.js.map +1 -1
- package/out/zero-client/src/client/make-mutate-property.js +46 -29
- package/out/zero-client/src/client/make-mutate-property.js.map +1 -1
- package/out/zero-client/src/client/make-replicache-mutators.js +80 -96
- package/out/zero-client/src/client/make-replicache-mutators.js.map +1 -1
- package/out/zero-client/src/client/metric-name-enum.js +11 -15
- package/out/zero-client/src/client/metric-name-enum.js.map +1 -1
- package/out/zero-client/src/client/metrics.js +210 -237
- package/out/zero-client/src/client/metrics.js.map +1 -1
- package/out/zero-client/src/client/mutation-tracker.js +264 -354
- package/out/zero-client/src/client/mutation-tracker.js.map +1 -1
- package/out/zero-client/src/client/mutator-proxy.js +122 -151
- package/out/zero-client/src/client/mutator-proxy.js.map +1 -1
- package/out/zero-client/src/client/options.js +7 -10
- package/out/zero-client/src/client/options.js.map +1 -1
- package/out/zero-client/src/client/query-manager.js +305 -373
- package/out/zero-client/src/client/query-manager.js.map +1 -1
- package/out/zero-client/src/client/reload-error-handler.js +80 -101
- package/out/zero-client/src/client/reload-error-handler.js.map +1 -1
- package/out/zero-client/src/client/server-option.js +30 -59
- package/out/zero-client/src/client/server-option.js.map +1 -1
- package/out/zero-client/src/client/update-needed-reason-type-enum.js +27 -9
- package/out/zero-client/src/client/update-needed-reason-type-enum.js.map +1 -1
- package/out/zero-client/src/client/version.js +9 -5
- package/out/zero-client/src/client/version.js.map +1 -1
- package/out/zero-client/src/client/zero-poke-handler.d.ts +1 -1
- package/out/zero-client/src/client/zero-poke-handler.d.ts.map +1 -1
- package/out/zero-client/src/client/zero-poke-handler.js +205 -293
- package/out/zero-client/src/client/zero-poke-handler.js.map +1 -1
- package/out/zero-client/src/client/zero-rep.js +61 -68
- package/out/zero-client/src/client/zero-rep.js.map +1 -1
- package/out/zero-client/src/client/zero.d.ts.map +1 -1
- package/out/zero-client/src/client/zero.js +1367 -1834
- package/out/zero-client/src/client/zero.js.map +1 -1
- package/out/zero-client/src/mod.js +21 -0
- package/out/zero-client/src/util/nanoid.js +13 -18
- package/out/zero-client/src/util/nanoid.js.map +1 -1
- package/out/zero-client/src/util/socket.js +6 -5
- package/out/zero-client/src/util/socket.js.map +1 -1
- package/out/zero-pg/src/mod.js +10 -0
- package/out/zero-protocol/src/analyze-query-result.js +108 -148
- package/out/zero-protocol/src/analyze-query-result.js.map +1 -1
- package/out/zero-protocol/src/application-error.js +36 -34
- package/out/zero-protocol/src/application-error.js.map +1 -1
- package/out/zero-protocol/src/ast.js +236 -309
- package/out/zero-protocol/src/ast.js.map +1 -1
- package/out/zero-protocol/src/change-desired-queries.js +8 -13
- package/out/zero-protocol/src/change-desired-queries.js.map +1 -1
- package/out/zero-protocol/src/client-schema.js +21 -42
- package/out/zero-protocol/src/client-schema.js.map +1 -1
- package/out/zero-protocol/src/close-connection.js +20 -12
- package/out/zero-protocol/src/close-connection.js.map +1 -1
- package/out/zero-protocol/src/connect.js +37 -52
- package/out/zero-protocol/src/connect.js.map +1 -1
- package/out/zero-protocol/src/custom-queries.js +34 -65
- package/out/zero-protocol/src/custom-queries.js.map +1 -1
- package/out/zero-protocol/src/data.js +6 -9
- package/out/zero-protocol/src/data.js.map +1 -1
- package/out/zero-protocol/src/delete-clients.js +11 -17
- package/out/zero-protocol/src/delete-clients.js.map +1 -1
- package/out/zero-protocol/src/down.js +11 -23
- package/out/zero-protocol/src/down.js.map +1 -1
- package/out/zero-protocol/src/error-kind-enum.js +24 -41
- package/out/zero-protocol/src/error-kind-enum.js.map +1 -1
- package/out/zero-protocol/src/error-origin-enum.js +8 -9
- package/out/zero-protocol/src/error-origin-enum.js.map +1 -1
- package/out/zero-protocol/src/error-reason-enum.js +12 -17
- package/out/zero-protocol/src/error-reason-enum.js.map +1 -1
- package/out/zero-protocol/src/error.js +76 -152
- package/out/zero-protocol/src/error.js.map +1 -1
- package/out/zero-protocol/src/inspect-down.js +51 -74
- package/out/zero-protocol/src/inspect-down.js.map +1 -1
- package/out/zero-protocol/src/inspect-up.js +28 -46
- package/out/zero-protocol/src/inspect-up.js.map +1 -1
- package/out/zero-protocol/src/mutation-id.js +9 -9
- package/out/zero-protocol/src/mutation-id.js.map +1 -1
- package/out/zero-protocol/src/mutation-type-enum.js +7 -7
- package/out/zero-protocol/src/mutation-type-enum.js.map +1 -1
- package/out/zero-protocol/src/mutations-patch.js +21 -16
- package/out/zero-protocol/src/mutations-patch.js.map +1 -1
- package/out/zero-protocol/src/ping.js +8 -9
- package/out/zero-protocol/src/ping.js.map +1 -1
- package/out/zero-protocol/src/poke.js +53 -59
- package/out/zero-protocol/src/poke.js.map +1 -1
- package/out/zero-protocol/src/pong.js +8 -9
- package/out/zero-protocol/src/pong.js.map +1 -1
- package/out/zero-protocol/src/primary-key.js +9 -19
- package/out/zero-protocol/src/primary-key.js.map +1 -1
- package/out/zero-protocol/src/protocol-version.js +5 -11
- package/out/zero-protocol/src/protocol-version.js.map +1 -1
- package/out/zero-protocol/src/pull.js +16 -28
- package/out/zero-protocol/src/pull.js.map +1 -1
- package/out/zero-protocol/src/push.js +162 -209
- package/out/zero-protocol/src/push.js.map +1 -1
- package/out/zero-protocol/src/queries-patch.js +22 -30
- package/out/zero-protocol/src/queries-patch.js.map +1 -1
- package/out/zero-protocol/src/query-hash.js +14 -17
- package/out/zero-protocol/src/query-hash.js.map +1 -1
- package/out/zero-protocol/src/row-patch.js +23 -30
- package/out/zero-protocol/src/row-patch.js.map +1 -1
- package/out/zero-protocol/src/up.js +11 -22
- package/out/zero-protocol/src/up.js.map +1 -1
- package/out/zero-protocol/src/update-auth.js +8 -13
- package/out/zero-protocol/src/update-auth.js.map +1 -1
- package/out/zero-protocol/src/version.js +8 -9
- package/out/zero-protocol/src/version.js.map +1 -1
- package/out/zero-react/src/bindings.js +12 -0
- package/out/zero-react/src/mod.js +5 -0
- package/out/zero-react/src/use-connection-state.js +14 -11
- package/out/zero-react/src/use-connection-state.js.map +1 -1
- package/out/zero-react/src/use-query.js +283 -281
- package/out/zero-react/src/use-query.js.map +1 -1
- package/out/zero-react/src/use-zero-online.js +17 -11
- package/out/zero-react/src/use-zero-online.js.map +1 -1
- package/out/zero-react/src/zero-provider.js +53 -69
- package/out/zero-react/src/zero-provider.js.map +1 -1
- package/out/zero-react/src/zero.js +22 -0
- package/out/zero-schema/src/builder/relationship-builder.js +25 -21
- package/out/zero-schema/src/builder/relationship-builder.js.map +1 -1
- package/out/zero-schema/src/builder/schema-builder.js +51 -79
- package/out/zero-schema/src/builder/schema-builder.js.map +1 -1
- package/out/zero-schema/src/builder/table-builder.js +99 -116
- package/out/zero-schema/src/builder/table-builder.js.map +1 -1
- package/out/zero-schema/src/compiled-permissions.js +21 -25
- package/out/zero-schema/src/compiled-permissions.js.map +1 -1
- package/out/zero-schema/src/name-mapper.js +31 -47
- package/out/zero-schema/src/name-mapper.js.map +1 -1
- package/out/zero-schema/src/permissions.js +94 -181
- package/out/zero-schema/src/permissions.js.map +1 -1
- package/out/zero-schema/src/schema-config.js +26 -32
- package/out/zero-schema/src/schema-config.js.map +1 -1
- package/out/zero-server/src/adapters/drizzle.d.ts.map +1 -1
- package/out/zero-server/src/adapters/drizzle.js +79 -76
- package/out/zero-server/src/adapters/drizzle.js.map +1 -1
- package/out/zero-server/src/adapters/pg.d.ts.map +1 -1
- package/out/zero-server/src/adapters/pg.js +79 -55
- package/out/zero-server/src/adapters/pg.js.map +1 -1
- package/out/zero-server/src/adapters/postgresjs.d.ts.map +1 -1
- package/out/zero-server/src/adapters/postgresjs.js +66 -40
- package/out/zero-server/src/adapters/postgresjs.js.map +1 -1
- package/out/zero-server/src/adapters/prisma.d.ts.map +1 -1
- package/out/zero-server/src/adapters/prisma.js +75 -55
- package/out/zero-server/src/adapters/prisma.js.map +1 -1
- package/out/zero-server/src/custom.d.ts.map +1 -1
- package/out/zero-server/src/custom.js +188 -265
- package/out/zero-server/src/custom.js.map +1 -1
- package/out/zero-server/src/logging.js +6 -5
- package/out/zero-server/src/logging.js.map +1 -1
- package/out/zero-server/src/mod.js +8 -0
- package/out/zero-server/src/pg-query-executor.js +14 -17
- package/out/zero-server/src/pg-query-executor.js.map +1 -1
- package/out/zero-server/src/process-mutations.js +293 -365
- package/out/zero-server/src/process-mutations.js.map +1 -1
- package/out/zero-server/src/push-processor.js +33 -49
- package/out/zero-server/src/push-processor.js.map +1 -1
- package/out/zero-server/src/queries/process-queries.js +106 -96
- package/out/zero-server/src/queries/process-queries.js.map +1 -1
- package/out/zero-server/src/schema.js +98 -144
- package/out/zero-server/src/schema.js.map +1 -1
- package/out/zero-server/src/zql-database.d.ts.map +1 -1
- package/out/zero-server/src/zql-database.js +54 -69
- package/out/zero-server/src/zql-database.js.map +1 -1
- package/out/zero-solid/src/bindings.js +12 -0
- package/out/zero-solid/src/mod.js +5 -0
- package/out/zero-solid/src/solid-view.js +135 -227
- package/out/zero-solid/src/solid-view.js.map +1 -1
- package/out/zero-solid/src/use-connection-state.js +18 -14
- package/out/zero-solid/src/use-connection-state.js.map +1 -1
- package/out/zero-solid/src/use-query.js +55 -100
- package/out/zero-solid/src/use-query.js.map +1 -1
- package/out/zero-solid/src/use-zero-online.js +18 -12
- package/out/zero-solid/src/use-zero-online.js.map +1 -1
- package/out/zero-solid/src/use-zero.js +65 -77
- package/out/zero-solid/src/use-zero.js.map +1 -1
- package/out/zero-solid/src/zero.js +22 -0
- package/out/zero-types/src/format.js +8 -7
- package/out/zero-types/src/format.js.map +1 -1
- package/out/zero-types/src/name-mapper.js +34 -47
- package/out/zero-types/src/name-mapper.js.map +1 -1
- package/out/zql/src/builder/builder.d.ts.map +1 -1
- package/out/zql/src/builder/builder.js +315 -476
- package/out/zql/src/builder/builder.js.map +1 -1
- package/out/zql/src/builder/debug-delegate.js +69 -74
- package/out/zql/src/builder/debug-delegate.js.map +1 -1
- package/out/zql/src/builder/filter.js +116 -140
- package/out/zql/src/builder/filter.js.map +1 -1
- package/out/zql/src/builder/like.js +41 -46
- package/out/zql/src/builder/like.js.map +1 -1
- package/out/zql/src/error.js +10 -9
- package/out/zql/src/error.js.map +1 -1
- package/out/zql/src/ivm/array-view.js +89 -91
- package/out/zql/src/ivm/array-view.js.map +1 -1
- package/out/zql/src/ivm/constraint.js +65 -74
- package/out/zql/src/ivm/constraint.js.map +1 -1
- package/out/zql/src/ivm/data.js +61 -48
- package/out/zql/src/ivm/data.js.map +1 -1
- package/out/zql/src/ivm/exists.js +164 -213
- package/out/zql/src/ivm/exists.js.map +1 -1
- package/out/zql/src/ivm/fan-in.js +62 -59
- package/out/zql/src/ivm/fan-in.js.map +1 -1
- package/out/zql/src/ivm/fan-out.js +52 -61
- package/out/zql/src/ivm/fan-out.js.map +1 -1
- package/out/zql/src/ivm/filter-operators.js +91 -96
- package/out/zql/src/ivm/filter-operators.js.map +1 -1
- package/out/zql/src/ivm/filter-push.js +22 -26
- package/out/zql/src/ivm/filter-push.js.map +1 -1
- package/out/zql/src/ivm/filter.js +41 -35
- package/out/zql/src/ivm/filter.js.map +1 -1
- package/out/zql/src/ivm/flipped-join.js +282 -391
- package/out/zql/src/ivm/flipped-join.js.map +1 -1
- package/out/zql/src/ivm/join-utils.js +85 -115
- package/out/zql/src/ivm/join-utils.js.map +1 -1
- package/out/zql/src/ivm/join.js +162 -231
- package/out/zql/src/ivm/join.js.map +1 -1
- package/out/zql/src/ivm/maybe-split-and-push-edit-change.js +21 -25
- package/out/zql/src/ivm/maybe-split-and-push-edit-change.js.map +1 -1
- package/out/zql/src/ivm/memory-source.js +364 -503
- package/out/zql/src/ivm/memory-source.js.map +1 -1
- package/out/zql/src/ivm/memory-storage.js +33 -34
- package/out/zql/src/ivm/memory-storage.js.map +1 -1
- package/out/zql/src/ivm/operator.js +13 -15
- package/out/zql/src/ivm/operator.js.map +1 -1
- package/out/zql/src/ivm/push-accumulated.js +267 -270
- package/out/zql/src/ivm/push-accumulated.js.map +1 -1
- package/out/zql/src/ivm/skip.js +91 -104
- package/out/zql/src/ivm/skip.js.map +1 -1
- package/out/zql/src/ivm/stream.js +10 -10
- package/out/zql/src/ivm/stream.js.map +1 -1
- package/out/zql/src/ivm/take.js +422 -569
- package/out/zql/src/ivm/take.js.map +1 -1
- package/out/zql/src/ivm/union-fan-in.js +157 -231
- package/out/zql/src/ivm/union-fan-in.js.map +1 -1
- package/out/zql/src/ivm/union-fan-out.js +38 -43
- package/out/zql/src/ivm/union-fan-out.js.map +1 -1
- package/out/zql/src/ivm/view-apply-change.js +166 -255
- package/out/zql/src/ivm/view-apply-change.js.map +1 -1
- package/out/zql/src/mutate/crud.js +35 -34
- package/out/zql/src/mutate/crud.js.map +1 -1
- package/out/zql/src/mutate/custom.d.ts.map +1 -1
- package/out/zql/src/mutate/custom.js +7 -11
- package/out/zql/src/mutate/custom.js.map +1 -1
- package/out/zql/src/mutate/mutator-registry.js +67 -71
- package/out/zql/src/mutate/mutator-registry.js.map +1 -1
- package/out/zql/src/mutate/mutator.js +26 -25
- package/out/zql/src/mutate/mutator.js.map +1 -1
- package/out/zql/src/planner/planner-builder.js +134 -239
- package/out/zql/src/planner/planner-builder.js.map +1 -1
- package/out/zql/src/planner/planner-connection.js +222 -212
- package/out/zql/src/planner/planner-connection.js.map +1 -1
- package/out/zql/src/planner/planner-constraint.js +15 -7
- package/out/zql/src/planner/planner-constraint.js.map +1 -1
- package/out/zql/src/planner/planner-debug.js +199 -224
- package/out/zql/src/planner/planner-debug.js.map +1 -1
- package/out/zql/src/planner/planner-fan-in.js +146 -162
- package/out/zql/src/planner/planner-fan-in.js.map +1 -1
- package/out/zql/src/planner/planner-fan-out.js +62 -74
- package/out/zql/src/planner/planner-fan-out.js.map +1 -1
- package/out/zql/src/planner/planner-graph.js +302 -334
- package/out/zql/src/planner/planner-graph.js.map +1 -1
- package/out/zql/src/planner/planner-join.js +255 -240
- package/out/zql/src/planner/planner-join.js.map +1 -1
- package/out/zql/src/planner/planner-node.js +10 -6
- package/out/zql/src/planner/planner-node.js.map +1 -1
- package/out/zql/src/planner/planner-source.js +15 -22
- package/out/zql/src/planner/planner-source.js.map +1 -1
- package/out/zql/src/planner/planner-terminus.js +28 -28
- package/out/zql/src/planner/planner-terminus.js.map +1 -1
- package/out/zql/src/query/complete-ordering.js +37 -61
- package/out/zql/src/query/complete-ordering.js.map +1 -1
- package/out/zql/src/query/create-builder.js +14 -22
- package/out/zql/src/query/create-builder.js.map +1 -1
- package/out/zql/src/query/error.js +10 -12
- package/out/zql/src/query/error.js.map +1 -1
- package/out/zql/src/query/escape-like.js +6 -5
- package/out/zql/src/query/escape-like.js.map +1 -1
- package/out/zql/src/query/expression.js +138 -157
- package/out/zql/src/query/expression.js.map +1 -1
- package/out/zql/src/query/measure-push-operator.js +35 -38
- package/out/zql/src/query/measure-push-operator.js.map +1 -1
- package/out/zql/src/query/metrics-delegate.js +7 -7
- package/out/zql/src/query/metrics-delegate.js.map +1 -1
- package/out/zql/src/query/named.js +52 -51
- package/out/zql/src/query/named.js.map +1 -1
- package/out/zql/src/query/query-delegate-base.js +190 -238
- package/out/zql/src/query/query-delegate-base.js.map +1 -1
- package/out/zql/src/query/query-impl.d.ts.map +1 -1
- package/out/zql/src/query/query-impl.js +271 -405
- package/out/zql/src/query/query-impl.js.map +1 -1
- package/out/zql/src/query/query-internals.js +16 -8
- package/out/zql/src/query/query-internals.js.map +1 -1
- package/out/zql/src/query/query-registry.js +83 -98
- package/out/zql/src/query/query-registry.js.map +1 -1
- package/out/zql/src/query/query.d.ts.map +1 -1
- package/out/zql/src/query/query.js +2 -0
- package/out/zql/src/query/runnable-query-impl.d.ts.map +1 -1
- package/out/zql/src/query/runnable-query-impl.js +30 -55
- package/out/zql/src/query/runnable-query-impl.js.map +1 -1
- package/out/zql/src/query/static-query.js +7 -14
- package/out/zql/src/query/static-query.js.map +1 -1
- package/out/zql/src/query/ttl.js +45 -67
- package/out/zql/src/query/ttl.js.map +1 -1
- package/out/zql/src/query/validate-input.js +23 -20
- package/out/zql/src/query/validate-input.js.map +1 -1
- package/out/zqlite/src/database-storage.js +99 -103
- package/out/zqlite/src/database-storage.js.map +1 -1
- package/out/zqlite/src/db.js +206 -249
- package/out/zqlite/src/db.js.map +1 -1
- package/out/zqlite/src/explain-queries.js +11 -13
- package/out/zqlite/src/explain-queries.js.map +1 -1
- package/out/zqlite/src/internal/sql-inline.js +54 -37
- package/out/zqlite/src/internal/sql-inline.js.map +1 -1
- package/out/zqlite/src/internal/sql.js +17 -15
- package/out/zqlite/src/internal/sql.js.map +1 -1
- package/out/zqlite/src/internal/statement-cache.js +117 -92
- package/out/zqlite/src/internal/statement-cache.js.map +1 -1
- package/out/zqlite/src/mod.js +5 -0
- package/out/zqlite/src/query-builder.js +81 -172
- package/out/zqlite/src/query-builder.js.map +1 -1
- package/out/zqlite/src/query-delegate.js +45 -55
- package/out/zqlite/src/query-delegate.js.map +1 -1
- package/out/zqlite/src/resolve-scalar-subqueries.js +134 -124
- package/out/zqlite/src/resolve-scalar-subqueries.js.map +1 -1
- package/out/zqlite/src/sqlite-cost-model.js +92 -97
- package/out/zqlite/src/sqlite-cost-model.js.map +1 -1
- package/out/zqlite/src/sqlite-stat-fanout.js +304 -286
- package/out/zqlite/src/sqlite-stat-fanout.js.map +1 -1
- package/out/zqlite/src/table-source.js +281 -455
- package/out/zqlite/src/table-source.js.map +1 -1
- package/package.json +8 -7
- package/out/replicache/src/db/index-operation-enum.js +0 -7
- package/out/replicache/src/db/index-operation-enum.js.map +0 -1
- package/out/replicache/src/db/meta-type-enum.js +0 -7
- package/out/replicache/src/db/meta-type-enum.js.map +0 -1
- package/out/replicache/src/format-version-enum.js +0 -11
- package/out/replicache/src/format-version-enum.js.map +0 -1
- package/out/replicache/src/http-status-unauthorized.js +0 -5
- package/out/replicache/src/http-status-unauthorized.js.map +0 -1
- package/out/replicache/src/invoke-kind-enum.js +0 -7
- package/out/replicache/src/invoke-kind-enum.js.map +0 -1
- package/out/replicache/src/sync/handle-pull-response-result-type-enum.js +0 -9
- package/out/replicache/src/sync/handle-pull-response-result-type-enum.js.map +0 -1
- package/out/zero/package.json.js +0 -9
- package/out/zero/package.json.js.map +0 -1
- package/out/zero/src/adapters/drizzle.js.map +0 -1
- package/out/zero/src/adapters/pg.js.map +0 -1
- package/out/zero/src/adapters/postgresjs.js.map +0 -1
- package/out/zero/src/adapters/prisma.js.map +0 -1
- package/out/zero/src/analyze-query.js.map +0 -1
- package/out/zero/src/ast-to-zql.js.map +0 -1
- package/out/zero/src/bindings.js.map +0 -1
- package/out/zero/src/change-protocol/v0.js.map +0 -1
- package/out/zero/src/cli.js.map +0 -1
- package/out/zero/src/deploy-permissions.js.map +0 -1
- package/out/zero/src/expo-sqlite.js.map +0 -1
- package/out/zero/src/op-sqlite.js.map +0 -1
- package/out/zero/src/pg.js.map +0 -1
- package/out/zero/src/react.js.map +0 -1
- package/out/zero/src/server.js.map +0 -1
- package/out/zero/src/solid.js.map +0 -1
- package/out/zero/src/sqlite.js.map +0 -1
- package/out/zero/src/transform-query.js.map +0 -1
- package/out/zero/src/zero.js.map +0 -1
- package/out/zero/src/zqlite.js.map +0 -1
- package/out/zero-cache/src/db/postgres-replica-identity-enum.js +0 -11
- package/out/zero-cache/src/db/postgres-replica-identity-enum.js.map +0 -1
- package/out/zero-cache/src/db/postgres-type-class-enum.js +0 -17
- package/out/zero-cache/src/db/postgres-type-class-enum.js.map +0 -1
- package/out/zero-cache/src/services/change-streamer/error-type-enum.js +0 -9
- package/out/zero-cache/src/services/change-streamer/error-type-enum.js.map +0 -1
|
@@ -1,1627 +1,1091 @@
|
|
|
1
|
-
import { Lock } from "@rocicorp/lock";
|
|
2
|
-
import { resolver } from "@rocicorp/resolver";
|
|
3
|
-
import { startSpan, startAsyncSpan, manualSpan } from "../../../../otel/src/span.js";
|
|
4
1
|
import { assert, unreachable } from "../../../../shared/src/asserts.js";
|
|
5
|
-
import { stringify } from "../../../../shared/src/bigint-json.js";
|
|
6
|
-
import { CustomKeyMap } from "../../../../shared/src/custom-key-map.js";
|
|
7
2
|
import { must } from "../../../../shared/src/must.js";
|
|
8
|
-
import {
|
|
9
|
-
import { Rehome, InvalidConnectionRequest, TransformFailed, InvalidConnectionRequestBaseCookie } from "../../../../zero-protocol/src/error-kind-enum.js";
|
|
3
|
+
import { InvalidConnectionRequest, InvalidConnectionRequestBaseCookie, Rehome } from "../../../../zero-protocol/src/error-kind-enum.js";
|
|
10
4
|
import { ZeroCache } from "../../../../zero-protocol/src/error-origin-enum.js";
|
|
11
|
-
import
|
|
5
|
+
import "../../../../zero-protocol/src/error-reason-enum.js";
|
|
12
6
|
import { ProtocolError, isProtocolError } from "../../../../zero-protocol/src/error.js";
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
15
|
-
import {
|
|
16
|
-
import {
|
|
7
|
+
import { MAX_TTL_MS, clampTTL } from "../../../../zql/src/query/ttl.js";
|
|
8
|
+
import { stringify } from "../../../../shared/src/bigint-json.js";
|
|
9
|
+
import { manualSpan, startAsyncSpan, startSpan } from "../../../../otel/src/span.js";
|
|
10
|
+
import { randInt } from "../../../../shared/src/rand.js";
|
|
17
11
|
import { rowIDString } from "../../types/row-key.js";
|
|
18
|
-
import {
|
|
12
|
+
import { ZERO_VERSION_COLUMN_NAME } from "../replicator/schema/constants.js";
|
|
19
13
|
import "../replicator/schema/replication-state.js";
|
|
14
|
+
import { transformAndHashQuery } from "../../auth/read-authorizer.js";
|
|
15
|
+
import { getOrCreateCounter, getOrCreateHistogram, getOrCreateUpDownCounter } from "../../observability/metrics.js";
|
|
16
|
+
import { ResetPipelinesSignal } from "./snapshotter.js";
|
|
17
|
+
import "./pipeline-driver.js";
|
|
18
|
+
import { Subscription } from "../../types/subscription.js";
|
|
19
|
+
import { CustomKeyMap } from "../../../../shared/src/custom-key-map.js";
|
|
20
|
+
import { ttlClockAsNumber, ttlClockFromNumber } from "./ttl-clock.js";
|
|
21
|
+
import { EMPTY_CVR_VERSION, cmpVersions, versionFromString, versionString, versionToCookie } from "./schema/types.js";
|
|
22
|
+
import { ProtocolErrorWithLevel, getLogLevel } from "../../types/error-with-level.js";
|
|
20
23
|
import { ClientHandler, startPoke } from "./client-handler.js";
|
|
21
24
|
import { CVRStore, ClientNotFoundError } from "./cvr-store.js";
|
|
22
|
-
import { CVRConfigDrivenUpdater, nextEvictionTime, CVRQueryDrivenUpdater } from "./cvr.js";
|
|
23
|
-
import { handleInspect } from "./inspect-handler.js";
|
|
24
|
-
import "../../../../shared/src/config.js";
|
|
25
|
-
import "compare-utf8";
|
|
26
|
-
import "../../../../zero-protocol/src/ast.js";
|
|
27
|
-
import "../../../../zero-protocol/src/data.js";
|
|
28
|
-
import "@rocicorp/zero-sqlite3";
|
|
29
|
-
import "../../../../zqlite/src/internal/sql.js";
|
|
30
|
-
import "@databases/escape-identifier";
|
|
31
|
-
import "../../../../shared/src/btree-set.js";
|
|
32
|
-
import "../../../../shared/src/iterables.js";
|
|
33
|
-
import "../../../../shared/src/valita.js";
|
|
34
|
-
import "../../../../zero-schema/src/compiled-permissions.js";
|
|
35
|
-
import "../../../../zero-protocol/src/primary-key.js";
|
|
36
|
-
import { ZERO_VERSION_COLUMN_NAME } from "../replicator/schema/constants.js";
|
|
37
|
-
import "../../types/pg-data-type.js";
|
|
38
|
-
import "../../db/specs.js";
|
|
39
|
-
import { ResetPipelinesSignal } from "./snapshotter.js";
|
|
40
|
-
import { versionString, cmpVersions, EMPTY_CVR_VERSION, versionToCookie, versionFromString } from "./schema/types.js";
|
|
41
25
|
import { tracer } from "./tracer.js";
|
|
42
|
-
import {
|
|
43
|
-
|
|
44
|
-
|
|
26
|
+
import { CVRConfigDrivenUpdater, CVRQueryDrivenUpdater, nextEvictionTime } from "./cvr.js";
|
|
27
|
+
import { handleInspect } from "./inspect-handler.js";
|
|
28
|
+
import { resolver } from "@rocicorp/resolver";
|
|
29
|
+
import { Lock } from "@rocicorp/lock";
|
|
30
|
+
//#region ../zero-cache/src/services/view-syncer/view-syncer.ts
|
|
31
|
+
var PROTOCOL_VERSION_ATTR = "protocol.version";
|
|
32
|
+
var DEFAULT_KEEPALIVE_MS = 5e3;
|
|
45
33
|
function randomID() {
|
|
46
|
-
|
|
34
|
+
return randInt(1, Number.MAX_SAFE_INTEGER).toString(36);
|
|
47
35
|
}
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
* If queries are added, removed, or queried due to a new state version,
|
|
1011
|
-
* a new CVR version is created and pokes sent to connected clients.
|
|
1012
|
-
*
|
|
1013
|
-
* This must be called from within the #lock.
|
|
1014
|
-
*/
|
|
1015
|
-
#syncQueryPipelineSet(lc, cvr, customQueryTransformMode) {
|
|
1016
|
-
return startAsyncSpan(tracer, "vs.#syncQueryPipelineSet", async () => {
|
|
1017
|
-
assert(
|
|
1018
|
-
this.#pipelines.initialized(),
|
|
1019
|
-
"pipelines must be initialized (syncQueryPipelineSet)"
|
|
1020
|
-
);
|
|
1021
|
-
if (this.#ttlClock === void 0) {
|
|
1022
|
-
this.#ttlClock = cvr.ttlClock;
|
|
1023
|
-
}
|
|
1024
|
-
const now = Date.now();
|
|
1025
|
-
const ttlClock = this.#getTTLClock(now);
|
|
1026
|
-
const cvrQueryEntires = Object.entries(cvr.queries);
|
|
1027
|
-
const customQueries = /* @__PURE__ */ new Map();
|
|
1028
|
-
const otherQueries = [];
|
|
1029
|
-
const transformedQueries = [];
|
|
1030
|
-
for (const [id, query] of cvrQueryEntires) {
|
|
1031
|
-
if (query.type === "custom") {
|
|
1032
|
-
assert(id === query.id, "custom query id mismatch");
|
|
1033
|
-
customQueries.set(id, query);
|
|
1034
|
-
} else {
|
|
1035
|
-
otherQueries.push({ id, query });
|
|
1036
|
-
}
|
|
1037
|
-
}
|
|
1038
|
-
for (const { id, query: origQuery } of otherQueries) {
|
|
1039
|
-
assert(id === origQuery.id, "query id mismatch");
|
|
1040
|
-
const auth = this.#authSession.auth;
|
|
1041
|
-
const transformed = transformAndHashQuery(
|
|
1042
|
-
lc,
|
|
1043
|
-
origQuery.id,
|
|
1044
|
-
origQuery.ast,
|
|
1045
|
-
must(this.#pipelines.currentPermissions()).permissions ?? {
|
|
1046
|
-
tables: {}
|
|
1047
|
-
},
|
|
1048
|
-
auth?.type === "jwt" ? auth : void 0,
|
|
1049
|
-
origQuery.type === "internal"
|
|
1050
|
-
);
|
|
1051
|
-
transformedQueries.push({
|
|
1052
|
-
id,
|
|
1053
|
-
origQuery,
|
|
1054
|
-
transformed
|
|
1055
|
-
});
|
|
1056
|
-
}
|
|
1057
|
-
if (customQueries.size > 0 && !this.#customQueryTransformer) {
|
|
1058
|
-
lc.warn?.(
|
|
1059
|
-
"Custom/named queries were requested but no `ZERO_QUERY_URL` is configured for Zero Cache."
|
|
1060
|
-
);
|
|
1061
|
-
}
|
|
1062
|
-
let erroredQueryIDs;
|
|
1063
|
-
const customQueriesToTransform = customQueryTransformMode === "all" ? [...customQueries.values()] : customQueryTransformMode && [...customQueries.values()].filter(
|
|
1064
|
-
(q) => !this.#pipelines.queries().has(q.id)
|
|
1065
|
-
);
|
|
1066
|
-
const customQueryTransformer = this.#customQueryTransformer;
|
|
1067
|
-
if (customQueryTransformer && customQueriesToTransform.length > 0) {
|
|
1068
|
-
const transformStart = performance.now();
|
|
1069
|
-
let transformedCustomQueries;
|
|
1070
|
-
try {
|
|
1071
|
-
transformedCustomQueries = await this.#runPriorityOp(
|
|
1072
|
-
lc,
|
|
1073
|
-
"#syncQueryPipelineSet transforming custom queries",
|
|
1074
|
-
() => customQueryTransformer.transform(
|
|
1075
|
-
this.#getHeaderOptions(true),
|
|
1076
|
-
customQueriesToTransform,
|
|
1077
|
-
this.userQueryURL
|
|
1078
|
-
)
|
|
1079
|
-
);
|
|
1080
|
-
if (!Array.isArray(transformedCustomQueries) && transformedCustomQueries.kind === TransformFailed) {
|
|
1081
|
-
throw new ProtocolErrorWithLevel(transformedCustomQueries, "warn");
|
|
1082
|
-
} else {
|
|
1083
|
-
this.#queryTransformations.add(1, { result: "success" });
|
|
1084
|
-
}
|
|
1085
|
-
} catch (e) {
|
|
1086
|
-
this.#queryTransformations.add(1, { result: "error" });
|
|
1087
|
-
throw e;
|
|
1088
|
-
} finally {
|
|
1089
|
-
const transformDuration = (performance.now() - transformStart) / 1e3;
|
|
1090
|
-
this.#queryTransformationTime.record(transformDuration);
|
|
1091
|
-
}
|
|
1092
|
-
const successfullyTransformedCustomQueries = /* @__PURE__ */ new Map();
|
|
1093
|
-
erroredQueryIDs = this.#processTransformedCustomQueries(
|
|
1094
|
-
lc,
|
|
1095
|
-
transformedCustomQueries,
|
|
1096
|
-
(q) => {
|
|
1097
|
-
const origQuery = customQueries.get(q.id);
|
|
1098
|
-
if (origQuery) {
|
|
1099
|
-
successfullyTransformedCustomQueries.set(q.id, q);
|
|
1100
|
-
transformedQueries.push({
|
|
1101
|
-
id: q.id,
|
|
1102
|
-
origQuery,
|
|
1103
|
-
transformed: q
|
|
1104
|
-
});
|
|
1105
|
-
}
|
|
1106
|
-
},
|
|
1107
|
-
customQueries
|
|
1108
|
-
);
|
|
1109
|
-
for (const [
|
|
1110
|
-
queryID,
|
|
1111
|
-
newTransform
|
|
1112
|
-
] of successfullyTransformedCustomQueries) {
|
|
1113
|
-
const existingTransformHash = cvr.queries[queryID]?.transformationHash;
|
|
1114
|
-
if (existingTransformHash) {
|
|
1115
|
-
const oldHash = existingTransformHash;
|
|
1116
|
-
const newHash = newTransform.transformationHash;
|
|
1117
|
-
if (oldHash !== newHash) {
|
|
1118
|
-
lc.info?.(
|
|
1119
|
-
`Query ${queryID} transformation changed: ${oldHash} -> ${newHash}`
|
|
1120
|
-
);
|
|
1121
|
-
this.#checkForThrashing(queryID);
|
|
1122
|
-
this.#queryTransformationHashChanges.add(1);
|
|
1123
|
-
} else {
|
|
1124
|
-
this.#queryTransformationNoOps.add(1);
|
|
1125
|
-
}
|
|
1126
|
-
}
|
|
1127
|
-
}
|
|
1128
|
-
}
|
|
1129
|
-
const removeQueriesQueryIds = new Set(
|
|
1130
|
-
Object.values(cvr.queries).filter((q) => expired(ttlClock, q)).map((q) => q.id).concat(erroredQueryIDs || [])
|
|
1131
|
-
);
|
|
1132
|
-
const addQueries = transformedQueries.map(({ id, transformed }) => ({
|
|
1133
|
-
id,
|
|
1134
|
-
ast: transformed.transformedAst,
|
|
1135
|
-
transformationHash: transformed.transformationHash
|
|
1136
|
-
})).filter(
|
|
1137
|
-
(q) => !removeQueriesQueryIds.has(q.id) && this.#pipelines.queries().get(q.id)?.transformationHash !== q.transformationHash
|
|
1138
|
-
);
|
|
1139
|
-
for (const q of addQueries) {
|
|
1140
|
-
const orig = cvr.queries[q.id];
|
|
1141
|
-
lc.debug?.(
|
|
1142
|
-
"ViewSyncer adding query",
|
|
1143
|
-
q.ast,
|
|
1144
|
-
"transformed from",
|
|
1145
|
-
orig.type === "custom" ? orig.name : orig.ast
|
|
1146
|
-
);
|
|
1147
|
-
}
|
|
1148
|
-
if (addQueries.length > 0 || removeQueriesQueryIds.size > 0) {
|
|
1149
|
-
await this.#addAndRemoveQueries(
|
|
1150
|
-
lc,
|
|
1151
|
-
cvr,
|
|
1152
|
-
addQueries,
|
|
1153
|
-
[...removeQueriesQueryIds].map((id) => ({ id }))
|
|
1154
|
-
);
|
|
1155
|
-
} else {
|
|
1156
|
-
await this.#catchupClients(lc, cvr);
|
|
1157
|
-
}
|
|
1158
|
-
});
|
|
1159
|
-
}
|
|
1160
|
-
/**
|
|
1161
|
-
* Check if a query is being replaced too frequently (thrashing).
|
|
1162
|
-
* Logs a warning if the query has been replaced more than 3 times in 60 seconds.
|
|
1163
|
-
*/
|
|
1164
|
-
#checkForThrashing(queryID) {
|
|
1165
|
-
const THRASH_WINDOW_MS = 6e4;
|
|
1166
|
-
const THRASH_THRESHOLD = 3;
|
|
1167
|
-
const now = Date.now();
|
|
1168
|
-
let record = this.#queryReplacements.get(queryID);
|
|
1169
|
-
if (!record) {
|
|
1170
|
-
record = { count: 1, windowStart: now };
|
|
1171
|
-
this.#queryReplacements.set(queryID, record);
|
|
1172
|
-
return;
|
|
1173
|
-
}
|
|
1174
|
-
if (now - record.windowStart > THRASH_WINDOW_MS) {
|
|
1175
|
-
this.#queryReplacements.delete(queryID);
|
|
1176
|
-
this.#queryReplacements.set(queryID, { count: 1, windowStart: now });
|
|
1177
|
-
return;
|
|
1178
|
-
}
|
|
1179
|
-
record.count++;
|
|
1180
|
-
if (record.count >= THRASH_THRESHOLD) {
|
|
1181
|
-
this.#lc.warn?.(
|
|
1182
|
-
`Query thrashing detected for query ${queryID}. ${record.count} replacements in 60s. This may indicate clients with different auth contexts connecting to the same client group.`
|
|
1183
|
-
);
|
|
1184
|
-
}
|
|
1185
|
-
}
|
|
1186
|
-
// This must be called from within the #lock.
|
|
1187
|
-
#addAndRemoveQueries(lc, cvr, addQueries, removeQueries) {
|
|
1188
|
-
return startAsyncSpan(tracer, "vs.#addAndRemoveQueries", async () => {
|
|
1189
|
-
assert(
|
|
1190
|
-
addQueries.length > 0 || removeQueries.length > 0,
|
|
1191
|
-
"Must have queries to add or remove"
|
|
1192
|
-
);
|
|
1193
|
-
const start = performance.now();
|
|
1194
|
-
const stateVersion = this.#pipelines.currentVersion();
|
|
1195
|
-
lc = lc.withContext("stateVersion", stateVersion);
|
|
1196
|
-
lc.info?.(`hydrating ${addQueries.length} queries`);
|
|
1197
|
-
const updater = new CVRQueryDrivenUpdater(
|
|
1198
|
-
this.#cvrStore,
|
|
1199
|
-
cvr,
|
|
1200
|
-
stateVersion,
|
|
1201
|
-
this.#pipelines.replicaVersion
|
|
1202
|
-
);
|
|
1203
|
-
const { newVersion, queryPatches } = updater.trackQueries(
|
|
1204
|
-
lc,
|
|
1205
|
-
addQueries,
|
|
1206
|
-
removeQueries
|
|
1207
|
-
);
|
|
1208
|
-
const clients = this.#getClients();
|
|
1209
|
-
const pokers = startPoke(clients, newVersion);
|
|
1210
|
-
for (const patch of queryPatches) {
|
|
1211
|
-
await pokers.addPatch(patch);
|
|
1212
|
-
}
|
|
1213
|
-
for (const q of removeQueries) {
|
|
1214
|
-
this.#pipelines.removeQuery(q.id);
|
|
1215
|
-
this.#inspectorDelegate.removeQuery(q.id);
|
|
1216
|
-
this.#queryReplacements.delete(q.id);
|
|
1217
|
-
}
|
|
1218
|
-
let totalProcessTime = 0;
|
|
1219
|
-
const timer = new TimeSliceTimer(lc);
|
|
1220
|
-
const pipelines = this.#pipelines;
|
|
1221
|
-
const hydrations = this.#hydrations;
|
|
1222
|
-
const hydrationTime = this.#hydrationTime;
|
|
1223
|
-
const self = this;
|
|
1224
|
-
await yieldProcess(lc);
|
|
1225
|
-
function* generateRowChanges(slowHydrateThreshold) {
|
|
1226
|
-
for (const q of addQueries) {
|
|
1227
|
-
lc = lc.withContext("hash", q.id).withContext("transformationHash", q.transformationHash);
|
|
1228
|
-
lc.debug?.(`adding pipeline for query`, q.ast);
|
|
1229
|
-
yield* pipelines.addQuery(
|
|
1230
|
-
q.transformationHash,
|
|
1231
|
-
q.id,
|
|
1232
|
-
q.ast,
|
|
1233
|
-
timer.startWithoutYielding()
|
|
1234
|
-
);
|
|
1235
|
-
const elapsed = timer.stop();
|
|
1236
|
-
totalProcessTime += elapsed;
|
|
1237
|
-
self.#addQueryMaterializationServerMetric(q.id, elapsed);
|
|
1238
|
-
if (elapsed > slowHydrateThreshold) {
|
|
1239
|
-
lc.warn?.("Slow query materialization", elapsed, q.ast);
|
|
1240
|
-
}
|
|
1241
|
-
manualSpan(tracer, "vs.addAndConsumeQuery", elapsed, {
|
|
1242
|
-
hash: q.id,
|
|
1243
|
-
transformationHash: q.transformationHash
|
|
1244
|
-
});
|
|
1245
|
-
}
|
|
1246
|
-
hydrations.add(1);
|
|
1247
|
-
hydrationTime.record(totalProcessTime / 1e3);
|
|
1248
|
-
}
|
|
1249
|
-
await this.#processChanges(
|
|
1250
|
-
lc,
|
|
1251
|
-
timer,
|
|
1252
|
-
generateRowChanges(this.#slowHydrateThreshold),
|
|
1253
|
-
updater,
|
|
1254
|
-
pokers
|
|
1255
|
-
);
|
|
1256
|
-
for (const patch of await updater.deleteUnreferencedRows(lc)) {
|
|
1257
|
-
await pokers.addPatch(patch);
|
|
1258
|
-
}
|
|
1259
|
-
this.#cvr = await this.#flushUpdater(lc, updater);
|
|
1260
|
-
const finalVersion = this.#cvr.version;
|
|
1261
|
-
await this.#catchupClients(
|
|
1262
|
-
lc,
|
|
1263
|
-
cvr,
|
|
1264
|
-
finalVersion,
|
|
1265
|
-
addQueries.map((q) => q.id),
|
|
1266
|
-
pokers
|
|
1267
|
-
);
|
|
1268
|
-
await pokers.end(finalVersion);
|
|
1269
|
-
const wallTime = performance.now() - start;
|
|
1270
|
-
lc.info?.(
|
|
1271
|
-
`finished processing queries (process: ${totalProcessTime} ms, wall: ${wallTime} ms)`
|
|
1272
|
-
);
|
|
1273
|
-
});
|
|
1274
|
-
}
|
|
1275
|
-
/**
|
|
1276
|
-
* @param cvr The CVR to which clients should be caught up to. This does
|
|
1277
|
-
* not necessarily need to be the current CVR.
|
|
1278
|
-
* @param current The expected current CVR version. Before performing
|
|
1279
|
-
* catchup, the snapshot read will verify that the CVR has not been
|
|
1280
|
-
* concurrently modified. Note that this only needs to be done for
|
|
1281
|
-
* catchup because it is the only time data from the CVR DB is
|
|
1282
|
-
* "exported" without being gated by a CVR flush (which provides
|
|
1283
|
-
* concurrency protection in all other cases).
|
|
1284
|
-
*
|
|
1285
|
-
* If unspecified, the version of the `cvr` is used.
|
|
1286
|
-
* @param excludeQueryHashes Exclude patches from rows associated with
|
|
1287
|
-
* the specified queries.
|
|
1288
|
-
* @param usePokers If specified, sends pokes on existing PokeHandlers,
|
|
1289
|
-
* in which case the caller is responsible for sending the `pokeEnd`
|
|
1290
|
-
* messages. If unspecified, the pokes will be started and ended
|
|
1291
|
-
* using the version from the supplied `cvr`.
|
|
1292
|
-
*/
|
|
1293
|
-
// Must be called within #lock
|
|
1294
|
-
#catchupClients(lc, cvr, current, excludeQueryHashes = [], usePokers) {
|
|
1295
|
-
return startAsyncSpan(tracer, "vs.#catchupClients", async (span) => {
|
|
1296
|
-
current ??= cvr.version;
|
|
1297
|
-
const clients = this.#getClients();
|
|
1298
|
-
const pokers = usePokers ?? startPoke(clients, cvr.version);
|
|
1299
|
-
span.setAttribute("numClients", clients.length);
|
|
1300
|
-
const catchupFrom = clients.map((c) => c.version()).reduce((a, b) => cmpVersions(a, b) < 0 ? a : b, cvr.version);
|
|
1301
|
-
const rowPatches = this.#cvrStore.catchupRowPatches(
|
|
1302
|
-
lc,
|
|
1303
|
-
catchupFrom,
|
|
1304
|
-
cvr,
|
|
1305
|
-
current,
|
|
1306
|
-
excludeQueryHashes
|
|
1307
|
-
);
|
|
1308
|
-
const configPatches = this.#cvrStore.catchupConfigPatches(
|
|
1309
|
-
lc,
|
|
1310
|
-
catchupFrom,
|
|
1311
|
-
cvr,
|
|
1312
|
-
current
|
|
1313
|
-
);
|
|
1314
|
-
configPatches.catch(() => {
|
|
1315
|
-
});
|
|
1316
|
-
let rowPatchCount = 0;
|
|
1317
|
-
for await (const rows of rowPatches) {
|
|
1318
|
-
for (const row of rows) {
|
|
1319
|
-
const { schema, table } = row;
|
|
1320
|
-
const rowKey = row.rowKey;
|
|
1321
|
-
const toVersion = versionFromString(row.patchVersion);
|
|
1322
|
-
const id = { schema, table, rowKey };
|
|
1323
|
-
let patch;
|
|
1324
|
-
if (!row.refCounts) {
|
|
1325
|
-
patch = { type: "row", op: "del", id };
|
|
1326
|
-
} else {
|
|
1327
|
-
const row2 = must(
|
|
1328
|
-
this.#pipelines.getRow(table, rowKey),
|
|
1329
|
-
`Missing row ${table}:${stringify(rowKey)}`
|
|
1330
|
-
);
|
|
1331
|
-
const { contents } = contentsAndVersion(row2);
|
|
1332
|
-
patch = { type: "row", op: "put", id, contents };
|
|
1333
|
-
}
|
|
1334
|
-
const patchToVersion = { patch, toVersion };
|
|
1335
|
-
await pokers.addPatch(patchToVersion);
|
|
1336
|
-
rowPatchCount++;
|
|
1337
|
-
}
|
|
1338
|
-
}
|
|
1339
|
-
span.setAttribute("rowPatchCount", rowPatchCount);
|
|
1340
|
-
if (rowPatchCount) {
|
|
1341
|
-
lc.debug?.(`sent ${rowPatchCount} row patches`);
|
|
1342
|
-
}
|
|
1343
|
-
for (const patch of await configPatches) {
|
|
1344
|
-
await pokers.addPatch(patch);
|
|
1345
|
-
}
|
|
1346
|
-
if (!usePokers) {
|
|
1347
|
-
await pokers.end(cvr.version);
|
|
1348
|
-
}
|
|
1349
|
-
});
|
|
1350
|
-
}
|
|
1351
|
-
#processChanges(lc, timer, changes, updater, pokers) {
|
|
1352
|
-
return startAsyncSpan(tracer, "vs.#processChanges", async () => {
|
|
1353
|
-
const start = performance.now();
|
|
1354
|
-
const rows = new CustomKeyMap(rowIDString);
|
|
1355
|
-
let total = 0;
|
|
1356
|
-
const processBatch = () => startAsyncSpan(tracer, "processBatch", async () => {
|
|
1357
|
-
const wallElapsed = performance.now() - start;
|
|
1358
|
-
total += rows.size;
|
|
1359
|
-
lc.debug?.(
|
|
1360
|
-
`processing ${rows.size} (of ${total}) rows (${wallElapsed} ms)`
|
|
1361
|
-
);
|
|
1362
|
-
const patches = await updater.received(lc, rows);
|
|
1363
|
-
for (const patch of patches) {
|
|
1364
|
-
await pokers.addPatch(patch);
|
|
1365
|
-
}
|
|
1366
|
-
rows.clear();
|
|
1367
|
-
});
|
|
1368
|
-
await startAsyncSpan(tracer, "loopingChanges", async (span) => {
|
|
1369
|
-
for (const change of changes) {
|
|
1370
|
-
if (change === "yield") {
|
|
1371
|
-
await timer.yieldProcess("yield in processChanges");
|
|
1372
|
-
continue;
|
|
1373
|
-
}
|
|
1374
|
-
const { type, queryID, table, rowKey, row } = change;
|
|
1375
|
-
const rowID = { schema: "", table, rowKey };
|
|
1376
|
-
let parsedRow = rows.get(rowID);
|
|
1377
|
-
if (!parsedRow) {
|
|
1378
|
-
parsedRow = { refCounts: {} };
|
|
1379
|
-
rows.set(rowID, parsedRow);
|
|
1380
|
-
}
|
|
1381
|
-
parsedRow.refCounts[queryID] ??= 0;
|
|
1382
|
-
const updateVersion = (row2) => {
|
|
1383
|
-
const { version, contents } = contentsAndVersion(row2);
|
|
1384
|
-
parsedRow.version = version;
|
|
1385
|
-
parsedRow.contents = contents;
|
|
1386
|
-
};
|
|
1387
|
-
switch (type) {
|
|
1388
|
-
case "add":
|
|
1389
|
-
updateVersion(row);
|
|
1390
|
-
parsedRow.refCounts[queryID]++;
|
|
1391
|
-
break;
|
|
1392
|
-
case "edit":
|
|
1393
|
-
updateVersion(row);
|
|
1394
|
-
break;
|
|
1395
|
-
case "remove":
|
|
1396
|
-
parsedRow.refCounts[queryID]--;
|
|
1397
|
-
break;
|
|
1398
|
-
default:
|
|
1399
|
-
unreachable(type);
|
|
1400
|
-
}
|
|
1401
|
-
if (rows.size % CURSOR_PAGE_SIZE === 0) {
|
|
1402
|
-
await processBatch();
|
|
1403
|
-
}
|
|
1404
|
-
}
|
|
1405
|
-
if (rows.size) {
|
|
1406
|
-
await processBatch();
|
|
1407
|
-
}
|
|
1408
|
-
span.setAttribute("totalRows", total);
|
|
1409
|
-
});
|
|
1410
|
-
});
|
|
1411
|
-
}
|
|
1412
|
-
/**
|
|
1413
|
-
* Advance to the current snapshot of the replica and apply / send
|
|
1414
|
-
* changes.
|
|
1415
|
-
*
|
|
1416
|
-
* Must be called from within the #lock.
|
|
1417
|
-
*
|
|
1418
|
-
* Returns false if the advancement failed due to a schema change.
|
|
1419
|
-
*/
|
|
1420
|
-
#advancePipelines(lc, cvr) {
|
|
1421
|
-
return startAsyncSpan(tracer, "vs.#advancePipelines", async () => {
|
|
1422
|
-
assert(
|
|
1423
|
-
this.#pipelines.initialized(),
|
|
1424
|
-
"pipelines must be initialized (advancePipelines"
|
|
1425
|
-
);
|
|
1426
|
-
const start = performance.now();
|
|
1427
|
-
const timer = new TimeSliceTimer(lc);
|
|
1428
|
-
const { version, numChanges, changes } = this.#pipelines.advance(timer);
|
|
1429
|
-
lc = lc.withContext("newVersion", version);
|
|
1430
|
-
const updater = new CVRQueryDrivenUpdater(
|
|
1431
|
-
this.#cvrStore,
|
|
1432
|
-
cvr,
|
|
1433
|
-
version,
|
|
1434
|
-
this.#pipelines.replicaVersion
|
|
1435
|
-
);
|
|
1436
|
-
const pokers = startPoke(
|
|
1437
|
-
this.#getClients(cvr.version),
|
|
1438
|
-
updater.updatedVersion()
|
|
1439
|
-
);
|
|
1440
|
-
lc.debug?.(`applying ${numChanges} to advance to ${version}`);
|
|
1441
|
-
try {
|
|
1442
|
-
await this.#processChanges(
|
|
1443
|
-
lc,
|
|
1444
|
-
await timer.start(),
|
|
1445
|
-
changes,
|
|
1446
|
-
updater,
|
|
1447
|
-
pokers
|
|
1448
|
-
);
|
|
1449
|
-
} catch (e) {
|
|
1450
|
-
if (e instanceof ResetPipelinesSignal) {
|
|
1451
|
-
await pokers.cancel();
|
|
1452
|
-
return e;
|
|
1453
|
-
}
|
|
1454
|
-
throw e;
|
|
1455
|
-
}
|
|
1456
|
-
this.#cvr = await this.#flushUpdater(lc, updater);
|
|
1457
|
-
const finalVersion = this.#cvr.version;
|
|
1458
|
-
await pokers.end(finalVersion);
|
|
1459
|
-
const wallTime = performance.now() - start;
|
|
1460
|
-
const totalProcessTime = timer.totalElapsed();
|
|
1461
|
-
lc.info?.(
|
|
1462
|
-
`finished processing advancement of ${numChanges} changes ((process: ${totalProcessTime} ms, wall: ${wallTime} ms))`
|
|
1463
|
-
);
|
|
1464
|
-
this.#transactionAdvanceTime.record(totalProcessTime / 1e3);
|
|
1465
|
-
return "success";
|
|
1466
|
-
});
|
|
1467
|
-
}
|
|
1468
|
-
async inspect(context, msg) {
|
|
1469
|
-
await this.#runInLockForClient(context, msg, this.#handleInspect);
|
|
1470
|
-
}
|
|
1471
|
-
// oxlint-disable-next-line require-await
|
|
1472
|
-
#handleInspect = async (lc, clientID, body, cvr) => {
|
|
1473
|
-
const client = must(this.#clients.get(clientID));
|
|
1474
|
-
const auth = this.#authSession.auth;
|
|
1475
|
-
return handleInspect(
|
|
1476
|
-
lc,
|
|
1477
|
-
body,
|
|
1478
|
-
cvr,
|
|
1479
|
-
client,
|
|
1480
|
-
this.#inspectorDelegate,
|
|
1481
|
-
this.id,
|
|
1482
|
-
this.#cvrStore,
|
|
1483
|
-
this.#config,
|
|
1484
|
-
this.#getHeaderOptions(this.#queryConfig.forwardCookies ?? false),
|
|
1485
|
-
this.userQueryURL,
|
|
1486
|
-
auth?.type === "jwt" ? auth : void 0
|
|
1487
|
-
);
|
|
1488
|
-
};
|
|
1489
|
-
stop() {
|
|
1490
|
-
this.#lc.info?.("stopping view syncer");
|
|
1491
|
-
this.#initialized.reject("shut down before initialization completed");
|
|
1492
|
-
this.#stateChanges.cancel();
|
|
1493
|
-
return this.#stopped.promise;
|
|
1494
|
-
}
|
|
1495
|
-
async #cleanup(err) {
|
|
1496
|
-
this.clearAuth();
|
|
1497
|
-
this.#stopTTLClockInterval();
|
|
1498
|
-
this.#stopExpireTimer();
|
|
1499
|
-
for (const client of this.#clients.values()) {
|
|
1500
|
-
if (err) {
|
|
1501
|
-
client.fail(err);
|
|
1502
|
-
} else {
|
|
1503
|
-
client.close(`closed clientGroupID=${this.id}`);
|
|
1504
|
-
}
|
|
1505
|
-
}
|
|
1506
|
-
await this.#lock.withLock(() => {
|
|
1507
|
-
});
|
|
1508
|
-
this.#pipelines.destroy();
|
|
1509
|
-
}
|
|
1510
|
-
/**
|
|
1511
|
-
* Test helper: Manually mark initialization as complete.
|
|
1512
|
-
* This should only be used in tests that don't call initConnection().
|
|
1513
|
-
*/
|
|
1514
|
-
markInitialized() {
|
|
1515
|
-
this.#initialized.resolve("initialized");
|
|
1516
|
-
}
|
|
1517
|
-
}
|
|
1518
|
-
const CURSOR_PAGE_SIZE = 1e4;
|
|
1519
|
-
const timeSliceQueue = new Lock();
|
|
36
|
+
/**
|
|
37
|
+
* We update the ttlClock in flush that writes to the CVR but
|
|
38
|
+
* some flushes do not write to the CVR and in those cases we
|
|
39
|
+
* use a timer to update the ttlClock every minute.
|
|
40
|
+
*/
|
|
41
|
+
var TTL_CLOCK_INTERVAL = 6e4;
|
|
42
|
+
var ViewSyncerService = class {
|
|
43
|
+
id;
|
|
44
|
+
#shard;
|
|
45
|
+
#lc;
|
|
46
|
+
#pipelines;
|
|
47
|
+
#stateChanges;
|
|
48
|
+
#drainCoordinator;
|
|
49
|
+
#keepaliveMs;
|
|
50
|
+
#slowHydrateThreshold;
|
|
51
|
+
#queryConfig;
|
|
52
|
+
#authSession;
|
|
53
|
+
userQueryURL;
|
|
54
|
+
userQueryHeaders;
|
|
55
|
+
#lastConnectTime = Date.now();
|
|
56
|
+
/**
|
|
57
|
+
* The TTL clock is used to determine the time at which queries are considered
|
|
58
|
+
* expired.
|
|
59
|
+
*/
|
|
60
|
+
#ttlClock;
|
|
61
|
+
/**
|
|
62
|
+
* The base time for the TTL clock. This is used to compute the current TTL
|
|
63
|
+
* clock value. The first time a connection is made, this is set to the
|
|
64
|
+
* current time. On subsequent connections, the TTL clock is computed as the
|
|
65
|
+
* difference between the current time and this base time.
|
|
66
|
+
*
|
|
67
|
+
* Every time we write the ttlClock this is update to the current time. That
|
|
68
|
+
* way we can compute how much time has passed since the last time we set the
|
|
69
|
+
* ttlClock. When we set the ttlClock we just increment it by the amount of
|
|
70
|
+
* time that has passed since the last time we set it.
|
|
71
|
+
*/
|
|
72
|
+
#ttlClockBase = Date.now();
|
|
73
|
+
/**
|
|
74
|
+
* We update the ttlClock every minute to ensure that it is not too much
|
|
75
|
+
* out of sync with the current time.
|
|
76
|
+
*/
|
|
77
|
+
#ttlClockInterval = 0;
|
|
78
|
+
#clients = /* @__PURE__ */ new Map();
|
|
79
|
+
#lock = new Lock();
|
|
80
|
+
#cvrStore;
|
|
81
|
+
#stopped = resolver();
|
|
82
|
+
#initialized = resolver();
|
|
83
|
+
#cvr;
|
|
84
|
+
#pipelinesSynced = false;
|
|
85
|
+
#httpCookie;
|
|
86
|
+
#origin;
|
|
87
|
+
#lastAuthRevision = 0;
|
|
88
|
+
#expiredQueriesTimer = 0;
|
|
89
|
+
#setTimeout;
|
|
90
|
+
#customQueryTransformer;
|
|
91
|
+
#queryReplacements = /* @__PURE__ */ new Map();
|
|
92
|
+
#activeClients = getOrCreateUpDownCounter("sync", "active-clients", "Number of active sync clients");
|
|
93
|
+
#hydrations = getOrCreateCounter("sync", "hydration", "Number of query hydrations");
|
|
94
|
+
#hydrationTime = getOrCreateHistogram("sync", "hydration-time", {
|
|
95
|
+
description: "Time to hydrate a query.",
|
|
96
|
+
unit: "s"
|
|
97
|
+
});
|
|
98
|
+
#transactionAdvanceTime = getOrCreateHistogram("sync", "advance-time", {
|
|
99
|
+
description: "Time to advance all queries for a given client group after applying a new transaction to the replica.",
|
|
100
|
+
unit: "s"
|
|
101
|
+
});
|
|
102
|
+
#queryTransformations = getOrCreateCounter("sync", "query.transformations", "Number of query transformations performed");
|
|
103
|
+
#queryTransformationTime = getOrCreateHistogram("sync", "query.transformation-time", {
|
|
104
|
+
description: "Time to transform custom queries via API server",
|
|
105
|
+
unit: "s"
|
|
106
|
+
});
|
|
107
|
+
#queryTransformationHashChanges = getOrCreateCounter("sync", "query.transformation-hash-changes", "Number of times query transformation hash changed");
|
|
108
|
+
#queryTransformationNoOps = getOrCreateCounter("sync", "query.transformation-no-ops", "Number of times query transformation resulted in no-op (hash unchanged)");
|
|
109
|
+
#inspectorDelegate;
|
|
110
|
+
#config;
|
|
111
|
+
#runPriorityOp;
|
|
112
|
+
constructor(config, lc, shard, taskID, clientGroupID, cvrDb, pipelineDriver, versionChanges, drainCoordinator, slowHydrateThreshold, inspectorDelegate, customQueryTransformer, runPriorityOp, authSession, keepaliveMs = DEFAULT_KEEPALIVE_MS, setTimeoutFn = setTimeout.bind(globalThis)) {
|
|
113
|
+
const queryConfig = config.query?.url ? config.query : config.getQueries;
|
|
114
|
+
this.#config = config;
|
|
115
|
+
this.id = clientGroupID;
|
|
116
|
+
this.#shard = shard;
|
|
117
|
+
this.#queryConfig = queryConfig;
|
|
118
|
+
this.#lc = lc;
|
|
119
|
+
this.#pipelines = pipelineDriver;
|
|
120
|
+
this.#stateChanges = versionChanges;
|
|
121
|
+
this.#drainCoordinator = drainCoordinator;
|
|
122
|
+
this.#keepaliveMs = keepaliveMs;
|
|
123
|
+
this.#slowHydrateThreshold = slowHydrateThreshold;
|
|
124
|
+
this.#inspectorDelegate = inspectorDelegate;
|
|
125
|
+
this.#customQueryTransformer = customQueryTransformer;
|
|
126
|
+
this.#authSession = authSession;
|
|
127
|
+
this.#cvrStore = new CVRStore(lc, cvrDb, shard, taskID, clientGroupID, () => this.#stateChanges.cancel());
|
|
128
|
+
this.#setTimeout = setTimeoutFn;
|
|
129
|
+
this.#runPriorityOp = runPriorityOp;
|
|
130
|
+
this.keepalive();
|
|
131
|
+
}
|
|
132
|
+
get auth() {
|
|
133
|
+
return this.#authSession.auth;
|
|
134
|
+
}
|
|
135
|
+
clearAuth() {
|
|
136
|
+
this.#authSession.clear();
|
|
137
|
+
this.#lastAuthRevision = 0;
|
|
138
|
+
}
|
|
139
|
+
initAuthSession(userID, wireAuth) {
|
|
140
|
+
return this.#authSession.update(userID, wireAuth);
|
|
141
|
+
}
|
|
142
|
+
#getHeaderOptions(forwardCookie) {
|
|
143
|
+
return {
|
|
144
|
+
apiKey: this.#queryConfig.apiKey,
|
|
145
|
+
customHeaders: this.userQueryHeaders,
|
|
146
|
+
allowedClientHeaders: this.#queryConfig.allowedClientHeaders,
|
|
147
|
+
token: this.#authSession.auth?.raw,
|
|
148
|
+
cookie: forwardCookie ? this.#httpCookie : void 0,
|
|
149
|
+
origin: this.#origin
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
#runInLockWithCVR(fn) {
|
|
153
|
+
const rid = randomID();
|
|
154
|
+
this.#lc.debug?.("about to acquire lock for cvr ", rid);
|
|
155
|
+
return this.#lock.withLock(async () => {
|
|
156
|
+
this.#lc.debug?.("acquired lock in #runInLockWithCVR ", rid);
|
|
157
|
+
const lc = this.#lc.withContext("lock", rid);
|
|
158
|
+
if (!this.#stateChanges.active) {
|
|
159
|
+
this.#lc.debug?.("state changes are inactive");
|
|
160
|
+
clearTimeout(this.#expiredQueriesTimer);
|
|
161
|
+
throw new ProtocolErrorWithLevel({
|
|
162
|
+
kind: Rehome,
|
|
163
|
+
message: "Reconnect required",
|
|
164
|
+
origin: ZeroCache
|
|
165
|
+
}, "info");
|
|
166
|
+
}
|
|
167
|
+
if (await this.#checkForShutdownConditionsInLock()) {
|
|
168
|
+
this.#lc.info?.(`closing clientGroupID=${this.id}`);
|
|
169
|
+
this.#stateChanges.cancel();
|
|
170
|
+
return;
|
|
171
|
+
}
|
|
172
|
+
if (!this.#cvr) {
|
|
173
|
+
this.#lc.debug?.("loading cvr");
|
|
174
|
+
this.#cvr = await this.#runPriorityOp(lc, "loading cvr", () => this.#cvrStore.load(lc, this.#lastConnectTime));
|
|
175
|
+
this.#ttlClock = this.#cvr.ttlClock;
|
|
176
|
+
this.#ttlClockBase = Date.now();
|
|
177
|
+
} else {
|
|
178
|
+
const now = Date.now();
|
|
179
|
+
this.#cvr = {
|
|
180
|
+
...this.#cvr,
|
|
181
|
+
ttlClock: this.#getTTLClock(now)
|
|
182
|
+
};
|
|
183
|
+
}
|
|
184
|
+
try {
|
|
185
|
+
await fn(lc, this.#cvr);
|
|
186
|
+
} catch (e) {
|
|
187
|
+
this.#cvr = void 0;
|
|
188
|
+
throw e;
|
|
189
|
+
}
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
readyState() {
|
|
193
|
+
return Promise.race([this.#initialized.promise, this.#drainCoordinator.draining]);
|
|
194
|
+
}
|
|
195
|
+
async run() {
|
|
196
|
+
try {
|
|
197
|
+
if (await this.readyState() === "draining") {
|
|
198
|
+
this.#lc.debug?.(`draining view-syncer ${this.id} before running`);
|
|
199
|
+
this.stop();
|
|
200
|
+
}
|
|
201
|
+
for await (const { state } of this.#stateChanges) {
|
|
202
|
+
if (this.#drainCoordinator.shouldDrain()) {
|
|
203
|
+
this.#lc.debug?.(`draining view-syncer ${this.id} (elective)`);
|
|
204
|
+
break;
|
|
205
|
+
}
|
|
206
|
+
assert(state === "version-ready", "state should be version-ready");
|
|
207
|
+
await this.#runInLockWithCVR(async (lc, cvr) => {
|
|
208
|
+
const clientSchema = must(cvr.clientSchema, "cvr.clientSchema missing after initialization");
|
|
209
|
+
if (!this.#pipelines.initialized()) this.#pipelines.init(clientSchema);
|
|
210
|
+
if (cvr.replicaVersion !== null && cvr.version.stateVersion !== "00" && this.#pipelines.replicaVersion < cvr.replicaVersion) {
|
|
211
|
+
const message = `Cannot sync from older replica: CVR=${cvr.replicaVersion}, DB=${this.#pipelines.replicaVersion}`;
|
|
212
|
+
lc.info?.(`resetting CVR: ${message}`);
|
|
213
|
+
throw new ClientNotFoundError(message);
|
|
214
|
+
}
|
|
215
|
+
if (this.#pipelinesSynced) {
|
|
216
|
+
const result = await this.#advancePipelines(lc, cvr);
|
|
217
|
+
if (result === "success") return;
|
|
218
|
+
lc.info?.(`resetting pipelines: ${result.message}`);
|
|
219
|
+
this.#pipelines.reset(clientSchema);
|
|
220
|
+
this.#pipelinesSynced = false;
|
|
221
|
+
}
|
|
222
|
+
const version = this.#pipelines.advanceWithoutDiff();
|
|
223
|
+
const cvrVer = versionString(cvr.version);
|
|
224
|
+
if (version < cvr.version.stateVersion) {
|
|
225
|
+
lc.debug?.(`replica@${version} is behind cvr@${cvrVer}`);
|
|
226
|
+
return;
|
|
227
|
+
}
|
|
228
|
+
lc.info?.(`init pipelines@${version} (cvr@${cvrVer})`);
|
|
229
|
+
await this.#hydrateUnchangedQueries(lc, cvr);
|
|
230
|
+
await this.#syncQueryPipelineSet(lc, cvr, "missing");
|
|
231
|
+
this.#pipelinesSynced = true;
|
|
232
|
+
});
|
|
233
|
+
}
|
|
234
|
+
if (this.#drainCoordinator.shouldDrain()) this.#drainCoordinator.drainNextIn(this.#totalHydrationTimeMs());
|
|
235
|
+
await this.#cleanup();
|
|
236
|
+
} catch (e) {
|
|
237
|
+
this.#lc[getLogLevel(e)]?.(`stopping view-syncer ${this.id}: ${String(e)}`, e);
|
|
238
|
+
await this.#cleanup(e);
|
|
239
|
+
} finally {
|
|
240
|
+
await this.#cvrStore.flushed(this.#lc).catch((e) => this.#lc[getLogLevel(e)]?.(e));
|
|
241
|
+
this.#lc.info?.(`view-syncer ${this.id} finished`);
|
|
242
|
+
this.#stopped.resolve();
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
#removeExpiredQueries = async (lc, cvr) => {
|
|
246
|
+
if (hasExpiredQueries(cvr)) {
|
|
247
|
+
lc = lc.withContext("method", "#removeExpiredQueries");
|
|
248
|
+
lc.debug?.("Queries have expired");
|
|
249
|
+
if (this.#pipelinesSynced) await this.#syncQueryPipelineSet(lc, cvr, "missing");
|
|
250
|
+
}
|
|
251
|
+
this.#scheduleExpireEviction(lc, cvr);
|
|
252
|
+
};
|
|
253
|
+
#totalHydrationTimeMs() {
|
|
254
|
+
return this.#pipelines.totalHydrationTimeMs();
|
|
255
|
+
}
|
|
256
|
+
#keepAliveUntil = 0;
|
|
257
|
+
/**
|
|
258
|
+
* Guarantees that the ViewSyncer will remain running for at least
|
|
259
|
+
* its configured `keepaliveMs`. This is called when establishing a
|
|
260
|
+
* new connection to ensure that its associated ViewSyncer isn't
|
|
261
|
+
* shutdown before it receives the connection.
|
|
262
|
+
*
|
|
263
|
+
* @return `true` if the ViewSyncer will stay alive, `false` if the
|
|
264
|
+
* ViewSyncer is shutting down.
|
|
265
|
+
*/
|
|
266
|
+
keepalive() {
|
|
267
|
+
if (!this.#stateChanges.active) return false;
|
|
268
|
+
this.#keepAliveUntil = Date.now() + this.#keepaliveMs;
|
|
269
|
+
return true;
|
|
270
|
+
}
|
|
271
|
+
#shutdownTimer = null;
|
|
272
|
+
#scheduleShutdown(delayMs = 0) {
|
|
273
|
+
this.#shutdownTimer ??= this.#setTimeout(() => {
|
|
274
|
+
this.#shutdownTimer = null;
|
|
275
|
+
this.#runInLockWithCVR(() => {}).catch((e) => this.#stateChanges.fail(e));
|
|
276
|
+
}, delayMs);
|
|
277
|
+
}
|
|
278
|
+
async #checkForShutdownConditionsInLock() {
|
|
279
|
+
if (this.#clients.size > 0) return false;
|
|
280
|
+
await this.#cvrStore.flushed(this.#lc);
|
|
281
|
+
if (Date.now() <= this.#keepAliveUntil) {
|
|
282
|
+
this.#scheduleShutdown(this.#keepaliveMs);
|
|
283
|
+
return false;
|
|
284
|
+
}
|
|
285
|
+
return this.#clients.size === 0;
|
|
286
|
+
}
|
|
287
|
+
#deleteClientDueToDisconnect(clientID, client) {
|
|
288
|
+
if (this.#clients.get(clientID) === client) {
|
|
289
|
+
this.#clients.delete(clientID);
|
|
290
|
+
if (this.#clients.size === 0) {
|
|
291
|
+
if (this.#ttlClock !== void 0) this.#updateTTLClockInCVRWithoutLock(this.#lc);
|
|
292
|
+
this.#stopExpireTimer();
|
|
293
|
+
this.#scheduleShutdown();
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
#stopExpireTimer() {
|
|
298
|
+
this.#lc.debug?.("Stopping expired queries timer");
|
|
299
|
+
clearTimeout(this.#expiredQueriesTimer);
|
|
300
|
+
this.#expiredQueriesTimer = 0;
|
|
301
|
+
}
|
|
302
|
+
initConnection(ctx, initConnectionMessage) {
|
|
303
|
+
this.#lc.debug?.("viewSyncer.initConnection");
|
|
304
|
+
return startSpan(tracer, "vs.initConnection", () => {
|
|
305
|
+
const { clientID, profileID, wsID, baseCookie, httpCookie, origin, protocolVersion } = ctx;
|
|
306
|
+
this.#httpCookie = httpCookie;
|
|
307
|
+
this.#origin = origin;
|
|
308
|
+
const [, { userQueryURL, userQueryHeaders }] = initConnectionMessage;
|
|
309
|
+
if (this.userQueryURL === void 0) {
|
|
310
|
+
this.userQueryURL = userQueryURL;
|
|
311
|
+
this.userQueryHeaders = userQueryHeaders;
|
|
312
|
+
} else if (this.userQueryURL !== userQueryURL) this.#lc.warn?.("Client provided different query parameters than client group", {
|
|
313
|
+
clientID,
|
|
314
|
+
clientURL: userQueryURL,
|
|
315
|
+
clientGroupURL: this.userQueryURL
|
|
316
|
+
});
|
|
317
|
+
const lc = this.#lc.withContext("clientID", clientID).withContext("wsID", wsID);
|
|
318
|
+
const downstream = Subscription.create({ cleanup: (_, err) => {
|
|
319
|
+
err ? lc[getLogLevel(err)]?.(`client closed with error`, err) : lc.info?.("client closed");
|
|
320
|
+
this.#deleteClientDueToDisconnect(clientID, newClient);
|
|
321
|
+
this.#activeClients.add(-1, { [PROTOCOL_VERSION_ATTR]: protocolVersion });
|
|
322
|
+
} });
|
|
323
|
+
this.#activeClients.add(1, { [PROTOCOL_VERSION_ATTR]: protocolVersion });
|
|
324
|
+
if (this.#clients.size === 0) this.#ttlClockBase = Date.now();
|
|
325
|
+
const newClient = new ClientHandler(lc, this.id, clientID, wsID, this.#shard, baseCookie, downstream);
|
|
326
|
+
this.#clients.get(clientID)?.close(`replaced by wsID: ${wsID}`);
|
|
327
|
+
this.#clients.set(clientID, newClient);
|
|
328
|
+
this.#runInLockForClient(ctx, initConnectionMessage, async (lc, clientID, msg, cvr) => {
|
|
329
|
+
if (cvr.clientSchema === null && !msg.clientSchema) throw new ProtocolErrorWithLevel({
|
|
330
|
+
kind: InvalidConnectionRequest,
|
|
331
|
+
message: "The initConnection message for a new client group must include client schema.",
|
|
332
|
+
origin: ZeroCache
|
|
333
|
+
}, "warn");
|
|
334
|
+
await this.#handleConfigUpdate(lc, clientID, msg, cvr, "all", profileID ?? `cg${this.id}`);
|
|
335
|
+
this.#initialized.resolve("initialized");
|
|
336
|
+
}, newClient).catch((e) => newClient.fail(e));
|
|
337
|
+
return downstream;
|
|
338
|
+
});
|
|
339
|
+
}
|
|
340
|
+
async changeDesiredQueries(ctx, msg) {
|
|
341
|
+
await this.#runInLockForClient(ctx, msg, async (lc, clientID, msg, cvr) => {
|
|
342
|
+
let customQueryTransformMode = "missing";
|
|
343
|
+
const currentAuthRevision = this.#authSession.revision;
|
|
344
|
+
if (this.#lastAuthRevision < currentAuthRevision) {
|
|
345
|
+
customQueryTransformMode = "all";
|
|
346
|
+
lc.debug?.("Auth revision changed, setting customQueryTransformMode to all");
|
|
347
|
+
}
|
|
348
|
+
const result = await this.#handleConfigUpdate(lc, clientID, msg, cvr, customQueryTransformMode);
|
|
349
|
+
if (customQueryTransformMode === "all") this.#lastAuthRevision = currentAuthRevision;
|
|
350
|
+
return result;
|
|
351
|
+
});
|
|
352
|
+
}
|
|
353
|
+
async updateAuth(ctx, msg) {
|
|
354
|
+
await this.#runInLockForClient(ctx, msg, async (lc, clientID, _, cvr) => {
|
|
355
|
+
const authResult = await this.#authSession.update(ctx.userID, msg[1].auth);
|
|
356
|
+
if (!authResult.ok) throw new ProtocolErrorWithLevel(authResult.error, "warn");
|
|
357
|
+
const currentAuthRevision = this.#authSession.revision;
|
|
358
|
+
if (this.#lastAuthRevision >= currentAuthRevision) {
|
|
359
|
+
lc.debug?.("Auth revision unchanged, skipping query re-transformation");
|
|
360
|
+
return;
|
|
361
|
+
} else lc.debug?.("Auth revision changed, re-transforming queries");
|
|
362
|
+
const result = await this.#handleConfigUpdate(lc, clientID, {}, cvr, "all");
|
|
363
|
+
this.#lastAuthRevision = currentAuthRevision;
|
|
364
|
+
return result;
|
|
365
|
+
});
|
|
366
|
+
}
|
|
367
|
+
async deleteClients(ctx, msg) {
|
|
368
|
+
return await this.#runInLockForClient(ctx, [msg[0], { deleted: msg[1] }], (lc, clientID, msg, cvr) => this.#handleConfigUpdate(lc, clientID, msg, cvr, "missing")) ?? [];
|
|
369
|
+
}
|
|
370
|
+
#getTTLClock(now) {
|
|
371
|
+
const delta = now - this.#ttlClockBase;
|
|
372
|
+
assert(this.#ttlClock !== void 0, "ttlClock should be defined");
|
|
373
|
+
const ttlClock = ttlClockFromNumber(ttlClockAsNumber(this.#ttlClock) + delta);
|
|
374
|
+
assert(ttlClockAsNumber(ttlClock) <= now, "ttlClock should be less than or equal to now");
|
|
375
|
+
this.#ttlClock = ttlClock;
|
|
376
|
+
this.#ttlClockBase = now;
|
|
377
|
+
return ttlClock;
|
|
378
|
+
}
|
|
379
|
+
#flushUpdater(lc, updater) {
|
|
380
|
+
return startAsyncSpan(tracer, "vs.#flushUpdater", () => this.#runPriorityOp(lc, "flushing cvr", async () => {
|
|
381
|
+
const now = Date.now();
|
|
382
|
+
const ttlClock = this.#getTTLClock(now);
|
|
383
|
+
const { cvr, flushed } = await updater.flush(lc, this.#lastConnectTime, now, ttlClock);
|
|
384
|
+
if (flushed) this.#startTTLClockInterval(lc);
|
|
385
|
+
return cvr;
|
|
386
|
+
}));
|
|
387
|
+
}
|
|
388
|
+
#startTTLClockInterval(lc) {
|
|
389
|
+
this.#stopTTLClockInterval();
|
|
390
|
+
this.#ttlClockInterval = this.#setTimeout(() => {
|
|
391
|
+
this.#updateTTLClockInCVRWithoutLock(lc);
|
|
392
|
+
this.#startTTLClockInterval(lc);
|
|
393
|
+
}, TTL_CLOCK_INTERVAL);
|
|
394
|
+
}
|
|
395
|
+
#stopTTLClockInterval() {
|
|
396
|
+
clearTimeout(this.#ttlClockInterval);
|
|
397
|
+
this.#ttlClockInterval = 0;
|
|
398
|
+
}
|
|
399
|
+
#updateTTLClockInCVRWithoutLock(lc) {
|
|
400
|
+
const rid = randomID();
|
|
401
|
+
lc.debug?.("Syncing ttlClock", rid);
|
|
402
|
+
const start = Date.now();
|
|
403
|
+
const ttlClock = this.#getTTLClock(start);
|
|
404
|
+
this.#cvrStore.updateTTLClock(ttlClock, start).then(() => {
|
|
405
|
+
lc.debug?.("Synced ttlClock", rid, `in ${Date.now() - start} ms`);
|
|
406
|
+
}).catch((e) => {
|
|
407
|
+
lc.error?.("failed to update TTL clock", rid, `after ${Date.now() - start} ms`, e);
|
|
408
|
+
});
|
|
409
|
+
}
|
|
410
|
+
async #updateCVRConfig(lc, cvr, clientID, customQueryTransformMode, fn) {
|
|
411
|
+
const updater = new CVRConfigDrivenUpdater(this.#cvrStore, cvr, this.#shard);
|
|
412
|
+
updater.ensureClient(clientID);
|
|
413
|
+
const patches = fn(updater);
|
|
414
|
+
this.#cvr = await this.#flushUpdater(lc, updater);
|
|
415
|
+
if (cmpVersions(cvr.version, this.#cvr.version) < 0) {
|
|
416
|
+
const newCVR = this.#cvr;
|
|
417
|
+
await startAsyncSpan(tracer, "vs.#updateCVRConfig.pokeClients", async () => {
|
|
418
|
+
const pokers = startPoke(this.#getClients(cvr.version), newCVR.version);
|
|
419
|
+
for (const patch of patches) await pokers.addPatch(patch);
|
|
420
|
+
await pokers.end(newCVR.version);
|
|
421
|
+
});
|
|
422
|
+
}
|
|
423
|
+
if (this.#pipelinesSynced) await this.#syncQueryPipelineSet(lc, this.#cvr, customQueryTransformMode);
|
|
424
|
+
return this.#cvr;
|
|
425
|
+
}
|
|
426
|
+
/**
|
|
427
|
+
* Runs the given `fn` to process the `msg` from within the `#lock`,
|
|
428
|
+
* optionally adding the `newClient` if supplied.
|
|
429
|
+
*/
|
|
430
|
+
#runInLockForClient(ctx, msg, fn, newClient) {
|
|
431
|
+
this.#lc.debug?.("viewSyncer.#runInLockForClient");
|
|
432
|
+
const { clientID, wsID } = ctx;
|
|
433
|
+
const [cmd, body] = msg;
|
|
434
|
+
if (newClient || !this.#clients.has(clientID)) this.#lastConnectTime = Date.now();
|
|
435
|
+
return startAsyncSpan(tracer, `vs.#runInLockForClient(${cmd})`, async () => {
|
|
436
|
+
let client;
|
|
437
|
+
let result;
|
|
438
|
+
try {
|
|
439
|
+
await this.#runInLockWithCVR(async (lc, cvr) => {
|
|
440
|
+
lc = lc.withContext("clientID", clientID).withContext("wsID", wsID).withContext("cmd", cmd);
|
|
441
|
+
lc.debug?.("acquired lock for cvr");
|
|
442
|
+
client = this.#clients.get(clientID);
|
|
443
|
+
if (client?.wsID !== wsID) {
|
|
444
|
+
lc.debug?.("mismatched wsID", client?.wsID, wsID);
|
|
445
|
+
return;
|
|
446
|
+
}
|
|
447
|
+
if (newClient) {
|
|
448
|
+
assert(newClient === client, "newClient must match existing client");
|
|
449
|
+
checkClientAndCVRVersions(client.version(), cvr.version);
|
|
450
|
+
} else if (!this.#clients.has(clientID)) lc.warn?.(`Processing ${cmd} before initConnection was received`);
|
|
451
|
+
lc.debug?.(cmd, body);
|
|
452
|
+
result = await fn(lc, clientID, body, cvr);
|
|
453
|
+
});
|
|
454
|
+
} catch (e) {
|
|
455
|
+
const lc = this.#lc.withContext("clientID", clientID).withContext("wsID", wsID).withContext("cmd", cmd);
|
|
456
|
+
lc[getLogLevel(e)]?.(`closing connection with error`, e);
|
|
457
|
+
if (isTransformAuthFailure(e)) {
|
|
458
|
+
lc.debug?.("Auth failure detected in transform response");
|
|
459
|
+
this.clearAuth();
|
|
460
|
+
}
|
|
461
|
+
if (client) client.fail(e);
|
|
462
|
+
else throw e;
|
|
463
|
+
}
|
|
464
|
+
return result;
|
|
465
|
+
});
|
|
466
|
+
}
|
|
467
|
+
#getClients(atVersion) {
|
|
468
|
+
const clients = [...this.#clients.values()];
|
|
469
|
+
return atVersion ? clients.filter((c) => cmpVersions(c.version() ?? EMPTY_CVR_VERSION, atVersion) === 0) : clients;
|
|
470
|
+
}
|
|
471
|
+
#handleConfigUpdate = (lc, clientID, { clientSchema, deleted, desiredQueriesPatch, activeClients }, cvr, customQueryTransformMode, profileID) => startAsyncSpan(tracer, "vs.#handleConfigUpdate", async () => {
|
|
472
|
+
const deletedClientIDs = [];
|
|
473
|
+
const deletedClientGroupIDs = [];
|
|
474
|
+
cvr = await this.#updateCVRConfig(lc, cvr, clientID, customQueryTransformMode, (updater) => {
|
|
475
|
+
const { ttlClock } = cvr;
|
|
476
|
+
const patches = [];
|
|
477
|
+
if (clientSchema) updater.setClientSchema(lc, clientSchema);
|
|
478
|
+
if (profileID) updater.setProfileID(lc, profileID);
|
|
479
|
+
lc.debug?.(`applying ${desiredQueriesPatch?.length ?? 0} query patches`);
|
|
480
|
+
if (desiredQueriesPatch?.length) for (const patch of desiredQueriesPatch) switch (patch.op) {
|
|
481
|
+
case "put":
|
|
482
|
+
patches.push(...updater.putDesiredQueries(clientID, [patch]));
|
|
483
|
+
break;
|
|
484
|
+
case "del":
|
|
485
|
+
patches.push(...updater.markDesiredQueriesAsInactive(clientID, [patch.hash], ttlClock));
|
|
486
|
+
break;
|
|
487
|
+
case "clear":
|
|
488
|
+
patches.push(...updater.clearDesiredQueries(clientID));
|
|
489
|
+
break;
|
|
490
|
+
}
|
|
491
|
+
const clientIDsToDelete = /* @__PURE__ */ new Set();
|
|
492
|
+
if (activeClients) {
|
|
493
|
+
const allClientIDs = Object.keys(cvr.clients);
|
|
494
|
+
const activeClientsSet = new Set(activeClients);
|
|
495
|
+
for (const id of allClientIDs) if (!activeClientsSet.has(id)) clientIDsToDelete.add(id);
|
|
496
|
+
}
|
|
497
|
+
if (deleted?.clientIDs?.length) for (const cid of deleted.clientIDs) {
|
|
498
|
+
assert(cid !== clientID, "cannot delete self");
|
|
499
|
+
clientIDsToDelete.add(cid);
|
|
500
|
+
}
|
|
501
|
+
for (const cid of clientIDsToDelete) {
|
|
502
|
+
const patchesDueToClient = updater.deleteClient(cid, ttlClock);
|
|
503
|
+
patches.push(...patchesDueToClient);
|
|
504
|
+
deletedClientIDs.push(cid);
|
|
505
|
+
}
|
|
506
|
+
if (deleted?.clientGroupIDs?.length) lc.debug?.(`ignoring ${deleted.clientGroupIDs.length} deprecated client group deletes`);
|
|
507
|
+
return patches;
|
|
508
|
+
});
|
|
509
|
+
if (deletedClientIDs.length && deleted?.clientIDs?.length || deletedClientGroupIDs.length) {
|
|
510
|
+
const clients = this.#getClients();
|
|
511
|
+
await startAsyncSpan(tracer, "vs.#handleConfigUpdate.sendDeleteClients", () => Promise.allSettled(clients.map((client) => client.sendDeleteClients(lc, deletedClientIDs, deletedClientGroupIDs))));
|
|
512
|
+
}
|
|
513
|
+
this.#scheduleExpireEviction(lc, cvr);
|
|
514
|
+
return deletedClientIDs;
|
|
515
|
+
});
|
|
516
|
+
#scheduleExpireEviction(lc, cvr) {
|
|
517
|
+
const { ttlClock } = cvr;
|
|
518
|
+
this.#stopExpireTimer();
|
|
519
|
+
const next = nextEvictionTime(cvr);
|
|
520
|
+
if (next === void 0) {
|
|
521
|
+
lc.debug?.("no inactive queries with ttl");
|
|
522
|
+
return;
|
|
523
|
+
}
|
|
524
|
+
const delay = Math.max(50, Math.min(ttlClockAsNumber(next) - ttlClockAsNumber(ttlClock) + 50, MAX_TTL_MS));
|
|
525
|
+
lc.debug?.("Scheduling eviction timer to run in ", delay, "ms");
|
|
526
|
+
this.#expiredQueriesTimer = this.#setTimeout(() => {
|
|
527
|
+
this.#expiredQueriesTimer = 0;
|
|
528
|
+
this.#runInLockWithCVR((lc, cvr) => this.#removeExpiredQueries(lc, cvr)).catch((e) => this.#stateChanges.fail(e));
|
|
529
|
+
}, delay);
|
|
530
|
+
}
|
|
531
|
+
/**
|
|
532
|
+
* Adds and hydrates pipelines for queries whose results are already
|
|
533
|
+
* recorded in the CVR. Namely:
|
|
534
|
+
*
|
|
535
|
+
* 1. The CVR state version and database version are the same.
|
|
536
|
+
* 2. The transformation hash of the queries equal those in the CVR.
|
|
537
|
+
*
|
|
538
|
+
* Note that by definition, only "got" queries can satisfy condition (2),
|
|
539
|
+
* as desired queries do not have a transformation hash.
|
|
540
|
+
*
|
|
541
|
+
* This is an initialization step that sets up pipeline state without
|
|
542
|
+
* the expensive of loading and diffing CVR row state.
|
|
543
|
+
*
|
|
544
|
+
* This must be called from within the #lock.
|
|
545
|
+
*/
|
|
546
|
+
async #hydrateUnchangedQueries(lc, cvr) {
|
|
547
|
+
assert(this.#pipelines.initialized(), "pipelines must be initialized");
|
|
548
|
+
const dbVersion = this.#pipelines.currentVersion();
|
|
549
|
+
const cvrVersion = cvr.version;
|
|
550
|
+
if (cvrVersion.stateVersion !== dbVersion) {
|
|
551
|
+
lc.info?.(`CVR (${versionToCookie(cvrVersion)}) is behind db ${dbVersion}`);
|
|
552
|
+
return;
|
|
553
|
+
}
|
|
554
|
+
const gotQueries = Object.entries(cvr.queries).filter(([_, state]) => state.transformationHash !== void 0);
|
|
555
|
+
const customQueries = /* @__PURE__ */ new Map();
|
|
556
|
+
const otherQueries = [];
|
|
557
|
+
for (const [, query] of gotQueries) {
|
|
558
|
+
if (query.type !== "internal" && Object.values(query.clientState).every(({ inactivatedAt }) => inactivatedAt !== void 0)) continue;
|
|
559
|
+
if (query.type === "custom") customQueries.set(query.id, query);
|
|
560
|
+
else otherQueries.push(query);
|
|
561
|
+
}
|
|
562
|
+
const transformedQueries = [];
|
|
563
|
+
if (customQueries.size > 0 && !this.#customQueryTransformer) lc.warn?.("Custom/named queries were requested but no `ZERO_QUERY_URL` is configured for Zero Cache.");
|
|
564
|
+
const customQueryTransformer = this.#customQueryTransformer;
|
|
565
|
+
if (customQueryTransformer && customQueries.size > 0) {
|
|
566
|
+
const transformedCustomQueries = await this.#runPriorityOp(lc, "#hydrateUnchangedQueries transforming custom queries", () => customQueryTransformer.transform(this.#getHeaderOptions(this.#queryConfig.forwardCookies), customQueries.values(), this.userQueryURL));
|
|
567
|
+
if (Array.isArray(transformedCustomQueries)) {
|
|
568
|
+
for (const q of transformedCustomQueries) if (!("error" in q) && q.transformationHash === customQueries.get(q.id)?.transformationHash) transformedQueries.push(q);
|
|
569
|
+
}
|
|
570
|
+
}
|
|
571
|
+
for (const q of otherQueries) {
|
|
572
|
+
const auth = this.#authSession.auth;
|
|
573
|
+
const transformed = transformAndHashQuery(lc, q.id, q.ast, must(this.#pipelines.currentPermissions()).permissions ?? { tables: {} }, auth?.type === "jwt" ? auth : void 0, q.type === "internal");
|
|
574
|
+
if (transformed.transformationHash === q.transformationHash) transformedQueries.push(transformed);
|
|
575
|
+
}
|
|
576
|
+
for (const { id: queryID, transformationHash, transformedAst } of transformedQueries) {
|
|
577
|
+
const timer = new TimeSliceTimer(lc);
|
|
578
|
+
let count = 0;
|
|
579
|
+
await startAsyncSpan(tracer, "vs.#hydrateUnchangedQueries.addQuery", async (span) => {
|
|
580
|
+
span.setAttribute("queryHash", queryID);
|
|
581
|
+
span.setAttribute("transformationHash", transformationHash);
|
|
582
|
+
span.setAttribute("table", transformedAst.table);
|
|
583
|
+
for (const change of this.#pipelines.addQuery(transformationHash, queryID, transformedAst, await timer.start())) if (change === "yield") await timer.yieldProcess("yield in hydrateUnchangedQueries");
|
|
584
|
+
else count++;
|
|
585
|
+
});
|
|
586
|
+
const elapsed = timer.totalElapsed();
|
|
587
|
+
this.#hydrations.add(1);
|
|
588
|
+
this.#hydrationTime.record(elapsed / 1e3);
|
|
589
|
+
this.#addQueryMaterializationServerMetric(transformationHash, elapsed);
|
|
590
|
+
lc.debug?.(`hydrated ${count} rows for ${queryID} (${elapsed} ms)`);
|
|
591
|
+
}
|
|
592
|
+
}
|
|
593
|
+
#processTransformedCustomQueries(lc, transformedCustomQueries, cb, customQueryMap) {
|
|
594
|
+
if ("kind" in transformedCustomQueries) {
|
|
595
|
+
this.#sendQueryTransformErrorToClients(customQueryMap, transformedCustomQueries);
|
|
596
|
+
return transformedCustomQueries.queryIDs;
|
|
597
|
+
}
|
|
598
|
+
const appQueryErrors = [];
|
|
599
|
+
for (const q of transformedCustomQueries) {
|
|
600
|
+
if ("error" in q) {
|
|
601
|
+
const errorMessage = `Error transforming custom query ${q.name}: ${q.error}${q.details ? ` ${JSON.stringify(q.details)}` : ""}`;
|
|
602
|
+
lc.warn?.(errorMessage, q);
|
|
603
|
+
appQueryErrors.push(q);
|
|
604
|
+
continue;
|
|
605
|
+
}
|
|
606
|
+
cb(q);
|
|
607
|
+
}
|
|
608
|
+
this.#sendQueryTransformErrorToClients(customQueryMap, appQueryErrors);
|
|
609
|
+
return appQueryErrors.map((q) => q.id);
|
|
610
|
+
}
|
|
611
|
+
#sendQueryTransformErrorToClients(customQueryMap, errorOrErrors) {
|
|
612
|
+
const getAffectedClientIDs = (queryIDs) => {
|
|
613
|
+
const clientIds = /* @__PURE__ */ new Set();
|
|
614
|
+
for (const queryID of queryIDs) {
|
|
615
|
+
const q = customQueryMap.get(queryID);
|
|
616
|
+
assert(q, `got an error for query ${queryID} that does not map back to a custom query`);
|
|
617
|
+
Object.keys(q.clientState).forEach((id) => clientIds.add(id));
|
|
618
|
+
}
|
|
619
|
+
return clientIds;
|
|
620
|
+
};
|
|
621
|
+
if ("queryIDs" in errorOrErrors) {
|
|
622
|
+
for (const clientId of getAffectedClientIDs(errorOrErrors.queryIDs)) this.#clients.get(clientId)?.sendQueryTransformFailedError(errorOrErrors);
|
|
623
|
+
return;
|
|
624
|
+
}
|
|
625
|
+
const appErrorGroups = /* @__PURE__ */ new Map();
|
|
626
|
+
for (const err of errorOrErrors) for (const clientId of getAffectedClientIDs([err.id])) {
|
|
627
|
+
const group = appErrorGroups.get(clientId) ?? [];
|
|
628
|
+
group.push(err);
|
|
629
|
+
appErrorGroups.set(clientId, group);
|
|
630
|
+
}
|
|
631
|
+
for (const [clientId, errors] of appErrorGroups) this.#clients.get(clientId)?.sendQueryTransformApplicationErrors(errors);
|
|
632
|
+
}
|
|
633
|
+
#addQueryMaterializationServerMetric(queryID, elapsed) {
|
|
634
|
+
this.#inspectorDelegate.addMetric("query-materialization-server", elapsed, queryID);
|
|
635
|
+
}
|
|
636
|
+
/**
|
|
637
|
+
* Adds and/or removes queries to/from the PipelineDriver to bring it
|
|
638
|
+
* in sync with the set of queries in the CVR (both got and desired).
|
|
639
|
+
* If queries are added, removed, or queried due to a new state version,
|
|
640
|
+
* a new CVR version is created and pokes sent to connected clients.
|
|
641
|
+
*
|
|
642
|
+
* This must be called from within the #lock.
|
|
643
|
+
*/
|
|
644
|
+
#syncQueryPipelineSet(lc, cvr, customQueryTransformMode) {
|
|
645
|
+
return startAsyncSpan(tracer, "vs.#syncQueryPipelineSet", async () => {
|
|
646
|
+
assert(this.#pipelines.initialized(), "pipelines must be initialized (syncQueryPipelineSet)");
|
|
647
|
+
if (this.#ttlClock === void 0) this.#ttlClock = cvr.ttlClock;
|
|
648
|
+
const now = Date.now();
|
|
649
|
+
const ttlClock = this.#getTTLClock(now);
|
|
650
|
+
const cvrQueryEntires = Object.entries(cvr.queries);
|
|
651
|
+
const customQueries = /* @__PURE__ */ new Map();
|
|
652
|
+
const otherQueries = [];
|
|
653
|
+
const transformedQueries = [];
|
|
654
|
+
for (const [id, query] of cvrQueryEntires) if (query.type === "custom") {
|
|
655
|
+
assert(id === query.id, "custom query id mismatch");
|
|
656
|
+
customQueries.set(id, query);
|
|
657
|
+
} else otherQueries.push({
|
|
658
|
+
id,
|
|
659
|
+
query
|
|
660
|
+
});
|
|
661
|
+
for (const { id, query: origQuery } of otherQueries) {
|
|
662
|
+
assert(id === origQuery.id, "query id mismatch");
|
|
663
|
+
const auth = this.#authSession.auth;
|
|
664
|
+
const transformed = transformAndHashQuery(lc, origQuery.id, origQuery.ast, must(this.#pipelines.currentPermissions()).permissions ?? { tables: {} }, auth?.type === "jwt" ? auth : void 0, origQuery.type === "internal");
|
|
665
|
+
transformedQueries.push({
|
|
666
|
+
id,
|
|
667
|
+
origQuery,
|
|
668
|
+
transformed
|
|
669
|
+
});
|
|
670
|
+
}
|
|
671
|
+
if (customQueries.size > 0 && !this.#customQueryTransformer) lc.warn?.("Custom/named queries were requested but no `ZERO_QUERY_URL` is configured for Zero Cache.");
|
|
672
|
+
let erroredQueryIDs;
|
|
673
|
+
const customQueriesToTransform = customQueryTransformMode === "all" ? [...customQueries.values()] : customQueryTransformMode && [...customQueries.values()].filter((q) => !this.#pipelines.queries().has(q.id));
|
|
674
|
+
const customQueryTransformer = this.#customQueryTransformer;
|
|
675
|
+
if (customQueryTransformer && customQueriesToTransform.length > 0) {
|
|
676
|
+
const transformStart = performance.now();
|
|
677
|
+
let transformedCustomQueries;
|
|
678
|
+
try {
|
|
679
|
+
transformedCustomQueries = await this.#runPriorityOp(lc, "#syncQueryPipelineSet transforming custom queries", () => customQueryTransformer.transform(this.#getHeaderOptions(true), customQueriesToTransform, this.userQueryURL));
|
|
680
|
+
if (!Array.isArray(transformedCustomQueries) && transformedCustomQueries.kind === "TransformFailed") throw new ProtocolErrorWithLevel(transformedCustomQueries, "warn");
|
|
681
|
+
else this.#queryTransformations.add(1, { result: "success" });
|
|
682
|
+
} catch (e) {
|
|
683
|
+
this.#queryTransformations.add(1, { result: "error" });
|
|
684
|
+
throw e;
|
|
685
|
+
} finally {
|
|
686
|
+
const transformDuration = (performance.now() - transformStart) / 1e3;
|
|
687
|
+
this.#queryTransformationTime.record(transformDuration);
|
|
688
|
+
}
|
|
689
|
+
const successfullyTransformedCustomQueries = /* @__PURE__ */ new Map();
|
|
690
|
+
erroredQueryIDs = this.#processTransformedCustomQueries(lc, transformedCustomQueries, (q) => {
|
|
691
|
+
const origQuery = customQueries.get(q.id);
|
|
692
|
+
if (origQuery) {
|
|
693
|
+
successfullyTransformedCustomQueries.set(q.id, q);
|
|
694
|
+
transformedQueries.push({
|
|
695
|
+
id: q.id,
|
|
696
|
+
origQuery,
|
|
697
|
+
transformed: q
|
|
698
|
+
});
|
|
699
|
+
}
|
|
700
|
+
}, customQueries);
|
|
701
|
+
for (const [queryID, newTransform] of successfullyTransformedCustomQueries) {
|
|
702
|
+
const existingTransformHash = cvr.queries[queryID]?.transformationHash;
|
|
703
|
+
if (existingTransformHash) {
|
|
704
|
+
const oldHash = existingTransformHash;
|
|
705
|
+
const newHash = newTransform.transformationHash;
|
|
706
|
+
if (oldHash !== newHash) {
|
|
707
|
+
lc.info?.(`Query ${queryID} transformation changed: ${oldHash} -> ${newHash}`);
|
|
708
|
+
this.#checkForThrashing(queryID);
|
|
709
|
+
this.#queryTransformationHashChanges.add(1);
|
|
710
|
+
} else this.#queryTransformationNoOps.add(1);
|
|
711
|
+
}
|
|
712
|
+
}
|
|
713
|
+
}
|
|
714
|
+
const removeQueriesQueryIds = new Set(Object.values(cvr.queries).filter((q) => expired(ttlClock, q)).map((q) => q.id).concat(erroredQueryIDs || []));
|
|
715
|
+
const addQueries = transformedQueries.map(({ id, transformed }) => ({
|
|
716
|
+
id,
|
|
717
|
+
ast: transformed.transformedAst,
|
|
718
|
+
transformationHash: transformed.transformationHash
|
|
719
|
+
})).filter((q) => !removeQueriesQueryIds.has(q.id) && this.#pipelines.queries().get(q.id)?.transformationHash !== q.transformationHash);
|
|
720
|
+
for (const q of addQueries) {
|
|
721
|
+
const orig = cvr.queries[q.id];
|
|
722
|
+
lc.debug?.("ViewSyncer adding query", q.ast, "transformed from", orig.type === "custom" ? orig.name : orig.ast);
|
|
723
|
+
}
|
|
724
|
+
if (addQueries.length > 0 || removeQueriesQueryIds.size > 0) await this.#addAndRemoveQueries(lc, cvr, addQueries, [...removeQueriesQueryIds].map((id) => ({ id })));
|
|
725
|
+
else await this.#catchupClients(lc, cvr);
|
|
726
|
+
});
|
|
727
|
+
}
|
|
728
|
+
/**
|
|
729
|
+
* Check if a query is being replaced too frequently (thrashing).
|
|
730
|
+
* Logs a warning if the query has been replaced more than 3 times in 60 seconds.
|
|
731
|
+
*/
|
|
732
|
+
#checkForThrashing(queryID) {
|
|
733
|
+
const THRASH_WINDOW_MS = 6e4;
|
|
734
|
+
const THRASH_THRESHOLD = 3;
|
|
735
|
+
const now = Date.now();
|
|
736
|
+
let record = this.#queryReplacements.get(queryID);
|
|
737
|
+
if (!record) {
|
|
738
|
+
record = {
|
|
739
|
+
count: 1,
|
|
740
|
+
windowStart: now
|
|
741
|
+
};
|
|
742
|
+
this.#queryReplacements.set(queryID, record);
|
|
743
|
+
return;
|
|
744
|
+
}
|
|
745
|
+
if (now - record.windowStart > THRASH_WINDOW_MS) {
|
|
746
|
+
this.#queryReplacements.delete(queryID);
|
|
747
|
+
this.#queryReplacements.set(queryID, {
|
|
748
|
+
count: 1,
|
|
749
|
+
windowStart: now
|
|
750
|
+
});
|
|
751
|
+
return;
|
|
752
|
+
}
|
|
753
|
+
record.count++;
|
|
754
|
+
if (record.count >= THRASH_THRESHOLD) this.#lc.warn?.(`Query thrashing detected for query ${queryID}. ${record.count} replacements in 60s. This may indicate clients with different auth contexts connecting to the same client group.`);
|
|
755
|
+
}
|
|
756
|
+
#addAndRemoveQueries(lc, cvr, addQueries, removeQueries) {
|
|
757
|
+
return startAsyncSpan(tracer, "vs.#addAndRemoveQueries", async () => {
|
|
758
|
+
assert(addQueries.length > 0 || removeQueries.length > 0, "Must have queries to add or remove");
|
|
759
|
+
const start = performance.now();
|
|
760
|
+
const stateVersion = this.#pipelines.currentVersion();
|
|
761
|
+
lc = lc.withContext("stateVersion", stateVersion);
|
|
762
|
+
lc.info?.(`hydrating ${addQueries.length} queries`);
|
|
763
|
+
const updater = new CVRQueryDrivenUpdater(this.#cvrStore, cvr, stateVersion, this.#pipelines.replicaVersion);
|
|
764
|
+
const { newVersion, queryPatches } = updater.trackQueries(lc, addQueries, removeQueries);
|
|
765
|
+
const pokers = startPoke(this.#getClients(), newVersion);
|
|
766
|
+
for (const patch of queryPatches) await pokers.addPatch(patch);
|
|
767
|
+
for (const q of removeQueries) {
|
|
768
|
+
this.#pipelines.removeQuery(q.id);
|
|
769
|
+
this.#inspectorDelegate.removeQuery(q.id);
|
|
770
|
+
this.#queryReplacements.delete(q.id);
|
|
771
|
+
}
|
|
772
|
+
let totalProcessTime = 0;
|
|
773
|
+
const timer = new TimeSliceTimer(lc);
|
|
774
|
+
const pipelines = this.#pipelines;
|
|
775
|
+
const hydrations = this.#hydrations;
|
|
776
|
+
const hydrationTime = this.#hydrationTime;
|
|
777
|
+
const self = this;
|
|
778
|
+
await yieldProcess(lc);
|
|
779
|
+
function* generateRowChanges(slowHydrateThreshold) {
|
|
780
|
+
for (const q of addQueries) {
|
|
781
|
+
lc = lc.withContext("hash", q.id).withContext("transformationHash", q.transformationHash);
|
|
782
|
+
lc.debug?.(`adding pipeline for query`, q.ast);
|
|
783
|
+
yield* pipelines.addQuery(q.transformationHash, q.id, q.ast, timer.startWithoutYielding());
|
|
784
|
+
const elapsed = timer.stop();
|
|
785
|
+
totalProcessTime += elapsed;
|
|
786
|
+
self.#addQueryMaterializationServerMetric(q.id, elapsed);
|
|
787
|
+
if (elapsed > slowHydrateThreshold) lc.warn?.("Slow query materialization", elapsed, q.ast);
|
|
788
|
+
manualSpan(tracer, "vs.addAndConsumeQuery", elapsed, {
|
|
789
|
+
hash: q.id,
|
|
790
|
+
transformationHash: q.transformationHash
|
|
791
|
+
});
|
|
792
|
+
}
|
|
793
|
+
hydrations.add(1);
|
|
794
|
+
hydrationTime.record(totalProcessTime / 1e3);
|
|
795
|
+
}
|
|
796
|
+
await this.#processChanges(lc, timer, generateRowChanges(this.#slowHydrateThreshold), updater, pokers);
|
|
797
|
+
for (const patch of await updater.deleteUnreferencedRows(lc)) await pokers.addPatch(patch);
|
|
798
|
+
this.#cvr = await this.#flushUpdater(lc, updater);
|
|
799
|
+
const finalVersion = this.#cvr.version;
|
|
800
|
+
await this.#catchupClients(lc, cvr, finalVersion, addQueries.map((q) => q.id), pokers);
|
|
801
|
+
await pokers.end(finalVersion);
|
|
802
|
+
const wallTime = performance.now() - start;
|
|
803
|
+
lc.info?.(`finished processing queries (process: ${totalProcessTime} ms, wall: ${wallTime} ms)`);
|
|
804
|
+
});
|
|
805
|
+
}
|
|
806
|
+
/**
|
|
807
|
+
* @param cvr The CVR to which clients should be caught up to. This does
|
|
808
|
+
* not necessarily need to be the current CVR.
|
|
809
|
+
* @param current The expected current CVR version. Before performing
|
|
810
|
+
* catchup, the snapshot read will verify that the CVR has not been
|
|
811
|
+
* concurrently modified. Note that this only needs to be done for
|
|
812
|
+
* catchup because it is the only time data from the CVR DB is
|
|
813
|
+
* "exported" without being gated by a CVR flush (which provides
|
|
814
|
+
* concurrency protection in all other cases).
|
|
815
|
+
*
|
|
816
|
+
* If unspecified, the version of the `cvr` is used.
|
|
817
|
+
* @param excludeQueryHashes Exclude patches from rows associated with
|
|
818
|
+
* the specified queries.
|
|
819
|
+
* @param usePokers If specified, sends pokes on existing PokeHandlers,
|
|
820
|
+
* in which case the caller is responsible for sending the `pokeEnd`
|
|
821
|
+
* messages. If unspecified, the pokes will be started and ended
|
|
822
|
+
* using the version from the supplied `cvr`.
|
|
823
|
+
*/
|
|
824
|
+
#catchupClients(lc, cvr, current, excludeQueryHashes = [], usePokers) {
|
|
825
|
+
return startAsyncSpan(tracer, "vs.#catchupClients", async (span) => {
|
|
826
|
+
current ??= cvr.version;
|
|
827
|
+
const clients = this.#getClients();
|
|
828
|
+
const pokers = usePokers ?? startPoke(clients, cvr.version);
|
|
829
|
+
span.setAttribute("numClients", clients.length);
|
|
830
|
+
const catchupFrom = clients.map((c) => c.version()).reduce((a, b) => cmpVersions(a, b) < 0 ? a : b, cvr.version);
|
|
831
|
+
const rowPatches = this.#cvrStore.catchupRowPatches(lc, catchupFrom, cvr, current, excludeQueryHashes);
|
|
832
|
+
const configPatches = this.#cvrStore.catchupConfigPatches(lc, catchupFrom, cvr, current);
|
|
833
|
+
configPatches.catch(() => {});
|
|
834
|
+
let rowPatchCount = 0;
|
|
835
|
+
for await (const rows of rowPatches) for (const row of rows) {
|
|
836
|
+
const { schema, table } = row;
|
|
837
|
+
const rowKey = row.rowKey;
|
|
838
|
+
const toVersion = versionFromString(row.patchVersion);
|
|
839
|
+
const id = {
|
|
840
|
+
schema,
|
|
841
|
+
table,
|
|
842
|
+
rowKey
|
|
843
|
+
};
|
|
844
|
+
let patch;
|
|
845
|
+
if (!row.refCounts) patch = {
|
|
846
|
+
type: "row",
|
|
847
|
+
op: "del",
|
|
848
|
+
id
|
|
849
|
+
};
|
|
850
|
+
else {
|
|
851
|
+
const { contents } = contentsAndVersion(must(this.#pipelines.getRow(table, rowKey), `Missing row ${table}:${stringify(rowKey)}`));
|
|
852
|
+
patch = {
|
|
853
|
+
type: "row",
|
|
854
|
+
op: "put",
|
|
855
|
+
id,
|
|
856
|
+
contents
|
|
857
|
+
};
|
|
858
|
+
}
|
|
859
|
+
const patchToVersion = {
|
|
860
|
+
patch,
|
|
861
|
+
toVersion
|
|
862
|
+
};
|
|
863
|
+
await pokers.addPatch(patchToVersion);
|
|
864
|
+
rowPatchCount++;
|
|
865
|
+
}
|
|
866
|
+
span.setAttribute("rowPatchCount", rowPatchCount);
|
|
867
|
+
if (rowPatchCount) lc.debug?.(`sent ${rowPatchCount} row patches`);
|
|
868
|
+
for (const patch of await configPatches) await pokers.addPatch(patch);
|
|
869
|
+
if (!usePokers) await pokers.end(cvr.version);
|
|
870
|
+
});
|
|
871
|
+
}
|
|
872
|
+
#processChanges(lc, timer, changes, updater, pokers) {
|
|
873
|
+
return startAsyncSpan(tracer, "vs.#processChanges", async () => {
|
|
874
|
+
const start = performance.now();
|
|
875
|
+
const rows = new CustomKeyMap(rowIDString);
|
|
876
|
+
let total = 0;
|
|
877
|
+
const processBatch = () => startAsyncSpan(tracer, "processBatch", async () => {
|
|
878
|
+
const wallElapsed = performance.now() - start;
|
|
879
|
+
total += rows.size;
|
|
880
|
+
lc.debug?.(`processing ${rows.size} (of ${total}) rows (${wallElapsed} ms)`);
|
|
881
|
+
const patches = await updater.received(lc, rows);
|
|
882
|
+
for (const patch of patches) await pokers.addPatch(patch);
|
|
883
|
+
rows.clear();
|
|
884
|
+
});
|
|
885
|
+
await startAsyncSpan(tracer, "loopingChanges", async (span) => {
|
|
886
|
+
for (const change of changes) {
|
|
887
|
+
if (change === "yield") {
|
|
888
|
+
await timer.yieldProcess("yield in processChanges");
|
|
889
|
+
continue;
|
|
890
|
+
}
|
|
891
|
+
const { type, queryID, table, rowKey, row } = change;
|
|
892
|
+
const rowID = {
|
|
893
|
+
schema: "",
|
|
894
|
+
table,
|
|
895
|
+
rowKey
|
|
896
|
+
};
|
|
897
|
+
let parsedRow = rows.get(rowID);
|
|
898
|
+
if (!parsedRow) {
|
|
899
|
+
parsedRow = { refCounts: {} };
|
|
900
|
+
rows.set(rowID, parsedRow);
|
|
901
|
+
}
|
|
902
|
+
parsedRow.refCounts[queryID] ??= 0;
|
|
903
|
+
const updateVersion = (row) => {
|
|
904
|
+
const { version, contents } = contentsAndVersion(row);
|
|
905
|
+
parsedRow.version = version;
|
|
906
|
+
parsedRow.contents = contents;
|
|
907
|
+
};
|
|
908
|
+
switch (type) {
|
|
909
|
+
case "add":
|
|
910
|
+
updateVersion(row);
|
|
911
|
+
parsedRow.refCounts[queryID]++;
|
|
912
|
+
break;
|
|
913
|
+
case "edit":
|
|
914
|
+
updateVersion(row);
|
|
915
|
+
break;
|
|
916
|
+
case "remove":
|
|
917
|
+
parsedRow.refCounts[queryID]--;
|
|
918
|
+
break;
|
|
919
|
+
default: unreachable(type);
|
|
920
|
+
}
|
|
921
|
+
if (rows.size % CURSOR_PAGE_SIZE === 0) await processBatch();
|
|
922
|
+
}
|
|
923
|
+
if (rows.size) await processBatch();
|
|
924
|
+
span.setAttribute("totalRows", total);
|
|
925
|
+
});
|
|
926
|
+
});
|
|
927
|
+
}
|
|
928
|
+
/**
|
|
929
|
+
* Advance to the current snapshot of the replica and apply / send
|
|
930
|
+
* changes.
|
|
931
|
+
*
|
|
932
|
+
* Must be called from within the #lock.
|
|
933
|
+
*
|
|
934
|
+
* Returns false if the advancement failed due to a schema change.
|
|
935
|
+
*/
|
|
936
|
+
#advancePipelines(lc, cvr) {
|
|
937
|
+
return startAsyncSpan(tracer, "vs.#advancePipelines", async () => {
|
|
938
|
+
assert(this.#pipelines.initialized(), "pipelines must be initialized (advancePipelines");
|
|
939
|
+
const start = performance.now();
|
|
940
|
+
const timer = new TimeSliceTimer(lc);
|
|
941
|
+
const { version, numChanges, changes } = this.#pipelines.advance(timer);
|
|
942
|
+
lc = lc.withContext("newVersion", version);
|
|
943
|
+
const updater = new CVRQueryDrivenUpdater(this.#cvrStore, cvr, version, this.#pipelines.replicaVersion);
|
|
944
|
+
const pokers = startPoke(this.#getClients(cvr.version), updater.updatedVersion());
|
|
945
|
+
lc.debug?.(`applying ${numChanges} to advance to ${version}`);
|
|
946
|
+
try {
|
|
947
|
+
await this.#processChanges(lc, await timer.start(), changes, updater, pokers);
|
|
948
|
+
} catch (e) {
|
|
949
|
+
if (e instanceof ResetPipelinesSignal) {
|
|
950
|
+
await pokers.cancel();
|
|
951
|
+
return e;
|
|
952
|
+
}
|
|
953
|
+
throw e;
|
|
954
|
+
}
|
|
955
|
+
this.#cvr = await this.#flushUpdater(lc, updater);
|
|
956
|
+
const finalVersion = this.#cvr.version;
|
|
957
|
+
await pokers.end(finalVersion);
|
|
958
|
+
const wallTime = performance.now() - start;
|
|
959
|
+
const totalProcessTime = timer.totalElapsed();
|
|
960
|
+
lc.info?.(`finished processing advancement of ${numChanges} changes ((process: ${totalProcessTime} ms, wall: ${wallTime} ms))`);
|
|
961
|
+
this.#transactionAdvanceTime.record(totalProcessTime / 1e3);
|
|
962
|
+
return "success";
|
|
963
|
+
});
|
|
964
|
+
}
|
|
965
|
+
async inspect(context, msg) {
|
|
966
|
+
await this.#runInLockForClient(context, msg, this.#handleInspect);
|
|
967
|
+
}
|
|
968
|
+
#handleInspect = async (lc, clientID, body, cvr) => {
|
|
969
|
+
const client = must(this.#clients.get(clientID));
|
|
970
|
+
const auth = this.#authSession.auth;
|
|
971
|
+
return handleInspect(lc, body, cvr, client, this.#inspectorDelegate, this.id, this.#cvrStore, this.#config, this.#getHeaderOptions(this.#queryConfig.forwardCookies ?? false), this.userQueryURL, auth?.type === "jwt" ? auth : void 0);
|
|
972
|
+
};
|
|
973
|
+
stop() {
|
|
974
|
+
this.#lc.info?.("stopping view syncer");
|
|
975
|
+
this.#initialized.reject("shut down before initialization completed");
|
|
976
|
+
this.#stateChanges.cancel();
|
|
977
|
+
return this.#stopped.promise;
|
|
978
|
+
}
|
|
979
|
+
async #cleanup(err) {
|
|
980
|
+
this.clearAuth();
|
|
981
|
+
this.#stopTTLClockInterval();
|
|
982
|
+
this.#stopExpireTimer();
|
|
983
|
+
for (const client of this.#clients.values()) if (err) client.fail(err);
|
|
984
|
+
else client.close(`closed clientGroupID=${this.id}`);
|
|
985
|
+
await this.#lock.withLock(() => {});
|
|
986
|
+
this.#pipelines.destroy();
|
|
987
|
+
}
|
|
988
|
+
/**
|
|
989
|
+
* Test helper: Manually mark initialization as complete.
|
|
990
|
+
* This should only be used in tests that don't call initConnection().
|
|
991
|
+
*/
|
|
992
|
+
markInitialized() {
|
|
993
|
+
this.#initialized.resolve("initialized");
|
|
994
|
+
}
|
|
995
|
+
};
|
|
996
|
+
var CURSOR_PAGE_SIZE = 1e4;
|
|
997
|
+
var timeSliceQueue = new Lock();
|
|
1520
998
|
function yieldProcess(_lc) {
|
|
1521
|
-
|
|
999
|
+
return timeSliceQueue.withLock(() => new Promise(setImmediate));
|
|
1522
1000
|
}
|
|
1523
1001
|
function contentsAndVersion(row) {
|
|
1524
|
-
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
|
|
1002
|
+
const { [ZERO_VERSION_COLUMN_NAME]: version, ...contents } = row;
|
|
1003
|
+
if (typeof version !== "string" || version.length === 0) throw new Error(`Invalid _0_version in ${stringify(row)}`);
|
|
1004
|
+
return {
|
|
1005
|
+
contents,
|
|
1006
|
+
version
|
|
1007
|
+
};
|
|
1529
1008
|
}
|
|
1530
|
-
|
|
1009
|
+
var NEW_CVR_VERSION = { stateVersion: "00" };
|
|
1531
1010
|
function checkClientAndCVRVersions(client, cvr) {
|
|
1532
|
-
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
|
|
1538
|
-
message: `CVR is at version ${versionString(cvr)}`,
|
|
1539
|
-
origin: ZeroCache
|
|
1540
|
-
});
|
|
1541
|
-
}
|
|
1011
|
+
if (cmpVersions(cvr, NEW_CVR_VERSION) === 0 && cmpVersions(client, NEW_CVR_VERSION) > 0) throw new ClientNotFoundError("Client not found");
|
|
1012
|
+
if (cmpVersions(client, cvr) > 0) throw new ProtocolError({
|
|
1013
|
+
kind: InvalidConnectionRequestBaseCookie,
|
|
1014
|
+
message: `CVR is at version ${versionString(cvr)}`,
|
|
1015
|
+
origin: ZeroCache
|
|
1016
|
+
});
|
|
1542
1017
|
}
|
|
1543
1018
|
function isTransformAuthFailure(error) {
|
|
1544
|
-
|
|
1545
|
-
|
|
1546
|
-
}
|
|
1547
|
-
return error.errorBody.kind === TransformFailed && error.errorBody.reason === HTTP && (error.errorBody.status === 401 || error.errorBody.status === 403);
|
|
1019
|
+
if (!isProtocolError(error)) return false;
|
|
1020
|
+
return error.errorBody.kind === "TransformFailed" && error.errorBody.reason === "http" && (error.errorBody.status === 401 || error.errorBody.status === 403);
|
|
1548
1021
|
}
|
|
1022
|
+
/**
|
|
1023
|
+
* A query must be expired for all clients in order to be considered
|
|
1024
|
+
* expired.
|
|
1025
|
+
*/
|
|
1549
1026
|
function expired(ttlClock, q) {
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
|
|
1558
|
-
const clampedTTL = clampTTL(ttl);
|
|
1559
|
-
if (ttlClockAsNumber(inactivatedAt) + clampedTTL > ttlClockAsNumber(ttlClock)) {
|
|
1560
|
-
return false;
|
|
1561
|
-
}
|
|
1562
|
-
}
|
|
1563
|
-
return true;
|
|
1027
|
+
if (q.type === "internal") return false;
|
|
1028
|
+
for (const clientState of Object.values(q.clientState)) {
|
|
1029
|
+
const { ttl, inactivatedAt } = clientState;
|
|
1030
|
+
if (inactivatedAt === void 0) return false;
|
|
1031
|
+
const clampedTTL = clampTTL(ttl);
|
|
1032
|
+
if (ttlClockAsNumber(inactivatedAt) + clampedTTL > ttlClockAsNumber(ttlClock)) return false;
|
|
1033
|
+
}
|
|
1034
|
+
return true;
|
|
1564
1035
|
}
|
|
1565
1036
|
function hasExpiredQueries(cvr) {
|
|
1566
|
-
|
|
1567
|
-
|
|
1568
|
-
|
|
1569
|
-
return true;
|
|
1570
|
-
}
|
|
1571
|
-
}
|
|
1572
|
-
return false;
|
|
1573
|
-
}
|
|
1574
|
-
class TimeSliceTimer {
|
|
1575
|
-
#total = 0;
|
|
1576
|
-
#start = 0;
|
|
1577
|
-
#lc;
|
|
1578
|
-
constructor(lc) {
|
|
1579
|
-
this.#lc = lc;
|
|
1580
|
-
}
|
|
1581
|
-
async start() {
|
|
1582
|
-
await yieldProcess(this.#lc);
|
|
1583
|
-
return this.startWithoutYielding();
|
|
1584
|
-
}
|
|
1585
|
-
startWithoutYielding() {
|
|
1586
|
-
this.#total = 0;
|
|
1587
|
-
this.#startLap();
|
|
1588
|
-
return this;
|
|
1589
|
-
}
|
|
1590
|
-
async yieldProcess(_msgForTesting) {
|
|
1591
|
-
this.#stopLap();
|
|
1592
|
-
await yieldProcess(this.#lc);
|
|
1593
|
-
this.#startLap();
|
|
1594
|
-
}
|
|
1595
|
-
#startLap() {
|
|
1596
|
-
assert(this.#start === 0, "already running");
|
|
1597
|
-
this.#start = performance.now();
|
|
1598
|
-
}
|
|
1599
|
-
elapsedLap() {
|
|
1600
|
-
assert(this.#start !== 0, "not running");
|
|
1601
|
-
return performance.now() - this.#start;
|
|
1602
|
-
}
|
|
1603
|
-
#stopLap() {
|
|
1604
|
-
assert(this.#start !== 0, "not running");
|
|
1605
|
-
this.#total += performance.now() - this.#start;
|
|
1606
|
-
this.#start = 0;
|
|
1607
|
-
}
|
|
1608
|
-
/** @returns the total elapsed time */
|
|
1609
|
-
stop() {
|
|
1610
|
-
this.#stopLap();
|
|
1611
|
-
return this.#total;
|
|
1612
|
-
}
|
|
1613
|
-
/**
|
|
1614
|
-
* @returns the elapsed time. This can be called while the Timer is running
|
|
1615
|
-
* or after it has been stopped.
|
|
1616
|
-
*/
|
|
1617
|
-
totalElapsed() {
|
|
1618
|
-
return this.#start === 0 ? this.#total : this.#total + performance.now() - this.#start;
|
|
1619
|
-
}
|
|
1037
|
+
const { ttlClock } = cvr;
|
|
1038
|
+
for (const q of Object.values(cvr.queries)) if (expired(ttlClock, q)) return true;
|
|
1039
|
+
return false;
|
|
1620
1040
|
}
|
|
1621
|
-
|
|
1622
|
-
|
|
1623
|
-
|
|
1624
|
-
|
|
1625
|
-
|
|
1041
|
+
var TimeSliceTimer = class {
|
|
1042
|
+
#total = 0;
|
|
1043
|
+
#start = 0;
|
|
1044
|
+
#lc;
|
|
1045
|
+
constructor(lc) {
|
|
1046
|
+
this.#lc = lc;
|
|
1047
|
+
}
|
|
1048
|
+
async start() {
|
|
1049
|
+
await yieldProcess(this.#lc);
|
|
1050
|
+
return this.startWithoutYielding();
|
|
1051
|
+
}
|
|
1052
|
+
startWithoutYielding() {
|
|
1053
|
+
this.#total = 0;
|
|
1054
|
+
this.#startLap();
|
|
1055
|
+
return this;
|
|
1056
|
+
}
|
|
1057
|
+
async yieldProcess(_msgForTesting) {
|
|
1058
|
+
this.#stopLap();
|
|
1059
|
+
await yieldProcess(this.#lc);
|
|
1060
|
+
this.#startLap();
|
|
1061
|
+
}
|
|
1062
|
+
#startLap() {
|
|
1063
|
+
assert(this.#start === 0, "already running");
|
|
1064
|
+
this.#start = performance.now();
|
|
1065
|
+
}
|
|
1066
|
+
elapsedLap() {
|
|
1067
|
+
assert(this.#start !== 0, "not running");
|
|
1068
|
+
return performance.now() - this.#start;
|
|
1069
|
+
}
|
|
1070
|
+
#stopLap() {
|
|
1071
|
+
assert(this.#start !== 0, "not running");
|
|
1072
|
+
this.#total += performance.now() - this.#start;
|
|
1073
|
+
this.#start = 0;
|
|
1074
|
+
}
|
|
1075
|
+
/** @returns the total elapsed time */
|
|
1076
|
+
stop() {
|
|
1077
|
+
this.#stopLap();
|
|
1078
|
+
return this.#total;
|
|
1079
|
+
}
|
|
1080
|
+
/**
|
|
1081
|
+
* @returns the elapsed time. This can be called while the Timer is running
|
|
1082
|
+
* or after it has been stopped.
|
|
1083
|
+
*/
|
|
1084
|
+
totalElapsed() {
|
|
1085
|
+
return this.#start === 0 ? this.#total : this.#total + performance.now() - this.#start;
|
|
1086
|
+
}
|
|
1626
1087
|
};
|
|
1627
|
-
//#
|
|
1088
|
+
//#endregion
|
|
1089
|
+
export { TimeSliceTimer, ViewSyncerService };
|
|
1090
|
+
|
|
1091
|
+
//# sourceMappingURL=view-syncer.js.map
|