@adonisjs/transmit
Advanced tools
Comparing version 0.5.0 to 0.5.1
@@ -0,1 +1,2 @@ | ||
import { Stream } from './stream.js'; | ||
import type { HttpContext } from '@adonisjs/core/http'; | ||
@@ -30,7 +31,7 @@ import type { Transport } from '@rlanz/bus/types/main'; | ||
#private; | ||
constructor(config: TransmitConfig, transport: Transport | null); | ||
constructor(config: TransmitConfig, transport?: Transport | null); | ||
/** | ||
* Creates and register a new stream for the given request and pipes it to the response. | ||
*/ | ||
$createStream(ctx: HttpContext): void; | ||
$createStream(ctx: HttpContext): Stream; | ||
/** | ||
@@ -37,0 +38,0 @@ * Store the authorization callback for the given channel. |
@@ -61,6 +61,6 @@ /* | ||
else if (type === TransportMessageType.Subscribe) { | ||
void this.#storage.addChannelToStream(message.payload.uid, message.channel); | ||
void this.#storage.addChannelToStream(payload.uid, channel); | ||
} | ||
else if (type === TransportMessageType.Unsubscribe) { | ||
void this.#storage.removeChannelFromStream(message.payload.uid, message.channel); | ||
void this.#storage.removeChannelFromStream(payload.uid, channel); | ||
} | ||
@@ -80,2 +80,5 @@ }); | ||
const { request, response } = ctx; | ||
if (!request.input('uid')) { | ||
throw new Error('Missing required field "uid" in the request body'); | ||
} | ||
const stream = new Stream(request.input('uid'), request.request); | ||
@@ -90,2 +93,3 @@ stream.pipe(response.response, undefined, response.getHeaders()); | ||
response.stream(stream); | ||
return stream; | ||
} | ||
@@ -92,0 +96,0 @@ /** |
{ | ||
"name": "@adonisjs/transmit", | ||
"description": "A Server-Sent-Event module bringing real-time capabilities to AdonisJS.", | ||
"version": "0.5.0", | ||
"version": "0.5.1", | ||
"engines": { | ||
@@ -44,3 +44,3 @@ "node": ">=20.11.1" | ||
"@poppinss/utils": "^6.7.2", | ||
"@rlanz/bus": "^0.1.0", | ||
"@rlanz/bus": "^0.2.0", | ||
"emittery": "^1.0.3" | ||
@@ -57,4 +57,4 @@ }, | ||
"@japa/runner": "3.1.1", | ||
"@swc/core": "1.4.6", | ||
"@types/node": "^20.11.25", | ||
"@swc/core": "1.4.11", | ||
"@types/node": "^20.11.30", | ||
"c8": "^9.1.0", | ||
@@ -64,6 +64,6 @@ "copyfiles": "^2.4.1", | ||
"eslint": "^8.57.0", | ||
"np": "^10.0.0", | ||
"np": "^10.0.2", | ||
"prettier": "^3.2.5", | ||
"ts-node": "^10.9.2", | ||
"typescript": "^5.4.2" | ||
"typescript": "^5.4.3" | ||
}, | ||
@@ -70,0 +70,0 @@ "peerDependencies": { |
@@ -87,3 +87,3 @@ /* | ||
constructor(config: TransmitConfig, transport: Transport | null) { | ||
constructor(config: TransmitConfig, transport?: Transport | null) { | ||
this.#config = config | ||
@@ -104,5 +104,5 @@ this.#storage = new StreamChannelRepository() | ||
} else if (type === TransportMessageType.Subscribe) { | ||
void this.#storage.addChannelToStream(message.payload.uid, message.channel) | ||
void this.#storage.addChannelToStream(payload.uid, channel) | ||
} else if (type === TransportMessageType.Unsubscribe) { | ||
void this.#storage.removeChannelFromStream(message.payload.uid, message.channel) | ||
void this.#storage.removeChannelFromStream(payload.uid, channel) | ||
} | ||
@@ -125,5 +125,9 @@ } | ||
*/ | ||
$createStream(ctx: HttpContext): void { | ||
$createStream(ctx: HttpContext): Stream { | ||
const { request, response } = ctx | ||
if (!request.input('uid')) { | ||
throw new Error('Missing required field "uid" in the request body') | ||
} | ||
const stream = new Stream(request.input('uid'), request.request) | ||
@@ -142,2 +146,4 @@ stream.pipe(response.response, undefined, response.getHeaders()) | ||
response.stream(stream) | ||
return stream | ||
} | ||
@@ -144,0 +150,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
73369
57
1786
+ Added@rlanz/bus@0.2.0(transitive)
- Removed@rlanz/bus@0.1.1(transitive)
Updated@rlanz/bus@^0.2.0