withTransport
Call Signature
Section titled “Call Signature”function withTransport<T>(parser, transport): ParserWithDefault<T>;Defined in: tanstack/core/built-in-parsers.ts:560
Wrap a parser with a string transport layer — the encoder/decoder stage.
encode runs after the parser’s serialize, decode before its parse.
Useful for base64url / signing on top of any existing parser. The inner
parser’s eq, default and .withOptions() carry over, so wrapping a
.withDefault() parser keeps it non-nullable. A decode that throws yields null.
Type Parameters
Section titled “Type Parameters”| Type Parameter |
|---|
T |
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
parser |
ParserWithDefault<T> |
transport |
Transport |
Returns
Section titled “Returns”Example
Section titled “Example”import { decodeBase64Url, encodeBase64Url } from "@xtandard/lib/pagination";import { parseAsInteger, parseAsJson, withTransport } from "@xtandard/lib/tanstack";import * as v from "valibot";
const filters = withTransport(parseAsJson(v.object({ status: v.string() })), { encode: encodeBase64Url, decode: decodeBase64Url,});filters.serialize({ status: "open" }); // → "eyJzdGF0dXMiOiJvcGVuIn0"filters.parse("eyJzdGF0dXMiOiJvcGVuIn0"); // → { status: "open" }
const page = withTransport(parseAsInteger.withDefault(1), { encode: btoa, decode: atob });page.defaultValue; // → 1Call Signature
Section titled “Call Signature”function withTransport<T>(parser, transport): Parser<T>;Defined in: tanstack/core/built-in-parsers.ts:564
Wrap a parser with a string transport layer — the encoder/decoder stage.
encode runs after the parser’s serialize, decode before its parse.
Useful for base64url / signing on top of any existing parser. The inner
parser’s eq, default and .withOptions() carry over, so wrapping a
.withDefault() parser keeps it non-nullable. A decode that throws yields null.
Type Parameters
Section titled “Type Parameters”| Type Parameter |
|---|
T |
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
parser |
Parser<T> |
transport |
Transport |
Returns
Section titled “Returns”Parser<T>
Example
Section titled “Example”import { decodeBase64Url, encodeBase64Url } from "@xtandard/lib/pagination";import { parseAsInteger, parseAsJson, withTransport } from "@xtandard/lib/tanstack";import * as v from "valibot";
const filters = withTransport(parseAsJson(v.object({ status: v.string() })), { encode: encodeBase64Url, decode: decodeBase64Url,});filters.serialize({ status: "open" }); // → "eyJzdGF0dXMiOiJvcGVuIn0"filters.parse("eyJzdGF0dXMiOiJvcGVuIn0"); // → { status: "open" }
const page = withTransport(parseAsInteger.withDefault(1), { encode: btoa, decode: atob });page.defaultValue; // → 1Call Signature
Section titled “Call Signature”function withTransport<T>(parser, transport): | Parser<T>| ParserWithDefault<T>;Defined in: tanstack/core/built-in-parsers.ts:565
Wrap a parser with a string transport layer — the encoder/decoder stage.
encode runs after the parser’s serialize, decode before its parse.
Useful for base64url / signing on top of any existing parser. The inner
parser’s eq, default and .withOptions() carry over, so wrapping a
.withDefault() parser keeps it non-nullable. A decode that throws yields null.
Type Parameters
Section titled “Type Parameters”| Type Parameter |
|---|
T |
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
parser |
AnySingleParser<T> |
transport |
Transport |
Returns
Section titled “Returns”| Parser<T>
| ParserWithDefault<T>
Example
Section titled “Example”import { decodeBase64Url, encodeBase64Url } from "@xtandard/lib/pagination";import { parseAsInteger, parseAsJson, withTransport } from "@xtandard/lib/tanstack";import * as v from "valibot";
const filters = withTransport(parseAsJson(v.object({ status: v.string() })), { encode: encodeBase64Url, decode: decodeBase64Url,});filters.serialize({ status: "open" }); // → "eyJzdGF0dXMiOiJvcGVuIn0"filters.parse("eyJzdGF0dXMiOiJvcGVuIn0"); // → { status: "open" }
const page = withTransport(parseAsInteger.withDefault(1), { encode: btoa, decode: atob });page.defaultValue; // → 1