MCPcopy Create free account
hub / github.com/Effect-TS/effect / effectifyWith

Function effectifyWith

packages/sql-kysely/src/internal/patch.ts:29–69  ·  view source on GitHub ↗
(
  obj: any,
  commit: (plugins: ReadonlyArray<KyselyPlugin>) => Effect.Effect<ReadonlyArray<unknown>, SqlError>,
  whitelist: Array<string>,
  plugins: ReadonlyArray<KyselyPlugin> = []
)

Source from the content-addressed store, hash-verified

27}
28
29function effectifyWith(
30 obj: any,
31 commit: (plugins: ReadonlyArray<KyselyPlugin>) => Effect.Effect<ReadonlyArray<unknown>, SqlError>,
32 whitelist: Array<string>,
33 plugins: ReadonlyArray<KyselyPlugin> = []
34) {
35 if (typeof obj !== "object" || obj === null) {
36 return obj
37 }
38 return new Proxy(obj, {
39 get(target, prop, receiver) {
40 // Proxy invariants require returning fixed properties unchanged.
41 const desc = Object.getOwnPropertyDescriptor(target, prop)
42 if (desc && !desc.configurable && !desc.writable) {
43 return target[prop]
44 }
45 const prototype = Object.getPrototypeOf(target)
46 if (Effect.EffectTypeId in prototype && prop === "commit") {
47 return commit.bind(target, plugins)
48 }
49 if (typeof (target[prop]) === "function") {
50 if (typeof prop === "string" && whitelist.includes(prop)) {
51 return target[prop].bind(target)
52 }
53 return (...args: Array<unknown>) => {
54 // Callback helpers need the proxy to retain plugin tracking.
55 if (prop === "$call" || (prop === "$if" && args[0])) {
56 return target[prop].call(receiver, ...args)
57 }
58 return effectifyWith(
59 target[prop].call(target, ...args),
60 commit,
61 whitelist,
62 prop === "withPlugin" ? [...plugins, args[0] as KyselyPlugin] : prop === "withoutPlugins" ? [] : plugins
63 )
64 }
65 }
66 return effectifyWith(target[prop], commit, whitelist, plugins)
67 }
68 })
69}
70
71/** @internal */
72const 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