graz 0.3.7 → 0.4.0-alpha.0

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/cli.js CHANGED
@@ -1,11 +1,15 @@
1
1
  #!/usr/bin/env node
2
2
  'use strict';
3
3
 
4
- var C = require('fs/promises');
5
- var me = require('path');
4
+ var d = require('fs/promises');
5
+ var S = require('path');
6
6
  var url = require('url');
7
7
  var cosmos = require('@keplr-wallet/cosmos');
8
+ var j = require('arg');
8
9
  var cosmosDirectoryClient = require('cosmos-directory-client');
10
+ var D = require('p-map');
11
+
12
+ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
9
13
 
10
14
  function _interopNamespace(e) {
11
15
  if (e && e.__esModule) return e;
@@ -25,10 +29,12 @@ function _interopNamespace(e) {
25
29
  return Object.freeze(n);
26
30
  }
27
31
 
28
- var C__namespace = /*#__PURE__*/_interopNamespace(C);
29
- var me__namespace = /*#__PURE__*/_interopNamespace(me);
32
+ var d__namespace = /*#__PURE__*/_interopNamespace(d);
33
+ var S__namespace = /*#__PURE__*/_interopNamespace(S);
34
+ var j__default = /*#__PURE__*/_interopDefault(j);
35
+ var D__default = /*#__PURE__*/_interopDefault(D);
30
36
 
31
- var fe=Object.create;var te=Object.defineProperty;var pe=Object.getOwnPropertyDescriptor;var ue=Object.getOwnPropertyNames;var ge=Object.getPrototypeOf,he=Object.prototype.hasOwnProperty;var _e=(e,n)=>()=>(e&&(n=e(e=0)),n);var Ee=(e,n)=>()=>(n||e((n={exports:{}}).exports,n),n.exports);var be=(e,n,r,d)=>{if(n&&typeof n=="object"||typeof n=="function")for(let o of ue(n))!he.call(e,o)&&o!==r&&te(e,o,{get:()=>n[o],enumerable:!(d=pe(n,o))||d.enumerable});return e};var we=(e,n,r)=>(r=e!=null?fe(ge(e)):{},be(te(r,"default",{value:e,enumerable:true}),e));var S=(e,n,r)=>new Promise((d,o)=>{var h=i=>{try{t(r.next(i));}catch(c){o(c);}},m=i=>{try{t(r.throw(i));}catch(c){o(c);}},t=i=>i.done?d(i.value):Promise.resolve(i.value).then(h,m);t((r=r.apply(e,n)).next());});var Ne,$,T=_e(()=>{Ne=()=>typeof document=="undefined"?new URL("file:"+__filename).href:document.currentScript&&document.currentScript.src||new URL("main.js",document.baseURI).href,$=Ne();});var oe=Ee((je,ne)=>{T();var F=Symbol("arg flag"),b=class e extends Error{constructor(n,r){super(n),this.name="ArgError",this.code=r,Object.setPrototypeOf(this,e.prototype);}};function x(e,{argv:n=process.argv.slice(2),permissive:r=false,stopAtPositional:d=false}={}){if(!e)throw new b("argument specification object is required","ARG_CONFIG_NO_SPEC");let o={_:[]},h={},m={};for(let t of Object.keys(e)){if(!t)throw new b("argument key cannot be an empty string","ARG_CONFIG_EMPTY_KEY");if(t[0]!=="-")throw new b(`argument key must start with '-' but found: '${t}'`,"ARG_CONFIG_NONOPT_KEY");if(t.length===1)throw new b(`argument key must have a name; singular '-' keys are not allowed: ${t}`,"ARG_CONFIG_NONAME_KEY");if(typeof e[t]=="string"){h[t]=e[t];continue}let i=e[t],c=false;if(Array.isArray(i)&&i.length===1&&typeof i[0]=="function"){let[u]=i;i=(f,_,a=[])=>(a.push(u(f,_,a[a.length-1])),a),c=u===Boolean||u[F]===true;}else if(typeof i=="function")c=i===Boolean||i[F]===true;else throw new b(`type missing or not a function or valid array type: ${t}`,"ARG_CONFIG_VAD_TYPE");if(t[1]!=="-"&&t.length>2)throw new b(`short argument keys (with a single hyphen) must have only one character: ${t}`,"ARG_CONFIG_SHORTOPT_TOOLONG");m[t]=[i,c];}for(let t=0,i=n.length;t<i;t++){let c=n[t];if(d&&o._.length>0){o._=o._.concat(n.slice(t));break}if(c==="--"){o._=o._.concat(n.slice(t+1));break}if(c.length>1&&c[0]==="-"){let u=c[1]==="-"||c.length===2?[c]:c.slice(1).split("").map(f=>`-${f}`);for(let f=0;f<u.length;f++){let _=u[f],[a,E]=_[1]==="-"?_.split(/=(.*)/,2):[_,void 0],l=a;for(;l in h;)l=h[l];if(!(l in m))if(r){o._.push(_);continue}else throw new b(`unknown or unexpected option: ${a}`,"ARG_UNKNOWN_OPTION");let[w,s]=m[l];if(!s&&f+1<u.length)throw new b(`option requires argument (but was followed by another short argument): ${a}`,"ARG_MISSING_REQUIRED_SHORTARG");if(s)o[l]=w(true,l,o[l]);else if(E===void 0){if(n.length<t+2||n[t+1].length>1&&n[t+1][0]==="-"&&!(n[t+1].match(/^-?\d*(\.(?=\d))?\d*$/)&&(w===Number||typeof BigInt!="undefined"&&w===BigInt))){let I=a===l?"":` (alias for ${l})`;throw new b(`option requires argument: ${a}${I}`,"ARG_MISSING_REQUIRED_LONGARG")}o[l]=w(n[t+1],l,o[l]),++t;}else o[l]=w(E,l,o[l]);}}else o._.push(c);}return o}x.flag=e=>(e[F]=true,e);x.COUNT=x.flag((e,n,r)=>(r||0)+1);x.ArgError=b;ne.exports=x;});T();var de=we(oe());T();var k=class extends Error{constructor(n){super(),this.name="AbortError",this.message=n;}},re=e=>globalThis.DOMException===void 0?new k(e):new DOMException(e),se=e=>{let n=e.reason===void 0?re("This operation was aborted."):e.reason;return n instanceof Error?n:re(n)};function v(h,m){return S(this,arguments,function*(e,n,{concurrency:r=Number.POSITIVE_INFINITY,stopOnError:d=true,signal:o}={}){return new Promise((t,i)=>{if(e[Symbol.iterator]===void 0&&e[Symbol.asyncIterator]===void 0)throw new TypeError(`Expected \`input\` to be either an \`Iterable\` or \`AsyncIterable\`, got (${typeof e})`);if(typeof n!="function")throw new TypeError("Mapper function is required");if(!((Number.isSafeInteger(r)||r===Number.POSITIVE_INFINITY)&&r>=1))throw new TypeError(`Expected \`concurrency\` to be an integer from 1 and up or \`Infinity\`, got \`${r}\` (${typeof r})`);let c=[],u=[],f=new Map,_=false,a=false,E=false,l=0,w=0,s=e[Symbol.iterator]===void 0?e[Symbol.asyncIterator]():e[Symbol.iterator](),I=N=>{_=true,a=true,i(N);};o&&(o.aborted&&I(se(o)),o.addEventListener("abort",()=>{I(se(o));}));let P=()=>S(this,null,function*(){if(a)return;let N=yield s.next(),R=w;if(w++,N.done){if(E=true,l===0&&!a){if(!d&&u.length>0){I(new AggregateError(u));return}if(a=true,f.size===0){t(c);return}let y=[];for(let[A,j]of c.entries())f.get(A)!==ie&&y.push(j);t(y);}return}l++,S(this,null,function*(){try{let y=yield N.value;if(a)return;let A=yield n(y,R);A===ie&&f.set(R,A),c[R]=A,l--,yield P();}catch(y){if(d)I(y);else {u.push(y),l--;try{yield P();}catch(A){I(A);}}}});});S(this,null,function*(){for(let N=0;N<r;N++){try{yield P();}catch(R){I(R);break}if(E||_)break}});})})}var ie=Symbol("skip");var Te=me.dirname(url.fileURLToPath($)),Ce=e=>/^\d+$/.test(e),L=e=>Ce(e[0])?`_${e}`:e,ae=`Usage: graz [options]
37
+ var N=()=>typeof document>"u"?new URL("file:"+__filename).href:document.currentScript&&document.currentScript.src||new URL("main.js",document.baseURI).href,E=N();var L=S.dirname(url.fileURLToPath(E)),M=n=>/^\d+$/.test(n),h=n=>M(n[0])?`_${n}`:n,b=`Usage: graz [options]
32
38
 
33
39
  Options:
34
40
 
@@ -43,7 +49,7 @@ Generate options:
43
49
  --authz Generate only authz compatible chains
44
50
 
45
51
  https://github.com/graz-sh/graz
46
- `,g=(0, de.default)({"--generate":Boolean,"-g":"--generate","--authz":Boolean,"--best":Boolean,"--mainnet":String,"--testnet":String,"-b":"--best","-M":"--mainnet","-T":"--testnet","--help":Boolean,"-h":"--help","--endpoint":String,"-e":"--endpoint"}),Pe=()=>S(void 0,null,function*(){if(g["--help"]){console.log(ae);return}if(g["--generate"]){yield Oe();return}console.log(ae);}),Oe=()=>S(void 0,null,function*(){console.log("\u23F3 Generating chain list..."),g["--authz"]&&console.log("\u270D\uFE0F Detected authz flag, generating only compatible chains..."),g["--best"]&&console.log("\u{1F481}\u200D\u2642\uFE0F Detected best flag, setting REST and RPC endpoints to best latency..."),(g["--mainnet"]||g["--testnet"])&&console.log("\u{1F419} Detected chain filtering flag, generating only given chain paths...");let e,n;if(g["--endpoint"]){console.log("\u{1F310} Fetching chain information from specified endpoint");try{let m=yield fetch(g["--endpoint"]);if(!m.ok)throw new Error(`HTTP error! status: ${m.status}`);let t=yield m.json();e=ce(t.mainnet,g["--mainnet"]),n=ce(t.testnet,g["--testnet"]);}catch(m){console.error(`\u274C Failed to fetch chain information: ${m.message}`),process.exit(1);}}else [e,n]=yield Promise.all([le(cosmosDirectoryClient.createClient(),{filter:g["--mainnet"]}),le(cosmosDirectoryClient.createTestnetClient(),{filter:g["--testnet"]})]);let[r,d]=yield Promise.all([C__namespace.readFile(G("index.js.stub"),{encoding:"utf-8"}),C__namespace.readFile(G("index.mjs.stub"),{encoding:"utf-8"})]),o=r.replace("/* REPLACE_MAINNET_DEFS */",M(e)).replace("/* REPLACE_TESTNET_DEFS */",M(n,{testnet:true})).replace("/* REPLACE_MAINNET_CHAINS */",D(e)).replace("/* REPLACE_TESTNET_CHAINS */",D(n,{testnet:true})).replace("/* REPLACE_MAINNET_CHAINS_ARRAY */",O(e)).replace("/* REPLACE_TESTNET_CHAINS_ARRAY */",O(n,{testnet:true})).replace("/* REPLACE_MAINNET_EXPORTS */",O(e)).replace("/* REPLACE_TESTNET_EXPORTS */",O(n,{testnet:true})).replace(/"(.+)":/g,"$1:").trim(),h=d.replace("/* REPLACE_MAINNET_DEFS */",M(e,{mjs:true})).replace("/* REPLACE_TESTNET_DEFS */",M(n,{mjs:true,testnet:true})).replace("/* REPLACE_MAINNET_CHAINS */",D(e)).replace("/* REPLACE_TESTNET_CHAINS */",D(n,{testnet:true})).replace("/* REPLACE_MAINNET_CHAINS_ARRAY */",O(e)).replace("/* REPLACE_TESTNET_CHAINS_ARRAY */",O(n,{testnet:true})).replace(/"(.+)":/g,"$1:").trim();yield Promise.all([C__namespace.writeFile(G("index.js"),o,{encoding:"utf-8"}),C__namespace.writeFile(G("index.mjs"),h.replace('"../dist"','"../dist/index.mjs"'),{encoding:"utf-8"}),C__namespace.writeFile(G("index.ts"),h,{encoding:"utf-8"})]),console.log('\u2728 Generate complete! You can import `mainnetChains` and `testnetChains` from "graz/chains".\n');}),ce=(e,n)=>{if(!n)return e;let r=new Set(n.split(","));return Object.fromEntries(Object.entries(e).filter(([d])=>r.has(d)))},G=(...e)=>me__namespace.resolve(Te,"../chains",...e),D=(e,{testnet:n=false}={})=>Object.keys(e).map(r=>` ${L(r)}: ${L(r)},`).join(`
47
- `),M=(e,{mjs:n=false,testnet:r=false}={})=>Object.entries(e).map(([d,o])=>{let h=`${L(d)}`,m=JSON.stringify(o,null,2);return `${n?"export ":""}const ${h} = defineChainInfo(${m});
48
- `}).join(""),O=(e,{testnet:n=false}={})=>Object.keys(e).map(r=>` ${L(r)},`).join(`
49
- `),le=(r,...d)=>S(void 0,[r,...d],function*(e,{filter:n=""}={}){let o=n?n.split(",").map(t=>({path:t})):yield e.fetchChains().then(t=>t.chains.map(({path:i})=>({path:i}))),h=yield v(o,t=>S(void 0,null,function*(){return e.fetchChain(t.path).then(i=>i.chain)}),{concurrency:4}),m={};return h.forEach(t=>{var i,c,u,f,_;try{if(g["--authz"]&&!((i=t.params)!=null&&i.authz))return;let a=g["--best"]?t.best_apis:t.apis;if(!a||!((c=a.rest)!=null&&c[0])||!((u=a.rpc)!=null&&u[0]))throw new Error(`\u26A0\uFE0F ${t.name} has no REST/RPC endpoints, skipping codegen...`);if(!t.assets)throw new Error(`\u26A0\uFE0F ${t.name} has no assets, skipping codegen...`);let E=t.assets[0],l={coinDenom:E.denom_units[E.denom_units.length-1].denom,coinMinimalDenom:E.denom_units[0].denom,coinDecimals:E.denom_units[E.denom_units.length-1].exponent,coinGeckoId:E.coingecko_id},w=(f=t.fees)==null?void 0:f.fee_tokens.map(s=>{var P,N,R,y,A,j,z,H,Y,U,B,q,K,V,Q,X,J,W,Z,ee;return s.low_gas_price&&s.average_gas_price&&s.high_gas_price?{coinDenom:((R=(N=(P=t.assets)==null?void 0:P.find(p=>p.denom===s.denom))==null?void 0:N.denom_units.at(-1))==null?void 0:R.denom)||s.denom,coinMinimalDenom:((j=(A=(y=t.assets)==null?void 0:y.find(p=>p.denom===s.denom))==null?void 0:A.denom_units[0])==null?void 0:j.denom)||s.denom,coinDecimals:Number((H=(z=t.assets)==null?void 0:z.find(p=>p.denom===s.denom))==null?void 0:H.decimals),coinGeckoId:((U=(Y=t.assets)==null?void 0:Y.find(p=>p.denom===s.denom))==null?void 0:U.coingecko_id)||void 0,gasPriceStep:{low:Number(s.low_gas_price),average:Number(s.average_gas_price),high:Number(s.high_gas_price)}}:{coinDenom:((K=(q=(B=t.assets)==null?void 0:B.find(p=>p.denom===s.denom))==null?void 0:q.denom_units.at(-1))==null?void 0:K.denom)||s.denom,coinMinimalDenom:((X=(Q=(V=t.assets)==null?void 0:V.find(p=>p.denom===s.denom))==null?void 0:Q.denom_units[0])==null?void 0:X.denom)||s.denom,coinDecimals:Number((W=(J=t.assets)==null?void 0:J.find(p=>p.denom===s.denom))==null?void 0:W.decimals),coinGeckoId:((ee=(Z=t.assets)==null?void 0:Z.find(p=>p.denom===s.denom))==null?void 0:ee.coingecko_id)||void 0}});if(!w)throw new Error(`\u26A0\uFE0F ${t.name} has no fee currencies, skipping codegen...`);m[t.path]={chainId:t.chain_id,currencies:t.assets.map(s=>({coinDenom:s.denom_units[s.denom_units.length-1].denom,coinMinimalDenom:s.denom_units[0].denom,coinDecimals:s.denom_units[s.denom_units.length-1].exponent,coinGeckoId:s.coingecko_id})),rest:a.rest[0].address||"",rpc:a.rpc[0].address||"",bech32Config:cosmos.Bech32Address.defaultBech32Config(t.bech32_prefix),chainName:t.chain_name,feeCurrencies:w,stakeCurrency:l,bip44:{coinType:(_=t.slip44)!=null?_:0}};}catch(a){console.error(a instanceof Error?a.message:String(a));}}),m});Pe();
52
+ `,a=j__default.default({"--generate":Boolean,"-g":"--generate","--authz":Boolean,"--best":Boolean,"--mainnet":String,"--testnet":String,"-b":"--best","-M":"--mainnet","-T":"--testnet","--help":Boolean,"-h":"--help","--endpoint":String,"-e":"--endpoint"}),$=async()=>{if(a["--help"]){console.log(b);return}if(a["--generate"]){await x();return}console.log(b);},x=async()=>{console.log("\u23F3 Generating chain list..."),a["--authz"]&&console.log("\u270D\uFE0F Detected authz flag, generating only compatible chains..."),a["--best"]&&console.log("\u{1F481}\u200D\u2642\uFE0F Detected best flag, setting REST and RPC endpoints to best latency..."),(a["--mainnet"]||a["--testnet"])&&console.log("\u{1F419} Detected chain filtering flag, generating only given chain paths...");let n,o;if(a["--endpoint"]){console.log("\u{1F310} Fetching chain information from specified endpoint");try{let s=await fetch(a["--endpoint"]);if(!s.ok)throw new Error(`HTTP error! status: ${s.status}`);let c=await s.json();n=A(c.mainnet,a["--mainnet"]),o=A(c.testnet,a["--testnet"]);}catch(s){console.error(`\u274C Failed to fetch chain information: ${s.message}`),process.exit(1);}}else [n,o]=await Promise.all([C(cosmosDirectoryClient.createClient(),{filter:a["--mainnet"]}),C(cosmosDirectoryClient.createTestnetClient(),{filter:a["--testnet"]})]);let[r,m]=await Promise.all([d__namespace.readFile(f("index.js.stub"),{encoding:"utf-8"}),d__namespace.readFile(f("index.mjs.stub"),{encoding:"utf-8"})]),l=r.replace("/* REPLACE_MAINNET_DEFS */",u(n)).replace("/* REPLACE_TESTNET_DEFS */",u(o,{testnet:true})).replace("/* REPLACE_MAINNET_CHAINS */",g(n)).replace("/* REPLACE_TESTNET_CHAINS */",g(o,{testnet:true})).replace("/* REPLACE_MAINNET_CHAINS_ARRAY */",p(n)).replace("/* REPLACE_TESTNET_CHAINS_ARRAY */",p(o,{testnet:true})).replace("/* REPLACE_MAINNET_EXPORTS */",p(n)).replace("/* REPLACE_TESTNET_EXPORTS */",p(o,{testnet:true})).replace(/"(.+)":/g,"$1:").trim(),e=m.replace("/* REPLACE_MAINNET_DEFS */",u(n,{mjs:true})).replace("/* REPLACE_TESTNET_DEFS */",u(o,{mjs:true,testnet:true})).replace("/* REPLACE_MAINNET_CHAINS */",g(n)).replace("/* REPLACE_TESTNET_CHAINS */",g(o,{testnet:true})).replace("/* REPLACE_MAINNET_CHAINS_ARRAY */",p(n)).replace("/* REPLACE_TESTNET_CHAINS_ARRAY */",p(o,{testnet:true})).replace(/"(.+)":/g,"$1:").trim();await Promise.all([d__namespace.writeFile(f("index.js"),l,{encoding:"utf-8"}),d__namespace.writeFile(f("index.mjs"),e.replace('"../dist"','"../dist/index.mjs"'),{encoding:"utf-8"}),d__namespace.writeFile(f("index.ts"),e,{encoding:"utf-8"})]),console.log('\u2728 Generate complete! You can import `mainnetChains` and `testnetChains` from "graz/chains".\n');},A=(n,o)=>{if(!o)return n;let r=new Set(o.split(","));return Object.fromEntries(Object.entries(n).filter(([m])=>r.has(m)))},f=(...n)=>S__namespace.resolve(L,"../chains",...n),g=(n,{testnet:o=false}={})=>Object.keys(n).map(r=>` ${h(r)}: ${h(r)},`).join(`
53
+ `),u=(n,{mjs:o=false,testnet:r=false}={})=>Object.entries(n).map(([m,l])=>{let e=`${h(m)}`,s=JSON.stringify(l,null,2);return `${o?"export ":""}const ${e} = defineChainInfo(${s});
54
+ `}).join(""),p=(n,{testnet:o=false}={})=>Object.keys(n).map(r=>` ${h(r)},`).join(`
55
+ `),C=async(n,{filter:o=""}={})=>{let r=o?o.split(",").map(e=>({path:e})):await n.fetchChains().then(e=>e.chains.map(({path:s})=>({path:s}))),m=await D__default.default(r,async e=>n.fetchChain(e.path).then(s=>s.chain),{concurrency:4}),l={};return m.forEach(e=>{try{if(a["--authz"]&&!e.params?.authz)return;let s=a["--best"]?e.best_apis:e.apis;if(!s||!s.rest?.[0]||!s.rpc?.[0])throw new Error(`\u26A0\uFE0F ${e.name} has no REST/RPC endpoints, skipping codegen...`);if(!e.assets)throw new Error(`\u26A0\uFE0F ${e.name} has no assets, skipping codegen...`);let c=e.assets[0],T={coinDenom:c.denom_units[c.denom_units.length-1].denom,coinMinimalDenom:c.denom_units[0].denom,coinDecimals:c.denom_units[c.denom_units.length-1].exponent,coinGeckoId:c.coingecko_id},_=e.fees?.fee_tokens.map(t=>t.low_gas_price&&t.average_gas_price&&t.high_gas_price?{coinDenom:e.assets?.find(i=>i.denom===t.denom)?.denom_units.at(-1)?.denom||t.denom,coinMinimalDenom:e.assets?.find(i=>i.denom===t.denom)?.denom_units[0]?.denom||t.denom,coinDecimals:Number(e.assets?.find(i=>i.denom===t.denom)?.decimals),coinGeckoId:e.assets?.find(i=>i.denom===t.denom)?.coingecko_id||void 0,gasPriceStep:{low:Number(t.low_gas_price),average:Number(t.average_gas_price),high:Number(t.high_gas_price)}}:{coinDenom:e.assets?.find(i=>i.denom===t.denom)?.denom_units.at(-1)?.denom||t.denom,coinMinimalDenom:e.assets?.find(i=>i.denom===t.denom)?.denom_units[0]?.denom||t.denom,coinDecimals:Number(e.assets?.find(i=>i.denom===t.denom)?.decimals),coinGeckoId:e.assets?.find(i=>i.denom===t.denom)?.coingecko_id||void 0});if(!_)throw new Error(`\u26A0\uFE0F ${e.name} has no fee currencies, skipping codegen...`);l[e.path]={chainId:e.chain_id,currencies:e.assets.map(t=>({coinDenom:t.denom_units[t.denom_units.length-1].denom,coinMinimalDenom:t.denom_units[0].denom,coinDecimals:t.denom_units[t.denom_units.length-1].exponent,coinGeckoId:t.coingecko_id})),rest:s.rest[0].address||"",rpc:s.rpc[0].address||"",bech32Config:cosmos.Bech32Address.defaultBech32Config(e.bech32_prefix),chainName:e.chain_name,feeCurrencies:_,stakeCurrency:T,bip44:{coinType:e.slip44??0}};}catch(s){console.error(s instanceof Error?s.message:String(s));}}),l};$();