@orpc/contract 0.0.0-next.3afb521 → 0.0.0-next.3b1dac3
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 +39 -36
- package/dist/index.d.ts +39 -36
- package/dist/index.mjs +4 -6
- package/package.json +4 -4
package/dist/index.d.mts
CHANGED
|
@@ -1,35 +1,37 @@
|
|
|
1
1
|
import { ORPCErrorCode, ORPCError, ClientContext, Client } from '@orpc/client';
|
|
2
2
|
export { ORPCError } from '@orpc/client';
|
|
3
|
-
import { StandardSchemaV1 } from '@standard-schema/spec';
|
|
4
3
|
import { Promisable, IsEqual } from '@orpc/shared';
|
|
4
|
+
import { StandardSchemaV1 } from '@standard-schema/spec';
|
|
5
5
|
|
|
6
|
-
type Schema = StandardSchemaV1
|
|
7
|
-
type
|
|
8
|
-
type
|
|
6
|
+
type Schema<TInput, TOutput> = StandardSchemaV1<TInput, TOutput>;
|
|
7
|
+
type AnySchema = Schema<any, any>;
|
|
8
|
+
type SchemaIssue = StandardSchemaV1.Issue;
|
|
9
|
+
type InferSchemaInput<T extends AnySchema> = T extends StandardSchemaV1<infer UInput, any> ? UInput : never;
|
|
10
|
+
type InferSchemaOutput<T extends AnySchema> = T extends StandardSchemaV1<any, infer UOutput> ? UOutput : never;
|
|
9
11
|
type TypeRest<TInput, TOutput> = [map: (input: TInput) => Promisable<TOutput>] | (IsEqual<TInput, TOutput> extends true ? [] : never);
|
|
10
|
-
declare function type<TInput, TOutput = TInput>(...[map]: TypeRest<TInput, TOutput>):
|
|
12
|
+
declare function type<TInput, TOutput = TInput>(...[map]: TypeRest<TInput, TOutput>): Schema<TInput, TOutput>;
|
|
11
13
|
|
|
12
14
|
interface ValidationErrorOptions extends ErrorOptions {
|
|
13
15
|
message: string;
|
|
14
|
-
issues: readonly
|
|
16
|
+
issues: readonly SchemaIssue[];
|
|
15
17
|
}
|
|
16
18
|
declare class ValidationError extends Error {
|
|
17
|
-
readonly issues: readonly
|
|
19
|
+
readonly issues: readonly SchemaIssue[];
|
|
18
20
|
constructor(options: ValidationErrorOptions);
|
|
19
21
|
}
|
|
20
|
-
interface ErrorMapItem<TDataSchema extends
|
|
22
|
+
interface ErrorMapItem<TDataSchema extends AnySchema> {
|
|
21
23
|
status?: number;
|
|
22
24
|
message?: string;
|
|
23
25
|
description?: string;
|
|
24
26
|
data?: TDataSchema;
|
|
25
27
|
}
|
|
26
28
|
type ErrorMap = {
|
|
27
|
-
[key in ORPCErrorCode]?: ErrorMapItem<
|
|
29
|
+
[key in ORPCErrorCode]?: ErrorMapItem<AnySchema>;
|
|
28
30
|
};
|
|
29
31
|
type MergedErrorMap<T1 extends ErrorMap, T2 extends ErrorMap> = Omit<T1, keyof T2> & T2;
|
|
30
32
|
declare function mergeErrorMap<T1 extends ErrorMap, T2 extends ErrorMap>(errorMap1: T1, errorMap2: T2): MergedErrorMap<T1, T2>;
|
|
31
33
|
type ORPCErrorFromErrorMap<TErrorMap extends ErrorMap> = {
|
|
32
|
-
[K in keyof TErrorMap]: K extends string ? TErrorMap[K] extends ErrorMapItem<infer TDataSchema
|
|
34
|
+
[K in keyof TErrorMap]: K extends string ? TErrorMap[K] extends ErrorMapItem<infer TDataSchema extends Schema<unknown, unknown>> ? ORPCError<K, InferSchemaOutput<TDataSchema>> : never : never;
|
|
33
35
|
}[keyof TErrorMap];
|
|
34
36
|
type ErrorFromErrorMap<TErrorMap extends ErrorMap> = Error | ORPCErrorFromErrorMap<TErrorMap>;
|
|
35
37
|
|
|
@@ -115,14 +117,14 @@ interface EnhanceRouteOptions {
|
|
|
115
117
|
}
|
|
116
118
|
declare function enhanceRoute(route: Route, options: EnhanceRouteOptions): Route;
|
|
117
119
|
|
|
118
|
-
interface ContractProcedureDef<TInputSchema extends
|
|
120
|
+
interface ContractProcedureDef<TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta> {
|
|
119
121
|
meta: TMeta;
|
|
120
122
|
route: Route;
|
|
121
|
-
inputSchema
|
|
122
|
-
outputSchema
|
|
123
|
+
inputSchema?: TInputSchema;
|
|
124
|
+
outputSchema?: TOutputSchema;
|
|
123
125
|
errorMap: TErrorMap;
|
|
124
126
|
}
|
|
125
|
-
declare class ContractProcedure<TInputSchema extends
|
|
127
|
+
declare class ContractProcedure<TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta> {
|
|
126
128
|
'~orpc': ContractProcedureDef<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
|
127
129
|
constructor(def: ContractProcedureDef<TInputSchema, TOutputSchema, TErrorMap, TMeta>);
|
|
128
130
|
}
|
|
@@ -133,10 +135,10 @@ type ContractRouter<TMeta extends Meta> = ContractProcedure<any, any, any, TMeta
|
|
|
133
135
|
[k: string]: ContractRouter<TMeta>;
|
|
134
136
|
};
|
|
135
137
|
type AnyContractRouter = ContractRouter<any>;
|
|
136
|
-
type InferContractRouterInputs<T extends AnyContractRouter> = T extends ContractProcedure<infer UInputSchema, any, any, any> ?
|
|
138
|
+
type InferContractRouterInputs<T extends AnyContractRouter> = T extends ContractProcedure<infer UInputSchema, any, any, any> ? InferSchemaInput<UInputSchema> : {
|
|
137
139
|
[K in keyof T]: T[K] extends AnyContractRouter ? InferContractRouterInputs<T[K]> : never;
|
|
138
140
|
};
|
|
139
|
-
type InferContractRouterOutputs<T extends AnyContractRouter> = T extends ContractProcedure<any, infer UOutputSchema, any, any> ?
|
|
141
|
+
type InferContractRouterOutputs<T extends AnyContractRouter> = T extends ContractProcedure<any, infer UOutputSchema, any, any> ? InferSchemaOutput<UOutputSchema> : {
|
|
140
142
|
[K in keyof T]: T[K] extends AnyContractRouter ? InferContractRouterOutputs<T[K]> : never;
|
|
141
143
|
};
|
|
142
144
|
type InferContractRouterErrorMap<T extends AnyContractRouter> = T extends ContractProcedure<any, any, infer UErrorMap, any> ? UErrorMap : {
|
|
@@ -153,26 +155,26 @@ interface EnhanceContractRouterOptions<TErrorMap extends ErrorMap> extends Enhan
|
|
|
153
155
|
}
|
|
154
156
|
declare function enhanceContractRouter<T extends AnyContractRouter, TErrorMap extends ErrorMap>(router: T, options: EnhanceContractRouterOptions<TErrorMap>): EnhancedContractRouter<T, TErrorMap>;
|
|
155
157
|
|
|
156
|
-
interface ContractProcedureBuilder<TInputSchema extends
|
|
158
|
+
interface ContractProcedureBuilder<TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta> extends ContractProcedure<TInputSchema, TOutputSchema, TErrorMap, TMeta> {
|
|
157
159
|
errors<U extends ErrorMap>(errors: U): ContractProcedureBuilder<TInputSchema, TOutputSchema, MergedErrorMap<TErrorMap, U>, TMeta>;
|
|
158
160
|
meta(meta: TMeta): ContractProcedureBuilder<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
|
159
161
|
route(route: Route): ContractProcedureBuilder<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
|
160
|
-
input<U extends
|
|
161
|
-
output<U extends
|
|
162
|
+
input<U extends AnySchema>(schema: U): ContractProcedureBuilderWithInput<U, TOutputSchema, TErrorMap, TMeta>;
|
|
163
|
+
output<U extends AnySchema>(schema: U): ContractProcedureBuilderWithOutput<TInputSchema, U, TErrorMap, TMeta>;
|
|
162
164
|
}
|
|
163
|
-
interface ContractProcedureBuilderWithInput<TInputSchema extends
|
|
165
|
+
interface ContractProcedureBuilderWithInput<TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta> extends ContractProcedure<TInputSchema, TOutputSchema, TErrorMap, TMeta> {
|
|
164
166
|
errors<U extends ErrorMap>(errors: U): ContractProcedureBuilderWithInput<TInputSchema, TOutputSchema, MergedErrorMap<TErrorMap, U>, TMeta>;
|
|
165
167
|
meta(meta: TMeta): ContractProcedureBuilderWithInput<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
|
166
168
|
route(route: Route): ContractProcedureBuilderWithInput<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
|
167
|
-
output<U extends
|
|
169
|
+
output<U extends AnySchema>(schema: U): ContractProcedureBuilderWithInputOutput<TInputSchema, U, TErrorMap, TMeta>;
|
|
168
170
|
}
|
|
169
|
-
interface ContractProcedureBuilderWithOutput<TInputSchema extends
|
|
171
|
+
interface ContractProcedureBuilderWithOutput<TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta> extends ContractProcedure<TInputSchema, TOutputSchema, TErrorMap, TMeta> {
|
|
170
172
|
errors<U extends ErrorMap>(errors: U): ContractProcedureBuilderWithOutput<TInputSchema, TOutputSchema, MergedErrorMap<TErrorMap, U>, TMeta>;
|
|
171
173
|
meta(meta: TMeta): ContractProcedureBuilderWithOutput<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
|
172
174
|
route(route: Route): ContractProcedureBuilderWithOutput<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
|
173
|
-
input<U extends
|
|
175
|
+
input<U extends AnySchema>(schema: U): ContractProcedureBuilderWithInputOutput<U, TOutputSchema, TErrorMap, TMeta>;
|
|
174
176
|
}
|
|
175
|
-
interface ContractProcedureBuilderWithInputOutput<TInputSchema extends
|
|
177
|
+
interface ContractProcedureBuilderWithInputOutput<TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta> extends ContractProcedure<TInputSchema, TOutputSchema, TErrorMap, TMeta> {
|
|
176
178
|
errors<U extends ErrorMap>(errors: U): ContractProcedureBuilderWithInputOutput<TInputSchema, TOutputSchema, MergedErrorMap<TErrorMap, U>, TMeta>;
|
|
177
179
|
meta(meta: TMeta): ContractProcedureBuilderWithInputOutput<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
|
178
180
|
route(route: Route): ContractProcedureBuilderWithInputOutput<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
|
@@ -185,9 +187,9 @@ interface ContractRouterBuilder<TErrorMap extends ErrorMap, TMeta extends Meta>
|
|
|
185
187
|
'router'<T extends ContractRouter<TMeta>>(router: T): EnhancedContractRouter<T, TErrorMap>;
|
|
186
188
|
}
|
|
187
189
|
|
|
188
|
-
interface ContractBuilderDef<TInputSchema extends
|
|
190
|
+
interface ContractBuilderDef<TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta> extends ContractProcedureDef<TInputSchema, TOutputSchema, TErrorMap, TMeta>, EnhanceContractRouterOptions<TErrorMap> {
|
|
189
191
|
}
|
|
190
|
-
declare class ContractBuilder<TInputSchema extends
|
|
192
|
+
declare class ContractBuilder<TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta> extends ContractProcedure<TInputSchema, TOutputSchema, TErrorMap, TMeta> {
|
|
191
193
|
'~orpc': ContractBuilderDef<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
|
192
194
|
constructor(def: ContractBuilderDef<TInputSchema, TOutputSchema, TErrorMap, TMeta>);
|
|
193
195
|
/**
|
|
@@ -201,13 +203,13 @@ declare class ContractBuilder<TInputSchema extends Schema, TOutputSchema extends
|
|
|
201
203
|
errors<U extends ErrorMap>(errors: U): ContractBuilder<TInputSchema, TOutputSchema, MergedErrorMap<TErrorMap, U>, TMeta>;
|
|
202
204
|
meta(meta: TMeta): ContractProcedureBuilder<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
|
203
205
|
route(route: Route): ContractProcedureBuilder<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
|
204
|
-
input<U extends
|
|
205
|
-
output<U extends
|
|
206
|
+
input<U extends AnySchema>(schema: U): ContractProcedureBuilderWithInput<U, TOutputSchema, TErrorMap, TMeta>;
|
|
207
|
+
output<U extends AnySchema>(schema: U): ContractProcedureBuilderWithOutput<TInputSchema, U, TErrorMap, TMeta>;
|
|
206
208
|
prefix(prefix: HTTPPath): ContractRouterBuilder<TErrorMap, TMeta>;
|
|
207
209
|
tag(...tags: string[]): ContractRouterBuilder<TErrorMap, TMeta>;
|
|
208
210
|
router<T extends ContractRouter<TMeta>>(router: T): EnhancedContractRouter<T, TErrorMap>;
|
|
209
211
|
}
|
|
210
|
-
declare const oc: ContractBuilder<
|
|
212
|
+
declare const oc: ContractBuilder<Schema<unknown, unknown>, Schema<unknown, unknown>, Record<never, never>, Record<never, never>>;
|
|
211
213
|
|
|
212
214
|
interface ContractConfig {
|
|
213
215
|
defaultMethod: HTTPMethod;
|
|
@@ -218,16 +220,17 @@ interface ContractConfig {
|
|
|
218
220
|
}
|
|
219
221
|
declare function fallbackContractConfig<T extends keyof ContractConfig>(key: T, value: ContractConfig[T] | undefined): ContractConfig[T];
|
|
220
222
|
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
223
|
+
interface EventIteratorSchemaDetails {
|
|
224
|
+
yields: AnySchema;
|
|
225
|
+
returns?: AnySchema;
|
|
226
|
+
}
|
|
227
|
+
declare function eventIterator<TYieldIn, TYieldOut, TReturnIn = unknown, TReturnOut = unknown>(yields: Schema<TYieldIn, TYieldOut>, returns?: Schema<TReturnIn, TReturnOut>): Schema<AsyncIteratorObject<TYieldIn, TReturnIn, void>, AsyncIteratorObject<TYieldOut, TReturnOut, void>>;
|
|
228
|
+
declare function getEventIteratorSchemaDetails(schema: AnySchema | undefined): undefined | EventIteratorSchemaDetails;
|
|
226
229
|
|
|
227
|
-
type ContractProcedureClient<TClientContext extends ClientContext, TInputSchema extends
|
|
230
|
+
type ContractProcedureClient<TClientContext extends ClientContext, TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap> = Client<TClientContext, InferSchemaInput<TInputSchema>, InferSchemaOutput<TOutputSchema>, ErrorFromErrorMap<TErrorMap>>;
|
|
228
231
|
|
|
229
232
|
type ContractRouterClient<TRouter extends AnyContractRouter, TClientContext extends ClientContext = Record<never, never>> = TRouter extends ContractProcedure<infer UInputSchema, infer UOutputSchema, infer UErrorMap, any> ? ContractProcedureClient<TClientContext, UInputSchema, UOutputSchema, UErrorMap> : {
|
|
230
233
|
[K in keyof TRouter]: TRouter[K] extends AnyContractRouter ? ContractRouterClient<TRouter[K], TClientContext> : never;
|
|
231
234
|
};
|
|
232
235
|
|
|
233
|
-
export { type AnyContractProcedure, type AnyContractRouter, ContractBuilder, type ContractBuilderDef, type ContractConfig, ContractProcedure, type ContractProcedureBuilder, type ContractProcedureBuilderWithInput, type ContractProcedureBuilderWithInputOutput, type ContractProcedureBuilderWithOutput, type ContractProcedureClient, type ContractProcedureDef, type ContractRouter, type ContractRouterBuilder, type ContractRouterClient, type EnhanceContractRouterOptions, type EnhanceRouteOptions, type EnhancedContractRouter, type ErrorFromErrorMap, type ErrorMap, type ErrorMapItem, type HTTPMethod, type HTTPPath, type InferContractRouterErrorMap, type InferContractRouterInputs, type InferContractRouterMeta, type InferContractRouterOutputs, type InputStructure, type MergedErrorMap, type Meta, type ORPCErrorFromErrorMap, type OutputStructure, type Route, type Schema, type
|
|
236
|
+
export { type AnyContractProcedure, type AnyContractRouter, type AnySchema, ContractBuilder, type ContractBuilderDef, type ContractConfig, ContractProcedure, type ContractProcedureBuilder, type ContractProcedureBuilderWithInput, type ContractProcedureBuilderWithInputOutput, type ContractProcedureBuilderWithOutput, type ContractProcedureClient, type ContractProcedureDef, type ContractRouter, type ContractRouterBuilder, type ContractRouterClient, type EnhanceContractRouterOptions, type EnhanceRouteOptions, type EnhancedContractRouter, type ErrorFromErrorMap, type ErrorMap, type ErrorMapItem, type EventIteratorSchemaDetails, type HTTPMethod, type HTTPPath, type InferContractRouterErrorMap, type InferContractRouterInputs, type InferContractRouterMeta, type InferContractRouterOutputs, type InferSchemaInput, type InferSchemaOutput, type InputStructure, type MergedErrorMap, type Meta, type ORPCErrorFromErrorMap, type OutputStructure, type Route, type Schema, type SchemaIssue, type TypeRest, ValidationError, type ValidationErrorOptions, enhanceContractRouter, enhanceRoute, eventIterator, fallbackContractConfig, getContractRouter, getEventIteratorSchemaDetails, isContractProcedure, mergeErrorMap, mergeMeta, mergePrefix, mergeRoute, mergeTags, oc, prefixRoute, type, unshiftTagRoute };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,35 +1,37 @@
|
|
|
1
1
|
import { ORPCErrorCode, ORPCError, ClientContext, Client } from '@orpc/client';
|
|
2
2
|
export { ORPCError } from '@orpc/client';
|
|
3
|
-
import { StandardSchemaV1 } from '@standard-schema/spec';
|
|
4
3
|
import { Promisable, IsEqual } from '@orpc/shared';
|
|
4
|
+
import { StandardSchemaV1 } from '@standard-schema/spec';
|
|
5
5
|
|
|
6
|
-
type Schema = StandardSchemaV1
|
|
7
|
-
type
|
|
8
|
-
type
|
|
6
|
+
type Schema<TInput, TOutput> = StandardSchemaV1<TInput, TOutput>;
|
|
7
|
+
type AnySchema = Schema<any, any>;
|
|
8
|
+
type SchemaIssue = StandardSchemaV1.Issue;
|
|
9
|
+
type InferSchemaInput<T extends AnySchema> = T extends StandardSchemaV1<infer UInput, any> ? UInput : never;
|
|
10
|
+
type InferSchemaOutput<T extends AnySchema> = T extends StandardSchemaV1<any, infer UOutput> ? UOutput : never;
|
|
9
11
|
type TypeRest<TInput, TOutput> = [map: (input: TInput) => Promisable<TOutput>] | (IsEqual<TInput, TOutput> extends true ? [] : never);
|
|
10
|
-
declare function type<TInput, TOutput = TInput>(...[map]: TypeRest<TInput, TOutput>):
|
|
12
|
+
declare function type<TInput, TOutput = TInput>(...[map]: TypeRest<TInput, TOutput>): Schema<TInput, TOutput>;
|
|
11
13
|
|
|
12
14
|
interface ValidationErrorOptions extends ErrorOptions {
|
|
13
15
|
message: string;
|
|
14
|
-
issues: readonly
|
|
16
|
+
issues: readonly SchemaIssue[];
|
|
15
17
|
}
|
|
16
18
|
declare class ValidationError extends Error {
|
|
17
|
-
readonly issues: readonly
|
|
19
|
+
readonly issues: readonly SchemaIssue[];
|
|
18
20
|
constructor(options: ValidationErrorOptions);
|
|
19
21
|
}
|
|
20
|
-
interface ErrorMapItem<TDataSchema extends
|
|
22
|
+
interface ErrorMapItem<TDataSchema extends AnySchema> {
|
|
21
23
|
status?: number;
|
|
22
24
|
message?: string;
|
|
23
25
|
description?: string;
|
|
24
26
|
data?: TDataSchema;
|
|
25
27
|
}
|
|
26
28
|
type ErrorMap = {
|
|
27
|
-
[key in ORPCErrorCode]?: ErrorMapItem<
|
|
29
|
+
[key in ORPCErrorCode]?: ErrorMapItem<AnySchema>;
|
|
28
30
|
};
|
|
29
31
|
type MergedErrorMap<T1 extends ErrorMap, T2 extends ErrorMap> = Omit<T1, keyof T2> & T2;
|
|
30
32
|
declare function mergeErrorMap<T1 extends ErrorMap, T2 extends ErrorMap>(errorMap1: T1, errorMap2: T2): MergedErrorMap<T1, T2>;
|
|
31
33
|
type ORPCErrorFromErrorMap<TErrorMap extends ErrorMap> = {
|
|
32
|
-
[K in keyof TErrorMap]: K extends string ? TErrorMap[K] extends ErrorMapItem<infer TDataSchema
|
|
34
|
+
[K in keyof TErrorMap]: K extends string ? TErrorMap[K] extends ErrorMapItem<infer TDataSchema extends Schema<unknown, unknown>> ? ORPCError<K, InferSchemaOutput<TDataSchema>> : never : never;
|
|
33
35
|
}[keyof TErrorMap];
|
|
34
36
|
type ErrorFromErrorMap<TErrorMap extends ErrorMap> = Error | ORPCErrorFromErrorMap<TErrorMap>;
|
|
35
37
|
|
|
@@ -115,14 +117,14 @@ interface EnhanceRouteOptions {
|
|
|
115
117
|
}
|
|
116
118
|
declare function enhanceRoute(route: Route, options: EnhanceRouteOptions): Route;
|
|
117
119
|
|
|
118
|
-
interface ContractProcedureDef<TInputSchema extends
|
|
120
|
+
interface ContractProcedureDef<TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta> {
|
|
119
121
|
meta: TMeta;
|
|
120
122
|
route: Route;
|
|
121
|
-
inputSchema
|
|
122
|
-
outputSchema
|
|
123
|
+
inputSchema?: TInputSchema;
|
|
124
|
+
outputSchema?: TOutputSchema;
|
|
123
125
|
errorMap: TErrorMap;
|
|
124
126
|
}
|
|
125
|
-
declare class ContractProcedure<TInputSchema extends
|
|
127
|
+
declare class ContractProcedure<TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta> {
|
|
126
128
|
'~orpc': ContractProcedureDef<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
|
127
129
|
constructor(def: ContractProcedureDef<TInputSchema, TOutputSchema, TErrorMap, TMeta>);
|
|
128
130
|
}
|
|
@@ -133,10 +135,10 @@ type ContractRouter<TMeta extends Meta> = ContractProcedure<any, any, any, TMeta
|
|
|
133
135
|
[k: string]: ContractRouter<TMeta>;
|
|
134
136
|
};
|
|
135
137
|
type AnyContractRouter = ContractRouter<any>;
|
|
136
|
-
type InferContractRouterInputs<T extends AnyContractRouter> = T extends ContractProcedure<infer UInputSchema, any, any, any> ?
|
|
138
|
+
type InferContractRouterInputs<T extends AnyContractRouter> = T extends ContractProcedure<infer UInputSchema, any, any, any> ? InferSchemaInput<UInputSchema> : {
|
|
137
139
|
[K in keyof T]: T[K] extends AnyContractRouter ? InferContractRouterInputs<T[K]> : never;
|
|
138
140
|
};
|
|
139
|
-
type InferContractRouterOutputs<T extends AnyContractRouter> = T extends ContractProcedure<any, infer UOutputSchema, any, any> ?
|
|
141
|
+
type InferContractRouterOutputs<T extends AnyContractRouter> = T extends ContractProcedure<any, infer UOutputSchema, any, any> ? InferSchemaOutput<UOutputSchema> : {
|
|
140
142
|
[K in keyof T]: T[K] extends AnyContractRouter ? InferContractRouterOutputs<T[K]> : never;
|
|
141
143
|
};
|
|
142
144
|
type InferContractRouterErrorMap<T extends AnyContractRouter> = T extends ContractProcedure<any, any, infer UErrorMap, any> ? UErrorMap : {
|
|
@@ -153,26 +155,26 @@ interface EnhanceContractRouterOptions<TErrorMap extends ErrorMap> extends Enhan
|
|
|
153
155
|
}
|
|
154
156
|
declare function enhanceContractRouter<T extends AnyContractRouter, TErrorMap extends ErrorMap>(router: T, options: EnhanceContractRouterOptions<TErrorMap>): EnhancedContractRouter<T, TErrorMap>;
|
|
155
157
|
|
|
156
|
-
interface ContractProcedureBuilder<TInputSchema extends
|
|
158
|
+
interface ContractProcedureBuilder<TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta> extends ContractProcedure<TInputSchema, TOutputSchema, TErrorMap, TMeta> {
|
|
157
159
|
errors<U extends ErrorMap>(errors: U): ContractProcedureBuilder<TInputSchema, TOutputSchema, MergedErrorMap<TErrorMap, U>, TMeta>;
|
|
158
160
|
meta(meta: TMeta): ContractProcedureBuilder<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
|
159
161
|
route(route: Route): ContractProcedureBuilder<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
|
160
|
-
input<U extends
|
|
161
|
-
output<U extends
|
|
162
|
+
input<U extends AnySchema>(schema: U): ContractProcedureBuilderWithInput<U, TOutputSchema, TErrorMap, TMeta>;
|
|
163
|
+
output<U extends AnySchema>(schema: U): ContractProcedureBuilderWithOutput<TInputSchema, U, TErrorMap, TMeta>;
|
|
162
164
|
}
|
|
163
|
-
interface ContractProcedureBuilderWithInput<TInputSchema extends
|
|
165
|
+
interface ContractProcedureBuilderWithInput<TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta> extends ContractProcedure<TInputSchema, TOutputSchema, TErrorMap, TMeta> {
|
|
164
166
|
errors<U extends ErrorMap>(errors: U): ContractProcedureBuilderWithInput<TInputSchema, TOutputSchema, MergedErrorMap<TErrorMap, U>, TMeta>;
|
|
165
167
|
meta(meta: TMeta): ContractProcedureBuilderWithInput<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
|
166
168
|
route(route: Route): ContractProcedureBuilderWithInput<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
|
167
|
-
output<U extends
|
|
169
|
+
output<U extends AnySchema>(schema: U): ContractProcedureBuilderWithInputOutput<TInputSchema, U, TErrorMap, TMeta>;
|
|
168
170
|
}
|
|
169
|
-
interface ContractProcedureBuilderWithOutput<TInputSchema extends
|
|
171
|
+
interface ContractProcedureBuilderWithOutput<TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta> extends ContractProcedure<TInputSchema, TOutputSchema, TErrorMap, TMeta> {
|
|
170
172
|
errors<U extends ErrorMap>(errors: U): ContractProcedureBuilderWithOutput<TInputSchema, TOutputSchema, MergedErrorMap<TErrorMap, U>, TMeta>;
|
|
171
173
|
meta(meta: TMeta): ContractProcedureBuilderWithOutput<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
|
172
174
|
route(route: Route): ContractProcedureBuilderWithOutput<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
|
173
|
-
input<U extends
|
|
175
|
+
input<U extends AnySchema>(schema: U): ContractProcedureBuilderWithInputOutput<U, TOutputSchema, TErrorMap, TMeta>;
|
|
174
176
|
}
|
|
175
|
-
interface ContractProcedureBuilderWithInputOutput<TInputSchema extends
|
|
177
|
+
interface ContractProcedureBuilderWithInputOutput<TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta> extends ContractProcedure<TInputSchema, TOutputSchema, TErrorMap, TMeta> {
|
|
176
178
|
errors<U extends ErrorMap>(errors: U): ContractProcedureBuilderWithInputOutput<TInputSchema, TOutputSchema, MergedErrorMap<TErrorMap, U>, TMeta>;
|
|
177
179
|
meta(meta: TMeta): ContractProcedureBuilderWithInputOutput<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
|
178
180
|
route(route: Route): ContractProcedureBuilderWithInputOutput<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
|
@@ -185,9 +187,9 @@ interface ContractRouterBuilder<TErrorMap extends ErrorMap, TMeta extends Meta>
|
|
|
185
187
|
'router'<T extends ContractRouter<TMeta>>(router: T): EnhancedContractRouter<T, TErrorMap>;
|
|
186
188
|
}
|
|
187
189
|
|
|
188
|
-
interface ContractBuilderDef<TInputSchema extends
|
|
190
|
+
interface ContractBuilderDef<TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta> extends ContractProcedureDef<TInputSchema, TOutputSchema, TErrorMap, TMeta>, EnhanceContractRouterOptions<TErrorMap> {
|
|
189
191
|
}
|
|
190
|
-
declare class ContractBuilder<TInputSchema extends
|
|
192
|
+
declare class ContractBuilder<TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta> extends ContractProcedure<TInputSchema, TOutputSchema, TErrorMap, TMeta> {
|
|
191
193
|
'~orpc': ContractBuilderDef<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
|
192
194
|
constructor(def: ContractBuilderDef<TInputSchema, TOutputSchema, TErrorMap, TMeta>);
|
|
193
195
|
/**
|
|
@@ -201,13 +203,13 @@ declare class ContractBuilder<TInputSchema extends Schema, TOutputSchema extends
|
|
|
201
203
|
errors<U extends ErrorMap>(errors: U): ContractBuilder<TInputSchema, TOutputSchema, MergedErrorMap<TErrorMap, U>, TMeta>;
|
|
202
204
|
meta(meta: TMeta): ContractProcedureBuilder<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
|
203
205
|
route(route: Route): ContractProcedureBuilder<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
|
204
|
-
input<U extends
|
|
205
|
-
output<U extends
|
|
206
|
+
input<U extends AnySchema>(schema: U): ContractProcedureBuilderWithInput<U, TOutputSchema, TErrorMap, TMeta>;
|
|
207
|
+
output<U extends AnySchema>(schema: U): ContractProcedureBuilderWithOutput<TInputSchema, U, TErrorMap, TMeta>;
|
|
206
208
|
prefix(prefix: HTTPPath): ContractRouterBuilder<TErrorMap, TMeta>;
|
|
207
209
|
tag(...tags: string[]): ContractRouterBuilder<TErrorMap, TMeta>;
|
|
208
210
|
router<T extends ContractRouter<TMeta>>(router: T): EnhancedContractRouter<T, TErrorMap>;
|
|
209
211
|
}
|
|
210
|
-
declare const oc: ContractBuilder<
|
|
212
|
+
declare const oc: ContractBuilder<Schema<unknown, unknown>, Schema<unknown, unknown>, Record<never, never>, Record<never, never>>;
|
|
211
213
|
|
|
212
214
|
interface ContractConfig {
|
|
213
215
|
defaultMethod: HTTPMethod;
|
|
@@ -218,16 +220,17 @@ interface ContractConfig {
|
|
|
218
220
|
}
|
|
219
221
|
declare function fallbackContractConfig<T extends keyof ContractConfig>(key: T, value: ContractConfig[T] | undefined): ContractConfig[T];
|
|
220
222
|
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
223
|
+
interface EventIteratorSchemaDetails {
|
|
224
|
+
yields: AnySchema;
|
|
225
|
+
returns?: AnySchema;
|
|
226
|
+
}
|
|
227
|
+
declare function eventIterator<TYieldIn, TYieldOut, TReturnIn = unknown, TReturnOut = unknown>(yields: Schema<TYieldIn, TYieldOut>, returns?: Schema<TReturnIn, TReturnOut>): Schema<AsyncIteratorObject<TYieldIn, TReturnIn, void>, AsyncIteratorObject<TYieldOut, TReturnOut, void>>;
|
|
228
|
+
declare function getEventIteratorSchemaDetails(schema: AnySchema | undefined): undefined | EventIteratorSchemaDetails;
|
|
226
229
|
|
|
227
|
-
type ContractProcedureClient<TClientContext extends ClientContext, TInputSchema extends
|
|
230
|
+
type ContractProcedureClient<TClientContext extends ClientContext, TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap> = Client<TClientContext, InferSchemaInput<TInputSchema>, InferSchemaOutput<TOutputSchema>, ErrorFromErrorMap<TErrorMap>>;
|
|
228
231
|
|
|
229
232
|
type ContractRouterClient<TRouter extends AnyContractRouter, TClientContext extends ClientContext = Record<never, never>> = TRouter extends ContractProcedure<infer UInputSchema, infer UOutputSchema, infer UErrorMap, any> ? ContractProcedureClient<TClientContext, UInputSchema, UOutputSchema, UErrorMap> : {
|
|
230
233
|
[K in keyof TRouter]: TRouter[K] extends AnyContractRouter ? ContractRouterClient<TRouter[K], TClientContext> : never;
|
|
231
234
|
};
|
|
232
235
|
|
|
233
|
-
export { type AnyContractProcedure, type AnyContractRouter, ContractBuilder, type ContractBuilderDef, type ContractConfig, ContractProcedure, type ContractProcedureBuilder, type ContractProcedureBuilderWithInput, type ContractProcedureBuilderWithInputOutput, type ContractProcedureBuilderWithOutput, type ContractProcedureClient, type ContractProcedureDef, type ContractRouter, type ContractRouterBuilder, type ContractRouterClient, type EnhanceContractRouterOptions, type EnhanceRouteOptions, type EnhancedContractRouter, type ErrorFromErrorMap, type ErrorMap, type ErrorMapItem, type HTTPMethod, type HTTPPath, type InferContractRouterErrorMap, type InferContractRouterInputs, type InferContractRouterMeta, type InferContractRouterOutputs, type InputStructure, type MergedErrorMap, type Meta, type ORPCErrorFromErrorMap, type OutputStructure, type Route, type Schema, type
|
|
236
|
+
export { type AnyContractProcedure, type AnyContractRouter, type AnySchema, ContractBuilder, type ContractBuilderDef, type ContractConfig, ContractProcedure, type ContractProcedureBuilder, type ContractProcedureBuilderWithInput, type ContractProcedureBuilderWithInputOutput, type ContractProcedureBuilderWithOutput, type ContractProcedureClient, type ContractProcedureDef, type ContractRouter, type ContractRouterBuilder, type ContractRouterClient, type EnhanceContractRouterOptions, type EnhanceRouteOptions, type EnhancedContractRouter, type ErrorFromErrorMap, type ErrorMap, type ErrorMapItem, type EventIteratorSchemaDetails, type HTTPMethod, type HTTPPath, type InferContractRouterErrorMap, type InferContractRouterInputs, type InferContractRouterMeta, type InferContractRouterOutputs, type InferSchemaInput, type InferSchemaOutput, type InputStructure, type MergedErrorMap, type Meta, type ORPCErrorFromErrorMap, type OutputStructure, type Route, type Schema, type SchemaIssue, type TypeRest, ValidationError, type ValidationErrorOptions, enhanceContractRouter, enhanceRoute, eventIterator, fallbackContractConfig, getContractRouter, getEventIteratorSchemaDetails, isContractProcedure, mergeErrorMap, mergeMeta, mergePrefix, mergeRoute, mergeTags, oc, prefixRoute, type, unshiftTagRoute };
|
package/dist/index.mjs
CHANGED
|
@@ -33,7 +33,7 @@ function isContractProcedure(item) {
|
|
|
33
33
|
if (item instanceof ContractProcedure) {
|
|
34
34
|
return true;
|
|
35
35
|
}
|
|
36
|
-
return (typeof item === "object" || typeof item === "function") && item !== null && "~orpc" in item && typeof item["~orpc"] === "object" && item["~orpc"] !== null && "
|
|
36
|
+
return (typeof item === "object" || typeof item === "function") && item !== null && "~orpc" in item && typeof item["~orpc"] === "object" && item["~orpc"] !== null && "errorMap" in item["~orpc"] && "route" in item["~orpc"] && "meta" in item["~orpc"];
|
|
37
37
|
}
|
|
38
38
|
|
|
39
39
|
function mergeRoute(a, b) {
|
|
@@ -173,8 +173,6 @@ class ContractBuilder extends ContractProcedure {
|
|
|
173
173
|
}
|
|
174
174
|
const oc = new ContractBuilder({
|
|
175
175
|
errorMap: {},
|
|
176
|
-
inputSchema: void 0,
|
|
177
|
-
outputSchema: void 0,
|
|
178
176
|
route: {},
|
|
179
177
|
meta: {}
|
|
180
178
|
});
|
|
@@ -193,11 +191,11 @@ function fallbackContractConfig(key, value) {
|
|
|
193
191
|
return value;
|
|
194
192
|
}
|
|
195
193
|
|
|
196
|
-
const
|
|
194
|
+
const EVENT_ITERATOR_DETAILS_SYMBOL = Symbol("ORPC_EVENT_ITERATOR_DETAILS");
|
|
197
195
|
function eventIterator(yields, returns) {
|
|
198
196
|
return {
|
|
199
197
|
"~standard": {
|
|
200
|
-
[
|
|
198
|
+
[EVENT_ITERATOR_DETAILS_SYMBOL]: { yields, returns },
|
|
201
199
|
vendor: "orpc",
|
|
202
200
|
version: 1,
|
|
203
201
|
validate(iterator) {
|
|
@@ -233,7 +231,7 @@ function getEventIteratorSchemaDetails(schema) {
|
|
|
233
231
|
if (schema === void 0) {
|
|
234
232
|
return void 0;
|
|
235
233
|
}
|
|
236
|
-
return schema["~standard"][
|
|
234
|
+
return schema["~standard"][EVENT_ITERATOR_DETAILS_SYMBOL];
|
|
237
235
|
}
|
|
238
236
|
|
|
239
237
|
function type(...[map]) {
|
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.3b1dac3",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"homepage": "https://orpc.unnoq.com",
|
|
7
7
|
"repository": {
|
|
@@ -25,9 +25,9 @@
|
|
|
25
25
|
],
|
|
26
26
|
"dependencies": {
|
|
27
27
|
"@standard-schema/spec": "^1.0.0",
|
|
28
|
-
"@orpc/
|
|
29
|
-
"@orpc/
|
|
30
|
-
"@orpc/
|
|
28
|
+
"@orpc/client": "0.0.0-next.3b1dac3",
|
|
29
|
+
"@orpc/shared": "0.0.0-next.3b1dac3",
|
|
30
|
+
"@orpc/standard-server": "0.0.0-next.3b1dac3"
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
33
33
|
"arktype": "2.0.0-rc.26",
|