@orpc/react 0.0.0-next.e9dc36e → 0.0.0-next.eaf61c7

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.
Files changed (79) hide show
  1. package/README.md +151 -0
  2. package/dist/hooks/index.d.mts +69 -0
  3. package/dist/hooks/index.d.ts +69 -0
  4. package/dist/hooks/index.mjs +77 -0
  5. package/dist/index.d.mts +19 -0
  6. package/dist/index.d.ts +19 -0
  7. package/dist/index.mjs +28 -0
  8. package/package.json +24 -24
  9. package/dist/index.js +0 -674
  10. package/dist/index.js.map +0 -1
  11. package/dist/src/general-hooks.d.ts +0 -24
  12. package/dist/src/general-hooks.d.ts.map +0 -1
  13. package/dist/src/general-utils.d.ts +0 -41
  14. package/dist/src/general-utils.d.ts.map +0 -1
  15. package/dist/src/index.d.ts +0 -9
  16. package/dist/src/index.d.ts.map +0 -1
  17. package/dist/src/orpc-path.d.ts +0 -5
  18. package/dist/src/orpc-path.d.ts.map +0 -1
  19. package/dist/src/procedure-hooks.d.ts +0 -31
  20. package/dist/src/procedure-hooks.d.ts.map +0 -1
  21. package/dist/src/procedure-utils.d.ts +0 -35
  22. package/dist/src/procedure-utils.d.ts.map +0 -1
  23. package/dist/src/react-context.d.ts +0 -13
  24. package/dist/src/react-context.d.ts.map +0 -1
  25. package/dist/src/react-hooks.d.ts +0 -22
  26. package/dist/src/react-hooks.d.ts.map +0 -1
  27. package/dist/src/react-utils.d.ts +0 -22
  28. package/dist/src/react-utils.d.ts.map +0 -1
  29. package/dist/src/react.d.ts +0 -21
  30. package/dist/src/react.d.ts.map +0 -1
  31. package/dist/src/tanstack-key.d.ts +0 -15
  32. package/dist/src/tanstack-key.d.ts.map +0 -1
  33. package/dist/src/tanstack-query.d.ts +0 -19
  34. package/dist/src/tanstack-query.d.ts.map +0 -1
  35. package/dist/src/types.d.ts +0 -5
  36. package/dist/src/types.d.ts.map +0 -1
  37. package/dist/src/use-queries/builder.d.ts +0 -20
  38. package/dist/src/use-queries/builder.d.ts.map +0 -1
  39. package/dist/src/use-queries/builders.d.ts +0 -19
  40. package/dist/src/use-queries/builders.d.ts.map +0 -1
  41. package/dist/src/use-queries/hook.d.ts +0 -16
  42. package/dist/src/use-queries/hook.d.ts.map +0 -1
  43. package/dist/tsconfig.tsbuildinfo +0 -1
  44. package/src/general-hooks.test-d.ts +0 -151
  45. package/src/general-hooks.test.tsx +0 -232
  46. package/src/general-hooks.ts +0 -101
  47. package/src/general-utils.test-d.ts +0 -454
  48. package/src/general-utils.test.tsx +0 -818
  49. package/src/general-utils.ts +0 -393
  50. package/src/index.ts +0 -8
  51. package/src/orpc-path.test-d.ts +0 -13
  52. package/src/orpc-path.test.ts +0 -12
  53. package/src/orpc-path.ts +0 -24
  54. package/src/procedure-hooks.test-d.ts +0 -321
  55. package/src/procedure-hooks.test.tsx +0 -388
  56. package/src/procedure-hooks.ts +0 -271
  57. package/src/procedure-utils.test-d.ts +0 -476
  58. package/src/procedure-utils.test.tsx +0 -330
  59. package/src/procedure-utils.ts +0 -312
  60. package/src/react-context.ts +0 -43
  61. package/src/react-hooks.ts +0 -94
  62. package/src/react-utils.ts +0 -98
  63. package/src/react.test-d.ts +0 -89
  64. package/src/react.test.tsx +0 -102
  65. package/src/react.tsx +0 -81
  66. package/src/tanstack-key.test-d.ts +0 -35
  67. package/src/tanstack-key.test.ts +0 -62
  68. package/src/tanstack-key.ts +0 -64
  69. package/src/tanstack-query.ts +0 -27
  70. package/src/types.ts +0 -7
  71. package/src/use-queries/builder.test-d.ts +0 -29
  72. package/src/use-queries/builder.test.ts +0 -25
  73. package/src/use-queries/builder.ts +0 -71
  74. package/src/use-queries/builders.test-d.ts +0 -30
  75. package/src/use-queries/builders.test.tsx +0 -29
  76. package/src/use-queries/builders.ts +0 -101
  77. package/src/use-queries/hook.test-d.ts +0 -64
  78. package/src/use-queries/hook.test.tsx +0 -89
  79. package/src/use-queries/hook.ts +0 -57
package/README.md ADDED
@@ -0,0 +1,151 @@
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
25
+
26
+ ---
27
+
28
+ ## Highlights
29
+
30
+ - **🔗 End-to-End Type Safety**: Ensure type-safe inputs, outputs, and errors from client to server.
31
+ - **📘 First-Class OpenAPI**: Built-in support that fully adheres to the OpenAPI standard.
32
+ - **📝 Contract-First Development**: Optionally define your API contract before implementation.
33
+ - **⚙️ Framework Integrations**: Seamlessly integrate with TanStack Query (React, Vue, Solid, Svelte), Pinia Colada, and more.
34
+ - **🚀 Server Actions**: Fully compatible with React Server Actions on Next.js, TanStack Start, and other platforms.
35
+ - **🔠 Standard Schema Support**: Works out of the box with Zod, Valibot, ArkType, and other schema validators.
36
+ - **🗃️ Native Types**: Supports native types like Date, File, Blob, BigInt, URL, and more.
37
+ - **⏱️ Lazy Router**: Enhance cold start times with our lazy routing feature.
38
+ - **📡 SSE & Streaming**: Enjoy full type-safe support for SSE and streaming.
39
+ - **🌍 Multi-Runtime Support**: Fast and lightweight on Cloudflare, Deno, Bun, Node.js, and beyond.
40
+ - **🔌 Extendability**: Easily extend functionality with plugins, middleware, and interceptors.
41
+ - **🛡️ Reliability**: Well-tested, TypeScript-based, production-ready, and MIT licensed.
42
+
43
+ ## Documentation
44
+
45
+ You can find the full documentation [here](https://orpc.unnoq.com).
46
+
47
+ ## Packages
48
+
49
+ - [@orpc/contract](https://www.npmjs.com/package/@orpc/contract): Build your API contract.
50
+ - [@orpc/server](https://www.npmjs.com/package/@orpc/server): Build your API or implement API contract.
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/nest](https://www.npmjs.com/package/@orpc/nest): Deeply integrate oRPC with [NestJS](https://nestjs.com/).
54
+ - [@orpc/react](https://www.npmjs.com/package/@orpc/react): Utilities for integrating oRPC with React and React Server Actions.
55
+ - [@orpc/tanstack-query](https://www.npmjs.com/package/@orpc/tanstack-query): [TanStack Query](https://tanstack.com/query/latest) integration.
56
+ - [@orpc/vue-colada](https://www.npmjs.com/package/@orpc/vue-colada): Integration with [Pinia Colada](https://pinia-colada.esm.dev/).
57
+ - [@orpc/hey-api](https://www.npmjs.com/package/@orpc/hey-api): [Hey API](https://heyapi.dev/) integration.
58
+ - [@orpc/zod](https://www.npmjs.com/package/@orpc/zod): More schemas that [Zod](https://zod.dev/) doesn't support yet.
59
+ - [@orpc/valibot](https://www.npmjs.com/package/@orpc/valibot): OpenAPI spec generation from [Valibot](https://valibot.dev/).
60
+ - [@orpc/arktype](https://www.npmjs.com/package/@orpc/arktype): OpenAPI spec generation from [ArkType](https://arktype.io/).
61
+
62
+ ## `@orpc/react`
63
+
64
+ Provides utilities for integrating oRPC with React and React Server Actions. Read the [documentation](https://orpc.unnoq.com/docs/server-action) for more information.
65
+
66
+ ### `useServerAction` Hook
67
+
68
+ The `useServerAction` hook simplifies invoking server actions in React.
69
+
70
+ ```tsx
71
+ 'use client'
72
+
73
+ import { isDefinedError, onError } from '@orpc/client'
74
+ import { useServerAction } from '@orpc/react'
75
+
76
+ export function MyComponent() {
77
+ const { execute, data, error, status } = useServerAction(someAction, {
78
+ interceptors: [
79
+ onError((error) => {
80
+ if (isDefinedError(error)) {
81
+ console.error(error.data)
82
+ // ^ Typed error data
83
+ }
84
+ }),
85
+ ],
86
+ })
87
+
88
+ const action = async (form: FormData) => {
89
+ const name = form.get('name') as string
90
+ execute({ name })
91
+ }
92
+
93
+ return (
94
+ <form action={action}>
95
+ <input type="text" name="name" required />
96
+ <button type="submit">Submit</button>
97
+ {status === 'pending' && <p>Loading...</p>}
98
+ </form>
99
+ )
100
+ }
101
+ ```
102
+
103
+ ### `createFormAction` Utility
104
+
105
+ Creates a form action that can be used in React forms and deserializes with bracket notation.
106
+
107
+ ```tsx
108
+ const dosomething = os
109
+ .input(
110
+ z.object({
111
+ user: z.object({
112
+ name: z.string(),
113
+ age: z.coerce.number(),
114
+ }),
115
+ })
116
+ )
117
+ .handler(({ input }) => {
118
+ console.log('Form action called!')
119
+ console.log(input)
120
+ })
121
+
122
+ export const redirectSomeWhereForm = createFormAction(dosomething, {
123
+ interceptors: [
124
+ onSuccess(async () => {
125
+ redirect('/some-where')
126
+ }),
127
+ ],
128
+ })
129
+
130
+ export function MyComponent() {
131
+ return (
132
+ <form action={redirectSomeWhereForm}>
133
+ <input type="text" name="user[name]" required />
134
+ <input type="number" name="user[age]" required />
135
+ <button type="submit">Submit</button>
136
+ </form>
137
+ )
138
+ }
139
+ ```
140
+
141
+ ## Sponsors
142
+
143
+ <p align="center">
144
+ <a href="https://cdn.jsdelivr.net/gh/unnoq/unnoq/sponsors.svg">
145
+ <img src='https://cdn.jsdelivr.net/gh/unnoq/unnoq/sponsors.svg'/>
146
+ </a>
147
+ </p>
148
+
149
+ ## License
150
+
151
+ Distributed under the MIT License. See [LICENSE](https://github.com/unnoq/orpc/blob/main/LICENSE) for more information.
@@ -0,0 +1,69 @@
1
+ import { SafeResult, ORPCErrorJSON } from '@orpc/client';
2
+ import { ActionableClient, UnactionableError } from '@orpc/server';
3
+ import { Interceptor, PromiseWithError } from '@orpc/shared';
4
+
5
+ interface UseServerActionOptions<TInput, TOutput, TError> {
6
+ interceptors?: Interceptor<{
7
+ input: TInput;
8
+ }, PromiseWithError<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
+ /**
62
+ * Use a Server Action Hook
63
+ *
64
+ * @see {@link https://orpc.unnoq.com/docs/server-action#useserveraction-hook Server Action Hook Docs}
65
+ */
66
+ 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>>;
67
+
68
+ export { useServerAction };
69
+ export type { UseServerActionErrorResult, UseServerActionExecuteOptions, UseServerActionExecuteRest, UseServerActionIdleResult, UseServerActionOptions, UseServerActionPendingResult, UseServerActionResultBase, UseServerActionSuccessResult };
@@ -0,0 +1,69 @@
1
+ import { SafeResult, ORPCErrorJSON } from '@orpc/client';
2
+ import { ActionableClient, UnactionableError } from '@orpc/server';
3
+ import { Interceptor, PromiseWithError } from '@orpc/shared';
4
+
5
+ interface UseServerActionOptions<TInput, TOutput, TError> {
6
+ interceptors?: Interceptor<{
7
+ input: TInput;
8
+ }, PromiseWithError<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
+ /**
62
+ * Use a Server Action Hook
63
+ *
64
+ * @see {@link https://orpc.unnoq.com/docs/server-action#useserveraction-hook Server Action Hook Docs}
65
+ */
66
+ 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>>;
67
+
68
+ export { useServerAction };
69
+ export type { UseServerActionErrorResult, UseServerActionExecuteOptions, UseServerActionExecuteRest, UseServerActionIdleResult, UseServerActionOptions, UseServerActionPendingResult, UseServerActionResultBase, UseServerActionSuccessResult };
@@ -0,0 +1,77 @@
1
+ import { safe, createORPCErrorFromJson } from '@orpc/client';
2
+ import { intercept, toArray } from '@orpc/shared';
3
+ import { useState, useRef, useTransition, 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
+ };
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"
22
+ };
23
+ function useServerAction(action, options = {}) {
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();
28
+ const reset = useCallback(() => {
29
+ executedAtRef.current = void 0;
30
+ setInput(void 0);
31
+ setState({ ...INITIAL_STATE });
32
+ }, []);
33
+ const execute = useCallback(async (input2, executeOptions = {}) => {
34
+ const executedAt = /* @__PURE__ */ new Date();
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
+ });
59
+ }
60
+ resolve(result2);
61
+ });
62
+ });
63
+ }, [action, ...toArray(options.interceptors)]);
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]);
74
+ return result;
75
+ }
76
+
77
+ export { useServerAction };
@@ -0,0 +1,19 @@
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
+ export { getIssueMessage, parseFormData } from '@orpc/openapi-client/standard';
5
+
6
+ interface FormAction {
7
+ (form: FormData): Promise<void>;
8
+ }
9
+ declare const orpcErrorToNextHttpFallbackInterceptor: Interceptor<any, Promise<any>>;
10
+ /**
11
+ * Create a server action accept a form data and deserialize with bracket notation.
12
+ *
13
+ * @see {@link https://orpc.unnoq.com/docs/server-action#createformaction-utility Create Form Action Utility Docs}
14
+ * @see {@link https://orpc.unnoq.com/docs/openapi/bracket-notation Bracket Notation Docs}
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;
17
+
18
+ export { createFormAction, orpcErrorToNextHttpFallbackInterceptor };
19
+ export type { FormAction };
@@ -0,0 +1,19 @@
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
+ export { getIssueMessage, parseFormData } from '@orpc/openapi-client/standard';
5
+
6
+ interface FormAction {
7
+ (form: FormData): Promise<void>;
8
+ }
9
+ declare const orpcErrorToNextHttpFallbackInterceptor: Interceptor<any, Promise<any>>;
10
+ /**
11
+ * Create a server action accept a form data and deserialize with bracket notation.
12
+ *
13
+ * @see {@link https://orpc.unnoq.com/docs/server-action#createformaction-utility Create Form Action Utility Docs}
14
+ * @see {@link https://orpc.unnoq.com/docs/openapi/bracket-notation Bracket Notation Docs}
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;
17
+
18
+ export { createFormAction, orpcErrorToNextHttpFallbackInterceptor };
19
+ export type { FormAction };
package/dist/index.mjs ADDED
@@ -0,0 +1,28 @@
1
+ import { ORPCError, createORPCErrorFromJson } from '@orpc/client';
2
+ import { StandardBracketNotationSerializer } from '@orpc/openapi-client/standard';
3
+ export { getIssueMessage, parseFormData } from '@orpc/openapi-client/standard';
4
+ import { createProcedureClient } from '@orpc/server';
5
+ import { onError, resolveMaybeOptionalOptions, toArray } from '@orpc/shared';
6
+
7
+ const orpcErrorToNextHttpFallbackInterceptor = onError((error) => {
8
+ if (error instanceof ORPCError && [401, 403, 404].includes(error.status)) {
9
+ const nextError = createORPCErrorFromJson(error.toJSON());
10
+ nextError.cause = error;
11
+ nextError.digest = `NEXT_HTTP_ERROR_FALLBACK;${error.status}`;
12
+ throw nextError;
13
+ }
14
+ });
15
+ function createFormAction(lazyableProcedure, ...rest) {
16
+ const options = resolveMaybeOptionalOptions(rest);
17
+ const client = createProcedureClient(lazyableProcedure, {
18
+ ...options,
19
+ interceptors: [orpcErrorToNextHttpFallbackInterceptor, ...toArray(options.interceptors)]
20
+ });
21
+ const bracketNotation = new StandardBracketNotationSerializer();
22
+ return async (form) => {
23
+ const input = bracketNotation.deserialize([...form]);
24
+ await client(input);
25
+ };
26
+ }
27
+
28
+ export { createFormAction, orpcErrorToNextHttpFallbackInterceptor };
package/package.json CHANGED
@@ -1,51 +1,51 @@
1
1
  {
2
2
  "name": "@orpc/react",
3
3
  "type": "module",
4
- "version": "0.0.0-next.e9dc36e",
5
- "author": {
6
- "name": "unnoq",
7
- "email": "contact@unnoq.com",
8
- "url": "https://unnoq.com"
9
- },
4
+ "version": "0.0.0-next.eaf61c7",
10
5
  "license": "MIT",
11
- "homepage": "https://github.com/unnoq/orpc",
6
+ "homepage": "https://orpc.unnoq.com",
12
7
  "repository": {
13
8
  "type": "git",
14
- "url": "https://github.com/unnoq/orpc.git",
9
+ "url": "git+https://github.com/unnoq/orpc.git",
15
10
  "directory": "packages/react"
16
11
  },
17
12
  "keywords": [
18
- "unnoq"
13
+ "unnoq",
14
+ "orpc",
15
+ "react",
16
+ "nextjs"
19
17
  ],
20
18
  "exports": {
21
19
  ".": {
22
- "types": "./dist/src/index.d.ts",
23
- "import": "./dist/index.js",
24
- "default": "./dist/index.js"
20
+ "types": "./dist/index.d.mts",
21
+ "import": "./dist/index.mjs",
22
+ "default": "./dist/index.mjs"
25
23
  },
26
- "./🔒/*": {
27
- "types": "./dist/src/*.d.ts"
24
+ "./hooks": {
25
+ "types": "./dist/hooks/index.d.mts",
26
+ "import": "./dist/hooks/index.mjs",
27
+ "default": "./dist/hooks/index.mjs"
28
28
  }
29
29
  },
30
30
  "files": [
31
- "dist",
32
- "src"
31
+ "dist"
33
32
  ],
34
33
  "peerDependencies": {
35
- "@tanstack/react-query": ">=5.59.0",
36
- "react": ">=18.3.0",
37
- "@orpc/client": "0.0.0-next.e9dc36e",
38
- "@orpc/server": "0.0.0-next.e9dc36e",
39
- "@orpc/contract": "0.0.0-next.e9dc36e"
34
+ "react": ">=18.0.0"
40
35
  },
41
36
  "dependencies": {
42
- "@orpc/shared": "0.0.0-next.e9dc36e"
37
+ "@orpc/client": "0.0.0-next.eaf61c7",
38
+ "@orpc/contract": "0.0.0-next.eaf61c7",
39
+ "@orpc/server": "0.0.0-next.eaf61c7",
40
+ "@orpc/shared": "0.0.0-next.eaf61c7",
41
+ "@orpc/openapi-client": "0.0.0-next.eaf61c7"
43
42
  },
44
43
  "devDependencies": {
45
- "zod": "^3.23.8"
44
+ "react": "^19.1.0",
45
+ "zod": "^3.25.57"
46
46
  },
47
47
  "scripts": {
48
- "build": "tsup --clean --sourcemap --entry.index=src/index.ts --format=esm --onSuccess='tsc -b --noCheck'",
48
+ "build": "unbuild",
49
49
  "build:watch": "pnpm run build --watch",
50
50
  "type:check": "tsc -b"
51
51
  }