@zap-studio/fetch 0.5.6 → 1.0.0

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/dist/constants.js DELETED
@@ -1,21 +0,0 @@
1
- //#region src/constants.ts
2
- /**
3
- * Default options for the global $fetch
4
- *
5
- * These defaults are used by the top-level `$fetch` export.
6
- * Use `createFetch(...)` when you need per-client defaults.
7
- *
8
- * @example
9
- * import { GLOBAL_DEFAULTS } from "@zap-studio/fetch/constants";
10
- *
11
- * console.log(GLOBAL_DEFAULTS.throwOnFetchError); // true
12
- */
13
- const GLOBAL_DEFAULTS = {
14
- baseURL: "",
15
- throwOnFetchError: true,
16
- throwOnValidationError: true
17
- };
18
- //#endregion
19
- export { GLOBAL_DEFAULTS };
20
-
21
- //# sourceMappingURL=constants.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"constants.js","names":[],"sources":["../src/constants.ts"],"sourcesContent":["/**\n * Shared defaults and constants for fetch behavior.\n *\n * @module @zap-studio/fetch/constants\n */\n\nimport type { FetchDefaults } from \"./types.js\";\n\n/**\n * Default options for the global $fetch\n *\n * These defaults are used by the top-level `$fetch` export.\n * Use `createFetch(...)` when you need per-client defaults.\n *\n * @example\n * import { GLOBAL_DEFAULTS } from \"@zap-studio/fetch/constants\";\n *\n * console.log(GLOBAL_DEFAULTS.throwOnFetchError); // true\n */\nexport const GLOBAL_DEFAULTS: FetchDefaults = {\n baseURL: \"\",\n throwOnFetchError: true,\n throwOnValidationError: true,\n};\n"],"mappings":";;;;;;;;;;;;AAmBA,MAAa,kBAAiC;CAC5C,SAAS;CACT,mBAAmB;CACnB,wBAAwB;AAC1B"}
@@ -1,222 +0,0 @@
1
- import { GLOBAL_DEFAULTS } from "./constants.js";
2
- import { FetchError } from "./errors.js";
3
- import { mergeHeaders } from "./headers.js";
4
- import { normalizeRequest } from "./request.js";
5
- import { resolveRequestUrl } from "./url.js";
6
- import { isStandardSchema, standardValidate } from "@zap-studio/validation";
7
- //#region src/_internal.ts
8
- /**
9
- * Normalizes request-level options into a final RequestInit payload and runtime flags.
10
- *
11
- * @param options - Request-level options.
12
- * @param defaults - Client-level defaults.
13
- * @returns Fully merged request init payload and effective runtime flags.
14
- */
15
- const prepareRequestInit = (options, defaults) => {
16
- const { headers, json, searchParams, throwOnFetchError = defaults.throwOnFetchError, throwOnValidationError = defaults.throwOnValidationError, ...rest } = options;
17
- const init = { ...rest };
18
- const mergedHeaders = mergeHeaders(defaults.headers, headers);
19
- if (mergedHeaders !== void 0) init.headers = mergedHeaders;
20
- if (json !== void 0) {
21
- if (init.body !== void 0 && init.body !== null) throw new TypeError("Cannot provide both `body` and `json`.");
22
- init.body = JSON.stringify(json);
23
- if (init.headers === void 0) init.headers = new Headers({ "Content-Type": "application/json" });
24
- else {
25
- const requestHeaders = new Headers(init.headers);
26
- if (!requestHeaders.has("Content-Type")) requestHeaders.set("Content-Type", "application/json");
27
- init.headers = requestHeaders;
28
- }
29
- }
30
- return {
31
- init,
32
- searchParams,
33
- throwOnFetchError,
34
- throwOnValidationError
35
- };
36
- };
37
- /**
38
- * Internal fetch implementation used by both $fetch and createFetch.
39
- *
40
- * This function normalizes request input, resolves final URL + query params,
41
- * executes `fetch`, optionally throws `FetchError`, and optionally validates
42
- * JSON response payloads using Standard Schema.
43
- *
44
- * @param input - Request URL, path, or Request object.
45
- * @param schema - Optional Standard Schema for response validation.
46
- * @param options - Optional request options and package-specific flags.
47
- * @param defaults - Effective client defaults.
48
- * @returns Raw `Response` when no schema is provided; otherwise validated output.
49
- * @throws {FetchError} When `throwOnFetchError` is `true` and the response is not ok.
50
- * @throws {ValidationError} When a schema is provided, validation returns issues, and
51
- * `throwOnValidationError` is `true`.
52
- * @throws {TypeError} When both `body` and `json` are provided, when JSON request
53
- * serialization fails, when request construction fails, when headers/search params are
54
- * invalid, when `response.json()` cannot read the body, or when the runtime `fetch`
55
- * implementation rejects network-level failures as `TypeError`.
56
- * @throws {DOMException} When the runtime rejects an aborted request or response body read
57
- * as an `AbortError` DOMException.
58
- * @throws {SyntaxError} When a schema is provided and `response.json()` cannot parse the
59
- * response body.
60
- * @throws {unknown} Any error thrown or rejected by the provided Standard Schema validator.
61
- */
62
- const fetchInternal = async (input, schema, options, defaults) => {
63
- const request = normalizeRequest(input, options);
64
- const { init, searchParams, throwOnFetchError, throwOnValidationError } = prepareRequestInit(request.options, defaults);
65
- const url = resolveRequestUrl(request.url, defaults, searchParams);
66
- const response = request.request ? await fetch(new Request(url, request.request), init) : await fetch(url, init);
67
- if (throwOnFetchError && !response.ok) throw new FetchError(`HTTP ${response.status}: ${response.statusText}`, response);
68
- if (schema === void 0) return response;
69
- const raw = await response.json();
70
- if (throwOnValidationError) return await standardValidate(schema, raw, { throwOnError: true });
71
- return await standardValidate(schema, raw, { throwOnError: false });
72
- };
73
- //#endregion
74
- //#region src/_methods.ts
75
- /**
76
- * Method helper factories used to build verb-specific fetch functions.
77
- *
78
- * @module @zap-studio/fetch/_methods (private)
79
- */
80
- /**
81
- * Creates an HTTP method helper bound to a fetch function.
82
- *
83
- * The returned function mirrors `$Fetch` overloads but forces the provided
84
- * HTTP method (`GET`, `POST`, etc.) into request options.
85
- *
86
- * @param fetchFn - Fetch function to wrap.
87
- * @param method - HTTP method to enforce.
88
- * @returns Method-bound fetch function.
89
- * @throws {unknown} Any error thrown or rejected by `fetchFn` when the returned method-bound
90
- * fetch function is called.
91
- *
92
- * @example
93
- * const get = createMethod($fetch, "GET");
94
- * const user = await get("/users/1", UserSchema);
95
- */
96
- const createMethod = (fetchFn, method) => {
97
- /**
98
- * Method-bound `$Fetch` implementation.
99
- *
100
- * Resolves schema/option overloads and injects the configured HTTP method.
101
- */
102
- async function methodFetch(input, schemaOrOptions, optionsOrUndefined) {
103
- if (isStandardSchema(schemaOrOptions)) {
104
- if (optionsOrUndefined?.throwOnValidationError === false) return await fetchFn(input, schemaOrOptions, {
105
- ...optionsOrUndefined,
106
- method,
107
- throwOnValidationError: false
108
- });
109
- const { throwOnValidationError, ...restOptions } = optionsOrUndefined ?? {};
110
- if (throwOnValidationError === true) return await fetchFn(input, schemaOrOptions, {
111
- ...restOptions,
112
- method,
113
- throwOnValidationError: true
114
- });
115
- return await fetchFn(input, schemaOrOptions, {
116
- ...restOptions,
117
- method
118
- });
119
- }
120
- return await fetchFn(input, {
121
- ...schemaOrOptions,
122
- method
123
- });
124
- }
125
- return methodFetch;
126
- };
127
- //#endregion
128
- //#region src/fetch.ts
129
- /**
130
- * Typed fetch client: `$fetch`, `api` method shortcuts, and the `createFetch`
131
- * instance factory.
132
- *
133
- * @module @zap-studio/fetch/fetch
134
- */
135
- async function $fetch(input, schemaOrOptions, optionsOrUndefined) {
136
- const [schema, options] = isStandardSchema(schemaOrOptions) ? [schemaOrOptions, optionsOrUndefined] : [void 0, schemaOrOptions];
137
- return await fetchInternal(input, schema, options, GLOBAL_DEFAULTS);
138
- }
139
- /**
140
- * Convenience methods for common HTTP verbs.
141
- *
142
- * These methods always require a schema for validation.
143
- * For raw responses without validation, use `$fetch` directly.
144
- *
145
- * Each method has the same throw behavior as {@link $fetch}.
146
- *
147
- * @example
148
- * import { z } from "zod";
149
- * import { api } from "@zap-studio/fetch";
150
- *
151
- * const PostSchema = z.object({
152
- * id: z.number(),
153
- * title: z.string(),
154
- * content: z.string(),
155
- * });
156
- *
157
- * async function fetchPost(postId: number) {
158
- * const post = await api.get(`https://api.example.com/posts/${postId}`, PostSchema);
159
- * return post; // post is typed as { id: number; title: string; content: string; }
160
- * }
161
- */
162
- const api = {
163
- delete: createMethod($fetch, "DELETE"),
164
- get: createMethod($fetch, "GET"),
165
- patch: createMethod($fetch, "PATCH"),
166
- post: createMethod($fetch, "POST"),
167
- put: createMethod($fetch, "PUT")
168
- };
169
- /**
170
- * Creates a custom fetch instance with pre-configured defaults.
171
- *
172
- * Use this factory to create API clients with a base URL, default headers,
173
- * and other shared configuration. Each instance is independent.
174
- *
175
- * The returned `$fetch` and `api` methods have the same throw behavior as the
176
- * top-level {@link $fetch} export.
177
- *
178
- * @example
179
- * import { z } from "zod";
180
- * import { createFetch } from "@zap-studio/fetch";
181
- *
182
- * // Create a configured instance
183
- * const { $fetch, api } = createFetch({
184
- * baseURL: "https://api.example.com",
185
- * headers: { "Authorization": "Bearer token" },
186
- * });
187
- *
188
- * const UserSchema = z.object({ id: z.number(), name: z.string() });
189
- *
190
- * // Now use relative paths - baseURL is prepended automatically
191
- * const user = await api.get("/users/1", UserSchema);
192
- *
193
- * // Or use $fetch directly
194
- * const response = await $fetch("/users", UserSchema, { method: "POST", json: { name: "John" } });
195
- */
196
- const createFetch = (factoryOptions = {}) => {
197
- const defaults = {
198
- ...GLOBAL_DEFAULTS,
199
- ...factoryOptions,
200
- baseURL: factoryOptions.baseURL ?? GLOBAL_DEFAULTS.baseURL,
201
- throwOnFetchError: factoryOptions.throwOnFetchError ?? GLOBAL_DEFAULTS.throwOnFetchError,
202
- throwOnValidationError: factoryOptions.throwOnValidationError ?? GLOBAL_DEFAULTS.throwOnValidationError
203
- };
204
- async function customFetch(input, schemaOrOptions, optionsOrUndefined) {
205
- const [schema, options] = isStandardSchema(schemaOrOptions) ? [schemaOrOptions, optionsOrUndefined] : [void 0, schemaOrOptions];
206
- return await fetchInternal(input, schema, options, defaults);
207
- }
208
- return {
209
- $fetch: customFetch,
210
- api: {
211
- delete: createMethod(customFetch, "DELETE"),
212
- get: createMethod(customFetch, "GET"),
213
- patch: createMethod(customFetch, "PATCH"),
214
- post: createMethod(customFetch, "POST"),
215
- put: createMethod(customFetch, "PUT")
216
- }
217
- };
218
- };
219
- //#endregion
220
- export { api as n, createFetch as r, $fetch as t };
221
-
222
- //# sourceMappingURL=fetch-D0IXjsUD.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"fetch-D0IXjsUD.js","names":[],"sources":["../src/_internal.ts","../src/_methods.ts","../src/fetch.ts"],"sourcesContent":["/**\n * Internal request execution and option preparation utilities.\n *\n * @module @zap-studio/fetch/_internal (private)\n */\n\nimport type { StandardSchemaV1 } from \"@zap-studio/validation\";\nimport { standardValidate } from \"@zap-studio/validation\";\n\nimport { FetchError } from \"./errors.js\";\nimport { mergeHeaders } from \"./headers.js\";\nimport { normalizeRequest } from \"./request.js\";\nimport type {\n ExtendedRequestInit,\n FetchDefaults,\n FetchInput,\n} from \"./types.js\";\nimport { resolveRequestUrl } from \"./url.js\";\n\n/**\n * Normalizes request-level options into a final RequestInit payload and runtime flags.\n *\n * @param options - Request-level options.\n * @param defaults - Client-level defaults.\n * @returns Fully merged request init payload and effective runtime flags.\n */\nconst prepareRequestInit = (\n options: ExtendedRequestInit,\n defaults: FetchDefaults\n): {\n init: RequestInit;\n searchParams: ExtendedRequestInit[\"searchParams\"] | undefined;\n throwOnFetchError: boolean;\n throwOnValidationError: boolean;\n} => {\n const {\n headers,\n json,\n searchParams,\n throwOnFetchError = defaults.throwOnFetchError,\n throwOnValidationError = defaults.throwOnValidationError,\n ...rest\n } = options;\n\n const init: RequestInit = { ...rest };\n const mergedHeaders = mergeHeaders(defaults.headers, headers);\n if (mergedHeaders !== undefined) {\n init.headers = mergedHeaders;\n }\n\n if (json !== undefined) {\n if (init.body !== undefined && init.body !== null) {\n throw new TypeError(\"Cannot provide both `body` and `json`.\");\n }\n\n init.body = JSON.stringify(json);\n if (init.headers === undefined) {\n init.headers = new Headers({ \"Content-Type\": \"application/json\" });\n } else {\n const requestHeaders = new Headers(init.headers);\n if (!requestHeaders.has(\"Content-Type\")) {\n requestHeaders.set(\"Content-Type\", \"application/json\");\n }\n init.headers = requestHeaders;\n }\n }\n\n return {\n init,\n searchParams,\n throwOnFetchError,\n throwOnValidationError,\n };\n};\n\n/**\n * Internal fetch implementation used by both $fetch and createFetch.\n *\n * This function normalizes request input, resolves final URL + query params,\n * executes `fetch`, optionally throws `FetchError`, and optionally validates\n * JSON response payloads using Standard Schema.\n *\n * @param input - Request URL, path, or Request object.\n * @param schema - Optional Standard Schema for response validation.\n * @param options - Optional request options and package-specific flags.\n * @param defaults - Effective client defaults.\n * @returns Raw `Response` when no schema is provided; otherwise validated output.\n * @throws {FetchError} When `throwOnFetchError` is `true` and the response is not ok.\n * @throws {ValidationError} When a schema is provided, validation returns issues, and\n * `throwOnValidationError` is `true`.\n * @throws {TypeError} When both `body` and `json` are provided, when JSON request\n * serialization fails, when request construction fails, when headers/search params are\n * invalid, when `response.json()` cannot read the body, or when the runtime `fetch`\n * implementation rejects network-level failures as `TypeError`.\n * @throws {DOMException} When the runtime rejects an aborted request or response body read\n * as an `AbortError` DOMException.\n * @throws {SyntaxError} When a schema is provided and `response.json()` cannot parse the\n * response body.\n * @throws {unknown} Any error thrown or rejected by the provided Standard Schema validator.\n */\nexport const fetchInternal = async (\n input: FetchInput,\n schema: StandardSchemaV1 | undefined,\n options: ExtendedRequestInit | undefined,\n defaults: FetchDefaults\n): Promise<unknown> => {\n const request = normalizeRequest(input, options);\n const { init, searchParams, throwOnFetchError, throwOnValidationError } =\n prepareRequestInit(request.options, defaults);\n const url = resolveRequestUrl(request.url, defaults, searchParams);\n const response = request.request\n ? await fetch(new Request(url, request.request), init)\n : 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 if (schema === undefined) {\n return response;\n }\n\n const raw: unknown = await response.json();\n if (throwOnValidationError) {\n return await standardValidate(schema, raw, { throwOnError: true });\n }\n return await standardValidate(schema, raw, { throwOnError: false });\n};\n","/**\n * Method helper factories used to build verb-specific fetch functions.\n *\n * @module @zap-studio/fetch/_methods (private)\n */\n\nimport { isStandardSchema } from \"@zap-studio/validation\";\nimport type { StandardSchemaV1 } from \"@zap-studio/validation\";\n\nimport type { $Fetch, ExtendedRequestInit, FetchInput } from \"./types.js\";\n\n/**\n * Creates an HTTP method helper bound to a fetch function.\n *\n * The returned function mirrors `$Fetch` overloads but forces the provided\n * HTTP method (`GET`, `POST`, etc.) into request options.\n *\n * @param fetchFn - Fetch function to wrap.\n * @param method - HTTP method to enforce.\n * @returns Method-bound fetch function.\n * @throws {unknown} Any error thrown or rejected by `fetchFn` when the returned method-bound\n * fetch function is called.\n *\n * @example\n * const get = createMethod($fetch, \"GET\");\n * const user = await get(\"/users/1\", UserSchema);\n */\nexport const createMethod = (fetchFn: $Fetch, method: string): $Fetch => {\n function methodFetch<TSchema extends StandardSchemaV1>(\n input: FetchInput,\n schema: TSchema,\n options: ExtendedRequestInit & {\n throwOnValidationError: false;\n }\n ): Promise<StandardSchemaV1.Result<StandardSchemaV1.InferOutput<TSchema>>>;\n\n function methodFetch<TSchema extends StandardSchemaV1>(\n input: FetchInput,\n schema: TSchema,\n options?: ExtendedRequestInit & {\n throwOnValidationError?: true;\n }\n ): Promise<StandardSchemaV1.InferOutput<TSchema>>;\n\n function methodFetch(\n input: FetchInput,\n options?: ExtendedRequestInit\n ): Promise<Response>;\n\n /**\n * Method-bound `$Fetch` implementation.\n *\n * Resolves schema/option overloads and injects the configured HTTP method.\n */\n async function methodFetch(\n input: FetchInput,\n schemaOrOptions?: StandardSchemaV1 | ExtendedRequestInit,\n optionsOrUndefined?: ExtendedRequestInit\n ): Promise<unknown> {\n if (isStandardSchema(schemaOrOptions)) {\n if (optionsOrUndefined?.throwOnValidationError === false) {\n return await fetchFn(input, schemaOrOptions, {\n ...optionsOrUndefined,\n method,\n throwOnValidationError: false,\n });\n }\n\n const { throwOnValidationError, ...restOptions } =\n optionsOrUndefined ?? {};\n\n if (throwOnValidationError === true) {\n return await fetchFn(input, schemaOrOptions, {\n ...restOptions,\n method,\n throwOnValidationError: true,\n });\n }\n\n return await fetchFn(input, schemaOrOptions, {\n ...restOptions,\n method,\n });\n }\n\n return await fetchFn(input, {\n ...schemaOrOptions,\n method,\n });\n }\n\n return methodFetch;\n};\n","/**\n * Typed fetch client: `$fetch`, `api` method shortcuts, and the `createFetch`\n * instance factory.\n *\n * @module @zap-studio/fetch/fetch\n */\n\nimport { isStandardSchema } from \"@zap-studio/validation\";\nimport type { StandardSchemaV1 } from \"@zap-studio/validation\";\n\nimport { fetchInternal } from \"./_internal.js\";\nimport { createMethod } from \"./_methods.js\";\nimport { GLOBAL_DEFAULTS } from \"./constants.js\";\nimport type {\n $Fetch,\n ApiMethods,\n ExtendedRequestInit,\n FetchDefaults,\n FetchInput,\n} from \"./types.js\";\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` is `true` and the response is not ok.\n * @throws {ValidationError} When a schema is provided, validation returns issues, and\n * `throwOnValidationError` is `true`.\n * @throws {TypeError} When both `body` and `json` are provided, when JSON request\n * serialization fails, when request construction fails, when headers/search params are\n * invalid, when `response.json()` cannot read the body, or when the runtime `fetch`\n * implementation rejects network-level failures as `TypeError`.\n * @throws {DOMException} When the runtime rejects an aborted request or response body read\n * as an `AbortError` DOMException.\n * @throws {SyntaxError} When a schema is provided and `response.json()` cannot parse the\n * response body.\n * @throws {unknown} Any error thrown or rejected by the provided Standard Schema validator.\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 input: FetchInput,\n schema: TSchema,\n options: ExtendedRequestInit & { throwOnValidationError: false }\n): Promise<StandardSchemaV1.Result<StandardSchemaV1.InferOutput<TSchema>>>;\n\nexport async function $fetch<TSchema extends StandardSchemaV1>(\n input: FetchInput,\n schema: TSchema,\n options?: ExtendedRequestInit & { throwOnValidationError?: true }\n): Promise<StandardSchemaV1.InferOutput<TSchema>>;\n\nexport async function $fetch(\n input: FetchInput,\n options?: ExtendedRequestInit\n): Promise<Response>;\n\nexport async function $fetch(\n input: FetchInput,\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(input, 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 * Each method has the same throw behavior as {@link $fetch}.\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 delete: createMethod($fetch, \"DELETE\"),\n get: createMethod($fetch, \"GET\"),\n patch: createMethod($fetch, \"PATCH\"),\n post: createMethod($fetch, \"POST\"),\n put: createMethod($fetch, \"PUT\"),\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 * The returned `$fetch` and `api` methods have the same throw behavior as the\n * top-level {@link $fetch} export.\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\", json: { name: \"John\" } });\n */\nexport const createFetch = (\n factoryOptions: Partial<FetchDefaults> = {}\n): {\n $fetch: $Fetch;\n api: ApiMethods;\n} => {\n const defaults: FetchDefaults = {\n ...GLOBAL_DEFAULTS,\n ...factoryOptions,\n baseURL: factoryOptions.baseURL ?? GLOBAL_DEFAULTS.baseURL,\n throwOnFetchError:\n factoryOptions.throwOnFetchError ?? GLOBAL_DEFAULTS.throwOnFetchError,\n throwOnValidationError:\n factoryOptions.throwOnValidationError ??\n GLOBAL_DEFAULTS.throwOnValidationError,\n };\n\n async function customFetch<TSchema extends StandardSchemaV1>(\n input: FetchInput,\n schema: TSchema,\n options: ExtendedRequestInit & { throwOnValidationError: false }\n ): Promise<StandardSchemaV1.Result<StandardSchemaV1.InferOutput<TSchema>>>;\n\n async function customFetch<TSchema extends StandardSchemaV1>(\n input: FetchInput,\n schema: TSchema,\n options?: ExtendedRequestInit & {\n throwOnValidationError?: true;\n }\n ): Promise<StandardSchemaV1.InferOutput<TSchema>>;\n\n async function customFetch(\n input: FetchInput,\n options?: ExtendedRequestInit\n ): Promise<Response>;\n\n async function customFetch(\n input: FetchInput,\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(input, schema, options, defaults);\n }\n\n const customApi = {\n delete: createMethod(customFetch, \"DELETE\"),\n get: createMethod(customFetch, \"GET\"),\n patch: createMethod(customFetch, \"PATCH\"),\n post: createMethod(customFetch, \"POST\"),\n put: createMethod(customFetch, \"PUT\"),\n };\n\n return {\n $fetch: customFetch,\n api: customApi,\n };\n};\n"],"mappings":"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"}
package/dist/fetch.d.ts DELETED
@@ -1,114 +0,0 @@
1
- import { $Fetch, ApiMethods, ExtendedRequestInit, FetchDefaults, FetchInput } from "./types.js";
2
- import { StandardSchemaV1 } from "@zap-studio/validation";
3
- //#region src/fetch.d.ts
4
- /**
5
- * Type-safe fetch wrapper with Standard Schema validation.
6
- *
7
- * - When `throwOnValidationError: true`: validated data of type `TSchema`
8
- * - When `throwOnValidationError: false`: Standard Schema Result object `{ value?, issues? }`
9
- * - When `throwOnFetchError: true`: throws `FetchError` on non-ok responses
10
- *
11
- * If no schema is provided, returns the raw `Response` object.
12
- *
13
- * @throws {FetchError} When `throwOnFetchError` is `true` and the response is not ok.
14
- * @throws {ValidationError} When a schema is provided, validation returns issues, and
15
- * `throwOnValidationError` is `true`.
16
- * @throws {TypeError} When both `body` and `json` are provided, when JSON request
17
- * serialization fails, when request construction fails, when headers/search params are
18
- * invalid, when `response.json()` cannot read the body, or when the runtime `fetch`
19
- * implementation rejects network-level failures as `TypeError`.
20
- * @throws {DOMException} When the runtime rejects an aborted request or response body read
21
- * as an `AbortError` DOMException.
22
- * @throws {SyntaxError} When a schema is provided and `response.json()` cannot parse the
23
- * response body.
24
- * @throws {unknown} Any error thrown or rejected by the provided Standard Schema validator.
25
- *
26
- * @example
27
- * import { z } from "zod";
28
- * import { $fetch } from "@zap-studio/fetch";
29
- *
30
- * const UserSchema = z.object({ id: z.number(), name: z.string() });
31
- *
32
- * // Basic usage (schema validation)
33
- * const user = await $fetch("/api/users/1", UserSchema, { headers: { "Authorization": "Bearer token" } });
34
- * console.log("Validated user:", user);
35
- *
36
- * // Raw usage (no schema validation and typed Response object)
37
- * const result = await $fetch("/api/data", { method: "POST", body: JSON.stringify({ key: "value" }) });
38
- * const json = await result.json() as ResultType;
39
- * console.log("Raw response data:", json);
40
- *
41
- * // Usage with validation errors returned instead of thrown
42
- * const result = await $fetch("/api/users/1", UserSchema, { throwOnValidationError: false });
43
- *
44
- * if (result.issues) {
45
- * console.error("Validation errors:", result.issues);
46
- * } else {
47
- * console.log("Validated user:", result.value);
48
- * }
49
- */
50
- declare function $fetch<TSchema extends StandardSchemaV1>(input: FetchInput, schema: TSchema, options: ExtendedRequestInit & {
51
- throwOnValidationError: false;
52
- }): Promise<StandardSchemaV1.Result<StandardSchemaV1.InferOutput<TSchema>>>;
53
- declare function $fetch<TSchema extends StandardSchemaV1>(input: FetchInput, schema: TSchema, options?: ExtendedRequestInit & {
54
- throwOnValidationError?: true;
55
- }): Promise<StandardSchemaV1.InferOutput<TSchema>>;
56
- declare function $fetch(input: FetchInput, options?: ExtendedRequestInit): Promise<Response>;
57
- /**
58
- * Convenience methods for common HTTP verbs.
59
- *
60
- * These methods always require a schema for validation.
61
- * For raw responses without validation, use `$fetch` directly.
62
- *
63
- * Each method has the same throw behavior as {@link $fetch}.
64
- *
65
- * @example
66
- * import { z } from "zod";
67
- * import { api } from "@zap-studio/fetch";
68
- *
69
- * const PostSchema = z.object({
70
- * id: z.number(),
71
- * title: z.string(),
72
- * content: z.string(),
73
- * });
74
- *
75
- * async function fetchPost(postId: number) {
76
- * const post = await api.get(`https://api.example.com/posts/${postId}`, PostSchema);
77
- * return post; // post is typed as { id: number; title: string; content: string; }
78
- * }
79
- */
80
- declare const api: ApiMethods;
81
- /**
82
- * Creates a custom fetch instance with pre-configured defaults.
83
- *
84
- * Use this factory to create API clients with a base URL, default headers,
85
- * and other shared configuration. Each instance is independent.
86
- *
87
- * The returned `$fetch` and `api` methods have the same throw behavior as the
88
- * top-level {@link $fetch} export.
89
- *
90
- * @example
91
- * import { z } from "zod";
92
- * import { createFetch } from "@zap-studio/fetch";
93
- *
94
- * // Create a configured instance
95
- * const { $fetch, api } = createFetch({
96
- * baseURL: "https://api.example.com",
97
- * headers: { "Authorization": "Bearer token" },
98
- * });
99
- *
100
- * const UserSchema = z.object({ id: z.number(), name: z.string() });
101
- *
102
- * // Now use relative paths - baseURL is prepended automatically
103
- * const user = await api.get("/users/1", UserSchema);
104
- *
105
- * // Or use $fetch directly
106
- * const response = await $fetch("/users", UserSchema, { method: "POST", json: { name: "John" } });
107
- */
108
- declare const createFetch: (factoryOptions?: Partial<FetchDefaults>) => {
109
- $fetch: $Fetch;
110
- api: ApiMethods;
111
- };
112
- //#endregion
113
- export { $fetch, api, createFetch };
114
- //# sourceMappingURL=fetch.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"fetch.d.ts","names":[],"sources":["../src/fetch.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAmEsB,OAAO,gBAAgB,kBAC3C,OAAO,YACP,QAAQ,SACR,SAAS;EAAwB;IAChC,QAAQ,iBAAiB,OAAO,iBAAiB,YAAY;iBAE1C,OAAO,gBAAgB,kBAC3C,OAAO,YACP,QAAQ,SACR,UAAU;EAAwB;IACjC,QAAQ,iBAAiB,YAAY;iBAElB,OACpB,OAAO,YACP,UAAU,sBACT,QAAQ;;;;;;;;;;;;;;;;;;;;;;;;cAqCE,KAAK;;;;;;;;;;;;;;;;;;;;;;;;;;;;cAmCL,cACX,iBAAgB,QAAQ;EAExB,QAAQ;EACR,KAAK"}
package/dist/fetch.js DELETED
@@ -1,3 +0,0 @@
1
- import "./constants.js";
2
- import { n as api, r as createFetch, t as $fetch } from "./fetch-D0IXjsUD.js";
3
- export { $fetch, api, createFetch };
package/dist/headers.d.ts DELETED
@@ -1,26 +0,0 @@
1
- //#region src/headers.d.ts
2
- /**
3
- * Header utility helpers for request normalization and merging.
4
- *
5
- * @module @zap-studio/fetch/headers
6
- */
7
- /**
8
- * Merges two HeadersInit objects, with the second one taking precedence.
9
- *
10
- * @param base - Base/default headers.
11
- * @param override - Request-level override headers.
12
- * @returns A merged `Headers` object, or `undefined` when both inputs are empty.
13
- * @throws {TypeError} When either header input contains invalid header names or values.
14
- *
15
- * @example
16
- * const headers = mergeHeaders(
17
- * { Authorization: "Bearer token" },
18
- * { "X-Trace-Id": "abc" },
19
- * );
20
- *
21
- * console.log(headers?.get("Authorization")); // Bearer token
22
- */
23
- declare const mergeHeaders: (base?: HeadersInit, override?: HeadersInit) => Headers | undefined;
24
- //#endregion
25
- export { mergeHeaders };
26
- //# sourceMappingURL=headers.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"headers.d.ts","names":[],"sources":["../src/headers.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;cAsBa,eACX,OAAO,aACP,WAAW,gBACV"}
package/dist/headers.js DELETED
@@ -1,34 +0,0 @@
1
- //#region src/headers.ts
2
- /**
3
- * Header utility helpers for request normalization and merging.
4
- *
5
- * @module @zap-studio/fetch/headers
6
- */
7
- /**
8
- * Merges two HeadersInit objects, with the second one taking precedence.
9
- *
10
- * @param base - Base/default headers.
11
- * @param override - Request-level override headers.
12
- * @returns A merged `Headers` object, or `undefined` when both inputs are empty.
13
- * @throws {TypeError} When either header input contains invalid header names or values.
14
- *
15
- * @example
16
- * const headers = mergeHeaders(
17
- * { Authorization: "Bearer token" },
18
- * { "X-Trace-Id": "abc" },
19
- * );
20
- *
21
- * console.log(headers?.get("Authorization")); // Bearer token
22
- */
23
- const mergeHeaders = (base, override) => {
24
- if (base === void 0 && override === void 0) return;
25
- if (base === void 0) return new Headers(override);
26
- if (override === void 0) return new Headers(base);
27
- const merged = new Headers(base);
28
- for (const [key, value] of new Headers(override).entries()) merged.set(key, value);
29
- return merged;
30
- };
31
- //#endregion
32
- export { mergeHeaders };
33
-
34
- //# sourceMappingURL=headers.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"headers.js","names":[],"sources":["../src/headers.ts"],"sourcesContent":["/**\n * Header utility helpers for request normalization and merging.\n *\n * @module @zap-studio/fetch/headers\n */\n\n/**\n * Merges two HeadersInit objects, with the second one taking precedence.\n *\n * @param base - Base/default headers.\n * @param override - Request-level override headers.\n * @returns A merged `Headers` object, or `undefined` when both inputs are empty.\n * @throws {TypeError} When either header input contains invalid header names or values.\n *\n * @example\n * const headers = mergeHeaders(\n * { Authorization: \"Bearer token\" },\n * { \"X-Trace-Id\": \"abc\" },\n * );\n *\n * console.log(headers?.get(\"Authorization\")); // Bearer token\n */\nexport const mergeHeaders = (\n base?: HeadersInit,\n override?: HeadersInit\n): Headers | undefined => {\n if (base === undefined && override === undefined) {\n return undefined;\n }\n\n if (base === undefined) {\n return new Headers(override);\n }\n\n if (override === undefined) {\n return new Headers(base);\n }\n\n const merged = new Headers(base);\n for (const [key, value] of new Headers(override).entries()) {\n merged.set(key, value);\n }\n return merged;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAsBA,MAAa,gBACX,MACA,aACwB;CACxB,IAAI,SAAS,KAAA,KAAa,aAAa,KAAA,GACrC;CAGF,IAAI,SAAS,KAAA,GACX,OAAO,IAAI,QAAQ,QAAQ;CAG7B,IAAI,aAAa,KAAA,GACf,OAAO,IAAI,QAAQ,IAAI;CAGzB,MAAM,SAAS,IAAI,QAAQ,IAAI;CAC/B,KAAK,MAAM,CAAC,KAAK,UAAU,IAAI,QAAQ,QAAQ,CAAC,CAAC,QAAQ,GACvD,OAAO,IAAI,KAAK,KAAK;CAEvB,OAAO;AACT"}
package/dist/request.d.ts DELETED
@@ -1,30 +0,0 @@
1
- import { ExtendedRequestInit, FetchInput } from "./types.js";
2
- //#region src/request.d.ts
3
- /**
4
- * Normalized representation used by internal request execution.
5
- *
6
- * - `url`: resolved string URL from the input (string or `URL`; `Request` uses `request.url`)
7
- * - `request`: original Request clone when input is a Request
8
- * - `options`: normalized request options merged with Request headers
9
- */
10
- interface NormalizedRequest {
11
- url: string;
12
- request?: Request;
13
- options: ExtendedRequestInit;
14
- }
15
- /**
16
- * Normalizes fetch `input` and request-level options into a consistent internal shape.
17
- *
18
- * @param input - Request URL/path or Request instance.
19
- * @param options - Optional request options.
20
- * @returns A normalized request structure for internal processing.
21
- * @throws {TypeError} When cloning a `Request` fails or the merged headers are invalid.
22
- *
23
- * @example
24
- * const normalized = normalizeRequest("/users", { method: "GET" });
25
- * console.log(normalized.url); // "/users"
26
- */
27
- declare const normalizeRequest: (input: FetchInput, options?: ExtendedRequestInit) => NormalizedRequest;
28
- //#endregion
29
- export { NormalizedRequest, normalizeRequest };
30
- //# sourceMappingURL=request.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"request.d.ts","names":[],"sources":["../src/request.ts"],"mappings":";;;;;;;;;UAkBiB;EACf;EACA,UAAU;EACV,SAAS;;;;;;;;;;;;;;cAeE,mBACX,OAAO,YACP,UAAU,wBACT"}
package/dist/request.js DELETED
@@ -1,43 +0,0 @@
1
- import { mergeHeaders } from "./headers.js";
2
- //#region src/request.ts
3
- /**
4
- * Request normalization helpers for fetch `input` values.
5
- *
6
- * @module @zap-studio/fetch/request
7
- */
8
- const EMPTY_OPTIONS = {};
9
- /**
10
- * Normalizes fetch `input` and request-level options into a consistent internal shape.
11
- *
12
- * @param input - Request URL/path or Request instance.
13
- * @param options - Optional request options.
14
- * @returns A normalized request structure for internal processing.
15
- * @throws {TypeError} When cloning a `Request` fails or the merged headers are invalid.
16
- *
17
- * @example
18
- * const normalized = normalizeRequest("/users", { method: "GET" });
19
- * console.log(normalized.url); // "/users"
20
- */
21
- const normalizeRequest = (input, options) => {
22
- if (!(input instanceof Request)) {
23
- const url = input instanceof URL ? input.href : input;
24
- return {
25
- options: options ?? EMPTY_OPTIONS,
26
- url
27
- };
28
- }
29
- const request = new Request(input);
30
- const { headers, ...rest } = options ?? {};
31
- const mergedHeaders = mergeHeaders(request.headers, headers);
32
- const normalizedOptions = { ...rest };
33
- if (mergedHeaders !== void 0) normalizedOptions.headers = mergedHeaders;
34
- return {
35
- options: normalizedOptions,
36
- request,
37
- url: request.url
38
- };
39
- };
40
- //#endregion
41
- export { normalizeRequest };
42
-
43
- //# sourceMappingURL=request.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"request.js","names":[],"sources":["../src/request.ts"],"sourcesContent":["/**\n * Request normalization helpers for fetch `input` values.\n *\n * @module @zap-studio/fetch/request\n */\n\nimport { mergeHeaders } from \"./headers.js\";\nimport type { ExtendedRequestInit, FetchInput } from \"./types.js\";\n\nconst EMPTY_OPTIONS = {} as ExtendedRequestInit;\n\n/**\n * Normalized representation used by internal request execution.\n *\n * - `url`: resolved string URL from the input (string or `URL`; `Request` uses `request.url`)\n * - `request`: original Request clone when input is a Request\n * - `options`: normalized request options merged with Request headers\n */\nexport interface NormalizedRequest {\n url: string;\n request?: Request;\n options: ExtendedRequestInit;\n}\n\n/**\n * Normalizes fetch `input` and request-level options into a consistent internal shape.\n *\n * @param input - Request URL/path or Request instance.\n * @param options - Optional request options.\n * @returns A normalized request structure for internal processing.\n * @throws {TypeError} When cloning a `Request` fails or the merged headers are invalid.\n *\n * @example\n * const normalized = normalizeRequest(\"/users\", { method: \"GET\" });\n * console.log(normalized.url); // \"/users\"\n */\nexport const normalizeRequest = (\n input: FetchInput,\n options?: ExtendedRequestInit\n): NormalizedRequest => {\n if (!(input instanceof Request)) {\n const url = input instanceof URL ? input.href : input;\n return {\n options: options ?? EMPTY_OPTIONS,\n url,\n };\n }\n\n const request = new Request(input);\n const { headers, ...rest } = options ?? {};\n const mergedHeaders = mergeHeaders(request.headers, headers);\n const normalizedOptions = { ...rest } as ExtendedRequestInit;\n\n if (mergedHeaders !== undefined) {\n normalizedOptions.headers = mergedHeaders;\n }\n\n return {\n options: normalizedOptions,\n request,\n url: request.url,\n };\n};\n"],"mappings":";;;;;;;AASA,MAAM,gBAAgB,CAAC;;;;;;;;;;;;;AA2BvB,MAAa,oBACX,OACA,YACsB;CACtB,IAAI,EAAE,iBAAiB,UAAU;EAC/B,MAAM,MAAM,iBAAiB,MAAM,MAAM,OAAO;EAChD,OAAO;GACL,SAAS,WAAW;GACpB;EACF;CACF;CAEA,MAAM,UAAU,IAAI,QAAQ,KAAK;CACjC,MAAM,EAAE,SAAS,GAAG,SAAS,WAAW,CAAC;CACzC,MAAM,gBAAgB,aAAa,QAAQ,SAAS,OAAO;CAC3D,MAAM,oBAAoB,EAAE,GAAG,KAAK;CAEpC,IAAI,kBAAkB,KAAA,GACpB,kBAAkB,UAAU;CAG9B,OAAO;EACL,SAAS;EACT;EACA,KAAK,QAAQ;CACf;AACF"}
package/dist/url.d.ts DELETED
@@ -1,26 +0,0 @@
1
- import { ExtendedRequestInit, FetchDefaults } from "./types.js";
2
- //#region src/url.d.ts
3
- /**
4
- * Resolves final request URL by applying baseURL and layered search params.
5
- *
6
- * Search param precedence:
7
- * 1. `defaults.searchParams`
8
- * 2. search params already present in `resourceUrl`
9
- * 3. per-request `searchParams`
10
- *
11
- * @example
12
- * const finalUrl = resolveRequestUrl(
13
- * "/users?page=2",
14
- * { ...defaults, baseURL: "https://api.example.com", searchParams: { locale: "en" } },
15
- * { page: "3" },
16
- * );
17
- * // https://api.example.com/users?locale=en&page=3
18
- *
19
- * @throws {TypeError} When `baseURL` and `resourceUrl` cannot be resolved by
20
- * `URL`, or when default/per-request search params cannot be converted by
21
- * `URLSearchParams`.
22
- */
23
- declare const resolveRequestUrl: (resourceUrl: string, defaults: FetchDefaults, searchParams?: ExtendedRequestInit["searchParams"]) => string;
24
- //#endregion
25
- export { resolveRequestUrl };
26
- //# sourceMappingURL=url.d.ts.map
package/dist/url.d.ts.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"url.d.ts","names":[],"sources":["../src/url.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;cAmFa,oBACX,qBACA,UAAU,eACV,eAAe"}