@orpc/contract 2.0.0-beta.50 → 2.0.0-beta.52
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 +11 -10
- package/dist/builder.d.ts +2 -2
- package/dist/error-factory.d.ts +1 -1
- package/dist/error-factory.js +1 -0
- package/dist/error.d.ts +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/plugins/response-validation.js +2 -5
- package/dist/procedure.js +3 -3
- package/dist/router-utils.d.ts +2 -1
- package/dist/router.d.ts +10 -5
- package/dist/schema-built-in.js +3 -4
- package/dist/schema.d.ts +2 -2
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -78,13 +78,14 @@ Read the full documentation at [orpc.dev](https://orpc.dev), starting with the [
|
|
|
78
78
|
|
|
79
79
|
**Built-in features**
|
|
80
80
|
|
|
81
|
-
| Package
|
|
82
|
-
|
|
|
83
|
-
| [@orpc/publisher](https://www.npmjs.com/package/@orpc/publisher)
|
|
84
|
-
| [@orpc/ratelimit](https://www.npmjs.com/package/@orpc/ratelimit)
|
|
85
|
-
| [@orpc/experimental-lock](https://www.npmjs.com/package/@orpc/experimental-lock)
|
|
86
|
-
| [@orpc/
|
|
87
|
-
| [@orpc/
|
|
81
|
+
| Package | Purpose | Docs |
|
|
82
|
+
| ---------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------- |
|
|
83
|
+
| [@orpc/publisher](https://www.npmjs.com/package/@orpc/publisher) | Pub/Sub with memory, Redis, and Upstash adapters. | [Publisher](https://orpc.dev/docs/helpers/publisher) |
|
|
84
|
+
| [@orpc/ratelimit](https://www.npmjs.com/package/@orpc/ratelimit) | Rate limiting with memory, Redis, and Upstash adapters. | [Rate Limit](https://orpc.dev/docs/helpers/ratelimit) |
|
|
85
|
+
| [@orpc/experimental-lock](https://www.npmjs.com/package/@orpc/experimental-lock) | Locking with memory, Redis, and Upstash adapters. | [Lock](https://orpc.dev/docs/helpers/lock) |
|
|
86
|
+
| [@orpc/experimental-openapi-inference](https://www.npmjs.com/package/@orpc/experimental-openapi-inference) | Generate OpenAPI specs from TypeScript types, no output schemas required. | [Type Inference](https://orpc.dev/docs/openapi/specification#type-inference) |
|
|
87
|
+
| [@orpc/hibernation](https://www.npmjs.com/package/@orpc/hibernation) | Leverage Hibernation APIs like [Cloudflare's Hibernation WebSocket](https://developers.cloudflare.com/durable-objects/best-practices/websockets/#durable-objects-hibernation-websocket-api). | [Hibernation](https://orpc.dev/docs/integrations/hibernation) |
|
|
88
|
+
| [@orpc/json-schema](https://www.npmjs.com/package/@orpc/json-schema) | Smart coercion for OpenAPI requests. | [Smart Coercion](https://orpc.dev/docs/plugins/smart-coercion) |
|
|
88
89
|
|
|
89
90
|
**Framework & ecosystem integrations**
|
|
90
91
|
|
|
@@ -182,16 +183,16 @@ Like what we build over at [middleapi](https://github.com/middleapi)? You can he
|
|
|
182
183
|
<td align="center"><a href="https://github.com/pumpkinlink?ref=middleapi&utm_source=middleapi&utm_medium=sponsor" target="_blank" rel="noopener sponsored" title="Denis"><img src="https://avatars.githubusercontent.com/u/11864620?u=5f47bbe6c65d0f6f5cf011021490238e4b0593d0&v=4" width="139" alt="Denis"/><br />Denis</a></td>
|
|
183
184
|
<td align="center"><a href="https://github.com/christopher-kapic?ref=middleapi&utm_source=middleapi&utm_medium=sponsor" target="_blank" rel="noopener sponsored" title="Christopher Kapic"><img src="https://avatars.githubusercontent.com/u/59740769?u=e7ad4b72b5bf6c9eb1644c26dbf3332a8f987377&v=4" width="139" alt="Christopher Kapic"/><br />Christopher Kapic</a></td>
|
|
184
185
|
<td align="center"><a href="http://ballingt.com/?ref=middleapi&utm_source=middleapi&utm_medium=sponsor" target="_blank" rel="noopener sponsored" title="Tom Ballinger"><img src="https://avatars.githubusercontent.com/u/458879?u=4b045ac75d721b6ac2b42a74d7d37f61f0414031&v=4" width="139" alt="Tom Ballinger"/><br />Tom Ballinger</a></td>
|
|
185
|
-
<td align="center"><a href="https://lee-sam.com/?ref=middleapi&utm_source=middleapi&utm_medium=sponsor" target="_blank" rel="noopener sponsored" title="Sam"><img src="https://avatars.githubusercontent.com/u/102863520?u=3c89611f549d5070be232eb4532f690c8f2e7a65&v=4" width="139" alt="Sam"/><br />Sam</a></td>
|
|
186
186
|
<td align="center"><a href="https://github.com/Titoine?ref=middleapi&utm_source=middleapi&utm_medium=sponsor" target="_blank" rel="noopener sponsored" title="Titoine"><img src="https://avatars.githubusercontent.com/u/3514286?u=1bb1e86b0c99c8a1121372e56d51a177eea12191&v=4" width="139" alt="Titoine"/><br />Titoine</a></td>
|
|
187
187
|
<td align="center"><a href="https://rigtch.fm/?ref=middleapi&utm_source=middleapi&utm_medium=sponsor" target="_blank" rel="noopener sponsored" title="Igor Makowski"><img src="https://avatars.githubusercontent.com/u/56691628?u=ee8c879478f7c151b9156aef6c74243fa3e247a8&v=4" width="139" alt="Igor Makowski"/><br />Igor Makowski</a></td>
|
|
188
|
+
<td align="center"><a href="https://blog.cwang.io/?ref=middleapi&utm_source=middleapi&utm_medium=sponsor" target="_blank" rel="noopener sponsored" title="hanayashiki"><img src="https://avatars.githubusercontent.com/u/26056783?u=06c3b9205a16fd41a871e82da1cc2a09306d53f5&v=4" width="139" alt="hanayashiki"/><br />hanayashiki</a></td>
|
|
188
189
|
</tr>
|
|
189
190
|
<tr>
|
|
190
|
-
<td align="center"><a href="https://blog.cwang.io/?ref=middleapi&utm_source=middleapi&utm_medium=sponsor" target="_blank" rel="noopener sponsored" title="hanayashiki"><img src="https://avatars.githubusercontent.com/u/26056783?u=06c3b9205a16fd41a871e82da1cc2a09306d53f5&v=4" width="139" alt="hanayashiki"/><br />hanayashiki</a></td>
|
|
191
191
|
<td align="center"><a href="https://dubinets.io/?ref=middleapi&utm_source=middleapi&utm_medium=sponsor" target="_blank" rel="noopener sponsored" title="Lev Dubinets"><img src="https://avatars.githubusercontent.com/u/3114081?u=f547f5d5012cab54851f1b1ad72d10e537f78fc2&v=4" width="139" alt="Lev Dubinets"/><br />Lev Dubinets</a></td>
|
|
192
192
|
<td align="center"><a href="https://kellychan.im/?ref=middleapi&utm_source=middleapi&utm_medium=sponsor" target="_blank" rel="noopener sponsored" title="Kelly Peilin Chan"><img src="https://avatars.githubusercontent.com/u/520852?u=6b0f7105f694e7b5cacf410a3f04c7044b469dc8&v=4" width="139" alt="Kelly Peilin Chan"/><br />Kelly Peilin Chan</a></td>
|
|
193
193
|
<td align="center"><a href="https://guyariely.com/?ref=middleapi&utm_source=middleapi&utm_medium=sponsor" target="_blank" rel="noopener sponsored" title="Guy Ariely"><img src="https://avatars.githubusercontent.com/u/42813496?u=edb6b7f563bf28e160a290832e7da57c0506f8ca&v=4" width="139" alt="Guy Ariely"/><br />Guy Ariely</a></td>
|
|
194
194
|
<td align="center"><a href="https://paulsenon.com/?ref=middleapi&utm_source=middleapi&utm_medium=sponsor" target="_blank" rel="noopener sponsored" title="PaulSenon"><img src="https://avatars.githubusercontent.com/u/19531087?u=6385741eb91d200b8c513ec6045482e301767ca6&v=4" width="139" alt="PaulSenon"/><br />PaulSenon</a></td>
|
|
195
|
+
<td align="center"><a href="https://usagerail.com/?ref=middleapi&utm_source=middleapi&utm_medium=sponsor" target="_blank" rel="noopener sponsored" title="UsageRail"><img src="https://avatars.githubusercontent.com/u/347653714?v=4" width="139" alt="UsageRail"/><br />UsageRail</a></td>
|
|
195
196
|
<td align="center"><a href="https://piscis.dev/?ref=middleapi&utm_source=middleapi&utm_medium=sponsor" target="_blank" rel="noopener sponsored" title="Alex"><img src="https://avatars.githubusercontent.com/u/326163?u=b245f368bd940cf51d08c0b6bf55f8257f359437&v=4" width="139" alt="Alex"/><br />Alex</a></td>
|
|
196
197
|
</tr>
|
|
197
198
|
<tr>
|
|
@@ -199,7 +200,7 @@ Like what we build over at [middleapi](https://github.com/middleapi)? You can he
|
|
|
199
200
|
</tr>
|
|
200
201
|
</table>
|
|
201
202
|
|
|
202
|
-
With thanks to [
|
|
203
|
+
With thanks to [41 past sponsors](https://orpc.dev/sponsors#past-sponsors) who helped get oRPC here.
|
|
203
204
|
|
|
204
205
|
## Open Source Programs
|
|
205
206
|
|
package/dist/builder.d.ts
CHANGED
|
@@ -35,7 +35,7 @@ export declare class ContractBuilder<TErrorMap extends ErrorMap> extends Procedu
|
|
|
35
35
|
*
|
|
36
36
|
* @see {@link https://orpc.dev/docs/contract/procedure | Procedure Contract}
|
|
37
37
|
*/
|
|
38
|
-
static create(): ContractBuilder<
|
|
38
|
+
static create(): ContractBuilder<{}>;
|
|
39
39
|
/**
|
|
40
40
|
* Applies metadata plugins to contracts built from this builder.
|
|
41
41
|
*
|
|
@@ -75,4 +75,4 @@ export declare class ContractBuilder<TErrorMap extends ErrorMap> extends Procedu
|
|
|
75
75
|
*
|
|
76
76
|
* @see {@link https://orpc.dev/docs/contract/procedure | Procedure Contract}
|
|
77
77
|
*/
|
|
78
|
-
export declare const oc: ContractBuilder<
|
|
78
|
+
export declare const oc: ContractBuilder<{}>;
|
package/dist/error-factory.d.ts
CHANGED
|
@@ -51,7 +51,7 @@ export type ORPCErrorConstructorMapItemOptions<TData> = Omit<ORPCErrorOptions<TD
|
|
|
51
51
|
export interface ORPCErrorConstructorMapItem<TCode extends ORPCErrorCode, TInData> {
|
|
52
52
|
(...rest: MaybeOptionalOptions<ORPCErrorConstructorMapItemOptions<TInData>>): ORPCError<TCode, TInData>;
|
|
53
53
|
}
|
|
54
|
-
export type ORPCErrorConstructorMap<T extends ErrorMap> = { [K in keyof T]
|
|
54
|
+
export type ORPCErrorConstructorMap<out T extends ErrorMap> = { [K in keyof T]-?: Exclude<T[K], undefined> extends (infer I extends ErrorMapItem) ? ORPCErrorConstructorMapItem<K & ORPCErrorCode, I["data"] extends AnySchema ? InferSchemaInput<I["data"]> : unknown> : never; };
|
|
55
55
|
/**
|
|
56
56
|
* Creates a map of ORPC error constructors.
|
|
57
57
|
*
|
package/dist/error-factory.js
CHANGED
|
@@ -60,6 +60,7 @@ function error(code, { data: dataSchema, message } = {}) {
|
|
|
60
60
|
});
|
|
61
61
|
}
|
|
62
62
|
static [Symbol.hasInstance](instance) {
|
|
63
|
+
if (Function.prototype[Symbol.hasInstance].call(this, instance)) return true;
|
|
63
64
|
if (!(instance instanceof ORPCError)) return false;
|
|
64
65
|
if (instance.code !== code) return false;
|
|
65
66
|
if (dataSchema && validateData(dataSchema, instance.data).issues) return false;
|
package/dist/error.d.ts
CHANGED
|
@@ -17,7 +17,7 @@ export interface ErrorMapItem {
|
|
|
17
17
|
* @see {@link https://orpc.dev/docs/metadata | Metadata}
|
|
18
18
|
*/
|
|
19
19
|
export type ErrorMap = { [key in ORPCErrorCode]?: ErrorMapItem; };
|
|
20
|
-
export type ORPCErrorFromErrorMap<TErrorMap extends ErrorMap> = { [K in keyof TErrorMap]
|
|
20
|
+
export type ORPCErrorFromErrorMap<TErrorMap extends ErrorMap> = { [K in keyof TErrorMap]-?: Exclude<TErrorMap[K], undefined> extends (infer I extends ErrorMapItem) ? ORPCError<K & ORPCErrorCode, I["data"] extends AnySchema ? InferSchemaOutput<I["data"]> : unknown> : never; }[keyof TErrorMap];
|
|
21
21
|
export interface ValidationErrorOptions extends ErrorOptions {
|
|
22
22
|
message: string;
|
|
23
23
|
issues: readonly SchemaIssue[];
|
package/dist/index.d.ts
CHANGED
|
@@ -9,12 +9,12 @@ import { PathMetaPlugin, getPathMeta, meta, resolveBasePathMeta } from "./meta-b
|
|
|
9
9
|
import { defineMeta, resolveMetaPlugins } from "./meta-utils.js";
|
|
10
10
|
import { AnyProcedureContract, ProcedureContract, ProcedureContractDefinition } from "./procedure.js";
|
|
11
11
|
import { ProcedureContractClient } from "./procedure-client.js";
|
|
12
|
-
import { InferRouterContractError, InferRouterContractErrorMap, InferRouterContractErrors, InferRouterContractInputs, InferRouterContractOutputs, RouterContract } from "./router.js";
|
|
12
|
+
import { InferRouterContractError, InferRouterContractErrorInternal, InferRouterContractErrorMap, InferRouterContractErrorMapInternal, InferRouterContractErrors, InferRouterContractErrorsInternal, InferRouterContractInputs, InferRouterContractInputsInternal, InferRouterContractOutputs, InferRouterContractOutputsInternal, RouterContract } from "./router.js";
|
|
13
13
|
import { RouterContractClient } from "./router-client.js";
|
|
14
|
-
import { AugmentContractRouterOptions, AugmentedContractRouter, getProcedureContractOrThrow, getRouterContract, minifyRouterContract } from "./router-utils.js";
|
|
14
|
+
import { AugmentContractRouterOptions, AugmentedContractRouter, AugmentedContractRouterInternal, getProcedureContractOrThrow, getRouterContract, minifyRouterContract } from "./router-utils.js";
|
|
15
15
|
import { AnySchema, InferSchemaInput, InferSchemaOutput, MergedSchema, Schema, SchemaIssue } from "./schema.js";
|
|
16
16
|
import { AsyncIteratorObjectSchemasDetails, asyncIteratorObject, getAsyncIteratorObjectSchemasDetails } from "./schema-built-in.js";
|
|
17
17
|
import { TypeRest, isSchemaIssue, type } from "./schema-utils.js";
|
|
18
18
|
import { AsyncIteratorClass, PromiseWithError, Registry, ThrowableError } from "@orpc/shared";
|
|
19
19
|
import { Client, ClientContext, ClientOptions, ClientRest, FriendlyClientOptions } from "@orpc/client";
|
|
20
|
-
export { type AnyProcedureContract as AnyContractProcedure, type RouterContract as AnyContractRouter, AnyMetaPlugin, AnyProcedureContract, AnySchema, type AsyncIteratorClass, type AsyncIteratorObjectSchemasDetails, type AugmentContractRouterOptions, type AugmentedContractRouter, type Client, type ClientContext, type ClientOptions, type ClientRest, ContractBuilder, ContractClientFactory, ContractClientFactoryOptions, type RouterContractClient as ContractRouterClient, ErrorMap, ErrorMapItem, type FriendlyClientOptions, type InferRouterContractErrorMap as InferContractRouterErrorMap, type InferRouterContractInputs as InferContractRouterInputs, type InferRouterContractOutputs as InferContractRouterOutputs, InferRouterContractError, InferRouterContractErrorMap, InferRouterContractErrors, InferRouterContractInputs, InferRouterContractOutputs, InferSchemaInput, InferSchemaOutput, InitialInputSchema, InitialOutputSchema, MergedErrorMap, MergedSchema, Meta, MetaPlugin, MetaPluginDefinition, ORPCErrorConstructorMap, ORPCErrorConstructorMapItem, ORPCErrorConstructorMapItemOptions, ORPCErrorFactory, ORPCErrorFactoryOptions, ORPCErrorFromErrorMap, PathMetaPlugin, ProcedureContract, ProcedureContractBuilderWithInput, ProcedureContractBuilderWithInputOutput, ProcedureContractBuilderWithOutput, ProcedureContractClient, ProcedureContractDefinition, type PromiseWithError, type Registry, RouterContract, RouterContractClient, Schema, SchemaIssue, type ThrowableError, TypeRest, ValidationError, ValidationErrorOptions, asyncIteratorObject, createContractClientFactory, createORPCErrorConstructorMap, defineMeta, error, asyncIteratorObject as eventIterator, getAsyncIteratorObjectSchemasDetails, getRouterContract as getContractRouter, getHiddenMetaPlugins, getPathMeta, getProcedureContractOrThrow, getRouterContract, isSchemaIssue, mergeErrorMap, meta, minifyRouterContract as minifyContractRouter, minifyRouterContract, oc, reconcileORPCError, resolveBasePathMeta, resolveMetaPlugins, setHiddenMetaPlugins, type };
|
|
20
|
+
export { type AnyProcedureContract as AnyContractProcedure, type RouterContract as AnyContractRouter, AnyMetaPlugin, AnyProcedureContract, AnySchema, type AsyncIteratorClass, type AsyncIteratorObjectSchemasDetails, type AugmentContractRouterOptions, type AugmentedContractRouter, type AugmentedContractRouterInternal, type Client, type ClientContext, type ClientOptions, type ClientRest, ContractBuilder, ContractClientFactory, ContractClientFactoryOptions, type RouterContractClient as ContractRouterClient, ErrorMap, ErrorMapItem, type FriendlyClientOptions, type InferRouterContractErrorMap as InferContractRouterErrorMap, type InferRouterContractInputs as InferContractRouterInputs, type InferRouterContractOutputs as InferContractRouterOutputs, InferRouterContractError, InferRouterContractErrorInternal, InferRouterContractErrorMap, InferRouterContractErrorMapInternal, InferRouterContractErrors, InferRouterContractErrorsInternal, InferRouterContractInputs, InferRouterContractInputsInternal, InferRouterContractOutputs, InferRouterContractOutputsInternal, InferSchemaInput, InferSchemaOutput, InitialInputSchema, InitialOutputSchema, MergedErrorMap, MergedSchema, Meta, MetaPlugin, MetaPluginDefinition, ORPCErrorConstructorMap, ORPCErrorConstructorMapItem, ORPCErrorConstructorMapItemOptions, ORPCErrorFactory, ORPCErrorFactoryOptions, ORPCErrorFromErrorMap, PathMetaPlugin, ProcedureContract, ProcedureContractBuilderWithInput, ProcedureContractBuilderWithInputOutput, ProcedureContractBuilderWithOutput, ProcedureContractClient, ProcedureContractDefinition, type PromiseWithError, type Registry, RouterContract, RouterContractClient, Schema, SchemaIssue, type ThrowableError, TypeRest, ValidationError, ValidationErrorOptions, asyncIteratorObject, createContractClientFactory, createORPCErrorConstructorMap, defineMeta, error, asyncIteratorObject as eventIterator, getAsyncIteratorObjectSchemasDetails, getRouterContract as getContractRouter, getHiddenMetaPlugins, getPathMeta, getProcedureContractOrThrow, getRouterContract, isSchemaIssue, mergeErrorMap, meta, minifyRouterContract as minifyContractRouter, minifyRouterContract, oc, reconcileORPCError, resolveBasePathMeta, resolveMetaPlugins, setHiddenMetaPlugins, type };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ValidationError } from "../error.js";
|
|
2
2
|
import { reconcileORPCError } from "../error-utils.js";
|
|
3
3
|
import { getProcedureContractOrThrow } from "../router-utils.js";
|
|
4
|
-
import { isAsyncIteratorObject,
|
|
4
|
+
import { isAsyncIteratorObject, toArray } from "@orpc/shared";
|
|
5
5
|
import { ORPCError, wrapAsyncIteratorPreservingEventMeta } from "@orpc/client";
|
|
6
6
|
// src/plugins/response-validation.ts
|
|
7
7
|
/**
|
|
@@ -31,11 +31,8 @@ var ResponseValidationLinkPlugin = class {
|
|
|
31
31
|
if (isAsyncIteratorObject(output))
|
|
32
32
|
/**
|
|
33
33
|
* Errors thrown while consuming the iterator must be reconciled too.
|
|
34
|
-
*
|
|
35
|
-
* @warning
|
|
36
|
-
* Remember use `override` for AsyncIteratorObject to remain other special properties
|
|
37
34
|
*/
|
|
38
|
-
return
|
|
35
|
+
return wrapAsyncIteratorPreservingEventMeta(output, { mapError: reconcileError });
|
|
39
36
|
return output;
|
|
40
37
|
} catch (error) {
|
|
41
38
|
throw await reconcileError(error);
|
package/dist/procedure.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { isNonPrimitive } from "@orpc/shared";
|
|
2
2
|
// src/procedure.ts
|
|
3
3
|
var ProcedureContract = class ProcedureContract {
|
|
4
4
|
"~orpc";
|
|
@@ -9,8 +9,8 @@ var ProcedureContract = class ProcedureContract {
|
|
|
9
9
|
* Checks if the given instance satisfies the {@link ProcedureContract} class/interface.
|
|
10
10
|
*/
|
|
11
11
|
static [Symbol.hasInstance](instance) {
|
|
12
|
-
if (
|
|
13
|
-
if (
|
|
12
|
+
if (Function.prototype[Symbol.hasInstance].call(this, instance)) return true;
|
|
13
|
+
if (this !== ProcedureContract) return false;
|
|
14
14
|
return isNonPrimitive(instance) && isNonPrimitive(instance["~orpc"]) && isNonPrimitive(instance["~orpc"].errorMap) && isNonPrimitive(instance["~orpc"].meta) && (instance["~orpc"].inputSchemas === void 0 || Array.isArray(instance["~orpc"].inputSchemas)) && (instance["~orpc"].outputSchemas === void 0 || Array.isArray(instance["~orpc"].outputSchemas));
|
|
15
15
|
}
|
|
16
16
|
};
|
package/dist/router-utils.d.ts
CHANGED
|
@@ -3,7 +3,8 @@ import { MergedErrorMap } from "./error-utils.js";
|
|
|
3
3
|
import { AnyMetaPlugin, Meta } from "./meta.js";
|
|
4
4
|
import { AnyProcedureContract, ProcedureContract } from "./procedure.js";
|
|
5
5
|
import { RouterContract } from "./router.js";
|
|
6
|
-
export type AugmentedContractRouter<T extends RouterContract, TErrorMap extends ErrorMap> =
|
|
6
|
+
export type AugmentedContractRouter<T extends RouterContract, TErrorMap extends ErrorMap> = AugmentedContractRouterInternal<T, TErrorMap>;
|
|
7
|
+
export type AugmentedContractRouterInternal<T, TErrorMap extends ErrorMap> = T extends ProcedureContract<infer $InputSchema, infer $OutputSchema, infer $Errors> ? ProcedureContract<$InputSchema, $OutputSchema, MergedErrorMap<TErrorMap, $Errors>> : { [K in keyof T]: AugmentedContractRouterInternal<T[K] & {}, TErrorMap>; };
|
|
7
8
|
export interface AugmentContractRouterOptions<TErrorMap extends ErrorMap> {
|
|
8
9
|
meta: Meta;
|
|
9
10
|
metaPlugins?: AnyMetaPlugin[] | undefined;
|
package/dist/router.d.ts
CHANGED
|
@@ -15,28 +15,33 @@ export type RouterContract = AnyProcedureContract | {
|
|
|
15
15
|
*
|
|
16
16
|
* @see {@link https://orpc.dev/docs/contract/router#infer-router-contract-inputs | Router Contract - Infer Router Contract Inputs}
|
|
17
17
|
*/
|
|
18
|
-
export type InferRouterContractInputs<T extends RouterContract> =
|
|
18
|
+
export type InferRouterContractInputs<T extends RouterContract> = InferRouterContractInputsInternal<T>;
|
|
19
|
+
export type InferRouterContractInputsInternal<T> = T extends ProcedureContract<infer UInputSchema, any, any> ? InferSchemaInput<UInputSchema> : { [K in keyof T]: InferRouterContractInputsInternal<T[K] & {}>; };
|
|
19
20
|
/**
|
|
20
21
|
* Infer the output types for each procedure-contract, preserving the router-contract shape.
|
|
21
22
|
*
|
|
22
23
|
* @see {@link https://orpc.dev/docs/contract/router#infer-router-contract-outputs | Router Contract - Infer Router Contract Outputs}
|
|
23
24
|
*/
|
|
24
|
-
export type InferRouterContractOutputs<T extends RouterContract> =
|
|
25
|
+
export type InferRouterContractOutputs<T extends RouterContract> = InferRouterContractOutputsInternal<T>;
|
|
26
|
+
export type InferRouterContractOutputsInternal<T> = T extends ProcedureContract<any, infer UOutputSchema, any> ? InferSchemaOutput<UOutputSchema> : { [K in keyof T]: InferRouterContractOutputsInternal<T[K] & {}>; };
|
|
25
27
|
/**
|
|
26
28
|
* Infer the union of error maps defined across the entire router-contract.
|
|
27
29
|
*
|
|
28
30
|
* @see {@link https://orpc.dev/docs/contract/router#infer-router-contract-error-map | Router Contract - Infer Router Contract Error Map}
|
|
29
31
|
*/
|
|
30
|
-
export type InferRouterContractErrorMap<T extends RouterContract> =
|
|
32
|
+
export type InferRouterContractErrorMap<T extends RouterContract> = InferRouterContractErrorMapInternal<T>;
|
|
33
|
+
export type InferRouterContractErrorMapInternal<T> = T extends ProcedureContract<any, any, infer UErrorMap> ? UErrorMap : { [K in keyof T]-?: InferRouterContractErrorMapInternal<T[K] & {}>; }[keyof T];
|
|
31
34
|
/**
|
|
32
35
|
* Infer the union of throwable errors for entire router-contract.
|
|
33
36
|
*
|
|
34
37
|
* @see {@link https://orpc.dev/docs/contract/router#infer-router-contract-error | Router Contract - Infer Router Contract Error}
|
|
35
38
|
*/
|
|
36
|
-
export type InferRouterContractError<T extends RouterContract> =
|
|
39
|
+
export type InferRouterContractError<T extends RouterContract> = InferRouterContractErrorInternal<T>;
|
|
40
|
+
export type InferRouterContractErrorInternal<T> = T extends ProcedureContract<any, any, infer UErrorMap> ? ORPCErrorFromErrorMap<UErrorMap> | ThrowableError : { [K in keyof T]-?: InferRouterContractErrorInternal<T[K] & {}>; }[keyof T];
|
|
37
41
|
/**
|
|
38
42
|
* Infer throwable errors for each procedure-contract, preserving the router-contract shape.
|
|
39
43
|
*
|
|
40
44
|
* @see {@link https://orpc.dev/docs/contract/router#infer-router-contract-errors | Router Contract - Infer Router Contract Errors}
|
|
41
45
|
*/
|
|
42
|
-
export type InferRouterContractErrors<T extends RouterContract> =
|
|
46
|
+
export type InferRouterContractErrors<T extends RouterContract> = InferRouterContractErrorsInternal<T>;
|
|
47
|
+
export type InferRouterContractErrorsInternal<T> = T extends ProcedureContract<any, any, infer UErrorMap> ? ORPCErrorFromErrorMap<UErrorMap> | ThrowableError : { [K in keyof T]: InferRouterContractErrorsInternal<T[K] & {}>; };
|
package/dist/schema-built-in.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ValidationError } from "./error.js";
|
|
2
|
-
import { ORPC_NAME, isAsyncIteratorObject
|
|
2
|
+
import { ORPC_NAME, isAsyncIteratorObject } from "@orpc/shared";
|
|
3
3
|
import { ORPCError, wrapAsyncIteratorPreservingEventMeta } from "@orpc/client";
|
|
4
4
|
// src/schema-built-in.ts
|
|
5
5
|
const ASYNC_ITERATOR_OBJECT_SCHEMA_DETAILS_SYMBOL = /* @__PURE__ */ Symbol.for("ORPC_ASYNC_ITERATOR_OBJECT_SCHEMA_DETAILS");
|
|
@@ -22,7 +22,7 @@ function asyncIteratorObject(yieldSchema, returnSchema) {
|
|
|
22
22
|
message: "Expect AsyncIteratorObject",
|
|
23
23
|
path: []
|
|
24
24
|
}] };
|
|
25
|
-
|
|
25
|
+
return { value: wrapAsyncIteratorPreservingEventMeta(iterator, { async mapResult(result) {
|
|
26
26
|
const schema = result.done ? returnSchema : yieldSchema;
|
|
27
27
|
if (!schema) return result;
|
|
28
28
|
const validated = await schema["~standard"].validate(result.value);
|
|
@@ -38,8 +38,7 @@ function asyncIteratorObject(yieldSchema, returnSchema) {
|
|
|
38
38
|
done: result.done,
|
|
39
39
|
value: validated.value
|
|
40
40
|
};
|
|
41
|
-
} });
|
|
42
|
-
return { value: override(iterator, mapped) };
|
|
41
|
+
} }) };
|
|
43
42
|
}
|
|
44
43
|
} };
|
|
45
44
|
}
|
package/dist/schema.d.ts
CHANGED
|
@@ -15,11 +15,11 @@ export type SchemaIssue = StandardSchemaV1.Issue;
|
|
|
15
15
|
*
|
|
16
16
|
* @see {@link https://orpc.dev/docs/metadata | Metadata}
|
|
17
17
|
*/
|
|
18
|
-
export type InferSchemaInput<T extends AnySchema> = T extends
|
|
18
|
+
export type InferSchemaInput<T extends AnySchema> = T extends unknown ? 0 extends 1 & T ? unknown : NonNullable<T["~standard"]["types"]>["input"] : never;
|
|
19
19
|
/**
|
|
20
20
|
* Infers the output type of a schema.
|
|
21
21
|
*
|
|
22
22
|
* @see {@link https://orpc.dev/docs/metadata | Metadata}
|
|
23
23
|
*/
|
|
24
|
-
export type InferSchemaOutput<T extends AnySchema> = T extends
|
|
24
|
+
export type InferSchemaOutput<T extends AnySchema> = T extends unknown ? 0 extends 1 & T ? unknown : NonNullable<T["~standard"]["types"]>["output"] : never;
|
|
25
25
|
export type MergedSchema<T extends AnySchema, U extends AnySchema> = T extends Schema<infer TInput, infer TOutput> ? U extends Schema<infer UInput, infer UOutput> ? Schema<TInput & UInput, TOutput & UOutput> : never : never;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@orpc/contract",
|
|
3
|
-
"version": "2.0.0-beta.
|
|
3
|
+
"version": "2.0.0-beta.52",
|
|
4
4
|
"description": "Define typesafe API contracts as the single source of truth for oRPC, powered by Standard Schema",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"api",
|
|
@@ -43,8 +43,8 @@
|
|
|
43
43
|
}
|
|
44
44
|
},
|
|
45
45
|
"dependencies": {
|
|
46
|
-
"@orpc/client": "2.0.0-beta.
|
|
47
|
-
"@orpc/shared": "2.0.0-beta.
|
|
46
|
+
"@orpc/client": "2.0.0-beta.52",
|
|
47
|
+
"@orpc/shared": "2.0.0-beta.52",
|
|
48
48
|
"@standard-schema/spec": "^1.1.0"
|
|
49
49
|
},
|
|
50
50
|
"devDependencies": {
|