@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.
Files changed (43) hide show
  1. package/dist/builder-variants.d.ts +79 -79
  2. package/dist/builder.d.ts +52 -52
  3. package/dist/builder.js +106 -110
  4. package/dist/client-factory.d.ts +12 -12
  5. package/dist/client-factory.js +36 -36
  6. package/dist/error-factory.d.ts +20 -23
  7. package/dist/error-factory.js +105 -117
  8. package/dist/error-utils.d.ts +3 -3
  9. package/dist/error-utils.js +35 -38
  10. package/dist/error.d.ts +23 -27
  11. package/dist/error.js +21 -19
  12. package/dist/index.d.ts +20 -62
  13. package/dist/index.js +12 -31
  14. package/dist/meta-built-in.d.ts +10 -10
  15. package/dist/meta-built-in.js +41 -50
  16. package/dist/meta-utils.d.ts +10 -13
  17. package/dist/meta-utils.js +67 -73
  18. package/dist/meta.d.ts +27 -27
  19. package/dist/meta.js +9 -11
  20. package/dist/plugins/index.d.ts +3 -12
  21. package/dist/plugins/index.js +2 -12
  22. package/dist/plugins/request-validation.d.ts +19 -19
  23. package/dist/plugins/request-validation.js +49 -54
  24. package/dist/plugins/response-validation.d.ts +8 -8
  25. package/dist/plugins/response-validation.js +66 -71
  26. package/dist/procedure-client.d.ts +5 -5
  27. package/dist/procedure.d.ts +24 -24
  28. package/dist/procedure.js +17 -28
  29. package/dist/router-client.d.ts +5 -7
  30. package/dist/router-utils.d.ts +10 -17
  31. package/dist/router-utils.js +53 -73
  32. package/dist/router.d.ts +10 -20
  33. package/dist/schema-built-in.d.ts +5 -10
  34. package/dist/schema-built-in.js +64 -71
  35. package/dist/schema-utils.d.ts +3 -3
  36. package/dist/schema-utils.js +32 -40
  37. package/dist/schema.d.ts +2 -2
  38. package/package.json +3 -3
  39. package/dist/builder-variants.js +0 -1
  40. package/dist/procedure-client.js +0 -1
  41. package/dist/router-client.js +0 -1
  42. package/dist/router.js +0 -1
  43. package/dist/schema.js +0 -1
@@ -1,9 +1,9 @@
1
- import type { InitialInputSchema, InitialOutputSchema } from './builder.ts';
2
- import type { MergedErrorMap } from './error-utils.ts';
3
- import type { ErrorMap } from './error.ts';
4
- import type { MetaPlugin } from './meta.ts';
5
- import type { ProcedureContract } from './procedure.ts';
6
- import type { AnySchema, MergedSchema } from './schema.ts';
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
- * 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>;
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
- * 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>;
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
- * 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
- }
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 type { ProcedureContractBuilderWithInput, ProcedureContractBuilderWithOutput } from './builder-variants.ts';
2
- import type { MergedErrorMap } from './error-utils.ts';
3
- import type { ErrorMap } from './error.ts';
4
- import type { MetaPlugin } from './meta.ts';
5
- import { ProcedureContract } from './procedure.ts';
6
- import type { AugmentedContractRouter } from './router-utils.ts';
7
- import type { RouterContract } from './router.ts';
8
- import type { AnySchema, Schema } from './schema.ts';
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
- * 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>;
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 { toArray } from '@orpc/shared';
2
- import { mergeErrorMap } from './error-utils.js';
3
- import { resolveMetaPlugins } from './meta-utils.js';
4
- import { getHiddenMetaPlugins } from './meta.js';
5
- import { ProcedureContract } from './procedure.js';
6
- import { augmentContractRouter } from './router-utils.js';
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
- * The contract builder behind `oc`. Chain its methods to define procedure
9
- * contracts — metadata, errors, and input/output schemas — without any
10
- * business logic.
11
- *
12
- * @see {@link https://orpc.dev/docs/contract/procedure | Procedure Contract}
13
- */
14
- export class ContractBuilder extends ProcedureContract {
15
- /**
16
- * Private constructor to prevent direct instantiation.
17
- * Use the static `create` method to initialize a new instance with a safe initial definition.
18
- */
19
- constructor(definition) {
20
- super(definition);
21
- }
22
- /**
23
- * Creates a fresh contract builder with an empty definition.
24
- * Prefer the exported `oc` instance over calling this directly.
25
- *
26
- * @see {@link https://orpc.dev/docs/contract/procedure | Procedure Contract}
27
- */
28
- static create() {
29
- return new ContractBuilder({
30
- errorMap: {},
31
- meta: {},
32
- });
33
- }
34
- /**
35
- * Applies metadata plugins to contracts built from this builder.
36
- *
37
- * @see {@link https://orpc.dev/docs/contract/procedure#metadata | Procedure Contract - Metadata}
38
- */
39
- meta(...plugins) {
40
- const [meta, metaPlugins] = resolveMetaPlugins(this['~orpc'].meta, this['~orpc'].metaPlugins, plugins);
41
- return new ContractBuilder({
42
- ...this['~orpc'],
43
- meta,
44
- metaPlugins,
45
- });
46
- }
47
- /**
48
- * Defines typesafe errors that implementations of this contract can throw.
49
- *
50
- * @see {@link https://orpc.dev/docs/contract/procedure#typesafe-errors | Procedure Contract - Typesafe Errors}
51
- */
52
- errors(errors) {
53
- let result = new ContractBuilder({
54
- ...this['~orpc'],
55
- errorMap: mergeErrorMap(this['~orpc'].errorMap, errors),
56
- });
57
- const plugins = getHiddenMetaPlugins(errors);
58
- if (plugins) {
59
- result = result.meta(...plugins);
60
- }
61
- return result;
62
- }
63
- /**
64
- * Defines the input schema used to validate and type the procedure input.
65
- *
66
- * @see {@link https://orpc.dev/docs/contract/procedure#inputoutput-validation | Procedure Contract - Input/Output Validation}
67
- */
68
- input(schema) {
69
- let result = new ContractBuilder({
70
- ...this['~orpc'],
71
- inputSchemas: [...toArray(this['~orpc'].inputSchemas), schema],
72
- });
73
- const plugins = getHiddenMetaPlugins(schema);
74
- if (plugins) {
75
- result = result.meta(...plugins);
76
- }
77
- return result;
78
- }
79
- /**
80
- * Defines the output schema used to validate and type the procedure output.
81
- *
82
- * @see {@link https://orpc.dev/docs/contract/procedure#inputoutput-validation | Procedure Contract - Input/Output Validation}
83
- */
84
- output(schema) {
85
- let result = new ContractBuilder({
86
- ...this['~orpc'],
87
- outputSchemas: [...toArray(this['~orpc'].outputSchemas), schema],
88
- });
89
- const plugins = getHiddenMetaPlugins(schema);
90
- if (plugins) {
91
- result = result.meta(...plugins);
92
- }
93
- return result;
94
- }
95
- /**
96
- * Applies the builder's errors and metadata to every procedure contract in
97
- * the given router contract.
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
- * The oRPC contract builder. Chain methods like `.input`, `.errors`, and
107
- * `.output` to define procedure contracts, then compose them into router
108
- * contracts.
109
- *
110
- * @see {@link https://orpc.dev/docs/contract/procedure | Procedure Contract}
111
- */
112
- export const oc = /* @__PURE__ */ ContractBuilder.create();
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 };
@@ -1,16 +1,16 @@
1
- import type { ClientContext, ClientLink, ORPCClientOptions } from '@orpc/client';
2
- import type { RouterContractClient } from './router-client.ts';
3
- import type { RouterContract } from './router.ts';
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
- <T extends RouterContract>(contract: T): RouterContractClient<T, TClientContext>;
5
+ <T extends RouterContract>(contract: T): RouterContractClient<T, TClientContext>;
6
6
  }
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;
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>;