()
| 47 | * Used in collection indexes and where clauses |
| 48 | */ |
| 49 | export function createSingleRowRefProxy< |
| 50 | T extends Record<string, any>, |
| 51 | >(): SingleRowRefProxy<T> { |
| 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> |
| 95 | } |
| 96 | |
| 97 | /** |
| 98 | * Creates a proxy object that records property access paths |
no test coverage detected