import { Future } from "./chunk-3E5YH6RS.js"; // src/futurify-class.ts function getTypeOf(Class, prop) { try { if (Reflect.has(Class, prop)) { return typeof Class[prop]; } if (Reflect.has(Class.prototype, prop)) { return typeof Class.prototype[prop]; } return "undefined"; } catch (error) { return `Error: ${error.message}`; } } function futurifyClass(Class) { const getInstanceProxy = (instance) => new Proxy( {}, { get(_, prop) { if (prop === "then") { return instance.then.bind(instance); } if (getTypeOf(Class, prop) === "function") { return (...args) => { const future = new Future( async (resolvedInstance) => { const rargs = await Promise.all(args); const result = await resolvedInstance[prop](...rargs); return result; }, [instance] ); return getInstanceProxy(future); }; } return instance.use((v) => v[prop]); } } ); const getStaticProxy = (staticFuture) => new Proxy( {}, { get(_, prop) { if (prop === "then") { return staticFuture.then.bind(staticFuture); } return staticFuture.use((v) => v[prop]); } } ); return new Proxy(Class, { get(target, prop) { if (getTypeOf(target, prop) === "function") { return (...args) => { const future2 = new Future(async () => { const rargs = await Promise.all(args); const result = await target[prop](...rargs); return result; }); return getStaticProxy(future2); }; } const future = new Future(async () => target[prop]); return getStaticProxy(future); }, construct(target, args) { const instance = new Future(async () => { const resolvedArgs = await Promise.all(args); return new target(...resolvedArgs); }); return getInstanceProxy(instance); } }); } export { futurifyClass };