frgen 0.3.2 → 0.3.4
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.
- package/lib/main.js +1 -1
- package/lib/make_validation.js +1 -1
- package/package.json +1 -1
package/lib/main.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
"use strict";var e,r=require("./_virtual/_rollupPluginBabelHelpers.js"),a=require("./utils.js"),t=require("./make_model.js"),n=require("./make_resource.js"),s=require("./make_controller.js"),c=require("./make_crud.js"),i=require("./make_validation.js"),o=require("./make_service.js"),u=require("./db.js"),l=r.toArray(process.argv);l[0],l[1];var k=l[2],f=l[3],v=l[4],
|
|
2
|
+
"use strict";var e,r=require("./_virtual/_rollupPluginBabelHelpers.js"),a=require("./utils.js"),t=require("./make_model.js"),n=require("./make_resource.js"),s=require("./make_controller.js"),c=require("./make_crud.js"),i=require("./make_validation.js"),o=require("./make_service.js"),u=require("./db.js"),l=r.toArray(process.argv);l[0],l[1];var k=l[2],f=l[3],v=l[4],p=l.slice(5);k||(console.error("action undefined."),process.exit(1));var m="default",x=null!==(e=process.env.DB_SCHEMA)&&void 0!==e?e:"public",d=!1;if(p.length>0){var b,h=r.createForOfIteratorHelper(p);try{for(h.s();!(b=h.n()).done;){var y=b.value.split("="),j=r.slicedToArray(y,2),q=j[0],_=j[1];"--schema"===q&&(x=_),"--path"===q&&(m=_),"--prisma"===q&&(d=!0)}}catch(e){h.e(e)}finally{h.f()}}if("make:crud"===k){var g=r.toArray(process.argv);g[0],g[1],g[2];var A=g.slice(3);if(A.length>0){var H,T=r.createForOfIteratorHelper(A);try{for(T.s();!(H=T.n()).done;){var w=H.value.split("="),B=r.slicedToArray(w,2),C=B[0],D=B[1];"--schema"===C&&(x=D),"--prisma"===C&&(d=!0)}}catch(e){T.e(e)}finally{T.f()}}}(function(){var e=r.asyncToGenerator(r.regeneratorRuntime().mark((function e(){return r.regeneratorRuntime().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,e.next=3,a.checkDatabaseConnection(u);case 3:if("make:model"!==k){e.next=8;break}return e.next=6,t(f,v,u,x);case 6:e.next=31;break;case 8:if("make:resource"!==k){e.next=13;break}return e.next=11,n(f,v,u,x);case 11:e.next=31;break;case 13:if("make:controller"!==k){e.next=18;break}return e.next=16,s(f,v,m,u,x,d);case 16:e.next=31;break;case 18:if("make:crud"!==k){e.next=23;break}return e.next=21,c(m,u,x,d);case 21:e.next=31;break;case 23:if("make:validation"!==k){e.next=28;break}return e.next=26,i(f,v,u,x);case 26:e.next=31;break;case 28:if("make:service"!==k){e.next=31;break}return e.next=31,o(f,v,m,d);case 31:e.next=37;break;case 33:e.prev=33,e.t0=e.catch(0),console.log(e.t0),process.exit(1);case 37:return e.prev=37,u.end(),e.finish(37);case 40:case"end":return e.stop()}}),e,null,[[0,33,37,40]])})));return function(){return e.apply(this,arguments)}})()();
|
package/lib/make_validation.js
CHANGED
|
@@ -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(n,t){var a=arguments.length>2&&void 0!==arguments[2]?arguments[2]:[],c=arguments.length>3&&void 0!==arguments[3]?arguments[3]:[],
|
|
2
|
+
"use strict";var e=require("./_virtual/_rollupPluginBabelHelpers.js"),n=require("fs"),t=require("path"),r=require("./utils.js");function a(n,t){var a=arguments.length>2&&void 0!==arguments[2]?arguments[2]:[],c=arguments.length>3&&void 0!==arguments[3]?arguments[3]:[],u=t.type,i=t.nullable,o=t.defaultValue,s=["y"],l=["integer","bigint","smallint","tinyint","numeric","decimal","float"].includes(u),m=["varchar","text","string","char","character varying","uuid","date","datetime","timestamp","timestamp with time zone"].includes(u),p=["boolean"].includes(u);l?s.push("number()"):m?s.push("string()"):p?s.push("boolean()"):s.push("mixed()");var d=a.includes(n);i?(s.push("optional()"),s.push("nullable()")):d?s.push('when("$method", {\n is: (method) => method === "PUT",\n then: (schema) => schema.required(),\n otherwise: (schema) => schema.notRequired(),\n })'):s.push("required()");var h=c.map((function(e){return e.column_name})).includes(n);if(h){var f=c.find((function(e){return e.column_name===n}));f&&s.push("oneOf(Object.values(".concat(f.enum_name,"))"))}var v=["CURRENT_TIMESTAMP"].includes(o);if(o&&!v&&!d){var y;if(l)y=parseInt(o);else if(h){var b=c.find((function(e){return e.column_name===n}));b&&(y="".concat(b.enum_name,".").concat(r.extractEnumValue(o)))}else y=p?o:"'".concat(o,"'");void 0!==e.typeof(y)&&s.push("default(".concat(y,")"))}return s.push("label('".concat(n.replaceAll("_"," "),"')")),"".concat(r.toCamelCase(n),":").concat(s.join("."))}var c=function(){var c=e.asyncToGenerator(e.regeneratorRuntime().mark((function c(u,i,o){var s,l,m,p,d,h,f,v,y,b,g,_,x,T=arguments;return e.regeneratorRuntime().wrap((function(c){for(;;)switch(c.prev=c.next){case 0:return s=T.length>3&&void 0!==T[3]?T[3]:"public",c.prev=1,u||(console.error("valiation name undefined"),process.exit(1)),i||(console.error("table name undefined"),process.exit(1)),l="".concat(u,".ts"),m=t.join(process.cwd(),"src","app","http","validation",l),p=r.toCamelCase(r.removePluralSuffix(i)),c.next=9,r.getTableColumns(o,i,s);case 9:return d=c.sent,h=Object.fromEntries(d.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}]}))),c.next=13,r.getPrimaryKeys(o,i,s);case 13:return f=c.sent,c.next=16,r.getEnumFieldsAndValues(o,i,s);case 16:v=c.sent,y=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),c=t[0],u=t[1];return[r.toCamelCase(c),a(c,u,f,v)]})),b="",v.length&&(g=v.map((function(e){return e.enum_name})).join(","),b="import { ".concat(g,' } from "@prisma/client";')),_='\n import * as yup from "yup";\n '.concat(b,"\n\n export const ").concat(p,"Schema = (y:typeof yup) => y.object().shape({\n ").concat(y.map((function(n){var t=e.slicedToArray(n,2);return t[0],t[1]})).join(",\n"),"\n });\n\n export type ").concat(r.capitalize(p),"Schema = yup.InferType<ReturnType<typeof ").concat(p,"Schema>>;\n "),x=t.dirname(m),n.existsSync(x)||n.mkdirSync(x,{recursive:!0}),n.writeFile(m,_,(function(e){e?console.error("err: ",e):console.log("File ".concat(l," has been created"))})),c.next=29;break;case 26:c.prev=26,c.t0=c.catch(1),console.error("err:",c.t0);case 29:return c.prev=29,c.finish(29);case 31:case"end":return c.stop()}}),c,null,[[1,26,29,31]])})));return function(e,n,t){return c.apply(this,arguments)}}();module.exports=c;
|