Skip to content

Commit 894e84f

Browse files
authored
feat: make AuthEntryReference typed (#420)
1 parent a5adadd commit 894e84f

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

python/cocoindex/auth_registry.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,19 @@
33
"""
44

55
from dataclasses import dataclass
6+
from typing import Generic, TypeVar
67

78
from . import _engine
89
from .convert import dump_engine_object
910

11+
T = TypeVar("T")
12+
1013
@dataclass
11-
class AuthEntryReference:
14+
class AuthEntryReference(Generic[T]):
1215
"""Reference an auth entry by its key."""
1316
key: str
1417

15-
def add_auth_entry(key: str, value) -> AuthEntryReference:
18+
def add_auth_entry(key: str, value: T) -> AuthEntryReference[T]:
1619
"""Add an auth entry to the registry. Returns its reference."""
1720
_engine.add_auth_entry(key, dump_engine_object(value))
1821
return AuthEntryReference(key)

python/cocoindex/storages.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55
from . import op
66
from . import index
77
from .auth_registry import AuthEntryReference
8+
from .setting import DatabaseConnectionSpec
89

910
class Postgres(op.StorageSpec):
1011
"""Storage powered by Postgres and pgvector."""
11-
12-
database: AuthEntryReference | None = None
12+
database: AuthEntryReference[DatabaseConnectionSpec] | None = None
1313
table_name: str | None = None
1414

1515
@dataclass
@@ -72,15 +72,14 @@ class Relationships:
7272

7373
class Neo4j(op.StorageSpec):
7474
"""Graph storage powered by Neo4j."""
75-
76-
connection: AuthEntryReference
75+
connection: AuthEntryReference[Neo4jConnection]
7776
mapping: Nodes | Relationships
7877

7978
class Neo4jDeclaration(op.DeclarationSpec):
8079
"""Declarations for Neo4j."""
8180

8281
kind = "Neo4j"
83-
connection: AuthEntryReference
82+
connection: AuthEntryReference[Neo4jConnection]
8483
nodes_label: str
8584
primary_key_fields: Sequence[str]
8685
vector_indexes: Sequence[index.VectorIndexDef] = ()

0 commit comments

Comments
 (0)