amsdal 0.3.3__cp311-cp311-macosx_10_9_universal2.whl → 0.5.29__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.
- amsdal/Third-Party Materials - AMSDAL Dependencies - License Notices.md +56 -2
- amsdal/__about__.py +1 -1
- amsdal/__init__.py +20 -0
- amsdal/__init__.pyi +9 -0
- amsdal/__migrations__/0000_initial.py +23 -190
- amsdal/__migrations__/0001_create_class_file.py +61 -0
- amsdal/__migrations__/0002_create_class_file.py +109 -0
- amsdal/__migrations__/0003_update_class_file.py +91 -0
- amsdal/__migrations__/0004_update_class_file.py +45 -0
- amsdal/cloud/__init__.cpython-311-darwin.so +0 -0
- amsdal/cloud/client.cpython-311-darwin.so +0 -0
- amsdal/cloud/constants.cpython-311-darwin.so +0 -0
- amsdal/cloud/enums.cpython-311-darwin.so +0 -0
- amsdal/cloud/models/__init__.cpython-311-darwin.so +0 -0
- amsdal/cloud/models/base.cpython-311-darwin.so +0 -0
- amsdal/cloud/services/__init__.cpython-311-darwin.so +0 -0
- amsdal/cloud/services/actions/__init__.cpython-311-darwin.so +0 -0
- amsdal/cloud/services/actions/add_allowlist_ip.cpython-311-darwin.so +0 -0
- amsdal/cloud/services/actions/add_basic_auth.cpython-311-darwin.so +0 -0
- amsdal/cloud/services/actions/add_dependency.cpython-311-darwin.so +0 -0
- amsdal/cloud/services/actions/add_secret.cpython-311-darwin.so +0 -0
- amsdal/cloud/services/actions/base.cpython-311-darwin.so +0 -0
- amsdal/cloud/services/actions/create_deploy.cpython-311-darwin.so +0 -0
- amsdal/cloud/services/actions/create_env.cpython-311-darwin.so +0 -0
- amsdal/cloud/services/actions/create_session.cpython-311-darwin.so +0 -0
- amsdal/cloud/services/actions/delete_allowlist_ip.cpython-311-darwin.so +0 -0
- amsdal/cloud/services/actions/delete_basic_auth.cpython-311-darwin.so +0 -0
- amsdal/cloud/services/actions/delete_dependency.cpython-311-darwin.so +0 -0
- amsdal/cloud/services/actions/delete_env.cpython-311-darwin.so +0 -0
- amsdal/cloud/services/actions/delete_secret.cpython-311-darwin.so +0 -0
- amsdal/cloud/services/actions/destroy_deploy.cpython-311-darwin.so +0 -0
- amsdal/cloud/services/actions/expose_db.cpython-311-darwin.so +0 -0
- amsdal/cloud/services/actions/get_basic_auth_credentials.cpython-311-darwin.so +0 -0
- amsdal/cloud/services/actions/get_monitoring_info.cpython-311-darwin.so +0 -0
- amsdal/cloud/services/actions/list_dependencies.cpython-311-darwin.so +0 -0
- amsdal/cloud/services/actions/list_deploys.cpython-311-darwin.so +0 -0
- amsdal/cloud/services/actions/list_envs.cpython-311-darwin.so +0 -0
- amsdal/cloud/services/actions/list_secrets.cpython-311-darwin.so +0 -0
- amsdal/cloud/services/actions/manager.cpython-311-darwin.so +0 -0
- amsdal/cloud/services/actions/signup_action.cpython-311-darwin.so +0 -0
- amsdal/cloud/services/actions/update_deploy.cpython-311-darwin.so +0 -0
- amsdal/cloud/services/auth/__init__.cpython-311-darwin.so +0 -0
- amsdal/cloud/services/auth/base.cpython-311-darwin.so +0 -0
- amsdal/cloud/services/auth/credentials.cpython-311-darwin.so +0 -0
- amsdal/cloud/services/auth/credentials.pyi +0 -1
- amsdal/cloud/services/auth/manager.cpython-311-darwin.so +0 -0
- amsdal/cloud/services/auth/signup_service.cpython-311-darwin.so +0 -0
- amsdal/cloud/services/auth/token.cpython-311-darwin.so +0 -0
- amsdal/cloud/services/auth/token.pyi +0 -1
- amsdal/configs/main.py +40 -20
- amsdal/configs/main.pyi +19 -18
- amsdal/contrib/__init__.cpython-311-darwin.so +0 -0
- amsdal/contrib/auth/errors.py +36 -0
- amsdal/contrib/auth/errors.pyi +12 -0
- amsdal/contrib/auth/fixtures/basic_permissions.json +64 -0
- amsdal/contrib/auth/lifecycle/consumer.py +13 -13
- amsdal/contrib/auth/lifecycle/consumer.pyi +3 -0
- amsdal/contrib/auth/migrations/0000_initial.py +69 -31
- amsdal/contrib/auth/migrations/0001_add_mfa_support.py +188 -0
- amsdal/contrib/auth/models/__init__.py +1 -0
- amsdal/contrib/auth/models/backup_code.py +85 -0
- amsdal/contrib/auth/models/email_mfa_device.py +108 -0
- amsdal/contrib/auth/models/login_session.py +235 -0
- amsdal/contrib/auth/models/mfa_device.py +86 -0
- amsdal/contrib/auth/models/permission.py +23 -0
- amsdal/contrib/auth/models/sms_device.py +113 -0
- amsdal/contrib/auth/models/totp_device.py +58 -0
- amsdal/contrib/auth/models/user.py +156 -0
- amsdal/contrib/auth/services/__init__.py +1 -0
- amsdal/contrib/auth/services/mfa_device_service.py +544 -0
- amsdal/contrib/auth/services/mfa_device_service.pyi +216 -0
- amsdal/contrib/auth/services/totp_service.py +358 -0
- amsdal/contrib/auth/services/totp_service.pyi +158 -0
- amsdal/contrib/auth/settings.py +8 -0
- amsdal/contrib/auth/settings.pyi +8 -0
- amsdal/contrib/auth/transactions/__init__.py +1 -0
- amsdal/contrib/auth/transactions/mfa_device_transactions.py +463 -0
- amsdal/contrib/auth/transactions/mfa_device_transactions.pyi +226 -0
- amsdal/contrib/auth/transactions/totp_transactions.py +206 -0
- amsdal/contrib/auth/transactions/totp_transactions.pyi +113 -0
- amsdal/contrib/auth/utils/__init__.py +0 -0
- amsdal/contrib/auth/utils/__init__.pyi +0 -0
- amsdal/contrib/auth/utils/mfa.py +257 -0
- amsdal/contrib/auth/utils/mfa.pyi +119 -0
- amsdal/contrib/frontend_configs/conversion/convert.py +85 -25
- amsdal/contrib/frontend_configs/conversion/convert.pyi +0 -1
- amsdal/contrib/frontend_configs/lifecycle/consumer.py +32 -13
- amsdal/contrib/frontend_configs/lifecycle/consumer.pyi +1 -1
- amsdal/contrib/frontend_configs/migrations/0000_initial.py +167 -195
- amsdal/contrib/frontend_configs/migrations/0001_update_frontend_control_config.py +245 -0
- amsdal/contrib/frontend_configs/migrations/0002_add_button_and_invoke_actions.py +352 -0
- amsdal/contrib/frontend_configs/migrations/0003_create_class_frontendconfigdashboardelement.py +145 -0
- amsdal/contrib/frontend_configs/models/__init__.py +0 -0
- amsdal/contrib/frontend_configs/models/frontend_activator_config.py +22 -0
- amsdal/contrib/frontend_configs/models/frontend_config_async_validator.py +11 -0
- amsdal/contrib/frontend_configs/models/frontend_config_control_action.py +110 -0
- amsdal/contrib/frontend_configs/models/frontend_config_dashboard.py +51 -0
- amsdal/contrib/frontend_configs/models/frontend_config_group_validator.py +21 -0
- amsdal/contrib/frontend_configs/models/frontend_config_option.py +12 -0
- amsdal/contrib/frontend_configs/models/frontend_config_skip_none_base.py +17 -0
- amsdal/contrib/frontend_configs/models/frontend_config_slider_option.py +13 -0
- amsdal/contrib/frontend_configs/models/frontend_config_text_mask.py +14 -0
- amsdal/contrib/frontend_configs/models/frontend_config_validator.py +28 -0
- amsdal/contrib/frontend_configs/models/frontend_control_config.py +110 -0
- amsdal/contrib/frontend_configs/models/frontend_model_config.py +14 -0
- amsdal/errors.py +0 -3
- amsdal/errors.pyi +0 -1
- amsdal/fixtures/__init__.cpython-311-darwin.so +0 -0
- amsdal/fixtures/manager.cpython-311-darwin.so +0 -0
- amsdal/fixtures/manager.pyi +73 -123
- amsdal/fixtures/utils.cpython-311-darwin.so +0 -0
- amsdal/fixtures/utils.pyi +9 -0
- amsdal/manager.cpython-311-darwin.so +0 -0
- amsdal/manager.pyi +9 -96
- amsdal/mixins/__init__.cpython-311-darwin.so +0 -0
- amsdal/mixins/class_versions_mixin.cpython-311-darwin.so +0 -0
- amsdal/models/__init__.py +19 -0
- amsdal/models/core/__init__.py +0 -0
- amsdal/models/core/class_object.py +38 -0
- amsdal/models/core/class_property.py +26 -0
- amsdal/models/core/file.py +243 -0
- amsdal/models/core/fixture.py +25 -0
- amsdal/models/core/option.py +11 -0
- amsdal/models/core/storage_metadata.py +15 -0
- amsdal/models/core/validator.py +12 -0
- amsdal/models/mixins.py +31 -0
- amsdal/models/types/__init__.py +0 -0
- amsdal/models/types/object.py +26 -0
- amsdal/queryset/__init__.py +21 -0
- amsdal/queryset/__init__.pyi +6 -0
- amsdal/schemas/core/class_object/model.json +20 -0
- amsdal/schemas/core/class_property/model.json +19 -0
- amsdal/schemas/core/file/properties/from_file.py +1 -1
- amsdal/schemas/core/file/properties/validate_data.py +3 -4
- amsdal/schemas/core/storage_metadata/model.json +52 -0
- amsdal/schemas/interfaces.py +25 -0
- amsdal/schemas/interfaces.pyi +20 -0
- amsdal/schemas/manager.cpython-311-darwin.so +0 -0
- amsdal/schemas/manager.py +0 -116
- amsdal/schemas/manager.pyi +0 -65
- amsdal/schemas/mixins/__init__.py +0 -0
- amsdal/schemas/mixins/__init__.pyi +0 -0
- amsdal/schemas/mixins/check_dependencies_mixin.py +130 -0
- amsdal/schemas/mixins/check_dependencies_mixin.pyi +45 -0
- amsdal/schemas/mixins/verify_schemas_mixin.py +96 -0
- amsdal/schemas/mixins/verify_schemas_mixin.pyi +33 -0
- amsdal/schemas/repository.py +84 -0
- amsdal/schemas/repository.pyi +22 -0
- amsdal/schemas/utils.py +16 -0
- amsdal/schemas/utils.pyi +10 -0
- amsdal/services/__init__.py +11 -0
- amsdal/services/__init__.pyi +4 -0
- amsdal/services/external_connections.py +262 -0
- amsdal/services/external_connections.pyi +190 -0
- amsdal/services/external_model_generator.py +350 -0
- amsdal/services/external_model_generator.pyi +134 -0
- amsdal/services/transaction_execution.cpython-311-darwin.so +0 -0
- amsdal/services/transaction_execution.pyi +2 -1
- amsdal/storages/__init__.py +20 -0
- amsdal/storages/__init__.pyi +8 -0
- amsdal/storages/file_system.py +214 -0
- amsdal/storages/file_system.pyi +36 -0
- amsdal/transactions/__init__.py +13 -0
- amsdal/transactions/__init__.pyi +4 -0
- amsdal/utils/rollback/__init__.py +99 -54
- amsdal/utils/rollback/__init__.pyi +6 -0
- amsdal/utils/tests/enums.py +0 -2
- amsdal/utils/tests/helpers.py +253 -231
- amsdal/utils/tests/migrations.py +157 -0
- {amsdal-0.3.3.dist-info → amsdal-0.5.29.dist-info}/METADATA +17 -10
- amsdal-0.5.29.dist-info/RECORD +276 -0
- {amsdal-0.3.3.dist-info → amsdal-0.5.29.dist-info}/WHEEL +1 -1
- amsdal/__migrations__/0001_datetime_type.py +0 -18
- amsdal/__migrations__/0002_fixture_order.py +0 -40
- amsdal/__migrations__/0003_schema_type_in_class_meta.py +0 -56
- amsdal/contrib/auth/models/login_session/hooks/pre_init.py +0 -68
- amsdal/contrib/auth/models/login_session/model.json +0 -23
- amsdal/contrib/auth/models/login_session/modifiers/display_name.py +0 -11
- amsdal/contrib/auth/models/permission/fixtures/basic_permissions.json +0 -62
- amsdal/contrib/auth/models/permission/model.json +0 -18
- amsdal/contrib/auth/models/permission/modifiers/display_name.py +0 -11
- amsdal/contrib/auth/models/user/hooks/post_init.py +0 -76
- amsdal/contrib/auth/models/user/hooks/pre_create.py +0 -8
- amsdal/contrib/auth/models/user/model.json +0 -25
- amsdal/contrib/auth/models/user/modifiers/display_name.py +0 -19
- amsdal/contrib/frontend_configs/models/frontend_activator_config/model.json +0 -11
- amsdal/contrib/frontend_configs/models/frontend_config_async_validator/model.json +0 -11
- amsdal/contrib/frontend_configs/models/frontend_config_group_validator/model.json +0 -52
- amsdal/contrib/frontend_configs/models/frontend_config_option/model.json +0 -15
- amsdal/contrib/frontend_configs/models/frontend_config_skip_none_base/model.json +0 -6
- amsdal/contrib/frontend_configs/models/frontend_config_skip_none_base/properties/model_dump.py +0 -13
- amsdal/contrib/frontend_configs/models/frontend_config_slider_option/model.json +0 -19
- amsdal/contrib/frontend_configs/models/frontend_config_text_mask/model.json +0 -26
- amsdal/contrib/frontend_configs/models/frontend_config_validator/model.json +0 -41
- amsdal/contrib/frontend_configs/models/frontend_control_config/model.json +0 -250
- amsdal/contrib/frontend_configs/models/frontend_model_config/fixtures/permissions.json +0 -24
- amsdal/contrib/frontend_configs/models/frontend_model_config/model.json +0 -17
- amsdal/contrib/frontend_configs/models/frontent_config_control_action/model.json +0 -54
- amsdal/contrib/frontend_configs/models/frontent_config_control_action/properties/action_validate.py +0 -33
- amsdal/migration/__init__.cpython-311-darwin.so +0 -0
- amsdal/migration/base_migration_schemas.cpython-311-darwin.so +0 -0
- amsdal/migration/base_migration_schemas.pyi +0 -120
- amsdal/migration/data_classes.cpython-311-darwin.so +0 -0
- amsdal/migration/data_classes.pyi +0 -172
- amsdal/migration/executors/__init__.cpython-311-darwin.so +0 -0
- amsdal/migration/executors/base.cpython-311-darwin.so +0 -0
- amsdal/migration/executors/base.pyi +0 -118
- amsdal/migration/executors/default_executor.cpython-311-darwin.so +0 -0
- amsdal/migration/executors/default_executor.pyi +0 -184
- amsdal/migration/executors/state_executor.cpython-311-darwin.so +0 -0
- amsdal/migration/executors/state_executor.pyi +0 -78
- amsdal/migration/file_migration_executor.cpython-311-darwin.so +0 -0
- amsdal/migration/file_migration_executor.pyi +0 -68
- amsdal/migration/file_migration_generator.cpython-311-darwin.so +0 -0
- amsdal/migration/file_migration_generator.pyi +0 -139
- amsdal/migration/file_migration_store.cpython-311-darwin.so +0 -0
- amsdal/migration/file_migration_store.pyi +0 -61
- amsdal/migration/file_migration_writer.cpython-311-darwin.so +0 -0
- amsdal/migration/file_migration_writer.pyi +0 -73
- amsdal/migration/migrations.cpython-311-darwin.so +0 -0
- amsdal/migration/migrations.pyi +0 -166
- amsdal/migration/migrations_loader.cpython-311-darwin.so +0 -0
- amsdal/migration/migrations_loader.pyi +0 -32
- amsdal/migration/schemas_loaders.cpython-311-darwin.so +0 -0
- amsdal/migration/schemas_loaders.pyi +0 -37
- amsdal/migration/templates/data_migration.tmpl +0 -18
- amsdal/migration/templates/dict_validator.tmpl +0 -4
- amsdal/migration/templates/migration.tmpl +0 -6
- amsdal/migration/templates/model_class.tmpl +0 -8
- amsdal/migration/templates/model_class_layout.tmpl +0 -24
- amsdal/migration/templates/options_validator.tmpl +0 -4
- amsdal/migration/utils.cpython-311-darwin.so +0 -0
- amsdal/migration/utils.pyi +0 -58
- amsdal/mixins/build_mixin.cpython-311-darwin.so +0 -0
- amsdal/mixins/build_mixin.pyi +0 -78
- amsdal/schemas/core/class_object_meta/model.json +0 -59
- amsdal/schemas/core/class_property_meta/model.json +0 -23
- amsdal/services/__init__.cpython-311-darwin.so +0 -0
- amsdal-0.3.3.dist-info/RECORD +0 -257
- amsdal-0.3.3.dist-info/licenses/LICENSE.txt +0 -107
- /amsdal/{migration → contrib/auth/services}/__init__.pyi +0 -0
- /amsdal/{migration/executors → contrib/auth/transactions}/__init__.pyi +0 -0
- {amsdal-0.3.3.dist-info → amsdal-0.5.29.dist-info/licenses}/LICENSE.txt +0 -0
- {amsdal-0.3.3.dist-info → amsdal-0.5.29.dist-info}/top_level.txt +0 -0
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
|
amsdal/schemas/manager.pyi
CHANGED
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
from _typeshed import Incomplete
|
|
2
|
-
from amsdal.configs.main import settings as settings
|
|
3
|
-
from amsdal_utils.models.data_models.schema import ObjectSchema as ObjectSchema
|
|
4
|
-
from amsdal_utils.models.enums import SchemaTypes
|
|
5
|
-
from amsdal_utils.utils.singleton import Singleton
|
|
6
|
-
|
|
7
|
-
class SchemaManager(metaclass=Singleton):
|
|
8
|
-
"""
|
|
9
|
-
Manages schema operations including retrieval, invalidation, and sorting.
|
|
10
|
-
|
|
11
|
-
This class handles various schema-related operations such as invalidating user schemas,
|
|
12
|
-
retrieving schemas by name or type, and sorting schemas based on predefined rules.
|
|
13
|
-
"""
|
|
14
|
-
_schema_manager_handler: Incomplete
|
|
15
|
-
def __init__(self) -> None: ...
|
|
16
|
-
def invalidate_user_schemas(self) -> None:
|
|
17
|
-
"""
|
|
18
|
-
Invalidates user schemas.
|
|
19
|
-
|
|
20
|
-
This method calls the handler to invalidate all user schemas, ensuring that any cached or outdated schemas
|
|
21
|
-
are refreshed.
|
|
22
|
-
|
|
23
|
-
Returns:
|
|
24
|
-
None
|
|
25
|
-
"""
|
|
26
|
-
def class_schemas(self) -> list[tuple[ObjectSchema, SchemaTypes]]:
|
|
27
|
-
"""
|
|
28
|
-
Returns a list of tuples containing object schemas and their types.
|
|
29
|
-
|
|
30
|
-
This method retrieves and sorts various schemas managed by the schema manager handler.
|
|
31
|
-
The schemas are categorized into types, core, user, and contrib schemas.
|
|
32
|
-
|
|
33
|
-
Returns:
|
|
34
|
-
list[tuple[ObjectSchema, SchemaTypes]]: A list of tuples where each tuple contains an object schema
|
|
35
|
-
and its corresponding type.
|
|
36
|
-
"""
|
|
37
|
-
@staticmethod
|
|
38
|
-
def _sort_key_for_schema(schema: ObjectSchema) -> int: ...
|
|
39
|
-
def get_schema_by_name(self, title: str, schema_type: SchemaTypes | None = None) -> ObjectSchema | None:
|
|
40
|
-
"""
|
|
41
|
-
Retrieves a schema by its title and optional type.
|
|
42
|
-
|
|
43
|
-
This method searches for a schema with the specified title and optional type
|
|
44
|
-
among the schemas managed by the schema manager handler.
|
|
45
|
-
|
|
46
|
-
Args:
|
|
47
|
-
title (str): The title of the schema to be retrieved.
|
|
48
|
-
schema_type (SchemaTypes | None, optional): The type of the schema to be retrieved. Defaults to None.
|
|
49
|
-
|
|
50
|
-
Returns:
|
|
51
|
-
ObjectSchema | None: The schema with the specified title and type, or None if not found.
|
|
52
|
-
"""
|
|
53
|
-
def get_schemas(self, schema_type: SchemaTypes | None = None) -> list[ObjectSchema]:
|
|
54
|
-
"""
|
|
55
|
-
Retrieves schemas based on the provided type.
|
|
56
|
-
|
|
57
|
-
This method returns a list of schemas filtered by the specified type. If no type is provided,
|
|
58
|
-
it returns all schemas managed by the schema manager handler.
|
|
59
|
-
|
|
60
|
-
Args:
|
|
61
|
-
schema_type (SchemaTypes | None, optional): The type of schemas to retrieve. Defaults to None.
|
|
62
|
-
|
|
63
|
-
Returns:
|
|
64
|
-
list[ObjectSchema]: A list of schemas filtered by the specified type, or all schemas if no type is provided.
|
|
65
|
-
"""
|
|
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: ...
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
from amsdal_utils.models.enums import ModuleType
|
|
2
|
+
from amsdal_utils.schemas.interfaces import BaseDependsSchemaLoader
|
|
3
|
+
from amsdal_utils.schemas.interfaces import BaseSchemaLoader
|
|
4
|
+
from amsdal_utils.schemas.schema import ObjectSchema
|
|
5
|
+
|
|
6
|
+
from amsdal.schemas.mixins.check_dependencies_mixin import CheckDependenciesMixin
|
|
7
|
+
from amsdal.schemas.mixins.verify_schemas_mixin import VerifySchemasMixin
|
|
8
|
+
from amsdal.schemas.utils import ModelModuleInfo
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class SchemaRepository(VerifySchemasMixin, CheckDependenciesMixin):
|
|
12
|
+
type_schemas: list[ObjectSchema]
|
|
13
|
+
core_schemas: list[ObjectSchema]
|
|
14
|
+
contrib_schemas: list[ObjectSchema]
|
|
15
|
+
user_schemas: list[ObjectSchema]
|
|
16
|
+
|
|
17
|
+
def __init__(
|
|
18
|
+
self,
|
|
19
|
+
type_schema_loader: BaseSchemaLoader,
|
|
20
|
+
core_schema_loader: BaseSchemaLoader | BaseDependsSchemaLoader,
|
|
21
|
+
contrib_schema_loader: BaseSchemaLoader | BaseDependsSchemaLoader,
|
|
22
|
+
user_schema_loader: BaseSchemaLoader | BaseDependsSchemaLoader,
|
|
23
|
+
):
|
|
24
|
+
self._type_schema_loader = type_schema_loader
|
|
25
|
+
self._core_schema_loader = core_schema_loader
|
|
26
|
+
self._contrib_schema_loader = contrib_schema_loader
|
|
27
|
+
self._user_schema_loader = user_schema_loader
|
|
28
|
+
|
|
29
|
+
self.type_schemas = type_schema_loader.load()
|
|
30
|
+
self.core_schemas = self._load_schemas(core_schema_loader)
|
|
31
|
+
self.contrib_schemas = self._load_schemas(contrib_schema_loader, self.core_schemas)
|
|
32
|
+
self.user_schemas = self._load_schemas(user_schema_loader, self.core_schemas, self.contrib_schemas)
|
|
33
|
+
|
|
34
|
+
self.verify_schemas(
|
|
35
|
+
self.type_schemas,
|
|
36
|
+
self.core_schemas,
|
|
37
|
+
self.contrib_schemas,
|
|
38
|
+
self.user_schemas,
|
|
39
|
+
)
|
|
40
|
+
self.check_dependencies(
|
|
41
|
+
self.type_schemas,
|
|
42
|
+
self.core_schemas,
|
|
43
|
+
self.contrib_schemas,
|
|
44
|
+
self.user_schemas,
|
|
45
|
+
)
|
|
46
|
+
|
|
47
|
+
@property
|
|
48
|
+
def model_module_info(self) -> ModelModuleInfo:
|
|
49
|
+
_type_info = self._prepare_info(self._type_schema_loader.schemas_per_module)
|
|
50
|
+
_core_info = self._prepare_info(self._core_schema_loader.schemas_per_module)
|
|
51
|
+
_contrib_info = self._prepare_info(self._contrib_schema_loader.schemas_per_module)
|
|
52
|
+
_user_info = self._prepare_info(self._user_schema_loader.schemas_per_module)
|
|
53
|
+
|
|
54
|
+
return ModelModuleInfo(
|
|
55
|
+
info={
|
|
56
|
+
ModuleType.TYPE: _type_info,
|
|
57
|
+
ModuleType.CORE: _core_info,
|
|
58
|
+
ModuleType.CONTRIB: _contrib_info,
|
|
59
|
+
ModuleType.USER: _user_info,
|
|
60
|
+
},
|
|
61
|
+
)
|
|
62
|
+
|
|
63
|
+
def _load_schemas(
|
|
64
|
+
self,
|
|
65
|
+
loader: BaseSchemaLoader | BaseDependsSchemaLoader,
|
|
66
|
+
*extra_schemas: list[ObjectSchema],
|
|
67
|
+
) -> list[ObjectSchema]:
|
|
68
|
+
|
|
69
|
+
if isinstance(loader, BaseDependsSchemaLoader):
|
|
70
|
+
return loader.load(self.type_schemas, *extra_schemas)
|
|
71
|
+
else:
|
|
72
|
+
_schemas, _circular = loader.load_sorted()
|
|
73
|
+
return _schemas + _circular
|
|
74
|
+
|
|
75
|
+
@staticmethod
|
|
76
|
+
def _prepare_info(schemas_per_module: dict[str, list[ObjectSchema]]) -> dict[str, str]:
|
|
77
|
+
_info = {}
|
|
78
|
+
|
|
79
|
+
for module_path, schemas in schemas_per_module.items():
|
|
80
|
+
_info.update(
|
|
81
|
+
{_schema.title: module_path for _schema in schemas},
|
|
82
|
+
)
|
|
83
|
+
|
|
84
|
+
return _info
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
from _typeshed import Incomplete
|
|
2
|
+
from amsdal.schemas.mixins.check_dependencies_mixin import CheckDependenciesMixin as CheckDependenciesMixin
|
|
3
|
+
from amsdal.schemas.mixins.verify_schemas_mixin import VerifySchemasMixin as VerifySchemasMixin
|
|
4
|
+
from amsdal.schemas.utils import ModelModuleInfo as ModelModuleInfo
|
|
5
|
+
from amsdal_utils.schemas.interfaces import BaseDependsSchemaLoader, BaseSchemaLoader as BaseSchemaLoader
|
|
6
|
+
from amsdal_utils.schemas.schema import ObjectSchema as ObjectSchema
|
|
7
|
+
|
|
8
|
+
class SchemaRepository(VerifySchemasMixin, CheckDependenciesMixin):
|
|
9
|
+
type_schemas: list[ObjectSchema]
|
|
10
|
+
core_schemas: list[ObjectSchema]
|
|
11
|
+
contrib_schemas: list[ObjectSchema]
|
|
12
|
+
user_schemas: list[ObjectSchema]
|
|
13
|
+
_type_schema_loader: Incomplete
|
|
14
|
+
_core_schema_loader: Incomplete
|
|
15
|
+
_contrib_schema_loader: Incomplete
|
|
16
|
+
_user_schema_loader: Incomplete
|
|
17
|
+
def __init__(self, type_schema_loader: BaseSchemaLoader, core_schema_loader: BaseSchemaLoader | BaseDependsSchemaLoader, contrib_schema_loader: BaseSchemaLoader | BaseDependsSchemaLoader, user_schema_loader: BaseSchemaLoader | BaseDependsSchemaLoader) -> None: ...
|
|
18
|
+
@property
|
|
19
|
+
def model_module_info(self) -> ModelModuleInfo: ...
|
|
20
|
+
def _load_schemas(self, loader: BaseSchemaLoader | BaseDependsSchemaLoader, *extra_schemas: list[ObjectSchema]) -> list[ObjectSchema]: ...
|
|
21
|
+
@staticmethod
|
|
22
|
+
def _prepare_info(schemas_per_module: dict[str, list[ObjectSchema]]) -> dict[str, str]: ...
|
amsdal/schemas/utils.py
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
from typing import TypeAlias
|
|
2
|
+
|
|
3
|
+
from amsdal_utils.models.enums import ModuleType
|
|
4
|
+
|
|
5
|
+
ModulePathType: TypeAlias = str
|
|
6
|
+
ClassNameType: TypeAlias = str
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class ModelModuleInfo:
|
|
10
|
+
_info: dict[ModuleType, dict[ClassNameType, ModulePathType]]
|
|
11
|
+
|
|
12
|
+
def __init__(self, info: dict[ModuleType, dict[ClassNameType, ModulePathType]]) -> None:
|
|
13
|
+
self._info = info
|
|
14
|
+
|
|
15
|
+
def get_by_type(self, module_type: ModuleType) -> dict[ClassNameType, ModulePathType]:
|
|
16
|
+
return self._info.get(module_type, {})
|
amsdal/schemas/utils.pyi
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
from amsdal_utils.models.enums import ModuleType as ModuleType
|
|
2
|
+
from typing import TypeAlias
|
|
3
|
+
|
|
4
|
+
ModulePathType: TypeAlias = str
|
|
5
|
+
ClassNameType: TypeAlias = str
|
|
6
|
+
|
|
7
|
+
class ModelModuleInfo:
|
|
8
|
+
_info: dict[ModuleType, dict[ClassNameType, ModulePathType]]
|
|
9
|
+
def __init__(self, info: dict[ModuleType, dict[ClassNameType, ModulePathType]]) -> None: ...
|
|
10
|
+
def get_by_type(self, module_type: ModuleType) -> dict[ClassNameType, ModulePathType]: ...
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# AMSDAL services package
|
|
2
|
+
|
|
3
|
+
from amsdal.services.external_connections import ExternalConnectionManager
|
|
4
|
+
from amsdal.services.external_connections import ExternalDatabaseReader
|
|
5
|
+
from amsdal.services.external_model_generator import ExternalModelGenerator
|
|
6
|
+
|
|
7
|
+
__all__ = [
|
|
8
|
+
'ExternalConnectionManager',
|
|
9
|
+
'ExternalDatabaseReader',
|
|
10
|
+
'ExternalModelGenerator',
|
|
11
|
+
]
|
amsdal/services/__init__.pyi
CHANGED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
from amsdal.services.external_connections import ExternalConnectionManager as ExternalConnectionManager, ExternalDatabaseReader as ExternalDatabaseReader
|
|
2
|
+
from amsdal.services.external_model_generator import ExternalModelGenerator as ExternalModelGenerator
|
|
3
|
+
|
|
4
|
+
__all__ = ['ExternalConnectionManager', 'ExternalDatabaseReader', 'ExternalModelGenerator']
|