@sigil-dev/grimoire 0.9.18 → 0.9.20

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/index.ts CHANGED
@@ -18,6 +18,12 @@ export type {
18
18
  RequestEvent,
19
19
  ResolveFunction,
20
20
  } from "./src/server/hooks";
21
+ export {
22
+ type CachedFn,
23
+ type CachedOptions,
24
+ cached,
25
+ cachedBy,
26
+ } from "./src/server/cached";
21
27
  export { clientAddress } from "./src/server/client-address";
22
28
  export { createHooks, sequence } from "./src/server/hooks";
23
29
  export type {
package/package.json CHANGED
@@ -11,7 +11,7 @@
11
11
  "module": "index.ts",
12
12
  "type": "module",
13
13
  "private": false,
14
- "version": "0.9.18",
14
+ "version": "0.9.20",
15
15
  "exports": {
16
16
  ".": "./index.ts",
17
17
  "./server": "./server.ts",
@@ -30,8 +30,8 @@
30
30
  "test": "bun test"
31
31
  },
32
32
  "dependencies": {
33
- "@sigil-dev/compiler": "0.9.18",
34
- "@sigil-dev/runtime": "0.9.18",
33
+ "@sigil-dev/compiler": "0.9.20",
34
+ "@sigil-dev/runtime": "0.9.20",
35
35
  "vite": "^8.0.16"
36
36
  },
37
37
  "peerDependencies": {
@@ -244,7 +244,6 @@ function generateTypesForGroup(group: RouteGroup, outFileDir: string): string {
244
244
  if (group.server) {
245
245
  const imp = toImportPath(outFileDir, group.server.filePath);
246
246
  lines.push(
247
- `import type { ServerWebSocket } from "bun";`,
248
247
  `type _SRV = typeof import("${imp}");`,
249
248
  `type _HttpMethods = "GET" | "POST" | "PUT" | "PATCH" | "DELETE" | "HEAD" | "OPTIONS";`,
250
249
  `type _ServerKeys = Extract<keyof _SRV, _HttpMethods>;`,
@@ -269,11 +268,23 @@ function generateTypesForGroup(group: RouteGroup, outFileDir: string): string {
269
268
  ` : {};`,
270
269
  `export type WsData = { params: Params } & Omit<_UpgradeReturn, "__handler">;`,
271
270
  ``,
271
+ `/** The parts of Bun's ServerWebSocket a handler uses, so this file needs no Bun types installed. */`,
272
+ `export type SocketOf<D> = {`,
273
+ ` readonly data: D;`,
274
+ ` readonly readyState: number;`,
275
+ ` readonly remoteAddress: string;`,
276
+ ` send(data: string | ArrayBufferView | ArrayBuffer, compress?: boolean): number;`,
277
+ ` close(code?: number, reason?: string): void;`,
278
+ ` subscribe(topic: string): void;`,
279
+ ` unsubscribe(topic: string): void;`,
280
+ ` isSubscribed(topic: string): boolean;`,
281
+ ` publish(topic: string, data: string | ArrayBufferView | ArrayBuffer, compress?: boolean): number;`,
282
+ `};`,
272
283
  `export type WebSocketHandler = {`,
273
- ` open?(ws: ServerWebSocket<WsData>): void | Promise<void>;`,
274
- ` message?(ws: ServerWebSocket<WsData>, data: string | Buffer): void | Promise<void>;`,
275
- ` close?(ws: ServerWebSocket<WsData>, code: number, reason?: string): void | Promise<void>;`,
276
- ` drain?(ws: ServerWebSocket<WsData>): void | Promise<void>;`,
284
+ ` open?(ws: SocketOf<WsData>): void | Promise<void>;`,
285
+ ` message?(ws: SocketOf<WsData>, data: string | Uint8Array): void | Promise<void>;`,
286
+ ` close?(ws: SocketOf<WsData>, code: number, reason?: string): void | Promise<void>;`,
287
+ ` drain?(ws: SocketOf<WsData>): void | Promise<void>;`,
277
288
  `};`,
278
289
  "",
279
290
  );
@@ -594,6 +594,22 @@ export async function comment() {
594
594
  }`,
595
595
  );
596
596
 
597
+ // a +server.ts route: its types must compile without Bun's types installed
598
+ const chatDir = join(tscDir, "src", "routes", "chat");
599
+ await mkdir(chatDir, { recursive: true });
600
+ await writeFile(
601
+ join(chatDir, "+server.ts"),
602
+ `export function GET() { return new Response("ok"); }
603
+ export function upgrade() { return { room: "lobby" }; }`,
604
+ );
605
+ await writeFile(
606
+ join(chatDir, "check.ts"),
607
+ `import type { WebSocketHandler } from "./$types";
608
+ export const websocket: WebSocketHandler = {
609
+ message(ws, data) { ws.send(\`\${ws.data.room}: \${String(data)}\`); },
610
+ };`,
611
+ );
612
+
597
613
  // File that uses the generated types — must live in the route dir for ./$types to resolve
598
614
  await writeFile(
599
615
  join(routeDir, "check.ts"),