@orpc/contract 0.0.0-next.e563486 → 0.0.0-next.e565e67
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 +31 -22
- package/dist/index.d.mts +221 -150
- package/dist/index.d.ts +221 -150
- package/dist/index.mjs +109 -35
- 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.CvRxURhn.d.mts +254 -0
- package/dist/shared/contract.CvRxURhn.d.ts +254 -0
- package/dist/shared/contract.D_dZrO__.mjs +53 -0
- package/package.json +12 -7
package/README.md
CHANGED
|
@@ -17,32 +17,31 @@
|
|
|
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/unnoq/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
|
|
|
@@ -53,12 +52,14 @@ You can find the full documentation [here](https://orpc.unnoq.com).
|
|
|
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.
|
|
56
|
-
- [@orpc/react-query](https://www.npmjs.com/package/@orpc/react-query): Integration with [React Query](https://tanstack.com/query/latest/docs/framework/react/overview).
|
|
57
|
-
- [@orpc/vue-query](https://www.npmjs.com/package/@orpc/vue-query): Integration with [Vue Query](https://tanstack.com/query/latest/docs/framework/vue/overview).
|
|
58
|
-
- [@orpc/solid-query](https://www.npmjs.com/package/@orpc/solid-query): Integration with [Solid Query](https://tanstack.com/query/latest/docs/framework/solid/overview).
|
|
59
|
-
- [@orpc/svelte-query](https://www.npmjs.com/package/@orpc/svelte-query): Integration with [Svelte Query](https://tanstack.com/query/latest/docs/framework/svelte/overview).
|
|
60
|
-
- [@orpc/vue-colada](https://www.npmjs.com/package/@orpc/vue-colada): Integration with [Pinia Colada](https://pinia-colada.esm.dev/).
|
|
61
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/).
|
|
58
|
+
- [@orpc/react](https://www.npmjs.com/package/@orpc/react): Utilities for integrating oRPC with React and React Server Actions.
|
|
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
|
+
- [@orpc/vue-colada](https://www.npmjs.com/package/@orpc/vue-colada): Integration with [Pinia Colada](https://pinia-colada.esm.dev/).
|
|
62
|
+
- [@orpc/hey-api](https://www.npmjs.com/package/@orpc/hey-api): [Hey API](https://heyapi.dev/) integration.
|
|
62
63
|
- [@orpc/zod](https://www.npmjs.com/package/@orpc/zod): More schemas that [Zod](https://zod.dev/) doesn't support yet.
|
|
63
64
|
- [@orpc/valibot](https://www.npmjs.com/package/@orpc/valibot): OpenAPI spec generation from [Valibot](https://valibot.dev/).
|
|
64
65
|
- [@orpc/arktype](https://www.npmjs.com/package/@orpc/arktype): OpenAPI spec generation from [ArkType](https://arktype.io/).
|
|
@@ -100,6 +101,14 @@ export const contract = {
|
|
|
100
101
|
}
|
|
101
102
|
```
|
|
102
103
|
|
|
104
|
+
## Sponsors
|
|
105
|
+
|
|
106
|
+
<p align="center">
|
|
107
|
+
<a href="https://cdn.jsdelivr.net/gh/unnoq/unnoq/sponsors.svg">
|
|
108
|
+
<img src='https://cdn.jsdelivr.net/gh/unnoq/unnoq/sponsors.svg'/>
|
|
109
|
+
</a>
|
|
110
|
+
</p>
|
|
111
|
+
|
|
103
112
|
## License
|
|
104
113
|
|
|
105
114
|
Distributed under the MIT License. See [LICENSE](https://github.com/unnoq/orpc/blob/main/LICENSE) for more information.
|
package/dist/index.d.mts
CHANGED
|
@@ -1,212 +1,268 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export { ORPCError } from '@orpc/client';
|
|
3
|
-
import {
|
|
4
|
-
|
|
1
|
+
import { HTTPPath, HTTPMethod, ClientContext, Client } from '@orpc/client';
|
|
2
|
+
export { HTTPMethod, HTTPPath, ORPCError } from '@orpc/client';
|
|
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.CvRxURhn.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.CvRxURhn.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';
|
|
5
9
|
|
|
6
|
-
|
|
7
|
-
type
|
|
8
|
-
|
|
9
|
-
type InferSchemaInput<T extends AnySchema> = T extends StandardSchemaV1<infer UInput, any> ? UInput : never;
|
|
10
|
-
type InferSchemaOutput<T extends AnySchema> = T extends StandardSchemaV1<any, infer UOutput> ? UOutput : never;
|
|
11
|
-
type TypeRest<TInput, TOutput> = [map: (input: TInput) => Promisable<TOutput>] | (IsEqual<TInput, TOutput> extends true ? [] : never);
|
|
12
|
-
declare function type<TInput, TOutput = TInput>(...[map]: TypeRest<TInput, TOutput>): Schema<TInput, TOutput>;
|
|
13
|
-
|
|
14
|
-
interface ValidationErrorOptions extends ErrorOptions {
|
|
15
|
-
message: string;
|
|
16
|
-
issues: readonly SchemaIssue[];
|
|
17
|
-
}
|
|
18
|
-
declare class ValidationError extends Error {
|
|
19
|
-
readonly issues: readonly SchemaIssue[];
|
|
20
|
-
constructor(options: ValidationErrorOptions);
|
|
21
|
-
}
|
|
22
|
-
interface ErrorMapItem<TDataSchema extends AnySchema> {
|
|
23
|
-
status?: number;
|
|
24
|
-
message?: string;
|
|
25
|
-
description?: string;
|
|
26
|
-
data?: TDataSchema;
|
|
27
|
-
}
|
|
28
|
-
type ErrorMap = {
|
|
29
|
-
[key in ORPCErrorCode]?: ErrorMapItem<AnySchema>;
|
|
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;
|
|
30
13
|
};
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
14
|
+
interface EnhanceContractRouterOptions<TErrorMap extends ErrorMap> extends EnhanceRouteOptions {
|
|
15
|
+
errorMap: TErrorMap;
|
|
16
|
+
}
|
|
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.unnoq.com/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;
|
|
40
27
|
|
|
41
|
-
|
|
42
|
-
type HTTPMethod = 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH';
|
|
43
|
-
type InputStructure = 'compact' | 'detailed';
|
|
44
|
-
type OutputStructure = 'compact' | 'detailed';
|
|
45
|
-
interface Route {
|
|
46
|
-
method?: HTTPMethod;
|
|
47
|
-
path?: HTTPPath;
|
|
48
|
-
summary?: string;
|
|
49
|
-
description?: string;
|
|
50
|
-
deprecated?: boolean;
|
|
51
|
-
tags?: readonly string[];
|
|
28
|
+
interface ContractProcedureBuilder<TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta> extends ContractProcedure<TInputSchema, TOutputSchema, TErrorMap, TMeta> {
|
|
52
29
|
/**
|
|
53
|
-
*
|
|
30
|
+
* Adds type-safe custom errors to the contract.
|
|
31
|
+
* The provided errors are spared-merged with any existing errors in the contract.
|
|
54
32
|
*
|
|
55
|
-
* @
|
|
33
|
+
* @see {@link https://orpc.unnoq.com/docs/error-handling#type%E2%80%90safe-error-handling Type-Safe Error Handling Docs}
|
|
56
34
|
*/
|
|
57
|
-
|
|
35
|
+
errors<U extends ErrorMap>(errors: U): ContractProcedureBuilder<TInputSchema, TOutputSchema, MergedErrorMap<TErrorMap, U>, TMeta>;
|
|
58
36
|
/**
|
|
59
|
-
*
|
|
37
|
+
* Sets or updates the metadata for the contract.
|
|
38
|
+
* The provided metadata is spared-merged with any existing metadata in the contract.
|
|
60
39
|
*
|
|
61
|
-
* @
|
|
40
|
+
* @see {@link https://orpc.unnoq.com/docs/metadata Metadata Docs}
|
|
62
41
|
*/
|
|
63
|
-
|
|
42
|
+
meta(meta: TMeta): ContractProcedureBuilder<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
|
64
43
|
/**
|
|
65
|
-
*
|
|
66
|
-
*
|
|
67
|
-
*
|
|
68
|
-
* Combines `params` and either `query` or `body` (depending on the HTTP method) into a single object.
|
|
44
|
+
* Sets or updates the route definition for the contract.
|
|
45
|
+
* The provided route is spared-merged with any existing route in the contract.
|
|
46
|
+
* This option is typically relevant when integrating with OpenAPI.
|
|
69
47
|
*
|
|
70
|
-
* @
|
|
71
|
-
*
|
|
72
|
-
*
|
|
73
|
-
* Example:
|
|
74
|
-
* ```ts
|
|
75
|
-
* const input = {
|
|
76
|
-
* params: { id: 1 },
|
|
77
|
-
* query: { search: 'hello' },
|
|
78
|
-
* headers: { 'Content-Type': 'application/json' },
|
|
79
|
-
* body: { name: 'John' },
|
|
80
|
-
* }
|
|
81
|
-
* ```
|
|
82
|
-
*
|
|
83
|
-
* @default 'compact'
|
|
48
|
+
* @see {@link https://orpc.unnoq.com/docs/openapi/routing OpenAPI Routing Docs}
|
|
49
|
+
* @see {@link https://orpc.unnoq.com/docs/openapi/input-output-structure OpenAPI Input/Output Structure Docs}
|
|
84
50
|
*/
|
|
85
|
-
|
|
51
|
+
route(route: Route): ContractProcedureBuilder<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
|
86
52
|
/**
|
|
87
|
-
*
|
|
88
|
-
*
|
|
89
|
-
* @option 'compact'
|
|
90
|
-
* Includes only the body data, encoded directly in the response.
|
|
53
|
+
* Defines the input validation schema for the contract.
|
|
91
54
|
*
|
|
92
|
-
* @
|
|
93
|
-
* Separates the output into `headers` and `body` fields.
|
|
94
|
-
* - `headers`: Custom headers to merge with the response headers.
|
|
95
|
-
* - `body`: The response data.
|
|
96
|
-
*
|
|
97
|
-
* Example:
|
|
98
|
-
* ```ts
|
|
99
|
-
* const output = {
|
|
100
|
-
* headers: { 'x-custom-header': 'value' },
|
|
101
|
-
* body: { message: 'Hello, world!' },
|
|
102
|
-
* };
|
|
103
|
-
* ```
|
|
104
|
-
*
|
|
105
|
-
* @default 'compact'
|
|
55
|
+
* @see {@link https://orpc.unnoq.com/docs/procedure#input-output-validation Input Validation Docs}
|
|
106
56
|
*/
|
|
107
|
-
outputStructure?: OutputStructure;
|
|
108
|
-
}
|
|
109
|
-
declare function mergeRoute(a: Route, b: Route): Route;
|
|
110
|
-
declare function prefixRoute(route: Route, prefix: HTTPPath): Route;
|
|
111
|
-
declare function unshiftTagRoute(route: Route, tags: readonly string[]): Route;
|
|
112
|
-
declare function mergePrefix(a: HTTPPath | undefined, b: HTTPPath): HTTPPath;
|
|
113
|
-
declare function mergeTags(a: readonly string[] | undefined, b: readonly string[]): readonly string[];
|
|
114
|
-
interface EnhanceRouteOptions {
|
|
115
|
-
prefix?: HTTPPath;
|
|
116
|
-
tags?: readonly string[];
|
|
117
|
-
}
|
|
118
|
-
declare function enhanceRoute(route: Route, options: EnhanceRouteOptions): Route;
|
|
119
|
-
|
|
120
|
-
interface ContractProcedureDef<TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta> {
|
|
121
|
-
meta: TMeta;
|
|
122
|
-
route: Route;
|
|
123
|
-
inputSchema?: TInputSchema;
|
|
124
|
-
outputSchema?: TOutputSchema;
|
|
125
|
-
errorMap: TErrorMap;
|
|
126
|
-
}
|
|
127
|
-
declare class ContractProcedure<TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta> {
|
|
128
|
-
'~orpc': ContractProcedureDef<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
|
129
|
-
constructor(def: ContractProcedureDef<TInputSchema, TOutputSchema, TErrorMap, TMeta>);
|
|
130
|
-
}
|
|
131
|
-
type AnyContractProcedure = ContractProcedure<any, any, any, any>;
|
|
132
|
-
declare function isContractProcedure(item: unknown): item is AnyContractProcedure;
|
|
133
|
-
|
|
134
|
-
type ContractRouter<TMeta extends Meta> = ContractProcedure<any, any, any, TMeta> | {
|
|
135
|
-
[k: string]: ContractRouter<TMeta>;
|
|
136
|
-
};
|
|
137
|
-
type AnyContractRouter = ContractRouter<any>;
|
|
138
|
-
type InferContractRouterInputs<T extends AnyContractRouter> = T extends ContractProcedure<infer UInputSchema, any, any, any> ? InferSchemaInput<UInputSchema> : {
|
|
139
|
-
[K in keyof T]: T[K] extends AnyContractRouter ? InferContractRouterInputs<T[K]> : never;
|
|
140
|
-
};
|
|
141
|
-
type InferContractRouterOutputs<T extends AnyContractRouter> = T extends ContractProcedure<any, infer UOutputSchema, any, any> ? InferSchemaOutput<UOutputSchema> : {
|
|
142
|
-
[K in keyof T]: T[K] extends AnyContractRouter ? InferContractRouterOutputs<T[K]> : never;
|
|
143
|
-
};
|
|
144
|
-
type InferContractRouterErrorMap<T extends AnyContractRouter> = T extends ContractProcedure<any, any, infer UErrorMap, any> ? UErrorMap : {
|
|
145
|
-
[K in keyof T]: T[K] extends AnyContractRouter ? InferContractRouterErrorMap<T[K]> : never;
|
|
146
|
-
}[keyof T];
|
|
147
|
-
type InferContractRouterMeta<T extends AnyContractRouter> = T extends ContractRouter<infer UMeta> ? UMeta : never;
|
|
148
|
-
|
|
149
|
-
declare function getContractRouter(router: AnyContractRouter, path: readonly string[]): AnyContractRouter | undefined;
|
|
150
|
-
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> : {
|
|
151
|
-
[K in keyof T]: T[K] extends AnyContractRouter ? EnhancedContractRouter<T[K], TErrorMap> : never;
|
|
152
|
-
};
|
|
153
|
-
interface EnhanceContractRouterOptions<TErrorMap extends ErrorMap> extends EnhanceRouteOptions {
|
|
154
|
-
errorMap: TErrorMap;
|
|
155
|
-
}
|
|
156
|
-
declare function enhanceContractRouter<T extends AnyContractRouter, TErrorMap extends ErrorMap>(router: T, options: EnhanceContractRouterOptions<TErrorMap>): EnhancedContractRouter<T, TErrorMap>;
|
|
157
|
-
|
|
158
|
-
interface ContractProcedureBuilder<TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta> extends ContractProcedure<TInputSchema, TOutputSchema, TErrorMap, TMeta> {
|
|
159
|
-
errors<U extends ErrorMap>(errors: U): ContractProcedureBuilder<TInputSchema, TOutputSchema, MergedErrorMap<TErrorMap, U>, TMeta>;
|
|
160
|
-
meta(meta: TMeta): ContractProcedureBuilder<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
|
161
|
-
route(route: Route): ContractProcedureBuilder<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
|
162
57
|
input<U extends AnySchema>(schema: U): ContractProcedureBuilderWithInput<U, TOutputSchema, TErrorMap, TMeta>;
|
|
58
|
+
/**
|
|
59
|
+
* Defines the output validation schema for the contract.
|
|
60
|
+
*
|
|
61
|
+
* @see {@link https://orpc.unnoq.com/docs/procedure#input-output-validation Output Validation Docs}
|
|
62
|
+
*/
|
|
163
63
|
output<U extends AnySchema>(schema: U): ContractProcedureBuilderWithOutput<TInputSchema, U, TErrorMap, TMeta>;
|
|
164
64
|
}
|
|
165
65
|
interface ContractProcedureBuilderWithInput<TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta> extends ContractProcedure<TInputSchema, TOutputSchema, TErrorMap, TMeta> {
|
|
66
|
+
/**
|
|
67
|
+
* Adds type-safe custom errors to the contract.
|
|
68
|
+
* The provided errors are spared-merged with any existing errors in the contract.
|
|
69
|
+
*
|
|
70
|
+
* @see {@link https://orpc.unnoq.com/docs/error-handling#type%E2%80%90safe-error-handling Type-Safe Error Handling Docs}
|
|
71
|
+
*/
|
|
166
72
|
errors<U extends ErrorMap>(errors: U): ContractProcedureBuilderWithInput<TInputSchema, TOutputSchema, MergedErrorMap<TErrorMap, U>, TMeta>;
|
|
73
|
+
/**
|
|
74
|
+
* Sets or updates the metadata for the contract.
|
|
75
|
+
* The provided metadata is spared-merged with any existing metadata in the contract.
|
|
76
|
+
*
|
|
77
|
+
* @see {@link https://orpc.unnoq.com/docs/metadata Metadata Docs}
|
|
78
|
+
*/
|
|
167
79
|
meta(meta: TMeta): ContractProcedureBuilderWithInput<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
|
80
|
+
/**
|
|
81
|
+
* Sets or updates the route definition for the contract.
|
|
82
|
+
* The provided route is spared-merged with any existing route in the contract.
|
|
83
|
+
* This option is typically relevant when integrating with OpenAPI.
|
|
84
|
+
*
|
|
85
|
+
* @see {@link https://orpc.unnoq.com/docs/openapi/routing OpenAPI Routing Docs}
|
|
86
|
+
* @see {@link https://orpc.unnoq.com/docs/openapi/input-output-structure OpenAPI Input/Output Structure Docs}
|
|
87
|
+
*/
|
|
168
88
|
route(route: Route): ContractProcedureBuilderWithInput<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
|
89
|
+
/**
|
|
90
|
+
* Defines the output validation schema for the contract.
|
|
91
|
+
*
|
|
92
|
+
* @see {@link https://orpc.unnoq.com/docs/procedure#input-output-validation Output Validation Docs}
|
|
93
|
+
*/
|
|
169
94
|
output<U extends AnySchema>(schema: U): ContractProcedureBuilderWithInputOutput<TInputSchema, U, TErrorMap, TMeta>;
|
|
170
95
|
}
|
|
171
96
|
interface ContractProcedureBuilderWithOutput<TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta> extends ContractProcedure<TInputSchema, TOutputSchema, TErrorMap, TMeta> {
|
|
97
|
+
/**
|
|
98
|
+
* Adds type-safe custom errors to the contract.
|
|
99
|
+
* The provided errors are spared-merged with any existing errors in the contract.
|
|
100
|
+
*
|
|
101
|
+
* @see {@link https://orpc.unnoq.com/docs/error-handling#type%E2%80%90safe-error-handling Type-Safe Error Handling Docs}
|
|
102
|
+
*/
|
|
172
103
|
errors<U extends ErrorMap>(errors: U): ContractProcedureBuilderWithOutput<TInputSchema, TOutputSchema, MergedErrorMap<TErrorMap, U>, TMeta>;
|
|
104
|
+
/**
|
|
105
|
+
* Sets or updates the metadata for the contract.
|
|
106
|
+
* The provided metadata is spared-merged with any existing metadata in the contract.
|
|
107
|
+
*
|
|
108
|
+
* @see {@link https://orpc.unnoq.com/docs/metadata Metadata Docs}
|
|
109
|
+
*/
|
|
173
110
|
meta(meta: TMeta): ContractProcedureBuilderWithOutput<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
|
111
|
+
/**
|
|
112
|
+
* Sets or updates the route definition for the contract.
|
|
113
|
+
* The provided route is spared-merged with any existing route in the contract.
|
|
114
|
+
* This option is typically relevant when integrating with OpenAPI.
|
|
115
|
+
*
|
|
116
|
+
* @see {@link https://orpc.unnoq.com/docs/openapi/routing OpenAPI Routing Docs}
|
|
117
|
+
* @see {@link https://orpc.unnoq.com/docs/openapi/input-output-structure OpenAPI Input/Output Structure Docs}
|
|
118
|
+
*/
|
|
174
119
|
route(route: Route): ContractProcedureBuilderWithOutput<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
|
120
|
+
/**
|
|
121
|
+
* Defines the input validation schema for the contract.
|
|
122
|
+
*
|
|
123
|
+
* @see {@link https://orpc.unnoq.com/docs/procedure#input-output-validation Input Validation Docs}
|
|
124
|
+
*/
|
|
175
125
|
input<U extends AnySchema>(schema: U): ContractProcedureBuilderWithInputOutput<U, TOutputSchema, TErrorMap, TMeta>;
|
|
176
126
|
}
|
|
177
127
|
interface ContractProcedureBuilderWithInputOutput<TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta> extends ContractProcedure<TInputSchema, TOutputSchema, TErrorMap, TMeta> {
|
|
128
|
+
/**
|
|
129
|
+
* Adds type-safe custom errors to the contract.
|
|
130
|
+
* The provided errors are spared-merged with any existing errors in the contract.
|
|
131
|
+
*
|
|
132
|
+
* @see {@link https://orpc.unnoq.com/docs/error-handling#type%E2%80%90safe-error-handling Type-Safe Error Handling Docs}
|
|
133
|
+
*/
|
|
178
134
|
errors<U extends ErrorMap>(errors: U): ContractProcedureBuilderWithInputOutput<TInputSchema, TOutputSchema, MergedErrorMap<TErrorMap, U>, TMeta>;
|
|
135
|
+
/**
|
|
136
|
+
* Sets or updates the metadata for the contract.
|
|
137
|
+
* The provided metadata is spared-merged with any existing metadata in the contract.
|
|
138
|
+
*
|
|
139
|
+
* @see {@link https://orpc.unnoq.com/docs/metadata Metadata Docs}
|
|
140
|
+
*/
|
|
179
141
|
meta(meta: TMeta): ContractProcedureBuilderWithInputOutput<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
|
142
|
+
/**
|
|
143
|
+
* Sets or updates the route definition for the contract.
|
|
144
|
+
* The provided route is spared-merged with any existing route in the contract.
|
|
145
|
+
* This option is typically relevant when integrating with OpenAPI.
|
|
146
|
+
*
|
|
147
|
+
* @see {@link https://orpc.unnoq.com/docs/openapi/routing OpenAPI Routing Docs}
|
|
148
|
+
* @see {@link https://orpc.unnoq.com/docs/openapi/input-output-structure OpenAPI Input/Output Structure Docs}
|
|
149
|
+
*/
|
|
180
150
|
route(route: Route): ContractProcedureBuilderWithInputOutput<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
|
181
151
|
}
|
|
182
152
|
interface ContractRouterBuilder<TErrorMap extends ErrorMap, TMeta extends Meta> {
|
|
153
|
+
/**
|
|
154
|
+
* This property holds the defined options for the contract router.
|
|
155
|
+
*/
|
|
183
156
|
'~orpc': EnhanceContractRouterOptions<TErrorMap>;
|
|
157
|
+
/**
|
|
158
|
+
* Adds type-safe custom errors to the contract.
|
|
159
|
+
* The provided errors are spared-merged with any existing errors in the contract.
|
|
160
|
+
*
|
|
161
|
+
* @see {@link https://orpc.unnoq.com/docs/error-handling#type%E2%80%90safe-error-handling Type-Safe Error Handling Docs}
|
|
162
|
+
*/
|
|
184
163
|
'errors'<U extends ErrorMap>(errors: U): ContractRouterBuilder<MergedErrorMap<TErrorMap, U>, TMeta>;
|
|
164
|
+
/**
|
|
165
|
+
* Prefixes all procedures in the contract router.
|
|
166
|
+
* The provided prefix is post-appended to any existing router prefix.
|
|
167
|
+
*
|
|
168
|
+
* @note This option does not affect procedures that do not define a path in their route definition.
|
|
169
|
+
*
|
|
170
|
+
* @see {@link https://orpc.unnoq.com/docs/openapi/routing#route-prefixes OpenAPI Route Prefixes Docs}
|
|
171
|
+
*/
|
|
185
172
|
'prefix'(prefix: HTTPPath): ContractRouterBuilder<TErrorMap, TMeta>;
|
|
173
|
+
/**
|
|
174
|
+
* Adds tags to all procedures in the contract router.
|
|
175
|
+
* This helpful when you want to group procedures together in the OpenAPI specification.
|
|
176
|
+
*
|
|
177
|
+
* @see {@link https://orpc.unnoq.com/docs/openapi/openapi-specification#operation-metadata OpenAPI Operation Metadata Docs}
|
|
178
|
+
*/
|
|
186
179
|
'tag'(...tags: string[]): ContractRouterBuilder<TErrorMap, TMeta>;
|
|
180
|
+
/**
|
|
181
|
+
* Applies all of the previously defined options to the specified contract router.
|
|
182
|
+
*
|
|
183
|
+
* @see {@link https://orpc.unnoq.com/docs/router#extending-router Extending Router Docs}
|
|
184
|
+
*/
|
|
187
185
|
'router'<T extends ContractRouter<TMeta>>(router: T): EnhancedContractRouter<T, TErrorMap>;
|
|
188
186
|
}
|
|
189
187
|
|
|
190
188
|
interface ContractBuilderDef<TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta> extends ContractProcedureDef<TInputSchema, TOutputSchema, TErrorMap, TMeta>, EnhanceContractRouterOptions<TErrorMap> {
|
|
191
189
|
}
|
|
192
190
|
declare class ContractBuilder<TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta> extends ContractProcedure<TInputSchema, TOutputSchema, TErrorMap, TMeta> {
|
|
191
|
+
/**
|
|
192
|
+
* This property holds the defined options for the contract.
|
|
193
|
+
*/
|
|
193
194
|
'~orpc': ContractBuilderDef<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
|
194
195
|
constructor(def: ContractBuilderDef<TInputSchema, TOutputSchema, TErrorMap, TMeta>);
|
|
195
196
|
/**
|
|
196
|
-
*
|
|
197
|
+
* Sets or overrides the initial meta.
|
|
198
|
+
*
|
|
199
|
+
* @see {@link https://orpc.unnoq.com/docs/metadata Metadata Docs}
|
|
197
200
|
*/
|
|
198
201
|
$meta<U extends Meta>(initialMeta: U): ContractBuilder<TInputSchema, TOutputSchema, TErrorMap, U & Record<never, never>>;
|
|
199
202
|
/**
|
|
200
|
-
*
|
|
203
|
+
* Sets or overrides the initial route.
|
|
204
|
+
* This option is typically relevant when integrating with OpenAPI.
|
|
205
|
+
*
|
|
206
|
+
* @see {@link https://orpc.unnoq.com/docs/openapi/routing OpenAPI Routing Docs}
|
|
207
|
+
* @see {@link https://orpc.unnoq.com/docs/openapi/input-output-structure OpenAPI Input/Output Structure Docs}
|
|
201
208
|
*/
|
|
202
209
|
$route(initialRoute: Route): ContractBuilder<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
|
210
|
+
/**
|
|
211
|
+
* Adds type-safe custom errors to the contract.
|
|
212
|
+
* The provided errors are spared-merged with any existing errors in the contract.
|
|
213
|
+
*
|
|
214
|
+
* @see {@link https://orpc.unnoq.com/docs/error-handling#type%E2%80%90safe-error-handling Type-Safe Error Handling Docs}
|
|
215
|
+
*/
|
|
203
216
|
errors<U extends ErrorMap>(errors: U): ContractBuilder<TInputSchema, TOutputSchema, MergedErrorMap<TErrorMap, U>, TMeta>;
|
|
217
|
+
/**
|
|
218
|
+
* Sets or updates the metadata for the contract.
|
|
219
|
+
* The provided metadata is spared-merged with any existing metadata in the contract.
|
|
220
|
+
*
|
|
221
|
+
* @see {@link https://orpc.unnoq.com/docs/metadata Metadata Docs}
|
|
222
|
+
*/
|
|
204
223
|
meta(meta: TMeta): ContractProcedureBuilder<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
|
224
|
+
/**
|
|
225
|
+
* Sets or updates the route definition for the contract.
|
|
226
|
+
* The provided route is spared-merged with any existing route in the contract.
|
|
227
|
+
* This option is typically relevant when integrating with OpenAPI.
|
|
228
|
+
*
|
|
229
|
+
* @see {@link https://orpc.unnoq.com/docs/openapi/routing OpenAPI Routing Docs}
|
|
230
|
+
* @see {@link https://orpc.unnoq.com/docs/openapi/input-output-structure OpenAPI Input/Output Structure Docs}
|
|
231
|
+
*/
|
|
205
232
|
route(route: Route): ContractProcedureBuilder<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
|
233
|
+
/**
|
|
234
|
+
* Defines the input validation schema for the contract.
|
|
235
|
+
*
|
|
236
|
+
* @see {@link https://orpc.unnoq.com/docs/procedure#input-output-validation Input Validation Docs}
|
|
237
|
+
*/
|
|
206
238
|
input<U extends AnySchema>(schema: U): ContractProcedureBuilderWithInput<U, TOutputSchema, TErrorMap, TMeta>;
|
|
239
|
+
/**
|
|
240
|
+
* Defines the output validation schema for the contract.
|
|
241
|
+
*
|
|
242
|
+
* @see {@link https://orpc.unnoq.com/docs/procedure#input-output-validation Output Validation Docs}
|
|
243
|
+
*/
|
|
207
244
|
output<U extends AnySchema>(schema: U): ContractProcedureBuilderWithOutput<TInputSchema, U, TErrorMap, TMeta>;
|
|
245
|
+
/**
|
|
246
|
+
* Prefixes all procedures in the contract router.
|
|
247
|
+
* The provided prefix is post-appended to any existing router prefix.
|
|
248
|
+
*
|
|
249
|
+
* @note This option does not affect procedures that do not define a path in their route definition.
|
|
250
|
+
*
|
|
251
|
+
* @see {@link https://orpc.unnoq.com/docs/openapi/routing#route-prefixes OpenAPI Route Prefixes Docs}
|
|
252
|
+
*/
|
|
208
253
|
prefix(prefix: HTTPPath): ContractRouterBuilder<TErrorMap, TMeta>;
|
|
254
|
+
/**
|
|
255
|
+
* Adds tags to all procedures in the contract router.
|
|
256
|
+
* This helpful when you want to group procedures together in the OpenAPI specification.
|
|
257
|
+
*
|
|
258
|
+
* @see {@link https://orpc.unnoq.com/docs/openapi/openapi-specification#operation-metadata OpenAPI Operation Metadata Docs}
|
|
259
|
+
*/
|
|
209
260
|
tag(...tags: string[]): ContractRouterBuilder<TErrorMap, TMeta>;
|
|
261
|
+
/**
|
|
262
|
+
* Applies all of the previously defined options to the specified contract router.
|
|
263
|
+
*
|
|
264
|
+
* @see {@link https://orpc.unnoq.com/docs/router#extending-router Extending Router Docs}
|
|
265
|
+
*/
|
|
210
266
|
router<T extends ContractRouter<TMeta>>(router: T): EnhancedContractRouter<T, TErrorMap>;
|
|
211
267
|
}
|
|
212
268
|
declare const oc: ContractBuilder<Schema<unknown, unknown>, Schema<unknown, unknown>, Record<never, never>, Record<never, never>>;
|
|
@@ -224,13 +280,28 @@ interface EventIteratorSchemaDetails {
|
|
|
224
280
|
yields: AnySchema;
|
|
225
281
|
returns?: AnySchema;
|
|
226
282
|
}
|
|
227
|
-
|
|
283
|
+
/**
|
|
284
|
+
* Define schema for an event iterator.
|
|
285
|
+
*
|
|
286
|
+
* @see {@link https://orpc.unnoq.com/docs/event-iterator#validate-event-iterator Validate Event Iterator Docs}
|
|
287
|
+
*/
|
|
288
|
+
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>>;
|
|
228
289
|
declare function getEventIteratorSchemaDetails(schema: AnySchema | undefined): undefined | EventIteratorSchemaDetails;
|
|
229
290
|
|
|
291
|
+
/**
|
|
292
|
+
* Help RPCLink automatically send requests using the specified HTTP method in the contract.
|
|
293
|
+
*
|
|
294
|
+
* @see {@link https://orpc.unnoq.com/docs/client/rpc-link#custom-request-method RPCLink Custom Request Method}
|
|
295
|
+
*/
|
|
296
|
+
declare function inferRPCMethodFromContractRouter(contract: AnyContractRouter): (options: unknown, path: readonly string[]) => Exclude<HTTPMethod, 'HEAD'>;
|
|
297
|
+
|
|
230
298
|
type ContractProcedureClient<TClientContext extends ClientContext, TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap> = Client<TClientContext, InferSchemaInput<TInputSchema>, InferSchemaOutput<TOutputSchema>, ErrorFromErrorMap<TErrorMap>>;
|
|
231
299
|
|
|
232
300
|
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> : {
|
|
233
301
|
[K in keyof TRouter]: TRouter[K] extends AnyContractRouter ? ContractRouterClient<TRouter[K], TClientContext> : never;
|
|
234
302
|
};
|
|
235
303
|
|
|
236
|
-
|
|
304
|
+
declare function isSchemaIssue(issue: unknown): issue is SchemaIssue;
|
|
305
|
+
|
|
306
|
+
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 };
|
|
307
|
+
export type { ContractBuilderDef, ContractConfig, ContractProcedureBuilder, ContractProcedureBuilderWithInput, ContractProcedureBuilderWithInputOutput, ContractProcedureBuilderWithOutput, ContractProcedureClient, ContractRouterBuilder, ContractRouterClient, EnhanceContractRouterOptions, EnhancedContractRouter, EventIteratorSchemaDetails };
|