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

Method Schema

packages/effect/src/unstable/workflow/Workflow.ts:548–592  ·  view source on GitHub ↗

* Builds the schema for completed workflow results from success and error schemas. * * @since 4.0.0

(options: {
    readonly success: Success
    readonly error: Error
  })

Source from the content-addressed store, hash-verified

546 * @since 4.0.0
547 */
548 static Schema<Success extends Schema.Constraint, Error extends Schema.Constraint>(options: {
549 readonly success: Success
550 readonly error: Error
551 }): CompleteSchema<Success, Error> {
552 // TODO: extract to a helper function
553 const schema = Schema.declareConstructor<
554 Complete<Success["Type"], Error["Type"]>,
555 Complete<Success["Encoded"], Error["Encoded"]>
556 >()(
557 [Schema.Exit(options.success, options.error, Schema.Defect())],
558 ([exit]) => (input, ast, options) => {
559 if (!(isResult(input) && input._tag === "Complete")) {
560 return Effect.fail(new SchemaIssue.InvalidType(ast, input, options))
561 }
562 return Effect.mapBothEager(
563 SchemaParser.decodeEffect(exit)(input.exit, options),
564 {
565 onSuccess: (exit) => new Complete({ exit }),
566 onFailure: (issue) => SchemaIssue.makeCompositeAtKey(ast, "exit", issue, input, options)
567 }
568 )
569 },
570 {
571 expected: "Workflow.Complete",
572 toCodecJson: ([exit]) =>
573 Schema.link<Complete<Success["Encoded"], Error["Encoded"]>>()(
574 Schema.Struct({
575 _tag: Schema.tag("Complete"),
576 exit
577 }),
578 Tranformation.transform({
579 decode: (encoded) => new Complete({ exit: encoded.exit }),
580 encode: (result) => (({
581 _tag: "Complete",
582 exit: result.exit
583 }) as const)
584 })
585 )
586 }
587 )
588 return Schema.make(schema.ast, {
589 success: options.success,
590 error: options.error
591 })
592 }
593}
594
595/**

Callers 5

makeAtomResultFunction · 0.80
index.test.tsxFile · 0.80
ServiceFunction · 0.80
ServiceFunction · 0.80
ResultFunction · 0.80

Calls 5

isResultFunction · 0.70
tagMethod · 0.65
transformMethod · 0.65
makeMethod · 0.65
failMethod · 0.45

Tested by 1

makeAtomResultFunction · 0.64