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
pokeStartandpokeEndzero-cache may send a poke’s parts as binary messages instead ofpokePartmessages: each is aMESSAGE_TYPEbyte and then the next bytes of the UTF-8 JSON of aPokePartBody[]. A chunk can end inside a UTF-8 sequence. - sec_
protocols - The
Sec-WebSocket-Protocolvalue that carries theinitConnectionmessage and the auth token (encodeSecProtocolsanddecodeSecProtocols): the UTF-8 ofJSON.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§
- Change
Desired Queries Body changeDesiredQueries(change-desired-queries.ts).- Client
Schema - Client
Table tableSchemaSchema: each column’s{type}, and the primary key.- Connected
Body - The
connectedmessage zero-cache sends once a connection is set up. - Connection
Url - The sync socket’s URL:
/sync/v{PROTOCOL_VERSION}/connecton the socket origin, with the query parameters in the order JS sets them (createConnectionURLinpackages/zero-client/src/client/zero.ts). - CrudOp
- One operation of a CRUD mutation (
crudOpSchema). An update’svalueis a partial row with at least the primary key columns; a delete’s holds the primary key columns, each a string, number, or boolean. - Delete
Clients Body deleteClients, in either direction (delete-clients.ts).- Init
Connection Body - The first message a client sends, usually in the
Sec-WebSocket-Protocolheader (initConnectionBodySchema). - Inspect
Down Body - An
inspectresponse from zero-cache (inspectDownBodySchema). - Inspect
UpBody - An
inspectrequest from the client (inspectUpBodySchema). - Mutation
Error - A failed mutation’s result (
mutationErrorSchema), kept as sent: seeMutationResultfor which results are errors. - Mutation
Id packages/zero-protocol/src/mutation-id.ts.- Mutation
Response mutationResponseSchema.- Poke
EndBody - Ends a poke (
pokeEndBodySchema). - Poke
Part Body - One part of a poke (
pokePartBodySchema). - Poke
Start Body - Starts a poke (
pokeStartBodySchema). - Pull
Request Body - A
pullrequest (pullRequestBodySchema). - Pull
Response Body - A
pullresponse (pullResponseBodySchema). Pull only recovers mutations, so it carries no patch. - Push
Body - The body of a
pushmessage (pushBodySchema). - Schema
Versions - The range of schema versions the server supports.
- UpQueries
Put - A query a client wants synced (
upPutOpSchema). A client query carries itsast; a custom query itsnameandargs. - Update
Auth Body updateAuth(update-auth.ts).
Enums§
- Crud
OpKind - 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.
- Error
Body - Error
Kind - The kind of a protocol error (
error-kind-enum.ts), in the order oferrorKindSchema, which valita’s messages list. - Error
Origin - Where an error came from (
error-origin-enum.ts). - Error
Reason - Why a push or transform failed (
error-reason-enum.ts). - Errored
Query - A custom query the API server failed to transform (
erroredQuerySchemaincustom-queries.ts). - Failure
Cause - Why a push or transform failed: the
originandreasonofpushFailedBodySchemaandtransformFailedBodySchema, whose three variants each allow different combinations. - Mutation
- A mutation as pushed to zero-cache (
mutationSchema). - Mutation
Patch Op - A change to the mutation results zero-cache tracks for a client
(
mutations-patch.ts). - Mutation
Result - The result of running a mutation on the API server
(
mutationResultSchema), read as the JS client reads it: inpassthroughmode, telling errors apart with'error' in result. The union’s OK branch,{data?}, accepts every object, so a result withdatais OK even if it has anerror, and any other result with anerror, whatever its value, is an error. - Mutation
Type mutation-type-enum.ts.- Push
Error - The deprecated error responses to a push (
pushErrorSchema). zero-cache now reports push failures witherrormessages. - Push
Response Body - The body of a
pushResponsemessage (pushResponseBodySchema). valita tries the OK variant first, and it has no discriminator: a body with a validmutationsarray is OK even if it also has anerrorkey. - Queries
Patch Op - A change to a set of queries as zero-cache sends it (
patchOpSchema). - RowPatch
Op - A change to the synced rows (
rowPatchOpSchema). - UpQueries
Patch Op - 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_VERSIONinpackages/zero-protocol/src/protocol-version.ts).
Functions§
- parse_
message - Parses the text of a WebSocket message.
Type Aliases§
- Primary
KeyValue Record - The values of a row’s primary key columns, by column. Each is a string, number, or boolean.
- Queries
Patch - RowRecord
- A row as the protocol carries it (
rowSchema): a record of JSON values. - UpQueries
Patch - Version
- A cookie: the version of the client view a client has. Where the
protocol allows a
NullableVersion,Noneis the state before the first pull.