o
    zsg                     @   s   d dl mZmZmZmZmZ d dlmZ d dlm	Z	m
Z
 ddlmZmZ ddlmZmZmZmZmZ ddlmZ G dd	 d	Zd
S )    )AnyDictLiteralOptionalUnion)warn)	HTTPErrorResponse   )FunctionsHttpErrorFunctionsRelayError)AsyncClientFunctionRegionis_http_urlis_valid_jwtis_valid_str_arg)__version__c                   @   s   e Zd Z		ddededededee f
dd	Z		dd
e	d dedeeeef  deee
e
f  def
ddZdeddfddZ	ddedee deeef fddZdS )AsyncFunctionsClientTNurlheaderstimeoutverifyproxyc              	   C   sV   t |std || _ddt i|| _t| j| jt|tt||ddd| _	d S )Nz#url must be a valid HTTP URL stringz
User-Agentzsupabase-py/functions-py vT)base_urlr   r   r   r   follow_redirectshttp2)
r   
ValueErrorr   r   r   r   boolintabs_client)selfr   r   r   r   r    r"   \/var/www/html/minecraft/env/lib/python3.10/site-packages/supafunc/_async/functions_client.py__init__   s    

zAsyncFunctionsClient.__init__method)GETOPTIONSHEADPOSTPUTPATCHDELETEjsonreturnc              
      sh   | j j||||dI d H }z|  W |S  ty3 } zt| dp,d|jjd|d }~ww )N)r-   r   errorz9An error occurred while requesting your edge function at .)r    requestraise_for_statusr   r   r-   getr   )r!   r%   r   r   r-   responseexcr"   r"   r#   _request+   s   
zAsyncFunctionsClient._requesttokenc                 C   s$   t |std d| | jd< dS )zUpdates the authorization header

        Parameters
        ----------
        token : str
            the new jwt token sent in the authorization header
        z5token must be a valid JWT authorization token string.zBearer AuthorizationN)r   r   r   )r!   r7   r"   r"   r#   set_auth=   s   	zAsyncFunctionsClient.set_authfunction_nameinvoke_optionsc           
         s&  t |s	td| j}d}d}|dur]||di  |dd}|d}|rEt|ts;td| d t|}|jd	krE|j|d
< |d}t|t	rTd|d< n	t|t
r]d|d< | jd| j d| ||dI dH }|jd}|r|dkrt| d|dkr| }	|	S |j}	|	S )a  Invokes a function

        Parameters
        ----------
        function_name : the name of the function to invoke
        invoke_options : object with the following properties
            `headers`: object representing the headers to send with the request
            `body`: the body of the request
            `responseType`: how the response should be parsed. The default is `json`
        z(function_name must a valid string value.Nz
text/plainr   responseTyperegionzUse FunctionRegion()anyzx-regionbodyzContent-Typezapplication/jsonr)   /)r   r-   zx-relay-headertruer/   r-   )r   r   r   updater3   
isinstancer   r   valuestrdictr6   r   r   r-   content)
r!   r:   r;   r   r@   response_typer=   r4   is_relay_errordatar"   r"   r#   invokeK   s@   







zAsyncFunctionsClient.invoke)TN)NN)N)__name__
__module____qualname__rF   r   r   r   r   r$   r   r   r	   r6   r9   r   bytesrL   r"   r"   r"   r#   r      sH    


r   N)typingr   r   r   r   r   warningsr   httpxr   r	   errorsr   r   utilsr   r   r   r   r   versionr   r   r"   r"   r"   r#   <module>   s    