import { Type } from 'io-ts'; import { Formatter } from './formatter'; import { RowLacks } from './helpers'; import { Parser } from './parser'; import { QueryValues } from './route'; /** * @category matchers * @since 0.4.0 */ export declare class Match { readonly parser: Parser; readonly formatter: Formatter; /** * @since 0.4.0 */ readonly _A: A; constructor(parser: Parser, formatter: Formatter); /** * @since 0.4.0 */ imap(f: (a: A) => B, g: (b: B) => A): Match; /** * @since 0.4.0 */ then(that: Match & Match>): Match; } /** * @category matchers * @since 0.5.1 */ export declare const imap: (f: (a: A) => B, g: (b: B) => A) => (ma: Match) => Match; /** * @category matchers * @since 0.5.1 */ export declare const then: (mb: Match) => (ma: Match & Match>) => Match; /** * `succeed` matches everything but consumes nothing * * @category matchers * @since 0.4.0 */ export declare const succeed: (a: A) => Match; /** * `end` matches the end of a route * * @category matchers * @since 0.4.0 */ export declare const end: Match<{}>; /** * `type` matches any io-ts type path component * * @example * import * as t from 'io-ts' * import { lit, type, Route } from 'fp-ts-routing' * import { some, none } from 'fp-ts/lib/Option' * * const T = t.keyof({ * a: null, * b: null * }) * * const match = lit('search').then(type('topic', T)) * * assert.deepStrictEqual(match.parser.run(Route.parse('/search/a')), some([{ topic: 'a' }, Route.empty])) * assert.deepStrictEqual(match.parser.run(Route.parse('/search/b')), some([{ topic: 'b' }, Route.empty])) * assert.deepStrictEqual(match.parser.run(Route.parse('/search/')), none) * * @category matchers * @since 0.4.0 */ export declare const type: (k: K, type: Type) => Match<{ [_ in K]: A; }>; /** * `str` matches any string path component * * @example * import { str, Route } from 'fp-ts-routing' * import { some, none } from 'fp-ts/lib/Option' * * assert.deepStrictEqual(str('id').parser.run(Route.parse('/abc')), some([{ id: 'abc' }, new Route([], {})])) * assert.deepStrictEqual(str('id').parser.run(Route.parse('/')), none) * * @category matchers * @since 0.4.0 */ export declare const str: (k: K) => Match<{ [_ in K]: string; }>; /** * @category matchers * @since 0.4.2 */ export declare const IntegerFromString: Type; /** * `int` matches any integer path component * * @example * import { int, Route } from 'fp-ts-routing' * import { some, none } from 'fp-ts/lib/Option' * * assert.deepStrictEqual(int('id').parser.run(Route.parse('/1')), some([{ id: 1 }, new Route([], {})])) * assert.deepStrictEqual(int('id').parser.run(Route.parse('/a')), none) * * @category matchers * @since 0.4.0 */ export declare const int: (k: K) => Match<{ [_ in K]: number; }>; /** * `lit(x)` will match exactly the path component `x` * * @example * import { lit, Route } from 'fp-ts-routing' * import { some, none } from 'fp-ts/lib/Option' * * assert.deepStrictEqual(lit('subview').parser.run(Route.parse('/subview/')), some([{}, new Route([], {})])) * assert.deepStrictEqual(lit('subview').parser.run(Route.parse('/')), none) * * @category matchers * @since 0.4.0 */ export declare const lit: (literal: string) => Match<{}>; /** * Will match a querystring. * * * **Note**. Use `io-ts`'s `strict` instead of `type` otherwise excess properties won't be removed. * * @example * import * as t from 'io-ts' * import { lit, str, query, Route } from 'fp-ts-routing' * * const route = lit('accounts') * .then(str('accountId')) * .then(lit('files')) * .then(query(t.strict({ pathparam: t.string }))) * .formatter.run(Route.empty, { accountId: 'testId', pathparam: '123' }) * .toString() * * assert.strictEqual(route, '/accounts/testId/files?pathparam=123') * * @category matchers * @since 0.4.0 */ export declare const query: (type: Type, unknown>) => Match;