o
    6dj                     @   s   d dl mZmZmZmZ d dlmZ d dlm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mZmZ d dl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dZd%ddZd%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_literals)Backend)ApiNamespace)BooleanBytesFloat32Float64Int32Int64ListString	TimestampUInt32UInt64Voidis_aliasis_list_typeis_struct_typeis_map_typeis_user_defined_type	fmt_camelbooleanstringnumberArrayr   ZvoidN c                 C   s   d|dkr|ndt | |f S )z
    Converts the error type into a TypeScript type.
    inside_namespace should be set to the namespace that the reference
    occurs in, or None if this parameter is not relevant.
    z%s<%s>r   Error)fmt_type)	data_typeinside_namespaceZwrap_error_in r$   qC:\Users\jesus\OneDrive\Desktop\erpjis_fastapi\backend\jisbackend\Lib\site-packages\stone/backends/tsd_helpers.pyfmt_error_type,   s   r&   c                 C   s   t | st| r| j|kr| jS d| jj| jf S t| jd}t| r2|dt| j	| d 7 }|S t
| rIt| jd}t| j|}d||f }|S )z
    Produces a TypeScript type name for the given data type.
    inside_namespace should be set to the namespace that the reference
    occurs in, or None if this parameter is not relevant.
    z%s.%sZObject<>r   z{[key: %s]: %s})r   r   	namespacename_base_type_tableget	__class__r   r!   r"   r   key_data_typefmt_type_namevalue_data_type)r"   r#   Z
fmted_typer.   r0   r$   r$   r%   r/   7   s   
r/   c                 C   s   t | |d S )z
    Produces a TypeScript type name for the meta-type that refers to the given
    struct, which belongs to an enumerated subtypes tree. This meta-type contains the
    .tag field that lets developers discriminate between subtypes.
    Z	Reference)r/   )r"   r#   r$   r$   r%   fmt_polymorphic_type_referenceL   s   
r1   c                 C   sd   t | r-|  r-g }|  }|D ]\}}|t|| q|  r)|t| | t|S t| |S )z
    Returns a TypeScript type annotation for a data type.
    May contain a union of enumerated subtypes.
    inside_namespace should be set to the namespace that the type reference
    occurs in, or None if this parameter is not relevant.
    )r   Zhas_enumerated_subtypesZget_all_subtypes_with_tagsappendr1   Zis_catch_all	fmt_unionr/   )r"   r#   Zpossible_typesZpossible_subtypes_subtyper$   r$   r%   r!   X   s   
r!   c                 C   s   t | dkrd| S | d S )z2
    Returns a union type of the given types.
       |r   )lenjoin)Ztype_stringsr$   r$   r%   r3   j   s   r3   c                 C   s"   |dkrt | S t | d| S )Nr6   zV{})r   format)r*   versionr$   r$   r%   fmt_funcp   s   r<   c                 C   s   t | S Nr   )r*   r$   r$   r%   fmt_varv   s   r>   c                 C   s   |dkr|}d|vr| dur| j d | }|S |dkr5d|v r,|dd\}}t|}nd}t||d S |dkrG|d	d\}}d
||f S |dkrM|S |dkrS|S td| )z.
    Processes a documentation reference.
    type.Nroute:r6   z()link z[%s]{@link %s}valfieldzUnknown doc ref tag %r)r*   splitintr<   rsplitRuntimeError)Zcur_namespacetagrE   Zfq_valr;   anchorrC   r$   r$   r%   fmt_tagy   s&   
rM   c                 C   sJ   i }| j D ]}t|j|j}||v r|| }td|||||< qdS )z
    Check name conflicts among generated route definitions. Raise a runtime exception when a
    conflict is encountered.
    z.There is a name conflict between {!r} and {!r}N)Zroutesr<   r*   r;   rJ   r:   )r)   Zroute_by_namerA   Z
route_nameZother_router$   r$   r%   check_route_name_conflict   s   


rN   c                 C   s<   |  }|sd S |D ]}| dj||jd q
|   d S )NzIimport * as {namespace_name} from '{module_name_prefix}{namespace_name}';)module_name_prefixZnamespace_name)Zget_imported_namespacesemitr:   r*   )backendr)   rO   Zimported_namespacesnsr$   r$   r%   *generate_imports_for_referenced_namespaces   s   rS   c                 C   s   | j | j S r=   )
data_typesaliases)r)   r$   r$   r%   get_data_types_for_namespace   s   rV   )Nr   r=   ))
__future__r   r   r   r   Zstone.backendr   Zstone.ir.apir   Zstone.irr   r	   r
   r   r   r   r   r   r   r   r   r   r   r   r   r   r   Zstone.backends.helpersr   r+   r&   r/   r1   r!   r3   r<   r>   rM   rN   rS   rV   r$   r$   r$   r%   <module>   s:    L



