cap-mock-generator 1.0.8 → 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,25 +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 isAssoc = property.type === 'cds.Association' ||
59
- property.type === 'cds.Composition' ||
60
- (property.type === undefined && propName.startsWith('to'));
61
- let finalType = property.type || 'Association';
62
- let finalPropName = propName;
63
- if (property.target === 'sap.common.Countries' || property.target === 'sap.common.Currencies') {
64
- finalPropName = `${propName}_code`;
65
- finalType = 'cds.String';
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;
66
74
  }
67
- else if (property.type === 'cds.Association' && !isAssoc) {
68
- finalPropName = `${propName}_ID`;
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;
69
87
  }
70
- if (typeof property.target === 'string') {
71
- finalType = `Association.${property.target}`;
88
+ const isAssociation = property.type === 'cds.Association' ||
89
+ property.type === 'cds.Composition' ||
90
+ !!property.target;
91
+ if (isAssociation) {
92
+ continue;
72
93
  }
73
94
  properties.push({
74
- name: finalPropName,
75
- type: finalType,
76
- isAssociation: isAssoc
95
+ name: propName,
96
+ type: property.type || 'cds.String',
97
+ isAssociation: false,
98
+ isKey: !!property.key
77
99
  });
78
100
  }
79
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
  }
@@ -24,32 +74,33 @@ class FakerService {
24
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
+ }
27
83
  if (lowerPropName.endsWith('currency') || lowerPropName.endsWith('code')) {
28
84
  return faker_1.faker.string.alpha({ length: 3, casing: 'upper' });
29
85
  }
30
86
  switch (propType) {
31
- case 'cds.Date': {
87
+ case 'cds.Date':
32
88
  return faker_1.faker.date.anytime().toISOString().split('T')[0];
33
- }
34
- case 'cds.UUID': {
89
+ case 'cds.UUID':
35
90
  return faker_1.faker.string.uuid();
36
- }
37
- case 'cds.Integer': {
91
+ case 'cds.Integer':
38
92
  return faker_1.faker.number.int({ min: 1, max: 60 });
39
- }
40
- case 'cds.Decimal': {
93
+ case 'cds.Decimal':
41
94
  return faker_1.faker.number.float({ min: 10, max: 500, multipleOf: 0.01 });
42
- }
43
- case 'cds.Boolean': {
95
+ case 'cds.Boolean':
44
96
  return faker_1.faker.datatype.boolean();
45
- }
46
97
  case 'cds.DateTime':
47
- case 'cds.Timestamp': {
98
+ case 'cds.Timestamp':
48
99
  return faker_1.faker.date.past().toISOString();
49
- }
50
- default: {
100
+ case 'cds.LargeString':
101
+ return faker_1.faker.lorem.paragraph();
102
+ default:
51
103
  return faker_1.faker.lorem.word();
52
- }
53
104
  }
54
105
  }
55
106
  generate(entity, count, parentIds) {
@@ -57,10 +108,14 @@ class FakerService {
57
108
  for (let i = 0; i < count; i++) {
58
109
  const row = {};
59
110
  for (const prop of entity.properties) {
60
- // to ile başlayan sanal ilişkiler veya many-to-many bağları temizce atlansın
61
111
  if (prop.isAssociation)
62
112
  continue;
63
- row[prop.name] = this.generateValue(prop.name, prop.type, parentIds);
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
+ }
64
119
  }
65
120
  mockData.push(row);
66
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 && !p.name.startsWith('to'))
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.8",
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
  },