78 lines
2.4 KiB
TypeScript
78 lines
2.4 KiB
TypeScript
const output_typescript : type_output = {
|
|
"render": function (input_data) {
|
|
const map_primitive_type = function (typename : string) : lib_plankton.prog.struct_type {
|
|
const mymap : Record<string, lib_plankton.prog.struct_type> = {
|
|
"boolean": new lib_plankton.prog.struct_type_boolean(),
|
|
"integer": new lib_plankton.prog.struct_type_integer(),
|
|
// "float": new lib_plankton.prog.struct_type_integer(),
|
|
"string_short": new lib_plankton.prog.struct_type_string(),
|
|
"string_medium": new lib_plankton.prog.struct_type_string(),
|
|
"string_long": new lib_plankton.prog.struct_type_string(),
|
|
};
|
|
return mymap[typename];
|
|
};
|
|
const name_type : string = ("type_" + domain.name);
|
|
const name_collection : string = ("collection_" + domain.name);
|
|
const prog_output : lib_plankton.prog.type_output = lib_plankton.prog.output_typescript();
|
|
return prog_output.render_program(
|
|
new lib_plankton.prog.struct_program(
|
|
input_data["domains"]
|
|
.map(
|
|
(domain) => ([
|
|
new lib_plankton.prog.struct_statement_type_definition(
|
|
name_type,
|
|
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,
|
|
})
|
|
)
|
|
)
|
|
),
|
|
new lib_plankton.prog.struct_statement_declaration(
|
|
false,
|
|
name_collection,
|
|
(
|
|
(domain.key_field === null)
|
|
? new lib_plankton.prog.struct_type_list(
|
|
new lib_plankton.prog.struct_type_construction(
|
|
name_type,
|
|
null
|
|
)
|
|
)
|
|
: new lib_plankton.prog.struct_type_map(
|
|
new lib_plankton.prog.struct_type_integer(),
|
|
new lib_plankton.prog.struct_type_construction(
|
|
name_type,
|
|
null
|
|
)
|
|
)
|
|
),
|
|
(
|
|
(domain.key_field === null)
|
|
? new lib_plankton.prog.struct_expression_literal([])
|
|
: new lib_plankton.prog.struct_expression_literal({})
|
|
)
|
|
)
|
|
])
|
|
)
|
|
.reduce((x, y) => x.concat(y), [])
|
|
)
|
|
);
|
|
},
|
|
};
|