@hyper-fetch/hono 9.9.0 → 10.1.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.
@@ -0,0 +1,333 @@
1
+ import { serve } from "@hono/node-server";
2
+ import type { ServerType } from "@hono/node-server";
3
+ import { createNodeWebSocket } from "@hono/node-ws";
4
+ import { Hono } from "hono";
5
+ import { streamSSE } from "hono/streaming";
6
+ import type { WSContext } from "hono/ws";
7
+ import type { AddressInfo } from "node:net";
8
+
9
+ export type ChatMessage = { roomId: string; text: string };
10
+ export type Notification = { userId: string; title: string };
11
+ export type Price = { symbol: string; price: number };
12
+ export type FeedEvent = { id: number; text: string };
13
+
14
+ /** `{ topic, data }` - the frame the WebsocketAdapter and the ServerSentEventsAdapter read and write by default */
15
+ type Frame = { topic: string; data: unknown };
16
+
17
+ const parseFrame = (raw: unknown): Frame | null => {
18
+ if (typeof raw !== "string") {
19
+ return null;
20
+ }
21
+ try {
22
+ const frame: unknown = JSON.parse(raw);
23
+ if (typeof frame === "object" && frame !== null && "topic" in frame && typeof frame.topic === "string") {
24
+ return { topic: frame.topic, data: "data" in frame ? frame.data : undefined };
25
+ }
26
+ } catch {
27
+ // Not JSON - the frame is ignored below
28
+ }
29
+ return null;
30
+ };
31
+
32
+ const readRoomId = (data: unknown): string | null => {
33
+ if (typeof data === "object" && data !== null && "roomId" in data && typeof data.roomId === "string") {
34
+ return data.roomId;
35
+ }
36
+ return null;
37
+ };
38
+
39
+ const readText = (data: unknown): string => {
40
+ if (typeof data === "object" && data !== null && "text" in data && typeof data.text === "string") {
41
+ return data.text;
42
+ }
43
+ return "";
44
+ };
45
+
46
+ const addTo = <K>(map: Map<K, Set<WSContext>>, key: K, ws: WSContext) => {
47
+ const group = map.get(key) ?? new Set<WSContext>();
48
+ group.add(ws);
49
+ map.set(key, group);
50
+ };
51
+
52
+ const removeFrom = <K>(map: Map<K, Set<WSContext>>, key: K, ws: WSContext) => {
53
+ const group = map.get(key);
54
+ group?.delete(ws);
55
+ if (group?.size === 0) {
56
+ map.delete(key);
57
+ }
58
+ };
59
+
60
+ type SseEvent = { id?: string; event?: string; data: string };
61
+ type SseClient = { send: (event: SseEvent) => Promise<void>; close: () => void };
62
+
63
+ /**
64
+ * A Hono app with the realtime routes the tests run against, and the server-side state the tests assert on.
65
+ * A factory, so every test starts with a fresh app and fresh state.
66
+ */
67
+ export const createRealtimeApp = () => {
68
+ const base = new Hono();
69
+ const { upgradeWebSocket, injectWebSocket, wss } = createNodeWebSocket({ app: base });
70
+
71
+ const state = {
72
+ /** Open connections of the multiplexed `/ws` route */
73
+ connections: new Set<WSContext>(),
74
+ /** Room subscriptions of the `/ws` route - joined with a `rooms/join` message */
75
+ rooms: new Map<string, Set<WSContext>>(),
76
+ /** `rooms/join` minus `rooms/leave` messages per room - a join without its leave shows up here */
77
+ joinBalance: new Map<string, number>(),
78
+ /** Connections of the per-room `/chat/:roomId` route */
79
+ roomConnections: new Map<string, Set<WSContext>>(),
80
+ /** Connections of the `/notifications` route, by the `userId` query param */
81
+ notificationConnections: new Map<string, Set<WSContext>>(),
82
+ /** Connections of the `/legacy` route, which speaks `{ type, payload }` instead of `{ topic, data }` */
83
+ legacyConnections: new Set<WSContext>(),
84
+ /** Frames the `/legacy` route received */
85
+ legacyFrames: [] as unknown[],
86
+ /** Open `/events` streams */
87
+ sseClients: new Set<SseClient>(),
88
+ /** `Last-Event-ID` header of every `/events` connection, `null` for a fresh one */
89
+ sseLastEventIds: [] as (string | null)[],
90
+ /** Events published on `/events`, replayed after `Last-Event-ID` when a stream reconnects */
91
+ sseLog: [] as (SseEvent & { id: string })[],
92
+ };
93
+
94
+ const app = base
95
+ .get("/health", (c) => c.json({ ok: true }))
96
+ // Multiplexed route: one connection, many rooms. Rooms are joined and left with messages.
97
+ .get(
98
+ "/ws",
99
+ upgradeWebSocket(() => ({
100
+ onOpen: (_event, ws) => {
101
+ state.connections.add(ws);
102
+ },
103
+ onMessage: (event, ws) => {
104
+ const frame = parseFrame(event.data);
105
+ if (!frame) {
106
+ return;
107
+ }
108
+ const roomId = readRoomId(frame.data);
109
+ if (frame.topic === "rooms/join" && roomId) {
110
+ addTo(state.rooms, roomId, ws);
111
+ state.joinBalance.set(roomId, (state.joinBalance.get(roomId) ?? 0) + 1);
112
+ ws.send(JSON.stringify({ topic: "rooms/joined", data: { roomId } }));
113
+ return;
114
+ }
115
+ if (frame.topic === "rooms/leave" && roomId) {
116
+ removeFrom(state.rooms, roomId, ws);
117
+ state.joinBalance.set(roomId, (state.joinBalance.get(roomId) ?? 0) - 1);
118
+ return;
119
+ }
120
+ if (frame.topic === "echo") {
121
+ ws.send(JSON.stringify({ topic: "echo", data: frame.data }));
122
+ return;
123
+ }
124
+ // `chat/<roomId>` - broadcast to everyone who joined the room
125
+ const [scope, room] = frame.topic.split("/");
126
+ if (scope === "chat" && room) {
127
+ const message: ChatMessage = { roomId: room, text: readText(frame.data) };
128
+ state.rooms.get(room)?.forEach((member) => {
129
+ member.send(JSON.stringify({ topic: frame.topic, data: message }));
130
+ });
131
+ }
132
+ },
133
+ onClose: (_event, ws) => {
134
+ state.connections.delete(ws);
135
+ state.rooms.forEach((_members, roomId) => removeFrom(state.rooms, roomId, ws));
136
+ },
137
+ })),
138
+ )
139
+ // Per-room route: the connection itself is the subscription
140
+ .get(
141
+ "/chat/:roomId",
142
+ upgradeWebSocket((c) => {
143
+ // The upgrade callback gets an untyped context, so the param is `string | undefined` here
144
+ const roomId = c.req.param("roomId") ?? "";
145
+ return {
146
+ onOpen: (_event, ws) => {
147
+ addTo(state.roomConnections, roomId, ws);
148
+ },
149
+ onMessage: (event) => {
150
+ const frame = parseFrame(event.data);
151
+ if (frame?.topic !== "message") {
152
+ return;
153
+ }
154
+ const message: ChatMessage = { roomId, text: readText(frame.data) };
155
+ state.roomConnections.get(roomId)?.forEach((member) => {
156
+ member.send(JSON.stringify({ topic: "message", data: message }));
157
+ });
158
+ },
159
+ onClose: (_event, ws) => {
160
+ removeFrom(state.roomConnections, roomId, ws);
161
+ },
162
+ };
163
+ }),
164
+ )
165
+ // The subscription input travels in the query params of the handshake
166
+ .get(
167
+ "/notifications",
168
+ upgradeWebSocket((c) => {
169
+ const userId = c.req.query("userId") ?? "";
170
+ return {
171
+ onOpen: (_event, ws) => {
172
+ addTo(state.notificationConnections, userId, ws);
173
+ },
174
+ onClose: (_event, ws) => {
175
+ removeFrom(state.notificationConnections, userId, ws);
176
+ },
177
+ };
178
+ }),
179
+ )
180
+ // An app with its own message shape - `{ type, payload }` - and plain-text pings
181
+ .get(
182
+ "/legacy",
183
+ upgradeWebSocket(() => ({
184
+ onOpen: (_event, ws) => {
185
+ state.legacyConnections.add(ws);
186
+ },
187
+ onMessage: (event, ws) => {
188
+ state.legacyFrames.push(typeof event.data === "string" ? JSON.parse(event.data) : event.data);
189
+ ws.send("ping");
190
+ ws.send(JSON.stringify({ type: "price", payload: { symbol: "BTC", price: 100 } }));
191
+ },
192
+ onClose: (_event, ws) => {
193
+ state.legacyConnections.delete(ws);
194
+ },
195
+ })),
196
+ )
197
+ .get("/events", (c) =>
198
+ streamSSE(c, async (stream) => {
199
+ const lastEventId = c.req.header("last-event-id") ?? null;
200
+ state.sseLastEventIds.push(lastEventId);
201
+
202
+ // Tell EventSource to come back quickly after the stream ends
203
+ await stream.write("retry: 10\n\n");
204
+ const missed = lastEventId ? state.sseLog.filter(({ id }) => Number(id) > Number(lastEventId)) : [];
205
+ // One after another - the order of the events is what the client resumes from
206
+ await missed.reduce((written, event) => written.then(() => stream.writeSSE(event)), Promise.resolve());
207
+
208
+ // The stream stays open until the client goes away or the test ends it
209
+ let client: SseClient | undefined;
210
+ await new Promise<void>((resolve) => {
211
+ client = { send: (event) => stream.writeSSE(event), close: resolve };
212
+ state.sseClients.add(client);
213
+ stream.onAbort(resolve);
214
+ });
215
+ if (client) {
216
+ state.sseClients.delete(client);
217
+ }
218
+ }),
219
+ );
220
+
221
+ /** Pushes `{ topic, data }` to every member of a `/ws` room */
222
+ const broadcast = (roomId: string, text: string) => {
223
+ const message: ChatMessage = { roomId, text };
224
+ state.rooms.get(roomId)?.forEach((ws) => ws.send(JSON.stringify({ topic: `chat/${roomId}`, data: message })));
225
+ };
226
+
227
+ const notify = (notification: Notification) => {
228
+ state.notificationConnections
229
+ .get(notification.userId)
230
+ ?.forEach((ws) => ws.send(JSON.stringify({ topic: "notification", data: notification })));
231
+ };
232
+
233
+ /** Writes an event on every open `/events` stream with the next id, so a reconnecting stream can resume after it */
234
+ const writeLogged = async (event: SseEvent) => {
235
+ const logged = { ...event, id: String(state.sseLog.length + 1) };
236
+ state.sseLog.push(logged);
237
+ await Promise.all([...state.sseClients].map((client) => client.send(logged)));
238
+ };
239
+
240
+ /** Publishes an unnamed `{ topic, data }` event on `/events` */
241
+ const publish = (frame: Frame) => writeLogged({ data: JSON.stringify(frame) });
242
+
243
+ /** Publishes a named event - `writeSSE({ event: name, data })` - with `data` written as it is */
244
+ const publishNamed = (name: string, data: string) => writeLogged({ event: name, data });
245
+
246
+ /** Sends `data` as it is - for apps whose events are not `{ topic, data }` */
247
+ const publishRaw = async (data: string) => {
248
+ await Promise.all([...state.sseClients].map((client) => client.send({ data })));
249
+ };
250
+
251
+ /** Ends every open `/events` stream - EventSource reconnects on its own with `Last-Event-ID` */
252
+ const endEventStreams = () => {
253
+ const clients = [...state.sseClients];
254
+ state.sseClients.clear();
255
+ clients.forEach((client) => client.close());
256
+ };
257
+
258
+ /** Closes every open `/ws` connection from the server side - `ws.close()` without a code sends 1005 */
259
+ const closeConnections = (code?: number) => {
260
+ state.connections.forEach((ws) => ws.close(code));
261
+ };
262
+
263
+ return {
264
+ app,
265
+ state,
266
+ wss,
267
+ injectWebSocket,
268
+ broadcast,
269
+ notify,
270
+ publish,
271
+ publishNamed,
272
+ publishRaw,
273
+ endEventStreams,
274
+ closeConnections,
275
+ };
276
+ };
277
+
278
+ /** The type the backend shares with the frontend */
279
+ export type RealtimeApp = ReturnType<typeof createRealtimeApp>["app"];
280
+
281
+ const HOST = "127.0.0.1";
282
+
283
+ /**
284
+ * Runs the realtime app on a real Node server. `stop()` drops every connection like a crashed server would,
285
+ * and `start()` afterwards listens on the same port again - a restart.
286
+ */
287
+ export const createRealtimeServer = () => {
288
+ const realtime = createRealtimeApp();
289
+ let server: ServerType | undefined;
290
+ let port = 0;
291
+
292
+ const start = () =>
293
+ new Promise<void>((resolve) => {
294
+ // An explicit IPv4 host: with "localhost" the client may resolve ::1 and reach another process that got the
295
+ // same port number on the other address family
296
+ const instance = serve({ fetch: realtime.app.fetch, port, hostname: HOST }, () => {
297
+ port = (instance.address() as AddressInfo).port;
298
+ resolve();
299
+ });
300
+ realtime.injectWebSocket(instance);
301
+ server = instance;
302
+ });
303
+
304
+ const stop = () =>
305
+ new Promise<void>((resolve, reject) => {
306
+ const instance = server;
307
+ server = undefined;
308
+ if (!instance) {
309
+ resolve();
310
+ return;
311
+ }
312
+ realtime.wss.clients.forEach((client) => client.terminate());
313
+ realtime.endEventStreams();
314
+ if ("closeAllConnections" in instance) {
315
+ instance.closeAllConnections();
316
+ }
317
+ instance.close((error) => (error ? reject(error) : resolve()));
318
+ });
319
+
320
+ return {
321
+ ...realtime,
322
+ start,
323
+ stop,
324
+ get httpUrl() {
325
+ return `http://${HOST}:${port}`;
326
+ },
327
+ get wsUrl() {
328
+ return `ws://${HOST}:${port}`;
329
+ },
330
+ };
331
+ };
332
+
333
+ export type RealtimeServer = ReturnType<typeof createRealtimeServer>;
@@ -20,6 +20,14 @@ type ExtractQuery<T> = "query" extends keyof T ? T["query"] : undefined;
20
20
  /** Hono encodes methods as `$get`, `$post`, ... on every path entry of the schema. */
21
21
  type ExtractMethodKeys<T> = Extract<keyof T, `$${string}`>;
22
22
  type StandardMethodKey = `$${(typeof METHODS)[number]}`;
23
+ /** Hono marks the routes handled by `upgradeWebSocket()` with the `ws` output format. */
24
+ type IsWebSocketEndpoint<T> = T extends {
25
+ outputFormat: "ws";
26
+ } ? true : false;
27
+ /** Method keys of a path entry that answer over HTTP - WebSocket upgrades are left out. */
28
+ type ExtractHttpMethodKeys<T> = {
29
+ [K in ExtractMethodKeys<T>]: IsWebSocketEndpoint<T[K]> extends true ? never : K;
30
+ }[ExtractMethodKeys<T>];
23
31
  /**
24
32
  * Hono stores `.all()` routes under `$all`, and `ALL` is not a method a client can send. Like Hono's
25
33
  * own client, the route gets every standard method instead. A method registered on the same path
@@ -31,9 +39,10 @@ type ExpandAllMethod<Methods> = "$all" extends keyof Methods ? Omit<Methods, "$a
31
39
  /**
32
40
  * Turns the `{ $method: endpoint }` entry of a Hono path into Hyper Fetch `Request`s. The endpoint
33
41
  * is the one `createSdk` builds from the accessors, so `:param` segments type `setParams()`.
42
+ * WebSocket upgrades are not requests, so they are skipped.
34
43
  */
35
44
  type ConvertMethods<Methods, Endpoint extends string, Client extends ClientInstance> = {
36
- [K in ExtractMethodKeys<Methods> as K extends `$${infer M extends string}` ? `$${Lowercase<M>}` : never]: Request<ExtractOutput<Methods[K]>, ExtractJson<ExtractInput<Methods[K]>>, ExtractQuery<ExtractInput<Methods[K]>>, undefined, Endpoint, Client>;
45
+ [K in ExtractHttpMethodKeys<Methods> as K extends `$${infer M extends string}` ? `$${Lowercase<M>}` : never]: Request<ExtractOutput<Methods[K]>, ExtractJson<ExtractInput<Methods[K]>>, ExtractQuery<ExtractInput<Methods[K]>>, undefined, Endpoint, Client>;
37
46
  };
38
47
  type TrimStartSlash<S extends string> = S extends `/${infer R}` ? R : S;
39
48
  /** Skips a regex pattern up to its closing brace, counting the braces nested inside it. */
@@ -75,8 +84,10 @@ type BuildNestedObject<Segments extends readonly string[], Value> = Segments ext
75
84
  } : Value;
76
85
  /** Distributes over the routes one Hono path expands to. */
77
86
  type ConvertRoutes<Methods, Routes extends string[], Client extends ClientInstance> = Routes extends string[] ? BuildNestedObject<Routes, Prettify<ConvertMethods<Methods, JoinPath<Routes>, Client>>> : never;
87
+ /** The routes one Hono path expands to - optional params give every prefix, regex patterns are dropped */
88
+ type ExpandPath<Path extends string> = ExpandOptionalParams<SplitPath<TrimStartSlash<StripPatterns<Path>>>>;
78
89
  type ConvertSchema<Schema extends Record<string, any>, Client extends ClientInstance> = UnionToIntersection<{
79
- [Path in keyof Schema & string]: ConvertRoutes<ExpandAllMethod<Schema[Path]>, ExpandOptionalParams<SplitPath<TrimStartSlash<StripPatterns<Path>>>>, Client>;
90
+ [Path in keyof Schema & string]: [ExtractHttpMethodKeys<ExpandAllMethod<Schema[Path]>>] extends [never] ? never : ConvertRoutes<ExpandAllMethod<Schema[Path]>, ExpandPath<Path>, Client>;
80
91
  }[keyof Schema & string]>;
81
92
  /**
82
93
  * Converts the type of a Hono app into a Hyper Fetch SDK schema for `createSdk`.
@@ -93,6 +104,10 @@ type ConvertSchema<Schema extends Record<string, any>, Client extends ClientInst
93
104
  * Pass the type of the app returned by your route chain, including apps mounted with
94
105
  * `app.route()` and `basePath()`. Anything that is not a Hono app resolves to `{}`.
95
106
  *
107
+ * Routes handled by `upgradeWebSocket()` are not requests, so they are left out - connect to them with a
108
+ * `Socket` and check the address with {@link HonoWebSocketPath}. Server-Sent Events routes (`streamSSE()`)
109
+ * stay in the schema as a `$get` with an untyped response: Hono types them like any other raw `Response`.
110
+ *
96
111
  * @typeParam App - The Hono app type, usually `typeof app`.
97
112
  * @typeParam Client - The client the requests belong to. `createSdk` injects its own client, so
98
113
  * this is only needed when the schema is used outside of `createSdk`.
@@ -109,5 +124,46 @@ type ConvertSchema<Schema extends Record<string, any>, Client extends ClientInst
109
124
  * ```
110
125
  */
111
126
  export type HonoAppToHyperFetch<App, Client extends ClientInstance = ClientInstance> = App extends HonoBase<any, infer S, any, any> ? Prettify<ConvertSchema<MergeUnionToRecord<S>, Client>> : {};
127
+ type ExtractAppSchema<App> = App extends HonoBase<any, infer S, any, any> ? MergeUnionToRecord<S> : never;
128
+ /** `path -> endpoint` of the routes that upgrade a GET to a WebSocket - the routes `hc` exposes as `$ws`. */
129
+ type ExtractWebSocketEndpoints<Schema> = {
130
+ [Path in keyof Schema & string as Schema[Path] extends {
131
+ $get: infer Endpoint;
132
+ } ? IsWebSocketEndpoint<Endpoint> extends true ? Path : never : never]: Schema[Path] extends {
133
+ $get: infer Endpoint;
134
+ } ? Endpoint : never;
135
+ };
136
+ type WebSocketEndpoints<App> = ExtractWebSocketEndpoints<ExtractAppSchema<App>>;
137
+ type ToSegmentPattern<Segment extends string> = Segment extends `:${string}` ? string : Segment;
138
+ /** Replaces every `:param` segment with `string`, so a path with the params filled in matches it. */
139
+ type ToRoutePattern<Segments extends string[]> = `/${JoinSegments<{
140
+ [I in keyof Segments]: ToSegmentPattern<Segments[I]>;
141
+ }>}`;
142
+ /** Every address of a Hono path, with optional params and regex patterns handled like in the HTTP schema */
143
+ type ToPathPattern<Path extends string> = ExpandPath<Path> extends infer Routes extends string[] ? Routes extends string[] ? ToRoutePattern<Routes> : never : never;
144
+ /**
145
+ * Union of the paths a `Socket` can connect to on a Hono app: every route handled by `upgradeWebSocket()`,
146
+ * including the `basePath()` and `app.route()` prefixes. A `:param` segment accepts any value, so
147
+ * `/chat/:roomId` becomes `` `/chat/${string}` `` and `/chat/42` matches it.
148
+ *
149
+ * Hono has no realtime protocol of its own, so this checks the address only. Describe the messages the
150
+ * route sends and receives with `ListenerModel` and `EmitterModel` in a `createSocketSdk` schema.
151
+ *
152
+ * @typeParam App - The Hono app type, usually `typeof app`. Anything that is not a Hono app resolves to `never`.
153
+ *
154
+ * @example
155
+ * ```ts
156
+ * // backend
157
+ * const app = new Hono().get("/chat/:roomId", upgradeWebSocket((c) => ({ onMessage() {} })));
158
+ * export type AppType = typeof app;
159
+ *
160
+ * // frontend
161
+ * const path: HonoWebSocketPath<AppType> = `/chat/${roomId}`;
162
+ * const socket = new Socket({ url: `wss://api.example.com${path}` });
163
+ * ```
164
+ */
165
+ export type HonoWebSocketPath<App> = {
166
+ [Path in keyof WebSocketEndpoints<App> & string]: ToPathPattern<Path>;
167
+ }[keyof WebSocketEndpoints<App> & string];
112
168
  export {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GAAG,CAAC,GAAG,MAAM,GAAG,aAAa,CAAC,IAAI,CAAC;CACtE,CAAC,MAAM,kBAAkB,CAAC,GAAG,CAAC,GAAG,MAAM,CAAC,CAAC"}
package/dist/index.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- export type { HonoAppToHyperFetch } from './hono.types';
1
+ export type { HonoAppToHyperFetch, HonoWebSocketPath } from './hono.types';
2
2
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,mBAAmB,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hyper-fetch/hono",
3
- "version": "9.9.0",
3
+ "version": "10.1.0",
4
4
  "description": "Turn a Hono app type into a fully typed Hyper Fetch SDK schema",
5
5
  "author": "Maciej Pyrc <maciekpyrc@gmail.com>, Kacper Skawina <kacper.skawina@gmail.com>",
6
6
  "homepage": "https://hyperfetch.bettertyped.com/",
@@ -44,6 +44,7 @@
44
44
  },
45
45
  "peerDependencies": {
46
46
  "@hyper-fetch/core": "*",
47
+ "@hyper-fetch/sockets": "*",
47
48
  "hono": ">=4"
48
49
  },
49
50
  "lint-staged": {
@@ -60,6 +61,9 @@
60
61
  ],
61
62
  "devDependencies": {
62
63
  "@hono/node-server": "^2.1.9",
63
- "hono": "^4.13.19"
64
+ "@hono/node-ws": "^1.3.1",
65
+ "eventsource": "^3.0.2",
66
+ "hono": "^4.13.19",
67
+ "ws": "^8.18.0"
64
68
  }
65
69
  }
package/src/hono.types.ts CHANGED
@@ -32,6 +32,14 @@ type ExtractMethodKeys<T> = Extract<keyof T, `$${string}`>;
32
32
 
33
33
  type StandardMethodKey = `$${(typeof METHODS)[number]}`;
34
34
 
35
+ /** Hono marks the routes handled by `upgradeWebSocket()` with the `ws` output format. */
36
+ type IsWebSocketEndpoint<T> = T extends { outputFormat: "ws" } ? true : false;
37
+
38
+ /** Method keys of a path entry that answer over HTTP - WebSocket upgrades are left out. */
39
+ type ExtractHttpMethodKeys<T> = {
40
+ [K in ExtractMethodKeys<T>]: IsWebSocketEndpoint<T[K]> extends true ? never : K;
41
+ }[ExtractMethodKeys<T>];
42
+
35
43
  /**
36
44
  * Hono stores `.all()` routes under `$all`, and `ALL` is not a method a client can send. Like Hono's
37
45
  * own client, the route gets every standard method instead. A method registered on the same path
@@ -44,9 +52,10 @@ type ExpandAllMethod<Methods> = "$all" extends keyof Methods
44
52
  /**
45
53
  * Turns the `{ $method: endpoint }` entry of a Hono path into Hyper Fetch `Request`s. The endpoint
46
54
  * is the one `createSdk` builds from the accessors, so `:param` segments type `setParams()`.
55
+ * WebSocket upgrades are not requests, so they are skipped.
47
56
  */
48
57
  type ConvertMethods<Methods, Endpoint extends string, Client extends ClientInstance> = {
49
- [K in ExtractMethodKeys<Methods> as K extends `$${infer M extends string}` ? `$${Lowercase<M>}` : never]: Request<
58
+ [K in ExtractHttpMethodKeys<Methods> as K extends `$${infer M extends string}` ? `$${Lowercase<M>}` : never]: Request<
50
59
  ExtractOutput<Methods[K]>,
51
60
  ExtractJson<ExtractInput<Methods[K]>>,
52
61
  ExtractQuery<ExtractInput<Methods[K]>>,
@@ -134,13 +143,15 @@ type ConvertRoutes<Methods, Routes extends string[], Client extends ClientInstan
134
143
  ? BuildNestedObject<Routes, Prettify<ConvertMethods<Methods, JoinPath<Routes>, Client>>>
135
144
  : never;
136
145
 
146
+ /** The routes one Hono path expands to - optional params give every prefix, regex patterns are dropped */
147
+ type ExpandPath<Path extends string> = ExpandOptionalParams<SplitPath<TrimStartSlash<StripPatterns<Path>>>>;
148
+
137
149
  type ConvertSchema<Schema extends Record<string, any>, Client extends ClientInstance> = UnionToIntersection<
138
150
  {
139
- [Path in keyof Schema & string]: ConvertRoutes<
140
- ExpandAllMethod<Schema[Path]>,
141
- ExpandOptionalParams<SplitPath<TrimStartSlash<StripPatterns<Path>>>>,
142
- Client
143
- >;
151
+ // A path served only by a WebSocket upgrade has no request to send
152
+ [Path in keyof Schema & string]: [ExtractHttpMethodKeys<ExpandAllMethod<Schema[Path]>>] extends [never]
153
+ ? never
154
+ : ConvertRoutes<ExpandAllMethod<Schema[Path]>, ExpandPath<Path>, Client>;
144
155
  }[keyof Schema & string]
145
156
  >;
146
157
 
@@ -159,6 +170,10 @@ type ConvertSchema<Schema extends Record<string, any>, Client extends ClientInst
159
170
  * Pass the type of the app returned by your route chain, including apps mounted with
160
171
  * `app.route()` and `basePath()`. Anything that is not a Hono app resolves to `{}`.
161
172
  *
173
+ * Routes handled by `upgradeWebSocket()` are not requests, so they are left out - connect to them with a
174
+ * `Socket` and check the address with {@link HonoWebSocketPath}. Server-Sent Events routes (`streamSSE()`)
175
+ * stay in the schema as a `$get` with an untyped response: Hono types them like any other raw `Response`.
176
+ *
162
177
  * @typeParam App - The Hono app type, usually `typeof app`.
163
178
  * @typeParam Client - The client the requests belong to. `createSdk` injects its own client, so
164
179
  * this is only needed when the schema is used outside of `createSdk`.
@@ -178,3 +193,60 @@ export type HonoAppToHyperFetch<App, Client extends ClientInstance = ClientInsta
178
193
  // Match `HonoBase` with all four generics: `.route()` returns `HonoBase<E, S, BasePath, CurrentPath>`,
179
194
  // so matching against `Hono<E, S, BasePath>` fails to infer the schema and resolves to `{}`.
180
195
  App extends HonoBase<any, infer S, any, any> ? Prettify<ConvertSchema<MergeUnionToRecord<S>, Client>> : {};
196
+
197
+ /* -------------------------------------------------------------------------------------------------
198
+ * WebSocket routes
199
+ * -----------------------------------------------------------------------------------------------*/
200
+
201
+ type ExtractAppSchema<App> = App extends HonoBase<any, infer S, any, any> ? MergeUnionToRecord<S> : never;
202
+
203
+ /** `path -> endpoint` of the routes that upgrade a GET to a WebSocket - the routes `hc` exposes as `$ws`. */
204
+ type ExtractWebSocketEndpoints<Schema> = {
205
+ [Path in keyof Schema & string as Schema[Path] extends { $get: infer Endpoint }
206
+ ? IsWebSocketEndpoint<Endpoint> extends true
207
+ ? Path
208
+ : never
209
+ : never]: Schema[Path] extends { $get: infer Endpoint } ? Endpoint : never;
210
+ };
211
+
212
+ type WebSocketEndpoints<App> = ExtractWebSocketEndpoints<ExtractAppSchema<App>>;
213
+
214
+ type ToSegmentPattern<Segment extends string> = Segment extends `:${string}` ? string : Segment;
215
+
216
+ /** Replaces every `:param` segment with `string`, so a path with the params filled in matches it. */
217
+ type ToRoutePattern<Segments extends string[]> = `/${JoinSegments<{
218
+ [I in keyof Segments]: ToSegmentPattern<Segments[I]>;
219
+ }>}`;
220
+
221
+ /** Every address of a Hono path, with optional params and regex patterns handled like in the HTTP schema */
222
+ type ToPathPattern<Path extends string> =
223
+ ExpandPath<Path> extends infer Routes extends string[]
224
+ ? Routes extends string[]
225
+ ? ToRoutePattern<Routes>
226
+ : never
227
+ : never;
228
+
229
+ /**
230
+ * Union of the paths a `Socket` can connect to on a Hono app: every route handled by `upgradeWebSocket()`,
231
+ * including the `basePath()` and `app.route()` prefixes. A `:param` segment accepts any value, so
232
+ * `/chat/:roomId` becomes `` `/chat/${string}` `` and `/chat/42` matches it.
233
+ *
234
+ * Hono has no realtime protocol of its own, so this checks the address only. Describe the messages the
235
+ * route sends and receives with `ListenerModel` and `EmitterModel` in a `createSocketSdk` schema.
236
+ *
237
+ * @typeParam App - The Hono app type, usually `typeof app`. Anything that is not a Hono app resolves to `never`.
238
+ *
239
+ * @example
240
+ * ```ts
241
+ * // backend
242
+ * const app = new Hono().get("/chat/:roomId", upgradeWebSocket((c) => ({ onMessage() {} })));
243
+ * export type AppType = typeof app;
244
+ *
245
+ * // frontend
246
+ * const path: HonoWebSocketPath<AppType> = `/chat/${roomId}`;
247
+ * const socket = new Socket({ url: `wss://api.example.com${path}` });
248
+ * ```
249
+ */
250
+ export type HonoWebSocketPath<App> = {
251
+ [Path in keyof WebSocketEndpoints<App> & string]: ToPathPattern<Path>;
252
+ }[keyof WebSocketEndpoints<App> & string];
package/src/index.ts CHANGED
@@ -1 +1 @@
1
- export type { HonoAppToHyperFetch } from "./hono.types";
1
+ export type { HonoAppToHyperFetch, HonoWebSocketPath } from "./hono.types";
package/vite.config.ts CHANGED
@@ -23,6 +23,8 @@ export default defineConfig({
23
23
  test: {
24
24
  alias: {
25
25
  "@hyper-fetch/core": path.resolve(__dirname, "../core/src/index.ts"),
26
+ "@hyper-fetch/react": path.resolve(__dirname, "../react/src/index.ts"),
27
+ "@hyper-fetch/sockets": path.resolve(__dirname, "../sockets/src/index.ts"),
26
28
  },
27
29
  coverage: {
28
30
  include: ["src/**/*.ts"],