hono-openapi 0.3.1 → 0.4.0
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/LICENSE +21 -21
- package/README.md +252 -252
- package/arktype.cjs +1 -0
- package/arktype.d.cts +1 -0
- package/arktype.d.ts +1 -0
- package/arktype.js +1 -0
- package/effect.cjs +1 -0
- package/effect.d.cts +1 -0
- package/effect.d.ts +1 -0
- package/effect.js +1 -0
- package/index.cjs +1 -0
- package/index.d.cts +1 -0
- package/index.d.ts +1 -0
- package/index.js +1 -0
- package/package.json +77 -32
- package/src/arktype.d.ts +13 -1
- package/src/effect.d.ts +12 -1
- package/src/helper.d.ts +1 -1
- package/src/index.d.ts +3 -3
- package/src/openapi.d.ts +200 -3
- package/src/route.d.ts +41 -1
- package/src/typebox.d.ts +13 -1
- package/src/types.d.ts +7 -4
- package/src/utils.d.ts +1 -1
- package/src/valibot.d.ts +13 -1
- package/src/zod.d.ts +13 -1
- package/typebox.cjs +1 -0
- package/typebox.d.cts +1 -0
- package/typebox.d.ts +1 -0
- package/typebox.js +1 -0
- package/valibot.cjs +1 -0
- package/valibot.d.cts +1 -0
- package/valibot.d.ts +1 -0
- package/valibot.js +1 -0
- package/zod.cjs +1 -0
- package/zod.d.cts +1 -0
- package/zod.d.ts +1 -0
- package/zod.js +1 -0
- package/arktype.cjs.d.ts +0 -1
- package/arktype.cjs.js +0 -1
- package/arktype.esm.d.ts +0 -1
- package/arktype.esm.js +0 -1
- package/effect.cjs.d.ts +0 -1
- package/effect.cjs.js +0 -1
- package/effect.esm.d.ts +0 -1
- package/effect.esm.js +0 -1
- package/index.cjs.d.ts +0 -1
- package/index.cjs.js +0 -1
- package/index.esm.d.ts +0 -1
- package/index.esm.js +0 -1
- package/typebox.cjs.d.ts +0 -1
- package/typebox.cjs.js +0 -1
- package/typebox.esm.d.ts +0 -1
- package/typebox.esm.js +0 -1
- package/valibot.cjs.d.ts +0 -1
- package/valibot.cjs.js +0 -1
- package/valibot.esm.d.ts +0 -1
- package/valibot.esm.js +0 -1
- package/zod.cjs.d.ts +0 -1
- package/zod.cjs.js +0 -1
- package/zod.esm.d.ts +0 -1
- package/zod.esm.js +0 -1
- /package/{toOpenAPISchema.cjs.js → toOpenAPISchema.cjs} +0 -0
- /package/{toOpenAPISchema.esm.js → toOpenAPISchema.js} +0 -0
- /package/{utils.cjs.js → utils.cjs} +0 -0
- /package/{utils.esm.js → utils.js} +0 -0
package/arktype.esm.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "./src\\arktype";
|
package/arktype.esm.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{arktypeValidator as a}from"@hono/arktype-validator";import{c as o}from"./toOpenAPISchema.esm.js";import{u as r,g as t}from"./utils.esm.js";import"json-schema-walker";function s(a){return{builder:async r=>({schema:await o(a.toJsonSchema())}),validator:o=>{a(o)}}}function e(o,e,i){const n=a(o,e,i);return Object.assign(n,{[r]:{resolver:async a=>t(o,await s(e).builder(a))}})}export{s as resolver,e as validator};
|
package/effect.cjs.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "./src\\effect";
|
package/effect.cjs.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";var e=require("@hono/effect-validator"),r=require("effect"),a=require("./toOpenAPISchema.cjs.js"),t=require("./utils.cjs.js");function i(e){return{builder:async t=>({schema:await a.convert(r.JSONSchema.make(e))}),validator:async a=>{await r.Schema.decodeUnknownPromise(e)(a)}}}require("json-schema-walker"),exports.resolver=i,exports.validator=function(r,a){const o=e.effectValidator(r,a);return Object.assign(o,{[t.uniqueSymbol]:{resolver:async e=>t.generateValidatorDocs(r,await i(a).builder(e))}})};
|
package/effect.esm.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "./src\\effect";
|
package/effect.esm.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{effectValidator as e}from"@hono/effect-validator";import{JSONSchema as o,Schema as a}from"effect";import{c as r}from"./toOpenAPISchema.esm.js";import{u as t,g as s}from"./utils.esm.js";import"json-schema-walker";function i(e){return{builder:async a=>({schema:await r(o.make(e))}),validator:async o=>{await a.decodeUnknownPromise(e)(o)}}}function n(o,a){const r=e(o,a);return Object.assign(r,{[t]:{resolver:async e=>s(o,await i(a).builder(e))}})}export{i as resolver,n as validator};
|
package/index.cjs.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "./src\\index";
|
package/index.cjs.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";var e=require("hono/http-exception"),t=require("./utils.cjs.js");const n=["GET","PUT","POST","DELETE","OPTIONS","HEAD","PATCH","TRACE"],s=e=>e.charAt(0).toUpperCase()+e.slice(1),o=(e,t)=>{let n=e;if("/"===t)return`${n}Index`;for(const e of t.split("/"))123===e.charCodeAt(0)?n+=`By${s(e.slice(1,-1))}`:n+=s(e);return n};function c({path:e,method:t,data:n,schema:s}){e=(e=>e.split("/").map((e=>{let t=e;return t.startsWith(":")&&(t=t.slice(1,t.length),t.endsWith("?")&&(t=t.slice(0,-1)),t=`{${t}}`),t})).join("/"))(e);const c=t.toLowerCase();s[e]={...s[e]?s[e]:{},[c]:{responses:{},...s[e]?.[c]??{},operationId:o(c,e),...n}}}function i(e,{excludeStaticFile:t=!0,exclude:n=[]}){const s={};for(const[o,c]of Object.entries(e))if(!(n.some((e=>"string"==typeof e?o===e:e.test(o)))||o.includes("*")||t&&o.includes("."))){for(const e of Object.keys(c)){const t=c[e];if(o.includes("{")){t.parameters||(t.parameters=[]);const e=o.split("/").filter((e=>e.startsWith("{")&&!t.parameters.find((t=>"path"===t.in&&t.name===e.slice(1,e.length-1)))));for(const n of e){const e=n.slice(1,n.length-1),s=t.parameters.findIndex((t=>"param"===t.in&&t.name===e));-1!==s?t.parameters[s].in="path":t.parameters.push({schema:{type:"string"},in:"path",name:e,required:!0})}}t.responses||(t.responses={200:{}})}s[o]=c}return s}exports.describeRoute=function(n){const{validateResponse:s,...o}=n;return Object.assign((async(t,o)=>{if(await o(),s&&n.responses){const s=t.res.status,o=t.res.headers.get("content-type");if(s&&o){const c=n.responses[s];if(c&&"content"in c&&c.content){const n=o.split(";")[0],s=c.content[n];if(s?.schema&&"validator"in s.schema)try{let e;if("application/json"===n?e=await t.res.json():"text/plain"===n&&(e=await t.res.text()),!e)throw new Error("No data to validate!");await s.schema.validator(e)}catch(t){throw new e.HTTPException(400,{message:"Response validation failed!"})}}}}}),{[t.uniqueSymbol]:{resolver:async e=>{let t={};if(o.responses)for(const n of Object.keys(o.responses)){const s=o.responses[n];if(!s||"content"in s)for(const n of Object.keys(s.content??{})){const o=s.content?.[n];if(o&&(o.schema&&"builder"in o.schema)){const n=await o.schema.builder(e);o.schema=n.schema,n.components&&(t={...t,...n.components})}}}return{docs:o,components:t}}}})},exports.openAPISpecs=function(e,{documentation:s={},excludeStaticFile:o=!0,exclude:a=[],excludeMethods:r=["OPTIONS"],excludeTags:l=[]}={documentation:{},excludeStaticFile:!0,exclude:[],excludeMethods:["OPTIONS"],excludeTags:[]}){const p={version:"3.1.0",components:{}},d={};let m=null;return async u=>{if(m)return u.json(m);for(const s of e.routes){if(!(t.uniqueSymbol in s.handler))continue;if(r.includes(s.method))continue;if(!1===n.includes(s.method)&&"ALL"!==s.method)continue;const{resolver:e,metadata:o={}}=s.handler[t.uniqueSymbol],{docs:i,components:a}=await e({...p,...o});if(p.components={...p.components,...a??{}},"ALL"===s.method)for(const e of n)c({path:s.path,data:i,method:e,schema:d});else c({method:s.method,path:s.path,data:i,schema:d})}for(const e in d)for(const t in d[e]){const n=d[e][t]?.hide;n&&("boolean"==typeof n?n:n(u))&&delete d[e][t]}return m={openapi:p.version,...{...s,tags:s.tags?.filter((e=>!l?.includes(e?.name))),info:{title:"Hono Documentation",description:"Development documentation",version:"0.0.0",...s.info},paths:{...i(d,{excludeStaticFile:o,exclude:Array.isArray(a)?a:[a]}),...s.paths},components:{...s.components,schemas:{...p.components,...s.components?.schemas}}}},u.json(m)}};
|
package/index.esm.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "./src\\index";
|
package/index.esm.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{HTTPException as e}from"hono/http-exception";import{u as t}from"./utils.esm.js";function n(n){const{validateResponse:s,...o}=n;return Object.assign((async(t,o)=>{if(await o(),s&&n.responses){const s=t.res.status,o=t.res.headers.get("content-type");if(s&&o){const a=n.responses[s];if(a&&"content"in a&&a.content){const n=o.split(";")[0],s=a.content[n];if(s?.schema&&"validator"in s.schema)try{let e;if("application/json"===n?e=await t.res.json():"text/plain"===n&&(e=await t.res.text()),!e)throw new Error("No data to validate!");await s.schema.validator(e)}catch(t){throw new e(400,{message:"Response validation failed!"})}}}}}),{[t]:{resolver:async e=>{let t={};if(o.responses)for(const n of Object.keys(o.responses)){const s=o.responses[n];if(!s||"content"in s)for(const n of Object.keys(s.content??{})){const o=s.content?.[n];if(o&&(o.schema&&"builder"in o.schema)){const n=await o.schema.builder(e);o.schema=n.schema,n.components&&(t={...t,...n.components})}}}return{docs:o,components:t}}}})}const s=["GET","PUT","POST","DELETE","OPTIONS","HEAD","PATCH","TRACE"],o=e=>e.charAt(0).toUpperCase()+e.slice(1),a=(e,t)=>{let n=e;if("/"===t)return`${n}Index`;for(const e of t.split("/"))123===e.charCodeAt(0)?n+=`By${o(e.slice(1,-1))}`:n+=o(e);return n};function c({path:e,method:t,data:n,schema:s}){e=(e=>e.split("/").map((e=>{let t=e;return t.startsWith(":")&&(t=t.slice(1,t.length),t.endsWith("?")&&(t=t.slice(0,-1)),t=`{${t}}`),t})).join("/"))(e);const o=t.toLowerCase();s[e]={...s[e]?s[e]:{},[o]:{responses:{},...s[e]?.[o]??{},operationId:a(o,e),...n}}}function i(e,{excludeStaticFile:t=!0,exclude:n=[]}){const s={};for(const[o,a]of Object.entries(e))if(!(n.some((e=>"string"==typeof e?o===e:e.test(o)))||o.includes("*")||t&&o.includes("."))){for(const e of Object.keys(a)){const t=a[e];if(o.includes("{")){t.parameters||(t.parameters=[]);const e=o.split("/").filter((e=>e.startsWith("{")&&!t.parameters.find((t=>"path"===t.in&&t.name===e.slice(1,e.length-1)))));for(const n of e){const e=n.slice(1,n.length-1),s=t.parameters.findIndex((t=>"param"===t.in&&t.name===e));-1!==s?t.parameters[s].in="path":t.parameters.push({schema:{type:"string"},in:"path",name:e,required:!0})}}t.responses||(t.responses={200:{}})}s[o]=a}return s}function r(e,{documentation:n={},excludeStaticFile:o=!0,exclude:a=[],excludeMethods:r=["OPTIONS"],excludeTags:l=[]}={documentation:{},excludeStaticFile:!0,exclude:[],excludeMethods:["OPTIONS"],excludeTags:[]}){const p={version:"3.1.0",components:{}},d={};let m=null;return async h=>{if(m)return h.json(m);for(const n of e.routes){if(!(t in n.handler))continue;if(r.includes(n.method))continue;if(!1===s.includes(n.method)&&"ALL"!==n.method)continue;const{resolver:e,metadata:o={}}=n.handler[t],{docs:a,components:i}=await e({...p,...o});if(p.components={...p.components,...i??{}},"ALL"===n.method)for(const e of s)c({path:n.path,data:a,method:e,schema:d});else c({method:n.method,path:n.path,data:a,schema:d})}for(const e in d)for(const t in d[e]){const n=d[e][t]?.hide;n&&("boolean"==typeof n?n:n(h))&&delete d[e][t]}return m={openapi:p.version,...{...n,tags:n.tags?.filter((e=>!l?.includes(e?.name))),info:{title:"Hono Documentation",description:"Development documentation",version:"0.0.0",...n.info},paths:{...i(d,{excludeStaticFile:o,exclude:Array.isArray(a)?a:[a]}),...n.paths},components:{...n.components,schemas:{...p.components,...n.components?.schemas}}}},h.json(m)}}export{n as describeRoute,r as openAPISpecs};
|
package/typebox.cjs.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "./src\\typebox";
|
package/typebox.cjs.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";var e=require("@hono/typebox-validator"),r=require("./toOpenAPISchema.cjs.js"),a=require("@sinclair/typebox/value"),t=require("./utils.cjs.js");function i(e){return{builder:async a=>({schema:await r.convert(e)}),validator:r=>{a.Value.Parse(e,r)}}}require("json-schema-walker"),exports.resolver=i,exports.validator=function(r,a,s){const o=e.tbValidator(r,a,s);return Object.assign(o,{[t.uniqueSymbol]:{resolver:async e=>t.generateValidatorDocs(r,await i(a).builder(e))}})};
|
package/typebox.esm.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "./src\\typebox";
|
package/typebox.esm.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{tbValidator as r}from"@hono/typebox-validator";import{c as o}from"./toOpenAPISchema.esm.js";import{Value as a}from"@sinclair/typebox/value";import{u as t,g as e}from"./utils.esm.js";import"json-schema-walker";function s(r){return{builder:async a=>({schema:await o(r)}),validator:o=>{a.Parse(r,o)}}}function i(o,a,i){const m=r(o,a,i);return Object.assign(m,{[t]:{resolver:async r=>e(o,await s(a).builder(r))}})}export{s as resolver,i as validator};
|
package/valibot.cjs.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "./src\\valibot";
|
package/valibot.cjs.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";var e=require("@hono/valibot-validator"),r=require("./toOpenAPISchema.cjs.js"),a=require("@valibot/to-json-schema"),t=require("valibot"),o=require("./utils.cjs.js");function s(e){return{builder:async t=>({schema:await r.convert(a.toJsonSchema(e))}),validator:async r=>{await t.parseAsync(e,r)}}}require("json-schema-walker"),exports.resolver=s,exports.validator=function(r,a,t){const i=e.vValidator(r,a,t);return Object.assign(i,{[o.uniqueSymbol]:{resolver:async e=>o.generateValidatorDocs(r,await s(a).builder(e))}})};
|
package/valibot.esm.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "./src\\valibot";
|
package/valibot.esm.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{vValidator as o}from"@hono/valibot-validator";import{c as a}from"./toOpenAPISchema.esm.js";import{toJsonSchema as t}from"@valibot/to-json-schema";import{parseAsync as r}from"valibot";import{u as i,g as s}from"./utils.esm.js";import"json-schema-walker";function m(o){return{builder:async r=>({schema:await a(t(o))}),validator:async a=>{await r(o,a)}}}function e(a,t,r){const e=o(a,t,r);return Object.assign(e,{[i]:{resolver:async o=>s(a,await m(t).builder(o))}})}export{m as resolver,e as validator};
|
package/zod.cjs.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "./src\\zod";
|
package/zod.cjs.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";var e=require("@hono/zod-validator"),r=require("zod-openapi"),a=require("./utils.cjs.js");function t(e){return{builder:a=>{const{version:t,...o}=a??{};return r.createSchema(e,a?{openapi:t,...o}:void 0)},validator:e.parse}}exports.resolver=t,exports.validator=function(r,o,i){const n=e.zValidator(r,o,i);return Object.assign(n,{[a.uniqueSymbol]:{resolver:async e=>a.generateValidatorDocs(r,await t(o).builder(e)),metadata:{schemaType:"input"}}})};
|
package/zod.esm.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "./src\\zod";
|
package/zod.esm.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{zValidator as o}from"@hono/zod-validator";import{createSchema as r}from"zod-openapi";import{u as t,g as a}from"./utils.esm.js";function e(o){return{builder:t=>{const{version:a,...e}=t??{};return r(o,t?{openapi:a,...e}:void 0)},validator:o.parse}}function i(r,i,n){const s=o(r,i,n);return Object.assign(s,{[t]:{resolver:async o=>a(r,await e(i).builder(o)),metadata:{schemaType:"input"}}})}export{e as resolver,i as validator};
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|