@orpc/contract 0.0.0-next.f56d2b3 → 0.0.0-next.fd0ca3d

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,180 +167,6 @@ var oc = new ContractBuilder({
160
167
  meta: {}
161
168
  });
162
169
 
163
- // src/error-orpc.ts
164
- import { isPlainObject } 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 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";
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
-
323
- // src/client-utils.ts
324
- async function safe(promise) {
325
- try {
326
- const output = await promise;
327
- return [output, void 0, false];
328
- } catch (e) {
329
- const error = e;
330
- if (isDefinedError(error)) {
331
- return [void 0, error, true];
332
- }
333
- return [void 0, error, false];
334
- }
335
- }
336
-
337
170
  // src/config.ts
338
171
  var DEFAULT_CONFIG = {
339
172
  defaultMethod: "POST",
@@ -349,14 +182,51 @@ function fallbackContractConfig(key, value) {
349
182
  return value;
350
183
  }
351
184
 
352
- // src/error.ts
353
- var ValidationError = class extends Error {
354
- issues;
355
- constructor(options) {
356
- super(options.message, options);
357
- 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;
358
227
  }
359
- };
228
+ return schema["~standard"][EVENT_ITERATOR_SCHEMA_SYMBOL];
229
+ }
360
230
 
361
231
  // src/schema.ts
362
232
  function type(...[map]) {
@@ -373,20 +243,20 @@ function type(...[map]) {
373
243
  }
374
244
  };
375
245
  }
246
+
247
+ // src/index.ts
248
+ import { ORPCError as ORPCError2 } from "@orpc/client";
376
249
  export {
377
- COMMON_ORPC_ERROR_DEFS,
378
250
  ContractBuilder,
379
251
  ContractProcedure,
380
- ORPCError,
252
+ ORPCError2 as ORPCError,
381
253
  ValidationError,
382
254
  adaptContractRouter,
383
255
  adaptRoute,
384
- createORPCErrorConstructorMap,
256
+ eventIterator,
385
257
  fallbackContractConfig,
386
- fallbackORPCErrorMessage,
387
- fallbackORPCErrorStatus,
258
+ getEventIteratorSchemaDetails,
388
259
  isContractProcedure,
389
- isDefinedError,
390
260
  mergeErrorMap,
391
261
  mergeMeta,
392
262
  mergePrefix,
@@ -394,9 +264,7 @@ export {
394
264
  mergeTags,
395
265
  oc,
396
266
  prefixRoute,
397
- safe,
398
267
  type,
399
- unshiftTagRoute,
400
- validateORPCError
268
+ unshiftTagRoute
401
269
  };
402
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,5 +11,5 @@ export * from './route';
15
11
  export * from './router';
16
12
  export * from './router-client';
17
13
  export * from './schema';
18
- export * from './types';
14
+ export { ORPCError } from '@orpc/client';
19
15
  //# sourceMappingURL=index.d.ts.map
@@ -1,6 +1,5 @@
1
- import type { Client } 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
- export type ContractProcedureClient<TClientContext, TInputSchema extends Schema, TOutputSchema extends Schema, TErrorMap extends ErrorMap> = Client<TClientContext, SchemaInput<TInputSchema>, SchemaOutput<TOutputSchema>, ErrorFromErrorMap<TErrorMap>>;
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,7 +1,8 @@
1
+ import type { ClientContext } from '@orpc/client';
1
2
  import type { ContractProcedure } from './procedure';
2
3
  import type { ContractProcedureClient } from './procedure-client';
3
4
  import type { AnyContractRouter } from './router';
4
- export type ContractRouterClient<TRouter extends AnyContractRouter, TClientContext> = 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> : {
5
6
  [K in keyof TRouter]: TRouter[K] extends AnyContractRouter ? ContractRouterClient<TRouter[K], TClientContext> : never;
6
7
  };
7
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.0.0-next.f56d2b3",
4
+ "version": "0.0.0-next.fd0ca3d",
5
5
  "license": "MIT",
6
6
  "homepage": "https://orpc.unnoq.com",
7
7
  "repository": {
@@ -29,13 +29,15 @@
29
29
  "dist"
30
30
  ],
31
31
  "dependencies": {
32
- "@standard-schema/spec": "1.0.0-rc.0",
33
- "@orpc/shared": "0.0.0-next.f56d2b3"
32
+ "@orpc/server-standard": "^0.4.0",
33
+ "@standard-schema/spec": "^1.0.0",
34
+ "@orpc/client": "0.0.0-next.fd0ca3d",
35
+ "@orpc/shared": "0.0.0-next.fd0ca3d"
34
36
  },
35
37
  "devDependencies": {
36
38
  "arktype": "2.0.0-rc.26",
37
39
  "valibot": "1.0.0-beta.9",
38
- "zod": "3.24.1"
40
+ "zod": "^3.24.1"
39
41
  },
40
42
  "scripts": {
41
43
  "build": "tsup --clean --sourcemap --entry.index=src/index.ts --format=esm --onSuccess='tsc -b --noCheck'",
@@ -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
- 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
- __error?: {
12
- type: TError;
13
- };
14
- };
15
- export interface Client<TClientContext, TInput, TOutput, TError extends Error> {
16
- (...rest: ClientRest<TClientContext, TInput>): ClientPromiseResult<TOutput, TError>;
17
- }
18
- export type NestedClient<TClientContext> = 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 { ErrorMap, ErrorMapItem } from './error-map';
2
- import type { SchemaOutput } from './schema';
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 ORPCErrorCode = CommonORPCErrorCode | (string & {});
86
- export declare function fallbackORPCErrorStatus(code: ORPCErrorCode, status: number | undefined): number;
87
- export declare function fallbackORPCErrorMessage(code: ORPCErrorCode, message: string | undefined): string;
88
- export type ORPCErrorOptions<TData> = ErrorOptions & {
89
- defined?: boolean;
90
- status?: number;
91
- message?: string;
92
- } & (undefined extends TData ? {
93
- data?: TData;
94
- } : {
95
- data: TData;
96
- });
97
- export type ORPCErrorOptionsRest<TData> = [options: ORPCErrorOptions<TData>] | (undefined extends TData ? [] : never);
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]: ORPCErrorOptionsRest<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,14 +0,0 @@
1
- import type { ErrorMap, ErrorMapItem } from './error-map';
2
- import type { ORPCErrorCode, ORPCErrorOptions } from './error-orpc';
3
- import type { SchemaInput } from './schema';
4
- import { ORPCError } from './error-orpc';
5
- export declare function isDefinedError<T>(error: T): error is Extract<T, ORPCError<any, any>>;
6
- export type ORPCErrorConstructorMapItemOptions<TData> = Omit<ORPCErrorOptions<TData>, 'defined' | 'status'>;
7
- export type ORPCErrorConstructorMapItemRest<TData> = [options: ORPCErrorConstructorMapItemOptions<TData>] | (undefined extends TData ? [] : never);
8
- export type ORPCErrorConstructorMapItem<TCode extends ORPCErrorCode, TInData> = (...rest: ORPCErrorConstructorMapItemRest<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
- //# sourceMappingURL=error-utils.d.ts.map
@@ -1,3 +0,0 @@
1
- import type { FindGlobalInstanceType } from '@orpc/shared';
2
- export type AbortSignal = FindGlobalInstanceType<'AbortSignal'>;
3
- //# sourceMappingURL=types.d.ts.map