@orpc/swr 2.0.0-beta.45 → 2.0.0-beta.46

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
@@ -21,9 +21,40 @@
21
21
  </a>
22
22
  </div>
23
23
 
24
+ **oRPC** is a TypeScript framework for building end-to-end typesafe APIs. Write your API once as plain TypeScript functions, and oRPC gives you a fully typed client, a REST API with an OpenAPI document, and MCP tools for AI agents, with no code generation. It runs on Node.js, Bun, Deno, Cloudflare Workers, and more.
25
+
26
+ Define procedures on the server and serve them with an [RPC handler](https://orpc.dev/docs/rpc/handler):
27
+
28
+ ```ts
29
+ import { os } from '@orpc/server'
30
+ import * as z from 'zod'
31
+
32
+ export const router = {
33
+ planet: {
34
+ find: os
35
+ .input(z.object({ id: z.number() }))
36
+ .handler(({ input }) => ({ id: input.id, name: 'Earth' })),
37
+ },
38
+ }
39
+ ```
40
+
41
+ Then call them from a client that knows every input and output, without generating anything:
42
+
43
+ ```ts
44
+ import type { RouterClient } from '@orpc/server'
45
+ import type { router } from './router'
46
+ import { createORPCClient } from '@orpc/client'
47
+ import { RPCLink } from '@orpc/client/fetch'
48
+
49
+ const link = new RPCLink({ origin: 'http://localhost:3000', url: '/rpc' })
50
+ const client: RouterClient<typeof router> = createORPCClient(link)
51
+
52
+ const planet = await client.planet.find({ id: 1 }) // { id: number, name: string }
53
+ ```
54
+
24
55
  ## Documentation
25
56
 
26
- You can read the documentation [here](https://orpc.dev).
57
+ Read the full documentation at [orpc.dev](https://orpc.dev), starting with the [Getting Started guide](https://orpc.dev/docs/getting-started).
27
58
 
28
59
  ## Packages
29
60
 
@@ -56,21 +87,21 @@ You can read the documentation [here](https://orpc.dev).
56
87
 
57
88
  **Framework & ecosystem integrations**
58
89
 
59
- | Package | Purpose | Docs |
60
- | ------------------------------------------------------------------------------------ | ----------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
61
- | [@orpc/next](https://www.npmjs.com/package/@orpc/next) | Integrate with [Next.js Server Functions](https://nextjs.org/docs/app/getting-started/mutating-data). | [Next.js](https://orpc.dev/docs/integrations/next) |
62
- | [@orpc/ai-sdk](https://www.npmjs.com/package/@orpc/ai-sdk) | Turn contracts and procedures into [AI SDK](https://ai-sdk.dev/) tools. | [AI SDK](https://orpc.dev/docs/integrations/ai-sdk) |
63
- | [@orpc/mcp](https://www.npmjs.com/package/@orpc/mcp) | Expose procedures as [MCP](https://modelcontextprotocol.io/) tools. | [MCP](https://orpc.dev/docs/integrations/mcp) |
64
- | [@orpc/tanstack-query](https://www.npmjs.com/package/@orpc/tanstack-query) | Integrate with [TanStack Query](https://tanstack.com/query/latest). | [TanStack Query](https://orpc.dev/docs/integrations/tanstack-query) |
65
- | [@orpc/pinia-colada](https://www.npmjs.com/package/@orpc/pinia-colada) | Integrate with [Pinia Colada](https://pinia-colada.esm.dev/). | [Pinia Colada](https://orpc.dev/docs/integrations/pinia-colada) |
66
- | [@orpc/swr](https://www.npmjs.com/package/@orpc/swr) | Integrate with [SWR](https://swr.vercel.app/). | [SWR](https://orpc.dev/docs/integrations/swr) |
67
- | [@orpc/msw](https://www.npmjs.com/package/@orpc/msw) | Mock procedures with [Mock Service Worker](https://mswjs.io/). | [MSW](https://orpc.dev/docs/integrations/msw) |
68
- | [@orpc/experimental-effect](https://www.npmjs.com/package/@orpc/experimental-effect) | Integrate with [Effect](https://effect.website/). | [Effect](https://orpc.dev/docs/integrations/effect) |
69
- | [@orpc/nest](https://www.npmjs.com/package/@orpc/nest) | Implement your contract with [NestJS](https://nestjs.com/). | [NestJS](https://orpc.dev/docs/integrations/nest) |
70
- | [@orpc/node](https://www.npmjs.com/package/@orpc/node) | [Node.js](https://nodejs.org/) plugins for static file serving and large uploads. | [Static File](https://orpc.dev/docs/plugins/static-file), [Tmp File Upload](https://orpc.dev/docs/plugins/tmp-file-upload), [Batch Response Compression](https://orpc.dev/docs/plugins/batch-response-compression) |
71
- | [@orpc/bun](https://www.npmjs.com/package/@orpc/bun) | Adapters for [Bun's Redis](https://bun.sh/). | [Publisher](https://orpc.dev/docs/helpers/publisher), [Rate Limit](https://orpc.dev/docs/helpers/ratelimit), [Lock](https://orpc.dev/docs/helpers/lock) |
72
- | [@orpc/cloudflare](https://www.npmjs.com/package/@orpc/cloudflare) | Adapters for [Cloudflare Workers](https://developers.cloudflare.com/workers/). | [Publisher](https://orpc.dev/docs/helpers/publisher), [Rate Limit](https://orpc.dev/docs/helpers/ratelimit), [Lock](https://orpc.dev/docs/helpers/lock), [Traces](https://orpc.dev/docs/integrations/cloudflare-traces) |
73
- | [@orpc/trpc](https://www.npmjs.com/package/@orpc/trpc) | Reuse existing [tRPC](https://trpc.io/) routers within oRPC. | [tRPC](https://orpc.dev/docs/integrations/trpc) |
90
+ | Package | Purpose | Docs |
91
+ | -------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
92
+ | [@orpc/next](https://www.npmjs.com/package/@orpc/next) | Integrate with [Next.js Server Functions](https://nextjs.org/docs/app/getting-started/mutating-data). | [Next.js](https://orpc.dev/docs/integrations/next) |
93
+ | [@orpc/ai-sdk](https://www.npmjs.com/package/@orpc/ai-sdk) | Turn contracts and procedures into [AI SDK](https://ai-sdk.dev/) tools. | [AI SDK](https://orpc.dev/docs/integrations/ai-sdk) |
94
+ | [@orpc/mcp](https://www.npmjs.com/package/@orpc/mcp) | Expose procedures as [MCP](https://modelcontextprotocol.io/) tools. | [MCP](https://orpc.dev/docs/integrations/mcp) |
95
+ | [@orpc/tanstack-query](https://www.npmjs.com/package/@orpc/tanstack-query) | Integrate with [TanStack Query](https://tanstack.com/query/latest). | [TanStack Query](https://orpc.dev/docs/integrations/tanstack-query) |
96
+ | [@orpc/pinia-colada](https://www.npmjs.com/package/@orpc/pinia-colada) | Integrate with [Pinia Colada](https://pinia-colada.esm.dev/). | [Pinia Colada](https://orpc.dev/docs/integrations/pinia-colada) |
97
+ | [@orpc/swr](https://www.npmjs.com/package/@orpc/swr) | Integrate with [SWR](https://swr.vercel.app/). | [SWR](https://orpc.dev/docs/integrations/swr) |
98
+ | [@orpc/msw](https://www.npmjs.com/package/@orpc/msw) | Mock procedures with [Mock Service Worker](https://mswjs.io/). | [MSW](https://orpc.dev/docs/integrations/msw) |
99
+ | [@orpc/effect](https://www.npmjs.com/package/@orpc/effect) | Integrate with [Effect](https://effect.website/). | [Effect](https://orpc.dev/docs/integrations/effect) |
100
+ | [@orpc/nest](https://www.npmjs.com/package/@orpc/nest) | Implement your contract with [NestJS](https://nestjs.com/). | [NestJS](https://orpc.dev/docs/integrations/nest) |
101
+ | [@orpc/node](https://www.npmjs.com/package/@orpc/node) | [Node.js](https://nodejs.org/) plugins for static file serving and large uploads. | [Static File](https://orpc.dev/docs/plugins/static-file), [Tmp File Upload](https://orpc.dev/docs/plugins/tmp-file-upload), [Batch Response Compression](https://orpc.dev/docs/plugins/batch-response-compression) |
102
+ | [@orpc/bun](https://www.npmjs.com/package/@orpc/bun) | Adapters for [Bun's Redis](https://bun.sh/). | [Publisher](https://orpc.dev/docs/helpers/publisher), [Rate Limit](https://orpc.dev/docs/helpers/ratelimit), [Lock](https://orpc.dev/docs/helpers/lock) |
103
+ | [@orpc/cloudflare](https://www.npmjs.com/package/@orpc/cloudflare) | Adapters for [Cloudflare Workers](https://developers.cloudflare.com/workers/). | [Publisher](https://orpc.dev/docs/helpers/publisher), [Rate Limit](https://orpc.dev/docs/helpers/ratelimit), [Lock](https://orpc.dev/docs/helpers/lock), [Traces](https://orpc.dev/docs/integrations/cloudflare-traces) |
104
+ | [@orpc/trpc](https://www.npmjs.com/package/@orpc/trpc) | Reuse existing [tRPC](https://trpc.io/) routers within oRPC. | [tRPC](https://orpc.dev/docs/integrations/trpc) |
74
105
 
75
106
  **Observability**
76
107
 
package/dist/index.d.mts CHANGED
@@ -1,4 +1,5 @@
1
1
  import { PartialDeep, MaybeOptionalOptions, Public } from '@orpc/shared';
2
+ export { Public } from '@orpc/shared';
2
3
  import { ClientContext, Client, AnyNestedClient } from '@orpc/client';
3
4
  import { SWRSubscriptionOptions } from 'swr/subscription';
4
5
 
@@ -13,12 +14,6 @@ type OperationKeyOptions<TInput> = OperationKeyPrefixOptions & {
13
14
  input?: PartialDeep<TInput> | undefined;
14
15
  };
15
16
  type OperationKey<TInput> = [path: string[], options: Omit<OperationKeyOptions<TInput>, 'prefix'>] | [prefix: string, path: string[], options: Omit<OperationKeyOptions<TInput>, 'prefix'>];
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
- declare function generateOperationKey<TInput>(path: string[], options?: OperationKeyOptions<TInput>): OperationKey<TInput>;
22
17
 
23
18
  type InferSubscriberOutput<TOutput> = TOutput extends AsyncIterable<infer U> ? U[] : never;
24
19
  type InferLiveSubscriberOutput<TOutput> = TOutput extends AsyncIterable<infer U> ? U : never;
@@ -163,7 +158,5 @@ interface RouterUtilsOptions extends OperationKeyPrefixOptions {
163
158
  */
164
159
  declare function createRouterUtils<T extends AnyNestedClient>(client: T, options?: RouterUtilsOptions): RouterUtils<T>;
165
160
 
166
- declare function isSubsetOf(subsetKey: unknown, fullKey: unknown): boolean;
167
-
168
- export { OPERATION_CONTEXT_SYMBOL, ProcedureUtils, OPERATION_CONTEXT_SYMBOL as SWR_OPERATION_CONTEXT_SYMBOL, SharedUtils, createRouterUtils, createRouterUtils as createSWRUtils, generateOperationKey, isSubsetOf };
161
+ export { OPERATION_CONTEXT_SYMBOL, ProcedureUtils, OPERATION_CONTEXT_SYMBOL as SWR_OPERATION_CONTEXT_SYMBOL, SharedUtils, createRouterUtils, createRouterUtils as createSWRUtils };
169
162
  export type { Fetcher, FetcherOptions, InferLiveSubscriberOutput, InferSubscriberOutput, KeyOptions, Matcher, MatcherOptions, MatcherStrategy, Mutator, MutatorOptions, OperationContext, OperationKey, OperationKeyOptions, OperationKeyPrefixOptions, OperationType, ProcedureUtilsOptions, RouterUtils, RouterUtilsOptions, OperationContext as SWROperationContext, Subscriber, SubscriberOptions };
package/dist/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import { PartialDeep, MaybeOptionalOptions, Public } from '@orpc/shared';
2
+ export { Public } from '@orpc/shared';
2
3
  import { ClientContext, Client, AnyNestedClient } from '@orpc/client';
3
4
  import { SWRSubscriptionOptions } from 'swr/subscription';
4
5
 
@@ -13,12 +14,6 @@ type OperationKeyOptions<TInput> = OperationKeyPrefixOptions & {
13
14
  input?: PartialDeep<TInput> | undefined;
14
15
  };
15
16
  type OperationKey<TInput> = [path: string[], options: Omit<OperationKeyOptions<TInput>, 'prefix'>] | [prefix: string, path: string[], options: Omit<OperationKeyOptions<TInput>, 'prefix'>];
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
- declare function generateOperationKey<TInput>(path: string[], options?: OperationKeyOptions<TInput>): OperationKey<TInput>;
22
17
 
23
18
  type InferSubscriberOutput<TOutput> = TOutput extends AsyncIterable<infer U> ? U[] : never;
24
19
  type InferLiveSubscriberOutput<TOutput> = TOutput extends AsyncIterable<infer U> ? U : never;
@@ -163,7 +158,5 @@ interface RouterUtilsOptions extends OperationKeyPrefixOptions {
163
158
  */
164
159
  declare function createRouterUtils<T extends AnyNestedClient>(client: T, options?: RouterUtilsOptions): RouterUtils<T>;
165
160
 
166
- declare function isSubsetOf(subsetKey: unknown, fullKey: unknown): boolean;
167
-
168
- export { OPERATION_CONTEXT_SYMBOL, ProcedureUtils, OPERATION_CONTEXT_SYMBOL as SWR_OPERATION_CONTEXT_SYMBOL, SharedUtils, createRouterUtils, createRouterUtils as createSWRUtils, generateOperationKey, isSubsetOf };
161
+ export { OPERATION_CONTEXT_SYMBOL, ProcedureUtils, OPERATION_CONTEXT_SYMBOL as SWR_OPERATION_CONTEXT_SYMBOL, SharedUtils, createRouterUtils, createRouterUtils as createSWRUtils };
169
162
  export type { Fetcher, FetcherOptions, InferLiveSubscriberOutput, InferSubscriberOutput, KeyOptions, Matcher, MatcherOptions, MatcherStrategy, Mutator, MutatorOptions, OperationContext, OperationKey, OperationKeyOptions, OperationKeyPrefixOptions, OperationType, ProcedureUtilsOptions, RouterUtils, RouterUtilsOptions, OperationContext as SWROperationContext, Subscriber, SubscriberOptions };
package/dist/index.mjs CHANGED
@@ -211,8 +211,11 @@ function createRouterUtils(client, options = {}) {
211
211
  const recursive = new Proxy(utils, {
212
212
  get(target, prop) {
213
213
  const value = Reflect.get(target, prop);
214
+ if (RECURSIVE_CLIENT_UNWRAP_KEYS.has(prop)) {
215
+ return value ?? Reflect.get(Object.prototype, prop);
216
+ }
214
217
  const nextClient = Reflect.get(client, prop);
215
- if (typeof prop !== "string" || RECURSIVE_CLIENT_UNWRAP_KEYS.has(prop) || !isTypescriptObject(nextClient)) {
218
+ if (typeof prop !== "string" || !isTypescriptObject(nextClient)) {
216
219
  return value;
217
220
  }
218
221
  let result = cache.get(prop);
@@ -234,4 +237,4 @@ function createRouterUtils(client, options = {}) {
234
237
  return recursive;
235
238
  }
236
239
 
237
- export { OPERATION_CONTEXT_SYMBOL, ProcedureUtils, OPERATION_CONTEXT_SYMBOL as SWR_OPERATION_CONTEXT_SYMBOL, SharedUtils, createRouterUtils, createRouterUtils as createSWRUtils, generateOperationKey, isSubsetOf };
240
+ export { OPERATION_CONTEXT_SYMBOL, ProcedureUtils, OPERATION_CONTEXT_SYMBOL as SWR_OPERATION_CONTEXT_SYMBOL, SharedUtils, createRouterUtils, createRouterUtils as createSWRUtils };
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.45",
4
+ "version": "2.0.0-beta.46",
5
5
  "description": "SWR integration for oRPC: typesafe React data fetching hooks",
6
6
  "license": "MIT",
7
7
  "funding": [
@@ -40,8 +40,8 @@
40
40
  "swr": ">=2.4.2"
41
41
  },
42
42
  "dependencies": {
43
- "@orpc/client": "2.0.0-beta.45",
44
- "@orpc/shared": "2.0.0-beta.45"
43
+ "@orpc/client": "2.0.0-beta.46",
44
+ "@orpc/shared": "2.0.0-beta.46"
45
45
  },
46
46
  "devDependencies": {
47
47
  "swr": "^2.5.0",