Skip to content

Commit 2b2c3fe

Browse files
Remove standard schema peer dependency (#72)
* remove standard schema peer dependency * Explicit type exports * 4.1.0
1 parent 8b64c07 commit 2b2c3fe

File tree

8 files changed

+63
-26
lines changed

8 files changed

+63
-26
lines changed

README.md

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -74,12 +74,6 @@ Or you can use it with Deno:
7474
import { makeService } from "https://deno.land/x/make_service/mod.ts";
7575
```
7676

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-
8377
# API
8478

8579
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.json

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "make-service",
3-
"version": "4.0.2",
3+
"version": "4.1.0",
44
"description": "Some utilities to extend the 'fetch' API to better interact with external APIs.",
55
"main": "./dist/index.js",
66
"module": "./dist/index.mjs",
@@ -33,7 +33,6 @@
3333
},
3434
"devDependencies": {
3535
"@biomejs/biome": "^2.0.0",
36-
"@standard-schema/spec": "^1.0.0",
3736
"@types/node": "^24.0.3",
3837
"arktype": "^2.1.20",
3938
"jsdom": "^26.1.0",
@@ -43,9 +42,7 @@
4342
"vitest": "latest",
4443
"zod": "3.25.67"
4544
},
46-
"peerDependencies": {
47-
"@standard-schema/spec": "^1.0.0"
48-
},
45+
"peerDependencies": {},
4946
"files": [
5047
"README.md",
5148
"./dist/*"

pnpm-lock.yaml

Lines changed: 0 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/index.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,20 @@ export {
88
replaceURLParams,
99
typeOf,
1010
} from './primitives'
11-
export type * from './types'
11+
export type { StandardSchema } from './standard-schema'
12+
export type {
13+
BaseOptions,
14+
EnhancedRequestInit,
15+
GetJson,
16+
GetText,
17+
HTTPMethod,
18+
JSONValue,
19+
PathParams,
20+
RequestTransformer,
21+
ResponseTransformer,
22+
SearchParams,
23+
ServiceRequestInit,
24+
TypedResponse,
25+
TypedResponseJson,
26+
TypedResponseText,
27+
} from './types'

src/internals.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import type { StandardSchemaV1 } from '@standard-schema/spec'
21
import { ParseResponseError } from './primitives'
2+
import type { StandardSchema } from './standard-schema'
33
import type { GetJson, GetText } from './types'
44

55
/**
@@ -10,7 +10,7 @@ import type { GetJson, GetText } from './types'
1010
const getJson: GetJson =
1111
(response) =>
1212
async <Input = unknown, Output = Input>(
13-
schema?: StandardSchemaV1<Input, Output>
13+
schema?: StandardSchema<Input, Output>
1414
) => {
1515
const json = await response.json()
1616
if (!schema) return json as Output
@@ -31,7 +31,7 @@ const getJson: GetJson =
3131
const getText: GetText =
3232
(response) =>
3333
async <Input extends string = string, Output = Input>(
34-
schema?: StandardSchemaV1<Input, Output>
34+
schema?: StandardSchema<Input, Output>
3535
) => {
3636
const text = await response.text()
3737
if (!schema) return text as Output

src/primitives.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { StandardSchemaV1 } from '@standard-schema/spec'
1+
import type { StandardSchema } from './standard-schema'
22
import type { JSONValue, PathParams, SearchParams } from './types'
33

44
/**
@@ -138,7 +138,7 @@ function typeOf(t: unknown) {
138138
class ParseResponseError extends Error {
139139
constructor(
140140
message: string,
141-
public issues: readonly StandardSchemaV1.Issue[]
141+
public issues: readonly StandardSchema.Issue[]
142142
) {
143143
super(JSON.stringify({ message, issues }, null, 2))
144144
this.name = 'ParseResponseError'

src/standard-schema.ts

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/** A minimal subset of the Standard Schema specification used internally */
2+
interface StandardSchema<Input = unknown, Output = Input> {
3+
readonly '~standard': StandardSchema.Props<Input, Output>
4+
}
5+
6+
declare namespace StandardSchema {
7+
interface Props<Input = unknown, Output = Input> {
8+
readonly version: 1
9+
readonly vendor: string
10+
readonly validate: (
11+
value: unknown
12+
) => Result<Output> | Promise<Result<Output>>
13+
}
14+
15+
type Result<Output> = SuccessResult<Output> | FailureResult
16+
17+
interface SuccessResult<Output> {
18+
readonly value: Output
19+
readonly issues?: undefined
20+
}
21+
22+
interface FailureResult {
23+
readonly issues: readonly Issue[]
24+
}
25+
26+
interface Issue {
27+
readonly message: string
28+
readonly path?: readonly (PropertyKey | PathSegment)[]
29+
}
30+
31+
interface PathSegment {
32+
readonly key: PropertyKey
33+
}
34+
}
35+
36+
export { StandardSchema }

src/types.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import type { StandardSchemaV1 } from '@standard-schema/spec'
21
import type { HTTP_METHODS } from './constants'
2+
import type { StandardSchema } from './standard-schema'
33

44
type JSONValue =
55
| string
@@ -53,11 +53,11 @@ type BaseOptions = {
5353
type HTTPMethod = (typeof HTTP_METHODS)[number]
5454

5555
type TypedResponseJson = <Input = unknown, Output = Input>(
56-
schema?: StandardSchemaV1<Input, Output>
56+
schema?: StandardSchema<Input, Output>
5757
) => Promise<Output>
5858

5959
type TypedResponseText = <Input extends string = string, Output = Input>(
60-
schema?: StandardSchemaV1<Input, Output>
60+
schema?: StandardSchema<Input, Output>
6161
) => Promise<Output>
6262

6363
type GetJson = (response: Response) => TypedResponseJson

0 commit comments

Comments
 (0)