@lucidcms/core
Version:
The core of the Lucid CMS. It's responsible for spinning up the API and serving the CMS.
2 lines • 4.55 kB
JavaScript
import{constants_default as e,translations_default as t}from"./errors-RyYO6qM6.js";import n from"zod/v4";const r=e=>{let t=new URL(e.req.url);return t},i=e=>{try{let t=r(e);return t.toString().split(`?`)[0]||``}catch(t){return e.req.url||``}},a=(e,t)=>{let n=[];if(!t.pagination)return n;let{page:i,perPage:a,count:o}=t.pagination,s=Math.ceil(o/Number(a));try{let t=r(e);for(let e=0;e<s;e++){let r=new URL(t.toString());e===0?r.searchParams.delete(`page`):r.searchParams.set(`page`,String(e+1)),n.push({active:i===e+1,label:String(e+1),url:r.toString(),page:e+1})}return n}catch(e){return console.error(`Error in buildMetaLinks:`,e),n}},o=(e,t)=>{if(t.pagination)try{let{page:n,perPage:i,count:a}=t.pagination,o=i===-1?1:Math.ceil(a/Number(i)),s=r(e),c={first:null,last:null,next:null,prev:null},l=new URL(s.toString());l.searchParams.delete(`page`),c.first=l.toString();let u=new URL(s.toString());if(n!==o&&u.searchParams.set(`page`,String(o)),c.last=u.toString(),n!==o){let e=new URL(s.toString());e.searchParams.set(`page`,String(Number(n)+1)),c.next=e.toString()}if(n!==1){let e=new URL(s.toString());e.searchParams.set(`page`,String(Number(n)-1)),c.prev=e.toString()}return c}catch(e){console.error(`Error in buildLinks:`,e);return}},s=(e,t)=>{let n=null;t.pagination&&(n=t.pagination.perPage===-1?1:Math.ceil(t.pagination.count/Number(t.pagination.perPage)));let r={path:i(e),links:a(e,t),currentPage:t.pagination?.page??null,perPage:t.pagination?.perPage??null,total:Number(t.pagination?.count)||null,lastPage:n},s=o(e,t);return{data:t.data||null,meta:r,links:s}};var c=s;const l={type:`object`,properties:{path:{type:`string`},links:{type:`array`,items:{}},currentPage:{type:`number`,nullable:!0,example:null},lastPage:{type:`number`,nullable:!0,example:null},perPage:{type:`number`,nullable:!0,example:null},total:{type:`number`,nullable:!0,example:null}}},u={type:`object`,properties:{path:{type:`string`},links:{type:`array`,items:{type:`object`,properties:{active:{type:`boolean`},label:{type:`string`},url:{type:`string`,nullable:!0},page:{type:`number`}}}},currentPage:{type:`number`,nullable:!0,example:e.query.page},lastPage:{type:`number`,nullable:!0,example:200/e.query.perPage},perPage:{type:`number`,nullable:!0,example:e.query.perPage},total:{type:`number`,nullable:!0,example:200}}},d={type:`object`,properties:{first:{type:`string`,nullable:!0},last:{type:`string`,nullable:!0},next:{type:`string`,nullable:!0},prev:{type:`string`,nullable:!0}}},f={type:`object`,description:t(`swagger_response_default`),properties:{status:{type:`number`,nullable:!0},code:{type:`string`,nullable:!0},name:{type:`string`,nullable:!0},message:{type:`string`,nullable:!0},errors:{type:`object`,nullable:!0,additionalProperties:!0}},additionalProperties:!0},p=e=>{let n={};return e?.schema?n[200]={description:t(`swagger_response_200`),content:{"application/json":{schema:e.noProperties===!0?{type:`object`,nullable:!0}:{type:`object`,properties:{data:e.schema,meta:e.paginated?u:l,...e.paginated?{links:d}:{}}}}}}:n[204]={description:t(`swagger_response_204`),content:{"application/json":{schema:{type:`object`,nullable:!0}}}},n.default={description:t(`swagger_response_default`),content:{"application/json":{schema:f}}},n};var m=p;const h=e=>({content:{"application/json":{schema:n.toJSONSchema(e)}}});var g=h;const _=e=>{let r=[];if(e.headers?.csrf!==void 0&&r.push({in:`header`,name:`_csrf`,required:e.headers.csrf,description:t(`swagger_csrf_header_description`),schema:{type:`string`}}),e.headers?.contentLocale!==void 0&&r.push({in:`header`,name:`lucid-content-locale`,required:e.headers.contentLocale,description:t(`swagger_content_locale_header_description`),example:`en`,schema:{type:`string`}}),e.headers?.authorization!==void 0&&r.push({in:`header`,name:`Authorization`,required:e.headers.authorization,description:t(`swagger_authorization_header_description`),schema:{type:`string`}}),e.params){let t=n.toJSONSchema(e.params);if(t.properties)for(let[e,n]of Object.entries(t.properties)){let t=n;r.push({name:e,in:`path`,required:!0,description:t.description,example:t.example})}}if(e.query){let t=n.toJSONSchema(e.query);if(t.properties)for(let[e,n]of Object.entries(t.properties)){let i=n;r.push({name:e,in:`query`,required:t.required?.includes(e),description:i.description,example:i.example})}}return r};var v=_;export{c as build_response_default,f as defaultErrorResponse,v as hono_swagger_paramaters_default,g as hono_swagger_request_body_default,m as hono_swagger_response_default};
//# sourceMappingURL=swagger-B1fvTrVq.js.map