@basaltkit/express 1.1.0 → 1.2.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.
Files changed (2) hide show
  1. package/dist/index.js +14 -1
  2. package/package.json +3 -3
package/dist/index.js CHANGED
@@ -4,7 +4,11 @@ import {
4
4
  HttpServerCollector,
5
5
  HTTP_SERVER,
6
6
  runRoute,
7
- toErrorResponse
7
+ toErrorResponse,
8
+ isSseResponse,
9
+ sseProducerOf,
10
+ driveSse,
11
+ SSE_HEADERS
8
12
  } from "@basaltkit/http";
9
13
  import express from "express";
10
14
  var EXPRESS = createToken("express");
@@ -63,6 +67,15 @@ function basaltHandler(definition, container, enrichers, guards) {
63
67
  enrichers,
64
68
  guards
65
69
  });
70
+ if (isSseResponse(result)) {
71
+ res.writeHead(200, SSE_HEADERS);
72
+ await driveSse(sseProducerOf(result), {
73
+ write: (frame) => void res.write(frame),
74
+ end: () => res.end(),
75
+ onClose: (listener) => req.on("close", listener)
76
+ });
77
+ return;
78
+ }
66
79
  if (!reply.sent) reply.send(result);
67
80
  } catch (error) {
68
81
  const { status, body } = toErrorResponse(error);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@basaltkit/express",
3
- "version": "1.1.0",
3
+ "version": "1.2.0",
4
4
  "description": "Express adapter for Basalt: run the same typed routes, enrichers and guards on Express that you would on Fastify or Hono.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -14,8 +14,8 @@
14
14
  "dist"
15
15
  ],
16
16
  "dependencies": {
17
- "@basaltkit/core": "^1.0.0",
18
- "@basaltkit/http": "^1.5.0"
17
+ "@basaltkit/core": "^1.1.0",
18
+ "@basaltkit/http": "^1.7.0"
19
19
  },
20
20
  "peerDependencies": {
21
21
  "express": "^4.19.0 || ^5.0.0"