Skip to content

Commit 12c0439

Browse files
committed
pull types from spec instead of inlining
1 parent 2e5b688 commit 12c0439

File tree

4 files changed

+11
-72
lines changed

4 files changed

+11
-72
lines changed

packages/toolkit/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@
125125
"react"
126126
],
127127
"dependencies": {
128+
"@standard-schema/spec": "^1.0.0",
128129
"@standard-schema/utils": "^0.3.0",
129130
"immer": "^10.0.3",
130131
"redux": "^5.0.1",

packages/toolkit/src/query/endpointDefinitions.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import type { Api } from '@reduxjs/toolkit/query'
2+
import type { StandardSchemaV1 } from '@standard-schema/spec'
23
import type {
34
BaseQueryApi,
45
BaseQueryArg,
@@ -37,7 +38,6 @@ import type {
3738
UnwrapPromise,
3839
} from './tsHelpers'
3940
import { isNotNullish } from './utils'
40-
import type { StandardSchemaV1 } from './standardSchema'
4141

4242
const resultType = /* @__PURE__ */ Symbol()
4343
const baseQuery = /* @__PURE__ */ Symbol()

packages/toolkit/src/query/standardSchema.ts

Lines changed: 1 addition & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -1,76 +1,6 @@
1+
import type { StandardSchemaV1 } from '@standard-schema/spec'
12
import { SchemaError } from '@standard-schema/utils'
23

3-
/** The Standard Schema interface. */
4-
export interface StandardSchemaV1<Input = unknown, Output = Input> {
5-
/** The Standard Schema properties. */
6-
readonly '~standard': StandardSchemaV1.Props<Input, Output>
7-
}
8-
9-
export declare namespace StandardSchemaV1 {
10-
/** The Standard Schema properties interface. */
11-
export interface Props<Input = unknown, Output = Input> {
12-
/** The version number of the standard. */
13-
readonly version: 1
14-
/** The vendor name of the schema library. */
15-
readonly vendor: string
16-
/** Validates unknown input values. */
17-
readonly validate: (
18-
value: unknown,
19-
) => Result<Output> | Promise<Result<Output>>
20-
/** Inferred types associated with the schema. */
21-
readonly types?: Types<Input, Output> | undefined
22-
}
23-
24-
/** The result interface of the validate function. */
25-
export type Result<Output> = SuccessResult<Output> | FailureResult
26-
27-
/** The result interface if validation succeeds. */
28-
export interface SuccessResult<Output> {
29-
/** The typed output value. */
30-
readonly value: Output
31-
/** The non-existent issues. */
32-
readonly issues?: undefined
33-
}
34-
35-
/** The result interface if validation fails. */
36-
export interface FailureResult {
37-
/** The issues of failed validation. */
38-
readonly issues: ReadonlyArray<Issue>
39-
}
40-
41-
/** The issue interface of the failure output. */
42-
export interface Issue {
43-
/** The error message of the issue. */
44-
readonly message: string
45-
/** The path of the issue, if any. */
46-
readonly path?: ReadonlyArray<PropertyKey | PathSegment> | undefined
47-
}
48-
49-
/** The path segment interface of the issue. */
50-
export interface PathSegment {
51-
/** The key representing a path segment. */
52-
readonly key: PropertyKey
53-
}
54-
55-
/** The Standard Schema types interface. */
56-
export interface Types<Input = unknown, Output = Input> {
57-
/** The input type of the schema. */
58-
readonly input: Input
59-
/** The output type of the schema. */
60-
readonly output: Output
61-
}
62-
63-
/** Infers the input type of a Standard Schema. */
64-
export type InferInput<Schema extends StandardSchemaV1> = NonNullable<
65-
Schema['~standard']['types']
66-
>['input']
67-
68-
/** Infers the output type of a Standard Schema. */
69-
export type InferOutput<Schema extends StandardSchemaV1> = NonNullable<
70-
Schema['~standard']['types']
71-
>['output']
72-
}
73-
744
export async function parseWithSchema<Schema extends StandardSchemaV1>(
755
schema: Schema,
766
data: unknown,

yarn.lock

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8133,6 +8133,7 @@ __metadata:
81338133
"@phryneas/ts-version": "npm:^1.0.2"
81348134
"@size-limit/file": "npm:^11.0.1"
81358135
"@size-limit/webpack": "npm:^11.0.1"
8136+
"@standard-schema/spec": "npm:^1.0.0"
81368137
"@standard-schema/utils": "npm:^0.3.0"
81378138
"@testing-library/dom": "npm:^10.4.0"
81388139
"@testing-library/react": "npm:^16.0.1"
@@ -8845,6 +8846,13 @@ __metadata:
88458846
languageName: node
88468847
linkType: hard
88478848

8849+
"@standard-schema/spec@npm:^1.0.0":
8850+
version: 1.0.0
8851+
resolution: "@standard-schema/spec@npm:1.0.0"
8852+
checksum: 10/aee780cc1431888ca4b9aba9b24ffc8f3073fc083acc105e3951481478a2f4dc957796931b2da9e2d8329584cf211e4542275f188296c1cdff3ed44fd93a8bc8
8853+
languageName: node
8854+
linkType: hard
8855+
88488856
"@standard-schema/utils@npm:^0.3.0":
88498857
version: 0.3.0
88508858
resolution: "@standard-schema/utils@npm:0.3.0"

0 commit comments

Comments
 (0)