@rocicorp/zero 1.12.0-canary.8 → 1.12.0-canary.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/out/replicache/src/btree/node.d.ts +0 -2
- package/out/replicache/src/btree/node.d.ts.map +1 -1
- package/out/replicache/src/btree/node.js.map +1 -1
- package/out/replicache/src/connection-loop.d.ts.map +1 -1
- package/out/replicache/src/connection-loop.js +1 -1
- package/out/replicache/src/connection-loop.js.map +1 -1
- package/out/replicache/src/db/commit.d.ts +0 -1
- package/out/replicache/src/db/commit.d.ts.map +1 -1
- package/out/replicache/src/db/commit.js +1 -1
- package/out/replicache/src/db/commit.js.map +1 -1
- package/out/replicache/src/db/write.d.ts +0 -2
- package/out/replicache/src/db/write.d.ts.map +1 -1
- package/out/replicache/src/db/write.js +1 -1
- package/out/replicache/src/db/write.js.map +1 -1
- package/out/replicache/src/deleted-clients.d.ts +0 -2
- package/out/replicache/src/deleted-clients.d.ts.map +1 -1
- package/out/replicache/src/deleted-clients.js +1 -1
- package/out/replicache/src/deleted-clients.js.map +1 -1
- package/out/replicache/src/frozen-json.d.ts +0 -1
- package/out/replicache/src/frozen-json.d.ts.map +1 -1
- package/out/replicache/src/frozen-json.js.map +1 -1
- package/out/replicache/src/index-defs.d.ts +0 -2
- package/out/replicache/src/index-defs.d.ts.map +1 -1
- package/out/replicache/src/index-defs.js +1 -1
- package/out/replicache/src/index-defs.js.map +1 -1
- package/out/replicache/src/kv/expo-sqlite/store.d.ts +0 -1
- package/out/replicache/src/kv/expo-sqlite/store.d.ts.map +1 -1
- package/out/replicache/src/kv/expo-sqlite/store.js +1 -1
- package/out/replicache/src/kv/expo-sqlite/store.js.map +1 -1
- package/out/replicache/src/kv/idb-store.js +1 -1
- package/out/replicache/src/kv/idb-store.js.map +1 -1
- package/out/replicache/src/kv/throw-if-closed.d.ts +0 -3
- package/out/replicache/src/kv/throw-if-closed.d.ts.map +1 -1
- package/out/replicache/src/kv/throw-if-closed.js.map +1 -1
- package/out/replicache/src/persist/client-group-gc.d.ts +0 -7
- package/out/replicache/src/persist/client-group-gc.d.ts.map +1 -1
- package/out/replicache/src/persist/client-group-gc.js +1 -1
- package/out/replicache/src/persist/client-group-gc.js.map +1 -1
- package/out/replicache/src/process-scheduler.js +1 -1
- package/out/replicache/src/process-scheduler.js.map +1 -1
- package/out/replicache/src/replicache-impl.d.ts +2 -7
- package/out/replicache/src/replicache-impl.d.ts.map +1 -1
- package/out/replicache/src/replicache-impl.js +1 -1
- package/out/replicache/src/replicache-impl.js.map +1 -1
- package/out/replicache/src/sync/patch.d.ts +0 -5
- package/out/replicache/src/sync/patch.d.ts.map +1 -1
- package/out/replicache/src/sync/patch.js +1 -1
- package/out/replicache/src/sync/patch.js.map +1 -1
- package/out/replicache/src/sync/pull.d.ts +0 -1
- package/out/replicache/src/sync/pull.d.ts.map +1 -1
- package/out/replicache/src/sync/pull.js.map +1 -1
- package/out/replicache/src/sync/push.d.ts +2 -1
- package/out/replicache/src/sync/push.d.ts.map +1 -1
- package/out/replicache/src/sync/push.js.map +1 -1
- package/out/replicache/src/types.d.ts +2 -1
- package/out/replicache/src/types.d.ts.map +1 -1
- package/out/shared/src/asserts.d.ts +0 -5
- package/out/shared/src/asserts.d.ts.map +1 -1
- package/out/shared/src/asserts.js +1 -1
- package/out/shared/src/asserts.js.map +1 -1
- package/out/shared/src/browser-env.d.ts +0 -17
- package/out/shared/src/browser-env.d.ts.map +1 -1
- package/out/shared/src/browser-env.js.map +1 -1
- package/out/shared/src/deep-clone.d.ts +0 -1
- package/out/shared/src/deep-clone.d.ts.map +1 -1
- package/out/shared/src/deep-clone.js +1 -1
- package/out/shared/src/deep-clone.js.map +1 -1
- package/out/shared/src/document-visible.js +1 -1
- package/out/shared/src/document-visible.js.map +1 -1
- package/out/shared/src/expand.d.ts +0 -3
- package/out/shared/src/expand.d.ts.map +1 -1
- package/out/shared/src/immutable.d.ts +1 -1
- package/out/shared/src/immutable.d.ts.map +1 -1
- package/out/shared/src/iterables.d.ts +0 -1
- package/out/shared/src/iterables.d.ts.map +1 -1
- package/out/shared/src/iterables.js.map +1 -1
- package/out/shared/src/logging-test-utils.js +1 -1
- package/out/shared/src/logging-test-utils.js.map +1 -1
- package/out/shared/src/options-types.d.ts +1 -1
- package/out/shared/src/options-types.d.ts.map +1 -1
- package/out/shared/src/options.d.ts +2 -3
- package/out/shared/src/options.d.ts.map +1 -1
- package/out/shared/src/options.js +1 -1
- package/out/shared/src/options.js.map +1 -1
- package/out/shared/src/promise-race.js +1 -1
- package/out/shared/src/promise-race.js.map +1 -1
- package/out/shared/src/queue.js +1 -1
- package/out/shared/src/queue.js.map +1 -1
- package/out/shared/src/resolved-promises.d.ts +0 -4
- package/out/shared/src/resolved-promises.d.ts.map +1 -1
- package/out/shared/src/resolved-promises.js +0 -1
- package/out/shared/src/resolved-promises.js.map +1 -1
- package/out/shared/src/resolver.d.ts +9 -0
- package/out/shared/src/resolver.d.ts.map +1 -0
- package/out/shared/src/resolver.js +6 -0
- package/out/shared/src/resolver.js.map +1 -0
- package/out/shared/src/sleep.js +1 -1
- package/out/shared/src/sleep.js.map +1 -1
- package/out/shared/src/tdigest.d.ts +0 -1
- package/out/shared/src/tdigest.d.ts.map +1 -1
- package/out/shared/src/tdigest.js.map +1 -1
- package/out/z2s/src/sql.d.ts +1 -5
- package/out/z2s/src/sql.d.ts.map +1 -1
- package/out/z2s/src/sql.js.map +1 -1
- package/out/zero/package.js +2 -3
- package/out/zero/package.js.map +1 -1
- package/out/zero/src/zero-cache-dev.js +1 -1
- package/out/zero/src/zero-cache-dev.js.map +1 -1
- package/out/zero-cache/src/config/zero-config.d.ts +14 -11
- package/out/zero-cache/src/config/zero-config.d.ts.map +1 -1
- package/out/zero-cache/src/config/zero-config.js +23 -0
- package/out/zero-cache/src/config/zero-config.js.map +1 -1
- package/out/zero-cache/src/db/migration-lite.js.map +1 -1
- package/out/zero-cache/src/db/migration.js +1 -1
- package/out/zero-cache/src/db/migration.js.map +1 -1
- package/out/zero-cache/src/db/pg-copy-binary.js +1 -1
- package/out/zero-cache/src/db/pg-copy-binary.js.map +1 -1
- package/out/zero-cache/src/db/pg-type-parser.js.map +1 -1
- package/out/zero-cache/src/db/specs.d.ts +3 -4
- package/out/zero-cache/src/db/specs.d.ts.map +1 -1
- package/out/zero-cache/src/db/specs.js +5 -7
- package/out/zero-cache/src/db/specs.js.map +1 -1
- package/out/zero-cache/src/db/transaction-pool.js +2 -2
- package/out/zero-cache/src/db/transaction-pool.js.map +1 -1
- package/out/zero-cache/src/observability/events.js +1 -1
- package/out/zero-cache/src/observability/events.js.map +1 -1
- package/out/zero-cache/src/server/change-streamer.js +1 -1
- package/out/zero-cache/src/server/change-streamer.js.map +1 -1
- package/out/zero-cache/src/server/main.js +1 -1
- package/out/zero-cache/src/server/main.js.map +1 -1
- package/out/zero-cache/src/server/runner/run-worker.js +1 -1
- package/out/zero-cache/src/server/runner/run-worker.js.map +1 -1
- package/out/zero-cache/src/services/change-source/common/backfill-manager.js +1 -1
- 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 +1 -1
- 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-restore.js.map +1 -1
- package/out/zero-cache/src/services/change-source/custom/change-source.js +1 -1
- package/out/zero-cache/src/services/change-source/custom/change-source.js.map +1 -1
- package/out/zero-cache/src/services/change-source/pg/backfill-stream.js +1 -1
- 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 +1 -1
- package/out/zero-cache/src/services/change-source/pg/change-source.js.map +1 -1
- package/out/zero-cache/src/services/change-source/pg/initial-sync.js +1 -1
- package/out/zero-cache/src/services/change-source/pg/initial-sync.js.map +1 -1
- package/out/zero-cache/src/services/change-source/pg/lsn.d.ts +0 -2
- package/out/zero-cache/src/services/change-source/pg/lsn.d.ts.map +1 -1
- package/out/zero-cache/src/services/change-source/pg/lsn.js.map +1 -1
- package/out/zero-cache/src/services/change-source/pg/replication-slots.js +1 -1
- package/out/zero-cache/src/services/change-source/pg/replication-slots.js.map +1 -1
- package/out/zero-cache/src/services/change-source/pg/schema/ddl.d.ts +0 -12
- package/out/zero-cache/src/services/change-source/pg/schema/ddl.d.ts.map +1 -1
- package/out/zero-cache/src/services/change-source/pg/schema/ddl.js +5 -3
- 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/index-predicate.d.ts +1 -1
- package/out/zero-cache/src/services/change-source/pg/schema/index-predicate.d.ts.map +1 -1
- package/out/zero-cache/src/services/change-source/pg/schema/index-predicate.js.map +1 -1
- package/out/zero-cache/src/services/change-source/pg/schema/validation.d.ts +0 -1
- package/out/zero-cache/src/services/change-source/pg/schema/validation.d.ts.map +1 -1
- package/out/zero-cache/src/services/change-source/pg/schema/validation.js.map +1 -1
- package/out/zero-cache/src/services/change-streamer/backup-monitor.js +1 -1
- package/out/zero-cache/src/services/change-streamer/backup-monitor.js.map +1 -1
- package/out/zero-cache/src/services/change-streamer/broadcast.js +1 -1
- 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 +1 -1
- 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.js +1 -1
- 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 +1 -1
- package/out/zero-cache/src/services/change-streamer/change-streamer.js.map +1 -1
- package/out/zero-cache/src/services/change-streamer/drain-tracker.js +1 -1
- package/out/zero-cache/src/services/change-streamer/drain-tracker.js.map +1 -1
- package/out/zero-cache/src/services/change-streamer/litestream3-prometheus-poller.js +2 -2
- package/out/zero-cache/src/services/change-streamer/litestream3-prometheus-poller.js.map +1 -1
- package/out/zero-cache/src/services/change-streamer/restore-admission.js +2 -2
- package/out/zero-cache/src/services/change-streamer/restore-admission.js.map +1 -1
- package/out/zero-cache/src/services/change-streamer/schema/tables.js +1 -1
- package/out/zero-cache/src/services/change-streamer/schema/tables.js.map +1 -1
- package/out/zero-cache/src/services/change-streamer/snapshot-message.js +2 -3
- package/out/zero-cache/src/services/change-streamer/snapshot-message.js.map +1 -1
- package/out/zero-cache/src/services/change-streamer/sqlite-change-log-catchup.js +2 -2
- package/out/zero-cache/src/services/change-streamer/sqlite-change-log-catchup.js.map +1 -1
- package/out/zero-cache/src/services/change-streamer/sqlite-change-log-read-router.js.map +1 -1
- package/out/zero-cache/src/services/change-streamer/storer.js +1 -1
- package/out/zero-cache/src/services/change-streamer/storer.js.map +1 -1
- package/out/zero-cache/src/services/change-streamer/subscribe.js +1 -1
- package/out/zero-cache/src/services/change-streamer/subscribe.js.map +1 -1
- package/out/zero-cache/src/services/change-streamer/subscriber.js +1 -1
- package/out/zero-cache/src/services/change-streamer/subscriber.js.map +1 -1
- package/out/zero-cache/src/services/life-cycle.js +1 -1
- package/out/zero-cache/src/services/life-cycle.js.map +1 -1
- package/out/zero-cache/src/services/litestream/commands.js +1 -1
- package/out/zero-cache/src/services/litestream/commands.js.map +1 -1
- package/out/zero-cache/src/services/litestream/metrics.js.map +1 -1
- package/out/zero-cache/src/services/mutagen/mutagen.js +2 -2
- package/out/zero-cache/src/services/mutagen/mutagen.js.map +1 -1
- package/out/zero-cache/src/services/plannerz.d.ts +4 -12
- package/out/zero-cache/src/services/plannerz.d.ts.map +1 -1
- package/out/zero-cache/src/services/plannerz.js +1 -3
- package/out/zero-cache/src/services/plannerz.js.map +1 -1
- package/out/zero-cache/src/services/replicator/change-log-db.js +1 -1
- package/out/zero-cache/src/services/replicator/change-log-db.js.map +1 -1
- package/out/zero-cache/src/services/replicator/change-log-stream-writer.js +1 -1
- package/out/zero-cache/src/services/replicator/change-log-stream-writer.js.map +1 -1
- package/out/zero-cache/src/services/replicator/drain-handler.js +1 -1
- package/out/zero-cache/src/services/replicator/drain-handler.js.map +1 -1
- package/out/zero-cache/src/services/replicator/reporter/recorder.js +1 -1
- package/out/zero-cache/src/services/replicator/reporter/recorder.js.map +1 -1
- package/out/zero-cache/src/services/replicator/reporter/report-schema.d.ts +2 -11
- package/out/zero-cache/src/services/replicator/reporter/report-schema.d.ts.map +1 -1
- package/out/zero-cache/src/services/replicator/reporter/report-schema.js +1 -1
- package/out/zero-cache/src/services/replicator/reporter/report-schema.js.map +1 -1
- package/out/zero-cache/src/services/replicator/schema/change-log.d.ts +0 -10
- package/out/zero-cache/src/services/replicator/schema/change-log.d.ts.map +1 -1
- package/out/zero-cache/src/services/replicator/schema/change-log.js.map +1 -1
- package/out/zero-cache/src/services/replicator/schema/column-metadata.d.ts +0 -7
- package/out/zero-cache/src/services/replicator/schema/column-metadata.d.ts.map +1 -1
- package/out/zero-cache/src/services/replicator/schema/column-metadata.js +1 -1
- package/out/zero-cache/src/services/replicator/schema/column-metadata.js.map +1 -1
- package/out/zero-cache/src/services/replicator/write-worker-client.js +1 -1
- package/out/zero-cache/src/services/replicator/write-worker-client.js.map +1 -1
- package/out/zero-cache/src/services/running-state.js +1 -1
- package/out/zero-cache/src/services/running-state.js.map +1 -1
- package/out/zero-cache/src/services/view-syncer/client-handler.js.map +1 -1
- package/out/zero-cache/src/services/view-syncer/connection-context-manager.js.map +1 -1
- package/out/zero-cache/src/services/view-syncer/cvr-store.js +1 -1
- package/out/zero-cache/src/services/view-syncer/cvr-store.js.map +1 -1
- package/out/zero-cache/src/services/view-syncer/cvr.js.map +1 -1
- package/out/zero-cache/src/services/view-syncer/drain-coordinator.js +1 -1
- package/out/zero-cache/src/services/view-syncer/drain-coordinator.js.map +1 -1
- package/out/zero-cache/src/services/view-syncer/pipeline-driver.js.map +1 -1
- package/out/zero-cache/src/services/view-syncer/query-stats.js.map +1 -1
- package/out/zero-cache/src/services/view-syncer/row-record-cache.js +1 -1
- 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 +1 -1
- package/out/zero-cache/src/services/view-syncer/schema/cvr.js.map +1 -1
- package/out/zero-cache/src/services/view-syncer/schema/types.js +3 -17
- package/out/zero-cache/src/services/view-syncer/schema/types.js.map +1 -1
- package/out/zero-cache/src/services/view-syncer/snapshotter.js +1 -1
- package/out/zero-cache/src/services/view-syncer/snapshotter.js.map +1 -1
- package/out/zero-cache/src/services/view-syncer/view-syncer.js +10 -10
- package/out/zero-cache/src/services/view-syncer/view-syncer.js.map +1 -1
- package/out/zero-cache/src/types/lite.d.ts +0 -1
- package/out/zero-cache/src/types/lite.d.ts.map +1 -1
- package/out/zero-cache/src/types/lite.js +2 -2
- package/out/zero-cache/src/types/lite.js.map +1 -1
- package/out/zero-cache/src/types/pg-types.d.ts +0 -40
- package/out/zero-cache/src/types/pg-types.d.ts.map +1 -1
- package/out/zero-cache/src/types/pg-types.js.map +1 -1
- package/out/zero-cache/src/types/poke-chunk.js +1 -1
- package/out/zero-cache/src/types/poke-chunk.js.map +1 -1
- package/out/zero-cache/src/types/row-key.d.ts +0 -5
- package/out/zero-cache/src/types/row-key.d.ts.map +1 -1
- package/out/zero-cache/src/types/row-key.js.map +1 -1
- package/out/zero-cache/src/types/streams.js +1 -1
- package/out/zero-cache/src/types/streams.js.map +1 -1
- package/out/zero-cache/src/types/subscription.js +1 -1
- package/out/zero-cache/src/types/subscription.js.map +1 -1
- package/out/zero-cache/src/types/websocket-handoff.d.ts +0 -6
- package/out/zero-cache/src/types/websocket-handoff.d.ts.map +1 -1
- package/out/zero-cache/src/types/websocket-handoff.js +8 -2
- package/out/zero-cache/src/types/websocket-handoff.js.map +1 -1
- package/out/zero-cache/src/types/ws.d.ts +2 -1
- package/out/zero-cache/src/types/ws.d.ts.map +1 -1
- package/out/zero-cache/src/types/ws.js +1 -1
- package/out/zero-cache/src/types/ws.js.map +1 -1
- package/out/zero-cache/src/workers/connection.js +4 -1
- package/out/zero-cache/src/workers/connection.js.map +1 -1
- package/out/zero-cache/src/workers/mutator.js +1 -1
- package/out/zero-cache/src/workers/mutator.js.map +1 -1
- package/out/zero-cache/src/workers/syncer.js +36 -2
- package/out/zero-cache/src/workers/syncer.js.map +1 -1
- package/out/zero-client/src/client/active-clients-manager.d.ts.map +1 -1
- package/out/zero-client/src/client/active-clients-manager.js +1 -1
- package/out/zero-client/src/client/active-clients-manager.js.map +1 -1
- package/out/zero-client/src/client/connection-manager.js +1 -1
- package/out/zero-client/src/client/connection-manager.js.map +1 -1
- package/out/zero-client/src/client/crud.d.ts +2 -8
- package/out/zero-client/src/client/crud.d.ts.map +1 -1
- package/out/zero-client/src/client/crud.js +1 -1
- package/out/zero-client/src/client/crud.js.map +1 -1
- package/out/zero-client/src/client/custom.d.ts +0 -2
- package/out/zero-client/src/client/custom.d.ts.map +1 -1
- package/out/zero-client/src/client/custom.js +1 -1
- package/out/zero-client/src/client/custom.js.map +1 -1
- package/out/zero-client/src/client/enable-analytics.d.ts +0 -1
- package/out/zero-client/src/client/enable-analytics.d.ts.map +1 -1
- package/out/zero-client/src/client/enable-analytics.js +2 -1
- package/out/zero-client/src/client/enable-analytics.js.map +1 -1
- package/out/zero-client/src/client/error.d.ts +4 -5
- package/out/zero-client/src/client/error.d.ts.map +1 -1
- package/out/zero-client/src/client/error.js.map +1 -1
- package/out/zero-client/src/client/keys.d.ts +0 -1
- package/out/zero-client/src/client/keys.d.ts.map +1 -1
- package/out/zero-client/src/client/keys.js +4 -2
- package/out/zero-client/src/client/keys.js.map +1 -1
- package/out/zero-client/src/client/mutation-tracker.d.ts.map +1 -1
- package/out/zero-client/src/client/mutation-tracker.js +1 -1
- package/out/zero-client/src/client/mutation-tracker.js.map +1 -1
- package/out/zero-client/src/client/options.d.ts +0 -4
- package/out/zero-client/src/client/options.d.ts.map +1 -1
- package/out/zero-client/src/client/options.js.map +1 -1
- package/out/zero-client/src/client/replicache-types.d.ts +3 -2
- package/out/zero-client/src/client/replicache-types.d.ts.map +1 -1
- package/out/zero-client/src/client/version.js +1 -1
- package/out/zero-client/src/client/zero-poke-handler.d.ts +1 -2
- package/out/zero-client/src/client/zero-poke-handler.d.ts.map +1 -1
- package/out/zero-client/src/client/zero-poke-handler.js +1 -1
- package/out/zero-client/src/client/zero-poke-handler.js.map +1 -1
- package/out/zero-client/src/client/zero.d.ts +1 -5
- package/out/zero-client/src/client/zero.d.ts.map +1 -1
- package/out/zero-client/src/client/zero.js +1 -1
- package/out/zero-client/src/client/zero.js.map +1 -1
- package/out/zero-client/src/types/client-state.d.ts +0 -6
- package/out/zero-client/src/types/client-state.d.ts.map +1 -1
- package/out/zero-permissions/src/permissions.d.ts +1 -12
- package/out/zero-permissions/src/permissions.d.ts.map +1 -1
- package/out/zero-permissions/src/permissions.js +1 -2
- package/out/zero-permissions/src/permissions.js.map +1 -1
- package/out/zero-protocol/src/ast.d.ts +0 -4
- package/out/zero-protocol/src/ast.d.ts.map +1 -1
- package/out/zero-protocol/src/ast.js +1 -2
- package/out/zero-protocol/src/ast.js.map +1 -1
- package/out/zero-protocol/src/change-desired-queries.d.ts +0 -20
- package/out/zero-protocol/src/change-desired-queries.d.ts.map +1 -1
- package/out/zero-protocol/src/change-desired-queries.js.map +1 -1
- package/out/zero-protocol/src/client-schema.d.ts +2 -5
- package/out/zero-protocol/src/client-schema.d.ts.map +1 -1
- package/out/zero-protocol/src/client-schema.js +1 -1
- package/out/zero-protocol/src/client-schema.js.map +1 -1
- package/out/zero-protocol/src/close-connection.d.ts +0 -8
- package/out/zero-protocol/src/close-connection.d.ts.map +1 -1
- package/out/zero-protocol/src/close-connection.js +1 -1
- package/out/zero-protocol/src/close-connection.js.map +1 -1
- package/out/zero-protocol/src/connect.d.ts +0 -12
- package/out/zero-protocol/src/connect.d.ts.map +1 -1
- package/out/zero-protocol/src/connect.js +1 -1
- package/out/zero-protocol/src/connect.js.map +1 -1
- package/out/zero-protocol/src/custom-queries.d.ts +3 -17
- package/out/zero-protocol/src/custom-queries.d.ts.map +1 -1
- package/out/zero-protocol/src/custom-queries.js +1 -1
- package/out/zero-protocol/src/custom-queries.js.map +1 -1
- package/out/zero-protocol/src/data.d.ts +0 -1
- package/out/zero-protocol/src/data.d.ts.map +1 -1
- package/out/zero-protocol/src/data.js +1 -1
- package/out/zero-protocol/src/data.js.map +1 -1
- package/out/zero-protocol/src/down.d.ts +27 -27
- package/out/zero-protocol/src/inspect-down.d.ts +82 -84
- package/out/zero-protocol/src/inspect-down.d.ts.map +1 -1
- package/out/zero-protocol/src/inspect-down.js +1 -1
- package/out/zero-protocol/src/inspect-down.js.map +1 -1
- package/out/zero-protocol/src/inspect-up.d.ts +0 -28
- package/out/zero-protocol/src/inspect-up.d.ts.map +1 -1
- package/out/zero-protocol/src/inspect-up.js +1 -1
- package/out/zero-protocol/src/inspect-up.js.map +1 -1
- package/out/zero-protocol/src/mutate-server.d.ts +0 -21
- package/out/zero-protocol/src/mutate-server.d.ts.map +1 -1
- package/out/zero-protocol/src/mutate-server.js +1 -1
- package/out/zero-protocol/src/mutate-server.js.map +1 -1
- package/out/zero-protocol/src/mutation-type-enum.d.ts +0 -1
- package/out/zero-protocol/src/mutation-type-enum.d.ts.map +1 -1
- package/out/zero-protocol/src/mutation-type-enum.js.map +1 -1
- package/out/zero-protocol/src/mutation.d.ts +2 -4
- package/out/zero-protocol/src/mutation.d.ts.map +1 -1
- package/out/zero-protocol/src/mutation.js +1 -1
- package/out/zero-protocol/src/mutation.js.map +1 -1
- package/out/zero-protocol/src/mutations-patch.d.ts +0 -33
- package/out/zero-protocol/src/mutations-patch.d.ts.map +1 -1
- package/out/zero-protocol/src/mutations-patch.js +1 -1
- package/out/zero-protocol/src/mutations-patch.js.map +1 -1
- package/out/zero-protocol/src/ping.d.ts +0 -2
- package/out/zero-protocol/src/ping.d.ts.map +1 -1
- package/out/zero-protocol/src/ping.js +1 -1
- package/out/zero-protocol/src/ping.js.map +1 -1
- package/out/zero-protocol/src/poke.d.ts +3 -2
- package/out/zero-protocol/src/poke.d.ts.map +1 -1
- package/out/zero-protocol/src/poke.js +1 -1
- package/out/zero-protocol/src/poke.js.map +1 -1
- package/out/zero-protocol/src/pong.d.ts +0 -2
- package/out/zero-protocol/src/pong.d.ts.map +1 -1
- package/out/zero-protocol/src/pong.js +1 -1
- package/out/zero-protocol/src/pong.js.map +1 -1
- package/out/zero-protocol/src/pull.d.ts +2 -7
- package/out/zero-protocol/src/pull.d.ts.map +1 -1
- package/out/zero-protocol/src/pull.js +1 -1
- package/out/zero-protocol/src/pull.js.map +1 -1
- package/out/zero-protocol/src/push.d.ts +1 -3
- package/out/zero-protocol/src/push.d.ts.map +1 -1
- package/out/zero-protocol/src/push.js +1 -1
- package/out/zero-protocol/src/push.js.map +1 -1
- package/out/zero-protocol/src/queries-patch.d.ts +0 -16
- package/out/zero-protocol/src/queries-patch.d.ts.map +1 -1
- package/out/zero-protocol/src/queries-patch.js +1 -1
- package/out/zero-protocol/src/queries-patch.js.map +1 -1
- package/out/zero-protocol/src/query-server.d.ts +2 -41
- package/out/zero-protocol/src/query-server.d.ts.map +1 -1
- package/out/zero-protocol/src/query-server.js +1 -1
- package/out/zero-protocol/src/query-server.js.map +1 -1
- package/out/zero-protocol/src/up.d.ts +42 -42
- package/out/zero-protocol/src/version.d.ts +0 -1
- package/out/zero-protocol/src/version.d.ts.map +1 -1
- package/out/zero-protocol/src/version.js.map +1 -1
- package/out/zero-react/src/use-query.js +1 -1
- package/out/zero-react/src/use-query.js.map +1 -1
- package/out/zero-schema/src/builder/relationship-builder.d.ts +0 -2
- package/out/zero-schema/src/builder/relationship-builder.d.ts.map +1 -1
- package/out/zero-schema/src/builder/relationship-builder.js.map +1 -1
- package/out/zero-schema/src/builder/table-builder.d.ts +1 -1
- package/out/zero-schema/src/builder/table-builder.d.ts.map +1 -1
- package/out/zero-schema/src/builder/table-builder.js +1 -1
- package/out/zero-schema/src/builder/table-builder.js.map +1 -1
- package/out/zero-schema/src/schema-config.d.ts +0 -1
- package/out/zero-schema/src/schema-config.d.ts.map +1 -1
- package/out/zero-schema/src/schema-config.js +1 -1
- package/out/zero-schema/src/schema-config.js.map +1 -1
- package/out/zero-schema/src/table-schema.d.ts +3 -11
- package/out/zero-schema/src/table-schema.d.ts.map +1 -1
- package/out/zero-server/src/queries/process-queries.d.ts +2 -4
- package/out/zero-server/src/queries/process-queries.d.ts.map +1 -1
- package/out/zero-server/src/queries/process-queries.js.map +1 -1
- package/out/zero-solid/src/solid-view.d.ts +0 -2
- package/out/zero-solid/src/solid-view.d.ts.map +1 -1
- package/out/zero-solid/src/solid-view.js +1 -1
- package/out/zero-solid/src/solid-view.js.map +1 -1
- package/out/zero-types/src/name-mapper.d.ts +2 -1
- package/out/zero-types/src/name-mapper.d.ts.map +1 -1
- package/out/zero-types/src/name-mapper.js.map +1 -1
- package/out/zero-types/src/schema-value.d.ts +3 -2
- package/out/zero-types/src/schema-value.d.ts.map +1 -1
- package/out/zero-types/src/schema.d.ts +1 -1
- package/out/zero-types/src/schema.d.ts.map +1 -1
- package/out/zql/src/builder/builder.d.ts +1 -11
- package/out/zql/src/builder/builder.d.ts.map +1 -1
- package/out/zql/src/builder/builder.js +1 -1
- package/out/zql/src/builder/builder.js.map +1 -1
- package/out/zql/src/builder/filter.d.ts +0 -1
- package/out/zql/src/builder/filter.d.ts.map +1 -1
- package/out/zql/src/builder/filter.js.map +1 -1
- package/out/zql/src/error.d.ts +0 -5
- package/out/zql/src/error.d.ts.map +1 -1
- package/out/zql/src/error.js.map +1 -1
- package/out/zql/src/ivm/constraint.d.ts +0 -7
- package/out/zql/src/ivm/constraint.d.ts.map +1 -1
- package/out/zql/src/ivm/constraint.js +1 -1
- package/out/zql/src/ivm/constraint.js.map +1 -1
- package/out/zql/src/ivm/data.d.ts +0 -1
- package/out/zql/src/ivm/data.d.ts.map +1 -1
- package/out/zql/src/ivm/data.js.map +1 -1
- package/out/zql/src/ivm/memory-source.d.ts +1 -2
- package/out/zql/src/ivm/memory-source.d.ts.map +1 -1
- package/out/zql/src/ivm/memory-source.js +1 -1
- package/out/zql/src/ivm/memory-source.js.map +1 -1
- package/out/zql/src/ivm/stream.d.ts +0 -1
- package/out/zql/src/ivm/stream.d.ts.map +1 -1
- package/out/zql/src/ivm/stream.js.map +1 -1
- package/out/zql/src/ivm/union-fan-in.d.ts +0 -1
- package/out/zql/src/ivm/union-fan-in.d.ts.map +1 -1
- package/out/zql/src/ivm/union-fan-in.js +1 -1
- package/out/zql/src/ivm/union-fan-in.js.map +1 -1
- package/out/zql/src/ivm/view-apply-change.d.ts +5 -35
- package/out/zql/src/ivm/view-apply-change.d.ts.map +1 -1
- package/out/zql/src/ivm/view-apply-change.js +1 -1
- package/out/zql/src/ivm/view-apply-change.js.map +1 -1
- package/out/zql/src/mutate/crud.d.ts +1 -3
- package/out/zql/src/mutate/crud.d.ts.map +1 -1
- package/out/zql/src/mutate/crud.js +1 -1
- package/out/zql/src/mutate/crud.js.map +1 -1
- package/out/zql/src/mutate/mutator-registry.d.ts +1 -1
- package/out/zql/src/mutate/mutator-registry.d.ts.map +1 -1
- package/out/zql/src/mutate/mutator-registry.js.map +1 -1
- package/out/zql/src/mutate/mutator.d.ts +1 -1
- package/out/zql/src/mutate/mutator.d.ts.map +1 -1
- package/out/zql/src/mutate/mutator.js.map +1 -1
- package/out/zql/src/planner/planner-debug.d.ts +10 -9
- package/out/zql/src/planner/planner-debug.d.ts.map +1 -1
- package/out/zql/src/planner/planner-debug.js.map +1 -1
- package/out/zql/src/planner/planner-node.d.ts +0 -1
- package/out/zql/src/planner/planner-node.d.ts.map +1 -1
- package/out/zql/src/planner/planner-node.js.map +1 -1
- package/out/zql/src/planner/planner-warnings.d.ts +3 -3
- package/out/zql/src/planner/planner-warnings.d.ts.map +1 -1
- package/out/zql/src/planner/planner-warnings.js.map +1 -1
- package/out/zql/src/query/expression.d.ts +0 -22
- package/out/zql/src/query/expression.d.ts.map +1 -1
- package/out/zql/src/query/expression.js +1 -1
- package/out/zql/src/query/expression.js.map +1 -1
- package/out/zql/src/query/query-delegate-base.d.ts +0 -7
- package/out/zql/src/query/query-delegate-base.d.ts.map +1 -1
- package/out/zql/src/query/query-delegate-base.js +2 -2
- package/out/zql/src/query/query-delegate-base.js.map +1 -1
- package/out/zql/src/query/query-delegate.d.ts +1 -4
- package/out/zql/src/query/query-delegate.d.ts.map +1 -1
- package/out/zql/src/query/query-internals.d.ts +0 -3
- package/out/zql/src/query/query-internals.d.ts.map +1 -1
- package/out/zql/src/query/query-internals.js.map +1 -1
- package/out/zql/src/query/query-registry.d.ts +5 -5
- package/out/zql/src/query/query-registry.d.ts.map +1 -1
- package/out/zql/src/query/query-registry.js.map +1 -1
- package/out/zql/src/query/query.d.ts +2 -13
- package/out/zql/src/query/query.d.ts.map +1 -1
- package/out/zql/src/query/runnable-query-impl.d.ts +1 -19
- package/out/zql/src/query/runnable-query-impl.d.ts.map +1 -1
- package/out/zql/src/query/runnable-query-impl.js +1 -1
- package/out/zql/src/query/runnable-query-impl.js.map +1 -1
- package/out/zql/src/query/ttl.d.ts +2 -3
- package/out/zql/src/query/ttl.d.ts.map +1 -1
- package/out/zql/src/query/ttl.js.map +1 -1
- package/out/zqlite/src/query-builder.d.ts +0 -2
- package/out/zqlite/src/query-builder.d.ts.map +1 -1
- package/out/zqlite/src/query-builder.js +1 -1
- package/out/zqlite/src/query-builder.js.map +1 -1
- package/out/zqlite/src/table-source.d.ts +0 -1
- package/out/zqlite/src/table-source.d.ts.map +1 -1
- package/out/zqlite/src/table-source.js +1 -1
- package/out/zqlite/src/table-source.js.map +1 -1
- package/package.json +2 -3
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"custom.js","names":[],"sources":["../../../../../zero-client/src/client/custom.ts"],"sourcesContent":["import type {LogContext} from '@rocicorp/logger';\nimport type {ZeroTxData} from '../../../replicache/src/replicache-options.ts';\nimport type {WriteTransactionImpl} from '../../../replicache/src/transactions.ts';\nimport {zeroData} from '../../../replicache/src/transactions.ts';\nimport {assert} from '../../../shared/src/asserts.ts';\nimport type {ReadonlyJSONValue} from '../../../shared/src/json.ts';\nimport {must} from '../../../shared/src/must.ts';\nimport {emptyFunction} from '../../../shared/src/sentinels.ts';\nimport type {DefaultSchema} from '../../../zero-types/src/default-types.ts';\nimport type {Schema} from '../../../zero-types/src/schema.ts';\nimport {\n makeTransactionMutate,\n type TransactionMutate,\n} from '../../../zql/src/mutate/crud.ts';\nimport type {\n ClientTransaction,\n Transaction,\n} from '../../../zql/src/mutate/custom.ts';\nimport {createRunnableBuilder} from '../../../zql/src/query/create-builder.ts';\nimport {\n type HumanReadable,\n type Query,\n type RunOptions,\n} from '../../../zql/src/query/query.ts';\nimport type {ConditionalSchemaQuery} from '../../../zql/src/query/schema-query.ts';\nimport type {ClientID} from '../types/client-state.ts';\nimport {ZeroContext} from './context.ts';\nimport {makeCRUDExecutor} from './crud.ts';\nimport type {IVMSourceBranch} from './ivm-branch.ts';\nimport type {WriteTransaction} from './replicache-types.ts';\n\n/**\n * The shape which a user's custom mutator definitions must conform to.\n * Supports arbitrary depth nesting of namespaces.\n */\nexport type CustomMutatorDefs = {\n // oxlint-disable-next-line no-explicit-any\n [namespaceOrKey: string]: CustomMutatorImpl<any> | CustomMutatorDefs;\n};\n\nexport type MutatorResultDetails =\n | {\n readonly type: 'success';\n readonly data?: ReadonlyJSONValue | undefined;\n }\n | {\n readonly type: 'error';\n readonly error:\n | {\n readonly type: 'app';\n readonly message: string;\n readonly details: ReadonlyJSONValue | undefined;\n }\n | {\n readonly type: 'zero';\n readonly message: string;\n };\n };\n\nexport type MutatorResultSuccessDetails = Extract<\n MutatorResultDetails,\n {type: 'success'}\n>;\nexport type MutatorResultErrorDetails = Extract<\n MutatorResultDetails,\n {type: 'error'}\n>;\n\nexport type MutatorResult = {\n client: Promise<MutatorResultDetails & {}>;\n server: Promise<MutatorResultDetails & {}>;\n} & {};\n\nexport type CustomMutatorImpl<\n S extends Schema,\n TWrappedTransaction = unknown,\n // oxlint-disable-next-line @typescript-eslint/no-explicit-any\n TArgs = any,\n Context = unknown,\n> = (\n tx: Transaction<S, TWrappedTransaction>,\n // TODO: many args. See commit: 52657c2f934b4a458d628ea77e56ce92b61eb3c6 which did have many args.\n // The issue being that it will be a protocol change to support varargs.\n args: TArgs,\n ctx: Context,\n) => Promise<ReadonlyJSONValue | void>;\n\n/**\n * The shape exposed on the `Zero.mutate` instance.\n * The signature of a custom mutator takes a `transaction` as its first arg\n * but the user does not provide this arg when calling the mutator.\n *\n * This utility strips the `tx` arg from the user's custom mutator signatures.\n * Supports arbitrary depth nesting of namespaces.\n */\nexport type MakeCustomMutatorInterfaces<\n S extends Schema,\n MD extends CustomMutatorDefs,\n TContext,\n> = {\n readonly [NamespaceOrName in keyof MD]: MD[NamespaceOrName] extends (\n tx: Transaction<S>,\n ...args: infer Args\n ) => Promise<unknown>\n ? (...args: Args) => MutatorResult\n : MD[NamespaceOrName] extends CustomMutatorDefs\n ? MakeCustomMutatorInterfaces<S, MD[NamespaceOrName], TContext>\n : never;\n};\n\nexport type MakeCustomMutatorInterface<TSchema extends Schema, F> = F extends (\n tx: ClientTransaction<TSchema>,\n ...args: infer Args\n) => Promise<unknown>\n ? (...args: Args) => MutatorResult\n : never;\n\nexport class TransactionImpl<\n TSchema extends Schema = DefaultSchema,\n> implements ClientTransaction<TSchema> {\n readonly location = 'client';\n readonly mutate: TransactionMutate<TSchema>;\n /**\n * @deprecated Use {@link createBuilder} with `tx.run(zql.table.where(...))` instead.\n */\n readonly query: ConditionalSchemaQuery<TSchema>;\n\n readonly #repTx: WriteTransaction;\n readonly #zeroContext: ZeroContext;\n\n constructor(lc: LogContext, repTx: WriteTransaction, schema: TSchema) {\n must(repTx.reason === 'initial' || repTx.reason === 'rebase');\n const txData = getZeroTxData(repTx);\n const ivmBranch = txData.ivmSources as IVMSourceBranch;\n\n this.#repTx = repTx;\n\n const executor = makeCRUDExecutor(repTx, schema, ivmBranch);\n this.mutate = makeTransactionMutate(schema, executor);\n\n const zeroContext = newZeroContext(\n lc,\n txData.ivmSources as IVMSourceBranch,\n );\n\n this.query = createRunnableBuilder(zeroContext, schema);\n\n this.#zeroContext = zeroContext;\n }\n\n get clientID(): ClientID {\n return this.#repTx.clientID;\n }\n\n get mutationID(): number {\n return this.#repTx.mutationID;\n }\n\n get reason(): 'optimistic' | 'rebase' {\n return this.#repTx.reason === 'initial' ? 'optimistic' : 'rebase';\n }\n\n get token(): string | undefined {\n return (this.#repTx as WriteTransactionImpl)[zeroData]?.token;\n }\n\n run<TTable extends keyof TSchema['tables'] & string, TReturn>(\n query: Query<TTable, TSchema, TReturn>,\n options?: RunOptions,\n ): Promise<HumanReadable<TReturn>> {\n return this.#zeroContext.run(query, options);\n }\n}\n\
|
|
1
|
+
{"version":3,"file":"custom.js","names":[],"sources":["../../../../../zero-client/src/client/custom.ts"],"sourcesContent":["import type {LogContext} from '@rocicorp/logger';\nimport type {ZeroTxData} from '../../../replicache/src/replicache-options.ts';\nimport type {WriteTransactionImpl} from '../../../replicache/src/transactions.ts';\nimport {zeroData} from '../../../replicache/src/transactions.ts';\nimport {assert} from '../../../shared/src/asserts.ts';\nimport type {ReadonlyJSONValue} from '../../../shared/src/json.ts';\nimport {must} from '../../../shared/src/must.ts';\nimport {emptyFunction} from '../../../shared/src/sentinels.ts';\nimport type {DefaultSchema} from '../../../zero-types/src/default-types.ts';\nimport type {Schema} from '../../../zero-types/src/schema.ts';\nimport {\n makeTransactionMutate,\n type TransactionMutate,\n} from '../../../zql/src/mutate/crud.ts';\nimport type {\n ClientTransaction,\n Transaction,\n} from '../../../zql/src/mutate/custom.ts';\nimport {createRunnableBuilder} from '../../../zql/src/query/create-builder.ts';\nimport {\n type HumanReadable,\n type Query,\n type RunOptions,\n} from '../../../zql/src/query/query.ts';\nimport type {ConditionalSchemaQuery} from '../../../zql/src/query/schema-query.ts';\nimport type {ClientID} from '../types/client-state.ts';\nimport {ZeroContext} from './context.ts';\nimport {makeCRUDExecutor} from './crud.ts';\nimport type {IVMSourceBranch} from './ivm-branch.ts';\nimport type {WriteTransaction} from './replicache-types.ts';\n\n/**\n * The shape which a user's custom mutator definitions must conform to.\n * Supports arbitrary depth nesting of namespaces.\n */\nexport type CustomMutatorDefs = {\n // oxlint-disable-next-line no-explicit-any\n [namespaceOrKey: string]: CustomMutatorImpl<any> | CustomMutatorDefs;\n};\n\nexport type MutatorResultDetails =\n | {\n readonly type: 'success';\n readonly data?: ReadonlyJSONValue | undefined;\n }\n | {\n readonly type: 'error';\n readonly error:\n | {\n readonly type: 'app';\n readonly message: string;\n readonly details: ReadonlyJSONValue | undefined;\n }\n | {\n readonly type: 'zero';\n readonly message: string;\n };\n };\n\nexport type MutatorResultSuccessDetails = Extract<\n MutatorResultDetails,\n {type: 'success'}\n>;\nexport type MutatorResultErrorDetails = Extract<\n MutatorResultDetails,\n {type: 'error'}\n>;\n\nexport type MutatorResult = {\n client: Promise<MutatorResultDetails & {}>;\n server: Promise<MutatorResultDetails & {}>;\n} & {};\n\nexport type CustomMutatorImpl<\n S extends Schema,\n TWrappedTransaction = unknown,\n // oxlint-disable-next-line @typescript-eslint/no-explicit-any\n TArgs = any,\n Context = unknown,\n> = (\n tx: Transaction<S, TWrappedTransaction>,\n // TODO: many args. See commit: 52657c2f934b4a458d628ea77e56ce92b61eb3c6 which did have many args.\n // The issue being that it will be a protocol change to support varargs.\n args: TArgs,\n ctx: Context,\n) => Promise<ReadonlyJSONValue | void>;\n\n/**\n * The shape exposed on the `Zero.mutate` instance.\n * The signature of a custom mutator takes a `transaction` as its first arg\n * but the user does not provide this arg when calling the mutator.\n *\n * This utility strips the `tx` arg from the user's custom mutator signatures.\n * Supports arbitrary depth nesting of namespaces.\n */\nexport type MakeCustomMutatorInterfaces<\n S extends Schema,\n MD extends CustomMutatorDefs,\n TContext,\n> = {\n readonly [NamespaceOrName in keyof MD]: MD[NamespaceOrName] extends (\n tx: Transaction<S>,\n ...args: infer Args\n ) => Promise<unknown>\n ? (...args: Args) => MutatorResult\n : MD[NamespaceOrName] extends CustomMutatorDefs\n ? MakeCustomMutatorInterfaces<S, MD[NamespaceOrName], TContext>\n : never;\n};\n\nexport type MakeCustomMutatorInterface<TSchema extends Schema, F> = F extends (\n tx: ClientTransaction<TSchema>,\n ...args: infer Args\n) => Promise<unknown>\n ? (...args: Args) => MutatorResult\n : never;\n\nexport class TransactionImpl<\n TSchema extends Schema = DefaultSchema,\n> implements ClientTransaction<TSchema> {\n readonly location = 'client';\n readonly mutate: TransactionMutate<TSchema>;\n /**\n * @deprecated Use {@link createBuilder} with `tx.run(zql.table.where(...))` instead.\n */\n readonly query: ConditionalSchemaQuery<TSchema>;\n\n readonly #repTx: WriteTransaction;\n readonly #zeroContext: ZeroContext;\n\n constructor(lc: LogContext, repTx: WriteTransaction, schema: TSchema) {\n must(repTx.reason === 'initial' || repTx.reason === 'rebase');\n const txData = getZeroTxData(repTx);\n const ivmBranch = txData.ivmSources as IVMSourceBranch;\n\n this.#repTx = repTx;\n\n const executor = makeCRUDExecutor(repTx, schema, ivmBranch);\n this.mutate = makeTransactionMutate(schema, executor);\n\n const zeroContext = newZeroContext(\n lc,\n txData.ivmSources as IVMSourceBranch,\n );\n\n this.query = createRunnableBuilder(zeroContext, schema);\n\n this.#zeroContext = zeroContext;\n }\n\n get clientID(): ClientID {\n return this.#repTx.clientID;\n }\n\n get mutationID(): number {\n return this.#repTx.mutationID;\n }\n\n get reason(): 'optimistic' | 'rebase' {\n return this.#repTx.reason === 'initial' ? 'optimistic' : 'rebase';\n }\n\n get token(): string | undefined {\n return (this.#repTx as WriteTransactionImpl)[zeroData]?.token;\n }\n\n run<TTable extends keyof TSchema['tables'] & string, TReturn>(\n query: Query<TTable, TSchema, TReturn>,\n options?: RunOptions,\n ): Promise<HumanReadable<TReturn>> {\n return this.#zeroContext.run(query, options);\n }\n}\n\nfunction getZeroTxData(repTx: WriteTransaction): ZeroTxData {\n const txData = must(\n (repTx as WriteTransactionImpl)[zeroData],\n 'zero was not set on replicache internal options!',\n );\n return txData as ZeroTxData;\n}\n\nexport function makeReplicacheMutator<\n S extends Schema,\n TWrappedTransaction,\n Context,\n>(\n lc: LogContext,\n mutator: CustomMutatorImpl<S, TWrappedTransaction>,\n schema: S,\n context: Context,\n): (\n repTx: WriteTransaction,\n args: ReadonlyJSONValue,\n) => Promise<ReadonlyJSONValue | void> {\n return async (repTx: WriteTransaction, args: ReadonlyJSONValue) => {\n const tx = new TransactionImpl(lc, repTx, schema);\n return await mutator(tx, args, context);\n };\n}\n\nfunction assertValidRunOptions(options: RunOptions | undefined): void {\n // TODO(arv): We should enforce this with the type system too.\n assert(\n options?.type !== 'complete' && options?.type !== 'cached',\n 'Cannot wait for cached or complete results in custom mutations',\n );\n}\n\nfunction newZeroContext(lc: LogContext, ivmBranch: IVMSourceBranch) {\n // The forked branch is already populated, so there is nothing to defer.\n return new ZeroContext(\n lc,\n ivmBranch,\n () => emptyFunction,\n () => emptyFunction,\n emptyFunction,\n emptyFunction,\n emptyFunction,\n applyViewUpdates => applyViewUpdates(),\n emptyFunction,\n assertValidRunOptions,\n ).markPipelinesReady();\n}\n"],"mappings":";;;;;;;;;;AAqHA,IAAa,kBAAb,MAEwC;CACtC,WAAoB;CACpB;;;;CAIA;CAEA;CACA;CAEA,YAAY,IAAgB,OAAyB,QAAiB;EACpE,KAAK,MAAM,WAAW,aAAa,MAAM,WAAW,QAAQ;EAC5D,MAAM,SAAS,cAAc,KAAK;EAClC,MAAM,YAAY,OAAO;EAEzB,KAAK,SAAS;EAEd,MAAM,WAAW,iBAAiB,OAAO,QAAQ,SAAS;EAC1D,KAAK,SAAS,sBAAsB,QAAQ,QAAQ;EAEpD,MAAM,cAAc,eAClB,IACA,OAAO,UACT;EAEA,KAAK,QAAQ,sBAAsB,aAAa,MAAM;EAEtD,KAAK,eAAe;CACtB;CAEA,IAAI,WAAqB;EACvB,OAAO,KAAK,OAAO;CACrB;CAEA,IAAI,aAAqB;EACvB,OAAO,KAAK,OAAO;CACrB;CAEA,IAAI,SAAkC;EACpC,OAAO,KAAK,OAAO,WAAW,YAAY,eAAe;CAC3D;CAEA,IAAI,QAA4B;EAC9B,OAAQ,KAAK,OAAgC,SAAS,EAAE;CAC1D;CAEA,IACE,OACA,SACiC;EACjC,OAAO,KAAK,aAAa,IAAI,OAAO,OAAO;CAC7C;AACF;AAEA,SAAS,cAAc,OAAqC;CAK1D,OAJe,KACZ,MAA+B,WAChC,kDAEK;AACT;AAEA,SAAgB,sBAKd,IACA,SACA,QACA,SAIqC;CACrC,OAAO,OAAO,OAAyB,SAA4B;EAEjE,OAAO,MAAM,QAAQ,IADN,gBAAgB,IAAI,OAAO,MACrB,GAAI,MAAM,OAAO;CACxC;AACF;AAEA,SAAS,sBAAsB,SAAuC;CAEpE,OACE,SAAS,SAAS,cAAc,SAAS,SAAS,UAClD,gEACF;AACF;AAEA,SAAS,eAAe,IAAgB,WAA4B;CAElE,OAAO,IAAI,YACT,IACA,iBACM,qBACA,eACN,eACA,eACA,gBACA,qBAAoB,iBAAiB,GACrC,eACA,qBACF,CAAC,CAAC,mBAAmB;AACvB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"enable-analytics.d.ts","sourceRoot":"","sources":["../../../../../zero-client/src/client/enable-analytics.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"enable-analytics.d.ts","sourceRoot":"","sources":["../../../../../zero-client/src/client/enable-analytics.ts"],"names":[],"mappings":"AAWA,wBAAgB,qBAAqB,CACnC,MAAM,EAAE,MAAM,GAAG,IAAI,EACrB,eAAe,UAAO,GACrB,OAAO,CAeT"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
//#region ../zero-client/src/client/enable-analytics.ts
|
|
1
2
|
var IP_ADDRESS_HOSTNAME_REGEX = new RegExp(`(${/^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/.source}|${/^\[[a-fA-F0-9:]*:[a-fA-F0-9:]*\]$/.source})`);
|
|
2
3
|
function shouldEnableAnalytics(server, enableAnalytics = true) {
|
|
3
4
|
if (!enableAnalytics) return false;
|
|
@@ -5,6 +6,6 @@ function shouldEnableAnalytics(server, enableAnalytics = true) {
|
|
|
5
6
|
return server !== null && socketHostname !== void 0 && socketHostname !== "localhost" && !IP_ADDRESS_HOSTNAME_REGEX.test(socketHostname);
|
|
6
7
|
}
|
|
7
8
|
//#endregion
|
|
8
|
-
export {
|
|
9
|
+
export { shouldEnableAnalytics };
|
|
9
10
|
|
|
10
11
|
//# sourceMappingURL=enable-analytics.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"enable-analytics.js","names":[],"sources":["../../../../../zero-client/src/client/enable-analytics.ts"],"sourcesContent":["// https://www.oreilly.com/library/view/regular-expressions-cookbook/9780596802837/ch07s16.html\nconst IPV4_ADDRESS_REGEX =\n /^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/;\n// This doesn't ensure a valid ipv6, but any ipv6 hostname will\n// match this regex, and no domain based hostnames will.\nconst IPV6_ADDRESS_HOSTNAME_REGEX = /^\\[[a-fA-F0-9:]*:[a-fA-F0-9:]*\\]$/;\n\
|
|
1
|
+
{"version":3,"file":"enable-analytics.js","names":[],"sources":["../../../../../zero-client/src/client/enable-analytics.ts"],"sourcesContent":["// https://www.oreilly.com/library/view/regular-expressions-cookbook/9780596802837/ch07s16.html\nconst IPV4_ADDRESS_REGEX =\n /^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/;\n// This doesn't ensure a valid ipv6, but any ipv6 hostname will\n// match this regex, and no domain based hostnames will.\nconst IPV6_ADDRESS_HOSTNAME_REGEX = /^\\[[a-fA-F0-9:]*:[a-fA-F0-9:]*\\]$/;\n\nconst IP_ADDRESS_HOSTNAME_REGEX = new RegExp(\n `(${IPV4_ADDRESS_REGEX.source}|${IPV6_ADDRESS_HOSTNAME_REGEX.source})`,\n);\n\nexport function shouldEnableAnalytics(\n server: string | null,\n enableAnalytics = true,\n): boolean {\n if (!enableAnalytics) {\n return false;\n }\n const serverURL = server === null ? null : new URL(server);\n const socketHostname = serverURL?.hostname;\n // If the hostname is undefined, localhost, or an ip address, then\n // this is most likely a test or local development, in which case we\n // do not want to enable analytics.\n return (\n server !== null &&\n socketHostname !== undefined &&\n socketHostname !== 'localhost' &&\n !IP_ADDRESS_HOSTNAME_REGEX.test(socketHostname)\n );\n}\n"],"mappings":";AAOA,IAAM,4BAA4B,IAAI,OACpC,IAAI,8FAAmB,OAAO,GAAG,oCAA4B,OAAO,EACtE;AAEA,SAAgB,sBACd,QACA,kBAAkB,MACT;CACT,IAAI,CAAC,iBACH,OAAO;CAGT,MAAM,kBADY,WAAW,OAAO,OAAO,IAAI,IAAI,MAAM,EAAA,EACvB;CAIlC,OACE,WAAW,QACX,mBAAmB,KAAA,KACnB,mBAAmB,eACnB,CAAC,0BAA0B,KAAK,cAAc;AAElD"}
|
|
@@ -16,7 +16,7 @@ export type ClosedError = ClientError<{
|
|
|
16
16
|
kind: ClientErrorKind.ClientClosed;
|
|
17
17
|
message: string;
|
|
18
18
|
}>;
|
|
19
|
-
|
|
19
|
+
type NeedsAuthReason = Expand<(ErrorBody & {
|
|
20
20
|
kind: ErrorKind.AuthInvalidated | ErrorKind.Unauthorized;
|
|
21
21
|
}) | (Extract<PushFailedBody, {
|
|
22
22
|
reason: ErrorReason.HTTP;
|
|
@@ -31,19 +31,17 @@ export type OfflineError = ClientError<{
|
|
|
31
31
|
kind: ClientErrorKind.Offline;
|
|
32
32
|
message: string;
|
|
33
33
|
}>;
|
|
34
|
-
|
|
34
|
+
type NoSocketOriginError = ClientError<{
|
|
35
35
|
kind: ClientErrorKind.NoSocketOrigin;
|
|
36
36
|
message: string;
|
|
37
37
|
}>;
|
|
38
|
-
|
|
38
|
+
type HiddenError = ClientError<{
|
|
39
39
|
kind: ClientErrorKind.Hidden;
|
|
40
40
|
message: string;
|
|
41
41
|
}>;
|
|
42
42
|
export type DisconnectedReason = OfflineError | NoSocketOriginError | HiddenError;
|
|
43
43
|
export type ServerError = ProtocolError<ErrorBody>;
|
|
44
44
|
export type ZeroError = ServerError | ClientError;
|
|
45
|
-
export type ZeroErrorBody = Expand<ErrorBody | ClientErrorBody>;
|
|
46
|
-
export type ZeroErrorDetails = Expand<Omit<ZeroErrorBody, 'message'>>;
|
|
47
45
|
export type ZeroErrorKind = Expand<ErrorKind | ClientErrorKind>;
|
|
48
46
|
/**
|
|
49
47
|
* Represents an error encountered by the Zero client.
|
|
@@ -83,4 +81,5 @@ export type ErrorConnectionTransition = {
|
|
|
83
81
|
* indicates that the connection should continue in the current state.
|
|
84
82
|
*/
|
|
85
83
|
export declare function getErrorConnectionTransition(ex: unknown): ErrorConnectionTransition;
|
|
84
|
+
export {};
|
|
86
85
|
//# sourceMappingURL=error.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"error.d.ts","sourceRoot":"","sources":["../../../../../zero-client/src/client/error.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAC,MAAM,EAAC,MAAM,+BAA+B,CAAC;AAC1D,OAAO,EAAC,SAAS,EAAC,MAAM,0CAA0C,CAAC;AACnE,OAAO,EAAC,WAAW,EAAC,MAAM,4CAA4C,CAAC;AACvE,OAAO,EAAC,WAAW,EAAC,MAAM,4CAA4C,CAAC;AACvE,OAAO,KAAK,EAAC,aAAa,EAAC,MAAM,qCAAqC,CAAC;AACvE,OAAO,EACL,KAAK,WAAW,EAChB,KAAK,SAAS,EAEd,KAAK,cAAc,EACnB,KAAK,mBAAmB,EACzB,MAAM,qCAAqC,CAAC;AAC7C,OAAO,EAAC,eAAe,EAAC,MAAM,wBAAwB,CAAC;AACvD,OAAO,EAAC,gBAAgB,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AAC,MAAM,EAAE,SAAS,CAAA;CAAC,CAAC;AAEzD;;;GAGG;AACH,wBAAgB,4BAA4B,CAC1C,EAAE,EAAE,OAAO,GACV,yBAAyB,CAmG3B"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"error.js","names":["ErrorOrigin.Client","ErrorKind.Rebalance","ErrorKind.Rehome","ErrorKind.ServerOverloaded","ConnectionStatus.NeedsAuth","ClientErrorKind.AbruptClose","ClientErrorKind.CleanClose","ClientErrorKind.ConnectTimeout","ClientErrorKind.PingTimeout","ClientErrorKind.PullTimeout","ClientErrorKind.UnexpectedBaseCookie","ClientErrorKind.Internal","ClientErrorKind.InvalidMessage","ClientErrorKind.UserDisconnect","ConnectionStatus.Error","ClientErrorKind.Hidden","ClientErrorKind.Offline","ClientErrorKind.NoSocketOrigin","ConnectionStatus.Disconnected","ClientErrorKind.ClientClosed","ConnectionStatus.Closed","ErrorKind.ClientNotFound","ErrorKind.InvalidConnectionRequest","ErrorKind.InvalidConnectionRequestBaseCookie","ErrorKind.InvalidConnectionRequestLastMutationID","ErrorKind.InvalidConnectionRequestClientDeleted","ErrorKind.InvalidMessage","ErrorKind.InvalidPush","ErrorKind.VersionNotSupported","ErrorKind.SchemaVersionNotSupported","ErrorKind.Internal","ErrorKind.PushFailed","ErrorKind.TransformFailed","ErrorKind.AuthInvalidated","ErrorKind.Unauthorized","ErrorKind.MutationRateLimited","ErrorKind.MutationFailed"],"sources":["../../../../../zero-client/src/client/error.ts"],"sourcesContent":["import {unreachable} from '../../../shared/src/asserts.ts';\nimport {getErrorMessage} from '../../../shared/src/error.ts';\nimport type {Expand} from '../../../shared/src/expand.ts';\nimport {ErrorKind} from '../../../zero-protocol/src/error-kind.ts';\nimport {ErrorOrigin} from '../../../zero-protocol/src/error-origin.ts';\nimport {ErrorReason} from '../../../zero-protocol/src/error-reason.ts';\nimport type {ProtocolError} from '../../../zero-protocol/src/error.ts';\nimport {\n type BackoffBody,\n type ErrorBody,\n isProtocolError,\n type PushFailedBody,\n type TransformFailedBody,\n} from '../../../zero-protocol/src/error.ts';\nimport {ClientErrorKind} from './client-error-kind.ts';\nimport {ConnectionStatus} from './connection-status.ts';\n\nexport type AuthError = ProtocolError<NeedsAuthReason>;\nexport type ClientErrorBody = {\n kind: ClientErrorKind;\n origin: typeof ErrorOrigin.Client;\n message: string;\n};\nexport type ClosedError = ClientError<{\n kind: ClientErrorKind.ClientClosed;\n message: string;\n}>;\nexport type NeedsAuthReason = Expand<\n | (ErrorBody & {\n kind: ErrorKind.AuthInvalidated | ErrorKind.Unauthorized;\n })\n | (Extract<PushFailedBody, {reason: ErrorReason.HTTP}> & {status: 401 | 403})\n | (Extract<TransformFailedBody, {reason: ErrorReason.HTTP}> & {\n status: 401 | 403;\n })\n>;\nexport type OfflineError = ClientError<{\n kind: ClientErrorKind.Offline;\n message: string;\n}>;\nexport type NoSocketOriginError = ClientError<{\n kind: ClientErrorKind.NoSocketOrigin;\n message: string;\n}>;\nexport type HiddenError = ClientError<{\n kind: ClientErrorKind.Hidden;\n message: string;\n}>;\nexport type DisconnectedReason =\n | OfflineError\n | NoSocketOriginError\n | HiddenError;\nexport type ServerError = ProtocolError<ErrorBody>;\nexport type ZeroError = ServerError | ClientError;\nexport type ZeroErrorBody = Expand<ErrorBody | ClientErrorBody>;\nexport type ZeroErrorDetails = Expand<Omit<ZeroErrorBody, 'message'>>;\nexport type ZeroErrorKind = Expand<ErrorKind | ClientErrorKind>;\n\n/**\n * Represents an error encountered by the Zero client.\n */\nexport class ClientError<\n const T extends Omit<ClientErrorBody, 'origin'> = Omit<\n ClientErrorBody,\n 'origin'\n >,\n> extends Error {\n readonly errorBody: {origin: typeof ErrorOrigin.Client} & T;\n\n constructor(errorBody: T, options?: ErrorOptions) {\n super(errorBody.message, options);\n this.name = 'ClientError';\n this.errorBody = {...errorBody, origin: ErrorOrigin.Client};\n }\n\n get kind(): T['kind'] {\n return this.errorBody.kind;\n }\n}\n\nexport function isZeroError(ex: unknown): ex is ZeroError {\n return isClientError(ex) || isServerError(ex);\n}\n\nexport function isClientError(ex: unknown): ex is ClientError<ClientErrorBody> {\n return (\n ex instanceof ClientError && ex.errorBody.origin === ErrorOrigin.Client\n );\n}\n\nexport function isServerError(ex: unknown): ex is ServerError {\n return (\n isProtocolError(ex) &&\n (ex.errorBody.origin === ErrorOrigin.Server ||\n ex.errorBody.origin === ErrorOrigin.ZeroCache)\n );\n}\n\nexport function isOfflineError(ex: unknown): ex is OfflineError {\n return isClientError(ex) && ex.kind === ClientErrorKind.Offline;\n}\n\nexport function isAuthError(ex: unknown): ex is AuthError {\n if (isServerError(ex)) {\n if (\n ex.kind === ErrorKind.AuthInvalidated ||\n ex.kind === ErrorKind.Unauthorized\n ) {\n return true;\n }\n if (\n (ex.errorBody.kind === ErrorKind.PushFailed ||\n ex.errorBody.kind === ErrorKind.TransformFailed) &&\n ex.errorBody.reason === ErrorReason.HTTP &&\n (ex.errorBody.status === 401 || ex.errorBody.status === 403)\n ) {\n return true;\n }\n }\n\n return false;\n}\n\nexport function getBackoffParams(error: ZeroError): BackoffBody | undefined {\n if (isServerError(error)) {\n switch (error.errorBody.kind) {\n case ErrorKind.Rebalance:\n case ErrorKind.Rehome:\n case ErrorKind.ServerOverloaded:\n return error.errorBody;\n }\n }\n return undefined;\n}\n\nexport const NO_STATUS_TRANSITION = 'NO_STATUS_TRANSITION';\n\nexport type ErrorConnectionTransition =\n | {status: typeof NO_STATUS_TRANSITION; reason: ZeroError}\n | {status: ConnectionStatus.NeedsAuth; reason: AuthError}\n | {status: ConnectionStatus.Error; reason: ZeroError}\n | {status: ConnectionStatus.Disconnected; reason: DisconnectedReason}\n | {status: ConnectionStatus.Closed; reason: ZeroError};\n\n/**\n * Returns the status to transition to, or null if the error\n * indicates that the connection should continue in the current state.\n */\nexport function getErrorConnectionTransition(\n ex: unknown,\n): ErrorConnectionTransition {\n // Handle auth errors by transitioning to needs-auth state\n if (isAuthError(ex)) {\n return {\n status: ConnectionStatus.NeedsAuth,\n reason: ex,\n } as const;\n }\n\n if (isClientError(ex)) {\n switch (ex.kind) {\n // Connecting errors that should continue in the current state\n case ClientErrorKind.AbruptClose:\n case ClientErrorKind.CleanClose:\n case ClientErrorKind.ConnectTimeout:\n case ClientErrorKind.PingTimeout:\n case ClientErrorKind.PullTimeout:\n case ClientErrorKind.UnexpectedBaseCookie:\n return {status: NO_STATUS_TRANSITION, reason: ex} as const;\n\n // Fatal errors that should transition to error state\n case ClientErrorKind.Internal:\n case ClientErrorKind.InvalidMessage:\n case ClientErrorKind.UserDisconnect:\n return {status: ConnectionStatus.Error, reason: ex} as const;\n\n // Disconnected errors\n case ClientErrorKind.Hidden:\n case ClientErrorKind.Offline:\n case ClientErrorKind.NoSocketOrigin:\n return {\n status: ConnectionStatus.Disconnected,\n reason: ex as DisconnectedReason,\n } as const;\n\n // Closed error (this should already result in a closed state)\n case ClientErrorKind.ClientClosed:\n return {status: ConnectionStatus.Closed, reason: ex} as const;\n\n default:\n unreachable(ex.kind);\n }\n }\n\n if (isServerError(ex)) {\n switch (ex.kind) {\n // Errors that should transition to error state\n case ErrorKind.ClientNotFound:\n case ErrorKind.InvalidConnectionRequest:\n case ErrorKind.InvalidConnectionRequestBaseCookie:\n case ErrorKind.InvalidConnectionRequestLastMutationID:\n case ErrorKind.InvalidConnectionRequestClientDeleted:\n case ErrorKind.InvalidMessage:\n case ErrorKind.InvalidPush:\n case ErrorKind.VersionNotSupported:\n case ErrorKind.SchemaVersionNotSupported:\n case ErrorKind.Internal:\n // PushFailed and TransformFailed can be auth errors (401/403)\n // or other errors - handle non-auth cases here\n case ErrorKind.PushFailed:\n case ErrorKind.TransformFailed:\n return {status: ConnectionStatus.Error, reason: ex} as const;\n\n // Errors that should continue with backoff/retry\n case ErrorKind.Rebalance:\n case ErrorKind.Rehome:\n case ErrorKind.ServerOverloaded:\n return {status: NO_STATUS_TRANSITION, reason: ex} as const;\n\n // Auth errors are handled above by isAuthError check\n case ErrorKind.AuthInvalidated:\n case ErrorKind.Unauthorized:\n return {\n status: ConnectionStatus.NeedsAuth,\n reason: ex as AuthError,\n } as const;\n\n // Mutation-specific errors don't affect connection state\n case ErrorKind.MutationRateLimited:\n case ErrorKind.MutationFailed:\n return {status: NO_STATUS_TRANSITION, reason: ex} as const;\n\n default:\n unreachable(ex.kind);\n }\n }\n\n // we default to error state if we don't know what to do\n // this is a catch-all for unexpected errors\n return {\n status: ConnectionStatus.Error,\n reason: new ClientError(\n {\n kind: ClientErrorKind.Internal,\n message: 'Unexpected internal error: ' + getErrorMessage(ex),\n },\n {cause: ex},\n ),\n } as const;\n}\n"],"mappings":";;;;;;;;;;;;AA6DA,IAAa,cAAb,cAKU,MAAM;CACd;CAEA,YAAY,WAAc,SAAwB;EAChD,MAAM,UAAU,SAAS,OAAO;EAChC,KAAK,OAAO;EACZ,KAAK,YAAY;GAAC,GAAG;GAAW,QAAQA;EAAkB;CAC5D;CAEA,IAAI,OAAkB;EACpB,OAAO,KAAK,UAAU;CACxB;AACF;AAEA,SAAgB,YAAY,IAA8B;CACxD,OAAO,cAAc,EAAE,KAAK,cAAc,EAAE;AAC9C;AAEA,SAAgB,cAAc,IAAiD;CAC7E,OACE,cAAc,eAAe,GAAG,UAAU,WAAW;AAEzD;AAEA,SAAgB,cAAc,IAAgC;CAC5D,OACE,gBAAgB,EAAE,MACjB,GAAG,UAAU,WAAW,YACvB,GAAG,UAAU,WAAW;AAE9B;AAMA,SAAgB,YAAY,IAA8B;CACxD,IAAI,cAAc,EAAE,GAAG;EACrB,IACE,GAAG,SAAS,qBACZ,GAAG,SAAS,gBAEZ,OAAO;EAET,KACG,GAAG,UAAU,SAAS,gBACrB,GAAG,UAAU,SAAS,sBACxB,GAAG,UAAU,WAAW,WACvB,GAAG,UAAU,WAAW,OAAO,GAAG,UAAU,WAAW,MAExD,OAAO;CAEX;CAEA,OAAO;AACT;AAEA,SAAgB,iBAAiB,OAA2C;CAC1E,IAAI,cAAc,KAAK,GACrB,QAAQ,MAAM,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,EAAC,OAAO,GAAE,CACZ;CACF;AACF"}
|
|
1
|
+
{"version":3,"file":"error.js","names":["ErrorOrigin.Client","ErrorKind.Rebalance","ErrorKind.Rehome","ErrorKind.ServerOverloaded","ConnectionStatus.NeedsAuth","ClientErrorKind.AbruptClose","ClientErrorKind.CleanClose","ClientErrorKind.ConnectTimeout","ClientErrorKind.PingTimeout","ClientErrorKind.PullTimeout","ClientErrorKind.UnexpectedBaseCookie","ClientErrorKind.Internal","ClientErrorKind.InvalidMessage","ClientErrorKind.UserDisconnect","ConnectionStatus.Error","ClientErrorKind.Hidden","ClientErrorKind.Offline","ClientErrorKind.NoSocketOrigin","ConnectionStatus.Disconnected","ClientErrorKind.ClientClosed","ConnectionStatus.Closed","ErrorKind.ClientNotFound","ErrorKind.InvalidConnectionRequest","ErrorKind.InvalidConnectionRequestBaseCookie","ErrorKind.InvalidConnectionRequestLastMutationID","ErrorKind.InvalidConnectionRequestClientDeleted","ErrorKind.InvalidMessage","ErrorKind.InvalidPush","ErrorKind.VersionNotSupported","ErrorKind.SchemaVersionNotSupported","ErrorKind.Internal","ErrorKind.PushFailed","ErrorKind.TransformFailed","ErrorKind.AuthInvalidated","ErrorKind.Unauthorized","ErrorKind.MutationRateLimited","ErrorKind.MutationFailed"],"sources":["../../../../../zero-client/src/client/error.ts"],"sourcesContent":["import {unreachable} from '../../../shared/src/asserts.ts';\nimport {getErrorMessage} from '../../../shared/src/error.ts';\nimport type {Expand} from '../../../shared/src/expand.ts';\nimport {ErrorKind} from '../../../zero-protocol/src/error-kind.ts';\nimport {ErrorOrigin} from '../../../zero-protocol/src/error-origin.ts';\nimport {ErrorReason} from '../../../zero-protocol/src/error-reason.ts';\nimport type {ProtocolError} from '../../../zero-protocol/src/error.ts';\nimport {\n type BackoffBody,\n type ErrorBody,\n isProtocolError,\n type PushFailedBody,\n type TransformFailedBody,\n} from '../../../zero-protocol/src/error.ts';\nimport {ClientErrorKind} from './client-error-kind.ts';\nimport {ConnectionStatus} from './connection-status.ts';\n\nexport type AuthError = ProtocolError<NeedsAuthReason>;\nexport type ClientErrorBody = {\n kind: ClientErrorKind;\n origin: typeof ErrorOrigin.Client;\n message: string;\n};\nexport type ClosedError = ClientError<{\n kind: ClientErrorKind.ClientClosed;\n message: string;\n}>;\ntype NeedsAuthReason = Expand<\n | (ErrorBody & {\n kind: ErrorKind.AuthInvalidated | ErrorKind.Unauthorized;\n })\n | (Extract<PushFailedBody, {reason: ErrorReason.HTTP}> & {status: 401 | 403})\n | (Extract<TransformFailedBody, {reason: ErrorReason.HTTP}> & {\n status: 401 | 403;\n })\n>;\nexport type OfflineError = ClientError<{\n kind: ClientErrorKind.Offline;\n message: string;\n}>;\ntype NoSocketOriginError = ClientError<{\n kind: ClientErrorKind.NoSocketOrigin;\n message: string;\n}>;\ntype HiddenError = ClientError<{\n kind: ClientErrorKind.Hidden;\n message: string;\n}>;\nexport type DisconnectedReason =\n | OfflineError\n | NoSocketOriginError\n | HiddenError;\nexport type ServerError = ProtocolError<ErrorBody>;\nexport type ZeroError = ServerError | ClientError;\nexport type ZeroErrorKind = Expand<ErrorKind | ClientErrorKind>;\n\n/**\n * Represents an error encountered by the Zero client.\n */\nexport class ClientError<\n const T extends Omit<ClientErrorBody, 'origin'> = Omit<\n ClientErrorBody,\n 'origin'\n >,\n> extends Error {\n readonly errorBody: {origin: typeof ErrorOrigin.Client} & T;\n\n constructor(errorBody: T, options?: ErrorOptions) {\n super(errorBody.message, options);\n this.name = 'ClientError';\n this.errorBody = {...errorBody, origin: ErrorOrigin.Client};\n }\n\n get kind(): T['kind'] {\n return this.errorBody.kind;\n }\n}\n\nexport function isZeroError(ex: unknown): ex is ZeroError {\n return isClientError(ex) || isServerError(ex);\n}\n\nexport function isClientError(ex: unknown): ex is ClientError<ClientErrorBody> {\n return (\n ex instanceof ClientError && ex.errorBody.origin === ErrorOrigin.Client\n );\n}\n\nexport function isServerError(ex: unknown): ex is ServerError {\n return (\n isProtocolError(ex) &&\n (ex.errorBody.origin === ErrorOrigin.Server ||\n ex.errorBody.origin === ErrorOrigin.ZeroCache)\n );\n}\n\nexport function isOfflineError(ex: unknown): ex is OfflineError {\n return isClientError(ex) && ex.kind === ClientErrorKind.Offline;\n}\n\nexport function isAuthError(ex: unknown): ex is AuthError {\n if (isServerError(ex)) {\n if (\n ex.kind === ErrorKind.AuthInvalidated ||\n ex.kind === ErrorKind.Unauthorized\n ) {\n return true;\n }\n if (\n (ex.errorBody.kind === ErrorKind.PushFailed ||\n ex.errorBody.kind === ErrorKind.TransformFailed) &&\n ex.errorBody.reason === ErrorReason.HTTP &&\n (ex.errorBody.status === 401 || ex.errorBody.status === 403)\n ) {\n return true;\n }\n }\n\n return false;\n}\n\nexport function getBackoffParams(error: ZeroError): BackoffBody | undefined {\n if (isServerError(error)) {\n switch (error.errorBody.kind) {\n case ErrorKind.Rebalance:\n case ErrorKind.Rehome:\n case ErrorKind.ServerOverloaded:\n return error.errorBody;\n }\n }\n return undefined;\n}\n\nexport const NO_STATUS_TRANSITION = 'NO_STATUS_TRANSITION';\n\nexport type ErrorConnectionTransition =\n | {status: typeof NO_STATUS_TRANSITION; reason: ZeroError}\n | {status: ConnectionStatus.NeedsAuth; reason: AuthError}\n | {status: ConnectionStatus.Error; reason: ZeroError}\n | {status: ConnectionStatus.Disconnected; reason: DisconnectedReason}\n | {status: ConnectionStatus.Closed; reason: ZeroError};\n\n/**\n * Returns the status to transition to, or null if the error\n * indicates that the connection should continue in the current state.\n */\nexport function getErrorConnectionTransition(\n ex: unknown,\n): ErrorConnectionTransition {\n // Handle auth errors by transitioning to needs-auth state\n if (isAuthError(ex)) {\n return {\n status: ConnectionStatus.NeedsAuth,\n reason: ex,\n } as const;\n }\n\n if (isClientError(ex)) {\n switch (ex.kind) {\n // Connecting errors that should continue in the current state\n case ClientErrorKind.AbruptClose:\n case ClientErrorKind.CleanClose:\n case ClientErrorKind.ConnectTimeout:\n case ClientErrorKind.PingTimeout:\n case ClientErrorKind.PullTimeout:\n case ClientErrorKind.UnexpectedBaseCookie:\n return {status: NO_STATUS_TRANSITION, reason: ex} as const;\n\n // Fatal errors that should transition to error state\n case ClientErrorKind.Internal:\n case ClientErrorKind.InvalidMessage:\n case ClientErrorKind.UserDisconnect:\n return {status: ConnectionStatus.Error, reason: ex} as const;\n\n // Disconnected errors\n case ClientErrorKind.Hidden:\n case ClientErrorKind.Offline:\n case ClientErrorKind.NoSocketOrigin:\n return {\n status: ConnectionStatus.Disconnected,\n reason: ex as DisconnectedReason,\n } as const;\n\n // Closed error (this should already result in a closed state)\n case ClientErrorKind.ClientClosed:\n return {status: ConnectionStatus.Closed, reason: ex} as const;\n\n default:\n unreachable(ex.kind);\n }\n }\n\n if (isServerError(ex)) {\n switch (ex.kind) {\n // Errors that should transition to error state\n case ErrorKind.ClientNotFound:\n case ErrorKind.InvalidConnectionRequest:\n case ErrorKind.InvalidConnectionRequestBaseCookie:\n case ErrorKind.InvalidConnectionRequestLastMutationID:\n case ErrorKind.InvalidConnectionRequestClientDeleted:\n case ErrorKind.InvalidMessage:\n case ErrorKind.InvalidPush:\n case ErrorKind.VersionNotSupported:\n case ErrorKind.SchemaVersionNotSupported:\n case ErrorKind.Internal:\n // PushFailed and TransformFailed can be auth errors (401/403)\n // or other errors - handle non-auth cases here\n case ErrorKind.PushFailed:\n case ErrorKind.TransformFailed:\n return {status: ConnectionStatus.Error, reason: ex} as const;\n\n // Errors that should continue with backoff/retry\n case ErrorKind.Rebalance:\n case ErrorKind.Rehome:\n case ErrorKind.ServerOverloaded:\n return {status: NO_STATUS_TRANSITION, reason: ex} as const;\n\n // Auth errors are handled above by isAuthError check\n case ErrorKind.AuthInvalidated:\n case ErrorKind.Unauthorized:\n return {\n status: ConnectionStatus.NeedsAuth,\n reason: ex as AuthError,\n } as const;\n\n // Mutation-specific errors don't affect connection state\n case ErrorKind.MutationRateLimited:\n case ErrorKind.MutationFailed:\n return {status: NO_STATUS_TRANSITION, reason: ex} as const;\n\n default:\n unreachable(ex.kind);\n }\n }\n\n // we default to error state if we don't know what to do\n // this is a catch-all for unexpected errors\n return {\n status: ConnectionStatus.Error,\n reason: new ClientError(\n {\n kind: ClientErrorKind.Internal,\n message: 'Unexpected internal error: ' + getErrorMessage(ex),\n },\n {cause: ex},\n ),\n } as const;\n}\n"],"mappings":";;;;;;;;;;;;AA2DA,IAAa,cAAb,cAKU,MAAM;CACd;CAEA,YAAY,WAAc,SAAwB;EAChD,MAAM,UAAU,SAAS,OAAO;EAChC,KAAK,OAAO;EACZ,KAAK,YAAY;GAAC,GAAG;GAAW,QAAQA;EAAkB;CAC5D;CAEA,IAAI,OAAkB;EACpB,OAAO,KAAK,UAAU;CACxB;AACF;AAEA,SAAgB,YAAY,IAA8B;CACxD,OAAO,cAAc,EAAE,KAAK,cAAc,EAAE;AAC9C;AAEA,SAAgB,cAAc,IAAiD;CAC7E,OACE,cAAc,eAAe,GAAG,UAAU,WAAW;AAEzD;AAEA,SAAgB,cAAc,IAAgC;CAC5D,OACE,gBAAgB,EAAE,MACjB,GAAG,UAAU,WAAW,YACvB,GAAG,UAAU,WAAW;AAE9B;AAMA,SAAgB,YAAY,IAA8B;CACxD,IAAI,cAAc,EAAE,GAAG;EACrB,IACE,GAAG,SAAS,qBACZ,GAAG,SAAS,gBAEZ,OAAO;EAET,KACG,GAAG,UAAU,SAAS,gBACrB,GAAG,UAAU,SAAS,sBACxB,GAAG,UAAU,WAAW,WACvB,GAAG,UAAU,WAAW,OAAO,GAAG,UAAU,WAAW,MAExD,OAAO;CAEX;CAEA,OAAO;AACT;AAEA,SAAgB,iBAAiB,OAA2C;CAC1E,IAAI,cAAc,KAAK,GACrB,QAAQ,MAAM,UAAU,MAAxB;EACE,KAAKC;EACL,KAAKC;EACL,KAAKC,kBACH,OAAO,MAAM;CACjB;AAGJ;AAEA,IAAa,uBAAuB;;;;;AAapC,SAAgB,6BACd,IAC2B;CAE3B,IAAI,YAAY,EAAE,GAChB,OAAO;EACL,QAAQC;EACR,QAAQ;CACV;CAGF,IAAI,cAAc,EAAE,GAClB,QAAQ,GAAG,MAAX;EAEE,KAAKC;EACL,KAAKC;EACL,KAAKC;EACL,KAAKC;EACL,KAAKC;EACL,KAAKC,sBACH,OAAO;GAAC,QAAQ;GAAsB,QAAQ;EAAE;EAGlD,KAAKC;EACL,KAAKC;EACL,KAAKC,gBACH,OAAO;GAAC,QAAQC;GAAwB,QAAQ;EAAE;EAGpD,KAAKC;EACL,KAAKC;EACL,KAAKC,gBACH,OAAO;GACL,QAAQC;GACR,QAAQ;EACV;EAGF,KAAKC,cACH,OAAO;GAAC,QAAQC;GAAyB,QAAQ;EAAE;EAErD,SACE,YAAY,GAAG,IAAI;CACvB;CAGF,IAAI,cAAc,EAAE,GAClB,QAAQ,GAAG,MAAX;EAEE,KAAKC;EACL,KAAKC;EACL,KAAKC;EACL,KAAKC;EACL,KAAKC;EACL,KAAKC;EACL,KAAKC;EACL,KAAKC;EACL,KAAKC;EACL,KAAKC;EAGL,KAAKC;EACL,KAAKC,iBACH,OAAO;GAAC,QAAQlB;GAAwB,QAAQ;EAAE;EAGpD,KAAKb;EACL,KAAKC;EACL,KAAKC,kBACH,OAAO;GAAC,QAAQ;GAAsB,QAAQ;EAAE;EAGlD,KAAK8B;EACL,KAAKC,cACH,OAAO;GACL,QAAQ9B;GACR,QAAQ;EACV;EAGF,KAAK+B;EACL,KAAKC,gBACH,OAAO;GAAC,QAAQ;GAAsB,QAAQ;EAAE;EAElD,SACE,YAAY,GAAG,IAAI;CACvB;CAKF,OAAO;EACL,QAAQtB;EACR,QAAQ,IAAI,YACV;GACE,MAAMH;GACN,SAAS,gCAAgC,gBAAgB,EAAE;EAC7D,GACA,EAAC,OAAO,GAAE,CACZ;CACF;AACF"}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import type { CompoundKey } from '../../../zero-protocol/src/ast.ts';
|
|
2
2
|
import type { Row } from '../../../zero-protocol/src/data.ts';
|
|
3
3
|
import type { MutationID } from '../../../zero-protocol/src/mutation-id.ts';
|
|
4
|
-
export declare const DESIRED_QUERIES_KEY_PREFIX = "d/";
|
|
5
4
|
export declare const GOT_QUERIES_KEY_PREFIX = "g/";
|
|
6
5
|
export declare const ENTITIES_KEY_PREFIX = "e/";
|
|
7
6
|
export declare const MUTATIONS_KEY_PREFIX = "m/";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"keys.d.ts","sourceRoot":"","sources":["../../../../../zero-client/src/client/keys.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAC,WAAW,EAAC,MAAM,mCAAmC,CAAC;AACnE,OAAO,KAAK,EAAC,GAAG,EAAC,MAAM,oCAAoC,CAAC;AAC5D,OAAO,KAAK,EAAC,UAAU,EAAC,MAAM,2CAA2C,CAAC;
|
|
1
|
+
{"version":3,"file":"keys.d.ts","sourceRoot":"","sources":["../../../../../zero-client/src/client/keys.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAC,WAAW,EAAC,MAAM,mCAAmC,CAAC;AACnE,OAAO,KAAK,EAAC,GAAG,EAAC,MAAM,oCAAoC,CAAC;AAC5D,OAAO,KAAK,EAAC,UAAU,EAAC,MAAM,2CAA2C,CAAC;AAI1E,eAAO,MAAM,sBAAsB,OAAO,CAAC;AAC3C,eAAO,MAAM,mBAAmB,OAAO,CAAC;AACxC,eAAO,MAAM,oBAAoB,OAAO,CAAC;AAEzC,wBAAgB,mBAAmB,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAE1E;AAED,wBAAgB,6BAA6B,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAEtE;AAED,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAEpD;AAED,wBAAgB,qBAAqB,CAAC,GAAG,EAAE,UAAU,GAAG,MAAM,CAE7D;AAED,wBAAgB,kBAAkB,CAChC,SAAS,EAAE,MAAM,EACjB,UAAU,EAAE,WAAW,EACvB,KAAK,EAAE,GAAG,GACT,MAAM,CAeR;AA0BD,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAGrD"}
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import { parse } from "../../../shared/src/valita.js";
|
|
2
2
|
import { h128 } from "../../../shared/src/hash.js";
|
|
3
3
|
import { primaryKeyValueSchema } from "../../../zero-protocol/src/primary-key.js";
|
|
4
|
+
//#region ../zero-client/src/client/keys.ts
|
|
5
|
+
var DESIRED_QUERIES_KEY_PREFIX = "d/";
|
|
4
6
|
function toDesiredQueriesKey(clientID, hash) {
|
|
5
|
-
return
|
|
7
|
+
return DESIRED_QUERIES_KEY_PREFIX + clientID + "/" + hash;
|
|
6
8
|
}
|
|
7
9
|
function desiredQueriesPrefixForClient(clientID) {
|
|
8
|
-
return
|
|
10
|
+
return DESIRED_QUERIES_KEY_PREFIX + clientID + "/";
|
|
9
11
|
}
|
|
10
12
|
function toGotQueriesKey(hash) {
|
|
11
13
|
return "g/" + hash;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"keys.js","names":["v.parse"],"sources":["../../../../../zero-client/src/client/keys.ts"],"sourcesContent":["import {h128} from '../../../shared/src/hash.ts';\nimport * as v from '../../../shared/src/valita.ts';\nimport type {CompoundKey} from '../../../zero-protocol/src/ast.ts';\nimport type {Row} from '../../../zero-protocol/src/data.ts';\nimport type {MutationID} from '../../../zero-protocol/src/mutation-id.ts';\nimport {primaryKeyValueSchema} from '../../../zero-protocol/src/primary-key.ts';\n\
|
|
1
|
+
{"version":3,"file":"keys.js","names":["v.parse"],"sources":["../../../../../zero-client/src/client/keys.ts"],"sourcesContent":["import {h128} from '../../../shared/src/hash.ts';\nimport * as v from '../../../shared/src/valita.ts';\nimport type {CompoundKey} from '../../../zero-protocol/src/ast.ts';\nimport type {Row} from '../../../zero-protocol/src/data.ts';\nimport type {MutationID} from '../../../zero-protocol/src/mutation-id.ts';\nimport {primaryKeyValueSchema} from '../../../zero-protocol/src/primary-key.ts';\n\nconst DESIRED_QUERIES_KEY_PREFIX = 'd/';\nexport const GOT_QUERIES_KEY_PREFIX = 'g/';\nexport const ENTITIES_KEY_PREFIX = 'e/';\nexport const MUTATIONS_KEY_PREFIX = 'm/';\n\nexport function toDesiredQueriesKey(clientID: string, hash: string): string {\n return DESIRED_QUERIES_KEY_PREFIX + clientID + '/' + hash;\n}\n\nexport function desiredQueriesPrefixForClient(clientID: string): string {\n return DESIRED_QUERIES_KEY_PREFIX + clientID + '/';\n}\n\nexport function toGotQueriesKey(hash: string): string {\n return GOT_QUERIES_KEY_PREFIX + hash;\n}\n\nexport function toMutationResponseKey(mid: MutationID): string {\n return MUTATIONS_KEY_PREFIX + mid.clientID + '/' + mid.id;\n}\n\nexport function toPrimaryKeyString(\n tableName: string,\n primaryKey: CompoundKey,\n value: Row,\n): string {\n if (primaryKey.length === 1) {\n return (\n ENTITIES_KEY_PREFIX +\n tableName +\n '/' +\n v.parse(value[primaryKey[0]], primaryKeyValueSchema)\n );\n }\n\n const values = primaryKey.map(k => v.parse(value[k], primaryKeyValueSchema));\n const str = JSON.stringify(values);\n\n const idSegment = u128ToDecimal(h128(str));\n return ENTITIES_KEY_PREFIX + tableName + '/' + idSegment;\n}\n\nconst E19 = 10n ** 19n;\n\n/**\n * `String(x)` for an unsigned 128-bit `x`: the decimal form entity keys have\n * always used for compound primary keys, so it must not change.\n *\n * Chromium 148 (V8 14.8) takes ~4us to stringify a bigint wider than 64 bits\n * in base 10, against ~100ns in node 24, Firefox and WebKit; bigints that fit\n * in 64 bits stay fast everywhere. Splitting `x` into base-10^19 pieces, each\n * under 2^64, keeps every conversion on that fast path: ~35x faster in\n * Chromium and within ~10% elsewhere.\n */\nfunction u128ToDecimal(x: bigint): string {\n if (x < E19) {\n return String(x);\n }\n const t = x / E19;\n const low = String(x % E19).padStart(19, '0');\n if (t < E19) {\n return String(t) + low;\n }\n return String(t / E19) + String(t % E19).padStart(19, '0') + low;\n}\n\nexport function sourceNameFromKey(key: string): string {\n const slash = key.indexOf('/', ENTITIES_KEY_PREFIX.length);\n return key.slice(ENTITIES_KEY_PREFIX.length, slash);\n}\n"],"mappings":";;;;AAOA,IAAM,6BAA6B;AAKnC,SAAgB,oBAAoB,UAAkB,MAAsB;CAC1E,OAAO,6BAA6B,WAAW,MAAM;AACvD;AAEA,SAAgB,8BAA8B,UAA0B;CACtE,OAAO,6BAA6B,WAAW;AACjD;AAEA,SAAgB,gBAAgB,MAAsB;CACpD,OAAA,OAAgC;AAClC;AAEA,SAAgB,sBAAsB,KAAyB;CAC7D,OAAA,OAA8B,IAAI,WAAW,MAAM,IAAI;AACzD;AAEA,SAAgB,mBACd,WACA,YACA,OACQ;CACR,IAAI,WAAW,WAAW,GACxB,OAAA,OAEE,YACA,MACAA,MAAQ,MAAM,WAAW,KAAK,qBAAqB;CAIvD,MAAM,SAAS,WAAW,KAAI,MAAKA,MAAQ,MAAM,IAAI,qBAAqB,CAAC;CAC3E,MAAM,MAAM,KAAK,UAAU,MAAM;CAEjC,MAAM,YAAY,cAAc,KAAK,GAAG,CAAC;CACzC,OAAA,OAA6B,YAAY,MAAM;AACjD;AAEA,IAAM,MAAM,OAAO;;;;;;;;;;;AAYnB,SAAS,cAAc,GAAmB;CACxC,IAAI,IAAI,KACN,OAAO,OAAO,CAAC;CAEjB,MAAM,IAAI,IAAI;CACd,MAAM,MAAM,OAAO,IAAI,GAAG,CAAC,CAAC,SAAS,IAAI,GAAG;CAC5C,IAAI,IAAI,KACN,OAAO,OAAO,CAAC,IAAI;CAErB,OAAO,OAAO,IAAI,GAAG,IAAI,OAAO,IAAI,GAAG,CAAC,CAAC,SAAS,IAAI,GAAG,IAAI;AAC/D;AAEA,SAAgB,kBAAkB,KAAqB;CACrD,MAAM,QAAQ,IAAI,QAAQ,KAAK,CAA0B;CACzD,OAAO,IAAI,MAAM,GAA4B,KAAK;AACpD"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mutation-tracker.d.ts","sourceRoot":"","sources":["../../../../../zero-client/src/client/mutation-tracker.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,UAAU,EAAC,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"mutation-tracker.d.ts","sourceRoot":"","sources":["../../../../../zero-client/src/client/mutation-tracker.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,UAAU,EAAC,MAAM,kBAAkB,CAAC;AAEjD,OAAO,KAAK,EAAC,cAAc,EAAC,MAAM,iCAAiC,CAAC;AACpE,OAAO,KAAK,EACV,WAAW,EACX,oBAAoB,EACrB,MAAM,+CAA+C,CAAC;AAGvD,OAAO,KAAK,EAAC,iBAAiB,EAAC,MAAM,6BAA6B,CAAC;AAcnE,OAAO,KAAK,EAAC,UAAU,EAAC,MAAM,2CAA2C,CAAC;AAM1E,OAAO,KAAK,EAGV,gBAAgB,EACjB,MAAM,oCAAoC,CAAC;AAC5C,OAAO,EAAc,KAAK,SAAS,EAAC,MAAM,YAAY,CAAC;AAGvD,KAAK,mBAAmB,GAAG,iBAAiB,GAAG,SAAS,CAAC;AAQzD;;GAEG;AACH,qBAAa,eAAe;;IAmB1B,YACE,EAAE,EAAE,UAAU,EACd,YAAY,EAAE,CAAC,IAAI,EAAE,UAAU,KAAK,IAAI,EACxC,YAAY,EAAE,CAAC,KAAK,EAAE,SAAS,KAAK,IAAI,EAUzC;IAED,mBAAmB,CACjB,QAAQ,EAAE,MAAM,EAChB,iBAAiB,EAAE,cAAc,CAAC,mBAAmB,CAAC,QAavD;IAED,aAAa,IAAI,oBAAoB,CAAC,mBAAmB,CAAC,CAQzD;IAED,kBAAkB,CAAC,EAAE,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,GAAG,IAAI,CAU5D;IAED;;;OAGG;IACH,cAAc,CAAC,EAAE,EAAE,WAAW,EAAE,CAAC,EAAE,OAAO,GAAG,IAAI,CAKhD;IAED;;;OAGG;IACH,6BAA6B,CAAC,KAAK,EAAE,SAAS,GAAG,IAAI,CASpD;IAiDD,mBAAmB,CAAC,QAAQ,EAAE,gBAAgB,GAAG,IAAI,CAapD;IA0CD;;;;;;;;;;;;;;;;;;;;OAoBG;IACH,WAAW,CAAC,cAAc,EAAE,MAAM,QAEjC;IAED;;;;;;OAMG;IACH,YAAY,CAAC,cAAc,EAAE,MAAM,GAAG,IAAI,CAkBzC;IAED,IAAI,IAAI,WAEP;IA2JD;;;;;;;;;OASG;IACH,qBAAqB,CAAC,QAAQ,EAAE,MAAM,IAAI,GAAG,IAAI,CAEhD;CAOF"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { assert, unreachable } from "../../../shared/src/asserts.js";
|
|
2
|
+
import { resolver } from "../../../shared/src/resolver.js";
|
|
2
3
|
import { parse } from "../../../shared/src/valita.js";
|
|
3
4
|
import { must } from "../../../shared/src/must.js";
|
|
4
5
|
import { getErrorDetails } from "../../../shared/src/error.js";
|
|
@@ -11,7 +12,6 @@ import { emptyObject } from "../../../shared/src/sentinels.js";
|
|
|
11
12
|
import { mutationResultSchema } from "../../../zero-protocol/src/mutation.js";
|
|
12
13
|
import { isZeroError } from "./error.js";
|
|
13
14
|
import "./keys.js";
|
|
14
|
-
import { resolver } from "@rocicorp/resolver";
|
|
15
15
|
//#region ../zero-client/src/client/mutation-tracker.ts
|
|
16
16
|
var currentEphemeralID = 0;
|
|
17
17
|
function nextEphemeralID() {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mutation-tracker.js","names":["v.parse","ErrorKind.PushFailed","ErrorOrigin.ZeroCache","ErrorReason.Internal","ErrorReason.HTTP","ErrorKind.InvalidPush","ErrorOrigin.Server"],"sources":["../../../../../zero-client/src/client/mutation-tracker.ts"],"sourcesContent":["import type {LogContext} from '@rocicorp/logger';\nimport {resolver, type Resolver} from '@rocicorp/resolver';\nimport type {NoIndexDiff} from '../../../replicache/src/btree/node.ts';\nimport type {ReplicacheImpl} from '../../../replicache/src/impl.ts';\nimport type {\n EphemeralID,\n MutationTrackingData,\n} from '../../../replicache/src/replicache-options.ts';\nimport {assert, unreachable} from '../../../shared/src/asserts.ts';\nimport {getErrorDetails} from '../../../shared/src/error.ts';\nimport type {ReadonlyJSONValue} from '../../../shared/src/json.ts';\nimport {must} from '../../../shared/src/must.ts';\nimport {emptyObject} from '../../../shared/src/sentinels.ts';\nimport * as v from '../../../shared/src/valita.ts';\nimport {\n ApplicationError,\n isApplicationError,\n wrapWithApplicationError,\n} from '../../../zero-protocol/src/application-error.ts';\nimport {ErrorKind} from '../../../zero-protocol/src/error-kind.ts';\nimport {ErrorOrigin} from '../../../zero-protocol/src/error-origin.ts';\nimport {ErrorReason} from '../../../zero-protocol/src/error-reason.ts';\nimport {ProtocolError} from '../../../zero-protocol/src/error.ts';\nimport type {MutationID} from '../../../zero-protocol/src/mutation-id.ts';\nimport {\n mutationResultSchema,\n type MutationError,\n type MutationOk,\n} from '../../../zero-protocol/src/mutation.ts';\nimport type {\n PushError,\n PushOk,\n PushResponseBody,\n} from '../../../zero-protocol/src/push.ts';\nimport {isZeroError, type ZeroError} from './error.ts';\nimport {MUTATIONS_KEY_PREFIX} from './keys.ts';\n\ntype MutationSuccessType = ReadonlyJSONValue | undefined;\ntype MutationErrorType = ApplicationError | ZeroError;\n\nlet currentEphemeralID = 0;\nfunction nextEphemeralID(): EphemeralID {\n return ++currentEphemeralID as EphemeralID;\n}\n\n/**\n * Tracks what pushes are in-flight and resolves promises when they're acked.\n */\nexport class MutationTracker {\n readonly #outstandingMutations: Map<\n EphemeralID,\n {\n mutationID?: number | undefined;\n resolver: Resolver<MutationSuccessType, MutationErrorType>;\n }\n >;\n readonly #ephemeralIDsByMutationID: Map<number, EphemeralID>;\n readonly #allMutationsAppliedListeners: Set<() => void>;\n readonly #lc: LogContext;\n\n readonly #ackMutations: (upTo: MutationID) => void;\n readonly #onFatalError: (error: ZeroError) => void;\n\n #clientID: string | undefined;\n #largestOutstandingMutationID: number;\n #currentMutationID: number;\n\n constructor(\n lc: LogContext,\n ackMutations: (upTo: MutationID) => void,\n onFatalError: (error: ZeroError) => void,\n ) {\n this.#lc = lc.withContext('MutationTracker');\n this.#outstandingMutations = new Map();\n this.#ephemeralIDsByMutationID = new Map();\n this.#allMutationsAppliedListeners = new Set();\n this.#largestOutstandingMutationID = 0;\n this.#currentMutationID = 0;\n this.#ackMutations = ackMutations;\n this.#onFatalError = onFatalError;\n }\n\n setClientIDAndWatch(\n clientID: string,\n experimentalWatch: ReplicacheImpl['experimentalWatch'],\n ) {\n assert(this.#clientID === undefined, 'clientID already set');\n this.#clientID = clientID;\n experimentalWatch(\n diffs => {\n this.#processMutationResponses(diffs);\n },\n {\n prefix: MUTATIONS_KEY_PREFIX + clientID + '/',\n initialValuesInFirstDiff: true,\n },\n );\n }\n\n trackMutation(): MutationTrackingData<MutationSuccessType> {\n const id = nextEphemeralID();\n const mutationResolver = resolver<MutationSuccessType, MutationErrorType>();\n\n this.#outstandingMutations.set(id, {\n resolver: mutationResolver,\n });\n return {ephemeralID: id, serverPromise: mutationResolver.promise};\n }\n\n mutationIDAssigned(id: EphemeralID, mutationID: number): void {\n const entry = this.#outstandingMutations.get(id);\n if (entry) {\n entry.mutationID = mutationID;\n this.#ephemeralIDsByMutationID.set(mutationID, id);\n this.#largestOutstandingMutationID = Math.max(\n this.#largestOutstandingMutationID,\n mutationID,\n );\n }\n }\n\n /**\n * Reject the mutation due to an unhandled exception on the client.\n * The mutation must not have been persisted to the client store.\n */\n rejectMutation(id: EphemeralID, e: unknown): void {\n const entry = this.#outstandingMutations.get(id);\n if (entry) {\n this.#settleMutation(id, entry, wrapWithApplicationError(e));\n }\n }\n\n /**\n * Reject all outstanding mutations. Called when the client is in a state\n * that prevents mutations from being applied, such as offline or closed.\n */\n rejectAllOutstandingMutations(error: ZeroError): void {\n if (this.#outstandingMutations.size === 0) {\n return;\n }\n for (const [id, entry] of this.#outstandingMutations) {\n this.#settleMutation(id, entry, error);\n }\n this.#largestOutstandingMutationID = this.#currentMutationID;\n this.#notifyAllMutationsAppliedListeners();\n }\n\n /**\n * Used when zero-cache pokes down mutation results.\n */\n #processMutationResponses(diffs: NoIndexDiff): void {\n const clientID = must(this.#clientID);\n let largestLmid = 0;\n for (const diff of diffs) {\n const mutationID = Number(\n diff.key.slice(MUTATIONS_KEY_PREFIX.length + clientID.length + 1),\n );\n assert(\n !isNaN(mutationID),\n `MutationTracker received a diff with an invalid mutation ID: ${diff.key}`,\n );\n largestLmid = Math.max(largestLmid, mutationID);\n switch (diff.op) {\n case 'add': {\n // Results are stored as the server sent them, so a newer server can\n // add fields. Don't use 'strip': mutationResultSchema's OK branch\n // has no discriminator, so it would turn every error into `{}`.\n const result = v.parse(\n diff.newValue,\n mutationResultSchema,\n 'passthrough',\n );\n if ('error' in result) {\n this.#processMutationError(clientID, mutationID, result);\n } else {\n this.#processMutationOk(clientID, mutationID, result);\n }\n break;\n }\n case 'del':\n break;\n case 'change':\n throw new Error('MutationTracker does not expect change operations');\n }\n }\n\n if (largestLmid > 0) {\n this.#ackMutations({\n clientID: must(this.#clientID),\n id: largestLmid,\n });\n }\n }\n\n processPushResponse(response: PushResponseBody): void {\n if ('error' in response) {\n this.#lc.error?.(\n 'Received an error response when pushing mutations',\n response,\n );\n const fatalError = this.#fatalErrorFromPushError(response);\n if (fatalError) {\n this.#onFatalError(fatalError);\n }\n } else {\n this.#processPushOk(response);\n }\n }\n\n #fatalErrorFromPushError(error: PushError): ZeroError | undefined {\n switch (error.error) {\n case 'unsupportedPushVersion':\n return new ProtocolError({\n kind: ErrorKind.PushFailed,\n origin: ErrorOrigin.ZeroCache,\n reason: ErrorReason.Internal,\n message: `Unsupported push version`,\n mutationIDs: [],\n });\n case 'unsupportedSchemaVersion':\n return new ProtocolError({\n kind: ErrorKind.PushFailed,\n origin: ErrorOrigin.ZeroCache,\n reason: ErrorReason.Internal,\n message: `Unsupported schema version`,\n mutationIDs: [],\n });\n case 'http':\n return new ProtocolError({\n kind: ErrorKind.PushFailed,\n origin: ErrorOrigin.ZeroCache,\n reason: ErrorReason.HTTP,\n status: error.status,\n message: `Fetch from API server returned non-OK status ${error.status}: ${error.details ?? 'unknown'}`,\n mutationIDs: [],\n });\n case 'zeroPusher':\n return new ProtocolError({\n kind: ErrorKind.PushFailed,\n origin: ErrorOrigin.ZeroCache,\n reason: ErrorReason.Internal,\n message: `ZeroPusher error: ${error.details ?? 'unknown'}`,\n mutationIDs: [],\n });\n default:\n unreachable(error);\n }\n }\n\n /**\n * DEPRECATED: to be removed when we switch to fully driving\n * mutation resolution via poke.\n *\n * When we reconnect to zero-cache, we resolve all outstanding mutations\n * whose ID is less than or equal to the lastMutationID.\n *\n * The reason is that any responses the API server sent\n * to those mutations have been lost.\n *\n * An example case: the API server responds while the connection\n * is down. Those responses are lost.\n *\n * Mutations whose LMID is > the lastMutationID are not resolved\n * since they will be retried by the client, giving us another chance\n * at getting a response.\n *\n * The only way to ensure that all API server responses are\n * received would be to have the API server write them\n * to the DB while writing the LMID.\n */\n onConnected(lastMutationID: number) {\n this.lmidAdvanced(lastMutationID);\n }\n\n /**\n * lmid advance will:\n * 1. notify \"allMutationsApplied\" listeners if the lastMutationID\n * is greater than or equal to the largest outstanding mutation ID.\n * 2. resolve all mutations whose mutation ID is less than or equal to\n * the lastMutationID.\n */\n lmidAdvanced(lastMutationID: number): void {\n assert(\n lastMutationID >= this.#currentMutationID,\n 'lmid must be greater than or equal to current lmid',\n );\n if (lastMutationID === this.#currentMutationID) {\n return;\n }\n\n try {\n this.#currentMutationID = lastMutationID;\n this.#resolveMutations(lastMutationID);\n } finally {\n if (lastMutationID >= this.#largestOutstandingMutationID) {\n // this is very important otherwise we hang query de-registration\n this.#notifyAllMutationsAppliedListeners();\n }\n }\n }\n\n get size() {\n return this.#outstandingMutations.size;\n }\n\n #resolveMutations(upTo: number): void {\n // We resolve all mutations whose mutation ID is less than or equal to\n // the upTo mutation ID.\n for (const [id, entry] of this.#outstandingMutations) {\n if (entry.mutationID && entry.mutationID <= upTo) {\n this.#settleMutation(id, entry, emptyObject);\n } else {\n break; // the map is in insertion order which is in mutation ID order\n }\n }\n }\n\n #processPushOk(success: PushOk): void {\n for (const mutation of success.mutations) {\n if ('error' in mutation.result) {\n this.#processMutationError(\n mutation.id.clientID,\n mutation.id.id,\n mutation.result,\n );\n } else {\n this.#processMutationOk(\n mutation.id.clientID,\n mutation.id.id,\n mutation.result,\n );\n }\n }\n }\n\n #processMutationError(\n clientID: string,\n mid: number,\n error: MutationError | Omit<PushError, 'mutationIDs'>,\n ): void {\n assert(\n clientID === this.#clientID,\n 'received mutation for the wrong client',\n );\n\n // Each tab sends all mutations for the client group\n // and the server responds back to the individual client that actually\n // ran the mutation. This means that N clients can send the same\n // mutation concurrently. If that happens, the promise for the mutation tracked\n // by this class will try to be resolved N times.\n // Every time after the first, the ephemeral ID will not be found.\n //\n // We also reject all outstanding mutations when the client is in a state\n // that prevents mutations from being applied, such as offline or closed.\n // In this case, the ephemeral ID will also not be found.\n const ephemeralID = this.#ephemeralIDsByMutationID.get(mid);\n if (!ephemeralID) {\n this.#lc.debug?.(\n 'Mutation already resolved or rejected (e.g. due to disconnect); ignore late reject.',\n );\n return;\n }\n\n const entry = this.#outstandingMutations.get(ephemeralID);\n assert(\n entry && entry.mutationID === mid,\n `outstanding mutation not found for mutation ID ${mid} and ephemeral ID ${ephemeralID}`,\n );\n\n if (error.error === 'alreadyProcessed') {\n // An earlier push committed this mutation, but its response was lost.\n // Leave it outstanding: its persisted result (if the mutator returned\n // data) or the lastMutationID advance arrives in a poke and settles it,\n // so returned data isn't dropped.\n return;\n }\n\n this.#settleMutation(\n ephemeralID,\n entry,\n error.error === 'app'\n ? new ApplicationError(\n error.message ?? `Unknown application error: ${error.error}`,\n error.details ? {details: error.details} : undefined,\n )\n : new ProtocolError({\n kind: ErrorKind.InvalidPush,\n origin: ErrorOrigin.Server,\n reason: ErrorReason.Internal,\n message:\n error.error === 'oooMutation'\n ? 'Server reported an out-of-order mutation'\n : `Unknown fallback error with mutation ID ${mid}: ${error.error}`,\n details: getErrorDetails(error),\n }),\n );\n\n // this is included for backwards compatibility with the per-mutation fatal error responses\n if (error.error === 'oooMutation') {\n this.#onFatalError(\n new ProtocolError({\n kind: ErrorKind.InvalidPush,\n origin: ErrorOrigin.Server,\n reason: ErrorReason.Internal,\n message: 'Server reported an out-of-order mutation',\n details: error.details,\n }),\n );\n }\n }\n\n #processMutationOk(clientID: string, mid: number, result: MutationOk): void {\n assert(\n clientID === this.#clientID,\n 'received mutation for the wrong client',\n );\n\n // We reject all outstanding mutations when the client is in a state\n // that prevents mutations from being applied, such as offline or closed.\n // In this case, the ephemeral ID will not be found.\n const ephemeralID = this.#ephemeralIDsByMutationID.get(mid);\n if (!ephemeralID) {\n this.#lc.debug?.(\n 'Mutation already resolved or rejected (e.g. due to disconnect); ignore late resolve.',\n );\n return;\n }\n\n const entry = this.#outstandingMutations.get(ephemeralID);\n assert(\n entry && entry.mutationID === mid,\n `outstanding mutation not found for mutation ID ${mid} and ephemeral ID ${ephemeralID}`,\n );\n this.#settleMutation(ephemeralID, entry, result);\n }\n\n #settleMutation<Result extends MutationOk | ApplicationError | ZeroError>(\n ephemeralID: EphemeralID,\n entry: {\n mutationID?: number | undefined;\n resolver: Resolver<MutationSuccessType, MutationErrorType>;\n },\n result: Result,\n ): void {\n if (isApplicationError(result) || isZeroError(result)) {\n // we reject here and catch in the mutator proxy\n // the mutator proxy catches both client and server errors\n entry.resolver.reject(result);\n } else {\n entry.resolver.resolve(result.data);\n }\n\n this.#outstandingMutations.delete(ephemeralID);\n if (entry.mutationID) {\n this.#ephemeralIDsByMutationID.delete(entry.mutationID);\n }\n }\n\n /**\n * Be notified when all mutations have been included in the server snapshot.\n *\n * The query manager will not de-register queries from the server until there\n * are no pending mutations.\n *\n * The reason is that a mutation may need to be rebased. We do not want\n * data that was available the first time it was run to not be available\n * on a rebase.\n */\n onAllMutationsApplied(listener: () => void): void {\n this.#allMutationsAppliedListeners.add(listener);\n }\n\n #notifyAllMutationsAppliedListeners() {\n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4B;EAChD,KAAK,8BAA8B,IAAI,QAAQ;CACjD;CAEA,sCAAsC;EACpC,KAAK,MAAM,YAAY,KAAK,+BAC1B,SAAS;CAEb;AACF"}
|
|
1
|
+
{"version":3,"file":"mutation-tracker.js","names":["v.parse","ErrorKind.PushFailed","ErrorOrigin.ZeroCache","ErrorReason.Internal","ErrorReason.HTTP","ErrorKind.InvalidPush","ErrorOrigin.Server"],"sources":["../../../../../zero-client/src/client/mutation-tracker.ts"],"sourcesContent":["import type {LogContext} from '@rocicorp/logger';\nimport type {NoIndexDiff} from '../../../replicache/src/btree/node.ts';\nimport type {ReplicacheImpl} from '../../../replicache/src/impl.ts';\nimport type {\n EphemeralID,\n MutationTrackingData,\n} from '../../../replicache/src/replicache-options.ts';\nimport {assert, unreachable} from '../../../shared/src/asserts.ts';\nimport {getErrorDetails} from '../../../shared/src/error.ts';\nimport type {ReadonlyJSONValue} from '../../../shared/src/json.ts';\nimport {must} from '../../../shared/src/must.ts';\nimport {resolver, type Resolver} from '../../../shared/src/resolver.ts';\nimport {emptyObject} from '../../../shared/src/sentinels.ts';\nimport * as v from '../../../shared/src/valita.ts';\nimport {\n ApplicationError,\n isApplicationError,\n wrapWithApplicationError,\n} from '../../../zero-protocol/src/application-error.ts';\nimport {ErrorKind} from '../../../zero-protocol/src/error-kind.ts';\nimport {ErrorOrigin} from '../../../zero-protocol/src/error-origin.ts';\nimport {ErrorReason} from '../../../zero-protocol/src/error-reason.ts';\nimport {ProtocolError} from '../../../zero-protocol/src/error.ts';\nimport type {MutationID} from '../../../zero-protocol/src/mutation-id.ts';\nimport {\n mutationResultSchema,\n type MutationError,\n type MutationOk,\n} from '../../../zero-protocol/src/mutation.ts';\nimport type {\n PushError,\n PushOk,\n PushResponseBody,\n} from '../../../zero-protocol/src/push.ts';\nimport {isZeroError, type ZeroError} from './error.ts';\nimport {MUTATIONS_KEY_PREFIX} from './keys.ts';\n\ntype MutationSuccessType = ReadonlyJSONValue | undefined;\ntype MutationErrorType = ApplicationError | ZeroError;\n\nlet currentEphemeralID = 0;\nfunction nextEphemeralID(): EphemeralID {\n return ++currentEphemeralID as EphemeralID;\n}\n\n/**\n * Tracks what pushes are in-flight and resolves promises when they're acked.\n */\nexport class MutationTracker {\n readonly #outstandingMutations: Map<\n EphemeralID,\n {\n mutationID?: number | undefined;\n resolver: Resolver<MutationSuccessType, MutationErrorType>;\n }\n >;\n readonly #ephemeralIDsByMutationID: Map<number, EphemeralID>;\n readonly #allMutationsAppliedListeners: Set<() => void>;\n readonly #lc: LogContext;\n\n readonly #ackMutations: (upTo: MutationID) => void;\n readonly #onFatalError: (error: ZeroError) => void;\n\n #clientID: string | undefined;\n #largestOutstandingMutationID: number;\n #currentMutationID: number;\n\n constructor(\n lc: LogContext,\n ackMutations: (upTo: MutationID) => void,\n onFatalError: (error: ZeroError) => void,\n ) {\n this.#lc = lc.withContext('MutationTracker');\n this.#outstandingMutations = new Map();\n this.#ephemeralIDsByMutationID = new Map();\n this.#allMutationsAppliedListeners = new Set();\n this.#largestOutstandingMutationID = 0;\n this.#currentMutationID = 0;\n this.#ackMutations = ackMutations;\n this.#onFatalError = onFatalError;\n }\n\n setClientIDAndWatch(\n clientID: string,\n experimentalWatch: ReplicacheImpl['experimentalWatch'],\n ) {\n assert(this.#clientID === undefined, 'clientID already set');\n this.#clientID = clientID;\n experimentalWatch(\n diffs => {\n this.#processMutationResponses(diffs);\n },\n {\n prefix: MUTATIONS_KEY_PREFIX + clientID + '/',\n initialValuesInFirstDiff: true,\n },\n );\n }\n\n trackMutation(): MutationTrackingData<MutationSuccessType> {\n const id = nextEphemeralID();\n const mutationResolver = resolver<MutationSuccessType, MutationErrorType>();\n\n this.#outstandingMutations.set(id, {\n resolver: mutationResolver,\n });\n return {ephemeralID: id, serverPromise: mutationResolver.promise};\n }\n\n mutationIDAssigned(id: EphemeralID, mutationID: number): void {\n const entry = this.#outstandingMutations.get(id);\n if (entry) {\n entry.mutationID = mutationID;\n this.#ephemeralIDsByMutationID.set(mutationID, id);\n this.#largestOutstandingMutationID = Math.max(\n this.#largestOutstandingMutationID,\n mutationID,\n );\n }\n }\n\n /**\n * Reject the mutation due to an unhandled exception on the client.\n * The mutation must not have been persisted to the client store.\n */\n rejectMutation(id: EphemeralID, e: unknown): void {\n const entry = this.#outstandingMutations.get(id);\n if (entry) {\n this.#settleMutation(id, entry, wrapWithApplicationError(e));\n }\n }\n\n /**\n * Reject all outstanding mutations. Called when the client is in a state\n * that prevents mutations from being applied, such as offline or closed.\n */\n rejectAllOutstandingMutations(error: ZeroError): void {\n if (this.#outstandingMutations.size === 0) {\n return;\n }\n for (const [id, entry] of this.#outstandingMutations) {\n this.#settleMutation(id, entry, error);\n }\n this.#largestOutstandingMutationID = this.#currentMutationID;\n this.#notifyAllMutationsAppliedListeners();\n }\n\n /**\n * Used when zero-cache pokes down mutation results.\n */\n #processMutationResponses(diffs: NoIndexDiff): void {\n const clientID = must(this.#clientID);\n let largestLmid = 0;\n for (const diff of diffs) {\n const mutationID = Number(\n diff.key.slice(MUTATIONS_KEY_PREFIX.length + clientID.length + 1),\n );\n assert(\n !isNaN(mutationID),\n `MutationTracker received a diff with an invalid mutation ID: ${diff.key}`,\n );\n largestLmid = Math.max(largestLmid, mutationID);\n switch (diff.op) {\n case 'add': {\n // Results are stored as the server sent them, so a newer server can\n // add fields. Don't use 'strip': mutationResultSchema's OK branch\n // has no discriminator, so it would turn every error into `{}`.\n const result = v.parse(\n diff.newValue,\n mutationResultSchema,\n 'passthrough',\n );\n if ('error' in result) {\n this.#processMutationError(clientID, mutationID, result);\n } else {\n this.#processMutationOk(clientID, mutationID, result);\n }\n break;\n }\n case 'del':\n break;\n case 'change':\n throw new Error('MutationTracker does not expect change operations');\n }\n }\n\n if (largestLmid > 0) {\n this.#ackMutations({\n clientID: must(this.#clientID),\n id: largestLmid,\n });\n }\n }\n\n processPushResponse(response: PushResponseBody): void {\n if ('error' in response) {\n this.#lc.error?.(\n 'Received an error response when pushing mutations',\n response,\n );\n const fatalError = this.#fatalErrorFromPushError(response);\n if (fatalError) {\n this.#onFatalError(fatalError);\n }\n } else {\n this.#processPushOk(response);\n }\n }\n\n #fatalErrorFromPushError(error: PushError): ZeroError | undefined {\n switch (error.error) {\n case 'unsupportedPushVersion':\n return new ProtocolError({\n kind: ErrorKind.PushFailed,\n origin: ErrorOrigin.ZeroCache,\n reason: ErrorReason.Internal,\n message: `Unsupported push version`,\n mutationIDs: [],\n });\n case 'unsupportedSchemaVersion':\n return new ProtocolError({\n kind: ErrorKind.PushFailed,\n origin: ErrorOrigin.ZeroCache,\n reason: ErrorReason.Internal,\n message: `Unsupported schema version`,\n mutationIDs: [],\n });\n case 'http':\n return new ProtocolError({\n kind: ErrorKind.PushFailed,\n origin: ErrorOrigin.ZeroCache,\n reason: ErrorReason.HTTP,\n status: error.status,\n message: `Fetch from API server returned non-OK status ${error.status}: ${error.details ?? 'unknown'}`,\n mutationIDs: [],\n });\n case 'zeroPusher':\n return new ProtocolError({\n kind: ErrorKind.PushFailed,\n origin: ErrorOrigin.ZeroCache,\n reason: ErrorReason.Internal,\n message: `ZeroPusher error: ${error.details ?? 'unknown'}`,\n mutationIDs: [],\n });\n default:\n unreachable(error);\n }\n }\n\n /**\n * DEPRECATED: to be removed when we switch to fully driving\n * mutation resolution via poke.\n *\n * When we reconnect to zero-cache, we resolve all outstanding mutations\n * whose ID is less than or equal to the lastMutationID.\n *\n * The reason is that any responses the API server sent\n * to those mutations have been lost.\n *\n * An example case: the API server responds while the connection\n * is down. Those responses are lost.\n *\n * Mutations whose LMID is > the lastMutationID are not resolved\n * since they will be retried by the client, giving us another chance\n * at getting a response.\n *\n * The only way to ensure that all API server responses are\n * received would be to have the API server write them\n * to the DB while writing the LMID.\n */\n onConnected(lastMutationID: number) {\n this.lmidAdvanced(lastMutationID);\n }\n\n /**\n * lmid advance will:\n * 1. notify \"allMutationsApplied\" listeners if the lastMutationID\n * is greater than or equal to the largest outstanding mutation ID.\n * 2. resolve all mutations whose mutation ID is less than or equal to\n * the lastMutationID.\n */\n lmidAdvanced(lastMutationID: number): void {\n assert(\n lastMutationID >= this.#currentMutationID,\n 'lmid must be greater than or equal to current lmid',\n );\n if (lastMutationID === this.#currentMutationID) {\n return;\n }\n\n try {\n this.#currentMutationID = lastMutationID;\n this.#resolveMutations(lastMutationID);\n } finally {\n if (lastMutationID >= this.#largestOutstandingMutationID) {\n // this is very important otherwise we hang query de-registration\n this.#notifyAllMutationsAppliedListeners();\n }\n }\n }\n\n get size() {\n return this.#outstandingMutations.size;\n }\n\n #resolveMutations(upTo: number): void {\n // We resolve all mutations whose mutation ID is less than or equal to\n // the upTo mutation ID.\n for (const [id, entry] of this.#outstandingMutations) {\n if (entry.mutationID && entry.mutationID <= upTo) {\n this.#settleMutation(id, entry, emptyObject);\n } else {\n break; // the map is in insertion order which is in mutation ID order\n }\n }\n }\n\n #processPushOk(success: PushOk): void {\n for (const mutation of success.mutations) {\n if ('error' in mutation.result) {\n this.#processMutationError(\n mutation.id.clientID,\n mutation.id.id,\n mutation.result,\n );\n } else {\n this.#processMutationOk(\n mutation.id.clientID,\n mutation.id.id,\n mutation.result,\n );\n }\n }\n }\n\n #processMutationError(\n clientID: string,\n mid: number,\n error: MutationError | Omit<PushError, 'mutationIDs'>,\n ): void {\n assert(\n clientID === this.#clientID,\n 'received mutation for the wrong client',\n );\n\n // Each tab sends all mutations for the client group\n // and the server responds back to the individual client that actually\n // ran the mutation. This means that N clients can send the same\n // mutation concurrently. If that happens, the promise for the mutation tracked\n // by this class will try to be resolved N times.\n // Every time after the first, the ephemeral ID will not be found.\n //\n // We also reject all outstanding mutations when the client is in a state\n // that prevents mutations from being applied, such as offline or closed.\n // In this case, the ephemeral ID will also not be found.\n const ephemeralID = this.#ephemeralIDsByMutationID.get(mid);\n if (!ephemeralID) {\n this.#lc.debug?.(\n 'Mutation already resolved or rejected (e.g. due to disconnect); ignore late reject.',\n );\n return;\n }\n\n const entry = this.#outstandingMutations.get(ephemeralID);\n assert(\n entry && entry.mutationID === mid,\n `outstanding mutation not found for mutation ID ${mid} and ephemeral ID ${ephemeralID}`,\n );\n\n if (error.error === 'alreadyProcessed') {\n // An earlier push committed this mutation, but its response was lost.\n // Leave it outstanding: its persisted result (if the mutator returned\n // data) or the lastMutationID advance arrives in a poke and settles it,\n // so returned data isn't dropped.\n return;\n }\n\n this.#settleMutation(\n ephemeralID,\n entry,\n error.error === 'app'\n ? new ApplicationError(\n error.message ?? `Unknown application error: ${error.error}`,\n error.details ? {details: error.details} : undefined,\n )\n : new ProtocolError({\n kind: ErrorKind.InvalidPush,\n origin: ErrorOrigin.Server,\n reason: ErrorReason.Internal,\n message:\n error.error === 'oooMutation'\n ? 'Server reported an out-of-order mutation'\n : `Unknown fallback error with mutation ID ${mid}: ${error.error}`,\n details: getErrorDetails(error),\n }),\n );\n\n // this is included for backwards compatibility with the per-mutation fatal error responses\n if (error.error === 'oooMutation') {\n this.#onFatalError(\n new ProtocolError({\n kind: ErrorKind.InvalidPush,\n origin: ErrorOrigin.Server,\n reason: ErrorReason.Internal,\n message: 'Server reported an out-of-order mutation',\n details: error.details,\n }),\n );\n }\n }\n\n #processMutationOk(clientID: string, mid: number, result: MutationOk): void {\n assert(\n clientID === this.#clientID,\n 'received mutation for the wrong client',\n );\n\n // We reject all outstanding mutations when the client is in a state\n // that prevents mutations from being applied, such as offline or closed.\n // In this case, the ephemeral ID will not be found.\n const ephemeralID = this.#ephemeralIDsByMutationID.get(mid);\n if (!ephemeralID) {\n this.#lc.debug?.(\n 'Mutation already resolved or rejected (e.g. due to disconnect); ignore late resolve.',\n );\n return;\n }\n\n const entry = this.#outstandingMutations.get(ephemeralID);\n assert(\n entry && entry.mutationID === mid,\n `outstanding mutation not found for mutation ID ${mid} and ephemeral ID ${ephemeralID}`,\n );\n this.#settleMutation(ephemeralID, entry, result);\n }\n\n #settleMutation<Result extends MutationOk | ApplicationError | ZeroError>(\n ephemeralID: EphemeralID,\n entry: {\n mutationID?: number | undefined;\n resolver: Resolver<MutationSuccessType, MutationErrorType>;\n },\n result: Result,\n ): void {\n if (isApplicationError(result) || isZeroError(result)) {\n // we reject here and catch in the mutator proxy\n // the mutator proxy catches both client and server errors\n entry.resolver.reject(result);\n } else {\n entry.resolver.resolve(result.data);\n }\n\n this.#outstandingMutations.delete(ephemeralID);\n if (entry.mutationID) {\n this.#ephemeralIDsByMutationID.delete(entry.mutationID);\n }\n }\n\n /**\n * Be notified when all mutations have been included in the server snapshot.\n *\n * The query manager will not de-register queries from the server until there\n * are no pending mutations.\n *\n * The reason is that a mutation may need to be rebased. We do not want\n * data that was available the first time it was run to not be available\n * on a rebase.\n */\n onAllMutationsApplied(listener: () => void): void {\n this.#allMutationsAppliedListeners.add(listener);\n }\n\n #notifyAllMutationsAppliedListeners() {\n for (const listener of this.#allMutationsAppliedListeners) {\n listener();\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;AAwCA,IAAI,qBAAqB;AACzB,SAAS,kBAA+B;CACtC,OAAO,EAAE;AACX;;;;AAKA,IAAa,kBAAb,MAA6B;CAC3B;CAOA;CACA;CACA;CAEA;CACA;CAEA;CACA;CACA;CAEA,YACE,IACA,cACA,cACA;EACA,KAAK,MAAM,GAAG,YAAY,iBAAiB;EAC3C,KAAK,wCAAwB,IAAI,IAAI;EACrC,KAAK,4CAA4B,IAAI,IAAI;EACzC,KAAK,gDAAgC,IAAI,IAAI;EAC7C,KAAK,gCAAgC;EACrC,KAAK,qBAAqB;EAC1B,KAAK,gBAAgB;EACrB,KAAK,gBAAgB;CACvB;CAEA,oBACE,UACA,mBACA;EACA,OAAO,KAAK,cAAc,KAAA,GAAW,sBAAsB;EAC3D,KAAK,YAAY;EACjB,mBACE,UAAS;GACP,KAAK,0BAA0B,KAAK;EACtC,GACA;GACE,QAAA,OAA+B,WAAW;GAC1C,0BAA0B;EAC5B,CACF;CACF;CAEA,gBAA2D;EACzD,MAAM,KAAK,gBAAgB;EAC3B,MAAM,mBAAmB,SAAiD;EAE1E,KAAK,sBAAsB,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,CAAC,aAAa;GAChB,KAAK,IAAI,QACP,sFACF;GACA;EACF;EAEA,MAAM,QAAQ,KAAK,sBAAsB,IAAI,WAAW;EACxD,OACE,SAAS,MAAM,eAAe,KAC9B,kDAAkD,IAAI,oBAAoB,aAC5E;EACA,KAAK,gBAAgB,aAAa,OAAO,MAAM;CACjD;CAEA,gBACE,aACA,OAIA,QACM;EACN,IAAI,mBAAmB,MAAM,KAAK,YAAY,MAAM,GAGlD,MAAM,SAAS,OAAO,MAAM;OAE5B,MAAM,SAAS,QAAQ,OAAO,IAAI;EAGpC,KAAK,sBAAsB,OAAO,WAAW;EAC7C,IAAI,MAAM,YACR,KAAK,0BAA0B,OAAO,MAAM,UAAU;CAE1D;;;;;;;;;;;CAYA,sBAAsB,UAA4B;EAChD,KAAK,8BAA8B,IAAI,QAAQ;CACjD;CAEA,sCAAsC;EACpC,KAAK,MAAM,YAAY,KAAK,+BAC1B,SAAS;CAEb;AACF"}
|
|
@@ -368,10 +368,6 @@ export type ZeroOptions<S extends BaseDefaultSchema = DefaultSchema, MD extends
|
|
|
368
368
|
} & (unknown extends DefaultContext ? {} : {
|
|
369
369
|
context: C;
|
|
370
370
|
});
|
|
371
|
-
/**
|
|
372
|
-
* @deprecated Use {@link ZeroOptions} instead.
|
|
373
|
-
*/
|
|
374
|
-
export type ZeroAdvancedOptions<S extends BaseDefaultSchema, MD extends CustomMutatorDefs | undefined, Context extends BaseDefaultContext> = ZeroOptions<S, MD, Context>;
|
|
375
371
|
type UpdateNeededReasonBase = {
|
|
376
372
|
message?: string;
|
|
377
373
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"options.d.ts","sourceRoot":"","sources":["../../../../../zero-client/src/client/options.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,QAAQ,EAAE,OAAO,EAAC,MAAM,kBAAkB,CAAC;AACxD,OAAO,KAAK,EAAC,aAAa,EAAC,MAAM,qCAAqC,CAAC;AACvE,OAAO,KAAK,EAA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,EAAE,MAAM,GAAG,SAAS,CAAC;IAEtC;;;;;OAKG;IACH,qBAAqB,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAE3C;;OAEG;IACH,OAAO,CAAC,EAAE,CAAC,GAAG,SAAS,CAAC;CACzB,GAAG,CAAC,OAAO,SAAS,cAAc,GAC/B,EAAE,GACF;IACE,OAAO,EAAE,CAAC,CAAC;CACZ,CAAC,CAAC;AAEP,KAAK,sBAAsB,GAAG;IAC5B,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF,MAAM,MAAM,kBAAkB,GAC1B,CAAC;IAAC,IAAI,EAAE,sBAAsB,CAAC,cAAc,CAAA;CAAC,GAAG,sBAAsB,CAAC,GACxE,CAAC;IACC,IAAI,EAAE,sBAAsB,CAAC,mBAAmB,CAAC;CAClD,GAAG,sBAAsB,CAAC,GAC3B,CAAC;IACC,IAAI,EAAE,sBAAsB,CAAC,yBAAyB,CAAC;CACxD,GAAG,sBAAsB,CAAC,CAAC;AAEhC,eAAO,MAAM,4BAA4B,EAAE,CAAC,CAAC,IAAI,CAAC,kBAAkB,CAAC,MAAM,CAAC,CAKzE,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"options.js","names":["v.literalUnion","UpdateNeededReasonType.NewClientGroup","UpdateNeededReasonType.VersionNotSupported","UpdateNeededReasonType.SchemaVersionNotSupported"],"sources":["../../../../../zero-client/src/client/options.ts"],"sourcesContent":["import type {LogLevel, LogSink} from '@rocicorp/logger';\nimport type {StoreProvider} from '../../../replicache/src/kv/store.ts';\nimport type {StorageFailureError} from '../../../replicache/src/storage-failure.ts';\nimport * as v from '../../../shared/src/valita.ts';\nimport type {\n BaseDefaultContext,\n BaseDefaultSchema,\n DefaultContext,\n DefaultSchema,\n} from '../../../zero-types/src/default-types.ts';\nimport type {AnyMutatorRegistry} from '../../../zql/src/mutate/mutator-registry.ts';\nimport type {CustomMutatorDefs} from './custom.ts';\nimport {UpdateNeededReasonType} from './update-needed-reason-type.ts';\n\n/**\n * Configuration for {@link Zero}.\n */\nexport type ZeroOptions<\n S extends BaseDefaultSchema = DefaultSchema,\n MD extends CustomMutatorDefs | undefined = undefined,\n C extends BaseDefaultContext = DefaultContext,\n> = {\n /**\n * URL to the zero-cache. This can be a simple hostname, e.g.\n * - \"https://myapp-myteam.zero.ms\"\n * or a prefix with a single path component, e.g.\n * - \"https://myapp-myteam.zero.ms/zero\"\n * - \"https://myapp-myteam.zero.ms/db\"\n *\n * The latter is useful for configuring routing rules (e.g. \"/zero/\\*\") when\n * the zero-cache is hosted on the same domain as the application. **Note that\n * only a single path segment is allowed (e.g. it cannot be \"/proxy/zero/\\*\")**.\n */\n cacheURL?: string | null | undefined;\n\n /**\n * @deprecated Use {@link cacheURL} instead.\n */\n server?: string | null | undefined;\n\n /**\n * A token to identify and authenticate the user.\n *\n * Set `auth` to `null` or `undefined` if there is no logged in user.\n *\n * The call to `connect` is handled automatically by the ZeroProvider component\n * for React and SolidJS when the `auth` prop changes.\n *\n * Transitions between authenticated and logged-out states recreate the Zero\n * instance instead.\n *\n * When `auth` changes while connected, Zero refreshes server-side auth context\n * and re-transforms queries without reconnecting.\n *\n * When a 401 or 403 HTTP status code is received from your server, Zero will\n * transition to the `needs-auth` connection state. The app should call\n * `zero.connection.connect({auth: newToken})` with a new token to reconnect.\n */\n auth?: string | null | undefined;\n\n /**\n * A unique identifier for the user.\n *\n * Omit this, or set to `null`, for logged-out clients.\n *\n * Each userID gets its own client-side storage so that the app can switch\n * between users without losing state.\n */\n userID?: string | null | undefined;\n\n /**\n * Distinguishes the storage used by this Zero instance from that of other\n * instances with the same userID. Useful in the case where the app wants to\n * have multiple Zero instances for the same user for different parts of the\n * app.\n */\n storageKey?: string | undefined;\n\n /**\n * Determines the level of detail at which Zero logs messages about\n * its operation. Messages are logged to the `console`.\n *\n * When this is set to `'debug'`, `'info'` and `'error'` messages are also\n * logged. When set to `'info'`, `'info'` and `'error'` but not\n * `'debug'` messages are logged. When set to `'error'` only `'error'`\n * messages are logged.\n *\n * Default is `'error'`.\n */\n logLevel?: LogLevel | undefined;\n\n /**\n * Destination for Zero's log output. When omitted, logs are written with\n * `console.log`/`info`/`warn`/`error` etc.\n *\n * Provide a custom {@link LogSink} to redirect logs — for example, to\n * `process.stderr` in a CLI so that the tool's structured stdout output\n * isn't polluted by log lines.\n *\n * Note: this overrides only the console sink. When analytics logging is\n * enabled, the Datadog sink is still installed alongside this one.\n */\n logSink?: LogSink | undefined;\n\n /**\n * This defines the schema of the tables used in Zero and their relationships\n * to one another.\n */\n schema: S;\n\n /**\n * `mutators` is a map of custom mutator definitions. The keys are\n * namespaces or names of the mutators. The values are the mutator\n * implementations. Client side mutators must be idempotent as a\n * mutation can be rebased multiple times when folding in authoritative\n * changes from the server to the client.\n *\n * Define mutators using the `defineMutator` function to create type-safe,\n * parameterized mutations. Mutators can be top-level or grouped in namespaces.\n *\n * @example\n * ```ts\n * import {defineMutator} from '@rocicorp/zero';\n *\n * const z = new Zero({\n * schema,\n * userID,\n * mutators: {\n * // Top-level mutator\n * increment: defineMutator(({tx, args}: {tx: Transaction<Schema>, args: {id: string}}) =>\n * tx.mutate.counter.update({id: args.id, value: tx.query.counter.where('id', '=', args.id).value + 1})\n * ),\n * // Namespace with multiple mutators\n * issues: {\n * create: defineMutator(({tx, args}: {tx: Transaction<Schema>, args: {title: string}}) =>\n * tx.mutate.issues.insert({id: nanoid(), title: args.title, status: 'open'})\n * ),\n * close: defineMutator(({tx, args}: {tx: Transaction<Schema>, args: {id: string}}) =>\n * tx.mutate.issues.update({id: args.id, status: 'closed'})\n * ),\n * },\n * },\n * });\n *\n * // Usage\n * await z.mutate.increment({id: 'counter-1'}).client;\n * await z.mutate.issues.create({title: 'New issue'}).client;\n * await z.mutate.issues.close({id: 'issue-123'}).client;\n * ```\n */\n mutators?: MD extends CustomMutatorDefs ? MD : AnyMutatorRegistry | undefined;\n\n /**\n * Custom URL for mutation requests sent to your API server.\n * If not provided, uses the default configured in zero-cache.\n */\n mutateURL?: string | undefined;\n\n /**\n * Custom headers to include in mutation requests sent to your API server.\n * These headers are passed through zero-cache to the mutate endpoint.\n */\n mutateHeaders?: Record<string, string> | undefined;\n\n /**\n * Custom URL for query requests sent to your API server.\n * If not provided, uses the default configured in zero-cache.\n *\n * @deprecated Use {@link queryURL} instead.\n */\n getQueriesURL?: string | undefined;\n\n /**\n * Custom URL for query requests sent to your API server.\n * If not provided, uses the default configured in zero-cache.\n */\n queryURL?: string | undefined;\n\n /**\n * Custom headers to include in query requests sent to your API server.\n * These headers are passed through zero-cache to the query endpoint.\n */\n queryHeaders?: Record<string, string> | undefined;\n\n /**\n * Optional callback that returns a W3C `traceparent` header value for\n * distributed tracing. Called before sending WebSocket messages that\n * trigger API server calls (`push`, `changeDesiredQueries`,\n * `initConnection`).\n *\n * This enables end-to-end trace correlation from your frontend through\n * zero-cache to your API server.\n *\n * @example\n * ```ts\n * import {propagation, context} from '@opentelemetry/api';\n *\n * new Zero({\n * getTraceparent: () => {\n * const carrier: Record<string, string> = {};\n * propagation.inject(context.active(), carrier);\n * return carrier.traceparent;\n * },\n * });\n * ```\n */\n getTraceparent?: (() => string | undefined) | undefined;\n\n /**\n * `onOnlineChange` is called when the Zero instance's online status changes.\n *\n * @deprecated Use {@link Connection.state.subscribe} on the Zero instance instead. e.g.\n * ```ts\n * const zero = new Zero({...});\n * zero.connection.state.subscribe((state) => {\n * console.log('Connection state:', state.name);\n * });\n * ```\n *\n * Or use a hook like {@link useConnectionState} to subscribe to state changes.\n */\n onOnlineChange?: ((online: boolean) => void) | undefined;\n\n /**\n * `onUpdateNeeded` is called when a client code update is needed.\n *\n * See {@link UpdateNeededReason} for why updates can be needed.\n *\n * The default behavior is to reload the page (using `location.reload()`).\n * Provide your own function to prevent the page from\n * reloading automatically. You may want to display a toast to inform the end\n * user there is a new version of your app available and prompt them to\n * refresh.\n */\n onUpdateNeeded?: ((reason: UpdateNeededReason) => void) | undefined;\n\n /**\n * `onClientStateNotFound` is called when this client is no longer able\n * to sync with zero-cache due to missing synchronization state. This\n * can be because:\n * - the local persistent synchronization state has been garbage collected.\n * This can happen if the client has no pending mutations and has not been\n * used for a while (e.g. the client's tab has been hidden for a long time).\n * - the local persistent synchronization state was found to be corrupt.\n * Replicache tries to drop the local database so that a reload starts\n * fresh. The callback is called even if that fails.\n * - zero-cache fails to find the server side synchronization state for\n * this client.\n * - zero-cache rejects this client's persisted synchronization state,\n * requiring the local Replicache database to be reset.\n *\n * The current `Zero` instance should be treated as dead and replaced, not\n * reconnected.\n *\n * The default behavior for the Zero client is to reload the page\n * (using `location.reload()`). The React and SolidJS providers will replace\n * the client in-place, without a full page reload.\n *\n * Provide your own function to prevent this functionality.\n */\n onClientStateNotFound?: (() => void) | undefined;\n\n /**\n * `onStorageFailure` is called once, the first time the local persistent\n * store reports that its storage has failed rather than its data, with the\n * {@link StorageFailureError} it threw: the device is out of space\n * (`full`), the database cannot be opened (`cannot-open`, including an\n * IndexedDB that fails to open), or a read or write to it failed\n * (`io-error`).\n *\n * A failure while this `Zero` instance is opening runs it on memory for the\n * session, as with `kvStore: 'mem'`: nothing is written to disk. A failure\n * after that stops persisting locally: queries and mutations keep running\n * against what the in-memory dag holds, and mutations keep pushing to\n * zero-cache, but nothing is written to disk until a new instance is\n * created; a read that needs a chunk not yet loaded\n * from the store (or since evicted from the in-memory cache) still fails\n * the way any store read does, and is reported here too, whichever caller\n * made it. An invalid ref count seen while the store is\n * failing with `cannot-open` or `io-error` is not treated as corruption, so\n * {@link onClientStateNotFound} is not called for it: a store that cannot\n * complete its reads and writes produces such readings without the data\n * being corrupt, and dropping the database would rebuild onto the same\n * failing storage. A `full` disk keeps the drop, since deleting the database\n * is also what frees the space.\n *\n * The default behavior is to log the failure and nothing else. Provide a\n * function to show the user what to do — free up space, or restart the\n * app once the storage is available again.\n */\n onStorageFailure?: ((failure: StorageFailureError) => void) | undefined;\n\n /**\n * The number of milliseconds to wait before disconnecting a Zero\n * instance whose tab has become hidden.\n *\n * Instances in hidden tabs are disconnected to save resources.\n *\n * Default is 5 minutes.\n */\n hiddenTabDisconnectDelay?: number | undefined;\n\n /**\n * The number of milliseconds to wait before disconnecting a Zero\n * instance when the connection to the server has timed out.\n *\n * Default is 1 minute.\n */\n disconnectTimeoutMs?: number | undefined;\n\n /**\n * The timeout in milliseconds for ping operations. This value is used for:\n * - How long to wait in idle before sending a ping to the server\n * - How long to wait for a pong response after sending a ping\n *\n * Total time to detect a dead connection is 2 × pingTimeoutMs.\n *\n * Default is 5_000.\n */\n pingTimeoutMs?: number | undefined;\n\n /**\n * Determines what kind of storage implementation to use on the client.\n *\n * Defaults to `'idb'` which means that Zero uses an IndexedDB storage\n * implementation. This allows the data to be persisted on the client and\n * enables faster syncs between application restarts.\n *\n * By setting this to `'mem'`, Zero uses an in memory storage and\n * the data is not persisted on the client.\n *\n * You can also set this to a function that is used to create new KV stores,\n * allowing a custom implementation of the underlying storage layer.\n */\n kvStore?: 'mem' | 'idb' | StoreProvider | undefined;\n\n /**\n * The maximum number of bytes to allow in a single header.\n *\n * Zero adds some extra information to headers on initialization if possible.\n * This speeds up data synchronization. This number should be kept less than\n * or equal to the maximum header size allowed by the zero-cache and any load\n * balancers.\n *\n * Default value: 8kb.\n */\n maxHeaderLength?: number | undefined;\n\n /**\n * The maximum amount of milliseconds to wait for a materialization to\n * complete (including network/server time) before printing a warning to the\n * console.\n *\n * Default value: 5_000.\n */\n slowMaterializeThreshold?: number | undefined;\n\n /**\n * UI rendering libraries will often provide a utility for batching multiple\n * state updates into a single render. Some examples are React's\n * `unstable_batchedUpdates`, and solid-js's `batch`.\n *\n * This option enables integrating these batch utilities with Zero.\n *\n * When `batchViewUpdates` is provided, Zero will call it whenever\n * it updates query view state with an `applyViewUpdates` function\n * that performs the actual state updates.\n *\n * Zero updates query view state when:\n * 1. creating a new view\n * 2. updating all existing queries' views to a new consistent state\n *\n * When creating a new view, that single view's creation will be wrapped\n * in a `batchViewUpdates` call.\n *\n * When updating existing queries, all queries will be updated in a single\n * `batchViewUpdates` call, so that the transition to the new consistent\n * state can be done in a single render.\n *\n * Implementations must always call `applyViewUpdates` synchronously.\n */\n batchViewUpdates?: ((applyViewUpdates: () => void) => void) | undefined;\n\n /**\n * The maximum number of recent queries, no longer subscribed to by a preload\n * or view, to continue syncing.\n *\n * Defaults is 0.\n *\n * @deprecated Use ttl instead\n */\n maxRecentQueries?: number | undefined;\n\n /**\n * Changes to queries are sent to server in batches. This option controls\n * the number of milliseconds to wait before sending the next batch.\n *\n * Defaults is 10.\n */\n queryChangeThrottleMs?: number | undefined;\n\n /**\n * Context is passed to queries when they are executed.\n */\n context?: C | undefined;\n} & (unknown extends DefaultContext\n ? {}\n : {\n context: C;\n });\n\n/**\n * @deprecated Use {@link ZeroOptions} instead.\n */\nexport type ZeroAdvancedOptions<\n S extends BaseDefaultSchema,\n MD extends CustomMutatorDefs | undefined,\n Context extends BaseDefaultContext,\n> = ZeroOptions<S, MD, Context>;\n\ntype UpdateNeededReasonBase = {\n message?: string;\n};\n\nexport type UpdateNeededReason =\n | ({type: UpdateNeededReasonType.NewClientGroup} & UpdateNeededReasonBase)\n | ({\n type: UpdateNeededReasonType.VersionNotSupported;\n } & UpdateNeededReasonBase)\n | ({\n type: UpdateNeededReasonType.SchemaVersionNotSupported;\n } & UpdateNeededReasonBase);\n\nexport const updateNeededReasonTypeSchema: v.Type<UpdateNeededReason['type']> =\n v.literalUnion(\n UpdateNeededReasonType.NewClientGroup,\n UpdateNeededReasonType.VersionNotSupported,\n UpdateNeededReasonType.SchemaVersionNotSupported,\n );\n"],"mappings":";;;AAibA,IAAa,+BACXA,aACEC,gBACAC,qBACAC,yBACF"}
|
|
1
|
+
{"version":3,"file":"options.js","names":["v.literalUnion","UpdateNeededReasonType.NewClientGroup","UpdateNeededReasonType.VersionNotSupported","UpdateNeededReasonType.SchemaVersionNotSupported"],"sources":["../../../../../zero-client/src/client/options.ts"],"sourcesContent":["import type {LogLevel, LogSink} from '@rocicorp/logger';\nimport type {StoreProvider} from '../../../replicache/src/kv/store.ts';\nimport type {StorageFailureError} from '../../../replicache/src/storage-failure.ts';\nimport * as v from '../../../shared/src/valita.ts';\nimport type {\n BaseDefaultContext,\n BaseDefaultSchema,\n DefaultContext,\n DefaultSchema,\n} from '../../../zero-types/src/default-types.ts';\nimport type {AnyMutatorRegistry} from '../../../zql/src/mutate/mutator-registry.ts';\nimport type {CustomMutatorDefs} from './custom.ts';\nimport {UpdateNeededReasonType} from './update-needed-reason-type.ts';\n\n/**\n * Configuration for {@link Zero}.\n */\nexport type ZeroOptions<\n S extends BaseDefaultSchema = DefaultSchema,\n MD extends CustomMutatorDefs | undefined = undefined,\n C extends BaseDefaultContext = DefaultContext,\n> = {\n /**\n * URL to the zero-cache. This can be a simple hostname, e.g.\n * - \"https://myapp-myteam.zero.ms\"\n * or a prefix with a single path component, e.g.\n * - \"https://myapp-myteam.zero.ms/zero\"\n * - \"https://myapp-myteam.zero.ms/db\"\n *\n * The latter is useful for configuring routing rules (e.g. \"/zero/\\*\") when\n * the zero-cache is hosted on the same domain as the application. **Note that\n * only a single path segment is allowed (e.g. it cannot be \"/proxy/zero/\\*\")**.\n */\n cacheURL?: string | null | undefined;\n\n /**\n * @deprecated Use {@link cacheURL} instead.\n */\n server?: string | null | undefined;\n\n /**\n * A token to identify and authenticate the user.\n *\n * Set `auth` to `null` or `undefined` if there is no logged in user.\n *\n * The call to `connect` is handled automatically by the ZeroProvider component\n * for React and SolidJS when the `auth` prop changes.\n *\n * Transitions between authenticated and logged-out states recreate the Zero\n * instance instead.\n *\n * When `auth` changes while connected, Zero refreshes server-side auth context\n * and re-transforms queries without reconnecting.\n *\n * When a 401 or 403 HTTP status code is received from your server, Zero will\n * transition to the `needs-auth` connection state. The app should call\n * `zero.connection.connect({auth: newToken})` with a new token to reconnect.\n */\n auth?: string | null | undefined;\n\n /**\n * A unique identifier for the user.\n *\n * Omit this, or set to `null`, for logged-out clients.\n *\n * Each userID gets its own client-side storage so that the app can switch\n * between users without losing state.\n */\n userID?: string | null | undefined;\n\n /**\n * Distinguishes the storage used by this Zero instance from that of other\n * instances with the same userID. Useful in the case where the app wants to\n * have multiple Zero instances for the same user for different parts of the\n * app.\n */\n storageKey?: string | undefined;\n\n /**\n * Determines the level of detail at which Zero logs messages about\n * its operation. Messages are logged to the `console`.\n *\n * When this is set to `'debug'`, `'info'` and `'error'` messages are also\n * logged. When set to `'info'`, `'info'` and `'error'` but not\n * `'debug'` messages are logged. When set to `'error'` only `'error'`\n * messages are logged.\n *\n * Default is `'error'`.\n */\n logLevel?: LogLevel | undefined;\n\n /**\n * Destination for Zero's log output. When omitted, logs are written with\n * `console.log`/`info`/`warn`/`error` etc.\n *\n * Provide a custom {@link LogSink} to redirect logs — for example, to\n * `process.stderr` in a CLI so that the tool's structured stdout output\n * isn't polluted by log lines.\n *\n * Note: this overrides only the console sink. When analytics logging is\n * enabled, the Datadog sink is still installed alongside this one.\n */\n logSink?: LogSink | undefined;\n\n /**\n * This defines the schema of the tables used in Zero and their relationships\n * to one another.\n */\n schema: S;\n\n /**\n * `mutators` is a map of custom mutator definitions. The keys are\n * namespaces or names of the mutators. The values are the mutator\n * implementations. Client side mutators must be idempotent as a\n * mutation can be rebased multiple times when folding in authoritative\n * changes from the server to the client.\n *\n * Define mutators using the `defineMutator` function to create type-safe,\n * parameterized mutations. Mutators can be top-level or grouped in namespaces.\n *\n * @example\n * ```ts\n * import {defineMutator} from '@rocicorp/zero';\n *\n * const z = new Zero({\n * schema,\n * userID,\n * mutators: {\n * // Top-level mutator\n * increment: defineMutator(({tx, args}: {tx: Transaction<Schema>, args: {id: string}}) =>\n * tx.mutate.counter.update({id: args.id, value: tx.query.counter.where('id', '=', args.id).value + 1})\n * ),\n * // Namespace with multiple mutators\n * issues: {\n * create: defineMutator(({tx, args}: {tx: Transaction<Schema>, args: {title: string}}) =>\n * tx.mutate.issues.insert({id: nanoid(), title: args.title, status: 'open'})\n * ),\n * close: defineMutator(({tx, args}: {tx: Transaction<Schema>, args: {id: string}}) =>\n * tx.mutate.issues.update({id: args.id, status: 'closed'})\n * ),\n * },\n * },\n * });\n *\n * // Usage\n * await z.mutate.increment({id: 'counter-1'}).client;\n * await z.mutate.issues.create({title: 'New issue'}).client;\n * await z.mutate.issues.close({id: 'issue-123'}).client;\n * ```\n */\n mutators?: MD extends CustomMutatorDefs ? MD : AnyMutatorRegistry | undefined;\n\n /**\n * Custom URL for mutation requests sent to your API server.\n * If not provided, uses the default configured in zero-cache.\n */\n mutateURL?: string | undefined;\n\n /**\n * Custom headers to include in mutation requests sent to your API server.\n * These headers are passed through zero-cache to the mutate endpoint.\n */\n mutateHeaders?: Record<string, string> | undefined;\n\n /**\n * Custom URL for query requests sent to your API server.\n * If not provided, uses the default configured in zero-cache.\n *\n * @deprecated Use {@link queryURL} instead.\n */\n getQueriesURL?: string | undefined;\n\n /**\n * Custom URL for query requests sent to your API server.\n * If not provided, uses the default configured in zero-cache.\n */\n queryURL?: string | undefined;\n\n /**\n * Custom headers to include in query requests sent to your API server.\n * These headers are passed through zero-cache to the query endpoint.\n */\n queryHeaders?: Record<string, string> | undefined;\n\n /**\n * Optional callback that returns a W3C `traceparent` header value for\n * distributed tracing. Called before sending WebSocket messages that\n * trigger API server calls (`push`, `changeDesiredQueries`,\n * `initConnection`).\n *\n * This enables end-to-end trace correlation from your frontend through\n * zero-cache to your API server.\n *\n * @example\n * ```ts\n * import {propagation, context} from '@opentelemetry/api';\n *\n * new Zero({\n * getTraceparent: () => {\n * const carrier: Record<string, string> = {};\n * propagation.inject(context.active(), carrier);\n * return carrier.traceparent;\n * },\n * });\n * ```\n */\n getTraceparent?: (() => string | undefined) | undefined;\n\n /**\n * `onOnlineChange` is called when the Zero instance's online status changes.\n *\n * @deprecated Use {@link Connection.state.subscribe} on the Zero instance instead. e.g.\n * ```ts\n * const zero = new Zero({...});\n * zero.connection.state.subscribe((state) => {\n * console.log('Connection state:', state.name);\n * });\n * ```\n *\n * Or use a hook like {@link useConnectionState} to subscribe to state changes.\n */\n onOnlineChange?: ((online: boolean) => void) | undefined;\n\n /**\n * `onUpdateNeeded` is called when a client code update is needed.\n *\n * See {@link UpdateNeededReason} for why updates can be needed.\n *\n * The default behavior is to reload the page (using `location.reload()`).\n * Provide your own function to prevent the page from\n * reloading automatically. You may want to display a toast to inform the end\n * user there is a new version of your app available and prompt them to\n * refresh.\n */\n onUpdateNeeded?: ((reason: UpdateNeededReason) => void) | undefined;\n\n /**\n * `onClientStateNotFound` is called when this client is no longer able\n * to sync with zero-cache due to missing synchronization state. This\n * can be because:\n * - the local persistent synchronization state has been garbage collected.\n * This can happen if the client has no pending mutations and has not been\n * used for a while (e.g. the client's tab has been hidden for a long time).\n * - the local persistent synchronization state was found to be corrupt.\n * Replicache tries to drop the local database so that a reload starts\n * fresh. The callback is called even if that fails.\n * - zero-cache fails to find the server side synchronization state for\n * this client.\n * - zero-cache rejects this client's persisted synchronization state,\n * requiring the local Replicache database to be reset.\n *\n * The current `Zero` instance should be treated as dead and replaced, not\n * reconnected.\n *\n * The default behavior for the Zero client is to reload the page\n * (using `location.reload()`). The React and SolidJS providers will replace\n * the client in-place, without a full page reload.\n *\n * Provide your own function to prevent this functionality.\n */\n onClientStateNotFound?: (() => void) | undefined;\n\n /**\n * `onStorageFailure` is called once, the first time the local persistent\n * store reports that its storage has failed rather than its data, with the\n * {@link StorageFailureError} it threw: the device is out of space\n * (`full`), the database cannot be opened (`cannot-open`, including an\n * IndexedDB that fails to open), or a read or write to it failed\n * (`io-error`).\n *\n * A failure while this `Zero` instance is opening runs it on memory for the\n * session, as with `kvStore: 'mem'`: nothing is written to disk. A failure\n * after that stops persisting locally: queries and mutations keep running\n * against what the in-memory dag holds, and mutations keep pushing to\n * zero-cache, but nothing is written to disk until a new instance is\n * created; a read that needs a chunk not yet loaded\n * from the store (or since evicted from the in-memory cache) still fails\n * the way any store read does, and is reported here too, whichever caller\n * made it. An invalid ref count seen while the store is\n * failing with `cannot-open` or `io-error` is not treated as corruption, so\n * {@link onClientStateNotFound} is not called for it: a store that cannot\n * complete its reads and writes produces such readings without the data\n * being corrupt, and dropping the database would rebuild onto the same\n * failing storage. A `full` disk keeps the drop, since deleting the database\n * is also what frees the space.\n *\n * The default behavior is to log the failure and nothing else. Provide a\n * function to show the user what to do — free up space, or restart the\n * app once the storage is available again.\n */\n onStorageFailure?: ((failure: StorageFailureError) => void) | undefined;\n\n /**\n * The number of milliseconds to wait before disconnecting a Zero\n * instance whose tab has become hidden.\n *\n * Instances in hidden tabs are disconnected to save resources.\n *\n * Default is 5 minutes.\n */\n hiddenTabDisconnectDelay?: number | undefined;\n\n /**\n * The number of milliseconds to wait before disconnecting a Zero\n * instance when the connection to the server has timed out.\n *\n * Default is 1 minute.\n */\n disconnectTimeoutMs?: number | undefined;\n\n /**\n * The timeout in milliseconds for ping operations. This value is used for:\n * - How long to wait in idle before sending a ping to the server\n * - How long to wait for a pong response after sending a ping\n *\n * Total time to detect a dead connection is 2 × pingTimeoutMs.\n *\n * Default is 5_000.\n */\n pingTimeoutMs?: number | undefined;\n\n /**\n * Determines what kind of storage implementation to use on the client.\n *\n * Defaults to `'idb'` which means that Zero uses an IndexedDB storage\n * implementation. This allows the data to be persisted on the client and\n * enables faster syncs between application restarts.\n *\n * By setting this to `'mem'`, Zero uses an in memory storage and\n * the data is not persisted on the client.\n *\n * You can also set this to a function that is used to create new KV stores,\n * allowing a custom implementation of the underlying storage layer.\n */\n kvStore?: 'mem' | 'idb' | StoreProvider | undefined;\n\n /**\n * The maximum number of bytes to allow in a single header.\n *\n * Zero adds some extra information to headers on initialization if possible.\n * This speeds up data synchronization. This number should be kept less than\n * or equal to the maximum header size allowed by the zero-cache and any load\n * balancers.\n *\n * Default value: 8kb.\n */\n maxHeaderLength?: number | undefined;\n\n /**\n * The maximum amount of milliseconds to wait for a materialization to\n * complete (including network/server time) before printing a warning to the\n * console.\n *\n * Default value: 5_000.\n */\n slowMaterializeThreshold?: number | undefined;\n\n /**\n * UI rendering libraries will often provide a utility for batching multiple\n * state updates into a single render. Some examples are React's\n * `unstable_batchedUpdates`, and solid-js's `batch`.\n *\n * This option enables integrating these batch utilities with Zero.\n *\n * When `batchViewUpdates` is provided, Zero will call it whenever\n * it updates query view state with an `applyViewUpdates` function\n * that performs the actual state updates.\n *\n * Zero updates query view state when:\n * 1. creating a new view\n * 2. updating all existing queries' views to a new consistent state\n *\n * When creating a new view, that single view's creation will be wrapped\n * in a `batchViewUpdates` call.\n *\n * When updating existing queries, all queries will be updated in a single\n * `batchViewUpdates` call, so that the transition to the new consistent\n * state can be done in a single render.\n *\n * Implementations must always call `applyViewUpdates` synchronously.\n */\n batchViewUpdates?: ((applyViewUpdates: () => void) => void) | undefined;\n\n /**\n * The maximum number of recent queries, no longer subscribed to by a preload\n * or view, to continue syncing.\n *\n * Defaults is 0.\n *\n * @deprecated Use ttl instead\n */\n maxRecentQueries?: number | undefined;\n\n /**\n * Changes to queries are sent to server in batches. This option controls\n * the number of milliseconds to wait before sending the next batch.\n *\n * Defaults is 10.\n */\n queryChangeThrottleMs?: number | undefined;\n\n /**\n * Context is passed to queries when they are executed.\n */\n context?: C | undefined;\n} & (unknown extends DefaultContext\n ? {}\n : {\n context: C;\n });\n\ntype UpdateNeededReasonBase = {\n message?: string;\n};\n\nexport type UpdateNeededReason =\n | ({type: UpdateNeededReasonType.NewClientGroup} & UpdateNeededReasonBase)\n | ({\n type: UpdateNeededReasonType.VersionNotSupported;\n } & UpdateNeededReasonBase)\n | ({\n type: UpdateNeededReasonType.SchemaVersionNotSupported;\n } & UpdateNeededReasonBase);\n\nexport const updateNeededReasonTypeSchema: v.Type<UpdateNeededReason['type']> =\n v.literalUnion(\n UpdateNeededReasonType.NewClientGroup,\n UpdateNeededReasonType.VersionNotSupported,\n UpdateNeededReasonType.SchemaVersionNotSupported,\n );\n"],"mappings":";;;AAwaA,IAAa,+BACXA,aACEC,gBACAC,qBACAC,yBACF"}
|
|
@@ -9,11 +9,11 @@ import type { ReadonlyJSONObject } from '../../../shared/src/json.ts';
|
|
|
9
9
|
* when they are run on the server, which can use it to supplement
|
|
10
10
|
* mutator args and to authorize the mutation.
|
|
11
11
|
*/
|
|
12
|
-
|
|
12
|
+
type AuthData = ReadonlyJSONObject & {
|
|
13
13
|
readonly userID: string;
|
|
14
14
|
};
|
|
15
15
|
/** Environment variables. */
|
|
16
|
-
|
|
16
|
+
type Env = {
|
|
17
17
|
readonly [key: string]: string;
|
|
18
18
|
};
|
|
19
19
|
export interface ReadTransaction extends ReplicacheReadTransaction {
|
|
@@ -47,4 +47,5 @@ export interface WriteTransaction extends ReplicacheWriteTransaction {
|
|
|
47
47
|
export type MutatorDefs = {
|
|
48
48
|
[key: string]: (tx: WriteTransaction, args?: any) => MutatorReturn;
|
|
49
49
|
};
|
|
50
|
+
export {};
|
|
50
51
|
//# sourceMappingURL=replicache-types.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"replicache-types.d.ts","sourceRoot":"","sources":["../../../../../zero-client/src/client/replicache-types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,eAAe,IAAI,yBAAyB,EAC5C,gBAAgB,IAAI,0BAA0B,EAC/C,MAAM,yCAAyC,CAAC;AACjD,OAAO,KAAK,EAAC,aAAa,EAAC,MAAM,kCAAkC,CAAC;AACpE,OAAO,KAAK,EAAC,kBAAkB,EAAC,MAAM,6BAA6B,CAAC;AAEpE;;;;;;;GAOG;AACH,
|
|
1
|
+
{"version":3,"file":"replicache-types.d.ts","sourceRoot":"","sources":["../../../../../zero-client/src/client/replicache-types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,eAAe,IAAI,yBAAyB,EAC5C,gBAAgB,IAAI,0BAA0B,EAC/C,MAAM,yCAAyC,CAAC;AACjD,OAAO,KAAK,EAAC,aAAa,EAAC,MAAM,kCAAkC,CAAC;AACpE,OAAO,KAAK,EAAC,kBAAkB,EAAC,MAAM,6BAA6B,CAAC;AAEpE;;;;;;;GAOG;AACH,KAAK,QAAQ,GAAG,kBAAkB,GAAG;IAAC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;CAAC,CAAC;AAE/D,6BAA6B;AAC7B,KAAK,GAAG,GAAG;IAAC,QAAQ,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,CAAA;CAAC,CAAC;AAE5C,MAAM,WAAW,eAAgB,SAAQ,yBAAyB;IAChE;;;;;;OAMG;IACH,QAAQ,CAAC,IAAI,CAAC,EAAE,QAAQ,GAAG,SAAS,CAAC;IAErC;;OAEG;IACH,QAAQ,CAAC,GAAG,CAAC,EAAE,GAAG,GAAG,SAAS,CAAC;CAChC;AAED,MAAM,WAAW,gBAAiB,SAAQ,0BAA0B;IAClE;;;;;;OAMG;IACH,QAAQ,CAAC,IAAI,CAAC,EAAE,QAAQ,GAAG,SAAS,CAAC;IAErC;;OAEG;IACH,QAAQ,CAAC,GAAG,CAAC,EAAE,GAAG,GAAG,SAAS,CAAC;CAChC;AAED,MAAM,MAAM,WAAW,GAAG;IACxB,CAAC,GAAG,EAAE,MAAM,GAAG,CACb,EAAE,EAAE,gBAAgB,EAGpB,IAAI,CAAC,EAAE,GAAG,KACP,aAAa,CAAC;CACpB,CAAC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { LogContext } from '@rocicorp/logger';
|
|
2
|
-
import type {
|
|
2
|
+
import type { PokeInternal } from '../../../replicache/src/impl.ts';
|
|
3
3
|
import type { ClientID } from '../../../replicache/src/sync/ids.ts';
|
|
4
4
|
import type { MutationPatch } from '../../../zero-protocol/src/mutations-patch.ts';
|
|
5
5
|
import { type PokeEndBody, type PokePartBody, type PokeStartBody } from '../../../zero-protocol/src/poke.ts';
|
|
@@ -36,6 +36,5 @@ export declare class PokeHandler {
|
|
|
36
36
|
export declare function mergePokes(pokeBuffer: PokeAccumulator[], schema: Schema, serverToClient: NameMapper): (PokeInternal & {
|
|
37
37
|
mutationResults?: MutationPatch[] | undefined;
|
|
38
38
|
}) | undefined;
|
|
39
|
-
export declare function mutationPatchOpToReplicachePatchOp(op: MutationPatch): PatchOperationInternal;
|
|
40
39
|
export {};
|
|
41
40
|
//# sourceMappingURL=zero-poke-handler.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"zero-poke-handler.d.ts","sourceRoot":"","sources":["../../../../../zero-client/src/client/zero-poke-handler.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAC,UAAU,EAAC,MAAM,kBAAkB,CAAC;AACjD,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"zero-poke-handler.d.ts","sourceRoot":"","sources":["../../../../../zero-client/src/client/zero-poke-handler.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAC,UAAU,EAAC,MAAM,kBAAkB,CAAC;AACjD,OAAO,KAAK,EAEV,YAAY,EACb,MAAM,iCAAiC,CAAC;AAEzC,OAAO,KAAK,EAAC,QAAQ,EAAC,MAAM,qCAAqC,CAAC;AAGlE,OAAO,KAAK,EAAC,aAAa,EAAC,MAAM,+CAA+C,CAAC;AACjF,OAAO,EAEL,KAAK,WAAW,EAChB,KAAK,YAAY,EAEjB,KAAK,aAAa,EACnB,MAAM,oCAAoC,CAAC;AAG5C,OAAO,EAEL,KAAK,UAAU,EAChB,MAAM,yCAAyC,CAAC;AACjD,OAAO,KAAK,EAAC,MAAM,EAAC,MAAM,mCAAmC,CAAC;AAO9D,OAAO,KAAK,EAAC,eAAe,EAAC,MAAM,uBAAuB,CAAC;AAE3D,KAAK,eAAe,GAAG;IACrB,QAAQ,CAAC,SAAS,EAAE,aAAa,CAAC;IAClC,QAAQ,CAAC,KAAK,EAAE,YAAY,EAAE,CAAC;IAC/B,QAAQ,CAAC,OAAO,EAAE,WAAW,CAAC;CAC/B,CAAC;AAQF,MAAM,MAAM,aAAa,GAAG;IAC1B,QAAQ,CAAC,2BAA2B,EAAE,MAAM,GAAG,SAAS,CAAC;IACzD,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;CAC3B,CAAC;AAEF;;;;;;;;GAQG;AACH,qBAAa,WAAW;;IAgBtB,YACE,cAAc,EAAE,CAAC,IAAI,EAAE,YAAY,KAAK,OAAO,CAAC,IAAI,CAAC,EACrD,WAAW,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,IAAI,EACrC,QAAQ,EAAE,QAAQ,EAClB,MAAM,EAAE,MAAM,EACd,EAAE,EAAE,UAAU,EACd,eAAe,EAAE,eAAe,EASjC;IAED,eAAe,CAAC,SAAS,EAAE,aAAa,QAgBvC;IAED,cAAc,CAAC,QAAQ,EAAE,YAAY,GAAG,MAAM,GAAG,SAAS,CAezD;IAED,eAAe,CAAC,KAAK,EAAE,UAAU,GAAG,IAAI,CAUvC;IAED,aAAa,CAAC,OAAO,EAAE,WAAW,GAAG,aAAa,GAAG,SAAS,CAmC7D;IAED,gBAAgB,IAAI,IAAI,CAGvB;CAgFF;AA6BD,wBAAgB,UAAU,CACxB,UAAU,EAAE,eAAe,EAAE,EAC7B,MAAM,EAAE,MAAM,EACd,cAAc,EAAE,UAAU,GAExB,CAAC,YAAY,GAAG;IAAC,eAAe,CAAC,EAAE,aAAa,EAAE,GAAG,SAAS,CAAA;CAAC,CAAC,GAChE,SAAS,CAyFZ"}
|
|
@@ -262,6 +262,6 @@ function rowsPatchOpToReplicachePatchOp(op, schema, serverToClient) {
|
|
|
262
262
|
}
|
|
263
263
|
}
|
|
264
264
|
//#endregion
|
|
265
|
-
export { PokeHandler, mergePokes
|
|
265
|
+
export { PokeHandler, mergePokes };
|
|
266
266
|
|
|
267
267
|
//# sourceMappingURL=zero-poke-handler.js.map
|