vona 5.0.4 → 5.0.8

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.
Files changed (328) hide show
  1. package/LICENSE +8 -0
  2. package/README.en-US.md +63 -0
  3. package/README.md +63 -1
  4. package/package.json +6 -76
  5. package/LICENSE.en-US +0 -3
  6. package/README.zh-CN.md +0 -1
  7. package/dist/app/extend/context.d.ts +0 -4
  8. package/dist/app/extend/context.js +0 -152
  9. package/dist/index.d.ts +0 -11
  10. package/dist/index.js +0 -35
  11. package/dist/lib/base/dbTransaction.d.ts +0 -12
  12. package/dist/lib/base/dbTransaction.js +0 -55
  13. package/dist/lib/base/error.d.ts +0 -18
  14. package/dist/lib/base/error.js +0 -70
  15. package/dist/lib/base/model.d.ts +0 -22
  16. package/dist/lib/base/model.js +0 -253
  17. package/dist/lib/bean/_beanLocal_.d.ts +0 -6
  18. package/dist/lib/bean/_beanLocal_.js +0 -16
  19. package/dist/lib/bean/beanBase.d.ts +0 -11
  20. package/dist/lib/bean/beanBase.js +0 -34
  21. package/dist/lib/bean/beanBaseSimple.d.ts +0 -8
  22. package/dist/lib/bean/beanBaseSimple.js +0 -31
  23. package/dist/lib/bean/beanContainer.d.ts +0 -39
  24. package/dist/lib/bean/beanContainer.js +0 -514
  25. package/dist/lib/bean/beanLocal.d.ts +0 -6
  26. package/dist/lib/bean/beanLocal.js +0 -16
  27. package/dist/lib/bean/beanModuleScopeBase.d.ts +0 -10
  28. package/dist/lib/bean/beanModuleScopeBase.js +0 -28
  29. package/dist/lib/bean/beanScopeBase.d.ts +0 -6
  30. package/dist/lib/bean/beanScopeBase.js +0 -19
  31. package/dist/lib/bean/beanScopeScene.d.ts +0 -12
  32. package/dist/lib/bean/beanScopeScene.js +0 -23
  33. package/dist/lib/bean/beanSimple.d.ts +0 -7
  34. package/dist/lib/bean/beanSimple.js +0 -24
  35. package/dist/lib/bean/index.d.ts +0 -8
  36. package/dist/lib/bean/index.js +0 -24
  37. package/dist/lib/bean/resource/config/broadcast.d.ts +0 -7
  38. package/dist/lib/bean/resource/config/broadcast.js +0 -3
  39. package/dist/lib/bean/resource/config/index.d.ts +0 -2
  40. package/dist/lib/bean/resource/config/index.js +0 -18
  41. package/dist/lib/bean/resource/config/middleware.d.ts +0 -9
  42. package/dist/lib/bean/resource/config/middleware.js +0 -3
  43. package/dist/lib/bean/resource/config/startup.d.ts +0 -9
  44. package/dist/lib/bean/resource/config/startup.js +0 -3
  45. package/dist/lib/bean/resource/config/type.d.ts +0 -43
  46. package/dist/lib/bean/resource/config/type.js +0 -3
  47. package/dist/lib/bean/resource/constant/index.d.ts +0 -2
  48. package/dist/lib/bean/resource/constant/index.js +0 -18
  49. package/dist/lib/bean/resource/constant/type.d.ts +0 -2
  50. package/dist/lib/bean/resource/constant/type.js +0 -3
  51. package/dist/lib/bean/resource/entity/entityBase.d.ts +0 -21
  52. package/dist/lib/bean/resource/entity/entityBase.js +0 -20
  53. package/dist/lib/bean/resource/entity/index.d.ts +0 -2
  54. package/dist/lib/bean/resource/entity/index.js +0 -18
  55. package/dist/lib/bean/resource/error/beanScopeError.d.ts +0 -11
  56. package/dist/lib/bean/resource/error/beanScopeError.js +0 -34
  57. package/dist/lib/bean/resource/error/beanScopeErrorImpl.d.ts +0 -14
  58. package/dist/lib/bean/resource/error/beanScopeErrorImpl.js +0 -35
  59. package/dist/lib/bean/resource/error/errorClass.d.ts +0 -18
  60. package/dist/lib/bean/resource/error/errorClass.js +0 -78
  61. package/dist/lib/bean/resource/error/errorContext.d.ts +0 -38
  62. package/dist/lib/bean/resource/error/errorContext.js +0 -3
  63. package/dist/lib/bean/resource/error/errorGlobal.d.ts +0 -8
  64. package/dist/lib/bean/resource/error/errorGlobal.js +0 -3
  65. package/dist/lib/bean/resource/error/errorInternal.d.ts +0 -67
  66. package/dist/lib/bean/resource/error/errorInternal.js +0 -70
  67. package/dist/lib/bean/resource/error/errorObject.d.ts +0 -5
  68. package/dist/lib/bean/resource/error/errorObject.js +0 -3
  69. package/dist/lib/bean/resource/error/index.d.ts +0 -9
  70. package/dist/lib/bean/resource/error/index.js +0 -25
  71. package/dist/lib/bean/resource/error/type.d.ts +0 -9
  72. package/dist/lib/bean/resource/error/type.js +0 -3
  73. package/dist/lib/bean/resource/index.d.ts +0 -8
  74. package/dist/lib/bean/resource/index.js +0 -24
  75. package/dist/lib/bean/resource/locale/beanScopeLocale.d.ts +0 -11
  76. package/dist/lib/bean/resource/locale/beanScopeLocale.js +0 -33
  77. package/dist/lib/bean/resource/locale/beanScopeLocaleImpl.d.ts +0 -3
  78. package/dist/lib/bean/resource/locale/beanScopeLocaleImpl.js +0 -14
  79. package/dist/lib/bean/resource/locale/index.d.ts +0 -4
  80. package/dist/lib/bean/resource/locale/index.js +0 -20
  81. package/dist/lib/bean/resource/locale/localeCtx.d.ts +0 -8
  82. package/dist/lib/bean/resource/locale/localeCtx.js +0 -63
  83. package/dist/lib/bean/resource/locale/type.d.ts +0 -19
  84. package/dist/lib/bean/resource/locale/type.js +0 -3
  85. package/dist/lib/bean/resource/model/beanModelBase.d.ts +0 -24
  86. package/dist/lib/bean/resource/model/beanModelBase.js +0 -165
  87. package/dist/lib/bean/resource/model/beanModelBaseInner.d.ts +0 -29
  88. package/dist/lib/bean/resource/model/beanModelBaseInner.js +0 -86
  89. package/dist/lib/bean/resource/model/index.d.ts +0 -2
  90. package/dist/lib/bean/resource/model/index.js +0 -18
  91. package/dist/lib/bean/resource/model/type.d.ts +0 -12
  92. package/dist/lib/bean/resource/model/type.js +0 -3
  93. package/dist/lib/bean/resource/route/index.d.ts +0 -2
  94. package/dist/lib/bean/resource/route/index.js +0 -18
  95. package/dist/lib/bean/resource/route/type.d.ts +0 -60
  96. package/dist/lib/bean/resource/route/type.js +0 -3
  97. package/dist/lib/bean/scope/beanScopeBase.d.ts +0 -19
  98. package/dist/lib/bean/scope/beanScopeBase.js +0 -104
  99. package/dist/lib/bean/scope/beanScopeBean.d.ts +0 -10
  100. package/dist/lib/bean/scope/beanScopeBean.js +0 -34
  101. package/dist/lib/bean/scope/beanScopeError.d.ts +0 -11
  102. package/dist/lib/bean/scope/beanScopeError.js +0 -21
  103. package/dist/lib/bean/scope/beanScopeErrorImpl.d.ts +0 -14
  104. package/dist/lib/bean/scope/beanScopeErrorImpl.js +0 -21
  105. package/dist/lib/bean/scope/beanScopeScene.d.ts +0 -12
  106. package/dist/lib/bean/scope/beanScopeScene.js +0 -42
  107. package/dist/lib/bean/scope/index.d.ts +0 -5
  108. package/dist/lib/bean/scope/index.js +0 -21
  109. package/dist/lib/bean/scope/type.d.ts +0 -21
  110. package/dist/lib/bean/scope/type.js +0 -3
  111. package/dist/lib/bean/type.d.ts +0 -17
  112. package/dist/lib/bean/type.js +0 -4
  113. package/dist/lib/core/index.d.ts +0 -5
  114. package/dist/lib/core/index.js +0 -21
  115. package/dist/lib/core/meta.d.ts +0 -65
  116. package/dist/lib/core/meta.js +0 -335
  117. package/dist/lib/core/metaCtx.d.ts +0 -16
  118. package/dist/lib/core/metaCtx.js +0 -71
  119. package/dist/lib/core/metadata.d.ts +0 -12
  120. package/dist/lib/core/metadata.js +0 -52
  121. package/dist/lib/core/resource.d.ts +0 -29
  122. package/dist/lib/core/resource.js +0 -172
  123. package/dist/lib/decorator/class/aop.d.ts +0 -3
  124. package/dist/lib/decorator/class/aop.js +0 -23
  125. package/dist/lib/decorator/class/atom.d.ts +0 -3
  126. package/dist/lib/decorator/class/atom.js +0 -22
  127. package/dist/lib/decorator/class/bean.d.ts +0 -3
  128. package/dist/lib/decorator/class/bean.js +0 -23
  129. package/dist/lib/decorator/class/controller.d.ts +0 -3
  130. package/dist/lib/decorator/class/controller.js +0 -22
  131. package/dist/lib/decorator/class/index.d.ts +0 -10
  132. package/dist/lib/decorator/class/index.js +0 -26
  133. package/dist/lib/decorator/class/local.d.ts +0 -3
  134. package/dist/lib/decorator/class/local.js +0 -23
  135. package/dist/lib/decorator/class/model.d.ts +0 -3
  136. package/dist/lib/decorator/class/model.js +0 -28
  137. package/dist/lib/decorator/class/scope.d.ts +0 -2
  138. package/dist/lib/decorator/class/scope.js +0 -20
  139. package/dist/lib/decorator/class/service.d.ts +0 -3
  140. package/dist/lib/decorator/class/service.js +0 -23
  141. package/dist/lib/decorator/class/use.d.ts +0 -5
  142. package/dist/lib/decorator/class/use.js +0 -43
  143. package/dist/lib/decorator/class/util.d.ts +0 -3
  144. package/dist/lib/decorator/class/util.js +0 -10
  145. package/dist/lib/decorator/class/virtual.d.ts +0 -3
  146. package/dist/lib/decorator/class/virtual.js +0 -24
  147. package/dist/lib/decorator/index.d.ts +0 -7
  148. package/dist/lib/decorator/index.js +0 -23
  149. package/dist/lib/decorator/interface/beanOptions.d.ts +0 -55
  150. package/dist/lib/decorator/interface/beanOptions.js +0 -8
  151. package/dist/lib/decorator/interface/useOptions.d.ts +0 -14
  152. package/dist/lib/decorator/interface/useOptions.js +0 -3
  153. package/dist/lib/decorator/type/constructable.d.ts +0 -2
  154. package/dist/lib/decorator/type/constructable.js +0 -3
  155. package/dist/lib/decorator/type/containerScope.d.ts +0 -2
  156. package/dist/lib/decorator/type/containerScope.js +0 -3
  157. package/dist/lib/decorator/type/injectionScope.d.ts +0 -2
  158. package/dist/lib/decorator/type/injectionScope.js +0 -3
  159. package/dist/lib/error/error.d.ts +0 -18
  160. package/dist/lib/error/error.js +0 -71
  161. package/dist/lib/error/errorClass.d.ts +0 -18
  162. package/dist/lib/error/errorClass.js +0 -72
  163. package/dist/lib/error/errorContext.d.ts +0 -38
  164. package/dist/lib/error/errorContext.js +0 -3
  165. package/dist/lib/error/errorGlobal.d.ts +0 -8
  166. package/dist/lib/error/errorGlobal.js +0 -3
  167. package/dist/lib/error/errorInternal.d.ts +0 -67
  168. package/dist/lib/error/errorInternal.js +0 -70
  169. package/dist/lib/error/errorObject.d.ts +0 -5
  170. package/dist/lib/error/errorObject.js +0 -3
  171. package/dist/lib/error/index.d.ts +0 -5
  172. package/dist/lib/error/index.js +0 -21
  173. package/dist/lib/framework/bootstrap.d.ts +0 -9
  174. package/dist/lib/framework/bootstrap.js +0 -35
  175. package/dist/lib/framework/framework.d.ts +0 -11
  176. package/dist/lib/framework/framework.js +0 -28
  177. package/dist/lib/framework/loader.d.ts +0 -21
  178. package/dist/lib/framework/loader.js +0 -57
  179. package/dist/lib/framework/meta.d.ts +0 -2
  180. package/dist/lib/framework/meta.js +0 -23
  181. package/dist/lib/framework/metaClass.d.ts +0 -2
  182. package/dist/lib/framework/metaClass.js +0 -26
  183. package/dist/lib/framework/moduleInfo.d.ts +0 -3
  184. package/dist/lib/framework/moduleInfo.js +0 -67
  185. package/dist/lib/framework/util.d.ts +0 -4
  186. package/dist/lib/framework/util.js +0 -15
  187. package/dist/lib/module/asset/errors.d.ts +0 -68
  188. package/dist/lib/module/asset/errors.js +0 -69
  189. package/dist/lib/module/bean/index.d.ts +0 -4
  190. package/dist/lib/module/bean/index.js +0 -24
  191. package/dist/lib/module/broadcast/broadcast.d.ts +0 -3
  192. package/dist/lib/module/broadcast/broadcast.js +0 -49
  193. package/dist/lib/module/broadcast/broadcastClient.d.ts +0 -24
  194. package/dist/lib/module/broadcast/broadcastClient.js +0 -91
  195. package/dist/lib/module/cluster/agent.d.ts +0 -3
  196. package/dist/lib/module/cluster/agent.js +0 -22
  197. package/dist/lib/module/cluster/app.d.ts +0 -3
  198. package/dist/lib/module/cluster/app.js +0 -26
  199. package/dist/lib/module/config.d.ts +0 -3
  200. package/dist/lib/module/config.js +0 -67
  201. package/dist/lib/module/constant.d.ts +0 -3
  202. package/dist/lib/module/constant.js +0 -46
  203. package/dist/lib/module/contextPatch.d.ts +0 -3
  204. package/dist/lib/module/contextPatch.js +0 -16
  205. package/dist/lib/module/errors.d.ts +0 -3
  206. package/dist/lib/module/errors.js +0 -49
  207. package/dist/lib/module/index.d.ts +0 -2
  208. package/dist/lib/module/index.js +0 -3
  209. package/dist/lib/module/loader.d.ts +0 -5
  210. package/dist/lib/module/loader.js +0 -73
  211. package/dist/lib/module/locales.d.ts +0 -3
  212. package/dist/lib/module/locales.js +0 -132
  213. package/dist/lib/module/messenger.d.ts +0 -25
  214. package/dist/lib/module/messenger.js +0 -128
  215. package/dist/lib/module/middleware.d.ts +0 -3
  216. package/dist/lib/module/middleware.js +0 -113
  217. package/dist/lib/module/model.d.ts +0 -3
  218. package/dist/lib/module/model.js +0 -47
  219. package/dist/lib/module/module.d.ts +0 -12
  220. package/dist/lib/module/module.js +0 -134
  221. package/dist/lib/module/moduleMeta.d.ts +0 -3
  222. package/dist/lib/module/moduleMeta.js +0 -26
  223. package/dist/lib/module/queue/queue.d.ts +0 -3
  224. package/dist/lib/module/queue/queue.js +0 -59
  225. package/dist/lib/module/queue/queueClient.d.ts +0 -26
  226. package/dist/lib/module/queue/queueClient.js +0 -262
  227. package/dist/lib/module/redis.d.ts +0 -11
  228. package/dist/lib/module/redis.js +0 -46
  229. package/dist/lib/module/reload/development.d.ts +0 -3
  230. package/dist/lib/module/reload/development.js +0 -98
  231. package/dist/lib/module/reload/reload.d.ts +0 -16
  232. package/dist/lib/module/reload/reload.js +0 -113
  233. package/dist/lib/module/reload.d.ts +0 -7
  234. package/dist/lib/module/reload.js +0 -17
  235. package/dist/lib/module/route.d.ts +0 -10
  236. package/dist/lib/module/route.js +0 -239
  237. package/dist/lib/module/schedule.d.ts +0 -3
  238. package/dist/lib/module/schedule.js +0 -129
  239. package/dist/lib/module/service.d.ts +0 -3
  240. package/dist/lib/module/service.js +0 -35
  241. package/dist/lib/module/socketio.d.ts +0 -5
  242. package/dist/lib/module/socketio.js +0 -47
  243. package/dist/lib/module/startup.d.ts +0 -2
  244. package/dist/lib/module/startup.js +0 -134
  245. package/dist/lib/module/version/clear.d.ts +0 -2
  246. package/dist/lib/module/version/clear.js +0 -42
  247. package/dist/lib/module/version/ready.d.ts +0 -6
  248. package/dist/lib/module/version/ready.js +0 -106
  249. package/dist/lib/resource/error/errorClass.d.ts +0 -18
  250. package/dist/lib/resource/error/errorClass.js +0 -72
  251. package/dist/lib/resource/error/errorContext.d.ts +0 -38
  252. package/dist/lib/resource/error/errorContext.js +0 -3
  253. package/dist/lib/resource/error/errorGlobal.d.ts +0 -8
  254. package/dist/lib/resource/error/errorGlobal.js +0 -3
  255. package/dist/lib/resource/error/errorInternal.d.ts +0 -67
  256. package/dist/lib/resource/error/errorInternal.js +0 -70
  257. package/dist/lib/resource/error/errorObject.d.ts +0 -5
  258. package/dist/lib/resource/error/errorObject.js +0 -3
  259. package/dist/lib/resource/error/index.d.ts +0 -5
  260. package/dist/lib/resource/error/index.js +0 -21
  261. package/dist/lib/utils/index.d.ts +0 -2
  262. package/dist/lib/utils/index.js +0 -18
  263. package/dist/lib/utils/isClass.d.ts +0 -2
  264. package/dist/lib/utils/isClass.js +0 -20
  265. package/dist/lib/utils/mockUtil.d.ts +0 -11
  266. package/dist/lib/utils/mockUtil.js +0 -34
  267. package/dist/lib/utils/mockUtilCtx.d.ts +0 -10
  268. package/dist/lib/utils/mockUtilCtx.js +0 -35
  269. package/dist/lib/utils/performAction.d.ts +0 -19
  270. package/dist/lib/utils/performAction.js +0 -137
  271. package/dist/lib/utils/util.d.ts +0 -63
  272. package/dist/lib/utils/util.js +0 -445
  273. package/dist/lib/utils/utilCtx.d.ts +0 -34
  274. package/dist/lib/utils/utilCtx.js +0 -137
  275. package/dist/types/application/app.d.ts +0 -19
  276. package/dist/types/application/app.js +0 -28
  277. package/dist/types/application/index.d.ts +0 -2
  278. package/dist/types/application/index.js +0 -18
  279. package/dist/types/config/appInfo.d.ts +0 -4
  280. package/dist/types/config/appInfo.js +0 -3
  281. package/dist/types/config/config.d.ts +0 -10
  282. package/dist/types/config/config.js +0 -3
  283. package/dist/types/config/development.d.ts +0 -4
  284. package/dist/types/config/development.js +0 -3
  285. package/dist/types/config/index.d.ts +0 -4
  286. package/dist/types/config/index.js +0 -20
  287. package/dist/types/config/locale.d.ts +0 -10
  288. package/dist/types/config/locale.js +0 -7
  289. package/dist/types/context/contextBase.d.ts +0 -21
  290. package/dist/types/context/contextBase.js +0 -3
  291. package/dist/types/context/contextConfig.d.ts +0 -4
  292. package/dist/types/context/contextConfig.js +0 -3
  293. package/dist/types/context/contextError.d.ts +0 -25
  294. package/dist/types/context/contextError.js +0 -3
  295. package/dist/types/context/contextLocale.d.ts +0 -9
  296. package/dist/types/context/contextLocale.js +0 -3
  297. package/dist/types/context/contextOthers.d.ts +0 -4
  298. package/dist/types/context/contextOthers.js +0 -3
  299. package/dist/types/context/contextState.d.ts +0 -8
  300. package/dist/types/context/contextState.js +0 -3
  301. package/dist/types/context/index.d.ts +0 -18
  302. package/dist/types/context/index.js +0 -18
  303. package/dist/types/enum/appEvent.d.ts +0 -5
  304. package/dist/types/enum/appEvent.js +0 -9
  305. package/dist/types/enum/index.d.ts +0 -2
  306. package/dist/types/enum/index.js +0 -18
  307. package/dist/types/index.d.ts +0 -7
  308. package/dist/types/index.js +0 -23
  309. package/dist/types/interface/broadcast.d.ts +0 -5
  310. package/dist/types/interface/broadcast.js +0 -3
  311. package/dist/types/interface/error.d.ts +0 -8
  312. package/dist/types/interface/error.js +0 -3
  313. package/dist/types/interface/index.d.ts +0 -6
  314. package/dist/types/interface/index.js +0 -22
  315. package/dist/types/interface/module.d.ts +0 -32
  316. package/dist/types/interface/module.js +0 -18
  317. package/dist/types/interface/monkey.d.ts +0 -25
  318. package/dist/types/interface/monkey.js +0 -3
  319. package/dist/types/interface/queue.d.ts +0 -29
  320. package/dist/types/interface/queue.js +0 -3
  321. package/dist/types/interface/schedule.d.ts +0 -11
  322. package/dist/types/interface/schedule.js +0 -3
  323. package/dist/types/utils/cast.d.ts +0 -6
  324. package/dist/types/utils/cast.js +0 -8
  325. package/dist/types/utils/index.d.ts +0 -3
  326. package/dist/types/utils/index.js +0 -19
  327. package/dist/types/utils/powerPartial.d.ts +0 -4
  328. package/dist/types/utils/powerPartial.js +0 -3
@@ -1,137 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- const http_1 = __importDefault(require("http"));
7
- const koa_compose_1 = __importDefault(require("koa-compose"));
8
- let __fnMiddleware;
9
- /**
10
- * perform action of this or that module
11
- * @param {string} options options
12
- * @param {string} options.method method
13
- * @param {string} options.url url
14
- * @param {json} options.body body(optional)
15
- * @return {promise} response.body.data or throw error
16
- */
17
- async function performAction({ ctxCaller, innerAccess,
18
- // subdomain, deprecated
19
- method, url, query, params, headers, body, }) {
20
- // app
21
- const app = ctxCaller.app;
22
- // middleware
23
- if (!__fnMiddleware) {
24
- const middleware = app.middleware[app.middleware.length - 1];
25
- __fnMiddleware = (0, koa_compose_1.default)([middleware]);
26
- }
27
- // request
28
- url = app.meta.util.combineFetchPath(ctxCaller.module && ctxCaller.module.info, url);
29
- const req = createRequest({ method, url }, ctxCaller);
30
- // response
31
- const res = new http_1.default.ServerResponse(req);
32
- // default status code
33
- res.statusCode = 404;
34
- // ctx
35
- const ctx = app.createContext(req, res);
36
- // locale
37
- Object.defineProperty(ctx, 'locale', {
38
- get() {
39
- return ctxCaller.locale;
40
- },
41
- });
42
- // subdomain
43
- Object.defineProperty(ctx, 'subdomain', {
44
- get() {
45
- return ctxCaller.subdomain;
46
- },
47
- });
48
- // query params body
49
- if (query) {
50
- ctx.req.query = ctx.request.query = query;
51
- }
52
- if (params) {
53
- ctx.req.params = ctx.request.params = params;
54
- }
55
- ctx.req.body = ctx.request.body = body !== undefined ? body : {}; // not undefined
56
- // headers
57
- delegateHeaders(ctx, ctxCaller, headers);
58
- // multipart
59
- ctx.multipart = function (options) {
60
- return ctxCaller.multipart(options);
61
- };
62
- // cookies
63
- delegateCookies(ctx, ctxCaller);
64
- // XX should not delegate session, because session._ctx related to ctx
65
- // not delegate ctx.user, because will create req.user by state.user
66
- for (const property of ['state', 'socket', 'session', 'instance']) {
67
- delegateProperty(ctx, ctxCaller, property);
68
- }
69
- // ctxCaller
70
- ctx.ctxCaller = ctxCaller;
71
- // innerAccess
72
- if (innerAccess !== undefined)
73
- ctx.innerAccess = innerAccess;
74
- // invoke middleware
75
- await __fnMiddleware(ctx);
76
- // check result
77
- if (ctx.status === 200) {
78
- if (!ctx.body || ctx.body.code === undefined) {
79
- // not check code, e.g. text/xml
80
- return ctx.body;
81
- }
82
- if (ctx.body.code === 0) {
83
- return ctx.body.data;
84
- }
85
- throw ctx.createError(ctx.body);
86
- }
87
- else {
88
- throw ctx.createError({
89
- code: ctx.status,
90
- message: ctx.message || ctx.body,
91
- });
92
- }
93
- }
94
- exports.default = performAction;
95
- function delegateHeaders(ctx, ctxCaller, headers) {
96
- if (ctxCaller && ctxCaller.headers) {
97
- Object.assign(ctx.headers, ctxCaller.headers);
98
- }
99
- if (headers) {
100
- Object.assign(ctx.headers, headers);
101
- }
102
- }
103
- function delegateCookies(ctx, ctxCaller) {
104
- const _cookies = ctx.cookies;
105
- Object.defineProperty(ctx, 'cookies', {
106
- get() {
107
- return ctxCaller.cookies || _cookies;
108
- },
109
- });
110
- }
111
- function delegateProperty(ctx, ctxCaller, property) {
112
- Object.defineProperty(ctx, property, {
113
- get() {
114
- return ctxCaller[property];
115
- },
116
- });
117
- }
118
- function createRequest({ method, url }, ctxCaller) {
119
- // _req
120
- const _req = ctxCaller.request;
121
- // req
122
- const req = new http_1.default.IncomingMessage(null);
123
- req.headers = _req.headers;
124
- req.host = _req.host;
125
- req.hostname = _req.hostname;
126
- req.protocol = _req.protocol;
127
- req.secure = _req.secure;
128
- req.method = method.toUpperCase();
129
- req.url = url;
130
- // path,
131
- req.socket = {
132
- remoteAddress: _req.socket.remoteAddress,
133
- remotePort: _req.socket.remotePort,
134
- };
135
- return req;
136
- }
137
- //# sourceMappingURL=performAction.js.map
@@ -1,63 +0,0 @@
1
- import Redlock from 'redlock';
2
- import { VonaContext, IModule, PowerPartial, TypeMonkeyName } from '../../types/index.js';
3
- import { BeanSimple } from '../bean/beanSimple.js';
4
- import { IModuleMiddlewareGate } from '../bean/index.js';
5
- export interface IExecuteBeanCallbackParams {
6
- ctx: VonaContext;
7
- bean: any;
8
- context: any;
9
- }
10
- export interface IExecuteBeanCallback {
11
- (params: IExecuteBeanCallbackParams): Promise<any>;
12
- }
13
- export declare class AppUtil extends BeanSimple {
14
- instanceStarted(subdomain: any): any;
15
- combineFetchPath(moduleName: any, arg: any): any;
16
- combineApiPath(moduleName: any, arg: any): any;
17
- combineQueries(url: any, queries: any): any;
18
- createError(data: any, returnObject?: boolean): any;
19
- monkeyModule(ebAppMonkey: any, ebModulesMonkey: any, monkeyName: TypeMonkeyName, moduleTarget?: IModule, ...monkeyData: any[]): Promise<void>;
20
- getWhiteListCors(ctx: any): any;
21
- isSafeDomain(ctx: any, origin: any): boolean;
22
- isNullOrEmptyString(str?: string | undefined | null): boolean;
23
- compose(chains: any, adapter: any): (context: any, next?: any) => any;
24
- composeAsync(chains: any, adapter: any): (context: any, next?: any) => Promise<any>;
25
- createAnonymousContext({ locale, subdomain, module, instance }: {
26
- locale: any;
27
- subdomain: any;
28
- module: any;
29
- instance: any;
30
- }): Promise<VonaContext>;
31
- executeBean({ locale, subdomain, beanModule, beanFullName, context, fn, transaction, ctxCaller, ctxParent, instance, }: {
32
- locale?: string;
33
- subdomain?: string;
34
- beanModule?: string;
35
- beanFullName?: string;
36
- context: any;
37
- fn?: any;
38
- transaction?: boolean;
39
- ctxCaller?: VonaContext;
40
- ctxParent?: PowerPartial<VonaContext>;
41
- instance?: boolean;
42
- }): Promise<any>;
43
- _executeBeanFn({ fn, ctx, bean, context }: {
44
- fn: any;
45
- ctx: any;
46
- bean: any;
47
- context: any;
48
- }): Promise<any>;
49
- lock({ subdomain, resource, fn, options, redlock, }: {
50
- subdomain?: string;
51
- resource: string;
52
- fn: () => Promise<any>;
53
- options: any;
54
- redlock?: Redlock;
55
- }): Promise<any>;
56
- subdomainDesp(subdomain: any): any;
57
- deprecated(oldUsage: any, newUsage: any): void;
58
- checkGate(gate?: IModuleMiddlewareGate): boolean;
59
- _checkGateEnv(env?: IModuleMiddlewareGate['env']): boolean;
60
- requireDynamic(file: any): any;
61
- private _requireDynamic_getFileTime;
62
- }
63
- //# sourceMappingURL=util.d.ts.map
@@ -1,445 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
- var __importDefault = (this && this.__importDefault) || function (mod) {
26
- return (mod && mod.__esModule) ? mod : { "default": mod };
27
- };
28
- Object.defineProperty(exports, "__esModule", { value: true });
29
- exports.AppUtil = void 0;
30
- const ModuleInfo = __importStar(require("@cabloy/module-info"));
31
- const fs_extra_1 = __importDefault(require("fs-extra"));
32
- const path_1 = __importDefault(require("path"));
33
- const url_1 = require("url");
34
- const is_type_of_1 = __importDefault(require("is-type-of"));
35
- const security = __importStar(require("egg-security"));
36
- const index_js_1 = require("../../types/index.js");
37
- const beanSimple_js_1 = require("../bean/beanSimple.js");
38
- const resource_js_1 = require("../core/resource.js");
39
- const compose_1 = require("@cabloy/compose");
40
- const __EnvTests = ['unittest', 'test'];
41
- class AppUtil extends beanSimple_js_1.BeanSimple {
42
- instanceStarted(subdomain) {
43
- return this.app.meta.appReadyInstances && this.app.meta.appReadyInstances[subdomain];
44
- }
45
- combineFetchPath(moduleName, arg) {
46
- if (arg.substr(0, 2) === '//')
47
- return arg.substr(1);
48
- if (arg.charAt(0) === '/')
49
- return `/api${arg}`;
50
- const moduleInfo = typeof moduleName === 'string' ? ModuleInfo.parseInfo(moduleName) : moduleName;
51
- if (!moduleInfo)
52
- throw new Error('invalid url');
53
- return `/api/${moduleInfo.url}/${arg}`;
54
- }
55
- combineApiPath(moduleName, arg) {
56
- if (arg.charAt(0) === '/')
57
- return arg;
58
- const moduleInfo = typeof moduleName === 'string' ? ModuleInfo.parseInfo(moduleName) : moduleName;
59
- if (!moduleInfo)
60
- throw new Error('invalid url');
61
- return `/${moduleInfo.url}/${arg}`;
62
- }
63
- combineQueries(url, queries) {
64
- //
65
- if (!queries)
66
- return url;
67
- //
68
- let str = '';
69
- for (const key of Object.keys(queries)) {
70
- str += `${key}=${encodeURIComponent(queries[key])}&`;
71
- }
72
- if (str) {
73
- str = str.substr(0, str.length - 1);
74
- }
75
- if (!str)
76
- return url;
77
- //
78
- if (!url)
79
- return '?' + str;
80
- //
81
- const pos = url.indexOf('?');
82
- if (pos === -1)
83
- return `${url}?${str}`;
84
- if (pos === url.length - 1)
85
- return `${url}${str}`;
86
- return `${url}&${str}`;
87
- }
88
- createError(data, returnObject) {
89
- const error = returnObject ? {} : new Error();
90
- error.code = data.code !== undefined ? data.code : 500;
91
- if (data.message && typeof data.message === 'object') {
92
- error.message = JSON.stringify(data.message, null, 2);
93
- }
94
- else {
95
- error.message = data.message;
96
- }
97
- if (data.stack)
98
- error.stack = data.stack;
99
- if (data.name)
100
- error.name = data.name;
101
- if (data.errno)
102
- error.errno = data.errno;
103
- if (data.sqlMessage)
104
- error.sqlMessage = data.sqlMessage;
105
- if (data.sqlState)
106
- error.sqlState = data.sqlState;
107
- if (data.index)
108
- error.index = data.index;
109
- if (data.sql)
110
- error.sql = data.sql;
111
- return error;
112
- }
113
- async monkeyModule(ebAppMonkey, ebModulesMonkey, monkeyName, moduleTarget, ...monkeyData) {
114
- // self: main
115
- if (moduleTarget && moduleTarget.mainInstance && moduleTarget.mainInstance[monkeyName]) {
116
- await moduleTarget.mainInstance[monkeyName](...monkeyData);
117
- }
118
- // module monkey
119
- for (const key in ebModulesMonkey) {
120
- const moduleMonkey = ebModulesMonkey[key];
121
- if (moduleMonkey.monkeyInstance && moduleMonkey.monkeyInstance[monkeyName]) {
122
- if (moduleTarget === undefined) {
123
- // @ts-ignore ignore
124
- await moduleMonkey.monkeyInstance[monkeyName](...monkeyData);
125
- }
126
- else {
127
- // @ts-ignore ignore
128
- await moduleMonkey.monkeyInstance[monkeyName](moduleTarget, ...monkeyData);
129
- }
130
- }
131
- }
132
- // app monkey
133
- if (ebAppMonkey && ebAppMonkey[monkeyName]) {
134
- if (moduleTarget === undefined) {
135
- await ebAppMonkey[monkeyName](...monkeyData);
136
- }
137
- else {
138
- await ebAppMonkey[monkeyName](moduleTarget, ...monkeyData);
139
- }
140
- }
141
- }
142
- getWhiteListCors(ctx) {
143
- let whiteListCors;
144
- const _config = ctx.config.module('a-base');
145
- const _whiteList = (_config && _config.cors && _config.cors.whiteList) || [];
146
- if (!Array.isArray(_whiteList)) {
147
- whiteListCors = _whiteList.split(',');
148
- }
149
- else {
150
- whiteListCors = _whiteList.concat();
151
- }
152
- // inherits from jsonp
153
- let _whiteListJsonp = _config && _config.jsonp && _config.jsonp.whiteList;
154
- if (_whiteListJsonp) {
155
- if (!Array.isArray(_whiteListJsonp)) {
156
- _whiteListJsonp = _whiteListJsonp.split(',');
157
- }
158
- whiteListCors = whiteListCors.concat(_whiteListJsonp);
159
- }
160
- // hostSelf
161
- const hostSelf = ctx.bean.base.getAbsoluteUrl();
162
- if (hostSelf) {
163
- whiteListCors.push(hostSelf);
164
- }
165
- // ok
166
- return whiteListCors;
167
- }
168
- isSafeDomain(ctx, origin) {
169
- // origin is {protocol}{hostname}{port}...
170
- if (!origin || origin === 'null' || origin === null)
171
- return true;
172
- let parsedUrl;
173
- try {
174
- parsedUrl = new url_1.URL(origin);
175
- }
176
- catch (_) {
177
- return false;
178
- }
179
- // whiteList
180
- const whiteListCors = this.getWhiteListCors(ctx);
181
- if (security.utils.isSafeDomain(parsedUrl.hostname, whiteListCors) ||
182
- security.utils.isSafeDomain(origin, whiteListCors)) {
183
- return true;
184
- }
185
- return false;
186
- }
187
- isNullOrEmptyString(str) {
188
- return str === undefined || str === null || str === '';
189
- }
190
- compose(chains, adapter) {
191
- return (0, compose_1.compose)(chains, adapter);
192
- }
193
- composeAsync(chains, adapter) {
194
- return (0, compose_1.composeAsync)(chains, adapter);
195
- }
196
- async createAnonymousContext({ locale, subdomain, module, instance }) {
197
- // url
198
- const url = module ? this.combineFetchPath(module, '') : '/api/a/base/';
199
- // ctx
200
- const ctx = this.app.createAnonymousContext({
201
- method: 'post',
202
- url,
203
- });
204
- ctx.req.ctx = ctx;
205
- // locale
206
- Object.defineProperty(ctx, 'locale', {
207
- get() {
208
- return locale || this.app.config.i18n.defaultLocale;
209
- },
210
- });
211
- // subdomain
212
- Object.defineProperty(ctx, 'subdomain', {
213
- get() {
214
- return subdomain;
215
- },
216
- });
217
- // instance
218
- if (subdomain !== undefined && subdomain !== null) {
219
- ctx.instance = await ctx.bean.instance.get({ subdomain });
220
- // start instance
221
- if (instance) {
222
- await ctx.bean.instance.checkAppReadyInstance();
223
- }
224
- }
225
- // ok
226
- return ctx;
227
- }
228
- async executeBean({ locale, subdomain, beanModule, beanFullName, context, fn, transaction, ctxCaller, ctxParent, instance, }) {
229
- // ctxModule
230
- let ctxModule = beanModule;
231
- if (!ctxModule && beanFullName) {
232
- const beanOptions = resource_js_1.appResource.getBean(beanFullName);
233
- ctxModule = beanOptions?.module;
234
- }
235
- if (!ctxModule) {
236
- ctxModule = ctxCaller?.module?.info?.relativeName || ctxParent?.module?.info?.relativeName;
237
- }
238
- // ctx
239
- const ctx = await this.createAnonymousContext({ locale, subdomain, module: ctxModule, instance });
240
- // innerAccess
241
- ctx.innerAccess = true;
242
- // ctxCaller
243
- if (ctxCaller) {
244
- // multipart
245
- ctx.multipart = function (options) {
246
- return ctxCaller.multipart(options);
247
- };
248
- // delegateProperties
249
- delegateProperties(ctx, ctxCaller);
250
- // ctxCaller
251
- ctx.ctxCaller = ctxCaller;
252
- }
253
- // ctxParent
254
- if (ctxParent) {
255
- // delegateProperties
256
- delegateProperties(ctx, ctxParent);
257
- // dbLevel
258
- ctx.dbLevel = (ctxParent.dbLevel || 0) + 1;
259
- }
260
- // dbLevel
261
- if (!ctxCaller && !ctxParent) {
262
- ctx.dbLevel = 1;
263
- }
264
- // bean
265
- const bean = beanFullName ? ctx.bean._getBean(beanFullName) : null;
266
- if (!bean && beanFullName && !is_type_of_1.default.function(fn)) {
267
- throw new Error(`bean not found: ${beanFullName}`);
268
- }
269
- // execute
270
- let res;
271
- if (transaction) {
272
- res = await (0, index_js_1.Cast)(ctx).transaction.begin(async () => {
273
- return await this._executeBeanFn({ fn, ctx, bean, context });
274
- });
275
- }
276
- else {
277
- res = await this._executeBeanFn({ fn, ctx, bean, context });
278
- }
279
- // tail done
280
- await ctx.tailDone();
281
- // ok
282
- return res;
283
- }
284
- async _executeBeanFn({ fn, ctx, bean, context }) {
285
- let res;
286
- if (is_type_of_1.default.function(fn)) {
287
- res = await fn({ ctx, bean, context });
288
- }
289
- else {
290
- fn = fn || 'execute';
291
- if (!bean[fn]) {
292
- throw new Error(`bean method not found: ${bean.__beanFullName__}:${fn}`);
293
- }
294
- res = await bean[fn](context);
295
- }
296
- return res;
297
- }
298
- async lock({ subdomain, resource, fn, options, redlock, }) {
299
- // resource
300
- const _lockResource = `redlock_${this.app.name}:${this.subdomainDesp(subdomain)}:${resource}`;
301
- // options
302
- const _lockOptions = Object.assign({}, this.app.config.queue.redlock.options, options);
303
- // redlock
304
- if (!redlock) {
305
- redlock = this.app.meta.redlock.create(_lockOptions);
306
- }
307
- let _lock = await redlock.lock(_lockResource, _lockOptions.lockTTL);
308
- // timer
309
- let _lockTimer = null;
310
- const _lockDone = () => {
311
- if (_lockTimer) {
312
- clearInterval(_lockTimer);
313
- _lockTimer = null;
314
- }
315
- };
316
- _lockTimer = setInterval(() => {
317
- _lock
318
- .extend(_lockOptions.lockTTL)
319
- .then(lock => {
320
- _lock = lock;
321
- })
322
- .catch(err => {
323
- this.app.logger.error(err);
324
- _lockDone();
325
- });
326
- }, _lockOptions.lockTTL / 2);
327
- try {
328
- const res = await fn();
329
- _lockDone();
330
- await _lock.unlock();
331
- return res;
332
- }
333
- catch (err) {
334
- _lockDone();
335
- await _lock.unlock();
336
- throw err;
337
- }
338
- }
339
- subdomainDesp(subdomain) {
340
- if (subdomain === undefined || subdomain === null)
341
- return '~';
342
- return subdomain || '-';
343
- }
344
- deprecated(oldUsage, newUsage) {
345
- const message = '`'
346
- .concat(oldUsage, '` is deprecated and will be removed in a later version. Use `')
347
- .concat(newUsage, '` instead');
348
- return console.warn(message);
349
- }
350
- checkGate(gate) {
351
- // check none
352
- if (!gate)
353
- return true;
354
- // check env
355
- if (!this._checkGateEnv(gate.env))
356
- return false;
357
- // default
358
- return true;
359
- }
360
- _checkGateEnv(env) {
361
- // check none
362
- if (!env)
363
- return true;
364
- if (!Array.isArray(env))
365
- env = env.split(',');
366
- const bingo = env.some(item => {
367
- if (this.app.config.env === item)
368
- return true;
369
- if (__EnvTests.includes(this.app.config.env) && __EnvTests.includes(item))
370
- return true;
371
- return false;
372
- });
373
- if (!bingo)
374
- return false;
375
- return true;
376
- }
377
- requireDynamic(file) {
378
- if (!file)
379
- throw new Error('file should not empty');
380
- let instance = require(file);
381
- const mtime = this._requireDynamic_getFileTime(file);
382
- if (instance.__requireDynamic_mtime === undefined) {
383
- instance.__requireDynamic_mtime = mtime;
384
- }
385
- else if (instance.__requireDynamic_mtime !== mtime) {
386
- delete require.cache[require.resolve(file)];
387
- instance = require(file);
388
- instance.__requireDynamic_mtime = mtime;
389
- }
390
- return instance;
391
- }
392
- _requireDynamic_getFileTime(file) {
393
- if (!path_1.default.isAbsolute(file))
394
- return null;
395
- const exists = fs_extra_1.default.pathExistsSync(file);
396
- if (!exists)
397
- return null;
398
- // stat
399
- const stat = fs_extra_1.default.statSync(file);
400
- return stat.mtime.valueOf();
401
- }
402
- }
403
- exports.AppUtil = AppUtil;
404
- function delegateProperties(ctx, ctxCaller) {
405
- const req = ctx.req;
406
- for (const property of ['cookies', 'session', 'user', 'state']) {
407
- delegateProperty(ctx, ctxCaller, property);
408
- }
409
- for (const property of ['query', 'params', 'headers', 'body']) {
410
- delegateProperty(ctx.request, ctxCaller.request, property);
411
- if (ctx.request[property])
412
- req[property] = ctx.request[property];
413
- }
414
- if (ctx.session)
415
- req.session = ctx.session;
416
- // if (ctx.query) req.query = ctx.query;
417
- // if (ctx.request.body) req.body = ctx.request.body;
418
- }
419
- function delegateProperty(ctx, ctxCaller, property) {
420
- const keyMock = `__executeBean__mock__${property}__`;
421
- const keyOriginal = `__executeBean__mock__${property}__original__`;
422
- if (['cookies', 'session', 'headers'].includes(property)) {
423
- ctx[keyOriginal] = ctx[property];
424
- }
425
- Object.defineProperty(ctx, property, {
426
- get() {
427
- const value = ctxCaller && ctxCaller[property];
428
- if (value)
429
- return value;
430
- //
431
- if (['user', 'body'].includes(property))
432
- return value;
433
- //
434
- if (['cookies', 'session', 'headers'].includes(property)) {
435
- return ctx[keyOriginal];
436
- }
437
- //
438
- if (!ctx[keyMock]) {
439
- ctx[keyMock] = {};
440
- }
441
- return ctx[keyMock];
442
- },
443
- });
444
- }
445
- //# sourceMappingURL=util.js.map
@@ -1,34 +0,0 @@
1
- import { BeanSimple } from '../bean/beanSimple.js';
2
- import { VonaContext, PowerPartial } from '../../types/index.js';
3
- import { IExecuteBeanCallback } from './util.js';
4
- export declare class CtxUtil extends BeanSimple {
5
- runInBackground(scope: any): void;
6
- lock({ subdomain, resource, fn, options, redlock }: any): Promise<any>;
7
- broadcastEmit({ locale, subdomain, module, broadcastName, data }: any): void;
8
- queuePush(info: any): void;
9
- queuePushAsync(info: any): Promise<unknown>;
10
- _queuePushInfoPrepare(info: any): any;
11
- executeBean({ locale, subdomain, beanModule, beanFullName, context, fn, transaction, instance, }: {
12
- locale?: string;
13
- subdomain?: string;
14
- beanModule?: string;
15
- beanFullName?: string;
16
- context?: any;
17
- fn?: IExecuteBeanCallback | string;
18
- transaction?: boolean;
19
- instance?: boolean;
20
- }): Promise<any>;
21
- executeBeanIsolate({ locale, subdomain, beanModule, beanFullName, context, fn, transaction, ctxParent, instance, }: {
22
- locale?: string;
23
- subdomain?: string | null;
24
- beanModule?: string;
25
- beanFullName?: string;
26
- context?: any;
27
- fn?: IExecuteBeanCallback | string;
28
- transaction?: boolean;
29
- ctxParent?: PowerPartial<VonaContext>;
30
- instance?: boolean;
31
- }): Promise<any>;
32
- performAction({ innerAccess, method, url, query, params, headers, body }: any): Promise<any>;
33
- }
34
- //# sourceMappingURL=utilCtx.d.ts.map