@zap-studio/fetch 0.5.3 → 0.5.5

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 CHANGED
@@ -1,5 +1,18 @@
1
+ ## @zap-studio/fetch@0.5.5
2
+
3
+ ### Migrate to ultracite lint/format
4
+
5
+ Internal formatting and lint cleanup only. No public API or behavior change.
6
+
1
7
  # @zap-studio/fetch
2
8
 
9
+ ## 0.5.4
10
+
11
+ ### Changed
12
+
13
+ - Added fetch ecosystem benchmarks and grouped benchmark output for easier cross-library comparisons.
14
+ - Applied small internal performance optimizations in request preparation, URL resolution, and header merging without changing public API behavior.
15
+
3
16
  ## 0.5.3
4
17
 
5
18
  ### Changed
package/README.md CHANGED
@@ -107,8 +107,7 @@ const created = await api.post("/api/users", UserSchema, {
107
107
  });
108
108
  ```
109
109
 
110
- In this example, `UserSchema` validates the response from `/api/users`.
111
- The `json` value is the outgoing request body and is not validated by `UserSchema`.
110
+ In this example, `UserSchema` validates the response from `/api/users`. The `json` value is the outgoing request body and is not validated by `UserSchema`.
112
111
 
113
112
  These helpers set the HTTP method for you. For raw responses without validation, use `$fetch`.
114
113
 
@@ -124,8 +123,7 @@ await api.post("/api/users", UserSchema, {
124
123
  });
125
124
  ```
126
125
 
127
- The schema argument still validates the response. Validate request bodies separately before
128
- passing them to `json` if your application needs outgoing payload validation.
126
+ The schema argument still validates the response. Validate request bodies separately before passing them to `json` if your application needs outgoing payload validation.
129
127
 
130
128
  This sets:
131
129
 
@@ -1,17 +1,16 @@
1
1
  import { FetchDefaults } from "./types.mjs";
2
-
3
2
  //#region src/constants.d.ts
4
3
  /**
5
- * Default options for the global $fetch
6
- *
7
- * These defaults are used by the top-level `$fetch` export.
8
- * Use `createFetch(...)` when you need per-client defaults.
9
- *
10
- * @example
11
- * import { GLOBAL_DEFAULTS } from "@zap-studio/fetch/constants";
12
- *
13
- * console.log(GLOBAL_DEFAULTS.throwOnFetchError); // true
14
- */
4
+ * Default options for the global $fetch
5
+ *
6
+ * These defaults are used by the top-level `$fetch` export.
7
+ * Use `createFetch(...)` when you need per-client defaults.
8
+ *
9
+ * @example
10
+ * import { GLOBAL_DEFAULTS } from "@zap-studio/fetch/constants";
11
+ *
12
+ * console.log(GLOBAL_DEFAULTS.throwOnFetchError); // true
13
+ */
15
14
  declare const GLOBAL_DEFAULTS: FetchDefaults;
16
15
  //#endregion
17
16
  export { GLOBAL_DEFAULTS };
@@ -1 +1 @@
1
- {"version":3,"file":"constants.d.mts","names":[],"sources":["../src/constants.ts"],"mappings":";;;;;;;;;;;;;;cAmBa,eAAA,EAAiB,aAAA"}
1
+ {"version":3,"file":"constants.d.mts","names":[],"sources":["../src/constants.ts"],"mappings":";;;;;;;;;;;;;cAmBa,iBAAiB"}
@@ -1 +1 @@
1
- {"version":3,"file":"constants.mjs","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;CACzB"}
1
+ {"version":3,"file":"constants.mjs","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"}
package/dist/errors.d.mts CHANGED
@@ -1,39 +1,39 @@
1
1
  //#region src/errors.d.ts
2
2
  /**
3
- * Custom error types used by the fetch package.
4
- *
5
- * @module @zap-studio/fetch/errors
6
- */
3
+ * Custom error types used by the fetch package.
4
+ *
5
+ * @module @zap-studio/fetch/errors
6
+ */
7
7
  /**
8
- * Error thrown for HTTP errors (non-2xx responses)
9
- *
10
- * Includes the failing `Response` object and status code for
11
- * downstream error handling and response inspection.
12
- *
13
- * @example
14
- * import { FetchError } from "@zap-studio/fetch/errors";
15
- *
16
- * try {
17
- * await $fetch("/users/404");
18
- * } catch (error) {
19
- * if (error instanceof FetchError) {
20
- * console.error(error.status);
21
- * console.error(await error.response.text());
22
- * }
23
- * }
24
- */
8
+ * Error thrown for HTTP errors (non-2xx responses)
9
+ *
10
+ * Includes the failing `Response` object and status code for
11
+ * downstream error handling and response inspection.
12
+ *
13
+ * @example
14
+ * import { FetchError } from "@zap-studio/fetch/errors";
15
+ *
16
+ * try {
17
+ * await $fetch("/users/404");
18
+ * } catch (error) {
19
+ * if (error instanceof FetchError) {
20
+ * console.error(error.status);
21
+ * console.error(await error.response.text());
22
+ * }
23
+ * }
24
+ */
25
25
  declare class FetchError extends Error {
26
26
  /**
27
- * HTTP status code from the failing response.
28
- */
27
+ * HTTP status code from the failing response.
28
+ */
29
29
  status: Response["status"];
30
30
  /**
31
- * Full response object for additional inspection.
32
- */
31
+ * Full response object for additional inspection.
32
+ */
33
33
  response: Response;
34
34
  /**
35
- * Creates a FetchError from a non-ok response.
36
- */
35
+ * Creates a FetchError from a non-ok response.
36
+ */
37
37
  constructor(message: string, response: Response);
38
38
  }
39
39
  //#endregion
@@ -1 +1 @@
1
- {"version":3,"file":"errors.d.mts","names":[],"sources":["../src/errors.ts"],"mappings":";;AAwBA;;;;;;;;;;;;;;;;;;;;;;cAAa,UAAA,SAAmB,KAAA;;;;EAI9B,MAAA,EAAQ,QAAA;;;;EAIR,QAAA,EAAU,QAAA;;;;EAKV,WAAA,CAAY,OAAA,UAAiB,QAAA,EAAU,QAAA;AAAA"}
1
+ {"version":3,"file":"errors.d.mts","names":[],"sources":["../src/errors.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;cAwBa,mBAAmB;;;;EAI9B,QAAQ;;;;EAIR,UAAU;;;;EAKV,YAAY,iBAAiB,UAAU"}
@@ -1 +1 @@
1
- {"version":3,"file":"errors.mjs","names":[],"sources":["../src/errors.ts"],"sourcesContent":["/**\n * Custom error types used by the fetch package.\n *\n * @module @zap-studio/fetch/errors\n */\n\n/**\n * Error thrown for HTTP errors (non-2xx responses)\n *\n * Includes the failing `Response` object and status code for\n * downstream error handling and response inspection.\n *\n * @example\n * import { FetchError } from \"@zap-studio/fetch/errors\";\n *\n * try {\n * await $fetch(\"/users/404\");\n * } catch (error) {\n * if (error instanceof FetchError) {\n * console.error(error.status);\n * console.error(await error.response.text());\n * }\n * }\n */\nexport class FetchError extends Error {\n /**\n * HTTP status code from the failing response.\n */\n status: Response[\"status\"];\n /**\n * Full response object for additional inspection.\n */\n response: Response;\n\n /**\n * Creates a FetchError from a non-ok response.\n */\n constructor(message: string, response: Response) {\n super(message);\n this.name = \"FetchError\";\n this.status = response.status;\n this.response = response;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAwBA,IAAa,aAAb,cAAgC,MAAM;;;;CAIpC;;;;CAIA;;;;CAKA,YAAY,SAAiB,UAAoB;AAC/C,QAAM,QAAQ;AACd,OAAK,OAAO;AACZ,OAAK,SAAS,SAAS;AACvB,OAAK,WAAW"}
1
+ {"version":3,"file":"errors.mjs","names":[],"sources":["../src/errors.ts"],"sourcesContent":["/**\n * Custom error types used by the fetch package.\n *\n * @module @zap-studio/fetch/errors\n */\n\n/**\n * Error thrown for HTTP errors (non-2xx responses)\n *\n * Includes the failing `Response` object and status code for\n * downstream error handling and response inspection.\n *\n * @example\n * import { FetchError } from \"@zap-studio/fetch/errors\";\n *\n * try {\n * await $fetch(\"/users/404\");\n * } catch (error) {\n * if (error instanceof FetchError) {\n * console.error(error.status);\n * console.error(await error.response.text());\n * }\n * }\n */\nexport class FetchError extends Error {\n /**\n * HTTP status code from the failing response.\n */\n status: Response[\"status\"];\n /**\n * Full response object for additional inspection.\n */\n response: Response;\n\n /**\n * Creates a FetchError from a non-ok response.\n */\n constructor(message: string, response: Response) {\n super(message);\n this.name = \"FetchError\";\n this.status = response.status;\n this.response = response;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAwBA,IAAa,aAAb,cAAgC,MAAM;;;;CAIpC;;;;CAIA;;;;CAKA,YAAY,SAAiB,UAAoB;EAC/C,MAAM,OAAO;EACb,KAAK,OAAO;EACZ,KAAK,SAAS,SAAS;EACvB,KAAK,WAAW;CAClB;AACF"}
@@ -1,26 +1,26 @@
1
1
  //#region src/headers.d.ts
2
2
  /**
3
- * Header utility helpers for request normalization and merging.
4
- *
5
- * @module @zap-studio/fetch/headers
6
- */
3
+ * Header utility helpers for request normalization and merging.
4
+ *
5
+ * @module @zap-studio/fetch/headers
6
+ */
7
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 function mergeHeaders(base?: HeadersInit, override?: HeadersInit): Headers | undefined;
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
24
  //#endregion
25
25
  export { mergeHeaders };
26
26
  //# sourceMappingURL=headers.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"headers.d.mts","names":[],"sources":["../src/headers.ts"],"mappings":";;AAsBA;;;;;;;;;;;;;;;;;;;;iBAAgB,YAAA,CAAa,IAAA,GAAO,WAAA,EAAa,QAAA,GAAW,WAAA,GAAc,OAAA"}
1
+ {"version":3,"file":"headers.d.mts","names":[],"sources":["../src/headers.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;cAsBa,eACX,OAAO,aACP,WAAW,gBACV"}
package/dist/headers.mjs CHANGED
@@ -20,15 +20,14 @@
20
20
  *
21
21
  * console.log(headers?.get("Authorization")); // Bearer token
22
22
  */
23
- function mergeHeaders(base, override) {
24
- if (!(base || override)) return;
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);
25
27
  const merged = new Headers(base);
26
- if (override) {
27
- const overrideHeaders = new Headers(override);
28
- for (const [key, value] of overrideHeaders.entries()) merged.set(key, value);
29
- }
28
+ for (const [key, value] of new Headers(override).entries()) merged.set(key, value);
30
29
  return merged;
31
- }
30
+ };
32
31
  //#endregion
33
32
  export { mergeHeaders };
34
33
 
@@ -1 +1 @@
1
- {"version":3,"file":"headers.mjs","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 function mergeHeaders(base?: HeadersInit, override?: HeadersInit): 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"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAsBA,SAAgB,aAAa,MAAoB,UAA6C;AAC5F,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"}
1
+ {"version":3,"file":"headers.mjs","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/index.d.mts CHANGED
@@ -1,53 +1,52 @@
1
1
  import { $Fetch, ApiMethods, ExtendedRequestInit, FetchDefaults, FetchInput } from "./types.mjs";
2
2
  import { StandardSchemaV1 } from "@zap-studio/validation";
3
-
4
3
  //#region src/index.d.ts
5
4
  /**
6
- * Type-safe fetch wrapper with Standard Schema validation.
7
- *
8
- * - When `throwOnValidationError: true`: validated data of type `TSchema`
9
- * - When `throwOnValidationError: false`: Standard Schema Result object `{ value?, issues? }`
10
- * - When `throwOnFetchError: true`: throws `FetchError` on non-ok responses
11
- *
12
- * If no schema is provided, returns the raw `Response` object.
13
- *
14
- * @throws {FetchError} When `throwOnFetchError` is `true` and the response is not ok.
15
- * @throws {ValidationError} When a schema is provided, validation returns issues, and
16
- * `throwOnValidationError` is `true`.
17
- * @throws {TypeError} When both `body` and `json` are provided, when JSON request
18
- * serialization fails, when request construction fails, when headers/search params are
19
- * invalid, when `response.json()` cannot read the body, or when the runtime `fetch`
20
- * implementation rejects network-level failures as `TypeError`.
21
- * @throws {DOMException} When the runtime rejects an aborted request or response body read
22
- * as an `AbortError` DOMException.
23
- * @throws {SyntaxError} When a schema is provided and `response.json()` cannot parse the
24
- * response body.
25
- * @throws Any error thrown or rejected by the provided Standard Schema validator.
26
- *
27
- * @example
28
- * import { z } from "zod";
29
- * import { $fetch } from "@zap-studio/fetch";
30
- *
31
- * const UserSchema = z.object({ id: z.number(), name: z.string() });
32
- *
33
- * // Basic usage (schema validation)
34
- * const user = await $fetch("/api/users/1", UserSchema, { headers: { "Authorization": "Bearer token" } });
35
- * console.log("Validated user:", user);
36
- *
37
- * // Raw usage (no schema validation and typed Response object)
38
- * const result = await $fetch("/api/data", { method: "POST", body: JSON.stringify({ key: "value" }) });
39
- * const json = await result.json() as ResultType;
40
- * console.log("Raw response data:", json);
41
- *
42
- * // Usage with validation errors returned instead of thrown
43
- * const result = await $fetch("/api/users/1", UserSchema, { throwOnValidationError: false });
44
- *
45
- * if (result.issues) {
46
- * console.error("Validation errors:", result.issues);
47
- * } else {
48
- * console.log("Validated user:", result.value);
49
- * }
50
- */
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
+ */
51
50
  declare function $fetch<TSchema extends StandardSchemaV1>(input: FetchInput, schema: TSchema, options: ExtendedRequestInit & {
52
51
  throwOnValidationError: false;
53
52
  }): Promise<StandardSchemaV1.Result<StandardSchemaV1.InferOutput<TSchema>>>;
@@ -56,57 +55,57 @@ declare function $fetch<TSchema extends StandardSchemaV1>(input: FetchInput, sch
56
55
  }): Promise<StandardSchemaV1.InferOutput<TSchema>>;
57
56
  declare function $fetch(input: FetchInput, options?: ExtendedRequestInit): Promise<Response>;
58
57
  /**
59
- * Convenience methods for common HTTP verbs.
60
- *
61
- * These methods always require a schema for validation.
62
- * For raw responses without validation, use `$fetch` directly.
63
- *
64
- * Each method has the same throw behavior as {@link $fetch}.
65
- *
66
- * @example
67
- * import { z } from "zod";
68
- * import { api } from "@zap-studio/fetch";
69
- *
70
- * const PostSchema = z.object({
71
- * id: z.number(),
72
- * title: z.string(),
73
- * content: z.string(),
74
- * });
75
- *
76
- * async function fetchPost(postId: number) {
77
- * const post = await api.get(`https://api.example.com/posts/${postId}`, PostSchema);
78
- * return post; // post is typed as { id: number; title: string; content: string; }
79
- * }
80
- */
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
+ */
81
80
  declare const api: ApiMethods;
82
81
  /**
83
- * Creates a custom fetch instance with pre-configured defaults.
84
- *
85
- * Use this factory to create API clients with a base URL, default headers,
86
- * and other shared configuration. Each instance is independent.
87
- *
88
- * The returned `$fetch` and `api` methods have the same throw behavior as the
89
- * top-level {@link $fetch} export.
90
- *
91
- * @example
92
- * import { z } from "zod";
93
- * import { createFetch } from "@zap-studio/fetch";
94
- *
95
- * // Create a configured instance
96
- * const { $fetch, api } = createFetch({
97
- * baseURL: "https://api.example.com",
98
- * headers: { "Authorization": "Bearer token" },
99
- * });
100
- *
101
- * const UserSchema = z.object({ id: z.number(), name: z.string() });
102
- *
103
- * // Now use relative paths - baseURL is prepended automatically
104
- * const user = await api.get("/users/1", UserSchema);
105
- *
106
- * // Or use $fetch directly
107
- * const response = await $fetch("/users", UserSchema, { method: "POST", json: { name: "John" } });
108
- */
109
- declare function createFetch(factoryOptions?: Partial<FetchDefaults>): {
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>) => {
110
109
  $fetch: $Fetch;
111
110
  api: ApiMethods;
112
111
  };
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.mts","names":[],"sources":["../src/index.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AA4EA;;;;;;;;;;;;;;;;;;;;;;;;iBANsB,MAAA,iBAAuB,gBAAA,CAAA,CAC3C,KAAA,EAAO,UAAA,EACP,MAAA,EAAQ,OAAA,EACR,OAAA,EAAS,mBAAA;EAAwB,sBAAA;AAAA,IAChC,OAAA,CAAQ,gBAAA,CAAiB,MAAA,CAAO,gBAAA,CAAiB,WAAA,CAAY,OAAA;AAAA,iBAE1C,MAAA,iBAAuB,gBAAA,CAAA,CAC3C,KAAA,EAAO,UAAA,EACP,MAAA,EAAQ,OAAA,EACR,OAAA,GAAU,mBAAA;EAAwB,sBAAA;AAAA,IACjC,OAAA,CAAQ,gBAAA,CAAiB,WAAA,CAAY,OAAA;AAAA,iBAElB,MAAA,CAAO,KAAA,EAAO,UAAA,EAAY,OAAA,GAAU,mBAAA,GAAsB,OAAA,CAAQ,QAAA;;;;;;;;;;;;;;AAqCxF;;;;;AAmCA;;;;;cAnCa,GAAA,EAAK,UAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAmCF,WAAA,CAAY,cAAA,GAAgB,OAAA,CAAQ,aAAA;EAClD,MAAA,EAAQ,MAAA;EACR,GAAA,EAAK,UAAA;AAAA"}
1
+ {"version":3,"file":"index.d.mts","names":[],"sources":["../src/index.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAuEsB,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/index.mjs CHANGED
@@ -41,11 +41,11 @@ async function $fetch(input, schemaOrOptions, optionsOrUndefined) {
41
41
  * }
42
42
  */
43
43
  const api = {
44
+ delete: createMethod($fetch, "DELETE"),
44
45
  get: createMethod($fetch, "GET"),
45
- post: createMethod($fetch, "POST"),
46
- put: createMethod($fetch, "PUT"),
47
46
  patch: createMethod($fetch, "PATCH"),
48
- delete: createMethod($fetch, "DELETE")
47
+ post: createMethod($fetch, "POST"),
48
+ put: createMethod($fetch, "PUT")
49
49
  };
50
50
  /**
51
51
  * Creates a custom fetch instance with pre-configured defaults.
@@ -74,7 +74,7 @@ const api = {
74
74
  * // Or use $fetch directly
75
75
  * const response = await $fetch("/users", UserSchema, { method: "POST", json: { name: "John" } });
76
76
  */
77
- function createFetch(factoryOptions = {}) {
77
+ const createFetch = (factoryOptions = {}) => {
78
78
  const defaults = {
79
79
  ...GLOBAL_DEFAULTS,
80
80
  ...factoryOptions,
@@ -89,14 +89,14 @@ function createFetch(factoryOptions = {}) {
89
89
  return {
90
90
  $fetch: customFetch,
91
91
  api: {
92
+ delete: createMethod(customFetch, "DELETE"),
92
93
  get: createMethod(customFetch, "GET"),
93
- post: createMethod(customFetch, "POST"),
94
- put: createMethod(customFetch, "PUT"),
95
94
  patch: createMethod(customFetch, "PATCH"),
96
- delete: createMethod(customFetch, "DELETE")
95
+ post: createMethod(customFetch, "POST"),
96
+ put: createMethod(customFetch, "PUT")
97
97
  }
98
98
  };
99
- }
99
+ };
100
100
  //#endregion
101
101
  export { $fetch, api, createFetch };
102
102
 
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","names":[],"sources":["../src/index.ts"],"sourcesContent":["/**\n * Public entrypoint for the fetch package.\n *\n * Exposes:\n * - `$fetch` low-level typed fetch function\n * - `api` method shortcuts\n * - `createFetch` instance factory\n *\n * @module @zap-studio/fetch\n */\n\nimport { isStandardSchema, type StandardSchemaV1 } from \"@zap-studio/validation\";\n\nimport { GLOBAL_DEFAULTS } from \"./constants.js\";\nimport { fetchInternal } from \"./internal.js\";\nimport { createMethod } from \"./methods.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 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(input: FetchInput, options?: ExtendedRequestInit): 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 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 * 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 function createFetch(factoryOptions: Partial<FetchDefaults> = {}): {\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: factoryOptions.throwOnFetchError ?? GLOBAL_DEFAULTS.throwOnFetchError,\n throwOnValidationError:\n factoryOptions.throwOnValidationError ?? 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(input: FetchInput, options?: ExtendedRequestInit): 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 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":";;;;;;;;;;;;;;;AAoFA,eAAsB,OACpB,OACA,iBACA,oBACkB;CAClB,MAAM,CAAC,QAAQ,WAAW,iBAAiB,gBAAgB,GACvD,CAAC,iBAAiB,mBAAmB,GACrC,CAAC,KAAA,GAAW,gBAAgB;AAEhC,QAAO,MAAM,cAAc,OAAO,QAAQ,SAAS,gBAAgB;;;;;;;;;;;;;;;;;;;;;;;;;AA0BrE,MAAa,MAAkB;CAC7B,KAAK,aAAa,QAAQ,MAAM;CAChC,MAAM,aAAa,QAAQ,OAAO;CAClC,KAAK,aAAa,QAAQ,MAAM;CAChC,OAAO,aAAa,QAAQ,QAAQ;CACpC,QAAQ,aAAa,QAAQ,SAAS;CACvC;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6BD,SAAgB,YAAY,iBAAyC,EAAE,EAGrE;CACA,MAAM,WAA0B;EAC9B,GAAG;EACH,GAAG;EACH,SAAS,eAAe,WAAW,gBAAgB;EACnD,mBAAmB,eAAe,qBAAqB,gBAAgB;EACvE,wBACE,eAAe,0BAA0B,gBAAgB;EAC5D;CAkBD,eAAe,YACb,OACA,iBACA,oBACkB;EAClB,MAAM,CAAC,QAAQ,WAAW,iBAAiB,gBAAgB,GACvD,CAAC,iBAAiB,mBAAmB,GACrC,CAAC,KAAA,GAAW,gBAAgB;AAEhC,SAAO,MAAM,cAAc,OAAO,QAAQ,SAAS,SAAS;;AAW9D,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":[],"sources":["../src/index.ts"],"sourcesContent":["/**\n * Public entrypoint for the fetch package.\n *\n * Exposes:\n * - `$fetch` low-level typed fetch function\n * - `api` method shortcuts\n * - `createFetch` instance factory\n *\n * @module @zap-studio/fetch\n */\n\nimport { isStandardSchema } from \"@zap-studio/validation\";\nimport type { StandardSchemaV1 } from \"@zap-studio/validation\";\n\nimport { GLOBAL_DEFAULTS } from \"./constants.js\";\nimport { fetchInternal } from \"./internal.js\";\nimport { createMethod } from \"./methods.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":";;;;;;;;;;;;;;;AAwFA,eAAsB,OACpB,OACA,iBACA,oBACkB;CAClB,MAAM,CAAC,QAAQ,WAAW,iBAAiB,eAAe,IACtD,CAAC,iBAAiB,kBAAkB,IACpC,CAAC,KAAA,GAAW,eAAe;CAE/B,OAAO,MAAM,cAAc,OAAO,QAAQ,SAAS,eAAe;AACpE;;;;;;;;;;;;;;;;;;;;;;;;AAyBA,MAAa,MAAkB;CAC7B,QAAQ,aAAa,QAAQ,QAAQ;CACrC,KAAK,aAAa,QAAQ,KAAK;CAC/B,OAAO,aAAa,QAAQ,OAAO;CACnC,MAAM,aAAa,QAAQ,MAAM;CACjC,KAAK,aAAa,QAAQ,KAAK;AACjC;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6BA,MAAa,eACX,iBAAyC,CAAC,MAIvC;CACH,MAAM,WAA0B;EAC9B,GAAG;EACH,GAAG;EACH,SAAS,eAAe,WAAW,gBAAgB;EACnD,mBACE,eAAe,qBAAqB,gBAAgB;EACtD,wBACE,eAAe,0BACf,gBAAgB;CACpB;CAqBA,eAAe,YACb,OACA,iBACA,oBACkB;EAClB,MAAM,CAAC,QAAQ,WAAW,iBAAiB,eAAe,IACtD,CAAC,iBAAiB,kBAAkB,IACpC,CAAC,KAAA,GAAW,eAAe;EAE/B,OAAO,MAAM,cAAc,OAAO,QAAQ,SAAS,QAAQ;CAC7D;CAUA,OAAO;EACL,QAAQ;EACR,KAAK;GATL,QAAQ,aAAa,aAAa,QAAQ;GAC1C,KAAK,aAAa,aAAa,KAAK;GACpC,OAAO,aAAa,aAAa,OAAO;GACxC,MAAM,aAAa,aAAa,MAAM;GACtC,KAAK,aAAa,aAAa,KAAK;EAKvB;CACf;AACF"}
@@ -1,33 +1,32 @@
1
1
  import { ExtendedRequestInit, FetchDefaults, FetchInput } from "./types.mjs";
2
2
  import { StandardSchemaV1 } from "@zap-studio/validation";
3
-
4
3
  //#region src/internal.d.ts
5
4
  /**
6
- * Internal fetch implementation used by both $fetch and createFetch.
7
- *
8
- * This function normalizes request input, resolves final URL + query params,
9
- * executes `fetch`, optionally throws `FetchError`, and optionally validates
10
- * JSON response payloads using Standard Schema.
11
- *
12
- * @param input - Request URL, path, or Request object.
13
- * @param schema - Optional Standard Schema for response validation.
14
- * @param options - Optional request options and package-specific flags.
15
- * @param defaults - Effective client defaults.
16
- * @returns Raw `Response` when no schema is provided; otherwise validated output.
17
- * @throws {FetchError} When `throwOnFetchError` is `true` and the response is not ok.
18
- * @throws {ValidationError} When a schema is provided, validation returns issues, and
19
- * `throwOnValidationError` is `true`.
20
- * @throws {TypeError} When both `body` and `json` are provided, when JSON request
21
- * serialization fails, when request construction fails, when headers/search params are
22
- * invalid, when `response.json()` cannot read the body, or when the runtime `fetch`
23
- * implementation rejects network-level failures as `TypeError`.
24
- * @throws {DOMException} When the runtime rejects an aborted request or response body read
25
- * as an `AbortError` DOMException.
26
- * @throws {SyntaxError} When a schema is provided and `response.json()` cannot parse the
27
- * response body.
28
- * @throws Any error thrown or rejected by the provided Standard Schema validator.
29
- */
30
- declare function fetchInternal(input: FetchInput, schema: StandardSchemaV1 | undefined, options: ExtendedRequestInit | undefined, defaults: FetchDefaults): Promise<unknown>;
5
+ * Internal fetch implementation used by both $fetch and createFetch.
6
+ *
7
+ * This function normalizes request input, resolves final URL + query params,
8
+ * executes `fetch`, optionally throws `FetchError`, and optionally validates
9
+ * JSON response payloads using Standard Schema.
10
+ *
11
+ * @param input - Request URL, path, or Request object.
12
+ * @param schema - Optional Standard Schema for response validation.
13
+ * @param options - Optional request options and package-specific flags.
14
+ * @param defaults - Effective client defaults.
15
+ * @returns Raw `Response` when no schema is provided; otherwise validated output.
16
+ * @throws {FetchError} When `throwOnFetchError` is `true` and the response is not ok.
17
+ * @throws {ValidationError} When a schema is provided, validation returns issues, and
18
+ * `throwOnValidationError` is `true`.
19
+ * @throws {TypeError} When both `body` and `json` are provided, when JSON request
20
+ * serialization fails, when request construction fails, when headers/search params are
21
+ * invalid, when `response.json()` cannot read the body, or when the runtime `fetch`
22
+ * implementation rejects network-level failures as `TypeError`.
23
+ * @throws {DOMException} When the runtime rejects an aborted request or response body read
24
+ * as an `AbortError` DOMException.
25
+ * @throws {SyntaxError} When a schema is provided and `response.json()` cannot parse the
26
+ * response body.
27
+ * @throws {unknown} Any error thrown or rejected by the provided Standard Schema validator.
28
+ */
29
+ declare const fetchInternal: (input: FetchInput, schema: StandardSchemaV1 | undefined, options: ExtendedRequestInit | undefined, defaults: FetchDefaults) => Promise<unknown>;
31
30
  //#endregion
32
31
  export { fetchInternal };
33
32
  //# sourceMappingURL=internal.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"internal.d.mts","names":[],"sources":["../src/internal.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAwCsB,aAAA,CACpB,KAAA,EAAO,UAAA,EACP,MAAA,EAAQ,gBAAA,cACR,OAAA,EAAS,mBAAA,cACT,QAAA,EAAU,aAAA,GACT,OAAA"}
1
+ {"version":3,"file":"internal.d.mts","names":[],"sources":["../src/internal.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;cAoGa,gBACX,OAAO,YACP,QAAQ,8BACR,SAAS,iCACT,UAAU,kBACT"}