From c4c3e81067a41071e5db37909007308ed83045d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20Fra=C3=9F?= Date: Mon, 24 Jul 2023 13:09:39 +0200 Subject: [PATCH] [mod] output:backend-typescript --- source/outputs/backend_typescript.ts | 1851 ++++++++++++++++++-------- tools/makefile | 4 +- 2 files changed, 1312 insertions(+), 543 deletions(-) diff --git a/source/outputs/backend_typescript.ts b/source/outputs/backend_typescript.ts index 9cf3ebd..2ecb751 100644 --- a/source/outputs/backend_typescript.ts +++ b/source/outputs/backend_typescript.ts @@ -22,6 +22,12 @@ namespace _sindri.outputs.backend.typescript const name_table = function (domain) : string {return (domain.name);}; const name_type = function (domain) : string {return ("type_" + domain.name);}; const name_collection = function (domain) : string {return ("collection_" + domain.name);}; + const database_path = lib_plankton.string.coin( + "/tmp/{{name}}.sqlite", + { + "name": "sindri", + } + ); const name_repository_function_list = function (domain) : string { return lib_plankton.string.coin( "repository_{{name}}_list", @@ -62,578 +68,1341 @@ namespace _sindri.outputs.backend.typescript } ); }; - return prog_output.render_program( - new lib_plankton.prog.struct_program( - [] - // base - .concat( - [ - ] - ) - // lib (database) - .concat( - [ - new lib_plankton.prog.struct_statement_function_definition( - "sql_query_get", - [ - { - "name": "template", - "type": new lib_plankton.prog.struct_type_string(), - }, - { - "name": "arguments", - "type": new lib_plankton.prog.struct_type_map( - new lib_plankton.prog.struct_type_string(), - new lib_plankton.prog.struct_type_any() - ), - } - ], - new lib_plankton.prog.struct_type_construction( - "Promise", - [ - new lib_plankton.prog.struct_type_construction( - "Array", - [ - new lib_plankton.prog.struct_type_construction( - "Record", - [ - new lib_plankton.prog.struct_type_string(), - new lib_plankton.prog.struct_type_any(), - ] - ) - ] - ), - ] + return ( + // base + "declare var require;\n" + + + prog_output.render_program( + new lib_plankton.prog.struct_program( + [] + // conf + .concat( + [ + new lib_plankton.prog.struct_statement_declaration( + true, + "conf", + null, + new lib_plankton.prog.struct_expression_dict( + [ + { + "key": "database_path", + "value": new lib_plankton.prog.struct_expression_literal(database_path), + }, + { + "key": "server_port", + "value": new lib_plankton.prog.struct_expression_literal(8888), + }, + ] + ) ), - [ - // TODO - new lib_plankton.prog.struct_statement_return( - new lib_plankton.prog.struct_expression_literal(null) - ), - ] - ), - new lib_plankton.prog.struct_statement_function_definition( - "sql_query_put", - [ - { - "name": "template", - "type": new lib_plankton.prog.struct_type_string(), - }, - { - "name": "arguments", - "type": new lib_plankton.prog.struct_type_map( - new lib_plankton.prog.struct_type_string(), - new lib_plankton.prog.struct_type_any() - ), - } - ], - new lib_plankton.prog.struct_type_construction( - "Promise", - [ - new lib_plankton.prog.struct_type_integer(), - ] - ), - [ - // TODO - new lib_plankton.prog.struct_statement_return( - new lib_plankton.prog.struct_expression_literal(null) - ), - ] - ), - new lib_plankton.prog.struct_statement_function_definition( - "sql_query_set", - [ - { - "name": "template", - "type": new lib_plankton.prog.struct_type_string(), - }, - { - "name": "arguments", - "type": new lib_plankton.prog.struct_type_map( - new lib_plankton.prog.struct_type_string(), - new lib_plankton.prog.struct_type_any() - ), - } - ], - new lib_plankton.prog.struct_type_construction( - "Promise", - [ - new lib_plankton.prog.struct_type_void(), - ] - ), - [ - // TODO - new lib_plankton.prog.struct_statement_return( - new lib_plankton.prog.struct_expression_literal(null) - ), - ] - ), - ] - ) - // entities - .concat( - input_data["domains"] - .map( - (domain) => new lib_plankton.prog.struct_statement_type_definition( - name_type(domain), - new lib_plankton.prog.struct_type_record( - domain.data_fields - .map( - (data_field) => ({ - "name": data_field.name, - "type": ( - data_field.nullable - ? new lib_plankton.prog.struct_type_union( - new lib_plankton.prog.struct_type_literal( - new lib_plankton.prog.struct_expression_literal( - null - ) - ), - map_primitive_type(data_field["type"]) - ) - : map_primitive_type(data_field["type"]) - ), - "mandatory": true, - }) + ] + ) + // entities + .concat( + input_data["domains"] + .map( + (domain) => new lib_plankton.prog.struct_statement_type_definition( + name_type(domain), + new lib_plankton.prog.struct_type_record( + domain.data_fields + .map( + (data_field) => ({ + "name": data_field.name, + "type": ( + data_field.nullable + ? new lib_plankton.prog.struct_type_union( + new lib_plankton.prog.struct_type_literal( + new lib_plankton.prog.struct_expression_literal( + null + ) + ), + map_primitive_type(data_field["type"]) + ) + : map_primitive_type(data_field["type"]) + ), + "mandatory": true, + }) + ) ) ) ) ) - ) - // repositories - .concat( - input_data["domains"] - .map( - (domain) => ( - (domain.key_field === null) - ? [ - // TODO - ] - : [ - // list - new lib_plankton.prog.struct_statement_function_definition( - name_repository_function_list(domain), - [], - new lib_plankton.prog.struct_type_construction( - "Promise", - [ - new lib_plankton.prog.struct_type_construction( - "Array", - [ - new lib_plankton.prog.struct_type_record( - [ - { - "name": "key", - "type": new lib_plankton.prog.struct_type_integer(), - "mandatory": true, - }, - { - "name": "value", - "type": new lib_plankton.prog.struct_type_construction( - name_type(domain), - null - ), - "mandatory": true, - }, - ] - ), - ] - ) - ] - ), - [ - new lib_plankton.prog.struct_statement_return( - // TODO - new lib_plankton.prog.struct_expression_function_application( - new lib_plankton.prog.struct_expression_fieldaccess( - new lib_plankton.prog.struct_expression_function_application( - new lib_plankton.prog.struct_expression_variable("sql_query_get"), - [ - new lib_plankton.prog.struct_expression_literal( - lib_plankton.string.coin( - "SELECT {{fields}} FROM {{name}};", - { - "fields": ( - [domain.key_field.name] - .concat(domain.data_fields.map(field => field.name)) - .join(",") - ), - "name": name_table(domain), - } - ) - ), - new lib_plankton.prog.struct_expression_dict( - [ - ] - ), - ] - ), - "then" - ), - [ - new lib_plankton.prog.struct_expression_abstraction( - [ - { - "name": "rows", - "type": null, - }, - ], - null, - [ - new lib_plankton.prog.struct_statement_return( - new lib_plankton.prog.struct_expression_function_application( - new lib_plankton.prog.struct_expression_fieldaccess( - new lib_plankton.prog.struct_expression_variable( - "rows" - ), - "map" - ), - [ - new lib_plankton.prog.struct_expression_abstraction( - [ - { - "name": "row", - "type": null, - }, - ], - null, - [ - new lib_plankton.prog.struct_statement_return( - new lib_plankton.prog.struct_expression_dict( - [ - { - "key": "key", - "value": new lib_plankton.prog.struct_expression_projection( - new lib_plankton.prog.struct_expression_variable("row"), - new lib_plankton.prog.struct_expression_literal(domain.key_field.name) - ), - }, - { - "key": "value", - "value": new lib_plankton.prog.struct_expression_dict( - domain.data_fields - .map( - field => ({ - "key": field.name, - "value": new lib_plankton.prog.struct_expression_projection( - new lib_plankton.prog.struct_expression_variable("row"), - new lib_plankton.prog.struct_expression_literal(field.name) - ) - }) - ) - ), - }, - ] - ) - ), - ] - ), - ] - ) - ), - ] - ), - ] - ), - ), - ] - ), - // read - new lib_plankton.prog.struct_statement_function_definition( - name_repository_function_read(domain), - [ - { - "name": "key", - "type": new lib_plankton.prog.struct_type_integer( - ), - }, - ], - new lib_plankton.prog.struct_type_construction( - "Promise", - [ - new lib_plankton.prog.struct_type_construction( - name_type(domain), - null - ), - ] - ), - [ - new lib_plankton.prog.struct_statement_return( - // TODO - new lib_plankton.prog.struct_expression_function_application( - new lib_plankton.prog.struct_expression_fieldaccess( - new lib_plankton.prog.struct_expression_function_application( - new lib_plankton.prog.struct_expression_variable("sql_query_get"), - [ - new lib_plankton.prog.struct_expression_literal( - lib_plankton.string.coin( - "SELECT {{fields}} FROM {{name}} WHERE ({{key}} = :key);", - { - "fields": ( - [] - .concat(domain.data_fields.map(field => field.name)) - .join(",") - ), - "name": name_table(domain), - "key": domain.key_field.name, - } - ) - ), - new lib_plankton.prog.struct_expression_dict( - [ - { - "key": "key", - "value": new lib_plankton.prog.struct_expression_variable("key"), - }, - ] - ), - ] - ), - "then" - ), - [ - new lib_plankton.prog.struct_expression_abstraction( - [ - { - "name": "rows", - "type": null, - }, - ], - null, - [ - new lib_plankton.prog.struct_statement_declaration( - true, - "row", - null, - new lib_plankton.prog.struct_expression_projection( - new lib_plankton.prog.struct_expression_variable("rows"), - new lib_plankton.prog.struct_expression_literal(0), - ) - ), - new lib_plankton.prog.struct_statement_return( - new lib_plankton.prog.struct_expression_dict( - domain.data_fields - .map( - field => ({ - "key": field.name, - "value": new lib_plankton.prog.struct_expression_projection( - new lib_plankton.prog.struct_expression_variable("row"), - new lib_plankton.prog.struct_expression_literal(field.name) - ) - }) - ) - ) - ), - ] - ), - ] - ) - ), - ] - ), - // create - new lib_plankton.prog.struct_statement_function_definition( - name_repository_function_create(domain), - [ - { - "name": "value", - "type": new lib_plankton.prog.struct_type_construction( - name_type(domain), - null - ), - }, - ], - new lib_plankton.prog.struct_type_construction( - "Promise", - [ - new lib_plankton.prog.struct_type_integer( - ), - ] - ), - [ - new lib_plankton.prog.struct_statement_return( - // TODO - new lib_plankton.prog.struct_expression_function_application( - new lib_plankton.prog.struct_expression_variable("sql_query_put"), - [ - new lib_plankton.prog.struct_expression_literal( - lib_plankton.string.coin( - "INSERT INTO {{name}}({{fields}}) VALUES ({{values}});", - { - "name": name_table(domain), - "fields": ( - domain.data_fields - .map(field => field.name) - .join(",") - ), - "values": ( - domain.data_fields - .map(field => (":" + field.name)) - .join(",") - ), - } - ) - ), - new lib_plankton.prog.struct_expression_dict( - domain.data_fields - .map( - field => ({ - "key": field.name, - "value": new lib_plankton.prog.struct_expression_fieldaccess( - new lib_plankton.prog.struct_expression_variable("value"), - field.name, - ), - }) - ) - ), - ] - ) - ), - ] - ), - // update - new lib_plankton.prog.struct_statement_function_definition( - name_repository_function_update(domain), - [ - { - "name": "key", - "type": new lib_plankton.prog.struct_type_integer( - ), - }, - { - "name": "value", - "type": new lib_plankton.prog.struct_type_construction( - name_type(domain), - null - ), - }, - ], - new lib_plankton.prog.struct_type_construction( - "Promise", - [ - new lib_plankton.prog.struct_type_void( - ), - ] - ), - [ - new lib_plankton.prog.struct_statement_return( - // TODO - new lib_plankton.prog.struct_expression_function_application( - new lib_plankton.prog.struct_expression_variable("sql_query_set"), - [ - new lib_plankton.prog.struct_expression_literal( - lib_plankton.string.coin( - "UPDATE {{name}} SET {{settings}} WHERE ({{key}} = :key);", - { - "name": name_table(domain), - "key": domain.key_field.name, - "settings": ( - domain.data_fields - .map( - field => lib_plankton.string.coin( - "{{key}} = {{value}}", - { - "key": field.name, - "value": (":" + field.name), - } - ) - ) - .join(", ") - ), - } - ) - ), - new lib_plankton.prog.struct_expression_dict( - [] - .concat( + // repositories + .concat( + input_data["domains"] + .map( + (domain) => ( + (domain.key_field === null) + ? [ + // TODO + ] + : [ + // list + new lib_plankton.prog.struct_statement_function_definition( + name_repository_function_list(domain), + [], + new lib_plankton.prog.struct_type_construction( + "Promise", + [ + new lib_plankton.prog.struct_type_construction( + "Array", + [ + new lib_plankton.prog.struct_type_record( [ { - "key": "key", - "value": new lib_plankton.prog.struct_expression_variable("key"), + "name": "key", + "type": new lib_plankton.prog.struct_type_integer(), + "mandatory": true, + }, + { + "name": "value", + "type": new lib_plankton.prog.struct_type_construction( + name_type(domain), + null + ), + "mandatory": true, }, ] - ) - .concat( - domain.data_fields - .map( - field => ({ - "key": field.name, - "value": new lib_plankton.prog.struct_expression_fieldaccess( - new lib_plankton.prog.struct_expression_variable("value"), - field.name, - ), - }) - ) - ) + ), + ] + ) + ] + ), + [ + new lib_plankton.prog.struct_statement_return( + // TODO + new lib_plankton.prog.struct_expression_function_application( + new lib_plankton.prog.struct_expression_fieldaccess( + new lib_plankton.prog.struct_expression_function_application( + new lib_plankton.prog.struct_expression_variable("lib_plankton.sqlite.query_get"), + [ + new lib_plankton.prog.struct_expression_fieldaccess(new lib_plankton.prog.struct_expression_variable("conf"), "database_path"), + new lib_plankton.prog.struct_expression_dict( + [ + { + "key": "template", + "value": new lib_plankton.prog.struct_expression_literal( + lib_plankton.string.coin( + "SELECT {{fields}} FROM {{name}};", + { + "fields": ( + [domain.key_field.name] + .concat(domain.data_fields.map(field => field.name)) + .join(",") + ), + "name": name_table(domain), + } + ) + ), + }, + { + "key": "arguments", + "value": new lib_plankton.prog.struct_expression_dict( + [ + ] + ), + }, + ] + ), + ] + ), + "then" ), + [ + new lib_plankton.prog.struct_expression_abstraction( + [ + { + "name": "rows", + "type": null, + }, + ], + null, + [ + new lib_plankton.prog.struct_statement_return( + new lib_plankton.prog.struct_expression_function_application( + new lib_plankton.prog.struct_expression_fieldaccess( + new lib_plankton.prog.struct_expression_variable( + "rows" + ), + "map" + ), + [ + new lib_plankton.prog.struct_expression_abstraction( + [ + { + "name": "row", + "type": null, + }, + ], + null, + [ + new lib_plankton.prog.struct_statement_return( + new lib_plankton.prog.struct_expression_dict( + [ + { + "key": "key", + "value": new lib_plankton.prog.struct_expression_projection( + new lib_plankton.prog.struct_expression_variable("row"), + new lib_plankton.prog.struct_expression_literal(0) + ), + }, + { + "key": "value", + "value": new lib_plankton.prog.struct_expression_dict( + domain.data_fields + .map( + (field, index) => ({ + "key": field.name, + "value": new lib_plankton.prog.struct_expression_projection( + new lib_plankton.prog.struct_expression_variable("row"), + new lib_plankton.prog.struct_expression_literal(index + 1) + ) + }) + ) + ), + }, + ] + ) + ), + ] + ), + ] + ) + ), + ] + ), + ] + ), + ), + ] + ), + // read + new lib_plankton.prog.struct_statement_function_definition( + name_repository_function_read(domain), + [ + { + "name": "key", + "type": new lib_plankton.prog.struct_type_integer( + ), + }, + ], + new lib_plankton.prog.struct_type_construction( + "Promise", + [ + new lib_plankton.prog.struct_type_construction( + name_type(domain), + null + ), + ] + ), + [ + new lib_plankton.prog.struct_statement_return( + // TODO + new lib_plankton.prog.struct_expression_function_application( + new lib_plankton.prog.struct_expression_fieldaccess( + new lib_plankton.prog.struct_expression_function_application( + new lib_plankton.prog.struct_expression_variable("lib_plankton.sqlite.query_get"), + [ + new lib_plankton.prog.struct_expression_fieldaccess(new lib_plankton.prog.struct_expression_variable("conf"), "database_path"), + new lib_plankton.prog.struct_expression_dict( + [ + { + "key": "template", + "value": new lib_plankton.prog.struct_expression_literal( + lib_plankton.string.coin( + "SELECT {{fields}} FROM {{name}} WHERE ({{key}} = :key);", + { + "fields": ( + [] + .concat(domain.data_fields.map(field => field.name)) + .join(",") + ), + "name": name_table(domain), + "key": domain.key_field.name, + } + ) + ), + }, + { + "key": "arguments", + "value": new lib_plankton.prog.struct_expression_dict( + [ + { + "key": "key", + "value": new lib_plankton.prog.struct_expression_variable("key"), + }, + ] + ), + }, + ] + ), + ] + ), + "then" + ), + [ + new lib_plankton.prog.struct_expression_abstraction( + [ + { + "name": "rows", + "type": null, + }, + ], + null, + [ + new lib_plankton.prog.struct_statement_declaration( + true, + "row", + null, + new lib_plankton.prog.struct_expression_projection( + new lib_plankton.prog.struct_expression_variable("rows"), + new lib_plankton.prog.struct_expression_literal(0), + ) + ), + new lib_plankton.prog.struct_statement_return( + new lib_plankton.prog.struct_expression_dict( + domain.data_fields + .map( + (field, index) => ({ + "key": field.name, + "value": new lib_plankton.prog.struct_expression_projection( + new lib_plankton.prog.struct_expression_variable("row"), + new lib_plankton.prog.struct_expression_literal(index) + ) + }) + ) + ) + ), + ] + ), + ] + ) + ), + ] + ), + // create + new lib_plankton.prog.struct_statement_function_definition( + name_repository_function_create(domain), + [ + { + "name": "value", + "type": new lib_plankton.prog.struct_type_construction( + name_type(domain), + null + ), + }, + ], + new lib_plankton.prog.struct_type_construction( + "Promise", + [ + new lib_plankton.prog.struct_type_integer( + ), + ] + ), + [ + new lib_plankton.prog.struct_statement_return( + new lib_plankton.prog.struct_expression_function_application( + new lib_plankton.prog.struct_expression_fieldaccess( + new lib_plankton.prog.struct_expression_function_application( + new lib_plankton.prog.struct_expression_variable("lib_plankton.sqlite.query_put"), + [ + new lib_plankton.prog.struct_expression_fieldaccess(new lib_plankton.prog.struct_expression_variable("conf"), "database_path"), + new lib_plankton.prog.struct_expression_dict( + [ + { + "key": "template", + "value": new lib_plankton.prog.struct_expression_literal( + lib_plankton.string.coin( + "INSERT INTO {{name}}({{fields}}) VALUES ({{values}});", + { + "name": name_table(domain), + "fields": ( + domain.data_fields + .map(field => field.name) + .join(",") + ), + "values": ( + domain.data_fields + .map(field => (":" + field.name)) + .join(",") + ), + } + ) + ), + }, + { + "key": "arguments", + "value": new lib_plankton.prog.struct_expression_dict( + domain.data_fields + .map( + field => ({ + "key": field.name, + "value": new lib_plankton.prog.struct_expression_fieldaccess( + new lib_plankton.prog.struct_expression_variable("value"), + field.name, + ), + }) + ) + ), + }, + ] + ), + ] + ), + "then" + ), + [ + new lib_plankton.prog.struct_expression_abstraction( + [ + { + "name": "result", + "type": null, + } + ], + null, + [ + new lib_plankton.prog.struct_statement_return( + new lib_plankton.prog.struct_expression_fieldaccess( + new lib_plankton.prog.struct_expression_variable("result"), + "id" + ) + ), + ] + ), + ] + ) + ), + ] + ), + // update + new lib_plankton.prog.struct_statement_function_definition( + name_repository_function_update(domain), + [ + { + "name": "key", + "type": new lib_plankton.prog.struct_type_integer( + ), + }, + { + "name": "value", + "type": new lib_plankton.prog.struct_type_construction( + name_type(domain), + null + ), + }, + ], + new lib_plankton.prog.struct_type_construction( + "Promise", + [ + new lib_plankton.prog.struct_type_void( + ), + ] + ), + [ + new lib_plankton.prog.struct_statement_return( + new lib_plankton.prog.struct_expression_function_application( + new lib_plankton.prog.struct_expression_fieldaccess( + new lib_plankton.prog.struct_expression_function_application( + new lib_plankton.prog.struct_expression_variable("lib_plankton.sqlite.query_put"), + [ + new lib_plankton.prog.struct_expression_fieldaccess(new lib_plankton.prog.struct_expression_variable("conf"), "database_path"), + new lib_plankton.prog.struct_expression_dict( + [ + { + "key": "template", + "value": new lib_plankton.prog.struct_expression_literal( + lib_plankton.string.coin( + "UPDATE {{name}} SET {{settings}} WHERE ({{key}} = :key);", + { + "name": name_table(domain), + "key": domain.key_field.name, + "settings": ( + domain.data_fields + .map( + field => lib_plankton.string.coin( + "{{key}} = {{value}}", + { + "key": field.name, + "value": (":" + field.name), + } + ) + ) + .join(", ") + ), + } + ) + ), + }, + { + "key": "arguments", + "value": new lib_plankton.prog.struct_expression_dict( + [] + .concat( + [ + { + "key": "key", + "value": new lib_plankton.prog.struct_expression_variable("key"), + }, + ] + ) + .concat( + domain.data_fields + .map( + field => ({ + "key": field.name, + "value": new lib_plankton.prog.struct_expression_fieldaccess( + new lib_plankton.prog.struct_expression_variable("value"), + field.name, + ), + }) + ) + ) + ), + }, + ] + ), + ] + ), + "then" + ), + [ + new lib_plankton.prog.struct_expression_abstraction( + [ + { + "name": "result", + "type": null, + } + ], + null, + [ + ] + ), + ] + ) + ), + ] + ), + // delete + new lib_plankton.prog.struct_statement_function_definition( + name_repository_function_delete(domain), + [ + { + "name": "key", + "type": new lib_plankton.prog.struct_type_integer( + ), + }, + ], + new lib_plankton.prog.struct_type_construction( + "Promise", + [ + new lib_plankton.prog.struct_type_void(), + ] + ), + [ + new lib_plankton.prog.struct_statement_return( + new lib_plankton.prog.struct_expression_function_application( + new lib_plankton.prog.struct_expression_fieldaccess( + new lib_plankton.prog.struct_expression_function_application( + new lib_plankton.prog.struct_expression_variable("lib_plankton.sqlite.query_put"), + [ + new lib_plankton.prog.struct_expression_fieldaccess(new lib_plankton.prog.struct_expression_variable("conf"), "database_path"), + new lib_plankton.prog.struct_expression_dict( + [ + { + "key": "template", + "value": new lib_plankton.prog.struct_expression_literal( + lib_plankton.string.coin( + "DELETE FROM {{name}} WHERE ({{key}} = :key);", + { + "name": name_table(domain), + "key": domain.key_field.name, + } + ) + ), + }, + { + "key": "arguments", + "value": new lib_plankton.prog.struct_expression_dict( + [ + { + "key": "key", + "value": new lib_plankton.prog.struct_expression_variable("key"), + }, + ] + ), + }, + ] + ), + ] + ), + "then" + ), + [ + new lib_plankton.prog.struct_expression_abstraction( + [ + { + "name": "result", + "type": null, + } + ], + null, + [ + ] + ), + ] + ) + ), + ] + ), + ] + ) + ) + .reduce( + (x, y) => x.concat(y), + [] + ) + ) + // misc + .concat( + [ + // lib_plankton.log.conf_push([new lib_plankton.log.class_channel_stdout()]); + new lib_plankton.prog.struct_statement_procedure_call( + new lib_plankton.prog.struct_expression_fieldaccess( + new lib_plankton.prog.struct_expression_fieldaccess( + new lib_plankton.prog.struct_expression_variable( + "lib_plankton" + ), + "log" + ), + "conf_push" + ), + [ + new lib_plankton.prog.struct_expression_list( + [ + new lib_plankton.prog.struct_expression_function_application( + new lib_plankton.prog.struct_expression_fieldaccess( + new lib_plankton.prog.struct_expression_fieldaccess( + new lib_plankton.prog.struct_expression_variable( + "new lib_plankton" // TODO: HACK! + ), + "log" + ), + "class_channel_stdout" + ), + [ ] - ) + ), + ] + ) + ] + ), + ] + ) + // api + .concat( + [ + new lib_plankton.prog.struct_statement_comment( + false, + [ + "define api", + ] + ), + new lib_plankton.prog.struct_statement_declaration( + true, + "rest", + new lib_plankton.prog.struct_type_construction( + "lib_plankton.rest.type_rest", + null + ), + new lib_plankton.prog.struct_expression_function_application( + new lib_plankton.prog.struct_expression_fieldaccess( + new lib_plankton.prog.struct_expression_fieldaccess( + new lib_plankton.prog.struct_expression_variable("lib_plankton"), + "rest" + ), + "make" + ), + [ + new lib_plankton.prog.struct_expression_dict( + [ + ] ), ] ), - // delete - new lib_plankton.prog.struct_statement_function_definition( - name_repository_function_delete(domain), - [ - { - "name": "key", - "type": new lib_plankton.prog.struct_type_integer( - ), - }, - ], - new lib_plankton.prog.struct_type_construction( - "Promise", + ), + new lib_plankton.prog.struct_statement_block( + [ + new lib_plankton.prog.struct_statement_comment( + false, [ - new lib_plankton.prog.struct_type_void(), + "meta", ] ), - [ - new lib_plankton.prog.struct_statement_return( - // TODO - new lib_plankton.prog.struct_expression_function_application( - new lib_plankton.prog.struct_expression_variable("sql_query_set"), + new lib_plankton.prog.struct_statement_block( + [ + new lib_plankton.prog.struct_statement_procedure_call( + new lib_plankton.prog.struct_expression_fieldaccess( + new lib_plankton.prog.struct_expression_fieldaccess( + new lib_plankton.prog.struct_expression_variable( + "lib_plankton" + ), + "rest" + ), + "register" + ), [ + new lib_plankton.prog.struct_expression_variable("rest"), + new lib_plankton.prog.struct_expression_fieldaccess( + new lib_plankton.prog.struct_expression_fieldaccess( + new lib_plankton.prog.struct_expression_fieldaccess( + new lib_plankton.prog.struct_expression_variable( + "lib_plankton" + ), + "http" + ), + "enum_method" + ), + "get" + ), new lib_plankton.prog.struct_expression_literal( - lib_plankton.string.coin( - "DELETE FROM {{name}} WHERE ({{key}} = :key);", - { - "name": name_table(domain), - "key": domain.key_field.name, - } - ) + "/_spec" ), new lib_plankton.prog.struct_expression_dict( [ { - "key": "key", - "value": new lib_plankton.prog.struct_expression_variable("key"), + "key": "execution", + "value": new lib_plankton.prog.struct_expression_abstraction( + [ + { + "name": "stuff", + "type": null, + } + ], + null, + [ + new lib_plankton.prog.struct_statement_return( + new lib_plankton.prog.struct_expression_dict( + [ + { + "key": "status_code", + "value": new lib_plankton.prog.struct_expression_literal(200), + }, + { + "key": "data", + "value": new lib_plankton.prog.struct_expression_function_application( + new lib_plankton.prog.struct_expression_fieldaccess( + new lib_plankton.prog.struct_expression_fieldaccess( + new lib_plankton.prog.struct_expression_variable( + "lib_plankton" + ), + "rest" + ), + "to_oas" + ), + [ + new lib_plankton.prog.struct_expression_variable( + "rest" + ), + ] + ), + } + ] + ) + ), + ], + { + "async": true, + } + ), }, ] ), ] - ) + ), + ] + ), + ] + .concat( + input_data["domains"] + .map( + domain => new lib_plankton.prog.struct_statement_block( + [ + new lib_plankton.prog.struct_statement_comment( + false, + [ + ("domain:" + domain.name), + ] + ), + // list + new lib_plankton.prog.struct_statement_procedure_call( + new lib_plankton.prog.struct_expression_fieldaccess( + new lib_plankton.prog.struct_expression_fieldaccess( + new lib_plankton.prog.struct_expression_variable( + "lib_plankton" + ), + "rest" + ), + "register" + ), + [ + new lib_plankton.prog.struct_expression_variable("rest"), + new lib_plankton.prog.struct_expression_fieldaccess( + new lib_plankton.prog.struct_expression_fieldaccess( + new lib_plankton.prog.struct_expression_fieldaccess( + new lib_plankton.prog.struct_expression_variable( + "lib_plankton" + ), + "http" + ), + "enum_method" + ), + "get" + ), + new lib_plankton.prog.struct_expression_literal( + lib_plankton.string.coin( + "/{{name}}", + { + "name": domain.name, + } + ) + ), + new lib_plankton.prog.struct_expression_dict( + [ + { + "key": "execution", + "value": new lib_plankton.prog.struct_expression_abstraction( + [ + { + "name": "stuff", + "type": null, + } + ], + null, + [ + new lib_plankton.prog.struct_statement_return( + new lib_plankton.prog.struct_expression_dict( + [ + { + "key": "status_code", + "value": new lib_plankton.prog.struct_expression_literal(200), + }, + { + "key": "data", + "value": new lib_plankton.prog.struct_expression_await( + new lib_plankton.prog.struct_expression_function_application( + new lib_plankton.prog.struct_expression_variable(name_repository_function_list(domain)), + [ + ] + ) + ), + } + ] + ) + ), + ], + { + "async": true, + } + ), + } + // TODO + ] + ), + ] + ), + // get + new lib_plankton.prog.struct_statement_procedure_call( + new lib_plankton.prog.struct_expression_fieldaccess( + new lib_plankton.prog.struct_expression_fieldaccess( + new lib_plankton.prog.struct_expression_variable( + "lib_plankton" + ), + "rest" + ), + "register" + ), + [ + new lib_plankton.prog.struct_expression_variable("rest"), + new lib_plankton.prog.struct_expression_fieldaccess( + new lib_plankton.prog.struct_expression_fieldaccess( + new lib_plankton.prog.struct_expression_fieldaccess( + new lib_plankton.prog.struct_expression_variable( + "lib_plankton" + ), + "http" + ), + "enum_method" + ), + "get" + ), + new lib_plankton.prog.struct_expression_literal( + lib_plankton.string.coin( + "/{{name}}/:id", + { + "name": domain.name, + } + ) + ), + new lib_plankton.prog.struct_expression_dict( + [ + { + "key": "execution", + "value": new lib_plankton.prog.struct_expression_abstraction( + [ + { + "name": "stuff", + "type": null, + } + ], + null, + [ + new lib_plankton.prog.struct_statement_return( + new lib_plankton.prog.struct_expression_dict( + [ + { + "key": "status_code", + "value": new lib_plankton.prog.struct_expression_literal(200), + }, + { + "key": "data", + "value": new lib_plankton.prog.struct_expression_await( + new lib_plankton.prog.struct_expression_function_application( + new lib_plankton.prog.struct_expression_variable(name_repository_function_read(domain)), + [ + new lib_plankton.prog.struct_expression_function_application( + new lib_plankton.prog.struct_expression_variable("parseInt"), + [ + new lib_plankton.prog.struct_expression_projection( + new lib_plankton.prog.struct_expression_fieldaccess( + new lib_plankton.prog.struct_expression_variable("stuff"), + "path_parameters" + ), + new lib_plankton.prog.struct_expression_literal("id") + ), + ] + ), + ] + ) + ), + } + ] + ) + ), + ], + { + "async": true, + } + ), + } + ] + ), + ] + ), + // add + new lib_plankton.prog.struct_statement_procedure_call( + new lib_plankton.prog.struct_expression_fieldaccess( + new lib_plankton.prog.struct_expression_fieldaccess( + new lib_plankton.prog.struct_expression_variable( + "lib_plankton" + ), + "rest" + ), + "register" + ), + [ + new lib_plankton.prog.struct_expression_variable("rest"), + new lib_plankton.prog.struct_expression_fieldaccess( + new lib_plankton.prog.struct_expression_fieldaccess( + new lib_plankton.prog.struct_expression_fieldaccess( + new lib_plankton.prog.struct_expression_variable( + "lib_plankton" + ), + "http" + ), + "enum_method" + ), + "post" + ), + new lib_plankton.prog.struct_expression_literal( + lib_plankton.string.coin( + "/{{name}}", + { + "name": domain.name, + } + ) + ), + new lib_plankton.prog.struct_expression_dict( + [ + { + "key": "execution", + "value": new lib_plankton.prog.struct_expression_abstraction( + [ + { + "name": "stuff", + "type": null, + } + ], + null, + [ + new lib_plankton.prog.struct_statement_declaration( + true, + "id", + null, + new lib_plankton.prog.struct_expression_await( + new lib_plankton.prog.struct_expression_function_application( + new lib_plankton.prog.struct_expression_variable(name_repository_function_create(domain)), + [ + new lib_plankton.prog.struct_expression_cast( + new lib_plankton.prog.struct_expression_fieldaccess( + new lib_plankton.prog.struct_expression_variable("stuff"), + "input" + ), + new lib_plankton.prog.struct_type_construction( + name_type(domain), + null + ), + ), + ] + ) + ) + ), + new lib_plankton.prog.struct_statement_return( + new lib_plankton.prog.struct_expression_dict( + [ + { + "key": "status_code", + "value": new lib_plankton.prog.struct_expression_literal(201), + }, + { + "key": "data", + "value": new lib_plankton.prog.struct_expression_variable("id"), + } + ] + ) + ), + ], + { + "async": true, + } + ), + } + ] + ), + ] + ), + // change + new lib_plankton.prog.struct_statement_procedure_call( + new lib_plankton.prog.struct_expression_fieldaccess( + new lib_plankton.prog.struct_expression_fieldaccess( + new lib_plankton.prog.struct_expression_variable( + "lib_plankton" + ), + "rest" + ), + "register" + ), + [ + new lib_plankton.prog.struct_expression_variable("rest"), + new lib_plankton.prog.struct_expression_fieldaccess( + new lib_plankton.prog.struct_expression_fieldaccess( + new lib_plankton.prog.struct_expression_fieldaccess( + new lib_plankton.prog.struct_expression_variable( + "lib_plankton" + ), + "http" + ), + "enum_method" + ), + "patch" + ), + new lib_plankton.prog.struct_expression_literal( + lib_plankton.string.coin( + "/{{name}}/:id", + { + "name": domain.name, + } + ) + ), + new lib_plankton.prog.struct_expression_dict( + [ + { + "key": "execution", + "value": new lib_plankton.prog.struct_expression_abstraction( + [ + { + "name": "stuff", + "type": null, + } + ], + null, + [ + new lib_plankton.prog.struct_statement_declaration( + true, + "dummy", + null, + new lib_plankton.prog.struct_expression_await( + new lib_plankton.prog.struct_expression_function_application( + new lib_plankton.prog.struct_expression_variable(name_repository_function_update(domain)), + [ + new lib_plankton.prog.struct_expression_function_application( + new lib_plankton.prog.struct_expression_variable("parseInt"), + [ + new lib_plankton.prog.struct_expression_projection( + new lib_plankton.prog.struct_expression_fieldaccess( + new lib_plankton.prog.struct_expression_variable("stuff"), + "path_parameters" + ), + new lib_plankton.prog.struct_expression_literal("id") + ), + ] + ), + new lib_plankton.prog.struct_expression_cast( + new lib_plankton.prog.struct_expression_fieldaccess( + new lib_plankton.prog.struct_expression_variable("stuff"), + "input" + ), + new lib_plankton.prog.struct_type_construction( + name_type(domain), + null + ), + ), + ] + ) + ) + ), + new lib_plankton.prog.struct_statement_return( + new lib_plankton.prog.struct_expression_dict( + [ + { + "key": "status_code", + "value": new lib_plankton.prog.struct_expression_literal(200), + }, + { + "key": "data", + "value": new lib_plankton.prog.struct_expression_literal(null), + } + ] + ) + ), + ], + { + "async": true, + } + ), + } + ] + ), + ] + ), + // remove + new lib_plankton.prog.struct_statement_procedure_call( + new lib_plankton.prog.struct_expression_fieldaccess( + new lib_plankton.prog.struct_expression_fieldaccess( + new lib_plankton.prog.struct_expression_variable( + "lib_plankton" + ), + "rest" + ), + "register" + ), + [ + new lib_plankton.prog.struct_expression_variable("rest"), + new lib_plankton.prog.struct_expression_fieldaccess( + new lib_plankton.prog.struct_expression_fieldaccess( + new lib_plankton.prog.struct_expression_fieldaccess( + new lib_plankton.prog.struct_expression_variable( + "lib_plankton" + ), + "http" + ), + "enum_method" + ), + "delete" + ), + new lib_plankton.prog.struct_expression_literal( + lib_plankton.string.coin( + "/{{name}}/:id", + { + "name": domain.name, + } + ) + ), + new lib_plankton.prog.struct_expression_dict( + [ + { + "key": "execution", + "value": new lib_plankton.prog.struct_expression_abstraction( + [ + { + "name": "stuff", + "type": null, + } + ], + null, + [ + new lib_plankton.prog.struct_statement_return( + new lib_plankton.prog.struct_expression_dict( + [ + { + "key": "status_code", + "value": new lib_plankton.prog.struct_expression_literal(200), + }, + { + "key": "data", + "value": new lib_plankton.prog.struct_expression_await( + new lib_plankton.prog.struct_expression_function_application( + new lib_plankton.prog.struct_expression_variable(name_repository_function_delete(domain)), + [ + new lib_plankton.prog.struct_expression_function_application( + new lib_plankton.prog.struct_expression_variable("parseInt"), + [ + new lib_plankton.prog.struct_expression_projection( + new lib_plankton.prog.struct_expression_fieldaccess( + new lib_plankton.prog.struct_expression_variable("stuff"), + "path_parameters" + ), + new lib_plankton.prog.struct_expression_literal("id") + ), + ] + ), + ] + ) + ), + } + ] + ) + ), + ], + { + "async": true, + } + ), + } + ] + ), + ] + ), + ] + ) + ) + ) + ) + ] + ) + // server + .concat( + [ + new lib_plankton.prog.struct_statement_comment( + false, + [ + "setup server", + ] + ), + new lib_plankton.prog.struct_statement_declaration( + true, + "server", + null, // TODO + new lib_plankton.prog.struct_expression_function_application( + new lib_plankton.prog.struct_expression_fieldaccess( + new lib_plankton.prog.struct_expression_fieldaccess( + new lib_plankton.prog.struct_expression_variable("lib_plankton"), + "server" + ), + "make" + ), + [ + new lib_plankton.prog.struct_expression_fieldaccess( + new lib_plankton.prog.struct_expression_variable("conf"), + "server_port" + ), + new lib_plankton.prog.struct_expression_abstraction( + [ + { + "name": "input", + "type": null, + }, + ], + null, + [ + new lib_plankton.prog.struct_statement_declaration( + true, + "http_request", + new lib_plankton.prog.struct_type_construction( + "lib_plankton.http.type_request", + null + ), + new lib_plankton.prog.struct_expression_function_application( + new lib_plankton.prog.struct_expression_fieldaccess( + new lib_plankton.prog.struct_expression_fieldaccess( + new lib_plankton.prog.struct_expression_variable("lib_plankton"), + "http" + ), + "decode_request" + ), + [ + new lib_plankton.prog.struct_expression_variable("input"), + ] + ) + ), + new lib_plankton.prog.struct_statement_declaration( + true, + "http_response", + new lib_plankton.prog.struct_type_construction( + "lib_plankton.http.type_response", + null + ), + new lib_plankton.prog.struct_expression_await( + new lib_plankton.prog.struct_expression_function_application( + new lib_plankton.prog.struct_expression_fieldaccess( + new lib_plankton.prog.struct_expression_fieldaccess( + new lib_plankton.prog.struct_expression_variable("lib_plankton"), + "rest" + ), + "call" + ), + [ + new lib_plankton.prog.struct_expression_variable("rest"), + new lib_plankton.prog.struct_expression_variable("http_request"), + ] + ) + ) + ), + new lib_plankton.prog.struct_statement_return( + new lib_plankton.prog.struct_expression_function_application( + new lib_plankton.prog.struct_expression_fieldaccess( + new lib_plankton.prog.struct_expression_fieldaccess( + new lib_plankton.prog.struct_expression_variable("lib_plankton"), + "http" + ), + "encode_response" + ), + [ + new lib_plankton.prog.struct_expression_variable("http_response"), + ] + ) + ), + ], + { + "async": true, + } ), ] + ) + ), + new lib_plankton.prog.struct_statement_procedure_call( + new lib_plankton.prog.struct_expression_fieldaccess( + new lib_plankton.prog.struct_expression_fieldaccess( + new lib_plankton.prog.struct_expression_variable("lib_plankton"), + "server" + ), + "start" ), - ] - ) + [ + new lib_plankton.prog.struct_expression_variable("server") + ] + ), + ] ) - .reduce( - (x, y) => x.concat(y), - [] - ) - ) - // services - .concat( - [] - ) - // api - .concat( - [] - ) - // server - .concat( - [] ) ) ); diff --git a/tools/makefile b/tools/makefile index edce9ff..86c0dd6 100644 --- a/tools/makefile +++ b/tools/makefile @@ -7,6 +7,7 @@ cmd_chmod := chmod cmd_echo := echo -e cmd_echox := echo cmd_log := echo -e "--" +cmd_copy := cp -r -u -v ## rules @@ -30,7 +31,6 @@ source/main.ts build/sindri: lib/plankton/plankton.js temp/sindri-unlinked.js @ ${cmd_log} "linking …" @ ${cmd_create_directory} build - @ ${cmd_echo} "#!/usr/bin/env node" > temp/head.js + @ ${cmd_echox} "#!/usr/bin/env node" > temp/head.js @ ${cmd_concatenate} temp/head.js $^ > $@ @ ${cmd_chmod} +x $@ -