
    iA                       d Z ddlmZ ddlZddlZddlZddlmZm	Z	m
Z
mZmZmZmZ ej        j        Zddddd"dZd#dZd$dZd%dZ G d dej                  Z G d d ej                  Z G d! dej                  ZdS )&z&
DigitalOcean integration for Inngest
    )annotationsN   )
client_libcomm_libconsterrorsfunction
server_libtypes)public_pathserve_origin
serve_pathclientclient_lib.Inngest	functions#list[function.Function[typing.Any]]r   
str | Noner   r   return9typing.Callable[[dict[str, object], _Context], _Response]c               |     t          j         t          |t          j        j                  d	 fd}|S )
a2  
    Serve Inngest functions in a DigitalOcean Function.

    Args:
    ----
        client: Inngest client.
        functions: List of functions to serve.
        public_path: Path that the Inngest server sends requests to. This is only necessary if the SDK is behind a proxy that rewrites the path.
        serve_origin: Origin for serving Inngest functions. This is typically only useful during Docker-based development.
        serve_path: Path for serving Inngest functions. This is only useful if you don't want serve Inngest at the /api/inngest path.
    )r   	frameworkr   	streamingeventdict[str, object]context_Contextr   	_Responsec           
     x   	 d| vrt          j        d          t                              | d                   }t	          |t
                    rt          j        |          |j        t          j        d          |j        t          j        d          t          j	        
                    |j                  }d|j        z   }t          j	                            |j        |          }t          j        t!          |j                  |j        ||| d|          }|j        dk    r"t'                              |                    S |j        d	k    ru|j        t          j        d
          t+          j        |j                  }t	          |t.                    st          j        d          t1          |                    t4          j        j        j                            }t1          |                    t4          j        j        j                            }	|(t          j        t4          j        j        j                  |	(t          j        t4          j        j        j                  t4          j                             |          }
t	          |
t
                    r|
t'          !                    |                    S |j        dk    rQd|j        z   }t          j	                            |j        |          }t'          "                    |                    S t          d|j                   # t
          $ rk}t          j#        $                    j%        |          }t	          |t           j        t           j        f          rd|_&        t'          |          cY d }~S d }~ww xY w)Nhttpzmissing "http" key in eventz6missing "headers" event.http; have you set "web: raw"?z:missing "queryString" event.http; have you set "web: raw"?z/api/v1/web)r   r   )bodyheadersr   query_paramsraw_requestrequest_urlr   r   GETPOSTz3missing "body" event.http; have you set "web: raw"?zbody must be an objectPUTzunsupported method: i  )'r   BodyInvalidError
_EventHTTPfrom_raw
isinstance	Exceptionr!   queryStringurllibparseparse_qsfunction_nameurljoinapi_hostr   CommRequest_to_body_bytesr    method_to_responseget_syncjsonloadsdict
_get_firstgetr
   QueryParamKeyFUNCTION_IDvalueSTEP_IDQueryParamMissingErrorServerRequest	post_syncput_syncCommResponse
from_errorloggerstatus_code)r   r   r   r"   pathr$   comm_reqr    fn_idstep_idcallecomm_resr   handlerr   r   r   s                R/root/projects/qq-shell/venv/lib/python3.11/site-packages/inngest/digital_ocean.pymainzserve.<locals>.main3   s   o	*U""-.KLLL&&uV}55D$	** 4-d333|#-L   '-P   "<001ABBL !7#88D ,..w/?FFK+#DI..')&"  ()%  H {e###$$X..   {f$$9$ 1M   z$),,!$-- L 12JKKK # $$"0<B  
 % $$Z%=%E%KLL  = 7"0<B   ? 7"08>   "/88>>dI.. J#%%h//   {e## %w'<<$l2273CTJJ#$$X..   @4;@@AAA 	* 	* 	*,77qIIHF+V-JK  + (+$))))))))	*s3   EM F M AM -M 
N9A N4.N94N9)r   r   r   r   r   r   )r   CommHandler	FRAMEWORKr   	StreamingDISABLE)r   r   r   r   r   rS   rQ   s   ` ``` @rR   serverX      su    ( "/)	  Gp* p* p* p* p* p* p* p* p* p*d K    itemslist[types.T] | Nonetypes.T | Nonec                @    | t          |           dk    rd S | d         S )Nr   )len)rZ   s    rR   r<   r<      s%     }E

at8OrY   r    bytesc                4    | dS |                      d          S )NrY   zutf-8)encode)r    s    rR   r5   r5      s    |s;;wrY   rP   comm_lib.CommResponser   c                ,    | j         | j        | j        dS )N)r    r!   
statusCode)r    r!   rI   )rP   s    rR   r7   r7      s$     #*  rY   c                  V    e Zd ZU dZded<   dZded<   dZded<   dZded<   dZded<   dS )	r)   Nr   r    zdict[str, str] | Noner!   r6   rJ   r-   )	__name__
__module____qualname__r    __annotations__r!   r6   rJ   r-    rY   rR   r)   r)      sg         D%)G))))FD"K""""""rY   r)   c                  $    e Zd ZU ded<   ded<   dS )r   strr3   r1   Nrf   rg   rh   ri   rj   rY   rR   r   r      s)         MMM rY   r   c                  .    e Zd ZU ded<   ded<   ded<   dS )r   rl   r    zdict[str, str]r!   intrd   Nrm   rj   rY   rR   r   r      s.         IIIOOOOOrY   )r   r   r   r   r   r   r   r   r   r   r   r   )rZ   r[   r   r\   )r    r   r   r_   )rP   rb   r   r   )__doc__
__future__r   r9   typingurllib.parser.   	_internalr   r   r   r   r	   r
   r   	FrameworkDIGITAL_OCEANrU   rX   r<   r5   r7   	BaseModelr)   Protocolr   	TypedDictr   rj   rY   rR   <module>rz      s    # " " " " "                         .	 ##!M M M M M M`             # # # # # # # #    v             rY   