@orpc/contract 1.3.0 → 1.4.0
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/dist/index.d.mts +25 -1
- package/dist/index.d.ts +25 -1
- package/dist/index.mjs +32 -2
- package/package.json +5 -4
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>;
|
|
@@ -159,6 +161,12 @@ interface Route {
|
|
|
159
161
|
* @default 'compact'
|
|
160
162
|
*/
|
|
161
163
|
outputStructure?: OutputStructure;
|
|
164
|
+
/**
|
|
165
|
+
* Override entire auto-generated OpenAPI Operation Object Specification.
|
|
166
|
+
*
|
|
167
|
+
* @see {@link https://orpc.unnoq.com/docs/openapi/openapi-specification#operation-metadata Operation Metadata Docs}
|
|
168
|
+
*/
|
|
169
|
+
spec?: OpenAPIV3_1.OperationObject;
|
|
162
170
|
}
|
|
163
171
|
declare function mergeRoute(a: Route, b: Route): Route;
|
|
164
172
|
declare function prefixRoute(route: Route, prefix: HTTPPath): Route;
|
|
@@ -240,6 +248,15 @@ interface EnhanceContractRouterOptions<TErrorMap extends ErrorMap> extends Enhan
|
|
|
240
248
|
errorMap: TErrorMap;
|
|
241
249
|
}
|
|
242
250
|
declare function enhanceContractRouter<T extends AnyContractRouter, TErrorMap extends ErrorMap>(router: T, options: EnhanceContractRouterOptions<TErrorMap>): EnhancedContractRouter<T, TErrorMap>;
|
|
251
|
+
/**
|
|
252
|
+
* Minify a contract router into a smaller object.
|
|
253
|
+
*
|
|
254
|
+
* 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.
|
|
255
|
+
* This reduces the size of the contract and helps prevent leaking internal details of the router to the client.
|
|
256
|
+
*
|
|
257
|
+
* @see {@link https://orpc.unnoq.com/docs/contract-first/router-to-contract#minify-export-the-contract-router-for-the-client Router to Contract Docs}
|
|
258
|
+
*/
|
|
259
|
+
declare function minifyContractRouter(router: AnyContractRouter): AnyContractRouter;
|
|
243
260
|
|
|
244
261
|
interface ContractProcedureBuilder<TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta> extends ContractProcedure<TInputSchema, TOutputSchema, TErrorMap, TMeta> {
|
|
245
262
|
/**
|
|
@@ -504,6 +521,13 @@ interface EventIteratorSchemaDetails {
|
|
|
504
521
|
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>>;
|
|
505
522
|
declare function getEventIteratorSchemaDetails(schema: AnySchema | undefined): undefined | EventIteratorSchemaDetails;
|
|
506
523
|
|
|
524
|
+
/**
|
|
525
|
+
* Help RPCLink automatically send requests using the specified HTTP method in the contract.
|
|
526
|
+
*
|
|
527
|
+
* @see {@link https://orpc.unnoq.com/docs/client/rpc-link#custom-request-method RPCLink Custom Request Method}
|
|
528
|
+
*/
|
|
529
|
+
declare function inferRPCMethodFromContractRouter(contract: AnyContractRouter): (options: unknown, path: readonly string[]) => Exclude<HTTPMethod, 'HEAD'>;
|
|
530
|
+
|
|
507
531
|
type ContractProcedureClient<TClientContext extends ClientContext, TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap> = Client<TClientContext, InferSchemaInput<TInputSchema>, InferSchemaOutput<TOutputSchema>, ErrorFromErrorMap<TErrorMap>>;
|
|
508
532
|
|
|
509
533
|
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> : {
|
|
@@ -512,5 +536,5 @@ type ContractRouterClient<TRouter extends AnyContractRouter, TClientContext exte
|
|
|
512
536
|
|
|
513
537
|
declare function isSchemaIssue(issue: unknown): issue is SchemaIssue;
|
|
514
538
|
|
|
515
|
-
export { ContractBuilder, ContractProcedure, ValidationError, enhanceContractRouter, enhanceRoute, eventIterator, fallbackContractConfig, getContractRouter, getEventIteratorSchemaDetails, isContractProcedure, isSchemaIssue, mergeErrorMap, mergeMeta, mergePrefix, mergeRoute, mergeTags, oc, prefixRoute, type, unshiftTagRoute };
|
|
539
|
+
export { ContractBuilder, ContractProcedure, ValidationError, enhanceContractRouter, enhanceRoute, eventIterator, fallbackContractConfig, getContractRouter, getEventIteratorSchemaDetails, inferRPCMethodFromContractRouter, isContractProcedure, isSchemaIssue, mergeErrorMap, mergeMeta, mergePrefix, mergeRoute, mergeTags, minifyContractRouter, oc, prefixRoute, type, unshiftTagRoute };
|
|
516
540
|
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>;
|
|
@@ -159,6 +161,12 @@ interface Route {
|
|
|
159
161
|
* @default 'compact'
|
|
160
162
|
*/
|
|
161
163
|
outputStructure?: OutputStructure;
|
|
164
|
+
/**
|
|
165
|
+
* Override entire auto-generated OpenAPI Operation Object Specification.
|
|
166
|
+
*
|
|
167
|
+
* @see {@link https://orpc.unnoq.com/docs/openapi/openapi-specification#operation-metadata Operation Metadata Docs}
|
|
168
|
+
*/
|
|
169
|
+
spec?: OpenAPIV3_1.OperationObject;
|
|
162
170
|
}
|
|
163
171
|
declare function mergeRoute(a: Route, b: Route): Route;
|
|
164
172
|
declare function prefixRoute(route: Route, prefix: HTTPPath): Route;
|
|
@@ -240,6 +248,15 @@ interface EnhanceContractRouterOptions<TErrorMap extends ErrorMap> extends Enhan
|
|
|
240
248
|
errorMap: TErrorMap;
|
|
241
249
|
}
|
|
242
250
|
declare function enhanceContractRouter<T extends AnyContractRouter, TErrorMap extends ErrorMap>(router: T, options: EnhanceContractRouterOptions<TErrorMap>): EnhancedContractRouter<T, TErrorMap>;
|
|
251
|
+
/**
|
|
252
|
+
* Minify a contract router into a smaller object.
|
|
253
|
+
*
|
|
254
|
+
* 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.
|
|
255
|
+
* This reduces the size of the contract and helps prevent leaking internal details of the router to the client.
|
|
256
|
+
*
|
|
257
|
+
* @see {@link https://orpc.unnoq.com/docs/contract-first/router-to-contract#minify-export-the-contract-router-for-the-client Router to Contract Docs}
|
|
258
|
+
*/
|
|
259
|
+
declare function minifyContractRouter(router: AnyContractRouter): AnyContractRouter;
|
|
243
260
|
|
|
244
261
|
interface ContractProcedureBuilder<TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta> extends ContractProcedure<TInputSchema, TOutputSchema, TErrorMap, TMeta> {
|
|
245
262
|
/**
|
|
@@ -504,6 +521,13 @@ interface EventIteratorSchemaDetails {
|
|
|
504
521
|
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>>;
|
|
505
522
|
declare function getEventIteratorSchemaDetails(schema: AnySchema | undefined): undefined | EventIteratorSchemaDetails;
|
|
506
523
|
|
|
524
|
+
/**
|
|
525
|
+
* Help RPCLink automatically send requests using the specified HTTP method in the contract.
|
|
526
|
+
*
|
|
527
|
+
* @see {@link https://orpc.unnoq.com/docs/client/rpc-link#custom-request-method RPCLink Custom Request Method}
|
|
528
|
+
*/
|
|
529
|
+
declare function inferRPCMethodFromContractRouter(contract: AnyContractRouter): (options: unknown, path: readonly string[]) => Exclude<HTTPMethod, 'HEAD'>;
|
|
530
|
+
|
|
507
531
|
type ContractProcedureClient<TClientContext extends ClientContext, TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap> = Client<TClientContext, InferSchemaInput<TInputSchema>, InferSchemaOutput<TOutputSchema>, ErrorFromErrorMap<TErrorMap>>;
|
|
508
532
|
|
|
509
533
|
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> : {
|
|
@@ -512,5 +536,5 @@ type ContractRouterClient<TRouter extends AnyContractRouter, TClientContext exte
|
|
|
512
536
|
|
|
513
537
|
declare function isSchemaIssue(issue: unknown): issue is SchemaIssue;
|
|
514
538
|
|
|
515
|
-
export { ContractBuilder, ContractProcedure, ValidationError, enhanceContractRouter, enhanceRoute, eventIterator, fallbackContractConfig, getContractRouter, getEventIteratorSchemaDetails, isContractProcedure, isSchemaIssue, mergeErrorMap, mergeMeta, mergePrefix, mergeRoute, mergeTags, oc, prefixRoute, type, unshiftTagRoute };
|
|
539
|
+
export { ContractBuilder, ContractProcedure, ValidationError, enhanceContractRouter, enhanceRoute, eventIterator, fallbackContractConfig, getContractRouter, getEventIteratorSchemaDetails, inferRPCMethodFromContractRouter, isContractProcedure, isSchemaIssue, mergeErrorMap, mergeMeta, mergePrefix, mergeRoute, mergeTags, minifyContractRouter, oc, prefixRoute, type, unshiftTagRoute };
|
|
516
540
|
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, isTypescriptObject, isPropertyKey } 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": {
|
|
@@ -322,4 +352,4 @@ function isSchemaIssue(issue) {
|
|
|
322
352
|
return true;
|
|
323
353
|
}
|
|
324
354
|
|
|
325
|
-
export { ContractBuilder, ContractProcedure, ValidationError, enhanceContractRouter, enhanceRoute, eventIterator, fallbackContractConfig, getContractRouter, getEventIteratorSchemaDetails, isContractProcedure, isSchemaIssue, mergeErrorMap, mergeMeta, mergePrefix, mergeRoute, mergeTags, oc, prefixRoute, type, unshiftTagRoute };
|
|
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": "1.
|
|
4
|
+
"version": "1.4.0",
|
|
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": "1.4.0",
|
|
30
|
+
"@orpc/shared": "1.4.0"
|
|
30
31
|
},
|
|
31
32
|
"devDependencies": {
|
|
32
33
|
"arktype": "2.1.20",
|
|
33
34
|
"valibot": "^1.1.0",
|
|
34
|
-
"zod": "^3.25.
|
|
35
|
+
"zod": "^3.25.49"
|
|
35
36
|
},
|
|
36
37
|
"scripts": {
|
|
37
38
|
"build": "unbuild",
|