(schema: S, options?: Options)
| 178 | * @internal |
| 179 | */ |
| 180 | export function toCodecDirect<S extends Schema.Constraint>(schema: S, options?: Options): toCodec<S> { |
| 181 | const cache = options?.fingerprint === true ? directFingerprintCodecCache : directCodecCache |
| 182 | const cached = cache.get(schema) |
| 183 | if (cached !== undefined) return cached |
| 184 | const { exact, exitSuccess, layout, target } = compileTarget(schema) |
| 185 | if (!exact) { |
| 186 | if (!exitSuccess) return toCodec(schema, options) |
| 187 | const trusted: Trusted = { value: undefined } |
| 188 | const codec = assembleCodec<S>( |
| 189 | withExitSuccessDecode(target, trusted), |
| 190 | layout, |
| 191 | compileMode(layout, options?.fingerprint), |
| 192 | trusted, |
| 193 | true |
| 194 | ) |
| 195 | cache.set(schema, codec) |
| 196 | return codec |
| 197 | } |
| 198 | const codec = assembleCodec<S>( |
| 199 | passThrough(target), |
| 200 | layout, |
| 201 | compileMode(layout, options?.fingerprint), |
| 202 | undefined |
| 203 | ) |
| 204 | cache.set(schema, codec) |
| 205 | return codec |
| 206 | } |
| 207 | |
| 208 | function assembleCodec<S extends Schema.Constraint>( |
| 209 | target: Schema.Constraint, |
nothing calls this directly
no test coverage detected