From 5115f718eccb32554b4e8ba0a44160f1d44ee75d Mon Sep 17 00:00:00 2001 From: Charlie Mordant Date: Sun, 3 Aug 2025 15:45:47 +0200 Subject: [PATCH] update prepare entity with base-application type --- .../support/prepare-entity.spec.ts | 4 +- .../support/prepare-entity.ts | 13 +++-- .../base-application/support/prepare-field.ts | 4 +- generators/base-application/types.d.ts | 33 ++++++++++++ generators/java/types.d.ts | 1 - generators/liquibase/types.d.ts | 1 - generators/spring-boot/types.d.ts | 4 +- lib/types/application-all.d.ts | 50 ++----------------- 8 files changed, 48 insertions(+), 62 deletions(-) diff --git a/generators/base-application/support/prepare-entity.spec.ts b/generators/base-application/support/prepare-entity.spec.ts index 9c5a2294bb29..5753d9971cdb 100644 --- a/generators/base-application/support/prepare-entity.spec.ts +++ b/generators/base-application/support/prepare-entity.spec.ts @@ -21,8 +21,8 @@ import { beforeEach, describe, it } from 'esmocha'; import { expect } from 'chai'; -import type { EntityAll } from '../../../lib/types/application-all.d.ts'; import { formatDateForChangelog } from '../../base/support/index.ts'; +import type { Entity } from '../types.d.ts'; import { entityDefaultConfig, prepareEntityPrimaryKeyForTemplates } from './prepare-entity.ts'; @@ -71,7 +71,7 @@ describe('generator - base-application - support - prepareEntity', () => { { fieldName: 'id', fieldType: 'CustomType', path: ['id'] }, { fieldName: 'uuid', fieldType: 'UUID', id: true, path: ['uuid'] }, ], - } as unknown as EntityAll; + } as unknown as Entity; beforeEach(() => { entity = prepareEntityPrimaryKeyForTemplates({ entity }); }); diff --git a/generators/base-application/support/prepare-entity.ts b/generators/base-application/support/prepare-entity.ts index d70753b15e62..d4cb907c50bf 100644 --- a/generators/base-application/support/prepare-entity.ts +++ b/generators/base-application/support/prepare-entity.ts @@ -23,7 +23,6 @@ import { APPLICATION_TYPE_GATEWAY, APPLICATION_TYPE_MICROSERVICE } from '../../. import { binaryOptions } from '../../../lib/jdl/core/built-in-options/index.ts'; import type { FieldType } from '../../../lib/jhipster/field-types.ts'; import { databaseTypes, fieldTypes, searchEngineTypes } from '../../../lib/jhipster/index.ts'; -import type { EntityAll, FieldAll } from '../../../lib/types/application-all.d.ts'; import { getMicroserviceAppName, mutateData, normalizePathEnd, stringHashCode, upperFirstCamelCase } from '../../../lib/utils/index.ts'; import { parseChangelog } from '../../base/support/timestamp.ts'; import type CoreGenerator from '../../base-core/generator.js'; @@ -36,7 +35,7 @@ import { getDatabaseTypeData, hibernateSnakeCase } from '../../server/support/in import type { Entity as ServerEntity } from '../../server/types.ts'; import type { Config as SpringBootConfig } from '../../spring-boot/types.ts'; import type { Config as SpringDataRelationalConfig } from '../../spring-data-relational/types.ts'; -import type { PrimaryKey } from '../types.js'; +import type { Entity, Field, PrimaryKey, Relationship } from '../types.ts'; import { createFaker } from './faker.ts'; import { fieldIsEnum } from './field-utils.ts'; @@ -278,7 +277,7 @@ export function prepareEntityPrimaryKeyForTemplates( entity: entityWithConfig, enableCompositeId = true, application, - }: { entity: EntityAll; enableCompositeId?: boolean; application?: any }, + }: { entity: Entity; enableCompositeId?: boolean; application?: any }, ) { const idFields = entityWithConfig.fields.filter(field => field.id); const idRelationships = entityWithConfig.relationships.filter(relationship => relationship.id); @@ -301,7 +300,7 @@ export function prepareEntityPrimaryKeyForTemplates( fieldNameHumanized: 'ID', fieldTranslationKey: 'global.field.id', autoGenerate: true, - } as FieldAll; + } as Field; entityWithConfig.fields.unshift(idField); } idFields.push(idField); @@ -440,7 +439,7 @@ export function prepareEntityPrimaryKeyForTemplates( return entityWithConfig; } -function fieldToId(field: FieldAll): any { +function fieldToId(field: Field): any { return { field, get name() { @@ -542,10 +541,10 @@ export function preparePostEntityCommonDerivedProperties(entity: CommonEntity) { entity.anyFieldHasTextContentType = blobFieldsContentType.includes(TEXT); } - preparePostEntityCommonDerivedPropertiesNotTyped(entity as EntityAll); + preparePostEntityCommonDerivedPropertiesNotTyped(entity as Entity); } -function preparePostEntityCommonDerivedPropertiesNotTyped(entity: EntityAll) { +function preparePostEntityCommonDerivedPropertiesNotTyped(entity: Entity) { const { relationships, fields } = entity; const oneToOneRelationships = relationships.filter(({ relationshipType }) => relationshipType === 'one-to-one'); entity.fieldsContainNoOwnerOneToOne = oneToOneRelationships.some(({ ownerSide }) => !ownerSide); diff --git a/generators/base-application/support/prepare-field.ts b/generators/base-application/support/prepare-field.ts index 8df4335b1a23..55d65eb7df8c 100644 --- a/generators/base-application/support/prepare-field.ts +++ b/generators/base-application/support/prepare-field.ts @@ -24,8 +24,8 @@ import { applyDerivedPropertyOnly, mutateData } from '../../../lib/utils/index.t import type CoreGenerator from '../../base-core/generator.js'; import { getTypescriptType } from '../../client/support/index.ts'; import type { Entity as CommonEntity, Field as CommonField } from '../../common/types.d.ts'; -import type { DatabaseProperty } from '../../liquibase/types.js'; import { isFieldEnumType } from '../internal/types/field-types.ts'; +import type { Field } from '../types.js'; import type { FakerWithRandexp } from './faker.js'; import { prepareProperty } from './prepare-property.ts'; @@ -195,7 +195,7 @@ function generateFakeDataForField( } else if (field.fieldTypeBinary && field.fieldTypeBlobContent === TEXT) { data = '../fake-data/blob/hipster.txt'; } else if (field.fieldType === STRING) { - data = field.id ? faker.string.uuid() : faker.helpers.fake(fakeStringTemplateForFieldName((field as DatabaseProperty).columnName!)); + data = field.id ? faker.string.uuid() : faker.helpers.fake(fakeStringTemplateForFieldName((field as Field).columnName!)); } else if (field.fieldType === UUID) { data = faker.string.uuid(); } else if (field.fieldType === BOOLEAN) { diff --git a/generators/base-application/types.d.ts b/generators/base-application/types.d.ts index 216d2e9a9505..3d7cb4feef0a 100644 --- a/generators/base-application/types.d.ts +++ b/generators/base-application/types.d.ts @@ -31,6 +31,7 @@ type Property = { skipClient?: boolean; skipServer?: boolean; + columnName?: string; }; export type Field = Property & @@ -85,6 +86,8 @@ export type Field = Property & fieldTypeBytes?: boolean; // Derived properties + dynamic?: boolean; + derivedPath?: string[]; fieldTypeBinary?: boolean; fieldTypeDuration?: boolean; fieldTypeLocalDate?: boolean; @@ -109,6 +112,7 @@ export type Field = Property & enumInstance?: string; builtIn?: boolean; + requiresPersistableImplementation?: boolean; }; export type DerivedField = F & { @@ -125,6 +129,13 @@ export interface Relationship extends Property, BaseRelationship, DerivedPropertiesOnlyOf<'relationship', 'LeftSide' | 'RightSide' | 'ManyToOne' | 'OneToMany' | 'OneToOne' | 'ManyToMany'> { + derivedPrimaryKey?: { + derivedFields: (Field & { + originalField: Field; + derived: boolean; + })[]; + }; + relationshipNameCapitalized: string; otherRelationship: this; collection: boolean; @@ -149,6 +160,7 @@ export interface Relationship relationshipValidate?: boolean; relationshipValidateRules?: string[]; + bagRelationship?: boolean; } /** @@ -205,6 +217,7 @@ export interface Entity>, 'relationships'> { relationships: RelationshipWithEntity[]; otherRelationships: R[]; + entityClass: string; primaryKey?: PrimaryKey; @@ -277,6 +290,26 @@ export interface Entity[]>; + differentRelationships?: Record[]>; + otherEntities?: this[]; + persistableRelationships?: RelationshipWithEntity[]; + otherEntitiesWithPersistableRelationship?: this[]; + updatableEntity?: boolean; + entityContainsCollectionField?: boolean; + requiresPersistableImplementation?: boolean; + otherEntityPrimaryKeyTypes?: string[]; + otherEntityPrimaryKeyTypesIncludesUUID?: boolean; + eagerLoad?: boolean; + relationshipsContainEagerLoad?: boolean; + containsBagRelationships?: boolean; + implementsEagerLoadApis?: boolean; + eagerRelations?: RelationshipWithEntity[]; + regularEagerRelations?: RelationshipWithEntity[]; + reactiveEagerRelations: RelationshipWithEntity[]; + reactiveRegularEagerRelations?: RelationshipWithEntity[]; } /* ApplicationType Start */ diff --git a/generators/java/types.d.ts b/generators/java/types.d.ts index 3417f988cbcf..dca1543bb7be 100644 --- a/generators/java/types.d.ts +++ b/generators/java/types.d.ts @@ -75,7 +75,6 @@ export interface Entity[]; reactiveOtherEntities: Set; reactiveUniqueEntityTypes: Set; diff --git a/lib/types/application-all.d.ts b/lib/types/application-all.d.ts index 97fd504ce1ff..660959237bc4 100644 --- a/lib/types/application-all.d.ts +++ b/lib/types/application-all.d.ts @@ -17,11 +17,7 @@ * limitations under the License. */ import type { Entity as AngularEntity } from '../../generators/angular/types.d.ts'; -import type { - Application as BaseApplication, - Entity as BaseApplicationEntity, - RelationshipWithEntity, -} from '../../generators/base-application/types.d.ts'; +import type { Application as BaseApplication, Entity as BaseApplicationEntity } from '../../generators/base-application/types.d.ts'; import type { Application as ClientApplication, Field as ClientField } from '../../generators/client/types.d.ts'; import type { Application as DockerApplication } from '../../generators/docker/types.d.ts'; import type { Application as GitApplication } from '../../generators/git/types.d.ts'; @@ -45,54 +41,16 @@ import type { Relationship as SpringDataRelationalRelationship, } from '../../generators/spring-data-relational/types.d.ts'; -export type FieldAll = SpringDataRelationalField & - LiquibaseField & - ClientField & { - derivedPath?: string[]; - dynamic?: boolean; - }; +export type FieldAll = SpringDataRelationalField & LiquibaseField & ClientField & {}; -export interface RelationshipAll extends SpringDataRelationalRelationship, ServerRelationship, LiquibaseRelationship { - bagRelationship?: boolean; - derivedPrimaryKey?: { - derivedFields: (FieldAll & { - originalField: FieldAll; - derived: boolean; - })[]; - }; -} +export interface RelationshipAll extends SpringDataRelationalRelationship, ServerRelationship, LiquibaseRelationship {} export interface EntityAll extends BaseApplicationEntity, AngularEntity, LiquibaseEntity, SpringDataRelationalEntity, - SpringBootEntity { - updatableEntity?: boolean; - eagerLoad?: boolean; - implementsEagerLoadApis?: boolean; - requiresPersistableImplementation?: boolean; - - fieldsContainNoOwnerOneToOne?: boolean; - anyPropertyHasValidation?: boolean; - entityContainsCollectionField?: boolean; - relationshipsContainEagerLoad?: boolean; - containsBagRelationships?: boolean; - - otherEntityPrimaryKeyTypes?: string[]; - otherEntityPrimaryKeyTypesIncludesUUID?: boolean; - - otherEntities?: this[]; - otherEntitiesWithPersistableRelationship?: this[]; - - regularEagerRelations?: RelationshipWithEntity[]; - eagerRelations?: RelationshipWithEntity[]; - reactiveRegularEagerRelations?: RelationshipWithEntity[]; - persistableRelationships?: RelationshipWithEntity[]; - - relationshipsByOtherEntity?: Record[]>; - differentRelationships?: Record[]>; -} + SpringBootEntity {} export interface UserEntity extends EntityAll { hasImageField?: boolean;