@orpc/contract 0.40.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 +15 -243
- package/dist/src/builder-variants.d.ts +1 -1
- package/dist/src/builder.d.ts +1 -1
- package/dist/src/error.d.ts +17 -3
- package/dist/src/event-iterator.d.ts +0 -4
- package/dist/src/index.d.ts +1 -5
- package/dist/src/procedure-client.d.ts +2 -3
- package/dist/src/procedure.d.ts +1 -1
- package/dist/src/router-client.d.ts +2 -2
- package/dist/src/router.d.ts +1 -1
- package/package.json +3 -2
- package/dist/src/client-utils.d.ts +0 -5
- package/dist/src/client.d.ts +0 -22
- package/dist/src/error-map.d.ts +0 -14
- package/dist/src/error-orpc.d.ts +0 -109
- package/dist/src/error-utils.d.ts +0 -15
package/dist/index.js
CHANGED
|
@@ -1,4 +1,11 @@
|
|
|
1
|
-
// src/error
|
|
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,196 +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, options) {
|
|
275
|
-
return new _ORPCError(json.code, {
|
|
276
|
-
...options,
|
|
277
|
-
...json
|
|
278
|
-
});
|
|
279
|
-
}
|
|
280
|
-
static isValidJSON(json) {
|
|
281
|
-
if (!isObject(json)) {
|
|
282
|
-
return false;
|
|
283
|
-
}
|
|
284
|
-
const validKeys = ["defined", "code", "status", "message", "data"];
|
|
285
|
-
if (Object.keys(json).some((k) => !validKeys.includes(k))) {
|
|
286
|
-
return false;
|
|
287
|
-
}
|
|
288
|
-
return "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";
|
|
289
|
-
}
|
|
290
|
-
};
|
|
291
|
-
|
|
292
|
-
// src/error-utils.ts
|
|
293
|
-
function isDefinedError(error) {
|
|
294
|
-
return error instanceof ORPCError && error.defined;
|
|
295
|
-
}
|
|
296
|
-
function createORPCErrorConstructorMap(errors) {
|
|
297
|
-
const proxy = new Proxy(errors, {
|
|
298
|
-
get(target, code) {
|
|
299
|
-
if (typeof code !== "string") {
|
|
300
|
-
return Reflect.get(target, code);
|
|
301
|
-
}
|
|
302
|
-
const item = (...[options]) => {
|
|
303
|
-
const config = errors[code];
|
|
304
|
-
return new ORPCError(code, {
|
|
305
|
-
defined: Boolean(config),
|
|
306
|
-
status: config?.status,
|
|
307
|
-
message: options?.message ?? config?.message,
|
|
308
|
-
data: options?.data,
|
|
309
|
-
cause: options?.cause
|
|
310
|
-
});
|
|
311
|
-
};
|
|
312
|
-
return item;
|
|
313
|
-
}
|
|
314
|
-
});
|
|
315
|
-
return proxy;
|
|
316
|
-
}
|
|
317
|
-
async function validateORPCError(map, error) {
|
|
318
|
-
const { code, status, message, data, cause, defined } = error;
|
|
319
|
-
const config = map?.[error.code];
|
|
320
|
-
if (!config || fallbackORPCErrorStatus(error.code, config.status) !== error.status) {
|
|
321
|
-
return defined ? new ORPCError(code, { defined: false, status, message, data, cause }) : error;
|
|
322
|
-
}
|
|
323
|
-
if (!config.data) {
|
|
324
|
-
return defined ? error : new ORPCError(code, { defined: true, status, message, data, cause });
|
|
325
|
-
}
|
|
326
|
-
const validated = await config.data["~standard"].validate(error.data);
|
|
327
|
-
if (validated.issues) {
|
|
328
|
-
return defined ? new ORPCError(code, { defined: false, status, message, data, cause }) : error;
|
|
329
|
-
}
|
|
330
|
-
return new ORPCError(code, { defined: true, status, message, data: validated.value, cause });
|
|
331
|
-
}
|
|
332
|
-
function toORPCError(error) {
|
|
333
|
-
return error instanceof ORPCError ? error : new ORPCError("INTERNAL_SERVER_ERROR", {
|
|
334
|
-
message: "Internal server error",
|
|
335
|
-
cause: error
|
|
336
|
-
});
|
|
337
|
-
}
|
|
338
|
-
|
|
339
|
-
// src/client-utils.ts
|
|
340
|
-
async function safe(promise) {
|
|
341
|
-
try {
|
|
342
|
-
const output = await promise;
|
|
343
|
-
return [output, void 0, false];
|
|
344
|
-
} catch (e) {
|
|
345
|
-
const error = e;
|
|
346
|
-
if (isDefinedError(error)) {
|
|
347
|
-
return [void 0, error, true];
|
|
348
|
-
}
|
|
349
|
-
return [void 0, error, false];
|
|
350
|
-
}
|
|
351
|
-
}
|
|
352
|
-
|
|
353
170
|
// src/config.ts
|
|
354
171
|
var DEFAULT_CONFIG = {
|
|
355
172
|
defaultMethod: "POST",
|
|
@@ -365,48 +182,9 @@ function fallbackContractConfig(key, value) {
|
|
|
365
182
|
return value;
|
|
366
183
|
}
|
|
367
184
|
|
|
368
|
-
// src/error.ts
|
|
369
|
-
var ValidationError = class extends Error {
|
|
370
|
-
issues;
|
|
371
|
-
constructor(options) {
|
|
372
|
-
super(options.message, options);
|
|
373
|
-
this.issues = options.issues;
|
|
374
|
-
}
|
|
375
|
-
};
|
|
376
|
-
|
|
377
185
|
// src/event-iterator.ts
|
|
378
|
-
import {
|
|
379
|
-
|
|
380
|
-
return async function* () {
|
|
381
|
-
try {
|
|
382
|
-
while (true) {
|
|
383
|
-
const { done, value } = await iterator.next();
|
|
384
|
-
let mappedValue = await maps.value(value, done);
|
|
385
|
-
if (mappedValue !== value) {
|
|
386
|
-
const meta = getEventMeta(value);
|
|
387
|
-
if (meta && isEventMetaContainer(mappedValue)) {
|
|
388
|
-
mappedValue = withEventMeta(mappedValue, meta);
|
|
389
|
-
}
|
|
390
|
-
}
|
|
391
|
-
if (done) {
|
|
392
|
-
return mappedValue;
|
|
393
|
-
}
|
|
394
|
-
yield mappedValue;
|
|
395
|
-
}
|
|
396
|
-
} catch (error) {
|
|
397
|
-
let mappedError = await maps.error(error);
|
|
398
|
-
if (mappedError !== error) {
|
|
399
|
-
const meta = getEventMeta(error);
|
|
400
|
-
if (meta && isEventMetaContainer(mappedError)) {
|
|
401
|
-
mappedError = withEventMeta(mappedError, meta);
|
|
402
|
-
}
|
|
403
|
-
}
|
|
404
|
-
throw mappedError;
|
|
405
|
-
} finally {
|
|
406
|
-
await iterator.return?.();
|
|
407
|
-
}
|
|
408
|
-
}();
|
|
409
|
-
}
|
|
186
|
+
import { mapEventIterator, ORPCError } from "@orpc/client";
|
|
187
|
+
import { isAsyncIteratorObject } from "@orpc/server-standard";
|
|
410
188
|
var EVENT_ITERATOR_SCHEMA_SYMBOL = Symbol("ORPC_EVENT_ITERATOR_SCHEMA");
|
|
411
189
|
function eventIterator(yields, returns) {
|
|
412
190
|
return {
|
|
@@ -465,23 +243,20 @@ function type(...[map]) {
|
|
|
465
243
|
}
|
|
466
244
|
};
|
|
467
245
|
}
|
|
246
|
+
|
|
247
|
+
// src/index.ts
|
|
248
|
+
import { ORPCError as ORPCError2 } from "@orpc/client";
|
|
468
249
|
export {
|
|
469
|
-
COMMON_ORPC_ERROR_DEFS,
|
|
470
250
|
ContractBuilder,
|
|
471
251
|
ContractProcedure,
|
|
472
|
-
ORPCError,
|
|
252
|
+
ORPCError2 as ORPCError,
|
|
473
253
|
ValidationError,
|
|
474
254
|
adaptContractRouter,
|
|
475
255
|
adaptRoute,
|
|
476
|
-
createORPCErrorConstructorMap,
|
|
477
256
|
eventIterator,
|
|
478
257
|
fallbackContractConfig,
|
|
479
|
-
fallbackORPCErrorMessage,
|
|
480
|
-
fallbackORPCErrorStatus,
|
|
481
258
|
getEventIteratorSchemaDetails,
|
|
482
259
|
isContractProcedure,
|
|
483
|
-
isDefinedError,
|
|
484
|
-
mapEventIterator,
|
|
485
260
|
mergeErrorMap,
|
|
486
261
|
mergeMeta,
|
|
487
262
|
mergePrefix,
|
|
@@ -489,10 +264,7 @@ export {
|
|
|
489
264
|
mergeTags,
|
|
490
265
|
oc,
|
|
491
266
|
prefixRoute,
|
|
492
|
-
safe,
|
|
493
|
-
toORPCError,
|
|
494
267
|
type,
|
|
495
|
-
unshiftTagRoute
|
|
496
|
-
validateORPCError
|
|
268
|
+
unshiftTagRoute
|
|
497
269
|
};
|
|
498
270
|
//# sourceMappingURL=index.js.map
|
package/dist/src/builder.d.ts
CHANGED
|
@@ -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
|
|
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';
|
package/dist/src/error.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
+
import type { ORPCError, ORPCErrorCode } from '@orpc/client';
|
|
1
2
|
import type { StandardSchemaV1 } from '@standard-schema/spec';
|
|
2
|
-
import type {
|
|
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
|
|
@@ -1,9 +1,5 @@
|
|
|
1
1
|
import type { StandardSchemaV1 } from '@standard-schema/spec';
|
|
2
2
|
import type { Schema } from './schema';
|
|
3
|
-
export declare function mapEventIterator<TYield, TReturn, TNext, TMap = TYield | TReturn>(iterator: AsyncIterator<TYield, TReturn, TNext>, maps: {
|
|
4
|
-
value: (value: NoInfer<TYield | TReturn>, done: boolean | undefined) => Promise<TMap>;
|
|
5
|
-
error: (error: unknown) => Promise<unknown>;
|
|
6
|
-
}): AsyncGenerator<TMap, TMap, TNext>;
|
|
7
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>>;
|
|
8
4
|
export declare function getEventIteratorSchemaDetails(schema: Schema): undefined | {
|
|
9
5
|
yields: Schema;
|
package/dist/src/index.d.ts
CHANGED
|
@@ -1,13 +1,8 @@
|
|
|
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';
|
|
11
6
|
export * from './event-iterator';
|
|
12
7
|
export * from './meta';
|
|
13
8
|
export * from './procedure';
|
|
@@ -16,4 +11,5 @@ export * from './route';
|
|
|
16
11
|
export * from './router';
|
|
17
12
|
export * from './router-client';
|
|
18
13
|
export * from './schema';
|
|
14
|
+
export { ORPCError } from '@orpc/client';
|
|
19
15
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import type { Client, ClientContext } from '
|
|
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
|
package/dist/src/procedure.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import type { ClientContext } from '
|
|
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
|
|
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
|
package/dist/src/router.d.ts
CHANGED
|
@@ -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
|
|
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.
|
|
4
|
+
"version": "0.41.0",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"homepage": "https://orpc.unnoq.com",
|
|
7
7
|
"repository": {
|
|
@@ -31,7 +31,8 @@
|
|
|
31
31
|
"dependencies": {
|
|
32
32
|
"@orpc/server-standard": "^0.4.0",
|
|
33
33
|
"@standard-schema/spec": "^1.0.0",
|
|
34
|
-
"@orpc/
|
|
34
|
+
"@orpc/client": "0.41.0",
|
|
35
|
+
"@orpc/shared": "0.41.0"
|
|
35
36
|
},
|
|
36
37
|
"devDependencies": {
|
|
37
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
|
package/dist/src/client.d.ts
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
export type ClientContext = Record<string, any>;
|
|
2
|
-
export type ClientOptions<TClientContext extends ClientContext> = {
|
|
3
|
-
signal?: AbortSignal;
|
|
4
|
-
lastEventId?: string | undefined;
|
|
5
|
-
} & (Record<never, never> extends TClientContext ? {
|
|
6
|
-
context?: TClientContext;
|
|
7
|
-
} : {
|
|
8
|
-
context: TClientContext;
|
|
9
|
-
});
|
|
10
|
-
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);
|
|
11
|
-
export type ClientPromiseResult<TOutput, TError extends Error> = Promise<TOutput> & {
|
|
12
|
-
__error?: {
|
|
13
|
-
type: TError;
|
|
14
|
-
};
|
|
15
|
-
};
|
|
16
|
-
export interface Client<TClientContext extends ClientContext, TInput, TOutput, TError extends Error> {
|
|
17
|
-
(...rest: ClientRest<TClientContext, TInput>): ClientPromiseResult<TOutput, TError>;
|
|
18
|
-
}
|
|
19
|
-
export type NestedClient<TClientContext extends ClientContext> = Client<TClientContext, any, any, any> | {
|
|
20
|
-
[k: string]: NestedClient<TClientContext>;
|
|
21
|
-
};
|
|
22
|
-
//# sourceMappingURL=client.d.ts.map
|
package/dist/src/error-map.d.ts
DELETED
|
@@ -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
|
package/dist/src/error-orpc.d.ts
DELETED
|
@@ -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>, options?: ErrorOptions): 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
|