BigIntFromStringType-level representation of BigIntFromString.
export interface BigIntFromString 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<BigInt, String> {
readonly "Rebuild": BigIntFromString
}
/**
* Schema that parses a string into a `bigint`.
*
* **When to use**
*
* Use to parse signed base-10 integer strings into bigint values while encoding
* bigint values back to decimal strings.
*
* **Details**
*
* Decoding:
* - A `string` is decoded as a `bigint`.
*
* Encoding:
* - A `bigint` is encoded as a `string`.
*
* **Gotchas**
*
* Decoding accepts only strings matching `^-?\d+$`.
*
* @see {@link isStringBigInt} for the string predicate used by this schema
* @see {@link BigInt} for validating values that are already bigint values
* @see {@link NumberFromString} for parsing JavaScript number strings, including non-finite values
* @see {@link BigDecimalFromString} for parsing decimal number strings
*
* @category BigInt
* @since 4.0.0
*/
export const const BigIntFromString: BigIntFromStringconst BigIntFromString: {
Rebuild: BigIntFromString;
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<bigint, readonly []>) => BigIntFromString;
annotateKey: (annotations: Annotations.Key<bigint>) => BigIntFromString;
check: (checks_0: SchemaAST.Check<bigint>, ...checks: Array<SchemaAST.Check<bigint>>) => BigIntFromString;
rebuild: (ast: SchemaAST.BigInt) => BigIntFromString;
make: (input: bigint, options?: MakeOptions) => bigint;
makeOption: (input: bigint, options?: MakeOptions) => Option_.Option<bigint>;
makeEffect: (input: bigint, options?: MakeOptions) => Effect.Effect<bigint, 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
BigIntFromString
.
Schema that parses a string into a bigint.
When to use
Use to parse signed base-10 integer strings into bigint values while encoding
bigint values back to decimal strings.
Details
Decoding:
- A
string is decoded as a bigint.
Encoding:
- A
bigint is encoded as a string.
Gotchas
Decoding accepts only strings matching ^-?\d+$.
BigIntFromString: BigIntFromString = const make: <S extends Constraint>(
ast: S["ast"],
options?: object
) => S
Creates a schema from an AST (Abstract Syntax Tree) node.
Details
This is the fundamental constructor for all schemas in the Effect Schema
library. It takes an AST node and wraps it in a fully-typed schema that
preserves all type information and provides the complete schema API.
The make function is used internally to create all primitive schemas like
String, Number, Boolean, etc., as well as more complex schemas. It's
the bridge between the untyped AST representation and the strongly-typed
schema.
make<String>(import SchemaASTSchemaAST.const bigIntString: SchemaAST.Stringconst bigIntString: {
_tag: 'String';
getParser: () => SchemaParser.Parser;
matchPart: (s: string, options: ParseOptions) => string | undefined;
getExpected: () => string;
annotations: Schema.Annotations.Annotations | undefined;
checks: Checks | undefined;
encoding: Encoding | undefined;
context: Context | undefined;
toString: () => string;
}
bigIntString).pipe(
function decodeTo<BigInt, Constraint, never, never>(to: BigInt, transformation: {
readonly decode: SchemaGetter.Getter<bigint, unknown, never>;
readonly encode: SchemaGetter.Getter<unknown, bigint, never>;
}): (from: Constraint) => decodeTo<BigInt, 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 BigInt: BigIntconst BigInt: {
Rebuild: Rebuild;
Iso: Iso;
ast: Ast;
Type: T;
Encoded: E;
DecodingServices: RD;
EncodingServices: RE;
annotate: (annotations: Annotations.Bottom<bigint, readonly []>) => BigInt;
annotateKey: (annotations: Annotations.Key<bigint>) => BigInt;
check: (checks_0: SchemaAST.Check<bigint>, ...checks: Array<SchemaAST.Check<bigint>>) => BigInt;
rebuild: (ast: SchemaAST.BigInt) => BigInt;
make: (input: bigint, options?: MakeOptions) => bigint;
makeOption: (input: bigint, options?: MakeOptions) => Option_.Option<bigint>;
makeEffect: (input: bigint, options?: MakeOptions) => Effect.Effect<bigint, 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
BigInt
.
Schema for bigint values. Validates that the input is typeof "bigint".
When to use
Use when the input is already a bigint and the schema should validate and
preserve bigint values without parsing from another representation.
BigInt, import SchemaTransformationSchemaTransformation.const bigintFromString: SchemaTransformation.Transformation<
bigint,
string,
never,
never
>
const bigintFromString: {
_tag: 'Transformation';
decode: SchemaGetter.Getter<T, E, RD>;
encode: SchemaGetter.Getter<E, T, RE>;
flip: () => SchemaTransformation.Transformation<string, bigint, never, never>;
compose: (other: SchemaTransformation.Transformation<T2, bigint, RD2, RE2>) => SchemaTransformation.Transformation<T2, string, RD2, RE2>;
}
Decodes a string into a bigint and encodes a bigint back to a
string.
When to use
Use when you need a schema transformation to parse large integer strings
(e.g. database IDs, blockchain values).
Details
Decoding coerces the string to a bigint like BigInt(s). Encoding coerces
the bigint to a string like String(n). Decoding fails if the string is not
a valid bigint representation.
Example (Converting a string to a BigInt)
import { Schema, SchemaTransformation } from "effect"
const schema = Schema.String.pipe(
Schema.decodeTo(Schema.BigInt, SchemaTransformation.bigintFromString)
)
bigintFromString)
)