( ast: SchemaAST.AST, compile: Compiler, compileConstructorDefault?: Compiler, constructorDefault?: SchemaAST.Link )
| 1079 | } |
| 1080 | |
| 1081 | function makeParser( |
| 1082 | ast: SchemaAST.AST, |
| 1083 | compile: Compiler, |
| 1084 | compileConstructorDefault?: Compiler, |
| 1085 | constructorDefault?: SchemaAST.Link |
| 1086 | ): Parser { |
| 1087 | const descriptor = compileConstructorDefault ? SchemaAST.getConstructorDescriptor(ast) : undefined |
| 1088 | const parser = descriptor |
| 1089 | ? makeConstructorParser(descriptor, compile) |
| 1090 | : ast.getParser(compile, compileConstructorDefault) |
| 1091 | const checks = ast.checks |
| 1092 | const links = constructorDefault |
| 1093 | ? ast.encoding ? [...ast.encoding, constructorDefault] : [constructorDefault] |
| 1094 | : ast.encoding |
| 1095 | const encodingChecks = (ast as any).encodingChecks |
| 1096 | const astOptions = (checks ? checks[checks.length - 1].annotations : ast.annotations) |
| 1097 | ?.["parseOptions"] |
| 1098 | if (!links && !checks && !encodingChecks) { |
| 1099 | if (!astOptions) { |
| 1100 | return parser |
| 1101 | } |
| 1102 | return (input, options) => parser(input, mergeParseOptions(options, astOptions)) |
| 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") { |
no test coverage detected