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

Method getParser

packages/effect/src/SchemaAST.ts:2855–2897  ·  view source on GitHub ↗

@internal

(
    compile: SchemaParser.Compiler,
    compileConstructorDefault?: SchemaParser.Compiler
  )

Source from the content-addressed store, hash-verified

2853 }
2854 /** @internal */
2855 getParser(
2856 compile: SchemaParser.Compiler,
2857 compileConstructorDefault?: SchemaParser.Compiler
2858 ): SchemaParser.Parser {
2859 // oxlint-disable-next-line @typescript-eslint/no-this-alias
2860 const ast = this
2861
2862 return (input, options) => {
2863 if (input === InternalParser.missing) {
2864 return InternalParser.missingExit
2865 }
2866 const candidates = getCandidates(input, ast.types, compileConstructorDefault !== undefined)
2867
2868 if (candidates.length === 1) {
2869 const result = compile(candidates[0])(input, options)
2870 if ((result as Exit.Exit<unknown, SchemaIssue.Issue>)._tag === "Success") return result
2871 return effectIsExit(result)
2872 ? failSingleUnionCandidate(ast, (result as Exit.Failure<unknown, SchemaIssue.Issue>).cause, input, options)
2873 : Effect.catchCause(result, (cause) => failSingleUnionCandidate(ast, cause, input, options))
2874 }
2875
2876 const state = {
2877 ast,
2878 compile,
2879 input,
2880 out: undefined,
2881 successes: ast.mode === "oneOf" ? [] : undefined,
2882 issues: undefined as Arr.NonEmptyArray<SchemaIssue.Issue> | undefined,
2883 options
2884 }
2885 const concurrency = resolveConcurrency(options?.concurrency)
2886 const eff = parseUnion(state, candidates, concurrency ? { ...concurrency, orderedStep: true } : undefined)
2887 if (!eff) {
2888 if (state.out) return state.out
2889 return Effect.fail(new SchemaIssue.AnyOf(ast, state.issues ?? [], input, options))
2890 }
2891 return Effect.flatMapEager(eff, (_) => {
2892 if (state.out === InternalParser.sameExit) return Effect.succeed(input)
2893 if (state.out) return state.out
2894 return Effect.fail(new SchemaIssue.AnyOf(ast, state.issues ?? [], input, options))
2895 })
2896 }
2897 }
2898 private _rebuild(recur: (ast: AST) => AST, checks: Checks | undefined, encodingChecks: Checks | undefined) {
2899 const types = mapOrSame(this.types, recur)
2900 return types === this.types && checks === this.checks && encodingChecks === this.encodingChecks ?

Callers

nothing calls this directly

Calls 7

effectIsExitFunction · 0.90
getCandidatesFunction · 0.85
failSingleUnionCandidateFunction · 0.85
resolveConcurrencyFunction · 0.85
compileFunction · 0.50
failMethod · 0.45
succeedMethod · 0.45

Tested by

no test coverage detected