prapti 0.0.6 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +36 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -106,6 +106,34 @@ const headers = response.validatedHeaders;
|
|
|
106
106
|
console.log(`Rate limit remaining: ${headers["x-rate-limit-remaining"]}`);
|
|
107
107
|
```
|
|
108
108
|
|
|
109
|
+
Notes:
|
|
110
|
+
- When `validate.request.headers` is provided, Prapti preserves original headers and overwrites them with validated values by default.
|
|
111
|
+
- Use `headerValidationMode: "strict"` to send only validated headers.
|
|
112
|
+
- If a header is validated to `null` or `undefined`, it is removed from the outgoing request.
|
|
113
|
+
- Include `content-type` in your header schema if you want it validated; in strict mode, include it if you want it sent.
|
|
114
|
+
|
|
115
|
+
</details>
|
|
116
|
+
|
|
117
|
+
<details>
|
|
118
|
+
<summary>Serialization</summary>
|
|
119
|
+
|
|
120
|
+
By default, Prapti uses `JSON.stringify` and `JSON.parse` for JSON payloads. You can supply a custom serializer per instance:
|
|
121
|
+
|
|
122
|
+
```typescript
|
|
123
|
+
import superjson from "superjson";
|
|
124
|
+
|
|
125
|
+
const { fetch } = prapti(zodAdapter, {
|
|
126
|
+
serializer: {
|
|
127
|
+
stringify: (value) => superjson.stringify(value),
|
|
128
|
+
parse: (value) => superjson.parse(value),
|
|
129
|
+
isJsonContentType: (contentType) =>
|
|
130
|
+
contentType?.toLowerCase().includes("application/json") ?? false,
|
|
131
|
+
},
|
|
132
|
+
});
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
`ValidatedResponse.json()` uses the same serializer for response parsing.
|
|
136
|
+
|
|
109
137
|
</details>
|
|
110
138
|
|
|
111
139
|
## Adapters
|
|
@@ -138,12 +166,18 @@ const { fetch } = prapti(customAdapter);
|
|
|
138
166
|
## API
|
|
139
167
|
|
|
140
168
|
<details>
|
|
141
|
-
<summary><code>prapti(adapter)</code></summary>
|
|
169
|
+
<summary><code>prapti(adapter, config?)</code></summary>
|
|
142
170
|
|
|
143
171
|
Factory function. Pass a validation adapter and get back an enhanced `fetch`.
|
|
144
172
|
|
|
145
173
|
```typescript
|
|
146
|
-
const { fetch } = prapti(zodAdapter
|
|
174
|
+
const { fetch } = prapti(zodAdapter, {
|
|
175
|
+
serializer: {
|
|
176
|
+
stringify: JSON.stringify,
|
|
177
|
+
parse: JSON.parse,
|
|
178
|
+
},
|
|
179
|
+
headerValidationMode: "preserve",
|
|
180
|
+
});
|
|
147
181
|
```
|
|
148
182
|
|
|
149
183
|
</details>
|