a
    bg'                     @   s   d dl mZmZmZmZmZ d dlmZ d dlm	Z	 d dl
mZ eeee gef ZG dd deZG dd deZG d	d
 d
eZG dd deZG dd deZG dd deZG dd deZG dd deZdS )    )AnyCallableIteratorMappingOptional)Document)guard_import)
BaseLoaderc                   @   s^   e Zd ZdZdeeef eeee ee ddddZ	e
e dddZeedd	d
ZdS )AirbyteCDKLoaderzDLoad with an `Airbyte` source connector implemented using the `CDK`.N)configsource_classstream_namerecord_handlerstatereturnc           	         sd   ddl m  ddlm} ddlm} G  fddd|}|||| |jdd| _|| _|| _	d	S )
a  Initializes the loader.

        Args:
            config: The config to pass to the source connector.
            source_class: The source connector class.
            stream_name: The name of the stream to load.
            record_handler: A function that takes in a record and an optional id and
                returns a Document. If None, the record will be used as the document.
                Defaults to None.
            state: The state to pass to the source connector. Defaults to None.
        r   )AirbyteRecordMessage)BaseEmbeddedIntegration)	CDKRunnerc                       s*   e Zd ZdZ ee edfddZdS )z1AirbyteCDKLoader.__init__.<locals>.CDKIntegrationz%A wrapper around the CDK integration.)recordidr   c                    s    r ||S t d|jdS )N )Zpage_contentmetadata)r   data)selfr   r   )r    z/var/www/html/cobodadashboardai.evdpl.com/venv/lib/python3.9/site-packages/langchain_community/document_loaders/airbyte.py_handle_record*   s    
z@AirbyteCDKLoader.__init__.<locals>.CDKIntegration._handle_recordN)__name__
__module____qualname____doc__r   strr   r   r   r   r   r   r   CDKIntegration'   s   r#   )sourcename)r   runnerN)
Z#airbyte_cdk.models.airbyte_protocolr   Z-airbyte_cdk.sources.embedded.base_integrationr   Z#airbyte_cdk.sources.embedded.runnerr   r   _integration_stream_name_state)	r   r   r   r   r   r   r   r   r#   r   r"   r   __init__   s    
zAirbyteCDKLoader.__init__)r   c                 C   s   | j j| j| jdS )N)r   r   )r'   Z
_load_datar(   r)   r   r   r   r   	lazy_load8   s    zAirbyteCDKLoader.lazy_loadc                 C   s   | j jS )N)r'   
last_stater+   r   r   r   r-   =   s    zAirbyteCDKLoader.last_state)NN)r   r   r   r    r   r!   r   r   RecordHandlerr*   r   r   r,   propertyr-   r   r   r   r   r
      s     
*r
   c                       s@   e Zd ZdZdeeef eee ee dd fddZ	  Z
S )AirbyteHubspotLoaderz8Load from `Hubspot` using an `Airbyte` source connector.Nr   r   r   r   r   c                    s(   t dddj}t j|||||d dS )  Initializes the loader.

        Args:
            config: The config to pass to the source connector.
            stream_name: The name of the stream to load.
            record_handler: A function that takes in a record and an optional id and
                returns a Document. If None, the record will be used as the document.
                Defaults to None.
            state: The state to pass to the source connector. Defaults to None.
        Zsource_hubspotzairbyte-source-hubspotZpip_namer   r   r   r   r   N)r   ZSourceHubspotsuperr*   r   r   r   r   r   r   	__class__r   r   r*   E   s    zAirbyteHubspotLoader.__init__)NNr   r   r   r    r   r!   r   r   r.   r*   __classcell__r   r   r7   r   r0   B   s     
r0   c                       s@   e Zd ZdZdeeef eee ee dd fddZ	  Z
S )AirbyteStripeLoaderz7Load from `Stripe` using an `Airbyte` source connector.Nr1   c                    s(   t dddj}t j|||||d dS )r2   Zsource_stripezairbyte-source-striper3   r4   N)r   ZSourceStriper5   r*   r6   r7   r   r   r*   e   s    zAirbyteStripeLoader.__init__)NNr9   r   r   r7   r   r;   b   s     
r;   c                       s@   e Zd ZdZdeeef eee ee dd fddZ	  Z
S )AirbyteTypeformLoaderz9Load from `Typeform` using an `Airbyte` source connector.Nr1   c                    s(   t dddj}t j|||||d dS )r2   Zsource_typeformzairbyte-source-typeformr3   r4   N)r   ZSourceTypeformr5   r*   r6   r7   r   r   r*      s    zAirbyteTypeformLoader.__init__)NNr9   r   r   r7   r   r<      s     
r<   c                       s@   e Zd ZdZdeeef eee ee dd fddZ	  Z
S )AirbyteZendeskSupportLoaderz@Load from `Zendesk Support` using an `Airbyte` source connector.Nr1   c                    s(   t dddj}t j|||||d dS )r2   Zsource_zendesk_supportzairbyte-source-zendesk-supportr3   r4   N)r   ZSourceZendeskSupportr5   r*   r6   r7   r   r   r*      s    z$AirbyteZendeskSupportLoader.__init__)NNr9   r   r   r7   r   r=      s     
r=   c                       s@   e Zd ZdZdeeef eee ee dd fddZ	  Z
S )AirbyteShopifyLoaderz8Load from `Shopify` using an `Airbyte` source connector.Nr1   c                    s(   t dddj}t j|||||d dS )r2   Zsource_shopifyzairbyte-source-shopifyr3   r4   N)r   ZSourceShopifyr5   r*   r6   r7   r   r   r*      s    zAirbyteShopifyLoader.__init__)NNr9   r   r   r7   r   r>      s     
r>   c                       s@   e Zd ZdZdeeef eee ee dd fddZ	  Z
S )AirbyteSalesforceLoaderz;Load from `Salesforce` using an `Airbyte` source connector.Nr1   c                    s(   t dddj}t j|||||d dS )r2   Zsource_salesforcezairbyte-source-salesforcer3   r4   N)r   ZSourceSalesforcer5   r*   r6   r7   r   r   r*      s    z AirbyteSalesforceLoader.__init__)NNr9   r   r   r7   r   r?      s     
r?   c                       s@   e Zd ZdZdeeef eee ee dd fddZ	  Z
S )AirbyteGongLoaderz5Load from `Gong` using an `Airbyte` source connector.Nr1   c                    s(   t dddj}t j|||||d dS )r2   Zsource_gongzairbyte-source-gongr3   r4   N)r   Z
SourceGongr5   r*   r6   r7   r   r   r*     s    zAirbyteGongLoader.__init__)NNr9   r   r   r7   r   r@     s     
r@   N)typingr   r   r   r   r   Zlangchain_core.documentsr   Zlangchain_core.utils.utilsr   Z)langchain_community.document_loaders.baser	   r!   r.   r
   r0   r;   r<   r=   r>   r?   r@   r   r   r   r   <module>   s   7      