@orpc/shared 0.51.0 → 0.52.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/README.md +1 -0
- package/dist/index.d.mts +25 -23
- package/dist/index.d.ts +25 -23
- package/dist/index.mjs +11 -8
- package/package.json +1 -1
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
|
@@ -14,17 +14,29 @@ type OmitChainMethodDeep<T extends object, K extends keyof any> = {
|
|
|
14
14
|
[P in keyof Omit<T, K>]: T[P] extends AnyFunction ? ((...args: Parameters<T[P]>) => OmitChainMethodDeep<ReturnType<T[P]>, K>) : T[P];
|
|
15
15
|
};
|
|
16
16
|
|
|
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> & {
|
|
17
|
+
type SetOptional<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
|
|
18
|
+
type IntersectPick<T, U> = Pick<T, keyof T & keyof U>;
|
|
19
|
+
type PromiseWithError<T, TError> = Promise<T> & {
|
|
24
20
|
__error?: {
|
|
25
21
|
type: TError;
|
|
26
22
|
};
|
|
27
23
|
};
|
|
24
|
+
/**
|
|
25
|
+
* The place where you can config the orpc types.
|
|
26
|
+
*
|
|
27
|
+
* - `throwableError` the error type that represent throwable errors should be `Error` or `null | undefined | {}` if you want more strict.
|
|
28
|
+
*/
|
|
29
|
+
interface Registry {
|
|
30
|
+
}
|
|
31
|
+
type ThrowableError = Registry extends {
|
|
32
|
+
throwableError: infer T;
|
|
33
|
+
} ? T : Error;
|
|
34
|
+
|
|
35
|
+
type InterceptableOptions = Record<string, any>;
|
|
36
|
+
type InterceptorOptions<TOptions extends InterceptableOptions, TResult, TError> = Omit<TOptions, 'next'> & {
|
|
37
|
+
next(options?: TOptions): PromiseWithError<TResult, TError>;
|
|
38
|
+
};
|
|
39
|
+
type Interceptor<TOptions extends InterceptableOptions, TResult, TError> = (options: InterceptorOptions<TOptions, TResult, TError>) => PromiseWithError<TResult, TError>;
|
|
28
40
|
/**
|
|
29
41
|
* Can used for interceptors or middlewares
|
|
30
42
|
*/
|
|
@@ -40,24 +52,16 @@ declare function onSuccess<TOptions extends {
|
|
|
40
52
|
/**
|
|
41
53
|
* Can used for interceptors or middlewares
|
|
42
54
|
*/
|
|
43
|
-
declare function onError<
|
|
55
|
+
declare function onError<TOptions extends {
|
|
44
56
|
next(): any;
|
|
45
|
-
}, TRest extends any[]>(callback: NoInfer<(error:
|
|
46
|
-
__error?: {
|
|
47
|
-
type: TError;
|
|
48
|
-
};
|
|
49
|
-
};
|
|
57
|
+
}, 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) => Promise<Awaited<ReturnType<TOptions['next']>>>;
|
|
50
58
|
type OnFinishState<TResult, TError> = [TResult, null, 'success'] | [undefined, TError, 'error'];
|
|
51
59
|
/**
|
|
52
60
|
* Can used for interceptors or middlewares
|
|
53
61
|
*/
|
|
54
|
-
declare function onFinish<
|
|
62
|
+
declare function onFinish<TOptions extends {
|
|
55
63
|
next(): any;
|
|
56
|
-
}, TRest extends any[]>(callback: NoInfer<(state: OnFinishState<Awaited<ReturnType<TOptions['next']>>,
|
|
57
|
-
__error?: {
|
|
58
|
-
type: TError;
|
|
59
|
-
};
|
|
60
|
-
};
|
|
64
|
+
}, 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) => Promise<Awaited<ReturnType<TOptions['next']>>>;
|
|
61
65
|
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
66
|
|
|
63
67
|
declare function isAsyncIteratorObject(maybe: unknown): maybe is AsyncIteratorObject<any, any, any>;
|
|
@@ -79,11 +83,9 @@ declare function isObject(value: unknown): value is Record<PropertyKey, unknown>
|
|
|
79
83
|
*/
|
|
80
84
|
declare function isTypescriptObject(value: unknown): value is object & Record<PropertyKey, unknown>;
|
|
81
85
|
declare function clone<T>(value: T): T;
|
|
82
|
-
|
|
83
|
-
type SetOptional<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
|
|
84
|
-
type IntersectPick<T, U> = Pick<T, keyof T & keyof U>;
|
|
86
|
+
declare function get(object: object, path: readonly string[]): unknown;
|
|
85
87
|
|
|
86
88
|
type Value<T, TArgs extends any[] = []> = T | ((...args: TArgs) => Promisable<T>);
|
|
87
89
|
declare function value<T, TArgs extends any[]>(value: Value<T, TArgs>, ...args: NoInfer<TArgs>): Promise<T extends Value<infer U, any> ? U : never>;
|
|
88
90
|
|
|
89
|
-
export { type AnyFunction, type InterceptableOptions, type Interceptor, type InterceptorOptions, type IntersectPick, type MaybeOptionalOptions, type OmitChainMethodDeep, type OnFinishState, type Segment, type SetOptional, type Value, clone, findDeepMatches, intercept, isAsyncIteratorObject, isObject, isTypescriptObject, onError, onFinish, onStart, onSuccess, once, parseEmptyableJSON, resolveMaybeOptionalOptions, stringifyJSON, toArray,
|
|
91
|
+
export { type AnyFunction, type InterceptableOptions, type Interceptor, type InterceptorOptions, type IntersectPick, type MaybeOptionalOptions, type OmitChainMethodDeep, type OnFinishState, type PromiseWithError, type Registry, type Segment, type SetOptional, type ThrowableError, type Value, clone, findDeepMatches, get, intercept, isAsyncIteratorObject, isObject, isTypescriptObject, onError, onFinish, onStart, onSuccess, once, parseEmptyableJSON, resolveMaybeOptionalOptions, stringifyJSON, toArray, value };
|
package/dist/index.d.ts
CHANGED
|
@@ -14,17 +14,29 @@ type OmitChainMethodDeep<T extends object, K extends keyof any> = {
|
|
|
14
14
|
[P in keyof Omit<T, K>]: T[P] extends AnyFunction ? ((...args: Parameters<T[P]>) => OmitChainMethodDeep<ReturnType<T[P]>, K>) : T[P];
|
|
15
15
|
};
|
|
16
16
|
|
|
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> & {
|
|
17
|
+
type SetOptional<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
|
|
18
|
+
type IntersectPick<T, U> = Pick<T, keyof T & keyof U>;
|
|
19
|
+
type PromiseWithError<T, TError> = Promise<T> & {
|
|
24
20
|
__error?: {
|
|
25
21
|
type: TError;
|
|
26
22
|
};
|
|
27
23
|
};
|
|
24
|
+
/**
|
|
25
|
+
* The place where you can config the orpc types.
|
|
26
|
+
*
|
|
27
|
+
* - `throwableError` the error type that represent throwable errors should be `Error` or `null | undefined | {}` if you want more strict.
|
|
28
|
+
*/
|
|
29
|
+
interface Registry {
|
|
30
|
+
}
|
|
31
|
+
type ThrowableError = Registry extends {
|
|
32
|
+
throwableError: infer T;
|
|
33
|
+
} ? T : Error;
|
|
34
|
+
|
|
35
|
+
type InterceptableOptions = Record<string, any>;
|
|
36
|
+
type InterceptorOptions<TOptions extends InterceptableOptions, TResult, TError> = Omit<TOptions, 'next'> & {
|
|
37
|
+
next(options?: TOptions): PromiseWithError<TResult, TError>;
|
|
38
|
+
};
|
|
39
|
+
type Interceptor<TOptions extends InterceptableOptions, TResult, TError> = (options: InterceptorOptions<TOptions, TResult, TError>) => PromiseWithError<TResult, TError>;
|
|
28
40
|
/**
|
|
29
41
|
* Can used for interceptors or middlewares
|
|
30
42
|
*/
|
|
@@ -40,24 +52,16 @@ declare function onSuccess<TOptions extends {
|
|
|
40
52
|
/**
|
|
41
53
|
* Can used for interceptors or middlewares
|
|
42
54
|
*/
|
|
43
|
-
declare function onError<
|
|
55
|
+
declare function onError<TOptions extends {
|
|
44
56
|
next(): any;
|
|
45
|
-
}, TRest extends any[]>(callback: NoInfer<(error:
|
|
46
|
-
__error?: {
|
|
47
|
-
type: TError;
|
|
48
|
-
};
|
|
49
|
-
};
|
|
57
|
+
}, 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) => Promise<Awaited<ReturnType<TOptions['next']>>>;
|
|
50
58
|
type OnFinishState<TResult, TError> = [TResult, null, 'success'] | [undefined, TError, 'error'];
|
|
51
59
|
/**
|
|
52
60
|
* Can used for interceptors or middlewares
|
|
53
61
|
*/
|
|
54
|
-
declare function onFinish<
|
|
62
|
+
declare function onFinish<TOptions extends {
|
|
55
63
|
next(): any;
|
|
56
|
-
}, TRest extends any[]>(callback: NoInfer<(state: OnFinishState<Awaited<ReturnType<TOptions['next']>>,
|
|
57
|
-
__error?: {
|
|
58
|
-
type: TError;
|
|
59
|
-
};
|
|
60
|
-
};
|
|
64
|
+
}, 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) => Promise<Awaited<ReturnType<TOptions['next']>>>;
|
|
61
65
|
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
66
|
|
|
63
67
|
declare function isAsyncIteratorObject(maybe: unknown): maybe is AsyncIteratorObject<any, any, any>;
|
|
@@ -79,11 +83,9 @@ declare function isObject(value: unknown): value is Record<PropertyKey, unknown>
|
|
|
79
83
|
*/
|
|
80
84
|
declare function isTypescriptObject(value: unknown): value is object & Record<PropertyKey, unknown>;
|
|
81
85
|
declare function clone<T>(value: T): T;
|
|
82
|
-
|
|
83
|
-
type SetOptional<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
|
|
84
|
-
type IntersectPick<T, U> = Pick<T, keyof T & keyof U>;
|
|
86
|
+
declare function get(object: object, path: readonly string[]): unknown;
|
|
85
87
|
|
|
86
88
|
type Value<T, TArgs extends any[] = []> = T | ((...args: TArgs) => Promisable<T>);
|
|
87
89
|
declare function value<T, TArgs extends any[]>(value: Value<T, TArgs>, ...args: NoInfer<TArgs>): Promise<T extends Value<infer U, any> ? U : never>;
|
|
88
90
|
|
|
89
|
-
export { type AnyFunction, type InterceptableOptions, type Interceptor, type InterceptorOptions, type IntersectPick, type MaybeOptionalOptions, type OmitChainMethodDeep, type OnFinishState, type Segment, type SetOptional, type Value, clone, findDeepMatches, intercept, isAsyncIteratorObject, isObject, isTypescriptObject, onError, onFinish, onStart, onSuccess, once, parseEmptyableJSON, resolveMaybeOptionalOptions, stringifyJSON, toArray,
|
|
91
|
+
export { type AnyFunction, type InterceptableOptions, type Interceptor, type InterceptorOptions, type IntersectPick, type MaybeOptionalOptions, type OmitChainMethodDeep, type OnFinishState, type PromiseWithError, type Registry, type Segment, type SetOptional, type ThrowableError, type Value, clone, findDeepMatches, get, intercept, isAsyncIteratorObject, isObject, isTypescriptObject, onError, onFinish, onStart, onSuccess, once, parseEmptyableJSON, resolveMaybeOptionalOptions, stringifyJSON, toArray, value };
|
package/dist/index.mjs
CHANGED
|
@@ -8,13 +8,6 @@ function toArray(value) {
|
|
|
8
8
|
return Array.isArray(value) ? value : value === void 0 || value === null ? [] : [value];
|
|
9
9
|
}
|
|
10
10
|
|
|
11
|
-
function toError(error) {
|
|
12
|
-
if (error instanceof Error) {
|
|
13
|
-
return error;
|
|
14
|
-
}
|
|
15
|
-
return new Error("Unknown error", { cause: error });
|
|
16
|
-
}
|
|
17
|
-
|
|
18
11
|
function once(fn) {
|
|
19
12
|
let cached;
|
|
20
13
|
return () => {
|
|
@@ -135,6 +128,16 @@ function clone(value) {
|
|
|
135
128
|
}
|
|
136
129
|
return value;
|
|
137
130
|
}
|
|
131
|
+
function get(object, path) {
|
|
132
|
+
let current = object;
|
|
133
|
+
for (const key of path) {
|
|
134
|
+
if (!isTypescriptObject(current)) {
|
|
135
|
+
return void 0;
|
|
136
|
+
}
|
|
137
|
+
current = current[key];
|
|
138
|
+
}
|
|
139
|
+
return current;
|
|
140
|
+
}
|
|
138
141
|
|
|
139
142
|
function value(value2, ...args) {
|
|
140
143
|
if (typeof value2 === "function") {
|
|
@@ -143,4 +146,4 @@ function value(value2, ...args) {
|
|
|
143
146
|
return value2;
|
|
144
147
|
}
|
|
145
148
|
|
|
146
|
-
export { clone, findDeepMatches, intercept, isAsyncIteratorObject, isObject, isTypescriptObject, onError, onFinish, onStart, onSuccess, once, parseEmptyableJSON, resolveMaybeOptionalOptions, stringifyJSON, toArray,
|
|
149
|
+
export { clone, findDeepMatches, get, intercept, isAsyncIteratorObject, isObject, isTypescriptObject, onError, onFinish, onStart, onSuccess, once, parseEmptyableJSON, resolveMaybeOptionalOptions, stringifyJSON, toArray, value };
|