New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

ts-sse

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ts-sse - npm Package Compare versions

Comparing version 0.0.3 to 0.0.4

2

lib/utils.js

@@ -17,5 +17,5 @@ "use strict";

.split(/\r\n|\r|\n/)
.map((line) => `data: ${line}\n`)
.map((line) => `data: ${line}\n\n`)
.join('');
}
exports.toDataString = toDataString;

@@ -49,3 +49,3 @@ "use strict";

const input = 'Hello\nWorld\r\nHow\rAre You';
const output = 'data: Hello\ndata: World\ndata: How\ndata: Are You\n';
const output = 'data: Hello\n\ndata: World\n\ndata: How\n\ndata: Are You\n\n';
expect((0, utils_1.toDataString)(input)).toBe(output);

@@ -55,3 +55,3 @@ });

const input = { a: 1, b: 'string' };
const output = 'data: {"a":1,"b":"string"}\n';
const output = 'data: {"a":1,"b":"string"}\n\n';
expect((0, utils_1.toDataString)(input)).toBe(output);

@@ -58,0 +58,0 @@ });

{
"name": "ts-sse",
"version": "0.0.3",
"version": "0.0.4",
"description": "utilities for Server Sent Events that adopts the HTML Spec Standard for the EventSource Web API.",

@@ -5,0 +5,0 @@ "main": "./lib/index.js",

@@ -29,3 +29,3 @@ # ts-sse

- have TypeScript.
- A basic understanding of [Server-Sent Events (SSE)]([HTML Spec Standard](https://html.spec.whatwg.org/multipage/server-sent-events.html)) and the [EventSource Web API](https://developer.mozilla.org/en-US/docs/Web/API/EventSource).
- A basic understanding of [Server-Sent Events "SSE"(https://html.spec.whatwg.org/multipage/server-sent-events.html)) and the [EventSource Web API](https://developer.mozilla.org/en-US/docs/Web/API/EventSource).

@@ -35,5 +35,10 @@

This wrapper is compatible with any server/runtime that can return a `responseStream.readable`. Here's an example with Nextjs that implements a "syncing" streaming route.
Go to the [examples/next-app](./examples/next-app) directory for a full example.
> the streaming route is at `/stream/route.tsx` and the client component is at `/StreamClient.tsx`
> This wrapper is compatible with any server/runtime that can return a `responseStream.readable`. Below is an example with Nextjs that implements a "syncing" streaming route.
#### Import the Utilities
```ts

@@ -59,2 +64,3 @@ import { EventNotifier, getSSEWriter } from 'ts-sse'

```ts
//api/stream/types.ts
type SyncEvents = EventNotifier<{

@@ -95,2 +101,5 @@ update: {

// api/stream/route.ts
import { EventNotifier, getSSEWriter } from 'ts-sse'
import { syncSchema, SyncEvents } from './types'
export async function GET() {

@@ -126,3 +135,3 @@ // ... (authentication and other logic)

// Use the getSSEWriter to initialize the utility with the writer
syncStatusStream(getSSEWriter(writer, encoder));
syncStatusStream(getSSEWriter(writer, encoder)); // 👈 inject encoder and writer into `getSSEWriter` factory

@@ -129,0 +138,0 @@ // Return the response stream

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