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

Function createRefProxy

packages/db/src/query/builder/ref-proxy.ts:101–194  ·  view source on GitHub ↗
(
  aliases: Array<string>,
)

Source from the content-addressed store, hash-verified

99 * Used in callbacks like where, select, etc. to create type-safe references
100 */
101export function createRefProxy<T extends Record<string, any>>(
102 aliases: Array<string>,
103): RefProxy<T> & T {
104 const cache = new Map<string, any>()
105 let accessId = 0 // Monotonic counter to record evaluation order
106
107 function createProxy(path: Array<string>): any {
108 const pathKey = path.join(`.`)
109 if (cache.has(pathKey)) {
110 return cache.get(pathKey)
111 }
112
113 const proxy = new Proxy({} as any, {
114 get(target, prop, receiver) {
115 if (prop === `__refProxy`) return true
116 if (prop === `__path`) return path
117 if (prop === `__type`) return undefined // Type is only for TypeScript inference
118 if (typeof prop === `symbol`) return Reflect.get(target, prop, receiver)
119
120 const newPath = [...path, String(prop)]
121 return createProxy(newPath)
122 },
123
124 has(target, prop) {
125 if (prop === `__refProxy` || prop === `__path` || prop === `__type`)
126 return true
127 return Reflect.has(target, prop)
128 },
129
130 ownKeys(target) {
131 const id = ++accessId
132 const sentinelKey = `__SPREAD_SENTINEL__${path.join(`.`)}__${id}`
133 if (!Object.prototype.hasOwnProperty.call(target, sentinelKey)) {
134 Object.defineProperty(target, sentinelKey, {
135 enumerable: true,
136 configurable: true,
137 value: true,
138 })
139 }
140 return Reflect.ownKeys(target)
141 },
142
143 getOwnPropertyDescriptor(target, prop) {
144 if (prop === `__refProxy` || prop === `__path` || prop === `__type`) {
145 return { enumerable: false, configurable: true }
146 }
147 return Reflect.getOwnPropertyDescriptor(target, prop)
148 },
149 })
150
151 cache.set(pathKey, proxy)
152 return proxy
153 }
154
155 // Create the root proxy with all aliases as top-level properties
156 const rootProxy = new Proxy({} as any, {
157 get(target, prop, receiver) {
158 if (prop === `__refProxy`) return true

Callers 8

joinMethod · 0.85
whereMethod · 0.85
havingMethod · 0.85
selectMethod · 0.85
orderByMethod · 0.85
groupByMethod · 0.85
ref-proxy.test.tsFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…