Skip to content

Commit

Permalink
Merge pull request #22118 from qmonmert/fakerjs800
Browse files Browse the repository at this point in the history
build(deps): bump @faker-js/faker from 7.6.0 to 8.0.1
  • Loading branch information
DanielFran committed Jul 9, 2023
2 parents 3ada22b + c7aeb24 commit 6e025e0
Show file tree
Hide file tree
Showing 10 changed files with 53 additions and 49 deletions.
16 changes: 8 additions & 8 deletions generators/base-application/support/prepare-field.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -123,23 +123,23 @@ function generateFakeDataForField(field, faker, changelogDate, type = 'csv') {
} else if (field.fieldIsEnum) {
if (field.fieldValues.length !== 0) {
const enumValues = field.enumValues;
data = enumValues[faker.datatype.number(enumValues.length - 1)].name;
data = enumValues[faker.number.int(enumValues.length - 1)].name;
} else {
this.log.warn(`Enum ${field.fieldType} is not valid`);
data = undefined;
}
} else if (field.fieldType === DURATION && type === 'cypress') {
data = `PT${faker.datatype.number({ min: 1, max: 59 })}M`;
data = `PT${faker.number.int({ min: 1, max: 59 })}M`;

// eslint-disable-next-line no-template-curly-in-string
} else if ([INTEGER, LONG, FLOAT, '${floatType}', DOUBLE, BIG_DECIMAL, DURATION].includes(field.fieldType)) {
data = faker.datatype.number({
max: field.fieldValidateRulesMax ? parseInt(field.fieldValidateRulesMax, 10) : undefined,
min: field.fieldValidateRulesMin ? parseInt(field.fieldValidateRulesMin, 10) : undefined,
data = faker.number.int({
max: field.fieldValidateRulesMax ? parseInt(field.fieldValidateRulesMax, 10) : 32767,
min: field.fieldValidateRulesMin ? parseInt(field.fieldValidateRulesMin, 10) : 0,
});
} else if ([INSTANT, ZONED_DATE_TIME, LOCAL_DATE].includes(field.fieldType)) {
// Iso: YYYY-MM-DDTHH:mm:ss.sssZ
const date = faker.date.recent(1, changelogDate);
const date = faker.date.recent({ days: 1, refDate: changelogDate });
const isoDate = date.toISOString();
if (field.fieldType === LOCAL_DATE) {
data = isoDate.split('T')[0];
Expand All @@ -160,9 +160,9 @@ function generateFakeDataForField(field, faker, changelogDate, type = 'csv') {
} else if (field.fieldType === BYTES && field.fieldTypeBlobContent === TEXT) {
data = '../fake-data/blob/hipster.txt';
} else if (field.fieldType === STRING) {
data = field.id ? faker.datatype.uuid() : faker.helpers.fake(fakeStringTemplateForFieldName(field.columnName));
data = field.id ? faker.string.uuid() : faker.helpers.fake(fakeStringTemplateForFieldName(field.columnName));
} else if (field.fieldType === UUID) {
data = faker.datatype.uuid();
data = faker.string.uuid();
} else if (field.fieldType === BOOLEAN) {
data = faker.datatype.boolean();
} else {
Expand Down
14 changes: 6 additions & 8 deletions generators/base/support/faker.mts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class RandexpWithFaker extends Randexp {
}
// In order to have consistent results with RandExp, the RNG is seeded.
this.randInt = (from: number, to?: number): number => {
return faker.datatype.number({ min: from, max: to });
return faker.number.int({ min: from, max: to });
};
}
}
Expand All @@ -54,23 +54,21 @@ class FakerWithRandexp extends Faker {
// eslint-disable-next-line import/prefer-default-export
export async function createFaker(nativeLanguage = 'en') {
nativeLanguage = languageToJavaLanguage(nativeLanguage);
let nativeFakerInstance;
let locale;
// Faker >=6 doesn't exports locales by itself, it exports a faker instance with the locale.
// We need a Faker instance for each entity, to build additional fake instances, use the locale from the exported localized faker instance.
// See https://github.com/faker-js/faker/pull/642
try {
// eslint-disable-next-line import/no-dynamic-require
nativeFakerInstance = (await import(`@faker-js/faker/locale/${nativeLanguage}`)).faker;
// eslint-disable-next-line import/no-dynamic-require, quotes
locale = (await import(`@faker-js/faker`))[nativeLanguage];
} catch (error) {
// Faker not implemented for the native language, fallback to en.
// eslint-disable-next-line import/no-unresolved, import/no-dynamic-require
nativeFakerInstance = (await import('@faker-js/faker/locale/en')).faker;
locale = (await import('@faker-js/faker')).en;
}

const faker = new FakerWithRandexp({
locales: nativeFakerInstance.locales,
locale: nativeFakerInstance.locale,
localeFallback: nativeFakerInstance.localeFallback,
locale: [locale],
});
faker.createRandexp = (pattern, m) => new RandexpWithFaker(pattern, m, faker);
return faker;
Expand Down
2 changes: 1 addition & 1 deletion generators/docker-compose/generator.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ export default class DockerComposeGenerator extends BaseDockerGenerator {
if (appConfig.applicationType === GATEWAY || appConfig.applicationType === MONOLITH) {
if (this.keycloakSecrets === undefined && appConfig.authenticationType === OAUTH2) {
faker.seed(stringHashCode(appConfig.baseName));
this.keycloakSecrets = Array.from(Array(6), () => faker.datatype.uuid());
this.keycloakSecrets = Array.from(Array(6), () => faker.string.uuid());
}
this.keycloakRedirectUris += `"http://localhost:${appConfig.composePort}/*", "https://localhost:${appConfig.composePort}/*", `;
if (appConfig.devServerPort !== undefined) {
Expand Down
2 changes: 1 addition & 1 deletion generators/docker/generator.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ export default class DockerGenerator extends BaseApplicationGenerator {
if (application.authenticationTypeOauth2) {
const faker = await createFaker();
faker.seed(stringHashCode(application.baseName));
application.keycloakSecrets = Array.from(Array(6), () => faker.datatype.uuid());
application.keycloakSecrets = Array.from(Array(6), () => faker.string.uuid());
}
await this.writeFiles({
sections: dockerFiles,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,16 +131,16 @@ ROLE_USER
},
"src/main/resources/config/liquibase/fake-data/20200102000100_entity_customer.csv": {
"contents": "id;foo
1;Frozen
2;South Real Crest
3;male Wooden
4;Marketing
5;Maserati joule calculate
6;Incredible Tactics Gasoline
7;Gloves
8;Money
9;Associate experiences
10;Southwest
1;ubiquitous
2;Awesome Hydrogen fluid
3;New East
4;pfft Gloves Marketing
5;Minivan similique elaborate
6;Officer
7;Planner Gasoline
8;sexy
9;redefine
10;Money
",
"stateCleared": "modified",
},
Expand Down Expand Up @@ -263,16 +263,16 @@ ROLE_USER
},
"src/main/resources/config/liquibase/fake-data/20200102000100_entity_customer.csv": {
"contents": "id;foo
1;Frozen
2;South Real Crest
3;male Wooden
4;Marketing
5;Maserati joule calculate
6;Incredible Tactics Gasoline
7;Gloves
8;Money
9;Associate experiences
10;Southwest
1;ubiquitous
2;Awesome Hydrogen fluid
3;New East
4;pfft Gloves Marketing
5;Minivan similique elaborate
6;Officer
7;Planner Gasoline
8;sexy
9;redefine
10;Money
",
"stateCleared": "modified",
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1153,7 +1153,7 @@ entity Customer {
entity: jdlApplicationEntitieWithByteTypes,
bytesFields: true,
testContent:
'1;geez;4178;../fake-data/blob/hipster.txt;../fake-data/blob/hipster.png;image/png;../fake-data/blob/hipster.png;image/png;Laptop;17242',
'1;geez;1369;../fake-data/blob/hipster.txt;../fake-data/blob/hipster.png;image/png;../fake-data/blob/hipster.png;image/png;Laptop;5650',
contentRequired: true,
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ for (lineNb = 0; lineNb < entity.fakeDataCount; lineNb++) {
const otherLiquibaseFakeData = relationship.otherEntity.liquibaseFakeData;
let relationshipRow = lineNb;
if (relationship.otherEntity.fakeDataCount > 0 && relationshipRow >= relationship.otherEntity.fakeDataCount && !relationship.unique) {
relationshipRow = entity.faker.datatype.number({min: 1, max: relationship.otherEntity.fakeDataCount}) - 1;
relationshipRow = entity.faker.number.int({min: 1, max: relationship.otherEntity.fakeDataCount}) - 1;
}
if (relationshipRow < relationship.otherEntity.fakeDataCount) {
line.push(otherLiquibaseFakeData[relationshipRow][relationship.otherEntity.primaryKey.name]);
Expand Down
18 changes: 12 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@
"watch": "concurrently \"tsc --watch\" \"node ./watch.mjs\""
},
"dependencies": {
"@faker-js/faker": "7.6.0",
"@faker-js/faker": "8.0.2",
"@iarna/toml": "3.0.0",
"@types/ejs": "3.1.2",
"@types/lodash": "4.14.195",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"cacheProvider": "no",
"clientFramework": "angular",
"clientPackageManager": "npm",
"creationTimestamp": 1596513172471,
"creationTimestamp": 1596513272473,
"databaseType": "sql",
"devDatabaseType": "h2Memory",
"enableHibernateCache": false,
Expand All @@ -19,7 +19,7 @@
"nativeLanguage": "en",
"packageFolder": "tech/jhipster/sample",
"packageName": "tech.jhipster.sample",
"prodDatabaseType": "mariadb",
"prodDatabaseType": "postgresql",
"reactive": true,
"rememberMeKey": "a5e93fdeb16e2ee2dc4a629b5dbdabb30f968e418dfc0483c53afdc695cfac96d06cf5c581cbefb93e3aaa241880857fcafe",
"searchEngine": "elasticsearch",
Expand Down

0 comments on commit 6e025e0

Please sign in to comment.