62 lines
782 B
TypeScript
62 lines
782 B
TypeScript
|
|
/**
|
|
*/
|
|
interface type_object extends lib_plankton.call.type_coproduct
|
|
{
|
|
}
|
|
|
|
|
|
/**
|
|
*/
|
|
let object_kind_pool : Record<
|
|
string,
|
|
(
|
|
(
|
|
data : any,
|
|
make : ((raw : any) => type_object)
|
|
)
|
|
=>
|
|
type_object
|
|
)
|
|
> = {};
|
|
|
|
|
|
/**
|
|
*/
|
|
function object_kind_register(
|
|
name : string,
|
|
factory : (
|
|
(data : any, make : ((raw : any) => type_object))
|
|
=>
|
|
type_object
|
|
)
|
|
) : void
|
|
{
|
|
if (name in object_kind_pool)
|
|
{
|
|
throw (new Error("kind '" + name + "' already registered"));
|
|
}
|
|
else
|
|
{
|
|
object_kind_pool[name] = factory;
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
*/
|
|
function object_make(
|
|
raw : any
|
|
) : type_object
|
|
{
|
|
if (! (raw["kind"] in object_kind_pool))
|
|
{
|
|
throw (new Error("kind '" + raw["kind"] + "' not registered"));
|
|
}
|
|
else
|
|
{
|
|
return object_kind_pool[raw["kind"]](raw["data"], object_make);
|
|
}
|
|
}
|
|
|