@orpc/react 0.0.0-next.783ae4e → 0.0.0-next.7bb9940
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/hooks/index.d.mts +10 -9
- package/dist/hooks/index.d.ts +10 -9
- package/dist/hooks/index.mjs +2 -2
- package/dist/index.d.mts +2 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.mjs +2 -2
- package/package.json +6 -6
package/dist/hooks/index.d.mts
CHANGED
|
@@ -2,19 +2,19 @@ import { SafeResult, ORPCErrorJSON } from '@orpc/client';
|
|
|
2
2
|
import { ActionableClient, UnactionableError } from '@orpc/server';
|
|
3
3
|
import { Interceptor } from '@orpc/shared';
|
|
4
4
|
|
|
5
|
-
interface UseServerActionOptions<TInput, TOutput, TError
|
|
5
|
+
interface UseServerActionOptions<TInput, TOutput, TError> {
|
|
6
6
|
interceptors?: Interceptor<{
|
|
7
7
|
input: TInput;
|
|
8
8
|
}, TOutput, TError>[];
|
|
9
9
|
}
|
|
10
|
-
interface UseServerActionExecuteOptions<TInput, TOutput, TError
|
|
10
|
+
interface UseServerActionExecuteOptions<TInput, TOutput, TError> extends Pick<UseServerActionOptions<TInput, TOutput, TError>, 'interceptors'> {
|
|
11
11
|
}
|
|
12
|
-
type UseServerActionExecuteRest<TInput, TOutput, TError
|
|
13
|
-
interface UseServerActionResultBase<TInput, TOutput, TError
|
|
12
|
+
type UseServerActionExecuteRest<TInput, TOutput, TError> = undefined extends TInput ? [input?: TInput, options?: UseServerActionExecuteOptions<TInput, TOutput, TError>] : [input: TInput, options?: UseServerActionExecuteOptions<TInput, TOutput, TError>];
|
|
13
|
+
interface UseServerActionResultBase<TInput, TOutput, TError> {
|
|
14
14
|
reset: () => void;
|
|
15
15
|
execute: (...rest: UseServerActionExecuteRest<TInput, TOutput, TError>) => Promise<SafeResult<TOutput, TError>>;
|
|
16
16
|
}
|
|
17
|
-
interface UseServerActionIdleResult<TInput, TOutput, TError
|
|
17
|
+
interface UseServerActionIdleResult<TInput, TOutput, TError> extends UseServerActionResultBase<TInput, TOutput, TError> {
|
|
18
18
|
input: undefined;
|
|
19
19
|
data: undefined;
|
|
20
20
|
error: null;
|
|
@@ -25,7 +25,7 @@ interface UseServerActionIdleResult<TInput, TOutput, TError extends Error> exten
|
|
|
25
25
|
status: 'idle';
|
|
26
26
|
executedAt: undefined;
|
|
27
27
|
}
|
|
28
|
-
interface UseServerActionPendingResult<TInput, TOutput, TError
|
|
28
|
+
interface UseServerActionPendingResult<TInput, TOutput, TError> extends UseServerActionResultBase<TInput, TOutput, TError> {
|
|
29
29
|
input: TInput;
|
|
30
30
|
data: undefined;
|
|
31
31
|
error: null;
|
|
@@ -36,7 +36,7 @@ interface UseServerActionPendingResult<TInput, TOutput, TError extends Error> ex
|
|
|
36
36
|
status: 'pending';
|
|
37
37
|
executedAt: Date;
|
|
38
38
|
}
|
|
39
|
-
interface UseServerActionSuccessResult<TInput, TOutput, TError
|
|
39
|
+
interface UseServerActionSuccessResult<TInput, TOutput, TError> extends UseServerActionResultBase<TInput, TOutput, TError> {
|
|
40
40
|
input: TInput;
|
|
41
41
|
data: TOutput;
|
|
42
42
|
error: null;
|
|
@@ -47,7 +47,7 @@ interface UseServerActionSuccessResult<TInput, TOutput, TError extends Error> ex
|
|
|
47
47
|
status: 'success';
|
|
48
48
|
executedAt: Date;
|
|
49
49
|
}
|
|
50
|
-
interface UseServerActionErrorResult<TInput, TOutput, TError
|
|
50
|
+
interface UseServerActionErrorResult<TInput, TOutput, TError> extends UseServerActionResultBase<TInput, TOutput, TError> {
|
|
51
51
|
input: TInput;
|
|
52
52
|
data: undefined;
|
|
53
53
|
error: TError;
|
|
@@ -60,4 +60,5 @@ interface UseServerActionErrorResult<TInput, TOutput, TError extends Error> exte
|
|
|
60
60
|
}
|
|
61
61
|
declare function useServerAction<TInput, TOutput, TError extends ORPCErrorJSON<any, any>>(action: ActionableClient<TInput, TOutput, TError>, options?: NoInfer<UseServerActionOptions<TInput, TOutput, UnactionableError<TError>>>): UseServerActionIdleResult<TInput, TOutput, UnactionableError<TError>> | UseServerActionSuccessResult<TInput, TOutput, UnactionableError<TError>> | UseServerActionErrorResult<TInput, TOutput, UnactionableError<TError>> | UseServerActionPendingResult<TInput, TOutput, UnactionableError<TError>>;
|
|
62
62
|
|
|
63
|
-
export {
|
|
63
|
+
export { useServerAction };
|
|
64
|
+
export type { UseServerActionErrorResult, UseServerActionExecuteOptions, UseServerActionExecuteRest, UseServerActionIdleResult, UseServerActionOptions, UseServerActionPendingResult, UseServerActionResultBase, UseServerActionSuccessResult };
|
package/dist/hooks/index.d.ts
CHANGED
|
@@ -2,19 +2,19 @@ import { SafeResult, ORPCErrorJSON } from '@orpc/client';
|
|
|
2
2
|
import { ActionableClient, UnactionableError } from '@orpc/server';
|
|
3
3
|
import { Interceptor } from '@orpc/shared';
|
|
4
4
|
|
|
5
|
-
interface UseServerActionOptions<TInput, TOutput, TError
|
|
5
|
+
interface UseServerActionOptions<TInput, TOutput, TError> {
|
|
6
6
|
interceptors?: Interceptor<{
|
|
7
7
|
input: TInput;
|
|
8
8
|
}, TOutput, TError>[];
|
|
9
9
|
}
|
|
10
|
-
interface UseServerActionExecuteOptions<TInput, TOutput, TError
|
|
10
|
+
interface UseServerActionExecuteOptions<TInput, TOutput, TError> extends Pick<UseServerActionOptions<TInput, TOutput, TError>, 'interceptors'> {
|
|
11
11
|
}
|
|
12
|
-
type UseServerActionExecuteRest<TInput, TOutput, TError
|
|
13
|
-
interface UseServerActionResultBase<TInput, TOutput, TError
|
|
12
|
+
type UseServerActionExecuteRest<TInput, TOutput, TError> = undefined extends TInput ? [input?: TInput, options?: UseServerActionExecuteOptions<TInput, TOutput, TError>] : [input: TInput, options?: UseServerActionExecuteOptions<TInput, TOutput, TError>];
|
|
13
|
+
interface UseServerActionResultBase<TInput, TOutput, TError> {
|
|
14
14
|
reset: () => void;
|
|
15
15
|
execute: (...rest: UseServerActionExecuteRest<TInput, TOutput, TError>) => Promise<SafeResult<TOutput, TError>>;
|
|
16
16
|
}
|
|
17
|
-
interface UseServerActionIdleResult<TInput, TOutput, TError
|
|
17
|
+
interface UseServerActionIdleResult<TInput, TOutput, TError> extends UseServerActionResultBase<TInput, TOutput, TError> {
|
|
18
18
|
input: undefined;
|
|
19
19
|
data: undefined;
|
|
20
20
|
error: null;
|
|
@@ -25,7 +25,7 @@ interface UseServerActionIdleResult<TInput, TOutput, TError extends Error> exten
|
|
|
25
25
|
status: 'idle';
|
|
26
26
|
executedAt: undefined;
|
|
27
27
|
}
|
|
28
|
-
interface UseServerActionPendingResult<TInput, TOutput, TError
|
|
28
|
+
interface UseServerActionPendingResult<TInput, TOutput, TError> extends UseServerActionResultBase<TInput, TOutput, TError> {
|
|
29
29
|
input: TInput;
|
|
30
30
|
data: undefined;
|
|
31
31
|
error: null;
|
|
@@ -36,7 +36,7 @@ interface UseServerActionPendingResult<TInput, TOutput, TError extends Error> ex
|
|
|
36
36
|
status: 'pending';
|
|
37
37
|
executedAt: Date;
|
|
38
38
|
}
|
|
39
|
-
interface UseServerActionSuccessResult<TInput, TOutput, TError
|
|
39
|
+
interface UseServerActionSuccessResult<TInput, TOutput, TError> extends UseServerActionResultBase<TInput, TOutput, TError> {
|
|
40
40
|
input: TInput;
|
|
41
41
|
data: TOutput;
|
|
42
42
|
error: null;
|
|
@@ -47,7 +47,7 @@ interface UseServerActionSuccessResult<TInput, TOutput, TError extends Error> ex
|
|
|
47
47
|
status: 'success';
|
|
48
48
|
executedAt: Date;
|
|
49
49
|
}
|
|
50
|
-
interface UseServerActionErrorResult<TInput, TOutput, TError
|
|
50
|
+
interface UseServerActionErrorResult<TInput, TOutput, TError> extends UseServerActionResultBase<TInput, TOutput, TError> {
|
|
51
51
|
input: TInput;
|
|
52
52
|
data: undefined;
|
|
53
53
|
error: TError;
|
|
@@ -60,4 +60,5 @@ interface UseServerActionErrorResult<TInput, TOutput, TError extends Error> exte
|
|
|
60
60
|
}
|
|
61
61
|
declare function useServerAction<TInput, TOutput, TError extends ORPCErrorJSON<any, any>>(action: ActionableClient<TInput, TOutput, TError>, options?: NoInfer<UseServerActionOptions<TInput, TOutput, UnactionableError<TError>>>): UseServerActionIdleResult<TInput, TOutput, UnactionableError<TError>> | UseServerActionSuccessResult<TInput, TOutput, UnactionableError<TError>> | UseServerActionErrorResult<TInput, TOutput, UnactionableError<TError>> | UseServerActionPendingResult<TInput, TOutput, UnactionableError<TError>>;
|
|
62
62
|
|
|
63
|
-
export {
|
|
63
|
+
export { useServerAction };
|
|
64
|
+
export type { UseServerActionErrorResult, UseServerActionExecuteOptions, UseServerActionExecuteRest, UseServerActionIdleResult, UseServerActionOptions, UseServerActionPendingResult, UseServerActionResultBase, UseServerActionSuccessResult };
|
package/dist/hooks/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { safe,
|
|
1
|
+
import { safe, createORPCErrorFromJson } from '@orpc/client';
|
|
2
2
|
import { intercept, toArray } from '@orpc/shared';
|
|
3
3
|
import { useState, useCallback, useMemo } from 'react';
|
|
4
4
|
|
|
@@ -36,7 +36,7 @@ function useServerAction(action, options = {}) {
|
|
|
36
36
|
{ input },
|
|
37
37
|
({ input: input2 }) => action(input2).then(([error, data]) => {
|
|
38
38
|
if (error) {
|
|
39
|
-
throw
|
|
39
|
+
throw createORPCErrorFromJson(error);
|
|
40
40
|
}
|
|
41
41
|
return data;
|
|
42
42
|
})
|
package/dist/index.d.mts
CHANGED
|
@@ -8,4 +8,5 @@ interface FormAction {
|
|
|
8
8
|
declare const orpcErrorToNextHttpFallbackInterceptor: Interceptor<any, any, any>;
|
|
9
9
|
declare function createFormAction<TInitialContext extends Context, TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta>(lazyableProcedure: Lazyable<Procedure<TInitialContext, any, TInputSchema, TOutputSchema, TErrorMap, TMeta>>, ...rest: MaybeOptionalOptions<CreateProcedureClientOptions<TInitialContext, TOutputSchema, TErrorMap, TMeta, Record<never, never>>>): FormAction;
|
|
10
10
|
|
|
11
|
-
export {
|
|
11
|
+
export { createFormAction, orpcErrorToNextHttpFallbackInterceptor };
|
|
12
|
+
export type { FormAction };
|
package/dist/index.d.ts
CHANGED
|
@@ -8,4 +8,5 @@ interface FormAction {
|
|
|
8
8
|
declare const orpcErrorToNextHttpFallbackInterceptor: Interceptor<any, any, any>;
|
|
9
9
|
declare function createFormAction<TInitialContext extends Context, TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta>(lazyableProcedure: Lazyable<Procedure<TInitialContext, any, TInputSchema, TOutputSchema, TErrorMap, TMeta>>, ...rest: MaybeOptionalOptions<CreateProcedureClientOptions<TInitialContext, TOutputSchema, TErrorMap, TMeta, Record<never, never>>>): FormAction;
|
|
10
10
|
|
|
11
|
-
export {
|
|
11
|
+
export { createFormAction, orpcErrorToNextHttpFallbackInterceptor };
|
|
12
|
+
export type { FormAction };
|
package/dist/index.mjs
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { ORPCError } from '@orpc/client';
|
|
1
|
+
import { ORPCError, createORPCErrorFromJson } from '@orpc/client';
|
|
2
2
|
import { StandardBracketNotationSerializer } from '@orpc/openapi-client/standard';
|
|
3
3
|
import { createProcedureClient } from '@orpc/server';
|
|
4
4
|
import { onError, resolveMaybeOptionalOptions, toArray } from '@orpc/shared';
|
|
5
5
|
|
|
6
6
|
const orpcErrorToNextHttpFallbackInterceptor = onError((error) => {
|
|
7
7
|
if (error instanceof ORPCError && [401, 403, 404].includes(error.status)) {
|
|
8
|
-
const nextError =
|
|
8
|
+
const nextError = createORPCErrorFromJson(error.toJSON());
|
|
9
9
|
nextError.cause = error;
|
|
10
10
|
nextError.digest = `NEXT_HTTP_ERROR_FALLBACK;${error.status}`;
|
|
11
11
|
throw nextError;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@orpc/react",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.0.0-next.
|
|
4
|
+
"version": "0.0.0-next.7bb9940",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"homepage": "https://orpc.unnoq.com",
|
|
7
7
|
"repository": {
|
|
@@ -34,11 +34,11 @@
|
|
|
34
34
|
"react": ">=18.0.0"
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|
|
37
|
-
"@orpc/client": "0.0.0-next.
|
|
38
|
-
"@orpc/contract": "0.0.0-next.
|
|
39
|
-
"@orpc/openapi-client": "0.0.0-next.
|
|
40
|
-
"@orpc/shared": "0.0.0-next.
|
|
41
|
-
"@orpc/server": "0.0.0-next.
|
|
37
|
+
"@orpc/client": "0.0.0-next.7bb9940",
|
|
38
|
+
"@orpc/contract": "0.0.0-next.7bb9940",
|
|
39
|
+
"@orpc/openapi-client": "0.0.0-next.7bb9940",
|
|
40
|
+
"@orpc/shared": "0.0.0-next.7bb9940",
|
|
41
|
+
"@orpc/server": "0.0.0-next.7bb9940"
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|
|
44
44
|
"react": "^19.1.0",
|