{% for e in outline.enums() %} /** * **{{ e.title() }}** * * {{ e.desc() }} */ export type {{ e.name() }} = {{ e.joined_enum_variant_names_for_ts() }} {%- endfor -%} {% for e in outline.enums() %} /// ## {{ e.title() }} /// /// {{ e.desc }} export const enum {{ e.name() }}EnumType { {%- for m in e.members() %} /// ### {{ m.title() }} /// /// {{ m.desc() }} {{ m.name() }} = "{{ m.name() }}", {%- endfor %} } {%- endfor %} {% for interface in outline.interfaces() %} /** * **{{ interface.title() }}** * * {{ interface.desc() }} */ export type {{ interface.name() }}{{ interface.generics_declaration() }} = {{ ts_extends(interface.extends(), mode.clone()) }}{ {% for field in interface.fields() %} /** * **{{ field.title() }}** * * {{ field.desc() }} */ {{ field.name() }}{%- if field.type().is_optional() -%}?{%- endif -%}: {{ lookup(field.type().unwrap_optional(), false, mode.clone()).unwrap() }} {% endfor %} } {%- if interface.is_output_result() %} export type {{ interface.name() }}GetPayload = S extends true ? {{ interface.name() }} : S extends undefined ? never : S extends {{ interface.model_name() }}Args | {{ interface.model_name() }}FindManyArgs ? 'include' extends U ? SelectSubset<{{ interface.model_name() }}, S> & { [P in ExistKeys]: {%- for field in interface.fields() %} {%- if field.is_relation() %} P extends '{{ field.name()|camelcase }}' ? {{ lookup(field.type().unwrap_optional().unwrap_array().unwrap_optional(), false, mode.clone()).unwrap() }}GetPayload{{ get_payload_suffix(field.type()) }} : {%- endif %} {%- endfor %} never } : SelectSubset<{{ interface.name() }}, S> : {{ interface.name() }} export type Get{{ interface.model_name() }}AggregateType = { [P in keyof T & keyof {{ interface.model_name() }}AggregateResult]: P extends '_count' | 'count' ? T[P] extends true ? number : GetScalarType : GetScalarType } export type Get{{ interface.model_name() }}GroupByPayload = Array< PickEnumerable<{{ interface.model_name() }}GroupByResult, T['by']> & { [P in ((keyof T) & (keyof {{ interface.model_name() }}GroupByResult))]: P extends '_count' ? T[P] extends boolean ? number : GetScalarType : GetScalarType } > {%- endif %} {% endfor %} {% for ns in namespace.namespaces().values() %} {{ render_namespace(ns, conf, main_namespace, mode.clone()) }} {% endfor %} {% if conf.is_client() %} {% for delegate in outline.delegates() %} export interface {{ delegate.name_with_conf(conf.class_name().to_string()) }} { {% for request_item in delegate.request_items() %} {{ request_item.name() }}<{% if request_item.is_group_by() %}{{ group_by_generics(lookup(request_item.input_type().unwrap_optional(), false, mode.clone()).unwrap()) }}{% else %}T extends {{ lookup(request_item.input_type().unwrap_optional(), false, mode.clone()).unwrap() }}{% endif %}>({%- if request_item.has_custom_url_args() -%}pathArgs: {[key: string]: string}, {%- endif -%}{%- if request_item.has_body_input() -%}body: {% if request_item.is_form() -%}FormData{% else %}{% if request_item.is_count() %}Subset{% else if request_item.is_aggregate() %}Subset{% else if request_item.is_group_by() %}SubsetIntersection & InputErrors{% else %}T{% endif %}{% endif -%}, {%- endif -%}headers?: {[key: string]: string} | undefined, queryString?: string | undefined): Promise<{% if request_item.is_count() %}std.Data ? T['select'] extends true ? number : GetScalarType : number>{%else%}{{ lookup(request_item.output_type().unwrap_optional(), true, mode.clone()).unwrap() }}{%endif%}> {% endfor %} {% for namespace_item in delegate.namespace_items() %} {{ namespace_item.property_name() }}: {{ namespace_item.path().join(".") }} {% endfor %} {% for group_item in delegate.group_items() %} {{ group_item.property_name() }}: {{ group_item.path().join(".") }} {% endfor %} /** * Get a new client altered with `headers`. * @param {headers?} headers - The new headers. */ $headers(headers?: {[key: string]: string} | undefined): {{ conf.class_name().to_string() }} } {% endfor %} {% if namespace.path().is_empty() %} /** * ## {{ conf.class_name().to_string() }} API Client * * {{ conf.class_name().to_string() }} API client for TypeScript & javaScript. It supports both browser and * node.js. It's generated by the fantastic Teo framework. * */ export const {{ conf.object_name().to_string() }}: {{ conf.class_name().to_string() }} {% endif %} {%- endif %} {% if conf.is_entity() %} {% for model in namespace.models().values() %} {%- if model.generate_entity() %} export class {{ model.name() }}Model { findManyObjects(query: {{ model.name() }}FindManyArgs): Promise<{{ model.name() }}[]> findUniqueObject(query: {{ model.name() }}FindUniqueArgs): Promise<{{ model.name() }} | null> findFirstObject(query: {{ model.name() }}FindManyArgs): Promise<{{ model.name() }} | null> createObject(input?: {{ model.name() }}CreateInput): Promise<{{ model.name() }}> count(input?: {{ model.name() }}CountArgs): Promise aggregate(input?: Subset): Promise> groupBy>, Extends<'take', Keys> >, OrderByArg extends True extends HasSelectOrTake ? { orderBy: {{ model.name() }}GroupByArgs['orderBy'] } : { orderBy?: {{ model.name() }}GroupByArgs['orderBy'] }, OrderFields extends ExcludeUnderscoreKeys>>, ByFields extends MaybeTupleToUnion, ByValid extends Has, HavingFields extends GetHavingFields, HavingValid extends Has, ByEmpty extends T['by'] extends never[] ? True : False, InputErrors extends ByEmpty extends True ? `Error: "by" must not be empty.` : HavingValid extends False ? { [P in HavingFields]: P extends ByFields ? never : P extends string ? `Error: Field "${P}" used in "having" needs to be provided in "by".` : [ Error, 'Field ', P, ` in "having" needs to be provided in "by"`, ] }[HavingFields] : 'take' extends Keys ? 'orderBy' extends Keys ? ByValid extends True ? {} : { [P in OrderFields]: P extends ByFields ? never : `Error: Field "${P}" in "orderBy" needs to be provided in "by"` }[OrderFields] : 'Error: If you provide "take", you also need to provide "orderBy"' : 'skip' extends Keys ? 'orderBy' extends Keys ? ByValid extends True ? {} : { [P in OrderFields]: P extends ByFields ? never : `Error: Field "${P}" in "orderBy" needs to be provided in "by"` }[OrderFields] : 'Error: If you provide "skip", you also need to provide "orderBy"' : ByValid extends True ? {} : { [P in OrderFields]: P extends ByFields ? never : `Error: Field "${P}" in "orderBy" needs to be provided in "by"` }[OrderFields]>(input: SubsetIntersection & InputErrors): Promise<{} extends InputErrors ? Get{{ model.name() }}GroupByPayload : InputErrors> {% if namespace.database().is_some() && namespace.database().unwrap().is_sql() %} sql(sql: string): Promise {% endif %} } export class {{ model.name() }} { get isNew(): boolean get isModified(): boolean set(input: {{ model.name() }}UpdateInput): Promise update(input: {{ model.name() }}ScalarUpdateInput): Promise save(): Promise delete(): Promise toTeon(): Promise<{{ model.name() }}Result> {%- for field in model.fields().values() %} /// ## {{ field.title() }} /// /// {{ field.desc() }} get {{ field.name() }}(): {{ optional_strategy(lookup(field.type(), false, mode.clone())?) }} /// ## {{ field.title() }} /// /// {{ field.desc() }} set {{ field.name() }}(newValue: {{ optional_strategy(lookup(field.type(), false, mode.clone())?) }}) {%- endfor %} {%- for field in model.relations().values() %} {%- if field.type().is_array() %} get {{ field.name() }}(): Promise<{{ optional_strategy(lookup(field.type(), false, mode.clone())?) }}> set{{ field.name()|pascalcase}}(newValue: {{ optional_strategy(lookup(field.type(), false, mode.clone())?) }}): Promise addTo{{ field.name()|pascalcase}}(newValue: {{ optional_strategy(lookup(field.type(), false, mode.clone())?) }}): Promise removeFrom{{ field.name()|pascalcase}}(newValue: {{ optional_strategy(lookup(field.type(), false, mode.clone())?) }}): Promise {%- else %} get {{ field.name() }}(): Promise<{{ optional_strategy(lookup(field.type(), false, mode.clone())?) }}> set{{ field.name()|pascalcase}}(newValue: {{ optional_strategy(lookup(field.type(), false, mode.clone())?) }}): Promise {%- endif %} {%- endfor %} {%- for field in model.properties().values() %} {%- if field.getter().is_some() %} get {{ field.name() }}(): Promise<{{ optional_strategy(lookup(field.type(), false, mode.clone())?) }}> {%- endif %} {%- if field.setter().is_some() %} set{{ field.name()|pascalcase }}(newValue: {{ optional_strategy(lookup(field.type(), false, mode.clone())?) }}): Promise {%- endif %} {%- endfor %} } {% endif %} {% endfor %} {% for path_arguments in outline.path_arguments() %} type {{ path_arguments.name() }} = { {% for item in path_arguments.items() %} {{ item }}: string {% endfor %} } {% endfor %} {%- if !namespace.is_std() %} declare class {% if namespace.is_main() %}Teo{% else %}{{ namespace.name()|capitalize }}Namespace{% endif %} { {% if namespace.is_main() %} transaction(callback: (teo: Teo) => Promise): Promise {% endif %} {%- for model in namespace.models().values() %} get {{ model.name()|camelcase }}(): {{ model.name() }}Model {%- endfor %} {%- for child in namespace.namespaces().values() %} {%- if !child.is_std() %} get {{ child.name() }}(): {{ child.name()|pascalcase }}Namespace {%- endif %} {%- endfor %} } {%- endif %} {% endif %}