@@ -10,6 +10,7 @@ import { isPlainObject } from "./is-plain-object.js";
1010import { safeParse } from "./schemas.js" ;
1111
1212export type Encoding =
13+ | "jsonl"
1314 | "json"
1415 | "text"
1516 | "bytes"
@@ -19,6 +20,7 @@ export type Encoding =
1920 | "fail" ;
2021
2122const DEFAULT_CONTENT_TYPES : Record < Encoding , string > = {
23+ jsonl : "application/jsonl" ,
2224 json : "application/json" ,
2325 text : "text/plain" ,
2426 bytes : "application/octet-stream" ,
@@ -72,6 +74,21 @@ export function json<T>(
7274 return { ...options , enc : "json" , codes, schema } ;
7375}
7476
77+ export function jsonl < T > (
78+ codes : StatusCodePredicate ,
79+ schema : Schema < T > ,
80+ options ?: MatchOptions ,
81+ ) : ValueMatcher < T > {
82+ return { ...options , enc : "jsonl" , codes, schema } ;
83+ }
84+
85+ export function jsonlErr < E > (
86+ codes : StatusCodePredicate ,
87+ schema : Schema < E > ,
88+ options ?: MatchOptions ,
89+ ) : ErrorMatcher < E > {
90+ return { ...options , err : true , enc : "jsonl" , codes, schema } ;
91+ }
7592export function textErr < E > (
7693 codes : StatusCodePredicate ,
7794 schema : Schema < E > ,
@@ -204,6 +221,9 @@ export function match<T, E>(
204221 case "json" :
205222 raw = await response . json ( ) ;
206223 break ;
224+ case "jsonl" :
225+ raw = response . body ;
226+ break ;
207227 case "bytes" :
208228 raw = new Uint8Array ( await response . arrayBuffer ( ) ) ;
209229 break ;
0 commit comments