@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/dist/internal.mjs CHANGED
@@ -5,6 +5,35 @@ import { resolveRequestUrl } from "./url.mjs";
5
5
  import { standardValidate } from "@zap-studio/validation";
6
6
  //#region src/internal.ts
7
7
  /**
8
+ * Normalizes request-level options into a final RequestInit payload and runtime flags.
9
+ *
10
+ * @param options - Request-level options.
11
+ * @param defaults - Client-level defaults.
12
+ * @returns Fully merged request init payload and effective runtime flags.
13
+ */
14
+ const prepareRequestInit = (options, defaults) => {
15
+ const { headers, json, searchParams, throwOnFetchError = defaults.throwOnFetchError, throwOnValidationError = defaults.throwOnValidationError, ...rest } = options;
16
+ const init = { ...rest };
17
+ const mergedHeaders = mergeHeaders(defaults.headers, headers);
18
+ if (mergedHeaders !== void 0) init.headers = mergedHeaders;
19
+ if (json !== void 0) {
20
+ if (init.body !== void 0 && init.body !== null) throw new TypeError("Cannot provide both `body` and `json`.");
21
+ init.body = JSON.stringify(json);
22
+ if (init.headers === void 0) init.headers = new Headers({ "Content-Type": "application/json" });
23
+ else {
24
+ const requestHeaders = new Headers(init.headers);
25
+ if (!requestHeaders.has("Content-Type")) requestHeaders.set("Content-Type", "application/json");
26
+ init.headers = requestHeaders;
27
+ }
28
+ }
29
+ return {
30
+ init,
31
+ searchParams,
32
+ throwOnFetchError,
33
+ throwOnValidationError
34
+ };
35
+ };
36
+ /**
8
37
  * Internal fetch implementation used by both $fetch and createFetch.
9
38
  *
10
39
  * This function normalizes request input, resolves final URL + query params,
@@ -27,46 +56,19 @@ import { standardValidate } from "@zap-studio/validation";
27
56
  * as an `AbortError` DOMException.
28
57
  * @throws {SyntaxError} When a schema is provided and `response.json()` cannot parse the
29
58
  * response body.
30
- * @throws Any error thrown or rejected by the provided Standard Schema validator.
59
+ * @throws {unknown} Any error thrown or rejected by the provided Standard Schema validator.
31
60
  */
32
- async function fetchInternal(input, schema, options, defaults) {
61
+ const fetchInternal = async (input, schema, options, defaults) => {
33
62
  const request = normalizeRequest(input, options);
34
63
  const { init, searchParams, throwOnFetchError, throwOnValidationError } = prepareRequestInit(request.options, defaults);
35
64
  const url = resolveRequestUrl(request.url, defaults, searchParams);
36
65
  const response = request.request ? await fetch(new Request(url, request.request), init) : await fetch(url, init);
37
66
  if (throwOnFetchError && !response.ok) throw new FetchError(`HTTP ${response.status}: ${response.statusText}`, response);
38
- if (!schema) return response;
67
+ if (schema === void 0) return response;
39
68
  const raw = await response.json();
40
- if (throwOnValidationError) return standardValidate(schema, raw, { throwOnError: true });
41
- return standardValidate(schema, raw, { throwOnError: false });
42
- }
43
- /**
44
- * Normalizes request-level options into a final RequestInit payload and runtime flags.
45
- *
46
- * @param options - Request-level options.
47
- * @param defaults - Client-level defaults.
48
- * @returns Fully merged request init payload and effective runtime flags.
49
- */
50
- function prepareRequestInit(options, defaults) {
51
- const { headers, json, searchParams, throwOnFetchError = defaults.throwOnFetchError, throwOnValidationError = defaults.throwOnValidationError, ...rest } = options;
52
- const init = {
53
- ...rest,
54
- headers: mergeHeaders(defaults.headers, headers)
55
- };
56
- if (json !== void 0) {
57
- if (init.body != null) throw new TypeError("Cannot provide both `body` and `json`.");
58
- init.body = JSON.stringify(json);
59
- const headers = new Headers(init.headers);
60
- if (!headers.has("Content-Type")) headers.set("Content-Type", "application/json");
61
- init.headers = headers;
62
- }
63
- return {
64
- init,
65
- searchParams,
66
- throwOnFetchError,
67
- throwOnValidationError
68
- };
69
- }
69
+ if (throwOnValidationError) return await standardValidate(schema, raw, { throwOnError: true });
70
+ return await standardValidate(schema, raw, { throwOnError: false });
71
+ };
70
72
  //#endregion
71
73
  export { fetchInternal };
72
74
 
@@ -1 +1 @@
1
- {"version":3,"file":"internal.mjs","names":[],"sources":["../src/internal.ts"],"sourcesContent":["/**\n * Internal request execution and option preparation utilities.\n *\n * @module @zap-studio/fetch/internal\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 { ExtendedRequestInit, FetchDefaults, FetchInput } from \"./types.js\";\nimport { resolveRequestUrl } from \"./url.js\";\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 Any error thrown or rejected by the provided Standard Schema validator.\n */\nexport async function fetchInternal(\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 } = prepareRequestInit(\n request.options,\n defaults,\n );\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(`HTTP ${response.status}: ${response.statusText}`, response);\n }\n\n if (!schema) {\n return response;\n }\n\n const raw = await response.json();\n if (throwOnValidationError) {\n return standardValidate(schema, raw, { throwOnError: true });\n }\n return standardValidate(schema, raw, { throwOnError: false });\n}\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 */\nfunction 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 = {\n ...rest,\n headers: mergeHeaders(defaults.headers, headers),\n } as RequestInit;\n\n if (json !== undefined) {\n if (init.body != null) {\n throw new TypeError(\"Cannot provide both `body` and `json`.\");\n }\n\n init.body = JSON.stringify(json);\n const headers = new Headers(init.headers);\n if (!headers.has(\"Content-Type\")) {\n headers.set(\"Content-Type\", \"application/json\");\n }\n init.headers = headers;\n }\n\n return {\n init,\n searchParams,\n throwOnFetchError,\n throwOnValidationError,\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAwCA,eAAsB,cACpB,OACA,QACA,SACA,UACkB;CAClB,MAAM,UAAU,iBAAiB,OAAO,QAAQ;CAChD,MAAM,EAAE,MAAM,cAAc,mBAAmB,2BAA2B,mBACxE,QAAQ,SACR,SACD;CACD,MAAM,MAAM,kBAAkB,QAAQ,KAAK,UAAU,aAAa;CAClE,MAAM,WAAW,QAAQ,UACrB,MAAM,MAAM,IAAI,QAAQ,KAAK,QAAQ,QAAQ,EAAE,KAAK,GACpD,MAAM,MAAM,KAAK,KAAK;AAE1B,KAAI,qBAAqB,CAAC,SAAS,GACjC,OAAM,IAAI,WAAW,QAAQ,SAAS,OAAO,IAAI,SAAS,cAAc,SAAS;AAGnF,KAAI,CAAC,OACH,QAAO;CAGT,MAAM,MAAM,MAAM,SAAS,MAAM;AACjC,KAAI,uBACF,QAAO,iBAAiB,QAAQ,KAAK,EAAE,cAAc,MAAM,CAAC;AAE9D,QAAO,iBAAiB,QAAQ,KAAK,EAAE,cAAc,OAAO,CAAC;;;;;;;;;AAU/D,SAAS,mBACP,SACA,UAMA;CACA,MAAM,EACJ,SACA,MACA,cACA,oBAAoB,SAAS,mBAC7B,yBAAyB,SAAS,wBAClC,GAAG,SACD;CAEJ,MAAM,OAAO;EACX,GAAG;EACH,SAAS,aAAa,SAAS,SAAS,QAAQ;EACjD;AAED,KAAI,SAAS,KAAA,GAAW;AACtB,MAAI,KAAK,QAAQ,KACf,OAAM,IAAI,UAAU,yCAAyC;AAG/D,OAAK,OAAO,KAAK,UAAU,KAAK;EAChC,MAAM,UAAU,IAAI,QAAQ,KAAK,QAAQ;AACzC,MAAI,CAAC,QAAQ,IAAI,eAAe,CAC9B,SAAQ,IAAI,gBAAgB,mBAAmB;AAEjD,OAAK,UAAU;;AAGjB,QAAO;EACL;EACA;EACA;EACA;EACD"}
1
+ {"version":3,"file":"internal.mjs","names":[],"sources":["../src/internal.ts"],"sourcesContent":["/**\n * Internal request execution and option preparation utilities.\n *\n * @module @zap-studio/fetch/internal\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"],"mappings":";;;;;;;;;;;;;AA0BA,MAAM,sBACJ,SACA,aAMG;CACH,MAAM,EACJ,SACA,MACA,cACA,oBAAoB,SAAS,mBAC7B,yBAAyB,SAAS,wBAClC,GAAG,SACD;CAEJ,MAAM,OAAoB,EAAE,GAAG,KAAK;CACpC,MAAM,gBAAgB,aAAa,SAAS,SAAS,OAAO;CAC5D,IAAI,kBAAkB,KAAA,GACpB,KAAK,UAAU;CAGjB,IAAI,SAAS,KAAA,GAAW;EACtB,IAAI,KAAK,SAAS,KAAA,KAAa,KAAK,SAAS,MAC3C,MAAM,IAAI,UAAU,wCAAwC;EAG9D,KAAK,OAAO,KAAK,UAAU,IAAI;EAC/B,IAAI,KAAK,YAAY,KAAA,GACnB,KAAK,UAAU,IAAI,QAAQ,EAAE,gBAAgB,mBAAmB,CAAC;OAC5D;GACL,MAAM,iBAAiB,IAAI,QAAQ,KAAK,OAAO;GAC/C,IAAI,CAAC,eAAe,IAAI,cAAc,GACpC,eAAe,IAAI,gBAAgB,kBAAkB;GAEvD,KAAK,UAAU;EACjB;CACF;CAEA,OAAO;EACL;EACA;EACA;EACA;CACF;AACF;;;;;;;;;;;;;;;;;;;;;;;;;;AA2BA,MAAa,gBAAgB,OAC3B,OACA,QACA,SACA,aACqB;CACrB,MAAM,UAAU,iBAAiB,OAAO,OAAO;CAC/C,MAAM,EAAE,MAAM,cAAc,mBAAmB,2BAC7C,mBAAmB,QAAQ,SAAS,QAAQ;CAC9C,MAAM,MAAM,kBAAkB,QAAQ,KAAK,UAAU,YAAY;CACjE,MAAM,WAAW,QAAQ,UACrB,MAAM,MAAM,IAAI,QAAQ,KAAK,QAAQ,OAAO,GAAG,IAAI,IACnD,MAAM,MAAM,KAAK,IAAI;CAEzB,IAAI,qBAAqB,CAAC,SAAS,IACjC,MAAM,IAAI,WACR,QAAQ,SAAS,OAAO,IAAI,SAAS,cACrC,QACF;CAGF,IAAI,WAAW,KAAA,GACb,OAAO;CAGT,MAAM,MAAe,MAAM,SAAS,KAAK;CACzC,IAAI,wBACF,OAAO,MAAM,iBAAiB,QAAQ,KAAK,EAAE,cAAc,KAAK,CAAC;CAEnE,OAAO,MAAM,iBAAiB,QAAQ,KAAK,EAAE,cAAc,MAAM,CAAC;AACpE"}
@@ -1,23 +1,22 @@
1
1
  import { $Fetch } from "./types.mjs";
2
-
3
2
  //#region src/methods.d.ts
4
3
  /**
5
- * Creates an HTTP method helper bound to a fetch function.
6
- *
7
- * The returned function mirrors `$Fetch` overloads but forces the provided
8
- * HTTP method (`GET`, `POST`, etc.) into request options.
9
- *
10
- * @param fetchFn - Fetch function to wrap.
11
- * @param method - HTTP method to enforce.
12
- * @returns Method-bound fetch function.
13
- * @throws Any error thrown or rejected by `fetchFn` when the returned method-bound
14
- * fetch function is called.
15
- *
16
- * @example
17
- * const get = createMethod($fetch, "GET");
18
- * const user = await get("/users/1", UserSchema);
19
- */
20
- declare function createMethod<TFetch extends $Fetch>(fetchFn: TFetch, method: string): $Fetch;
4
+ * Creates an HTTP method helper bound to a fetch function.
5
+ *
6
+ * The returned function mirrors `$Fetch` overloads but forces the provided
7
+ * HTTP method (`GET`, `POST`, etc.) into request options.
8
+ *
9
+ * @param fetchFn - Fetch function to wrap.
10
+ * @param method - HTTP method to enforce.
11
+ * @returns Method-bound fetch function.
12
+ * @throws {unknown} Any error thrown or rejected by `fetchFn` when the returned method-bound
13
+ * fetch function is called.
14
+ *
15
+ * @example
16
+ * const get = createMethod($fetch, "GET");
17
+ * const user = await get("/users/1", UserSchema);
18
+ */
19
+ declare const createMethod: (fetchFn: $Fetch, method: string) => $Fetch;
21
20
  //#endregion
22
21
  export { createMethod };
23
22
  //# sourceMappingURL=methods.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"methods.d.mts","names":[],"sources":["../src/methods.ts"],"mappings":";;;;;AA0BA;;;;;;;;;;;;;;iBAAgB,YAAA,gBAA4B,MAAA,CAAA,CAAQ,OAAA,EAAS,MAAA,EAAQ,MAAA,WAAiB,MAAA"}
1
+ {"version":3,"file":"methods.d.mts","names":[],"sources":["../src/methods.ts"],"mappings":";;;;;;;;;;;;;;;;;;cA2Ba,eAAgB,SAAS,QAAQ,mBAAiB"}
package/dist/methods.mjs CHANGED
@@ -14,44 +14,44 @@ import { isStandardSchema } from "@zap-studio/validation";
14
14
  * @param fetchFn - Fetch function to wrap.
15
15
  * @param method - HTTP method to enforce.
16
16
  * @returns Method-bound fetch function.
17
- * @throws Any error thrown or rejected by `fetchFn` when the returned method-bound
17
+ * @throws {unknown} Any error thrown or rejected by `fetchFn` when the returned method-bound
18
18
  * fetch function is called.
19
19
  *
20
20
  * @example
21
21
  * const get = createMethod($fetch, "GET");
22
22
  * const user = await get("/users/1", UserSchema);
23
23
  */
24
- function createMethod(fetchFn, method) {
24
+ const createMethod = (fetchFn, method) => {
25
25
  /**
26
26
  * Method-bound `$Fetch` implementation.
27
27
  *
28
28
  * Resolves schema/option overloads and injects the configured HTTP method.
29
29
  */
30
- function methodFetch(input, schemaOrOptions, optionsOrUndefined) {
30
+ async function methodFetch(input, schemaOrOptions, optionsOrUndefined) {
31
31
  if (isStandardSchema(schemaOrOptions)) {
32
- if (optionsOrUndefined?.throwOnValidationError === false) return fetchFn(input, schemaOrOptions, {
32
+ if (optionsOrUndefined?.throwOnValidationError === false) return await fetchFn(input, schemaOrOptions, {
33
33
  ...optionsOrUndefined,
34
34
  method,
35
35
  throwOnValidationError: false
36
36
  });
37
37
  const { throwOnValidationError, ...restOptions } = optionsOrUndefined ?? {};
38
- if (throwOnValidationError === true) return fetchFn(input, schemaOrOptions, {
38
+ if (throwOnValidationError === true) return await fetchFn(input, schemaOrOptions, {
39
39
  ...restOptions,
40
40
  method,
41
41
  throwOnValidationError: true
42
42
  });
43
- return fetchFn(input, schemaOrOptions, {
43
+ return await fetchFn(input, schemaOrOptions, {
44
44
  ...restOptions,
45
45
  method
46
46
  });
47
47
  }
48
- return fetchFn(input, {
48
+ return await fetchFn(input, {
49
49
  ...schemaOrOptions,
50
50
  method
51
51
  });
52
52
  }
53
53
  return methodFetch;
54
- }
54
+ };
55
55
  //#endregion
56
56
  export { createMethod };
57
57
 
@@ -1 +1 @@
1
- {"version":3,"file":"methods.mjs","names":[],"sources":["../src/methods.ts"],"sourcesContent":["/**\n * Method helper factories used to build verb-specific fetch functions.\n *\n * @module @zap-studio/fetch/methods\n */\n\nimport { isStandardSchema, 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 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 function createMethod<TFetch extends $Fetch>(fetchFn: TFetch, 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(input: FetchInput, options?: ExtendedRequestInit): Promise<Response>;\n\n /**\n * Method-bound `$Fetch` implementation.\n *\n * Resolves schema/option overloads and injects the configured HTTP method.\n */\n 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 fetchFn(input, schemaOrOptions, {\n ...optionsOrUndefined,\n method,\n throwOnValidationError: false,\n });\n }\n\n const { throwOnValidationError, ...restOptions } = optionsOrUndefined ?? {};\n\n if (throwOnValidationError === true) {\n return fetchFn(input, schemaOrOptions, {\n ...restOptions,\n method,\n throwOnValidationError: true,\n });\n }\n\n return fetchFn(input, schemaOrOptions, {\n ...restOptions,\n method,\n });\n }\n\n return fetchFn(input, {\n ...schemaOrOptions,\n method,\n });\n }\n\n return methodFetch;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AA0BA,SAAgB,aAAoC,SAAiB,QAAwB;;;;;;CAwB3F,SAAS,YACP,OACA,iBACA,oBACkB;AAClB,MAAI,iBAAiB,gBAAgB,EAAE;AACrC,OAAI,oBAAoB,2BAA2B,MACjD,QAAO,QAAQ,OAAO,iBAAiB;IACrC,GAAG;IACH;IACA,wBAAwB;IACzB,CAAC;GAGJ,MAAM,EAAE,wBAAwB,GAAG,gBAAgB,sBAAsB,EAAE;AAE3E,OAAI,2BAA2B,KAC7B,QAAO,QAAQ,OAAO,iBAAiB;IACrC,GAAG;IACH;IACA,wBAAwB;IACzB,CAAC;AAGJ,UAAO,QAAQ,OAAO,iBAAiB;IACrC,GAAG;IACH;IACD,CAAC;;AAGJ,SAAO,QAAQ,OAAO;GACpB,GAAG;GACH;GACD,CAAC;;AAGJ,QAAO"}
1
+ {"version":3,"file":"methods.mjs","names":[],"sources":["../src/methods.ts"],"sourcesContent":["/**\n * Method helper factories used to build verb-specific fetch functions.\n *\n * @module @zap-studio/fetch/methods\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"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AA2BA,MAAa,gBAAgB,SAAiB,WAA2B;;;;;;CA2BvE,eAAe,YACb,OACA,iBACA,oBACkB;EAClB,IAAI,iBAAiB,eAAe,GAAG;GACrC,IAAI,oBAAoB,2BAA2B,OACjD,OAAO,MAAM,QAAQ,OAAO,iBAAiB;IAC3C,GAAG;IACH;IACA,wBAAwB;GAC1B,CAAC;GAGH,MAAM,EAAE,wBAAwB,GAAG,gBACjC,sBAAsB,CAAC;GAEzB,IAAI,2BAA2B,MAC7B,OAAO,MAAM,QAAQ,OAAO,iBAAiB;IAC3C,GAAG;IACH;IACA,wBAAwB;GAC1B,CAAC;GAGH,OAAO,MAAM,QAAQ,OAAO,iBAAiB;IAC3C,GAAG;IACH;GACF,CAAC;EACH;EAEA,OAAO,MAAM,QAAQ,OAAO;GAC1B,GAAG;GACH;EACF,CAAC;CACH;CAEA,OAAO;AACT"}
@@ -1,31 +1,30 @@
1
1
  import { ExtendedRequestInit, FetchInput } from "./types.mjs";
2
-
3
2
  //#region src/request.d.ts
4
3
  /**
5
- * Normalized representation used by internal request execution.
6
- *
7
- * - `url`: resolved string URL from the input (string or `URL`; `Request` uses `request.url`)
8
- * - `request`: original Request clone when input is a Request
9
- * - `options`: normalized request options merged with Request headers
10
- */
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
+ */
11
10
  interface NormalizedRequest {
12
11
  url: string;
13
12
  request?: Request;
14
13
  options: ExtendedRequestInit;
15
14
  }
16
15
  /**
17
- * Normalizes fetch `input` and request-level options into a consistent internal shape.
18
- *
19
- * @param input - Request URL/path or Request instance.
20
- * @param options - Optional request options.
21
- * @returns A normalized request structure for internal processing.
22
- * @throws {TypeError} When cloning a `Request` fails or the merged headers are invalid.
23
- *
24
- * @example
25
- * const normalized = normalizeRequest("/users", { method: "GET" });
26
- * console.log(normalized.url); // "/users"
27
- */
28
- declare function normalizeRequest(input: FetchInput, options?: ExtendedRequestInit): NormalizedRequest;
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;
29
28
  //#endregion
30
29
  export { NormalizedRequest, normalizeRequest };
31
30
  //# sourceMappingURL=request.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"request.d.mts","names":[],"sources":["../src/request.ts"],"mappings":";;;;;AAgBA;;;;;UAAiB,iBAAA;EACf,GAAA;EACA,OAAA,GAAU,OAAA;EACV,OAAA,EAAS,mBAAA;AAAA;;AAeX;;;;;;;;;;;iBAAgB,gBAAA,CACd,KAAA,EAAO,UAAA,EACP,OAAA,GAAU,mBAAA,GACT,iBAAA"}
1
+ {"version":3,"file":"request.d.mts","names":[],"sources":["../src/request.ts"],"mappings":";;;;;;;;;UAkBiB;EACf;EACA,UAAU;EACV,SAAS;;;;;;;;;;;;;;cAeE,mBACX,OAAO,YACP,UAAU,wBACT"}
package/dist/request.mjs CHANGED
@@ -5,6 +5,7 @@ import { mergeHeaders } from "./headers.mjs";
5
5
  *
6
6
  * @module @zap-studio/fetch/request
7
7
  */
8
+ const EMPTY_OPTIONS = {};
8
9
  /**
9
10
  * Normalizes fetch `input` and request-level options into a consistent internal shape.
10
11
  *
@@ -17,22 +18,25 @@ import { mergeHeaders } from "./headers.mjs";
17
18
  * const normalized = normalizeRequest("/users", { method: "GET" });
18
19
  * console.log(normalized.url); // "/users"
19
20
  */
20
- function normalizeRequest(input, options) {
21
- if (!(input instanceof Request)) return {
22
- url: input instanceof URL ? input.href : input,
23
- options: options ?? {}
24
- };
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
+ }
25
29
  const request = new Request(input);
26
- const { headers, ...rest } = options || {};
30
+ const { headers, ...rest } = options ?? {};
27
31
  const mergedHeaders = mergeHeaders(request.headers, headers);
28
32
  const normalizedOptions = { ...rest };
29
- if (mergedHeaders) normalizedOptions.headers = mergedHeaders;
33
+ if (mergedHeaders !== void 0) normalizedOptions.headers = mergedHeaders;
30
34
  return {
31
- url: request.url,
35
+ options: normalizedOptions,
32
36
  request,
33
- options: normalizedOptions
37
+ url: request.url
34
38
  };
35
- }
39
+ };
36
40
  //#endregion
37
41
  export { normalizeRequest };
38
42
 
@@ -1 +1 @@
1
- {"version":3,"file":"request.mjs","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\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 function 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 url,\n options: options ?? {},\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) {\n normalizedOptions.headers = mergedHeaders;\n }\n\n return {\n url: request.url,\n request,\n options: normalizedOptions,\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAkCA,SAAgB,iBACd,OACA,SACmB;AACnB,KAAI,EAAE,iBAAiB,SAErB,QAAO;EACL,KAFU,iBAAiB,MAAM,MAAM,OAAO;EAG9C,SAAS,WAAW,EAAE;EACvB;CAGH,MAAM,UAAU,IAAI,QAAQ,MAAM;CAClC,MAAM,EAAE,SAAS,GAAG,SAAS,WAAW,EAAE;CAC1C,MAAM,gBAAgB,aAAa,QAAQ,SAAS,QAAQ;CAC5D,MAAM,oBAAoB,EAAE,GAAG,MAAM;AAErC,KAAI,cACF,mBAAkB,UAAU;AAG9B,QAAO;EACL,KAAK,QAAQ;EACb;EACA,SAAS;EACV"}
1
+ {"version":3,"file":"request.mjs","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/types.d.mts CHANGED
@@ -1,9 +1,8 @@
1
1
  import { StandardSchemaV1 } from "@zap-studio/validation";
2
-
3
2
  //#region src/types.d.ts
4
3
  /**
5
- * Accepted `fetch` input type (`string`, `URL`, or `Request`).
6
- */
4
+ * Accepted `fetch` input type (`string`, `URL`, or `Request`).
5
+ */
7
6
  type FetchInput = Parameters<typeof fetch>[0];
8
7
  type URLSearchParamsInput = ConstructorParameters<typeof URLSearchParams>[0];
9
8
  type RequestBodyInit = RequestInit & {
@@ -11,157 +10,157 @@ type RequestBodyInit = RequestInit & {
11
10
  };
12
11
  type JsonBodyInit = Omit<RequestInit, "body"> & {
13
12
  /**
14
- * JSON body convenience. When provided, this is JSON-stringified into `body`.
15
- * @default undefined
16
- */
13
+ * JSON body convenience. When provided, this is JSON-stringified into `body`.
14
+ * @default undefined
15
+ */
17
16
  json: unknown;
18
17
  body?: never;
19
18
  };
20
- type CustomRequestInit = {
19
+ interface CustomRequestInit {
21
20
  /**
22
- * Per-request query/search params
23
- * @default undefined
24
- */
21
+ * Per-request query/search params
22
+ * @default undefined
23
+ */
25
24
  searchParams?: URLSearchParamsInput;
26
25
  /**
27
- * Whether to throw a FetchError on HTTP errors (non-2xx responses)
28
- * @default true
29
- */
26
+ * Whether to throw a FetchError on HTTP errors (non-2xx responses)
27
+ * @default true
28
+ */
30
29
  throwOnFetchError?: boolean;
31
30
  /**
32
- * Whether to throw a ValidationError on validation errors
33
- * @default true
34
- */
31
+ * Whether to throw a ValidationError on validation errors
32
+ * @default true
33
+ */
35
34
  throwOnValidationError?: boolean;
36
- };
35
+ }
37
36
  /**
38
- * Extended RequestInit type to include custom fetch options
39
- *
40
- * @example
41
- * const options: ExtendedRequestInit = {
42
- * method: "POST",
43
- * json: { name: "Ada" },
44
- * throwOnFetchError: true,
45
- * };
46
- */
37
+ * Extended RequestInit type to include custom fetch options
38
+ *
39
+ * @example
40
+ * const options: ExtendedRequestInit = {
41
+ * method: "POST",
42
+ * json: { name: "Ada" },
43
+ * throwOnFetchError: true,
44
+ * };
45
+ */
47
46
  type ExtendedRequestInit = (RequestBodyInit | JsonBodyInit) & CustomRequestInit;
48
47
  /**
49
- * Internal defaults used by fetchInternal
50
- *
51
- * @example
52
- * const defaults: FetchDefaults = {
53
- * baseURL: "https://api.example.com",
54
- * throwOnFetchError: true,
55
- * throwOnValidationError: true,
56
- * };
57
- */
48
+ * Internal defaults used by fetchInternal
49
+ *
50
+ * @example
51
+ * const defaults: FetchDefaults = {
52
+ * baseURL: "https://api.example.com",
53
+ * throwOnFetchError: true,
54
+ * throwOnValidationError: true,
55
+ * };
56
+ */
58
57
  interface FetchDefaults {
59
58
  /**
60
- * Base URL to prepend to all requests
61
- * @default ""
62
- */
59
+ * Base URL to prepend to all requests
60
+ * @default ""
61
+ */
63
62
  baseURL: string;
64
63
  /**
65
- * Default headers to include in all requests (can be overridden per request)
66
- * @default undefined
67
- */
64
+ * Default headers to include in all requests (can be overridden per request)
65
+ * @default undefined
66
+ */
68
67
  headers?: HeadersInit;
69
68
  /**
70
- * Default query/search params applied to every request (can be overridden per request)
71
- * @default undefined
72
- */
69
+ * Default query/search params applied to every request (can be overridden per request)
70
+ * @default undefined
71
+ */
73
72
  searchParams?: URLSearchParamsInput;
74
73
  /**
75
- * Whether to throw a `FetchError` on HTTP errors (non-2xx responses)
76
- * @default true
77
- */
74
+ * Whether to throw a `FetchError` on HTTP errors (non-2xx responses)
75
+ * @default true
76
+ */
78
77
  throwOnFetchError: boolean;
79
78
  /**
80
- * Whether to throw a `ValidationError` on validation errors
81
- * @default true
82
- */
79
+ * Whether to throw a `ValidationError` on validation errors
80
+ * @default true
81
+ */
83
82
  throwOnValidationError: boolean;
84
83
  }
85
84
  /**
86
- * Type-safe fetch function with Standard Schema validation support
87
- */
85
+ * Type-safe fetch function with Standard Schema validation support
86
+ */
88
87
  interface $Fetch {
89
88
  /**
90
- * Fetch with schema validation and throwOnValidationError: false
91
- * @param input - URL or path to fetch
92
- * @param schema - Standard Schema for response validation
93
- * @param options - Extended request options with throwOnValidationError: false
94
- * @returns Standard Schema Result object with value or issues
95
- * @throws {FetchError} When `throwOnFetchError` is `true` and the response is not ok.
96
- * @throws {TypeError} When request construction, JSON request serialization, headers,
97
- * search params, native `fetch`, or `response.json()` body reading fail with a
98
- * `TypeError`.
99
- * @throws {DOMException} When native `fetch` or `response.json()` rejects an aborted
100
- * request/body read as an `AbortError` DOMException.
101
- * @throws {SyntaxError} When `response.json()` cannot parse the response body.
102
- * @throws Any error thrown or rejected by the provided Standard Schema validator.
103
- */
89
+ * Fetch with schema validation and throwOnValidationError: false
90
+ * @param input - URL or path to fetch
91
+ * @param schema - Standard Schema for response validation
92
+ * @param options - Extended request options with throwOnValidationError: false
93
+ * @returns Standard Schema Result object with value or issues
94
+ * @throws {FetchError} When `throwOnFetchError` is `true` and the response is not ok.
95
+ * @throws {TypeError} When request construction, JSON request serialization, headers,
96
+ * search params, native `fetch`, or `response.json()` body reading fail with a
97
+ * `TypeError`.
98
+ * @throws {DOMException} When native `fetch` or `response.json()` rejects an aborted
99
+ * request/body read as an `AbortError` DOMException.
100
+ * @throws {SyntaxError} When `response.json()` cannot parse the response body.
101
+ * @throws {unknown} Any error thrown or rejected by the provided Standard Schema validator.
102
+ */
104
103
  <TSchema extends StandardSchemaV1>(input: FetchInput, schema: TSchema, options: ExtendedRequestInit & {
105
104
  throwOnValidationError: false;
106
105
  }): Promise<StandardSchemaV1.Result<StandardSchemaV1.InferOutput<TSchema>>>;
107
106
  /**
108
- * Fetch with schema validation and throwOnValidationError: true or undefined (default)
109
- * @param input - URL or path to fetch
110
- * @param schema - Standard Schema for response validation
111
- * @param options - Extended request options
112
- * @returns Validated data of type TSchema
113
- * @throws {FetchError} When `throwOnFetchError` is `true` and the response is not ok.
114
- * @throws {ValidationError} When validation returns issues.
115
- * @throws {TypeError} When request construction, JSON request serialization, headers,
116
- * search params, native `fetch`, or `response.json()` body reading fail with a
117
- * `TypeError`.
118
- * @throws {DOMException} When native `fetch` or `response.json()` rejects an aborted
119
- * request/body read as an `AbortError` DOMException.
120
- * @throws {SyntaxError} When `response.json()` cannot parse the response body.
121
- * @throws Any error thrown or rejected by the provided Standard Schema validator.
122
- */
107
+ * Fetch with schema validation and throwOnValidationError: true or undefined (default)
108
+ * @param input - URL or path to fetch
109
+ * @param schema - Standard Schema for response validation
110
+ * @param options - Extended request options
111
+ * @returns Validated data of type TSchema
112
+ * @throws {FetchError} When `throwOnFetchError` is `true` and the response is not ok.
113
+ * @throws {ValidationError} When validation returns issues.
114
+ * @throws {TypeError} When request construction, JSON request serialization, headers,
115
+ * search params, native `fetch`, or `response.json()` body reading fail with a
116
+ * `TypeError`.
117
+ * @throws {DOMException} When native `fetch` or `response.json()` rejects an aborted
118
+ * request/body read as an `AbortError` DOMException.
119
+ * @throws {SyntaxError} When `response.json()` cannot parse the response body.
120
+ * @throws {unknown} Any error thrown or rejected by the provided Standard Schema validator.
121
+ */
123
122
  <TSchema extends StandardSchemaV1>(input: FetchInput, schema: TSchema, options?: ExtendedRequestInit & {
124
123
  throwOnValidationError?: true;
125
124
  }): Promise<StandardSchemaV1.InferOutput<TSchema>>;
126
125
  /**
127
- * Fetch without schema validation
128
- * @param input - URL or path to fetch
129
- * @param options - Extended request options
130
- * @returns Raw Response object
131
- * @throws {FetchError} When `throwOnFetchError` is `true` and the response is not ok.
132
- * @throws {TypeError} When request construction, JSON request serialization, headers,
133
- * search params, or native `fetch` fail with a `TypeError`.
134
- * @throws {DOMException} When native `fetch` rejects an aborted request as an
135
- * `AbortError` DOMException.
136
- */
126
+ * Fetch without schema validation
127
+ * @param input - URL or path to fetch
128
+ * @param options - Extended request options
129
+ * @returns Raw Response object
130
+ * @throws {FetchError} When `throwOnFetchError` is `true` and the response is not ok.
131
+ * @throws {TypeError} When request construction, JSON request serialization, headers,
132
+ * search params, or native `fetch` fail with a `TypeError`.
133
+ * @throws {DOMException} When native `fetch` rejects an aborted request as an
134
+ * `AbortError` DOMException.
135
+ */
137
136
  (input: FetchInput, options?: ExtendedRequestInit): Promise<Response>;
138
137
  }
139
138
  /**
140
- * API HTTP method-specific fetch functions
141
- *
142
- * @example
143
- * const user = await api.get("/users/1", UserSchema);
144
- */
139
+ * API HTTP method-specific fetch functions
140
+ *
141
+ * @example
142
+ * const user = await api.get("/users/1", UserSchema);
143
+ */
145
144
  interface ApiMethods {
146
145
  /**
147
- * DELETE method fetch function
148
- */
146
+ * DELETE method fetch function
147
+ */
149
148
  delete: $Fetch;
150
149
  /**
151
- * GET method fetch function
152
- */
150
+ * GET method fetch function
151
+ */
153
152
  get: $Fetch;
154
153
  /**
155
- * PATCH method fetch function
156
- */
154
+ * PATCH method fetch function
155
+ */
157
156
  patch: $Fetch;
158
157
  /**
159
- * POST method fetch function
160
- */
158
+ * POST method fetch function
159
+ */
161
160
  post: $Fetch;
162
161
  /**
163
- * PUT method fetch function
164
- */
162
+ * PUT method fetch function
163
+ */
165
164
  put: $Fetch;
166
165
  }
167
166
  //#endregion