2025-03-29 22:59:13 +01:00
|
|
|
import {Type} from "./types/type";
|
2024-10-03 23:33:00 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Property definition class.
|
|
|
|
*/
|
2025-06-23 20:31:34 +02:00
|
|
|
export class Definition<SerializedType, ModelType> {
|
2024-10-03 23:33:00 +02:00
|
|
|
readonly _sharkitek: ModelType;
|
|
|
|
readonly _serialized: SerializedType;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a property definer instance.
|
|
|
|
* @param type Property type.
|
|
|
|
*/
|
2025-06-23 20:31:34 +02:00
|
|
|
constructor(public readonly type: Type<SerializedType, ModelType>) {}
|
2024-10-03 23:33:00 +02:00
|
|
|
}
|
|
|
|
|
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.
|
|
|
|
*/
|
2025-06-23 20:31:34 +02:00
|
|
|
export function define<SerializedType, ModelType>(
|
|
|
|
type: Type<SerializedType, ModelType>,
|
|
|
|
): Definition<SerializedType, ModelType> {
|
2024-10-03 23:33:00 +02:00
|
|
|
return new Definition(type);
|
|
|
|
}
|