script_engine/README.md

31 lines
1.6 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# script_engine 逻辑编程(脚本/规则引擎)模块
脚本/规则引擎:`script_engine` 脚本表 CRUD + 执行/校验接口。独立模块,无业务依赖。
## 功能
- 脚本表 CRUD`create_script / update_script / delete_script / get_script / list_scripts`(含复数别名)
- 执行接口:`execute_script`(按 id 或 content+script_type校验后执行
- 校验接口:`validate_script_api`(仅校验,不落库不执行)
- 脚本类型:`0`=Python`1`=SQL
- Python 受限执行AST 校验(禁 import/类/λ/async/await/对象方法调用)+ builtins 白名单
- SQL 仅允许只读单语句SELECT/SHOW/DESCRIBE/EXPLAIN禁写语句/多语句/危险关键字
## 数据表
- `script_engine`id(str32 PK)、script_name(str100)、script_type(str32 default '0')、content(text)、description(str255)、status(str32 default '1')、created_at、updated_at
- 索引idx_script_name、idx_script_type
- 编码script_type→appcodes_kv parentid='script_type'0=Python1=SQLstatus→parentid='script_status'0=停用1=启用)
## 集成
```python
from script_engine.init import load_script_engine
load_script_engine() # 注册全部函数到 ServerEnv
```
- 取库名:`ServerEnv().get_module_dbname('script_engine')`.py/ `get_module_dbname('script_engine')`.dspy 全局)
- REST`wwwroot/api/script_create.dspy` 等 11 个端点
- RBAC`scripts/load_path.py` 显式注册(无通配符)
## 构建
```bash
./build.sh # 1) 装 xls2ddl 2) models→mysql.ddl.sql 3) json→CRUD UI 4) wwwroot 软链
```