o
    6d                     @   s\  d dl mZmZmZmZ d dlZd dlZdZerd dlZd dl	Z	e	
edZd dlmZ d dlmZmZmZmZmZmZ d dlmZ ejdd	Zejd
dd ejddd ejddeddd ejddeddd ejddeddd ejdeddd ejdedd d ejd!dd"d#d$ ejd%ed&d'd ejd(edd)d d*ZG d+d, d,eZdS )-    )absolute_importdivisionprint_functionunicode_literalsNFargparse)CodeBackend)check_route_name_conflictfmt_error_typefmt_funcfmt_tagfmt_typeget_data_types_for_namespace)Voidztsd-client-backend)progtemplatezAA template to use when generating the TypeScript definition file.)helpfilenamez[The name to give the single TypeScript definition file to contain all of the emitted types.z-tz--template-stringZROUTESzThe name of the template string to replace with route definitions. Defaults to ROUTES, which replaces the string /*ROUTES*/ with route definitions.)typedefaultr   z-iz--indent-level   zbIndentation level to emit types at. Routes are automatically indented one level further than this.z-sz--spaces-per-indent   z.Number of spaces to use per indentation level.z--wrap-response-in z&Wraps the response in a response classz--wrap-error-inz!Wraps the error in an error classz--import-namespaces
store_truezAdds an import statement at the top of the file to import each namespace from the as a named import. Must be used in conjunction with the --export-namespaces command when generating the ts_types.)r   actionr   z--import-template-stringZIMPORTzThe name of the template string to replace with import statement. Defaults to IMPORT, which replaces the string /*IMPORT*/ with import.z--types-filezgIf using the --import-namespaces flag, this is the file that contains the named exports to import here.z+// Auto-generated by Stone, do not modify.
c                   @   s@   e Zd ZdZeZdZdd Zdd Zdd Z	d	d
 Z
dd ZdS )TSDClientBackendz;Generates a TypeScript definition file with routes defined.Tc              	   C   s  | j j}| j j}tj| j| j j}| j j}| 	| j j
 tj|r@t|ddd}| }W d    n1 s:w   Y  ntdtd| |}|sTtd| | }	| }
||
d  dk}t|}||d  dk}| j jr| j j}| j j}td| |}|std| | }| }||d  dk}t|}||d  dk}| |d	| |sdnd
  | || | ||d |
 |sdnd
  n| |d	|	 |sdnd
  | ||| | ||
d | |sdnd
  W d    d S 1 sw   Y  d S )Nrzutf-8)encodingz(TypeScript template file does not exist.z/\*%s\*/z+Missing /*%s*/ in TypeScript template file.r   
r   r   )argsspaces_per_indentindent_levelospathjoinZtarget_folder_pathr   template_stringZoutput_to_relative_pathr   isfileopenreadAssertionErrorresearchstartendlenZimport_namespacesimport_template_stringZ
types_fileZemit_raw_generate_import_generate_routes)selfapir   r    Ztemplate_pathr$   Ztemplate_filer   Zr_matchZr_startZr_endZr_ends_with_newlineZt_endZt_ends_with_newliner.   Zimport_from_fileZi_matchZi_startZi_endZi_ends_with_newline r3   pC:\Users\jesus\OneDrive\Desktop\erpjis_fastapi\backend\jisbackend\Lib\site-packages\stone/backends/tsd_client.pygeneraten   sR   
$$$zTSDClientBackend.generatec                 C   s>   t dd |j }dtdd |}| d||f  d S )Nc                 S   s   t t| dkS )Nr   )r-   r   	namespacer3   r3   r4   <lambda>   s    z3TSDClientBackend._generate_import.<locals>.<lambda>z, c                 S   s   | j S )N)namer6   r3   r3   r4   r8      s    zimport { %s } from '%s';)filter
namespacesvaluesr#   mapemit)r1   r2   Z	type_fileZnamespaces_with_typesr;   r3   r3   r4   r/      s   z!TSDClientBackend._generate_importc                 C   sj   | j ||d  d! |j D ]}t| |jD ]}| || qqW d    d S 1 s.w   Y  d S )Nr   )Zdent)indentr;   r<   r   Zroutes_generate_route)r1   r2   r   r    r7   router3   r3   r4   r0      s   
"z!TSDClientBackend._generate_routesc                 C   s  t |jd |j |j}|   | d |jr*| j| |j| jdd | d | jdt|j	| j
jd dd |jrB| d |jjtkrM| d	 | d
 d }| j
jrdd| j
jt|jf }ndt|j }d}|jjtkrzdt|j }| d|||f  d S )N_z/**z * )prefixz *zAWhen an error occurs, the route rejects the promise with type %s.)wrap_error_inz * @deprecatedz% * @param arg The request parameters.z */zPromise<%s<%s>>;zPromise<%s>;r   zarg: %szpublic %s(%s): %s)r
   r9   versionr>   docZemit_wrapped_textZprocess_doc_docfr	   Zerror_data_typer   rD   
deprecatedZarg_data_type	__class__r   Zwrap_response_inr   Zresult_data_type)r1   r7   rA   Zfunction_namereturn_typeargr3   r3   r4   r@      s8   




z TSDClientBackend._generate_routec                 C   s   t d||S )z?
        Callback to process documentation references.
        N)r   )r1   tagvalr3   r3   r4   rG      s   zTSDClientBackend._docfN)__name__
__module____qualname____doc___cmdline_parserZcmdline_parserZpreserve_aliasesr5   r/   r0   r@   rG   r3   r3   r3   r4   r   g   s    /	r   )
__future__r   r   r   r   r!   r)   Z_MYPYtyping	importlibimport_modulestrr   Zstone.backendr   Zstone.backends.tsd_helpersr   r	   r
   r   r   r   Zstone.irr   ArgumentParserrR   add_argumentintZ_headerr   r3   r3   r3   r4   <module>   s     	