@orpc/react 0.0.0-next.ff41b3a → 0.0.0-next.ff7ad2e
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 +8 -7
- package/dist/hooks/index.d.mts +15 -5
- package/dist/hooks/index.d.ts +15 -5
- package/dist/hooks/index.mjs +70 -44
- package/dist/index.d.mts +21 -3
- package/dist/index.d.ts +21 -3
- package/dist/index.mjs +32 -2
- package/package.json +8 -8
package/README.md
CHANGED
@@ -30,7 +30,8 @@
|
|
30
30
|
- **🔗 End-to-End Type Safety**: Ensure type-safe inputs, outputs, and errors from client to server.
|
31
31
|
- **📘 First-Class OpenAPI**: Built-in support that fully adheres to the OpenAPI standard.
|
32
32
|
- **📝 Contract-First Development**: Optionally define your API contract before implementation.
|
33
|
-
-
|
33
|
+
- **🔍 First-Class OpenTelemetry**: Seamlessly integrate with OpenTelemetry for observability.
|
34
|
+
- **⚙️ Framework Integrations**: Seamlessly integrate with TanStack Query (React, Vue, Solid, Svelte, Angular), SWR, Pinia Colada, and more.
|
34
35
|
- **🚀 Server Actions**: Fully compatible with React Server Actions on Next.js, TanStack Start, and other platforms.
|
35
36
|
- **🔠 Standard Schema Support**: Works out of the box with Zod, Valibot, ArkType, and other schema validators.
|
36
37
|
- **🗃️ Native Types**: Supports native types like Date, File, Blob, BigInt, URL, and more.
|
@@ -38,7 +39,6 @@
|
|
38
39
|
- **📡 SSE & Streaming**: Enjoy full type-safe support for SSE and streaming.
|
39
40
|
- **🌍 Multi-Runtime Support**: Fast and lightweight on Cloudflare, Deno, Bun, Node.js, and beyond.
|
40
41
|
- **🔌 Extendability**: Easily extend functionality with plugins, middleware, and interceptors.
|
41
|
-
- **🛡️ Reliability**: Well-tested, TypeScript-based, production-ready, and MIT licensed.
|
42
42
|
|
43
43
|
## Documentation
|
44
44
|
|
@@ -49,13 +49,14 @@ You can find the full documentation [here](https://orpc.unnoq.com).
|
|
49
49
|
- [@orpc/contract](https://www.npmjs.com/package/@orpc/contract): Build your API contract.
|
50
50
|
- [@orpc/server](https://www.npmjs.com/package/@orpc/server): Build your API or implement API contract.
|
51
51
|
- [@orpc/client](https://www.npmjs.com/package/@orpc/client): Consume your API on the client with type-safety.
|
52
|
+
- [@orpc/openapi](https://www.npmjs.com/package/@orpc/openapi): Generate OpenAPI specs and handle OpenAPI requests.
|
53
|
+
- [@orpc/otel](https://www.npmjs.com/package/@orpc/otel): [OpenTelemetry](https://opentelemetry.io/) integration for observability.
|
54
|
+
- [@orpc/nest](https://www.npmjs.com/package/@orpc/nest): Deeply integrate oRPC with [NestJS](https://nestjs.com/).
|
52
55
|
- [@orpc/react](https://www.npmjs.com/package/@orpc/react): Utilities for integrating oRPC with React and React Server Actions.
|
53
|
-
- [@orpc/
|
54
|
-
- [@orpc/
|
55
|
-
- [@orpc/solid-query](https://www.npmjs.com/package/@orpc/solid-query): Integration with [Solid Query](https://tanstack.com/query/latest/docs/framework/solid/overview).
|
56
|
-
- [@orpc/svelte-query](https://www.npmjs.com/package/@orpc/svelte-query): Integration with [Svelte Query](https://tanstack.com/query/latest/docs/framework/svelte/overview).
|
56
|
+
- [@orpc/tanstack-query](https://www.npmjs.com/package/@orpc/tanstack-query): [TanStack Query](https://tanstack.com/query/latest) integration.
|
57
|
+
- [@orpc/experimental-react-swr](https://www.npmjs.com/package/@orpc/experimental-react-swr): [SWR](https://swr.vercel.app/) integration.
|
57
58
|
- [@orpc/vue-colada](https://www.npmjs.com/package/@orpc/vue-colada): Integration with [Pinia Colada](https://pinia-colada.esm.dev/).
|
58
|
-
- [@orpc/
|
59
|
+
- [@orpc/hey-api](https://www.npmjs.com/package/@orpc/hey-api): [Hey API](https://heyapi.dev/) integration.
|
59
60
|
- [@orpc/zod](https://www.npmjs.com/package/@orpc/zod): More schemas that [Zod](https://zod.dev/) doesn't support yet.
|
60
61
|
- [@orpc/valibot](https://www.npmjs.com/package/@orpc/valibot): OpenAPI spec generation from [Valibot](https://valibot.dev/).
|
61
62
|
- [@orpc/arktype](https://www.npmjs.com/package/@orpc/arktype): OpenAPI spec generation from [ArkType](https://arktype.io/).
|
package/dist/hooks/index.d.mts
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
import { SafeResult, ORPCErrorJSON } from '@orpc/client';
|
2
2
|
import { ActionableClient, UnactionableError } from '@orpc/server';
|
3
|
-
import { Interceptor } from '@orpc/shared';
|
3
|
+
import { Interceptor, PromiseWithError } from '@orpc/shared';
|
4
4
|
|
5
5
|
interface UseServerActionOptions<TInput, TOutput, TError> {
|
6
6
|
interceptors?: Interceptor<{
|
7
7
|
input: TInput;
|
8
|
-
}, TOutput, TError
|
8
|
+
}, PromiseWithError<TOutput, TError>>[];
|
9
9
|
}
|
10
10
|
interface UseServerActionExecuteOptions<TInput, TOutput, TError> extends Pick<UseServerActionOptions<TInput, TOutput, TError>, 'interceptors'> {
|
11
11
|
}
|
@@ -58,12 +58,22 @@ interface UseServerActionErrorResult<TInput, TOutput, TError> extends UseServerA
|
|
58
58
|
status: 'error';
|
59
59
|
executedAt: Date;
|
60
60
|
}
|
61
|
+
type UseServerActionResult<TInput, TOutput, TError> = UseServerActionIdleResult<TInput, TOutput, TError> | UseServerActionSuccessResult<TInput, TOutput, TError> | UseServerActionErrorResult<TInput, TOutput, TError> | UseServerActionPendingResult<TInput, TOutput, TError>;
|
61
62
|
/**
|
62
63
|
* Use a Server Action Hook
|
63
64
|
*
|
64
65
|
* @see {@link https://orpc.unnoq.com/docs/server-action#useserveraction-hook Server Action Hook Docs}
|
65
66
|
*/
|
66
|
-
declare function useServerAction<TInput, TOutput, TError extends ORPCErrorJSON<any, any>>(action: ActionableClient<TInput, TOutput, TError>, options?:
|
67
|
+
declare function useServerAction<TInput, TOutput, TError extends ORPCErrorJSON<any, any>>(action: ActionableClient<TInput, TOutput, TError>, options?: UseServerActionOptions<TInput, TOutput, UnactionableError<TError>>): UseServerActionResult<TInput, TOutput, UnactionableError<TError>>;
|
67
68
|
|
68
|
-
|
69
|
-
|
69
|
+
interface UseOptimisticServerActionOptions<TInput, TOutput, TError, TOptimisticState> extends UseServerActionOptions<TInput, TOutput, TError> {
|
70
|
+
optimisticPassthrough: TOptimisticState;
|
71
|
+
optimisticReducer: (state: TOptimisticState, input: TInput) => TOptimisticState;
|
72
|
+
}
|
73
|
+
type UseOptimisticServerActionResult<TInput, TOutput, TError, TOptimisticState> = UseServerActionResult<TInput, TOutput, TError> & {
|
74
|
+
optimisticState: TOptimisticState;
|
75
|
+
};
|
76
|
+
declare function useOptimisticServerAction<TInput, TOutput, TError extends ORPCErrorJSON<any, any>, TOptimisticState>(action: ActionableClient<TInput, TOutput, TError>, options: UseOptimisticServerActionOptions<TInput, TOutput, UnactionableError<TError>, TOptimisticState>): UseOptimisticServerActionResult<TInput, TOutput, UnactionableError<TError>, TOptimisticState>;
|
77
|
+
|
78
|
+
export { useOptimisticServerAction, useServerAction };
|
79
|
+
export type { UseOptimisticServerActionOptions, UseOptimisticServerActionResult, UseServerActionErrorResult, UseServerActionExecuteOptions, UseServerActionExecuteRest, UseServerActionIdleResult, UseServerActionOptions, UseServerActionPendingResult, UseServerActionResult, UseServerActionResultBase, UseServerActionSuccessResult };
|
package/dist/hooks/index.d.ts
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
import { SafeResult, ORPCErrorJSON } from '@orpc/client';
|
2
2
|
import { ActionableClient, UnactionableError } from '@orpc/server';
|
3
|
-
import { Interceptor } from '@orpc/shared';
|
3
|
+
import { Interceptor, PromiseWithError } from '@orpc/shared';
|
4
4
|
|
5
5
|
interface UseServerActionOptions<TInput, TOutput, TError> {
|
6
6
|
interceptors?: Interceptor<{
|
7
7
|
input: TInput;
|
8
|
-
}, TOutput, TError
|
8
|
+
}, PromiseWithError<TOutput, TError>>[];
|
9
9
|
}
|
10
10
|
interface UseServerActionExecuteOptions<TInput, TOutput, TError> extends Pick<UseServerActionOptions<TInput, TOutput, TError>, 'interceptors'> {
|
11
11
|
}
|
@@ -58,12 +58,22 @@ interface UseServerActionErrorResult<TInput, TOutput, TError> extends UseServerA
|
|
58
58
|
status: 'error';
|
59
59
|
executedAt: Date;
|
60
60
|
}
|
61
|
+
type UseServerActionResult<TInput, TOutput, TError> = UseServerActionIdleResult<TInput, TOutput, TError> | UseServerActionSuccessResult<TInput, TOutput, TError> | UseServerActionErrorResult<TInput, TOutput, TError> | UseServerActionPendingResult<TInput, TOutput, TError>;
|
61
62
|
/**
|
62
63
|
* Use a Server Action Hook
|
63
64
|
*
|
64
65
|
* @see {@link https://orpc.unnoq.com/docs/server-action#useserveraction-hook Server Action Hook Docs}
|
65
66
|
*/
|
66
|
-
declare function useServerAction<TInput, TOutput, TError extends ORPCErrorJSON<any, any>>(action: ActionableClient<TInput, TOutput, TError>, options?:
|
67
|
+
declare function useServerAction<TInput, TOutput, TError extends ORPCErrorJSON<any, any>>(action: ActionableClient<TInput, TOutput, TError>, options?: UseServerActionOptions<TInput, TOutput, UnactionableError<TError>>): UseServerActionResult<TInput, TOutput, UnactionableError<TError>>;
|
67
68
|
|
68
|
-
|
69
|
-
|
69
|
+
interface UseOptimisticServerActionOptions<TInput, TOutput, TError, TOptimisticState> extends UseServerActionOptions<TInput, TOutput, TError> {
|
70
|
+
optimisticPassthrough: TOptimisticState;
|
71
|
+
optimisticReducer: (state: TOptimisticState, input: TInput) => TOptimisticState;
|
72
|
+
}
|
73
|
+
type UseOptimisticServerActionResult<TInput, TOutput, TError, TOptimisticState> = UseServerActionResult<TInput, TOutput, TError> & {
|
74
|
+
optimisticState: TOptimisticState;
|
75
|
+
};
|
76
|
+
declare function useOptimisticServerAction<TInput, TOutput, TError extends ORPCErrorJSON<any, any>, TOptimisticState>(action: ActionableClient<TInput, TOutput, TError>, options: UseOptimisticServerActionOptions<TInput, TOutput, UnactionableError<TError>, TOptimisticState>): UseOptimisticServerActionResult<TInput, TOutput, UnactionableError<TError>, TOptimisticState>;
|
77
|
+
|
78
|
+
export { useOptimisticServerAction, useServerAction };
|
79
|
+
export type { UseOptimisticServerActionOptions, UseOptimisticServerActionResult, UseServerActionErrorResult, UseServerActionExecuteOptions, UseServerActionExecuteRest, UseServerActionIdleResult, UseServerActionOptions, UseServerActionPendingResult, UseServerActionResult, UseServerActionResultBase, UseServerActionSuccessResult };
|
package/dist/hooks/index.mjs
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
+
import { intercept, toArray, onStart } from '@orpc/shared';
|
2
|
+
import { useState, useRef, useTransition, useCallback, useMemo, useOptimistic } from 'react';
|
1
3
|
import { safe, createORPCErrorFromJson } from '@orpc/client';
|
2
|
-
import { intercept, toArray } from '@orpc/shared';
|
3
|
-
import { useState, useCallback, useMemo } from 'react';
|
4
4
|
|
5
5
|
const INITIAL_STATE = {
|
6
6
|
data: void 0,
|
@@ -9,57 +9,83 @@ const INITIAL_STATE = {
|
|
9
9
|
isPending: false,
|
10
10
|
isSuccess: false,
|
11
11
|
isError: false,
|
12
|
-
status: "idle"
|
13
|
-
|
14
|
-
|
12
|
+
status: "idle"
|
13
|
+
};
|
14
|
+
const PENDING_STATE = {
|
15
|
+
data: void 0,
|
16
|
+
error: null,
|
17
|
+
isIdle: false,
|
18
|
+
isPending: true,
|
19
|
+
isSuccess: false,
|
20
|
+
isError: false,
|
21
|
+
status: "pending"
|
15
22
|
};
|
16
23
|
function useServerAction(action, options = {}) {
|
17
24
|
const [state, setState] = useState(INITIAL_STATE);
|
25
|
+
const executedAtRef = useRef(void 0);
|
26
|
+
const [input, setInput] = useState(void 0);
|
27
|
+
const [isPending, startTransition] = useTransition();
|
18
28
|
const reset = useCallback(() => {
|
19
|
-
|
29
|
+
executedAtRef.current = void 0;
|
30
|
+
setInput(void 0);
|
31
|
+
setState({ ...INITIAL_STATE });
|
20
32
|
}, []);
|
21
|
-
const execute = useCallback(async (
|
33
|
+
const execute = useCallback(async (input2, executeOptions = {}) => {
|
22
34
|
const executedAt = /* @__PURE__ */ new Date();
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
35
|
+
executedAtRef.current = executedAt;
|
36
|
+
setInput(input2);
|
37
|
+
return new Promise((resolve) => {
|
38
|
+
startTransition(async () => {
|
39
|
+
const result2 = await safe(intercept(
|
40
|
+
[...toArray(options.interceptors), ...toArray(executeOptions.interceptors)],
|
41
|
+
{ input: input2 },
|
42
|
+
async ({ input: input3 }) => action(input3).then(([error, data]) => {
|
43
|
+
if (error) {
|
44
|
+
throw createORPCErrorFromJson(error);
|
45
|
+
}
|
46
|
+
return data;
|
47
|
+
})
|
48
|
+
));
|
49
|
+
if (executedAtRef.current === executedAt) {
|
50
|
+
setState({
|
51
|
+
data: result2.data,
|
52
|
+
error: result2.error,
|
53
|
+
isIdle: false,
|
54
|
+
isPending: false,
|
55
|
+
isSuccess: !result2.error,
|
56
|
+
isError: !!result2.error,
|
57
|
+
status: !result2.error ? "success" : "error"
|
58
|
+
});
|
40
59
|
}
|
41
|
-
|
42
|
-
})
|
43
|
-
));
|
44
|
-
setState({
|
45
|
-
data: result2.data,
|
46
|
-
error: result2.error,
|
47
|
-
isIdle: false,
|
48
|
-
isPending: false,
|
49
|
-
isSuccess: !result2.error,
|
50
|
-
isError: !!result2.error,
|
51
|
-
status: !result2.error ? "success" : "error",
|
52
|
-
executedAt,
|
53
|
-
input
|
60
|
+
resolve(result2);
|
61
|
+
});
|
54
62
|
});
|
55
|
-
return result2;
|
56
63
|
}, [action, ...toArray(options.interceptors)]);
|
57
|
-
const result = useMemo(() =>
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
64
|
+
const result = useMemo(() => {
|
65
|
+
const currentState = isPending && executedAtRef.current !== void 0 ? PENDING_STATE : state;
|
66
|
+
return {
|
67
|
+
...currentState,
|
68
|
+
executedAt: executedAtRef.current,
|
69
|
+
input,
|
70
|
+
reset,
|
71
|
+
execute
|
72
|
+
};
|
73
|
+
}, [isPending, state, input, reset, execute]);
|
62
74
|
return result;
|
63
75
|
}
|
64
76
|
|
65
|
-
|
77
|
+
function useOptimisticServerAction(action, options) {
|
78
|
+
const [optimisticState, addOptimistic] = useOptimistic(options.optimisticPassthrough, options.optimisticReducer);
|
79
|
+
const state = useServerAction(action, {
|
80
|
+
...options,
|
81
|
+
interceptors: [
|
82
|
+
useCallback(onStart(({ input }) => {
|
83
|
+
addOptimistic(input);
|
84
|
+
}), [addOptimistic]),
|
85
|
+
...toArray(options.interceptors)
|
86
|
+
]
|
87
|
+
});
|
88
|
+
return useMemo(() => ({ ...state, optimisticState }), [state, optimisticState]);
|
89
|
+
}
|
90
|
+
|
91
|
+
export { useOptimisticServerAction, useServerAction };
|
package/dist/index.d.mts
CHANGED
@@ -1,11 +1,12 @@
|
|
1
1
|
import { AnySchema } from '@orpc/contract';
|
2
2
|
import { Context, ErrorMap, Meta, Lazyable, Procedure, CreateProcedureClientOptions } from '@orpc/server';
|
3
|
-
import { Interceptor, MaybeOptionalOptions } from '@orpc/shared';
|
3
|
+
import { Interceptor, MaybeOptionalOptions, onStart, onSuccess, onError, onFinish } from '@orpc/shared';
|
4
|
+
export { getIssueMessage, parseFormData } from '@orpc/openapi-client/standard';
|
4
5
|
|
5
6
|
interface FormAction {
|
6
7
|
(form: FormData): Promise<void>;
|
7
8
|
}
|
8
|
-
declare const orpcErrorToNextHttpFallbackInterceptor: Interceptor<any, any
|
9
|
+
declare const orpcErrorToNextHttpFallbackInterceptor: Interceptor<any, Promise<any>>;
|
9
10
|
/**
|
10
11
|
* Create a server action accept a form data and deserialize with bracket notation.
|
11
12
|
*
|
@@ -14,5 +15,22 @@ declare const orpcErrorToNextHttpFallbackInterceptor: Interceptor<any, any, any>
|
|
14
15
|
*/
|
15
16
|
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;
|
16
17
|
|
17
|
-
|
18
|
+
/**
|
19
|
+
* Like `onStart`, but defers execution, useful for updating states.
|
20
|
+
*/
|
21
|
+
declare const onStartDeferred: typeof onStart;
|
22
|
+
/**
|
23
|
+
* Like `onSuccess`, but defers execution, useful for updating states.
|
24
|
+
*/
|
25
|
+
declare const onSuccessDeferred: typeof onSuccess;
|
26
|
+
/**
|
27
|
+
* Like `onError`, but defers execution, useful for updating states.
|
28
|
+
*/
|
29
|
+
declare const onErrorDeferred: typeof onError;
|
30
|
+
/**
|
31
|
+
* Like `onFinish`, but defers execution, useful for updating states.
|
32
|
+
*/
|
33
|
+
declare const onFinishDeferred: typeof onFinish;
|
34
|
+
|
35
|
+
export { createFormAction, onErrorDeferred, onFinishDeferred, onStartDeferred, onSuccessDeferred, orpcErrorToNextHttpFallbackInterceptor };
|
18
36
|
export type { FormAction };
|
package/dist/index.d.ts
CHANGED
@@ -1,11 +1,12 @@
|
|
1
1
|
import { AnySchema } from '@orpc/contract';
|
2
2
|
import { Context, ErrorMap, Meta, Lazyable, Procedure, CreateProcedureClientOptions } from '@orpc/server';
|
3
|
-
import { Interceptor, MaybeOptionalOptions } from '@orpc/shared';
|
3
|
+
import { Interceptor, MaybeOptionalOptions, onStart, onSuccess, onError, onFinish } from '@orpc/shared';
|
4
|
+
export { getIssueMessage, parseFormData } from '@orpc/openapi-client/standard';
|
4
5
|
|
5
6
|
interface FormAction {
|
6
7
|
(form: FormData): Promise<void>;
|
7
8
|
}
|
8
|
-
declare const orpcErrorToNextHttpFallbackInterceptor: Interceptor<any, any
|
9
|
+
declare const orpcErrorToNextHttpFallbackInterceptor: Interceptor<any, Promise<any>>;
|
9
10
|
/**
|
10
11
|
* Create a server action accept a form data and deserialize with bracket notation.
|
11
12
|
*
|
@@ -14,5 +15,22 @@ declare const orpcErrorToNextHttpFallbackInterceptor: Interceptor<any, any, any>
|
|
14
15
|
*/
|
15
16
|
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;
|
16
17
|
|
17
|
-
|
18
|
+
/**
|
19
|
+
* Like `onStart`, but defers execution, useful for updating states.
|
20
|
+
*/
|
21
|
+
declare const onStartDeferred: typeof onStart;
|
22
|
+
/**
|
23
|
+
* Like `onSuccess`, but defers execution, useful for updating states.
|
24
|
+
*/
|
25
|
+
declare const onSuccessDeferred: typeof onSuccess;
|
26
|
+
/**
|
27
|
+
* Like `onError`, but defers execution, useful for updating states.
|
28
|
+
*/
|
29
|
+
declare const onErrorDeferred: typeof onError;
|
30
|
+
/**
|
31
|
+
* Like `onFinish`, but defers execution, useful for updating states.
|
32
|
+
*/
|
33
|
+
declare const onFinishDeferred: typeof onFinish;
|
34
|
+
|
35
|
+
export { createFormAction, onErrorDeferred, onFinishDeferred, onStartDeferred, onSuccessDeferred, orpcErrorToNextHttpFallbackInterceptor };
|
18
36
|
export type { FormAction };
|
package/dist/index.mjs
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
import { ORPCError, createORPCErrorFromJson } from '@orpc/client';
|
2
2
|
import { StandardBracketNotationSerializer } from '@orpc/openapi-client/standard';
|
3
|
+
export { getIssueMessage, parseFormData } from '@orpc/openapi-client/standard';
|
3
4
|
import { createProcedureClient } from '@orpc/server';
|
4
|
-
import { onError, resolveMaybeOptionalOptions, toArray } from '@orpc/shared';
|
5
|
+
import { onError, resolveMaybeOptionalOptions, toArray, onStart, onSuccess, onFinish } from '@orpc/shared';
|
5
6
|
|
6
7
|
const orpcErrorToNextHttpFallbackInterceptor = onError((error) => {
|
7
8
|
if (error instanceof ORPCError && [401, 403, 404].includes(error.status)) {
|
@@ -24,4 +25,33 @@ function createFormAction(lazyableProcedure, ...rest) {
|
|
24
25
|
};
|
25
26
|
}
|
26
27
|
|
27
|
-
|
28
|
+
const onStartDeferred = (callback, ...rest) => {
|
29
|
+
return onStart((...args) => {
|
30
|
+
setTimeout(() => {
|
31
|
+
callback(...args);
|
32
|
+
}, 6);
|
33
|
+
}, ...rest);
|
34
|
+
};
|
35
|
+
const onSuccessDeferred = (callback, ...rest) => {
|
36
|
+
return onSuccess((...args) => {
|
37
|
+
setTimeout(() => {
|
38
|
+
callback(...args);
|
39
|
+
}, 6);
|
40
|
+
}, ...rest);
|
41
|
+
};
|
42
|
+
const onErrorDeferred = (callback, ...rest) => {
|
43
|
+
return onError((...args) => {
|
44
|
+
setTimeout(() => {
|
45
|
+
callback(...args);
|
46
|
+
}, 6);
|
47
|
+
}, ...rest);
|
48
|
+
};
|
49
|
+
const onFinishDeferred = (callback, ...rest) => {
|
50
|
+
return onFinish((...args) => {
|
51
|
+
setTimeout(() => {
|
52
|
+
callback(...args);
|
53
|
+
}, 6);
|
54
|
+
}, ...rest);
|
55
|
+
};
|
56
|
+
|
57
|
+
export { createFormAction, onErrorDeferred, onFinishDeferred, onStartDeferred, onSuccessDeferred, orpcErrorToNextHttpFallbackInterceptor };
|
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.ff7ad2e",
|
5
5
|
"license": "MIT",
|
6
6
|
"homepage": "https://orpc.unnoq.com",
|
7
7
|
"repository": {
|
@@ -34,15 +34,15 @@
|
|
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/
|
40
|
-
"@orpc/
|
41
|
-
"@orpc/shared": "0.0.0-next.
|
37
|
+
"@orpc/client": "0.0.0-next.ff7ad2e",
|
38
|
+
"@orpc/contract": "0.0.0-next.ff7ad2e",
|
39
|
+
"@orpc/openapi-client": "0.0.0-next.ff7ad2e",
|
40
|
+
"@orpc/server": "0.0.0-next.ff7ad2e",
|
41
|
+
"@orpc/shared": "0.0.0-next.ff7ad2e"
|
42
42
|
},
|
43
43
|
"devDependencies": {
|
44
|
-
"react": "^19.1.
|
45
|
-
"zod": "^
|
44
|
+
"react": "^19.1.1",
|
45
|
+
"zod": "^4.0.17"
|
46
46
|
},
|
47
47
|
"scripts": {
|
48
48
|
"build": "unbuild",
|