namespace _sindri.outputs.typescript { /** */ function render_entity_type( domain ) : string { return lib_plankton.string.coin( "type type_{{name}} = {\n{{fields}}\n};\n", { "name": domain.name, "fields": ( domain.data_fields .map( (data_field) => lib_plankton.string.coin( "\t{{name}} : {{type}};{{macro_comment}}", { "name": data_field.name, "type": lib_plankton.string.coin( (data_field.nullable ? "(null | {{core}})" : "{{core}}"), { "core": { "boolean": "boolean", "integer": "number", "float": "number", "string_short": "string", "string_medium": "string", "string_long": "string", }[data_field["type"]], } ), "macro_comment": ( (data_field.description !== null) ? lib_plankton.string.coin( " // {{comment}}", { "comment": data_field.description, } ) : "" ), } ) ) // .map(x => ("\t" + x)) .join("\n") ), } ); } /** */ function render_entity_collection( domain ) : string { return lib_plankton.string.coin( "let collection_{{name}} : {{collection_type}} = {{collection_value}};\n", { "name": domain.name, "collection_type": ( (domain.key_field === null) ? lib_plankton.string.coin( "Array", { "name": domain.name, } ) : lib_plankton.string.coin( "Record", { "name": domain.name, } ) ), "collection_value": ( (domain.key_field === null) ? "[]" : "{}" ), } ); } /** */ function render_entity( domain ) : string { return ( render_entity_type(domain) + render_entity_collection(domain) ); } /** */ function render_functions( domain ) : string { return ( [ // list "function {{name}}_list() : Promise {return sql_query_get(\"SELECT * FROM {{name}};\");}", // read "", // create "", // update "", // delete "", ] .join("\n\n") ); } /** */ function render_api_actions( domain ) : string { return ( [ // list "", // read "", // create "", // update "", // delete "", ] .join("\n\n") ); } /** */ export function render( input_data ) : string { return ( input_data["domains"] .map( (domain) => render_entity(domain) ) .map(x => (x + "\n")) .join("\n") ); } } const output_typescript : type_output = { "render": _sindri.outputs.typescript.render, };