* @internal * replace at runtime the commit method on instances that have been patched by the provided one * this allows multiple client db instances to have different drivers (@effect/sql or kysely)
( obj: any, commit: () => Effect.Effect<ReadonlyArray<unknown>, SqlError>, whitelist: Array<string> )
| 32 | * this allows multiple client db instances to have different drivers (@effect/sql or kysely) |
| 33 | */ |
| 34 | function effectifyWith( |
| 35 | obj: any, |
| 36 | commit: () => Effect.Effect<ReadonlyArray<unknown>, SqlError>, |
| 37 | whitelist: Array<string> |
| 38 | ) { |
| 39 | if (typeof obj !== "object" || obj === null) { |
| 40 | return obj |
| 41 | } |
| 42 | return new Proxy(obj, { |
| 43 | get(target, prop): any { |
| 44 | // Respect the proxy invariant: non-configurable, non-writable |
| 45 | // properties must return their actual value. |
| 46 | const desc = Object.getOwnPropertyDescriptor(target, prop) |
| 47 | if (desc && !desc.configurable && !desc.writable) { |
| 48 | return target[prop] |
| 49 | } |
| 50 | const prototype = Object.getPrototypeOf(target) |
| 51 | if (Effect.EffectTypeId in prototype && prop === "commit") { |
| 52 | return commit.bind(target) |
| 53 | } |
| 54 | if (typeof (target[prop]) === "function") { |
| 55 | if (typeof prop === "string" && whitelist.includes(prop)) { |
| 56 | return target[prop].bind(target) |
| 57 | } |
| 58 | return (...args: Array<any>) => effectifyWith(target[prop].call(target, ...args), commit, whitelist) |
| 59 | } |
| 60 | return effectifyWith(target[prop], commit, whitelist) |
| 61 | } |
| 62 | }) |
| 63 | } |
| 64 | |
| 65 | /** @internal */ |
| 66 | const makeSqlCommit = (client: Client.SqlClient) => { |
no outgoing calls
no test coverage detected
searching dependent graphs…