@lowerdeck/hono 1.0.3 → 1.0.5

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/package.json CHANGED
@@ -1,9 +1,15 @@
1
1
  {
2
2
  "name": "@lowerdeck/hono",
3
- "version": "1.0.3",
3
+ "version": "1.0.5",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
7
+ "files": [
8
+ "src/**",
9
+ "dist/**",
10
+ "README.md",
11
+ "package.json"
12
+ ],
7
13
  "author": "Tobias Herber",
8
14
  "license": "Apache 2",
9
15
  "type": "module",
@@ -21,17 +27,17 @@
21
27
  "scripts": {
22
28
  "test": "vitest run --passWithNoTests",
23
29
  "lint": "prettier src/**/*.ts --check",
24
- "build": "microbundle"
30
+ "build": "rm -rf ./dist && microbundle"
25
31
  },
26
32
  "dependencies": {
27
33
  "hono": "^4.5.5",
28
- "@lowerdeck/forwarded-for": "^1.0.2",
29
- "@lowerdeck/validation": "^1.0.2",
30
- "@lowerdeck/error": "^1.0.6"
34
+ "@lowerdeck/forwarded-for": "^1.0.4",
35
+ "@lowerdeck/validation": "^1.0.4",
36
+ "@lowerdeck/error": "^1.0.8"
31
37
  },
32
38
  "devDependencies": {
33
39
  "microbundle": "^0.15.1",
34
- "@lowerdeck/tsconfig": "^1.0.0",
40
+ "@lowerdeck/tsconfig": "^1.0.1",
35
41
  "typescript": "5.8.2",
36
42
  "vitest": "^3.1.2"
37
43
  }
@@ -1,14 +0,0 @@
1
-
2
- $ microbundle
3
- No name was provided for external module '@lowerdeck/forwarded-for' in output.globals – guessing 'forwardedFor'
4
- No name was provided for external module '@lowerdeck/error' in output.globals – guessing 'error'
5
- No name was provided for external module 'hono/cors' in output.globals – guessing 'cors'
6
- Build "@lowerdeck/hono" to dist:
7
- 821 B: index.cjs.gz
8
- 707 B: index.cjs.br
9
- 720 B: index.module.js.gz
10
- 626 B: index.module.js.br
11
- 805 B: index.module.js.gz
12
- 705 B: index.module.js.br
13
- 911 B: index.umd.js.gz
14
- 782 B: index.umd.js.br
@@ -1,11 +0,0 @@
1
-
2
- $ vitest run --passWithNoTests
3
- [?25l
4
-  RUN  v3.2.4 /Users/tobias/code/metorial/metorial-enterprise/oss/src/packages/server/hono
5
-
6
- No test files found, exiting with code 0
7
-
8
- include: **/*.{test,spec}.?(c|m)[jt]s?(x)
9
- exclude: **/node_modules/**, **/dist/**, **/cypress/**, **/.{idea,git,cache,output,temp}/**, **/{karma,rollup,webpack,vite,vitest,jest,ava,babel,nyc,cypress,tsup,build,eslint,prettier}.config.*
10
-
11
- [?25h
package/CHANGELOG.md DELETED
@@ -1,29 +0,0 @@
1
- # @lowerdeck/hono
2
-
3
- ## 1.0.3
4
-
5
- ### Patch Changes
6
-
7
- - update versions
8
- - Updated dependencies
9
- - @lowerdeck/forwarded-for@1.0.2
10
- - @lowerdeck/validation@1.0.2
11
- - @lowerdeck/error@1.0.6
12
-
13
- ## 1.0.2
14
-
15
- ### Patch Changes
16
-
17
- - sync
18
- - Updated dependencies
19
- - @lowerdeck/error@1.0.5
20
-
21
- ## 1.0.1
22
-
23
- ### Patch Changes
24
-
25
- - Fix exports
26
- - Updated dependencies
27
- - @lowerdeck/forwarded-for@1.0.1
28
- - @lowerdeck/validation@1.0.1
29
- - @lowerdeck/error@1.0.1
@@ -1,2 +0,0 @@
1
- import{parseForwardedFor as e}from"@lowerdeck/forwarded-for";import{notFoundError as r,isServiceError as o,internalServerError as t,ServiceError as n,badRequestError as a,validationError as s}from"@lowerdeck/error";import{Hono as l}from"hono";export{cors}from"hono/cors";let i=r=>{var o,t,n,a;return{ua:r.req.header("user-agent"),ip:null!=(o=e(null!=(t=null!=(n=null!=(a=r.req.header("metorial-connecting-ip"))?a:r.req.header("cf-connecting-ip"))?n:r.req.header("x-forwarded-for"))?t:r.req.header("x-real-ip")))?o:"0.0.0.0"}},d=e=>{let n=new l;return e&&(n=n.basePath(e)),n.use(async(e,r)=>{await r(),e.res.headers.set("X-Powered-By","Metorial")}),n.notFound(e=>e.json(r("endpoint",null).toResponse(),404)),n.onError((e,r)=>o(e)?r.json(e.toResponse(),e.data.status):(console.error(e),r.json(t().toResponse(),500))),n},c=async(e,r)=>{var o;let t;if(null!=(o=e.req.header("Content-Type"))&&o.includes("application/x-www-form-urlencoded"))t=Object.fromEntries(new URLSearchParams(await e.req.text()));else try{t=await e.req.json()}catch(e){throw new n(a({message:"Invalid JSON body"}))}let l=r.validate(t);if(!l.success)throw new n(s({entity:"body",errors:l.errors}));return l.value},u=async(e,r)=>{let o;try{o=e.req.query()}catch(e){throw new n(a({message:"Invalid JSON body"}))}let t=r.validate(o);if(!t.success)throw new n(s({entity:"query",errors:t.errors}));return t.value};export{d as createHono,i as useRequestContext,c as useValidatedBody,u as useValidatedQuery};
2
- //# sourceMappingURL=index.modern.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.modern.js","sources":["../src/context.ts","../src/hono.ts","../src/validation.ts"],"sourcesContent":["import { parseForwardedFor } from '@lowerdeck/forwarded-for';\nimport { Context } from 'hono';\n\nexport let useRequestContext = (c: Context) => {\n let ua = c.req.header('user-agent');\n let ip =\n parseForwardedFor(\n c.req.header('metorial-connecting-ip') ??\n c.req.header('cf-connecting-ip') ??\n c.req.header('x-forwarded-for') ??\n c.req.header('x-real-ip')\n ) ?? '0.0.0.0';\n\n return { ua, ip };\n};\n","import { internalServerError, isServiceError, notFoundError } from '@lowerdeck/error';\nimport { Context, Env, Hono } from 'hono';\nimport { cors } from 'hono/cors';\n\nexport { cors, type Context };\n\nexport let createHono = <E extends Env>(basePath?: string) => {\n let app = new Hono<E>();\n if (basePath) app = app.basePath(basePath);\n\n app.use(async (c, next) => {\n await next();\n\n c.res.headers.set('X-Powered-By', 'Metorial');\n });\n\n app.notFound(c => {\n return c.json(notFoundError('endpoint', null).toResponse(), 404);\n });\n\n app.onError((e, c) => {\n if (isServiceError(e)) {\n return c.json(e.toResponse(), e.data.status);\n }\n\n console.error(e);\n\n return c.json(internalServerError().toResponse(), 500);\n });\n\n return app;\n};\n","import { badRequestError, ServiceError, validationError } from '@lowerdeck/error';\nimport { ValidationType } from '@lowerdeck/validation';\nimport { Context } from 'hono';\n\nexport let useValidatedBody = async <T>(c: Context, v: ValidationType<T>): Promise<T> => {\n let body: any;\n\n if (c.req.header('Content-Type')?.includes('application/x-www-form-urlencoded')) {\n body = Object.fromEntries(new URLSearchParams(await c.req.text()));\n } else {\n try {\n body = await c.req.json();\n } catch (e) {\n throw new ServiceError(\n badRequestError({\n message: 'Invalid JSON body'\n })\n );\n }\n }\n\n let val = v.validate(body);\n if (!val.success) {\n throw new ServiceError(\n validationError({\n entity: 'body',\n errors: val.errors\n })\n );\n }\n\n return val.value;\n};\n\nexport let useValidatedQuery = async <T>(c: Context, v: ValidationType<T>): Promise<T> => {\n let body: any;\n\n try {\n body = c.req.query();\n } catch (e) {\n throw new ServiceError(\n badRequestError({\n message: 'Invalid JSON body'\n })\n );\n }\n\n let val = v.validate(body);\n if (!val.success) {\n throw new ServiceError(\n validationError({\n entity: 'query',\n errors: val.errors\n })\n );\n }\n\n return val.value;\n};\n"],"names":["useRequestContext","c","_parseForwardedFor","_ref","_ref2","_c$req$header","ua","req","header","ip","parseForwardedFor","createHono","basePath","app","Hono","use","async","next","res","headers","set","notFound","json","notFoundError","toResponse","onError","e","isServiceError","data","status","console","error","internalServerError","useValidatedBody","v","body","includes","Object","fromEntries","URLSearchParams","text","ServiceError","badRequestError","message","val","validate","success","validationError","entity","errors","value","useValidatedQuery","query"],"mappings":"+QAGW,IAAAA,EAAqBC,QAAcC,EAAAC,EAAAC,EAAAC,EAU5C,MAAO,CAAEC,GATAL,EAAEM,IAAIC,OAAO,cASTC,UARPP,EACJQ,EAGmCP,OAHlBA,SAAAC,EACuB,OADvBC,EACfJ,EAAEM,IAAIC,OAAO,2BAAyBH,EACpCJ,EAAEM,IAAIC,OAAO,qBAAmBJ,EAChCH,EAAEM,IAAIC,OAAO,oBAAkBL,EAC/BF,EAAEM,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https://json.schemastore.org/tsconfig",
3
- "extends": "@lowerdeck/tsconfig/base.json",
4
- "exclude": ["dist"],
5
- "include": ["src"],
6
- "compilerOptions": {
7
- "outDir": "dist",
8
- "lib": ["es2021"],
9
- "target": "ES2019"
10
- }
11
- }