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
@@ -1,196 +0,0 @@
1
- import os
2
-
3
- from fastapp_template._zrb.config import APP_DIR
4
- from fastapp_template._zrb.group import app_create_group
5
- from fastapp_template._zrb.helper import (
6
- get_existing_module_names,
7
- get_existing_schema_names,
8
- )
9
- from fastapp_template._zrb.input import (
10
- existing_module_input,
11
- new_entity_column_input,
12
- new_entity_input,
13
- plural_entity_input,
14
- )
15
-
16
- from zrb import AnyContext, Scaffolder, Task, make_task
17
- from zrb.util.codemod.add_code_to_module import add_code_to_module
18
- from zrb.util.codemod.add_parent_to_class import add_parent_to_class
19
- from zrb.util.string.conversion import to_pascal_case, to_snake_case
20
-
21
-
22
- @make_task(
23
- name="validate-create-my-app-name-entity",
24
- input=[
25
- existing_module_input,
26
- new_entity_input,
27
- plural_entity_input,
28
- new_entity_column_input,
29
- ],
30
- retries=0,
31
- )
32
- async def validate_create_my_app_name_entity(ctx: AnyContext):
33
- module_name = to_snake_case(ctx.input.module)
34
- if module_name not in get_existing_module_names():
35
- raise ValueError(f"Module not exist: {module_name}")
36
- schema_name = to_snake_case(ctx.input.entity)
37
- if schema_name in get_existing_schema_names():
38
- raise ValueError(f"Schema already exists: {schema_name}")
39
-
40
-
41
- scaffold_my_app_name_schema = Scaffolder(
42
- name="scaffold-my-app-name-schema",
43
- input=[
44
- existing_module_input,
45
- new_entity_input,
46
- new_entity_column_input,
47
- ],
48
- source_path=os.path.join(os.path.dirname(__file__), "schema.template.py"),
49
- render_source_path=False,
50
- destination_path=lambda ctx: os.path.join(
51
- APP_DIR,
52
- "schema",
53
- f"{to_snake_case(ctx.input.entity)}.py",
54
- ),
55
- transform_content={
56
- "MyEntity": "{to_pascal_case(ctx.input.entity)}",
57
- "my_column": "{to_snake_case(ctx.input.column)}",
58
- },
59
- retries=0,
60
- upstream=validate_create_my_app_name_entity,
61
- )
62
-
63
- scaffold_my_app_name_module_entity = Scaffolder(
64
- name="scaffold-my-app-name-schema",
65
- input=[
66
- existing_module_input,
67
- new_entity_input,
68
- plural_entity_input,
69
- ],
70
- source_path=os.path.join(os.path.dirname(__file__), "module_template"),
71
- render_source_path=False,
72
- destination_path=lambda ctx: os.path.join(
73
- APP_DIR,
74
- "module",
75
- f"{to_snake_case(ctx.input.module)}",
76
- ),
77
- transform_content={
78
- "my_module": "{to_snake_case(ctx.input.module)}",
79
- "MyEntity": "{to_pascal_case(ctx.input.entity)}",
80
- "my_entity": "{to_snake_case(ctx.input.entity)}",
81
- "my_entities": "{to_snake_case(ctx.input.plural)}",
82
- "my-entities": "{to_kebab_case(ctx.input.plural)}",
83
- },
84
- retries=0,
85
- upstream=validate_create_my_app_name_entity,
86
- )
87
-
88
-
89
- @make_task(
90
- name="register-my-app-name-migration",
91
- input=[existing_module_input, new_entity_input],
92
- retries=0,
93
- upstream=validate_create_my_app_name_entity,
94
- )
95
- async def register_my_app_name_migration(ctx: AnyContext):
96
- migration_metadata_file_path = os.path.join(
97
- APP_DIR, "module", to_snake_case(ctx.input.module), "migration_metadata.py"
98
- )
99
- app_name = os.path.basename(APP_DIR)
100
- with open(migration_metadata_file_path, "r") as f:
101
- file_content = f.read()
102
- entity_name = to_snake_case(ctx.input.entity)
103
- entity_class = to_pascal_case(ctx.input.entity)
104
- new_file_content_list = (
105
- [f"from {app_name}.schema.{entity_name} import {entity_class}"]
106
- + file_content.strip()
107
- + [
108
- f"{entity_class}.metadata = metadata",
109
- f"{entity_class}.__table__.tometadata(metadata)",
110
- "",
111
- ]
112
- )
113
- with open(migration_metadata_file_path, "w") as f:
114
- f.write("\n".join(new_file_content_list))
115
-
116
-
117
- @make_task(
118
- name="register-my-app-name-api-client",
119
- input=[existing_module_input, new_entity_input],
120
- retries=0,
121
- upstream=validate_create_my_app_name_entity,
122
- )
123
- async def register_my_app_name_api_client(ctx: AnyContext):
124
- api_client_file_path = os.path.join(
125
- APP_DIR, "module", to_snake_case(ctx.input.module), "client", "api_client.py"
126
- )
127
- with open(api_client_file_path, "r") as f:
128
- file_content = f.read()
129
- module_config_name = to_snake_case(ctx.input.module).upper()
130
- new_code = add_code_to_module(
131
- file_content,
132
- f"user_api_client = user_usecase.as_api_client(base_url=APP_{module_config_name}_BASE_URL)", # noqa
133
- )
134
- new_code = add_parent_to_class(
135
- original_code=new_code,
136
- class_name="APIClient",
137
- parent_class_name="user_api_client",
138
- )
139
- app_name = os.path.basename(APP_DIR)
140
- entity_name = to_snake_case(ctx.input.entity)
141
- module_name = to_snake_case(ctx.input.module)
142
- new_file_content_list = [
143
- f"from {app_name}.module.{module_name}.service.{entity_name} import {entity_name}_usecase", # noqa
144
- new_code.strip(),
145
- "",
146
- ]
147
- with open(api_client_file_path, "w") as f:
148
- f.write("\n".join(new_file_content_list))
149
-
150
-
151
- @make_task(
152
- name="register-my-app-name-direct-client",
153
- input=[existing_module_input, new_entity_input],
154
- retries=0,
155
- upstream=validate_create_my_app_name_entity,
156
- )
157
- async def register_my_app_name_direct_client(ctx: AnyContext):
158
- direct_client_file_path = os.path.join(
159
- APP_DIR, "module", to_snake_case(ctx.input.module), "client", "direct_client.py"
160
- )
161
- with open(direct_client_file_path, "r") as f:
162
- file_content = f.read()
163
- new_code = add_code_to_module(
164
- file_content, "user_direct_client = user_usecase.as_direct_client()"
165
- )
166
- new_code = add_parent_to_class(
167
- original_code=new_code,
168
- class_name="DirectClient",
169
- parent_class_name="user_direct_client",
170
- )
171
- app_name = os.path.basename(APP_DIR)
172
- entity_name = to_snake_case(ctx.input.entity)
173
- module_name = to_snake_case(ctx.input.module)
174
- new_file_content_list = [
175
- f"from {app_name}.module.{module_name}.service.{entity_name} import {entity_name}_usecase", # noqa
176
- new_code.strip(),
177
- "",
178
- ]
179
- with open(direct_client_file_path, "w") as f:
180
- f.write("\n".join(new_file_content_list))
181
-
182
-
183
- create_my_app_name_entity = app_create_group.add_task(
184
- Task(
185
- name="create-my-app-name-entity",
186
- description="🏗️ Create new entity on a module",
187
- successor="",
188
- ),
189
- alias="entity",
190
- )
191
- create_my_app_name_entity << [
192
- scaffold_my_app_name_schema,
193
- scaffold_my_app_name_module_entity,
194
- register_my_app_name_api_client,
195
- register_my_app_name_direct_client,
196
- ]
@@ -1,13 +0,0 @@
1
- from fastapp_template.common.db_engine import engine
2
- from fastapp_template.config import APP_REPOSITORY_TYPE
3
- from fastapp_template.module.my_module.service.my_entity.repository.my_entity_db_repository import (
4
- MyEntityDBRepository,
5
- )
6
- from fastapp_template.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,136 +0,0 @@
1
- import os
2
-
3
- from fastapp_template._zrb.config import APP_DIR
4
- from fastapp_template._zrb.group import app_create_group
5
- from fastapp_template._zrb.helper import get_existing_module_names
6
- from fastapp_template._zrb.input import new_module_input
7
-
8
- from zrb import AnyContext, Scaffolder, Task, make_task
9
- from zrb.util.string.conversion import to_kebab_case, to_pascal_case, to_snake_case
10
-
11
-
12
- @make_task(
13
- name="validate-create-my-app-name-module",
14
- input=new_module_input,
15
- retries=0,
16
- )
17
- async def validate_create_my_app_name_module(ctx: AnyContext):
18
- if ctx.input.module in get_existing_module_names():
19
- raise ValueError(f"Module already exists: {ctx.input.module}")
20
-
21
-
22
- scaffold_my_app_name_module = Scaffolder(
23
- name="scaffold-my-app-name-module",
24
- input=new_module_input,
25
- source_path=os.path.join(os.path.dirname(__file__), "module_template"),
26
- render_source_path=False,
27
- destination_path=lambda ctx: os.path.join(
28
- APP_DIR,
29
- "module",
30
- to_snake_case(ctx.input.module),
31
- ),
32
- transform_content={
33
- "module_template": "{to_snake_case(ctx.input.module)}",
34
- "MY_MODULE_NAME": "{to_snake_case(ctx.input.module).upper()}",
35
- },
36
- retries=0,
37
- upstream=validate_create_my_app_name_module,
38
- )
39
-
40
-
41
- @make_task(
42
- name="register-my-app-name-module-config",
43
- input=new_module_input,
44
- upstream=validate_create_my_app_name_module,
45
- retries=0,
46
- )
47
- async def register_my_app_name_module_config(ctx: AnyContext):
48
- """Registering module to config.py"""
49
- existing_module_names = get_existing_module_names()
50
- module_port = 3000 + len(
51
- [
52
- module_name
53
- for module_name in existing_module_names
54
- if module_name != to_snake_case(ctx.input.module)
55
- ]
56
- )
57
- module_base_url = f"http://localhost:{module_port}"
58
- config_file_name = os.path.join(APP_DIR, "config.py")
59
- upper_module_name = to_snake_case(ctx.input.module).upper()
60
- config_name = f"APP_{upper_module_name}_BASE_URL"
61
- env_name = f"MY_APP_NAME_{upper_module_name}_BASE_URL"
62
- # TODO: check before write
63
- with open(config_file_name, "a") as f:
64
- f.write(f'{config_name} = os.getenv("{env_name}", "{module_base_url}")\n')
65
-
66
-
67
- @make_task(
68
- name="register-my-app-name-module",
69
- input=new_module_input,
70
- upstream=validate_create_my_app_name_module,
71
- retries=0,
72
- )
73
- async def register_my_app_name_module(ctx: AnyContext):
74
- """Registering module to application's main.py"""
75
- app_main_file_name = os.path.join(APP_DIR, "main.py")
76
- module_name = to_snake_case(ctx.input.module)
77
- import_code = f"from fastapp_template.module.{module_name} import route as {module_name}_route" # noqa
78
- assert_code = f"assert {module_name}_route"
79
- with open(app_main_file_name, "r") as f:
80
- code = f.read()
81
- new_code = "\n".join([import_code, code.strip(), assert_code, ""])
82
- # TODO: check before write
83
- with open(app_main_file_name, "w") as f:
84
- f.write(new_code)
85
-
86
-
87
- @make_task(
88
- name="register-my-app-name-module-runner",
89
- input=new_module_input,
90
- upstream=validate_create_my_app_name_module,
91
- retries=0,
92
- )
93
- async def register_my_app_name_module_runner(ctx: AnyContext):
94
- """Registering module to _zrb's main.py"""
95
- task_main_file_name = os.path.join(APP_DIR, "_zrb", "main.py")
96
- existing_module_names = get_existing_module_names()
97
- module_port = 3001 + len(
98
- [
99
- module_name
100
- for module_name in existing_module_names
101
- if module_name != to_snake_case(ctx.input.module)
102
- ]
103
- )
104
- module_snake_name = to_snake_case(ctx.input.module)
105
- module_kebab_name = to_kebab_case(ctx.input.module)
106
- module_pascal_name = to_pascal_case(ctx.input.module)
107
- with open(os.path.join(os.path.dirname(__file__), "run_module.template.py")) as f:
108
- module_runner_code = (
109
- f.read()
110
- .replace("my_module", module_snake_name)
111
- .replace("my-module", module_kebab_name)
112
- .replace("My Module", module_pascal_name)
113
- .replace("3000", f"{module_port}")
114
- )
115
- with open(task_main_file_name, "r") as f:
116
- code = f.read()
117
- new_code = "\n".join([code.strip(), "", module_runner_code, ""])
118
- # TODO: check before write
119
- with open(task_main_file_name, "w") as f:
120
- f.write(new_code)
121
-
122
-
123
- create_my_app_name_module = app_create_group.add_task(
124
- Task(
125
- name="create-my-app-name-module",
126
- description="🧩 Create new module on My App Name",
127
- retries=0,
128
- ),
129
- alias="module",
130
- )
131
- create_my_app_name_module << [
132
- scaffold_my_app_name_module,
133
- register_my_app_name_module,
134
- register_my_app_name_module_config,
135
- register_my_app_name_module_runner,
136
- ]
@@ -1,27 +0,0 @@
1
- from abc import ABC, abstractmethod
2
-
3
- from fastapp_template.schema.user import UserCreate, UserResponse, UserUpdate
4
-
5
-
6
- class BaseClient(ABC):
7
- @abstractmethod
8
- async def get_user_by_id(self, user_id: str) -> UserResponse:
9
- pass
10
-
11
- @abstractmethod
12
- async def get_all_users(self) -> list[UserResponse]:
13
- pass
14
-
15
- @abstractmethod
16
- async def create_user(
17
- self, data: UserCreate | list[UserCreate]
18
- ) -> UserResponse | list[UserResponse]:
19
- pass
20
-
21
- @abstractmethod
22
- async def update_user(self, user_id: str, data: UserUpdate) -> UserResponse:
23
- pass
24
-
25
- @abstractmethod
26
- async def delete_user(self, user_id: str) -> UserResponse:
27
- pass
@@ -1,6 +0,0 @@
1
- from fastapp_template.config import APP_MY_MODULE_NAME_BASE_URL
2
- from fastapp_template.module.module_template.client.any_client import BaseClient
3
-
4
-
5
- class APIClient(BaseClient):
6
- pass
@@ -1,6 +0,0 @@
1
- from fastapp_template.module.module_template.client.any_client import BaseClient
2
- from fastapp_template.module.module_template.service.user.usecase import user_usecase
3
-
4
-
5
- class DirectClient(BaseClient):
6
- pass
@@ -1,9 +0,0 @@
1
- from fastapp_template.config import APP_COMMUNICATION
2
- from fastapp_template.module.module_template.client.any_client import BaseClient
3
- from fastapp_template.module.module_template.client.api_client import APIClient
4
- from fastapp_template.module.module_template.client.direct_client import DirectClient
5
-
6
- if APP_COMMUNICATION == "direct":
7
- client: BaseClient = DirectClient()
8
- elif APP_COMMUNICATION == "api":
9
- client: BaseClient = APIClient()
@@ -1,19 +0,0 @@
1
- from fastapp_template.common.app import app
2
- from fastapp_template.common.schema import BasicResponse
3
- from fastapp_template.config import APP_MODE, APP_MODULES
4
-
5
- if APP_MODE == "microservices" and "auth" in APP_MODULES:
6
-
7
- if APP_MODE == "microservices" and (
8
- len(APP_MODULES) > 0 and APP_MODULES[0] == "auth"
9
- ):
10
-
11
- @app.api_route("/health", methods=["GET", "HEAD"], response_model=BasicResponse)
12
- async def health():
13
- return BasicResponse(message="ok")
14
-
15
- @app.api_route(
16
- "/readiness", methods=["GET", "HEAD"], response_model=BasicResponse
17
- )
18
- async def readiness():
19
- return BasicResponse(message="ok")
@@ -1,7 +0,0 @@
1
- from fastapp_template.common.app import app
2
- from fastapp_template.module.auth import route as auth_route
3
- from fastapp_template.module.gateway import route as gateway_route
4
-
5
- assert app
6
- assert gateway_route
7
- assert auth_route
@@ -1,3 +0,0 @@
1
- from fastapp_template.module.auth import migration as auth_migration
2
-
3
- assert auth_migration
@@ -1,7 +0,0 @@
1
- from fastapp_template.config import APP_AUTH_BASE_URL
2
- from fastapp_template.module.auth.client.any_client import BaseClient
3
- from fastapp_template.module.auth.service.user.user_usecase import user_usecase
4
-
5
-
6
- class APIClient(user_usecase.as_api_client(base_url=APP_AUTH_BASE_URL), BaseClient):
7
- pass
@@ -1,6 +0,0 @@
1
- from fastapp_template.module.auth.client.any_client import BaseClient
2
- from fastapp_template.module.auth.service.user.user_usecase import user_usecase
3
-
4
-
5
- class DirectClient(user_usecase.as_direct_client(), BaseClient):
6
- pass
@@ -1,9 +0,0 @@
1
- from fastapp_template.config import APP_COMMUNICATION
2
- from fastapp_template.module.auth.client.any_client import BaseClient
3
- from fastapp_template.module.auth.client.api_client import APIClient
4
- from fastapp_template.module.auth.client.direct_client import DirectClient
5
-
6
- if APP_COMMUNICATION == "direct":
7
- client: BaseClient = DirectClient()
8
- elif APP_COMMUNICATION == "api":
9
- client: BaseClient = APIClient()
@@ -1,37 +0,0 @@
1
- """Add user table
2
-
3
- Revision ID: 3093c7336477
4
- Revises:
5
- Create Date: 2024-11-20 05:57:01.684118
6
-
7
- """
8
-
9
- from typing import Sequence, Union
10
-
11
- import sqlalchemy as sa
12
- import sqlmodel
13
- from alembic import op
14
-
15
- # revision identifiers, used by Alembic.
16
- revision: str = "3093c7336477"
17
- down_revision: Union[str, None] = None
18
- branch_labels: Union[str, Sequence[str], None] = None
19
- depends_on: Union[str, Sequence[str], None] = None
20
-
21
-
22
- def upgrade() -> None:
23
- # ### commands auto generated by Alembic - please adjust! ###
24
- op.create_table(
25
- "user",
26
- sa.Column("id", sqlmodel.sql.sqltypes.AutoString(), nullable=False),
27
- sa.Column("username", sqlmodel.sql.sqltypes.AutoString(), nullable=False),
28
- sa.Column("password", sqlmodel.sql.sqltypes.AutoString(), nullable=False),
29
- sa.PrimaryKeyConstraint("id"),
30
- )
31
- # ### end Alembic commands ###
32
-
33
-
34
- def downgrade() -> None:
35
- # ### commands auto generated by Alembic - please adjust! ###
36
- op.drop_table("user")
37
- # ### end Alembic commands ###
@@ -1,22 +0,0 @@
1
- from fastapp_template.common.app import app
2
- from fastapp_template.common.schema import BasicResponse
3
- from fastapp_template.config import APP_MODE, APP_MODULES
4
- from fastapp_template.module.auth.service.user.user_usecase import user_usecase
5
-
6
- if APP_MODE == "microservices" and "auth" in APP_MODULES:
7
-
8
- if APP_MODE == "microservices" and (
9
- len(APP_MODULES) > 0 and APP_MODULES[0] == "auth"
10
- ):
11
-
12
- @app.api_route("/health", methods=["GET", "HEAD"], response_model=BasicResponse)
13
- async def health():
14
- return BasicResponse(message="ok")
15
-
16
- @app.api_route(
17
- "/readiness", methods=["GET", "HEAD"], response_model=BasicResponse
18
- )
19
- async def readiness():
20
- return BasicResponse(message="ok")
21
-
22
- user_usecase.serve_route(app)
@@ -1,13 +0,0 @@
1
- from fastapp_template.common.db_engine import engine
2
- from fastapp_template.config import APP_REPOSITORY_TYPE
3
- from fastapp_template.module.auth.service.user.repository.user_db_repository import (
4
- UserDBRepository,
5
- )
6
- from fastapp_template.module.auth.service.user.repository.user_repository import (
7
- UserRepository,
8
- )
9
-
10
- if APP_REPOSITORY_TYPE == "db":
11
- user_repository: UserRepository = UserDBRepository(engine)
12
- else:
13
- user_repository: UserRepository = None
@@ -1,34 +0,0 @@
1
- from abc import ABC, abstractmethod
2
-
3
- from fastapp_template.schema.user import User, UserCreate, UserResponse, UserUpdate
4
-
5
-
6
- class UserRepository(ABC):
7
-
8
- @abstractmethod
9
- async def create(self, user_data: UserCreate) -> UserResponse:
10
- pass
11
-
12
- @abstractmethod
13
- async def get_by_id(self, user_id: str) -> User:
14
- pass
15
-
16
- @abstractmethod
17
- async def get_all(self) -> list[User]:
18
- pass
19
-
20
- @abstractmethod
21
- async def update(self, user_id: str, user_data: UserUpdate) -> User:
22
- pass
23
-
24
- @abstractmethod
25
- async def delete(self, user_id: str) -> User:
26
- pass
27
-
28
- @abstractmethod
29
- async def create_bulk(self, user_data_list: list[UserCreate]) -> list[UserResponse]:
30
- pass
31
-
32
- @abstractmethod
33
- async def get_by_credentials(self, username: str, password: str) -> UserResponse:
34
- pass
@@ -1,27 +0,0 @@
1
- from fastapp_template.common.app import app
2
- from fastapp_template.common.schema import BasicResponse
3
- from fastapp_template.config import APP_MODE, APP_MODULES
4
- from fastapp_template.module.auth.client.factory import client as auth_client
5
- from fastapp_template.schema.user import UserCreate, UserResponse
6
-
7
- if APP_MODE == "monolith" or "gateway" in APP_MODULES:
8
-
9
- if APP_MODE == "monolith" or (len(APP_MODULES) > 0 and APP_MODULES[0] == "gateway"):
10
-
11
- @app.api_route("/health", methods=["GET", "HEAD"], response_model=BasicResponse)
12
- async def health():
13
- return BasicResponse(message="ok")
14
-
15
- @app.api_route(
16
- "/readiness", methods=["GET", "HEAD"], response_model=BasicResponse
17
- )
18
- async def readiness():
19
- return BasicResponse(message="ok")
20
-
21
- @app.get("/api/v1/users", response_model=list[UserResponse])
22
- async def auth_get_all_users() -> UserResponse:
23
- return await auth_client.get_all_users()
24
-
25
- @app.post("/api/v1/users", response_model=UserResponse | list[UserResponse])
26
- async def auth_create_user(data: UserCreate | list[UserCreate]):
27
- return await auth_client.create_user(data)