handleSyncRequest
handleSyncRequest<
TEnv,TDurableObjectRpc,CFHostMetada,TSyncPayload>(__namedParameters):Promise<Response>
Defined in: worker.ts:170
Handles LiveStore sync requests (e.g. with search params ?storeId=...&transport=...).
Type Parameters
Section titled “Type Parameters”TDurableObjectRpc
Section titled “TDurableObjectRpc”TDurableObjectRpc extends any = undefined
CFHostMetada
Section titled “CFHostMetada”CFHostMetada = unknown
TSyncPayload
Section titled “TSyncPayload”TSyncPayload = Json
Parameters
Section titled “Parameters”__namedParameters
Section titled “__namedParameters”ExecutionContext
Only there for type-level reasons
TEnv
headers?
Section titled “headers?”any
request
Section titled “request”Request<CFHostMetada>
searchParams
Section titled “searchParams”any
syncBackendBinding
Section titled “syncBackendBinding”ExtractDurableObjectKeys<TEnv>
Binding name of the sync backend Durable Object
syncPayloadSchema?
Section titled “syncPayloadSchema?”any
validatePayload?
Section titled “validatePayload?”(payload, context) => void | Promise<void>
Returns
Section titled “Returns”Promise<Response>
Examples
Section titled “Examples”const validatePayload = (payload: Schema.Json | undefined, context: { storeId: string }) => { if (payload?.authToken !== 'insecure-token-change-me') { throw new Error('Invalid auth token') }}const validatePayload = async (payload: Schema.Json | 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