polkadot-api 1.20.2 → 1.20.3

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.20.2";
4
+ var version = "1.20.3";
5
5
 
6
6
  getCli({
7
7
  add,
@@ -1 +1 @@
1
- (function(R,h){typeof exports=="object"&&typeof module<"u"?h(exports):typeof define=="function"&&define.amd?define(["exports"],h):(R=typeof globalThis<"u"?globalThis:R||self,h(R.papiWsProvider={}))})(this,(function(R){"use strict";var h=(n=>(n[n.CONNECTING=0]="CONNECTING",n[n.CONNECTED=1]="CONNECTED",n[n.ERROR=2]="ERROR",n[n.CLOSE=3]="CLOSE",n))(h||{});const T=n=>JSON.stringify({jsonrpc:"2.0",...n});let J=0;const I=()=>`proxyOpaque${J++}`,M=()=>`___proxyInternalId__${I()}`,j=n=>{let e={type:1,activeBroadcasts:new Map,pending:[]};const a=s=>{let i=!0;if(e.type===0){const o=JSON.parse(s);if("id"in o){const{id:r}=o;if(e.pendingBroadcasts.has(r)){const d=e.pendingBroadcasts.get(r),c=o.result;e.pendingBroadcasts.delete(r),e.activeBroadcasts.get(d)?e.activeBroadcasts.get(d).upToken=c:e.connection.send(T({id:M(),method:"transaction_v1_stop",params:[c]}));return}i=e.onGoingRequests.has(r),"result"in o&&e.onGoingRequests.get(r)?.type===0&&e.activeChainHeads.add(o.result),e.onGoingRequests.delete(o.id)}else if("params"in o){const{subscription:r,result:d}=o.params;d?.event==="stop"&&e.activeChainHeads.delete(r)}}i&&e.type!==2&&n(s)},l=s=>{if(e.type===2)return;const i=JSON.parse(s);if("id"in i){const{method:o,id:r,params:d}=i,[c,,p]=o.split("_");if(c==="transaction"){if(p==="stop"){const[t]=d,u=e.activeBroadcasts.get(t);e.activeBroadcasts.delete(t),n(T({id:r,result:null})),e.type===0&&u&&u.upToken&&e.connection.send(T({id:r,method:o,params:[u.upToken]}));return}if(p==="broadcast"){const t=I();e.activeBroadcasts.set(t,{tx:d[0],synToken:t}),e.type===0&&(e.pendingBroadcasts.set(r,t),e.connection.send(s)),n(T({id:r,result:t}));return}}}if(e.type===1){e.pending.push(s);return}if(i.method==="chainHead_v1_unfollow"&&e.activeChainHeads.delete(i.params[0]),"id"in i){const{method:o,id:r}=i,[d,,c]=o.split("_"),p=d==="chainHead"?c==="follow"?{type:0,msg:s}:{type:1,id:r}:{type:2,msg:s};e.onGoingRequests.set(r,p)}e.connection.send(s)};return{send:l,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:i,activeBroadcasts:o}=e,r=new Map,d=new Set;e={type:0,connection:s(a,()=>{const p=e.type!==2?e.activeBroadcasts:new Map;p.forEach(t=>t.upToken=void 0),e={type:1,activeBroadcasts:p,pending:[]},d.forEach(t=>{a(T({params:{subscription:t,result:{event:"stop",internal:!0}}}))}),d.clear();for(const t of r.values())t.type===1?a(T({id:t.id,error:{code:-32603,message:"Internal error"},internal:!0})):l(t.msg);r.clear()}),activeBroadcasts:o,pendingBroadcasts:new Map,onGoingRequests:r,activeChainHeads:d},o.forEach(p=>{if(e.type===0){const t=M();e.pendingBroadcasts.set(t,p.synToken),l(T({id:t,method:"transaction_v1_broadcast",params:[p.tx]}))}}),i.forEach(l)}}},A=n=>e=>{let a=j(e);const l=()=>{n().then(s=>{if(a)a.connect((i,o)=>s(i,()=>{o(),l()}));else try{s(()=>{},()=>{}).disconnect()}catch{}},()=>{a&&setTimeout(l,0)})};return l(),{send:s=>{a?.send(s)},disconnect:()=>{a?.disconnect(),a=null}}},L={};["v1","unstable"].forEach(n=>{L[`chainHead_${n}_follow`]="follow",L[`chainHead_${n}_unfollow`]="unfollow"});const G=()=>({latest:Date.now(),count:0}),z=(n,e)=>{const a=new Set,l=new Map,s=new Set;let i,o=G();return Object.assign(d=>{const{send:c,disconnect:p}=n(t=>{const u=JSON.parse(t);if("id"in u){const{id:m,result:v}=u;if(m===i&&(i=void 0,v&&!v.methods.some(y=>{const[f,,b]=y.split("_");return f==="chainHead"&&b==="follow"}))){d(t),e();return}const g=l.get(m);if(g){if(l.delete(m),a.has(v)){a.delete(v);return}s.add(v);const y=s.size+l.size;if(y>2)console.warn(`Too many chainHead follow subscriptions (${y})`);else if(u.error){console.warn(`chainHead follow failed on the ${y} sub`),e(),l.set(m,g),c(g);return}}}else{const{subscription:m,result:v}=u.params;if(v?.event==="stop"){const g=Date.now()-o.latest;o.latest+=g,o.count=g<1e3?o.count+1:1,s.has(m)?s.delete(m):a.add(m)}}d(t),o.count>2&&(o=G(),e())});return{send(t){const u=JSON.parse(t);u.method==="rpc_methods"&&(i=u.id);const m=L[u.method];m==="follow"?l.set(u.id,t):m==="unfollow"&&s.delete(u.params[0]),c(t)},disconnect:p}},{cleanup:()=>{a.clear(),l.clear(),s.clear()}})},$={type:h.ERROR,event:{type:"timeout"}},N=()=>{},D={onStatusChanged:N,innerEnhancer:n=>n,timeout:5e3,heartbeatTimeout:4e4},P=n=>n.map(e=>typeof e=="string"?[e]:[e.uri,e.protocol]),F=(n,e)=>{const{onStatusChanged:a,innerEnhancer:l,timeout:s,heartbeatTimeout:i}={...D,...e},o=P(Array.isArray(n)?n:[n]),r=e?.websocketClass??globalThis.WebSocket;if(!r)throw new Error("Missing WebSocket class");let d=0,c,p=null,t=N,u=N;const m=z(A(async()=>{const[g,y]=p||o[d++%n.length];p=null;const f=new r(g,y),b=()=>{try{f.addEventListener("error",N,{once:!0}),f.close()}catch{}};a(c={type:h.CONNECTING,uri:g,protocols:y}),await new Promise((B,S)=>{const O=()=>{_(),B()},E=w=>{_(),w==null&&b(),console.error(`Unable to connect to ${g}${y?", protocols: "+y:""}`),a(c={type:w?h.ERROR:h.CLOSE,event:w}),setTimeout(S,w?300:0,w)},k=s!==1/0?setTimeout(()=>{_(),b(),a(c=$),S($.event)},s):void 0,_=()=>{clearTimeout(k),f.removeEventListener("error",E),f.removeEventListener("open",O)};f.addEventListener("open",O),f.addEventListener("error",E),t=()=>{E(null)}}),a(c={type:h.CONNECTED,uri:g,protocols:y});let q;const W=l(B=>(q=B,{send:S=>{f.send(S)},disconnect:()=>{t()}}));return(B,S)=>{let O;const E=()=>{i>U||(clearTimeout(O),O=setTimeout(()=>{console.warn("Terminate: heartbeat timeout"),t(!0)},i))};E();const k=W(B),_=C=>{E(),typeof C.data=="string"&&q(C.data)},w=C=>X=>{clearTimeout(O),console.warn(`WS halt (${C})`),a(c={type:C,event:X}),S()},x=w(h.ERROR),H=w(h.CLOSE);return f.addEventListener("ping",E),f.addEventListener("message",_),f.addEventListener("error",x),f.addEventListener("close",H),t=C=>{clearTimeout(O),u(),t=N,f.removeEventListener("ping",E),f.removeEventListener("message",_),f.removeEventListener("error",x),f.removeEventListener("close",H),b(),C&&H({}),k.disconnect()},k}}),()=>{v()});u=m.cleanup,delete m.cleanup;const v=(...g)=>{c.type!==h.CLOSE&&(g.length&&(p=g),c.type!==h.ERROR&&t(!0))};return Object.assign(m,{switch:v,getStatus:()=>c})},U=2147483647;R.WsEvent=h,R.getWsProvider=F}));
1
+ (function(S,h){typeof exports=="object"&&typeof module<"u"?h(exports):typeof define=="function"&&define.amd?define(["exports"],h):(S=typeof globalThis<"u"?globalThis:S||self,h(S.papiWsProvider={}))})(this,(function(S){"use strict";var h=(n=>(n[n.CONNECTING=0]="CONNECTING",n[n.CONNECTED=1]="CONNECTED",n[n.ERROR=2]="ERROR",n[n.CLOSE=3]="CLOSE",n))(h||{});const T=n=>JSON.stringify({jsonrpc:"2.0",...n});let D=0;const I=()=>`proxyOpaque${D++}`,M=()=>`___proxyInternalId__${I()}`,J=n=>{let e={type:1,activeBroadcasts:new Map,pending:[]};const d=s=>{let i=!0;if(e.type===0){const o=JSON.parse(s);if("id"in o){const{id:r}=o;if(e.pendingBroadcasts.has(r)){const c=e.pendingBroadcasts.get(r),a=o.result;e.pendingBroadcasts.delete(r),e.activeBroadcasts.get(c)?e.activeBroadcasts.get(c).upToken=a:e.connection.send(T({id:M(),method:"transaction_v1_stop",params:[a]}));return}i=e.onGoingRequests.has(r),"result"in o&&e.onGoingRequests.get(r)?.type===0&&e.activeChainHeads.add(o.result),e.onGoingRequests.delete(o.id)}else if("params"in o){const{subscription:r,result:c}=o.params;c?.event==="stop"&&e.activeChainHeads.delete(r)}}i&&e.type!==2&&n(s)},f=s=>{if(e.type===2)return;const i=JSON.parse(s);if("id"in i){const{method:o,id:r,params:c}=i,[a,,l]=o.split("_");if(a==="transaction"){if(l==="stop"){const[t]=c,p=e.activeBroadcasts.get(t);e.activeBroadcasts.delete(t),n(T({id:r,result:null})),e.type===0&&p&&p.upToken&&e.connection.send(T({id:r,method:o,params:[p.upToken]}));return}if(l==="broadcast"){const t=I();e.activeBroadcasts.set(t,{tx:c[0],synToken:t}),e.type===0&&(e.pendingBroadcasts.set(r,t),e.connection.send(s)),n(T({id:r,result:t}));return}}}if(e.type===1){e.pending.push(s);return}if(i.method==="chainHead_v1_unfollow"&&e.activeChainHeads.delete(i.params[0]),"id"in i){const{method:o,id:r}=i,[c,,a]=o.split("_"),l=c==="chainHead"?a==="follow"?{type:0,msg:s}:{type:1,id:r}:{type:2,msg:s};e.onGoingRequests.set(r,l)}e.connection.send(s)};return{send:f,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:i,activeBroadcasts:o}=e,r=new Map,c=new Set,a=()=>{const l=e.type!==2?e.activeBroadcasts:new Map;l.forEach(t=>t.upToken=void 0),e={type:1,activeBroadcasts:l,pending:[]},c.forEach(t=>{d(T({params:{subscription:t,result:{event:"stop",internal:!0}}}))}),c.clear();for(const t of r.values())t.type===1?d(T({id:t.id,error:{code:-32603,message:"Internal error"},internal:!0})):f(t.msg);r.clear()};e={type:0,connection:null,activeBroadcasts:o,pendingBroadcasts:new Map,onGoingRequests:r,activeChainHeads:c},e.connection=s(d,a),o.forEach(l=>{if(e.type===0){const t=M();e.pendingBroadcasts.set(t,l.synToken),f(T({id:t,method:"transaction_v1_broadcast",params:[l.tx]}))}}),i.forEach(f)}}},G=250,j=n=>e=>{let d=J(e),f=Date.now(),s=0,i;const o=()=>s&&2**Math.min(5,s)*G,r=()=>n().then(a=>{if(d)d.connect((l,t)=>a(l,()=>{const p=f-Date.now();s+=p>G+o()?-s:1,f+=p,t(),c()}));else try{a(()=>{},()=>{}).disconnect()}catch{}},c),c=()=>{i=setTimeout(r,o())};return r(),{send:a=>{d?.send(a)},disconnect:()=>{clearTimeout(i),d?.disconnect(),d=null}}},L={};["v1","unstable"].forEach(n=>{L[`chainHead_${n}_follow`]="follow",L[`chainHead_${n}_unfollow`]="unfollow"});const $=()=>({latest:Date.now(),count:0}),z=(n,e)=>{const d=new Set,f=new Map,s=new Set;let i,o=$();return Object.assign(c=>{const{send:a,disconnect:l}=n(t=>{const p=JSON.parse(t);if("id"in p){const{id:m,result:v}=p;if(m===i&&(i=void 0,v&&!v.methods.some(y=>{const[u,,B]=y.split("_");return u==="chainHead"&&B==="follow"}))){c(t),e();return}const g=f.get(m);if(g){if(f.delete(m),d.has(v)){d.delete(v);return}s.add(v);const y=s.size+f.size;if(y>2)console.warn(`Too many chainHead follow subscriptions (${y})`);else if(p.error){console.warn(`chainHead follow failed on the ${y} sub`),e(),f.set(m,g),a(g);return}}}else{const{subscription:m,result:v}=p.params;if(v?.event==="stop"){const g=Date.now()-o.latest;o.latest+=g,o.count=g<1e3?o.count+1:1,s.has(m)?s.delete(m):d.add(m)}}c(t),o.count>2&&(o=$(),e())});return{send(t){const p=JSON.parse(t);p.method==="rpc_methods"&&(i=p.id);const m=L[p.method];m==="follow"?f.set(p.id,t):m==="unfollow"&&s.delete(p.params[0]),a(t)},disconnect:l}},{cleanup:()=>{d.clear(),f.clear(),s.clear()}})},q={type:h.ERROR,event:{type:"timeout"}},N=()=>{},P={onStatusChanged:N,innerEnhancer:n=>n,timeout:5e3,heartbeatTimeout:4e4},W=n=>n.map(e=>typeof e=="string"?[e]:[e.uri,e.protocol]),F=(n,e)=>{const{onStatusChanged:d,innerEnhancer:f,timeout:s,heartbeatTimeout:i}={...P,...e},o=W(Array.isArray(n)?n:[n]),r=e?.websocketClass??globalThis.WebSocket;if(!r)throw new Error("Missing WebSocket class");let c=0,a,l=null,t=N,p=N;const m=z(j(async()=>{const[g,y]=l||o[c++%n.length];l=null;const u=new r(g,y),B=()=>{try{u.addEventListener("error",N,{once:!0}),u.close()}catch{}};d(a={type:h.CONNECTING,uri:g,protocols:y}),await new Promise((b,R)=>{const O=()=>{_(),b()},E=w=>{_(),w==null&&B(),console.error(`Unable to connect to ${g}${y?", protocols: "+y:""}`),d(a={type:w?h.ERROR:h.CLOSE,event:w}),setTimeout(R,w?300:0,w)},k=s!==1/0?setTimeout(()=>{_(),B(),d(a=q),R(q.event)},s):void 0,_=()=>{clearTimeout(k),u.removeEventListener("error",E),u.removeEventListener("open",O)};u.addEventListener("open",O),u.addEventListener("error",E),t=()=>{E(null)}}),d(a={type:h.CONNECTED,uri:g,protocols:y});let x;const X=f(b=>(x=b,{send:R=>{u.send(R)},disconnect:()=>{t()}}));return(b,R)=>{let O;const E=()=>{i>U||(clearTimeout(O),O=setTimeout(()=>{console.warn("Terminate: heartbeat timeout"),t(!0)},i))};E();const k=X(b),_=C=>{E(),typeof C.data=="string"&&x(C.data)},w=C=>K=>{clearTimeout(O),console.warn(`WS halt (${C})`),d(a={type:C,event:K}),R()},A=w(h.ERROR),H=w(h.CLOSE);return u.addEventListener("ping",E),u.addEventListener("message",_),u.addEventListener("error",A),u.addEventListener("close",H),t=C=>{clearTimeout(O),p(),t=N,u.removeEventListener("ping",E),u.removeEventListener("message",_),u.removeEventListener("error",A),u.removeEventListener("close",H),B(),C&&H({}),k.disconnect()},k}}),()=>{v()});p=m.cleanup,delete m.cleanup;const v=(...g)=>{a.type!==h.CLOSE&&(g.length&&(l=g),a.type!==h.ERROR&&t(!0))};return Object.assign(m,{switch:v,getStatus:()=>a})},U=2147483647;S.WsEvent=h,S.getWsProvider=F}));
@@ -1 +1 @@
1
- (function(S,y){typeof exports=="object"&&typeof module<"u"?y(exports):typeof define=="function"&&define.amd?define(["exports"],y):(S=typeof globalThis<"u"?globalThis:S||self,y(S.papiWsProviderWeb={}))})(this,(function(S){"use strict";const y=n=>JSON.stringify({jsonrpc:"2.0",...n});let j=0;const M=()=>`proxyOpaque${j++}`,$=()=>`___proxyInternalId__${M()}`,J=n=>{let e={type:1,activeBroadcasts:new Map,pending:[]};const i=r=>{let c=!0;if(e.type===0){const o=JSON.parse(r);if("id"in o){const{id:t}=o;if(e.pendingBroadcasts.has(t)){const a=e.pendingBroadcasts.get(t),l=o.result;e.pendingBroadcasts.delete(t),e.activeBroadcasts.get(a)?e.activeBroadcasts.get(a).upToken=l:e.connection.send(y({id:$(),method:"transaction_v1_stop",params:[l]}));return}c=e.onGoingRequests.has(t),"result"in o&&e.onGoingRequests.get(t)?.type===0&&e.activeChainHeads.add(o.result),e.onGoingRequests.delete(o.id)}else if("params"in o){const{subscription:t,result:a}=o.params;a?.event==="stop"&&e.activeChainHeads.delete(t)}}c&&e.type!==2&&n(r)},d=r=>{if(e.type===2)return;const c=JSON.parse(r);if("id"in c){const{method:o,id:t,params:a}=c,[l,,p]=o.split("_");if(l==="transaction"){if(p==="stop"){const[s]=a,u=e.activeBroadcasts.get(s);e.activeBroadcasts.delete(s),n(y({id:t,result:null})),e.type===0&&u&&u.upToken&&e.connection.send(y({id:t,method:o,params:[u.upToken]}));return}if(p==="broadcast"){const s=M();e.activeBroadcasts.set(s,{tx:a[0],synToken:s}),e.type===0&&(e.pendingBroadcasts.set(t,s),e.connection.send(r)),n(y({id:t,result:s}));return}}}if(e.type===1){e.pending.push(r);return}if(c.method==="chainHead_v1_unfollow"&&e.activeChainHeads.delete(c.params[0]),"id"in c){const{method:o,id:t}=c,[a,,l]=o.split("_"),p=a==="chainHead"?l==="follow"?{type:0,msg:r}:{type:1,id:t}:{type:2,msg:r};e.onGoingRequests.set(t,p)}e.connection.send(r)};return{send:d,disconnect:()=>{e.type!==2&&(e.type===0&&e.connection.disconnect(),e={type:2})},connect:r=>{if(e.type!==1)throw new Error("Nonesense");const{pending:c,activeBroadcasts:o}=e,t=new Map,a=new Set;e={type:0,connection:r(i,()=>{const p=e.type!==2?e.activeBroadcasts:new Map;p.forEach(s=>s.upToken=void 0),e={type:1,activeBroadcasts:p,pending:[]},a.forEach(s=>{i(y({params:{subscription:s,result:{event:"stop",internal:!0}}}))}),a.clear();for(const s of t.values())s.type===1?i(y({id:s.id,error:{code:-32603,message:"Internal error"},internal:!0})):d(s.msg);t.clear()}),activeBroadcasts:o,pendingBroadcasts:new Map,onGoingRequests:t,activeChainHeads:a},o.forEach(p=>{if(e.type===0){const s=$();e.pendingBroadcasts.set(s,p.synToken),d(y({id:s,method:"transaction_v1_broadcast",params:[p.tx]}))}}),c.forEach(d)}}},x=n=>e=>{let i=J(e);const d=()=>{n().then(r=>{if(i)i.connect((c,o)=>r(c,()=>{o(),d()}));else try{r(()=>{},()=>{}).disconnect()}catch{}},()=>{i&&setTimeout(d,0)})};return d(),{send:r=>{i?.send(r)},disconnect:()=>{i?.disconnect(),i=null}}};var g=(n=>(n[n.CONNECTING=0]="CONNECTING",n[n.CONNECTED=1]="CONNECTED",n[n.ERROR=2]="ERROR",n[n.CLOSE=3]="CLOSE",n))(g||{});const B={};["v1","unstable"].forEach(n=>{B[`chainHead_${n}_follow`]="follow",B[`chainHead_${n}_unfollow`]="unfollow"});const A=()=>({latest:Date.now(),count:0}),z=(n,e)=>{const i=new Set,d=new Map,r=new Set;let c,o=A();return Object.assign(a=>{const{send:l,disconnect:p}=n(s=>{const u=JSON.parse(s);if("id"in u){const{id:h,result:E}=u;if(h===c&&(c=void 0,E&&!E.methods.some(v=>{const[f,,N]=v.split("_");return f==="chainHead"&&N==="follow"}))){a(s),e();return}const m=d.get(h);if(m){if(d.delete(h),i.has(E)){i.delete(E);return}r.add(E);const v=r.size+d.size;if(v>2)console.warn(`Too many chainHead follow subscriptions (${v})`);else if(u.error){console.warn(`chainHead follow failed on the ${v} sub`),e(),d.set(h,m),l(m);return}}}else{const{subscription:h,result:E}=u.params;if(E?.event==="stop"){const m=Date.now()-o.latest;o.latest+=m,o.count=m<1e3?o.count+1:1,r.has(h)?r.delete(h):i.add(h)}}a(s),o.count>2&&(o=A(),e())});return{send(s){const u=JSON.parse(s);u.method==="rpc_methods"&&(c=u.id);const h=B[u.method];h==="follow"?d.set(u.id,s):h==="unfollow"&&r.delete(u.params[0]),l(s)},disconnect:p}},{cleanup:()=>{i.clear(),d.clear(),r.clear()}})},G={type:g.ERROR,event:{type:"timeout"}},R=()=>{},q={onStatusChanged:R,innerEnhancer:n=>n,timeout:5e3,heartbeatTimeout:4e4},H=n=>n.map(e=>typeof e=="string"?[e]:[e.uri,e.protocol]),D=(n,e)=>{const{onStatusChanged:i,innerEnhancer:d,timeout:r,heartbeatTimeout:c}={...q,...e},o=H(Array.isArray(n)?n:[n]),t=e?.websocketClass??globalThis.WebSocket;if(!t)throw new Error("Missing WebSocket class");let a=0,l,p=null,s=R,u=R;const h=z(x(async()=>{const[m,v]=p||o[a++%n.length];p=null;const f=new t(m,v),N=()=>{try{f.addEventListener("error",R,{once:!0}),f.close()}catch{}};i(l={type:g.CONNECTING,uri:m,protocols:v}),await new Promise((L,b)=>{const C=()=>{_(),L()},T=w=>{_(),w==null&&N(),console.error(`Unable to connect to ${m}${v?", protocols: "+v:""}`),i(l={type:w?g.ERROR:g.CLOSE,event:w}),setTimeout(b,w?300:0,w)},k=r!==1/0?setTimeout(()=>{_(),N(),i(l=G),b(G.event)},r):void 0,_=()=>{clearTimeout(k),f.removeEventListener("error",T),f.removeEventListener("open",C)};f.addEventListener("open",C),f.addEventListener("error",T),s=()=>{T(null)}}),i(l={type:g.CONNECTED,uri:m,protocols:v});let P;const X=d(L=>(P=L,{send:b=>{f.send(b)},disconnect:()=>{s()}}));return(L,b)=>{let C;const T=()=>{c>F||(clearTimeout(C),C=setTimeout(()=>{console.warn("Terminate: heartbeat timeout"),s(!0)},c))};T();const k=X(L),_=O=>{T(),typeof O.data=="string"&&P(O.data)},w=O=>K=>{clearTimeout(C),console.warn(`WS halt (${O})`),i(l={type:O,event:K}),b()},W=w(g.ERROR),I=w(g.CLOSE);return f.addEventListener("ping",T),f.addEventListener("message",_),f.addEventListener("error",W),f.addEventListener("close",I),s=O=>{clearTimeout(C),u(),s=R,f.removeEventListener("ping",T),f.removeEventListener("message",_),f.removeEventListener("error",W),f.removeEventListener("close",I),N(),O&&I({}),k.disconnect()},k}}),()=>{E()});u=h.cleanup,delete h.cleanup;const E=(...m)=>{l.type!==g.CLOSE&&(m.length&&(p=m),l.type!==g.ERROR&&s(!0))};return Object.assign(h,{switch:E,getStatus:()=>l})},F=2147483647,U=(n=>(...e)=>{let i=[],{heartbeatTimeout:d,timeout:r,innerEnhancer:c,onStatusChanged:o}=q;const[t]=e;return e.length===1&&typeof t=="object"&&!Array.isArray(t)?(i=H(t.endpoints),o=t.onStatusChanged??R,r=t.timeout??r,d=t.heartbeatTimeout??d,c=t.innerEnhancer??(a=>a)):(typeof e[1]=="function"&&(o=e[1]),Array.isArray(t)?i=H(t):(i=[[t]],e[1]&&e[1]!==o&&(i[0][1]=e[1]),e[2]&&(o=e[2]))),D(i.map(a=>a.length===1?a[0]:{uri:a[0],protocol:a[1]}),{websocketClass:n,onStatusChanged:o,timeout:r,innerEnhancer:c,heartbeatTimeout:d})})(WebSocket);S.WsEvent=g,S.getWsProvider=U}));
1
+ (function(S,y){typeof exports=="object"&&typeof module<"u"?y(exports):typeof define=="function"&&define.amd?define(["exports"],y):(S=typeof globalThis<"u"?globalThis:S||self,y(S.papiWsProviderWeb={}))})(this,(function(S){"use strict";const y=s=>JSON.stringify({jsonrpc:"2.0",...s});let D=0;const M=()=>`proxyOpaque${D++}`,A=()=>`___proxyInternalId__${M()}`,J=s=>{let e={type:1,activeBroadcasts:new Map,pending:[]};const a=r=>{let d=!0;if(e.type===0){const o=JSON.parse(r);if("id"in o){const{id:t}=o;if(e.pendingBroadcasts.has(t)){const i=e.pendingBroadcasts.get(t),c=o.result;e.pendingBroadcasts.delete(t),e.activeBroadcasts.get(i)?e.activeBroadcasts.get(i).upToken=c:e.connection.send(y({id:A(),method:"transaction_v1_stop",params:[c]}));return}d=e.onGoingRequests.has(t),"result"in o&&e.onGoingRequests.get(t)?.type===0&&e.activeChainHeads.add(o.result),e.onGoingRequests.delete(o.id)}else if("params"in o){const{subscription:t,result:i}=o.params;i?.event==="stop"&&e.activeChainHeads.delete(t)}}d&&e.type!==2&&s(r)},l=r=>{if(e.type===2)return;const d=JSON.parse(r);if("id"in d){const{method:o,id:t,params:i}=d,[c,,u]=o.split("_");if(c==="transaction"){if(u==="stop"){const[n]=i,p=e.activeBroadcasts.get(n);e.activeBroadcasts.delete(n),s(y({id:t,result:null})),e.type===0&&p&&p.upToken&&e.connection.send(y({id:t,method:o,params:[p.upToken]}));return}if(u==="broadcast"){const n=M();e.activeBroadcasts.set(n,{tx:i[0],synToken:n}),e.type===0&&(e.pendingBroadcasts.set(t,n),e.connection.send(r)),s(y({id:t,result:n}));return}}}if(e.type===1){e.pending.push(r);return}if(d.method==="chainHead_v1_unfollow"&&e.activeChainHeads.delete(d.params[0]),"id"in d){const{method:o,id:t}=d,[i,,c]=o.split("_"),u=i==="chainHead"?c==="follow"?{type:0,msg:r}:{type:1,id:t}:{type:2,msg:r};e.onGoingRequests.set(t,u)}e.connection.send(r)};return{send:l,disconnect:()=>{e.type!==2&&(e.type===0&&e.connection.disconnect(),e={type:2})},connect:r=>{if(e.type!==1)throw new Error("Nonesense");const{pending:d,activeBroadcasts:o}=e,t=new Map,i=new Set,c=()=>{const u=e.type!==2?e.activeBroadcasts:new Map;u.forEach(n=>n.upToken=void 0),e={type:1,activeBroadcasts:u,pending:[]},i.forEach(n=>{a(y({params:{subscription:n,result:{event:"stop",internal:!0}}}))}),i.clear();for(const n of t.values())n.type===1?a(y({id:n.id,error:{code:-32603,message:"Internal error"},internal:!0})):l(n.msg);t.clear()};e={type:0,connection:null,activeBroadcasts:o,pendingBroadcasts:new Map,onGoingRequests:t,activeChainHeads:i},e.connection=r(a,c),o.forEach(u=>{if(e.type===0){const n=A();e.pendingBroadcasts.set(n,u.synToken),l(y({id:n,method:"transaction_v1_broadcast",params:[u.tx]}))}}),d.forEach(l)}}},$=250,x=s=>e=>{let a=J(e),l=Date.now(),r=0,d;const o=()=>r&&2**Math.min(5,r)*$,t=()=>s().then(c=>{if(a)a.connect((u,n)=>c(u,()=>{const p=l-Date.now();r+=p>$+o()?-r:1,l+=p,n(),i()}));else try{c(()=>{},()=>{}).disconnect()}catch{}},i),i=()=>{d=setTimeout(t,o())};return t(),{send:c=>{a?.send(c)},disconnect:()=>{clearTimeout(d),a?.disconnect(),a=null}}};var g=(s=>(s[s.CONNECTING=0]="CONNECTING",s[s.CONNECTED=1]="CONNECTED",s[s.ERROR=2]="ERROR",s[s.CLOSE=3]="CLOSE",s))(g||{});const L={};["v1","unstable"].forEach(s=>{L[`chainHead_${s}_follow`]="follow",L[`chainHead_${s}_unfollow`]="unfollow"});const G=()=>({latest:Date.now(),count:0}),z=(s,e)=>{const a=new Set,l=new Map,r=new Set;let d,o=G();return Object.assign(i=>{const{send:c,disconnect:u}=s(n=>{const p=JSON.parse(n);if("id"in p){const{id:h,result:E}=p;if(h===d&&(d=void 0,E&&!E.methods.some(v=>{const[f,,N]=v.split("_");return f==="chainHead"&&N==="follow"}))){i(n),e();return}const m=l.get(h);if(m){if(l.delete(h),a.has(E)){a.delete(E);return}r.add(E);const v=r.size+l.size;if(v>2)console.warn(`Too many chainHead follow subscriptions (${v})`);else if(p.error){console.warn(`chainHead follow failed on the ${v} sub`),e(),l.set(h,m),c(m);return}}}else{const{subscription:h,result:E}=p.params;if(E?.event==="stop"){const m=Date.now()-o.latest;o.latest+=m,o.count=m<1e3?o.count+1:1,r.has(h)?r.delete(h):a.add(h)}}i(n),o.count>2&&(o=G(),e())});return{send(n){const p=JSON.parse(n);p.method==="rpc_methods"&&(d=p.id);const h=L[p.method];h==="follow"?l.set(p.id,n):h==="unfollow"&&r.delete(p.params[0]),c(n)},disconnect:u}},{cleanup:()=>{a.clear(),l.clear(),r.clear()}})},q={type:g.ERROR,event:{type:"timeout"}},R=()=>{},W={onStatusChanged:R,innerEnhancer:s=>s,timeout:5e3,heartbeatTimeout:4e4},H=s=>s.map(e=>typeof e=="string"?[e]:[e.uri,e.protocol]),F=(s,e)=>{const{onStatusChanged:a,innerEnhancer:l,timeout:r,heartbeatTimeout:d}={...W,...e},o=H(Array.isArray(s)?s:[s]),t=e?.websocketClass??globalThis.WebSocket;if(!t)throw new Error("Missing WebSocket class");let i=0,c,u=null,n=R,p=R;const h=z(x(async()=>{const[m,v]=u||o[i++%s.length];u=null;const f=new t(m,v),N=()=>{try{f.addEventListener("error",R,{once:!0}),f.close()}catch{}};a(c={type:g.CONNECTING,uri:m,protocols:v}),await new Promise((k,_)=>{const C=()=>{b(),k()},T=w=>{b(),w==null&&N(),console.error(`Unable to connect to ${m}${v?", protocols: "+v:""}`),a(c={type:w?g.ERROR:g.CLOSE,event:w}),setTimeout(_,w?300:0,w)},B=r!==1/0?setTimeout(()=>{b(),N(),a(c=q),_(q.event)},r):void 0,b=()=>{clearTimeout(B),f.removeEventListener("error",T),f.removeEventListener("open",C)};f.addEventListener("open",C),f.addEventListener("error",T),n=()=>{T(null)}}),a(c={type:g.CONNECTED,uri:m,protocols:v});let P;const K=l(k=>(P=k,{send:_=>{f.send(_)},disconnect:()=>{n()}}));return(k,_)=>{let C;const T=()=>{d>U||(clearTimeout(C),C=setTimeout(()=>{console.warn("Terminate: heartbeat timeout"),n(!0)},d))};T();const B=K(k),b=O=>{T(),typeof O.data=="string"&&P(O.data)},w=O=>Q=>{clearTimeout(C),console.warn(`WS halt (${O})`),a(c={type:O,event:Q}),_()},j=w(g.ERROR),I=w(g.CLOSE);return f.addEventListener("ping",T),f.addEventListener("message",b),f.addEventListener("error",j),f.addEventListener("close",I),n=O=>{clearTimeout(C),p(),n=R,f.removeEventListener("ping",T),f.removeEventListener("message",b),f.removeEventListener("error",j),f.removeEventListener("close",I),N(),O&&I({}),B.disconnect()},B}}),()=>{E()});p=h.cleanup,delete h.cleanup;const E=(...m)=>{c.type!==g.CLOSE&&(m.length&&(u=m),c.type!==g.ERROR&&n(!0))};return Object.assign(h,{switch:E,getStatus:()=>c})},U=2147483647,X=(s=>(...e)=>{let a=[],{heartbeatTimeout:l,timeout:r,innerEnhancer:d,onStatusChanged:o}=W;const[t]=e;return e.length===1&&typeof t=="object"&&!Array.isArray(t)?(a=H(t.endpoints),o=t.onStatusChanged??R,r=t.timeout??r,l=t.heartbeatTimeout??l,d=t.innerEnhancer??(i=>i)):(typeof e[1]=="function"&&(o=e[1]),Array.isArray(t)?a=H(t):(a=[[t]],e[1]&&e[1]!==o&&(a[0][1]=e[1]),e[2]&&(o=e[2]))),F(a.map(i=>i.length===1?i[0]:{uri:i[0],protocol:i[1]}),{websocketClass:s,onStatusChanged:o,timeout:r,innerEnhancer:d,heartbeatTimeout:l})})(WebSocket);S.WsEvent=g,S.getWsProvider=X}));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "polkadot-api",
3
- "version": "1.20.2",
3
+ "version": "1.20.3",
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/ink-contracts": "0.4.3",
207
+ "@polkadot-api/cli": "0.15.6",
208
208
  "@polkadot-api/json-rpc-provider": "0.0.4",
209
209
  "@polkadot-api/known-chains": "0.9.13",
210
- "@polkadot-api/cli": "0.15.5",
211
210
  "@polkadot-api/logs-provider": "0.0.6",
211
+ "@polkadot-api/ink-contracts": "0.4.3",
212
+ "@polkadot-api/metadata-compatibility": "0.4.0",
212
213
  "@polkadot-api/metadata-builders": "0.13.7",
214
+ "@polkadot-api/polkadot-sdk-compat": "2.3.3",
213
215
  "@polkadot-api/observable-client": "0.16.1",
214
- "@polkadot-api/metadata-compatibility": "0.4.0",
215
216
  "@polkadot-api/pjs-signer": "0.6.17",
216
- "@polkadot-api/polkadot-sdk-compat": "2.3.3",
217
217
  "@polkadot-api/polkadot-signer": "0.1.6",
218
218
  "@polkadot-api/signer": "0.2.11",
219
- "@polkadot-api/sm-provider": "0.1.12",
220
- "@polkadot-api/substrate-bindings": "0.16.5",
219
+ "@polkadot-api/sm-provider": "0.1.13",
221
220
  "@polkadot-api/smoldot": "0.3.14",
222
221
  "@polkadot-api/substrate-client": "0.4.7",
223
- "@polkadot-api/utils": "0.2.0",
224
- "@polkadot-api/ws-provider": "0.7.2"
222
+ "@polkadot-api/ws-provider": "0.7.3",
223
+ "@polkadot-api/substrate-bindings": "0.16.5",
224
+ "@polkadot-api/utils": "0.2.0"
225
225
  },
226
226
  "devDependencies": {
227
227
  "rxjs": "^7.8.2",