Transformation<unknown, URLSearchParams, never, never>Decodes URLSearchParams into a nested record using bracket-path keys and
encodes object-like values back into URLSearchParams.
When to use
Use when you need a schema transformation for query strings whose keys, such
as filter[name] or items[0], should become nested data.
Details
Decode produces string leaves. Encode flattens nested objects and arrays into
bracket-path entries and returns empty URLSearchParams for non-object
inputs.
Example (Decoding URLSearchParams)
import { Schema, SchemaTransformation } from "effect"
const schema = Schema.instanceOf(URLSearchParams).pipe(
Schema.decodeTo(Schema.Unknown, SchemaTransformation.fromURLSearchParams)
)export const const fromURLSearchParams: Transformation<
unknown,
URLSearchParams,
never,
never
>
const fromURLSearchParams: {
_tag: 'Transformation';
decode: SchemaGetter.Getter<T, E, RD>;
encode: SchemaGetter.Getter<E, T, RE>;
flip: () => Transformation<URLSearchParams, unknown, never, never>;
compose: (other: Transformation<T2, unknown, RD2, RE2>) => Transformation<T2, URLSearchParams, RD2, RE2>;
}
Decodes URLSearchParams into a nested record using bracket-path keys and
encodes object-like values back into URLSearchParams.
When to use
Use when you need a schema transformation for query strings whose keys, such
as filter[name] or items[0], should become nested data.
Details
Decode produces string leaves. Encode flattens nested objects and arrays into
bracket-path entries and returns empty URLSearchParams for non-object
inputs.
Example (Decoding URLSearchParams)
import { Schema, SchemaTransformation } from "effect"
const schema = Schema.instanceOf(URLSearchParams).pipe(
Schema.decodeTo(Schema.Unknown, SchemaTransformation.fromURLSearchParams)
)
fromURLSearchParams = new constructor Transformation<unknown, URLSearchParams, never, never>(decode: SchemaGetter.Getter<unknown, URLSearchParams, never>, encode: SchemaGetter.Getter<URLSearchParams, unknown, never>): Transformation<unknown, URLSearchParams, never, never>Represents a bidirectional transformation between a decoded type T and an encoded
type E, built from a pair of Getters.
When to use
Use when you need a schema transformation that defines how a schema converts
between two representations.
- You want to compose multiple transformations into a pipeline.
- You want to flip a transformation to swap decode/encode.
Details
This is the primary building block for Schema.decodeTo, Schema.encodeTo,
Schema.decode, Schema.encode, and Schema.link. Each direction is a
SchemaGetter.Getter that handles optionality, failure, and Effect services.
- Immutable —
flip() and compose() return new instances.
flip() swaps the decode and encode getters.
compose(other) chains: this.decode then other.decode for decoding,
other.encode then this.encode for encoding.
Example (Composing two transformations)
import { SchemaTransformation } from "effect"
const trimAndLower = SchemaTransformation.trim().compose(
SchemaTransformation.toLowerCase()
)
// decode: trim then lowercase
// encode: passthrough (both directions)
Transformation<unknown, URLSearchParams>(
import SchemaGetterSchemaGetter.decodeURLSearchParams(),
import SchemaGetterSchemaGetter.encodeURLSearchParams()
)