spooder 4.2.9 → 4.2.10

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
@@ -728,6 +728,16 @@ server.dir('/static', '/static', (file_path, file, stat, request, url) => {
728
728
  > [!NOTE]
729
729
  > The directory handler function is only called for files that exist on disk - including directories.
730
730
 
731
+ Asynchronous directory handlers are supported and will be awaited.
732
+
733
+ ```js
734
+ server.dir('/static', '/static', async (file_path, file) => {
735
+ let file_contents = await file.text();
736
+ // do something with file_contents
737
+ return file_contents;
738
+ });
739
+ ```
740
+
731
741
  <a id="api-routing-server-sse"></a>
732
742
  ## API > Routing > Server-Sent Events
733
743
 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "spooder",
3
3
  "type": "module",
4
- "version": "4.2.9",
4
+ "version": "4.2.10",
5
5
  "exports": {
6
6
  ".": {
7
7
  "bun": "./src/api.ts",
@@ -10,8 +10,7 @@
10
10
  },
11
11
  "module": "./src/api.ts",
12
12
  "devDependencies": {
13
- "@types/node": "^20.0.0",
14
- "bun-types": "^0.5.0"
13
+ "@types/bun": "^1.0.5"
15
14
  },
16
15
  "bin": {
17
16
  "spooder": "./src/cli.ts"
package/src/api.d.ts CHANGED
@@ -1,6 +1,4 @@
1
1
  /// <reference types="node" />
2
- /// <reference types="bun-types" />
3
- /// <reference types="node" />
4
2
  /// <reference types="node" />
5
3
  import fs from 'node:fs/promises';
6
4
  import { Blob } from 'node:buffer';
package/src/api.ts CHANGED
@@ -331,7 +331,7 @@ function route_directory(route_path: string, dir: string, handler: DirHandler):
331
331
  const file_stat = await fs.stat(file_path);
332
332
  const bun_file = Bun.file(file_path);
333
333
 
334
- return handler(file_path, bun_file, file_stat, req, url);
334
+ return await handler(file_path, bun_file, file_stat, req, url);
335
335
  } catch (e) {
336
336
  const err = e as NodeJS.ErrnoException;
337
337
  if (err?.code === 'ENOENT')
@@ -385,7 +385,8 @@ export function serve(port: number) {
385
385
 
386
386
  // Content-type/content-length are automatically set for blobs.
387
387
  if (response instanceof Blob)
388
- return new Response(response as Blob, { status: status_code });
388
+ // @ts-ignore Response does accept Blob in Bun, typing disagrees.
389
+ return new Response(response, { status: status_code });
389
390
 
390
391
  // Status codes can be returned from some handlers.
391
392
  if (return_status_code && typeof response === 'number')
@@ -559,14 +560,16 @@ export function serve(port: number) {
559
560
 
560
561
  const queue = Array<string>();
561
562
  const stream = new ReadableStream({
563
+ // @ts-ignore Bun implements a "direct" mode which does not exist in the spec.
562
564
  type: 'direct',
563
565
 
564
- async pull(controller: ReadableStreamDirectController) {
565
- stream_controller = controller;
566
+ async pull(controller) {
567
+ // @ts-ignore `controller` in "direct" mode is ReadableStreamDirectController.
568
+ stream_controller = controller as ReadableStreamDirectController;
566
569
  while (!req.signal.aborted) {
567
570
  if (queue.length > 0) {
568
- controller.write(queue.shift()!);
569
- controller.flush();
571
+ stream_controller.write(queue.shift()!);
572
+ stream_controller.flush();
570
573
  } else {
571
574
  await Bun.sleep(50);
572
575
  }
package/src/cli.ts CHANGED
@@ -64,7 +64,7 @@ async function start_server() {
64
64
  function capture_stream(stream: ReadableStream, output: NodeJS.WritableStream) {
65
65
  const reader = stream.getReader();
66
66
 
67
- reader.read().then(function read_chunk(chunk: ReadableStreamDefaultReadResult<Uint8Array>) {
67
+ reader.read().then(function read_chunk(chunk) {
68
68
  if (chunk.done)
69
69
  return;
70
70