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

Function makeShipped

packages/effect/src/ui/Query.ts:4390–4529  ·  view source on GitHub ↗
(
  input: unknown
)

Source from the content-addressed store, hash-verified

4388 * @internal
4389 */
4390export const makeShipped = (
4391 input: unknown
4392): queryCore.ShippedHydration | undefined => {
4393 const parsed = parseRaw(input)
4394 if (parsed === undefined) return undefined
4395 const memo = new Map<RawTuple, ShippedMemoEntry>()
4396 // After adoption, interrupt pending cache decodes that have no instance reader.
4397 let swept = false
4398
4399 const decodeOf = (
4400 def: QueryDef,
4401 tuple: RawTuple
4402 ): Exit.Exit<unknown, SchemaIssue.Issue> | PendingDecode => {
4403 const hit = memo.get(tuple)
4404 if (hit !== undefined && hit.def === def) {
4405 return hit._tag === "Done" ? Exit.succeed(hit.value) : hit
4406 }
4407 const ran = runCodec(def.codec().decodeSuccessEffect(tuple[2]))
4408 if (Exit.isExit(ran)) {
4409 if (Exit.isSuccess(ran)) {
4410 memo.set(tuple, { _tag: "Done", def, value: ran.value })
4411 }
4412 return ran
4413 }
4414 const pending: PendingDecode = {
4415 _tag: "Pending",
4416 def,
4417 fiber: ran,
4418 waiters: 0
4419 }
4420 memo.set(tuple, pending)
4421 ran.addObserver((exit) => {
4422 if (memo.get(tuple) !== pending) return
4423 if (Exit.isSuccess(exit)) {
4424 memo.set(tuple, { _tag: "Done", def, value: exit.value })
4425 } else memo.delete(tuple)
4426 })
4427 return pending
4428 }
4429
4430 const cancel = (tuple: RawTuple, pending: PendingDecode): void => {
4431 memo.delete(tuple)
4432 pending.fiber.interruptUnsafe()
4433 }
4434
4435 const lookup: queryCore.ShippedContext = {
4436 peek: (def: QueryDef, argsKey: string) => {
4437 const tuple = parsed.get(def.name)?.get(argsKey)
4438 if (tuple === undefined || tuple[1] !== 0) return undefined
4439 const hit = memo.get(tuple)
4440 return hit?._tag === "Done" && hit.def === def
4441 ? AsyncResult.success(hit.value, { timestamp: tuple[3] })
4442 : undefined
4443 },
4444 decode: (def: QueryDef, argsKey: string) => {
4445 const tuple = parsed.get(def.name)?.get(argsKey)
4446 if (tuple === undefined || tuple[1] !== 0) {
4447 return Effect.fail(

Callers

nothing calls this directly

Calls 9

parseRawFunction · 0.85
snapshotIssueFunction · 0.85
decodeOfFunction · 0.85
cancelFunction · 0.70
getMethod · 0.65
failMethod · 0.65
awaitMethod · 0.65
mapMethod · 0.45
syncMethod · 0.45

Tested by

no test coverage detected