make-service 4.0.0 → 4.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -496,7 +496,7 @@ This little library has plenty of other useful functions that you can use to bui
496
496
  ## addQueryToURL
497
497
  It receives a URL instance or URL string and an object-like query and returns a new URL with the query appended to it.
498
498
 
499
- It will preserve the original query if it exists and will also preserve the type of the given URL.
499
+ It will preserve the original query if it exists and will also preserve the type of the given URL. When a `URL` object is provided, the original instance is left untouched and a new one is returned.
500
500
 
501
501
  ```ts
502
502
  import { addQueryToURL } from 'make-service'
@@ -510,17 +510,17 @@ addQueryToURL(
510
510
  )
511
511
  // https://example.com/api/users?role=admin&page=2
512
512
 
513
- addQueryToURL(
514
- new URL("https://example.com/api/users"),
515
- { page: "2" },
516
- )
513
+ const url = new URL("https://example.com/api/users")
514
+ addQueryToURL(url, { page: "2" })
517
515
  // https://example.com/api/users?page=2
516
+ url.toString()
517
+ // 'https://example.com/api/users'
518
518
 
519
- addQueryToURL(
520
- new URL("https://example.com/api/users?role=admin"),
521
- { page: "2" },
522
- )
519
+ const urlWithRole = new URL("https://example.com/api/users?role=admin")
520
+ addQueryToURL(urlWithRole, { page: "2" })
523
521
  // https://example.com/api/users?role=admin&page=2
522
+ urlWithRole.toString()
523
+ // 'https://example.com/api/users?role=admin'
524
524
  ```
525
525
 
526
526
  ## ensureStringBody
package/dist/index.d.mts CHANGED
@@ -1,5 +1,4 @@
1
- import { StandardSchemaV1 } from 'zod/lib/standard-schema';
2
- import { StandardSchemaV1 as StandardSchemaV1$1 } from '@standard-schema/spec';
1
+ import { StandardSchemaV1 } from '@standard-schema/spec';
3
2
 
4
3
  declare const HTTP_METHODS: readonly ["GET", "POST", "PUT", "DELETE", "PATCH", "OPTIONS", "HEAD", "CONNECT"];
5
4
 
@@ -28,8 +27,8 @@ type BaseOptions = {
28
27
  responseTransformer?: ResponseTransformer;
29
28
  };
30
29
  type HTTPMethod = (typeof HTTP_METHODS)[number];
31
- type TypedResponseJson = <T = unknown>(schema?: StandardSchemaV1<T>) => Promise<T>;
32
- type TypedResponseText = <T extends string = string>(schema?: StandardSchemaV1<T>) => Promise<T>;
30
+ type TypedResponseJson = <Input = unknown, Output = Input>(schema?: StandardSchemaV1<Input, Output>) => Promise<Output>;
31
+ type TypedResponseText = <Input extends string = string, Output = Input>(schema?: StandardSchemaV1<Input, Output>) => Promise<Output>;
33
32
  type GetJson = (response: Response) => TypedResponseJson;
34
33
  type GetText = (response: Response) => TypedResponseText;
35
34
  type Prettify<T> = {
@@ -144,8 +143,8 @@ declare function typeOf(t: unknown): "array" | "arraybuffer" | "bigint" | "blob"
144
143
  * Error thrown when the response cannot be parsed.
145
144
  */
146
145
  declare class ParseResponseError extends Error {
147
- issues: readonly StandardSchemaV1$1.Issue[];
148
- constructor(message: string, issues: readonly StandardSchemaV1$1.Issue[]);
146
+ issues: readonly StandardSchemaV1.Issue[];
147
+ constructor(message: string, issues: readonly StandardSchemaV1.Issue[]);
149
148
  }
150
149
 
151
150
  export { type BaseOptions, type EnhancedRequestInit, type GetJson, type GetText, type HTTPMethod, type JSONValue, ParseResponseError, type PathParams, type RequestTransformer, type ResponseTransformer, type SearchParams, type ServiceRequestInit, type TypedResponse, type TypedResponseJson, type TypedResponseText, addQueryToURL, enhancedFetch, ensureStringBody, makeFetcher, makeGetApiURL, makeService, mergeHeaders, replaceURLParams, typeOf, typedResponse };
package/dist/index.d.ts CHANGED
@@ -1,5 +1,4 @@
1
- import { StandardSchemaV1 } from 'zod/lib/standard-schema';
2
- import { StandardSchemaV1 as StandardSchemaV1$1 } from '@standard-schema/spec';
1
+ import { StandardSchemaV1 } from '@standard-schema/spec';
3
2
 
4
3
  declare const HTTP_METHODS: readonly ["GET", "POST", "PUT", "DELETE", "PATCH", "OPTIONS", "HEAD", "CONNECT"];
5
4
 
@@ -28,8 +27,8 @@ type BaseOptions = {
28
27
  responseTransformer?: ResponseTransformer;
29
28
  };
30
29
  type HTTPMethod = (typeof HTTP_METHODS)[number];
31
- type TypedResponseJson = <T = unknown>(schema?: StandardSchemaV1<T>) => Promise<T>;
32
- type TypedResponseText = <T extends string = string>(schema?: StandardSchemaV1<T>) => Promise<T>;
30
+ type TypedResponseJson = <Input = unknown, Output = Input>(schema?: StandardSchemaV1<Input, Output>) => Promise<Output>;
31
+ type TypedResponseText = <Input extends string = string, Output = Input>(schema?: StandardSchemaV1<Input, Output>) => Promise<Output>;
33
32
  type GetJson = (response: Response) => TypedResponseJson;
34
33
  type GetText = (response: Response) => TypedResponseText;
35
34
  type Prettify<T> = {
@@ -144,8 +143,8 @@ declare function typeOf(t: unknown): "array" | "arraybuffer" | "bigint" | "blob"
144
143
  * Error thrown when the response cannot be parsed.
145
144
  */
146
145
  declare class ParseResponseError extends Error {
147
- issues: readonly StandardSchemaV1$1.Issue[];
148
- constructor(message: string, issues: readonly StandardSchemaV1$1.Issue[]);
146
+ issues: readonly StandardSchemaV1.Issue[];
147
+ constructor(message: string, issues: readonly StandardSchemaV1.Issue[]);
149
148
  }
150
149
 
151
150
  export { type BaseOptions, type EnhancedRequestInit, type GetJson, type GetText, type HTTPMethod, type JSONValue, ParseResponseError, type PathParams, type RequestTransformer, type ResponseTransformer, type SearchParams, type ServiceRequestInit, type TypedResponse, type TypedResponseJson, type TypedResponseText, addQueryToURL, enhancedFetch, ensureStringBody, makeFetcher, makeGetApiURL, makeService, mergeHeaders, replaceURLParams, typeOf, typedResponse };
package/dist/index.js CHANGED
@@ -55,9 +55,11 @@ function addQueryToURL(url, searchParams) {
55
55
  return `${url}${separator}${new URLSearchParams(searchParams)}`;
56
56
  }
57
57
  if (searchParams && url instanceof URL) {
58
+ const result = new URL(url.toString());
58
59
  for (const [key, value] of new URLSearchParams(searchParams).entries()) {
59
- url.searchParams.set(key, value);
60
+ result.searchParams.set(key, value);
60
61
  }
62
+ return result;
61
63
  }
62
64
  return url;
63
65
  }
@@ -90,9 +92,9 @@ function mergeHeaders(...entries) {
90
92
  function replaceURLParams(url, params) {
91
93
  if (!params) return url;
92
94
  let urlString = String(url);
93
- Object.entries(params).forEach(([key, value]) => {
95
+ for (const [key, value] of Object.entries(params)) {
94
96
  urlString = urlString.replace(new RegExp(`:${key}($|/)`), `${value}$1`);
95
- });
97
+ }
96
98
  return url instanceof URL ? new URL(urlString) : urlString;
97
99
  }
98
100
  function typeOf(t) {
@@ -113,7 +115,10 @@ var getJson = (response) => async (schema) => {
113
115
  if (!schema) return json;
114
116
  const result = await schema["~standard"].validate(json);
115
117
  if (result.issues) {
116
- throw new ParseResponseError("Failed to parse response.json", result.issues);
118
+ throw new ParseResponseError(
119
+ "Failed to parse response.json",
120
+ result.issues
121
+ );
117
122
  }
118
123
  return result.value;
119
124
  };
@@ -122,7 +127,10 @@ var getText = (response) => async (schema) => {
122
127
  if (!schema) return text;
123
128
  const result = await schema["~standard"].validate(text);
124
129
  if (result.issues) {
125
- throw new ParseResponseError("Failed to parse response.text", result.issues);
130
+ throw new ParseResponseError(
131
+ "Failed to parse response.text",
132
+ result.issues
133
+ );
126
134
  }
127
135
  return result.value;
128
136
  };
package/dist/index.mjs CHANGED
@@ -19,9 +19,11 @@ function addQueryToURL(url, searchParams) {
19
19
  return `${url}${separator}${new URLSearchParams(searchParams)}`;
20
20
  }
21
21
  if (searchParams && url instanceof URL) {
22
+ const result = new URL(url.toString());
22
23
  for (const [key, value] of new URLSearchParams(searchParams).entries()) {
23
- url.searchParams.set(key, value);
24
+ result.searchParams.set(key, value);
24
25
  }
26
+ return result;
25
27
  }
26
28
  return url;
27
29
  }
@@ -54,9 +56,9 @@ function mergeHeaders(...entries) {
54
56
  function replaceURLParams(url, params) {
55
57
  if (!params) return url;
56
58
  let urlString = String(url);
57
- Object.entries(params).forEach(([key, value]) => {
59
+ for (const [key, value] of Object.entries(params)) {
58
60
  urlString = urlString.replace(new RegExp(`:${key}($|/)`), `${value}$1`);
59
- });
61
+ }
60
62
  return url instanceof URL ? new URL(urlString) : urlString;
61
63
  }
62
64
  function typeOf(t) {
@@ -77,7 +79,10 @@ var getJson = (response) => async (schema) => {
77
79
  if (!schema) return json;
78
80
  const result = await schema["~standard"].validate(json);
79
81
  if (result.issues) {
80
- throw new ParseResponseError("Failed to parse response.json", result.issues);
82
+ throw new ParseResponseError(
83
+ "Failed to parse response.json",
84
+ result.issues
85
+ );
81
86
  }
82
87
  return result.value;
83
88
  };
@@ -86,7 +91,10 @@ var getText = (response) => async (schema) => {
86
91
  if (!schema) return text;
87
92
  const result = await schema["~standard"].validate(text);
88
93
  if (result.issues) {
89
- throw new ParseResponseError("Failed to parse response.text", result.issues);
94
+ throw new ParseResponseError(
95
+ "Failed to parse response.text",
96
+ result.issues
97
+ );
90
98
  }
91
99
  return result.value;
92
100
  };
package/package.json CHANGED
@@ -1,33 +1,47 @@
1
1
  {
2
2
  "name": "make-service",
3
- "version": "4.0.0",
3
+ "version": "4.0.1",
4
4
  "description": "Some utilities to extend the 'fetch' API to better interact with external APIs.",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",
7
7
  "types": "./dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./dist/index.d.ts",
11
+ "require": "./dist/index.js",
12
+ "import": "./dist/index.mjs"
13
+ }
14
+ },
15
+ "keywords": [
16
+ "fetch",
17
+ "api",
18
+ "wrapper",
19
+ "service",
20
+ "typescript"
21
+ ],
8
22
  "author": "Gustavo Guichard <@gugaguichard>",
9
23
  "license": "MIT",
24
+ "engines": {
25
+ "node": ">=18"
26
+ },
10
27
  "scripts": {
11
28
  "build": "tsup ./src/index.ts --format esm,cjs --dts",
12
29
  "dev": "tsup ./src/index.ts --format esm,cjs --watch --dts",
13
- "lint": "eslint --config eslint.config.mjs .",
30
+ "lint": "node_modules/.bin/biome check --write --error-on-warnings",
14
31
  "tsc": "tsc --noEmit",
15
32
  "test": "vitest run"
16
33
  },
17
34
  "devDependencies": {
35
+ "@biomejs/biome": "^2.0.0",
18
36
  "@standard-schema/spec": "^1.0.0",
19
- "@types/node": "^22.1.0",
20
- "@typescript-eslint/eslint-plugin": "^8.0.0",
21
- "@typescript-eslint/parser": "^8.0.0",
22
- "arktype": "^2.0.4",
23
- "eslint": "^9.8.0",
24
- "jsdom": "^24.1.1",
25
- "prettier": "latest",
26
- "string-ts": "^2.2.0",
27
- "tsup": "^8.2.4",
28
- "typescript": "^5.5.4",
37
+ "@types/node": "^24.0.3",
38
+ "arktype": "^2.1.20",
39
+ "jsdom": "^26.1.0",
40
+ "string-ts": "^2.2.1",
41
+ "tsup": "^8.5.0",
42
+ "typescript": "^5.8.3",
29
43
  "vitest": "latest",
30
- "zod": "latest"
44
+ "zod": "3.25.67"
31
45
  },
32
46
  "files": [
33
47
  "README.md",