zrb 1.0.0a16__py3-none-any.whl → 1.0.0a20__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 (196) hide show
  1. zrb/__init__.py +5 -0
  2. zrb/__main__.py +3 -0
  3. zrb/builtin/__init__.py +2 -2
  4. zrb/builtin/git.py +10 -2
  5. zrb/builtin/git_subtree.py +4 -0
  6. zrb/builtin/llm/tool/rag.py +2 -2
  7. zrb/builtin/project/add/fastapp/fastapp_input.py +16 -0
  8. zrb/builtin/project/add/fastapp/fastapp_task.py +78 -0
  9. zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/.flake8 +3 -0
  10. zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/_zrb/column/create_column_task.py +14 -0
  11. zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/_zrb/entity/add_entity_task.py +128 -0
  12. zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/_zrb/entity/add_entity_util.py +213 -0
  13. zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/_zrb/entity/template/any_client_method.py +27 -0
  14. zrb/builtin/project/add/{fastapp_template/_zrb/entity/module_template → fastapp/fastapp_template/my_app_name/_zrb/entity/template/app_template/module/my_module}/service/my_entity/my_entity_usecase.py +9 -10
  15. zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/_zrb/entity/template/app_template/module/my_module/service/my_entity/repository/factory.py +13 -0
  16. zrb/builtin/project/add/{fastapp_template/_zrb/entity/module_template → fastapp/fastapp_template/my_app_name/_zrb/entity/template/app_template/module/my_module}/service/my_entity/repository/my_entity_db_repository.py +14 -9
  17. zrb/builtin/project/add/{fastapp_template/_zrb/entity/module_template → fastapp/fastapp_template/my_app_name/_zrb/entity/template/app_template/module/my_module}/service/my_entity/repository/my_entity_repository.py +6 -7
  18. zrb/builtin/project/add/{fastapp_template/_zrb/entity/schema.template.py → fastapp/fastapp_template/my_app_name/_zrb/entity/template/app_template/schema/my_entity.py} +8 -0
  19. zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/_zrb/format_task.py +17 -0
  20. zrb/builtin/project/add/{fastapp_template → fastapp/fastapp_template/my_app_name}/_zrb/input.py +1 -4
  21. zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/_zrb/module/add_module_task.py +85 -0
  22. zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/_zrb/module/add_module_util.py +154 -0
  23. zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/_zrb/module/template/app_template/module/my_module/client/any_client.py +7 -0
  24. zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/_zrb/module/template/app_template/module/my_module/client/api_client.py +6 -0
  25. zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/_zrb/module/template/app_template/module/my_module/client/direct_client.py +6 -0
  26. zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/_zrb/module/template/app_template/module/my_module/client/factory.py +9 -0
  27. zrb/builtin/project/add/{fastapp_template/_zrb/module/module_template → fastapp/fastapp_template/my_app_name/_zrb/module/template/app_template/module/my_module}/migration/env.py +2 -4
  28. zrb/builtin/project/add/{fastapp_template/module/auth → fastapp/fastapp_template/my_app_name/_zrb/module/template/app_template/module/my_module}/migration/script.py.mako +1 -0
  29. zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/_zrb/module/template/app_template/module/my_module/route.py +33 -0
  30. zrb/builtin/project/add/{fastapp_template/_zrb/main.py → fastapp/fastapp_template/my_app_name/_zrb/task.py} +12 -14
  31. zrb/builtin/project/add/{fastapp_template/_zrb/helper.py → fastapp/fastapp_template/my_app_name/_zrb/util.py} +1 -1
  32. zrb/builtin/project/add/{fastapp_template → fastapp/fastapp_template/my_app_name}/_zrb/venv_task.py +1 -1
  33. zrb/builtin/project/add/{fastapp_template → fastapp/fastapp_template/my_app_name}/common/app.py +2 -2
  34. zrb/builtin/project/add/{fastapp_template → fastapp/fastapp_template/my_app_name}/common/base_db_repository.py +1 -1
  35. zrb/builtin/project/add/{fastapp_template → fastapp/fastapp_template/my_app_name}/common/base_usecase.py +19 -6
  36. zrb/builtin/project/add/{fastapp_template → fastapp/fastapp_template/my_app_name}/common/db_engine.py +1 -1
  37. zrb/builtin/project/add/{fastapp_template → fastapp/fastapp_template/my_app_name}/config.py +1 -0
  38. zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/main.py +7 -0
  39. zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/migrate.py +3 -0
  40. zrb/builtin/project/add/{fastapp_template → fastapp/fastapp_template/my_app_name}/module/auth/client/any_client.py +10 -4
  41. zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/module/auth/client/api_client.py +7 -0
  42. zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/module/auth/client/direct_client.py +6 -0
  43. zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/module/auth/client/factory.py +9 -0
  44. zrb/builtin/project/add/{fastapp_template → fastapp/fastapp_template/my_app_name}/module/auth/migration/env.py +2 -4
  45. zrb/builtin/project/add/{fastapp_template/module/gateway → fastapp/fastapp_template/my_app_name/module/auth}/migration/script.py.mako +1 -0
  46. zrb/builtin/project/add/{fastapp_template → fastapp/fastapp_template/my_app_name}/module/auth/migration_metadata.py +1 -1
  47. zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/module/auth/route.py +37 -0
  48. zrb/builtin/project/add/{fastapp_template → fastapp/fastapp_template/my_app_name}/module/auth/service/user/repository/user_db_repository.py +13 -7
  49. zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/module/auth/service/user/repository/user_repository.py +42 -0
  50. zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/module/auth/service/user/repository/user_repository_factory.py +13 -0
  51. zrb/builtin/project/add/{fastapp_template → fastapp/fastapp_template/my_app_name}/module/auth/service/user/user_usecase.py +13 -12
  52. zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/module/auth/service/user/user_usecase_factory.py +6 -0
  53. zrb/builtin/project/add/{fastapp_template → fastapp/fastapp_template/my_app_name}/module/gateway/migration/env.py +2 -4
  54. zrb/builtin/project/add/{fastapp_template/_zrb/module/module_template → fastapp/fastapp_template/my_app_name/module/gateway}/migration/script.py.mako +1 -0
  55. zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/module/gateway/route.py +37 -0
  56. zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/module/gateway/subroute/auth.py +44 -0
  57. zrb/builtin/project/add/{fastapp_template → fastapp/fastapp_template/my_app_name}/requirements.txt +1 -1
  58. zrb/builtin/project/add/{fastapp_template → fastapp/fastapp_template/my_app_name}/schema/permission.py +8 -0
  59. zrb/builtin/project/add/{fastapp_template → fastapp/fastapp_template/my_app_name}/schema/role.py +8 -0
  60. zrb/builtin/project/add/{fastapp_template → fastapp/fastapp_template/my_app_name}/schema/user.py +8 -0
  61. zrb/builtin/project/add/fastapp/fastapp_util.py +46 -0
  62. zrb/builtin/project/create/{create.py → project_task.py} +1 -1
  63. zrb/builtin/python.py +4 -1
  64. zrb/builtin/setup/asdf/asdf_helper.py +4 -8
  65. zrb/builtin/setup/tmux/tmux.py +7 -12
  66. zrb/builtin/todo.py +42 -26
  67. zrb/callback/callback.py +0 -1
  68. zrb/cmd/cmd_val.py +2 -2
  69. zrb/config.py +18 -0
  70. zrb/content_transformer/content_transformer.py +8 -7
  71. zrb/context/any_context.py +6 -6
  72. zrb/group/group.py +0 -1
  73. zrb/input/any_input.py +4 -0
  74. zrb/input/base_input.py +17 -5
  75. zrb/input/bool_input.py +1 -1
  76. zrb/input/float_input.py +2 -2
  77. zrb/input/int_input.py +1 -1
  78. zrb/input/option_input.py +2 -2
  79. zrb/input/password_input.py +2 -2
  80. zrb/input/text_input.py +6 -6
  81. zrb/runner/cli.py +9 -35
  82. zrb/runner/common_util.py +31 -0
  83. zrb/runner/web_app.py +169 -46
  84. zrb/runner/web_config.py +288 -0
  85. zrb/runner/web_controller/error_page/controller.py +27 -0
  86. zrb/runner/web_controller/error_page/view.html +33 -0
  87. zrb/runner/web_controller/group_info_page/controller.py +40 -0
  88. zrb/runner/web_controller/group_info_page/view.html +36 -0
  89. zrb/runner/web_controller/home_page/controller.py +14 -57
  90. zrb/runner/web_controller/home_page/view.html +29 -20
  91. zrb/runner/web_controller/login_page/controller.py +25 -0
  92. zrb/runner/web_controller/login_page/view.html +50 -0
  93. zrb/runner/web_controller/logout_page/controller.py +26 -0
  94. zrb/runner/web_controller/logout_page/view.html +40 -0
  95. zrb/runner/web_controller/{task_ui → session_page}/controller.py +36 -34
  96. zrb/runner/web_controller/{task_ui → session_page}/partial/input.html +1 -1
  97. zrb/runner/web_controller/session_page/view.html +91 -0
  98. zrb/runner/web_controller/static/common.css +11 -0
  99. zrb/runner/web_controller/static/login/event.js +33 -0
  100. zrb/runner/web_controller/static/logout/event.js +20 -0
  101. zrb/runner/web_controller/static/pico.min.css +1 -1
  102. zrb/runner/web_controller/static/session/common-util.js +63 -0
  103. zrb/runner/web_controller/static/session/current-session.js +164 -0
  104. zrb/runner/web_controller/static/session/event.js +120 -0
  105. zrb/runner/web_controller/static/session/past-session.js +138 -0
  106. zrb/runner/web_util.py +53 -0
  107. zrb/session_state_logger/any_session_state_logger.py +0 -1
  108. zrb/session_state_logger/file_session_state_logger.py +4 -8
  109. zrb/task/base_trigger.py +0 -1
  110. zrb/task/cmd_task.py +1 -1
  111. zrb/task/llm_task.py +3 -6
  112. zrb/task/make_task.py +0 -1
  113. zrb/task/scaffolder.py +18 -4
  114. zrb/task/scheduler.py +0 -1
  115. zrb/util/cmd/command.py +0 -1
  116. zrb/util/codemod/{add_code_to_class.py → append_code_to_class.py} +4 -4
  117. zrb/util/codemod/{add_code_to_function.py → append_code_to_function.py} +5 -3
  118. zrb/util/codemod/{add_code_to_method.py → append_code_to_method.py} +3 -3
  119. zrb/util/codemod/{add_key_to_dict.py → append_key_to_dict.py} +1 -1
  120. zrb/util/codemod/{add_param_to_function_call.py → append_param_to_function_call.py} +1 -1
  121. zrb/util/codemod/{add_code_to_module.py → prepend_code_to_module.py} +2 -2
  122. zrb/util/codemod/{add_parent_to_class.py → prepend_parent_to_class.py} +1 -1
  123. zrb/util/codemod/{add_property_to_class.py → prepend_property_to_class.py} +1 -1
  124. zrb/util/file.py +18 -0
  125. zrb/util/git_subtree.py +3 -4
  126. zrb/util/todo.py +105 -24
  127. zrb/xcom/xcom.py +0 -1
  128. {zrb-1.0.0a16.dist-info → zrb-1.0.0a20.dist-info}/METADATA +3 -2
  129. zrb-1.0.0a20.dist-info/RECORD +243 -0
  130. zrb/builtin/project/add/fastapp.py +0 -87
  131. zrb/builtin/project/add/fastapp_template/_zrb/column/create_column_task.py +0 -11
  132. zrb/builtin/project/add/fastapp_template/_zrb/entity/create_entity_task.py +0 -196
  133. zrb/builtin/project/add/fastapp_template/_zrb/entity/module_template/service/my_entity/repository/factory.py +0 -13
  134. zrb/builtin/project/add/fastapp_template/_zrb/module/create_module_task.py +0 -136
  135. zrb/builtin/project/add/fastapp_template/_zrb/module/module_template/client/any_client.py +0 -27
  136. zrb/builtin/project/add/fastapp_template/_zrb/module/module_template/client/api_client.py +0 -6
  137. zrb/builtin/project/add/fastapp_template/_zrb/module/module_template/client/direct_client.py +0 -6
  138. zrb/builtin/project/add/fastapp_template/_zrb/module/module_template/client/factory.py +0 -9
  139. zrb/builtin/project/add/fastapp_template/_zrb/module/module_template/route.py +0 -19
  140. zrb/builtin/project/add/fastapp_template/main.py +0 -7
  141. zrb/builtin/project/add/fastapp_template/migrate.py +0 -3
  142. zrb/builtin/project/add/fastapp_template/module/auth/client/api_client.py +0 -7
  143. zrb/builtin/project/add/fastapp_template/module/auth/client/direct_client.py +0 -6
  144. zrb/builtin/project/add/fastapp_template/module/auth/client/factory.py +0 -9
  145. zrb/builtin/project/add/fastapp_template/module/auth/migration/versions/3093c7336477_add_user_table.py +0 -37
  146. zrb/builtin/project/add/fastapp_template/module/auth/route.py +0 -22
  147. zrb/builtin/project/add/fastapp_template/module/auth/service/user/repository/factory.py +0 -13
  148. zrb/builtin/project/add/fastapp_template/module/auth/service/user/repository/user_repository.py +0 -34
  149. zrb/builtin/project/add/fastapp_template/module/gateway/route.py +0 -27
  150. zrb/runner/web_controller/group_info_ui/controller.py +0 -91
  151. zrb/runner/web_controller/group_info_ui/partial/group_info.html +0 -2
  152. zrb/runner/web_controller/group_info_ui/partial/group_li.html +0 -1
  153. zrb/runner/web_controller/group_info_ui/partial/task_info.html +0 -2
  154. zrb/runner/web_controller/group_info_ui/partial/task_li.html +0 -1
  155. zrb/runner/web_controller/group_info_ui/view.html +0 -31
  156. zrb/runner/web_controller/home_page/partial/group_info.html +0 -2
  157. zrb/runner/web_controller/home_page/partial/group_li.html +0 -1
  158. zrb/runner/web_controller/home_page/partial/task_info.html +0 -2
  159. zrb/runner/web_controller/home_page/partial/task_li.html +0 -1
  160. zrb/runner/web_controller/task_ui/partial/common-util.js +0 -37
  161. zrb/runner/web_controller/task_ui/partial/main.js +0 -195
  162. zrb/runner/web_controller/task_ui/partial/show-existing-session.js +0 -97
  163. zrb/runner/web_controller/task_ui/partial/visualize-history.js +0 -104
  164. zrb/runner/web_controller/task_ui/view.html +0 -87
  165. zrb-1.0.0a16.dist-info/RECORD +0 -231
  166. /zrb/builtin/project/add/{fastapp_template → fastapp/fastapp_template/my_app_name}/.gitignore +0 -0
  167. /zrb/builtin/project/add/{fastapp_template → fastapp/fastapp_template/my_app_name}/README.md +0 -0
  168. /zrb/builtin/project/add/{__init__.py → fastapp/fastapp_template/my_app_name/__init__.py} +0 -0
  169. /zrb/builtin/project/add/{fastapp_template → fastapp/fastapp_template/my_app_name}/_zrb/config.py +0 -0
  170. /zrb/builtin/project/add/{fastapp_template → fastapp/fastapp_template/my_app_name}/_zrb/group.py +0 -0
  171. /zrb/builtin/project/add/{fastapp_template/__init__.py → fastapp/fastapp_template/my_app_name/_zrb/module/template/app_template/module/gateway/subroute/my_module.py} +0 -0
  172. /zrb/builtin/project/add/{fastapp_template/_zrb/module/module_template → fastapp/fastapp_template/my_app_name/_zrb/module/template/app_template/module/my_module}/alembic.ini +0 -0
  173. /zrb/builtin/project/add/{fastapp_template/_zrb/module/module_template → fastapp/fastapp_template/my_app_name/_zrb/module/template/app_template/module/my_module}/migration/README +0 -0
  174. /zrb/builtin/project/add/{fastapp_template/module/gateway → fastapp/fastapp_template/my_app_name/_zrb/module/template/app_template/module/my_module}/migration/versions/.gitkeep +0 -0
  175. /zrb/builtin/project/add/{fastapp_template/_zrb/module/module_template → fastapp/fastapp_template/my_app_name/_zrb/module/template/app_template/module/my_module}/migration_metadata.py +0 -0
  176. /zrb/builtin/project/add/{fastapp_template/_zrb/module/module_template → fastapp/fastapp_template/my_app_name/_zrb/module/template/app_template/module/my_module}/service/__init__.py +0 -0
  177. /zrb/builtin/project/add/{fastapp_template/_zrb/module/run_module.template.py → fastapp/fastapp_template/my_app_name/_zrb/module/template/module_task_definition.py} +0 -0
  178. /zrb/builtin/project/add/{fastapp_template → fastapp/fastapp_template/my_app_name}/common/__init__.py +0 -0
  179. /zrb/builtin/project/add/{fastapp_template → fastapp/fastapp_template/my_app_name}/common/error.py +0 -0
  180. /zrb/builtin/project/add/{fastapp_template → fastapp/fastapp_template/my_app_name}/common/schema.py +0 -0
  181. /zrb/builtin/project/add/{fastapp_template → fastapp/fastapp_template/my_app_name}/module/__init__.py +0 -0
  182. /zrb/builtin/project/add/{fastapp_template → fastapp/fastapp_template/my_app_name}/module/auth/alembic.ini +0 -0
  183. /zrb/builtin/project/add/{fastapp_template → fastapp/fastapp_template/my_app_name}/module/auth/migration/README +0 -0
  184. /zrb/builtin/project/add/{fastapp_template/_zrb/module/module_template → fastapp/fastapp_template/my_app_name/module/auth}/migration/versions/3093c7336477_add_user_table.py +0 -0
  185. /zrb/builtin/project/add/{fastapp_template → fastapp/fastapp_template/my_app_name}/module/auth/service/__init__.py +0 -0
  186. /zrb/builtin/project/add/{fastapp_template → fastapp/fastapp_template/my_app_name}/module/auth/service/user/__init__.py +0 -0
  187. /zrb/builtin/project/add/{fastapp_template → fastapp/fastapp_template/my_app_name}/module/gateway/alembic.ini +0 -0
  188. /zrb/builtin/project/add/{fastapp_template → fastapp/fastapp_template/my_app_name}/module/gateway/migration/README +0 -0
  189. /zrb/builtin/project/add/{fastapp_template/module/auth/service/user/repository/__init__.py → fastapp/fastapp_template/my_app_name/module/gateway/migration/versions/.gitkeep} +0 -0
  190. /zrb/builtin/project/add/{fastapp_template → fastapp/fastapp_template/my_app_name}/module/gateway/migration_metadata.py +0 -0
  191. /zrb/builtin/project/add/{fastapp_template → fastapp/fastapp_template/my_app_name}/schema/__init__.py +0 -0
  192. /zrb/builtin/project/add/{fastapp_template → fastapp/fastapp_template/my_app_name}/template.env +0 -0
  193. /zrb/runner/web_controller/{group_info_ui → group_info_page}/__init__.py +0 -0
  194. /zrb/runner/web_controller/{task_ui → session_page}/__init__.py +0 -0
  195. {zrb-1.0.0a16.dist-info → zrb-1.0.0a20.dist-info}/WHEEL +0 -0
  196. {zrb-1.0.0a16.dist-info → zrb-1.0.0a20.dist-info}/entry_points.txt +0 -0
@@ -0,0 +1,13 @@
1
+ from my_app_name.common.db_engine import engine
2
+ from my_app_name.config import APP_REPOSITORY_TYPE
3
+ from my_app_name.module.my_module.service.my_entity.repository.my_entity_db_repository import (
4
+ MyEntityDBRepository,
5
+ )
6
+ from my_app_name.module.my_module.service.my_entity.repository.my_entity_repository import (
7
+ MyEntityRepository,
8
+ )
9
+
10
+ if APP_REPOSITORY_TYPE == "db":
11
+ my_entity_repository: MyEntityRepository = MyEntityDBRepository(engine)
12
+ else:
13
+ my_entity_repository: MyEntityRepository = None
@@ -1,13 +1,13 @@
1
- from fastapp_template.common.base_db_repository import BaseDBRepository
2
- from fastapp_template.common.error import NotFoundError
3
- from fastapp_template.module.my_module.service.my_entity.repository.my_entity_repository import (
1
+ from my_app_name.common.base_db_repository import BaseDBRepository
2
+ from my_app_name.common.error import NotFoundError
3
+ from my_app_name.module.my_module.service.my_entity.repository.my_entity_repository import (
4
4
  MyEntityRepository,
5
5
  )
6
- from fastapp_template.schema.my_entity import (
6
+ from my_app_name.schema.my_entity import (
7
7
  MyEntity,
8
- MyEntityCreate,
8
+ MyEntityCreateWithAudit,
9
9
  MyEntityResponse,
10
- MyEntityUpdate,
10
+ MyEntityUpdateWithAudit,
11
11
  )
12
12
  from passlib.context import CryptContext
13
13
  from sqlalchemy.ext.asyncio import AsyncSession
@@ -22,12 +22,17 @@ def hash_password(password: str) -> str:
22
22
 
23
23
 
24
24
  class MyEntityDBRepository(
25
- BaseDBRepository[MyEntity, MyEntityResponse, MyEntityCreate, MyEntityUpdate],
25
+ BaseDBRepository[
26
+ MyEntity,
27
+ MyEntityResponse,
28
+ MyEntityCreateWithAudit,
29
+ MyEntityUpdateWithAudit,
30
+ ],
26
31
  MyEntityRepository,
27
32
  ):
28
33
  db_model = MyEntity
29
34
  response_model = MyEntityResponse
30
- create_model = MyEntityCreate
31
- update_model = MyEntityUpdate
35
+ create_model = MyEntityCreateWithAudit
36
+ update_model = MyEntityUpdateWithAudit
32
37
  entity_name = "my_entity"
33
38
  column_preprocessors = {}
@@ -1,17 +1,16 @@
1
1
  from abc import ABC, abstractmethod
2
2
 
3
- from fastapp_template.schema.my_entity import (
3
+ from my_app_name.schema.my_entity import (
4
4
  MyEntity,
5
- MyEntityCreate,
5
+ MyEntityCreateWithAudit,
6
6
  MyEntityResponse,
7
- MyEntityUpdate,
7
+ MyEntityUpdateWithAudit,
8
8
  )
9
9
 
10
10
 
11
11
  class MyEntityRepository(ABC):
12
-
13
12
  @abstractmethod
14
- async def create(self, my_entity_data: MyEntityCreate) -> MyEntityResponse:
13
+ async def create(self, my_entity_data: MyEntityCreateWithAudit) -> MyEntityResponse:
15
14
  pass
16
15
 
17
16
  @abstractmethod
@@ -24,7 +23,7 @@ class MyEntityRepository(ABC):
24
23
 
25
24
  @abstractmethod
26
25
  async def update(
27
- self, my_entity_id: str, my_entity_data: MyEntityUpdate
26
+ self, my_entity_id: str, my_entity_data: MyEntityUpdateWithAudit
28
27
  ) -> MyEntity:
29
28
  pass
30
29
 
@@ -34,6 +33,6 @@ class MyEntityRepository(ABC):
34
33
 
35
34
  @abstractmethod
36
35
  async def create_bulk(
37
- self, my_entity_data_list: list[MyEntityCreate]
36
+ self, my_entity_data_list: list[MyEntityCreateWithAudit]
38
37
  ) -> list[MyEntityResponse]:
39
38
  pass
@@ -12,10 +12,18 @@ class MyEntityCreate(MyEntityBase):
12
12
  pass
13
13
 
14
14
 
15
+ class MyEntityCreateWithAudit(MyEntityCreate):
16
+ created_by: str
17
+
18
+
15
19
  class MyEntityUpdate(SQLModel):
16
20
  my_column: str | None = None
17
21
 
18
22
 
23
+ class MyEntityUpdateWithAudit(MyEntityUpdate):
24
+ updated_by: str
25
+
26
+
19
27
  class MyEntityResponse(MyEntityBase):
20
28
  id: str
21
29
 
@@ -0,0 +1,17 @@
1
+ from my_app_name._zrb.config import APP_DIR
2
+ from my_app_name._zrb.group import app_group
3
+
4
+ from zrb.task.cmd_task import CmdTask
5
+
6
+ format_my_app_name_code = app_group.add_task(
7
+ CmdTask(
8
+ name="format-my-app-name-code",
9
+ description="✏️ Format Python code",
10
+ cmd=[
11
+ "isort . --profile black --force-grid-wrap 0",
12
+ "black .",
13
+ ],
14
+ cwd=APP_DIR,
15
+ ),
16
+ alias="format",
17
+ )
@@ -1,7 +1,4 @@
1
- from fastapp_template._zrb.helper import (
2
- get_existing_module_names,
3
- get_existing_schema_names,
4
- )
1
+ from my_app_name._zrb.util import get_existing_module_names, get_existing_schema_names
5
2
 
6
3
  from zrb import OptionInput, StrInput
7
4
  from zrb.util.string.conversion import pluralize
@@ -0,0 +1,85 @@
1
+ import os
2
+
3
+ from my_app_name._zrb.config import APP_DIR
4
+ from my_app_name._zrb.format_task import format_my_app_name_code
5
+ from my_app_name._zrb.group import app_create_group
6
+ from my_app_name._zrb.input import new_module_input
7
+ from my_app_name._zrb.module.add_module_util import (
8
+ is_app_config_file,
9
+ is_app_main_file,
10
+ is_app_zrb_config_file,
11
+ is_app_zrb_task_file,
12
+ is_in_module_dir,
13
+ update_app_config_file,
14
+ update_app_main_file,
15
+ update_app_zrb_config_file,
16
+ update_app_zrb_task_file,
17
+ )
18
+ from my_app_name._zrb.util import get_existing_module_names
19
+
20
+ from zrb import AnyContext, ContentTransformer, Scaffolder, Task, make_task
21
+
22
+
23
+ @make_task(
24
+ name="validate-create-my-app-name-module",
25
+ input=new_module_input,
26
+ retries=0,
27
+ )
28
+ async def validate_create_my_app_name_module(ctx: AnyContext):
29
+ if ctx.input.module in get_existing_module_names():
30
+ raise ValueError(f"Module already exists: {ctx.input.module}")
31
+
32
+
33
+ scaffold_my_app_name_module = Scaffolder(
34
+ name="scaffold-my-app-name-module",
35
+ input=new_module_input,
36
+ source_path=os.path.join(os.path.dirname(__file__), "template", "app_template"),
37
+ render_source_path=False,
38
+ destination_path=APP_DIR,
39
+ transform_path={
40
+ "my_module": "{to_snake_case(ctx.input.module)}",
41
+ },
42
+ transform_content=[
43
+ # Common transformation (my_app_name/module/snake_module_name)
44
+ ContentTransformer(
45
+ match=is_in_module_dir,
46
+ transform={
47
+ "MY_MODULE": "{to_snake_case(ctx.input.module).upper()}",
48
+ "my_module": "{to_snake_case(ctx.input.module)}",
49
+ },
50
+ ),
51
+ # Register module config to my_app_name/config.py
52
+ ContentTransformer(
53
+ match=is_app_config_file,
54
+ transform=update_app_config_file,
55
+ ),
56
+ # Register module route to my_app_name/main.py
57
+ ContentTransformer(
58
+ match=is_app_main_file,
59
+ transform=update_app_main_file,
60
+ ),
61
+ # Register module's tasks to my_app_name/_zrb/task.py
62
+ ContentTransformer(
63
+ match=is_app_zrb_task_file,
64
+ transform=update_app_zrb_task_file,
65
+ ),
66
+ # Register module's base url to my_app_name/_zrb/config.py
67
+ ContentTransformer(
68
+ match=is_app_zrb_config_file,
69
+ transform=update_app_zrb_config_file,
70
+ ),
71
+ ],
72
+ retries=0,
73
+ upstream=validate_create_my_app_name_module,
74
+ )
75
+
76
+ add_my_app_name_module = app_create_group.add_task(
77
+ Task(
78
+ name="add-my-app-name-module",
79
+ description="🧩 Create new module on My App Name",
80
+ upstream=scaffold_my_app_name_module,
81
+ successor=format_my_app_name_code,
82
+ retries=0,
83
+ ),
84
+ alias="module",
85
+ )
@@ -0,0 +1,154 @@
1
+ import os
2
+
3
+ from my_app_name._zrb.config import APP_DIR
4
+ from my_app_name._zrb.util import get_existing_module_names
5
+
6
+ from zrb.context.any_context import AnyContext
7
+ from zrb.util.codemod.append_key_to_dict import append_key_to_dict
8
+ from zrb.util.file import read_file, write_file
9
+ from zrb.util.string.conversion import to_kebab_case, to_pascal_case, to_snake_case
10
+
11
+
12
+ def is_app_config_file(ctx: AnyContext, file_path: str) -> bool:
13
+ return file_path == os.path.join(APP_DIR, "config.py")
14
+
15
+
16
+ def is_app_main_file(ctx: AnyContext, file_path: str) -> bool:
17
+ return file_path == os.path.join(APP_DIR, "main.py")
18
+
19
+
20
+ def is_app_zrb_task_file(ctx: AnyContext, file_path: str) -> bool:
21
+ return file_path == os.path.join(APP_DIR, "_zrb", "task.py")
22
+
23
+
24
+ def is_app_zrb_config_file(ctx: AnyContext, file_path: str) -> bool:
25
+ return file_path == os.path.join(APP_DIR, "_zrb", "config.py")
26
+
27
+
28
+ def is_in_module_dir(ctx: AnyContext, file_path: str) -> bool:
29
+ return file_path.startswith(
30
+ os.path.join(APP_DIR, "module", to_snake_case(ctx.input.module))
31
+ )
32
+
33
+
34
+ def update_app_zrb_config_file(ctx: AnyContext, zrb_config_file_path: str):
35
+ existing_zrb_config_code = read_file(zrb_config_file_path)
36
+ module_name = ctx.input.module
37
+ upper_snake_module_name = to_snake_case(module_name).upper()
38
+ existing_module_names = get_existing_module_names()
39
+ module_port = 3001 + len(
40
+ [
41
+ existing_module_name
42
+ for existing_module_name in existing_module_names
43
+ if existing_module_name != to_snake_case(module_name)
44
+ ]
45
+ )
46
+ write_file(
47
+ file_path=zrb_config_file_path,
48
+ content=append_key_to_dict(
49
+ original_code=existing_zrb_config_code,
50
+ dictionary_name="MICROSERVICES_ENV_VARS",
51
+ new_key=f"MY_APP_NAME_{upper_snake_module_name}_BASE_URL",
52
+ new_value=f"http://localhost:{module_port}",
53
+ ),
54
+ )
55
+
56
+
57
+ def update_app_zrb_task_file(ctx: AnyContext, zrb_task_file_path: str):
58
+ existing_zrb_task_code = read_file(zrb_task_file_path)
59
+ write_file(
60
+ file_path=zrb_task_file_path,
61
+ content=[
62
+ existing_zrb_task_code.strip(),
63
+ "",
64
+ _get_task_definition_code(existing_zrb_task_code, ctx.input.module),
65
+ ],
66
+ )
67
+
68
+
69
+ def _get_task_definition_code(existing_code: str, module_name: str) -> str | None:
70
+ existing_module_names = get_existing_module_names()
71
+ module_port = 3001 + len(
72
+ [
73
+ existing_module_name
74
+ for existing_module_name in existing_module_names
75
+ if existing_module_name != to_snake_case(module_name)
76
+ ]
77
+ )
78
+ snake_module_name = to_snake_case(module_name)
79
+ kebab_module_name = to_kebab_case(module_name)
80
+ pascal_module_name = to_pascal_case(module_name)
81
+ task_definition_code = read_file(
82
+ file_path=os.path.join(
83
+ os.path.dirname(__file__), "template", "module_task_definition.py"
84
+ ),
85
+ replace_map={
86
+ "my_module": snake_module_name,
87
+ "my-module": kebab_module_name,
88
+ "My Module": pascal_module_name,
89
+ "3000": f"{module_port}",
90
+ },
91
+ ).strip()
92
+ if task_definition_code in existing_code:
93
+ return None
94
+ return task_definition_code
95
+
96
+
97
+ def update_app_main_file(ctx: AnyContext, app_main_file_path: str):
98
+ existing_app_main_code = read_file(app_main_file_path)
99
+ write_file(
100
+ file_path=app_main_file_path,
101
+ content=[
102
+ _get_import_module_route_code(existing_app_main_code, ctx.input.module),
103
+ existing_app_main_code,
104
+ "",
105
+ _get_assert_module_route_code(existing_app_main_code, ctx.input.module),
106
+ ],
107
+ )
108
+
109
+
110
+ def _get_import_module_route_code(existing_code: str, module_name: str) -> str | None:
111
+ snake_module_name = to_snake_case(module_name)
112
+ import_module_path = f"my_app_name.module.{snake_module_name}"
113
+ import_route_code = (
114
+ f"from {import_module_path} import route as {snake_module_name}_route"
115
+ )
116
+ if import_route_code in existing_code:
117
+ return None
118
+ return import_route_code
119
+
120
+
121
+ def _get_assert_module_route_code(existing_code: str, module_name: str) -> str | None:
122
+ snake_module_name = to_snake_case(module_name)
123
+ assert_route_code = f"assert {snake_module_name}_route"
124
+ return assert_route_code if assert_route_code not in existing_code else None
125
+
126
+
127
+ def update_app_config_file(ctx: AnyContext, module_config_path: str):
128
+ existing_config_code = read_file(module_config_path)
129
+ write_file(
130
+ module_config_path,
131
+ [
132
+ existing_config_code.strip(),
133
+ _get_new_module_config_code(existing_config_code, ctx.input.module),
134
+ ],
135
+ )
136
+
137
+
138
+ def _get_new_module_config_code(existing_code: str, module_name: str) -> str | None:
139
+ existing_module_names = get_existing_module_names()
140
+ module_port = 3000 + len(
141
+ [
142
+ existing_module_name
143
+ for existing_module_name in existing_module_names
144
+ if existing_module_name != to_snake_case(module_name)
145
+ ]
146
+ )
147
+ module_base_url = f"http://localhost:{module_port}"
148
+ upper_snake_module_name = to_snake_case(module_name).upper()
149
+ config_name = f"APP_{upper_snake_module_name}_BASE_URL"
150
+ env_name = f"MY_APP_NAME_{upper_snake_module_name}_BASE_URL"
151
+ config_code = f'{config_name} = os.getenv("{env_name}", "{module_base_url}")'
152
+ if config_code in existing_code:
153
+ return None
154
+ return config_code
@@ -0,0 +1,7 @@
1
+ from abc import ABC, abstractmethod
2
+
3
+
4
+ class AnyClient(ABC):
5
+ """
6
+ Defining client methods
7
+ """
@@ -0,0 +1,6 @@
1
+ from my_app_name.config import APP_MY_MODULE_BASE_URL
2
+ from my_app_name.module.module_template.client.any_client import AnyClient
3
+
4
+
5
+ class APIClient(AnyClient):
6
+ pass
@@ -0,0 +1,6 @@
1
+ from my_app_name.module.module_template.client.any_client import AnyClient
2
+ from my_app_name.module.module_template.service.user.usecase import user_usecase
3
+
4
+
5
+ class DirectClient(AnyClient):
6
+ pass
@@ -0,0 +1,9 @@
1
+ from my_app_name.config import APP_COMMUNICATION
2
+ from my_app_name.module.module_template.client.any_client import AnyClient
3
+ from my_app_name.module.module_template.client.api_client import APIClient
4
+ from my_app_name.module.module_template.client.direct_client import DirectClient
5
+
6
+ if APP_COMMUNICATION == "direct":
7
+ client: AnyClient = DirectClient()
8
+ elif APP_COMMUNICATION == "api":
9
+ client: AnyClient = APIClient()
@@ -1,8 +1,8 @@
1
1
  from logging.config import fileConfig
2
2
 
3
3
  from alembic import context
4
- from fastapp_template.config import APP_DB_URL
5
- from fastapp_template.module.my_module.migration_metadata import metadata
4
+ from my_app_name.config import APP_DB_URL
5
+ from my_app_name.module.my_module.migration_metadata import metadata
6
6
  from sqlalchemy import engine_from_config, pool
7
7
 
8
8
  # this is the Alembic Config object, which provides
@@ -68,7 +68,6 @@ def run_migrations_offline() -> None:
68
68
  target_metadata=target_metadata,
69
69
  literal_binds=True,
70
70
  dialect_opts={"paramstyle": "named"},
71
- imports=["import sqlmodel"], # 🔥 FastApp Modification
72
71
  version_table=MIGRATION_TABLE, # 🔥 FastApp Modification
73
72
  include_object=include_object, # 🔥 FastApp Modification
74
73
  )
@@ -94,7 +93,6 @@ def run_migrations_online() -> None:
94
93
  context.configure(
95
94
  connection=connection,
96
95
  target_metadata=target_metadata,
97
- imports=["import sqlmodel"], # 🔥 FastApp Modification
98
96
  version_table=MIGRATION_TABLE, # 🔥 FastApp Modification
99
97
  include_object=include_object, # 🔥 FastApp Modification
100
98
  )
@@ -9,6 +9,7 @@ from typing import Sequence, Union
9
9
 
10
10
  from alembic import op
11
11
  import sqlalchemy as sa
12
+ import sqlmodel # 🔥 FastApp Modification
12
13
  ${imports if imports else ""}
13
14
 
14
15
  # revision identifiers, used by Alembic.
@@ -0,0 +1,33 @@
1
+ from fastapi import FastAPI
2
+ from my_app_name.common.app import app
3
+ from my_app_name.common.schema import BasicResponse
4
+ from my_app_name.config import APP_MAIN_MODULE, APP_MODE, APP_MODULES
5
+
6
+
7
+ def serve_health_check(app: FastAPI):
8
+ @app.api_route("/health", methods=["GET", "HEAD"], response_model=BasicResponse)
9
+ async def health():
10
+ """
11
+ Microservice's health check
12
+ """
13
+ return BasicResponse(message="ok")
14
+
15
+
16
+ def serve_readiness_check(app: FastAPI):
17
+ @app.api_route("/readiness", methods=["GET", "HEAD"], response_model=BasicResponse)
18
+ async def readiness():
19
+ """
20
+ Microservice's readiness check
21
+ """
22
+ return BasicResponse(message="ok")
23
+
24
+
25
+ def serve_route(app: FastAPI):
26
+ if APP_MODE != "microservices" or "my_module" not in APP_MODULES:
27
+ return
28
+ if APP_MAIN_MODULE == "my_module":
29
+ serve_health_check(app)
30
+ serve_readiness_check(app)
31
+
32
+
33
+ serve_route(app)
@@ -1,26 +1,24 @@
1
1
  import os
2
2
 
3
- from fastapp_template._zrb.column.create_column_task import create_my_app_name_column
4
- from fastapp_template._zrb.config import ACTIVATE_VENV_SCRIPT, APP_DIR
5
- from fastapp_template._zrb.entity.create_entity_task import create_my_app_name_entity
6
- from fastapp_template._zrb.group import (
3
+ from my_app_name._zrb.column.create_column_task import add_my_app_name_column
4
+ from my_app_name._zrb.config import ACTIVATE_VENV_SCRIPT, APP_DIR
5
+ from my_app_name._zrb.entity.add_entity_task import add_my_app_name_entity
6
+ from my_app_name._zrb.format_task import format_my_app_name_code
7
+ from my_app_name._zrb.group import (
7
8
  app_create_migration_group,
8
9
  app_migrate_group,
9
10
  app_run_group,
10
11
  )
11
- from fastapp_template._zrb.helper import (
12
- create_migration,
13
- migrate_module,
14
- run_microservice,
15
- )
16
- from fastapp_template._zrb.module.create_module_task import create_my_app_name_module
17
- from fastapp_template._zrb.venv_task import prepare_venv
12
+ from my_app_name._zrb.module.add_module_task import add_my_app_name_module
13
+ from my_app_name._zrb.util import create_migration, migrate_module, run_microservice
14
+ from my_app_name._zrb.venv_task import prepare_venv
18
15
 
19
16
  from zrb import CmdTask, Env, EnvFile, Task
20
17
 
21
- assert create_my_app_name_entity
22
- assert create_my_app_name_module
23
- assert create_my_app_name_column
18
+ assert add_my_app_name_entity
19
+ assert add_my_app_name_module
20
+ assert add_my_app_name_column
21
+ assert format_my_app_name_code
24
22
 
25
23
  # 🚀 Run/Migrate All ===========================================================
26
24
 
@@ -1,6 +1,6 @@
1
1
  import os
2
2
 
3
- from fastapp_template._zrb.config import (
3
+ from my_app_name._zrb.config import (
4
4
  ACTIVATE_VENV_SCRIPT,
5
5
  APP_DIR,
6
6
  MICROSERVICES_ENV_VARS,
@@ -1,6 +1,6 @@
1
1
  import os
2
2
 
3
- from fastapp_template._zrb.config import ACTIVATE_VENV_SCRIPT, APP_DIR
3
+ from my_app_name._zrb.config import ACTIVATE_VENV_SCRIPT, APP_DIR
4
4
 
5
5
  from zrb import CmdTask
6
6
 
@@ -1,8 +1,8 @@
1
1
  from contextlib import asynccontextmanager
2
2
 
3
3
  from fastapi import FastAPI
4
- from fastapp_template.common.db_engine import engine
5
- from fastapp_template.config import APP_MODE, APP_MODULES
4
+ from my_app_name.common.db_engine import engine
5
+ from my_app_name.config import APP_MODE, APP_MODULES
6
6
  from sqlmodel import SQLModel
7
7
 
8
8
 
@@ -1,6 +1,6 @@
1
1
  from typing import Any, Callable, Generic, Type, TypeVar
2
2
 
3
- from fastapp_template.common.error import NotFoundError
3
+ from my_app_name.common.error import NotFoundError
4
4
  from sqlalchemy import Engine
5
5
  from sqlalchemy.ext.asyncio import AsyncEngine, AsyncSession
6
6
  from sqlmodel import Session, SQLModel, select
@@ -67,6 +67,12 @@ class RouteParam:
67
67
  class BaseUsecase:
68
68
  _route_params: dict[str, RouteParam] = {}
69
69
 
70
+ def __init__(self):
71
+ self._route_params: dict[str, RouteParam] = {}
72
+ for name, method in self.__class__.__dict__.items():
73
+ if hasattr(method, "__route_param__"):
74
+ self._route_params[name] = getattr(method, "__route_param__")
75
+
70
76
  @classmethod
71
77
  def route(
72
78
  cls,
@@ -100,7 +106,15 @@ class BaseUsecase:
100
106
  """
101
107
 
102
108
  def decorator(func: Callable):
103
- cls._route_params[func.__name__] = RouteParam(
109
+ @wraps(func)
110
+ async def wrapped(*args, **kwargs):
111
+ return await func(*args, **kwargs)
112
+
113
+ # Inject __route_param__ property to the method
114
+ # Method with __route_param__ property will automatically
115
+ # registered to self._route_param and will be automatically exposed
116
+ # into DirectClient and APIClient
117
+ wrapped.__route_param__ = RouteParam(
104
118
  path=path,
105
119
  response_model=response_model,
106
120
  status_code=status_code,
@@ -126,11 +140,6 @@ class BaseUsecase:
126
140
  generate_unique_id_function=generate_unique_id_function,
127
141
  func=func,
128
142
  )
129
-
130
- @wraps(func)
131
- async def wrapped(*args, **kwargs):
132
- return await func(*args, **kwargs)
133
-
134
143
  return wrapped
135
144
 
136
145
  return decorator
@@ -144,6 +153,8 @@ class BaseUsecase:
144
153
  for name, details in _methods.items():
145
154
  func = details.func
146
155
  client_method = create_direct_client_method(func, self)
156
+ # Use __get__ to make a bounded method,
157
+ # ensuring that client_method use DirectClient as `self`
147
158
  setattr(DirectClient, name, client_method.__get__(DirectClient))
148
159
  return DirectClient
149
160
 
@@ -156,6 +167,8 @@ class BaseUsecase:
156
167
  # Dynamically generate methods
157
168
  for name, param in _methods.items():
158
169
  client_method = create_api_client_method(param, base_url)
170
+ # Use __get__ to make a bounded method,
171
+ # ensuring that client_method use APIClient as `self`
159
172
  setattr(APIClient, name, client_method.__get__(APIClient))
160
173
  return APIClient
161
174
 
@@ -1,4 +1,4 @@
1
- from fastapp_template.config import APP_DB_URL
1
+ from my_app_name.config import APP_DB_URL
2
2
  from sqlmodel import create_engine
3
3
 
4
4
  connect_args = {"check_same_thread": False}
@@ -8,6 +8,7 @@ APP_MODULES = [
8
8
  for module in os.getenv("MY_APP_NAME_MODULES", "").split(",")
9
9
  if module.strip() != ""
10
10
  ]
11
+ APP_MAIN_MODULE = APP_MODULES[0] if len(APP_MODULES) > 0 else None
11
12
  APP_PORT = int(os.getenv("MY_APP_NAME_PORT", "3000"))
12
13
  APP_COMMUNICATION = os.getenv(
13
14
  "MY_APP_NAME_COMMUNICATION", "direct" if APP_MODE == "monolith" else "api"
@@ -0,0 +1,7 @@
1
+ from my_app_name.common.app import app
2
+ from my_app_name.module.auth import route as auth_route
3
+ from my_app_name.module.gateway import route as gateway_route
4
+
5
+ assert app
6
+ assert gateway_route
7
+ assert auth_route
@@ -0,0 +1,3 @@
1
+ from my_app_name.module.auth import migration as auth_migration
2
+
3
+ assert auth_migration