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

Function make

packages/sql/src/SqlResolver.ts:119–180  ·  view source on GitHub ↗
(context: Context.Context<R> | undefined)

Source from the content-addressed store, hash-verified

117 withContext?: boolean
118): Effect.Effect<SqlResolver<T, I, A, E, RI>, never, R> => {
119 function make(context: Context.Context<R> | undefined) {
120 const encode = Schema.encode(Request)
121 function makeExecute(self: RequestResolver.RequestResolver<SqlRequest<T, A, E>>) {
122 return function(input: I) {
123 return Effect.useSpan(
124 `sql.Resolver.execute ${tag}`,
125 { kind: "client", captureStackTrace: false },
126 (span) =>
127 Effect.withFiberRuntime<A, E | ParseError, RI>((fiber) => {
128 span.attribute("request.input", input)
129 const currentContext = fiber.currentContext
130 const connection = currentContext.unsafeMap.get(
131 internalClient.TransactionConnection.key
132 )
133 let toProvide: Context.Context<R> | undefined = context
134 if (connection !== undefined) {
135 if (toProvide === undefined) {
136 toProvide = Context.make(
137 internalClient.TransactionConnection,
138 connection
139 ) as Context.Context<R>
140 } else {
141 toProvide = Context.add(
142 toProvide,
143 internalClient.TransactionConnection,
144 connection
145 )
146 }
147 }
148 const resolver = toProvide === undefined
149 ? self
150 : RequestResolver.provideContext(self, toProvide)
151 return Effect.flatMap(
152 encode(input),
153 (encoded) => Effect.request(makeRequest<T, I, II, A, E>(tag, input, encoded, span), resolver)
154 )
155 })
156 )
157 }
158 }
159 return Object.assign(self, {
160 request(input: I) {
161 return Effect.withFiberRuntime<SqlRequest<T, A, E>, ParseError, RI>(
162 (fiber) => {
163 const span = fiber.currentContext.unsafeMap.get(Tracer.ParentSpan.key)
164 return Effect.map(encode(input), (encoded) => makeRequest(tag, input, encoded, span))
165 }
166 )
167 },
168 cachePopulate(input: I, value: A) {
169 return Effect.cacheRequestResult(makeRequest(tag, input, null as any, null as any), Exit.succeed(value))
170 },
171 cacheInvalidate(input: I) {
172 return Effect.withFiberRuntime<void>((fiber) => {
173 const cache = fiber.getFiberRef(FiberRef.currentRequestCache)
174 return cache.invalidate(makeRequest(tag, input, null as any, null as any))
175 })
176 },

Callers 1

makeResolverFunction · 0.70

Calls 2

makeExecuteFunction · 0.85
encodeMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…