trpc-msw 4.10.1 → 4.12.0

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.
@@ -1,10 +1,11 @@
1
1
  import { WEBSOCKET_ROUTER_REPLACED_CLOSE_CODE } from "./constants.js";
2
2
  import { MswWebSocketAdapter } from "./models/MswWebSocketAdapter.js";
3
- import "./models/UnhandledProcedureAction.js";
3
+ import { UnhandledProcedureAction } from "./models/UnhandledProcedureAction.js";
4
4
  import { checkIsProcedureType } from "./services/checkIsProcedureType.js";
5
5
  import { createMockRouter } from "./services/createMockRouter.js";
6
6
  import { getProcedurePaths } from "./services/getProcedurePaths.js";
7
7
  import { WebSocketServerAdapter } from "./packages/trpc-nuxt-module/dist/runtime/server/models/WebSocketServerAdapter.js";
8
+ import { omitUndefined } from "@esposter/shared";
8
9
  import { createTRPCRecursiveProxy } from "@trpc/server";
9
10
  import { fetchRequestHandler } from "@trpc/server/adapters/fetch";
10
11
  import { applyWSSHandler } from "@trpc/server/adapters/ws";
@@ -12,17 +13,19 @@ import { http, ws } from "msw";
12
13
  import { IncomingMessage } from "node:http";
13
14
  import { Socket } from "node:net";
14
15
  // src/createTRPCMsw.ts
15
- const createTRPCMsw = ({ allowMethodOverride, createContext, endpoint, onUnhandledProcedure = "Error", router, t, webSocketUrl }) => {
16
+ const createTRPCMsw = ({ allowMethodOverride, createContext, endpoint, onUnhandledProcedure = UnhandledProcedureAction.Error, router, t, webSocketUrl }) => {
16
17
  const registrations = /* @__PURE__ */ new Map();
17
18
  const procedureTypes = /* @__PURE__ */ new Map();
18
19
  const endpointPathname = new URL(endpoint, "http://localhost").pathname;
19
20
  let httpRouter;
20
21
  const handlers = [http.all(`${endpoint}/*`, ({ request }) => {
21
- if (onUnhandledProcedure === "Bypass" && !getProcedurePaths(request.url, endpointPathname).some((path) => registrations.has(path))) return void 0;
22
+ if (onUnhandledProcedure === UnhandledProcedureAction.Bypass && !getProcedurePaths(request.url, endpointPathname).some((path) => registrations.has(path))) return void 0;
22
23
  httpRouter ??= createMockRouter(t, procedureTypes, registrations, router);
23
24
  return fetchRequestHandler({
24
- allowMethodOverride,
25
- createContext,
25
+ ...omitUndefined({
26
+ allowMethodOverride,
27
+ createContext
28
+ }),
26
29
  endpoint: endpointPathname,
27
30
  req: request,
28
31
  router: httpRouter
@@ -31,7 +34,7 @@ const createTRPCMsw = ({ allowMethodOverride, createContext, endpoint, onUnhandl
31
34
  const createWebSocketServer = () => {
32
35
  const webSocketServer = new WebSocketServerAdapter();
33
36
  applyWSSHandler({
34
- createContext,
37
+ ...omitUndefined({ createContext }),
35
38
  router: createMockRouter(t, new Map(procedureTypes), registrations, router),
36
39
  wss: webSocketServer
37
40
  });
@@ -1,4 +1,4 @@
1
1
  import { ProcedureResolverOptions } from "./ProcedureResolverOptions.js";
2
- import { Promisable } from "../vendor/pnpm/type-fest@5.10.0/vendor/type-fest/source/promisable.js";
2
+ import { Promisable } from "../vendor/pnpm/type-fest@6.0.0/vendor/type-fest/source/promisable.js";
3
3
  import { AnyTRPCProcedure, inferProcedureInput, inferProcedureOutput } from "@trpc/server";
4
4
  export type ProcedureResolver<TContext, TProcedure extends AnyTRPCProcedure> = (options: ProcedureResolverOptions<TContext, inferProcedureInput<TProcedure>>) => Promisable<inferProcedureOutput<TProcedure>>;
@@ -1,7 +1,7 @@
1
1
  export interface ProcedureResolverOptions<TContext, TInput> {
2
- batchIndex?: number;
2
+ batchIndex?: number | undefined;
3
3
  ctx: TContext;
4
4
  input: TInput;
5
5
  path: string;
6
- signal?: AbortSignal;
6
+ signal?: AbortSignal | undefined;
7
7
  }
@@ -1,5 +1,5 @@
1
1
  import { ProcedureResolverOptions } from "./ProcedureResolverOptions.js";
2
- import { Promisable } from "../vendor/pnpm/type-fest@5.10.0/vendor/type-fest/source/promisable.js";
2
+ import { Promisable } from "../vendor/pnpm/type-fest@6.0.0/vendor/type-fest/source/promisable.js";
3
3
  export interface SubscriptionRegistration {
4
4
  resolver: (options: ProcedureResolverOptions<unknown, unknown>) => Promisable<AsyncIterable<unknown>>;
5
5
  type: "subscription";
@@ -1,7 +1,7 @@
1
1
  import { CreateContextOptions } from "./CreateContextOptions.js";
2
2
  import { TRPCMswRoot } from "./TRPCMswRoot.js";
3
3
  import { UnhandledProcedureAction } from "./UnhandledProcedureAction.js";
4
- import { Promisable } from "../vendor/pnpm/type-fest@5.10.0/vendor/type-fest/source/promisable.js";
4
+ import { Promisable } from "../vendor/pnpm/type-fest@6.0.0/vendor/type-fest/source/promisable.js";
5
5
  import { AnyTRPCRouter } from "@trpc/server";
6
6
  export interface TRPCMswOptions<TContext extends object> {
7
7
  allowMethodOverride?: boolean;
@@ -1,4 +1,5 @@
1
- export declare enum UnhandledProcedureAction {
2
- Bypass = "Bypass",
3
- Error = "Error"
4
- }
1
+ export declare const UnhandledProcedureAction: {
2
+ readonly Bypass: "Bypass";
3
+ readonly Error: "Error";
4
+ };
5
+ export type UnhandledProcedureAction = (typeof UnhandledProcedureAction)[keyof typeof UnhandledProcedureAction];
@@ -1,7 +1,6 @@
1
1
  // src/models/UnhandledProcedureAction.ts
2
- let UnhandledProcedureAction = /* @__PURE__ */ function(UnhandledProcedureAction) {
3
- UnhandledProcedureAction["Bypass"] = "Bypass";
4
- UnhandledProcedureAction["Error"] = "Error";
5
- return UnhandledProcedureAction;
6
- }({});
2
+ const UnhandledProcedureAction = {
3
+ Bypass: "Bypass",
4
+ Error: "Error"
5
+ };
7
6
  export { UnhandledProcedureAction };
@@ -5,8 +5,6 @@ Use-cases:
5
5
  - A function accepts a callback that may either return a value synchronously or may return a promised value.
6
6
  - This type could be the return type of `Promise#then()`, `Promise#catch()`, and `Promise#finally()` callbacks.
7
7
 
8
- Please upvote [this issue](https://github.com/microsoft/TypeScript/issues/31394) if you want to have this type as a built-in in TypeScript.
9
-
10
8
  @example
11
9
  ```
12
10
  import type {Promisable} from 'type-fest';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "trpc-msw",
3
- "version": "4.10.1",
3
+ "version": "4.12.0",
4
4
  "description": "tRPC for Mock Service Worker — answers queries, mutations and subscriptions over HTTP, batching, SSE and WebSockets with tRPC's own handlers, typed off your router.",
5
5
  "keywords": [
6
6
  "api-mocking",
@@ -46,25 +46,25 @@
46
46
  "typecheck": "tsrs --fast"
47
47
  },
48
48
  "dependencies": {
49
- "@esposter/shared": "4.10.1"
49
+ "@esposter/shared": "4.12.0"
50
50
  },
51
51
  "devDependencies": {
52
- "@esposter/configuration": "4.10.1",
52
+ "@esposter/configuration": "4.12.0",
53
53
  "@standard-schema/spec": "^1.1.0",
54
- "@trpc/client": "^11.28.0",
54
+ "@trpc/client": "^11.28.3",
55
55
  "@types/node": "^26.6.6",
56
56
  "superjson": "^2.2.6",
57
- "trpc-nuxt-module": "4.10.1",
57
+ "trpc-nuxt-module": "4.12.0",
58
58
  "tsdown": "^0.23.7",
59
- "type-fest": "^5.10.0",
59
+ "type-fest": "^6.0.0",
60
60
  "zod": "^4.6.7"
61
61
  },
62
62
  "peerDependencies": {
63
- "@trpc/server": "^11.28.0",
64
- "msw": "^3.0.5"
63
+ "@trpc/server": "^11.28.3",
64
+ "msw": "^3.0.6"
65
65
  },
66
66
  "inlinedDependencies": {
67
- "type-fest": "5.10.0"
67
+ "type-fest": "6.0.0"
68
68
  },
69
- "gitHead": "ca4dde04444294c59649179ae1a07a908b48125a"
69
+ "gitHead": "6667a4a1664bf5282bec24f4c7e6d30f2c4789de"
70
70
  }