orpc-nuxt 0.3.0 → 0.3.1

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
@@ -454,34 +454,22 @@ Each procedure leaf in `procedures` has a `.handle()` method that registers a ty
454
454
  // test/nuxt/setup.ts
455
455
  import { mockNuxtImport } from "@nuxt/test-utils/runtime"
456
456
  import type { RouterClient } from "@orpc/server"
457
- import { QueryClient } from "@tanstack/vue-query"
458
457
  import { createTestORPCClient } from "orpc-nuxt/testing"
459
458
  import { afterEach } from "vitest"
460
459
 
461
460
  import type { router } from "~~/server/rpc/router"
462
461
 
463
- const queryClient = new QueryClient({
464
- // Report a failing procedure instead of retrying it until the test times out.
465
- defaultOptions: { queries: { retry: false } },
466
- })
467
-
468
- export const { client, procedures, reset } = createTestORPCClient<RouterClient<typeof router>>({
469
- queryClient,
470
- })
462
+ export const { client, procedures, reset } = createTestORPCClient<RouterClient<typeof router>>()
471
463
 
472
464
  // Return the composable itself; Vitest hoists this factory before the setup file runs.
473
465
  mockNuxtImport("useOrpc", () => () => client)
474
466
 
475
- afterEach(() => {
476
- reset() // Remove registered handlers.
477
- queryClient.clear() // Remove cached responses.
478
- })
467
+ afterEach(reset)
479
468
  ```
480
469
 
481
470
  `orpc-nuxt/testing` does not import `nuxt/app`, so the hoisted `mockNuxtImport()` factory can load it safely.
482
- The explicit QueryClient keeps the test cache isolated and lets the setup clear it after each test.
483
- To use the application's QueryClient instead, omit the option and configure its defaults through `orpc.queryClient`.
484
- In that mode, import `useOrpcQueryClient()` only from a module that the hoisted factory cannot reach.
471
+ The client owns a QueryClient that never retries, so a failing procedure fails the test instead of timing out, and `reset()` removes the registered handlers together with the cached responses.
472
+ Reach that cache as `queryClient` to seed or inspect it, or pass your own to `createTestORPCClient()`; `reset()` clears that one as well.
485
473
 
486
474
  Register the required handlers before mounting; `mountSuspended()` waits for awaited queries before assertions:
487
475
 
package/dist/module.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "compatibility": {
5
5
  "nuxt": "^3.14.1592 || ^4.0.1"
6
6
  },
7
- "version": "0.3.0",
7
+ "version": "0.3.1",
8
8
  "builder": {
9
9
  "@nuxt/module-builder": "1.0.3",
10
10
  "unbuild": "3.6.1"
@@ -1,4 +1,5 @@
1
1
  import type { AnyNestedClient, Client } from "@orpc/client";
2
+ import { QueryClient } from "@tanstack/vue-query";
2
3
  import type { Mock } from "vitest";
3
4
  import type { ORPCNuxtClient, ORPCNuxtClientOptions } from "./types.js";
4
5
  type MaybePromise<T> = T | Promise<T>;
@@ -19,7 +20,9 @@ export interface TestORPCClient<T extends AnyNestedClient> {
19
20
  client: ORPCNuxtClient<T>;
20
21
  /** Register typed implementations and receive Vitest mocks for call assertions. */
21
22
  procedures: TestORPCProcedures<T>;
22
- /** Remove every registered procedure implementation. */
23
+ /** The cache the client reads and writes, to seed or inspect from a test. */
24
+ queryClient: QueryClient;
25
+ /** Remove every registered procedure implementation and clear the query cache. */
23
26
  reset: () => void;
24
27
  }
25
28
  /**
@@ -27,8 +30,11 @@ export interface TestORPCClient<T extends AnyNestedClient> {
27
30
  * The entrypoint has no Nuxt runtime dependency.
28
31
  * A shared setup file can therefore import it when Vitest hoists `mockNuxtImport()`.
29
32
  *
30
- * @param options - Cache key prefix and an optional test-owned QueryClient.
31
- * @returns A decorated client, its typed registration tree and a registration reset function.
33
+ * Without a `queryClient` the client owns one that never retries, so a failing procedure fails
34
+ * the test instead of retrying until it times out.
35
+ *
36
+ * @param options - Cache key prefix and a QueryClient to use instead of the owned one.
37
+ * @returns A decorated client, its typed registration tree, its cache and a reset function.
32
38
  */
33
39
  export declare function createTestORPCClient<T extends AnyNestedClient>(options?: ORPCNuxtClientOptions): TestORPCClient<T>;
34
40
  export {};
@@ -1,8 +1,15 @@
1
1
  import { createORPCClient } from "@orpc/client";
2
+ import { QueryClient } from "@tanstack/vue-query";
2
3
  import { vi } from "vitest";
3
4
  import { createORPCNuxtClient } from "./client/create.js";
4
5
  export function createTestORPCClient(options = {}) {
5
6
  const registrations = /* @__PURE__ */ new Map();
7
+ const queryClient = options.queryClient ?? new QueryClient({
8
+ defaultOptions: {
9
+ // Retries turn a failing procedure into a test timeout instead of a reported failure.
10
+ queries: { retry: false }
11
+ }
12
+ });
6
13
  function registerHandler(path, handler) {
7
14
  const mock = vi.fn(handler);
8
15
  registrations.set(path, mock);
@@ -20,7 +27,7 @@ export function createTestORPCClient(options = {}) {
20
27
  return await callHandler(path.join("."), input);
21
28
  }
22
29
  };
23
- const client = createORPCNuxtClient(createORPCClient(link), options);
30
+ const client = createORPCNuxtClient(createORPCClient(link), { ...options, queryClient });
24
31
  const procedures = createRecursiveProxy([], (path, args) => {
25
32
  if (path.at(-1) !== "handle") {
26
33
  throw new Error(`Unknown test procedure call: ${path.join(".")}`);
@@ -36,7 +43,11 @@ export function createTestORPCClient(options = {}) {
36
43
  return {
37
44
  client,
38
45
  procedures,
39
- reset: () => registrations.clear()
46
+ queryClient,
47
+ reset: () => {
48
+ registrations.clear();
49
+ queryClient.clear();
50
+ }
40
51
  };
41
52
  }
42
53
  function createRecursiveProxy(path, call) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "orpc-nuxt",
3
- "version": "0.3.0",
3
+ "version": "0.3.1",
4
4
  "description": "oRPC integration for Nuxt with TanStack Vue Query composables.",
5
5
  "homepage": "https://github.com/IlyaSemenov/orpc-nuxt#readme",
6
6
  "bugs": "https://github.com/IlyaSemenov/orpc-nuxt/issues",