
    x
h                        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	j                   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j1                  d	      Zej5                  d
d       ej5                  dd       ej5                  ddedd       ej5                  ddedd       ej5                  ddedd       ej5                  dedd       ej5                  dedd        ej5                  d!dd"d#$       ej5                  d%ed&d'       ej5                  d(edd)       d*Z G d+ d,e      Zy)-    )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-string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-string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                   6    e Zd ZdZeZdZd Zd Zd Z	d Z
d Zy)	TSDClientBackendz;Generates a TypeScript definition file with routes defined.Tc                    | j                   j                  }| j                   j                  }t        j                  j                  | j                  | j                   j                        }| j                   j                  }| j                  | j                   j                        5  t        j                  j                  |      r(t        |dd      5 }|j                         }d d d        nt        d      t        j                   d|z        }|st        d|z        |j#                         }	|j%                         }
||
dz
     dk(  }t'        |      }||dz
     dk(  }| j                   j(                  r| j                   j*                  }| j                   j,                  }t        j                   d|z  |      }|st        d|z        |j#                         }|j%                         }||dz
     dk(  }t'        |      }||dz
     dk(  }| j/                  |d	| |sdnd
z          | j1                  ||       | j/                  ||dz   |
 |sdnd
z          n| j/                  |d	|	 |sdnd
z          | j3                  |||       | j/                  ||
dz   | |sdnd
z          d d d        y # 1 sw Y   xY w# 1 sw Y   y xY w)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jointarget_folder_pathr   template_stringoutput_to_relative_pathr   isfileopenreadAssertionErrorresearchstartendlenimport_namespacesimport_template_string
types_fileemit_raw_generate_import_generate_routes)selfapir$   r%   template_pathr*   template_filer   r_matchr_startr_endr_ends_with_newlinet_endt_ends_with_newliner6   import_from_filei_matchi_starti_endi_ends_with_newlines                       ^/var/www/html/lionshead-backend/venv/lib/python3.12/site-packages/stone/backends/tsd_client.pygeneratezTSDClientBackend.generaten   s    II77yy--T%<%<dii>P>PQ))33))$))*<*<=ww~~m,-w?=,113H @? %%OPP ii @(KG$AOSU U mmoGKKME"*519"5"=ME"*519"5"=yy**)-)I)I&#'99#7#7 ))L4J$KXV(EH^^` `!--/&.uqy&9T&A#H&.uqy&9T&A#hq1ATTZ\]^%%c+;<huqy7GZ4`bcdhq1ATTZ\]^!!#'8,GMM(519U3CVt\^_`O >=?? >=s%   &.J=J0%GJ=0J:	5J==Kc                     t        d |j                  j                               }dj                  t	        d |            }| j                  d|d|d       y )Nc                 0    t        t        |             dk7  S )Nr   )r4   r   	namespaces    rJ   <lambda>z3TSDClientBackend._generate_import.<locals>.<lambda>   s    c">y"IJaO    z, c                     | j                   S )N)namerN   s    rJ   rP   z3TSDClientBackend._generate_import.<locals>.<lambda>   s    Y^^rQ   z	import { z	 } from 'z';)filter
namespacesvaluesr(   mapemit)r;   r<   	type_filenamespaces_with_typesrU   s        rJ   r9   z!TSDClientBackend._generate_import   sJ     &ONN!!#!% YYs#CEZ[\
		
IFGrQ   c                     | j                  ||dz   z        5  |j                  j                         D ]0  }t        |       |j                  D ]  }| j                  ||        2 	 d d d        y # 1 sw Y   y xY w)Nr   )dent)indentrU   rV   r	   routes_generate_route)r;   r<   r$   r%   rO   routes         rJ   r:   z!TSDClientBackend._generate_routes   sj    [[/<!3CD[E ^^224	))4&--E((!5* . 5 FEEs   AA11A:c                    t        |j                  dz   |j                  z   |j                        }| j                          | j                  d       |j                  rH| j                  | j                  |j                  | j                        d       | j                  d       | j                  dt        |j                  | j                  j                        z  d       |j                  r| j                  d       |j                  j                  t        k7  r| j                  d	       | j                  d
       d }| j                  j                   r1d| j                  j                   dt#        |j$                        d}ndt#        |j$                        z  }d}|j                  j                  t        k7  rdt#        |j                        z  }| j                  d|d|d|       y )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<<z>>;zPromise<%s>;r   zarg: %szpublic (z): )r   rS   versionrX   docemit_wrapped_textprocess_doc_docfr
   error_data_typer#   rd   
deprecatedarg_data_type	__class__r   wrap_response_inr   result_data_type)r;   rO   r`   function_namereturn_typeargs         rJ   r_   z TSDClientBackend._generate_route   s    #!5

!BEMMR				%99""4#3#3EIItzz#JSX"YIIdOb!/0E0E-1YY-D-D"F FNS 	 	U II&'((D0II=>		%99%%04		0J0J//02K )HU5K5K,LMK((D0hu':':;;C		[IJrQ   c                     t        d||      S )z?
        Callback to process documentation references.
        N)r   )r;   tagvals      rJ   rk   zTSDClientBackend._docf   s     tS#&&rQ   N)__name__
__module____qualname____doc___cmdline_parsercmdline_parserpreserve_aliasesrK   r9   r:   r_   rk    rQ   rJ   r   r   g   s-    E$N-a^H*K<'rQ   r   )
__future__r   r   r   r   r&   r0   _MYPYtyping	importlibimport_modulestrr   stone.backendr   stone.backends.tsd_helpersr	   r
   r   r   r   r   stone.irr   ArgumentParserr|   add_argumentint_headerr   r   rQ   rJ   <module>r      s   R R 	 	 "9""3z?3 %   ))/C)D   
M     &  
   	     	2     	
:     	
2	     	
-	     O	     	R	     	.	  i'{ i'rQ   