orionis 0.404.0__py3-none-any.whl → 0.406.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (165) hide show
  1. orionis/console/base/command.py +57 -50
  2. orionis/console/base/contracts/command.py +68 -0
  3. orionis/console/dynamic/contracts/progress_bar.py +3 -3
  4. orionis/console/dynamic/progress_bar.py +8 -8
  5. orionis/console/output/console.py +8 -2
  6. orionis/console/output/contracts/console.py +1 -1
  7. orionis/container/container.py +2 -2
  8. orionis/container/context/scope.py +4 -1
  9. orionis/container/contracts/service_provider.py +2 -2
  10. orionis/container/entities/binding.py +31 -44
  11. orionis/container/enums/lifetimes.py +22 -1
  12. orionis/container/facades/facade.py +1 -2
  13. orionis/container/providers/service_provider.py +2 -2
  14. orionis/foundation/application.py +542 -248
  15. orionis/foundation/config/app/entities/app.py +107 -90
  16. orionis/foundation/config/auth/entities/auth.py +4 -33
  17. orionis/foundation/config/cache/entities/cache.py +18 -41
  18. orionis/foundation/config/cache/entities/file.py +8 -35
  19. orionis/foundation/config/cache/entities/stores.py +17 -38
  20. orionis/foundation/config/cors/entities/cors.py +41 -54
  21. orionis/foundation/config/database/entities/connections.py +40 -56
  22. orionis/foundation/config/database/entities/database.py +11 -38
  23. orionis/foundation/config/database/entities/mysql.py +48 -76
  24. orionis/foundation/config/database/entities/oracle.py +30 -57
  25. orionis/foundation/config/database/entities/pgsql.py +45 -61
  26. orionis/foundation/config/database/entities/sqlite.py +26 -53
  27. orionis/foundation/config/filesystems/entitites/aws.py +28 -49
  28. orionis/foundation/config/filesystems/entitites/disks.py +27 -47
  29. orionis/foundation/config/filesystems/entitites/filesystems.py +15 -37
  30. orionis/foundation/config/filesystems/entitites/local.py +9 -35
  31. orionis/foundation/config/filesystems/entitites/public.py +14 -41
  32. orionis/foundation/config/logging/entities/channels.py +56 -86
  33. orionis/foundation/config/logging/entities/chunked.py +18 -10
  34. orionis/foundation/config/logging/entities/daily.py +17 -9
  35. orionis/foundation/config/logging/entities/hourly.py +15 -7
  36. orionis/foundation/config/logging/entities/logging.py +12 -18
  37. orionis/foundation/config/logging/entities/monthly.py +16 -8
  38. orionis/foundation/config/logging/entities/stack.py +15 -7
  39. orionis/foundation/config/logging/entities/weekly.py +15 -7
  40. orionis/foundation/config/logging/validators/path.py +6 -0
  41. orionis/foundation/config/mail/entities/file.py +9 -36
  42. orionis/foundation/config/mail/entities/mail.py +22 -40
  43. orionis/foundation/config/mail/entities/mailers.py +29 -44
  44. orionis/foundation/config/mail/entities/smtp.py +47 -48
  45. orionis/foundation/config/queue/entities/brokers.py +19 -41
  46. orionis/foundation/config/queue/entities/database.py +24 -46
  47. orionis/foundation/config/queue/entities/queue.py +28 -40
  48. orionis/foundation/config/roots/paths.py +272 -468
  49. orionis/foundation/config/session/entities/session.py +23 -53
  50. orionis/foundation/config/startup.py +165 -135
  51. orionis/foundation/config/testing/entities/testing.py +137 -122
  52. orionis/foundation/config/testing/enums/__init__.py +6 -2
  53. orionis/foundation/config/testing/enums/drivers.py +16 -0
  54. orionis/foundation/config/testing/enums/verbosity.py +18 -0
  55. orionis/foundation/contracts/application.py +152 -362
  56. orionis/foundation/providers/console_provider.py +24 -2
  57. orionis/foundation/providers/dumper_provider.py +24 -2
  58. orionis/foundation/providers/logger_provider.py +24 -2
  59. orionis/foundation/providers/path_resolver_provider.py +25 -2
  60. orionis/foundation/providers/progress_bar_provider.py +24 -2
  61. orionis/foundation/providers/testing_provider.py +39 -0
  62. orionis/foundation/providers/workers_provider.py +24 -2
  63. orionis/metadata/framework.py +1 -1
  64. orionis/services/environment/helpers/functions.py +1 -2
  65. orionis/services/environment/key/__init__.py +0 -0
  66. orionis/services/environment/key/key_generator.py +37 -0
  67. orionis/services/log/handlers/filename.py +64 -0
  68. orionis/services/log/handlers/size_rotating.py +9 -40
  69. orionis/services/log/handlers/timed_rotating.py +9 -41
  70. orionis/services/log/log_service.py +9 -52
  71. orionis/support/entities/__init__.py +0 -0
  72. orionis/support/entities/base.py +104 -0
  73. orionis/support/facades/testing.py +15 -0
  74. orionis/support/facades/workers.py +1 -1
  75. orionis/test/cases/asynchronous.py +0 -11
  76. orionis/test/cases/synchronous.py +0 -9
  77. orionis/test/contracts/dumper.py +11 -4
  78. orionis/test/contracts/kernel.py +5 -110
  79. orionis/test/contracts/logs.py +27 -65
  80. orionis/test/contracts/printer.py +16 -128
  81. orionis/test/contracts/test_result.py +100 -0
  82. orionis/test/contracts/unit_test.py +87 -150
  83. orionis/test/core/unit_test.py +608 -554
  84. orionis/test/entities/result.py +22 -2
  85. orionis/test/enums/__init__.py +0 -2
  86. orionis/test/enums/status.py +14 -9
  87. orionis/test/exceptions/config.py +9 -1
  88. orionis/test/exceptions/failure.py +34 -11
  89. orionis/test/exceptions/persistence.py +10 -2
  90. orionis/test/exceptions/runtime.py +9 -1
  91. orionis/test/exceptions/value.py +13 -1
  92. orionis/test/kernel.py +87 -289
  93. orionis/test/output/dumper.py +82 -18
  94. orionis/test/output/printer.py +399 -156
  95. orionis/test/records/logs.py +203 -82
  96. orionis/test/validators/__init__.py +33 -0
  97. orionis/test/validators/base_path.py +45 -0
  98. orionis/test/validators/execution_mode.py +45 -0
  99. orionis/test/validators/fail_fast.py +37 -0
  100. orionis/test/validators/folder_path.py +34 -0
  101. orionis/test/validators/module_name.py +31 -0
  102. orionis/test/validators/name_pattern.py +40 -0
  103. orionis/test/validators/pattern.py +36 -0
  104. orionis/test/validators/persistent.py +42 -0
  105. orionis/test/validators/persistent_driver.py +43 -0
  106. orionis/test/validators/print_result.py +37 -0
  107. orionis/test/validators/tags.py +37 -0
  108. orionis/test/validators/throw_exception.py +39 -0
  109. orionis/test/validators/verbosity.py +37 -0
  110. orionis/test/validators/web_report.py +35 -0
  111. orionis/test/validators/workers.py +31 -0
  112. orionis/test/view/render.py +48 -54
  113. {orionis-0.404.0.dist-info → orionis-0.406.0.dist-info}/METADATA +1 -1
  114. {orionis-0.404.0.dist-info → orionis-0.406.0.dist-info}/RECORD +160 -108
  115. tests/container/__init__.py +0 -0
  116. tests/container/context/__init__.py +0 -0
  117. tests/container/context/test_manager.py +27 -0
  118. tests/container/context/test_scope.py +23 -0
  119. tests/container/entities/__init__.py +0 -0
  120. tests/container/entities/test_binding.py +133 -0
  121. tests/container/enums/__init__.py +0 -0
  122. tests/container/enums/test_lifetimes.py +63 -0
  123. tests/container/facades/__init__.py +0 -0
  124. tests/container/facades/test_facade.py +61 -0
  125. tests/container/mocks/__init__.py +0 -0
  126. tests/container/mocks/mock_complex_classes.py +482 -0
  127. tests/container/mocks/mock_simple_classes.py +32 -0
  128. tests/container/providers/__init__.py +0 -0
  129. tests/container/providers/test_providers.py +48 -0
  130. tests/container/resolver/__init__.py +0 -0
  131. tests/container/resolver/test_resolver.py +55 -0
  132. tests/container/test_container.py +254 -0
  133. tests/container/test_singleton.py +98 -0
  134. tests/container/test_thread_safety.py +217 -0
  135. tests/container/validators/__init__.py +0 -0
  136. tests/container/validators/test_implements.py +140 -0
  137. tests/container/validators/test_is_abstract_class.py +99 -0
  138. tests/container/validators/test_is_callable.py +73 -0
  139. tests/container/validators/test_is_concrete_class.py +97 -0
  140. tests/container/validators/test_is_instance.py +105 -0
  141. tests/container/validators/test_is_not_subclass.py +117 -0
  142. tests/container/validators/test_is_subclass.py +115 -0
  143. tests/container/validators/test_is_valid_alias.py +113 -0
  144. tests/container/validators/test_lifetime.py +75 -0
  145. tests/foundation/config/logging/test_foundation_config_logging_chunked.py +12 -34
  146. tests/foundation/config/logging/test_foundation_config_logging_daily.py +11 -11
  147. tests/foundation/config/logging/test_foundation_config_logging_hourly.py +7 -8
  148. tests/foundation/config/logging/test_foundation_config_logging_monthly.py +7 -10
  149. tests/foundation/config/logging/test_foundation_config_logging_stack.py +6 -11
  150. tests/foundation/config/logging/test_foundation_config_logging_weekly.py +6 -5
  151. tests/foundation/config/testing/test_foundation_config_testing.py +1 -1
  152. tests/metadata/test_metadata_framework.py +18 -18
  153. tests/testing/test_testing_result.py +117 -117
  154. tests/testing/test_testing_unit.py +209 -209
  155. orionis/foundation/config/base.py +0 -112
  156. orionis/test/arguments/parser.py +0 -187
  157. orionis/test/contracts/parser.py +0 -43
  158. orionis/test/entities/arguments.py +0 -38
  159. orionis/test/enums/execution_mode.py +0 -16
  160. /orionis/{test/arguments → console/base/contracts}/__init__.py +0 -0
  161. /orionis/foundation/config/testing/enums/{test_mode.py → mode.py} +0 -0
  162. {orionis-0.404.0.dist-info → orionis-0.406.0.dist-info}/WHEEL +0 -0
  163. {orionis-0.404.0.dist-info → orionis-0.406.0.dist-info}/licenses/LICENCE +0 -0
  164. {orionis-0.404.0.dist-info → orionis-0.406.0.dist-info}/top_level.txt +0 -0
  165. {orionis-0.404.0.dist-info → orionis-0.406.0.dist-info}/zip-safe +0 -0
@@ -1,4 +1,4 @@
1
- from dataclasses import asdict, dataclass, field, fields
1
+ from dataclasses import dataclass, field
2
2
  from typing import Optional
3
3
  from orionis.foundation.config.database.enums import (
4
4
  OracleEncoding,
@@ -6,9 +6,10 @@ from orionis.foundation.config.database.enums import (
6
6
  )
7
7
  from orionis.foundation.exceptions import OrionisIntegrityException
8
8
  from orionis.services.environment.env import Env
9
+ from orionis.support.entities.base import BaseEntity
9
10
 
10
11
  @dataclass(unsafe_hash=True, kw_only=True)
11
- class Oracle:
12
+ class Oracle(BaseEntity):
12
13
  """
13
14
  Data class to represent Oracle database configuration using oracledb.
14
15
 
@@ -37,90 +38,90 @@ class Oracle:
37
38
  """
38
39
 
39
40
  driver: str = field(
40
- default="oracle",
41
- metadata={
41
+ default = "oracle",
42
+ metadata = {
42
43
  "description": "The database driver being used, typically 'oracle'.",
43
44
  "default": "oracle"
44
45
  }
45
46
  )
46
47
 
47
48
  username: str = field(
48
- default_factory=lambda: Env.get("DB_USERNAME", "sys"),
49
- metadata={
49
+ default = Env.get("DB_USERNAME", "sys"),
50
+ metadata = {
50
51
  "description": "Oracle DB username.",
51
52
  "default": "sys"
52
53
  }
53
54
  )
54
55
 
55
56
  password: str = field(
56
- default_factory=lambda: Env.get("DB_PASSWORD", ""),
57
- metadata={
57
+ default = Env.get("DB_PASSWORD", ""),
58
+ metadata = {
58
59
  "description": "Oracle DB password.",
59
60
  "default": ""
60
61
  }
61
62
  )
62
63
 
63
64
  host: str = field(
64
- default_factory=lambda: Env.get("DB_HOST", "localhost"),
65
- metadata={
65
+ default = Env.get("DB_HOST", "localhost"),
66
+ metadata = {
66
67
  "description": "Oracle DB host address.",
67
68
  "default": "localhost"
68
69
  }
69
70
  )
70
71
 
71
72
  port: int = field(
72
- default_factory=lambda: Env.get("DB_PORT", 1521),
73
- metadata={
73
+ default = Env.get("DB_PORT", 1521),
74
+ metadata = {
74
75
  "description": "Oracle DB listener port.",
75
76
  "default": 1521
76
77
  }
77
78
  )
78
79
 
79
80
  service_name: Optional[str] = field(
80
- default_factory=lambda: Env.get("DB_SERVICE_NAME", "ORCL"),
81
- metadata={
81
+ default = Env.get("DB_SERVICE_NAME", "ORCL"),
82
+ metadata = {
82
83
  "description": "Service name for Oracle DB.",
83
84
  "default": "ORCL"
84
85
  }
85
86
  )
86
87
 
87
88
  sid: Optional[str] = field(
88
- default_factory=lambda: Env.get("DB_SID", None),
89
- metadata={
89
+ default = Env.get("DB_SID", None),
90
+ metadata = {
90
91
  "description": "SID for Oracle DB.",
91
92
  "default": None
92
93
  }
93
94
  )
94
95
 
95
96
  dsn: Optional[str] = field(
96
- default_factory=lambda: Env.get("DB_DSN", None),
97
- metadata={
97
+ default = Env.get("DB_DSN", None),
98
+ metadata = {
98
99
  "description": "DSN string (overrides host/port/service/sid).",
99
100
  "default": None
100
101
  }
101
102
  )
102
103
 
103
104
  tns_name: Optional[str] = field(
104
- default_factory=lambda: Env.get("DB_TNS", None),
105
- metadata={
105
+ default = Env.get("DB_TNS", None),
106
+ metadata = {
106
107
  "description": "TNS alias defined in tnsnames.ora file.",
107
108
  "default": None
108
109
  }
109
110
  )
110
111
 
111
112
  encoding: str | OracleEncoding = field(
112
- default_factory=lambda: Env.get("DB_ENCODING", OracleEncoding.AL32UTF8),
113
- metadata={
113
+ default = Env.get("DB_ENCODING", OracleEncoding.AL32UTF8.value),
114
+ metadata = {
114
115
  "description": "Database charset (CHAR/VARCHAR2)",
115
- "default": "AL32UTF8"
116
+ "default": OracleEncoding.AL32UTF8.value
116
117
  }
117
118
  )
118
119
 
119
120
  nencoding: str | OracleNencoding = field(
120
- default_factory=lambda: Env.get("DB_NENCODING", OracleNencoding.AL32UTF8),
121
- metadata={
121
+ default = Env.get("DB_NENCODING", OracleNencoding.AL32UTF8.value),
122
+ metadata = {
122
123
  "description": "Database charset (NCHAR/NVARCHAR2)",
123
- "default": "AL32UTF8"
124
+ "default": OracleNencoding.AL32UTF8.value
124
125
  }
125
126
  )
126
127
 
@@ -130,6 +131,7 @@ class Oracle:
130
131
  This method performs strict validation on the configuration fields required to establish
131
132
  an Oracle database connection. It ensures that all necessary parameters are present and
132
133
  correctly formatted, raising an `OrionisIntegrityException` if any validation fails.
134
+
133
135
  Validation rules:
134
136
  - `driver` must be the string 'oracle'.
135
137
  - `username` and `password` must be non-empty strings.
@@ -141,6 +143,7 @@ class Oracle:
141
143
  - If provided, `service_name` and `sid` must be non-empty strings or None.
142
144
  - `encoding` must be a non-empty string or an instance of `OracleEncoding`.
143
145
  - `nencoding` must be a non-empty string.
146
+
144
147
  Raises:
145
148
  OrionisIntegrityException: If any configuration parameter is invalid.
146
149
  """
@@ -218,34 +221,4 @@ class Oracle:
218
221
  elif isinstance(self.nencoding, OracleNencoding):
219
222
  self.nencoding = self.nencoding.value
220
223
  else:
221
- raise OrionisIntegrityException("Invalid 'nencoding': must be a string or OracleNencoding.")
222
-
223
- def toDict(self) -> dict:
224
- """
225
- Convert the object to a dictionary representation.
226
- Returns:
227
- dict: A dictionary representation of the Dataclass object.
228
- """
229
- return asdict(self)
230
-
231
- def getFields(self):
232
- """
233
- Retrieves a list of field information for the current dataclass instance.
234
-
235
- Returns:
236
- list: A list of dictionaries, each containing details about a field:
237
- - name (str): The name of the field.
238
- - type (type): The type of the field.
239
- - default: The default value of the field, if specified; otherwise, the value from metadata or None.
240
- - metadata (mapping): The metadata associated with the field.
241
- """
242
- __fields = []
243
- for field in fields(self):
244
- __metadata = dict(field.metadata) or {}
245
- __fields.append({
246
- "name": field.name,
247
- "type": field.type.__name__ if hasattr(field.type, '__name__') else str(field.type),
248
- "default": field.default if (field.default is not None and '_MISSING_TYPE' not in str(field.default)) else __metadata.get('default', None),
249
- "metadata": __metadata
250
- })
251
- return __fields
224
+ raise OrionisIntegrityException("Invalid 'nencoding': must be a string or OracleNencoding.")
@@ -1,15 +1,17 @@
1
- from dataclasses import asdict, dataclass, field, fields
1
+ from dataclasses import dataclass, field
2
2
  from orionis.foundation.config.database.enums import (
3
3
  PGSQLCharset,
4
4
  PGSQLSSLMode
5
5
  )
6
6
  from orionis.foundation.exceptions import OrionisIntegrityException
7
7
  from orionis.services.environment.env import Env
8
+ from orionis.support.entities.base import BaseEntity
8
9
 
9
10
  @dataclass(unsafe_hash=True, kw_only=True)
10
- class PGSQL:
11
+ class PGSQL(BaseEntity):
11
12
  """
12
13
  Pgsql database configuration entity.
14
+
13
15
  Attributes:
14
16
  driver (str): Database driver type. Default: "pgsql".
15
17
  host (str): Database host. Default: value of the environment variable DB_HOST or "127.0.0.1".
@@ -25,90 +27,90 @@ class PGSQL:
25
27
  """
26
28
 
27
29
  driver: str = field(
28
- default="pgsql",
29
- metadata={
30
+ default = "pgsql",
31
+ metadata = {
30
32
  "description": "Database driver type",
31
33
  "default": "pgsql"
32
34
  }
33
35
  )
34
36
 
35
37
  host: str = field(
36
- default_factory=lambda: Env.get("DB_HOST", "127.0.0.1"),
37
- metadata={
38
+ default = Env.get("DB_HOST", "127.0.0.1"),
39
+ metadata = {
38
40
  "description": "Database host",
39
41
  "default": "127.0.0.1"
40
42
  }
41
43
  )
42
44
 
43
- port: str = field(
44
- default_factory=lambda: Env.get("DB_PORT", "5432"),
45
- metadata={
45
+ port: str | int = field(
46
+ default = Env.get("DB_PORT", 5432),
47
+ metadata = {
46
48
  "description": "Database port",
47
- "default": "5432"
49
+ "default": 5432
48
50
  }
49
51
  )
50
52
 
51
53
  database: str = field(
52
- default_factory=lambda: Env.get("DB_DATABASE", "orionis"),
53
- metadata={
54
+ default = Env.get("DB_DATABASE", "orionis"),
55
+ metadata = {
54
56
  "description": "Database name",
55
57
  "default": "orionis"
56
58
  }
57
59
  )
58
60
 
59
61
  username: str = field(
60
- default_factory=lambda: Env.get("DB_USERNAME", "root"),
61
- metadata={
62
+ default = Env.get("DB_USERNAME", "postgres"),
63
+ metadata = {
62
64
  "description": "Database user",
63
- "default": "root"
65
+ "default": "postgres"
64
66
  }
65
67
  )
66
68
 
67
69
  password: str = field(
68
- default_factory=lambda: Env.get("DB_PASSWORD", ""),
69
- metadata={
70
+ default = Env.get("DB_PASSWORD", ""),
71
+ metadata = {
70
72
  "description": "Database password",
71
73
  "default": ""
72
74
  }
73
75
  )
74
76
 
75
77
  charset: str | PGSQLCharset = field(
76
- default_factory=lambda: Env.get("DB_CHARSET", PGSQLCharset.UTF8),
77
- metadata={
78
+ default = Env.get("DB_CHARSET", PGSQLCharset.UTF8),
79
+ metadata = {
78
80
  "description": "Database charset",
79
- "default": "utf8"
81
+ "default": PGSQLCharset.UTF8.value
80
82
  }
81
83
  )
82
84
 
83
85
  prefix: str = field(
84
- default="",
85
- metadata={
86
+ default = "",
87
+ metadata = {
86
88
  "description": "Table prefix",
87
89
  "default": ""
88
90
  }
89
91
  )
90
92
 
91
93
  prefix_indexes: bool = field(
92
- default=True,
93
- metadata={
94
+ default = True,
95
+ metadata = {
94
96
  "description": "Whether to prefix indexes",
95
97
  "default": True
96
98
  }
97
99
  )
98
100
 
99
101
  search_path: str = field(
100
- default="public",
101
- metadata={
102
+ default = "public",
103
+ metadata = {
102
104
  "description": "PostgreSQL schema search_path",
103
105
  "default": "public"
104
106
  }
105
107
  )
106
108
 
107
109
  sslmode: str | PGSQLSSLMode = field(
108
- default=PGSQLSSLMode.PREFER,
109
- metadata={
110
+ default = PGSQLSSLMode.PREFER.value,
111
+ metadata = {
110
112
  "description": "Connection SSL mode",
111
- "default": PGSQLSSLMode.PREFER
113
+ "default": PGSQLSSLMode.PREFER.value
112
114
  }
113
115
  )
114
116
 
@@ -132,24 +134,31 @@ class PGSQL:
132
134
  - 'sslmode' is a non-empty string.
133
135
  """
134
136
 
137
+ # Validate `driver` attribute
135
138
  if not isinstance(self.driver, str) or not self.driver:
136
139
  raise OrionisIntegrityException(f"The 'driver' attribute must be a non-empty string. Received: {self.driver!r}")
137
140
 
141
+ # Validate `host` attribute
138
142
  if not isinstance(self.host, str) or not self.host.strip():
139
143
  raise OrionisIntegrityException(f"The 'host' attribute must be a non-empty string. Received: {self.host!r}")
140
144
 
141
- if not isinstance(self.port, str) or not self.port.isdigit():
142
- raise OrionisIntegrityException(f"The 'port' attribute must be a numeric string. Received: {self.port!r}")
145
+ # Validate `port` attribute
146
+ if not (isinstance(self.port, (str, int)) and str(self.port).isdigit()):
147
+ raise OrionisIntegrityException(f"The 'port' attribute must be a numeric string or integer. Received: {self.port!r}")
143
148
 
149
+ # Validate `database` attribute
144
150
  if not isinstance(self.database, str) or not self.database.strip():
145
151
  raise OrionisIntegrityException(f"The 'database' attribute must be a non-empty string. Received: {self.database!r}")
146
152
 
153
+ # Validate `username` attribute
147
154
  if not isinstance(self.username, str) or not self.username.strip():
148
155
  raise OrionisIntegrityException(f"The 'username' attribute must be a non-empty string. Received: {self.username!r}")
149
156
 
157
+ # Validate `password` attribute
150
158
  if not isinstance(self.password, str):
151
159
  raise OrionisIntegrityException(f"The 'password' attribute must be a string. Received: {self.password!r}")
152
160
 
161
+ # Validate `charset` attribute
153
162
  options_charset = PGSQLCharset._member_names_
154
163
  if isinstance(self.charset, str):
155
164
  _value = self.charset.upper().strip()
@@ -160,18 +169,23 @@ class PGSQL:
160
169
  else:
161
170
  self.charset = self.charset.value
162
171
 
172
+ # Validate `prefix` attribute
163
173
  if not isinstance(self.prefix, str):
164
174
  raise OrionisIntegrityException(f"The 'prefix' attribute must be a string. Received: {self.prefix!r}")
165
175
 
176
+ # Validate `prefix_indexes` attribute
166
177
  if not isinstance(self.prefix_indexes, bool):
167
178
  raise OrionisIntegrityException(f"The 'prefix_indexes' attribute must be boolean. Received: {self.prefix_indexes!r}")
168
179
 
180
+ # Validate `search_path` attribute
169
181
  if not isinstance(self.search_path, str) or not self.search_path.strip():
170
182
  raise OrionisIntegrityException(f"The 'search_path' attribute must be a non-empty string. Received: {self.search_path!r}")
171
183
 
184
+ # Validate `sslmode` attribute
172
185
  if not isinstance(self.sslmode, (str, PGSQLSSLMode)):
173
186
  raise OrionisIntegrityException(f"The 'sslmode' attribute must be a string or PGSQLSSLMode. Received: {self.sslmode!r}")
174
187
 
188
+ # Validate `sslmode` attribute
175
189
  options_sslmode = PGSQLSSLMode._member_names_
176
190
  if isinstance(self.sslmode, str):
177
191
  _value = self.sslmode.upper().strip()
@@ -181,33 +195,3 @@ class PGSQL:
181
195
  self.sslmode = PGSQLSSLMode[_value].value
182
196
  else:
183
197
  self.sslmode = self.sslmode.value
184
-
185
- def toDict(self) -> dict:
186
- """
187
- Convert the object to a dictionary representation.
188
- Returns:
189
- dict: A dictionary representation of the Dataclass object.
190
- """
191
- return asdict(self)
192
-
193
- def getFields(self):
194
- """
195
- Retrieves a list of field information for the current dataclass instance.
196
-
197
- Returns:
198
- list: A list of dictionaries, each containing details about a field:
199
- - name (str): The name of the field.
200
- - type (type): The type of the field.
201
- - default: The default value of the field, if specified; otherwise, the value from metadata or None.
202
- - metadata (mapping): The metadata associated with the field.
203
- """
204
- __fields = []
205
- for field in fields(self):
206
- __metadata = dict(field.metadata) or {}
207
- __fields.append({
208
- "name": field.name,
209
- "type": field.type.__name__ if hasattr(field.type, '__name__') else str(field.type),
210
- "default": field.default if (field.default is not None and '_MISSING_TYPE' not in str(field.default)) else __metadata.get('default', None),
211
- "metadata": __metadata
212
- })
213
- return __fields
@@ -1,4 +1,4 @@
1
- from dataclasses import asdict, dataclass, field, fields
1
+ from dataclasses import dataclass, field
2
2
  from orionis.foundation.config.database.enums import (
3
3
  SQLiteForeignKey,
4
4
  SQLiteJournalMode,
@@ -6,9 +6,10 @@ from orionis.foundation.config.database.enums import (
6
6
  )
7
7
  from orionis.foundation.exceptions.integrity import OrionisIntegrityException
8
8
  from orionis.services.environment.env import Env
9
+ from orionis.support.entities.base import BaseEntity
9
10
 
10
11
  @dataclass(unsafe_hash=True, kw_only=True)
11
- class SQLite:
12
+ class SQLite(BaseEntity):
12
13
  """
13
14
  Data class to represent the SQLite database configuration.
14
15
 
@@ -33,72 +34,73 @@ class SQLite:
33
34
  """
34
35
 
35
36
  driver: str = field(
36
- default='sqlite',
37
- metadata={
37
+ default = 'sqlite',
38
+ metadata = {
38
39
  "description": "The database driver being used.",
39
40
  "example": "sqlite",
40
41
  },
41
42
  )
42
43
 
43
44
  url: str = field(
44
- default_factory=lambda: Env.get('DB_URL', 'sqlite:///' + Env.get('DB_DATABASE', 'database/database.sqlite')),
45
- metadata={
45
+ default = Env.get('DB_URL', 'sqlite:///' + Env.get('DB_DATABASE', 'database/database.sqlite')),
46
+ metadata = {
46
47
  "description": "The URL for connecting to the database.",
47
48
  "example": "sqlite:///database/database.sqlite",
48
49
  },
49
50
  )
50
51
 
51
52
  database: str = field(
52
- default_factory=lambda: Env.get('DB_DATABASE', 'database.sqlite'),
53
- metadata={
53
+ default = Env.get('DB_DATABASE', 'database.sqlite'),
54
+ metadata = {
54
55
  "description": "The path to the SQLite database file.",
55
56
  "example": "database.sqlite",
56
57
  },
57
58
  )
58
59
 
59
60
  prefix: str = field(
60
- default_factory=lambda: Env.get('DB_PREFIX', ''),
61
- metadata={
61
+ default = Env.get('DB_PREFIX', ''),
62
+ metadata = {
62
63
  "description": "Prefix for table names.",
63
64
  "example": "",
64
65
  },
65
66
  )
66
67
 
67
68
  foreign_key_constraints: bool | SQLiteForeignKey = field(
68
- default_factory=lambda: Env.get('DB_FOREIGN_KEYS', SQLiteForeignKey.OFF),
69
- metadata={
69
+ default = Env.get('DB_FOREIGN_KEYS', SQLiteForeignKey.OFF.value),
70
+ metadata = {
70
71
  "description": "Whether foreign key constraints are enabled.",
71
- "example": 'OFF',
72
+ "example": SQLiteForeignKey.OFF.value
72
73
  },
73
74
  )
74
75
 
75
76
  busy_timeout: int = field(
76
- default_factory=lambda: Env.get('DB_BUSY_TIMEOUT', 5000),
77
- metadata={
77
+ default = Env.get('DB_BUSY_TIMEOUT', 5000),
78
+ metadata = {
78
79
  "description": "The timeout period (in milliseconds) before retrying a locked database.",
79
- "example": 5000,
80
+ "example": 5000
80
81
  },
81
82
  )
82
83
 
83
84
  journal_mode: str | SQLiteJournalMode = field(
84
- default_factory=lambda: Env.get('DB_JOURNAL_MODE', SQLiteJournalMode.DELETE),
85
- metadata={
85
+ default = Env.get('DB_JOURNAL_MODE', SQLiteJournalMode.DELETE.value),
86
+ metadata = {
86
87
  "description": "The journal mode used for transactions.",
87
- "example": "DELETE",
88
+ "example": SQLiteJournalMode.DELETE.value
88
89
  },
89
90
  )
90
91
 
91
92
  synchronous: str | SQLiteSynchronous = field(
92
- default_factory=lambda: Env.get('DB_SYNCHRONOUS', SQLiteSynchronous.NORMAL),
93
- metadata={
93
+ default = Env.get('DB_SYNCHRONOUS', SQLiteSynchronous.NORMAL.value),
94
+ metadata = {
94
95
  "description": "The synchronization level for the database.",
95
- "example": "NORMAL",
96
+ "example": SQLiteSynchronous.NORMAL.value
96
97
  },
97
98
  )
98
99
 
99
100
  def __post_init__(self):
100
101
  """
101
102
  Post-initialization validation for SQLite database configuration fields.
103
+
102
104
  This method ensures that all configuration attributes are of the correct type and meet required constraints:
103
105
  - `driver`: Must be a non-empty string (e.g., 'sqlite').
104
106
  - `url`: Must be a non-empty string (e.g., 'sqlite:///database/database.sqlite').
@@ -108,6 +110,7 @@ class SQLite:
108
110
  - `busy_timeout`: If provided, must be a non-negative integer (milliseconds) or None.
109
111
  - `journal_mode`: If provided, must be a string or None (e.g., 'WAL', 'DELETE').
110
112
  - `synchronous`: If provided, must be a string or None (e.g., 'FULL', 'NORMAL', 'OFF').
113
+
111
114
  Raises:
112
115
  OrionisIntegrityException: If any attribute fails its validation check.
113
116
  """
@@ -169,34 +172,4 @@ class SQLite:
169
172
  else:
170
173
  self.synchronous = SQLiteSynchronous[_value].value
171
174
  else:
172
- self.synchronous = self.synchronous.value
173
-
174
- def toDict(self) -> dict:
175
- """
176
- Convert the object to a dictionary representation.
177
- Returns:
178
- dict: A dictionary representation of the Dataclass object.
179
- """
180
- return asdict(self)
181
-
182
- def getFields(self):
183
- """
184
- Retrieves a list of field information for the current dataclass instance.
185
-
186
- Returns:
187
- list: A list of dictionaries, each containing details about a field:
188
- - name (str): The name of the field.
189
- - type (type): The type of the field.
190
- - default: The default value of the field, if specified; otherwise, the value from metadata or None.
191
- - metadata (mapping): The metadata associated with the field.
192
- """
193
- __fields = []
194
- for field in fields(self):
195
- __metadata = dict(field.metadata) or {}
196
- __fields.append({
197
- "name": field.name,
198
- "type": field.type.__name__ if hasattr(field.type, '__name__') else str(field.type),
199
- "default": field.default if (field.default is not None and '_MISSING_TYPE' not in str(field.default)) else __metadata.get('default', None),
200
- "metadata": __metadata
201
- })
202
- return __fields
175
+ self.synchronous = self.synchronous.value