[mod] output:backend:typescript:use templates

This commit is contained in:
Christian Fraß 2023-08-08 16:35:33 +02:00
parent fd733f69da
commit ab9f1a6d6d
5 changed files with 567 additions and 1388 deletions

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,88 @@
// {{domain_name}}
{
lib_plankton.rest.register(
rest,
lib_plankton.http.enum_method.get,
"/{{path_base}}{{domain_name}}",
{
"execution": async function (stuff) {
return {
"status_code": 200,
"data": await {{repository_function_list}}(
)
};
}
}
);
lib_plankton.rest.register(
rest,
lib_plankton.http.enum_method.get,
"/{{path_base}}{{domain_name}}/:id",
{
"execution": async function (stuff) {
return {
"status_code": 200,
"data": await {{repository_function_read}}(
parseInt(
stuff.path_parameters["id"]
)
)
};
}
}
);
lib_plankton.rest.register(
rest,
lib_plankton.http.enum_method.post,
"/{{path_base}}{{domain_name}}",
{
"execution": async function (stuff) {
const id = await {{repository_function_create}}(
(stuff.input as {{type_name}})
);
return {
"status_code": 201,
"data": id
};
}
}
);
lib_plankton.rest.register(
rest,
lib_plankton.http.enum_method.patch,
"/{{path_base}}{{domain_name}}/:id",
{
"execution": async function (stuff) {
const dummy = await {{repository_function_create}}(
parseInt(
stuff.path_parameters["id"]
),
(stuff.input as {{type_name}})
);
return {
"status_code": 200,
"data": null
};
}
}
);
lib_plankton.rest.register(
rest,
lib_plankton.http.enum_method.delete,
"/{{path_base}}{{domain_name}}/:id",
{
"execution": async function (stuff) {
const dummy = await {{repository_function_delete}}(
parseInt(
stuff.path_parameters["id"]
)
);
return {
"status_code": 200,
"data": null
};
}
}
);
}

View file

@ -0,0 +1,4 @@
export namespace {{domain_name}}
{
{{defs}}
}

View file

@ -0,0 +1,74 @@
// declare var require;
namespace {{namespace_base}}entities
{
{{entities}}
}
namespace {{namespace_base}}repositories
{
{{repositories}}
}
namespace {{namespace_base}}main
{
// run
export function run(
) : void
{
lib_plankton.log.conf_push(
[
new lib_plankton.log.class_channel_stdout(
)
]
);
// define api
{
// meta
{
lib_plankton.rest.register(
rest,
lib_plankton.http.enum_method.get,
"/_spec",
{
"execution": async function (stuff) {
return {
"status_code": 200,
"data": lib_plankton.rest.to_oas(
rest
)
};
}
}
);
}
{{api}}
}
// setup server
const server = lib_plankton.server.make(
conf.server_port,
async function (input) {
const http_request : lib_plankton.http.type_request = lib_plankton.http.decode_request(
input
);
const http_response : lib_plankton.http.type_response = await lib_plankton.rest.call(
rest,
http_request
);
return lib_plankton.http.encode_response(
http_response
);
}
);
// start
lib_plankton.server.start(
server
);
}
}

View file

@ -0,0 +1,121 @@
export namespace {{domain_name}}
{
// list
export function {{list_function_name}}(
) : Promise<Array<{key : number; value : {{type_name}};}>>
{
return (
lib_plankton.sqlite.query_get(
conf.database_path,
{
"template": "SELECT {{list_query_fields}} FROM {{table_name}};",
"arguments": {
}
}
)
.then(
function (rows) {
return rows.map(
function (row) {
return {{list_result}};
}
);
}
)
);
}
// read
export function {{read_function_name}}(
key : number
) : Promise<{{type_name}}>
{
return (
lib_plankton.sqlite.query_get(
conf.database_path,
{
"template": "SELECT {{read_query_fields}} FROM {{table_name}} WHERE (id = :key);",
"arguments": {
"key": key
}
}
)
.then(
function (rows) {
const row = rows[0];
return {{read_result_fields}};
}
)
);
}
// create
export function {{create_function_name}}(
value : {{type_name}}
) : Promise<number>
{
return (
lib_plankton.sqlite.query_put(
conf.database_path,
{
"template": "INSERT INTO {{table_name}}({{create_query_field_names}}) VALUES ({{create_query_field_placeholders}});",
"arguments": {{create_query_field_values}}
}
)
.then(
function (result) {
return result.id;
}
)
);
}
// update
export function {{update_function_name}}(
key : number,
value : {{type_name}}
) : Promise<void>
{
return (
lib_plankton.sqlite.query_put(
conf.database_path,
{
"template": "UPDATE {{table_name}} SET {{update_query_assignments}} WHERE (id = :key);",
"arguments": {
"key": key,
{{update_query_values}}
}
}
)
.then(
function (result) {
}
)
);
}
// delete
export function {{delete_function_name}}(
key : number
) : Promise<void>
{
return (
lib_plankton.sqlite.query_put(
conf.database_path,
{
"template": "DELETE FROM {{table_name}} WHERE (id = :key);",
"arguments": {
"key": key
}
}
)
.then(
function (result) {
}
)
);
}
}