mm_os 4.3.7 → 5.0.0

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 (232) hide show
  1. package/README.md +101 -504
  2. package/index.js +26 -19
  3. package/lib/loader.js +787 -0
  4. package/lib/os.js +369 -0
  5. package/package.json +55 -84
  6. package/LICENSE +0 -21
  7. package/README_EN.md +0 -505
  8. package/adapter/adapter.js +0 -484
  9. package/adapter/custom_persistence.js +0 -661
  10. package/adapter/mqtt.js +0 -254
  11. package/adapter/socket.js +0 -244
  12. package/adapter/web.js +0 -92
  13. package/adapter/websocket.js +0 -43
  14. package/ai.js +0 -130
  15. package/com/api/README.md +0 -3
  16. package/com/api/com.json +0 -5
  17. package/com/api/config.tpl.json +0 -41
  18. package/com/api/drive.js +0 -732
  19. package/com/api/index.js +0 -201
  20. package/com/api/oauth.js +0 -200
  21. package/com/api/script.tpl.js +0 -32
  22. package/com/cmd/README.md +0 -11
  23. package/com/cmd/com.json +0 -5
  24. package/com/cmd/config.tpl.json +0 -48
  25. package/com/cmd/drive.js +0 -176
  26. package/com/cmd/index.js +0 -287
  27. package/com/cmd/job/config.json +0 -66
  28. package/com/cmd/job/index.js +0 -241
  29. package/com/cmd/job/test.js +0 -188
  30. package/com/cmd/msg.json +0 -48
  31. package/com/cmd/script.tpl.js +0 -12
  32. package/com/db/README.md +0 -3
  33. package/com/db/com.json +0 -5
  34. package/com/db/drive.js +0 -2206
  35. package/com/db/index.js +0 -241
  36. package/com/event/README.md +0 -4
  37. package/com/event/com.json +0 -5
  38. package/com/event/config.tpl.json +0 -20
  39. package/com/event/drive.js +0 -61
  40. package/com/event/index.js +0 -438
  41. package/com/event/script.tpl.js +0 -23
  42. package/com/mqtt/README.md +0 -47
  43. package/com/mqtt/com.json +0 -5
  44. package/com/mqtt/config.tpl.json +0 -42
  45. package/com/mqtt/drive.js +0 -704
  46. package/com/mqtt/index.js +0 -1052
  47. package/com/mqtt/index.test.js +0 -503
  48. package/com/mqtt/script.tpl.js +0 -719
  49. package/com/nav/README.md +0 -2
  50. package/com/nav/com.json +0 -5
  51. package/com/nav/config.tpl.json +0 -84
  52. package/com/nav/drive.js +0 -702
  53. package/com/nav/index.js +0 -228
  54. package/com/nav/tpl/admin_pc/page_channel.vue +0 -305
  55. package/com/nav/tpl/admin_pc/page_config.vue +0 -280
  56. package/com/nav/tpl/admin_pc/page_config_form.vue +0 -194
  57. package/com/nav/tpl/admin_pc/page_default.vue +0 -247
  58. package/com/nav/tpl/admin_pc/page_form.vue +0 -180
  59. package/com/nav/tpl/admin_pc/page_lang.vue +0 -264
  60. package/com/nav/tpl/admin_pc/page_nav.vue +0 -321
  61. package/com/nav/tpl/admin_pc/page_table.vue +0 -296
  62. package/com/nav/tpl/admin_pc/page_type.vue +0 -321
  63. package/com/nav/tpl/admin_pc/page_view.vue +0 -124
  64. package/com/nav/tpl/dev_pc/page_channel.vue +0 -253
  65. package/com/nav/tpl/dev_pc/page_config.vue +0 -253
  66. package/com/nav/tpl/dev_pc/page_default.vue +0 -247
  67. package/com/nav/tpl/dev_pc/page_form.vue +0 -162
  68. package/com/nav/tpl/dev_pc/page_nav.vue +0 -253
  69. package/com/nav/tpl/dev_pc/page_table.vue +0 -247
  70. package/com/nav/tpl/dev_pc/page_type.vue +0 -313
  71. package/com/nav/tpl/home_pc/page_channel.vue +0 -234
  72. package/com/nav/tpl/home_pc/page_default.vue +0 -234
  73. package/com/nav/tpl/home_pc/page_form.vue +0 -137
  74. package/com/nav/tpl/home_pc/page_list.vue +0 -234
  75. package/com/nav/tpl/home_pc/page_nav.vue +0 -221
  76. package/com/nav/tpl/home_pc/page_type.vue +0 -234
  77. package/com/nav/tpl/home_pc/page_view.vue +0 -125
  78. package/com/nav/tpl/home_phone/page_channel.vue +0 -234
  79. package/com/nav/tpl/home_phone/page_default.vue +0 -234
  80. package/com/nav/tpl/home_phone/page_form.vue +0 -137
  81. package/com/nav/tpl/home_phone/page_list.vue +0 -234
  82. package/com/nav/tpl/home_phone/page_nav.vue +0 -237
  83. package/com/nav/tpl/home_phone/page_type.vue +0 -234
  84. package/com/nav/tpl/home_phone/page_view.vue +0 -125
  85. package/com/nav/viewmodel.js +0 -446
  86. package/com/param/README.md +0 -2
  87. package/com/param/com.json +0 -5
  88. package/com/param/config.tpl.json +0 -136
  89. package/com/param/drive.js +0 -502
  90. package/com/param/index.js +0 -158
  91. package/com/param/script.tpl.js +0 -12
  92. package/com/pendant/README.md +0 -3
  93. package/com/pendant/com.json +0 -5
  94. package/com/pendant/config.tpl.json +0 -32
  95. package/com/pendant/drive.js +0 -204
  96. package/com/pendant/index.js +0 -467
  97. package/com/pendant/pendant.html +0 -16
  98. package/com/pendant/script.tpl.js +0 -18
  99. package/com/socket/README.md +0 -47
  100. package/com/socket/com.json +0 -5
  101. package/com/socket/config.tpl.json +0 -12
  102. package/com/socket/drive.js +0 -679
  103. package/com/socket/index.js +0 -402
  104. package/com/socket/script.tpl.js +0 -41
  105. package/com/sql/README.md +0 -3
  106. package/com/sql/com.json +0 -5
  107. package/com/sql/config.tpl.json +0 -74
  108. package/com/sql/drive.js +0 -1328
  109. package/com/sql/index.js +0 -152
  110. package/com/sql/script.tpl.js +0 -47
  111. package/com/static/README.md +0 -2
  112. package/com/static/com.json +0 -5
  113. package/com/static/config.tpl.json +0 -24
  114. package/com/static/drive.js +0 -194
  115. package/com/static/index.js +0 -237
  116. package/com/static/script.tpl.js +0 -28
  117. package/com/task/README.md +0 -3
  118. package/com/task/com.json +0 -5
  119. package/com/task/config.tpl.json +0 -24
  120. package/com/task/drive.js +0 -428
  121. package/com/task/index.js +0 -159
  122. package/com/task/script.tpl.js +0 -40
  123. package/com/template/com.json +0 -5
  124. package/com/template/config.tpl.json +0 -16
  125. package/com/template/drive.js +0 -81
  126. package/com/template/index.js +0 -141
  127. package/com.js +0 -237
  128. package/common/README.md +0 -2
  129. package/common/middleware/web_after/index.js +0 -26
  130. package/common/middleware/web_after/middleware.json +0 -9
  131. package/common/middleware/web_base/index.js +0 -113
  132. package/common/middleware/web_base/middleware.json +0 -19
  133. package/common/middleware/web_before/index.js +0 -33
  134. package/common/middleware/web_before/middleware.json +0 -9
  135. package/common/middleware/web_cors/index.js +0 -87
  136. package/common/middleware/web_cors/middleware.json +0 -24
  137. package/common/middleware/web_error/index.js +0 -131
  138. package/common/middleware/web_error/middleware.json +0 -19
  139. package/common/middleware/web_ip/index.js +0 -15
  140. package/common/middleware/web_ip/middleware.json +0 -14
  141. package/common/middleware/web_logger/index.js +0 -156
  142. package/common/middleware/web_logger/middleware.json +0 -14
  143. package/common/middleware/web_main/index.js +0 -26
  144. package/common/middleware/web_main/middleware.json +0 -9
  145. package/common/middleware/web_static/index.js +0 -73
  146. package/common/middleware/web_static/middleware.json +0 -54
  147. package/common/middleware/web_waf/index.js +0 -395
  148. package/common/middleware/web_waf/middleware.json +0 -13
  149. package/core/app/config.tpl.json +0 -67
  150. package/core/app/index.js +0 -711
  151. package/core/app/script.tpl.js +0 -52
  152. package/core/channel/index.js +0 -899
  153. package/core/channel/matcher.js +0 -585
  154. package/core/com/config.tpl.json +0 -16
  155. package/core/com/index.js +0 -77
  156. package/core/com/script.tpl.js +0 -5
  157. package/core/component/component.js +0 -42
  158. package/core/component/config.tpl.json +0 -63
  159. package/core/component/index.js +0 -273
  160. package/core/component/script.tpl.js +0 -19
  161. package/core/controller/config.tpl.json +0 -14
  162. package/core/controller/index.js +0 -371
  163. package/core/controller/script.tpl.js +0 -27
  164. package/core/factory/config.tpl.json +0 -14
  165. package/core/factory/entity.js +0 -275
  166. package/core/factory/index.js +0 -241
  167. package/core/factory/script.tpl.js +0 -16
  168. package/core/game/bat/index.js +0 -137
  169. package/core/game/bat/world.js +0 -622
  170. package/core/game/config.tpl.json +0 -16
  171. package/core/game/entity_admin.js +0 -230
  172. package/core/game/index.js +0 -186
  173. package/core/handler/config.tpl.json +0 -22
  174. package/core/handler/index.js +0 -181
  175. package/core/handler/script.tpl.js +0 -23
  176. package/core/logic/config.tpl.json +0 -14
  177. package/core/logic/index.js +0 -59
  178. package/core/logic/script.tpl.js +0 -19
  179. package/core/middleware/config.tpl.json +0 -16
  180. package/core/middleware/index.js +0 -117
  181. package/core/middleware/script.tpl.js +0 -37
  182. package/core/mod/config.tpl.json +0 -22
  183. package/core/mod/index.js +0 -136
  184. package/core/mod/script.tpl.js +0 -34
  185. package/core/model/config.tpl.json +0 -219
  186. package/core/model/index.js +0 -272
  187. package/core/model/model.js +0 -27
  188. package/core/model/script.tpl.js +0 -20
  189. package/core/notifier/config.tpl.json +0 -14
  190. package/core/notifier/index.js +0 -77
  191. package/core/notifier/script.tpl.js +0 -20
  192. package/core/plugin/config.tpl.json +0 -36
  193. package/core/plugin/index.js +0 -267
  194. package/core/plugin/script.tpl.js +0 -51
  195. package/core/pusher/config.tpl.json +0 -14
  196. package/core/pusher/index.js +0 -158
  197. package/core/pusher/script.tpl.js +0 -20
  198. package/core/room/bat/index.js +0 -170
  199. package/core/room/bat/room.js +0 -524
  200. package/core/room/config.tpl.json +0 -20
  201. package/core/room/index.js +0 -249
  202. package/core/room/room.js +0 -61
  203. package/core/scene/config.tpl.json +0 -14
  204. package/core/scene/index.js +0 -467
  205. package/core/scene/loop.js +0 -1306
  206. package/core/scene/map.js +0 -28
  207. package/core/scene/script.tpl.js +0 -22
  208. package/core/sender/config.tpl.json +0 -14
  209. package/core/sender/index.js +0 -79
  210. package/core/sender/script.tpl.js +0 -20
  211. package/core/service/config.tpl.json +0 -14
  212. package/core/service/index.js +0 -100
  213. package/core/service/script.tpl.js +0 -25
  214. package/core/store/config.tpl.json +0 -26
  215. package/core/store/index.js +0 -1794
  216. package/core/store/script.tpl.js +0 -22
  217. package/core/system/config.tpl.json +0 -18
  218. package/core/system/index.js +0 -312
  219. package/core/system/script.tpl.js +0 -77
  220. package/core/view/config.tpl.json +0 -14
  221. package/core/view/index.js +0 -91
  222. package/core/view/script.tpl.js +0 -20
  223. package/core/zone/bat/index.js +0 -744
  224. package/core/zone/config.tpl.json +0 -54
  225. package/core/zone/index.js +0 -655
  226. package/core/zone/script.tpl.js +0 -10
  227. package/core/zone/zone_bat.js +0 -136
  228. package/core//345/237/272/347/261/273/346/250/241/345/235/227/346/270/205/345/215/225.md +0 -24
  229. package/os.js +0 -53
  230. package/server.js +0 -602
  231. package/ulits/id_gen.js +0 -134
  232. package/ulits/word.js +0 -206
package/README_EN.md DELETED
@@ -1,505 +0,0 @@
1
- # MM_OS Server Architecture
2
-
3
- [![npm version](https://badge.fury.io/js/mm_os.svg)](https://badge.fury.io/js/mm_os)
4
- [![npm downloads](https://img.shields.io/npm/dm/mm_os.svg)](https://www.npmjs.com/package/mm_os)
5
- [![License](https://img.shields.io/npm/l/mm_os.svg)](https://gitee.com/qiuwenwu91/mm_os/blob/master/LICENSE)
6
-
7
- ## Project Introduction
8
-
9
- MM_OS is a lightweight server architecture that provides a complete server development framework, including support for multiple communication protocols such as Web, WebSocket, MQTT, Socket, as well as rich components and modules.
10
-
11
- **Use Cases:**
12
- - **Website Development**: Quickly build enterprise websites, e-commerce platforms, content management systems
13
- - **Mini Programs**: Backend services for WeChat Mini Programs, Alipay Mini Programs, etc.
14
- - **AI Applications**: AI API services, intelligent assistants, machine learning inference services
15
- - **IoT/AIoT**: IoT device management, sensor data collection, smart hardware control
16
- - **Game Servers**: Small-to-medium game servers, real-time battle games, game backend management
17
-
18
- Supports **AI, GAME, IOT, AIOT, Games, Internet of Things, Mini Programs, Website Development** and other application scenarios.
19
-
20
- ## Core Features
21
-
22
- - **Multi-protocol support**: Web, WebSocket, MQTT, Socket
23
- - **Modular design**: Application, Module, Middleware, Notifier, Sender, Pusher
24
- - **Infrastructure**: Database, Cache, Log, File Management
25
- - **Event-driven**: Asynchronous processing based on event bus
26
- - **Plugin system**: Support for function extension
27
-
28
- ## Design Philosophy: Configuration and Logic Separation
29
-
30
- The core design principle of MM_OS framework is **separation of configuration and logic**. Both `core` modules and `com` components follow a unified structure:
31
-
32
- ### Module Composition
33
-
34
- Each module consists of the following files:
35
-
36
- | File Type | File Name | Purpose |
37
- |-----------|-----------|---------|
38
- | **Configuration** | `config.tpl.json` / `com.json` | Declarative definition of module configuration and metadata |
39
- | **Logic** | `index.js` / `script.tpl.js` | Implementation of business logic and functionality |
40
- | **Driver** | `drive.js` (optional) | Protocol driver and adapter logic |
41
-
42
- ### Design Advantages
43
-
44
- **1. Declarative Configuration**
45
- - JSON files define module metadata and configuration declaratively
46
- - Module registration and parameter configuration can be completed without writing code
47
- - Easy to manage and configure through visual tools
48
-
49
- **2. Logic and Configuration Decoupling**
50
- - Configuration changes do not require code modification, reducing maintenance costs
51
- - The same business logic can be reused with different configurations
52
- - Configuration files can be independently version-managed and deployed
53
-
54
- **3. Automation Capabilities**
55
- - Framework can automatically scan JSON configurations for module registration
56
- - Automatically generate documentation and configuration forms
57
- - Automatically perform parameter validation, reducing repetitive code
58
-
59
- **4. Hot Update Support**
60
- - Configuration files can be hot-updated without restarting the service
61
- - Supports dynamic addition/modification of module configurations
62
-
63
- **5. Team Collaboration Optimization**
64
- - Configuration personnel and developers can work in parallel
65
- - Non-developers can also participate in module configuration
66
- - Unified configuration format reduces communication costs
67
-
68
- ### Module Types
69
-
70
- **core modules**: Framework base modules including app, controller, model, logic, plugin, service, view, middleware, etc.
71
-
72
- **com components**: Reusable common components including sql, cache, api, event, task, static, template, MQTT, Socket, etc.
73
-
74
- ## Quick Start
75
-
76
- ### Installation
77
-
78
- ```bash
79
- npm install mm_os
80
- ```
81
-
82
- ### Basic Usage
83
-
84
- ```javascript
85
- const { MM_os } = require('mm_os');
86
-
87
- // Set runtime path
88
- $.run_path = __dirname;
89
-
90
- // Create server instance
91
- const server = new MM_os({
92
- web: {
93
- host: '0.0.0.0',
94
- port: 8000,
95
- socket: true
96
- },
97
- mysql: {
98
- host: '127.0.0.1',
99
- port: 3306,
100
- user: 'root',
101
- password: '123456',
102
- database: 'test'
103
- },
104
- cache: {
105
- way: 'memory'
106
- }
107
- });
108
-
109
- // Start server
110
- async function startServer() {
111
- await server.init();
112
- await server.start();
113
- console.log('服务启动成功');
114
- }
115
-
116
- startServer();
117
- ```
118
-
119
- ## Project Directory Structure
120
-
121
- Projects developed with MM_OS framework follow a standardized directory structure:
122
-
123
- ```
124
- ├── app/ # Application directory containing multiple apps
125
- │ ├── app_name/ # Application name
126
- │ │ ├── event_api/ # Event API directory
127
- │ │ │ ├── web/ # Web route handling
128
- │ │ │ │ ├── event.json # Event configuration
129
- │ │ │ │ └── main.js # Entry file
130
- │ │ │ ├── api/ # API route
131
- │ │ │ ├── client/ # Client API route
132
- │ │ │ └── manage/ # Management backend route
133
- │ │ ├── plugin/ # Plugin directory
134
- │ │ │ ├── main/ # Main plugins (business logic)
135
- │ │ │ │ └── api_{app}_{channel}/{api_name}/
136
- │ │ │ │ ├── api.json # API configuration
137
- │ │ │ │ ├── param.json # Parameter validation config
138
- │ │ │ │ └── index.js # API implementation
139
- │ │ │ └── server/ # Server plugins (data management)
140
- │ │ ├── pendant/ # Pendant component directory
141
- │ │ ├── static/ # Static resources
142
- │ │ ├── app.json # Application configuration
143
- │ │ └── index.js # Application entry
144
- ├── cache/ # Cache configuration directory
145
- ├── com/ # Common components directory
146
- ├── config/ # Global configuration directory
147
- │ ├── local.json # Local configuration
148
- │ ├── development.json # Development configuration
149
- │ └── production.json # Production configuration
150
- ├── db/ # Database files directory (SQLite, etc.)
151
- ├── static/ # Global static resources
152
- ├── index.js # Project entry
153
- └── config.json # Main configuration file
154
- ```
155
-
156
- ## Application Development
157
-
158
- ### Create Application
159
-
160
- Each application contains independent business logic. Application configuration file `app.json`:
161
-
162
- ```json
163
- {
164
- "name": "user",
165
- "version": "1.0",
166
- "title": "User",
167
- "description": "User authentication service",
168
- "author": "developer",
169
- "scope": "server",
170
- "main": "./index.js",
171
- "func_name": "main",
172
- "sort": 10,
173
- "state": 1,
174
- "sql": {
175
- "way": "mysql",
176
- "mysql": {
177
- "host": "127.0.0.1",
178
- "port": 3306,
179
- "user": "root",
180
- "password": "password",
181
- "database": "example"
182
- }
183
- },
184
- "cache": {
185
- "way": "redis"
186
- }
187
- }
188
- ```
189
-
190
- ### Event Route Configuration (event.json)
191
-
192
- Define application routing rules:
193
-
194
- ```json
195
- {
196
- "/api/user/list": {
197
- "method": "GET",
198
- "title": "Get User List",
199
- "auth": false
200
- },
201
- "/api/user/create": {
202
- "method": "POST",
203
- "title": "Create User",
204
- "auth": true
205
- },
206
- "/user/*": {
207
- "method": "ALL",
208
- "title": "User Page Routes",
209
- "auth": false
210
- }
211
- }
212
- ```
213
-
214
- ### Create API Interface
215
-
216
- API is the core component of MM_OS framework. Each API consists of three files:
217
-
218
- #### 1. api.json - API Configuration
219
-
220
- ```json
221
- {
222
- "name": "user_sign_in",
223
- "title": "User Login",
224
- "description": "User login interface, supports username/password, phone/code, and social login",
225
- "path": "/api/user/sign_in",
226
- "type": "api",
227
- "method": "ALL",
228
- "cache": 0,
229
- "param_path": "./param.json",
230
- "check_param": true,
231
- "sort": 1
232
- }
233
- ```
234
-
235
- **api.json Field Description:**
236
-
237
- | Field | Type | Required | Description |
238
- |-------|------|----------|-------------|
239
- | name | string | Yes | Unique API identifier |
240
- | title | string | Yes | Display name |
241
- | description | string | No | Description |
242
- | path | string | Yes | Access path |
243
- | type | string | Yes | Type, fixed as "api" |
244
- | method | string | Yes | HTTP method: GET, POST, ALL |
245
- | cache | number | No | Cache time in seconds, 0 means no cache |
246
- | param_path | string | No | Parameter validation config path |
247
- | check_param | boolean | No | Whether to validate parameters |
248
- | sort | number | No | Sort order |
249
-
250
- #### 2. param.json - Parameter Validation Configuration
251
-
252
- ```json
253
- {
254
- "title": "User Login Validation Model",
255
- "name": "user_sign_in",
256
- "filter": true,
257
- "get": {
258
- "query": ["account", "password", "code"],
259
- "query_required": ["account"]
260
- },
261
- "post": {
262
- "body": ["account", "password", "code", "phone"],
263
- "body_required": ["account"]
264
- },
265
- "list": [
266
- {
267
- "name": "account",
268
- "title": "Account",
269
- "type": "string",
270
- "string": {
271
- "min": 5,
272
- "max": 16,
273
- "format": "username"
274
- }
275
- },
276
- {
277
- "name": "password",
278
- "title": "Password",
279
- "type": "string",
280
- "string": {
281
- "min": 32,
282
- "max": 32,
283
- "format": "password"
284
- }
285
- },
286
- {
287
- "name": "phone",
288
- "title": "Phone Number",
289
- "type": "string",
290
- "string": {
291
- "format": "phone",
292
- "range": [11, 11]
293
- }
294
- },
295
- {
296
- "name": "code",
297
- "title": "Verification Code",
298
- "type": "string"
299
- }
300
- ]
301
- }
302
- ```
303
-
304
- **param.json Field Description:**
305
-
306
- | Field | Type | Description |
307
- |-------|------|-------------|
308
- | title | string | Validation model name |
309
- | name | string | Model identifier |
310
- | filter | boolean | Whether to enable filtering |
311
- | get.query | array | Acceptable query parameters for GET |
312
- | get.query_required | array | Required parameters for GET |
313
- | post.body | array | Acceptable body parameters for POST |
314
- | post.body_required | array | Required parameters for POST |
315
- | list | array | Parameter validation rules |
316
-
317
- **Supported Parameter Types:**
318
- - `string`: String type, supports format (phone, email, username, password), min, max, range
319
- - `number`: Number type, supports min, max, range
320
- - `boolean`: Boolean type
321
- - `array`: Array type
322
- - `object`: Object type
323
-
324
- #### 3. index.js - API Implementation
325
-
326
- ```javascript
327
- /**
328
- * User Login API
329
- * @param {Object} ctx HTTP context
330
- * @param {Object} db Data manager
331
- * @return {Object} Execution result
332
- */
333
- async function main(ctx, db) {
334
- // Get request parameters
335
- var params = ctx.method === "POST" ? ctx.request.body : ctx.request.query;
336
-
337
- // Validate parameters
338
- var account = params['account'];
339
- var password = params['password'];
340
-
341
- if (!account) {
342
- return { code: 30001, message: 'Account cannot be empty' };
343
- }
344
- if (!password) {
345
- return { code: 30002, message: 'Password cannot be empty' };
346
- }
347
-
348
- // Query user
349
- db.table = "user_account";
350
- db.key = "user_id";
351
- var users = await db.get({ username: account });
352
-
353
- if (users.length === 0) {
354
- return { code: 60001, message: 'User does not exist' };
355
- }
356
-
357
- var user = users[0];
358
-
359
- // Validate password
360
- var pass = (password + user.salt).md5();
361
- if (pass !== user.password) {
362
- return { code: 30003, message: 'Incorrect password' };
363
- }
364
-
365
- // Set login state
366
- ctx.session.user = user;
367
-
368
- // Return result
369
- return {
370
- code: 200,
371
- message: 'Login successful',
372
- data: {
373
- user_id: user.user_id,
374
- username: user.username,
375
- nickname: user.nickname
376
- }
377
- };
378
- }
379
-
380
- exports.main = main;
381
- ```
382
-
383
- ### Event Handler Entry (main.js)
384
-
385
- ```javascript
386
- // Use API manager
387
- var api = $.admin.api('user_web', 'Website - User Management');
388
- api.call('update');
389
-
390
- /**
391
- * @description Main handler function
392
- * @param {Object} ctx HTTP context
393
- * @param {Object} db Data manager
394
- * @return {Object} Execution result
395
- */
396
- async function main(ctx, db) {
397
- // Set database connection
398
- $.push(db, $.admin.sql('sys').db(), true);
399
-
400
- // Use template engine
401
- db.tpl = new $.Tpl();
402
- var bag = db.tpl.viewBag;
403
- bag.path = ctx.path;
404
- bag.query = ctx.query;
405
-
406
- // Execute API routing
407
- return await api.run(ctx, db);
408
- }
409
-
410
- exports.main = main;
411
- ```
412
-
413
- ## Configuration
414
-
415
- MM_OS supports multiple configuration options:
416
-
417
- - **web**: Web server configuration
418
- - **mysql**: MySQL database configuration
419
- - **sqlite**: SQLite database configuration
420
- - **cache**: Cache configuration (`way` specifies type: `memory`, `redis`, `mongodb`)
421
- - **redis**: Redis cache configuration
422
- - **mongodb**: MongoDB configuration
423
- - **mqtt**: MQTT server configuration
424
- - **socket**: Socket server configuration
425
-
426
- ### Configuration File Example
427
-
428
- ```json
429
- {
430
- "name": "mm_os",
431
- "title": "Server System",
432
- "log": {
433
- "level": "debug",
434
- "file": true
435
- },
436
- "web": {
437
- "state": true,
438
- "host": "0.0.0.0",
439
- "port": 8000,
440
- "socket": false,
441
- "cos": {
442
- "status": true,
443
- "origin": "*"
444
- },
445
- "static": {
446
- "state": 1,
447
- "root": "./static"
448
- }
449
- },
450
- "mysql": {
451
- "host": "127.0.0.1",
452
- "port": 3306,
453
- "user": "root",
454
- "password": "password",
455
- "database": "example"
456
- },
457
- "cache": {
458
- "way": "redis"
459
- },
460
- "redis": {
461
- "host": "localhost",
462
- "port": 6379,
463
- "password": "",
464
- "database": 0
465
- }
466
- }
467
- ```
468
-
469
- ## Global Objects
470
-
471
- MM_OS provides rich global objects for development:
472
-
473
- ### `$` Object
474
-
475
- | Property | Description |
476
- |----------|-------------|
477
- | `$.sql` | Database operation object |
478
- | `$.cache` | Cache operation object |
479
- | `$.log` | Log object |
480
- | `$.admin` | Admin object |
481
- | `$.eventer` | Event bus |
482
- | `$.config` | Configuration manager |
483
- | `$.Tpl` | Template engine class |
484
- | `$.ret` | Response utility |
485
- | `$.run_path` | Current runtime path |
486
-
487
- ### `$.ret` Response Utility
488
-
489
- ```javascript
490
- // Success response
491
- return $.ret.body(data); // { code: 200, message: 'success', data: data }
492
-
493
- // Error response
494
- return $.ret.error(code, message); // { code: code, message: message }
495
- ```
496
-
497
- ## Development Guide
498
-
499
- 1. **Install dependencies**: `npm install`
500
- 2. **Development and debugging**: `npm run dev`
501
- 3. **Run tests**: `npm run test`
502
-
503
- ## License
504
-
505
- ISC