MCPcopy Index your code
hub / github.com/Effect-TS/effect / effectifyWith

Function effectifyWith

packages/sql-kysely/src/internal/patch.ts:34–63  ·  view source on GitHub ↗

* @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>
)

Source from the content-addressed store, hash-verified

32 * this allows multiple client db instances to have different drivers (@effect/sql or kysely)
33 */
34function 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 */
66const makeSqlCommit = (client: Client.SqlClient) => {

Callers 3

getFunction · 0.85
effectifyWithSqlFunction · 0.85
effectifyWithExecuteFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…