@wyrly/hono 1.0.4 → 1.0.6

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,57 @@
1
+ # @wyrly/hono
2
+
3
+ Wyrly DI adapter for Hono — request scope via `di()` middleware and `getDI(c)`.
4
+
5
+ Japanese: [README.ja.md](./README.ja.md)
6
+
7
+ ## Install
8
+
9
+ ```sh
10
+ npm install @wyrly/hono @wyrly/core hono
11
+ ```
12
+
13
+ Peer dependency: **hono ^4.0.0**.
14
+
15
+ Tested on **Node.js**, **Bun**, and **Cloudflare Workers** (see monorepo `compat/`).
16
+
17
+ ## Requirements
18
+
19
+ - Everything required by [`@wyrly/core`](../core/README.md)
20
+ - **Hono 4.x**
21
+
22
+ ## Quick start
23
+
24
+ ```ts
25
+ import { Hono } from "hono";
26
+ import { di, getDI, type HonoDIVariables } from "@wyrly/hono";
27
+ import { createContainer } from "@wyrly/core";
28
+
29
+ const app = new Hono<{ Variables: HonoDIVariables }>();
30
+ app.use(di(createContainer()));
31
+
32
+ app.get("/users/:id", (c) => {
33
+ const scope = getDI(c);
34
+ return c.json({ disposed: scope.isDisposed() });
35
+ });
36
+ ```
37
+
38
+ ## Documentation
39
+
40
+ - [@wyrly/core](../core/README.md)
41
+ - [API reference](https://github.com/valid-lab/wyrly/blob/main/API.md)
42
+ - [Monorepo README](https://github.com/valid-lab/wyrly/blob/main/README.md)
43
+
44
+ ## Related packages
45
+
46
+ | Package | npm | Description |
47
+ | ---------------- | -------- | --------------- |
48
+ | `@wyrly/core` | yes | Core DI |
49
+ | `@wyrly/hono` | yes | This package |
50
+ | `@wyrly/express` | yes | Express adapter |
51
+ | `@wyrly/graphql` | yes | GraphQL adapter |
52
+ | `@wyrly/next` | yes | Next.js adapter |
53
+ | `@wyrly/fresh` | JSR only | Fresh 2.x |
54
+
55
+ ## License
56
+
57
+ Apache-2.0 — see [LICENSE](https://github.com/valid-lab/wyrly/blob/main/LICENSE).
@@ -1,6 +1,2 @@
1
- import { Deno } from "@deno/shim-deno";
2
- export { Deno } from "@deno/shim-deno";
3
- export declare const dntGlobalThis: Omit<typeof globalThis, "Deno"> & {
4
- Deno: typeof Deno;
5
- };
1
+ export declare const dntGlobalThis: Omit<typeof globalThis, never>;
6
2
  //# sourceMappingURL=_dnt.shims.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"_dnt.shims.d.ts","sourceRoot":"","sources":["../src/_dnt.shims.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAC;AACvC,OAAO,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAC;AAKvC,eAAO,MAAM,aAAa;;CAA2C,CAAC"}
1
+ {"version":3,"file":"_dnt.shims.d.ts","sourceRoot":"","sources":["../src/_dnt.shims.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,aAAa,gCAA2C,CAAC"}
package/esm/_dnt.shims.js CHANGED
@@ -1,8 +1,4 @@
1
- import { Deno } from "@deno/shim-deno";
2
- export { Deno } from "@deno/shim-deno";
3
- const dntGlobals = {
4
- Deno,
5
- };
1
+ const dntGlobals = {};
6
2
  export const dntGlobalThis = createMergeProxy(globalThis, dntGlobals);
7
3
  function createMergeProxy(baseObj, extObj) {
8
4
  return new Proxy(baseObj, {
@@ -1 +1 @@
1
- {"version":3,"file":"i18n.d.ts","sourceRoot":"","sources":["../../src/core/i18n.ts"],"names":[],"mappings":"AAGA,MAAM,MAAM,MAAM,GAAG,IAAI,GAAG,IAAI,CAAC;AAEjC,wEAAwE;AACxE,eAAO,MAAM,cAAc,EAAE,MAAa,CAAC;AAE3C,gEAAgE;AAChE,MAAM,MAAM,qBAAqB,GAC7B,uBAAuB,GACvB,6BAA6B,GAC7B,6BAA6B,GAC7B,qBAAqB,GACrB,iBAAiB,CAAC;AAEtB,gEAAgE;AAChE,MAAM,MAAM,gBAAgB,GACxB,kBAAkB,GAClB,oBAAoB,GACpB,eAA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ClC,2CAA2C,GAC3C,wBAAwB,CAAC;AAE7B,qEAAqE;AACrE,wBAAgB,kBAAkB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAItD;AAqBD,oEAAoE;AACpE,wBAAgB,aAAa,CAAC,OAAO,CAAC,EAAE;IAAE,MAAM,CAAC,EAAE,MAAM,CAAA;CAAE,GAAG,MAAM,CA0BnE;AAED,sEAAsE;AACtE,wBAAgB,iBAAiB,CAC/B,IAAI,EAAE,qBAAqB,EAC3B,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EAC9B,MAAM,EAAE,MAAM,GACb,MAAM,CAsBR;AAED,mEAAmE;AACnE,wBAAgB,YAAY,CAC1B,IAAI,EAAE,gBAAgB,EACtB,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EAC9B,MAAM,EAAE,MAAM,GACb,MAAM,CA6CR;AAED,+DAA+D;AAC/D,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAI3D;AAED,gEAAgE;AAChE,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAI5D"}
package/esm/core/i18n.js CHANGED
@@ -11,7 +11,20 @@ export function normalizeLocaleTag(tag) {
11
11
  }
12
12
  function envGet(key) {
13
13
  try {
14
- return dntShim.Deno.env.get(key);
14
+ const proc = dntShim.dntGlobalThis
15
+ .process;
16
+ const fromProcess = proc?.env?.[key];
17
+ if (fromProcess !== undefined)
18
+ return fromProcess;
19
+ }
20
+ catch {
21
+ // ignore
22
+ }
23
+ try {
24
+ const runtime = dntShim.dntGlobalThis;
25
+ const env = runtime["Deno"]
26
+ ?.env;
27
+ return env?.get(key);
15
28
  }
16
29
  catch {
17
30
  return undefined;
@@ -1,5 +1,5 @@
1
- import type { MiddlewareHandler } from "hono";
2
1
  import type { Container } from "../core/mod.js";
2
+ import type { HonoMiddlewareHandler } from "./public_types.js";
3
3
  /**
4
4
  * Creates a DI scope per request and attaches it via `c.set("di", scope)`.
5
5
  * Disposes the scope after `await next()` (including on handler error, via `finally`).
@@ -7,5 +7,5 @@ import type { Container } from "../core/mod.js";
7
7
  * In the domain layer, avoid injecting `HonoContextToken` / `RequestToken` directly;
8
8
  * map them to port tokens (e.g. `CurrentUser`) in the composition root instead.
9
9
  */
10
- export declare function di(container: Container): MiddlewareHandler;
10
+ export declare function di(container: Container): HonoMiddlewareHandler;
11
11
  //# sourceMappingURL=middleware.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"middleware.d.ts","sourceRoot":"","sources":["../../src/hono/middleware.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,MAAM,CAAC;AAC9C,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAIhD;;;;;;GAMG;AACH,wBAAgB,EAAE,CAAC,SAAS,EAAE,SAAS,GAAG,iBAAiB,CAY1D"}
1
+ {"version":3,"file":"middleware.d.ts","sourceRoot":"","sources":["../../src/hono/middleware.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAChD,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAC;AAI/D;;;;;;GAMG;AACH,wBAAgB,EAAE,CAAC,SAAS,EAAE,SAAS,GAAG,qBAAqB,CAa9D"}
@@ -8,7 +8,7 @@ import { diVariableKey } from "./types.js";
8
8
  * map them to port tokens (e.g. `CurrentUser`) in the composition root instead.
9
9
  */
10
10
  export function di(container) {
11
- return async (c, next) => {
11
+ const handler = async (c, next) => {
12
12
  const scope = container.createScope();
13
13
  scope.set(HonoContextToken, c);
14
14
  scope.set(RequestToken, c.req.raw);
@@ -20,4 +20,5 @@ export function di(container) {
20
20
  await scope.dispose();
21
21
  }
22
22
  };
23
+ return handler;
23
24
  }
package/esm/hono/mod.d.ts CHANGED
@@ -19,6 +19,7 @@
19
19
  * @module
20
20
  */
21
21
  export type { ClassProvider, ClassToken, Container, DependencyEdge, DependencyGraph, DependencyNode, ExistingProvider, FactoryProvider, InjectionToken, Lifetime, Locale, Provider, ProviderType, Scope, Token, ValidateOptions, ValidationIssue, ValidationResult, ValueProvider, } from "../core/mod.js";
22
+ export type { HonoContext, HonoMiddlewareHandler } from "./public_types.js";
22
23
  export { di } from "./middleware.js";
23
24
  export { HonoContextToken, RequestToken } from "./tokens.js";
24
25
  export { diVariableKey, getDI, type HonoDIVariables } from "./types.js";
@@ -1 +1 @@
1
- {"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../../src/hono/mod.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AACH,YAAY,EACV,aAAa,EACb,UAAU,EACV,SAAS,EACT,cAAc,EACd,eAAe,EACf,cAAc,EACd,gBAAgB,EAChB,eAAe,EACf,cAAc,EACd,QAAQ,EACR,MAAM,EACN,QAAQ,EACR,YAAY,EACZ,KAAK,EACL,KAAK,EACL,eAAe,EACf,eAAe,EACf,gBAAgB,EAChB,aAAa,GACd,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,EAAE,EAAE,MAAM,iBAAiB,CAAC;AACrC,OAAO,EAAE,gBAAgB,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC7D,OAAO,EAAE,aAAa,EAAE,KAAK,EAAE,KAAK,eAAe,EAAE,MAAM,YAAY,CAAC"}
1
+ {"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../../src/hono/mod.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AACH,YAAY,EACV,aAAa,EACb,UAAU,EACV,SAAS,EACT,cAAc,EACd,eAAe,EACf,cAAc,EACd,gBAAgB,EAChB,eAAe,EACf,cAAc,EACd,QAAQ,EACR,MAAM,EACN,QAAQ,EACR,YAAY,EACZ,KAAK,EACL,KAAK,EACL,eAAe,EACf,eAAe,EACf,gBAAgB,EAChB,aAAa,GACd,MAAM,gBAAgB,CAAC;AACxB,YAAY,EAAE,WAAW,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAC;AAC5E,OAAO,EAAE,EAAE,EAAE,MAAM,iBAAiB,CAAC;AACrC,OAAO,EAAE,gBAAgB,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC7D,OAAO,EAAE,aAAa,EAAE,KAAK,EAAE,KAAK,eAAe,EAAE,MAAM,YAAY,CAAC"}
@@ -0,0 +1,7 @@
1
+ import type { Context as HonoContextBase } from "hono";
2
+ /** Hono request context (package-public doc type). */
3
+ export interface HonoContext extends HonoContextBase {
4
+ }
5
+ /** Hono middleware signature used by `di()` (package-public doc type). */
6
+ export type HonoMiddlewareHandler = (c: HonoContext, next: () => Promise<void>) => Promise<void | Response>;
7
+ //# sourceMappingURL=public_types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"public_types.d.ts","sourceRoot":"","sources":["../../src/hono/public_types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,IAAI,eAAe,EAAE,MAAM,MAAM,CAAC;AAEvD,sDAAsD;AACtD,MAAM,WAAW,WAAY,SAAQ,eAAe;CAAG;AAEvD,0EAA0E;AAC1E,MAAM,MAAM,qBAAqB,GAAG,CAClC,CAAC,EAAE,WAAW,EACd,IAAI,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,KACtB,OAAO,CAAC,IAAI,GAAG,QAAQ,CAAC,CAAC"}
@@ -0,0 +1 @@
1
+ export {};
@@ -1,7 +1,7 @@
1
- import type { Context } from "hono";
2
1
  import { type Token } from "../core/mod.js";
2
+ import type { HonoContext } from "./public_types.js";
3
3
  /** Current Hono `Context` (resolvable only in request scope) */
4
- export declare const HonoContextToken: Token<Context>;
4
+ export declare const HonoContextToken: Token<HonoContext>;
5
5
  /** Current Web API `Request` (`c.req.raw`; resolvable only in request scope) */
6
6
  export declare const RequestToken: Token<Request>;
7
7
  //# sourceMappingURL=tokens.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"tokens.d.ts","sourceRoot":"","sources":["../../src/hono/tokens.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AACpC,OAAO,EAAE,KAAK,KAAK,EAAS,MAAM,gBAAgB,CAAC;AAEnD,gEAAgE;AAChE,eAAO,MAAM,gBAAgB,EAAE,KAAK,CAAC,OAAO,CAAiC,CAAC;AAE9E,gFAAgF;AAChF,eAAO,MAAM,YAAY,EAAE,KAAK,CAAC,OAAO,CAA6B,CAAC"}
1
+ {"version":3,"file":"tokens.d.ts","sourceRoot":"","sources":["../../src/hono/tokens.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,KAAK,EAAS,MAAM,gBAAgB,CAAC;AACnD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAErD,gEAAgE;AAChE,eAAO,MAAM,gBAAgB,EAAE,KAAK,CAAC,WAAW,CAAqC,CAAC;AAEtF,gFAAgF;AAChF,eAAO,MAAM,YAAY,EAAE,KAAK,CAAC,OAAO,CAA6B,CAAC"}
@@ -1,5 +1,5 @@
1
- import type { Context } from "hono";
2
1
  import type { Scope } from "../core/mod.js";
2
+ import type { HonoContext } from "./public_types.js";
3
3
  /** Context variable key used by `di()` middleware. */
4
4
  export declare const diVariableKey: "di";
5
5
  /** Pass to `new Hono<{ Variables: HonoDIVariables }>()` for typed `getDI(c)`. */
@@ -7,5 +7,5 @@ export type HonoDIVariables = {
7
7
  [diVariableKey]: Scope;
8
8
  };
9
9
  /** Read the request DI scope set by `di()` (use when `Variables` is not generic). */
10
- export declare function getDI(c: Context): Scope;
10
+ export declare function getDI(c: HonoContext): Scope;
11
11
  //# sourceMappingURL=types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/hono/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AACpC,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AAE5C,sDAAsD;AACtD,eAAO,MAAM,aAAa,EAAG,IAAa,CAAC;AAE3C,iFAAiF;AACjF,MAAM,MAAM,eAAe,GAAG;IAC5B,CAAC,aAAa,CAAC,EAAE,KAAK,CAAC;CACxB,CAAC;AAEF,qFAAqF;AACrF,wBAAgB,KAAK,CAAC,CAAC,EAAE,OAAO,GAAG,KAAK,CAEvC"}
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/hono/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AAC5C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAErD,sDAAsD;AACtD,eAAO,MAAM,aAAa,EAAG,IAAa,CAAC;AAE3C,iFAAiF;AACjF,MAAM,MAAM,eAAe,GAAG;IAC5B,CAAC,aAAa,CAAC,EAAE,KAAK,CAAC;CACxB,CAAC;AAEF,qFAAqF;AACrF,wBAAgB,KAAK,CAAC,CAAC,EAAE,WAAW,GAAG,KAAK,CAE3C"}
package/package.json CHANGED
@@ -1,13 +1,30 @@
1
1
  {
2
2
  "name": "@wyrly/hono",
3
- "version": "1.0.4",
4
- "description": "Wyrly DI adapter for Hono",
3
+ "version": "1.0.6",
4
+ "description": "Wyrly DI adapter for Hono — request scope via di() middleware",
5
+ "keywords": [
6
+ "wyrly",
7
+ "dependency-injection",
8
+ "di",
9
+ "typescript",
10
+ "inversion-of-control",
11
+ "ioc",
12
+ "hono",
13
+ "middleware",
14
+ "bun",
15
+ "cloudflare-workers",
16
+ "edge"
17
+ ],
18
+ "homepage": "https://github.com/valid-lab/wyrly/tree/main/packages/hono",
5
19
  "repository": {
6
20
  "type": "git",
7
21
  "url": "git+https://github.com/valid-lab/wyrly.git",
8
22
  "directory": "packages/hono"
9
23
  },
10
24
  "license": "Apache-2.0",
25
+ "bugs": {
26
+ "url": "https://github.com/valid-lab/wyrly/issues"
27
+ },
11
28
  "module": "./esm/hono/mod.js",
12
29
  "exports": {
13
30
  ".": {
@@ -18,14 +35,10 @@
18
35
  "sideEffects": false,
19
36
  "dependencies": {
20
37
  "hono": "4",
21
- "@deno/shim-deno": "~0.18.0",
22
- "@wyrly/core": "^1.0.4"
38
+ "@wyrly/core": "^1.0.6"
23
39
  },
24
40
  "peerDependencies": {
25
41
  "hono": "^4.0.0"
26
42
  },
27
- "devDependencies": {
28
- "@types/node": "^20.9.0"
29
- },
30
43
  "_generatedBy": "dnt@dev"
31
44
  }