@orpc/contract 2.0.0-beta.3 → 2.0.0-beta.30

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.
@@ -6,28 +6,63 @@ import { StandardSchemaV1 } from '@standard-schema/spec';
6
6
  * TOutput default = TInput for better readability (shorter) in-case both TInput, TOutput is equal
7
7
  */
8
8
  type Schema<TInput, TOutput = TInput> = StandardSchemaV1<TInput, TOutput>;
9
+ /**
10
+ * Any Standard Schema compatible schema, regardless of its input and output types.
11
+ *
12
+ * @see {@link https://orpc.dev/docs/integrations/standard-schema | Standard Schema Integration}
13
+ */
9
14
  type AnySchema = Schema<any>;
10
15
  type SchemaIssue = StandardSchemaV1.Issue;
16
+ /**
17
+ * Infers the input type of a schema.
18
+ *
19
+ * @see {@link https://orpc.dev/docs/metadata | Metadata}
20
+ */
11
21
  type InferSchemaInput<T extends AnySchema> = T extends StandardSchemaV1<infer UInput, any> ? UInput : never;
22
+ /**
23
+ * Infers the output type of a schema.
24
+ *
25
+ * @see {@link https://orpc.dev/docs/metadata | Metadata}
26
+ */
12
27
  type InferSchemaOutput<T extends AnySchema> = T extends StandardSchemaV1<any, infer UOutput> ? UOutput : never;
13
28
  type MergedSchema<T extends AnySchema, U extends AnySchema> = T extends Schema<infer TInput, infer TOutput> ? U extends Schema<infer UInput, infer UOutput> ? Schema<TInput & UInput, TOutput & UOutput> : never : never;
14
29
 
15
- interface ErrorMapItem<TDataSchema extends AnySchema> {
16
- message?: string;
17
- data?: TDataSchema;
30
+ interface ErrorMapItem {
31
+ /**
32
+ * Default message, can be overridden when constructing an error.
33
+ */
34
+ message?: undefined | string;
35
+ /**
36
+ * Schema used to type and validate the error data.
37
+ */
38
+ data?: undefined | AnySchema;
18
39
  }
40
+ /**
41
+ * Map of error codes to their definitions, as passed to `.errors(...)`.
42
+ * Errors defined here remain properly typed on the client.
43
+ *
44
+ * @see {@link https://orpc.dev/docs/metadata | Metadata}
45
+ */
19
46
  type ErrorMap = {
20
- [key in ORPCErrorCode]?: ErrorMapItem<AnySchema>;
47
+ [key in ORPCErrorCode]?: ErrorMapItem;
21
48
  };
22
49
  type ORPCErrorFromErrorMap<TErrorMap extends ErrorMap> = {
23
- [K in keyof TErrorMap]: K extends string ? TErrorMap[K] extends ErrorMapItem<infer TDataSchema extends Schema<unknown>> ? ORPCError<K, InferSchemaOutput<TDataSchema>> : never : never;
50
+ [K in keyof TErrorMap]: TErrorMap[K] extends ErrorMapItem ? ORPCError<K & ORPCErrorCode, TErrorMap[K]['data'] extends AnySchema ? InferSchemaOutput<TErrorMap[K]['data']> : unknown> : never;
24
51
  }[keyof TErrorMap];
25
52
  interface ValidationErrorOptions extends ErrorOptions {
26
53
  message: string;
27
54
  issues: readonly SchemaIssue[];
28
55
  invalidData: unknown;
29
56
  }
57
+ /**
58
+ * Error thrown when input, output, or error data fails schema validation,
59
+ * carrying the standard-schema `issues` and the invalid data.
60
+ * Usually found as the `cause` of an `ORPCError`.
61
+ *
62
+ * @see {@link https://orpc.dev/docs/advanced/validation-customization | Validation Customization}
63
+ */
30
64
  declare class ValidationError extends Error {
65
+ name: string;
31
66
  /**
32
67
  * This array is readonly because the upstream Standard Schema returns readonly issues.
33
68
  */
@@ -36,6 +71,12 @@ declare class ValidationError extends Error {
36
71
  constructor(options: ValidationErrorOptions);
37
72
  }
38
73
 
74
+ /**
75
+ * Arbitrary metadata attached to a procedure.
76
+ * Middleware, plugins, and tooling can read it later to control behavior.
77
+ *
78
+ * @see {@link https://orpc.dev/docs/metadata | Metadata}
79
+ */
39
80
  interface Meta {
40
81
  [key: PropertyKey]: unknown;
41
82
  }
@@ -50,6 +91,12 @@ interface MetaPluginDefinition<TInputSchema extends AnySchema, TOutputSchema ext
50
91
  type: TErrorMap;
51
92
  };
52
93
  }
94
+ /**
95
+ * A metadata plugin passed to `.meta(...)`.
96
+ * Defines how metadata is initialized and merged, and can infer or restrict procedure types.
97
+ *
98
+ * @see {@link https://orpc.dev/docs/metadata | Metadata}
99
+ */
53
100
  interface MetaPlugin<TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap> {
54
101
  /** This only for types, so it should be optional */
55
102
  '~orpc'?: MetaPluginDefinition<TInputSchema, TOutputSchema, TErrorMap> | undefined;
@@ -66,6 +113,12 @@ interface MetaPlugin<TInputSchema extends AnySchema, TOutputSchema extends AnySc
66
113
  */
67
114
  'apply'?: (meta: Meta) => Meta;
68
115
  }
116
+ /**
117
+ * A `MetaPlugin` with all type parameters relaxed to `any`.
118
+ *
119
+ * @see {@link https://orpc.dev/docs/contract/procedure | Procedure Contract}
120
+ * @see {@link https://orpc.dev/docs/procedure | Procedure}
121
+ */
69
122
  type AnyMetaPlugin = MetaPlugin<any, any, any>;
70
123
  declare const HIDDEN_META_PLUGINS_SYMBOL: unique symbol;
71
124
  declare function getHiddenMetaPlugins(container: unknown): AnyMetaPlugin[] | undefined;
@@ -91,36 +144,60 @@ declare class ProcedureContract<TInputSchema extends AnySchema, TOutputSchema ex
91
144
  '~orpc': ProcedureContractDefinition<TInputSchema, TOutputSchema, TErrorMap>;
92
145
  constructor(def: ProcedureContractDefinition<TInputSchema, TOutputSchema, TErrorMap>);
93
146
  /**
94
- * Checks if the given instance satisfies the {@see ProcedureContract} class/interface.
147
+ * Checks if the given instance satisfies the {@link ProcedureContract} class/interface.
95
148
  */
96
149
  static [Symbol.hasInstance](instance: unknown): boolean;
97
150
  }
98
151
  type AnyProcedureContract = ProcedureContract<any, any, any>;
99
152
 
153
+ /**
154
+ * A router contract: a single procedure contract or a nested record of them.
155
+ *
156
+ * @see {@link https://orpc.dev/docs/advanced/scaling-large-projects | Scaling Large Projects}
157
+ */
100
158
  type RouterContract = AnyProcedureContract | {
101
159
  [k: string]: RouterContract;
102
160
  };
161
+ /**
162
+ * Infer the input types for each procedure-contract, preserving the router-contract shape.
163
+ *
164
+ * @see {@link https://orpc.dev/docs/contract/router#infer-router-contract-inputs | Router Contract - Infer Router Contract Inputs}
165
+ */
103
166
  type InferRouterContractInputs<T extends RouterContract> = T extends ProcedureContract<infer UInputSchema, any, any> ? InferSchemaInput<UInputSchema> : {
104
167
  [K in keyof T]: T[K] extends RouterContract ? InferRouterContractInputs<T[K]> : never;
105
168
  };
169
+ /**
170
+ * Infer the output types for each procedure-contract, preserving the router-contract shape.
171
+ *
172
+ * @see {@link https://orpc.dev/docs/contract/router#infer-router-contract-outputs | Router Contract - Infer Router Contract Outputs}
173
+ */
106
174
  type InferRouterContractOutputs<T extends RouterContract> = T extends ProcedureContract<any, infer UOutputSchema, any> ? InferSchemaOutput<UOutputSchema> : {
107
175
  [K in keyof T]: T[K] extends RouterContract ? InferRouterContractOutputs<T[K]> : never;
108
176
  };
177
+ /**
178
+ * Infer the union of error maps defined across the entire router-contract.
179
+ *
180
+ * @see {@link https://orpc.dev/docs/contract/router#infer-router-contract-error-map | Router Contract - Infer Router Contract Error Map}
181
+ */
109
182
  type InferRouterContractErrorMap<T extends RouterContract> = T extends ProcedureContract<any, any, infer UErrorMap> ? UErrorMap : {
110
183
  [K in keyof T]: T[K] extends RouterContract ? InferRouterContractErrorMap<T[K]> : never;
111
184
  }[keyof T];
112
185
  /**
113
186
  * Infer the union of throwable errors for entire router-contract.
187
+ *
188
+ * @see {@link https://orpc.dev/docs/contract/router#infer-router-contract-error | Router Contract - Infer Router Contract Error}
114
189
  */
115
190
  type InferRouterContractError<T extends RouterContract> = T extends ProcedureContract<any, any, infer UErrorMap> ? ORPCErrorFromErrorMap<UErrorMap> | ThrowableError : {
116
191
  [K in keyof T]: T[K] extends RouterContract ? InferRouterContractError<T[K]> : never;
117
192
  }[keyof T];
118
193
  /**
119
194
  * Infer throwable errors for each procedure-contract, preserving the router-contract shape.
195
+ *
196
+ * @see {@link https://orpc.dev/docs/contract/router#infer-router-contract-errors | Router Contract - Infer Router Contract Errors}
120
197
  */
121
198
  type InferRouterContractErrors<T extends RouterContract> = T extends ProcedureContract<any, any, infer UErrorMap> ? ORPCErrorFromErrorMap<UErrorMap> | ThrowableError : {
122
199
  [K in keyof T]: T[K] extends RouterContract ? InferRouterContractErrors<T[K]> : never;
123
200
  };
124
201
 
125
202
  export { HIDDEN_META_PLUGINS_SYMBOL as H, ProcedureContract as P, ValidationError as V, getHiddenMetaPlugins as p, setHiddenMetaPlugins as s };
126
- export type { AnySchema as A, ErrorMap as E, InferSchemaInput as I, MetaPlugin as M, ORPCErrorFromErrorMap as O, RouterContract as R, Schema as S, MergedSchema as a, Meta as b, AnyMetaPlugin as c, AnyProcedureContract as d, InferSchemaOutput as e, SchemaIssue as f, ErrorMapItem as g, InferRouterContractError as h, InferRouterContractErrorMap as i, InferRouterContractErrors as j, InferRouterContractInputs as k, InferRouterContractOutputs as l, MetaPluginDefinition as m, ProcedureContractDefinition as n, ValidationErrorOptions as o };
203
+ export type { AnySchema as A, ErrorMap as E, InferSchemaInput as I, MetaPlugin as M, ORPCErrorFromErrorMap as O, RouterContract as R, Schema as S, MergedSchema as a, Meta as b, AnyMetaPlugin as c, AnyProcedureContract as d, InferSchemaOutput as e, ErrorMapItem as f, SchemaIssue as g, InferRouterContractErrorMap as h, InferRouterContractInputs as i, InferRouterContractOutputs as j, InferRouterContractError as k, InferRouterContractErrors as l, MetaPluginDefinition as m, ProcedureContractDefinition as n, ValidationErrorOptions as o };
@@ -82,7 +82,7 @@ class ProcedureContract {
82
82
  this["~orpc"] = def;
83
83
  }
84
84
  /**
85
- * Checks if the given instance satisfies the {@see ProcedureContract} class/interface.
85
+ * Checks if the given instance satisfies the {@link ProcedureContract} class/interface.
86
86
  */
87
87
  static [Symbol.hasInstance](instance) {
88
88
  if (this !== ProcedureContract) {
@@ -165,6 +165,7 @@ function minifyRouterContract(router) {
165
165
  }
166
166
 
167
167
  class ValidationError extends Error {
168
+ name = "ValidationError";
168
169
  /**
169
170
  * This array is readonly because the upstream Standard Schema returns readonly issues.
170
171
  */
@@ -177,4 +178,4 @@ class ValidationError extends Error {
177
178
  }
178
179
  }
179
180
 
180
- export { ProcedureContract as P, ValidationError as V, augmentContractRouter as a, getRouterContract as b, minifyRouterContract as c, defineMeta as d, reconcileORPCError as e, getProcedureContractOrThrow as g, mergeErrorMap as m, resolveMetaPlugins as r };
181
+ export { ProcedureContract as P, ValidationError as V, augmentContractRouter as a, getProcedureContractOrThrow as b, minifyRouterContract as c, defineMeta as d, reconcileORPCError as e, getRouterContract as g, mergeErrorMap as m, resolveMetaPlugins as r };
package/package.json CHANGED
@@ -1,8 +1,13 @@
1
1
  {
2
2
  "name": "@orpc/contract",
3
3
  "type": "module",
4
- "version": "2.0.0-beta.3",
4
+ "version": "2.0.0-beta.30",
5
+ "description": "Define typesafe API contracts as the single source of truth for oRPC, powered by Standard Schema",
5
6
  "license": "MIT",
7
+ "funding": [
8
+ "https://github.com/sponsors/dinwwwh",
9
+ "https://opencollective.com/middleapi"
10
+ ],
6
11
  "homepage": "https://orpc.dev",
7
12
  "repository": {
8
13
  "type": "git",
@@ -10,7 +15,15 @@
10
15
  "directory": "packages/contract"
11
16
  },
12
17
  "keywords": [
13
- "orpc"
18
+ "orpc",
19
+ "rpc",
20
+ "api",
21
+ "typescript",
22
+ "typesafe",
23
+ "contract",
24
+ "contract-first",
25
+ "standard-schema",
26
+ "openapi"
14
27
  ],
15
28
  "sideEffects": false,
16
29
  "exports": {
@@ -31,12 +44,12 @@
31
44
  ],
32
45
  "dependencies": {
33
46
  "@standard-schema/spec": "^1.1.0",
34
- "@orpc/shared": "2.0.0-beta.3",
35
- "@orpc/client": "2.0.0-beta.3"
47
+ "@orpc/client": "2.0.0-beta.30",
48
+ "@orpc/shared": "2.0.0-beta.30"
36
49
  },
37
50
  "devDependencies": {
38
- "arktype": "^2.1.29",
39
- "valibot": "^1.2.0",
51
+ "arktype": "^2.2.1",
52
+ "valibot": "^1.4.1",
40
53
  "zod": "^4.4.3"
41
54
  },
42
55
  "scripts": {