@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
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import
|
|
1
|
+
import { InitialInputSchema, InitialOutputSchema } from "./builder.js";
|
|
2
|
+
import { ErrorMap } from "./error.js";
|
|
3
|
+
import { MergedErrorMap } from "./error-utils.js";
|
|
4
|
+
import { MetaPlugin } from "./meta.js";
|
|
5
|
+
import { ProcedureContract } from "./procedure.js";
|
|
6
|
+
import { AnySchema, MergedSchema } from "./schema.js";
|
|
7
7
|
/**
|
|
8
8
|
* The contract builder variant returned after `.input` is called.
|
|
9
9
|
* It is already a complete procedure contract that can still be refined.
|
|
@@ -11,30 +11,30 @@ import type { AnySchema, MergedSchema } from './schema.ts';
|
|
|
11
11
|
* @see {@link https://orpc.dev/docs/contract/procedure | Procedure Contract}
|
|
12
12
|
*/
|
|
13
13
|
export interface ProcedureContractBuilderWithInput<TInputSchema extends AnySchema, TErrorMap extends ErrorMap> extends ProcedureContract<TInputSchema, InitialOutputSchema, TErrorMap> {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
14
|
+
/**
|
|
15
|
+
* Applies metadata plugins to contracts built from this builder.
|
|
16
|
+
*
|
|
17
|
+
* @see {@link https://orpc.dev/docs/contract/procedure#metadata | Procedure Contract - Metadata}
|
|
18
|
+
*/
|
|
19
|
+
meta(...plugins: MetaPlugin<TInputSchema, InitialOutputSchema, TErrorMap>[]): ProcedureContractBuilderWithInput<TInputSchema, TErrorMap>;
|
|
20
|
+
/**
|
|
21
|
+
* Defines typesafe errors that implementations of this contract can throw.
|
|
22
|
+
*
|
|
23
|
+
* @see {@link https://orpc.dev/docs/contract/procedure#typesafe-errors | Procedure Contract - Typesafe Errors}
|
|
24
|
+
*/
|
|
25
|
+
errors<T extends ErrorMap>(errors: T): ProcedureContractBuilderWithInput<TInputSchema, MergedErrorMap<TErrorMap, T>>;
|
|
26
|
+
/**
|
|
27
|
+
* Adds an additional input schema, merged with the previously defined one.
|
|
28
|
+
*
|
|
29
|
+
* @see {@link https://orpc.dev/docs/contract/procedure#multiple-schemas | Procedure Contract - Multiple Schemas}
|
|
30
|
+
*/
|
|
31
|
+
input<T extends AnySchema>(schema: T): ProcedureContractBuilderWithInput<MergedSchema<T, TInputSchema>, TErrorMap>;
|
|
32
|
+
/**
|
|
33
|
+
* Defines the output schema used to validate and type the procedure output.
|
|
34
|
+
*
|
|
35
|
+
* @see {@link https://orpc.dev/docs/contract/procedure#inputoutput-validation | Procedure Contract - Input/Output Validation}
|
|
36
|
+
*/
|
|
37
|
+
output<T extends AnySchema>(schema: T): ProcedureContractBuilderWithInputOutput<TInputSchema, T, TErrorMap>;
|
|
38
38
|
}
|
|
39
39
|
/**
|
|
40
40
|
* The contract builder variant returned after `.output` is called.
|
|
@@ -43,30 +43,30 @@ export interface ProcedureContractBuilderWithInput<TInputSchema extends AnySchem
|
|
|
43
43
|
* @see {@link https://orpc.dev/docs/contract/procedure | Procedure Contract}
|
|
44
44
|
*/
|
|
45
45
|
export interface ProcedureContractBuilderWithOutput<TOutputSchema extends AnySchema, TErrorMap extends ErrorMap> extends ProcedureContract<InitialInputSchema, TOutputSchema, TErrorMap> {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
46
|
+
/**
|
|
47
|
+
* Applies metadata plugins to contracts built from this builder.
|
|
48
|
+
*
|
|
49
|
+
* @see {@link https://orpc.dev/docs/contract/procedure#metadata | Procedure Contract - Metadata}
|
|
50
|
+
*/
|
|
51
|
+
meta(...plugins: MetaPlugin<InitialInputSchema, TOutputSchema, TErrorMap>[]): ProcedureContractBuilderWithOutput<TOutputSchema, TErrorMap>;
|
|
52
|
+
/**
|
|
53
|
+
* Defines typesafe errors that implementations of this contract can throw.
|
|
54
|
+
*
|
|
55
|
+
* @see {@link https://orpc.dev/docs/contract/procedure#typesafe-errors | Procedure Contract - Typesafe Errors}
|
|
56
|
+
*/
|
|
57
|
+
errors<T extends ErrorMap>(errors: T): ProcedureContractBuilderWithOutput<TOutputSchema, MergedErrorMap<TErrorMap, T>>;
|
|
58
|
+
/**
|
|
59
|
+
* Defines the input schema used to validate and type the procedure input.
|
|
60
|
+
*
|
|
61
|
+
* @see {@link https://orpc.dev/docs/contract/procedure#inputoutput-validation | Procedure Contract - Input/Output Validation}
|
|
62
|
+
*/
|
|
63
|
+
input<T extends AnySchema>(schema: T): ProcedureContractBuilderWithInputOutput<T, TOutputSchema, TErrorMap>;
|
|
64
|
+
/**
|
|
65
|
+
* Adds an additional output schema, merged with the previously defined one.
|
|
66
|
+
*
|
|
67
|
+
* @see {@link https://orpc.dev/docs/contract/procedure#multiple-schemas | Procedure Contract - Multiple Schemas}
|
|
68
|
+
*/
|
|
69
|
+
output<T extends AnySchema>(schema: T): ProcedureContractBuilderWithOutput<MergedSchema<T, TOutputSchema>, TErrorMap>;
|
|
70
70
|
}
|
|
71
71
|
/**
|
|
72
72
|
* The contract builder variant returned after both `.input` and `.output`
|
|
@@ -76,28 +76,28 @@ export interface ProcedureContractBuilderWithOutput<TOutputSchema extends AnySch
|
|
|
76
76
|
* @see {@link https://orpc.dev/docs/contract/procedure | Procedure Contract}
|
|
77
77
|
*/
|
|
78
78
|
export interface ProcedureContractBuilderWithInputOutput<TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap> extends ProcedureContract<TInputSchema, TOutputSchema, TErrorMap> {
|
|
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
|
-
}
|
|
79
|
+
/**
|
|
80
|
+
* Applies metadata plugins to contracts built from this builder.
|
|
81
|
+
*
|
|
82
|
+
* @see {@link https://orpc.dev/docs/contract/procedure#metadata | Procedure Contract - Metadata}
|
|
83
|
+
*/
|
|
84
|
+
meta(...plugins: MetaPlugin<TInputSchema, TOutputSchema, TErrorMap>[]): ProcedureContractBuilderWithInputOutput<TInputSchema, TOutputSchema, TErrorMap>;
|
|
85
|
+
/**
|
|
86
|
+
* Defines typesafe errors that implementations of this contract can throw.
|
|
87
|
+
*
|
|
88
|
+
* @see {@link https://orpc.dev/docs/contract/procedure#typesafe-errors | Procedure Contract - Typesafe Errors}
|
|
89
|
+
*/
|
|
90
|
+
errors<T extends ErrorMap>(errors: T): ProcedureContractBuilderWithInputOutput<TInputSchema, TOutputSchema, MergedErrorMap<TErrorMap, T>>;
|
|
91
|
+
/**
|
|
92
|
+
* Adds an additional input schema, merged with the previously defined one.
|
|
93
|
+
*
|
|
94
|
+
* @see {@link https://orpc.dev/docs/contract/procedure#multiple-schemas | Procedure Contract - Multiple Schemas}
|
|
95
|
+
*/
|
|
96
|
+
input<T extends AnySchema>(schema: T): ProcedureContractBuilderWithInputOutput<MergedSchema<T, TInputSchema>, TOutputSchema, TErrorMap>;
|
|
97
|
+
/**
|
|
98
|
+
* Adds an additional output schema, merged with the previously defined one.
|
|
99
|
+
*
|
|
100
|
+
* @see {@link https://orpc.dev/docs/contract/procedure#multiple-schemas | Procedure Contract - Multiple Schemas}
|
|
101
|
+
*/
|
|
102
|
+
output<T extends AnySchema>(schema: T): ProcedureContractBuilderWithInputOutput<TInputSchema, MergedSchema<T, TOutputSchema>, TErrorMap>;
|
|
103
|
+
}
|
package/dist/builder.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import { ProcedureContract } from
|
|
6
|
-
import
|
|
7
|
-
import
|
|
8
|
-
import
|
|
1
|
+
import { ProcedureContractBuilderWithInput, ProcedureContractBuilderWithOutput } from "./builder-variants.js";
|
|
2
|
+
import { ErrorMap } from "./error.js";
|
|
3
|
+
import { MergedErrorMap } from "./error-utils.js";
|
|
4
|
+
import { MetaPlugin } from "./meta.js";
|
|
5
|
+
import { ProcedureContract } from "./procedure.js";
|
|
6
|
+
import { RouterContract } from "./router.js";
|
|
7
|
+
import { AugmentedContractRouter } from "./router-utils.js";
|
|
8
|
+
import { AnySchema, Schema } from "./schema.js";
|
|
9
9
|
/**
|
|
10
10
|
* The input schema type used before `.input` is called.
|
|
11
11
|
* Input is `void` for better compatibility with third-party libraries,
|
|
@@ -24,49 +24,49 @@ export type InitialOutputSchema = Schema<unknown>;
|
|
|
24
24
|
* @see {@link https://orpc.dev/docs/contract/procedure | Procedure Contract}
|
|
25
25
|
*/
|
|
26
26
|
export declare class ContractBuilder<TErrorMap extends ErrorMap> extends ProcedureContract<InitialInputSchema, InitialOutputSchema, TErrorMap> {
|
|
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
|
-
|
|
69
|
-
|
|
27
|
+
/**
|
|
28
|
+
* Private constructor to prevent direct instantiation.
|
|
29
|
+
* Use the static `create` method to initialize a new instance with a safe initial definition.
|
|
30
|
+
*/
|
|
31
|
+
private constructor();
|
|
32
|
+
/**
|
|
33
|
+
* Creates a fresh contract builder with an empty definition.
|
|
34
|
+
* Prefer the exported `oc` instance over calling this directly.
|
|
35
|
+
*
|
|
36
|
+
* @see {@link https://orpc.dev/docs/contract/procedure | Procedure Contract}
|
|
37
|
+
*/
|
|
38
|
+
static create(): ContractBuilder<Record<never, never>>;
|
|
39
|
+
/**
|
|
40
|
+
* Applies metadata plugins to contracts built from this builder.
|
|
41
|
+
*
|
|
42
|
+
* @see {@link https://orpc.dev/docs/contract/procedure#metadata | Procedure Contract - Metadata}
|
|
43
|
+
*/
|
|
44
|
+
meta(...plugins: MetaPlugin<InitialInputSchema, InitialOutputSchema, TErrorMap>[]): ContractBuilder<TErrorMap>;
|
|
45
|
+
/**
|
|
46
|
+
* Defines typesafe errors that implementations of this contract can throw.
|
|
47
|
+
*
|
|
48
|
+
* @see {@link https://orpc.dev/docs/contract/procedure#typesafe-errors | Procedure Contract - Typesafe Errors}
|
|
49
|
+
*/
|
|
50
|
+
errors<T extends ErrorMap>(errors: T): ContractBuilder<MergedErrorMap<TErrorMap, T>>;
|
|
51
|
+
/**
|
|
52
|
+
* Defines the input schema used to validate and type the procedure input.
|
|
53
|
+
*
|
|
54
|
+
* @see {@link https://orpc.dev/docs/contract/procedure#inputoutput-validation | Procedure Contract - Input/Output Validation}
|
|
55
|
+
*/
|
|
56
|
+
input<T extends AnySchema>(schema: T): ProcedureContractBuilderWithInput<T, TErrorMap>;
|
|
57
|
+
/**
|
|
58
|
+
* Defines the output schema used to validate and type the procedure output.
|
|
59
|
+
*
|
|
60
|
+
* @see {@link https://orpc.dev/docs/contract/procedure#inputoutput-validation | Procedure Contract - Input/Output Validation}
|
|
61
|
+
*/
|
|
62
|
+
output<T extends AnySchema>(schema: T): ProcedureContractBuilderWithOutput<T, TErrorMap>;
|
|
63
|
+
/**
|
|
64
|
+
* Applies the builder's errors and metadata to every procedure contract in
|
|
65
|
+
* the given router contract.
|
|
66
|
+
*
|
|
67
|
+
* @see {@link https://orpc.dev/docs/contract/router#extending-router | Router Contract - Extending Router}
|
|
68
|
+
*/
|
|
69
|
+
router<T extends RouterContract>(router: T): AugmentedContractRouter<T, TErrorMap>;
|
|
70
70
|
}
|
|
71
71
|
/**
|
|
72
72
|
* The oRPC contract builder. Chain methods like `.input`, `.errors`, and
|
|
@@ -75,4 +75,4 @@ export declare class ContractBuilder<TErrorMap extends ErrorMap> extends Procedu
|
|
|
75
75
|
*
|
|
76
76
|
* @see {@link https://orpc.dev/docs/contract/procedure | Procedure Contract}
|
|
77
77
|
*/
|
|
78
|
-
export declare const oc: ContractBuilder<Record<never, never>>;
|
|
78
|
+
export declare const oc: ContractBuilder<Record<never, never>>;
|
package/dist/builder.js
CHANGED
|
@@ -1,112 +1,108 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { resolveMetaPlugins } from
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
1
|
+
import { mergeErrorMap } from "./error-utils.js";
|
|
2
|
+
import { getHiddenMetaPlugins } from "./meta.js";
|
|
3
|
+
import { resolveMetaPlugins } from "./meta-utils.js";
|
|
4
|
+
import { ProcedureContract } from "./procedure.js";
|
|
5
|
+
import { augmentContractRouter } from "./router-utils.js";
|
|
6
|
+
import { toArray } from "@orpc/shared";
|
|
7
|
+
// src/builder.ts
|
|
7
8
|
/**
|
|
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
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
* @see {@link https://orpc.dev/docs/contract/router#extending-router | Router Contract - Extending Router}
|
|
100
|
-
*/
|
|
101
|
-
router(router) {
|
|
102
|
-
return augmentContractRouter(router, this['~orpc']);
|
|
103
|
-
}
|
|
104
|
-
}
|
|
9
|
+
* The contract builder behind `oc`. Chain its methods to define procedure
|
|
10
|
+
* contracts — metadata, errors, and input/output schemas — without any
|
|
11
|
+
* business logic.
|
|
12
|
+
*
|
|
13
|
+
* @see {@link https://orpc.dev/docs/contract/procedure | Procedure Contract}
|
|
14
|
+
*/
|
|
15
|
+
var ContractBuilder = class ContractBuilder extends ProcedureContract {
|
|
16
|
+
/**
|
|
17
|
+
* Private constructor to prevent direct instantiation.
|
|
18
|
+
* Use the static `create` method to initialize a new instance with a safe initial definition.
|
|
19
|
+
*/
|
|
20
|
+
constructor(definition) {
|
|
21
|
+
super(definition);
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Creates a fresh contract builder with an empty definition.
|
|
25
|
+
* Prefer the exported `oc` instance over calling this directly.
|
|
26
|
+
*
|
|
27
|
+
* @see {@link https://orpc.dev/docs/contract/procedure | Procedure Contract}
|
|
28
|
+
*/
|
|
29
|
+
static create() {
|
|
30
|
+
return new ContractBuilder({
|
|
31
|
+
errorMap: {},
|
|
32
|
+
meta: {}
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Applies metadata plugins to contracts built from this builder.
|
|
37
|
+
*
|
|
38
|
+
* @see {@link https://orpc.dev/docs/contract/procedure#metadata | Procedure Contract - Metadata}
|
|
39
|
+
*/
|
|
40
|
+
meta(...plugins) {
|
|
41
|
+
const [meta, metaPlugins] = resolveMetaPlugins(this["~orpc"].meta, this["~orpc"].metaPlugins, plugins);
|
|
42
|
+
return new ContractBuilder({
|
|
43
|
+
...this["~orpc"],
|
|
44
|
+
meta,
|
|
45
|
+
metaPlugins
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Defines typesafe errors that implementations of this contract can throw.
|
|
50
|
+
*
|
|
51
|
+
* @see {@link https://orpc.dev/docs/contract/procedure#typesafe-errors | Procedure Contract - Typesafe Errors}
|
|
52
|
+
*/
|
|
53
|
+
errors(errors) {
|
|
54
|
+
let result = new ContractBuilder({
|
|
55
|
+
...this["~orpc"],
|
|
56
|
+
errorMap: mergeErrorMap(this["~orpc"].errorMap, errors)
|
|
57
|
+
});
|
|
58
|
+
const plugins = getHiddenMetaPlugins(errors);
|
|
59
|
+
if (plugins) result = result.meta(...plugins);
|
|
60
|
+
return result;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Defines the input schema used to validate and type the procedure input.
|
|
64
|
+
*
|
|
65
|
+
* @see {@link https://orpc.dev/docs/contract/procedure#inputoutput-validation | Procedure Contract - Input/Output Validation}
|
|
66
|
+
*/
|
|
67
|
+
input(schema) {
|
|
68
|
+
let result = new ContractBuilder({
|
|
69
|
+
...this["~orpc"],
|
|
70
|
+
inputSchemas: [...toArray(this["~orpc"].inputSchemas), schema]
|
|
71
|
+
});
|
|
72
|
+
const plugins = getHiddenMetaPlugins(schema);
|
|
73
|
+
if (plugins) result = result.meta(...plugins);
|
|
74
|
+
return result;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Defines the output schema used to validate and type the procedure output.
|
|
78
|
+
*
|
|
79
|
+
* @see {@link https://orpc.dev/docs/contract/procedure#inputoutput-validation | Procedure Contract - Input/Output Validation}
|
|
80
|
+
*/
|
|
81
|
+
output(schema) {
|
|
82
|
+
let result = new ContractBuilder({
|
|
83
|
+
...this["~orpc"],
|
|
84
|
+
outputSchemas: [...toArray(this["~orpc"].outputSchemas), schema]
|
|
85
|
+
});
|
|
86
|
+
const plugins = getHiddenMetaPlugins(schema);
|
|
87
|
+
if (plugins) result = result.meta(...plugins);
|
|
88
|
+
return result;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Applies the builder's errors and metadata to every procedure contract in
|
|
92
|
+
* the given router contract.
|
|
93
|
+
*
|
|
94
|
+
* @see {@link https://orpc.dev/docs/contract/router#extending-router | Router Contract - Extending Router}
|
|
95
|
+
*/
|
|
96
|
+
router(router) {
|
|
97
|
+
return augmentContractRouter(router, this["~orpc"]);
|
|
98
|
+
}
|
|
99
|
+
};
|
|
105
100
|
/**
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
101
|
+
* The oRPC contract builder. Chain methods like `.input`, `.errors`, and
|
|
102
|
+
* `.output` to define procedure contracts, then compose them into router
|
|
103
|
+
* contracts.
|
|
104
|
+
*
|
|
105
|
+
* @see {@link https://orpc.dev/docs/contract/procedure | Procedure Contract}
|
|
106
|
+
*/
|
|
107
|
+
const oc = /* @__PURE__ */ ContractBuilder.create();
|
|
108
|
+
export { ContractBuilder, oc };
|
package/dist/client-factory.d.ts
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
1
|
+
import { RouterContract } from "./router.js";
|
|
2
|
+
import { RouterContractClient } from "./router-client.js";
|
|
3
|
+
import { ClientContext, ClientLink, ORPCClientOptions } from "@orpc/client";
|
|
4
4
|
export interface ContractClientFactory<TClientContext extends ClientContext> {
|
|
5
|
-
|
|
5
|
+
<T extends RouterContract>(contract: T): RouterContractClient<T, TClientContext>;
|
|
6
6
|
}
|
|
7
|
-
export interface ContractClientFactoryOptions<TClientContext extends ClientContext> extends Pick<ORPCClientOptions<RouterContractClient<RouterContract, TClientContext>>,
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
7
|
+
export interface ContractClientFactoryOptions<TClientContext extends ClientContext> extends Pick<ORPCClientOptions<RouterContractClient<RouterContract, TClientContext>>, "interceptors" | "scoped"> {
|
|
8
|
+
/**
|
|
9
|
+
* An optional reference to the root router-contract.
|
|
10
|
+
* When provided, the client factory will automatically register the passed contract
|
|
11
|
+
* into the router at the path defined by `meta.path`.
|
|
12
|
+
*/
|
|
13
|
+
contractRef?: RouterContract | undefined;
|
|
14
14
|
}
|
|
15
15
|
/**
|
|
16
16
|
* Creates a client factory that builds a client from any procedure or router contract,
|
|
@@ -21,4 +21,4 @@ export interface ContractClientFactoryOptions<TClientContext extends ClientConte
|
|
|
21
21
|
*
|
|
22
22
|
* @see {@link https://orpc.dev/docs/contract/client-factory | Contract Client Factory}
|
|
23
23
|
*/
|
|
24
|
-
export declare function createContractClientFactory<TClientContext extends ClientContext>(link: ClientLink<TClientContext>, options?: ContractClientFactoryOptions<TClientContext>): ContractClientFactory<TClientContext>;
|
|
24
|
+
export declare function createContractClientFactory<TClientContext extends ClientContext>(link: ClientLink<TClientContext>, options?: ContractClientFactoryOptions<TClientContext>): ContractClientFactory<TClientContext>;
|