DateTimeUtcFromStringType-level representation of DateTimeUtcFromString.
export interface DateTimeUtcFromString extends interface decodeTo<To extends Constraint, From extends Constraint, RD = never, RE = never>Creates a schema that transforms from a source schema to a target schema.
When to use
Use when decoding should change the schema's decoded type or encoded shape,
with an optional custom bidirectional transformation.
Details
Call it with the target schema to and then pipe the source schema from
into the returned function. The resulting schema decodes from
From["Encoded"] to To["Type"] and encodes from To["Type"] back to
From["Encoded"].
When no transformation is provided, SchemaTransformation.passthrough() is
used, so From["Type"] must already be compatible with To["Encoded"].
The resulting schema combines decoding and encoding services from both
schemas and any custom transformation.
Gotchas
In a custom transformation, decode maps From["Type"] to To["Encoded"]
and is used on the encoding path, while encode maps To["Encoded"] to
From["Type"] and is used on the decoding path.
Example (Transforming strings to numbers with a schema transformation)
import { Schema, SchemaGetter } from "effect"
const NumberFromString = Schema.String.pipe(
Schema.decodeTo(
Schema.Number,
{
decode: SchemaGetter.transform((s) => Number(s)),
encode: SchemaGetter.transform((n) => String(n))
}
)
)
const result = Schema.decodeUnknownSync(NumberFromString)("123")
// result: 123
Type-level representation returned by
decodeTo
.
decodeTo<DateTimeUtc, String> {
readonly "Rebuild": DateTimeUtcFromString
}
/**
* Schema that decodes a date-time string into a `DateTime.Utc`.
*
* **Details**
*
* Decoding:
*
* - A string accepted by `DateTime.make` is parsed and normalized to UTC. Strings
* without an explicit zone are interpreted as UTC.
*
* Encoding:
*
* - A `DateTime.Utc` is encoded as a UTC ISO 8601 string.
*
* @see {@link DateTimeUtcFromDate} for decoding JavaScript Date values into UTC values
* @see {@link DateTimeUtcFromMillis} for decoding epoch milliseconds into UTC values
* @see {@link DateFromString} for decoding strings into JavaScript Date instances
*
* @category DateTime
* @since 4.0.0
*/
export const const DateTimeUtcFromString: DateTimeUtcFromStringconst DateTimeUtcFromString: {
Rebuild: DateTimeUtcFromString;
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: Annotations.Bottom<DateTime.Utc, readonly []>) => DateTimeUtcFromString;
annotateKey: (annotations: Annotations.Key<DateTime.Utc>) => DateTimeUtcFromString;
check: (checks_0: SchemaAST.Check<DateTime.Utc>, ...checks: Array<SchemaAST.Check<DateTime.Utc>>) => DateTimeUtcFromString;
rebuild: (ast: SchemaAST.Declaration) => DateTimeUtcFromString;
make: (input: DateTime.Utc, options?: MakeOptions) => DateTime.Utc;
makeOption: (input: DateTime.Utc, options?: MakeOptions) => Option_.Option<DateTime.Utc>;
makeEffect: (input: DateTime.Utc, options?: MakeOptions) => Effect.Effect<DateTime.Utc, SchemaError, never>;
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; <…;
}
Type-level representation of
DateTimeUtcFromString
.
Schema that decodes a date-time string into a DateTime.Utc.
Details
Decoding:
- A string accepted by
DateTime.make is parsed and normalized to UTC. Strings
without an explicit zone are interpreted as UTC.
Encoding:
- A
DateTime.Utc is encoded as a UTC ISO 8601 string.
DateTimeUtcFromString: DateTimeUtcFromString = const String: Stringconst String: {
Rebuild: Rebuild;
Iso: Iso;
ast: Ast;
Type: T;
Encoded: E;
DecodingServices: RD;
EncodingServices: RE;
annotate: (annotations: Annotations.Bottom<string, readonly []>) => String;
annotateKey: (annotations: Annotations.Key<string>) => String;
check: (checks_0: SchemaAST.Check<string>, ...checks: Array<SchemaAST.Check<string>>) => String;
rebuild: (ast: SchemaAST.String) => String;
make: (input: string, options?: MakeOptions) => string;
makeOption: (input: string, options?: MakeOptions) => Option_.Option<string>;
makeEffect: (input: string, options?: MakeOptions) => Effect.Effect<string, SchemaError, never>;
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; <…;
}
Type-level representation of
String
.
Schema for string values. Validates that the input is typeof "string".
String.Bottom<string, string, never, never, String, String, string, string, readonly [], string, "readonly", "required", "no-default", "readonly", "required">.annotate(annotations: Annotations.Bottom<string, readonly []>): Stringannotate({
Annotations.Augment.expected?: string | undefinedHuman-readable description of what a value is expected to satisfy.
Details
For filter and refinement failures, the default formatter uses
message first, then expected, and finally falls back to <filter>.
Use this to name a failed filter in the default message:
Expected <expected>, got <actual>.
expected: "a string that will be decoded as a DateTime.Utc"
}).pipe(
function decodeTo<DateTimeUtc, Constraint, never, never>(to: DateTimeUtc, transformation: {
readonly decode: SchemaGetter.Getter<DateTime.Utc, unknown, never>;
readonly encode: SchemaGetter.Getter<unknown, DateTime.Utc, never>;
}): (from: Constraint) => decodeTo<DateTimeUtc, Constraint, never, never> (+1 overload)
Creates a schema that transforms from a source schema to a target schema.
When to use
Use when decoding should change the schema's decoded type or encoded shape,
with an optional custom bidirectional transformation.
Details
Call it with the target schema to and then pipe the source schema from
into the returned function. The resulting schema decodes from
From["Encoded"] to To["Type"] and encodes from To["Type"] back to
From["Encoded"].
When no transformation is provided, SchemaTransformation.passthrough() is
used, so From["Type"] must already be compatible with To["Encoded"].
The resulting schema combines decoding and encoding services from both
schemas and any custom transformation.
Gotchas
In a custom transformation, decode maps From["Type"] to To["Encoded"]
and is used on the encoding path, while encode maps To["Encoded"] to
From["Type"] and is used on the decoding path.
Example (Transforming strings to numbers with a schema transformation)
import { Schema, SchemaGetter } from "effect"
const NumberFromString = Schema.String.pipe(
Schema.decodeTo(
Schema.Number,
{
decode: SchemaGetter.transform((s) => Number(s)),
encode: SchemaGetter.transform((n) => String(n))
}
)
)
const result = Schema.decodeUnknownSync(NumberFromString)("123")
// result: 123
decodeTo(
const DateTimeUtc: DateTimeUtcconst DateTimeUtc: {
Rebuild: DateTimeUtc;
Iso: Iso;
ast: Ast;
Type: T;
Encoded: E;
DecodingServices: RD;
EncodingServices: RE;
annotate: (annotations: Annotations.Bottom<DateTime.Utc, readonly []>) => DateTimeUtc;
annotateKey: (annotations: Annotations.Key<DateTime.Utc>) => DateTimeUtc;
check: (checks_0: SchemaAST.Check<DateTime.Utc>, ...checks: Array<SchemaAST.Check<DateTime.Utc>>) => DateTimeUtc;
rebuild: (ast: SchemaAST.Declaration) => DateTimeUtc;
make: (input: DateTime.Utc, options?: MakeOptions) => DateTime.Utc;
makeOption: (input: DateTime.Utc, options?: MakeOptions) => Option_.Option<DateTime.Utc>;
makeEffect: (input: DateTime.Utc, options?: MakeOptions) => Effect.Effect<DateTime.Utc, SchemaError, never>;
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; <…;
}
Type-level representation of
DateTimeUtc
.
Schema for DateTime.Utc values.
When to use
Use to validate existing DateTime.Utc schema values and use the default JSON
codec that represents them as UTC ISO strings.
Details
The default JSON codec decodes UTC ISO strings into DateTime.Utc values and
encodes DateTime.Utc values as UTC ISO strings.
DateTimeUtc,
import SchemaTransformationSchemaTransformation.const dateTimeUtcFromString: Transformation<
DateTime.Utc,
string
>
const dateTimeUtcFromString: {
_tag: 'Transformation';
decode: SchemaGetter.Getter<T, E, RD>;
encode: SchemaGetter.Getter<E, T, RE>;
flip: () => SchemaTransformation.Transformation<string, DateTime.Utc, never, never>;
compose: (other: SchemaTransformation.Transformation<T2, DateTime.Utc, RD2, RE2>) => SchemaTransformation.Transformation<T2, string, RD2, RE2>;
}
Decodes a date-time string into a DateTime.Utc and encodes it back to an ISO
string.
When to use
Use when you need a schema transformation to decode date-time strings to a
normalized DateTime.Utc and encode back as a UTC ISO string.
Details
Decode accepts strings supported by DateTime.make, converts the result to
UTC, and fails with InvalidValue when parsing fails. Encode uses
DateTime.formatIso.
dateTimeUtcFromString
)
)