@orpc/swr 2.0.0-beta.23 → 2.0.0-beta.25
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 +4 -1
- package/dist/index.d.mts +26 -11
- package/dist/index.d.ts +26 -11
- package/dist/index.mjs +25 -22
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -44,6 +44,7 @@ You can read the documentation [here](https://orpc.dev).
|
|
|
44
44
|
|
|
45
45
|
- [@orpc/publisher](https://www.npmjs.com/package/@orpc/publisher): Pub/Sub with memory, Redis, and Upstash adapters.
|
|
46
46
|
- [@orpc/ratelimit](https://www.npmjs.com/package/@orpc/ratelimit): Rate limiting with memory, Redis, and Upstash adapters.
|
|
47
|
+
- [@orpc/hibernation](https://www.npmjs.com/package/@orpc/hibernation): Leverage Hibernation APIs like [Cloudflare's Hibernation WebSocket](https://developers.cloudflare.com/durable-objects/best-practices/websockets/#durable-objects-hibernation-websocket-api).
|
|
47
48
|
- [@orpc/json-schema](https://www.npmjs.com/package/@orpc/json-schema): Smart coercion for OpenAPI requests.
|
|
48
49
|
|
|
49
50
|
**Framework & ecosystem integrations**
|
|
@@ -114,6 +115,7 @@ Like what we build over at [middleapi](https://github.com/middleapi)? You can he
|
|
|
114
115
|
</tr>
|
|
115
116
|
<tr>
|
|
116
117
|
<td align="center"><a href="https://github.com/itigoore01?ref=orpc" target="_blank" rel="noopener" title="shota"><img src="https://avatars.githubusercontent.com/u/11831107?u=c976a6dc7e055eb026304c46c99100ed22b0c8e0&v=4" width="139" alt="shota"/><br />shota</a></td>
|
|
118
|
+
<td align="center"><a href="https://github.com/ellis-driscoll?ref=orpc" target="_blank" rel="noopener" title="Ellis Driscoll"><img src="https://avatars.githubusercontent.com/u/70685966?u=c5f95bc33b5991d9744abe00052542e4a2ed3cb9&v=4" width="139" alt="Ellis Driscoll"/><br />Ellis Driscoll</a></td>
|
|
117
119
|
</tr>
|
|
118
120
|
</table>
|
|
119
121
|
|
|
@@ -139,8 +141,9 @@ Like what we build over at [middleapi](https://github.com/middleapi)? You can he
|
|
|
139
141
|
<td align="center"><a href="https://github.com/mr-kelly?ref=orpc" target="_blank" rel="noopener" title="Kelly Peilin Chan"><img src="https://avatars.githubusercontent.com/u/520852?u=6b0f7105f694e7b5cacf410a3f04c7044b469dc8&v=4" width="119" alt="Kelly Peilin Chan"/><br />Kelly Peilin Chan</a></td>
|
|
140
142
|
</tr>
|
|
141
143
|
<tr>
|
|
144
|
+
<td align="center"><a href="https://github.com/guyariely?ref=orpc" target="_blank" rel="noopener" title="Guy Ariely"><img src="https://avatars.githubusercontent.com/u/42813496?u=edb6b7f563bf28e160a290832e7da57c0506f8ca&v=4" width="119" alt="Guy Ariely"/><br />Guy Ariely</a></td>
|
|
142
145
|
<td align="center"><a href="https://github.com/piscis?ref=orpc" target="_blank" rel="noopener" title="Alex"><img src="https://avatars.githubusercontent.com/u/326163?u=b245f368bd940cf51d08c0b6bf55f8257f359437&v=4" width="119" alt="Alex"/><br />Alex</a></td>
|
|
143
|
-
<td align="center"><a href="https://github.com/finom?ref=orpc" target="_blank" rel="noopener" title="Andrey Gubanov"><img src="https://avatars.githubusercontent.com/u/1082083?u=
|
|
146
|
+
<td align="center"><a href="https://github.com/finom?ref=orpc" target="_blank" rel="noopener" title="Andrey Gubanov"><img src="https://avatars.githubusercontent.com/u/1082083?u=c5f2daf7ebece498e85c83367bb37b4e10e2649d&v=4" width="119" alt="Andrey Gubanov"/><br />Andrey Gubanov</a></td>
|
|
144
147
|
</tr>
|
|
145
148
|
</table>
|
|
146
149
|
|
package/dist/index.d.mts
CHANGED
|
@@ -16,14 +16,26 @@ type OperationKey<TInput> = [path: string[], options: Omit<OperationKeyOptions<T
|
|
|
16
16
|
/**
|
|
17
17
|
* Generate a **full matching** key for SWR operations.
|
|
18
18
|
*
|
|
19
|
-
* @see {@link https://orpc.dev/docs/integrations/swr#data-fetching SWR
|
|
19
|
+
* @see {@link https://orpc.dev/docs/integrations/swr#data-fetching | SWR Integration - Data Fetching}
|
|
20
20
|
*/
|
|
21
21
|
declare function generateOperationKey<TInput>(path: string[], options?: OperationKeyOptions<TInput>): OperationKey<TInput>;
|
|
22
22
|
|
|
23
23
|
type InferSubscriberOutput<TOutput> = TOutput extends AsyncIterable<infer U> ? U[] : never;
|
|
24
24
|
type InferLiveSubscriberOutput<TOutput> = TOutput extends AsyncIterable<infer U> ? U : never;
|
|
25
25
|
type OperationType = 'fetcher' | 'mutator' | 'subscriber' | 'liveSubscriber';
|
|
26
|
+
/**
|
|
27
|
+
* The symbol under which SWR utils attach operation details
|
|
28
|
+
* (key and operation type) to the client context.
|
|
29
|
+
*
|
|
30
|
+
* @see {@link https://orpc.dev/docs/integrations/swr#operation-context | SWR Integration - Operation Context}
|
|
31
|
+
*/
|
|
26
32
|
declare const OPERATION_CONTEXT_SYMBOL: unique symbol;
|
|
33
|
+
/**
|
|
34
|
+
* A client context automatically populated by SWR utils,
|
|
35
|
+
* exposing the operation key and type of the calling operation.
|
|
36
|
+
*
|
|
37
|
+
* @see {@link https://orpc.dev/docs/integrations/swr#operation-context | SWR Integration - Operation Context}
|
|
38
|
+
*/
|
|
27
39
|
interface OperationContext {
|
|
28
40
|
[OPERATION_CONTEXT_SYMBOL]?: {
|
|
29
41
|
key: unknown;
|
|
@@ -82,7 +94,7 @@ declare class SharedUtils<TInput> {
|
|
|
82
94
|
/**
|
|
83
95
|
* Generate a matcher function that returns `true` if the key matches the specified conditions.
|
|
84
96
|
*
|
|
85
|
-
* @see {@link https://orpc.dev/docs/integrations/swr#manual-revalidation SWR Manual Revalidation
|
|
97
|
+
* @see {@link https://orpc.dev/docs/integrations/swr#manual-revalidation | SWR Integration - Manual Revalidation}
|
|
86
98
|
*/
|
|
87
99
|
matcher<TStrategy extends MatcherStrategy>(...rest: MaybeOptionalOptions<MatcherOptions<TStrategy, TInput>>): Matcher;
|
|
88
100
|
}
|
|
@@ -93,38 +105,38 @@ declare class ProcedureUtils<TClientContext extends ClientContext, TInput, TOutp
|
|
|
93
105
|
/**
|
|
94
106
|
* Calling corresponding procedure client
|
|
95
107
|
*
|
|
96
|
-
* @see {@link https://orpc.dev/docs/integrations/swr#calling-clients SWR
|
|
108
|
+
* @see {@link https://orpc.dev/docs/integrations/swr#calling-clients | SWR Integration - Calling Clients}
|
|
97
109
|
*/
|
|
98
110
|
call: Client<TClientContext, TInput, TOutput, TError>;
|
|
99
111
|
constructor(path: string[], client: Client<TClientContext, TInput, TOutput, TError>, options?: ProcedureUtilsOptions);
|
|
100
112
|
/**
|
|
101
113
|
* Generate a **full matching** key for SWR operations.
|
|
102
114
|
*
|
|
103
|
-
* @see {@link https://orpc.dev/docs/integrations/swr#data-fetching SWR
|
|
115
|
+
* @see {@link https://orpc.dev/docs/integrations/swr#data-fetching | SWR Integration - Data Fetching}
|
|
104
116
|
*/
|
|
105
117
|
key(...rest: MaybeOptionalOptions<KeyOptions<TInput>>): OperationKey<TInput>;
|
|
106
118
|
/**
|
|
107
119
|
* Generate a fetcher function for use with useSWR, useSWRInfinite, and other SWR hooks.
|
|
108
120
|
*
|
|
109
|
-
* @see {@link https://orpc.dev/docs/integrations/swr#data-fetching SWR Data Fetching
|
|
121
|
+
* @see {@link https://orpc.dev/docs/integrations/swr#data-fetching | SWR Integration - Data Fetching}
|
|
110
122
|
*/
|
|
111
123
|
fetcher(...rest: MaybeOptionalOptions<FetcherOptions<TClientContext>>): Fetcher<TInput, TOutput>;
|
|
112
124
|
/**
|
|
113
125
|
* Generate a subscriber function that subscribes to an [AsyncIteratorObject](https://orpc.dev/docs/async-iterator-object) for use with useSWRSubscription, etc.
|
|
114
126
|
*
|
|
115
|
-
* @see {@link https://orpc.dev/docs/integrations/swr#subscriptions SWR Subscriptions
|
|
127
|
+
* @see {@link https://orpc.dev/docs/integrations/swr#subscriptions | SWR Integration - Subscriptions}
|
|
116
128
|
*/
|
|
117
129
|
subscriber(...rest: MaybeOptionalOptions<SubscriberOptions<TClientContext>>): Subscriber<TInput, InferSubscriberOutput<TOutput>, TError>;
|
|
118
130
|
/**
|
|
119
131
|
* Generate a live subscriber that subscribes to the latest events from an [AsyncIteratorObject](https://orpc.dev/docs/async-iterator-object) for use with useSWRSubscription, etc.
|
|
120
132
|
*
|
|
121
|
-
* @see {@link https://orpc.dev/docs/integrations/swr#subscriptions SWR Subscriptions
|
|
133
|
+
* @see {@link https://orpc.dev/docs/integrations/swr#subscriptions | SWR Integration - Subscriptions}
|
|
122
134
|
*/
|
|
123
135
|
liveSubscriber(...rest: MaybeOptionalOptions<FetcherOptions<TClientContext>>): Subscriber<TInput, InferLiveSubscriberOutput<TOutput>, TError>;
|
|
124
136
|
/**
|
|
125
137
|
* Generate a mutator function for use with useSWRMutation, etc.
|
|
126
138
|
*
|
|
127
|
-
* @see {@link https://orpc.dev/docs/integrations/swr#mutations SWR Mutations
|
|
139
|
+
* @see {@link https://orpc.dev/docs/integrations/swr#mutations | SWR Integration - Mutations}
|
|
128
140
|
*/
|
|
129
141
|
mutator(...rest: MaybeOptionalOptions<MutatorOptions<TClientContext>>): Mutator<TInput, TOutput>;
|
|
130
142
|
}
|
|
@@ -141,10 +153,13 @@ interface RouterUtilsOptions extends OperationKeyPrefixOptions {
|
|
|
141
153
|
path?: string[] | undefined;
|
|
142
154
|
}
|
|
143
155
|
/**
|
|
144
|
-
*
|
|
156
|
+
* Creates SWR utils from a client, exposing fetcher/mutator/subscriber
|
|
157
|
+
* helpers for every procedure in the router.
|
|
158
|
+
*
|
|
159
|
+
* @remarks
|
|
160
|
+
* **Note**: Both client-side and server-side clients are supported.
|
|
145
161
|
*
|
|
146
|
-
* @
|
|
147
|
-
* @see {@link https://orpc.dev/docs/integrations/swr SWR Integration}
|
|
162
|
+
* @see {@link https://orpc.dev/docs/integrations/swr | SWR Integration}
|
|
148
163
|
*/
|
|
149
164
|
declare function createRouterUtils<T extends AnyNestedClient>(client: T, options?: RouterUtilsOptions): RouterUtils<T>;
|
|
150
165
|
|
package/dist/index.d.ts
CHANGED
|
@@ -16,14 +16,26 @@ type OperationKey<TInput> = [path: string[], options: Omit<OperationKeyOptions<T
|
|
|
16
16
|
/**
|
|
17
17
|
* Generate a **full matching** key for SWR operations.
|
|
18
18
|
*
|
|
19
|
-
* @see {@link https://orpc.dev/docs/integrations/swr#data-fetching SWR
|
|
19
|
+
* @see {@link https://orpc.dev/docs/integrations/swr#data-fetching | SWR Integration - Data Fetching}
|
|
20
20
|
*/
|
|
21
21
|
declare function generateOperationKey<TInput>(path: string[], options?: OperationKeyOptions<TInput>): OperationKey<TInput>;
|
|
22
22
|
|
|
23
23
|
type InferSubscriberOutput<TOutput> = TOutput extends AsyncIterable<infer U> ? U[] : never;
|
|
24
24
|
type InferLiveSubscriberOutput<TOutput> = TOutput extends AsyncIterable<infer U> ? U : never;
|
|
25
25
|
type OperationType = 'fetcher' | 'mutator' | 'subscriber' | 'liveSubscriber';
|
|
26
|
+
/**
|
|
27
|
+
* The symbol under which SWR utils attach operation details
|
|
28
|
+
* (key and operation type) to the client context.
|
|
29
|
+
*
|
|
30
|
+
* @see {@link https://orpc.dev/docs/integrations/swr#operation-context | SWR Integration - Operation Context}
|
|
31
|
+
*/
|
|
26
32
|
declare const OPERATION_CONTEXT_SYMBOL: unique symbol;
|
|
33
|
+
/**
|
|
34
|
+
* A client context automatically populated by SWR utils,
|
|
35
|
+
* exposing the operation key and type of the calling operation.
|
|
36
|
+
*
|
|
37
|
+
* @see {@link https://orpc.dev/docs/integrations/swr#operation-context | SWR Integration - Operation Context}
|
|
38
|
+
*/
|
|
27
39
|
interface OperationContext {
|
|
28
40
|
[OPERATION_CONTEXT_SYMBOL]?: {
|
|
29
41
|
key: unknown;
|
|
@@ -82,7 +94,7 @@ declare class SharedUtils<TInput> {
|
|
|
82
94
|
/**
|
|
83
95
|
* Generate a matcher function that returns `true` if the key matches the specified conditions.
|
|
84
96
|
*
|
|
85
|
-
* @see {@link https://orpc.dev/docs/integrations/swr#manual-revalidation SWR Manual Revalidation
|
|
97
|
+
* @see {@link https://orpc.dev/docs/integrations/swr#manual-revalidation | SWR Integration - Manual Revalidation}
|
|
86
98
|
*/
|
|
87
99
|
matcher<TStrategy extends MatcherStrategy>(...rest: MaybeOptionalOptions<MatcherOptions<TStrategy, TInput>>): Matcher;
|
|
88
100
|
}
|
|
@@ -93,38 +105,38 @@ declare class ProcedureUtils<TClientContext extends ClientContext, TInput, TOutp
|
|
|
93
105
|
/**
|
|
94
106
|
* Calling corresponding procedure client
|
|
95
107
|
*
|
|
96
|
-
* @see {@link https://orpc.dev/docs/integrations/swr#calling-clients SWR
|
|
108
|
+
* @see {@link https://orpc.dev/docs/integrations/swr#calling-clients | SWR Integration - Calling Clients}
|
|
97
109
|
*/
|
|
98
110
|
call: Client<TClientContext, TInput, TOutput, TError>;
|
|
99
111
|
constructor(path: string[], client: Client<TClientContext, TInput, TOutput, TError>, options?: ProcedureUtilsOptions);
|
|
100
112
|
/**
|
|
101
113
|
* Generate a **full matching** key for SWR operations.
|
|
102
114
|
*
|
|
103
|
-
* @see {@link https://orpc.dev/docs/integrations/swr#data-fetching SWR
|
|
115
|
+
* @see {@link https://orpc.dev/docs/integrations/swr#data-fetching | SWR Integration - Data Fetching}
|
|
104
116
|
*/
|
|
105
117
|
key(...rest: MaybeOptionalOptions<KeyOptions<TInput>>): OperationKey<TInput>;
|
|
106
118
|
/**
|
|
107
119
|
* Generate a fetcher function for use with useSWR, useSWRInfinite, and other SWR hooks.
|
|
108
120
|
*
|
|
109
|
-
* @see {@link https://orpc.dev/docs/integrations/swr#data-fetching SWR Data Fetching
|
|
121
|
+
* @see {@link https://orpc.dev/docs/integrations/swr#data-fetching | SWR Integration - Data Fetching}
|
|
110
122
|
*/
|
|
111
123
|
fetcher(...rest: MaybeOptionalOptions<FetcherOptions<TClientContext>>): Fetcher<TInput, TOutput>;
|
|
112
124
|
/**
|
|
113
125
|
* Generate a subscriber function that subscribes to an [AsyncIteratorObject](https://orpc.dev/docs/async-iterator-object) for use with useSWRSubscription, etc.
|
|
114
126
|
*
|
|
115
|
-
* @see {@link https://orpc.dev/docs/integrations/swr#subscriptions SWR Subscriptions
|
|
127
|
+
* @see {@link https://orpc.dev/docs/integrations/swr#subscriptions | SWR Integration - Subscriptions}
|
|
116
128
|
*/
|
|
117
129
|
subscriber(...rest: MaybeOptionalOptions<SubscriberOptions<TClientContext>>): Subscriber<TInput, InferSubscriberOutput<TOutput>, TError>;
|
|
118
130
|
/**
|
|
119
131
|
* Generate a live subscriber that subscribes to the latest events from an [AsyncIteratorObject](https://orpc.dev/docs/async-iterator-object) for use with useSWRSubscription, etc.
|
|
120
132
|
*
|
|
121
|
-
* @see {@link https://orpc.dev/docs/integrations/swr#subscriptions SWR Subscriptions
|
|
133
|
+
* @see {@link https://orpc.dev/docs/integrations/swr#subscriptions | SWR Integration - Subscriptions}
|
|
122
134
|
*/
|
|
123
135
|
liveSubscriber(...rest: MaybeOptionalOptions<FetcherOptions<TClientContext>>): Subscriber<TInput, InferLiveSubscriberOutput<TOutput>, TError>;
|
|
124
136
|
/**
|
|
125
137
|
* Generate a mutator function for use with useSWRMutation, etc.
|
|
126
138
|
*
|
|
127
|
-
* @see {@link https://orpc.dev/docs/integrations/swr#mutations SWR Mutations
|
|
139
|
+
* @see {@link https://orpc.dev/docs/integrations/swr#mutations | SWR Integration - Mutations}
|
|
128
140
|
*/
|
|
129
141
|
mutator(...rest: MaybeOptionalOptions<MutatorOptions<TClientContext>>): Mutator<TInput, TOutput>;
|
|
130
142
|
}
|
|
@@ -141,10 +153,13 @@ interface RouterUtilsOptions extends OperationKeyPrefixOptions {
|
|
|
141
153
|
path?: string[] | undefined;
|
|
142
154
|
}
|
|
143
155
|
/**
|
|
144
|
-
*
|
|
156
|
+
* Creates SWR utils from a client, exposing fetcher/mutator/subscriber
|
|
157
|
+
* helpers for every procedure in the router.
|
|
158
|
+
*
|
|
159
|
+
* @remarks
|
|
160
|
+
* **Note**: Both client-side and server-side clients are supported.
|
|
145
161
|
*
|
|
146
|
-
* @
|
|
147
|
-
* @see {@link https://orpc.dev/docs/integrations/swr SWR Integration}
|
|
162
|
+
* @see {@link https://orpc.dev/docs/integrations/swr | SWR Integration}
|
|
148
163
|
*/
|
|
149
164
|
declare function createRouterUtils<T extends AnyNestedClient>(client: T, options?: RouterUtilsOptions): RouterUtils<T>;
|
|
150
165
|
|
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { isPlainObject, resolveMaybeOptionalOptions, isAsyncIteratorObject, toArray, bindMethods,
|
|
1
|
+
import { isPlainObject, resolveMaybeOptionalOptions, isAsyncIteratorObject, toArray, bindMethods, isTypescriptObject } from '@orpc/shared';
|
|
2
2
|
import { RECURSIVE_CLIENT_UNWRAP_KEYS } from '@orpc/client';
|
|
3
3
|
|
|
4
4
|
function generateOperationKey(path, options = {}) {
|
|
@@ -23,7 +23,7 @@ class SharedUtils {
|
|
|
23
23
|
/**
|
|
24
24
|
* Generate a matcher function that returns `true` if the key matches the specified conditions.
|
|
25
25
|
*
|
|
26
|
-
* @see {@link https://orpc.dev/docs/integrations/swr#manual-revalidation SWR Manual Revalidation
|
|
26
|
+
* @see {@link https://orpc.dev/docs/integrations/swr#manual-revalidation | SWR Integration - Manual Revalidation}
|
|
27
27
|
*/
|
|
28
28
|
matcher(...rest) {
|
|
29
29
|
const { input, strategy = "partial" } = resolveMaybeOptionalOptions(rest);
|
|
@@ -46,7 +46,7 @@ class ProcedureUtils extends SharedUtils {
|
|
|
46
46
|
/**
|
|
47
47
|
* Calling corresponding procedure client
|
|
48
48
|
*
|
|
49
|
-
* @see {@link https://orpc.dev/docs/integrations/swr#calling-clients SWR
|
|
49
|
+
* @see {@link https://orpc.dev/docs/integrations/swr#calling-clients | SWR Integration - Calling Clients}
|
|
50
50
|
*/
|
|
51
51
|
call;
|
|
52
52
|
constructor(path, client, options = {}) {
|
|
@@ -56,7 +56,7 @@ class ProcedureUtils extends SharedUtils {
|
|
|
56
56
|
/**
|
|
57
57
|
* Generate a **full matching** key for SWR operations.
|
|
58
58
|
*
|
|
59
|
-
* @see {@link https://orpc.dev/docs/integrations/swr#data-fetching SWR
|
|
59
|
+
* @see {@link https://orpc.dev/docs/integrations/swr#data-fetching | SWR Integration - Data Fetching}
|
|
60
60
|
*/
|
|
61
61
|
key(...rest) {
|
|
62
62
|
const options = resolveMaybeOptionalOptions(rest);
|
|
@@ -65,7 +65,7 @@ class ProcedureUtils extends SharedUtils {
|
|
|
65
65
|
/**
|
|
66
66
|
* Generate a fetcher function for use with useSWR, useSWRInfinite, and other SWR hooks.
|
|
67
67
|
*
|
|
68
|
-
* @see {@link https://orpc.dev/docs/integrations/swr#data-fetching SWR Data Fetching
|
|
68
|
+
* @see {@link https://orpc.dev/docs/integrations/swr#data-fetching | SWR Integration - Data Fetching}
|
|
69
69
|
*/
|
|
70
70
|
fetcher(...rest) {
|
|
71
71
|
const options = resolveMaybeOptionalOptions(rest);
|
|
@@ -82,7 +82,7 @@ class ProcedureUtils extends SharedUtils {
|
|
|
82
82
|
/**
|
|
83
83
|
* Generate a subscriber function that subscribes to an [AsyncIteratorObject](https://orpc.dev/docs/async-iterator-object) for use with useSWRSubscription, etc.
|
|
84
84
|
*
|
|
85
|
-
* @see {@link https://orpc.dev/docs/integrations/swr#subscriptions SWR Subscriptions
|
|
85
|
+
* @see {@link https://orpc.dev/docs/integrations/swr#subscriptions | SWR Integration - Subscriptions}
|
|
86
86
|
*/
|
|
87
87
|
subscriber(...rest) {
|
|
88
88
|
const { maxChunks, refetchMode = "reset", ...options } = resolveMaybeOptionalOptions(rest);
|
|
@@ -145,7 +145,7 @@ class ProcedureUtils extends SharedUtils {
|
|
|
145
145
|
/**
|
|
146
146
|
* Generate a live subscriber that subscribes to the latest events from an [AsyncIteratorObject](https://orpc.dev/docs/async-iterator-object) for use with useSWRSubscription, etc.
|
|
147
147
|
*
|
|
148
|
-
* @see {@link https://orpc.dev/docs/integrations/swr#subscriptions SWR Subscriptions
|
|
148
|
+
* @see {@link https://orpc.dev/docs/integrations/swr#subscriptions | SWR Integration - Subscriptions}
|
|
149
149
|
*/
|
|
150
150
|
liveSubscriber(...rest) {
|
|
151
151
|
const options = resolveMaybeOptionalOptions(rest);
|
|
@@ -181,7 +181,7 @@ class ProcedureUtils extends SharedUtils {
|
|
|
181
181
|
/**
|
|
182
182
|
* Generate a mutator function for use with useSWRMutation, etc.
|
|
183
183
|
*
|
|
184
|
-
* @see {@link https://orpc.dev/docs/integrations/swr#mutations SWR Mutations
|
|
184
|
+
* @see {@link https://orpc.dev/docs/integrations/swr#mutations | SWR Integration - Mutations}
|
|
185
185
|
*/
|
|
186
186
|
mutator(...rest) {
|
|
187
187
|
const options = resolveMaybeOptionalOptions(rest);
|
|
@@ -196,26 +196,29 @@ class ProcedureUtils extends SharedUtils {
|
|
|
196
196
|
|
|
197
197
|
function createRouterUtils(client, options = {}) {
|
|
198
198
|
const path = toArray(options.path);
|
|
199
|
-
const utils = typeof client === "function" ? bindMethods(new ProcedureUtils(path, client, { prefix: options.prefix })) : bindMethods(new SharedUtils(path, { prefix: options.prefix }));
|
|
199
|
+
const utils = typeof client === "function" ? bindMethods(new ProcedureUtils(path, client, { prefix: options.prefix }), { unbound: ["call"] }) : bindMethods(new SharedUtils(path, { prefix: options.prefix }));
|
|
200
|
+
const cache = /* @__PURE__ */ new Map();
|
|
200
201
|
const recursive = new Proxy(utils, {
|
|
201
202
|
get(target, prop) {
|
|
202
|
-
const value =
|
|
203
|
-
const nextClient = client
|
|
203
|
+
const value = Reflect.get(target, prop);
|
|
204
|
+
const nextClient = Reflect.get(client, prop);
|
|
204
205
|
if (typeof prop !== "string" || RECURSIVE_CLIENT_UNWRAP_KEYS.has(prop) || !isTypescriptObject(nextClient)) {
|
|
205
206
|
return value;
|
|
206
207
|
}
|
|
207
|
-
|
|
208
|
-
if (
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
208
|
+
let result = cache.get(prop);
|
|
209
|
+
if (result === void 0) {
|
|
210
|
+
const nextUtils = createRouterUtils(nextClient, { ...options, path: [...path, prop] });
|
|
211
|
+
result = typeof value !== "function" ? nextUtils : new Proxy(value, {
|
|
212
|
+
get(target2, prop2) {
|
|
213
|
+
if (typeof prop2 !== "string" || RECURSIVE_CLIENT_UNWRAP_KEYS.has(prop2)) {
|
|
214
|
+
return Reflect.get(target2, prop2);
|
|
215
|
+
}
|
|
216
|
+
return Reflect.get(nextUtils, prop2);
|
|
215
217
|
}
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
}
|
|
218
|
+
});
|
|
219
|
+
cache.set(prop, result);
|
|
220
|
+
}
|
|
221
|
+
return result;
|
|
219
222
|
}
|
|
220
223
|
});
|
|
221
224
|
return recursive;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@orpc/swr",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "2.0.0-beta.
|
|
4
|
+
"version": "2.0.0-beta.25",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"homepage": "https://orpc.dev",
|
|
7
7
|
"repository": {
|
|
@@ -30,8 +30,8 @@
|
|
|
30
30
|
"swr": ">=2.4.2"
|
|
31
31
|
},
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"@orpc/client": "2.0.0-beta.
|
|
34
|
-
"@orpc/shared": "2.0.0-beta.
|
|
33
|
+
"@orpc/client": "2.0.0-beta.25",
|
|
34
|
+
"@orpc/shared": "2.0.0-beta.25"
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|
|
37
37
|
"swr": "^2.4.2",
|