diff --git a/packages/server/modules/cli/commands/db/seed/users.js b/packages/server/modules/cli/commands/db/seed/users.js index 1d7331cf2d..649189b22a 100644 --- a/packages/server/modules/cli/commands/db/seed/users.js +++ b/packages/server/modules/cli/commands/db/seed/users.js @@ -3,28 +3,36 @@ const { Users, ServerAcl } = require('@/modules/core/dbSchema') const { Roles } = require('@/modules/core/helpers/mainConstants') const { faker } = require('@faker-js/faker') const { range } = require('lodash') +const { UniqueEnforcer } = require('enforce-unique') const RETRY_COUNT = 3 const UNIQUE_MAX_TIME = 500 +const uniqueEnforcer = new UniqueEnforcer() + function createFakeUser() { return { - id: faker.unique(faker.random.alphaNumeric, [10], { maxTime: UNIQUE_MAX_TIME }), - name: faker.name.firstName() + ' ' + faker.name.lastName(), + id: uniqueEnforcer.enforce(() => faker.string.alphanumeric(10), { + maxTime: UNIQUE_MAX_TIME + }), + name: faker.person.firstName() + ' ' + faker.person.lastName(), bio: faker.lorem.lines(5), - company: faker.company.companyName(), - email: faker.unique( - faker.internet.email, - [ - faker.unique(faker.random.alphaNumeric, [10]), - faker.unique(faker.random.alphaNumeric, [10]) - ], - { maxTime: UNIQUE_MAX_TIME } + company: faker.company.name(), + email: uniqueEnforcer.enforce( + () => + faker.internet.email({ + firstName: faker.string.alphanumeric(), + lastName: faker.string.alphanumeric() + }), + { + maxTime: UNIQUE_MAX_TIME, + maxRetries: RETRY_COUNT + } ), verified: faker.datatype.boolean(), - avatar: faker.random.alphaNumeric(255), + avatar: faker.string.alphanumeric(255), ip: faker.internet.ipv4(), - passwordDigest: faker.random.alphaNumeric(255) + passwordDigest: faker.string.alphanumeric(255) } } diff --git a/packages/server/package.json b/packages/server/package.json index 1f9ea49fac..5a287753ee 100644 --- a/packages/server/package.json +++ b/packages/server/package.json @@ -162,6 +162,7 @@ "concurrently": "^7.0.0", "cross-env": "^7.0.3", "deep-equal-in-any-order": "^1.1.15", + "enforce-unique": "^1.3.0", "eslint": "^8.11.0", "eslint-config-prettier": "^8.5.0", "http-proxy-middleware": "v3.0.0-beta.0", diff --git a/yarn.lock b/yarn.lock index b56eb6917a..8f1641e80c 100644 --- a/yarn.lock +++ b/yarn.lock @@ -15620,6 +15620,7 @@ __metadata: deep-equal-in-any-order: "npm:^1.1.15" dotenv: "npm:^8.2.0" ejs: "npm:^3.1.8" + enforce-unique: "npm:^1.3.0" eslint: "npm:^8.11.0" eslint-config-prettier: "npm:^8.5.0" eventemitter2: "npm:^6.4.7" @@ -28386,6 +28387,13 @@ __metadata: languageName: node linkType: hard +"enforce-unique@npm:^1.3.0": + version: 1.3.0 + resolution: "enforce-unique@npm:1.3.0" + checksum: 10/c92da297787ff17ac1671c5c86ddc075308fb895fc0d728d2860ce152d1ab2f7b04d5c41ba4b86e75175c723b70aaf7f3d282930ec464fff3a96d3d8ddcdb4ba + languageName: node + linkType: hard + "enhanced-resolve@npm:^4.1.1": version: 4.5.0 resolution: "enhanced-resolve@npm:4.5.0"