@orpc/contract 0.0.0-next.f22c7ec → 0.0.0-next.f4d410a
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 +103 -0
- package/dist/index.d.mts +236 -0
- package/dist/index.d.ts +236 -0
- package/dist/index.mjs +252 -0
- package/package.json +10 -13
- package/dist/index.js +0 -406
- package/dist/src/builder.d.ts +0 -23
- package/dist/src/client-utils.d.ts +0 -5
- package/dist/src/client.d.ts +0 -19
- package/dist/src/config.d.ts +0 -36
- package/dist/src/error-map.d.ts +0 -58
- package/dist/src/error-orpc.d.ts +0 -109
- package/dist/src/error.d.ts +0 -13
- package/dist/src/index.d.ts +0 -18
- package/dist/src/procedure-client.d.ts +0 -6
- package/dist/src/procedure-decorated.d.ts +0 -14
- package/dist/src/procedure.d.ts +0 -83
- package/dist/src/router-builder.d.ts +0 -23
- package/dist/src/router-client.d.ts +0 -7
- package/dist/src/router.d.ts +0 -13
- package/dist/src/types.d.ts +0 -11
package/README.md
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
<div align="center">
|
|
2
|
+
<image align="center" src="https://orpc.unnoq.com/logo.webp" width=280 alt="oRPC logo" />
|
|
3
|
+
</div>
|
|
4
|
+
|
|
5
|
+
<h1></h1>
|
|
6
|
+
|
|
7
|
+
<div align="center">
|
|
8
|
+
<a href="https://codecov.io/gh/unnoq/orpc">
|
|
9
|
+
<img alt="codecov" src="https://codecov.io/gh/unnoq/orpc/branch/main/graph/badge.svg">
|
|
10
|
+
</a>
|
|
11
|
+
<a href="https://www.npmjs.com/package/@orpc/contract">
|
|
12
|
+
<img alt="weekly downloads" src="https://img.shields.io/npm/dw/%40orpc%2Fcontract?logo=npm" />
|
|
13
|
+
</a>
|
|
14
|
+
<a href="https://github.com/unnoq/orpc/blob/main/LICENSE">
|
|
15
|
+
<img alt="MIT License" src="https://img.shields.io/github/license/unnoq/orpc?logo=open-source-initiative" />
|
|
16
|
+
</a>
|
|
17
|
+
<a href="https://discord.gg/TXEbwRBvQn">
|
|
18
|
+
<img alt="Discord" src="https://img.shields.io/discord/1308966753044398161?color=7389D8&label&logo=discord&logoColor=ffffff" />
|
|
19
|
+
</a>
|
|
20
|
+
</div>
|
|
21
|
+
|
|
22
|
+
<h3 align="center">Typesafe APIs Made Simple 🪄</h3>
|
|
23
|
+
|
|
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, ensuring a smooth and enjoyable developer experience.
|
|
25
|
+
|
|
26
|
+
---
|
|
27
|
+
|
|
28
|
+
## Highlights
|
|
29
|
+
|
|
30
|
+
- **End-to-End Type Safety 🔒**: Ensure complete type safety from inputs to outputs and errors, bridging server and client seamlessly.
|
|
31
|
+
- **First-Class OpenAPI 📄**: Adheres to the OpenAPI standard out of the box, ensuring seamless integration and comprehensive API documentation.
|
|
32
|
+
- **Contract-First Development 📜**: (Optional) Define your API contract upfront and implement it with confidence.
|
|
33
|
+
- **Exceptional Developer Experience ✨**: Enjoy a streamlined workflow with robust typing and clear, in-code documentation.
|
|
34
|
+
- **Multi-Runtime Support 🌍**: Run your code seamlessly on Cloudflare, Deno, Bun, Node.js, and more.
|
|
35
|
+
- **Framework Integrations 🧩**: Supports Tanstack Query (React, Vue, Solid, Svelte), Pinia Colada, and more.
|
|
36
|
+
- **Server Actions ⚡️**: Fully compatible with React Server Actions on Next.js, TanStack Start, and more.
|
|
37
|
+
- **Standard Schema Support 🗂️**: Effortlessly work with Zod, Valibot, ArkType, and others right out of the box.
|
|
38
|
+
- **Fast & Lightweight 💨**: Built on native APIs across all runtimes – optimized for speed and efficiency.
|
|
39
|
+
- **Native Types 📦**: Enjoy built-in support for Date, File, Blob, BigInt, URL and more with no extra setup.
|
|
40
|
+
- **Lazy Router ⏱️**: Improve cold start times with our lazy routing feature.
|
|
41
|
+
- **SSE & Streaming 📡**: Provides SSE and streaming features – perfect for real-time notifications and AI-powered streaming responses.
|
|
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.
|
|
46
|
+
|
|
47
|
+
## Documentation
|
|
48
|
+
|
|
49
|
+
You can find the full documentation [here](https://orpc.unnoq.com).
|
|
50
|
+
|
|
51
|
+
## Packages
|
|
52
|
+
|
|
53
|
+
- [@orpc/contract](https://www.npmjs.com/package/@orpc/contract): Build your API contract.
|
|
54
|
+
- [@orpc/server](https://www.npmjs.com/package/@orpc/server): Build your API or implement API contract.
|
|
55
|
+
- [@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
|
+
- [@orpc/openapi](https://www.npmjs.com/package/@orpc/openapi): Generate OpenAPI specs and handle OpenAPI requests.
|
|
62
|
+
- [@orpc/zod](https://www.npmjs.com/package/@orpc/zod): More schemas that [Zod](https://zod.dev/) doesn't support yet.
|
|
63
|
+
|
|
64
|
+
## `@orpc/contract`
|
|
65
|
+
|
|
66
|
+
Build your API contract. Read the [documentation](https://orpc.unnoq.com/docs/contract-first/define-contract) for more information.
|
|
67
|
+
|
|
68
|
+
```ts
|
|
69
|
+
export const PlanetSchema = z.object({
|
|
70
|
+
id: z.number().int().min(1),
|
|
71
|
+
name: z.string(),
|
|
72
|
+
description: z.string().optional(),
|
|
73
|
+
})
|
|
74
|
+
|
|
75
|
+
export const listPlanetContract = oc
|
|
76
|
+
.input(
|
|
77
|
+
z.object({
|
|
78
|
+
limit: z.number().int().min(1).max(100).optional(),
|
|
79
|
+
cursor: z.number().int().min(0).default(0),
|
|
80
|
+
}),
|
|
81
|
+
)
|
|
82
|
+
.output(z.array(PlanetSchema))
|
|
83
|
+
|
|
84
|
+
export const findPlanetContract = oc
|
|
85
|
+
.input(PlanetSchema.pick({ id: true }))
|
|
86
|
+
.output(PlanetSchema)
|
|
87
|
+
|
|
88
|
+
export const createPlanetContract = oc
|
|
89
|
+
.input(PlanetSchema.omit({ id: true }))
|
|
90
|
+
.output(PlanetSchema)
|
|
91
|
+
|
|
92
|
+
export const contract = {
|
|
93
|
+
planet: {
|
|
94
|
+
list: listPlanetContract,
|
|
95
|
+
find: findPlanetContract,
|
|
96
|
+
create: createPlanetContract,
|
|
97
|
+
},
|
|
98
|
+
}
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
## License
|
|
102
|
+
|
|
103
|
+
Distributed under the MIT License. See [LICENSE](https://github.com/unnoq/orpc/blob/main/LICENSE) for more information.
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
import { ORPCErrorCode, ORPCError, ClientContext, Client } from '@orpc/client';
|
|
2
|
+
export { ORPCError } from '@orpc/client';
|
|
3
|
+
import { Promisable, IsEqual } from '@orpc/shared';
|
|
4
|
+
import { StandardSchemaV1 } from '@standard-schema/spec';
|
|
5
|
+
|
|
6
|
+
type Schema<TInput, TOutput> = StandardSchemaV1<TInput, TOutput>;
|
|
7
|
+
type AnySchema = Schema<any, any>;
|
|
8
|
+
type SchemaIssue = StandardSchemaV1.Issue;
|
|
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>;
|
|
30
|
+
};
|
|
31
|
+
type MergedErrorMap<T1 extends ErrorMap, T2 extends ErrorMap> = Omit<T1, keyof T2> & T2;
|
|
32
|
+
declare function mergeErrorMap<T1 extends ErrorMap, T2 extends ErrorMap>(errorMap1: T1, errorMap2: T2): MergedErrorMap<T1, T2>;
|
|
33
|
+
type ORPCErrorFromErrorMap<TErrorMap extends ErrorMap> = {
|
|
34
|
+
[K in keyof TErrorMap]: K extends string ? TErrorMap[K] extends ErrorMapItem<infer TDataSchema extends Schema<unknown, unknown>> ? ORPCError<K, InferSchemaOutput<TDataSchema>> : never : never;
|
|
35
|
+
}[keyof TErrorMap];
|
|
36
|
+
type ErrorFromErrorMap<TErrorMap extends ErrorMap> = Error | ORPCErrorFromErrorMap<TErrorMap>;
|
|
37
|
+
|
|
38
|
+
type Meta = Record<string, any>;
|
|
39
|
+
declare function mergeMeta<T extends Meta>(meta1: T, meta2: T): T;
|
|
40
|
+
|
|
41
|
+
type HTTPPath = `/${string}`;
|
|
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[];
|
|
52
|
+
/**
|
|
53
|
+
* The status code of the response when the procedure is successful.
|
|
54
|
+
*
|
|
55
|
+
* @default 200
|
|
56
|
+
*/
|
|
57
|
+
successStatus?: number;
|
|
58
|
+
/**
|
|
59
|
+
* The description of the response when the procedure is successful.
|
|
60
|
+
*
|
|
61
|
+
* @default 'OK'
|
|
62
|
+
*/
|
|
63
|
+
successDescription?: string;
|
|
64
|
+
/**
|
|
65
|
+
* Determines how the input should be structured based on `params`, `query`, `headers`, and `body`.
|
|
66
|
+
*
|
|
67
|
+
* @option 'compact'
|
|
68
|
+
* Combines `params` and either `query` or `body` (depending on the HTTP method) into a single object.
|
|
69
|
+
*
|
|
70
|
+
* @option 'detailed'
|
|
71
|
+
* Keeps each part of the request (`params`, `query`, `headers`, and `body`) as separate fields in the input object.
|
|
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'
|
|
84
|
+
*/
|
|
85
|
+
inputStructure?: InputStructure;
|
|
86
|
+
/**
|
|
87
|
+
* Determines how the response should be structured based on the output.
|
|
88
|
+
*
|
|
89
|
+
* @option 'compact'
|
|
90
|
+
* Includes only the body data, encoded directly in the response.
|
|
91
|
+
*
|
|
92
|
+
* @option 'detailed'
|
|
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'
|
|
106
|
+
*/
|
|
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
|
+
input<U extends AnySchema>(schema: U): ContractProcedureBuilderWithInput<U, TOutputSchema, TErrorMap, TMeta>;
|
|
163
|
+
output<U extends AnySchema>(schema: U): ContractProcedureBuilderWithOutput<TInputSchema, U, TErrorMap, TMeta>;
|
|
164
|
+
}
|
|
165
|
+
interface ContractProcedureBuilderWithInput<TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta> extends ContractProcedure<TInputSchema, TOutputSchema, TErrorMap, TMeta> {
|
|
166
|
+
errors<U extends ErrorMap>(errors: U): ContractProcedureBuilderWithInput<TInputSchema, TOutputSchema, MergedErrorMap<TErrorMap, U>, TMeta>;
|
|
167
|
+
meta(meta: TMeta): ContractProcedureBuilderWithInput<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
|
168
|
+
route(route: Route): ContractProcedureBuilderWithInput<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
|
169
|
+
output<U extends AnySchema>(schema: U): ContractProcedureBuilderWithInputOutput<TInputSchema, U, TErrorMap, TMeta>;
|
|
170
|
+
}
|
|
171
|
+
interface ContractProcedureBuilderWithOutput<TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta> extends ContractProcedure<TInputSchema, TOutputSchema, TErrorMap, TMeta> {
|
|
172
|
+
errors<U extends ErrorMap>(errors: U): ContractProcedureBuilderWithOutput<TInputSchema, TOutputSchema, MergedErrorMap<TErrorMap, U>, TMeta>;
|
|
173
|
+
meta(meta: TMeta): ContractProcedureBuilderWithOutput<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
|
174
|
+
route(route: Route): ContractProcedureBuilderWithOutput<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
|
175
|
+
input<U extends AnySchema>(schema: U): ContractProcedureBuilderWithInputOutput<U, TOutputSchema, TErrorMap, TMeta>;
|
|
176
|
+
}
|
|
177
|
+
interface ContractProcedureBuilderWithInputOutput<TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta> extends ContractProcedure<TInputSchema, TOutputSchema, TErrorMap, TMeta> {
|
|
178
|
+
errors<U extends ErrorMap>(errors: U): ContractProcedureBuilderWithInputOutput<TInputSchema, TOutputSchema, MergedErrorMap<TErrorMap, U>, TMeta>;
|
|
179
|
+
meta(meta: TMeta): ContractProcedureBuilderWithInputOutput<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
|
180
|
+
route(route: Route): ContractProcedureBuilderWithInputOutput<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
|
181
|
+
}
|
|
182
|
+
interface ContractRouterBuilder<TErrorMap extends ErrorMap, TMeta extends Meta> {
|
|
183
|
+
'~orpc': EnhanceContractRouterOptions<TErrorMap>;
|
|
184
|
+
'errors'<U extends ErrorMap>(errors: U): ContractRouterBuilder<MergedErrorMap<TErrorMap, U>, TMeta>;
|
|
185
|
+
'prefix'(prefix: HTTPPath): ContractRouterBuilder<TErrorMap, TMeta>;
|
|
186
|
+
'tag'(...tags: string[]): ContractRouterBuilder<TErrorMap, TMeta>;
|
|
187
|
+
'router'<T extends ContractRouter<TMeta>>(router: T): EnhancedContractRouter<T, TErrorMap>;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
interface ContractBuilderDef<TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta> extends ContractProcedureDef<TInputSchema, TOutputSchema, TErrorMap, TMeta>, EnhanceContractRouterOptions<TErrorMap> {
|
|
191
|
+
}
|
|
192
|
+
declare class ContractBuilder<TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta> extends ContractProcedure<TInputSchema, TOutputSchema, TErrorMap, TMeta> {
|
|
193
|
+
'~orpc': ContractBuilderDef<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
|
194
|
+
constructor(def: ContractBuilderDef<TInputSchema, TOutputSchema, TErrorMap, TMeta>);
|
|
195
|
+
/**
|
|
196
|
+
* Reset initial meta
|
|
197
|
+
*/
|
|
198
|
+
$meta<U extends Meta>(initialMeta: U): ContractBuilder<TInputSchema, TOutputSchema, TErrorMap, U & Record<never, never>>;
|
|
199
|
+
/**
|
|
200
|
+
* Reset initial route
|
|
201
|
+
*/
|
|
202
|
+
$route(initialRoute: Route): ContractBuilder<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
|
203
|
+
errors<U extends ErrorMap>(errors: U): ContractBuilder<TInputSchema, TOutputSchema, MergedErrorMap<TErrorMap, U>, TMeta>;
|
|
204
|
+
meta(meta: TMeta): ContractProcedureBuilder<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
|
205
|
+
route(route: Route): ContractProcedureBuilder<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
|
206
|
+
input<U extends AnySchema>(schema: U): ContractProcedureBuilderWithInput<U, TOutputSchema, TErrorMap, TMeta>;
|
|
207
|
+
output<U extends AnySchema>(schema: U): ContractProcedureBuilderWithOutput<TInputSchema, U, TErrorMap, TMeta>;
|
|
208
|
+
prefix(prefix: HTTPPath): ContractRouterBuilder<TErrorMap, TMeta>;
|
|
209
|
+
tag(...tags: string[]): ContractRouterBuilder<TErrorMap, TMeta>;
|
|
210
|
+
router<T extends ContractRouter<TMeta>>(router: T): EnhancedContractRouter<T, TErrorMap>;
|
|
211
|
+
}
|
|
212
|
+
declare const oc: ContractBuilder<Schema<unknown, unknown>, Schema<unknown, unknown>, Record<never, never>, Record<never, never>>;
|
|
213
|
+
|
|
214
|
+
interface ContractConfig {
|
|
215
|
+
defaultMethod: HTTPMethod;
|
|
216
|
+
defaultSuccessStatus: number;
|
|
217
|
+
defaultSuccessDescription: string;
|
|
218
|
+
defaultInputStructure: InputStructure;
|
|
219
|
+
defaultOutputStructure: OutputStructure;
|
|
220
|
+
}
|
|
221
|
+
declare function fallbackContractConfig<T extends keyof ContractConfig>(key: T, value: ContractConfig[T] | undefined): ContractConfig[T];
|
|
222
|
+
|
|
223
|
+
interface EventIteratorSchemaDetails {
|
|
224
|
+
yields: AnySchema;
|
|
225
|
+
returns?: AnySchema;
|
|
226
|
+
}
|
|
227
|
+
declare function eventIterator<TYieldIn, TYieldOut, TReturnIn = unknown, TReturnOut = unknown>(yields: Schema<TYieldIn, TYieldOut>, returns?: Schema<TReturnIn, TReturnOut>): Schema<AsyncIteratorObject<TYieldIn, TReturnIn, void>, AsyncIteratorObject<TYieldOut, TReturnOut, void>>;
|
|
228
|
+
declare function getEventIteratorSchemaDetails(schema: AnySchema | undefined): undefined | EventIteratorSchemaDetails;
|
|
229
|
+
|
|
230
|
+
type ContractProcedureClient<TClientContext extends ClientContext, TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap> = Client<TClientContext, InferSchemaInput<TInputSchema>, InferSchemaOutput<TOutputSchema>, ErrorFromErrorMap<TErrorMap>>;
|
|
231
|
+
|
|
232
|
+
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
|
+
[K in keyof TRouter]: TRouter[K] extends AnyContractRouter ? ContractRouterClient<TRouter[K], TClientContext> : never;
|
|
234
|
+
};
|
|
235
|
+
|
|
236
|
+
export { type AnyContractProcedure, type AnyContractRouter, type AnySchema, ContractBuilder, type ContractBuilderDef, type ContractConfig, ContractProcedure, type ContractProcedureBuilder, type ContractProcedureBuilderWithInput, type ContractProcedureBuilderWithInputOutput, type ContractProcedureBuilderWithOutput, type ContractProcedureClient, type ContractProcedureDef, type ContractRouter, type ContractRouterBuilder, type ContractRouterClient, type EnhanceContractRouterOptions, type EnhanceRouteOptions, type EnhancedContractRouter, type ErrorFromErrorMap, type ErrorMap, type ErrorMapItem, type EventIteratorSchemaDetails, type HTTPMethod, type HTTPPath, type InferContractRouterErrorMap, type InferContractRouterInputs, type InferContractRouterMeta, type InferContractRouterOutputs, type InferSchemaInput, type InferSchemaOutput, type InputStructure, type MergedErrorMap, type Meta, type ORPCErrorFromErrorMap, type OutputStructure, type Route, type Schema, type SchemaIssue, type TypeRest, ValidationError, type ValidationErrorOptions, enhanceContractRouter, enhanceRoute, eventIterator, fallbackContractConfig, getContractRouter, getEventIteratorSchemaDetails, isContractProcedure, mergeErrorMap, mergeMeta, mergePrefix, mergeRoute, mergeTags, oc, prefixRoute, type, unshiftTagRoute };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
import { ORPCErrorCode, ORPCError, ClientContext, Client } from '@orpc/client';
|
|
2
|
+
export { ORPCError } from '@orpc/client';
|
|
3
|
+
import { Promisable, IsEqual } from '@orpc/shared';
|
|
4
|
+
import { StandardSchemaV1 } from '@standard-schema/spec';
|
|
5
|
+
|
|
6
|
+
type Schema<TInput, TOutput> = StandardSchemaV1<TInput, TOutput>;
|
|
7
|
+
type AnySchema = Schema<any, any>;
|
|
8
|
+
type SchemaIssue = StandardSchemaV1.Issue;
|
|
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>;
|
|
30
|
+
};
|
|
31
|
+
type MergedErrorMap<T1 extends ErrorMap, T2 extends ErrorMap> = Omit<T1, keyof T2> & T2;
|
|
32
|
+
declare function mergeErrorMap<T1 extends ErrorMap, T2 extends ErrorMap>(errorMap1: T1, errorMap2: T2): MergedErrorMap<T1, T2>;
|
|
33
|
+
type ORPCErrorFromErrorMap<TErrorMap extends ErrorMap> = {
|
|
34
|
+
[K in keyof TErrorMap]: K extends string ? TErrorMap[K] extends ErrorMapItem<infer TDataSchema extends Schema<unknown, unknown>> ? ORPCError<K, InferSchemaOutput<TDataSchema>> : never : never;
|
|
35
|
+
}[keyof TErrorMap];
|
|
36
|
+
type ErrorFromErrorMap<TErrorMap extends ErrorMap> = Error | ORPCErrorFromErrorMap<TErrorMap>;
|
|
37
|
+
|
|
38
|
+
type Meta = Record<string, any>;
|
|
39
|
+
declare function mergeMeta<T extends Meta>(meta1: T, meta2: T): T;
|
|
40
|
+
|
|
41
|
+
type HTTPPath = `/${string}`;
|
|
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[];
|
|
52
|
+
/**
|
|
53
|
+
* The status code of the response when the procedure is successful.
|
|
54
|
+
*
|
|
55
|
+
* @default 200
|
|
56
|
+
*/
|
|
57
|
+
successStatus?: number;
|
|
58
|
+
/**
|
|
59
|
+
* The description of the response when the procedure is successful.
|
|
60
|
+
*
|
|
61
|
+
* @default 'OK'
|
|
62
|
+
*/
|
|
63
|
+
successDescription?: string;
|
|
64
|
+
/**
|
|
65
|
+
* Determines how the input should be structured based on `params`, `query`, `headers`, and `body`.
|
|
66
|
+
*
|
|
67
|
+
* @option 'compact'
|
|
68
|
+
* Combines `params` and either `query` or `body` (depending on the HTTP method) into a single object.
|
|
69
|
+
*
|
|
70
|
+
* @option 'detailed'
|
|
71
|
+
* Keeps each part of the request (`params`, `query`, `headers`, and `body`) as separate fields in the input object.
|
|
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'
|
|
84
|
+
*/
|
|
85
|
+
inputStructure?: InputStructure;
|
|
86
|
+
/**
|
|
87
|
+
* Determines how the response should be structured based on the output.
|
|
88
|
+
*
|
|
89
|
+
* @option 'compact'
|
|
90
|
+
* Includes only the body data, encoded directly in the response.
|
|
91
|
+
*
|
|
92
|
+
* @option 'detailed'
|
|
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'
|
|
106
|
+
*/
|
|
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
|
+
input<U extends AnySchema>(schema: U): ContractProcedureBuilderWithInput<U, TOutputSchema, TErrorMap, TMeta>;
|
|
163
|
+
output<U extends AnySchema>(schema: U): ContractProcedureBuilderWithOutput<TInputSchema, U, TErrorMap, TMeta>;
|
|
164
|
+
}
|
|
165
|
+
interface ContractProcedureBuilderWithInput<TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta> extends ContractProcedure<TInputSchema, TOutputSchema, TErrorMap, TMeta> {
|
|
166
|
+
errors<U extends ErrorMap>(errors: U): ContractProcedureBuilderWithInput<TInputSchema, TOutputSchema, MergedErrorMap<TErrorMap, U>, TMeta>;
|
|
167
|
+
meta(meta: TMeta): ContractProcedureBuilderWithInput<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
|
168
|
+
route(route: Route): ContractProcedureBuilderWithInput<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
|
169
|
+
output<U extends AnySchema>(schema: U): ContractProcedureBuilderWithInputOutput<TInputSchema, U, TErrorMap, TMeta>;
|
|
170
|
+
}
|
|
171
|
+
interface ContractProcedureBuilderWithOutput<TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta> extends ContractProcedure<TInputSchema, TOutputSchema, TErrorMap, TMeta> {
|
|
172
|
+
errors<U extends ErrorMap>(errors: U): ContractProcedureBuilderWithOutput<TInputSchema, TOutputSchema, MergedErrorMap<TErrorMap, U>, TMeta>;
|
|
173
|
+
meta(meta: TMeta): ContractProcedureBuilderWithOutput<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
|
174
|
+
route(route: Route): ContractProcedureBuilderWithOutput<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
|
175
|
+
input<U extends AnySchema>(schema: U): ContractProcedureBuilderWithInputOutput<U, TOutputSchema, TErrorMap, TMeta>;
|
|
176
|
+
}
|
|
177
|
+
interface ContractProcedureBuilderWithInputOutput<TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta> extends ContractProcedure<TInputSchema, TOutputSchema, TErrorMap, TMeta> {
|
|
178
|
+
errors<U extends ErrorMap>(errors: U): ContractProcedureBuilderWithInputOutput<TInputSchema, TOutputSchema, MergedErrorMap<TErrorMap, U>, TMeta>;
|
|
179
|
+
meta(meta: TMeta): ContractProcedureBuilderWithInputOutput<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
|
180
|
+
route(route: Route): ContractProcedureBuilderWithInputOutput<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
|
181
|
+
}
|
|
182
|
+
interface ContractRouterBuilder<TErrorMap extends ErrorMap, TMeta extends Meta> {
|
|
183
|
+
'~orpc': EnhanceContractRouterOptions<TErrorMap>;
|
|
184
|
+
'errors'<U extends ErrorMap>(errors: U): ContractRouterBuilder<MergedErrorMap<TErrorMap, U>, TMeta>;
|
|
185
|
+
'prefix'(prefix: HTTPPath): ContractRouterBuilder<TErrorMap, TMeta>;
|
|
186
|
+
'tag'(...tags: string[]): ContractRouterBuilder<TErrorMap, TMeta>;
|
|
187
|
+
'router'<T extends ContractRouter<TMeta>>(router: T): EnhancedContractRouter<T, TErrorMap>;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
interface ContractBuilderDef<TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta> extends ContractProcedureDef<TInputSchema, TOutputSchema, TErrorMap, TMeta>, EnhanceContractRouterOptions<TErrorMap> {
|
|
191
|
+
}
|
|
192
|
+
declare class ContractBuilder<TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta> extends ContractProcedure<TInputSchema, TOutputSchema, TErrorMap, TMeta> {
|
|
193
|
+
'~orpc': ContractBuilderDef<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
|
194
|
+
constructor(def: ContractBuilderDef<TInputSchema, TOutputSchema, TErrorMap, TMeta>);
|
|
195
|
+
/**
|
|
196
|
+
* Reset initial meta
|
|
197
|
+
*/
|
|
198
|
+
$meta<U extends Meta>(initialMeta: U): ContractBuilder<TInputSchema, TOutputSchema, TErrorMap, U & Record<never, never>>;
|
|
199
|
+
/**
|
|
200
|
+
* Reset initial route
|
|
201
|
+
*/
|
|
202
|
+
$route(initialRoute: Route): ContractBuilder<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
|
203
|
+
errors<U extends ErrorMap>(errors: U): ContractBuilder<TInputSchema, TOutputSchema, MergedErrorMap<TErrorMap, U>, TMeta>;
|
|
204
|
+
meta(meta: TMeta): ContractProcedureBuilder<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
|
205
|
+
route(route: Route): ContractProcedureBuilder<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
|
206
|
+
input<U extends AnySchema>(schema: U): ContractProcedureBuilderWithInput<U, TOutputSchema, TErrorMap, TMeta>;
|
|
207
|
+
output<U extends AnySchema>(schema: U): ContractProcedureBuilderWithOutput<TInputSchema, U, TErrorMap, TMeta>;
|
|
208
|
+
prefix(prefix: HTTPPath): ContractRouterBuilder<TErrorMap, TMeta>;
|
|
209
|
+
tag(...tags: string[]): ContractRouterBuilder<TErrorMap, TMeta>;
|
|
210
|
+
router<T extends ContractRouter<TMeta>>(router: T): EnhancedContractRouter<T, TErrorMap>;
|
|
211
|
+
}
|
|
212
|
+
declare const oc: ContractBuilder<Schema<unknown, unknown>, Schema<unknown, unknown>, Record<never, never>, Record<never, never>>;
|
|
213
|
+
|
|
214
|
+
interface ContractConfig {
|
|
215
|
+
defaultMethod: HTTPMethod;
|
|
216
|
+
defaultSuccessStatus: number;
|
|
217
|
+
defaultSuccessDescription: string;
|
|
218
|
+
defaultInputStructure: InputStructure;
|
|
219
|
+
defaultOutputStructure: OutputStructure;
|
|
220
|
+
}
|
|
221
|
+
declare function fallbackContractConfig<T extends keyof ContractConfig>(key: T, value: ContractConfig[T] | undefined): ContractConfig[T];
|
|
222
|
+
|
|
223
|
+
interface EventIteratorSchemaDetails {
|
|
224
|
+
yields: AnySchema;
|
|
225
|
+
returns?: AnySchema;
|
|
226
|
+
}
|
|
227
|
+
declare function eventIterator<TYieldIn, TYieldOut, TReturnIn = unknown, TReturnOut = unknown>(yields: Schema<TYieldIn, TYieldOut>, returns?: Schema<TReturnIn, TReturnOut>): Schema<AsyncIteratorObject<TYieldIn, TReturnIn, void>, AsyncIteratorObject<TYieldOut, TReturnOut, void>>;
|
|
228
|
+
declare function getEventIteratorSchemaDetails(schema: AnySchema | undefined): undefined | EventIteratorSchemaDetails;
|
|
229
|
+
|
|
230
|
+
type ContractProcedureClient<TClientContext extends ClientContext, TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap> = Client<TClientContext, InferSchemaInput<TInputSchema>, InferSchemaOutput<TOutputSchema>, ErrorFromErrorMap<TErrorMap>>;
|
|
231
|
+
|
|
232
|
+
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
|
+
[K in keyof TRouter]: TRouter[K] extends AnyContractRouter ? ContractRouterClient<TRouter[K], TClientContext> : never;
|
|
234
|
+
};
|
|
235
|
+
|
|
236
|
+
export { type AnyContractProcedure, type AnyContractRouter, type AnySchema, ContractBuilder, type ContractBuilderDef, type ContractConfig, ContractProcedure, type ContractProcedureBuilder, type ContractProcedureBuilderWithInput, type ContractProcedureBuilderWithInputOutput, type ContractProcedureBuilderWithOutput, type ContractProcedureClient, type ContractProcedureDef, type ContractRouter, type ContractRouterBuilder, type ContractRouterClient, type EnhanceContractRouterOptions, type EnhanceRouteOptions, type EnhancedContractRouter, type ErrorFromErrorMap, type ErrorMap, type ErrorMapItem, type EventIteratorSchemaDetails, type HTTPMethod, type HTTPPath, type InferContractRouterErrorMap, type InferContractRouterInputs, type InferContractRouterMeta, type InferContractRouterOutputs, type InferSchemaInput, type InferSchemaOutput, type InputStructure, type MergedErrorMap, type Meta, type ORPCErrorFromErrorMap, type OutputStructure, type Route, type Schema, type SchemaIssue, type TypeRest, ValidationError, type ValidationErrorOptions, enhanceContractRouter, enhanceRoute, eventIterator, fallbackContractConfig, getContractRouter, getEventIteratorSchemaDetails, isContractProcedure, mergeErrorMap, mergeMeta, mergePrefix, mergeRoute, mergeTags, oc, prefixRoute, type, unshiftTagRoute };
|