(schema: S, options?: Options)
| 128 | * @since 4.0.0 |
| 129 | */ |
| 130 | export 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 |
no test coverage detected