(entry: LogEntry): Effect.Effect<string, Schema.SchemaError>export const const encodeLogEntryNdjson: (
entry: LogEntry
) => Effect.Effect<string, Schema.SchemaError>
encodeLogEntryNdjson = (
entry: LogEntry(parameter) entry: {
date: string;
level: LogLevel;
message: string;
cause: string;
annotations: Readonly<Record<string, string>>;
spans: ReadonlyArray<string>;
}
entry: LogEntry,
): import EffectEffect.interface Effect<out A, out E = never, out R = never>The Effect interface defines a value that lazily describes a workflow or
job. The workflow requires some context R, and may fail with an error of
type E, or succeed with a value of type A.
When to use
Use when you need to represent a lazy, composable workflow that can require
services, fail with a typed error, or succeed with a typed value.
Details
Effect values model resourceful interaction with the outside world,
including synchronous, asynchronous, concurrent, and parallel interaction.
They use a fiber-based concurrency model, with built-in support for
scheduling, fine-grained interruption, structured concurrency, and high
scalability.
To run an Effect value, you need a Runtime, which is a type that is
capable of executing Effect values.
Effect<string, import SchemaSchema.class SchemaError
export SchemaError
class SchemaError {
message: string;
toString: () => string;
name: string;
stack: string;
cause: unknown;
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; <…;
toJSON: () => unknown;
_tag: Tag;
issue: Issue;
}
Error thrown (or returned as the error channel value) when schema decoding
or encoding fails.
Details
The issue field contains a structured
SchemaIssue.Issue
tree describing
every validation failure, including the path to the problematic value,
expected types, and actual values received. message renders the issue tree
as a human-readable string.
Use
isSchemaError
to narrow an unknown value to SchemaError.
Example (Catching a SchemaError)
import { Schema } from "effect"
try {
Schema.decodeUnknownSync(Schema.Number)("not a number")
} catch (err) {
if (Schema.isSchemaError(err)) {
console.log(err.message)
// Expected number, actual "not a number"
}
}
SchemaError> =>
import SchemaSchema.const encodeEffect: <Schema.fromJsonString<Schema.Struct<{
readonly date: Schema.String;
readonly level: Schema.Literals<readonly ["All", "Fatal", "Error", "Warn", "Info", "Debug", "Trace", "None"]>;
readonly message: Schema.String;
readonly cause: Schema.optional<Schema.String>;
readonly annotations: Schema.$Record<Schema.String, Schema.String>;
readonly spans: Schema.$Array<Schema.String>;
}>>>(schema: Schema.fromJsonString<Schema.Struct<{
readonly date: Schema.String;
readonly level: Schema.Literals<readonly ["All", "Fatal", "Error", "Warn", "Info", "Debug", "Trace", "None"]>;
readonly message: Schema.String;
readonly cause: Schema.optional<Schema.String>;
readonly annotations: Schema.$Record<Schema.String, Schema.String>;
readonly spans: Schema.$Array<Schema.String>;
}>>, options?: ParseOptions) => (input: {
...;
}, options?: ParseOptions) => Effect.Effect<...>
Encodes a typed input (the schema's Type) against a schema, returning an
Effect that succeeds with the encoded value or fails with a
SchemaError
.
When to use
Use when you need to encode input already typed as the schema's Type in
an Effect whose failure channel is SchemaError.
Details
For unknown input use
encodeUnknownEffect
.
Options may be provided either when creating the encoder or when applying it;
application options override creation options.
encodeEffect(const LogEntryNdjson: Schema.fromJsonString<
Schema.Struct<{
readonly date: Schema.String
readonly level: Schema.Literals<
readonly [
"All",
"Fatal",
"Error",
"Warn",
"Info",
"Debug",
"Trace",
"None"
]
>
readonly message: Schema.String
readonly cause: Schema.optional<Schema.String>
readonly annotations: Schema.$Record<
Schema.String,
Schema.String
>
readonly spans: Schema.$Array<Schema.String>
}>
>
const LogEntryNdjson: {
Rebuild: fromJsonString<S>;
Type: To["Type"];
Encoded: From["Encoded"];
DecodingServices: To["DecodingServices"] | From["DecodingServices"] | RD;
EncodingServices: To["EncodingServices"] | From["EncodingServices"] | RE;
Iso: To["Iso"];
from: From;
to: To;
ast: Ast;
annotate: (annotations: Schema.Annotations.Bottom<{ readonly annotations: { readonly [x: string]: string; }; readonly spans: ReadonlyArray<string>; readonly date: string; readonly level: 'All' | 'Fatal' | 'Error' | 'Warn' | 'Info' | 'Debug' | 'Trace…;
annotateKey: (annotations: Schema.Annotations.Key<{ readonly annotations: { readonly [x: string]: string }; readonly spans: ReadonlyArray<string>; readonly date: string; readonly level: 'All' | 'Fatal' | 'Error' | 'Warn' | 'Info' | 'Debug' | 'Trace' | …;
check: (checks_0: Check<{ readonly annotations: { readonly [x: string]: string }; readonly spans: ReadonlyArray<string>; readonly date: string; readonly level: 'All' | 'Fatal' | 'Error' | 'Warn' | 'Info' | 'Debug' | 'Trace' | 'None'; readonly mes…;
rebuild: (ast: Objects) => Schema.fromJsonString<Schema.Struct<{ readonly date: Schema.String; readonly level: Schema.Literals<readonly ['All', 'Fatal', 'Error', 'Warn', 'Info', 'Debug', 'Trace', 'None']>; readonly message: Schema.String; readonly …;
make: (input: { readonly annotations: { readonly [x: string]: string }; readonly spans: ReadonlyArray<string>; readonly date: string; readonly level: 'All' | 'Fatal' | 'Error' | 'Warn' | 'Info' | 'Debug' | 'Trace' | 'None'; readonly message: str…;
makeOption: (input: { readonly annotations: { readonly [x: string]: string }; readonly spans: ReadonlyArray<string>; readonly date: string; readonly level: 'All' | 'Fatal' | 'Error' | 'Warn' | 'Info' | 'Debug' | 'Trace' | 'None'; readonly message: str…;
makeEffect: (input: { readonly annotations: { readonly [x: string]: string }; readonly spans: ReadonlyArray<string>; readonly date: string; readonly level: 'All' | 'Fatal' | 'Error' | 'Warn' | 'Info' | 'Debug' | 'Trace' | 'None'; readonly message: str…;
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; <…;
}
LogEntryNdjson)(entry: LogEntry(parameter) entry: {
date: string;
level: LogLevel;
message: string;
cause: string;
annotations: Readonly<Record<string, string>>;
spans: ReadonlyArray<string>;
}
entry);