trpc-msw 4.3.1 → 4.3.3
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/dist/index.d.ts +0 -38
- package/dist/index.js +10 -20
- package/package.json +5 -5
package/dist/index.d.ts
CHANGED
|
@@ -3,10 +3,7 @@ import { AnyTRPCProcedure, AnyTRPCRootTypes, AnyTRPCRouter, TRPCProcedureType, T
|
|
|
3
3
|
import { FetchCreateContextFnOptions } from "@trpc/server/adapters/fetch";
|
|
4
4
|
import { CreateWSSContextFnOptions } from "@trpc/server/adapters/ws";
|
|
5
5
|
import { HttpHandler, WebSocketData, WebSocketHandler, WebSocketHandlerConnection } from "msw";
|
|
6
|
-
//#region src/constants.d.ts
|
|
7
6
|
export declare const WEBSOCKET_ROUTER_REPLACED_CLOSE_CODE = 4e3;
|
|
8
|
-
//#endregion
|
|
9
|
-
//#region src/models/ProcedureResolverOptions.d.ts
|
|
10
7
|
export interface ProcedureResolverOptions<TContext, TInput> {
|
|
11
8
|
batchIndex?: number;
|
|
12
9
|
ctx: TContext;
|
|
@@ -14,8 +11,6 @@ export interface ProcedureResolverOptions<TContext, TInput> {
|
|
|
14
11
|
path: string;
|
|
15
12
|
signal?: AbortSignal;
|
|
16
13
|
}
|
|
17
|
-
//#endregion
|
|
18
|
-
//#region ../../node_modules/.pnpm/type-fest@5.10.0/node_modules/type-fest/source/promisable.d.ts
|
|
19
14
|
/**
|
|
20
15
|
Create a type that represents either the value or the value wrapped in `PromiseLike`.
|
|
21
16
|
|
|
@@ -41,36 +36,22 @@ await logger(() => Promise.resolve('bar'));
|
|
|
41
36
|
@category Async
|
|
42
37
|
*/
|
|
43
38
|
type Promisable<T> = T | PromiseLike<T>;
|
|
44
|
-
//#endregion
|
|
45
|
-
//#region src/models/ProcedureResolver.d.ts
|
|
46
39
|
export type ProcedureResolver<TContext, TProcedure extends AnyTRPCProcedure> = (options: ProcedureResolverOptions<TContext, inferProcedureInput<TProcedure>>) => Promisable<inferProcedureOutput<TProcedure>>;
|
|
47
|
-
//#endregion
|
|
48
|
-
//#region src/models/TRPCMswRouterRecord.d.ts
|
|
49
40
|
export type TRPCMswRouterRecord<TContext, TRecord extends TRPCRouterRecord> = { readonly [TKey in keyof TRecord]: TRecord[TKey] extends AnyTRPCProcedure ? Readonly<Record<TRecord[TKey]["_def"]["type"], (resolver: ProcedureResolver<TContext, TRecord[TKey]>) => void>> : TRecord[TKey] extends TRPCRouterRecord ? TRPCMswRouterRecord<TContext, TRecord[TKey]> : never; };
|
|
50
|
-
//#endregion
|
|
51
|
-
//#region src/models/TRPCMsw.d.ts
|
|
52
41
|
export interface TRPCMsw<TRouter extends AnyTRPCRouter, TContext> {
|
|
53
42
|
handlers: (HttpHandler | WebSocketHandler)[];
|
|
54
43
|
reset: () => void;
|
|
55
44
|
trpc: TRPCMswRouterRecord<TContext, TRouter["_def"]["record"]>;
|
|
56
45
|
}
|
|
57
|
-
//#endregion
|
|
58
|
-
//#region src/models/CreateContextOptions.d.ts
|
|
59
46
|
export type CreateContextOptions = CreateWSSContextFnOptions | FetchCreateContextFnOptions;
|
|
60
|
-
//#endregion
|
|
61
|
-
//#region src/models/TRPCMswRoot.d.ts
|
|
62
47
|
export interface TRPCMswRoot<TContext extends object> {
|
|
63
48
|
procedure: TRPCRootObject<TContext, object, object>["procedure"];
|
|
64
49
|
router: TRPCRouterBuilder<AnyTRPCRootTypes>;
|
|
65
50
|
}
|
|
66
|
-
//#endregion
|
|
67
|
-
//#region src/models/UnhandledProcedureAction.d.ts
|
|
68
51
|
export declare enum UnhandledProcedureAction {
|
|
69
52
|
Bypass = "Bypass",
|
|
70
53
|
Error = "Error"
|
|
71
54
|
}
|
|
72
|
-
//#endregion
|
|
73
|
-
//#region src/models/TRPCMswOptions.d.ts
|
|
74
55
|
export interface TRPCMswOptions<TContext extends object> {
|
|
75
56
|
allowMethodOverride?: boolean;
|
|
76
57
|
createContext?: (options: CreateContextOptions) => Promisable<TContext>;
|
|
@@ -80,11 +61,7 @@ export interface TRPCMswOptions<TContext extends object> {
|
|
|
80
61
|
t: TRPCMswRoot<TContext>;
|
|
81
62
|
webSocketUrl?: string;
|
|
82
63
|
}
|
|
83
|
-
//#endregion
|
|
84
|
-
//#region src/createTRPCMsw.d.ts
|
|
85
64
|
export declare const createTRPCMsw: <TRouter extends AnyTRPCRouter, TContext extends object = object>({ allowMethodOverride, createContext, endpoint, onUnhandledProcedure, router, t, webSocketUrl }: TRPCMswOptions<TContext>) => TRPCMsw<TRouter, TContext>;
|
|
86
|
-
//#endregion
|
|
87
|
-
//#region src/models/MswWebSocketAdapter.d.ts
|
|
88
65
|
type MswWebSocketClient = WebSocketHandlerConnection["client"];
|
|
89
66
|
export declare class MswWebSocketAdapter extends EventEmitter {
|
|
90
67
|
#private;
|
|
@@ -98,32 +75,17 @@ export declare class MswWebSocketAdapter extends EventEmitter {
|
|
|
98
75
|
send(data: string): void;
|
|
99
76
|
terminate(): void;
|
|
100
77
|
}
|
|
101
|
-
//#endregion
|
|
102
|
-
//#region src/models/SubscriptionRegistration.d.ts
|
|
103
78
|
export interface SubscriptionRegistration {
|
|
104
79
|
resolver: (options: ProcedureResolverOptions<unknown, unknown>) => Promisable<AsyncIterable<unknown>>;
|
|
105
80
|
type: "subscription";
|
|
106
81
|
}
|
|
107
|
-
//#endregion
|
|
108
|
-
//#region src/models/ProcedureRegistration.d.ts
|
|
109
82
|
export type ProcedureRegistration = SubscriptionRegistration | {
|
|
110
83
|
resolver: (options: ProcedureResolverOptions<unknown, unknown>) => unknown;
|
|
111
84
|
type: Exclude<TRPCProcedureType, "subscription">;
|
|
112
85
|
};
|
|
113
|
-
//#endregion
|
|
114
|
-
//#region src/services/checkIsProcedureType.d.ts
|
|
115
86
|
export declare const checkIsProcedureType: (value: unknown) => value is TRPCProcedureType;
|
|
116
|
-
//#endregion
|
|
117
|
-
//#region src/services/createMockRouter.d.ts
|
|
118
87
|
export declare const createMockRouter: <TContext extends object>({ procedure: baseProcedure, router }: TRPCMswRoot<TContext>, procedureTypes: ReadonlyMap<string, TRPCProcedureType>, registrations: ReadonlyMap<string, ProcedureRegistration>, inputRouter?: AnyTRPCRouter) => AnyTRPCRouter;
|
|
119
|
-
//#endregion
|
|
120
|
-
//#region src/services/getProcedurePaths.d.ts
|
|
121
88
|
export declare const getProcedurePaths: (url: string, endpointPathname: string) => string[];
|
|
122
|
-
//#endregion
|
|
123
|
-
//#region src/services/toBuffer.d.ts
|
|
124
89
|
export declare const toBuffer: (data: WebSocketData) => Buffer;
|
|
125
|
-
//#endregion
|
|
126
|
-
//#region src/services/toResolverOptions.d.ts
|
|
127
90
|
export declare const toResolverOptions: ({ batchIndex, ctx, input, path, signal }: ProcedureResolverOptions<unknown, unknown>) => ProcedureResolverOptions<unknown, unknown>;
|
|
128
|
-
//#endregion
|
|
129
91
|
export {};
|
package/dist/index.js
CHANGED
|
@@ -6,18 +6,16 @@ import { applyWSSHandler } from "@trpc/server/adapters/ws";
|
|
|
6
6
|
import { http, ws } from "msw";
|
|
7
7
|
import { IncomingMessage } from "node:http";
|
|
8
8
|
import { Socket } from "node:net";
|
|
9
|
-
|
|
9
|
+
// src/constants.ts
|
|
10
10
|
const WEBSOCKET_ROUTER_REPLACED_CLOSE_CODE = 4e3;
|
|
11
|
-
|
|
12
|
-
//#region src/services/toBuffer.ts
|
|
11
|
+
// src/services/toBuffer.ts
|
|
13
12
|
const toBuffer = (data) => {
|
|
14
13
|
if (typeof data === "string") return Buffer.from(data);
|
|
15
14
|
else if (ArrayBuffer.isView(data)) return Buffer.from(data.buffer, data.byteOffset, data.byteLength);
|
|
16
15
|
else if (data instanceof Blob) throw new TypeError("A WebSocket message sent as a Blob cannot be read in order");
|
|
17
16
|
else return Buffer.from(data);
|
|
18
17
|
};
|
|
19
|
-
|
|
20
|
-
//#region src/models/MswWebSocketAdapter.ts
|
|
18
|
+
// src/models/MswWebSocketAdapter.ts
|
|
21
19
|
var MswWebSocketAdapter = class extends EventEmitter {
|
|
22
20
|
CLOSED = WebSocket.CLOSED;
|
|
23
21
|
CLOSING = WebSocket.CLOSING;
|
|
@@ -47,23 +45,20 @@ var MswWebSocketAdapter = class extends EventEmitter {
|
|
|
47
45
|
this.close();
|
|
48
46
|
}
|
|
49
47
|
};
|
|
50
|
-
|
|
51
|
-
//#region src/models/UnhandledProcedureAction.ts
|
|
48
|
+
// src/models/UnhandledProcedureAction.ts
|
|
52
49
|
let UnhandledProcedureAction = /* @__PURE__ */ function(UnhandledProcedureAction) {
|
|
53
50
|
UnhandledProcedureAction["Bypass"] = "Bypass";
|
|
54
51
|
UnhandledProcedureAction["Error"] = "Error";
|
|
55
52
|
return UnhandledProcedureAction;
|
|
56
53
|
}({});
|
|
57
|
-
|
|
58
|
-
//#region src/services/checkIsProcedureType.ts
|
|
54
|
+
// src/services/checkIsProcedureType.ts
|
|
59
55
|
const PROCEDURE_TYPES = /* @__PURE__ */ new Set([
|
|
60
56
|
"mutation",
|
|
61
57
|
"query",
|
|
62
58
|
"subscription"
|
|
63
59
|
]);
|
|
64
60
|
const checkIsProcedureType = (value) => PROCEDURE_TYPES.has(value);
|
|
65
|
-
|
|
66
|
-
//#region src/services/toResolverOptions.ts
|
|
61
|
+
// src/services/toResolverOptions.ts
|
|
67
62
|
const toResolverOptions = ({ batchIndex, ctx, input, path, signal }) => ({
|
|
68
63
|
batchIndex,
|
|
69
64
|
ctx,
|
|
@@ -71,8 +66,7 @@ const toResolverOptions = ({ batchIndex, ctx, input, path, signal }) => ({
|
|
|
71
66
|
path,
|
|
72
67
|
signal
|
|
73
68
|
});
|
|
74
|
-
|
|
75
|
-
//#region src/services/createMockRouter.ts
|
|
69
|
+
// src/services/createMockRouter.ts
|
|
76
70
|
const createMockRouter = ({ procedure: baseProcedure, router }, procedureTypes, registrations, inputRouter) => router(Object.fromEntries(procedureTypes.entries().map(([path, type]) => {
|
|
77
71
|
const procedure = (inputRouter?._def.procedures[path]?._def.inputs ?? []).reduce((builder, parser) => builder.input(parser), baseProcedure);
|
|
78
72
|
const createNotFoundError = () => new TRPCError({
|
|
@@ -94,11 +88,9 @@ const createMockRouter = ({ procedure: baseProcedure, router }, procedureTypes,
|
|
|
94
88
|
default: return exhaustiveGuard(type);
|
|
95
89
|
}
|
|
96
90
|
})));
|
|
97
|
-
|
|
98
|
-
//#region src/services/getProcedurePaths.ts
|
|
91
|
+
// src/services/getProcedurePaths.ts
|
|
99
92
|
const getProcedurePaths = (url, endpointPathname) => decodeURIComponent(new URL(url).pathname.slice(endpointPathname.length + 1)).split(",");
|
|
100
|
-
|
|
101
|
-
//#region ../trpc-nuxt-module/dist/runtime/server/models/WebSocketServerAdapter.js
|
|
93
|
+
// ../trpc-nuxt-module/dist/runtime/server/models/WebSocketServerAdapter.js
|
|
102
94
|
var WebSocketServerAdapter = class extends EventEmitter {
|
|
103
95
|
clients = /* @__PURE__ */ new Set();
|
|
104
96
|
addConnection(client, request) {
|
|
@@ -109,8 +101,7 @@ var WebSocketServerAdapter = class extends EventEmitter {
|
|
|
109
101
|
this.emit("connection", client, request);
|
|
110
102
|
}
|
|
111
103
|
};
|
|
112
|
-
|
|
113
|
-
//#region src/createTRPCMsw.ts
|
|
104
|
+
// src/createTRPCMsw.ts
|
|
114
105
|
const createTRPCMsw = ({ allowMethodOverride, createContext, endpoint, onUnhandledProcedure = "Error", router, t, webSocketUrl }) => {
|
|
115
106
|
const registrations = /* @__PURE__ */ new Map();
|
|
116
107
|
const procedureTypes = /* @__PURE__ */ new Map();
|
|
@@ -171,5 +162,4 @@ const createTRPCMsw = ({ allowMethodOverride, createContext, endpoint, onUnhandl
|
|
|
171
162
|
})
|
|
172
163
|
};
|
|
173
164
|
};
|
|
174
|
-
//#endregion
|
|
175
165
|
export { MswWebSocketAdapter, UnhandledProcedureAction, WEBSOCKET_ROUTER_REPLACED_CLOSE_CODE, checkIsProcedureType, createMockRouter, createTRPCMsw, getProcedurePaths, toBuffer, toResolverOptions };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "trpc-msw",
|
|
3
|
-
"version": "4.3.
|
|
3
|
+
"version": "4.3.3",
|
|
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
|
"batch",
|
|
@@ -47,15 +47,15 @@
|
|
|
47
47
|
"typecheck": "tsc"
|
|
48
48
|
},
|
|
49
49
|
"dependencies": {
|
|
50
|
-
"@esposter/shared": "4.3.
|
|
50
|
+
"@esposter/shared": "4.3.3"
|
|
51
51
|
},
|
|
52
52
|
"devDependencies": {
|
|
53
|
-
"@esposter/configuration": "4.3.
|
|
53
|
+
"@esposter/configuration": "4.3.3",
|
|
54
54
|
"@standard-schema/spec": "^1.1.0",
|
|
55
55
|
"@trpc/client": "^11.19.0",
|
|
56
56
|
"@types/node": "^26.6.5",
|
|
57
57
|
"superjson": "^2.2.6",
|
|
58
|
-
"trpc-nuxt-module": "4.3.
|
|
58
|
+
"trpc-nuxt-module": "4.3.3",
|
|
59
59
|
"tsdown": "^0.23.1",
|
|
60
60
|
"type-fest": "^5.10.0",
|
|
61
61
|
"zod": "^4.6.7"
|
|
@@ -67,5 +67,5 @@
|
|
|
67
67
|
"inlinedDependencies": {
|
|
68
68
|
"type-fest": "5.10.0"
|
|
69
69
|
},
|
|
70
|
-
"gitHead": "
|
|
70
|
+
"gitHead": "955bbc130ad9b28877fd4ae8efc73a045141ce01"
|
|
71
71
|
}
|