@orpc/contract 2.0.0-beta.49 → 2.0.0-beta.50
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/dist/builder-variants.d.ts +79 -79
- package/dist/builder.d.ts +52 -52
- package/dist/builder.js +106 -110
- package/dist/client-factory.d.ts +12 -12
- package/dist/client-factory.js +36 -36
- package/dist/error-factory.d.ts +20 -23
- package/dist/error-factory.js +105 -117
- package/dist/error-utils.d.ts +3 -3
- package/dist/error-utils.js +35 -38
- package/dist/error.d.ts +23 -27
- package/dist/error.js +21 -19
- package/dist/index.d.ts +20 -62
- package/dist/index.js +12 -31
- package/dist/meta-built-in.d.ts +10 -10
- package/dist/meta-built-in.js +41 -50
- package/dist/meta-utils.d.ts +10 -13
- package/dist/meta-utils.js +67 -73
- package/dist/meta.d.ts +27 -27
- package/dist/meta.js +9 -11
- package/dist/plugins/index.d.ts +3 -12
- package/dist/plugins/index.js +2 -12
- package/dist/plugins/request-validation.d.ts +19 -19
- package/dist/plugins/request-validation.js +49 -54
- package/dist/plugins/response-validation.d.ts +8 -8
- package/dist/plugins/response-validation.js +66 -71
- package/dist/procedure-client.d.ts +5 -5
- package/dist/procedure.d.ts +24 -24
- package/dist/procedure.js +17 -28
- package/dist/router-client.d.ts +5 -7
- package/dist/router-utils.d.ts +10 -17
- package/dist/router-utils.js +53 -73
- package/dist/router.d.ts +10 -20
- package/dist/schema-built-in.d.ts +5 -10
- package/dist/schema-built-in.js +64 -71
- package/dist/schema-utils.d.ts +3 -3
- package/dist/schema-utils.js +32 -40
- package/dist/schema.d.ts +2 -2
- package/package.json +3 -3
- package/dist/builder-variants.js +0 -1
- package/dist/procedure-client.js +0 -1
- package/dist/router-client.js +0 -1
- package/dist/router.js +0 -1
- package/dist/schema.js +0 -1
package/dist/client-factory.js
CHANGED
|
@@ -1,38 +1,38 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
1
|
+
import { resolveBasePathMeta } from "./meta-built-in.js";
|
|
2
|
+
import { ProcedureContract } from "./procedure.js";
|
|
3
|
+
import { get, isNonPrimitive, set } from "@orpc/shared";
|
|
4
|
+
import { createORPCClient } from "@orpc/client";
|
|
5
|
+
// src/client-factory.ts
|
|
5
6
|
/**
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
};
|
|
37
|
-
return factory;
|
|
7
|
+
* Creates a client factory that builds a client from any procedure or router contract,
|
|
8
|
+
* so large projects can import individual contracts instead of a single root client.
|
|
9
|
+
*
|
|
10
|
+
* @remarks
|
|
11
|
+
* **Warning**: Every procedure contract passed to the factory must define `meta.path` matching its location in the root contract.
|
|
12
|
+
*
|
|
13
|
+
* @see {@link https://orpc.dev/docs/contract/client-factory | Contract Client Factory}
|
|
14
|
+
*/
|
|
15
|
+
function createContractClientFactory(link, options = {}) {
|
|
16
|
+
const factory = (contract) => {
|
|
17
|
+
const path = resolveBasePathMeta(contract);
|
|
18
|
+
if (path === void 0) throw new TypeError("ContractClientFactory: procedure contract must define `meta.path` that matches its path in the root router contract.");
|
|
19
|
+
const contractRef = options.contractRef;
|
|
20
|
+
if (contractRef) {
|
|
21
|
+
const register = (contract, path) => {
|
|
22
|
+
if (contract instanceof ProcedureContract) {
|
|
23
|
+
set(contractRef, [...path, "~orpc"], contract["~orpc"]);
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
if (isNonPrimitive(contract)) for (const [key, value] of Object.entries(contract)) register(value, [...path, key]);
|
|
27
|
+
};
|
|
28
|
+
register(contract, path);
|
|
29
|
+
}
|
|
30
|
+
return createORPCClient(link, {
|
|
31
|
+
...options,
|
|
32
|
+
scoped: get(options.scoped, path),
|
|
33
|
+
path
|
|
34
|
+
});
|
|
35
|
+
};
|
|
36
|
+
return factory;
|
|
38
37
|
}
|
|
38
|
+
export { createContractClientFactory };
|
package/dist/error-factory.d.ts
CHANGED
|
@@ -1,23 +1,22 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import type { AnySchema, InferSchemaInput, Schema } from './schema.ts';
|
|
1
|
+
import { ErrorMap, ErrorMapItem } from "./error.js";
|
|
2
|
+
import { AnySchema, InferSchemaInput, Schema } from "./schema.js";
|
|
3
|
+
import { MaybeOptionalOptions } from "@orpc/shared";
|
|
4
|
+
import { ORPCError, ORPCErrorCode, ORPCErrorOptions } from "@orpc/client";
|
|
6
5
|
export interface ORPCErrorFactoryOptions<TData> {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
6
|
+
/**
|
|
7
|
+
* Optional schema used to type and validate the error data.
|
|
8
|
+
* Must be a synchronous schema.
|
|
9
|
+
*/
|
|
10
|
+
data?: Schema<TData> | undefined;
|
|
11
|
+
/**
|
|
12
|
+
* Optional default message, can be overridden when constructing an error.
|
|
13
|
+
*/
|
|
14
|
+
message?: string | undefined;
|
|
16
15
|
}
|
|
17
16
|
export interface ORPCErrorFactory<TCode extends ORPCErrorCode, TData> extends ErrorMapItem {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
17
|
+
code: TCode;
|
|
18
|
+
data: Schema<TData>;
|
|
19
|
+
new (...rest: MaybeOptionalOptions<ORPCErrorOptions<TData>>): ORPCError<TCode, TData>;
|
|
21
20
|
}
|
|
22
21
|
/**
|
|
23
22
|
* Creates a reusable error class ({@link ORPCErrorFactory}) for the given code,
|
|
@@ -48,13 +47,11 @@ export interface ORPCErrorFactory<TCode extends ORPCErrorCode, TData> extends Er
|
|
|
48
47
|
* @see {@link https://orpc.dev/docs/error-handling#error-factory | Error Handling - Error Factory}
|
|
49
48
|
*/
|
|
50
49
|
export declare function error<TCode extends ORPCErrorCode, TData = unknown>(code: TCode, { data: dataSchema, message }?: ORPCErrorFactoryOptions<TData>): ORPCErrorFactory<TCode, TData>;
|
|
51
|
-
export type ORPCErrorConstructorMapItemOptions<TData> = Omit<ORPCErrorOptions<TData>,
|
|
50
|
+
export type ORPCErrorConstructorMapItemOptions<TData> = Omit<ORPCErrorOptions<TData>, "status">;
|
|
52
51
|
export interface ORPCErrorConstructorMapItem<TCode extends ORPCErrorCode, TInData> {
|
|
53
|
-
|
|
52
|
+
(...rest: MaybeOptionalOptions<ORPCErrorConstructorMapItemOptions<TInData>>): ORPCError<TCode, TInData>;
|
|
54
53
|
}
|
|
55
|
-
export type ORPCErrorConstructorMap<T extends ErrorMap> = {
|
|
56
|
-
[K in keyof T]: T[K] extends ErrorMapItem ? ORPCErrorConstructorMapItem<K & ORPCErrorCode, T[K]['data'] extends AnySchema ? InferSchemaInput<T[K]['data']> : unknown> : never;
|
|
57
|
-
};
|
|
54
|
+
export type ORPCErrorConstructorMap<T extends ErrorMap> = { [K in keyof T]: T[K] extends ErrorMapItem ? ORPCErrorConstructorMapItem<K & ORPCErrorCode, T[K]["data"] extends AnySchema ? InferSchemaInput<T[K]["data"]> : unknown> : never; };
|
|
58
55
|
/**
|
|
59
56
|
* Creates a map of ORPC error constructors.
|
|
60
57
|
*
|
|
@@ -77,4 +74,4 @@ export type ORPCErrorConstructorMap<T extends ErrorMap> = {
|
|
|
77
74
|
* throw errorMap.NOT_FOUND()
|
|
78
75
|
* ```
|
|
79
76
|
*/
|
|
80
|
-
export declare function createORPCErrorConstructorMap<T extends ErrorMap>(errorMap: T): ORPCErrorConstructorMap<T>;
|
|
77
|
+
export declare function createORPCErrorConstructorMap<T extends ErrorMap>(errorMap: T): ORPCErrorConstructorMap<T>;
|
package/dist/error-factory.js
CHANGED
|
@@ -1,121 +1,109 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
1
|
+
import { ValidationError } from "./error.js";
|
|
2
|
+
import { type } from "./schema-utils.js";
|
|
3
|
+
import { getOwn, resolveMaybeOptionalOptions } from "@orpc/shared";
|
|
4
|
+
import { ORPCError, RECURSIVE_CLIENT_UNWRAP_KEYS } from "@orpc/client";
|
|
5
|
+
// src/error-factory.ts
|
|
5
6
|
/**
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
if (dataSchema && validateData(dataSchema, instance.data).issues) {
|
|
69
|
-
return false;
|
|
70
|
-
}
|
|
71
|
-
return true;
|
|
72
|
-
}
|
|
73
|
-
};
|
|
7
|
+
* Creates a reusable error class ({@link ORPCErrorFactory}) for the given code,
|
|
8
|
+
* default message, and data schema.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```ts
|
|
12
|
+
* const RateLimitedError = error('RATE_LIMITED', {
|
|
13
|
+
* message: 'You are being rate limited',
|
|
14
|
+
* data: z.object({ retryAfter: z.number() }),
|
|
15
|
+
* })
|
|
16
|
+
*
|
|
17
|
+
* const procedure = os
|
|
18
|
+
* .errors({ [RateLimitedError.code]: RateLimitedError })
|
|
19
|
+
* .handler(() => {
|
|
20
|
+
* throw new RateLimitedError({ data: { retryAfter: 60 } })
|
|
21
|
+
* })
|
|
22
|
+
*
|
|
23
|
+
* try {
|
|
24
|
+
* const output = call(procedure)
|
|
25
|
+
* } catch (error) {
|
|
26
|
+
* if (error instanceof RateLimitedError) {
|
|
27
|
+
* console.log(error.data.retryAfter)
|
|
28
|
+
* }
|
|
29
|
+
* }
|
|
30
|
+
* ```
|
|
31
|
+
*
|
|
32
|
+
* @see {@link https://orpc.dev/docs/error-handling#error-factory | Error Handling - Error Factory}
|
|
33
|
+
*/
|
|
34
|
+
function error(code, { data: dataSchema, message } = {}) {
|
|
35
|
+
const validateData = (schema, value) => {
|
|
36
|
+
const result = schema["~standard"].validate(value);
|
|
37
|
+
if (result instanceof Promise) throw new TypeError(`Error factory "${code}" does not support async data schemas.`);
|
|
38
|
+
return result;
|
|
39
|
+
};
|
|
40
|
+
return class extends ORPCError {
|
|
41
|
+
static code = code;
|
|
42
|
+
static data = dataSchema ?? type();
|
|
43
|
+
static message = message;
|
|
44
|
+
constructor(...rest) {
|
|
45
|
+
const options = resolveMaybeOptionalOptions(rest);
|
|
46
|
+
let data = options.data;
|
|
47
|
+
if (dataSchema) {
|
|
48
|
+
const result = validateData(dataSchema, options.data);
|
|
49
|
+
if (result.issues) throw new ValidationError({
|
|
50
|
+
message: `Error factory "${code}" data validation failed`,
|
|
51
|
+
issues: result.issues,
|
|
52
|
+
invalidData: options.data
|
|
53
|
+
});
|
|
54
|
+
data = result.value;
|
|
55
|
+
}
|
|
56
|
+
super(code, {
|
|
57
|
+
...options,
|
|
58
|
+
message: options.message ?? message,
|
|
59
|
+
data
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
static [Symbol.hasInstance](instance) {
|
|
63
|
+
if (!(instance instanceof ORPCError)) return false;
|
|
64
|
+
if (instance.code !== code) return false;
|
|
65
|
+
if (dataSchema && validateData(dataSchema, instance.data).issues) return false;
|
|
66
|
+
return true;
|
|
67
|
+
}
|
|
68
|
+
};
|
|
74
69
|
}
|
|
75
70
|
/**
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
error.defined = true;
|
|
114
|
-
}
|
|
115
|
-
return error;
|
|
116
|
-
};
|
|
117
|
-
return item;
|
|
118
|
-
},
|
|
119
|
-
});
|
|
120
|
-
return proxy;
|
|
71
|
+
* Creates a map of ORPC error constructors.
|
|
72
|
+
*
|
|
73
|
+
* The returned object is a `Proxy` that allows access to arbitrary error codes:
|
|
74
|
+
* - If the code exists in the provided `errorMap`, the corresponding constructor
|
|
75
|
+
* will create a **defined** `ORPCError`.
|
|
76
|
+
* - If the code does not exist, a fallback `ORPCError` constructor is returned.
|
|
77
|
+
*
|
|
78
|
+
* The `in` operator can be used to check whether an error code is explicitly
|
|
79
|
+
* defined in the map.
|
|
80
|
+
*
|
|
81
|
+
* @example
|
|
82
|
+
* ```ts
|
|
83
|
+
* const errorMap = createORPCErrorConstructorMap({
|
|
84
|
+
* NOT_FOUND: {
|
|
85
|
+
* message: 'Not Found',
|
|
86
|
+
* },
|
|
87
|
+
* })
|
|
88
|
+
*
|
|
89
|
+
* throw errorMap.NOT_FOUND()
|
|
90
|
+
* ```
|
|
91
|
+
*/
|
|
92
|
+
function createORPCErrorConstructorMap(errorMap) {
|
|
93
|
+
return new Proxy(errorMap, { get(target, code) {
|
|
94
|
+
if (typeof code !== "string" || RECURSIVE_CLIENT_UNWRAP_KEYS.has(code)) return Reflect.get(target, code);
|
|
95
|
+
const item = (...rest) => {
|
|
96
|
+
const options = resolveMaybeOptionalOptions(rest);
|
|
97
|
+
const config = getOwn(errorMap, code);
|
|
98
|
+
const error = new ORPCError(code, {
|
|
99
|
+
message: options.message ?? config?.message,
|
|
100
|
+
data: options.data,
|
|
101
|
+
cause: options.cause
|
|
102
|
+
});
|
|
103
|
+
if (config) error.defined = true;
|
|
104
|
+
return error;
|
|
105
|
+
};
|
|
106
|
+
return item;
|
|
107
|
+
} });
|
|
121
108
|
}
|
|
109
|
+
export { createORPCErrorConstructorMap, error };
|
package/dist/error-utils.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
1
|
+
import { ErrorMap } from "./error.js";
|
|
2
|
+
import { AnyORPCError } from "@orpc/client";
|
|
3
3
|
export type MergedErrorMap<T1 extends ErrorMap, T2 extends ErrorMap> = keyof T1 extends never | keyof T2 ? T2 : Omit<T1, keyof T2> & T2;
|
|
4
4
|
export declare function mergeErrorMap<T1 extends ErrorMap = object, T2 extends ErrorMap = object>(errorMap1: T1 | undefined, errorMap2: T2 | undefined): MergedErrorMap<T1, T2>;
|
|
5
|
-
export declare function reconcileORPCError(map: ErrorMap, error: AnyORPCError): Promise<AnyORPCError>;
|
|
5
|
+
export declare function reconcileORPCError(map: ErrorMap, error: AnyORPCError): Promise<AnyORPCError>;
|
package/dist/error-utils.js
CHANGED
|
@@ -1,40 +1,37 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import { getOwn } from "@orpc/shared";
|
|
2
|
+
import { cloneORPCError } from "@orpc/client";
|
|
3
|
+
// src/error-utils.ts
|
|
4
|
+
function mergeErrorMap(errorMap1, errorMap2) {
|
|
5
|
+
return {
|
|
6
|
+
...errorMap1,
|
|
7
|
+
...errorMap2
|
|
8
|
+
};
|
|
5
9
|
}
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
}
|
|
33
|
-
if (error.data === validated.value && error.defined) {
|
|
34
|
-
return error;
|
|
35
|
-
}
|
|
36
|
-
const cloned = cloneORPCError(error);
|
|
37
|
-
cloned.data = validated.value;
|
|
38
|
-
cloned.defined = true;
|
|
39
|
-
return cloned;
|
|
10
|
+
async function reconcileORPCError(map, error) {
|
|
11
|
+
const config = getOwn(map, error.code);
|
|
12
|
+
if (!config) {
|
|
13
|
+
if (!error.defined) return error;
|
|
14
|
+
const cloned = cloneORPCError(error);
|
|
15
|
+
cloned.defined = false;
|
|
16
|
+
return cloned;
|
|
17
|
+
}
|
|
18
|
+
if (!config.data) {
|
|
19
|
+
if (error.defined) return error;
|
|
20
|
+
const cloned = cloneORPCError(error);
|
|
21
|
+
cloned.defined = true;
|
|
22
|
+
return cloned;
|
|
23
|
+
}
|
|
24
|
+
const validated = await config.data["~standard"].validate(error.data);
|
|
25
|
+
if (validated.issues) {
|
|
26
|
+
if (!error.defined) return error;
|
|
27
|
+
const cloned = cloneORPCError(error);
|
|
28
|
+
cloned.defined = false;
|
|
29
|
+
return cloned;
|
|
30
|
+
}
|
|
31
|
+
if (error.data === validated.value && error.defined) return error;
|
|
32
|
+
const cloned = cloneORPCError(error);
|
|
33
|
+
cloned.data = validated.value;
|
|
34
|
+
cloned.defined = true;
|
|
35
|
+
return cloned;
|
|
40
36
|
}
|
|
37
|
+
export { mergeErrorMap, reconcileORPCError };
|
package/dist/error.d.ts
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
1
|
+
import { AnySchema, InferSchemaOutput, SchemaIssue } from "./schema.js";
|
|
2
|
+
import { ORPCError, ORPCErrorCode } from "@orpc/client";
|
|
3
3
|
export interface ErrorMapItem {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
4
|
+
/**
|
|
5
|
+
* Default message, can be overridden when constructing an error.
|
|
6
|
+
*/
|
|
7
|
+
message?: string | undefined;
|
|
8
|
+
/**
|
|
9
|
+
* Schema used to type and validate the error data.
|
|
10
|
+
*/
|
|
11
|
+
data?: AnySchema | undefined;
|
|
12
12
|
}
|
|
13
13
|
/**
|
|
14
14
|
* Map of error codes to their definitions, as passed to `.errors(...)`.
|
|
@@ -16,16 +16,12 @@ export interface ErrorMapItem {
|
|
|
16
16
|
*
|
|
17
17
|
* @see {@link https://orpc.dev/docs/metadata | Metadata}
|
|
18
18
|
*/
|
|
19
|
-
export type ErrorMap = {
|
|
20
|
-
|
|
21
|
-
};
|
|
22
|
-
export type ORPCErrorFromErrorMap<TErrorMap extends ErrorMap> = {
|
|
23
|
-
[K in keyof TErrorMap]: TErrorMap[K] extends ErrorMapItem ? ORPCError<K & ORPCErrorCode, TErrorMap[K]['data'] extends AnySchema ? InferSchemaOutput<TErrorMap[K]['data']> : unknown> : never;
|
|
24
|
-
}[keyof TErrorMap];
|
|
19
|
+
export type ErrorMap = { [key in ORPCErrorCode]?: ErrorMapItem; };
|
|
20
|
+
export type ORPCErrorFromErrorMap<TErrorMap extends ErrorMap> = { [K in keyof TErrorMap]: TErrorMap[K] extends ErrorMapItem ? ORPCError<K & ORPCErrorCode, TErrorMap[K]["data"] extends AnySchema ? InferSchemaOutput<TErrorMap[K]["data"]> : unknown> : never; }[keyof TErrorMap];
|
|
25
21
|
export interface ValidationErrorOptions extends ErrorOptions {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
22
|
+
message: string;
|
|
23
|
+
issues: readonly SchemaIssue[];
|
|
24
|
+
invalidData: unknown;
|
|
29
25
|
}
|
|
30
26
|
/**
|
|
31
27
|
* Error thrown when input, output, or error data fails schema validation,
|
|
@@ -35,11 +31,11 @@ export interface ValidationErrorOptions extends ErrorOptions {
|
|
|
35
31
|
* @see {@link https://orpc.dev/docs/recipes/validation-customization | Validation Customization}
|
|
36
32
|
*/
|
|
37
33
|
export declare class ValidationError extends Error {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
}
|
|
34
|
+
override name: string;
|
|
35
|
+
/**
|
|
36
|
+
* This array is readonly because the upstream Standard Schema returns readonly issues.
|
|
37
|
+
*/
|
|
38
|
+
issues: readonly SchemaIssue[];
|
|
39
|
+
invalidData: unknown;
|
|
40
|
+
constructor(options: ValidationErrorOptions);
|
|
41
|
+
}
|
package/dist/error.js
CHANGED
|
@@ -1,20 +1,22 @@
|
|
|
1
|
+
// src/error.ts
|
|
1
2
|
/**
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
}
|
|
3
|
+
* Error thrown when input, output, or error data fails schema validation,
|
|
4
|
+
* carrying the standard-schema `issues` and the invalid data.
|
|
5
|
+
* Usually found as the `cause` of an `ORPCError`.
|
|
6
|
+
*
|
|
7
|
+
* @see {@link https://orpc.dev/docs/recipes/validation-customization | Validation Customization}
|
|
8
|
+
*/
|
|
9
|
+
var ValidationError = class extends Error {
|
|
10
|
+
name = "ValidationError";
|
|
11
|
+
/**
|
|
12
|
+
* This array is readonly because the upstream Standard Schema returns readonly issues.
|
|
13
|
+
*/
|
|
14
|
+
issues;
|
|
15
|
+
invalidData;
|
|
16
|
+
constructor(options) {
|
|
17
|
+
super(options.message, options);
|
|
18
|
+
this.issues = options.issues;
|
|
19
|
+
this.invalidData = options.invalidData;
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
export { ValidationError };
|