@orpc/shared 0.0.0-next.a246703 → 0.0.0-next.a2b3a55
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 +1 -0
- package/dist/index.d.mts +32 -29
- package/dist/index.d.ts +32 -29
- package/dist/index.mjs +10 -14
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -58,6 +58,7 @@ You can find the full documentation [here](https://orpc.unnoq.com).
|
|
|
58
58
|
- [@orpc/contract](https://www.npmjs.com/package/@orpc/contract): Build your API contract.
|
|
59
59
|
- [@orpc/server](https://www.npmjs.com/package/@orpc/server): Build your API or implement API contract.
|
|
60
60
|
- [@orpc/client](https://www.npmjs.com/package/@orpc/client): Consume your API on the client with type-safety.
|
|
61
|
+
- [@orpc/react](https://www.npmjs.com/package/@orpc/react): Utilities for integrating oRPC with React and React Server Actions.
|
|
61
62
|
- [@orpc/react-query](https://www.npmjs.com/package/@orpc/react-query): Integration with [React Query](https://tanstack.com/query/latest/docs/framework/react/overview).
|
|
62
63
|
- [@orpc/vue-query](https://www.npmjs.com/package/@orpc/vue-query): Integration with [Vue Query](https://tanstack.com/query/latest/docs/framework/vue/overview).
|
|
63
64
|
- [@orpc/solid-query](https://www.npmjs.com/package/@orpc/solid-query): Integration with [Solid Query](https://tanstack.com/query/latest/docs/framework/solid/overview).
|
package/dist/index.d.mts
CHANGED
|
@@ -5,7 +5,8 @@ export { group, guard, mapEntries, mapValues, omit } from 'radash';
|
|
|
5
5
|
type MaybeOptionalOptions<TOptions> = Record<never, never> extends TOptions ? [options?: TOptions] : [options: TOptions];
|
|
6
6
|
declare function resolveMaybeOptionalOptions<T>(rest: MaybeOptionalOptions<T>): T;
|
|
7
7
|
|
|
8
|
-
declare function toArray<T>(value: T
|
|
8
|
+
declare function toArray<T>(value: T): T extends readonly any[] ? T : Exclude<T, undefined | null>[];
|
|
9
|
+
declare function splitInHalf<T>(arr: readonly T[]): [T[], T[]];
|
|
9
10
|
|
|
10
11
|
type AnyFunction = (...args: any[]) => any;
|
|
11
12
|
declare function once<T extends () => any>(fn: T): () => ReturnType<T>;
|
|
@@ -14,50 +15,54 @@ type OmitChainMethodDeep<T extends object, K extends keyof any> = {
|
|
|
14
15
|
[P in keyof Omit<T, K>]: T[P] extends AnyFunction ? ((...args: Parameters<T[P]>) => OmitChainMethodDeep<ReturnType<T[P]>, K>) : T[P];
|
|
15
16
|
};
|
|
16
17
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
type
|
|
20
|
-
type InterceptorOptions<TOptions extends InterceptableOptions, TResult> = Omit<TOptions, 'next'> & {
|
|
21
|
-
next(options?: TOptions): Promise<TResult>;
|
|
22
|
-
};
|
|
23
|
-
type Interceptor<TOptions extends InterceptableOptions, TResult, TError> = (options: InterceptorOptions<TOptions, TResult>) => Promise<TResult> & {
|
|
18
|
+
type SetOptional<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
|
|
19
|
+
type IntersectPick<T, U> = Pick<T, keyof T & keyof U>;
|
|
20
|
+
type PromiseWithError<T, TError> = Promise<T> & {
|
|
24
21
|
__error?: {
|
|
25
22
|
type: TError;
|
|
26
23
|
};
|
|
27
24
|
};
|
|
25
|
+
/**
|
|
26
|
+
* The place where you can config the orpc types.
|
|
27
|
+
*
|
|
28
|
+
* - `throwableError` the error type that represent throwable errors should be `Error` or `null | undefined | {}` if you want more strict.
|
|
29
|
+
*/
|
|
30
|
+
interface Registry {
|
|
31
|
+
}
|
|
32
|
+
type ThrowableError = Registry extends {
|
|
33
|
+
throwableError: infer T;
|
|
34
|
+
} ? T : Error;
|
|
35
|
+
|
|
36
|
+
type InterceptableOptions = Record<string, any>;
|
|
37
|
+
type InterceptorOptions<TOptions extends InterceptableOptions, TResult, TError> = Omit<TOptions, 'next'> & {
|
|
38
|
+
next(options?: TOptions): PromiseWithError<TResult, TError>;
|
|
39
|
+
};
|
|
40
|
+
type Interceptor<TOptions extends InterceptableOptions, TResult, TError> = (options: InterceptorOptions<TOptions, TResult, TError>) => Promisable<TResult>;
|
|
28
41
|
/**
|
|
29
42
|
* Can used for interceptors or middlewares
|
|
30
43
|
*/
|
|
31
|
-
declare function onStart<TOptions extends {
|
|
44
|
+
declare function onStart<T, TOptions extends {
|
|
32
45
|
next(): any;
|
|
33
|
-
}, TRest extends any[]>(callback: NoInfer<(options: TOptions, ...rest: TRest) => Promisable<void>>): (options: TOptions, ...rest: TRest) => Promise<Awaited<ReturnType<TOptions['next']>>>;
|
|
46
|
+
}, TRest extends any[]>(callback: NoInfer<(options: TOptions, ...rest: TRest) => Promisable<void>>): (options: TOptions, ...rest: TRest) => T | Promise<Awaited<ReturnType<TOptions['next']>>>;
|
|
34
47
|
/**
|
|
35
48
|
* Can used for interceptors or middlewares
|
|
36
49
|
*/
|
|
37
|
-
declare function onSuccess<TOptions extends {
|
|
50
|
+
declare function onSuccess<T, TOptions extends {
|
|
38
51
|
next(): any;
|
|
39
|
-
}, 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']>>>;
|
|
52
|
+
}, TRest extends any[]>(callback: NoInfer<(result: Awaited<ReturnType<TOptions['next']>>, options: TOptions, ...rest: TRest) => Promisable<void>>): (options: TOptions, ...rest: TRest) => T | Promise<Awaited<ReturnType<TOptions['next']>>>;
|
|
40
53
|
/**
|
|
41
54
|
* Can used for interceptors or middlewares
|
|
42
55
|
*/
|
|
43
|
-
declare function onError<
|
|
56
|
+
declare function onError<T, TOptions extends {
|
|
44
57
|
next(): any;
|
|
45
|
-
}, TRest extends any[]>(callback: NoInfer<(error:
|
|
46
|
-
|
|
47
|
-
type: TError;
|
|
48
|
-
};
|
|
49
|
-
};
|
|
50
|
-
type OnFinishState<TResult, TError> = [TResult, null, 'success'] | [undefined, TError, 'error'];
|
|
58
|
+
}, TRest extends any[]>(callback: NoInfer<(error: ReturnType<TOptions['next']> extends PromiseWithError<any, infer E> ? E : ThrowableError, options: TOptions, ...rest: TRest) => Promisable<void>>): (options: TOptions, ...rest: TRest) => T | Promise<Awaited<ReturnType<TOptions['next']>>>;
|
|
59
|
+
type OnFinishState<TResult, TError> = [error: TError, data: undefined, isSuccess: false] | [error: null, data: TResult, isSuccess: true];
|
|
51
60
|
/**
|
|
52
61
|
* Can used for interceptors or middlewares
|
|
53
62
|
*/
|
|
54
|
-
declare function onFinish<
|
|
63
|
+
declare function onFinish<T, TOptions extends {
|
|
55
64
|
next(): any;
|
|
56
|
-
}, TRest extends any[]>(callback: NoInfer<(state: OnFinishState<Awaited<ReturnType<TOptions['next']>>,
|
|
57
|
-
__error?: {
|
|
58
|
-
type: TError;
|
|
59
|
-
};
|
|
60
|
-
};
|
|
65
|
+
}, TRest extends any[]>(callback: NoInfer<(state: OnFinishState<Awaited<ReturnType<TOptions['next']>>, ReturnType<TOptions['next']> extends PromiseWithError<any, infer E> ? E : ThrowableError>, options: TOptions, ...rest: TRest) => Promisable<void>>): (options: TOptions, ...rest: TRest) => T | Promise<Awaited<ReturnType<TOptions['next']>>>;
|
|
61
66
|
declare function intercept<TOptions extends InterceptableOptions, TResult, TError>(interceptors: Interceptor<TOptions, TResult, TError>[], options: NoInfer<TOptions>, main: NoInfer<(options: TOptions) => Promisable<TResult>>): Promise<TResult>;
|
|
62
67
|
|
|
63
68
|
declare function isAsyncIteratorObject(maybe: unknown): maybe is AsyncIteratorObject<any, any, any>;
|
|
@@ -81,10 +86,8 @@ declare function isTypescriptObject(value: unknown): value is object & Record<Pr
|
|
|
81
86
|
declare function clone<T>(value: T): T;
|
|
82
87
|
declare function get(object: object, path: readonly string[]): unknown;
|
|
83
88
|
|
|
84
|
-
type SetOptional<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
|
|
85
|
-
type IntersectPick<T, U> = Pick<T, keyof T & keyof U>;
|
|
86
|
-
|
|
87
89
|
type Value<T, TArgs extends any[] = []> = T | ((...args: TArgs) => Promisable<T>);
|
|
88
90
|
declare function value<T, TArgs extends any[]>(value: Value<T, TArgs>, ...args: NoInfer<TArgs>): Promise<T extends Value<infer U, any> ? U : never>;
|
|
89
91
|
|
|
90
|
-
export {
|
|
92
|
+
export { clone, findDeepMatches, get, intercept, isAsyncIteratorObject, isObject, isTypescriptObject, onError, onFinish, onStart, onSuccess, once, parseEmptyableJSON, resolveMaybeOptionalOptions, splitInHalf, stringifyJSON, toArray, value };
|
|
93
|
+
export type { AnyFunction, InterceptableOptions, Interceptor, InterceptorOptions, IntersectPick, MaybeOptionalOptions, OmitChainMethodDeep, OnFinishState, PromiseWithError, Registry, Segment, SetOptional, ThrowableError, Value };
|
package/dist/index.d.ts
CHANGED
|
@@ -5,7 +5,8 @@ export { group, guard, mapEntries, mapValues, omit } from 'radash';
|
|
|
5
5
|
type MaybeOptionalOptions<TOptions> = Record<never, never> extends TOptions ? [options?: TOptions] : [options: TOptions];
|
|
6
6
|
declare function resolveMaybeOptionalOptions<T>(rest: MaybeOptionalOptions<T>): T;
|
|
7
7
|
|
|
8
|
-
declare function toArray<T>(value: T
|
|
8
|
+
declare function toArray<T>(value: T): T extends readonly any[] ? T : Exclude<T, undefined | null>[];
|
|
9
|
+
declare function splitInHalf<T>(arr: readonly T[]): [T[], T[]];
|
|
9
10
|
|
|
10
11
|
type AnyFunction = (...args: any[]) => any;
|
|
11
12
|
declare function once<T extends () => any>(fn: T): () => ReturnType<T>;
|
|
@@ -14,50 +15,54 @@ type OmitChainMethodDeep<T extends object, K extends keyof any> = {
|
|
|
14
15
|
[P in keyof Omit<T, K>]: T[P] extends AnyFunction ? ((...args: Parameters<T[P]>) => OmitChainMethodDeep<ReturnType<T[P]>, K>) : T[P];
|
|
15
16
|
};
|
|
16
17
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
type
|
|
20
|
-
type InterceptorOptions<TOptions extends InterceptableOptions, TResult> = Omit<TOptions, 'next'> & {
|
|
21
|
-
next(options?: TOptions): Promise<TResult>;
|
|
22
|
-
};
|
|
23
|
-
type Interceptor<TOptions extends InterceptableOptions, TResult, TError> = (options: InterceptorOptions<TOptions, TResult>) => Promise<TResult> & {
|
|
18
|
+
type SetOptional<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
|
|
19
|
+
type IntersectPick<T, U> = Pick<T, keyof T & keyof U>;
|
|
20
|
+
type PromiseWithError<T, TError> = Promise<T> & {
|
|
24
21
|
__error?: {
|
|
25
22
|
type: TError;
|
|
26
23
|
};
|
|
27
24
|
};
|
|
25
|
+
/**
|
|
26
|
+
* The place where you can config the orpc types.
|
|
27
|
+
*
|
|
28
|
+
* - `throwableError` the error type that represent throwable errors should be `Error` or `null | undefined | {}` if you want more strict.
|
|
29
|
+
*/
|
|
30
|
+
interface Registry {
|
|
31
|
+
}
|
|
32
|
+
type ThrowableError = Registry extends {
|
|
33
|
+
throwableError: infer T;
|
|
34
|
+
} ? T : Error;
|
|
35
|
+
|
|
36
|
+
type InterceptableOptions = Record<string, any>;
|
|
37
|
+
type InterceptorOptions<TOptions extends InterceptableOptions, TResult, TError> = Omit<TOptions, 'next'> & {
|
|
38
|
+
next(options?: TOptions): PromiseWithError<TResult, TError>;
|
|
39
|
+
};
|
|
40
|
+
type Interceptor<TOptions extends InterceptableOptions, TResult, TError> = (options: InterceptorOptions<TOptions, TResult, TError>) => Promisable<TResult>;
|
|
28
41
|
/**
|
|
29
42
|
* Can used for interceptors or middlewares
|
|
30
43
|
*/
|
|
31
|
-
declare function onStart<TOptions extends {
|
|
44
|
+
declare function onStart<T, TOptions extends {
|
|
32
45
|
next(): any;
|
|
33
|
-
}, TRest extends any[]>(callback: NoInfer<(options: TOptions, ...rest: TRest) => Promisable<void>>): (options: TOptions, ...rest: TRest) => Promise<Awaited<ReturnType<TOptions['next']>>>;
|
|
46
|
+
}, TRest extends any[]>(callback: NoInfer<(options: TOptions, ...rest: TRest) => Promisable<void>>): (options: TOptions, ...rest: TRest) => T | Promise<Awaited<ReturnType<TOptions['next']>>>;
|
|
34
47
|
/**
|
|
35
48
|
* Can used for interceptors or middlewares
|
|
36
49
|
*/
|
|
37
|
-
declare function onSuccess<TOptions extends {
|
|
50
|
+
declare function onSuccess<T, TOptions extends {
|
|
38
51
|
next(): any;
|
|
39
|
-
}, 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']>>>;
|
|
52
|
+
}, TRest extends any[]>(callback: NoInfer<(result: Awaited<ReturnType<TOptions['next']>>, options: TOptions, ...rest: TRest) => Promisable<void>>): (options: TOptions, ...rest: TRest) => T | Promise<Awaited<ReturnType<TOptions['next']>>>;
|
|
40
53
|
/**
|
|
41
54
|
* Can used for interceptors or middlewares
|
|
42
55
|
*/
|
|
43
|
-
declare function onError<
|
|
56
|
+
declare function onError<T, TOptions extends {
|
|
44
57
|
next(): any;
|
|
45
|
-
}, TRest extends any[]>(callback: NoInfer<(error:
|
|
46
|
-
|
|
47
|
-
type: TError;
|
|
48
|
-
};
|
|
49
|
-
};
|
|
50
|
-
type OnFinishState<TResult, TError> = [TResult, null, 'success'] | [undefined, TError, 'error'];
|
|
58
|
+
}, TRest extends any[]>(callback: NoInfer<(error: ReturnType<TOptions['next']> extends PromiseWithError<any, infer E> ? E : ThrowableError, options: TOptions, ...rest: TRest) => Promisable<void>>): (options: TOptions, ...rest: TRest) => T | Promise<Awaited<ReturnType<TOptions['next']>>>;
|
|
59
|
+
type OnFinishState<TResult, TError> = [error: TError, data: undefined, isSuccess: false] | [error: null, data: TResult, isSuccess: true];
|
|
51
60
|
/**
|
|
52
61
|
* Can used for interceptors or middlewares
|
|
53
62
|
*/
|
|
54
|
-
declare function onFinish<
|
|
63
|
+
declare function onFinish<T, TOptions extends {
|
|
55
64
|
next(): any;
|
|
56
|
-
}, TRest extends any[]>(callback: NoInfer<(state: OnFinishState<Awaited<ReturnType<TOptions['next']>>,
|
|
57
|
-
__error?: {
|
|
58
|
-
type: TError;
|
|
59
|
-
};
|
|
60
|
-
};
|
|
65
|
+
}, TRest extends any[]>(callback: NoInfer<(state: OnFinishState<Awaited<ReturnType<TOptions['next']>>, ReturnType<TOptions['next']> extends PromiseWithError<any, infer E> ? E : ThrowableError>, options: TOptions, ...rest: TRest) => Promisable<void>>): (options: TOptions, ...rest: TRest) => T | Promise<Awaited<ReturnType<TOptions['next']>>>;
|
|
61
66
|
declare function intercept<TOptions extends InterceptableOptions, TResult, TError>(interceptors: Interceptor<TOptions, TResult, TError>[], options: NoInfer<TOptions>, main: NoInfer<(options: TOptions) => Promisable<TResult>>): Promise<TResult>;
|
|
62
67
|
|
|
63
68
|
declare function isAsyncIteratorObject(maybe: unknown): maybe is AsyncIteratorObject<any, any, any>;
|
|
@@ -81,10 +86,8 @@ declare function isTypescriptObject(value: unknown): value is object & Record<Pr
|
|
|
81
86
|
declare function clone<T>(value: T): T;
|
|
82
87
|
declare function get(object: object, path: readonly string[]): unknown;
|
|
83
88
|
|
|
84
|
-
type SetOptional<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
|
|
85
|
-
type IntersectPick<T, U> = Pick<T, keyof T & keyof U>;
|
|
86
|
-
|
|
87
89
|
type Value<T, TArgs extends any[] = []> = T | ((...args: TArgs) => Promisable<T>);
|
|
88
90
|
declare function value<T, TArgs extends any[]>(value: Value<T, TArgs>, ...args: NoInfer<TArgs>): Promise<T extends Value<infer U, any> ? U : never>;
|
|
89
91
|
|
|
90
|
-
export {
|
|
92
|
+
export { clone, findDeepMatches, get, intercept, isAsyncIteratorObject, isObject, isTypescriptObject, onError, onFinish, onStart, onSuccess, once, parseEmptyableJSON, resolveMaybeOptionalOptions, splitInHalf, stringifyJSON, toArray, value };
|
|
93
|
+
export type { AnyFunction, InterceptableOptions, Interceptor, InterceptorOptions, IntersectPick, MaybeOptionalOptions, OmitChainMethodDeep, OnFinishState, PromiseWithError, Registry, Segment, SetOptional, ThrowableError, Value };
|
package/dist/index.mjs
CHANGED
|
@@ -7,12 +7,9 @@ function resolveMaybeOptionalOptions(rest) {
|
|
|
7
7
|
function toArray(value) {
|
|
8
8
|
return Array.isArray(value) ? value : value === void 0 || value === null ? [] : [value];
|
|
9
9
|
}
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
return error;
|
|
14
|
-
}
|
|
15
|
-
return new Error("Unknown error", { cause: error });
|
|
10
|
+
function splitInHalf(arr) {
|
|
11
|
+
const half = Math.ceil(arr.length / 2);
|
|
12
|
+
return [arr.slice(0, half), arr.slice(half)];
|
|
16
13
|
}
|
|
17
14
|
|
|
18
15
|
function once(fn) {
|
|
@@ -55,10 +52,10 @@ function onFinish(callback) {
|
|
|
55
52
|
return async (options, ...rest) => {
|
|
56
53
|
try {
|
|
57
54
|
const result = await options.next();
|
|
58
|
-
state = [
|
|
55
|
+
state = [null, result, true];
|
|
59
56
|
return result;
|
|
60
57
|
} catch (error) {
|
|
61
|
-
state = [void 0,
|
|
58
|
+
state = [error, void 0, false];
|
|
62
59
|
throw error;
|
|
63
60
|
} finally {
|
|
64
61
|
await callback(state, options, ...rest);
|
|
@@ -66,18 +63,17 @@ function onFinish(callback) {
|
|
|
66
63
|
};
|
|
67
64
|
}
|
|
68
65
|
async function intercept(interceptors, options, main) {
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
const interceptor = interceptors[index++];
|
|
66
|
+
const next = async (options2, index) => {
|
|
67
|
+
const interceptor = interceptors[index];
|
|
72
68
|
if (!interceptor) {
|
|
73
69
|
return await main(options2);
|
|
74
70
|
}
|
|
75
71
|
return await interceptor({
|
|
76
72
|
...options2,
|
|
77
|
-
next: (newOptions = options2) => next(newOptions)
|
|
73
|
+
next: (newOptions = options2) => next(newOptions, index + 1)
|
|
78
74
|
});
|
|
79
75
|
};
|
|
80
|
-
return
|
|
76
|
+
return next(options, 0);
|
|
81
77
|
}
|
|
82
78
|
|
|
83
79
|
function isAsyncIteratorObject(maybe) {
|
|
@@ -153,4 +149,4 @@ function value(value2, ...args) {
|
|
|
153
149
|
return value2;
|
|
154
150
|
}
|
|
155
151
|
|
|
156
|
-
export { clone, findDeepMatches, get, intercept, isAsyncIteratorObject, isObject, isTypescriptObject, onError, onFinish, onStart, onSuccess, once, parseEmptyableJSON, resolveMaybeOptionalOptions, stringifyJSON, toArray,
|
|
152
|
+
export { clone, findDeepMatches, get, intercept, isAsyncIteratorObject, isObject, isTypescriptObject, onError, onFinish, onStart, onSuccess, once, parseEmptyableJSON, resolveMaybeOptionalOptions, splitInHalf, stringifyJSON, toArray, value };
|
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.a2b3a55",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"homepage": "https://orpc.unnoq.com",
|
|
7
7
|
"repository": {
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
],
|
|
26
26
|
"dependencies": {
|
|
27
27
|
"radash": "^12.1.0",
|
|
28
|
-
"type-fest": "^4.
|
|
28
|
+
"type-fest": "^4.39.1"
|
|
29
29
|
},
|
|
30
30
|
"scripts": {
|
|
31
31
|
"build": "unbuild",
|