2025-03-29 22:59:13 +01:00
|
|
|
import {Type} from "./types/type";
|
2024-10-03 23:33:00 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Property definition class.
|
|
|
|
*/
|
|
|
|
export class Definition<SerializedType, ModelType>
|
|
|
|
{
|
|
|
|
readonly _sharkitek: ModelType;
|
|
|
|
readonly _serialized: SerializedType;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a property definer instance.
|
|
|
|
* @param type Property type.
|
|
|
|
*/
|
|
|
|
constructor(public readonly type: Type<SerializedType, ModelType>)
|
|
|
|
{}
|
|
|
|
}
|
|
|
|
|
2025-03-29 22:59:13 +01:00
|
|
|
/**
|
|
|
|
* Unknown property definition.
|
|
|
|
*/
|
|
|
|
export type UnknownDefinition = Definition<unknown, unknown>;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Any property definition.
|
|
|
|
*/
|
|
|
|
export type AnyDefinition = Definition<any, any>;
|
|
|
|
|
2024-10-03 23:33:00 +02:00
|
|
|
/**
|
|
|
|
* New definition of a property of the given type.
|
|
|
|
* @param type Type of the property to define.
|
|
|
|
*/
|
|
|
|
export function define<SerializedType, ModelType>(type: Type<SerializedType, ModelType>): Definition<SerializedType, ModelType>
|
|
|
|
{
|
|
|
|
return new Definition(type);
|
|
|
|
}
|