@polkadot-api/substrate-client
Advanced tools
Comparing version 0.0.1-30e26b39de13843b610000e45ad741bfb69972cc.1.0 to 0.0.1-3a25db5320a701befeda3e24152e33a2a2acac68.1.0
@@ -118,10 +118,10 @@ "use strict"; | ||
function isTerminalEvent(event) { | ||
return terminalEvents.has(event.event); | ||
return terminalEvents.has(event.type); | ||
} | ||
var TransactionError = class extends Error { | ||
constructor(e) { | ||
super(`TxError: ${e.event} - ${e.error}`); | ||
super(`TxError: ${e.type} - ${e.error}`); | ||
__publicField(this, "type"); | ||
__publicField(this, "error"); | ||
this.type = e.event; | ||
this.type = e.type; | ||
this.error = e.error; | ||
@@ -139,3 +139,3 @@ this.name = "TransactionError"; | ||
cancel = noop; | ||
if (event.event !== "finalized") | ||
if (event.type !== "finalized") | ||
return error(new TransactionError(event)); | ||
@@ -219,5 +219,5 @@ } | ||
const _e = e; | ||
if (_e.event === "operationError") { | ||
if (_e.type === "operationError") { | ||
rej(new OperationError(_e.error)); | ||
} else if (_e.event === "operationInaccessible") { | ||
} else if (_e.type === "operationInaccessible") { | ||
rej(new OperationInaccessibleError()); | ||
@@ -327,3 +327,3 @@ } else { | ||
const resultBuilder = (e, res) => { | ||
if (e.event === "operationStorageDone") | ||
if (e.type === "operationStorageDone") | ||
return res(result); | ||
@@ -389,3 +389,3 @@ e.items.forEach((item) => { | ||
return subscriptions.next(event.operationId, event); | ||
if (event.event !== "stop") | ||
if (event.type !== "stop") | ||
return onFollowEvent(event); | ||
@@ -392,0 +392,0 @@ onFollowError(new StopError()); |
@@ -48,3 +48,3 @@ import { GetProvider } from '@polkadot-api/json-rpc-provider'; | ||
interface Initialized { | ||
event: "initialized"; | ||
type: "initialized"; | ||
finalizedBlockHash: string; | ||
@@ -56,3 +56,3 @@ } | ||
interface NewBlock { | ||
event: "newBlock"; | ||
type: "newBlock"; | ||
blockHash: string; | ||
@@ -65,7 +65,7 @@ parentBlockHash: string; | ||
interface BestBlockChanged { | ||
event: "bestBlockChanged"; | ||
type: "bestBlockChanged"; | ||
bestBlockHash: string; | ||
} | ||
interface Finalized { | ||
event: "finalized"; | ||
type: "finalized"; | ||
finalizedBlockHashes: Array<string>; | ||
@@ -135,3 +135,3 @@ prunedBlockHashes: Array<string>; | ||
interface Stop { | ||
event: "stop"; | ||
type: "stop"; | ||
} | ||
@@ -142,9 +142,9 @@ interface OperationEvent { | ||
type OperationWaitingForContinue = OperationEvent & { | ||
event: "operationWaitingForContinue"; | ||
type: "operationWaitingForContinue"; | ||
}; | ||
type OperationInaccessible = OperationEvent & { | ||
event: "operationInaccessible"; | ||
type: "operationInaccessible"; | ||
}; | ||
type OperationError = OperationEvent & { | ||
event: "operationError"; | ||
type: "operationError"; | ||
error: string; | ||
@@ -154,7 +154,7 @@ }; | ||
type OperationBodyDone = OperationEvent & { | ||
event: "operationBodyDone"; | ||
type: "operationBodyDone"; | ||
value: Array<string>; | ||
}; | ||
type OperationCallDone = OperationEvent & { | ||
event: "operationCallDone"; | ||
type: "operationCallDone"; | ||
output: string; | ||
@@ -169,7 +169,7 @@ }; | ||
type OperationStorageItems = OperationEvent & { | ||
event: "operationStorageItems"; | ||
type: "operationStorageItems"; | ||
items: Array<StorageItemResponse>; | ||
}; | ||
type OperationStorageDone = OperationEvent & { | ||
event: "operationStorageDone"; | ||
type: "operationStorageDone"; | ||
}; | ||
@@ -182,10 +182,10 @@ type OperationEvents = OperationBodyDone | OperationCallDone | OperationStorageItems | OperationWaitingForContinue | OperationStorageDone | CommonOperationEvents; | ||
interface TxValidated { | ||
event: "validated"; | ||
type: "validated"; | ||
} | ||
interface TxBroadcasted { | ||
event: "broadcasted"; | ||
type: "broadcasted"; | ||
numPeers: number; | ||
} | ||
interface TxBestChainBlockIncluded { | ||
event: "bestChainBlockIncluded"; | ||
type: "bestChainBlockIncluded"; | ||
block: { | ||
@@ -197,3 +197,3 @@ hash: string; | ||
interface TxFinalized { | ||
event: "finalized"; | ||
type: "finalized"; | ||
block: { | ||
@@ -205,7 +205,7 @@ hash: string; | ||
interface TxInvalid { | ||
event: "invalid"; | ||
type: "invalid"; | ||
error: string; | ||
} | ||
interface TxDropped { | ||
event: "dropped"; | ||
type: "dropped"; | ||
broadcasted: boolean; | ||
@@ -215,3 +215,3 @@ error: string; | ||
interface TxError { | ||
event: "error"; | ||
type: "error"; | ||
error: string; | ||
@@ -224,3 +224,3 @@ } | ||
interface ITxError { | ||
type: ErrorEvents["event"]; | ||
type: ErrorEvents["type"]; | ||
error: string; | ||
@@ -227,0 +227,0 @@ } |
@@ -118,10 +118,10 @@ "use strict"; | ||
function isTerminalEvent(event) { | ||
return terminalEvents.has(event.event); | ||
return terminalEvents.has(event.type); | ||
} | ||
var TransactionError = class extends Error { | ||
constructor(e) { | ||
super(`TxError: ${e.event} - ${e.error}`); | ||
super(`TxError: ${e.type} - ${e.error}`); | ||
__publicField(this, "type"); | ||
__publicField(this, "error"); | ||
this.type = e.event; | ||
this.type = e.type; | ||
this.error = e.error; | ||
@@ -139,3 +139,3 @@ this.name = "TransactionError"; | ||
cancel = noop; | ||
if (event.event !== "finalized") | ||
if (event.type !== "finalized") | ||
return error(new TransactionError(event)); | ||
@@ -219,5 +219,5 @@ } | ||
const _e = e; | ||
if (_e.event === "operationError") { | ||
if (_e.type === "operationError") { | ||
rej(new OperationError(_e.error)); | ||
} else if (_e.event === "operationInaccessible") { | ||
} else if (_e.type === "operationInaccessible") { | ||
rej(new OperationInaccessibleError()); | ||
@@ -327,3 +327,3 @@ } else { | ||
const resultBuilder = (e, res) => { | ||
if (e.event === "operationStorageDone") | ||
if (e.type === "operationStorageDone") | ||
return res(result); | ||
@@ -389,3 +389,3 @@ e.items.forEach((item) => { | ||
return subscriptions.next(event.operationId, event); | ||
if (event.event !== "stop") | ||
if (event.type !== "stop") | ||
return onFollowEvent(event); | ||
@@ -392,0 +392,0 @@ onFollowError(new StopError()); |
@@ -48,3 +48,3 @@ import { GetProvider } from '@polkadot-api/json-rpc-provider'; | ||
interface Initialized { | ||
event: "initialized"; | ||
type: "initialized"; | ||
finalizedBlockHash: string; | ||
@@ -56,3 +56,3 @@ } | ||
interface NewBlock { | ||
event: "newBlock"; | ||
type: "newBlock"; | ||
blockHash: string; | ||
@@ -65,7 +65,7 @@ parentBlockHash: string; | ||
interface BestBlockChanged { | ||
event: "bestBlockChanged"; | ||
type: "bestBlockChanged"; | ||
bestBlockHash: string; | ||
} | ||
interface Finalized { | ||
event: "finalized"; | ||
type: "finalized"; | ||
finalizedBlockHashes: Array<string>; | ||
@@ -135,3 +135,3 @@ prunedBlockHashes: Array<string>; | ||
interface Stop { | ||
event: "stop"; | ||
type: "stop"; | ||
} | ||
@@ -142,9 +142,9 @@ interface OperationEvent { | ||
type OperationWaitingForContinue = OperationEvent & { | ||
event: "operationWaitingForContinue"; | ||
type: "operationWaitingForContinue"; | ||
}; | ||
type OperationInaccessible = OperationEvent & { | ||
event: "operationInaccessible"; | ||
type: "operationInaccessible"; | ||
}; | ||
type OperationError = OperationEvent & { | ||
event: "operationError"; | ||
type: "operationError"; | ||
error: string; | ||
@@ -154,7 +154,7 @@ }; | ||
type OperationBodyDone = OperationEvent & { | ||
event: "operationBodyDone"; | ||
type: "operationBodyDone"; | ||
value: Array<string>; | ||
}; | ||
type OperationCallDone = OperationEvent & { | ||
event: "operationCallDone"; | ||
type: "operationCallDone"; | ||
output: string; | ||
@@ -169,7 +169,7 @@ }; | ||
type OperationStorageItems = OperationEvent & { | ||
event: "operationStorageItems"; | ||
type: "operationStorageItems"; | ||
items: Array<StorageItemResponse>; | ||
}; | ||
type OperationStorageDone = OperationEvent & { | ||
event: "operationStorageDone"; | ||
type: "operationStorageDone"; | ||
}; | ||
@@ -182,10 +182,10 @@ type OperationEvents = OperationBodyDone | OperationCallDone | OperationStorageItems | OperationWaitingForContinue | OperationStorageDone | CommonOperationEvents; | ||
interface TxValidated { | ||
event: "validated"; | ||
type: "validated"; | ||
} | ||
interface TxBroadcasted { | ||
event: "broadcasted"; | ||
type: "broadcasted"; | ||
numPeers: number; | ||
} | ||
interface TxBestChainBlockIncluded { | ||
event: "bestChainBlockIncluded"; | ||
type: "bestChainBlockIncluded"; | ||
block: { | ||
@@ -197,3 +197,3 @@ hash: string; | ||
interface TxFinalized { | ||
event: "finalized"; | ||
type: "finalized"; | ||
block: { | ||
@@ -205,7 +205,7 @@ hash: string; | ||
interface TxInvalid { | ||
event: "invalid"; | ||
type: "invalid"; | ||
error: string; | ||
} | ||
interface TxDropped { | ||
event: "dropped"; | ||
type: "dropped"; | ||
broadcasted: boolean; | ||
@@ -215,3 +215,3 @@ error: string; | ||
interface TxError { | ||
event: "error"; | ||
type: "error"; | ||
error: string; | ||
@@ -224,3 +224,3 @@ } | ||
interface ITxError { | ||
type: ErrorEvents["event"]; | ||
type: ErrorEvents["type"]; | ||
error: string; | ||
@@ -227,0 +227,0 @@ } |
@@ -1,2 +0,2 @@ | ||
"use strict";var I=Object.defineProperty;var K=Object.getOwnPropertyDescriptor;var $=Object.getOwnPropertyNames;var Q=Object.prototype.hasOwnProperty;var X=(r,e,t)=>e in r?I(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t;var Y=(r,e)=>{for(var t in e)I(r,t,{get:e[t],enumerable:!0})},Z=(r,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of $(e))!Q.call(r,o)&&o!==t&&I(r,o,{get:()=>e[o],enumerable:!(n=K(e,o))||n.enumerable});return r};var ee=r=>Z(I({},"__esModule",{value:!0}),r);var C=(r,e,t)=>(X(r,typeof e!="symbol"?e+"":e,t),t);var se={};Y(se,{DisjointError:()=>x,OperationError:()=>A,OperationInaccessibleError:()=>P,OperationLimitError:()=>O,RpcError:()=>T,StopError:()=>F,TransactionError:()=>R,createClient:()=>oe});module.exports=ee(se);var D=class extends Error{constructor(){super("Aborted by AbortSignal"),this.name="AbortError"}},U=r=>(...e)=>new Promise((t,n)=>{let[o,m]=e[e.length-1]instanceof AbortSignal?[e.slice(0,e.length-1),e[e.length-1]]:[e],u=()=>{i(),n(new D)};m?.addEventListener("abort",u,{once:!0});let d=y=>c=>{m?.removeEventListener("abort",u),y(c)},i=r(d(t),d(n),...o)});function j(){let r=()=>{},e=()=>{};return{promise:new Promise((n,o)=>{r=n,e=o}),res:r,rej:e}}var E=()=>{};var _=()=>{let r=new Map;return{has:r.has.bind(r),subscribe(e,t){r.set(e,t)},unsubscribe(e){r.delete(e)},next(e,t){r.get(e)?.next(t)},error(e,t){let n=r.get(e);n&&(r.delete(e),n.error(t))},errorAll(e){let t=[...r.values()];r.clear(),t.forEach(n=>{n.error(e)})}}};var re=new Set(["dropped","invalid","finalized","error"]);function te(r){return re.has(r.event)}var R=class extends Error{constructor(t){super(`TxError: ${t.event} - ${t.error}`);C(this,"type");C(this,"error");this.type=t.event,this.error=t.error,this.name="TransactionError"}},M=r=>(e,t,n)=>{let o=r("transaction_unstable_submitAndWatch",[e],{onSuccess:(m,u)=>{let d=u(m,{next:i=>{if(te(i)&&(d(),o=E,i.event!=="finalized"))return n(new R(i));t(i)},error(i){o(),o=E,n(i)}});o=()=>{d(),r("transaction_unstable_unwatch",[m])}},onError:n});return()=>{o()}};var F=class extends Error{constructor(){super("ChainHead stopped"),this.name="StopError"}},x=class extends Error{constructor(){super("ChainHead disjointed"),this.name="DisjointError"}},O=class extends Error{constructor(){super("ChainHead operations limit reached"),this.name="OperationLimitError"}},A=class extends Error{constructor(e){super(e),this.name="OperationError"}},P=class extends Error{constructor(){super("ChainHead operation inaccessible"),this.name="OperationInaccessibleError"}};var q=(r,e)=>t=>U((n,o,...m)=>{let[u,d]=e(...m),i=t(r,u,{onSuccess:(y,c)=>{if(y.result==="limitReached")return i=E,o(new O);let b=!0,f=E,h=a=>{b=!1,f(),n(a)},s=a=>{b=!1,f(),o(a)};f=c(y.operationId,{next:a=>{let l=a;l.event==="operationError"?o(new A(l.error)):l.event==="operationInaccessible"?o(new P):d(a,h,s)},error:s}),i=()=>{b&&(f(),t("chainHead_unstable_stopOperation",[y.operationId]))}},onError:o});return()=>{i()}});var B=q("chainHead_unstable_body",r=>[[r],(e,t)=>{t(e.value)}]);var G=q("chainHead_unstable_call",(r,e,t)=>[[r,e,t],(n,o)=>{o(n.output)}]);var N=r=>e=>new Promise((t,n)=>{r("chainHead_unstable_header",[e],{onSuccess:t,onError:n})});var L=q("chainHead_unstable_storage",(r,e,t)=>{let n={value:new Set(e.value??[]),hash:new Set(e.hash??[]),closestDescendantMerkleValue:new Set(e.closestDescendantMerkleValue??[]),descendantsValues:new Set(e.descendantsValues??[]),descendantsHashes:new Set(e.descendantsHashes??[])},o=[];e.value?.forEach(i=>{o.push({type:"value",key:i})}),e.hash?.forEach(i=>{o.push({type:"hash",key:i})}),e.descendantsValues?.forEach(i=>{o.push({type:"descendantsValues",key:i})}),e.descendantsHashes?.forEach(i=>{o.push({type:"descendantsHashes",key:i})}),n.closestDescendantMerkleValue?.forEach(i=>{o.push({type:"closestDescendantMerkleValue",key:i})});let m=[r,o,t],u={values:{},hashes:{},closests:{},descendantsHashes:{},descendantsValues:{}};return[m,(i,y)=>{if(i.event==="operationStorageDone")return y(u);i.items.forEach(c=>{if(c.value)if(n.value.has(c.key))u.values[c.key]=c.value;else{let b=[...n.descendantsValues].filter(h=>c.key.startsWith(h)).sort((h,s)=>s.length-h.length)[0],f=u.descendantsValues[b]??[];f.push({key:c.key,value:c.value}),u.descendantsValues[b]=f}if(c.hash)if(n.hash.has(c.key))u.hashes[c.key]=c.hash;else{let b=[...n.descendantsHashes].filter(h=>c.key.startsWith(h)).sort((h,s)=>s.length-h.length)[0],f=u.descendantsHashes[b]??[];f.push({key:c.key,hash:c.hash}),u.descendantsHashes[b]=f}c.closestDescendantMerkleValue&&n.closestDescendantMerkleValue.has(c.key)&&(u.closests[c.key]=c.closestDescendantMerkleValue)})}]});var z=r=>e=>new Promise((t,n)=>{r("chainHead_unstable_unpin",[e],{onSuccess(){t()},onError:n})});function ne(r){return r.operationId!==void 0}function V(r){return(e,t,n)=>{let o=_(),m=new Set,u=j(),d=u.promise,i=s=>{if(ne(s))return o.next(s.operationId,s);if(s.event!=="stop")return t(s);n(new F),f(!1)},y=s=>{n(s),f()},f=r("chainHead_unstable_follow",[e],{onSuccess:(s,a)=>{let l=a(s,{next:i,error:y});f=(p=!0)=>{d=null,f=E,l(),p&&r("chainHead_unstable_unfollow",[s]),o.errorAll(new x),m.forEach(v=>{v()}),m.clear()},d=s,u.res(s)},onError:s=>{n(s),d=null,u.res(s)}}),h=(s,a,l)=>{let p=()=>{l?.onError(new x)};if(d===null)return p(),E;let v=g=>{if(!l)return r(s,[g,...a]);m.add(p);let H=(w,W)=>d===null?(W.error(new x),E):(o.subscribe(w,W),()=>{o.unsubscribe(w)}),k=r(s,[g,...a],{onSuccess:w=>{m.delete(p),l.onSuccess(w,H)},onError:w=>{m.delete(p),l.onError(w)}});return()=>{m.delete(p),k()}};if(typeof d=="string")return v(d);let S=E;return d.then(g=>{if(g instanceof Error)return p();d&&(S=v(g))}),()=>{S()}};return{unfollow(){f(),d=null},body:B(h),call:G(h),header:N(h),storage:L(h),unpin:z(h),_request:h}}}var T=class extends Error{constructor(t){super(t.message);C(this,"code");C(this,"data");this.code=t.code,this.data=t.data,this.name="RpcError"}};var J=r=>{let e=new Map,t=_(),n=new Map,o=null,m="disconnected",u=(s,a,l)=>{o.send(JSON.stringify({jsonrpc:"2.0",id:s,method:a,params:l}))};function d(s){try{let a,l,p,v,S;if({id:a,result:l,error:p,params:v}=JSON.parse(s),a){let g=e.get(a);return g?(e.delete(a),p?g.onError(new T(p)):g.onSuccess(l,(H,k)=>(t.subscribe(H,k),()=>{t.unsubscribe(H)}))):void 0}if({subscription:S,result:l,error:p}=v,!S||!p&&!Object.hasOwn(v,"result"))throw 0;p?t.error(S,new T(p)):t.next(S,l)}catch(a){console.warn("Error parsing incomming message: "+s),console.error(a)}}function i(s){s==="connected"&&(n.forEach((a,l)=>{b(l,...a)}),n.clear()),m=s}let y=()=>{o=r(d,i),o.open()},c=()=>{o?.close(),o=null,e.clear(),n.clear(),t.errorAll(new Error("disconnected"))},b=(s,...a)=>{let[l,p,v]=a;v&&e.set(s,v),u(s,l,p)},f=1;return{request:(s,a,l)=>{if(!o)throw new Error("Not connected");let p=f++;return m==="connected"?b(p,s,a,l):n.set(p,[s,a,l]),()=>{if(n.has(p)){n.delete(p);return}e.delete(p)}},connect:y,disconnect:c}};var oe=r=>{let e=J(r);return e.connect(),{chainHead:V(e.request),transaction:M(e.request),_request:e.request}}; | ||
"use strict";var I=Object.defineProperty;var K=Object.getOwnPropertyDescriptor;var $=Object.getOwnPropertyNames;var Q=Object.prototype.hasOwnProperty;var X=(r,e,t)=>e in r?I(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t;var Y=(r,e)=>{for(var t in e)I(r,t,{get:e[t],enumerable:!0})},Z=(r,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of $(e))!Q.call(r,o)&&o!==t&&I(r,o,{get:()=>e[o],enumerable:!(n=K(e,o))||n.enumerable});return r};var ee=r=>Z(I({},"__esModule",{value:!0}),r);var C=(r,e,t)=>(X(r,typeof e!="symbol"?e+"":e,t),t);var se={};Y(se,{DisjointError:()=>x,OperationError:()=>A,OperationInaccessibleError:()=>P,OperationLimitError:()=>O,RpcError:()=>T,StopError:()=>F,TransactionError:()=>R,createClient:()=>oe});module.exports=ee(se);var D=class extends Error{constructor(){super("Aborted by AbortSignal"),this.name="AbortError"}},U=r=>(...e)=>new Promise((t,n)=>{let[o,m]=e[e.length-1]instanceof AbortSignal?[e.slice(0,e.length-1),e[e.length-1]]:[e],u=()=>{i(),n(new D)};m?.addEventListener("abort",u,{once:!0});let d=b=>c=>{m?.removeEventListener("abort",u),b(c)},i=r(d(t),d(n),...o)});function j(){let r=()=>{},e=()=>{};return{promise:new Promise((n,o)=>{r=n,e=o}),res:r,rej:e}}var v=()=>{};var _=()=>{let r=new Map;return{has:r.has.bind(r),subscribe(e,t){r.set(e,t)},unsubscribe(e){r.delete(e)},next(e,t){r.get(e)?.next(t)},error(e,t){let n=r.get(e);n&&(r.delete(e),n.error(t))},errorAll(e){let t=[...r.values()];r.clear(),t.forEach(n=>{n.error(e)})}}};var re=new Set(["dropped","invalid","finalized","error"]);function te(r){return re.has(r.type)}var R=class extends Error{constructor(t){super(`TxError: ${t.type} - ${t.error}`);C(this,"type");C(this,"error");this.type=t.type,this.error=t.error,this.name="TransactionError"}},M=r=>(e,t,n)=>{let o=r("transaction_unstable_submitAndWatch",[e],{onSuccess:(m,u)=>{let d=u(m,{next:i=>{if(te(i)&&(d(),o=v,i.type!=="finalized"))return n(new R(i));t(i)},error(i){o(),o=v,n(i)}});o=()=>{d(),r("transaction_unstable_unwatch",[m])}},onError:n});return()=>{o()}};var F=class extends Error{constructor(){super("ChainHead stopped"),this.name="StopError"}},x=class extends Error{constructor(){super("ChainHead disjointed"),this.name="DisjointError"}},O=class extends Error{constructor(){super("ChainHead operations limit reached"),this.name="OperationLimitError"}},A=class extends Error{constructor(e){super(e),this.name="OperationError"}},P=class extends Error{constructor(){super("ChainHead operation inaccessible"),this.name="OperationInaccessibleError"}};var q=(r,e)=>t=>U((n,o,...m)=>{let[u,d]=e(...m),i=t(r,u,{onSuccess:(b,c)=>{if(b.result==="limitReached")return i=v,o(new O);let h=!0,f=v,y=a=>{h=!1,f(),n(a)},s=a=>{h=!1,f(),o(a)};f=c(b.operationId,{next:a=>{let l=a;l.type==="operationError"?o(new A(l.error)):l.type==="operationInaccessible"?o(new P):d(a,y,s)},error:s}),i=()=>{h&&(f(),t("chainHead_unstable_stopOperation",[b.operationId]))}},onError:o});return()=>{i()}});var B=q("chainHead_unstable_body",r=>[[r],(e,t)=>{t(e.value)}]);var G=q("chainHead_unstable_call",(r,e,t)=>[[r,e,t],(n,o)=>{o(n.output)}]);var N=r=>e=>new Promise((t,n)=>{r("chainHead_unstable_header",[e],{onSuccess:t,onError:n})});var L=q("chainHead_unstable_storage",(r,e,t)=>{let n={value:new Set(e.value??[]),hash:new Set(e.hash??[]),closestDescendantMerkleValue:new Set(e.closestDescendantMerkleValue??[]),descendantsValues:new Set(e.descendantsValues??[]),descendantsHashes:new Set(e.descendantsHashes??[])},o=[];e.value?.forEach(i=>{o.push({type:"value",key:i})}),e.hash?.forEach(i=>{o.push({type:"hash",key:i})}),e.descendantsValues?.forEach(i=>{o.push({type:"descendantsValues",key:i})}),e.descendantsHashes?.forEach(i=>{o.push({type:"descendantsHashes",key:i})}),n.closestDescendantMerkleValue?.forEach(i=>{o.push({type:"closestDescendantMerkleValue",key:i})});let m=[r,o,t],u={values:{},hashes:{},closests:{},descendantsHashes:{},descendantsValues:{}};return[m,(i,b)=>{if(i.type==="operationStorageDone")return b(u);i.items.forEach(c=>{if(c.value)if(n.value.has(c.key))u.values[c.key]=c.value;else{let h=[...n.descendantsValues].filter(y=>c.key.startsWith(y)).sort((y,s)=>s.length-y.length)[0],f=u.descendantsValues[h]??[];f.push({key:c.key,value:c.value}),u.descendantsValues[h]=f}if(c.hash)if(n.hash.has(c.key))u.hashes[c.key]=c.hash;else{let h=[...n.descendantsHashes].filter(y=>c.key.startsWith(y)).sort((y,s)=>s.length-y.length)[0],f=u.descendantsHashes[h]??[];f.push({key:c.key,hash:c.hash}),u.descendantsHashes[h]=f}c.closestDescendantMerkleValue&&n.closestDescendantMerkleValue.has(c.key)&&(u.closests[c.key]=c.closestDescendantMerkleValue)})}]});var z=r=>e=>new Promise((t,n)=>{r("chainHead_unstable_unpin",[e],{onSuccess(){t()},onError:n})});function ne(r){return r.operationId!==void 0}function V(r){return(e,t,n)=>{let o=_(),m=new Set,u=j(),d=u.promise,i=s=>{if(ne(s))return o.next(s.operationId,s);if(s.type!=="stop")return t(s);n(new F),f(!1)},b=s=>{n(s),f()},f=r("chainHead_unstable_follow",[e],{onSuccess:(s,a)=>{let l=a(s,{next:i,error:b});f=(p=!0)=>{d=null,f=v,l(),p&&r("chainHead_unstable_unfollow",[s]),o.errorAll(new x),m.forEach(E=>{E()}),m.clear()},d=s,u.res(s)},onError:s=>{n(s),d=null,u.res(s)}}),y=(s,a,l)=>{let p=()=>{l?.onError(new x)};if(d===null)return p(),v;let E=g=>{if(!l)return r(s,[g,...a]);m.add(p);let H=(w,W)=>d===null?(W.error(new x),v):(o.subscribe(w,W),()=>{o.unsubscribe(w)}),k=r(s,[g,...a],{onSuccess:w=>{m.delete(p),l.onSuccess(w,H)},onError:w=>{m.delete(p),l.onError(w)}});return()=>{m.delete(p),k()}};if(typeof d=="string")return E(d);let S=v;return d.then(g=>{if(g instanceof Error)return p();d&&(S=E(g))}),()=>{S()}};return{unfollow(){f(),d=null},body:B(y),call:G(y),header:N(y),storage:L(y),unpin:z(y),_request:y}}}var T=class extends Error{constructor(t){super(t.message);C(this,"code");C(this,"data");this.code=t.code,this.data=t.data,this.name="RpcError"}};var J=r=>{let e=new Map,t=_(),n=new Map,o=null,m="disconnected",u=(s,a,l)=>{o.send(JSON.stringify({jsonrpc:"2.0",id:s,method:a,params:l}))};function d(s){try{let a,l,p,E,S;if({id:a,result:l,error:p,params:E}=JSON.parse(s),a){let g=e.get(a);return g?(e.delete(a),p?g.onError(new T(p)):g.onSuccess(l,(H,k)=>(t.subscribe(H,k),()=>{t.unsubscribe(H)}))):void 0}if({subscription:S,result:l,error:p}=E,!S||!p&&!Object.hasOwn(E,"result"))throw 0;p?t.error(S,new T(p)):t.next(S,l)}catch(a){console.warn("Error parsing incomming message: "+s),console.error(a)}}function i(s){s==="connected"&&(n.forEach((a,l)=>{h(l,...a)}),n.clear()),m=s}let b=()=>{o=r(d,i),o.open()},c=()=>{o?.close(),o=null,e.clear(),n.clear(),t.errorAll(new Error("disconnected"))},h=(s,...a)=>{let[l,p,E]=a;E&&e.set(s,E),u(s,l,p)},f=1;return{request:(s,a,l)=>{if(!o)throw new Error("Not connected");let p=f++;return m==="connected"?h(p,s,a,l):n.set(p,[s,a,l]),()=>{if(n.has(p)){n.delete(p);return}e.delete(p)}},connect:b,disconnect:c}};var oe=r=>{let e=J(r);return e.connect(),{chainHead:V(e.request),transaction:M(e.request),_request:e.request}}; | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "@polkadot-api/substrate-client", | ||
"version": "0.0.1-30e26b39de13843b610000e45ad741bfb69972cc.1.0", | ||
"version": "0.0.1-3a25db5320a701befeda3e24152e33a2a2acac68.1.0", | ||
"author": "Josep M Sobrepere (https://github.com/josepot)", | ||
@@ -44,4 +44,4 @@ "repository": { | ||
"@vitest/coverage-v8": "^0.34.3", | ||
"@polkadot-api/json-rpc-provider": "0.0.1-30e26b39de13843b610000e45ad741bfb69972cc.1.0", | ||
"@polkadot-api/utils": "0.0.1-30e26b39de13843b610000e45ad741bfb69972cc.1.0" | ||
"@polkadot-api/json-rpc-provider": "0.0.1-3a25db5320a701befeda3e24152e33a2a2acac68.1.0", | ||
"@polkadot-api/utils": "0.0.1-3a25db5320a701befeda3e24152e33a2a2acac68.1.0" | ||
}, | ||
@@ -48,0 +48,0 @@ "scripts": { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
205339