mm_os 3.3.1 → 4.0.1

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 (380) hide show
  1. package/LICENSE +21 -201
  2. package/README.md +498 -99
  3. package/README_EN.md +505 -0
  4. package/adapter/adapter.js +431 -0
  5. package/adapter/custom_persistence.js +660 -0
  6. package/adapter/mqtt.js +273 -0
  7. package/adapter/socket.js +113 -0
  8. package/adapter/web.js +67 -0
  9. package/adapter/websocket.js +146 -0
  10. package/com/api/com.json +5 -0
  11. package/{core/com → com}/api/config.tpl.json +8 -8
  12. package/com/api/drive.js +708 -0
  13. package/com/api/index.js +198 -0
  14. package/com/api/oauth.js +200 -0
  15. package/com/api/script.tpl.js +32 -0
  16. package/com/cmd/README.md +11 -0
  17. package/com/cmd/com.json +5 -0
  18. package/com/cmd/config.tpl.json +122 -0
  19. package/com/cmd/drive.js +1548 -0
  20. package/com/cmd/index.js +1066 -0
  21. package/com/cmd/msg.json +48 -0
  22. package/com/cmd/nlp.js +525 -0
  23. package/com/cmd/script.tpl.js +32 -0
  24. package/com/db/com.json +5 -0
  25. package/com/db/drive.js +1999 -0
  26. package/com/db/index.js +242 -0
  27. package/{core/com → com}/event/README.md +4 -4
  28. package/com/event/com.json +5 -0
  29. package/{core/com → com}/event/config.tpl.json +18 -18
  30. package/com/event/drive.js +59 -0
  31. package/com/event/index.js +409 -0
  32. package/com/event/script.tpl.js +23 -0
  33. package/com/mqtt/com.json +5 -0
  34. package/{core/com → com}/mqtt/config.tpl.json +3 -5
  35. package/com/mqtt/drive.js +676 -0
  36. package/com/mqtt/index.js +822 -0
  37. package/com/mqtt/mm_mqtt.js +425 -0
  38. package/com/mqtt/script.tpl.js +723 -0
  39. package/com/nav/com.json +5 -0
  40. package/com/nav/config.tpl.json +84 -0
  41. package/com/nav/drive.js +702 -0
  42. package/com/nav/index.js +231 -0
  43. package/{core/com → com}/nav/tpl/admin_pc/page_config.vue +280 -280
  44. package/{core/com → com}/nav/tpl/admin_pc/page_config_form.vue +194 -194
  45. package/com/nav/tpl/admin_pc/page_form.vue +180 -0
  46. package/com/nav/tpl/admin_pc/page_view.vue +124 -0
  47. package/com/nav/tpl/dev_pc/page_default.vue +247 -0
  48. package/com/nav/tpl/dev_pc/page_type.vue +313 -0
  49. package/com/nav/tpl/home_pc/page_default.vue +234 -0
  50. package/com/nav/tpl/home_pc/page_form.vue +137 -0
  51. package/com/nav/tpl/home_pc/page_list.vue +234 -0
  52. package/com/nav/tpl/home_pc/page_nav.vue +221 -0
  53. package/com/nav/tpl/home_pc/page_type.vue +234 -0
  54. package/com/nav/tpl/home_pc/page_view.vue +125 -0
  55. package/com/nav/tpl/home_phone/page_channel.vue +234 -0
  56. package/com/nav/tpl/home_phone/page_default.vue +234 -0
  57. package/com/nav/tpl/home_phone/page_form.vue +137 -0
  58. package/com/nav/tpl/home_phone/page_nav.vue +237 -0
  59. package/com/nav/tpl/home_phone/page_type.vue +234 -0
  60. package/com/nav/tpl/home_phone/page_view.vue +125 -0
  61. package/com/nav/viewmodel.js +446 -0
  62. package/com/param/com.json +5 -0
  63. package/{core/com → com}/param/config.tpl.json +7 -1
  64. package/com/param/drive.js +502 -0
  65. package/com/param/index.js +155 -0
  66. package/com/param/script.tpl.js +12 -0
  67. package/com/pendant/com.json +5 -0
  68. package/{core/com/component → com/pendant}/config.tpl.json +15 -13
  69. package/com/pendant/drive.js +204 -0
  70. package/com/pendant/index.js +441 -0
  71. package/com/pendant/pendant.html +16 -0
  72. package/com/pendant/script.tpl.js +18 -0
  73. package/com/socket/com.json +5 -0
  74. package/com/socket/config.tpl.json +12 -0
  75. package/com/socket/drive.js +651 -0
  76. package/com/socket/index.js +351 -0
  77. package/com/socket/script.tpl.js +41 -0
  78. package/com/sql/com.json +5 -0
  79. package/{core/com → com}/sql/config.tpl.json +13 -9
  80. package/com/sql/drive.js +1259 -0
  81. package/com/sql/index.js +150 -0
  82. package/com/sql/script.tpl.js +47 -0
  83. package/com/static/com.json +5 -0
  84. package/{core/com → com}/static/config.tpl.json +10 -6
  85. package/com/static/drive.js +194 -0
  86. package/com/static/index.js +226 -0
  87. package/com/static/script.tpl.js +28 -0
  88. package/com/task/com.json +5 -0
  89. package/{core/com → com}/task/config.tpl.json +4 -6
  90. package/com/task/drive.js +405 -0
  91. package/com/task/index.js +148 -0
  92. package/com/task/script.tpl.js +37 -0
  93. package/com/template/com.json +5 -0
  94. package/com/template/config.tpl.json +16 -0
  95. package/com/template/drive.js +80 -0
  96. package/com/template/index.js +141 -0
  97. package/com.js +156 -0
  98. package/common/README.md +2 -0
  99. package/common/handler/msg/handler.json +22 -0
  100. package/common/handler/msg/index.js +23 -0
  101. package/common/handler/player/handler.json +22 -0
  102. package/common/handler/player/index.js +287 -0
  103. package/common/handler/user/handler.json +22 -0
  104. package/common/handler/user/index.js +23 -0
  105. package/common/middleware/web_after/index.js +29 -0
  106. package/common/middleware/web_after/middleware.json +9 -0
  107. package/common/middleware/web_base/index.js +113 -0
  108. package/common/middleware/web_base/middleware.json +19 -0
  109. package/common/middleware/web_before/index.js +33 -0
  110. package/common/middleware/web_before/middleware.json +9 -0
  111. package/common/middleware/web_cors/index.js +87 -0
  112. package/common/middleware/web_cors/middleware.json +24 -0
  113. package/common/middleware/web_error/index.js +119 -0
  114. package/common/middleware/web_error/middleware.json +18 -0
  115. package/common/middleware/web_ip/index.js +15 -0
  116. package/common/middleware/web_ip/middleware.json +14 -0
  117. package/common/middleware/web_logger/index.js +156 -0
  118. package/common/middleware/web_logger/middleware.json +14 -0
  119. package/common/middleware/web_main/index.js +24 -0
  120. package/common/middleware/web_main/middleware.json +9 -0
  121. package/common/middleware/web_static/index.js +73 -0
  122. package/common/middleware/web_static/middleware.json +54 -0
  123. package/common/middleware/web_waf/index.js +385 -0
  124. package/common/middleware/web_waf/middleware.json +13 -0
  125. package/common/model/msg/index.js +88 -0
  126. package/common/model/msg/model.json +401 -0
  127. package/common/model/player/index.js +63 -0
  128. package/common/model/player/model.json +185 -0
  129. package/common/model/user/index.js +11 -0
  130. package/common/model/user/model.json +219 -0
  131. package/core/app/config.tpl.json +67 -0
  132. package/core/app/index.js +632 -0
  133. package/core/app/script.tpl.js +52 -0
  134. package/core/channel/index.js +899 -0
  135. package/core/channel/matcher.js +585 -0
  136. package/core/com/config.tpl.json +16 -0
  137. package/core/com/index.js +74 -0
  138. package/core/com/script.tpl.js +5 -0
  139. package/core/component/component.js +42 -0
  140. package/core/component/config.tpl.json +63 -0
  141. package/core/component/index.js +273 -0
  142. package/core/component/script.tpl.js +19 -0
  143. package/core/controller/config.tpl.json +14 -0
  144. package/core/controller/index.js +373 -0
  145. package/core/controller/script.tpl.js +27 -0
  146. package/core/factory/config.tpl.json +14 -0
  147. package/core/factory/entity.js +275 -0
  148. package/core/factory/index.js +241 -0
  149. package/core/factory/script.tpl.js +16 -0
  150. package/core/game/bat/index.js +137 -0
  151. package/core/game/bat/world.js +622 -0
  152. package/core/game/config.tpl.json +16 -0
  153. package/core/game/entity_admin.js +230 -0
  154. package/core/game/index.js +186 -0
  155. package/core/handler/config.tpl.json +22 -0
  156. package/core/handler/index.js +181 -0
  157. package/core/handler/script.tpl.js +23 -0
  158. package/core/logic/config.tpl.json +14 -0
  159. package/core/logic/index.js +59 -0
  160. package/core/logic/script.tpl.js +19 -0
  161. package/core/middleware/config.tpl.json +16 -0
  162. package/core/middleware/index.js +125 -0
  163. package/core/middleware/script.tpl.js +37 -0
  164. package/core/mod/config.tpl.json +22 -0
  165. package/core/mod/index.js +130 -0
  166. package/core/mod/script.tpl.js +34 -0
  167. package/core/model/config.tpl.json +219 -0
  168. package/core/model/index.js +272 -0
  169. package/core/model/model.js +27 -0
  170. package/core/model/script.tpl.js +20 -0
  171. package/core/notifier/config.tpl.json +14 -0
  172. package/core/notifier/index.js +77 -0
  173. package/core/notifier/script.tpl.js +20 -0
  174. package/core/plugin/config.tpl.json +24 -0
  175. package/core/plugin/index.js +232 -0
  176. package/core/plugin/script.tpl.js +51 -0
  177. package/core/pusher/config.tpl.json +14 -0
  178. package/core/pusher/index.js +161 -0
  179. package/core/pusher/script.tpl.js +20 -0
  180. package/core/room/bat/index.js +170 -0
  181. package/core/room/bat/room.js +524 -0
  182. package/core/room/config.tpl.json +20 -0
  183. package/core/room/index.js +249 -0
  184. package/core/room/room.js +61 -0
  185. package/core/scene/config.tpl.json +14 -0
  186. package/core/scene/index.js +466 -0
  187. package/core/scene/loop.js +1255 -0
  188. package/core/scene/map.js +28 -0
  189. package/core/scene/script.tpl.js +22 -0
  190. package/core/sender/config.tpl.json +14 -0
  191. package/core/sender/index.js +79 -0
  192. package/core/sender/script.tpl.js +20 -0
  193. package/core/service/config.tpl.json +14 -0
  194. package/core/service/index.js +100 -0
  195. package/core/service/script.tpl.js +25 -0
  196. package/core/store/config.tpl.json +26 -0
  197. package/core/store/index.js +1755 -0
  198. package/core/store/script.tpl.js +22 -0
  199. package/core/store/sql.js +1464 -0
  200. package/core/system/config.tpl.json +18 -0
  201. package/core/system/index.js +312 -0
  202. package/core/system/script.tpl.js +77 -0
  203. package/core/view/config.tpl.json +14 -0
  204. package/core/view/index.js +91 -0
  205. package/core/view/script.tpl.js +20 -0
  206. package/core/zone/bat/index.js +725 -0
  207. package/core/zone/config.tpl.json +54 -0
  208. package/core/zone/index.js +614 -0
  209. package/core/zone/script.tpl.js +10 -0
  210. package/core/zone/zone_bat.js +136 -0
  211. package/core//345/237/272/347/261/273/346/250/241/345/235/227/346/270/205/345/215/225.md +24 -0
  212. package/index.js +17 -333
  213. package/os.js +57 -0
  214. package/package.json +65 -55
  215. package/server.js +598 -0
  216. package/README.en.md +0 -36
  217. package/conf.json +0 -3
  218. package/core/base/mqtt/index.js +0 -1110
  219. package/core/base/mqtt/lib.js +0 -40
  220. package/core/base/web/index.js +0 -245
  221. package/core/com/api/com.json +0 -4
  222. package/core/com/api/drive.js +0 -668
  223. package/core/com/api/index.js +0 -108
  224. package/core/com/api/oauth.js +0 -158
  225. package/core/com/api/script.js +0 -32
  226. package/core/com/app/README.md +0 -3
  227. package/core/com/app/com.json +0 -4
  228. package/core/com/app/config.tpl.json +0 -16
  229. package/core/com/app/drive.js +0 -309
  230. package/core/com/app/index.js +0 -211
  231. package/core/com/app/script.js +0 -155
  232. package/core/com/cmd/com.json +0 -4
  233. package/core/com/cmd/config.tpl.json +0 -66
  234. package/core/com/cmd/drive.js +0 -513
  235. package/core/com/cmd/index.js +0 -354
  236. package/core/com/cmd/old/5w2h.js +0 -54
  237. package/core/com/cmd/old/drive.js +0 -423
  238. package/core/com/cmd/script.js +0 -11
  239. package/core/com/component/README.md +0 -3
  240. package/core/com/component/com.json +0 -4
  241. package/core/com/component/component.html +0 -16
  242. package/core/com/component/drive.js +0 -197
  243. package/core/com/component/index.js +0 -312
  244. package/core/com/component/script.js +0 -18
  245. package/core/com/db/com.json +0 -4
  246. package/core/com/db/drive.js +0 -1160
  247. package/core/com/db/index.js +0 -176
  248. package/core/com/event/com.json +0 -4
  249. package/core/com/event/drive.js +0 -133
  250. package/core/com/event/index.js +0 -345
  251. package/core/com/event/script.js +0 -26
  252. package/core/com/eventer/com.js +0 -477
  253. package/core/com/eventer/com.json +0 -4
  254. package/core/com/middleware/com.js +0 -154
  255. package/core/com/middleware/com.json +0 -4
  256. package/core/com/middleware/config.tpl.json +0 -8
  257. package/core/com/middleware/script.js +0 -9
  258. package/core/com/mqtt/com.json +0 -4
  259. package/core/com/mqtt/drive.js +0 -600
  260. package/core/com/mqtt/index.js +0 -572
  261. package/core/com/mqtt/mm_mqtt.js +0 -330
  262. package/core/com/mqtt/script.js +0 -604
  263. package/core/com/msg/com.js +0 -296
  264. package/core/com/msg/com.json +0 -4
  265. package/core/com/nav/com.json +0 -4
  266. package/core/com/nav/config.tpl.json +0 -75
  267. package/core/com/nav/drive.js +0 -549
  268. package/core/com/nav/index.js +0 -182
  269. package/core/com/nav/tpl/admin_pc/page_form.vue +0 -180
  270. package/core/com/nav/tpl/admin_pc/page_view.vue +0 -124
  271. package/core/com/nav/tpl/dev_pc/page_default.vue +0 -247
  272. package/core/com/nav/tpl/dev_pc/page_type.vue +0 -313
  273. package/core/com/nav/tpl/home_pc/page_default.vue +0 -234
  274. package/core/com/nav/tpl/home_pc/page_form.vue +0 -137
  275. package/core/com/nav/tpl/home_pc/page_list.vue +0 -234
  276. package/core/com/nav/tpl/home_pc/page_nav.vue +0 -221
  277. package/core/com/nav/tpl/home_pc/page_type.vue +0 -234
  278. package/core/com/nav/tpl/home_pc/page_view.vue +0 -125
  279. package/core/com/nav/tpl/home_phone/page_channel.vue +0 -234
  280. package/core/com/nav/tpl/home_phone/page_default.vue +0 -234
  281. package/core/com/nav/tpl/home_phone/page_form.vue +0 -137
  282. package/core/com/nav/tpl/home_phone/page_nav.vue +0 -237
  283. package/core/com/nav/tpl/home_phone/page_type.vue +0 -234
  284. package/core/com/nav/tpl/home_phone/page_view.vue +0 -125
  285. package/core/com/nav/viewmodel.js +0 -296
  286. package/core/com/param/drive.js +0 -366
  287. package/core/com/param/index.js +0 -80
  288. package/core/com/param/script.js +0 -12
  289. package/core/com/param/test.js +0 -98
  290. package/core/com/plugin/README.md +0 -3
  291. package/core/com/plugin/com.json +0 -4
  292. package/core/com/plugin/config.tpl.json +0 -26
  293. package/core/com/plugin/drive.js +0 -536
  294. package/core/com/plugin/index.js +0 -259
  295. package/core/com/plugin/script.js +0 -213
  296. package/core/com/rpc/com.json +0 -4
  297. package/core/com/rpc/drive.js +0 -160
  298. package/core/com/rpc/index.js +0 -87
  299. package/core/com/rpc/rpc.js +0 -118
  300. package/core/com/socket/com.json +0 -4
  301. package/core/com/socket/config.tpl.json +0 -14
  302. package/core/com/socket/drive.js +0 -403
  303. package/core/com/socket/index.js +0 -62
  304. package/core/com/socket/script.js +0 -42
  305. package/core/com/sql/drive.js +0 -1087
  306. package/core/com/sql/index.js +0 -83
  307. package/core/com/sql/script.js +0 -48
  308. package/core/com/static/com.json +0 -4
  309. package/core/com/static/drive.js +0 -220
  310. package/core/com/static/index.js +0 -149
  311. package/core/com/static/script.js +0 -28
  312. package/core/com/task/com.json +0 -4
  313. package/core/com/task/drive.js +0 -403
  314. package/core/com/task/index.js +0 -110
  315. package/core/com/task/script.js +0 -37
  316. package/core/com/timer/com.js +0 -217
  317. package/core/com/timer/com.json +0 -4
  318. package/core/com/tpl/com.js +0 -19
  319. package/core/com/tpl/com.json +0 -4
  320. package/lib/actions.js +0 -50
  321. package/lib/base.js +0 -361
  322. package/lib/com.js +0 -29
  323. package/lib/ref.js +0 -121
  324. package/middleware/cors/index.js +0 -119
  325. package/middleware/cors/middleware.json +0 -20
  326. package/middleware/csrf/index.js +0 -202
  327. package/middleware/csrf/middleware.json +0 -24
  328. package/middleware/ip_firewall/index.js +0 -476
  329. package/middleware/ip_firewall/middleware.json +0 -109
  330. package/middleware/mqtt_base/index.js +0 -10
  331. package/middleware/mqtt_base/middleware.json +0 -11
  332. package/middleware/security_audit/index.js +0 -543
  333. package/middleware/security_audit/middleware.json +0 -48
  334. package/middleware/waf/index.js +0 -343
  335. package/middleware/waf/middleware.json +0 -10
  336. package/middleware/waf_ddos/index.js +0 -520
  337. package/middleware/waf_ddos/middleware.json +0 -38
  338. package/middleware/waf_xss/index.js +0 -269
  339. package/middleware/waf_xss/middleware.json +0 -18
  340. package/middleware/web_after/index.js +0 -33
  341. package/middleware/web_after/middleware.json +0 -10
  342. package/middleware/web_base/index.js +0 -90
  343. package/middleware/web_base/middleware.json +0 -10
  344. package/middleware/web_before/index.js +0 -27
  345. package/middleware/web_before/middleware.json +0 -10
  346. package/middleware/web_check/index.js +0 -28
  347. package/middleware/web_check/middleware.json +0 -10
  348. package/middleware/web_main/index.js +0 -28
  349. package/middleware/web_main/middleware.json +0 -10
  350. package/middleware/web_proxy/index.js +0 -37
  351. package/middleware/web_proxy/middleware.json +0 -10
  352. package/middleware/web_render/index.js +0 -87
  353. package/middleware/web_render/middleware.json +0 -10
  354. package/middleware/web_socket/index.js +0 -34
  355. package/middleware/web_socket/middleware.json +0 -10
  356. package/middleware/web_static/index.js +0 -115
  357. package/middleware/web_static/middleware.json +0 -10
  358. /package/{core/com → com}/api/README.md +0 -0
  359. /package/{core/com → com}/db/README.md +0 -0
  360. /package/{core/com → com}/mqtt/README.md +0 -0
  361. /package/{core/com → com}/nav/README.md +0 -0
  362. /package/{core/com → com}/nav/tpl/admin_pc/page_channel.vue +0 -0
  363. /package/{core/com → com}/nav/tpl/admin_pc/page_default.vue +0 -0
  364. /package/{core/com → com}/nav/tpl/admin_pc/page_lang.vue +0 -0
  365. /package/{core/com → com}/nav/tpl/admin_pc/page_nav.vue +0 -0
  366. /package/{core/com → com}/nav/tpl/admin_pc/page_table.vue +0 -0
  367. /package/{core/com → com}/nav/tpl/admin_pc/page_type.vue +0 -0
  368. /package/{core/com → com}/nav/tpl/dev_pc/page_channel.vue +0 -0
  369. /package/{core/com → com}/nav/tpl/dev_pc/page_config.vue +0 -0
  370. /package/{core/com → com}/nav/tpl/dev_pc/page_form.vue +0 -0
  371. /package/{core/com → com}/nav/tpl/dev_pc/page_nav.vue +0 -0
  372. /package/{core/com → com}/nav/tpl/dev_pc/page_table.vue +0 -0
  373. /package/{core/com → com}/nav/tpl/home_pc/page_channel.vue +0 -0
  374. /package/{core/com → com}/nav/tpl/home_phone/page_list.vue +0 -0
  375. /package/{core/com → com}/param/README.md +0 -0
  376. /package/{core/com/cmd → com/pendant}/README.md +0 -0
  377. /package/{core/com → com}/socket/README.md +0 -0
  378. /package/{core/com → com}/sql/README.md +0 -0
  379. /package/{core/com → com}/static/README.md +0 -0
  380. /package/{core/com → com}/task/README.md +0 -0
@@ -0,0 +1,150 @@
1
+ const Manager = require('mm_machine').Manager;
2
+ const Drive = require('./drive');
3
+
4
+ /**
5
+ * Sql语句拓展类
6
+ * @augments {Manager}
7
+ * @class
8
+ */
9
+ class Sql extends Manager {
10
+ /**
11
+ * 配置参数
12
+ * @type {object}
13
+ */
14
+ static config = {
15
+ /**
16
+ * 名称
17
+ * @type {string}
18
+ */
19
+ name: '',
20
+ /**
21
+ * 标题
22
+ * @type {string}
23
+ */
24
+ title: 'sql管理',
25
+ /**
26
+ * 描述
27
+ * @type {string}
28
+ */
29
+ description: '这是sql管理器',
30
+ /**
31
+ * 检索文件名
32
+ * @type {string}
33
+ */
34
+ filename: 'sql.json',
35
+ /**
36
+ * 模板目录
37
+ * @type {string}
38
+ */
39
+ tpl_dir: __dirname,
40
+ /**
41
+ * 基础目录
42
+ * @type {string}
43
+ */
44
+ base_dir: '../common/sql'.fullname(__dirname),
45
+ /**
46
+ * 自定义目录,加载项目自定义资源
47
+ * @type {string}
48
+ */
49
+ dir: './app'.fullname(),
50
+ /**
51
+ * 搜索模式 dir按目录搜索 | file按文件名搜索
52
+ * @type {string}
53
+ */
54
+ search_way: 'file',
55
+ /**
56
+ * 是否懒加载
57
+ * @type {boolean}
58
+ */
59
+ lazy_load: true,
60
+ /**
61
+ * 模式
62
+ * 1.生产模式,改变文件不会重新加载
63
+ * 2.热更新模式,改变配置文件会重新加载配置,不重新加载脚本
64
+ * 3.热重载模式,改变配置文件都会加载配置和脚本
65
+ * 4.重载模式,执行完后重新加载脚本,避免变量污染
66
+ * 5.热更新+重载模式,改变配置文件重新加载配置和脚本,执行完后重新加载脚本
67
+ * @type {number}
68
+ */
69
+ mode: 3
70
+ };
71
+
72
+ /**
73
+ * 构造函数
74
+ * @param {object} config 配置参数
75
+ * @param {object} parent 父级模块
76
+ */
77
+ constructor(config, parent) {
78
+ super({ ...Sql.config, ...config }, parent);
79
+ }
80
+ }
81
+
82
+ /**
83
+ * sql驱动类
84
+ * @type {Drive}
85
+ */
86
+ Sql.prototype.Drive = Drive;
87
+
88
+ /**
89
+ * 排序
90
+ */
91
+ Sql.prototype.sort = function () {
92
+ let infos = this.getInfos();
93
+ infos.sortBy('asc', 'name');
94
+ };
95
+
96
+ /**
97
+ * 执行sql
98
+ * @param {string} name 名称
99
+ * @param {object} query 查询参数
100
+ * @param {object} body 修改参数
101
+ * @param {object} db 数据库管理器 (object) 只支持可用sql语句的数据库
102
+ * @returns {object} 执行结果
103
+ */
104
+ Sql.prototype.run = async function (name, query, body, db) {
105
+ var obj = this.get(name);
106
+ if (obj) {
107
+ var ret = await obj.run(query, body, db);
108
+ if (this.mode > 4) {
109
+ obj.do('reload');
110
+ }
111
+ return ret;
112
+ }
113
+ return null;
114
+ };
115
+
116
+ exports.Sql = Sql;
117
+
118
+
119
+ /**
120
+ * Sql模板池
121
+ */
122
+ if (!$.pool.sql) {
123
+ $.pool.sql = {};
124
+ }
125
+
126
+ /**
127
+ * Sql管理器,用于创建缓存
128
+ * @param {string} scope 作用域
129
+ * @param {string} title 标题
130
+ * @returns {object} 返回一个缓存类
131
+ */
132
+ function sqlAdmin(scope, title) {
133
+ var sc = scope || $.val.scope + '';
134
+ var obj = $.pool.sql[sc];
135
+ if (!obj) {
136
+ $.pool.sql[sc] = new Sql({
137
+ name: sc,
138
+ title: title
139
+ });
140
+ obj = $.pool.sql[sc];
141
+ }
142
+ return obj;
143
+ }
144
+
145
+ /**
146
+ * @module 导出Sql管理器
147
+ */
148
+ if ($.admin) {
149
+ $.admin.sql = sqlAdmin;
150
+ }
@@ -0,0 +1,47 @@
1
+
2
+
3
+ module.exports = {
4
+ /**
5
+ * 执行前, 用于过滤参数
6
+ * @param {object} params 参数对象,包含query和body 如:{ query: {} body: {} }
7
+ * @returns {object} 过滤后的参数
8
+ */
9
+ before(params) {
10
+ return params;
11
+ },
12
+
13
+ /**
14
+ * 验证, 用于判断是否执行
15
+ * @param {object} params 参数对象,包含query和body 如:{ query: {} body: {} }
16
+ * @returns {boolean} 验证通过返回true, 失败返回false
17
+ */
18
+ check(params) {
19
+ return true;
20
+ },
21
+
22
+ /**
23
+ * 执行后 可用于附加执行
24
+ * @param {object} params 参数对象,包含query和body 如:{ query: {} body: {} }
25
+ * @param {object} sql SQL模板对象
26
+ * @param {object} ret 最终执行结果
27
+ * @returns {object} 返回执行结果
28
+ */
29
+ after(params, sql, ret) {
30
+ return ret;
31
+ },
32
+
33
+ /**
34
+ * 执行主函数
35
+ * @param {object} params 参数对象,包含query和body 如:{ query: {} body: {} }
36
+ * @returns {object} 返回执行结果
37
+ */
38
+ main(params) {
39
+ var sql = '';
40
+ var ret = null;
41
+
42
+ return {
43
+ sql,
44
+ ret
45
+ };
46
+ }
47
+ };
@@ -0,0 +1,5 @@
1
+ {
2
+ "name": "Static",
3
+ "title": "静态文件管理器",
4
+ "state": 1
5
+ }
@@ -1,10 +1,14 @@
1
1
  {
2
2
  // 路由路径,注意:这里是泛路径,相当于/*
3
- "path": "/",
4
- // 默认文件,当直接访问这个路径时,如果存在默认文件,这直接访问该文件
5
- "index": "index.html",
3
+ "path": "${path || '/${name}'}",
4
+ // 名称, 由中英文和下“_”组成, 用于修改或卸载 例如: demo
5
+ "name": "${name || 'static'}",
6
+ // 标题, 用于查询时
7
+ "title": "${title || 'static资源'}",
8
+ // 状态 0未启用,1启用
9
+ "state": 1,
6
10
  // 资源缓存寿命,单位:秒
7
- "maxAge": 0,
11
+ "max_age": 0,
8
12
  // 是否恒久不变,一般资源文件可能变化,所以这里一般是false
9
13
  "immutable": false,
10
14
  // 是否使用brotli压缩方式
@@ -15,6 +19,6 @@
15
19
  "extensions": null,
16
20
  // 是否转换JS、vue代码为amd标准,true的情况下会把es6和commonJS都转成amd格式
17
21
  "convert_amd": false,
18
- // 调用脚本文件,如果请求改路由情况会调用改脚本文件
19
- "func_file": "./static.js"
22
+ // 调用脚本文件,如果请求改路由情况会调用改脚本文件 ./static.js
23
+ "main": ""
20
24
  }
@@ -0,0 +1,194 @@
1
+ const send = require('koa-send');
2
+ const Item = require('mm_machine').Drive;
3
+ const { Static } = require('mm_statics');
4
+
5
+ /**
6
+ * 静态文件驱动类
7
+ * @augments {Item}
8
+ * @class
9
+ */
10
+ class Drive extends Item {
11
+ static config = {
12
+ // 应用名
13
+ 'app': 'server',
14
+ // 插件名
15
+ 'plugin': 'sys',
16
+ // 物理根目录
17
+ 'root': '',
18
+ // 路由根路径
19
+ 'path': '',
20
+ // 名称
21
+ 'name': '',
22
+ // 首页
23
+ 'index': 'index.html',
24
+ // 重定向
25
+ 'redirect': true,
26
+ // 缓存保留10分钟
27
+ 'max_age': 60 * 10,
28
+ // 是否保持不变
29
+ 'immutable': true,
30
+ // 是否启用brotli压缩
31
+ 'brotli': true,
32
+ // 是否启用gizp压缩
33
+ 'gzip': true,
34
+ // 允许访问的拓展名
35
+ 'extensions': null,
36
+ // 是否将ES6转换AMD
37
+ 'convert_amd': true,
38
+ // 主程序文件 - 默认为空
39
+ 'main': ''
40
+ };
41
+ /**
42
+ * 构造函数
43
+ * @param {object} config 配置参数
44
+ * @param {object} parent 父对象
45
+ * @class
46
+ */
47
+ constructor(config, parent) {
48
+ super({ ...Drive.config, ...config }, parent);
49
+ // 更新并重载
50
+ this.mode = 3;
51
+ }
52
+ }
53
+
54
+ /**
55
+ * 发送文件函数
56
+ */
57
+ Drive.prototype.send = send;
58
+
59
+ /**
60
+ * 更新配置对象前
61
+ */
62
+ Drive.prototype._preset = function () {
63
+ var cg = this.config;
64
+ if (cg.maxAge) {
65
+ cg.max_age = cg.maxAge * 1000;
66
+ delete cg.maxAge;
67
+ }
68
+ if (!cg.app) {
69
+ cg.app = this.getAppName(this.config_file);
70
+ }
71
+ if (!cg.plugin) {
72
+ cg.plugin = this.getPluginName(this.config_file);
73
+ }
74
+ if (!cg.path) {
75
+ let app = cg.app || this.getAppName(this.config_file);
76
+ let plugin = cg.plugin || this.getPluginName(this.config_file);
77
+ if (plugin) {
78
+ cg.path = `/${app}/${plugin}/`;
79
+ }
80
+ else {
81
+ cg.path = `/${app}/`;
82
+ }
83
+ }
84
+ else if (!cg.path.endsWith('/')) {
85
+ cg.path += '/';
86
+ }
87
+ if (!cg.root) {
88
+ cg.root = this._getRoot(this.config_file);
89
+ }
90
+ this.static = new Static(cg);
91
+ };
92
+
93
+ /**
94
+ * 获取应用名
95
+ * @param {string} file 文件路径
96
+ * @returns {string} 应用名
97
+ */
98
+ Drive.prototype.getAppName = function (file) {
99
+ if (!file || typeof file !== 'string') {
100
+ return '';
101
+ }
102
+ return file.between('app/', '/') || '';
103
+ };
104
+
105
+ /**
106
+ * 获取插件名
107
+ * @param {string} file 文件路径
108
+ * @returns {string} 插件名
109
+ */
110
+ Drive.prototype.getPluginName = function (file) {
111
+ if (!file || typeof file !== 'string') {
112
+ return '';
113
+ }
114
+ return file.between('plugin/', '/') || '';
115
+ };
116
+
117
+ /**
118
+ * 获取物理根目录
119
+ * @param {string} file 文件路径
120
+ * @returns {string} 物理根目录
121
+ */
122
+ Drive.prototype._getRoot = function (file) {
123
+ if (!file || typeof file !== 'string') {
124
+ return '';
125
+ }
126
+ let f = file.replace(/\\/g, '/');
127
+ let dir = f.dirname().replace(/\\/g, '/').toLowerCase();
128
+ let ph = $.run_path.replace(/\\/g, '/').toLowerCase();
129
+ return dir.replace(ph, '.');
130
+ };
131
+
132
+ /**
133
+ * 执行前
134
+ * @param {object} ctx http请求上下文
135
+ * @param {object} path 文件路径
136
+ */
137
+ Drive.prototype.before = async function (ctx, path) { };
138
+
139
+ /**
140
+ * 执行
141
+ * @param {object} ctx http请求上下文
142
+ * @param {object} path 文件路径
143
+ * @returns {boolean} 成功发送返回true,失败返回false
144
+ */
145
+ Drive.prototype.main = async function (ctx, path) {
146
+ return send(ctx, path, this.config);
147
+ };
148
+
149
+ /**
150
+ * 执行后
151
+ * @param {object} ctx http请求上下文
152
+ * @param {object} path 文件路径
153
+ */
154
+ Drive.prototype.after = async function (ctx, path) { };
155
+
156
+ /**
157
+ * 执行静态文件
158
+ * @param {object} ctx Http请求上下文
159
+ * @param {object} next 跳过当前函数
160
+ * @returns {string} 执行成功返回文件路径
161
+ */
162
+ Drive.prototype.run = async function (ctx, next) {
163
+ return await this.static.main(ctx, next);
164
+ };
165
+
166
+ /**
167
+ * 获取名称
168
+ * @param {string} file 文件路径
169
+ * @returns {string} 名称
170
+ */
171
+ Drive.prototype._getName = function (file) {
172
+ return file.dirname().dirname().basename();
173
+ };
174
+
175
+ /**
176
+ * 获取模型
177
+ * @param {string} type 模型类型
178
+ * @returns {object} 返回获取到的模型
179
+ */
180
+ Drive.prototype.getModel = function (type) {
181
+ let model = { ...this.config };
182
+ let dir = this._getDir();
183
+ let l = $.slash;
184
+ let app_name = dir.between('app' + l, l);
185
+ let plugin_name = dir.between('plugin' + l, l);
186
+ let name = dir.basename();
187
+ model.app = app_name;
188
+ model.plugin = plugin_name;
189
+ model.name = model.name || plugin_name ? plugin_name + '_' + name : app_name + '_' + name;
190
+ model.path = model.path || plugin_name ? `/${app_name}/${plugin_name}/` : `/${app_name}/`;
191
+ return model;
192
+ };
193
+
194
+ module.exports = Drive;
@@ -0,0 +1,226 @@
1
+ const Manager = require('mm_machine').Manager;
2
+ const Drive = require('./drive');
3
+
4
+ /**
5
+ * 静态文件管理类
6
+ * @augments {Manager}
7
+ * @class
8
+ */
9
+ class Static extends Manager {
10
+ /**
11
+ * 配置参数
12
+ * @type {object}
13
+ */
14
+ static config = {
15
+ /**
16
+ * 名称
17
+ * @type {string}
18
+ */
19
+ name: '',
20
+ /**
21
+ * 标题
22
+ * @type {string}
23
+ */
24
+ title: '静态文件管理',
25
+ /**
26
+ * 描述
27
+ * @type {string}
28
+ */
29
+ description: '这是静态文件管理器',
30
+ /**
31
+ * 检索文件名
32
+ * @type {string}
33
+ */
34
+ filename: 'static.json',
35
+ /**
36
+ * 模板目录
37
+ * @type {string}
38
+ */
39
+ tpl_dir: __dirname,
40
+ /**
41
+ * 基础目录
42
+ * @type {string}
43
+ */
44
+ base_dir: '../common/static'.fullname(__dirname),
45
+ /**
46
+ * 自定义目录,加载项目自定义资源
47
+ * @type {string}
48
+ */
49
+ dir: './app'.fullname(),
50
+ /**
51
+ * 搜索模式 dir按目录搜索 | file按文件名搜索
52
+ * @type {string}
53
+ */
54
+ search_way: 'file',
55
+ /**
56
+ * 是否懒加载
57
+ * @type {boolean}
58
+ */
59
+ lazy_load: false,
60
+ /**
61
+ * 模式
62
+ * 1.生产模式,改变文件不会重新加载
63
+ * 2.热更新模式,改变配置文件会重新加载配置,不重新加载脚本
64
+ * 3.热重载模式,改变配置文件都会加载配置和脚本
65
+ * 4.重载模式,执行完后重新加载脚本,避免变量污染
66
+ * 5.热更新+重载模式,改变配置文件重新加载配置和脚本,执行完后重新加载脚本
67
+ * @type {number}
68
+ */
69
+ mode: 3
70
+ };
71
+
72
+ /**
73
+ * 构造函数
74
+ * @param {object} config 配置参数
75
+ * @param {object} parent 父级模块
76
+ */
77
+ constructor(config, parent) {
78
+ super({ ...Static.config, ...config }, parent);
79
+ }
80
+
81
+ /**
82
+ * 处理请求
83
+ * @param {object} ctx Http请求上下文
84
+ * @param {object} next 跳过函数
85
+ */
86
+ async _handleRequest(ctx, next) {
87
+ var md = ctx.method;
88
+ var path = ctx.path;
89
+ if (md === 'GET' || md === 'HEAD') {
90
+ await this._handleGetRequest(ctx, next, path);
91
+ } else {
92
+ await next();
93
+ }
94
+ }
95
+
96
+ /**
97
+ * 处理GET请求
98
+ * @param {object} ctx Http请求上下文
99
+ * @param {object} next 跳过函数
100
+ */
101
+ async run(ctx, next) {
102
+ var done;
103
+ var infos = this.getInfos();
104
+ var len = infos.length;
105
+ let path = ctx.path;
106
+ if (path.indexOf('.') !== -1) {
107
+ done = await this._tryServeFile(ctx, infos, len, function () { });
108
+ if (!done) {
109
+ await next();
110
+ }
111
+ } else {
112
+ await next();
113
+ await this._handleDirReq(ctx, infos, len, path);
114
+ }
115
+ }
116
+
117
+ /**
118
+ * 尝试提供文件服务
119
+ * @param {object} ctx Http请求上下文
120
+ * @param {Array} list 驱动列表
121
+ * @param {number} len 列表长度
122
+ * @param {object} next 跳过函数
123
+ * @returns {boolean} 是否成功
124
+ */
125
+ async _tryServeFile(ctx, infos, len, next) {
126
+ for (var i = 0; i < len; i++) {
127
+ var info = infos[i];
128
+ if (info.state === 1) {
129
+ let mod = this.getMod(info.name);
130
+ if (mod) {
131
+ var done = await mod.run(ctx, next);
132
+ if (done) {
133
+ return true;
134
+ }
135
+ }
136
+ }
137
+ }
138
+ return false;
139
+ }
140
+
141
+ /**
142
+ * 处理目录请求
143
+ * @param {object} ctx Http请求上下文
144
+ * @param {Array} infos 驱动信息列表
145
+ * @param {number} len 列表长度
146
+ * @param {string} path 请求路径
147
+ */
148
+ async _handleDirReq(ctx, infos, len, path) {
149
+ var q = ctx.request.querystring;
150
+ for (var i = 0; i < len; i++) {
151
+ var info = infos[i];
152
+ if (info.state === 1) {
153
+ let mod = this.getMod(info.name);
154
+ if (mod) {
155
+ var p = mod.config.path;
156
+ if (path === p) {
157
+ this._handleExactMatch(ctx, q, p);
158
+ break;
159
+ } else {
160
+ var done = await mod.run(ctx, () => { });
161
+ if (done) {
162
+ break;
163
+ }
164
+ }
165
+ }
166
+ }
167
+ }
168
+ }
169
+
170
+ /**
171
+ * 处理精确匹配
172
+ * @param {object} ctx Http请求上下文
173
+ * @param {string} q 查询字符串
174
+ * @param {string} p 路径
175
+ */
176
+ _handleExactMatch(ctx, q, p) {
177
+ if (ctx.status === 404) {
178
+ if (q) {
179
+ ctx.redirect(p + '/?' + q);
180
+ } else {
181
+ ctx.redirect(p + '/');
182
+ }
183
+ }
184
+ }
185
+ }
186
+
187
+ /**
188
+ * 静态文件驱动类
189
+ * @type {Drive}
190
+ */
191
+ Static.prototype.Drive = Drive;
192
+
193
+ exports.Static = Static;
194
+
195
+ /**
196
+ * 创建全局管理器
197
+ */
198
+ if (!$.pool.static) {
199
+ $.pool.static = {};
200
+ }
201
+
202
+ /**
203
+ * 静态文件管理器
204
+ * @param {string} scope 作用域
205
+ * @param {string} title 标题
206
+ * @returns {object} 返回一个缓存类
207
+ */
208
+ function staticAdmin(scope, title) {
209
+ var sc = scope || $.val.scope + '';
210
+ var obj = $.pool.static[sc];
211
+ if (!obj) {
212
+ $.pool.static[sc] = new Static({
213
+ name: sc,
214
+ title: title
215
+ });
216
+ obj = $.pool.static[sc];
217
+ }
218
+ return obj;
219
+ }
220
+
221
+ /**
222
+ * @module 导出Static管理器
223
+ */
224
+ if ($.admin) {
225
+ $.admin.static = staticAdmin;
226
+ }
@@ -0,0 +1,28 @@
1
+ /**
2
+ * 执行前
3
+ * @param {object} ctx http请求上下文
4
+ * @param {object} path 文件路径
5
+ */
6
+ async function before(ctx, path) {};
7
+
8
+ /**
9
+ * 执行
10
+ * @param {object} ctx http请求上下文
11
+ * @param {object} path 文件路径
12
+ * @returns {boolean} 成功发送返回true,失败返回false
13
+ */
14
+ async function main(ctx, path) {
15
+ return this.send(ctx, path, this.config);
16
+ };
17
+
18
+ /**
19
+ * 执行后
20
+ * @param {object} ctx http请求上下文
21
+ * @param {object} path 文件路径
22
+ */
23
+ async function after(ctx, path) {};
24
+
25
+
26
+ exports.before = before;
27
+ exports.main = main;
28
+ exports.after = after;
@@ -0,0 +1,5 @@
1
+ {
2
+ "name": "Task",
3
+ "title": "定时任务管理器",
4
+ "state": 1
5
+ }
@@ -1,14 +1,12 @@
1
1
  {
2
+ // 任务名称,用于动态增删改查
3
+ "name": "${name || 'demo'}",
2
4
  // 任务标题
3
- "title": "示例任务",
5
+ "title": "${title || '任务'}",
4
6
  // 任务描述
5
- "description": "描述任务使用方法",
6
- // 任务名称,用于动态增删改查
7
- "name": "demo",
7
+ "description": "${description || '描述任务使用方法'}",
8
8
  // 状态 0未启用,1启用
9
9
  "state": 1,
10
- // 任务驱动的脚本文件
11
- "func_file": "./index.js",
12
10
  // 任务执行次数,执行次数达标后不再执行。0为不限次数,一直执行
13
11
  "num": 2,
14
12
  // 任务间隔时长,单位:毫秒