Browse Source

fix: enum types

e22m4u 3 months ago
parent
commit
bf87bd245c

+ 13 - 8
src/definition/model/properties/data-type.d.ts

@@ -1,11 +1,16 @@
 /**
  * Data type.
  */
-export declare enum DataType {
-  ANY = 'any',
-  STRING = 'string',
-  NUMBER = 'number',
-  BOOLEAN = 'boolean',
-  ARRAY = 'array',
-  OBJECT = 'object',
-}
+export declare const DataType: {
+  ANY: 'any';
+  STRING: 'string';
+  NUMBER: 'number';
+  BOOLEAN: 'boolean';
+  ARRAY: 'array';
+  OBJECT: 'object';
+};
+
+/**
+ * Type of DataType.
+ */
+export type DataType = (typeof DataType)[keyof typeof DataType];

+ 3 - 3
src/definition/model/properties/property-definition.d.ts

@@ -7,8 +7,8 @@ import {PropertyTransformOptions} from './property-transformer/index.js';
  * Full property definition.
  */
 export declare type FullPropertyDefinition = {
-  type: `${DataType}`;
-  itemType?: `${DataType}`;
+  type: DataType;
+  itemType?: DataType;
   itemModel?: string;
   model?: string;
   primaryKey?: boolean;
@@ -18,7 +18,7 @@ export declare type FullPropertyDefinition = {
   default?: unknown;
   validate?: PropertyValidateOptions;
   transform?: PropertyTransformOptions;
-  unique?: boolean | `${PropertyUniqueness}`;
+  unique?: boolean | PropertyUniqueness;
 };
 
 /**

+ 11 - 5
src/definition/model/properties/property-uniqueness.d.ts

@@ -1,8 +1,14 @@
 /**
  * Property uniqueness.
  */
-export declare enum PropertyUniqueness {
-  STRICT = 'strict',
-  SPARSE = 'sparse',
-  NON_UNIQUE = 'nonUnique',
-}
+export declare const PropertyUniqueness: {
+  STRICT: 'strict';
+  SPARSE: 'sparse';
+  NON_UNIQUE: 'nonUnique';
+};
+
+/**
+ * Type of PropertyUniqueness.
+ */
+export type PropertyUniqueness =
+  (typeof PropertyUniqueness)[keyof typeof PropertyUniqueness];

+ 9 - 9
src/definition/model/relations/relation-definition.d.ts

@@ -50,7 +50,7 @@ export declare type RelationDefinition =
  * ```
  */
 export declare type BelongsToDefinition = {
-  type: `${RelationType.BELONGS_TO}`;
+  type: typeof RelationType.BELONGS_TO;
   polymorphic?: false;
   model: string;
   foreignKey?: string;
@@ -78,7 +78,7 @@ export declare type BelongsToDefinition = {
  * ```
  */
 export declare type PolyBelongsToDefinition = {
-  type: `${RelationType.BELONGS_TO}`;
+  type: typeof RelationType.BELONGS_TO;
   polymorphic: true;
   foreignKey?: string;
   discriminator?: string;
@@ -97,7 +97,7 @@ export declare type PolyBelongsToDefinition = {
  * ```
  */
 export declare type HasOneDefinition = {
-  type: `${RelationType.HAS_ONE}`;
+  type: typeof RelationType.HAS_ONE;
   model: string;
   foreignKey: string;
   polymorphic?: false;
@@ -117,7 +117,7 @@ export declare type HasOneDefinition = {
  * ```
  */
 export declare type PolyHasOneDefinitionWithTargetRelationName = {
-  type: `${RelationType.HAS_ONE}`;
+  type: typeof RelationType.HAS_ONE;
   model: string;
   polymorphic: string;
   foreignKey?: undefined;
@@ -139,7 +139,7 @@ export declare type PolyHasOneDefinitionWithTargetRelationName = {
  * ```
  */
 export declare type PolyHasOneDefinitionWithTargetKeys = {
-  type: `${RelationType.HAS_ONE}`;
+  type: typeof RelationType.HAS_ONE;
   model: string;
   polymorphic: true;
   foreignKey: string;
@@ -159,7 +159,7 @@ export declare type PolyHasOneDefinitionWithTargetKeys = {
  * ```
  */
 export declare type HasManyDefinition = {
-  type: `${RelationType.HAS_MANY}`;
+  type: typeof RelationType.HAS_MANY;
   model: string;
   foreignKey: string;
   polymorphic?: false;
@@ -179,7 +179,7 @@ export declare type HasManyDefinition = {
  * ```
  */
 export declare type PolyHasManyDefinitionWithTargetRelationName = {
-  type: `${RelationType.HAS_MANY}`;
+  type: typeof RelationType.HAS_MANY;
   model: string;
   polymorphic: string;
   foreignKey?: undefined;
@@ -201,7 +201,7 @@ export declare type PolyHasManyDefinitionWithTargetRelationName = {
  * ```
  */
 export declare type PolyHasManyDefinitionWithTargetKeys = {
-  type: `${RelationType.HAS_MANY}`;
+  type: typeof RelationType.HAS_MANY;
   model: string;
   polymorphic: true;
   foreignKey: string;
@@ -229,7 +229,7 @@ export declare type PolyHasManyDefinitionWithTargetKeys = {
  * ```
  */
 export declare type ReferencesManyDefinition = {
-  type: `${RelationType.REFERENCES_MANY}`;
+  type: typeof RelationType.REFERENCES_MANY;
   model: string;
   foreignKey?: string;
   discriminator?: undefined;

+ 11 - 6
src/definition/model/relations/relation-type.d.ts

@@ -1,9 +1,14 @@
 /**
  * Relation type.
  */
-export declare enum RelationType {
-  BELONGS_TO = 'belongsTo',
-  HAS_ONE = 'hasOne',
-  HAS_MANY = 'hasMany',
-  REFERENCES_MANY = 'referencesMany',
-}
+export declare const RelationType: {
+  BELONGS_TO: 'belongsTo';
+  HAS_ONE: 'hasOne';
+  HAS_MANY: 'hasMany';
+  REFERENCES_MANY: 'referencesMany';
+};
+
+/**
+ * Type of RelationType.
+ */
+export type RelationType = (typeof RelationType)[keyof typeof RelationType];