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

Function parseLocal

packages/effect/src/SchemaParser.ts:1105–1162  ·  view source on GitHub ↗
(
    input: unknown,
    options: SchemaAST.ParseOptions
  )

Source from the content-addressed store, hash-verified

1103 }
1104 let encodingParsers: ReadonlyArray<Parser> | undefined
1105 const parseLocal = (
1106 input: unknown,
1107 options: SchemaAST.ParseOptions
1108 ) => {
1109 let result = parser(input, options)
1110 if (encodingChecks && !options.disableChecks) {
1111 if (effectIsExit(result)) {
1112 if (result._tag === "Success") {
1113 const output = result === InternalParser.sameExit
1114 ? input
1115 : (result as InternalParser.Success<unknown, SchemaIssue.Issue>)[InternalParser.args]
1116 if (input !== InternalParser.missing && output !== InternalParser.missing) {
1117 const issues = SchemaAST.collectIssues(encodingChecks, input, undefined, ast, options)
1118 if (issues) {
1119 result = Effect.fail(new SchemaIssue.Composite(ast, issues, input, options))
1120 }
1121 }
1122 }
1123 } else {
1124 result = Effect.flatMap(result, (value) => {
1125 if (input !== InternalParser.missing && value !== InternalParser.missing) {
1126 const issues = SchemaAST.collectIssues(encodingChecks, input, undefined, ast, options)
1127 if (issues) {
1128 return Effect.fail(new SchemaIssue.Composite(ast, issues, input, options))
1129 }
1130 }
1131 return Effect.succeed(value)
1132 })
1133 }
1134 }
1135
1136 if (checks && !options.disableChecks) {
1137 if (effectIsExit(result)) {
1138 if (result._tag === "Success") {
1139 const value = result === InternalParser.sameExit
1140 ? input
1141 : (result as InternalParser.Success<unknown, SchemaIssue.Issue>)[InternalParser.args]
1142 if (value === InternalParser.missing) return result
1143 const issues = SchemaAST.collectIssues(checks, value, undefined, ast, options)
1144 if (issues) {
1145 result = Effect.fail(new SchemaIssue.Composite(ast, issues, value, options))
1146 }
1147 }
1148 } else {
1149 result = Effect.flatMap(result, (value) => {
1150 if (value !== InternalParser.missing) {
1151 const issues = SchemaAST.collectIssues(checks, value, undefined, ast, options)
1152 if (issues) {
1153 return Effect.fail(new SchemaIssue.Composite(ast, issues, value, options))
1154 }
1155 }
1156 return Effect.succeed(value)
1157 })
1158 }
1159 }
1160
1161 return result
1162 }

Callers 1

makeParserFunction · 0.85

Calls 3

effectIsExitFunction · 0.90
failMethod · 0.45
succeedMethod · 0.45

Tested by

no test coverage detected