@orpc/react 0.27.0 → 1.0.0-beta.5
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 +156 -0
- package/dist/hooks/index.d.mts +63 -0
- package/dist/hooks/index.d.ts +63 -0
- package/dist/hooks/index.mjs +65 -0
- package/dist/index.d.mts +11 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.mjs +27 -0
- package/package.json +20 -17
- package/dist/index.js +0 -672
- package/dist/src/general-hooks.d.ts +0 -23
- package/dist/src/general-utils.d.ts +0 -40
- package/dist/src/index.d.ts +0 -9
- package/dist/src/orpc-path.d.ts +0 -5
- package/dist/src/procedure-hooks.d.ts +0 -30
- package/dist/src/procedure-utils.d.ts +0 -34
- package/dist/src/react-context.d.ts +0 -11
- package/dist/src/react-hooks.d.ts +0 -18
- package/dist/src/react-utils.d.ts +0 -18
- package/dist/src/react.d.ts +0 -15
- package/dist/src/tanstack-key.d.ts +0 -14
- package/dist/src/tanstack-query.d.ts +0 -19
- package/dist/src/types.d.ts +0 -5
- package/dist/src/use-queries/builder.d.ts +0 -19
- package/dist/src/use-queries/builders.d.ts +0 -14
- package/dist/src/use-queries/hook.d.ts +0 -12
package/README.md
ADDED
@@ -0,0 +1,156 @@
|
|
1
|
+
<div align="center">
|
2
|
+
<image align="center" src="https://orpc.unnoq.com/logo.webp" width=280 alt="oRPC logo" />
|
3
|
+
</div>
|
4
|
+
|
5
|
+
<h1></h1>
|
6
|
+
|
7
|
+
<div align="center">
|
8
|
+
<a href="https://codecov.io/gh/unnoq/orpc">
|
9
|
+
<img alt="codecov" src="https://codecov.io/gh/unnoq/orpc/branch/main/graph/badge.svg">
|
10
|
+
</a>
|
11
|
+
<a href="https://www.npmjs.com/package/@orpc/react">
|
12
|
+
<img alt="weekly downloads" src="https://img.shields.io/npm/dw/%40orpc%2Freact?logo=npm" />
|
13
|
+
</a>
|
14
|
+
<a href="https://github.com/unnoq/orpc/blob/main/LICENSE">
|
15
|
+
<img alt="MIT License" src="https://img.shields.io/github/license/unnoq/orpc?logo=open-source-initiative" />
|
16
|
+
</a>
|
17
|
+
<a href="https://discord.gg/TXEbwRBvQn">
|
18
|
+
<img alt="Discord" src="https://img.shields.io/discord/1308966753044398161?color=7389D8&label&logo=discord&logoColor=ffffff" />
|
19
|
+
</a>
|
20
|
+
</div>
|
21
|
+
|
22
|
+
<h3 align="center">Typesafe APIs Made Simple 🪄</h3>
|
23
|
+
|
24
|
+
**oRPC is a powerful combination of RPC and OpenAPI**, makes it easy to build APIs that are end-to-end type-safe and adhere to OpenAPI standards, ensuring a smooth and enjoyable developer experience.
|
25
|
+
|
26
|
+
---
|
27
|
+
|
28
|
+
## Highlights
|
29
|
+
|
30
|
+
- **End-to-End Type Safety 🔒**: Ensure complete type safety from inputs to outputs and errors, bridging server and client seamlessly.
|
31
|
+
- **First-Class OpenAPI 📄**: Adheres to the OpenAPI standard out of the box, ensuring seamless integration and comprehensive API documentation.
|
32
|
+
- **Contract-First Development 📜**: (Optional) Define your API contract upfront and implement it with confidence.
|
33
|
+
- **Exceptional Developer Experience ✨**: Enjoy a streamlined workflow with robust typing and clear, in-code documentation.
|
34
|
+
- **Multi-Runtime Support 🌍**: Run your code seamlessly on Cloudflare, Deno, Bun, Node.js, and more.
|
35
|
+
- **Framework Integrations 🧩**: Supports Tanstack Query (React, Vue, Solid, Svelte), Pinia Colada, and more.
|
36
|
+
- **Server Actions ⚡️**: Fully compatible with React Server Actions on Next.js, TanStack Start, and more.
|
37
|
+
- **Standard Schema Support 🗂️**: Effortlessly work with Zod, Valibot, ArkType, and others right out of the box.
|
38
|
+
- **Fast & Lightweight 💨**: Built on native APIs across all runtimes – optimized for speed and efficiency.
|
39
|
+
- **Native Types 📦**: Enjoy built-in support for Date, File, Blob, BigInt, URL and more with no extra setup.
|
40
|
+
- **Lazy Router ⏱️**: Improve cold start times with our lazy routing feature.
|
41
|
+
- **SSE & Streaming 📡**: Provides SSE and streaming features – perfect for real-time notifications and AI-powered streaming responses.
|
42
|
+
- **Reusability 🔄**: Write once and reuse your code across multiple purposes effortlessly.
|
43
|
+
- **Extendability 🔌**: Easily enhance oRPC with plugins, middleware, and interceptors.
|
44
|
+
- **Reliability 🛡️**: Well-tested, fully TypeScript, production-ready, and MIT licensed for peace of mind.
|
45
|
+
- **Simplicity 💡**: Enjoy straightforward, clean code with no hidden magic.
|
46
|
+
|
47
|
+
## Documentation
|
48
|
+
|
49
|
+
You can find the full documentation [here](https://orpc.unnoq.com).
|
50
|
+
|
51
|
+
## Packages
|
52
|
+
|
53
|
+
- [@orpc/contract](https://www.npmjs.com/package/@orpc/contract): Build your API contract.
|
54
|
+
- [@orpc/server](https://www.npmjs.com/package/@orpc/server): Build your API or implement API contract.
|
55
|
+
- [@orpc/client](https://www.npmjs.com/package/@orpc/client): Consume your API on the client with type-safety.
|
56
|
+
- [@orpc/react](https://www.npmjs.com/package/@orpc/react): Utilities for integrating oRPC with React and React Server Actions.
|
57
|
+
- [@orpc/react-query](https://www.npmjs.com/package/@orpc/react-query): Integration with [React Query](https://tanstack.com/query/latest/docs/framework/react/overview).
|
58
|
+
- [@orpc/vue-query](https://www.npmjs.com/package/@orpc/vue-query): Integration with [Vue Query](https://tanstack.com/query/latest/docs/framework/vue/overview).
|
59
|
+
- [@orpc/solid-query](https://www.npmjs.com/package/@orpc/solid-query): Integration with [Solid Query](https://tanstack.com/query/latest/docs/framework/solid/overview).
|
60
|
+
- [@orpc/svelte-query](https://www.npmjs.com/package/@orpc/svelte-query): Integration with [Svelte Query](https://tanstack.com/query/latest/docs/framework/svelte/overview).
|
61
|
+
- [@orpc/vue-colada](https://www.npmjs.com/package/@orpc/vue-colada): Integration with [Pinia Colada](https://pinia-colada.esm.dev/).
|
62
|
+
- [@orpc/openapi](https://www.npmjs.com/package/@orpc/openapi): Generate OpenAPI specs and handle OpenAPI requests.
|
63
|
+
- [@orpc/zod](https://www.npmjs.com/package/@orpc/zod): More schemas that [Zod](https://zod.dev/) doesn't support yet.
|
64
|
+
- [@orpc/valibot](https://www.npmjs.com/package/@orpc/valibot): OpenAPI spec generation from [Valibot](https://valibot.dev/).
|
65
|
+
- [@orpc/arktype](https://www.npmjs.com/package/@orpc/arktype): OpenAPI spec generation from [ArkType](https://arktype.io/).
|
66
|
+
|
67
|
+
## `@orpc/react`
|
68
|
+
|
69
|
+
Provides utilities for integrating oRPC with React and React Server Actions. Read the [documentation](https://orpc.unnoq.com/docs/server-action) for more information.
|
70
|
+
|
71
|
+
### `useServerAction` Hook
|
72
|
+
|
73
|
+
The `useServerAction` hook simplifies invoking server actions in React.
|
74
|
+
|
75
|
+
```tsx
|
76
|
+
'use client'
|
77
|
+
|
78
|
+
import { isDefinedError, onError } from '@orpc/client'
|
79
|
+
import { useServerAction } from '@orpc/react'
|
80
|
+
|
81
|
+
export function MyComponent() {
|
82
|
+
const { execute, data, error, status } = useServerAction(someAction, {
|
83
|
+
interceptors: [
|
84
|
+
onError((error) => {
|
85
|
+
if (isDefinedError(error)) {
|
86
|
+
console.error(error.data)
|
87
|
+
// ^ Typed error data
|
88
|
+
}
|
89
|
+
}),
|
90
|
+
],
|
91
|
+
})
|
92
|
+
|
93
|
+
const action = async (form: FormData) => {
|
94
|
+
const name = form.get('name') as string
|
95
|
+
execute({ name })
|
96
|
+
}
|
97
|
+
|
98
|
+
return (
|
99
|
+
<form action={action}>
|
100
|
+
<input type="text" name="name" required />
|
101
|
+
<button type="submit">Submit</button>
|
102
|
+
{status === 'pending' && <p>Loading...</p>}
|
103
|
+
</form>
|
104
|
+
)
|
105
|
+
}
|
106
|
+
```
|
107
|
+
|
108
|
+
### `createFormAction` Utility
|
109
|
+
|
110
|
+
Creates a form action that can be used in React forms and deserializes with bracket notation.
|
111
|
+
|
112
|
+
```tsx
|
113
|
+
const dosomething = os
|
114
|
+
.input(
|
115
|
+
z.object({
|
116
|
+
user: z.object({
|
117
|
+
name: z.string(),
|
118
|
+
age: z.coerce.number(),
|
119
|
+
}),
|
120
|
+
})
|
121
|
+
)
|
122
|
+
.handler(({ input }) => {
|
123
|
+
console.log('Form action called!')
|
124
|
+
console.log(input)
|
125
|
+
})
|
126
|
+
|
127
|
+
export const redirectSomeWhereForm = createFormAction(dosomething, {
|
128
|
+
interceptors: [
|
129
|
+
onSuccess(async () => {
|
130
|
+
redirect('/some-where')
|
131
|
+
}),
|
132
|
+
],
|
133
|
+
})
|
134
|
+
|
135
|
+
export function MyComponent() {
|
136
|
+
return (
|
137
|
+
<form action={redirectSomeWhereForm}>
|
138
|
+
<input type="text" name="user[name]" required />
|
139
|
+
<input type="number" name="user[age]" required />
|
140
|
+
<button type="submit">Submit</button>
|
141
|
+
</form>
|
142
|
+
)
|
143
|
+
}
|
144
|
+
```
|
145
|
+
|
146
|
+
## Sponsors
|
147
|
+
|
148
|
+
<p align="center">
|
149
|
+
<a href="https://cdn.jsdelivr.net/gh/unnoq/unnoq/sponsors.svg">
|
150
|
+
<img src='https://cdn.jsdelivr.net/gh/unnoq/unnoq/sponsors.svg'/>
|
151
|
+
</a>
|
152
|
+
</p>
|
153
|
+
|
154
|
+
## License
|
155
|
+
|
156
|
+
Distributed under the MIT License. See [LICENSE](https://github.com/unnoq/orpc/blob/main/LICENSE) for more information.
|
@@ -0,0 +1,63 @@
|
|
1
|
+
import { SafeResult, ORPCErrorJSON } from '@orpc/client';
|
2
|
+
import { ActionableClient, UnactionableError } from '@orpc/server';
|
3
|
+
import { Interceptor } from '@orpc/shared';
|
4
|
+
|
5
|
+
interface UseServerActionOptions<TInput, TOutput, TError> {
|
6
|
+
interceptors?: Interceptor<{
|
7
|
+
input: TInput;
|
8
|
+
}, TOutput, TError>[];
|
9
|
+
}
|
10
|
+
interface UseServerActionExecuteOptions<TInput, TOutput, TError> extends Pick<UseServerActionOptions<TInput, TOutput, TError>, 'interceptors'> {
|
11
|
+
}
|
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
|
+
reset: () => void;
|
15
|
+
execute: (...rest: UseServerActionExecuteRest<TInput, TOutput, TError>) => Promise<SafeResult<TOutput, TError>>;
|
16
|
+
}
|
17
|
+
interface UseServerActionIdleResult<TInput, TOutput, TError> extends UseServerActionResultBase<TInput, TOutput, TError> {
|
18
|
+
input: undefined;
|
19
|
+
data: undefined;
|
20
|
+
error: null;
|
21
|
+
isIdle: true;
|
22
|
+
isPending: false;
|
23
|
+
isSuccess: false;
|
24
|
+
isError: false;
|
25
|
+
status: 'idle';
|
26
|
+
executedAt: undefined;
|
27
|
+
}
|
28
|
+
interface UseServerActionPendingResult<TInput, TOutput, TError> extends UseServerActionResultBase<TInput, TOutput, TError> {
|
29
|
+
input: TInput;
|
30
|
+
data: undefined;
|
31
|
+
error: null;
|
32
|
+
isIdle: false;
|
33
|
+
isPending: true;
|
34
|
+
isSuccess: false;
|
35
|
+
isError: false;
|
36
|
+
status: 'pending';
|
37
|
+
executedAt: Date;
|
38
|
+
}
|
39
|
+
interface UseServerActionSuccessResult<TInput, TOutput, TError> extends UseServerActionResultBase<TInput, TOutput, TError> {
|
40
|
+
input: TInput;
|
41
|
+
data: TOutput;
|
42
|
+
error: null;
|
43
|
+
isIdle: false;
|
44
|
+
isPending: false;
|
45
|
+
isSuccess: true;
|
46
|
+
isError: false;
|
47
|
+
status: 'success';
|
48
|
+
executedAt: Date;
|
49
|
+
}
|
50
|
+
interface UseServerActionErrorResult<TInput, TOutput, TError> extends UseServerActionResultBase<TInput, TOutput, TError> {
|
51
|
+
input: TInput;
|
52
|
+
data: undefined;
|
53
|
+
error: TError;
|
54
|
+
isIdle: false;
|
55
|
+
isPending: false;
|
56
|
+
isSuccess: false;
|
57
|
+
isError: true;
|
58
|
+
status: 'error';
|
59
|
+
executedAt: Date;
|
60
|
+
}
|
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
|
+
|
63
|
+
export { type UseServerActionErrorResult, type UseServerActionExecuteOptions, type UseServerActionExecuteRest, type UseServerActionIdleResult, type UseServerActionOptions, type UseServerActionPendingResult, type UseServerActionResultBase, type UseServerActionSuccessResult, useServerAction };
|
@@ -0,0 +1,63 @@
|
|
1
|
+
import { SafeResult, ORPCErrorJSON } from '@orpc/client';
|
2
|
+
import { ActionableClient, UnactionableError } from '@orpc/server';
|
3
|
+
import { Interceptor } from '@orpc/shared';
|
4
|
+
|
5
|
+
interface UseServerActionOptions<TInput, TOutput, TError> {
|
6
|
+
interceptors?: Interceptor<{
|
7
|
+
input: TInput;
|
8
|
+
}, TOutput, TError>[];
|
9
|
+
}
|
10
|
+
interface UseServerActionExecuteOptions<TInput, TOutput, TError> extends Pick<UseServerActionOptions<TInput, TOutput, TError>, 'interceptors'> {
|
11
|
+
}
|
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
|
+
reset: () => void;
|
15
|
+
execute: (...rest: UseServerActionExecuteRest<TInput, TOutput, TError>) => Promise<SafeResult<TOutput, TError>>;
|
16
|
+
}
|
17
|
+
interface UseServerActionIdleResult<TInput, TOutput, TError> extends UseServerActionResultBase<TInput, TOutput, TError> {
|
18
|
+
input: undefined;
|
19
|
+
data: undefined;
|
20
|
+
error: null;
|
21
|
+
isIdle: true;
|
22
|
+
isPending: false;
|
23
|
+
isSuccess: false;
|
24
|
+
isError: false;
|
25
|
+
status: 'idle';
|
26
|
+
executedAt: undefined;
|
27
|
+
}
|
28
|
+
interface UseServerActionPendingResult<TInput, TOutput, TError> extends UseServerActionResultBase<TInput, TOutput, TError> {
|
29
|
+
input: TInput;
|
30
|
+
data: undefined;
|
31
|
+
error: null;
|
32
|
+
isIdle: false;
|
33
|
+
isPending: true;
|
34
|
+
isSuccess: false;
|
35
|
+
isError: false;
|
36
|
+
status: 'pending';
|
37
|
+
executedAt: Date;
|
38
|
+
}
|
39
|
+
interface UseServerActionSuccessResult<TInput, TOutput, TError> extends UseServerActionResultBase<TInput, TOutput, TError> {
|
40
|
+
input: TInput;
|
41
|
+
data: TOutput;
|
42
|
+
error: null;
|
43
|
+
isIdle: false;
|
44
|
+
isPending: false;
|
45
|
+
isSuccess: true;
|
46
|
+
isError: false;
|
47
|
+
status: 'success';
|
48
|
+
executedAt: Date;
|
49
|
+
}
|
50
|
+
interface UseServerActionErrorResult<TInput, TOutput, TError> extends UseServerActionResultBase<TInput, TOutput, TError> {
|
51
|
+
input: TInput;
|
52
|
+
data: undefined;
|
53
|
+
error: TError;
|
54
|
+
isIdle: false;
|
55
|
+
isPending: false;
|
56
|
+
isSuccess: false;
|
57
|
+
isError: true;
|
58
|
+
status: 'error';
|
59
|
+
executedAt: Date;
|
60
|
+
}
|
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
|
+
|
63
|
+
export { type UseServerActionErrorResult, type UseServerActionExecuteOptions, type UseServerActionExecuteRest, type UseServerActionIdleResult, type UseServerActionOptions, type UseServerActionPendingResult, type UseServerActionResultBase, type UseServerActionSuccessResult, useServerAction };
|
@@ -0,0 +1,65 @@
|
|
1
|
+
import { safe, ORPCError } from '@orpc/client';
|
2
|
+
import { intercept, toArray } from '@orpc/shared';
|
3
|
+
import { useState, useCallback, useMemo } from 'react';
|
4
|
+
|
5
|
+
const INITIAL_STATE = {
|
6
|
+
data: void 0,
|
7
|
+
error: null,
|
8
|
+
isIdle: true,
|
9
|
+
isPending: false,
|
10
|
+
isSuccess: false,
|
11
|
+
isError: false,
|
12
|
+
status: "idle",
|
13
|
+
executedAt: void 0,
|
14
|
+
input: void 0
|
15
|
+
};
|
16
|
+
function useServerAction(action, options = {}) {
|
17
|
+
const [state, setState] = useState(INITIAL_STATE);
|
18
|
+
const reset = useCallback(() => {
|
19
|
+
setState(INITIAL_STATE);
|
20
|
+
}, []);
|
21
|
+
const execute = useCallback(async (input, executeOptions = {}) => {
|
22
|
+
const executedAt = /* @__PURE__ */ new Date();
|
23
|
+
setState({
|
24
|
+
data: void 0,
|
25
|
+
error: null,
|
26
|
+
isIdle: false,
|
27
|
+
isPending: true,
|
28
|
+
isSuccess: false,
|
29
|
+
isError: false,
|
30
|
+
status: "pending",
|
31
|
+
executedAt,
|
32
|
+
input
|
33
|
+
});
|
34
|
+
const result2 = await safe(intercept(
|
35
|
+
[...toArray(options.interceptors), ...toArray(executeOptions.interceptors)],
|
36
|
+
{ input },
|
37
|
+
({ input: input2 }) => action(input2).then(([error, data]) => {
|
38
|
+
if (error) {
|
39
|
+
throw ORPCError.fromJSON(error);
|
40
|
+
}
|
41
|
+
return data;
|
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
|
54
|
+
});
|
55
|
+
return result2;
|
56
|
+
}, [action, ...toArray(options.interceptors)]);
|
57
|
+
const result = useMemo(() => ({
|
58
|
+
...state,
|
59
|
+
reset,
|
60
|
+
execute
|
61
|
+
}), [state, reset, execute]);
|
62
|
+
return result;
|
63
|
+
}
|
64
|
+
|
65
|
+
export { useServerAction };
|
package/dist/index.d.mts
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
import { AnySchema } from '@orpc/contract';
|
2
|
+
import { Context, ErrorMap, Meta, Lazyable, Procedure, CreateProcedureClientOptions } from '@orpc/server';
|
3
|
+
import { Interceptor, MaybeOptionalOptions } from '@orpc/shared';
|
4
|
+
|
5
|
+
interface FormAction {
|
6
|
+
(form: FormData): Promise<void>;
|
7
|
+
}
|
8
|
+
declare const orpcErrorToNextHttpFallbackInterceptor: Interceptor<any, any, any>;
|
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
|
+
|
11
|
+
export { type FormAction, createFormAction, orpcErrorToNextHttpFallbackInterceptor };
|
package/dist/index.d.ts
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
import { AnySchema } from '@orpc/contract';
|
2
|
+
import { Context, ErrorMap, Meta, Lazyable, Procedure, CreateProcedureClientOptions } from '@orpc/server';
|
3
|
+
import { Interceptor, MaybeOptionalOptions } from '@orpc/shared';
|
4
|
+
|
5
|
+
interface FormAction {
|
6
|
+
(form: FormData): Promise<void>;
|
7
|
+
}
|
8
|
+
declare const orpcErrorToNextHttpFallbackInterceptor: Interceptor<any, any, any>;
|
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
|
+
|
11
|
+
export { type FormAction, createFormAction, orpcErrorToNextHttpFallbackInterceptor };
|
package/dist/index.mjs
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
import { ORPCError } from '@orpc/client';
|
2
|
+
import { StandardBracketNotationSerializer } from '@orpc/openapi-client/standard';
|
3
|
+
import { createProcedureClient } from '@orpc/server';
|
4
|
+
import { onError, resolveMaybeOptionalOptions, toArray } from '@orpc/shared';
|
5
|
+
|
6
|
+
const orpcErrorToNextHttpFallbackInterceptor = onError((error) => {
|
7
|
+
if (error instanceof ORPCError && [401, 403, 404].includes(error.status)) {
|
8
|
+
const nextError = ORPCError.fromJSON(error.toJSON());
|
9
|
+
nextError.cause = error;
|
10
|
+
nextError.digest = `NEXT_HTTP_ERROR_FALLBACK;${error.status}`;
|
11
|
+
throw nextError;
|
12
|
+
}
|
13
|
+
});
|
14
|
+
function createFormAction(lazyableProcedure, ...rest) {
|
15
|
+
const options = resolveMaybeOptionalOptions(rest);
|
16
|
+
const client = createProcedureClient(lazyableProcedure, {
|
17
|
+
...options,
|
18
|
+
interceptors: [orpcErrorToNextHttpFallbackInterceptor, ...toArray(options.interceptors)]
|
19
|
+
});
|
20
|
+
const bracketNotation = new StandardBracketNotationSerializer();
|
21
|
+
return async (form) => {
|
22
|
+
const input = bracketNotation.deserialize([...form]);
|
23
|
+
await client(input);
|
24
|
+
};
|
25
|
+
}
|
26
|
+
|
27
|
+
export { createFormAction, orpcErrorToNextHttpFallbackInterceptor };
|
package/package.json
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"name": "@orpc/react",
|
3
3
|
"type": "module",
|
4
|
-
"version": "0.
|
4
|
+
"version": "1.0.0-beta.5",
|
5
5
|
"license": "MIT",
|
6
6
|
"homepage": "https://orpc.unnoq.com",
|
7
7
|
"repository": {
|
@@ -11,38 +11,41 @@
|
|
11
11
|
},
|
12
12
|
"keywords": [
|
13
13
|
"unnoq",
|
14
|
-
"orpc"
|
14
|
+
"orpc",
|
15
|
+
"react",
|
16
|
+
"nextjs"
|
15
17
|
],
|
16
18
|
"exports": {
|
17
19
|
".": {
|
18
|
-
"types": "./dist/
|
19
|
-
"import": "./dist/index.
|
20
|
-
"default": "./dist/index.
|
20
|
+
"types": "./dist/index.d.mts",
|
21
|
+
"import": "./dist/index.mjs",
|
22
|
+
"default": "./dist/index.mjs"
|
21
23
|
},
|
22
|
-
"
|
23
|
-
"types": "./dist/
|
24
|
+
"./hooks": {
|
25
|
+
"types": "./dist/hooks/index.d.mts",
|
26
|
+
"import": "./dist/hooks/index.mjs",
|
27
|
+
"default": "./dist/hooks/index.mjs"
|
24
28
|
}
|
25
29
|
},
|
26
30
|
"files": [
|
27
|
-
"!**/*.map",
|
28
|
-
"!**/*.tsbuildinfo",
|
29
31
|
"dist"
|
30
32
|
],
|
31
33
|
"peerDependencies": {
|
32
|
-
"
|
33
|
-
"react": ">=18.3.0",
|
34
|
-
"@orpc/client": "0.27.0",
|
35
|
-
"@orpc/server": "0.27.0",
|
36
|
-
"@orpc/contract": "0.27.0"
|
34
|
+
"react": ">=18.0.0"
|
37
35
|
},
|
38
36
|
"dependencies": {
|
39
|
-
"@orpc/
|
37
|
+
"@orpc/client": "1.0.0-beta.5",
|
38
|
+
"@orpc/contract": "1.0.0-beta.5",
|
39
|
+
"@orpc/openapi-client": "1.0.0-beta.5",
|
40
|
+
"@orpc/server": "1.0.0-beta.5",
|
41
|
+
"@orpc/shared": "1.0.0-beta.5"
|
40
42
|
},
|
41
43
|
"devDependencies": {
|
42
|
-
"
|
44
|
+
"react": "^19.1.0",
|
45
|
+
"zod": "^3.24.2"
|
43
46
|
},
|
44
47
|
"scripts": {
|
45
|
-
"build": "
|
48
|
+
"build": "unbuild",
|
46
49
|
"build:watch": "pnpm run build --watch",
|
47
50
|
"type:check": "tsc -b"
|
48
51
|
}
|