Coverage for /home/runner/work/bijux-cli/bijux-cli/src/bijux_cli/contracts/memory.py: 100%
10 statements
« prev ^ index » next coverage.py v7.10.4, created at 2025-08-19 23:36 +0000
« prev ^ index » next coverage.py v7.10.4, created at 2025-08-19 23:36 +0000
1# SPDX-License-Identifier: MIT
2# Copyright © 2025 Bijan Mousavi
4"""Defines the contract for the transient in-memory key-value service.
6This module specifies the `MemoryProtocol`, a formal interface that any
7service providing a non-persistent, in-memory key-value store must
8implement. This is used for managing ephemeral state within the CLI.
9"""
11from __future__ import annotations
13from typing import Any, Protocol, TypeVar, runtime_checkable
15T = TypeVar("T")
18@runtime_checkable
19class MemoryProtocol(Protocol):
20 """Defines the contract for a simple in-memory key-value store.
22 This interface specifies the essential methods for a basic key-value data
23 storage service. It is used for managing ephemeral state within the CLI
24 that does not need to persist across sessions.
25 """
27 def get(self, key: str) -> Any:
28 """Retrieves a value by its key.
30 Args:
31 key (str): The key of the value to retrieve.
33 Returns:
34 Any: The value associated with the key.
36 Raises:
37 KeyError: If the key does not exist in the store.
38 """
39 ...
41 def set(self, key: str, value: Any) -> None:
42 """Sets a key-value pair in the store.
44 If the key already exists, its value will be overwritten.
46 Args:
47 key (str): The key for the value being set.
48 value (Any): The value to store.
50 Returns:
51 None:
52 """
53 ...
55 def delete(self, key: str) -> None:
56 """Deletes a key-value pair by its key.
58 Args:
59 key (str): The key of the value to delete.
61 Raises:
62 KeyError: If the key does not exist in the store.
63 """
64 ...
66 def clear(self) -> None:
67 """Removes all key-value pairs from the store."""
68 ...
70 def keys(self) -> list[str]:
71 """Returns a list of all keys currently in the store.
73 Returns:
74 list[str]: A list of all string keys.
75 """
76 ...