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

Method Schema

packages/effect/src/workflow/Workflow.ts:586–630  ·  view source on GitHub ↗

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

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

Source from the content-addressed store, hash-verified

584 * @since 4.0.0
585 */
586 static Schema<Success extends Schema.Constraint, Error extends Schema.Constraint>(options: {
587 readonly success: Success
588 readonly error: Error
589 }): CompleteSchema<Success, Error> {
590 // TODO: extract to a helper function
591 const schema = Schema.declareConstructor<
592 Complete<Success["Type"], Error["Type"]>,
593 Complete<Success["Encoded"], Error["Encoded"]>
594 >()(
595 [Schema.Exit(options.success, options.error, Schema.Defect())],
596 ([exit]) => (input, ast, options) => {
597 if (!(isResult(input) && input._tag === "Complete")) {
598 return Effect.fail(new SchemaIssue.InvalidType(ast, input, options))
599 }
600 return Effect.mapBothEager(
601 SchemaParser.decodeEffect(exit)(input.exit, options),
602 {
603 onSuccess: (exit) => new Complete({ exit }),
604 onFailure: (issue) => SchemaIssue.makeCompositeAtKey(ast, "exit", issue, input, options)
605 }
606 )
607 },
608 {
609 expected: "Workflow.Complete",
610 toCodecJson: ([exit]) =>
611 Schema.link<Complete<Success["Encoded"], Error["Encoded"]>>()(
612 Schema.Struct({
613 _tag: Schema.tag("Complete"),
614 exit
615 }),
616 Tranformation.transform({
617 decode: (encoded) => new Complete({ exit: encoded.exit }),
618 encode: (result) => (({
619 _tag: "Complete",
620 exit: result.exit
621 }) as const)
622 })
623 )
624 }
625 )
626 return Schema.make(schema.ast, {
627 success: options.success,
628 error: options.error
629 })
630 }
631}
632
633/**

Callers 6

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

Calls 6

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

Tested by 1

makeAtomResultFunction · 0.64