spooder 5.1.8 → 5.1.9

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
@@ -1191,10 +1191,11 @@ Register a route which handles websocket connections.
1191
1191
  server.websocket('/path/to/websocket', {
1192
1192
  // all of these handlers are OPTIONAL
1193
1193
 
1194
- accept: (req) => {
1194
+ accept: (req, url) => {
1195
1195
  // validates a request before it is upgraded
1196
1196
  // returns HTTP 401 if FALSE is returned
1197
1197
  // allows you to check headers/authentication
1198
+ // url parameter contains query parameters from route
1198
1199
 
1199
1200
  // if an OBJECT is returned, the object will
1200
1201
  // be accessible on the websocket as ws.data.*
@@ -1212,7 +1213,7 @@ server.websocket('/path/to/websocket', {
1212
1213
 
1213
1214
  message: (ws, message) => {
1214
1215
  // called when a websocket message is received
1215
- // message is a string
1216
+ // message is a string or buffer
1216
1217
  },
1217
1218
 
1218
1219
  message_json: (ws, data) => {
package/bun.lock CHANGED
@@ -4,7 +4,7 @@
4
4
  "": {
5
5
  "name": "spooder",
6
6
  "devDependencies": {
7
- "@types/bun": "^1.2.16",
7
+ "@types/bun": "^1.2.20",
8
8
  },
9
9
  "optionalDependencies": {
10
10
  "mysql2": "^3.11.0",
@@ -12,15 +12,15 @@
12
12
  },
13
13
  },
14
14
  "packages": {
15
- "@types/bun": ["@types/bun@1.2.20", "", { "dependencies": { "bun-types": "1.2.20" } }, "sha512-dX3RGzQ8+KgmMw7CsW4xT5ITBSCrSbfHc36SNT31EOUg/LA9JWq0VDdEXDRSe1InVWpd2yLUM1FUF/kEOyTzYA=="],
15
+ "@types/bun": ["@types/bun@1.2.21", "", { "dependencies": { "bun-types": "1.2.21" } }, "sha512-NiDnvEqmbfQ6dmZ3EeUO577s4P5bf4HCTXtI6trMc6f6RzirY5IrF3aIookuSpyslFzrnvv2lmEWv5HyC1X79A=="],
16
16
 
17
17
  "@types/node": ["@types/node@24.3.0", "", { "dependencies": { "undici-types": "~7.10.0" } }, "sha512-aPTXCrfwnDLj4VvXrm+UUCQjNEvJgNA8s5F1cvwQU+3KNltTOkBm1j30uNLyqqPNe7gE3KFzImYoZEfLhp4Yow=="],
18
18
 
19
- "@types/react": ["@types/react@19.1.10", "", { "dependencies": { "csstype": "^3.0.2" } }, "sha512-EhBeSYX0Y6ye8pNebpKrwFJq7BoQ8J5SO6NlvNwwHjSj6adXJViPQrKlsyPw7hLBLvckEMO1yxeGdR82YBBlDg=="],
19
+ "@types/react": ["@types/react@19.1.12", "", { "dependencies": { "csstype": "^3.0.2" } }, "sha512-cMoR+FoAf/Jyq6+Df2/Z41jISvGZZ2eTlnsaJRptmZ76Caldwy1odD4xTr/gNV9VLj0AWgg/nmkevIyUfIIq5w=="],
20
20
 
21
21
  "aws-ssl-profiles": ["aws-ssl-profiles@1.1.2", "", {}, "sha512-NZKeq9AfyQvEeNlN0zSYAaWrmBffJh3IELMZfRpJVWgrpEbtEpnjvzqBPf+mxoI287JohRDoa+/nsfqqiZmF6g=="],
22
22
 
23
- "bun-types": ["bun-types@1.2.20", "", { "dependencies": { "@types/node": "*" }, "peerDependencies": { "@types/react": "^19" } }, "sha512-pxTnQYOrKvdOwyiyd/7sMt9yFOenN004Y6O4lCcCUoKVej48FS5cvTw9geRaEcB9TsDZaJKAxPTVvi8tFsVuXA=="],
23
+ "bun-types": ["bun-types@1.2.21", "", { "dependencies": { "@types/node": "*" }, "peerDependencies": { "@types/react": "^19" } }, "sha512-sa2Tj77Ijc/NTLS0/Odjq/qngmEPZfbfnOERi0KRUYhT9R8M4VBioWVmMWE5GrYbKMc+5lVybXygLdibHaqVqw=="],
24
24
 
25
25
  "csstype": ["csstype@3.1.3", "", {}, "sha512-M1uQkMl8rQK/szD0LNhtqxIPLpimGm8sOBwU7lLnCpSbTyY3yeU1Vc7l4KT5zT4s/yOxHH5O7tIuuLOCnLADRw=="],
26
26
 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "spooder",
3
3
  "type": "module",
4
- "version": "5.1.8",
4
+ "version": "5.1.9",
5
5
  "module": "./src/api.ts",
6
6
  "bin": {
7
7
  "spooder": "./src/cli.ts"
@@ -15,7 +15,7 @@
15
15
  }
16
16
  },
17
17
  "devDependencies": {
18
- "@types/bun": "^1.2.16"
18
+ "@types/bun": "^1.2.20"
19
19
  },
20
20
  "optionalDependencies": {
21
21
  "mysql2": "^3.11.0"
package/src/api.ts CHANGED
@@ -1011,7 +1011,7 @@ function print_request_info(req: Request, res: Response, url: URL, request_time:
1011
1011
  // format request time based on range (0-100ms is green, 100-500ms is yellow, 500ms+ is red), use ansi colors.
1012
1012
  const time_fmt = request_time < 100 ? '\x1b[32m' : request_time < 500 ? '\x1b[33m' : '\x1b[31m';
1013
1013
  const request_time_str = time_fmt + request_time + 'ms\x1b[0m';
1014
-
1014
+
1015
1015
  log_spooder(`[${status_code}] {${req.method}} ${url.pathname} ${search_params} [{${request_time_str}}]`);
1016
1016
  return res;
1017
1017
  }
@@ -1059,8 +1059,8 @@ async function resolve_bootstrap_content(content: string | BunFile): Promise<str
1059
1059
 
1060
1060
  type WebsocketAcceptReturn = object | boolean;
1061
1061
  type WebsocketHandlers = {
1062
- accept?: (req: Request) => WebsocketAcceptReturn | Promise<WebsocketAcceptReturn>,
1063
- message?: (ws: WebSocket, message: string) => void,
1062
+ accept?: (req: Request, url: URL) => WebsocketAcceptReturn | Promise<WebsocketAcceptReturn>,
1063
+ message?: (ws: WebSocket, message: string | Buffer) => void,
1064
1064
  message_json?: (ws: WebSocket, message: JsonSerializable) => void,
1065
1065
  open?: (ws: WebSocket) => void,
1066
1066
  close?: (ws: WebSocket, code: number, reason: string) => void,
@@ -1347,10 +1347,10 @@ export function http_serve(port: number, hostname?: string) {
1347
1347
 
1348
1348
  /** Add a route to upgrade connections to websockets. */
1349
1349
  websocket: (path: string, handlers: WebsocketHandlers): void => {
1350
- routes.push([path.split('/'), async (req: Request) => {
1350
+ routes.push([path.split('/'), async (req: Request, url: URL) => {
1351
1351
  let context_data = undefined;
1352
1352
  if (handlers.accept) {
1353
- const res = await handlers.accept(req);
1353
+ const res = await handlers.accept(req, url);
1354
1354
 
1355
1355
  if (typeof res === 'object') {
1356
1356
  context_data = res;
package/tsconfig.json CHANGED
@@ -16,8 +16,7 @@
16
16
  "declaration": true,
17
17
  "allowJs": true,
18
18
  "types": [
19
- "node",
20
- "bun-types" // add Bun global
19
+ "bun"
21
20
  ]
22
21
  }
23
22
  }