@polkadot-api/json-rpc-provider-proxy
Advanced tools
Comparing version 0.0.1-5f0fe49a72a058a62aaac5040bea83d67b0f32a5.1.0 to 0.0.1-8b1b9459bb99c052281ba0a2e0f324046e1dce80.1.0
@@ -37,3 +37,3 @@ "use strict"; | ||
]); | ||
var chainHeadFollow = { | ||
var chainHeadFollow = (onMessage) => ({ | ||
onSent(parsed) { | ||
@@ -61,13 +61,17 @@ if (parsed.method === START_METHOD) | ||
}, | ||
onAbort: (id) => ({ | ||
jsonrpc: "2.0", | ||
method: NOTIFICATION_METHOD, | ||
params: { | ||
subscription: id, | ||
result: { | ||
event: ABORT_EVENT | ||
} | ||
} | ||
}) | ||
}; | ||
onAbort: (id) => { | ||
onMessage( | ||
JSON.stringify({ | ||
jsonrpc: "2.0", | ||
method: NOTIFICATION_METHOD, | ||
params: { | ||
subscription: id, | ||
result: { | ||
event: ABORT_EVENT | ||
} | ||
} | ||
}) | ||
); | ||
} | ||
}); | ||
@@ -80,3 +84,3 @@ // src/subscription-manager/transaction-submit-watch.ts | ||
var terminalEvents2 = /* @__PURE__ */ new Set([ABORT_EVENT2, "finalized", "error", "invalid"]); | ||
var txSubmitAndWatch = { | ||
var txSubmitAndWatch = (onMessage) => ({ | ||
onSent(parsed) { | ||
@@ -104,13 +108,17 @@ if (parsed.method === START_METHOD2) | ||
}, | ||
onAbort: (id) => ({ | ||
jsonrpc: "2.0", | ||
method: NOTIFICATION_METHOD2, | ||
params: { | ||
subscription: id, | ||
result: { | ||
event: ABORT_EVENT2 | ||
} | ||
} | ||
}) | ||
}; | ||
onAbort: (id) => { | ||
onMessage( | ||
JSON.stringify({ | ||
jsonrpc: "2.0", | ||
method: NOTIFICATION_METHOD2, | ||
params: { | ||
subscription: id, | ||
result: { | ||
event: ABORT_EVENT2 | ||
} | ||
} | ||
}) | ||
); | ||
} | ||
}); | ||
@@ -125,2 +133,6 @@ // src/subscription-manager/subscription-manager.ts | ||
const active = /* @__PURE__ */ new Set(); | ||
const onDisconnect = () => { | ||
preActive.clear(); | ||
active.clear(); | ||
}; | ||
return { | ||
@@ -150,13 +162,13 @@ onSent(parsed) { | ||
}, | ||
onDisconnect, | ||
onAbort() { | ||
preActive.clear(); | ||
const result = [...active].map(onAbort); | ||
active.clear(); | ||
return result; | ||
const activeCopy = [...active]; | ||
onDisconnect(); | ||
activeCopy.forEach(onAbort); | ||
} | ||
}; | ||
}; | ||
var getSubscriptionManager = () => { | ||
var getSubscriptionManager = (onMessage) => { | ||
const subscriptions = [chainHeadFollow, txSubmitAndWatch].map( | ||
(logic) => addSubscription(logic) | ||
(logic) => addSubscription(logic(onMessage)) | ||
); | ||
@@ -179,4 +191,7 @@ return { | ||
}, | ||
onDisconnect() { | ||
subscriptions.forEach((s) => s.onDisconnect()); | ||
}, | ||
onAbort() { | ||
return subscriptions.map((s) => s.onAbort()).flat(); | ||
subscriptions.forEach((s) => s.onAbort()); | ||
} | ||
@@ -191,3 +206,3 @@ }; | ||
const pendingResponses = /* @__PURE__ */ new Set(); | ||
const subscriptionManager = getSubscriptionManager(); | ||
const subscriptionManager = getSubscriptionManager(onMessage); | ||
const onMessageProxy = (message) => { | ||
@@ -225,6 +240,6 @@ let parsed; | ||
pendingResponses.clear(); | ||
if (!provider) | ||
throw null; | ||
const result = start(); | ||
subscriptionManager.onAbort().forEach((msg) => { | ||
onMessage(JSON.stringify(msg)); | ||
}); | ||
subscriptionManager.onAbort(); | ||
pendingResponsesCopy.forEach((id) => { | ||
@@ -269,9 +284,9 @@ onMessage( | ||
const finishIt = (input2) => { | ||
subscriptionManager.onAbort(); | ||
subscriptionManager.onDisconnect(); | ||
pendingResponses.clear(); | ||
provider = null; | ||
input2.disconnect(); | ||
input2?.disconnect(); | ||
}; | ||
if (provider instanceof Promise) { | ||
provider.then(finishIt); | ||
provider.then(finishIt, finishIt); | ||
provider = null; | ||
@@ -278,0 +293,0 @@ } else |
@@ -37,3 +37,3 @@ "use strict"; | ||
]); | ||
var chainHeadFollow = { | ||
var chainHeadFollow = (onMessage) => ({ | ||
onSent(parsed) { | ||
@@ -61,13 +61,17 @@ if (parsed.method === START_METHOD) | ||
}, | ||
onAbort: (id) => ({ | ||
jsonrpc: "2.0", | ||
method: NOTIFICATION_METHOD, | ||
params: { | ||
subscription: id, | ||
result: { | ||
event: ABORT_EVENT | ||
} | ||
} | ||
}) | ||
}; | ||
onAbort: (id) => { | ||
onMessage( | ||
JSON.stringify({ | ||
jsonrpc: "2.0", | ||
method: NOTIFICATION_METHOD, | ||
params: { | ||
subscription: id, | ||
result: { | ||
event: ABORT_EVENT | ||
} | ||
} | ||
}) | ||
); | ||
} | ||
}); | ||
@@ -80,3 +84,3 @@ // src/subscription-manager/transaction-submit-watch.ts | ||
var terminalEvents2 = /* @__PURE__ */ new Set([ABORT_EVENT2, "finalized", "error", "invalid"]); | ||
var txSubmitAndWatch = { | ||
var txSubmitAndWatch = (onMessage) => ({ | ||
onSent(parsed) { | ||
@@ -104,13 +108,17 @@ if (parsed.method === START_METHOD2) | ||
}, | ||
onAbort: (id) => ({ | ||
jsonrpc: "2.0", | ||
method: NOTIFICATION_METHOD2, | ||
params: { | ||
subscription: id, | ||
result: { | ||
event: ABORT_EVENT2 | ||
} | ||
} | ||
}) | ||
}; | ||
onAbort: (id) => { | ||
onMessage( | ||
JSON.stringify({ | ||
jsonrpc: "2.0", | ||
method: NOTIFICATION_METHOD2, | ||
params: { | ||
subscription: id, | ||
result: { | ||
event: ABORT_EVENT2 | ||
} | ||
} | ||
}) | ||
); | ||
} | ||
}); | ||
@@ -125,2 +133,6 @@ // src/subscription-manager/subscription-manager.ts | ||
const active = /* @__PURE__ */ new Set(); | ||
const onDisconnect = () => { | ||
preActive.clear(); | ||
active.clear(); | ||
}; | ||
return { | ||
@@ -150,13 +162,13 @@ onSent(parsed) { | ||
}, | ||
onDisconnect, | ||
onAbort() { | ||
preActive.clear(); | ||
const result = [...active].map(onAbort); | ||
active.clear(); | ||
return result; | ||
const activeCopy = [...active]; | ||
onDisconnect(); | ||
activeCopy.forEach(onAbort); | ||
} | ||
}; | ||
}; | ||
var getSubscriptionManager = () => { | ||
var getSubscriptionManager = (onMessage) => { | ||
const subscriptions = [chainHeadFollow, txSubmitAndWatch].map( | ||
(logic) => addSubscription(logic) | ||
(logic) => addSubscription(logic(onMessage)) | ||
); | ||
@@ -179,4 +191,7 @@ return { | ||
}, | ||
onDisconnect() { | ||
subscriptions.forEach((s) => s.onDisconnect()); | ||
}, | ||
onAbort() { | ||
return subscriptions.map((s) => s.onAbort()).flat(); | ||
subscriptions.forEach((s) => s.onAbort()); | ||
} | ||
@@ -191,3 +206,3 @@ }; | ||
const pendingResponses = /* @__PURE__ */ new Set(); | ||
const subscriptionManager = getSubscriptionManager(); | ||
const subscriptionManager = getSubscriptionManager(onMessage); | ||
const onMessageProxy = (message) => { | ||
@@ -225,6 +240,6 @@ let parsed; | ||
pendingResponses.clear(); | ||
if (!provider) | ||
throw null; | ||
const result = start(); | ||
subscriptionManager.onAbort().forEach((msg) => { | ||
onMessage(JSON.stringify(msg)); | ||
}); | ||
subscriptionManager.onAbort(); | ||
pendingResponsesCopy.forEach((id) => { | ||
@@ -269,9 +284,9 @@ onMessage( | ||
const finishIt = (input2) => { | ||
subscriptionManager.onAbort(); | ||
subscriptionManager.onDisconnect(); | ||
pendingResponses.clear(); | ||
provider = null; | ||
input2.disconnect(); | ||
input2?.disconnect(); | ||
}; | ||
if (provider instanceof Promise) { | ||
provider.then(finishIt); | ||
provider.then(finishIt, finishIt); | ||
provider = null; | ||
@@ -278,0 +293,0 @@ } else |
@@ -1,2 +0,2 @@ | ||
"use strict";var d=Object.defineProperty;var _=Object.getOwnPropertyDescriptor;var E=Object.getOwnPropertyNames;var I=Object.prototype.hasOwnProperty;var O=(n,t)=>{for(var e in t)d(n,e,{get:t[e],enumerable:!0})},R=(n,t,e,a)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of E(t))!I.call(n,o)&&o!==e&&d(n,o,{get:()=>t[o],enumerable:!(a=_(t,o))||a.enumerable});return n};var M=n=>R(d({},"__esModule",{value:!0}),n);var q={};O(q,{getSyncProvider:()=>D});module.exports=M(q);var N="chainHead_unstable_follow",H="chainHead_unstable_unfollow",m="chainHead_unstable_followEvent",y="stop",w=new Set([y,"operationInaccessible","operationError"]),S={onSent(n){return n.method===N?{type:"subscribe",id:n.id,onRes:t=>t.id===n.id?{id:t.result}:null}:n.method===H?{type:"unsubscribe",id:Object.values(n.params)[0]}:null},onNotification(n){return n.method!==m?null:w.has(n.params.result.event)?{type:"end",id:n.params.subscription}:null},onAbort:n=>({jsonrpc:"2.0",method:m,params:{subscription:n,result:{event:y}}})};var x="transaction_unstable_submitAndWatch",C="transaction_unstable_unwatch",g="transaction_unstable_watchEvent",h="dropped",J=new Set([h,"finalized","error","invalid"]),v={onSent(n){return n.method===x?{type:"subscribe",id:n.id,onRes:t=>t.id===n.id?{id:t.result}:null}:n.method===C?{type:"unsubscribe",id:Object.values(n.params)[0]}:null},onNotification(n){return n.method!==g?null:J.has(n.params.result.event)?{type:"end",id:n.params.subscription}:null},onAbort:n=>({jsonrpc:"2.0",method:g,params:{subscription:n,result:{event:h}}})};var j=({onSent:n,onNotification:t,onAbort:e})=>{let a=new Map,o=new Set;return{onSent(r){let c=n(r);c&&(c.type==="subscribe"?a.set(c.id,c.onRes):o.delete(c.id))},onResponse(r){let c=a.get(r.id)?.(r);c&&(a.delete(r.id),o.add(c.id))},onNotifiaction(r){let c=t(r);c&&o.delete(c.id)},onAbort(){a.clear();let r=[...o].map(e);return o.clear(),r}}},A=()=>{let n=[S,v].map(t=>j(t));return{onSent(t){n.forEach(e=>{e.onSent(t)})},onResponse(t){n.forEach(e=>{e.onResponse(t)})},onNotifiaction(t){n.forEach(e=>{e.onNotifiaction(t)})},onAbort(){return n.map(t=>t.onAbort()).flat()}}};var D=n=>t=>{let e,a=[],o=new Set,r=A(),c=s=>{let i;try{i=JSON.parse(s)}catch{console.error(`Unable to parse incoming message: ${s}`);return}i.id!==void 0?(o.delete(i.id),r.onResponse(i)):r.onNotifiaction(i),t(s)},P=s=>{if(!e)return;let i=JSON.parse(s);r.onSent(i),i.id&&o.add(i.id),e instanceof Promise?a.push(s):e.send(s)},p=()=>{a=[];let s=[...o];o.clear();let i=b();return r.onAbort().forEach(u=>{t(JSON.stringify(u))}),s.forEach(u=>{t(JSON.stringify({jsonrpc:"2.0",error:{code:-32603,message:"Internal error"},id:u}))}),i},b=()=>{let s=i=>{let u=!1,f=i(l=>{u||c(l)},()=>{u||(u=!0,p())});return a.forEach(l=>{f.send(l)}),a=[],e=f};return e=n().then(s,L(p)),e},T=()=>{if(!e)return;let s=i=>{r.onAbort(),o.clear(),e=null,i.disconnect()};e instanceof Promise?(e.then(s),e=null):s(e)};return b(),{send:P,disconnect:T}},L=n=>(...t)=>new Promise(e=>setTimeout(e,0)).then(()=>n(...t)); | ||
"use strict";var p=Object.defineProperty;var A=Object.getOwnPropertyDescriptor;var E=Object.getOwnPropertyNames;var O=Object.prototype.hasOwnProperty;var I=(o,n)=>{for(var t in n)p(o,t,{get:n[t],enumerable:!0})},R=(o,n,t,e)=>{if(n&&typeof n=="object"||typeof n=="function")for(let r of E(n))!O.call(o,r)&&r!==t&&p(o,r,{get:()=>n[r],enumerable:!(e=A(n,r))||e.enumerable});return o};var N=o=>R(p({},"__esModule",{value:!0}),o);var q={};I(q,{getSyncProvider:()=>L});module.exports=N(q);var w="chainHead_unstable_follow",H="chainHead_unstable_unfollow",g="chainHead_unstable_followEvent",h="stop",M=new Set([h,"operationInaccessible","operationError"]),S=o=>({onSent(n){return n.method===w?{type:"subscribe",id:n.id,onRes:t=>t.id===n.id?{id:t.result}:null}:n.method===H?{type:"unsubscribe",id:Object.values(n.params)[0]}:null},onNotification(n){return n.method!==g?null:M.has(n.params.result.event)?{type:"end",id:n.params.subscription}:null},onAbort:n=>{o(JSON.stringify({jsonrpc:"2.0",method:g,params:{subscription:n,result:{event:h}}}))}});var x="transaction_unstable_submitAndWatch",D="transaction_unstable_unwatch",y="transaction_unstable_watchEvent",v="dropped",C=new Set([v,"finalized","error","invalid"]),P=o=>({onSent(n){return n.method===x?{type:"subscribe",id:n.id,onRes:t=>t.id===n.id?{id:t.result}:null}:n.method===D?{type:"unsubscribe",id:Object.values(n.params)[0]}:null},onNotification(n){return n.method!==y?null:C.has(n.params.result.event)?{type:"end",id:n.params.subscription}:null},onAbort:n=>{o(JSON.stringify({jsonrpc:"2.0",method:y,params:{subscription:n,result:{event:v}}}))}});var j=({onSent:o,onNotification:n,onAbort:t})=>{let e=new Map,r=new Set,u=()=>{e.clear(),r.clear()};return{onSent(a){let c=o(a);c&&(c.type==="subscribe"?e.set(c.id,c.onRes):r.delete(c.id))},onResponse(a){let c=e.get(a.id)?.(a);c&&(e.delete(a.id),r.add(c.id))},onNotifiaction(a){let c=n(a);c&&r.delete(c.id)},onDisconnect:u,onAbort(){let a=[...r];u(),a.forEach(t)}}},T=o=>{let n=[S,P].map(t=>j(t(o)));return{onSent(t){n.forEach(e=>{e.onSent(t)})},onResponse(t){n.forEach(e=>{e.onResponse(t)})},onNotifiaction(t){n.forEach(e=>{e.onNotifiaction(t)})},onDisconnect(){n.forEach(t=>t.onDisconnect())},onAbort(){n.forEach(t=>t.onAbort())}}};var L=o=>n=>{let t,e=[],r=new Set,u=T(n),a=i=>{let s;try{s=JSON.parse(i)}catch{console.error(`Unable to parse incoming message: ${i}`);return}s.id!==void 0?(r.delete(s.id),u.onResponse(s)):u.onNotifiaction(s),n(i)},c=i=>{if(!t)return;let s=JSON.parse(i);u.onSent(s),s.id&&r.add(s.id),t instanceof Promise?e.push(i):t.send(i)},f=()=>{e=[];let i=[...r];if(r.clear(),!t)throw null;let s=m();return u.onAbort(),i.forEach(l=>{n(JSON.stringify({jsonrpc:"2.0",error:{code:-32603,message:"Internal error"},id:l}))}),s},m=()=>{let i=s=>{let l=!1,b=s(d=>{l||a(d)},()=>{l||(l=!0,f())});return e.forEach(d=>{b.send(d)}),e=[],t=b};return t=o().then(i,J(f)),t},_=()=>{if(!t)return;let i=s=>{u.onDisconnect(),r.clear(),t=null,s?.disconnect()};t instanceof Promise?(t.then(i,i),t=null):i(t)};return m(),{send:c,disconnect:_}},J=o=>(...n)=>new Promise(t=>setTimeout(t,0)).then(()=>o(...n)); | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "@polkadot-api/json-rpc-provider-proxy", | ||
"version": "0.0.1-5f0fe49a72a058a62aaac5040bea83d67b0f32a5.1.0", | ||
"version": "0.0.1-8b1b9459bb99c052281ba0a2e0f324046e1dce80.1.0", | ||
"author": "Josep M Sobrepere (https://github.com/josepot)", | ||
@@ -43,3 +43,3 @@ "repository": { | ||
"devDependencies": { | ||
"@polkadot-api/json-rpc-provider": "0.0.1-5f0fe49a72a058a62aaac5040bea83d67b0f32a5.1.0" | ||
"@polkadot-api/json-rpc-provider": "0.0.1-8b1b9459bb99c052281ba0a2e0f324046e1dce80.1.0" | ||
}, | ||
@@ -46,0 +46,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
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
79124
1126