@canmi/seam-adapter-hono 0.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,21 @@
1
+ # @canmi/seam-adapter-hono
2
+
3
+ Hono middleware adapter that routes `/_seam/*` requests through the seam HTTP handler.
4
+
5
+ ## Usage
6
+
7
+ Exports a single `seam()` function that returns a Hono `MiddlewareHandler`. Wraps `createHttpHandler` and `toWebResponse` from `@canmi/seam-server`.
8
+
9
+ ## Structure
10
+
11
+ - `src/index.ts` — Middleware factory
12
+
13
+ ## Development
14
+
15
+ - Build: `bun run --filter '@canmi/seam-adapter-hono' build`
16
+ - Test: `bun run --filter '@canmi/seam-adapter-hono' test`
17
+
18
+ ## Notes
19
+
20
+ - Peer dependencies: `@canmi/seam-server`, `hono` ^4.0.0
21
+ - Designed for use with Hono's `app.use()` middleware registration
@@ -0,0 +1,13 @@
1
+ import { DefinitionMap, HttpHandler, Router } from "@canmi/seam-server";
2
+ import { MiddlewareHandler } from "hono";
3
+
4
+ //#region src/index.d.ts
5
+ interface SeamHonoOptions {
6
+ staticDir?: string;
7
+ fallback?: HttpHandler;
8
+ }
9
+ /** Hono middleware that handles all /_seam/* routes via the seam router */
10
+ declare function seam<T extends DefinitionMap>(router: Router<T>, opts?: SeamHonoOptions): MiddlewareHandler;
11
+ //#endregion
12
+ export { SeamHonoOptions, seam };
13
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","names":[],"sources":["../src/index.ts"],"mappings":";;;;UAMiB,eAAA;EACf,SAAA;EACA,QAAA,GAAW,WAAA;AAAA;;iBAMG,IAAA,WAAe,aAAA,CAAA,CAC7B,MAAA,EAAQ,MAAA,CAAO,CAAA,GACf,IAAA,GAAO,eAAA,GACN,iBAAA"}
package/dist/index.js ADDED
@@ -0,0 +1,24 @@
1
+ import { createHttpHandler, toWebResponse } from "@canmi/seam-server";
2
+
3
+ //#region src/index.ts
4
+ const SEAM_PREFIX = "/_seam/";
5
+ /** Hono middleware that handles all /_seam/* routes via the seam router */
6
+ function seam(router, opts) {
7
+ const handlerOpts = {};
8
+ if (opts?.staticDir) handlerOpts.staticDir = opts.staticDir;
9
+ if (opts?.fallback) handlerOpts.fallback = opts.fallback;
10
+ const handler = createHttpHandler(router, handlerOpts);
11
+ return async (c, next) => {
12
+ if (!new URL(c.req.url).pathname.startsWith(SEAM_PREFIX)) return next();
13
+ const raw = c.req.raw;
14
+ return toWebResponse(await handler({
15
+ method: raw.method,
16
+ url: raw.url,
17
+ body: () => raw.json()
18
+ }));
19
+ };
20
+ }
21
+
22
+ //#endregion
23
+ export { seam };
24
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","names":[],"sources":["../src/index.ts"],"sourcesContent":["/* packages/server/adapter/hono/src/index.ts */\n\nimport { createHttpHandler, toWebResponse } from \"@canmi/seam-server\";\nimport type { DefinitionMap, Router, HttpHandler, HttpHandlerOptions } from \"@canmi/seam-server\";\nimport type { MiddlewareHandler } from \"hono\";\n\nexport interface SeamHonoOptions {\n staticDir?: string;\n fallback?: HttpHandler;\n}\n\nconst SEAM_PREFIX = \"/_seam/\";\n\n/** Hono middleware that handles all /_seam/* routes via the seam router */\nexport function seam<T extends DefinitionMap>(\n router: Router<T>,\n opts?: SeamHonoOptions,\n): MiddlewareHandler {\n const handlerOpts: HttpHandlerOptions = {};\n if (opts?.staticDir) handlerOpts.staticDir = opts.staticDir;\n if (opts?.fallback) handlerOpts.fallback = opts.fallback;\n\n const handler = createHttpHandler(router, handlerOpts);\n\n return async (c, next) => {\n const url = new URL(c.req.url);\n\n if (!url.pathname.startsWith(SEAM_PREFIX)) {\n return next();\n }\n\n const raw = c.req.raw;\n const result = await handler({\n method: raw.method,\n url: raw.url,\n body: () => raw.json(),\n });\n\n return toWebResponse(result);\n };\n}\n"],"mappings":";;;AAWA,MAAM,cAAc;;AAGpB,SAAgB,KACd,QACA,MACmB;CACnB,MAAM,cAAkC,EAAE;AAC1C,KAAI,MAAM,UAAW,aAAY,YAAY,KAAK;AAClD,KAAI,MAAM,SAAU,aAAY,WAAW,KAAK;CAEhD,MAAM,UAAU,kBAAkB,QAAQ,YAAY;AAEtD,QAAO,OAAO,GAAG,SAAS;AAGxB,MAAI,CAFQ,IAAI,IAAI,EAAE,IAAI,IAAI,CAErB,SAAS,WAAW,YAAY,CACvC,QAAO,MAAM;EAGf,MAAM,MAAM,EAAE,IAAI;AAOlB,SAAO,cANQ,MAAM,QAAQ;GAC3B,QAAQ,IAAI;GACZ,KAAK,IAAI;GACT,YAAY,IAAI,MAAM;GACvB,CAAC,CAE0B"}
package/package.json ADDED
@@ -0,0 +1,29 @@
1
+ {
2
+ "name": "@canmi/seam-adapter-hono",
3
+ "version": "0.2.3",
4
+ "files": [
5
+ "dist"
6
+ ],
7
+ "type": "module",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./dist/index.d.ts",
11
+ "import": "./dist/index.js"
12
+ }
13
+ },
14
+ "scripts": {
15
+ "build": "tsdown",
16
+ "test": "vitest run"
17
+ },
18
+ "devDependencies": {
19
+ "@canmi/seam-server": "workspace:*",
20
+ "hono": "^4.0.0",
21
+ "tsdown": "^0.20.0",
22
+ "typescript": "^5.7.0",
23
+ "vitest": "^3.0.0"
24
+ },
25
+ "peerDependencies": {
26
+ "@canmi/seam-server": "workspace:*",
27
+ "hono": "^4.0.0"
28
+ }
29
+ }