@orpc/swr 2.0.0-beta.49 → 2.0.0-beta.51

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 CHANGED
@@ -78,13 +78,14 @@ Read the full documentation at [orpc.dev](https://orpc.dev), starting with the [
78
78
 
79
79
  **Built-in features**
80
80
 
81
- | Package | Purpose | Docs |
82
- | -------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------- |
83
- | [@orpc/publisher](https://www.npmjs.com/package/@orpc/publisher) | Pub/Sub with memory, Redis, and Upstash adapters. | [Publisher](https://orpc.dev/docs/helpers/publisher) |
84
- | [@orpc/ratelimit](https://www.npmjs.com/package/@orpc/ratelimit) | Rate limiting with memory, Redis, and Upstash adapters. | [Rate Limit](https://orpc.dev/docs/helpers/ratelimit) |
85
- | [@orpc/experimental-lock](https://www.npmjs.com/package/@orpc/experimental-lock) | Locking with memory, Redis, and Upstash adapters. | [Lock](https://orpc.dev/docs/helpers/lock) |
86
- | [@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). | [Hibernation](https://orpc.dev/docs/integrations/hibernation) |
87
- | [@orpc/json-schema](https://www.npmjs.com/package/@orpc/json-schema) | Smart coercion for OpenAPI requests. | [Smart Coercion](https://orpc.dev/docs/plugins/smart-coercion) |
81
+ | Package | Purpose | Docs |
82
+ | ---------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------- |
83
+ | [@orpc/publisher](https://www.npmjs.com/package/@orpc/publisher) | Pub/Sub with memory, Redis, and Upstash adapters. | [Publisher](https://orpc.dev/docs/helpers/publisher) |
84
+ | [@orpc/ratelimit](https://www.npmjs.com/package/@orpc/ratelimit) | Rate limiting with memory, Redis, and Upstash adapters. | [Rate Limit](https://orpc.dev/docs/helpers/ratelimit) |
85
+ | [@orpc/experimental-lock](https://www.npmjs.com/package/@orpc/experimental-lock) | Locking with memory, Redis, and Upstash adapters. | [Lock](https://orpc.dev/docs/helpers/lock) |
86
+ | [@orpc/experimental-openapi-inference](https://www.npmjs.com/package/@orpc/experimental-openapi-inference) | Generate OpenAPI specs from TypeScript types, no output schemas required. | [Type Inference](https://orpc.dev/docs/openapi/specification#type-inference) |
87
+ | [@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). | [Hibernation](https://orpc.dev/docs/integrations/hibernation) |
88
+ | [@orpc/json-schema](https://www.npmjs.com/package/@orpc/json-schema) | Smart coercion for OpenAPI requests. | [Smart Coercion](https://orpc.dev/docs/plugins/smart-coercion) |
88
89
 
89
90
  **Framework & ecosystem integrations**
90
91
 
@@ -192,9 +193,10 @@ Like what we build over at [middleapi](https://github.com/middleapi)? You can he
192
193
  <td align="center"><a href="https://kellychan.im/?ref=middleapi&amp;utm_source=middleapi&amp;utm_medium=sponsor" target="_blank" rel="noopener sponsored" title="Kelly Peilin Chan"><img src="https://avatars.githubusercontent.com/u/520852?u=6b0f7105f694e7b5cacf410a3f04c7044b469dc8&amp;v=4" width="139" alt="Kelly Peilin Chan"/><br />Kelly Peilin Chan</a></td>
193
194
  <td align="center"><a href="https://guyariely.com/?ref=middleapi&amp;utm_source=middleapi&amp;utm_medium=sponsor" target="_blank" rel="noopener sponsored" title="Guy Ariely"><img src="https://avatars.githubusercontent.com/u/42813496?u=edb6b7f563bf28e160a290832e7da57c0506f8ca&amp;v=4" width="139" alt="Guy Ariely"/><br />Guy Ariely</a></td>
194
195
  <td align="center"><a href="https://paulsenon.com/?ref=middleapi&amp;utm_source=middleapi&amp;utm_medium=sponsor" target="_blank" rel="noopener sponsored" title="PaulSenon"><img src="https://avatars.githubusercontent.com/u/19531087?u=6385741eb91d200b8c513ec6045482e301767ca6&amp;v=4" width="139" alt="PaulSenon"/><br />PaulSenon</a></td>
195
- <td align="center"><a href="https://piscis.dev/?ref=middleapi&amp;utm_source=middleapi&amp;utm_medium=sponsor" target="_blank" rel="noopener sponsored" title="Alex"><img src="https://avatars.githubusercontent.com/u/326163?u=b245f368bd940cf51d08c0b6bf55f8257f359437&amp;v=4" width="139" alt="Alex"/><br />Alex</a></td>
196
+ <td align="center"><a href="https://usagerail.com/?ref=middleapi&amp;utm_source=middleapi&amp;utm_medium=sponsor" target="_blank" rel="noopener sponsored" title="UsageRail"><img src="https://avatars.githubusercontent.com/u/347653714?v=4" width="139" alt="UsageRail"/><br />UsageRail</a></td>
196
197
  </tr>
197
198
  <tr>
199
+ <td align="center"><a href="https://piscis.dev/?ref=middleapi&amp;utm_source=middleapi&amp;utm_medium=sponsor" target="_blank" rel="noopener sponsored" title="Alex"><img src="https://avatars.githubusercontent.com/u/326163?u=b245f368bd940cf51d08c0b6bf55f8257f359437&amp;v=4" width="139" alt="Alex"/><br />Alex</a></td>
198
200
  <td align="center"><a href="https://opensource.gubanov.eu/?ref=middleapi&amp;utm_source=middleapi&amp;utm_medium=sponsor" target="_blank" rel="noopener sponsored" title="Andrey Gubanov"><img src="https://avatars.githubusercontent.com/u/1082083?u=c5f2daf7ebece498e85c83367bb37b4e10e2649d&amp;v=4" width="139" alt="Andrey Gubanov"/><br />Andrey Gubanov</a></td>
199
201
  </tr>
200
202
  </table>
package/dist/index.d.ts CHANGED
@@ -1,9 +1,7 @@
1
- export type { OperationKey, OperationKeyOptions, OperationKeyPrefixOptions } from './key.ts';
2
- export { ProcedureUtils } from './procedure-utils.ts';
3
- export type { ProcedureUtilsOptions } from './procedure-utils.ts';
4
- export * from './router-utils.ts';
5
- export { createRouterUtils as createSWRUtils } from './router-utils.ts';
6
- export { SharedUtils } from './shared-utils.ts';
7
- export * from './types.ts';
8
- export { OPERATION_CONTEXT_SYMBOL as SWR_OPERATION_CONTEXT_SYMBOL, type OperationContext as SWROperationContext, } from './types.ts';
9
- export type { Public } from '@orpc/shared';
1
+ import { OperationKey, OperationKeyOptions, OperationKeyPrefixOptions } from "./key.js";
2
+ import { ProcedureUtils, ProcedureUtilsOptions } from "./procedure-utils.js";
3
+ import { RouterUtils, RouterUtilsInternal, RouterUtilsOptions, createRouterUtils } from "./router-utils.js";
4
+ import { SharedUtils } from "./shared-utils.js";
5
+ import { Fetcher, FetcherOptions, InferLiveSubscriberOutput, InferSubscriberOutput, KeyOptions, Matcher, MatcherOptions, MatcherStrategy, Mutator, MutatorOptions, OPERATION_CONTEXT_SYMBOL, OperationContext, OperationType, Subscriber, SubscriberOptions } from "./types.js";
6
+ import { Public } from "@orpc/shared";
7
+ export { Fetcher, FetcherOptions, InferLiveSubscriberOutput, InferSubscriberOutput, KeyOptions, Matcher, MatcherOptions, MatcherStrategy, Mutator, MutatorOptions, OPERATION_CONTEXT_SYMBOL, OperationContext, type OperationKey, type OperationKeyOptions, type OperationKeyPrefixOptions, OperationType, ProcedureUtils, type ProcedureUtilsOptions, type Public, RouterUtils, RouterUtilsInternal, RouterUtilsOptions, type OperationContext as SWROperationContext, OPERATION_CONTEXT_SYMBOL as SWR_OPERATION_CONTEXT_SYMBOL, SharedUtils, Subscriber, SubscriberOptions, createRouterUtils, createRouterUtils as createSWRUtils };
package/dist/index.js CHANGED
@@ -1,6 +1,4 @@
1
- export { ProcedureUtils } from './procedure-utils.js';
2
- export * from './router-utils.js';
3
- export { createRouterUtils as createSWRUtils } from './router-utils.js';
4
- export { SharedUtils } from './shared-utils.js';
5
- export * from './types.js';
6
- export { OPERATION_CONTEXT_SYMBOL as SWR_OPERATION_CONTEXT_SYMBOL, } from './types.js';
1
+ export { ProcedureUtils } from "./procedure-utils.js";
2
+ export { createRouterUtils, createRouterUtils as createSWRUtils } from "./router-utils.js";
3
+ export { SharedUtils } from "./shared-utils.js";
4
+ export { OPERATION_CONTEXT_SYMBOL, OPERATION_CONTEXT_SYMBOL as SWR_OPERATION_CONTEXT_SYMBOL } from "./types.js";
package/dist/key.d.ts CHANGED
@@ -1,18 +1,12 @@
1
- import type { PartialDeep } from '@orpc/shared';
1
+ import { PartialDeep } from "@orpc/shared";
2
2
  export interface OperationKeyPrefixOptions {
3
- /**
4
- * Prepended as the first element of the key when present.
5
- * Use this to avoid key conflicts when multiple router utils share the same client.
6
- */
7
- prefix?: string | undefined;
3
+ /**
4
+ * Prepended as the first element of the key when present.
5
+ * Use this to avoid key conflicts when multiple router utils share the same client.
6
+ */
7
+ prefix?: string | undefined;
8
8
  }
9
9
  export type OperationKeyOptions<TInput> = OperationKeyPrefixOptions & {
10
- input?: PartialDeep<TInput> | undefined;
10
+ input?: PartialDeep<TInput> | undefined;
11
11
  };
12
- export type OperationKey<TInput> = [path: string[], options: Omit<OperationKeyOptions<TInput>, 'prefix'>] | [prefix: string, path: string[], options: Omit<OperationKeyOptions<TInput>, 'prefix'>];
13
- /**
14
- * Generate a **full matching** key for SWR operations.
15
- *
16
- * @see {@link https://orpc.dev/docs/integrations/swr#data-fetching | SWR Integration - Data Fetching}
17
- */
18
- export declare function generateOperationKey<TInput>(path: string[], options?: OperationKeyOptions<TInput>): OperationKey<TInput>;
12
+ export type OperationKey<TInput> = [path: string[], options: Omit<OperationKeyOptions<TInput>, "prefix">] | [prefix: string, path: string[], options: Omit<OperationKeyOptions<TInput>, "prefix">];
package/dist/key.js CHANGED
@@ -1,12 +1,14 @@
1
+ // src/key.ts
1
2
  /**
2
- * Generate a **full matching** key for SWR operations.
3
- *
4
- * @see {@link https://orpc.dev/docs/integrations/swr#data-fetching | SWR Integration - Data Fetching}
5
- */
6
- export function generateOperationKey(path, options = {}) {
7
- return [
8
- ...(options.prefix !== undefined ? [options.prefix] : []),
9
- path,
10
- options.input !== undefined ? { input: options.input } : {},
11
- ];
3
+ * Generate a **full matching** key for SWR operations.
4
+ *
5
+ * @see {@link https://orpc.dev/docs/integrations/swr#data-fetching | SWR Integration - Data Fetching}
6
+ */
7
+ function generateOperationKey(path, options = {}) {
8
+ return [
9
+ ...options.prefix !== void 0 ? [options.prefix] : [],
10
+ path,
11
+ options.input !== void 0 ? { input: options.input } : {}
12
+ ];
12
13
  }
14
+ export { generateOperationKey };
@@ -1,46 +1,45 @@
1
- import type { Client, ClientContext } from '@orpc/client';
2
- import type { MaybeOptionalOptions } from '@orpc/shared';
3
- import type { OperationKey, OperationKeyPrefixOptions } from './key.ts';
4
- import { SharedUtils } from './shared-utils.ts';
5
- import type { Fetcher, FetcherOptions, InferLiveSubscriberOutput, InferSubscriberOutput, KeyOptions, Mutator, MutatorOptions, Subscriber, SubscriberOptions } from './types.ts';
6
- export interface ProcedureUtilsOptions extends OperationKeyPrefixOptions {
7
- }
1
+ import { OperationKey, OperationKeyPrefixOptions } from "./key.js";
2
+ import { SharedUtils } from "./shared-utils.js";
3
+ import { Fetcher, FetcherOptions, InferLiveSubscriberOutput, InferSubscriberOutput, KeyOptions, Mutator, MutatorOptions, Subscriber, SubscriberOptions } from "./types.js";
4
+ import { MaybeOptionalOptions } from "@orpc/shared";
5
+ import { Client, ClientContext } from "@orpc/client";
6
+ export interface ProcedureUtilsOptions extends OperationKeyPrefixOptions {}
8
7
  export declare class ProcedureUtils<TClientContext extends ClientContext, TInput, TOutput, TError> extends SharedUtils<TInput> {
9
- /**
10
- * Calling corresponding procedure client
11
- *
12
- * @see {@link https://orpc.dev/docs/integrations/swr#calling-clients | SWR Integration - Calling Clients}
13
- */
14
- call: Client<TClientContext, TInput, TOutput, TError>;
15
- constructor(path: string[], client: Client<TClientContext, TInput, TOutput, TError>, options?: ProcedureUtilsOptions);
16
- /**
17
- * Generate a **full matching** key for SWR operations.
18
- *
19
- * @see {@link https://orpc.dev/docs/integrations/swr#data-fetching | SWR Integration - Data Fetching}
20
- */
21
- key(...rest: MaybeOptionalOptions<KeyOptions<TInput>>): OperationKey<TInput>;
22
- /**
23
- * Generate a fetcher function for use with useSWR, useSWRInfinite, and other SWR hooks.
24
- *
25
- * @see {@link https://orpc.dev/docs/integrations/swr#data-fetching | SWR Integration - Data Fetching}
26
- */
27
- fetcher(...rest: MaybeOptionalOptions<FetcherOptions<TClientContext>>): Fetcher<TInput, TOutput>;
28
- /**
29
- * Generate a subscriber function that subscribes to an [AsyncIteratorObject](https://orpc.dev/docs/async-iterator-object) for use with useSWRSubscription, etc.
30
- *
31
- * @see {@link https://orpc.dev/docs/integrations/swr#subscriptions | SWR Integration - Subscriptions}
32
- */
33
- subscriber(...rest: MaybeOptionalOptions<SubscriberOptions<TClientContext>>): Subscriber<TInput, InferSubscriberOutput<TOutput>, TError>;
34
- /**
35
- * 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.
36
- *
37
- * @see {@link https://orpc.dev/docs/integrations/swr#subscriptions | SWR Integration - Subscriptions}
38
- */
39
- liveSubscriber(...rest: MaybeOptionalOptions<FetcherOptions<TClientContext>>): Subscriber<TInput, InferLiveSubscriberOutput<TOutput>, TError>;
40
- /**
41
- * Generate a mutator function for use with useSWRMutation, etc.
42
- *
43
- * @see {@link https://orpc.dev/docs/integrations/swr#mutations | SWR Integration - Mutations}
44
- */
45
- mutator(...rest: MaybeOptionalOptions<MutatorOptions<TClientContext>>): Mutator<TInput, TOutput>;
46
- }
8
+ /**
9
+ * Calling corresponding procedure client
10
+ *
11
+ * @see {@link https://orpc.dev/docs/integrations/swr#calling-clients | SWR Integration - Calling Clients}
12
+ */
13
+ call: Client<TClientContext, TInput, TOutput, TError>;
14
+ constructor(path: string[], client: Client<TClientContext, TInput, TOutput, TError>, options?: ProcedureUtilsOptions);
15
+ /**
16
+ * Generate a **full matching** key for SWR operations.
17
+ *
18
+ * @see {@link https://orpc.dev/docs/integrations/swr#data-fetching | SWR Integration - Data Fetching}
19
+ */
20
+ key(...rest: MaybeOptionalOptions<KeyOptions<TInput>>): OperationKey<TInput>;
21
+ /**
22
+ * Generate a fetcher function for use with useSWR, useSWRInfinite, and other SWR hooks.
23
+ *
24
+ * @see {@link https://orpc.dev/docs/integrations/swr#data-fetching | SWR Integration - Data Fetching}
25
+ */
26
+ fetcher(...rest: MaybeOptionalOptions<FetcherOptions<TClientContext>>): Fetcher<TInput, TOutput>;
27
+ /**
28
+ * Generate a subscriber function that subscribes to an [AsyncIteratorObject](https://orpc.dev/docs/async-iterator-object) for use with useSWRSubscription, etc.
29
+ *
30
+ * @see {@link https://orpc.dev/docs/integrations/swr#subscriptions | SWR Integration - Subscriptions}
31
+ */
32
+ subscriber(...rest: MaybeOptionalOptions<SubscriberOptions<TClientContext>>): Subscriber<TInput, InferSubscriberOutput<TOutput>, TError>;
33
+ /**
34
+ * 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.
35
+ *
36
+ * @see {@link https://orpc.dev/docs/integrations/swr#subscriptions | SWR Integration - Subscriptions}
37
+ */
38
+ liveSubscriber(...rest: MaybeOptionalOptions<FetcherOptions<TClientContext>>): Subscriber<TInput, InferLiveSubscriberOutput<TOutput>, TError>;
39
+ /**
40
+ * Generate a mutator function for use with useSWRMutation, etc.
41
+ *
42
+ * @see {@link https://orpc.dev/docs/integrations/swr#mutations | SWR Integration - Mutations}
43
+ */
44
+ mutator(...rest: MaybeOptionalOptions<MutatorOptions<TClientContext>>): Mutator<TInput, TOutput>;
45
+ }
@@ -1,174 +1,165 @@
1
- import { isAsyncIteratorObject, resolveMaybeOptionalOptions } from '@orpc/shared';
2
- import { generateOperationKey } from './key.js';
3
- import { SharedUtils } from './shared-utils.js';
4
- import { OPERATION_CONTEXT_SYMBOL } from './types.js';
5
- export class ProcedureUtils extends SharedUtils {
6
- /**
7
- * Calling corresponding procedure client
8
- *
9
- * @see {@link https://orpc.dev/docs/integrations/swr#calling-clients | SWR Integration - Calling Clients}
10
- */
11
- call;
12
- constructor(path, client, options = {}) {
13
- super(path, options);
14
- this.call = client;
15
- }
16
- /**
17
- * Generate a **full matching** key for SWR operations.
18
- *
19
- * @see {@link https://orpc.dev/docs/integrations/swr#data-fetching | SWR Integration - Data Fetching}
20
- */
21
- key(...rest) {
22
- const options = resolveMaybeOptionalOptions(rest);
23
- return generateOperationKey(this.path, {
24
- ...options,
25
- prefix: this.options.prefix,
26
- });
27
- }
28
- /**
29
- * Generate a fetcher function for use with useSWR, useSWRInfinite, and other SWR hooks.
30
- *
31
- * @see {@link https://orpc.dev/docs/integrations/swr#data-fetching | SWR Integration - Data Fetching}
32
- */
33
- fetcher(...rest) {
34
- const options = resolveMaybeOptionalOptions(rest);
35
- return async (key) => {
36
- /**
37
- * Input can be omitted from the key when it is undefined,
38
- * so we can safely cast it to TInput with an undefined fallback.
39
- */
40
- const { input } = key[key.length - 1];
41
- return this.call(input, {
42
- context: {
43
- [OPERATION_CONTEXT_SYMBOL]: { key, type: 'fetcher' },
44
- ...options.context,
45
- },
46
- });
47
- };
48
- }
49
- /**
50
- * Generate a subscriber function that subscribes to an [AsyncIteratorObject](https://orpc.dev/docs/async-iterator-object) for use with useSWRSubscription, etc.
51
- *
52
- * @see {@link https://orpc.dev/docs/integrations/swr#subscriptions | SWR Integration - Subscriptions}
53
- */
54
- subscriber(...rest) {
55
- const { maxChunks, refetchMode = 'reset', ...options } = resolveMaybeOptionalOptions(rest);
56
- return (key, { next }) => {
57
- const controller = new AbortController();
58
- void (async () => {
59
- try {
60
- /**
61
- * Input can be omitted from the key when it is undefined,
62
- * so we can safely cast it to TInput with an undefined fallback.
63
- */
64
- const { input } = key[key.length - 1];
65
- const iterator = await this.call(input, {
66
- context: {
67
- [OPERATION_CONTEXT_SYMBOL]: { key, type: 'subscriber' },
68
- ...options.context,
69
- },
70
- signal: controller.signal,
71
- });
72
- if (!isAsyncIteratorObject(iterator)) {
73
- throw new TypeError('.subscriber requires an AsyncIteratorObject output');
74
- }
75
- if (controller.signal.aborted) {
76
- await iterator.return?.();
77
- return;
78
- }
79
- if (refetchMode === 'reset') {
80
- next(undefined, []);
81
- }
82
- for await (const event of iterator) {
83
- if (controller.signal.aborted) {
84
- break;
85
- }
86
- next(undefined, (old) => {
87
- const newData = Array.isArray(old) ? [...old, event] : [event];
88
- if (typeof maxChunks === 'number' && newData.length > maxChunks) {
89
- return newData.slice(newData.length - maxChunks);
90
- }
91
- return newData;
92
- });
93
- }
94
- }
95
- catch (error) {
96
- /**
97
- * Only report the error if the controller is not aborted.
98
- */
99
- if (!controller.signal.aborted) {
100
- next(error);
101
- }
102
- }
103
- })();
104
- return () => {
105
- controller.abort();
106
- };
107
- };
108
- }
109
- /**
110
- * 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.
111
- *
112
- * @see {@link https://orpc.dev/docs/integrations/swr#subscriptions | SWR Integration - Subscriptions}
113
- */
114
- liveSubscriber(...rest) {
115
- const options = resolveMaybeOptionalOptions(rest);
116
- return (key, { next }) => {
117
- const controller = new AbortController();
118
- void (async () => {
119
- try {
120
- /**
121
- * Input can be omitted from the key when it is undefined,
122
- * so we can safely cast it to TInput with an undefined fallback.
123
- */
124
- const { input } = key[key.length - 1];
125
- const iterator = await this.call(input, {
126
- context: {
127
- [OPERATION_CONTEXT_SYMBOL]: { key, type: 'liveSubscriber' },
128
- ...options.context,
129
- },
130
- signal: controller.signal,
131
- });
132
- if (!isAsyncIteratorObject(iterator)) {
133
- throw new TypeError('.liveSubscriber requires an AsyncIteratorObject output');
134
- }
135
- if (controller.signal.aborted) {
136
- await iterator.return?.();
137
- return;
138
- }
139
- for await (const event of iterator) {
140
- if (controller.signal.aborted) {
141
- break;
142
- }
143
- next(undefined, event);
144
- }
145
- }
146
- catch (error) {
147
- /**
148
- * Only report the error if the controller is not aborted.
149
- */
150
- if (!controller.signal.aborted) {
151
- next(error);
152
- }
153
- }
154
- })();
155
- return () => {
156
- controller.abort();
157
- };
158
- };
159
- }
160
- /**
161
- * Generate a mutator function for use with useSWRMutation, etc.
162
- *
163
- * @see {@link https://orpc.dev/docs/integrations/swr#mutations | SWR Integration - Mutations}
164
- */
165
- mutator(...rest) {
166
- const options = resolveMaybeOptionalOptions(rest);
167
- return (key, { arg }) => this.call(arg, {
168
- context: {
169
- [OPERATION_CONTEXT_SYMBOL]: { key, type: 'mutator' },
170
- ...options.context,
171
- },
172
- });
173
- }
174
- }
1
+ import { generateOperationKey } from "./key.js";
2
+ import { SharedUtils } from "./shared-utils.js";
3
+ import { OPERATION_CONTEXT_SYMBOL } from "./types.js";
4
+ import { isAsyncIteratorObject, resolveMaybeOptionalOptions, takeLast } from "@orpc/shared";
5
+ // src/procedure-utils.ts
6
+ var ProcedureUtils = class extends SharedUtils {
7
+ /**
8
+ * Calling corresponding procedure client
9
+ *
10
+ * @see {@link https://orpc.dev/docs/integrations/swr#calling-clients | SWR Integration - Calling Clients}
11
+ */
12
+ call;
13
+ constructor(path, client, options = {}) {
14
+ super(path, options);
15
+ this.call = client;
16
+ }
17
+ /**
18
+ * Generate a **full matching** key for SWR operations.
19
+ *
20
+ * @see {@link https://orpc.dev/docs/integrations/swr#data-fetching | SWR Integration - Data Fetching}
21
+ */
22
+ key(...rest) {
23
+ const options = resolveMaybeOptionalOptions(rest);
24
+ return generateOperationKey(this.path, {
25
+ ...options,
26
+ prefix: this.options.prefix
27
+ });
28
+ }
29
+ /**
30
+ * Generate a fetcher function for use with useSWR, useSWRInfinite, and other SWR hooks.
31
+ *
32
+ * @see {@link https://orpc.dev/docs/integrations/swr#data-fetching | SWR Integration - Data Fetching}
33
+ */
34
+ fetcher(...rest) {
35
+ const options = resolveMaybeOptionalOptions(rest);
36
+ return async (key) => {
37
+ /**
38
+ * Input can be omitted from the key when it is undefined,
39
+ * so we can safely cast it to TInput with an undefined fallback.
40
+ */
41
+ const { input } = key[key.length - 1];
42
+ return this.call(input, { context: {
43
+ [OPERATION_CONTEXT_SYMBOL]: {
44
+ key,
45
+ type: "fetcher"
46
+ },
47
+ ...options.context
48
+ } });
49
+ };
50
+ }
51
+ /**
52
+ * Generate a subscriber function that subscribes to an [AsyncIteratorObject](https://orpc.dev/docs/async-iterator-object) for use with useSWRSubscription, etc.
53
+ *
54
+ * @see {@link https://orpc.dev/docs/integrations/swr#subscriptions | SWR Integration - Subscriptions}
55
+ */
56
+ subscriber(...rest) {
57
+ const { maxChunks, refetchMode = "reset", ...options } = resolveMaybeOptionalOptions(rest);
58
+ return (key, { next }) => {
59
+ const controller = new AbortController();
60
+ (async () => {
61
+ try {
62
+ /**
63
+ * Input can be omitted from the key when it is undefined,
64
+ * so we can safely cast it to TInput with an undefined fallback.
65
+ */
66
+ const { input } = key[key.length - 1];
67
+ const iterator = await this.call(input, {
68
+ context: {
69
+ [OPERATION_CONTEXT_SYMBOL]: {
70
+ key,
71
+ type: "subscriber"
72
+ },
73
+ ...options.context
74
+ },
75
+ signal: controller.signal
76
+ });
77
+ if (!isAsyncIteratorObject(iterator)) throw new TypeError(".subscriber requires an AsyncIteratorObject output");
78
+ if (controller.signal.aborted) {
79
+ await iterator.return?.();
80
+ return;
81
+ }
82
+ if (refetchMode === "reset") next(void 0, []);
83
+ for await (const event of iterator) {
84
+ if (controller.signal.aborted) break;
85
+ next(void 0, (old) => {
86
+ const newData = Array.isArray(old) ? [...old, event] : [event];
87
+ return typeof maxChunks === "number" ? takeLast(newData, maxChunks) : newData;
88
+ });
89
+ }
90
+ } catch (error) {
91
+ /**
92
+ * Only report the error if the controller is not aborted.
93
+ */
94
+ if (!controller.signal.aborted) next(error);
95
+ }
96
+ })();
97
+ return () => {
98
+ controller.abort();
99
+ };
100
+ };
101
+ }
102
+ /**
103
+ * 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.
104
+ *
105
+ * @see {@link https://orpc.dev/docs/integrations/swr#subscriptions | SWR Integration - Subscriptions}
106
+ */
107
+ liveSubscriber(...rest) {
108
+ const options = resolveMaybeOptionalOptions(rest);
109
+ return (key, { next }) => {
110
+ const controller = new AbortController();
111
+ (async () => {
112
+ try {
113
+ /**
114
+ * Input can be omitted from the key when it is undefined,
115
+ * so we can safely cast it to TInput with an undefined fallback.
116
+ */
117
+ const { input } = key[key.length - 1];
118
+ const iterator = await this.call(input, {
119
+ context: {
120
+ [OPERATION_CONTEXT_SYMBOL]: {
121
+ key,
122
+ type: "liveSubscriber"
123
+ },
124
+ ...options.context
125
+ },
126
+ signal: controller.signal
127
+ });
128
+ if (!isAsyncIteratorObject(iterator)) throw new TypeError(".liveSubscriber requires an AsyncIteratorObject output");
129
+ if (controller.signal.aborted) {
130
+ await iterator.return?.();
131
+ return;
132
+ }
133
+ for await (const event of iterator) {
134
+ if (controller.signal.aborted) break;
135
+ next(void 0, event);
136
+ }
137
+ } catch (error) {
138
+ /**
139
+ * Only report the error if the controller is not aborted.
140
+ */
141
+ if (!controller.signal.aborted) next(error);
142
+ }
143
+ })();
144
+ return () => {
145
+ controller.abort();
146
+ };
147
+ };
148
+ }
149
+ /**
150
+ * Generate a mutator function for use with useSWRMutation, etc.
151
+ *
152
+ * @see {@link https://orpc.dev/docs/integrations/swr#mutations | SWR Integration - Mutations}
153
+ */
154
+ mutator(...rest) {
155
+ const options = resolveMaybeOptionalOptions(rest);
156
+ return (key, { arg }) => this.call(arg, { context: {
157
+ [OPERATION_CONTEXT_SYMBOL]: {
158
+ key,
159
+ type: "mutator"
160
+ },
161
+ ...options.context
162
+ } });
163
+ }
164
+ };
165
+ export { ProcedureUtils };
@@ -1,18 +1,17 @@
1
- import type { AnyNestedClient, Client } from '@orpc/client';
2
- import type { Public } from '@orpc/shared';
3
- import type { OperationKeyPrefixOptions } from './key.ts';
4
- import { ProcedureUtils } from './procedure-utils.ts';
5
- import { SharedUtils } from './shared-utils.ts';
6
- export type RouterUtils<T extends AnyNestedClient> = T extends Client<infer UClientContext, infer UInput, infer UOutput, infer UError> ? Public<ProcedureUtils<UClientContext, UInput, UOutput, UError>> : {
7
- [K in keyof T]: T[K] extends AnyNestedClient ? RouterUtils<T[K]> : never;
8
- } & Public<SharedUtils<unknown>>;
1
+ import { OperationKeyPrefixOptions } from "./key.js";
2
+ import { ProcedureUtils } from "./procedure-utils.js";
3
+ import { SharedUtils } from "./shared-utils.js";
4
+ import { Public } from "@orpc/shared";
5
+ import { AnyNestedClient, Client } from "@orpc/client";
6
+ export type RouterUtils<T extends AnyNestedClient> = RouterUtilsInternal<T>;
7
+ export type RouterUtilsInternal<T> = T extends Client<infer UClientContext, infer UInput, infer UOutput, infer UError> ? Public<ProcedureUtils<UClientContext, UInput, UOutput, UError>> : { [K in keyof T]: RouterUtilsInternal<T[K] & {}>; } & Public<SharedUtils<unknown>>;
9
8
  export interface RouterUtilsOptions extends OperationKeyPrefixOptions {
10
- /**
11
- * Base path for all keys.
12
- *
13
- * @internal
14
- */
15
- path?: string[] | undefined;
9
+ /**
10
+ * Base path for all keys.
11
+ *
12
+ * @internal
13
+ */
14
+ path?: string[] | undefined;
16
15
  }
17
16
  /**
18
17
  * Creates SWR utils from a client, exposing fetcher/mutator/subscriber
@@ -23,4 +22,4 @@ export interface RouterUtilsOptions extends OperationKeyPrefixOptions {
23
22
  *
24
23
  * @see {@link https://orpc.dev/docs/integrations/swr | SWR Integration}
25
24
  */
26
- export declare function createRouterUtils<T extends AnyNestedClient>(client: T, options?: RouterUtilsOptions): RouterUtils<T>;
25
+ export declare function createRouterUtils<T extends AnyNestedClient>(client: T, options?: RouterUtilsOptions): RouterUtils<T>;
@@ -1,55 +1,39 @@
1
- import { RECURSIVE_CLIENT_UNWRAP_KEYS } from '@orpc/client';
2
- import { bindMethods, isNonPrimitive, toArray } from '@orpc/shared';
3
- import { ProcedureUtils } from './procedure-utils.js';
4
- import { SharedUtils } from './shared-utils.js';
1
+ import { ProcedureUtils } from "./procedure-utils.js";
2
+ import { SharedUtils } from "./shared-utils.js";
3
+ import { bindMethods, isNonPrimitive, toArray } from "@orpc/shared";
4
+ import { RECURSIVE_CLIENT_UNWRAP_KEYS } from "@orpc/client";
5
+ // src/router-utils.ts
5
6
  /**
6
- * Creates SWR utils from a client, exposing fetcher/mutator/subscriber
7
- * helpers for every procedure in the router.
8
- *
9
- * @remarks
10
- * **Note**: Both client-side and server-side clients are supported.
11
- *
12
- * @see {@link https://orpc.dev/docs/integrations/swr | SWR Integration}
13
- */
14
- export function createRouterUtils(client, options = {}) {
15
- const path = toArray(options.path);
16
- const utils = typeof client === 'function'
17
- ? bindMethods(new ProcedureUtils(path, client, { prefix: options.prefix }), {
18
- unbound: ['call'],
19
- })
20
- : bindMethods(new SharedUtils(path, { prefix: options.prefix }));
21
- const cache = new Map();
22
- const recursive = new Proxy(utils, {
23
- get(target, prop) {
24
- const value = Reflect.get(target, prop);
25
- if (RECURSIVE_CLIENT_UNWRAP_KEYS.has(prop)) {
26
- return value ?? Reflect.get(Object.prototype, prop);
27
- }
28
- const nextClient = Reflect.get(client, prop);
29
- if (typeof prop !== 'string' || !isNonPrimitive(nextClient)) {
30
- return value;
31
- }
32
- let result = cache.get(prop);
33
- if (result === undefined) {
34
- const nextUtils = createRouterUtils(nextClient, {
35
- ...options,
36
- path: [...path, prop],
37
- });
38
- result =
39
- typeof value !== 'function'
40
- ? nextUtils
41
- : new Proxy(value, {
42
- get(target, prop) {
43
- if (typeof prop !== 'string' || RECURSIVE_CLIENT_UNWRAP_KEYS.has(prop)) {
44
- return Reflect.get(target, prop);
45
- }
46
- return Reflect.get(nextUtils, prop);
47
- },
48
- });
49
- cache.set(prop, result);
50
- }
51
- return result;
52
- },
53
- });
54
- return recursive;
7
+ * Creates SWR utils from a client, exposing fetcher/mutator/subscriber
8
+ * helpers for every procedure in the router.
9
+ *
10
+ * @remarks
11
+ * **Note**: Both client-side and server-side clients are supported.
12
+ *
13
+ * @see {@link https://orpc.dev/docs/integrations/swr | SWR Integration}
14
+ */
15
+ function createRouterUtils(client, options = {}) {
16
+ const path = toArray(options.path);
17
+ const utils = typeof client === "function" ? bindMethods(new ProcedureUtils(path, client, { prefix: options.prefix }), { unbound: ["call"] }) : bindMethods(new SharedUtils(path, { prefix: options.prefix }));
18
+ const cache = /* @__PURE__ */ new Map();
19
+ return new Proxy(utils, { get(target, prop) {
20
+ const value = Reflect.get(target, prop);
21
+ if (RECURSIVE_CLIENT_UNWRAP_KEYS.has(prop)) return value ?? Reflect.get(Object.prototype, prop);
22
+ const nextClient = Reflect.get(client, prop);
23
+ if (typeof prop !== "string" || !isNonPrimitive(nextClient)) return value;
24
+ let result = cache.get(prop);
25
+ if (result === void 0) {
26
+ const nextUtils = createRouterUtils(nextClient, {
27
+ ...options,
28
+ path: [...path, prop]
29
+ });
30
+ result = typeof value !== "function" ? nextUtils : new Proxy(value, { get(target, prop) {
31
+ if (typeof prop !== "string" || RECURSIVE_CLIENT_UNWRAP_KEYS.has(prop)) return Reflect.get(target, prop);
32
+ return Reflect.get(nextUtils, prop);
33
+ } });
34
+ cache.set(prop, result);
35
+ }
36
+ return result;
37
+ } });
55
38
  }
39
+ export { createRouterUtils };
@@ -1,14 +1,14 @@
1
- import type { MaybeOptionalOptions } from '@orpc/shared';
2
- import type { OperationKeyPrefixOptions } from './key.ts';
3
- import type { Matcher, MatcherOptions, MatcherStrategy } from './types.ts';
1
+ import { OperationKeyPrefixOptions } from "./key.js";
2
+ import { Matcher, MatcherOptions, MatcherStrategy } from "./types.js";
3
+ import { MaybeOptionalOptions } from "@orpc/shared";
4
4
  export declare class SharedUtils<TInput> {
5
- protected readonly path: string[];
6
- protected readonly options: OperationKeyPrefixOptions;
7
- constructor(path: string[], options: OperationKeyPrefixOptions);
8
- /**
9
- * Generate a matcher function that returns `true` if the key matches the specified conditions.
10
- *
11
- * @see {@link https://orpc.dev/docs/integrations/swr#manual-revalidation | SWR Integration - Manual Revalidation}
12
- */
13
- matcher<TStrategy extends MatcherStrategy>(...rest: MaybeOptionalOptions<MatcherOptions<TStrategy, TInput>>): Matcher;
14
- }
5
+ protected readonly path: string[];
6
+ protected readonly options: OperationKeyPrefixOptions;
7
+ constructor(path: string[], options: OperationKeyPrefixOptions);
8
+ /**
9
+ * Generate a matcher function that returns `true` if the key matches the specified conditions.
10
+ *
11
+ * @see {@link https://orpc.dev/docs/integrations/swr#manual-revalidation | SWR Integration - Manual Revalidation}
12
+ */
13
+ matcher<TStrategy extends MatcherStrategy>(...rest: MaybeOptionalOptions<MatcherOptions<TStrategy, TInput>>): Matcher;
14
+ }
@@ -1,32 +1,30 @@
1
- import { resolveMaybeOptionalOptions } from '@orpc/shared';
2
- import { generateOperationKey } from './key.js';
3
- import { isSubsetOf } from './utils.js';
4
- export class SharedUtils {
5
- path;
6
- options;
7
- constructor(path, options) {
8
- this.path = path;
9
- this.options = options;
10
- }
11
- /**
12
- * Generate a matcher function that returns `true` if the key matches the specified conditions.
13
- *
14
- * @see {@link https://orpc.dev/docs/integrations/swr#manual-revalidation | SWR Integration - Manual Revalidation}
15
- */
16
- matcher(...rest) {
17
- const { input, strategy = 'partial' } = resolveMaybeOptionalOptions(rest);
18
- const expectedKey = generateOperationKey(this.path, {
19
- prefix: this.options.prefix,
20
- input: input,
21
- });
22
- return (key) => {
23
- if (!isSubsetOf(expectedKey, key)) {
24
- return false;
25
- }
26
- if (strategy === 'exact' && !isSubsetOf(key, expectedKey)) {
27
- return false;
28
- }
29
- return true;
30
- };
31
- }
32
- }
1
+ import { generateOperationKey } from "./key.js";
2
+ import { isSubsetOf } from "./utils.js";
3
+ import { resolveMaybeOptionalOptions } from "@orpc/shared";
4
+ // src/shared-utils.ts
5
+ var SharedUtils = class {
6
+ path;
7
+ options;
8
+ constructor(path, options) {
9
+ this.path = path;
10
+ this.options = options;
11
+ }
12
+ /**
13
+ * Generate a matcher function that returns `true` if the key matches the specified conditions.
14
+ *
15
+ * @see {@link https://orpc.dev/docs/integrations/swr#manual-revalidation | SWR Integration - Manual Revalidation}
16
+ */
17
+ matcher(...rest) {
18
+ const { input, strategy = "partial" } = resolveMaybeOptionalOptions(rest);
19
+ const expectedKey = generateOperationKey(this.path, {
20
+ prefix: this.options.prefix,
21
+ input
22
+ });
23
+ return (key) => {
24
+ if (!isSubsetOf(expectedKey, key)) return false;
25
+ if (strategy === "exact" && !isSubsetOf(key, expectedKey)) return false;
26
+ return true;
27
+ };
28
+ }
29
+ };
30
+ export { SharedUtils };
package/dist/types.d.ts CHANGED
@@ -1,10 +1,10 @@
1
- import type { ClientContext } from '@orpc/client';
2
- import type { PartialDeep } from '@orpc/shared';
3
- import type { SWRSubscriptionOptions } from 'swr/subscription';
4
- import type { OperationKey } from './key.ts';
1
+ import { OperationKey } from "./key.js";
2
+ import { PartialDeep } from "@orpc/shared";
3
+ import { ClientContext } from "@orpc/client";
4
+ import { SWRSubscriptionOptions } from "swr/subscription";
5
5
  export type InferSubscriberOutput<TOutput> = TOutput extends AsyncIterable<infer U> ? U[] : never;
6
6
  export type InferLiveSubscriberOutput<TOutput> = TOutput extends AsyncIterable<infer U> ? U : never;
7
- export type OperationType = 'fetcher' | 'mutator' | 'subscriber' | 'liveSubscriber';
7
+ export type OperationType = "fetcher" | "mutator" | "subscriber" | "liveSubscriber";
8
8
  /**
9
9
  * The symbol under which SWR utils attach operation details
10
10
  * (key and operation type) to the client context.
@@ -19,52 +19,52 @@ export declare const OPERATION_CONTEXT_SYMBOL: unique symbol;
19
19
  * @see {@link https://orpc.dev/docs/integrations/swr#operation-context | SWR Integration - Operation Context}
20
20
  */
21
21
  export interface OperationContext {
22
- [OPERATION_CONTEXT_SYMBOL]?: {
23
- key: unknown;
24
- type: OperationType;
25
- };
22
+ [OPERATION_CONTEXT_SYMBOL]?: {
23
+ key: unknown;
24
+ type: OperationType;
25
+ };
26
26
  }
27
27
  export type KeyOptions<TInput> = undefined extends TInput ? {
28
- input?: TInput;
28
+ input?: TInput;
29
29
  } : {
30
- input: TInput;
30
+ input: TInput;
31
31
  };
32
- export type MatcherStrategy = 'exact' | 'partial';
33
- export type MatcherOptions<TStrategy extends MatcherStrategy, TInput> = ('partial' extends TStrategy ? {
34
- input?: PartialDeep<TInput> | undefined;
32
+ export type MatcherStrategy = "exact" | "partial";
33
+ export type MatcherOptions<TStrategy extends MatcherStrategy, TInput> = ("partial" extends TStrategy ? {
34
+ input?: PartialDeep<TInput> | undefined;
35
35
  } : undefined extends TInput ? {
36
- input?: TInput;
36
+ input?: TInput;
37
37
  } : {
38
- input: TInput;
38
+ input: TInput;
39
39
  }) & {
40
- strategy?: TStrategy | undefined;
40
+ strategy?: TStrategy | undefined;
41
41
  };
42
42
  export type Matcher = (key?: unknown) => boolean;
43
- export type FetcherOptions<TClientContext extends ClientContext> = object extends TClientContext ? {
44
- context?: TClientContext | undefined;
43
+ export type FetcherOptions<TClientContext extends ClientContext> = {} extends TClientContext ? {
44
+ context?: TClientContext | undefined;
45
45
  } : {
46
- context: TClientContext;
46
+ context: TClientContext;
47
47
  };
48
48
  export type SubscriberOptions<TClientContext extends ClientContext> = FetcherOptions<TClientContext> & {
49
- /**
50
- * Determines how data is handled when the subscription is subscribed again.
51
- * Existing data stays until the new stream connects.
52
- *
53
- * - `'reset'`: The data becomes `[]` when the stream connects.
54
- * - `'append'`: New chunks are added to the existing data.
55
- *
56
- * @default 'reset'
57
- */
58
- refetchMode?: 'append' | 'reset' | undefined;
59
- /**
60
- * Maximum number of chunks to store.
61
- * When exceeded, the oldest chunks will be removed.
62
- */
63
- maxChunks?: number | undefined;
49
+ /**
50
+ * Determines how data is handled when the subscription is subscribed again.
51
+ * Existing data stays until the new stream connects.
52
+ *
53
+ * - `'reset'`: The data becomes `[]` when the stream connects.
54
+ * - `'append'`: New chunks are added to the existing data.
55
+ *
56
+ * @default 'reset'
57
+ */
58
+ refetchMode?: "append" | "reset" | undefined;
59
+ /**
60
+ * Maximum number of chunks to store.
61
+ * When exceeded, the oldest chunks will be removed.
62
+ */
63
+ maxChunks?: number | undefined;
64
64
  };
65
65
  export type MutatorOptions<TClientContext extends ClientContext> = FetcherOptions<TClientContext>;
66
66
  export type Fetcher<TInput, TOutput> = (key: OperationKey<TInput>) => Promise<TOutput>;
67
67
  export type Mutator<TInput, TOutput> = (key: unknown, options: Readonly<{
68
- arg: TInput;
68
+ arg: TInput;
69
69
  }>) => Promise<TOutput>;
70
- export type Subscriber<TInput, TData, TError> = (key: OperationKey<TInput>, options: SWRSubscriptionOptions<TData, TError>) => () => void;
70
+ export type Subscriber<TInput, TData, TError> = (key: OperationKey<TInput>, options: SWRSubscriptionOptions<TData, TError>) => () => void;
package/dist/types.js CHANGED
@@ -1,7 +1,9 @@
1
+ // src/types.ts
1
2
  /**
2
- * The symbol under which SWR utils attach operation details
3
- * (key and operation type) to the client context.
4
- *
5
- * @see {@link https://orpc.dev/docs/integrations/swr#operation-context | SWR Integration - Operation Context}
6
- */
7
- export const OPERATION_CONTEXT_SYMBOL = /* @__PURE__ */ Symbol.for('ORPC_SWR_OPERATION_CONTEXT');
3
+ * The symbol under which SWR utils attach operation details
4
+ * (key and operation type) to the client context.
5
+ *
6
+ * @see {@link https://orpc.dev/docs/integrations/swr#operation-context | SWR Integration - Operation Context}
7
+ */
8
+ const OPERATION_CONTEXT_SYMBOL = /* @__PURE__ */ Symbol.for("ORPC_SWR_OPERATION_CONTEXT");
9
+ export { OPERATION_CONTEXT_SYMBOL };
package/dist/utils.js CHANGED
@@ -1,14 +1,6 @@
1
- import { isPlainObject } from '@orpc/shared';
2
- export function isSubsetOf(subsetKey, fullKey) {
3
- return subsetKey === fullKey
4
- ? true
5
- : typeof subsetKey !== typeof fullKey
6
- ? false
7
- : isPlainObject(subsetKey) && isPlainObject(fullKey)
8
- ? Object.keys(subsetKey).every((key) => subsetKey[key] === undefined || isSubsetOf(subsetKey[key], fullKey[key]))
9
- : Array.isArray(subsetKey) && Array.isArray(fullKey)
10
- ? subsetKey.every((value, index) => isSubsetOf(value, fullKey[index]))
11
- : subsetKey instanceof Date && fullKey instanceof Date
12
- ? Object.is(subsetKey.getTime(), fullKey.getTime())
13
- : false;
1
+ import { isPlainObject } from "@orpc/shared";
2
+ // src/utils.ts
3
+ function isSubsetOf(subsetKey, fullKey) {
4
+ return subsetKey === fullKey ? true : typeof subsetKey !== typeof fullKey ? false : isPlainObject(subsetKey) && isPlainObject(fullKey) ? Object.keys(subsetKey).every((key) => subsetKey[key] === void 0 || isSubsetOf(subsetKey[key], fullKey[key])) : Array.isArray(subsetKey) && Array.isArray(fullKey) ? subsetKey.every((value, index) => isSubsetOf(value, fullKey[index])) : subsetKey instanceof Date && fullKey instanceof Date ? Object.is(subsetKey.getTime(), fullKey.getTime()) : false;
14
5
  }
6
+ export { isSubsetOf };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@orpc/swr",
3
- "version": "2.0.0-beta.49",
3
+ "version": "2.0.0-beta.51",
4
4
  "description": "SWR integration for oRPC: typesafe React data fetching hooks",
5
5
  "keywords": [
6
6
  "data-fetching",
@@ -37,8 +37,8 @@
37
37
  }
38
38
  },
39
39
  "dependencies": {
40
- "@orpc/client": "2.0.0-beta.49",
41
- "@orpc/shared": "2.0.0-beta.49"
40
+ "@orpc/client": "2.0.0-beta.51",
41
+ "@orpc/shared": "2.0.0-beta.51"
42
42
  },
43
43
  "devDependencies": {
44
44
  "swr": "^2.5.0",
package/dist/utils.d.ts DELETED
@@ -1 +0,0 @@
1
- export declare function isSubsetOf(subsetKey: unknown, fullKey: unknown): boolean;