@@ -10,6 +10,7 @@ import { isPlainObject } from "./is-plain-object.js";
10
10
import { safeParse } from "./schemas.js" ;
11
11
12
12
export type Encoding =
13
+ | "jsonl"
13
14
| "json"
14
15
| "text"
15
16
| "bytes"
@@ -19,6 +20,7 @@ export type Encoding =
19
20
| "fail" ;
20
21
21
22
const DEFAULT_CONTENT_TYPES : Record < Encoding , string > = {
23
+ jsonl : "application/jsonl" ,
22
24
json : "application/json" ,
23
25
text : "text/plain" ,
24
26
bytes : "application/octet-stream" ,
@@ -72,6 +74,21 @@ export function json<T>(
72
74
return { ...options , enc : "json" , codes, schema } ;
73
75
}
74
76
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
+ }
75
92
export function textErr < E > (
76
93
codes : StatusCodePredicate ,
77
94
schema : Schema < E > ,
@@ -204,6 +221,9 @@ export function match<T, E>(
204
221
case "json" :
205
222
raw = await response . json ( ) ;
206
223
break ;
224
+ case "jsonl" :
225
+ raw = response . body ;
226
+ break ;
207
227
case "bytes" :
208
228
raw = new Uint8Array ( await response . arrayBuffer ( ) ) ;
209
229
break ;
0 commit comments