78 lines
1 KiB
TypeScript
78 lines
1 KiB
TypeScript
|
|
/**
|
|
*/
|
|
interface type_output<type_result> extends lib_plankton.call.type_coproduct
|
|
{
|
|
|
|
/**
|
|
*/
|
|
render_object(
|
|
object : type_object
|
|
) : type_result
|
|
;
|
|
|
|
|
|
/**
|
|
*/
|
|
render_document(
|
|
document : type_document
|
|
) : type_result
|
|
;
|
|
|
|
}
|
|
|
|
|
|
/**
|
|
*/
|
|
let output_kind_pool : Record<
|
|
string,
|
|
(
|
|
(
|
|
data : any,
|
|
make : ((raw : any) => type_output<any>)
|
|
)
|
|
=>
|
|
type_output<any>
|
|
)
|
|
> = {};
|
|
|
|
|
|
/**
|
|
*/
|
|
function output_kind_register<type_result>(
|
|
name : string,
|
|
factory : (
|
|
(data : any, make : ((raw : any) => type_output<type_result>))
|
|
=>
|
|
type_output<type_result>
|
|
)
|
|
) : void
|
|
{
|
|
if (name in output_kind_pool)
|
|
{
|
|
throw (new Error("kind '" + name + "' already registered"));
|
|
}
|
|
else
|
|
{
|
|
output_kind_pool[name] = factory;
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
*/
|
|
function output_make<type_result>(
|
|
raw : any
|
|
) : type_output<type_result>
|
|
{
|
|
if (! (raw["kind"] in output_kind_pool))
|
|
{
|
|
throw (new Error("kind '" + raw["kind"] + "' not registered"));
|
|
}
|
|
else
|
|
{
|
|
return output_kind_pool[raw["kind"]](raw["data"], output_make<type_result>);
|
|
}
|
|
}
|
|
|