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

Function toCodec

packages/effect/src/encoding/SchemaBinary.ts:130–145  ·  view source on GitHub ↗
(schema: S, options?: Options)

Source from the content-addressed store, hash-verified

128 * @since 4.0.0
129 */
130export function toCodec<S extends Schema.Constraint>(schema: S, options?: Options): toCodec<S> {
131 const cache = options?.fingerprint === true ? fingerprintCodecCache : codecCache
132 const cached = cache.get(schema)
133 if (cached !== undefined) return cached
134 const { exact, layout, recursive, target } = compileTarget(schema)
135 const mode = compileMode(layout, options?.fingerprint)
136 const trusted: Trusted | undefined = exact ? { value: undefined } : undefined
137 const codec = assembleCodec<S>(
138 trusted === undefined ? target : withTrustedDecode(target, trusted, !recursive),
139 layout,
140 mode,
141 trusted
142 )
143 cache.set(schema, codec)
144 return codec
145}
146
147/**
148 * Derives the default-mode {@link toCodec} codec, except that decoding rejects

Callers 2

toCodecDirectFunction · 0.70
encodeUnknownSyncFunction · 0.70

Calls 6

compileTargetFunction · 0.85
compileModeFunction · 0.85
assembleCodecFunction · 0.85
withTrustedDecodeFunction · 0.85
getMethod · 0.65
setMethod · 0.65

Tested by

no test coverage detected