Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/rotten-radios-hope.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@hono/event-emitter': minor
---

Add `EmitterEnv` type paramater
5 changes: 2 additions & 3 deletions .github/workflows/autofix.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,15 @@ jobs:
- uses: actions/cache@v5
with:
path: .turbo
key: ${{ runner.os }}-turbo-autofix-${{ github.sha }}
key: ${{ runner.os }}-turbo-${{ github.sha }}
restore-keys: |
${{ runner.os }}-turbo-autofix-
${{ runner.os }}-turbo-
- uses: actions/setup-node@v6
with:
node-version-file: .tool-versions
- run: yarn install
- run: yarn lint:fix --cache-strategy content
- run: yarn format:fix
- run: yarn lint:fix
- name: Apply fixes
uses: autofix-ci/action@v1
with:
Expand Down
5 changes: 1 addition & 4 deletions .github/workflows/ci-bun-transpiler.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,7 @@ jobs:
with:
bun-version-file: .tool-versions
- run: yarn workspaces focus hono-middleware @hono/bun-transpiler
- run: yarn workspace @hono/bun-transpiler build
- run: yarn workspace @hono/bun-transpiler typecheck
- run: yarn eslint packages/bun-transpiler
- run: yarn prettier --check . !packages packages/bun-transpiler
- run: yarn turbo --filter @hono/bun-transpiler build
- run: yarn workspace @hono/bun-transpiler test --coverage --coverage-reporter lcov
- uses: codecov/codecov-action@v5
with:
Expand Down
8 changes: 7 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,17 @@ jobs:

steps:
- uses: actions/checkout@v6
- uses: actions/cache@v5
with:
path: .turbo
key: ${{ runner.os }}-turbo-${{ github.sha }}
restore-keys: |
${{ runner.os }}-turbo-
- uses: actions/setup-node@v6
with:
node-version-file: .tool-versions
- run: yarn workspaces focus hono-middleware @hono/${{ matrix.package }}
- run: yarn workspaces foreach --topological --recursive --from @hono/${{ matrix.package }} run build
- run: yarn turbo --filter @hono/${{ matrix.package }} build
- run: yarn test --coverage --project @hono/${{ matrix.package }}
id: test
if: ${{ matrix.package != 'eslint-config' && matrix.package != 'qwik-city' && matrix.package != 'react-compat' }}
Expand Down
9 changes: 8 additions & 1 deletion .github/workflows/cr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@ jobs:
with:
fetch-depth: 0

- uses: actions/cache@v5
with:
path: .turbo
key: ${{ runner.os }}-turbo-${{ github.sha }}
restore-keys: |
${{ runner.os }}-turbo-

- uses: actions/setup-node@v6
with:
node-version-file: .tool-versions
Expand All @@ -28,7 +35,7 @@ jobs:
run: yarn

- name: Build
run: yarn build
run: yarn turbo build

- name: Publish to StackBlitz
run: yarn pkg-pr-new publish --compact --no-template './packages/*'
10 changes: 8 additions & 2 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ jobs:
node-version-file: .tool-versions
- run: yarn
- run: yarn typecheck
- run: yarn lint
- run: yarn lint --cache-strategy content
- run: yarn format

dry-run:
Expand All @@ -66,11 +66,17 @@ jobs:

steps:
- uses: actions/checkout@v6
- uses: actions/cache@v5
with:
path: .turbo
key: ${{ runner.os }}-turbo-${{ github.sha }}
restore-keys: |
${{ runner.os }}-turbo-
- uses: actions/setup-node@v6
with:
node-version-file: .tool-versions
- run: yarn workspaces focus hono-middleware @hono/${{ matrix.package }}
- run: yarn workspaces foreach --topological --recursive --from @hono/${{ matrix.package }} run build
- run: yarn turbo --filter @hono/${{ matrix.package }} build
- run: yarn test --coverage --project @hono/${{ matrix.package }}
id: test
if: ${{ matrix.package != 'eslint-config' && matrix.package != 'qwik-city' && matrix.package != 'react-compat' }}
Expand Down
10 changes: 9 additions & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,14 @@ jobs:
- name: Checkout Repo
uses: actions/checkout@v6

- name: Build Cache
uses: actions/cache@v5
with:
path: .turbo
key: ${{ runner.os }}-turbo-${{ github.sha }}
restore-keys: |
${{ runner.os }}-turbo-

- name: Setup Node.js 20.x
uses: actions/setup-node@v6
with:
Expand All @@ -32,7 +40,7 @@ jobs:
run: yarn

- name: Build
run: yarn build
run: yarn turbo build

- name: Create Release Pull Request or Publish to npm
id: changesets
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
"@types/ws": "^8.18.0",
"@vitest/coverage-istanbul": "^4.0.16",
"eslint": "^9.34.0",
"hono": "^4.11.1",
"hono": "^4.11.3",
"pkg-pr-new": "^0.0.54",
"prettier": "^3.6.2",
"publint": "^0.3.16",
Expand Down
2 changes: 1 addition & 1 deletion packages/ajv-validator/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
},
"devDependencies": {
"ajv": "^8.12.0",
"hono": "^4.11.1",
"hono": "^4.11.3",
"tsdown": "^0.15.9",
"typescript": "^5.8.2",
"vitest": "^4.0.16"
Expand Down
2 changes: 1 addition & 1 deletion packages/ajv-validator/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ export function ajvValidator<
> {
const ajv = new Ajv()
const validate = ajv.compile(schema)

// @ts-expect-error not typed well
return validator(target, (data, c) => {
const valid = validate(data)
if (valid) {
Expand Down
2 changes: 1 addition & 1 deletion packages/arktype-validator/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
},
"devDependencies": {
"arktype": "^2.1.20",
"hono": "^4.11.1",
"hono": "^4.11.3",
"tsdown": "^0.15.9",
"typescript": "^5.8.2",
"vitest": "^4.0.16"
Expand Down
2 changes: 1 addition & 1 deletion packages/auth-js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
"devDependencies": {
"@auth/core": "^0.35.3",
"@types/react": "^19",
"hono": "^4.11.1",
"hono": "^4.11.3",
"react": "^19.2.3",
"tsdown": "^0.15.9",
"typescript": "^5.8.2",
Expand Down
2 changes: 1 addition & 1 deletion packages/bun-compress/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
"devDependencies": {
"@types/bun": "^1.2.12",
"@types/node": "^25.0.3",
"hono": "^4.11.1",
"hono": "^4.11.3",
"tsdown": "^0.15.9",
"typescript": "^5.8.2",
"vitest": "^4.0.16"
Expand Down
2 changes: 1 addition & 1 deletion packages/bun-transpiler/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
"hono": ">=4.0.0"
},
"devDependencies": {
"hono": "^4.11.1",
"hono": "^4.11.3",
"tsdown": "^0.15.9",
"typescript": "^5.8.2",
"vitest": "^4.0.16"
Expand Down
2 changes: 1 addition & 1 deletion packages/capnweb/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
"@hono/node-ws": "^1.2.0",
"@types/ws": "^8.5.0",
"capnweb": "^0.3.0",
"hono": "^4.11.1",
"hono": "^4.11.3",
"publint": "^0.3.16",
"tsdown": "^0.15.9",
"typescript": "^5.8.2",
Expand Down
2 changes: 1 addition & 1 deletion packages/casbin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
},
"devDependencies": {
"casbin": "^5.40.0",
"hono": "^4.11.1",
"hono": "^4.11.3",
"tsdown": "^0.15.9",
"typescript": "^5.8.2",
"vitest": "^4.0.16"
Expand Down
2 changes: 1 addition & 1 deletion packages/class-validator/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
"hono": ">=3.9.0"
},
"devDependencies": {
"hono": "^4.11.1",
"hono": "^4.11.3",
"tsdown": "^0.15.9",
"typescript": "^5.8.2",
"vitest": "^4.0.16"
Expand Down
2 changes: 1 addition & 1 deletion packages/clerk-auth/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
},
"devDependencies": {
"@types/react": "^19",
"hono": "^4.11.1",
"hono": "^4.11.3",
"react": "^19.2.3",
"tsdown": "^0.15.9",
"typescript": "^5.8.2",
Expand Down
2 changes: 1 addition & 1 deletion packages/cloudflare-access/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
"hono": ">=4.0.0"
},
"devDependencies": {
"hono": "^4.11.1",
"hono": "^4.11.3",
"tsdown": "^0.15.9",
"typescript": "^5.8.2",
"vitest": "^4.0.16"
Expand Down
2 changes: 1 addition & 1 deletion packages/conform-validator/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
"@conform-to/valibot": "^1.14.1",
"@conform-to/yup": "^1.14.0",
"@conform-to/zod": "^1.14.0",
"hono": "^4.11.1",
"hono": "^4.11.3",
"tsdown": "^0.15.9",
"typescript": "^5.8.2",
"valibot": "^1.1.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/effect-validator/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
},
"devDependencies": {
"effect": "3.19.12",
"hono": "^4.11.1",
"hono": "^4.11.3",
"tsdown": "^0.15.9",
"typescript": "^5.8.2",
"vitest": "^4.0.16"
Expand Down
2 changes: 1 addition & 1 deletion packages/esbuild-transpiler/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
"devDependencies": {
"esbuild": "^0.25.10",
"esbuild-wasm": "^0.27.2",
"hono": "^4.11.1",
"hono": "^4.11.3",
"tsdown": "^0.15.9",
"typescript": "^5.8.2",
"vitest": "^4.0.16"
Expand Down
18 changes: 6 additions & 12 deletions packages/event-emitter/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ export default app
```ts
// types.ts

import type { Emitter } from '@hono/event-emitter'
import type { EmitterEnv } from '@hono/event-emitter'

export type User = {
id: string
Expand All @@ -192,13 +192,7 @@ export type AvailableEvents = {
foo: { bar: number }
}

export type Env = {
Bindings: {}
Variables: {
// Define emitter variable type
emitter: Emitter<AvailableEvents>
}
}
export type Env = EmitterEnv<AvailableEvents>
```

```ts
Expand Down Expand Up @@ -360,7 +354,7 @@ export default app
Creates a Hono middleware that adds an event emitter to the context.

```ts
function emitter<EPMap extends EventPayloadMap>(
function emitter<EPMap>(
eventHandlers?: EventHandlers<EPMap>,
options?: EventEmitterOptions
): MiddlewareHandler
Expand All @@ -386,7 +380,7 @@ app.use(emitter(eventHandlers))
Creates new instance of event emitter with provided handlers. This is usefull when you want to use the emitter as standalone feature instead of Hono middleware.

```ts
function createEmitter<EPMap extends EventPayloadMap>(
function createEmitter<EPMap>(
eventHandlers?: EventHandlers<EPMap>,
options?: EventEmitterOptions
): Emitter<EPMap>
Expand All @@ -412,7 +406,7 @@ const ee = createEmitter(eventHandlers)
A utility function to define a typed event handler.

```ts
function defineHandler<EPMap extends EventPayloadMap, Key extends keyof EPMap, E extends Env = Env>(
function defineHandler<EPMap, Key extends keyof EPMap, E extends Env = Env>(
handler: EventHandler<EPMap[Key], E>
): EventHandler<EPMap[Key], E>
```
Expand Down Expand Up @@ -448,7 +442,7 @@ const handler = defineHandler<AvailableEvents, 'user:created'>((c, payload) => {
A utility function to define multiple typed event handlers.

```ts
function defineHandlers<EPMap extends EventPayloadMap, E extends Env = Env>(handlers: {
function defineHandlers<EPMap, E extends Env = Env>(handlers: {
[K in keyof EPMap]?: EventHandler<EPMap[K], E>[]
}): { [K in keyof EPMap]?: EventHandler<EPMap[K], E>[] }
```
Expand Down
2 changes: 1 addition & 1 deletion packages/event-emitter/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
"hono": ">=4.0.0"
},
"devDependencies": {
"hono": "^4.11.1",
"hono": "^4.11.3",
"tsdown": "^0.15.9",
"typescript": "^5.8.2",
"vitest": "^4.0.16"
Expand Down
6 changes: 3 additions & 3 deletions packages/event-emitter/src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import type { Context } from 'hono'
import { describe, expect, it, vi } from 'vitest'
import { createEmitter, defineHandler, defineHandlers, emitter } from './index'
import type { Emitter } from './index' // Adjust the import path as needed
import type { Emitter, EmitterEnv } from './index' // Adjust the import path as needed

describe('Event Emitter Middleware', () => {
describe('createEmitter', () => {
Expand Down Expand Up @@ -89,12 +89,12 @@
const ee = createEmitter<EventPayloadMap>()
const delay = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms))
const handler1 = vi.fn(
defineHandler<EventPayloadMap, 'test'>(async (_c, _payload) => {

Check warning on line 92 in packages/event-emitter/src/index.test.ts

View workflow job for this annotation

GitHub Actions / autofix

'_payload' is defined but never used

Check warning on line 92 in packages/event-emitter/src/index.test.ts

View workflow job for this annotation

GitHub Actions / autofix

'_c' is defined but never used
await delay(100)
})
)
const handler2 = vi.fn(
defineHandler<EventPayloadMap, 'test'>(async (_c, _payload) => {

Check warning on line 97 in packages/event-emitter/src/index.test.ts

View workflow job for this annotation

GitHub Actions / autofix

'_payload' is defined but never used

Check warning on line 97 in packages/event-emitter/src/index.test.ts

View workflow job for this annotation

GitHub Actions / autofix

'_c' is defined but never used
await delay(100)
})
)
Expand Down Expand Up @@ -123,12 +123,12 @@
const ee = createEmitter<EventPayloadMap>()
const delay = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms))
const handler1 = vi.fn(
defineHandler<EventPayloadMap, 'test'>(async (_c, _payload) => {

Check warning on line 126 in packages/event-emitter/src/index.test.ts

View workflow job for this annotation

GitHub Actions / autofix

'_payload' is defined but never used

Check warning on line 126 in packages/event-emitter/src/index.test.ts

View workflow job for this annotation

GitHub Actions / autofix

'_c' is defined but never used
await delay(101)
})
)
const handler2 = vi.fn(
defineHandler<EventPayloadMap, 'test'>(async (_c, _payload) => {

Check warning on line 131 in packages/event-emitter/src/index.test.ts

View workflow job for this annotation

GitHub Actions / autofix

'_c' is defined but never used
await delay(101)
})
)
Expand Down Expand Up @@ -391,7 +391,7 @@
'todo:created': { id: string; text: string }
}

type Env = { Variables: { emitter: Emitter<EventPayloadMap> } }
type Env = EmitterEnv<EventPayloadMap>

const handlers = defineHandlers<EventPayloadMap>({
'todo:created': [vi.fn((_c, _payload) => {})],
Expand Down Expand Up @@ -423,7 +423,7 @@
'todo:created': { id: string; text: string }
}

type Env = { Variables: { emitter: Emitter<EventPayloadMap> } }
type Env = EmitterEnv<EventPayloadMap>

const handlers = defineHandlers<EventPayloadMap>({
'todo:created': [vi.fn(async (_c, _payload) => {})],
Expand Down
Loading
Loading