MCPcopy Index your code
hub / github.com/anomalyco/opencode / make

Function make

packages/core/src/system-context/index.ts:135–173  ·  view source on GitHub ↗
(source: Source<A>)

Source from the content-addressed store, hash-verified

133
134/** Closes a typed source into a context that composes with differently typed sources. */
135export function make<A>(source: Source<A>): SystemContext {
136 const decode = Schema.decodeUnknownOption(source.codec)
137 const encode = Schema.encodeSync(source.codec)
138 const equivalent = Schema.toEquivalence(source.codec)
139 return context([
140 {
141 key: source.key,
142 load: source.load.pipe(
143 Effect.map((value) => {
144 if (isUnavailable(value)) return value
145 const snapshot = (): SourceSnapshot => ({
146 value: encode(value),
147 ...(source.removed ? { removed: requireText(source.key, "removal", source.removed(value)) } : {}),
148 })
149 return {
150 baseline: (): Rendered => ({
151 text: requireText(source.key, "baseline", source.baseline(value)),
152 snapshot: snapshot(),
153 }),
154 compare: (previous): Compared =>
155 Option.match(decode(previous), {
156 onNone: (): Compared => ({ _tag: "Incompatible" }),
157 onSome: (decoded): Compared =>
158 equivalent(decoded, value)
159 ? { _tag: "Unchanged" }
160 : {
161 _tag: "Updated",
162 render: () => ({
163 text: requireText(source.key, "update", source.update(decoded, value)),
164 snapshot: snapshot(),
165 }),
166 },
167 }),
168 }
169 }),
170 ),
171 },
172 ])
173}
174
175/** Combines contexts in order and rejects duplicate source keys immediately. */
176export function combine(values: ReadonlyArray<SystemContext>): SystemContext {

Callers

nothing calls this directly

Calls 7

isUnavailableFunction · 0.85
requireTextFunction · 0.85
equivalentFunction · 0.85
contextFunction · 0.70
snapshotFunction · 0.70
updateMethod · 0.65
decodeFunction · 0.50

Tested by

no test coverage detected