Skip to content

Commit b878987

Browse files
added ComponentConstructor class
1 parent 51cfea5 commit b878987

File tree

1 file changed

+72
-0
lines changed

1 file changed

+72
-0
lines changed
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
#
2+
# Copyright (c) 2025 Airbyte, Inc., all rights reserved.
3+
#
4+
5+
from dataclasses import dataclass
6+
from typing import Any, Callable, Generic, Mapping, Optional, Type, TypeVar
7+
8+
from airbyte_cdk.sources.declarative.models.declarative_component_schema import ValueType
9+
from airbyte_cdk.sources.types import Config
10+
from pydantic.v1 import BaseModel
11+
12+
M = TypeVar("M", bound=BaseModel)
13+
14+
15+
@dataclass
16+
class ComponentConstructor(Generic[M]):
17+
@classmethod
18+
def resolve_dependencies(
19+
cls,
20+
model: M,
21+
config: Config,
22+
dependency_constructor: Callable[..., Any],
23+
additional_flags: Optional[Mapping[str, Any]] = None,
24+
**kwargs: Any,
25+
) -> Mapping[str, Any]:
26+
"""
27+
Resolves the component's dependencies, this method should be created in the component,
28+
if there are any dependencies on other components, or we need to adopt / change / adjust / fine-tune
29+
specific component's behavior.
30+
"""
31+
return {}
32+
33+
@classmethod
34+
def build(
35+
cls,
36+
model: M,
37+
config: Config,
38+
dependency_constructor: Callable[..., Any],
39+
additional_flags: Optional[Mapping[str, Any]],
40+
**kwargs: Any,
41+
) -> "ComponentConstructor[M]":
42+
"""
43+
Builds up the Component and it's component-specific dependencies.
44+
Order of operations:
45+
- build the dependencies first
46+
- build the component with the resolved dependencies
47+
"""
48+
49+
# resolve the component dependencies first
50+
resolved_dependencies: Mapping[str, Any] = cls.resolve_dependencies(
51+
model=model,
52+
config=config,
53+
dependency_constructor=dependency_constructor,
54+
additional_flags=additional_flags,
55+
**kwargs,
56+
)
57+
58+
# returns the instance of the component class,
59+
# with resolved dependencies and model-specific arguments.
60+
return cls(**resolved_dependencies)
61+
62+
@staticmethod
63+
def _json_schema_type_name_to_type(value_type: Optional[ValueType]) -> Optional[Type[Any]]:
64+
if not value_type:
65+
return None
66+
names_to_types = {
67+
ValueType.string: str,
68+
ValueType.number: float,
69+
ValueType.integer: int,
70+
ValueType.boolean: bool,
71+
}
72+
return names_to_types[value_type]

0 commit comments

Comments
 (0)