zrb 1.0.0a21__py3-none-any.whl → 1.0.0b3__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 (195) hide show
  1. zrb/__init__.py +2 -1
  2. zrb/__main__.py +3 -3
  3. zrb/builtin/__init__.py +3 -0
  4. zrb/builtin/group.py +1 -0
  5. zrb/builtin/llm/llm_chat.py +5 -3
  6. zrb/builtin/llm/tool/cli.py +1 -1
  7. zrb/builtin/llm/tool/rag.py +108 -145
  8. zrb/builtin/llm/tool/web.py +1 -1
  9. zrb/builtin/project/add/fastapp/fastapp_task.py +2 -0
  10. zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/_zrb/config.py +5 -2
  11. zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/_zrb/entity/add_entity_task.py +80 -20
  12. zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/_zrb/entity/add_entity_util.py +150 -42
  13. zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/_zrb/entity/template/app_template/module/my_module/service/my_entity/my_entity_service.py +113 -0
  14. zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/_zrb/entity/template/app_template/module/my_module/service/my_entity/my_entity_service_factory.py +9 -0
  15. zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/_zrb/entity/template/app_template/module/my_module/service/my_entity/repository/my_entity_db_repository.py +0 -10
  16. zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/_zrb/entity/template/app_template/module/my_module/service/my_entity/repository/my_entity_repository.py +37 -16
  17. zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/_zrb/entity/template/app_template/module/my_module/service/my_entity/repository/{factory.py → my_entity_repository_factory.py} +2 -2
  18. zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/_zrb/entity/template/app_template/schema/my_entity.py +16 -6
  19. zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/_zrb/entity/template/client_method.py +57 -0
  20. zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/_zrb/entity/template/gateway_subroute.py +74 -0
  21. zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/_zrb/format_task.py +1 -1
  22. zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/_zrb/input.py +13 -0
  23. zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/_zrb/module/add_module_task.py +23 -0
  24. zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/_zrb/module/add_module_util.py +42 -0
  25. zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/_zrb/module/template/app_template/module/gateway/subroute/my_module.py +7 -0
  26. zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/_zrb/module/template/app_template/module/my_module/client/my_module_api_client.py +6 -0
  27. zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/_zrb/module/template/app_template/module/my_module/client/{any_client.py → my_module_client.py} +1 -1
  28. zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/_zrb/module/template/app_template/module/my_module/client/my_module_client_factory.py +11 -0
  29. zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/_zrb/module/template/app_template/module/my_module/client/my_module_direct_client.py +5 -0
  30. zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/_zrb/module/template/app_template/module/my_module/route.py +11 -11
  31. zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/_zrb/module/template/module_task_definition.py +2 -2
  32. zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/_zrb/task.py +8 -8
  33. zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/_zrb/util.py +47 -20
  34. zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/common/app_factory.py +29 -0
  35. zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/common/base_db_repository.py +230 -102
  36. zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/common/base_service.py +236 -0
  37. zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/common/{db_engine.py → db_engine_factory.py} +1 -1
  38. zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/common/error.py +12 -0
  39. zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/common/logger_factory.py +10 -0
  40. zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/common/parser_factory.py +7 -0
  41. zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/common/util/app.py +47 -0
  42. zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/common/util/parser.py +105 -0
  43. zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/common/util/user_agent.py +58 -0
  44. zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/common/util/view.py +37 -0
  45. zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/config.py +37 -1
  46. zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/main.py +1 -1
  47. zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/module/auth/client/auth_api_client.py +16 -0
  48. zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/module/auth/client/auth_client.py +169 -0
  49. zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/module/auth/client/auth_client_factory.py +9 -0
  50. zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/module/auth/client/auth_direct_client.py +15 -0
  51. zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/module/auth/migration/versions/3093c7336477_add_auth_tables.py +160 -0
  52. zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/module/auth/migration_metadata.py +18 -1
  53. zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/module/auth/route.py +7 -3
  54. zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/module/auth/service/permission/permission_service.py +117 -0
  55. zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/module/auth/service/permission/permission_service_factory.py +11 -0
  56. zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/module/auth/service/permission/repository/permission_db_repository.py +26 -0
  57. zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/module/auth/service/permission/repository/permission_repository.py +61 -0
  58. zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/module/auth/service/permission/repository/permission_repository_factory.py +13 -0
  59. zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/module/auth/service/role/repository/role_db_repository.py +89 -0
  60. zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/module/auth/service/role/repository/role_repository.py +67 -0
  61. zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/module/auth/service/role/repository/role_repository_factory.py +13 -0
  62. zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/module/auth/service/role/role_service.py +137 -0
  63. zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/module/auth/service/role/role_service_factory.py +7 -0
  64. zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/module/auth/service/user/repository/user_db_repository.py +179 -12
  65. zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/module/auth/service/user/repository/user_repository.py +67 -17
  66. zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/module/auth/service/user/repository/user_repository_factory.py +2 -2
  67. zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/module/auth/service/user/user_service.py +127 -0
  68. zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/module/auth/service/user/user_service_factory.py +7 -0
  69. zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/module/gateway/route.py +43 -14
  70. zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/module/gateway/subroute/auth.py +200 -30
  71. zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/module/gateway/util/view.py +74 -0
  72. zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/module/gateway/view/content/error.html +6 -0
  73. zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/module/gateway/view/content/homepage.html +6 -0
  74. zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/module/gateway/view/static/images/android-chrome-192x192.png +0 -0
  75. zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/module/gateway/view/static/images/android-chrome-512x512.png +0 -0
  76. zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/module/gateway/view/static/images/favicon-32x32.png +0 -0
  77. zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/module/gateway/view/static/pico-css/pico.amber.min.css +4 -0
  78. zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/module/gateway/view/static/pico-css/pico.blue.min.css +4 -0
  79. zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/module/gateway/view/static/pico-css/pico.cyan.min.css +4 -0
  80. zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/module/gateway/view/static/pico-css/pico.fuchsia.min.css +4 -0
  81. zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/module/gateway/view/static/pico-css/pico.green.min.css +4 -0
  82. zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/module/gateway/view/static/pico-css/pico.grey.min.css +4 -0
  83. zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/module/gateway/view/static/pico-css/pico.indigo.min.css +4 -0
  84. zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/module/gateway/view/static/pico-css/pico.jade.min.css +4 -0
  85. zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/module/gateway/view/static/pico-css/pico.lime.min.css +4 -0
  86. zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/module/gateway/view/static/pico-css/pico.min.css +4 -0
  87. zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/module/gateway/view/static/pico-css/pico.orange.min.css +4 -0
  88. zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/module/gateway/view/static/pico-css/pico.pink.min.css +4 -0
  89. zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/module/gateway/view/static/pico-css/pico.pumpkin.min.css +4 -0
  90. zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/module/gateway/view/static/pico-css/pico.purple.min.css +4 -0
  91. zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/module/gateway/view/static/pico-css/pico.red.min.css +4 -0
  92. zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/module/gateway/view/static/pico-css/pico.sand.min.css +4 -0
  93. zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/module/gateway/view/static/pico-css/pico.slate.min.css +4 -0
  94. zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/module/gateway/view/static/pico-css/pico.violet.min.css +4 -0
  95. zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/module/gateway/view/static/pico-css/pico.yellow.min.css +4 -0
  96. zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/module/gateway/view/static/pico-css/pico.zinc.min.css +4 -0
  97. zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/module/gateway/view/template/default.html +34 -0
  98. zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/requirements.txt +1 -0
  99. zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/schema/permission.py +17 -5
  100. zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/schema/role.py +78 -4
  101. zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/schema/session.py +48 -0
  102. zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/schema/user.py +69 -5
  103. zrb/builtin/python.py +1 -1
  104. zrb/builtin/random.py +61 -0
  105. zrb/cmd/cmd_val.py +6 -5
  106. zrb/config.py +14 -1
  107. zrb/content_transformer/any_content_transformer.py +7 -0
  108. zrb/content_transformer/content_transformer.py +6 -0
  109. zrb/runner/cli.py +14 -7
  110. zrb/runner/web_app.py +28 -280
  111. zrb/runner/web_config/config.py +91 -0
  112. zrb/runner/web_config/config_factory.py +26 -0
  113. zrb/runner/web_route/docs_route.py +17 -0
  114. zrb/runner/web_route/error_page/serve_default_404.py +28 -0
  115. zrb/runner/{web_controller/error_page/controller.py → web_route/error_page/show_error_page.py} +4 -3
  116. zrb/runner/{web_controller → web_route}/error_page/view.html +5 -0
  117. zrb/runner/web_route/home_page/home_page_route.py +51 -0
  118. zrb/runner/web_route/login_api_route.py +31 -0
  119. zrb/runner/web_route/login_page/login_page_route.py +39 -0
  120. zrb/runner/web_route/logout_api_route.py +18 -0
  121. zrb/runner/web_route/logout_page/logout_page_route.py +40 -0
  122. zrb/runner/{web_controller/group_info_page/controller.py → web_route/node_page/group/show_group_page.py} +3 -3
  123. zrb/runner/web_route/node_page/node_page_route.py +50 -0
  124. zrb/runner/{web_controller/session_page/controller.py → web_route/node_page/task/show_task_page.py} +3 -3
  125. zrb/runner/web_route/refresh_token_api_route.py +38 -0
  126. zrb/runner/{web_controller/static → web_route/static/resources}/session/current-session.js +5 -2
  127. zrb/runner/{web_controller/static → web_route/static/resources}/session/event.js +5 -2
  128. zrb/runner/web_route/static/static_route.py +44 -0
  129. zrb/runner/web_route/task_input_api_route.py +47 -0
  130. zrb/runner/web_route/task_session_api_route.py +147 -0
  131. zrb/runner/web_schema/session.py +5 -0
  132. zrb/runner/web_schema/token.py +11 -0
  133. zrb/runner/web_schema/user.py +32 -0
  134. zrb/runner/web_util/cookie.py +29 -0
  135. zrb/runner/{web_util.py → web_util/html.py} +1 -23
  136. zrb/runner/web_util/token.py +72 -0
  137. zrb/runner/web_util/user.py +63 -0
  138. zrb/session/session.py +6 -4
  139. zrb/session_state_logger/{default_session_state_logger.py → session_state_logger_factory.py} +1 -1
  140. zrb/task/base_task.py +56 -8
  141. zrb/task/base_trigger.py +2 -0
  142. zrb/task/cmd_task.py +9 -5
  143. zrb/task/http_check.py +2 -0
  144. zrb/task/llm_task.py +184 -71
  145. zrb/task/make_task.py +2 -0
  146. zrb/task/rsync_task.py +2 -0
  147. zrb/task/scaffolder.py +8 -5
  148. zrb/task/scheduler.py +2 -0
  149. zrb/task/tcp_check.py +2 -0
  150. zrb/task_status/task_status.py +4 -3
  151. zrb/util/cmd/command.py +1 -0
  152. zrb/util/file.py +7 -1
  153. zrb/util/llm/tool.py +3 -7
  154. {zrb-1.0.0a21.dist-info → zrb-1.0.0b3.dist-info}/METADATA +2 -1
  155. zrb-1.0.0b3.dist-info/RECORD +307 -0
  156. zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/_zrb/entity/template/any_client_method.py +0 -27
  157. zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/_zrb/entity/template/app_template/module/my_module/service/my_entity/my_entity_usecase.py +0 -65
  158. zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/_zrb/module/template/app_template/module/my_module/client/api_client.py +0 -6
  159. zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/_zrb/module/template/app_template/module/my_module/client/direct_client.py +0 -6
  160. zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/_zrb/module/template/app_template/module/my_module/client/factory.py +0 -9
  161. zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/common/app.py +0 -20
  162. zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/common/base_usecase.py +0 -245
  163. zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/module/auth/client/any_client.py +0 -33
  164. zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/module/auth/client/api_client.py +0 -7
  165. zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/module/auth/client/direct_client.py +0 -6
  166. zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/module/auth/client/factory.py +0 -9
  167. zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/module/auth/migration/versions/3093c7336477_add_user_table.py +0 -37
  168. zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/module/auth/service/user/user_usecase.py +0 -53
  169. zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/module/auth/service/user/user_usecase_factory.py +0 -6
  170. zrb/runner/web_config.py +0 -274
  171. zrb/runner/web_controller/home_page/controller.py +0 -33
  172. zrb/runner/web_controller/login_page/controller.py +0 -25
  173. zrb/runner/web_controller/logout_page/controller.py +0 -26
  174. zrb-1.0.0a21.dist-info/RECORD +0 -244
  175. /zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/_zrb/column/{create_column_task.py → add_column_task.py} +0 -0
  176. /zrb/{runner/web_controller → builtin/project/add/fastapp/fastapp_template/my_app_name/module/auth/service/permission}/__init__.py +0 -0
  177. /zrb/{runner/web_controller/group_info_page → builtin/project/add/fastapp/fastapp_template/my_app_name/module/auth/service/role}/__init__.py +0 -0
  178. /zrb/runner/{web_controller/home_page → web_route}/__init__.py +0 -0
  179. /zrb/runner/{web_controller/session_page → web_route/home_page}/__init__.py +0 -0
  180. /zrb/runner/{web_controller → web_route}/home_page/view.html +0 -0
  181. /zrb/runner/{web_controller → web_route}/login_page/view.html +0 -0
  182. /zrb/runner/{web_controller → web_route}/logout_page/view.html +0 -0
  183. /zrb/runner/{web_controller/group_info_page → web_route/node_page/group}/view.html +0 -0
  184. /zrb/runner/{web_controller/session_page → web_route/node_page/task}/partial/input.html +0 -0
  185. /zrb/runner/{web_controller/session_page → web_route/node_page/task}/view.html +0 -0
  186. /zrb/runner/{refresh-token.template.js → web_route/static/refresh-token.template.js} +0 -0
  187. /zrb/runner/{web_controller/static → web_route/static/resources}/common.css +0 -0
  188. /zrb/runner/{web_controller/static → web_route/static/resources}/favicon-32x32.png +0 -0
  189. /zrb/runner/{web_controller/static → web_route/static/resources}/login/event.js +0 -0
  190. /zrb/runner/{web_controller/static → web_route/static/resources}/logout/event.js +0 -0
  191. /zrb/runner/{web_controller/static → web_route/static/resources}/pico.min.css +0 -0
  192. /zrb/runner/{web_controller/static → web_route/static/resources}/session/common-util.js +0 -0
  193. /zrb/runner/{web_controller/static → web_route/static/resources}/session/past-session.js +0 -0
  194. {zrb-1.0.0a21.dist-info → zrb-1.0.0b3.dist-info}/WHEEL +0 -0
  195. {zrb-1.0.0a21.dist-info → zrb-1.0.0b3.dist-info}/entry_points.txt +0 -0
@@ -0,0 +1,74 @@
1
+ # MyEntity routes
2
+
3
+
4
+ @app.get("/api/v1/my-entities", response_model=MultipleMyEntityResponse)
5
+ async def get_my_entities(
6
+ page: int = 1,
7
+ page_size: int = 10,
8
+ sort: str | None = None,
9
+ filter: str | None = None,
10
+ ) -> MultipleMyEntityResponse:
11
+ return await my_module_client.get_my_entities(
12
+ page=page, page_size=page_size, sort=sort, filter=filter
13
+ )
14
+
15
+
16
+ @app.get("/api/v1/my-entities/{my_entity_id}", response_model=MyEntityResponse)
17
+ async def get_my_entity_by_id(my_entity_id: str) -> MyEntityResponse:
18
+ return await my_module_client.get_my_entity_by_id(my_entity_id)
19
+
20
+
21
+ @app.post(
22
+ "/api/v1/my-entities/bulk",
23
+ response_model=list[MyEntityResponse],
24
+ )
25
+ async def create_my_entity_bulk(data: list[MyEntityCreate]):
26
+ return await my_module_client.create_my_entity_bulk(
27
+ [row.with_audit(created_by="system") for row in data]
28
+ )
29
+
30
+
31
+ @app.post(
32
+ "/api/v1/my-entities",
33
+ response_model=MyEntityResponse,
34
+ )
35
+ async def create_my_entity(data: MyEntityCreate):
36
+ return await my_module_client.create_my_entity(data.with_audit(created_by="system"))
37
+
38
+
39
+ @app.put(
40
+ "/api/v1/my-entities/bulk",
41
+ response_model=list[MyEntityResponse],
42
+ )
43
+ async def update_my_entity_bulk(my_entity_ids: list[str], data: MyEntityUpdate):
44
+ return await my_module_client.update_my_entity_bulk(
45
+ my_entity_ids, data.with_audit(updated_by="system")
46
+ )
47
+
48
+
49
+ @app.put(
50
+ "/api/v1/my-entities/{my_entity_id}",
51
+ response_model=MyEntityResponse,
52
+ )
53
+ async def update_my_entity(my_entity_id: str, data: MyEntityUpdate):
54
+ return await my_module_client.update_my_entity(
55
+ my_entity_id, data.with_audit(updated_by="system")
56
+ )
57
+
58
+
59
+ @app.delete(
60
+ "/api/v1/my-entities/bulk",
61
+ response_model=list[MyEntityResponse],
62
+ )
63
+ async def delete_my_entity_bulk(my_entity_ids: list[str]):
64
+ return await my_module_client.delete_my_entity_bulk(
65
+ my_entity_ids, deleted_by="system"
66
+ )
67
+
68
+
69
+ @app.delete(
70
+ "/api/v1/my-entities/{my_entity_id}",
71
+ response_model=MyEntityResponse,
72
+ )
73
+ async def delete_my_entity(my_entity_id: str):
74
+ return await my_module_client.delete_my_entity(my_entity_id, deleted_by="system")
@@ -6,7 +6,7 @@ from zrb.task.cmd_task import CmdTask
6
6
  format_my_app_name_code = app_group.add_task(
7
7
  CmdTask(
8
8
  name="format-my-app-name-code",
9
- description="✏️ Format Python code",
9
+ description=" Format Python code",
10
10
  cmd=[
11
11
  "isort . --profile black --force-grid-wrap 0",
12
12
  "black .",
@@ -38,3 +38,16 @@ new_entity_column_input = StrInput(
38
38
  prompt="New entity's column name",
39
39
  default_str="name",
40
40
  )
41
+
42
+ new_column_input = StrInput(
43
+ name="column",
44
+ description="Column name",
45
+ prompt="New column name",
46
+ )
47
+
48
+ new_column_type_input = OptionInput(
49
+ name="type",
50
+ description="Column type",
51
+ prompt="Column type",
52
+ options=["str", "int", "float", "bool", "datetime", "date"],
53
+ )
@@ -9,11 +9,14 @@ from my_app_name._zrb.module.add_module_util import (
9
9
  is_app_main_file,
10
10
  is_app_zrb_config_file,
11
11
  is_app_zrb_task_file,
12
+ is_gateway_module_subroute_file,
13
+ is_gateway_route_file,
12
14
  is_in_module_dir,
13
15
  update_app_config_file,
14
16
  update_app_main_file,
15
17
  update_app_zrb_config_file,
16
18
  update_app_zrb_task_file,
19
+ update_gateway_route_file,
17
20
  )
18
21
  from my_app_name._zrb.util import get_existing_module_names
19
22
 
@@ -42,32 +45,52 @@ scaffold_my_app_name_module = Scaffolder(
42
45
  transform_content=[
43
46
  # Common transformation (my_app_name/module/snake_module_name)
44
47
  ContentTransformer(
48
+ name="transform-module-dir",
45
49
  match=is_in_module_dir,
46
50
  transform={
47
51
  "MY_MODULE": "{to_snake_case(ctx.input.module).upper()}",
48
52
  "my_module": "{to_snake_case(ctx.input.module)}",
53
+ "MyModule": "{to_pascal_case(ctx.input.module)}",
54
+ },
55
+ ),
56
+ # Gateway's module subroute (my_app_name/module/gateway/subroute/snake_module_name.py)
57
+ ContentTransformer(
58
+ name="transform-gateway-subroute",
59
+ match=is_gateway_module_subroute_file,
60
+ transform={
61
+ "my_module": "{to_snake_case(ctx.input.module)}",
49
62
  },
50
63
  ),
51
64
  # Register module config to my_app_name/config.py
52
65
  ContentTransformer(
66
+ name="transform-app-config",
53
67
  match=is_app_config_file,
54
68
  transform=update_app_config_file,
55
69
  ),
56
70
  # Register module route to my_app_name/main.py
57
71
  ContentTransformer(
72
+ name="transform-app-main",
58
73
  match=is_app_main_file,
59
74
  transform=update_app_main_file,
60
75
  ),
61
76
  # Register module's tasks to my_app_name/_zrb/task.py
62
77
  ContentTransformer(
78
+ name="transform-zrb-task",
63
79
  match=is_app_zrb_task_file,
64
80
  transform=update_app_zrb_task_file,
65
81
  ),
66
82
  # Register module's base url to my_app_name/_zrb/config.py
67
83
  ContentTransformer(
84
+ name="transform-zrb-config",
68
85
  match=is_app_zrb_config_file,
69
86
  transform=update_app_zrb_config_file,
70
87
  ),
88
+ # Register module's subroute to my_app_name/gateway/route.py
89
+ ContentTransformer(
90
+ name="transform-gateway-route",
91
+ match=is_gateway_route_file,
92
+ transform=update_gateway_route_file,
93
+ ),
71
94
  ],
72
95
  retries=0,
73
96
  upstream=validate_create_my_app_name_module,
@@ -4,6 +4,7 @@ from my_app_name._zrb.config import APP_DIR
4
4
  from my_app_name._zrb.util import get_existing_module_names
5
5
 
6
6
  from zrb.context.any_context import AnyContext
7
+ from zrb.util.codemod.append_code_to_function import append_code_to_function
7
8
  from zrb.util.codemod.append_key_to_dict import append_key_to_dict
8
9
  from zrb.util.file import read_file, write_file
9
10
  from zrb.util.string.conversion import to_kebab_case, to_pascal_case, to_snake_case
@@ -17,6 +18,10 @@ def is_app_main_file(ctx: AnyContext, file_path: str) -> bool:
17
18
  return file_path == os.path.join(APP_DIR, "main.py")
18
19
 
19
20
 
21
+ def is_gateway_route_file(ctx: AnyContext, file_path: str) -> bool:
22
+ return file_path == os.path.join(APP_DIR, "module", "gateway", "route.py")
23
+
24
+
20
25
  def is_app_zrb_task_file(ctx: AnyContext, file_path: str) -> bool:
21
26
  return file_path == os.path.join(APP_DIR, "_zrb", "task.py")
22
27
 
@@ -31,6 +36,13 @@ def is_in_module_dir(ctx: AnyContext, file_path: str) -> bool:
31
36
  )
32
37
 
33
38
 
39
+ def is_gateway_module_subroute_file(ctx: AnyContext, file_path: str) -> bool:
40
+ module_subroute_file_name = f"{to_snake_case(ctx.input.module)}.py"
41
+ return file_path == os.path.join(
42
+ APP_DIR, "module", "gateway", "subroute", module_subroute_file_name
43
+ )
44
+
45
+
34
46
  def update_app_zrb_config_file(ctx: AnyContext, zrb_config_file_path: str):
35
47
  existing_zrb_config_code = read_file(zrb_config_file_path)
36
48
  module_name = ctx.input.module
@@ -152,3 +164,33 @@ def _get_new_module_config_code(existing_code: str, module_name: str) -> str | N
152
164
  if config_code in existing_code:
153
165
  return None
154
166
  return config_code
167
+
168
+
169
+ def update_gateway_route_file(ctx: AnyContext, gateway_route_file_path: str):
170
+ existing_gateway_route_code = read_file(gateway_route_file_path)
171
+ snake_module_name = to_snake_case(ctx.input.module)
172
+ write_file(
173
+ file_path=gateway_route_file_path,
174
+ content=[
175
+ _get_module_subroute_import(existing_gateway_route_code, ctx.input.module),
176
+ append_code_to_function(
177
+ original_code=existing_gateway_route_code,
178
+ function_name="serve_route",
179
+ new_code="\n".join(
180
+ [
181
+ f"# Serve {snake_module_name} route",
182
+ f"serve_{snake_module_name}_route(app)",
183
+ ]
184
+ ),
185
+ ),
186
+ ],
187
+ )
188
+
189
+
190
+ def _get_module_subroute_import(existing_code: str, module_name: str) -> str | None:
191
+ snake_module_name = to_snake_case(module_name)
192
+ import_module_path = f"my_app_name.module.gateway.subroute.{snake_module_name}"
193
+ import_code = f"from {import_module_path} import serve_{snake_module_name}_route"
194
+ if import_code in existing_code:
195
+ return None
196
+ return import_code
@@ -0,0 +1,7 @@
1
+ from fastapi import FastAPI
2
+
3
+
4
+ def serve_my_module_route(app: FastAPI):
5
+ """
6
+ Serving routes for my_module
7
+ """
@@ -0,0 +1,6 @@
1
+ from my_app_name.config import APP_MY_MODULE_BASE_URL
2
+ from my_app_name.module.my_module.client.my_module_client import MyModuleClient
3
+
4
+
5
+ class MyModuleAPIClient(MyModuleClient):
6
+ pass
@@ -1,7 +1,7 @@
1
1
  from abc import ABC, abstractmethod
2
2
 
3
3
 
4
- class AnyClient(ABC):
4
+ class MyModuleClient(ABC):
5
5
  """
6
6
  Defining client methods
7
7
  """
@@ -0,0 +1,11 @@
1
+ from my_app_name.config import APP_COMMUNICATION
2
+ from my_app_name.module.my_module.client.my_module_api_client import MyModuleAPIClient
3
+ from my_app_name.module.my_module.client.my_module_client import MyModuleClient
4
+ from my_app_name.module.my_module.client.my_module_direct_client import (
5
+ MyModuleDirectClient,
6
+ )
7
+
8
+ if APP_COMMUNICATION == "direct":
9
+ my_module_client: MyModuleClient = MyModuleDirectClient()
10
+ elif APP_COMMUNICATION == "api":
11
+ my_module_client: MyModuleClient = MyModuleAPIClient()
@@ -0,0 +1,5 @@
1
+ from my_app_name.module.my_module.client.my_module_client import MyModuleClient
2
+
3
+
4
+ class MyModuleDirectClient(MyModuleClient):
5
+ pass
@@ -1,10 +1,18 @@
1
1
  from fastapi import FastAPI
2
- from my_app_name.common.app import app
2
+ from my_app_name.common.app_factory import app
3
3
  from my_app_name.common.schema import BasicResponse
4
4
  from my_app_name.config import APP_MAIN_MODULE, APP_MODE, APP_MODULES
5
5
 
6
6
 
7
- def serve_health_check(app: FastAPI):
7
+ def serve_route(app: FastAPI):
8
+ if APP_MODE != "microservices" or "my_module" not in APP_MODULES:
9
+ return
10
+ if APP_MAIN_MODULE == "my_module":
11
+ _serve_health_check(app)
12
+ _serve_readiness_check(app)
13
+
14
+
15
+ def _serve_health_check(app: FastAPI):
8
16
  @app.api_route("/health", methods=["GET", "HEAD"], response_model=BasicResponse)
9
17
  async def health():
10
18
  """
@@ -13,7 +21,7 @@ def serve_health_check(app: FastAPI):
13
21
  return BasicResponse(message="ok")
14
22
 
15
23
 
16
- def serve_readiness_check(app: FastAPI):
24
+ def _serve_readiness_check(app: FastAPI):
17
25
  @app.api_route("/readiness", methods=["GET", "HEAD"], response_model=BasicResponse)
18
26
  async def readiness():
19
27
  """
@@ -22,12 +30,4 @@ def serve_readiness_check(app: FastAPI):
22
30
  return BasicResponse(message="ok")
23
31
 
24
32
 
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
33
  serve_route(app)
@@ -1,7 +1,7 @@
1
1
  # 🔐 Run/Migrate My Module ==========================================================
2
2
 
3
3
  run_my_module = app_run_group.add_task(
4
- run_microservice("my-module", 3000, "my_module"), alias="microservices-my_module"
4
+ run_microservice("my-module", 3000, "my_module"), alias="svc-my_module"
5
5
  )
6
6
  prepare_venv >> run_my_module >> run_microservices
7
7
 
@@ -17,7 +17,7 @@ prepare_venv >> migrate_monolith_my_module >> [migrate_monolith, run_monolith]
17
17
 
18
18
  migrate_microservices_my_module = app_migrate_group.add_task(
19
19
  migrate_module("my-module", "my_module", as_microservices=True),
20
- alias="microservices-my-module",
20
+ alias="svc-my-module",
21
21
  )
22
22
  (
23
23
  prepare_venv
@@ -1,7 +1,7 @@
1
1
  import os
2
2
 
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
3
+ from my_app_name._zrb.column.add_column_task import add_my_app_name_column
4
+ from my_app_name._zrb.config import ACTIVATE_VENV_SCRIPT, APP_DIR, MONOLITH_ENV_VARS
5
5
  from my_app_name._zrb.entity.add_entity_task import add_my_app_name_entity
6
6
  from my_app_name._zrb.format_task import format_my_app_name_code
7
7
  from my_app_name._zrb.group import (
@@ -13,7 +13,7 @@ from my_app_name._zrb.module.add_module_task import add_my_app_name_module
13
13
  from my_app_name._zrb.util import create_migration, migrate_module, run_microservice
14
14
  from my_app_name._zrb.venv_task import prepare_venv
15
15
 
16
- from zrb import CmdTask, Env, EnvFile, Task
16
+ from zrb import CmdTask, EnvFile, EnvMap, Task
17
17
 
18
18
  assert add_my_app_name_entity
19
19
  assert add_my_app_name_module
@@ -54,7 +54,7 @@ run_monolith = app_run_group.add_task(
54
54
  description="🗿 Run My App Name as a monolith",
55
55
  env=[
56
56
  EnvFile(path=os.path.join(APP_DIR, "template.env")),
57
- Env(name="MY_APP_NAME_MODE", default="monolith"),
57
+ EnvMap(vars=MONOLITH_ENV_VARS),
58
58
  ],
59
59
  cwd=APP_DIR,
60
60
  cmd=[
@@ -100,7 +100,7 @@ migrate_microservices >> migrate_all
100
100
  # 📡 Run/Migrate Gateway =======================================================
101
101
 
102
102
  run_gateway = app_run_group.add_task(
103
- run_microservice("gateway", 3001, "gateway"), alias="microservices-gateway"
103
+ run_microservice("gateway", 3001, "gateway"), alias="svc-gateway"
104
104
  )
105
105
  prepare_venv >> run_gateway >> run_microservices
106
106
 
@@ -114,14 +114,14 @@ prepare_venv >> migrate_monolith_gateway >> [migrate_monolith, run_monolith]
114
114
 
115
115
  migrate_microservices_gateway = app_migrate_group.add_task(
116
116
  migrate_module("gateway", "gateway", as_microservices=True),
117
- alias="microservices-gateway",
117
+ alias="svc-gateway",
118
118
  )
119
119
  prepare_venv >> migrate_microservices_gateway >> [migrate_microservices, run_gateway]
120
120
 
121
121
  # 🔐 Run/Migrate Auth ==========================================================
122
122
 
123
123
  run_auth = app_run_group.add_task(
124
- run_microservice("auth", 3002, "auth"), alias="microservices-auth"
124
+ run_microservice("auth", 3002, "auth"), alias="svc-auth"
125
125
  )
126
126
  prepare_venv >> run_auth >> run_microservices
127
127
 
@@ -134,6 +134,6 @@ migrate_monolith_auth = migrate_module("auth", "auth", as_microservices=False)
134
134
  prepare_venv >> migrate_monolith_auth >> [migrate_monolith, run_monolith]
135
135
 
136
136
  migrate_microservices_auth = app_migrate_group.add_task(
137
- migrate_module("auth", "auth", as_microservices=True), alias="microservices-auth"
137
+ migrate_module("auth", "auth", as_microservices=True), alias="svc-auth"
138
138
  )
139
139
  prepare_venv >> migrate_microservices_auth >> [migrate_microservices, run_auth]
@@ -1,4 +1,5 @@
1
1
  import os
2
+ import platform
2
3
 
3
4
  from my_app_name._zrb.config import (
4
5
  ACTIVATE_VENV_SCRIPT,
@@ -8,6 +9,7 @@ from my_app_name._zrb.config import (
8
9
  )
9
10
 
10
11
  from zrb import Cmd, CmdTask, EnvFile, EnvMap, StrInput, Task
12
+ from zrb.util.string.conversion import double_quote, to_snake_case
11
13
 
12
14
 
13
15
  def create_migration(name: str, module: str) -> Task:
@@ -20,19 +22,13 @@ def create_migration(name: str, module: str) -> Task:
20
22
  prompt="Migration message",
21
23
  allow_empty=False,
22
24
  ),
23
- env=[
24
- EnvFile(path=os.path.join(APP_DIR, "template.env")),
25
- EnvMap(
26
- vars={
27
- "APP_DB_URL": f"sqlite:///{APP_DIR}/.migration.{module}.db",
28
- "MY_APP_NAME_MODULES": f"{module}",
29
- }
30
- ),
31
- ],
25
+ env=EnvFile(path=os.path.join(APP_DIR, "template.env")),
32
26
  cwd=APP_DIR,
33
27
  cmd=[
34
28
  ACTIVATE_VENV_SCRIPT,
35
- f"cd {os.path.join(APP_DIR, 'module', module)}",
29
+ set_create_migration_db_url_env(module),
30
+ set_module_env(module),
31
+ cd_module_script(module),
36
32
  "alembic upgrade head",
37
33
  Cmd(
38
34
  "alembic revision --autogenerate -m {double_quote(ctx.input.message)}",
@@ -45,7 +41,11 @@ def create_migration(name: str, module: str) -> Task:
45
41
 
46
42
 
47
43
  def migrate_module(name: str, module: str, as_microservices: bool) -> Task:
48
- env_vars = MICROSERVICES_ENV_VARS if as_microservices else MONOLITH_ENV_VARS
44
+ env_vars = (
45
+ dict(MICROSERVICES_ENV_VARS) if as_microservices else dict(MONOLITH_ENV_VARS)
46
+ )
47
+ if as_microservices:
48
+ env_vars["MY_APP_NAME_MODULES"] = to_snake_case(module)
49
49
  return CmdTask(
50
50
  name=(
51
51
  f"migrate-my-app-name-{name}"
@@ -55,17 +55,12 @@ def migrate_module(name: str, module: str, as_microservices: bool) -> Task:
55
55
  description=f"🧩 Run My App Name {name.capitalize()} DB migration",
56
56
  env=[
57
57
  EnvFile(path=os.path.join(APP_DIR, "template.env")),
58
- EnvMap(
59
- vars={
60
- **env_vars,
61
- "MY_APP_NAME_MODULES": f"{module}",
62
- }
63
- ),
58
+ EnvMap(vars=env_vars),
64
59
  ],
65
60
  cwd=APP_DIR,
66
61
  cmd=[
67
62
  ACTIVATE_VENV_SCRIPT,
68
- f"cd {os.path.join(APP_DIR, 'module', module)}",
63
+ cd_module_script(module),
69
64
  "alembic upgrade head",
70
65
  ],
71
66
  render_cmd=False,
@@ -82,14 +77,14 @@ def run_microservice(name: str, port: int, module: str) -> Task:
82
77
  EnvMap(
83
78
  vars={
84
79
  **MICROSERVICES_ENV_VARS,
85
- "MY_APP_NAME_PORT": f"{port}",
86
- "MY_APP_NAME_MODULES": f"{module}",
87
80
  }
88
81
  ),
89
82
  ],
90
83
  cwd=APP_DIR,
91
84
  cmd=[
92
85
  ACTIVATE_VENV_SCRIPT,
86
+ set_env("MY_APP_NAME_MODULES", module),
87
+ set_env("MY_APP_NAME_PORT", f"{port}"),
93
88
  'fastapi dev main.py --port "${MY_APP_NAME_PORT}"',
94
89
  ],
95
90
  render_cmd=False,
@@ -109,3 +104,35 @@ def get_existing_schema_names() -> list[str]:
109
104
  for entry in os.scandir(module_dir_path)
110
105
  if entry.is_file() and entry.name.endswith(".py")
111
106
  ]
107
+
108
+
109
+ def set_create_migration_db_url_env(module_name: str) -> str:
110
+ return set_env(
111
+ "MY_APP_NAME_DB_URL",
112
+ f"sqlite:///{APP_DIR}/.migration.{to_snake_case(module_name)}.db",
113
+ )
114
+
115
+
116
+ def set_module_env(module_name: str) -> str:
117
+ return (set_env("MY_APP_NAME_MODULES", to_snake_case(module_name)),)
118
+
119
+
120
+ def cd_module_script(module_name: str) -> str:
121
+ module_dir_path = os.path.join(APP_DIR, "module", to_snake_case(module_name))
122
+ return f"cd {module_dir_path}"
123
+
124
+
125
+ def set_env(var_name: str, var_value: str) -> str:
126
+ """
127
+ Generates a script to set an environment variable depending on the OS.
128
+ :param var_name: Name of the environment variable.
129
+ :param var_value: Value of the environment variable.
130
+ :return: A string containing the appropriate script.
131
+ """
132
+ if platform.system() == "Windows":
133
+ # PowerShell script for Windows
134
+ script = f'[Environment]::SetEnvironmentVariable({double_quote(var_name)}, {double_quote(var_value)}, "User")' # noqa
135
+ else:
136
+ # Bash script for Unix-like systems
137
+ script = f"export {var_name}={double_quote(var_value)}"
138
+ return script
@@ -0,0 +1,29 @@
1
+ import os
2
+
3
+ from fastapi import FastAPI
4
+ from my_app_name.common.db_engine_factory import db_engine
5
+ from my_app_name.common.util.app import (
6
+ create_default_app_lifespan,
7
+ get_default_app_title,
8
+ serve_docs,
9
+ serve_static_dir,
10
+ )
11
+ from my_app_name.config import (
12
+ APP_GATEWAY_FAVICON_PATH,
13
+ APP_GATEWAY_TITLE,
14
+ APP_GATEWAY_VIEW_PATH,
15
+ APP_MODE,
16
+ APP_MODULES,
17
+ APP_VERSION,
18
+ )
19
+
20
+ app_title = get_default_app_title(APP_GATEWAY_TITLE, mode=APP_MODE, modules=APP_MODULES)
21
+ app = FastAPI(
22
+ title=app_title,
23
+ version=APP_VERSION,
24
+ lifespan=create_default_app_lifespan(db_engine),
25
+ docs_url=None,
26
+ )
27
+
28
+ serve_static_dir(app, os.path.join(APP_GATEWAY_VIEW_PATH, "static"))
29
+ serve_docs(app, app_title=app_title, favicon_url=APP_GATEWAY_FAVICON_PATH)