UNPKG

@openapi-qraft/react

Version:

OpenAPI client for React, providing type-safe requests and dynamic TanStack Query React Hooks via a modular, Proxy-based architecture.

35 lines (32 loc) 1.35 kB
'use strict'; /** * Creates a recursive proxy that calls the `getCallback` and `applyCallback` functions * @param getCallback The callback to call when a proxy property is accessed * @param applyCallback The callback to call when a proxy is called as a function * @param path The current path of the proxy */ function createRecursiveProxy(getCallback, applyCallback, path) { return new Proxy(noop, { get (_obj, key) { if (key === 'then') { // special case for if the proxy is accidentally treated // like a PromiseLike (like in `Promise.resolve(proxy)`) return undefined; } return getCallback(path, key) ?? createRecursiveProxy(getCallback, applyCallback, [ ...path, key ]); }, apply (_1, _2, args) { const functionName = path[path.length - 1]; const isCall = functionName === 'call'; const isApply = isCall ? false : functionName === 'apply'; return applyCallback(isApply || isCall ? path.slice(0, -1) : path, isApply ? args.length >= 2 ? args[1] : [] : isCall ? args.slice(1) : args); } }); } function noop() { // noop } exports.createRecursiveProxy = createRecursiveProxy; //# sourceMappingURL=createRecursiveProxy.cjs.map