(): Getter<Schema.TreeRecord<string>, URLSearchParams>Decodes a URLSearchParams object into a nested tree structure using bracket-path notation.
When to use
Use when you need a schema getter to parse query parameters from URLs into structured objects.
Details
The getter is pure and never fails. It interprets bracket-path keys such as
user[name] and items[0] to build nested objects or arrays, and each leaf
value is a string.
Example (Decoding URLSearchParams)
import { SchemaGetter } from "effect"
const decode = SchemaGetter.decodeURLSearchParams()
// Getter<TreeObject<string>, URLSearchParams>export function function decodeURLSearchParams(): Getter<
Schema.TreeRecord<string>,
URLSearchParams
>
Decodes a URLSearchParams object into a nested tree structure using bracket-path notation.
When to use
Use when you need a schema getter to parse query parameters from URLs into
structured objects.
Details
The getter is pure and never fails. It interprets bracket-path keys such as
user[name] and items[0] to build nested objects or arrays, and each leaf
value is a string.
Example (Decoding URLSearchParams)
import { SchemaGetter } from "effect"
const decode = SchemaGetter.decodeURLSearchParams()
// Getter<TreeObject<string>, URLSearchParams>
decodeURLSearchParams(): class Getter<out T, in E, R = never>class Getter {
run: (input: Option.Option<E>, options: SchemaAST.ParseOptions) => Effect.Effect<Option.Option<T>, SchemaIssue.Issue, R>;
map: <T2>(f: (t: T) => T2) => Getter<T2, E, R>;
compose: <T2, R2>(other: Getter<T2, T, R2>) => Getter<T2, E, R | 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; <…;
}
Represents a composable transformation from an encoded type E to a decoded type T.
When to use
Use when you need a schema getter to build and compose custom transformations
for Schema.decodeTo or Schema.decode.
Details
A getter wraps a function Option<E> -> Effect<Option<T>, Issue, R>. It
receives Option.None when the encoded key is absent, such as a missing
struct field, and returns Option.None to omit the value from the decoded
output. It fails with Issue on invalid input and may require Effect
services via R. .map(f) applies f to the decoded value inside Some
while leaving None unchanged. .compose(other) chains two getters by
feeding the output of this into other; passthrough getters on either side
are optimized away.
Example (Creating and composing getters)
import { SchemaGetter } from "effect"
const parseNumber = SchemaGetter.transform<number, string>((s) => Number(s))
const double = SchemaGetter.transform<number, number>((n) => n * 2)
const composed = parseNumber.compose(double)
// composed: Getter<number, string> — parses then doubles
Getter<import SchemaSchema.type Schema.TreeRecord = /*unresolved*/ anyTreeRecord<string>, URLSearchParams> {
return function transform<T, E>(
f: (e: E) => T
): Getter<T, E>
Creates a getter that applies a pure function to present values.
When to use
Use when you need a schema getter for a pure, infallible transformation
between types.
- Building encode/decode pairs for
Schema.decodeTo.
Details
- This is the most commonly used constructor.
- Transforms
Some(e) to Some(f(e)) and leaves None unchanged.
- Skips
None inputs — only called when a value is present.
- Never fails.
Example (Transforming strings to numbers)
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))
})
)
transform((input: URLSearchParamsinput) => function makeTreeRecord<A>(
bracketPathEntries: ReadonlyArray<
readonly [bracketPath: string, value: A]
>
): Schema.TreeRecord<A>
Builds a nested tree object from a list of bracket-path entries.
When to use
Use when you need a schema getter to parse FormData or URLSearchParams
entries into structured objects.
- You have flat key-value pairs with bracket-path keys that need nesting.
Details
- A bracket path is a string like
"user[address][city]" that describes nested
object/array structure.
- Interprets bracket paths and constructs the corresponding nested object.
- Builds and returns a nested object from the input entries.
- Supported syntax:
"foo" → object key "foo"
"foo[bar]" → nested { foo: { bar: ... } }
"foo[0]" → array index { foo: [value] }
"foo[]" → append to array foo
"" → real empty key
- Duplicate keys for the same path are merged into arrays.
Example (Building a tree from bracket paths)
import { SchemaGetter } from "effect"
const tree = SchemaGetter.makeTreeRecord([
["user[name]", "Alice"],
["user[tags][]", "admin"],
["user[tags][]", "editor"]
])
// { user: { name: "Alice", tags: ["admin", "editor"] } }
makeTreeRecord(var Array: ArrayConstructorArray.ArrayConstructor.from<[string, string]>(iterable: Iterable<[string, string]> | ArrayLike<[string, string]>): [string, string][] (+3 overloads)Creates an array from an iterable object.
from(input: URLSearchParamsinput.URLSearchParams.entries(): URLSearchParamsIterator<[string, string]>Returns an array of key, value pairs for every entry in the search params.
entries())))
}