nuql 0.0.2__py3-none-any.whl → 0.0.3__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.
nuql/fields/list.py CHANGED
@@ -27,55 +27,17 @@ class List(FieldBase):
27
27
  )
28
28
  self.of = field_map['of']
29
29
 
30
- def __call__(self, value: Any, action: 'types.SerialisationType', validator: 'resources.Validator') -> Any:
31
- """
32
- Encapsulates the internal serialisation logic to prepare for
33
- sending the record to DynamoDB.
34
-
35
- :arg value: Deserialised value.
36
- :arg action: SerialisationType (`create`, `update`, `write` or `query`).
37
- :arg validator: Validator instance.
38
- :return: Serialised value.
39
- """
40
- has_value = not isinstance(value, resources.EmptyValue)
41
-
42
- # Apply generators if applicable to the field to overwrite the value
43
- if action in ['create', 'update', 'write']:
44
- if action == 'create' and self.on_create:
45
- value = self.on_create()
46
-
47
- if action == 'update' and self.on_update:
48
- value = self.on_update()
49
-
50
- if self.on_write:
51
- value = self.on_write()
52
-
53
- # Set default value if applicable
54
- if not has_value and not value:
55
- value = self.default
56
-
57
- # Serialise the value
30
+ def serialise_internal(
31
+ self,
32
+ value: Any,
33
+ action: 'types.SerialisationType',
34
+ validator: 'resources.Validator'
35
+ ) -> Any:
36
+ """Internal serialisation"""
58
37
  if not isinstance(value, list):
59
- value = None
38
+ return None
60
39
  else:
61
- value = [self.of(item, action, validator) for item in value]
62
-
63
- # Validate required field
64
- if self.required and action == 'create' and value is None:
65
- validator.add(name=self.name, message='Field is required')
66
-
67
- # Validate against enum
68
- if self.enum and has_value and action in ['create', 'update', 'write'] and value not in self.enum:
69
- validator.add(name=self.name, message=f'Value must be one of: {", ".join(self.enum)}')
70
-
71
- # Run internal validation
72
- self.internal_validation(value, action, validator)
73
-
74
- # Run custom validation logic
75
- if self.validator and action in ['create', 'update', 'write']:
76
- self.validator(value, validator)
77
-
78
- return value
40
+ return [self.of(item, action, validator) for item in value]
79
41
 
80
42
  def deserialise(self, value: _List[Any] | None) -> _List[Any] | None:
81
43
  """
nuql/fields/map.py CHANGED
@@ -22,46 +22,16 @@ class Map(resources.FieldBase):
22
22
  self.fields = resources.create_field_map(self.config['fields'], self.parent, self.parent.provider.fields)
23
23
  self.serialiser = resources.Serialiser(self)
24
24
 
25
- def __call__(self, value: Any, action: 'types.SerialisationType', validator: 'resources.Validator') -> Any:
26
- """
27
- Encapsulates the internal serialisation logic to prepare for
28
- sending the record to DynamoDB.
29
-
30
- :arg value: Deserialised value.
31
- :arg action: SerialisationType (`create`, `update`, `write` or `query`).
32
- :arg validator: Validator instance.
33
- :return: Serialised value.
34
- """
35
- has_value = not isinstance(value, resources.EmptyValue)
36
-
37
- # Apply generators if applicable to the field to overwrite the value
38
- if action in ['create', 'update', 'write']:
39
- if action == 'create' and self.on_create:
40
- value = self.on_create()
41
-
42
- if action == 'update' and self.on_update:
43
- value = self.on_update()
44
-
45
- if self.on_write:
46
- value = self.on_write()
47
-
48
- # Set default value if applicable
49
- if not has_value and not value:
50
- value = self.default
51
-
52
- # Serialise the value
25
+ def serialise_internal(
26
+ self,
27
+ value: Any,
28
+ action: 'types.SerialisationType',
29
+ validator: 'resources.Validator'
30
+ ) -> Any:
31
+ """Serialises the Map value"""
53
32
  if value:
54
- value = self.serialiser.serialise(action, value, validator)
55
-
56
- # Validate required field
57
- if self.required and action == 'create' and value is None:
58
- validator.add(name=self.name, message='Field is required')
59
-
60
- # Run internal validation
61
- self.internal_validation(value, action, validator)
62
-
63
- # Run custom validation logic
64
- if self.validator and action in ['create', 'update', 'write']:
65
- self.validator(value, validator)
33
+ return self.serialiser.serialise(action, value, validator)
66
34
 
67
- return value
35
+ def deserialise(self, value: Any) -> Any:
36
+ """Deserialises the Map value"""
37
+ return self.serialiser.deserialise(value)
@@ -62,10 +62,10 @@ def get_field_types(field_types: List[Type['types.FieldType']] | None = None) ->
62
62
 
63
63
  def is_valid(_obj: Any) -> bool:
64
64
  """Check the provided object is a valid field type."""
65
- if not inspect.isclass(obj):
65
+ if not inspect.isclass(_obj):
66
66
  return False
67
67
 
68
- if not issubclass(obj, resources.FieldBase):
68
+ if not issubclass(_obj, resources.FieldBase):
69
69
  return False
70
70
 
71
71
  return True
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: nuql
3
- Version: 0.0.2
3
+ Version: 0.0.3
4
4
  Summary: Nuql (pronounced 'nuckle') is a lightweight DynamoDB library for implementing the single table model pattern.
5
5
  License: MIT License
6
6
 
@@ -32,8 +32,8 @@ nuql/fields/datetime_timestamp.py,sha256=drJLpmGhL8ANrfGsArKeVLb4v7maiignhzC4qpQ
32
32
  nuql/fields/float.py,sha256=x48Spo_GNku0djO0Ogs8usZTfwOY-27Mh5OPOQBO3OY,1316
33
33
  nuql/fields/integer.py,sha256=pHs3CJM4xKN60IYg5aTe4QjSQQBR4jp08HyANtidHgs,1312
34
34
  nuql/fields/key.py,sha256=r2Q4qVlAS51dOUI7Zk_OTr08VKkMBXNyUJb3ieY-nnY,6621
35
- nuql/fields/list.py,sha256=EJI4wlqg8H2FsaB0jAhjnESAeHxX-dt9a-jb3ezFWEM,3067
36
- nuql/fields/map.py,sha256=dlKA2c9wLupr2soIig5-TYHfNkm05VF2svCfkRv2G1w,2340
35
+ nuql/fields/list.py,sha256=m7wTIb4-VRRKO5C8XZJFeGOPHIqrvc3xNbWw-vHppQM,1508
36
+ nuql/fields/map.py,sha256=jFbJ9YhvVMrkLlzktMEQOrZw7uqOLgdfmwxuw9Zue-Y,1169
37
37
  nuql/fields/string.py,sha256=-7yk6T3HrKn52KdAyqoXqgtPdzpZKCCcbYR-TTtTjfk,5519
38
38
  nuql/fields/ulid.py,sha256=mcwTztzIqE_3q1cRa2pf6pN8s0322NQlfQcky9xAWkI,971
39
39
  nuql/fields/uuid.py,sha256=fhwAcMUHuih2NgPh7QOs4hcCwrl8Cu2CqSpvLMBAV-c,1041
@@ -44,7 +44,7 @@ nuql/generators/uuid.py,sha256=MoEQVxgEsqGlhpf4W-OuRiLKqNwRtE2NtS3eFTOc5lo,394
44
44
  nuql/resources/__init__.py,sha256=8HRJ_H5yTdQtfeVZ29ikdbLQSPKiZRyNkoocQd5QtZ8,92
45
45
  nuql/resources/fields/__init__.py,sha256=bajUBAvrK8kIMyb2vD_0NCwibRHOLo4Yoq1sac0Dobc,70
46
46
  nuql/resources/fields/field.py,sha256=NSynnwHwrKk7SaCvzpb2Zsjeu1LFNCfk0QR6cIKVvHo,5473
47
- nuql/resources/fields/field_map.py,sha256=tDDoXdyXnxRJWJ9Il7-uu81R_zSOUXiwrY5mllS3jYU,2517
47
+ nuql/resources/fields/field_map.py,sha256=bOzoBFbB2XOyLfnqaVEL_BDwt3S9_oUGIl1N0awgZ7g,2519
48
48
  nuql/resources/fields/value.py,sha256=CG3PnGeSMHDQciIMR6jkMhogCJZhpEfipLdyk9gnjJw,59
49
49
  nuql/resources/records/__init__.py,sha256=gD8-xt4uIOpx_ZTnw1QTzOiwUpjKhR3nhkZw4AmEvaI,81
50
50
  nuql/resources/records/projections.py,sha256=PTwoc8-XXieXsYw0H-3Fv7G8SzSN__j35QsqempXBj8,1618
@@ -60,7 +60,7 @@ nuql/types/__init__.py,sha256=Ea4KR4mUs1RNUEskKF9sXfGpoQw2V9cnIYeE20wkChs,76
60
60
  nuql/types/config.py,sha256=lFfPPe62l4DkfLXR8ecw5AiSRAFzsTYy_3a0d_1M7hY,659
61
61
  nuql/types/fields.py,sha256=LjGgXM84WO54gRDkgvnwF3pjFvFxErdGYOvs0BskF_o,883
62
62
  nuql/types/serialisation.py,sha256=XAy_gARcwYmfEuxWAJox2ClWK9ow0F5WXKVbMUVBq9w,242
63
- nuql-0.0.2.dist-info/METADATA,sha256=6ssfY-pyeYyxkXwz-aFFV7i7eZGb929QN5EPSvKPOjM,1735
64
- nuql-0.0.2.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
65
- nuql-0.0.2.dist-info/licenses/LICENSE,sha256=AS8DF6oGYsvk781m40Nec9eCkj_S_oUVAWaFakB2LMs,1097
66
- nuql-0.0.2.dist-info/RECORD,,
63
+ nuql-0.0.3.dist-info/METADATA,sha256=roZu3DYVIpe27JIm0RzEKQTbzk6jEqu7ofEcAhCmhbc,1735
64
+ nuql-0.0.3.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
65
+ nuql-0.0.3.dist-info/licenses/LICENSE,sha256=AS8DF6oGYsvk781m40Nec9eCkj_S_oUVAWaFakB2LMs,1097
66
+ nuql-0.0.3.dist-info/RECORD,,
File without changes