@rocicorp/zero 0.25.10-canary.9 → 0.25.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/out/zero/package.json.js +1 -1
- package/out/zero-cache/src/custom/fetch.d.ts +3 -3
- package/out/zero-cache/src/custom/fetch.d.ts.map +1 -1
- package/out/zero-cache/src/custom/fetch.js +116 -76
- package/out/zero-cache/src/custom/fetch.js.map +1 -1
- package/out/zero-cache/src/custom-queries/transform-query.d.ts.map +1 -1
- package/out/zero-cache/src/custom-queries/transform-query.js +0 -1
- package/out/zero-cache/src/custom-queries/transform-query.js.map +1 -1
- package/out/zero-cache/src/server/anonymous-otel-start.d.ts.map +1 -1
- package/out/zero-cache/src/server/anonymous-otel-start.js +1 -0
- package/out/zero-cache/src/server/anonymous-otel-start.js.map +1 -1
- package/out/zero-cache/src/server/inspector-delegate.d.ts.map +1 -1
- package/out/zero-cache/src/server/inspector-delegate.js +2 -2
- package/out/zero-cache/src/server/inspector-delegate.js.map +1 -1
- package/out/zero-cache/src/server/priority-op.d.ts +8 -0
- package/out/zero-cache/src/server/priority-op.d.ts.map +1 -0
- package/out/zero-cache/src/server/priority-op.js +29 -0
- package/out/zero-cache/src/server/priority-op.js.map +1 -0
- package/out/zero-cache/src/server/syncer.d.ts.map +1 -1
- package/out/zero-cache/src/server/syncer.js +9 -2
- package/out/zero-cache/src/server/syncer.js.map +1 -1
- package/out/zero-cache/src/services/analyze.js +1 -1
- package/out/zero-cache/src/services/analyze.js.map +1 -1
- package/out/zero-cache/src/services/change-source/replica-schema.d.ts.map +1 -1
- package/out/zero-cache/src/services/change-source/replica-schema.js +5 -1
- package/out/zero-cache/src/services/change-source/replica-schema.js.map +1 -1
- package/out/zero-cache/src/services/change-streamer/backup-monitor.d.ts +1 -1
- package/out/zero-cache/src/services/change-streamer/backup-monitor.d.ts.map +1 -1
- package/out/zero-cache/src/services/change-streamer/backup-monitor.js +10 -6
- package/out/zero-cache/src/services/change-streamer/backup-monitor.js.map +1 -1
- package/out/zero-cache/src/services/change-streamer/change-streamer-http.js +2 -2
- package/out/zero-cache/src/services/change-streamer/change-streamer-http.js.map +1 -1
- package/out/zero-cache/src/services/mutagen/pusher.d.ts.map +1 -1
- package/out/zero-cache/src/services/mutagen/pusher.js +1 -3
- package/out/zero-cache/src/services/mutagen/pusher.js.map +1 -1
- package/out/zero-cache/src/services/view-syncer/cvr-store.d.ts.map +1 -1
- package/out/zero-cache/src/services/view-syncer/cvr-store.js +60 -22
- package/out/zero-cache/src/services/view-syncer/cvr-store.js.map +1 -1
- package/out/zero-cache/src/services/view-syncer/cvr.d.ts.map +1 -1
- package/out/zero-cache/src/services/view-syncer/cvr.js +2 -0
- package/out/zero-cache/src/services/view-syncer/cvr.js.map +1 -1
- package/out/zero-cache/src/services/view-syncer/pipeline-driver.d.ts +1 -1
- package/out/zero-cache/src/services/view-syncer/pipeline-driver.d.ts.map +1 -1
- package/out/zero-cache/src/services/view-syncer/pipeline-driver.js +2 -2
- package/out/zero-cache/src/services/view-syncer/pipeline-driver.js.map +1 -1
- package/out/zero-cache/src/services/view-syncer/row-record-cache.d.ts +1 -1
- package/out/zero-cache/src/services/view-syncer/row-record-cache.d.ts.map +1 -1
- package/out/zero-cache/src/services/view-syncer/row-record-cache.js +22 -11
- package/out/zero-cache/src/services/view-syncer/row-record-cache.js.map +1 -1
- package/out/zero-cache/src/services/view-syncer/view-syncer.d.ts +2 -1
- package/out/zero-cache/src/services/view-syncer/view-syncer.d.ts.map +1 -1
- package/out/zero-cache/src/services/view-syncer/view-syncer.js +80 -52
- package/out/zero-cache/src/services/view-syncer/view-syncer.js.map +1 -1
- package/out/zero-cache/src/types/error-with-level.d.ts +1 -1
- package/out/zero-cache/src/types/error-with-level.d.ts.map +1 -1
- package/out/zero-cache/src/types/error-with-level.js +1 -1
- package/out/zero-cache/src/types/error-with-level.js.map +1 -1
- package/out/zero-client/src/client/connection-manager.d.ts +3 -0
- package/out/zero-client/src/client/connection-manager.d.ts.map +1 -1
- package/out/zero-client/src/client/connection-manager.js +10 -3
- package/out/zero-client/src/client/connection-manager.js.map +1 -1
- package/out/zero-client/src/client/error.d.ts +5 -1
- package/out/zero-client/src/client/error.d.ts.map +1 -1
- package/out/zero-client/src/client/error.js +3 -3
- package/out/zero-client/src/client/error.js.map +1 -1
- package/out/zero-client/src/client/options.d.ts +1 -1
- package/out/zero-client/src/client/options.js.map +1 -1
- package/out/zero-client/src/client/version.js +1 -1
- package/out/zero-client/src/client/zero.d.ts +1 -1
- 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/package.json +2 -2
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { resolver } from "@rocicorp/resolver";
|
|
2
2
|
import { Subscribable } from "../../../shared/src/subscribable.js";
|
|
3
|
-
import { ClientClosed, Offline, ConnectTimeout, AbruptClose, CleanClose } from "./client-error-kind-enum.js";
|
|
3
|
+
import { Hidden, ClientClosed, Offline, ConnectTimeout, AbruptClose, CleanClose } from "./client-error-kind-enum.js";
|
|
4
4
|
import { Connecting, NeedsAuth, Error, Closed, Disconnected, Connected } from "./connection-status-enum.js";
|
|
5
5
|
import { ClientError, isClientError } from "./error.js";
|
|
6
6
|
const DEFAULT_TIMEOUT_CHECK_INTERVAL_MS = 1e3;
|
|
@@ -93,16 +93,23 @@ class ConnectionManager extends Subscribable {
|
|
|
93
93
|
* This starts the timeout timer, but if we've entered disconnected state,
|
|
94
94
|
* we stay there and continue retrying.
|
|
95
95
|
*
|
|
96
|
+
* If we're disconnected due to a hidden tab, allow a transition back to
|
|
97
|
+
* connecting when visibility returns.
|
|
98
|
+
*
|
|
96
99
|
* @returns An object containing a promise that resolves on the next state change.
|
|
97
100
|
*/
|
|
98
101
|
connecting(reason) {
|
|
99
102
|
if (this.#state.name === Closed) {
|
|
100
103
|
return { nextStatePromise: this.#nextStatePromise() };
|
|
101
104
|
}
|
|
102
|
-
|
|
105
|
+
const isHiddenDisconnect = this.#state.name === Disconnected && this.#state.reason.kind === Hidden;
|
|
106
|
+
if (this.#state.name === Disconnected && !isHiddenDisconnect) {
|
|
103
107
|
return { nextStatePromise: this.#nextStatePromise() };
|
|
104
108
|
}
|
|
105
109
|
const now = Date.now();
|
|
110
|
+
if (isHiddenDisconnect) {
|
|
111
|
+
this.#connectingStartedAt = void 0;
|
|
112
|
+
}
|
|
106
113
|
if (this.#state.name === Connecting) {
|
|
107
114
|
this.#state = {
|
|
108
115
|
...this.#state,
|
|
@@ -297,7 +304,7 @@ class ConnectionManager extends Subscribable {
|
|
|
297
304
|
}
|
|
298
305
|
const throwIfConnectionError = (state) => {
|
|
299
306
|
if (ConnectionManager.isTerminalState(state) || state.name === Closed || (state.name === Connecting || state.name === Disconnected) && state.reason) {
|
|
300
|
-
if (isClientError(state.reason) && (state.reason.kind === ConnectTimeout || state.reason.kind === AbruptClose || state.reason.kind === CleanClose)) {
|
|
307
|
+
if (isClientError(state.reason) && (state.reason.kind === ConnectTimeout || state.reason.kind === AbruptClose || state.reason.kind === CleanClose || state.reason.kind === Hidden)) {
|
|
301
308
|
return;
|
|
302
309
|
}
|
|
303
310
|
throw state.reason;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"connection-manager.js","sources":["../../../../../zero-client/src/client/connection-manager.ts"],"sourcesContent":["import {resolver, type Resolver} from '@rocicorp/resolver';\nimport {Subscribable} from '../../../shared/src/subscribable.ts';\nimport {ClientErrorKind} from './client-error-kind.ts';\nimport {ConnectionStatus} from './connection-status.ts';\nimport {\n ClientError,\n isClientError,\n type AuthError,\n type ClosedError,\n type DisconnectedReason,\n type ZeroError,\n} from './error.ts';\n\nconst DEFAULT_TIMEOUT_CHECK_INTERVAL_MS = 1_000;\n\nexport type ConnectionManagerState =\n | {\n name: ConnectionStatus.Disconnected;\n reason: DisconnectedReason;\n }\n | {\n name: ConnectionStatus.Connecting;\n attempt: number;\n disconnectAt: number;\n reason?: ZeroError | undefined;\n }\n | {\n name: ConnectionStatus.Connected;\n }\n | {\n name: ConnectionStatus.NeedsAuth;\n reason: AuthError;\n }\n | {\n name: ConnectionStatus.Error;\n reason: ZeroError;\n }\n | {\n name: ConnectionStatus.Closed;\n reason: ClosedError;\n };\n\nexport type ConnectionManagerOptions = {\n /**\n * The amount of milliseconds we allow for continuous connecting attempts before\n * transitioning to disconnected state.\n */\n disconnectTimeout: number;\n /**\n * How frequently we check whether the connecting timeout has elapsed.\n * Defaults to 1 second.\n */\n timeoutCheckIntervalMs?: number | undefined;\n};\n\nconst TERMINAL_STATES = [\n ConnectionStatus.NeedsAuth,\n ConnectionStatus.Error,\n] as const satisfies ConnectionStatus[];\n\ntype TerminalConnectionStatus = (typeof TERMINAL_STATES)[number];\ntype TerminalConnectionManagerState = Extract<\n ConnectionManagerState,\n {name: TerminalConnectionStatus}\n>;\n\nexport class ConnectionManager extends Subscribable<ConnectionManagerState> {\n #state: ConnectionManagerState;\n\n /**\n * The timestamp when we first started trying to connect.\n * This is used to track the retry window.\n * Reset to undefined when we successfully connect or when we transition to disconnected.\n */\n #connectingStartedAt: number | undefined;\n\n /**\n * The amount of milliseconds we allow for continuous connecting attempts before\n * transitioning to disconnected state.\n */\n #disconnectTimeout: number;\n\n /**\n * Handle for the timeout interval that periodically checks whether we've\n * exceeded the allowed connecting window.\n */\n #timeoutInterval: ReturnType<typeof setInterval> | undefined;\n\n /**\n * Interval duration for checking whether the connecting timeout has elapsed.\n */\n #timeoutCheckIntervalMs: number;\n\n /**\n * Resolver used to signal waiting callers when the state changes.\n */\n #stateChangeResolver: Resolver<ConnectionManagerState> = resolver();\n\n constructor(options: ConnectionManagerOptions) {\n super();\n\n const now = Date.now();\n\n this.#disconnectTimeout = options.disconnectTimeout;\n this.#timeoutCheckIntervalMs =\n options.timeoutCheckIntervalMs ?? DEFAULT_TIMEOUT_CHECK_INTERVAL_MS;\n this.#state = {\n name: ConnectionStatus.Connecting,\n attempt: 0,\n disconnectAt: now + this.#disconnectTimeout,\n };\n this.#connectingStartedAt = now;\n this.#maybeStartTimeoutInterval();\n }\n\n get state(): ConnectionManagerState {\n return this.#state;\n }\n\n /**\n * Returns true if the current state is equal to the given status.\n */\n is(status: ConnectionStatus): boolean {\n return this.#state.name === status;\n }\n\n /**\n * Returns true if the current state is a terminal state\n * that can be recovered from by calling connect().\n */\n isInTerminalState(): boolean {\n return ConnectionManager.isTerminalState(this.#state);\n }\n\n /**\n * Returns true if the given status is a terminal state\n * that can be recovered from by calling connect().\n */\n static isTerminalState(\n state: ConnectionManagerState,\n ): state is TerminalConnectionManagerState {\n return (TERMINAL_STATES as readonly ConnectionStatus[]).includes(\n state.name,\n );\n }\n\n /**\n * Returns true if the run loop should continue.\n * The run loop continues in all states except closed.\n * In needs-auth and error states, the run loop pauses and waits for connect() to be called.\n */\n shouldContinueRunLoop(): boolean {\n return this.#state.name !== ConnectionStatus.Closed;\n }\n\n /**\n * Waits for the next state change.\n * @returns A promise that resolves when the next state change occurs.\n */\n waitForStateChange(): Promise<ConnectionManagerState> {\n return this.#nextStatePromise();\n }\n\n /**\n * Transition to connecting state.\n *\n * This starts the timeout timer, but if we've entered disconnected state,\n * we stay there and continue retrying.\n *\n * @returns An object containing a promise that resolves on the next state change.\n */\n connecting(reason?: ZeroError): {\n nextStatePromise: Promise<ConnectionManagerState>;\n } {\n // cannot transition from closed to any other status\n if (this.#state.name === ConnectionStatus.Closed) {\n return {nextStatePromise: this.#nextStatePromise()};\n }\n\n // we cannot intentionally transition from disconnected to connecting\n // disconnected can transition to connected on successful connection\n // or a terminal state\n if (this.#state.name === ConnectionStatus.Disconnected) {\n return {nextStatePromise: this.#nextStatePromise()};\n }\n\n const now = Date.now();\n\n // If we're already connecting, increment the attempt counter\n if (this.#state.name === ConnectionStatus.Connecting) {\n this.#state = {\n ...this.#state,\n attempt: this.#state.attempt + 1,\n reason,\n };\n const nextStatePromise = this.#publishStateAndGetPromise();\n this.#maybeStartTimeoutInterval();\n return {nextStatePromise};\n }\n\n // Starting a new connecting session\n // If #connectingStartedAt is undefined, this is a fresh start - set it to now\n // If it's already set, we're retrying within the same retry window, so keep it\n if (this.#connectingStartedAt === undefined) {\n this.#connectingStartedAt = now;\n }\n\n const disconnectAt = this.#connectingStartedAt + this.#disconnectTimeout;\n\n this.#state = {\n name: ConnectionStatus.Connecting,\n attempt: 1,\n disconnectAt,\n reason,\n };\n const nextStatePromise = this.#publishStateAndGetPromise();\n this.#maybeStartTimeoutInterval();\n return {nextStatePromise};\n }\n\n /**\n * Transition to connected state.\n * This resets the connecting timeout timer.\n *\n * @returns An object containing a promise that resolves on the next state change.\n */\n connected(): {nextStatePromise: Promise<ConnectionManagerState>} {\n // cannot transition from closed to any other status\n if (this.#state.name === ConnectionStatus.Closed) {\n return {nextStatePromise: this.#nextStatePromise()};\n }\n\n // Already connected, no-op\n if (this.#state.name === ConnectionStatus.Connected) {\n return {nextStatePromise: this.#nextStatePromise()};\n }\n\n // Reset the timeout timer on successful connection\n this.#connectingStartedAt = undefined;\n this.#maybeStopTimeoutInterval();\n\n this.#state = {\n name: ConnectionStatus.Connected,\n };\n const nextStatePromise = this.#publishStateAndGetPromise();\n return {nextStatePromise};\n }\n\n /**\n * Transition to disconnected state.\n * This is called when the timeout expires.\n * The run loop will continue trying to reconnect.\n *\n * @returns An object containing a promise that resolves on the next state change.\n */\n disconnected(reason: DisconnectedReason): {\n nextStatePromise: Promise<ConnectionManagerState>;\n } {\n // cannot transition from closed to any other status\n if (this.#state.name === ConnectionStatus.Closed) {\n return {nextStatePromise: this.#nextStatePromise()};\n }\n\n // Already disconnected, no-op\n if (this.#state.name === ConnectionStatus.Disconnected) {\n return {nextStatePromise: this.#nextStatePromise()};\n }\n\n // When transitioning from connected to disconnected, we've lost a connection\n // we previously had. Clear the timeout timer so we can start a fresh timeout window.\n if (this.#state.name === ConnectionStatus.Connected) {\n this.#connectingStartedAt = undefined;\n }\n // When transitioning from connecting to disconnected (e.g., due to timeout),\n // we keep the start time to maintain the context that we've been trying for a while.\n\n this.#maybeStopTimeoutInterval();\n\n this.#state = {\n name: ConnectionStatus.Disconnected,\n reason,\n };\n const nextStatePromise = this.#publishStateAndGetPromise();\n return {nextStatePromise};\n }\n\n /**\n * Transition to needs-auth state.\n * This pauses the run loop until connect() is called with new credentials.\n * Resets the retry window and attempt counter.\n *\n * @returns An object containing a promise that resolves on the next state change.\n */\n needsAuth(reason: AuthError): {\n nextStatePromise: Promise<ConnectionManagerState>;\n } {\n // cannot transition from closed to any other status\n if (this.#state.name === ConnectionStatus.Closed) {\n return {nextStatePromise: this.#nextStatePromise()};\n }\n\n // Already in needs-auth state, no-op\n if (this.#state.name === ConnectionStatus.NeedsAuth) {\n return {nextStatePromise: this.#nextStatePromise()};\n }\n\n // Reset the timeout timer and connecting start time\n this.#connectingStartedAt = undefined;\n this.#maybeStopTimeoutInterval();\n\n this.#state = {\n name: ConnectionStatus.NeedsAuth,\n reason,\n };\n const nextStatePromise = this.#publishStateAndGetPromise();\n return {nextStatePromise};\n }\n\n /**\n * Transition to error state.\n * This pauses the run loop until connect() is called.\n * Resets the retry window and attempt counter.\n *\n * @returns An object containing a promise that resolves on the next state change.\n */\n error(reason: ZeroError): {\n nextStatePromise: Promise<ConnectionManagerState>;\n } {\n // cannot transition from closed to any other status\n if (this.#state.name === ConnectionStatus.Closed) {\n return {nextStatePromise: this.#nextStatePromise()};\n }\n\n // Already in error state, no-op\n if (this.#state.name === ConnectionStatus.Error) {\n return {nextStatePromise: this.#nextStatePromise()};\n }\n\n // Reset the timeout timer and connecting start time\n this.#connectingStartedAt = undefined;\n this.#maybeStopTimeoutInterval();\n\n this.#state = {\n name: ConnectionStatus.Error,\n reason,\n };\n const nextStatePromise = this.#publishStateAndGetPromise();\n return {nextStatePromise};\n }\n\n /**\n * Transition to closed state.\n * This is terminal - no further transitions are allowed.\n */\n closed() {\n // Already closed, no-op\n if (this.#state.name === ConnectionStatus.Closed) {\n return;\n }\n\n this.#connectingStartedAt = undefined;\n this.#maybeStopTimeoutInterval();\n\n this.#state = {\n name: ConnectionStatus.Closed,\n reason: new ClientError({\n kind: ClientErrorKind.ClientClosed,\n message: 'Zero was explicitly closed by calling zero.close()',\n }),\n };\n this.#publishState();\n this.cleanup();\n return;\n }\n\n override cleanup = (): void => {\n this._listeners.clear();\n this.#resolveNextStateWaiters();\n };\n\n #resolveNextStateWaiters(): void {\n this.#stateChangeResolver.resolve(this.#state);\n this.#stateChangeResolver = resolver();\n }\n\n #publishState(): void {\n this.notify(this.#state);\n this.#resolveNextStateWaiters();\n }\n\n #nextStatePromise(): Promise<ConnectionManagerState> {\n return this.#stateChangeResolver.promise;\n }\n\n #publishStateAndGetPromise(): Promise<ConnectionManagerState> {\n this.#publishState();\n return this.#nextStatePromise();\n }\n\n /**\n * Check if we should transition from connecting to disconnected due to timeout.\n * Returns true if the transition happened.\n */\n #checkTimeout(): boolean {\n if (this.#state.name !== ConnectionStatus.Connecting) {\n return false;\n }\n\n const now = Date.now();\n if (now >= this.#state.disconnectAt) {\n this.disconnected(\n new ClientError({\n kind: ClientErrorKind.Offline,\n message: `Zero was unable to connect for ${Math.floor(this.#disconnectTimeout / 1_000)} seconds and was disconnected`,\n }),\n );\n return true;\n }\n\n return false;\n }\n\n #maybeStartTimeoutInterval(): void {\n if (this.#timeoutInterval !== undefined) {\n return;\n }\n this.#timeoutInterval = setInterval(() => {\n this.#checkTimeout();\n }, this.#timeoutCheckIntervalMs);\n }\n\n #maybeStopTimeoutInterval(): void {\n if (this.#timeoutInterval === undefined) {\n return;\n }\n clearInterval(this.#timeoutInterval);\n this.#timeoutInterval = undefined;\n }\n}\n\n/**\n * Used to trigger the catch block when a terminal state is reached.\n *\n * @param state - The current connection state.\n */\nexport const throwIfConnectionError = (state: ConnectionManagerState) => {\n if (\n ConnectionManager.isTerminalState(state) ||\n state.name === ConnectionStatus.Closed ||\n ((state.name === ConnectionStatus.Connecting ||\n state.name === ConnectionStatus.Disconnected) &&\n state.reason)\n ) {\n if (\n isClientError(state.reason) &&\n (state.reason.kind === ClientErrorKind.ConnectTimeout ||\n state.reason.kind === ClientErrorKind.AbruptClose ||\n state.reason.kind === ClientErrorKind.CleanClose)\n ) {\n return;\n }\n throw state.reason;\n }\n};\n"],"names":["ConnectionStatus.NeedsAuth","ConnectionStatus.Error","ConnectionStatus.Connecting","ConnectionStatus.Closed","ConnectionStatus.Disconnected","nextStatePromise","ConnectionStatus.Connected","ClientErrorKind.ClientClosed","ClientErrorKind.Offline","ClientErrorKind.ConnectTimeout","ClientErrorKind.AbruptClose","ClientErrorKind.CleanClose"],"mappings":";;;;;AAaA,MAAM,oCAAoC;AA0C1C,MAAM,kBAAkB;AAAA,EACtBA;AAAAA,EACAC;AACF;AAQO,MAAM,0BAA0B,aAAqC;AAAA,EAC1E;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA;AAAA;AAAA;AAAA;AAAA,EAKA;AAAA;AAAA;AAAA;AAAA,EAKA,uBAAyD,SAAA;AAAA,EAEzD,YAAY,SAAmC;AAC7C,UAAA;AAEA,UAAM,MAAM,KAAK,IAAA;AAEjB,SAAK,qBAAqB,QAAQ;AAClC,SAAK,0BACH,QAAQ,0BAA0B;AACpC,SAAK,SAAS;AAAA,MACZ,MAAMC;AAAAA,MACN,SAAS;AAAA,MACT,cAAc,MAAM,KAAK;AAAA,IAAA;AAE3B,SAAK,uBAAuB;AAC5B,SAAK,2BAAA;AAAA,EACP;AAAA,EAEA,IAAI,QAAgC;AAClC,WAAO,KAAK;AAAA,EACd;AAAA;AAAA;AAAA;AAAA,EAKA,GAAG,QAAmC;AACpC,WAAO,KAAK,OAAO,SAAS;AAAA,EAC9B;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,oBAA6B;AAC3B,WAAO,kBAAkB,gBAAgB,KAAK,MAAM;AAAA,EACtD;AAAA;AAAA;AAAA;AAAA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ACH,IAAI,YAAY;AAAA,UACd,MAAMM;AAAAA,UACN,SAAS,kCAAkC,KAAK,MAAM,KAAK,qBAAqB,GAAK,CAAC;AAAA,QAAA,CACvF;AAAA,MAAA;AAEH,aAAO;AAAA,IACT;AAEA,WAAO;AAAA,EACT;AAAA,EAEA,6BAAmC;AACjC,QAAI,KAAK,qBAAqB,QAAW;AACvC;AAAA,IACF;AACA,SAAK,mBAAmB,YAAY,MAAM;AACxC,WAAK,cAAA;AAAA,IACP,GAAG,KAAK,uBAAuB;AAAA,EACjC;AAAA,EAEA,4BAAkC;AAChC,QAAI,KAAK,qBAAqB,QAAW;AACvC;AAAA,IACF;AACA,kBAAc,KAAK,gBAAgB;AACnC,SAAK,mBAAmB;AAAA,EAC1B;AACF;AAOO,MAAM,yBAAyB,CAAC,UAAkC;AACvE,MACE,kBAAkB,gBAAgB,KAAK,KACvC,MAAM,SAASL,WACb,MAAM,SAASD,cACf,MAAM,SAASE,iBACf,MAAM,QACR;AACA,QACE,cAAc,MAAM,MAAM,MACzB,MAAM,OAAO,SAASK,kBACrB,MAAM,OAAO,SAASC,eACtB,MAAM,OAAO,SAASC,aACxB;AACA;AAAA,IACF;AACA,UAAM,MAAM;AAAA,EACd;AACF;"}
|
|
1
|
+
{"version":3,"file":"connection-manager.js","sources":["../../../../../zero-client/src/client/connection-manager.ts"],"sourcesContent":["import {resolver, type Resolver} from '@rocicorp/resolver';\nimport {Subscribable} from '../../../shared/src/subscribable.ts';\nimport {ClientErrorKind} from './client-error-kind.ts';\nimport {ConnectionStatus} from './connection-status.ts';\nimport {\n ClientError,\n isClientError,\n type AuthError,\n type ClosedError,\n type DisconnectedReason,\n type ZeroError,\n} from './error.ts';\n\nconst DEFAULT_TIMEOUT_CHECK_INTERVAL_MS = 1_000;\n\nexport type ConnectionManagerState =\n | {\n name: ConnectionStatus.Disconnected;\n reason: DisconnectedReason;\n }\n | {\n name: ConnectionStatus.Connecting;\n attempt: number;\n disconnectAt: number;\n reason?: ZeroError | undefined;\n }\n | {\n name: ConnectionStatus.Connected;\n }\n | {\n name: ConnectionStatus.NeedsAuth;\n reason: AuthError;\n }\n | {\n name: ConnectionStatus.Error;\n reason: ZeroError;\n }\n | {\n name: ConnectionStatus.Closed;\n reason: ClosedError;\n };\n\nexport type ConnectionManagerOptions = {\n /**\n * The amount of milliseconds we allow for continuous connecting attempts before\n * transitioning to disconnected state.\n */\n disconnectTimeout: number;\n /**\n * How frequently we check whether the connecting timeout has elapsed.\n * Defaults to 1 second.\n */\n timeoutCheckIntervalMs?: number | undefined;\n};\n\nconst TERMINAL_STATES = [\n ConnectionStatus.NeedsAuth,\n ConnectionStatus.Error,\n] as const satisfies ConnectionStatus[];\n\ntype TerminalConnectionStatus = (typeof TERMINAL_STATES)[number];\ntype TerminalConnectionManagerState = Extract<\n ConnectionManagerState,\n {name: TerminalConnectionStatus}\n>;\n\nexport class ConnectionManager extends Subscribable<ConnectionManagerState> {\n #state: ConnectionManagerState;\n\n /**\n * The timestamp when we first started trying to connect.\n * This is used to track the retry window.\n * Reset to undefined when we successfully connect or when we transition to disconnected.\n */\n #connectingStartedAt: number | undefined;\n\n /**\n * The amount of milliseconds we allow for continuous connecting attempts before\n * transitioning to disconnected state.\n */\n #disconnectTimeout: number;\n\n /**\n * Handle for the timeout interval that periodically checks whether we've\n * exceeded the allowed connecting window.\n */\n #timeoutInterval: ReturnType<typeof setInterval> | undefined;\n\n /**\n * Interval duration for checking whether the connecting timeout has elapsed.\n */\n #timeoutCheckIntervalMs: number;\n\n /**\n * Resolver used to signal waiting callers when the state changes.\n */\n #stateChangeResolver: Resolver<ConnectionManagerState> = resolver();\n\n constructor(options: ConnectionManagerOptions) {\n super();\n\n const now = Date.now();\n\n this.#disconnectTimeout = options.disconnectTimeout;\n this.#timeoutCheckIntervalMs =\n options.timeoutCheckIntervalMs ?? DEFAULT_TIMEOUT_CHECK_INTERVAL_MS;\n this.#state = {\n name: ConnectionStatus.Connecting,\n attempt: 0,\n disconnectAt: now + this.#disconnectTimeout,\n };\n this.#connectingStartedAt = now;\n this.#maybeStartTimeoutInterval();\n }\n\n get state(): ConnectionManagerState {\n return this.#state;\n }\n\n /**\n * Returns true if the current state is equal to the given status.\n */\n is(status: ConnectionStatus): boolean {\n return this.#state.name === status;\n }\n\n /**\n * Returns true if the current state is a terminal state\n * that can be recovered from by calling connect().\n */\n isInTerminalState(): boolean {\n return ConnectionManager.isTerminalState(this.#state);\n }\n\n /**\n * Returns true if the given status is a terminal state\n * that can be recovered from by calling connect().\n */\n static isTerminalState(\n state: ConnectionManagerState,\n ): state is TerminalConnectionManagerState {\n return (TERMINAL_STATES as readonly ConnectionStatus[]).includes(\n state.name,\n );\n }\n\n /**\n * Returns true if the run loop should continue.\n * The run loop continues in all states except closed.\n * In needs-auth and error states, the run loop pauses and waits for connect() to be called.\n */\n shouldContinueRunLoop(): boolean {\n return this.#state.name !== ConnectionStatus.Closed;\n }\n\n /**\n * Waits for the next state change.\n * @returns A promise that resolves when the next state change occurs.\n */\n waitForStateChange(): Promise<ConnectionManagerState> {\n return this.#nextStatePromise();\n }\n\n /**\n * Transition to connecting state.\n *\n * This starts the timeout timer, but if we've entered disconnected state,\n * we stay there and continue retrying.\n *\n * If we're disconnected due to a hidden tab, allow a transition back to\n * connecting when visibility returns.\n *\n * @returns An object containing a promise that resolves on the next state change.\n */\n connecting(reason?: ZeroError): {\n nextStatePromise: Promise<ConnectionManagerState>;\n } {\n // cannot transition from closed to any other status\n if (this.#state.name === ConnectionStatus.Closed) {\n return {nextStatePromise: this.#nextStatePromise()};\n }\n\n const isHiddenDisconnect =\n this.#state.name === ConnectionStatus.Disconnected &&\n this.#state.reason.kind === ClientErrorKind.Hidden;\n\n // we cannot intentionally transition from disconnected to connecting\n // unless the disconnection was due to a hidden tab\n if (\n this.#state.name === ConnectionStatus.Disconnected &&\n !isHiddenDisconnect\n ) {\n return {nextStatePromise: this.#nextStatePromise()};\n }\n\n const now = Date.now();\n\n if (isHiddenDisconnect) {\n // Reset the retry window after a hidden-tab disconnect.\n this.#connectingStartedAt = undefined;\n }\n\n // If we're already connecting, increment the attempt counter\n if (this.#state.name === ConnectionStatus.Connecting) {\n this.#state = {\n ...this.#state,\n attempt: this.#state.attempt + 1,\n reason,\n };\n const nextStatePromise = this.#publishStateAndGetPromise();\n this.#maybeStartTimeoutInterval();\n return {nextStatePromise};\n }\n\n // Starting a new connecting session\n // If #connectingStartedAt is undefined, this is a fresh start - set it to now\n // If it's already set, we're retrying within the same retry window, so keep it\n if (this.#connectingStartedAt === undefined) {\n this.#connectingStartedAt = now;\n }\n\n const disconnectAt = this.#connectingStartedAt + this.#disconnectTimeout;\n\n this.#state = {\n name: ConnectionStatus.Connecting,\n attempt: 1,\n disconnectAt,\n reason,\n };\n const nextStatePromise = this.#publishStateAndGetPromise();\n this.#maybeStartTimeoutInterval();\n return {nextStatePromise};\n }\n\n /**\n * Transition to connected state.\n * This resets the connecting timeout timer.\n *\n * @returns An object containing a promise that resolves on the next state change.\n */\n connected(): {nextStatePromise: Promise<ConnectionManagerState>} {\n // cannot transition from closed to any other status\n if (this.#state.name === ConnectionStatus.Closed) {\n return {nextStatePromise: this.#nextStatePromise()};\n }\n\n // Already connected, no-op\n if (this.#state.name === ConnectionStatus.Connected) {\n return {nextStatePromise: this.#nextStatePromise()};\n }\n\n // Reset the timeout timer on successful connection\n this.#connectingStartedAt = undefined;\n this.#maybeStopTimeoutInterval();\n\n this.#state = {\n name: ConnectionStatus.Connected,\n };\n const nextStatePromise = this.#publishStateAndGetPromise();\n return {nextStatePromise};\n }\n\n /**\n * Transition to disconnected state.\n * This is called when the timeout expires.\n * The run loop will continue trying to reconnect.\n *\n * @returns An object containing a promise that resolves on the next state change.\n */\n disconnected(reason: DisconnectedReason): {\n nextStatePromise: Promise<ConnectionManagerState>;\n } {\n // cannot transition from closed to any other status\n if (this.#state.name === ConnectionStatus.Closed) {\n return {nextStatePromise: this.#nextStatePromise()};\n }\n\n // Already disconnected, no-op\n if (this.#state.name === ConnectionStatus.Disconnected) {\n return {nextStatePromise: this.#nextStatePromise()};\n }\n\n // When transitioning from connected to disconnected, we've lost a connection\n // we previously had. Clear the timeout timer so we can start a fresh timeout window.\n if (this.#state.name === ConnectionStatus.Connected) {\n this.#connectingStartedAt = undefined;\n }\n // When transitioning from connecting to disconnected (e.g., due to timeout),\n // we keep the start time to maintain the context that we've been trying for a while.\n\n this.#maybeStopTimeoutInterval();\n\n this.#state = {\n name: ConnectionStatus.Disconnected,\n reason,\n };\n const nextStatePromise = this.#publishStateAndGetPromise();\n return {nextStatePromise};\n }\n\n /**\n * Transition to needs-auth state.\n * This pauses the run loop until connect() is called with new credentials.\n * Resets the retry window and attempt counter.\n *\n * @returns An object containing a promise that resolves on the next state change.\n */\n needsAuth(reason: AuthError): {\n nextStatePromise: Promise<ConnectionManagerState>;\n } {\n // cannot transition from closed to any other status\n if (this.#state.name === ConnectionStatus.Closed) {\n return {nextStatePromise: this.#nextStatePromise()};\n }\n\n // Already in needs-auth state, no-op\n if (this.#state.name === ConnectionStatus.NeedsAuth) {\n return {nextStatePromise: this.#nextStatePromise()};\n }\n\n // Reset the timeout timer and connecting start time\n this.#connectingStartedAt = undefined;\n this.#maybeStopTimeoutInterval();\n\n this.#state = {\n name: ConnectionStatus.NeedsAuth,\n reason,\n };\n const nextStatePromise = this.#publishStateAndGetPromise();\n return {nextStatePromise};\n }\n\n /**\n * Transition to error state.\n * This pauses the run loop until connect() is called.\n * Resets the retry window and attempt counter.\n *\n * @returns An object containing a promise that resolves on the next state change.\n */\n error(reason: ZeroError): {\n nextStatePromise: Promise<ConnectionManagerState>;\n } {\n // cannot transition from closed to any other status\n if (this.#state.name === ConnectionStatus.Closed) {\n return {nextStatePromise: this.#nextStatePromise()};\n }\n\n // Already in error state, no-op\n if (this.#state.name === ConnectionStatus.Error) {\n return {nextStatePromise: this.#nextStatePromise()};\n }\n\n // Reset the timeout timer and connecting start time\n this.#connectingStartedAt = undefined;\n this.#maybeStopTimeoutInterval();\n\n this.#state = {\n name: ConnectionStatus.Error,\n reason,\n };\n const nextStatePromise = this.#publishStateAndGetPromise();\n return {nextStatePromise};\n }\n\n /**\n * Transition to closed state.\n * This is terminal - no further transitions are allowed.\n */\n closed() {\n // Already closed, no-op\n if (this.#state.name === ConnectionStatus.Closed) {\n return;\n }\n\n this.#connectingStartedAt = undefined;\n this.#maybeStopTimeoutInterval();\n\n this.#state = {\n name: ConnectionStatus.Closed,\n reason: new ClientError({\n kind: ClientErrorKind.ClientClosed,\n message: 'Zero was explicitly closed by calling zero.close()',\n }),\n };\n this.#publishState();\n this.cleanup();\n return;\n }\n\n override cleanup = (): void => {\n this._listeners.clear();\n this.#resolveNextStateWaiters();\n };\n\n #resolveNextStateWaiters(): void {\n this.#stateChangeResolver.resolve(this.#state);\n this.#stateChangeResolver = resolver();\n }\n\n #publishState(): void {\n this.notify(this.#state);\n this.#resolveNextStateWaiters();\n }\n\n #nextStatePromise(): Promise<ConnectionManagerState> {\n return this.#stateChangeResolver.promise;\n }\n\n #publishStateAndGetPromise(): Promise<ConnectionManagerState> {\n this.#publishState();\n return this.#nextStatePromise();\n }\n\n /**\n * Check if we should transition from connecting to disconnected due to timeout.\n * Returns true if the transition happened.\n */\n #checkTimeout(): boolean {\n if (this.#state.name !== ConnectionStatus.Connecting) {\n return false;\n }\n\n const now = Date.now();\n if (now >= this.#state.disconnectAt) {\n this.disconnected(\n new ClientError({\n kind: ClientErrorKind.Offline,\n message: `Zero was unable to connect for ${Math.floor(this.#disconnectTimeout / 1_000)} seconds and was disconnected`,\n }),\n );\n return true;\n }\n\n return false;\n }\n\n #maybeStartTimeoutInterval(): void {\n if (this.#timeoutInterval !== undefined) {\n return;\n }\n this.#timeoutInterval = setInterval(() => {\n this.#checkTimeout();\n }, this.#timeoutCheckIntervalMs);\n }\n\n #maybeStopTimeoutInterval(): void {\n if (this.#timeoutInterval === undefined) {\n return;\n }\n clearInterval(this.#timeoutInterval);\n this.#timeoutInterval = undefined;\n }\n}\n\n/**\n * Used to trigger the catch block when a terminal state is reached.\n *\n * @param state - The current connection state.\n */\nexport const throwIfConnectionError = (state: ConnectionManagerState) => {\n if (\n ConnectionManager.isTerminalState(state) ||\n state.name === ConnectionStatus.Closed ||\n ((state.name === ConnectionStatus.Connecting ||\n state.name === ConnectionStatus.Disconnected) &&\n state.reason)\n ) {\n if (\n isClientError(state.reason) &&\n (state.reason.kind === ClientErrorKind.ConnectTimeout ||\n state.reason.kind === ClientErrorKind.AbruptClose ||\n state.reason.kind === ClientErrorKind.CleanClose ||\n state.reason.kind === ClientErrorKind.Hidden)\n ) {\n return;\n }\n throw state.reason;\n }\n};\n"],"names":["ConnectionStatus.NeedsAuth","ConnectionStatus.Error","ConnectionStatus.Connecting","ConnectionStatus.Closed","ConnectionStatus.Disconnected","ClientErrorKind.Hidden","nextStatePromise","ConnectionStatus.Connected","ClientErrorKind.ClientClosed","ClientErrorKind.Offline","ClientErrorKind.ConnectTimeout","ClientErrorKind.AbruptClose","ClientErrorKind.CleanClose"],"mappings":";;;;;AAaA,MAAM,oCAAoC;AA0C1C,MAAM,kBAAkB;AAAA,EACtBA;AAAAA,EACAC;AACF;AAQO,MAAM,0BAA0B,aAAqC;AAAA,EAC1E;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA;AAAA;AAAA;AAAA;AAAA,EAKA;AAAA;AAAA;AAAA;AAAA,EAKA,uBAAyD,SAAA;AAAA,EAEzD,YAAY,SAAmC;AAC7C,UAAA;AAEA,UAAM,MAAM,KAAK,IAAA;AAEjB,SAAK,qBAAqB,QAAQ;AAClC,SAAK,0BACH,QAAQ,0BAA0B;AACpC,SAAK,SAAS;AAAA,MACZ,MAAMC;AAAAA,MACN,SAAS;AAAA,MACT,cAAc,MAAM,KAAK;AAAA,IAAA;AAE3B,SAAK,uBAAuB;AAC5B,SAAK,2BAAA;AAAA,EACP;AAAA,EAEA,I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= ClientError<{
|
|
|
35
35
|
kind: ClientErrorKind.NoSocketOrigin;
|
|
36
36
|
message: string;
|
|
37
37
|
}>;
|
|
38
|
-
export type
|
|
38
|
+
export type HiddenError = ClientError<{
|
|
39
|
+
kind: ClientErrorKind.Hidden;
|
|
40
|
+
message: string;
|
|
41
|
+
}>;
|
|
42
|
+
export type DisconnectedReason = OfflineError | NoSocketOriginError | HiddenError;
|
|
39
43
|
export type ServerError = ProtocolError<ErrorBody>;
|
|
40
44
|
export type ZeroError = ServerError | ClientError;
|
|
41
45
|
export type ZeroErrorBody = Expand<ErrorBody | ClientErrorBody>;
|
|
@@ -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,EAAC,MAAM,wBAAwB,CAAC;AAExD,MAAM,MAAM,SAAS,GAAG,aAAa,CAAC,eAAe,CAAC,CAAC;AACvD,MAAM,MAAM,eAAe,GAAG;IAC5B,IAAI,EAAE,eAAe,CAAC;IACtB,MAAM,EAAE,OAAO,WAAW,CAAC,MAAM,CAAC;IAClC,OAAO,EAAE,MAAM,CAAC;CACjB,CAAC;AACF,MAAM,MAAM,WAAW,GAAG,WAAW,CAAC;IACpC,IA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D;AAED,wBAAgB,WAAW,CAAC,EAAE,EAAE,OAAO,GAAG,EAAE,IAAI,SAAS,CAmBxD;AAED,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,SAAS,GAAG,WAAW,GAAG,SAAS,CAU1E;AAED,eAAO,MAAM,oBAAoB,yBAAyB,CAAC;AAE3D,MAAM,MAAM,yBAAyB,GACjC;IAAC,MAAM,EAAE,OAAO,oBAAoB,CAAC;IAAC,MAAM,EAAE,SAAS,CAAA;CAAC,GACxD;IAAC,MAAM,EAAE,gBAAgB,CAAC,SAAS,CAAC;IAAC,MAAM,EAAE,SAAS,CAAA;CAAC,GACvD;IAAC,MAAM,EAAE,gBAAgB,CAAC,KAAK,CAAC;IAAC,MAAM,EAAE,SAAS,CAAA;CAAC,GACnD;IAAC,MAAM,EAAE,gBAAgB,CAAC,YAAY,CAAC;IAAC,MAAM,EAAE,kBAAkB,CAAA;CAAC,GACnE;IAAC,MAAM,EAAE,gBAAgB,CAAC,MAAM,CAAC;IAAC,MAAM,EAAE,SAAS,CAAA;CAAC,CAAC;AAEzD;;;GAGG;AACH,wBAAgB,4BAA4B,CAC1C,EAAE,EAAE,OAAO,GACV,yBAAyB,CAmG3B"}
|
|
@@ -4,7 +4,7 @@ import { MutationFailed, MutationRateLimited, Unauthorized, AuthInvalidated, Ser
|
|
|
4
4
|
import { Client, Server, ZeroCache } from "../../../zero-protocol/src/error-origin-enum.js";
|
|
5
5
|
import { HTTP } from "../../../zero-protocol/src/error-reason-enum.js";
|
|
6
6
|
import { isProtocolError } from "../../../zero-protocol/src/error.js";
|
|
7
|
-
import { ClientClosed, NoSocketOrigin, Offline, UserDisconnect, InvalidMessage, Internal, UnexpectedBaseCookie,
|
|
7
|
+
import { ClientClosed, NoSocketOrigin, Offline, Hidden, UserDisconnect, InvalidMessage, Internal, UnexpectedBaseCookie, PullTimeout, PingTimeout, ConnectTimeout, CleanClose, AbruptClose } from "./client-error-kind-enum.js";
|
|
8
8
|
import { NeedsAuth, Closed, Disconnected, Error as Error$1 } from "./connection-status-enum.js";
|
|
9
9
|
class ClientError extends Error {
|
|
10
10
|
errorBody;
|
|
@@ -64,7 +64,6 @@ function getErrorConnectionTransition(ex) {
|
|
|
64
64
|
case ConnectTimeout:
|
|
65
65
|
case PingTimeout:
|
|
66
66
|
case PullTimeout:
|
|
67
|
-
case Hidden:
|
|
68
67
|
case UnexpectedBaseCookie:
|
|
69
68
|
return { status: NO_STATUS_TRANSITION, reason: ex };
|
|
70
69
|
// Fatal errors that should transition to error state
|
|
@@ -72,7 +71,8 @@ function getErrorConnectionTransition(ex) {
|
|
|
72
71
|
case InvalidMessage:
|
|
73
72
|
case UserDisconnect:
|
|
74
73
|
return { status: Error$1, reason: ex };
|
|
75
|
-
// Disconnected
|
|
74
|
+
// Disconnected errors
|
|
75
|
+
case Hidden:
|
|
76
76
|
case Offline:
|
|
77
77
|
case NoSocketOrigin:
|
|
78
78
|
return {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"error.js","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 DisconnectedReason = OfflineError | NoSocketOriginError;\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.Hidden:\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 error (this should already result in a disconnected state)\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"],"names":["ErrorOrigin.Client","ErrorOrigin.Server","ErrorOrigin.ZeroCache","ErrorKind.AuthInvalidated","ErrorKind.Unauthorized","ErrorKind.PushFailed","ErrorKind.TransformFailed","ErrorReason.HTTP","ErrorKind.Rebalance","ErrorKind.Rehome","ErrorKind.ServerOverloaded","ConnectionStatus.NeedsAuth","ClientErrorKind.AbruptClose","ClientErrorKind.CleanClose","ClientErrorKind.ConnectTimeout","ClientErrorKind.PingTimeout","ClientErrorKind.PullTimeout","ClientErrorKind.Hidden","ClientErrorKind.UnexpectedBaseCookie","ClientErrorKind.Internal","ClientErrorKind.InvalidMessage","ClientErrorKind.UserDisconnect","ConnectionStatus.Error","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.MutationRateLimited","ErrorKind.MutationFailed"],"mappings":";;;;;;;;AAsDO,MAAM,oBAKH,MAAM;AAAA,EACL;AAAA,EAET,YAAY,WAAc,SAAwB;AAChD,UAAM,UAAU,SAAS,OAAO;AAChC,SAAK,OAAO;AACZ,SAAK,YAAY,EAAC,GAAG,WAAW,QAAQA,OAAY;AAAA,EACtD;AAAA,EAEA,IAAI,OAAkB;AACpB,WAAO,KAAK,UAAU;AAAA,EACxB;AACF;AAEO,SAAS,YAAY,IAA8B;AACxD,SAAO,cAAc,EAAE,KAAK,cAAc,EAAE;AAC9C;AAEO,SAAS,cAAc,IAAiD;AAC7E,SACE,cAAc,eAAe,GAAG,UAAU,WAAWA;AAEzD;AAE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;AAAA,MAIZ,KAAKC;AACH,eAAO,EAAC,QAAQC,QAAyB,QAAQ,GAAA;AAAA,MAEnD;AACE,oBAAY,GAAG,IAAI;AAAA,IAAA;AAAA,EAEzB;AAEA,MAAI,cAAc,EAAE,GAAG;AACrB,YAAQ,GAAG,MAAA;AAAA;AAAA,MAET,KAAKC;AAAAA,MACL,KAAKC;AAAAA,MACL,KAAKC;AAAAA,MACL,KAAKC;AAAAA,MACL,KAAKC;AAAAA,MACL,KAAKC;AAAAA,MACL,KAAKC;AAAAA,MACL,KAAKC;AAAAA,MACL,KAAKC;AAAAA,MACL,KAAKC;AAAAA;AAAAA;AAAAA,MAGL,KAAKhC;AAAAA,MACL,KAAKC;AACH,eAAO,EAAC,QAAQgB,SAAwB,QAAQ,GAAA;AAAA;AAAA,MAGlD,KAAKd;AAAAA,MACL,KAAKC;AAAAA,MACL,KAAKC;AACH,eAAO,EAAC,QAAQ,sBAAsB,QAAQ,GAAA;AAAA;AAAA,MAGhD,KAAKP;AAAAA,MACL,KAAKC;AACH,eAAO;AAAA,UACL,QAAQO;AAAAA,UACR,QAAQ;AAAA,QAAA;AAAA;AAAA,MAIZ,KAAK2B;AAAAA,MACL,KAAKC;AACH,eAAO,EAAC,QAAQ,sBAAsB,QAAQ,GAAA;AAAA,MAEhD;AACE,oBAAY,GAAG,IAAI;AAAA,IAAA;AAAA,EAEzB;AAIA,SAAO;AAAA,IACL,QAAQjB;AAAAA,IACR,QAAQ,IAAI;AAAA,MACV;AAAA,QACE,MAAMH;AAAAA,QACN,SAAS,gCAAgC,gBAAgB,EAAE;AAAA,MAAA;AAAA,MAE7D,EAAC,OAAO,GAAA;AAAA,IAAE;AAAA,EACZ;AAEJ;"}
|
|
1
|
+
{"version":3,"file":"error.js","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"],"names":["ErrorOrigin.Client","ErrorOrigin.Server","ErrorOrigin.ZeroCache","ErrorKind.AuthInvalidated","ErrorKind.Unauthorized","ErrorKind.PushFailed","ErrorKind.TransformFailed","ErrorReason.HTTP","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.MutationRateLimited","ErrorKind.MutationFailed"],"mappings":";;;;;;;;AA6DO,MAAM,oBAKH,MAAM;AAAA,EACL;AAAA,EAET,YAAY,WAAc,SAAwB;AAChD,UAAM,UAAU,SAAS,OAAO;AAChC,SAAK,OAAO;AACZ,SAAK,YAAY,EAAC,GAAG,WAAW,QAAQA,OAAY;AAAA,EACtD;AAAA,EAEA,IAAI,OAAkB;AACpB,WAAO,KAAK,UAAU;AAAA,EACxB;AACF;AAEO,SAAS,YAAY,IAA8B;AACxD,SAAO,cAAc,EAAE,KAAK,cAAc,EAAE;AAC9C;AAEO,SAAS,cAAc,IAAiD;AAC7E,SACE,cAAc,eAAe,GAAG,UAAU,WAAWA;AAEzD;AAEO,SAAS,cAAc,IAAgC;AAC5D,SACE,gBAAgB,EAAE,MACjB,GAAG,UAAU,WAAWC,UACvB,GAAG,UAAU,WAAWC;AAE9B;AAMO,SAAS,YAAY,IAA8B;AACxD,MAAI,cAAc,EAAE,GAAG;AACrB,QACE,GAAG,SAASC,mBACZ,GAAG,SAASC,cACZ;AACA,aAAO;AAAA,IACT;AACA,SACG,GAAG,UAAU,SAASC,cACrB,GAAG,UAAU,SAASC,oBACxB,GAAG,UAAU,WAAWC,SACvB,GAAG,UAAU,WAAW,OAAO,GAAG,UAAU,WAAW,MACxD;AACA,aAAO;AAAA,IACT;AAAA,EACF;AAEA,SAAO;AACT;AAEO,SAAS,iBAAiB,OAA2C;AAC1E,MAAI,cAAc,KAAK,GAAG;AACxB,YAAQ,MAAM,UAAU,MAAA;AAAA,MACtB,KAAKC;AAAAA,MACL,KAAKC;AAAAA,MACL,KAAKC;AACH,eAAO,MAAM;AAAA,IAAA;AAAA,EAEnB;AACA,SAAO;AACT;AAEO,MAAM,uBAAuB;AAa7B,SAAS,6BACd,IAC2B;AAE3B,MAAI,YAAY,EAAE,GAAG;AACnB,WAAO;AA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AIZ,KAAK2B;AAAAA,MACL,KAAKC;AACH,eAAO,EAAC,QAAQ,sBAAsB,QAAQ,GAAA;AAAA,MAEhD;AACE,oBAAY,GAAG,IAAI;AAAA,IAAA;AAAA,EAEzB;AAIA,SAAO;AAAA,IACL,QAAQlB;AAAAA,IACR,QAAQ,IAAI;AAAA,MACV;AAAA,QACE,MAAMH;AAAAA,QACN,SAAS,gCAAgC,gBAAgB,EAAE;AAAA,MAAA;AAAA,MAE7D,EAAC,OAAO,GAAA;AAAA,IAAE;AAAA,EACZ;AAEJ;"}
|
|
@@ -187,7 +187,7 @@ export interface ZeroOptions<S extends Schema = DefaultSchema, MD extends Custom
|
|
|
187
187
|
*
|
|
188
188
|
* Instances in hidden tabs are disconnected to save resources.
|
|
189
189
|
*
|
|
190
|
-
* Default is
|
|
190
|
+
* Default is 5 minutes.
|
|
191
191
|
*/
|
|
192
192
|
hiddenTabDisconnectDelay?: number | undefined;
|
|
193
193
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"options.js","sources":["../../../../../zero-client/src/client/options.ts"],"sourcesContent":["import type {LogLevel} from '@rocicorp/logger';\nimport type {StoreProvider} from '../../../replicache/src/kv/store.ts';\nimport * as v from '../../../shared/src/valita.ts';\nimport type {\n DefaultContext,\n DefaultSchema,\n} from '../../../zero-types/src/default-types.ts';\nimport type {Schema} from '../../../zero-types/src/schema.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 {@linkcode Zero}.\n */\nexport interface ZeroOptions<\n S extends Schema = DefaultSchema,\n MD extends CustomMutatorDefs | undefined = undefined,\n C = 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 {@linkcode 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 * 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 * The call to `connect` is handled automatically by the ZeroProvider component\n * for React and SolidJS when the `auth` prop changes.\n */\n auth?: string | null | undefined;\n\n /**\n * A unique identifier for the user. Must be non-empty.\n *\n * Each userID gets its own client-side storage so that the app can switch\n * between users without losing state.\n *\n * This must match the `sub` claim of the `auth` token if\n * `auth` is provided.\n */\n userID: string;\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 * 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 {@linkcode 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 * `onOnlineChange` is called when the Zero instance's online status changes.\n *\n * @deprecated Use {@linkcode 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 {@linkcode 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 the 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 zero-cache fails to find the server side synchronization state for\n * this client.\n *\n * The default behavior is to reload the page (using `location.reload()`).\n * Provide your own function to prevent the page from reloading automatically.\n */\n onClientStateNotFound?: (() => 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_000.\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 Synced Queries when they are executed\n */\n // TODO(arv): Mutators should also get context.\n context?: C | undefined;\n}\n\n/**\n * @deprecated Use {@link ZeroOptions} instead.\n */\nexport interface ZeroAdvancedOptions<\n S extends Schema,\n MD extends CustomMutatorDefs | undefined,\n Context,\n> extends 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"],"names":["v.literalUnion","UpdateNeededReasonType.NewClientGroup","UpdateNeededReasonType.VersionNotSupported","UpdateNeededReasonType.SchemaVersionNotSupported"],"mappings":";;AAyVO,MAAM,+BACXA;AAAAA,EACEC;AAAAA,EACAC;AAAAA,EACAC;AACF;"}
|
|
1
|
+
{"version":3,"file":"options.js","sources":["../../../../../zero-client/src/client/options.ts"],"sourcesContent":["import type {LogLevel} from '@rocicorp/logger';\nimport type {StoreProvider} from '../../../replicache/src/kv/store.ts';\nimport * as v from '../../../shared/src/valita.ts';\nimport type {\n DefaultContext,\n DefaultSchema,\n} from '../../../zero-types/src/default-types.ts';\nimport type {Schema} from '../../../zero-types/src/schema.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 {@linkcode Zero}.\n */\nexport interface ZeroOptions<\n S extends Schema = DefaultSchema,\n MD extends CustomMutatorDefs | undefined = undefined,\n C = 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 {@linkcode 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 * 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 * The call to `connect` is handled automatically by the ZeroProvider component\n * for React and SolidJS when the `auth` prop changes.\n */\n auth?: string | null | undefined;\n\n /**\n * A unique identifier for the user. Must be non-empty.\n *\n * Each userID gets its own client-side storage so that the app can switch\n * between users without losing state.\n *\n * This must match the `sub` claim of the `auth` token if\n * `auth` is provided.\n */\n userID: string;\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 * 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 {@linkcode 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 * `onOnlineChange` is called when the Zero instance's online status changes.\n *\n * @deprecated Use {@linkcode 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 {@linkcode 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 the 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 zero-cache fails to find the server side synchronization state for\n * this client.\n *\n * The default behavior is to reload the page (using `location.reload()`).\n * Provide your own function to prevent the page from reloading automatically.\n */\n onClientStateNotFound?: (() => 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 Synced Queries when they are executed\n */\n // TODO(arv): Mutators should also get context.\n context?: C | undefined;\n}\n\n/**\n * @deprecated Use {@link ZeroOptions} instead.\n */\nexport interface ZeroAdvancedOptions<\n S extends Schema,\n MD extends CustomMutatorDefs | undefined,\n Context,\n> extends 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"],"names":["v.literalUnion","UpdateNeededReasonType.NewClientGroup","UpdateNeededReasonType.VersionNotSupported","UpdateNeededReasonType.SchemaVersionNotSupported"],"mappings":";;AAyVO,MAAM,+BACXA;AAAAA,EACEC;AAAAA,EACAC;AAAAA,EACAC;AACF;"}
|
|
@@ -57,7 +57,7 @@ export declare const DEFAULT_PING_TIMEOUT_MS = 5000;
|
|
|
57
57
|
* request timed out.
|
|
58
58
|
*/
|
|
59
59
|
export declare const PULL_TIMEOUT_MS = 5000;
|
|
60
|
-
export declare const DEFAULT_DISCONNECT_HIDDEN_DELAY_MS
|
|
60
|
+
export declare const DEFAULT_DISCONNECT_HIDDEN_DELAY_MS: number;
|
|
61
61
|
/**
|
|
62
62
|
* The amount of time we allow for continuous connecting attempts before
|
|
63
63
|
* transitioning to disconnected state.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"zero.d.ts","sourceRoot":"","sources":["../../../../../zero-client/src/client/zero.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,UAAU,EAAgB,MAAM,kBAAkB,CAAC;AAC3D,OAAO,EAAC,KAAK,QAAQ,EAAW,MAAM,oBAAoB,CAAC;AAE3D,OAAO,EACL,cAAc,EAEf,MAAM,iCAAiC,CAAC;AAEzC,OAAO,KAAK,EAAC,MAAM,EAAe,MAAM,mCAAmC,CAAC;AAC5E,OAAO,KAAK,EAAC,MAAM,EAAe,MAAM,mCAAmC,CAAC;AAE5E,OAAO,KAAK,EACV,aAAa,EACb,QAAQ,EACT,MAAM,qCAAqC,CAAC;AAG7C,OAAO,KAAK,EACV,WAAW,EAEZ,MA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M,GAAG,IAAI,EACzB,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,EACZ,GAAG,EAAE,IAAI,CAAC,cAAc,CAAC,EAAE,CAAC,EAAE,WAAW,CAAC,EAC1C,SAAS,EAAE,OAAO,EAClB,uBAAuB,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,SAAS,EAC3D,EAAE,EAAE,UAAU,CAAC,OAAO,EAAE,EAAE,OAAO,EAAE,EAAE,OAAO,EAAE,EAAE,OAAO,EAAE,CAAC,gBA6B3D"}
|
|
@@ -61,7 +61,7 @@ import { ZeroRep, fromReplicacheAuthToken, toReplicacheAuthToken } from "./zero-
|
|
|
61
61
|
const RUN_LOOP_INTERVAL_MS = 5e3;
|
|
62
62
|
const DEFAULT_PING_TIMEOUT_MS = 5e3;
|
|
63
63
|
const PULL_TIMEOUT_MS = 5e3;
|
|
64
|
-
const DEFAULT_DISCONNECT_HIDDEN_DELAY_MS =
|
|
64
|
+
const DEFAULT_DISCONNECT_HIDDEN_DELAY_MS = 5 * 60 * 1e3;
|
|
65
65
|
const DEFAULT_DISCONNECT_TIMEOUT_MS = 60 * 1e3;
|
|
66
66
|
const CONNECT_TIMEOUT_MS = 1e4;
|
|
67
67
|
const CHECK_CONNECTIVITY_ON_ERROR_FREQUENCY = 6;
|