@orpc/contract 0.39.0 → 0.41.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,4 +1,11 @@
1
- // src/error-map.ts
1
+ // src/error.ts
2
+ var ValidationError = class extends Error {
3
+ issues;
4
+ constructor(options) {
5
+ super(options.message, options);
6
+ this.issues = options.issues;
7
+ }
8
+ };
2
9
  function mergeErrorMap(errorMap1, errorMap2) {
3
10
  return { ...errorMap1, ...errorMap2 };
4
11
  }
@@ -160,186 +167,6 @@ var oc = new ContractBuilder({
160
167
  meta: {}
161
168
  });
162
169
 
163
- // src/error-orpc.ts
164
- import { isObject } from "@orpc/shared";
165
- var COMMON_ORPC_ERROR_DEFS = {
166
- BAD_REQUEST: {
167
- status: 400,
168
- message: "Bad Request"
169
- },
170
- UNAUTHORIZED: {
171
- status: 401,
172
- message: "Unauthorized"
173
- },
174
- FORBIDDEN: {
175
- status: 403,
176
- message: "Forbidden"
177
- },
178
- NOT_FOUND: {
179
- status: 404,
180
- message: "Not Found"
181
- },
182
- METHOD_NOT_SUPPORTED: {
183
- status: 405,
184
- message: "Method Not Supported"
185
- },
186
- NOT_ACCEPTABLE: {
187
- status: 406,
188
- message: "Not Acceptable"
189
- },
190
- TIMEOUT: {
191
- status: 408,
192
- message: "Request Timeout"
193
- },
194
- CONFLICT: {
195
- status: 409,
196
- message: "Conflict"
197
- },
198
- PRECONDITION_FAILED: {
199
- status: 412,
200
- message: "Precondition Failed"
201
- },
202
- PAYLOAD_TOO_LARGE: {
203
- status: 413,
204
- message: "Payload Too Large"
205
- },
206
- UNSUPPORTED_MEDIA_TYPE: {
207
- status: 415,
208
- message: "Unsupported Media Type"
209
- },
210
- UNPROCESSABLE_CONTENT: {
211
- status: 422,
212
- message: "Unprocessable Content"
213
- },
214
- TOO_MANY_REQUESTS: {
215
- status: 429,
216
- message: "Too Many Requests"
217
- },
218
- CLIENT_CLOSED_REQUEST: {
219
- status: 499,
220
- message: "Client Closed Request"
221
- },
222
- INTERNAL_SERVER_ERROR: {
223
- status: 500,
224
- message: "Internal Server Error"
225
- },
226
- NOT_IMPLEMENTED: {
227
- status: 501,
228
- message: "Not Implemented"
229
- },
230
- BAD_GATEWAY: {
231
- status: 502,
232
- message: "Bad Gateway"
233
- },
234
- SERVICE_UNAVAILABLE: {
235
- status: 503,
236
- message: "Service Unavailable"
237
- },
238
- GATEWAY_TIMEOUT: {
239
- status: 504,
240
- message: "Gateway Timeout"
241
- }
242
- };
243
- function fallbackORPCErrorStatus(code, status) {
244
- return status ?? COMMON_ORPC_ERROR_DEFS[code]?.status ?? 500;
245
- }
246
- function fallbackORPCErrorMessage(code, message) {
247
- return message || COMMON_ORPC_ERROR_DEFS[code]?.message || code;
248
- }
249
- var ORPCError = class _ORPCError extends Error {
250
- defined;
251
- code;
252
- status;
253
- data;
254
- constructor(code, ...[options]) {
255
- if (options?.status && (options.status < 400 || options.status >= 600)) {
256
- throw new Error("[ORPCError] The error status code must be in the 400-599 range.");
257
- }
258
- const message = fallbackORPCErrorMessage(code, options?.message);
259
- super(message, options);
260
- this.code = code;
261
- this.status = fallbackORPCErrorStatus(code, options?.status);
262
- this.defined = options?.defined ?? false;
263
- this.data = options?.data;
264
- }
265
- toJSON() {
266
- return {
267
- defined: this.defined,
268
- code: this.code,
269
- status: this.status,
270
- message: this.message,
271
- data: this.data
272
- };
273
- }
274
- static fromJSON(json) {
275
- return new _ORPCError(json.code, json);
276
- }
277
- static isValidJSON(json) {
278
- return isObject(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";
279
- }
280
- };
281
-
282
- // src/error-utils.ts
283
- function isDefinedError(error) {
284
- return error instanceof ORPCError && error.defined;
285
- }
286
- function createORPCErrorConstructorMap(errors) {
287
- const proxy = new Proxy(errors, {
288
- get(target, code) {
289
- if (typeof code !== "string") {
290
- return Reflect.get(target, code);
291
- }
292
- const item = (...[options]) => {
293
- const config = errors[code];
294
- return new ORPCError(code, {
295
- defined: Boolean(config),
296
- status: config?.status,
297
- message: options?.message ?? config?.message,
298
- data: options?.data,
299
- cause: options?.cause
300
- });
301
- };
302
- return item;
303
- }
304
- });
305
- return proxy;
306
- }
307
- async function validateORPCError(map, error) {
308
- const { code, status, message, data, cause, defined } = error;
309
- const config = map?.[error.code];
310
- if (!config || fallbackORPCErrorStatus(error.code, config.status) !== error.status) {
311
- return defined ? new ORPCError(code, { defined: false, status, message, data, cause }) : error;
312
- }
313
- if (!config.data) {
314
- return defined ? error : new ORPCError(code, { defined: true, status, message, data, cause });
315
- }
316
- const validated = await config.data["~standard"].validate(error.data);
317
- if (validated.issues) {
318
- return defined ? new ORPCError(code, { defined: false, status, message, data, cause }) : error;
319
- }
320
- return new ORPCError(code, { defined: true, status, message, data: validated.value, cause });
321
- }
322
- function toORPCError(error) {
323
- return error instanceof ORPCError ? error : new ORPCError("INTERNAL_SERVER_ERROR", {
324
- message: "Internal server error",
325
- cause: error
326
- });
327
- }
328
-
329
- // src/client-utils.ts
330
- async function safe(promise) {
331
- try {
332
- const output = await promise;
333
- return [output, void 0, false];
334
- } catch (e) {
335
- const error = e;
336
- if (isDefinedError(error)) {
337
- return [void 0, error, true];
338
- }
339
- return [void 0, error, false];
340
- }
341
- }
342
-
343
170
  // src/config.ts
344
171
  var DEFAULT_CONFIG = {
345
172
  defaultMethod: "POST",
@@ -355,14 +182,51 @@ function fallbackContractConfig(key, value) {
355
182
  return value;
356
183
  }
357
184
 
358
- // src/error.ts
359
- var ValidationError = class extends Error {
360
- issues;
361
- constructor(options) {
362
- super(options.message, options);
363
- this.issues = options.issues;
185
+ // src/event-iterator.ts
186
+ import { mapEventIterator, ORPCError } from "@orpc/client";
187
+ import { isAsyncIteratorObject } from "@orpc/server-standard";
188
+ var EVENT_ITERATOR_SCHEMA_SYMBOL = Symbol("ORPC_EVENT_ITERATOR_SCHEMA");
189
+ function eventIterator(yields, returns) {
190
+ return {
191
+ "~standard": {
192
+ [EVENT_ITERATOR_SCHEMA_SYMBOL]: { yields, returns },
193
+ vendor: "orpc",
194
+ version: 1,
195
+ validate(iterator) {
196
+ if (!isAsyncIteratorObject(iterator)) {
197
+ return { issues: [{ message: "Expect event source iterator", path: [] }] };
198
+ }
199
+ const mapped = mapEventIterator(iterator, {
200
+ async value(value, done) {
201
+ const schema = done ? returns : yields;
202
+ if (!schema) {
203
+ return value;
204
+ }
205
+ const result = await schema["~standard"].validate(value);
206
+ if (result.issues) {
207
+ throw new ORPCError("EVENT_ITERATOR_VALIDATION_FAILED", {
208
+ message: "Event source iterator validation failed",
209
+ cause: new ValidationError({
210
+ issues: result.issues,
211
+ message: "Event source iterator validation failed"
212
+ })
213
+ });
214
+ }
215
+ return result.value;
216
+ },
217
+ error: async (error) => error
218
+ });
219
+ return { value: mapped };
220
+ }
221
+ }
222
+ };
223
+ }
224
+ function getEventIteratorSchemaDetails(schema) {
225
+ if (schema === void 0) {
226
+ return void 0;
364
227
  }
365
- };
228
+ return schema["~standard"][EVENT_ITERATOR_SCHEMA_SYMBOL];
229
+ }
366
230
 
367
231
  // src/schema.ts
368
232
  function type(...[map]) {
@@ -379,20 +243,20 @@ function type(...[map]) {
379
243
  }
380
244
  };
381
245
  }
246
+
247
+ // src/index.ts
248
+ import { ORPCError as ORPCError2 } from "@orpc/client";
382
249
  export {
383
- COMMON_ORPC_ERROR_DEFS,
384
250
  ContractBuilder,
385
251
  ContractProcedure,
386
- ORPCError,
252
+ ORPCError2 as ORPCError,
387
253
  ValidationError,
388
254
  adaptContractRouter,
389
255
  adaptRoute,
390
- createORPCErrorConstructorMap,
256
+ eventIterator,
391
257
  fallbackContractConfig,
392
- fallbackORPCErrorMessage,
393
- fallbackORPCErrorStatus,
258
+ getEventIteratorSchemaDetails,
394
259
  isContractProcedure,
395
- isDefinedError,
396
260
  mergeErrorMap,
397
261
  mergeMeta,
398
262
  mergePrefix,
@@ -400,10 +264,7 @@ export {
400
264
  mergeTags,
401
265
  oc,
402
266
  prefixRoute,
403
- safe,
404
- toORPCError,
405
267
  type,
406
- unshiftTagRoute,
407
- validateORPCError
268
+ unshiftTagRoute
408
269
  };
409
270
  //# sourceMappingURL=index.js.map
@@ -1,4 +1,4 @@
1
- import type { ErrorMap, MergedErrorMap } from './error-map';
1
+ import type { ErrorMap, MergedErrorMap } from './error';
2
2
  import type { Meta } from './meta';
3
3
  import type { ContractProcedure } from './procedure';
4
4
  import type { HTTPPath, Route } from './route';
@@ -2,7 +2,7 @@ import type { ContractProcedureBuilder, ContractProcedureBuilderWithInput, Contr
2
2
  import type { ContractProcedureDef } from './procedure';
3
3
  import type { AdaptContractRouterOptions, AdaptedContractRouter, ContractRouter } from './router';
4
4
  import type { Schema } from './schema';
5
- import { type ErrorMap, type MergedErrorMap } from './error-map';
5
+ import { type ErrorMap, type MergedErrorMap } from './error';
6
6
  import { type Meta } from './meta';
7
7
  import { ContractProcedure } from './procedure';
8
8
  import { type HTTPPath, type Route } from './route';
@@ -1,7 +1,6 @@
1
+ import type { ORPCError, ORPCErrorCode } from '@orpc/client';
1
2
  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>;
3
+ import type { Schema, SchemaOutput } from './schema';
5
4
  export interface ValidationErrorOptions extends ErrorOptions {
6
5
  message: string;
7
6
  issues: readonly StandardSchemaV1.Issue[];
@@ -10,4 +9,19 @@ export declare class ValidationError extends Error {
10
9
  readonly issues: readonly StandardSchemaV1.Issue[];
11
10
  constructor(options: ValidationErrorOptions);
12
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>;
13
27
  //# sourceMappingURL=error.d.ts.map
@@ -0,0 +1,8 @@
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,13 +1,9 @@
1
1
  /** unnoq */
2
2
  export * from './builder';
3
3
  export * from './builder-variants';
4
- export * from './client';
5
- export * from './client-utils';
6
4
  export * from './config';
7
5
  export * from './error';
8
- export * from './error-map';
9
- export * from './error-orpc';
10
- export * from './error-utils';
6
+ export * from './event-iterator';
11
7
  export * from './meta';
12
8
  export * from './procedure';
13
9
  export * from './procedure-client';
@@ -15,4 +11,5 @@ export * from './route';
15
11
  export * from './router';
16
12
  export * from './router-client';
17
13
  export * from './schema';
14
+ export { ORPCError } from '@orpc/client';
18
15
  //# sourceMappingURL=index.d.ts.map
@@ -1,6 +1,5 @@
1
- import type { Client, ClientContext } from './client';
2
- import type { ErrorFromErrorMap } from './error';
3
- import type { ErrorMap } from './error-map';
1
+ import type { Client, ClientContext } from '@orpc/client';
2
+ import type { ErrorFromErrorMap, ErrorMap } from './error';
4
3
  import type { Schema, SchemaInput, SchemaOutput } from './schema';
5
4
  export type ContractProcedureClient<TClientContext extends ClientContext, TInputSchema extends Schema, TOutputSchema extends Schema, TErrorMap extends ErrorMap> = Client<TClientContext, SchemaInput<TInputSchema>, SchemaOutput<TOutputSchema>, ErrorFromErrorMap<TErrorMap>>;
6
5
  //# sourceMappingURL=procedure-client.d.ts.map
@@ -1,4 +1,4 @@
1
- import type { ErrorMap } from './error-map';
1
+ import type { ErrorMap } from './error';
2
2
  import type { Meta } from './meta';
3
3
  import type { Route } from './route';
4
4
  import type { Schema } from './schema';
@@ -1,8 +1,8 @@
1
- import type { ClientContext } from './client';
1
+ import type { ClientContext } from '@orpc/client';
2
2
  import type { ContractProcedure } from './procedure';
3
3
  import type { ContractProcedureClient } from './procedure-client';
4
4
  import type { AnyContractRouter } from './router';
5
- export type ContractRouterClient<TRouter extends AnyContractRouter, TClientContext extends ClientContext> = TRouter extends ContractProcedure<infer UInputSchema, infer UOutputSchema, infer UErrorMap, any> ? ContractProcedureClient<TClientContext, UInputSchema, UOutputSchema, UErrorMap> : {
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
6
  [K in keyof TRouter]: TRouter[K] extends AnyContractRouter ? ContractRouterClient<TRouter[K], TClientContext> : never;
7
7
  };
8
8
  //# sourceMappingURL=router-client.d.ts.map
@@ -1,6 +1,6 @@
1
1
  import type { Meta } from './meta';
2
2
  import type { SchemaInput, SchemaOutput } from './schema';
3
- import { type ErrorMap, type MergedErrorMap } from './error-map';
3
+ import { type ErrorMap, type MergedErrorMap } from './error';
4
4
  import { ContractProcedure } from './procedure';
5
5
  import { type HTTPPath } from './route';
6
6
  export type ContractRouter<TMeta extends Meta> = ContractProcedure<any, any, any, TMeta> | {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@orpc/contract",
3
3
  "type": "module",
4
- "version": "0.39.0",
4
+ "version": "0.41.0",
5
5
  "license": "MIT",
6
6
  "homepage": "https://orpc.unnoq.com",
7
7
  "repository": {
@@ -29,8 +29,10 @@
29
29
  "dist"
30
30
  ],
31
31
  "dependencies": {
32
- "@standard-schema/spec": "1.0.0",
33
- "@orpc/shared": "0.39.0"
32
+ "@orpc/server-standard": "^0.4.0",
33
+ "@standard-schema/spec": "^1.0.0",
34
+ "@orpc/client": "0.41.0",
35
+ "@orpc/shared": "0.41.0"
34
36
  },
35
37
  "devDependencies": {
36
38
  "arktype": "2.0.0-rc.26",
@@ -1,5 +0,0 @@
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
@@ -1,21 +0,0 @@
1
- export type ClientContext = Record<string, any>;
2
- export type ClientOptions<TClientContext extends ClientContext> = {
3
- signal?: AbortSignal;
4
- } & (Record<never, never> extends TClientContext ? {
5
- context?: TClientContext;
6
- } : {
7
- context: TClientContext;
8
- });
9
- export type ClientRest<TClientContext extends ClientContext, TInput> = [input: TInput, options: ClientOptions<TClientContext>] | (Record<never, never> extends TClientContext ? (undefined extends TInput ? [input?: TInput] : [input: TInput]) : never);
10
- export type ClientPromiseResult<TOutput, TError extends Error> = Promise<TOutput> & {
11
- __error?: {
12
- type: TError;
13
- };
14
- };
15
- export interface Client<TClientContext extends ClientContext, TInput, TOutput, TError extends Error> {
16
- (...rest: ClientRest<TClientContext, TInput>): ClientPromiseResult<TOutput, TError>;
17
- }
18
- export type NestedClient<TClientContext extends ClientContext> = Client<TClientContext, any, any, any> | {
19
- [k: string]: NestedClient<TClientContext>;
20
- };
21
- //# sourceMappingURL=client.d.ts.map
@@ -1,14 +0,0 @@
1
- import type { ORPCErrorCode } from './error-orpc';
2
- import type { Schema } from './schema';
3
- export type ErrorMapItem<TDataSchema extends Schema> = {
4
- status?: number;
5
- message?: string;
6
- description?: string;
7
- data?: TDataSchema;
8
- };
9
- export type ErrorMap = {
10
- [key in ORPCErrorCode]?: ErrorMapItem<Schema>;
11
- };
12
- export type MergedErrorMap<T1 extends ErrorMap, T2 extends ErrorMap> = Omit<T1, keyof T2> & T2;
13
- export declare function mergeErrorMap<T1 extends ErrorMap, T2 extends ErrorMap>(errorMap1: T1, errorMap2: T2): MergedErrorMap<T1, T2>;
14
- //# sourceMappingURL=error-map.d.ts.map
@@ -1,109 +0,0 @@
1
- import type { MaybeOptionalOptions } from '@orpc/shared';
2
- import type { ErrorMap, ErrorMapItem } from './error-map';
3
- import type { SchemaOutput } from './schema';
4
- export type ORPCErrorFromErrorMap<TErrorMap extends ErrorMap> = {
5
- [K in keyof TErrorMap]: K extends string ? TErrorMap[K] extends ErrorMapItem<infer TDataSchema> ? ORPCError<K, SchemaOutput<TDataSchema>> : never : never;
6
- }[keyof TErrorMap];
7
- export declare const COMMON_ORPC_ERROR_DEFS: {
8
- readonly BAD_REQUEST: {
9
- readonly status: 400;
10
- readonly message: "Bad Request";
11
- };
12
- readonly UNAUTHORIZED: {
13
- readonly status: 401;
14
- readonly message: "Unauthorized";
15
- };
16
- readonly FORBIDDEN: {
17
- readonly status: 403;
18
- readonly message: "Forbidden";
19
- };
20
- readonly NOT_FOUND: {
21
- readonly status: 404;
22
- readonly message: "Not Found";
23
- };
24
- readonly METHOD_NOT_SUPPORTED: {
25
- readonly status: 405;
26
- readonly message: "Method Not Supported";
27
- };
28
- readonly NOT_ACCEPTABLE: {
29
- readonly status: 406;
30
- readonly message: "Not Acceptable";
31
- };
32
- readonly TIMEOUT: {
33
- readonly status: 408;
34
- readonly message: "Request Timeout";
35
- };
36
- readonly CONFLICT: {
37
- readonly status: 409;
38
- readonly message: "Conflict";
39
- };
40
- readonly PRECONDITION_FAILED: {
41
- readonly status: 412;
42
- readonly message: "Precondition Failed";
43
- };
44
- readonly PAYLOAD_TOO_LARGE: {
45
- readonly status: 413;
46
- readonly message: "Payload Too Large";
47
- };
48
- readonly UNSUPPORTED_MEDIA_TYPE: {
49
- readonly status: 415;
50
- readonly message: "Unsupported Media Type";
51
- };
52
- readonly UNPROCESSABLE_CONTENT: {
53
- readonly status: 422;
54
- readonly message: "Unprocessable Content";
55
- };
56
- readonly TOO_MANY_REQUESTS: {
57
- readonly status: 429;
58
- readonly message: "Too Many Requests";
59
- };
60
- readonly CLIENT_CLOSED_REQUEST: {
61
- readonly status: 499;
62
- readonly message: "Client Closed Request";
63
- };
64
- readonly INTERNAL_SERVER_ERROR: {
65
- readonly status: 500;
66
- readonly message: "Internal Server Error";
67
- };
68
- readonly NOT_IMPLEMENTED: {
69
- readonly status: 501;
70
- readonly message: "Not Implemented";
71
- };
72
- readonly BAD_GATEWAY: {
73
- readonly status: 502;
74
- readonly message: "Bad Gateway";
75
- };
76
- readonly SERVICE_UNAVAILABLE: {
77
- readonly status: 503;
78
- readonly message: "Service Unavailable";
79
- };
80
- readonly GATEWAY_TIMEOUT: {
81
- readonly status: 504;
82
- readonly message: "Gateway Timeout";
83
- };
84
- };
85
- export type CommonORPCErrorCode = keyof typeof COMMON_ORPC_ERROR_DEFS;
86
- export type ORPCErrorCode = CommonORPCErrorCode | (string & {});
87
- export declare function fallbackORPCErrorStatus(code: ORPCErrorCode, status: number | undefined): number;
88
- export declare function fallbackORPCErrorMessage(code: ORPCErrorCode, message: string | undefined): string;
89
- export type ORPCErrorOptions<TData> = ErrorOptions & {
90
- defined?: boolean;
91
- status?: number;
92
- message?: string;
93
- } & (undefined extends TData ? {
94
- data?: TData;
95
- } : {
96
- data: TData;
97
- });
98
- export declare class ORPCError<TCode extends ORPCErrorCode, TData> extends Error {
99
- readonly defined: boolean;
100
- readonly code: TCode;
101
- readonly status: number;
102
- readonly data: TData;
103
- constructor(code: TCode, ...[options]: MaybeOptionalOptions<ORPCErrorOptions<TData>>);
104
- toJSON(): ORPCErrorJSON<TCode, TData>;
105
- static fromJSON<TCode extends ORPCErrorCode, TData>(json: ORPCErrorJSON<TCode, TData>): ORPCError<TCode, TData>;
106
- static isValidJSON(json: unknown): json is ORPCErrorJSON<ORPCErrorCode, unknown>;
107
- }
108
- export type ORPCErrorJSON<TCode extends string, TData> = Pick<ORPCError<TCode, TData>, 'defined' | 'code' | 'status' | 'message' | 'data'>;
109
- //# sourceMappingURL=error-orpc.d.ts.map
@@ -1,15 +0,0 @@
1
- import type { MaybeOptionalOptions } from '@orpc/shared';
2
- import type { ErrorMap, ErrorMapItem } from './error-map';
3
- import type { ORPCErrorCode, ORPCErrorOptions } from './error-orpc';
4
- import type { SchemaInput } from './schema';
5
- import { ORPCError } from './error-orpc';
6
- export declare function isDefinedError<T>(error: T): error is Extract<T, ORPCError<any, any>>;
7
- export type ORPCErrorConstructorMapItemOptions<TData> = Omit<ORPCErrorOptions<TData>, 'defined' | 'status'>;
8
- export type ORPCErrorConstructorMapItem<TCode extends ORPCErrorCode, TInData> = (...rest: MaybeOptionalOptions<ORPCErrorConstructorMapItemOptions<TInData>>) => ORPCError<TCode, TInData>;
9
- export type ORPCErrorConstructorMap<T extends ErrorMap> = {
10
- [K in keyof T]: K extends ORPCErrorCode ? T[K] extends ErrorMapItem<infer UInputSchema> ? ORPCErrorConstructorMapItem<K, SchemaInput<UInputSchema>> : never : never;
11
- };
12
- export declare function createORPCErrorConstructorMap<T extends ErrorMap>(errors: T): ORPCErrorConstructorMap<T>;
13
- export declare function validateORPCError(map: ErrorMap, error: ORPCError<any, any>): Promise<ORPCError<string, unknown>>;
14
- export declare function toORPCError(error: unknown): ORPCError<any, any>;
15
- //# sourceMappingURL=error-utils.d.ts.map