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

Function asPromise

packages/effect/src/SchemaParser.ts:1001–1015  ·  view source on GitHub ↗
(
  parser: (input: E, options?: SchemaAST.ParseOptions) => Effect.Effect<T, SchemaIssue.Issue>
)

Source from the content-addressed store, hash-verified

999}
1000
1001function asPromise<T, E>(
1002 parser: (input: E, options?: SchemaAST.ParseOptions) => Effect.Effect<T, SchemaIssue.Issue>
1003): (input: E, options?: SchemaAST.ParseOptions) => Promise<T> {
1004 return (input: E, options?: SchemaAST.ParseOptions) =>
1005 Effect.runPromiseExit(parser(input, options)).then((exit) => {
1006 if (Exit.isSuccess(exit)) {
1007 return exit.value
1008 }
1009 const issue = InternalSchemaCause.getSchemaIssueOrThrow(
1010 exit.cause,
1011 "Promise adapter can only reject schema issues"
1012 )
1013 throw new Error("Schema validation failed", { cause: issue })
1014 })
1015}
1016
1017function asExit<T, E, R>(
1018 parser: (input: E, options?: SchemaAST.ParseOptions) => Effect.Effect<T, SchemaIssue.Issue, R>

Callers 3

decodeUnknownPromiseFunction · 0.85
decodePromiseFunction · 0.85
encodeUnknownPromiseFunction · 0.85

Calls 1

parserFunction · 0.70

Tested by

no test coverage detected