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

Function makeLazyTestFumaDb

packages/core/sdk/src/test-config.ts:26–113  ·  view source on GitHub ↗
(options: {
  readonly tables: ReturnType<typeof collectTables>;
  readonly backend: TestDatabaseBackend;
  readonly dataDir?: string;
})

Source from the content-addressed store, hash-verified

24};
25
26const makeLazyTestFumaDb = (options: {
27 readonly tables: ReturnType<typeof collectTables>;
28 readonly backend: TestDatabaseBackend;
29 readonly dataDir?: string;
30}): TestFumaDb => {
31 let started: Promise<SqliteTestFumaDb> | undefined;
32 const start = () => {
33 if (!started) {
34 started = import("./sqlite-test-db").then(({ createSqliteTestFumaDb }) =>
35 createSqliteTestFumaDb({
36 tables: options.tables,
37 namespace: "executor_test",
38 path: options.dataDir ? `${options.dataDir}/test.db` : undefined,
39 }),
40 );
41 }
42 return started;
43 };
44
45 const internal: FumaDb["internal"] = {
46 tables: options.tables,
47 count: async (table, value) => (await start()).db.internal.count(table, value),
48 create: async (table, values) => (await start()).db.internal.create(table, values),
49 createMany: async (table, values) => (await start()).db.internal.createMany(table, values),
50 deleteMany: async (table, value) => (await start()).db.internal.deleteMany(table, value),
51 findFirst: async (table, value) => (await start()).db.internal.findFirst(table, value),
52 findMany: async (table, value) => (await start()).db.internal.findMany(table, value),
53 transaction: async (run) => (await start()).db.internal.transaction(run),
54 updateMany: async (table, value) => (await start()).db.internal.updateMany(table, value),
55 upsert: async (table, value) => (await start()).db.internal.upsert(table, value),
56 upsertMany: async (table, value) => {
57 const actual = await start();
58 if (!actual.db.internal.upsertMany) {
59 // oxlint-disable-next-line executor/no-try-catch-or-throw, executor/no-error-constructor -- boundary: lazy test DB must expose the current FumaDB adapter surface
60 throw new Error("[FumaDB] upsertMany is not supported by this adapter.");
61 }
62 return actual.db.internal.upsertMany(table, value);
63 },
64 };
65
66 const queryMethods = new Set<PropertyKey>([
67 "count",
68 "create",
69 "createMany",
70 "deleteMany",
71 "findFirst",
72 "findMany",
73 "transaction",
74 "updateMany",
75 "upsert",
76 "upsertMany",
77 ]);
78
79 const makeDb = (context?: ExecutorOwnerPolicyContext): FumaDb =>
80 new Proxy(
81 { internal: context === undefined ? internal : { ...internal, context } },
82 {
83 get(target, prop) {

Callers 1

makeTestConfigFunction · 0.85

Calls 5

countMethod · 0.80
startFunction · 0.70
makeDbFunction · 0.70
transactionMethod · 0.65
closeMethod · 0.65

Tested by

no test coverage detected