46 lines
2.3 KiB
Markdown
46 lines
2.3 KiB
Markdown
---
|
||
name: script_engine
|
||
description: 逻辑编程(脚本/规则引擎)模块——脚本表 CRUD + execute_script/validate_script 接口,通过 load_script_engine() 挂载。脚本类型 0=Python / 1=SQL。
|
||
---
|
||
|
||
# script_engine 模块
|
||
|
||
脚本/规则引擎:脚本表(`script_engine`)CRUD + 执行/校验接口。独立模块,无业务依赖。
|
||
|
||
## 数据模型
|
||
|
||
- `script_engine`:`id`(str32 PK)、`script_name`(str100 not null)、`script_type`(str32 default '0')、`content`(text not null)、`description`(str255)、`status`(str32 default '1')、`created_at`、`updated_at`
|
||
- 索引:`idx_script_name`、`idx_script_type`
|
||
- 编码:`script_type` → appcodes_kv parentid='script_type'(0=Python,1=SQL);`status` → appcodes_kv parentid='script_status'(0=停用,1=启用)
|
||
|
||
## 关键接口(ServerEnv 注册函数,.dspy 直接调用)
|
||
|
||
- `create_script / update_script / delete_script / get_script / list_scripts`
|
||
- `execute_script`(id 或 content+script_type,校验后执行)
|
||
- `validate_script_api`(仅校验,不落库不执行)
|
||
- 复数别名 `create_scripts/update_scripts/delete_scripts` 与单数同实现(CRUD 框架约定)
|
||
|
||
## 错误结构与分页
|
||
|
||
- 统一 `{code, message, field, detail}`;code=0 成功
|
||
- 分页 `{list, total}`(list_scripts 返回 data.list / data.total)
|
||
|
||
## REST 接口(wwwroot/api/*.dspy)
|
||
|
||
- script_create.dspy / script_update.dspy / script_delete.dspy / script_get.dspy / script_list.dspy
|
||
- script_execute.dspy / execute_script.dspy / script_validate.dspy / validate_script.dspy
|
||
- get_search_script_type.dspy / get_search_status.dspy(下拉 [{value,text}])
|
||
|
||
## 陷阱
|
||
|
||
- 取库名用 `ServerEnv().get_module_dbname('script_engine')`,禁止硬编码 DBNAME
|
||
- 非法输入(空名/超长/非法类型/语法错误/受限语法/危险调用)100% 拦截,不落库不执行
|
||
- Python 执行受限命名空间:仅内置白名单函数,禁 import/类/λ/async/await/对象方法调用(engine.py ast 校验 + 白名单 builtins)
|
||
- SQL 仅允许只读单语句(SELECT/SHOW/DESCRIBE/EXPLAIN),禁写语句/多语句/危险关键字
|
||
- .dspy 无 import/print/uuid/f-string,显式 return;helper 在 init.py
|
||
- init/data.json 为 Format B appcodes(parentid + items),幂等落库
|
||
|
||
## 依赖
|
||
|
||
- 无业务依赖;依赖基础包 sqlor / ahserver / appPublic
|