@claritylabs/cl-sync/convex) wires CL Sync’s local-first store directly to Convex’s real-time query subscriptions and mutations. You get instant IndexedDB hydration on load, live updates as Convex pushes changes, and durable optimistic mutations through the outbox — all with Convex function references typed end-to-end.
Requires
convex >=1.30.0 as a peer dependency. Install it alongside @claritylabs/cl-sync: npm install @claritylabs/cl-sync convexDefine a Convex collection
defineConvexCollection extends defineCollection with a query field (a Convex query function reference) and an optional mapSnapshot transform.
FunctionReference
required
A Convex query function reference (e.g.,
api.todos.list). Passed to client.watchQuery(query, args) to establish a real-time subscription.(result: TQuery) => TRecord[]
Optional transform applied to the Convex query result before writing records to the store. Use this when the query returns a shape that doesn’t match your
TRecord type directly.name, getId, deriveKey, sort, persist, redactBeforePersist, staleMs — behave identically to defineCollection.
Define a Convex mutation
defineConvexMutation takes a ConvexReactClient and a definition object, and returns a MutationDefinition whose flush function calls convex.mutation(...) under the hood.
FunctionReference
required
A Convex mutation function reference (e.g.,
api.todos.create).(args: TArgs, clientMutationId: string) => ConvexArgs
Optional transform applied to your mutation args before they’re passed to
convex.mutation. Use it to inject clientMutationId for server-side deduplication, rename fields, or strip client-only data.reducer, onAck, and onReject alongside mutation — the adapter only provides the flush implementation.
Subscribe to a Convex query
subscribeConvexCollection wires a Convex query subscription to your store. It fires immediately with the current snapshot and streams all subsequent updates via onUpdate.
onError callback:
Full React setup
Here’s a complete example combining the Convex adapter withSyncProvider and hooks:
Adapter types
type
Extends
CollectionDefinition<TRecord> with query: FunctionReference<"query", TQuery> and optional mapSnapshot: (result: TQuery) => TRecord[].type
Extends
MutationDefinition<TArgs, TResult> with mutation: FunctionReference<"mutation", TMutation> and optional mapArgs: (args: TArgs, clientMutationId: string) => TMutation.