@orpc/contract 0.0.0-next.4a7a06a → 0.0.0-next.4b3a4c5
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 +8 -8
- package/dist/index.d.mts +46 -5
- package/dist/index.d.ts +46 -5
- package/dist/index.mjs +51 -3
- package/package.json +6 -5
package/README.md
CHANGED
|
@@ -30,7 +30,8 @@
|
|
|
30
30
|
- **🔗 End-to-End Type Safety**: Ensure type-safe inputs, outputs, and errors from client to server.
|
|
31
31
|
- **📘 First-Class OpenAPI**: Built-in support that fully adheres to the OpenAPI standard.
|
|
32
32
|
- **📝 Contract-First Development**: Optionally define your API contract before implementation.
|
|
33
|
-
-
|
|
33
|
+
- **🔍 First-Class OpenTelemetry**: Seamlessly integrate with OpenTelemetry for observability.
|
|
34
|
+
- **⚙️ Framework Integrations**: Seamlessly integrate with TanStack Query (React, Vue, Solid, Svelte, Angular), SWR, Pinia Colada, and more.
|
|
34
35
|
- **🚀 Server Actions**: Fully compatible with React Server Actions on Next.js, TanStack Start, and other platforms.
|
|
35
36
|
- **🔠 Standard Schema Support**: Works out of the box with Zod, Valibot, ArkType, and other schema validators.
|
|
36
37
|
- **🗃️ Native Types**: Supports native types like Date, File, Blob, BigInt, URL, and more.
|
|
@@ -38,7 +39,6 @@
|
|
|
38
39
|
- **📡 SSE & Streaming**: Enjoy full type-safe support for SSE and streaming.
|
|
39
40
|
- **🌍 Multi-Runtime Support**: Fast and lightweight on Cloudflare, Deno, Bun, Node.js, and beyond.
|
|
40
41
|
- **🔌 Extendability**: Easily extend functionality with plugins, middleware, and interceptors.
|
|
41
|
-
- **🛡️ Reliability**: Well-tested, TypeScript-based, production-ready, and MIT licensed.
|
|
42
42
|
|
|
43
43
|
## Documentation
|
|
44
44
|
|
|
@@ -49,14 +49,14 @@ You can find the full documentation [here](https://orpc.unnoq.com).
|
|
|
49
49
|
- [@orpc/contract](https://www.npmjs.com/package/@orpc/contract): Build your API contract.
|
|
50
50
|
- [@orpc/server](https://www.npmjs.com/package/@orpc/server): Build your API or implement API contract.
|
|
51
51
|
- [@orpc/client](https://www.npmjs.com/package/@orpc/client): Consume your API on the client with type-safety.
|
|
52
|
-
- [@orpc/
|
|
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/).
|
|
53
55
|
- [@orpc/react](https://www.npmjs.com/package/@orpc/react): Utilities for integrating oRPC with React and React Server Actions.
|
|
54
|
-
- [@orpc/
|
|
55
|
-
- [@orpc/
|
|
56
|
-
- [@orpc/solid-query](https://www.npmjs.com/package/@orpc/solid-query): Integration with [Solid Query](https://tanstack.com/query/latest/docs/framework/solid/overview).
|
|
57
|
-
- [@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.
|
|
57
|
+
- [@orpc/experimental-react-swr](https://www.npmjs.com/package/@orpc/experimental-react-swr): [SWR](https://swr.vercel.app/) integration.
|
|
58
58
|
- [@orpc/vue-colada](https://www.npmjs.com/package/@orpc/vue-colada): Integration with [Pinia Colada](https://pinia-colada.esm.dev/).
|
|
59
|
-
- [@orpc/
|
|
59
|
+
- [@orpc/hey-api](https://www.npmjs.com/package/@orpc/hey-api): [Hey API](https://heyapi.dev/) integration.
|
|
60
60
|
- [@orpc/zod](https://www.npmjs.com/package/@orpc/zod): More schemas that [Zod](https://zod.dev/) doesn't support yet.
|
|
61
61
|
- [@orpc/valibot](https://www.npmjs.com/package/@orpc/valibot): OpenAPI spec generation from [Valibot](https://valibot.dev/).
|
|
62
62
|
- [@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>;
|
|
@@ -21,6 +23,10 @@ declare function type<TInput, TOutput = TInput>(...[map]: TypeRest<TInput, TOutp
|
|
|
21
23
|
interface ValidationErrorOptions extends ErrorOptions {
|
|
22
24
|
message: string;
|
|
23
25
|
issues: readonly SchemaIssue[];
|
|
26
|
+
/**
|
|
27
|
+
* @todo require this field in v2
|
|
28
|
+
*/
|
|
29
|
+
data?: unknown;
|
|
24
30
|
}
|
|
25
31
|
/**
|
|
26
32
|
* This errors usually used for ORPCError.cause when the error is a validation error.
|
|
@@ -29,6 +35,7 @@ interface ValidationErrorOptions extends ErrorOptions {
|
|
|
29
35
|
*/
|
|
30
36
|
declare class ValidationError extends Error {
|
|
31
37
|
readonly issues: readonly SchemaIssue[];
|
|
38
|
+
readonly data: unknown;
|
|
32
39
|
constructor(options: ValidationErrorOptions);
|
|
33
40
|
}
|
|
34
41
|
interface ErrorMapItem<TDataSchema extends AnySchema> {
|
|
@@ -66,6 +73,13 @@ interface Route {
|
|
|
66
73
|
* @see {@link https://orpc.unnoq.com/docs/openapi/routing OpenAPI Routing Docs}
|
|
67
74
|
*/
|
|
68
75
|
path?: HTTPPath;
|
|
76
|
+
/**
|
|
77
|
+
* The operation ID of the endpoint.
|
|
78
|
+
* This option is typically relevant when integrating with OpenAPI.
|
|
79
|
+
*
|
|
80
|
+
* @default Concatenation of router segments
|
|
81
|
+
*/
|
|
82
|
+
operationId?: string;
|
|
69
83
|
/**
|
|
70
84
|
* The summary of the procedure.
|
|
71
85
|
* This option is typically relevant when integrating with OpenAPI.
|
|
@@ -96,6 +110,7 @@ interface Route {
|
|
|
96
110
|
tags?: readonly string[];
|
|
97
111
|
/**
|
|
98
112
|
* The status code of the response when the procedure is successful.
|
|
113
|
+
* The status code must be in the 200-399 range.
|
|
99
114
|
* This option is typically relevant when integrating with OpenAPI.
|
|
100
115
|
*
|
|
101
116
|
* @see {@link https://orpc.unnoq.com/docs/openapi/routing OpenAPI Routing Docs}
|
|
@@ -137,16 +152,18 @@ interface Route {
|
|
|
137
152
|
* Determines how the response should be structured based on the output.
|
|
138
153
|
*
|
|
139
154
|
* @option 'compact'
|
|
140
|
-
*
|
|
155
|
+
* The output data is directly returned as the response body.
|
|
141
156
|
*
|
|
142
157
|
* @option 'detailed'
|
|
143
|
-
*
|
|
144
|
-
* - `
|
|
145
|
-
* - `
|
|
158
|
+
* Return an object with optional properties:
|
|
159
|
+
* - `status`: The response status (must be in 200-399 range) if not set fallback to `successStatus`.
|
|
160
|
+
* - `headers`: Custom headers to merge with the response headers (`Record<string, string | string[] | undefined>`)
|
|
161
|
+
* - `body`: The response body.
|
|
146
162
|
*
|
|
147
163
|
* Example:
|
|
148
164
|
* ```ts
|
|
149
165
|
* const output = {
|
|
166
|
+
* status: 201,
|
|
150
167
|
* headers: { 'x-custom-header': 'value' },
|
|
151
168
|
* body: { message: 'Hello, world!' },
|
|
152
169
|
* };
|
|
@@ -156,6 +173,12 @@ interface Route {
|
|
|
156
173
|
* @default 'compact'
|
|
157
174
|
*/
|
|
158
175
|
outputStructure?: OutputStructure;
|
|
176
|
+
/**
|
|
177
|
+
* Override entire auto-generated OpenAPI Operation Object Specification.
|
|
178
|
+
*
|
|
179
|
+
* @see {@link https://orpc.unnoq.com/docs/openapi/openapi-specification#operation-metadata Operation Metadata Docs}
|
|
180
|
+
*/
|
|
181
|
+
spec?: OpenAPIV3_1.OperationObject | ((current: OpenAPIV3_1.OperationObject) => OpenAPIV3_1.OperationObject);
|
|
159
182
|
}
|
|
160
183
|
declare function mergeRoute(a: Route, b: Route): Route;
|
|
161
184
|
declare function prefixRoute(route: Route, prefix: HTTPPath): Route;
|
|
@@ -237,6 +260,15 @@ interface EnhanceContractRouterOptions<TErrorMap extends ErrorMap> extends Enhan
|
|
|
237
260
|
errorMap: TErrorMap;
|
|
238
261
|
}
|
|
239
262
|
declare function enhanceContractRouter<T extends AnyContractRouter, TErrorMap extends ErrorMap>(router: T, options: EnhanceContractRouterOptions<TErrorMap>): EnhancedContractRouter<T, TErrorMap>;
|
|
263
|
+
/**
|
|
264
|
+
* Minify a contract router into a smaller object.
|
|
265
|
+
*
|
|
266
|
+
* 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.
|
|
267
|
+
* This reduces the size of the contract and helps prevent leaking internal details of the router to the client.
|
|
268
|
+
*
|
|
269
|
+
* @see {@link https://orpc.unnoq.com/docs/contract-first/router-to-contract#minify-export-the-contract-router-for-the-client Router to Contract Docs}
|
|
270
|
+
*/
|
|
271
|
+
declare function minifyContractRouter(router: AnyContractRouter): AnyContractRouter;
|
|
240
272
|
|
|
241
273
|
interface ContractProcedureBuilder<TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta> extends ContractProcedure<TInputSchema, TOutputSchema, TErrorMap, TMeta> {
|
|
242
274
|
/**
|
|
@@ -501,11 +533,20 @@ interface EventIteratorSchemaDetails {
|
|
|
501
533
|
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
534
|
declare function getEventIteratorSchemaDetails(schema: AnySchema | undefined): undefined | EventIteratorSchemaDetails;
|
|
503
535
|
|
|
536
|
+
/**
|
|
537
|
+
* Help RPCLink automatically send requests using the specified HTTP method in the contract.
|
|
538
|
+
*
|
|
539
|
+
* @see {@link https://orpc.unnoq.com/docs/client/rpc-link#custom-request-method RPCLink Custom Request Method}
|
|
540
|
+
*/
|
|
541
|
+
declare function inferRPCMethodFromContractRouter(contract: AnyContractRouter): (options: unknown, path: readonly string[]) => Exclude<HTTPMethod, 'HEAD'>;
|
|
542
|
+
|
|
504
543
|
type ContractProcedureClient<TClientContext extends ClientContext, TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap> = Client<TClientContext, InferSchemaInput<TInputSchema>, InferSchemaOutput<TOutputSchema>, ErrorFromErrorMap<TErrorMap>>;
|
|
505
544
|
|
|
506
545
|
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
546
|
[K in keyof TRouter]: TRouter[K] extends AnyContractRouter ? ContractRouterClient<TRouter[K], TClientContext> : never;
|
|
508
547
|
};
|
|
509
548
|
|
|
510
|
-
|
|
549
|
+
declare function isSchemaIssue(issue: unknown): issue is SchemaIssue;
|
|
550
|
+
|
|
551
|
+
export { ContractBuilder, ContractProcedure, ValidationError, enhanceContractRouter, enhanceRoute, eventIterator, fallbackContractConfig, getContractRouter, getEventIteratorSchemaDetails, inferRPCMethodFromContractRouter, isContractProcedure, isSchemaIssue, mergeErrorMap, mergeMeta, mergePrefix, mergeRoute, mergeTags, minifyContractRouter, oc, prefixRoute, type, unshiftTagRoute };
|
|
511
552
|
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>;
|
|
@@ -21,6 +23,10 @@ declare function type<TInput, TOutput = TInput>(...[map]: TypeRest<TInput, TOutp
|
|
|
21
23
|
interface ValidationErrorOptions extends ErrorOptions {
|
|
22
24
|
message: string;
|
|
23
25
|
issues: readonly SchemaIssue[];
|
|
26
|
+
/**
|
|
27
|
+
* @todo require this field in v2
|
|
28
|
+
*/
|
|
29
|
+
data?: unknown;
|
|
24
30
|
}
|
|
25
31
|
/**
|
|
26
32
|
* This errors usually used for ORPCError.cause when the error is a validation error.
|
|
@@ -29,6 +35,7 @@ interface ValidationErrorOptions extends ErrorOptions {
|
|
|
29
35
|
*/
|
|
30
36
|
declare class ValidationError extends Error {
|
|
31
37
|
readonly issues: readonly SchemaIssue[];
|
|
38
|
+
readonly data: unknown;
|
|
32
39
|
constructor(options: ValidationErrorOptions);
|
|
33
40
|
}
|
|
34
41
|
interface ErrorMapItem<TDataSchema extends AnySchema> {
|
|
@@ -66,6 +73,13 @@ interface Route {
|
|
|
66
73
|
* @see {@link https://orpc.unnoq.com/docs/openapi/routing OpenAPI Routing Docs}
|
|
67
74
|
*/
|
|
68
75
|
path?: HTTPPath;
|
|
76
|
+
/**
|
|
77
|
+
* The operation ID of the endpoint.
|
|
78
|
+
* This option is typically relevant when integrating with OpenAPI.
|
|
79
|
+
*
|
|
80
|
+
* @default Concatenation of router segments
|
|
81
|
+
*/
|
|
82
|
+
operationId?: string;
|
|
69
83
|
/**
|
|
70
84
|
* The summary of the procedure.
|
|
71
85
|
* This option is typically relevant when integrating with OpenAPI.
|
|
@@ -96,6 +110,7 @@ interface Route {
|
|
|
96
110
|
tags?: readonly string[];
|
|
97
111
|
/**
|
|
98
112
|
* The status code of the response when the procedure is successful.
|
|
113
|
+
* The status code must be in the 200-399 range.
|
|
99
114
|
* This option is typically relevant when integrating with OpenAPI.
|
|
100
115
|
*
|
|
101
116
|
* @see {@link https://orpc.unnoq.com/docs/openapi/routing OpenAPI Routing Docs}
|
|
@@ -137,16 +152,18 @@ interface Route {
|
|
|
137
152
|
* Determines how the response should be structured based on the output.
|
|
138
153
|
*
|
|
139
154
|
* @option 'compact'
|
|
140
|
-
*
|
|
155
|
+
* The output data is directly returned as the response body.
|
|
141
156
|
*
|
|
142
157
|
* @option 'detailed'
|
|
143
|
-
*
|
|
144
|
-
* - `
|
|
145
|
-
* - `
|
|
158
|
+
* Return an object with optional properties:
|
|
159
|
+
* - `status`: The response status (must be in 200-399 range) if not set fallback to `successStatus`.
|
|
160
|
+
* - `headers`: Custom headers to merge with the response headers (`Record<string, string | string[] | undefined>`)
|
|
161
|
+
* - `body`: The response body.
|
|
146
162
|
*
|
|
147
163
|
* Example:
|
|
148
164
|
* ```ts
|
|
149
165
|
* const output = {
|
|
166
|
+
* status: 201,
|
|
150
167
|
* headers: { 'x-custom-header': 'value' },
|
|
151
168
|
* body: { message: 'Hello, world!' },
|
|
152
169
|
* };
|
|
@@ -156,6 +173,12 @@ interface Route {
|
|
|
156
173
|
* @default 'compact'
|
|
157
174
|
*/
|
|
158
175
|
outputStructure?: OutputStructure;
|
|
176
|
+
/**
|
|
177
|
+
* Override entire auto-generated OpenAPI Operation Object Specification.
|
|
178
|
+
*
|
|
179
|
+
* @see {@link https://orpc.unnoq.com/docs/openapi/openapi-specification#operation-metadata Operation Metadata Docs}
|
|
180
|
+
*/
|
|
181
|
+
spec?: OpenAPIV3_1.OperationObject | ((current: OpenAPIV3_1.OperationObject) => OpenAPIV3_1.OperationObject);
|
|
159
182
|
}
|
|
160
183
|
declare function mergeRoute(a: Route, b: Route): Route;
|
|
161
184
|
declare function prefixRoute(route: Route, prefix: HTTPPath): Route;
|
|
@@ -237,6 +260,15 @@ interface EnhanceContractRouterOptions<TErrorMap extends ErrorMap> extends Enhan
|
|
|
237
260
|
errorMap: TErrorMap;
|
|
238
261
|
}
|
|
239
262
|
declare function enhanceContractRouter<T extends AnyContractRouter, TErrorMap extends ErrorMap>(router: T, options: EnhanceContractRouterOptions<TErrorMap>): EnhancedContractRouter<T, TErrorMap>;
|
|
263
|
+
/**
|
|
264
|
+
* Minify a contract router into a smaller object.
|
|
265
|
+
*
|
|
266
|
+
* 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.
|
|
267
|
+
* This reduces the size of the contract and helps prevent leaking internal details of the router to the client.
|
|
268
|
+
*
|
|
269
|
+
* @see {@link https://orpc.unnoq.com/docs/contract-first/router-to-contract#minify-export-the-contract-router-for-the-client Router to Contract Docs}
|
|
270
|
+
*/
|
|
271
|
+
declare function minifyContractRouter(router: AnyContractRouter): AnyContractRouter;
|
|
240
272
|
|
|
241
273
|
interface ContractProcedureBuilder<TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta> extends ContractProcedure<TInputSchema, TOutputSchema, TErrorMap, TMeta> {
|
|
242
274
|
/**
|
|
@@ -501,11 +533,20 @@ interface EventIteratorSchemaDetails {
|
|
|
501
533
|
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
534
|
declare function getEventIteratorSchemaDetails(schema: AnySchema | undefined): undefined | EventIteratorSchemaDetails;
|
|
503
535
|
|
|
536
|
+
/**
|
|
537
|
+
* Help RPCLink automatically send requests using the specified HTTP method in the contract.
|
|
538
|
+
*
|
|
539
|
+
* @see {@link https://orpc.unnoq.com/docs/client/rpc-link#custom-request-method RPCLink Custom Request Method}
|
|
540
|
+
*/
|
|
541
|
+
declare function inferRPCMethodFromContractRouter(contract: AnyContractRouter): (options: unknown, path: readonly string[]) => Exclude<HTTPMethod, 'HEAD'>;
|
|
542
|
+
|
|
504
543
|
type ContractProcedureClient<TClientContext extends ClientContext, TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap> = Client<TClientContext, InferSchemaInput<TInputSchema>, InferSchemaOutput<TOutputSchema>, ErrorFromErrorMap<TErrorMap>>;
|
|
505
544
|
|
|
506
545
|
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
546
|
[K in keyof TRouter]: TRouter[K] extends AnyContractRouter ? ContractRouterClient<TRouter[K], TClientContext> : never;
|
|
508
547
|
};
|
|
509
548
|
|
|
510
|
-
|
|
549
|
+
declare function isSchemaIssue(issue: unknown): issue is SchemaIssue;
|
|
550
|
+
|
|
551
|
+
export { ContractBuilder, ContractProcedure, ValidationError, enhanceContractRouter, enhanceRoute, eventIterator, fallbackContractConfig, getContractRouter, getEventIteratorSchemaDetails, inferRPCMethodFromContractRouter, isContractProcedure, isSchemaIssue, mergeErrorMap, mergeMeta, mergePrefix, mergeRoute, mergeTags, minifyContractRouter, oc, prefixRoute, type, unshiftTagRoute };
|
|
511
552
|
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,12 +1,14 @@
|
|
|
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;
|
|
7
|
+
data;
|
|
7
8
|
constructor(options) {
|
|
8
9
|
super(options.message, options);
|
|
9
10
|
this.issues = options.issues;
|
|
11
|
+
this.data = options.data;
|
|
10
12
|
}
|
|
11
13
|
}
|
|
12
14
|
function mergeErrorMap(errorMap1, errorMap2) {
|
|
@@ -103,6 +105,23 @@ function enhanceContractRouter(router, options) {
|
|
|
103
105
|
}
|
|
104
106
|
return enhanced;
|
|
105
107
|
}
|
|
108
|
+
function minifyContractRouter(router) {
|
|
109
|
+
if (isContractProcedure(router)) {
|
|
110
|
+
const procedure = {
|
|
111
|
+
"~orpc": {
|
|
112
|
+
errorMap: {},
|
|
113
|
+
meta: router["~orpc"].meta,
|
|
114
|
+
route: router["~orpc"].route
|
|
115
|
+
}
|
|
116
|
+
};
|
|
117
|
+
return procedure;
|
|
118
|
+
}
|
|
119
|
+
const json = {};
|
|
120
|
+
for (const key in router) {
|
|
121
|
+
json[key] = minifyContractRouter(router[key]);
|
|
122
|
+
}
|
|
123
|
+
return json;
|
|
124
|
+
}
|
|
106
125
|
|
|
107
126
|
class ContractBuilder extends ContractProcedure {
|
|
108
127
|
constructor(def) {
|
|
@@ -272,7 +291,8 @@ function eventIterator(yields, returns) {
|
|
|
272
291
|
message: "Event iterator validation failed",
|
|
273
292
|
cause: new ValidationError({
|
|
274
293
|
issues: result.issues,
|
|
275
|
-
message: "Event iterator validation failed"
|
|
294
|
+
message: "Event iterator validation failed",
|
|
295
|
+
data: value
|
|
276
296
|
})
|
|
277
297
|
});
|
|
278
298
|
}
|
|
@@ -292,6 +312,19 @@ function getEventIteratorSchemaDetails(schema) {
|
|
|
292
312
|
return schema["~standard"][EVENT_ITERATOR_DETAILS_SYMBOL];
|
|
293
313
|
}
|
|
294
314
|
|
|
315
|
+
function inferRPCMethodFromContractRouter(contract) {
|
|
316
|
+
return (_, path) => {
|
|
317
|
+
const procedure = get(contract, path);
|
|
318
|
+
if (!isContractProcedure(procedure)) {
|
|
319
|
+
throw new Error(
|
|
320
|
+
`[inferRPCMethodFromContractRouter] No valid procedure found at path "${path.join(".")}". This may happen when the contract router is not properly configured.`
|
|
321
|
+
);
|
|
322
|
+
}
|
|
323
|
+
const method = fallbackContractConfig("defaultMethod", procedure["~orpc"].route.method);
|
|
324
|
+
return method === "HEAD" ? "GET" : method;
|
|
325
|
+
};
|
|
326
|
+
}
|
|
327
|
+
|
|
295
328
|
function type(...[map]) {
|
|
296
329
|
return {
|
|
297
330
|
"~standard": {
|
|
@@ -307,4 +340,19 @@ function type(...[map]) {
|
|
|
307
340
|
};
|
|
308
341
|
}
|
|
309
342
|
|
|
310
|
-
|
|
343
|
+
function isSchemaIssue(issue) {
|
|
344
|
+
if (!isTypescriptObject(issue) || typeof issue.message !== "string") {
|
|
345
|
+
return false;
|
|
346
|
+
}
|
|
347
|
+
if (issue.path !== void 0) {
|
|
348
|
+
if (!Array.isArray(issue.path)) {
|
|
349
|
+
return false;
|
|
350
|
+
}
|
|
351
|
+
if (!issue.path.every((segment) => isPropertyKey(segment) || isTypescriptObject(segment) && isPropertyKey(segment.key))) {
|
|
352
|
+
return false;
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
return true;
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
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.4b3a4c5",
|
|
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/shared": "0.0.0-next.
|
|
28
|
+
"openapi-types": "^12.1.3",
|
|
29
|
+
"@orpc/shared": "0.0.0-next.4b3a4c5",
|
|
30
|
+
"@orpc/client": "0.0.0-next.4b3a4c5"
|
|
30
31
|
},
|
|
31
32
|
"devDependencies": {
|
|
32
33
|
"arktype": "2.1.20",
|
|
33
|
-
"valibot": "1.
|
|
34
|
-
"zod": "^
|
|
34
|
+
"valibot": "^1.1.0",
|
|
35
|
+
"zod": "^4.1.3"
|
|
35
36
|
},
|
|
36
37
|
"scripts": {
|
|
37
38
|
"build": "unbuild",
|