polkadot-api 1.19.0 → 1.19.1
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,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 +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(
|
|
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}));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "polkadot-api",
|
|
3
|
-
"version": "1.19.
|
|
3
|
+
"version": "1.19.1",
|
|
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/
|
|
207
|
+
"@polkadot-api/cli": "0.15.1",
|
|
208
|
+
"@polkadot-api/json-rpc-provider": "0.0.4",
|
|
209
209
|
"@polkadot-api/ink-contracts": "0.4.0",
|
|
210
|
+
"@polkadot-api/known-chains": "0.9.11",
|
|
210
211
|
"@polkadot-api/logs-provider": "0.0.6",
|
|
211
|
-
"@polkadot-api/json-rpc-provider": "0.0.4",
|
|
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",
|
|
215
214
|
"@polkadot-api/pjs-signer": "0.6.15",
|
|
216
|
-
"@polkadot-api/
|
|
215
|
+
"@polkadot-api/observable-client": "0.15.1",
|
|
217
216
|
"@polkadot-api/polkadot-signer": "0.1.6",
|
|
218
217
|
"@polkadot-api/signer": "0.2.9",
|
|
219
218
|
"@polkadot-api/sm-provider": "0.1.11",
|
|
220
|
-
"@polkadot-api/
|
|
219
|
+
"@polkadot-api/polkadot-sdk-compat": "2.3.3",
|
|
221
220
|
"@polkadot-api/substrate-bindings": "0.16.3",
|
|
222
|
-
"@polkadot-api/
|
|
221
|
+
"@polkadot-api/substrate-client": "0.4.7",
|
|
223
222
|
"@polkadot-api/utils": "0.2.0",
|
|
224
|
-
"@polkadot-api/ws-provider": "0.6.
|
|
223
|
+
"@polkadot-api/ws-provider": "0.6.1",
|
|
224
|
+
"@polkadot-api/smoldot": "0.3.14"
|
|
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",
|