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

Function patchField

packages/effect/src/eventlog/EventRow.ts:660–675  ·  view source on GitHub ↗
(field: Schema.Constraint)

Source from the content-addressed store, hash-verified

658
659// Run the field codec only for present keys, bypassing missing-key defaults.
660const patchField = (field: Schema.Constraint): Schema.Constraint => {
661 const decode = SchemaParser.decodeUnknownEffect(field)
662 // The struct wrapper detects encodings that drop a written key.
663 const encode = SchemaParser.encodeUnknownEffect(Schema.Struct({ value: field }))
664 return Schema.optionalKey(Schema.toEncoded(field)).pipe(Schema.decodeTo(Schema.optionalKey(Schema.toType(field)), {
665 decode: SchemaGetter.transformEffect(decode),
666 encode: SchemaGetter.transformEffect((value, options) =>
667 Effect.flatMap(encode({ value }, options), (encoded) =>
668 Object.hasOwn(encoded, "value")
669 ? Effect.succeed(encoded.value)
670 : Effect.fail(
671 new SchemaIssue.Forbidden({ message: "A patch cannot write a value whose encoding omits the key" }, value)
672 ))
673 )
674 }))
675}
676
677type DecodingServices<
678 Fields extends Schema.Struct.Fields,

Callers 1

makeFunction · 0.85

Calls 5

pipeMethod · 0.65
optionalKeyMethod · 0.65
failMethod · 0.65
encodeFunction · 0.50
succeedMethod · 0.45

Tested by

no test coverage detected