diff --git a/generators/base-application/generator.ts b/generators/base-application/generator.ts index 45d80f685e8f..8dc395802a75 100644 --- a/generators/base-application/generator.ts +++ b/generators/base-application/generator.ts @@ -30,7 +30,6 @@ import { GENERATOR_BOOTSTRAP_APPLICATION_SERVER, } from '../generator-list.js'; import type { TaskTypes as DefaultTaskTypes } from '../../lib/types/application/tasks.js'; -import type { ApplicationType } from '../../lib/types/application/application.js'; import type { Entity } from '../../lib/types/application/entity.js'; import type { GenericTaskGroup } from '../../lib/types/base/tasks.js'; import type { ApplicationConfiguration } from '../../lib/types/application/yo-rc.js'; @@ -94,7 +93,7 @@ export default class BaseApplicationGenerator< static POST_WRITING_ENTITIES = asPriority(POST_WRITING_ENTITIES); declare jhipsterConfig: ApplicationConfiguration & Record; - declare sharedData: SharedData; + declare sharedData: SharedData; constructor(args: string | string[], options: JHipsterGeneratorOptions, features: JHipsterGeneratorFeatures) { super(args, options, features); diff --git a/generators/base-core/generator.ts b/generators/base-core/generator.ts index f450912d6a85..908490bedb37 100644 --- a/generators/base-core/generator.ts +++ b/generators/base-core/generator.ts @@ -1390,7 +1390,7 @@ templates: ${JSON.stringify(existingTemplates, null, 2)}`; return this.options.sharedData.applications?.[this.calculateApplicationId(applicationFolder)]; } - private createSharedData({ help }: { help?: boolean }): SharedData { + private createSharedData({ help }: { help?: boolean }): SharedData { const applicationId = this.options.applicationId ?? this.calculateApplicationId(this.destinationPath()); if (this.options.sharedData.applications === undefined) { this.options.sharedData.applications = {}; @@ -1401,7 +1401,7 @@ templates: ${JSON.stringify(existingTemplates, null, 2)}`; } const { ignoreNeedlesError } = this.options; - return new SharedData( + return new SharedData( sharedApplications[applicationId], { destinationPath: this.destinationPath(), memFs: this.env.sharedFs, log: this.log, logCwd: this.env.logCwd }, { ignoreNeedlesError }, diff --git a/generators/base/shared-data.ts b/generators/base/shared-data.ts index a7dcc28fd244..ac95dd54066a 100644 --- a/generators/base/shared-data.ts +++ b/generators/base/shared-data.ts @@ -24,11 +24,13 @@ import { lt as semverLessThan } from 'semver'; import { defaults } from 'lodash-es'; import type { MemFsEditor } from 'mem-fs-editor'; import { create } from 'mem-fs-editor'; -import { type BaseApplication } from '../base-application/types.js'; import { GENERATOR_JHIPSTER } from '../generator-constants.js'; +import type { ApplicationType } from '../../lib/types/application/application.js'; +import type { Entity } from '../../lib/types/application/entity.js'; +import type { Entity as BaseEntity } from '../../lib/types/base/entity.js'; import type { CleanupArgumentType, Control } from './types.js'; -export default class SharedData { +export default class SharedData { _storage: any; _editor: MemFsEditor; _log: any; @@ -145,20 +147,20 @@ export default class SharedData): void { this._storage.sharedEntities[entityName] = entity; } - hasEntity(entityName) { + hasEntity(entityName): boolean { return Boolean(this._storage.sharedEntities[entityName]); } - getEntity(entityName) { + getEntity(entityName): EntityType { const entity = this._storage.sharedEntities[entityName]; if (!entity) { throw new Error(`Entity definition not loaded for ${entityName}`); @@ -166,11 +168,11 @@ export default class SharedData ({ entityName, entity: this.getEntity(entityName) })); } - getEntitiesMap() { + getEntitiesMap(): Record { return this._storage.sharedEntities; } } diff --git a/generators/bootstrap-application-base/generator.ts b/generators/bootstrap-application-base/generator.ts index 50d6deb5e842..cd0d59f339fa 100644 --- a/generators/bootstrap-application-base/generator.ts +++ b/generators/bootstrap-application-base/generator.ts @@ -239,11 +239,11 @@ export default class BootstrapApplicationBase extends BaseApplicationGenerator { } if (entityConfig.changelogDate) { - entityConfig.annotations.changelogDate = entityConfig.changelogDate; + entityConfig.annotations!.changelogDate = entityConfig.changelogDate; delete entityConfig.changelogDate; } - if (!entityConfig.annotations.changelogDate) { - entityConfig.annotations.changelogDate = this.dateFormatForLiquibase(); + if (!entityConfig.annotations!.changelogDate) { + entityConfig.annotations!.changelogDate = this.dateFormatForLiquibase(); entityStorage.save(); } }, @@ -359,6 +359,17 @@ export default class BootstrapApplicationBase extends BaseApplicationGenerator { this.validateResult(loadEntitiesOtherSide(entities, { application })); for (const entity of entities) { + if (!entity.builtIn) { + const invalidRelationship = entity.relationships.find( + ({ otherEntity }) => !otherEntity.builtIn && entity.microserviceName !== otherEntity.microserviceName, + ); + if (invalidRelationship) { + throw new Error( + `Microservice entities cannot have relationships with entities from other microservice: '${entity.name}.${invalidRelationship.relationshipName}'`, + ); + } + } + for (const field of entity.fields) { if (isFieldBinaryType(field)) { if (isFieldBlobType(field)) { diff --git a/lib/types/base/entity.d.ts b/lib/types/base/entity.d.ts index c4c816a0d149..2b3d8079bdec 100644 --- a/lib/types/base/entity.d.ts +++ b/lib/types/base/entity.d.ts @@ -13,6 +13,7 @@ export type Entity; readOnly?: boolean; embedded?: boolean;