@orpc/contract 0.0.0-next.4a31e17 → 0.0.0-next.4e27480

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.js CHANGED
@@ -6,6 +6,9 @@ var ContractProcedure = class {
6
6
  if (def.route?.successStatus && (def.route.successStatus < 200 || def.route?.successStatus > 299)) {
7
7
  throw new Error("[ContractProcedure] The successStatus must be between 200 and 299");
8
8
  }
9
+ if (Object.values(def.errorMap ?? {}).some((val) => val && val.status && (val.status < 400 || val.status > 599))) {
10
+ throw new Error("[ContractProcedure] The error status code must be in the 400-599 range.");
11
+ }
9
12
  this["~orpc"] = def;
10
13
  }
11
14
  };
@@ -13,7 +16,7 @@ function isContractProcedure(item) {
13
16
  if (item instanceof ContractProcedure) {
14
17
  return true;
15
18
  }
16
- return (typeof item === "object" || typeof item === "function") && item !== null && "~type" in item && item["~type"] === "ContractProcedure" && "~orpc" in item && typeof item["~orpc"] === "object" && item["~orpc"] !== null && "InputSchema" in item["~orpc"] && "OutputSchema" in item["~orpc"];
19
+ return (typeof item === "object" || typeof item === "function") && item !== null && "~type" in item && item["~type"] === "ContractProcedure" && "~orpc" in item && typeof item["~orpc"] === "object" && item["~orpc"] !== null && "InputSchema" in item["~orpc"] && "OutputSchema" in item["~orpc"] && "errorMap" in item["~orpc"];
17
20
  }
18
21
 
19
22
  // src/procedure-decorated.ts
@@ -24,6 +27,15 @@ var DecoratedContractProcedure = class _DecoratedContractProcedure extends Contr
24
27
  }
25
28
  return new _DecoratedContractProcedure(procedure["~orpc"]);
26
29
  }
30
+ errors(errors) {
31
+ return new _DecoratedContractProcedure({
32
+ ...this["~orpc"],
33
+ errorMap: {
34
+ ...this["~orpc"].errorMap,
35
+ ...errors
36
+ }
37
+ });
38
+ }
27
39
  route(route) {
28
40
  return new _DecoratedContractProcedure({
29
41
  ...this["~orpc"],
@@ -56,15 +68,89 @@ var DecoratedContractProcedure = class _DecoratedContractProcedure extends Contr
56
68
  }
57
69
  });
58
70
  }
71
+ };
72
+
73
+ // src/procedure-builder-with-input.ts
74
+ var ContractProcedureBuilderWithInput = class _ContractProcedureBuilderWithInput extends ContractProcedure {
75
+ errors(errors) {
76
+ const decorated = DecoratedContractProcedure.decorate(this).errors(errors);
77
+ return new _ContractProcedureBuilderWithInput(decorated["~orpc"]);
78
+ }
79
+ route(route) {
80
+ const decorated = DecoratedContractProcedure.decorate(this).route(route);
81
+ return new _ContractProcedureBuilderWithInput(decorated["~orpc"]);
82
+ }
83
+ prefix(prefix) {
84
+ const decorated = DecoratedContractProcedure.decorate(this).prefix(prefix);
85
+ return new _ContractProcedureBuilderWithInput(decorated["~orpc"]);
86
+ }
87
+ unshiftTag(...tags) {
88
+ const decorated = DecoratedContractProcedure.decorate(this).unshiftTag(...tags);
89
+ return new _ContractProcedureBuilderWithInput(decorated["~orpc"]);
90
+ }
91
+ output(schema, example) {
92
+ return new DecoratedContractProcedure({
93
+ ...this["~orpc"],
94
+ OutputSchema: schema,
95
+ outputExample: example
96
+ });
97
+ }
98
+ };
99
+
100
+ // src/procedure-builder-with-output.ts
101
+ var ContractProcedureBuilderWithOutput = class _ContractProcedureBuilderWithOutput extends ContractProcedure {
102
+ errors(errors) {
103
+ const decorated = DecoratedContractProcedure.decorate(this).errors(errors);
104
+ return new _ContractProcedureBuilderWithOutput(decorated["~orpc"]);
105
+ }
106
+ route(route) {
107
+ const decorated = DecoratedContractProcedure.decorate(this).route(route);
108
+ return new _ContractProcedureBuilderWithOutput(decorated["~orpc"]);
109
+ }
110
+ prefix(prefix) {
111
+ const decorated = DecoratedContractProcedure.decorate(this).prefix(prefix);
112
+ return new _ContractProcedureBuilderWithOutput(decorated["~orpc"]);
113
+ }
114
+ unshiftTag(...tags) {
115
+ const decorated = DecoratedContractProcedure.decorate(this).unshiftTag(...tags);
116
+ return new _ContractProcedureBuilderWithOutput(decorated["~orpc"]);
117
+ }
59
118
  input(schema, example) {
60
- return new _DecoratedContractProcedure({
119
+ return new DecoratedContractProcedure({
120
+ ...this["~orpc"],
121
+ InputSchema: schema,
122
+ inputExample: example
123
+ });
124
+ }
125
+ };
126
+
127
+ // src/procedure-builder.ts
128
+ var ContractProcedureBuilder = class _ContractProcedureBuilder extends ContractProcedure {
129
+ errors(errors) {
130
+ const decorated = DecoratedContractProcedure.decorate(this).errors(errors);
131
+ return new _ContractProcedureBuilder(decorated["~orpc"]);
132
+ }
133
+ route(route) {
134
+ const decorated = DecoratedContractProcedure.decorate(this).route(route);
135
+ return new _ContractProcedureBuilder(decorated["~orpc"]);
136
+ }
137
+ prefix(prefix) {
138
+ const decorated = DecoratedContractProcedure.decorate(this).prefix(prefix);
139
+ return new _ContractProcedureBuilder(decorated["~orpc"]);
140
+ }
141
+ unshiftTag(...tags) {
142
+ const decorated = DecoratedContractProcedure.decorate(this).unshiftTag(...tags);
143
+ return new _ContractProcedureBuilder(decorated["~orpc"]);
144
+ }
145
+ input(schema, example) {
146
+ return new ContractProcedureBuilderWithInput({
61
147
  ...this["~orpc"],
62
148
  InputSchema: schema,
63
149
  inputExample: example
64
150
  });
65
151
  }
66
152
  output(schema, example) {
67
- return new _DecoratedContractProcedure({
153
+ return new ContractProcedureBuilderWithOutput({
68
154
  ...this["~orpc"],
69
155
  OutputSchema: schema,
70
156
  outputExample: example
@@ -91,6 +177,15 @@ var ContractRouterBuilder = class _ContractRouterBuilder {
91
177
  tags: [...this["~orpc"].tags ?? [], ...tags]
92
178
  });
93
179
  }
180
+ errors(errors) {
181
+ return new _ContractRouterBuilder({
182
+ ...this["~orpc"],
183
+ errorMap: {
184
+ ...this["~orpc"].errorMap,
185
+ ...errors
186
+ }
187
+ });
188
+ }
94
189
  router(router) {
95
190
  if (isContractProcedure(router)) {
96
191
  let decorated = DecoratedContractProcedure.decorate(router);
@@ -100,6 +195,7 @@ var ContractRouterBuilder = class _ContractRouterBuilder {
100
195
  if (this["~orpc"].prefix) {
101
196
  decorated = decorated.prefix(this["~orpc"].prefix);
102
197
  }
198
+ decorated = decorated.errors(this["~orpc"].errorMap);
103
199
  return decorated;
104
200
  }
105
201
  const adapted = {};
@@ -111,42 +207,230 @@ var ContractRouterBuilder = class _ContractRouterBuilder {
111
207
  };
112
208
 
113
209
  // src/builder.ts
114
- var ContractBuilder = class {
115
- prefix(prefix) {
116
- return new ContractRouterBuilder({
117
- prefix
210
+ var ContractBuilder = class _ContractBuilder extends ContractProcedure {
211
+ constructor(def) {
212
+ super(def);
213
+ }
214
+ config(config) {
215
+ return new _ContractBuilder({
216
+ ...this["~orpc"],
217
+ config: {
218
+ ...this["~orpc"].config,
219
+ ...config
220
+ }
118
221
  });
119
222
  }
120
- tag(...tags) {
121
- return new ContractRouterBuilder({
122
- tags
223
+ errors(errors) {
224
+ return new _ContractBuilder({
225
+ ...this["~orpc"],
226
+ errorMap: {
227
+ ...this["~orpc"].errorMap,
228
+ ...errors
229
+ }
123
230
  });
124
231
  }
125
232
  route(route) {
126
- return new DecoratedContractProcedure({
127
- route,
233
+ return new ContractProcedureBuilder({
234
+ route: {
235
+ ...this["~orpc"].config.initialRoute,
236
+ ...route
237
+ },
128
238
  InputSchema: void 0,
129
- OutputSchema: void 0
239
+ OutputSchema: void 0,
240
+ errorMap: this["~orpc"].errorMap
130
241
  });
131
242
  }
132
243
  input(schema, example) {
133
- return new DecoratedContractProcedure({
244
+ return new ContractProcedureBuilderWithInput({
245
+ route: this["~orpc"].config.initialRoute,
134
246
  InputSchema: schema,
135
247
  inputExample: example,
136
- OutputSchema: void 0
248
+ OutputSchema: void 0,
249
+ errorMap: this["~orpc"].errorMap
137
250
  });
138
251
  }
139
252
  output(schema, example) {
140
- return new DecoratedContractProcedure({
253
+ return new ContractProcedureBuilderWithOutput({
254
+ route: this["~orpc"].config.initialRoute,
141
255
  OutputSchema: schema,
142
256
  outputExample: example,
143
- InputSchema: void 0
257
+ InputSchema: void 0,
258
+ errorMap: this["~orpc"].errorMap
259
+ });
260
+ }
261
+ prefix(prefix) {
262
+ return new ContractRouterBuilder({
263
+ prefix,
264
+ errorMap: this["~orpc"].errorMap
265
+ });
266
+ }
267
+ tag(...tags) {
268
+ return new ContractRouterBuilder({
269
+ tags,
270
+ errorMap: this["~orpc"].errorMap
144
271
  });
145
272
  }
146
273
  router(router) {
147
- return router;
274
+ return new ContractRouterBuilder({
275
+ errorMap: this["~orpc"].errorMap
276
+ }).router(router);
277
+ }
278
+ };
279
+
280
+ // src/error-orpc.ts
281
+ import { isPlainObject } from "@orpc/shared";
282
+ var COMMON_ORPC_ERROR_DEFS = {
283
+ BAD_REQUEST: {
284
+ status: 400,
285
+ message: "Bad Request"
286
+ },
287
+ UNAUTHORIZED: {
288
+ status: 401,
289
+ message: "Unauthorized"
290
+ },
291
+ FORBIDDEN: {
292
+ status: 403,
293
+ message: "Forbidden"
294
+ },
295
+ NOT_FOUND: {
296
+ status: 404,
297
+ message: "Not Found"
298
+ },
299
+ METHOD_NOT_SUPPORTED: {
300
+ status: 405,
301
+ message: "Method Not Supported"
302
+ },
303
+ NOT_ACCEPTABLE: {
304
+ status: 406,
305
+ message: "Not Acceptable"
306
+ },
307
+ TIMEOUT: {
308
+ status: 408,
309
+ message: "Request Timeout"
310
+ },
311
+ CONFLICT: {
312
+ status: 409,
313
+ message: "Conflict"
314
+ },
315
+ PRECONDITION_FAILED: {
316
+ status: 412,
317
+ message: "Precondition Failed"
318
+ },
319
+ PAYLOAD_TOO_LARGE: {
320
+ status: 413,
321
+ message: "Payload Too Large"
322
+ },
323
+ UNSUPPORTED_MEDIA_TYPE: {
324
+ status: 415,
325
+ message: "Unsupported Media Type"
326
+ },
327
+ UNPROCESSABLE_CONTENT: {
328
+ status: 422,
329
+ message: "Unprocessable Content"
330
+ },
331
+ TOO_MANY_REQUESTS: {
332
+ status: 429,
333
+ message: "Too Many Requests"
334
+ },
335
+ CLIENT_CLOSED_REQUEST: {
336
+ status: 499,
337
+ message: "Client Closed Request"
338
+ },
339
+ INTERNAL_SERVER_ERROR: {
340
+ status: 500,
341
+ message: "Internal Server Error"
342
+ },
343
+ NOT_IMPLEMENTED: {
344
+ status: 501,
345
+ message: "Not Implemented"
346
+ },
347
+ BAD_GATEWAY: {
348
+ status: 502,
349
+ message: "Bad Gateway"
350
+ },
351
+ SERVICE_UNAVAILABLE: {
352
+ status: 503,
353
+ message: "Service Unavailable"
354
+ },
355
+ GATEWAY_TIMEOUT: {
356
+ status: 504,
357
+ message: "Gateway Timeout"
148
358
  }
149
359
  };
360
+ function fallbackORPCErrorStatus(code, status) {
361
+ return status ?? COMMON_ORPC_ERROR_DEFS[code]?.status ?? 500;
362
+ }
363
+ function fallbackORPCErrorMessage(code, message) {
364
+ return message || COMMON_ORPC_ERROR_DEFS[code]?.message || code;
365
+ }
366
+ var ORPCError = class extends Error {
367
+ defined;
368
+ code;
369
+ status;
370
+ data;
371
+ constructor(options) {
372
+ if (options.status && (options.status < 400 || options.status >= 600)) {
373
+ throw new Error("[ORPCError] The error status code must be in the 400-599 range.");
374
+ }
375
+ const message = fallbackORPCErrorMessage(options.code, options.message);
376
+ super(message, options);
377
+ this.code = options.code;
378
+ this.status = fallbackORPCErrorStatus(options.code, options.status);
379
+ this.defined = options.defined ?? false;
380
+ this.data = options.data;
381
+ }
382
+ toJSON() {
383
+ return {
384
+ defined: this.defined,
385
+ code: this.code,
386
+ status: this.status,
387
+ message: this.message,
388
+ data: this.data
389
+ };
390
+ }
391
+ static isValidJSON(json) {
392
+ return isPlainObject(json) && "defined" in json && typeof json.defined === "boolean" && "code" in json && typeof json.code === "string" && "status" in json && typeof json.status === "number" && "message" in json && typeof json.message === "string";
393
+ }
394
+ };
395
+ function isDefinedError(error) {
396
+ return error instanceof ORPCError && error.defined;
397
+ }
398
+ async function validateORPCError(map, error) {
399
+ const { code, status, message, data, cause, defined } = error;
400
+ const config = map?.[error.code];
401
+ if (!config || fallbackORPCErrorStatus(error.code, config.status) !== error.status) {
402
+ return defined ? new ORPCError({ defined: false, code, status, message, data, cause }) : error;
403
+ }
404
+ if (!config.data) {
405
+ return defined ? error : new ORPCError({ defined: true, code, status, message, data, cause });
406
+ }
407
+ const validated = await config.data["~standard"].validate(error.data);
408
+ if (validated.issues) {
409
+ return defined ? new ORPCError({ defined: false, code, status, message, data, cause }) : error;
410
+ }
411
+ return new ORPCError({
412
+ defined: true,
413
+ code,
414
+ status,
415
+ message,
416
+ data: validated.value,
417
+ cause
418
+ });
419
+ }
420
+
421
+ // src/client-utils.ts
422
+ async function safe(promise) {
423
+ try {
424
+ const output = await promise;
425
+ return [output, void 0, false];
426
+ } catch (e) {
427
+ const error = e;
428
+ if (isDefinedError(error)) {
429
+ return [void 0, error, true];
430
+ }
431
+ return [void 0, error, false];
432
+ }
433
+ }
150
434
 
151
435
  // src/config.ts
152
436
  var DEFAULT_CONFIG = {
@@ -156,34 +440,64 @@ var DEFAULT_CONFIG = {
156
440
  defaultInputStructure: "compact",
157
441
  defaultOutputStructure: "compact"
158
442
  };
159
- var GLOBAL_CONFIG_REF = { value: DEFAULT_CONFIG };
160
- function configGlobal(config) {
161
- if (config.defaultSuccessStatus !== void 0 && (config.defaultSuccessStatus < 200 || config.defaultSuccessStatus > 299)) {
162
- throw new Error("[configGlobal] The defaultSuccessStatus must be between 200 and 299");
163
- }
164
- GLOBAL_CONFIG_REF.value = config;
165
- }
166
- function fallbackToGlobalConfig(key, value) {
443
+ function fallbackContractConfig(key, value) {
167
444
  if (value === void 0) {
168
- const fallback = GLOBAL_CONFIG_REF.value[key];
169
- if (fallback === void 0) {
170
- return DEFAULT_CONFIG[key];
171
- }
172
- return fallback;
445
+ return DEFAULT_CONFIG[key];
173
446
  }
174
447
  return value;
175
448
  }
176
449
 
450
+ // src/error.ts
451
+ var ValidationError = class extends Error {
452
+ issues;
453
+ constructor(options) {
454
+ super(options.message, options);
455
+ this.issues = options.issues;
456
+ }
457
+ };
458
+
459
+ // src/schema-utils.ts
460
+ function type(...[map]) {
461
+ return {
462
+ "~standard": {
463
+ vendor: "custom",
464
+ version: 1,
465
+ async validate(value) {
466
+ if (map) {
467
+ return { value: await map(value) };
468
+ }
469
+ return { value };
470
+ }
471
+ }
472
+ };
473
+ }
474
+
177
475
  // src/index.ts
178
- var oc = new ContractBuilder();
476
+ var oc = new ContractBuilder({
477
+ errorMap: {},
478
+ InputSchema: void 0,
479
+ OutputSchema: void 0,
480
+ config: {}
481
+ });
179
482
  export {
483
+ COMMON_ORPC_ERROR_DEFS,
180
484
  ContractBuilder,
181
485
  ContractProcedure,
486
+ ContractProcedureBuilder,
487
+ ContractProcedureBuilderWithInput,
488
+ ContractProcedureBuilderWithOutput,
182
489
  ContractRouterBuilder,
183
490
  DecoratedContractProcedure,
184
- configGlobal,
185
- fallbackToGlobalConfig,
491
+ ORPCError,
492
+ ValidationError,
493
+ fallbackContractConfig,
494
+ fallbackORPCErrorMessage,
495
+ fallbackORPCErrorStatus,
186
496
  isContractProcedure,
187
- oc
497
+ isDefinedError,
498
+ oc,
499
+ safe,
500
+ type,
501
+ validateORPCError
188
502
  };
189
503
  //# sourceMappingURL=index.js.map
@@ -1,14 +1,29 @@
1
- import type { RouteOptions } from './procedure';
1
+ import type { ErrorMap, ErrorMapGuard, ErrorMapSuggestions, StrictErrorMap } from './error-map';
2
+ import type { ContractProcedureDef, RouteOptions } from './procedure';
2
3
  import type { ContractRouter } from './router';
4
+ import type { AdaptedContractRouter } from './router-builder';
3
5
  import type { HTTPPath, Schema, SchemaInput, SchemaOutput } from './types';
4
- import { DecoratedContractProcedure } from './procedure-decorated';
6
+ import { ContractProcedure } from './procedure';
7
+ import { ContractProcedureBuilder } from './procedure-builder';
8
+ import { ContractProcedureBuilderWithInput } from './procedure-builder-with-input';
9
+ import { ContractProcedureBuilderWithOutput } from './procedure-builder-with-output';
5
10
  import { ContractRouterBuilder } from './router-builder';
6
- export declare class ContractBuilder {
7
- prefix(prefix: HTTPPath): ContractRouterBuilder;
8
- tag(...tags: string[]): ContractRouterBuilder;
9
- route(route: RouteOptions): DecoratedContractProcedure<undefined, undefined>;
10
- input<U extends Schema = undefined>(schema: U, example?: SchemaInput<U>): DecoratedContractProcedure<U, undefined>;
11
- output<U extends Schema = undefined>(schema: U, example?: SchemaOutput<U>): DecoratedContractProcedure<undefined, U>;
12
- router<T extends ContractRouter>(router: T): T;
11
+ export interface ContractBuilderConfig {
12
+ initialRoute?: RouteOptions;
13
+ }
14
+ export interface ContractBuilderDef<TErrorMap extends ErrorMap> extends ContractProcedureDef<undefined, undefined, TErrorMap> {
15
+ config: ContractBuilderConfig;
16
+ }
17
+ export declare class ContractBuilder<TErrorMap extends ErrorMap> extends ContractProcedure<undefined, undefined, TErrorMap> {
18
+ '~orpc': ContractBuilderDef<TErrorMap>;
19
+ constructor(def: ContractBuilderDef<TErrorMap>);
20
+ config(config: ContractBuilderConfig): ContractBuilder<TErrorMap>;
21
+ errors<const U extends ErrorMap & ErrorMapGuard<TErrorMap> & ErrorMapSuggestions>(errors: U): ContractBuilder<U & TErrorMap>;
22
+ route(route: RouteOptions): ContractProcedureBuilder<TErrorMap>;
23
+ input<U extends Schema>(schema: U, example?: SchemaInput<U>): ContractProcedureBuilderWithInput<U, TErrorMap>;
24
+ output<U extends Schema>(schema: U, example?: SchemaOutput<U>): ContractProcedureBuilderWithOutput<U, TErrorMap>;
25
+ prefix(prefix: HTTPPath): ContractRouterBuilder<TErrorMap>;
26
+ tag(...tags: string[]): ContractRouterBuilder<TErrorMap>;
27
+ router<T extends ContractRouter<ErrorMap & Partial<StrictErrorMap<TErrorMap>>>>(router: T): AdaptedContractRouter<T, TErrorMap>;
13
28
  }
14
29
  //# sourceMappingURL=builder.d.ts.map
@@ -0,0 +1,5 @@
1
+ import type { ClientPromiseResult } from './client';
2
+ import { type ORPCError } from './error-orpc';
3
+ export type SafeResult<TOutput, TError extends Error> = [output: TOutput, error: undefined, isDefinedError: false] | [output: undefined, error: TError, isDefinedError: false] | [output: undefined, error: Extract<TError, ORPCError<any, any>>, isDefinedError: true];
4
+ export declare function safe<TOutput, TError extends Error>(promise: ClientPromiseResult<TOutput, TError>): Promise<SafeResult<TOutput, TError>>;
5
+ //# sourceMappingURL=client-utils.d.ts.map
@@ -0,0 +1,19 @@
1
+ import type { AbortSignal } from './types';
2
+ export type ClientOptions<TClientContext> = {
3
+ signal?: AbortSignal;
4
+ } & (undefined extends TClientContext ? {
5
+ context?: TClientContext;
6
+ } : {
7
+ context: TClientContext;
8
+ });
9
+ export type ClientRest<TClientContext, TInput> = [input: TInput, options: ClientOptions<TClientContext>] | (undefined extends TInput & TClientContext ? [] : never) | (undefined extends TClientContext ? [input: TInput] : never);
10
+ export type ClientPromiseResult<TOutput, TError extends Error> = Promise<TOutput> & {
11
+ __typeError?: TError;
12
+ };
13
+ export interface Client<TClientContext, TInput, TOutput, TError extends Error> {
14
+ (...rest: ClientRest<TClientContext, TInput>): ClientPromiseResult<TOutput, TError>;
15
+ }
16
+ export type NestedClient<TClientContext> = Client<TClientContext, any, any, any> | {
17
+ [k: string]: NestedClient<TClientContext>;
18
+ };
19
+ //# sourceMappingURL=client.d.ts.map
@@ -1,36 +1,10 @@
1
1
  import type { HTTPMethod, InputStructure } from './types';
2
- export interface ORPCConfig {
3
- /**
4
- * @default 'POST'
5
- */
6
- defaultMethod?: HTTPMethod;
7
- /**
8
- *
9
- * @default 200
10
- */
11
- defaultSuccessStatus?: number;
12
- /**
13
- *
14
- * @default 'OK'
15
- */
16
- defaultSuccessDescription?: string;
17
- /**
18
- *
19
- * @default 'compact'
20
- */
21
- defaultInputStructure?: InputStructure;
22
- /**
23
- *
24
- * @default 'compact'
25
- */
26
- defaultOutputStructure?: InputStructure;
2
+ export interface ContractConfig {
3
+ defaultMethod: HTTPMethod;
4
+ defaultSuccessStatus: number;
5
+ defaultSuccessDescription: string;
6
+ defaultInputStructure: InputStructure;
7
+ defaultOutputStructure: InputStructure;
27
8
  }
28
- /**
29
- * Set the global configuration, this configuration can effect entire project
30
- */
31
- export declare function configGlobal(config: ORPCConfig): void;
32
- /**
33
- * Fallback the value to the global config if it is undefined
34
- */
35
- export declare function fallbackToGlobalConfig<T extends keyof ORPCConfig>(key: T, value: ORPCConfig[T]): Exclude<ORPCConfig[T], undefined>;
9
+ export declare function fallbackContractConfig<T extends keyof ContractConfig>(key: T, value: ContractConfig[T] | undefined): ContractConfig[T];
36
10
  //# sourceMappingURL=config.d.ts.map
@@ -0,0 +1,58 @@
1
+ import type { CommonORPCErrorCode } from './error-orpc';
2
+ import type { Schema } from './types';
3
+ export type ErrorMapItem<TDataSchema extends Schema> = {
4
+ /**
5
+ *
6
+ * @default 500
7
+ */
8
+ status?: number;
9
+ message?: string;
10
+ description?: string;
11
+ data?: TDataSchema;
12
+ };
13
+ export interface ErrorMap {
14
+ [k: string]: ErrorMapItem<Schema>;
15
+ }
16
+ /**
17
+ * const U extends ErrorMap & ErrorMapGuard<TErrorMap> & ErrorMapSuggestions
18
+ *
19
+ * Purpose:
20
+ * - Helps `U` suggest `CommonORPCErrorCode` to the user when typing.
21
+ *
22
+ * Why not replace `ErrorMap` with `ErrorMapSuggestions`?
23
+ * - `ErrorMapSuggestions` has a drawback: it allows `undefined` values for items.
24
+ * - `ErrorMapGuard<TErrorMap>` uses `Partial`, which can introduce `undefined` values.
25
+ *
26
+ * This could lead to unintended behavior where `undefined` values override `TErrorMap`,
27
+ * potentially resulting in a `never` type after merging.
28
+ *
29
+ * Recommendation:
30
+ * - Use `ErrorMapSuggestions` to assist users in typing correctly but do not replace `ErrorMap`.
31
+ * - Ensure `ErrorMapGuard<TErrorMap>` is adjusted to prevent `undefined` values.
32
+ */
33
+ export type ErrorMapSuggestions = {
34
+ [key in CommonORPCErrorCode | (string & {})]?: ErrorMapItem<Schema>;
35
+ };
36
+ /**
37
+ * `U` extends `ErrorMap` & `ErrorMapGuard<TErrorMap>`
38
+ *
39
+ * `ErrorMapGuard` is a utility type that ensures `U` cannot redefine the structure of `TErrorMap`.
40
+ * It achieves this by setting each key in `TErrorMap` to `never`, effectively preventing any redefinition.
41
+ *
42
+ * Why not just use `Partial<TErrorMap>`?
43
+ * - Allowing users to redefine existing error map items would require using `StrictErrorMap`.
44
+ * - However, I prefer not to use `StrictErrorMap` frequently, due to perceived performance concerns,
45
+ * though this has not been benchmarked and is based on personal preference.
46
+ *
47
+ */
48
+ export type ErrorMapGuard<TErrorMap extends ErrorMap> = {
49
+ [K in keyof TErrorMap]?: never;
50
+ };
51
+ /**
52
+ * Since `undefined` has a specific meaning (it use default value),
53
+ * we ensure all additional properties in each item of the ErrorMap are explicitly set to `undefined`.
54
+ */
55
+ export type StrictErrorMap<T extends ErrorMap> = {
56
+ [K in keyof T]: T[K] & Partial<Record<Exclude<keyof ErrorMapItem<any>, keyof T[K]>, undefined>>;
57
+ };
58
+ //# sourceMappingURL=error-map.d.ts.map
@@ -0,0 +1,109 @@
1
+ import type { ErrorMap, ErrorMapItem } from './error-map';
2
+ import type { SchemaOutput } from './types';
3
+ export type ORPCErrorFromErrorMap<TErrorMap extends ErrorMap> = {
4
+ [K in keyof TErrorMap]: K extends string ? TErrorMap[K] extends ErrorMapItem<infer TDataSchema> ? ORPCError<K, SchemaOutput<TDataSchema>> : never : never;
5
+ }[keyof TErrorMap];
6
+ export declare const COMMON_ORPC_ERROR_DEFS: {
7
+ readonly BAD_REQUEST: {
8
+ readonly status: 400;
9
+ readonly message: "Bad Request";
10
+ };
11
+ readonly UNAUTHORIZED: {
12
+ readonly status: 401;
13
+ readonly message: "Unauthorized";
14
+ };
15
+ readonly FORBIDDEN: {
16
+ readonly status: 403;
17
+ readonly message: "Forbidden";
18
+ };
19
+ readonly NOT_FOUND: {
20
+ readonly status: 404;
21
+ readonly message: "Not Found";
22
+ };
23
+ readonly METHOD_NOT_SUPPORTED: {
24
+ readonly status: 405;
25
+ readonly message: "Method Not Supported";
26
+ };
27
+ readonly NOT_ACCEPTABLE: {
28
+ readonly status: 406;
29
+ readonly message: "Not Acceptable";
30
+ };
31
+ readonly TIMEOUT: {
32
+ readonly status: 408;
33
+ readonly message: "Request Timeout";
34
+ };
35
+ readonly CONFLICT: {
36
+ readonly status: 409;
37
+ readonly message: "Conflict";
38
+ };
39
+ readonly PRECONDITION_FAILED: {
40
+ readonly status: 412;
41
+ readonly message: "Precondition Failed";
42
+ };
43
+ readonly PAYLOAD_TOO_LARGE: {
44
+ readonly status: 413;
45
+ readonly message: "Payload Too Large";
46
+ };
47
+ readonly UNSUPPORTED_MEDIA_TYPE: {
48
+ readonly status: 415;
49
+ readonly message: "Unsupported Media Type";
50
+ };
51
+ readonly UNPROCESSABLE_CONTENT: {
52
+ readonly status: 422;
53
+ readonly message: "Unprocessable Content";
54
+ };
55
+ readonly TOO_MANY_REQUESTS: {
56
+ readonly status: 429;
57
+ readonly message: "Too Many Requests";
58
+ };
59
+ readonly CLIENT_CLOSED_REQUEST: {
60
+ readonly status: 499;
61
+ readonly message: "Client Closed Request";
62
+ };
63
+ readonly INTERNAL_SERVER_ERROR: {
64
+ readonly status: 500;
65
+ readonly message: "Internal Server Error";
66
+ };
67
+ readonly NOT_IMPLEMENTED: {
68
+ readonly status: 501;
69
+ readonly message: "Not Implemented";
70
+ };
71
+ readonly BAD_GATEWAY: {
72
+ readonly status: 502;
73
+ readonly message: "Bad Gateway";
74
+ };
75
+ readonly SERVICE_UNAVAILABLE: {
76
+ readonly status: 503;
77
+ readonly message: "Service Unavailable";
78
+ };
79
+ readonly GATEWAY_TIMEOUT: {
80
+ readonly status: 504;
81
+ readonly message: "Gateway Timeout";
82
+ };
83
+ };
84
+ export type CommonORPCErrorCode = keyof typeof COMMON_ORPC_ERROR_DEFS;
85
+ export type ORPCErrorOptions<TCode extends string, TData> = ErrorOptions & {
86
+ defined?: boolean;
87
+ code: TCode;
88
+ status?: number;
89
+ message?: string;
90
+ } & (undefined extends TData ? {
91
+ data?: TData;
92
+ } : {
93
+ data: TData;
94
+ });
95
+ export declare function fallbackORPCErrorStatus(code: CommonORPCErrorCode | (string & {}), status: number | undefined): number;
96
+ export declare function fallbackORPCErrorMessage(code: CommonORPCErrorCode | (string & {}), message: string | undefined): string;
97
+ export declare class ORPCError<TCode extends CommonORPCErrorCode | (string & {}), TData> extends Error {
98
+ readonly defined: boolean;
99
+ readonly code: TCode;
100
+ readonly status: number;
101
+ readonly data: TData;
102
+ constructor(options: ORPCErrorOptions<TCode, TData>);
103
+ toJSON(): ORPCErrorJSON<TCode, TData>;
104
+ static isValidJSON(json: unknown): json is ORPCErrorJSON<string, unknown>;
105
+ }
106
+ export type ORPCErrorJSON<TCode extends string, TData> = Pick<ORPCError<TCode, TData>, 'defined' | 'code' | 'status' | 'message' | 'data'>;
107
+ export declare function isDefinedError<T>(error: T): error is Extract<T, ORPCError<any, any>>;
108
+ export declare function validateORPCError(map: ErrorMap, error: ORPCError<any, any>): Promise<ORPCError<string, unknown>>;
109
+ //# sourceMappingURL=error-orpc.d.ts.map
@@ -0,0 +1,13 @@
1
+ import type { StandardSchemaV1 } from '@standard-schema/spec';
2
+ import type { ErrorMap } from './error-map';
3
+ import type { ORPCErrorFromErrorMap } from './error-orpc';
4
+ export type ErrorFromErrorMap<TErrorMap extends ErrorMap> = Error | ORPCErrorFromErrorMap<TErrorMap>;
5
+ export interface ValidationErrorOptions extends ErrorOptions {
6
+ message: string;
7
+ issues: readonly StandardSchemaV1.Issue[];
8
+ }
9
+ export declare class ValidationError extends Error {
10
+ readonly issues: readonly StandardSchemaV1.Issue[];
11
+ constructor(options: ValidationErrorOptions);
12
+ }
13
+ //# sourceMappingURL=error.d.ts.map
@@ -1,11 +1,22 @@
1
1
  /** unnoq */
2
2
  import { ContractBuilder } from './builder';
3
3
  export * from './builder';
4
+ export * from './client';
5
+ export * from './client-utils';
4
6
  export * from './config';
7
+ export * from './error';
8
+ export * from './error-map';
9
+ export * from './error-orpc';
5
10
  export * from './procedure';
11
+ export * from './procedure-builder';
12
+ export * from './procedure-builder-with-input';
13
+ export * from './procedure-builder-with-output';
14
+ export * from './procedure-client';
6
15
  export * from './procedure-decorated';
7
16
  export * from './router';
8
17
  export * from './router-builder';
18
+ export * from './router-client';
19
+ export * from './schema-utils';
9
20
  export * from './types';
10
- export declare const oc: ContractBuilder;
21
+ export declare const oc: ContractBuilder<Record<never, never>>;
11
22
  //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,19 @@
1
+ import type { ErrorMap, ErrorMapGuard, ErrorMapSuggestions } from './error-map';
2
+ import type { RouteOptions } from './procedure';
3
+ import type { HTTPPath, Schema, SchemaOutput } from './types';
4
+ import { ContractProcedure } from './procedure';
5
+ import { DecoratedContractProcedure } from './procedure-decorated';
6
+ /**
7
+ * `ContractProcedureBuilderWithInput` is a branch of `ContractProcedureBuilder` which it has input schema.
8
+ *
9
+ * Why?
10
+ * - prevents override input schema after .input
11
+ */
12
+ export declare class ContractProcedureBuilderWithInput<TInputSchema extends Schema, TErrorMap extends ErrorMap> extends ContractProcedure<TInputSchema, undefined, TErrorMap> {
13
+ errors<const U extends ErrorMap & ErrorMapGuard<TErrorMap> & ErrorMapSuggestions>(errors: U): ContractProcedureBuilderWithInput<TInputSchema, TErrorMap & U>;
14
+ route(route: RouteOptions): ContractProcedureBuilderWithInput<TInputSchema, TErrorMap>;
15
+ prefix(prefix: HTTPPath): ContractProcedureBuilderWithInput<TInputSchema, TErrorMap>;
16
+ unshiftTag(...tags: string[]): ContractProcedureBuilderWithInput<TInputSchema, TErrorMap>;
17
+ output<U extends Schema>(schema: U, example?: SchemaOutput<U>): DecoratedContractProcedure<TInputSchema, U, TErrorMap>;
18
+ }
19
+ //# sourceMappingURL=procedure-builder-with-input.d.ts.map
@@ -0,0 +1,19 @@
1
+ import type { ErrorMap, ErrorMapGuard, ErrorMapSuggestions } from './error-map';
2
+ import type { RouteOptions } from './procedure';
3
+ import type { HTTPPath, Schema, SchemaInput } from './types';
4
+ import { ContractProcedure } from './procedure';
5
+ import { DecoratedContractProcedure } from './procedure-decorated';
6
+ /**
7
+ * `ContractProcedureBuilderWithOutput` is a branch of `ContractProcedureBuilder` which it has output schema.
8
+ *
9
+ * Why?
10
+ * - prevents override output schema after .output
11
+ */
12
+ export declare class ContractProcedureBuilderWithOutput<TOutputSchema extends Schema, TErrorMap extends ErrorMap> extends ContractProcedure<undefined, TOutputSchema, TErrorMap> {
13
+ errors<const U extends ErrorMap & ErrorMapGuard<TErrorMap> & ErrorMapSuggestions>(errors: U): ContractProcedureBuilderWithOutput<TOutputSchema, TErrorMap & U>;
14
+ route(route: RouteOptions): ContractProcedureBuilderWithOutput<TOutputSchema, TErrorMap>;
15
+ prefix(prefix: HTTPPath): ContractProcedureBuilderWithOutput<TOutputSchema, TErrorMap>;
16
+ unshiftTag(...tags: string[]): ContractProcedureBuilderWithOutput<TOutputSchema, TErrorMap>;
17
+ input<U extends Schema>(schema: U, example?: SchemaInput<U>): DecoratedContractProcedure<U, TOutputSchema, TErrorMap>;
18
+ }
19
+ //# sourceMappingURL=procedure-builder-with-output.d.ts.map
@@ -0,0 +1,15 @@
1
+ import type { ErrorMap, ErrorMapGuard, ErrorMapSuggestions } from './error-map';
2
+ import type { RouteOptions } from './procedure';
3
+ import type { HTTPPath, Schema, SchemaInput, SchemaOutput } from './types';
4
+ import { ContractProcedure } from './procedure';
5
+ import { ContractProcedureBuilderWithInput } from './procedure-builder-with-input';
6
+ import { ContractProcedureBuilderWithOutput } from './procedure-builder-with-output';
7
+ export declare class ContractProcedureBuilder<TErrorMap extends ErrorMap> extends ContractProcedure<undefined, undefined, TErrorMap> {
8
+ errors<const U extends ErrorMap & ErrorMapGuard<TErrorMap> & ErrorMapSuggestions>(errors: U): ContractProcedureBuilder<TErrorMap & U>;
9
+ route(route: RouteOptions): ContractProcedureBuilder<TErrorMap>;
10
+ prefix(prefix: HTTPPath): ContractProcedureBuilder<TErrorMap>;
11
+ unshiftTag(...tags: string[]): ContractProcedureBuilder<TErrorMap>;
12
+ input<U extends Schema>(schema: U, example?: SchemaInput<U>): ContractProcedureBuilderWithInput<U, TErrorMap>;
13
+ output<U extends Schema>(schema: U, example?: SchemaOutput<U>): ContractProcedureBuilderWithOutput<U, TErrorMap>;
14
+ }
15
+ //# sourceMappingURL=procedure-builder.d.ts.map
@@ -0,0 +1,6 @@
1
+ import type { Client } from './client';
2
+ import type { ErrorFromErrorMap } from './error';
3
+ import type { ErrorMap } from './error-map';
4
+ import type { Schema, SchemaInput, SchemaOutput } from './types';
5
+ export type ContractProcedureClient<TClientContext, TInputSchema extends Schema, TOutputSchema extends Schema, TErrorMap extends ErrorMap> = Client<TClientContext, SchemaInput<TInputSchema>, SchemaOutput<TOutputSchema>, ErrorFromErrorMap<TErrorMap>>;
6
+ //# sourceMappingURL=procedure-client.d.ts.map
@@ -1,12 +1,12 @@
1
+ import type { ErrorMap, ErrorMapGuard, ErrorMapSuggestions } from './error-map';
1
2
  import type { RouteOptions } from './procedure';
2
- import type { HTTPPath, Schema, SchemaInput, SchemaOutput } from './types';
3
+ import type { HTTPPath, Schema } from './types';
3
4
  import { ContractProcedure } from './procedure';
4
- export declare class DecoratedContractProcedure<TInputSchema extends Schema, TOutputSchema extends Schema> extends ContractProcedure<TInputSchema, TOutputSchema> {
5
- static decorate<UInputSchema extends Schema = undefined, UOutputSchema extends Schema = undefined>(procedure: ContractProcedure<UInputSchema, UOutputSchema>): DecoratedContractProcedure<UInputSchema, UOutputSchema>;
6
- route(route: RouteOptions): DecoratedContractProcedure<TInputSchema, TOutputSchema>;
7
- prefix(prefix: HTTPPath): DecoratedContractProcedure<TInputSchema, TOutputSchema>;
8
- unshiftTag(...tags: string[]): DecoratedContractProcedure<TInputSchema, TOutputSchema>;
9
- input<U extends Schema = undefined>(schema: U, example?: SchemaInput<U>): DecoratedContractProcedure<U, TOutputSchema>;
10
- output<U extends Schema = undefined>(schema: U, example?: SchemaOutput<U>): DecoratedContractProcedure<TInputSchema, U>;
5
+ export declare class DecoratedContractProcedure<TInputSchema extends Schema, TOutputSchema extends Schema, TErrorMap extends ErrorMap> extends ContractProcedure<TInputSchema, TOutputSchema, TErrorMap> {
6
+ static decorate<UInputSchema extends Schema, UOutputSchema extends Schema, TErrorMap extends ErrorMap>(procedure: ContractProcedure<UInputSchema, UOutputSchema, TErrorMap>): DecoratedContractProcedure<UInputSchema, UOutputSchema, TErrorMap>;
7
+ errors<const U extends ErrorMap & ErrorMapGuard<TErrorMap> & ErrorMapSuggestions>(errors: U): DecoratedContractProcedure<TInputSchema, TOutputSchema, TErrorMap & U>;
8
+ route(route: RouteOptions): DecoratedContractProcedure<TInputSchema, TOutputSchema, TErrorMap>;
9
+ prefix(prefix: HTTPPath): DecoratedContractProcedure<TInputSchema, TOutputSchema, TErrorMap>;
10
+ unshiftTag(...tags: string[]): DecoratedContractProcedure<TInputSchema, TOutputSchema, TErrorMap>;
11
11
  }
12
12
  //# sourceMappingURL=procedure-decorated.d.ts.map
@@ -1,3 +1,4 @@
1
+ import type { ErrorMap } from './error-map';
1
2
  import type { HTTPMethod, HTTPPath, InputStructure, OutputStructure, Schema, SchemaOutput } from './types';
2
3
  export interface RouteOptions {
3
4
  method?: HTTPMethod;
@@ -63,19 +64,20 @@ export interface RouteOptions {
63
64
  */
64
65
  outputStructure?: OutputStructure;
65
66
  }
66
- export interface ContractProcedureDef<TInputSchema extends Schema, TOutputSchema extends Schema> {
67
+ export interface ContractProcedureDef<TInputSchema extends Schema, TOutputSchema extends Schema, TErrorMap extends ErrorMap> {
67
68
  route?: RouteOptions;
68
69
  InputSchema: TInputSchema;
69
70
  inputExample?: SchemaOutput<TInputSchema>;
70
71
  OutputSchema: TOutputSchema;
71
72
  outputExample?: SchemaOutput<TOutputSchema>;
73
+ errorMap: TErrorMap;
72
74
  }
73
- export declare class ContractProcedure<TInputSchema extends Schema, TOutputSchema extends Schema> {
75
+ export declare class ContractProcedure<TInputSchema extends Schema, TOutputSchema extends Schema, TErrorMap extends ErrorMap> {
74
76
  '~type': "ContractProcedure";
75
- '~orpc': ContractProcedureDef<TInputSchema, TOutputSchema>;
76
- constructor(def: ContractProcedureDef<TInputSchema, TOutputSchema>);
77
+ '~orpc': ContractProcedureDef<TInputSchema, TOutputSchema, TErrorMap>;
78
+ constructor(def: ContractProcedureDef<TInputSchema, TOutputSchema, TErrorMap>);
77
79
  }
78
- export type ANY_CONTRACT_PROCEDURE = ContractProcedure<any, any>;
79
- export type WELL_CONTRACT_PROCEDURE = ContractProcedure<Schema, Schema>;
80
+ export type ANY_CONTRACT_PROCEDURE = ContractProcedure<any, any, any>;
81
+ export type WELL_CONTRACT_PROCEDURE = ContractProcedure<Schema, Schema, ErrorMap>;
80
82
  export declare function isContractProcedure(item: unknown): item is ANY_CONTRACT_PROCEDURE;
81
83
  //# sourceMappingURL=procedure.d.ts.map
@@ -1,20 +1,23 @@
1
+ import type { ErrorMap, ErrorMapGuard, ErrorMapSuggestions, StrictErrorMap } from './error-map';
1
2
  import type { ContractProcedure } from './procedure';
2
3
  import type { ContractRouter } from './router';
3
4
  import type { HTTPPath } from './types';
4
5
  import { DecoratedContractProcedure } from './procedure-decorated';
5
- export type AdaptedContractRouter<TContract extends ContractRouter> = {
6
- [K in keyof TContract]: TContract[K] extends ContractProcedure<infer UInputSchema, infer UOutputSchema> ? DecoratedContractProcedure<UInputSchema, UOutputSchema> : TContract[K] extends ContractRouter ? AdaptedContractRouter<TContract[K]> : never;
6
+ export type AdaptedContractRouter<TContract extends ContractRouter<any>, TErrorMapExtra extends ErrorMap> = {
7
+ [K in keyof TContract]: TContract[K] extends ContractProcedure<infer UInputSchema, infer UOutputSchema, infer UErrors> ? DecoratedContractProcedure<UInputSchema, UOutputSchema, UErrors & TErrorMapExtra> : TContract[K] extends ContractRouter<any> ? AdaptedContractRouter<TContract[K], TErrorMapExtra> : never;
7
8
  };
8
- export interface ContractRouterBuilderDef {
9
+ export interface ContractRouterBuilderDef<TErrorMap extends ErrorMap> {
9
10
  prefix?: HTTPPath;
10
11
  tags?: string[];
12
+ errorMap: TErrorMap;
11
13
  }
12
- export declare class ContractRouterBuilder {
14
+ export declare class ContractRouterBuilder<TErrorMap extends ErrorMap> {
13
15
  '~type': "ContractProcedure";
14
- '~orpc': ContractRouterBuilderDef;
15
- constructor(def: ContractRouterBuilderDef);
16
- prefix(prefix: HTTPPath): ContractRouterBuilder;
17
- tag(...tags: string[]): ContractRouterBuilder;
18
- router<T extends ContractRouter>(router: T): AdaptedContractRouter<T>;
16
+ '~orpc': ContractRouterBuilderDef<TErrorMap>;
17
+ constructor(def: ContractRouterBuilderDef<TErrorMap>);
18
+ prefix(prefix: HTTPPath): ContractRouterBuilder<TErrorMap>;
19
+ tag(...tags: string[]): ContractRouterBuilder<TErrorMap>;
20
+ errors<const U extends ErrorMap & ErrorMapGuard<TErrorMap> & ErrorMapSuggestions>(errors: U): ContractRouterBuilder<U & TErrorMap>;
21
+ router<T extends ContractRouter<ErrorMap & Partial<StrictErrorMap<TErrorMap>>>>(router: T): AdaptedContractRouter<T, TErrorMap>;
19
22
  }
20
23
  //# sourceMappingURL=router-builder.d.ts.map
@@ -0,0 +1,7 @@
1
+ import type { ContractProcedure } from './procedure';
2
+ import type { ContractProcedureClient } from './procedure-client';
3
+ import type { ContractRouter } from './router';
4
+ export type ContractRouterClient<TRouter extends ContractRouter<any>, TClientContext> = TRouter extends ContractProcedure<infer UInputSchema, infer UOutputSchema, infer UErrorMap> ? ContractProcedureClient<TClientContext, UInputSchema, UOutputSchema, UErrorMap> : {
5
+ [K in keyof TRouter]: TRouter[K] extends ContractRouter<any> ? ContractRouterClient<TRouter[K], TClientContext> : never;
6
+ };
7
+ //# sourceMappingURL=router-client.d.ts.map
@@ -1,12 +1,13 @@
1
- import type { ANY_CONTRACT_PROCEDURE, ContractProcedure } from './procedure';
1
+ import type { ErrorMap } from './error-map';
2
+ import type { ContractProcedure } from './procedure';
2
3
  import type { SchemaInput, SchemaOutput } from './types';
3
- export type ContractRouter = ANY_CONTRACT_PROCEDURE | {
4
- [k: string]: ContractRouter;
4
+ export type ContractRouter<T extends ErrorMap> = ContractProcedure<any, any, T> | {
5
+ [k: string]: ContractRouter<T>;
5
6
  };
6
- export type InferContractRouterInputs<T extends ContractRouter> = T extends ContractProcedure<infer UInputSchema, any> ? SchemaInput<UInputSchema> : {
7
- [K in keyof T]: T[K] extends ContractRouter ? InferContractRouterInputs<T[K]> : never;
7
+ export type InferContractRouterInputs<T extends ContractRouter<any>> = T extends ContractProcedure<infer UInputSchema, any, any> ? SchemaInput<UInputSchema> : {
8
+ [K in keyof T]: T[K] extends ContractRouter<any> ? InferContractRouterInputs<T[K]> : never;
8
9
  };
9
- export type InferContractRouterOutputs<T extends ContractRouter> = T extends ContractProcedure<any, infer UOutputSchema> ? SchemaOutput<UOutputSchema> : {
10
- [K in keyof T]: T[K] extends ContractRouter ? InferContractRouterOutputs<T[K]> : never;
10
+ export type InferContractRouterOutputs<T extends ContractRouter<any>> = T extends ContractProcedure<any, infer UOutputSchema, any> ? SchemaOutput<UOutputSchema> : {
11
+ [K in keyof T]: T[K] extends ContractRouter<any> ? InferContractRouterOutputs<T[K]> : never;
11
12
  };
12
13
  //# sourceMappingURL=router.d.ts.map
@@ -0,0 +1,5 @@
1
+ import type { IsEqual, Promisable } from '@orpc/shared';
2
+ import type { StandardSchemaV1 } from '@standard-schema/spec';
3
+ export type TypeRest<TInput, TOutput> = [map: (input: TInput) => Promisable<TOutput>] | (IsEqual<TInput, TOutput> extends true ? [] : never);
4
+ export declare function type<TInput, TOutput = TInput>(...[map]: TypeRest<TInput, TOutput>): StandardSchemaV1<TInput, TOutput>;
5
+ //# sourceMappingURL=schema-utils.d.ts.map
@@ -1,3 +1,4 @@
1
+ import type { FindGlobalInstanceType } from '@orpc/shared';
1
2
  import type { StandardSchemaV1 } from '@standard-schema/spec';
2
3
  export type HTTPPath = `/${string}`;
3
4
  export type HTTPMethod = 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH';
@@ -6,4 +7,5 @@ export type OutputStructure = 'compact' | 'detailed';
6
7
  export type Schema = StandardSchemaV1 | undefined;
7
8
  export type SchemaInput<TSchema extends Schema, TFallback = unknown> = TSchema extends undefined ? TFallback : TSchema extends StandardSchemaV1 ? StandardSchemaV1.InferInput<TSchema> : TFallback;
8
9
  export type SchemaOutput<TSchema extends Schema, TFallback = unknown> = TSchema extends undefined ? TFallback : TSchema extends StandardSchemaV1 ? StandardSchemaV1.InferOutput<TSchema> : TFallback;
10
+ export type AbortSignal = FindGlobalInstanceType<'AbortSignal'>;
9
11
  //# sourceMappingURL=types.d.ts.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.4a31e17",
4
+ "version": "0.0.0-next.4e27480",
5
5
  "license": "MIT",
6
6
  "homepage": "https://orpc.unnoq.com",
7
7
  "repository": {
@@ -30,7 +30,7 @@
30
30
  ],
31
31
  "dependencies": {
32
32
  "@standard-schema/spec": "1.0.0-beta.4",
33
- "@orpc/shared": "0.0.0-next.4a31e17"
33
+ "@orpc/shared": "0.0.0-next.4e27480"
34
34
  },
35
35
  "devDependencies": {
36
36
  "arktype": "2.0.0-rc.26",