117 lines
3.1 KiB
Python
117 lines
3.1 KiB
Python
|
|
from __future__ import annotations
|
||
|
|
|
||
|
|
from collections.abc import Sequence
|
||
|
|
|
||
|
|
from repo_registry.core.models import Repository, RepositoryAbilityMap, SearchResult
|
||
|
|
from repo_registry.storage.sqlite import RegistryStore
|
||
|
|
|
||
|
|
|
||
|
|
class RegistryService:
|
||
|
|
"""Application service for the manual registry MVP."""
|
||
|
|
|
||
|
|
def __init__(self, store: RegistryStore) -> None:
|
||
|
|
self.store = store
|
||
|
|
|
||
|
|
def register_repository(
|
||
|
|
self,
|
||
|
|
*,
|
||
|
|
name: str,
|
||
|
|
url: str,
|
||
|
|
description: str | None = None,
|
||
|
|
branch: str = "main",
|
||
|
|
) -> Repository:
|
||
|
|
return self.store.create_repository(
|
||
|
|
name=name,
|
||
|
|
url=url,
|
||
|
|
description=description,
|
||
|
|
branch=branch,
|
||
|
|
)
|
||
|
|
|
||
|
|
def list_repositories(self) -> list[Repository]:
|
||
|
|
return self.store.list_repositories()
|
||
|
|
|
||
|
|
def get_repository(self, repository_id: int) -> Repository:
|
||
|
|
return self.store.get_repository(repository_id)
|
||
|
|
|
||
|
|
def add_ability(
|
||
|
|
self,
|
||
|
|
repository_id: int,
|
||
|
|
*,
|
||
|
|
name: str,
|
||
|
|
description: str = "",
|
||
|
|
confidence: float = 1.0,
|
||
|
|
) -> int:
|
||
|
|
self.store.get_repository(repository_id)
|
||
|
|
return self.store.create_ability(
|
||
|
|
repository_id,
|
||
|
|
name=name,
|
||
|
|
description=description,
|
||
|
|
confidence=confidence,
|
||
|
|
)
|
||
|
|
|
||
|
|
def add_capability(
|
||
|
|
self,
|
||
|
|
repository_id: int,
|
||
|
|
ability_id: int,
|
||
|
|
*,
|
||
|
|
name: str,
|
||
|
|
description: str = "",
|
||
|
|
inputs: Sequence[str] = (),
|
||
|
|
outputs: Sequence[str] = (),
|
||
|
|
confidence: float = 1.0,
|
||
|
|
) -> int:
|
||
|
|
self.store.ensure_ability(repository_id, ability_id)
|
||
|
|
return self.store.create_capability(
|
||
|
|
repository_id,
|
||
|
|
ability_id,
|
||
|
|
name=name,
|
||
|
|
description=description,
|
||
|
|
inputs=list(inputs),
|
||
|
|
outputs=list(outputs),
|
||
|
|
confidence=confidence,
|
||
|
|
)
|
||
|
|
|
||
|
|
def add_feature(
|
||
|
|
self,
|
||
|
|
repository_id: int,
|
||
|
|
capability_id: int,
|
||
|
|
*,
|
||
|
|
name: str,
|
||
|
|
type: str,
|
||
|
|
location: str = "",
|
||
|
|
confidence: float = 1.0,
|
||
|
|
) -> int:
|
||
|
|
self.store.ensure_capability(repository_id, capability_id)
|
||
|
|
return self.store.create_feature(
|
||
|
|
repository_id,
|
||
|
|
capability_id,
|
||
|
|
name=name,
|
||
|
|
type=type,
|
||
|
|
location=location,
|
||
|
|
confidence=confidence,
|
||
|
|
)
|
||
|
|
|
||
|
|
def add_evidence(
|
||
|
|
self,
|
||
|
|
repository_id: int,
|
||
|
|
capability_id: int,
|
||
|
|
*,
|
||
|
|
type: str,
|
||
|
|
reference: str,
|
||
|
|
strength: str = "medium",
|
||
|
|
) -> int:
|
||
|
|
self.store.ensure_capability(repository_id, capability_id)
|
||
|
|
return self.store.create_evidence(
|
||
|
|
repository_id,
|
||
|
|
capability_id,
|
||
|
|
type=type,
|
||
|
|
reference=reference,
|
||
|
|
strength=strength,
|
||
|
|
)
|
||
|
|
|
||
|
|
def ability_map(self, repository_id: int) -> RepositoryAbilityMap:
|
||
|
|
return self.store.get_ability_map(repository_id)
|
||
|
|
|
||
|
|
def search(self, query: str) -> list[SearchResult]:
|
||
|
|
return self.store.search(query)
|