On this pageFunctions
Route
/**
* Creates a parser that captures a URL segment as a named integer field.
*
* Fails if the segment is not a valid integer.
*/
<K extends string>(name: K): Biparser<Record<K, number>>/**
* Combines multiple parsers, trying each in order until one succeeds.
*
* Returns a `Parser` (parse-only) since the union of different route
* shapes cannot provide a single unified print function.
*/
<Parsers extends readonly Array<ParserInput>>(parsers: Parsers): Parser<InferParsed<Parsers[number]>>/** Creates a parser for a dynamic URL segment with custom parse and print functions. */
<A>(
label: string,
parse: (segment: string) => Effect<A, ParseError>,
print: (value: A) => string
): Biparser<A>label: A descriptive name used in error messages.
parse: Converts a raw URL segment string into the parsed value.
print: Converts the parsed value back into a URL segment string.
/**
* Parses a URL against a parser, falling back to a not-found route if no
* parser matches.
*/
<A, B>(
parser: Parser<A>,
notFoundRouteConstructor: {
make: (data: {
path: string
}) => B
}
): (url: Url.Url) => A | Bparser: The parser (typically from `oneOf`) to attempt.
notFoundRouteConstructor: Constructor called with `{ path }` when
no route matches.
/**
* Adds query parameter parsing to a `Biparser` using an Effect `Schema`.
*
* Produces a `TerminalParser` that cannot be extended with `slash`,
* since query parameters must appear at the end of a route definition.
*/
<A, I extends ReadonlyRecord<string, unknown>>(schema: Codec<A, I>): (parser: Biparser<B>) => TerminalParser<B & A>schema: An Effect Schema describing the expected query parameters.
/**
* Wraps `Schema.TaggedStruct` to create a route variant you can call directly as a constructor.
* Use `r` for route types — enabling `Home()` instead of `Home.make()`.
*/
<Tag extends string>(tag: Tag): CallableTaggedStruct<Tag, {}>
<Tag extends string, Fields extends Fields>(
tag: Tag,
fields: Fields
): CallableTaggedStruct<Tag, Fields>/**
* Composes two `Biparser`s sequentially, combining their parsed values.
*
* Cannot be used after `query` since query parameters are terminal.
*/
<A extends Record<string, unknown>, B extends Record<string, unknown>>(parserB: Biparser<A>): (parserA: Biparser<B> & {
__terminal: undefined
Cannot use slash after query - query parameters must be terminal: undefined
}) => Biparser<B & A>/** Creates a parser that captures a URL segment as a named string field. */
<K extends string>(name: K): Biparser<Record<K, string>>/**
* A bidirectional parser that can both parse URL segments into a value
* and print a value back to URL segments.
*/
type Biparser = {
parse: (segments: ReadonlyArray<string>, search?: string) => Effect.Effect<ParseResult<A>, ParseError>
print: (value: A, state: PrintState) => Effect.Effect<PrintState, ParseError>
}/** The result of parsing: a tuple of the parsed value and remaining URL segments. */
type ParseResult = [A, ReadonlyArray<string>]/**
* A parse-only parser with no print/build capabilities.
*
* Returned by `oneOf`, which combines multiple parsers whose print
* types may differ and therefore cannot be unified into a single `Biparser`.
*/
type Parser = {
parse: (segments: ReadonlyArray<string>, search?: string) => Effect.Effect<ParseResult<A>, ParseError>
}/**
* A parser with a `build` method that can reconstruct URLs from parsed values.
*
* Created by applying `mapTo` to a `Biparser`, binding it to a tagged
* type constructor so parsed values carry a discriminant tag and URLs can be
* built from tag payloads.
*
* Routers are callable — `homeRouter()` or `personRouter({ id: 42 })` —
* and also expose `.build` as an alias and `.parse` for URL matching.
*/
type Router = BuildFn<A> & {
build: BuildFn<A>
parse: (segments: ReadonlyArray<string>, search?: string) => Effect.Effect<ParseResult<A>, ParseError>
}/**
* A `Biparser` that has been terminated (e.g. by `query`) and cannot
* be extended with `slash`.
*/
type TerminalParser = Biparser<A> & {
__terminal: true
}/**
* Converts a `Biparser` into a `Router` by mapping parsed values to a
* tagged type constructor.
*
* The resulting `Router` can both parse URLs into tagged route values and
* build URLs from route payloads.
*/
const mapTo: (appRouteConstructor: {
make: () => T
}) => (parser: Biparser<{}>) => Router<T>