Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@katt/trpc-client

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@katt/trpc-client - npm Package Compare versions

Comparing version 1.0.0-alpha.10 to 1.0.0-alpha.13

8

dist/createTRPCClient.d.ts

@@ -1,2 +0,2 @@

import type { AnyRouter, HTTPResponseEnvelope, HTTPSuccessResponseEnvelope, inferAsyncReturnType, inferEndpointArgs, inferHandler, inferSubscriptionData, Maybe, DataTransformer } from '@katt/trpc-server';
import type { AnyRouter, DataTransformer, HTTPResponseEnvelope, HTTPSuccessResponseEnvelope, inferAsyncReturnType, inferEndpointArgs, inferHandler, inferSubscriptionData, Maybe } from '@katt/trpc-server';
declare type UnsubscribeFn = () => void;

@@ -12,3 +12,3 @@ declare type inferSubscriptionFn<TRouter extends AnyRouter> = <TPath extends keyof TRouter['_def']['subscriptions'], TArgs extends inferEndpointArgs<TRouter['_def']['subscriptions'][TPath]> & any[], TData extends inferSubscriptionData<inferAsyncReturnType<TRouter['_def']['subscriptions'][TPath]>>>(pathAndArgs: [TPath, ...TArgs], opts: {

subscription: inferSubscriptionFn<TRouter>;
transformers: DataTransformer[];
transformer: DataTransformer;
};

@@ -35,7 +35,5 @@ export declare class TRPCClientError extends Error {

onError?: (error: TRPCClientError) => void;
transformers?: DataTransformer[];
transformer?: DataTransformer;
}
export declare function transformArgs(transformers: DataTransformer[], args: unknown[]): unknown[];
export declare function transformData(transformers: DataTransformer[], data: unknown): unknown;
export declare function createTRPCClient<TRouter extends AnyRouter>(opts: CreateTRPCClientOptions): TRPCClient<TRouter>;
export {};

@@ -942,16 +942,4 @@ 'use strict';

function transformArgs(transformers, args) {
return args.map(function (arg) {
return transformers.reduce(function (prev, transformer) {
return transformer.serialize(prev);
}, arg);
});
}
function transformData(transformers, data) {
return transformers.reduce(function (prev, transformer) {
return transformer.deserialize(prev);
}, data);
}
function createTRPCClient(opts) {
var _opts$transformers;
var _opts$transformer;

@@ -964,3 +952,10 @@ var fetchOpts = opts.fetchOpts,

var AC = getAbortController(fetchOpts == null ? void 0 : fetchOpts.AbortController);
var transformers = (_opts$transformers = opts.transformers) != null ? _opts$transformers : [];
var transformer = (_opts$transformer = opts.transformer) != null ? _opts$transformer : {
serialize: function serialize(data) {
return data;
},
deserialize: function deserialize(data) {
return data;
}
};

@@ -997,3 +992,5 @@ function handleResponse(_x) {

opts.onSuccess && opts.onSuccess(json);
opts.onSuccess && opts.onSuccess(_extends({}, json, {
data: transformer.deserialize(json.data)
}));
return _context4.abrupt("return", json.data);

@@ -1059,3 +1056,3 @@

if (args == null ? void 0 : args.length) {
target += "?args=" + encodeURIComponent(JSON.stringify(transformArgs(transformers, args)));
target += "?args=" + encodeURIComponent(JSON.stringify(args.map(transformer.serialize)));
}

@@ -1100,3 +1097,3 @@

body: JSON.stringify({
args: transformArgs(transformers, args)
args: args.map(transformer.serialize)
}),

@@ -1153,13 +1150,10 @@ headers: getHeaders()

console.log('args', args);
if (!stopped) {
_context3.next = 5;
_context3.next = 3;
break;
}
console.log('subscriptions have stopped');
return _context3.abrupt("return");
case 5:
case 3:
controller = AC ? new AC() : null;

@@ -1170,3 +1164,3 @@ signal = (_controller = controller) == null ? void 0 : _controller.signal;

body: JSON.stringify({
args: transformArgs(transformers, thisArgs)
args: args.map(transformer.serialize)
}),

@@ -1176,15 +1170,13 @@ headers: getHeaders(),

});
_context3.prev = 8;
console.log('⏳ waiting for', path, thisArgs);
_context3.t0 = transformData;
_context3.t1 = transformers;
_context3.next = 14;
_context3.prev = 6;
_context3.t0 = transformer;
_context3.next = 10;
return handleResponse(promise);
case 14:
_context3.t2 = _context3.sent;
data = (0, _context3.t0)(_context3.t1, _context3.t2);
case 10:
_context3.t1 = _context3.sent;
data = _context3.t0.deserialize.call(_context3.t0, _context3.t1);
if (!stopped) {
_context3.next = 18;
_context3.next = 14;
break;

@@ -1195,17 +1187,17 @@ }

case 18:
case 14:
opts.onSuccess && opts.onSuccess(data);
nextArgs = opts.getNextArgs ? opts.getNextArgs(data) : thisArgs;
console.log('nextArgs', nextArgs);
nextArgs = opts.getNextArgs ? opts.getNextArgs(data) : thisArgs; // console.log('nextArgs', nextArgs);
attemptIndex = 0;
exec.apply(void 0, nextArgs);
_context3.next = 36;
_context3.next = 29;
break;
case 25:
_context3.prev = 25;
_context3.t3 = _context3["catch"](8);
case 20:
_context3.prev = 20;
_context3.t2 = _context3["catch"](6);
if (!stopped) {
_context3.next = 30;
_context3.next = 25;
break;

@@ -1217,5 +1209,4 @@ }

case 30:
err = _context3.t3;
console.log('❌ subscription failed :(', err.message);
case 25:
err = _context3.t2; // console.log('❌ subscription failed :(', err.message);

@@ -1228,4 +1219,4 @@ if (((_err$json = err.json) == null ? void 0 : _err$json.statusCode) === 408) {

delay = retryDelay(attemptIndex);
console.log('trying again in', delay, 'ms');
delay = retryDelay(attemptIndex); // console.log('trying again in', delay, 'ms');
nextTry = setTimeout(function () {

@@ -1235,3 +1226,3 @@ exec.apply(void 0, thisArgs);

case 36:
case 29:
case "end":

@@ -1241,3 +1232,3 @@ return _context3.stop();

}
}, _callee3, null, [[8, 25]]);
}, _callee3, null, [[6, 20]]);
}));

@@ -1248,5 +1239,5 @@

};
}();
}(); // console.log('argds', args);
console.log('argds', args);
exec.apply(void 0, args);

@@ -1266,3 +1257,3 @@ return function () {

subscription: subscription,
transformers: transformers
transformer: transformer
};

@@ -1273,4 +1264,2 @@ }

exports.createTRPCClient = createTRPCClient;
exports.transformArgs = transformArgs;
exports.transformData = transformData;
//# sourceMappingURL=trpc-client.cjs.development.js.map

@@ -1,2 +0,2 @@

"use strict";function t(t,r,e,n,o,i,a){try{var u=t[i](a),c=u.value}catch(t){return void e(t)}u.done?r(c):Promise.resolve(c).then(n,o)}function r(r){return function(){var e=this,n=arguments;return new Promise((function(o,i){var a=r.apply(e,n);function u(r){t(a,o,i,u,c,"next",r)}function c(r){t(a,o,i,u,c,"throw",r)}u(void 0)}))}}function e(){return(e=Object.assign||function(t){for(var r=1;r<arguments.length;r++){var e=arguments[r];for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n])}return t}).apply(this,arguments)}function n(t){return(n=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}function o(t,r){return(o=Object.setPrototypeOf||function(t,r){return t.__proto__=r,t})(t,r)}function i(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],(function(){}))),!0}catch(t){return!1}}function a(t,r,e){return(a=i()?Reflect.construct:function(t,r,e){var n=[null];n.push.apply(n,r);var i=new(Function.bind.apply(t,n));return e&&o(i,e.prototype),i}).apply(null,arguments)}function u(t){var r="function"==typeof Map?new Map:void 0;return(u=function(t){if(null===t||-1===Function.toString.call(t).indexOf("[native code]"))return t;if("function"!=typeof t)throw new TypeError("Super expression must either be null or a function");if(void 0!==r){if(r.has(t))return r.get(t);r.set(t,e)}function e(){return a(t,arguments,n(this).constructor)}return e.prototype=Object.create(t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),o(e,t)})(t)}function c(t,r){return t(r={exports:{}},r.exports),r.exports}Object.defineProperty(exports,"__esModule",{value:!0});var s=c((function(t){var r=function(t){var r=Object.prototype,e=r.hasOwnProperty,n="function"==typeof Symbol?Symbol:{},o=n.iterator||"@@iterator",i=n.asyncIterator||"@@asyncIterator",a=n.toStringTag||"@@toStringTag";function u(t,r,e){return Object.defineProperty(t,r,{value:e,enumerable:!0,configurable:!0,writable:!0}),t[r]}try{u({},"")}catch(t){u=function(t,r,e){return t[r]=e}}function c(t,r,e,n){var o=Object.create((r&&r.prototype instanceof f?r:f).prototype),i=new E(n||[]);return o._invoke=function(t,r,e){var n="suspendedStart";return function(o,i){if("executing"===n)throw new Error("Generator is already running");if("completed"===n){if("throw"===o)throw i;return{value:void 0,done:!0}}for(e.method=o,e.arg=i;;){var a=e.delegate;if(a){var u=b(a,e);if(u){if(u===l)continue;return u}}if("next"===e.method)e.sent=e._sent=e.arg;else if("throw"===e.method){if("suspendedStart"===n)throw n="completed",e.arg;e.dispatchException(e.arg)}else"return"===e.method&&e.abrupt("return",e.arg);n="executing";var c=s(t,r,e);if("normal"===c.type){if(n=e.done?"completed":"suspendedYield",c.arg===l)continue;return{value:c.arg,done:e.done}}"throw"===c.type&&(n="completed",e.method="throw",e.arg=c.arg)}}}(t,e,i),o}function s(t,r,e){try{return{type:"normal",arg:t.call(r,e)}}catch(t){return{type:"throw",arg:t}}}t.wrap=c;var l={};function f(){}function p(){}function h(){}var d={};d[o]=function(){return this};var y=Object.getPrototypeOf,v=y&&y(y(_([])));v&&v!==r&&e.call(v,o)&&(d=v);var g=h.prototype=f.prototype=Object.create(d);function w(t){["next","throw","return"].forEach((function(r){u(t,r,(function(t){return this._invoke(r,t)}))}))}function m(t,r){var n;this._invoke=function(o,i){function a(){return new r((function(n,a){!function n(o,i,a,u){var c=s(t[o],t,i);if("throw"!==c.type){var l=c.arg,f=l.value;return f&&"object"==typeof f&&e.call(f,"__await")?r.resolve(f.__await).then((function(t){n("next",t,a,u)}),(function(t){n("throw",t,a,u)})):r.resolve(f).then((function(t){l.value=t,a(l)}),(function(t){return n("throw",t,a,u)}))}u(c.arg)}(o,i,n,a)}))}return n=n?n.then(a,a):a()}}function b(t,r){var e=t.iterator[r.method];if(void 0===e){if(r.delegate=null,"throw"===r.method){if(t.iterator.return&&(r.method="return",r.arg=void 0,b(t,r),"throw"===r.method))return l;r.method="throw",r.arg=new TypeError("The iterator does not provide a 'throw' method")}return l}var n=s(e,t.iterator,r.arg);if("throw"===n.type)return r.method="throw",r.arg=n.arg,r.delegate=null,l;var o=n.arg;return o?o.done?(r[t.resultName]=o.value,r.next=t.nextLoc,"return"!==r.method&&(r.method="next",r.arg=void 0),r.delegate=null,l):o:(r.method="throw",r.arg=new TypeError("iterator result is not an object"),r.delegate=null,l)}function x(t){var r={tryLoc:t[0]};1 in t&&(r.catchLoc=t[1]),2 in t&&(r.finallyLoc=t[2],r.afterLoc=t[3]),this.tryEntries.push(r)}function O(t){var r=t.completion||{};r.type="normal",delete r.arg,t.completion=r}function E(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(x,this),this.reset(!0)}function _(t){if(t){var r=t[o];if(r)return r.call(t);if("function"==typeof t.next)return t;if(!isNaN(t.length)){var n=-1,i=function r(){for(;++n<t.length;)if(e.call(t,n))return r.value=t[n],r.done=!1,r;return r.value=void 0,r.done=!0,r};return i.next=i}}return{next:j}}function j(){return{value:void 0,done:!0}}return p.prototype=g.constructor=h,h.constructor=p,p.displayName=u(h,a,"GeneratorFunction"),t.isGeneratorFunction=function(t){var r="function"==typeof t&&t.constructor;return!!r&&(r===p||"GeneratorFunction"===(r.displayName||r.name))},t.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,h):(t.__proto__=h,u(t,a,"GeneratorFunction")),t.prototype=Object.create(g),t},t.awrap=function(t){return{__await:t}},w(m.prototype),m.prototype[i]=function(){return this},t.AsyncIterator=m,t.async=function(r,e,n,o,i){void 0===i&&(i=Promise);var a=new m(c(r,e,n,o),i);return t.isGeneratorFunction(e)?a:a.next().then((function(t){return t.done?t.value:a.next()}))},w(g),u(g,a,"Generator"),g[o]=function(){return this},g.toString=function(){return"[object Generator]"},t.keys=function(t){var r=[];for(var e in t)r.push(e);return r.reverse(),function e(){for(;r.length;){var n=r.pop();if(n in t)return e.value=n,e.done=!1,e}return e.done=!0,e}},t.values=_,E.prototype={constructor:E,reset:function(t){if(this.prev=0,this.next=0,this.sent=this._sent=void 0,this.done=!1,this.delegate=null,this.method="next",this.arg=void 0,this.tryEntries.forEach(O),!t)for(var r in this)"t"===r.charAt(0)&&e.call(this,r)&&!isNaN(+r.slice(1))&&(this[r]=void 0)},stop:function(){this.done=!0;var t=this.tryEntries[0].completion;if("throw"===t.type)throw t.arg;return this.rval},dispatchException:function(t){if(this.done)throw t;var r=this;function n(e,n){return a.type="throw",a.arg=t,r.next=e,n&&(r.method="next",r.arg=void 0),!!n}for(var o=this.tryEntries.length-1;o>=0;--o){var i=this.tryEntries[o],a=i.completion;if("root"===i.tryLoc)return n("end");if(i.tryLoc<=this.prev){var u=e.call(i,"catchLoc"),c=e.call(i,"finallyLoc");if(u&&c){if(this.prev<i.catchLoc)return n(i.catchLoc,!0);if(this.prev<i.finallyLoc)return n(i.finallyLoc)}else if(u){if(this.prev<i.catchLoc)return n(i.catchLoc,!0)}else{if(!c)throw new Error("try statement without catch or finally");if(this.prev<i.finallyLoc)return n(i.finallyLoc)}}}},abrupt:function(t,r){for(var n=this.tryEntries.length-1;n>=0;--n){var o=this.tryEntries[n];if(o.tryLoc<=this.prev&&e.call(o,"finallyLoc")&&this.prev<o.finallyLoc){var i=o;break}}i&&("break"===t||"continue"===t)&&i.tryLoc<=r&&r<=i.finallyLoc&&(i=null);var a=i?i.completion:{};return a.type=t,a.arg=r,i?(this.method="next",this.next=i.finallyLoc,l):this.complete(a)},complete:function(t,r){if("throw"===t.type)throw t.arg;return"break"===t.type||"continue"===t.type?this.next=t.arg:"return"===t.type?(this.rval=this.arg=t.arg,this.method="return",this.next="end"):"normal"===t.type&&r&&(this.next=r),l},finish:function(t){for(var r=this.tryEntries.length-1;r>=0;--r){var e=this.tryEntries[r];if(e.finallyLoc===t)return this.complete(e.completion,e.afterLoc),O(e),l}},catch:function(t){for(var r=this.tryEntries.length-1;r>=0;--r){var e=this.tryEntries[r];if(e.tryLoc===t){var n=e.completion;if("throw"===n.type){var o=n.arg;O(e)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(t,r,e){return this.delegate={iterator:_(t),resultName:r,nextLoc:e},"next"===this.method&&(this.arg=void 0),l}},t}(t.exports);try{regeneratorRuntime=r}catch(t){Function("r","regeneratorRuntime = r")(r)}})),l=function(t){return 0===t?0:Math.min(1e3*Math.pow(2,t),3e4)},f=function(t){var r,e;function n(r,e){var o,i=e.res,a=e.json,u=e.originalError;return(o=t.call(this,r)||this).message=r,o.res=i,o.json=a,o.originalError=u,Object.setPrototypeOf(function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(o),n.prototype),o}return e=t,(r=n).prototype=Object.create(e.prototype),r.prototype.constructor=r,r.__proto__=e,n}(u(Error));function p(t,r){return r.map((function(r){return t.reduce((function(t,r){return r.serialize(t)}),r)}))}function h(t,r){return t.reduce((function(t,r){return r.deserialize(t)}),r)}exports.TRPCClientError=f,exports.createTRPCClient=function(t){var n,o=t.fetchOpts,i=t.url,a=function(t){if(t)return t;if("undefined"!=typeof window&&window.fetch)return window.fetch;if("undefined"!=typeof global&&global.fetch)return global.fetch;throw new Error("No fetch implementation found")}(null==o?void 0:o.fetch),u=(null==o?void 0:o.AbortController)||("undefined"!=typeof window&&window.AbortController?window.AbortController:"undefined"!=typeof global&&global.AbortController?global.AbortController:null),c=null!=(n=t.transformers)?n:[];function d(t){return y.apply(this,arguments)}function y(){return(y=r(s.mark((function r(e){var n,o,i;return s.wrap((function(r){for(;;)switch(r.prev=r.next){case 0:return n=null,o=null,r.prev=2,r.next=5,e;case 5:return n=r.sent,r.next=8,n.json();case 8:if(!(o=r.sent).ok){r.next=12;break}return t.onSuccess&&t.onSuccess(o),r.abrupt("return",o.data);case 12:throw new f(o.error.message,{json:o,res:n});case 15:throw r.prev=15,r.t0=r.catch(2),(i=r.t0)instanceof f||(i=new f(r.t0.message,{originalError:r.t0,res:n,json:o})),t.onError&&t.onError(i),i;case 21:case"end":return r.stop()}}),r,null,[[2,15]])})))).apply(this,arguments)}function v(){return e({},t.getHeaders?t.getHeaders():{},{"content-type":"application/json"})}var g=function(){var t=r(s.mark((function t(r){var e,n,o,u,l,f=arguments;return s.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:for(e=i+"/"+r,n=f.length,o=new Array(n>1?n-1:0),u=1;u<n;u++)o[u-1]=f[u];return(null==o?void 0:o.length)&&(e+="?args="+encodeURIComponent(JSON.stringify(p(c,o)))),l=a(e,{headers:v()}),t.abrupt("return",d(l));case 5:case"end":return t.stop()}}),t)})));return function(r){return t.apply(this,arguments)}}();return{mutate:function(){var t=r(s.mark((function t(r){var e,n,o,u,l=arguments;return s.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:for(e=l.length,n=new Array(e>1?e-1:0),o=1;o<e;o++)n[o-1]=l[o];return u=a(i+"/"+r,{method:"POST",body:JSON.stringify({args:p(c,n)}),headers:v()}),t.abrupt("return",d(u));case 3:case"end":return t.stop()}}),t)})));return function(r){return t.apply(this,arguments)}}(),query:g,subscription:function(t,e){var n,o=t[0],f=t.slice(1),y=!1,g=null,w=0,m=function(){var t=r(s.mark((function t(){var r,b,x,O,E,_,j,L,P,k,S,A=arguments;return s.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:for(b=A.length,x=new Array(b),O=0;O<b;O++)x[O]=A[O];if(console.log("args",f),!y){t.next=5;break}return console.log("subscriptions have stopped"),t.abrupt("return");case 5:return g=u?new u:null,E=null==(r=g)?void 0:r.signal,_=a(i+"/"+o,{method:"PATCH",body:JSON.stringify({args:p(c,x)}),headers:v(),signal:E}),t.prev=8,console.log("⏳ waiting for",o,x),t.t0=h,t.t1=c,t.next=14,d(_);case 14:if(t.t2=t.sent,j=(0,t.t0)(t.t1,t.t2),!y){t.next=18;break}return t.abrupt("return");case 18:e.onSuccess&&e.onSuccess(j),L=e.getNextArgs?e.getNextArgs(j):x,console.log("nextArgs",L),w=0,m.apply(void 0,L),t.next=36;break;case 25:if(t.prev=25,t.t3=t.catch(8),!y){t.next=30;break}return console.log("sub stopped"),t.abrupt("return");case 30:k=t.t3,console.log("❌ subscription failed :(",k.message),408===(null==(P=k.json)?void 0:P.statusCode)?w=0:w++,S=l(w),console.log("trying again in",S,"ms"),n=setTimeout((function(){m.apply(void 0,x)}),S);case 36:case"end":return t.stop()}}),t,null,[[8,25]])})));return function(){return t.apply(this,arguments)}}();return console.log("argds",f),m.apply(void 0,f),function(){var t;y=!0,clearTimeout(n),null==(t=g)||t.abort()}},transformers:c}},exports.transformArgs=p,exports.transformData=h;
"use strict";function t(t,r,e,n,o,i,a){try{var u=t[i](a),c=u.value}catch(t){return void e(t)}u.done?r(c):Promise.resolve(c).then(n,o)}function r(r){return function(){var e=this,n=arguments;return new Promise((function(o,i){var a=r.apply(e,n);function u(r){t(a,o,i,u,c,"next",r)}function c(r){t(a,o,i,u,c,"throw",r)}u(void 0)}))}}function e(){return(e=Object.assign||function(t){for(var r=1;r<arguments.length;r++){var e=arguments[r];for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n])}return t}).apply(this,arguments)}function n(t){return(n=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}function o(t,r){return(o=Object.setPrototypeOf||function(t,r){return t.__proto__=r,t})(t,r)}function i(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],(function(){}))),!0}catch(t){return!1}}function a(t,r,e){return(a=i()?Reflect.construct:function(t,r,e){var n=[null];n.push.apply(n,r);var i=new(Function.bind.apply(t,n));return e&&o(i,e.prototype),i}).apply(null,arguments)}function u(t){var r="function"==typeof Map?new Map:void 0;return(u=function(t){if(null===t||-1===Function.toString.call(t).indexOf("[native code]"))return t;if("function"!=typeof t)throw new TypeError("Super expression must either be null or a function");if(void 0!==r){if(r.has(t))return r.get(t);r.set(t,e)}function e(){return a(t,arguments,n(this).constructor)}return e.prototype=Object.create(t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),o(e,t)})(t)}function c(t,r){return t(r={exports:{}},r.exports),r.exports}Object.defineProperty(exports,"__esModule",{value:!0});var s=c((function(t){var r=function(t){var r=Object.prototype,e=r.hasOwnProperty,n="function"==typeof Symbol?Symbol:{},o=n.iterator||"@@iterator",i=n.asyncIterator||"@@asyncIterator",a=n.toStringTag||"@@toStringTag";function u(t,r,e){return Object.defineProperty(t,r,{value:e,enumerable:!0,configurable:!0,writable:!0}),t[r]}try{u({},"")}catch(t){u=function(t,r,e){return t[r]=e}}function c(t,r,e,n){var o=Object.create((r&&r.prototype instanceof f?r:f).prototype),i=new E(n||[]);return o._invoke=function(t,r,e){var n="suspendedStart";return function(o,i){if("executing"===n)throw new Error("Generator is already running");if("completed"===n){if("throw"===o)throw i;return{value:void 0,done:!0}}for(e.method=o,e.arg=i;;){var a=e.delegate;if(a){var u=b(a,e);if(u){if(u===l)continue;return u}}if("next"===e.method)e.sent=e._sent=e.arg;else if("throw"===e.method){if("suspendedStart"===n)throw n="completed",e.arg;e.dispatchException(e.arg)}else"return"===e.method&&e.abrupt("return",e.arg);n="executing";var c=s(t,r,e);if("normal"===c.type){if(n=e.done?"completed":"suspendedYield",c.arg===l)continue;return{value:c.arg,done:e.done}}"throw"===c.type&&(n="completed",e.method="throw",e.arg=c.arg)}}}(t,e,i),o}function s(t,r,e){try{return{type:"normal",arg:t.call(r,e)}}catch(t){return{type:"throw",arg:t}}}t.wrap=c;var l={};function f(){}function p(){}function h(){}var d={};d[o]=function(){return this};var y=Object.getPrototypeOf,v=y&&y(y(_([])));v&&v!==r&&e.call(v,o)&&(d=v);var g=h.prototype=f.prototype=Object.create(d);function w(t){["next","throw","return"].forEach((function(r){u(t,r,(function(t){return this._invoke(r,t)}))}))}function m(t,r){var n;this._invoke=function(o,i){function a(){return new r((function(n,a){!function n(o,i,a,u){var c=s(t[o],t,i);if("throw"!==c.type){var l=c.arg,f=l.value;return f&&"object"==typeof f&&e.call(f,"__await")?r.resolve(f.__await).then((function(t){n("next",t,a,u)}),(function(t){n("throw",t,a,u)})):r.resolve(f).then((function(t){l.value=t,a(l)}),(function(t){return n("throw",t,a,u)}))}u(c.arg)}(o,i,n,a)}))}return n=n?n.then(a,a):a()}}function b(t,r){var e=t.iterator[r.method];if(void 0===e){if(r.delegate=null,"throw"===r.method){if(t.iterator.return&&(r.method="return",r.arg=void 0,b(t,r),"throw"===r.method))return l;r.method="throw",r.arg=new TypeError("The iterator does not provide a 'throw' method")}return l}var n=s(e,t.iterator,r.arg);if("throw"===n.type)return r.method="throw",r.arg=n.arg,r.delegate=null,l;var o=n.arg;return o?o.done?(r[t.resultName]=o.value,r.next=t.nextLoc,"return"!==r.method&&(r.method="next",r.arg=void 0),r.delegate=null,l):o:(r.method="throw",r.arg=new TypeError("iterator result is not an object"),r.delegate=null,l)}function x(t){var r={tryLoc:t[0]};1 in t&&(r.catchLoc=t[1]),2 in t&&(r.finallyLoc=t[2],r.afterLoc=t[3]),this.tryEntries.push(r)}function O(t){var r=t.completion||{};r.type="normal",delete r.arg,t.completion=r}function E(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(x,this),this.reset(!0)}function _(t){if(t){var r=t[o];if(r)return r.call(t);if("function"==typeof t.next)return t;if(!isNaN(t.length)){var n=-1,i=function r(){for(;++n<t.length;)if(e.call(t,n))return r.value=t[n],r.done=!1,r;return r.value=void 0,r.done=!0,r};return i.next=i}}return{next:j}}function j(){return{value:void 0,done:!0}}return p.prototype=g.constructor=h,h.constructor=p,p.displayName=u(h,a,"GeneratorFunction"),t.isGeneratorFunction=function(t){var r="function"==typeof t&&t.constructor;return!!r&&(r===p||"GeneratorFunction"===(r.displayName||r.name))},t.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,h):(t.__proto__=h,u(t,a,"GeneratorFunction")),t.prototype=Object.create(g),t},t.awrap=function(t){return{__await:t}},w(m.prototype),m.prototype[i]=function(){return this},t.AsyncIterator=m,t.async=function(r,e,n,o,i){void 0===i&&(i=Promise);var a=new m(c(r,e,n,o),i);return t.isGeneratorFunction(e)?a:a.next().then((function(t){return t.done?t.value:a.next()}))},w(g),u(g,a,"Generator"),g[o]=function(){return this},g.toString=function(){return"[object Generator]"},t.keys=function(t){var r=[];for(var e in t)r.push(e);return r.reverse(),function e(){for(;r.length;){var n=r.pop();if(n in t)return e.value=n,e.done=!1,e}return e.done=!0,e}},t.values=_,E.prototype={constructor:E,reset:function(t){if(this.prev=0,this.next=0,this.sent=this._sent=void 0,this.done=!1,this.delegate=null,this.method="next",this.arg=void 0,this.tryEntries.forEach(O),!t)for(var r in this)"t"===r.charAt(0)&&e.call(this,r)&&!isNaN(+r.slice(1))&&(this[r]=void 0)},stop:function(){this.done=!0;var t=this.tryEntries[0].completion;if("throw"===t.type)throw t.arg;return this.rval},dispatchException:function(t){if(this.done)throw t;var r=this;function n(e,n){return a.type="throw",a.arg=t,r.next=e,n&&(r.method="next",r.arg=void 0),!!n}for(var o=this.tryEntries.length-1;o>=0;--o){var i=this.tryEntries[o],a=i.completion;if("root"===i.tryLoc)return n("end");if(i.tryLoc<=this.prev){var u=e.call(i,"catchLoc"),c=e.call(i,"finallyLoc");if(u&&c){if(this.prev<i.catchLoc)return n(i.catchLoc,!0);if(this.prev<i.finallyLoc)return n(i.finallyLoc)}else if(u){if(this.prev<i.catchLoc)return n(i.catchLoc,!0)}else{if(!c)throw new Error("try statement without catch or finally");if(this.prev<i.finallyLoc)return n(i.finallyLoc)}}}},abrupt:function(t,r){for(var n=this.tryEntries.length-1;n>=0;--n){var o=this.tryEntries[n];if(o.tryLoc<=this.prev&&e.call(o,"finallyLoc")&&this.prev<o.finallyLoc){var i=o;break}}i&&("break"===t||"continue"===t)&&i.tryLoc<=r&&r<=i.finallyLoc&&(i=null);var a=i?i.completion:{};return a.type=t,a.arg=r,i?(this.method="next",this.next=i.finallyLoc,l):this.complete(a)},complete:function(t,r){if("throw"===t.type)throw t.arg;return"break"===t.type||"continue"===t.type?this.next=t.arg:"return"===t.type?(this.rval=this.arg=t.arg,this.method="return",this.next="end"):"normal"===t.type&&r&&(this.next=r),l},finish:function(t){for(var r=this.tryEntries.length-1;r>=0;--r){var e=this.tryEntries[r];if(e.finallyLoc===t)return this.complete(e.completion,e.afterLoc),O(e),l}},catch:function(t){for(var r=this.tryEntries.length-1;r>=0;--r){var e=this.tryEntries[r];if(e.tryLoc===t){var n=e.completion;if("throw"===n.type){var o=n.arg;O(e)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(t,r,e){return this.delegate={iterator:_(t),resultName:r,nextLoc:e},"next"===this.method&&(this.arg=void 0),l}},t}(t.exports);try{regeneratorRuntime=r}catch(t){Function("r","regeneratorRuntime = r")(r)}})),l=function(t){return 0===t?0:Math.min(1e3*Math.pow(2,t),3e4)},f=function(t){var r,e;function n(r,e){var o,i=e.res,a=e.json,u=e.originalError;return(o=t.call(this,r)||this).message=r,o.res=i,o.json=a,o.originalError=u,Object.setPrototypeOf(function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(o),n.prototype),o}return e=t,(r=n).prototype=Object.create(e.prototype),r.prototype.constructor=r,r.__proto__=e,n}(u(Error));exports.TRPCClientError=f,exports.createTRPCClient=function(t){var n,o=t.fetchOpts,i=t.url,a=function(t){if(t)return t;if("undefined"!=typeof window&&window.fetch)return window.fetch;if("undefined"!=typeof global&&global.fetch)return global.fetch;throw new Error("No fetch implementation found")}(null==o?void 0:o.fetch),u=(null==o?void 0:o.AbortController)||("undefined"!=typeof window&&window.AbortController?window.AbortController:"undefined"!=typeof global&&global.AbortController?global.AbortController:null),c=null!=(n=t.transformer)?n:{serialize:function(t){return t},deserialize:function(t){return t}};function p(t){return h.apply(this,arguments)}function h(){return(h=r(s.mark((function r(n){var o,i,a;return s.wrap((function(r){for(;;)switch(r.prev=r.next){case 0:return o=null,i=null,r.prev=2,r.next=5,n;case 5:return o=r.sent,r.next=8,o.json();case 8:if(!(i=r.sent).ok){r.next=12;break}return t.onSuccess&&t.onSuccess(e({},i,{data:c.deserialize(i.data)})),r.abrupt("return",i.data);case 12:throw new f(i.error.message,{json:i,res:o});case 15:throw r.prev=15,r.t0=r.catch(2),(a=r.t0)instanceof f||(a=new f(r.t0.message,{originalError:r.t0,res:o,json:i})),t.onError&&t.onError(a),a;case 21:case"end":return r.stop()}}),r,null,[[2,15]])})))).apply(this,arguments)}function d(){return e({},t.getHeaders?t.getHeaders():{},{"content-type":"application/json"})}var y=function(){var t=r(s.mark((function t(r){var e,n,o,u,l,f=arguments;return s.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:for(e=i+"/"+r,n=f.length,o=new Array(n>1?n-1:0),u=1;u<n;u++)o[u-1]=f[u];return(null==o?void 0:o.length)&&(e+="?args="+encodeURIComponent(JSON.stringify(o.map(c.serialize)))),l=a(e,{headers:d()}),t.abrupt("return",p(l));case 5:case"end":return t.stop()}}),t)})));return function(r){return t.apply(this,arguments)}}();return{mutate:function(){var t=r(s.mark((function t(r){var e,n,o,u,l=arguments;return s.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:for(e=l.length,n=new Array(e>1?e-1:0),o=1;o<e;o++)n[o-1]=l[o];return u=a(i+"/"+r,{method:"POST",body:JSON.stringify({args:n.map(c.serialize)}),headers:d()}),t.abrupt("return",p(u));case 3:case"end":return t.stop()}}),t)})));return function(r){return t.apply(this,arguments)}}(),query:y,subscription:function(t,e){var n,o=t[0],f=t.slice(1),h=!1,y=null,v=0,g=function(){var t=r(s.mark((function t(){var r,w,m,b,x,O,E,_,j,L,P=arguments;return s.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:for(w=P.length,m=new Array(w),b=0;b<w;b++)m[b]=P[b];if(!h){t.next=3;break}return t.abrupt("return");case 3:return y=u?new u:null,x=null==(r=y)?void 0:r.signal,O=a(i+"/"+o,{method:"PATCH",body:JSON.stringify({args:f.map(c.serialize)}),headers:d(),signal:x}),t.prev=6,t.t0=c,t.next=10,p(O);case 10:if(t.t1=t.sent,E=t.t0.deserialize.call(t.t0,t.t1),!h){t.next=14;break}return t.abrupt("return");case 14:e.onSuccess&&e.onSuccess(E),_=e.getNextArgs?e.getNextArgs(E):m,v=0,g.apply(void 0,_),t.next=29;break;case 20:if(t.prev=20,t.t2=t.catch(6),!h){t.next=25;break}return console.log("sub stopped"),t.abrupt("return");case 25:408===(null==(j=t.t2.json)?void 0:j.statusCode)?v=0:v++,L=l(v),n=setTimeout((function(){g.apply(void 0,m)}),L);case 29:case"end":return t.stop()}}),t,null,[[6,20]])})));return function(){return t.apply(this,arguments)}}();return g.apply(void 0,f),function(){var t;h=!0,clearTimeout(n),null==(t=y)||t.abort()}},transformer:c}};
//# sourceMappingURL=trpc-client.cjs.production.min.js.map

@@ -938,16 +938,4 @@ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {

function transformArgs(transformers, args) {
return args.map(function (arg) {
return transformers.reduce(function (prev, transformer) {
return transformer.serialize(prev);
}, arg);
});
}
function transformData(transformers, data) {
return transformers.reduce(function (prev, transformer) {
return transformer.deserialize(prev);
}, data);
}
function createTRPCClient(opts) {
var _opts$transformers;
var _opts$transformer;

@@ -960,3 +948,10 @@ var fetchOpts = opts.fetchOpts,

var AC = getAbortController(fetchOpts == null ? void 0 : fetchOpts.AbortController);
var transformers = (_opts$transformers = opts.transformers) != null ? _opts$transformers : [];
var transformer = (_opts$transformer = opts.transformer) != null ? _opts$transformer : {
serialize: function serialize(data) {
return data;
},
deserialize: function deserialize(data) {
return data;
}
};

@@ -993,3 +988,5 @@ function handleResponse(_x) {

opts.onSuccess && opts.onSuccess(json);
opts.onSuccess && opts.onSuccess(_extends({}, json, {
data: transformer.deserialize(json.data)
}));
return _context4.abrupt("return", json.data);

@@ -1055,3 +1052,3 @@

if (args == null ? void 0 : args.length) {
target += "?args=" + encodeURIComponent(JSON.stringify(transformArgs(transformers, args)));
target += "?args=" + encodeURIComponent(JSON.stringify(args.map(transformer.serialize)));
}

@@ -1096,3 +1093,3 @@

body: JSON.stringify({
args: transformArgs(transformers, args)
args: args.map(transformer.serialize)
}),

@@ -1149,13 +1146,10 @@ headers: getHeaders()

console.log('args', args);
if (!stopped) {
_context3.next = 5;
_context3.next = 3;
break;
}
console.log('subscriptions have stopped');
return _context3.abrupt("return");
case 5:
case 3:
controller = AC ? new AC() : null;

@@ -1166,3 +1160,3 @@ signal = (_controller = controller) == null ? void 0 : _controller.signal;

body: JSON.stringify({
args: transformArgs(transformers, thisArgs)
args: args.map(transformer.serialize)
}),

@@ -1172,15 +1166,13 @@ headers: getHeaders(),

});
_context3.prev = 8;
console.log('⏳ waiting for', path, thisArgs);
_context3.t0 = transformData;
_context3.t1 = transformers;
_context3.next = 14;
_context3.prev = 6;
_context3.t0 = transformer;
_context3.next = 10;
return handleResponse(promise);
case 14:
_context3.t2 = _context3.sent;
data = (0, _context3.t0)(_context3.t1, _context3.t2);
case 10:
_context3.t1 = _context3.sent;
data = _context3.t0.deserialize.call(_context3.t0, _context3.t1);
if (!stopped) {
_context3.next = 18;
_context3.next = 14;
break;

@@ -1191,17 +1183,17 @@ }

case 18:
case 14:
opts.onSuccess && opts.onSuccess(data);
nextArgs = opts.getNextArgs ? opts.getNextArgs(data) : thisArgs;
console.log('nextArgs', nextArgs);
nextArgs = opts.getNextArgs ? opts.getNextArgs(data) : thisArgs; // console.log('nextArgs', nextArgs);
attemptIndex = 0;
exec.apply(void 0, nextArgs);
_context3.next = 36;
_context3.next = 29;
break;
case 25:
_context3.prev = 25;
_context3.t3 = _context3["catch"](8);
case 20:
_context3.prev = 20;
_context3.t2 = _context3["catch"](6);
if (!stopped) {
_context3.next = 30;
_context3.next = 25;
break;

@@ -1213,5 +1205,4 @@ }

case 30:
err = _context3.t3;
console.log('❌ subscription failed :(', err.message);
case 25:
err = _context3.t2; // console.log('❌ subscription failed :(', err.message);

@@ -1224,4 +1215,4 @@ if (((_err$json = err.json) == null ? void 0 : _err$json.statusCode) === 408) {

delay = retryDelay(attemptIndex);
console.log('trying again in', delay, 'ms');
delay = retryDelay(attemptIndex); // console.log('trying again in', delay, 'ms');
nextTry = setTimeout(function () {

@@ -1231,3 +1222,3 @@ exec.apply(void 0, thisArgs);

case 36:
case 29:
case "end":

@@ -1237,3 +1228,3 @@ return _context3.stop();

}
}, _callee3, null, [[8, 25]]);
}, _callee3, null, [[6, 20]]);
}));

@@ -1244,5 +1235,5 @@

};
}();
}(); // console.log('argds', args);
console.log('argds', args);
exec.apply(void 0, args);

@@ -1262,7 +1253,7 @@ return function () {

subscription: subscription,
transformers: transformers
transformer: transformer
};
}
export { TRPCClientError, createTRPCClient, transformArgs, transformData };
export { TRPCClientError, createTRPCClient };
//# sourceMappingURL=trpc-client.esm.js.map
{
"name": "@katt/trpc-client",
"version": "1.0.0-alpha.10",
"version": "1.0.0-alpha.13",
"description": "TRPC Client lib",

@@ -30,3 +30,3 @@ "author": "KATT",

"devDependencies": {
"@katt/trpc-server": "^1.0.0-alpha.10",
"@katt/trpc-server": "^1.0.0-alpha.13",
"react-query": "^3.5.16"

@@ -37,3 +37,3 @@ },

},
"gitHead": "d9c5eeeb33f65699e06d3d77b5a31221ead5be00"
"gitHead": "dd478aa969982872b3d3e3977a46cee772c0e8c8"
}

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc