make-service 4.0.2 → 4.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +0 -6
- package/dist/index.d.mts +32 -7
- package/dist/index.d.ts +32 -7
- package/package.json +2 -5
package/README.md
CHANGED
|
@@ -74,12 +74,6 @@ Or you can use it with Deno:
|
|
|
74
74
|
import { makeService } from "https://deno.land/x/make_service/mod.ts";
|
|
75
75
|
```
|
|
76
76
|
|
|
77
|
-
If you want to use it with a schema parser - such as [zod](https://zod.dev/), [arktype](https://arktype.dev/), [valibot](https://valibot.dev/), or other [standard-schema](https://standardschema.dev) libraries -, you need to install it as a peer dependency:
|
|
78
|
-
|
|
79
|
-
```sh
|
|
80
|
-
npm install make-service @standard-schema/spec
|
|
81
|
-
```
|
|
82
|
-
|
|
83
77
|
# API
|
|
84
78
|
|
|
85
79
|
This library exports the `makeService` function and some primitives used to build it. You can use the primitives as you wish but the `makeService` will have all the features combined.
|
package/dist/index.d.mts
CHANGED
|
@@ -1,7 +1,32 @@
|
|
|
1
|
-
import { StandardSchemaV1 } from '@standard-schema/spec';
|
|
2
|
-
|
|
3
1
|
declare const HTTP_METHODS: readonly ["GET", "POST", "PUT", "DELETE", "PATCH", "OPTIONS", "HEAD", "CONNECT"];
|
|
4
2
|
|
|
3
|
+
/** A minimal subset of the Standard Schema specification used internally */
|
|
4
|
+
interface StandardSchema<Input = unknown, Output = Input> {
|
|
5
|
+
readonly '~standard': StandardSchema.Props<Input, Output>;
|
|
6
|
+
}
|
|
7
|
+
declare namespace StandardSchema {
|
|
8
|
+
interface Props<Input = unknown, Output = Input> {
|
|
9
|
+
readonly version: 1;
|
|
10
|
+
readonly vendor: string;
|
|
11
|
+
readonly validate: (value: unknown) => Result<Output> | Promise<Result<Output>>;
|
|
12
|
+
}
|
|
13
|
+
type Result<Output> = SuccessResult<Output> | FailureResult;
|
|
14
|
+
interface SuccessResult<Output> {
|
|
15
|
+
readonly value: Output;
|
|
16
|
+
readonly issues?: undefined;
|
|
17
|
+
}
|
|
18
|
+
interface FailureResult {
|
|
19
|
+
readonly issues: readonly Issue[];
|
|
20
|
+
}
|
|
21
|
+
interface Issue {
|
|
22
|
+
readonly message: string;
|
|
23
|
+
readonly path?: readonly (PropertyKey | PathSegment)[];
|
|
24
|
+
}
|
|
25
|
+
interface PathSegment {
|
|
26
|
+
readonly key: PropertyKey;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
5
30
|
type JSONValue = string | number | boolean | Date | {
|
|
6
31
|
[x: string]: JSONValue | undefined | null;
|
|
7
32
|
} | Array<JSONValue | undefined | null>;
|
|
@@ -27,8 +52,8 @@ type BaseOptions = {
|
|
|
27
52
|
responseTransformer?: ResponseTransformer;
|
|
28
53
|
};
|
|
29
54
|
type HTTPMethod = (typeof HTTP_METHODS)[number];
|
|
30
|
-
type TypedResponseJson = <Input = unknown, Output = Input>(schema?:
|
|
31
|
-
type TypedResponseText = <Input extends string = string, Output = Input>(schema?:
|
|
55
|
+
type TypedResponseJson = <Input = unknown, Output = Input>(schema?: StandardSchema<Input, Output>) => Promise<Output>;
|
|
56
|
+
type TypedResponseText = <Input extends string = string, Output = Input>(schema?: StandardSchema<Input, Output>) => Promise<Output>;
|
|
32
57
|
type GetJson = (response: Response) => TypedResponseJson;
|
|
33
58
|
type GetText = (response: Response) => TypedResponseText;
|
|
34
59
|
type Prettify<T> = {
|
|
@@ -143,8 +168,8 @@ declare function typeOf(t: unknown): "array" | "arraybuffer" | "bigint" | "blob"
|
|
|
143
168
|
* Error thrown when the response cannot be parsed.
|
|
144
169
|
*/
|
|
145
170
|
declare class ParseResponseError extends Error {
|
|
146
|
-
issues: readonly
|
|
147
|
-
constructor(message: string, issues: readonly
|
|
171
|
+
issues: readonly StandardSchema.Issue[];
|
|
172
|
+
constructor(message: string, issues: readonly StandardSchema.Issue[]);
|
|
148
173
|
}
|
|
149
174
|
|
|
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 };
|
|
175
|
+
export { type BaseOptions, type EnhancedRequestInit, type GetJson, type GetText, type HTTPMethod, type JSONValue, ParseResponseError, type PathParams, type RequestTransformer, type ResponseTransformer, type SearchParams, type ServiceRequestInit, StandardSchema, type TypedResponse, type TypedResponseJson, type TypedResponseText, addQueryToURL, enhancedFetch, ensureStringBody, makeFetcher, makeGetApiURL, makeService, mergeHeaders, replaceURLParams, typeOf, typedResponse };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,32 @@
|
|
|
1
|
-
import { StandardSchemaV1 } from '@standard-schema/spec';
|
|
2
|
-
|
|
3
1
|
declare const HTTP_METHODS: readonly ["GET", "POST", "PUT", "DELETE", "PATCH", "OPTIONS", "HEAD", "CONNECT"];
|
|
4
2
|
|
|
3
|
+
/** A minimal subset of the Standard Schema specification used internally */
|
|
4
|
+
interface StandardSchema<Input = unknown, Output = Input> {
|
|
5
|
+
readonly '~standard': StandardSchema.Props<Input, Output>;
|
|
6
|
+
}
|
|
7
|
+
declare namespace StandardSchema {
|
|
8
|
+
interface Props<Input = unknown, Output = Input> {
|
|
9
|
+
readonly version: 1;
|
|
10
|
+
readonly vendor: string;
|
|
11
|
+
readonly validate: (value: unknown) => Result<Output> | Promise<Result<Output>>;
|
|
12
|
+
}
|
|
13
|
+
type Result<Output> = SuccessResult<Output> | FailureResult;
|
|
14
|
+
interface SuccessResult<Output> {
|
|
15
|
+
readonly value: Output;
|
|
16
|
+
readonly issues?: undefined;
|
|
17
|
+
}
|
|
18
|
+
interface FailureResult {
|
|
19
|
+
readonly issues: readonly Issue[];
|
|
20
|
+
}
|
|
21
|
+
interface Issue {
|
|
22
|
+
readonly message: string;
|
|
23
|
+
readonly path?: readonly (PropertyKey | PathSegment)[];
|
|
24
|
+
}
|
|
25
|
+
interface PathSegment {
|
|
26
|
+
readonly key: PropertyKey;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
5
30
|
type JSONValue = string | number | boolean | Date | {
|
|
6
31
|
[x: string]: JSONValue | undefined | null;
|
|
7
32
|
} | Array<JSONValue | undefined | null>;
|
|
@@ -27,8 +52,8 @@ type BaseOptions = {
|
|
|
27
52
|
responseTransformer?: ResponseTransformer;
|
|
28
53
|
};
|
|
29
54
|
type HTTPMethod = (typeof HTTP_METHODS)[number];
|
|
30
|
-
type TypedResponseJson = <Input = unknown, Output = Input>(schema?:
|
|
31
|
-
type TypedResponseText = <Input extends string = string, Output = Input>(schema?:
|
|
55
|
+
type TypedResponseJson = <Input = unknown, Output = Input>(schema?: StandardSchema<Input, Output>) => Promise<Output>;
|
|
56
|
+
type TypedResponseText = <Input extends string = string, Output = Input>(schema?: StandardSchema<Input, Output>) => Promise<Output>;
|
|
32
57
|
type GetJson = (response: Response) => TypedResponseJson;
|
|
33
58
|
type GetText = (response: Response) => TypedResponseText;
|
|
34
59
|
type Prettify<T> = {
|
|
@@ -143,8 +168,8 @@ declare function typeOf(t: unknown): "array" | "arraybuffer" | "bigint" | "blob"
|
|
|
143
168
|
* Error thrown when the response cannot be parsed.
|
|
144
169
|
*/
|
|
145
170
|
declare class ParseResponseError extends Error {
|
|
146
|
-
issues: readonly
|
|
147
|
-
constructor(message: string, issues: readonly
|
|
171
|
+
issues: readonly StandardSchema.Issue[];
|
|
172
|
+
constructor(message: string, issues: readonly StandardSchema.Issue[]);
|
|
148
173
|
}
|
|
149
174
|
|
|
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 };
|
|
175
|
+
export { type BaseOptions, type EnhancedRequestInit, type GetJson, type GetText, type HTTPMethod, type JSONValue, ParseResponseError, type PathParams, type RequestTransformer, type ResponseTransformer, type SearchParams, type ServiceRequestInit, StandardSchema, type TypedResponse, type TypedResponseJson, type TypedResponseText, addQueryToURL, enhancedFetch, ensureStringBody, makeFetcher, makeGetApiURL, makeService, mergeHeaders, replaceURLParams, typeOf, typedResponse };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "make-service",
|
|
3
|
-
"version": "4.0
|
|
3
|
+
"version": "4.1.0",
|
|
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",
|
|
@@ -33,7 +33,6 @@
|
|
|
33
33
|
},
|
|
34
34
|
"devDependencies": {
|
|
35
35
|
"@biomejs/biome": "^2.0.0",
|
|
36
|
-
"@standard-schema/spec": "^1.0.0",
|
|
37
36
|
"@types/node": "^24.0.3",
|
|
38
37
|
"arktype": "^2.1.20",
|
|
39
38
|
"jsdom": "^26.1.0",
|
|
@@ -43,9 +42,7 @@
|
|
|
43
42
|
"vitest": "latest",
|
|
44
43
|
"zod": "3.25.67"
|
|
45
44
|
},
|
|
46
|
-
"peerDependencies": {
|
|
47
|
-
"@standard-schema/spec": "^1.0.0"
|
|
48
|
-
},
|
|
45
|
+
"peerDependencies": {},
|
|
49
46
|
"files": [
|
|
50
47
|
"README.md",
|
|
51
48
|
"./dist/*"
|