/** * Copyright 2013-2025 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 { Storage } from 'yeoman-generator'; import type { Merge, OmitIndexSignature, Simplify } 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: Simplify< OmitIndexSignature<{ [Key in keyof (Partial & { __override__?: boolean })]?: Key extends '__override__' ? boolean : Key extends keyof A ? A[Key] | ((ctx: A) => A[Key]) : never; }> >[] ) => 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 EntityToLoad = { entityName: string; /** Entity storage */ entityStorage: Storage; /** Proxy object for the entitystorage */ entityConfig: BaseEntity; /** Initial entity object */ entityBootstrap: Entity; }; type LoadingEntitiesTaskParam> = TaskParamWithApplication & { entitiesToLoad: EntityToLoad[]; }; type EntityTaskParam = { entity: E; entityName: string; description: string; }; type PreparingEachEntityTaskParam> = TaskParamWithApplication & EntityTaskParam; 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; } >;