polkadot-api 1.7.3 → 1.7.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/dist/umd/ws-provider_web.min.js +1 -1
- package/package.json +10 -10
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(
|
|
1
|
+
(function(w,C){typeof exports=="object"&&typeof module<"u"?C(exports):typeof define=="function"&&define.amd?define(["exports"],C):(w=typeof globalThis<"u"?globalThis:w||self,C(w.papiWsProviderWeb={}))})(this,function(w){"use strict";const C=o=>JSON.stringify({jsonrpc:"2.0",...o}),I=new Set(["v1","unstable"].map(o=>`chainHead_${o}_unfollow`)),_=o=>{let e={type:1,pending:[]};const r=t=>{if(e.type===0){const n=JSON.parse(t);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:l,result:i}=n.params;i?.event==="stop"&&e.activeChainHeads.delete(l)}}e.type!==2&&o(t)},s=t=>{if(e.type===2)return;if(e.type===1){e.pending.push(t);return}const n=JSON.parse(t);if(I.has(n.method)&&e.activeChainHeads.delete(n.params[0]),"id"in n){const{method:l,id:i}=n,E=l.startsWith("chainHead")?l.endsWith("follow")?{type:0,msg:t}:{type:1,id:i}:{type:2,msg:t};e.onGoingRequests.set(i,E)}e.connection.send(t)};return{send:s,disconnect:()=>{e.type!==2&&(e.type===0&&e.connection.disconnect(),e={type:2})},connect:t=>{if(e.type!==1)throw new Error("Nonesense");const{pending:n}=e,l=new Map,i=new Set;e={type:0,connection:t(r,()=>{e={type:1,pending:[]},i.forEach(c=>{r(C({params:{subscription:c,result:{event:"stop",internal:!0}}}))}),i.clear();for(const c of l.values())c.type===1?r(C({id:c.id,error:{code:-32603,message:"Internal error"},internal:!0})):s(c.msg);l.clear()}),onGoingRequests:l,activeChainHeads:i},n.forEach(s)}}},$=o=>e=>{let r=_(e);const s=()=>{o().then(t=>{if(r)r.connect((n,l)=>t(n,()=>{l(),s()}));else try{t(()=>{},()=>{}).disconnect()}catch{}},()=>{r&&setTimeout(s,0)})};return s(),{send:t=>{r?.send(t)},disconnect:()=>{r?.disconnect(),r=null}}};var u=(o=>(o[o.CONNECTING=0]="CONNECTING",o[o.CONNECTED=1]="CONNECTED",o[o.ERROR=2]="ERROR",o[o.CLOSE=3]="CLOSE",o))(u||{});const L={};["v1","unstable"].forEach(o=>{L[`chainHead_${o}_follow`]="follow",L[`chainHead_${o}_unfollow`]="unfollow"});const M=(o,e)=>{const r=new Set,s=new Map,t=new Set;return Object.assign(l=>{const{send:i,disconnect:E}=o(c=>{const f=JSON.parse(c);if("id"in f){const{id:d,result:m}=f,h=s.get(d);if(h){if(s.delete(d),r.has(m)){r.delete(m);return}t.add(m);const y=t.size+s.size;if(y>2)console.warn(`Too many chainHead follow subscriptions (${y})`);else if(f.error){console.warn(`chainHead follow failed on the ${y} sub`),e(),s.set(d,h),i(h);return}}}else{const{subscription:d,result:m}=f.params;m?.event==="stop"&&(t.has(d)?t.delete(d):r.add(d))}l(c)});return{send(c){const f=JSON.parse(c),d=L[f.method];d==="follow"?s.set(f.id,c):d==="unfollow"&&t.delete(f.params[0]),i(c)},disconnect:E}},{cleanup:()=>{r.clear(),s.clear(),t.clear()}})},b={type:u.ERROR,event:{type:"timeout"}},g=()=>{},G=o=>o.map(e=>typeof e=="string"?[e]:[e.uri,e.protocol]),P=(o=>(...e)=>{let r=[],s=g,t=3500;const[n]=e;e.length===1&&typeof n=="object"&&!Array.isArray(n)?(r=G(n.endpoints),s=n.onStatusChanged??g,t=n.timeout??t):(typeof e[1]=="function"&&(s=e[1]),Array.isArray(n)?r=G(n):(r=[[n]],e[1]&&e[1]!==s&&(r[0][1]=e[1]),e[2]&&(s=e[2])));let l=0,i,E=null,c=g,f=g;const d=M($(async()=>{const[h,y]=E||r[l++%r.length];E=null;const p=new o(h,y),T=()=>{try{p.addEventListener("error",g,{once:!0}),p.close()}catch{}};return s(i={type:u.CONNECTING,uri:h,protocols:y}),await new Promise((H,S)=>{const R=()=>{v(),H()},O=a=>{v(),a==null&&T(),console.error(`Unable to connect to ${h}${y?", protocols: "+y:""}`),s(i={type:a?u.ERROR:u.CLOSE,event:a}),setTimeout(S,a?300:0,a)},N=t!==1/0?setTimeout(()=>{v(),T(),s(i=b),S(b.event)},t):void 0,v=()=>{clearTimeout(N),p.removeEventListener("error",O),p.removeEventListener("open",R)};p.addEventListener("open",R),p.addEventListener("error",O),c=()=>{O(null)}}),s(i={type:u.CONNECTED,uri:h,protocols:y}),(H,S)=>{const R=a=>{typeof a.data=="string"&&H(a.data)},O=a=>j=>{console.warn(`WS halt (${a})`),s(i={type:a,event:j}),S()},N=O(u.ERROR),v=O(u.CLOSE);return p.addEventListener("message",R),p.addEventListener("error",N),p.addEventListener("close",v),c=a=>{f(),c=g,p.removeEventListener("message",R),p.removeEventListener("error",N),p.removeEventListener("close",v),T(),a&&v({})},{send:a=>{p.send(a)},disconnect:c}}}),()=>{m()});f=d.cleanup,delete d.cleanup;const m=(...h)=>{i.type!==u.CLOSE&&(h.length&&(E=h),i.type!==u.ERROR&&c(!0))};return Object.assign(d,{switch:m,getStatus:()=>i})})(WebSocket);w.WsEvent=u,w.getWsProvider=P});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "polkadot-api",
|
|
3
|
-
"version": "1.7.
|
|
3
|
+
"version": "1.7.5",
|
|
4
4
|
"author": "Josep M Sobrepere (https://github.com/josepot)",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -191,28 +191,28 @@
|
|
|
191
191
|
"rxjs": ">=7.8.0"
|
|
192
192
|
},
|
|
193
193
|
"dependencies": {
|
|
194
|
-
"@polkadot-api/cli": "0.9.
|
|
195
|
-
"@polkadot-api/ink-contracts": "0.2.
|
|
196
|
-
"@polkadot-api/json-rpc-provider": "0.0.4",
|
|
197
|
-
"@polkadot-api/metadata-builders": "0.9.1",
|
|
194
|
+
"@polkadot-api/cli": "0.9.19",
|
|
195
|
+
"@polkadot-api/ink-contracts": "0.2.1",
|
|
198
196
|
"@polkadot-api/logs-provider": "0.0.6",
|
|
197
|
+
"@polkadot-api/json-rpc-provider": "0.0.4",
|
|
199
198
|
"@polkadot-api/polkadot-sdk-compat": "2.3.1",
|
|
199
|
+
"@polkadot-api/metadata-builders": "0.9.1",
|
|
200
200
|
"@polkadot-api/metadata-compatibility": "0.1.11",
|
|
201
201
|
"@polkadot-api/observable-client": "0.6.2",
|
|
202
202
|
"@polkadot-api/pjs-signer": "0.6.0",
|
|
203
203
|
"@polkadot-api/polkadot-signer": "0.1.6",
|
|
204
204
|
"@polkadot-api/signer": "0.1.10",
|
|
205
|
-
"@polkadot-api/sm-provider": "0.1.
|
|
205
|
+
"@polkadot-api/sm-provider": "0.1.7",
|
|
206
206
|
"@polkadot-api/substrate-bindings": "0.9.3",
|
|
207
|
-
"@polkadot-api/ws-provider": "0.3.4",
|
|
208
207
|
"@polkadot-api/substrate-client": "0.3.0",
|
|
208
|
+
"@polkadot-api/ws-provider": "0.3.6",
|
|
209
209
|
"@polkadot-api/utils": "0.1.2",
|
|
210
|
-
"@polkadot-api/known-chains": "0.5.
|
|
211
|
-
"@polkadot-api/smoldot": "0.3.
|
|
210
|
+
"@polkadot-api/known-chains": "0.5.7",
|
|
211
|
+
"@polkadot-api/smoldot": "0.3.6"
|
|
212
212
|
},
|
|
213
213
|
"devDependencies": {
|
|
214
214
|
"rxjs": "^7.8.1",
|
|
215
|
-
"@polkadot-api/codegen": "0.12.
|
|
215
|
+
"@polkadot-api/codegen": "0.12.8"
|
|
216
216
|
},
|
|
217
217
|
"scripts": {
|
|
218
218
|
"build-core": "tsc --noEmit && rollup -c",
|