@jwn-js/common 2.4.1 → 2.4.2
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/docs/classes/ApiError.html +2 -2
- package/docs/classes/AsyncJwt.html +2 -2
- package/docs/classes/Binding.html +2 -2
- package/docs/classes/Controller.html +2 -2
- package/docs/classes/Jwt.html +2 -2
- package/docs/classes/Memcached.html +2 -2
- package/docs/classes/Model.html +2 -2
- package/docs/classes/Server.html +2 -2
- package/docs/classes/Ssr.html +2 -2
- package/docs/classes/Web.html +2 -2
- package/docs/functions/action.html +1 -1
- package/docs/functions/allow.html +1 -1
- package/docs/functions/body.html +1 -1
- package/docs/functions/codeToStatus.html +1 -1
- package/docs/functions/config-1.html +1 -1
- package/docs/functions/connection.html +1 -1
- package/docs/functions/context.html +1 -1
- package/docs/functions/controller-1.html +1 -1
- package/docs/functions/cookies.html +1 -1
- package/docs/functions/db.html +1 -1
- package/docs/functions/headers.html +1 -1
- package/docs/functions/home.html +1 -1
- package/docs/functions/hostname.html +1 -1
- package/docs/functions/http.html +1 -1
- package/docs/functions/init.html +1 -1
- package/docs/functions/inject.html +1 -1
- package/docs/functions/json.html +1 -1
- package/docs/functions/logerror.html +1 -1
- package/docs/functions/method.html +1 -1
- package/docs/functions/mixin.html +1 -1
- package/docs/functions/mount.html +1 -1
- package/docs/functions/pool.html +1 -1
- package/docs/functions/protocol.html +1 -1
- package/docs/functions/remote.html +1 -1
- package/docs/functions/request.html +1 -1
- package/docs/functions/selectControllersSchema.html +1 -1
- package/docs/functions/stream.html +1 -1
- package/docs/functions/subaction.html +1 -1
- package/docs/functions/url.html +1 -1
- package/docs/functions/xml.html +1 -1
- package/docs/index.html +2 -2
- package/docs/interfaces/ApiErrorMessage.html +2 -2
- package/docs/interfaces/Config.html +2 -2
- package/docs/interfaces/ContextSsr.html +2 -2
- package/docs/interfaces/ContextWeb.html +2 -2
- package/docs/interfaces/OptionsSsr.html +2 -2
- package/docs/interfaces/OptionsWeb.html +2 -2
- package/docs/interfaces/ResponseOptions.html +2 -2
- package/docs/interfaces/Route.html +2 -2
- package/docs/interfaces/Schema.html +2 -2
- package/docs/interfaces/ServerHandler.html +2 -2
- package/docs/interfaces/ServerOptions.html +2 -2
- package/docs/interfaces/ServerWebsocket.html +2 -2
- package/docs/modules.html +2 -2
- package/docs/types/ServerRoutes.html +1 -1
- package/docs/variables/helpers.html +2 -2
- package/index.js +1 -1
- package/index.mjs +1 -1
- package/package.json +1 -1
package/index.mjs
CHANGED
|
@@ -54,4 +54,4 @@ import{ApiError as d}from"./ApiError.mjs";import{codeToStatus as x}from"./Server
|
|
|
54
54
|
FROM app_controllers c
|
|
55
55
|
INNER JOIN app_subactions s ON s.app_controllers_id = c.id
|
|
56
56
|
LEFT JOIN app_actions a ON a.id = s.app_actions_id;
|
|
57
|
-
`)).forEach(s=>{t[s.action_name]={id:s.action_id,name:s.action_name,isActive:!!s.action_is_active,method:s.action_method},e[s.controller_name]=e[s.controller_name]||{id:s.controller_id,name:s.controller_name,isActive:!!s.controller_is_active,isSitemap:!!s.controller_is_sitemap,subactions:[]},e[s.controller_name].subactions.push({id:s.subaction_id,action:s.action_name,name:s.subaction_name,isPermission:!!s.subaction_is_permission,isCheckMethod:!!s.subaction_is_check_method,isLog:!!s.subaction_is_log,isActive:!!s.subaction_is_active,isSync:!!s.subaction_is_sync})}),{controllers:Object.values(e),actions:Object.values(t)}},j=(o,t,e,s)=>{let n=o.controllers.find(h=>h.name===e);if(!n)throw new d({statusCode:404,code:11,message:`Controller ${e} not found is site schema`});if(n=Object.assign({isActive:!0,isSitemap:!1},n),!n.isActive)throw new d({statusCode:404,code:11,message:`Controller ${e} not active is site schema`});let r=n.subactions.find(h=>h.name===s);if(!r)throw new d({statusCode:404,code:11,message:`Subaction ${s} not found is site schema`});if(r=Object.assign({isPermission:!1,isCheckMethod:!1,isLog:!1,isActive:!0},r),!r.isActive)throw new d({statusCode:404,code:11,message:`Subaction ${s} not active is site schema`});let a=o.actions.find(h=>h.name===r.action);if(!a)throw new d({statusCode:404,code:11,message:"Action not found is site schema"});if(a=Object.assign({isActive:!0,method:"any"},a),!a.isActive)throw new d({statusCode:404,code:11,message:`Action ${a.name} not active is site schema`});const i=(a?.method||"").split(",").map(h=>h.trim());if(r.isCheckMethod&&a.method!=="any"&&!i.includes(t))throw new d({statusCode:404,code:11,message:`Controller ${e} action ${a.name} allow only ${a.method} method`});return{controller:{id:n.id,name:n.name,isActive:n.isActive,isSitemap:n.isSitemap},subaction:{id:r.id,name:r.name,isPermission:r.isPermission,isCheckMethod:r.isCheckMethod,isLog:r.isLog,isActive:r.isActive,isSync:!!r.isSync},action:{id:a.id,name:a.name,isActive:a.isActive,method:a.method}}};class $t{constructor(t,e,s){this.defaultRequest={lang:"ru"},this.defaultResponse={statusCode:200,headers:{"content-type":"application/json"},body:{}},this.defaultControllerSubaction={controller:"Index",subaction:"index"},this.res=t,this.req=e,this.res.onAborted(()=>new d({message:"The connection was close",code:1,statusCode:404})),this.context=s,this.context.routes||(this.context.routes=this.context.schema?.controllers.map(n=>({name:n.name,method:n.method,component:n.component,binding:n.binding})))}setDefaultRequest(t){return Object.assign(this.defaultRequest,t),this}async request(t={}){let e={};try{const s=this.req.getQuery(),n=Object.assign({},this.defaultRequest,t,ct.parse(this.req.getQuery()));this.contextWeb={url:this.req.getUrl()+(s?`?${s}`:""),method:this.req.getMethod(),remote:Buffer.from(this.res.getProxiedRemoteAddressAsText()).toString()||Buffer.from(this.res.getRemoteAddressAsText()).toString(),getRequest:()=>n,config:this.context.config,db:this.context.db,stack:this.context.stack||{},headers:{},cookies:this.req.cookies,schema:this.context.schema,routes:this.context.routes,$di:{},hostname:this.req.getHeader("host"),protocol:this.req.getHeader("x-forwarded-proto")||"http"},this.memcachedKey=`${this.contextWeb.protocol}://${this.contextWeb.hostname}${this.contextWeb.url}`,this.req.forEach((c,u)=>this.contextWeb.headers[c]=u);const r=this.contextWeb.headers["content-type"]||"application/json";if(n.controller&&n.subaction&&this.context.schema&&(this.route=this.findRoute(n.controller),Object.defineProperty(this.contextWeb,"$route",{enumerable:!1,configurable:!1,writable:!1,value:this.route}),Object.assign(this.contextWeb,j(this.context.schema,this.contextWeb.method,this.route.name,n.subaction)),this.contextWeb.subaction.isSync)){["get","head"].includes(this.contextWeb.method)||Object.defineProperty(this.contextWeb,"$stream",{enumerable:!1,configurable:!1,writable:!1,value:w(this.res,this.req,!1)});const c=this.importControllerSync(),u=new c;if(this.injectContext(u),n.subaction in u)e=await u[n.subaction]();else throw new d({statusCode:404,code:13,message:`Method ${n.subaction} not found in ${n.controller} route`});e=Object.assign({},this.defaultResponse,e),this.success(e);return}if(["get","head"].includes(this.contextWeb.method)&&this.contextWeb?.stack?.memcached instanceof S){const c=this.contextWeb.stack.memcached;if(c.isConnectedServers()){const u=await c.getPage(this.memcachedKey);if(u){const{data:g,headers:b}=u;this.success({body:g.toString(),headers:b,statusCode:200})}}}if(n.controller=n.controller||this.defaultControllerSubaction.controller,n.subaction=n.subaction||this.defaultControllerSubaction.subaction,!["get","head"].includes(this.contextWeb.method))if(r.indexOf("application/json")!==-1||r.indexOf("text/json")!==-1)Object.assign(n,await R(this.res));else if(r.indexOf("multipart/form-data")!==-1)Object.assign(n,await M(this.res,this.req)),Object.defineProperty(this.contextWeb,"$files",{enumerable:!1,configurable:!1,writable:!1,value:n.files});else if(r.indexOf("application/x-www-form-urlencoded")!==-1)Object.assign(n,await W(this.res));else if(r.indexOf("application/xml")!==-1||r.indexOf("text/xml")!==-1){const c=(await O(this.res)).toString(),u=A.xml2js(c,{compact:!0,cdataKey:"_value",textKey:"_value"});Object.assign(n,u||{})}else r.indexOf("stream")!==-1?Object.defineProperty(this.contextWeb,"$stream",{enumerable:!1,configurable:!1,writable:!1,value:w(this.res,this.req,!1)}):r.indexOf("binary")!==-1?await new Promise(c=>{const u=w(this.res,this.req),g=ht.tmpdir(),b="./body_"+tt.randomBytes(32).toString("hex"),$=rt.resolve(g,b),m=T.createWriteStream($);u.pipe(m),Object.defineProperty(this.contextWeb,"$files",{enumerable:!1,configurable:!1,writable:!1,value:{body:{path:$}}}),u.on("end",()=>c(!0))}):Object.defineProperty(this.contextWeb,"$body",{enumerable:!1,configurable:!1,writable:!1,value:await O(this.res)});if(this.route=this.findRoute(n.controller),Object.assign(this.contextWeb,this.context.schema?j(this.context.schema,this.contextWeb.method,this.route.name,n.subaction):await U(this.contextWeb.db.home,this.contextWeb.method,this.route.name,n.subaction,this.context.stack?.memcached,this.context.stack?.memcachedPrefix,this.context.stack?.memcachedExpiry)),Object.defineProperty(this.contextWeb,"$route",{enumerable:!1,configurable:!1,writable:!1,value:this.route}),this.route.binding){const c=await this.importBinding(),u=new c;this.injectContext(u),this.contextWeb.$di=await this.initComponent(u)}const a=await this.importController(),i=new a;this.injectContext(i);const h=await this.initComponent(i);if(typeof h>"u")if(n.subaction in i)e=await i[n.subaction]();else throw new d({statusCode:404,code:13,message:`Method ${n.subaction} not found in ${n.controller} route`});else e=h;e=Object.assign({},this.defaultResponse,e),this.success(e)}catch(s){this.error(s)}}async importBinding(){let t=this.route.binding.default||this.route.binding;if(L(t)||(t=(await this.route.binding()).default),typeof t!="function")throw new d({statusCode:404,code:12,message:`Binding class not found for ${this.route.name} route`});return t}async importController(){let t=this.route.component.default||this.route.component;if(L(t)||(t=(await this.route.component()).default),typeof t!="function")throw new d({statusCode:404,code:12,message:`Class not found for ${this.route.name} route`});return t}importControllerSync(){const t=this.route.component.default||this.route.component;if(typeof t!="function")throw new d({statusCode:404,code:12,message:`Class not found for ${this.route.name} route`});return t}findRoute(t){const e=this.context.routes.filter(s=>s.name===t&&(s.method===this.contextWeb.method||s.method==="any"||Array.isArray(s.method)&&s.method.includes(this.contextWeb.method)||typeof s.method>"u"))?.[0];if(!e)throw new d({statusCode:404,code:11,message:`Route ${t} not found`});return e}injectContext(t){"$inject"in t&&t.$inject(this.contextWeb)}async initComponent(t){const e=[...new Set(["init",...t.$inits||[]])];for(const s of e)if(t[s]){const n=await t[s]();if(n)return n}}success(t){const e=t.body instanceof P,s=t.body instanceof Uint8Array,n=t.statusCode||200,r=x(n),a=!s&&!e&&C(t.body)?JSON.stringify(t.body):t.body;!s&&!e&&["get","head"].includes(this.contextWeb.method)&&n===200&&t.memcache&&this.contextWeb?.stack?.memcached instanceof S&&this.contextWeb.stack.memcached.setPage(this.memcachedKey,t.headers,a,t.memcache).then(),e?this.res.cork(()=>{this.res.writeStatus(r),this.writeHeaders(t.headers),a.on("data",i=>{this.res.write(i)}).on("end",()=>{this.res.end()})}):this.res.cork(()=>{this.res.writeStatus(r),this.writeHeaders(t.headers),this.res.end(a)})}error(t){const e=t instanceof d&&t.getData()instanceof P;let s=x(404),n=this.defaultResponse.headers,r=t.message;if(t instanceof d){const a={isError:!0,code:t.getCode(),error:t.getMessage()};s=x(t.getStatusCode()),n=Object.assign({},this.defaultResponse.headers,t.getHeaders()||{}),e?r=t.getData():r=C(t.getData())&&Object.keys(t.getData()).length>0?JSON.stringify(t.getData()):JSON.stringify(a)}e?this.res.cork(()=>{this.res.writeStatus(s),this.writeHeaders(n),r.on("data",a=>{this.res.write(a)}).on("end",()=>{this.res.end()})}):this.res.cork(()=>{this.res.writeStatus(s),this.writeHeaders(n),this.res.end(r)})}writeHeaders(t){Object.entries(t).forEach(([e,s])=>{Array.isArray(s)?s.forEach(n=>this.res.writeHeader(e,n)):this.res.writeHeader(e,s)})}}const F={compact:!0,ignoreComment:!0,spaces:4};class k{constructor(){this.responseHeaders={}}setCookieHeader(t,e,s={}){return E(t,e,s)}success(t={},e){return{headers:Object.assign({"content-type":"application/json"},this.responseHeaders,e?.headers||{}),body:{isError:!1,data:t},memcache:e?.memcache||null,statusCode:e?.statusCode||200}}successBuffer(t,e){return{headers:Object.assign({"content-type":"application/octet-stream"},this.responseHeaders,e?.headers||{}),body:t,memcache:e?.memcache||null,statusCode:e?.statusCode||200}}error(t){const e=t,s=e.code?e.code:0,n=e.message?e.message:"Api request error",r=e.statusCode?e.statusCode:404,a=e.data?e.data:{},i=e.response?{status:e.response.status,headers:e.response.headers,config:{url:e.response.url,method:e.response.method,params:e.response.params,headers:e.response.headers},data:e.response.data}:{};return{headers:Object.assign({"content-type":"application/json"},e.headers),body:{isError:!0,error:n,code:s,data:a,stack:process.env.NODE_ENV!=="production"?e.stack:"",response:process.env.NODE_ENV!=="production"?i:{}},statusCode:r}}successXml(t={},e){const s={_declaration:{_attributes:{version:"1.0",encoding:"utf-8"}}},n=this.success(t,e);return{headers:Object.assign({"content-type":"application/xml"},this.responseHeaders,e?.headers||{}),body:A.js2xml(Object.assign(s,{body:{...n.body}}),F),memcache:n.memcache}}errorXml(t){const e=t,s={_declaration:{_attributes:{version:"1.0",encoding:"utf-8"}}},n=this.error(e);return{headers:Object.assign({"content-type":"application/xml"},e.headers),body:A.js2xml(Object.assign(s,{body:{...n.body}}),F),statusCode:n.statusCode}}async $create(t,...e){const s=new t(...e);"$inject"in s&&s.$inject({url:this.$context.url,method:this.$context.method,remote:this.$context.remote,getRequest:this.$context.getRequest,getUrl:this.$context.getUrl,config:this.$context.config,db:this.$context.db,stack:this.$context.stack,headers:this.$context.headers,cookies:this.$context.cookies,controller:this.$context.controller,action:this.$context.action,subaction:this.$context.subaction,schema:this.$context.schema,routes:this.$context.routes,setResponseHeader:(r,a)=>this.setResponseHeader(r,a),setCookieHeader:this.setCookieHeader,$di:this.$context.$di});const n=["init",...s.$inits||[]];for(const r of n)s[r]&&await s[r]();return s}async $createAll(t){return Promise.all(t.map(e=>this.$create(...e)))}$inject(t){this.$context=t}getContext(){return this.$context}getRequest(){return this.$context.getRequest()}getBody(){return this.$context.$body||Buffer.from("")}getFiles(){return this.$context.$files||{}}getStream(){return this.$context.$stream||new q().end()}getConfig(){return this.$context.config}getSchema(){return this.$context.schema}getRoutes(){return this.$context.routes}getMethod(){return this.$context.method}getRemote(){return this.$context.remote}getCookies(){return this.$context.cookies}getHostname(){return this.$context.hostname}getUrl(){return this.$context.url}getProtocol(){return this.$context.protocol}getDb(){return this.$context.db}getHeaders(){return this.$context.headers}getController(){return this.$context.controller}getAction(){return this.$context.action}getSubaction(){return this.$context.subaction}getHome(){return this.getDb().home}getPool(t="home"){return this.getDb()[t]}getStack(){return this.$context.stack}setResponseHeader(t,e){this.responseHeaders.hasOwnProperty(t)?(this.responseHeaders[t]=Array.isArray(this.responseHeaders[t])?this.responseHeaders[t]:[this.responseHeaders[t]],this.responseHeaders[t].push(e)):this.responseHeaders[t]=e}}class K{async $create(t,...e){const s=new t(...e);return"$inject"in s&&s.$inject({url:this.$context.url,method:this.$context.method,getRequest:this.$context.getRequest,config:this.$context.config,db:this.$context.db,stack:this.$context.stack,headers:this.$context.headers,cookies:this.$context.cookies,controller:this.$context.controller,action:this.$context.action,subaction:this.$context.subaction,schema:this.$context.schema,routes:this.$context.routes,setResponseHeader:this.$context.setResponseHeader,setCookieHeader:this.$context.setCookieHeader,$di:this.$context.$di}),"init"in s&&await s.init(),s}async $createAll(t){return Promise.all(t.map(e=>this.$create(...e)))}$inject(t){this.$context=t}getContext(){return this.$context}getRequest(){return this.$context.getRequest()}getUrl(){return this.$context.url}getConfig(){return this.$context.config}getSchema(){return this.$context.schema}getRoutes(){return this.$context.routes}getMethod(){return this.$context.method}getRemote(){return this.$context.remote}getHeaders(){return this.$context.headers}getCookies(){return this.$context.cookies}getController(){return this.$context.controller}getAction(){return this.$context.action}getSubaction(){return this.$context.subaction}getDb(){return this.$context.db}getHome(){return this.$context.db.home}getPool(t="home"){return this.getDb()[t]}getStack(){return this.$context.stack}setResponseHeader(t,e){return this.$context.setResponseHeader(t,e)}setCookieHeader(t,e,s={}){return this.$context.setCookieHeader(t,e,s)}}class Q{async $create(t,...e){const s=new t(...e);return"$inject"in s&&s.$inject({url:this.$context.url,method:this.$context.method,getRequest:this.$context.getRequest,config:this.$context.config,db:this.$context.db,stack:this.$context.stack,headers:this.$context.headers,cookies:this.$context.cookies,controller:this.$context.controller,action:this.$context.action,subaction:this.$context.subaction,schema:this.$context.schema,routes:this.$context.routes,setResponseHeader:this.$context.setResponseHeader,setCookieHeader:this.$context.setCookieHeader,$di:this.$context.$di}),"init"in s&&await s.init(),s}async $createAll(t){return Promise.all(t.map(e=>this.$create(...e)))}$inject(t){this.$context=t}getContext(){return this.$context}getRequest(){return this.$context.getRequest()}getUrl(){return this.$context.url}getConfig(){return this.$context.config}getSchema(){return this.$context.schema}getRoutes(){return this.$context.routes}getMethod(){return this.$context.method}getRemote(){return this.$context.remote}getHeaders(){return this.$context.headers}getCookies(){return this.$context.cookies}getController(){return this.$context.controller}getAction(){return this.$context.action}getSubaction(){return this.$context.subaction}getDb(){return this.$context.db}getPool(t="home"){return this.getDb()[t]}getStack(){return this.$context.stack}}const _t=async(o,t,e={},s)=>{const n=async i=>{const h=[...new Set(["init",...i.$inits||[]])];for(const c of h)if(i[c]){const u=await i[c]();if(u)return u}},r=(i,h)=>{"$inject"in i&&i.$inject(h)};t=Object.assign({config:{},getRequest:()=>e,method:"get",...e.controller&&e.subaction&&t.db?.home&&!t.schema?await U(t.db.home,t.method||"get",e.controller,e.subaction):{},...e.controller&&e.subaction&&t.schema?j(t.schema,t.method||"get",e.controller,e.subaction):{},cookies:{},hostname:"",protocol:"http",headers:{}},t);const a=new o(...s||[]);if(a instanceof k)return r(a,t),t.$initResponse=await n(a),a;if(a instanceof K||a instanceof Q){const i=new class extends k{async init(){this.model=await this.$create(o,...s||[])}getModel(){return this.model}};return r(i,t),t.$initResponse=await n(i),i.getModel()}else throw new d({message:"Class should be an instance of Controller or Model or Binding",statusCode:400})},f=Symbol("arguments"),V=Symbol("connections"),v=Symbol("response"),X=Symbol("init"),z=Symbol("logger"),G=Symbol("filters"),yt=o=>o.charAt(0).toUpperCase()+o.slice(1);function wt(o){const t=(s,n)=>{for(const a of Reflect.ownKeys(n))Object.defineProperty(s.prototype,a,{value:n[a]});const r=Object.getPrototypeOf(n);r&&t(s,r)};function e(s){return t(s,o),s}return e}const l=(o,t,e,s,n,r)=>{const a=Reflect.getOwnMetadata(o,t,e)||{};a[s]={type:n,params:r},Reflect.defineMetadata(o,a,t,e)};function St(){return function(o,t,e){l(f,o,t,e,"request")}}function Ct(){return function(o,t,e){l(f,o,t,e,"context")}}function At(){return function(o,t,e){l(f,o,t,e,"config")}}function Ot(){return function(o,t,e){l(f,o,t,e,"method")}}function jt(){return function(o,t,e){l(f,o,t,e,"remote")}}function kt(){return function(o,t,e){l(f,o,t,e,"cookies")}}function vt(){return function(o,t,e){l(f,o,t,e,"hostname")}}function Ht(){return function(o,t,e){l(f,o,t,e,"url")}}function Rt(){return function(o,t,e){l(f,o,t,e,"protocol")}}function qt(){return function(o,t,e){l(f,o,t,e,"db")}}function Pt(){return function(o,t,e){l(f,o,t,e,"headers")}}function Wt(){return function(o,t,e){l(f,o,t,e,"controller")}}function Mt(){return function(o,t,e){l(f,o,t,e,"action")}}function Bt(){return function(o,t,e){l(f,o,t,e,"subaction")}}function Et(){return function(o,t,e){l(f,o,t,e,"body")}}function Nt(){return function(o,t,e){l(f,o,t,e,"stream")}}function Dt(){return function(o,t,e){l(f,o,t,e,"home")}}function Jt(o="home"){return function(t,e,s){l(f,t,e,s,"pool",o)}}function Tt(o="home"){return function(t,e,s){l(V,t,e,s,"connection",o)}}function Lt(o={}){return function(t,e,s){l(v,t,e,0,"json",o)}}function It(o={}){return function(t,e,s){l(v,t,e,0,"xml",o)}}function Ut(o){return function(t,e,s){l(z,t,e,o,"logger",o)}}function Ft(o){return function(t,e,s){const n={format:"json"},r=s.value;s.value=async function(){o&&Object.assign(n,await o.apply(this)||{});const a=[],i=[],h=Reflect.getOwnMetadata(f,t,e)||{},c=Reflect.getOwnMetadata(V,t,e)||{},u=Reflect.getOwnMetadata(z,t,e)||{},g=Reflect.getOwnMetadata(v,t,e)?.[0]||{type:"json",params:{}},b=Reflect.getOwnMetadata(X,t,e)?.[0]||{type:"",params:{}},$=(Reflect.getOwnMetadata(G,t,e)?.[0]||{type:"allow",params:[]}).params;if($.length&&!$.includes(this.getMethod())&&this.getMethod()!=="any")throw new d({statusCode:404,code:11,message:`Controller ${this.getController().name} subaction ${this.getSubaction().name} allow only ${$.join(",")} methods`});for(const m in h){if(!h.hasOwnProperty(m))continue;const p=`get${yt(h[m].type)}`;a[+m]=this[p](h[m].params)}for(const m in c)c.hasOwnProperty(m)&&(c[m].type,a[+m]=await this.getDb()[c[m].params].getConnection(),i.push(a[+m]));try{let m=await r.apply(this,a),p;if(Array.isArray(m)&&([m,p]=m),b.type!=="init")return n.format==="xml"||g.type==="xml"?this.successXml(m,Object.assign(g.params,p||{})):n.format==="buffer"?this.successBuffer(m,Object.assign(g.params,p||{})):this.success(m,Object.assign(g.params,p||{}))}catch(m){await Promise.all([...i.map(_=>_.rollback())]);let p;n.format==="xml"||g.type==="xml"?p=this.errorXml(m):p=this.error(m);for(const _ in u){if(!u.hasOwnProperty(_))continue;const Y=u[_].params;await this[Y].error(m,{response:at(p?.body||{},["stack"])})}return p}finally{await Promise.all([...i.map(m=>m.release())])}}}}function Kt(){return function(o,t,e){l(X,o,t,0,"init"),"$inits"in o||Object.defineProperty(o,"$inits",{value:[]}),o.$inits.push(t)}}function Qt(o){return o=(Array.isArray(o)?o:[o]).map(t=>t.toLowerCase()),function(t,e,s){l(G,t,e,0,"allow",o)}}function Vt(o){return function(t,e){delete t[e]&&Object.defineProperty(t,e,{get:function(){return this.$di[o||e]},enumerable:!0,configurable:!1})}}const Xt={cookieParse:B,cookieString:E,jsonBody:R,rawBody:O,streamBody:w,urlencodedBody:W,multipartBody:M,readConfig:ot,readConfigSync:nt,staticBody:J,extensions:D,getExt:N,jwtDecode:dt,readJsonConfigsSync:lt};export{d as ApiError,ut as AsyncJwt,Q as Binding,k as Controller,Se as Jwt,S as Memcached,K as Model,ye as Server,ft as Ssr,$t as Web,Mt as action,Qt as allow,Et as body,x as codeToStatus,At as config,Tt as connection,Ct as context,Wt as controller,kt as cookies,qt as db,Pt as headers,Xt as helpers,Dt as home,vt as hostname,Ft as http,Kt as init,Vt as inject,Lt as json,Ut as logerror,Ot as method,wt as mixin,_t as mount,Jt as pool,Rt as protocol,jt as remote,St as request,xt as selectControllersSchema,Nt as stream,Bt as subaction,Ht as url,It as xml};
|
|
57
|
+
`)).forEach(s=>{t[s.action_name]={id:s.action_id,name:s.action_name,isActive:!!s.action_is_active,method:s.action_method},e[s.controller_name]=e[s.controller_name]||{id:s.controller_id,name:s.controller_name,isActive:!!s.controller_is_active,isSitemap:!!s.controller_is_sitemap,subactions:[]},e[s.controller_name].subactions.push({id:s.subaction_id,action:s.action_name,name:s.subaction_name,isPermission:!!s.subaction_is_permission,isCheckMethod:!!s.subaction_is_check_method,isLog:!!s.subaction_is_log,isActive:!!s.subaction_is_active,isSync:!!s.subaction_is_sync})}),{controllers:Object.values(e),actions:Object.values(t)}},j=(o,t,e,s)=>{let n=o.controllers.find(h=>h.name===e);if(!n)throw new d({statusCode:404,code:11,message:`Controller ${e} not found is site schema`});if(n=Object.assign({isActive:!0,isSitemap:!1},n),!n.isActive)throw new d({statusCode:404,code:11,message:`Controller ${e} not active is site schema`});let r=n.subactions.find(h=>h.name===s);if(!r)throw new d({statusCode:404,code:11,message:`Subaction ${s} not found is site schema`});if(r=Object.assign({isPermission:!1,isCheckMethod:!1,isLog:!1,isActive:!0},r),!r.isActive)throw new d({statusCode:404,code:11,message:`Subaction ${s} not active is site schema`});let a=o.actions.find(h=>h.name===r.action);if(!a)throw new d({statusCode:404,code:11,message:"Action not found is site schema"});if(a=Object.assign({isActive:!0,method:"any"},a),!a.isActive)throw new d({statusCode:404,code:11,message:`Action ${a.name} not active is site schema`});const i=(a?.method||"").split(",").map(h=>h.trim());if(r.isCheckMethod&&a.method!=="any"&&!i.includes(t))throw new d({statusCode:404,code:11,message:`Controller ${e} action ${a.name} allow only ${a.method} method`});return{controller:{id:n.id,name:n.name,isActive:n.isActive,isSitemap:n.isSitemap},subaction:{id:r.id,name:r.name,isPermission:r.isPermission,isCheckMethod:r.isCheckMethod,isLog:r.isLog,isActive:r.isActive,isSync:!!r.isSync},action:{id:a.id,name:a.name,isActive:a.isActive,method:a.method}}};class $t{constructor(t,e,s){this.defaultRequest={lang:"ru"},this.defaultResponse={statusCode:200,headers:{"content-type":"application/json"},body:{}},this.defaultControllerSubaction={controller:"Index",subaction:"index"},this.res=t,this.req=e,this.res.onAborted(()=>new d({message:"The connection was close",code:1,statusCode:404})),this.context=s,this.context.routes||(this.context.routes=this.context.schema?.controllers.map(n=>({name:n.name,method:n.method,component:n.component,binding:n.binding})))}setDefaultRequest(t){return Object.assign(this.defaultRequest,t),this}async request(t={}){let e={};try{const s=this.req.getQuery(),n=Object.assign({},this.defaultRequest,t,ct.parse(this.req.getQuery()));this.contextWeb={url:this.req.getUrl()+(s?`?${s}`:""),method:this.req.getMethod(),remote:Buffer.from(this.res.getProxiedRemoteAddressAsText()).toString()||Buffer.from(this.res.getRemoteAddressAsText()).toString(),getRequest:()=>n,config:this.context.config,db:this.context.db,stack:this.context.stack||{},headers:{},cookies:this.req.cookies,schema:this.context.schema,routes:this.context.routes,$di:{},hostname:this.req.getHeader("host"),protocol:this.req.getHeader("x-forwarded-proto")||"http"},this.memcachedKey=`${this.contextWeb.protocol}://${this.contextWeb.hostname}${this.contextWeb.url}`,this.req.forEach((c,u)=>this.contextWeb.headers[c]=u);const r=this.contextWeb.headers["content-type"]||"application/json";if(n.controller&&n.subaction&&this.context.schema&&(this.route=this.findRoute(n.controller),Object.defineProperty(this.contextWeb,"$route",{enumerable:!1,configurable:!1,writable:!1,value:this.route}),Object.assign(this.contextWeb,j(this.context.schema,this.contextWeb.method,this.route.name,n.subaction)),this.contextWeb.subaction.isSync)){["get","head"].includes(this.contextWeb.method)||Object.defineProperty(this.contextWeb,"$stream",{enumerable:!1,configurable:!1,writable:!1,value:w(this.res,this.req,!1)});const c=this.importControllerSync(),u=new c;if(this.injectContext(u),n.subaction in u)e=await u[n.subaction]();else throw new d({statusCode:404,code:13,message:`Method ${n.subaction} not found in ${n.controller} route`});e=Object.assign({},this.defaultResponse,e),this.success(e);return}if(["get","head"].includes(this.contextWeb.method)&&this.contextWeb?.stack?.memcached instanceof S){const c=this.contextWeb.stack.memcached;if(c.isConnectedServers()){const u=await c.getPage(this.memcachedKey);if(u){const{data:g,headers:b}=u;this.success({body:g.toString(),headers:b,statusCode:200})}}}if(n.controller=n.controller||this.defaultControllerSubaction.controller,n.subaction=n.subaction||this.defaultControllerSubaction.subaction,!["get","head"].includes(this.contextWeb.method))if(r.indexOf("application/json")!==-1||r.indexOf("text/json")!==-1)Object.assign(n,await R(this.res));else if(r.indexOf("multipart/form-data")!==-1)Object.assign(n,await M(this.res,this.req)),Object.defineProperty(this.contextWeb,"$files",{enumerable:!1,configurable:!1,writable:!1,value:n.files});else if(r.indexOf("application/x-www-form-urlencoded")!==-1)Object.assign(n,await W(this.res));else if(r.indexOf("application/xml")!==-1||r.indexOf("text/xml")!==-1){const c=(await O(this.res)).toString(),u=A.xml2js(c,{compact:!0,cdataKey:"_value",textKey:"_value"});Object.assign(n,u||{})}else r.indexOf("stream")!==-1?Object.defineProperty(this.contextWeb,"$stream",{enumerable:!1,configurable:!1,writable:!1,value:w(this.res,this.req,!1)}):r.indexOf("binary")!==-1?await new Promise(c=>{const u=w(this.res,this.req),g=ht.tmpdir(),b="./body_"+tt.randomBytes(32).toString("hex"),$=rt.resolve(g,b),m=T.createWriteStream($);u.pipe(m),Object.defineProperty(this.contextWeb,"$files",{enumerable:!1,configurable:!1,writable:!1,value:{body:{path:$}}}),u.on("end",()=>c(!0))}):Object.defineProperty(this.contextWeb,"$body",{enumerable:!1,configurable:!1,writable:!1,value:await O(this.res)});if(this.route=this.findRoute(n.controller),Object.assign(this.contextWeb,this.context.schema?j(this.context.schema,this.contextWeb.method,this.route.name,n.subaction):await U(this.contextWeb.db.home,this.contextWeb.method,this.route.name,n.subaction,this.context.stack?.memcached,this.context.stack?.memcachedPrefix,this.context.stack?.memcachedExpiry)),Object.defineProperty(this.contextWeb,"$route",{enumerable:!1,configurable:!1,writable:!1,value:this.route}),this.route.binding){const c=await this.importBinding(),u=new c;this.injectContext(u),this.contextWeb.$di=await this.initComponent(u)}const a=await this.importController(),i=new a;this.injectContext(i);const h=await this.initComponent(i);if(typeof h>"u")if(n.subaction in i)e=await i[n.subaction]();else throw new d({statusCode:404,code:13,message:`Method ${n.subaction} not found in ${n.controller} route`});else e=h;e=Object.assign({},this.defaultResponse,e),this.success(e)}catch(s){this.error(s)}}async importBinding(){let t=this.route.binding.default||this.route.binding;if(L(t)||(t=(await this.route.binding()).default),typeof t!="function")throw new d({statusCode:404,code:12,message:`Binding class not found for ${this.route.name} route`});return t}async importController(){let t=this.route.component.default||this.route.component;if(L(t)||(t=(await this.route.component()).default),typeof t!="function")throw new d({statusCode:404,code:12,message:`Class not found for ${this.route.name} route`});return t}importControllerSync(){const t=this.route.component.default||this.route.component;if(typeof t!="function")throw new d({statusCode:404,code:12,message:`Class not found for ${this.route.name} route`});return t}findRoute(t){const e=this.context.routes.filter(s=>s.name===t&&(s.method===this.contextWeb.method||s.method==="any"||Array.isArray(s.method)&&s.method.includes(this.contextWeb.method)||typeof s.method>"u"))?.[0];if(!e)throw new d({statusCode:404,code:11,message:`Route ${t} not found`});return e}injectContext(t){"$inject"in t&&t.$inject(this.contextWeb)}async initComponent(t){const e=[...new Set(["init",...t.$inits||[]])];for(const s of e)if(t[s]){const n=await t[s]();if(n)return n}}success(t){const e=t.body instanceof P,s=t.body instanceof Uint8Array,n=t.statusCode||200,r=x(n),a=!s&&!e&&C(t.body)?JSON.stringify(t.body):t.body;!s&&!e&&["get","head"].includes(this.contextWeb.method)&&n===200&&t.memcache&&this.contextWeb?.stack?.memcached instanceof S&&this.contextWeb.stack.memcached.setPage(this.memcachedKey,t.headers,a,t.memcache).then(),e?this.res.cork(()=>{this.res.writeStatus(r),this.writeHeaders(t.headers),a.on("data",i=>{this.res.write(i)}).on("end",()=>{this.res.end()})}):this.res.cork(()=>{this.res.writeStatus(r),this.writeHeaders(t.headers),this.res.end(a)})}error(t){const e=t instanceof d&&t.getData()instanceof P;let s=x(404),n=this.defaultResponse.headers,r=t.message;if(t instanceof d){const a={isError:!0,code:t.getCode(),error:t.getMessage()};s=x(t.getStatusCode()),n=Object.assign({},this.defaultResponse.headers,t.getHeaders()||{}),e?r=t.getData():r=C(t.getData())&&Object.keys(t.getData()).length>0?JSON.stringify(t.getData()):JSON.stringify(a)}e?this.res.cork(()=>{this.res.writeStatus(s),this.writeHeaders(n),r.on("data",a=>{this.res.write(a)}).on("end",()=>{this.res.end()})}):this.res.cork(()=>{this.res.writeStatus(s),this.writeHeaders(n),this.res.end(r)})}writeHeaders(t){Object.entries(t).forEach(([e,s])=>{Array.isArray(s)?s.forEach(n=>this.res.writeHeader(e,n)):this.res.writeHeader(e,s)})}}const F={compact:!0,ignoreComment:!0,spaces:4};class k{constructor(){this.responseHeaders={}}setCookieHeader(t,e,s={}){return E(t,e,s)}success(t={},e){return{headers:Object.assign({"content-type":"application/json"},this.responseHeaders,e?.headers||{}),body:{isError:!1,data:t},memcache:e?.memcache||null,statusCode:e?.statusCode||200}}successBuffer(t,e){return{headers:Object.assign({"content-type":"application/octet-stream"},this.responseHeaders,e?.headers||{}),body:t,memcache:e?.memcache||null,statusCode:e?.statusCode||200}}error(t){const e=t,s=e.code?e.code:0,n=e.message?e.message:"Api request error",r=e.statusCode?e.statusCode:404,a=e.data?e.data:{},i=e.response?{status:e.response.status,headers:e.response.headers,config:{url:e.response.url,method:e.response.method,params:e.response.params,headers:e.response.headers},data:e.response.data}:{};return{headers:Object.assign({"content-type":"application/json"},e.headers),body:{isError:!0,error:n,code:s,data:a,stack:process.env.NODE_ENV!=="production"?e.stack:"",response:process.env.NODE_ENV!=="production"?i:{}},statusCode:r}}successXml(t={},e){const s={_declaration:{_attributes:{version:"1.0",encoding:"utf-8"}}},n=this.success(t,e);return{headers:Object.assign({"content-type":"application/xml"},this.responseHeaders,e?.headers||{}),body:A.js2xml(Object.assign(s,{body:{...n.body}}),F),memcache:n.memcache}}errorXml(t){const e=t,s={_declaration:{_attributes:{version:"1.0",encoding:"utf-8"}}},n=this.error(e);return{headers:Object.assign({"content-type":"application/xml"},e.headers),body:A.js2xml(Object.assign(s,{body:{...n.body}}),F),statusCode:n.statusCode}}async $create(t,...e){const s=new t(...e);"$inject"in s&&s.$inject({url:this.$context.url,method:this.$context.method,remote:this.$context.remote,getRequest:this.$context.getRequest,getUrl:this.$context.getUrl,config:this.$context.config,db:this.$context.db,stack:this.$context.stack,headers:this.$context.headers,cookies:this.$context.cookies,controller:this.$context.controller,action:this.$context.action,subaction:this.$context.subaction,schema:this.$context.schema,routes:this.$context.routes,setResponseHeader:(r,a)=>this.setResponseHeader(r,a),setCookieHeader:this.setCookieHeader,$di:this.$context.$di});const n=["init",...s.$inits||[]];for(const r of n)s[r]&&await s[r]();return s}async $createAll(t){return Promise.all(t.map(e=>this.$create(...e)))}$inject(t){this.$context=t}getContext(){return this.$context}getRequest(){return this.$context.getRequest()}getBody(){return this.$context.$body||Buffer.from("")}getFiles(){return this.$context.$files||{}}getStream(){return this.$context.$stream||new q().end()}getConfig(){return this.$context.config}getSchema(){return this.$context.schema}getRoutes(){return this.$context.routes}getMethod(){return this.$context.method}getRemote(){return this.$context.remote}getCookies(){return this.$context.cookies}getHostname(){return this.$context.hostname}getUrl(){return this.$context.url}getProtocol(){return this.$context.protocol}getDb(){return this.$context.db}getHeaders(){return this.$context.headers}getController(){return this.$context.controller}getAction(){return this.$context.action}getSubaction(){return this.$context.subaction}getHome(){return this.getDb().home}getPool(t="home"){return this.getDb()[t]}getStack(){return this.$context.stack}setResponseHeader(t,e){this.responseHeaders.hasOwnProperty(t)?(this.responseHeaders[t]=Array.isArray(this.responseHeaders[t])?this.responseHeaders[t]:[this.responseHeaders[t]],this.responseHeaders[t].push(e)):this.responseHeaders[t]=e}}class K{async $create(t,...e){const s=new t(...e);return"$inject"in s&&s.$inject({url:this.$context.url,method:this.$context.method,getRequest:this.$context.getRequest,config:this.$context.config,db:this.$context.db,stack:this.$context.stack,headers:this.$context.headers,cookies:this.$context.cookies,controller:this.$context.controller,action:this.$context.action,subaction:this.$context.subaction,schema:this.$context.schema,routes:this.$context.routes,setResponseHeader:this.$context.setResponseHeader,setCookieHeader:this.$context.setCookieHeader,$di:this.$context.$di}),"init"in s&&await s.init(),s}async $createAll(t){return Promise.all(t.map(e=>this.$create(...e)))}$inject(t){this.$context=t}getContext(){return this.$context}getRequest(){return this.$context.getRequest()}getUrl(){return this.$context.url}getConfig(){return this.$context.config}getSchema(){return this.$context.schema}getRoutes(){return this.$context.routes}getMethod(){return this.$context.method}getRemote(){return this.$context.remote}getHeaders(){return this.$context.headers}getCookies(){return this.$context.cookies}getController(){return this.$context.controller}getAction(){return this.$context.action}getSubaction(){return this.$context.subaction}getDb(){return this.$context.db}getHome(){return this.$context.db.home}getPool(t="home"){return this.getDb()[t]}getStack(){return this.$context.stack}setResponseHeader(t,e){return this.$context.setResponseHeader(t,e)}setCookieHeader(t,e,s={}){return this.$context.setCookieHeader(t,e,s)}}class Q{async $create(t,...e){const s=new t(...e);return"$inject"in s&&s.$inject({url:this.$context.url,method:this.$context.method,getRequest:this.$context.getRequest,config:this.$context.config,db:this.$context.db,stack:this.$context.stack,headers:this.$context.headers,cookies:this.$context.cookies,controller:this.$context.controller,action:this.$context.action,subaction:this.$context.subaction,schema:this.$context.schema,routes:this.$context.routes,setResponseHeader:this.$context.setResponseHeader,setCookieHeader:this.$context.setCookieHeader,$di:this.$context.$di}),"init"in s&&await s.init(),s}async $createAll(t){return Promise.all(t.map(e=>this.$create(...e)))}$inject(t){this.$context=t}getContext(){return this.$context}getRequest(){return this.$context.getRequest()}getUrl(){return this.$context.url}getConfig(){return this.$context.config}getSchema(){return this.$context.schema}getRoutes(){return this.$context.routes}getMethod(){return this.$context.method}getRemote(){return this.$context.remote}getHeaders(){return this.$context.headers}getCookies(){return this.$context.cookies}getController(){return this.$context.controller}getAction(){return this.$context.action}getSubaction(){return this.$context.subaction}getDb(){return this.$context.db}getPool(t="home"){return this.getDb()[t]}getStack(){return this.$context.stack}}const _t=async(o,t,e={},s)=>{const n=async i=>{const h=[...new Set(["init",...i.$inits||[]])];for(const c of h)if(i[c]){const u=await i[c]();if(u)return u}},r=(i,h)=>{"$inject"in i&&i.$inject(h)};t=Object.assign({config:{},getRequest:()=>e,method:"get",...e.controller&&e.subaction&&t.db?.home&&!t.schema?await U(t.db.home,t.method||"get",e.controller,e.subaction):{},...e.controller&&e.subaction&&t.schema?j(t.schema,t.method||"get",e.controller,e.subaction):{},cookies:{},hostname:"",protocol:"http",headers:{}},t);const a=new o(...s||[]);if(a instanceof k)return r(a,t),t.$initResponse=await n(a),a;if(a instanceof K||a instanceof Q){const i=new class extends k{async init(){this.model=await this.$create(o,...s||[])}getModel(){return this.model}};return r(i,t),t.$initResponse=await n(i),i.getModel()}else throw new d({message:"Class should be an instance of Controller or Model or Binding",statusCode:400})},f=Symbol("arguments"),V=Symbol("connections"),v=Symbol("response"),X=Symbol("init"),z=Symbol("logger"),G=Symbol("filters"),yt=o=>o.charAt(0).toUpperCase()+o.slice(1);function wt(o){const t=(s,n)=>{for(const a of Reflect.ownKeys(n))Object.defineProperty(s.prototype,a,{value:n[a]});const r=Object.getPrototypeOf(n);r&&t(s,r)};function e(s){return t(s,o),s}return e}const l=(o,t,e,s,n,r)=>{const a=Reflect.getOwnMetadata(o,t,e)||{};a[s]={type:n,params:r},Reflect.defineMetadata(o,a,t,e)};function St(){return function(o,t,e){l(f,o,t,e,"request")}}function Ct(){return function(o,t,e){l(f,o,t,e,"context")}}function At(){return function(o,t,e){l(f,o,t,e,"config")}}function Ot(){return function(o,t,e){l(f,o,t,e,"method")}}function jt(){return function(o,t,e){l(f,o,t,e,"remote")}}function kt(){return function(o,t,e){l(f,o,t,e,"cookies")}}function vt(){return function(o,t,e){l(f,o,t,e,"hostname")}}function Ht(){return function(o,t,e){l(f,o,t,e,"url")}}function Rt(){return function(o,t,e){l(f,o,t,e,"protocol")}}function qt(){return function(o,t,e){l(f,o,t,e,"db")}}function Pt(){return function(o,t,e){l(f,o,t,e,"headers")}}function Wt(){return function(o,t,e){l(f,o,t,e,"controller")}}function Mt(){return function(o,t,e){l(f,o,t,e,"action")}}function Bt(){return function(o,t,e){l(f,o,t,e,"subaction")}}function Et(){return function(o,t,e){l(f,o,t,e,"body")}}function Nt(){return function(o,t,e){l(f,o,t,e,"stream")}}function Dt(){return function(o,t,e){l(f,o,t,e,"home")}}function Jt(o="home"){return function(t,e,s){l(f,t,e,s,"pool",o)}}function Tt(o="home"){return function(t,e,s){l(V,t,e,s,"connection",o)}}function Lt(o={}){return function(t,e,s){l(v,t,e,0,"json",o)}}function It(o={}){return function(t,e,s){l(v,t,e,0,"xml",o)}}function Ut(o){return function(t,e,s){l(z,t,e,o,"logger",o)}}function Ft(o){return function(t,e,s){const n={format:"json"},r=s.value;s.value=async function(){o&&Object.assign(n,await o.apply(this)||{});const a=[],i=[],h=Reflect.getOwnMetadata(f,t,e)||{},c=Reflect.getOwnMetadata(V,t,e)||{},u=Reflect.getOwnMetadata(z,t,e)||{},g=Reflect.getOwnMetadata(v,t,e)?.[0]||{type:"json",params:{}},b=Reflect.getOwnMetadata(X,t,e)?.[0]||{type:"",params:{}},$=(Reflect.getOwnMetadata(G,t,e)?.[0]||{type:"allow",params:[]}).params;if($.length&&!$.includes(this.getMethod())&&this.getMethod()!=="any")throw new d({statusCode:404,code:11,message:`Controller ${this.getController().name} subaction ${this.getSubaction().name} allow only ${$.join(",")} methods`});for(const m in h){if(!h.hasOwnProperty(m))continue;const p=`get${yt(h[m].type)}`;a[+m]=this[p](h[m].params)}for(const m in c)c.hasOwnProperty(m)&&(c[m].type,a[+m]=await this.getDb()[c[m].params].getConnection(),i.push(a[+m]));try{let m=await r.apply(this,a),p;if(Array.isArray(m)&&([m,p]=m),b.type!=="init")return n.format==="xml"||g.type==="xml"?this.successXml(m,Object.assign(g.params,p||{})):n.format==="buffer"?this.successBuffer(m,Object.assign(g.params,p||{})):this.success(m,Object.assign(g.params,p||{}))}catch(m){await Promise.all([...i.map(_=>_.rollback())]);let p;n.format==="xml"||g.type==="xml"?p=this.errorXml(m):p=this.error(m);for(const _ in u){if(!u.hasOwnProperty(_))continue;const Y=u[_].params;await this[Y].error(m,{response:at(p?.body||{},["stack"])})}return p}finally{await Promise.all([...i.map(m=>m.release())])}}}}function Kt(){return function(o,t,e){l(X,o,t,0,"init"),"$inits"in o||Object.defineProperty(o,"$inits",{value:[]}),o.$inits.push(t)}}function Qt(o){return o=(Array.isArray(o)?o:[o]).map(t=>t.toLowerCase()),function(t,e,s){l(G,t,e,0,"allow",o)}}function Vt(o){return function(t,e){delete t[e]&&Object.defineProperty(t,e,{get:function(){return this.$context.$di[o||e]},enumerable:!0,configurable:!1})}}const Xt={cookieParse:B,cookieString:E,jsonBody:R,rawBody:O,streamBody:w,urlencodedBody:W,multipartBody:M,readConfig:ot,readConfigSync:nt,staticBody:J,extensions:D,getExt:N,jwtDecode:dt,readJsonConfigsSync:lt};export{d as ApiError,ut as AsyncJwt,Q as Binding,k as Controller,Se as Jwt,S as Memcached,K as Model,ye as Server,ft as Ssr,$t as Web,Mt as action,Qt as allow,Et as body,x as codeToStatus,At as config,Tt as connection,Ct as context,Wt as controller,kt as cookies,qt as db,Pt as headers,Xt as helpers,Dt as home,vt as hostname,Ft as http,Kt as init,Vt as inject,Lt as json,Ut as logerror,Ot as method,wt as mixin,_t as mount,Jt as pool,Rt as protocol,jt as remote,St as request,xt as selectControllersSchema,Nt as stream,Bt as subaction,Ht as url,It as xml};
|