Skip to main content

Module protocol

Module protocol 

Source
Expand description

The zero-protocol wire messages (packages/zero-protocol/src), decoded as valita does in passthrough mode: unknown keys are accepted and dropped, and optional fields may be absent but not null unless they are nullable.

Modules§

poke_chunk
The binary poke chunks of protocol 52 and later. Between pokeStart and pokeEnd zero-cache may send a poke’s parts as binary messages instead of pokePart messages: each is a MESSAGE_TYPE byte and then the next bytes of the UTF-8 JSON of a PokePartBody[]. A chunk can end inside a UTF-8 sequence.
sec_protocols
The Sec-WebSocket-Protocol value that carries the initConnection message and the auth token (encodeSecProtocols and decodeSecProtocols): the UTF-8 of JSON.stringify({initConnectionMessage, authToken}), base64 encoded, then URI encoded.
valita
A small interpreter of valita schemas (packages/shared/src/valita.ts), for messages kept as JSON rather than decoded into Rust types.

Structs§

ChangeDesiredQueriesBody
changeDesiredQueries (change-desired-queries.ts).
ClientSchema
ClientTable
tableSchemaSchema: each column’s {type}, and the primary key.
ConnectedBody
The connected message zero-cache sends once a connection is set up.
ConnectionUrl
The sync socket’s URL: /sync/v{PROTOCOL_VERSION}/connect on the socket origin, with the query parameters in the order JS sets them (createConnectionURL in packages/zero-client/src/client/zero.ts).
CrudOp
One operation of a CRUD mutation (crudOpSchema). An update’s value is a partial row with at least the primary key columns; a delete’s holds the primary key columns, each a string, number, or boolean.
DeleteClientsBody
deleteClients, in either direction (delete-clients.ts).
InitConnectionBody
The first message a client sends, usually in the Sec-WebSocket-Protocol header (initConnectionBodySchema).
InspectDownBody
An inspect response from zero-cache (inspectDownBodySchema).
InspectUpBody
An inspect request from the client (inspectUpBodySchema).
MutationError
A failed mutation’s result (mutationErrorSchema), kept as sent: see MutationResult for which results are errors.
MutationId
packages/zero-protocol/src/mutation-id.ts.
MutationResponse
mutationResponseSchema.
PokeEndBody
Ends a poke (pokeEndBodySchema).
PokePartBody
One part of a poke (pokePartBodySchema).
PokeStartBody
Starts a poke (pokeStartBodySchema).
PullRequestBody
A pull request (pullRequestBodySchema).
PullResponseBody
A pull response (pullResponseBodySchema). Pull only recovers mutations, so it carries no patch.
PushBody
The body of a push message (pushBodySchema).
SchemaVersions
The range of schema versions the server supports.
UpQueriesPut
A query a client wants synced (upPutOpSchema). A client query carries its ast; a custom query its name and args.
UpdateAuthBody
updateAuth (update-auth.ts).

Enums§

CrudOpKind
Downstream
A message from zero-cache. The union is closed: the client treats a message with a tag it doesn’t know as invalid and disconnects.
ErrorBody
ErrorKind
The kind of a protocol error (error-kind-enum.ts), in the order of errorKindSchema, which valita’s messages list.
ErrorOrigin
Where an error came from (error-origin-enum.ts).
ErrorReason
Why a push or transform failed (error-reason-enum.ts).
ErroredQuery
A custom query the API server failed to transform (erroredQuerySchema in custom-queries.ts).
FailureCause
Why a push or transform failed: the origin and reason of pushFailedBodySchema and transformFailedBodySchema, whose three variants each allow different combinations.
Mutation
A mutation as pushed to zero-cache (mutationSchema).
MutationPatchOp
A change to the mutation results zero-cache tracks for a client (mutations-patch.ts).
MutationResult
The result of running a mutation on the API server (mutationResultSchema), read as the JS client reads it: in passthrough mode, telling errors apart with 'error' in result. The union’s OK branch, {data?}, accepts every object, so a result with data is OK even if it has an error, and any other result with an error, whatever its value, is an error.
MutationType
mutation-type-enum.ts.
PushError
The deprecated error responses to a push (pushErrorSchema). zero-cache now reports push failures with error messages.
PushResponseBody
The body of a pushResponse message (pushResponseBodySchema). valita tries the OK variant first, and it has no discriminator: a body with a valid mutations array is OK even if it also has an error key.
QueriesPatchOp
A change to a set of queries as zero-cache sends it (patchOpSchema).
RowPatchOp
A change to the synced rows (rowPatchOpSchema).
UpQueriesPatchOp
A change to a client’s desired queries, as the client sends it (upPatchOpSchema).
Upstream

Constants§

CRUD_MUTATION_NAME
The name of every CRUD mutation (CRUD_MUTATION_NAME).
PROTOCOL_VERSION
The sync protocol version this client speaks (PROTOCOL_VERSION in packages/zero-protocol/src/protocol-version.ts).

Functions§

parse_message
Parses the text of a WebSocket message.

Type Aliases§

PrimaryKeyValueRecord
The values of a row’s primary key columns, by column. Each is a string, number, or boolean.
QueriesPatch
RowRecord
A row as the protocol carries it (rowSchema): a record of JSON values.
UpQueriesPatch
Version
A cookie: the version of the client view a client has. Where the protocol allows a NullableVersion, None is the state before the first pull.