1- # Copyright (c) 2025 the Eclipse BaSyx Authors
1+ # Copyright (c) 2026 the Eclipse BaSyx Authors
22#
33# This program and the accompanying materials are made available under the terms of the MIT License, available in
44# the LICENSE file of this project.
1717from .base import Identifier , Identifiable
1818
1919
20- _K = TypeVar ('_K' )
21- _V = TypeVar ('_V' )
20+ _KEY = TypeVar ('_KEY' ) # Generic key type
21+ _VALUE = TypeVar ('_VALUE' ) # Generic value type
2222
2323
24- class AbstractObjectProvider (Generic [_K , _V ], metaclass = abc .ABCMeta ):
24+ class AbstractObjectProvider (Generic [_KEY , _VALUE ], metaclass = abc .ABCMeta ):
2525 """
26- Documentation when we agree on this solution.
26+ Abstract base class for all objects that allow retrieving values by a key.
27+
28+ This includes local object stores, database clients and AAS API clients.
2729 """
2830
2931 @abc .abstractmethod
30- def get_item (self , key : _K ) -> _V :
32+ def get_item (self , key : _KEY ) -> _VALUE :
3133 """Retrieve the item or raise a KeyError."""
3234 pass
3335
34- def get (self , key : _K , default : Optional [_V ] = None ) -> Optional [_V ]:
36+ def get (self , key : _KEY , default : Optional [_VALUE ] = None ) -> Optional [_VALUE ]:
3537 """Retrieve the item or return a default value."""
3638 try :
3739 return self .get_item (key )
3840 except KeyError :
3941 return default
4042
4143
42- class AbstractObjectStore (AbstractObjectProvider [_K , _V ], MutableSet [_V ]):
44+ class AbstractObjectStore (AbstractObjectProvider [_KEY , _VALUE ], MutableSet [_VALUE ]):
4345 """
44- Abstract baseclass of for container-like objects for storage of :class:`~basyx.aas.model.base.Identifiable` objects .
46+ Abstract base class for container-like objects for storage of values .
4547
46- ObjectStores are special ObjectProvides that – in addition to retrieving objects by
47- :class:`~basyx.aas.model.base.Identifier` – allow to add and delete objects (i.e. behave like a Python set).
48- This includes local object stores (like :class:`~.DictObjectStore`) and specific object stores
49- (like :class:`~basyx.aas.backend.couchdb.CouchDBObjectStore` and
48+ ObjectStores are special ObjectProviders that, in addition to retrieving values by a key, allow adding and deleting
49+ values (i.e. behave like a Python set). This includes local object stores (like :class:`~.DictObjectStore`) and
50+ specific object stores (like :class:`~basyx.aas.backend.couchdb.CouchDBObjectStore` and
5051 :class:`~basyx.aas.backend.local_file.LocalFileObjectStore`).
5152
5253 The AbstractObjectStore inherits from the :class:`~collections.abc.MutableSet` abstract collections class and
@@ -57,22 +58,20 @@ class AbstractObjectStore(AbstractObjectProvider[_K, _V], MutableSet[_V]):
5758 def __init__ (self ):
5859 pass
5960
60- def update (self , other : Iterable [_V ]) -> None :
61+ def update (self , other : Iterable [_VALUE ]) -> None :
6162 for x in other :
6263 self .add (x )
6364
64- def sync (self , other : Iterable [_V ], overwrite : bool ) -> Tuple [int , int , int ]:
65+ def sync (self , other : Iterable [_VALUE ], overwrite : bool ) -> Tuple [int , int , int ]:
6566 """
66- Merge :class:`Identifiables <basyx.aas.model.base.Identifiable>` from an
67- :class:`~collections.abc.Iterable` into this :class:`~ basyx.aas.model.provider.AbstractObjectStore`.
67+ Merge values from an :class:`~collections.abc.Iterable` into this
68+ :class:`~basyx.aas.model.provider.AbstractObjectStore`.
6869
6970 :param other: :class:`~collections.abc.Iterable` to sync with
70- :param overwrite: Flag to overwrite existing :class:`Identifiables <basyx.aas.model.base.Identifiable>` in this
71+ :param overwrite: Flag to overwrite existing values in this
7172 :class:`~basyx.aas.model.provider.AbstractObjectStore` with updated versions from ``other``,
72- :class:`Identifiables <basyx.aas.model.base.Identifiable>` unique to this
73- :class:`~basyx.aas.model.provider.AbstractObjectStore` are always preserved
74- :return: Counts of processed :class:`Identifiables <basyx.aas.model.base.Identifiable>` as
75- ``(added, overwritten, skipped)``
73+ values unique to this :class:`~basyx.aas.model.provider.AbstractObjectStore` are always preserved
74+ :return: Counts of processed values as``(added, overwritten, skipped)``
7675 """
7776 added , overwritten , skipped = 0 , 0 , 0
7877 for value in other :
@@ -103,6 +102,31 @@ def sync(self, other: Iterable[_V], overwrite: bool) -> Tuple[int, int, int]:
103102 return added , overwritten , skipped
104103
105104
105+ class ObjectProviderMultiplexer (AbstractObjectProvider [_KEY , _VALUE ]):
106+ """
107+ A multiplexer for :class:`AbstractObjectProviders <.AbstractObjectProvider>`.
108+
109+ This class combines multiple :class:`AbstractObjectProviders <.AbstractObjectProvider>` into a single one to allow
110+ retrieving values from different sources. It implements the :class:`~.AbstractObjectProvider` interface to be used
111+ as registry itself.
112+
113+ :param registries: A list of :class:`AbstractObjectProviders <.AbstractObjectProvider>` to query when looking up a
114+ key
115+ """
116+
117+ def __init__ (self , registries : Optional [List [AbstractObjectProvider [_KEY , _VALUE ]]] = None ) -> None :
118+ self .providers : List [AbstractObjectProvider [_KEY , _VALUE ]] = registries if registries is not None else []
119+
120+ def get_item (self , key : _KEY ) -> _VALUE :
121+ for provider in self .providers :
122+ try :
123+ return provider .get_item (key )
124+ except KeyError :
125+ pass
126+ raise KeyError ("Key could not be found in any of the {} consulted registries."
127+ .format (len (self .providers )))
128+
129+
106130_IT = TypeVar ('_IT' , bound = Identifiable )
107131
108132
@@ -153,7 +177,7 @@ def __iter__(self) -> Iterator[_IT]:
153177 return iter (self ._backend .values ())
154178
155179
156- class DictObjectStore (DictIdentifiableStore ):
180+ class DictObjectStore (DictIdentifiableStore [ _IT ] ):
157181 """
158182 `DictObjectStore` has been renamed to :class:`~.DictIdentifiableStore` and will be removed in a future release.
159183 Please migrate to :class:`~.DictIdentifiableStore`.
@@ -168,6 +192,14 @@ def __init__(self, iterables: Iterable[_IT] = ()) -> None:
168192 )
169193 super ().__init__ (iterables )
170194
195+ def get_identifiable (self , identifier : Identifier ) -> _IT :
196+ warnings .warn (
197+ "`get_identifiable()` is deprecated. Use `get_item()` from `DictIdentifiableStore` instead." ,
198+ DeprecationWarning ,
199+ stacklevel = 2 ,
200+ )
201+ return super ().get_item (identifier )
202+
171203
172204class SetIdentifiableStore (AbstractObjectStore [Identifier , _IT ]):
173205 """
@@ -228,7 +260,7 @@ def __iter__(self) -> Iterator[_IT]:
228260 return iter (self ._backend )
229261
230262
231- class SetObjectStore (SetIdentifiableStore ):
263+ class SetObjectStore (SetIdentifiableStore [ _IT ] ):
232264 """
233265 `SetObjectStore` has been renamed to :class:`~.SetIdentifiableStore` and will be removed in a future release.
234266 Please migrate to :class:`~.SetIdentifiableStore`.
@@ -243,27 +275,10 @@ def __init__(self, objects: Iterable[_IT] = ()) -> None:
243275 )
244276 super ().__init__ (objects )
245277
246-
247- class ObjectProviderMultiplexer (AbstractObjectProvider [_K , _V ]):
248- """
249- A multiplexer for Providers of :class:`~basyx.aas.model.base.Identifiable` objects.
250-
251- This class combines multiple registries of :class:`~basyx.aas.model.base.Identifiable` objects into a single one
252- to allow retrieving :class:`~basyx.aas.model.base.Identifiable` objects from different sources.
253- It implements the :class:`~.AbstractObjectProvider` interface to be used as registry itself.
254-
255- :param registries: A list of :class:`AbstractObjectProviders <.AbstractObjectProvider>` to query when looking up an
256- object
257- """
258-
259- def __init__ (self , registries : Optional [List [AbstractObjectProvider [_K , _V ]]] = None ) -> None :
260- self .providers : List [AbstractObjectProvider [_K , _V ]] = registries if registries is not None else []
261-
262- def get_item (self , key : _K ) -> _V :
263- for provider in self .providers :
264- try :
265- return provider .get_item (key )
266- except KeyError :
267- pass
268- raise KeyError ("Key could not be found in any of the {} consulted registries."
269- .format (len (self .providers )))
278+ def get_identifiable (self , identifier : Identifier ) -> _IT :
279+ warnings .warn (
280+ "`get_identifiable()` is deprecated. Use `get_item()` from `SetIdentifiableStore` instead." ,
281+ DeprecationWarning ,
282+ stacklevel = 2 ,
283+ )
284+ return super ().get_item (identifier )
0 commit comments