@orpc/contract 0.0.0-next.f47352c → 0.0.0-next.f4868a1
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/README.md +32 -32
- package/dist/index.d.mts +240 -146
- package/dist/index.d.ts +240 -146
- package/dist/index.mjs +142 -36
- package/dist/plugins/index.d.mts +43 -0
- package/dist/plugins/index.d.ts +43 -0
- package/dist/plugins/index.mjs +81 -0
- package/dist/shared/contract.D_dZrO__.mjs +53 -0
- package/dist/shared/contract.TuRtB1Ca.d.mts +254 -0
- package/dist/shared/contract.TuRtB1Ca.d.ts +254 -0
- package/package.json +15 -11
package/README.md
CHANGED
|
@@ -1,72 +1,72 @@
|
|
|
1
1
|
<div align="center">
|
|
2
|
-
<image align="center" src="https://orpc.
|
|
2
|
+
<image align="center" src="https://orpc.dev/logo.webp" width=280 alt="oRPC logo" />
|
|
3
3
|
</div>
|
|
4
4
|
|
|
5
5
|
<h1></h1>
|
|
6
6
|
|
|
7
7
|
<div align="center">
|
|
8
|
-
<a href="https://codecov.io/gh/
|
|
9
|
-
<img alt="codecov" src="https://codecov.io/gh/
|
|
8
|
+
<a href="https://codecov.io/gh/middleapi/orpc">
|
|
9
|
+
<img alt="codecov" src="https://codecov.io/gh/middleapi/orpc/branch/main/graph/badge.svg">
|
|
10
10
|
</a>
|
|
11
11
|
<a href="https://www.npmjs.com/package/@orpc/contract">
|
|
12
12
|
<img alt="weekly downloads" src="https://img.shields.io/npm/dw/%40orpc%2Fcontract?logo=npm" />
|
|
13
13
|
</a>
|
|
14
|
-
<a href="https://github.com/
|
|
15
|
-
<img alt="MIT License" src="https://img.shields.io/github/license/
|
|
14
|
+
<a href="https://github.com/middleapi/orpc/blob/main/LICENSE">
|
|
15
|
+
<img alt="MIT License" src="https://img.shields.io/github/license/middleapi/orpc?logo=open-source-initiative" />
|
|
16
16
|
</a>
|
|
17
17
|
<a href="https://discord.gg/TXEbwRBvQn">
|
|
18
18
|
<img alt="Discord" src="https://img.shields.io/discord/1308966753044398161?color=7389D8&label&logo=discord&logoColor=ffffff" />
|
|
19
19
|
</a>
|
|
20
|
+
<a href="https://deepwiki.com/middleapi/orpc">
|
|
21
|
+
<img src="https://deepwiki.com/badge.svg" alt="Ask DeepWiki">
|
|
22
|
+
</a>
|
|
20
23
|
</div>
|
|
21
24
|
|
|
22
25
|
<h3 align="center">Typesafe APIs Made Simple 🪄</h3>
|
|
23
26
|
|
|
24
|
-
**oRPC is a powerful combination of RPC and OpenAPI**, makes it easy to build APIs that are end-to-end type-safe and adhere to OpenAPI standards
|
|
27
|
+
**oRPC is a powerful combination of RPC and OpenAPI**, makes it easy to build APIs that are end-to-end type-safe and adhere to OpenAPI standards
|
|
25
28
|
|
|
26
29
|
---
|
|
27
30
|
|
|
28
31
|
## Highlights
|
|
29
32
|
|
|
30
|
-
-
|
|
31
|
-
-
|
|
32
|
-
-
|
|
33
|
-
-
|
|
34
|
-
-
|
|
35
|
-
-
|
|
36
|
-
-
|
|
37
|
-
-
|
|
38
|
-
-
|
|
39
|
-
-
|
|
40
|
-
-
|
|
41
|
-
-
|
|
42
|
-
- **Reusability 🔄**: Write once and reuse your code across multiple purposes effortlessly.
|
|
43
|
-
- **Extendability 🔌**: Easily enhance oRPC with plugins, middleware, and interceptors.
|
|
44
|
-
- **Reliability 🛡️**: Well-tested, fully TypeScript, production-ready, and MIT licensed for peace of mind.
|
|
45
|
-
- **Simplicity 💡**: Enjoy straightforward, clean code with no hidden magic.
|
|
33
|
+
- **🔗 End-to-End Type Safety**: Ensure type-safe inputs, outputs, and errors from client to server.
|
|
34
|
+
- **📘 First-Class OpenAPI**: Built-in support that fully adheres to the OpenAPI standard.
|
|
35
|
+
- **📝 Contract-First Development**: Optionally define your API contract before implementation.
|
|
36
|
+
- **🔍 First-Class OpenTelemetry**: Seamlessly integrate with OpenTelemetry for observability.
|
|
37
|
+
- **⚙️ Framework Integrations**: Seamlessly integrate with TanStack Query (React, Vue, Solid, Svelte, Angular), SWR, Pinia Colada, and more.
|
|
38
|
+
- **🚀 Server Actions**: Fully compatible with React Server Actions on Next.js, TanStack Start, and other platforms.
|
|
39
|
+
- **🔠 Standard Schema Support**: Works out of the box with Zod, Valibot, ArkType, and other schema validators.
|
|
40
|
+
- **🗃️ Native Types**: Supports native types like Date, File, Blob, BigInt, URL, and more.
|
|
41
|
+
- **⏱️ Lazy Router**: Enhance cold start times with our lazy routing feature.
|
|
42
|
+
- **📡 SSE & Streaming**: Enjoy full type-safe support for SSE and streaming.
|
|
43
|
+
- **🌍 Multi-Runtime Support**: Fast and lightweight on Cloudflare, Deno, Bun, Node.js, and beyond.
|
|
44
|
+
- **🔌 Extendability**: Easily extend functionality with plugins, middleware, and interceptors.
|
|
46
45
|
|
|
47
46
|
## Documentation
|
|
48
47
|
|
|
49
|
-
You can find the full documentation [here](https://orpc.
|
|
48
|
+
You can find the full documentation [here](https://orpc.dev).
|
|
50
49
|
|
|
51
50
|
## Packages
|
|
52
51
|
|
|
53
52
|
- [@orpc/contract](https://www.npmjs.com/package/@orpc/contract): Build your API contract.
|
|
54
53
|
- [@orpc/server](https://www.npmjs.com/package/@orpc/server): Build your API or implement API contract.
|
|
55
54
|
- [@orpc/client](https://www.npmjs.com/package/@orpc/client): Consume your API on the client with type-safety.
|
|
55
|
+
- [@orpc/openapi](https://www.npmjs.com/package/@orpc/openapi): Generate OpenAPI specs and handle OpenAPI requests.
|
|
56
|
+
- [@orpc/otel](https://www.npmjs.com/package/@orpc/otel): [OpenTelemetry](https://opentelemetry.io/) integration for observability.
|
|
57
|
+
- [@orpc/nest](https://www.npmjs.com/package/@orpc/nest): Deeply integrate oRPC with [NestJS](https://nestjs.com/).
|
|
56
58
|
- [@orpc/react](https://www.npmjs.com/package/@orpc/react): Utilities for integrating oRPC with React and React Server Actions.
|
|
57
|
-
- [@orpc/
|
|
58
|
-
- [@orpc/
|
|
59
|
-
- [@orpc/solid-query](https://www.npmjs.com/package/@orpc/solid-query): Integration with [Solid Query](https://tanstack.com/query/latest/docs/framework/solid/overview).
|
|
60
|
-
- [@orpc/svelte-query](https://www.npmjs.com/package/@orpc/svelte-query): Integration with [Svelte Query](https://tanstack.com/query/latest/docs/framework/svelte/overview).
|
|
59
|
+
- [@orpc/tanstack-query](https://www.npmjs.com/package/@orpc/tanstack-query): [TanStack Query](https://tanstack.com/query/latest) integration.
|
|
60
|
+
- [@orpc/experimental-react-swr](https://www.npmjs.com/package/@orpc/experimental-react-swr): [SWR](https://swr.vercel.app/) integration.
|
|
61
61
|
- [@orpc/vue-colada](https://www.npmjs.com/package/@orpc/vue-colada): Integration with [Pinia Colada](https://pinia-colada.esm.dev/).
|
|
62
|
-
- [@orpc/
|
|
62
|
+
- [@orpc/hey-api](https://www.npmjs.com/package/@orpc/hey-api): [Hey API](https://heyapi.dev/) integration.
|
|
63
63
|
- [@orpc/zod](https://www.npmjs.com/package/@orpc/zod): More schemas that [Zod](https://zod.dev/) doesn't support yet.
|
|
64
64
|
- [@orpc/valibot](https://www.npmjs.com/package/@orpc/valibot): OpenAPI spec generation from [Valibot](https://valibot.dev/).
|
|
65
65
|
- [@orpc/arktype](https://www.npmjs.com/package/@orpc/arktype): OpenAPI spec generation from [ArkType](https://arktype.io/).
|
|
66
66
|
|
|
67
67
|
## `@orpc/contract`
|
|
68
68
|
|
|
69
|
-
Build your API contract. Read the [documentation](https://orpc.
|
|
69
|
+
Build your API contract. Read the [documentation](https://orpc.dev/docs/contract-first/define-contract) for more information.
|
|
70
70
|
|
|
71
71
|
```ts
|
|
72
72
|
export const PlanetSchema = z.object({
|
|
@@ -104,11 +104,11 @@ export const contract = {
|
|
|
104
104
|
## Sponsors
|
|
105
105
|
|
|
106
106
|
<p align="center">
|
|
107
|
-
<a href="https://cdn.jsdelivr.net/gh/
|
|
108
|
-
<img src='https://cdn.jsdelivr.net/gh/
|
|
107
|
+
<a href="https://cdn.jsdelivr.net/gh/dinwwwh/dinwwwh/sponsors.svg">
|
|
108
|
+
<img src='https://cdn.jsdelivr.net/gh/dinwwwh/dinwwwh/sponsors.svg'/>
|
|
109
109
|
</a>
|
|
110
110
|
</p>
|
|
111
111
|
|
|
112
112
|
## License
|
|
113
113
|
|
|
114
|
-
Distributed under the MIT License. See [LICENSE](https://github.com/
|
|
114
|
+
Distributed under the MIT License. See [LICENSE](https://github.com/middleapi/orpc/blob/main/LICENSE) for more information.
|
package/dist/index.d.mts
CHANGED
|
@@ -1,210 +1,289 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { HTTPPath, HTTPMethod, ClientContext, Client } from '@orpc/client';
|
|
2
2
|
export { HTTPMethod, HTTPPath, ORPCError } from '@orpc/client';
|
|
3
|
-
import {
|
|
4
|
-
export {
|
|
5
|
-
import {
|
|
3
|
+
import { E as ErrorMap, a as EnhanceRouteOptions, A as AnyContractRouter, C as ContractProcedure, M as MergedErrorMap, b as AnySchema, c as Meta, R as Route, d as ContractRouter, e as ContractProcedureDef, S as Schema, I as InputStructure, O as OutputStructure, f as InferSchemaInput, g as InferSchemaOutput, h as ErrorFromErrorMap, i as SchemaIssue } from './shared/contract.TuRtB1Ca.mjs';
|
|
4
|
+
export { o as AnyContractProcedure, k as ErrorMapItem, z as InferContractRouterErrorMap, x as InferContractRouterInputs, B as InferContractRouterMeta, y as InferContractRouterOutputs, l as ORPCErrorFromErrorMap, T as TypeRest, j as ValidationError, V as ValidationErrorOptions, w as enhanceRoute, p as isContractProcedure, m as mergeErrorMap, n as mergeMeta, s as mergePrefix, q as mergeRoute, t as mergeTags, r as prefixRoute, D as type, u as unshiftTagRoute, v as validateORPCError } from './shared/contract.TuRtB1Ca.mjs';
|
|
5
|
+
import { AsyncIteratorClass } from '@orpc/shared';
|
|
6
|
+
export { AsyncIteratorClass, Registry, ThrowableError } from '@orpc/shared';
|
|
7
|
+
export { OpenAPIV3_1 as OpenAPI } from 'openapi-types';
|
|
8
|
+
import '@standard-schema/spec';
|
|
6
9
|
|
|
7
|
-
|
|
8
|
-
type
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
declare function type<TInput, TOutput = TInput>(...[map]: TypeRest<TInput, TOutput>): Schema<TInput, TOutput>;
|
|
14
|
-
|
|
15
|
-
interface ValidationErrorOptions extends ErrorOptions {
|
|
16
|
-
message: string;
|
|
17
|
-
issues: readonly SchemaIssue[];
|
|
18
|
-
}
|
|
19
|
-
declare class ValidationError extends Error {
|
|
20
|
-
readonly issues: readonly SchemaIssue[];
|
|
21
|
-
constructor(options: ValidationErrorOptions);
|
|
22
|
-
}
|
|
23
|
-
interface ErrorMapItem<TDataSchema extends AnySchema> {
|
|
24
|
-
status?: number;
|
|
25
|
-
message?: string;
|
|
26
|
-
data?: TDataSchema;
|
|
10
|
+
declare function getContractRouter(router: AnyContractRouter, path: readonly string[]): AnyContractRouter | undefined;
|
|
11
|
+
type EnhancedContractRouter<T extends AnyContractRouter, TErrorMap extends ErrorMap> = T extends ContractProcedure<infer UInputSchema, infer UOutputSchema, infer UErrors, infer UMeta> ? ContractProcedure<UInputSchema, UOutputSchema, MergedErrorMap<TErrorMap, UErrors>, UMeta> : {
|
|
12
|
+
[K in keyof T]: T[K] extends AnyContractRouter ? EnhancedContractRouter<T[K], TErrorMap> : never;
|
|
13
|
+
};
|
|
14
|
+
interface EnhanceContractRouterOptions<TErrorMap extends ErrorMap> extends EnhanceRouteOptions {
|
|
15
|
+
errorMap: TErrorMap;
|
|
27
16
|
}
|
|
28
|
-
|
|
29
|
-
|
|
17
|
+
declare function enhanceContractRouter<T extends AnyContractRouter, TErrorMap extends ErrorMap>(router: T, options: EnhanceContractRouterOptions<TErrorMap>): EnhancedContractRouter<T, TErrorMap>;
|
|
18
|
+
/**
|
|
19
|
+
* Minify a contract router into a smaller object.
|
|
20
|
+
*
|
|
21
|
+
* You should export the result to a JSON file. On the client side, you can import this JSON file and use it as a contract router.
|
|
22
|
+
* This reduces the size of the contract and helps prevent leaking internal details of the router to the client.
|
|
23
|
+
*
|
|
24
|
+
* @see {@link https://orpc.dev/docs/contract-first/router-to-contract#minify-export-the-contract-router-for-the-client Router to Contract Docs}
|
|
25
|
+
*/
|
|
26
|
+
declare function minifyContractRouter(router: AnyContractRouter): AnyContractRouter;
|
|
27
|
+
type PopulatedContractRouterPaths<T extends AnyContractRouter> = T extends ContractProcedure<infer UInputSchema, infer UOutputSchema, infer UErrors, infer UMeta> ? ContractProcedure<UInputSchema, UOutputSchema, UErrors, UMeta> : {
|
|
28
|
+
[K in keyof T]: T[K] extends AnyContractRouter ? PopulatedContractRouterPaths<T[K]> : never;
|
|
30
29
|
};
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
30
|
+
interface PopulateContractRouterPathsOptions {
|
|
31
|
+
path?: readonly string[];
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Automatically populates missing route paths using the router's nested keys.
|
|
35
|
+
*
|
|
36
|
+
* Constructs paths by joining router keys with `/`.
|
|
37
|
+
* Useful for NestJS integration that require explicit route paths.
|
|
38
|
+
*
|
|
39
|
+
* @see {@link https://orpc.dev/docs/openapi/integrations/implement-contract-in-nest#define-your-contract NestJS Implement Contract Docs}
|
|
40
|
+
*/
|
|
41
|
+
declare function populateContractRouterPaths<T extends AnyContractRouter>(router: T, options?: PopulateContractRouterPathsOptions): PopulatedContractRouterPaths<T>;
|
|
40
42
|
|
|
41
|
-
|
|
42
|
-
type OutputStructure = 'compact' | 'detailed';
|
|
43
|
-
interface Route {
|
|
44
|
-
method?: HTTPMethod;
|
|
45
|
-
path?: HTTPPath;
|
|
46
|
-
summary?: string;
|
|
47
|
-
description?: string;
|
|
48
|
-
deprecated?: boolean;
|
|
49
|
-
tags?: readonly string[];
|
|
43
|
+
interface ContractProcedureBuilder<TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta> extends ContractProcedure<TInputSchema, TOutputSchema, TErrorMap, TMeta> {
|
|
50
44
|
/**
|
|
51
|
-
*
|
|
45
|
+
* Adds type-safe custom errors to the contract.
|
|
46
|
+
* The provided errors are spared-merged with any existing errors in the contract.
|
|
52
47
|
*
|
|
53
|
-
* @
|
|
48
|
+
* @see {@link https://orpc.dev/docs/error-handling#type%E2%80%90safe-error-handling Type-Safe Error Handling Docs}
|
|
54
49
|
*/
|
|
55
|
-
|
|
50
|
+
errors<U extends ErrorMap>(errors: U): ContractProcedureBuilder<TInputSchema, TOutputSchema, MergedErrorMap<TErrorMap, U>, TMeta>;
|
|
56
51
|
/**
|
|
57
|
-
*
|
|
52
|
+
* Sets or updates the metadata for the contract.
|
|
53
|
+
* The provided metadata is spared-merged with any existing metadata in the contract.
|
|
58
54
|
*
|
|
59
|
-
* @
|
|
55
|
+
* @see {@link https://orpc.dev/docs/metadata Metadata Docs}
|
|
60
56
|
*/
|
|
61
|
-
|
|
57
|
+
meta(meta: TMeta): ContractProcedureBuilder<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
|
62
58
|
/**
|
|
63
|
-
*
|
|
64
|
-
*
|
|
65
|
-
*
|
|
66
|
-
* Combines `params` and either `query` or `body` (depending on the HTTP method) into a single object.
|
|
67
|
-
*
|
|
68
|
-
* @option 'detailed'
|
|
69
|
-
* Keeps each part of the request (`params`, `query`, `headers`, and `body`) as separate fields in the input object.
|
|
59
|
+
* Sets or updates the route definition for the contract.
|
|
60
|
+
* The provided route is spared-merged with any existing route in the contract.
|
|
61
|
+
* This option is typically relevant when integrating with OpenAPI.
|
|
70
62
|
*
|
|
71
|
-
*
|
|
72
|
-
*
|
|
73
|
-
* const input = {
|
|
74
|
-
* params: { id: 1 },
|
|
75
|
-
* query: { search: 'hello' },
|
|
76
|
-
* headers: { 'Content-Type': 'application/json' },
|
|
77
|
-
* body: { name: 'John' },
|
|
78
|
-
* }
|
|
79
|
-
* ```
|
|
80
|
-
*
|
|
81
|
-
* @default 'compact'
|
|
63
|
+
* @see {@link https://orpc.dev/docs/openapi/routing OpenAPI Routing Docs}
|
|
64
|
+
* @see {@link https://orpc.dev/docs/openapi/input-output-structure OpenAPI Input/Output Structure Docs}
|
|
82
65
|
*/
|
|
83
|
-
|
|
66
|
+
route(route: Route): ContractProcedureBuilder<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
|
84
67
|
/**
|
|
85
|
-
*
|
|
86
|
-
*
|
|
87
|
-
* @option 'compact'
|
|
88
|
-
* Includes only the body data, encoded directly in the response.
|
|
89
|
-
*
|
|
90
|
-
* @option 'detailed'
|
|
91
|
-
* Separates the output into `headers` and `body` fields.
|
|
92
|
-
* - `headers`: Custom headers to merge with the response headers.
|
|
93
|
-
* - `body`: The response data.
|
|
68
|
+
* Defines the input validation schema for the contract.
|
|
94
69
|
*
|
|
95
|
-
*
|
|
96
|
-
* ```ts
|
|
97
|
-
* const output = {
|
|
98
|
-
* headers: { 'x-custom-header': 'value' },
|
|
99
|
-
* body: { message: 'Hello, world!' },
|
|
100
|
-
* };
|
|
101
|
-
* ```
|
|
102
|
-
*
|
|
103
|
-
* @default 'compact'
|
|
70
|
+
* @see {@link https://orpc.dev/docs/procedure#input-output-validation Input Validation Docs}
|
|
104
71
|
*/
|
|
105
|
-
outputStructure?: OutputStructure;
|
|
106
|
-
}
|
|
107
|
-
declare function mergeRoute(a: Route, b: Route): Route;
|
|
108
|
-
declare function prefixRoute(route: Route, prefix: HTTPPath): Route;
|
|
109
|
-
declare function unshiftTagRoute(route: Route, tags: readonly string[]): Route;
|
|
110
|
-
declare function mergePrefix(a: HTTPPath | undefined, b: HTTPPath): HTTPPath;
|
|
111
|
-
declare function mergeTags(a: readonly string[] | undefined, b: readonly string[]): readonly string[];
|
|
112
|
-
interface EnhanceRouteOptions {
|
|
113
|
-
prefix?: HTTPPath;
|
|
114
|
-
tags?: readonly string[];
|
|
115
|
-
}
|
|
116
|
-
declare function enhanceRoute(route: Route, options: EnhanceRouteOptions): Route;
|
|
117
|
-
|
|
118
|
-
interface ContractProcedureDef<TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta> {
|
|
119
|
-
meta: TMeta;
|
|
120
|
-
route: Route;
|
|
121
|
-
inputSchema?: TInputSchema;
|
|
122
|
-
outputSchema?: TOutputSchema;
|
|
123
|
-
errorMap: TErrorMap;
|
|
124
|
-
}
|
|
125
|
-
declare class ContractProcedure<TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta> {
|
|
126
|
-
'~orpc': ContractProcedureDef<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
|
127
|
-
constructor(def: ContractProcedureDef<TInputSchema, TOutputSchema, TErrorMap, TMeta>);
|
|
128
|
-
}
|
|
129
|
-
type AnyContractProcedure = ContractProcedure<any, any, any, any>;
|
|
130
|
-
declare function isContractProcedure(item: unknown): item is AnyContractProcedure;
|
|
131
|
-
|
|
132
|
-
type ContractRouter<TMeta extends Meta> = ContractProcedure<any, any, any, TMeta> | {
|
|
133
|
-
[k: string]: ContractRouter<TMeta>;
|
|
134
|
-
};
|
|
135
|
-
type AnyContractRouter = ContractRouter<any>;
|
|
136
|
-
type InferContractRouterInputs<T extends AnyContractRouter> = T extends ContractProcedure<infer UInputSchema, any, any, any> ? InferSchemaInput<UInputSchema> : {
|
|
137
|
-
[K in keyof T]: T[K] extends AnyContractRouter ? InferContractRouterInputs<T[K]> : never;
|
|
138
|
-
};
|
|
139
|
-
type InferContractRouterOutputs<T extends AnyContractRouter> = T extends ContractProcedure<any, infer UOutputSchema, any, any> ? InferSchemaOutput<UOutputSchema> : {
|
|
140
|
-
[K in keyof T]: T[K] extends AnyContractRouter ? InferContractRouterOutputs<T[K]> : never;
|
|
141
|
-
};
|
|
142
|
-
type InferContractRouterErrorMap<T extends AnyContractRouter> = T extends ContractProcedure<any, any, infer UErrorMap, any> ? UErrorMap : {
|
|
143
|
-
[K in keyof T]: T[K] extends AnyContractRouter ? InferContractRouterErrorMap<T[K]> : never;
|
|
144
|
-
}[keyof T];
|
|
145
|
-
type InferContractRouterMeta<T extends AnyContractRouter> = T extends ContractRouter<infer UMeta> ? UMeta : never;
|
|
146
|
-
|
|
147
|
-
declare function getContractRouter(router: AnyContractRouter, path: readonly string[]): AnyContractRouter | undefined;
|
|
148
|
-
type EnhancedContractRouter<T extends AnyContractRouter, TErrorMap extends ErrorMap> = T extends ContractProcedure<infer UInputSchema, infer UOutputSchema, infer UErrors, infer UMeta> ? ContractProcedure<UInputSchema, UOutputSchema, MergedErrorMap<TErrorMap, UErrors>, UMeta> : {
|
|
149
|
-
[K in keyof T]: T[K] extends AnyContractRouter ? EnhancedContractRouter<T[K], TErrorMap> : never;
|
|
150
|
-
};
|
|
151
|
-
interface EnhanceContractRouterOptions<TErrorMap extends ErrorMap> extends EnhanceRouteOptions {
|
|
152
|
-
errorMap: TErrorMap;
|
|
153
|
-
}
|
|
154
|
-
declare function enhanceContractRouter<T extends AnyContractRouter, TErrorMap extends ErrorMap>(router: T, options: EnhanceContractRouterOptions<TErrorMap>): EnhancedContractRouter<T, TErrorMap>;
|
|
155
|
-
|
|
156
|
-
interface ContractProcedureBuilder<TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta> extends ContractProcedure<TInputSchema, TOutputSchema, TErrorMap, TMeta> {
|
|
157
|
-
errors<U extends ErrorMap>(errors: U): ContractProcedureBuilder<TInputSchema, TOutputSchema, MergedErrorMap<TErrorMap, U>, TMeta>;
|
|
158
|
-
meta(meta: TMeta): ContractProcedureBuilder<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
|
159
|
-
route(route: Route): ContractProcedureBuilder<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
|
160
72
|
input<U extends AnySchema>(schema: U): ContractProcedureBuilderWithInput<U, TOutputSchema, TErrorMap, TMeta>;
|
|
73
|
+
/**
|
|
74
|
+
* Defines the output validation schema for the contract.
|
|
75
|
+
*
|
|
76
|
+
* @see {@link https://orpc.dev/docs/procedure#input-output-validation Output Validation Docs}
|
|
77
|
+
*/
|
|
161
78
|
output<U extends AnySchema>(schema: U): ContractProcedureBuilderWithOutput<TInputSchema, U, TErrorMap, TMeta>;
|
|
162
79
|
}
|
|
163
80
|
interface ContractProcedureBuilderWithInput<TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta> extends ContractProcedure<TInputSchema, TOutputSchema, TErrorMap, TMeta> {
|
|
81
|
+
/**
|
|
82
|
+
* Adds type-safe custom errors to the contract.
|
|
83
|
+
* The provided errors are spared-merged with any existing errors in the contract.
|
|
84
|
+
*
|
|
85
|
+
* @see {@link https://orpc.dev/docs/error-handling#type%E2%80%90safe-error-handling Type-Safe Error Handling Docs}
|
|
86
|
+
*/
|
|
164
87
|
errors<U extends ErrorMap>(errors: U): ContractProcedureBuilderWithInput<TInputSchema, TOutputSchema, MergedErrorMap<TErrorMap, U>, TMeta>;
|
|
88
|
+
/**
|
|
89
|
+
* Sets or updates the metadata for the contract.
|
|
90
|
+
* The provided metadata is spared-merged with any existing metadata in the contract.
|
|
91
|
+
*
|
|
92
|
+
* @see {@link https://orpc.dev/docs/metadata Metadata Docs}
|
|
93
|
+
*/
|
|
165
94
|
meta(meta: TMeta): ContractProcedureBuilderWithInput<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
|
95
|
+
/**
|
|
96
|
+
* Sets or updates the route definition for the contract.
|
|
97
|
+
* The provided route is spared-merged with any existing route in the contract.
|
|
98
|
+
* This option is typically relevant when integrating with OpenAPI.
|
|
99
|
+
*
|
|
100
|
+
* @see {@link https://orpc.dev/docs/openapi/routing OpenAPI Routing Docs}
|
|
101
|
+
* @see {@link https://orpc.dev/docs/openapi/input-output-structure OpenAPI Input/Output Structure Docs}
|
|
102
|
+
*/
|
|
166
103
|
route(route: Route): ContractProcedureBuilderWithInput<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
|
104
|
+
/**
|
|
105
|
+
* Defines the output validation schema for the contract.
|
|
106
|
+
*
|
|
107
|
+
* @see {@link https://orpc.dev/docs/procedure#input-output-validation Output Validation Docs}
|
|
108
|
+
*/
|
|
167
109
|
output<U extends AnySchema>(schema: U): ContractProcedureBuilderWithInputOutput<TInputSchema, U, TErrorMap, TMeta>;
|
|
168
110
|
}
|
|
169
111
|
interface ContractProcedureBuilderWithOutput<TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta> extends ContractProcedure<TInputSchema, TOutputSchema, TErrorMap, TMeta> {
|
|
112
|
+
/**
|
|
113
|
+
* Adds type-safe custom errors to the contract.
|
|
114
|
+
* The provided errors are spared-merged with any existing errors in the contract.
|
|
115
|
+
*
|
|
116
|
+
* @see {@link https://orpc.dev/docs/error-handling#type%E2%80%90safe-error-handling Type-Safe Error Handling Docs}
|
|
117
|
+
*/
|
|
170
118
|
errors<U extends ErrorMap>(errors: U): ContractProcedureBuilderWithOutput<TInputSchema, TOutputSchema, MergedErrorMap<TErrorMap, U>, TMeta>;
|
|
119
|
+
/**
|
|
120
|
+
* Sets or updates the metadata for the contract.
|
|
121
|
+
* The provided metadata is spared-merged with any existing metadata in the contract.
|
|
122
|
+
*
|
|
123
|
+
* @see {@link https://orpc.dev/docs/metadata Metadata Docs}
|
|
124
|
+
*/
|
|
171
125
|
meta(meta: TMeta): ContractProcedureBuilderWithOutput<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
|
126
|
+
/**
|
|
127
|
+
* Sets or updates the route definition for the contract.
|
|
128
|
+
* The provided route is spared-merged with any existing route in the contract.
|
|
129
|
+
* This option is typically relevant when integrating with OpenAPI.
|
|
130
|
+
*
|
|
131
|
+
* @see {@link https://orpc.dev/docs/openapi/routing OpenAPI Routing Docs}
|
|
132
|
+
* @see {@link https://orpc.dev/docs/openapi/input-output-structure OpenAPI Input/Output Structure Docs}
|
|
133
|
+
*/
|
|
172
134
|
route(route: Route): ContractProcedureBuilderWithOutput<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
|
135
|
+
/**
|
|
136
|
+
* Defines the input validation schema for the contract.
|
|
137
|
+
*
|
|
138
|
+
* @see {@link https://orpc.dev/docs/procedure#input-output-validation Input Validation Docs}
|
|
139
|
+
*/
|
|
173
140
|
input<U extends AnySchema>(schema: U): ContractProcedureBuilderWithInputOutput<U, TOutputSchema, TErrorMap, TMeta>;
|
|
174
141
|
}
|
|
175
142
|
interface ContractProcedureBuilderWithInputOutput<TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta> extends ContractProcedure<TInputSchema, TOutputSchema, TErrorMap, TMeta> {
|
|
143
|
+
/**
|
|
144
|
+
* Adds type-safe custom errors to the contract.
|
|
145
|
+
* The provided errors are spared-merged with any existing errors in the contract.
|
|
146
|
+
*
|
|
147
|
+
* @see {@link https://orpc.dev/docs/error-handling#type%E2%80%90safe-error-handling Type-Safe Error Handling Docs}
|
|
148
|
+
*/
|
|
176
149
|
errors<U extends ErrorMap>(errors: U): ContractProcedureBuilderWithInputOutput<TInputSchema, TOutputSchema, MergedErrorMap<TErrorMap, U>, TMeta>;
|
|
150
|
+
/**
|
|
151
|
+
* Sets or updates the metadata for the contract.
|
|
152
|
+
* The provided metadata is spared-merged with any existing metadata in the contract.
|
|
153
|
+
*
|
|
154
|
+
* @see {@link https://orpc.dev/docs/metadata Metadata Docs}
|
|
155
|
+
*/
|
|
177
156
|
meta(meta: TMeta): ContractProcedureBuilderWithInputOutput<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
|
157
|
+
/**
|
|
158
|
+
* Sets or updates the route definition for the contract.
|
|
159
|
+
* The provided route is spared-merged with any existing route in the contract.
|
|
160
|
+
* This option is typically relevant when integrating with OpenAPI.
|
|
161
|
+
*
|
|
162
|
+
* @see {@link https://orpc.dev/docs/openapi/routing OpenAPI Routing Docs}
|
|
163
|
+
* @see {@link https://orpc.dev/docs/openapi/input-output-structure OpenAPI Input/Output Structure Docs}
|
|
164
|
+
*/
|
|
178
165
|
route(route: Route): ContractProcedureBuilderWithInputOutput<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
|
179
166
|
}
|
|
180
167
|
interface ContractRouterBuilder<TErrorMap extends ErrorMap, TMeta extends Meta> {
|
|
168
|
+
/**
|
|
169
|
+
* This property holds the defined options for the contract router.
|
|
170
|
+
*/
|
|
181
171
|
'~orpc': EnhanceContractRouterOptions<TErrorMap>;
|
|
172
|
+
/**
|
|
173
|
+
* Adds type-safe custom errors to the contract.
|
|
174
|
+
* The provided errors are spared-merged with any existing errors in the contract.
|
|
175
|
+
*
|
|
176
|
+
* @see {@link https://orpc.dev/docs/error-handling#type%E2%80%90safe-error-handling Type-Safe Error Handling Docs}
|
|
177
|
+
*/
|
|
182
178
|
'errors'<U extends ErrorMap>(errors: U): ContractRouterBuilder<MergedErrorMap<TErrorMap, U>, TMeta>;
|
|
179
|
+
/**
|
|
180
|
+
* Prefixes all procedures in the contract router.
|
|
181
|
+
* The provided prefix is post-appended to any existing router prefix.
|
|
182
|
+
*
|
|
183
|
+
* @note This option does not affect procedures that do not define a path in their route definition.
|
|
184
|
+
*
|
|
185
|
+
* @see {@link https://orpc.dev/docs/openapi/routing#route-prefixes OpenAPI Route Prefixes Docs}
|
|
186
|
+
*/
|
|
183
187
|
'prefix'(prefix: HTTPPath): ContractRouterBuilder<TErrorMap, TMeta>;
|
|
188
|
+
/**
|
|
189
|
+
* Adds tags to all procedures in the contract router.
|
|
190
|
+
* This helpful when you want to group procedures together in the OpenAPI specification.
|
|
191
|
+
*
|
|
192
|
+
* @see {@link https://orpc.dev/docs/openapi/openapi-specification#operation-metadata OpenAPI Operation Metadata Docs}
|
|
193
|
+
*/
|
|
184
194
|
'tag'(...tags: string[]): ContractRouterBuilder<TErrorMap, TMeta>;
|
|
195
|
+
/**
|
|
196
|
+
* Applies all of the previously defined options to the specified contract router.
|
|
197
|
+
*
|
|
198
|
+
* @see {@link https://orpc.dev/docs/router#extending-router Extending Router Docs}
|
|
199
|
+
*/
|
|
185
200
|
'router'<T extends ContractRouter<TMeta>>(router: T): EnhancedContractRouter<T, TErrorMap>;
|
|
186
201
|
}
|
|
187
202
|
|
|
188
203
|
interface ContractBuilderDef<TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta> extends ContractProcedureDef<TInputSchema, TOutputSchema, TErrorMap, TMeta>, EnhanceContractRouterOptions<TErrorMap> {
|
|
189
204
|
}
|
|
190
205
|
declare class ContractBuilder<TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta> extends ContractProcedure<TInputSchema, TOutputSchema, TErrorMap, TMeta> {
|
|
206
|
+
/**
|
|
207
|
+
* This property holds the defined options for the contract.
|
|
208
|
+
*/
|
|
191
209
|
'~orpc': ContractBuilderDef<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
|
192
210
|
constructor(def: ContractBuilderDef<TInputSchema, TOutputSchema, TErrorMap, TMeta>);
|
|
193
211
|
/**
|
|
194
|
-
*
|
|
212
|
+
* Sets or overrides the initial meta.
|
|
213
|
+
*
|
|
214
|
+
* @see {@link https://orpc.dev/docs/metadata Metadata Docs}
|
|
195
215
|
*/
|
|
196
216
|
$meta<U extends Meta>(initialMeta: U): ContractBuilder<TInputSchema, TOutputSchema, TErrorMap, U & Record<never, never>>;
|
|
197
217
|
/**
|
|
198
|
-
*
|
|
218
|
+
* Sets or overrides the initial route.
|
|
219
|
+
* This option is typically relevant when integrating with OpenAPI.
|
|
220
|
+
*
|
|
221
|
+
* @see {@link https://orpc.dev/docs/openapi/routing OpenAPI Routing Docs}
|
|
222
|
+
* @see {@link https://orpc.dev/docs/openapi/input-output-structure OpenAPI Input/Output Structure Docs}
|
|
199
223
|
*/
|
|
200
224
|
$route(initialRoute: Route): ContractBuilder<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
|
225
|
+
/**
|
|
226
|
+
* Sets or overrides the initial input schema.
|
|
227
|
+
*
|
|
228
|
+
* @see {@link https://orpc.dev/docs/procedure#initial-configuration Initial Procedure Configuration Docs}
|
|
229
|
+
*/
|
|
230
|
+
$input<U extends AnySchema>(initialInputSchema?: U): ContractBuilder<U, TOutputSchema, TErrorMap, TMeta>;
|
|
231
|
+
/**
|
|
232
|
+
* Adds type-safe custom errors to the contract.
|
|
233
|
+
* The provided errors are spared-merged with any existing errors in the contract.
|
|
234
|
+
*
|
|
235
|
+
* @see {@link https://orpc.dev/docs/error-handling#type%E2%80%90safe-error-handling Type-Safe Error Handling Docs}
|
|
236
|
+
*/
|
|
201
237
|
errors<U extends ErrorMap>(errors: U): ContractBuilder<TInputSchema, TOutputSchema, MergedErrorMap<TErrorMap, U>, TMeta>;
|
|
238
|
+
/**
|
|
239
|
+
* Sets or updates the metadata for the contract.
|
|
240
|
+
* The provided metadata is spared-merged with any existing metadata in the contract.
|
|
241
|
+
*
|
|
242
|
+
* @see {@link https://orpc.dev/docs/metadata Metadata Docs}
|
|
243
|
+
*/
|
|
202
244
|
meta(meta: TMeta): ContractProcedureBuilder<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
|
245
|
+
/**
|
|
246
|
+
* Sets or updates the route definition for the contract.
|
|
247
|
+
* The provided route is spared-merged with any existing route in the contract.
|
|
248
|
+
* This option is typically relevant when integrating with OpenAPI.
|
|
249
|
+
*
|
|
250
|
+
* @see {@link https://orpc.dev/docs/openapi/routing OpenAPI Routing Docs}
|
|
251
|
+
* @see {@link https://orpc.dev/docs/openapi/input-output-structure OpenAPI Input/Output Structure Docs}
|
|
252
|
+
*/
|
|
203
253
|
route(route: Route): ContractProcedureBuilder<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
|
254
|
+
/**
|
|
255
|
+
* Defines the input validation schema for the contract.
|
|
256
|
+
*
|
|
257
|
+
* @see {@link https://orpc.dev/docs/procedure#input-output-validation Input Validation Docs}
|
|
258
|
+
*/
|
|
204
259
|
input<U extends AnySchema>(schema: U): ContractProcedureBuilderWithInput<U, TOutputSchema, TErrorMap, TMeta>;
|
|
260
|
+
/**
|
|
261
|
+
* Defines the output validation schema for the contract.
|
|
262
|
+
*
|
|
263
|
+
* @see {@link https://orpc.dev/docs/procedure#input-output-validation Output Validation Docs}
|
|
264
|
+
*/
|
|
205
265
|
output<U extends AnySchema>(schema: U): ContractProcedureBuilderWithOutput<TInputSchema, U, TErrorMap, TMeta>;
|
|
266
|
+
/**
|
|
267
|
+
* Prefixes all procedures in the contract router.
|
|
268
|
+
* The provided prefix is post-appended to any existing router prefix.
|
|
269
|
+
*
|
|
270
|
+
* @note This option does not affect procedures that do not define a path in their route definition.
|
|
271
|
+
*
|
|
272
|
+
* @see {@link https://orpc.dev/docs/openapi/routing#route-prefixes OpenAPI Route Prefixes Docs}
|
|
273
|
+
*/
|
|
206
274
|
prefix(prefix: HTTPPath): ContractRouterBuilder<TErrorMap, TMeta>;
|
|
275
|
+
/**
|
|
276
|
+
* Adds tags to all procedures in the contract router.
|
|
277
|
+
* This helpful when you want to group procedures together in the OpenAPI specification.
|
|
278
|
+
*
|
|
279
|
+
* @see {@link https://orpc.dev/docs/openapi/openapi-specification#operation-metadata OpenAPI Operation Metadata Docs}
|
|
280
|
+
*/
|
|
207
281
|
tag(...tags: string[]): ContractRouterBuilder<TErrorMap, TMeta>;
|
|
282
|
+
/**
|
|
283
|
+
* Applies all of the previously defined options to the specified contract router.
|
|
284
|
+
*
|
|
285
|
+
* @see {@link https://orpc.dev/docs/router#extending-router Extending Router Docs}
|
|
286
|
+
*/
|
|
208
287
|
router<T extends ContractRouter<TMeta>>(router: T): EnhancedContractRouter<T, TErrorMap>;
|
|
209
288
|
}
|
|
210
289
|
declare const oc: ContractBuilder<Schema<unknown, unknown>, Schema<unknown, unknown>, Record<never, never>, Record<never, never>>;
|
|
@@ -222,13 +301,28 @@ interface EventIteratorSchemaDetails {
|
|
|
222
301
|
yields: AnySchema;
|
|
223
302
|
returns?: AnySchema;
|
|
224
303
|
}
|
|
225
|
-
|
|
304
|
+
/**
|
|
305
|
+
* Define schema for an event iterator.
|
|
306
|
+
*
|
|
307
|
+
* @see {@link https://orpc.dev/docs/event-iterator#validate-event-iterator Validate Event Iterator Docs}
|
|
308
|
+
*/
|
|
309
|
+
declare function eventIterator<TYieldIn, TYieldOut, TReturnIn = unknown, TReturnOut = unknown>(yields: Schema<TYieldIn, TYieldOut>, returns?: Schema<TReturnIn, TReturnOut>): Schema<AsyncIteratorObject<TYieldIn, TReturnIn, void>, AsyncIteratorClass<TYieldOut, TReturnOut, void>>;
|
|
226
310
|
declare function getEventIteratorSchemaDetails(schema: AnySchema | undefined): undefined | EventIteratorSchemaDetails;
|
|
227
311
|
|
|
312
|
+
/**
|
|
313
|
+
* Help RPCLink automatically send requests using the specified HTTP method in the contract.
|
|
314
|
+
*
|
|
315
|
+
* @see {@link https://orpc.dev/docs/client/rpc-link#custom-request-method RPCLink Custom Request Method}
|
|
316
|
+
*/
|
|
317
|
+
declare function inferRPCMethodFromContractRouter(contract: AnyContractRouter): (options: unknown, path: readonly string[]) => Exclude<HTTPMethod, 'HEAD'>;
|
|
318
|
+
|
|
228
319
|
type ContractProcedureClient<TClientContext extends ClientContext, TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap> = Client<TClientContext, InferSchemaInput<TInputSchema>, InferSchemaOutput<TOutputSchema>, ErrorFromErrorMap<TErrorMap>>;
|
|
229
320
|
|
|
230
321
|
type ContractRouterClient<TRouter extends AnyContractRouter, TClientContext extends ClientContext = Record<never, never>> = TRouter extends ContractProcedure<infer UInputSchema, infer UOutputSchema, infer UErrorMap, any> ? ContractProcedureClient<TClientContext, UInputSchema, UOutputSchema, UErrorMap> : {
|
|
231
322
|
[K in keyof TRouter]: TRouter[K] extends AnyContractRouter ? ContractRouterClient<TRouter[K], TClientContext> : never;
|
|
232
323
|
};
|
|
233
324
|
|
|
234
|
-
|
|
325
|
+
declare function isSchemaIssue(issue: unknown): issue is SchemaIssue;
|
|
326
|
+
|
|
327
|
+
export { AnyContractRouter, AnySchema, ContractBuilder, ContractProcedure, ContractProcedureDef, ContractRouter, EnhanceRouteOptions, ErrorFromErrorMap, ErrorMap, InferSchemaInput, InferSchemaOutput, InputStructure, MergedErrorMap, Meta, OutputStructure, Route, Schema, SchemaIssue, enhanceContractRouter, eventIterator, fallbackContractConfig, getContractRouter, getEventIteratorSchemaDetails, inferRPCMethodFromContractRouter, isSchemaIssue, minifyContractRouter, oc, populateContractRouterPaths };
|
|
328
|
+
export type { ContractBuilderDef, ContractConfig, ContractProcedureBuilder, ContractProcedureBuilderWithInput, ContractProcedureBuilderWithInputOutput, ContractProcedureBuilderWithOutput, ContractProcedureClient, ContractRouterBuilder, ContractRouterClient, EnhanceContractRouterOptions, EnhancedContractRouter, EventIteratorSchemaDetails, PopulateContractRouterPathsOptions, PopulatedContractRouterPaths };
|