handleSyncRequest
handleSyncRequest<
TEnv,TDurableObjectRpc,CFHostMetada,TSyncPayload>(__namedParameters):Promise<Response>
Defined in: packages/@livestore/sync-cf/src/cf-worker/worker.ts:168
Handles LiveStore sync requests (e.g. with search params ?storeId=...&transport=...).
Type Parameters
Section titled “Type Parameters”TDurableObjectRpc
Section titled “TDurableObjectRpc”TDurableObjectRpc extends undefined | DurableObjectBranded = undefined
CFHostMetada
Section titled “CFHostMetada”CFHostMetada = unknown
TSyncPayload
Section titled “TSyncPayload”TSyncPayload = JsonValue
Parameters
Section titled “Parameters”__namedParameters
Section titled “__namedParameters”Only there for type-level reasons
TEnv
headers?
Section titled “headers?”request
Section titled “request”Request<CFHostMetada>
searchParams
Section titled “searchParams”{ payload: undefined | JsonValue; storeId: string; transport: "http" | "ws"; }
searchParams.payload
Section titled “searchParams.payload”undefined | JsonValue = ...
searchParams.storeId
Section titled “searchParams.storeId”string = Schema.String
searchParams.transport
Section titled “searchParams.transport”"http" | "ws" = ...
syncBackendBinding
Section titled “syncBackendBinding”ExtractDurableObjectKeys<TEnv>
Binding name of the sync backend Durable Object
syncPayloadSchema?
Section titled “syncPayloadSchema?”Schema<TSyncPayload, TSyncPayload, never>
validatePayload?
Section titled “validatePayload?”(payload, context) => void | Promise<void>
Returns
Section titled “Returns”Promise<Response>
Examples
Section titled “Examples”const validatePayload = (payload: Schema.JsonValue | undefined, context: { storeId: string }) => { if (payload?.authToken !== 'insecure-token-change-me') { throw new Error('Invalid auth token') }}const validatePayload = async (payload: Schema.JsonValue | undefined, { storeId, headers }) => { const cookie = headers.get('cookie') const session = await validateSessionFromCookie(cookie) if (!session) throw new Error('Unauthorized')}Throws
Section titled “Throws”If the payload is invalid