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

Function withDecodingDefaultKey

packages/effect/src/Schema.ts:5886–5897  ·  view source on GitHub ↗
(
  defaultValue: Effect.Effect<S["Encoded"], SchemaError, R>,
  options?: DecodingDefaultOptions
)

Source from the content-addressed store, hash-verified

5884 * @since 4.0.0
5885 */
5886export function withDecodingDefaultKey<S extends Constraint, R = never>(
5887 defaultValue: Effect.Effect<S["Encoded"], SchemaError, R>,
5888 options?: DecodingDefaultOptions
5889) {
5890 const encode = options?.encodingStrategy === "omit" ? SchemaGetter.omit() : SchemaGetter.passthrough()
5891 return (self: S): withDecodingDefaultKey<S, R> => {
5892 return optionalKey(toEncoded(self)).pipe(decodeTo(self, {
5893 decode: SchemaGetter.withDefault(toIssueEffect(defaultValue)),
5894 encode
5895 }))
5896 }
5897}
5898
5899/**
5900 * Type-level representation returned by {@link withDecodingDefaultTypeKey}.

Callers 2

tagDefaultOmitFunction · 0.70

Calls 6

optionalKeyInterface · 0.85
toEncodedInterface · 0.85
toIssueEffectFunction · 0.85
decodeToFunction · 0.70
omitMethod · 0.65
pipeMethod · 0.65

Tested by

no test coverage detected