o
    6dD                     @   s   d dl mZmZmZm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mZmZmZmZmZmZmZmZ d dlmZmZ ede	de
dedededededededed	ed
iZdd ZdddZdd Zdd Zdd Zdd Z dd Z!dd Z"dd Z#dS )    )absolute_importdivisionprint_functionunicode_literalsN)BooleanBytesFloat32Float64Int32Int64ListString	TimestampUInt32UInt64Voidis_list_typeis_struct_typeis_user_defined_type)	fmt_camel
fmt_pascalbooleanstringnumberArrayr   Zvoidc                 C   s(   t | tjrt| dS tj| ddS )Nu   )indent)
isinstancesix	text_typereprlstripjsondumps)o r&   pC:\Users\jesus\OneDrive\Desktop\erpjis_fastapi\backend\jisbackend\Lib\site-packages\stone/backends/js_helpers.pyfmt_obj,   s   r(    c                 C   s   d|dkr|ndt | f S )z4
    Converts the error type into a JSDoc type.
    z%s.<%s>r)   Error)fmt_type)	data_typeZwrap_error_inr&   r&   r'   fmt_error_type4   s   r-   c                 C   sN   t | rtd| jj| jf S t| jd}t| r%|dt| j	 d 7 }|S )zg
    Returns the JSDoc name for the given data type.
    (Does not attempt to enumerate subtypes.)
    z%s%sZObjectz.<>)
r   r   	namespacename_base_type_tableget	__class__r   r+   r,   )r,   Z
fmted_typer&   r&   r'   fmt_type_name>   s   r4   c                 C   s^   t | r+|  r+g }|  }|D ]\}}|t| q|  r'|t|  t|S t| S )ze
    Returns a JSDoc annotation for a data type.
    May contain a union of enumerated subtypes.
    )r   Zhas_enumerated_subtypesZget_all_subtypes_with_tagsappendr4   Zis_catch_allfmt_jsdoc_union)r,   Zpossible_typesZpossible_subtypes_subtyper&   r&   r'   r+   L   s   r+   c                 C   s&   t | dkrdd|  d S | d S )z:
    Returns a JSDoc union of the given type strings.
       (|)r   )lenjoin)Ztype_stringsr&   r&   r'   r6   ]   s   &r6   c                 C   s"   |dkrt | S t | d| S )Nr9   zV{})r   format)r0   versionr&   r&   r'   fmt_funcd   s   rA   c                 C   s"   |dkrd | ||S d | |S )Nr9   z	{}/{}_v{}z{}/{})r?   )Znamespace_name
route_nameZroute_versionr&   r&   r'   fmt_urlj   s   rC   c                 C   s   t | S )N)r   )r0   r&   r&   r'   fmt_varq   s   rD   c                 C   sL   i }| j D ]}t|j|jd}||v r|| }td|||||< qdS )z
    Check name conflicts among generated route definitions. Raise a runtime exception when a
    conflict is encountered.
    )r@   z.There is a name conflict between {!r} and {!r}N)ZroutesrA   r0   r@   RuntimeErrorr?   )r/   Zroute_by_nameZrouterB   Zother_router&   r&   r'   check_route_name_conflictu   s   


rF   )r)   )$
__future__r   r   r   r   r#   r   Zstone.irr   r   r   r	   r
   r   r   r   r   r   r   r   r   r   r   Zstone.backends.helpersr   r   r1   r(   r-   r4   r+   r6   rA   rC   rD   rF   r&   r&   r&   r'   <module>   s6    D

