( db: FumaDb, record: <A>(key: string, run: () => Promise<A>) => Promise<A>, )
| 954 | * `<table>.<method>`. `withContext` re-wraps so the executor's |
| 955 | * context-bound handles stay recorded. */ |
| 956 | const withRecordedReads = ( |
| 957 | db: FumaDb, |
| 958 | record: <A>(key: string, run: () => Promise<A>) => Promise<A>, |
| 959 | ): FumaDb => { |
| 960 | const wrap = (inner: FumaDb): FumaDb => |
| 961 | new Proxy(inner, { |
| 962 | get(target, prop) { |
| 963 | if (prop === "withContext") { |
| 964 | return (context: unknown) => |
| 965 | wrap((target.withContext as (c: unknown) => FumaDb)(context)); |
| 966 | } |
| 967 | if (prop === "findFirst" || prop === "findMany") { |
| 968 | return (table: unknown, query: unknown) => |
| 969 | record(`${String(table)}.${prop}`, () => |
| 970 | (Reflect.get(target, prop) as (t: unknown, q: unknown) => Promise<unknown>).call( |
| 971 | target, |
| 972 | table, |
| 973 | query, |
| 974 | ), |
| 975 | ); |
| 976 | } |
| 977 | return Reflect.get(target, prop); |
| 978 | }, |
| 979 | }); |
| 980 | return wrap(db); |
| 981 | }; |
| 982 | |
| 983 | const countingProvider = ( |
| 984 | calls: { count: number }, |
no test coverage detected