async-call-rpc
Advanced tools
Comparing version 6.1.3 to 6.1.4
@@ -728,21 +728,16 @@ /// <reference types="./base.d.ts" /> | ||
}; | ||
const getTrap = new Proxy( | ||
{}, | ||
{ | ||
get(_, method) { | ||
const f = { | ||
// This function will be logged to the console so it must be 1 line | ||
[method]: (..._) => call(method, _, new Error().stack), | ||
}[method ]; | ||
const f2 = { | ||
[method]: (..._) => call(method, _, new Error().stack, true), | ||
}[method ]; | ||
// @ts-expect-error | ||
f[AsyncCallNotify] = f2[AsyncCallNotify] = f2; | ||
isString(method) && Object.defineProperty(methodContainer, method, { value: f, configurable: true }); | ||
return f | ||
}, | ||
}, | ||
); | ||
const methodContainer = { __proto__: getTrap }; | ||
const getTrap = (_, method) => { | ||
const f = { | ||
// This function will be logged to the console so it must be 1 line | ||
[method]: (..._) => call(method, _, new Error().stack), | ||
}[method ]; | ||
const f2 = { | ||
[method]: (..._) => call(method, _, new Error().stack, true), | ||
}[method ]; | ||
// @ts-expect-error | ||
f[AsyncCallNotify] = f2[AsyncCallNotify] = f2; | ||
isString(method) && Object.defineProperty(methodContainer, method, { value: f, configurable: true }); | ||
return f | ||
}; | ||
const methodContainer = { __proto__: new Proxy({}, { get: getTrap }) }; | ||
if (thenable === false) methodContainer.then = undefined$1; | ||
@@ -767,3 +762,3 @@ else if (thenable === undefined$1) { | ||
getOwnPropertyDescriptor(_, method) { | ||
if (!(method in methodContainer)) (getTrap )[method]; // trigger [[Get]] | ||
if (!(method in methodContainer)) getTrap(_, method); // trigger [[Get]] | ||
return Object.getOwnPropertyDescriptor(methodContainer, method) | ||
@@ -770,0 +765,0 @@ }, |
/// <reference types="./base.min.d.ts" /> | ||
((r,e)=>{"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((r="undefined"!=typeof globalThis?globalThis:r||self).AsyncCall={})})(this,(function(r){"use strict";class e extends Error{constructor(r,e,t,n){super(e),this.name=r,this.code=t,this.stack=n}}const t={},n={},o=[{},{},t,n];function s(r,e){const t=o.indexOf(r);return e.message+=`Error ${t}: https://github.com/Jack-Works/async-call-rpc/wiki/Errors#`+t,e}const a={__proto__:null,Error,EvalError,RangeError,ReferenceError,SyntaxError,TypeError,URIError},i="DOMException:",c=r=>(r+"").replace(/^.+\n.+\n/,""),l=()=>{try{return DOMException}catch(r){}},u=r=>"string"==typeof r,f=r=>"boolean"==typeof r,d=r=>"function"==typeof r,p=r=>"object"==typeof r&&null!==r,y="Error",h=void 0,g=Array.isArray,m=()=>"() => replay()",E="2.0",b=(r,e,t,n)=>{r===h&&(r=null),Number.isNaN(e=Math.floor(e))&&(e=-1);const o={jsonrpc:E,id:r,error:{code:e,message:t,data:n}};return O(o.error,"data"),o},w=(r,e,t)=>{const{id:n}=r,{code:o,message:s,data:a}=t(e,r);return b(n,o,s,a)},k=(r="",e=-1)=>t=>{let n=S("",(()=>t.message)),o=S(y,((r=t.constructor)=>d(r)&&r.name));const s=l();return s&&t instanceof s&&(o=i+t.name),(u(t)||"number"==typeof t||f(t)||"bigint"==typeof t)&&(o=y,n=t+""),{code:e,message:n,data:r?{stack:r,type:o}:{type:o}}},P=r=>{if(!p(r))return!1;if(!$(r,"jsonrpc"))return!1;if(r.jsonrpc!==E)return!1;if($(r,"params")){const e=r.params;if(!g(e)&&!p(e))return!1}return!0},$=(r,e)=>e in r,S=(r,e)=>{try{const t=e();return t===h?r:t+""}catch(e){return r}},O=(r,e)=>{r[e]===h&&delete r[e]},v={serialization:r=>r,deserialization:r=>r},x="AsyncCall/",_=Symbol.for(x+"ignored"),j=Symbol.for(x+"notify"),z=Symbol.for(x+"batch"),M=(r,e)=>r[e][j],N=()=>Math.random().toString(36).slice(2),R=r=>void 0===r||r;r.AsyncCall=(r,o)=>{let S=!0,x=h,M=h;const A=async()=>{try{x=await r}catch(r){M=r,er("AsyncCall failed to start",r)}finally{S=!1}},{serializer:C=v,key:T="rpc",strict:W=!0,log:D=!0,parameterStructures:I="by-position",preferLocalImplementation:J=!1,idGenerator:q=N,mapError:F,logger:L,channel:U,thenable:G}=o;r instanceof Promise?A():(x=r,S=!1);const[B,H]=(r=>{if(!f(r)){const{methodNotFound:e,unknownMessage:t}=r;return[e,t]}return[r,r]})(W),[K,Q,V,X,Y,Z]=(r=>{if("all"===r)return[!0,!0,!0,!0,!0,!0];if(!f(r)){const{beCalled:e,localError:t,remoteError:n,type:o,requestReplay:s,sendLocalStack:a}=r;return[R(e),R(t),R(n),"basic"!==o,s,a]}return r?[!0,!0,!0,!0]:[]})(D),{log:rr,error:er=rr,debug:tr=rr,groupCollapsed:nr=rr,groupEnd:or=rr,warn:sr=rr}=L||console,ar=new Map,ir=async r=>{let e;try{if(e=await ur(r),P(e))return await yr(e);if(g(e)&&e.every(P)&&0!==e.length)return Promise.all(e.map(yr));if(H){let r=e.id;return r===h&&(r=null),(r=>b(r,-32600,"Invalid Request"))(r)}return h}catch(r){return Q&&er(r,e,void 0),((r,e)=>{const t=w({},r,e),n=t.error;return n.code=-32700,n.message="Parse error",t})(r,F||k(r&&r.stack))}},cr=async r=>{if(r){if(g(r)){const e=r.filter((r=>r&&$(r,"id")));if(0===e.length)return;return lr(e)}return lr(r)}},lr=r=>C.serialization(r),ur=r=>C.deserialization(r);var fr;if($(fr=U,"setup")&&d(fr.setup)&&U.setup((r=>ir(r).then(cr)),(r=>{const e=ur(r);return!!P(e)||(r=>Promise.resolve(r))(e).then(P)})),(r=>$(r,"send")&&d(r.send))(U)){const r=U;r.on&&r.on((e=>ir(e).then(cr).then((e=>e&&r.send(e)))))}function dr(r,e,t){return p(r)&&$(r,"stack")&&(r.stack=e.split("\n").reduce(((r,e)=>r.replace(e+"\n","")),""+r.stack)),Q&&er(r),w(t,r,F||k(Z?r.stack:h))}async function pr(r,e=!1){e&&(r=[...r]);const t=await lr(r);return U.send(t)}const yr=async r=>{if($(r,"method")){const e=(async r=>{if(S)await A();else if(M)return dr(M,"",r);let e="";try{const{params:t,method:n,id:o,remoteStack:s}=r,a=n.startsWith("rpc.")?Symbol.for(n):n,i=x&&x[a];if(!d(i))return B?b(o,-32601,"Method not found"):void(Q&&tr("Missing method",a,r));const l=g(t)?t:[t];e=c(Error().stack);const u=new Promise((r=>r(i.apply(x,l))));if(K)if(X){const r=[`${T}.%c${n}%c(${l.map((()=>"%o")).join(", ")}%c)\n%o %c@${o}`,"color: #d2c057","",...l,"",u,"color: gray; font-style: italic;"];if(Y){const e=()=>{debugger;return i.apply(x,l)};e.toString=m,r.push(e)}s?(nr(...r),rr(s),or()):rr(...r)}else rr(`${T}.${n}(${""+[...l]}) @${o}`);if(await u===_)return;return((r,e)=>{const t={jsonrpc:E,id:r,result:e};return O(t,"id"),t})(o,await u)}catch(t){return dr(t,e,r)}})(r);if($(r,"id"))return e;try{await e}catch(r){}return h}return(async r=>{let t="",n="",o=0,s=y;if($(r,"error")){const e=r.error;t=e.message,o=e.code;const a=e.data;n=p(a)&&$(a,"stack")&&u(a.stack)?a.stack:"<remote stack not available>",s=p(a)&&$(a,"type")&&u(a.type)?a.type:y,V&&(X?er(`${s}: ${t}(${o}) %c@${r.id}\n%c${n}`,"color: gray",""):er(`${s}: ${t}(${o}) @${r.id}\n${n}`))}if(null===r.id||r.id===h)return;const{f:[c,f]=[null,null],stack:d=""}=ar.get(r.id)||{};c&&f&&(ar.delete(r.id),$(r,"error")?f(((r,t,n,o)=>{try{const s=l();if(r.startsWith(i)&&s)return new s(t,r.slice(13));if(r in a){const e=new a[r](t);return e.stack=o,e.code=n,e}return new e(r,t,n,o)}catch(e){return Error(`E${n} ${r}: ${t}\n${o}`)}})(s,t,o,n+"\n аt AsyncCall (rpc) \n"+d)):c(r.result))})(r)},hr=(r,e,n,o=!1)=>new Promise(((a,i)=>{let l=h;if(r===z&&(l=e.shift(),r=e.shift()),"symbol"==typeof r){const e=Symbol.keyFor(r)||r.description;if(e){if(!e.startsWith("rpc."))throw new TypeError("Not start with rpc.");r=e}}else if(r.startsWith("rpc."))throw s(t,new TypeError);if(J&&!S&&u(r)){const t=x&&x[r];if(d(t))return a(t(...e))}const f=q();n=c(n);const y="by-name"===I&&1===e.length&&p(e[0])?e[0]:e,g=((r,e,t,n)=>{const o={jsonrpc:E,id:r,method:e,params:t,remoteStack:n};return O(o,"id"),((r,e)=>{r[e]||delete r[e]})(o,"remoteStack"),o})(o?h:f,r,y,Z?n:h);if(l?(l.push(g),l.r||(l.r=[()=>pr(l,!0),r=>((r,e)=>{for(const t of r)if($(t,"id")){const r=ar.get(t.id);r&&r.f[1](e)}})(l,r)])):pr(g).catch(i),o)return a();ar.set(f,{f:[a,i],stack:n})})),gr={__proto__:new Proxy({},{get(r,e){const t={[e]:(...r)=>hr(e,r,Error().stack)}[e],n={[e]:(...r)=>hr(e,r,Error().stack,!0)}[e];return t[j]=n[j]=n,u(e)&&Object.defineProperty(gr,e,{value:t,configurable:!0}),t}})};return!1===G?gr.then=h:G===h&&Object.defineProperty(gr,"then",{configurable:!0,get(){sr(s(n,new TypeError("RPC used as Promise: ")))}}),new Proxy(gr,{getPrototypeOf:()=>null,setPrototypeOf:(r,e)=>null===e,getOwnPropertyDescriptor:(r,e)=>Object.getOwnPropertyDescriptor(gr,e)})},r.JSONSerialization=(r=[h,h],e,t="null")=>({serialization(n){if(t&&p(n)&&$(n,"result")&&n.result===h){const r={...n};r.result=null,"keep"===t&&(r.undef=!0),n=r}return JSON.stringify(n,r[0],e)},deserialization(e){const t=JSON.parse(e,r[1]);return p(t)&&$(t,"result")&&null===t.result&&$(t,"undef")&&!0===t.undef&&(t.result=h,delete t.undef),t}}),r.NoSerialization=v,r.batch=r=>{const e=[],t={__proto__:new Proxy({},{get(n,o){const s=(...t)=>r[z](e,o,...t);return(s[j]=(...t)=>r[z][j](e,o,...t))[j]=s[j],u(o)&&Object.defineProperty(t,o,{value:s,configurable:!0}),s}})};return[new Proxy(t,{getPrototypeOf:()=>null,setPrototypeOf:(r,e)=>null===e}),()=>{e.length&&e.r[0](),e.length=0},(r=Error("Aborted"))=>{e.length&&e.r[1](r),e.length=0}]},r.notify=r=>d(r)?r[j]:new Proxy(r,{get:M}),Object.defineProperty(r,"__esModule",{value:!0})})); | ||
((r,e)=>{"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((r="undefined"!=typeof globalThis?globalThis:r||self).AsyncCall={})})(this,(function(r){"use strict";class e extends Error{constructor(r,e,t,n){super(e),this.name=r,this.code=t,this.stack=n}}const t={},n={},o=[{},{},t,n];function s(r,e){const t=o.indexOf(r);return e.message+=`Error ${t}: https://github.com/Jack-Works/async-call-rpc/wiki/Errors#`+t,e}const a={__proto__:null,Error,EvalError,RangeError,ReferenceError,SyntaxError,TypeError,URIError},i="DOMException:",c=r=>(r+"").replace(/^.+\n.+\n/,""),l=()=>{try{return DOMException}catch(r){}},u=r=>"string"==typeof r,f=r=>"boolean"==typeof r,d=r=>"function"==typeof r,p=r=>"object"==typeof r&&null!==r,y="Error",h=void 0,g=Array.isArray,m=()=>"() => replay()",E="2.0",b=(r,e,t,n)=>{r===h&&(r=null),Number.isNaN(e=Math.floor(e))&&(e=-1);const o={jsonrpc:E,id:r,error:{code:e,message:t,data:n}};return O(o.error,"data"),o},w=(r,e,t)=>{const{id:n}=r,{code:o,message:s,data:a}=t(e,r);return b(n,o,s,a)},k=(r="",e=-1)=>t=>{let n=S("",(()=>t.message)),o=S(y,((r=t.constructor)=>d(r)&&r.name));const s=l();return s&&t instanceof s&&(o=i+t.name),(u(t)||"number"==typeof t||f(t)||"bigint"==typeof t)&&(o=y,n=t+""),{code:e,message:n,data:r?{stack:r,type:o}:{type:o}}},P=r=>{if(!p(r))return!1;if(!$(r,"jsonrpc"))return!1;if(r.jsonrpc!==E)return!1;if($(r,"params")){const e=r.params;if(!g(e)&&!p(e))return!1}return!0},$=(r,e)=>e in r,S=(r,e)=>{try{const t=e();return t===h?r:t+""}catch(e){return r}},O=(r,e)=>{r[e]===h&&delete r[e]},v={serialization:r=>r,deserialization:r=>r},x="AsyncCall/",_=Symbol.for(x+"ignored"),j=Symbol.for(x+"notify"),z=Symbol.for(x+"batch"),M=(r,e)=>r[e][j],N=()=>Math.random().toString(36).slice(2),R=r=>void 0===r||r;r.AsyncCall=(r,o)=>{let S=!0,x=h,M=h;const A=async()=>{try{x=await r}catch(r){M=r,er("AsyncCall failed to start",r)}finally{S=!1}},{serializer:C=v,key:T="rpc",strict:W=!0,log:D=!0,parameterStructures:I="by-position",preferLocalImplementation:J=!1,idGenerator:q=N,mapError:F,logger:L,channel:U,thenable:G}=o;r instanceof Promise?A():(x=r,S=!1);const[B,H]=(r=>{if(!f(r)){const{methodNotFound:e,unknownMessage:t}=r;return[e,t]}return[r,r]})(W),[K,Q,V,X,Y,Z]=(r=>{if("all"===r)return[!0,!0,!0,!0,!0,!0];if(!f(r)){const{beCalled:e,localError:t,remoteError:n,type:o,requestReplay:s,sendLocalStack:a}=r;return[R(e),R(t),R(n),"basic"!==o,s,a]}return r?[!0,!0,!0,!0]:[]})(D),{log:rr,error:er=rr,debug:tr=rr,groupCollapsed:nr=rr,groupEnd:or=rr,warn:sr=rr}=L||console,ar=new Map,ir=async r=>{let e;try{if(e=await ur(r),P(e))return await yr(e);if(g(e)&&e.every(P)&&0!==e.length)return Promise.all(e.map(yr));if(H){let r=e.id;return r===h&&(r=null),(r=>b(r,-32600,"Invalid Request"))(r)}return h}catch(r){return Q&&er(r,e,void 0),((r,e)=>{const t=w({},r,e),n=t.error;return n.code=-32700,n.message="Parse error",t})(r,F||k(r&&r.stack))}},cr=async r=>{if(r){if(g(r)){const e=r.filter((r=>r&&$(r,"id")));if(0===e.length)return;return lr(e)}return lr(r)}},lr=r=>C.serialization(r),ur=r=>C.deserialization(r);var fr;if($(fr=U,"setup")&&d(fr.setup)&&U.setup((r=>ir(r).then(cr)),(r=>{const e=ur(r);return!!P(e)||(r=>Promise.resolve(r))(e).then(P)})),(r=>$(r,"send")&&d(r.send))(U)){const r=U;r.on&&r.on((e=>ir(e).then(cr).then((e=>e&&r.send(e)))))}function dr(r,e,t){return p(r)&&$(r,"stack")&&(r.stack=e.split("\n").reduce(((r,e)=>r.replace(e+"\n","")),""+r.stack)),Q&&er(r),w(t,r,F||k(Z?r.stack:h))}async function pr(r,e=!1){e&&(r=[...r]);const t=await lr(r);return U.send(t)}const yr=async r=>{if($(r,"method")){const e=(async r=>{if(S)await A();else if(M)return dr(M,"",r);let e="";try{const{params:t,method:n,id:o,remoteStack:s}=r,a=n.startsWith("rpc.")?Symbol.for(n):n,i=x&&x[a];if(!d(i))return B?b(o,-32601,"Method not found"):void(Q&&tr("Missing method",a,r));const l=g(t)?t:[t];e=c(Error().stack);const u=new Promise((r=>r(i.apply(x,l))));if(K)if(X){const r=[`${T}.%c${n}%c(${l.map((()=>"%o")).join(", ")}%c)\n%o %c@${o}`,"color: #d2c057","",...l,"",u,"color: gray; font-style: italic;"];if(Y){const e=()=>{debugger;return i.apply(x,l)};e.toString=m,r.push(e)}s?(nr(...r),rr(s),or()):rr(...r)}else rr(`${T}.${n}(${""+[...l]}) @${o}`);if(await u===_)return;return((r,e)=>{const t={jsonrpc:E,id:r,result:e};return O(t,"id"),t})(o,await u)}catch(t){return dr(t,e,r)}})(r);if($(r,"id"))return e;try{await e}catch(r){}return h}return(async r=>{let t="",n="",o=0,s=y;if($(r,"error")){const e=r.error;t=e.message,o=e.code;const a=e.data;n=p(a)&&$(a,"stack")&&u(a.stack)?a.stack:"<remote stack not available>",s=p(a)&&$(a,"type")&&u(a.type)?a.type:y,V&&(X?er(`${s}: ${t}(${o}) %c@${r.id}\n%c${n}`,"color: gray",""):er(`${s}: ${t}(${o}) @${r.id}\n${n}`))}if(null===r.id||r.id===h)return;const{f:[c,f]=[null,null],stack:d=""}=ar.get(r.id)||{};c&&f&&(ar.delete(r.id),$(r,"error")?f(((r,t,n,o)=>{try{const s=l();if(r.startsWith(i)&&s)return new s(t,r.slice(13));if(r in a){const e=new a[r](t);return e.stack=o,e.code=n,e}return new e(r,t,n,o)}catch(e){return Error(`E${n} ${r}: ${t}\n${o}`)}})(s,t,o,n+"\n аt AsyncCall (rpc) \n"+d)):c(r.result))})(r)},hr=(r,e,n,o=!1)=>new Promise(((a,i)=>{let l=h;if(r===z&&(l=e.shift(),r=e.shift()),"symbol"==typeof r){const e=Symbol.keyFor(r)||r.description;if(e){if(!e.startsWith("rpc."))throw new TypeError("Not start with rpc.");r=e}}else if(r.startsWith("rpc."))throw s(t,new TypeError);if(J&&!S&&u(r)){const t=x&&x[r];if(d(t))return a(t(...e))}const f=q();n=c(n);const y="by-name"===I&&1===e.length&&p(e[0])?e[0]:e,g=((r,e,t,n)=>{const o={jsonrpc:E,id:r,method:e,params:t,remoteStack:n};return O(o,"id"),((r,e)=>{r[e]||delete r[e]})(o,"remoteStack"),o})(o?h:f,r,y,Z?n:h);if(l?(l.push(g),l.r||(l.r=[()=>pr(l,!0),r=>((r,e)=>{for(const t of r)if($(t,"id")){const r=ar.get(t.id);r&&r.f[1](e)}})(l,r)])):pr(g).catch(i),o)return a();ar.set(f,{f:[a,i],stack:n})})),gr=(r,e)=>{const t={[e]:(...r)=>hr(e,r,Error().stack)}[e],n={[e]:(...r)=>hr(e,r,Error().stack,!0)}[e];return t[j]=n[j]=n,u(e)&&Object.defineProperty(mr,e,{value:t,configurable:!0}),t},mr={__proto__:new Proxy({},{get:gr})};return!1===G?mr.then=h:G===h&&Object.defineProperty(mr,"then",{configurable:!0,get(){sr(s(n,new TypeError("RPC used as Promise: ")))}}),new Proxy(mr,{getPrototypeOf:()=>null,setPrototypeOf:(r,e)=>null===e,getOwnPropertyDescriptor:(r,e)=>(e in mr||gr(0,e),Object.getOwnPropertyDescriptor(mr,e))})},r.JSONSerialization=(r=[h,h],e,t="null")=>({serialization(n){if(t&&p(n)&&$(n,"result")&&n.result===h){const r={...n};r.result=null,"keep"===t&&(r.undef=!0),n=r}return JSON.stringify(n,r[0],e)},deserialization(e){const t=JSON.parse(e,r[1]);return p(t)&&$(t,"result")&&null===t.result&&$(t,"undef")&&!0===t.undef&&(t.result=h,delete t.undef),t}}),r.NoSerialization=v,r.batch=r=>{const e=[],t={__proto__:new Proxy({},{get(n,o){const s=(...t)=>r[z](e,o,...t);return(s[j]=(...t)=>r[z][j](e,o,...t))[j]=s[j],u(o)&&Object.defineProperty(t,o,{value:s,configurable:!0}),s}})};return[new Proxy(t,{getPrototypeOf:()=>null,setPrototypeOf:(r,e)=>null===e}),()=>{e.length&&e.r[0](),e.length=0},(r=Error("Aborted"))=>{e.length&&e.r[1](r),e.length=0}]},r.notify=r=>d(r)?r[j]:new Proxy(r,{get:M}),Object.defineProperty(r,"__esModule",{value:!0})})); | ||
//# sourceMappingURL=base.min.js.map |
@@ -729,21 +729,16 @@ /// <reference types="./full.d.ts" /> | ||
}; | ||
const getTrap = new Proxy( | ||
{}, | ||
{ | ||
get(_, method) { | ||
const f = { | ||
// This function will be logged to the console so it must be 1 line | ||
[method]: (..._) => call(method, _, new Error().stack), | ||
}[method ]; | ||
const f2 = { | ||
[method]: (..._) => call(method, _, new Error().stack, true), | ||
}[method ]; | ||
// @ts-expect-error | ||
f[AsyncCallNotify] = f2[AsyncCallNotify] = f2; | ||
isString(method) && Object.defineProperty(methodContainer, method, { value: f, configurable: true }); | ||
return f | ||
}, | ||
}, | ||
); | ||
const methodContainer = { __proto__: getTrap }; | ||
const getTrap = (_, method) => { | ||
const f = { | ||
// This function will be logged to the console so it must be 1 line | ||
[method]: (..._) => call(method, _, new Error().stack), | ||
}[method ]; | ||
const f2 = { | ||
[method]: (..._) => call(method, _, new Error().stack, true), | ||
}[method ]; | ||
// @ts-expect-error | ||
f[AsyncCallNotify] = f2[AsyncCallNotify] = f2; | ||
isString(method) && Object.defineProperty(methodContainer, method, { value: f, configurable: true }); | ||
return f | ||
}; | ||
const methodContainer = { __proto__: new Proxy({}, { get: getTrap }) }; | ||
if (thenable === false) methodContainer.then = undefined$1; | ||
@@ -768,3 +763,3 @@ else if (thenable === undefined$1) { | ||
getOwnPropertyDescriptor(_, method) { | ||
if (!(method in methodContainer)) (getTrap )[method]; // trigger [[Get]] | ||
if (!(method in methodContainer)) getTrap(_, method); // trigger [[Get]] | ||
return Object.getOwnPropertyDescriptor(methodContainer, method) | ||
@@ -920,20 +915,14 @@ }, | ||
const getTrap = new Proxy( | ||
{}, | ||
{ | ||
get(_, method) { | ||
if (!isString(method)) | ||
throw makeHostedMessage(Err_Only_string_can_be_the_RPC_method_name, new TypeError('')) | ||
const f = { | ||
[method]: (..._) => { | ||
const id = remote[AsyncIteratorStart](method, _); | ||
return new _AsyncGenerator(remote, id) | ||
}, | ||
}[method]; | ||
Object.defineProperty(methodContainer, method, { value: f, configurable: true }); | ||
return f | ||
const getTrap = (_, method) => { | ||
if (!isString(method)) throw makeHostedMessage(Err_Only_string_can_be_the_RPC_method_name, new TypeError('')) | ||
const f = { | ||
[method]: (..._) => { | ||
const id = remote[AsyncIteratorStart](method, _); | ||
return new _AsyncGenerator(remote, id) | ||
}, | ||
}, | ||
); | ||
const methodContainer = { __proto__: getTrap }; | ||
}[method]; | ||
Object.defineProperty(methodContainer, method, { value: f, configurable: true }); | ||
return f | ||
}; | ||
const methodContainer = { __proto__: new Proxy({}, { get: getTrap }) }; | ||
return new Proxy(methodContainer, { | ||
@@ -944,3 +933,3 @@ getPrototypeOf: () => null, | ||
getOwnPropertyDescriptor(_, method) { | ||
if (!(method in methodContainer)) (getTrap )[method]; // trigger [[Get]] | ||
if (!(method in methodContainer)) getTrap(_, method); // trigger [[Get]] | ||
return Object.getOwnPropertyDescriptor(methodContainer, method) | ||
@@ -947,0 +936,0 @@ }, |
/// <reference types="./full.min.d.ts" /> | ||
((r,t)=>{"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((r="undefined"!=typeof globalThis?globalThis:r||self).AsyncCall={})})(this,(function(r){"use strict";class t extends Error{constructor(r,t,e,n){super(t),this.name=r,this.code=e,this.stack=n}}const e={},n={},o={},s={},i=[e,n,o,s];function c(r,t){const e=i.indexOf(r);return t.message+=`Error ${e}: https://github.com/Jack-Works/async-call-rpc/wiki/Errors#`+e,t}const a={__proto__:null,Error,EvalError,RangeError,ReferenceError,SyntaxError,TypeError,URIError},l="DOMException:",u=r=>(r+"").replace(/^.+\n.+\n/,""),f=()=>{try{return DOMException}catch(r){}},y=r=>"string"==typeof r,p=r=>"boolean"==typeof r,d=r=>"function"==typeof r,h=r=>"object"==typeof r&&null!==r,g="Error",m=void 0,w=Object.setPrototypeOf,b=Array.isArray,E=()=>"() => replay()",P="2.0",k=(r,t,e,n)=>{r===m&&(r=null),Number.isNaN(t=Math.floor(t))&&(t=-1);const o={jsonrpc:P,id:r,error:{code:t,message:e,data:n}};return j(o.error,"data"),o},O=(r,t,e)=>{const{id:n}=r,{code:o,message:s,data:i}=e(t,r);return k(n,o,s,i)},_=(r="",t=-1)=>e=>{let n=x("",(()=>e.message)),o=x(g,((r=e.constructor)=>d(r)&&r.name));const s=f();return s&&e instanceof s&&(o=l+e.name),(y(e)||"number"==typeof e||p(e)||"bigint"==typeof e)&&(o=g,n=e+""),{code:t,message:n,data:r?{stack:r,type:o}:{type:o}}},$=r=>{if(!h(r))return!1;if(!S(r,"jsonrpc"))return!1;if(r.jsonrpc!==P)return!1;if(S(r,"params")){const t=r.params;if(!b(t)&&!h(t))return!1}return!0},S=(r,t)=>t in r,x=(r,t)=>{try{const e=t();return e===m?r:e+""}catch(t){return r}},j=(r,t)=>{r[t]===m&&delete r[t]},v={serialization:r=>r,deserialization:r=>r},M="AsyncCall/",z=Symbol.for(M+"ignored"),A=Symbol.for(M+"notify"),C=Symbol.for(M+"batch"),N=(r,t)=>r[t][A],R=()=>Math.random().toString(36).slice(2),T=r=>void 0===r||r,D=r=>{if(!p(r)){const{methodNotFound:t,unknownMessage:e}=r;return[t,e]}return[r,r]};function I(r,e){let n=!0,i=m,w=m;const x=async()=>{try{i=await r}catch(r){w=r,er("AsyncCall failed to start",r)}finally{n=!1}},{serializer:M=v,key:N="rpc",strict:I=!0,log:W=!0,parameterStructures:J="by-position",preferLocalImplementation:G=!1,idGenerator:q=R,mapError:F,logger:L,channel:U,thenable:B}=e;r instanceof Promise?x():(i=r,n=!1);const[H,K]=D(I),[Q,V,X,Y,Z,rr]=(r=>{if("all"===r)return[!0,!0,!0,!0,!0,!0];if(!p(r)){const{beCalled:t,localError:e,remoteError:n,type:o,requestReplay:s,sendLocalStack:i}=r;return[T(t),T(e),T(n),"basic"!==o,s,i]}return r?[!0,!0,!0,!0]:[]})(W),{log:tr,error:er=tr,debug:nr=tr,groupCollapsed:or=tr,groupEnd:sr=tr,warn:ir=tr}=L||console,cr=new Map,ar=async r=>{let t;try{if(t=await fr(r),$(t))return await hr(t);if(b(t)&&t.every($)&&0!==t.length)return Promise.all(t.map(hr));if(K){let r=t.id;return r===m&&(r=null),(r=>k(r,-32600,"Invalid Request"))(r)}return m}catch(r){return V&&er(r,t,void 0),((r,t)=>{const e=O({},r,t),n=e.error;return n.code=-32700,n.message="Parse error",e})(r,F||_(r&&r.stack))}},lr=async r=>{if(r){if(b(r)){const t=r.filter((r=>r&&S(r,"id")));if(0===t.length)return;return ur(t)}return ur(r)}},ur=r=>M.serialization(r),fr=r=>M.deserialization(r);var yr;if(S(yr=U,"setup")&&d(yr.setup)&&U.setup((r=>ar(r).then(lr)),(r=>{const t=fr(r);return!!$(t)||(r=>Promise.resolve(r))(t).then($)})),(r=>S(r,"send")&&d(r.send))(U)){const r=U;r.on&&r.on((t=>ar(t).then(lr).then((t=>t&&r.send(t)))))}function pr(r,t,e){return h(r)&&S(r,"stack")&&(r.stack=t.split("\n").reduce(((r,t)=>r.replace(t+"\n","")),""+r.stack)),V&&er(r),O(e,r,F||_(rr?r.stack:m))}async function dr(r,t=!1){t&&(r=[...r]);const e=await ur(r);return U.send(e)}const hr=async r=>{if(S(r,"method")){const t=(async r=>{if(n)await x();else if(w)return pr(w,"",r);let t="";try{const{params:e,method:n,id:o,remoteStack:s}=r,c=n.startsWith("rpc.")?Symbol.for(n):n,a=i&&i[c];if(!d(a))return H?k(o,-32601,"Method not found"):void(V&&nr("Missing method",c,r));const l=b(e)?e:[e];t=u(Error().stack);const f=new Promise((r=>r(a.apply(i,l))));if(Q)if(Y){const r=[`${N}.%c${n}%c(${l.map((()=>"%o")).join(", ")}%c)\n%o %c@${o}`,"color: #d2c057","",...l,"",f,"color: gray; font-style: italic;"];if(Z){const t=()=>{debugger;return a.apply(i,l)};t.toString=E,r.push(t)}s?(or(...r),tr(s),sr()):tr(...r)}else tr(`${N}.${n}(${""+[...l]}) @${o}`);if(await f===z)return;return((r,t)=>{const e={jsonrpc:P,id:r,result:t};return j(e,"id"),e})(o,await f)}catch(e){return pr(e,t,r)}})(r);if(S(r,"id"))return t;try{await t}catch(r){}return m}return(async r=>{let e="",n="",o=0,s=g;if(S(r,"error")){const t=r.error;e=t.message,o=t.code;const i=t.data;n=h(i)&&S(i,"stack")&&y(i.stack)?i.stack:"<remote stack not available>",s=h(i)&&S(i,"type")&&y(i.type)?i.type:g,X&&(Y?er(`${s}: ${e}(${o}) %c@${r.id}\n%c${n}`,"color: gray",""):er(`${s}: ${e}(${o}) @${r.id}\n${n}`))}if(null===r.id||r.id===m)return;const{f:[i,c]=[null,null],stack:u=""}=cr.get(r.id)||{};i&&c&&(cr.delete(r.id),S(r,"error")?c(((r,e,n,o)=>{try{const s=f();if(r.startsWith(l)&&s)return new s(e,r.slice(13));if(r in a){const t=new a[r](e);return t.stack=o,t.code=n,t}return new t(r,e,n,o)}catch(t){return Error(`E${n} ${r}: ${e}\n${o}`)}})(s,e,o,n+"\n аt AsyncCall (rpc) \n"+u)):i(r.result))})(r)},gr=(r,t,e,s=!1)=>new Promise(((a,l)=>{let f=m;if(r===C&&(f=t.shift(),r=t.shift()),"symbol"==typeof r){const t=Symbol.keyFor(r)||r.description;if(t){if(!t.startsWith("rpc."))throw new TypeError("Not start with rpc.");r=t}}else if(r.startsWith("rpc."))throw c(o,new TypeError);if(G&&!n&&y(r)){const e=i&&i[r];if(d(e))return a(e(...t))}const p=q();e=u(e);const g="by-name"===J&&1===t.length&&h(t[0])?t[0]:t,w=((r,t,e,n)=>{const o={jsonrpc:P,id:r,method:t,params:e,remoteStack:n};return j(o,"id"),((r,t)=>{r[t]||delete r[t]})(o,"remoteStack"),o})(s?m:p,r,g,rr?e:m);if(f?(f.push(w),f.r||(f.r=[()=>dr(f,!0),r=>((r,t)=>{for(const e of r)if(S(e,"id")){const r=cr.get(e.id);r&&r.f[1](t)}})(f,r)])):dr(w).catch(l),s)return a();cr.set(p,{f:[a,l],stack:e})})),mr={__proto__:new Proxy({},{get(r,t){const e={[t]:(...r)=>gr(t,r,Error().stack)}[t],n={[t]:(...r)=>gr(t,r,Error().stack,!0)}[t];return e[A]=n[A]=n,y(t)&&Object.defineProperty(mr,t,{value:e,configurable:!0}),e}})};return!1===B?mr.then=m:B===m&&Object.defineProperty(mr,"then",{configurable:!0,get(){ir(c(s,new TypeError("RPC used as Promise: ")))}}),new Proxy(mr,{getPrototypeOf:()=>null,setPrototypeOf:(r,t)=>null===t,getOwnPropertyDescriptor:(r,t)=>Object.getOwnPropertyDescriptor(mr,t)})}const W="rpc.async-iterator.",J=Symbol.for(W+"start"),G=Symbol.for(W+"next"),q=Symbol.for(W+"return"),F=Symbol.for(W+"throw");class L{__init(){this.d=!1}__init2(){this.c=async r=>(await H(r,(()=>this.d=!0)),r)}constructor(r,t){this.r=r,this.i=t,L.prototype.__init.call(this),L.prototype.__init2.call(this)}async return(r){return this.d?K(!0,r):this.c(this.r[q](await this.i,r))}async next(r){return this.d?K(!0):this.c(this.r[G](await this.i,r))}async throw(r){if(!this.d)return this.c(this.r[F](await this.i,r));throw r}}const U=async function*(){};w(L,U.constructor.prototype);const B=Object.getPrototypeOf(U());w(L.prototype,B);const H=async(r,t)=>{try{const e=await r;e&&e.done&&t()}catch(r){}},K=(r,t)=>({done:r,value:t});r.AsyncCall=I,r.AsyncGeneratorCall=(r,t)=>{const o=new Map,[s]=D(null==(i=t.strict)||i);var i;const{idGenerator:a=R}=t,l=(r,t)=>{const n=o.get(r);if(!n){if(s)throw c(e,Error(`Iterator ${r}, `));return z}const i=t(n);return H(i,(()=>o.delete(r))),i},u=I({async[J](t,e){const n=(await r)[t];if(!d(n)){if(s)throw new TypeError(t+" is not a function");return z}const i=n(...e),c=a();return o.set(c,i),c},[G]:(r,t)=>l(r,(r=>r.next(t))),[q]:(r,t)=>l(r,(r=>d(r.return)&&r.return(t))),[F]:(r,t)=>l(r,(r=>d(r.throw)&&r.throw(t)))},t),f={__proto__:new Proxy({},{get(r,t){if(!y(t))throw c(n,new TypeError(""));const e={[t]:(...r)=>{const e=u[J](t,r);return new L(u,e)}}[t];return Object.defineProperty(f,t,{value:e,configurable:!0}),e}})};return new Proxy(f,{getPrototypeOf:()=>null,setPrototypeOf:(r,t)=>null===t,getOwnPropertyDescriptor:(r,t)=>Object.getOwnPropertyDescriptor(f,t)})},r.JSONSerialization=(r=[m,m],t,e="null")=>({serialization(n){if(e&&h(n)&&S(n,"result")&&n.result===m){const r={...n};r.result=null,"keep"===e&&(r.undef=!0),n=r}return JSON.stringify(n,r[0],t)},deserialization(t){const e=JSON.parse(t,r[1]);return h(e)&&S(e,"result")&&null===e.result&&S(e,"undef")&&!0===e.undef&&(e.result=m,delete e.undef),e}}),r.NoSerialization=v,r.batch=r=>{const t=[],e={__proto__:new Proxy({},{get(n,o){const s=(...e)=>r[C](t,o,...e);return(s[A]=(...e)=>r[C][A](t,o,...e))[A]=s[A],y(o)&&Object.defineProperty(e,o,{value:s,configurable:!0}),s}})};return[new Proxy(e,{getPrototypeOf:()=>null,setPrototypeOf:(r,t)=>null===t}),()=>{t.length&&t.r[0](),t.length=0},(r=Error("Aborted"))=>{t.length&&t.r[1](r),t.length=0}]},r.notify=r=>d(r)?r[A]:new Proxy(r,{get:N}),Object.defineProperty(r,"__esModule",{value:!0})})); | ||
((r,t)=>{"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((r="undefined"!=typeof globalThis?globalThis:r||self).AsyncCall={})})(this,(function(r){"use strict";class t extends Error{constructor(r,t,e,n){super(t),this.name=r,this.code=e,this.stack=n}}const e={},n={},o={},s={},i=[e,n,o,s];function c(r,t){const e=i.indexOf(r);return t.message+=`Error ${e}: https://github.com/Jack-Works/async-call-rpc/wiki/Errors#`+e,t}const a={__proto__:null,Error,EvalError,RangeError,ReferenceError,SyntaxError,TypeError,URIError},l="DOMException:",u=r=>(r+"").replace(/^.+\n.+\n/,""),f=()=>{try{return DOMException}catch(r){}},y=r=>"string"==typeof r,p=r=>"boolean"==typeof r,d=r=>"function"==typeof r,h=r=>"object"==typeof r&&null!==r,g="Error",m=void 0,w=Object.setPrototypeOf,b=Array.isArray,E=()=>"() => replay()",P="2.0",k=(r,t,e,n)=>{r===m&&(r=null),Number.isNaN(t=Math.floor(t))&&(t=-1);const o={jsonrpc:P,id:r,error:{code:t,message:e,data:n}};return j(o.error,"data"),o},O=(r,t,e)=>{const{id:n}=r,{code:o,message:s,data:i}=e(t,r);return k(n,o,s,i)},_=(r="",t=-1)=>e=>{let n=x("",(()=>e.message)),o=x(g,((r=e.constructor)=>d(r)&&r.name));const s=f();return s&&e instanceof s&&(o=l+e.name),(y(e)||"number"==typeof e||p(e)||"bigint"==typeof e)&&(o=g,n=e+""),{code:t,message:n,data:r?{stack:r,type:o}:{type:o}}},$=r=>{if(!h(r))return!1;if(!S(r,"jsonrpc"))return!1;if(r.jsonrpc!==P)return!1;if(S(r,"params")){const t=r.params;if(!b(t)&&!h(t))return!1}return!0},S=(r,t)=>t in r,x=(r,t)=>{try{const e=t();return e===m?r:e+""}catch(t){return r}},j=(r,t)=>{r[t]===m&&delete r[t]},v={serialization:r=>r,deserialization:r=>r},M="AsyncCall/",z=Symbol.for(M+"ignored"),A=Symbol.for(M+"notify"),C=Symbol.for(M+"batch"),N=(r,t)=>r[t][A],R=()=>Math.random().toString(36).slice(2),T=r=>void 0===r||r,D=r=>{if(!p(r)){const{methodNotFound:t,unknownMessage:e}=r;return[t,e]}return[r,r]};function I(r,e){let n=!0,i=m,w=m;const x=async()=>{try{i=await r}catch(r){w=r,er("AsyncCall failed to start",r)}finally{n=!1}},{serializer:M=v,key:N="rpc",strict:I=!0,log:W=!0,parameterStructures:J="by-position",preferLocalImplementation:G=!1,idGenerator:q=R,mapError:F,logger:L,channel:U,thenable:B}=e;r instanceof Promise?x():(i=r,n=!1);const[H,K]=D(I),[Q,V,X,Y,Z,rr]=(r=>{if("all"===r)return[!0,!0,!0,!0,!0,!0];if(!p(r)){const{beCalled:t,localError:e,remoteError:n,type:o,requestReplay:s,sendLocalStack:i}=r;return[T(t),T(e),T(n),"basic"!==o,s,i]}return r?[!0,!0,!0,!0]:[]})(W),{log:tr,error:er=tr,debug:nr=tr,groupCollapsed:or=tr,groupEnd:sr=tr,warn:ir=tr}=L||console,cr=new Map,ar=async r=>{let t;try{if(t=await fr(r),$(t))return await hr(t);if(b(t)&&t.every($)&&0!==t.length)return Promise.all(t.map(hr));if(K){let r=t.id;return r===m&&(r=null),(r=>k(r,-32600,"Invalid Request"))(r)}return m}catch(r){return V&&er(r,t,void 0),((r,t)=>{const e=O({},r,t),n=e.error;return n.code=-32700,n.message="Parse error",e})(r,F||_(r&&r.stack))}},lr=async r=>{if(r){if(b(r)){const t=r.filter((r=>r&&S(r,"id")));if(0===t.length)return;return ur(t)}return ur(r)}},ur=r=>M.serialization(r),fr=r=>M.deserialization(r);var yr;if(S(yr=U,"setup")&&d(yr.setup)&&U.setup((r=>ar(r).then(lr)),(r=>{const t=fr(r);return!!$(t)||(r=>Promise.resolve(r))(t).then($)})),(r=>S(r,"send")&&d(r.send))(U)){const r=U;r.on&&r.on((t=>ar(t).then(lr).then((t=>t&&r.send(t)))))}function pr(r,t,e){return h(r)&&S(r,"stack")&&(r.stack=t.split("\n").reduce(((r,t)=>r.replace(t+"\n","")),""+r.stack)),V&&er(r),O(e,r,F||_(rr?r.stack:m))}async function dr(r,t=!1){t&&(r=[...r]);const e=await ur(r);return U.send(e)}const hr=async r=>{if(S(r,"method")){const t=(async r=>{if(n)await x();else if(w)return pr(w,"",r);let t="";try{const{params:e,method:n,id:o,remoteStack:s}=r,c=n.startsWith("rpc.")?Symbol.for(n):n,a=i&&i[c];if(!d(a))return H?k(o,-32601,"Method not found"):void(V&&nr("Missing method",c,r));const l=b(e)?e:[e];t=u(Error().stack);const f=new Promise((r=>r(a.apply(i,l))));if(Q)if(Y){const r=[`${N}.%c${n}%c(${l.map((()=>"%o")).join(", ")}%c)\n%o %c@${o}`,"color: #d2c057","",...l,"",f,"color: gray; font-style: italic;"];if(Z){const t=()=>{debugger;return a.apply(i,l)};t.toString=E,r.push(t)}s?(or(...r),tr(s),sr()):tr(...r)}else tr(`${N}.${n}(${""+[...l]}) @${o}`);if(await f===z)return;return((r,t)=>{const e={jsonrpc:P,id:r,result:t};return j(e,"id"),e})(o,await f)}catch(e){return pr(e,t,r)}})(r);if(S(r,"id"))return t;try{await t}catch(r){}return m}return(async r=>{let e="",n="",o=0,s=g;if(S(r,"error")){const t=r.error;e=t.message,o=t.code;const i=t.data;n=h(i)&&S(i,"stack")&&y(i.stack)?i.stack:"<remote stack not available>",s=h(i)&&S(i,"type")&&y(i.type)?i.type:g,X&&(Y?er(`${s}: ${e}(${o}) %c@${r.id}\n%c${n}`,"color: gray",""):er(`${s}: ${e}(${o}) @${r.id}\n${n}`))}if(null===r.id||r.id===m)return;const{f:[i,c]=[null,null],stack:u=""}=cr.get(r.id)||{};i&&c&&(cr.delete(r.id),S(r,"error")?c(((r,e,n,o)=>{try{const s=f();if(r.startsWith(l)&&s)return new s(e,r.slice(13));if(r in a){const t=new a[r](e);return t.stack=o,t.code=n,t}return new t(r,e,n,o)}catch(t){return Error(`E${n} ${r}: ${e}\n${o}`)}})(s,e,o,n+"\n аt AsyncCall (rpc) \n"+u)):i(r.result))})(r)},gr=(r,t,e,s=!1)=>new Promise(((a,l)=>{let f=m;if(r===C&&(f=t.shift(),r=t.shift()),"symbol"==typeof r){const t=Symbol.keyFor(r)||r.description;if(t){if(!t.startsWith("rpc."))throw new TypeError("Not start with rpc.");r=t}}else if(r.startsWith("rpc."))throw c(o,new TypeError);if(G&&!n&&y(r)){const e=i&&i[r];if(d(e))return a(e(...t))}const p=q();e=u(e);const g="by-name"===J&&1===t.length&&h(t[0])?t[0]:t,w=((r,t,e,n)=>{const o={jsonrpc:P,id:r,method:t,params:e,remoteStack:n};return j(o,"id"),((r,t)=>{r[t]||delete r[t]})(o,"remoteStack"),o})(s?m:p,r,g,rr?e:m);if(f?(f.push(w),f.r||(f.r=[()=>dr(f,!0),r=>((r,t)=>{for(const e of r)if(S(e,"id")){const r=cr.get(e.id);r&&r.f[1](t)}})(f,r)])):dr(w).catch(l),s)return a();cr.set(p,{f:[a,l],stack:e})})),mr=(r,t)=>{const e={[t]:(...r)=>gr(t,r,Error().stack)}[t],n={[t]:(...r)=>gr(t,r,Error().stack,!0)}[t];return e[A]=n[A]=n,y(t)&&Object.defineProperty(wr,t,{value:e,configurable:!0}),e},wr={__proto__:new Proxy({},{get:mr})};return!1===B?wr.then=m:B===m&&Object.defineProperty(wr,"then",{configurable:!0,get(){ir(c(s,new TypeError("RPC used as Promise: ")))}}),new Proxy(wr,{getPrototypeOf:()=>null,setPrototypeOf:(r,t)=>null===t,getOwnPropertyDescriptor:(r,t)=>(t in wr||mr(0,t),Object.getOwnPropertyDescriptor(wr,t))})}const W="rpc.async-iterator.",J=Symbol.for(W+"start"),G=Symbol.for(W+"next"),q=Symbol.for(W+"return"),F=Symbol.for(W+"throw");class L{__init(){this.d=!1}__init2(){this.c=async r=>(await H(r,(()=>this.d=!0)),r)}constructor(r,t){this.r=r,this.i=t,L.prototype.__init.call(this),L.prototype.__init2.call(this)}async return(r){return this.d?K(!0,r):this.c(this.r[q](await this.i,r))}async next(r){return this.d?K(!0):this.c(this.r[G](await this.i,r))}async throw(r){if(!this.d)return this.c(this.r[F](await this.i,r));throw r}}const U=async function*(){};w(L,U.constructor.prototype);const B=Object.getPrototypeOf(U());w(L.prototype,B);const H=async(r,t)=>{try{const e=await r;e&&e.done&&t()}catch(r){}},K=(r,t)=>({done:r,value:t});r.AsyncCall=I,r.AsyncGeneratorCall=(r,t)=>{const o=new Map,[s]=D(null==(i=t.strict)||i);var i;const{idGenerator:a=R}=t,l=(r,t)=>{const n=o.get(r);if(!n){if(s)throw c(e,Error(`Iterator ${r}, `));return z}const i=t(n);return H(i,(()=>o.delete(r))),i},u=I({async[J](t,e){const n=(await r)[t];if(!d(n)){if(s)throw new TypeError(t+" is not a function");return z}const i=n(...e),c=a();return o.set(c,i),c},[G]:(r,t)=>l(r,(r=>r.next(t))),[q]:(r,t)=>l(r,(r=>d(r.return)&&r.return(t))),[F]:(r,t)=>l(r,(r=>d(r.throw)&&r.throw(t)))},t),f=(r,t)=>{if(!y(t))throw c(n,new TypeError(""));const e={[t]:(...r)=>{const e=u[J](t,r);return new L(u,e)}}[t];return Object.defineProperty(p,t,{value:e,configurable:!0}),e},p={__proto__:new Proxy({},{get:f})};return new Proxy(p,{getPrototypeOf:()=>null,setPrototypeOf:(r,t)=>null===t,getOwnPropertyDescriptor:(r,t)=>(t in p||f(0,t),Object.getOwnPropertyDescriptor(p,t))})},r.JSONSerialization=(r=[m,m],t,e="null")=>({serialization(n){if(e&&h(n)&&S(n,"result")&&n.result===m){const r={...n};r.result=null,"keep"===e&&(r.undef=!0),n=r}return JSON.stringify(n,r[0],t)},deserialization(t){const e=JSON.parse(t,r[1]);return h(e)&&S(e,"result")&&null===e.result&&S(e,"undef")&&!0===e.undef&&(e.result=m,delete e.undef),e}}),r.NoSerialization=v,r.batch=r=>{const t=[],e={__proto__:new Proxy({},{get(n,o){const s=(...e)=>r[C](t,o,...e);return(s[A]=(...e)=>r[C][A](t,o,...e))[A]=s[A],y(o)&&Object.defineProperty(e,o,{value:s,configurable:!0}),s}})};return[new Proxy(e,{getPrototypeOf:()=>null,setPrototypeOf:(r,t)=>null===t}),()=>{t.length&&t.r[0](),t.length=0},(r=Error("Aborted"))=>{t.length&&t.r[1](r),t.length=0}]},r.notify=r=>d(r)?r[A]:new Proxy(r,{get:N}),Object.defineProperty(r,"__esModule",{value:!0})})); | ||
//# sourceMappingURL=full.min.js.map |
{ | ||
"name": "async-call-rpc", | ||
"packageManager": "pnpm@7.9.0", | ||
"version": "6.1.3", | ||
"version": "6.1.4", | ||
"description": "A lightweight JSON RPC server & client", | ||
@@ -6,0 +6,0 @@ "main": "out/base.js", |
@@ -158,20 +158,14 @@ /** | ||
const getTrap = new Proxy( | ||
{}, | ||
{ | ||
get(_, method) { | ||
if (!isString(method)) | ||
throw makeHostedMessage(Err_Only_string_can_be_the_RPC_method_name, new TypeError('')) | ||
const f = { | ||
[method]: (..._: unknown[]) => { | ||
const id = remote[AsyncIteratorStart](method, _) | ||
return new _AsyncGenerator(remote, id) | ||
}, | ||
}[method]! | ||
Object.defineProperty(methodContainer, method, { value: f, configurable: true }) | ||
return f | ||
const getTrap = (_: any, method: PropertyKey) => { | ||
if (!isString(method)) throw makeHostedMessage(Err_Only_string_can_be_the_RPC_method_name, new TypeError('')) | ||
const f = { | ||
[method]: (..._: unknown[]) => { | ||
const id = remote[AsyncIteratorStart](method, _) | ||
return new _AsyncGenerator(remote, id) | ||
}, | ||
}, | ||
) | ||
const methodContainer = { __proto__: getTrap } as any | ||
}[method]! | ||
Object.defineProperty(methodContainer, method, { value: f, configurable: true }) | ||
return f | ||
} | ||
const methodContainer: any = { __proto__: new Proxy({}, { get: getTrap }) } | ||
return new Proxy(methodContainer, { | ||
@@ -182,3 +176,3 @@ getPrototypeOf: () => null, | ||
getOwnPropertyDescriptor(_, method) { | ||
if (!(method in methodContainer)) (getTrap as any)[method] // trigger [[Get]] | ||
if (!(method in methodContainer)) getTrap(_, method) // trigger [[Get]] | ||
return Object.getOwnPropertyDescriptor(methodContainer, method) | ||
@@ -185,0 +179,0 @@ }, |
@@ -348,21 +348,16 @@ export * from './types.js' | ||
} | ||
const getTrap = new Proxy( | ||
{}, | ||
{ | ||
get(_, method) { | ||
const f = { | ||
// This function will be logged to the console so it must be 1 line | ||
[method]: (..._: unknown[]) => call(method, _, new Error().stack), | ||
}[method as any]! | ||
const f2 = { | ||
[method]: (..._: unknown[]) => call(method, _, new Error().stack, true), | ||
}[method as any]! | ||
// @ts-expect-error | ||
f[AsyncCallNotify] = f2[AsyncCallNotify] = f2 | ||
isString(method) && Object.defineProperty(methodContainer, method, { value: f, configurable: true }) | ||
return f | ||
}, | ||
}, | ||
) | ||
const methodContainer = { __proto__: getTrap } as any | ||
const getTrap = (_: any, method: string | symbol) => { | ||
const f = { | ||
// This function will be logged to the console so it must be 1 line | ||
[method]: (..._: unknown[]) => call(method, _, new Error().stack), | ||
}[method as any]! | ||
const f2 = { | ||
[method]: (..._: unknown[]) => call(method, _, new Error().stack, true), | ||
}[method as any]! | ||
// @ts-expect-error | ||
f[AsyncCallNotify] = f2[AsyncCallNotify] = f2 | ||
isString(method) && Object.defineProperty(methodContainer, method, { value: f, configurable: true }) | ||
return f | ||
} | ||
const methodContainer: any = { __proto__: new Proxy({}, { get: getTrap }) } | ||
if (thenable === false) methodContainer.then = undefined | ||
@@ -387,3 +382,3 @@ else if (thenable === undefined) { | ||
getOwnPropertyDescriptor(_, method) { | ||
if (!(method in methodContainer)) (getTrap as any)[method] // trigger [[Get]] | ||
if (!(method in methodContainer)) getTrap(_, method) // trigger [[Get]] | ||
return Object.getOwnPropertyDescriptor(methodContainer, method) | ||
@@ -390,0 +385,0 @@ }, |
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
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
715636
4824