cap-mock-generator 1.0.7 → 1.0.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -55,18 +55,47 @@ class CdsParserService {
|
|
|
55
55
|
const properties = [];
|
|
56
56
|
for (const [propName, propDef] of Object.entries(definition.elements)) {
|
|
57
57
|
const property = propDef;
|
|
58
|
-
const
|
|
58
|
+
const rawType = property.type || '';
|
|
59
|
+
const lowerType = rawType.toLowerCase();
|
|
60
|
+
const isCommonCountryType = rawType === 'Country' ||
|
|
61
|
+
rawType === 'sap.common.Country' ||
|
|
62
|
+
lowerType.endsWith('.country');
|
|
63
|
+
const isCommonCurrencyType = rawType === 'Currency' ||
|
|
64
|
+
rawType === 'sap.common.Currency' ||
|
|
65
|
+
lowerType.endsWith('.currency');
|
|
66
|
+
if (isCommonCountryType || isCommonCurrencyType) {
|
|
67
|
+
properties.push({
|
|
68
|
+
name: `${propName}_code`,
|
|
69
|
+
type: 'cds.String',
|
|
70
|
+
isAssociation: false,
|
|
71
|
+
isKey: !!property.key
|
|
72
|
+
});
|
|
73
|
+
continue;
|
|
74
|
+
}
|
|
75
|
+
const isManagedAssociation = property.type === 'cds.Association' &&
|
|
76
|
+
typeof property.target === 'string' &&
|
|
77
|
+
!property.on &&
|
|
78
|
+
property.cardinality?.max !== '*';
|
|
79
|
+
if (isManagedAssociation) {
|
|
80
|
+
properties.push({
|
|
81
|
+
name: `${propName}_ID`,
|
|
82
|
+
type: 'cds.UUID',
|
|
83
|
+
isAssociation: false,
|
|
84
|
+
isKey: !!property.key
|
|
85
|
+
});
|
|
86
|
+
continue;
|
|
87
|
+
}
|
|
88
|
+
const isAssociation = property.type === 'cds.Association' ||
|
|
59
89
|
property.type === 'cds.Composition' ||
|
|
60
|
-
property.
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
if (typeof property.target === 'string') {
|
|
64
|
-
finalType = `Association.${property.target}`;
|
|
90
|
+
!!property.target;
|
|
91
|
+
if (isAssociation) {
|
|
92
|
+
continue;
|
|
65
93
|
}
|
|
66
94
|
properties.push({
|
|
67
95
|
name: propName,
|
|
68
|
-
type:
|
|
69
|
-
isAssociation:
|
|
96
|
+
type: property.type || 'cds.String',
|
|
97
|
+
isAssociation: false,
|
|
98
|
+
isKey: !!property.key
|
|
70
99
|
});
|
|
71
100
|
}
|
|
72
101
|
parsedEntities.push({
|
|
@@ -2,6 +2,50 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const faker_1 = require("@faker-js/faker");
|
|
4
4
|
class FakerService {
|
|
5
|
+
generateKeyValue(prop, index) {
|
|
6
|
+
const lowerPropName = prop.name.toLowerCase();
|
|
7
|
+
if (lowerPropName === 'fromcurrency') {
|
|
8
|
+
const values = ['USD', 'EUR', 'TRY', 'GBP', 'CHF', 'JPY'];
|
|
9
|
+
return values[index % values.length];
|
|
10
|
+
}
|
|
11
|
+
if (lowerPropName === 'tocurrency') {
|
|
12
|
+
const values = ['EUR', 'USD', 'GBP', 'TRY', 'JPY', 'CHF'];
|
|
13
|
+
return values[index % values.length];
|
|
14
|
+
}
|
|
15
|
+
if (lowerPropName === 'validfrom' && prop.type === 'cds.Date') {
|
|
16
|
+
const date = new Date(2024, 0, 1);
|
|
17
|
+
date.setDate(date.getDate() + index);
|
|
18
|
+
return date.toISOString().split('T')[0];
|
|
19
|
+
}
|
|
20
|
+
switch (prop.type) {
|
|
21
|
+
case 'cds.UUID':
|
|
22
|
+
return faker_1.faker.string.uuid();
|
|
23
|
+
case 'cds.Integer':
|
|
24
|
+
return index + 1;
|
|
25
|
+
case 'cds.Date': {
|
|
26
|
+
const date = new Date(2024, 0, 1);
|
|
27
|
+
date.setDate(date.getDate() + index);
|
|
28
|
+
return date.toISOString().split('T')[0];
|
|
29
|
+
}
|
|
30
|
+
case 'cds.DateTime':
|
|
31
|
+
case 'cds.Timestamp': {
|
|
32
|
+
const date = new Date(2024, 0, 1, 0, 0, 0);
|
|
33
|
+
date.setMinutes(date.getMinutes() + index);
|
|
34
|
+
return date.toISOString();
|
|
35
|
+
}
|
|
36
|
+
default: {
|
|
37
|
+
if (lowerPropName.includes('currency')) {
|
|
38
|
+
const currencies = ['USD', 'EUR', 'TRY', 'GBP', 'CHF', 'JPY'];
|
|
39
|
+
return currencies[index % currencies.length];
|
|
40
|
+
}
|
|
41
|
+
if (lowerPropName.includes('country')) {
|
|
42
|
+
const countries = ['US', 'DE', 'TR', 'GB', 'FR', 'NL'];
|
|
43
|
+
return countries[index % countries.length];
|
|
44
|
+
}
|
|
45
|
+
return `${prop.name}_${index + 1}`;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
5
49
|
generateValue(propName, propType, parentIds) {
|
|
6
50
|
const lowerPropName = propName.toLowerCase();
|
|
7
51
|
if (lowerPropName.endsWith('id') && lowerPropName !== 'id') {
|
|
@@ -12,6 +56,12 @@ class FakerService {
|
|
|
12
56
|
if (lowerPropName.includes('mail')) {
|
|
13
57
|
return faker_1.faker.internet.email();
|
|
14
58
|
}
|
|
59
|
+
if (lowerPropName.includes('firstname')) {
|
|
60
|
+
return faker_1.faker.person.firstName();
|
|
61
|
+
}
|
|
62
|
+
if (lowerPropName.includes('lastname')) {
|
|
63
|
+
return faker_1.faker.person.lastName();
|
|
64
|
+
}
|
|
15
65
|
if (lowerPropName.includes('name')) {
|
|
16
66
|
return faker_1.faker.person.fullName();
|
|
17
67
|
}
|
|
@@ -21,29 +71,36 @@ class FakerService {
|
|
|
21
71
|
if (lowerPropName.includes('receiver')) {
|
|
22
72
|
return faker_1.faker.internet.username();
|
|
23
73
|
}
|
|
24
|
-
if (lowerPropName.includes('createdby')) {
|
|
74
|
+
if (lowerPropName.includes('createdby') || lowerPropName.includes('modifiedby')) {
|
|
25
75
|
return faker_1.faker.internet.username();
|
|
26
76
|
}
|
|
77
|
+
if (lowerPropName === 'country_code' || lowerPropName.endsWith('country_code')) {
|
|
78
|
+
return faker_1.faker.helpers.arrayElement(['TR', 'DE', 'US', 'GB', 'FR', 'NL']);
|
|
79
|
+
}
|
|
80
|
+
if (lowerPropName === 'currency_code' || lowerPropName.endsWith('currency_code')) {
|
|
81
|
+
return faker_1.faker.helpers.arrayElement(['TRY', 'EUR', 'USD', 'GBP', 'CHF']);
|
|
82
|
+
}
|
|
83
|
+
if (lowerPropName.endsWith('currency') || lowerPropName.endsWith('code')) {
|
|
84
|
+
return faker_1.faker.string.alpha({ length: 3, casing: 'upper' });
|
|
85
|
+
}
|
|
27
86
|
switch (propType) {
|
|
28
|
-
case 'cds.
|
|
87
|
+
case 'cds.Date':
|
|
88
|
+
return faker_1.faker.date.anytime().toISOString().split('T')[0];
|
|
89
|
+
case 'cds.UUID':
|
|
29
90
|
return faker_1.faker.string.uuid();
|
|
30
|
-
|
|
31
|
-
case 'cds.Integer': {
|
|
91
|
+
case 'cds.Integer':
|
|
32
92
|
return faker_1.faker.number.int({ min: 1, max: 60 });
|
|
33
|
-
|
|
34
|
-
case 'cds.Decimal': {
|
|
93
|
+
case 'cds.Decimal':
|
|
35
94
|
return faker_1.faker.number.float({ min: 10, max: 500, multipleOf: 0.01 });
|
|
36
|
-
|
|
37
|
-
case 'cds.Boolean': {
|
|
95
|
+
case 'cds.Boolean':
|
|
38
96
|
return faker_1.faker.datatype.boolean();
|
|
39
|
-
}
|
|
40
97
|
case 'cds.DateTime':
|
|
41
|
-
case 'cds.Timestamp':
|
|
98
|
+
case 'cds.Timestamp':
|
|
42
99
|
return faker_1.faker.date.past().toISOString();
|
|
43
|
-
|
|
44
|
-
|
|
100
|
+
case 'cds.LargeString':
|
|
101
|
+
return faker_1.faker.lorem.paragraph();
|
|
102
|
+
default:
|
|
45
103
|
return faker_1.faker.lorem.word();
|
|
46
|
-
}
|
|
47
104
|
}
|
|
48
105
|
}
|
|
49
106
|
generate(entity, count, parentIds) {
|
|
@@ -51,9 +108,14 @@ class FakerService {
|
|
|
51
108
|
for (let i = 0; i < count; i++) {
|
|
52
109
|
const row = {};
|
|
53
110
|
for (const prop of entity.properties) {
|
|
54
|
-
if (prop.isAssociation
|
|
111
|
+
if (prop.isAssociation)
|
|
55
112
|
continue;
|
|
56
|
-
|
|
113
|
+
if (prop.isKey) {
|
|
114
|
+
row[prop.name] = this.generateKeyValue(prop, i);
|
|
115
|
+
}
|
|
116
|
+
else {
|
|
117
|
+
row[prop.name] = this.generateValue(prop.name, prop.type, parentIds);
|
|
118
|
+
}
|
|
57
119
|
}
|
|
58
120
|
mockData.push(row);
|
|
59
121
|
}
|
|
@@ -86,7 +86,7 @@ class WizardService {
|
|
|
86
86
|
globalIdPool[shortName] = generatedIds;
|
|
87
87
|
const filteredEntity = {
|
|
88
88
|
...entity,
|
|
89
|
-
properties: entity.properties.filter(p => !p.isAssociation
|
|
89
|
+
properties: entity.properties.filter(p => !p.isAssociation)
|
|
90
90
|
};
|
|
91
91
|
const baseDir = path.dirname(path.dirname(path.resolve(schemaPath)));
|
|
92
92
|
const outputFolder = path.join(baseDir, 'db', 'data');
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cap-mock-generator",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.9",
|
|
4
4
|
"description": "An interactive mock data generation engine for SAP CAP applications, leveraging the official @sap/cds-compiler by SAP for schema parsing.",
|
|
5
5
|
"main": "dist/cli.js",
|
|
6
6
|
"bin": {
|
|
@@ -32,13 +32,13 @@
|
|
|
32
32
|
"@google/genai": "^2.8.0",
|
|
33
33
|
"@inquirer/prompts": "^8.5.2",
|
|
34
34
|
"@sap/cds-compiler": "^6.9.2",
|
|
35
|
+
"cap-mock-generator": "file:cap-mock-generator-1.0.8.tgz",
|
|
35
36
|
"commander": "^15.0.0",
|
|
36
37
|
"csv-writer": "^1.6.0",
|
|
37
38
|
"dotenv": "^17.4.2",
|
|
38
39
|
"openai": "^6.42.0"
|
|
39
40
|
},
|
|
40
41
|
"devDependencies": {
|
|
41
|
-
"@types/dotenv": "^6.1.1",
|
|
42
42
|
"@types/node": "^25.9.2",
|
|
43
43
|
"typescript": "^6.0.3"
|
|
44
44
|
},
|