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

Function withRecordedReads

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

Source from the content-addressed store, hash-verified

844 * `<table>.<method>`. `withContext` re-wraps so the executor's
845 * context-bound handles stay recorded. */
846const withRecordedReads = (
847 db: FumaDb,
848 record: <A>(key: string, run: () => Promise<A>) => Promise<A>,
849): FumaDb => {
850 const wrap = (inner: FumaDb): FumaDb =>
851 new Proxy(inner, {
852 get(target, prop) {
853 if (prop === "withContext") {
854 return (context: unknown) =>
855 wrap((target.withContext as (c: unknown) => FumaDb)(context));
856 }
857 if (prop === "findFirst" || prop === "findMany") {
858 return (table: unknown, query: unknown) =>
859 record(`${String(table)}.${prop}`, () =>
860 (Reflect.get(target, prop) as (t: unknown, q: unknown) => Promise<unknown>).call(
861 target,
862 table,
863 query,
864 ),
865 );
866 }
867 return Reflect.get(target, prop);
868 },
869 });
870 return wrap(db);
871};
872
873const countingProvider = (
874 calls: { count: number },

Callers 2

recordToolRowLaunchFunction · 0.85
recordCredentialLaunchFunction · 0.85

Calls 1

wrapFunction · 0.70

Tested by

no test coverage detected