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

Method parse

packages/effect/src/SchemaAST.ts:2445–2489  ·  view source on GitHub ↗
(
      input: ReadonlyArray<unknown>,
      options: ParseOptions
    )

Source from the content-addressed store, hash-verified

2443 }
2444
2445 const parse = (
2446 input: ReadonlyArray<unknown>,
2447 options: ParseOptions
2448 ): Effect.Effect<unknown, SchemaIssue.Issue, any> => {
2449 const len = input.length
2450 const concurrency = options.concurrency === undefined ? 1 : resolveConcurrency(options.concurrency)
2451 const output: Array<unknown> = []
2452 const refinement = concurrency === 1 ? itemRefinement : undefined
2453 let start = 0
2454 let item: unknown
2455 if (refinement !== undefined) {
2456 // Leading items the refinement accepts are copied without a parser call
2457 while (start < len && refinement(item = input[start])) output[start++] = item
2458 if (start === len) return InternalParser.succeed(output)
2459 }
2460 const state: ArrayParserState = {
2461 ast,
2462 getParser,
2463 input,
2464 len,
2465 tailThreshold: Math.max(elementLen, len - tailLen),
2466 output,
2467 issues: undefined,
2468 options
2469 }
2470 if (refinement !== undefined) {
2471 // The rejected item goes to its parser here, so that it is read once
2472 const exit = rest![0].parser(item, options) as Exit.Exit<unknown, SchemaIssue.Issue>
2473 const terminal = stepArray(state, item, exit, start++)
2474 if (terminal) return terminal
2475 }
2476 const end = ast.rest.length === 0 ? elementLen : Math.max(len, elementLen + tailLen)
2477 const eff = concurrency === 1
2478 ? parseArray(state, input, start, end)
2479 : parseArrayConcurrent(state, input, { concurrency, end })
2480 if (!eff) return finish(state)
2481 if (effectIsExit(eff)) return Effect.flatMapEager(eff, () => finish(state))
2482 // Reparse on later runs to avoid reusing mutable traversal state.
2483 let first = true
2484 return Effect.suspend(() => {
2485 if (!first) return parse(input, options)
2486 first = false
2487 return Effect.flatMap(eff, () => finish(state))
2488 })
2489 }
2490
2491 return (input, options) => {
2492 if (input === InternalParser.missing) return InternalParser.missingExit

Callers 15

formatFunction · 0.45
Plugin.test.tsFile · 0.45
OpenApiPatch.tsFile · 0.45
githubClientFunction · 0.45
packagesAtBumpFunction · 0.45
Generator.test.tsFile · 0.45
parseSpecFunction · 0.45
Discovery.tsFile · 0.45
readPackageMetadataFunction · 0.45
loadJSDocConfigFunction · 0.45

Calls 7

effectIsExitFunction · 0.90
refinementFunction · 0.85
stepArrayFunction · 0.85
finishFunction · 0.70
parseFunction · 0.70
succeedMethod · 0.45
parserMethod · 0.45

Tested by 15

githubClientFunction · 0.36
githubFunction · 0.36
capturedFunction · 0.36
pairsOfFunction · 0.36
checkFunction · 0.36
bodyJsonFunction · 0.36
sendMethod · 0.36
bodyJsonFunction · 0.36
requestBodyFunction · 0.36
invokeFunction · 0.36