Skip to content

Commit

Permalink
Add a new model class type.
Browse files Browse the repository at this point in the history
  • Loading branch information
Madeorsk committed Oct 4, 2024
1 parent 22bc42a commit 62e62f9
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
</p>

<p align="center">
<img alt="Version 3.0.0" src="https://img.shields.io/badge/version-3.0.0-blue" />
<img alt="Version 3.0.1" src="https://img.shields.io/badge/version-3.0.1-blue" />
</p>

## Introduction
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@sharkitek/core",
"version": "3.0.0",
"version": "3.0.1",
"description": "TypeScript library for well-designed model architectures.",
"keywords": [
"deserialization",
Expand Down
9 changes: 7 additions & 2 deletions src/Model/Model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ export type SerializedModel<Shape extends ModelShape> = {
*/
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.
*/
Expand Down Expand Up @@ -91,7 +96,7 @@ export interface ModelDefinition<Shape extends ModelShape, IdentifierType>
export function model<Shape extends ModelShape, Identifier extends keyof Shape = any>(
shape: Shape,
identifier?: Identifier,
): ConstructorOf<Model<Shape, IdentifierType<Shape, Identifier>>>
): ModelClass<Shape, Identifier>
{
// Get shape entries.
const shapeEntries = Object.entries(shape) as [keyof Shape, UnknownDefinition][];
Expand Down Expand Up @@ -227,5 +232,5 @@ export function model<Shape extends ModelShape, Identifier extends keyof Shape =
return diff; // Return the difference.
}

} as unknown as ConstructorOf<Model<Shape, IdentifierType<Shape, Identifier>>>;
} as unknown as ModelClass<Shape, Identifier>;
}

0 comments on commit 62e62f9

Please sign in to comment.