ts-proto-client 1.0.3 → 1.0.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/README.md CHANGED
@@ -214,4 +214,4 @@ protoc --version
214
214
 
215
215
  ## License
216
216
 
217
- MIT
217
+ MIT
package/dist/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
- import{Command as q}from"commander";import R from"fs";import b from"path";import y from"fs";import j from"path";import{Root as x,Service as P}from"protobufjs";import u from"path";import C from"fs";var g=["get","post","put","delete","patch"];function w(t){let o=[t,u.join(t,"/third_party/googleapis")],e=new x;return e.resolvePath=(n,p)=>{for(let s of o){let i=u.join(s,p);if(C.existsSync(i))return i}return p},e}function h(t,o=[]){if(!t.nested)return o;for(let e of Object.values(t.nested))e instanceof P&&o.push(e),h(e,o);return o}function A(t){let o=t.parsedOptions?.find(n=>n["(google.api.http)"])?.["(google.api.http)"];if(!o)return null;let e=g.find(n=>o[n]);return e?{method:e,url:o[e],summary:t.options?.["(grpc.gateway.protoc_gen_openapiv2.options.openapiv2_operation).summary"]}:null}function O(t,o){let e=u.resolve(process.cwd(),t),n=w(e);n.loadSync(u.join(e,o));let p=h(n),s={};for(let i of p){let a=[];for(let r of Object.values(i.methods)){let m=A(r);m&&a.push({name:r.name,requestType:r.requestType,responseType:r.responseType,...m})}s[i.name]=a}return s}function v(t,o){let e=[];for(let[n,p]of Object.entries(t)){let s=new Set,i=[];for(let r of p){s.add(r.requestType),s.add(r.responseType);let m=r.method==="get"?"params: data":"data",d=[];r.summary&&d.push(`// ${r.summary}`),d.push(`export function ${r.name}(data: ${r.requestType}) {`,` return service<${r.responseType}>({`,` url: "${r.url.replace("/api","")}",`,` method: "${r.method}",`,` ${m}`," })","}"),i.push(d.join(`
3
- `))}let a=[...s].sort();e.push({[n]:['import { service } from "@/plugins";',"","import type {",` ${a.join(`,
2
+ import{Command as q}from"commander";import b from"fs";import R from"path";import y from"fs";import j from"path";import{Root as P,Service as x}from"protobufjs";import u from"path";import w from"fs";var g=["get","post","put","delete","patch"];function C(t){let o=[t,u.join(t,"/third_party/googleapis")],e=new P;return e.resolvePath=(n,p)=>{for(let s of o){let i=u.join(s,p);if(w.existsSync(i))return i}return p},e}function h(t,o=[]){if(!t.nested)return o;for(let e of Object.values(t.nested))e instanceof x&&o.push(e),h(e,o);return o}function A(t){let o=t.parsedOptions?.find(n=>n["(google.api.http)"])?.["(google.api.http)"];if(!o)return null;let e=g.find(n=>o[n]);return e?{method:e,url:o[e],summary:t.options?.["(grpc.gateway.protoc_gen_openapiv2.options.openapiv2_operation).summary"]}:null}function v(t,o){let e=u.resolve(process.cwd(),t),n=C(e);n.loadSync(u.join(e,o));let p=h(n),s={};for(let i of p){let a=[];for(let r of Object.values(i.methods)){let m=A(r);m&&a.push({name:r.name,requestType:r.requestType,responseType:r.responseType,...m})}s[i.name]=a}return s}function O(t,o){let e=[];for(let[n,p]of Object.entries(t)){let s=new Set,i=[];for(let r of p){s.add(r.requestType),s.add(r.responseType);let m=r.method==="get"?"params: data":"data",d=[];r.summary&&d.push(`// ${r.summary}`),d.push(`export function ${r.name}(data: ${r.requestType}) {`,` return service<${r.responseType}>({`,` url: "${r.url.replace("/api","")}",`,` method: "${r.method}",`,` ${m}`," })","}"),i.push(d.join(`
3
+ `))}let a=[...s].sort();e.push({[n]:['import { service } from "../..";',"","import type {",` ${a.join(`,
4
4
  `)}`,`} from "${o}";`,"",i.join(`
5
5
 
6
6
  `)].join(`
7
- `)})}return e}function T(t,o){let e=o.replace(/\\/g,"/").replace(/^\.?\//,"").replace(/\.proto$/,"");return u.join(t,e)}function _(t){let o=j.resolve(process.cwd(),t.apiOutput);y.existsSync(o)||y.mkdirSync(o,{recursive:!0});let e=O(t.root,t.file),n=T(t.typeOutput,t.file),p=j.relative(t.apiOutput,n).replace(/\\/g,"/"),s=v(e,p);for(let i of s)for(let[a,r]of Object.entries(i))y.writeFileSync(`${o}/${a}.ts`,r,"utf8");console.log("\u2705 Generate Success")}import{execSync as H}from"child_process";import f from"fs";import c from"path";function S(t){let o=c.resolve(process.cwd(),t.typeOutput);f.existsSync(o)||f.mkdirSync(o,{recursive:!0});let e=c.resolve(process.cwd(),t.root),n=["protoc",`--ts_proto_out=${o}`,"--ts_proto_opt=onlyTypes=true","--ts_proto_opt=useOptionals=messages","--ts_proto_opt=esModuleInterop=true",`--proto_path=${e}`,`--proto_path=${c.join(e,"/third_party/googleapis")}`,c.join(e,t.file)],p={...process.env,PATH:`${c.join(process.cwd(),"node_modules",".bin")};${process.env.PATH}`};H(n.join(" "),{stdio:"inherit",env:p}),f.rmSync(c.join(o,"google"),{recursive:!0,force:!0}),f.rmSync(c.join(o,"common.ts"),{force:!0})}async function $(t){if(!R.existsSync(b.resolve(process.cwd(),t.root))){console.log(`proto \u9879\u76EE\u4E0D\u5B58\u5728(${t.root})`);return}S(t),_(t)}var l=new q;l.name("proto-gen").description("proto code generator").version("1.0.0");l.command("generate").option("--file, --file <path>").option("--root, --root <path>").option("--type-output, --typeOutput <path>").option("--api-output, --apiOutput <path>").action(t=>{if(t.file===void 0){console.log("proto file \u4E0D\u80FD\u4E3A\u7A7A, \u8BF7\u8F93\u5165 --file ./account.proto");return}if(t.root===void 0){console.log("proto \u6587\u4EF6\u7684\u6839\u8DEF\u5F84\u4E0D\u80FD\u4E3A\u7A7A, \u8BF7\u8F93\u5165 --root ../protos");return}t.typeOutput===void 0&&(t.typeOutput="src/protos/type"),t.apiOutput===void 0&&(t.apiOutput="src/protos/api"),$(t)});l.parse();
7
+ `)})}return e}function T(t,o){let e=o.replace(/\\/g,"/").replace(/^\.?\//,"").replace(/\.proto$/,"");return u.join(t,e)}function _(t){let o=j.resolve(process.cwd(),t.apiOutput);y.existsSync(o)||y.mkdirSync(o,{recursive:!0});let e=v(t.root,t.file),n=T(t.typeOutput,t.file),p=j.relative(t.apiOutput,n).replace(/\\/g,"/"),s=O(e,p);for(let i of s)for(let[a,r]of Object.entries(i))y.writeFileSync(`${o}/${a}.ts`,r,"utf8");console.log("\u2705 Generate Success")}import{execSync as H}from"child_process";import f from"fs";import c from"path";function $(t){let o=c.resolve(process.cwd(),t.typeOutput);f.existsSync(o)||f.mkdirSync(o,{recursive:!0});let e=c.resolve(process.cwd(),t.root),n=["protoc",`--ts_proto_out=${o}`,"--ts_proto_opt=onlyTypes=true","--ts_proto_opt=useOptionals=messages","--ts_proto_opt=esModuleInterop=true",`--proto_path=${e}`,`--proto_path=${c.join(e,"/third_party/googleapis")}`,c.join(e,t.file)],p={...process.env,PATH:`${c.join(process.cwd(),"node_modules",".bin")};${process.env.PATH}`};console.log(`${c.join(process.cwd(),"node_modules",".bin")};${process.env.PATH}`),H(n.join(" "),{stdio:"inherit",env:p}),f.rmSync(c.join(o,"google"),{recursive:!0,force:!0}),f.rmSync(c.join(o,"common.ts"),{force:!0})}async function S(t){if(!b.existsSync(R.resolve(process.cwd(),t.root))){console.log(`proto \u9879\u76EE\u4E0D\u5B58\u5728(${t.root})`);return}$(t),_(t)}var l=new q;l.name("proto-gen").description("proto code generator").version("1.0.0");l.command("generate").option("--file, --file <path>").option("--root, --root <path>").option("--type-output, --typeOutput <path>").option("--api-output, --apiOutput <path>").action(t=>{if(t.file===void 0){console.log("proto file \u4E0D\u80FD\u4E3A\u7A7A, \u8BF7\u8F93\u5165 --file ./account.proto");return}if(t.root===void 0){console.log("proto \u6587\u4EF6\u7684\u6839\u8DEF\u5F84\u4E0D\u80FD\u4E3A\u7A7A, \u8BF7\u8F93\u5165 --root ../protos");return}t.typeOutput===void 0&&(t.typeOutput="src/protos/type"),t.apiOutput===void 0&&(t.apiOutput="src/protos/api"),S(t)});l.parse();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ts-proto-client",
3
- "version": "1.0.3",
3
+ "version": "1.0.4",
4
4
  "type": "module",
5
5
  "description": "",
6
6
  "scripts": {