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.
Files changed (138) hide show
  1. aury/boot/__init__.py +66 -0
  2. aury/boot/_version.py +2 -2
  3. aury/boot/application/__init__.py +120 -0
  4. aury/boot/application/app/__init__.py +39 -0
  5. aury/boot/application/app/base.py +511 -0
  6. aury/boot/application/app/components.py +434 -0
  7. aury/boot/application/app/middlewares.py +101 -0
  8. aury/boot/application/config/__init__.py +44 -0
  9. aury/boot/application/config/settings.py +663 -0
  10. aury/boot/application/constants/__init__.py +19 -0
  11. aury/boot/application/constants/components.py +50 -0
  12. aury/boot/application/constants/scheduler.py +28 -0
  13. aury/boot/application/constants/service.py +29 -0
  14. aury/boot/application/errors/__init__.py +55 -0
  15. aury/boot/application/errors/chain.py +80 -0
  16. aury/boot/application/errors/codes.py +67 -0
  17. aury/boot/application/errors/exceptions.py +238 -0
  18. aury/boot/application/errors/handlers.py +320 -0
  19. aury/boot/application/errors/response.py +120 -0
  20. aury/boot/application/interfaces/__init__.py +76 -0
  21. aury/boot/application/interfaces/egress.py +224 -0
  22. aury/boot/application/interfaces/ingress.py +98 -0
  23. aury/boot/application/middleware/__init__.py +22 -0
  24. aury/boot/application/middleware/logging.py +451 -0
  25. aury/boot/application/migrations/__init__.py +13 -0
  26. aury/boot/application/migrations/manager.py +685 -0
  27. aury/boot/application/migrations/setup.py +237 -0
  28. aury/boot/application/rpc/__init__.py +63 -0
  29. aury/boot/application/rpc/base.py +108 -0
  30. aury/boot/application/rpc/client.py +294 -0
  31. aury/boot/application/rpc/discovery.py +218 -0
  32. aury/boot/application/scheduler/__init__.py +13 -0
  33. aury/boot/application/scheduler/runner.py +123 -0
  34. aury/boot/application/server/__init__.py +296 -0
  35. aury/boot/commands/__init__.py +30 -0
  36. aury/boot/commands/add.py +76 -0
  37. aury/boot/commands/app.py +105 -0
  38. aury/boot/commands/config.py +177 -0
  39. aury/boot/commands/docker.py +367 -0
  40. aury/boot/commands/docs.py +284 -0
  41. aury/boot/commands/generate.py +1277 -0
  42. aury/boot/commands/init.py +892 -0
  43. aury/boot/commands/migrate/__init__.py +37 -0
  44. aury/boot/commands/migrate/app.py +54 -0
  45. aury/boot/commands/migrate/commands.py +303 -0
  46. aury/boot/commands/scheduler.py +124 -0
  47. aury/boot/commands/server/__init__.py +21 -0
  48. aury/boot/commands/server/app.py +541 -0
  49. aury/boot/commands/templates/generate/api.py.tpl +105 -0
  50. aury/boot/commands/templates/generate/model.py.tpl +17 -0
  51. aury/boot/commands/templates/generate/repository.py.tpl +19 -0
  52. aury/boot/commands/templates/generate/schema.py.tpl +29 -0
  53. aury/boot/commands/templates/generate/service.py.tpl +48 -0
  54. aury/boot/commands/templates/project/CLI.md.tpl +92 -0
  55. aury/boot/commands/templates/project/DEVELOPMENT.md.tpl +1397 -0
  56. aury/boot/commands/templates/project/README.md.tpl +111 -0
  57. aury/boot/commands/templates/project/admin_console_init.py.tpl +50 -0
  58. aury/boot/commands/templates/project/config.py.tpl +30 -0
  59. aury/boot/commands/templates/project/conftest.py.tpl +26 -0
  60. aury/boot/commands/templates/project/env.example.tpl +213 -0
  61. aury/boot/commands/templates/project/gitignore.tpl +128 -0
  62. aury/boot/commands/templates/project/main.py.tpl +41 -0
  63. aury/boot/commands/templates/project/modules/api.py.tpl +19 -0
  64. aury/boot/commands/templates/project/modules/exceptions.py.tpl +84 -0
  65. aury/boot/commands/templates/project/modules/schedules.py.tpl +18 -0
  66. aury/boot/commands/templates/project/modules/tasks.py.tpl +20 -0
  67. aury/boot/commands/worker.py +143 -0
  68. aury/boot/common/__init__.py +35 -0
  69. aury/boot/common/exceptions/__init__.py +114 -0
  70. aury/boot/common/i18n/__init__.py +16 -0
  71. aury/boot/common/i18n/translator.py +272 -0
  72. aury/boot/common/logging/__init__.py +716 -0
  73. aury/boot/contrib/__init__.py +10 -0
  74. aury/boot/contrib/admin_console/__init__.py +18 -0
  75. aury/boot/contrib/admin_console/auth.py +137 -0
  76. aury/boot/contrib/admin_console/discovery.py +69 -0
  77. aury/boot/contrib/admin_console/install.py +172 -0
  78. aury/boot/contrib/admin_console/utils.py +44 -0
  79. aury/boot/domain/__init__.py +79 -0
  80. aury/boot/domain/exceptions/__init__.py +132 -0
  81. aury/boot/domain/models/__init__.py +51 -0
  82. aury/boot/domain/models/base.py +69 -0
  83. aury/boot/domain/models/mixins.py +135 -0
  84. aury/boot/domain/models/models.py +96 -0
  85. aury/boot/domain/pagination/__init__.py +279 -0
  86. aury/boot/domain/repository/__init__.py +23 -0
  87. aury/boot/domain/repository/impl.py +423 -0
  88. aury/boot/domain/repository/interceptors.py +47 -0
  89. aury/boot/domain/repository/interface.py +106 -0
  90. aury/boot/domain/repository/query_builder.py +348 -0
  91. aury/boot/domain/service/__init__.py +11 -0
  92. aury/boot/domain/service/base.py +73 -0
  93. aury/boot/domain/transaction/__init__.py +404 -0
  94. aury/boot/infrastructure/__init__.py +104 -0
  95. aury/boot/infrastructure/cache/__init__.py +31 -0
  96. aury/boot/infrastructure/cache/backends.py +348 -0
  97. aury/boot/infrastructure/cache/base.py +68 -0
  98. aury/boot/infrastructure/cache/exceptions.py +37 -0
  99. aury/boot/infrastructure/cache/factory.py +94 -0
  100. aury/boot/infrastructure/cache/manager.py +274 -0
  101. aury/boot/infrastructure/database/__init__.py +39 -0
  102. aury/boot/infrastructure/database/config.py +71 -0
  103. aury/boot/infrastructure/database/exceptions.py +44 -0
  104. aury/boot/infrastructure/database/manager.py +317 -0
  105. aury/boot/infrastructure/database/query_tools/__init__.py +164 -0
  106. aury/boot/infrastructure/database/strategies/__init__.py +198 -0
  107. aury/boot/infrastructure/di/__init__.py +15 -0
  108. aury/boot/infrastructure/di/container.py +393 -0
  109. aury/boot/infrastructure/events/__init__.py +33 -0
  110. aury/boot/infrastructure/events/bus.py +362 -0
  111. aury/boot/infrastructure/events/config.py +52 -0
  112. aury/boot/infrastructure/events/consumer.py +134 -0
  113. aury/boot/infrastructure/events/middleware.py +51 -0
  114. aury/boot/infrastructure/events/models.py +63 -0
  115. aury/boot/infrastructure/monitoring/__init__.py +529 -0
  116. aury/boot/infrastructure/scheduler/__init__.py +19 -0
  117. aury/boot/infrastructure/scheduler/exceptions.py +37 -0
  118. aury/boot/infrastructure/scheduler/manager.py +478 -0
  119. aury/boot/infrastructure/storage/__init__.py +38 -0
  120. aury/boot/infrastructure/storage/base.py +164 -0
  121. aury/boot/infrastructure/storage/exceptions.py +37 -0
  122. aury/boot/infrastructure/storage/factory.py +88 -0
  123. aury/boot/infrastructure/tasks/__init__.py +24 -0
  124. aury/boot/infrastructure/tasks/config.py +45 -0
  125. aury/boot/infrastructure/tasks/constants.py +37 -0
  126. aury/boot/infrastructure/tasks/exceptions.py +37 -0
  127. aury/boot/infrastructure/tasks/manager.py +490 -0
  128. aury/boot/testing/__init__.py +24 -0
  129. aury/boot/testing/base.py +122 -0
  130. aury/boot/testing/client.py +163 -0
  131. aury/boot/testing/factory.py +154 -0
  132. aury/boot/toolkit/__init__.py +21 -0
  133. aury/boot/toolkit/http/__init__.py +367 -0
  134. {aury_boot-0.0.2.dist-info → aury_boot-0.0.4.dist-info}/METADATA +3 -2
  135. aury_boot-0.0.4.dist-info/RECORD +137 -0
  136. aury_boot-0.0.2.dist-info/RECORD +0 -5
  137. {aury_boot-0.0.2.dist-info → aury_boot-0.0.4.dist-info}/WHEEL +0 -0
  138. {aury_boot-0.0.2.dist-info → aury_boot-0.0.4.dist-info}/entry_points.txt +0 -0
@@ -0,0 +1,37 @@
1
+ """存储相关异常定义。
2
+
3
+ Infrastructure 层异常,继承自 FoundationError。
4
+ """
5
+
6
+ from __future__ import annotations
7
+
8
+ from aury.boot.common.exceptions import FoundationError
9
+
10
+
11
+ class StorageError(FoundationError):
12
+ """存储相关错误基类。
13
+
14
+ 所有存储相关的异常都应该继承此类。
15
+ """
16
+
17
+ pass
18
+
19
+
20
+ class StorageNotFoundError(StorageError):
21
+ """存储文件不存在错误。"""
22
+
23
+ pass
24
+
25
+
26
+ class StorageBackendError(StorageError):
27
+ """存储后端错误。"""
28
+
29
+ pass
30
+
31
+
32
+ __all__ = [
33
+ "StorageBackendError",
34
+ "StorageError",
35
+ "StorageNotFoundError",
36
+ ]
37
+
@@ -0,0 +1,88 @@
1
+ """存储工厂 - 注册机制。
2
+
3
+ 通过注册机制支持多种存储后端。
4
+ """
5
+
6
+ from __future__ import annotations
7
+
8
+ from typing import ClassVar
9
+
10
+ from aury.boot.common.logging import logger
11
+
12
+ from aury.sdk.storage.storage import IStorage, LocalStorage
13
+
14
+
15
+ class StorageFactory:
16
+ """存储工厂 - 注册机制。
17
+
18
+ 类似缓存工厂的设计,通过注册机制支持多种后端。
19
+
20
+ 使用示例:
21
+ # 注册后端
22
+ StorageFactory.register("local", LocalStorage)
23
+ StorageFactory.register("s3", S3Storage)
24
+
25
+ # 创建存储实例
26
+ storage = await StorageFactory.create("local", base_path="./storage")
27
+ storage = await StorageFactory.create("s3", access_key_id="...", ...)
28
+ """
29
+
30
+ _backends: ClassVar[dict[str, type[IStorage]]] = {}
31
+
32
+ @classmethod
33
+ def register(cls, name: str, backend_class: type[IStorage]) -> None:
34
+ """注册存储后端。
35
+
36
+ Args:
37
+ name: 后端名称
38
+ backend_class: 后端类
39
+ """
40
+ cls._backends[name] = backend_class
41
+ logger.debug(f"注册存储后端: {name} -> {backend_class.__name__}")
42
+
43
+ @classmethod
44
+ async def create(cls, backend_name: str, **config) -> IStorage:
45
+ """创建存储实例。
46
+
47
+ Args:
48
+ backend_name: 后端名称
49
+ **config: 配置参数
50
+
51
+ Returns:
52
+ IStorage: 存储实例
53
+
54
+ Raises:
55
+ ValueError: 后端未注册
56
+ """
57
+ if backend_name not in cls._backends:
58
+ available = ", ".join(cls._backends.keys())
59
+ raise ValueError(
60
+ f"存储后端 '{backend_name}' 未注册。"
61
+ f"可用后端: {available}"
62
+ )
63
+
64
+ backend_class = cls._backends[backend_name]
65
+ instance = backend_class(**config)
66
+
67
+ # 如果后端需要初始化
68
+ if hasattr(instance, "initialize"):
69
+ await instance.initialize()
70
+
71
+ logger.info(f"创建存储实例: {backend_name}")
72
+ return instance
73
+
74
+ @classmethod
75
+ def get_registered(cls) -> list[str]:
76
+ """获取已注册的后端名称。"""
77
+ return list(cls._backends.keys())
78
+
79
+
80
+ # 注册默认后端(本地)
81
+ StorageFactory.register("local", LocalStorage)
82
+ # 说明:S3/COS/OSS 请直接使用 StorageManager + StorageConfig 或 SDK 中的 S3Storage
83
+
84
+
85
+ __all__ = [
86
+ "StorageFactory",
87
+ ]
88
+
@@ -0,0 +1,24 @@
1
+ """异步任务管理器模块。
2
+
3
+ 提供统一的任务队列接口,支持条件注册以避免 API 模式下重复注册。
4
+ """
5
+
6
+ from .constants import TaskQueueName, TaskRunMode
7
+ from .exceptions import (
8
+ TaskError,
9
+ TaskExecutionError,
10
+ TaskQueueError,
11
+ )
12
+ from .manager import TaskManager, TaskProxy, conditional_actor
13
+
14
+ __all__ = [
15
+ "TaskError",
16
+ "TaskExecutionError",
17
+ "TaskManager",
18
+ "TaskProxy",
19
+ "TaskQueueError",
20
+ "TaskQueueName",
21
+ "TaskRunMode",
22
+ "conditional_actor",
23
+ ]
24
+
@@ -0,0 +1,45 @@
1
+ """任务队列配置。
2
+
3
+ Infrastructure 层配置,不依赖 application 层。
4
+ """
5
+
6
+ from __future__ import annotations
7
+
8
+ from pydantic import Field
9
+ from pydantic_settings import BaseSettings, SettingsConfigDict
10
+
11
+
12
+ class TaskConfig(BaseSettings):
13
+ """任务队列基础设施配置。
14
+
15
+ Infrastructure 层直接使用的任务队列配置。
16
+
17
+ 环境变量前缀: TASK_
18
+ 示例: TASK_BROKER_URL, TASK_MAX_RETRIES
19
+ """
20
+
21
+ broker_url: str = Field(
22
+ default="redis://localhost:6379/0",
23
+ description="任务队列Broker URL"
24
+ )
25
+ max_retries: int = Field(
26
+ default=3,
27
+ description="最大重试次数"
28
+ )
29
+ time_limit: int = Field(
30
+ default=3600000,
31
+ description="任务执行时间限制(毫秒)"
32
+ )
33
+
34
+ model_config = SettingsConfigDict(
35
+ env_prefix="TASK_",
36
+ case_sensitive=False,
37
+ )
38
+
39
+
40
+ __all__ = [
41
+ "TaskConfig",
42
+ ]
43
+
44
+
45
+
@@ -0,0 +1,37 @@
1
+ """任务队列常量。
2
+
3
+ 任务队列模块内部的常量定义。
4
+ """
5
+
6
+ from __future__ import annotations
7
+
8
+ from enum import Enum
9
+
10
+
11
+ class TaskQueueName(str, Enum):
12
+ """任务队列名称常量。
13
+
14
+ 框架提供的通用队列名称。业务相关的队列名称应由用户自行定义。
15
+ """
16
+
17
+ DEFAULT = "default"
18
+ HIGH_PRIORITY = "high_priority"
19
+ LOW_PRIORITY = "low_priority"
20
+
21
+
22
+ class TaskRunMode(str, Enum):
23
+ """任务运行模式(任务队列模块内部使用)。
24
+
25
+ 用于控制任务装饰器的行为:
26
+ - WORKER: Worker 模式(执行者),正常注册为 actor,执行任务
27
+ - PRODUCER: Producer 模式(生产者),返回 TaskProxy,不注册但可以发送消息
28
+ """
29
+
30
+ WORKER = "worker"
31
+ PRODUCER = "producer"
32
+
33
+
34
+ __all__ = [
35
+ "TaskQueueName",
36
+ "TaskRunMode",
37
+ ]
@@ -0,0 +1,37 @@
1
+ """任务队列相关异常定义。
2
+
3
+ Infrastructure 层异常,继承自 FoundationError。
4
+ """
5
+
6
+ from __future__ import annotations
7
+
8
+ from aury.boot.common.exceptions import FoundationError
9
+
10
+
11
+ class TaskError(FoundationError):
12
+ """任务队列相关错误基类。
13
+
14
+ 所有任务队列相关的异常都应该继承此类。
15
+ """
16
+
17
+ pass
18
+
19
+
20
+ class TaskQueueError(TaskError):
21
+ """任务队列错误。"""
22
+
23
+ pass
24
+
25
+
26
+ class TaskExecutionError(TaskError):
27
+ """任务执行错误。"""
28
+
29
+ pass
30
+
31
+
32
+ __all__ = [
33
+ "TaskError",
34
+ "TaskExecutionError",
35
+ "TaskQueueError",
36
+ ]
37
+