| 13434 | } |
| 13435 | |
| 13436 | const makeTagProxy = (TagClass: Context.Tag<any, any> & Record<PropertyKey, any>) => { |
| 13437 | const cache = new Map() |
| 13438 | return new Proxy(TagClass, { |
| 13439 | get(target: any, prop: any, receiver) { |
| 13440 | if (prop in target) { |
| 13441 | return Reflect.get(target, prop, receiver) |
| 13442 | } |
| 13443 | if (cache.has(prop)) { |
| 13444 | return cache.get(prop) |
| 13445 | } |
| 13446 | const fn = (...args: Array<any>) => |
| 13447 | core.andThen(target, (s: any) => { |
| 13448 | if (typeof s[prop] === "function") { |
| 13449 | cache.set(prop, (...args: Array<any>) => core.andThen(target, (s: any) => s[prop](...args))) |
| 13450 | return s[prop](...args) |
| 13451 | } |
| 13452 | cache.set(prop, core.andThen(target, (s: any) => s[prop])) |
| 13453 | return s[prop] |
| 13454 | }) |
| 13455 | const cn = core.andThen(target, (s: any) => s[prop]) |
| 13456 | // @effect-diagnostics-next-line floatingEffect:off |
| 13457 | Object.assign(fn, cn) |
| 13458 | const apply = fn.apply |
| 13459 | const bind = fn.bind |
| 13460 | const call = fn.call |
| 13461 | const proto = Object.setPrototypeOf({}, Object.getPrototypeOf(cn)) |
| 13462 | proto.apply = apply |
| 13463 | proto.bind = bind |
| 13464 | proto.call = call |
| 13465 | Object.setPrototypeOf(fn, proto) |
| 13466 | cache.set(prop, fn) |
| 13467 | return fn |
| 13468 | } |
| 13469 | }) |
| 13470 | } |
| 13471 | |
| 13472 | /** |
| 13473 | * Creates a unique tag for a dependency, embedding the service's methods as |