fastify-sse-v2
Advanced tools
Comparing version 1.0.5 to 2.0.0
@@ -9,5 +9,5 @@ # Changelog | ||
## [1.0.5] | ||
## Fixed | ||
- use response stream directly | ||
## [2.0.0] | ||
## Feature | ||
- fastify v3 support | ||
@@ -30,4 +30,4 @@ ## [1.0.4] | ||
[Unreleased]: https://github.com/nodefactoryio/fastify-sse-v2/compare/v1.0.5...HEAD | ||
[1.0.5]: https://github.com/nodefactoryio/fastify-sse-v2/compare/v1.0.4...v1.0.5 | ||
[Unreleased]: https://github.com/nodefactoryio/fastify-sse-v2/compare/v2.0.0...HEAD | ||
[2.0.0]: https://github.com/nodefactoryio/fastify-sse-v2/compare/v1.0.4...v2.0.0 | ||
[1.0.4]: https://github.com/nodefactoryio/fastify-sse-v2/compare/v1.0.3...v1.0.4 | ||
@@ -34,0 +34,0 @@ [1.0.3]: https://github.com/nodefactoryio/fastify-sse-v2/compare/v1.0.2...v1.0.3 |
/// <reference types="node" /> | ||
import { IncomingMessage, Server, ServerResponse } from "http"; | ||
import { Plugin } from "fastify"; | ||
import { SsePluginOptions } from "./types"; | ||
export declare const FastifySSEPlugin: Plugin<Server, IncomingMessage, ServerResponse, SsePluginOptions>; | ||
export declare const FastifySSEPlugin: import("fastify").FastifyPluginCallback<import("./types").SsePluginOptions, import("http").Server>; | ||
declare module "fastify" { | ||
@@ -25,5 +22,5 @@ interface EventMessage { | ||
} | ||
interface FastifyReply<HttpResponse> { | ||
interface FastifyReply { | ||
sse(source: AsyncIterable<EventMessage>): void; | ||
} | ||
} |
@@ -16,5 +16,5 @@ "use strict"; | ||
name: "fastify-sse-v2", | ||
fastify: "2.x" | ||
fastify: "3.x" | ||
}); | ||
exports.FastifySSEPlugin = FastifySSEPlugin; | ||
//# sourceMappingURL=index.js.map |
@@ -1,5 +0,3 @@ | ||
/// <reference types="node" /> | ||
import { Plugin } from "fastify"; | ||
import { IncomingMessage, Server, ServerResponse } from "http"; | ||
import { FastifyPluginAsync } from "fastify"; | ||
import { SsePluginOptions } from "./types"; | ||
export declare const plugin: Plugin<Server, IncomingMessage, ServerResponse, SsePluginOptions>; | ||
export declare const plugin: FastifyPluginAsync<SsePluginOptions>; |
@@ -16,7 +16,8 @@ "use strict"; | ||
instance.decorateReply("sse", function (source) { | ||
this.res.write((0, _sse.serializeSSEEvent)({ | ||
const outputStream = this.raw; | ||
outputStream.write((0, _sse.serializeSSEEvent)({ | ||
retry: options.retryDelay || 3000 | ||
})); | ||
this.type("text/event-stream").header("Connection", "keep-alive").header("Cache-Control", "no-cache"); | ||
(0, _itToStream.default)((0, _sse.transformAsyncIterable)(source)).pipe(this.res); | ||
(0, _itToStream.default)((0, _sse.transformAsyncIterable)(source)).pipe(outputStream); | ||
}); | ||
@@ -23,0 +24,0 @@ }; |
{ | ||
"name": "fastify-sse-v2", | ||
"version": "1.0.5", | ||
"version": "2.0.0", | ||
"description": "Fastify plugin for sending server side events.", | ||
@@ -12,3 +12,3 @@ "main": "lib/index.js", | ||
"scripts": { | ||
"test": "mocha -r ts-node/register test/**/*.spec.ts ", | ||
"test": "mocha -r ts-node/register test/**/*.spec.ts", | ||
"clean": "rm -rf lib", | ||
@@ -48,2 +48,3 @@ "lint": "eslint --ext .ts src/", | ||
"chai": "^4.2.0", | ||
"cross-env": "^7.0.2", | ||
"es6-promisify": "^6.1.0", | ||
@@ -53,3 +54,3 @@ "eslint": "5.16.0", | ||
"eventsource": "^1.0.7", | ||
"fastify": "^2.15.2", | ||
"fastify": "3.1.1", | ||
"it-pushable": "^1.4.0", | ||
@@ -62,8 +63,8 @@ "mocha": "^6.1.4", | ||
"dependencies": { | ||
"fastify-plugin": "^1.6.1", | ||
"fastify-plugin": "2.0.1", | ||
"it-to-stream": "^0.1.1" | ||
}, | ||
"peerDependencies": { | ||
"fastify": "2.x" | ||
"fastify": "3.x" | ||
} | ||
} |
@@ -7,2 +7,4 @@ # Fastify SSE Plugin | ||
For fastify@2.x use fastify-sse-v2@1.x! | ||
### How to use? | ||
@@ -9,0 +11,0 @@ |
import fastifyPlugin from "fastify-plugin"; | ||
import {plugin} from "./plugin"; | ||
import {IncomingMessage, Server, ServerResponse} from "http"; | ||
import {Plugin} from "fastify"; | ||
import {SsePluginOptions} from "./types"; | ||
export const FastifySSEPlugin: Plugin<Server, IncomingMessage, ServerResponse, SsePluginOptions> | ||
= fastifyPlugin(plugin, { | ||
name: "fastify-sse-v2", | ||
fastify: "2.x", | ||
}); | ||
export const FastifySSEPlugin = fastifyPlugin(plugin, { | ||
name: "fastify-sse-v2", | ||
fastify: "3.x", | ||
}); | ||
@@ -37,5 +33,5 @@ declare module "fastify" { | ||
interface FastifyReply<HttpResponse> { | ||
interface FastifyReply { | ||
sse(source: AsyncIterable<EventMessage>): void; | ||
} | ||
} | ||
} |
@@ -1,18 +0,19 @@ | ||
import {EventMessage, FastifyReply, Plugin} from "fastify"; | ||
import {IncomingMessage, Server, ServerResponse} from "http"; | ||
import {EventMessage, FastifyPluginAsync, FastifyReply} from "fastify"; | ||
import {SsePluginOptions} from "./types"; | ||
import {Writable} from "stream"; | ||
import {serializeSSEEvent, transformAsyncIterable} from "./sse"; | ||
import toStream from "it-to-stream"; | ||
export const plugin: Plugin<Server, IncomingMessage, ServerResponse, SsePluginOptions> = | ||
export const plugin: FastifyPluginAsync<SsePluginOptions> = | ||
async function (instance, options): Promise<void> { | ||
instance.decorateReply( | ||
"sse", | ||
function (this: FastifyReply<ServerResponse>, source: AsyncIterable<EventMessage>): void { | ||
this.res.write(serializeSSEEvent({retry: options.retryDelay || 3000})); | ||
function (this: FastifyReply, source: AsyncIterable<EventMessage>): void { | ||
const outputStream: Writable = this.raw; | ||
outputStream.write(serializeSSEEvent({retry: options.retryDelay || 3000})); | ||
this.type("text/event-stream") | ||
.header("Connection", "keep-alive") | ||
.header("Cache-Control", "no-cache"); | ||
toStream(transformAsyncIterable(source)).pipe(this.res); | ||
toStream(transformAsyncIterable(source)).pipe(outputStream); | ||
}); | ||
}; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
65
16860
25
189
+ Added@fastify/ajv-compiler@1.1.0(transitive)
+ Added@fastify/error@2.0.0(transitive)
+ Addedajv@8.17.1(transitive)
+ Addedavvio@7.2.5(transitive)
+ Addedcookie@0.5.0(transitive)
+ Addedfast-content-type-parse@1.1.0(transitive)
+ Addedfast-json-stringify@2.7.13(transitive)
+ Addedfast-redact@3.5.0(transitive)
+ Addedfast-uri@3.0.3(transitive)
+ Addedfastify@3.29.5(transitive)
+ Addedfastify-plugin@2.0.1(transitive)
+ Addedfind-my-way@4.5.1(transitive)
+ Addedjson-schema-traverse@1.0.0(transitive)
+ Addedlight-my-request@4.12.0(transitive)
+ Addedpino@6.14.0(transitive)
+ Addedpino-std-serializers@3.2.0(transitive)
+ Addedprocess-warning@1.0.0(transitive)
+ Addedqueue-microtask@1.2.3(transitive)
+ Addedquick-format-unescaped@4.0.4(transitive)
+ Addedrequire-from-string@2.0.2(transitive)
+ Addedsemver@7.6.3(transitive)
+ Addedsonic-boom@1.4.1(transitive)
+ Addedtiny-lru@8.0.2(transitive)
- Removedavvio@6.5.0(transitive)
- Removedcookie@0.4.2(transitive)
- Removedfast-json-stringify@1.21.0(transitive)
- Removedfast-redact@2.1.0(transitive)
- Removedfastify@2.15.3(transitive)
- Removedfastify-plugin@1.6.1(transitive)
- Removedfind-my-way@2.2.5(transitive)
- Removedlight-my-request@3.8.0(transitive)
- Removedmiddie@4.1.0(transitive)
- Removedpath-to-regexp@4.0.5(transitive)
- Removedpino@5.17.0(transitive)
- Removedpino-std-serializers@2.5.0(transitive)
- Removedquick-format-unescaped@3.0.3(transitive)
- Removedsemver@6.3.1(transitive)
- Removedsonic-boom@0.7.7(transitive)
- Removedtiny-lru@7.0.6(transitive)
Updatedfastify-plugin@2.0.1