From be9d8925bf32cfbeb5fa04abd9d472596ac77d09 Mon Sep 17 00:00:00 2001 From: CatsMiaow Date: Thu, 20 Feb 2020 13:26:47 +0900 Subject: [PATCH] Fix type NamingStrategy --- src/ModelCustomization.ts | 17 +++++------------ src/NamingStrategy.ts | 12 ++++++++---- 2 files changed, 13 insertions(+), 16 deletions(-) diff --git a/src/ModelCustomization.ts b/src/ModelCustomization.ts index 46f80d0..75f2b50 100644 --- a/src/ModelCustomization.ts +++ b/src/ModelCustomization.ts @@ -4,20 +4,13 @@ import { Entity } from "./models/Entity"; import IGenerationOptions from "./IGenerationOptions"; import * as NamingStrategy from "./NamingStrategy"; import * as TomgUtils from "./Utils"; -import { Relation } from "./models/Relation"; -import { RelationId } from "./models/RelationId"; -import { Column } from "./models/Column"; type NamingStrategy = { - enablePluralization: (value: boolean) => void; - relationIdName: ( - relationId: RelationId, - relation: Relation, - owner: Entity - ) => string; - relationName: (relation: Relation, owner: Entity) => string; - columnName: (columnName: string, column?: Column) => string; - entityName: (entityName: string, entity?: Entity) => string; + enablePluralization: typeof NamingStrategy.enablePluralization; + relationIdName: typeof NamingStrategy.relationIdName; + relationName: typeof NamingStrategy.relationName; + columnName: typeof NamingStrategy.columnName; + entityName: typeof NamingStrategy.entityName; }; export default function modelCustomizationPhase( diff --git a/src/NamingStrategy.ts b/src/NamingStrategy.ts index 4836377..e9edbba 100644 --- a/src/NamingStrategy.ts +++ b/src/NamingStrategy.ts @@ -1,7 +1,10 @@ +/* eslint-disable @typescript-eslint/no-unused-vars */ import { plural } from "pluralize"; import * as changeCase from "change-case"; import { Relation } from "./models/Relation"; import { RelationId } from "./models/RelationId"; +import { Entity } from "./models/Entity"; +import { Column } from "./models/Column"; let pluralize: boolean; @@ -11,7 +14,8 @@ export function enablePluralization(value: boolean) { export function relationIdName( relationId: RelationId, - relation: Relation + relation: Relation, + owner?: Entity ): string { const columnOldName = relationId.fieldName; @@ -35,7 +39,7 @@ export function relationIdName( return newColumnName; } -export function relationName(relation: Relation): string { +export function relationName(relation: Relation, owner?: Entity): string { const columnOldName = relation.fieldName; const isRelationToMany = @@ -66,10 +70,10 @@ export function relationName(relation: Relation): string { return newColumnName; } -export function entityName(oldEntityName: string): string { +export function entityName(oldEntityName: string, entity?: Entity): string { return oldEntityName; } -export function columnName(oldColumnName: string): string { +export function columnName(oldColumnName: string, column?: Column): string { return oldColumnName; }