Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

fastify-sse-v2

Package Overview
Dependencies
Maintainers
1
Versions
22
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fastify-sse-v2 - npm Package Compare versions

Comparing version 1.0.5 to 2.0.0

10

CHANGELOG.md

@@ -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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc