diff --git a/generators/angular/cleanup.ts b/generators/angular/cleanup.ts index 336944999a31..30e1a7a99c80 100644 --- a/generators/angular/cleanup.ts +++ b/generators/angular/cleanup.ts @@ -17,16 +17,15 @@ * limitations under the License. */ -import type CoreGenerator from '../base-core/index.js'; +import { asWritingTask } from '../base-application/support/task-type-inference.js'; import { CLIENT_WEBPACK_DIR } from '../generator-constants.js'; -import type { GeneratorDefinition } from '../base-application/generator.js'; /** * Removes files that where generated in previous JHipster versions and therefore * need to be removed. */ -export default function cleanupOldFilesTask(this: CoreGenerator, { application }: GeneratorDefinition['writingTaskParam']) { +export default asWritingTask(function cleanupOldFilesTask(this, { application }) { if (this.isJhipsterVersionLessThan('3.2.0')) { // removeFile and removeFolder methods should be called here for files and folders to cleanup this.removeFile(`${application.clientSrcDir}app/components/form/uib-pager.config.js`); @@ -292,4 +291,4 @@ export default function cleanupOldFilesTask(this: CoreGenerator, { application } this.removeFile(`${application.clientSrcDir}app/entities/user/user.service.ts`); this.removeFile(`${application.clientSrcDir}app/entities/user/user.service.spec.ts`); } -} +}); diff --git a/generators/angular/entity-files-angular.ts b/generators/angular/entity-files-angular.ts index addf8f6c7491..48ae2dcabd21 100644 --- a/generators/angular/entity-files-angular.ts +++ b/generators/angular/entity-files-angular.ts @@ -16,11 +16,9 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import type { GeneratorDefinition } from '../base-application/generator.js'; import { clientApplicationTemplatesBlock } from '../client/support/files.js'; -import type CoreGenerator from '../base-core/index.js'; import type { WriteFileSection } from '../base/api.js'; -import { asWritingEntitiesTask } from '../base-application/support/index.js'; +import { asPostWritingEntitiesTask, asWritingEntitiesTask } from '../base-application/support/index.js'; const entityModelFiles = clientApplicationTemplatesBlock({ templates: ['entities/_entityFolder_/_entityFile_.model.ts', 'entities/_entityFolder_/_entityFile_.test-samples.ts'], @@ -95,10 +93,7 @@ export const userManagementFiles: WriteFileSection = { ], }; -export const writeEntitiesFiles = asWritingEntitiesTask(async function ( - this: CoreGenerator, - { control, application, entities }: GeneratorDefinition['writingEntitiesTaskParam'], -) { +export const writeEntitiesFiles = asWritingEntitiesTask(async function ({ control, application, entities }) { for (const entity of (control.filterEntitiesAndPropertiesForClient ?? (entities => entities))(entities)) { if (entity.builtInUser) { await this.writeFiles({ @@ -111,7 +106,7 @@ export const writeEntitiesFiles = asWritingEntitiesTask(async function ( }, }); - if (application.generateUserManagement && application.userManagement.skipClient) { + if (application.generateUserManagement && application.userManagement!.skipClient) { await this.writeFiles({ sections: userManagementFiles, context: { @@ -132,18 +127,15 @@ export const writeEntitiesFiles = asWritingEntitiesTask(async function ( } }); -export async function postWriteEntitiesFiles(this: CoreGenerator, taskParam: GeneratorDefinition['postWritingEntitiesTaskParam']) { - const { control, source, application } = taskParam; +export const postWriteEntitiesFiles = asPostWritingEntitiesTask(async function (this, taskParam) { + const { control, source } = taskParam; const entities = (control.filterEntitiesForClient ?? (entities => entities))(taskParam.entities).filter( entity => !entity.builtInUser && !entity.embedded && !entity.entityClientModelOnly, ); - source.addEntitiesToClient({ application, entities }); -} + source.addEntitiesToClient({ ...taskParam, entities }); +}); -export function cleanupEntitiesFiles( - this: CoreGenerator, - { control, application, entities }: GeneratorDefinition['writingEntitiesTaskParam'], -) { +export const cleanupEntitiesFiles = asWritingEntitiesTask(function ({ control, application, entities }) { for (const entity of (control.filterEntitiesForClient ?? (entities => entities))(entities).filter(entity => !entity.builtIn)) { const { entityFolderName, entityFileName, name: entityName } = entity; if (this.isJhipsterVersionLessThan('5.0.0')) { @@ -189,4 +181,4 @@ export function cleanupEntitiesFiles( this.removeFile(`${application.clientSrcDir}app/entities/${entityFolderName}/route/${entityFileName}-routing.module.ts`); } } -} +}); diff --git a/generators/angular/support/needles.ts b/generators/angular/support/needles.ts index 6fabcdde6e46..b13606868186 100644 --- a/generators/angular/support/needles.ts +++ b/generators/angular/support/needles.ts @@ -16,11 +16,12 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import type { Entity } from '../../base-application/index.js'; -import type { BaseApplication, CommonClientServerApplication } from '../../base-application/types.js'; +import type { Entity } from '../../../lib/types/application/entity.js'; +import type { BaseApplication } from '../../base-application/types.js'; import { createNeedleCallback } from '../../base/support/needles.js'; import { upperFirstCamelCase } from '../../../lib/utils/string.js'; import { joinCallbacks } from '../../base/support/write-files.js'; +import { asPostWritingEntitiesTask } from '../../base-application/support/task-type-inference.js'; export function addRoute({ needle, @@ -55,7 +56,7 @@ export function addRoute({ }); } -export function addEntitiesRoute({ application, entities }: { application: CommonClientServerApplication; entities: Entity[] }) { +export const addEntitiesRoute = asPostWritingEntitiesTask(function addEntitiesRoute({ application, entities }: { application; entities }) { const { enableTranslation } = application; return joinCallbacks( ...entities.map(entity => { @@ -72,7 +73,7 @@ export function addEntitiesRoute({ application, entities }: { application: Commo }); }), ); -} +}); type MenuItem = { jhiPrefix: string; diff --git a/generators/base-application/generator.ts b/generators/base-application/generator.ts index 4b2a388a481a..6c7ec2d5842c 100644 --- a/generators/base-application/generator.ts +++ b/generators/base-application/generator.ts @@ -21,10 +21,6 @@ import type { ComposeOptions, Storage } from 'yeoman-generator'; import BaseGenerator from '../base/index.js'; import { JHIPSTER_CONFIG_DIR } from '../generator-constants.js'; -import type { GenericSourceTypeDefinition, GenericTaskGroup } from '../base/tasks.js'; -import type { SpringBootSourceType } from '../server/types.js'; -import type { ClientSourceType } from '../client/types.js'; -import type { I18nApplication } from '../languages/types.js'; import type { JHipsterGeneratorFeatures, JHipsterGeneratorOptions } from '../base/api.js'; import { mutateData } from '../../lib/utils/object.js'; import { @@ -33,9 +29,11 @@ import { GENERATOR_BOOTSTRAP_APPLICATION_CLIENT, 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 { getEntitiesFromDir } from './support/index.js'; -import type { BaseApplication, CommonClientServerApplication } from './types.js'; -import type { BaseApplicationGeneratorDefinition, GenericApplicationDefinition } from './tasks.js'; import { CUSTOM_PRIORITIES, PRIORITY_NAMES, QUEUES } from './priorities.js'; const { @@ -71,24 +69,14 @@ const { const asPriority = BaseGenerator.asPriority; -export type BaseApplicationSource = Record any> & SpringBootSourceType & ClientSourceType & I18nApplication; - -export type JHipsterApplication = BaseApplication & Partial; - -export type GeneratorDefinition = BaseApplicationGeneratorDefinition< - GenericApplicationDefinition & GenericSourceTypeDefinition ->; - /** * This is the base class for a generator that generates entities. */ export default class BaseApplicationGenerator< - Definition extends BaseApplicationGeneratorDefinition<{ - applicationType: any; - entityType: any; - sourceType: any; - }> = GeneratorDefinition, -> extends BaseGenerator { + E = Entity, + A = ApplicationType, + TaskTypes extends DefaultTaskTypes = DefaultTaskTypes, +> extends BaseGenerator { static CONFIGURING_EACH_ENTITY = asPriority(CONFIGURING_EACH_ENTITY); static LOADING_ENTITIES = asPriority(LOADING_ENTITIES); @@ -218,118 +206,118 @@ export default class BaseApplicationGenerator< * * Configuring each entity should configure entities. */ - get configuringEachEntity(): GenericTaskGroup { - return this.asConfiguringEachEntityTaskGroup({}); + get configuringEachEntity() { + return {}; } - get preparingEachEntity(): GenericTaskGroup { - return this.asPreparingEachEntityTaskGroup({}); + get preparingEachEntity() { + return {}; } /** * Priority API stub for blueprints. */ - get preparingEachEntityField(): GenericTaskGroup { - return this.asPreparingEachEntityFieldTaskGroup({}); + get preparingEachEntityField() { + return {}; } /** * Priority API stub for blueprints. */ - get preparingEachEntityRelationship(): GenericTaskGroup { - return this.asPreparingEachEntityRelationshipTaskGroup({}); + get preparingEachEntityRelationship() { + return {}; } /** * Priority API stub for blueprints. */ - get postPreparingEachEntity(): GenericTaskGroup { - return this.asPostPreparingEachEntityTaskGroup({}); + get postPreparingEachEntity() { + return {}; } /** * Priority API stub for blueprints. */ - get writingEntities(): GenericTaskGroup { - return this.asWritingEntitiesTaskGroup({}); + get writingEntities() { + return {}; } /** * Priority API stub for blueprints. */ - get postWritingEntities(): GenericTaskGroup { - return this.asPostWritingEntitiesTaskGroup({}); + get postWritingEntities() { + return {}; } /** * Utility method to get typed objects for autocomplete. */ - asConfiguringEachEntityTaskGroup( - taskGroup: GenericTaskGroup, - ): GenericTaskGroup { + asConfiguringEachEntityTaskGroup( + taskGroup: GenericTaskGroup, + ): GenericTaskGroup { return taskGroup; } /** * Utility method to get typed objects for autocomplete. */ - asLoadingEntitiesTaskGroup( - taskGroup: GenericTaskGroup, - ): GenericTaskGroup { + asLoadingEntitiesTaskGroup( + taskGroup: GenericTaskGroup, + ): GenericTaskGroup { return taskGroup; } /** * Utility method to get typed objects for autocomplete. */ - asPreparingEachEntityTaskGroup( - taskGroup: GenericTaskGroup, - ): GenericTaskGroup { + asPreparingEachEntityTaskGroup( + taskGroup: GenericTaskGroup, + ): GenericTaskGroup { return taskGroup; } /** * Utility method to get typed objects for autocomplete. */ - asPreparingEachEntityFieldTaskGroup( - taskGroup: GenericTaskGroup, - ): GenericTaskGroup { + asPreparingEachEntityFieldTaskGroup( + taskGroup: GenericTaskGroup, + ): GenericTaskGroup { return taskGroup; } /** * Utility method to get typed objects for autocomplete. */ - asPreparingEachEntityRelationshipTaskGroup( - taskGroup: GenericTaskGroup, - ): GenericTaskGroup { + asPreparingEachEntityRelationshipTaskGroup( + taskGroup: GenericTaskGroup, + ): GenericTaskGroup { return taskGroup; } /** * Utility method to get typed objects for autocomplete. */ - asPostPreparingEachEntityTaskGroup( - taskGroup: GenericTaskGroup, - ): GenericTaskGroup { + asPostPreparingEachEntityTaskGroup( + taskGroup: GenericTaskGroup, + ): GenericTaskGroup { return taskGroup; } /** * Utility method to get typed objects for autocomplete. */ - asWritingEntitiesTaskGroup( - taskGroup: GenericTaskGroup, - ): GenericTaskGroup { + asWritingEntitiesTaskGroup( + taskGroup: GenericTaskGroup, + ): GenericTaskGroup { return taskGroup; } /** * Utility method to get typed objects for autocomplete. */ - asPostWritingEntitiesTaskGroup( - taskGroup: GenericTaskGroup, - ): GenericTaskGroup { + asPostWritingEntitiesTaskGroup( + taskGroup: GenericTaskGroup, + ): GenericTaskGroup { return taskGroup; } diff --git a/generators/base-application/index.ts b/generators/base-application/index.ts index 82dbddeb9ffa..c040c6bcb452 100644 --- a/generators/base-application/index.ts +++ b/generators/base-application/index.ts @@ -21,4 +21,4 @@ * Register generator-base at yeoman-environment */ export { default } from './generator.js'; -export type { BaseEntity, Entity, Field, Relationship } from './types/index.js'; +export type { Entity, Field, Relationship } from '../../lib/types/application/index.js'; diff --git a/generators/base-application/support/prepare-entity.ts b/generators/base-application/support/prepare-entity.ts index a074a4055e69..c7c8fccd8728 100644 --- a/generators/base-application/support/prepare-entity.ts +++ b/generators/base-application/support/prepare-entity.ts @@ -33,7 +33,7 @@ import { getEntityParentPathAddition, getTypescriptKeyType } from '../../client/ import { applicationTypes, databaseTypes, entityOptions, fieldTypes, searchEngineTypes } from '../../../jdl/jhipster/index.js'; import { binaryOptions } from '../../../jdl/built-in-options/index.js'; -import type { Entity } from '../types/index.js'; +import type { Entity } from '../../../lib/types/application/index.js'; import type CoreGenerator from '../../base-core/generator.js'; import { fieldIsEnum } from './field-utils.js'; import { fieldToReference } from './prepare-field.js'; diff --git a/generators/base-application/support/task-type-inference.ts b/generators/base-application/support/task-type-inference.ts index 4340ae35208c..be5cbdac503b 100644 --- a/generators/base-application/support/task-type-inference.ts +++ b/generators/base-application/support/task-type-inference.ts @@ -14,100 +14,124 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +import type { ApplicationType } from '../../../lib/types/application/application.js'; +import type { TaskTypes } from '../../../lib/types/application/tasks.js'; import type CoreGenerator from '../../base-core/generator.js'; import type { WriteFileBlock, WriteFileSection } from '../../base/api.js'; -import type { GeneratorDefinition } from '../generator.js'; +import type { Entity } from '../../../lib/types/application/entity.js'; -export function asWriteFilesSection( - section: WriteFileSection, -) { +export function asWriteFilesSection>(section: WriteFileSection) { return section; } -export function asWriteFilesBlock( - section: WriteFileBlock, -) { +export function asWriteFilesBlock>(section: WriteFileBlock) { return section; } -export function asInitializingTask(task: (this: CoreGenerator, params: GeneratorDefinition['initializingTaskParam']) => void) { +export function asInitializingTask>( + task: (this: CoreGenerator, params: TaskTypes['InitializingTaskParam']) => void, +) { return task; } -export function asPromptingTask(task: (this: CoreGenerator, params: GeneratorDefinition['promptingTaskParam']) => void) { +export function asPromptingTask>( + task: (this: CoreGenerator, params: TaskTypes['PromptingTaskParam']) => void, +) { return task; } -export function asConfiguringTask(task: (this: CoreGenerator, params: GeneratorDefinition['configuringTaskParam']) => void) { +export function asConfiguringTask>( + task: (this: CoreGenerator, params: TaskTypes['ConfiguringTaskParam']) => void, +) { return task; } -export function asComposingTask(task: (this: CoreGenerator, params: GeneratorDefinition['composingTaskParam']) => void) { +export function asComposingTask>( + task: (this: CoreGenerator, params: TaskTypes['ComposingTaskParam']) => void, +) { return task; } -export function asLoadingTask(task: (this: CoreGenerator, params: GeneratorDefinition['loadingTaskParam']) => void) { +export function asLoadingTask>( + task: (this: CoreGenerator, params: TaskTypes['LoadingTaskParam']) => void, +) { return task; } -export function asPreparingTask(task: (this: CoreGenerator, params: GeneratorDefinition['preparingTaskParam']) => void) { +export function asPreparingTask>( + task: (this: CoreGenerator, params: TaskTypes['PreparingTaskParam']) => void, +) { return task; } -export function asPostPreparingTask(task: (this: CoreGenerator, params: GeneratorDefinition['postPreparingTaskParam']) => void) { +export function asPostPreparingTask>( + task: (this: CoreGenerator, params: TaskTypes['PostPreparingTaskParam']) => void, +) { return task; } -export function asPreparingEachEntityTask( - task: (this: CoreGenerator, params: GeneratorDefinition['preparingEachEntityTaskParam']) => void, +export function asPreparingEachEntityTask>( + task: (this: CoreGenerator, params: TaskTypes['PreparingEachEntityTaskParam']) => void, ) { return task; } -export function asPreparingEachEntityFieldTask( - task: (this: CoreGenerator, params: GeneratorDefinition['preparingEachEntityFieldTaskParam']) => void, +export function asPreparingEachEntityFieldTask>( + task: (this: CoreGenerator, params: TaskTypes['PreparingEachEntityFieldTaskParam']) => void, ) { return task; } -export function asPreparingEachEntityRelationshipTask( - task: (this: CoreGenerator, params: GeneratorDefinition['preparingEachEntityRelationshipTaskParam']) => void, +export function asPreparingEachEntityRelationshipTask>( + task: (this: CoreGenerator, params: TaskTypes['PreparingEachEntityRelationshipTaskParam']) => void, ) { return task; } -export function asPostPreparingEachEntityTask( - task: (this: CoreGenerator, params: GeneratorDefinition['postPreparingEachEntityTaskParam']) => void, +export function asPostPreparingEachEntityTask>( + task: (this: CoreGenerator, params: TaskTypes['PostPreparingEachEntityTaskParam']) => void, ) { return task; } -export function asDefaultTask(task: (this: CoreGenerator, params: GeneratorDefinition['defaultTaskParam']) => void) { +export function asDefaultTask>( + task: (this: CoreGenerator, params: TaskTypes['DefaultTaskParam']) => void, +) { return task; } -export function asWritingTask(task: (this: CoreGenerator, params: GeneratorDefinition['writingTaskParam']) => void) { +export function asWritingTask>( + task: (this: CoreGenerator, params: TaskTypes['WritingTaskParam']) => void, +) { return task; } -export function asWritingEntitiesTask(task: (this: CoreGenerator, params: GeneratorDefinition['writingEntitiesTaskParam']) => void) { +export function asWritingEntitiesTask>( + task: (this: CoreGenerator, params: TaskTypes['WritingEntitiesTaskParam']) => void, +) { return task; } -export function asPostWritingTask(task: (this: CoreGenerator, params: GeneratorDefinition['postWritingTaskParam']) => void) { +export function asPostWritingTask>( + task: (this: CoreGenerator, params: TaskTypes['PostWritingTaskParam']) => void, +) { return task; } -export function asPostWritingEntitiesTask( - task: (this: CoreGenerator, params: GeneratorDefinition['postWritingEntitiesTaskParam']) => void, +export function asPostWritingEntitiesTask>( + task: (this: CoreGenerator, params: TaskTypes['PostWritingEntitiesTaskParam']) => void, ) { return task; } -export function asInstallTask(task: (this: CoreGenerator, params: GeneratorDefinition['installTaskParam']) => void) { +export function asInstallTask>( + task: (this: CoreGenerator, params: TaskTypes['InstallTaskParam']) => void, +) { return task; } -export function asEndTask(task: (this: CoreGenerator, params: GeneratorDefinition['endTaskParam']) => void) { +export function asEndTask>( + task: (this: CoreGenerator, params: TaskTypes['EndTaskParam']) => void, +) { return task; } diff --git a/generators/base-application/tasks.d.ts b/generators/base-application/tasks.d.ts deleted file mode 100644 index 1964b3344ee3..000000000000 --- a/generators/base-application/tasks.d.ts +++ /dev/null @@ -1,123 +0,0 @@ -import type { Storage } from 'yeoman-generator'; -import type { BaseGeneratorDefinition, ControlTaskParam, GenericSourceTypeDefinition, SourceTaskParam } from '../base/tasks.js'; -import type { ClientSourceType } from '../client/types.js'; -import type { BaseChangelog } from '../base-entity-changes/types.js'; -import type { CommonClientServerApplication } from './types.js'; -import type { Entity, Field, Relationship } from './types/index.js'; - -export type GenericApplicationDefinition = { - applicationType: ApplicationType; - entityType: Entity; -}; - -type ConfiguringEachEntityTaskParam = { - entityName: string; - /** Entity storage */ - entityStorage: Storage; - /** Proxy object for the entitystorage */ - entityConfig: Record; -}; - -type LoadingEntitiesTaskParam = { - entitiesToLoad: { - entityName: string; - /** Entity storage */ - entityStorage: Storage; - /** Proxy object for the entitystorage */ - entityConfig: Record; - /** Initial entity object */ - entityBootstrap: Record; - }[]; -}; - -type ApplicationTaskParam = { - application: Definition['applicationType'] & { user: Definition['entityType'] }; -}; - -type ApplicationDefaultsTaskParam = { - /** - * Parameter properties accepts: - * - functions: receives the application and the return value is set at the application property. - * - non functions: application property will receive the property in case current value is undefined. - * - * Applies each object in order. - * - * @example - * // application = { prop: 'foo-bar', prop2: 'foo2' } - * applicationDefaults( - * application, - * { prop: 'foo', prop2: ({ prop }) => prop + 2 }, - * { prop: ({ prop }) => prop + '-bar', prop2: 'won\'t override' }, - * ); - */ - applicationDefaults: (...defaults: Record[]) => void; -}; - -export type EntitiesTaskParam = { - entities: Definition['entityType'][]; -}; - -type EachEntityTaskParam = { - entity: Definition['entityType']; - entityName: string; - description: string; -}; - -type PreparingEachEntityFieldTaskParam = - EachEntityTaskParam & { - field: Field; - fieldName: string; - }; - -type PreparingEachEntityRelationshipTaskParam = - EachEntityTaskParam & { - relationship: Relationship; - relationshipName: string; - }; - -type ClientSource = { - addEntitiesToClient?: (param: ControlTaskParam & { source: ExtendsSelf } & EntitiesTaskParam) => any; -}; - -export type BaseApplicationGeneratorDefinition< - Definition extends { applicationType: any; entityType: any; sourceType: any } = GenericApplicationDefinition & - GenericSourceTypeDefinition any>>, -> = BaseGeneratorDefinition & - // Add application to existing priorities - Record<'loadingTaskParam' | 'preparingTaskParam', ApplicationTaskParam & ApplicationDefaultsTaskParam> & - Record< - | 'postPreparingTaskParam' - | 'defaultTaskParam' - | 'postWritingTaskParam' - | 'preConflictsTaskParam' - | 'installTaskParam' - | 'postInstallTaskParam' - | 'endTaskParam', - ApplicationTaskParam - > & - Record<'writingTaskParam', ApplicationTaskParam & { configChanges?: Record }> & - // Add entities to existing priorities - Record<'defaultTaskParam', EntitiesTaskParam & { entityChanges?: BaseChangelog[] }> & - // Add application and control to new priorities - Record< - | 'configuringEachEntityTaskParam' - | 'loadingEntitiesTaskParam' - | 'preparingEachEntityTaskParam' - | 'preparingEachEntityFieldTaskParam' - | 'preparingEachEntityRelationshipTaskParam' - | 'postPreparingEachEntityTaskParam' - | 'writingEntitiesTaskParam' - | 'postWritingEntitiesTaskParam', - ControlTaskParam & ApplicationTaskParam - > & { - // Add additional types to each priority - applicationType: Definition['applicationType']; - configuringEachEntityTaskParam: ConfiguringEachEntityTaskParam; - loadingEntitiesTaskParam: LoadingEntitiesTaskParam; - preparingEachEntityTaskParam: EachEntityTaskParam; - preparingEachEntityFieldTaskParam: PreparingEachEntityFieldTaskParam; - preparingEachEntityRelationshipTaskParam: PreparingEachEntityRelationshipTaskParam; - postPreparingEachEntityTaskParam: EachEntityTaskParam; - writingEntitiesTaskParam: EntitiesTaskParam & { entityChanges?: BaseChangelog[] }; - postWritingEntitiesTaskParam: SourceTaskParam & EntitiesTaskParam & { entityChanges?: BaseChangelog[] }; - }; diff --git a/generators/base-application/types.d.ts b/generators/base-application/types.d.ts index e60bc53a3663..ca0d5c8b02c0 100644 --- a/generators/base-application/types.d.ts +++ b/generators/base-application/types.d.ts @@ -2,7 +2,7 @@ import type CoreGenerator from '../base-core/generator.ts'; import type { ClientApplication } from '../client/types.js'; import type { I18nApplication } from '../languages/types.js'; import type { SpringBootApplication } from '../server/types.js'; -import type { DeterministicOptionWithDerivedProperties, OptionWithDerivedProperties } from './application-options.js'; +import type { OptionWithDerivedProperties } from './application-options.js'; export type BaseApplication = { jhipsterVersion: string; @@ -59,15 +59,23 @@ type GatewayApplication = MicroservicesArchitectureApplication & { microfrontends: string[]; }; +/* +Deterministic option causes types to be too complex type ApplicationType = DeterministicOptionWithDerivedProperties< 'applicationType', ['monolith', 'gateway', 'microservice'], [Record, GatewayApplication, MicroservicesArchitectureApplication] >; +*/ +type ApplicationProperties = OptionWithDerivedProperties<'applicationType', ['monolith', 'gateway', 'microservice']> & + GatewayApplication & + MicroservicesArchitectureApplication; /* ApplicationType End */ /* AuthenticationType Start */ +/* +Deterministic option causes types to be too complex type UserManagement = | { skipUserManagement: true; @@ -84,8 +92,17 @@ type UserManagement = generateBuiltInAuthorityEntity: boolean; authority: any; }; - -type JwtApplication = UserManagement & { + */ +type UserManagement = { + skipUserManagement: boolean; + generateUserManagement: boolean; + generateBuiltInUserEntity?: boolean; + generateBuiltInAuthorityEntity: boolean; + user: Entity; + userManagement: Entity; + authority: Entity; +}; +type JwtApplication = { jwtSecretKey: string; }; @@ -97,15 +114,23 @@ type Oauth2Application = { generateUserManagement: false; }; -type SessionApplication = UserManagement & { +type SessionApplication = { rememberMeKey: string; }; +/* +Deterministic option causes types to be too complex type AuthenticationType = DeterministicOptionWithDerivedProperties< 'authenticationType', ['jwt', 'oauth2', 'session'], [JwtApplication, Oauth2Application, SessionApplication] >; +*/ +type AuthenticationProperties = OptionWithDerivedProperties<'authenticationType', ['jwt', 'oauth2', 'session']> & + UserManagement & + JwtApplication & + Oauth2Application & + SessionApplication; /* AuthenticationType End */ @@ -113,12 +138,12 @@ type QuirksApplication = { cypressBootstrapEntities?: boolean; }; -export type CommonClientServerApplication = BaseApplication & +export type CommonClientServerApplication = BaseApplication & QuirksApplication & - AuthenticationType & + AuthenticationProperties & SpringBootApplication & ClientApplication & - ApplicationType & { + ApplicationProperties & { clientRootDir: string; clientSrcDir: string; clientTestDir?: string; diff --git a/generators/base-application/types/entity.d.ts b/generators/base-application/types/entity.d.ts deleted file mode 100644 index 5cb6e3413316..000000000000 --- a/generators/base-application/types/entity.d.ts +++ /dev/null @@ -1,139 +0,0 @@ -/** - * Copyright 2013-2024 the original author or authors from the JHipster project. - * - * This file is part of the JHipster project, see https://www.jhipster.tech/ - * for more information. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import type { SpringEntity } from '../../server/types.js'; -import type Field from './field.js'; -import type Relationship from './relationship.js'; - -export type BaseEntity = { - name: string; - changelogDate?: string; - dto?: string; - - primaryKey?: Record; - fields?: Field[]; - relationships?: Relationship[]; - - readOnly?: boolean; - embedded?: boolean; - skipClient?: boolean; - skipServer?: boolean; -}; - -type AngularEntity = { - entityAngularAuthorities?: string; - entityAngularReadAuthorities?: string; -}; - -type Entity = Required & - SpringEntity & - AngularEntity & { - builtIn?: boolean; - builtInUser?: boolean; - builtInAuthority?: boolean; - microserviceName?: string; - adminEntity?: boolean; - entityAuthority?: string; - entityReadAuthority?: string; - hasCyclicRequiredRelationship?: boolean; - - entityNameCapitalized: string; - entityClass: string; - entityInstance: string; - entityTableName: string; - entityNamePlural: string; - - dtoClass?: string; - dtoInstance?: string; - - persistClass: string; - persistInstance: string; - restClass: string; - restInstance: string; - - entityNamePluralizedAndSpinalCased: string; - entityClassPlural: string; - entityInstancePlural: string; - - entityI18nVariant: string; - entityClassHumanized: string; - entityClassPluralHumanized: string; - - entityFileName: string; - entityFolderName: string; - entityModelFileName: string; - entityParentPathAddition: string; - entityPluralFileName: string; - entityServiceFileName: string; - - /** Generate only the model at client side for relationships. */ - entityClientModelOnly?: boolean; - entityAngularName: string; - entityAngularNamePlural: string; - entityReactName: string; - - entityApiUrl: string; - entityStateName: string; - entityUrl: string; - - entityTranslationKey: string; - entityTranslationKeyMenu: string; - - i18nKeyPrefix: string; - i18nAlertHeaderPrefix: string; - - entityApi: string; - entityPage: string; - - anyFieldIsBigDecimal: boolean; - /** - * Any file is of type Bytes or ByteBuffer - */ - anyFieldIsBlobDerived: boolean; - /** - * Any field is of type ZonedDateTime, Instant or LocalDate - */ - anyFieldIsDateDerived: boolean; - anyFieldIsDuration: boolean; - anyFieldIsInstant: boolean; - anyFieldIsLocalDate: boolean; - /** - * Any field is of type ZonedDateTime or Instant - */ - anyFieldIsTimeDerived: boolean; - anyFieldIsUUID: boolean; - anyFieldIsZonedDateTime: boolean; - - anyFieldHasDocumentation: boolean; - anyFieldHasImageContentType: boolean; - anyFieldHasTextContentType: boolean; - /** - * Any field has image or any contentType - */ - anyFieldHasFileBasedContentType: boolean; - - /** - * Any relationship is required or id - */ - anyRelationshipIsRequired: boolean; - - dtoMapstruct: boolean; - }; - -export default Entity; diff --git a/generators/base-core/generator.ts b/generators/base-core/generator.ts index 6e272768eb7f..e87080fc83a2 100644 --- a/generators/base-core/generator.ts +++ b/generators/base-core/generator.ts @@ -66,6 +66,7 @@ import { getGradleLibsVersionsProperties } from '../gradle/support/dependabot-gr import { dockerPlaceholderGenerator } from '../docker/utils.js'; import { getConfigWithDefaults } from '../../jdl/jhipster/index.js'; import { extractArgumentsFromConfigs } from '../../lib/command/index.js'; +import type { Entity } from '../../lib/types/base/entity.js'; const { INITIALIZING, @@ -139,7 +140,7 @@ export default class CoreGenerator extends YeomanGenerator; + readonly sharedData!: SharedData>; readonly logger: Logger; jhipsterConfig!: Record; /** @@ -807,7 +808,7 @@ You can ignore this error by passing '--skip-checks' to jhipster command.`); /** * write the given files using provided options. */ - async writeFiles(options: WriteFileOptions): Promise { + async writeFiles(options: WriteFileOptions): Promise { const paramCount = Object.keys(options).filter(key => ['sections', 'blocks', 'templates'].includes(key)).length; assert(paramCount > 0, 'One of sections, blocks or templates is required'); assert(paramCount === 1, 'Only one of sections, blocks or templates must be provided'); diff --git a/generators/base-entity-changes/generator.ts b/generators/base-entity-changes/generator.ts index 1795e6c37e2f..6520d5569d0a 100644 --- a/generators/base-entity-changes/generator.ts +++ b/generators/base-entity-changes/generator.ts @@ -22,6 +22,9 @@ import { PRIORITY_NAMES } from '../base-application/priorities.js'; import { loadEntitiesAnnotations, loadEntitiesOtherSide } from '../base-application/support/index.js'; import { relationshipEquals, relationshipNeedsForeignKeyRecreationOnly } from '../liquibase/support/index.js'; import { addEntitiesOtherRelationships } from '../server/support/index.js'; +import type { TaskTypes as ApplicationTaskTypes } 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 { BaseChangelog } from './types.js'; const { DEFAULT, WRITING_ENTITIES, POST_WRITING_ENTITIES } = PRIORITY_NAMES; @@ -41,10 +44,20 @@ const baseChangelog: () => Omit = ApplicationTaskTypes & { + DefaultTaskParam: { entityChanges?: BaseChangelog[] }; + WritingEntitiesTaskParam: { entityChanges?: BaseChangelog[] }; + PostWritingEntitiesTaskParam: { entityChanges?: BaseChangelog[] }; +}; + /** * This is the base class for a generator for every generator. */ -export default abstract class GeneratorBaseEntityChanges extends GeneratorBaseApplication { +export default abstract class GeneratorBaseEntityChanges> extends GeneratorBaseApplication< + E, + A, + TaskTypes +> { recreateInitialChangelog!: boolean; private entityChanges!: any[]; diff --git a/generators/base-workspaces/generator.ts b/generators/base-workspaces/generator.ts index fb20bef03a14..119bf0a5255b 100644 --- a/generators/base-workspaces/generator.ts +++ b/generators/base-workspaces/generator.ts @@ -66,7 +66,8 @@ export default abstract class BaseWorkspacesGenerator extends BaseGenerator { } } - protected loadWorkspacesConfig({ context = this } = {}) { + protected loadWorkspacesConfig(opts?) { + const { context = this } = opts ?? {}; context.appsFolders = this.jhipsterConfig.appsFolders; context.directoryPath = this.jhipsterConfig.directoryPath ?? './'; } diff --git a/generators/base/api.d.ts b/generators/base/api.d.ts index abfc07841467..722bab16974e 100644 --- a/generators/base/api.d.ts +++ b/generators/base/api.d.ts @@ -1,5 +1,7 @@ import type { BaseFeatures, BaseOptions, CliOptionSpec } from 'yeoman-generator'; import type CoreGenerator from '../base-core/index.js'; +import type { ApplicationType } from '../../lib/types/application/application.js'; +import type { Entity } from '../../lib/types/application/entity.js'; type ConfigScope = 'storage' | 'blueprint' | 'control' | 'generator'; type CliSpecType = CliOptionSpec['type']; @@ -123,7 +125,7 @@ export type CascatedEditFileCallback = ( ...callbacks: EditFileCallback[] ) => CascatedEditFileCallback; -export type WriteFileTemplate = +export type WriteFileTemplate, Generator = CoreGenerator> = | string | ((this: Generator, data: DataType, filePath: string) => string) | { @@ -144,7 +146,7 @@ export type WriteFileTemplate = override?: boolean | ((this: Generator, data: DataType) => boolean); }; -export type WriteFileBlock = { +export type WriteFileBlock, Generator = CoreGenerator> = { /** relative path were sources are placed */ from?: ((this: Generator, data: DataType) => string) | string; /** relative path were the files should be written, fallbacks to from/path */ @@ -156,16 +158,19 @@ export type WriteFileBlock = { condition?: (this: Generator, data: DataType) => boolean | undefined; /** transforms (files processing) to be applied */ transform?: boolean | (() => string)[]; - templates: WriteFileTemplate[]; + templates: WriteFileTemplate[]; }; -export type WriteFileSection = Record[]>; +export type WriteFileSection, Generator = CoreGenerator> = Record< + string, + WriteFileBlock[] +>; -export type WriteFileOptions = { +export type WriteFileOptions, Generator = CoreGenerator> = { /** transforms (files processing) to be applied */ transform?: EditFileCallback[]; /** context to be used as template data */ - context?: DataType; + context?: any; /** config passed to render methods */ renderOptions?: Record; /** @@ -182,15 +187,15 @@ export type WriteFileOptions = { }) => undefined | { sourceFile: string; resolvedSourceFile: string; destinationFile: string }; } & ( | { - sections: WriteFileSection; + sections: WriteFileSection; } | { /** templates to be written */ - templates: WriteFileTemplate; + templates: WriteFileTemplate; } | { /** blocks to be written */ - blocks: WriteFileBlock[]; + blocks: WriteFileBlock[]; } ); diff --git a/generators/base/generator.ts b/generators/base/generator.ts index 7d514c775beb..fb39488e2c4c 100644 --- a/generators/base/generator.ts +++ b/generators/base/generator.ts @@ -25,19 +25,17 @@ import type { ComposeOptions } from 'yeoman-generator'; import { packageJson } from '../../lib/index.js'; import CoreGenerator from '../base-core/index.js'; import { loadStoredAppOptions } from '../app/support/index.js'; +import type { TaskTypes as BaseTaskTypes, GenericTaskGroup } from '../../lib/types/base/tasks.js'; import { packageNameToNamespace } from './support/index.js'; import { loadBlueprintsFromConfiguration, mergeBlueprints, normalizeBlueprintName, parseBluePrints } from './internal/index.js'; import { PRIORITY_NAMES } from './priorities.js'; -import type { BaseGeneratorDefinition, GenericTaskGroup } from './tasks.js'; import type { JHipsterGeneratorFeatures, JHipsterGeneratorOptions } from './api.js'; import { LOCAL_BLUEPRINT_PACKAGE_NAMESPACE } from './support/constants.js'; /** * Base class that contains blueprints support. */ -export default class JHipsterBaseBlueprintGenerator< - Definition extends BaseGeneratorDefinition = BaseGeneratorDefinition, -> extends CoreGenerator { +export default class JHipsterBaseBlueprintGenerator extends CoreGenerator { fromBlueprint!: boolean; sbsBlueprint?: boolean; delegateToBlueprint?: boolean; @@ -105,7 +103,7 @@ export default class JHipsterBaseBlueprintGenerator< * * Initializing priority is used to show logo and tasks related to preparing for prompts, like loading constants. */ - get initializing(): GenericTaskGroup { + get initializing() { return this.asInitializingTaskGroup(this._initializing()); } @@ -120,9 +118,9 @@ export default class JHipsterBaseBlueprintGenerator< /** * Utility method to get typed objects for autocomplete. */ - asInitializingTaskGroup( - taskGroup: GenericTaskGroup, - ): GenericTaskGroup { + asInitializingTaskGroup( + taskGroup: GenericTaskGroup, + ): GenericTaskGroup { return taskGroup; } @@ -131,8 +129,8 @@ export default class JHipsterBaseBlueprintGenerator< * * Prompting priority is used to prompt users for configuration values. */ - get prompting(): GenericTaskGroup { - return this.asPromptingTaskGroup(this._prompting()); + get prompting() { + return this._prompting(); } /** @@ -146,9 +144,9 @@ export default class JHipsterBaseBlueprintGenerator< /** * Utility method to get typed objects for autocomplete. */ - asPromptingTaskGroup( - taskGroup: GenericTaskGroup, - ): GenericTaskGroup { + asPromptingTaskGroup( + taskGroup: GenericTaskGroup, + ): GenericTaskGroup { return taskGroup; } @@ -157,8 +155,8 @@ export default class JHipsterBaseBlueprintGenerator< * * Configuring priority is used to customize and validate the configuration. */ - get configuring(): GenericTaskGroup { - return this.asConfiguringTaskGroup(this._configuring()); + get configuring() { + return this._configuring(); } /** @@ -172,9 +170,9 @@ export default class JHipsterBaseBlueprintGenerator< /** * Utility method to get typed objects for autocomplete. */ - asConfiguringTaskGroup( - taskGroup: GenericTaskGroup, - ): GenericTaskGroup { + asConfiguringTaskGroup( + taskGroup: GenericTaskGroup, + ): GenericTaskGroup { return taskGroup; } @@ -183,8 +181,8 @@ export default class JHipsterBaseBlueprintGenerator< * * Composing should be used to compose with others generators. */ - get composing(): GenericTaskGroup { - return this.asComposingTaskGroup(this._composing()); + get composing() { + return this._composing(); } /** @@ -198,9 +196,9 @@ export default class JHipsterBaseBlueprintGenerator< /** * Utility method to get typed objects for autocomplete. */ - asComposingTaskGroup( - taskGroup: GenericTaskGroup, - ): GenericTaskGroup { + asComposingTaskGroup( + taskGroup: GenericTaskGroup, + ): GenericTaskGroup { return taskGroup; } @@ -209,16 +207,16 @@ export default class JHipsterBaseBlueprintGenerator< * * ComposingComponent priority should be used to handle component configuration order. */ - get composingComponent(): GenericTaskGroup { + get composingComponent(): any { return {}; } /** * Utility method to get typed objects for autocomplete. */ - asComposingComponentTaskGroup( - taskGroup: GenericTaskGroup, - ): GenericTaskGroup { + asComposingComponentTaskGroup( + taskGroup: GenericTaskGroup, + ): GenericTaskGroup { return taskGroup; } @@ -228,7 +226,7 @@ export default class JHipsterBaseBlueprintGenerator< * Loading should be used to load application configuration from jhipster configuration. * Before this priority the configuration should be considered dirty, while each generator configures itself at configuring priority, another generator composed at composing priority can still change it. */ - get loading(): GenericTaskGroup { + get loading(): any { return this.asLoadingTaskGroup(this._loading()); } @@ -243,9 +241,9 @@ export default class JHipsterBaseBlueprintGenerator< /** * Utility method to get typed objects for autocomplete. */ - asLoadingTaskGroup( - taskGroup: GenericTaskGroup, - ): GenericTaskGroup { + asLoadingTaskGroup( + taskGroup: GenericTaskGroup, + ): GenericTaskGroup { return taskGroup; } @@ -254,8 +252,8 @@ export default class JHipsterBaseBlueprintGenerator< * * Preparing should be used to generate derived properties. */ - get preparing(): GenericTaskGroup { - return this.asPreparingTaskGroup(this._preparing()); + get preparing() { + return this._preparing(); } /** @@ -269,9 +267,9 @@ export default class JHipsterBaseBlueprintGenerator< /** * Utility method to get typed objects for autocomplete. */ - asPreparingTaskGroup( - taskGroup: GenericTaskGroup, - ): GenericTaskGroup { + asPreparingTaskGroup( + taskGroup: GenericTaskGroup, + ): GenericTaskGroup { return taskGroup; } @@ -280,16 +278,16 @@ export default class JHipsterBaseBlueprintGenerator< * * Preparing should be used to generate derived properties. */ - get postPreparing(): GenericTaskGroup { - return this.asPreparingTaskGroup({}); + get postPreparing() { + return {}; } /** * Utility method to get typed objects for autocomplete. */ - asPostPreparingTaskGroup( - taskGroup: GenericTaskGroup, - ): GenericTaskGroup { + asPostPreparingTaskGroup( + taskGroup: GenericTaskGroup, + ): GenericTaskGroup { return taskGroup; } @@ -298,8 +296,8 @@ export default class JHipsterBaseBlueprintGenerator< * * Default priority should used as misc customizations. */ - get default(): GenericTaskGroup { - return this.asDefaultTaskGroup(this._default()); + get default() { + return this._default(); } /** @@ -313,9 +311,9 @@ export default class JHipsterBaseBlueprintGenerator< /** * Utility method to get typed objects for autocomplete. */ - asDefaultTaskGroup( - taskGroup: GenericTaskGroup, - ): GenericTaskGroup { + asDefaultTaskGroup( + taskGroup: GenericTaskGroup, + ): GenericTaskGroup { return taskGroup; } @@ -324,8 +322,8 @@ export default class JHipsterBaseBlueprintGenerator< * * Writing priority should used to write files. */ - get writing(): GenericTaskGroup { - return this.asWritingTaskGroup(this._writing()); + get writing() { + return this._writing(); } /** @@ -339,9 +337,9 @@ export default class JHipsterBaseBlueprintGenerator< /** * Utility method to get typed objects for autocomplete. */ - asWritingTaskGroup( - taskGroup: GenericTaskGroup, - ): GenericTaskGroup { + asWritingTaskGroup( + taskGroup: GenericTaskGroup, + ): GenericTaskGroup { return taskGroup; } @@ -350,8 +348,8 @@ export default class JHipsterBaseBlueprintGenerator< * * PostWriting priority should used to customize files. */ - get postWriting(): GenericTaskGroup { - return this.asPostWritingTaskGroup(this._postWriting()); + get postWriting() { + return this._postWriting(); } /** @@ -365,9 +363,9 @@ export default class JHipsterBaseBlueprintGenerator< /** * Utility method to get typed objects for autocomplete. */ - asPostWritingTaskGroup( - taskGroup: GenericTaskGroup, - ): GenericTaskGroup { + asPostWritingTaskGroup( + taskGroup: GenericTaskGroup, + ): GenericTaskGroup { return taskGroup; } @@ -376,8 +374,8 @@ export default class JHipsterBaseBlueprintGenerator< * * Install priority should used to prepare the project. */ - get install(): GenericTaskGroup { - return this.asInstallTaskGroup(this._install()); + get install() { + return this._install(); } /** @@ -391,9 +389,9 @@ export default class JHipsterBaseBlueprintGenerator< /** * Utility method to get typed objects for autocomplete. */ - asInstallTaskGroup( - taskGroup: GenericTaskGroup, - ): GenericTaskGroup { + asInstallTaskGroup( + taskGroup: GenericTaskGroup, + ): GenericTaskGroup { return taskGroup; } @@ -402,8 +400,8 @@ export default class JHipsterBaseBlueprintGenerator< * * PostWriting priority should used to customize files. */ - get postInstall(): GenericTaskGroup { - return this.asPostInstallTaskGroup(this._postInstall()); + get postInstall() { + return this._postInstall(); } /** @@ -417,9 +415,9 @@ export default class JHipsterBaseBlueprintGenerator< /** * Utility method to get typed objects for autocomplete. */ - asPostInstallTaskGroup( - taskGroup: GenericTaskGroup, - ): GenericTaskGroup { + asPostInstallTaskGroup( + taskGroup: GenericTaskGroup, + ): GenericTaskGroup { return taskGroup; } @@ -428,8 +426,8 @@ export default class JHipsterBaseBlueprintGenerator< * * End priority should used to say good bye and print instructions. */ - get end(): GenericTaskGroup { - return this.asEndTaskGroup(this._end()); + get end() { + return this._end(); } /** @@ -443,7 +441,9 @@ export default class JHipsterBaseBlueprintGenerator< /** * Utility method to get typed objects for autocomplete. */ - asEndTaskGroup(taskGroup: GenericTaskGroup): GenericTaskGroup { + asEndTaskGroup( + taskGroup: GenericTaskGroup, + ): GenericTaskGroup { return taskGroup; } diff --git a/generators/base/tasks.d.ts b/generators/base/tasks.d.ts deleted file mode 100644 index 268b3c5989eb..000000000000 --- a/generators/base/tasks.d.ts +++ /dev/null @@ -1,32 +0,0 @@ -import type { Control } from './types.js'; - -export type ControlTaskParam = { - control: Control & Record; -}; - -export type GenericSourceTypeDefinition = { sourceType: SourceType }; - -export type SourceTaskParam = { - source: Definition['sourceType']; -}; - -export type GenericTask = (this: ThisType, arg1: Arg1Type) => unknown; - -export type GenericTaskGroup = Record>; - -export type BaseGeneratorDefinition = Record< - | 'initializingTaskParam' - | 'promptingTaskParam' - | 'configuringTaskParam' - | 'composingTaskParam' - | 'loadingTaskParam' - | 'defaultTaskParam' - | 'writingTaskParam' - | 'postWritingTaskParam' - | 'preConflictsTaskParam' - | 'installTaskParam' - | 'postInstallTaskParam' - | 'endTaskParam', - ControlTaskParam -> & - Record<'preparingTaskParam' | 'postPreparingTaskParam' | 'postWritingTaskParam', SourceTaskParam>; diff --git a/generators/bootstrap-application-server/generator.ts b/generators/bootstrap-application-server/generator.ts index 1717c35398e1..a88983313060 100644 --- a/generators/bootstrap-application-server/generator.ts +++ b/generators/bootstrap-application-server/generator.ts @@ -214,7 +214,7 @@ export default class BoostrapApplicationServer extends BaseApplicationGenerator return; } // derivedPrimary uses '@MapsId', which requires for each relationship id field to have corresponding field in the model - const derivedFields = entity.primaryKey.derivedFields; + const derivedFields = primaryKey.derivedFields; entity.fields.unshift(...derivedFields); }, }); diff --git a/generators/bootstrap-application/generator.ts b/generators/bootstrap-application/generator.ts index 97ff0768fc6c..852a9d44470c 100644 --- a/generators/bootstrap-application/generator.ts +++ b/generators/bootstrap-application/generator.ts @@ -102,7 +102,7 @@ export default class BootstrapApplicationGenerator extends BaseApplicationGenera entityConfig.name = entityName; } - entityConfig.fields.forEach((field: any) => { + entityConfig.fields!.forEach((field: any) => { const { fieldName, fieldType, fieldValidateRules } = field; assert(fieldName, `fieldName is missing in .jhipster/${entityName}.json for field ${stringifyApplicationData(field)}`); diff --git a/generators/bootstrap/generator.ts b/generators/bootstrap/generator.ts index b33339518517..d3673eed33e2 100644 --- a/generators/bootstrap/generator.ts +++ b/generators/bootstrap/generator.ts @@ -28,8 +28,8 @@ import BaseGenerator from '../base/index.js'; import { PRETTIER_EXTENSIONS } from '../generator-constants.js'; import { GENERATOR_UPGRADE } from '../generator-list.js'; import { PRIORITY_NAMES, QUEUES } from '../base-application/priorities.js'; -import type { BaseGeneratorDefinition, GenericTaskGroup } from '../base/tasks.js'; import { loadStoredAppOptions } from '../app/support/index.js'; +import type { GenericTaskGroup, TaskParamWithControl } from '../../lib/types/base/tasks.js'; import { autoCrlfTransform, createESLintTransform, @@ -107,7 +107,7 @@ export default class BootstrapGenerator extends BaseGenerator { return this.multistepTransform; } - get preConflicts(): GenericTaskGroup { + get preConflicts(): GenericTaskGroup { return { queueCommitPrettierConfig() { this.queueCommitPrettierConfig(); diff --git a/generators/client/index.ts b/generators/client/index.ts index 0fef8da0318c..8044359653d7 100644 --- a/generators/client/index.ts +++ b/generators/client/index.ts @@ -16,12 +16,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import type { GeneratorDefinition } from '../base-application/generator.js'; - export { default } from './generator.js'; export { default as command } from './command.js'; export { files as commonFiles } from './files-common.js'; - -export type SourceType = { - addEntitiesToClient: (arg1: GeneratorDefinition['postWritingEntitiesTaskParam']) => void; -}; diff --git a/generators/client/support/files.ts b/generators/client/support/files.ts index cb3c535d2056..aa3e7a69b164 100644 --- a/generators/client/support/files.ts +++ b/generators/client/support/files.ts @@ -1,7 +1,6 @@ import type { WriteFileBlock } from '../../base/api.js'; import type CoreGenerator from '../../base-core/index.js'; import { CLIENT_MAIN_SRC_DIR, CLIENT_TEST_SRC_DIR } from '../../generator-constants.js'; -import type { CommonClientServerApplication } from '../../base-application/types.js'; export const replaceEntityFilePath = (data: any, filepath: string) => filepath @@ -11,7 +10,7 @@ export const replaceEntityFilePath = (data: any, filepath: string) => const CLIENT_TEMPLATES_SRC_DIR = CLIENT_MAIN_SRC_DIR; -type RelativeWriteFileBlock = WriteFileBlock> & { +type RelativeWriteFileBlock = WriteFileBlock & { relativePath?: string; }; diff --git a/generators/client/support/update-languages.ts b/generators/client/support/update-languages.ts index ee137e954ee6..da6539d84444 100644 --- a/generators/client/support/update-languages.ts +++ b/generators/client/support/update-languages.ts @@ -19,7 +19,10 @@ import type { CommonClientServerApplication } from '../../base-application/types.js'; import type BaseGenerator from '../../base/index.js'; -export type UpdateClientLanguagesTaskParam = { application: CommonClientServerApplication & { enableTranslation: true }; control?: any }; +export type UpdateClientLanguagesTaskParam = { + application: CommonClientServerApplication & { enableTranslation: true }; + control?: any; +}; /** * Update DayJS Locales. diff --git a/generators/client/types.d.ts b/generators/client/types.d.ts index fe0e7ddfe50b..b930fcf0d470 100644 --- a/generators/client/types.d.ts +++ b/generators/client/types.d.ts @@ -3,6 +3,7 @@ import type { AngularApplication } from '../angular/types.js'; import type { ExportApplicationPropertiesFromCommand, ExportStoragePropertiesFromCommand } from '../../lib/command/index.js'; import type { CypressApplication } from '../cypress/types.js'; import type { JavaScriptApplication, JavaScriptSourceType } from '../javascript/types.js'; +import type { PostWritingEntitiesTaskParam } from '../../lib/types/application/tasks.js'; import type { Command } from './command.ts'; export type StoredClientProperties = ExportStoragePropertiesFromCommand; @@ -26,7 +27,9 @@ export type ClientResources = { */ comment?: string; }; + export type ClientSourceType = JavaScriptSourceType & { + addEntitiesToClient: (arg1: PostWritingEntitiesTaskParam) => void; /** * Add external resources to root file(index.html). */ diff --git a/generators/common/index.ts b/generators/common/index.ts index fd8b65cf3efe..5560397a490b 100644 --- a/generators/common/index.ts +++ b/generators/common/index.ts @@ -16,21 +16,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import type { BaseApplicationGeneratorDefinition } from '../base-application/tasks.js'; -import { type Entity } from '../base-application/index.js'; -import type { ClientServerApplication } from './types.js'; - export { default } from './generator.js'; export { default as command } from './command.js'; export { commonFiles as files } from './files.js'; - -// TODO move to ./generator.mts -type ApplicationDefinition = { - applicationType: ClientServerApplication; - entityType: Entity; - sourceType: Record any>; -}; - -// TODO move to ./generator.mts -export type GeneratorDefinition = - BaseApplicationGeneratorDefinition; diff --git a/generators/cucumber/files.ts b/generators/cucumber/files.ts index 071b78105533..539dac3bb3b3 100644 --- a/generators/cucumber/files.ts +++ b/generators/cucumber/files.ts @@ -19,10 +19,9 @@ import { moveToJavaPackageTestDir } from '../server/support/index.js'; import { GRADLE_BUILD_SRC_MAIN_DIR, SERVER_TEST_RES_DIR, SERVER_TEST_SRC_DIR } from '../generator-constants.js'; import type { WriteFileSection } from '../base/api.js'; -import type { CommonClientServerApplication } from '../base-application/types.js'; import type Generator from './generator.js'; -const cucumberFiles: WriteFileSection = { +const cucumberFiles: WriteFileSection = { cucumberFiles: [ { path: `${SERVER_TEST_SRC_DIR}_package_/`, diff --git a/generators/cypress/files.ts b/generators/cypress/files.ts index b6d1097a3a3d..d35a4c20e38c 100644 --- a/generators/cypress/files.ts +++ b/generators/cypress/files.ts @@ -19,15 +19,11 @@ import { CLIENT_TEST_SRC_DIR } from '../generator-constants.js'; import type { WriteFileSection } from '../base/api.js'; -import { type Entity } from '../base-application/index.js'; -import type { CommonClientServerApplication } from '../base-application/types.js'; import { clientRootTemplatesBlock } from '../client/support/index.js'; -import type { CypressApplication } from './types.js'; -import type CypressGenerator from './generator.js'; const CYPRESS_TEMPLATE_SOURCE_DIR = `${CLIENT_TEST_SRC_DIR}cypress/`; -export const cypressFiles: WriteFileSection = { +export const cypressFiles: WriteFileSection = { common: [ { templates: ['README.md.jhi.cypress'], @@ -103,7 +99,7 @@ export const cypressFiles: WriteFileSection = { +export const cypressEntityFiles: WriteFileSection = { testsCypress: [ { path: CYPRESS_TEMPLATE_SOURCE_DIR, diff --git a/generators/gatling/files.ts b/generators/gatling/files.ts index b25b721f457e..ffdeb7cd331b 100644 --- a/generators/gatling/files.ts +++ b/generators/gatling/files.ts @@ -18,10 +18,9 @@ */ import { GRADLE_BUILD_SRC_MAIN_DIR, TEST_DIR } from '../generator-constants.js'; import type { WriteFileSection } from '../base/api.js'; -import type { SpringBootApplication } from '../server/types.js'; import type Generator from './generator.js'; -const gatlingFiles: WriteFileSection = { +const gatlingFiles: WriteFileSection = { gatlingFiles: [ { templates: ['README.md.jhi.gatling'], diff --git a/generators/gradle/generator.ts b/generators/gradle/generator.ts index 4c9187b7a895..824736a1ddae 100644 --- a/generators/gradle/generator.ts +++ b/generators/gradle/generator.ts @@ -107,8 +107,8 @@ export default class GradleGenerator extends BaseApplicationGenerator { source.addGradleDependencies = (dependencies, options = {}) => { const { gradleFile } = gradleNeedleOptionsWithDefaults(options); if (gradleFile === 'build.gradle') { - (source as any)._gradleDependencies = source._gradleDependencies ?? []; - (source as any)._gradleDependencies.push(...dependencies); + source._gradleDependencies = source._gradleDependencies ?? []; + source._gradleDependencies.push(...dependencies); this.queueTask({ method: () => { this.editFile(gradleFile, addGradleDependenciesCallback((source as any)._gradleDependencies.sort(sortDependencies))); diff --git a/generators/gradle/types.d.ts b/generators/gradle/types.d.ts index ea49286945d1..af391c415c51 100644 --- a/generators/gradle/types.d.ts +++ b/generators/gradle/types.d.ts @@ -35,6 +35,7 @@ export type GradleCatalogNeedleOptions = { gradleVersionCatalogFile?: string }; export type GradleNeedleOptions = GradleFileNeedleOptions & GradleCatalogNeedleOptions; export type GradleSourceType = { + _gradleDependencies?: GradleDependency[]; applyFromGradle?(script: GradleScript): void; addGradleDependency?(dependency: GradleDependency, options?: GradleFileNeedleOptions): void; addGradleDependencies?(dependency: GradleDependency[], options?: GradleFileNeedleOptions): void; diff --git a/generators/java/generators/domain/entity-files.ts b/generators/java/generators/domain/entity-files.ts index 7115ee3d9d43..754a8a640bd4 100644 --- a/generators/java/generators/domain/entity-files.ts +++ b/generators/java/generators/domain/entity-files.ts @@ -51,7 +51,7 @@ export const entityServerFiles: WriteFileSection = { export const enumFiles: WriteFileSection = { enumFiles: [ javaMainPackageTemplatesBlock({ - renameTo: (data, filepath) => filepath.replace('_enumName_', data.enumName), + renameTo: (data, filepath) => filepath.replace('_enumName_', (data as any).enumName), templates: ['_entityPackage_/domain/enumeration/_enumName_.java'], }), ], diff --git a/generators/java/support/files.ts b/generators/java/support/files.ts index 4d53a55beecc..8271aa2fb56e 100644 --- a/generators/java/support/files.ts +++ b/generators/java/support/files.ts @@ -20,6 +20,8 @@ import type { WriteFileBlock } from '../../base/api.js'; import type CoreGenerator from '../../base-core/generator.js'; import { SERVER_MAIN_RES_DIR, SERVER_MAIN_SRC_DIR, SERVER_TEST_RES_DIR, SERVER_TEST_SRC_DIR } from '../../generator-constants.js'; +import type { ApplicationType } from '../../../lib/types/application/application.js'; +import type { Entity } from '../../../lib/types/application/entity.js'; export const replaceEntityFilePathVariables = (data: any, filePath: string) => { filePath = filePath @@ -60,7 +62,9 @@ export const moveToSrcTestResourcesDir = (data: any, filePath: string) => type RelativeWriteFileBlock = WriteFileBlock & { relativePath?: string }; -export function javaMainPackageTemplatesBlock(blockOrRelativePath?: string): Pick; +export function javaMainPackageTemplatesBlock>( + blockOrRelativePath?: string, +): Pick, 'path' | 'renameTo'>; export function javaMainPackageTemplatesBlock(blockOrRelativePath: RelativeWriteFileBlock): WriteFileBlock; export function javaMainPackageTemplatesBlock( blockOrRelativePath: string | RelativeWriteFileBlock = '', diff --git a/generators/javascript/generators/eslint/generator.ts b/generators/javascript/generators/eslint/generator.ts index bf5d7c244172..c8172c419e6a 100644 --- a/generators/javascript/generators/eslint/generator.ts +++ b/generators/javascript/generators/eslint/generator.ts @@ -56,7 +56,7 @@ export default class EslintGenerator extends BaseApplicationGenerator { importToAdd ? createNeedleCallback({ needle: 'eslint-add-import', contentToAdd: importToAdd }) : content => content, ); source.addEslintIgnore = ({ ignorePattern }) => - source.addEslintConfig({ config: `{ ignores: '${ignorePattern.replaceAll("'", "\\')}")},` }); + source.addEslintConfig!({ config: `{ ignores: '${ignorePattern.replaceAll("'", "\\')}")},` }); }, }); } diff --git a/generators/javascript/generators/eslint/support/tasks.ts b/generators/javascript/generators/eslint/support/tasks.ts index 22232b932558..07a2f6103136 100644 --- a/generators/javascript/generators/eslint/support/tasks.ts +++ b/generators/javascript/generators/eslint/support/tasks.ts @@ -18,9 +18,10 @@ * limitations under the License. */ import { asWritingTask } from '../../../../base-application/support/index.js'; +import type { WritingTaskParam } from '../../../../base-application/tasks.js'; import { clientRootTemplatesBlock } from '../../../../client/support/files.js'; -export const writeEslintClientRootConfigFile: any = asWritingTask(async function writingEslintFile({ application }) { +export const writeEslintClientRootConfigFile: WritingTaskParam = asWritingTask(async function writingEslintFile({ application }) { await this.writeFiles({ blocks: [ clientRootTemplatesBlock({ diff --git a/generators/javascript/types.d.ts b/generators/javascript/types.d.ts index e93b90796c66..ddddcd46d69f 100644 --- a/generators/javascript/types.d.ts +++ b/generators/javascript/types.d.ts @@ -1,6 +1,9 @@ export type JavaScriptSourceType = { mergePrettierConfig?: (config: Record) => void; addPrettierIgnore?: (newContent: string) => void; + + addEslintIgnore?: (opts: { ignorePattern: string }) => void; + addEslintConfig?: (opts: { import?: string | string[]; config?: string | string[] }) => void; }; export type JavaScriptApplication = { diff --git a/generators/languages/types.d.ts b/generators/languages/types.d.ts index 53f3df94d8b6..85e93f7121a5 100644 --- a/generators/languages/types.d.ts +++ b/generators/languages/types.d.ts @@ -18,17 +18,15 @@ */ import type { Language } from './support/languages.js'; +export type LanguagesSource = { + addEntityTranslationKey: (arg: { translationKey: string; translationValue: string; language: string }) => void; +}; + export type I18nApplication = { + enableTranslation: boolean; enableI18nRTL: boolean; nativeLanguage: string; nativeLanguageDefinition: Language; -} & ( - | { - enableTranslation: false; - } - | { - enableTranslation: true; - languages: string[]; - languagesDefinition: readonly Language[]; - } -); + languages: string[]; + languagesDefinition: readonly Language[]; +}; diff --git a/generators/liquibase/files.ts b/generators/liquibase/files.ts index 17fa4732d071..204f2e949576 100644 --- a/generators/liquibase/files.ts +++ b/generators/liquibase/files.ts @@ -19,10 +19,8 @@ import type { WriteFileSection } from '../base/api.js'; import { SERVER_MAIN_RES_DIR, SERVER_MAIN_SRC_DIR } from '../generator-constants.js'; import { moveToJavaPackageSrcDir } from '../server/support/index.js'; -import type { CommonClientServerApplication } from '../base-application/types.js'; -import type LiquibaseGenerator from './generator.js'; -export const liquibaseFiles: WriteFileSection = { +export const liquibaseFiles: WriteFileSection = { liquibase: [ { condition: ctx => ctx.backendTypeSpringBoot, diff --git a/generators/liquibase/generator.ts b/generators/liquibase/generator.ts index 30fc57f64212..c00b5a00cb72 100644 --- a/generators/liquibase/generator.ts +++ b/generators/liquibase/generator.ts @@ -148,9 +148,7 @@ export default class LiquibaseGenerator extends BaseEntityChangesGenerator { get postPreparingEachEntity() { return this.asPostPreparingEachEntityTaskGroup({ - postPrepareEntity({ application, entity }) { - postPrepareEntity({ application, entity }); - }, + postPrepareEntity, }); } @@ -192,7 +190,7 @@ export default class LiquibaseGenerator extends BaseEntityChangesGenerator { prepareRelationship(entity, relationship, this, true); prepareRelationshipForLiquibase(entity, relationship); } - postPrepareEntity({ application, entity }); + postPrepareEntity.call(this, { application, entity } as any); } } diff --git a/generators/liquibase/support/post-prepare-entity.ts b/generators/liquibase/support/post-prepare-entity.ts index 9c04d1d3fc57..e1e4f72a195f 100644 --- a/generators/liquibase/support/post-prepare-entity.ts +++ b/generators/liquibase/support/post-prepare-entity.ts @@ -18,24 +18,21 @@ */ import { fieldTypes } from '../../../jdl/jhipster/index.js'; import type { LiquibaseEntity } from '../types.js'; -import type { GeneratorDefinition } from '../../base-application/generator.js'; +import { asPostPreparingEachEntityTask } from '../../base-application/support/task-type-inference.js'; const { CommonDBTypes } = fieldTypes; const { LONG: TYPE_LONG, INTEGER: TYPE_INTEGER } = CommonDBTypes; -export default function postPrepareEntity({ - application, - entity, -}: Pick) { +export default asPostPreparingEachEntityTask(function postPrepareEntity({ application, entity }) { const { relationships, builtIn, name, primaryKey } = entity; - if (builtIn && name === 'User') { + if (builtIn && name === 'User' && primaryKey) { const userIdType = primaryKey.type; const idField = primaryKey.fields[0]; const idFieldName = idField.fieldName ?? 'id'; const liquibaseFakeData = application.generateUserManagement ? [ - { [idFieldName]: [TYPE_INTEGER, TYPE_LONG].includes(userIdType) ? 1 : idField.generateFakeData() }, - { [idFieldName]: [TYPE_INTEGER, TYPE_LONG].includes(userIdType) ? 2 : idField.generateFakeData() }, + { [idFieldName]: [TYPE_INTEGER, TYPE_LONG].includes(userIdType) ? 1 : idField.generateFakeData!() }, + { [idFieldName]: [TYPE_INTEGER, TYPE_LONG].includes(userIdType) ? 2 : idField.generateFakeData!() }, ] : []; (entity as LiquibaseEntity).liquibaseFakeData = liquibaseFakeData; @@ -43,4 +40,4 @@ export default function postPrepareEntity({ } (entity as LiquibaseEntity).anyRelationshipIsOwnerSide = relationships.some(relationship => relationship.ownerSide); -} +}); diff --git a/generators/maven/generator.ts b/generators/maven/generator.ts index abfefdf04741..2f6af237fde9 100644 --- a/generators/maven/generator.ts +++ b/generators/maven/generator.ts @@ -23,13 +23,12 @@ import { isFileStateModified } from 'mem-fs-editor/state'; import BaseApplicationGenerator from '../base-application/index.js'; -import { type GeneratorDefinition as SpringBootGeneratorDefinition } from '../server/index.js'; import files from './files.js'; import { MAVEN } from './constants.js'; import cleanupOldServerFilesTask from './cleanup.js'; import { type PomStorage, createPomStorage, sortPomFile } from './support/index.js'; -export default class MavenGenerator extends BaseApplicationGenerator { +export default class MavenGenerator extends BaseApplicationGenerator { pomStorage!: PomStorage; sortMavenPom!: boolean; @@ -98,7 +97,7 @@ export default class MavenGenerator extends BaseApplicationGenerator { properties = Array.isArray(properties) ? properties : [properties]; for (const property of properties) { - javaProperties[property.property] = property.value!; + javaProperties![property.property] = property.value!; this.pomStorage.addProperty(property); } }; diff --git a/generators/maven/types.d.ts b/generators/maven/types.d.ts index 6301cfb5ca9e..d35b10743c67 100644 --- a/generators/maven/types.d.ts +++ b/generators/maven/types.d.ts @@ -76,7 +76,7 @@ export type MavenDefinition = { }; export type MavenSourceType = { - mergeMavenPomContent?(content: any): void; + mergeMavenPomContent?(content: Record): void; addMavenAnnotationProcessor?(artifact: MavenAnnotationProcessor | MavenAnnotationProcessor[]): void; addMavenDependency?(dependency: MavenDependency | MavenDependency[]): void; addMavenDependencyManagement?(dependency: MavenDependency | MavenDependency[]): void; diff --git a/generators/server/index.ts b/generators/server/index.ts index b12327b650b5..1cfadd692bb6 100644 --- a/generators/server/index.ts +++ b/generators/server/index.ts @@ -16,18 +16,5 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - -import type { BaseApplicationGeneratorDefinition, GenericApplicationDefinition } from '../base-application/tasks.js'; -import type { GenericSourceTypeDefinition } from '../base/tasks.js'; -import type { SpringBootApplication, SpringBootSourceType } from './types.js'; - export { default } from './generator.js'; export { default as command } from './command.js'; - -// TODO move to ./generator.mts -export type ApplicationDefinition = GenericApplicationDefinition; - -// TODO move to ./generator.mts -export type GeneratorDefinition = BaseApplicationGeneratorDefinition< - ApplicationDefinition & GenericSourceTypeDefinition ->; diff --git a/generators/server/support/update-languages.ts b/generators/server/support/update-languages.ts index 21d61d49432b..71be0fbdf80f 100644 --- a/generators/server/support/update-languages.ts +++ b/generators/server/support/update-languages.ts @@ -17,17 +17,14 @@ * limitations under the License. */ -import type BaseGenerator from '../../base/index.js'; -import { type CommonClientServerApplication } from '../../base-application/types.js'; - -type UpdateServerLanguagesTaskParam = { application: CommonClientServerApplication & { enableTranslation: true }; control: any }; +import { asPostWritingTask } from '../../base-application/support/task-type-inference.js'; /** * Update Languages In MailServiceIT * * @param application */ -export function updateLanguagesInMailServiceITTask(this: BaseGenerator, { application, control }: UpdateServerLanguagesTaskParam) { +export const updateLanguagesInMailServiceITTask = asPostWritingTask(function updateLanguagesInMailServiceITTask({ application, control }) { const { javaPackageTestDir, languagesDefinition } = application; const { ignoreNeedlesError: ignoreNonExisting } = control; let newContent = 'private static final String[] languages = {\n'; @@ -39,8 +36,8 @@ export function updateLanguagesInMailServiceITTask(this: BaseGenerator, { applic this.editFile(`${javaPackageTestDir}/service/MailServiceIT.java`, { ignoreNonExisting }, content => content.replace(/private.*static.*String.*languages.*\{([^}]*jhipster-needle-i18n-language-constant[^}]*)\};/g, newContent), ); -} +}); -export default function updateLanguagesTask(this: BaseGenerator, taskParam: UpdateServerLanguagesTaskParam) { +export default asPostWritingTask(function updateLanguagesTask(this, taskParam) { updateLanguagesInMailServiceITTask.call(this, taskParam); -} +}); diff --git a/generators/server/types.d.ts b/generators/server/types.d.ts index 346a4571c846..13b537875d49 100644 --- a/generators/server/types.d.ts +++ b/generators/server/types.d.ts @@ -3,7 +3,7 @@ import type { GradleSourceType } from '../gradle/types.js'; import type { MavenSourceType } from '../maven/types.js'; import type { LiquibaseSourceType } from '../liquibase/types.js'; import type { SpringCacheSourceType } from '../spring-cache/types.js'; -import type { DeterministicOptionWithDerivedProperties, OptionWithDerivedProperties } from '../base-application/application-options.js'; +import type { OptionWithDerivedProperties } from '../base-application/application-options.js'; import type { GatewayApplication } from '../spring-cloud/generators/gateway/types.js'; import type { JavaAnnotation } from '../java/support/add-java-annotation.ts'; import type { ApplicationPropertiesNeedles } from './support/needles.ts'; @@ -54,6 +54,8 @@ export type LiquibaseApplication = { liquibaseDefaultSchemaName: string; }; +/* +Deterministic option causes types to be too complex type DatabaseTypeSqlApplication = ( | ReactiveApplication | (ImperativeApplication & { @@ -64,13 +66,27 @@ type DatabaseTypeSqlApplication = ( prodDatabaseType: string; devDatabaseTypeMysql: boolean; } & LiquibaseApplication; - + */ +type DatabaseTypeSqlApplication = { + enableHibernateCache: boolean; +} & { + devDatabaseType: string; + prodDatabaseType: string; + devDatabaseTypeMysql: boolean; +} & LiquibaseApplication; +/* +Deterministic option causes types to be too complex type DatabaseTypeApplication = DeterministicOptionWithDerivedProperties< 'databaseType', ['sql', 'no', 'cassandra', 'couchbase', 'mongodb', 'neo4j'], [DatabaseTypeSqlApplication] >; +*/ +type DatabaseTypeApplication = DatabaseTypeSqlApplication & + OptionWithDerivedProperties<'databaseType', ['sql', 'no', 'cassandra', 'couchbase', 'mongodb', 'neo4j']>; +/* +Deterministic option causes types to be too complex type BuildToolApplication = DeterministicOptionWithDerivedProperties< 'buildTool', ['maven', 'gradle'], @@ -81,12 +97,20 @@ type BuildToolApplication = DeterministicOptionWithDerivedProperties< }, ] >; +*/ +type BuildToolApplication = OptionWithDerivedProperties<'buildTool', ['maven', 'gradle']> & { + enableGradleEnterprise: boolean; +}; type SearchEngine = { searchEngine: string; }; +/* +Deterministic option causes types to be too complex type ApplicationNature = (ImperativeApplication & CacheProviderApplication) | ReactiveApplication; +*/ +type ApplicationNature = { reactive: boolean } & CacheProviderApplication; export type SpringBootApplication = JavaApplication & ApplicationNature & diff --git a/generators/spring-boot/generator.ts b/generators/spring-boot/generator.ts index 362b9cc63843..46d23dad67df 100644 --- a/generators/spring-boot/generator.ts +++ b/generators/spring-boot/generator.ts @@ -397,10 +397,11 @@ public void set${javaBeanCase(propertyName)}(${propertyType} ${propertyName}) { } }, prepareEntity({ relationship }) { - if (relationship.otherEntity.embedded) return; + const { primaryKey } = relationship.otherEntity; + if (!primaryKey) return; const { relationshipName, relationshipNameCapitalized } = relationship; - const otherEntityPkField = relationship.otherEntity.primaryKey.fields[0]; + const otherEntityPkField = primaryKey.fields[0]; mutateData(relationship, { propertyJavaFilterName: `${relationshipName}Id`, propertyJavaFilterJavaBeanName: `${relationshipNameCapitalized}Id`, diff --git a/generators/spring-cache/files.ts b/generators/spring-cache/files.ts index efc2d31faf47..704beebe574b 100644 --- a/generators/spring-cache/files.ts +++ b/generators/spring-cache/files.ts @@ -21,7 +21,7 @@ import { GRADLE_BUILD_SRC_MAIN_DIR, SERVER_MAIN_SRC_DIR, SERVER_TEST_SRC_DIR } f import type { WriteFileSection } from '../base/api.js'; import type Generator from './generator.js'; -const files: WriteFileSection = { +const files: WriteFileSection = { cacheFiles: [ { condition: data => data.buildToolGradle, diff --git a/generators/spring-cache/generator.ts b/generators/spring-cache/generator.ts index 8cb18cf8147b..c07599fe345f 100644 --- a/generators/spring-cache/generator.ts +++ b/generators/spring-cache/generator.ts @@ -165,8 +165,8 @@ export default class SpringCacheGenerator extends BaseApplicationGenerator { if (application.databaseTypeSql) { for (const entity of entities.filter(entity => !entity.skipServer && !entity.builtInUser)) { source.addEntityToCache?.({ - entityAbsoluteClass: (entity as any).entityAbsoluteClass, - relationships: entity.relationships, + entityAbsoluteClass: entity.entityAbsoluteClass, + relationships: entity.relationships as any, }); } } diff --git a/generators/spring-cloud-stream/generators/kafka/files.ts b/generators/spring-cloud-stream/generators/kafka/files.ts index fb37bcfb40fc..22ca4bcce597 100644 --- a/generators/spring-cloud-stream/generators/kafka/files.ts +++ b/generators/spring-cloud-stream/generators/kafka/files.ts @@ -20,7 +20,7 @@ import type { WriteFileSection } from '../../../base/api.js'; import { GRADLE_BUILD_SRC_MAIN_DIR, SERVER_MAIN_SRC_DIR, SERVER_TEST_SRC_DIR } from '../../../generator-constants.js'; import { moveToJavaPackageSrcDir, moveToJavaPackageTestDir } from '../../../server/support/index.js'; -export const kafkaFiles: WriteFileSection = { +export const kafkaFiles: WriteFileSection = { config: [ { condition: data => data.buildToolGradle, diff --git a/generators/spring-cloud-stream/generators/pulsar/files.ts b/generators/spring-cloud-stream/generators/pulsar/files.ts index 6213a195419e..4124956e6c49 100644 --- a/generators/spring-cloud-stream/generators/pulsar/files.ts +++ b/generators/spring-cloud-stream/generators/pulsar/files.ts @@ -20,7 +20,7 @@ import type { WriteFileSection } from '../../../base/api.js'; import { GRADLE_BUILD_SRC_MAIN_DIR, SERVER_TEST_SRC_DIR } from '../../../generator-constants.js'; import { moveToJavaPackageTestDir } from '../../../java/support/index.js'; -export const pulsarFiles: WriteFileSection = { +export const pulsarFiles: WriteFileSection = { config: [ { condition: data => data.buildToolGradle, diff --git a/generators/spring-websocket/files.ts b/generators/spring-websocket/files.ts index e9559c199cbe..8e5cf40067eb 100644 --- a/generators/spring-websocket/files.ts +++ b/generators/spring-websocket/files.ts @@ -19,10 +19,9 @@ import { moveToJavaPackageSrcDir } from '../server/support/index.js'; import { SERVER_MAIN_SRC_DIR } from '../generator-constants.js'; import type { WriteFileSection } from '../base/api.js'; -import type { SpringBootApplication } from '../server/types.js'; import type Generator from './generator.js'; -const files: WriteFileSection = { +const files: WriteFileSection = { websocketFiles: [ { path: `${SERVER_MAIN_SRC_DIR}_package_/`, diff --git a/lib/command/types.d.ts b/lib/command/types.d.ts index 41a845d3a107..0e333b3fde30 100644 --- a/lib/command/types.d.ts +++ b/lib/command/types.d.ts @@ -1,6 +1,7 @@ import type { ArgumentSpec, CliOptionSpec } from 'yeoman-generator'; import type { RequireAtLeastOne, SetOptional, Simplify, TaggedUnion, TupleToUnion, ValueOf } from 'type-fest'; import type { JHipsterOptionDefinition } from '../../jdl/types/types.js'; +import type { DerivedPropertiesOf, DerivedPropertiesWithInferenceUnion } from '../types/utils/derived-properties.js'; import type { MergeUnion } from './support/merge-union.js'; type ConfigScope = 'storage' | 'blueprint' | 'control' | 'generator'; @@ -137,20 +138,6 @@ type GetType = // eslint-disable-next-line @typescript-eslint/no-wrapper-object-types type WrapperToPrimitive = T extends Boolean ? boolean : T extends String ? string : T extends Number ? number : T; -/* - * @example - * ```ts - * DerivedPropertiesOf<'clientFramework', 'angular', 'angular', 'no'> = - * { clientFrameworkAngular: true; clientFrameworkNo: false; clientFramework: 'angular'; clientFrameworkAny: true; } - * ``` - */ -type DerivedPropertiesOf

= Simplify< - { - [K in C as `${P}${Capitalize}`]: K extends V ? true : false; - } & Record & - Record<`${P}Any`, V extends 'no' ? false : true> ->; - type GetChoiceValue = Choice extends string ? Choice : Choice extends { value: string } @@ -166,22 +153,6 @@ type NormalizeChoices; }; -/** - * ```ts - * type ExplodedConfigChoices = ExplodeConfigChoicesWithInference<['angular', 'no'], 'clientFramework'>; - * type ExplodedConfigChoices = - * | { clientFrameworkAngular: true; clientFrameworkNo: false; clientFramework: 'angular'; clientFrameworkAny: true; } - * | { clientFrameworkAngular: false; clientFrameworkNo: true; clientFramework: 'no'; clientFrameworkAny: true; } - * ``` - */ -type ExplodeConfigChoicesWithInference = ValueOf<{ - [Index in Exclude]: Choices[Index] extends infer Choice - ? Choice extends string - ? DerivedPropertiesOf - : never - : never; -}>; - /** * @example * ```ts @@ -196,14 +167,14 @@ type ExplodeConfigChoicesWithInference = { +type DerivedPropertiesWithInferenceUnionFromParseableConfigs = { [K in keyof U]: U[K] extends infer RequiredChoices ? RequiredChoices extends { choices: JHispterChoices } ? K extends infer StringKey ? StringKey extends string ? NormalizeChoices extends infer NormalizedChoices ? // @ts-expect-error Mapped typle type is loosy https://github.com/microsoft/TypeScript/issues/27995 - Simplify> + Simplify> : never : never : never @@ -211,13 +182,6 @@ type ExplodeCommandChoicesWithInference = { : never; }; -type DerivedPropertiesNoInferenceOf = Simplify< - { - [K in Choices as `${Property}${Capitalize}`]: boolean; - } & Record & - Record<`${Property}Any`, boolean> ->; - type ExplodeCommandChoicesNoInference = { [K in keyof U]: U[K] extends infer RequiredChoices ? RequiredChoices extends { choices: any } @@ -225,7 +189,7 @@ type ExplodeCommandChoicesNoInference = { ? StringKey extends string ? NormalizeChoices extends infer NormalizedChoices ? // @ts-expect-error Mapped typle type is loosy https://github.com/microsoft/TypeScript/issues/27995 - Simplify> + Simplify> : never : never : never diff --git a/lib/types/application/application.d.ts b/lib/types/application/application.d.ts new file mode 100644 index 000000000000..567d47e2ce21 --- /dev/null +++ b/lib/types/application/application.d.ts @@ -0,0 +1,7 @@ +import type { BaseApplication, CommonClientServerApplication } from '../../../generators/base-application/types.js'; +import type { ClientSourceType } from '../../../generators/client/types.js'; +import type { LanguagesSource } from '../../../generators/languages/types.js'; +import type { SpringBootSourceType } from '../../../generators/server/types.js'; + +export type ApplicationType = BaseApplication & Partial>; +export type BaseApplicationSource = SpringBootSourceType & ClientSourceType & LanguagesSource; diff --git a/lib/types/application/entity.d.ts b/lib/types/application/entity.d.ts new file mode 100644 index 000000000000..b133a359c0de --- /dev/null +++ b/lib/types/application/entity.d.ts @@ -0,0 +1,143 @@ +/** + * Copyright 2013-2024 the original author or authors from the JHipster project. + * + * This file is part of the JHipster project, see https://www.jhipster.tech/ + * for more information. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import type { IsNever } from 'type-fest'; +import type { Entity as BaseEntity } from '../base/entity.js'; +import type { SpringEntity } from '../../../generators/server/types.js'; +import type { Field as BaseField } from '../base/field.js'; +import type { Relationship as BaseRelationship } from '../base/relationship.js'; +import type { Field } from './field.js'; +import type { Relationship } from './relationship.js'; + +type AngularEntity = { + entityAngularAuthorities?: string; + entityAngularReadAuthorities?: string; +}; + +export interface Entity + extends Omit>, 'relationships'>, + SpringEntity, + AngularEntity { + relationships: (IsNever extends true ? Relationship> : R)[]; + + primaryKey?: { + fields: F[]; + derivedFields: F[]; + type: string; + composite: boolean; + derived: boolean; + javaValueGenerator?: string; + javaBuildSpecification?: string; + }; + + builtIn?: boolean; + builtInUser?: boolean; + builtInAuthority?: boolean; + microserviceName?: string; + adminEntity?: boolean; + entityAuthority?: string; + entityReadAuthority?: string; + hasCyclicRequiredRelationship?: boolean; + jpaMetamodelFiltering?: boolean; + + entityNameCapitalized: string; + entityClass: string; + entityInstance: string; + entityTableName: string; + entityNamePlural: string; + entityAbsoluteClass: string; + + dtoClass?: string; + dtoInstance?: string; + + persistClass: string; + persistInstance: string; + restClass: string; + restInstance: string; + + entityNamePluralizedAndSpinalCased: string; + entityClassPlural: string; + entityInstancePlural: string; + + entityI18nVariant: string; + entityClassHumanized: string; + entityClassPluralHumanized: string; + + entityFileName: string; + entityFolderName: string; + entityModelFileName: string; + entityParentPathAddition: string; + entityPluralFileName: string; + entityServiceFileName: string; + + /** Generate only the model at client side for relationships. */ + entityClientModelOnly?: boolean; + entityAngularName: string; + entityAngularNamePlural: string; + entityReactName: string; + + entityApiUrl: string; + entityStateName: string; + entityUrl: string; + + entityTranslationKey: string; + entityTranslationKeyMenu: string; + + i18nKeyPrefix: string; + i18nAlertHeaderPrefix: string; + + entityApi: string; + entityPage: string; + + anyFieldIsBigDecimal: boolean; + /** + * Any file is of type Bytes or ByteBuffer + */ + anyFieldIsBlobDerived: boolean; + /** + * Any field is of type ZonedDateTime, Instant or LocalDate + */ + anyFieldIsDateDerived: boolean; + anyFieldIsDuration: boolean; + anyFieldIsInstant: boolean; + anyFieldIsLocalDate: boolean; + /** + * Any field is of type ZonedDateTime or Instant + */ + anyFieldIsTimeDerived: boolean; + anyFieldIsUUID: boolean; + anyFieldIsZonedDateTime: boolean; + + anyFieldHasDocumentation: boolean; + anyFieldHasImageContentType: boolean; + anyFieldHasTextContentType: boolean; + /** + * Any field has image or any contentType + */ + anyFieldHasFileBasedContentType: boolean; + + /** + * Any relationship is required or id + */ + anyRelationshipIsRequired: boolean; + + dtoMapstruct: boolean; + + propertyJavaFilteredType?: string; +} diff --git a/lib/types/application/field.d.ts b/lib/types/application/field.d.ts new file mode 100644 index 000000000000..b721b8b04a16 --- /dev/null +++ b/lib/types/application/field.d.ts @@ -0,0 +1,43 @@ +import type { Field as BaseField } from '../../../lib/types/base/field.js'; + +export interface Field extends BaseField { + propertyName: string; + + enumFileName?: string; + documentation?: string; + fieldIsEnum?: boolean; + + skipClient?: boolean; + skipServer?: boolean; + + fieldTypeBlobContent?: string; + blobContentTypeText?: string; + + filterableField?: boolean; + transient?: boolean; + columnRequired?: boolean; + + // Java specific + propertyJavaBeanName?: string; + propertyDtoJavaType?: string; + propertyJavaFilterType?: string; + fieldInJavaBeanMethod?: string; + fieldJavaBuildSpecification?: string; + fieldJavaValueGenerator?: string; + javaValueGenerator?: string; + propertyJavaFilteredType?: string; + liquibaseDefaultValueAttributeValue?: string; + + propertyJavaCustomFilter?: { type: string; superType: string; fieldType: string }; + + generateFakeData?: () => any; + + fieldTypeDuration?: boolean; + fieldTypeBoolean: boolean; + /** @deprecated */ + fieldTypeTemporal: boolean; + /** @deprecated */ + fieldTypeCharSequence: boolean; + /** @deprecated */ + fieldTypeNumeric: boolean; +} diff --git a/generators/base-application/types/index.d.ts b/lib/types/application/index.d.ts similarity index 80% rename from generators/base-application/types/index.d.ts rename to lib/types/application/index.d.ts index 87a4ba629f4c..75d52ccaba5c 100644 --- a/generators/base-application/types/index.d.ts +++ b/lib/types/application/index.d.ts @@ -17,6 +17,6 @@ * limitations under the License. */ -export type { default as Entity, BaseEntity } from './entity.js'; -export type { default as Field } from './field.js'; -export type { default as Relationship } from './relationship.js'; +export type { Entity } from './entity.js'; +export type { Field } from './field.js'; +export type { Relationship } from './relationship.js'; diff --git a/lib/types/application/relationship.d.ts b/lib/types/application/relationship.d.ts new file mode 100644 index 000000000000..f713d945c496 --- /dev/null +++ b/lib/types/application/relationship.d.ts @@ -0,0 +1,23 @@ +import type { Entity } from '../base/entity.js'; +import type { Relationship as BaseRelationship } from '../base/relationship.js'; + +export interface Relationship extends BaseRelationship { + propertyName: string; + relationshipNameCapitalized: string; + + collection: boolean; + skipClient?: boolean; + skipServer?: boolean; + /** + * A persistable relationship means that the relationship will be updated in the database. + */ + persistableRelationship: boolean; + + otherEntity: E; + + ownerSide?: boolean; + relationshipEagerLoad?: boolean; + + propertyJavaBeanName?: string; + propertyDtoJavaType?: string; +} diff --git a/lib/types/application/tasks.d.ts b/lib/types/application/tasks.d.ts new file mode 100644 index 000000000000..a1297bdd48df --- /dev/null +++ b/lib/types/application/tasks.d.ts @@ -0,0 +1,110 @@ +import type { Storage } from 'yeoman-generator'; +import type { Merge } from 'type-fest'; +import type { Entity as BaseEntity } from '../base/entity.js'; +import type { GetFieldType, GetRelationshipType } from '../utils/entity-utils.ts'; +import type { TaskTypes as BaseTaskTypes, TaskParamWithControl, TaskParamWithSource } from '../base/tasks.js'; +import type { Entity } from './entity.js'; +import type { ApplicationType, BaseApplicationSource } from './application.js'; + +type ApplicationDefaultsTaskParam = { + /** + * Parameter properties accepts: + * - functions: receives the application and the return value is set at the application property. + * - non functions: application property will receive the property in case current value is undefined. + * + * Applies each object in order. + * + * @example + * // application = { prop: 'foo-bar', prop2: 'foo2' } + * applicationDefaults( + * application, + * { prop: 'foo', prop2: ({ prop }) => prop + 2 }, + * { prop: ({ prop }) => prop + '-bar', prop2: 'won\'t override' }, + * ); + */ + applicationDefaults: (...defaults: Record[]) => void; +}; + +type TaskParamWithApplication> = TaskParamWithControl & { + application: A; +}; + +type TaskParamWithEntities> = TaskParamWithApplication & { + entities: E[]; +}; + +type TaskParamWithApplicationDefaults> = TaskParamWithControl & + TaskParamWithApplication & + ApplicationDefaultsTaskParam; + +type PreparingTaskParam> = TaskParamWithApplicationDefaults & + TaskParamWithSource; + +type ConfiguringEachEntityTaskParam> = TaskParamWithApplication & { + entityName: string; + /** Entity storage */ + entityStorage: Storage; + /** Proxy object for the entitystorage */ + entityConfig: BaseEntity & Record; +}; + +type LoadingEntitiesTaskParam> = TaskParamWithApplication & { + entitiesToLoad: { + entityName: string; + /** Entity storage */ + entityStorage: Storage; + /** Proxy object for the entitystorage */ + entityConfig: Record; + /** Initial entity object */ + entityBootstrap: Record; + }[]; +}; + +type PreparingEachEntityTaskParam> = TaskParamWithApplication & { + entity: E; + entityName: string; + description: string; +}; + +type PreparingEachEntityFieldTaskParam> = PreparingEachEntityTaskParam & { + field: GetFieldType; + fieldName: string; +}; + +type PreparingEachEntityRelationshipTaskParam> = PreparingEachEntityTaskParam & { + relationship: GetRelationshipType; + relationshipName: string; +}; + +type WritingTaskParam> = TaskParamWithApplication & { + configChanges?: Record; +}; + +type PostWritingTaskParam> = TaskParamWithApplication & TaskParamWithSource; + +type PostWritingEntitiesTaskParam> = TaskParamWithEntities & + TaskParamWithSource; + +export type TaskTypes> = Merge< + BaseTaskTypes, + { + LoadingTaskParam: TaskParamWithApplicationDefaults; + PreparingTaskParam: PreparingTaskParam; + ConfiguringEachEntityTaskParam: ConfiguringEachEntityTaskParam; + LoadingEntitiesTaskParam: LoadingEntitiesTaskParam; + PreparingEachEntityTaskParam: PreparingEachEntityTaskParam; + PreparingEachEntityFieldTaskParam: PreparingEachEntityFieldTaskParam; + PreparingEachEntityRelationshipTaskParam: PreparingEachEntityRelationshipTaskParam; + PostPreparingEachEntityTaskParam: PreparingEachEntityTaskParam; + PostPreparingTaskParam: TaskParamWithSource & TaskParamWithApplication; + DefaultTaskParam: TaskParamWithEntities; + WritingTaskParam: WritingTaskParam; + WritingEntitiesTaskParam: TaskParamWithEntities; + PostWritingTaskParam: PostWritingTaskParam; + PostWritingEntitiesTaskParam: PostWritingEntitiesTaskParam; + PreConflictsTaskParam: TaskParamWithApplication; + InstallTaskParam: TaskParamWithApplication; + PostInstallTaskParam: TaskParamWithApplication; + EndTaskParam: TaskParamWithApplication; + } +>; diff --git a/lib/types/base/entity.d.ts b/lib/types/base/entity.d.ts new file mode 100644 index 000000000000..ff90f2b956d4 --- /dev/null +++ b/lib/types/base/entity.d.ts @@ -0,0 +1,16 @@ +import type { Field } from './field.js'; +import type { Relationship } from './relationship.js'; + +export type Entity = { + name: string; + changelogDate?: string; + dto?: string; + + fields?: F[]; + relationships?: R[]; + + readOnly?: boolean; + embedded?: boolean; + skipClient?: boolean; + skipServer?: boolean; +}; diff --git a/generators/base-application/types/field.d.ts b/lib/types/base/field.d.ts similarity index 86% rename from generators/base-application/types/field.d.ts rename to lib/types/base/field.d.ts index 77c0305cc8b8..2cf809db416f 100644 --- a/generators/base-application/types/field.d.ts +++ b/lib/types/base/field.d.ts @@ -17,11 +17,7 @@ * limitations under the License. */ -type Field = { +export type Field = { fieldName: string; fieldType: string; - fieldTypeBlobContent?: string; - propertyName: string; -} & Record; - -export default Field; +}; diff --git a/generators/base-application/types/relationship.d.ts b/lib/types/base/relationship.d.ts similarity index 74% rename from generators/base-application/types/relationship.d.ts rename to lib/types/base/relationship.d.ts index dc0cf549b449..8f14c149e134 100644 --- a/generators/base-application/types/relationship.d.ts +++ b/lib/types/base/relationship.d.ts @@ -17,14 +17,6 @@ * limitations under the License. */ -type Relationship = { +export type Relationship = { relationshipName: string; - propertyName: string; - collection: boolean; - /** - * A persistable relationship means that the relationship will be updated in the database. - */ - persistableRelationship: boolean; -} & Record; - -export default Relationship; +}; diff --git a/lib/types/base/tasks.d.ts b/lib/types/base/tasks.d.ts new file mode 100644 index 000000000000..38105b4386e6 --- /dev/null +++ b/lib/types/base/tasks.d.ts @@ -0,0 +1,30 @@ +import type { Control } from '../../../generators/base/types.js'; + +export type TaskParamWithControl = { + control: Control & Record; +}; + +export type TaskParamWithSource = TaskParamWithControl & { + source: Source; +}; + +export type TaskTypes = { + InitializingTaskParam: TaskParamWithControl; + PromptingTaskParam: TaskParamWithControl; + ConfiguringTaskParam: TaskParamWithControl; + ComposingTaskParam: TaskParamWithControl; + LoadingTaskParam: TaskParamWithControl; + PreparingTaskParam: TaskParamWithSource; + PostPreparingTaskParam: TaskParamWithSource; + DefaultTaskParam: TaskParamWithControl; + WritingTaskParam: TaskParamWithControl; + PostWritingTaskParam: TaskParamWithSource; + PreConflictsTaskParam: TaskParamWithControl; + InstallTaskParam: TaskParamWithControl; + PostInstallTaskParam: TaskParamWithControl; + EndTaskParam: TaskParamWithControl; +}; + +type GenericTask = (this: ThisType, arg1: Arg1Type) => unknown; + +export type GenericTaskGroup = Record>; diff --git a/lib/types/utils/derived-properties.d.ts b/lib/types/utils/derived-properties.d.ts new file mode 100644 index 000000000000..c0be8c7d309b --- /dev/null +++ b/lib/types/utils/derived-properties.d.ts @@ -0,0 +1,45 @@ +import type { Simplify, ValueOf } from 'type-fest'; + +/* + * @example + * ```ts + * DerivedPropertiesOf<'clientFramework', 'angular' | 'no'> = + * { clientFrameworkAngular: boolean; clientFrameworkNo: boolean; clientFramework: 'angular' | 'no'; clientFrameworkAny: boolean; } + * ``` + */ +export type DerivedPropertiesOf = Simplify< + { + [K in Choices as `${Property}${Capitalize}`]: boolean; + } & Record & + Record<`${Property}Any`, boolean> +>; + +/* + * @example + * ```ts + * DerivedPropertiesWithInferenceOf<'clientFramework', 'angular', 'angular', 'no'> = + * { clientFrameworkAngular: true; clientFrameworkNo: false; clientFramework: 'angular'; clientFrameworkAny: true; } + * ``` + */ +type DerivedPropertiesWithInferenceOf

= Simplify< + { + [K in C as `${P}${Capitalize}`]: K extends V ? true : false; + } & Record & + Record<`${P}Any`, V extends 'no' ? false : true> +>; + +/** + * ```ts + * type ExplodedConfigChoices = ExplodeDerivedPropertiesWithInference<['angular', 'no'], 'clientFramework'>; + * type ExplodedConfigChoices = + * | { clientFrameworkAngular: true; clientFrameworkNo: false; clientFramework: 'angular'; clientFrameworkAny: true; } + * | { clientFrameworkAngular: false; clientFrameworkNo: true; clientFramework: 'no'; clientFrameworkAny: true; } + * ``` + */ +export type DerivedPropertiesWithInferenceUnion = ValueOf<{ + [Index in Exclude]: Choices[Index] extends infer Choice + ? Choice extends string + ? DerivedPropertiesWithInferenceOf + : never + : never; +}>; diff --git a/lib/types/utils/entity-utils.ts b/lib/types/utils/entity-utils.ts new file mode 100644 index 000000000000..cf83acb76ce0 --- /dev/null +++ b/lib/types/utils/entity-utils.ts @@ -0,0 +1,2 @@ +export type GetRelationshipType = E extends { relationships: (infer R)[] } ? R : never; +export type GetFieldType = E extends { fields: (infer F)[] } ? F : never; diff --git a/package.json b/package.json index 5c2f8e943844..d5690e1f530a 100644 --- a/package.json +++ b/package.json @@ -37,49 +37,49 @@ "type": "module", "exports": { ".": { - "types": "./dist/types/generators/index.d.ts", + "types": "./dist/generators/index.d.ts", "default": "./dist/generators/index.js" }, "./cli": { - "types": "./dist/types/cli/index.d.mts", + "types": "./dist/cli/index.d.mts", "default": "./dist/cli/index.mjs" }, "./package.json": "./package.json", "./eslint/recommended": { - "types": "./dist/types/lib/eslint/index.d.ts", + "types": "./dist/lib/eslint/index.d.ts", "default": "./dist/lib/eslint/index.js" }, "./generators": { - "types": "./dist/types/generators/generator-list.d.ts", + "types": "./dist/generators/generator-list.d.ts", "default": "./dist/generators/generator-list.js" }, "./generators/*": { - "types": "./dist/types/generators/*/types-export.d.ts", + "types": "./dist/generators/*/types-export.d.ts", "default": "./dist/generators/*/index.js" }, "./generators/*/support": { - "types": "./dist/types/generators/*/support/index.d.ts", + "types": "./dist/generators/*/support/index.d.ts", "default": "./dist/generators/*/support/index.js" }, "./generators/*/generators/*": { - "types": "./dist/types/generators/*/generators/*/types-export.d.ts", + "types": "./dist/generators/*/generators/*/types-export.d.ts", "default": "./dist/generators/*/generators/*/index.js" }, "./generators/*/generators/*/support": { - "types": "./dist/types/generators/*/generators/*/support/index.d.ts", + "types": "./dist/generators/*/generators/*/support/index.d.ts", "default": "./dist/generators/*/generators/*/support/index.js" }, "./jdl": { - "types": "./dist/types/jdl/index.d.ts", + "types": "./dist/jdl/index.d.ts", "default": "./dist/jdl/index.js" }, "./testing": { - "types": "./dist/types/testing/index.d.ts", + "types": "./dist/testing/index.d.ts", "default": "./dist/testing/index.js" } }, "main": "./dist/generators/index.js", - "types": "./dist/types/generators/index.d.ts", + "types": "./dist/generators/index.d.ts", "bin": { "jhipster": "dist/cli/jhipster.cjs" }, @@ -91,22 +91,21 @@ ], "scripts": { "prebuild": "npm run clean", - "build": "npm run compile && npm run copy-files && npm run compile-types && npm run copy-types", + "build": "npm run compile && npm run copy-files && npm run copy-types", "postbuild": "node bin/fix-bin.cjs", "check-types": "tsc -p tsconfig.spec.json", "clean": "rimraf dist", "compile": "tsc", - "compile-types": "tsc -p tsconfig.types.json", "completion": "tabtab install --name jhipster --auto", "copy-files": "cpy \"jdl/*.json\" \"dist/jdl\" && cpy \"generators/**\" \"!**/*.(js|cjs|mjs|ts|cts|mts|snap)\" \"!**/__*/*\" dist/generators", - "copy-types": "cpy \"generators/**/*.d.(|c|m)ts\" dist/types/generators && cpy \"jdl/**/*.d.(|c|m)ts\" dist/types/jdl", + "copy-types": "cpy \"generators/**/*.d.(|c|m)ts\" dist/generators && cpy \"jdl/**/*.d.(|c|m)ts\" dist/jdl && cpy \"lib/**/*.d.(|c|m)ts\" dist/lib", "ejslint": "ejslint generators/**/*.ejs", "eslint": "eslint . --max-warnings 5", "jdl:test": "esmocha jdl --no-insight --forbid-only -p", "jdl:test-watch": "npm run jdl:test -- --watch", "jsdoc": "jsdoc --configure jsdoc-conf.json", "lint": "npm run eslint && npm run ejslint", - "lint-fix": "npm run prettier:format && npm run eslint -- --fix", + "lint-fix": "npm run eslint -- --fix && npm run prettier:format", "mocha-test": "esmocha jdl --no-insight --forbid-only --parallel --max-old-space-size=4096", "prepare": "npm run build", "prettier:check": "prettier --check \"{,**/}*.{js,ts,cjs,mjs,cts,mts,json,md,yml,java}\"", diff --git a/tsconfig.json b/tsconfig.json index d14ef691106f..6dea1945d0b7 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,5 +1,5 @@ { - "include": ["cli/**/*", "generators/**/*", "jdl/**/*", "lib/**/*", "testing/**/*"], + "include": ["./cli", "./generators", "./jdl", "./lib", "./testing"], "exclude": ["**/*.spec.*", "**/__*/**", "**/node_modules", "**/.*/"], "compilerOptions": { /* Language and Environment */ @@ -17,6 +17,7 @@ /* Emit */ "outDir": "./dist" /* Specify an output folder for all emitted files. */, + "declaration": true, /* Interop Constraints */ "allowSyntheticDefaultImports": true /* Allow 'import x from y' when a module doesn't have a default export. */, @@ -28,6 +29,6 @@ "noImplicitAny": false, /* Completeness */ - "skipLibCheck": true /* Skip type checking all .d.ts files. */ + "skipLibCheck": false /* Skip type checking all .d.ts files. */ } } diff --git a/tsconfig.types.json b/tsconfig.types.json deleted file mode 100644 index bc954fec8bc9..000000000000 --- a/tsconfig.types.json +++ /dev/null @@ -1,24 +0,0 @@ -{ - "include": [ - "./cli", - "./jdl", - "./testing", - "./lib/eslint/recommended.ts", - "./generators/index.ts", - "./generators/base", - "./generators/base-application", - "./generators/base-core", - "./generators/**/support/**/*", - "./generators/**/internal/**/*", - "./generators/**/jdl/**/*", - "./generators/*/type-export.d.ts" - ], - "exclude": ["**/*.spec.*", "**/__*/**"], - "extends": "./tsconfig.json", - "compilerOptions": { - "declarationDir": "./dist/types", - "declaration": true, - "skipLibCheck": false /* Skip type checking all .d.ts files. */, - "emitDeclarationOnly": true - } -}