(source: Source<A>)
| 133 | |
| 134 | /** Closes a typed source into a context that composes with differently typed sources. */ |
| 135 | export 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. */ |
| 176 | export function combine(values: ReadonlyArray<SystemContext>): SystemContext { |
nothing calls this directly
no test coverage detected