Skip to content

Commit b6a44d1

Browse files
committed
npm support
1 parent d486991 commit b6a44d1

File tree

9 files changed

+876
-25
lines changed

9 files changed

+876
-25
lines changed

.github/workflows/publish.yml

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,16 @@ jobs:
1212
id-token: write
1313
steps:
1414
- uses: actions/checkout@v4
15-
- name: Publish package
16-
run: npx jsr publish
15+
- uses: actions/setup-node@v4
16+
with:
17+
node-version: '20'
18+
registry-url: 'https://registry.npmjs.org'
19+
- uses: denoland/setup-deno@v2
20+
21+
- name: Update npm
22+
run: npm install -g npm@latest
23+
24+
- run: deno task build
25+
26+
- run: npm publish
27+
- run: npx jsr publish

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
node_modules
2+
dist

README.md

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,23 @@
77
- **Type-safe streaming**: Share the same generic type between server and client thanks to `TypedResponse` support.
88
- **Simple API surface**: Call `typedStream` on the server and `receiveTypedStream` on the client—no manual plumbing required.
99
- **Built for Hono**: Leverages `streamText`, works smoothly with `testClient`, and fits naturally into existing Hono apps.
10-
- **Batteries included**: Ships `TextLineSplitterStream` and `JSONParserStream` to handle newline-delimited JSON payloads.
1110

1211
## Installation
1312

13+
### npm
14+
15+
https://www.npmjs.com/packages/hono-typedstream
16+
17+
```
18+
npm install hono-typedstream # npm
19+
yarn add hono-typedstream # yarn
20+
pnpm add hono-typedstream # pnpm
21+
bun add hono-typedstream # bun
22+
deno add npm:hono-typedstream # deno
23+
```
24+
25+
### jsr
26+
1427
The package is published to [jsr.io/@ns/hono-typedstream](https://jsr.io/@ns/hono-typedstream).
1528

1629
```
@@ -22,8 +35,8 @@ deno add jsr:@ns/hono-typedstream # deno
2235
```
2336

2437
```ts
25-
import { typedStream } from '@ns/hono-typedstream'
26-
import { receiveTypedStream } from '@ns/hono-typedstream/client'
38+
import { typedStream } from 'hono-typedstream'
39+
import { receiveTypedStream } from 'hono-typedstream/client'
2740
```
2841

2942
## Usage
@@ -34,7 +47,7 @@ import { receiveTypedStream } from '@ns/hono-typedstream/client'
3447

3548
```ts
3649
import { Hono } from 'hono'
37-
import { typedStream } from 'jsr:@ns/hono-typedstream'
50+
import { typedStream } from 'hono-typedstream'
3851

3952
const app = new Hono()
4053

@@ -63,7 +76,7 @@ export type AppType = typeof app
6376
6477
```ts
6578
import { hc } from 'hono/client'
66-
import { receiveTypedStream } from 'jsr:@ns/hono-typedstream/client'
79+
import { receiveTypedStream } from 'hono-typedstream/client'
6780
import type { AppType } from './server.ts'
6881

6982
const client = hc<AppType>('/')

client.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import type { TYPED_STREAM_KEY } from './shared.ts'
99
/**
1010
* Splits a text stream into individual lines using newline delimiters.
1111
* @example
12+
* ```ts
1213
* const readable = new ReadableStream({
1314
* start(controller) {
1415
* const encoder = new TextEncoder()
@@ -22,6 +23,7 @@ import type { TYPED_STREAM_KEY } from './shared.ts'
2223
* for await (const line of lines) {
2324
* console.log(line) // "one", then "two"
2425
* }
26+
* ```
2527
*/
2628
export class TextLineSplitterStream extends TransformStream<string, string> {
2729
constructor() {
@@ -49,6 +51,7 @@ export class TextLineSplitterStream extends TransformStream<string, string> {
4951
/**
5052
* Parses newline-delimited JSON chunks into strongly typed objects.
5153
* @example
54+
* ```ts
5255
* const readable = new ReadableStream({
5356
* start(controller) {
5457
* controller.enqueue(JSON.stringify({ ok: true }))
@@ -60,6 +63,7 @@ export class TextLineSplitterStream extends TransformStream<string, string> {
6063
* for await (const result of objects) {
6164
* console.log(result.ok) // true
6265
* }
66+
* ```
6367
*/
6468
export class JSONParserStream<T> extends TransformStream<string, T> {
6569
constructor() {
@@ -81,11 +85,13 @@ export class JSONParserStream<T> extends TransformStream<string, T> {
8185
* @param res Response returned by the Hono client request.
8286
* @returns Readable stream of typed JSON objects.
8387
* @example
88+
* ```ts
8489
* const res = await client.api.events.$get()
8590
* const dataStream = receiveTypedStream(res)
8691
* for await (const payload of dataStream) {
8792
* console.log(payload.type)
8893
* }
94+
* ```
8995
*/
9096
export const receiveTypedStream = <T>(
9197
res: ClientResponse<T, StatusCode, TYPED_STREAM_KEY>

deno.json

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,21 @@
11
{
2-
"name": "@ns/hono-typedstream",
3-
"version": "0.1.0",
4-
"exports": {
5-
".": "./server.ts",
6-
"./client": "./client.ts"
7-
},
8-
"imports": {
9-
"@std/assert": "jsr:@std/assert@^1.0.15",
10-
"hono": "npm:hono@^4.10.4"
11-
},
12-
"fmt": {
13-
"semiColons": false,
14-
"singleQuote": true
15-
},
16-
"license": "MIT"
17-
}
2+
"name": "@ns/hono-typedstream",
3+
"version": "0.1.1",
4+
"exports": {
5+
".": "./server.ts",
6+
"./client": "./client.ts"
7+
},
8+
"imports": {
9+
"@std/assert": "jsr:@std/assert@^1.0.15",
10+
"hono": "npm:hono@^4.10.4"
11+
},
12+
"fmt": {
13+
"semiColons": false,
14+
"singleQuote": true
15+
},
16+
"license": "MIT",
17+
"tasks": {
18+
"build": "deno run -A npm:tsup server.ts client.ts --dts && deno task copy:version",
19+
"copy:version": "jq --slurp '.[1].version as $v | .[0] | .version = $v' package.json deno.json > tmp.json && mv tmp.json package.json"
20+
}
21+
}

0 commit comments

Comments
 (0)