domain.protocols.provider_repository¶
src.domain.protocols.provider_repository
¶
Provider repository protocol.
Defines the interface for provider persistence operations. Providers are typically seeded at deployment and rarely change.
Classes¶
ProviderRepository
¶
Bases: Protocol
Protocol for provider persistence operations.
Defines the contract for storing and retrieving provider data. Infrastructure layer provides concrete implementations (e.g., PostgreSQL).
Design Principles: - Read methods return domain entities (Provider), not database models - Providers are relatively static (seeded at deployment) - Most operations are reads (list, get by slug/id) - Write operations typically admin-only or migration scripts
Implementation Notes: - Caching recommended since providers rarely change - slug is unique and the primary lookup key - is_active filters available providers from inactive ones
Source code in src/domain/protocols/provider_repository.py
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 | |
Functions¶
find_by_id
async
¶
Find provider by ID.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
provider_id
|
UUID
|
Unique provider identifier. |
required |
Returns:
| Type | Description |
|---|---|
Provider | None
|
Provider entity if found, None otherwise. |
Example
provider = await repo.find_by_id(provider_id) if provider: ... print(f"Found: {provider.name}")
Source code in src/domain/protocols/provider_repository.py
find_by_slug
async
¶
Find provider by slug.
This is the primary lookup method - slug is human-readable and used in URLs, configs, and API requests.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
slug
|
str
|
Provider slug (e.g., "schwab", "chase"). |
required |
Returns:
| Type | Description |
|---|---|
Provider | None
|
Provider entity if found, None otherwise. |
Example
provider = await repo.find_by_slug("schwab") if provider: ... print(f"Found: {provider.name}")
Source code in src/domain/protocols/provider_repository.py
list_all
async
¶
List all providers (including inactive).
Returns:
| Type | Description |
|---|---|
list[Provider]
|
List of all providers in the registry. |
Example
providers = await repo.list_all() print(f"Total providers: {len(providers)}")
Source code in src/domain/protocols/provider_repository.py
list_active
async
¶
List only active providers.
Returns providers available for new connections.
Returns:
| Type | Description |
|---|---|
list[Provider]
|
List of active providers. |
Example
providers = await repo.list_active() for p in providers: ... print(f"{p.name} ({p.slug})")
Source code in src/domain/protocols/provider_repository.py
save
async
¶
Save a provider (create or update).
Creates new provider if ID doesn't exist, updates if it does. Typically used in migrations/seeding, not runtime operations.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
provider
|
Provider
|
Provider entity to save. |
required |
Raises:
| Type | Description |
|---|---|
DuplicateSlugError
|
If slug already exists for different provider. |
Example
provider = Provider( ... id=uuid7(), ... slug="schwab", ... name="Charles Schwab", ... credential_type=CredentialType.OAUTH2, ... ) await repo.save(provider)
Source code in src/domain/protocols/provider_repository.py
exists_by_slug
async
¶
Check if provider with slug exists.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
slug
|
str
|
Provider slug to check. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if provider exists, False otherwise. |
Example
if await repo.exists_by_slug("schwab"): ... print("Schwab is already registered")