very-express 0.5.22 → 0.5.23
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/dist/index.js +3 -3
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1009,7 +1009,7 @@ export const {{documentName}}Model: Model<{{documentName}}Document> = model<{{do
|
|
|
1009
1009
|
`+n.slice(f,_),f=_+1),h=g;return v+=`
|
|
1010
1010
|
`,n.length-f>s&&h>f?v+=n.slice(f,h)+`
|
|
1011
1011
|
`+n.slice(h+1):v+=n.slice(f),v.slice(1)}function y$r(n){for(var s="",c=0,p,f=0;f<n.length;c>=65536?f+=2:f++)c=gX(n,f),p=$g[c],!p&&DX(c)?(s+=n[f],c>=65536&&(s+=n[f+1])):s+=p||c$r(c);return s}function v$r(n,s,c){var p="",f=n.tag,_,h,g;for(_=0,h=c.length;_<h;_+=1)g=c[_],n.replacer&&(g=n.replacer.call(c,String(_),g)),(JS(n,s,g,!1,!1)||typeof g=="undefined"&&JS(n,s,null,!1,!1))&&(p!==""&&(p+=","+(n.condenseFlow?"":" ")),p+=n.dump);n.tag=f,n.dump="["+p+"]"}function YFe(n,s,c,p){var f="",_=n.tag,h,g,v;for(h=0,g=c.length;h<g;h+=1)v=c[h],n.replacer&&(v=n.replacer.call(c,String(h),v)),(JS(n,s+1,v,!0,!0,!1,!0)||typeof v=="undefined"&&JS(n,s+1,null,!0,!0,!1,!0))&&((!p||f!=="")&&(f+=uhe(n,s)),n.dump&&vX===n.dump.charCodeAt(0)?f+="-":f+="- ",f+=n.dump);n.tag=_,n.dump=f||"[]"}function x$r(n,s,c){var p="",f=n.tag,_=Object.keys(c),h,g,v,x,E;for(h=0,g=_.length;h<g;h+=1)E="",p!==""&&(E+=", "),n.condenseFlow&&(E+='"'),v=_[h],x=c[v],n.replacer&&(x=n.replacer.call(c,v,x)),JS(n,s,v,!1,!1)&&(n.dump.length>1024&&(E+="? "),E+=n.dump+(n.condenseFlow?'"':"")+":"+(n.condenseFlow?"":" "),JS(n,s,x,!1,!1)&&(E+=n.dump,p+=E));n.tag=f,n.dump="{"+p+"}"}function D$r(n,s,c,p){var f="",_=n.tag,h=Object.keys(c),g,v,x,E,w,O;if(n.sortKeys===!0)h.sort();else if(typeof n.sortKeys=="function")h.sort(n.sortKeys);else if(n.sortKeys)throw new Hy("sortKeys must be a boolean or a function");for(g=0,v=h.length;g<v;g+=1)O="",(!p||f!=="")&&(O+=uhe(n,s)),x=h[g],E=c[x],n.replacer&&(E=n.replacer.call(c,x,E)),JS(n,s+1,x,!0,!0,!0)&&(w=n.tag!==null&&n.tag!=="?"||n.dump&&n.dump.length>1024,w&&(n.dump&&vX===n.dump.charCodeAt(0)?O+="?":O+="? "),O+=n.dump,w&&(O+=uhe(n,s)),JS(n,s+1,E,!0,w)&&(n.dump&&vX===n.dump.charCodeAt(0)?O+=":":O+=": ",O+=n.dump,f+=O));n.tag=_,n.dump=f||"{}"}function XFe(n,s,c){var p,f,_,h,g,v;for(f=c?n.explicitTypes:n.implicitTypes,_=0,h=f.length;_<h;_+=1)if(g=f[_],(g.instanceOf||g.predicate)&&(!g.instanceOf||typeof s=="object"&&s instanceof g.instanceOf)&&(!g.predicate||g.predicate(s))){if(c?g.multi&&g.representName?n.tag=g.representName(s):n.tag=g.tag:n.tag="?",g.represent){if(v=n.styleMap[g.tag]||g.defaultStyle,T9e.call(g.represent)==="[object Function]")p=g.represent(s,v);else if(k9e.call(g.represent,v))p=g.represent[v](s,v);else throw new Hy("!<"+g.tag+'> tag resolver accepts not "'+v+'" style');n.dump=p}return!0}return!1}function JS(n,s,c,p,f,_,h){n.tag=null,n.dump=c,XFe(n,c,!1)||XFe(n,c,!0);var g=T9e.call(n.dump),v=p,x;p&&(p=n.flowLevel<0||n.flowLevel>s);var E=g==="[object Object]"||g==="[object Array]",w,O;if(E&&(w=n.duplicates.indexOf(c),O=w!==-1),(n.tag!==null&&n.tag!=="?"||O||n.indent!==2&&s>0)&&(f=!1),O&&n.usedDuplicates[w])n.dump="*ref_"+w;else{if(E&&O&&!n.usedDuplicates[w]&&(n.usedDuplicates[w]=!0),g==="[object Object]")p&&Object.keys(n.dump).length!==0?(D$r(n,s,n.dump,f),O&&(n.dump="&ref_"+w+n.dump)):(x$r(n,s,n.dump),O&&(n.dump="&ref_"+w+" "+n.dump));else if(g==="[object Array]")p&&n.dump.length!==0?(n.noArrayIndent&&!h&&s>0?YFe(n,s-1,n.dump,f):YFe(n,s,n.dump,f),O&&(n.dump="&ref_"+w+n.dump)):(v$r(n,s,n.dump),O&&(n.dump="&ref_"+w+" "+n.dump));else if(g==="[object String]")n.tag!=="?"&&m$r(n,n.dump,s,_,v);else{if(g==="[object Undefined]")return!1;if(n.skipInvalid)return!1;throw new Hy("unacceptable kind of an object to dump "+g)}n.tag!==null&&n.tag!=="?"&&(x=encodeURI(n.tag[0]==="!"?n.tag.slice(1):n.tag).replace(/!/g,"%21"),n.tag[0]==="!"?x="!"+x:x.slice(0,18)==="tag:yaml.org,2002:"?x="!!"+x.slice(18):x="!<"+x+">",n.dump=x+" "+n.dump)}return!0}function b$r(n,s){var c=[],p=[],f,_;for(lhe(n,c,p),f=0,_=p.length;f<_;f+=1)s.duplicates.push(c[p[f]]);s.usedDuplicates=new Array(_)}function lhe(n,s,c){var p,f,_;if(n!==null&&typeof n=="object")if(f=s.indexOf(n),f!==-1)c.indexOf(f)===-1&&c.push(f);else if(s.push(n),Array.isArray(n))for(f=0,_=n.length;f<_;f+=1)lhe(n[f],s,c);else for(p=Object.keys(n),f=0,_=p.length;f<_;f+=1)lhe(n[p[f]],s,c)}function E$r(n,s){s=s||{};var c=new p$r(s);c.noRefs||b$r(n,c);var p=n;return c.replacer&&(p=c.replacer.call({"":p},"",p)),JS(c,0,p,!0,!0)?c.dump+`
|
|
1012
|
-
`:""}var C$r=E$r,A$r={dump:C$r};function mhe(n,s){return function(){throw new Error("Function yaml."+n+" is removed in js-yaml 4. Use yaml."+s+" instead, which is now safe by default.")}}var S$r=$2,w$r=e9e,T$r=i9e,k$r=c9e,F$r=l9e,P$r=fhe,O$r=w9e.load,N$r=w9e.loadAll,I$r=A$r.dump,B$r=Hy,L$r={binary:h9e,float:u9e,map:n9e,null:a9e,pairs:g9e,set:y9e,timestamp:d9e,bool:s9e,int:o9e,merge:_9e,omap:m9e,seq:r9e,str:t9e},R$r=mhe("safeLoad","load"),j$r=mhe("safeLoadAll","loadAll"),M$r=mhe("safeDump","dump"),q$r={Type:S$r,Schema:w$r,FAILSAFE_SCHEMA:T$r,JSON_SCHEMA:k$r,CORE_SCHEMA:F$r,DEFAULT_SCHEMA:P$r,load:O$r,loadAll:N$r,dump:I$r,YAMLException:B$r,types:L$r,safeLoad:R$r,safeLoadAll:j$r,safeDump:M$r},Tae=q$r;var B3=S_(require("fs")),Fae=S_(require("path"));function $$r(n,...s){console.log("\x1B[34m%s\x1B[0m","[PROCESSING]",n,s.length>0?s:"")}function U$r(n,...s){console.log("\x1B[32m%s\x1B[0m","[WRITING]",n,s.length>0?s:"")}function K$r(n,...s){console.log("\x1B[36m%s\x1B[0m","[INFO]",n,s.length>0?s:"")}function V$r(n,...s){console.log("\x1B[33m%s\x1B[0m","[WARN]",n,s.length>0?s:"")}function H$r(n,...s){console.log("\x1B[41m%s\x1B[0m","[ERROR]",n,s.length>0?s:""),process.exit(1)}var Yl={process:$$r,writing:U$r,info:K$r,warn:V$r,error:H$r};var T$={name:"very-express",version:"0.5.
|
|
1012
|
+
`:""}var C$r=E$r,A$r={dump:C$r};function mhe(n,s){return function(){throw new Error("Function yaml."+n+" is removed in js-yaml 4. Use yaml."+s+" instead, which is now safe by default.")}}var S$r=$2,w$r=e9e,T$r=i9e,k$r=c9e,F$r=l9e,P$r=fhe,O$r=w9e.load,N$r=w9e.loadAll,I$r=A$r.dump,B$r=Hy,L$r={binary:h9e,float:u9e,map:n9e,null:a9e,pairs:g9e,set:y9e,timestamp:d9e,bool:s9e,int:o9e,merge:_9e,omap:m9e,seq:r9e,str:t9e},R$r=mhe("safeLoad","load"),j$r=mhe("safeLoadAll","loadAll"),M$r=mhe("safeDump","dump"),q$r={Type:S$r,Schema:w$r,FAILSAFE_SCHEMA:T$r,JSON_SCHEMA:k$r,CORE_SCHEMA:F$r,DEFAULT_SCHEMA:P$r,load:O$r,loadAll:N$r,dump:I$r,YAMLException:B$r,types:L$r,safeLoad:R$r,safeLoadAll:j$r,safeDump:M$r},Tae=q$r;var B3=S_(require("fs")),Fae=S_(require("path"));function $$r(n,...s){console.log("\x1B[34m%s\x1B[0m","[PROCESSING]",n,s.length>0?s:"")}function U$r(n,...s){console.log("\x1B[32m%s\x1B[0m","[WRITING]",n,s.length>0?s:"")}function K$r(n,...s){console.log("\x1B[36m%s\x1B[0m","[INFO]",n,s.length>0?s:"")}function V$r(n,...s){console.log("\x1B[33m%s\x1B[0m","[WARN]",n,s.length>0?s:"")}function H$r(n,...s){console.log("\x1B[41m%s\x1B[0m","[ERROR]",n,s.length>0?s:""),process.exit(1)}var Yl={process:$$r,writing:U$r,info:K$r,warn:V$r,error:H$r};var T$={name:"very-express",version:"0.5.23",description:"based on json schema and openapi, generate Express RestApi server with mongoDb ",author:"Justin26l",license:"MIT",main:"index.js",bin:{vex:"./dist/index.js"},scripts:{start:"node ./dist/index.js",dev:"npm run compile && npm run start",build:"npm run lint && npm run compile",lint:"eslint ./src --ext .ts --fix",compile:"node ./scripts/build.js && node ./scripts/copyTsTemplates.js"},keywords:["jsonSchema","express","RestApi","mongoDb","mongoose","json2mongoose"],repository:{type:"git",url:"git+https://github.com/Justin26l/VeryExpress.git"},devDependencies:{"@types/js-yaml":"^4.0.9","@types/minimist":"^1.2.5","@types/ms":"^2.1.0","@types/node":"^20.10.5","@types/passport":"^1.0.16","@typescript-eslint/eslint-plugin":"^6.18.1","@typescript-eslint/parser":"^6.18.1","diff-match-patch":"^1.0.5",dotenv:"^16.3.1",esbuild:"0.23.0",eslint:"^8.57.1","js-yaml":"^4.1.0","json-schema-to-openapi-schema":"^0.4.0","json-schema-to-typescript":"^13.1.1",json2mongoose:"^0.4.8",minimist:"^1.2.8",mongoose:"^8.7.1","ts-node":"^10.9.2",typescript:"^5.3.3"}};function ghe(n){return`/**
|
|
1013
1013
|
* Generated by veryExpress@${n}
|
|
1014
1014
|
* https://github.com/Justin26l/VeryExpress
|
|
1015
1015
|
*/
|
|
@@ -1020,7 +1020,7 @@ export const {{documentName}}Model: Model<{{documentName}}Document> = model<{{do
|
|
|
1020
1020
|
`}function z$r(){return`// Generated by veryExpress@${T$.version}`}function W$r(){return"// Generated by veryExpress"}function kae(n){return Object.keys(n.auth.oauthProviders).filter(s=>n.auth.oauthProviders[s]===!0)}function yhe(n){return n.auth.localAuth||kae(n).length>0}var vhe={rootDir:".",srcDir:"./src",sysDir:"./src/system",jsonSchemaDir:"./jsonSchema",openapiDir:"./openapi",generator:{commitBeforeGenerate:!1},app:{enableSwagger:!0,useUserSchema:!0,useStatefulRedisAuth:!1,useObjectID:!0,allowApiCreateUpdate_id:!1},useRBAC:{roles:["user"],default:"user",schemaIncluded:["user"]},auth:{localAuth:!0,useHttpOnlyCookieToken:!1,oauthProviders:{google:!1,microsoft:!1,apple:!1,github:!1}},_:{writtedDir:[]}},M9e={defaultCompilerOptions:vhe,getDefaultHeaderComment:ghe,getStaticHeaderComment:G$r,getSimpleHeaderComment:z$r,getSimpleStaticHeaderComment:W$r,OAuthProviders:kae,isAuthEnabled:yhe};var $9e=vhe,Y$r=ghe(T$.version);function q9e(n){return n.replace(/\r\n/g,`
|
|
1021
1021
|
`).replace(/[ \t]+$/gm,"").trim()}var X$r=(n,s)=>Fae.default.relative(n,s).replace(/\\/g,"/");function Q$r(n,s){let c=B3.default.existsSync(n);if(!c&&s)return s();if(c)try{let p=JSON.parse(B3.default.readFileSync(n,"utf8"));return p||Yl.error(`FILE JSON : Read Error ${n}`)}catch(p){return Yl.error(`FILE : ${n}
|
|
1022
1022
|
`,p.message)}else return Yl.error(`FILE : ${n} not found`)}function U9e(n,s,c){let p=B3.default.existsSync(s)?B3.default.readFileSync(s,"utf8"):"",f=/\/\*\*\s*\r?\n \* Generated by veryExpress@[^\r\n]+\r?\n \* https:\/\/github\.com\/Justin26l\/VeryExpress\s*\r?\n \*\/\s*/g,_=q9e(p.replace(f,"")),h=/^.*({{headerComment}}|\/\/ {{headerComment}}).*$(\r?\n)?/gm,g=q9e(c.replace(h,""));return _===g?!1:(Yl.writing(`${n} : "${s}"`),c=c.replace(/\/\/ {{headerComment}}|{{headerComment}}/g,Y$r||"// generated files by very-express"),B3.default.writeFileSync(s,c),!0)}function K9e(n,s,c,p){B3.default.existsSync(s)||B3.default.mkdirSync(s);let f=B3.default.readdirSync(n);for(let _=0;_<f.length;_++){let h=f[_],g=h=="index.ts"?h:h.replace(".ts",".gen.ts"),v=Fae.default.posix.join(n,h),x=Fae.default.posix.join(s,g);if(B3.default.lstatSync(v).isDirectory())K9e(v,x,c,p);else if(!p&&B3.default.existsSync(x))Yl.info(`FILE : AVOID OVERWRITE, skip "${x}"`);else{let E=B3.default.readFileSync(v,"utf8");U9e(`FILE : ${x}`,x,E)}}}function Z$r(n){$9e=n}function eUr(){return $9e}var V9e={relativePath:X$r,copyDir:K9e,loadJson:Q$r,writeFile:U9e,setCompilerOptions:Z$r,getCompilerOptions:eUr};function tUr(n){let s=/'FUNC{{(.*?)}}'/g,c;for(c=s.exec(n);c!=null;)n=n.replace(c[0],c[1]),c=s.exec(n);return n}var H9e={format:tUr};var bhe=S_(require("fs"));var J9e=["get","getList","post","put","patch","delete","options","head","trace"],Pae=["get","post","put","patch","delete","options","head","trace"];function rUr(n){if(!bhe.default.existsSync(n))return Yl.error(`loadJsonSchema : File Not Found ${n}`);try{return JSON.parse(bhe.default.readFileSync(n,"utf8"))}catch(s){return Yl.error(`Error Load JsonSchema :
|
|
1023
|
-
`,s.message||s,n)}}function G9e(n,s){let c=JSON.parse(JSON.stringify(n)),p=Array.isArray(s),f=p?s:[],_=p?{}:s;for(let h in c)h.startsWith("x-")||p&&f.includes(h)||!p&&typeof _[h]!="undefined"&&_[h]==typeof c[h]?delete c[h]:typeof c[h]=="object"&&(c[h]=G9e(c[h],s));return c}function nUr(n,s){if(n=="getList")return"post";if(Pae.includes(n))return n;Yl.error(`httpMethod : invalid method "${n}" in "${s}".`),process.exit(1)}var z9e={cleanXcustomValue:G9e,httpMethod:nUr,loadJsonSchema:rUr};function iUr(n){if(!n)throw new Error("vex.config is undefined");if(!n.srcDir)throw new Error("vex.config.srcDir is undefined");if(!n.sysDir)throw new Error("vex.config.sysDir is undefined");if(!n.openapiDir)throw new Error("vex.config.openapiDir is undefined");if(!n.jsonSchemaDir)throw new Error("vex.config.jsonSchemaDir is undefined")}var W9e={checkConfigValid:iUr};var Yc={common:V9e,generator:M9e,template:H9e,jsonSchema:z9e,logger:Yl,configChecker:W9e};function X9e(n,s){return wp(this,null,function*(){let c={openapi:"3.0.0",info:{title:"veryExpress generated api server",description:"OpenApi Spec generated by veryExpress",version:"1.0.0"},paths:{},components:{securitySchemes:{},schemas:{}}};Yc.generator.isAuthEnabled(s)&&(c.components.securitySchemes={BearerAuth:{type:"http",scheme:"bearer",bearerFormat:"JWT"},AuthIndex:{type:"apiKey",in:"header",name:"X-Auth-Index"}}),Ehe.default.readdirSync(s.jsonSchemaDir).forEach(g=>{if(!g.endsWith(".json"))return;let v=Y9e.default.posix.join(s.jsonSchemaDir,g);Yl.process(`OpenApi : ${v}`);let x=Ehe.default.readFileSync(`${s.jsonSchemaDir}/${g}`),E=JSON.parse(x.toString());c=aUr(c,E,v,s),c=sUr(c,E,v,s)});let f=(0,k$.default)(c,{version:3}),_=Tae.dump(f),h=s.openapiDir+n;Yc.common.writeFile("OpenApi",h,_)})}function aUr(n,s,c,p){let f=s["x-documentConfig"],_=f.documentName.toLowerCase(),h=f.documentName,g=[{BearerAuth:[]},{AuthIndex:[]}],v=s.properties,x={["/api/"+_]:{"x-documentName":h},["/api/"+_+"/search"]:{"x-documentName":h},["/api/"+_+"/{id}"]:{"x-documentName":h}};return f.methods.forEach(E=>{let w=["get","put","patch","delete"].includes(E),O=E=="getList",F=["getList","post","put","patch"].includes(E),P="/api/"+_+(w?"/{id}":O?"/search":""),M=Yc.jsonSchema.httpMethod(E,c),ee=[],ae,$={200:{description:"OK",content:{"application/json":{schema:{$ref:`#/components/schemas/${E}${h}Response`}}}}};if(w&&v._id){let U={name:"id",in:"path",description:v._id.description,required:!0,schema:{type:v._id.type,format:v._id.format,"x-format":v._id["x-format"],minLength:v._id.minLength,maxLength:v._id.maxLength,minimum:v._id.minimum,maximum:v._id.maximum,enum:v._id.enum}};ee.push(U)}if(M=="post"?($[201]=Object.assign({},$[200]),$[201].description="Crerated",delete $[200]):M=="delete"&&delete $[200].content,F){let U={schema:{$ref:`#/components/schemas/${E}${h}Body`}};ae={description:`${E} ${f.documentName}`,required:!1,content:E=="getList"?{"text/plain":U}:{"application/json":U}}}x[P][M]={operationId:E+h,tags:[_],security:Yc.generator.isAuthEnabled(p)?g:void 0,parameters:ee,requestBody:ae,responses:Object.assign({400:{description:"Bad Request"},401:{description:"Unauthorized"},403:{description:"Forbidden"},404:{description:"Not Found"},405:{description:"Method Not Allowed"},413:{description:"Payload Too Large"},429:{description:"Too Many Requests"},500:{description:"Internal Server Error"},502:{description:"Bad Gateway"},503:{description:"Service Unavailable"}},$)}}),n.paths=Object.assign(n.paths,x),n}function sUr(n,s,c,p){let f={},_=s["x-documentConfig"],h=_.documentName,g={type:"object",properties:(0,k$.default)(Yc.jsonSchema.cleanXcustomValue(s.properties,["index","unique","required"]),{version:3})},v={type:"object",properties:(0,k$.default)(Yc.jsonSchema.cleanXcustomValue(s.properties,{index:"boolean",unique:"boolean",required:"boolean"}),{version:3}),required:s.required},x={type:"object",properties:(0,k$.default)(Yc.jsonSchema.cleanXcustomValue(v.properties,{_id:"object"}),{version:3}),required:s.required},E={type:"object",properties:(0,k$.default)(Yc.jsonSchema.cleanXcustomValue(x.properties,["required"]),{version:3})};return _.methods.forEach(w=>{let O=Yc.jsonSchema.httpMethod(w,c);switch(w){case"delete":break;case"get":f[O+h+"Response"]=g;break;case"getList":{f[w+h+"Body"]=oUr(),f[w+h+"Response"]={type:"array",items:g};break}case"patch":f[O+h+"Body"]=E,f[O+h+"Response"]=g;break;case"post":f[O+h+"Body"]=p.app.allowApiCreateUpdate_id?v:x,f[O+h+"Response"]=g;break;case"put":f[O+h+"Body"]=p.app.allowApiCreateUpdate_id?v:x,f[O+h+"Response"]=g;break;default:break}}),n.components.schemas=Object.assign(n.components.schemas,f),n}function oUr(){return{type:"object",properties:{_filter:{type:"object"},_select:{type:"array",items:{type:"string"}},_join:{type:"array",items:{type:"string"}}},example:{_filter:{fieldName:{$regex:/wildcardText/}},_select:["FieldName"],_join:["CollectionName"]}}}function Q9e(n,s){var f;let c=((f=n.split("/").pop())==null?void 0:f.split(".")[0])||"Unknown_File_Name",p=Yc.jsonSchema.loadJsonSchema(n);return p["x-documentConfig"]||Yl.error(`Json Schema Formatting: "${n}" x-documentConfig not found.`),p["x-documentConfig"].documentName||(Yl.warn(`Json Schema Formatting: "${n}" x-documentConfig.documentName added.`),p["x-documentConfig"].documentName=c),p["x-documentConfig"].methods||(Yl.warn(`Json Schema Formatting: "${n}" x-documentConfig.methods not found, supported methods added.`),p["x-documentConfig"].methods=Object.assign([],J9e)),p["x-documentConfig"].documentName!=c&&Yl.error(`Json Schema Formatting: "${n}" x-documentConfig.documentName is not consistant with file name.`),typeof p.properties!="object"&&Yl.error(`properties is invalid in ${n}`),s.app.useObjectID&&cUr(p,n),p.required=Che(p,n),Yc.common.writeFile("Json Schema Formatting",n,JSON.stringify(p,null,4)),p}function Che(n,s){let c,p=[],f=_=>!!(_.type=="array"&&_.items&&_.items.type=="object");if(f(n))c=n.items.properties,p=typeof n.items.required=="object"?n.items.required:[];else if(n.type=="object")c=n.properties,p=typeof n.required=="object"?n.required:[];else return;return c==null?Yl.error(`formatJsonSchema > formatRequired : invalid "schema.properties" in ${s}`,n):Object.keys(c).forEach(_=>{let h=c==null?void 0:c[_],g=!p.includes(_);h&&h.type!=="object"&&h.required===!0&&g?p.push(_):h&&h.items&&f(h)?h.items.required=Che(h.items,s):h&&h.type=="object"&&(h.required=Che(h,s),h.required&&h.required.length>0&&g&&p.push(_))}),p}function cUr(n,s){n.properties&&!n.properties._id&&(n.properties._id={type:"string",description:"Unique Identifier",example:"60c8c9d2b2b4f2c3e8d6f3e1"},Yl.info(`formatJsonSchema : "_id" field added to ${s}`))}var Z9e=S_(require("fs"));function ePe(n){var c;if(!n.compilerOptions.useRBAC)return;let s=["create","read","update","delete","search"];(c=n.compilerOptions.useRBAC)==null||c.roles.forEach(p=>{Yl.process(`Role Setting File : ${p}`);let f=`${n.roleSetupDir}/${p}.json`,_={};Z9e.default.existsSync(f)&&Object.assign(_,Yc.common.loadJson(f)),n.collectionList.forEach(h=>{_[h]||(_[h]=s)}),Yc.common.writeFile(`Role Setting File : ${f}`,f,JSON.stringify(_,null,4))})}function tPe(n){var s;n.compilerOptions.useRBAC&&((s=n.compilerOptions.useRBAC)==null||s.schemaIncluded.forEach(c=>{var _,h;Yl.process(`Schema Role Formatting : ${c}.json`);let p=`${n.compilerOptions.jsonSchemaDir}/${c}.json`,f=Yc.common.loadJson(p);for(let g in f.properties){let v=f.properties[g];if(v["x-vexData"]==="role"){v.type="array",v.default=[(_=n.compilerOptions.useRBAC)==null?void 0:_.default],v.items||(v.items={type:""}),v.items.type="string",v.items.enum=(h=n.compilerOptions.useRBAC)==null?void 0:h.roles;break}}Yc.common.writeFile("Schema Role Formatting",p,JSON.stringify(f,null,4))}))}function rPe(n){return wp(this,null,function*(){if(!n.compilerOptions.app.useUserSchema)return;Yl.process("UserSchmea");let s=`${n.compilerOptions.jsonSchemaDir}/User.json`,c=Yc.common.loadJson(__dirname+"/templates/jsonSchema/User.json"),p=Yc.common.loadJson(s,()=>c);Object.keys(c.properties).forEach(f=>{var _,h;p.properties[f]||(p.properties[f]=c.properties[f]),((_=p.properties[f])==null?void 0:_["x-vexData"])=="role"&&(p.properties[f].items.enum=((h=n.compilerOptions.useRBAC)==null?void 0:h.roles)||["user"])}),Yc.common.writeFile("UserSchmea",s,JSON.stringify(p,null,4))})}var She=S_(require("path"));var Ahe=S_(require("fs"));var nPe={main:"index.js",scripts:{build:"tsc -p . && node scripts/build.js",start:"node dist/server.js",dev:"nodemon --watch src --exec ts-node src/server.ts","docker-build":"docker build -t very-express .","docker-start":"docker run -p 3000:3000 very-express"},dependencies:{cookie:"^0.6.0","cookie-parser":"^1.4.6",dotenv:"^16.4.4",express:"^4.18.2","express-validator":"^7.0.1",helmet:"^7.1.0","js-yaml":"^4.1.0",jsonwebtoken:"^9.0.2","mongo-ts-querystring":"^1.0.4",mongodb:"^5.6.0",mongoose:"^7.4.0",passport:"^0.7.0","passport-google-oauth20":"^2.0.0","passport-github":"^1.1.0","passport-jwt":"^4.0.1","swagger-ui-express":"^5.0.0"},devDependencies:{"@types/cookie-parser":"^1.4.7","@types/jsonwebtoken":"^9.0.7","@types/crypto-js":"^4.1.2","@types/dotenv":"^8.2.0","@types/express":"^4.17.17","@types/express-validator":"^3.0.0","@types/js-yaml":"^4.0.9","@types/mongodb":"^4.0.7","@types/ms":"^2.1.0","@types/node":"^20.4.2","@types/passport":"^1.0.16","@types/passport-google-oauth20":"^2.0.14","@types/passport-github":"^1.1.12","@types/sequelize":"^4.28.15","@types/swagger-ui-express":"^4.1.6","@types/ws":"^8.5.5",nodemon:"^2.0.22","strip-json-comments":"^5.0.1","ts-node":"^10.9.1",typescript:"^5.1.6"}};function fUr(n,s){return wp(this,null,function*(){Yl.process(`Project Settings : ${n}`);let c="";Ahe.default.existsSync(n)?c=Ahe.default.readFileSync(n).toString():c=JSON.stringify(nPe);let p=JSON.parse(c);p.scripts.build||(Yl.process(`package.json : Update script : build > ${p.scripts.build}`),p.scripts.build="tsc -p . && node scripts/build.js"),p.scripts.dev||(Yl.process(`package.json : Update script : dev > ${p.scripts.dev}`),p.scripts.dev=`nodemon --watch src --exec ts-node ${s.srcDir}/server.ts`),p.scripts.start||(Yl.process(`package.json : Update script : start > ${p.scripts.start}`),p.scripts.start="node ./dist/server.js"),Yc.common.writeFile(`Project Settings : ${n}`,n,JSON.stringify(p,null,4))})}var iPe={compile:fUr};var aPe=S_(require("fs")),sPe=S_(require("path"));function dUr(n){return wp(this,null,function*(){let s=aPe.default.readFileSync(__dirname+"/templates/root/scripts/build.js","utf8"),c=Yc.common.relativePath(n.rootDir,n.openapiDir);s=s.replace("{{openapiDir}}",c),Yc.common.writeFile("Build Scripts",sPe.default.join(n.rootDir,"scripts/build.js"),s)})}var oPe={compile:dUr};var Oae=S_(require("fs"));function _Ur(n){return wp(this,null,function*(){Yl.process(`Project Settings : ${n}`);let s="",c=Oae.default.readFileSync(__dirname+"/templates/_projectSettings/env","utf8");if(console.log(`Processing .env file at ${n}`),!Oae.default.existsSync(n))s=c;else{s=Oae.default.readFileSync(n,"utf-8");let p=[],f=[],_=[];s.split(`
|
|
1023
|
+
`,s.message||s,n)}}function G9e(n,s){let c=JSON.parse(JSON.stringify(n)),p=Array.isArray(s),f=p?s:[],_=p?{}:s;for(let h in c)h.startsWith("x-")||p&&f.includes(h)||!p&&typeof _[h]!="undefined"&&_[h]==typeof c[h]?delete c[h]:typeof c[h]=="object"&&(c[h]=G9e(c[h],s));return c}function nUr(n,s){if(n=="getList")return"post";if(Pae.includes(n))return n;Yl.error(`httpMethod : invalid method "${n}" in "${s}".`),process.exit(1)}var z9e={cleanXcustomValue:G9e,httpMethod:nUr,loadJsonSchema:rUr};function iUr(n){if(!n)throw new Error("vex.config is undefined");if(!n.srcDir)throw new Error("vex.config.srcDir is undefined");if(!n.sysDir)throw new Error("vex.config.sysDir is undefined");if(!n.openapiDir)throw new Error("vex.config.openapiDir is undefined");if(!n.jsonSchemaDir)throw new Error("vex.config.jsonSchemaDir is undefined")}var W9e={checkConfigValid:iUr};var Yc={common:V9e,generator:M9e,template:H9e,jsonSchema:z9e,logger:Yl,configChecker:W9e};function X9e(n,s){return wp(this,null,function*(){let c={openapi:"3.0.0",info:{title:"veryExpress generated api server",description:"OpenApi Spec generated by veryExpress",version:"1.0.0"},paths:{},components:{securitySchemes:{},schemas:{}}};Yc.generator.isAuthEnabled(s)&&(c.components.securitySchemes={BearerAuth:{type:"http",scheme:"bearer",bearerFormat:"JWT"},AuthIndex:{type:"apiKey",in:"header",name:"X-Auth-Index"}}),Ehe.default.readdirSync(s.jsonSchemaDir).forEach(g=>{if(!g.endsWith(".json"))return;let v=Y9e.default.posix.join(s.jsonSchemaDir,g);Yl.process(`OpenApi : ${v}`);let x=Ehe.default.readFileSync(`${s.jsonSchemaDir}/${g}`),E=JSON.parse(x.toString());c=aUr(c,E,v,s),c=sUr(c,E,v,s)});let f=(0,k$.default)(c,{version:3}),_=Tae.dump(f),h=s.openapiDir+n;Yc.common.writeFile("OpenApi",h,_)})}function aUr(n,s,c,p){let f=s["x-documentConfig"],_=f.documentName.toLowerCase(),h=f.documentName,g=[{BearerAuth:[]},{AuthIndex:[]}],v=s.properties,x={["/api/"+_]:{"x-documentName":h},["/api/"+_+"/search"]:{"x-documentName":h},["/api/"+_+"/{id}"]:{"x-documentName":h}};return f.methods.forEach(E=>{let w=["get","put","patch","delete"].includes(E),O=E=="getList",F=["getList","post","put","patch"].includes(E),P="/api/"+_+(w?"/{id}":O?"/search":""),M=Yc.jsonSchema.httpMethod(E,c),ee=[],ae,$={200:{description:"OK",content:{"application/json":{schema:{$ref:`#/components/schemas/${E}${h}Response`}}}}};if(w&&v._id){let U={name:"id",in:"path",description:v._id.description,required:!0,schema:{type:v._id.type,format:v._id.format,"x-format":v._id["x-format"],minLength:v._id.minLength,maxLength:v._id.maxLength,minimum:v._id.minimum,maximum:v._id.maximum,enum:v._id.enum}};ee.push(U)}if(M=="post"?($[201]=Object.assign({},$[200]),$[201].description="Crerated",delete $[200]):M=="delete"&&delete $[200].content,F){let U={schema:{$ref:`#/components/schemas/${E}${h}Body`}};ae={description:`${E} ${f.documentName}`,required:!1,content:{"application/json":U}}}x[P][M]={operationId:E+h,tags:[_],security:Yc.generator.isAuthEnabled(p)?g:void 0,parameters:ee,requestBody:ae,responses:Object.assign({400:{description:"Bad Request"},401:{description:"Unauthorized"},403:{description:"Forbidden"},404:{description:"Not Found"},405:{description:"Method Not Allowed"},413:{description:"Payload Too Large"},429:{description:"Too Many Requests"},500:{description:"Internal Server Error"},502:{description:"Bad Gateway"},503:{description:"Service Unavailable"}},$)}}),n.paths=Object.assign(n.paths,x),n}function sUr(n,s,c,p){let f={},_=s["x-documentConfig"],h=_.documentName,g={type:"object",properties:(0,k$.default)(Yc.jsonSchema.cleanXcustomValue(s.properties,["index","unique","required"]),{version:3})},v={type:"object",properties:(0,k$.default)(Yc.jsonSchema.cleanXcustomValue(s.properties,{index:"boolean",unique:"boolean",required:"boolean"}),{version:3}),required:s.required},x={type:"object",properties:(0,k$.default)(Yc.jsonSchema.cleanXcustomValue(v.properties,{_id:"object"}),{version:3}),required:s.required},E={type:"object",properties:(0,k$.default)(Yc.jsonSchema.cleanXcustomValue(x.properties,["required"]),{version:3})};return _.methods.forEach(w=>{let O=Yc.jsonSchema.httpMethod(w,c);switch(w){case"delete":break;case"get":f[O+h+"Response"]=g;break;case"getList":{f[w+h+"Body"]=oUr(),f[w+h+"Response"]={type:"array",items:g};break}case"patch":f[O+h+"Body"]=E,f[O+h+"Response"]=g;break;case"post":f[O+h+"Body"]=p.app.allowApiCreateUpdate_id?v:x,f[O+h+"Response"]=g;break;case"put":f[O+h+"Body"]=p.app.allowApiCreateUpdate_id?v:x,f[O+h+"Response"]=g;break;default:break}}),n.components.schemas=Object.assign(n.components.schemas,f),n}function oUr(){return{type:"object",properties:{_filter:{type:"object"},_select:{type:"array",items:{type:"string"}},_join:{type:"array",items:{type:"string"}}},example:{_filter:{fieldName:{$regex:"str",$options:"i"}},_select:["FieldName"],_join:["CollectionName"]}}}function Q9e(n,s){var f;let c=((f=n.split("/").pop())==null?void 0:f.split(".")[0])||"Unknown_File_Name",p=Yc.jsonSchema.loadJsonSchema(n);return p["x-documentConfig"]||Yl.error(`Json Schema Formatting: "${n}" x-documentConfig not found.`),p["x-documentConfig"].documentName||(Yl.warn(`Json Schema Formatting: "${n}" x-documentConfig.documentName added.`),p["x-documentConfig"].documentName=c),p["x-documentConfig"].methods||(Yl.warn(`Json Schema Formatting: "${n}" x-documentConfig.methods not found, supported methods added.`),p["x-documentConfig"].methods=Object.assign([],J9e)),p["x-documentConfig"].documentName!=c&&Yl.error(`Json Schema Formatting: "${n}" x-documentConfig.documentName is not consistant with file name.`),typeof p.properties!="object"&&Yl.error(`properties is invalid in ${n}`),s.app.useObjectID&&cUr(p,n),p.required=Che(p,n),Yc.common.writeFile("Json Schema Formatting",n,JSON.stringify(p,null,4)),p}function Che(n,s){let c,p=[],f=_=>!!(_.type=="array"&&_.items&&_.items.type=="object");if(f(n))c=n.items.properties,p=typeof n.items.required=="object"?n.items.required:[];else if(n.type=="object")c=n.properties,p=typeof n.required=="object"?n.required:[];else return;return c==null?Yl.error(`formatJsonSchema > formatRequired : invalid "schema.properties" in ${s}`,n):Object.keys(c).forEach(_=>{let h=c==null?void 0:c[_],g=!p.includes(_);h&&h.type!=="object"&&h.required===!0&&g?p.push(_):h&&h.items&&f(h)?h.items.required=Che(h.items,s):h&&h.type=="object"&&(h.required=Che(h,s),h.required&&h.required.length>0&&g&&p.push(_))}),p}function cUr(n,s){n.properties&&!n.properties._id&&(n.properties._id={type:"string",description:"Unique Identifier",example:"60c8c9d2b2b4f2c3e8d6f3e1"},Yl.info(`formatJsonSchema : "_id" field added to ${s}`))}var Z9e=S_(require("fs"));function ePe(n){var c;if(!n.compilerOptions.useRBAC)return;let s=["create","read","update","delete","search"];(c=n.compilerOptions.useRBAC)==null||c.roles.forEach(p=>{Yl.process(`Role Setting File : ${p}`);let f=`${n.roleSetupDir}/${p}.json`,_={};Z9e.default.existsSync(f)&&Object.assign(_,Yc.common.loadJson(f)),n.collectionList.forEach(h=>{_[h]||(_[h]=s)}),Yc.common.writeFile(`Role Setting File : ${f}`,f,JSON.stringify(_,null,4))})}function tPe(n){var s;n.compilerOptions.useRBAC&&((s=n.compilerOptions.useRBAC)==null||s.schemaIncluded.forEach(c=>{var _,h;Yl.process(`Schema Role Formatting : ${c}.json`);let p=`${n.compilerOptions.jsonSchemaDir}/${c}.json`,f=Yc.common.loadJson(p);for(let g in f.properties){let v=f.properties[g];if(v["x-vexData"]==="role"){v.type="array",v.default=[(_=n.compilerOptions.useRBAC)==null?void 0:_.default],v.items||(v.items={type:""}),v.items.type="string",v.items.enum=(h=n.compilerOptions.useRBAC)==null?void 0:h.roles;break}}Yc.common.writeFile("Schema Role Formatting",p,JSON.stringify(f,null,4))}))}function rPe(n){return wp(this,null,function*(){if(!n.compilerOptions.app.useUserSchema)return;Yl.process("UserSchmea");let s=`${n.compilerOptions.jsonSchemaDir}/User.json`,c=Yc.common.loadJson(__dirname+"/templates/jsonSchema/User.json"),p=Yc.common.loadJson(s,()=>c);Object.keys(c.properties).forEach(f=>{var _,h;p.properties[f]||(p.properties[f]=c.properties[f]),((_=p.properties[f])==null?void 0:_["x-vexData"])=="role"&&(p.properties[f].items.enum=((h=n.compilerOptions.useRBAC)==null?void 0:h.roles)||["user"])}),Yc.common.writeFile("UserSchmea",s,JSON.stringify(p,null,4))})}var She=S_(require("path"));var Ahe=S_(require("fs"));var nPe={main:"index.js",scripts:{build:"tsc -p . && node scripts/build.js",start:"node dist/server.js",dev:"nodemon --watch src --exec ts-node src/server.ts","docker-build":"docker build -t very-express .","docker-start":"docker run -p 3000:3000 very-express"},dependencies:{cookie:"^0.6.0","cookie-parser":"^1.4.6",dotenv:"^16.4.4",express:"^4.18.2","express-validator":"^7.0.1",helmet:"^7.1.0","js-yaml":"^4.1.0",jsonwebtoken:"^9.0.2","mongo-ts-querystring":"^1.0.4",mongodb:"^5.6.0",mongoose:"^7.4.0",passport:"^0.7.0","passport-google-oauth20":"^2.0.0","passport-github":"^1.1.0","passport-jwt":"^4.0.1","swagger-ui-express":"^5.0.0"},devDependencies:{"@types/cookie-parser":"^1.4.7","@types/jsonwebtoken":"^9.0.7","@types/crypto-js":"^4.1.2","@types/dotenv":"^8.2.0","@types/express":"^4.17.17","@types/express-validator":"^3.0.0","@types/js-yaml":"^4.0.9","@types/mongodb":"^4.0.7","@types/ms":"^2.1.0","@types/node":"^20.4.2","@types/passport":"^1.0.16","@types/passport-google-oauth20":"^2.0.14","@types/passport-github":"^1.1.12","@types/sequelize":"^4.28.15","@types/swagger-ui-express":"^4.1.6","@types/ws":"^8.5.5",nodemon:"^2.0.22","strip-json-comments":"^5.0.1","ts-node":"^10.9.1",typescript:"^5.1.6"}};function fUr(n,s){return wp(this,null,function*(){Yl.process(`Project Settings : ${n}`);let c="";Ahe.default.existsSync(n)?c=Ahe.default.readFileSync(n).toString():c=JSON.stringify(nPe);let p=JSON.parse(c);p.scripts.build||(Yl.process(`package.json : Update script : build > ${p.scripts.build}`),p.scripts.build="tsc -p . && node scripts/build.js"),p.scripts.dev||(Yl.process(`package.json : Update script : dev > ${p.scripts.dev}`),p.scripts.dev=`nodemon --watch src --exec ts-node ${s.srcDir}/server.ts`),p.scripts.start||(Yl.process(`package.json : Update script : start > ${p.scripts.start}`),p.scripts.start="node ./dist/server.js"),Yc.common.writeFile(`Project Settings : ${n}`,n,JSON.stringify(p,null,4))})}var iPe={compile:fUr};var aPe=S_(require("fs")),sPe=S_(require("path"));function dUr(n){return wp(this,null,function*(){let s=aPe.default.readFileSync(__dirname+"/templates/root/scripts/build.js","utf8"),c=Yc.common.relativePath(n.rootDir,n.openapiDir);s=s.replace("{{openapiDir}}",c),Yc.common.writeFile("Build Scripts",sPe.default.join(n.rootDir,"scripts/build.js"),s)})}var oPe={compile:dUr};var Oae=S_(require("fs"));function _Ur(n){return wp(this,null,function*(){Yl.process(`Project Settings : ${n}`);let s="",c=Oae.default.readFileSync(__dirname+"/templates/_projectSettings/env","utf8");if(console.log(`Processing .env file at ${n}`),!Oae.default.existsSync(n))s=c;else{s=Oae.default.readFileSync(n,"utf-8");let p=[],f=[],_=[];s.split(`
|
|
1024
1024
|
`).forEach(h=>{if(!/=/g.test(h))return;let g=h.split("=",2)[0].replace("# ","");g&&p.push(g)}),c.split(`
|
|
1025
1025
|
`).forEach(h=>{if(!/=/g.test(h))return;let g=h.split("=",2)[0];g&&f.push(g)}),f.forEach(h=>{p.includes(h.replace("# ",""))||_.push(h)}),_.length>0&&(s+=`
|
|
1026
1026
|
|
|
@@ -1145,7 +1145,7 @@ class {{documentName}}Controller extends controllerFactory._ControllerFactory {
|
|
|
1145
1145
|
}
|
|
1146
1146
|
|
|
1147
1147
|
public async getList{{documentName}}(req: Request, res: Response): Promise<Response> {
|
|
1148
|
-
const searchFilter = req.body.
|
|
1148
|
+
const searchFilter = req.body._filter;
|
|
1149
1149
|
const selectedFields = utils.common.parseFieldsSelect(req);
|
|
1150
1150
|
const populateOptions = utils.common.parseCollectionJoin(req, {{populateOptions}});
|
|
1151
1151
|
|