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
@@ -304,9 +304,9 @@ export const GeneratedReducers = {
304
304
  apiSection.apiList.reduce((acc, curVal) => {
305
305
  if (curVal?.directOutput?.name) {
306
306
  const [moduleName, dataName] = curVal?.directOutput?.name?.split("->");
307
- console.log(dataName,moduleName,"DataName...........")
307
+ // console.log(dataName,moduleName,"DataName...........")
308
308
  if(dataName) {
309
- acc = acc + `import {${dataName?.replace("[]","")}} from "../../../data/${moduleName}";`;
309
+ acc = acc + `import * as ${moduleName} from "../../../data/${moduleName}";`;
310
310
  }
311
311
 
312
312
  }
@@ -346,13 +346,13 @@ export const GeneratedReducers = {
346
346
 
347
347
 
348
348
  export const ${curVal.name}Api = async (${inputKeyList.length > 0 ? `input: ${inputDataTypeName},` : ``} ) => {
349
- 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()}'}` : ''});
349
+ 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()}'}` : ''});
350
350
  }
351
351
 
352
- 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) => {
352
+ export const call${this.capitalizeFirstLetter(curVal.name)}Api = async (${inputKeyList.length > 0 ? `input: ${inputDataTypeName},` : ``} output: (output: ${outputKeyList.length > 0 ? outputDataTypeName :dataName?`${moduleName}.${dataName}`: 'any'}) => any,error: (errMsg: any) => void) => {
353
353
  try {
354
- //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()}'}` : ''});
355
- const { data } = await ${curVal.name}Api(${inputKeyList.length > 0 ? `${curVal.type == 'post' ? 'input' : 'input'}` : ''});
354
+ //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()}'}` : ''});
355
+ const { data } = await ${curVal.name}Api(${inputKeyList.length > 0 ? `${curVal.type == 'POST' ? 'input' : 'input'}` : ''});
356
356
  return output(data);
357
357
  } catch (err: any) {
358
358
  return error(showError(err));
@@ -116,19 +116,26 @@ import { Schema, model, connect, Types } from 'mongoose';\n
116
116
  import {${interfaceName}} from './interfaces';
117
117
  const ${collection.name}Schema = new Schema<${interfaceName}>({
118
118
  ${collection.fields.reduce((acc: any, currVal) => {
119
- acc = acc + `${currVal.name}: {type: ${currVal.type} ${currVal.required ? ',required:true' : ''} ${currVal.index ? ",index:true" : ""}${currVal.unique ? ',unique:true' : ''}${currVal.ref ? `,ref:"${currVal.ref}"` : ''}},\n\t`;
119
+ const type = this.getCollectionType(currVal.type);
120
+ acc = acc + `${currVal.name}: {type: ${type} ${currVal.required ? ',required:true' : ''} ${currVal.index ? ",index:true" : ""}${currVal.unique ? ',unique:true' : ''}${currVal.ref ? `,ref:"${currVal.ref}"` : ''}},\n\t`;
120
121
  return acc;
121
122
  }, "")
122
123
  }
123
124
  });
124
125
 
125
- const ${collection.name} = Database.${dbName}Db.model<${interfaceName}>('${collection.name}', ${collection.name}Schema);
126
+ const ${collection.name} = Database.${dbName}Db.model<${interfaceName}>('${collection.name}', ${collection.name}Schema,'${CommonHelper.hyphenSepratedString(collection.name)}');
126
127
 
127
128
  export default ${collection.name};
128
129
  `
129
130
  return code;
130
131
  }
131
132
 
133
+ getCollectionType(type: string) {
134
+ if(type.endsWith("[]")) {
135
+ return `[${type.slice(0, -2)}]`;
136
+ }
137
+ return type;
138
+ }
132
139
 
133
140
  generateCollectionInterfaceCode(collectionList: ICollection[], dbName: string) {
134
141
  const code = 'import { ObjectId } from "mongoose";\n'+ collectionList.reduce((acc, collection) => {
@@ -160,7 +160,7 @@ export default class RNHelper {
160
160
  const specCode = FileHelper.readFile(rnFilePath);
161
161
  const rnHelper = new BlendRNGrammarHelper();
162
162
  const json = rnHelper.parseBlendRN(specCode);
163
- if(!json.valid) {
163
+ if (!json.valid) {
164
164
  throw new Error("Error while parsing the react native screens");
165
165
  } else {
166
166
  sectionObj.rnModuleList.push(json.json);
@@ -172,7 +172,7 @@ export default class RNHelper {
172
172
  // projectName = rnModule.name;
173
173
  });
174
174
 
175
-
175
+
176
176
  sectionRnList.push(sectionObj);
177
177
  });
178
178
 
@@ -198,8 +198,7 @@ export default class RNHelper {
198
198
  rnModule.screenList.forEach(screen => {
199
199
  const screenPath = `${rnProjectPath}/src/view/${screen.path}/`;
200
200
  const screenCode = this.generateScreenCode(screen);
201
- FileHelper.createFile(`${screenPath}${screen.name}.tsx`, screenCode
202
- )
201
+ FileHelper.createFile(`${screenPath}${screen.name}.tsx`, screenCode)
203
202
  });
204
203
 
205
204
  // })
@@ -210,37 +209,37 @@ export default class RNHelper {
210
209
  }
211
210
 
212
211
  buildComponents() {
213
- const reactSectionList: IRNSection[] = JSON.parse(FileHelper.readFile(`${this.configPath}/rnConfig.json`));
214
- reactSectionList.forEach(reactSection => {
215
- const reactFolderPath = path.join(this.folderPath, `module/${reactSection.name}/react-native`);
216
-
217
- reactSection.rnModuleList.forEach(reactModule => {
218
- this.buildLayouts(reactSection, reactModule);
219
- const rnProjectPath = path.join(reactFolderPath, reactModule.name);
220
- const mdpHookComponentPath = `${rnProjectPath}/src-gen/component/mdpHook.ts`;
221
- const mdpPath = `${rnProjectPath}/src-gen/component/MDP.ts`;
222
- const mdpHookCode = this.generateMDPHookCode(reactModule.componentList);
223
- FileHelper.writeFile(`${mdpHookComponentPath}`, mdpHookCode);
224
- FileHelper.writeFile(`${mdpPath}`, `export interface MDP {getMetaData:() => any;}\nexport interface IBasicComponent {value?: any;onInput?:(val: any) => any;}`);
225
- reactModule.componentList.forEach(component => {
226
- const componentPath = `${rnProjectPath}/src/component/${component.path}/`;
227
- const componentCode = this.generateComponentCode(component);
228
- const mdpCode = this.generateComponentMDPCode(component);
229
- FileHelper.createFile(`${componentPath}/${component.name}/${component.name}.tsx`, componentCode);
230
- FileHelper.createFile(`${componentPath}/${component.name}/${component.name}MDP.ts`, mdpCode);
231
- FileHelper.createFile(`${componentPath}/${component.name}/index.ts`, `export {default} from './${component.name}';\nexport * from "./${component.name}MDP";`);
232
-
233
- });
234
- })
212
+ const reactSectionList: IRNSection[] = JSON.parse(FileHelper.readFile(`${this.configPath}/rnConfig.json`));
213
+ reactSectionList.forEach(reactSection => {
214
+ const reactFolderPath = path.join(this.folderPath, `module/${reactSection.name}/react-native`);
215
+
216
+ reactSection.rnModuleList.forEach(reactModule => {
217
+ this.buildLayouts(reactSection, reactModule);
218
+ const rnProjectPath = path.join(reactFolderPath, reactModule.name);
219
+ const mdpHookComponentPath = `${rnProjectPath}/src-gen/component/mdpHook.ts`;
220
+ const mdpPath = `${rnProjectPath}/src-gen/component/MDP.ts`;
221
+ const mdpHookCode = this.generateMDPHookCode(reactModule.componentList);
222
+ FileHelper.writeFile(`${mdpHookComponentPath}`, mdpHookCode);
223
+ FileHelper.writeFile(`${mdpPath}`, `export interface MDP {getMetaData:() => any;}\nexport interface IBasicComponent {value?: any;onInput?:(val: any) => any;}`);
224
+ reactModule.componentList.forEach(component => {
225
+ const componentPath = `${rnProjectPath}/src/component/${component.path}/`;
226
+ const componentCode = this.generateComponentCode(component);
227
+ const mdpCode = this.generateComponentMDPCode(component);
228
+ FileHelper.createFile(`${componentPath}/${component.name}/${component.name}.tsx`, componentCode);
229
+ FileHelper.createFile(`${componentPath}/${component.name}/${component.name}MDP.ts`, mdpCode);
230
+ FileHelper.createFile(`${componentPath}/${component.name}/index.ts`, `export {default} from './${component.name}';\nexport * from "./${component.name}MDP";`);
231
+
232
+ });
235
233
  })
236
- }
237
- generateMDPHookCode(componentList: IRNComponent[]) {
238
- const importsCode = `
234
+ })
235
+ }
236
+ generateMDPHookCode(componentList: IRNComponent[]) {
237
+ const importsCode = `
239
238
  ${componentList.reduce((acc, component) => {
240
- acc = acc + `import ${component.name} from '../../src/component/${component.path}/${component.name}';\n`
241
- return acc;
242
- }, "")}`
243
- return `
239
+ acc = acc + `import ${component.name} from '../../src/component/${component.path}/${component.name}';\n`
240
+ return acc;
241
+ }, "")}`
242
+ return `
244
243
  import React, { useEffect, useState } from "react"
245
244
  import { MDP } from "./MDP";
246
245
  ${importsCode}
@@ -278,13 +277,20 @@ export default class RNHelper {
278
277
  ...extraProps
279
278
  })
280
279
  }
280
+
281
+
282
+ export const MetaDataContainer = (props: {mdp: MDP,value?: any, onInput?: (val: any)=>void,extraProps?:object}) => {
283
+ const componentClassMetaData = props.mdp.getMetaData();
284
+ return generateElementFromMetaData({...props,componentClassMetaData})
285
+ }
286
+
281
287
 
282
288
 
283
289
  const ComponentNameMap: any = {
284
290
  ${componentList.reduce((acc, component) => {
285
- acc = acc + `"${component.name}": ${component.name},\n`
286
- return acc;
287
- }, "")}
291
+ acc = acc + `"${component.name}": ${component.name},\n`
292
+ return acc;
293
+ }, "")}
288
294
  }
289
295
 
290
296
  export interface IMetaDataHook {
@@ -293,8 +299,8 @@ export default class RNHelper {
293
299
  }
294
300
 
295
301
  `;
296
-
297
- }
302
+
303
+ }
298
304
 
299
305
  checkForFolderAndCreateReactNativeApp() {
300
306
  return new Promise(async (checkRes) => {
@@ -308,7 +314,7 @@ export default class RNHelper {
308
314
  const modulePath = path.join(rnFolderPath, rnModule.name);
309
315
  if (!FileHelper.exists(modulePath)) {
310
316
  promises.push(new Promise(res => {
311
- runCommand(`npx @react-native-community/cli@latest init ${rnModule.name} --version 0.78.0`, rnFolderPath) ;
317
+ runCommand(`npx @react-native-community/cli@latest init ${rnModule.name} --version 0.78.0`, rnFolderPath);
312
318
  runCommand(`npm install -D @tsconfig/react-native@3.0.5 @types/jest@29.5.14 @types/react@19.0.10 @types/react-test-renderer@19.0.0 typescript@5.0.4`, modulePath);
313
319
 
314
320
  const dependencies = [
@@ -327,30 +333,30 @@ export default class RNHelper {
327
333
  'redux-saga@1.3.0',
328
334
  "axios@1.8.1",
329
335
  "react-native-dotenv@3.4.11"
330
- ];
331
- runCommand(`npm install ${dependencies.join(' ')}`, modulePath);
332
- FileHelper.writeFile(`${modulePath}/tsconfig.json`,`{
336
+ ];
337
+ runCommand(`npm install ${dependencies.join(' ')}`, modulePath);
338
+ FileHelper.writeFile(`${modulePath}/tsconfig.json`, `{
333
339
  "extends": "@tsconfig/react-native/tsconfig.json"
334
340
  }`);
335
341
 
336
- FileHelper.writeFile(`${modulePath}/App.tsx`,mainAppcode)
337
- FileHelper.writeFile(`${modulePath}/babel.config.js`,`module.exports = {
342
+ FileHelper.writeFile(`${modulePath}/App.tsx`, mainAppcode)
343
+ FileHelper.writeFile(`${modulePath}/babel.config.js`, `module.exports = {
338
344
  presets: ['module:@react-native/babel-preset'],
339
345
  plugins: [
340
346
  ['module:react-native-dotenv']
341
347
  ]
342
348
  };`)
343
349
 
344
- FileHelper.writeFile(`${modulePath}/.env.dev`,"")
345
- FileHelper.writeFile(`${modulePath}/.env.prod`,"")
346
- FileHelper.writeFile(`${modulePath}/env.d.ts`,`
350
+ FileHelper.writeFile(`${modulePath}/.env.dev`, "")
351
+ FileHelper.writeFile(`${modulePath}/.env.prod`, "")
352
+ FileHelper.writeFile(`${modulePath}/env.d.ts`, `
347
353
  declare module '@env' {
348
354
  export const API_URL: string;
349
355
  export const APP_ENV: string;
350
356
  }`)
351
-
352
-
353
-
357
+
358
+
359
+
354
360
  }))
355
361
  }
356
362
  })
@@ -565,7 +571,7 @@ export default ${lo.name}Layout;
565
571
  }
566
572
 
567
573
  generateComponentCode(component: IRNComponent) {
568
- return `
574
+ return `
569
575
  import React from "react";
570
576
  import {Text} from "react-native";
571
577
  import {I${component.name}Props} from './${component.name}MDP';
@@ -579,17 +585,17 @@ export default ${lo.name}Layout;
579
585
 
580
586
  export default ${component.name};
581
587
  `
582
- }
583
-
584
-
585
-
586
-
587
- generateComponentMDPCode(component: IRNComponent) {
588
- const pathCode = '../../../' + component.path.split("/").reduce((acc,curVal) => {
589
- acc = acc + '../'
590
- return acc;
591
- },"")
592
- return `
588
+ }
589
+
590
+
591
+
592
+
593
+ generateComponentMDPCode(component: IRNComponent) {
594
+ const pathCode = '../../../' + component.path.split("/").reduce((acc, curVal) => {
595
+ acc = acc + '../'
596
+ return acc;
597
+ }, "")
598
+ return `
593
599
  import { MDP,IBasicComponent } from "${pathCode}src-gen/component/MDP";
594
600
 
595
601
  export class ${component.name}MDP implements I${component.name}MDP {
@@ -611,14 +617,6 @@ export default ${lo.name}Layout;
611
617
  getMetaData: () => {componentName: string, props: I${component.name}Props}
612
618
  }
613
619
  `
614
- }
615
-
616
-
617
-
618
-
619
-
620
-
621
-
622
620
  }
623
621
 
624
622
 
@@ -627,6 +625,14 @@ export default ${lo.name}Layout;
627
625
 
628
626
 
629
627
 
628
+ }
629
+
630
+
631
+
632
+
633
+
634
+
635
+
630
636
 
631
637
  const mainAppcode = `
632
638
 
@@ -207,6 +207,13 @@ export const generateElementFromMetaData = ({ componentClassMetaData, value, onI
207
207
  }
208
208
 
209
209
 
210
+ export const MetaDataContainerWithObject = (props: {metadata: object,value?: any, onInput?: (val: any)=>void,extraProps?:object}) => {
211
+ const componentClassMetaData = props.metadata;
212
+ return generateElementFromMetaData({...props,componentClassMetaData})
213
+ }
214
+
215
+
216
+
210
217
 
211
218
  const ComponentNameMap: any = {
212
219
  ${componentList.reduce((acc, component) => {
@@ -345,6 +352,7 @@ ${this.generateLayoutCode(lo, reactModule)}
345
352
 
346
353
  console.log([mainLayout],JSON.stringify([mainLayout]),"Main layout///////////////")
347
354
  const routerJsonCode = `const router = createBrowserRouter([${this.generateLayoutRouterJSONCode([mainLayout])}])\nexport default router;`
355
+ const routerConstant = this.generateRouterConstant(frontEnd.layout);
348
356
  console.log(this.generateFlattenedArray(mainLayout.children), "this.generateFlattenedArray(mainLayout.children)");
349
357
  const importCode = `${this.generateFlattenedArray(mainLayout.children).reduce((acc, item) => {
350
358
  const importCode = ` ${item.children ? `
@@ -355,7 +363,7 @@ ${this.generateLayoutCode(lo, reactModule)}
355
363
  acc = acc + importCode;
356
364
  return acc;
357
365
  }, "")}`;
358
- return importCode + defaultImportCode + routerJsonCode;
366
+ return importCode + defaultImportCode + routerJsonCode + '\n'+routerConstant;
359
367
  }
360
368
  generateLayoutRouterJSONCode(layoutList: IReactLayout[]) {
361
369
  return layoutList.reduce((acc, layout) => {
@@ -404,7 +412,7 @@ ${this.generateLayoutCode(lo, reactModule)}
404
412
  }, {})
405
413
  }
406
414
 
407
- return JSON.stringify(routeObj);
415
+ return `export const RouterConstant = ${JSON.stringify(routeObj)}`;
408
416
  }
409
417
 
410
418
  generateLayoutCode(lo: IReactLayout, frontEnd: IReactModule) {
@@ -2,35 +2,70 @@ import { CharStreams, CommonTokenStream } from "antlr4ts";
2
2
  import { BlendApiLexer } from "../../parser/blendApi/src/grammar/BlendApiLexer";
3
3
  import { BlendApiParser } from "../../parser/blendApi/src/grammar/BlendApiParser";
4
4
  import { IApiMainSection, IApiSection, IApiSpec, IExpressSection } from "../../types/apiOperationTypes";
5
+ import path from "node:path";
5
6
 
6
7
  export default class BlendApiGrammarHelper {
7
- parseBlendApi(code: string) {
8
+ parseBlendApi(code: string,dataModuleList:string[]) {
8
9
  const inputStream = CharStreams.fromString(code);
9
10
  const lexer = new BlendApiLexer(inputStream);
10
11
  const tokenStream = new CommonTokenStream(lexer);
11
12
  const parser = new BlendApiParser(tokenStream);
12
13
 
13
14
  const mainModule = parser.program();
15
+ let haveDuplicateSection: boolean = false;
16
+ let duplicateApis: any = {};
17
+ let haveNoDataFoundError : boolean = false;
18
+ const sectionNameList = new Set<string>();
14
19
  const json: IExpressSection = {
15
20
  name: mainModule.moduleDefinition().CAPITAL_IDENTIFIER().text,
16
21
  apiSectionList: mainModule.sectionDefinition().map(item => {
22
+
23
+ if(sectionNameList.has(item.CAPITAL_IDENTIFIER().text)) {
24
+ console.error(`❌ Duplicate Section '${item.CAPITAL_IDENTIFIER().text}' at line ${item.start.line}`);
25
+ haveDuplicateSection=true;
26
+ }
27
+ const apiNameList = new Set<string>();
28
+
17
29
  const apiSection: IApiSection = {
18
30
  name: item.CAPITAL_IDENTIFIER().text, apiList: item.apiDefinition().map(api => {
31
+ const apiName = api.IDENTIFIER().text;
32
+ if (apiNameList.has(apiName)) {
33
+ duplicateApis[apiName] = true;
34
+ console.error(`❌ Duplicate API '${apiName}' in section '${item.CAPITAL_IDENTIFIER().text}' at line ${api.start.line}`);
35
+ } else {
36
+ apiNameList.add(apiName);
37
+ }
19
38
  const apiSpec: IApiSpec = {
20
39
  input: {},
21
40
  output: {},
22
- name: api.IDENTIFIER().text,
41
+ name: apiName,
23
42
  type: api.HTTP_METHOD().text,
24
- directOutput: api.outputDefinition()?.directOutputDefenition()?.type()? {
43
+ directOutput: api.outputDefinition()?.directOutputDefenition()?.type() ? {
25
44
  required: !api.outputDefinition()?.directOutputDefenition()?.type().text.includes("?"),
26
45
  name: api.outputDefinition()?.directOutputDefenition()?.type().text?.replace("?", ""),
27
- }:{},
28
- authenticated: api?.authenticated()?.text=="authenticated"
46
+ } : {},
47
+ authenticated: api?.authenticated()?.text == "authenticated"
29
48
  }
30
49
  api.inputDefinition()?.field()?.forEach(field => {
31
50
  apiSpec.input[field.IDENTIFIER().text] = { type: field.type().text?.replace("?", ""), required: !field?.type().text.includes("?") };
32
51
  })
52
+ // console.log(JSON.stringify(api.outputDefinition()?.field()||[]),"api.outputDefinition()")
53
+
54
+ const customData = api.outputDefinition()?.directOutputDefenition()?.type().text;
55
+ if(customData&&!dataModuleList.includes(customData?.split("->")[0])) {
56
+ console.error(`❌ No Data Module '${customData.split("->")[0]}' Found in section '${item.CAPITAL_IDENTIFIER().text}' at line ${api.start.line}`);
57
+ haveNoDataFoundError = true;
58
+ }
33
59
  api.outputDefinition()?.field()?.forEach(field => {
60
+
61
+ if(field.type().text.includes("->")) {
62
+ const customDataSplit = field.type().text.split("->");
63
+ console.log(dataModuleList,"dataModuleList....")
64
+ if(!dataModuleList.includes(customDataSplit[0])) {
65
+ console.error(`❌ No Data Module '${customDataSplit[0]}' Found in section '${item.CAPITAL_IDENTIFIER().text}' at line ${api.start.line}`);
66
+ haveNoDataFoundError = true;
67
+ }
68
+ }
34
69
  apiSpec.output[field.IDENTIFIER().text] = { type: field.type().text?.replace("?", ""), required: !field?.type().text.includes("?") };
35
70
  })
36
71
  return apiSpec;
@@ -40,6 +75,11 @@ export default class BlendApiGrammarHelper {
40
75
  }),
41
76
  includedDataModuleList: []
42
77
  }
43
- return { isValid: parser.numberOfSyntaxErrors === 0, json };
78
+ return { isValid: parser.numberOfSyntaxErrors === 0 && Object.keys(duplicateApis).length===0 && !haveDuplicateSection&&!haveNoDataFoundError, json };
79
+ }
80
+
81
+ static getDatasInDataSection(dataSectionName,folderPath) {
82
+ const sectionPath = path.join(folderPath, `module/${dataSectionName}`);
83
+ // sectionData.sectionDataList.forEach(async (moduleData) => {
44
84
  }
45
85
  }
@@ -1,7 +1,7 @@
1
1
  import { CharStreams, CommonTokenStream } from "antlr4ts";
2
2
  import { BlendMongoLexer } from "../../parser/blendMongo/src/grammar/BlendMongoLexer";
3
3
  import { BlendMongoParser } from "../../parser/blendMongo/src/grammar/BlendMongoParser";
4
- import { IDataBase } from "../../types/mongoOperationTypes";
4
+ import { Field, IDataBase } from "../../types/mongoOperationTypes";
5
5
 
6
6
  export default class BlendMongoGrammarHelper {
7
7
  parseBlendMongo(code: string){
@@ -15,12 +15,13 @@ export default class BlendMongoGrammarHelper {
15
15
  const json: IDataBase = {
16
16
  dbName: moduleDefinition.CAPITAL_IDENTIFIER().text,
17
17
  collectionList: collectionDefinitionList.map(collectionDefinition => {
18
- const propertyFields = collectionDefinition.property().map(property => {
18
+ const propertyFields: Field[] = collectionDefinition.property().map(property => {
19
19
  return {
20
20
  name: property.IDENTIFIER().text,
21
- type: property.type().text,
21
+ type: property.type().text.replace("?", ""),
22
22
  unique: property.propertyChars()?.mongoChars()?property.propertyChars()?.mongoChars()?.findIndex(item => item.text === "unique") !=-1: undefined,
23
23
  index: property.propertyChars()?.mongoChars()?property.propertyChars()?.mongoChars()?.findIndex(item => item.text === "index") !=-1: undefined,
24
+ required: property.type().text.includes("?")?false:true,
24
25
  // ref: collectionDefinition.reference()?collectionDefinition.reference()?.CAPITAL_IDENTIFIER().text:undefined,
25
26
  }
26
27
  });
package/src/index.ts CHANGED
@@ -116,7 +116,7 @@ program.command('prepare')
116
116
  });
117
117
 
118
118
  // Command 3: blend-generate (add your logic here)
119
- program.command('generate')
119
+ program.command('serve')
120
120
  .description('Generate files or configurations based on existing ones')
121
121
  .action(async () => {
122
122
  const folderPath = path.join(process.cwd());
@@ -147,7 +147,7 @@ program.command('generate')
147
147
  // Add your custom logic here
148
148
  });
149
149
 
150
- program.command('cook')
150
+ program.command('chop')
151
151
  .description('Generate files or configurations based on existing ones')
152
152
  .action(() => {
153
153
  const folderPath = path.join(process.cwd());
@@ -165,4 +165,5 @@ program.command('cook')
165
165
  // Add your custom logic here
166
166
  });
167
167
 
168
+
168
169
  program.parse(process.argv);
@@ -0,0 +1,70 @@
1
+ token literal names:
2
+ null
3
+ 'section'
4
+ '{'
5
+ '}'
6
+ 'module'
7
+ 'api'
8
+ '('
9
+ ')'
10
+ 'authenticated'
11
+ 'input('
12
+ ','
13
+ 'output('
14
+ ':'
15
+ '[]'
16
+ '?'
17
+ '->'
18
+ 'string'
19
+ 'number'
20
+ 'boolean'
21
+ 'any'
22
+ 'object'
23
+ null
24
+ null
25
+ null
26
+ null
27
+
28
+ token symbolic names:
29
+ null
30
+ null
31
+ null
32
+ null
33
+ null
34
+ null
35
+ null
36
+ null
37
+ null
38
+ null
39
+ null
40
+ null
41
+ null
42
+ null
43
+ null
44
+ null
45
+ null
46
+ null
47
+ null
48
+ null
49
+ null
50
+ HTTP_METHOD
51
+ IDENTIFIER
52
+ CAPITAL_IDENTIFIER
53
+ WS
54
+
55
+ rule names:
56
+ program
57
+ sectionDefinition
58
+ moduleDefinition
59
+ apiDefinition
60
+ authenticated
61
+ inputDefinition
62
+ outputDefinition
63
+ directOutputDefenition
64
+ field
65
+ type
66
+ primitiveType
67
+
68
+
69
+ atn:
70
+ [3, 51485, 51898, 1421, 44986, 20307, 1543, 60043, 49729, 3, 26, 121, 4, 2, 9, 2, 4, 3, 9, 3, 4, 4, 9, 4, 4, 5, 9, 5, 4, 6, 9, 6, 4, 7, 9, 7, 4, 8, 9, 8, 4, 9, 9, 9, 4, 10, 9, 10, 4, 11, 9, 11, 4, 12, 9, 12, 3, 2, 3, 2, 7, 2, 27, 10, 2, 12, 2, 14, 2, 30, 11, 2, 3, 3, 3, 3, 3, 3, 3, 3, 7, 3, 36, 10, 3, 12, 3, 14, 3, 39, 11, 3, 3, 3, 3, 3, 3, 4, 3, 4, 3, 4, 3, 5, 3, 5, 3, 5, 3, 5, 3, 5, 3, 5, 3, 5, 5, 5, 53, 10, 5, 3, 5, 5, 5, 56, 10, 5, 3, 5, 5, 5, 59, 10, 5, 3, 5, 3, 5, 3, 6, 3, 6, 3, 7, 3, 7, 3, 7, 3, 7, 7, 7, 69, 10, 7, 12, 7, 14, 7, 72, 11, 7, 3, 7, 3, 7, 3, 8, 3, 8, 3, 8, 3, 8, 7, 8, 80, 10, 8, 12, 8, 14, 8, 83, 11, 8, 3, 8, 3, 8, 3, 8, 3, 8, 3, 8, 3, 8, 5, 8, 91, 10, 8, 3, 9, 3, 9, 3, 10, 3, 10, 3, 10, 3, 10, 3, 11, 3, 11, 3, 11, 3, 11, 3, 11, 3, 11, 3, 11, 3, 11, 3, 11, 3, 11, 3, 11, 3, 11, 3, 11, 3, 11, 3, 11, 3, 11, 3, 11, 3, 11, 5, 11, 117, 10, 11, 3, 12, 3, 12, 3, 12, 2, 2, 2, 13, 2, 2, 4, 2, 6, 2, 8, 2, 10, 2, 12, 2, 14, 2, 16, 2, 18, 2, 20, 2, 22, 2, 2, 3, 3, 2, 18, 22, 2, 122, 2, 24, 3, 2, 2, 2, 4, 31, 3, 2, 2, 2, 6, 42, 3, 2, 2, 2, 8, 45, 3, 2, 2, 2, 10, 62, 3, 2, 2, 2, 12, 64, 3, 2, 2, 2, 14, 90, 3, 2, 2, 2, 16, 92, 3, 2, 2, 2, 18, 94, 3, 2, 2, 2, 20, 116, 3, 2, 2, 2, 22, 118, 3, 2, 2, 2, 24, 28, 5, 6, 4, 2, 25, 27, 5, 4, 3, 2, 26, 25, 3, 2, 2, 2, 27, 30, 3, 2, 2, 2, 28, 26, 3, 2, 2, 2, 28, 29, 3, 2, 2, 2, 29, 3, 3, 2, 2, 2, 30, 28, 3, 2, 2, 2, 31, 32, 7, 3, 2, 2, 32, 33, 7, 25, 2, 2, 33, 37, 7, 4, 2, 2, 34, 36, 5, 8, 5, 2, 35, 34, 3, 2, 2, 2, 36, 39, 3, 2, 2, 2, 37, 35, 3, 2, 2, 2, 37, 38, 3, 2, 2, 2, 38, 40, 3, 2, 2, 2, 39, 37, 3, 2, 2, 2, 40, 41, 7, 5, 2, 2, 41, 5, 3, 2, 2, 2, 42, 43, 7, 6, 2, 2, 43, 44, 7, 25, 2, 2, 44, 7, 3, 2, 2, 2, 45, 46, 7, 7, 2, 2, 46, 47, 7, 24, 2, 2, 47, 48, 7, 8, 2, 2, 48, 49, 7, 23, 2, 2, 49, 50, 7, 9, 2, 2, 50, 52, 7, 4, 2, 2, 51, 53, 5, 10, 6, 2, 52, 51, 3, 2, 2, 2, 52, 53, 3, 2, 2, 2, 53, 55, 3, 2, 2, 2, 54, 56, 5, 12, 7, 2, 55, 54, 3, 2, 2, 2, 55, 56, 3, 2, 2, 2, 56, 58, 3, 2, 2, 2, 57, 59, 5, 14, 8, 2, 58, 57, 3, 2, 2, 2, 58, 59, 3, 2, 2, 2, 59, 60, 3, 2, 2, 2, 60, 61, 7, 5, 2, 2, 61, 9, 3, 2, 2, 2, 62, 63, 7, 10, 2, 2, 63, 11, 3, 2, 2, 2, 64, 65, 7, 11, 2, 2, 65, 70, 5, 18, 10, 2, 66, 67, 7, 12, 2, 2, 67, 69, 5, 18, 10, 2, 68, 66, 3, 2, 2, 2, 69, 72, 3, 2, 2, 2, 70, 68, 3, 2, 2, 2, 70, 71, 3, 2, 2, 2, 71, 73, 3, 2, 2, 2, 72, 70, 3, 2, 2, 2, 73, 74, 7, 9, 2, 2, 74, 13, 3, 2, 2, 2, 75, 76, 7, 13, 2, 2, 76, 81, 5, 18, 10, 2, 77, 78, 7, 12, 2, 2, 78, 80, 5, 18, 10, 2, 79, 77, 3, 2, 2, 2, 80, 83, 3, 2, 2, 2, 81, 79, 3, 2, 2, 2, 81, 82, 3, 2, 2, 2, 82, 84, 3, 2, 2, 2, 83, 81, 3, 2, 2, 2, 84, 85, 7, 9, 2, 2, 85, 91, 3, 2, 2, 2, 86, 87, 7, 13, 2, 2, 87, 88, 5, 16, 9, 2, 88, 89, 7, 9, 2, 2, 89, 91, 3, 2, 2, 2, 90, 75, 3, 2, 2, 2, 90, 86, 3, 2, 2, 2, 91, 15, 3, 2, 2, 2, 92, 93, 5, 20, 11, 2, 93, 17, 3, 2, 2, 2, 94, 95, 7, 24, 2, 2, 95, 96, 7, 14, 2, 2, 96, 97, 5, 20, 11, 2, 97, 19, 3, 2, 2, 2, 98, 117, 5, 22, 12, 2, 99, 100, 5, 22, 12, 2, 100, 101, 7, 15, 2, 2, 101, 117, 3, 2, 2, 2, 102, 103, 5, 22, 12, 2, 103, 104, 7, 16, 2, 2, 104, 117, 3, 2, 2, 2, 105, 106, 7, 25, 2, 2, 106, 107, 7, 17, 2, 2, 107, 117, 7, 25, 2, 2, 108, 109, 7, 25, 2, 2, 109, 110, 7, 17, 2, 2, 110, 111, 7, 25, 2, 2, 111, 117, 7, 16, 2, 2, 112, 113, 7, 25, 2, 2, 113, 114, 7, 17, 2, 2, 114, 115, 7, 25, 2, 2, 115, 117, 7, 15, 2, 2, 116, 98, 3, 2, 2, 2, 116, 99, 3, 2, 2, 2, 116, 102, 3, 2, 2, 2, 116, 105, 3, 2, 2, 2, 116, 108, 3, 2, 2, 2, 116, 112, 3, 2, 2, 2, 117, 21, 3, 2, 2, 2, 118, 119, 9, 2, 2, 2, 119, 23, 3, 2, 2, 2, 11, 28, 37, 52, 55, 58, 70, 81, 90, 116]
@@ -0,0 +1,44 @@
1
+ T__0=1
2
+ T__1=2
3
+ T__2=3
4
+ T__3=4
5
+ T__4=5
6
+ T__5=6
7
+ T__6=7
8
+ T__7=8
9
+ T__8=9
10
+ T__9=10
11
+ T__10=11
12
+ T__11=12
13
+ T__12=13
14
+ T__13=14
15
+ T__14=15
16
+ T__15=16
17
+ T__16=17
18
+ T__17=18
19
+ T__18=19
20
+ T__19=20
21
+ HTTP_METHOD=21
22
+ IDENTIFIER=22
23
+ CAPITAL_IDENTIFIER=23
24
+ WS=24
25
+ 'section'=1
26
+ '{'=2
27
+ '}'=3
28
+ 'module'=4
29
+ 'api'=5
30
+ '('=6
31
+ ')'=7
32
+ 'authenticated'=8
33
+ 'input('=9
34
+ ','=10
35
+ 'output('=11
36
+ ':'=12
37
+ '[]'=13
38
+ '?'=14
39
+ '->'=15
40
+ 'string'=16
41
+ 'number'=17
42
+ 'boolean'=18
43
+ 'any'=19
44
+ 'object'=20