MCPcopy Index your code
hub / github.com/upstash/jstack / get

Function get

packages/jstack/src/server/client.ts:224–277  ·  view source on GitHub ↗
(target, prop, receiver)

Source from the content-addressed store, hash-verified

222): any {
223 return new Proxy(baseClient, {
224 get(target, prop, receiver) {
225 if (typeof prop === "string") {
226 const routePath = [...path, prop]
227
228 if (prop === "$get") {
229 return async (...args: any[]) => {
230 const [data, options] = args
231 const serializedQuery = serializeWithSuperJSON(data)
232 return target.$get({ query: serializedQuery }, options)
233 }
234 }
235
236 if (prop === "$post") {
237 return async (...args: any[]) => {
238 const [data, options] = args
239 const serializedJson = serializeWithSuperJSON(data)
240 return target.$post({ json: serializedJson }, options)
241 }
242 }
243
244 if (prop === "$url") {
245 return (args?: any) => {
246 const endpointPath = `/${routePath.slice(0, -1).join("/")}`
247 const normalizedPath = endpointPath.replace(baseUrl, "")
248 const url = new URL(baseUrl + normalizedPath)
249
250 if (args?.query) {
251 Object.entries(args.query).forEach(([key, value]) => {
252 url.searchParams.append(key, String(value))
253 })
254 }
255
256 return url
257 }
258 }
259
260 if (prop === "$ws") {
261 return () => {
262 const endpointPath = `/${routePath.slice(0, -1).join("/")}`
263 const normalizedPath = endpointPath.replace(baseUrl, "")
264 const url = new URL(baseUrl + normalizedPath)
265
266 // Change protocol to ws:// or wss:// depending on if https or http
267 url.protocol = url.protocol === "https:" ? "wss:" : "ws:"
268
269 return new ClientSocket(url)
270 }
271 }
272
273 return createProxy(target[prop], baseUrl, routePath)
274 }
275
276 return Reflect.get(target, prop, receiver)
277 },
278 })
279}
280

Callers

nothing calls this directly

Calls 4

serializeWithSuperJSONFunction · 0.85
createProxyFunction · 0.85
joinMethod · 0.80
getMethod · 0.80

Tested by

no test coverage detected