@orpc/contract 0.0.0-next.f81b4a2 → 0.0.0-next.f9e0a4c
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 +18 -22
- package/dist/index.d.mts +41 -5
- package/dist/index.d.ts +41 -5
- package/dist/index.mjs +47 -2
- package/package.json +7 -6
package/README.md
CHANGED
|
@@ -21,28 +21,24 @@
|
|
|
21
21
|
|
|
22
22
|
<h3 align="center">Typesafe APIs Made Simple 🪄</h3>
|
|
23
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
|
|
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
|
|
25
25
|
|
|
26
26
|
---
|
|
27
27
|
|
|
28
28
|
## Highlights
|
|
29
29
|
|
|
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.
|
|
30
|
+
- **🔗 End-to-End Type Safety**: Ensure type-safe inputs, outputs, and errors from client to server.
|
|
31
|
+
- **📘 First-Class OpenAPI**: Built-in support that fully adheres to the OpenAPI standard.
|
|
32
|
+
- **📝 Contract-First Development**: Optionally define your API contract before implementation.
|
|
33
|
+
- **🔍 First-Class OpenTelemetry**: Seamlessly integrate with OpenTelemetry for observability.
|
|
34
|
+
- **⚙️ Framework Integrations**: Seamlessly integrate with TanStack Query (React, Vue, Solid, Svelte, Angular), Pinia Colada, and more.
|
|
35
|
+
- **🚀 Server Actions**: Fully compatible with React Server Actions on Next.js, TanStack Start, and other platforms.
|
|
36
|
+
- **🔠 Standard Schema Support**: Works out of the box with Zod, Valibot, ArkType, and other schema validators.
|
|
37
|
+
- **🗃️ Native Types**: Supports native types like Date, File, Blob, BigInt, URL, and more.
|
|
38
|
+
- **⏱️ Lazy Router**: Enhance cold start times with our lazy routing feature.
|
|
39
|
+
- **📡 SSE & Streaming**: Enjoy full type-safe support for SSE and streaming.
|
|
40
|
+
- **🌍 Multi-Runtime Support**: Fast and lightweight on Cloudflare, Deno, Bun, Node.js, and beyond.
|
|
41
|
+
- **🔌 Extendability**: Easily extend functionality with plugins, middleware, and interceptors.
|
|
46
42
|
|
|
47
43
|
## Documentation
|
|
48
44
|
|
|
@@ -53,13 +49,13 @@ You can find the full documentation [here](https://orpc.unnoq.com).
|
|
|
53
49
|
- [@orpc/contract](https://www.npmjs.com/package/@orpc/contract): Build your API contract.
|
|
54
50
|
- [@orpc/server](https://www.npmjs.com/package/@orpc/server): Build your API or implement API contract.
|
|
55
51
|
- [@orpc/client](https://www.npmjs.com/package/@orpc/client): Consume your API on the client with type-safety.
|
|
52
|
+
- [@orpc/openapi](https://www.npmjs.com/package/@orpc/openapi): Generate OpenAPI specs and handle OpenAPI requests.
|
|
53
|
+
- [@orpc/otel](https://www.npmjs.com/package/@orpc/otel): [OpenTelemetry](https://opentelemetry.io/) integration for observability.
|
|
54
|
+
- [@orpc/nest](https://www.npmjs.com/package/@orpc/nest): Deeply integrate oRPC with [NestJS](https://nestjs.com/).
|
|
56
55
|
- [@orpc/react](https://www.npmjs.com/package/@orpc/react): Utilities for integrating oRPC with React and React Server Actions.
|
|
57
|
-
- [@orpc/
|
|
58
|
-
- [@orpc/vue-query](https://www.npmjs.com/package/@orpc/vue-query): Integration with [Vue Query](https://tanstack.com/query/latest/docs/framework/vue/overview).
|
|
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).
|
|
56
|
+
- [@orpc/tanstack-query](https://www.npmjs.com/package/@orpc/tanstack-query): [TanStack Query](https://tanstack.com/query/latest) integration.
|
|
61
57
|
- [@orpc/vue-colada](https://www.npmjs.com/package/@orpc/vue-colada): Integration with [Pinia Colada](https://pinia-colada.esm.dev/).
|
|
62
|
-
- [@orpc/
|
|
58
|
+
- [@orpc/hey-api](https://www.npmjs.com/package/@orpc/hey-api): [Hey API](https://heyapi.dev/) integration.
|
|
63
59
|
- [@orpc/zod](https://www.npmjs.com/package/@orpc/zod): More schemas that [Zod](https://zod.dev/) doesn't support yet.
|
|
64
60
|
- [@orpc/valibot](https://www.npmjs.com/package/@orpc/valibot): OpenAPI spec generation from [Valibot](https://valibot.dev/).
|
|
65
61
|
- [@orpc/arktype](https://www.npmjs.com/package/@orpc/arktype): OpenAPI spec generation from [ArkType](https://arktype.io/).
|
package/dist/index.d.mts
CHANGED
|
@@ -3,6 +3,8 @@ export { HTTPMethod, HTTPPath, ORPCError } from '@orpc/client';
|
|
|
3
3
|
import { Promisable, IsEqual, ThrowableError } from '@orpc/shared';
|
|
4
4
|
export { Registry, ThrowableError } from '@orpc/shared';
|
|
5
5
|
import { StandardSchemaV1 } from '@standard-schema/spec';
|
|
6
|
+
import { OpenAPIV3_1 } from 'openapi-types';
|
|
7
|
+
export { OpenAPIV3_1 as OpenAPI } from 'openapi-types';
|
|
6
8
|
|
|
7
9
|
type Schema<TInput, TOutput> = StandardSchemaV1<TInput, TOutput>;
|
|
8
10
|
type AnySchema = Schema<any, any>;
|
|
@@ -66,6 +68,13 @@ interface Route {
|
|
|
66
68
|
* @see {@link https://orpc.unnoq.com/docs/openapi/routing OpenAPI Routing Docs}
|
|
67
69
|
*/
|
|
68
70
|
path?: HTTPPath;
|
|
71
|
+
/**
|
|
72
|
+
* The operation ID of the endpoint.
|
|
73
|
+
* This option is typically relevant when integrating with OpenAPI.
|
|
74
|
+
*
|
|
75
|
+
* @default Concatenation of router segments
|
|
76
|
+
*/
|
|
77
|
+
operationId?: string;
|
|
69
78
|
/**
|
|
70
79
|
* The summary of the procedure.
|
|
71
80
|
* This option is typically relevant when integrating with OpenAPI.
|
|
@@ -96,6 +105,7 @@ interface Route {
|
|
|
96
105
|
tags?: readonly string[];
|
|
97
106
|
/**
|
|
98
107
|
* The status code of the response when the procedure is successful.
|
|
108
|
+
* The status code must be in the 200-399 range.
|
|
99
109
|
* This option is typically relevant when integrating with OpenAPI.
|
|
100
110
|
*
|
|
101
111
|
* @see {@link https://orpc.unnoq.com/docs/openapi/routing OpenAPI Routing Docs}
|
|
@@ -137,16 +147,18 @@ interface Route {
|
|
|
137
147
|
* Determines how the response should be structured based on the output.
|
|
138
148
|
*
|
|
139
149
|
* @option 'compact'
|
|
140
|
-
*
|
|
150
|
+
* The output data is directly returned as the response body.
|
|
141
151
|
*
|
|
142
152
|
* @option 'detailed'
|
|
143
|
-
*
|
|
144
|
-
* - `
|
|
145
|
-
* - `
|
|
153
|
+
* Return an object with optional properties:
|
|
154
|
+
* - `status`: The response status (must be in 200-399 range) if not set fallback to `successStatus`.
|
|
155
|
+
* - `headers`: Custom headers to merge with the response headers (`Record<string, string | string[] | undefined>`)
|
|
156
|
+
* - `body`: The response body.
|
|
146
157
|
*
|
|
147
158
|
* Example:
|
|
148
159
|
* ```ts
|
|
149
160
|
* const output = {
|
|
161
|
+
* status: 201,
|
|
150
162
|
* headers: { 'x-custom-header': 'value' },
|
|
151
163
|
* body: { message: 'Hello, world!' },
|
|
152
164
|
* };
|
|
@@ -156,6 +168,12 @@ interface Route {
|
|
|
156
168
|
* @default 'compact'
|
|
157
169
|
*/
|
|
158
170
|
outputStructure?: OutputStructure;
|
|
171
|
+
/**
|
|
172
|
+
* Override entire auto-generated OpenAPI Operation Object Specification.
|
|
173
|
+
*
|
|
174
|
+
* @see {@link https://orpc.unnoq.com/docs/openapi/openapi-specification#operation-metadata Operation Metadata Docs}
|
|
175
|
+
*/
|
|
176
|
+
spec?: OpenAPIV3_1.OperationObject | ((current: OpenAPIV3_1.OperationObject) => OpenAPIV3_1.OperationObject);
|
|
159
177
|
}
|
|
160
178
|
declare function mergeRoute(a: Route, b: Route): Route;
|
|
161
179
|
declare function prefixRoute(route: Route, prefix: HTTPPath): Route;
|
|
@@ -237,6 +255,15 @@ interface EnhanceContractRouterOptions<TErrorMap extends ErrorMap> extends Enhan
|
|
|
237
255
|
errorMap: TErrorMap;
|
|
238
256
|
}
|
|
239
257
|
declare function enhanceContractRouter<T extends AnyContractRouter, TErrorMap extends ErrorMap>(router: T, options: EnhanceContractRouterOptions<TErrorMap>): EnhancedContractRouter<T, TErrorMap>;
|
|
258
|
+
/**
|
|
259
|
+
* Minify a contract router into a smaller object.
|
|
260
|
+
*
|
|
261
|
+
* 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.
|
|
262
|
+
* This reduces the size of the contract and helps prevent leaking internal details of the router to the client.
|
|
263
|
+
*
|
|
264
|
+
* @see {@link https://orpc.unnoq.com/docs/contract-first/router-to-contract#minify-export-the-contract-router-for-the-client Router to Contract Docs}
|
|
265
|
+
*/
|
|
266
|
+
declare function minifyContractRouter(router: AnyContractRouter): AnyContractRouter;
|
|
240
267
|
|
|
241
268
|
interface ContractProcedureBuilder<TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta> extends ContractProcedure<TInputSchema, TOutputSchema, TErrorMap, TMeta> {
|
|
242
269
|
/**
|
|
@@ -501,11 +528,20 @@ interface EventIteratorSchemaDetails {
|
|
|
501
528
|
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>>;
|
|
502
529
|
declare function getEventIteratorSchemaDetails(schema: AnySchema | undefined): undefined | EventIteratorSchemaDetails;
|
|
503
530
|
|
|
531
|
+
/**
|
|
532
|
+
* Help RPCLink automatically send requests using the specified HTTP method in the contract.
|
|
533
|
+
*
|
|
534
|
+
* @see {@link https://orpc.unnoq.com/docs/client/rpc-link#custom-request-method RPCLink Custom Request Method}
|
|
535
|
+
*/
|
|
536
|
+
declare function inferRPCMethodFromContractRouter(contract: AnyContractRouter): (options: unknown, path: readonly string[]) => Exclude<HTTPMethod, 'HEAD'>;
|
|
537
|
+
|
|
504
538
|
type ContractProcedureClient<TClientContext extends ClientContext, TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap> = Client<TClientContext, InferSchemaInput<TInputSchema>, InferSchemaOutput<TOutputSchema>, ErrorFromErrorMap<TErrorMap>>;
|
|
505
539
|
|
|
506
540
|
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> : {
|
|
507
541
|
[K in keyof TRouter]: TRouter[K] extends AnyContractRouter ? ContractRouterClient<TRouter[K], TClientContext> : never;
|
|
508
542
|
};
|
|
509
543
|
|
|
510
|
-
|
|
544
|
+
declare function isSchemaIssue(issue: unknown): issue is SchemaIssue;
|
|
545
|
+
|
|
546
|
+
export { ContractBuilder, ContractProcedure, ValidationError, enhanceContractRouter, enhanceRoute, eventIterator, fallbackContractConfig, getContractRouter, getEventIteratorSchemaDetails, inferRPCMethodFromContractRouter, isContractProcedure, isSchemaIssue, mergeErrorMap, mergeMeta, mergePrefix, mergeRoute, mergeTags, minifyContractRouter, oc, prefixRoute, type, unshiftTagRoute };
|
|
511
547
|
export type { AnyContractProcedure, AnyContractRouter, AnySchema, ContractBuilderDef, ContractConfig, ContractProcedureBuilder, ContractProcedureBuilderWithInput, ContractProcedureBuilderWithInputOutput, ContractProcedureBuilderWithOutput, ContractProcedureClient, ContractProcedureDef, ContractRouter, ContractRouterBuilder, ContractRouterClient, EnhanceContractRouterOptions, EnhanceRouteOptions, EnhancedContractRouter, ErrorFromErrorMap, ErrorMap, ErrorMapItem, EventIteratorSchemaDetails, InferContractRouterErrorMap, InferContractRouterInputs, InferContractRouterMeta, InferContractRouterOutputs, InferSchemaInput, InferSchemaOutput, InputStructure, MergedErrorMap, Meta, ORPCErrorFromErrorMap, OutputStructure, Route, Schema, SchemaIssue, TypeRest, ValidationErrorOptions };
|
package/dist/index.d.ts
CHANGED
|
@@ -3,6 +3,8 @@ export { HTTPMethod, HTTPPath, ORPCError } from '@orpc/client';
|
|
|
3
3
|
import { Promisable, IsEqual, ThrowableError } from '@orpc/shared';
|
|
4
4
|
export { Registry, ThrowableError } from '@orpc/shared';
|
|
5
5
|
import { StandardSchemaV1 } from '@standard-schema/spec';
|
|
6
|
+
import { OpenAPIV3_1 } from 'openapi-types';
|
|
7
|
+
export { OpenAPIV3_1 as OpenAPI } from 'openapi-types';
|
|
6
8
|
|
|
7
9
|
type Schema<TInput, TOutput> = StandardSchemaV1<TInput, TOutput>;
|
|
8
10
|
type AnySchema = Schema<any, any>;
|
|
@@ -66,6 +68,13 @@ interface Route {
|
|
|
66
68
|
* @see {@link https://orpc.unnoq.com/docs/openapi/routing OpenAPI Routing Docs}
|
|
67
69
|
*/
|
|
68
70
|
path?: HTTPPath;
|
|
71
|
+
/**
|
|
72
|
+
* The operation ID of the endpoint.
|
|
73
|
+
* This option is typically relevant when integrating with OpenAPI.
|
|
74
|
+
*
|
|
75
|
+
* @default Concatenation of router segments
|
|
76
|
+
*/
|
|
77
|
+
operationId?: string;
|
|
69
78
|
/**
|
|
70
79
|
* The summary of the procedure.
|
|
71
80
|
* This option is typically relevant when integrating with OpenAPI.
|
|
@@ -96,6 +105,7 @@ interface Route {
|
|
|
96
105
|
tags?: readonly string[];
|
|
97
106
|
/**
|
|
98
107
|
* The status code of the response when the procedure is successful.
|
|
108
|
+
* The status code must be in the 200-399 range.
|
|
99
109
|
* This option is typically relevant when integrating with OpenAPI.
|
|
100
110
|
*
|
|
101
111
|
* @see {@link https://orpc.unnoq.com/docs/openapi/routing OpenAPI Routing Docs}
|
|
@@ -137,16 +147,18 @@ interface Route {
|
|
|
137
147
|
* Determines how the response should be structured based on the output.
|
|
138
148
|
*
|
|
139
149
|
* @option 'compact'
|
|
140
|
-
*
|
|
150
|
+
* The output data is directly returned as the response body.
|
|
141
151
|
*
|
|
142
152
|
* @option 'detailed'
|
|
143
|
-
*
|
|
144
|
-
* - `
|
|
145
|
-
* - `
|
|
153
|
+
* Return an object with optional properties:
|
|
154
|
+
* - `status`: The response status (must be in 200-399 range) if not set fallback to `successStatus`.
|
|
155
|
+
* - `headers`: Custom headers to merge with the response headers (`Record<string, string | string[] | undefined>`)
|
|
156
|
+
* - `body`: The response body.
|
|
146
157
|
*
|
|
147
158
|
* Example:
|
|
148
159
|
* ```ts
|
|
149
160
|
* const output = {
|
|
161
|
+
* status: 201,
|
|
150
162
|
* headers: { 'x-custom-header': 'value' },
|
|
151
163
|
* body: { message: 'Hello, world!' },
|
|
152
164
|
* };
|
|
@@ -156,6 +168,12 @@ interface Route {
|
|
|
156
168
|
* @default 'compact'
|
|
157
169
|
*/
|
|
158
170
|
outputStructure?: OutputStructure;
|
|
171
|
+
/**
|
|
172
|
+
* Override entire auto-generated OpenAPI Operation Object Specification.
|
|
173
|
+
*
|
|
174
|
+
* @see {@link https://orpc.unnoq.com/docs/openapi/openapi-specification#operation-metadata Operation Metadata Docs}
|
|
175
|
+
*/
|
|
176
|
+
spec?: OpenAPIV3_1.OperationObject | ((current: OpenAPIV3_1.OperationObject) => OpenAPIV3_1.OperationObject);
|
|
159
177
|
}
|
|
160
178
|
declare function mergeRoute(a: Route, b: Route): Route;
|
|
161
179
|
declare function prefixRoute(route: Route, prefix: HTTPPath): Route;
|
|
@@ -237,6 +255,15 @@ interface EnhanceContractRouterOptions<TErrorMap extends ErrorMap> extends Enhan
|
|
|
237
255
|
errorMap: TErrorMap;
|
|
238
256
|
}
|
|
239
257
|
declare function enhanceContractRouter<T extends AnyContractRouter, TErrorMap extends ErrorMap>(router: T, options: EnhanceContractRouterOptions<TErrorMap>): EnhancedContractRouter<T, TErrorMap>;
|
|
258
|
+
/**
|
|
259
|
+
* Minify a contract router into a smaller object.
|
|
260
|
+
*
|
|
261
|
+
* 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.
|
|
262
|
+
* This reduces the size of the contract and helps prevent leaking internal details of the router to the client.
|
|
263
|
+
*
|
|
264
|
+
* @see {@link https://orpc.unnoq.com/docs/contract-first/router-to-contract#minify-export-the-contract-router-for-the-client Router to Contract Docs}
|
|
265
|
+
*/
|
|
266
|
+
declare function minifyContractRouter(router: AnyContractRouter): AnyContractRouter;
|
|
240
267
|
|
|
241
268
|
interface ContractProcedureBuilder<TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta> extends ContractProcedure<TInputSchema, TOutputSchema, TErrorMap, TMeta> {
|
|
242
269
|
/**
|
|
@@ -501,11 +528,20 @@ interface EventIteratorSchemaDetails {
|
|
|
501
528
|
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>>;
|
|
502
529
|
declare function getEventIteratorSchemaDetails(schema: AnySchema | undefined): undefined | EventIteratorSchemaDetails;
|
|
503
530
|
|
|
531
|
+
/**
|
|
532
|
+
* Help RPCLink automatically send requests using the specified HTTP method in the contract.
|
|
533
|
+
*
|
|
534
|
+
* @see {@link https://orpc.unnoq.com/docs/client/rpc-link#custom-request-method RPCLink Custom Request Method}
|
|
535
|
+
*/
|
|
536
|
+
declare function inferRPCMethodFromContractRouter(contract: AnyContractRouter): (options: unknown, path: readonly string[]) => Exclude<HTTPMethod, 'HEAD'>;
|
|
537
|
+
|
|
504
538
|
type ContractProcedureClient<TClientContext extends ClientContext, TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap> = Client<TClientContext, InferSchemaInput<TInputSchema>, InferSchemaOutput<TOutputSchema>, ErrorFromErrorMap<TErrorMap>>;
|
|
505
539
|
|
|
506
540
|
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> : {
|
|
507
541
|
[K in keyof TRouter]: TRouter[K] extends AnyContractRouter ? ContractRouterClient<TRouter[K], TClientContext> : never;
|
|
508
542
|
};
|
|
509
543
|
|
|
510
|
-
|
|
544
|
+
declare function isSchemaIssue(issue: unknown): issue is SchemaIssue;
|
|
545
|
+
|
|
546
|
+
export { ContractBuilder, ContractProcedure, ValidationError, enhanceContractRouter, enhanceRoute, eventIterator, fallbackContractConfig, getContractRouter, getEventIteratorSchemaDetails, inferRPCMethodFromContractRouter, isContractProcedure, isSchemaIssue, mergeErrorMap, mergeMeta, mergePrefix, mergeRoute, mergeTags, minifyContractRouter, oc, prefixRoute, type, unshiftTagRoute };
|
|
511
547
|
export type { AnyContractProcedure, AnyContractRouter, AnySchema, ContractBuilderDef, ContractConfig, ContractProcedureBuilder, ContractProcedureBuilderWithInput, ContractProcedureBuilderWithInputOutput, ContractProcedureBuilderWithOutput, ContractProcedureClient, ContractProcedureDef, ContractRouter, ContractRouterBuilder, ContractRouterClient, EnhanceContractRouterOptions, EnhanceRouteOptions, EnhancedContractRouter, ErrorFromErrorMap, ErrorMap, ErrorMapItem, EventIteratorSchemaDetails, InferContractRouterErrorMap, InferContractRouterInputs, InferContractRouterMeta, InferContractRouterOutputs, InferSchemaInput, InferSchemaOutput, InputStructure, MergedErrorMap, Meta, ORPCErrorFromErrorMap, OutputStructure, Route, Schema, SchemaIssue, TypeRest, ValidationErrorOptions };
|
package/dist/index.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { isORPCErrorStatus, mapEventIterator, ORPCError } from '@orpc/client';
|
|
2
2
|
export { ORPCError } from '@orpc/client';
|
|
3
|
-
import { isAsyncIteratorObject } from '@orpc/shared';
|
|
3
|
+
import { isAsyncIteratorObject, get, isTypescriptObject, isPropertyKey } from '@orpc/shared';
|
|
4
4
|
|
|
5
5
|
class ValidationError extends Error {
|
|
6
6
|
issues;
|
|
@@ -103,6 +103,23 @@ function enhanceContractRouter(router, options) {
|
|
|
103
103
|
}
|
|
104
104
|
return enhanced;
|
|
105
105
|
}
|
|
106
|
+
function minifyContractRouter(router) {
|
|
107
|
+
if (isContractProcedure(router)) {
|
|
108
|
+
const procedure = {
|
|
109
|
+
"~orpc": {
|
|
110
|
+
errorMap: {},
|
|
111
|
+
meta: router["~orpc"].meta,
|
|
112
|
+
route: router["~orpc"].route
|
|
113
|
+
}
|
|
114
|
+
};
|
|
115
|
+
return procedure;
|
|
116
|
+
}
|
|
117
|
+
const json = {};
|
|
118
|
+
for (const key in router) {
|
|
119
|
+
json[key] = minifyContractRouter(router[key]);
|
|
120
|
+
}
|
|
121
|
+
return json;
|
|
122
|
+
}
|
|
106
123
|
|
|
107
124
|
class ContractBuilder extends ContractProcedure {
|
|
108
125
|
constructor(def) {
|
|
@@ -292,6 +309,19 @@ function getEventIteratorSchemaDetails(schema) {
|
|
|
292
309
|
return schema["~standard"][EVENT_ITERATOR_DETAILS_SYMBOL];
|
|
293
310
|
}
|
|
294
311
|
|
|
312
|
+
function inferRPCMethodFromContractRouter(contract) {
|
|
313
|
+
return (_, path) => {
|
|
314
|
+
const procedure = get(contract, path);
|
|
315
|
+
if (!isContractProcedure(procedure)) {
|
|
316
|
+
throw new Error(
|
|
317
|
+
`[inferRPCMethodFromContractRouter] No valid procedure found at path "${path.join(".")}". This may happen when the contract router is not properly configured.`
|
|
318
|
+
);
|
|
319
|
+
}
|
|
320
|
+
const method = fallbackContractConfig("defaultMethod", procedure["~orpc"].route.method);
|
|
321
|
+
return method === "HEAD" ? "GET" : method;
|
|
322
|
+
};
|
|
323
|
+
}
|
|
324
|
+
|
|
295
325
|
function type(...[map]) {
|
|
296
326
|
return {
|
|
297
327
|
"~standard": {
|
|
@@ -307,4 +337,19 @@ function type(...[map]) {
|
|
|
307
337
|
};
|
|
308
338
|
}
|
|
309
339
|
|
|
310
|
-
|
|
340
|
+
function isSchemaIssue(issue) {
|
|
341
|
+
if (!isTypescriptObject(issue) || typeof issue.message !== "string") {
|
|
342
|
+
return false;
|
|
343
|
+
}
|
|
344
|
+
if (issue.path !== void 0) {
|
|
345
|
+
if (!Array.isArray(issue.path)) {
|
|
346
|
+
return false;
|
|
347
|
+
}
|
|
348
|
+
if (!issue.path.every((segment) => isPropertyKey(segment) || isTypescriptObject(segment) && isPropertyKey(segment.key))) {
|
|
349
|
+
return false;
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
return true;
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
export { ContractBuilder, ContractProcedure, ValidationError, enhanceContractRouter, enhanceRoute, eventIterator, fallbackContractConfig, getContractRouter, getEventIteratorSchemaDetails, inferRPCMethodFromContractRouter, isContractProcedure, isSchemaIssue, mergeErrorMap, mergeMeta, mergePrefix, mergeRoute, mergeTags, minifyContractRouter, oc, prefixRoute, type, unshiftTagRoute };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@orpc/contract",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.0.0-next.
|
|
4
|
+
"version": "0.0.0-next.f9e0a4c",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"homepage": "https://orpc.unnoq.com",
|
|
7
7
|
"repository": {
|
|
@@ -25,13 +25,14 @@
|
|
|
25
25
|
],
|
|
26
26
|
"dependencies": {
|
|
27
27
|
"@standard-schema/spec": "^1.0.0",
|
|
28
|
-
"
|
|
29
|
-
"@orpc/
|
|
28
|
+
"openapi-types": "^12.1.3",
|
|
29
|
+
"@orpc/client": "0.0.0-next.f9e0a4c",
|
|
30
|
+
"@orpc/shared": "0.0.0-next.f9e0a4c"
|
|
30
31
|
},
|
|
31
32
|
"devDependencies": {
|
|
32
|
-
"arktype": "2.1.
|
|
33
|
-
"valibot": "1.
|
|
34
|
-
"zod": "^
|
|
33
|
+
"arktype": "2.1.20",
|
|
34
|
+
"valibot": "^1.1.0",
|
|
35
|
+
"zod": "^4.0.17"
|
|
35
36
|
},
|
|
36
37
|
"scripts": {
|
|
37
38
|
"build": "unbuild",
|