frgen 0.3.3 → 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/make_validation.js +1 -1
- package/package.json +1 -1
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;
|