Skip to content

Commit 1af5aec

Browse files
authored
Lots of work related to implicit any (#30099)
1 parent 210c02d commit 1af5aec

File tree

54 files changed

+871
-502
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+871
-502
lines changed

cli/program.mts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import { packageNameToNamespace } from '../lib/utils/index.js';
3030
import baseCommand from '../generators/base/command.js';
3131
import { GENERATOR_APP, GENERATOR_BOOTSTRAP, GENERATOR_JDL } from '../generators/generator-list.js';
3232
import { extractArgumentsFromConfigs, type JHipsterCommandDefinition } from '../lib/command/index.js';
33-
import { buildJDLApplicationConfig } from '../lib/command/jdl.js';
33+
import { buildJDLApplicationConfig } from '../lib/jdl-config/jhipster-jdl-config.ts';
3434
import logo from './logo.mjs';
3535
import EnvironmentBuilder from './environment-builder.mjs';
3636
import SUB_GENERATORS from './commands.mjs';

generators/liquibase/generator.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,12 @@ import {
3030
prepareRelationship,
3131
} from '../base-application/support/index.js';
3232
import { prepareSqlApplicationProperties } from '../spring-data-relational/support/index.js';
33-
import { checkAndReturnRelationshipOnValue, fieldTypes } from '../../lib/jhipster/index.js';
33+
import { fieldTypes } from '../../lib/jhipster/index.js';
3434
import type { MavenProperty } from '../maven/types.js';
3535
import type { HandleCommandTypes } from '../../lib/command/types.js';
3636
import type { Config as BaseApplicationConfig, Options as BaseApplicationOptions } from '../base-entity-changes/types.js';
3737
import type { Source as SpringBootSource } from '../spring-boot/index.js';
38+
import { checkAndReturnRelationshipOnValue } from './internal/relationship-on-handler-options.ts';
3839
import { liquibaseFiles } from './files.js';
3940
import {
4041
liquibaseComment,
@@ -157,8 +158,8 @@ export default class LiquibaseGenerator extends BaseEntityChangesGenerator<
157158
return this.asPreparingEachEntityRelationshipTaskGroup({
158159
prepareEntityRelationship({ application, entity, relationship }) {
159160
prepareRelationshipForLiquibase({ application, entity, relationship });
160-
relationship.onDelete = checkAndReturnRelationshipOnValue(relationship.options?.onDelete, this);
161-
relationship.onUpdate = checkAndReturnRelationshipOnValue(relationship.options?.onUpdate, this);
161+
relationship.onDelete = checkAndReturnRelationshipOnValue(relationship.onDelete, this);
162+
relationship.onUpdate = checkAndReturnRelationshipOnValue(relationship.onUpdate, this);
162163
},
163164
});
164165
}

lib/jhipster/relationship-on-handler-options.ts renamed to generators/liquibase/internal/relationship-on-handler-options.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
* limitations under the License.
1818
*/
1919

20+
import type { Logger } from '../../../lib/utils/logger.ts';
21+
2022
const validOptions = ['NO ACTION', 'RESTRICT', 'CASCADE', 'SET NULL', 'SET DEFAULT'];
2123

2224
/**
@@ -25,12 +27,12 @@ const validOptions = ['NO ACTION', 'RESTRICT', 'CASCADE', 'SET NULL', 'SET DEFAU
2527
* @param generator
2628
* @returns
2729
*/
28-
export default function checkAndReturnRelationshipOnValue(onValue, generator) {
30+
export function checkAndReturnRelationshipOnValue(onValue: string | undefined, { log }: { log: Logger }) {
2931
let result = onValue;
3032

3133
if (result) {
3234
if (!validOptions.includes(result)) {
33-
generator.log.warn(`Invalid value '${result}' for onDelete or onUpdate - resetting to undefined.`);
35+
log.warn(`Invalid value '${result}' for onDelete or onUpdate - resetting to undefined.`);
3436

3537
result = undefined;
3638
}

generators/liquibase/types.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ type Property = {
5454
export interface Relationship extends BaseEntityChangesRelationship, DatabaseRelationship, Property {
5555
columnDataType?: string;
5656

57-
onDelete?: boolean;
58-
onUpdate?: boolean;
57+
onDelete?: string;
58+
onUpdate?: string;
5959

6060
shouldWriteRelationship?: boolean;
6161

generators/spring-cloud-stream/generator.spec.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,4 +58,16 @@ describe(`generator - ${generator}`, () => {
5858
});
5959
});
6060
});
61+
62+
describe('invalid option in jdl', () => {
63+
it('should fail', async () => {
64+
await expect(
65+
helpers
66+
.runJDL('application { config { baseName jhipster, messageBroker foo } }')
67+
.withMockedJHipsterGenerators()
68+
.withMockedSource()
69+
.withJHipsterConfig(),
70+
).rejects.toThrowError(`The value 'foo' is not allowed for the option 'messageBroker'`);
71+
});
72+
});
6173
});
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`generator - spring-cloud-stream:kafka jdl support should match files snapshot 1`] = `
4+
{
5+
".yo-rc.json": {
6+
"contents": "{
7+
"generator-jhipster": {
8+
"baseName": "jhipster",
9+
"creationTimestamp": 1577836800000,
10+
"entities": [],
11+
"messageBroker": "kafka"
12+
}
13+
}
14+
",
15+
"stateCleared": "modified",
16+
},
17+
}
18+
`;
19+
20+
exports[`generator - spring-cloud-stream:kafka with defaults options should call source snapshot 1`] = `
21+
{
22+
"addIntegrationTestAnnotation": [
23+
{
24+
"annotation": "EmbeddedKafka",
25+
"package": "com.mycompany.myapp.config",
26+
},
27+
],
28+
"addMainLog": [
29+
{
30+
"level": "INFO",
31+
"name": "org.apache.kafka",
32+
},
33+
{
34+
"level": "WARN",
35+
"name": "org.apache.kafka",
36+
},
37+
],
38+
"addMavenDependency": [
39+
[
40+
{
41+
"artifactId": "spring-cloud-stream",
42+
"groupId": "org.springframework.cloud",
43+
},
44+
{
45+
"artifactId": "spring-cloud-starter-stream-kafka",
46+
"groupId": "org.springframework.cloud",
47+
},
48+
{
49+
"artifactId": "spring-cloud-stream-test-binder",
50+
"groupId": "org.springframework.cloud",
51+
"scope": "test",
52+
},
53+
{
54+
"artifactId": "junit-jupiter",
55+
"groupId": "org.testcontainers",
56+
"scope": "test",
57+
},
58+
{
59+
"artifactId": "testcontainers",
60+
"groupId": "org.testcontainers",
61+
"scope": "test",
62+
},
63+
{
64+
"artifactId": "kafka",
65+
"groupId": "org.testcontainers",
66+
"scope": "test",
67+
},
68+
],
69+
],
70+
"addTestLog": [
71+
{
72+
"level": "WARN",
73+
"name": "kafka",
74+
},
75+
{
76+
"level": "WARN",
77+
"name": "org.I0Itec",
78+
},
79+
],
80+
"addTestSpringFactory": [
81+
{
82+
"key": "org.springframework.test.context.ContextCustomizerFactory",
83+
"value": "com.mycompany.myapp.config.KafkaTestContainersSpringContextCustomizerFactory",
84+
},
85+
],
86+
}
87+
`;
88+
89+
exports[`generator - spring-cloud-stream:kafka with defaults options should match files snapshot 1`] = `
90+
{
91+
".yo-rc.json": {
92+
"stateCleared": "modified",
93+
},
94+
"src/main/java/com/mycompany/myapp/broker/KafkaConsumer.java": {
95+
"stateCleared": "modified",
96+
},
97+
"src/main/java/com/mycompany/myapp/broker/KafkaProducer.java": {
98+
"stateCleared": "modified",
99+
},
100+
"src/main/java/com/mycompany/myapp/web/rest/JhipsterKafkaResource.java": {
101+
"stateCleared": "modified",
102+
},
103+
"src/test/java/com/mycompany/myapp/config/EmbeddedKafka.java": {
104+
"stateCleared": "modified",
105+
},
106+
"src/test/java/com/mycompany/myapp/config/KafkaTestContainer.java": {
107+
"stateCleared": "modified",
108+
},
109+
"src/test/java/com/mycompany/myapp/config/KafkaTestContainersSpringContextCustomizerFactory.java": {
110+
"stateCleared": "modified",
111+
},
112+
"src/test/java/com/mycompany/myapp/web/rest/JhipsterKafkaResourceIT.java": {
113+
"stateCleared": "modified",
114+
},
115+
}
116+
`;
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/**
2+
* Copyright 2013-2025 the original author or authors from the JHipster project.
3+
*
4+
* This file is part of the JHipster project, see https://www.jhipster.tech/
5+
* for more information.
6+
*
7+
* Licensed under the Apache License, Version 2.0 (the "License");
8+
* you may not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at
10+
*
11+
* https://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS,
15+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
*/
19+
import { basename, dirname, resolve } from 'node:path';
20+
import { fileURLToPath } from 'node:url';
21+
import { before, describe, expect, it } from 'esmocha';
22+
23+
import { shouldSupportFeatures, testBlueprintSupport } from '../../../../test/support/tests.js';
24+
import { defaultHelpers as helpers, result } from '../../../../lib/testing/index.js';
25+
import Generator from './index.js';
26+
27+
const __filename = fileURLToPath(import.meta.url);
28+
const __dirname = dirname(__filename);
29+
30+
const generator = `${basename(resolve(__dirname, '../../'))}:${basename(__dirname)}`;
31+
32+
describe(`generator - ${generator}`, () => {
33+
shouldSupportFeatures(Generator);
34+
describe('blueprint support', () => testBlueprintSupport(generator));
35+
36+
describe('with defaults options', () => {
37+
before(async () => {
38+
await helpers.runJHipster(generator).withMockedJHipsterGenerators().withMockedSource().withSharedApplication({}).withJHipsterConfig();
39+
});
40+
41+
it('should match files snapshot', () => {
42+
expect(result.getStateSnapshot()).toMatchSnapshot();
43+
});
44+
45+
it('should call source snapshot', () => {
46+
expect(result.sourceCallsArg).toMatchSnapshot();
47+
});
48+
49+
it('should compose with generators', () => {
50+
expect(result.composedMockedGenerators).toMatchInlineSnapshot(`[]`);
51+
});
52+
});
53+
54+
describe('jdl support', () => {
55+
before(async () => {
56+
await helpers
57+
.runJDL('application { config { baseName jhipster, messageBroker kafka } }')
58+
.withMockedJHipsterGenerators()
59+
.withMockedSource()
60+
.withJHipsterConfig();
61+
});
62+
63+
it('should match files snapshot', () => {
64+
expect(result.getSnapshot()).toMatchSnapshot();
65+
});
66+
});
67+
});
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`generator - spring-cloud-stream:pulsar jdl support should match files snapshot 1`] = `
4+
{
5+
".yo-rc.json": {
6+
"contents": "{
7+
"generator-jhipster": {
8+
"baseName": "jhipster",
9+
"creationTimestamp": 1577836800000,
10+
"entities": [],
11+
"messageBroker": "pulsar"
12+
}
13+
}
14+
",
15+
"stateCleared": "modified",
16+
},
17+
}
18+
`;
19+
20+
exports[`generator - spring-cloud-stream:pulsar with defaults options should call source snapshot 1`] = `
21+
{
22+
"addIntegrationTestAnnotation": [
23+
{
24+
"annotation": "EmbeddedPulsar",
25+
"package": "com.mycompany.myapp.config",
26+
},
27+
],
28+
"addMainLog": [
29+
{
30+
"level": "INFO",
31+
"name": "org.apache.pulsar",
32+
},
33+
],
34+
"addMavenDefinition": [
35+
{
36+
"dependencies": [
37+
{
38+
"artifactId": "spring-cloud-stream",
39+
"groupId": "org.springframework.cloud",
40+
},
41+
{
42+
"artifactId": "spring-cloud-stream-binder-pulsar",
43+
"groupId": "org.springframework.cloud",
44+
},
45+
{
46+
"artifactId": "junit-jupiter",
47+
"groupId": "org.testcontainers",
48+
"scope": "test",
49+
},
50+
{
51+
"artifactId": "testcontainers",
52+
"groupId": "org.testcontainers",
53+
"scope": "test",
54+
},
55+
{
56+
"artifactId": "pulsar",
57+
"groupId": "org.testcontainers",
58+
"scope": "test",
59+
},
60+
],
61+
"properties": [
62+
{
63+
"property": "spring-pulsar.version",
64+
"value": undefined,
65+
},
66+
],
67+
},
68+
],
69+
"addTestSpringFactory": [
70+
{
71+
"key": "org.springframework.test.context.ContextCustomizerFactory",
72+
"value": "com.mycompany.myapp.config.PulsarTestContainersSpringContextCustomizerFactory",
73+
},
74+
],
75+
}
76+
`;
77+
78+
exports[`generator - spring-cloud-stream:pulsar with defaults options should match files snapshot 1`] = `
79+
{
80+
".yo-rc.json": {
81+
"stateCleared": "modified",
82+
},
83+
"src/test/java/com/mycompany/myapp/broker/PulsarIT.java": {
84+
"stateCleared": "modified",
85+
},
86+
"src/test/java/com/mycompany/myapp/config/BrokerConfiguration.java": {
87+
"stateCleared": "modified",
88+
},
89+
"src/test/java/com/mycompany/myapp/config/EmbeddedPulsar.java": {
90+
"stateCleared": "modified",
91+
},
92+
"src/test/java/com/mycompany/myapp/config/PulsarTestContainer.java": {
93+
"stateCleared": "modified",
94+
},
95+
"src/test/java/com/mycompany/myapp/config/PulsarTestContainersSpringContextCustomizerFactory.java": {
96+
"stateCleared": "modified",
97+
},
98+
}
99+
`;

0 commit comments

Comments
 (0)