MCPcopy Create free account
hub / github.com/UsefulSoftwareCo/executor / withRecordedReads

Function withRecordedReads

packages/core/sdk/src/executor.test.ts:956–981  ·  view source on GitHub ↗
(
  db: FumaDb,
  record: <A>(key: string, run: () => Promise<A>) => Promise<A>,
)

Source from the content-addressed store, hash-verified

954 * `<table>.<method>`. `withContext` re-wraps so the executor's
955 * context-bound handles stay recorded. */
956const 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
983const countingProvider = (
984 calls: { count: number },

Callers 2

recordToolRowLaunchFunction · 0.85
recordCredentialLaunchFunction · 0.85

Calls 1

wrapFunction · 0.70

Tested by

no test coverage detected