<S extends Top>(
annotations: Annotations.Bottom<S["Encoded"], readonly []>
): (self: S) => S["Rebuild"]Adds metadata annotations to the encoded side of a schema without
changing its runtime behavior. This is the encoded-side counterpart of
annotate, which targets the decoded (Type) side.
Details
Internally the schema is flipped so that Encoded becomes Type,
annotated, and then flipped back.
Example (Adding a title to the encoded representation)
import { Schema } from "effect"
const schema = Schema.NumberFromString.pipe(
Schema.annotateEncoded({
title: "my title"
})
)
console.log(Schema.toEncoded(schema).ast.annotations?.title)
// "my title"export function function annotateEncoded<S extends Top>(
annotations: Annotations.Bottom<
S["Encoded"],
readonly []
>
): (self: S) => S["Rebuild"]
Adds metadata annotations to the encoded side of a schema without
changing its runtime behavior. This is the encoded-side counterpart of
annotate, which targets the decoded (Type) side.
Details
Internally the schema is flipped so that Encoded becomes Type,
annotated, and then flipped back.
Example (Adding a title to the encoded representation)
import { Schema } from "effect"
const schema = Schema.NumberFromString.pipe(
Schema.annotateEncoded({
title: "my title"
})
)
console.log(Schema.toEncoded(schema).ast.annotations?.title)
// "my title"
annotateEncoded<function (type parameter) S in annotateEncoded<S extends Top>(annotations: Annotations.Bottom<S["Encoded"], readonly []>): (self: S) => S["Rebuild"]S extends Top>(annotations: Annotations.Bottom<
S["Encoded"],
readonly []
>
(parameter) annotations: {
message: string | undefined;
messageUnexpectedKey: string | undefined;
identifier: string | undefined;
parseOptions: SchemaAST.ParseOptions | undefined;
meta: Meta | undefined;
brands: ReadonlyArray<string> | undefined;
toArbitrary: ToArbitrary.Declaration<T, TypeParameters> | undefined;
default: T | undefined;
examples: ReadonlyArray<T> | undefined;
expected: string | undefined;
title: string | undefined;
description: string | undefined;
documentation: string | undefined;
readOnly: boolean | undefined;
writeOnly: boolean | undefined;
format: string | undefined;
contentEncoding: string | undefined;
contentMediaType: string | undefined;
}
annotations: Annotations.interface Annotations.Bottom<T, TypeParameters extends ReadonlyArray<Constraint>>Base annotations shared by all composite schema nodes. Extends
Documentation
with error messages, branding, parse options, and
arbitrary generation hooks.
Declaration
and other annotation
interfaces build on top of this.
Bottom<function (type parameter) S in annotateEncoded<S extends Top>(annotations: Annotations.Bottom<S["Encoded"], readonly []>): (self: S) => S["Rebuild"]S["Encoded"], readonly []>) {
return (self: S extends Topself: function (type parameter) S in annotateEncoded<S extends Top>(annotations: Annotations.Bottom<S["Encoded"], readonly []>): (self: S) => S["Rebuild"]S): function (type parameter) S in annotateEncoded<S extends Top>(annotations: Annotations.Bottom<S["Encoded"], readonly []>): (self: S) => S["Rebuild"]S["Rebuild"] => function flip<S extends Top>(
schema: S
): S extends flip<infer F>
? F["Rebuild"]
: flip<S>
Swaps the decoded and encoded sides of a schema.
When to use
Use to invert a schema transformation direction.
Details
Calling flip twice returns the original schema.
Example (Flipping a number-from-string schema)
import { Schema } from "effect"
// NumberFromString: decodes string → number
const flipped = Schema.flip(Schema.NumberFromString)
// flipped: decodes number → string
flip(function flip<S extends Top>(
schema: S
): S extends flip<infer F>
? F["Rebuild"]
: flip<S>
Swaps the decoded and encoded sides of a schema.
When to use
Use to invert a schema transformation direction.
Details
Calling flip twice returns the original schema.
Example (Flipping a number-from-string schema)
import { Schema } from "effect"
// NumberFromString: decodes string → number
const flipped = Schema.flip(Schema.NumberFromString)
// flipped: decodes number → string
flip(self: S extends Topself).Bottom<out T, out E, out RD, out RE, out Ast extends SchemaAST.AST, out Rebuild extends Top, out TypeMakeIn = T, out Iso = T, in out TypeParameters extends ReadonlyArray<Constraint> = readonly [], out TypeMake = TypeMakeIn, out TypeMutability extends Mutability = "readonly", out TypeOptionality extends Optionality = "required", out TypeConstructorDefault extends ConstructorDefault = "no-default", out EncodedMutability extends Mutability = "readonly", out EncodedOptionality extends Optionality = "required">.annotate(annotations: Annotations.Bottom<unknown, any>): Topannotate(annotations: Annotations.Bottom<
S["Encoded"],
readonly []
>
(parameter) annotations: {
message: string | undefined;
messageUnexpectedKey: string | undefined;
identifier: string | undefined;
parseOptions: SchemaAST.ParseOptions | undefined;
meta: Meta | undefined;
brands: ReadonlyArray<string> | undefined;
toArbitrary: ToArbitrary.Declaration<T, TypeParameters> | undefined;
default: T | undefined;
examples: ReadonlyArray<T> | undefined;
expected: string | undefined;
title: string | undefined;
description: string | undefined;
documentation: string | undefined;
readOnly: boolean | undefined;
writeOnly: boolean | undefined;
format: string | undefined;
contentEncoding: string | undefined;
contentMediaType: string | undefined;
}
annotations))
}