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

Function beginRun

packages/effect/src/ui/Query.ts:6805–7026  ·  view source on GitHub ↗
(runOptions)

Source from the content-addressed store, hash-verified

6803 return fresh
6804 }
6805 const beginRun: CacheInternals["beginRun"] = (runOptions) => {
6806 const optimistic = runOptions.optimistic ?? []
6807 registerTargets(runOptions.invalidates)
6808 const declared = compileTargets(runOptions.invalidates)
6809 const targets = optimistic.length === 0
6810 ? declared
6811 : compileTargets(runOptions.invalidates, optimistic)
6812 // Open streams need explicit invalidation; a patch alone doesn't reopen them.
6813 const reopened = (): Set<Entry> => {
6814 const hit = resolve(targets)
6815 if (declared === targets) return hit
6816 for (const entry of hit) {
6817 if (
6818 entry.live !== undefined &&
6819 !targetsHit(declared, entry.def.name, entry.def.tags, entry.argsKey)
6820 ) hit.delete(entry)
6821 }
6822 return hit
6823 }
6824 // A patch over an entry with no Success isn't registered, silently.
6825 const planned: Array<{ readonly entry: Entry; readonly patch: Patch }> = []
6826 for (const patch of optimistic) {
6827 const def = register(defOf(patch.query))
6828 if (patch._tag === "Patch") {
6829 const entry = lookup(def, argsKeyOf(patch))
6830 if (entry !== undefined && entry.result?._tag === "Success") {
6831 planned.push({ entry, patch })
6832 }
6833 } else {
6834 for (const entry of index.get(def.name)?.values() ?? []) {
6835 if (entry.result?._tag === "Success") planned.push({ entry, patch })
6836 }
6837 }
6838 }
6839 // First application is all-or-nothing: a throw here leaves nothing registered.
6840 const values = new Map<Entry, unknown>()
6841 const before = new Map<Entry, { readonly encoded: unknown } | undefined>()
6842 const invalid = new Set<Entry>()
6843 for (const { entry, patch } of planned) {
6844 if (!values.has(entry)) {
6845 const server = (entry.result as AsyncResult.Success<any, any>).value
6846 // Materialized: an encoding can share parts with the value, such as under `Schema.Any`.
6847 before.set(
6848 entry,
6849 materializedEncoding(() => entry.def.codec().encodeSuccess(server))
6850 )
6851 values.set(
6852 entry,
6853 (patchedViewOf(entry, entry.result!) as {
6854 readonly result: AsyncResult.Success<any, any>
6855 })
6856 .result.value
6857 )
6858 }
6859 const next = applyPatch(
6860 patch,
6861 entry.def.name,
6862 entry.argsKey,

Callers

nothing calls this directly

Calls 15

registerTargetsFunction · 0.85
compileTargetsFunction · 0.85
defOfFunction · 0.85
argsKeyOfFunction · 0.85
materializedEncodingFunction · 0.85
patchedViewOfFunction · 0.85
applyPatchFunction · 0.85
isValidSuccessFunction · 0.85
logKeyOfFunction · 0.85
equalsOrTrueFunction · 0.85
dropFetchFunction · 0.85
holdBackFunction · 0.85

Tested by

no test coverage detected