very-express 0.7.3 → 0.7.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/dist/index.js CHANGED
@@ -978,7 +978,7 @@ export const {{documentName}}Model: Model<{{documentName}}Document> = model<{{do
978
978
  */
979
979
  `}u6.getGenaratorHeaderComment=F_e;u6.defaultCompilerOptions={headerComment:F_e(),use_id:!1};u6.default={getGenaratorHeaderComment:F_e,defaultCompilerOptions:u6.defaultCompilerOptions}});var m9e=vs(Vg=>{"use strict";var Ojr=Vg&&Vg.__createBinding||(Object.create?function(a,s,l,p){p===void 0&&(p=l);var d=Object.getOwnPropertyDescriptor(s,l);(!d||("get"in d?!s.__esModule:d.writable||d.configurable))&&(d={enumerable:!0,get:function(){return s[l]}}),Object.defineProperty(a,p,d)}:function(a,s,l,p){p===void 0&&(p=l),a[p]=s[l]}),Njr=Vg&&Vg.__setModuleDefault||(Object.create?function(a,s){Object.defineProperty(a,"default",{enumerable:!0,value:s})}:function(a,s){a.default=s}),f9e=Vg&&Vg.__importStar||function(a){if(a&&a.__esModule)return a;var s={};if(a!=null)for(var l in a)l!=="default"&&Object.prototype.hasOwnProperty.call(a,l)&&Ojr(s,a,l);return Njr(s,a),s},Ijr=Vg&&Vg.__awaiter||function(a,s,l,p){function d(_){return _ instanceof l?_:new l(function(h){h(_)})}return new(l||(l=Promise))(function(_,h){function y(C){try{x(p.next(C))}catch(k){h(k)}}function v(C){try{x(p.throw(C))}catch(k){h(k)}}function x(C){C.done?_(C.value):d(C.value).then(y,v)}x((p=p.apply(a,s||[])).next())})},N_e=Vg&&Vg.__importDefault||function(a){return a&&a.__esModule?a:{default:a}};Object.defineProperty(Vg,"__esModule",{value:!0});Vg.compileFromFile=Vg.json2Mongoose=void 0;var Bjr=f9e(require("util")),l9e=f9e(require("fs")),Ljr=N_e(u9e()),O_e=N_e(P_e()),Rjr=N_e(T_e());function p9e(a){switch(a.toLocaleLowerCase()){case"unix":case"unixtime":case"unix-time":return"new Date().getTime()";case"date":return"new Date().toISOString().slice(0, 10)";case"time":return"new Date().toISOString().slice(11, 19)";case"datetime":case"date-time":return"new Date().toISOString()";default:return a}}function d9e(a,s){var l,p;let d={onCreate:{},onUpdate:{}},_=s.type==="object"?s.properties:((l=s.items)===null||l===void 0?void 0:l.type)==="object"?s.items.properties:s;return s.type==="object"||((p=s.items)===null||p===void 0?void 0:p.type)==="object"?Object.keys(_).forEach(h=>{let y=_[h],v=d9e(h,y);Object.keys(v.onCreate).forEach(x=>{let C=[a,x].filter(k=>k).join(".");d.onCreate[C]=v.onCreate[x]}),Object.keys(v.onUpdate).forEach(x=>{let C=[a,x].filter(k=>k).join(".");d.onUpdate[C]=v.onUpdate[x]})}):a&&(s["x-onCreateValue"]&&(d.onCreate[a]=p9e(s["x-onCreateValue"])),s["x-onUpdateValue"]&&(d.onUpdate[a]=p9e(s["x-onUpdateValue"]))),d}function _9e(a,s){var l;let p={},d=a.required||[],_=a.index||[];for(let h in a.properties){let y=a.properties[h];if(!s.use_id&&h==="_id"||typeof y.type!="string")continue;let v=C=>{switch(C.toLowerCase()){case"string":return"{{String}}";case"integer":case"float":case"number":return"{{Number}}";case"boolean":return"{{Boolean}}";case"null":return"{{null}}";default:throw new Error(`Unsupported type [${C}]`)}},x=(C,k,N)=>{let F={type:"String",index:N.index||!!N["x-foreignKey"]||_.includes(h)||!1,required:N.required||d.includes(h)||!1};switch(k.toLowerCase()){case"string":if(N["x-foreignKey"]){let P=N["x-format"]=="ObjectId"?"Schema.Types.ObjectId":"String";F.type=`{{${P}}}`}else F.type="{{String}}";break;case"integer":case"float":case"number":F.type="{{Number}}";break;case"boolean":F.type="{{Boolean}}";break;case"null":F.type="{{null}}";break;case"array":if(N.items)if(N.items.type=="object"){if(!N.items.properties)throw new Error(`"${C}" Array items as object must have properties defined !`);F.type=[x(C,N.items.type,N.items)]}else if(N.items["x-foreignKey"]){let P=N.items["x-format"]=="ObjectId"?"Schema.Types.ObjectId":"String";F.type=[`{{${P}}}`]}else F.type=[v(N.items.type)];break;case"object":F=_9e(N,s);break;default:throw new Error(`Unsupported type [${N.type}]`)}return F};p[h]=x(h,y.type,y),y.default&&(p[h].default=y.default),(y["x-foreignKey"]||!((l=y.items)===null||l===void 0)&&l["x-foreignKey"])&&(p[h].ref=y["x-foreignKey"]||y.items["x-foreignKey"])}return p}function h9e(a,s,l){if(!a["x-documentConfig"])throw new Error("( jsonSchema.x-documentConfig : object ) is required");let d=a["x-documentConfig"].documentName,_=_9e(a,l||O_e.default.defaultCompilerOptions),y=Bjr.inspect(_,{depth:null}).replace(/'{{/g,"").replace(/}}'/g,"").replace(/"{{/g,"").replace(/}}"/g,""),v=d9e(void 0,a);return Ljr.default.modelsTemplate(s,d,y,v,l||O_e.default.defaultCompilerOptions)}Vg.json2Mongoose=h9e;function jjr(a,s,l,p){return Ijr(this,void 0,void 0,function*(){try{Rjr.default.process(`Model : ${a} > ${l}`);let d=l9e.readFileSync(a),_=JSON.parse(d.toString()),h=h9e(_,s,p||O_e.default.defaultCompilerOptions);return l9e.writeFileSync(l,h),h}catch(d){throw new Error(`Processing File [${a}] :
980
980
  ${d.message||d}`)}})}Vg.compileFromFile=jjr});var b9e=vs(z7=>{"use strict";var Mjr=z7&&z7.__createBinding||(Object.create?function(a,s,l,p){p===void 0&&(p=l);var d=Object.getOwnPropertyDescriptor(s,l);(!d||("get"in d?!s.__esModule:d.writable||d.configurable))&&(d={enumerable:!0,get:function(){return s[l]}}),Object.defineProperty(a,p,d)}:function(a,s,l,p){p===void 0&&(p=l),a[p]=s[l]}),qjr=z7&&z7.__setModuleDefault||(Object.create?function(a,s){Object.defineProperty(a,"default",{enumerable:!0,value:s})}:function(a,s){a.default=s}),I_e=z7&&z7.__importStar||function(a){if(a&&a.__esModule)return a;var s={};if(a!=null)for(var l in a)l!=="default"&&Object.prototype.hasOwnProperty.call(a,l)&&Mjr(s,a,l);return qjr(s,a),s},y9e=z7&&z7.__importDefault||function(a){return a&&a.__esModule?a:{default:a}};Object.defineProperty(z7,"__esModule",{value:!0});z7.genarate=void 0;var bT=I_e(require("fs")),v9e=I_e(s9e()),x9e=I_e(m9e()),$jr=y9e(require("path")),g9e=y9e(P_e()),Ujr=(a,s)=>$jr.default.relative(a,s).replace(/\\/g,"/");function D9e(a,s,l,p){bT.readdir(a,(d,_)=>{if(d){console.log(d);return}bT.existsSync(s)&&bT.rmSync(s,{recursive:!0}),bT.mkdirSync(s),bT.existsSync(l)&&bT.rmSync(l,{recursive:!0}),bT.mkdirSync(l),_.forEach(h=>{var y;try{if(!h.endsWith(".json"))return;let v=bT.readFileSync(`${a}/${h}`),C=(y=JSON.parse(v.toString())["x-documentConfig"])===null||y===void 0?void 0:y.documentName;if(!C)throw new Error(`invalid "x-documentConfig.documentName" in ${a}/${h}`);v9e.compileFromFile(`${a}/${h}`,`${l}/${C}.ts`,p||g9e.default.defaultCompilerOptions),x9e.compileFromFile(`${a}/${h}`,`${Ujr(s,l)}/${C}`,`${s}/${C}Model.ts`,p||g9e.default.defaultCompilerOptions)}catch(v){console.error("\x1B[31m%s\x1B[0m",`Processing File : ${a}/${h}
981
- `,v)}})})}z7.genarate=D9e;z7.default={genarate:D9e,typesGen:v9e,modelsGen:x9e}});var RO=dd(require("fs")),R9e=dd(require("child_process")),j9e=dd(Kbe());var w3=dd(require("fs")),Y_=dd(require("path"));var Qd=dd(require("fs")),KE=dd(require("path"));function PEr(a,...s){console.log("\x1B[34m%s\x1B[0m","[PROCESSING]",a,s.length>0?s:"")}function OEr(a,...s){console.log("\x1B[32m%s\x1B[0m","[WRITING]",a,s.length>0?s:"")}function NEr(a,...s){console.log("\x1B[36m%s\x1B[0m","[INFO]",a,s.length>0?s:"")}function IEr(a,...s){console.log("\x1B[33m%s\x1B[0m","[WARN]",a,s.length>0?s:"")}function BEr(a,...s){console.log("\x1B[41m%s\x1B[0m","[ERROR]",a,s.length>0?s:""),process.exit(1)}var gc={process:PEr,writing:OEr,info:NEr,warn:IEr,error:BEr};var X5={name:"very-express",version:"0.7.3",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",preversion:"npm run lint && npm run compile",postversion:"npm run compile && git push --tags && git push"},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.19.39","@types/passport":"^1.0.16","@types/pg":"^8.20.0","@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",knex:"^3.2.9",minimist:"^1.2.8",mongoose:"^8.7.1",mysql2:"^3.22.0",objection:"^3.1.5",pg:"^8.20.0","ts-node":"^10.9.2",typescript:"^5.3.3"}};function fpe(a){return`/**
981
+ `,v)}})})}z7.genarate=D9e;z7.default={genarate:D9e,typesGen:v9e,modelsGen:x9e}});var RO=dd(require("fs")),R9e=dd(require("child_process")),j9e=dd(Kbe());var w3=dd(require("fs")),Y_=dd(require("path"));var Qd=dd(require("fs")),KE=dd(require("path"));function PEr(a,...s){console.log("\x1B[34m%s\x1B[0m","[PROCESSING]",a,s.length>0?s:"")}function OEr(a,...s){console.log("\x1B[32m%s\x1B[0m","[WRITING]",a,s.length>0?s:"")}function NEr(a,...s){console.log("\x1B[36m%s\x1B[0m","[INFO]",a,s.length>0?s:"")}function IEr(a,...s){console.log("\x1B[33m%s\x1B[0m","[WARN]",a,s.length>0?s:"")}function BEr(a,...s){console.log("\x1B[41m%s\x1B[0m","[ERROR]",a,s.length>0?s:""),process.exit(1)}var gc={process:PEr,writing:OEr,info:NEr,warn:IEr,error:BEr};var X5={name:"very-express",version:"0.7.4",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",preversion:"npm run lint && npm run compile",postversion:"npm run compile && git push --tags && git push"},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.19.39","@types/passport":"^1.0.16","@types/pg":"^8.20.0","@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",knex:"^3.2.9",minimist:"^1.2.8",mongoose:"^8.7.1",mysql2:"^3.22.0",objection:"^3.1.5",pg:"^8.20.0","ts-node":"^10.9.2",typescript:"^5.3.3"}};function fpe(a){return`/**
982
982
  * Generated by veryExpress@${a}
983
983
  * https://github.com/Justin26l/VeryExpress
984
984
  */
@@ -1054,13 +1054,26 @@ export default new RoleBaseAccessControl()
1054
1054
  `)}
1055
1055
  ${sr} {
1056
1056
  ${mr}
1057
- }`:`// ${tt[0].replace(/^@/,"")} disabled`}let ie=_?`@Middlewares(JoinWhitelistMiddleware.middleware("${s}"))`:null,ue=Ee(p.includes("getList"),['@Post("/search")','@SuccessResponse(200, "Success")',...ie?[ie]:[]],`public async getList${s}(@Body() body: { filter: Filter${s}, join?: string[], select?: string[], pagination?: VexPagination }): Promise<VexResponse<${s}${d?"":"WithApiRelations"}[] | PaginatedResult<${s}${d?"":"WithApiRelations"}>>>`,`if (body.pagination) {
1057
+ }`:`// ${tt[0].replace(/^@/,"")} disabled`}let ie=_?`@Middlewares(JoinWhitelistMiddleware.middleware("${s}"))`:null,ue=Ee(p.includes("getList"),['@Post("/search")','@SuccessResponse(200, "Success")',...ie?[ie]:[]],`public async getList${s}(@Body() body: { filter: Filter${s}, join?: string[], select?: string[], pagination?: VexPagination }): Promise<VexResponse<PaginatedResult<${s}${d?"":"WithApiRelations"}>>>`,`if (body.pagination) {
1058
1058
  const data = await this.repo.find(body.filter as Filter<${s}>, body.join, body.select, body.pagination);
1059
1059
  const total = await this.repo.count(body.filter as Filter<${s}>);
1060
- throw new VexResOk(200, { result: { data, total, page: body.pagination.page || 1, perPage: body.pagination.perPage || 20 } });
1060
+ throw new VexResOk(200, {
1061
+ result: {
1062
+ data,
1063
+ total,
1064
+ page: body.pagination.page || 1,
1065
+ perPage: body.pagination.perPage || 20
1066
+ }
1067
+ });
1061
1068
  }
1062
- const result = await this.repo.find(body.filter as Filter<${s}>, body.join, body.select);
1063
- throw new VexResOk(200, { result });`),pe=Ee(p.includes("get"),['@Get("{id}")','@SuccessResponse(200, "Success")',...ie?[ie]:[]],`public async get${s}(${$}, @Query() join?: string[], @Query() select?: string[]): Promise<VexResponse<${s}${d?"":"WithApiRelations"}>>`,`const result = await this.repo.findOne({ _id: id }, join, select);
1069
+ else {
1070
+ const result = await this.repo.find(body.filter as Filter<${s}>, body.join, body.select);
1071
+ throw new VexResOk(200, {
1072
+ result: {
1073
+ data: result
1074
+ }
1075
+ });
1076
+ };`),pe=Ee(p.includes("get"),['@Get("{id}")','@SuccessResponse(200, "Success")',...ie?[ie]:[]],`public async get${s}(${$}, @Query() join?: string[], @Query() select?: string[]): Promise<VexResponse<${s}${d?"":"WithApiRelations"}>>`,`const result = await this.repo.findOne({ _id: id }, join, select);
1064
1077
  if (!result) throw new VexResErr(404);
1065
1078
  throw new VexResOk(200, { result });`),ye=Ee(p.includes("post"),["@Post()",'@SuccessResponse(201, "Created")'],`public async create${s}(@Body() body: ${s}): Promise<VexResponse<${s}>>`,`${N}
1066
1079
  const result = await this.repo.create(body);
@@ -37,9 +37,9 @@ export type VexPagination = {
37
37
 
38
38
  export type PaginatedResult<T> = {
39
39
  data: T[];
40
- total: number;
41
- page: number;
42
- perPage: number;
40
+ total?: number;
41
+ page?: number;
42
+ perPage?: number;
43
43
  };
44
44
 
45
45
  export interface VexRequest<T = any> {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "very-express",
3
- "version": "0.7.3",
3
+ "version": "0.7.4",
4
4
  "description": "based on json schema and openapi, generate Express RestApi server with mongoDb ",
5
5
  "author": "Justin26l",
6
6
  "license": "MIT",