o
    Zh'                     @   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                   @   sl   e Zd ZdZ		ddeeef dededee dee ddfd	d
Z	de
e fddZedef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d dee def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    c/var/www/html/lang_env/lib/python3.10/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__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                       L   e Zd ZdZ		d
deeef dedee dee ddf
 fdd	Z	  Z
S )AirbyteHubspotLoaderz8Load from `Hubspot` using an `Airbyte` source connector.Nr   r   r   r   r   c                    (   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      
zAirbyteHubspotLoader.__init__r.   r   r   r   r    r   r!   r   r   r/   r*   __classcell__r   r   r9   r   r2   B       
r2   c                       r1   )AirbyteStripeLoaderz7Load from `Stripe` using an `Airbyte` source connector.Nr   r   r   r   r   c                    r3   )r4   Zsource_stripezairbyte-source-striper5   r6   N)r   ZSourceStriper7   r*   r8   r9   r   r   r*   e   r;   zAirbyteStripeLoader.__init__r.   r<   r   r   r9   r   r?   b   r>   r?   c                       r1   )AirbyteTypeformLoaderz9Load from `Typeform` using an `Airbyte` source connector.Nr   r   r   r   r   c                    r3   )r4   Zsource_typeformzairbyte-source-typeformr5   r6   N)r   ZSourceTypeformr7   r*   r8   r9   r   r   r*      r;   zAirbyteTypeformLoader.__init__r.   r<   r   r   r9   r   r@      r>   r@   c                       r1   )AirbyteZendeskSupportLoaderz@Load from `Zendesk Support` using an `Airbyte` source connector.Nr   r   r   r   r   c                    r3   )r4   Zsource_zendesk_supportzairbyte-source-zendesk-supportr5   r6   N)r   ZSourceZendeskSupportr7   r*   r8   r9   r   r   r*      r;   z$AirbyteZendeskSupportLoader.__init__r.   r<   r   r   r9   r   rA      r>   rA   c                       r1   )AirbyteShopifyLoaderz8Load from `Shopify` using an `Airbyte` source connector.Nr   r   r   r   r   c                    r3   )r4   Zsource_shopifyzairbyte-source-shopifyr5   r6   N)r   ZSourceShopifyr7   r*   r8   r9   r   r   r*      r;   zAirbyteShopifyLoader.__init__r.   r<   r   r   r9   r   rB      r>   rB   c                       r1   )AirbyteSalesforceLoaderz;Load from `Salesforce` using an `Airbyte` source connector.Nr   r   r   r   r   c                    r3   )r4   Zsource_salesforcezairbyte-source-salesforcer5   r6   N)r   ZSourceSalesforcer7   r*   r8   r9   r   r   r*      r;   z AirbyteSalesforceLoader.__init__r.   r<   r   r   r9   r   rC      r>   rC   c                       r1   )AirbyteGongLoaderz5Load from `Gong` using an `Airbyte` source connector.Nr   r   r   r   r   c                    r3   )r4   Zsource_gongzairbyte-source-gongr5   r6   N)r   Z
SourceGongr7   r*   r8   r9   r   r   r*     r;   zAirbyteGongLoader.__init__r.   r<   r   r   r9   r   rD     r>   rD   N)typingr   r   r   r   r   Zlangchain_core.documentsr   Zlangchain_core.utils.utilsr   Z)langchain_community.document_loaders.baser	   r!   r/   r
   r2   r?   r@   rA   rB   rC   rD   r   r   r   r   <module>   s    7      