frgen 0.0.4 → 0.0.6

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.
@@ -1,2 +1,2 @@
1
1
  #!/usr/bin/env node
2
- "use strict";var e=require("./_virtual/_rollupPluginBabelHelpers.js"),n=require("fs"),t=require("path"),r=require("./utils.js");function a(e,n){var t=n.type,a=n.nullable,o=["yup"],c=["integer","bigint","smallint","tinyint","numeric","decimal","float"].includes(t),i=["varchar","text","string","char","character varying","uuid","date","datetime","timestamp","timestamp with time zone"].includes(t),s=["boolean"].includes(t);return c?o.push("number()"):i?o.push("string()"):s?o.push("boolean()"):o.push("mixed()"),a?o.push("optional()"):o.push("required()"),o.push("label('".concat(e.replaceAll("_"," "),"')")),"".concat(r.toCamelCase(e),":").concat(o.join("."))}var o=function(){var o=e.asyncToGenerator(e.regeneratorRuntime().mark((function o(c,i,s,l){var u,d,m,p,y,h,f,x,b,w,q,g=arguments;return e.regeneratorRuntime().wrap((function(o){for(;;)switch(o.prev=o.next){case 0:return u=g.length>4&&void 0!==g[4]?g[4]:"public",o.prev=1,c||(console.error("class name undefined"),process.exit(1)),i||(console.error("table name undefined"),process.exit(1)),d="".concat(c,".ts"),m=t.join(process.cwd(),"src","app","http","controller",d),s&&"default"!==s&&("/"!==s.charAt(s.length-1)&&(s+="/"),m=t.join(process.cwd(),"src",s,d)),p=c.replace(/Controller$/,""),o.next=10,l.select("table_name","column_name","column_default","is_nullable","data_type","character_maximum_length").from("information_schema.columns").whereRaw("table_catalog = current_database()").where("table_name",null!=i?i:p+"s").where("table_schema",u);case 10:y=o.sent,h=Object.fromEntries(y.map((function(e){return[e.column_name,{defaultValue:e.column_default,type:e.data_type,maxLength:e.character_maximum_length,nullable:"YES"===e.is_nullable}]}))),f="",x="",Object.keys(h).length&&(b=Object.entries(h).filter((function(n){var t=e.slicedToArray(n,1)[0];return!["created_at","updated_at","createdAt","updatedAt"].includes(t)})).map((function(n){var t=e.slicedToArray(n,2),o=t[0],c=t[1];return[r.toCamelCase(o),a(o,c)]})),x="\n const validated = await req.validation((yup) => yup.object({\n ".concat(b.map((function(n){var t=e.slicedToArray(n,2);return t[0],t[1]})).join(",\n"),"\n }));\n "),f="\n const validated = await req.validation((yup) => yup.object({\n ".concat(b.filter((function(n){return"id"!==e.slicedToArray(n,1)[0]})).map((function(n){var t=e.slicedToArray(n,2);return t[0],t[1]})).join(",\n"),"\n }));\n ")),w='\nimport NotFoundException from "@exception/NotFoundException";\nimport '.concat(p,' from "@model/').concat(p,'";\nimport ').concat(p,'Resource from "@resource/').concat(p,'Resource";\nimport express from "express";\n\nconst ').concat(c," = express.Router();\n\n").concat(c,'.get("/", async (req, res, next) => {\n try {\n const results = await ').concat(p,'.query().page(req.getQuery("page", 0), req.getQuery("perPage", 10));\n res.json(results);\n } catch (error) {\n next(error);\n }\n});\n\n').concat(c,'.get("/:id", async (req, res, next) => {\n try {\n const model = await ').concat(p,'.query().findById(req.params.id);\n if (!model) {\n throw new NotFoundException("').concat(p,'");\n }\n res.json(new ').concat(p,"Resource(model, true));\n } catch (error) {\n next(error);\n }\n});\n\n").concat(c,'.post("/", async (req, res, next) => {\n try {\n ').concat(f,"\n const model = await ").concat(p,".query().insertAndFetch(").concat(""===f?"req.body":"validated",");\n res.json(new ").concat(p,"Resource(model, true));\n } catch (error) {\n next(error);\n }\n});\n\n").concat(c,'.put("/", async (req, res, next) => {\n try {\n ').concat(x,"\n const model = await ").concat(p,".query().findById(").concat(""===x?"req.body.id":"validated.id",');\n if (!model) {\n throw new NotFoundException("').concat(p,'");\n }\n await model.$query().updateAndFetch(').concat(""===x?"req.body":"validated",");\n res.json(new ").concat(p,"Resource(model, true));\n } catch (error) {\n next(error);\n }\n});\n\n").concat(c,'.delete("/:id", async (req, res, next) => {\n try {\n const model = await ').concat(p,'.query().findById(+req.params.id);\n if (!model) {\n throw new NotFoundException("').concat(p,'");\n }\n await model.$query().delete();\n res.json(new ').concat(p,"Resource(model, true));\n } catch (error) {\n next(error);\n }\n});\n\nexport default ").concat(c,";\n"),q=t.dirname(m),n.existsSync(q)||n.mkdirSync(q,{recursive:!0}),n.writeFile(m,w,(function(e){e?console.error("Gagal membuat file:",e):console.log("File ".concat(d," berhasil dibuat di ").concat(m))})),o.next=24;break;case 21:o.prev=21,o.t0=o.catch(1),console.error("Gagal mendapatkan informasi kolom:",o.t0);case 24:return o.prev=24,o.finish(24);case 26:case"end":return o.stop()}}),o,null,[[1,21,24,26]])})));return function(e,n,t,r){return o.apply(this,arguments)}}();module.exports=o;
2
+ "use strict";var e=require("./_virtual/_rollupPluginBabelHelpers.js"),n=require("fs"),t=require("path"),r=require("./utils.js");function a(e,n){var t=n.type,a=n.nullable,o=["yup"],c=["integer","bigint","smallint","tinyint","numeric","decimal","float"].includes(t),i=["varchar","text","string","char","character varying","uuid","date","datetime","timestamp","timestamp with time zone"].includes(t),s=["boolean"].includes(t);return c?o.push("number()"):i?o.push("string()"):s?o.push("boolean()"):o.push("mixed()"),a?o.push("optional()"):o.push("required()"),o.push("label('".concat(e.replaceAll("_"," "),"')")),"".concat(r.toCamelCase(e),":").concat(o.join("."))}var o=function(){var o=e.asyncToGenerator(e.regeneratorRuntime().mark((function o(c,i,s,l){var u,d,m,p,y,h,f,x,b,w,g,q=arguments;return e.regeneratorRuntime().wrap((function(o){for(;;)switch(o.prev=o.next){case 0:return u=q.length>4&&void 0!==q[4]?q[4]:"public",o.prev=1,c||(console.error("class name undefined"),process.exit(1)),i||(console.error("table name undefined"),process.exit(1)),d="".concat(c,".ts"),m=t.join(process.cwd(),"src","app","http","controller",d),s&&"default"!==s&&("/"!==s.charAt(s.length-1)&&(s+="/"),m=t.join(process.cwd(),"src",s,d)),p=c.replace(/Controller$/,""),o.next=10,l.select("table_name","column_name","column_default","is_nullable","data_type","character_maximum_length").from("information_schema.columns").whereRaw("table_catalog = current_database()").where("table_name",null!=i?i:p+"s").where("table_schema",u);case 10:y=o.sent,h=Object.fromEntries(y.map((function(e){return[e.column_name,{defaultValue:e.column_default,type:e.data_type,maxLength:e.character_maximum_length,nullable:"YES"===e.is_nullable}]}))),f="",x="",Object.keys(h).length&&(b=Object.entries(h).filter((function(n){var t=e.slicedToArray(n,1)[0];return!["created_at","updated_at","createdAt","updatedAt"].includes(t)})).map((function(n){var t=e.slicedToArray(n,2),o=t[0],c=t[1];return[r.toCamelCase(o),a(o,c)]})),x="\n const validated = await req.validation((yup) => yup.object({\n ".concat(b.map((function(n){var t=e.slicedToArray(n,2);return t[0],t[1]})).join(",\n"),"\n }));\n "),f="\n const validated = await req.validation((yup) => yup.object({\n ".concat(b.filter((function(n){return"id"!==e.slicedToArray(n,1)[0]})).map((function(n){var t=e.slicedToArray(n,2);return t[0],t[1]})).join(",\n"),"\n }));\n ")),w='\nimport NotFoundException from "@exception/NotFoundException";\nimport '.concat(p,' from "@model/').concat(p,'";\nimport ').concat(p,'Resource from "@resource/').concat(p,'Resource";\nimport express from "express";\n\nconst ').concat(c," = express.Router();\n\n").concat(c,'.get("/", async (req, res, next) => {\n try {\n const results = await ').concat(p,'.query().page(req.getQuery("page", 0), req.getQuery("perPage", 10));\n res.json(').concat(p,"Resource.paginate(results));\n } catch (error) {\n next(error);\n }\n});\n\n").concat(c,'.get("/:id", async (req, res, next) => {\n try {\n const model = await ').concat(p,'.query().findById(req.params.id);\n if (!model) {\n throw new NotFoundException("').concat(p,'");\n }\n res.json(new ').concat(p,"Resource(model, true));\n } catch (error) {\n next(error);\n }\n});\n\n").concat(c,'.post("/", async (req, res, next) => {\n try {\n ').concat(f,"\n const model = await ").concat(p,".query().insertAndFetch(").concat(""===f?"req.body":"validated",");\n res.json(new ").concat(p,"Resource(model, true));\n } catch (error) {\n next(error);\n }\n});\n\n").concat(c,'.put("/", async (req, res, next) => {\n try {\n ').concat(x,"\n const model = await ").concat(p,".query().findById(").concat(""===x?"req.body.id":"validated.id",');\n if (!model) {\n throw new NotFoundException("').concat(p,'");\n }\n await model.$query().updateAndFetch(').concat(""===x?"req.body":"validated",");\n res.json(new ").concat(p,"Resource(model, true));\n } catch (error) {\n next(error);\n }\n});\n\n").concat(c,'.delete("/:id", async (req, res, next) => {\n try {\n const model = await ').concat(p,'.query().findById(+req.params.id);\n if (!model) {\n throw new NotFoundException("').concat(p,'");\n }\n await model.$query().delete();\n res.json(new ').concat(p,"Resource(model, true));\n } catch (error) {\n next(error);\n }\n});\n\nexport default ").concat(c,";\n"),g=t.dirname(m),n.existsSync(g)||n.mkdirSync(g,{recursive:!0}),n.writeFile(m,w,(function(e){e?console.error("Gagal membuat file:",e):console.log("File ".concat(d," berhasil dibuat di ").concat(m))})),o.next=24;break;case 21:o.prev=21,o.t0=o.catch(1),console.error("Gagal mendapatkan informasi kolom:",o.t0);case 24:return o.prev=24,o.finish(24);case 26:case"end":return o.stop()}}),o,null,[[1,21,24,26]])})));return function(e,n,t,r){return o.apply(this,arguments)}}();module.exports=o;
package/lib/make_crud.js CHANGED
@@ -1,2 +1,2 @@
1
1
  #!/usr/bin/env node
2
- "use strict";var e=require("./_virtual/_rollupPluginBabelHelpers.js"),r=require("./make_controller.js"),t=require("./make_model.js"),a=require("./make_resource.js"),n=require("./utils.js"),s=function(){var s=e.asyncToGenerator(e.regeneratorRuntime().mark((function s(c,o){var i,l,u,m,p,f,v,h,_,b=arguments;return e.regeneratorRuntime().wrap((function(s){for(;;)switch(s.prev=s.next){case 0:return i=b.length>2&&void 0!==b[2]?b[2]:"public",s.prev=1,s.next=4,o.select("*").from("information_schema.tables").whereNotIn("table_schema",["information_schema","pg_catalog"]).whereNotIn("table_name",["migrations","migrations_lock"]).where("table_type","BASE TABLE");case 4:l=s.sent,u=e.createForOfIteratorHelper(l),s.prev=6,u.s();case 8:if((m=u.n()).done){s.next=22;break}return p=m.value,f=p.table_name,v=n.capitalize(n.toCamelCase(n.removePluralSuffix(f))),h="".concat(v,"Resource"),_="".concat(v,"Controller"),s.next=16,t(v,f,o,i);case 16:return s.next=18,a(h,f,o,i);case 18:return s.next=20,r(_,f,c,o,i);case 20:s.next=8;break;case 22:s.next=27;break;case 24:s.prev=24,s.t0=s.catch(6),u.e(s.t0);case 27:return s.prev=27,u.f(),s.finish(27);case 30:s.next=35;break;case 32:s.prev=32,s.t1=s.catch(1),console.log(s.t1);case 35:return s.prev=35,s.finish(35);case 37:case"end":return s.stop()}}),s,null,[[1,32,35,37],[6,24,27,30]])})));return function(e,r){return s.apply(this,arguments)}}();module.exports=s;
2
+ "use strict";var e=require("./_virtual/_rollupPluginBabelHelpers.js"),r=require("./make_controller.js"),t=require("./make_model.js"),a=require("./make_resource.js"),n=require("./utils.js"),s=function(){var s=e.asyncToGenerator(e.regeneratorRuntime().mark((function s(c,o){var i,l,u,m,p,f,h,v,_,b=arguments;return e.regeneratorRuntime().wrap((function(s){for(;;)switch(s.prev=s.next){case 0:return i=b.length>2&&void 0!==b[2]?b[2]:"public",s.prev=1,s.next=4,o.select("*").from("information_schema.tables").whereNotIn("table_schema",["information_schema","pg_catalog"]).whereNotIn("table_name",["migrations","migrations_lock"]).where("table_type","BASE TABLE").where("table_schema",i);case 4:l=s.sent,u=e.createForOfIteratorHelper(l),s.prev=7,u.s();case 9:if((m=u.n()).done){s.next=23;break}return p=m.value,f=p.table_name,h=n.capitalize(n.toCamelCase(n.removePluralSuffix(f))),v="".concat(h,"Resource"),_="".concat(h,"Controller"),s.next=17,t(h,f,o,i);case 17:return s.next=19,a(v,f,o,i);case 19:return s.next=21,r(_,f,c,o,i);case 21:s.next=9;break;case 23:s.next=28;break;case 25:s.prev=25,s.t0=s.catch(7),u.e(s.t0);case 28:return s.prev=28,u.f(),s.finish(28);case 31:s.next=36;break;case 33:s.prev=33,s.t1=s.catch(1),console.log(s.t1);case 36:return s.prev=36,s.finish(36);case 38:case"end":return s.stop()}}),s,null,[[1,33,36,38],[7,25,28,31]])})));return function(e,r){return s.apply(this,arguments)}}();module.exports=s;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "frgen",
3
- "version": "0.0.4",
3
+ "version": "0.0.6",
4
4
  "description": "helper generator",
5
5
  "main": "lib/",
6
6
  "types": "lib/index.d.ts",