Skip to main content

Module client

Module client 

Source
Expand description

The client engine (packages/zero-client/src/client): the connection, the replica and its pending mutations, and the query and mutation bookkeeping, on memory storage.

Everything runs synchronously on one thread, driven by a Scheduler and the socket events of a SocketFactory; see event_loop.

Structs§

AnalyzeQueryOptions
What Inspector::analyze_query asks the server for besides the basics (AnalyzeQueryOptions). Options left None are not sent.
AnalyzeQueryResult
The server’s analysis of a query (AnalyzeQueryResult in packages/zero-protocol/src/analyze-query-result.ts).
ApplicationError
An error a mutator raised for the app to handle, or that the API server reported for a mutation (ApplicationError in packages/zero-protocol/src/application-error.ts). Return it from a mutator to give the caller a message and details.
ClientGroupRecord
A client group: the clients that share a replica because they register the same mutators (ClientGroup).
ClientIdPair
A deleted client the server may not know about yet.
ClientRecord
A client that used the database (ClientV6).
Connection
The connection to zero-cache (Connection in packages/zero-client/src/client/connection.ts).
Deferred
A value that arrives later, like a JS promise: the first resolve or reject wins. result reads it without waiting; a Deferred is also a future that waits for it.
DroppedDatabases
What Zero::delete and drop_all_databases deleted.
Inspector
The inspector of a client (Inspector in inspector/inspector.ts), from Zero::inspector.
InspectorClient
A client in the local store (Client in inspector/client.ts).
InspectorClientGroup
A client group in the local store (ClientGroup in inspector/client-group.ts).
InspectorQuery
A query as the server and the client know it (Query in inspector/query.ts): one row of the server’s queries answer, with the client’s metrics merged in.
MaterializedView
A view of a query that stays current as data changes (TypedView).
Metrics
The client’s and the server’s query metrics (Metrics in lazy-inspector.ts), each a digest of times in ms.
MutateRequest
A mutator applied to its arguments, ready for Zero::mutate_request (MutateRequest in JS and Swift). A define_mutator definition makes one with with.
Mutator
A mutator the client can run and replay by name (defineMutator in packages/zql/src/mutate/mutator.ts). The name must match the TS registry entry the API server runs.
MutatorResult
What mutate returns: the outcome of the optimistic run on the client, and the server’s.
PlanDebugEvent
One of the planner’s debug events (PlanDebugEventJSON in packages/zero-protocol/src/analyze-query-result.ts), as JSON: its type says which.
Preload
What preload returns.
QueryError
A query the server could not run.
StderrLogSink
The default sink: standard error.
StorageFailure
A failure of the local storage, rather than of its data (StorageFailureError): the client keeps running on memory.
StoredClients
What a database holds besides the groups’ data, read when it opens.
StoredGroup
What a client group keeps: the last server snapshot and the mutations not yet in it.
StoredMutation
A mutation that ran on a client and the server has not confirmed.
TableMutator
The CRUD operations on one table (TableCRUD in packages/zql/src/mutate/crud.ts). Values are keyed by client column name.
Transaction
The transaction a mutator runs in.
UpdateNeededReason
Why the client must be updated (UpdateNeededReason).
Zero
A Zero client: syncs the rows of named queries from zero-cache into a local replica, keeps materialized views of them current, and runs mutators optimistically before the server confirms them.
ZeroOptions
The options of a Zero client (ZeroOptions in packages/zero-client/src/client/options.ts).

Enums§

ClientErrorKind
The kinds of error the client raises itself (packages/zero-client/src/client/client-error-kind-enum.ts).
ConnectionError
Why a connection ended or could not be made: an error the client raised (ClientError) or one the server sent (ProtocolError), together ZeroError in packages/zero-client/src/client/error.ts.
ConnectionState
The connection state an app sees (ConnectionState in packages/zero-client/src/client/connection.ts).
ConnectionStatus
The status names (packages/zero-client/src/client/connection-status-enum.ts).
Error
An error of the client’s API.
LoadError
Why a database couldn’t be read.
LogLevel
How much the client logs (LogLevel). A level includes the levels after it: Warn logs warnings and errors.
MutationOutcome
How a mutation ended, on the client or on the server (MutatorResultDetails in packages/zero-client/src/client/custom.ts).
NeedsAuthReason
Why the client needs new credentials.
Reason
Why a mutator runs.
RunType
Which rows Zero::run returns.
SocketMessage
A frame from the server.
StorageFailureKind
What part of the store failed.
StorageOp
A change to the database, applied in order.
ZeroStorage
Where a client keeps its replica (ZeroStorage in zero-swift, kvStore in JS).

Traits§

LogSink
Where the client’s log messages go (LogSink).
Scheduler
The clock and timers the engine runs on: Date.now(), performance.now() and setTimeout in JS. Tests use ManualScheduler so a scenario runs the same way every time; an app’s transport provides one that runs on its event loop.
SocketConnection
An open or opening WebSocket.
SocketEvents
Receives the events of one socket.
SocketFactory
Opens the sync socket. Every call is on the engine’s thread.
StorageBackend
A place that keeps a client’s databases, such as a directory of SQLite files. Every call is on the client’s thread.
StoredDatabase
An open database of a StorageBackend.
Timer
A timer from Scheduler::schedule.

Functions§

drop_all_databases
Deletes every Zero database in storage, of every user (dropAllDatabases). Clients still open on one keep running on what they have in memory, and their later writes are dropped.
timer_delay
The delay setTimeout and setInterval wait for ms: none for NaN, a negative delay, or one past 2^31 - 1 ms, which browsers and Node fire at once.

Type Aliases§

AggregateWrites
The synced aggregate rows (a/ keys) a mutation’s last run wrote, with their values after it (None for deleted).
BatchViewUpdates
ZeroOptions::batch_view_updates: called with the function that updates the views.
RowCountsBySource
Row counts by source, then by query.
RowsByQuery
Rows by query (or table).
RowsBySource
Rows by source, then by query.
StorageFailureHandler
Called when the local store fails (onStorageFailure).
UpdateNeededHandler
Called when the server needs a newer client (onUpdateNeeded).
ViewListener
Called with a view’s data, result type, and error.