@orpc/shared 0.0.0-next.6a8bf13 → 0.0.0-next.6acfc62
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 +143 -17
- package/dist/src/chain.d.ts +5 -0
- package/dist/src/constants.d.ts +3 -0
- package/dist/src/error.d.ts +1 -62
- package/dist/src/function.d.ts +3 -0
- package/dist/src/hook.d.ts +4 -4
- package/dist/src/index.d.ts +7 -1
- package/dist/src/interceptor.d.ts +47 -0
- package/dist/src/object.d.ts +1 -1
- package/dist/src/proxy.d.ts +3 -0
- package/dist/src/value.d.ts +2 -2
- package/package.json +4 -9
- package/dist/chunk-4KZEIATV.js +0 -92
- package/dist/error.js +0 -11
package/dist/index.js
CHANGED
|
@@ -1,17 +1,50 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
// src/constants.ts
|
|
2
|
+
var ORPC_HANDLER_HEADER = "x-orpc-handler";
|
|
3
|
+
var ORPC_HANDLER_VALUE = "orpc";
|
|
4
|
+
|
|
5
|
+
// src/error.ts
|
|
6
|
+
import { isPlainObject } from "is-what";
|
|
7
|
+
function toError(error) {
|
|
8
|
+
if (error instanceof Error) {
|
|
9
|
+
return error;
|
|
10
|
+
}
|
|
11
|
+
if (typeof error === "string") {
|
|
12
|
+
return new Error(error, { cause: error });
|
|
13
|
+
}
|
|
14
|
+
if (isPlainObject(error)) {
|
|
15
|
+
if ("message" in error && typeof error.message === "string") {
|
|
16
|
+
return new Error(error.message, { cause: error });
|
|
17
|
+
}
|
|
18
|
+
if ("name" in error && typeof error.name === "string") {
|
|
19
|
+
return new Error(error.name, { cause: error });
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
return new Error("Unknown error", { cause: error });
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// src/function.ts
|
|
26
|
+
function once(fn) {
|
|
27
|
+
let cached;
|
|
28
|
+
return () => {
|
|
29
|
+
if (cached) {
|
|
30
|
+
return cached.result;
|
|
31
|
+
}
|
|
32
|
+
const result = fn();
|
|
33
|
+
cached = { result };
|
|
34
|
+
return result;
|
|
35
|
+
};
|
|
36
|
+
}
|
|
4
37
|
|
|
5
38
|
// src/hook.ts
|
|
6
39
|
async function executeWithHooks(options) {
|
|
7
|
-
const
|
|
40
|
+
const interceptors = convertToArray(options.hooks?.interceptor);
|
|
8
41
|
const onStarts = convertToArray(options.hooks?.onStart);
|
|
9
42
|
const onSuccesses = convertToArray(options.hooks?.onSuccess);
|
|
10
43
|
const onErrors = convertToArray(options.hooks?.onError);
|
|
11
44
|
const onFinishes = convertToArray(options.hooks?.onFinish);
|
|
12
45
|
let currentExecuteIndex = 0;
|
|
13
46
|
const next = async () => {
|
|
14
|
-
const execute =
|
|
47
|
+
const execute = interceptors[currentExecuteIndex];
|
|
15
48
|
if (execute) {
|
|
16
49
|
currentExecuteIndex++;
|
|
17
50
|
return await execute(options.input, options.context, {
|
|
@@ -21,8 +54,8 @@ async function executeWithHooks(options) {
|
|
|
21
54
|
}
|
|
22
55
|
let state = { status: "pending", input: options.input, output: void 0, error: void 0 };
|
|
23
56
|
try {
|
|
24
|
-
for (const
|
|
25
|
-
await
|
|
57
|
+
for (const onStart2 of onStarts) {
|
|
58
|
+
await onStart2(state, options.context, options.meta);
|
|
26
59
|
}
|
|
27
60
|
const output = await options.execute();
|
|
28
61
|
state = { status: "success", input: options.input, output, error: void 0 };
|
|
@@ -30,12 +63,12 @@ async function executeWithHooks(options) {
|
|
|
30
63
|
await onSuccesses[i](state, options.context, options.meta);
|
|
31
64
|
}
|
|
32
65
|
} catch (e) {
|
|
33
|
-
state = { status: "error", input: options.input, error:
|
|
66
|
+
state = { status: "error", input: options.input, error: toError(e), output: void 0 };
|
|
34
67
|
for (let i = onErrors.length - 1; i >= 0; i--) {
|
|
35
68
|
try {
|
|
36
69
|
await onErrors[i](state, options.context, options.meta);
|
|
37
70
|
} catch (e2) {
|
|
38
|
-
state = { status: "error", input: options.input, error:
|
|
71
|
+
state = { status: "error", input: options.input, error: toError(e2), output: void 0 };
|
|
39
72
|
}
|
|
40
73
|
}
|
|
41
74
|
}
|
|
@@ -43,7 +76,7 @@ async function executeWithHooks(options) {
|
|
|
43
76
|
try {
|
|
44
77
|
await onFinishes[i](state, options.context, options.meta);
|
|
45
78
|
} catch (e) {
|
|
46
|
-
state = { status: "error", input: options.input, error:
|
|
79
|
+
state = { status: "error", input: options.input, error: toError(e), output: void 0 };
|
|
47
80
|
}
|
|
48
81
|
}
|
|
49
82
|
if (state.status === "error") {
|
|
@@ -60,6 +93,60 @@ function convertToArray(value2) {
|
|
|
60
93
|
return Array.isArray(value2) ? value2 : [value2];
|
|
61
94
|
}
|
|
62
95
|
|
|
96
|
+
// src/interceptor.ts
|
|
97
|
+
function onStart(callback) {
|
|
98
|
+
return async (options, ...rest) => {
|
|
99
|
+
await callback(options, ...rest);
|
|
100
|
+
return await options.next();
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
function onSuccess(callback) {
|
|
104
|
+
return async (options, ...rest) => {
|
|
105
|
+
const result = await options.next();
|
|
106
|
+
await callback(result, options, ...rest);
|
|
107
|
+
return result;
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
function onError(callback) {
|
|
111
|
+
return async (options, ...rest) => {
|
|
112
|
+
try {
|
|
113
|
+
return await options.next();
|
|
114
|
+
} catch (error) {
|
|
115
|
+
await callback(error, options, ...rest);
|
|
116
|
+
throw error;
|
|
117
|
+
}
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
function onFinish(callback) {
|
|
121
|
+
let state;
|
|
122
|
+
return async (options, ...rest) => {
|
|
123
|
+
try {
|
|
124
|
+
const result = await options.next();
|
|
125
|
+
state = [result, void 0, "success"];
|
|
126
|
+
return result;
|
|
127
|
+
} catch (error) {
|
|
128
|
+
state = [void 0, error, "error"];
|
|
129
|
+
throw error;
|
|
130
|
+
} finally {
|
|
131
|
+
await callback(state, options, ...rest);
|
|
132
|
+
}
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
async function intercept(interceptors, options, main) {
|
|
136
|
+
let index = 0;
|
|
137
|
+
const next = async (nextOptions = options) => {
|
|
138
|
+
const interceptor = interceptors[index++];
|
|
139
|
+
if (!interceptor) {
|
|
140
|
+
return await main(nextOptions);
|
|
141
|
+
}
|
|
142
|
+
return await interceptor({
|
|
143
|
+
...nextOptions,
|
|
144
|
+
next
|
|
145
|
+
});
|
|
146
|
+
};
|
|
147
|
+
return await next();
|
|
148
|
+
}
|
|
149
|
+
|
|
63
150
|
// src/json.ts
|
|
64
151
|
function parseJSONSafely(text) {
|
|
65
152
|
if (text === "")
|
|
@@ -72,7 +159,7 @@ function parseJSONSafely(text) {
|
|
|
72
159
|
}
|
|
73
160
|
|
|
74
161
|
// src/object.ts
|
|
75
|
-
import { isPlainObject } from "is-what";
|
|
162
|
+
import { isPlainObject as isPlainObject2 } from "is-what";
|
|
76
163
|
function set(root, segments, value2) {
|
|
77
164
|
const ref = { root };
|
|
78
165
|
let currentRef = ref;
|
|
@@ -108,7 +195,7 @@ function findDeepMatches(check, payload, segments = [], maps = [], values = [])
|
|
|
108
195
|
payload.forEach((v, i) => {
|
|
109
196
|
findDeepMatches(check, v, [...segments, i], maps, values);
|
|
110
197
|
});
|
|
111
|
-
} else if (
|
|
198
|
+
} else if (isPlainObject2(payload)) {
|
|
112
199
|
for (const key in payload) {
|
|
113
200
|
findDeepMatches(check, payload[key], [...segments, key], maps, values);
|
|
114
201
|
}
|
|
@@ -116,29 +203,68 @@ function findDeepMatches(check, payload, segments = [], maps = [], values = [])
|
|
|
116
203
|
return { maps, values };
|
|
117
204
|
}
|
|
118
205
|
|
|
206
|
+
// src/proxy.ts
|
|
207
|
+
function createCallableObject(obj, handler) {
|
|
208
|
+
const proxy = new Proxy(handler, {
|
|
209
|
+
has(target, key) {
|
|
210
|
+
return Reflect.has(obj, key) || Reflect.has(target, key);
|
|
211
|
+
},
|
|
212
|
+
ownKeys(target) {
|
|
213
|
+
return Array.from(new Set(Reflect.ownKeys(obj).concat(...Reflect.ownKeys(target))));
|
|
214
|
+
},
|
|
215
|
+
get(target, key) {
|
|
216
|
+
if (!Reflect.has(target, key) || Reflect.has(obj, key)) {
|
|
217
|
+
return Reflect.get(obj, key);
|
|
218
|
+
}
|
|
219
|
+
return Reflect.get(target, key);
|
|
220
|
+
},
|
|
221
|
+
defineProperty(_, key, descriptor) {
|
|
222
|
+
return Reflect.defineProperty(obj, key, descriptor);
|
|
223
|
+
},
|
|
224
|
+
set(_, key, value2) {
|
|
225
|
+
return Reflect.set(obj, key, value2);
|
|
226
|
+
},
|
|
227
|
+
deleteProperty(target, key) {
|
|
228
|
+
return Reflect.deleteProperty(target, key) && Reflect.deleteProperty(obj, key);
|
|
229
|
+
}
|
|
230
|
+
});
|
|
231
|
+
return proxy;
|
|
232
|
+
}
|
|
233
|
+
|
|
119
234
|
// src/value.ts
|
|
120
|
-
function value(value2) {
|
|
235
|
+
function value(value2, ...args) {
|
|
121
236
|
if (typeof value2 === "function") {
|
|
122
|
-
return value2();
|
|
237
|
+
return value2(...args);
|
|
123
238
|
}
|
|
124
239
|
return value2;
|
|
125
240
|
}
|
|
126
241
|
|
|
127
242
|
// src/index.ts
|
|
128
|
-
import { isPlainObject as
|
|
129
|
-
import { guard, mapEntries, mapValues, omit, trim } from "radash";
|
|
243
|
+
import { isPlainObject as isPlainObject3 } from "is-what";
|
|
244
|
+
import { group, guard, mapEntries, mapValues, omit, trim } from "radash";
|
|
130
245
|
export {
|
|
246
|
+
ORPC_HANDLER_HEADER,
|
|
247
|
+
ORPC_HANDLER_VALUE,
|
|
131
248
|
convertToArray,
|
|
249
|
+
createCallableObject,
|
|
132
250
|
executeWithHooks,
|
|
133
251
|
findDeepMatches,
|
|
134
252
|
get,
|
|
253
|
+
group,
|
|
135
254
|
guard,
|
|
136
|
-
|
|
255
|
+
intercept,
|
|
256
|
+
isPlainObject3 as isPlainObject,
|
|
137
257
|
mapEntries,
|
|
138
258
|
mapValues,
|
|
139
259
|
omit,
|
|
260
|
+
onError,
|
|
261
|
+
onFinish,
|
|
262
|
+
onStart,
|
|
263
|
+
onSuccess,
|
|
264
|
+
once,
|
|
140
265
|
parseJSONSafely,
|
|
141
266
|
set,
|
|
267
|
+
toError,
|
|
142
268
|
trim,
|
|
143
269
|
value
|
|
144
270
|
};
|
|
@@ -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,63 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
export declare const ORPC_ERROR_CODE_STATUSES: {
|
|
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 interface ORPCErrorJSON<TCode extends ORPCErrorCode, TData> {
|
|
25
|
-
code: TCode;
|
|
26
|
-
status: number;
|
|
27
|
-
message: string;
|
|
28
|
-
data: TData;
|
|
29
|
-
issues?: ZodIssue[];
|
|
30
|
-
}
|
|
31
|
-
export type ANY_ORPC_ERROR_JSON = ORPCErrorJSON<any, any>;
|
|
32
|
-
export type WELL_ORPC_ERROR_JSON = ORPCErrorJSON<ORPCErrorCode, unknown>;
|
|
33
|
-
export declare class ORPCError<TCode extends ORPCErrorCode, TData> extends Error {
|
|
34
|
-
zz$oe: {
|
|
35
|
-
code: TCode;
|
|
36
|
-
status?: number;
|
|
37
|
-
message?: string;
|
|
38
|
-
cause?: unknown;
|
|
39
|
-
} & (undefined extends TData ? {
|
|
40
|
-
data?: TData;
|
|
41
|
-
} : {
|
|
42
|
-
data: TData;
|
|
43
|
-
});
|
|
44
|
-
constructor(zz$oe: {
|
|
45
|
-
code: TCode;
|
|
46
|
-
status?: number;
|
|
47
|
-
message?: string;
|
|
48
|
-
cause?: unknown;
|
|
49
|
-
} & (undefined extends TData ? {
|
|
50
|
-
data?: TData;
|
|
51
|
-
} : {
|
|
52
|
-
data: TData;
|
|
53
|
-
}));
|
|
54
|
-
get code(): TCode;
|
|
55
|
-
get status(): number;
|
|
56
|
-
get data(): TData;
|
|
57
|
-
get issues(): ZodIssue[] | undefined;
|
|
58
|
-
toJSON(): ORPCErrorJSON<TCode, TData>;
|
|
59
|
-
static fromJSON(json: unknown): ORPCError<ORPCErrorCode, any> | undefined;
|
|
60
|
-
}
|
|
61
|
-
export type WELL_ORPC_ERROR = ORPCError<ORPCErrorCode, unknown>;
|
|
62
|
-
export declare function convertToStandardError(error: unknown): Error;
|
|
1
|
+
export declare function toError(error: unknown): Error;
|
|
63
2
|
//# sourceMappingURL=error.d.ts.map
|
package/dist/src/hook.d.ts
CHANGED
|
@@ -18,18 +18,18 @@ export type OnErrorState<TInput> = {
|
|
|
18
18
|
error: Error;
|
|
19
19
|
};
|
|
20
20
|
export interface BaseHookMeta<TOutput> {
|
|
21
|
-
next
|
|
21
|
+
next(): Promise<TOutput>;
|
|
22
22
|
}
|
|
23
|
-
export interface Hooks<TInput, TOutput, TContext, TMeta extends (Record<string,
|
|
23
|
+
export interface Hooks<TInput, TOutput, TContext, TMeta extends (Record<string, any> & {
|
|
24
24
|
next?: never;
|
|
25
25
|
}) | undefined> {
|
|
26
|
-
|
|
26
|
+
interceptor?: Arrayable<(input: TInput, context: TContext, meta: (TMeta extends undefined ? unknown : TMeta) & BaseHookMeta<TOutput>) => Promise<TOutput>>;
|
|
27
27
|
onStart?: Arrayable<(state: OnStartState<TInput>, context: TContext, meta: TMeta) => Promisable<void>>;
|
|
28
28
|
onSuccess?: Arrayable<(state: OnSuccessState<TInput, TOutput>, context: TContext, meta: TMeta) => Promisable<void>>;
|
|
29
29
|
onError?: Arrayable<(state: OnErrorState<TInput>, context: TContext, meta: TMeta) => Promisable<void>>;
|
|
30
30
|
onFinish?: Arrayable<(state: OnSuccessState<TInput, TOutput> | OnErrorState<TInput>, context: TContext, meta: TMeta) => Promisable<void>>;
|
|
31
31
|
}
|
|
32
|
-
export declare function executeWithHooks<TInput, TOutput, TContext, TMeta extends (Record<string,
|
|
32
|
+
export declare function executeWithHooks<TInput, TOutput, TContext, TMeta extends (Record<string, any> & {
|
|
33
33
|
next?: never;
|
|
34
34
|
}) | undefined>(options: {
|
|
35
35
|
hooks?: Hooks<TInput, TOutput, TContext, TMeta>;
|
package/dist/src/index.d.ts
CHANGED
|
@@ -1,8 +1,14 @@
|
|
|
1
|
+
export * from './chain';
|
|
2
|
+
export * from './constants';
|
|
3
|
+
export * from './error';
|
|
4
|
+
export * from './function';
|
|
1
5
|
export * from './hook';
|
|
6
|
+
export * from './interceptor';
|
|
2
7
|
export * from './json';
|
|
3
8
|
export * from './object';
|
|
9
|
+
export * from './proxy';
|
|
4
10
|
export * from './value';
|
|
5
11
|
export { isPlainObject } from 'is-what';
|
|
6
|
-
export { guard, mapEntries, mapValues, omit, trim } from 'radash';
|
|
12
|
+
export { group, guard, mapEntries, mapValues, omit, trim } from 'radash';
|
|
7
13
|
export type * from 'type-fest';
|
|
8
14
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import type { Promisable } from 'type-fest';
|
|
2
|
+
import type { AnyFunction } from './function';
|
|
3
|
+
export type InterceptableOptions = Record<string, any>;
|
|
4
|
+
export type InterceptorOptions<TOptions extends InterceptableOptions, TResult> = Omit<TOptions, 'next'> & {
|
|
5
|
+
next(options?: TOptions): Promise<TResult>;
|
|
6
|
+
};
|
|
7
|
+
export type Interceptor<TOptions extends InterceptableOptions, TResult, TError> = (options: InterceptorOptions<TOptions, TResult>) => Promise<TResult> & {
|
|
8
|
+
__error?: {
|
|
9
|
+
type: TError;
|
|
10
|
+
};
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* Can used for interceptors or middlewares
|
|
14
|
+
*/
|
|
15
|
+
export declare function onStart<TOptions extends {
|
|
16
|
+
next(): any;
|
|
17
|
+
}, TRest extends any[]>(callback: NoInfer<(options: TOptions, ...rest: TRest) => Promisable<void>>): (options: TOptions, ...rest: TRest) => Promise<Awaited<ReturnType<TOptions['next']>>>;
|
|
18
|
+
/**
|
|
19
|
+
* Can used for interceptors or middlewares
|
|
20
|
+
*/
|
|
21
|
+
export declare function onSuccess<TOptions extends {
|
|
22
|
+
next(): any;
|
|
23
|
+
}, 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']>>>;
|
|
24
|
+
export type InferError<T extends AnyFunction> = T extends Interceptor<any, any, infer TError> ? TError : unknown;
|
|
25
|
+
/**
|
|
26
|
+
* Can used for interceptors or middlewares
|
|
27
|
+
*/
|
|
28
|
+
export declare function onError<TError, TOptions extends {
|
|
29
|
+
next(): any;
|
|
30
|
+
}, TRest extends any[]>(callback: NoInfer<(error: TError, options: TOptions, ...rest: TRest) => Promisable<void>>): (options: TOptions, ...rest: TRest) => Promise<Awaited<ReturnType<TOptions['next']>>> & {
|
|
31
|
+
__error?: {
|
|
32
|
+
type: TError;
|
|
33
|
+
};
|
|
34
|
+
};
|
|
35
|
+
export type OnFinishState<TResult, TError> = [TResult, undefined, 'success'] | [undefined, TError, 'error'];
|
|
36
|
+
/**
|
|
37
|
+
* Can used for interceptors or middlewares
|
|
38
|
+
*/
|
|
39
|
+
export declare function onFinish<TError, TOptions extends {
|
|
40
|
+
next(): any;
|
|
41
|
+
}, 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']>>> & {
|
|
42
|
+
__error?: {
|
|
43
|
+
type: TError;
|
|
44
|
+
};
|
|
45
|
+
};
|
|
46
|
+
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>;
|
|
47
|
+
//# sourceMappingURL=interceptor.d.ts.map
|
package/dist/src/object.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
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[][];
|
package/dist/src/value.d.ts
CHANGED
|
@@ -1,4 +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 Value<any
|
|
2
|
+
export type Value<T, TArgs extends any[] = []> = T | ((...args: TArgs) => Promisable<T>);
|
|
3
|
+
export declare function value<T extends Value<any, TArgs>, TArgs extends any[] = []>(value: T, ...args: TArgs): Promise<T extends Value<infer U, any> ? U : never>;
|
|
4
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.6acfc62",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"homepage": "https://orpc.unnoq.com",
|
|
7
7
|
"repository": {
|
|
@@ -19,11 +19,6 @@
|
|
|
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
|
}
|
|
@@ -34,13 +29,13 @@
|
|
|
34
29
|
"dist"
|
|
35
30
|
],
|
|
36
31
|
"dependencies": {
|
|
32
|
+
"@standard-schema/spec": "1.0.0-beta.4",
|
|
37
33
|
"is-what": "^5.0.2",
|
|
38
34
|
"radash": "^12.1.0",
|
|
39
|
-
"type-fest": "^4.26.1"
|
|
40
|
-
"zod": "^3.23.8"
|
|
35
|
+
"type-fest": "^4.26.1"
|
|
41
36
|
},
|
|
42
37
|
"scripts": {
|
|
43
|
-
"build": "tsup --clean --sourcemap --entry.index=src/index.ts --
|
|
38
|
+
"build": "tsup --clean --sourcemap --entry.index=src/index.ts --format=esm --onSuccess='tsc -b --noCheck'",
|
|
44
39
|
"build:watch": "pnpm run build --watch",
|
|
45
40
|
"type:check": "tsc -b"
|
|
46
41
|
}
|
package/dist/chunk-4KZEIATV.js
DELETED
|
@@ -1,92 +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
|
-
function convertToStandardError(error) {
|
|
70
|
-
if (error instanceof Error) {
|
|
71
|
-
return error;
|
|
72
|
-
}
|
|
73
|
-
if (typeof error === "string") {
|
|
74
|
-
return new Error(error, { cause: error });
|
|
75
|
-
}
|
|
76
|
-
if (typeof error === "object" && error !== null) {
|
|
77
|
-
if ("message" in error && typeof error.message === "string") {
|
|
78
|
-
return new Error(error.message, { cause: error });
|
|
79
|
-
}
|
|
80
|
-
if ("name" in error && typeof error.name === "string") {
|
|
81
|
-
return new Error(error.name, { cause: error });
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
return new Error("Unknown error", { cause: error });
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
export {
|
|
88
|
-
ORPC_ERROR_CODE_STATUSES,
|
|
89
|
-
ORPCError,
|
|
90
|
-
convertToStandardError
|
|
91
|
-
};
|
|
92
|
-
//# sourceMappingURL=chunk-4KZEIATV.js.map
|