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

Function makeSyncEntry

packages/effect/src/SchemaParser.ts:1068–1092  ·  view source on GitHub ↗
(
  entry: CompilerRegistry.Entry,
  options?: SchemaAST.ParseOptions
)

Source from the content-addressed store, hash-verified

1066}
1067
1068function makeSyncEntry<T>(
1069 entry: CompilerRegistry.Entry,
1070 options?: SchemaAST.ParseOptions
1071): (input: unknown, options?: SchemaAST.ParseOptions) => T {
1072 const decode = entry.decode
1073 let detailed: ((input: unknown, options?: SchemaAST.ParseOptions) => T) | undefined
1074 const run = decode === undefined
1075 ? (input: unknown, parseOptions = SchemaAST.defaultParseOptions): T =>
1076 (detailed ??= makeDetailedSync<T>(entry))(input, parseOptions)
1077 : (input: unknown, parseOptions = SchemaAST.defaultParseOptions): T => {
1078 if (input === InternalParser.missing) {
1079 return (detailed ??= makeDetailedSync<T>(entry))(input, parseOptions)
1080 }
1081 let output: unknown
1082 try {
1083 output = decode(input, parseOptions)
1084 } catch (error) {
1085 InternalSchemaCause.getSchemaIssueOrThrow(Cause.die(error), "Sync adapter can only throw schema issues")
1086 throw error
1087 }
1088 if (output !== CompilerRegistry.invalid) return output as T
1089 return (detailed ??= makeDetailedSync<T>(entry))(input, parseOptions)
1090 }
1091 return withParseOptions(run, options)
1092}
1093
1094function makeDetailedSync<T>(
1095 entry: CompilerRegistry.Entry

Callers 1

makeSyncFunction · 0.85

Calls 3

makeDetailedSyncFunction · 0.85
withParseOptionsFunction · 0.85
decodeFunction · 0.70

Tested by

no test coverage detected