Add a new model class type.
This commit is contained in:
parent
22bc42acba
commit
419b838f54
2 changed files with 8 additions and 3 deletions
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "@sharkitek/core",
|
"name": "@sharkitek/core",
|
||||||
"version": "3.0.0",
|
"version": "3.0.1",
|
||||||
"description": "TypeScript library for well-designed model architectures.",
|
"description": "TypeScript library for well-designed model architectures.",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"deserialization",
|
"deserialization",
|
||||||
|
|
|
@ -34,6 +34,11 @@ export type SerializedModel<Shape extends ModelShape> = {
|
||||||
*/
|
*/
|
||||||
export type Model<Shape extends ModelShape, IdentifierType = unknown> = ModelDefinition<Shape, IdentifierType> & PropertiesModel<Shape>;
|
export type Model<Shape extends ModelShape, IdentifierType = unknown> = ModelDefinition<Shape, IdentifierType> & PropertiesModel<Shape>;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Type of a model class.
|
||||||
|
*/
|
||||||
|
export type ModelClass<Shape extends ModelShape, Identifier extends keyof Shape = any> = ConstructorOf<Model<Shape, IdentifierType<Shape, Identifier>>>;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Identifier type.
|
* Identifier type.
|
||||||
*/
|
*/
|
||||||
|
@ -91,7 +96,7 @@ export interface ModelDefinition<Shape extends ModelShape, IdentifierType>
|
||||||
export function model<Shape extends ModelShape, Identifier extends keyof Shape = any>(
|
export function model<Shape extends ModelShape, Identifier extends keyof Shape = any>(
|
||||||
shape: Shape,
|
shape: Shape,
|
||||||
identifier?: Identifier,
|
identifier?: Identifier,
|
||||||
): ConstructorOf<Model<Shape, IdentifierType<Shape, Identifier>>>
|
): ModelClass<Shape, Identifier>
|
||||||
{
|
{
|
||||||
// Get shape entries.
|
// Get shape entries.
|
||||||
const shapeEntries = Object.entries(shape) as [keyof Shape, UnknownDefinition][];
|
const shapeEntries = Object.entries(shape) as [keyof Shape, UnknownDefinition][];
|
||||||
|
@ -227,5 +232,5 @@ export function model<Shape extends ModelShape, Identifier extends keyof Shape =
|
||||||
return diff; // Return the difference.
|
return diff; // Return the difference.
|
||||||
}
|
}
|
||||||
|
|
||||||
} as unknown as ConstructorOf<Model<Shape, IdentifierType<Shape, Identifier>>>;
|
} as unknown as ModelClass<Shape, Identifier>;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue