MCPcopy Index your code
hub / github.com/TanStack/db / createProxy

Function createProxy

packages/db/src/query/builder/ref-proxy.ts:54–91  ·  view source on GitHub ↗
(path: Array<string>)

Source from the content-addressed store, hash-verified

52 const cache = new Map<string, any>()
53
54 function createProxy(path: Array<string>): any {
55 const pathKey = path.join(`.`)
56 if (cache.has(pathKey)) {
57 return cache.get(pathKey)
58 }
59
60 const proxy = new Proxy({} as any, {
61 get(target, prop, receiver) {
62 if (prop === `__refProxy`) return true
63 if (prop === `__path`) return path
64 if (prop === `__type`) return undefined // Type is only for TypeScript inference
65 if (typeof prop === `symbol`) return Reflect.get(target, prop, receiver)
66
67 const newPath = [...path, String(prop)]
68 return createProxy(newPath)
69 },
70
71 has(target, prop) {
72 if (prop === `__refProxy` || prop === `__path` || prop === `__type`)
73 return true
74 return Reflect.has(target, prop)
75 },
76
77 ownKeys(target) {
78 return Reflect.ownKeys(target)
79 },
80
81 getOwnPropertyDescriptor(target, prop) {
82 if (prop === `__refProxy` || prop === `__path` || prop === `__type`) {
83 return { enumerable: false, configurable: true }
84 }
85 return Reflect.getOwnPropertyDescriptor(target, prop)
86 },
87 })
88
89 cache.set(pathKey, proxy)
90 return proxy
91 }
92
93 // Return the root proxy that starts with an empty path
94 return createProxy([]) as SingleRowRefProxy<T>

Callers 2

getFunction · 0.85
createSingleRowRefProxyFunction · 0.85

Calls 4

joinMethod · 0.45
hasMethod · 0.45
getMethod · 0.45
setMethod · 0.45

Tested by

no test coverage detected