amsdal 0.3.6__cp312-cp312-macosx_10_13_universal2.whl → 0.4.0__cp312-cp312-macosx_10_13_universal2.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.

Potentially problematic release.


This version of amsdal might be problematic. Click here for more details.

Files changed (208) hide show
  1. amsdal/__about__.py +1 -1
  2. amsdal/__migrations__/0000_initial.py +34 -25
  3. amsdal/__migrations__/0001_datetime_type.py +4 -4
  4. amsdal/__migrations__/0002_fixture_order.py +7 -3
  5. amsdal/__migrations__/0003_schema_type_in_class_meta.py +3 -15
  6. amsdal/cloud/__init__.cpython-312-darwin.so +0 -0
  7. amsdal/cloud/client.cpython-312-darwin.so +0 -0
  8. amsdal/cloud/constants.cpython-312-darwin.so +0 -0
  9. amsdal/cloud/enums.cpython-312-darwin.so +0 -0
  10. amsdal/cloud/models/__init__.cpython-312-darwin.so +0 -0
  11. amsdal/cloud/models/base.cpython-312-darwin.so +0 -0
  12. amsdal/cloud/services/__init__.cpython-312-darwin.so +0 -0
  13. amsdal/cloud/services/actions/__init__.cpython-312-darwin.so +0 -0
  14. amsdal/cloud/services/actions/add_allowlist_ip.cpython-312-darwin.so +0 -0
  15. amsdal/cloud/services/actions/add_basic_auth.cpython-312-darwin.so +0 -0
  16. amsdal/cloud/services/actions/add_dependency.cpython-312-darwin.so +0 -0
  17. amsdal/cloud/services/actions/add_secret.cpython-312-darwin.so +0 -0
  18. amsdal/cloud/services/actions/base.cpython-312-darwin.so +0 -0
  19. amsdal/cloud/services/actions/create_deploy.cpython-312-darwin.so +0 -0
  20. amsdal/cloud/services/actions/create_env.cpython-312-darwin.so +0 -0
  21. amsdal/cloud/services/actions/create_session.cpython-312-darwin.so +0 -0
  22. amsdal/cloud/services/actions/delete_allowlist_ip.cpython-312-darwin.so +0 -0
  23. amsdal/cloud/services/actions/delete_basic_auth.cpython-312-darwin.so +0 -0
  24. amsdal/cloud/services/actions/delete_dependency.cpython-312-darwin.so +0 -0
  25. amsdal/cloud/services/actions/delete_env.cpython-312-darwin.so +0 -0
  26. amsdal/cloud/services/actions/delete_secret.cpython-312-darwin.so +0 -0
  27. amsdal/cloud/services/actions/destroy_deploy.cpython-312-darwin.so +0 -0
  28. amsdal/cloud/services/actions/expose_db.cpython-312-darwin.so +0 -0
  29. amsdal/cloud/services/actions/get_basic_auth_credentials.cpython-312-darwin.so +0 -0
  30. amsdal/cloud/services/actions/get_monitoring_info.cpython-312-darwin.so +0 -0
  31. amsdal/cloud/services/actions/list_dependencies.cpython-312-darwin.so +0 -0
  32. amsdal/cloud/services/actions/list_deploys.cpython-312-darwin.so +0 -0
  33. amsdal/cloud/services/actions/list_envs.cpython-312-darwin.so +0 -0
  34. amsdal/cloud/services/actions/list_secrets.cpython-312-darwin.so +0 -0
  35. amsdal/cloud/services/actions/manager.cpython-312-darwin.so +0 -0
  36. amsdal/cloud/services/actions/signup_action.cpython-312-darwin.so +0 -0
  37. amsdal/cloud/services/actions/update_deploy.cpython-312-darwin.so +0 -0
  38. amsdal/cloud/services/auth/__init__.cpython-312-darwin.so +0 -0
  39. amsdal/cloud/services/auth/base.cpython-312-darwin.so +0 -0
  40. amsdal/cloud/services/auth/credentials.cpython-312-darwin.so +0 -0
  41. amsdal/cloud/services/auth/credentials.pyi +0 -1
  42. amsdal/cloud/services/auth/manager.cpython-312-darwin.so +0 -0
  43. amsdal/cloud/services/auth/signup_service.cpython-312-darwin.so +0 -0
  44. amsdal/cloud/services/auth/token.cpython-312-darwin.so +0 -0
  45. amsdal/cloud/services/auth/token.pyi +0 -1
  46. amsdal/configs/main.py +23 -19
  47. amsdal/configs/main.pyi +12 -15
  48. amsdal/contrib/__init__.cpython-312-darwin.so +0 -0
  49. amsdal/contrib/auth/lifecycle/consumer.py +10 -10
  50. amsdal/contrib/auth/migrations/0000_initial.py +41 -7
  51. amsdal/contrib/auth/models/login_session.py +66 -0
  52. amsdal/contrib/auth/models/login_session.pyi +33 -0
  53. amsdal/contrib/auth/models/permission.py +23 -0
  54. amsdal/contrib/auth/models/permission.pyi +18 -0
  55. amsdal/contrib/auth/models/user.py +106 -0
  56. amsdal/contrib/auth/models/user.pyi +46 -0
  57. amsdal/contrib/frontend_configs/conversion/convert.py +47 -15
  58. amsdal/contrib/frontend_configs/conversion/convert.pyi +0 -1
  59. amsdal/contrib/frontend_configs/lifecycle/consumer.py +32 -13
  60. amsdal/contrib/frontend_configs/lifecycle/consumer.pyi +1 -1
  61. amsdal/contrib/frontend_configs/migrations/0000_initial.py +15 -14
  62. amsdal/contrib/frontend_configs/models/__init__.py +0 -0
  63. amsdal/contrib/frontend_configs/models/__init__.pyi +0 -0
  64. amsdal/contrib/frontend_configs/models/frontend_activator_config.py +22 -0
  65. amsdal/contrib/frontend_configs/models/frontend_activator_config.pyi +12 -0
  66. amsdal/contrib/frontend_configs/models/frontend_config_async_validator.py +11 -0
  67. amsdal/contrib/frontend_configs/models/frontend_config_async_validator.pyi +7 -0
  68. amsdal/contrib/frontend_configs/models/frontend_config_control_action.py +54 -0
  69. amsdal/contrib/frontend_configs/models/frontend_config_control_action.pyi +32 -0
  70. amsdal/contrib/frontend_configs/models/frontend_config_group_validator.py +21 -0
  71. amsdal/contrib/frontend_configs/models/frontend_config_group_validator.pyi +11 -0
  72. amsdal/contrib/frontend_configs/models/frontend_config_option.py +12 -0
  73. amsdal/contrib/frontend_configs/models/frontend_config_option.pyi +8 -0
  74. amsdal/contrib/frontend_configs/models/frontend_config_skip_none_base.py +17 -0
  75. amsdal/contrib/frontend_configs/models/frontend_config_skip_none_base.pyi +8 -0
  76. amsdal/contrib/frontend_configs/models/frontend_config_slider_option.py +13 -0
  77. amsdal/contrib/frontend_configs/models/frontend_config_slider_option.pyi +9 -0
  78. amsdal/contrib/frontend_configs/models/frontend_config_text_mask.py +14 -0
  79. amsdal/contrib/frontend_configs/models/frontend_config_text_mask.pyi +10 -0
  80. amsdal/contrib/frontend_configs/models/frontend_config_validator.py +28 -0
  81. amsdal/contrib/frontend_configs/models/frontend_config_validator.pyi +15 -0
  82. amsdal/contrib/frontend_configs/models/frontend_control_config.py +87 -0
  83. amsdal/contrib/frontend_configs/models/frontend_control_config.pyi +35 -0
  84. amsdal/contrib/frontend_configs/models/frontend_model_config.py +14 -0
  85. amsdal/contrib/frontend_configs/models/frontend_model_config.pyi +9 -0
  86. amsdal/errors.py +0 -3
  87. amsdal/errors.pyi +0 -1
  88. amsdal/fixtures/__init__.cpython-312-darwin.so +0 -0
  89. amsdal/fixtures/manager.cpython-312-darwin.so +0 -0
  90. amsdal/fixtures/manager.pyi +72 -123
  91. amsdal/fixtures/utils.cpython-312-darwin.so +0 -0
  92. amsdal/fixtures/utils.pyi +9 -0
  93. amsdal/manager.cpython-312-darwin.so +0 -0
  94. amsdal/manager.pyi +4 -96
  95. amsdal/mixins/__init__.cpython-312-darwin.so +0 -0
  96. amsdal/mixins/class_versions_mixin.cpython-312-darwin.so +0 -0
  97. amsdal/models/__init__.py +0 -0
  98. amsdal/models/__init__.pyi +0 -0
  99. amsdal/models/core/__init__.py +0 -0
  100. amsdal/models/core/__init__.pyi +0 -0
  101. amsdal/models/core/class_object.py +37 -0
  102. amsdal/models/core/class_object.pyi +24 -0
  103. amsdal/models/core/class_object_meta.py +26 -0
  104. amsdal/models/core/class_object_meta.pyi +15 -0
  105. amsdal/models/core/class_property.py +19 -0
  106. amsdal/models/core/class_property.pyi +10 -0
  107. amsdal/models/core/class_property_meta.py +15 -0
  108. amsdal/models/core/class_property_meta.pyi +10 -0
  109. amsdal/models/core/file.py +156 -0
  110. amsdal/models/core/file.pyi +104 -0
  111. amsdal/models/core/fixture.py +25 -0
  112. amsdal/models/core/fixture.pyi +14 -0
  113. amsdal/models/core/option.py +11 -0
  114. amsdal/models/core/option.pyi +8 -0
  115. amsdal/models/core/validator.py +12 -0
  116. amsdal/models/core/validator.pyi +8 -0
  117. amsdal/models/types/__init__.py +0 -0
  118. amsdal/models/types/__init__.pyi +0 -0
  119. amsdal/models/types/object.py +26 -0
  120. amsdal/models/types/object.pyi +16 -0
  121. amsdal/schemas/core/file/properties/validate_data.py +1 -1
  122. amsdal/schemas/interfaces.py +25 -0
  123. amsdal/schemas/interfaces.pyi +20 -0
  124. amsdal/schemas/manager.cpython-312-darwin.so +0 -0
  125. amsdal/schemas/manager.py +0 -116
  126. amsdal/schemas/manager.pyi +0 -65
  127. amsdal/schemas/mixins/__init__.py +0 -0
  128. amsdal/schemas/mixins/__init__.pyi +0 -0
  129. amsdal/schemas/mixins/check_dependencies_mixin.py +115 -0
  130. amsdal/schemas/mixins/check_dependencies_mixin.pyi +42 -0
  131. amsdal/schemas/mixins/verify_schemas_mixin.py +96 -0
  132. amsdal/schemas/mixins/verify_schemas_mixin.pyi +33 -0
  133. amsdal/schemas/repository.py +84 -0
  134. amsdal/schemas/repository.pyi +22 -0
  135. amsdal/schemas/utils.py +16 -0
  136. amsdal/schemas/utils.pyi +10 -0
  137. amsdal/services/__init__.cpython-312-darwin.so +0 -0
  138. amsdal/services/transaction_execution.cpython-312-darwin.so +0 -0
  139. amsdal/utils/rollback/__init__.py +99 -54
  140. amsdal/utils/tests/helpers.py +46 -37
  141. {amsdal-0.3.6.dist-info → amsdal-0.4.0.dist-info}/METADATA +8 -8
  142. {amsdal-0.3.6.dist-info → amsdal-0.4.0.dist-info}/RECORD +148 -140
  143. amsdal/contrib/auth/models/login_session/hooks/pre_init.py +0 -68
  144. amsdal/contrib/auth/models/login_session/model.json +0 -23
  145. amsdal/contrib/auth/models/login_session/modifiers/display_name.py +0 -11
  146. amsdal/contrib/auth/models/permission/fixtures/basic_permissions.json +0 -62
  147. amsdal/contrib/auth/models/permission/model.json +0 -18
  148. amsdal/contrib/auth/models/permission/modifiers/display_name.py +0 -11
  149. amsdal/contrib/auth/models/user/hooks/post_init.py +0 -76
  150. amsdal/contrib/auth/models/user/hooks/pre_create.py +0 -8
  151. amsdal/contrib/auth/models/user/model.json +0 -25
  152. amsdal/contrib/auth/models/user/modifiers/display_name.py +0 -19
  153. amsdal/contrib/frontend_configs/models/frontend_activator_config/model.json +0 -11
  154. amsdal/contrib/frontend_configs/models/frontend_config_async_validator/model.json +0 -11
  155. amsdal/contrib/frontend_configs/models/frontend_config_group_validator/model.json +0 -52
  156. amsdal/contrib/frontend_configs/models/frontend_config_option/model.json +0 -15
  157. amsdal/contrib/frontend_configs/models/frontend_config_skip_none_base/model.json +0 -6
  158. amsdal/contrib/frontend_configs/models/frontend_config_skip_none_base/properties/model_dump.py +0 -13
  159. amsdal/contrib/frontend_configs/models/frontend_config_slider_option/model.json +0 -19
  160. amsdal/contrib/frontend_configs/models/frontend_config_text_mask/model.json +0 -26
  161. amsdal/contrib/frontend_configs/models/frontend_config_validator/model.json +0 -41
  162. amsdal/contrib/frontend_configs/models/frontend_control_config/model.json +0 -250
  163. amsdal/contrib/frontend_configs/models/frontend_model_config/fixtures/permissions.json +0 -24
  164. amsdal/contrib/frontend_configs/models/frontend_model_config/model.json +0 -17
  165. amsdal/contrib/frontend_configs/models/frontent_config_control_action/model.json +0 -54
  166. amsdal/contrib/frontend_configs/models/frontent_config_control_action/properties/action_validate.py +0 -33
  167. amsdal/migration/__init__.cpython-312-darwin.so +0 -0
  168. amsdal/migration/base_migration_schemas.cpython-312-darwin.so +0 -0
  169. amsdal/migration/base_migration_schemas.pyi +0 -119
  170. amsdal/migration/data_classes.cpython-312-darwin.so +0 -0
  171. amsdal/migration/data_classes.pyi +0 -165
  172. amsdal/migration/executors/__init__.cpython-312-darwin.so +0 -0
  173. amsdal/migration/executors/base.cpython-312-darwin.so +0 -0
  174. amsdal/migration/executors/base.pyi +0 -117
  175. amsdal/migration/executors/default_executor.cpython-312-darwin.so +0 -0
  176. amsdal/migration/executors/default_executor.pyi +0 -184
  177. amsdal/migration/executors/state_executor.cpython-312-darwin.so +0 -0
  178. amsdal/migration/executors/state_executor.pyi +0 -151
  179. amsdal/migration/file_migration_executor.cpython-312-darwin.so +0 -0
  180. amsdal/migration/file_migration_executor.pyi +0 -122
  181. amsdal/migration/file_migration_generator.cpython-312-darwin.so +0 -0
  182. amsdal/migration/file_migration_generator.pyi +0 -229
  183. amsdal/migration/file_migration_store.cpython-312-darwin.so +0 -0
  184. amsdal/migration/file_migration_store.pyi +0 -114
  185. amsdal/migration/file_migration_writer.cpython-312-darwin.so +0 -0
  186. amsdal/migration/file_migration_writer.pyi +0 -73
  187. amsdal/migration/migrations.cpython-312-darwin.so +0 -0
  188. amsdal/migration/migrations.pyi +0 -166
  189. amsdal/migration/migrations_loader.cpython-312-darwin.so +0 -0
  190. amsdal/migration/migrations_loader.pyi +0 -32
  191. amsdal/migration/schemas_loaders.cpython-312-darwin.so +0 -0
  192. amsdal/migration/schemas_loaders.pyi +0 -37
  193. amsdal/migration/templates/data_migration.tmpl +0 -18
  194. amsdal/migration/templates/dict_validator.tmpl +0 -4
  195. amsdal/migration/templates/migration.tmpl +0 -6
  196. amsdal/migration/templates/model_class.tmpl +0 -8
  197. amsdal/migration/templates/model_class_layout.tmpl +0 -24
  198. amsdal/migration/templates/options_validator.tmpl +0 -4
  199. amsdal/migration/utils.cpython-312-darwin.so +0 -0
  200. amsdal/migration/utils.pyi +0 -58
  201. amsdal/mixins/build_mixin.cpython-312-darwin.so +0 -0
  202. amsdal/mixins/build_mixin.pyi +0 -78
  203. /amsdal/{migration/__init__.pyi → contrib/auth/models/__init__.py} +0 -0
  204. /amsdal/{migration/executors → contrib/auth/models}/__init__.pyi +0 -0
  205. {amsdal-0.3.6.dist-info → amsdal-0.4.0.dist-info}/LICENSE.txt +0 -0
  206. {amsdal-0.3.6.dist-info → amsdal-0.4.0.dist-info}/WHEEL +0 -0
  207. {amsdal-0.3.6.dist-info → amsdal-0.4.0.dist-info}/licenses/LICENSE.txt +0 -0
  208. {amsdal-0.3.6.dist-info → amsdal-0.4.0.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,15 @@
1
+ from amsdal.models.core.class_property_meta import *
2
+ from amsdal_models.classes.model import Model
3
+ from amsdal_utils.models.enums import ModuleType
4
+ from typing import Any, ClassVar
5
+
6
+ class ClassObjectMeta(Model):
7
+ __module_type__: ClassVar[ModuleType] = ...
8
+ title: str = ...
9
+ type: str = ...
10
+ default: Any | None = ...
11
+ class_schema_type: str | None = ...
12
+ properties: dict[str, ClassPropertyMeta | None] | None = ...
13
+ custom_code: str | None = ...
14
+ @classmethod
15
+ def _non_empty_keys_properties(cls, value: Any) -> Any: ...
@@ -0,0 +1,19 @@
1
+ from typing import Any
2
+ from typing import ClassVar
3
+
4
+ from amsdal_models.builder.validators.dict_validators import validate_non_empty_keys
5
+ from amsdal_models.classes.model import TypeModel
6
+ from amsdal_utils.models.enums import ModuleType
7
+ from pydantic.fields import Field
8
+ from pydantic.functional_validators import field_validator
9
+
10
+
11
+ class ClassProperty(TypeModel):
12
+ __module_type__: ClassVar[ModuleType] = ModuleType.CORE
13
+ type: str = Field(title='Type')
14
+ items: dict[str, Any | None] | None = Field(None, title='Items')
15
+
16
+ @field_validator('items')
17
+ @classmethod
18
+ def _non_empty_keys_items(cls: type, value: Any) -> Any: # type: ignore # noqa: A003
19
+ return validate_non_empty_keys(value)
@@ -0,0 +1,10 @@
1
+ from amsdal_models.classes.model import TypeModel
2
+ from amsdal_utils.models.enums import ModuleType
3
+ from typing import Any, ClassVar
4
+
5
+ class ClassProperty(TypeModel):
6
+ __module_type__: ClassVar[ModuleType]
7
+ type: str
8
+ items: dict[str, Any | None] | None
9
+ @classmethod
10
+ def _non_empty_keys_items(cls, value: Any) -> Any: ...
@@ -0,0 +1,15 @@
1
+ from typing import Any
2
+ from typing import ClassVar
3
+
4
+ from amsdal_models.classes.model import TypeModel
5
+ from amsdal_utils.models.enums import ModuleType
6
+ from pydantic.fields import Field
7
+
8
+ from amsdal.models.core.option import * # noqa: F403
9
+
10
+
11
+ class ClassPropertyMeta(TypeModel):
12
+ __module_type__: ClassVar[ModuleType] = ModuleType.CORE
13
+ title: str | None = Field(None, title='Title')
14
+ default: Any | None = Field(None, title='Default')
15
+ options: list['Option'] | None = Field(None, title='Options') # noqa: F405
@@ -0,0 +1,10 @@
1
+ from amsdal.models.core.option import *
2
+ from amsdal_models.classes.model import TypeModel
3
+ from amsdal_utils.models.enums import ModuleType
4
+ from typing import Any, ClassVar
5
+
6
+ class ClassPropertyMeta(TypeModel):
7
+ __module_type__: ClassVar[ModuleType]
8
+ title: str | None
9
+ default: Any | None
10
+ options: list['Option'] | None
@@ -0,0 +1,156 @@
1
+ import base64
2
+ from pathlib import Path
3
+ from typing import BinaryIO
4
+ from typing import ClassVar
5
+
6
+ from amsdal_models.classes.model import Model
7
+ from amsdal_utils.models.enums import ModuleType
8
+ from pydantic import field_validator
9
+ from pydantic.fields import Field
10
+
11
+
12
+ class File(Model):
13
+ __module_type__: ClassVar[ModuleType] = ModuleType.CORE
14
+ filename: str = Field(title='Filename')
15
+ data: bytes = Field(title='Data')
16
+ size: float | None = Field(None, title='Size')
17
+
18
+ def __repr__(self) -> str:
19
+ return f'File<{self.filename}>({self.size or len(self.data) or 0} bytes)'
20
+
21
+ def __str__(self) -> str:
22
+ return repr(self)
23
+
24
+ async def apre_create(self) -> None:
25
+ """
26
+ Prepares the object for creation by setting its size attribute.
27
+
28
+ This method calculates the size of the object's data and assigns it to the size attribute.
29
+ If the data is None, it defaults to an empty byte string.
30
+
31
+ Args:
32
+ None
33
+ """
34
+ self.size = len(self.data or b'')
35
+
36
+ async def apre_update(self) -> None:
37
+ """
38
+ Prepares the object for update by setting its size attribute.
39
+
40
+ This method calculates the size of the object's data and assigns it to the size attribute.
41
+ If the data is None, it defaults to an empty byte string.
42
+
43
+ Args:
44
+ None
45
+ """
46
+ self.size = len(self.data or b'')
47
+
48
+ @field_validator('data')
49
+ @classmethod
50
+ def data_base64_decode(cls, v: bytes) -> bytes:
51
+ """
52
+ Decodes a base64-encoded byte string if it is base64-encoded.
53
+
54
+ This method checks if the provided byte string is base64-encoded and decodes it if true.
55
+ If the byte string is not base64-encoded, it returns the original byte string.
56
+
57
+ Args:
58
+ cls: The class this method belongs to.
59
+ v (bytes): The byte string to be checked and potentially decoded.
60
+
61
+ Returns:
62
+ bytes: The decoded byte string if it was base64-encoded, otherwise the original byte string.
63
+ """
64
+ is_base64: bool = False
65
+ try:
66
+ is_base64 = base64.b64encode(base64.b64decode(v)) == v
67
+ except Exception:
68
+ ...
69
+ if is_base64:
70
+ return base64.b64decode(v)
71
+ return v
72
+
73
+ @classmethod
74
+ def from_file(cls, file_or_path: Path | BinaryIO) -> 'File':
75
+ """
76
+ Creates a `File` object from a file path or a binary file object.
77
+
78
+ Args:
79
+ file_or_path (Path | BinaryIO): The file path or binary file object.
80
+
81
+ Returns:
82
+ File: The created `File` object.
83
+
84
+ Raises:
85
+ ValueError: If the provided path is a directory.
86
+ """
87
+ if isinstance(file_or_path, Path):
88
+ if file_or_path.is_dir():
89
+ msg = f'{file_or_path} is a directory'
90
+ raise ValueError(msg)
91
+ data = file_or_path.read_bytes()
92
+ filename = file_or_path.name
93
+ else:
94
+ file_or_path.seek(0)
95
+ data = file_or_path.read()
96
+ filename = Path(file_or_path.name).name
97
+ return cls(data=data, filename=filename) # type: ignore[call-arg]
98
+
99
+ @property
100
+ def mimetype(self) -> str | None:
101
+ """
102
+ Returns the MIME type of the file based on its filename.
103
+
104
+ This method uses the `mimetypes` module to guess the MIME type of the file.
105
+
106
+ Returns:
107
+ str | None: The guessed MIME type of the file, or None if it cannot be determined.
108
+ """
109
+ import mimetypes
110
+
111
+ return mimetypes.guess_type(self.filename)[0]
112
+
113
+ def pre_create(self) -> None:
114
+ """
115
+ Prepares the object for creation by setting its size attribute.
116
+
117
+ This method calculates the size of the object's data and assigns it to the size attribute.
118
+ If the data is None, it defaults to an empty byte string.
119
+
120
+ Args:
121
+ None
122
+ """
123
+ self.size = len(self.data or b'')
124
+
125
+ def pre_update(self) -> None:
126
+ """
127
+ Prepares the object for update by setting its size attribute.
128
+
129
+ This method calculates the size of the object's data and assigns it to the size attribute.
130
+ If the data is None, it defaults to an empty byte string.
131
+
132
+ Args:
133
+ None
134
+ """
135
+ self.size = len(self.data or b'')
136
+
137
+ def to_file(self, file_or_path: Path | BinaryIO) -> None:
138
+ """
139
+ Writes the object's data to a file path or a binary file object.
140
+
141
+ Args:
142
+ file_or_path (Path | BinaryIO): The file path or binary file object where the data will be written.
143
+
144
+ Returns:
145
+ None
146
+
147
+ Raises:
148
+ ValueError: If the provided path is a directory.
149
+ """
150
+ if isinstance(file_or_path, Path):
151
+ if file_or_path.is_dir():
152
+ file_or_path = file_or_path / self.name
153
+ file_or_path.write_bytes(self.data) # type: ignore[union-attr]
154
+ else:
155
+ file_or_path.write(self.data)
156
+ file_or_path.seek(0)
@@ -0,0 +1,104 @@
1
+ from amsdal_models.classes.model import Model
2
+ from amsdal_utils.models.enums import ModuleType
3
+ from pathlib import Path
4
+ from typing import BinaryIO, ClassVar
5
+
6
+ class File(Model):
7
+ __module_type__: ClassVar[ModuleType] = ...
8
+ filename: str = ...
9
+ data: bytes = ...
10
+ size: float | None = ...
11
+ def __repr__(self) -> str: ...
12
+ def __str__(self) -> str: ...
13
+ async def apre_create(self) -> None:
14
+ """
15
+ Prepares the object for creation by setting its size attribute.
16
+
17
+ This method calculates the size of the object's data and assigns it to the size attribute.
18
+ If the data is None, it defaults to an empty byte string.
19
+
20
+ Args:
21
+ None
22
+ """
23
+ async def apre_update(self) -> None:
24
+ """
25
+ Prepares the object for update by setting its size attribute.
26
+
27
+ This method calculates the size of the object's data and assigns it to the size attribute.
28
+ If the data is None, it defaults to an empty byte string.
29
+
30
+ Args:
31
+ None
32
+ """
33
+ @classmethod
34
+ def data_base64_decode(cls, v: bytes) -> bytes:
35
+ """
36
+ Decodes a base64-encoded byte string if it is base64-encoded.
37
+
38
+ This method checks if the provided byte string is base64-encoded and decodes it if true.
39
+ If the byte string is not base64-encoded, it returns the original byte string.
40
+
41
+ Args:
42
+ cls: The class this method belongs to.
43
+ v (bytes): The byte string to be checked and potentially decoded.
44
+
45
+ Returns:
46
+ bytes: The decoded byte string if it was base64-encoded, otherwise the original byte string.
47
+ """
48
+ @classmethod
49
+ def from_file(cls, file_or_path: Path | BinaryIO) -> File:
50
+ """
51
+ Creates a `File` object from a file path or a binary file object.
52
+
53
+ Args:
54
+ file_or_path (Path | BinaryIO): The file path or binary file object.
55
+
56
+ Returns:
57
+ File: The created `File` object.
58
+
59
+ Raises:
60
+ ValueError: If the provided path is a directory.
61
+ """
62
+ @property
63
+ def mimetype(self) -> str | None:
64
+ """
65
+ Returns the MIME type of the file based on its filename.
66
+
67
+ This method uses the `mimetypes` module to guess the MIME type of the file.
68
+
69
+ Returns:
70
+ str | None: The guessed MIME type of the file, or None if it cannot be determined.
71
+ """
72
+ def pre_create(self) -> None:
73
+ """
74
+ Prepares the object for creation by setting its size attribute.
75
+
76
+ This method calculates the size of the object's data and assigns it to the size attribute.
77
+ If the data is None, it defaults to an empty byte string.
78
+
79
+ Args:
80
+ None
81
+ """
82
+ def pre_update(self) -> None:
83
+ """
84
+ Prepares the object for update by setting its size attribute.
85
+
86
+ This method calculates the size of the object's data and assigns it to the size attribute.
87
+ If the data is None, it defaults to an empty byte string.
88
+
89
+ Args:
90
+ None
91
+ """
92
+ def to_file(self, file_or_path: Path | BinaryIO) -> None:
93
+ """
94
+ Writes the object's data to a file path or a binary file object.
95
+
96
+ Args:
97
+ file_or_path (Path | BinaryIO): The file path or binary file object where the data will be written.
98
+
99
+ Returns:
100
+ None
101
+
102
+ Raises:
103
+ ValueError: If the provided path is a directory.
104
+ """
@@ -0,0 +1,25 @@
1
+ from typing import Any
2
+ from typing import ClassVar
3
+
4
+ from amsdal_models.builder.validators.dict_validators import validate_non_empty_keys
5
+ from amsdal_models.classes.data_models.constraints import UniqueConstraint
6
+ from amsdal_models.classes.model import Model
7
+ from amsdal_utils.models.enums import ModuleType
8
+ from pydantic.fields import Field
9
+ from pydantic.functional_validators import field_validator
10
+
11
+
12
+ class Fixture(Model):
13
+ __module_type__: ClassVar[ModuleType] = ModuleType.CORE
14
+ __constraints__: ClassVar[list[UniqueConstraint]] = [
15
+ UniqueConstraint(name='unq_fixture_external_id', fields=['external_id'])
16
+ ]
17
+ class_name: str | None = Field(None, title='Class Name')
18
+ order: float | None = Field(None, title='Order')
19
+ external_id: str = Field(title='External ID')
20
+ data: dict[str, Any | None] = Field(title='Data')
21
+
22
+ @field_validator('data')
23
+ @classmethod
24
+ def _non_empty_keys_data(cls: type, value: Any) -> Any:
25
+ return validate_non_empty_keys(value)
@@ -0,0 +1,14 @@
1
+ from amsdal_models.classes.data_models.constraints import UniqueConstraint
2
+ from amsdal_models.classes.model import Model
3
+ from amsdal_utils.models.enums import ModuleType
4
+ from typing import Any, ClassVar
5
+
6
+ class Fixture(Model):
7
+ __module_type__: ClassVar[ModuleType] = ...
8
+ __constraints__: ClassVar[list[UniqueConstraint]] = ...
9
+ class_name: str | None = ...
10
+ order: float | None = ...
11
+ external_id: str = ...
12
+ data: dict[str, Any | None] = ...
13
+ @classmethod
14
+ def _non_empty_keys_data(cls, value: Any) -> Any: ...
@@ -0,0 +1,11 @@
1
+ from typing import ClassVar
2
+
3
+ from amsdal_models.classes.model import TypeModel
4
+ from amsdal_utils.models.enums import ModuleType
5
+ from pydantic.fields import Field
6
+
7
+
8
+ class Option(TypeModel):
9
+ __module_type__: ClassVar[ModuleType] = ModuleType.CORE
10
+ key: str = Field(title='Key')
11
+ value: str = Field(title='Value Type')
@@ -0,0 +1,8 @@
1
+ from amsdal_models.classes.model import TypeModel
2
+ from amsdal_utils.models.enums import ModuleType
3
+ from typing import ClassVar
4
+
5
+ class Option(TypeModel):
6
+ __module_type__: ClassVar[ModuleType]
7
+ key: str
8
+ value: str
@@ -0,0 +1,12 @@
1
+ from typing import Any
2
+ from typing import ClassVar
3
+
4
+ from amsdal_models.classes.model import TypeModel
5
+ from amsdal_utils.models.enums import ModuleType
6
+ from pydantic.fields import Field
7
+
8
+
9
+ class Validator(TypeModel):
10
+ __module_type__: ClassVar[ModuleType] = ModuleType.CORE
11
+ name: str = Field(title='Validator Name')
12
+ data: Any = Field(title='Validator Data')
@@ -0,0 +1,8 @@
1
+ from amsdal_models.classes.model import TypeModel
2
+ from amsdal_utils.models.enums import ModuleType
3
+ from typing import Any, ClassVar
4
+
5
+ class Validator(TypeModel):
6
+ __module_type__: ClassVar[ModuleType]
7
+ name: str
8
+ data: Any
File without changes
File without changes
@@ -0,0 +1,26 @@
1
+ from typing import Any
2
+ from typing import ClassVar
3
+ from typing import Optional
4
+
5
+ from amsdal_models.builder.validators.dict_validators import validate_non_empty_keys
6
+ from amsdal_models.classes.model import Model
7
+ from amsdal_utils.models.enums import ModuleType
8
+ from pydantic.fields import Field
9
+ from pydantic.functional_validators import field_validator
10
+
11
+
12
+ class Object(Model):
13
+ __module_type__: ClassVar[ModuleType] = ModuleType.TYPE
14
+ title: Optional[str] = Field(None, title='Title') # noqa: UP007
15
+ type: Optional[str] = Field(None, title='Type') # noqa: UP007
16
+ default: Optional[Any] = Field(None, title='Default') # noqa: UP007
17
+ properties: Optional[dict[str, Optional[Any]]] = Field(None, title='Properties') # noqa: UP007
18
+ required: Optional[list[str]] = Field(None, title='Required') # noqa: UP007
19
+ unique: Optional[list[list[str]]] = Field(None, title='Unique Fields') # noqa: UP007
20
+ custom_code: Optional[str] = Field(None, title='Custom Code') # noqa: UP007
21
+ meta_class: Optional[str] = Field(None, title='Meta Class') # noqa: UP007
22
+
23
+ @field_validator('properties')
24
+ @classmethod
25
+ def _non_empty_keys_properties(cls: type, value: Any) -> Any: # type: ignore # noqa: A003
26
+ return validate_non_empty_keys(value)
@@ -0,0 +1,16 @@
1
+ from amsdal_models.classes.model import Model
2
+ from amsdal_utils.models.enums import ModuleType
3
+ from typing import Any, ClassVar
4
+
5
+ class Object(Model):
6
+ __module_type__: ClassVar[ModuleType] = ...
7
+ title: str | None = ...
8
+ type: str | None = ...
9
+ default: Any | None = ...
10
+ properties: dict[str, Any | None] | None = ...
11
+ required: list[str] | None = ...
12
+ unique: list[list[str]] | None = ...
13
+ custom_code: str | None = ...
14
+ meta_class: str | None = ...
15
+ @classmethod
16
+ def _non_empty_keys_properties(cls, value: Any) -> Any: ...
@@ -5,7 +5,7 @@ from pydantic import field_validator
5
5
 
6
6
  @field_validator('data') # type: ignore[misc]
7
7
  @classmethod
8
- def data_base64_decode(cls, v: bytes) -> bytes: # type: ignore[no-untyped-def] # noqa: ARG001
8
+ def data_base64_decode(cls, v: bytes) -> bytes: # type: ignore[no-untyped-def]
9
9
  """
10
10
  Decodes a base64-encoded byte string if it is base64-encoded.
11
11
 
@@ -0,0 +1,25 @@
1
+ from abc import ABC
2
+ from abc import abstractmethod
3
+ from typing import TypeAlias
4
+
5
+ from amsdal_utils.schemas.schema import ObjectSchema
6
+
7
+ ModulePathType: TypeAlias = str
8
+
9
+
10
+ class BaseSchemaLoader(ABC):
11
+ @property
12
+ @abstractmethod
13
+ def schemas_per_module(self) -> dict[ModulePathType, list[ObjectSchema]]: ...
14
+
15
+ @abstractmethod
16
+ def load(self) -> list[ObjectSchema]: ...
17
+
18
+
19
+ class BaseDependsSchemaLoader(ABC):
20
+ @property
21
+ @abstractmethod
22
+ def schemas_per_module(self) -> dict[ModulePathType, list[ObjectSchema]]: ...
23
+
24
+ @abstractmethod
25
+ def load(self, type_schemas: list[ObjectSchema], *extra_schemas: list[ObjectSchema]) -> list[ObjectSchema]: ...
@@ -0,0 +1,20 @@
1
+ import abc
2
+ from abc import ABC, abstractmethod
3
+ from amsdal_utils.schemas.schema import ObjectSchema as ObjectSchema
4
+ from typing import TypeAlias
5
+
6
+ ModulePathType: TypeAlias
7
+
8
+ class BaseSchemaLoader(ABC, metaclass=abc.ABCMeta):
9
+ @property
10
+ @abstractmethod
11
+ def schemas_per_module(self) -> dict[ModulePathType, list[ObjectSchema]]: ...
12
+ @abstractmethod
13
+ def load(self) -> list[ObjectSchema]: ...
14
+
15
+ class BaseDependsSchemaLoader(ABC, metaclass=abc.ABCMeta):
16
+ @property
17
+ @abstractmethod
18
+ def schemas_per_module(self) -> dict[ModulePathType, list[ObjectSchema]]: ...
19
+ @abstractmethod
20
+ def load(self, type_schemas: list[ObjectSchema], *extra_schemas: list[ObjectSchema]) -> list[ObjectSchema]: ...
amsdal/schemas/manager.py CHANGED
@@ -1,116 +0,0 @@
1
- from amsdal_models.schemas.manager import SchemaManagerHandler
2
- from amsdal_utils.models.data_models.enums import BaseClasses
3
- from amsdal_utils.models.data_models.schema import ObjectSchema
4
- from amsdal_utils.models.enums import SchemaTypes
5
- from amsdal_utils.utils.singleton import Singleton
6
-
7
- from amsdal.configs.main import settings
8
-
9
-
10
- class SchemaManager(metaclass=Singleton):
11
- """
12
- Manages schema operations including retrieval, invalidation, and sorting.
13
-
14
- This class handles various schema-related operations such as invalidating user schemas,
15
- retrieving schemas by name or type, and sorting schemas based on predefined rules.
16
- """
17
-
18
- def __init__(self) -> None:
19
- self._schema_manager_handler = SchemaManagerHandler(settings.schemas_root_path)
20
-
21
- def invalidate_user_schemas(self) -> None:
22
- """
23
- Invalidates user schemas.
24
-
25
- This method calls the handler to invalidate all user schemas, ensuring that any cached or outdated schemas
26
- are refreshed.
27
-
28
- Returns:
29
- None
30
- """
31
- self._schema_manager_handler.invalidate_user_schemas()
32
-
33
- def class_schemas(self) -> list[tuple[ObjectSchema, SchemaTypes]]:
34
- """
35
- Returns a list of tuples containing object schemas and their types.
36
-
37
- This method retrieves and sorts various schemas managed by the schema manager handler.
38
- The schemas are categorized into types, core, user, and contrib schemas.
39
-
40
- Returns:
41
- list[tuple[ObjectSchema, SchemaTypes]]: A list of tuples where each tuple contains an object schema
42
- and its corresponding type.
43
- """
44
- return (
45
- [
46
- (type_schema, SchemaTypes.TYPE)
47
- for type_schema in self._schema_manager_handler.type_schemas
48
- if type_schema.title == BaseClasses.OBJECT
49
- ]
50
- + [
51
- (core_schema, SchemaTypes.CORE)
52
- for core_schema in sorted(self._schema_manager_handler.core_schemas, key=self._sort_key_for_schema)
53
- ]
54
- + [(user_schema, SchemaTypes.USER) for user_schema in self._schema_manager_handler.user_schemas]
55
- + [(contrib_schema, SchemaTypes.CONTRIB) for contrib_schema in self._schema_manager_handler.contrib_schemas]
56
- )
57
-
58
- @staticmethod
59
- def _sort_key_for_schema(schema: ObjectSchema) -> int:
60
- # We need to register ClassObject first, coz ClassObjectMeta has a reference to it.
61
- # All other classes have reference to ClassObject
62
- if schema.title == BaseClasses.CLASS_OBJECT:
63
- return 0
64
- elif schema.title == BaseClasses.CLASS_OBJECT_META:
65
- return 1
66
- else:
67
- return 2
68
-
69
- def get_schema_by_name(self, title: str, schema_type: SchemaTypes | None = None) -> ObjectSchema | None:
70
- """
71
- Retrieves a schema by its title and optional type.
72
-
73
- This method searches for a schema with the specified title and optional type
74
- among the schemas managed by the schema manager handler.
75
-
76
- Args:
77
- title (str): The title of the schema to be retrieved.
78
- schema_type (SchemaTypes | None, optional): The type of the schema to be retrieved. Defaults to None.
79
-
80
- Returns:
81
- ObjectSchema | None: The schema with the specified title and type, or None if not found.
82
- """
83
- _schemas = self.get_schemas(schema_type)
84
-
85
- for schema in _schemas:
86
- if schema.title == title:
87
- return schema
88
-
89
- return None
90
-
91
- def get_schemas(self, schema_type: SchemaTypes | None = None) -> list[ObjectSchema]:
92
- """
93
- Retrieves schemas based on the provided type.
94
-
95
- This method returns a list of schemas filtered by the specified type. If no type is provided,
96
- it returns all schemas managed by the schema manager handler.
97
-
98
- Args:
99
- schema_type (SchemaTypes | None, optional): The type of schemas to retrieve. Defaults to None.
100
-
101
- Returns:
102
- list[ObjectSchema]: A list of schemas filtered by the specified type, or all schemas if no type is provided.
103
- """
104
- if schema_type == SchemaTypes.CONTRIB:
105
- return self._schema_manager_handler.contrib_schemas
106
-
107
- if schema_type == SchemaTypes.CORE:
108
- return self._schema_manager_handler.core_schemas
109
-
110
- if schema_type == SchemaTypes.TYPE:
111
- return self._schema_manager_handler.type_schemas
112
-
113
- if schema_type == SchemaTypes.USER:
114
- return self._schema_manager_handler.user_schemas
115
-
116
- return self._schema_manager_handler.all_schemas