Uint8ArrayFromBase64UrlType-level representation of Uint8ArrayFromBase64Url.
export interface Uint8ArrayFromBase64Url 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<Uint8Array, String> {
readonly "Rebuild": Uint8ArrayFromBase64Url
}
/**
* Schema that decodes a base64 (URL) encoded string into a
* `Uint8Array`.
*
* **Details**
*
* Decoding:
* - A **valid** base64 (URL) encoded string is decoded as a `Uint8Array`.
*
* Encoding:
* - A `Uint8Array` is encoded as a base64 (URL) encoded string.
*
* @category Uint8Array
* @since 3.10.0
*/
export const const Uint8ArrayFromBase64Url: Uint8ArrayFromBase64Urlconst Uint8ArrayFromBase64Url: {
Rebuild: Uint8ArrayFromBase64Url;
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<globalThis.Uint8Array<ArrayBufferLike>, readonly []>) => Uint8ArrayFromBase64Url;
annotateKey: (annotations: Annotations.Key<globalThis.Uint8Array<ArrayBufferLike>>) => Uint8ArrayFromBase64Url;
check: (checks_0: SchemaAST.Check<globalThis.Uint8Array<ArrayBufferLike>>, ...checks: Array<SchemaAST.Check<globalThis.Uint8Array<ArrayBufferLike>>>) => Uint8ArrayFromBase64Url;
rebuild: (ast: SchemaAST.Declaration) => Uint8ArrayFromBase64Url;
make: (input: globalThis.Uint8Array<ArrayBufferLike>, options?: MakeOptions) => globalThis.Uint8Array<ArrayBufferLike>;
makeOption: (input: globalThis.Uint8Array<ArrayBufferLike>, options?: MakeOptions) => Option_.Option<globalThis.Uint8Array<ArrayBufferLike>>;
makeEffect: (input: globalThis.Uint8Array<ArrayBufferLike>, options?: MakeOptions) => Effect.Effect<globalThis.Uint8Array<ArrayBufferLike>, 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
Uint8ArrayFromBase64Url
.
Schema that decodes a base64 (URL) encoded string into a
Uint8Array.
Details
Decoding:
- A valid base64 (URL) encoded string is decoded as a
Uint8Array.
Encoding:
- A
Uint8Array is encoded as a base64 (URL) encoded string.
Uint8ArrayFromBase64Url: Uint8ArrayFromBase64Url = 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 base64 (URL) encoded string that will be decoded as a Uint8Array"
}).pipe(
function decodeTo<Uint8Array, Constraint, never, never>(to: Uint8Array, transformation: {
readonly decode: SchemaGetter.Getter<NoInfer<globalThis.Uint8Array<ArrayBufferLike>>, unknown, never>;
readonly encode: SchemaGetter.Getter<unknown, NoInfer<globalThis.Uint8Array<ArrayBufferLike>>, never>;
}): (from: Constraint) => decodeTo<Uint8Array, 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 Uint8Array: Uint8Arrayconst Uint8Array: {
Rebuild: Uint8Array;
Iso: Iso;
ast: Ast;
Type: T;
Encoded: E;
DecodingServices: RD;
EncodingServices: RE;
annotate: (annotations: Annotations.Bottom<globalThis.Uint8Array<ArrayBufferLike>, readonly []>) => Uint8Array;
annotateKey: (annotations: Annotations.Key<globalThis.Uint8Array<ArrayBufferLike>>) => Uint8Array;
check: (checks_0: SchemaAST.Check<globalThis.Uint8Array<ArrayBufferLike>>, ...checks: Array<SchemaAST.Check<globalThis.Uint8Array<ArrayBufferLike>>>) => Uint8Array;
rebuild: (ast: SchemaAST.Declaration) => Uint8Array;
make: (input: globalThis.Uint8Array<ArrayBufferLike>, options?: MakeOptions) => globalThis.Uint8Array<ArrayBufferLike>;
makeOption: (input: globalThis.Uint8Array<ArrayBufferLike>, options?: MakeOptions) => Option_.Option<globalThis.Uint8Array<ArrayBufferLike>>;
makeEffect: (input: globalThis.Uint8Array<ArrayBufferLike>, options?: MakeOptions) => Effect.Effect<globalThis.Uint8Array<ArrayBufferLike>, 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
Uint8Array
.
Schema for JavaScript Uint8Array objects.
Details
Default JSON serializer:
The default JSON serializer encodes Uint8Array as a Base64 encoded string.
Uint8Array, {
decode: SchemaGetter.Getter<
globalThis.Uint8Array<ArrayBufferLike>,
string,
never
>
(property) decode: {
run: (input: Option.Option<E>, options: SchemaAST.ParseOptions) => Effect.Effect<Option.Option<T>, SchemaIssue.Issue, R>;
map: (f: (t: globalThis.Uint8Array<ArrayBufferLike>) => T2) => SchemaGetter.Getter<T2, string, never>;
compose: (other: SchemaGetter.Getter<T2, globalThis.Uint8Array<ArrayBufferLike>, R2>) => SchemaGetter.Getter<T2, string, R2>;
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; <…;
}
decode: import SchemaGetterSchemaGetter.function decodeBase64Url<
E extends string
>(): Getter<Uint8Array, E>
Decodes a URL-safe Base64 string to a Uint8Array.
Details
- Fails with
SchemaIssue.InvalidValue if the input is not valid Base64Url.
Example (Decoding Base64Url to bytes)
import { SchemaGetter } from "effect"
const decode = SchemaGetter.decodeBase64Url<string>()
// Getter<Uint8Array, string>
decodeBase64Url(),
encode: SchemaGetter.Getter<
string,
NoInfer<globalThis.Uint8Array<ArrayBufferLike>>,
never
>
(property) encode: {
run: (input: Option.Option<E>, options: SchemaAST.ParseOptions) => Effect.Effect<Option.Option<T>, SchemaIssue.Issue, R>;
map: (f: (t: string) => T2) => SchemaGetter.Getter<T2, NoInfer<globalThis.Uint8Array<ArrayBufferLike>>, never>;
compose: (other: SchemaGetter.Getter<T2, string, R2>) => SchemaGetter.Getter<T2, NoInfer<globalThis.Uint8Array<ArrayBufferLike>>, R2>;
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; <…;
}
encode: import SchemaGetterSchemaGetter.function encodeBase64Url<
E extends Uint8Array | string
>(): Getter<string, E>
Encodes a Uint8Array or string to a URL-safe Base64 string.
Details
The getter is pure and never fails.
Example (Encoding to Base64Url)
import { SchemaGetter } from "effect"
const encode = SchemaGetter.encodeBase64Url<Uint8Array>()
encodeBase64Url()
})
)