polkadot-api 1.19.0 → 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 +1 -1
- package/dist/umd/ws-provider.min.js +1 -1
- package/dist/umd/ws-provider_web.min.js +1 -1
- package/package.json +10 -10
package/bin/cli.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(C,
|
|
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}),
|
|
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.
|
|
3
|
+
"version": "1.19.2",
|
|
4
4
|
"author": "Josep M Sobrepere (https://github.com/josepot)",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -204,28 +204,28 @@
|
|
|
204
204
|
},
|
|
205
205
|
"dependencies": {
|
|
206
206
|
"@rx-state/core": "^0.1.4",
|
|
207
|
-
"@polkadot-api/cli": "0.15.
|
|
208
|
-
"@polkadot-api/known-chains": "0.9.11",
|
|
207
|
+
"@polkadot-api/cli": "0.15.2",
|
|
209
208
|
"@polkadot-api/ink-contracts": "0.4.0",
|
|
210
|
-
"@polkadot-api/logs-provider": "0.0.6",
|
|
211
209
|
"@polkadot-api/json-rpc-provider": "0.0.4",
|
|
210
|
+
"@polkadot-api/known-chains": "0.9.11",
|
|
211
|
+
"@polkadot-api/logs-provider": "0.0.6",
|
|
212
212
|
"@polkadot-api/metadata-builders": "0.13.5",
|
|
213
|
-
"@polkadot-api/observable-client": "0.15.1",
|
|
214
213
|
"@polkadot-api/metadata-compatibility": "0.3.6",
|
|
214
|
+
"@polkadot-api/observable-client": "0.15.1",
|
|
215
215
|
"@polkadot-api/pjs-signer": "0.6.15",
|
|
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.9",
|
|
219
219
|
"@polkadot-api/sm-provider": "0.1.11",
|
|
220
|
-
"@polkadot-api/substrate-client": "0.4.7",
|
|
221
|
-
"@polkadot-api/substrate-bindings": "0.16.3",
|
|
222
220
|
"@polkadot-api/smoldot": "0.3.14",
|
|
221
|
+
"@polkadot-api/substrate-bindings": "0.16.3",
|
|
223
222
|
"@polkadot-api/utils": "0.2.0",
|
|
224
|
-
"@polkadot-api/ws-provider": "0.6.
|
|
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",
|
|
228
|
-
"@polkadot-api/codegen": "0.19.
|
|
228
|
+
"@polkadot-api/codegen": "0.19.1"
|
|
229
229
|
},
|
|
230
230
|
"scripts": {
|
|
231
231
|
"build-core": "tsc --noEmit && rollup -c",
|