Skip to content

Commit 7a09541

Browse files
committed
Improving helper types
1 parent 128d328 commit 7a09541

File tree

2 files changed

+106
-5
lines changed

2 files changed

+106
-5
lines changed

arangoasync/typings.py

Lines changed: 88 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1692,6 +1692,32 @@ def __init__(self, data: Json) -> None:
16921692
def name(self) -> str:
16931693
return cast(str, self._data["name"])
16941694

1695+
@property
1696+
def is_smart(self) -> bool:
1697+
"""Check if the graph is a smart graph."""
1698+
return cast(bool, self._data.get("isSmart", False))
1699+
1700+
@property
1701+
def is_satellite(self) -> bool:
1702+
"""Check if the graph is a satellite graph."""
1703+
return cast(bool, self._data.get("isSatellite", False))
1704+
1705+
@property
1706+
def number_of_shards(self) -> Optional[int]:
1707+
return cast(Optional[int], self._data.get("numberOfShards"))
1708+
1709+
@property
1710+
def replication_factor(self) -> Optional[int | str]:
1711+
return cast(Optional[int | str], self._data.get("replicationFactor"))
1712+
1713+
@property
1714+
def min_replication_factor(self) -> Optional[int]:
1715+
return cast(Optional[int], self._data.get("minReplicationFactor"))
1716+
1717+
@property
1718+
def write_concern(self) -> Optional[int]:
1719+
return cast(Optional[int], self._data.get("writeConcern"))
1720+
16951721
@property
16961722
def edge_definitions(self) -> Jsons:
16971723
return cast(Jsons, self._data.get("edgeDefinitions", list()))
@@ -1720,15 +1746,18 @@ class GraphOptions(JsonWrapper):
17201746
Enterprise Edition.
17211747
write_concern (int | None): The write concern for new collections in the
17221748
graph.
1749+
1750+
References:
1751+
- `create-a-graph <https://docs.arangodb.com/stable/develop/http-api/graphs/named-graphs/#create-a-graph>`__
17231752
""" # noqa: E501
17241753

17251754
def __init__(
17261755
self,
1727-
number_of_shards: Optional[int],
1728-
replication_factor: Optional[int | str],
1729-
satellites: Optional[List[str]],
1730-
smart_graph_attribute: Optional[str],
1731-
write_concern: Optional[int],
1756+
number_of_shards: Optional[int] = None,
1757+
replication_factor: Optional[int | str] = None,
1758+
satellites: Optional[List[str]] = None,
1759+
smart_graph_attribute: Optional[str] = None,
1760+
write_concern: Optional[int] = None,
17321761
) -> None:
17331762
data: Json = dict()
17341763
if number_of_shards is not None:
@@ -1762,3 +1791,57 @@ def smart_graph_attribute(self) -> Optional[str]:
17621791
@property
17631792
def write_concern(self) -> Optional[int]:
17641793
return cast(Optional[int], self._data.get("writeConcern"))
1794+
1795+
1796+
class VertexCollectionOptions(JsonWrapper):
1797+
"""Special options for vertex collection creation.
1798+
1799+
Args:
1800+
satellites (list): An array of collection names that is used to create
1801+
SatelliteCollections for a (Disjoint) SmartGraph using
1802+
SatelliteCollections (Enterprise Edition only). Each array element must
1803+
be a string and a valid collection name.
1804+
1805+
References:
1806+
- `add-a-vertex-collection <https://docs.arangodb.com/stable/develop/http-api/graphs/named-graphs/#add-a-vertex-collection>`__
1807+
""" # noqa: E501
1808+
1809+
def __init__(
1810+
self,
1811+
satellites: Optional[List[str]] = None,
1812+
) -> None:
1813+
data: Json = dict()
1814+
if satellites is not None:
1815+
data["satellites"] = satellites
1816+
super().__init__(data)
1817+
1818+
@property
1819+
def satellites(self) -> Optional[List[str]]:
1820+
return cast(Optional[List[str]], self._data.get("satellites"))
1821+
1822+
1823+
class EdgeDefinitionOptions(JsonWrapper):
1824+
"""Special options for edge definition creation.
1825+
1826+
Args:
1827+
satellites (list): An array of collection names that is used to create
1828+
SatelliteCollections for a (Disjoint) SmartGraph using
1829+
SatelliteCollections (Enterprise Edition only). Each array element must
1830+
be a string and a valid collection name.
1831+
1832+
References:
1833+
- `add-an-edge-definition <https://docs.arangodb.com/stable/develop/http-api/graphs/named-graphs/#add-an-edge-definition>`__
1834+
""" # noqa: E501
1835+
1836+
def __init__(
1837+
self,
1838+
satellites: Optional[List[str]] = None,
1839+
) -> None:
1840+
data: Json = dict()
1841+
if satellites is not None:
1842+
data["satellites"] = satellites
1843+
super().__init__(data)
1844+
1845+
@property
1846+
def satellites(self) -> Optional[List[str]]:
1847+
return cast(Optional[List[str]], self._data.get("satellites"))

tests/test_typings.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
CollectionInfo,
55
CollectionStatus,
66
CollectionType,
7+
EdgeDefinitionOptions,
78
GraphOptions,
89
GraphProperties,
910
JsonWrapper,
@@ -17,6 +18,7 @@
1718
QueryProperties,
1819
QueryTrackingConfiguration,
1920
UserInfo,
21+
VertexCollectionOptions,
2022
)
2123

2224

@@ -368,3 +370,19 @@ def test_GraphOptions():
368370
assert graph_options.satellites == ["satellite1", "satellite2"]
369371
assert graph_options.smart_graph_attribute == "region"
370372
assert graph_options.write_concern == 1
373+
374+
375+
def test_VertexCollectionOptions():
376+
options = VertexCollectionOptions(
377+
satellites=["col1", "col2"],
378+
)
379+
380+
assert options.satellites == ["col1", "col2"]
381+
382+
383+
def test_EdgeDefinitionOptions():
384+
options = EdgeDefinitionOptions(
385+
satellites=["col1", "col2"],
386+
)
387+
388+
assert options.satellites == ["col1", "col2"]

0 commit comments

Comments
 (0)