Releases: sor4chi/hono-do
[email protected]
[email protected]
[email protected]
[email protected]
Major Changes
-
#21
f659d6c
Thanks @sor4chi! - Support for three handlers about Hibernation Websocket API.webSocketMessage
handlerwebSocketClose
handlerwebSocketError
handler
You can use these handlers same way as
alarm
handler in Hono DO.Usage
Flat way
const DO = generateHonoObject("/", () => {}); DO.alarm(async () => {}); DO.webSocketMessage(async () => {}); DO.webSocketClose(async () => {}); DO.webSocketError(async () => {});
Chaining way
generateHonoObject("/", () => {}) .alarm(async () => {}) .webSocketMessage(async () => {}) .webSocketClose(async () => {}) .webSocketError(async () => {});
Argument way
generateHonoObject("/", () => {}, { alarm: async () => {}, webSocketMessage: async () => {}, webSocketClose: async () => {}, webSocketError: async () => {}, });
Take care for registering multiple handlers for same event.
If you register so, you will get an error.Breaking changes
Changed the interface of how to configure
AlarmHandler
ingenerateHonoObject
argument.Before
generateHonoObject( "/", () => {}, () => { console.log("alarm"); }, );
After
generateHonoObject("/", () => {}, { alarm: () => { console.log("alarm"); }, });
This is because we want to support many fields of Durable Object as handlers.
[email protected]
Patch Changes
-
#19
9722471
Thanks @sor4chi! - Fixed an issue where theBasePath
type ingenerateHonoObject
did not inherit the basePath of the first argument.// Before generateHonoObject("/foo", (app) => { app.get("/bar", (c) => { c; // $ExpectType Context<Env, "/bar", {}> }); }); // After generateHonoObject("/foo", (app) => { app.get("/bar", (c) => { c; // $ExpectType Context<Env, "/foo/bar", {}> }); });
[email protected]
Minor Changes
-
#14
1d59c26
Thanks @sor4chi! - Support Alarms APIYou can now create and manage alarms using the Alarms API. See the Alarms API documentation for details.
import { generateHonoObject } from "hono-do"; const SECONDS = 1000; declare module "hono-do" { interface HonoObjectVars { count: number; // custom fields (vars) type support } } export const Batcher = generateHonoObject("/batcher", async (app, { storage }, vars) => { vars.count = (await storage.get<number>("count")) ?? 0; app.post("/", async (c) => { vars.count++; const currentAlarm = await storage.getAlarm(); if (currentAlarm == null) { await storage.setAlarm(Date.now() + 10 * SECONDS); } return c.json({ queued: vars.count }); }); }).alarm(async ({ storage }, vars) => { console.log("Alarm fired, count is", vars.count); await storage.deleteAll(); vars.count = 0; });
-
#2
7de88ad
Thanks @sor4chi! - Implement storage helper as sub packageYou can use
state.storage
type-safely like hooks in React.import { defineStorage } from "hono-do/storage"; export const Counter = generateHonoObject("/counter", async (app, { storage }) => { const [getValue, setValue, delValue] = await defineStorage(storage, "value", 0); await getValue(); // 0 await setValue(1); await getValue(); // 1 await setValue((value) => value + 1); // 2 await getValue(); // 2 await delValue(); await getValue(); // 0 });