MCPcopy
hub / github.com/electric-sql/pglite / fetchClient

Function fetchClient

packages/pglite-sync/test-e2e/sync-e2e.test.ts:29–67  ·  view source on GitHub ↗
(
  url: string | Request | URL,
  options: RequestInit = {},
)

Source from the content-addressed store, hash-verified

27let fetchCount = 0
28
29const fetchClient: typeof fetch = async (
30 url: string | Request | URL,
31 options: RequestInit = {},
32) => {
33 const thisFetchCount = fetchCount++
34 if (LOG_FETCH) {
35 console.log('>> fetch', thisFetchCount, url, options)
36 }
37 let table: string | null = null
38 if (typeof url === 'string') {
39 table = new URL(url).searchParams.get('table')
40 } else if (url instanceof Request) {
41 table = new URL(url.url).searchParams.get('table')
42 } else if (url instanceof URL) {
43 table = url.searchParams.get('table')
44 }
45 let res: Response
46 try {
47 res = await fetch(url, options)
48 } catch (e) {
49 if (LOG_FETCH) {
50 console.log('>> fetch error', thisFetchCount, e)
51 }
52 throw e
53 }
54 if (table) {
55 shapeHandles.set(res.headers.get('electric-handle')!, table)
56 }
57 if (LOG_FETCH) {
58 console.log(
59 '>> fetch res',
60 thisFetchCount,
61 res.status,
62 res.statusText,
63 res.headers,
64 )
65 }
66 return res
67}
68
69const deleteShape = async (table: string, handle: string) => {
70 const deleteUrl = new URL(ELECTRIC_URL)

Callers

nothing calls this directly

Calls 1

logMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…