MCPcopy Create free account
hub / github.com/electric-sql/electric / parseRequest

Function parseRequest

examples/yjs/src/server/server.ts:45–69  ·  view source on GitHub ↗
(
  c: Context
)

Source from the content-addressed store, hash-verified

43)
44
45const parseRequest = async (
46 c: Context
47): Promise<ValidRequest | InvalidRequest> => {
48 const url = new URL(c.req.url)
49 const room = url.searchParams.get(`room`)
50
51 if (!room) {
52 return { isValid: false, error: `Room is required` }
53 }
54
55 const client_id = url.searchParams.get(`client_id`) ?? undefined
56
57 // Get update binary from request body
58 const arrayBuffer = await c.req.arrayBuffer()
59 const update = new Uint8Array(arrayBuffer)
60
61 if (update.length === 0) {
62 return { isValid: false, error: `No update provided` }
63 }
64 if (client_id) {
65 return { isValid: true, room, client_id, update }
66 } else {
67 return { isValid: true, room, update }
68 }
69}
70
71app.put(`/api/update`, async (c: Context) => {
72 try {

Callers 1

server.tsFile · 0.85

Calls 1

getMethod · 0.65

Tested by

no test coverage detected