amsdal 0.5.23__cp311-cp311-macosx_10_9_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 (252) hide show
  1. amsdal/Third-Party Materials - AMSDAL Dependencies - License Notices.md +1334 -0
  2. amsdal/__about__.py +4 -0
  3. amsdal/__about__.pyi +1 -0
  4. amsdal/__init__.py +23 -0
  5. amsdal/__init__.pyi +9 -0
  6. amsdal/__migrations__/0000_initial.py +36 -0
  7. amsdal/__migrations__/0001_create_class_file.py +61 -0
  8. amsdal/__migrations__/0002_create_class_file.py +109 -0
  9. amsdal/__migrations__/0003_update_class_file.py +91 -0
  10. amsdal/__migrations__/0004_update_class_file.py +45 -0
  11. amsdal/cloud/__init__.cpython-311-darwin.so +0 -0
  12. amsdal/cloud/__init__.pyi +0 -0
  13. amsdal/cloud/client.cpython-311-darwin.so +0 -0
  14. amsdal/cloud/client.pyi +57 -0
  15. amsdal/cloud/constants.cpython-311-darwin.so +0 -0
  16. amsdal/cloud/constants.pyi +13 -0
  17. amsdal/cloud/enums.cpython-311-darwin.so +0 -0
  18. amsdal/cloud/enums.pyi +68 -0
  19. amsdal/cloud/models/__init__.cpython-311-darwin.so +0 -0
  20. amsdal/cloud/models/__init__.pyi +0 -0
  21. amsdal/cloud/models/base.cpython-311-darwin.so +0 -0
  22. amsdal/cloud/models/base.pyi +247 -0
  23. amsdal/cloud/services/__init__.cpython-311-darwin.so +0 -0
  24. amsdal/cloud/services/__init__.pyi +0 -0
  25. amsdal/cloud/services/actions/__init__.cpython-311-darwin.so +0 -0
  26. amsdal/cloud/services/actions/__init__.pyi +0 -0
  27. amsdal/cloud/services/actions/add_allowlist_ip.cpython-311-darwin.so +0 -0
  28. amsdal/cloud/services/actions/add_allowlist_ip.pyi +19 -0
  29. amsdal/cloud/services/actions/add_basic_auth.cpython-311-darwin.so +0 -0
  30. amsdal/cloud/services/actions/add_basic_auth.pyi +21 -0
  31. amsdal/cloud/services/actions/add_dependency.cpython-311-darwin.so +0 -0
  32. amsdal/cloud/services/actions/add_dependency.pyi +19 -0
  33. amsdal/cloud/services/actions/add_secret.cpython-311-darwin.so +0 -0
  34. amsdal/cloud/services/actions/add_secret.pyi +20 -0
  35. amsdal/cloud/services/actions/base.cpython-311-darwin.so +0 -0
  36. amsdal/cloud/services/actions/base.pyi +122 -0
  37. amsdal/cloud/services/actions/create_deploy.cpython-311-darwin.so +0 -0
  38. amsdal/cloud/services/actions/create_deploy.pyi +41 -0
  39. amsdal/cloud/services/actions/create_env.cpython-311-darwin.so +0 -0
  40. amsdal/cloud/services/actions/create_env.pyi +19 -0
  41. amsdal/cloud/services/actions/create_session.cpython-311-darwin.so +0 -0
  42. amsdal/cloud/services/actions/create_session.pyi +17 -0
  43. amsdal/cloud/services/actions/delete_allowlist_ip.cpython-311-darwin.so +0 -0
  44. amsdal/cloud/services/actions/delete_allowlist_ip.pyi +19 -0
  45. amsdal/cloud/services/actions/delete_basic_auth.cpython-311-darwin.so +0 -0
  46. amsdal/cloud/services/actions/delete_basic_auth.pyi +20 -0
  47. amsdal/cloud/services/actions/delete_dependency.cpython-311-darwin.so +0 -0
  48. amsdal/cloud/services/actions/delete_dependency.pyi +21 -0
  49. amsdal/cloud/services/actions/delete_env.cpython-311-darwin.so +0 -0
  50. amsdal/cloud/services/actions/delete_env.pyi +21 -0
  51. amsdal/cloud/services/actions/delete_secret.cpython-311-darwin.so +0 -0
  52. amsdal/cloud/services/actions/delete_secret.pyi +21 -0
  53. amsdal/cloud/services/actions/destroy_deploy.cpython-311-darwin.so +0 -0
  54. amsdal/cloud/services/actions/destroy_deploy.pyi +18 -0
  55. amsdal/cloud/services/actions/expose_db.cpython-311-darwin.so +0 -0
  56. amsdal/cloud/services/actions/expose_db.pyi +22 -0
  57. amsdal/cloud/services/actions/get_basic_auth_credentials.cpython-311-darwin.so +0 -0
  58. amsdal/cloud/services/actions/get_basic_auth_credentials.pyi +21 -0
  59. amsdal/cloud/services/actions/get_monitoring_info.cpython-311-darwin.so +0 -0
  60. amsdal/cloud/services/actions/get_monitoring_info.pyi +21 -0
  61. amsdal/cloud/services/actions/list_dependencies.cpython-311-darwin.so +0 -0
  62. amsdal/cloud/services/actions/list_dependencies.pyi +21 -0
  63. amsdal/cloud/services/actions/list_deploys.cpython-311-darwin.so +0 -0
  64. amsdal/cloud/services/actions/list_deploys.pyi +19 -0
  65. amsdal/cloud/services/actions/list_envs.cpython-311-darwin.so +0 -0
  66. amsdal/cloud/services/actions/list_envs.pyi +20 -0
  67. amsdal/cloud/services/actions/list_secrets.cpython-311-darwin.so +0 -0
  68. amsdal/cloud/services/actions/list_secrets.pyi +22 -0
  69. amsdal/cloud/services/actions/manager.cpython-311-darwin.so +0 -0
  70. amsdal/cloud/services/actions/manager.pyi +278 -0
  71. amsdal/cloud/services/actions/signup_action.cpython-311-darwin.so +0 -0
  72. amsdal/cloud/services/actions/signup_action.pyi +20 -0
  73. amsdal/cloud/services/actions/update_deploy.cpython-311-darwin.so +0 -0
  74. amsdal/cloud/services/actions/update_deploy.pyi +19 -0
  75. amsdal/cloud/services/auth/__init__.cpython-311-darwin.so +0 -0
  76. amsdal/cloud/services/auth/__init__.pyi +0 -0
  77. amsdal/cloud/services/auth/base.cpython-311-darwin.so +0 -0
  78. amsdal/cloud/services/auth/base.pyi +6 -0
  79. amsdal/cloud/services/auth/credentials.cpython-311-darwin.so +0 -0
  80. amsdal/cloud/services/auth/credentials.pyi +30 -0
  81. amsdal/cloud/services/auth/manager.cpython-311-darwin.so +0 -0
  82. amsdal/cloud/services/auth/manager.pyi +26 -0
  83. amsdal/cloud/services/auth/signup_service.cpython-311-darwin.so +0 -0
  84. amsdal/cloud/services/auth/signup_service.pyi +32 -0
  85. amsdal/cloud/services/auth/token.cpython-311-darwin.so +0 -0
  86. amsdal/cloud/services/auth/token.pyi +27 -0
  87. amsdal/configs/__init__.py +0 -0
  88. amsdal/configs/__init__.pyi +0 -0
  89. amsdal/configs/constants.py +33 -0
  90. amsdal/configs/constants.pyi +22 -0
  91. amsdal/configs/main.py +274 -0
  92. amsdal/configs/main.pyi +178 -0
  93. amsdal/context/__init__.py +0 -0
  94. amsdal/context/__init__.pyi +0 -0
  95. amsdal/context/manager.py +69 -0
  96. amsdal/context/manager.pyi +50 -0
  97. amsdal/contrib/__init__.cpython-311-darwin.so +0 -0
  98. amsdal/contrib/__init__.pyi +0 -0
  99. amsdal/contrib/app_config.py +7 -0
  100. amsdal/contrib/app_config.pyi +6 -0
  101. amsdal/contrib/auth/__init__.py +0 -0
  102. amsdal/contrib/auth/__init__.pyi +0 -0
  103. amsdal/contrib/auth/app.py +27 -0
  104. amsdal/contrib/auth/app.pyi +15 -0
  105. amsdal/contrib/auth/decorators/__init__.py +35 -0
  106. amsdal/contrib/auth/decorators/__init__.pyi +6 -0
  107. amsdal/contrib/auth/errors.py +7 -0
  108. amsdal/contrib/auth/errors.pyi +4 -0
  109. amsdal/contrib/auth/fixtures/basic_permissions.json +64 -0
  110. amsdal/contrib/auth/lifecycle/__init__.py +0 -0
  111. amsdal/contrib/auth/lifecycle/__init__.pyi +0 -0
  112. amsdal/contrib/auth/lifecycle/consumer.py +394 -0
  113. amsdal/contrib/auth/lifecycle/consumer.pyi +108 -0
  114. amsdal/contrib/auth/migrations/0000_initial.py +87 -0
  115. amsdal/contrib/auth/models/__init__.py +0 -0
  116. amsdal/contrib/auth/models/login_session.py +118 -0
  117. amsdal/contrib/auth/models/permission.py +23 -0
  118. amsdal/contrib/auth/models/user.py +106 -0
  119. amsdal/contrib/auth/settings.py +36 -0
  120. amsdal/contrib/auth/settings.pyi +26 -0
  121. amsdal/contrib/frontend_configs/__init__.py +0 -0
  122. amsdal/contrib/frontend_configs/__init__.pyi +0 -0
  123. amsdal/contrib/frontend_configs/app.py +24 -0
  124. amsdal/contrib/frontend_configs/app.pyi +19 -0
  125. amsdal/contrib/frontend_configs/constants.py +1 -0
  126. amsdal/contrib/frontend_configs/constants.pyi +1 -0
  127. amsdal/contrib/frontend_configs/conversion/__init__.py +5 -0
  128. amsdal/contrib/frontend_configs/conversion/__init__.pyi +3 -0
  129. amsdal/contrib/frontend_configs/conversion/convert.py +310 -0
  130. amsdal/contrib/frontend_configs/conversion/convert.pyi +22 -0
  131. amsdal/contrib/frontend_configs/lifecycle/__init__.py +0 -0
  132. amsdal/contrib/frontend_configs/lifecycle/__init__.pyi +0 -0
  133. amsdal/contrib/frontend_configs/lifecycle/consumer.py +306 -0
  134. amsdal/contrib/frontend_configs/lifecycle/consumer.pyi +98 -0
  135. amsdal/contrib/frontend_configs/migrations/0000_initial.py +227 -0
  136. amsdal/contrib/frontend_configs/migrations/0001_update_frontend_control_config.py +245 -0
  137. amsdal/contrib/frontend_configs/migrations/0002_add_button_and_invoke_actions.py +352 -0
  138. amsdal/contrib/frontend_configs/models/__init__.py +0 -0
  139. amsdal/contrib/frontend_configs/models/frontend_activator_config.py +22 -0
  140. amsdal/contrib/frontend_configs/models/frontend_config_async_validator.py +11 -0
  141. amsdal/contrib/frontend_configs/models/frontend_config_control_action.py +110 -0
  142. amsdal/contrib/frontend_configs/models/frontend_config_group_validator.py +21 -0
  143. amsdal/contrib/frontend_configs/models/frontend_config_option.py +12 -0
  144. amsdal/contrib/frontend_configs/models/frontend_config_skip_none_base.py +17 -0
  145. amsdal/contrib/frontend_configs/models/frontend_config_slider_option.py +13 -0
  146. amsdal/contrib/frontend_configs/models/frontend_config_text_mask.py +14 -0
  147. amsdal/contrib/frontend_configs/models/frontend_config_validator.py +28 -0
  148. amsdal/contrib/frontend_configs/models/frontend_control_config.py +108 -0
  149. amsdal/contrib/frontend_configs/models/frontend_model_config.py +14 -0
  150. amsdal/contrib/frontend_configs/utils.py +29 -0
  151. amsdal/contrib/frontend_configs/utils.pyi +17 -0
  152. amsdal/errors.py +31 -0
  153. amsdal/errors.pyi +12 -0
  154. amsdal/fixtures/__init__.cpython-311-darwin.so +0 -0
  155. amsdal/fixtures/__init__.pyi +0 -0
  156. amsdal/fixtures/manager.cpython-311-darwin.so +0 -0
  157. amsdal/fixtures/manager.pyi +170 -0
  158. amsdal/fixtures/utils.cpython-311-darwin.so +0 -0
  159. amsdal/fixtures/utils.pyi +9 -0
  160. amsdal/manager.cpython-311-darwin.so +0 -0
  161. amsdal/manager.pyi +265 -0
  162. amsdal/mixins/__init__.cpython-311-darwin.so +0 -0
  163. amsdal/mixins/__init__.pyi +0 -0
  164. amsdal/mixins/class_versions_mixin.cpython-311-darwin.so +0 -0
  165. amsdal/mixins/class_versions_mixin.pyi +12 -0
  166. amsdal/models/__init__.py +19 -0
  167. amsdal/models/core/__init__.py +0 -0
  168. amsdal/models/core/class_object.py +38 -0
  169. amsdal/models/core/class_property.py +26 -0
  170. amsdal/models/core/file.py +243 -0
  171. amsdal/models/core/fixture.py +25 -0
  172. amsdal/models/core/option.py +11 -0
  173. amsdal/models/core/storage_metadata.py +15 -0
  174. amsdal/models/core/validator.py +12 -0
  175. amsdal/models/mixins.py +31 -0
  176. amsdal/models/types/__init__.py +0 -0
  177. amsdal/models/types/object.py +26 -0
  178. amsdal/py.typed +0 -0
  179. amsdal/queryset/__init__.py +21 -0
  180. amsdal/queryset/__init__.pyi +6 -0
  181. amsdal/schemas/__init__.py +0 -0
  182. amsdal/schemas/__init__.pyi +0 -0
  183. amsdal/schemas/core/class_object/model.json +51 -0
  184. amsdal/schemas/core/class_object/properties/display_name.py +9 -0
  185. amsdal/schemas/core/class_property/model.json +41 -0
  186. amsdal/schemas/core/file/hooks/pre_create.py +24 -0
  187. amsdal/schemas/core/file/hooks/pre_update.py +24 -0
  188. amsdal/schemas/core/file/model.json +23 -0
  189. amsdal/schemas/core/file/properties/from_file.py +34 -0
  190. amsdal/schemas/core/file/properties/mimetype.py +13 -0
  191. amsdal/schemas/core/file/properties/str.py +6 -0
  192. amsdal/schemas/core/file/properties/to_file.py +24 -0
  193. amsdal/schemas/core/file/properties/validate_data.py +31 -0
  194. amsdal/schemas/core/fixture/model.json +35 -0
  195. amsdal/schemas/core/option/model.json +19 -0
  196. amsdal/schemas/core/storage_metadata/model.json +52 -0
  197. amsdal/schemas/core/validator/model.json +19 -0
  198. amsdal/schemas/interfaces.py +25 -0
  199. amsdal/schemas/interfaces.pyi +20 -0
  200. amsdal/schemas/manager.cpython-311-darwin.so +0 -0
  201. amsdal/schemas/manager.py +0 -0
  202. amsdal/schemas/manager.pyi +0 -0
  203. amsdal/schemas/mixins/__init__.py +0 -0
  204. amsdal/schemas/mixins/__init__.pyi +0 -0
  205. amsdal/schemas/mixins/check_dependencies_mixin.py +130 -0
  206. amsdal/schemas/mixins/check_dependencies_mixin.pyi +45 -0
  207. amsdal/schemas/mixins/verify_schemas_mixin.py +96 -0
  208. amsdal/schemas/mixins/verify_schemas_mixin.pyi +33 -0
  209. amsdal/schemas/repository.py +84 -0
  210. amsdal/schemas/repository.pyi +22 -0
  211. amsdal/schemas/types/anything/model.json +7 -0
  212. amsdal/schemas/types/array/model.json +7 -0
  213. amsdal/schemas/types/binary/model.json +7 -0
  214. amsdal/schemas/types/boolean/model.json +17 -0
  215. amsdal/schemas/types/date/model.json +7 -0
  216. amsdal/schemas/types/datetime/model.json +7 -0
  217. amsdal/schemas/types/dictionary/model.json +8 -0
  218. amsdal/schemas/types/number/model.json +8 -0
  219. amsdal/schemas/types/object/model.json +53 -0
  220. amsdal/schemas/types/string/model.json +8 -0
  221. amsdal/schemas/utils.py +16 -0
  222. amsdal/schemas/utils.pyi +10 -0
  223. amsdal/services/__init__.py +11 -0
  224. amsdal/services/__init__.pyi +4 -0
  225. amsdal/services/external_connections.py +262 -0
  226. amsdal/services/external_connections.pyi +190 -0
  227. amsdal/services/external_model_generator.py +350 -0
  228. amsdal/services/external_model_generator.pyi +134 -0
  229. amsdal/services/transaction_execution.cpython-311-darwin.so +0 -0
  230. amsdal/services/transaction_execution.pyi +93 -0
  231. amsdal/storages/__init__.py +20 -0
  232. amsdal/storages/__init__.pyi +8 -0
  233. amsdal/storages/file_system.py +214 -0
  234. amsdal/storages/file_system.pyi +36 -0
  235. amsdal/transactions/__init__.py +13 -0
  236. amsdal/transactions/__init__.pyi +4 -0
  237. amsdal/utils/__init__.py +0 -0
  238. amsdal/utils/__init__.pyi +0 -0
  239. amsdal/utils/contrib_paths.py +23 -0
  240. amsdal/utils/contrib_paths.pyi +14 -0
  241. amsdal/utils/rollback/__init__.py +440 -0
  242. amsdal/utils/rollback/__init__.pyi +38 -0
  243. amsdal/utils/tests/__init__.py +0 -0
  244. amsdal/utils/tests/enums.py +16 -0
  245. amsdal/utils/tests/factories.py +49 -0
  246. amsdal/utils/tests/helpers.py +331 -0
  247. amsdal/utils/tests/migrations.py +157 -0
  248. amsdal-0.5.23.dist-info/METADATA +373 -0
  249. amsdal-0.5.23.dist-info/RECORD +252 -0
  250. amsdal-0.5.23.dist-info/WHEEL +5 -0
  251. amsdal-0.5.23.dist-info/licenses/LICENSE.txt +107 -0
  252. amsdal-0.5.23.dist-info/top_level.txt +1 -0
@@ -0,0 +1,23 @@
1
+ {
2
+ "title": "File",
3
+ "type": "object",
4
+ "default": null,
5
+ "properties": {
6
+ "filename": {
7
+ "title": "Filename",
8
+ "type": "string"
9
+ },
10
+ "data": {
11
+ "title": "Data",
12
+ "type": "binary"
13
+ },
14
+ "size": {
15
+ "title": "Size",
16
+ "type": "number"
17
+ }
18
+ },
19
+ "required": [
20
+ "filename",
21
+ "data"
22
+ ]
23
+ }
@@ -0,0 +1,34 @@
1
+ from pathlib import Path
2
+ from typing import BinaryIO
3
+
4
+
5
+ @classmethod # type: ignore[misc, no-untyped-def]
6
+ def from_file( # type: ignore[no-untyped-def]
7
+ cls,
8
+ file_or_path: Path | BinaryIO,
9
+ ) -> 'File': # type: ignore[name-defined] # noqa: F821
10
+ """
11
+ Creates a `File` object from a file path or a binary file object.
12
+
13
+ Args:
14
+ file_or_path (Path | BinaryIO): The file path or binary file object.
15
+
16
+ Returns:
17
+ File: The created `File` object.
18
+
19
+ Raises:
20
+ ValueError: If the provided path is a directory.
21
+ """
22
+ if isinstance(file_or_path, Path):
23
+ if file_or_path.is_dir():
24
+ msg = f'{file_or_path} is a directory'
25
+ raise ValueError(msg)
26
+
27
+ data = file_or_path.read_bytes()
28
+ filename = file_or_path.name
29
+ else:
30
+ file_or_path.seek(0)
31
+ data = file_or_path.read()
32
+ filename = Path(file_or_path.name).name
33
+
34
+ return cls(data=data, filename=filename)
@@ -0,0 +1,13 @@
1
+ @property # type: ignore[misc]
2
+ def mimetype(self) -> str | None: # type: ignore[no-untyped-def]
3
+ """
4
+ Returns the MIME type of the file based on its filename.
5
+
6
+ This method uses the `mimetypes` module to guess the MIME type of the file.
7
+
8
+ Returns:
9
+ str | None: The guessed MIME type of the file, or None if it cannot be determined.
10
+ """
11
+ import mimetypes
12
+
13
+ return mimetypes.guess_type(self.filename)[0]
@@ -0,0 +1,6 @@
1
+ def __str__(self) -> str: # type: ignore[no-untyped-def] # noqa: N807
2
+ return repr(self)
3
+
4
+
5
+ def __repr__(self) -> str: # type: ignore[no-untyped-def] # noqa: N807
6
+ return f'File<{self.filename}>({self.size or len(self.data) or 0} bytes)'
@@ -0,0 +1,24 @@
1
+ from pathlib import Path
2
+ from typing import BinaryIO
3
+
4
+
5
+ def to_file(self, file_or_path: Path | BinaryIO) -> None: # type: ignore[no-untyped-def]
6
+ """
7
+ Writes the object's data to a file path or a binary file object.
8
+
9
+ Args:
10
+ file_or_path (Path | BinaryIO): The file path or binary file object where the data will be written.
11
+
12
+ Returns:
13
+ None
14
+
15
+ Raises:
16
+ ValueError: If the provided path is a directory.
17
+ """
18
+ if isinstance(file_or_path, Path):
19
+ if file_or_path.is_dir():
20
+ file_or_path = file_or_path / self.name
21
+ file_or_path.write_bytes(self.data) # type: ignore[union-attr]
22
+ else:
23
+ file_or_path.write(self.data)
24
+ file_or_path.seek(0)
@@ -0,0 +1,31 @@
1
+ import base64
2
+ from contextlib import suppress
3
+
4
+ from pydantic import field_validator
5
+
6
+
7
+ @field_validator('data') # type: ignore[misc]
8
+ @classmethod
9
+ def data_base64_decode(cls, v: bytes) -> bytes: # type: ignore[no-untyped-def]
10
+ """
11
+ Decodes a base64-encoded byte string if it is base64-encoded.
12
+
13
+ This method checks if the provided byte string is base64-encoded and decodes it if true.
14
+ If the byte string is not base64-encoded, it returns the original byte string.
15
+
16
+ Args:
17
+ cls: The class this method belongs to.
18
+ v (bytes): The byte string to be checked and potentially decoded.
19
+
20
+ Returns:
21
+ bytes: The decoded byte string if it was base64-encoded, otherwise the original byte string.
22
+ """
23
+ is_base64: bool = False
24
+
25
+ with suppress(Exception):
26
+ is_base64 = base64.b64encode(base64.b64decode(v)) == v
27
+
28
+ if is_base64:
29
+ return base64.b64decode(v)
30
+
31
+ return v
@@ -0,0 +1,35 @@
1
+ {
2
+ "title": "Fixture",
3
+ "type": "object",
4
+ "properties": {
5
+ "class_name": {
6
+ "title": "Class Name",
7
+ "type": "string"
8
+ },
9
+ "order": {
10
+ "title": "Order",
11
+ "type": "number"
12
+ },
13
+ "external_id": {
14
+ "title": "External ID",
15
+ "type": "string"
16
+ },
17
+ "data": {
18
+ "title": "Data",
19
+ "type": "dictionary",
20
+ "items": {
21
+ "key": {"type": "string"},
22
+ "value": {"type": "anything"}
23
+ }
24
+ }
25
+ },
26
+ "required": [
27
+ "data",
28
+ "external_id"
29
+ ],
30
+ "unique": [
31
+ [
32
+ "external_id"
33
+ ]
34
+ ]
35
+ }
@@ -0,0 +1,19 @@
1
+ {
2
+ "title": "Option",
3
+ "type": "object",
4
+ "properties": {
5
+ "key": {
6
+ "title": "Key",
7
+ "type": "string"
8
+ },
9
+ "value": {
10
+ "title": "Value Type",
11
+ "type": "string"
12
+ }
13
+ },
14
+ "required": [
15
+ "key",
16
+ "value"
17
+ ],
18
+ "meta_class": "TypeMeta"
19
+ }
@@ -0,0 +1,52 @@
1
+ {
2
+ "title": "StorageMetadata",
3
+ "type": "object",
4
+ "properties": {
5
+ "table_name": {
6
+ "title": "Table name",
7
+ "type": "string"
8
+ },
9
+ "db_fields": {
10
+ "title": "Database fields",
11
+ "type": "dictionary",
12
+ "items": {
13
+ "key": {"type": "string"},
14
+ "value": {
15
+ "type": "array",
16
+ "items": {
17
+ "type": "string"
18
+ }
19
+ }
20
+ }
21
+ },
22
+ "primary_key": {
23
+ "title": "Primary key fields",
24
+ "type": "array",
25
+ "items": {
26
+ "type": "string"
27
+ }
28
+ },
29
+ "indexed": {
30
+ "title": "Indexed",
31
+ "type": "array",
32
+ "items": {
33
+ "type": "array",
34
+ "items": {
35
+ "type": "string"
36
+ }
37
+ }
38
+ },
39
+ "unique": {
40
+ "title": "Unique Fields",
41
+ "type": "array",
42
+ "items": {
43
+ "type": "array",
44
+ "items": {
45
+ "type": "string"
46
+ }
47
+ }
48
+ }
49
+ },
50
+ "required": [],
51
+ "meta_class": "TypeMeta"
52
+ }
@@ -0,0 +1,19 @@
1
+ {
2
+ "title": "Validator",
3
+ "type": "object",
4
+ "properties": {
5
+ "name": {
6
+ "title": "Validator Name",
7
+ "type": "string"
8
+ },
9
+ "data": {
10
+ "title": "Validator Data",
11
+ "type": "anything"
12
+ }
13
+ },
14
+ "required": [
15
+ "name",
16
+ "data"
17
+ ],
18
+ "meta_class": "TypeMeta"
19
+ }
@@ -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 = str
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]: ...
File without changes
File without changes
File without changes
File without changes
@@ -0,0 +1,130 @@
1
+ from amsdal_models.errors import AmsdalValidationError
2
+ from amsdal_utils.models.data_models.core import DictSchema
3
+ from amsdal_utils.models.data_models.core import LegacyDictSchema
4
+ from amsdal_utils.models.data_models.core import TypeData
5
+ from amsdal_utils.models.data_models.enums import CoreTypes
6
+ from amsdal_utils.schemas.schema import ObjectSchema
7
+
8
+
9
+ class CheckDependenciesMixin:
10
+ """
11
+ Mixin class to check dependencies among schemas.
12
+
13
+ This class provides methods to check if all dependencies for a given set of schemas are defined. It raises an
14
+ `AmsdalValidationError` if any dependency is not defined.
15
+ """
16
+
17
+ def check_dependencies(
18
+ self,
19
+ type_schemas: list[ObjectSchema],
20
+ core_schemas: list[ObjectSchema],
21
+ contrib_schemas: list[ObjectSchema],
22
+ user_schemas: list[ObjectSchema],
23
+ ) -> None:
24
+ """
25
+ Checks if all dependencies for the given schemas are defined.
26
+
27
+ This method verifies that all dependencies for the provided type, core, contrib, and user schemas are defined.
28
+ If any dependency is not defined, it raises an `AmsdalValidationError`.
29
+
30
+ Args:
31
+ type_schemas (list[ObjectSchema]): A list of type schemas to check.
32
+ core_schemas (list[ObjectSchema]): A list of core schemas to check.
33
+ contrib_schemas (list[ObjectSchema]): A list of contrib schemas to check.
34
+ user_schemas (list[ObjectSchema]): A list of user schemas to check.
35
+
36
+ Raises:
37
+ AmsdalValidationError: If any dependency is not defined.
38
+
39
+ Returns:
40
+ None
41
+ """
42
+ _defined_schemas: set[str] = {
43
+ *[schema.title.lower() for schema in type_schemas],
44
+ *[schema.title for schema in core_schemas],
45
+ *[schema.title for schema in contrib_schemas],
46
+ *[schema.title for schema in user_schemas],
47
+ }
48
+ _defined_schemas.update(
49
+ {
50
+ CoreTypes.NUMBER,
51
+ CoreTypes.INTEGER,
52
+ CoreTypes.STRING,
53
+ CoreTypes.BOOLEAN,
54
+ CoreTypes.DICTIONARY,
55
+ CoreTypes.ARRAY,
56
+ CoreTypes.ANYTHING,
57
+ CoreTypes.BINARY,
58
+ CoreTypes.OBJECT,
59
+ CoreTypes.DATETIME,
60
+ CoreTypes.DATE,
61
+ }
62
+ )
63
+ all_schemas: list[ObjectSchema] = []
64
+ all_schemas.extend(type_schemas)
65
+ all_schemas.extend(core_schemas)
66
+ all_schemas.extend(contrib_schemas)
67
+ all_schemas.extend(user_schemas)
68
+
69
+ for source, schemas in (
70
+ ('type_schemas', type_schemas),
71
+ ('core_schemas', core_schemas),
72
+ ('contrib_schemas', contrib_schemas),
73
+ ('user_schemas', user_schemas),
74
+ ):
75
+ for _schema in schemas:
76
+ for _dependency in self.get_dependency_type_names(_schema):
77
+ _dependencies = [_dependency]
78
+ if '|' in _dependency:
79
+ _dependencies = [dep.strip() for dep in _dependency.split('|')]
80
+
81
+ for _d in _dependencies:
82
+ if _d not in _defined_schemas:
83
+ exc_msg = f'Class {_d} ({source}) is undefined! This class is set as dependency for {_schema.title}' # noqa: E501
84
+ raise AmsdalValidationError(exc_msg)
85
+
86
+ @classmethod
87
+ def get_dependency_type_names(cls, schema: ObjectSchema) -> set[str]:
88
+ """
89
+ Returns a set of dependency type names for the given schema.
90
+
91
+ This method extracts and returns a set of type names that the given schema depends on. It includes the schema's
92
+ own type, the types of its properties, and the types of items within array or dictionary properties.
93
+
94
+ Args:
95
+ schema (ObjectSchema): The schema for which to get dependency type names.
96
+
97
+ Returns:
98
+ set[str]: A set of dependency type names for the given schema.
99
+ """
100
+ _dependencies: set[str] = {
101
+ schema.type,
102
+ }
103
+
104
+ for _property in schema.properties.values() if schema.properties else []:
105
+ if cls._is_enum(_property):
106
+ continue
107
+
108
+ _dependencies.add(_property.type)
109
+
110
+ if _property.type == CoreTypes.ARRAY and isinstance(_property.items, TypeData):
111
+ if not cls._is_enum(_property.items):
112
+ _dependencies.add(_property.items.type)
113
+ elif _property.type == CoreTypes.DICTIONARY:
114
+ if isinstance(_property.items, LegacyDictSchema):
115
+ _dependencies.add(_property.items.key_type)
116
+ _dependencies.add(_property.items.value_type)
117
+ elif isinstance(_property.items, DictSchema):
118
+ if not cls._is_enum(_property.items.key):
119
+ _dependencies.add(_property.items.key.type)
120
+ if not cls._is_enum(_property.items.value):
121
+ _dependencies.add(_property.items.value.type)
122
+
123
+ # remove self reference
124
+ _dependencies.discard(schema.title)
125
+
126
+ return _dependencies
127
+
128
+ @classmethod
129
+ def _is_enum(cls, _type: TypeData) -> bool:
130
+ return bool(hasattr(_type, 'enum') and _type.enum and _type.options)
@@ -0,0 +1,45 @@
1
+ from amsdal_utils.models.data_models.core import TypeData
2
+ from amsdal_utils.schemas.schema import ObjectSchema as ObjectSchema
3
+
4
+ class CheckDependenciesMixin:
5
+ """
6
+ Mixin class to check dependencies among schemas.
7
+
8
+ This class provides methods to check if all dependencies for a given set of schemas are defined. It raises an
9
+ `AmsdalValidationError` if any dependency is not defined.
10
+ """
11
+ def check_dependencies(self, type_schemas: list[ObjectSchema], core_schemas: list[ObjectSchema], contrib_schemas: list[ObjectSchema], user_schemas: list[ObjectSchema]) -> None:
12
+ """
13
+ Checks if all dependencies for the given schemas are defined.
14
+
15
+ This method verifies that all dependencies for the provided type, core, contrib, and user schemas are defined.
16
+ If any dependency is not defined, it raises an `AmsdalValidationError`.
17
+
18
+ Args:
19
+ type_schemas (list[ObjectSchema]): A list of type schemas to check.
20
+ core_schemas (list[ObjectSchema]): A list of core schemas to check.
21
+ contrib_schemas (list[ObjectSchema]): A list of contrib schemas to check.
22
+ user_schemas (list[ObjectSchema]): A list of user schemas to check.
23
+
24
+ Raises:
25
+ AmsdalValidationError: If any dependency is not defined.
26
+
27
+ Returns:
28
+ None
29
+ """
30
+ @classmethod
31
+ def get_dependency_type_names(cls, schema: ObjectSchema) -> set[str]:
32
+ """
33
+ Returns a set of dependency type names for the given schema.
34
+
35
+ This method extracts and returns a set of type names that the given schema depends on. It includes the schema's
36
+ own type, the types of its properties, and the types of items within array or dictionary properties.
37
+
38
+ Args:
39
+ schema (ObjectSchema): The schema for which to get dependency type names.
40
+
41
+ Returns:
42
+ set[str]: A set of dependency type names for the given schema.
43
+ """
44
+ @classmethod
45
+ def _is_enum(cls, _type: TypeData) -> bool: ...
@@ -0,0 +1,96 @@
1
+ from amsdal_models.errors import AmsdalValidationError
2
+ from amsdal_utils.schemas.schema import ObjectSchema
3
+
4
+
5
+ class VerifySchemasMixin:
6
+ """
7
+ Mixin class to verify schemas for uniqueness and property consistency.
8
+
9
+ This class provides methods to verify that schemas are unique and that their properties are consistent. It raises
10
+ an `AmsdalValidationError` if any schema is duplicated or if any required or unique property is missing.
11
+ """
12
+
13
+ def verify_schemas(
14
+ self,
15
+ type_schemas: list[ObjectSchema],
16
+ core_schemas: list[ObjectSchema],
17
+ contrib_schemas: list[ObjectSchema],
18
+ user_schemas: list[ObjectSchema],
19
+ ) -> None:
20
+ """
21
+ Verifies the provided schemas for uniqueness and property consistency.
22
+
23
+ This method checks that the provided type, core, contrib, and user schemas are unique and that their properties
24
+ are consistent. It raises an `AmsdalValidationError` if any schema is duplicated or if any required or unique
25
+ property is missing.
26
+
27
+ Args:
28
+ type_schemas (list[ObjectSchema]): A list of type schemas to verify.
29
+ core_schemas (list[ObjectSchema]): A list of core schemas to verify.
30
+ contrib_schemas (list[ObjectSchema]): A list of contrib schemas to verify.
31
+ user_schemas (list[ObjectSchema]): A list of user schemas to verify.
32
+
33
+ Raises:
34
+ AmsdalValidationError: If any schema is duplicated or if any required or unique property is missing.
35
+
36
+ Returns:
37
+ None
38
+ """
39
+ self._verify_unique_schemas(type_schemas, core_schemas, contrib_schemas, user_schemas)
40
+ self._verify_properties(type_schemas, core_schemas, contrib_schemas, user_schemas)
41
+
42
+ @staticmethod
43
+ def _verify_unique_schemas(
44
+ type_schemas: list[ObjectSchema],
45
+ core_schemas: list[ObjectSchema],
46
+ contrib_schemas: list[ObjectSchema],
47
+ user_schemas: list[ObjectSchema],
48
+ ) -> None:
49
+ _unique_schemas: dict[str, str] = {}
50
+
51
+ for source, schemas in (
52
+ ('type_schemas', type_schemas),
53
+ ('core_schemas', core_schemas),
54
+ ('contrib_schemas', contrib_schemas),
55
+ ('user_schemas', user_schemas),
56
+ ):
57
+ for _schema in schemas:
58
+ if _schema.title in _unique_schemas:
59
+ msg = f"Schema '{source}'.'{_schema.title}' is duplicated (already registered in {_unique_schemas[_schema.title]})." # noqa: E501
60
+ raise AmsdalValidationError(msg)
61
+
62
+ _unique_schemas[_schema.title] = source
63
+
64
+ @staticmethod
65
+ def _verify_properties(
66
+ type_schemas: list[ObjectSchema],
67
+ core_schemas: list[ObjectSchema],
68
+ contrib_schemas: list[ObjectSchema],
69
+ user_schemas: list[ObjectSchema],
70
+ ) -> None:
71
+ all_schemas: list[ObjectSchema] = []
72
+ all_schemas.extend(type_schemas)
73
+ all_schemas.extend(core_schemas)
74
+ all_schemas.extend(contrib_schemas)
75
+ all_schemas.extend(user_schemas)
76
+
77
+ for _schema in all_schemas:
78
+ for _field in ['required', 'indexed']:
79
+ for _required_property in getattr(_schema, _field, None) or []:
80
+ if _required_property not in (_schema.properties or {}):
81
+ exc_msg = (
82
+ f'Property {_required_property} marked as {_field} '
83
+ f"but wasn't found in class schema's properties."
84
+ )
85
+
86
+ raise AmsdalValidationError(exc_msg)
87
+
88
+ for unique in getattr(_schema, 'unique', None) or []:
89
+ for unique_property in unique:
90
+ if unique_property not in (_schema.properties or {}):
91
+ exc_msg = (
92
+ f"Property {unique_property} marked is used in 'unique' "
93
+ f"but wasn't found in class schema's properties."
94
+ )
95
+
96
+ raise AmsdalValidationError(exc_msg)
@@ -0,0 +1,33 @@
1
+ from amsdal_utils.schemas.schema import ObjectSchema as ObjectSchema
2
+
3
+ class VerifySchemasMixin:
4
+ """
5
+ Mixin class to verify schemas for uniqueness and property consistency.
6
+
7
+ This class provides methods to verify that schemas are unique and that their properties are consistent. It raises
8
+ an `AmsdalValidationError` if any schema is duplicated or if any required or unique property is missing.
9
+ """
10
+ def verify_schemas(self, type_schemas: list[ObjectSchema], core_schemas: list[ObjectSchema], contrib_schemas: list[ObjectSchema], user_schemas: list[ObjectSchema]) -> None:
11
+ """
12
+ Verifies the provided schemas for uniqueness and property consistency.
13
+
14
+ This method checks that the provided type, core, contrib, and user schemas are unique and that their properties
15
+ are consistent. It raises an `AmsdalValidationError` if any schema is duplicated or if any required or unique
16
+ property is missing.
17
+
18
+ Args:
19
+ type_schemas (list[ObjectSchema]): A list of type schemas to verify.
20
+ core_schemas (list[ObjectSchema]): A list of core schemas to verify.
21
+ contrib_schemas (list[ObjectSchema]): A list of contrib schemas to verify.
22
+ user_schemas (list[ObjectSchema]): A list of user schemas to verify.
23
+
24
+ Raises:
25
+ AmsdalValidationError: If any schema is duplicated or if any required or unique property is missing.
26
+
27
+ Returns:
28
+ None
29
+ """
30
+ @staticmethod
31
+ def _verify_unique_schemas(type_schemas: list[ObjectSchema], core_schemas: list[ObjectSchema], contrib_schemas: list[ObjectSchema], user_schemas: list[ObjectSchema]) -> None: ...
32
+ @staticmethod
33
+ def _verify_properties(type_schemas: list[ObjectSchema], core_schemas: list[ObjectSchema], contrib_schemas: list[ObjectSchema], user_schemas: list[ObjectSchema]) -> None: ...