Skip to content

Commit bb7aec0

Browse files
authored
Merge pull request #95 from MatthewWid/jsr
Publish on JSR
2 parents ec6ec59 + 8998583 commit bb7aec0

File tree

11 files changed

+81
-36
lines changed

11 files changed

+81
-36
lines changed

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## Unreleased
99

10+
## 0.15.1 - 2025-05-26
11+
12+
### Added
13+
14+
* Added support for publishing on the [JavaScript Registry (JSR)](https://jsr.io/).
15+
16+
### Fixed
17+
18+
* Fixed the `stream`, `iterate` and `EventBuffer#clear` methods not having explicit return types, resulting in [slow inference](https://jsr.io/docs/about-slow-types) in certain environments.
19+
1020
## 0.15.0 - 2025-05-22
1121

1222
### Added

README.md

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,19 @@
11
# Better SSE
22

33
<p>
4-
<img src="https://img.shields.io/npm/v/better-sse?color=blue&style=flat-square" />
5-
<img src="https://img.shields.io/npm/l/better-sse?color=green&style=flat-square" />
6-
<img src="https://img.shields.io/npm/dt/better-sse?color=grey&style=flat-square" />
7-
<a href="https://github.com/MatthewWid/better-sse"><img src="https://img.shields.io/github/stars/MatthewWid/better-sse?style=social" /></a>
4+
<a href="https://www.npmjs.com/package/better-sse">
5+
<img src="https://img.shields.io/npm/v/better-sse?color=blue&style=flat-square" alt="npm" />
6+
</a>
7+
<a href="https://jsr.io/@mwid/better-sse">
8+
<img src="https://jsr.io/badges/@mwid/better-sse" alt="jsr" />
9+
</a>
10+
<a href="https://github.com/MatthewWid/better-sse/blob/master/LICENSE">
11+
<img src="https://img.shields.io/npm/l/better-sse?color=green&style=flat-square" alt="MIT license" />
12+
</a>
13+
<img src="https://img.shields.io/npm/dt/better-sse?color=grey&style=flat-square" alt="Downloads" />
14+
<a href="https://github.com/MatthewWid/better-sse">
15+
<img src="https://img.shields.io/github/stars/MatthewWid/better-sse?style=social" alt="GitHub stars" />
16+
</a>
817
</p>
918

1019
A dead simple, dependency-less, spec-compliant server-sent events implementation written in TypeScript.
@@ -47,7 +56,7 @@ Read the [Getting Started](https://matthewwid.github.io/better-sse/guides/gettin
4756

4857
# Installation
4958

50-
Install with any package manager:
59+
Better SSE is published as a package on [npm](https://www.npmjs.com/package/better-sse) and the [JSR](https://jsr.io/@mwid/better-sse). You can install it with any package manager:
5160

5261
```sh
5362
npm install better-sse
@@ -66,7 +75,7 @@ bun add better-sse
6675
```
6776

6877
```sh
69-
deno install npm:better-sse
78+
deno install jsr:@mwid/better-sse
7079
```
7180

7281
_Better SSE ships with types built in. No need to install from DefinitelyTyped for TypeScript users!_

biome.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
"ignore": [
1111
"docs/src/content/snippets/*.ts",
1212
"docs/src/**/*.astro",
13+
"docs/.astro/**/*",
1314
"examples/*/public/*.js"
1415
],
1516
"ignoreUnknown": false

docs/src/content/docs/guides/getting-started.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ The technology can be used for things such as live notifications, news tickers,
4040

4141
### Install
4242

43-
Better SSE is shipped [as a package on npm](https://www.npmjs.com/package/better-sse). You can install it with any package manager.
43+
Better SSE is shipped as a package on [npm](https://www.npmjs.com/package/better-sse) and the [JSR](https://jsr.io/@mwid/better-sse). You can install it with any package manager.
4444

4545
<Tabs>
4646
<TabItem label="npm">
@@ -56,7 +56,7 @@ Better SSE is shipped [as a package on npm](https://www.npmjs.com/package/better
5656
<Code code={`bun add better-sse`} lang="shellscript" />
5757
</TabItem>
5858
<TabItem label="Deno">
59-
<Code code={`deno install npm:better-sse`} lang="shellscript" />
59+
<Code code={`deno install jsr:@mwid/better-sse`} lang="shellscript" />
6060
</TabItem>
6161
</Tabs>
6262

jsr.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"name": "@mwid/better-sse",
3+
"version": "0.15.1",
4+
"exports": "./src/index.ts",
5+
"publish": {
6+
"include": ["LICENSE", "README.md", "CHANGELOG.md", "src/**/*.ts"],
7+
"exclude": ["src/**/*.test.ts"]
8+
}
9+
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "better-sse",
33
"description": "Dead simple, dependency-less, spec-compliant server-sent events implementation written in TypeScript.",
4-
"version": "0.15.0",
4+
"version": "0.15.1",
55
"license": "MIT",
66
"author": "Matthew W. <matthew.widdi@gmail.com>",
77
"repository": "github:MatthewWid/better-sse",

src/EventBuffer.ts

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
1-
import {createPushFromIterable} from "./lib/createPushFromIterable";
2-
import {createPushFromStream} from "./lib/createPushFromStream";
1+
import {
2+
type PushFromIterable,
3+
createPushFromIterable,
4+
} from "./lib/createPushFromIterable";
5+
import {
6+
type PushFromStream,
7+
createPushFromStream,
8+
} from "./lib/createPushFromStream";
39
import {generateId} from "./lib/generateId";
410
import {type SanitizerFunction, sanitize} from "./lib/sanitize";
511
import {type SerializerFunction, serialize} from "./lib/serialize";
@@ -134,7 +140,7 @@ class EventBuffer {
134140
push = (
135141
data: unknown,
136142
eventName = "message",
137-
eventId = generateId()
143+
eventId: string = generateId()
138144
): this => {
139145
this.event(eventName).id(eventId).data(data).dispatch();
140146

@@ -151,9 +157,9 @@ class EventBuffer {
151157
* @param stream - Readable stream to consume data from.
152158
* @param options - Event name to use for each event created.
153159
*
154-
* @returns A promise that resolves or rejects based on the success of the stream write finishing.
160+
* @returns A promise that resolves with `true` or rejects based on the success of the stream write finishing.
155161
*/
156-
stream = createPushFromStream(this.push);
162+
stream: PushFromStream = createPushFromStream(this.push);
157163

158164
/**
159165
* Iterate over an iterable and write yielded values as events into the buffer.
@@ -166,12 +172,12 @@ class EventBuffer {
166172
*
167173
* @returns A promise that resolves once all data has been successfully yielded from the iterable.
168174
*/
169-
iterate = createPushFromIterable(this.push);
175+
iterate: PushFromIterable = createPushFromIterable(this.push);
170176

171177
/**
172178
* Clear the contents of the buffer.
173179
*/
174-
clear = () => {
180+
clear = (): this => {
175181
this.buffer = "";
176182

177183
return this;

src/Session.ts

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,14 @@ import {NodeHttp2CompatConnection} from "./adapters/NodeHttp2CompatConnection";
1212
import {SseError} from "./lib/SseError";
1313
import {type EventMap, TypedEmitter} from "./lib/TypedEmitter";
1414
import {applyHeaders} from "./lib/applyHeaders";
15-
import {createPushFromIterable} from "./lib/createPushFromIterable";
16-
import {createPushFromStream} from "./lib/createPushFromStream";
15+
import {
16+
type PushFromIterable,
17+
createPushFromIterable,
18+
} from "./lib/createPushFromIterable";
19+
import {
20+
type PushFromStream,
21+
createPushFromStream,
22+
} from "./lib/createPushFromStream";
1723
import {generateId} from "./lib/generateId";
1824
import {
1925
type SanitizerFunction,
@@ -362,7 +368,7 @@ class Session<State = DefaultSessionState> extends TypedEmitter<SessionEvents> {
362368
push = (
363369
data: unknown,
364370
eventName = "message",
365-
eventId = generateId()
371+
eventId: string = generateId()
366372
): this => {
367373
if (!this.isConnected) {
368374
throw new SseError(
@@ -394,9 +400,9 @@ class Session<State = DefaultSessionState> extends TypedEmitter<SessionEvents> {
394400
* @param stream - Readable stream to consume data from.
395401
* @param options - Options to alter how the stream is flushed to the client.
396402
*
397-
* @returns A promise that resolves or rejects based on the success of the stream write finishing.
403+
* @returns A promise that resolves with `true` or rejects based on the success of the stream write finishing.
398404
*/
399-
stream = createPushFromStream(this.push);
405+
stream: PushFromStream = createPushFromStream(this.push);
400406

401407
/**
402408
* Iterate over an iterable and send yielded values as events to the client.
@@ -409,7 +415,7 @@ class Session<State = DefaultSessionState> extends TypedEmitter<SessionEvents> {
409415
*
410416
* @returns A promise that resolves once all data has been successfully yielded from the iterable.
411417
*/
412-
iterate = createPushFromIterable(this.push);
418+
iterate: PushFromIterable = createPushFromIterable(this.push);
413419

414420
/**
415421
* Batch and send multiple events at once.
@@ -427,7 +433,7 @@ class Session<State = DefaultSessionState> extends TypedEmitter<SessionEvents> {
427433
*/
428434
batch = async (
429435
batcher: EventBuffer | ((buffer: EventBuffer) => void | Promise<void>)
430-
) => {
436+
): Promise<void> => {
431437
if (batcher instanceof EventBuffer) {
432438
this.connection.sendChunk(batcher.read());
433439
} else {

src/createEventBuffer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@ import {EventBuffer} from "./EventBuffer";
22

33
const createEventBuffer = (
44
...args: ConstructorParameters<typeof EventBuffer>
5-
) => new EventBuffer(...args);
5+
): EventBuffer => new EventBuffer(...args);
66

77
export {createEventBuffer};

src/lib/createPushFromIterable.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,20 @@ interface IterateOptions {
77
eventName?: string;
88
}
99

10+
type PushFromIterable = (
11+
iterable: Iterable<unknown> | AsyncIterable<unknown>,
12+
options?: IterateOptions
13+
) => Promise<void>;
14+
1015
const createPushFromIterable =
11-
(push: (data: unknown, eventName: string) => void) =>
12-
async <DataType = unknown>(
13-
iterable: Iterable<DataType> | AsyncIterable<DataType>,
14-
options: IterateOptions = {}
15-
): Promise<void> => {
16+
(push: (data: unknown, eventName: string) => void): PushFromIterable =>
17+
async (iterable, options = {}) => {
1618
const {eventName = "iteration"} = options;
1719

1820
for await (const data of iterable) {
1921
push(data, eventName);
2022
}
2123
};
2224

23-
export type {IterateOptions};
25+
export type {IterateOptions, PushFromIterable};
2426
export {createPushFromIterable};

0 commit comments

Comments
 (0)