@orpc/contract 0.43.0 → 0.44.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/README.md CHANGED
@@ -1,5 +1,5 @@
1
1
  <div align="center">
2
- <image align="center" src="https://orpc.unnoq.com/logo.webp" width=280 />
2
+ <image align="center" src="https://orpc.unnoq.com/logo.webp" width=280 alt="oRPC logo" />
3
3
  </div>
4
4
 
5
5
  <h1></h1>
@@ -0,0 +1,233 @@
1
+ import { ORPCErrorCode, ORPCError, ClientContext, Client } from '@orpc/client';
2
+ export { ORPCError } from '@orpc/client';
3
+ import { StandardSchemaV1 } from '@standard-schema/spec';
4
+ import { Promisable, IsEqual } from '@orpc/shared';
5
+
6
+ type Schema = StandardSchemaV1 | undefined;
7
+ type SchemaInput<TSchema extends Schema, TFallback = unknown> = TSchema extends undefined ? TFallback : TSchema extends StandardSchemaV1 ? StandardSchemaV1.InferInput<TSchema> : TFallback;
8
+ type SchemaOutput<TSchema extends Schema, TFallback = unknown> = TSchema extends undefined ? TFallback : TSchema extends StandardSchemaV1 ? StandardSchemaV1.InferOutput<TSchema> : TFallback;
9
+ 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>): StandardSchemaV1<TInput, TOutput>;
11
+
12
+ interface ValidationErrorOptions extends ErrorOptions {
13
+ message: string;
14
+ issues: readonly StandardSchemaV1.Issue[];
15
+ }
16
+ declare class ValidationError extends Error {
17
+ readonly issues: readonly StandardSchemaV1.Issue[];
18
+ constructor(options: ValidationErrorOptions);
19
+ }
20
+ type ErrorMapItem<TDataSchema extends Schema> = {
21
+ status?: number;
22
+ message?: string;
23
+ description?: string;
24
+ data?: TDataSchema;
25
+ };
26
+ type ErrorMap = {
27
+ [key in ORPCErrorCode]?: ErrorMapItem<Schema>;
28
+ };
29
+ type MergedErrorMap<T1 extends ErrorMap, T2 extends ErrorMap> = Omit<T1, keyof T2> & T2;
30
+ declare function mergeErrorMap<T1 extends ErrorMap, T2 extends ErrorMap>(errorMap1: T1, errorMap2: T2): MergedErrorMap<T1, T2>;
31
+ type ORPCErrorFromErrorMap<TErrorMap extends ErrorMap> = {
32
+ [K in keyof TErrorMap]: K extends string ? TErrorMap[K] extends ErrorMapItem<infer TDataSchema> ? ORPCError<K, SchemaOutput<TDataSchema>> : never : never;
33
+ }[keyof TErrorMap];
34
+ type ErrorFromErrorMap<TErrorMap extends ErrorMap> = Error | ORPCErrorFromErrorMap<TErrorMap>;
35
+
36
+ type Meta = Record<string, any>;
37
+ declare function mergeMeta<T extends Meta>(meta1: T, meta2: T): T;
38
+
39
+ type HTTPPath = `/${string}`;
40
+ type HTTPMethod = 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH';
41
+ type InputStructure = 'compact' | 'detailed';
42
+ type OutputStructure = 'compact' | 'detailed';
43
+ interface Route {
44
+ method?: HTTPMethod;
45
+ path?: HTTPPath;
46
+ summary?: string;
47
+ description?: string;
48
+ deprecated?: boolean;
49
+ tags?: readonly string[];
50
+ /**
51
+ * The status code of the response when the procedure is successful.
52
+ *
53
+ * @default 200
54
+ */
55
+ successStatus?: number;
56
+ /**
57
+ * The description of the response when the procedure is successful.
58
+ *
59
+ * @default 'OK'
60
+ */
61
+ successDescription?: string;
62
+ /**
63
+ * Determines how the input should be structured based on `params`, `query`, `headers`, and `body`.
64
+ *
65
+ * @option 'compact'
66
+ * Combines `params` and either `query` or `body` (depending on the HTTP method) into a single object.
67
+ *
68
+ * @option 'detailed'
69
+ * Keeps each part of the request (`params`, `query`, `headers`, and `body`) as separate fields in the input object.
70
+ *
71
+ * Example:
72
+ * ```ts
73
+ * const input = {
74
+ * params: { id: 1 },
75
+ * query: { search: 'hello' },
76
+ * headers: { 'Content-Type': 'application/json' },
77
+ * body: { name: 'John' },
78
+ * }
79
+ * ```
80
+ *
81
+ * @default 'compact'
82
+ */
83
+ inputStructure?: InputStructure;
84
+ /**
85
+ * Determines how the response should be structured based on the output.
86
+ *
87
+ * @option 'compact'
88
+ * Includes only the body data, encoded directly in the response.
89
+ *
90
+ * @option 'detailed'
91
+ * Separates the output into `headers` and `body` fields.
92
+ * - `headers`: Custom headers to merge with the response headers.
93
+ * - `body`: The response data.
94
+ *
95
+ * Example:
96
+ * ```ts
97
+ * const output = {
98
+ * headers: { 'x-custom-header': 'value' },
99
+ * body: { message: 'Hello, world!' },
100
+ * };
101
+ * ```
102
+ *
103
+ * @default 'compact'
104
+ */
105
+ outputStructure?: OutputStructure;
106
+ }
107
+ declare function mergeRoute(a: Route, b: Route): Route;
108
+ declare function prefixRoute(route: Route, prefix: HTTPPath): Route;
109
+ declare function unshiftTagRoute(route: Route, tags: readonly string[]): Route;
110
+ declare function mergePrefix(a: HTTPPath | undefined, b: HTTPPath): HTTPPath;
111
+ declare function mergeTags(a: readonly string[] | undefined, b: readonly string[]): readonly string[];
112
+ interface AdaptRouteOptions {
113
+ prefix?: HTTPPath;
114
+ tags?: readonly string[];
115
+ }
116
+ declare function adaptRoute(route: Route, options: AdaptRouteOptions): Route;
117
+
118
+ interface ContractProcedureDef<TInputSchema extends Schema, TOutputSchema extends Schema, TErrorMap extends ErrorMap, TMeta extends Meta> {
119
+ meta: TMeta;
120
+ route: Route;
121
+ inputSchema: TInputSchema;
122
+ outputSchema: TOutputSchema;
123
+ errorMap: TErrorMap;
124
+ }
125
+ declare class ContractProcedure<TInputSchema extends Schema, TOutputSchema extends Schema, TErrorMap extends ErrorMap, TMeta extends Meta> {
126
+ '~orpc': ContractProcedureDef<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
127
+ constructor(def: ContractProcedureDef<TInputSchema, TOutputSchema, TErrorMap, TMeta>);
128
+ }
129
+ type AnyContractProcedure = ContractProcedure<any, any, any, any>;
130
+ declare function isContractProcedure(item: unknown): item is AnyContractProcedure;
131
+
132
+ type ContractRouter<TMeta extends Meta> = ContractProcedure<any, any, any, TMeta> | {
133
+ [k: string]: ContractRouter<TMeta>;
134
+ };
135
+ type AnyContractRouter = ContractRouter<any>;
136
+ type AdaptedContractRouter<TContract extends AnyContractRouter, TErrorMap extends ErrorMap> = {
137
+ [K in keyof TContract]: TContract[K] extends ContractProcedure<infer UInputSchema, infer UOutputSchema, infer UErrors, infer UMeta> ? ContractProcedure<UInputSchema, UOutputSchema, MergedErrorMap<TErrorMap, UErrors>, UMeta> : TContract[K] extends AnyContractRouter ? AdaptedContractRouter<TContract[K], TErrorMap> : never;
138
+ };
139
+ interface AdaptContractRouterOptions<TErrorMap extends ErrorMap> {
140
+ errorMap: TErrorMap;
141
+ prefix?: HTTPPath;
142
+ tags?: readonly string[];
143
+ }
144
+ declare function adaptContractRouter<TRouter extends ContractRouter<any>, TErrorMap extends ErrorMap>(contract: TRouter, options: AdaptContractRouterOptions<TErrorMap>): AdaptedContractRouter<TRouter, TErrorMap>;
145
+ type InferContractRouterInputs<T extends AnyContractRouter> = T extends ContractProcedure<infer UInputSchema, any, any, any> ? SchemaInput<UInputSchema> : {
146
+ [K in keyof T]: T[K] extends AnyContractRouter ? InferContractRouterInputs<T[K]> : never;
147
+ };
148
+ type InferContractRouterOutputs<T extends AnyContractRouter> = T extends ContractProcedure<any, infer UOutputSchema, any, any> ? SchemaOutput<UOutputSchema> : {
149
+ [K in keyof T]: T[K] extends AnyContractRouter ? InferContractRouterOutputs<T[K]> : never;
150
+ };
151
+ type ContractRouterToErrorMap<T extends AnyContractRouter> = T extends ContractProcedure<any, any, infer UErrorMap, any> ? UErrorMap : {
152
+ [K in keyof T]: T[K] extends AnyContractRouter ? ContractRouterToErrorMap<T[K]> : never;
153
+ }[keyof T];
154
+ type ContractRouterToMeta<T extends AnyContractRouter> = T extends ContractRouter<infer UMeta> ? UMeta : never;
155
+
156
+ interface ContractProcedureBuilder<TInputSchema extends Schema, TOutputSchema extends Schema, TErrorMap extends ErrorMap, TMeta extends Meta> extends ContractProcedure<TInputSchema, TOutputSchema, TErrorMap, TMeta> {
157
+ errors<U extends ErrorMap>(errors: U): ContractProcedureBuilder<TInputSchema, TOutputSchema, MergedErrorMap<TErrorMap, U>, TMeta>;
158
+ meta(meta: TMeta): ContractProcedureBuilder<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
159
+ route(route: Route): ContractProcedureBuilder<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
160
+ input<U extends Schema>(schema: U): ContractProcedureBuilderWithInput<U, TOutputSchema, TErrorMap, TMeta>;
161
+ output<U extends Schema>(schema: U): ContractProcedureBuilderWithOutput<TInputSchema, U, TErrorMap, TMeta>;
162
+ }
163
+ interface ContractProcedureBuilderWithInput<TInputSchema extends Schema, TOutputSchema extends Schema, TErrorMap extends ErrorMap, TMeta extends Meta> extends ContractProcedure<TInputSchema, TOutputSchema, TErrorMap, TMeta> {
164
+ errors<U extends ErrorMap>(errors: U): ContractProcedureBuilderWithInput<TInputSchema, TOutputSchema, MergedErrorMap<TErrorMap, U>, TMeta>;
165
+ meta(meta: TMeta): ContractProcedureBuilderWithInput<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
166
+ route(route: Route): ContractProcedureBuilderWithInput<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
167
+ output<U extends Schema>(schema: U): ContractProcedureBuilderWithInputOutput<TInputSchema, U, TErrorMap, TMeta>;
168
+ }
169
+ interface ContractProcedureBuilderWithOutput<TInputSchema extends Schema, TOutputSchema extends Schema, TErrorMap extends ErrorMap, TMeta extends Meta> extends ContractProcedure<TInputSchema, TOutputSchema, TErrorMap, TMeta> {
170
+ errors<U extends ErrorMap>(errors: U): ContractProcedureBuilderWithOutput<TInputSchema, TOutputSchema, MergedErrorMap<TErrorMap, U>, TMeta>;
171
+ meta(meta: TMeta): ContractProcedureBuilderWithOutput<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
172
+ route(route: Route): ContractProcedureBuilderWithOutput<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
173
+ input<U extends Schema>(schema: U): ContractProcedureBuilderWithInputOutput<U, TOutputSchema, TErrorMap, TMeta>;
174
+ }
175
+ interface ContractProcedureBuilderWithInputOutput<TInputSchema extends Schema, TOutputSchema extends Schema, TErrorMap extends ErrorMap, TMeta extends Meta> extends ContractProcedure<TInputSchema, TOutputSchema, TErrorMap, TMeta> {
176
+ errors<U extends ErrorMap>(errors: U): ContractProcedureBuilderWithInputOutput<TInputSchema, TOutputSchema, MergedErrorMap<TErrorMap, U>, TMeta>;
177
+ meta(meta: TMeta): ContractProcedureBuilderWithInputOutput<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
178
+ route(route: Route): ContractProcedureBuilderWithInputOutput<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
179
+ }
180
+ interface ContractRouterBuilder<TErrorMap extends ErrorMap, TMeta extends Meta> {
181
+ '~orpc': AdaptContractRouterOptions<TErrorMap>;
182
+ 'errors'<U extends ErrorMap>(errors: U): ContractRouterBuilder<MergedErrorMap<TErrorMap, U>, TMeta>;
183
+ 'prefix'(prefix: HTTPPath): ContractRouterBuilder<TErrorMap, TMeta>;
184
+ 'tag'(...tags: string[]): ContractRouterBuilder<TErrorMap, TMeta>;
185
+ 'router'<T extends ContractRouter<TMeta>>(router: T): AdaptedContractRouter<T, TErrorMap>;
186
+ }
187
+
188
+ interface ContractBuilderDef<TInputSchema extends Schema, TOutputSchema extends Schema, TErrorMap extends ErrorMap, TMeta extends Meta> extends ContractProcedureDef<TInputSchema, TOutputSchema, TErrorMap, TMeta>, AdaptContractRouterOptions<TErrorMap> {
189
+ }
190
+ declare class ContractBuilder<TInputSchema extends Schema, TOutputSchema extends Schema, TErrorMap extends ErrorMap, TMeta extends Meta> extends ContractProcedure<TInputSchema, TOutputSchema, TErrorMap, TMeta> {
191
+ '~orpc': ContractBuilderDef<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
192
+ constructor(def: ContractBuilderDef<TInputSchema, TOutputSchema, TErrorMap, TMeta>);
193
+ /**
194
+ * Reset initial meta
195
+ */
196
+ $meta<U extends Meta>(initialMeta: U): ContractBuilder<TInputSchema, TOutputSchema, TErrorMap, U>;
197
+ /**
198
+ * Reset initial route
199
+ */
200
+ $route(initialRoute: Route): ContractBuilder<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
201
+ errors<U extends ErrorMap>(errors: U): ContractBuilder<TInputSchema, TOutputSchema, MergedErrorMap<TErrorMap, U>, TMeta>;
202
+ meta(meta: TMeta): ContractProcedureBuilder<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
203
+ route(route: Route): ContractProcedureBuilder<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
204
+ input<U extends Schema>(schema: U): ContractProcedureBuilderWithInput<U, TOutputSchema, TErrorMap, TMeta>;
205
+ output<U extends Schema>(schema: U): ContractProcedureBuilderWithOutput<TInputSchema, U, TErrorMap, TMeta>;
206
+ prefix(prefix: HTTPPath): ContractRouterBuilder<TErrorMap, TMeta>;
207
+ tag(...tags: string[]): ContractRouterBuilder<TErrorMap, TMeta>;
208
+ router<T extends ContractRouter<TMeta>>(router: T): AdaptedContractRouter<T, TErrorMap>;
209
+ }
210
+ declare const oc: ContractBuilder<undefined, undefined, {}, {}>;
211
+
212
+ interface ContractConfig {
213
+ defaultMethod: HTTPMethod;
214
+ defaultSuccessStatus: number;
215
+ defaultSuccessDescription: string;
216
+ defaultInputStructure: InputStructure;
217
+ defaultOutputStructure: InputStructure;
218
+ }
219
+ declare function fallbackContractConfig<T extends keyof ContractConfig>(key: T, value: ContractConfig[T] | undefined): ContractConfig[T];
220
+
221
+ declare function eventIterator<TYieldIn, TYieldOut, TReturnIn = unknown, TReturnOut = unknown>(yields: StandardSchemaV1<TYieldIn, TYieldOut>, returns?: StandardSchemaV1<TReturnIn, TReturnOut>): StandardSchemaV1<AsyncIteratorObject<TYieldIn, TReturnIn, void>, AsyncIteratorObject<TYieldOut, TReturnOut, void>>;
222
+ declare function getEventIteratorSchemaDetails(schema: Schema): undefined | {
223
+ yields: Schema;
224
+ returns: Schema;
225
+ };
226
+
227
+ type ContractProcedureClient<TClientContext extends ClientContext, TInputSchema extends Schema, TOutputSchema extends Schema, TErrorMap extends ErrorMap> = Client<TClientContext, SchemaInput<TInputSchema>, SchemaOutput<TOutputSchema>, ErrorFromErrorMap<TErrorMap>>;
228
+
229
+ 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
+ [K in keyof TRouter]: TRouter[K] extends AnyContractRouter ? ContractRouterClient<TRouter[K], TClientContext> : never;
231
+ };
232
+
233
+ export { type AdaptContractRouterOptions, type AdaptRouteOptions, type AdaptedContractRouter, 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 ContractRouterToErrorMap, type ContractRouterToMeta, type ErrorFromErrorMap, type ErrorMap, type ErrorMapItem, type HTTPMethod, type HTTPPath, type InferContractRouterInputs, type InferContractRouterOutputs, type InputStructure, type MergedErrorMap, type Meta, type ORPCErrorFromErrorMap, type OutputStructure, type Route, type Schema, type SchemaInput, type SchemaOutput, type TypeRest, ValidationError, type ValidationErrorOptions, adaptContractRouter, adaptRoute, eventIterator, fallbackContractConfig, getEventIteratorSchemaDetails, isContractProcedure, mergeErrorMap, mergeMeta, mergePrefix, mergeRoute, mergeTags, oc, prefixRoute, type, unshiftTagRoute };
@@ -0,0 +1,233 @@
1
+ import { ORPCErrorCode, ORPCError, ClientContext, Client } from '@orpc/client';
2
+ export { ORPCError } from '@orpc/client';
3
+ import { StandardSchemaV1 } from '@standard-schema/spec';
4
+ import { Promisable, IsEqual } from '@orpc/shared';
5
+
6
+ type Schema = StandardSchemaV1 | undefined;
7
+ type SchemaInput<TSchema extends Schema, TFallback = unknown> = TSchema extends undefined ? TFallback : TSchema extends StandardSchemaV1 ? StandardSchemaV1.InferInput<TSchema> : TFallback;
8
+ type SchemaOutput<TSchema extends Schema, TFallback = unknown> = TSchema extends undefined ? TFallback : TSchema extends StandardSchemaV1 ? StandardSchemaV1.InferOutput<TSchema> : TFallback;
9
+ 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>): StandardSchemaV1<TInput, TOutput>;
11
+
12
+ interface ValidationErrorOptions extends ErrorOptions {
13
+ message: string;
14
+ issues: readonly StandardSchemaV1.Issue[];
15
+ }
16
+ declare class ValidationError extends Error {
17
+ readonly issues: readonly StandardSchemaV1.Issue[];
18
+ constructor(options: ValidationErrorOptions);
19
+ }
20
+ type ErrorMapItem<TDataSchema extends Schema> = {
21
+ status?: number;
22
+ message?: string;
23
+ description?: string;
24
+ data?: TDataSchema;
25
+ };
26
+ type ErrorMap = {
27
+ [key in ORPCErrorCode]?: ErrorMapItem<Schema>;
28
+ };
29
+ type MergedErrorMap<T1 extends ErrorMap, T2 extends ErrorMap> = Omit<T1, keyof T2> & T2;
30
+ declare function mergeErrorMap<T1 extends ErrorMap, T2 extends ErrorMap>(errorMap1: T1, errorMap2: T2): MergedErrorMap<T1, T2>;
31
+ type ORPCErrorFromErrorMap<TErrorMap extends ErrorMap> = {
32
+ [K in keyof TErrorMap]: K extends string ? TErrorMap[K] extends ErrorMapItem<infer TDataSchema> ? ORPCError<K, SchemaOutput<TDataSchema>> : never : never;
33
+ }[keyof TErrorMap];
34
+ type ErrorFromErrorMap<TErrorMap extends ErrorMap> = Error | ORPCErrorFromErrorMap<TErrorMap>;
35
+
36
+ type Meta = Record<string, any>;
37
+ declare function mergeMeta<T extends Meta>(meta1: T, meta2: T): T;
38
+
39
+ type HTTPPath = `/${string}`;
40
+ type HTTPMethod = 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH';
41
+ type InputStructure = 'compact' | 'detailed';
42
+ type OutputStructure = 'compact' | 'detailed';
43
+ interface Route {
44
+ method?: HTTPMethod;
45
+ path?: HTTPPath;
46
+ summary?: string;
47
+ description?: string;
48
+ deprecated?: boolean;
49
+ tags?: readonly string[];
50
+ /**
51
+ * The status code of the response when the procedure is successful.
52
+ *
53
+ * @default 200
54
+ */
55
+ successStatus?: number;
56
+ /**
57
+ * The description of the response when the procedure is successful.
58
+ *
59
+ * @default 'OK'
60
+ */
61
+ successDescription?: string;
62
+ /**
63
+ * Determines how the input should be structured based on `params`, `query`, `headers`, and `body`.
64
+ *
65
+ * @option 'compact'
66
+ * Combines `params` and either `query` or `body` (depending on the HTTP method) into a single object.
67
+ *
68
+ * @option 'detailed'
69
+ * Keeps each part of the request (`params`, `query`, `headers`, and `body`) as separate fields in the input object.
70
+ *
71
+ * Example:
72
+ * ```ts
73
+ * const input = {
74
+ * params: { id: 1 },
75
+ * query: { search: 'hello' },
76
+ * headers: { 'Content-Type': 'application/json' },
77
+ * body: { name: 'John' },
78
+ * }
79
+ * ```
80
+ *
81
+ * @default 'compact'
82
+ */
83
+ inputStructure?: InputStructure;
84
+ /**
85
+ * Determines how the response should be structured based on the output.
86
+ *
87
+ * @option 'compact'
88
+ * Includes only the body data, encoded directly in the response.
89
+ *
90
+ * @option 'detailed'
91
+ * Separates the output into `headers` and `body` fields.
92
+ * - `headers`: Custom headers to merge with the response headers.
93
+ * - `body`: The response data.
94
+ *
95
+ * Example:
96
+ * ```ts
97
+ * const output = {
98
+ * headers: { 'x-custom-header': 'value' },
99
+ * body: { message: 'Hello, world!' },
100
+ * };
101
+ * ```
102
+ *
103
+ * @default 'compact'
104
+ */
105
+ outputStructure?: OutputStructure;
106
+ }
107
+ declare function mergeRoute(a: Route, b: Route): Route;
108
+ declare function prefixRoute(route: Route, prefix: HTTPPath): Route;
109
+ declare function unshiftTagRoute(route: Route, tags: readonly string[]): Route;
110
+ declare function mergePrefix(a: HTTPPath | undefined, b: HTTPPath): HTTPPath;
111
+ declare function mergeTags(a: readonly string[] | undefined, b: readonly string[]): readonly string[];
112
+ interface AdaptRouteOptions {
113
+ prefix?: HTTPPath;
114
+ tags?: readonly string[];
115
+ }
116
+ declare function adaptRoute(route: Route, options: AdaptRouteOptions): Route;
117
+
118
+ interface ContractProcedureDef<TInputSchema extends Schema, TOutputSchema extends Schema, TErrorMap extends ErrorMap, TMeta extends Meta> {
119
+ meta: TMeta;
120
+ route: Route;
121
+ inputSchema: TInputSchema;
122
+ outputSchema: TOutputSchema;
123
+ errorMap: TErrorMap;
124
+ }
125
+ declare class ContractProcedure<TInputSchema extends Schema, TOutputSchema extends Schema, TErrorMap extends ErrorMap, TMeta extends Meta> {
126
+ '~orpc': ContractProcedureDef<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
127
+ constructor(def: ContractProcedureDef<TInputSchema, TOutputSchema, TErrorMap, TMeta>);
128
+ }
129
+ type AnyContractProcedure = ContractProcedure<any, any, any, any>;
130
+ declare function isContractProcedure(item: unknown): item is AnyContractProcedure;
131
+
132
+ type ContractRouter<TMeta extends Meta> = ContractProcedure<any, any, any, TMeta> | {
133
+ [k: string]: ContractRouter<TMeta>;
134
+ };
135
+ type AnyContractRouter = ContractRouter<any>;
136
+ type AdaptedContractRouter<TContract extends AnyContractRouter, TErrorMap extends ErrorMap> = {
137
+ [K in keyof TContract]: TContract[K] extends ContractProcedure<infer UInputSchema, infer UOutputSchema, infer UErrors, infer UMeta> ? ContractProcedure<UInputSchema, UOutputSchema, MergedErrorMap<TErrorMap, UErrors>, UMeta> : TContract[K] extends AnyContractRouter ? AdaptedContractRouter<TContract[K], TErrorMap> : never;
138
+ };
139
+ interface AdaptContractRouterOptions<TErrorMap extends ErrorMap> {
140
+ errorMap: TErrorMap;
141
+ prefix?: HTTPPath;
142
+ tags?: readonly string[];
143
+ }
144
+ declare function adaptContractRouter<TRouter extends ContractRouter<any>, TErrorMap extends ErrorMap>(contract: TRouter, options: AdaptContractRouterOptions<TErrorMap>): AdaptedContractRouter<TRouter, TErrorMap>;
145
+ type InferContractRouterInputs<T extends AnyContractRouter> = T extends ContractProcedure<infer UInputSchema, any, any, any> ? SchemaInput<UInputSchema> : {
146
+ [K in keyof T]: T[K] extends AnyContractRouter ? InferContractRouterInputs<T[K]> : never;
147
+ };
148
+ type InferContractRouterOutputs<T extends AnyContractRouter> = T extends ContractProcedure<any, infer UOutputSchema, any, any> ? SchemaOutput<UOutputSchema> : {
149
+ [K in keyof T]: T[K] extends AnyContractRouter ? InferContractRouterOutputs<T[K]> : never;
150
+ };
151
+ type ContractRouterToErrorMap<T extends AnyContractRouter> = T extends ContractProcedure<any, any, infer UErrorMap, any> ? UErrorMap : {
152
+ [K in keyof T]: T[K] extends AnyContractRouter ? ContractRouterToErrorMap<T[K]> : never;
153
+ }[keyof T];
154
+ type ContractRouterToMeta<T extends AnyContractRouter> = T extends ContractRouter<infer UMeta> ? UMeta : never;
155
+
156
+ interface ContractProcedureBuilder<TInputSchema extends Schema, TOutputSchema extends Schema, TErrorMap extends ErrorMap, TMeta extends Meta> extends ContractProcedure<TInputSchema, TOutputSchema, TErrorMap, TMeta> {
157
+ errors<U extends ErrorMap>(errors: U): ContractProcedureBuilder<TInputSchema, TOutputSchema, MergedErrorMap<TErrorMap, U>, TMeta>;
158
+ meta(meta: TMeta): ContractProcedureBuilder<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
159
+ route(route: Route): ContractProcedureBuilder<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
160
+ input<U extends Schema>(schema: U): ContractProcedureBuilderWithInput<U, TOutputSchema, TErrorMap, TMeta>;
161
+ output<U extends Schema>(schema: U): ContractProcedureBuilderWithOutput<TInputSchema, U, TErrorMap, TMeta>;
162
+ }
163
+ interface ContractProcedureBuilderWithInput<TInputSchema extends Schema, TOutputSchema extends Schema, TErrorMap extends ErrorMap, TMeta extends Meta> extends ContractProcedure<TInputSchema, TOutputSchema, TErrorMap, TMeta> {
164
+ errors<U extends ErrorMap>(errors: U): ContractProcedureBuilderWithInput<TInputSchema, TOutputSchema, MergedErrorMap<TErrorMap, U>, TMeta>;
165
+ meta(meta: TMeta): ContractProcedureBuilderWithInput<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
166
+ route(route: Route): ContractProcedureBuilderWithInput<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
167
+ output<U extends Schema>(schema: U): ContractProcedureBuilderWithInputOutput<TInputSchema, U, TErrorMap, TMeta>;
168
+ }
169
+ interface ContractProcedureBuilderWithOutput<TInputSchema extends Schema, TOutputSchema extends Schema, TErrorMap extends ErrorMap, TMeta extends Meta> extends ContractProcedure<TInputSchema, TOutputSchema, TErrorMap, TMeta> {
170
+ errors<U extends ErrorMap>(errors: U): ContractProcedureBuilderWithOutput<TInputSchema, TOutputSchema, MergedErrorMap<TErrorMap, U>, TMeta>;
171
+ meta(meta: TMeta): ContractProcedureBuilderWithOutput<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
172
+ route(route: Route): ContractProcedureBuilderWithOutput<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
173
+ input<U extends Schema>(schema: U): ContractProcedureBuilderWithInputOutput<U, TOutputSchema, TErrorMap, TMeta>;
174
+ }
175
+ interface ContractProcedureBuilderWithInputOutput<TInputSchema extends Schema, TOutputSchema extends Schema, TErrorMap extends ErrorMap, TMeta extends Meta> extends ContractProcedure<TInputSchema, TOutputSchema, TErrorMap, TMeta> {
176
+ errors<U extends ErrorMap>(errors: U): ContractProcedureBuilderWithInputOutput<TInputSchema, TOutputSchema, MergedErrorMap<TErrorMap, U>, TMeta>;
177
+ meta(meta: TMeta): ContractProcedureBuilderWithInputOutput<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
178
+ route(route: Route): ContractProcedureBuilderWithInputOutput<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
179
+ }
180
+ interface ContractRouterBuilder<TErrorMap extends ErrorMap, TMeta extends Meta> {
181
+ '~orpc': AdaptContractRouterOptions<TErrorMap>;
182
+ 'errors'<U extends ErrorMap>(errors: U): ContractRouterBuilder<MergedErrorMap<TErrorMap, U>, TMeta>;
183
+ 'prefix'(prefix: HTTPPath): ContractRouterBuilder<TErrorMap, TMeta>;
184
+ 'tag'(...tags: string[]): ContractRouterBuilder<TErrorMap, TMeta>;
185
+ 'router'<T extends ContractRouter<TMeta>>(router: T): AdaptedContractRouter<T, TErrorMap>;
186
+ }
187
+
188
+ interface ContractBuilderDef<TInputSchema extends Schema, TOutputSchema extends Schema, TErrorMap extends ErrorMap, TMeta extends Meta> extends ContractProcedureDef<TInputSchema, TOutputSchema, TErrorMap, TMeta>, AdaptContractRouterOptions<TErrorMap> {
189
+ }
190
+ declare class ContractBuilder<TInputSchema extends Schema, TOutputSchema extends Schema, TErrorMap extends ErrorMap, TMeta extends Meta> extends ContractProcedure<TInputSchema, TOutputSchema, TErrorMap, TMeta> {
191
+ '~orpc': ContractBuilderDef<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
192
+ constructor(def: ContractBuilderDef<TInputSchema, TOutputSchema, TErrorMap, TMeta>);
193
+ /**
194
+ * Reset initial meta
195
+ */
196
+ $meta<U extends Meta>(initialMeta: U): ContractBuilder<TInputSchema, TOutputSchema, TErrorMap, U>;
197
+ /**
198
+ * Reset initial route
199
+ */
200
+ $route(initialRoute: Route): ContractBuilder<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
201
+ errors<U extends ErrorMap>(errors: U): ContractBuilder<TInputSchema, TOutputSchema, MergedErrorMap<TErrorMap, U>, TMeta>;
202
+ meta(meta: TMeta): ContractProcedureBuilder<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
203
+ route(route: Route): ContractProcedureBuilder<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
204
+ input<U extends Schema>(schema: U): ContractProcedureBuilderWithInput<U, TOutputSchema, TErrorMap, TMeta>;
205
+ output<U extends Schema>(schema: U): ContractProcedureBuilderWithOutput<TInputSchema, U, TErrorMap, TMeta>;
206
+ prefix(prefix: HTTPPath): ContractRouterBuilder<TErrorMap, TMeta>;
207
+ tag(...tags: string[]): ContractRouterBuilder<TErrorMap, TMeta>;
208
+ router<T extends ContractRouter<TMeta>>(router: T): AdaptedContractRouter<T, TErrorMap>;
209
+ }
210
+ declare const oc: ContractBuilder<undefined, undefined, {}, {}>;
211
+
212
+ interface ContractConfig {
213
+ defaultMethod: HTTPMethod;
214
+ defaultSuccessStatus: number;
215
+ defaultSuccessDescription: string;
216
+ defaultInputStructure: InputStructure;
217
+ defaultOutputStructure: InputStructure;
218
+ }
219
+ declare function fallbackContractConfig<T extends keyof ContractConfig>(key: T, value: ContractConfig[T] | undefined): ContractConfig[T];
220
+
221
+ declare function eventIterator<TYieldIn, TYieldOut, TReturnIn = unknown, TReturnOut = unknown>(yields: StandardSchemaV1<TYieldIn, TYieldOut>, returns?: StandardSchemaV1<TReturnIn, TReturnOut>): StandardSchemaV1<AsyncIteratorObject<TYieldIn, TReturnIn, void>, AsyncIteratorObject<TYieldOut, TReturnOut, void>>;
222
+ declare function getEventIteratorSchemaDetails(schema: Schema): undefined | {
223
+ yields: Schema;
224
+ returns: Schema;
225
+ };
226
+
227
+ type ContractProcedureClient<TClientContext extends ClientContext, TInputSchema extends Schema, TOutputSchema extends Schema, TErrorMap extends ErrorMap> = Client<TClientContext, SchemaInput<TInputSchema>, SchemaOutput<TOutputSchema>, ErrorFromErrorMap<TErrorMap>>;
228
+
229
+ 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
+ [K in keyof TRouter]: TRouter[K] extends AnyContractRouter ? ContractRouterClient<TRouter[K], TClientContext> : never;
231
+ };
232
+
233
+ export { type AdaptContractRouterOptions, type AdaptRouteOptions, type AdaptedContractRouter, 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 ContractRouterToErrorMap, type ContractRouterToMeta, type ErrorFromErrorMap, type ErrorMap, type ErrorMapItem, type HTTPMethod, type HTTPPath, type InferContractRouterInputs, type InferContractRouterOutputs, type InputStructure, type MergedErrorMap, type Meta, type ORPCErrorFromErrorMap, type OutputStructure, type Route, type Schema, type SchemaInput, type SchemaOutput, type TypeRest, ValidationError, type ValidationErrorOptions, adaptContractRouter, adaptRoute, eventIterator, fallbackContractConfig, getEventIteratorSchemaDetails, isContractProcedure, mergeErrorMap, mergeMeta, mergePrefix, mergeRoute, mergeTags, oc, prefixRoute, type, unshiftTagRoute };
@@ -1,22 +1,23 @@
1
- // src/error.ts
2
- var ValidationError = class extends Error {
1
+ import { mapEventIterator, ORPCError } from '@orpc/client';
2
+ export { ORPCError } from '@orpc/client';
3
+ import { isAsyncIteratorObject } from '@orpc/shared';
4
+
5
+ class ValidationError extends Error {
3
6
  issues;
4
7
  constructor(options) {
5
8
  super(options.message, options);
6
9
  this.issues = options.issues;
7
10
  }
8
- };
11
+ }
9
12
  function mergeErrorMap(errorMap1, errorMap2) {
10
13
  return { ...errorMap1, ...errorMap2 };
11
14
  }
12
15
 
13
- // src/meta.ts
14
16
  function mergeMeta(meta1, meta2) {
15
17
  return { ...meta1, ...meta2 };
16
18
  }
17
19
 
18
- // src/procedure.ts
19
- var ContractProcedure = class {
20
+ class ContractProcedure {
20
21
  "~orpc";
21
22
  constructor(def) {
22
23
  if (def.route?.successStatus && (def.route.successStatus < 200 || def.route?.successStatus > 299)) {
@@ -27,7 +28,7 @@ var ContractProcedure = class {
27
28
  }
28
29
  this["~orpc"] = def;
29
30
  }
30
- };
31
+ }
31
32
  function isContractProcedure(item) {
32
33
  if (item instanceof ContractProcedure) {
33
34
  return true;
@@ -35,7 +36,6 @@ function isContractProcedure(item) {
35
36
  return (typeof item === "object" || typeof item === "function") && item !== null && "~orpc" in item && typeof item["~orpc"] === "object" && item["~orpc"] !== null && "inputSchema" in item["~orpc"] && "outputSchema" in item["~orpc"] && "errorMap" in item["~orpc"] && "route" in item["~orpc"] && "meta" in item["~orpc"];
36
37
  }
37
38
 
38
- // src/route.ts
39
39
  function mergeRoute(a, b) {
40
40
  return { ...a, ...b };
41
41
  }
@@ -71,7 +71,6 @@ function adaptRoute(route, options) {
71
71
  return router;
72
72
  }
73
73
 
74
- // src/router.ts
75
74
  function adaptContractRouter(contract, options) {
76
75
  if (isContractProcedure(contract)) {
77
76
  const adapted2 = new ContractProcedure({
@@ -88,8 +87,7 @@ function adaptContractRouter(contract, options) {
88
87
  return adapted;
89
88
  }
90
89
 
91
- // src/builder.ts
92
- var ContractBuilder = class _ContractBuilder extends ContractProcedure {
90
+ class ContractBuilder extends ContractProcedure {
93
91
  constructor(def) {
94
92
  super(def);
95
93
  this["~orpc"].prefix = def.prefix;
@@ -99,7 +97,7 @@ var ContractBuilder = class _ContractBuilder extends ContractProcedure {
99
97
  * Reset initial meta
100
98
  */
101
99
  $meta(initialMeta) {
102
- return new _ContractBuilder({
100
+ return new ContractBuilder({
103
101
  ...this["~orpc"],
104
102
  meta: initialMeta
105
103
  });
@@ -108,49 +106,49 @@ var ContractBuilder = class _ContractBuilder extends ContractProcedure {
108
106
  * Reset initial route
109
107
  */
110
108
  $route(initialRoute) {
111
- return new _ContractBuilder({
109
+ return new ContractBuilder({
112
110
  ...this["~orpc"],
113
111
  route: initialRoute
114
112
  });
115
113
  }
116
114
  errors(errors) {
117
- return new _ContractBuilder({
115
+ return new ContractBuilder({
118
116
  ...this["~orpc"],
119
117
  errorMap: mergeErrorMap(this["~orpc"].errorMap, errors)
120
118
  });
121
119
  }
122
120
  meta(meta) {
123
- return new _ContractBuilder({
121
+ return new ContractBuilder({
124
122
  ...this["~orpc"],
125
123
  meta: mergeMeta(this["~orpc"].meta, meta)
126
124
  });
127
125
  }
128
126
  route(route) {
129
- return new _ContractBuilder({
127
+ return new ContractBuilder({
130
128
  ...this["~orpc"],
131
129
  route: mergeRoute(this["~orpc"].route, route)
132
130
  });
133
131
  }
134
132
  input(schema) {
135
- return new _ContractBuilder({
133
+ return new ContractBuilder({
136
134
  ...this["~orpc"],
137
135
  inputSchema: schema
138
136
  });
139
137
  }
140
138
  output(schema) {
141
- return new _ContractBuilder({
139
+ return new ContractBuilder({
142
140
  ...this["~orpc"],
143
141
  outputSchema: schema
144
142
  });
145
143
  }
146
144
  prefix(prefix) {
147
- return new _ContractBuilder({
145
+ return new ContractBuilder({
148
146
  ...this["~orpc"],
149
147
  prefix: mergePrefix(this["~orpc"].prefix, prefix)
150
148
  });
151
149
  }
152
150
  tag(...tags) {
153
- return new _ContractBuilder({
151
+ return new ContractBuilder({
154
152
  ...this["~orpc"],
155
153
  tags: mergeTags(this["~orpc"].tags, tags)
156
154
  });
@@ -158,8 +156,8 @@ var ContractBuilder = class _ContractBuilder extends ContractProcedure {
158
156
  router(router) {
159
157
  return adaptContractRouter(router, this["~orpc"]);
160
158
  }
161
- };
162
- var oc = new ContractBuilder({
159
+ }
160
+ const oc = new ContractBuilder({
163
161
  errorMap: {},
164
162
  inputSchema: void 0,
165
163
  outputSchema: void 0,
@@ -167,8 +165,7 @@ var oc = new ContractBuilder({
167
165
  meta: {}
168
166
  });
169
167
 
170
- // src/config.ts
171
- var DEFAULT_CONFIG = {
168
+ const DEFAULT_CONFIG = {
172
169
  defaultMethod: "POST",
173
170
  defaultSuccessStatus: 200,
174
171
  defaultSuccessDescription: "OK",
@@ -182,10 +179,7 @@ function fallbackContractConfig(key, value) {
182
179
  return value;
183
180
  }
184
181
 
185
- // src/event-iterator.ts
186
- import { mapEventIterator, ORPCError } from "@orpc/client";
187
- import { isAsyncIteratorObject } from "@orpc/standard-server";
188
- var EVENT_ITERATOR_SCHEMA_SYMBOL = Symbol("ORPC_EVENT_ITERATOR_SCHEMA");
182
+ const EVENT_ITERATOR_SCHEMA_SYMBOL = Symbol("ORPC_EVENT_ITERATOR_SCHEMA");
189
183
  function eventIterator(yields, returns) {
190
184
  return {
191
185
  "~standard": {
@@ -228,7 +222,6 @@ function getEventIteratorSchemaDetails(schema) {
228
222
  return schema["~standard"][EVENT_ITERATOR_SCHEMA_SYMBOL];
229
223
  }
230
224
 
231
- // src/schema.ts
232
225
  function type(...[map]) {
233
226
  return {
234
227
  "~standard": {
@@ -244,27 +237,4 @@ function type(...[map]) {
244
237
  };
245
238
  }
246
239
 
247
- // src/index.ts
248
- import { ORPCError as ORPCError2 } from "@orpc/client";
249
- export {
250
- ContractBuilder,
251
- ContractProcedure,
252
- ORPCError2 as ORPCError,
253
- ValidationError,
254
- adaptContractRouter,
255
- adaptRoute,
256
- eventIterator,
257
- fallbackContractConfig,
258
- getEventIteratorSchemaDetails,
259
- isContractProcedure,
260
- mergeErrorMap,
261
- mergeMeta,
262
- mergePrefix,
263
- mergeRoute,
264
- mergeTags,
265
- oc,
266
- prefixRoute,
267
- type,
268
- unshiftTagRoute
269
- };
270
- //# sourceMappingURL=index.js.map
240
+ export { ContractBuilder, ContractProcedure, ValidationError, adaptContractRouter, adaptRoute, eventIterator, fallbackContractConfig, getEventIteratorSchemaDetails, isContractProcedure, mergeErrorMap, mergeMeta, mergePrefix, mergeRoute, mergeTags, 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.43.0",
4
+ "version": "0.44.0",
5
5
  "license": "MIT",
6
6
  "homepage": "https://orpc.unnoq.com",
7
7
  "repository": {
@@ -15,24 +15,19 @@
15
15
  ],
16
16
  "exports": {
17
17
  ".": {
18
- "types": "./dist/src/index.d.ts",
19
- "import": "./dist/index.js",
20
- "default": "./dist/index.js"
21
- },
22
- "./🔒/*": {
23
- "types": "./dist/src/*.d.ts"
18
+ "types": "./dist/index.d.mts",
19
+ "import": "./dist/index.mjs",
20
+ "default": "./dist/index.mjs"
24
21
  }
25
22
  },
26
23
  "files": [
27
- "!**/*.map",
28
- "!**/*.tsbuildinfo",
29
24
  "dist"
30
25
  ],
31
26
  "dependencies": {
32
27
  "@standard-schema/spec": "^1.0.0",
33
- "@orpc/client": "0.43.0",
34
- "@orpc/standard-server": "0.43.0",
35
- "@orpc/shared": "0.43.0"
28
+ "@orpc/shared": "0.44.0",
29
+ "@orpc/standard-server": "0.44.0",
30
+ "@orpc/client": "0.44.0"
36
31
  },
37
32
  "devDependencies": {
38
33
  "arktype": "2.0.0-rc.26",
@@ -40,7 +35,7 @@
40
35
  "zod": "^3.24.1"
41
36
  },
42
37
  "scripts": {
43
- "build": "tsup --clean --sourcemap --entry.index=src/index.ts --format=esm --onSuccess='tsc -b --noCheck'",
38
+ "build": "unbuild",
44
39
  "build:watch": "pnpm run build --watch",
45
40
  "type:check": "tsc -b"
46
41
  }
@@ -1,38 +0,0 @@
1
- import type { ErrorMap, MergedErrorMap } from './error';
2
- import type { Meta } from './meta';
3
- import type { ContractProcedure } from './procedure';
4
- import type { HTTPPath, Route } from './route';
5
- import type { AdaptContractRouterOptions, AdaptedContractRouter, ContractRouter } from './router';
6
- import type { Schema } from './schema';
7
- export interface ContractProcedureBuilder<TInputSchema extends Schema, TOutputSchema extends Schema, TErrorMap extends ErrorMap, TMeta extends Meta> extends ContractProcedure<TInputSchema, TOutputSchema, TErrorMap, TMeta> {
8
- errors<U extends ErrorMap>(errors: U): ContractProcedureBuilder<TInputSchema, TOutputSchema, MergedErrorMap<TErrorMap, U>, TMeta>;
9
- meta(meta: TMeta): ContractProcedureBuilder<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
10
- route(route: Route): ContractProcedureBuilder<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
11
- input<U extends Schema>(schema: U): ContractProcedureBuilderWithInput<U, TOutputSchema, TErrorMap, TMeta>;
12
- output<U extends Schema>(schema: U): ContractProcedureBuilderWithOutput<TInputSchema, U, TErrorMap, TMeta>;
13
- }
14
- export interface ContractProcedureBuilderWithInput<TInputSchema extends Schema, TOutputSchema extends Schema, TErrorMap extends ErrorMap, TMeta extends Meta> extends ContractProcedure<TInputSchema, TOutputSchema, TErrorMap, TMeta> {
15
- errors<U extends ErrorMap>(errors: U): ContractProcedureBuilderWithInput<TInputSchema, TOutputSchema, MergedErrorMap<TErrorMap, U>, TMeta>;
16
- meta(meta: TMeta): ContractProcedureBuilderWithInput<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
17
- route(route: Route): ContractProcedureBuilderWithInput<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
18
- output<U extends Schema>(schema: U): ContractProcedureBuilderWithInputOutput<TInputSchema, U, TErrorMap, TMeta>;
19
- }
20
- export interface ContractProcedureBuilderWithOutput<TInputSchema extends Schema, TOutputSchema extends Schema, TErrorMap extends ErrorMap, TMeta extends Meta> extends ContractProcedure<TInputSchema, TOutputSchema, TErrorMap, TMeta> {
21
- errors<U extends ErrorMap>(errors: U): ContractProcedureBuilderWithOutput<TInputSchema, TOutputSchema, MergedErrorMap<TErrorMap, U>, TMeta>;
22
- meta(meta: TMeta): ContractProcedureBuilderWithOutput<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
23
- route(route: Route): ContractProcedureBuilderWithOutput<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
24
- input<U extends Schema>(schema: U): ContractProcedureBuilderWithInputOutput<U, TOutputSchema, TErrorMap, TMeta>;
25
- }
26
- export interface ContractProcedureBuilderWithInputOutput<TInputSchema extends Schema, TOutputSchema extends Schema, TErrorMap extends ErrorMap, TMeta extends Meta> extends ContractProcedure<TInputSchema, TOutputSchema, TErrorMap, TMeta> {
27
- errors<U extends ErrorMap>(errors: U): ContractProcedureBuilderWithInputOutput<TInputSchema, TOutputSchema, MergedErrorMap<TErrorMap, U>, TMeta>;
28
- meta(meta: TMeta): ContractProcedureBuilderWithInputOutput<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
29
- route(route: Route): ContractProcedureBuilderWithInputOutput<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
30
- }
31
- export interface ContractRouterBuilder<TErrorMap extends ErrorMap, TMeta extends Meta> {
32
- '~orpc': AdaptContractRouterOptions<TErrorMap>;
33
- 'errors'<U extends ErrorMap>(errors: U): ContractRouterBuilder<MergedErrorMap<TErrorMap, U>, TMeta>;
34
- 'prefix'(prefix: HTTPPath): ContractRouterBuilder<TErrorMap, TMeta>;
35
- 'tag'(...tags: string[]): ContractRouterBuilder<TErrorMap, TMeta>;
36
- 'router'<T extends ContractRouter<TMeta>>(router: T): AdaptedContractRouter<T, TErrorMap>;
37
- }
38
- //# sourceMappingURL=builder-variants.d.ts.map
@@ -1,32 +0,0 @@
1
- import type { ContractProcedureBuilder, ContractProcedureBuilderWithInput, ContractProcedureBuilderWithOutput, ContractRouterBuilder } from './builder-variants';
2
- import type { ContractProcedureDef } from './procedure';
3
- import type { AdaptContractRouterOptions, AdaptedContractRouter, ContractRouter } from './router';
4
- import type { Schema } from './schema';
5
- import { type ErrorMap, type MergedErrorMap } from './error';
6
- import { type Meta } from './meta';
7
- import { ContractProcedure } from './procedure';
8
- import { type HTTPPath, type Route } from './route';
9
- export interface ContractBuilderDef<TInputSchema extends Schema, TOutputSchema extends Schema, TErrorMap extends ErrorMap, TMeta extends Meta> extends ContractProcedureDef<TInputSchema, TOutputSchema, TErrorMap, TMeta>, AdaptContractRouterOptions<TErrorMap> {
10
- }
11
- export declare class ContractBuilder<TInputSchema extends Schema, TOutputSchema extends Schema, TErrorMap extends ErrorMap, TMeta extends Meta> extends ContractProcedure<TInputSchema, TOutputSchema, TErrorMap, TMeta> {
12
- '~orpc': ContractBuilderDef<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
13
- constructor(def: ContractBuilderDef<TInputSchema, TOutputSchema, TErrorMap, TMeta>);
14
- /**
15
- * Reset initial meta
16
- */
17
- $meta<U extends Meta>(initialMeta: U): ContractBuilder<TInputSchema, TOutputSchema, TErrorMap, U>;
18
- /**
19
- * Reset initial route
20
- */
21
- $route(initialRoute: Route): ContractBuilder<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
22
- errors<U extends ErrorMap>(errors: U): ContractBuilder<TInputSchema, TOutputSchema, MergedErrorMap<TErrorMap, U>, TMeta>;
23
- meta(meta: TMeta): ContractProcedureBuilder<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
24
- route(route: Route): ContractProcedureBuilder<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
25
- input<U extends Schema>(schema: U): ContractProcedureBuilderWithInput<U, TOutputSchema, TErrorMap, TMeta>;
26
- output<U extends Schema>(schema: U): ContractProcedureBuilderWithOutput<TInputSchema, U, TErrorMap, TMeta>;
27
- prefix(prefix: HTTPPath): ContractRouterBuilder<TErrorMap, TMeta>;
28
- tag(...tags: string[]): ContractRouterBuilder<TErrorMap, TMeta>;
29
- router<T extends ContractRouter<TMeta>>(router: T): AdaptedContractRouter<T, TErrorMap>;
30
- }
31
- export declare const oc: ContractBuilder<undefined, undefined, {}, {}>;
32
- //# sourceMappingURL=builder.d.ts.map
@@ -1,10 +0,0 @@
1
- import type { HTTPMethod, InputStructure } from './route';
2
- export interface ContractConfig {
3
- defaultMethod: HTTPMethod;
4
- defaultSuccessStatus: number;
5
- defaultSuccessDescription: string;
6
- defaultInputStructure: InputStructure;
7
- defaultOutputStructure: InputStructure;
8
- }
9
- export declare function fallbackContractConfig<T extends keyof ContractConfig>(key: T, value: ContractConfig[T] | undefined): ContractConfig[T];
10
- //# sourceMappingURL=config.d.ts.map
@@ -1,27 +0,0 @@
1
- import type { ORPCError, ORPCErrorCode } from '@orpc/client';
2
- import type { StandardSchemaV1 } from '@standard-schema/spec';
3
- import type { Schema, SchemaOutput } from './schema';
4
- export interface ValidationErrorOptions extends ErrorOptions {
5
- message: string;
6
- issues: readonly StandardSchemaV1.Issue[];
7
- }
8
- export declare class ValidationError extends Error {
9
- readonly issues: readonly StandardSchemaV1.Issue[];
10
- constructor(options: ValidationErrorOptions);
11
- }
12
- export type ErrorMapItem<TDataSchema extends Schema> = {
13
- status?: number;
14
- message?: string;
15
- description?: string;
16
- data?: TDataSchema;
17
- };
18
- export type ErrorMap = {
19
- [key in ORPCErrorCode]?: ErrorMapItem<Schema>;
20
- };
21
- export type MergedErrorMap<T1 extends ErrorMap, T2 extends ErrorMap> = Omit<T1, keyof T2> & T2;
22
- export declare function mergeErrorMap<T1 extends ErrorMap, T2 extends ErrorMap>(errorMap1: T1, errorMap2: T2): MergedErrorMap<T1, T2>;
23
- export type ORPCErrorFromErrorMap<TErrorMap extends ErrorMap> = {
24
- [K in keyof TErrorMap]: K extends string ? TErrorMap[K] extends ErrorMapItem<infer TDataSchema> ? ORPCError<K, SchemaOutput<TDataSchema>> : never : never;
25
- }[keyof TErrorMap];
26
- export type ErrorFromErrorMap<TErrorMap extends ErrorMap> = Error | ORPCErrorFromErrorMap<TErrorMap>;
27
- //# sourceMappingURL=error.d.ts.map
@@ -1,8 +0,0 @@
1
- import type { StandardSchemaV1 } from '@standard-schema/spec';
2
- import type { Schema } from './schema';
3
- export declare function eventIterator<TYieldIn, TYieldOut, TReturnIn = unknown, TReturnOut = unknown>(yields: StandardSchemaV1<TYieldIn, TYieldOut>, returns?: StandardSchemaV1<TReturnIn, TReturnOut>): StandardSchemaV1<AsyncIteratorObject<TYieldIn, TReturnIn, void>, AsyncIteratorObject<TYieldOut, TReturnOut, void>>;
4
- export declare function getEventIteratorSchemaDetails(schema: Schema): undefined | {
5
- yields: Schema;
6
- returns: Schema;
7
- };
8
- //# sourceMappingURL=event-iterator.d.ts.map
@@ -1,15 +0,0 @@
1
- /** unnoq */
2
- export * from './builder';
3
- export * from './builder-variants';
4
- export * from './config';
5
- export * from './error';
6
- export * from './event-iterator';
7
- export * from './meta';
8
- export * from './procedure';
9
- export * from './procedure-client';
10
- export * from './route';
11
- export * from './router';
12
- export * from './router-client';
13
- export * from './schema';
14
- export { ORPCError } from '@orpc/client';
15
- //# sourceMappingURL=index.d.ts.map
@@ -1,3 +0,0 @@
1
- export type Meta = Record<string, any>;
2
- export declare function mergeMeta<T extends Meta>(meta1: T, meta2: T): T;
3
- //# sourceMappingURL=meta.d.ts.map
@@ -1,5 +0,0 @@
1
- import type { Client, ClientContext } from '@orpc/client';
2
- import type { ErrorFromErrorMap, ErrorMap } from './error';
3
- import type { Schema, SchemaInput, SchemaOutput } from './schema';
4
- export type ContractProcedureClient<TClientContext extends ClientContext, TInputSchema extends Schema, TOutputSchema extends Schema, TErrorMap extends ErrorMap> = Client<TClientContext, SchemaInput<TInputSchema>, SchemaOutput<TOutputSchema>, ErrorFromErrorMap<TErrorMap>>;
5
- //# sourceMappingURL=procedure-client.d.ts.map
@@ -1,18 +0,0 @@
1
- import type { ErrorMap } from './error';
2
- import type { Meta } from './meta';
3
- import type { Route } from './route';
4
- import type { Schema } from './schema';
5
- export interface ContractProcedureDef<TInputSchema extends Schema, TOutputSchema extends Schema, TErrorMap extends ErrorMap, TMeta extends Meta> {
6
- meta: TMeta;
7
- route: Route;
8
- inputSchema: TInputSchema;
9
- outputSchema: TOutputSchema;
10
- errorMap: TErrorMap;
11
- }
12
- export declare class ContractProcedure<TInputSchema extends Schema, TOutputSchema extends Schema, TErrorMap extends ErrorMap, TMeta extends Meta> {
13
- '~orpc': ContractProcedureDef<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
14
- constructor(def: ContractProcedureDef<TInputSchema, TOutputSchema, TErrorMap, TMeta>);
15
- }
16
- export type AnyContractProcedure = ContractProcedure<any, any, any, any>;
17
- export declare function isContractProcedure(item: unknown): item is AnyContractProcedure;
18
- //# sourceMappingURL=procedure.d.ts.map
@@ -1,79 +0,0 @@
1
- export type HTTPPath = `/${string}`;
2
- export type HTTPMethod = 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH';
3
- export type InputStructure = 'compact' | 'detailed';
4
- export type OutputStructure = 'compact' | 'detailed';
5
- export interface Route {
6
- method?: HTTPMethod;
7
- path?: HTTPPath;
8
- summary?: string;
9
- description?: string;
10
- deprecated?: boolean;
11
- tags?: readonly string[];
12
- /**
13
- * The status code of the response when the procedure is successful.
14
- *
15
- * @default 200
16
- */
17
- successStatus?: number;
18
- /**
19
- * The description of the response when the procedure is successful.
20
- *
21
- * @default 'OK'
22
- */
23
- successDescription?: string;
24
- /**
25
- * Determines how the input should be structured based on `params`, `query`, `headers`, and `body`.
26
- *
27
- * @option 'compact'
28
- * Combines `params` and either `query` or `body` (depending on the HTTP method) into a single object.
29
- *
30
- * @option 'detailed'
31
- * Keeps each part of the request (`params`, `query`, `headers`, and `body`) as separate fields in the input object.
32
- *
33
- * Example:
34
- * ```ts
35
- * const input = {
36
- * params: { id: 1 },
37
- * query: { search: 'hello' },
38
- * headers: { 'Content-Type': 'application/json' },
39
- * body: { name: 'John' },
40
- * }
41
- * ```
42
- *
43
- * @default 'compact'
44
- */
45
- inputStructure?: InputStructure;
46
- /**
47
- * Determines how the response should be structured based on the output.
48
- *
49
- * @option 'compact'
50
- * Includes only the body data, encoded directly in the response.
51
- *
52
- * @option 'detailed'
53
- * Separates the output into `headers` and `body` fields.
54
- * - `headers`: Custom headers to merge with the response headers.
55
- * - `body`: The response data.
56
- *
57
- * Example:
58
- * ```ts
59
- * const output = {
60
- * headers: { 'x-custom-header': 'value' },
61
- * body: { message: 'Hello, world!' },
62
- * };
63
- * ```
64
- *
65
- * @default 'compact'
66
- */
67
- outputStructure?: OutputStructure;
68
- }
69
- export declare function mergeRoute(a: Route, b: Route): Route;
70
- export declare function prefixRoute(route: Route, prefix: HTTPPath): Route;
71
- export declare function unshiftTagRoute(route: Route, tags: readonly string[]): Route;
72
- export declare function mergePrefix(a: HTTPPath | undefined, b: HTTPPath): HTTPPath;
73
- export declare function mergeTags(a: readonly string[] | undefined, b: readonly string[]): readonly string[];
74
- export interface AdaptRouteOptions {
75
- prefix?: HTTPPath;
76
- tags?: readonly string[];
77
- }
78
- export declare function adaptRoute(route: Route, options: AdaptRouteOptions): Route;
79
- //# sourceMappingURL=route.d.ts.map
@@ -1,8 +0,0 @@
1
- import type { ClientContext } from '@orpc/client';
2
- import type { ContractProcedure } from './procedure';
3
- import type { ContractProcedureClient } from './procedure-client';
4
- import type { AnyContractRouter } from './router';
5
- export 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> : {
6
- [K in keyof TRouter]: TRouter[K] extends AnyContractRouter ? ContractRouterClient<TRouter[K], TClientContext> : never;
7
- };
8
- //# sourceMappingURL=router-client.d.ts.map
@@ -1,29 +0,0 @@
1
- import type { Meta } from './meta';
2
- import type { SchemaInput, SchemaOutput } from './schema';
3
- import { type ErrorMap, type MergedErrorMap } from './error';
4
- import { ContractProcedure } from './procedure';
5
- import { type HTTPPath } from './route';
6
- export type ContractRouter<TMeta extends Meta> = ContractProcedure<any, any, any, TMeta> | {
7
- [k: string]: ContractRouter<TMeta>;
8
- };
9
- export type AnyContractRouter = ContractRouter<any>;
10
- export type AdaptedContractRouter<TContract extends AnyContractRouter, TErrorMap extends ErrorMap> = {
11
- [K in keyof TContract]: TContract[K] extends ContractProcedure<infer UInputSchema, infer UOutputSchema, infer UErrors, infer UMeta> ? ContractProcedure<UInputSchema, UOutputSchema, MergedErrorMap<TErrorMap, UErrors>, UMeta> : TContract[K] extends AnyContractRouter ? AdaptedContractRouter<TContract[K], TErrorMap> : never;
12
- };
13
- export interface AdaptContractRouterOptions<TErrorMap extends ErrorMap> {
14
- errorMap: TErrorMap;
15
- prefix?: HTTPPath;
16
- tags?: readonly string[];
17
- }
18
- export declare function adaptContractRouter<TRouter extends ContractRouter<any>, TErrorMap extends ErrorMap>(contract: TRouter, options: AdaptContractRouterOptions<TErrorMap>): AdaptedContractRouter<TRouter, TErrorMap>;
19
- export type InferContractRouterInputs<T extends AnyContractRouter> = T extends ContractProcedure<infer UInputSchema, any, any, any> ? SchemaInput<UInputSchema> : {
20
- [K in keyof T]: T[K] extends AnyContractRouter ? InferContractRouterInputs<T[K]> : never;
21
- };
22
- export type InferContractRouterOutputs<T extends AnyContractRouter> = T extends ContractProcedure<any, infer UOutputSchema, any, any> ? SchemaOutput<UOutputSchema> : {
23
- [K in keyof T]: T[K] extends AnyContractRouter ? InferContractRouterOutputs<T[K]> : never;
24
- };
25
- export type ContractRouterToErrorMap<T extends AnyContractRouter> = T extends ContractProcedure<any, any, infer UErrorMap, any> ? UErrorMap : {
26
- [K in keyof T]: T[K] extends AnyContractRouter ? ContractRouterToErrorMap<T[K]> : never;
27
- }[keyof T];
28
- export type ContractRouterToMeta<T extends AnyContractRouter> = T extends ContractRouter<infer UMeta> ? UMeta : never;
29
- //# sourceMappingURL=router.d.ts.map
@@ -1,8 +0,0 @@
1
- import type { IsEqual, Promisable } from '@orpc/shared';
2
- import type { StandardSchemaV1 } from '@standard-schema/spec';
3
- export type Schema = StandardSchemaV1 | undefined;
4
- export type SchemaInput<TSchema extends Schema, TFallback = unknown> = TSchema extends undefined ? TFallback : TSchema extends StandardSchemaV1 ? StandardSchemaV1.InferInput<TSchema> : TFallback;
5
- export type SchemaOutput<TSchema extends Schema, TFallback = unknown> = TSchema extends undefined ? TFallback : TSchema extends StandardSchemaV1 ? StandardSchemaV1.InferOutput<TSchema> : TFallback;
6
- export type TypeRest<TInput, TOutput> = [map: (input: TInput) => Promisable<TOutput>] | (IsEqual<TInput, TOutput> extends true ? [] : never);
7
- export declare function type<TInput, TOutput = TInput>(...[map]: TypeRest<TInput, TOutput>): StandardSchemaV1<TInput, TOutput>;
8
- //# sourceMappingURL=schema.d.ts.map