@orpc/shared 0.0.0-next.ef3ba82 → 0.0.0-next.f17a1a0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +68 -0
- package/dist/index.js +94 -19
- package/dist/src/chain.d.ts +5 -0
- package/dist/src/error.d.ts +2 -57
- package/dist/src/function.d.ts +2 -0
- package/dist/src/index.d.ts +8 -4
- package/dist/src/interceptor.d.ts +45 -0
- package/dist/src/object.d.ts +6 -1
- package/dist/src/types.d.ts +3 -0
- package/dist/src/value.d.ts +3 -2
- package/package.json +5 -11
- package/dist/error.js +0 -72
- package/dist/src/json.d.ts +0 -1
package/README.md
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
<div align="center">
|
|
2
|
+
<image align="center" src="https://orpc.unnoq.com/logo.webp" width=280 />
|
|
3
|
+
</div>
|
|
4
|
+
|
|
5
|
+
<h1></h1>
|
|
6
|
+
|
|
7
|
+
<div align="center">
|
|
8
|
+
<a href="https://codecov.io/gh/unnoq/orpc">
|
|
9
|
+
<img alt="codecov" src="https://codecov.io/gh/unnoq/orpc/branch/main/graph/badge.svg">
|
|
10
|
+
</a>
|
|
11
|
+
<a href="https://www.npmjs.com/package/@orpc/shared">
|
|
12
|
+
<img alt="weekly downloads" src="https://img.shields.io/npm/dw/%40orpc%2Fshared?logo=npm" />
|
|
13
|
+
</a>
|
|
14
|
+
<a href="https://github.com/unnoq/orpc/blob/main/LICENSE">
|
|
15
|
+
<img alt="MIT License" src="https://img.shields.io/github/license/unnoq/orpc?logo=open-source-initiative" />
|
|
16
|
+
</a>
|
|
17
|
+
<a href="https://discord.gg/TXEbwRBvQn">
|
|
18
|
+
<img alt="Discord" src="https://img.shields.io/discord/1308966753044398161?color=7389D8&label&logo=discord&logoColor=ffffff" />
|
|
19
|
+
</a>
|
|
20
|
+
</div>
|
|
21
|
+
|
|
22
|
+
<h3 align="center">Typesafe APIs Made Simple 🪄</h3>
|
|
23
|
+
|
|
24
|
+
**oRPC is a powerful combination of RPC and OpenAPI**, makes it easy to build APIs that are end-to-end type-safe and adhere to OpenAPI standards, ensuring a smooth and enjoyable developer experience.
|
|
25
|
+
|
|
26
|
+
---
|
|
27
|
+
|
|
28
|
+
## Highlights
|
|
29
|
+
|
|
30
|
+
- **End-to-End Type Safety 🔒**: Ensure complete type safety from inputs to outputs and errors, bridging server and client seamlessly.
|
|
31
|
+
- **First-Class OpenAPI 📄**: Adheres to the OpenAPI standard out of the box, ensuring seamless integration and comprehensive API documentation.
|
|
32
|
+
- **Contract-First Development 📜**: (Optional) Define your API contract upfront and implement it with confidence.
|
|
33
|
+
- **Exceptional Developer Experience ✨**: Enjoy a streamlined workflow with robust typing and clear, in-code documentation.
|
|
34
|
+
- **Multi-Runtime Support 🌍**: Run your code seamlessly on Cloudflare, Deno, Bun, Node.js, and more.
|
|
35
|
+
- **Framework Integrations 🧩**: Supports Tanstack Query (React, Vue), Pinia Colada, and more.
|
|
36
|
+
- **Server Actions ⚡️**: Fully compatible with React Server Actions on Next.js, TanStack Start, and more.
|
|
37
|
+
- **Standard Schema Support 🗂️**: Effortlessly work with Zod, Valibot, ArkType, and others right out of the box.
|
|
38
|
+
- **Fast & Lightweight 💨**: Built on native APIs across all runtimes – optimized for speed and efficiency.
|
|
39
|
+
- **Native Types 📦**: Enjoy built-in support for Date, File, Blob, BigInt, URL and more with no extra setup.
|
|
40
|
+
- **Lazy Router ⏱️**: Improve cold start times with our lazy routing feature.
|
|
41
|
+
- **SSE & Streaming 📡**: Provides SSE and streaming features – perfect for real-time notifications and AI-powered streaming responses.
|
|
42
|
+
- **Reusability 🔄**: Write once and reuse your code across multiple purposes effortlessly.
|
|
43
|
+
- **Extendability 🔌**: Easily enhance oRPC with plugins, middleware, and interceptors.
|
|
44
|
+
- **Reliability 🛡️**: Well-tested, fully TypeScript, production-ready, and MIT licensed for peace of mind.
|
|
45
|
+
- **Simplicity 💡**: Enjoy straightforward, clean code with no hidden magic.
|
|
46
|
+
|
|
47
|
+
## Documentation
|
|
48
|
+
|
|
49
|
+
You can find the full documentation [here](https://orpc.unnoq.com).
|
|
50
|
+
|
|
51
|
+
## Packages
|
|
52
|
+
|
|
53
|
+
- [@orpc/contract](https://www.npmjs.com/package/@orpc/contract): Build your API contract.
|
|
54
|
+
- [@orpc/server](https://www.npmjs.com/package/@orpc/server): Build your API or implement API contract.
|
|
55
|
+
- [@orpc/client](https://www.npmjs.com/package/@orpc/client): Consume your API on the client with type-safety.
|
|
56
|
+
- [@orpc/react-query](https://www.npmjs.com/package/@orpc/react-query): Integration with [React Query](https://tanstack.com/query/latest/docs/framework/react/overview).
|
|
57
|
+
- [@orpc/vue-query](https://www.npmjs.com/package/@orpc/vue-query): Integration with [Vue Query](https://tanstack.com/query/latest/docs/framework/vue/overview).
|
|
58
|
+
- [@orpc/vue-colada](https://www.npmjs.com/package/@orpc/vue-colada): Integration with [Pinia Colada](https://pinia-colada.esm.dev/).
|
|
59
|
+
- [@orpc/openapi](https://www.npmjs.com/package/@orpc/openapi): Generate OpenAPI specs and handle OpenAPI requests.
|
|
60
|
+
- [@orpc/zod](https://www.npmjs.com/package/@orpc/zod): More schemas that [Zod](https://zod.dev/) doesn't support yet.
|
|
61
|
+
|
|
62
|
+
## `@orpc/shared`
|
|
63
|
+
|
|
64
|
+
Provides shared utilities for oRPC packages.
|
|
65
|
+
|
|
66
|
+
## License
|
|
67
|
+
|
|
68
|
+
Distributed under the MIT License. See [LICENSE](https://github.com/unnoq/orpc/blob/main/LICENSE) for more information.
|
package/dist/index.js
CHANGED
|
@@ -1,16 +1,4 @@
|
|
|
1
|
-
// src/json.ts
|
|
2
|
-
function parseJSONSafely(text) {
|
|
3
|
-
if (text === "")
|
|
4
|
-
return void 0;
|
|
5
|
-
try {
|
|
6
|
-
return JSON.parse(text);
|
|
7
|
-
} catch {
|
|
8
|
-
return text;
|
|
9
|
-
}
|
|
10
|
-
}
|
|
11
|
-
|
|
12
1
|
// src/object.ts
|
|
13
|
-
import { isPlainObject } from "is-what";
|
|
14
2
|
function set(root, segments, value2) {
|
|
15
3
|
const ref = { root };
|
|
16
4
|
let currentRef = ref;
|
|
@@ -46,35 +34,122 @@ function findDeepMatches(check, payload, segments = [], maps = [], values = [])
|
|
|
46
34
|
payload.forEach((v, i) => {
|
|
47
35
|
findDeepMatches(check, v, [...segments, i], maps, values);
|
|
48
36
|
});
|
|
49
|
-
} else if (
|
|
37
|
+
} else if (isObject(payload)) {
|
|
50
38
|
for (const key in payload) {
|
|
51
39
|
findDeepMatches(check, payload[key], [...segments, key], maps, values);
|
|
52
40
|
}
|
|
53
41
|
}
|
|
54
42
|
return { maps, values };
|
|
55
43
|
}
|
|
44
|
+
function isObject(value2) {
|
|
45
|
+
if (!value2 || typeof value2 !== "object") {
|
|
46
|
+
return false;
|
|
47
|
+
}
|
|
48
|
+
const proto = Object.getPrototypeOf(value2);
|
|
49
|
+
return proto === Object.prototype || !proto || !proto.constructor;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// src/error.ts
|
|
53
|
+
function toError(error) {
|
|
54
|
+
if (error instanceof Error) {
|
|
55
|
+
return error;
|
|
56
|
+
}
|
|
57
|
+
if (typeof error === "string") {
|
|
58
|
+
return new Error(error, { cause: error });
|
|
59
|
+
}
|
|
60
|
+
if (isObject(error)) {
|
|
61
|
+
if ("message" in error && typeof error.message === "string") {
|
|
62
|
+
return new Error(error.message, { cause: error });
|
|
63
|
+
}
|
|
64
|
+
if ("name" in error && typeof error.name === "string") {
|
|
65
|
+
return new Error(error.name, { cause: error });
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
return new Error("Unknown error", { cause: error });
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// src/interceptor.ts
|
|
72
|
+
function onStart(callback) {
|
|
73
|
+
return async (options, ...rest) => {
|
|
74
|
+
await callback(options, ...rest);
|
|
75
|
+
return await options.next();
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
function onSuccess(callback) {
|
|
79
|
+
return async (options, ...rest) => {
|
|
80
|
+
const result = await options.next();
|
|
81
|
+
await callback(result, options, ...rest);
|
|
82
|
+
return result;
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
function onError(callback) {
|
|
86
|
+
return async (options, ...rest) => {
|
|
87
|
+
try {
|
|
88
|
+
return await options.next();
|
|
89
|
+
} catch (error) {
|
|
90
|
+
await callback(error, options, ...rest);
|
|
91
|
+
throw error;
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
function onFinish(callback) {
|
|
96
|
+
let state;
|
|
97
|
+
return async (options, ...rest) => {
|
|
98
|
+
try {
|
|
99
|
+
const result = await options.next();
|
|
100
|
+
state = [result, void 0, "success"];
|
|
101
|
+
return result;
|
|
102
|
+
} catch (error) {
|
|
103
|
+
state = [void 0, error, "error"];
|
|
104
|
+
throw error;
|
|
105
|
+
} finally {
|
|
106
|
+
await callback(state, options, ...rest);
|
|
107
|
+
}
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
async function intercept(interceptors, options, main) {
|
|
111
|
+
let index = 0;
|
|
112
|
+
const next = async (options2) => {
|
|
113
|
+
const interceptor = interceptors[index++];
|
|
114
|
+
if (!interceptor) {
|
|
115
|
+
return await main(options2);
|
|
116
|
+
}
|
|
117
|
+
return await interceptor({
|
|
118
|
+
...options2,
|
|
119
|
+
next: (newOptions = options2) => next(newOptions)
|
|
120
|
+
});
|
|
121
|
+
};
|
|
122
|
+
return await next(options);
|
|
123
|
+
}
|
|
56
124
|
|
|
57
125
|
// src/value.ts
|
|
58
|
-
function value(value2) {
|
|
126
|
+
function value(value2, ...args) {
|
|
59
127
|
if (typeof value2 === "function") {
|
|
60
|
-
return value2();
|
|
128
|
+
return value2(...args);
|
|
61
129
|
}
|
|
62
130
|
return value2;
|
|
63
131
|
}
|
|
64
132
|
|
|
65
133
|
// src/index.ts
|
|
66
|
-
import {
|
|
67
|
-
import { guard, mapEntries, mapValues, omit, trim } from "radash";
|
|
134
|
+
import { group, guard, mapEntries, mapValues, omit, retry, trim } from "radash";
|
|
68
135
|
export {
|
|
69
136
|
findDeepMatches,
|
|
70
137
|
get,
|
|
138
|
+
group,
|
|
71
139
|
guard,
|
|
72
|
-
|
|
140
|
+
intercept,
|
|
141
|
+
isObject,
|
|
73
142
|
mapEntries,
|
|
74
143
|
mapValues,
|
|
75
144
|
omit,
|
|
76
|
-
|
|
145
|
+
onError,
|
|
146
|
+
onFinish,
|
|
147
|
+
onStart,
|
|
148
|
+
onSuccess,
|
|
149
|
+
retry,
|
|
77
150
|
set,
|
|
151
|
+
toError,
|
|
78
152
|
trim,
|
|
79
153
|
value
|
|
80
154
|
};
|
|
155
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { AnyFunction } from './function';
|
|
2
|
+
export type OmitChainMethodDeep<T extends object, K extends keyof any> = {
|
|
3
|
+
[P in keyof Omit<T, K>]: T[P] extends AnyFunction ? ((...args: Parameters<T[P]>) => OmitChainMethodDeep<ReturnType<T[P]>, K>) : T[P];
|
|
4
|
+
};
|
|
5
|
+
//# sourceMappingURL=chain.d.ts.map
|
package/dist/src/error.d.ts
CHANGED
|
@@ -1,57 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
readonly BAD_REQUEST: 400;
|
|
4
|
-
readonly UNAUTHORIZED: 401;
|
|
5
|
-
readonly FORBIDDEN: 403;
|
|
6
|
-
readonly NOT_FOUND: 404;
|
|
7
|
-
readonly METHOD_NOT_SUPPORTED: 405;
|
|
8
|
-
readonly NOT_ACCEPTABLE: 406;
|
|
9
|
-
readonly TIMEOUT: 408;
|
|
10
|
-
readonly CONFLICT: 409;
|
|
11
|
-
readonly PRECONDITION_FAILED: 412;
|
|
12
|
-
readonly PAYLOAD_TOO_LARGE: 413;
|
|
13
|
-
readonly UNSUPPORTED_MEDIA_TYPE: 415;
|
|
14
|
-
readonly UNPROCESSABLE_CONTENT: 422;
|
|
15
|
-
readonly TOO_MANY_REQUESTS: 429;
|
|
16
|
-
readonly CLIENT_CLOSED_REQUEST: 499;
|
|
17
|
-
readonly INTERNAL_SERVER_ERROR: 500;
|
|
18
|
-
readonly NOT_IMPLEMENTED: 501;
|
|
19
|
-
readonly BAD_GATEWAY: 502;
|
|
20
|
-
readonly SERVICE_UNAVAILABLE: 503;
|
|
21
|
-
readonly GATEWAY_TIMEOUT: 504;
|
|
22
|
-
};
|
|
23
|
-
export type ORPCErrorCode = keyof typeof ORPC_ERROR_CODE_STATUSES;
|
|
24
|
-
export declare class ORPCError<TCode extends ORPCErrorCode, TData> extends Error {
|
|
25
|
-
zz$oe: {
|
|
26
|
-
code: TCode;
|
|
27
|
-
status?: number;
|
|
28
|
-
message?: string;
|
|
29
|
-
cause?: unknown;
|
|
30
|
-
} & (undefined extends TData ? {
|
|
31
|
-
data?: TData;
|
|
32
|
-
} : {
|
|
33
|
-
data: TData;
|
|
34
|
-
});
|
|
35
|
-
constructor(zz$oe: {
|
|
36
|
-
code: TCode;
|
|
37
|
-
status?: number;
|
|
38
|
-
message?: string;
|
|
39
|
-
cause?: unknown;
|
|
40
|
-
} & (undefined extends TData ? {
|
|
41
|
-
data?: TData;
|
|
42
|
-
} : {
|
|
43
|
-
data: TData;
|
|
44
|
-
}));
|
|
45
|
-
get code(): TCode;
|
|
46
|
-
get status(): number;
|
|
47
|
-
get data(): TData;
|
|
48
|
-
get issues(): ZodIssue[] | undefined;
|
|
49
|
-
toJSON(): {
|
|
50
|
-
code: TCode;
|
|
51
|
-
status: number;
|
|
52
|
-
message: string;
|
|
53
|
-
data: TData;
|
|
54
|
-
issues?: ZodIssue[];
|
|
55
|
-
};
|
|
56
|
-
static fromJSON(json: unknown): ORPCError<ORPCErrorCode, any> | undefined;
|
|
57
|
-
}
|
|
1
|
+
export declare function toError(error: unknown): Error;
|
|
2
|
+
//# sourceMappingURL=error.d.ts.map
|
package/dist/src/index.d.ts
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
|
-
export * from './
|
|
1
|
+
export * from './chain';
|
|
2
|
+
export * from './error';
|
|
3
|
+
export * from './function';
|
|
4
|
+
export * from './interceptor';
|
|
2
5
|
export * from './object';
|
|
6
|
+
export * from './types';
|
|
3
7
|
export * from './value';
|
|
4
|
-
export {
|
|
5
|
-
export {
|
|
6
|
-
|
|
8
|
+
export { group, guard, mapEntries, mapValues, omit, retry, trim } from 'radash';
|
|
9
|
+
export type { IsEqual, IsNever, PartialDeep, Promisable } from 'type-fest';
|
|
10
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import type { Promisable } from 'type-fest';
|
|
2
|
+
export type InterceptableOptions = Record<string, any>;
|
|
3
|
+
export type InterceptorOptions<TOptions extends InterceptableOptions, TResult> = Omit<TOptions, 'next'> & {
|
|
4
|
+
next(options?: TOptions): Promise<TResult>;
|
|
5
|
+
};
|
|
6
|
+
export type Interceptor<TOptions extends InterceptableOptions, TResult, TError> = (options: InterceptorOptions<TOptions, TResult>) => Promise<TResult> & {
|
|
7
|
+
__error?: {
|
|
8
|
+
type: TError;
|
|
9
|
+
};
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* Can used for interceptors or middlewares
|
|
13
|
+
*/
|
|
14
|
+
export declare function onStart<TOptions extends {
|
|
15
|
+
next(): any;
|
|
16
|
+
}, TRest extends any[]>(callback: NoInfer<(options: TOptions, ...rest: TRest) => Promisable<void>>): (options: TOptions, ...rest: TRest) => Promise<Awaited<ReturnType<TOptions['next']>>>;
|
|
17
|
+
/**
|
|
18
|
+
* Can used for interceptors or middlewares
|
|
19
|
+
*/
|
|
20
|
+
export declare function onSuccess<TOptions extends {
|
|
21
|
+
next(): any;
|
|
22
|
+
}, TRest extends any[]>(callback: NoInfer<(result: Awaited<ReturnType<TOptions['next']>>, options: TOptions, ...rest: TRest) => Promisable<void>>): (options: TOptions, ...rest: TRest) => Promise<Awaited<ReturnType<TOptions['next']>>>;
|
|
23
|
+
/**
|
|
24
|
+
* Can used for interceptors or middlewares
|
|
25
|
+
*/
|
|
26
|
+
export declare function onError<TError, TOptions extends {
|
|
27
|
+
next(): any;
|
|
28
|
+
}, TRest extends any[]>(callback: NoInfer<(error: TError, options: TOptions, ...rest: TRest) => Promisable<void>>): (options: TOptions, ...rest: TRest) => Promise<Awaited<ReturnType<TOptions['next']>>> & {
|
|
29
|
+
__error?: {
|
|
30
|
+
type: TError;
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
export type OnFinishState<TResult, TError> = [TResult, undefined, 'success'] | [undefined, TError, 'error'];
|
|
34
|
+
/**
|
|
35
|
+
* Can used for interceptors or middlewares
|
|
36
|
+
*/
|
|
37
|
+
export declare function onFinish<TError, TOptions extends {
|
|
38
|
+
next(): any;
|
|
39
|
+
}, TRest extends any[]>(callback: NoInfer<(state: OnFinishState<Awaited<ReturnType<TOptions['next']>>, TError>, options: TOptions, ...rest: TRest) => Promisable<void>>): (options: TOptions, ...rest: TRest) => Promise<Awaited<ReturnType<TOptions['next']>>> & {
|
|
40
|
+
__error?: {
|
|
41
|
+
type: TError;
|
|
42
|
+
};
|
|
43
|
+
};
|
|
44
|
+
export declare function intercept<TOptions extends InterceptableOptions, TResult, TError>(interceptors: Interceptor<TOptions, TResult, TError>[], options: NoInfer<TOptions>, main: NoInfer<(options: TOptions) => Promisable<TResult>>): Promise<TResult>;
|
|
45
|
+
//# sourceMappingURL=interceptor.d.ts.map
|
package/dist/src/object.d.ts
CHANGED
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
export type Segment = string | number;
|
|
2
|
-
export declare function set(root:
|
|
2
|
+
export declare function set(root: unknown, segments: Readonly<Segment[]>, value: unknown): unknown;
|
|
3
3
|
export declare function get(root: Readonly<Record<string, unknown> | unknown[]>, segments: Readonly<Segment[]>): unknown;
|
|
4
4
|
export declare function findDeepMatches(check: (value: unknown) => boolean, payload: unknown, segments?: Segment[], maps?: Segment[][], values?: unknown[]): {
|
|
5
5
|
maps: Segment[][];
|
|
6
6
|
values: unknown[];
|
|
7
7
|
};
|
|
8
|
+
/**
|
|
9
|
+
* Check if the value is an object even it created by `Object.create(null)` or more tricky way.
|
|
10
|
+
*/
|
|
11
|
+
export declare function isObject(value: unknown): value is Record<PropertyKey, unknown>;
|
|
12
|
+
//# sourceMappingURL=object.d.ts.map
|
package/dist/src/value.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
import type { Promisable } from 'type-fest';
|
|
2
|
-
export type Value<T> = T | (() => Promisable<T>);
|
|
3
|
-
export declare function value<T extends
|
|
2
|
+
export type Value<T, TArgs extends any[] = []> = T | ((...args: TArgs) => Promisable<T>);
|
|
3
|
+
export declare function value<T, TArgs extends any[]>(value: Value<T, TArgs>, ...args: NoInfer<TArgs>): Promise<T extends Value<infer U, any> ? U : never>;
|
|
4
|
+
//# sourceMappingURL=value.d.ts.map
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@orpc/shared",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.0.0-next.
|
|
4
|
+
"version": "0.0.0-next.f17a1a0",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"homepage": "https://orpc.unnoq.com",
|
|
7
7
|
"repository": {
|
|
@@ -19,27 +19,21 @@
|
|
|
19
19
|
"import": "./dist/index.js",
|
|
20
20
|
"default": "./dist/index.js"
|
|
21
21
|
},
|
|
22
|
-
"./error": {
|
|
23
|
-
"types": "./dist/src/error.d.ts",
|
|
24
|
-
"import": "./dist/error.js",
|
|
25
|
-
"default": "./dist/error.js"
|
|
26
|
-
},
|
|
27
22
|
"./🔒/*": {
|
|
28
23
|
"types": "./dist/src/*.d.ts"
|
|
29
24
|
}
|
|
30
25
|
},
|
|
31
26
|
"files": [
|
|
32
|
-
"
|
|
27
|
+
"!**/*.map",
|
|
28
|
+
"!**/*.tsbuildinfo",
|
|
33
29
|
"dist"
|
|
34
30
|
],
|
|
35
31
|
"dependencies": {
|
|
36
|
-
"is-what": "^5.0.2",
|
|
37
32
|
"radash": "^12.1.0",
|
|
38
|
-
"type-fest": "^4.26.1"
|
|
39
|
-
"zod": "^3.23.8"
|
|
33
|
+
"type-fest": "^4.26.1"
|
|
40
34
|
},
|
|
41
35
|
"scripts": {
|
|
42
|
-
"build": "tsup --clean --entry.index=src/index.ts --
|
|
36
|
+
"build": "tsup --clean --sourcemap --entry.index=src/index.ts --format=esm --onSuccess='tsc -b --noCheck'",
|
|
43
37
|
"build:watch": "pnpm run build --watch",
|
|
44
38
|
"type:check": "tsc -b"
|
|
45
39
|
}
|
package/dist/error.js
DELETED
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
// src/error.ts
|
|
2
|
-
import { ZodError } from "zod";
|
|
3
|
-
var ORPC_ERROR_CODE_STATUSES = {
|
|
4
|
-
BAD_REQUEST: 400,
|
|
5
|
-
UNAUTHORIZED: 401,
|
|
6
|
-
FORBIDDEN: 403,
|
|
7
|
-
NOT_FOUND: 404,
|
|
8
|
-
METHOD_NOT_SUPPORTED: 405,
|
|
9
|
-
NOT_ACCEPTABLE: 406,
|
|
10
|
-
TIMEOUT: 408,
|
|
11
|
-
CONFLICT: 409,
|
|
12
|
-
PRECONDITION_FAILED: 412,
|
|
13
|
-
PAYLOAD_TOO_LARGE: 413,
|
|
14
|
-
UNSUPPORTED_MEDIA_TYPE: 415,
|
|
15
|
-
UNPROCESSABLE_CONTENT: 422,
|
|
16
|
-
TOO_MANY_REQUESTS: 429,
|
|
17
|
-
CLIENT_CLOSED_REQUEST: 499,
|
|
18
|
-
INTERNAL_SERVER_ERROR: 500,
|
|
19
|
-
NOT_IMPLEMENTED: 501,
|
|
20
|
-
BAD_GATEWAY: 502,
|
|
21
|
-
SERVICE_UNAVAILABLE: 503,
|
|
22
|
-
GATEWAY_TIMEOUT: 504
|
|
23
|
-
};
|
|
24
|
-
var ORPCError = class _ORPCError extends Error {
|
|
25
|
-
constructor(zz$oe) {
|
|
26
|
-
if (zz$oe.status && (zz$oe.status < 400 || zz$oe.status >= 600)) {
|
|
27
|
-
throw new Error("The ORPCError status code must be in the 400-599 range.");
|
|
28
|
-
}
|
|
29
|
-
super(zz$oe.message, { cause: zz$oe.cause });
|
|
30
|
-
this.zz$oe = zz$oe;
|
|
31
|
-
}
|
|
32
|
-
get code() {
|
|
33
|
-
return this.zz$oe.code;
|
|
34
|
-
}
|
|
35
|
-
get status() {
|
|
36
|
-
return this.zz$oe.status ?? ORPC_ERROR_CODE_STATUSES[this.code];
|
|
37
|
-
}
|
|
38
|
-
get data() {
|
|
39
|
-
return this.zz$oe.data;
|
|
40
|
-
}
|
|
41
|
-
get issues() {
|
|
42
|
-
if (this.code === "BAD_REQUEST" && this.zz$oe.cause instanceof ZodError) {
|
|
43
|
-
return this.zz$oe.cause.issues;
|
|
44
|
-
}
|
|
45
|
-
return void 0;
|
|
46
|
-
}
|
|
47
|
-
toJSON() {
|
|
48
|
-
return {
|
|
49
|
-
code: this.code,
|
|
50
|
-
status: this.status,
|
|
51
|
-
message: this.message,
|
|
52
|
-
data: this.data,
|
|
53
|
-
issues: this.issues
|
|
54
|
-
};
|
|
55
|
-
}
|
|
56
|
-
static fromJSON(json) {
|
|
57
|
-
if (typeof json !== "object" || json === null || !("code" in json) || !Object.keys(ORPC_ERROR_CODE_STATUSES).find((key) => json.code === key) || !("status" in json) || typeof json.status !== "number" || "message" in json && json.message !== void 0 && typeof json.message !== "string" || "issues" in json && json.issues !== void 0 && !Array.isArray(json.issues)) {
|
|
58
|
-
return void 0;
|
|
59
|
-
}
|
|
60
|
-
return new _ORPCError({
|
|
61
|
-
code: json.code,
|
|
62
|
-
status: json.status,
|
|
63
|
-
message: Reflect.get(json, "message"),
|
|
64
|
-
data: Reflect.get(json, "data"),
|
|
65
|
-
cause: "issues" in json ? new ZodError(json.issues) : void 0
|
|
66
|
-
});
|
|
67
|
-
}
|
|
68
|
-
};
|
|
69
|
-
export {
|
|
70
|
-
ORPCError,
|
|
71
|
-
ORPC_ERROR_CODE_STATUSES
|
|
72
|
-
};
|
package/dist/src/json.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function parseJSONSafely(text: string): unknown;
|