blend-kit 1.0.1 → 1.0.2

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.
Files changed (70) hide show
  1. package/antlr.readme +1 -0
  2. package/dist/ai-models/api-label/APILabelHelper.js +76 -0
  3. package/dist/ai-models/api-label/APILabelHelper.ts +34 -0
  4. package/dist/ai-models/api-label/labels.json +1 -0
  5. package/dist/ai-models/api-label/model.json +1 -0
  6. package/dist/ai-models/api-label/weights.bin +0 -0
  7. package/dist/ai-models/api-label/wordIndex.json +1 -0
  8. package/dist/ai-models/tokenizer.js +18 -0
  9. package/dist/ai-models/tokenizer.ts +16 -0
  10. package/dist/commands/ui.js +15 -0
  11. package/dist/helper/ExpressHelper.js +18 -12
  12. package/dist/helper/FrontEndApiHelper.js +12 -14
  13. package/dist/helper/FrontEndReactApiHelper.js +6 -6
  14. package/dist/helper/MongoHelper.js +9 -2
  15. package/dist/helper/RNHelper.js +7 -0
  16. package/dist/helper/ReactHelper.js +10 -2
  17. package/dist/helper/grammarHelper/BlendApiGrammarHelper.js +44 -5
  18. package/dist/helper/grammarHelper/BlendMongoGrammarHelper.js +2 -1
  19. package/dist/index.js +2 -2
  20. package/dist/parser/blendExpress/src/grammar/BlendExpressLexer.js +201 -0
  21. package/dist/parser/blendExpress/src/grammar/BlendExpressListener.js +3 -0
  22. package/dist/parser/blendExpress/src/grammar/BlendExpressParser.js +961 -0
  23. package/dist/parser/blendReact/src/grammar/BlendReactLexer.js +1 -1
  24. package/dist/server.js +31 -0
  25. package/dist/types/apiOperationTypes.js +8 -1
  26. package/package.json +6 -3
  27. package/src/ai-models/api-label/APILabelHelper.ts +34 -0
  28. package/src/ai-models/api-label/labels.json +1 -0
  29. package/src/ai-models/api-label/model.json +1 -0
  30. package/src/ai-models/api-label/weights.bin +0 -0
  31. package/src/ai-models/api-label/wordIndex.json +1 -0
  32. package/src/ai-models/tokenizer.ts +16 -0
  33. package/src/grammar/.antlr/BlendApiLexer.java +2 -2
  34. package/src/grammar/.antlr/BlendExpress.interp +70 -0
  35. package/src/grammar/.antlr/BlendExpress.tokens +44 -0
  36. package/src/grammar/.antlr/BlendExpressLexer.interp +89 -0
  37. package/src/grammar/.antlr/BlendExpressLexer.java +237 -0
  38. package/src/grammar/.antlr/BlendExpressLexer.tokens +44 -0
  39. package/src/grammar/.antlr/BlendExpressParser.java +767 -0
  40. package/src/grammar/.antlr/BlendMongo.interp +3 -1
  41. package/src/grammar/.antlr/BlendMongo.tokens +5 -3
  42. package/src/grammar/.antlr/BlendMongoLexer.interp +4 -1
  43. package/src/grammar/.antlr/BlendMongoLexer.java +99 -95
  44. package/src/grammar/.antlr/BlendMongoLexer.tokens +5 -3
  45. package/src/grammar/.antlr/BlendMongoParser.java +11 -11
  46. package/src/grammar/.antlr/BlendReactLexer.interp +1 -1
  47. package/src/grammar/.antlr/BlendReactLexer.java +1 -1
  48. package/src/grammar/BlendExpress.g4 +26 -0
  49. package/src/grammar/BlendMongo.g4 +1 -1
  50. package/src/grammar/BlendReact.g4 +1 -1
  51. package/src/helper/ExpressHelper.ts +153 -141
  52. package/src/helper/FrontEndApiHelper.ts +13 -14
  53. package/src/helper/FrontEndReactApiHelper.ts +6 -6
  54. package/src/helper/MongoHelper.ts +9 -2
  55. package/src/helper/RNHelper.ts +76 -70
  56. package/src/helper/ReactHelper.ts +10 -2
  57. package/src/helper/grammarHelper/BlendApiGrammarHelper.ts +46 -6
  58. package/src/helper/grammarHelper/BlendMongoGrammarHelper.ts +4 -3
  59. package/src/index.ts +3 -2
  60. package/src/parser/blendExpress/src/grammar/BlendExpress.interp +70 -0
  61. package/src/parser/blendExpress/src/grammar/BlendExpress.tokens +44 -0
  62. package/src/parser/blendExpress/src/grammar/BlendExpressLexer.interp +89 -0
  63. package/src/parser/blendExpress/src/grammar/BlendExpressLexer.tokens +44 -0
  64. package/src/parser/blendExpress/src/grammar/BlendExpressLexer.ts +193 -0
  65. package/src/parser/blendExpress/src/grammar/BlendExpressListener.ts +145 -0
  66. package/src/parser/blendExpress/src/grammar/BlendExpressParser.ts +968 -0
  67. package/src/parser/blendReact/src/grammar/BlendReactLexer.interp +1 -1
  68. package/src/parser/blendReact/src/grammar/BlendReactLexer.ts +1 -1
  69. package/src/types/apiOperationTypes.ts +12 -0
  70. package/tsconfig.json +1 -0
@@ -6,6 +6,8 @@ import { IApiSection, ApiType, IApiMainSection, IExpressSection, IApiDataField,
6
6
  import { IBasicProject } from '../types/basicOperationTypes';
7
7
  import { IDataField } from '../types/dataOperationTypes';
8
8
  import BlendApiGrammarHelper from './grammarHelper/BlendApiGrammarHelper';
9
+ import APILabelAIHelper from '../ai-models/api-label/APILabelHelper';
10
+ import { IMongoSection } from '../types/mongoOperationTypes';
9
11
  export default class ExpressHelper {
10
12
  basicFilePath: string;
11
13
  folderName: string;
@@ -61,18 +63,19 @@ export default class ExpressHelper {
61
63
  this.basicProjectContent.sectionList.forEach(section => {
62
64
  const sectionName = section.name;
63
65
  const sectionFolderPath = path.join(this.folderPath, 'spec', sectionName);
64
- const expressSectionList: IExpressSection[]=[];
66
+ const expressSectionList: IExpressSection[] = [];
65
67
  // Ensure the section folder and its data subfolder exist
66
68
  const apiFolderPath = path.join(sectionFolderPath, 'api');
67
69
 
68
70
  section.expressModuleList.forEach(module => {
69
- const filePath = path.join(apiFolderPath, `${module.name}.express`);
70
- const specCode = FileHelper.readFile(filePath);
71
- const json = new BlendApiGrammarHelper().parseBlendApi(specCode);
72
- if(!json.isValid) {
73
- throw new Error("Error while parsing the syntax");
74
- }
75
- expressSectionList.push(json.json);
71
+ const filePath = path.join(apiFolderPath, `${module.name}.express`);
72
+ const specCode = FileHelper.readFile(filePath);
73
+ let currentSection = this.basicProjectContent.sectionList.find(item =>item.name === sectionName);
74
+ const json = new BlendApiGrammarHelper().parseBlendApi(specCode,currentSection.dataModuleList||[]);
75
+ if (!json.isValid) {
76
+ throw new Error("Error while parsing the syntax");
77
+ }
78
+ expressSectionList.push(json.json);
76
79
  });
77
80
  let sectionObj = {
78
81
  name: sectionName,
@@ -81,7 +84,7 @@ export default class ExpressHelper {
81
84
 
82
85
  apiMainSectionList.push(sectionObj);
83
86
 
84
-
87
+
85
88
  })
86
89
 
87
90
  FileHelper.writeFile(`${this.configPath}/apiConfig.json`, JSON.stringify(apiMainSectionList));
@@ -92,57 +95,58 @@ export default class ExpressHelper {
92
95
  parseJSONAndGenerateFiles() {
93
96
  const apiMainSectionList: IApiMainSection[] = JSON.parse(FileHelper.readFile(`${this.configPath}/apiConfig.json`));
94
97
  apiMainSectionList.forEach(sectionApi => {
98
+ // console.log(sectionApi.name,"sectionApisectionApisectionApisectionApisectionApisectionApisectionApisectionApi")
95
99
  const mainSectionPath = path.join(this.folderPath, `module/${sectionApi.name}`);
96
100
  sectionApi.expressSectionList.forEach(expressSection => {
97
101
  const expressPath = path.join(mainSectionPath, `express/${sectionApi.name}-api`);
98
102
  expressSection.apiSectionList.forEach(apiSection => {
99
103
  // const apiPath = ``
100
- this.writeApi(apiSection, expressPath,expressSection);
101
- this.writeInterfaceCode(apiSection, expressPath,expressSection)
102
- this.writeApiDatacode(apiSection, expressPath,expressSection);
103
- this.writeRouteCode(apiSection, expressPath,expressSection);
104
+ this.writeApi(apiSection, expressPath, expressSection,sectionApi.name);
105
+ this.writeInterfaceCode(apiSection, expressPath, expressSection,sectionApi.name)
106
+ this.writeApiDatacode(apiSection, expressPath, expressSection);
107
+ this.writeRouteCode(apiSection, expressPath, expressSection);
104
108
  })
105
109
  })
106
110
  })
107
111
  }
108
112
 
109
- writeApi(apiSection: IApiSection, expressPath: string, expressSection: IExpressSection) {
110
- const apiCode = this.generateApiCode(apiSection,expressSection);
113
+ writeApi(apiSection: IApiSection, expressPath: string, expressSection: IExpressSection,mainSectionName: string) {
114
+ const apiCode = this.generateApiCode(apiSection, expressSection,mainSectionName);
111
115
  const apiPath = `${expressPath}/src/services/${expressSection.name}`;
112
116
  const fileName = `${apiSection.name}/${apiSection.name}.service.ts`
113
117
  FileHelper.createFile(`${apiPath}/${fileName}`, apiCode);
114
118
  }
115
119
 
116
120
 
117
- writeInterfaceCode(apiSection: IApiSection, expressPath: string,expressSection: IExpressSection) {
121
+ writeInterfaceCode(apiSection: IApiSection, expressPath: string, expressSection: IExpressSection,mainSectionName: string) {
118
122
  const interfacePath = `${expressPath}/src-gen/api-interfaces/${expressSection.name}`;
119
123
  const fileName = `${apiSection.name}.interface.ts`
120
- const code = this.generateApiInterfaceCode(apiSection,expressSection);
124
+ const code = this.generateApiInterfaceCode(apiSection, expressSection,mainSectionName);
121
125
  FileHelper.writeFile(`${interfacePath}/${fileName}`, code);
122
126
  }
123
127
 
124
- writeApiDatacode(apiSection: IApiSection, expressPath: string,expressSection: IExpressSection) {
128
+ writeApiDatacode(apiSection: IApiSection, expressPath: string, expressSection: IExpressSection) {
125
129
  const dataPath = `${expressPath}/src-gen/api-data/${expressSection.name}`;
126
130
  const fileName = `${apiSection.name}.data.ts`
127
131
  const code = this.generateSampleApiDataCode(apiSection);
128
132
  FileHelper.writeFile(`${dataPath}/${fileName}`, code);
129
133
  }
130
134
 
131
- writeRouteCode(apiSection: IApiSection, expressPath: string,expressSection: IExpressSection) {
135
+ writeRouteCode(apiSection: IApiSection, expressPath: string, expressSection: IExpressSection) {
132
136
  const dataPath = `${expressPath}/src-gen/api-routes/${expressSection.name}`;
133
137
  const fileName = `${apiSection.name}.routes.ts`
134
- const code = this.generateRoutesCode(apiSection,expressSection);
138
+ const code = this.generateRoutesCode(apiSection, expressSection);
135
139
  FileHelper.writeFile(`${dataPath}/${fileName}`, code);
136
140
  }
137
141
 
138
142
 
139
143
  createExpressProject() {
140
144
  this.basicProjectContent.sectionList.forEach(section => {
141
- if(section.expressModuleList&&section.expressModuleList.length>0) {
145
+ if (section.expressModuleList && section.expressModuleList.length > 0) {
142
146
  this.createProject(section.name, `${section.name}-api`);
143
147
  }
144
148
  })
145
-
149
+
146
150
  }
147
151
 
148
152
  createProject(sectionName: string, projectName: string) {
@@ -174,7 +178,7 @@ export default class ExpressHelper {
174
178
 
175
179
 
176
180
 
177
- generateApiInterfaceCode(apiSection: IApiSection,expressSection: IExpressSection) {
181
+ generateApiInterfaceCode(apiSection: IApiSection, expressSection: IExpressSection,mainSectionName: string) {
178
182
  const interfaceName: string = `I${apiSection.name}Api`;
179
183
  const sectionName: string = `${apiSection.name}Service`;
180
184
  const apiCode = this.generateApiFunctionCodes(apiSection);
@@ -211,7 +215,7 @@ ${apiCode}
211
215
  return code;
212
216
  }
213
217
 
214
- generateSampleApiDataCode(apiSection: IApiSection,type="api") {
218
+ generateSampleApiDataCode(apiSection: IApiSection, type = "api") {
215
219
  const code = `
216
220
  ${apiSection.apiList.reduce((acc: string, api) => {
217
221
  const inputKeyList = Object.keys(api.input);
@@ -219,31 +223,31 @@ ${apiCode}
219
223
  const inputDataTypeName: string = (`${apiSection.name}_${api.name}_Input`).toUpperCase();
220
224
  const outputDataTypeName: string = (`${apiSection.name}_${api.name}_Output`).toUpperCase();
221
225
  const imports = new Set<string>(); // Collect unique imports
222
- inputKeyList.forEach(inputKey=>{
226
+ inputKeyList.forEach(inputKey => {
223
227
  const typeParts = api.input[inputKey].type.split("->");
224
228
  if (typeParts.length === 2) {
225
229
  const [module, typeName] = typeParts;
226
230
  const baseTypeName = typeName.endsWith("[]") ? typeName.slice(0, -2) : typeName;
227
- if(type==="api") {
231
+ if (type === "api") {
228
232
  imports.add(`import { ${baseTypeName} } from '../data/${module}';`);
229
233
  } else {
230
234
  imports.add(`import { ${baseTypeName} } from '../../../../data/${module}';`);
231
235
  }
232
-
236
+
233
237
  }
234
238
  })
235
239
 
236
- outputKeyList.forEach(outputKey=>{
240
+ outputKeyList.forEach(outputKey => {
237
241
  const typeParts = api.output[outputKey].type.split("->");
238
242
  if (typeParts.length === 2) {
239
243
  const [module, typeName] = typeParts;
240
244
  const baseTypeName = typeName.endsWith("[]") ? typeName.slice(0, -2) : typeName;
241
- if(type==="api") {
245
+ if (type === "api") {
242
246
  imports.add(`import { ${baseTypeName} } from '../data/${module}';`);
243
247
  } else {
244
248
  imports.add(`import { ${baseTypeName} } from '../../../../data/${module}';`);
245
249
  }
246
-
250
+
247
251
  }
248
252
  })
249
253
  acc = acc + `
@@ -255,41 +259,41 @@ export class ${inputDataTypeName} {
255
259
 
256
260
  constructor(
257
261
  ${inputKeyList
258
- .map(
259
- (inputKey) =>
260
- ` public ${inputKey}: ${this.resolveType(api.input[inputKey].type)}${!api.input[inputKey].required ? '|undefined' : ''} = ${this.getDefaultValue(
261
- api.input[inputKey]
262
- )},`
263
- )
264
- .join('\n')}
262
+ .map(
263
+ (inputKey) =>
264
+ ` public ${inputKey}: ${this.resolveType(api.input[inputKey].type)}${!api.input[inputKey].required ? '|undefined' : ''} = ${this.getDefaultValue(
265
+ api.input[inputKey]
266
+ )},`
267
+ )
268
+ .join('\n')}
265
269
  ) {}
266
270
 
267
271
  static fromJSON(jsonObj: any):${inputDataTypeName} {
268
272
  return new ${inputDataTypeName}(
269
273
  ${inputKeyList
270
- .map((inputKey) => this.generateFromJSONField({...api.input[inputKey],name: inputKey}))
271
- .join(',\n')}
274
+ .map((inputKey) => this.generateFromJSONField({ ...api.input[inputKey], name: inputKey }))
275
+ .join(',\n')}
272
276
  );
273
277
  }
274
278
 
275
279
  toJSON():object {
276
280
  return {
277
281
  ${inputKeyList
278
- .map((inputKey) => this.generateToJSONField({...api.input[inputKey],name: inputKey}))
279
- .join('\n')}
282
+ .map((inputKey) => this.generateToJSONField({ ...api.input[inputKey], name: inputKey }))
283
+ .join('\n')}
280
284
  };
281
285
  }
282
286
 
283
287
  checkDefaultPreCondition() {
284
288
  const error: any = {};
285
289
  ${inputKeyList.reduce((acc, inputKey) => {
286
- acc = acc + `${api.input[inputKey].required == true ?
287
- `if(!this.${inputKey}) {
290
+ acc = acc + `${api.input[inputKey].required == true ?
291
+ `if(!this.${inputKey}) {
288
292
  error['${inputKey}']="${inputKey} is required"
289
293
  }`
290
- : ``}`
291
- return acc
292
- }, "")}
294
+ : ``}`
295
+ return acc
296
+ }, "")}
293
297
  return {
294
298
  isValid: Object.keys(error).length==0,
295
299
  errorBody: error
@@ -301,20 +305,20 @@ ${outputKeyList.length > 0 ? `export class ${outputDataTypeName} {
301
305
 
302
306
  constructor(
303
307
  ${outputKeyList
304
- .map(
305
- (outputKey) =>
306
- ` public ${outputKey}: ${this.resolveType(api.output[outputKey].type)}${!api.output[outputKey].required ? '|undefined' : ''} = ${this.getDefaultValue(
307
- api.output[outputKey]
308
- )},`
309
- )
310
- .join('\n')}
308
+ .map(
309
+ (outputKey) =>
310
+ ` public ${outputKey}: ${this.resolveType(api.output[outputKey].type)}${!api.output[outputKey].required ? '|undefined' : ''} = ${this.getDefaultValue(
311
+ api.output[outputKey]
312
+ )},`
313
+ )
314
+ .join('\n')}
311
315
  ) {}
312
316
 
313
317
  static fromJSON(jsonObj: any):${outputDataTypeName} {
314
318
  return new ${outputDataTypeName}(
315
319
  ${outputKeyList
316
- .map((outputKey) => this.generateFromJSONField({...api.output[outputKey],name: outputKey}))
317
- .join(',\n')}
320
+ .map((outputKey) => this.generateFromJSONField({ ...api.output[outputKey], name: outputKey }))
321
+ .join(',\n')}
318
322
  );
319
323
  }
320
324
 
@@ -322,8 +326,8 @@ constructor(
322
326
  toJSON():object {
323
327
  return {
324
328
  ${outputKeyList
325
- .map((outputKey) => this.generateToJSONField({...api.output[outputKey],name: outputKey}))
326
- .join('\n')}
329
+ .map((outputKey) => this.generateToJSONField({ ...api.output[outputKey], name: outputKey }))
330
+ .join('\n')}
327
331
  };
328
332
  }
329
333
  }
@@ -336,15 +340,20 @@ constructor(
336
340
  `
337
341
  return code
338
342
  }
339
- generateApiCode(apiSection: IApiSection,expressSection: IExpressSection) {
343
+ generateApiCode(apiSection: IApiSection, expressSection: IExpressSection,mainSectionName: string) {
344
+
340
345
  const serviceName = `${apiSection.name}Service`;
341
346
  const interfaceName = `I${apiSection.name}Api`;
347
+ const totalInputs = apiSection.apiList.reduce((acc: number, currVal) => {
348
+ acc = acc + Object.keys(currVal.input).length;
349
+ return acc
350
+ }, 0);
342
351
  const code = `
343
352
  import express from 'express';\n
344
353
  import { ${interfaceName} } from '../../../../src-gen/api-interfaces/${expressSection.name}/${apiSection.name}.interface';\n
345
- ${apiSection.apiList.length > 0 ? `import {${apiSection.apiList.reduce((acc: string, currVal) => {
354
+ ${apiSection.apiList.length > 0 && totalInputs > 0 ? `import {${apiSection.apiList.reduce((acc: string, currVal) => {
346
355
  const inputName: string = (`${apiSection.name}_${currVal.name}_Input`).toUpperCase();
347
- acc = acc + inputName + ',';
356
+ acc = acc + `${Object.keys(currVal.input).length > 0 ? `${inputName + ','}` : ``}`;
348
357
  return acc
349
358
  }, '')}} from '../../../../src-gen/api-data/${expressSection.name}/${apiSection.name}.data';` : ''}
350
359
 
@@ -356,7 +365,8 @@ export default class ${serviceName} implements ${interfaceName} {
356
365
  return code;
357
366
  }
358
367
 
359
- generateApiFunctionCodes(apiSection: IApiSection) {
368
+ generateApiFunctionCodes(apiSection: IApiSection) {
369
+
360
370
  return apiSection.apiList.reduce((acc, api) => {
361
371
  const inputName: string = (`${apiSection.name}_${api.name}_Input`).toUpperCase();
362
372
  acc = acc + `public async ${api.name}(${api.authenticated === true ? 'currentUser: any,' : ''}${Object.keys(api.input).length > 0 ? `input: ${inputName},` : ''} res: express.Response) {
@@ -373,9 +383,11 @@ export default class ${serviceName} implements ${interfaceName} {
373
383
  }\n`;
374
384
  return acc;
375
385
  }, "")
386
+
387
+
376
388
  }
377
389
 
378
- generateRoutesCode(apiSection: IApiSection,expressSection: IExpressSection) {
390
+ generateRoutesCode(apiSection: IApiSection, expressSection: IExpressSection) {
379
391
  const className = `${apiSection.name}Routes`;
380
392
  const serviceName = `${apiSection.name}Service`;
381
393
  const totalInputs = apiSection.apiList.reduce((acc: number, currVal) => {
@@ -416,7 +428,7 @@ export default class ${serviceName} implements ${interfaceName} {
416
428
 
417
429
  acc = acc + `
418
430
 
419
- ${this.generateSwaggerSpecCode(expressSection,apiSection,currVal)}
431
+ ${this.generateSwaggerSpecCode(expressSection, apiSection, currVal)}
420
432
 
421
433
  this.app.route('/${this.getApiName(expressSection.name)}/${this.getApiName(apiSection.name)}/${this.getApiName(currVal.name)}').${currVal.type.toLowerCase()}(${currVal.authenticated === true ? 'verifyToken,' : ''}async (req: express.Request, res: express.Response) => {
422
434
  ${Object.keys(currVal.input).length > 0 ?
@@ -450,7 +462,7 @@ export default class ${serviceName} implements ${interfaceName} {
450
462
 
451
463
  generateSwaggerSpecCode(expressSection: IExpressSection, apiSection: IApiSection, api: IApiSpec) {
452
464
  const inputKeyList = Object.keys(api.input);
453
-
465
+
454
466
  if (api.type === ApiType.Get) {
455
467
  return `
456
468
  /**
@@ -461,17 +473,17 @@ export default class ${serviceName} implements ${interfaceName} {
461
473
  * - BearerAuth: []
462
474
  * tags:
463
475
  * - ${apiSection.name}
464
- * parameters:
476
+ * parameters: ${inputKeyList.length == 0 ? '[]' : ''}
465
477
  ${inputKeyList
466
- .map((item) => {
467
- const apiObj: IApiDataField = api.input[item];
468
- return ` * - in: query
478
+ .map((item) => {
479
+ const apiObj: IApiDataField = api.input[item];
480
+ return ` * - in: query
469
481
  * name: ${item}
470
482
  * required: ${apiObj.required}
471
483
  * schema:
472
484
  * type: ${this.getType(apiObj.type)}`;
473
- })
474
- .join("\n")}
485
+ })
486
+ .join("\n")}
475
487
  * responses:
476
488
  * 200:
477
489
  * description: Successful response
@@ -498,17 +510,17 @@ export default class ${serviceName} implements ${interfaceName} {
498
510
  * schema:
499
511
  * type: object
500
512
  * required: [${inputKeyList
501
- .filter(inputKey => api.input[inputKey].required)
502
- .map(item => `"${item}"`)
503
- .join(", ")}]
513
+ .filter(inputKey => api.input[inputKey].required)
514
+ .map(item => `"${item}"`)
515
+ .join(", ")}]
504
516
  * properties:
505
517
  ${inputKeyList
506
- .map((item) => {
507
- const apiObj: IApiDataField = api.input[item];
508
- return ` * ${item}:
518
+ .map((item) => {
519
+ const apiObj: IApiDataField = api.input[item];
520
+ return ` * ${item}:
509
521
  * type: ${this.getType(apiObj.type)}`;
510
- })
511
- .join("\n")}
522
+ })
523
+ .join("\n")}
512
524
  * responses:
513
525
  * 201:
514
526
  * description: Created successfully
@@ -520,21 +532,21 @@ export default class ${serviceName} implements ${interfaceName} {
520
532
  `;
521
533
  }
522
534
  }
523
-
524
-
535
+
536
+
525
537
  getType(type: string) {
526
- const premitiveTypes = ["string","number","boolean","object"];
527
- if(premitiveTypes.includes(type)) {
538
+ const premitiveTypes = ["string", "number", "boolean", "object"];
539
+ if (premitiveTypes.includes(type)) {
528
540
  return type;
529
- } else if(type.includes("[]")) {
541
+ } else if (type.includes("[]")) {
530
542
  return "array"
531
543
  } else {
532
544
  return "object"
533
545
  }
534
546
  }
535
547
 
536
-
537
-
548
+
549
+
538
550
 
539
551
 
540
552
  getApiName(apiName: string) {
@@ -542,67 +554,67 @@ export default class ${serviceName} implements ${interfaceName} {
542
554
  }
543
555
 
544
556
  resolveType(type: string): string {
545
- const typeParts = type.split("->");
546
- const baseType = typeParts.length === 2 ? typeParts[1] : type;
547
- return baseType.endsWith("[]") ? `${baseType.slice(0, -2)}[]` : baseType; // Handle array types
557
+ const typeParts = type.split("->");
558
+ const baseType = typeParts.length === 2 ? typeParts[1] : type;
559
+ return baseType.endsWith("[]") ? `${baseType.slice(0, -2)}[]` : baseType; // Handle array types
560
+ }
561
+
562
+ getDefaultValue(field: IDataField): string {
563
+ const typeParts = field.type.split("->");
564
+ const baseType = typeParts.length === 2 ? typeParts[1] : field.type;
565
+ if (baseType.endsWith("[]")) {
566
+ return "[]"; // Default value for arrays
548
567
  }
549
-
550
- getDefaultValue(field: IDataField): string {
551
- const typeParts = field.type.split("->");
552
- const baseType = typeParts.length === 2 ? typeParts[1] : field.type;
553
- if (baseType.endsWith("[]")) {
554
- return "[]"; // Default value for arrays
555
- }
556
- if (typeParts.length === 2) {
557
- const [, typeName] = typeParts;
558
- const baseTypeName = typeName.endsWith("[]") ? typeName.slice(0, -2) : typeName;
559
- return `new ${baseTypeName}()`; // Instantiate the imported class
560
- }
561
- switch (field.type) {
562
- case "string":
563
- return field.required ? "''" : "undefined";
564
- case "object":
565
- return field.required ? "{}" : "undefined";
566
- case "boolean":
567
- return field.required ? "false" : "undefined";
568
- case "number":
569
- return field.required ? "0" : "undefined";
570
- default:
571
- return "null";
572
- }
568
+ if (typeParts.length === 2) {
569
+ const [, typeName] = typeParts;
570
+ const baseTypeName = typeName.endsWith("[]") ? typeName.slice(0, -2) : typeName;
571
+ return `new ${baseTypeName}()`; // Instantiate the imported class
573
572
  }
574
-
575
- generateFromJSONField(field: IDataField): string {
576
- console.log(field,"field")
577
- const typeParts = field.type.split("->");
578
- const baseType = typeParts.length === 2 ? typeParts[1] : field.type;
579
- if (baseType.endsWith("[]")) {
580
- const elementType = baseType.slice(0, -2);
581
- if (["string", "number", "boolean"].includes(elementType)) {
582
- return ` jsonObj.${field.name} ?? []`;
583
- }
584
- return ` (jsonObj.${field.name} != null) ? jsonObj.${field.name}.map((item: any) => ${elementType}.fromJSON(item)) : []`;
585
- }
586
- if (typeParts.length === 2) {
587
- const [, typeName] = typeParts;
588
- const baseTypeName = typeName.endsWith("[]") ? typeName.slice(0, -2) : typeName;
589
- return ` (jsonObj.${field.name} != null) ? ${baseTypeName}.fromJSON(jsonObj.${field.name}) : new ${baseTypeName}()`;
573
+ switch (field.type) {
574
+ case "string":
575
+ return field.required ? "''" : "undefined";
576
+ case "object":
577
+ return field.required ? "{}" : "undefined";
578
+ case "boolean":
579
+ return field.required ? "false" : "undefined";
580
+ case "number":
581
+ return field.required ? "0" : "undefined";
582
+ default:
583
+ return "null";
584
+ }
585
+ }
586
+
587
+ generateFromJSONField(field: IDataField): string {
588
+ console.log(field, "field")
589
+ const typeParts = field.type.split("->");
590
+ const baseType = typeParts.length === 2 ? typeParts[1] : field.type;
591
+ if (baseType.endsWith("[]")) {
592
+ const elementType = baseType.slice(0, -2);
593
+ if (["string", "number", "boolean"].includes(elementType)) {
594
+ return ` jsonObj.${field.name} ?? []`;
590
595
  }
591
- return ` (jsonObj.${field.name} !== null) ? jsonObj?.${field.name} : undefined`;
596
+ return ` (jsonObj.${field.name} != null) ? jsonObj.${field.name}.map((item: any) => ${elementType}.fromJSON(item)) : []`;
592
597
  }
593
-
594
- generateToJSONField(field: IApiDataField): string {
595
- const typeParts = field.type.split("->");
596
- const baseType = typeParts.length === 2 ? typeParts[1] : field.type;
597
- if (baseType.endsWith("[]")) {
598
- const elementType = baseType.slice(0, -2);
599
- if (["string", "number", "boolean"].includes(elementType)) {
600
- return ` ${field.name}: this.${field.name} ?? [],`;
601
- }
602
- return ` ${field.name}: (this.${field.name} != null) ? this.${field.name}.map((x) => x.toJson()) : [],`;
598
+ if (typeParts.length === 2) {
599
+ const [, typeName] = typeParts;
600
+ const baseTypeName = typeName.endsWith("[]") ? typeName.slice(0, -2) : typeName;
601
+ return ` (jsonObj.${field.name} != null) ? ${baseTypeName}.fromJSON(jsonObj.${field.name}) : new ${baseTypeName}()`;
602
+ }
603
+ return ` (jsonObj.${field.name} !== null) ? jsonObj?.${field.name} : undefined`;
604
+ }
605
+
606
+ generateToJSONField(field: IApiDataField): string {
607
+ const typeParts = field.type.split("->");
608
+ const baseType = typeParts.length === 2 ? typeParts[1] : field.type;
609
+ if (baseType.endsWith("[]")) {
610
+ const elementType = baseType.slice(0, -2);
611
+ if (["string", "number", "boolean"].includes(elementType)) {
612
+ return ` ${field.name}: this.${field.name} ?? [],`;
603
613
  }
604
- return ` ${field.name}: this.${field.name} != null ? this.${field.name} : undefined,`;
614
+ return ` ${field.name}: (this.${field.name} != null) ? this.${field.name}.map((x) => x.toJson()) : [],`;
605
615
  }
616
+ return ` ${field.name}: this.${field.name} != null ? this.${field.name} : undefined,`;
617
+ }
606
618
  }
607
619
 
608
620
 
@@ -773,7 +785,7 @@ export default verifyToken;
773
785
  `
774
786
 
775
787
 
776
- const swaggerConfigCode = `
788
+ const swaggerConfigCode = `
777
789
  import swaggerJSDoc from "swagger-jsdoc";
778
790
  import swaggerUi from "swagger-ui-express";
779
791
  import { Express } from "express";
@@ -109,6 +109,7 @@ headers: {
109
109
  }
110
110
 
111
111
  generateSliceCode(apiSection: IApiSection) {
112
+ let includedModuleList = [];
112
113
  const filteredApiListForData = apiSection.apiList.filter(api => {
113
114
  const inputKeyList = Object.keys(api.input);
114
115
  const outputKeyList = Object.keys(api.output);
@@ -128,21 +129,17 @@ ${filteredApiListForData.length>0?`import { ${apiSection.apiList.reduce((acc, cu
128
129
  return acc
129
130
  }, '')} } from "./data";
130
131
 
131
- ${apiSection.apiList.reduce((acc, curVal) => {
132
- if (curVal?.directOutput?.name) {
133
- const [moduleName, dataName] = curVal?.directOutput?.name?.split("->");
134
- acc = acc + `import {${dataName?.replace("[]","")}} from "../../../data/${moduleName}";`;
135
- }
136
-
137
- return acc
138
- }, '')} `:''}
132
+ `:''}
139
133
 
140
134
  ${apiSection.apiList.reduce((acc, curVal) => {
141
135
  if (curVal?.directOutput?.name) {
142
136
  const [moduleName, dataName] = curVal?.directOutput?.name?.split("->");
143
- acc = acc + `import {${dataName?.replace("[]","")}} from "../../../data/${moduleName}";`;
137
+ acc = acc + !includedModuleList.includes(moduleName) ?`import * as ${moduleName} from "../../../data/${moduleName}";`:'';
138
+ includedModuleList.push(moduleName);
144
139
  }
145
140
 
141
+ console.log(includedModuleList,"includedModuleListincludedModuleListincludedModuleListincludedModuleList")
142
+
146
143
  return acc
147
144
  }, '')}
148
145
 
@@ -153,7 +150,7 @@ interface ${apiSection.name}State {
153
150
  ${apiSection.apiList.reduce((acc, curVal) => {
154
151
  const [moduleName, dataName] = curVal?.directOutput?.name?.split("->")||[];
155
152
  acc = acc + `${curVal.name}: {
156
- data: ${Object.keys(curVal.output).length > 0 ? `${apiSection.name.toUpperCase()}_${curVal.name.toUpperCase()}_OUTPUT` :dataName?dataName: "any"},\n
153
+ data: ${Object.keys(curVal.output).length > 0 ? `${apiSection.name.toUpperCase()}_${curVal.name.toUpperCase()}_OUTPUT` :dataName?`${moduleName}.${dataName}`: "any"},\n
157
154
  status: ApiStatus,
158
155
  error:string|null
159
156
  }
@@ -278,6 +275,7 @@ export const GeneratedReducers = {
278
275
  }
279
276
 
280
277
  generateApiActioncode(apiSection: IApiSection, expressSection: IExpressSection) {
278
+ let includedModuleList = [];
281
279
  const filteredApiListForData = apiSection.apiList.filter(api => {
282
280
  const inputKeyList = Object.keys(api.input);
283
281
  const outputKeyList = Object.keys(api.output);
@@ -303,7 +301,8 @@ export const GeneratedReducers = {
303
301
  ${apiSection.apiList.reduce((acc, curVal) => {
304
302
  if (curVal?.directOutput?.name) {
305
303
  const [moduleName, dataName] = curVal?.directOutput?.name?.split("->");
306
- acc = acc + `import {${dataName?.replace("[]","")}} from "../../../data/${moduleName}";`;
304
+ acc = acc + !includedModuleList.includes(moduleName)?`import {${dataName?.replace("[]","")}} from "../../../data/${moduleName}";`:'';
305
+ includedModuleList.push(moduleName);
307
306
  }
308
307
 
309
308
  return acc
@@ -340,13 +339,13 @@ export const GeneratedReducers = {
340
339
 
341
340
 
342
341
  export const ${curVal.name}Api = async (${inputKeyList.length > 0 ? `input: ${inputDataTypeName},` : ``} ) => {
343
- return ${expressSection.name}Api.${curVal.type.toLowerCase()}('${this.getApiName(expressSection.name)}/${this.getApiName(apiSection.name)}/${this.getApiName(curVal.name)}',${inputKeyList.length > 0 ? `${curVal.type == 'post' ? 'input' : '{params: input.toJSON()}'}` : ''});
342
+ return ${expressSection.name}Api.${curVal.type.toLowerCase()}('${this.getApiName(expressSection.name)}/${this.getApiName(apiSection.name)}/${this.getApiName(curVal.name)}',${inputKeyList.length > 0 ? `${curVal.type == 'POST' ? 'input' : '{params: input.toJSON()}'}` : ''});
344
343
  }
345
344
 
346
345
  export const call${this.capitalizeFirstLetter(curVal.name)}Api = async (${inputKeyList.length > 0 ? `input: ${inputDataTypeName},` : ``} output: (output: ${outputKeyList.length > 0 ? outputDataTypeName :dataName?dataName: 'any'}) => any,error: (errMsg: any) => void) => {
347
346
  try {
348
- //const { data } = await ${expressSection.name}Api.${curVal.type.toLowerCase()}('${this.getApiName(apiSection.name)}/${this.getApiName(curVal.name)}',${inputKeyList.length > 0 ? `${curVal.type == 'post' ? 'input' : '{params: input.toJSON()}'}` : ''});
349
- const { data } = await ${curVal.name}Api(${inputKeyList.length > 0 ? `${curVal.type == 'post' ? 'input' : 'input'}` : ''});
347
+ //const { data } = await ${expressSection.name}Api.${curVal.type.toLowerCase()}('${this.getApiName(apiSection.name)}/${this.getApiName(curVal.name)}',${inputKeyList.length > 0 ? `${curVal.type == 'POST' ? 'input' : '{params: input.toJSON()}'}` : ''});
348
+ const { data } = await ${curVal.name}Api(${inputKeyList.length > 0 ? `${curVal.type == 'POST' ? 'input' : 'input'}` : ''});
350
349
  return output(data);
351
350
  } catch (err: any) {
352
351
  return error(showError(err));