@zap-studio/fetch 0.4.7 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. package/CHANGELOG.md +38 -0
  2. package/LICENSE +1 -1
  3. package/README.md +276 -32
  4. package/dist/constants.d.mts +8 -1
  5. package/dist/constants.d.mts.map +1 -1
  6. package/dist/constants.mjs +9 -2
  7. package/dist/constants.mjs.map +1 -1
  8. package/dist/errors.d.mts +29 -0
  9. package/dist/errors.d.mts.map +1 -1
  10. package/dist/errors.mjs +46 -2
  11. package/dist/errors.mjs.map +1 -0
  12. package/dist/headers.d.mts +26 -0
  13. package/dist/headers.d.mts.map +1 -0
  14. package/dist/headers.mjs +35 -0
  15. package/dist/headers.mjs.map +1 -0
  16. package/dist/index.d.mts +28 -10
  17. package/dist/index.d.mts.map +1 -1
  18. package/dist/index.mjs +23 -8
  19. package/dist/index.mjs.map +1 -1
  20. package/dist/internal.d.mts +33 -0
  21. package/dist/internal.d.mts.map +1 -0
  22. package/dist/internal.mjs +73 -0
  23. package/dist/internal.mjs.map +1 -0
  24. package/dist/methods.d.mts +23 -0
  25. package/dist/methods.d.mts.map +1 -0
  26. package/dist/methods.mjs +53 -0
  27. package/dist/methods.mjs.map +1 -0
  28. package/dist/request.d.mts +31 -0
  29. package/dist/request.d.mts.map +1 -0
  30. package/dist/request.mjs +39 -0
  31. package/dist/request.mjs.map +1 -0
  32. package/dist/types.d.mts +73 -47
  33. package/dist/types.d.mts.map +1 -1
  34. package/dist/types.mjs +1 -1
  35. package/dist/url.d.mts +27 -0
  36. package/dist/url.d.mts.map +1 -0
  37. package/dist/url.mjs +56 -0
  38. package/dist/url.mjs.map +1 -0
  39. package/package.json +46 -53
  40. package/bin/intent.js +0 -4
  41. package/dist/errors-DQfwnwmz.mjs +0 -18
  42. package/dist/errors-DQfwnwmz.mjs.map +0 -1
  43. package/dist/utils.d.mts +0 -33
  44. package/dist/utils.d.mts.map +0 -1
  45. package/dist/utils.mjs +0 -180
  46. package/dist/utils.mjs.map +0 -1
  47. package/skills/zap-fetch-typed-http/SKILL.md +0 -152
package/dist/types.d.mts CHANGED
@@ -1,55 +1,56 @@
1
- import { StandardSchemaV1 } from "@standard-schema/spec";
1
+ import { StandardSchemaV1 } from "@zap-studio/validation";
2
2
 
3
3
  //#region src/types.d.ts
4
-
5
- /**
6
- * Type representing various formats for search parameters
7
- * that can be used in requests.
8
- * Can be a URLSearchParams object, a record of string pairs,
9
- * a query string, or an array of tuples.
10
- */
11
- type SearchParams = URLSearchParams | Record<string, string> | string | [string, string][];
12
- /**
13
- * JSON-serializable value used for request bodies.
14
- */
15
- type JsonValue = string | number | boolean | null | JsonValue[] | {
16
- [key: string]: JsonValue;
4
+ type FetchInput = Parameters<typeof fetch>[0];
5
+ type URLSearchParamsInput = ConstructorParameters<typeof URLSearchParams>[0];
6
+ type RequestBodyInit = RequestInit & {
7
+ json?: never;
17
8
  };
18
- /**
19
- * Request body type accepted by the fetch wrapper.
20
- */
21
- type RequestBody = BodyInit | JsonValue;
22
- /**
23
- * Base extended request options without throwOnValidationError
24
- */
25
- type BaseExtendedRequestInit = Omit<RequestInit, "body"> & {
9
+ type JsonBodyInit = Omit<RequestInit, "body"> & {
26
10
  /**
27
- * Request body - can be a BodyInit value or an object that will be JSON-stringified
11
+ * JSON body convenience. When provided, this is JSON-stringified into `body`.
12
+ * @default undefined
28
13
  */
29
- body?: RequestBody;
14
+ json: unknown;
15
+ body?: never;
16
+ };
17
+ type CustomRequestInit = {
30
18
  /**
31
19
  * Per-request query/search params
32
20
  * @default undefined
33
21
  */
34
- searchParams?: SearchParams;
22
+ searchParams?: URLSearchParamsInput | undefined;
35
23
  /**
36
24
  * Whether to throw a FetchError on HTTP errors (non-2xx responses)
37
25
  * @default true
38
26
  */
39
- throwOnFetchError?: boolean;
40
- };
41
- /**
42
- * Extended RequestInit type to include custom fetch options
43
- */
44
- type ExtendedRequestInit<TThrowOnValidationError extends boolean | undefined = boolean | undefined> = BaseExtendedRequestInit & {
27
+ throwOnFetchError?: boolean | undefined;
45
28
  /**
46
29
  * Whether to throw a ValidationError on validation errors
47
30
  * @default true
48
31
  */
49
- throwOnValidationError?: TThrowOnValidationError;
32
+ throwOnValidationError?: boolean | undefined;
50
33
  };
51
34
  /**
35
+ * Extended RequestInit type to include custom fetch options
36
+ *
37
+ * @example
38
+ * const options: ExtendedRequestInit = {
39
+ * method: "POST",
40
+ * json: { name: "Ada" },
41
+ * throwOnFetchError: true,
42
+ * };
43
+ */
44
+ type ExtendedRequestInit = (RequestBodyInit | JsonBodyInit) & CustomRequestInit;
45
+ /**
52
46
  * Internal defaults used by fetchInternal
47
+ *
48
+ * @example
49
+ * const defaults: FetchDefaults = {
50
+ * baseURL: "https://api.example.com",
51
+ * throwOnFetchError: true,
52
+ * throwOnValidationError: true,
53
+ * };
53
54
  */
54
55
  interface FetchDefaults {
55
56
  /**
@@ -61,12 +62,12 @@ interface FetchDefaults {
61
62
  * Default headers to include in all requests (can be overridden per request)
62
63
  * @default undefined
63
64
  */
64
- headers?: HeadersInit;
65
+ headers?: HeadersInit | undefined;
65
66
  /**
66
67
  * Default query/search params applied to every request (can be overridden per request)
67
68
  * @default undefined
68
69
  */
69
- searchParams?: SearchParams;
70
+ searchParams?: URLSearchParamsInput | undefined;
70
71
  /**
71
72
  * Whether to throw a `FetchError` on HTTP errors (non-2xx responses)
72
73
  * @default true
@@ -79,39 +80,64 @@ interface FetchDefaults {
79
80
  throwOnValidationError: boolean;
80
81
  }
81
82
  /**
82
- * Options for creating a custom fetch instance with `createFetch`
83
- */
84
- type CreateFetchOptions = Partial<FetchDefaults>;
85
- /**
86
83
  * Type-safe fetch function with Standard Schema validation support
87
84
  */
88
85
  interface $Fetch {
89
86
  /**
90
87
  * Fetch with schema validation and throwOnValidationError: false
91
- * @param resource - URL or path to fetch
88
+ * @param input - URL or path to fetch
92
89
  * @param schema - Standard Schema for response validation
93
90
  * @param options - Extended request options with throwOnValidationError: false
94
91
  * @returns Standard Schema Result object with value or issues
95
- */
96
- <TSchema extends StandardSchemaV1>(resource: string, schema: TSchema, options: ExtendedRequestInit<false>): Promise<StandardSchemaV1.Result<StandardSchemaV1.InferOutput<TSchema>>>;
92
+ * @throws {FetchError} When `throwOnFetchError` is `true` and the response is not ok.
93
+ * @throws {TypeError} When request construction, JSON request serialization, headers,
94
+ * search params, native `fetch`, or `response.json()` body reading fail with a
95
+ * `TypeError`.
96
+ * @throws {DOMException} When native `fetch` or `response.json()` rejects an aborted
97
+ * request/body read as an `AbortError` DOMException.
98
+ * @throws {SyntaxError} When `response.json()` cannot parse the response body.
99
+ * @throws Any error thrown or rejected by the provided Standard Schema validator.
100
+ */
101
+ <TSchema extends StandardSchemaV1>(input: FetchInput, schema: TSchema, options: ExtendedRequestInit & {
102
+ throwOnValidationError: false;
103
+ }): Promise<StandardSchemaV1.Result<StandardSchemaV1.InferOutput<TSchema>>>;
97
104
  /**
98
105
  * Fetch with schema validation and throwOnValidationError: true or undefined (default)
99
- * @param resource - URL or path to fetch
106
+ * @param input - URL or path to fetch
100
107
  * @param schema - Standard Schema for response validation
101
108
  * @param options - Extended request options
102
109
  * @returns Validated data of type TSchema
103
- */
104
- <TSchema extends StandardSchemaV1>(resource: string, schema: TSchema, options?: ExtendedRequestInit<true | undefined>): Promise<StandardSchemaV1.InferOutput<TSchema>>;
110
+ * @throws {FetchError} When `throwOnFetchError` is `true` and the response is not ok.
111
+ * @throws {ValidationError} When validation returns issues.
112
+ * @throws {TypeError} When request construction, JSON request serialization, headers,
113
+ * search params, native `fetch`, or `response.json()` body reading fail with a
114
+ * `TypeError`.
115
+ * @throws {DOMException} When native `fetch` or `response.json()` rejects an aborted
116
+ * request/body read as an `AbortError` DOMException.
117
+ * @throws {SyntaxError} When `response.json()` cannot parse the response body.
118
+ * @throws Any error thrown or rejected by the provided Standard Schema validator.
119
+ */
120
+ <TSchema extends StandardSchemaV1>(input: FetchInput, schema: TSchema, options?: ExtendedRequestInit & {
121
+ throwOnValidationError?: true | undefined;
122
+ }): Promise<StandardSchemaV1.InferOutput<TSchema>>;
105
123
  /**
106
124
  * Fetch without schema validation
107
- * @param resource - URL or path to fetch
125
+ * @param input - URL or path to fetch
108
126
  * @param options - Extended request options
109
127
  * @returns Raw Response object
128
+ * @throws {FetchError} When `throwOnFetchError` is `true` and the response is not ok.
129
+ * @throws {TypeError} When request construction, JSON request serialization, headers,
130
+ * search params, or native `fetch` fail with a `TypeError`.
131
+ * @throws {DOMException} When native `fetch` rejects an aborted request as an
132
+ * `AbortError` DOMException.
110
133
  */
111
- (resource: string, options?: ExtendedRequestInit): Promise<Response>;
134
+ (input: FetchInput, options?: ExtendedRequestInit): Promise<Response>;
112
135
  }
113
136
  /**
114
137
  * API HTTP method-specific fetch functions
138
+ *
139
+ * @example
140
+ * const user = await api.get("/users/1", UserSchema);
115
141
  */
116
142
  interface ApiMethods {
117
143
  /**
@@ -136,5 +162,5 @@ interface ApiMethods {
136
162
  put: $Fetch;
137
163
  }
138
164
  //#endregion
139
- export { $Fetch, ApiMethods, CreateFetchOptions, ExtendedRequestInit, FetchDefaults, JsonValue, RequestBody, SearchParams };
165
+ export { $Fetch, ApiMethods, ExtendedRequestInit, FetchDefaults, FetchInput };
140
166
  //# sourceMappingURL=types.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.mts","names":[],"sources":["../src/types.ts"],"sourcesContent":[],"mappings":";;;;;;AAQA;AASA;AAWA;AAAqC;AAKD,KAzBxB,YAAA,GACR,eAwBgC,GAvBhC,MAuBgC,CAAA,MAAA,EAAA,MAAA,CAAA,GAAA,MAAA,GAAA,CAAA,MAAA,EAAA,MAAA,CAAA,EAAA;;;;AASnB,KAzBL,SAAA,GAyBK,MAAA,GAAA,MAAA,GAAA,OAAA,GAAA,IAAA,GApBb,SAoBa,EAAA,GAAA;EAWjB,CAAA,GAAY,EAAA,MAAA,CAAA,EA9BS,SA8BT;AAaZ,CAAA;AA+BA;AAKA;;AAUY,KApFA,WAAA,GAAc,QAoFd,GApFyB,SAoFzB;;;;KA/EP,uBAAA,GAA0B,IAiFD,CAjFM,WAiFN,EAAA,MAAA,CAAA,GAAA;EAAzB;;;EAYS,IAAA,CAAA,EAzFL,WAyFK;EAC4B;;;;EAQmB,YAAA,CAAA,EA7F5C,YA6F4C;EAAR;;AAMrD;;EAQO,iBAAA,CAAA,EAAA,OAAA;CAIE;;;;KApGG,iGAER;;;;;2BAKuB;;;;;UAMV,aAAA;;;;;;;;;;YAUL;;;;;iBAKK;;;;;;;;;;;;;;;KAgBL,kBAAA,GAAqB,QAAQ;;;;UAKxB,MAAA;;;;;;;;mBAQE,4CAEP,kBACC,6BACR,QAAQ,gBAAA,CAAiB,OAAO,gBAAA,CAAiB,YAAY;;;;;;;;mBAS/C,4CAEP,mBACE,wCACT,QAAQ,gBAAA,CAAiB,YAAY;;;;;;;+BAQX,sBAAsB,QAAQ;;;;;UAM5C,UAAA;;;;UAIP;;;;OAIH;;;;SAIE;;;;QAID;;;;OAID"}
1
+ {"version":3,"file":"types.d.mts","names":[],"sources":["../src/types.ts"],"mappings":";;;KAQY,UAAA,GAAa,UAAA,QAAkB,KAAA;AAAA,KAEtC,oBAAA,GAAuB,qBAAA,QAA6B,eAAA;AAAA,KAEpD,eAAA,GAAkB,WAAA;EACrB,IAAA;AAAA;AAAA,KAGG,YAAA,GAAe,IAAA,CAAK,WAAA;EANgC;AAAA;;;EAWvD,IAAA;EACA,IAAA;AAAA;AAAA,KAGG,iBAAA;;;;;EAKH,YAAA,GAAe,oBAAA;;;;AARf;EAaA,iBAAA;;;;;EAKA,sBAAA;AAAA;;;AAaF;;;;;;;;KAAY,mBAAA,IAAuB,eAAA,GAAkB,YAAA,IAAgB,iBAAA;;;;;AAYrE;;;;;;UAAiB,aAAA;;;;;EAKf,OAAA;EAoBA;AAMF;;;EArBE,OAAA,GAAU,WAAA;;;;;EAKV,YAAA,GAAe,oBAAA;;;;;EAKf,iBAAA;;;;;EAKA,sBAAA;AAAA;;;;UAMe,MAAA;;;;;;;;;;;;;;;;mBAgBE,gBAAA,EACf,KAAA,EAAO,UAAA,EACP,MAAA,EAAQ,OAAA,EACR,OAAA,EAAS,mBAAA;IAAwB,sBAAA;EAAA,IAChC,OAAA,CAAQ,gBAAA,CAAiB,MAAA,CAAO,gBAAA,CAAiB,WAAA,CAAY,OAAA;;;;;;;;;;;;;;;;;mBAkB/C,gBAAA,EACf,KAAA,EAAO,UAAA,EACP,MAAA,EAAQ,OAAA,EACR,OAAA,GAAU,mBAAA;IACR,sBAAA;EAAA,IAED,OAAA,CAAQ,gBAAA,CAAiB,WAAA,CAAY,OAAA;EAsBzB;;;;;;;;;;;EAAA,CATd,KAAA,EAAO,UAAA,EAAY,OAAA,GAAU,mBAAA,GAAsB,OAAA,CAAQ,QAAA;AAAA;;;;;;;UAS7C,UAAA;EAoBV;;;EAhBL,MAAA,EAAQ,MAAA;;;;EAIR,GAAA,EAAK,MAAA;;;;EAIL,KAAA,EAAO,MAAA;;;;EAIP,IAAA,EAAM,MAAA;;;;EAIN,GAAA,EAAK,MAAA;AAAA"}
package/dist/types.mjs CHANGED
@@ -1 +1 @@
1
- export { };
1
+ export {};
package/dist/url.d.mts ADDED
@@ -0,0 +1,27 @@
1
+ import { ExtendedRequestInit, FetchDefaults } from "./types.mjs";
2
+
3
+ //#region src/url.d.ts
4
+ /**
5
+ * Resolves final request URL by applying baseURL and layered search params.
6
+ *
7
+ * Search param precedence:
8
+ * 1. `defaults.searchParams`
9
+ * 2. search params already present in `resourceUrl`
10
+ * 3. per-request `searchParams`
11
+ *
12
+ * @example
13
+ * const finalUrl = resolveRequestUrl(
14
+ * "/users?page=2",
15
+ * { ...defaults, baseURL: "https://api.example.com", searchParams: { locale: "en" } },
16
+ * { page: "3" },
17
+ * );
18
+ * // https://api.example.com/users?locale=en&page=3
19
+ *
20
+ * @throws {TypeError} When `baseURL` and `resourceUrl` cannot be resolved by
21
+ * `URL`, or when default/per-request search params cannot be converted by
22
+ * `URLSearchParams`.
23
+ */
24
+ declare function resolveRequestUrl(resourceUrl: string, defaults: FetchDefaults, searchParams: ExtendedRequestInit["searchParams"] | undefined): string;
25
+ //#endregion
26
+ export { resolveRequestUrl };
27
+ //# sourceMappingURL=url.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"url.d.mts","names":[],"sources":["../src/url.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;iBA4BgB,iBAAA,CACd,WAAA,UACA,QAAA,EAAU,aAAA,EACV,YAAA,EAAc,mBAAA"}
package/dist/url.mjs ADDED
@@ -0,0 +1,56 @@
1
+ //#region src/url.ts
2
+ /**
3
+ * Resolves final request URL by applying baseURL and layered search params.
4
+ *
5
+ * Search param precedence:
6
+ * 1. `defaults.searchParams`
7
+ * 2. search params already present in `resourceUrl`
8
+ * 3. per-request `searchParams`
9
+ *
10
+ * @example
11
+ * const finalUrl = resolveRequestUrl(
12
+ * "/users?page=2",
13
+ * { ...defaults, baseURL: "https://api.example.com", searchParams: { locale: "en" } },
14
+ * { page: "3" },
15
+ * );
16
+ * // https://api.example.com/users?locale=en&page=3
17
+ *
18
+ * @throws {TypeError} When `baseURL` and `resourceUrl` cannot be resolved by
19
+ * `URL`, or when default/per-request search params cannot be converted by
20
+ * `URLSearchParams`.
21
+ */
22
+ function resolveRequestUrl(resourceUrl, defaults, searchParams) {
23
+ return resolveSearchParams(defaults.baseURL ? new URL(resourceUrl, ensureTrailingSlash(defaults.baseURL)).toString() : resourceUrl, defaults.searchParams, searchParams);
24
+ }
25
+ /**
26
+ * Resolves search params by applying default params, URL params, then request params.
27
+ */
28
+ function resolveSearchParams(url, defaultSearchParams, searchParams) {
29
+ const hasFragment = url.includes("#");
30
+ const [urlWithoutHash = "", hash = ""] = url.split("#", 2);
31
+ const [pathname = "", urlSearchParams] = urlWithoutHash.split("?", 2);
32
+ const resolvedSearchParams = new URLSearchParams();
33
+ mergeSearchParams(resolvedSearchParams, defaultSearchParams);
34
+ mergeSearchParams(resolvedSearchParams, urlSearchParams);
35
+ mergeSearchParams(resolvedSearchParams, searchParams);
36
+ const resolvedSearch = resolvedSearchParams.toString();
37
+ const fragmentSuffix = hasFragment ? `#${hash}` : "";
38
+ if (!resolvedSearch) return `${pathname}${fragmentSuffix}`;
39
+ return `${pathname}?${resolvedSearch}${fragmentSuffix}`;
40
+ }
41
+ /**
42
+ * Ensures a URL has a trailing slash for relative URL resolution.
43
+ */
44
+ function ensureTrailingSlash(url) {
45
+ return url.endsWith("/") ? url : `${url}/`;
46
+ }
47
+ /**
48
+ * Copies search params into target, overriding duplicate keys.
49
+ */
50
+ function mergeSearchParams(target, source) {
51
+ for (const [key, value] of new URLSearchParams(source)) target.set(key, value);
52
+ }
53
+ //#endregion
54
+ export { resolveRequestUrl };
55
+
56
+ //# sourceMappingURL=url.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"url.mjs","names":[],"sources":["../src/url.ts"],"sourcesContent":["/**\n * URL resolution and query merging utilities.\n *\n * @module\n */\n\nimport type { ExtendedRequestInit, FetchDefaults } from \"./types.js\";\n\n/**\n * Resolves final request URL by applying baseURL and layered search params.\n *\n * Search param precedence:\n * 1. `defaults.searchParams`\n * 2. search params already present in `resourceUrl`\n * 3. per-request `searchParams`\n *\n * @example\n * const finalUrl = resolveRequestUrl(\n * \"/users?page=2\",\n * { ...defaults, baseURL: \"https://api.example.com\", searchParams: { locale: \"en\" } },\n * { page: \"3\" },\n * );\n * // https://api.example.com/users?locale=en&page=3\n *\n * @throws {TypeError} When `baseURL` and `resourceUrl` cannot be resolved by\n * `URL`, or when default/per-request search params cannot be converted by\n * `URLSearchParams`.\n */\nexport function resolveRequestUrl(\n resourceUrl: string,\n defaults: FetchDefaults,\n searchParams: ExtendedRequestInit[\"searchParams\"] | undefined,\n): string {\n const url = defaults.baseURL\n ? new URL(resourceUrl, ensureTrailingSlash(defaults.baseURL)).toString()\n : resourceUrl;\n\n return resolveSearchParams(url, defaults.searchParams, searchParams);\n}\n\n/**\n * Resolves search params by applying default params, URL params, then request params.\n */\nfunction resolveSearchParams(\n url: string,\n defaultSearchParams: FetchDefaults[\"searchParams\"] | undefined,\n searchParams: ExtendedRequestInit[\"searchParams\"] | undefined,\n): string {\n const hasFragment = url.includes(\"#\");\n const [urlWithoutHash = \"\", hash = \"\"] = url.split(\"#\", 2);\n const [pathname = \"\", urlSearchParams] = urlWithoutHash.split(\"?\", 2);\n const resolvedSearchParams = new URLSearchParams();\n\n mergeSearchParams(resolvedSearchParams, defaultSearchParams);\n mergeSearchParams(resolvedSearchParams, urlSearchParams);\n mergeSearchParams(resolvedSearchParams, searchParams);\n\n const resolvedSearch = resolvedSearchParams.toString();\n const fragmentSuffix = hasFragment ? `#${hash}` : \"\";\n\n if (!resolvedSearch) {\n return `${pathname}${fragmentSuffix}`;\n }\n\n return `${pathname}?${resolvedSearch}${fragmentSuffix}`;\n}\n\n/**\n * Ensures a URL has a trailing slash for relative URL resolution.\n */\nfunction ensureTrailingSlash(url: string): string {\n return url.endsWith(\"/\") ? url : `${url}/`;\n}\n\n/**\n * Copies search params into target, overriding duplicate keys.\n */\nfunction mergeSearchParams(\n target: URLSearchParams,\n source: ExtendedRequestInit[\"searchParams\"] | undefined,\n): void {\n for (const [key, value] of new URLSearchParams(source)) {\n target.set(key, value);\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AA4BA,SAAgB,kBACd,aACA,UACA,cACQ;AAKR,QAAO,oBAJK,SAAS,UACjB,IAAI,IAAI,aAAa,oBAAoB,SAAS,QAAQ,CAAC,CAAC,UAAU,GACtE,aAE4B,SAAS,cAAc,aAAa;;;;;AAMtE,SAAS,oBACP,KACA,qBACA,cACQ;CACR,MAAM,cAAc,IAAI,SAAS,IAAI;CACrC,MAAM,CAAC,iBAAiB,IAAI,OAAO,MAAM,IAAI,MAAM,KAAK,EAAE;CAC1D,MAAM,CAAC,WAAW,IAAI,mBAAmB,eAAe,MAAM,KAAK,EAAE;CACrE,MAAM,uBAAuB,IAAI,iBAAiB;AAElD,mBAAkB,sBAAsB,oBAAoB;AAC5D,mBAAkB,sBAAsB,gBAAgB;AACxD,mBAAkB,sBAAsB,aAAa;CAErD,MAAM,iBAAiB,qBAAqB,UAAU;CACtD,MAAM,iBAAiB,cAAc,IAAI,SAAS;AAElD,KAAI,CAAC,eACH,QAAO,GAAG,WAAW;AAGvB,QAAO,GAAG,SAAS,GAAG,iBAAiB;;;;;AAMzC,SAAS,oBAAoB,KAAqB;AAChD,QAAO,IAAI,SAAS,IAAI,GAAG,MAAM,GAAG,IAAI;;;;;AAM1C,SAAS,kBACP,QACA,QACM;AACN,MAAK,MAAM,CAAC,KAAK,UAAU,IAAI,gBAAgB,OAAO,CACpD,QAAO,IAAI,KAAK,MAAM"}
package/package.json CHANGED
@@ -1,80 +1,73 @@
1
1
  {
2
2
  "name": "@zap-studio/fetch",
3
- "version": "0.4.7",
4
- "type": "module",
5
- "license": "MIT",
3
+ "version": "0.5.0",
6
4
  "private": false,
7
- "homepage": "https://www.zapstudio.dev/packages/fetch",
8
- "repository": {
9
- "type": "git",
10
- "url": "https://github.com/zap-studio/monorepo.git",
11
- "directory": "packages/fetch"
12
- },
13
5
  "description": "A type-safe fetch wrapper for HTTP requests with runtime schema validation.",
14
6
  "keywords": [
15
- "fetch",
16
- "type-safe",
17
- "validation",
18
- "schema",
19
- "typescript",
20
- "http",
21
7
  "api",
22
- "zod",
23
- "valibot",
24
8
  "arktype",
25
- "runtime validation",
26
9
  "error handling",
27
- "standard schema",
10
+ "fetch",
11
+ "http",
28
12
  "request",
29
- "response"
13
+ "response",
14
+ "runtime validation",
15
+ "schema",
16
+ "standard schema",
17
+ "type-safe",
18
+ "typescript",
19
+ "valibot",
20
+ "validation",
21
+ "zod"
30
22
  ],
31
- "publishConfig": {
32
- "access": "public"
23
+ "homepage": "https://www.zapstudio.dev/packages/fetch",
24
+ "license": "MIT",
25
+ "repository": {
26
+ "type": "git",
27
+ "url": "git+https://github.com/zap-studio/monorepo.git",
28
+ "directory": "packages/fetch"
33
29
  },
34
30
  "files": [
35
31
  "dist",
36
32
  "CHANGELOG.md",
37
33
  "LICENSE",
38
- "README.md",
39
- "skills",
40
- "bin",
41
- "!skills/_artifacts"
34
+ "README.md"
42
35
  ],
43
- "dependencies": {
44
- "@standard-schema/spec": "^1.1.0",
45
- "@zap-studio/validation": "0.3.2"
46
- },
47
- "devDependencies": {
48
- "@types/node": "^25.0.2",
49
- "@vitest/coverage-v8": "^4.0.15",
50
- "arktype": "^2.1.29",
51
- "tsdown": "^0.18.0",
52
- "typescript": "^5.9.3",
53
- "valibot": "^1.2.0",
54
- "vitest": "^4.0.18",
55
- "zod": "^4.2.0",
56
- "@zap-studio/tsdown-config": "0.0.0",
57
- "@zap-studio/typescript-config": "0.0.0",
58
- "@zap-studio/vitest-config": "0.0.0"
59
- },
36
+ "type": "module",
37
+ "sideEffects": false,
38
+ "types": "./dist/index.d.mts",
60
39
  "exports": {
61
40
  ".": "./dist/index.mjs",
62
41
  "./constants": "./dist/constants.mjs",
63
42
  "./errors": "./dist/errors.mjs",
43
+ "./headers": "./dist/headers.mjs",
44
+ "./internal": "./dist/internal.mjs",
45
+ "./methods": "./dist/methods.mjs",
46
+ "./request": "./dist/request.mjs",
64
47
  "./types": "./dist/types.mjs",
65
- "./utils": "./dist/utils.mjs",
48
+ "./url": "./dist/url.mjs",
66
49
  "./package.json": "./package.json"
67
50
  },
68
- "main": "./dist/index.mjs",
69
- "module": "./dist/index.mjs",
70
- "types": "./dist/index.d.mts",
71
- "bin": {
72
- "intent": "./bin/intent.js"
51
+ "publishConfig": {
52
+ "access": "public"
53
+ },
54
+ "dependencies": {
55
+ "@zap-studio/validation": "0.3.2"
56
+ },
57
+ "devDependencies": {
58
+ "arktype": "^2.2.0",
59
+ "typescript": "^6.0.3",
60
+ "valibot": "^1.3.1",
61
+ "vite-plus": "^0.1.19",
62
+ "zod": "^4.3.6",
63
+ "@zap-studio/typescript": "0.0.0"
64
+ },
65
+ "engines": {
66
+ "node": ">=18.0.0"
73
67
  },
74
68
  "scripts": {
75
- "build": "tsdown --config tsdown.config.ts",
76
- "typecheck": "tsc --noEmit",
77
- "test": "vitest run",
78
- "test:watch": "vitest --watch"
69
+ "build": "vp pack",
70
+ "test": "vp test run",
71
+ "test:watch": "vp test watch"
79
72
  }
80
73
  }
package/bin/intent.js DELETED
@@ -1,4 +0,0 @@
1
- #!/usr/bin/env node
2
- // Auto-generated by @tanstack/intent setup
3
- // Exposes the intent end-user CLI for consumers of this library.
4
- await import("@tanstack/intent/intent-library");
@@ -1,18 +0,0 @@
1
- //#region src/errors.ts
2
- /**
3
- * Error thrown for HTTP errors (non-2xx responses)
4
- */
5
- var FetchError = class extends Error {
6
- status;
7
- response;
8
- constructor(message, response) {
9
- super(message);
10
- this.name = "FetchError";
11
- this.status = response.status;
12
- this.response = response;
13
- }
14
- };
15
-
16
- //#endregion
17
- export { FetchError as t };
18
- //# sourceMappingURL=errors-DQfwnwmz.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"errors-DQfwnwmz.mjs","names":[],"sources":["../src/errors.ts"],"sourcesContent":["/**\n * Error thrown for HTTP errors (non-2xx responses)\n */\nexport class FetchError extends Error {\n status: Response[\"status\"];\n response: 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":";;;;AAGA,IAAa,aAAb,cAAgC,MAAM;CACpC;CACA;CAEA,YAAY,SAAiB,UAAoB;AAC/C,QAAM,QAAQ;AACd,OAAK,OAAO;AACZ,OAAK,SAAS,SAAS;AACvB,OAAK,WAAW"}
package/dist/utils.d.mts DELETED
@@ -1,33 +0,0 @@
1
- import { $Fetch, ExtendedRequestInit, FetchDefaults } from "./types.mjs";
2
- import { StandardSchemaV1 } from "@standard-schema/spec";
3
-
4
- //#region src/utils.d.ts
5
-
6
- /**
7
- * Merges two HeadersInit objects, with the second one taking precedence
8
- *
9
- * @example
10
- * const baseHeaders = { "Authorization": "Bearer token", "Content-Type": "application/json" };
11
- * const overrideHeaders = { "Content-Type": "application/xml", "X-Custom-Header": "value" };
12
- *
13
- * const merged = mergeHeaders(baseHeaders, overrideHeaders);
14
- *
15
- * // Resulting headers:
16
- * // {
17
- * // "Authorization": "Bearer token",
18
- * // "Content-Type": "application/xml",
19
- * // "X-Custom-Header": "value"
20
- * // }
21
- */
22
- declare function mergeHeaders(base: HeadersInit | undefined, override: HeadersInit | undefined): Headers | undefined;
23
- /**
24
- * Internal fetch implementation used by both $fetch and createFetch
25
- */
26
- declare function fetchInternal(resource: string, schema: StandardSchemaV1 | undefined, options: ExtendedRequestInit | undefined, defaults: FetchDefaults): Promise<unknown>;
27
- /**
28
- * Creates an HTTP method helper bound to a fetch function
29
- */
30
- declare function createMethod<TFetch extends $Fetch>(fetchFn: TFetch, method: string): $Fetch;
31
- //#endregion
32
- export { createMethod, fetchInternal, mergeHeaders };
33
- //# sourceMappingURL=utils.d.mts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"utils.d.mts","names":[],"sources":["../src/utils.ts"],"sourcesContent":[],"mappings":";;;;;;;AA0BA;;;;;AAyLA;;;;;;AAiFA;;;AAGG,iBA7Qa,YAAA,CA6Qb,IAAA,EA5QK,WA4QL,GAAA,SAAA,EAAA,QAAA,EA3QS,WA2QT,GAAA,SAAA,CAAA,EA1QA,OA0QA,GAAA,SAAA;;;;iBApFmB,aAAA,2BAEZ,uCACC,2CACC,gBACT;;;;iBA4Ea,4BAA4B,iBACjC,yBAER"}