polkadot-api 1.20.4 → 1.20.5

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.4";
4
+ var version = "1.20.5";
5
5
 
6
6
  getCli({
7
7
  add,
@@ -1 +1 @@
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
+ (function(S,m){typeof exports=="object"&&typeof module<"u"?m(exports):typeof define=="function"&&define.amd?define(["exports"],m):(S=typeof globalThis<"u"?globalThis:S||self,m(S.papiWsProvider={}))})(this,(function(S){"use strict";var m=(n=>(n[n.CONNECTING=0]="CONNECTING",n[n.CONNECTED=1]="CONNECTED",n[n.ERROR=2]="ERROR",n[n.CLOSE=3]="CLOSE",n))(m||{});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=r=>{let i=!0;if(e.type===0){const o=JSON.parse(r);if("id"in o){const{id:a}=o;if(e.pendingBroadcasts.has(a)){const c=e.pendingBroadcasts.get(a),s=o.result;e.pendingBroadcasts.delete(a),e.activeBroadcasts.get(c)?e.activeBroadcasts.get(c).upToken=s:e.connection.send(T({id:M(),method:"transaction_v1_stop",params:[s]}));return}i=e.onGoingRequests.has(a),"result"in o&&e.onGoingRequests.get(a)?.type===0&&e.activeChainHeads.add(o.result),e.onGoingRequests.delete(o.id)}else if("params"in o){const{subscription:a,result:c}=o.params;c?.event==="stop"&&e.activeChainHeads.delete(a)}}i&&e.type!==2&&n(r)},h=r=>{if(e.type===2)return;const i=JSON.parse(r);if("id"in i){const{method:o,id:a,params:c}=i,[s,,l]=o.split("_");if(s==="transaction"){if(l==="stop"){const[t]=c,u=e.activeBroadcasts.get(t);e.activeBroadcasts.delete(t),n(T({id:a,result:null})),e.type===0&&u&&u.upToken&&e.connection.send(T({id:a,method:o,params:[u.upToken]}));return}if(l==="broadcast"){const t=I();e.activeBroadcasts.set(t,{tx:c[0],synToken:t}),e.type===0&&(e.pendingBroadcasts.set(a,t),e.connection.send(r)),n(T({id:a,result:t}));return}}}if(e.type===1){e.pending.push(r);return}if(i.method==="chainHead_v1_unfollow"&&e.activeChainHeads.delete(i.params[0]),"id"in i){const{method:o,id:a}=i,[c,,s]=o.split("_"),l=c==="chainHead"?s==="follow"?{type:0,msg:r}:{type:1,id:a}:{type:2,msg:r};e.onGoingRequests.set(a,l)}e.connection.send(r)};return{send:h,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:i,activeBroadcasts:o}=e,a=new Map,c=new Set,s=()=>{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 a.values())t.type===1?d(T({id:t.id,error:{code:-32603,message:"Internal error"},internal:!0})):h(t.msg);a.clear()};e={type:0,connection:null,activeBroadcasts:o,pendingBroadcasts:new Map,onGoingRequests:a,activeChainHeads:c},e.connection=r(d,s),o.forEach(l=>{if(e.type===0){const t=M();e.pendingBroadcasts.set(t,l.synToken),h(T({id:t,method:"transaction_v1_broadcast",params:[l.tx]}))}}),i.forEach(h)}}},G=250,j=n=>e=>{let d=J(e),h=Date.now(),r=0,i;const o=()=>r&&2**Math.min(5,r)*G,a=()=>n().then(s=>{if(d)d.connect((l,t)=>{let u=!0;return s(l,()=>{if(u){u=!1;const p=h-Date.now();r+=p>G+o()?-r:1,h+=p,t(),c()}})});else try{s(()=>{},()=>{}).disconnect()}catch{}},c),c=()=>{i=setTimeout(a,o())};return a(),{send:s=>{d?.send(s)},disconnect:()=>{clearTimeout(i);const s=d?.disconnect||(()=>{});d=null,s()}}},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,h=new Map,r=new Set;let i,o=$();return Object.assign(c=>{const{send:s,disconnect:l}=n(t=>{const u=JSON.parse(t);if("id"in u){const{id:p,result:v}=u;if(p===i&&(i=void 0,v&&!v.methods.some(y=>{const[f,,B]=y.split("_");return f==="chainHead"&&B==="follow"}))){c(t),e();return}const g=h.get(p);if(g){if(h.delete(p),d.has(v)){d.delete(v);return}r.add(v);const y=r.size+h.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(),h.set(p,g),s(g);return}}}else{const{subscription:p,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,r.has(p)?r.delete(p):d.add(p)}}c(t),o.count>2&&(o=$(),e())});return{send(t){const u=JSON.parse(t);u.method==="rpc_methods"&&(i=u.id);const p=L[u.method];p==="follow"?h.set(u.id,t):p==="unfollow"&&r.delete(u.params[0]),s(t)},disconnect:l}},{cleanup:()=>{d.clear(),h.clear(),r.clear()}})},q={type:m.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:h,timeout:r,heartbeatTimeout:i}={...P,...e},o=W(Array.isArray(n)?n:[n]),a=e?.websocketClass??globalThis.WebSocket;if(!a)throw new Error("Missing WebSocket class");let c=0,s,l=null,t=N,u=N;const p=z(j(async()=>{const[g,y]=l||o[c++%n.length];l=null;const f=new a(g,y),B=()=>{try{f.addEventListener("error",N,{once:!0}),f.close()}catch{}};d(s={type:m.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(s={type:w?m.ERROR:m.CLOSE,event:w}),setTimeout(R,w?300:0,w)},k=r!==1/0?setTimeout(()=>{_(),B(),d(s=q),R(q.event)},r):void 0,_=()=>{clearTimeout(k),f.removeEventListener("error",E),f.removeEventListener("open",O)};f.addEventListener("open",O),f.addEventListener("error",E),t=()=>{E(null)}}),d(s={type:m.CONNECTED,uri:g,protocols:y});let x;const X=h(b=>(x=b,{send:R=>{f.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(s={type:C,event:K}),R()},A=w(m.ERROR),H=w(m.CLOSE);return f.addEventListener("ping",E),f.addEventListener("message",_),f.addEventListener("error",A),f.addEventListener("close",H),t=C=>{clearTimeout(O),u(),t=N,f.removeEventListener("ping",E),f.removeEventListener("message",_),f.removeEventListener("error",A),f.removeEventListener("close",H),B(),C&&H({}),k.disconnect()},k}}),()=>{v()});u=p.cleanup,delete p.cleanup;const v=(...g)=>{s.type!==m.CLOSE&&(g.length&&(l=g),s.type!==m.ERROR&&t(!0))};return Object.assign(p,{switch:v,getStatus:()=>s})},U=2147483647;S.WsEvent=m,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=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}));
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 c=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),a=o.result;e.pendingBroadcasts.delete(t),e.activeBroadcasts.get(i)?e.activeBroadcasts.get(i).upToken=a:e.connection.send(y({id:A(),method:"transaction_v1_stop",params:[a]}));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,[a,,u]=o.split("_");if(a==="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,,a]=o.split("_"),u=i==="chainHead"?a==="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,a=()=>{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=>{c(y({params:{subscription:n,result:{event:"stop",internal:!0}}}))}),i.clear();for(const n of t.values())n.type===1?c(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(c,a),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 c=J(e),l=Date.now(),r=0,d;const o=()=>r&&2**Math.min(5,r)*$,t=()=>s().then(a=>{if(c)c.connect((u,n)=>{let p=!0;return a(u,()=>{if(p){p=!1;const f=l-Date.now();r+=f>$+o()?-r:1,l+=f,n(),i()}})});else try{a(()=>{},()=>{}).disconnect()}catch{}},i),i=()=>{d=setTimeout(t,o())};return t(),{send:a=>{c?.send(a)},disconnect:()=>{clearTimeout(d);const a=c?.disconnect||(()=>{});c=null,a()}}};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 c=new Set,l=new Map,r=new Set;let d,o=G();return Object.assign(i=>{const{send:a,disconnect:u}=s(n=>{const p=JSON.parse(n);if("id"in p){const{id:f,result:E}=p;if(f===d&&(d=void 0,E&&!E.methods.some(v=>{const[h,,N]=v.split("_");return h==="chainHead"&&N==="follow"}))){i(n),e();return}const m=l.get(f);if(m){if(l.delete(f),c.has(E)){c.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(f,m),a(m);return}}}else{const{subscription:f,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(f)?r.delete(f):c.add(f)}}i(n),o.count>2&&(o=G(),e())});return{send(n){const p=JSON.parse(n);p.method==="rpc_methods"&&(d=p.id);const f=L[p.method];f==="follow"?l.set(p.id,n):f==="unfollow"&&r.delete(p.params[0]),a(n)},disconnect:u}},{cleanup:()=>{c.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:c,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,a,u=null,n=R,p=R;const f=z(x(async()=>{const[m,v]=u||o[i++%s.length];u=null;const h=new t(m,v),N=()=>{try{h.addEventListener("error",R,{once:!0}),h.close()}catch{}};c(a={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:""}`),c(a={type:w?g.ERROR:g.CLOSE,event:w}),setTimeout(_,w?300:0,w)},B=r!==1/0?setTimeout(()=>{b(),N(),c(a=q),_(q.event)},r):void 0,b=()=>{clearTimeout(B),h.removeEventListener("error",T),h.removeEventListener("open",C)};h.addEventListener("open",C),h.addEventListener("error",T),n=()=>{T(null)}}),c(a={type:g.CONNECTED,uri:m,protocols:v});let P;const K=l(k=>(P=k,{send:_=>{h.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})`),c(a={type:O,event:Q}),_()},j=w(g.ERROR),I=w(g.CLOSE);return h.addEventListener("ping",T),h.addEventListener("message",b),h.addEventListener("error",j),h.addEventListener("close",I),n=O=>{clearTimeout(C),p(),n=R,h.removeEventListener("ping",T),h.removeEventListener("message",b),h.removeEventListener("error",j),h.removeEventListener("close",I),N(),O&&I({}),B.disconnect()},B}}),()=>{E()});p=f.cleanup,delete f.cleanup;const E=(...m)=>{a.type!==g.CLOSE&&(m.length&&(u=m),a.type!==g.ERROR&&n(!0))};return Object.assign(f,{switch:E,getStatus:()=>a})},U=2147483647,X=(s=>(...e)=>{let c=[],{heartbeatTimeout:l,timeout:r,innerEnhancer:d,onStatusChanged:o}=W;const[t]=e;return e.length===1&&typeof t=="object"&&!Array.isArray(t)?(c=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)?c=H(t):(c=[[t]],e[1]&&e[1]!==o&&(c[0][1]=e[1]),e[2]&&(o=e[2]))),F(c.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.4",
3
+ "version": "1.20.5",
4
4
  "author": "Josep M Sobrepere (https://github.com/josepot)",
5
5
  "repository": {
6
6
  "type": "git",
@@ -204,7 +204,7 @@
204
204
  },
205
205
  "dependencies": {
206
206
  "@rx-state/core": "^0.1.4",
207
- "@polkadot-api/cli": "0.15.7",
207
+ "@polkadot-api/cli": "0.15.8",
208
208
  "@polkadot-api/ink-contracts": "0.4.3",
209
209
  "@polkadot-api/json-rpc-provider": "0.0.4",
210
210
  "@polkadot-api/known-chains": "0.9.13",
@@ -213,15 +213,15 @@
213
213
  "@polkadot-api/metadata-compatibility": "0.4.1",
214
214
  "@polkadot-api/observable-client": "0.16.1",
215
215
  "@polkadot-api/pjs-signer": "0.6.17",
216
- "@polkadot-api/polkadot-sdk-compat": "2.3.3",
217
216
  "@polkadot-api/polkadot-signer": "0.1.6",
217
+ "@polkadot-api/polkadot-sdk-compat": "2.3.3",
218
218
  "@polkadot-api/signer": "0.2.11",
219
- "@polkadot-api/sm-provider": "0.1.13",
219
+ "@polkadot-api/sm-provider": "0.1.14",
220
220
  "@polkadot-api/smoldot": "0.3.14",
221
221
  "@polkadot-api/substrate-bindings": "0.16.5",
222
222
  "@polkadot-api/substrate-client": "0.4.7",
223
223
  "@polkadot-api/utils": "0.2.0",
224
- "@polkadot-api/ws-provider": "0.7.3"
224
+ "@polkadot-api/ws-provider": "0.7.4"
225
225
  },
226
226
  "devDependencies": {
227
227
  "rxjs": "^7.8.2",