Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chore/backing store support #101

Merged
merged 18 commits into from
Aug 4, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# ------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All Rights Reserved.
# Licensed under the MIT License.
# See License in the project root for license information.
# ------------------------------------------------------------------------------

from typing import Callable, Optional

from .parsable import Parsable
Expand Down
32 changes: 24 additions & 8 deletions kiota_abstractions/store/backed_model.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,33 @@
# ------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All Rights Reserved.
# Licensed under the MIT License.
# See License in the project root for license information.
# ------------------------------------------------------------------------------

from abc import ABC, abstractmethod
from dataclasses import dataclass
from typing import Optional

from .backing_store import BackingStore


class BackedModel(ABC):
@dataclass
class BackedModel:
"""Defines the contracts for a model that is backed by a store.
"""
# Stores model information.
backing_store: BackingStore

def __setattr__(self, prop, val):
if not prop == "backing_store":
self.__backing_store.set(prop, val)
super().__setattr__(prop, self.__backing_store.get(prop))
super().__setattr__(prop, val)

@abstractmethod
def get_backing_store(self) -> BackingStore:
"""Gets the store that is backing the model
@property
def __backing_store(self):
return self.backing_store

Returns:
BackingStore: The store backing the model
"""
pass
@__backing_store.setter
def __backing_store(self, value):
self.backing_store = value
37 changes: 26 additions & 11 deletions kiota_abstractions/store/backing_store.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# ------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All Rights Reserved.
# Licensed under the MIT License.
# See License in the project root for license information.
# ------------------------------------------------------------------------------

from abc import ABC, abstractmethod
from typing import Any, Callable, Generic, List, Optional, Tuple, TypeVar

Expand All @@ -7,8 +13,7 @@
class BackingStore(ABC, Generic[T]):
"""Stores model information in a different location than the object properties.
Implementations can provide dirty tracking capabilities, caching capabilities
or integration with 3rd party stores
"""
or integration with 3rd party stores"""

@abstractmethod
def get(self, key: str) -> Optional[T]:
Expand Down Expand Up @@ -54,7 +59,9 @@ def enumerate_keys_for_values_changed_to_null(self) -> List[str]:

@abstractmethod
def subscribe(
self, callback: Callable[[str, Any, Any], None], subscription_id: Optional[str]
self,
callback: Callable[[str, Any, Any], None],
subscription_id: Optional[str] = None
) -> str:
"""Creates a subscription to any data change happening.

Expand Down Expand Up @@ -83,8 +90,9 @@ def clear(self) -> None:
"""Clears the data stored in the backing store. Doesn't trigger any subscription."""
pass

@property
@abstractmethod
def get_is_initialization_completed(self) -> bool:
def is_initialization_completed(self) -> bool:
"""Whether the initialization of the object and/or the initial deserialization has been
completed to track whether objects have changed.

Expand All @@ -93,15 +101,20 @@ def get_is_initialization_completed(self) -> bool:
"""
pass

@is_initialization_completed.setter
@abstractmethod
def set_is_initialization_completed(self, completed) -> None:
"""Sets whether the initialization of the object and/or the initial deserialization has been
completed to track whether objects have changed.
def is_initialization_completed(self, completed: bool) -> None:
"""Sets the initialization completed state of the object.

Args:
completed (bool): Whether the initialization of the object and/or the initial
deserialization has been completed to track whether objects have changed.
"""
pass

@property
@abstractmethod
def get_return_only_changed_values(self) -> bool:
def return_only_changed_values(self) -> bool:
"""Whether to return only values that have changed since the initialization of the object
when calling the Get and Enumerate methods.

Expand All @@ -110,12 +123,14 @@ def get_return_only_changed_values(self) -> bool:
"""
pass

@return_only_changed_values.setter
@abstractmethod
def set_return_only_changed_values(self, changed) -> None:
def return_only_changed_values(self, changed: bool) -> None:
"""Sets whether to return only values that have changed since the initialization of the
object when calling the Get and Enumerate methods.

Returns:
bool:
Args:
changed (bool): Whether to return only values that have changed since the
initialization of the object when calling the Get and Enumerate methods.
"""
pass
6 changes: 6 additions & 0 deletions kiota_abstractions/store/backing_store_factory.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# ------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All Rights Reserved.
# Licensed under the MIT License.
# See License in the project root for license information.
# ------------------------------------------------------------------------------

from abc import ABC, abstractmethod

from .backing_store import BackingStore
Expand Down
10 changes: 7 additions & 3 deletions kiota_abstractions/store/backing_store_factory_singleton.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
# ------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All Rights Reserved.
# Licensed under the MIT License.
# See License in the project root for license information.
# ------------------------------------------------------------------------------

from typing_extensions import Self

from kiota_abstractions.store.backing_store_factory import BackingStoreFactory
from kiota_abstractions.store.in_memory_backing_store_factory import (
InMemoryBackingStoreFactory,
)
from kiota_abstractions.store.in_memory_backing_store_factory import InMemoryBackingStoreFactory


class BackingStoreFactorySingleton:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# ------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All Rights Reserved.
# Licensed under the MIT License.
# See License in the project root for license information.
# ------------------------------------------------------------------------------

from typing import Callable

from ..serialization import Parsable, ParseNodeFactory, ParseNodeProxyFactory
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# ------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All Rights Reserved.
# Licensed under the MIT License.
# See License in the project root for license information.
# ------------------------------------------------------------------------------

from ..serialization import SerializationWriterFactory, SerializationWriterProxyFactory
from .backed_model import BackedModel

Expand Down
Loading