aury-boot 0.0.2__py3-none-any.whl → 0.0.4__py3-none-any.whl
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.
- aury/boot/__init__.py +66 -0
- aury/boot/_version.py +2 -2
- aury/boot/application/__init__.py +120 -0
- aury/boot/application/app/__init__.py +39 -0
- aury/boot/application/app/base.py +511 -0
- aury/boot/application/app/components.py +434 -0
- aury/boot/application/app/middlewares.py +101 -0
- aury/boot/application/config/__init__.py +44 -0
- aury/boot/application/config/settings.py +663 -0
- aury/boot/application/constants/__init__.py +19 -0
- aury/boot/application/constants/components.py +50 -0
- aury/boot/application/constants/scheduler.py +28 -0
- aury/boot/application/constants/service.py +29 -0
- aury/boot/application/errors/__init__.py +55 -0
- aury/boot/application/errors/chain.py +80 -0
- aury/boot/application/errors/codes.py +67 -0
- aury/boot/application/errors/exceptions.py +238 -0
- aury/boot/application/errors/handlers.py +320 -0
- aury/boot/application/errors/response.py +120 -0
- aury/boot/application/interfaces/__init__.py +76 -0
- aury/boot/application/interfaces/egress.py +224 -0
- aury/boot/application/interfaces/ingress.py +98 -0
- aury/boot/application/middleware/__init__.py +22 -0
- aury/boot/application/middleware/logging.py +451 -0
- aury/boot/application/migrations/__init__.py +13 -0
- aury/boot/application/migrations/manager.py +685 -0
- aury/boot/application/migrations/setup.py +237 -0
- aury/boot/application/rpc/__init__.py +63 -0
- aury/boot/application/rpc/base.py +108 -0
- aury/boot/application/rpc/client.py +294 -0
- aury/boot/application/rpc/discovery.py +218 -0
- aury/boot/application/scheduler/__init__.py +13 -0
- aury/boot/application/scheduler/runner.py +123 -0
- aury/boot/application/server/__init__.py +296 -0
- aury/boot/commands/__init__.py +30 -0
- aury/boot/commands/add.py +76 -0
- aury/boot/commands/app.py +105 -0
- aury/boot/commands/config.py +177 -0
- aury/boot/commands/docker.py +367 -0
- aury/boot/commands/docs.py +284 -0
- aury/boot/commands/generate.py +1277 -0
- aury/boot/commands/init.py +892 -0
- aury/boot/commands/migrate/__init__.py +37 -0
- aury/boot/commands/migrate/app.py +54 -0
- aury/boot/commands/migrate/commands.py +303 -0
- aury/boot/commands/scheduler.py +124 -0
- aury/boot/commands/server/__init__.py +21 -0
- aury/boot/commands/server/app.py +541 -0
- aury/boot/commands/templates/generate/api.py.tpl +105 -0
- aury/boot/commands/templates/generate/model.py.tpl +17 -0
- aury/boot/commands/templates/generate/repository.py.tpl +19 -0
- aury/boot/commands/templates/generate/schema.py.tpl +29 -0
- aury/boot/commands/templates/generate/service.py.tpl +48 -0
- aury/boot/commands/templates/project/CLI.md.tpl +92 -0
- aury/boot/commands/templates/project/DEVELOPMENT.md.tpl +1397 -0
- aury/boot/commands/templates/project/README.md.tpl +111 -0
- aury/boot/commands/templates/project/admin_console_init.py.tpl +50 -0
- aury/boot/commands/templates/project/config.py.tpl +30 -0
- aury/boot/commands/templates/project/conftest.py.tpl +26 -0
- aury/boot/commands/templates/project/env.example.tpl +213 -0
- aury/boot/commands/templates/project/gitignore.tpl +128 -0
- aury/boot/commands/templates/project/main.py.tpl +41 -0
- aury/boot/commands/templates/project/modules/api.py.tpl +19 -0
- aury/boot/commands/templates/project/modules/exceptions.py.tpl +84 -0
- aury/boot/commands/templates/project/modules/schedules.py.tpl +18 -0
- aury/boot/commands/templates/project/modules/tasks.py.tpl +20 -0
- aury/boot/commands/worker.py +143 -0
- aury/boot/common/__init__.py +35 -0
- aury/boot/common/exceptions/__init__.py +114 -0
- aury/boot/common/i18n/__init__.py +16 -0
- aury/boot/common/i18n/translator.py +272 -0
- aury/boot/common/logging/__init__.py +716 -0
- aury/boot/contrib/__init__.py +10 -0
- aury/boot/contrib/admin_console/__init__.py +18 -0
- aury/boot/contrib/admin_console/auth.py +137 -0
- aury/boot/contrib/admin_console/discovery.py +69 -0
- aury/boot/contrib/admin_console/install.py +172 -0
- aury/boot/contrib/admin_console/utils.py +44 -0
- aury/boot/domain/__init__.py +79 -0
- aury/boot/domain/exceptions/__init__.py +132 -0
- aury/boot/domain/models/__init__.py +51 -0
- aury/boot/domain/models/base.py +69 -0
- aury/boot/domain/models/mixins.py +135 -0
- aury/boot/domain/models/models.py +96 -0
- aury/boot/domain/pagination/__init__.py +279 -0
- aury/boot/domain/repository/__init__.py +23 -0
- aury/boot/domain/repository/impl.py +423 -0
- aury/boot/domain/repository/interceptors.py +47 -0
- aury/boot/domain/repository/interface.py +106 -0
- aury/boot/domain/repository/query_builder.py +348 -0
- aury/boot/domain/service/__init__.py +11 -0
- aury/boot/domain/service/base.py +73 -0
- aury/boot/domain/transaction/__init__.py +404 -0
- aury/boot/infrastructure/__init__.py +104 -0
- aury/boot/infrastructure/cache/__init__.py +31 -0
- aury/boot/infrastructure/cache/backends.py +348 -0
- aury/boot/infrastructure/cache/base.py +68 -0
- aury/boot/infrastructure/cache/exceptions.py +37 -0
- aury/boot/infrastructure/cache/factory.py +94 -0
- aury/boot/infrastructure/cache/manager.py +274 -0
- aury/boot/infrastructure/database/__init__.py +39 -0
- aury/boot/infrastructure/database/config.py +71 -0
- aury/boot/infrastructure/database/exceptions.py +44 -0
- aury/boot/infrastructure/database/manager.py +317 -0
- aury/boot/infrastructure/database/query_tools/__init__.py +164 -0
- aury/boot/infrastructure/database/strategies/__init__.py +198 -0
- aury/boot/infrastructure/di/__init__.py +15 -0
- aury/boot/infrastructure/di/container.py +393 -0
- aury/boot/infrastructure/events/__init__.py +33 -0
- aury/boot/infrastructure/events/bus.py +362 -0
- aury/boot/infrastructure/events/config.py +52 -0
- aury/boot/infrastructure/events/consumer.py +134 -0
- aury/boot/infrastructure/events/middleware.py +51 -0
- aury/boot/infrastructure/events/models.py +63 -0
- aury/boot/infrastructure/monitoring/__init__.py +529 -0
- aury/boot/infrastructure/scheduler/__init__.py +19 -0
- aury/boot/infrastructure/scheduler/exceptions.py +37 -0
- aury/boot/infrastructure/scheduler/manager.py +478 -0
- aury/boot/infrastructure/storage/__init__.py +38 -0
- aury/boot/infrastructure/storage/base.py +164 -0
- aury/boot/infrastructure/storage/exceptions.py +37 -0
- aury/boot/infrastructure/storage/factory.py +88 -0
- aury/boot/infrastructure/tasks/__init__.py +24 -0
- aury/boot/infrastructure/tasks/config.py +45 -0
- aury/boot/infrastructure/tasks/constants.py +37 -0
- aury/boot/infrastructure/tasks/exceptions.py +37 -0
- aury/boot/infrastructure/tasks/manager.py +490 -0
- aury/boot/testing/__init__.py +24 -0
- aury/boot/testing/base.py +122 -0
- aury/boot/testing/client.py +163 -0
- aury/boot/testing/factory.py +154 -0
- aury/boot/toolkit/__init__.py +21 -0
- aury/boot/toolkit/http/__init__.py +367 -0
- {aury_boot-0.0.2.dist-info → aury_boot-0.0.4.dist-info}/METADATA +3 -2
- aury_boot-0.0.4.dist-info/RECORD +137 -0
- aury_boot-0.0.2.dist-info/RECORD +0 -5
- {aury_boot-0.0.2.dist-info → aury_boot-0.0.4.dist-info}/WHEEL +0 -0
- {aury_boot-0.0.2.dist-info → aury_boot-0.0.4.dist-info}/entry_points.txt +0 -0
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"""{class_name} 业务逻辑层。"""
|
|
2
|
+
|
|
3
|
+
{uuid_import}from sqlalchemy.ext.asyncio import AsyncSession
|
|
4
|
+
|
|
5
|
+
from aury.boot.application.errors import AlreadyExistsError, NotFoundError
|
|
6
|
+
from aury.boot.domain.service.base import BaseService
|
|
7
|
+
from aury.boot.domain.transaction import transactional
|
|
8
|
+
|
|
9
|
+
from {import_prefix}models.{file_name} import {class_name}
|
|
10
|
+
from {import_prefix}repositories.{file_name}_repository import {class_name}Repository
|
|
11
|
+
from {import_prefix}schemas.{file_name} import {class_name}Create, {class_name}Update
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
class {class_name}Service(BaseService):
|
|
15
|
+
"""{class_name} 服务。"""
|
|
16
|
+
|
|
17
|
+
def __init__(self, session: AsyncSession) -> None:
|
|
18
|
+
super().__init__(session)
|
|
19
|
+
self.repo = {class_name}Repository(session, {class_name})
|
|
20
|
+
|
|
21
|
+
async def get(self, id: {id_py_type}) -> {class_name}:
|
|
22
|
+
"""获取 {class_name}。"""
|
|
23
|
+
entity = await self.repo.get(id)
|
|
24
|
+
if not entity:
|
|
25
|
+
raise NotFoundError(f"{class_name} 不存在", resource=id)
|
|
26
|
+
return entity
|
|
27
|
+
|
|
28
|
+
async def list(self, skip: int = 0, limit: int = 100) -> list[{class_name}]:
|
|
29
|
+
"""获取 {class_name} 列表。"""
|
|
30
|
+
return await self.repo.list(skip=skip, limit=limit)
|
|
31
|
+
|
|
32
|
+
@transactional
|
|
33
|
+
async def create(self, data: {class_name}Create) -> {class_name}:
|
|
34
|
+
"""创建 {class_name}。"""
|
|
35
|
+
{unique_check_str}
|
|
36
|
+
return await self.repo.create(data.model_dump())
|
|
37
|
+
|
|
38
|
+
@transactional
|
|
39
|
+
async def update(self, id: {id_py_type}, data: {class_name}Update) -> {class_name}:
|
|
40
|
+
"""更新 {class_name}。"""
|
|
41
|
+
entity = await self.get(id)
|
|
42
|
+
return await self.repo.update(entity, data.model_dump(exclude_unset=True))
|
|
43
|
+
|
|
44
|
+
@transactional
|
|
45
|
+
async def delete(self, id: {id_py_type}) -> None:
|
|
46
|
+
"""删除 {class_name}。"""
|
|
47
|
+
entity = await self.get(id)
|
|
48
|
+
await self.repo.delete(entity)
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
# {project_name} CLI 命令参考
|
|
2
|
+
|
|
3
|
+
本文档基于 [Aury Boot](https://github.com/AuriMyth/aury-boot) 框架。
|
|
4
|
+
|
|
5
|
+
## 服务器命令
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
# 开发模式(自动重载)
|
|
9
|
+
aury server dev
|
|
10
|
+
|
|
11
|
+
# 生产模式
|
|
12
|
+
aury server prod
|
|
13
|
+
|
|
14
|
+
# 自定义运行
|
|
15
|
+
aury server run --host 0.0.0.0 --port 8000 --workers 4
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
## 代码生成
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
# 生成完整 CRUD
|
|
22
|
+
aury generate crud user
|
|
23
|
+
|
|
24
|
+
# 交互式生成(推荐):逐步选择字段、类型、约束等
|
|
25
|
+
aury generate crud user -i
|
|
26
|
+
aury generate model user -i
|
|
27
|
+
|
|
28
|
+
# 单独生成
|
|
29
|
+
aury generate model user # SQLAlchemy 模型
|
|
30
|
+
aury generate repo user # Repository
|
|
31
|
+
aury generate service user # Service
|
|
32
|
+
aury generate api user # API 路由
|
|
33
|
+
aury generate schema user # Pydantic Schema
|
|
34
|
+
|
|
35
|
+
# 指定字段(非交互式)
|
|
36
|
+
aury generate model user --fields "name:str,email:str,age:int"
|
|
37
|
+
|
|
38
|
+
# 指定模型基类
|
|
39
|
+
aury generate model user --base UUIDAuditableStateModel # UUID主键 + 软删除(推荐)
|
|
40
|
+
aury generate model user --base UUIDModel # UUID主键 + 时间戳
|
|
41
|
+
aury generate model user --base Model # int主键 + 时间戳
|
|
42
|
+
aury generate model user --base VersionedUUIDModel # UUID + 乐观锁 + 时间戳
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
## 数据库迁移
|
|
46
|
+
|
|
47
|
+
```bash
|
|
48
|
+
aury migrate make -m "add user table" # 创建迁移
|
|
49
|
+
aury migrate up # 执行迁移
|
|
50
|
+
aury migrate down # 回滚迁移
|
|
51
|
+
aury migrate status # 查看状态
|
|
52
|
+
aury migrate show # 查看历史
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
## 调度器和 Worker
|
|
56
|
+
|
|
57
|
+
```bash
|
|
58
|
+
aury scheduler # 独立运行调度器
|
|
59
|
+
aury worker # 运行 Dramatiq Worker
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
## 环境变量配置
|
|
63
|
+
|
|
64
|
+
所有配置项都可通过环境变量设置,优先级:命令行参数 > 环境变量 > .env 文件 > 默认值
|
|
65
|
+
|
|
66
|
+
| 变量 | 说明 | 默认值 |
|
|
67
|
+
|------|------|--------|
|
|
68
|
+
| `DATABASE_URL` | 数据库连接 URL | `sqlite+aiosqlite:///./dev.db` |
|
|
69
|
+
| `CACHE_TYPE` | 缓存类型 (memory/redis) | `memory` |
|
|
70
|
+
| `CACHE_URL` | Redis URL | - |
|
|
71
|
+
| `LOG_LEVEL` | 日志级别 | `INFO` |
|
|
72
|
+
| `LOG_DIR` | 日志目录 | `logs` |
|
|
73
|
+
| `SCHEDULER_ENABLED` | 启用内嵌调度器 | `true` |
|
|
74
|
+
| `TASK_BROKER_URL` | 任务队列 Broker URL | - |
|
|
75
|
+
|
|
76
|
+
## 管理后台(Admin Console)
|
|
77
|
+
|
|
78
|
+
框架提供可选的 SQLAdmin 管理后台扩展,默认路径:`/api/admin-console`。
|
|
79
|
+
|
|
80
|
+
常用环境变量:
|
|
81
|
+
|
|
82
|
+
| 变量 | 说明 | 默认值 |
|
|
83
|
+
|------|------|--------|
|
|
84
|
+
| `ADMIN_ENABLED` | 是否启用管理后台 | `false` |
|
|
85
|
+
| `ADMIN_PATH` | 管理后台路径 | `/api/admin-console` |
|
|
86
|
+
| `ADMIN_DATABASE_URL` | 管理后台同步数据库 URL(可覆盖自动推导) | - |
|
|
87
|
+
| `ADMIN_AUTH_MODE` | 认证模式(basic/bearer/none/custom/jwt) | `basic` |
|
|
88
|
+
| `ADMIN_AUTH_SECRET_KEY` | session 签名密钥(生产必配) | - |
|
|
89
|
+
| `ADMIN_AUTH_BASIC_USERNAME` | basic 用户名 | - |
|
|
90
|
+
| `ADMIN_AUTH_BASIC_PASSWORD` | basic 密码 | - |
|
|
91
|
+
| `ADMIN_AUTH_BEARER_TOKENS` | bearer token 白名单 | `[]` |
|
|
92
|
+
| `ADMIN_AUTH_BACKEND` | 自定义认证后端导入路径(module:attr) | - |
|