tiferet 1.0.0a8__py3-none-any.whl → 1.0.0a10__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.
tiferet/data/container.py CHANGED
@@ -1,5 +1,8 @@
1
1
  # *** imports
2
2
 
3
+ # ** core
4
+ from typing import Any, Dict
5
+
3
6
  # ** app
4
7
  from ..configs import *
5
8
  from ..domain import DataObject
@@ -21,8 +24,8 @@ class ContainerDependencyYamlData(ContainerDependency, DataObject):
21
24
 
22
25
  serialize_when_none = False
23
26
  roles = {
24
- 'to_model': DataObject.allow(),
25
- 'to_data.yaml': DataObject.deny('flag')
27
+ 'to_model': DataObject.deny('params'),
28
+ 'to_data': DataObject.deny('flag')
26
29
  }
27
30
 
28
31
  # * attribute: flag
@@ -54,11 +57,18 @@ class ContainerDependencyYamlData(ContainerDependency, DataObject):
54
57
  '''
55
58
 
56
59
  # Map to the container dependency object.
57
- return super().map(ContainerDependency, **kwargs)
60
+ obj = super().map(ContainerDependency, **kwargs, validate=False)
61
+
62
+ # Set the parameters in due to the deserializer.
63
+ obj.parameters = self.parameters
64
+
65
+ # Validate and return the object.
66
+ obj.validate()
67
+ return obj
58
68
 
59
69
  # * method: new
60
70
  @staticmethod
61
- def new(**kwargs) -> 'ContainerDependencyYamlData':
71
+ def from_data(**kwargs) -> 'ContainerDependencyYamlData':
62
72
  '''
63
73
  Initializes a new ContainerDependencyData object from YAML data.
64
74
 
@@ -68,14 +78,14 @@ class ContainerDependencyYamlData(ContainerDependency, DataObject):
68
78
  :rtype: ContainerDependencyYamlData
69
79
  '''
70
80
 
71
- # Create a new ContainerDependencyYamlData object.
72
- data = ContainerDependencyYamlData(dict(
73
- **kwargs,
74
- ), strict=False)
75
-
76
- # Validate and return the object.
77
- data.validate()
78
- return data
81
+ # Create a new ContainerDependencyData object.
82
+ return super(
83
+ ContainerDependencyYamlData,
84
+ ContainerDependencyYamlData
85
+ ).from_data(
86
+ ContainerDependencyYamlData,
87
+ **kwargs
88
+ )
79
89
 
80
90
  # * method: from_model
81
91
  @staticmethod
@@ -90,8 +100,9 @@ class ContainerDependencyYamlData(ContainerDependency, DataObject):
90
100
  '''
91
101
 
92
102
  # Create and return a new ContainerDependencyData object.
93
- return ContainerDependencyYamlData.new(
94
- **model.to_primitive(),
103
+ return super(ContainerDependencyYamlData, ContainerDependencyYamlData).from_model(
104
+ ContainerDependencyYamlData,
105
+ model,
95
106
  **kwargs,
96
107
  )
97
108
 
@@ -110,7 +121,7 @@ class ContainerAttributeYamlData(ContainerAttribute, DataObject):
110
121
  serialize_when_none = False
111
122
  roles = {
112
123
  'to_model': DataObject.allow(),
113
- 'to_data.yaml': DataObject.deny('id')
124
+ 'to_data': DataObject.deny('id')
114
125
  }
115
126
 
116
127
  # * attribute: dependencies
@@ -140,23 +151,33 @@ class ContainerAttributeYamlData(ContainerAttribute, DataObject):
140
151
 
141
152
  # * method: new
142
153
  @staticmethod
143
- def new(**kwargs) -> 'ContainerAttributeYamlData':
154
+ def from_data(**kwargs) -> 'ContainerAttributeYamlData':
144
155
  '''
145
156
  Initializes a new ContainerAttributeData object from YAML data.
146
157
 
158
+ :param deps: The dependencies data.
159
+ :type deps: dict
147
160
  :param kwargs: Additional keyword arguments.
148
161
  :type kwargs: dict
149
- '''
162
+ '''
150
163
 
151
164
  # Create a new ContainerAttributeData object.
152
- data = ContainerAttributeYamlData(dict(
153
- **kwargs,
154
- ), strict=False)
165
+ obj = super(
166
+ ContainerAttributeYamlData,
167
+ ContainerAttributeYamlData
168
+ ).from_data(
169
+ ContainerAttributeYamlData,
170
+ **kwargs,
171
+ validate=False
172
+ )
173
+
174
+ # Set the dependencies.
175
+ for flag, dep in obj.dependencies.items():
176
+ dep.flag = flag
155
177
 
156
-
157
178
  # Validate and return the object.
158
- data.validate()
159
- return data
179
+ obj.validate()
180
+ return obj
160
181
 
161
182
  # * method: from_model
162
183
  @staticmethod
@@ -170,10 +191,23 @@ class ContainerAttributeYamlData(ContainerAttribute, DataObject):
170
191
  :type kwargs: dict
171
192
  '''
172
193
 
194
+ # Create the dependency data.
195
+ dependencies = {dep.flag: dep.to_primitive() for dep in model.dependencies}
196
+
197
+ # Create a new model object without the dependencies.
198
+ data = model.to_primitive()
199
+ data['dependencies'] = dependencies
200
+
173
201
  # Create a new ContainerAttributeData object.
174
- return ContainerAttributeYamlData.new(
175
- id=model.id,
176
- type=model.type,
177
- dependencies = {dep.flag: dep for dep in model.dependencies},
202
+ obj = ContainerAttributeYamlData(
203
+ dict(
204
+ **data,
205
+ **kwargs
206
+ ),
207
+ strict=False
178
208
  )
209
+
210
+ # Validate and return the object.
211
+ obj.validate()
212
+ return obj
179
213
 
tiferet/data/error.py CHANGED
@@ -17,8 +17,8 @@ class ErrorMessageData(ErrorMessage, DataObject):
17
17
  class Options():
18
18
  serialize_when_none = False
19
19
  roles = {
20
- 'to_data.yaml': DataObject.allow('id'),
21
- 'to_object.yaml': DataObject.allow()
20
+ 'to_data': DataObject.allow(),
21
+ 'to_model': DataObject.allow()
22
22
  }
23
23
 
24
24
 
@@ -31,8 +31,8 @@ class ErrorData(Error, DataObject):
31
31
  class Options():
32
32
  serialize_when_none = False
33
33
  roles = {
34
- 'to_data.yaml': DataObject.deny('id'),
35
- 'to_object.yaml': DataObject.allow()
34
+ 'to_data': DataObject.deny('id'),
35
+ 'to_model': DataObject.allow()
36
36
  }
37
37
 
38
38
  # * attribute: message
@@ -44,13 +44,30 @@ class ErrorData(Error, DataObject):
44
44
  )
45
45
  )
46
46
 
47
+ # * to_primitive
48
+ def to_primitive(self, role: str = 'to_data', **kwargs) -> dict:
49
+ '''
50
+ Converts the data object to a primitive dictionary.
51
+
52
+ :param role: The role.
53
+ :type role: str
54
+ :param kwargs: Additional keyword arguments.
55
+ :type kwargs: dict
56
+ :return: The primitive dictionary.
57
+ :rtype: dict
58
+ '''
59
+
60
+ # Convert the data object to a primitive dictionary.
61
+ return super().to_primitive(
62
+ role,
63
+ **kwargs
64
+ )
65
+
47
66
  # * method: map
48
- def map(self, role: str = 'to_object.yaml', **kwargs):
67
+ def map(self, **kwargs) -> Error:
49
68
  '''
50
69
  Maps the error data to an error object.
51
70
 
52
- :param role: The role for the mapping.
53
- :type role: str
54
71
  :param kwargs: Additional keyword arguments.
55
72
  :type kwargs: dict
56
73
  :return: A new error object.
@@ -58,11 +75,13 @@ class ErrorData(Error, DataObject):
58
75
  '''
59
76
 
60
77
  # Map the error messages.
61
- return super().map(Error, role, **kwargs)
78
+ return super().map(Error,
79
+ **self.to_primitive('to_model'),
80
+ **kwargs)
62
81
 
63
- # * method: new
82
+ # * method: from_data
64
83
  @staticmethod
65
- def new(**kwargs) -> 'ErrorData':
84
+ def from_data(**kwargs) -> 'ErrorData':
66
85
  '''
67
86
  Creates a new ErrorData object.
68
87
 
@@ -73,6 +92,7 @@ class ErrorData(Error, DataObject):
73
92
  '''
74
93
 
75
94
  # Create a new ErrorData object.
76
- return ErrorData(
77
- super(ErrorData, ErrorData).new(**kwargs)
95
+ return super(ErrorData, ErrorData).from_data(
96
+ ErrorData,
97
+ **kwargs
78
98
  )
tiferet/data/feature.py CHANGED
@@ -1,6 +1,9 @@
1
+ # *** imports
1
2
 
3
+ # ** infra
2
4
  from schematics.types.serializable import serializable
3
5
 
6
+ #
4
7
  from ..domain import *
5
8
  from ..domain.feature import Feature, FeatureCommand
6
9
 
@@ -20,11 +23,11 @@ class FeatureCommandData(FeatureCommand, DataObject):
20
23
 
21
24
  # Define the roles for the feature handler data.
22
25
  roles = {
23
- 'to_object.yaml': DataObject.allow(),
24
- 'to_data.yaml': DataObject.allow()
26
+ 'to_model': DataObject.allow(),
27
+ 'to_data': DataObject.allow()
25
28
  }
26
29
 
27
- def map(self, role: str = 'to_object', **kwargs) -> FeatureCommand:
30
+ def map(self, role: str = 'to_model', **kwargs) -> FeatureCommand:
28
31
  '''
29
32
  Maps the feature handler data to a feature handler object.
30
33
 
@@ -53,8 +56,8 @@ class FeatureData(Feature, DataObject):
53
56
 
54
57
  # Define the roles for the feature data.
55
58
  roles = {
56
- 'to_object.yaml': DataObject.deny('feature_key'),
57
- 'to_data.yaml': DataObject.deny('feature_key', 'group_id', 'id')
59
+ 'to_model': DataObject.deny('feature_key'),
60
+ 'to_data': DataObject.deny('feature_key', 'group_id', 'id')
58
61
  }
59
62
 
60
63
  commands = t.ListType(t.ModelType(FeatureCommandData),
@@ -69,7 +72,7 @@ class FeatureData(Feature, DataObject):
69
72
  # Return the feature key.
70
73
  return self.id.split('.')[-1]
71
74
 
72
- def map(self, role: str = 'to_object.yaml', **kwargs) -> Feature:
75
+ def map(self, role: str = 'to_model', **kwargs) -> Feature:
73
76
  '''
74
77
  Maps the feature data to a feature object.
75
78
 
@@ -82,10 +85,13 @@ class FeatureData(Feature, DataObject):
82
85
  '''
83
86
 
84
87
  # Map the feature data to a feature object.
85
- return super().map(Feature, role, **kwargs)
88
+ return super().map(Feature, role,
89
+ feature_key=self.feature_key,
90
+ **kwargs
91
+ )
86
92
 
87
93
  @staticmethod
88
- def new(**kwargs) -> 'FeatureData':
94
+ def from_data(**kwargs) -> 'FeatureData':
89
95
  '''
90
96
  Initializes a new FeatureData object from a Feature object.
91
97
 
@@ -96,37 +102,7 @@ class FeatureData(Feature, DataObject):
96
102
  '''
97
103
 
98
104
  # Create a new FeatureData object.
99
- _data = FeatureData(
100
- dict(**kwargs,),
101
- strict=False
105
+ return super(FeatureData, FeatureData).from_data(
106
+ FeatureData,
107
+ **kwargs
102
108
  )
103
-
104
- # Validate and return the new FeatureData object.
105
- _data.validate()
106
- return _data
107
-
108
- @staticmethod
109
- def from_yaml_data(id: str, group_id: str, **kwargs) -> 'FeatureData':
110
- '''
111
- Initializes a new FeatureData object from yaml data.
112
-
113
- :param id: The feature id.
114
- :type id: str
115
- :param group_id: The context group id.
116
- :type group_id: str
117
- :param kwargs: Additional keyword arguments.
118
- :type kwargs: dict
119
- :return: A new FeatureData object.
120
- :rtype: FeatureData
121
- '''
122
-
123
- # Create a new FeatureData object.
124
- _data = FeatureData(
125
- dict(**kwargs,
126
- id=id, group_id=group_id
127
- ),
128
- strict=False)
129
-
130
- # Validate and return the new FeatureData object.
131
- _data.validate()
132
- return _data
@@ -1,5 +1,5 @@
1
1
  from .core import *
2
- from .app import AppInterface
3
- from .container import ContainerAttribute
2
+ from .app import AppInterface, AppDependency, AppRepositoryConfiguration
3
+ from .container import ContainerAttribute, ContainerDependency
4
4
  from .error import Error
5
5
  from .feature import Feature
tiferet/domain/app.py CHANGED
@@ -184,61 +184,3 @@ class AppRepositoryConfiguration(ModuleDependency):
184
184
  **kwargs),
185
185
  strict=False,
186
186
  )
187
-
188
-
189
- # ** model: app_configuration
190
- class AppConfiguration(Entity):
191
- '''
192
- The application configuration object.
193
- '''
194
-
195
- # * attribute: name
196
- name = StringType(
197
- required=True,
198
- metadata=dict(
199
- description='The name of the application.'
200
- )
201
- )
202
-
203
- # * attribute: description
204
- description = StringType(
205
- metadata=dict(
206
- description='The description of the application.'
207
- )
208
- )
209
-
210
- # * attribute: app_repo
211
- app_repo = ModelType(AppRepositoryConfiguration,
212
- required=True,
213
- metadata=dict(
214
- description='The application repository configuration.'
215
- ),
216
- )
217
-
218
- # * attribute: interfaces
219
- interfaces = ListType(
220
- ModelType(AppInterface),
221
- required=True,
222
- default=[],
223
- metadata=dict(
224
- description='The application interfaces.'
225
- )
226
- )
227
-
228
- # * method: new
229
- @staticmethod
230
- def new(**kwargs) -> 'AppConfiguration':
231
- '''
232
- Initializes a new AppConfiguration object.
233
-
234
- :param kwargs: Additional keyword arguments.
235
- :type kwargs: dict
236
- :return: A new AppConfiguration object.
237
- :rtype: AppConfiguration
238
- '''
239
-
240
- # Create and return a new AppConfiguration object.
241
- return super(AppConfiguration, AppConfiguration).new(
242
- AppConfiguration,
243
- **kwargs
244
- )
@@ -22,7 +22,7 @@ class ContainerDependency(ModuleDependency):
22
22
  '''
23
23
 
24
24
  # * attribute: flag
25
- flag = t.StringType(
25
+ flag = StringType(
26
26
  required=True,
27
27
  metadata=dict(
28
28
  description='The flag for the container dependency.'
@@ -30,8 +30,8 @@ class ContainerDependency(ModuleDependency):
30
30
  )
31
31
 
32
32
  # * attribute: parameters
33
- parameters = t.DictType(
34
- t.StringType,
33
+ parameters = DictType(
34
+ StringType,
35
35
  default={},
36
36
  metadata=dict(
37
37
  description='The container dependency parameters.'
@@ -51,7 +51,7 @@ class ContainerDependency(ModuleDependency):
51
51
  '''
52
52
 
53
53
  # Create and return a new ContainerDependency object.
54
- super(ContainerDependency, ContainerDependency).new(
54
+ return super(ContainerDependency, ContainerDependency).new(
55
55
  ContainerDependency,
56
56
  **kwargs)
57
57
 
@@ -63,7 +63,7 @@ class ContainerAttribute(Entity):
63
63
  '''
64
64
 
65
65
  # * attribute: id
66
- id = t.StringType(
66
+ id = StringType(
67
67
  required=True,
68
68
  metadata=dict(
69
69
  description='The unique identifier for the container attribute.'
@@ -71,7 +71,7 @@ class ContainerAttribute(Entity):
71
71
  )
72
72
 
73
73
  # * attribute: type
74
- type = t.StringType(
74
+ type = StringType(
75
75
  required=True,
76
76
  choices=CONTAINER_ATTRIBUTE_TYPE_CHOICES,
77
77
  metadata=dict(
@@ -80,8 +80,8 @@ class ContainerAttribute(Entity):
80
80
  )
81
81
 
82
82
  # * attribute: dependencies
83
- dependencies = t.ListType(
84
- t.ModelType(ContainerDependency),
83
+ dependencies = ListType(
84
+ ModelType(ContainerDependency),
85
85
  default=[],
86
86
  metadata=dict(
87
87
  description='The container attribute dependencies.'
@@ -101,10 +101,27 @@ class ContainerAttribute(Entity):
101
101
  '''
102
102
 
103
103
  # Create and return a new ContainerAttribute object.
104
- super(ContainerAttribute, ContainerAttribute).new(
104
+ return super(ContainerAttribute, ContainerAttribute).new(
105
105
  ContainerAttribute,
106
106
  **kwargs)
107
107
 
108
+ # * method: get_dependency
109
+ def get_dependency(self, flag: str) -> ContainerDependency:
110
+ '''
111
+ Gets a container dependency by flag.
112
+
113
+ :param flag: The flag for the container dependency.
114
+ :type flag: str
115
+ :return: The container dependency.
116
+ :rtype: ContainerDependency
117
+ '''
118
+
119
+ # Return the dependency with the matching flag.
120
+ return next(
121
+ (dependency for dependency in self.dependencies if dependency.flag == flag),
122
+ None
123
+ )
124
+
108
125
  # * method: set_dependency
109
126
  def set_dependency(self, dependency: ContainerDependency):
110
127
  '''
@@ -122,20 +139,3 @@ class ContainerAttribute(Entity):
122
139
 
123
140
  # Append the dependency otherwise.
124
141
  self.dependencies.append(dependency)
125
-
126
- # * method: get_dependency
127
- def get_dependency(self, flag: str) -> ContainerDependency:
128
- '''
129
- Gets a container dependency by flag.
130
-
131
- :param flag: The flag for the container dependency.
132
- :type flag: str
133
- :return: The container dependency.
134
- :rtype: ContainerDependency
135
- '''
136
-
137
- # Return the dependency with the matching flag.
138
- return next(
139
- (dependency for dependency in self.dependencies if dependency.flag == flag),
140
- None
141
- )
tiferet/domain/core.py CHANGED
@@ -88,6 +88,7 @@ class DataObject(Model):
88
88
  def map(self,
89
89
  type: ModelObject,
90
90
  role: str = 'to_model',
91
+ validate: bool = True,
91
92
  **kwargs
92
93
  ) -> ModelObject:
93
94
  '''
@@ -97,6 +98,8 @@ class DataObject(Model):
97
98
  :type type: type
98
99
  :param role: The role for the mapping.
99
100
  :type role: str
101
+ :param validate: True to validate the model object.
102
+ :type validate: bool
100
103
  :param kwargs: Additional keyword arguments for mapping.
101
104
  :type kwargs: dict
102
105
  :return: A new model object.
@@ -112,13 +115,19 @@ class DataObject(Model):
112
115
  # Map the data object to a model object.
113
116
  _object = type.new(**_data, strict=False)
114
117
 
118
+ # Validate if specified.
119
+ if validate:
120
+ _object.validate()
121
+
115
122
  # Return the model data.
116
123
  return _object
117
-
124
+
118
125
  # ** method: from_model
119
126
  @staticmethod
120
127
  def from_model(
128
+ data: 'DataObject',
121
129
  model: ModelObject,
130
+ validate: bool = True,
122
131
  **kwargs
123
132
  ) -> 'DataObject':
124
133
  '''
@@ -126,6 +135,10 @@ class DataObject(Model):
126
135
 
127
136
  :param model: The type of model object to map from.
128
137
  :type model: type
138
+ :param data: The data object to map from.
139
+ :type data: DataObject
140
+ :param validate: True to validate the data object.
141
+ :type validate: bool
129
142
  :param kwargs: Keyword arguments.
130
143
  :type kwargs: dict
131
144
  :return: A new data object.
@@ -133,10 +146,35 @@ class DataObject(Model):
133
146
  '''
134
147
 
135
148
  # Create a new data object.
136
- return DataObject(
137
- model.new(**kwargs, strict=False),
138
- strict=False,
139
- )
149
+ obj = data(dict(
150
+ **model.to_primitive(),
151
+ **kwargs
152
+ ), strict=False)
153
+
154
+ # Validate the data object if specified.
155
+ if validate:
156
+ obj.validate()
157
+
158
+ # Return the data object.
159
+ return obj
160
+
161
+ @staticmethod
162
+ def from_data(
163
+ data: type,
164
+ **kwargs
165
+ ) -> 'DataObject':
166
+ '''
167
+ Initializes a new data object from a dictionary.
168
+
169
+ :param data: The type of data object to map from.
170
+ :param kwargs: Keyword arguments.
171
+ :type kwargs: dict
172
+ :return: A new data object.
173
+ :rtype: DataObject
174
+ '''
175
+
176
+ # Create a new data object.
177
+ return data(dict(**kwargs), strict=False)
140
178
 
141
179
  # ** method: allow
142
180
  @staticmethod
tiferet/domain/error.py CHANGED
@@ -28,6 +28,23 @@ class ErrorMessage(ValueObject):
28
28
  )
29
29
  )
30
30
 
31
+ # * method: new
32
+ @staticmethod
33
+ def new(**kwargs) -> 'ErrorMessage':
34
+ '''Initializes a new ErrorMessage object.
35
+
36
+ :param kwargs: Additional keyword arguments.
37
+ :type kwargs: dict
38
+ :return: A new ErrorMessage object.
39
+ :rtype: ErrorMessage
40
+ '''
41
+
42
+ # Create and return a new ErrorMessage object.
43
+ return super(ErrorMessage, ErrorMessage).new(
44
+ ErrorMessage,
45
+ **kwargs
46
+ )
47
+
31
48
  # * method: format
32
49
  def format(self, *args) -> str:
33
50
  '''
@@ -106,6 +123,7 @@ class Error(Entity):
106
123
 
107
124
  # Create and return a new Error object.
108
125
  return super(Error, Error).new(
126
+ Error,
109
127
  id=id,
110
128
  name=name,
111
129
  error_code=error_code,
tiferet/domain/feature.py CHANGED
@@ -127,7 +127,7 @@ class Feature(Entity):
127
127
 
128
128
  # * method: new
129
129
  @staticmethod
130
- def new(name: str, group_id: str, feature_key: str, description: str = None, **kwargs) -> 'Feature':
130
+ def new(name: str, group_id: str, feature_key: str = None, id: str = None, description: str = None, **kwargs) -> 'Feature':
131
131
  '''Initializes a new Feature object.
132
132
 
133
133
  :param name: The name of the feature.
@@ -136,6 +136,8 @@ class Feature(Entity):
136
136
  :type group_id: str
137
137
  :param feature_key: The key of the feature.
138
138
  :type feature_key: str
139
+ :param id: The identifier of the feature.
140
+ :type id: str
139
141
  :param description: The description of the feature.
140
142
  :type description: str
141
143
  :param kwargs: Additional keyword arguments.
@@ -143,8 +145,13 @@ class Feature(Entity):
143
145
  :return: A new Feature object.
144
146
  '''
145
147
 
148
+ # Set the feature key as the snake case of the name if not provided.
149
+ if not feature_key:
150
+ feature_key = name.lower().replace(' ', '_')
151
+
146
152
  # Feature ID is the group ID and feature key separated by a period.
147
- id = f'{group_id}.{feature_key}'
153
+ if not id:
154
+ id = f'{group_id}.{feature_key}'
148
155
 
149
156
  # Set the description as the name if not provided.
150
157
  if not description:
@@ -152,6 +159,7 @@ class Feature(Entity):
152
159
 
153
160
  # Create and return a new Feature object.
154
161
  return super(Feature, Feature).new(
162
+ Feature,
155
163
  id=id,
156
164
  name=name,
157
165
  group_id=group_id,
@@ -170,7 +178,7 @@ class Feature(Entity):
170
178
  '''
171
179
 
172
180
  # Add the handler to the feature.
173
- if position:
181
+ if position is not None:
174
182
  self.commands.insert(position, handler)
175
183
  else:
176
184
  self.commands.append(handler)
tiferet/repos/__init__.py CHANGED
@@ -0,0 +1,7 @@
1
+ # *** imports
2
+
3
+ # ** app
4
+ from .app import AppRepository
5
+ from .container import ContainerRepository
6
+ from .error import ErrorRepository
7
+ from .feature import FeatureRepository