@orpc/experimental-react-swr 0.0.0 → 1.8.3
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 +5 -4
- package/dist/index.d.mts +40 -5
- package/dist/index.d.ts +40 -5
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -8,8 +8,8 @@
|
|
|
8
8
|
<a href="https://codecov.io/gh/unnoq/orpc">
|
|
9
9
|
<img alt="codecov" src="https://codecov.io/gh/unnoq/orpc/branch/main/graph/badge.svg">
|
|
10
10
|
</a>
|
|
11
|
-
<a href="https://www.npmjs.com/package/@orpc/react-swr">
|
|
12
|
-
<img alt="weekly downloads" src="https://img.shields.io/npm/dw/%40orpc%
|
|
11
|
+
<a href="https://www.npmjs.com/package/@orpc/experimental-react-swr">
|
|
12
|
+
<img alt="weekly downloads" src="https://img.shields.io/npm/dw/%40orpc%2Fexperimental-react-swr?logo=npm" />
|
|
13
13
|
</a>
|
|
14
14
|
<a href="https://github.com/unnoq/orpc/blob/main/LICENSE">
|
|
15
15
|
<img alt="MIT License" src="https://img.shields.io/github/license/unnoq/orpc?logo=open-source-initiative" />
|
|
@@ -31,7 +31,7 @@
|
|
|
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), Pinia Colada, and more.
|
|
34
|
+
- **⚙️ Framework Integrations**: Seamlessly integrate with TanStack Query (React, Vue, Solid, Svelte, Angular), SWR, Pinia Colada, and more.
|
|
35
35
|
- **🚀 Server Actions**: Fully compatible with React Server Actions on Next.js, TanStack Start, and other platforms.
|
|
36
36
|
- **🔠 Standard Schema Support**: Works out of the box with Zod, Valibot, ArkType, and other schema validators.
|
|
37
37
|
- **🗃️ Native Types**: Supports native types like Date, File, Blob, BigInt, URL, and more.
|
|
@@ -54,13 +54,14 @@ You can find the full documentation [here](https://orpc.unnoq.com).
|
|
|
54
54
|
- [@orpc/nest](https://www.npmjs.com/package/@orpc/nest): Deeply integrate oRPC with [NestJS](https://nestjs.com/).
|
|
55
55
|
- [@orpc/react](https://www.npmjs.com/package/@orpc/react): Utilities for integrating oRPC with React and React Server Actions.
|
|
56
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
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/).
|
|
62
63
|
|
|
63
|
-
## `@orpc/react-swr`
|
|
64
|
+
## `@orpc/experimental-react-swr`
|
|
64
65
|
|
|
65
66
|
[SWR](https://swr.vercel.app/) integration for oRPC, providing a simple way to fetch data using oRPC endpoints with SWR's caching and revalidation features.
|
|
66
67
|
|
package/dist/index.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { PartialDeep, MaybeOptionalOptions, InferAsyncIterableYield
|
|
1
|
+
import { PartialDeep, MaybeOptionalOptions, InferAsyncIterableYield } from '@orpc/shared';
|
|
2
2
|
import { ClientContext, Client, NestedClient } from '@orpc/client';
|
|
3
3
|
import { SWRSubscriptionOptions } from 'swr/subscription';
|
|
4
4
|
|
|
@@ -61,6 +61,11 @@ type CreateSubscriberOptions<TClientContext extends ClientContext> = CreateFetch
|
|
|
61
61
|
type Subscriber<TInput, TOutput, TError> = (key: Key<TInput>, options: SWRSubscriptionOptions<TOutput, TError>) => (() => void);
|
|
62
62
|
|
|
63
63
|
interface GeneralUtils<TInput> {
|
|
64
|
+
/**
|
|
65
|
+
* Generate a matcher function that returns `true` if the key matches the specified conditions.
|
|
66
|
+
*
|
|
67
|
+
* @see {@link https://orpc.unnoq.com/docs/integrations/react-swr#manual-revalidation React SWR Manual Revalidation Docs}
|
|
68
|
+
*/
|
|
64
69
|
matcher<TStrategy extends MatcherStrategy>(...rest: MaybeOptionalOptions<CreateMatcherOptions<TStrategy, TInput>>): Matcher;
|
|
65
70
|
}
|
|
66
71
|
declare function createGeneralUtils<TInput>(path: readonly string[]): GeneralUtils<TInput>;
|
|
@@ -69,17 +74,41 @@ interface ProcedureUtilsOptions {
|
|
|
69
74
|
path: readonly string[];
|
|
70
75
|
}
|
|
71
76
|
interface ProcedureUtils<TClientContext extends ClientContext, TInput, TOutput, TError> {
|
|
77
|
+
/**
|
|
78
|
+
* Calling corresponding procedure client
|
|
79
|
+
*
|
|
80
|
+
* @see {@link https://orpc.unnoq.com/docs/integrations/react-swr#calling-clients React SWR Calling Procedure Client Docs}
|
|
81
|
+
*/
|
|
72
82
|
call: Client<TClientContext, TInput, TOutput, TError>;
|
|
83
|
+
/**
|
|
84
|
+
* Generate a **full matching** key for SWR operations.
|
|
85
|
+
*
|
|
86
|
+
* @see {@link https://orpc.unnoq.com/docs/integrations/react-swr#data-fetching React SWR Key Docs}
|
|
87
|
+
*/
|
|
73
88
|
key(...rest: MaybeOptionalOptions<CreateKeyOptions<TInput>>): Key<TInput>;
|
|
89
|
+
/**
|
|
90
|
+
* Generate a fetcher function for use with useSWR, useSWRInfinite, and other SWR hooks.
|
|
91
|
+
*
|
|
92
|
+
* @see {@link https://orpc.unnoq.com/docs/integrations/react-swr#data-fetching React SWR Data Fetching Docs}
|
|
93
|
+
*/
|
|
74
94
|
fetcher(...rest: MaybeOptionalOptions<CreateFetcherOptions<TClientContext>>): Fetcher<TInput, TOutput>;
|
|
75
95
|
/**
|
|
76
|
-
*
|
|
96
|
+
* Generate a subscriber function that subscribes to an [Event Iterator](https://orpc.unnoq.com/docs/event-iterator) for use with useSWRSubscription, etc.
|
|
97
|
+
*
|
|
98
|
+
* @see {@link https://orpc.unnoq.com/docs/integrations/react-swr#subscriptions React SWR Subscriptions Docs}
|
|
99
|
+
*/
|
|
100
|
+
subscriber(...rest: MaybeOptionalOptions<CreateSubscriberOptions<TClientContext>>): Subscriber<TInput, InferAsyncIterableYield<TOutput>[], TError>;
|
|
101
|
+
/**
|
|
102
|
+
* Generate a live subscriber that subscribes to the latest events from an [Event Iterator](https://orpc.unnoq.com/docs/event-iterator) for use with useSWRSubscription, etc.
|
|
103
|
+
*
|
|
104
|
+
* @see {@link https://orpc.unnoq.com/docs/integrations/react-swr#subscriptions React SWR Subscriptions Docs}
|
|
77
105
|
*/
|
|
78
|
-
|
|
106
|
+
liveSubscriber(...rest: MaybeOptionalOptions<CreateFetcherOptions<TClientContext>>): Subscriber<TInput, InferAsyncIterableYield<TOutput>, TError>;
|
|
79
107
|
/**
|
|
80
|
-
*
|
|
108
|
+
* Generate a mutator function for use with useSWRMutation, etc.
|
|
109
|
+
*
|
|
110
|
+
* @see {@link https://orpc.unnoq.com/docs/integrations/react-swr#mutations React SWR Mutations Docs}
|
|
81
111
|
*/
|
|
82
|
-
liveSubscriber(...rest: MaybeOptionalOptions<CreateFetcherOptions<TClientContext>>): Subscriber<TInput, InferAsyncIterableYield<TOutput>, ThrowableError>;
|
|
83
112
|
mutator(...rest: MaybeOptionalOptions<CreateFetcherOptions<TClientContext>>): Mutator<TInput, TOutput>;
|
|
84
113
|
}
|
|
85
114
|
declare function createProcedureUtils<TClientContext extends ClientContext, TInput, TOutput, TError>(client: Client<TClientContext, TInput, TOutput, TError>, options: ProcedureUtilsOptions): ProcedureUtils<TClientContext, TInput, TOutput, TError>;
|
|
@@ -90,6 +119,12 @@ type RouterUtils<T extends NestedClient<any>> = T extends Client<infer UClientCo
|
|
|
90
119
|
interface CreateRouterUtilsOptions {
|
|
91
120
|
path?: readonly string[];
|
|
92
121
|
}
|
|
122
|
+
/**
|
|
123
|
+
* Create a swr router utils from a client.
|
|
124
|
+
*
|
|
125
|
+
* @info Both client-side and server-side clients are supported.
|
|
126
|
+
* @see {@link https://orpc.unnoq.com/docs/integrations/react-swr React SWR Integration}
|
|
127
|
+
*/
|
|
93
128
|
declare function createRouterUtils<T extends NestedClient<any>>(client: T, options?: CreateRouterUtilsOptions): RouterUtils<T>;
|
|
94
129
|
|
|
95
130
|
declare function isSubsetOf(subsetKey: unknown, fullKey: unknown): boolean;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { PartialDeep, MaybeOptionalOptions, InferAsyncIterableYield
|
|
1
|
+
import { PartialDeep, MaybeOptionalOptions, InferAsyncIterableYield } from '@orpc/shared';
|
|
2
2
|
import { ClientContext, Client, NestedClient } from '@orpc/client';
|
|
3
3
|
import { SWRSubscriptionOptions } from 'swr/subscription';
|
|
4
4
|
|
|
@@ -61,6 +61,11 @@ type CreateSubscriberOptions<TClientContext extends ClientContext> = CreateFetch
|
|
|
61
61
|
type Subscriber<TInput, TOutput, TError> = (key: Key<TInput>, options: SWRSubscriptionOptions<TOutput, TError>) => (() => void);
|
|
62
62
|
|
|
63
63
|
interface GeneralUtils<TInput> {
|
|
64
|
+
/**
|
|
65
|
+
* Generate a matcher function that returns `true` if the key matches the specified conditions.
|
|
66
|
+
*
|
|
67
|
+
* @see {@link https://orpc.unnoq.com/docs/integrations/react-swr#manual-revalidation React SWR Manual Revalidation Docs}
|
|
68
|
+
*/
|
|
64
69
|
matcher<TStrategy extends MatcherStrategy>(...rest: MaybeOptionalOptions<CreateMatcherOptions<TStrategy, TInput>>): Matcher;
|
|
65
70
|
}
|
|
66
71
|
declare function createGeneralUtils<TInput>(path: readonly string[]): GeneralUtils<TInput>;
|
|
@@ -69,17 +74,41 @@ interface ProcedureUtilsOptions {
|
|
|
69
74
|
path: readonly string[];
|
|
70
75
|
}
|
|
71
76
|
interface ProcedureUtils<TClientContext extends ClientContext, TInput, TOutput, TError> {
|
|
77
|
+
/**
|
|
78
|
+
* Calling corresponding procedure client
|
|
79
|
+
*
|
|
80
|
+
* @see {@link https://orpc.unnoq.com/docs/integrations/react-swr#calling-clients React SWR Calling Procedure Client Docs}
|
|
81
|
+
*/
|
|
72
82
|
call: Client<TClientContext, TInput, TOutput, TError>;
|
|
83
|
+
/**
|
|
84
|
+
* Generate a **full matching** key for SWR operations.
|
|
85
|
+
*
|
|
86
|
+
* @see {@link https://orpc.unnoq.com/docs/integrations/react-swr#data-fetching React SWR Key Docs}
|
|
87
|
+
*/
|
|
73
88
|
key(...rest: MaybeOptionalOptions<CreateKeyOptions<TInput>>): Key<TInput>;
|
|
89
|
+
/**
|
|
90
|
+
* Generate a fetcher function for use with useSWR, useSWRInfinite, and other SWR hooks.
|
|
91
|
+
*
|
|
92
|
+
* @see {@link https://orpc.unnoq.com/docs/integrations/react-swr#data-fetching React SWR Data Fetching Docs}
|
|
93
|
+
*/
|
|
74
94
|
fetcher(...rest: MaybeOptionalOptions<CreateFetcherOptions<TClientContext>>): Fetcher<TInput, TOutput>;
|
|
75
95
|
/**
|
|
76
|
-
*
|
|
96
|
+
* Generate a subscriber function that subscribes to an [Event Iterator](https://orpc.unnoq.com/docs/event-iterator) for use with useSWRSubscription, etc.
|
|
97
|
+
*
|
|
98
|
+
* @see {@link https://orpc.unnoq.com/docs/integrations/react-swr#subscriptions React SWR Subscriptions Docs}
|
|
99
|
+
*/
|
|
100
|
+
subscriber(...rest: MaybeOptionalOptions<CreateSubscriberOptions<TClientContext>>): Subscriber<TInput, InferAsyncIterableYield<TOutput>[], TError>;
|
|
101
|
+
/**
|
|
102
|
+
* Generate a live subscriber that subscribes to the latest events from an [Event Iterator](https://orpc.unnoq.com/docs/event-iterator) for use with useSWRSubscription, etc.
|
|
103
|
+
*
|
|
104
|
+
* @see {@link https://orpc.unnoq.com/docs/integrations/react-swr#subscriptions React SWR Subscriptions Docs}
|
|
77
105
|
*/
|
|
78
|
-
|
|
106
|
+
liveSubscriber(...rest: MaybeOptionalOptions<CreateFetcherOptions<TClientContext>>): Subscriber<TInput, InferAsyncIterableYield<TOutput>, TError>;
|
|
79
107
|
/**
|
|
80
|
-
*
|
|
108
|
+
* Generate a mutator function for use with useSWRMutation, etc.
|
|
109
|
+
*
|
|
110
|
+
* @see {@link https://orpc.unnoq.com/docs/integrations/react-swr#mutations React SWR Mutations Docs}
|
|
81
111
|
*/
|
|
82
|
-
liveSubscriber(...rest: MaybeOptionalOptions<CreateFetcherOptions<TClientContext>>): Subscriber<TInput, InferAsyncIterableYield<TOutput>, ThrowableError>;
|
|
83
112
|
mutator(...rest: MaybeOptionalOptions<CreateFetcherOptions<TClientContext>>): Mutator<TInput, TOutput>;
|
|
84
113
|
}
|
|
85
114
|
declare function createProcedureUtils<TClientContext extends ClientContext, TInput, TOutput, TError>(client: Client<TClientContext, TInput, TOutput, TError>, options: ProcedureUtilsOptions): ProcedureUtils<TClientContext, TInput, TOutput, TError>;
|
|
@@ -90,6 +119,12 @@ type RouterUtils<T extends NestedClient<any>> = T extends Client<infer UClientCo
|
|
|
90
119
|
interface CreateRouterUtilsOptions {
|
|
91
120
|
path?: readonly string[];
|
|
92
121
|
}
|
|
122
|
+
/**
|
|
123
|
+
* Create a swr router utils from a client.
|
|
124
|
+
*
|
|
125
|
+
* @info Both client-side and server-side clients are supported.
|
|
126
|
+
* @see {@link https://orpc.unnoq.com/docs/integrations/react-swr React SWR Integration}
|
|
127
|
+
*/
|
|
93
128
|
declare function createRouterUtils<T extends NestedClient<any>>(client: T, options?: CreateRouterUtilsOptions): RouterUtils<T>;
|
|
94
129
|
|
|
95
130
|
declare function isSubsetOf(subsetKey: unknown, fullKey: unknown): boolean;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@orpc/experimental-react-swr",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "
|
|
4
|
+
"version": "1.8.3",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"homepage": "https://orpc.unnoq.com",
|
|
7
7
|
"repository": {
|
|
@@ -25,10 +25,10 @@
|
|
|
25
25
|
],
|
|
26
26
|
"peerDependencies": {
|
|
27
27
|
"swr": ">=2.3.6",
|
|
28
|
-
"@orpc/client": "1.8.
|
|
28
|
+
"@orpc/client": "1.8.3"
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@orpc/shared": "1.8.
|
|
31
|
+
"@orpc/shared": "1.8.3"
|
|
32
32
|
},
|
|
33
33
|
"devDependencies": {
|
|
34
34
|
"swr": "^2.3.6"
|