[mod] namespaces verwenden
This commit is contained in:
parent
94864eaeec
commit
fc4c1c4c27
|
|
@ -7,7 +7,7 @@ async function main(
|
||||||
const outputs : Record<string, type_output> = {
|
const outputs : Record<string, type_output> = {
|
||||||
"sqlite": output_sqlite,
|
"sqlite": output_sqlite,
|
||||||
"mysql": output_mysql,
|
"mysql": output_mysql,
|
||||||
"typescript": output_typescript,
|
"backend-typescript": output_typescript,
|
||||||
"jsonschema": output_jsonschema,
|
"jsonschema": output_jsonschema,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,9 @@
|
||||||
function mysql_value_encode(
|
namespace _sindri.outputs.mysql
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
*/
|
||||||
|
function value_encode(
|
||||||
value : any
|
value : any
|
||||||
) : string
|
) : string
|
||||||
{
|
{
|
||||||
|
|
@ -27,8 +32,13 @@ function mysql_value_encode(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const output_mysql : type_output = {
|
|
||||||
"render": function (input_data) {
|
/**
|
||||||
|
*/
|
||||||
|
export function render(
|
||||||
|
input_data
|
||||||
|
) : string
|
||||||
|
{
|
||||||
return (
|
return (
|
||||||
input_data.domains
|
input_data.domains
|
||||||
.map(
|
.map(
|
||||||
|
|
@ -114,7 +124,7 @@ const output_mysql : type_output = {
|
||||||
lib_plankton.string.coin(
|
lib_plankton.string.coin(
|
||||||
"DEFAULT {{value}}",
|
"DEFAULT {{value}}",
|
||||||
{
|
{
|
||||||
"value": mysql_value_encode(data_field.default),
|
"value": value_encode(data_field.default),
|
||||||
}
|
}
|
||||||
),
|
),
|
||||||
]
|
]
|
||||||
|
|
@ -195,5 +205,13 @@ const output_mysql : type_output = {
|
||||||
.map(x => (x + "\n"))
|
.map(x => (x + "\n"))
|
||||||
.join("\n")
|
.join("\n")
|
||||||
);
|
);
|
||||||
},
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
*/
|
||||||
|
const output_mysql : type_output = {
|
||||||
|
"render": _sindri.outputs.mysql.render,
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,9 @@
|
||||||
function sqlite_value_encode(
|
namespace _sindri.outputs.sqlite
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
*/
|
||||||
|
function value_encode(
|
||||||
value : any
|
value : any
|
||||||
) : string
|
) : string
|
||||||
{
|
{
|
||||||
|
|
@ -27,8 +32,13 @@ function sqlite_value_encode(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const output_sqlite : type_output = {
|
|
||||||
"render": function (input_data) {
|
/**
|
||||||
|
*/
|
||||||
|
export function render(
|
||||||
|
input_data
|
||||||
|
) : string
|
||||||
|
{
|
||||||
return (
|
return (
|
||||||
input_data["domains"]
|
input_data["domains"]
|
||||||
.map(
|
.map(
|
||||||
|
|
@ -92,7 +102,7 @@ const output_sqlite : type_output = {
|
||||||
lib_plankton.string.coin(
|
lib_plankton.string.coin(
|
||||||
"DEFAULT {{value}}",
|
"DEFAULT {{value}}",
|
||||||
{
|
{
|
||||||
"value": sqlite_value_encode(data_field.default),
|
"value": value_encode(data_field.default),
|
||||||
}
|
}
|
||||||
),
|
),
|
||||||
]
|
]
|
||||||
|
|
@ -160,5 +170,10 @@ const output_sqlite : type_output = {
|
||||||
.map(x => (x + "\n"))
|
.map(x => (x + "\n"))
|
||||||
.join("\n")
|
.join("\n")
|
||||||
);
|
);
|
||||||
},
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
const output_sqlite : type_output = {
|
||||||
|
"render": _sindri.outputs.sqlite.render,
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,14 @@
|
||||||
const output_typescript : type_output = {
|
namespace _sindri.outputs.typescript
|
||||||
"render": function (input_data) {
|
{
|
||||||
return (
|
|
||||||
input_data["domains"]
|
/**
|
||||||
.map(
|
*/
|
||||||
(domain) => lib_plankton.string.coin(
|
function render_entity_type(
|
||||||
"type type_{{name}} = {\n{{fields}}\n};\nlet collection_{{name}} : {{collection_type}} = {{collection_value}};\n",
|
domain
|
||||||
|
) : string
|
||||||
|
{
|
||||||
|
return lib_plankton.string.coin(
|
||||||
|
"type type_{{name}} = {\n{{fields}}\n};\n",
|
||||||
{
|
{
|
||||||
"name": domain.name,
|
"name": domain.name,
|
||||||
"fields": (
|
"fields": (
|
||||||
|
|
@ -43,6 +47,21 @@ const output_typescript : type_output = {
|
||||||
// .map(x => ("\t" + x))
|
// .map(x => ("\t" + x))
|
||||||
.join("\n")
|
.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": (
|
"collection_type": (
|
||||||
(domain.key_field === null)
|
(domain.key_field === null)
|
||||||
? lib_plankton.string.coin(
|
? lib_plankton.string.coin(
|
||||||
|
|
@ -64,10 +83,91 @@ const output_typescript : type_output = {
|
||||||
: "{}"
|
: "{}"
|
||||||
),
|
),
|
||||||
}
|
}
|
||||||
)
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
*/
|
||||||
|
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<type_{{name}}> {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"))
|
.map(x => (x + "\n"))
|
||||||
.join("\n")
|
.join("\n")
|
||||||
);
|
);
|
||||||
},
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
const output_typescript : type_output = {
|
||||||
|
"render": _sindri.outputs.typescript.render,
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -18,8 +18,8 @@ lib/plankton/plankton.d.ts \
|
||||||
source/types.ts \
|
source/types.ts \
|
||||||
source/outputs/sqlite.ts \
|
source/outputs/sqlite.ts \
|
||||||
source/outputs/mysql.ts \
|
source/outputs/mysql.ts \
|
||||||
source/outputs/typescript.ts \
|
|
||||||
source/outputs/jsonschema.ts \
|
source/outputs/jsonschema.ts \
|
||||||
|
source/outputs/typescript.ts \
|
||||||
source/conf.ts \
|
source/conf.ts \
|
||||||
source/main.ts
|
source/main.ts
|
||||||
@ ${cmd_log} "compiling …"
|
@ ${cmd_log} "compiling …"
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue