<S extends Schema.Constraint>(schema: S): (
input: S["~type.make.in"],
options?: Schema.MakeOptions
) => S["Type"]Creates a synchronous maker for the schema's decoded type side.
When to use
Use to construct decoded schema values synchronously when invalid input
should throw an Error whose cause is SchemaIssue.Issue.
Details
The returned function constructs a value from constructor input and throws an
Error with the SchemaIssue.Issue in its cause when construction fails.
Gotchas
Causes that contain defects, interruptions, or asynchronous work at this
synchronous boundary throw an Error whose cause is the underlying Cause,
instead of being converted to a schema validation error.
export function function make<
S extends Schema.Constraint
>(
schema: S
): (
input: S["~type.make.in"],
options?: Schema.MakeOptions
) => S["Type"]
Creates a synchronous maker for the schema's decoded type side.
When to use
Use to construct decoded schema values synchronously when invalid input
should throw an Error whose cause is SchemaIssue.Issue.
Details
The returned function constructs a value from constructor input and throws an
Error with the SchemaIssue.Issue in its cause when construction fails.
Gotchas
Causes that contain defects, interruptions, or asynchronous work at this
synchronous boundary throw an Error whose cause is the underlying Cause,
instead of being converted to a schema validation error.
make<function (type parameter) S in make<S extends Schema.Constraint>(schema: S): (input: S["~type.make.in"], options?: Schema.MakeOptions) => S["Type"]S extends import SchemaSchema.Constraint>(schema: S extends Schema.Constraintschema: function (type parameter) S in make<S extends Schema.Constraint>(schema: S): (input: S["~type.make.in"], options?: Schema.MakeOptions) => S["Type"]S) {
const const parser: (
input: S["~type.make.in"],
options?: Schema.MakeOptions
) => Effect.Effect<
S["Type"],
SchemaIssue.Issue,
never
>
parser = function makeEffect<
S extends Schema.Constraint
>(
schema: S
): (
input: S["~type.make.in"],
options?: Schema.MakeOptions
) => Effect.Effect<S["Type"], SchemaIssue.Issue>
Creates an effectful maker for the schema's decoded type side.
When to use
Use to construct decoded schema values in Effect while preserving
construction failures as SchemaIssue.Issue values in the error channel.
Details
The returned function accepts constructor input, applies constructor defaults,
runs type-side validation unless checks are disabled, and fails with a
SchemaIssue.Issue when construction fails.
makeEffect(schema: S extends Schema.Constraintschema)
return (input: S["~type.make.in"]input: function (type parameter) S in make<S extends Schema.Constraint>(schema: S): (input: S["~type.make.in"], options?: Schema.MakeOptions) => S["Type"]S["~type.make.in"], options: Schema.MakeOptionsoptions?: import SchemaSchema.MakeOptions): function (type parameter) S in make<S extends Schema.Constraint>(schema: S): (input: S["~type.make.in"], options?: Schema.MakeOptions) => S["Type"]S["Type"] => {
const const exit: Exit.Exit<
S["Type"],
SchemaIssue.Issue
>
exit = import EffectEffect.const runSyncExit: <A, E>(
effect: Effect<A, E>
) => Exit.Exit<A, E>
Runs an effect synchronously and captures the outcome safely as an Exit type, which
represents the outcome (success or failure) of the effect.
When to use
Use to find out whether an effect succeeded or failed,
including any defects, without dealing with asynchronous operations.
Details
The Exit type represents the result of the effect. Successful effects are
wrapped in Success, and failed effects are wrapped in Failure with a
Cause.
If the effect contains asynchronous operations, runSyncExit will
return an Failure with a Die cause, indicating that the effect cannot be
resolved synchronously.
Example (Observing synchronous results as Exit)
import { Effect } from "effect"
console.log(Effect.runSyncExit(Effect.succeed(1)))
// Output:
// {
// _id: "Exit",
// _tag: "Success",
// value: 1
// }
console.log(Effect.runSyncExit(Effect.fail("my error")))
// Output:
// {
// _id: "Exit",
// _tag: "Failure",
// cause: {
// _id: "Cause",
// _tag: "Fail",
// failure: "my error"
// }
// }
Example (Capturing async work as a Die cause)
import { Effect } from "effect"
console.log(Effect.runSyncExit(Effect.promise(() => Promise.resolve(1))))
// Output:
// {
// _id: 'Exit',
// _tag: 'Failure',
// cause: {
// _id: 'Cause',
// _tag: 'Die',
// defect: [Fiber #0 cannot be resolved synchronously. This is caused by using runSync on an effect that performs async work] {
// fiber: [FiberRuntime],
// _tag: 'AsyncFiberException',
// name: 'AsyncFiberException'
// }
// }
// }
runSyncExit(const parser: (
input: S["~type.make.in"],
options?: Schema.MakeOptions
) => Effect.Effect<
S["Type"],
SchemaIssue.Issue,
never
>
parser(input: S["~type.make.in"]input, options: Schema.MakeOptionsoptions))
if (import ExitExit.const isSuccess: <A, E>(
self: Exit<A, E>
) => self is Success<A, E>
Checks whether an Exit is a Success.
When to use
Use as a type guard to narrow Exit<A, E> to Success<A, E> and access the
value property.
Example (Narrowing to success)
import { Exit } from "effect"
const exit = Exit.succeed(42)
if (Exit.isSuccess(exit)) {
console.log(exit.value) // 42
}
isSuccess(const exit: Exit.Exit<
S["Type"],
SchemaIssue.Issue
>
exit)) {
return const exit: Exit.Success<
S["Type"],
SchemaIssue.Issue
>
const exit: {
_tag: "Success";
value: A;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
toString: () => string;
toJSON: () => unknown;
}
exit.Success<S["Type"], Issue>.value: S["Type"]value
}
const const issue: SchemaIssue.Issueissue = import InternalSchemaCauseInternalSchemaCause.function getSchemaIssueOrThrow(
cause: Cause.Cause<SchemaIssue.Issue>,
message: string
): SchemaIssue.Issue
getSchemaIssueOrThrow(
const exit: Exit.Failure<
S["Type"],
SchemaIssue.Issue
>
const exit: {
_tag: "Failure";
cause: Cause.Cause<E>;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
toString: () => string;
toJSON: () => unknown;
}
exit.Failure<S["Type"], Issue>.cause: Cause.Cause<E>(property) Failure<S["Type"], Issue>.cause: {
reasons: ReadonlyArray<Reason<E>>;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
toString: () => string;
toJSON: () => unknown;
}
cause,
"Constructor adapter can only throw schema issues"
)
throw new var Error: ErrorConstructor
new (message?: string, options?: ErrorOptions) => Error (+1 overload)
Error(const issue: SchemaIssue.Issueissue.Base.toString(this: Issue): stringtoString(), { ErrorOptions.cause?: SchemaIssue.Issuecause: const issue: SchemaIssue.Issueissue })
}
}