From e373efdd0a08f310a6230f32690dfae0e4064d5b Mon Sep 17 00:00:00 2001 From: Madeorsk Date: Sat, 5 Oct 2024 14:16:15 +0200 Subject: [PATCH] Add a way to get the identifier name of a model. --- README.md | 2 +- package.json | 2 +- src/Model/Model.ts | 17 ++++++++++++++++- 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 4d8bd75..24c4cf8 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,7 @@

- Version 3.1.0 + Version 3.2.0

## Introduction diff --git a/package.json b/package.json index 08685e8..a59d876 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@sharkitek/core", - "version": "3.1.0", + "version": "3.2.0", "description": "TypeScript library for well-designed model architectures.", "keywords": [ "deserialization", diff --git a/src/Model/Model.ts b/src/Model/Model.ts index d38bdef..dc7d63c 100644 --- a/src/Model/Model.ts +++ b/src/Model/Model.ts @@ -54,6 +54,11 @@ export type ModelClass = Shape[K]["_sharkitek"]; +/** + * Identifier name type. + */ +export type IdentifierNameType = Shape extends ModelShape ? keyof Shape : unknown; + /** * Interface of a Sharkitek model definition. */ @@ -64,6 +69,11 @@ export interface ModelDefinition; + /** * Serialize the model. */ @@ -103,7 +113,7 @@ export interface ModelDefinition>, Shape extends ModelShape, Identifier extends keyof Shape = any>( +export function model>, Shape extends ModelShape, Identifier extends IdentifierNameType = any>( shape: Shape, identifier?: Identifier, ): ModelClass @@ -160,6 +170,11 @@ export function model)?.[identifier]; } + getIdentifierName(): IdentifierNameType + { + return identifier; + } + serialize(): SerializedModel { // Creating an empty (=> partial) serialized object.