polkadot-api 1.19.1 → 1.19.2

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/bin/cli.mjs CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
  import { getCli, ink, update, remove, generate, add } from '@polkadot-api/cli';
3
3
 
4
- var version = "1.19.1";
4
+ var version = "1.19.2";
5
5
 
6
6
  getCli({
7
7
  add,
@@ -1 +1 @@
1
- (function(C,c){typeof exports=="object"&&typeof module<"u"?c(exports):typeof define=="function"&&define.amd?define(["exports"],c):(C=typeof globalThis<"u"?globalThis:C||self,c(C.papiWsProvider={}))})(this,(function(C){"use strict";var c=(t=>(t[t.CONNECTING=0]="CONNECTING",t[t.CONNECTED=1]="CONNECTED",t[t.ERROR=2]="ERROR",t[t.CLOSE=3]="CLOSE",t))(c||{});const G=t=>JSON.stringify({jsonrpc:"2.0",...t}),M=new Set(["v1","unstable"].map(t=>`chainHead_${t}_unfollow`)),$=t=>{let e={type:1,pending:[]};const s=n=>{if(e.type===0){const o=JSON.parse(n);if("id"in o)"result"in o&&e.onGoingRequests.get(o.id)?.type===0&&e.activeChainHeads.add(o.result),e.onGoingRequests.delete(o.id);else if("params"in o){const{subscription:l,result:p}=o.params;p?.event==="stop"&&e.activeChainHeads.delete(l)}}e.type!==2&&t(n)},i=n=>{if(e.type===2)return;if(e.type===1){e.pending.push(n);return}const o=JSON.parse(n);if(M.has(o.method)&&e.activeChainHeads.delete(o.params[0]),"id"in o){const{method:l,id:p}=o,d=l.startsWith("chainHead")?l.endsWith("follow")?{type:0,msg:n}:{type:1,id:p}:{type:2,msg:n};e.onGoingRequests.set(p,d)}e.connection.send(n)};return{send:i,disconnect:()=>{e.type!==2&&(e.type===0&&e.connection.disconnect(),e={type:2})},connect:n=>{if(e.type!==1)throw new Error("Nonesense");const{pending:o}=e,l=new Map,p=new Set;e={type:0,connection:n(s,()=>{e={type:1,pending:[]},p.forEach(y=>{s(G({params:{subscription:y,result:{event:"stop",internal:!0}}}))}),p.clear();for(const y of l.values())y.type===1?s(G({id:y.id,error:{code:-32603,message:"Internal error"},internal:!0})):i(y.msg);l.clear()}),onGoingRequests:l,activeChainHeads:p},o.forEach(i)}}},k=t=>e=>{let s=$(e);const i=()=>{t().then(n=>{if(s)s.connect((o,l)=>n(o,()=>{l(),i()}));else try{n(()=>{},()=>{}).disconnect()}catch{}},()=>{s&&setTimeout(i,0)})};return i(),{send:n=>{s?.send(n)},disconnect:()=>{s?.disconnect(),s=null}}},_={};["v1","unstable"].forEach(t=>{_[`chainHead_${t}_follow`]="follow",_[`chainHead_${t}_unfollow`]="unfollow"});const q=(t,e)=>{const s=new Set,i=new Map,n=new Set;let o;return Object.assign(p=>{const{send:d,disconnect:y}=t(f=>{let u={latest:Date.now(),count:0};const m=JSON.parse(f);if("id"in m){const{id:E,result:a}=m;if(E===o&&(o=void 0,a&&!a.methods.some(r=>{const[N,,T]=r.split("_");return N==="chainHead"&&T==="follow"}))){p(f),e();return}const h=i.get(E);if(h){if(i.delete(E),s.has(a)){s.delete(a);return}n.add(a);const r=n.size+i.size;if(r>2)console.warn(`Too many chainHead follow subscriptions (${r})`);else if(m.error){console.warn(`chainHead follow failed on the ${r} sub`),e(),i.set(E,h),d(h);return}}}else{const{subscription:E,result:a}=m.params;if(a?.event==="stop"){const h=Date.now()-u.latest;u.latest+=h,u.count=h<1e3?u.count+1:1,n.has(E)?n.delete(E):s.add(E)}}p(f),u.count>2&&e()});return{send(f){const u=JSON.parse(f);u.method==="rpc_methods"&&(o=u.id);const m=_[u.method];m==="follow"?i.set(u.id,f):m==="unfollow"&&n.delete(u.params[0]),d(f)},disconnect:y}},{cleanup:()=>{s.clear(),i.clear(),n.clear()}})},I={type:c.ERROR,event:{type:"timeout"}},R=()=>{},J={onStatusChanged:R,innerEnhancer:t=>t,timeout:5e3},j=t=>t.map(e=>typeof e=="string"?[e]:[e.uri,e.protocol]),x=(t,e)=>{const{onStatusChanged:s,innerEnhancer:i,timeout:n}={...J,...e},o=j(Array.isArray(t)?t:[t]),l=e?.websocketClass??globalThis.WebSocket;if(!l)throw new Error("Missing WebSocket class");let p=0,d,y=null,f=R,u=R;const m=q(k(async()=>{const[a,h]=y||o[p++%t.length];y=null;const r=new l(a,h),N=()=>{try{r.addEventListener("error",R,{once:!0}),r.close()}catch{}};s(d={type:c.CONNECTING,uri:a,protocols:h}),await new Promise((L,v)=>{const b=()=>{S(),L()},O=w=>{S(),w==null&&N(),console.error(`Unable to connect to ${a}${h?", protocols: "+h:""}`),s(d={type:w?c.ERROR:c.CLOSE,event:w}),setTimeout(v,w?300:0,w)},H=n!==1/0?setTimeout(()=>{S(),N(),s(d=I),v(I.event)},n):void 0,S=()=>{clearTimeout(H),r.removeEventListener("error",O),r.removeEventListener("open",b)};r.addEventListener("open",b),r.addEventListener("error",O),f=()=>{O(null)}}),s(d={type:c.CONNECTED,uri:a,protocols:h});let T;const z=i(L=>(T=L,{send:v=>{r.send(v)},disconnect:()=>{f()}}));return(L,v)=>{const b=z(L),O=g=>{typeof g.data=="string"&&T(g.data)},H=g=>D=>{console.warn(`WS halt (${g})`),s(d={type:g,event:D}),v()},S=H(c.ERROR),w=H(c.CLOSE);return r.addEventListener("message",O),r.addEventListener("error",S),r.addEventListener("close",w),f=g=>{u(),f=R,r.removeEventListener("message",O),r.removeEventListener("error",S),r.removeEventListener("close",w),N(),g&&w({})},b}}),()=>{E()});u=m.cleanup,delete m.cleanup;const E=(...a)=>{d.type!==c.CLOSE&&(a.length&&(y=a),d.type!==c.ERROR&&f(!0))};return Object.assign(m,{switch:E,getStatus:()=>d})};C.WsEvent=c,C.getWsProvider=x}));
1
+ (function(C,a){typeof exports=="object"&&typeof module<"u"?a(exports):typeof define=="function"&&define.amd?define(["exports"],a):(C=typeof globalThis<"u"?globalThis:C||self,a(C.papiWsProvider={}))})(this,(function(C){"use strict";var a=(t=>(t[t.CONNECTING=0]="CONNECTING",t[t.CONNECTED=1]="CONNECTED",t[t.ERROR=2]="ERROR",t[t.CLOSE=3]="CLOSE",t))(a||{});const G=t=>JSON.stringify({jsonrpc:"2.0",...t}),$=new Set(["v1","unstable"].map(t=>`chainHead_${t}_unfollow`)),k=t=>{let e={type:1,pending:[]};const s=n=>{if(e.type===0){const o=JSON.parse(n);if("id"in o)"result"in o&&e.onGoingRequests.get(o.id)?.type===0&&e.activeChainHeads.add(o.result),e.onGoingRequests.delete(o.id);else if("params"in o){const{subscription:r,result:y}=o.params;y?.event==="stop"&&e.activeChainHeads.delete(r)}}e.type!==2&&t(n)},c=n=>{if(e.type===2)return;if(e.type===1){e.pending.push(n);return}const o=JSON.parse(n);if($.has(o.method)&&e.activeChainHeads.delete(o.params[0]),"id"in o){const{method:r,id:y}=o,d=r.startsWith("chainHead")?r.endsWith("follow")?{type:0,msg:n}:{type:1,id:y}:{type:2,msg:n};e.onGoingRequests.set(y,d)}e.connection.send(n)};return{send:c,disconnect:()=>{e.type!==2&&(e.type===0&&e.connection.disconnect(),e={type:2})},connect:n=>{if(e.type!==1)throw new Error("Nonesense");const{pending:o}=e,r=new Map,y=new Set;e={type:0,connection:n(s,()=>{e={type:1,pending:[]},y.forEach(f=>{s(G({params:{subscription:f,result:{event:"stop",internal:!0}}}))}),y.clear();for(const f of r.values())f.type===1?s(G({id:f.id,error:{code:-32603,message:"Internal error"},internal:!0})):c(f.msg);r.clear()}),onGoingRequests:r,activeChainHeads:y},o.forEach(c)}}},q=t=>e=>{let s=k(e);const c=()=>{t().then(n=>{if(s)s.connect((o,r)=>n(o,()=>{r(),c()}));else try{n(()=>{},()=>{}).disconnect()}catch{}},()=>{s&&setTimeout(c,0)})};return c(),{send:n=>{s?.send(n)},disconnect:()=>{s?.disconnect(),s=null}}},_={};["v1","unstable"].forEach(t=>{_[`chainHead_${t}_follow`]="follow",_[`chainHead_${t}_unfollow`]="unfollow"});const I=()=>({latest:Date.now(),count:0}),J=(t,e)=>{const s=new Set,c=new Map,n=new Set;let o,r=I();return Object.assign(d=>{const{send:f,disconnect:w}=t(m=>{const u=JSON.parse(m);if("id"in u){const{id:p,result:l}=u;if(p===o&&(o=void 0,l&&!l.methods.some(i=>{const[N,,b]=i.split("_");return N==="chainHead"&&b==="follow"}))){d(m),e();return}const h=c.get(p);if(h){if(c.delete(p),s.has(l)){s.delete(l);return}n.add(l);const i=n.size+c.size;if(i>2)console.warn(`Too many chainHead follow subscriptions (${i})`);else if(u.error){console.warn(`chainHead follow failed on the ${i} sub`),e(),c.set(p,h),f(h);return}}}else{const{subscription:p,result:l}=u.params;if(l?.event==="stop"){const h=Date.now()-r.latest;r.latest+=h,r.count=h<1e3?r.count+1:1,n.has(p)?n.delete(p):s.add(p)}}d(m),r.count>2&&(r=I(),e())});return{send(m){const u=JSON.parse(m);u.method==="rpc_methods"&&(o=u.id);const p=_[u.method];p==="follow"?c.set(u.id,m):p==="unfollow"&&n.delete(u.params[0]),f(m)},disconnect:w}},{cleanup:()=>{s.clear(),c.clear(),n.clear()}})},M={type:a.ERROR,event:{type:"timeout"}},R=()=>{},j={onStatusChanged:R,innerEnhancer:t=>t,timeout:5e3},x=t=>t.map(e=>typeof e=="string"?[e]:[e.uri,e.protocol]),z=(t,e)=>{const{onStatusChanged:s,innerEnhancer:c,timeout:n}={...j,...e},o=x(Array.isArray(t)?t:[t]),r=e?.websocketClass??globalThis.WebSocket;if(!r)throw new Error("Missing WebSocket class");let y=0,d,f=null,w=R,m=R;const u=J(q(async()=>{const[l,h]=f||o[y++%t.length];f=null;const i=new r(l,h),N=()=>{try{i.addEventListener("error",R,{once:!0}),i.close()}catch{}};s(d={type:a.CONNECTING,uri:l,protocols:h}),await new Promise((L,v)=>{const T=()=>{S(),L()},O=E=>{S(),E==null&&N(),console.error(`Unable to connect to ${l}${h?", protocols: "+h:""}`),s(d={type:E?a.ERROR:a.CLOSE,event:E}),setTimeout(v,E?300:0,E)},H=n!==1/0?setTimeout(()=>{S(),N(),s(d=M),v(M.event)},n):void 0,S=()=>{clearTimeout(H),i.removeEventListener("error",O),i.removeEventListener("open",T)};i.addEventListener("open",T),i.addEventListener("error",O),w=()=>{O(null)}}),s(d={type:a.CONNECTED,uri:l,protocols:h});let b;const D=c(L=>(b=L,{send:v=>{i.send(v)},disconnect:()=>{w()}}));return(L,v)=>{const T=D(L),O=g=>{typeof g.data=="string"&&b(g.data)},H=g=>P=>{console.warn(`WS halt (${g})`),s(d={type:g,event:P}),v()},S=H(a.ERROR),E=H(a.CLOSE);return i.addEventListener("message",O),i.addEventListener("error",S),i.addEventListener("close",E),w=g=>{m(),w=R,i.removeEventListener("message",O),i.removeEventListener("error",S),i.removeEventListener("close",E),N(),g&&E({}),T.disconnect()},T}}),()=>{p()});m=u.cleanup,delete u.cleanup;const p=(...l)=>{d.type!==a.CLOSE&&(l.length&&(f=l),d.type!==a.ERROR&&w(!0))};return Object.assign(u,{switch:p,getStatus:()=>d})};C.WsEvent=a,C.getWsProvider=z}));
@@ -1 +1 @@
1
- (function(C,v){typeof exports=="object"&&typeof module<"u"?v(exports):typeof define=="function"&&define.amd?define(["exports"],v):(C=typeof globalThis<"u"?globalThis:C||self,v(C.papiWsProviderWeb={}))})(this,(function(C){"use strict";const v=t=>JSON.stringify({jsonrpc:"2.0",...t}),M=new Set(["v1","unstable"].map(t=>`chainHead_${t}_unfollow`)),W=t=>{let e={type:1,pending:[]};const s=o=>{if(e.type===0){const n=JSON.parse(o);if("id"in n)"result"in n&&e.onGoingRequests.get(n.id)?.type===0&&e.activeChainHeads.add(n.result),e.onGoingRequests.delete(n.id);else if("params"in n){const{subscription:r,result:c}=n.params;c?.event==="stop"&&e.activeChainHeads.delete(r)}}e.type!==2&&t(o)},i=o=>{if(e.type===2)return;if(e.type===1){e.pending.push(o);return}const n=JSON.parse(o);if(M.has(n.method)&&e.activeChainHeads.delete(n.params[0]),"id"in n){const{method:r,id:c}=n,d=r.startsWith("chainHead")?r.endsWith("follow")?{type:0,msg:o}:{type:1,id:c}:{type:2,msg:o};e.onGoingRequests.set(c,d)}e.connection.send(o)};return{send:i,disconnect:()=>{e.type!==2&&(e.type===0&&e.connection.disconnect(),e={type:2})},connect:o=>{if(e.type!==1)throw new Error("Nonesense");const{pending:n}=e,r=new Map,c=new Set;e={type:0,connection:o(s,()=>{e={type:1,pending:[]},c.forEach(y=>{s(v({params:{subscription:y,result:{event:"stop",internal:!0}}}))}),c.clear();for(const y of r.values())y.type===1?s(v({id:y.id,error:{code:-32603,message:"Internal error"},internal:!0})):i(y.msg);r.clear()}),onGoingRequests:r,activeChainHeads:c},n.forEach(i)}}},A=t=>e=>{let s=W(e);const i=()=>{t().then(o=>{if(s)s.connect((n,r)=>o(n,()=>{r(),i()}));else try{o(()=>{},()=>{}).disconnect()}catch{}},()=>{s&&setTimeout(i,0)})};return i(),{send:o=>{s?.send(o)},disconnect:()=>{s?.disconnect(),s=null}}};var h=(t=>(t[t.CONNECTING=0]="CONNECTING",t[t.CONNECTED=1]="CONNECTED",t[t.ERROR=2]="ERROR",t[t.CLOSE=3]="CLOSE",t))(h||{});const $={};["v1","unstable"].forEach(t=>{$[`chainHead_${t}_follow`]="follow",$[`chainHead_${t}_unfollow`]="unfollow"});const P=(t,e)=>{const s=new Set,i=new Map,o=new Set;let n;return Object.assign(c=>{const{send:d,disconnect:y}=t(p=>{let u={latest:Date.now(),count:0};const m=JSON.parse(p);if("id"in m){const{id:E,result:l}=m;if(E===n&&(n=void 0,l&&!l.methods.some(a=>{const[L,,T]=a.split("_");return L==="chainHead"&&T==="follow"}))){c(p),e();return}const f=i.get(E);if(f){if(i.delete(E),s.has(l)){s.delete(l);return}o.add(l);const a=o.size+i.size;if(a>2)console.warn(`Too many chainHead follow subscriptions (${a})`);else if(m.error){console.warn(`chainHead follow failed on the ${a} sub`),e(),i.set(E,f),d(f);return}}}else{const{subscription:E,result:l}=m.params;if(l?.event==="stop"){const f=Date.now()-u.latest;u.latest+=f,u.count=f<1e3?u.count+1:1,o.has(E)?o.delete(E):s.add(E)}}c(p),u.count>2&&e()});return{send(p){const u=JSON.parse(p);u.method==="rpc_methods"&&(n=u.id);const m=$[u.method];m==="follow"?i.set(u.id,p):m==="unfollow"&&o.delete(u.params[0]),d(p)},disconnect:y}},{cleanup:()=>{s.clear(),i.clear(),o.clear()}})},G={type:h.ERROR,event:{type:"timeout"}},S=()=>{},I={onStatusChanged:S,innerEnhancer:t=>t,timeout:5e3},k=t=>t.map(e=>typeof e=="string"?[e]:[e.uri,e.protocol]),j=(t,e)=>{const{onStatusChanged:s,innerEnhancer:i,timeout:o}={...I,...e},n=k(Array.isArray(t)?t:[t]),r=e?.websocketClass??globalThis.WebSocket;if(!r)throw new Error("Missing WebSocket class");let c=0,d,y=null,p=S,u=S;const m=P(A(async()=>{const[l,f]=y||n[c++%t.length];y=null;const a=new r(l,f),L=()=>{try{a.addEventListener("error",S,{once:!0}),a.close()}catch{}};s(d={type:h.CONNECTING,uri:l,protocols:f}),await new Promise((b,O)=>{const H=()=>{N(),b()},R=g=>{N(),g==null&&L(),console.error(`Unable to connect to ${l}${f?", protocols: "+f:""}`),s(d={type:g?h.ERROR:h.CLOSE,event:g}),setTimeout(O,g?300:0,g)},_=o!==1/0?setTimeout(()=>{N(),L(),s(d=G),O(G.event)},o):void 0,N=()=>{clearTimeout(_),a.removeEventListener("error",R),a.removeEventListener("open",H)};a.addEventListener("open",H),a.addEventListener("error",R),p=()=>{R(null)}}),s(d={type:h.CONNECTED,uri:l,protocols:f});let T;const J=i(b=>(T=b,{send:O=>{a.send(O)},disconnect:()=>{p()}}));return(b,O)=>{const H=J(b),R=w=>{typeof w.data=="string"&&T(w.data)},_=w=>z=>{console.warn(`WS halt (${w})`),s(d={type:w,event:z}),O()},N=_(h.ERROR),g=_(h.CLOSE);return a.addEventListener("message",R),a.addEventListener("error",N),a.addEventListener("close",g),p=w=>{u(),p=S,a.removeEventListener("message",R),a.removeEventListener("error",N),a.removeEventListener("close",g),L(),w&&g({})},H}}),()=>{E()});u=m.cleanup,delete m.cleanup;const E=(...l)=>{d.type!==h.CLOSE&&(l.length&&(y=l),d.type!==h.ERROR&&p(!0))};return Object.assign(m,{switch:E,getStatus:()=>d})},q=(t=>(...e)=>{let s=[],{timeout:i,innerEnhancer:o,onStatusChanged:n}=I;const[r]=e;return e.length===1&&typeof r=="object"&&!Array.isArray(r)?(s=k(r.endpoints),n=r.onStatusChanged??S,i=r.timeout??i,o=r.innerEnhancer??(c=>c)):(typeof e[1]=="function"&&(n=e[1]),Array.isArray(r)?s=k(r):(s=[[r]],e[1]&&e[1]!==n&&(s[0][1]=e[1]),e[2]&&(n=e[2]))),j(s.map(c=>c.length===1?c[0]:{uri:c[0],protocol:c[1]}),{websocketClass:t,onStatusChanged:n,timeout:i,innerEnhancer:o})})(WebSocket);C.WsEvent=h,C.getWsProvider=q}));
1
+ (function(C,v){typeof exports=="object"&&typeof module<"u"?v(exports):typeof define=="function"&&define.amd?define(["exports"],v):(C=typeof globalThis<"u"?globalThis:C||self,v(C.papiWsProviderWeb={}))})(this,(function(C){"use strict";const v=t=>JSON.stringify({jsonrpc:"2.0",...t}),W=new Set(["v1","unstable"].map(t=>`chainHead_${t}_unfollow`)),A=t=>{let e={type:1,pending:[]};const r=s=>{if(e.type===0){const o=JSON.parse(s);if("id"in o)"result"in o&&e.onGoingRequests.get(o.id)?.type===0&&e.activeChainHeads.add(o.result),e.onGoingRequests.delete(o.id);else if("params"in o){const{subscription:n,result:a}=o.params;a?.event==="stop"&&e.activeChainHeads.delete(n)}}e.type!==2&&t(s)},i=s=>{if(e.type===2)return;if(e.type===1){e.pending.push(s);return}const o=JSON.parse(s);if(W.has(o.method)&&e.activeChainHeads.delete(o.params[0]),"id"in o){const{method:n,id:a}=o,d=n.startsWith("chainHead")?n.endsWith("follow")?{type:0,msg:s}:{type:1,id:a}:{type:2,msg:s};e.onGoingRequests.set(a,d)}e.connection.send(s)};return{send:i,disconnect:()=>{e.type!==2&&(e.type===0&&e.connection.disconnect(),e={type:2})},connect:s=>{if(e.type!==1)throw new Error("Nonesense");const{pending:o}=e,n=new Map,a=new Set;e={type:0,connection:s(r,()=>{e={type:1,pending:[]},a.forEach(f=>{r(v({params:{subscription:f,result:{event:"stop",internal:!0}}}))}),a.clear();for(const f of n.values())f.type===1?r(v({id:f.id,error:{code:-32603,message:"Internal error"},internal:!0})):i(f.msg);n.clear()}),onGoingRequests:n,activeChainHeads:a},o.forEach(i)}}},P=t=>e=>{let r=A(e);const i=()=>{t().then(s=>{if(r)r.connect((o,n)=>s(o,()=>{n(),i()}));else try{s(()=>{},()=>{}).disconnect()}catch{}},()=>{r&&setTimeout(i,0)})};return i(),{send:s=>{r?.send(s)},disconnect:()=>{r?.disconnect(),r=null}}};var y=(t=>(t[t.CONNECTING=0]="CONNECTING",t[t.CONNECTED=1]="CONNECTED",t[t.ERROR=2]="ERROR",t[t.CLOSE=3]="CLOSE",t))(y||{});const $={};["v1","unstable"].forEach(t=>{$[`chainHead_${t}_follow`]="follow",$[`chainHead_${t}_unfollow`]="unfollow"});const G=()=>({latest:Date.now(),count:0}),j=(t,e)=>{const r=new Set,i=new Map,s=new Set;let o,n=G();return Object.assign(d=>{const{send:f,disconnect:g}=t(m=>{const u=JSON.parse(m);if("id"in u){const{id:p,result:l}=u;if(p===o&&(o=void 0,l&&!l.methods.some(c=>{const[L,,H]=c.split("_");return L==="chainHead"&&H==="follow"}))){d(m),e();return}const h=i.get(p);if(h){if(i.delete(p),r.has(l)){r.delete(l);return}s.add(l);const c=s.size+i.size;if(c>2)console.warn(`Too many chainHead follow subscriptions (${c})`);else if(u.error){console.warn(`chainHead follow failed on the ${c} sub`),e(),i.set(p,h),f(h);return}}}else{const{subscription:p,result:l}=u.params;if(l?.event==="stop"){const h=Date.now()-n.latest;n.latest+=h,n.count=h<1e3?n.count+1:1,s.has(p)?s.delete(p):r.add(p)}}d(m),n.count>2&&(n=G(),e())});return{send(m){const u=JSON.parse(m);u.method==="rpc_methods"&&(o=u.id);const p=$[u.method];p==="follow"?i.set(u.id,m):p==="unfollow"&&s.delete(u.params[0]),f(m)},disconnect:g}},{cleanup:()=>{r.clear(),i.clear(),s.clear()}})},I={type:y.ERROR,event:{type:"timeout"}},S=()=>{},M={onStatusChanged:S,innerEnhancer:t=>t,timeout:5e3},k=t=>t.map(e=>typeof e=="string"?[e]:[e.uri,e.protocol]),q=(t,e)=>{const{onStatusChanged:r,innerEnhancer:i,timeout:s}={...M,...e},o=k(Array.isArray(t)?t:[t]),n=e?.websocketClass??globalThis.WebSocket;if(!n)throw new Error("Missing WebSocket class");let a=0,d,f=null,g=S,m=S;const u=j(P(async()=>{const[l,h]=f||o[a++%t.length];f=null;const c=new n(l,h),L=()=>{try{c.addEventListener("error",S,{once:!0}),c.close()}catch{}};r(d={type:y.CONNECTING,uri:l,protocols:h}),await new Promise((b,O)=>{const T=()=>{N(),b()},R=E=>{N(),E==null&&L(),console.error(`Unable to connect to ${l}${h?", protocols: "+h:""}`),r(d={type:E?y.ERROR:y.CLOSE,event:E}),setTimeout(O,E?300:0,E)},_=s!==1/0?setTimeout(()=>{N(),L(),r(d=I),O(I.event)},s):void 0,N=()=>{clearTimeout(_),c.removeEventListener("error",R),c.removeEventListener("open",T)};c.addEventListener("open",T),c.addEventListener("error",R),g=()=>{R(null)}}),r(d={type:y.CONNECTED,uri:l,protocols:h});let H;const z=i(b=>(H=b,{send:O=>{c.send(O)},disconnect:()=>{g()}}));return(b,O)=>{const T=z(b),R=w=>{typeof w.data=="string"&&H(w.data)},_=w=>D=>{console.warn(`WS halt (${w})`),r(d={type:w,event:D}),O()},N=_(y.ERROR),E=_(y.CLOSE);return c.addEventListener("message",R),c.addEventListener("error",N),c.addEventListener("close",E),g=w=>{m(),g=S,c.removeEventListener("message",R),c.removeEventListener("error",N),c.removeEventListener("close",E),L(),w&&E({}),T.disconnect()},T}}),()=>{p()});m=u.cleanup,delete u.cleanup;const p=(...l)=>{d.type!==y.CLOSE&&(l.length&&(f=l),d.type!==y.ERROR&&g(!0))};return Object.assign(u,{switch:p,getStatus:()=>d})},J=(t=>(...e)=>{let r=[],{timeout:i,innerEnhancer:s,onStatusChanged:o}=M;const[n]=e;return e.length===1&&typeof n=="object"&&!Array.isArray(n)?(r=k(n.endpoints),o=n.onStatusChanged??S,i=n.timeout??i,s=n.innerEnhancer??(a=>a)):(typeof e[1]=="function"&&(o=e[1]),Array.isArray(n)?r=k(n):(r=[[n]],e[1]&&e[1]!==o&&(r[0][1]=e[1]),e[2]&&(o=e[2]))),q(r.map(a=>a.length===1?a[0]:{uri:a[0],protocol:a[1]}),{websocketClass:t,onStatusChanged:o,timeout:i,innerEnhancer:s})})(WebSocket);C.WsEvent=y,C.getWsProvider=J}));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "polkadot-api",
3
- "version": "1.19.1",
3
+ "version": "1.19.2",
4
4
  "author": "Josep M Sobrepere (https://github.com/josepot)",
5
5
  "repository": {
6
6
  "type": "git",
@@ -204,24 +204,24 @@
204
204
  },
205
205
  "dependencies": {
206
206
  "@rx-state/core": "^0.1.4",
207
- "@polkadot-api/cli": "0.15.1",
208
- "@polkadot-api/json-rpc-provider": "0.0.4",
207
+ "@polkadot-api/cli": "0.15.2",
209
208
  "@polkadot-api/ink-contracts": "0.4.0",
209
+ "@polkadot-api/json-rpc-provider": "0.0.4",
210
210
  "@polkadot-api/known-chains": "0.9.11",
211
211
  "@polkadot-api/logs-provider": "0.0.6",
212
212
  "@polkadot-api/metadata-builders": "0.13.5",
213
213
  "@polkadot-api/metadata-compatibility": "0.3.6",
214
- "@polkadot-api/pjs-signer": "0.6.15",
215
214
  "@polkadot-api/observable-client": "0.15.1",
215
+ "@polkadot-api/pjs-signer": "0.6.15",
216
216
  "@polkadot-api/polkadot-signer": "0.1.6",
217
+ "@polkadot-api/polkadot-sdk-compat": "2.3.3",
217
218
  "@polkadot-api/signer": "0.2.9",
218
219
  "@polkadot-api/sm-provider": "0.1.11",
219
- "@polkadot-api/polkadot-sdk-compat": "2.3.3",
220
+ "@polkadot-api/smoldot": "0.3.14",
220
221
  "@polkadot-api/substrate-bindings": "0.16.3",
221
- "@polkadot-api/substrate-client": "0.4.7",
222
222
  "@polkadot-api/utils": "0.2.0",
223
- "@polkadot-api/ws-provider": "0.6.1",
224
- "@polkadot-api/smoldot": "0.3.14"
223
+ "@polkadot-api/ws-provider": "0.6.2",
224
+ "@polkadot-api/substrate-client": "0.4.7"
225
225
  },
226
226
  "devDependencies": {
227
227
  "rxjs": "^7.8.2",