@sumor/app
Advanced tools
Comparing version 17.0.8 to 17.0.9
@@ -1,1 +0,1 @@ | ||
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define("Sumor_App",[],t):"object"==typeof exports?exports.Sumor_App=t():e.Sumor_App=t()}("undefined"!=typeof self?self:this,(function(){return function(e){var t={};function r(o){if(t[o])return t[o].exports;var n=t[o]={i:o,l:!1,exports:{}};return e[o].call(n.exports,n,n.exports,r),n.l=!0,n.exports}return r.m=e,r.c=t,r.d=function(e,t,o){r.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:o})},r.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},r.t=function(e,t){if(1&t&&(e=r(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var o=Object.create(null);if(r.r(o),Object.defineProperty(o,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var n in e)r.d(o,n,function(t){return e[t]}.bind(null,n));return o},r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,"a",t),t},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.p="",r(r.s=6)}([function(e,t){e.exports=require("@sumor/utils")},function(e,t){e.exports=require("@sumor/base")},function(e,t){e.exports=require("selfsigned")},function(e,t){e.exports=require("http")},function(e,t){e.exports=require("express")},function(e,t){e.exports=require("spdy")},function(e,t,r){"use strict";r.r(t),r.d(t,"App",(function(){return g})),r.d(t,"_meta",(function(){return h}));var o=r(1),n=r.n(o),a=r(0),i=r.n(a),s=r(2),c=r.n(s),l=async(e,t)=>{const r={key:e+"/domain.key",cert:e+"/domain.cer",ca:e+"/ca.cer"};let o=await i.a.file.exists(r.key)&&await i.a.file.exists(r.cert);if(o||(await(async(e,t)=>{t=t||"selfsigned";const r=await new Promise((e,r)=>{c.a.generate([{name:"commonName",value:t}],{days:3650},(function(t,o){t?r(t):e(o)}))});r.private&&await i.a.file.writeFile(e.key,r.private),r.cert&&await i.a.file.writeFile(e.cert,r.cert)})(r,t),o=!0),o){const e=await i.a.file.readFile(r.key),t=await i.a.file.readFile(r.cert);let o;return await i.a.file.exists(r.ca)&&(o=await i.a.file.readFile(r.ca)),{key:e,cert:t,ca:o}}},p=r(3),u=r.n(p),f=r(4),d=r.n(f),m=r(5),y=r.n(m);class g{constructor(e){this.root=e||process.cwd(),this.program={}}async init(){this.runtime||(this.runtime=await(async e=>{e=e||process.cwd();const t={};t.config=await i.a.file.readJson(e+"/config.json")||{},t.path={ssl:e+"/ssl"},t.ssl=await l(t.path.ssl),t.ssl?t.protocol=t.config.protocol||"https":t.protocol="http",t.domain=t.config.domain||"localhost",t.port=t.config.port||("https"===t.protocol?443:80);const r="http"===t.protocol&&80===t.port||"https"===t.protocol&&443===t.port?"":":"+t.port;return t.origin=`${t.protocol}://${t.domain}${r}`,t})(this.root))}handle(e){for(let t in e._meta.program){const r=t,o=e._meta.program[t],a=n.a.object.get(e,r);this.program[r]={meta:o,handler:a}}}async serve(){await this.init(),await(async(e,t)=>{const r=d()();for(let o in t){const a="/api/"+o.replace(/\./g,"/");console.log(`${e.origin}${a}`),r.all(a,(async function(e,r,a){const i={};Object.assign(i,e.query,e.body);const s=n.a.caller(t[o].handler,t[o].meta,{});let c;try{c={code:"OK",data:await s(i)}}catch(e){c={code:e.code||"INTERNAL_ERROR",message:e.message}}r.send(c)}))}const o=()=>{console.log("应用已运行在:"+e.origin)};if(e.ssl){y.a.createServer(e.ssl,r).listen(e.port,o)}else{u.a.createServer(r).listen(e.port,o)}})(this.runtime,this.program)}}var h={program:{App:{name:"轻呈云应用",desc:"构建轻呈云应用",arguments:"path",isClass:!0,parameters:{path:{name:"应用目录"}}}}};t.default={App:g,_meta:h}}])})); | ||
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define("Sumor_App",[],t):"object"==typeof exports?exports.Sumor_App=t():e.Sumor_App=t()}("undefined"!=typeof self?self:this,(function(){return function(e){var t={};function r(o){if(t[o])return t[o].exports;var n=t[o]={i:o,l:!1,exports:{}};return e[o].call(n.exports,n,n.exports,r),n.l=!0,n.exports}return r.m=e,r.c=t,r.d=function(e,t,o){r.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:o})},r.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},r.t=function(e,t){if(1&t&&(e=r(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var o=Object.create(null);if(r.r(o),Object.defineProperty(o,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var n in e)r.d(o,n,function(t){return e[t]}.bind(null,n));return o},r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,"a",t),t},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.p="",r(r.s=10)}([function(e,t){e.exports=require("@sumor/utils")},function(e,t){e.exports=require("@sumor/base")},function(e,t){e.exports=require("body-parser")},function(e,t){e.exports=require("selfsigned")},function(e,t){e.exports=require("express")},function(e,t){e.exports=require("compression")},function(e,t){e.exports=require("zlib")},function(e,t){e.exports=require("serve-static")},function(e,t){e.exports=require("spdy")},function(e,t){e.exports=require("http")},function(e,t,r){"use strict";r.r(t),r.d(t,"App",(function(){return L})),r.d(t,"_meta",(function(){return q}));var o=r(0),n=r.n(o),a=r(3),s=r.n(a),i=async(e,t)=>{const r={key:e+"/domain.key",cert:e+"/domain.cer",ca:e+"/ca.cer"};let o=await n.a.file.exists(r.key)&&await n.a.file.exists(r.cert);if(o||(await(async(e,t)=>{t=t||"selfsigned";const r=await new Promise((e,r)=>{s.a.generate([{name:"commonName",value:t}],{days:3650},(function(t,o){t?r(t):e(o)}))});r.private&&await n.a.file.writeFile(e.key,r.private),r.cert&&await n.a.file.writeFile(e.cert,r.cert)})(r,t),o=!0),o){const e=await n.a.file.readFile(r.key),t=await n.a.file.readFile(r.cert);let o;return await n.a.file.exists(r.ca)&&(o=await n.a.file.readFile(r.ca)),{key:e,cert:t,ca:o}}},c=r(1),l=r.n(c),p=r(4),u=r.n(p),f=r(5),g=r.n(f),m=r(6),d=r.n(m),h=r(7),y=r.n(h),w=r(2),x=r.n(w),b=r(8),v=r.n(b),_=r(9),P=r.n(_),j=async(e,t)=>{const r=u()();r.disable("x-powered-by"),e.express=r,(async e=>{const t=e.express,r=new o.Logger("HTTP");t.use((async function(e,t,o){r.trace(`${e.method} ${e.originalUrl} "${e.get("user-agent")}"`),await o()}))})(e),(e=>{const t=e.express;t.use(g()({filter:function(){return!0},flush:d.a.Z_SYNC_FLUSH})),e.logger.debug("静态文件目录:"+e.path.static),t.use(y()(e.path.static)),t.use(x.a.urlencoded({extended:!1})),t.use(x.a.json()),t.use(x.a.text())})(e),((e,t)=>{const r=e.express,o=t.getList("api");for(let n of o){const o="/"+n.replace(/\./g,"/");e.logger.debug(`API已监听:${e.origin}${o}`),r.all(o,(async function(e,r,o){const a=Date.now();let s;const i={};Object.assign(i,e.query,e.body);const c={};try{const e=t.getProgram("event.context");if(e)for(let t in e){const r=l.a.caller(e[t].handler,e[t].meta,c);await r()}const r=t.caller(n,c);s={code:"OK",data:await r(i)}}catch(e){const r=t.getProgram("event.error");if(r)for(let e in r){const t=l.a.caller(r[e].handler,r[e].meta,c);await t()}s={code:e.code||"INTERNAL_ERROR",message:e.message}}const p=Date.now();r.set("sumor-response-time",p-a+"ms"),r.send(s)}))}})(e,t),await(async e=>{const t=e.express,r=e.path.static+"/index.html";if(await n.a.file.exists(r)){const e=await n.a.file.readFile(r,"utf-8");t.use((t,r)=>{r.set("Content-Type","text/html;charset=utf-8"),r.send(e)})}})(e),await(async e=>{const t=e.express;return await new Promise(r=>{const o=()=>{e.logger.info("网页服务已运行在:"+e.origin),r()};if(e.ssl){v.a.createServer(e.ssl,t).listen(e.port,o)}else{P.a.createServer(t).listen(e.port,o)}})})(e)};class S{constructor(e){this.program={},this.init(e)}init(e){for(let t in e){const r=e[t];for(let e in r._meta.program){this.program[e]=this.program[e]||[];const t=r._meta.program[e],o=l.a.object.get(r,e);this.program[e].push({library:r._meta.name,meta:t,handler:o})}}}getList(e){const t=[];for(let r in this.program)new RegExp(`^${e}.`).test(r)&&t.push(r);return t}getProgram(e){return this.program[e]}caller(e,t){let r=!1;for(let t in this.program[e]){this.program[e][t].meta.async&&(r=!0)}const n=t.token&&t.token.userId?t.token.userId:"";return r?async r=>{let a;for(let s in this.program[e]){t.logger=new o.Logger(this.program[e][s].library||"APP",{user:n});const i=l.a.caller(this.program[e][s].handler,this.program[e][s].meta,t),c=await i(r);void 0!==c&&(a=c)}return a}:r=>{let a;for(let s in this.program[e]){t.logger=new o.Logger(this.program[e][s].library||"APP",{user:n});const i=l.a.caller(this.program[e][s].handler,this.program[e][s].meta,t)(r);void 0!==i&&(a=i)}return a}}}class L{constructor(e){this.root=e||process.cwd(),this.handler=[],this.program={}}async init(){this.runtime||(this.runtime=await(async e=>{e=e||process.cwd();const t={};t.config=await n.a.file.readJson(e+"/config.json")||{},n.a.Logger.setLevel(t.config.SumorLogLevel||t.config.logLevel||"trace"),t.logger=new n.a.Logger("Sumor_App"),t.path={ssl:e+"/ssl",static:e+"/static"};for(let e in t.path)t.path[e]=l.a.name.path.normalize(t.path[e]);t.ssl=await i(t.path.ssl),t.ssl?t.protocol=t.config.protocol||"https":t.protocol="http",t.domain=t.config.domain||"localhost",t.port=t.config.port||("https"===t.protocol?443:80);const r="http"===t.protocol&&80===t.port||"https"===t.protocol&&443===t.port?"":":"+t.port;return t.origin=`${t.protocol}://${t.domain}${r}`,t})(this.root))}handle(e){this.handler.push(e)}async serve(){const e=Date.now();await this.init(),this.program=new S(this.handler),await j(this.runtime,this.program);const t=Date.now();this.runtime.logger.info(`服务已启动完成,耗时${t-e}毫秒`)}}var q={program:{App:{name:"轻呈云应用",desc:"构建轻呈云应用",arguments:"path",isClass:!0,parameters:{path:{name:"应用目录"}}}}};t.default={App:L,_meta:q}}])})); |
{ | ||
"name": "@sumor/app", | ||
"version": "17.0.8", | ||
"version": "17.0.9", | ||
"dependencies": { | ||
"@sumor/base": "^17.0.8", | ||
"@sumor/utils": "^17.0.4", | ||
"@sumor/base": "^17.0.12", | ||
"@sumor/utils": "^17.0.6", | ||
"body-parser": "^1.19.0", | ||
"compression": "^1.7.4", | ||
"cookie-parser": "^1.4.5", | ||
"express": "^4.17.1", | ||
"spdy": "^4.0.2", | ||
"selfsigned": "^1.10.7" | ||
"selfsigned": "^1.10.7", | ||
"serve-static": "^1.14.1", | ||
"spdy": "^4.0.2" | ||
} | ||
} |
@@ -28,3 +28,3 @@ # @sumor/app | ||
## 构建应用 | ||
## 构建应用示例 | ||
```javascript | ||
@@ -36,18 +36,8 @@ const {App} = require("@sumor/app"); | ||
program:{ | ||
"say.hello.world":{ | ||
parameters:{ | ||
p1:{ | ||
name:"参数1", | ||
type:"string", | ||
length:3 | ||
} | ||
} | ||
} | ||
"api.demo":{}// 参照实体定义 | ||
} | ||
}, | ||
say:{ | ||
hello:{ | ||
world:(parameters,context)=>{ | ||
return parameters.p1; | ||
} | ||
api:{ | ||
demo:(parameters,context)=>{ | ||
return parameters.p1; | ||
} | ||
@@ -60,2 +50,9 @@ } | ||
## 事件增强 | ||
### context | ||
交互上下文处理事件,可藉由此拓展上下文内容 | ||
### error | ||
错误处理,用于拓展错误发生处理额外的操作,如数据库回滚 | ||
## SSL 临时证书设置 | ||
@@ -62,0 +59,0 @@ 在开发阶段,如您无法提供有效证书,将会自动生成临时证书。 |
8807
9
88
+ Addedbody-parser@^1.19.0
+ Addedcompression@^1.7.4
+ Addedcookie-parser@^1.4.5
+ Addedserve-static@^1.14.1
+ Addedcompressible@2.0.18(transitive)
+ Addedcompression@1.7.5(transitive)
+ Addedcookie@0.7.2(transitive)
+ Addedcookie-parser@1.4.7(transitive)
+ Addedmime-db@1.53.0(transitive)
+ Addednegotiator@0.6.4(transitive)
+ Addedon-headers@1.0.2(transitive)
Updated@sumor/base@^17.0.12
Updated@sumor/utils@^17.0.6