@zap-studio/fetch 0.2.2 → 0.3.1
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/CHANGELOG.md +19 -0
- package/README.md +0 -176
- package/dist/index.d.mts +3 -2
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +88 -5
- package/dist/index.mjs.map +1 -1
- package/dist/{types-BB4ejGeA.d.mts → types-CvCrPMIR.d.mts} +40 -10
- package/dist/types-CvCrPMIR.d.mts.map +1 -0
- package/dist/types.d.mts +2 -2
- package/dist/validator.mjs +0 -1
- package/package.json +5 -5
- package/dist/types-BB4ejGeA.d.mts.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,24 @@
|
|
|
1
1
|
# @zap-studio/fetch
|
|
2
2
|
|
|
3
|
+
## 0.3.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 9919f63: Add discriminated return types based on `throwOnValidationError` option
|
|
8
|
+
|
|
9
|
+
The return type of `$fetch` and `api.*` methods now correctly narrows based on the `throwOnValidationError` option:
|
|
10
|
+
|
|
11
|
+
- When `throwOnValidationError: true` (default) or unspecified: returns `Promise<TSchema>` (the validated data directly)
|
|
12
|
+
- When `throwOnValidationError: false`: returns `Promise<StandardSchemaV1.Result<TSchema>>` (the result object with `value` or `issues`)
|
|
13
|
+
|
|
14
|
+
This improves type safety by eliminating the need for manual type narrowing when using the default behavior.
|
|
15
|
+
|
|
16
|
+
## 0.3.0
|
|
17
|
+
|
|
18
|
+
### Minor Changes
|
|
19
|
+
|
|
20
|
+
- 659621c: Add `searchParams` option to `createFetch` to allow factory-level default query/search parameters. Per-request `searchParams` continue to override factory defaults.
|
|
21
|
+
|
|
3
22
|
## 0.2.2
|
|
4
23
|
|
|
5
24
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -55,179 +55,3 @@ const user = await api.get("https://api.example.com/users/1", UserSchema);
|
|
|
55
55
|
// user is fully typed and validated! ✨
|
|
56
56
|
console.log(user.name); // TypeScript knows this is a string
|
|
57
57
|
```
|
|
58
|
-
|
|
59
|
-
## API
|
|
60
|
-
|
|
61
|
-
### `api.get(url, schema, options?)`
|
|
62
|
-
|
|
63
|
-
```typescript
|
|
64
|
-
const user = await api.get("/api/users/1", UserSchema);
|
|
65
|
-
```
|
|
66
|
-
|
|
67
|
-
### `api.post(url, schema, options?)`
|
|
68
|
-
|
|
69
|
-
```typescript
|
|
70
|
-
const newUser = await api.post("/api/users", UserSchema, {
|
|
71
|
-
body: {
|
|
72
|
-
name: "John Doe",
|
|
73
|
-
email: "john@example.com",
|
|
74
|
-
},
|
|
75
|
-
});
|
|
76
|
-
// Automatically stringifies body and sets Content-Type: application/json
|
|
77
|
-
```
|
|
78
|
-
|
|
79
|
-
### `api.put(url, schema, options?)`
|
|
80
|
-
|
|
81
|
-
```typescript
|
|
82
|
-
const updated = await api.put("/api/users/1", UserSchema, {
|
|
83
|
-
body: { name: "Jane Doe" },
|
|
84
|
-
});
|
|
85
|
-
```
|
|
86
|
-
|
|
87
|
-
### `api.patch(url, schema, options?)`
|
|
88
|
-
|
|
89
|
-
```typescript
|
|
90
|
-
const patched = await api.patch("/api/users/1", UserSchema, {
|
|
91
|
-
body: { email: "newemail@example.com" },
|
|
92
|
-
});
|
|
93
|
-
```
|
|
94
|
-
|
|
95
|
-
### `api.delete(url, schema, options?)`
|
|
96
|
-
|
|
97
|
-
```typescript
|
|
98
|
-
const deleted = await api.delete("/api/users/1", UserSchema);
|
|
99
|
-
```
|
|
100
|
-
|
|
101
|
-
> **Note:** The `api.*` methods always require a schema for validation. For raw responses without validation, use `$fetch` directly.
|
|
102
|
-
|
|
103
|
-
## Advanced Usage
|
|
104
|
-
|
|
105
|
-
### Using `$fetch` directly
|
|
106
|
-
|
|
107
|
-
For more control or when you don't need schema validation:
|
|
108
|
-
|
|
109
|
-
```typescript
|
|
110
|
-
import { $fetch } from "@zap-studio/fetch";
|
|
111
|
-
|
|
112
|
-
// With schema validation
|
|
113
|
-
const user = await $fetch("https://api.example.com/users/1", UserSchema, {
|
|
114
|
-
method: "GET",
|
|
115
|
-
headers: {
|
|
116
|
-
Authorization: "Bearer token",
|
|
117
|
-
},
|
|
118
|
-
});
|
|
119
|
-
|
|
120
|
-
// Without schema - returns raw Response object
|
|
121
|
-
const response = await $fetch("https://api.example.com/users/1", {
|
|
122
|
-
method: "GET",
|
|
123
|
-
});
|
|
124
|
-
const data = await response.json();
|
|
125
|
-
```
|
|
126
|
-
|
|
127
|
-
### Factory Pattern with `createFetch`
|
|
128
|
-
|
|
129
|
-
Create pre-configured fetch instances with base URLs and default headers. Useful for API clients:
|
|
130
|
-
|
|
131
|
-
```typescript
|
|
132
|
-
import { z } from "zod";
|
|
133
|
-
import { createFetch } from "@zap-studio/fetch";
|
|
134
|
-
|
|
135
|
-
// Create a configured instance
|
|
136
|
-
const { $fetch, api } = createFetch({
|
|
137
|
-
baseURL: "https://api.example.com",
|
|
138
|
-
headers: {
|
|
139
|
-
Authorization: "Bearer your-token",
|
|
140
|
-
"X-API-Key": "your-api-key",
|
|
141
|
-
},
|
|
142
|
-
});
|
|
143
|
-
|
|
144
|
-
const UserSchema = z.object({
|
|
145
|
-
id: z.number(),
|
|
146
|
-
name: z.string(),
|
|
147
|
-
});
|
|
148
|
-
|
|
149
|
-
// Now use relative paths - baseURL is prepended automatically
|
|
150
|
-
const user = await api.get("/users/1", UserSchema);
|
|
151
|
-
|
|
152
|
-
// POST with auto-stringified body
|
|
153
|
-
const newUser = await api.post("/users", UserSchema, {
|
|
154
|
-
body: { name: "John Doe" },
|
|
155
|
-
});
|
|
156
|
-
```
|
|
157
|
-
|
|
158
|
-
#### Factory Options
|
|
159
|
-
|
|
160
|
-
| Option | Type | Default | Description |
|
|
161
|
-
| ------------------------ | ------------- | ------- | ------------------------------------------------ |
|
|
162
|
-
| `baseURL` | `string` | `""` | Base URL prepended to relative paths only |
|
|
163
|
-
| `headers` | `HeadersInit` | - | Default headers included in all requests |
|
|
164
|
-
| `throwOnFetchError` | `boolean` | `true` | Throw `FetchError` on non-2xx responses |
|
|
165
|
-
| `throwOnValidationError` | `boolean` | `true` | Throw `ValidationError` on schema validation failures |
|
|
166
|
-
|
|
167
|
-
> **Note:** Absolute URLs (starting with `http://`, `https://`, or `//`) are used as-is and ignore the `baseURL`.
|
|
168
|
-
|
|
169
|
-
#### Multiple API Clients
|
|
170
|
-
|
|
171
|
-
You can create separate fetch instances for different APIs:
|
|
172
|
-
|
|
173
|
-
```typescript
|
|
174
|
-
import { createFetch } from "@zap-studio/fetch";
|
|
175
|
-
|
|
176
|
-
// GitHub API client
|
|
177
|
-
const github = createFetch({
|
|
178
|
-
baseURL: "https://api.github.com",
|
|
179
|
-
headers: { Authorization: "Bearer github-token" },
|
|
180
|
-
});
|
|
181
|
-
|
|
182
|
-
// Your internal API client
|
|
183
|
-
const internal = createFetch({
|
|
184
|
-
baseURL: "https://internal.example.com/api",
|
|
185
|
-
headers: { "X-Internal-Key": "secret" },
|
|
186
|
-
});
|
|
187
|
-
|
|
188
|
-
// Use them independently
|
|
189
|
-
const repo = await github.api.get("/repos/owner/repo", RepoSchema);
|
|
190
|
-
const data = await internal.api.get("/data", DataSchema);
|
|
191
|
-
```
|
|
192
|
-
|
|
193
|
-
### Error Handling
|
|
194
|
-
|
|
195
|
-
The package exports specialized error classes for granular error handling:
|
|
196
|
-
|
|
197
|
-
```typescript
|
|
198
|
-
import { $fetch } from "@zap-studio/fetch";
|
|
199
|
-
import { FetchError, ValidationError } from "@zap-studio/fetch/errors";
|
|
200
|
-
|
|
201
|
-
try {
|
|
202
|
-
const user = await api.get("/api/users/1", UserSchema);
|
|
203
|
-
} catch (error) {
|
|
204
|
-
if (error instanceof FetchError) {
|
|
205
|
-
console.error(`HTTP ${error.status}: ${error.response.statusText}`);
|
|
206
|
-
}
|
|
207
|
-
if (error instanceof ValidationError) {
|
|
208
|
-
console.error("Validation failed:", error.issues);
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
|
-
```
|
|
212
|
-
|
|
213
|
-
### Flexible Validation
|
|
214
|
-
|
|
215
|
-
You can choose whether validation errors should throw exceptions:
|
|
216
|
-
|
|
217
|
-
```typescript
|
|
218
|
-
// Throw on validation error (default)
|
|
219
|
-
const user = await $fetch(url, UserSchema, {
|
|
220
|
-
throwOnValidationError: true,
|
|
221
|
-
});
|
|
222
|
-
|
|
223
|
-
// Return validation result without throwing
|
|
224
|
-
const result = await $fetch(url, UserSchema, {
|
|
225
|
-
throwOnValidationError: false,
|
|
226
|
-
});
|
|
227
|
-
|
|
228
|
-
if (result.issues) {
|
|
229
|
-
console.error("Validation failed:", result.issues);
|
|
230
|
-
} else {
|
|
231
|
-
console.log("Success:", result.value);
|
|
232
|
-
}
|
|
233
|
-
```
|
package/dist/index.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { i as ExtendedRequestInit, n as ApiMethods, r as CreateFetchOptions, t as $Fetch } from "./types-
|
|
1
|
+
import { i as ExtendedRequestInit, n as ApiMethods, r as CreateFetchOptions, t as $Fetch } from "./types-CvCrPMIR.mjs";
|
|
2
2
|
import { StandardSchemaV1 } from "@standard-schema/spec";
|
|
3
3
|
|
|
4
4
|
//#region src/index.d.ts
|
|
@@ -39,7 +39,8 @@ import { StandardSchemaV1 } from "@standard-schema/spec";
|
|
|
39
39
|
* console.log("Validated user:", result.value);
|
|
40
40
|
* }
|
|
41
41
|
*/
|
|
42
|
-
declare function $fetch<TSchema extends StandardSchemaV1>(resource: string, schema: TSchema, options
|
|
42
|
+
declare function $fetch<TSchema extends StandardSchemaV1>(resource: string, schema: TSchema, options: ExtendedRequestInit<false>): Promise<StandardSchemaV1.Result<StandardSchemaV1.InferOutput<TSchema>>>;
|
|
43
|
+
declare function $fetch<TSchema extends StandardSchemaV1>(resource: string, schema: TSchema, options?: ExtendedRequestInit<true | undefined>): Promise<StandardSchemaV1.InferOutput<TSchema>>;
|
|
43
44
|
declare function $fetch(resource: string, options?: ExtendedRequestInit): Promise<Response>;
|
|
44
45
|
/**
|
|
45
46
|
* Convenience methods for common HTTP verbs.
|
package/dist/index.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","names":["api: ApiMethods"],"sources":["../src/index.ts"],"sourcesContent":[],"mappings":";;;;;;;AAgDA
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":["api: ApiMethods"],"sources":["../src/index.ts"],"sourcesContent":[],"mappings":";;;;;;;AAgDA;;;;;;;;;AAMA;;;;;;;;AAMA;;;;;AAsCA;AAgCA;;;;;;;;;;;iBAlFsB,uBAAuB,4CAEnC,kBACC,6BACR,QAAQ,gBAAA,CAAiB,OAAO,gBAAA,CAAiB,YAAY;iBAE1C,uBAAuB,4CAEnC,mBACE,wCACT,QAAQ,gBAAA,CAAiB,YAAY;iBAElB,MAAA,6BAEV,sBACT,QAAQ;;;;;;;;;;;;;;;;;;;;;;cAmCEA,KAAK;;;;;;;;;;;;;;;;;;;;;;;;;iBAgCF,WAAA,kBAA4B;UAClC;OACH"}
|
package/dist/index.mjs
CHANGED
|
@@ -63,10 +63,87 @@ function isAbsoluteURL(url) {
|
|
|
63
63
|
return ABSOLUTE_URL_PATTERN.test(url);
|
|
64
64
|
}
|
|
65
65
|
/**
|
|
66
|
+
* Normalizes search parameters into a URLSearchParams object.
|
|
67
|
+
*/
|
|
68
|
+
function normalizeSearchParams(input) {
|
|
69
|
+
if (input === void 0 || input === null) return new URLSearchParams();
|
|
70
|
+
if (input instanceof URLSearchParams) return new URLSearchParams(input);
|
|
71
|
+
if (typeof input === "string") return new URLSearchParams(input);
|
|
72
|
+
if (Array.isArray(input)) return new URLSearchParams(input);
|
|
73
|
+
const params = new URLSearchParams();
|
|
74
|
+
for (const [k, v] of Object.entries(input)) params.set(k, v);
|
|
75
|
+
return params;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Parses a URL string into its path, query, and hash components.
|
|
79
|
+
* Handles both absolute URLs (using URL constructor) and relative paths.
|
|
80
|
+
*/
|
|
81
|
+
function parseUrlComponents(url) {
|
|
82
|
+
if (isAbsoluteURL(url)) try {
|
|
83
|
+
const parsed = new URL(url);
|
|
84
|
+
const pathOnly = `${parsed.origin}${parsed.pathname}`;
|
|
85
|
+
const existingQuery = parsed.search.startsWith("?") ? parsed.search.slice(1) : parsed.search;
|
|
86
|
+
let hash$1 = parsed.hash;
|
|
87
|
+
if (hash$1 === "" && url.endsWith("#")) hash$1 = "#";
|
|
88
|
+
return {
|
|
89
|
+
pathOnly,
|
|
90
|
+
existingQuery,
|
|
91
|
+
hash: hash$1
|
|
92
|
+
};
|
|
93
|
+
} catch {}
|
|
94
|
+
let hash = "";
|
|
95
|
+
let urlWithoutHash = url;
|
|
96
|
+
const hashIndex = url.indexOf("#");
|
|
97
|
+
if (hashIndex !== -1) {
|
|
98
|
+
hash = url.slice(hashIndex);
|
|
99
|
+
urlWithoutHash = url.slice(0, hashIndex);
|
|
100
|
+
}
|
|
101
|
+
const queryIndex = urlWithoutHash.indexOf("?");
|
|
102
|
+
if (queryIndex === -1) return {
|
|
103
|
+
pathOnly: urlWithoutHash,
|
|
104
|
+
existingQuery: "",
|
|
105
|
+
hash
|
|
106
|
+
};
|
|
107
|
+
return {
|
|
108
|
+
pathOnly: urlWithoutHash.slice(0, queryIndex),
|
|
109
|
+
existingQuery: urlWithoutHash.slice(queryIndex + 1),
|
|
110
|
+
hash
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Builds a URL with merged search parameters from factory defaults,
|
|
115
|
+
* request options, and existing query parameters.
|
|
116
|
+
*
|
|
117
|
+
* This function takes a base URL, factory search parameters,
|
|
118
|
+
* and request search parameters, and combines them into a single URL.
|
|
119
|
+
*
|
|
120
|
+
* Priority (highest to lowest):
|
|
121
|
+
* 1. Request search parameters (highest priority, overwrites all others)
|
|
122
|
+
* 2. Existing query parameters from the URL (overwrites factory defaults)
|
|
123
|
+
* 3. Factory search parameters (lowest priority, overwritten by all others)
|
|
124
|
+
*
|
|
125
|
+
* If no search parameters are provided, the URL will not have a query string.
|
|
126
|
+
* Any trailing hash/fragment is preserved.
|
|
127
|
+
*/
|
|
128
|
+
function buildUrlWithMergedSearchParams(url, factorySearch, requestSearch) {
|
|
129
|
+
const { pathOnly, existingQuery, hash } = parseUrlComponents(url);
|
|
130
|
+
if (!(factorySearch ?? requestSearch ?? existingQuery)) return url;
|
|
131
|
+
const mergedParams = new URLSearchParams();
|
|
132
|
+
const resourceParams = new URLSearchParams(existingQuery);
|
|
133
|
+
const factoryParams = normalizeSearchParams(factorySearch);
|
|
134
|
+
const reqParams = normalizeSearchParams(requestSearch);
|
|
135
|
+
for (const [k, v] of factoryParams.entries()) mergedParams.set(k, v);
|
|
136
|
+
for (const [k, v] of resourceParams.entries()) mergedParams.set(k, v);
|
|
137
|
+
for (const [k, v] of reqParams.entries()) mergedParams.set(k, v);
|
|
138
|
+
const queryString = mergedParams.toString();
|
|
139
|
+
if (queryString) return `${pathOnly}?${queryString}${hash}`;
|
|
140
|
+
return `${pathOnly}${hash}`;
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
66
143
|
* Internal fetch implementation used by both $fetch and createFetch
|
|
67
144
|
*/
|
|
68
145
|
async function fetchInternal(resource, schema, options, defaults) {
|
|
69
|
-
const { throwOnValidationError = defaults.throwOnValidationError, throwOnFetchError = defaults.throwOnFetchError, headers: requestHeaders, ...rest } = options || {};
|
|
146
|
+
const { throwOnValidationError = defaults.throwOnValidationError, throwOnFetchError = defaults.throwOnFetchError, headers: requestHeaders, searchParams: requestSearchParams, ...rest } = options || {};
|
|
70
147
|
const mergedHeaders = mergeHeaders(defaults.headers, requestHeaders);
|
|
71
148
|
const init = {
|
|
72
149
|
...rest,
|
|
@@ -85,6 +162,7 @@ async function fetchInternal(resource, schema, options, defaults) {
|
|
|
85
162
|
const path = trimLeadingSlashes(resource);
|
|
86
163
|
url = base ? `${base}/${path}` : resource;
|
|
87
164
|
}
|
|
165
|
+
url = buildUrlWithMergedSearchParams(url, defaults.searchParams, requestSearchParams);
|
|
88
166
|
const response = await fetch(url, init);
|
|
89
167
|
if (throwOnFetchError && !response.ok) throw new FetchError(`HTTP ${response.status}: ${response.statusText}`, response);
|
|
90
168
|
if (schema) return standardValidate(schema, await response.json(), throwOnValidationError);
|
|
@@ -94,10 +172,14 @@ async function fetchInternal(resource, schema, options, defaults) {
|
|
|
94
172
|
* Creates an HTTP method helper bound to a fetch function
|
|
95
173
|
*/
|
|
96
174
|
function createMethod(fetchFn, method) {
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
175
|
+
function methodFetch(resource, schemaOrOptions, optionsOrUndefined) {
|
|
176
|
+
const [schema, options] = isStandardSchema(schemaOrOptions) ? [schemaOrOptions, optionsOrUndefined] : [void 0, schemaOrOptions];
|
|
177
|
+
return fetchFn(resource, schema, {
|
|
178
|
+
...options,
|
|
179
|
+
method
|
|
180
|
+
});
|
|
181
|
+
}
|
|
182
|
+
return methodFetch;
|
|
101
183
|
}
|
|
102
184
|
|
|
103
185
|
//#endregion
|
|
@@ -162,6 +244,7 @@ function createFetch(factoryOptions = {}) {
|
|
|
162
244
|
const defaults = {
|
|
163
245
|
baseURL: factoryOptions.baseURL ?? "",
|
|
164
246
|
headers: factoryOptions.headers,
|
|
247
|
+
searchParams: factoryOptions.searchParams,
|
|
165
248
|
throwOnFetchError: factoryOptions.throwOnFetchError ?? true,
|
|
166
249
|
throwOnValidationError: factoryOptions.throwOnValidationError ?? true
|
|
167
250
|
};
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":["GLOBAL_DEFAULTS: FetchDefaults","url: string","api: ApiMethods","defaults: FetchDefaults"],"sources":["../src/internal/constants.ts","../src/internal/utils.ts","../src/index.ts"],"sourcesContent":["import type { FetchDefaults } from \"../types\";\n\n/**\n * Default options for the global $fetch\n */\nexport const GLOBAL_DEFAULTS: FetchDefaults = {\n baseURL: \"\",\n headers: undefined,\n throwOnFetchError: true,\n throwOnValidationError: true,\n};\n","import type { StandardSchemaV1 } from \"@standard-schema/spec\";\nimport { FetchError } from \"../errors\";\nimport type { $Fetch, ExtendedRequestInit, FetchDefaults } from \"../types\";\nimport { standardValidate } from \"../validator\";\n\n/**\n * Merges two HeadersInit objects, with the second one taking precedence\n *\n * @example\n * const baseHeaders = { \"Authorization\": \"Bearer token\", \"Content-Type\": \"application/json\" };\n * const overrideHeaders = { \"Content-Type\": \"application/xml\", \"X-Custom-Header\": \"value\" };\n *\n * const merged = mergeHeaders(baseHeaders, overrideHeaders);\n *\n * // Resulting headers:\n * // {\n * // \"Authorization\": \"Bearer token\",\n * // \"Content-Type\": \"application/xml\",\n * // \"X-Custom-Header\": \"value\"\n * // }\n */\nexport function mergeHeaders(\n base: HeadersInit | undefined,\n override: HeadersInit | undefined\n): Headers | undefined {\n if (!(base || override)) {\n return;\n }\n\n const merged = new Headers(base);\n if (override) {\n const overrideHeaders = new Headers(override);\n for (const [key, value] of overrideHeaders.entries()) {\n merged.set(key, value);\n }\n }\n return merged;\n}\n\n/**\n * Removes trailing slashes from a string\n */\nfunction trimTrailingSlashes(str: string): string {\n let end = str.length;\n while (end > 0 && str[end - 1] === \"/\") {\n end -= 1;\n }\n return str.slice(0, end);\n}\n\n/**\n * Removes leading slashes from a string\n */\nfunction trimLeadingSlashes(str: string): string {\n let start = 0;\n while (start < str.length && str[start] === \"/\") {\n start += 1;\n }\n return str.slice(start);\n}\n\nconst ABSOLUTE_URL_PATTERN = /^(?:https?:)?\\/\\//i;\n\n/**\n * Checks if a URL is absolute (starts with http://, https://, or //)\n */\nfunction isAbsoluteURL(url: string): boolean {\n return ABSOLUTE_URL_PATTERN.test(url);\n}\n\n/**\n * Internal fetch implementation used by both $fetch and createFetch\n */\nexport async function fetchInternal(\n resource: string,\n schema: StandardSchemaV1 | undefined,\n options: ExtendedRequestInit | undefined,\n defaults: FetchDefaults\n): Promise<unknown> {\n const {\n throwOnValidationError = defaults.throwOnValidationError,\n throwOnFetchError = defaults.throwOnFetchError,\n headers: requestHeaders,\n ...rest\n } = options || {};\n\n const mergedHeaders = mergeHeaders(defaults.headers, requestHeaders);\n const init = { ...rest, headers: mergedHeaders } as RequestInit;\n\n // Auto-stringify body and set default Content-Type if we have a schema\n if (schema && init.body) {\n init.body = JSON.stringify(init.body);\n\n const existingHeaders = new Headers(init.headers);\n if (!existingHeaders.has(\"Content-Type\")) {\n existingHeaders.set(\"Content-Type\", \"application/json\");\n }\n\n init.headers = existingHeaders;\n }\n\n // For absolute URLs, ignore baseURL entirely\n let url: string;\n if (isAbsoluteURL(resource)) {\n url = resource;\n } else {\n // Normalize URL by avoiding double slashes between baseURL and resource\n const base = trimTrailingSlashes(defaults.baseURL);\n const path = trimLeadingSlashes(resource);\n url = base ? `${base}/${path}` : resource;\n }\n\n const response = await fetch(url, init);\n\n if (throwOnFetchError && !response.ok) {\n throw new FetchError(\n `HTTP ${response.status}: ${response.statusText}`,\n response\n );\n }\n\n // For json with schema, validate\n if (schema) {\n const raw = await response.json();\n return standardValidate(schema, raw, throwOnValidationError);\n }\n\n // No validation, return raw response data\n return response;\n}\n\n/**\n * Creates an HTTP method helper bound to a fetch function\n */\nexport function createMethod<TFetch extends $Fetch>(\n fetchFn: TFetch,\n method: string\n): $Fetch {\n return <TSchema extends StandardSchemaV1>(\n resource: string,\n schema: TSchema,\n options?: Omit<ExtendedRequestInit, \"method\">\n ) => fetchFn(resource, schema, { ...options, method });\n}\n","import type { StandardSchemaV1 } from \"@standard-schema/spec\";\nimport { GLOBAL_DEFAULTS } from \"./internal/constants\";\nimport { createMethod, fetchInternal } from \"./internal/utils\";\nimport type {\n $Fetch,\n ApiMethods,\n CreateFetchOptions,\n ExtendedRequestInit,\n FetchDefaults,\n} from \"./types\";\nimport { isStandardSchema } from \"./validator\";\n\n/**\n * Type-safe fetch wrapper with Standard Schema validation.\n *\n * - When `throwOnValidationError: true`: validated data of type `TSchema`\n * - When `throwOnValidationError: false`: Standard Schema Result object `{ value?, issues? }`\n * - When `throwOnFetchError: true`: throws `FetchError` on non-ok responses\n *\n * If no schema is provided, returns the raw `Response` object.\n *\n * @throws {FetchError} When `throwOnFetchError: true` and response is not ok\n * @throws {ValidationError} When `throwOnValidationError: true` and validation fails\n *\n * @example\n * import { z } from \"zod\";\n * import { $fetch } from \"@zap-studio/fetch\";\n *\n * const UserSchema = z.object({ id: z.number(), name: z.string() });\n *\n * // Basic usage (schema validation)\n * const user = await $fetch(\"/api/users/1\", UserSchema, { headers: { \"Authorization\": \"Bearer token\" } });\n * console.log(\"Validated user:\", user);\n *\n * // Raw usage (no schema validation and typed Response object)\n * const result = await $fetch(\"/api/data\", { method: \"POST\", body: JSON.stringify({ key: \"value\" }) });\n * const json = await result.json() as ResultType;\n * console.log(\"Raw response data:\", json);\n *\n * // Usage with validation errors returned instead of thrown\n * const result = await $fetch(\"/api/users/1\", UserSchema, { throwOnValidationError: false });\n *\n * if (result.issues) {\n * console.error(\"Validation errors:\", result.issues);\n * } else {\n * console.log(\"Validated user:\", result.value);\n * }\n */\nexport async function $fetch<TSchema extends StandardSchemaV1>(\n resource: string,\n schema: TSchema,\n options?: ExtendedRequestInit\n): Promise<\n | StandardSchemaV1.InferOutput<TSchema>\n | StandardSchemaV1.Result<StandardSchemaV1.InferOutput<TSchema>>\n>;\n\nexport async function $fetch(\n resource: string,\n options?: ExtendedRequestInit\n): Promise<Response>;\n\nexport async function $fetch(\n resource: string,\n schemaOrOptions?: StandardSchemaV1 | ExtendedRequestInit,\n optionsOrUndefined?: ExtendedRequestInit\n): Promise<unknown> {\n const [schema, options] = isStandardSchema(schemaOrOptions)\n ? [schemaOrOptions, optionsOrUndefined]\n : [undefined, schemaOrOptions];\n\n return await fetchInternal(resource, schema, options, GLOBAL_DEFAULTS);\n}\n\n/**\n * Convenience methods for common HTTP verbs.\n *\n * These methods always require a schema for validation.\n * For raw responses without validation, use `$fetch` directly.\n *\n * @example\n * import { z } from \"zod\";\n * import { api } from \"@zap-studio/fetch\";\n *\n * const PostSchema = z.object({\n * id: z.number(),\n * title: z.string(),\n * content: z.string(),\n * });\n *\n * async function fetchPost(postId: number) {\n * const post = await api.get(`https://api.example.com/posts/${postId}`, PostSchema);\n * return post; // post is typed as { id: number; title: string; content: string; }\n * }\n */\nexport const api: ApiMethods = {\n get: createMethod($fetch, \"GET\"),\n post: createMethod($fetch, \"POST\"),\n put: createMethod($fetch, \"PUT\"),\n patch: createMethod($fetch, \"PATCH\"),\n delete: createMethod($fetch, \"DELETE\"),\n};\n\n/**\n * Creates a custom fetch instance with pre-configured defaults.\n *\n * Use this factory to create API clients with a base URL, default headers,\n * and other shared configuration. Each instance is independent.\n *\n * @example\n * import { z } from \"zod\";\n * import { createFetch } from \"@zap-studio/fetch\";\n *\n * // Create a configured instance\n * const { $fetch, api } = createFetch({\n * baseURL: \"https://api.example.com\",\n * headers: { \"Authorization\": \"Bearer token\" },\n * });\n *\n * const UserSchema = z.object({ id: z.number(), name: z.string() });\n *\n * // Now use relative paths - baseURL is prepended automatically\n * const user = await api.get(\"/users/1\", UserSchema);\n *\n * // Or use $fetch directly\n * const response = await $fetch(\"/users\", UserSchema, { method: \"POST\", body: { name: \"John\" } });\n */\nexport function createFetch(factoryOptions: CreateFetchOptions = {}): {\n $fetch: $Fetch;\n api: ApiMethods;\n} {\n const defaults: FetchDefaults = {\n baseURL: factoryOptions.baseURL ?? \"\",\n headers: factoryOptions.headers,\n throwOnFetchError: factoryOptions.throwOnFetchError ?? true,\n throwOnValidationError: factoryOptions.throwOnValidationError ?? true,\n };\n\n async function customFetch<TSchema extends StandardSchemaV1>(\n resource: string,\n schema: TSchema,\n options?: ExtendedRequestInit\n ): Promise<\n | StandardSchemaV1.InferOutput<TSchema>\n | StandardSchemaV1.Result<StandardSchemaV1.InferOutput<TSchema>>\n >;\n\n async function customFetch(\n resource: string,\n options?: ExtendedRequestInit\n ): Promise<Response>;\n\n async function customFetch(\n resource: string,\n schemaOrOptions?: StandardSchemaV1 | ExtendedRequestInit,\n optionsOrUndefined?: ExtendedRequestInit\n ): Promise<unknown> {\n const [schema, options] = isStandardSchema(schemaOrOptions)\n ? [schemaOrOptions, optionsOrUndefined]\n : [undefined, schemaOrOptions];\n\n return await fetchInternal(resource, schema, options, defaults);\n }\n\n const customApi = {\n get: createMethod(customFetch, \"GET\"),\n post: createMethod(customFetch, \"POST\"),\n put: createMethod(customFetch, \"PUT\"),\n patch: createMethod(customFetch, \"PATCH\"),\n delete: createMethod(customFetch, \"DELETE\"),\n };\n\n return {\n $fetch: customFetch,\n api: customApi,\n };\n}\n"],"mappings":";;;;;;;AAKA,MAAaA,kBAAiC;CAC5C,SAAS;CACT,SAAS;CACT,mBAAmB;CACnB,wBAAwB;CACzB;;;;;;;;;;;;;;;;;;;;ACWD,SAAgB,aACd,MACA,UACqB;AACrB,KAAI,EAAE,QAAQ,UACZ;CAGF,MAAM,SAAS,IAAI,QAAQ,KAAK;AAChC,KAAI,UAAU;EACZ,MAAM,kBAAkB,IAAI,QAAQ,SAAS;AAC7C,OAAK,MAAM,CAAC,KAAK,UAAU,gBAAgB,SAAS,CAClD,QAAO,IAAI,KAAK,MAAM;;AAG1B,QAAO;;;;;AAMT,SAAS,oBAAoB,KAAqB;CAChD,IAAI,MAAM,IAAI;AACd,QAAO,MAAM,KAAK,IAAI,MAAM,OAAO,IACjC,QAAO;AAET,QAAO,IAAI,MAAM,GAAG,IAAI;;;;;AAM1B,SAAS,mBAAmB,KAAqB;CAC/C,IAAI,QAAQ;AACZ,QAAO,QAAQ,IAAI,UAAU,IAAI,WAAW,IAC1C,UAAS;AAEX,QAAO,IAAI,MAAM,MAAM;;AAGzB,MAAM,uBAAuB;;;;AAK7B,SAAS,cAAc,KAAsB;AAC3C,QAAO,qBAAqB,KAAK,IAAI;;;;;AAMvC,eAAsB,cACpB,UACA,QACA,SACA,UACkB;CAClB,MAAM,EACJ,yBAAyB,SAAS,w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AO,aAAa,QAAQ,QAAQ;CACpC,QAAQ,aAAa,QAAQ,SAAS;CACvC;;;;;;;;;;;;;;;;;;;;;;;;;AA0BD,SAAgB,YAAY,iBAAqC,EAAE,EAGjE;CACA,MAAMC,WAA0B;EAC9B,SAAS,eAAe,WAAW;EACnC,SAAS,eAAe;EACxB,mBAAmB,eAAe,qBAAqB;EACvD,wBAAwB,eAAe,0BAA0B;EAClE;CAgBD,eAAe,YACb,UACA,iBACA,oBACkB;EAClB,MAAM,CAAC,QAAQ,WAAW,iBAAiB,gBAAgB,GACvD,CAAC,iBAAiB,mBAAmB,GACrC,CAAC,QAAW,gBAAgB;AAEhC,SAAO,MAAM,cAAc,UAAU,QAAQ,SAAS,SAAS;;AAWjE,QAAO;EACL,QAAQ;EACR,KAVgB;GAChB,KAAK,aAAa,aAAa,MAAM;GACrC,MAAM,aAAa,aAAa,OAAO;GACvC,KAAK,aAAa,aAAa,MAAM;GACrC,OAAO,aAAa,aAAa,QAAQ;GACzC,QAAQ,aAAa,aAAa,SAAS;GAC5C;EAKA"}
|
|
1
|
+
{"version":3,"file":"index.mjs","names":["GLOBAL_DEFAULTS: FetchDefaults","hash","url: string","api: ApiMethods","defaults: FetchDefaults"],"sources":["../src/internal/constants.ts","../src/internal/utils.ts","../src/index.ts"],"sourcesContent":["import type { FetchDefaults } from \"../types\";\n\n/**\n * Default options for the global $fetch\n */\nexport const GLOBAL_DEFAULTS: FetchDefaults = {\n baseURL: \"\",\n headers: undefined,\n throwOnFetchError: true,\n throwOnValidationError: true,\n};\n","import type { StandardSchemaV1 } from \"@standard-schema/spec\";\nimport { FetchError } from \"../errors\";\nimport type {\n $Fetch,\n ExtendedRequestInit,\n FetchDefaults,\n SearchParams,\n} from \"../types\";\nimport { isStandardSchema, standardValidate } from \"../validator\";\n\n/**\n * Merges two HeadersInit objects, with the second one taking precedence\n *\n * @example\n * const baseHeaders = { \"Authorization\": \"Bearer token\", \"Content-Type\": \"application/json\" };\n * const overrideHeaders = { \"Content-Type\": \"application/xml\", \"X-Custom-Header\": \"value\" };\n *\n * const merged = mergeHeaders(baseHeaders, overrideHeaders);\n *\n * // Resulting headers:\n * // {\n * // \"Authorization\": \"Bearer token\",\n * // \"Content-Type\": \"application/xml\",\n * // \"X-Custom-Header\": \"value\"\n * // }\n */\nexport function mergeHeaders(\n base: HeadersInit | undefined,\n override: HeadersInit | undefined\n): Headers | undefined {\n if (!(base || override)) {\n return;\n }\n\n const merged = new Headers(base);\n if (override) {\n const overrideHeaders = new Headers(override);\n for (const [key, value] of overrideHeaders.entries()) {\n merged.set(key, value);\n }\n }\n return merged;\n}\n\n/**\n * Removes trailing slashes from a string\n */\nfunction trimTrailingSlashes(str: string): string {\n let end = str.length;\n while (end > 0 && str[end - 1] === \"/\") {\n end -= 1;\n }\n return str.slice(0, end);\n}\n\n/**\n * Removes leading slashes from a string\n */\nfunction trimLeadingSlashes(str: string): string {\n let start = 0;\n while (start < str.length && str[start] === \"/\") {\n start += 1;\n }\n return str.slice(start);\n}\n\nconst ABSOLUTE_URL_PATTERN = /^(?:https?:)?\\/\\//i;\n\n/**\n * Checks if a URL is absolute (starts with http://, https://, or //)\n */\nfunction isAbsoluteURL(url: string): boolean {\n return ABSOLUTE_URL_PATTERN.test(url);\n}\n\n/**\n * Normalizes search parameters into a URLSearchParams object.\n */\nfunction normalizeSearchParams(\n input: SearchParams | undefined\n): URLSearchParams {\n if (input === undefined || input === null) {\n return new URLSearchParams();\n }\n\n if (input instanceof URLSearchParams) {\n return new URLSearchParams(input);\n }\n\n if (typeof input === \"string\") {\n return new URLSearchParams(input);\n }\n\n if (Array.isArray(input)) {\n return new URLSearchParams(input);\n }\n\n const params = new URLSearchParams();\n for (const [k, v] of Object.entries(input)) {\n params.set(k, v);\n }\n\n return params;\n}\n\n/**\n * Parses a URL string into its path, query, and hash components.\n * Handles both absolute URLs (using URL constructor) and relative paths.\n */\nfunction parseUrlComponents(url: string): {\n pathOnly: string;\n existingQuery: string;\n hash: string;\n} {\n // Try parsing as absolute URL first\n if (isAbsoluteURL(url)) {\n try {\n const parsed = new URL(url);\n const pathOnly = `${parsed.origin}${parsed.pathname}`;\n // parsed.search includes the leading \"?\", so strip it\n const existingQuery = parsed.search.startsWith(\"?\")\n ? parsed.search.slice(1)\n : parsed.search;\n // URL constructor normalizes away empty hash, if original URL had # at end, preserve it\n let hash = parsed.hash;\n if (hash === \"\" && url.endsWith(\"#\")) {\n hash = \"#\";\n }\n return { pathOnly, existingQuery, hash };\n } catch {\n // Fall through to manual parsing if URL constructor fails\n }\n }\n\n // Manual parsing for relative URLs or if URL constructor failed\n let hash = \"\";\n let urlWithoutHash = url;\n const hashIndex = url.indexOf(\"#\");\n if (hashIndex !== -1) {\n hash = url.slice(hashIndex);\n urlWithoutHash = url.slice(0, hashIndex);\n }\n\n // Find the first \"?\" to split path and query\n const queryIndex = urlWithoutHash.indexOf(\"?\");\n if (queryIndex === -1) {\n return { pathOnly: urlWithoutHash, existingQuery: \"\", hash };\n }\n\n const pathOnly = urlWithoutHash.slice(0, queryIndex);\n const existingQuery = urlWithoutHash.slice(queryIndex + 1);\n return { pathOnly, existingQuery, hash };\n}\n\n/**\n * Builds a URL with merged search parameters from factory defaults,\n * request options, and existing query parameters.\n *\n * This function takes a base URL, factory search parameters,\n * and request search parameters, and combines them into a single URL.\n *\n * Priority (highest to lowest):\n * 1. Request search parameters (highest priority, overwrites all others)\n * 2. Existing query parameters from the URL (overwrites factory defaults)\n * 3. Factory search parameters (lowest priority, overwritten by all others)\n *\n * If no search parameters are provided, the URL will not have a query string.\n * Any trailing hash/fragment is preserved.\n */\nfunction buildUrlWithMergedSearchParams(\n url: string,\n factorySearch: FetchDefaults[\"searchParams\"] | undefined,\n requestSearch: ExtendedRequestInit[\"searchParams\"] | undefined\n): string {\n const { pathOnly, existingQuery, hash } = parseUrlComponents(url);\n\n // Early return if no search params to merge\n const hasSearchParams = factorySearch ?? requestSearch ?? existingQuery;\n if (!hasSearchParams) {\n return url;\n }\n\n const mergedParams = new URLSearchParams();\n\n const resourceParams = new URLSearchParams(existingQuery);\n const factoryParams = normalizeSearchParams(factorySearch);\n const reqParams = normalizeSearchParams(requestSearch);\n\n for (const [k, v] of factoryParams.entries()) {\n mergedParams.set(k, v);\n }\n\n for (const [k, v] of resourceParams.entries()) {\n mergedParams.set(k, v);\n }\n\n for (const [k, v] of reqParams.entries()) {\n mergedParams.set(k, v);\n }\n\n const queryString = mergedParams.toString();\n if (queryString) {\n return `${pathOnly}?${queryString}${hash}`;\n }\n\n return `${pathOnly}${hash}`;\n}\n\n/**\n * Internal fetch implementation used by both $fetch and createFetch\n */\nexport async function fetchInternal(\n resource: string,\n schema: StandardSchemaV1 | undefined,\n options: ExtendedRequestInit | undefined,\n defaults: FetchDefaults\n): Promise<unknown> {\n const {\n throwOnValidationError = defaults.throwOnValidationError,\n throwOnFetchError = defaults.throwOnFetchError,\n headers: requestHeaders,\n searchParams: requestSearchParams,\n ...rest\n } = options || {};\n\n const mergedHeaders = mergeHeaders(defaults.headers, requestHeaders);\n const init = { ...rest, headers: mergedHeaders } as RequestInit;\n\n // Auto-stringify body and set default Content-Type if we have a schema\n if (schema && init.body) {\n init.body = JSON.stringify(init.body);\n\n const existingHeaders = new Headers(init.headers);\n if (!existingHeaders.has(\"Content-Type\")) {\n existingHeaders.set(\"Content-Type\", \"application/json\");\n }\n\n init.headers = existingHeaders;\n }\n\n // For absolute URLs, ignore baseURL entirely\n let url: string;\n if (isAbsoluteURL(resource)) {\n url = resource;\n } else {\n // Normalize URL by avoiding double slashes between baseURL and resource\n const base = trimTrailingSlashes(defaults.baseURL);\n const path = trimLeadingSlashes(resource);\n url = base ? `${base}/${path}` : resource;\n }\n\n // Merge query/search params\n url = buildUrlWithMergedSearchParams(\n url,\n defaults.searchParams,\n requestSearchParams\n );\n\n const response = await fetch(url, init);\n\n if (throwOnFetchError && !response.ok) {\n throw new FetchError(\n `HTTP ${response.status}: ${response.statusText}`,\n response\n );\n }\n\n // For json with schema, validate\n if (schema) {\n const raw = await response.json();\n return standardValidate(schema, raw, throwOnValidationError);\n }\n\n // No validation, return raw response data\n return response;\n}\n\n/**\n * Creates an HTTP method helper bound to a fetch function\n */\nexport function createMethod<TFetch extends $Fetch>(\n fetchFn: TFetch,\n method: string\n): $Fetch {\n function methodFetch<TSchema extends StandardSchemaV1>(\n resource: string,\n schema: TSchema,\n options: Omit<ExtendedRequestInit<false>, \"method\">\n ): Promise<StandardSchemaV1.Result<StandardSchemaV1.InferOutput<TSchema>>>;\n\n function methodFetch<TSchema extends StandardSchemaV1>(\n resource: string,\n schema: TSchema,\n options?: Omit<ExtendedRequestInit<true | undefined>, \"method\">\n ): Promise<StandardSchemaV1.InferOutput<TSchema>>;\n\n function methodFetch(\n resource: string,\n options?: Omit<ExtendedRequestInit, \"method\">\n ): Promise<Response>;\n\n function methodFetch(\n resource: string,\n schemaOrOptions?: StandardSchemaV1 | Omit<ExtendedRequestInit, \"method\">,\n optionsOrUndefined?: Omit<ExtendedRequestInit, \"method\">\n ): Promise<unknown> {\n const [schema, options] = isStandardSchema(schemaOrOptions)\n ? [schemaOrOptions, optionsOrUndefined]\n : [undefined, schemaOrOptions];\n\n return (fetchFn as (...args: unknown[]) => Promise<unknown>)(\n resource,\n schema,\n { ...options, method }\n );\n }\n\n return methodFetch;\n}\n","import type { StandardSchemaV1 } from \"@standard-schema/spec\";\nimport { GLOBAL_DEFAULTS } from \"./internal/constants\";\nimport { createMethod, fetchInternal } from \"./internal/utils\";\nimport type {\n $Fetch,\n ApiMethods,\n CreateFetchOptions,\n ExtendedRequestInit,\n FetchDefaults,\n} from \"./types\";\nimport { isStandardSchema } from \"./validator\";\n\n/**\n * Type-safe fetch wrapper with Standard Schema validation.\n *\n * - When `throwOnValidationError: true`: validated data of type `TSchema`\n * - When `throwOnValidationError: false`: Standard Schema Result object `{ value?, issues? }`\n * - When `throwOnFetchError: true`: throws `FetchError` on non-ok responses\n *\n * If no schema is provided, returns the raw `Response` object.\n *\n * @throws {FetchError} When `throwOnFetchError: true` and response is not ok\n * @throws {ValidationError} When `throwOnValidationError: true` and validation fails\n *\n * @example\n * import { z } from \"zod\";\n * import { $fetch } from \"@zap-studio/fetch\";\n *\n * const UserSchema = z.object({ id: z.number(), name: z.string() });\n *\n * // Basic usage (schema validation)\n * const user = await $fetch(\"/api/users/1\", UserSchema, { headers: { \"Authorization\": \"Bearer token\" } });\n * console.log(\"Validated user:\", user);\n *\n * // Raw usage (no schema validation and typed Response object)\n * const result = await $fetch(\"/api/data\", { method: \"POST\", body: JSON.stringify({ key: \"value\" }) });\n * const json = await result.json() as ResultType;\n * console.log(\"Raw response data:\", json);\n *\n * // Usage with validation errors returned instead of thrown\n * const result = await $fetch(\"/api/users/1\", UserSchema, { throwOnValidationError: false });\n *\n * if (result.issues) {\n * console.error(\"Validation errors:\", result.issues);\n * } else {\n * console.log(\"Validated user:\", result.value);\n * }\n */\nexport async function $fetch<TSchema extends StandardSchemaV1>(\n resource: string,\n schema: TSchema,\n options: ExtendedRequestInit<false>\n): Promise<StandardSchemaV1.Result<StandardSchemaV1.InferOutput<TSchema>>>;\n\nexport async function $fetch<TSchema extends StandardSchemaV1>(\n resource: string,\n schema: TSchema,\n options?: ExtendedRequestInit<true | undefined>\n): Promise<StandardSchemaV1.InferOutput<TSchema>>;\n\nexport async function $fetch(\n resource: string,\n options?: ExtendedRequestInit\n): Promise<Response>;\n\nexport async function $fetch(\n resource: string,\n schemaOrOptions?: StandardSchemaV1 | ExtendedRequestInit,\n optionsOrUndefined?: ExtendedRequestInit\n): Promise<unknown> {\n const [schema, options] = isStandardSchema(schemaOrOptions)\n ? [schemaOrOptions, optionsOrUndefined]\n : [undefined, schemaOrOptions];\n\n return await fetchInternal(resource, schema, options, GLOBAL_DEFAULTS);\n}\n\n/**\n * Convenience methods for common HTTP verbs.\n *\n * These methods always require a schema for validation.\n * For raw responses without validation, use `$fetch` directly.\n *\n * @example\n * import { z } from \"zod\";\n * import { api } from \"@zap-studio/fetch\";\n *\n * const PostSchema = z.object({\n * id: z.number(),\n * title: z.string(),\n * content: z.string(),\n * });\n *\n * async function fetchPost(postId: number) {\n * const post = await api.get(`https://api.example.com/posts/${postId}`, PostSchema);\n * return post; // post is typed as { id: number; title: string; content: string; }\n * }\n */\nexport const api: ApiMethods = {\n get: createMethod($fetch, \"GET\"),\n post: createMethod($fetch, \"POST\"),\n put: createMethod($fetch, \"PUT\"),\n patch: createMethod($fetch, \"PATCH\"),\n delete: createMethod($fetch, \"DELETE\"),\n};\n\n/**\n * Creates a custom fetch instance with pre-configured defaults.\n *\n * Use this factory to create API clients with a base URL, default headers,\n * and other shared configuration. Each instance is independent.\n *\n * @example\n * import { z } from \"zod\";\n * import { createFetch } from \"@zap-studio/fetch\";\n *\n * // Create a configured instance\n * const { $fetch, api } = createFetch({\n * baseURL: \"https://api.example.com\",\n * headers: { \"Authorization\": \"Bearer token\" },\n * });\n *\n * const UserSchema = z.object({ id: z.number(), name: z.string() });\n *\n * // Now use relative paths - baseURL is prepended automatically\n * const user = await api.get(\"/users/1\", UserSchema);\n *\n * // Or use $fetch directly\n * const response = await $fetch(\"/users\", UserSchema, { method: \"POST\", body: { name: \"John\" } });\n */\nexport function createFetch(factoryOptions: CreateFetchOptions = {}): {\n $fetch: $Fetch;\n api: ApiMethods;\n} {\n const defaults: FetchDefaults = {\n baseURL: factoryOptions.baseURL ?? \"\",\n headers: factoryOptions.headers,\n searchParams: factoryOptions.searchParams,\n throwOnFetchError: factoryOptions.throwOnFetchError ?? true,\n throwOnValidationError: factoryOptions.throwOnValidationError ?? true,\n };\n\n async function customFetch<TSchema extends StandardSchemaV1>(\n resource: string,\n schema: TSchema,\n options: ExtendedRequestInit<false>\n ): Promise<StandardSchemaV1.Result<StandardSchemaV1.InferOutput<TSchema>>>;\n\n async function customFetch<TSchema extends StandardSchemaV1>(\n resource: string,\n schema: TSchema,\n options?: ExtendedRequestInit<true | undefined>\n ): Promise<StandardSchemaV1.InferOutput<TSchema>>;\n\n async function customFetch(\n resource: string,\n options?: ExtendedRequestInit\n ): Promise<Response>;\n\n async function customFetch(\n resource: string,\n schemaOrOptions?: StandardSchemaV1 | ExtendedRequestInit,\n optionsOrUndefined?: ExtendedRequestInit\n ): Promise<unknown> {\n const [schema, options] = isStandardSchema(schemaOrOptions)\n ? [schemaOrOptions, optionsOrUndefined]\n : [undefined, schemaOrOptions];\n\n return await fetchInternal(resource, schema, options, defaults);\n }\n\n const customApi = {\n get: createMethod(customFetch, \"GET\"),\n post: createMethod(customFetch, \"POST\"),\n put: createMethod(customFetch, \"PUT\"),\n patch: createMethod(customFetch, \"PATCH\"),\n delete: createMethod(customFetch, \"DELETE\"),\n };\n\n return {\n $fetch: customFetch,\n api: customApi,\n };\n}\n"],"mappings":";;;;;;;AAKA,MAAaA,kBAAiC;CAC5C,SAAS;CACT,SAAS;CACT,mBAAmB;CACnB,wBAAwB;CACzB;;;;;;;;;;;;;;;;;;;;ACgBD,SAAgB,aACd,MACA,UACqB;AACrB,KAAI,EAAE,QAAQ,UACZ;CAGF,MAAM,SAAS,IAAI,QAAQ,KAAK;AAChC,KAAI,UAAU;EACZ,MAAM,kBAAkB,IAAI,QAAQ,SAAS;AAC7C,OAAK,MAAM,CAAC,KAAK,UAAU,gBAAgB,SAAS,CAClD,QAAO,IAAI,KAAK,MAAM;;AAG1B,QAAO;;;;;AAMT,SAAS,oBAAoB,KAAqB;CAChD,IAAI,MAAM,IAAI;AACd,QAAO,MAAM,KAAK,IAAI,MAAM,OAAO,IACjC,QAAO;AAET,QAAO,IAAI,MAAM,GAAG,IAAI;;;;;AAM1B,SAAS,mBAAmB,KAAqB;CAC/C,IAAI,QAAQ;AACZ,QAAO,QAAQ,IAAI,UAAU,IAAI,WAAW,IAC1C,UAAS;AAEX,QAAO,IAAI,MAAM,MAAM;;AAGzB,MAAM,uBAAuB;;;;AAK7B,SAAS,cAAc,KAAsB;AAC3C,QAAO,qBAAqB,KAAK,IAAI;;;;;AAMvC,SAAS,sBACP,OACiB;AACjB,KAAI,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S;;AAWjE,QAAO;EACL,QAAQ;EACR,KAVgB;GAChB,KAAK,aAAa,aAAa,MAAM;GACrC,MAAM,aAAa,aAAa,OAAO;GACvC,KAAK,aAAa,aAAa,MAAM;GACrC,OAAO,aAAa,aAAa,QAAQ;GACzC,QAAQ,aAAa,aAAa,SAAS;GAC5C;EAKA"}
|
|
@@ -3,23 +3,40 @@ import { StandardSchemaV1 } from "@standard-schema/spec";
|
|
|
3
3
|
//#region src/types.d.ts
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
|
-
*
|
|
6
|
+
* Type representing various formats for search parameters
|
|
7
|
+
* that can be used in requests.
|
|
8
|
+
* Can be a URLSearchParams object, a record of string pairs,
|
|
9
|
+
* a query string, or an array of tuples.
|
|
10
|
+
*/
|
|
11
|
+
type SearchParams = URLSearchParams | Record<string, string> | string | [string, string][];
|
|
12
|
+
/**
|
|
13
|
+
* Base extended request options without throwOnValidationError
|
|
7
14
|
*/
|
|
8
|
-
type
|
|
15
|
+
type BaseExtendedRequestInit = Omit<RequestInit, "body"> & {
|
|
9
16
|
/**
|
|
10
17
|
* Request body - can be a BodyInit value or an object that will be JSON-stringified
|
|
11
18
|
*/
|
|
12
19
|
body?: BodyInit | Record<string, unknown>;
|
|
13
20
|
/**
|
|
21
|
+
* Per-request query/search params
|
|
22
|
+
* @default undefined
|
|
23
|
+
*/
|
|
24
|
+
searchParams?: SearchParams;
|
|
25
|
+
/**
|
|
14
26
|
* Whether to throw a FetchError on HTTP errors (non-2xx responses)
|
|
15
27
|
* @default true
|
|
16
28
|
*/
|
|
17
29
|
throwOnFetchError?: boolean;
|
|
30
|
+
};
|
|
31
|
+
/**
|
|
32
|
+
* Extended RequestInit type to include custom fetch options
|
|
33
|
+
*/
|
|
34
|
+
type ExtendedRequestInit<TThrowOnValidationError extends boolean | undefined = boolean | undefined> = BaseExtendedRequestInit & {
|
|
18
35
|
/**
|
|
19
36
|
* Whether to throw a ValidationError on validation errors
|
|
20
37
|
* @default true
|
|
21
38
|
*/
|
|
22
|
-
throwOnValidationError?:
|
|
39
|
+
throwOnValidationError?: TThrowOnValidationError;
|
|
23
40
|
};
|
|
24
41
|
/**
|
|
25
42
|
* Internal defaults used by fetchInternal
|
|
@@ -31,10 +48,15 @@ type FetchDefaults = {
|
|
|
31
48
|
*/
|
|
32
49
|
baseURL: string;
|
|
33
50
|
/**
|
|
34
|
-
* Default headers to include in all requests
|
|
51
|
+
* Default headers to include in all requests (can be overridden per request)
|
|
52
|
+
* @default undefined
|
|
53
|
+
*/
|
|
54
|
+
headers?: HeadersInit;
|
|
55
|
+
/**
|
|
56
|
+
* Default query/search params applied to every request (can be overridden per request)
|
|
35
57
|
* @default undefined
|
|
36
58
|
*/
|
|
37
|
-
|
|
59
|
+
searchParams?: SearchParams;
|
|
38
60
|
/**
|
|
39
61
|
* Whether to throw a `FetchError` on HTTP errors (non-2xx responses)
|
|
40
62
|
* @default true
|
|
@@ -55,13 +77,21 @@ type CreateFetchOptions = Partial<FetchDefaults>;
|
|
|
55
77
|
*/
|
|
56
78
|
type $Fetch = {
|
|
57
79
|
/**
|
|
58
|
-
* Fetch with schema validation
|
|
80
|
+
* Fetch with schema validation and throwOnValidationError: false
|
|
81
|
+
* @param resource - URL or path to fetch
|
|
82
|
+
* @param schema - Standard Schema for response validation
|
|
83
|
+
* @param options - Extended request options with throwOnValidationError: false
|
|
84
|
+
* @returns Standard Schema Result object with value or issues
|
|
85
|
+
*/
|
|
86
|
+
<TSchema extends StandardSchemaV1>(resource: string, schema: TSchema, options: ExtendedRequestInit<false>): Promise<StandardSchemaV1.Result<StandardSchemaV1.InferOutput<TSchema>>>;
|
|
87
|
+
/**
|
|
88
|
+
* Fetch with schema validation and throwOnValidationError: true or undefined (default)
|
|
59
89
|
* @param resource - URL or path to fetch
|
|
60
90
|
* @param schema - Standard Schema for response validation
|
|
61
91
|
* @param options - Extended request options
|
|
62
|
-
* @returns Validated data
|
|
92
|
+
* @returns Validated data of type TSchema
|
|
63
93
|
*/
|
|
64
|
-
<TSchema extends StandardSchemaV1>(resource: string, schema: TSchema, options?: ExtendedRequestInit): Promise<StandardSchemaV1.InferOutput<TSchema
|
|
94
|
+
<TSchema extends StandardSchemaV1>(resource: string, schema: TSchema, options?: ExtendedRequestInit<true | undefined>): Promise<StandardSchemaV1.InferOutput<TSchema>>;
|
|
65
95
|
/**
|
|
66
96
|
* Fetch without schema validation
|
|
67
97
|
* @param resource - URL or path to fetch
|
|
@@ -96,5 +126,5 @@ type ApiMethods = {
|
|
|
96
126
|
patch: $Fetch;
|
|
97
127
|
};
|
|
98
128
|
//#endregion
|
|
99
|
-
export { FetchDefaults as a, ExtendedRequestInit as i, ApiMethods as n, CreateFetchOptions as r, $Fetch as t };
|
|
100
|
-
//# sourceMappingURL=types-
|
|
129
|
+
export { FetchDefaults as a, ExtendedRequestInit as i, ApiMethods as n, SearchParams as o, CreateFetchOptions as r, $Fetch as t };
|
|
130
|
+
//# sourceMappingURL=types-CvCrPMIR.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types-CvCrPMIR.d.mts","names":[],"sources":["../src/types.ts"],"sourcesContent":[],"mappings":";;;;;;AAQA;AAEI;;;AAWK,KAbG,YAAA,GACR,eAYK,GAXL,MAWK,CAAA,MAAA,EAAA,MAAA,CAAA,GAAA,MAAA,GAAA,CAAA,MAAA,EAAA,MAAA,CAAA,EAAA;;;;AAgBT,KApBK,uBAAA,GAA0B,IAoBnB,CApBwB,WAoBxB,EAAA,MAAA,CAAA,GAAA;EAaZ;AA+BA;AAKA;EAQmB,IAAA,CAAA,EAzEV,QAyEU,GAzEC,MAyED,CAAA,MAAA,EAAA,OAAA,CAAA;EAEP;;;;EAEC,YAAA,CAAA,EAxEI,YAwEa;EAAzB;;;;EAaqC,iBAAA,CAAA,EAAA,OAAA;CAA7B;;;;AAQwC,KAlFzC,mBAkFyC,CAAA,gCAAA,OAAA,GAAA,SAAA,GAAA,OAAA,GAAA,SAAA,CAAA,GAhFjD,uBAgFiD,GAAA;EAAA;AAMrD;;;EAYO,sBAAA,CAAA,EA7FoB,uBA6FpB;CAIG;;;;KA3FE,aAAA;;;;;;;;;;YAUA;;;;;iBAKK;;;;;;;;;;;;;;;KAgBL,kBAAA,GAAqB,QAAQ;;;;KAK7B,MAAA;;;;;;;;mBAQO,4CAEP,kBACC,6BACR,QAAQ,gBAAA,CAAiB,OAAO,gBAAA,CAAiB,YAAY;;;;;;;;mBAS/C,4CAEP,mBACE,wCACT,QAAQ,gBAAA,CAAiB,YAAY;;;;;;;+BAQX,sBAAsB,QAAQ;;;;;KAMjD,UAAA;;;;OAIL;;;;QAIC;;;;OAID;;;;UAIG;;;;SAID"}
|
package/dist/types.d.mts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as FetchDefaults, i as ExtendedRequestInit, n as ApiMethods, r as CreateFetchOptions, t as $Fetch } from "./types-
|
|
2
|
-
export { $Fetch, ApiMethods, CreateFetchOptions, ExtendedRequestInit, FetchDefaults };
|
|
1
|
+
import { a as FetchDefaults, i as ExtendedRequestInit, n as ApiMethods, o as SearchParams, r as CreateFetchOptions, t as $Fetch } from "./types-CvCrPMIR.mjs";
|
|
2
|
+
export { $Fetch, ApiMethods, CreateFetchOptions, ExtendedRequestInit, FetchDefaults, SearchParams };
|
package/dist/validator.mjs
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zap-studio/fetch",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"private": false,
|
|
@@ -17,13 +17,13 @@
|
|
|
17
17
|
},
|
|
18
18
|
"devDependencies": {
|
|
19
19
|
"@types/node": "^24.10.1",
|
|
20
|
-
"@vitest/coverage-v8": "^4.0.
|
|
21
|
-
"arktype": "^2.1.
|
|
20
|
+
"@vitest/coverage-v8": "^4.0.15",
|
|
21
|
+
"arktype": "^2.1.28",
|
|
22
22
|
"jsdom": "^27.2.0",
|
|
23
|
-
"tsdown": "
|
|
23
|
+
"tsdown": "0.17.0-beta.6",
|
|
24
24
|
"typescript": "^5.9.3",
|
|
25
25
|
"valibot": "^1.2.0",
|
|
26
|
-
"vitest": "^4.0.
|
|
26
|
+
"vitest": "^4.0.15",
|
|
27
27
|
"zod": "^4.1.13",
|
|
28
28
|
"@zap-studio/tsdown-config": "0.0.0",
|
|
29
29
|
"@zap-studio/typescript-config": "0.0.0",
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types-BB4ejGeA.d.mts","names":[],"sources":["../src/types.ts"],"sourcesContent":[],"mappings":";;;;;;AAKA;AAAuC,KAA3B,mBAAA,GAAsB,IAAK,CAAA,WAAA,EAAA,MAAA,CAAA,GAAA;EAAL;;;EAId,IAAA,CAAA,EAAX,QAAW,GAAA,MAAA,CAAA,MAAA,EAAA,OAAA,CAAA;EAgBpB;AA0BA;AAKA;;EAUY,iBAAA,CAAA,EAAA,OAAA;EACE;;;;EAGgB,sBAAiB,CAAA,EAAA,OAAA;CAAzC;;;;AAS+C,KAtDzC,aAAA,GAsDyC;EAAA;AAMrD;;;EAYO,OAAA,EAAA,MAAA;EAIG;;;;WAlEC;;;;;;;;;;;;;;;KAgBC,kBAAA,GAAqB,QAAQ;;;;KAK7B,MAAA;;;;;;;;mBAQO,4CAEP,mBACE,sBACT,QACC,gBAAA,CAAiB,YAAY,WAC7B,gBAAA,CAAiB,OAAO,gBAAA,CAAiB,YAAY;;;;;;;+BAS5B,sBAAsB,QAAQ;;;;;KAMjD,UAAA;;;;OAIL;;;;QAIC;;;;OAID;;;;UAIG;;;;SAID"}
|