Skip to content

Commit 7931e2b

Browse files
committed
Improve packages exports
1 parent a18ff4d commit 7931e2b

File tree

136 files changed

+616
-488
lines changed

Some content is hidden

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

136 files changed

+616
-488
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,4 +181,4 @@ check-documentation-videos-format: ## Check the documentation format
181181
./scripts/check-documentation-videos-format.sh
182182

183183
release: ## Start the release process and publish the packages to npm using lerna
184-
./scripts/release.sh
184+
./scripts/release.sh

examples/crm/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@
44
"private": true,
55
"type": "module",
66
"dependencies": {
7+
"@faker-js/faker": "^10.0.0",
78
"@hello-pangea/dnd": "^16.3.0",
89
"@mui/icons-material": "^5.16.12",
910
"@mui/material": "^5.16.12",
1011
"@nivo/bar": "^0.80.0",
1112
"@nivo/core": "^0.80.0",
1213
"clsx": "^2.1.1",
1314
"date-fns": "^3.6.0",
14-
"faker": "~5.4.0",
1515
"fakerest": "4.1.3",
1616
"lodash": "~4.17.5",
1717
"papaparse": "^5.4.1",
@@ -28,7 +28,6 @@
2828
"@testing-library/jest-dom": "^6.4.5",
2929
"@testing-library/react": "^15.0.7",
3030
"@testing-library/user-event": "^14.5.2",
31-
"@types/faker": "^5.1.7",
3231
"@types/jest": "^29.5.2",
3332
"@types/jsonexport": "^3.0.5",
3433
"@types/lodash": "~4.14.168",

examples/crm/src/providers/fakerest/dataGenerator/companies.ts

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,4 @@
1-
import {
2-
address,
3-
company,
4-
internet,
5-
lorem,
6-
phone,
7-
random,
8-
} from 'faker/locale/en_US';
1+
import { faker } from '@faker-js/faker';
92
import { randomDate } from './utils';
103

114
import { defaultCompanySectors } from '../../../root/defaultConfiguration';
@@ -18,35 +11,42 @@ const regex = /\W+/;
1811

1912
export const generateCompanies = (db: Db): Required<Company>[] => {
2013
return Array.from(Array(55).keys()).map(id => {
21-
const name = company.companyName();
14+
const name = faker.company.name();
2215
return {
2316
id,
2417
name: name,
2518
logo: {
26-
title: lorem.text(1),
19+
title: faker.lorem.text(),
2720
src: `./logos/${id}.png`,
2821
} as RAFile,
29-
sector: random.arrayElement(defaultCompanySectors),
30-
size: random.arrayElement(sizes) as 1 | 10 | 50 | 250 | 500,
22+
sector: faker.helpers.arrayElement(defaultCompanySectors),
23+
size: faker.helpers.arrayElement(sizes) as 1 | 10 | 50 | 250 | 500,
3124
linkedin_url: `https://www.linkedin.com/company/${name
3225
.toLowerCase()
3326
.replace(regex, '_')}`,
34-
website: internet.url(),
35-
phone_number: phone.phoneNumber(),
36-
address: address.streetAddress(),
37-
zipcode: address.zipCode(),
38-
city: address.city(),
39-
stateAbbr: address.stateAbbr(),
27+
website: faker.internet.url(),
28+
phone_number: faker.phone.number(),
29+
address: faker.location.streetAddress(),
30+
zipcode: faker.location.zipCode(),
31+
city: faker.location.city(),
32+
stateAbbr: faker.location.state({ abbreviated: true }),
4033
nb_contacts: 0,
4134
nb_deals: 0,
4235
// at least 1/3rd of companies for Jane Doe
4336
sales_id:
44-
random.number(2) === 0 ? 0 : random.arrayElement(db.sales).id,
37+
faker.number.int(2) === 0
38+
? 0
39+
: faker.helpers.arrayElement(db.sales).id,
4540
created_at: randomDate().toISOString(),
46-
description: lorem.paragraph(),
47-
revenue: random.arrayElement(['$1M', '$10M', '$100M', '$1B']),
48-
tax_identifier: random.alphaNumeric(10),
49-
country: random.arrayElement(['USA', 'France', 'UK']),
41+
description: faker.lorem.paragraph(),
42+
revenue: faker.helpers.arrayElement([
43+
'$1M',
44+
'$10M',
45+
'$100M',
46+
'$1B',
47+
]),
48+
tax_identifier: faker.string.alphanumeric({ length: 10 }),
49+
country: faker.helpers.arrayElement(['USA', 'France', 'UK']),
5050
context_links: [],
5151
};
5252
});
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { lorem, random } from 'faker/locale/en_US';
1+
import { faker } from '@faker-js/faker';
22

33
import { defaultNoteStatuses } from '../../../root/defaultConfiguration';
44
import { ContactNote } from '../../../types';
@@ -7,7 +7,7 @@ import { randomDate } from './utils';
77

88
export const generateContactNotes = (db: Db): ContactNote[] => {
99
return Array.from(Array(1200).keys()).map(id => {
10-
const contact = random.arrayElement(db.contacts);
10+
const contact = faker.helpers.arrayElement(db.contacts);
1111
const date = randomDate(new Date(contact.first_seen));
1212
contact.last_seen =
1313
date > new Date(contact.last_seen)
@@ -16,10 +16,10 @@ export const generateContactNotes = (db: Db): ContactNote[] => {
1616
return {
1717
id,
1818
contact_id: contact.id,
19-
text: lorem.paragraphs(random.number({ min: 1, max: 4 })),
19+
text: faker.lorem.paragraphs(faker.number.int({ min: 1, max: 4 })),
2020
date: date.toISOString(),
2121
sales_id: contact.sales_id,
22-
status: random.arrayElement(defaultNoteStatuses).value,
22+
status: faker.helpers.arrayElement(defaultNoteStatuses).value,
2323
};
2424
});
2525
};

examples/crm/src/providers/fakerest/dataGenerator/contacts.ts

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,4 @@
1-
import {
2-
company as fakerCompany,
3-
internet,
4-
lorem,
5-
name,
6-
phone,
7-
random,
8-
} from 'faker/locale/en_US';
1+
import { faker } from '@faker-js/faker';
92

103
import {
114
defaultContactGender,
@@ -30,18 +23,21 @@ export const generateContacts = (db: Db): Required<Contact>[] => {
3023
return Array.from(Array(500).keys()).map(id => {
3124
const has_avatar =
3225
weightedBoolean(25) && numberOfContacts < nbAvailblePictures;
33-
const gender = random.arrayElement(defaultContactGender).value;
34-
const first_name = name.firstName(gender as any);
35-
const last_name = name.lastName();
36-
const email = internet.email(first_name, last_name);
26+
const gender = faker.helpers.arrayElement(defaultContactGender).value;
27+
const first_name = faker.person.firstName(gender as any);
28+
const last_name = faker.person.lastName();
29+
const email = faker.internet.email({
30+
firstName: first_name,
31+
lastName: last_name,
32+
});
3733
const avatar = {
3834
src: has_avatar
3935
? 'https://marmelab.com/posters/avatar-' +
4036
(223 - numberOfContacts) +
4137
'.jpeg'
4238
: undefined,
4339
};
44-
const title = fakerCompany.bsAdjective();
40+
const title = faker.company.buzzAdjective();
4541

4642
if (has_avatar) {
4743
numberOfContacts++;
@@ -50,7 +46,7 @@ export const generateContacts = (db: Db): Required<Contact>[] => {
5046
// choose company with people left to know
5147
let company: Required<Company>;
5248
do {
53-
company = random.arrayElement(db.companies);
49+
company = faker.helpers.arrayElement(db.companies);
5450
} while (company.nb_contacts >= maxContacts[company.size]);
5551
company.nb_contacts++;
5652

@@ -68,19 +64,22 @@ export const generateContacts = (db: Db): Required<Contact>[] => {
6864
company_id: company.id,
6965
company_name: company.name,
7066
email,
71-
phone_1_number: phone.phoneNumber(),
72-
phone_1_type: random.arrayElement(['Work', 'Home', 'Other']),
73-
phone_2_number: phone.phoneNumber(),
74-
phone_2_type: random.arrayElement(['Work', 'Home', 'Other']),
75-
background: lorem.sentence(),
76-
acquisition: random.arrayElement(['inbound', 'outbound']),
67+
phone_1_number: faker.phone.number(),
68+
phone_1_type: faker.helpers.arrayElement(['Work', 'Home', 'Other']),
69+
phone_2_number: faker.phone.number(),
70+
phone_2_type: faker.helpers.arrayElement(['Work', 'Home', 'Other']),
71+
background: faker.lorem.sentence(),
72+
acquisition: faker.helpers.arrayElement(['inbound', 'outbound']),
7773
avatar,
7874
first_seen: first_seen,
7975
last_seen: last_seen,
8076
has_newsletter: weightedBoolean(30),
81-
status: random.arrayElement(defaultNoteStatuses).value,
82-
tags: random
83-
.arrayElements(db.tags, random.arrayElement([0, 0, 0, 1, 1, 2]))
77+
status: faker.helpers.arrayElement(defaultNoteStatuses).value,
78+
tags: faker.helpers
79+
.arrayElements(
80+
db.tags,
81+
faker.helpers.arrayElement([0, 0, 0, 1, 1, 2])
82+
)
8483
.map(tag => tag.id), // finalize
8584
sales_id: company.sales_id,
8685
nb_tasks: 0,

examples/crm/src/providers/fakerest/dataGenerator/dealNotes.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
import { random, lorem } from 'faker/locale/en_US';
1+
import { faker } from '@faker-js/faker';
22

33
import { Db } from './types';
44
import { randomDate } from './utils';
55

66
export const generateDealNotes = (db: Db) => {
77
return Array.from(Array(300).keys()).map(id => {
8-
const deal = random.arrayElement(db.deals);
8+
const deal = faker.helpers.arrayElement(db.deals);
99
return {
1010
id,
1111
deal_id: deal.id,
12-
text: lorem.paragraphs(random.number({ min: 1, max: 4 })),
12+
text: faker.lorem.paragraphs(faker.number.int({ min: 1, max: 4 })),
1313
date: randomDate(
1414
new Date(db.deals[deal.id as number].created_at)
1515
).toISOString(),

examples/crm/src/providers/fakerest/dataGenerator/deals.ts

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { add } from 'date-fns';
2-
import { lorem, random } from 'faker/locale/en_US';
2+
import { faker } from '@faker-js/faker';
33

44
import {
55
defaultDealCategories,
@@ -11,13 +11,13 @@ import { randomDate } from './utils';
1111

1212
export const generateDeals = (db: Db): Deal[] => {
1313
const deals = Array.from(Array(50).keys()).map(id => {
14-
const company = random.arrayElement(db.companies);
14+
const company = faker.helpers.arrayElement(db.companies);
1515
company.nb_deals++;
16-
const contacts = random.arrayElements(
16+
const contacts = faker.helpers.arrayElements(
1717
db.contacts.filter(contact => contact.company_id === company.id),
18-
random.number({ min: 1, max: 3 })
18+
faker.number.int({ min: 1, max: 3 })
1919
);
20-
const lowercaseName = lorem.words();
20+
const lowercaseName = faker.lorem.words();
2121
const created_at = randomDate(
2222
new Date(company.created_at)
2323
).toISOString();
@@ -32,10 +32,12 @@ export const generateDeals = (db: Db): Deal[] => {
3232
name: lowercaseName[0].toUpperCase() + lowercaseName.slice(1),
3333
company_id: company.id,
3434
contact_ids: contacts.map(contact => contact.id),
35-
category: random.arrayElement(defaultDealCategories),
36-
stage: random.arrayElement(defaultDealStages).value,
37-
description: lorem.paragraphs(random.number({ min: 1, max: 4 })),
38-
amount: random.number(1000) * 100,
35+
category: faker.helpers.arrayElement(defaultDealCategories),
36+
stage: faker.helpers.arrayElement(defaultDealStages).value,
37+
description: faker.lorem.paragraphs(
38+
faker.number.int({ min: 1, max: 4 })
39+
),
40+
amount: faker.number.int(1000) * 100,
3941
created_at,
4042
updated_at: randomDate(new Date(created_at)).toISOString(),
4143
expected_closing_date,

examples/crm/src/providers/fakerest/dataGenerator/sales.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
1-
import { internet, name } from 'faker/locale/en_US';
1+
import { faker } from '@faker-js/faker';
22

33
import { RAFile, Sale } from '../../../types';
44
import { Db } from './types';
55

66
export const generateSales = (_: Db): Sale[] => {
77
const randomSales = Array.from(Array(5).keys()).map(id => {
8-
const first_name = name.firstName();
9-
const last_name = name.lastName();
10-
const email = internet.email(first_name, last_name);
8+
const first_name = faker.person.firstName();
9+
const last_name = faker.person.lastName();
10+
const email = faker.internet.email({
11+
firstName: first_name,
12+
lastName: last_name,
13+
});
1114

1215
return {
1316
id: id + 1,

examples/crm/src/providers/fakerest/dataGenerator/tasks.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { lorem, random } from 'faker/locale/en_US';
1+
import { faker } from '@faker-js/faker';
22

33
import { defaultTaskTypes } from '../../../root/defaultConfiguration';
44
import { Task } from '../../../types';
@@ -37,15 +37,17 @@ export const type: TaskType[] = [
3737

3838
export const generateTasks = (db: Db) => {
3939
return Array.from(Array(400).keys()).map<Task>(id => {
40-
const contact = random.arrayElement(db.contacts);
40+
const contact = faker.helpers.arrayElement(db.contacts);
4141
contact.nb_tasks++;
4242
return {
4343
id,
4444
contact_id: contact.id,
45-
type: random.arrayElement(defaultTaskTypes),
46-
text: lorem.sentence(),
45+
type: faker.helpers.arrayElement(defaultTaskTypes),
46+
text: faker.lorem.sentence(),
4747
due_date: randomDate(
48-
random.boolean() ? new Date() : new Date(contact.first_seen),
48+
faker.datatype.boolean()
49+
? new Date()
50+
: new Date(contact.first_seen),
4951
new Date(Date.now() + 100 * 24 * 60 * 60 * 1000)
5052
).toISOString(),
5153
done_date: undefined,
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import faker from 'faker/locale/en';
1+
import { faker } from '@faker-js/faker';
22

33
export const weightedArrayElement = (values: any[], weights: any) =>
4-
faker.random.arrayElement(
4+
faker.helpers.arrayElement(
55
values.reduce(
66
(acc, value, index) =>
77
acc.concat(new Array(weights[index]).fill(value)),
@@ -10,7 +10,7 @@ export const weightedArrayElement = (values: any[], weights: any) =>
1010
);
1111

1212
export const weightedBoolean = (likelyhood: number) =>
13-
faker.random.number(99) < likelyhood;
13+
faker.number.int(99) < likelyhood;
1414

1515
export const randomDate = (minDate?: Date, maxDate?: Date) => {
1616
const minTs =
@@ -19,11 +19,11 @@ export const randomDate = (minDate?: Date, maxDate?: Date) => {
1919
: Date.now() - 5 * 365 * 24 * 60 * 60 * 1000; // 5 years
2020
const maxTs = maxDate instanceof Date ? maxDate.getTime() : Date.now();
2121
const range = maxTs - minTs;
22-
const randomRange = faker.random.number({ max: range });
22+
const randomRange = faker.number.int({ max: range });
2323
// move it more towards today to account for traffic increase
2424
const ts = Math.sqrt(randomRange / range) * range;
2525
return new Date(minTs + ts);
2626
};
2727

2828
export const randomFloat = (min: number, max: number) =>
29-
parseFloat(faker.random.number({ min, max, precision: 0.01 }).toFixed(2));
29+
parseFloat(faker.number.float({ min, max, fractionDigits: 2 }).toFixed(2));

0 commit comments

Comments
 (0)