Skip to content

Releases: sor4chi/hono-do

[email protected]

07 May 01:04
fbb0f63
Compare
Choose a tag to compare

Major Changes

  • a27936f Thanks @sor4chi! - Updated the version of the dependency 'hono' to 4.x.

[email protected]

03 Dec 11:24
a0fbd34
Compare
Choose a tag to compare

Minor Changes

  • #31 44c46e2 Thanks @sor4chi! - feat: enable to get bindings env from vars

    import { generateHonoObject } from "hono-do";
    
    type Env = {
      Bindings: {
        KV: KVNamespace;
      };
    };
    
    export const Batcher = generateHonoObject<Env>(
      "/",
      async (app, state, vars) => {
        vars.env.KV; // KVNamespace
      },
    );

[email protected]

01 Dec 12:12
607c7a3
Compare
Choose a tag to compare

Patch Changes

  • #26 bdb39b9 Thanks @sor4chi! - Fixed a bug that caused an error when a duplicate route was registered when the basepath of HonoObject was dynamic.

[email protected]

30 Nov 15:25
38162ef
Compare
Choose a tag to compare

Major Changes

  • #21 f659d6c Thanks @sor4chi! - Support for three handlers about Hibernation Websocket API.

    • webSocketMessage handler
    • webSocketClose handler
    • webSocketError 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 in generateHonoObject 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]

06 Oct 19:19
c53ea34
Compare
Choose a tag to compare

Patch Changes

  • #19 9722471 Thanks @sor4chi! - Fixed an issue where the BasePath type in generateHonoObject 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]

29 Sep 01:33
922be19
Compare
Choose a tag to compare

Minor Changes

  • #14 1d59c26 Thanks @sor4chi! - Support Alarms API

    You 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 package

    You 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
    });

[email protected]

26 Sep 17:36
bcd0232
Compare
Choose a tag to compare

Minor Changes

  • #3 7fc9954 Thanks @sor4chi! - wrap initialize function of durable object with blockConcurrencyWhile