nuql 0.0.2__tar.gz → 0.0.4__tar.gz
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-0.0.2 → nuql-0.0.4}/PKG-INFO +1 -1
- nuql-0.0.4/nuql/fields/list.py +52 -0
- nuql-0.0.4/nuql/fields/map.py +37 -0
- {nuql-0.0.2 → nuql-0.0.4}/nuql/resources/fields/field.py +4 -1
- {nuql-0.0.2 → nuql-0.0.4}/nuql/resources/fields/field_map.py +2 -2
- {nuql-0.0.2 → nuql-0.0.4}/pyproject.toml +1 -1
- nuql-0.0.2/nuql/fields/list.py +0 -90
- nuql-0.0.2/nuql/fields/map.py +0 -67
- {nuql-0.0.2 → nuql-0.0.4}/.gitignore +0 -0
- {nuql-0.0.2 → nuql-0.0.4}/LICENSE +0 -0
- {nuql-0.0.2 → nuql-0.0.4}/nuql/__init__.py +0 -0
- {nuql-0.0.2 → nuql-0.0.4}/nuql/api/__init__.py +0 -0
- {nuql-0.0.2 → nuql-0.0.4}/nuql/api/adapter.py +0 -0
- {nuql-0.0.2 → nuql-0.0.4}/nuql/api/batch_get/__init__.py +0 -0
- {nuql-0.0.2 → nuql-0.0.4}/nuql/api/batch_get/batch_get.py +0 -0
- {nuql-0.0.2 → nuql-0.0.4}/nuql/api/batch_get/queue.py +0 -0
- {nuql-0.0.2 → nuql-0.0.4}/nuql/api/batch_write.py +0 -0
- {nuql-0.0.2 → nuql-0.0.4}/nuql/api/condition_check.py +0 -0
- {nuql-0.0.2 → nuql-0.0.4}/nuql/api/create.py +0 -0
- {nuql-0.0.2 → nuql-0.0.4}/nuql/api/delete.py +0 -0
- {nuql-0.0.2 → nuql-0.0.4}/nuql/api/get.py +0 -0
- {nuql-0.0.2 → nuql-0.0.4}/nuql/api/put_item.py +0 -0
- {nuql-0.0.2 → nuql-0.0.4}/nuql/api/put_update.py +0 -0
- {nuql-0.0.2 → nuql-0.0.4}/nuql/api/query/__init__.py +0 -0
- {nuql-0.0.2 → nuql-0.0.4}/nuql/api/query/condition.py +0 -0
- {nuql-0.0.2 → nuql-0.0.4}/nuql/api/query/condition_builder.py +0 -0
- {nuql-0.0.2 → nuql-0.0.4}/nuql/api/query/key_condition.py +0 -0
- {nuql-0.0.2 → nuql-0.0.4}/nuql/api/query/query.py +0 -0
- {nuql-0.0.2 → nuql-0.0.4}/nuql/api/transaction.py +0 -0
- {nuql-0.0.2 → nuql-0.0.4}/nuql/api/update/__init__.py +0 -0
- {nuql-0.0.2 → nuql-0.0.4}/nuql/api/update/expression_builder.py +0 -0
- {nuql-0.0.2 → nuql-0.0.4}/nuql/api/update/update_item.py +0 -0
- {nuql-0.0.2 → nuql-0.0.4}/nuql/api/update/utils.py +0 -0
- {nuql-0.0.2 → nuql-0.0.4}/nuql/api/upsert.py +0 -0
- {nuql-0.0.2 → nuql-0.0.4}/nuql/client.py +0 -0
- {nuql-0.0.2 → nuql-0.0.4}/nuql/connection.py +0 -0
- {nuql-0.0.2 → nuql-0.0.4}/nuql/exceptions.py +0 -0
- {nuql-0.0.2 → nuql-0.0.4}/nuql/fields/__init__.py +0 -0
- {nuql-0.0.2 → nuql-0.0.4}/nuql/fields/boolean.py +0 -0
- {nuql-0.0.2 → nuql-0.0.4}/nuql/fields/datetime.py +0 -0
- {nuql-0.0.2 → nuql-0.0.4}/nuql/fields/datetime_timestamp.py +0 -0
- {nuql-0.0.2 → nuql-0.0.4}/nuql/fields/float.py +0 -0
- {nuql-0.0.2 → nuql-0.0.4}/nuql/fields/integer.py +0 -0
- {nuql-0.0.2 → nuql-0.0.4}/nuql/fields/key.py +0 -0
- {nuql-0.0.2 → nuql-0.0.4}/nuql/fields/string.py +0 -0
- {nuql-0.0.2 → nuql-0.0.4}/nuql/fields/ulid.py +0 -0
- {nuql-0.0.2 → nuql-0.0.4}/nuql/fields/uuid.py +0 -0
- {nuql-0.0.2 → nuql-0.0.4}/nuql/generators/__init__.py +0 -0
- {nuql-0.0.2 → nuql-0.0.4}/nuql/generators/datetime.py +0 -0
- {nuql-0.0.2 → nuql-0.0.4}/nuql/generators/ulid.py +0 -0
- {nuql-0.0.2 → nuql-0.0.4}/nuql/generators/uuid.py +0 -0
- {nuql-0.0.2 → nuql-0.0.4}/nuql/resources/__init__.py +0 -0
- {nuql-0.0.2 → nuql-0.0.4}/nuql/resources/fields/__init__.py +0 -0
- {nuql-0.0.2 → nuql-0.0.4}/nuql/resources/fields/value.py +0 -0
- {nuql-0.0.2 → nuql-0.0.4}/nuql/resources/records/__init__.py +0 -0
- {nuql-0.0.2 → nuql-0.0.4}/nuql/resources/records/projections.py +0 -0
- {nuql-0.0.2 → nuql-0.0.4}/nuql/resources/records/serialiser.py +0 -0
- {nuql-0.0.2 → nuql-0.0.4}/nuql/resources/records/validator.py +0 -0
- {nuql-0.0.2 → nuql-0.0.4}/nuql/resources/tables/__init__.py +0 -0
- {nuql-0.0.2 → nuql-0.0.4}/nuql/resources/tables/indexes.py +0 -0
- {nuql-0.0.2 → nuql-0.0.4}/nuql/resources/tables/table.py +0 -0
- {nuql-0.0.2 → nuql-0.0.4}/nuql/resources/utils/__init__.py +0 -0
- {nuql-0.0.2 → nuql-0.0.4}/nuql/resources/utils/dict.py +0 -0
- {nuql-0.0.2 → nuql-0.0.4}/nuql/resources/utils/validators.py +0 -0
- {nuql-0.0.2 → nuql-0.0.4}/nuql/types/__init__.py +0 -0
- {nuql-0.0.2 → nuql-0.0.4}/nuql/types/config.py +0 -0
- {nuql-0.0.2 → nuql-0.0.4}/nuql/types/fields.py +0 -0
- {nuql-0.0.2 → nuql-0.0.4}/nuql/types/serialisation.py +0 -0
@@ -0,0 +1,52 @@
|
|
1
|
+
__all__ = ['List']
|
2
|
+
|
3
|
+
from typing import List as _List, Any
|
4
|
+
|
5
|
+
import nuql
|
6
|
+
from nuql import resources, types
|
7
|
+
from nuql.resources import FieldBase
|
8
|
+
|
9
|
+
|
10
|
+
class List(FieldBase):
|
11
|
+
type = 'list'
|
12
|
+
of: FieldBase
|
13
|
+
|
14
|
+
def on_init(self) -> None:
|
15
|
+
"""Defines the contents of the list."""
|
16
|
+
if 'of' not in self.config:
|
17
|
+
raise nuql.NuqlError(
|
18
|
+
code='SchemaError',
|
19
|
+
message='Config key \'of\' must be defined for the list field type'
|
20
|
+
)
|
21
|
+
|
22
|
+
# Initialise the configured 'of' field type
|
23
|
+
field_map = resources.create_field_map(
|
24
|
+
fields={'of': self.config['of']},
|
25
|
+
parent=self.parent,
|
26
|
+
field_types=self.parent.provider.fields
|
27
|
+
)
|
28
|
+
self.of = field_map['of']
|
29
|
+
|
30
|
+
def serialise_internal(
|
31
|
+
self,
|
32
|
+
value: Any,
|
33
|
+
action: 'types.SerialisationType',
|
34
|
+
validator: 'resources.Validator'
|
35
|
+
) -> Any:
|
36
|
+
"""Internal serialisation"""
|
37
|
+
if not isinstance(value, list):
|
38
|
+
return None
|
39
|
+
else:
|
40
|
+
return [self.of(item, action, validator) for item in value]
|
41
|
+
|
42
|
+
def deserialise(self, value: _List[Any] | None) -> _List[Any] | None:
|
43
|
+
"""
|
44
|
+
Deserialises a list of values.
|
45
|
+
|
46
|
+
:arg value: List or None.
|
47
|
+
:return: List or None.
|
48
|
+
"""
|
49
|
+
if not isinstance(value, list):
|
50
|
+
return None
|
51
|
+
|
52
|
+
return [self.of.deserialise(item) for item in value]
|
@@ -0,0 +1,37 @@
|
|
1
|
+
__all__ = ['Map']
|
2
|
+
|
3
|
+
from typing import Dict as _Dict, Any
|
4
|
+
|
5
|
+
import nuql
|
6
|
+
from nuql import resources, types
|
7
|
+
|
8
|
+
|
9
|
+
class Map(resources.FieldBase):
|
10
|
+
type = 'map'
|
11
|
+
fields: _Dict[str, Any] = {}
|
12
|
+
serialiser: 'resources.Serialiser' = None
|
13
|
+
|
14
|
+
def on_init(self) -> None:
|
15
|
+
"""Initialises the dict schema."""
|
16
|
+
if 'fields' not in self.config:
|
17
|
+
raise nuql.NuqlError(
|
18
|
+
code='SchemaError',
|
19
|
+
message='Config key \'fields\' must be defined for the dict field type'
|
20
|
+
)
|
21
|
+
|
22
|
+
self.fields = resources.create_field_map(self.config['fields'], self.parent, self.parent.provider.fields)
|
23
|
+
self.serialiser = resources.Serialiser(self)
|
24
|
+
|
25
|
+
def serialise_internal(
|
26
|
+
self,
|
27
|
+
value: Any,
|
28
|
+
action: 'types.SerialisationType',
|
29
|
+
validator: 'resources.Validator'
|
30
|
+
) -> Any:
|
31
|
+
"""Serialises the Map value"""
|
32
|
+
if value:
|
33
|
+
return self.serialiser.serialise(action, value, validator)
|
34
|
+
|
35
|
+
def deserialise(self, value: Any) -> Any:
|
36
|
+
"""Deserialises the Map value"""
|
37
|
+
return self.serialiser.deserialise(value)
|
@@ -96,7 +96,10 @@ class FieldBase:
|
|
96
96
|
value = self.default
|
97
97
|
|
98
98
|
# Serialise the value
|
99
|
-
|
99
|
+
if not isinstance(value, (None, resources.EmptyValue)):
|
100
|
+
value = self.serialise_internal(value, action, validator)
|
101
|
+
else:
|
102
|
+
value = None
|
100
103
|
|
101
104
|
# Validate required field
|
102
105
|
if self.required and action == 'create' and value is None:
|
@@ -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(
|
65
|
+
if not inspect.isclass(_obj):
|
66
66
|
return False
|
67
67
|
|
68
|
-
if not issubclass(
|
68
|
+
if not issubclass(_obj, resources.FieldBase):
|
69
69
|
return False
|
70
70
|
|
71
71
|
return True
|
nuql-0.0.2/nuql/fields/list.py
DELETED
@@ -1,90 +0,0 @@
|
|
1
|
-
__all__ = ['List']
|
2
|
-
|
3
|
-
from typing import List as _List, Any
|
4
|
-
|
5
|
-
import nuql
|
6
|
-
from nuql import resources, types
|
7
|
-
from nuql.resources import FieldBase
|
8
|
-
|
9
|
-
|
10
|
-
class List(FieldBase):
|
11
|
-
type = 'list'
|
12
|
-
of: FieldBase
|
13
|
-
|
14
|
-
def on_init(self) -> None:
|
15
|
-
"""Defines the contents of the list."""
|
16
|
-
if 'of' not in self.config:
|
17
|
-
raise nuql.NuqlError(
|
18
|
-
code='SchemaError',
|
19
|
-
message='Config key \'of\' must be defined for the list field type'
|
20
|
-
)
|
21
|
-
|
22
|
-
# Initialise the configured 'of' field type
|
23
|
-
field_map = resources.create_field_map(
|
24
|
-
fields={'of': self.config['of']},
|
25
|
-
parent=self.parent,
|
26
|
-
field_types=self.parent.provider.fields
|
27
|
-
)
|
28
|
-
self.of = field_map['of']
|
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
|
58
|
-
if not isinstance(value, list):
|
59
|
-
value = None
|
60
|
-
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
|
79
|
-
|
80
|
-
def deserialise(self, value: _List[Any] | None) -> _List[Any] | None:
|
81
|
-
"""
|
82
|
-
Deserialises a list of values.
|
83
|
-
|
84
|
-
:arg value: List or None.
|
85
|
-
:return: List or None.
|
86
|
-
"""
|
87
|
-
if not isinstance(value, list):
|
88
|
-
return None
|
89
|
-
|
90
|
-
return [self.of.deserialise(item) for item in value]
|
nuql-0.0.2/nuql/fields/map.py
DELETED
@@ -1,67 +0,0 @@
|
|
1
|
-
__all__ = ['Map']
|
2
|
-
|
3
|
-
from typing import Dict as _Dict, Any
|
4
|
-
|
5
|
-
import nuql
|
6
|
-
from nuql import resources, types
|
7
|
-
|
8
|
-
|
9
|
-
class Map(resources.FieldBase):
|
10
|
-
type = 'map'
|
11
|
-
fields: _Dict[str, Any] = {}
|
12
|
-
serialiser: 'resources.Serialiser' = None
|
13
|
-
|
14
|
-
def on_init(self) -> None:
|
15
|
-
"""Initialises the dict schema."""
|
16
|
-
if 'fields' not in self.config:
|
17
|
-
raise nuql.NuqlError(
|
18
|
-
code='SchemaError',
|
19
|
-
message='Config key \'fields\' must be defined for the dict field type'
|
20
|
-
)
|
21
|
-
|
22
|
-
self.fields = resources.create_field_map(self.config['fields'], self.parent, self.parent.provider.fields)
|
23
|
-
self.serialiser = resources.Serialiser(self)
|
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
|
53
|
-
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)
|
66
|
-
|
67
|
-
return value
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|