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

@katt/trpc-server

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-server - npm Package Compare versions

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

7

dist/trpc-server.cjs.development.js

@@ -1375,3 +1375,3 @@ 'use strict';

case 69:
_context.next = 75;
_context.next = 74;
break;

@@ -1382,6 +1382,5 @@

_context.t3 = _context["catch"](64);
console.error('Teardown failed');
throw _context.t3;
console.error('Teardown failed', _context.t3);
case 75:
case 74:
case "end":

@@ -1388,0 +1387,0 @@ return _context.stop();

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

"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require("events");function e(){if("undefined"!=typeof window)throw new Error("Imported server-only code in the broowser")}function r(t,e,r,n,o,i,a){try{var s=t[i](a),u=s.value}catch(t){return void r(t)}s.done?e(u):Promise.resolve(u).then(n,o)}function n(t){return function(){var e=this,n=arguments;return new Promise((function(o,i){var a=t.apply(e,n);function s(t){r(a,o,i,s,u,"next",t)}function u(t){r(a,o,i,s,u,"throw",t)}s(void 0)}))}}function o(){return(o=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var r=arguments[e];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(t[n]=r[n])}return t}).apply(this,arguments)}function i(t,e){t.prototype=Object.create(e.prototype),t.prototype.constructor=t,t.__proto__=e}function a(t){return(a=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}function s(t,e){return(s=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t})(t,e)}function u(){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 c(t,e,r){return(c=u()?Reflect.construct:function(t,e,r){var n=[null];n.push.apply(n,e);var o=new(Function.bind.apply(t,n));return r&&s(o,r.prototype),o}).apply(null,arguments)}function f(t){var e="function"==typeof Map?new Map:void 0;return(f=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!==e){if(e.has(t))return e.get(t);e.set(t,r)}function r(){return c(t,arguments,a(this).constructor)}return r.prototype=Object.create(t.prototype,{constructor:{value:r,enumerable:!1,writable:!0,configurable:!0}}),s(r,t)})(t)}function p(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}function l(t,e){return t(e={exports:{}},e.exports),e.exports}var h=l((function(t){var e=function(t){var e=Object.prototype,r=e.hasOwnProperty,n="function"==typeof Symbol?Symbol:{},o=n.iterator||"@@iterator",i=n.asyncIterator||"@@asyncIterator",a=n.toStringTag||"@@toStringTag";function s(t,e,r){return Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}),t[e]}try{s({},"")}catch(t){s=function(t,e,r){return t[e]=r}}function u(t,e,r,n){var o=Object.create((e&&e.prototype instanceof p?e:p).prototype),i=new k(n||[]);return o._invoke=function(t,e,r){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(r.method=o,r.arg=i;;){var a=r.delegate;if(a){var s=g(a,r);if(s){if(s===f)continue;return s}}if("next"===r.method)r.sent=r._sent=r.arg;else if("throw"===r.method){if("suspendedStart"===n)throw n="completed",r.arg;r.dispatchException(r.arg)}else"return"===r.method&&r.abrupt("return",r.arg);n="executing";var u=c(t,e,r);if("normal"===u.type){if(n=r.done?"completed":"suspendedYield",u.arg===f)continue;return{value:u.arg,done:r.done}}"throw"===u.type&&(n="completed",r.method="throw",r.arg=u.arg)}}}(t,r,i),o}function c(t,e,r){try{return{type:"normal",arg:t.call(e,r)}}catch(t){return{type:"throw",arg:t}}}t.wrap=u;var f={};function p(){}function l(){}function h(){}var d={};d[o]=function(){return this};var y=Object.getPrototypeOf,v=y&&y(y(_([])));v&&v!==e&&r.call(v,o)&&(d=v);var m=h.prototype=p.prototype=Object.create(d);function w(t){["next","throw","return"].forEach((function(e){s(t,e,(function(t){return this._invoke(e,t)}))}))}function b(t,e){var n;this._invoke=function(o,i){function a(){return new e((function(n,a){!function n(o,i,a,s){var u=c(t[o],t,i);if("throw"!==u.type){var f=u.arg,p=f.value;return p&&"object"==typeof p&&r.call(p,"__await")?e.resolve(p.__await).then((function(t){n("next",t,a,s)}),(function(t){n("throw",t,a,s)})):e.resolve(p).then((function(t){f.value=t,a(f)}),(function(t){return n("throw",t,a,s)}))}s(u.arg)}(o,i,n,a)}))}return n=n?n.then(a,a):a()}}function g(t,e){var r=t.iterator[e.method];if(void 0===r){if(e.delegate=null,"throw"===e.method){if(t.iterator.return&&(e.method="return",e.arg=void 0,g(t,e),"throw"===e.method))return f;e.method="throw",e.arg=new TypeError("The iterator does not provide a 'throw' method")}return f}var n=c(r,t.iterator,e.arg);if("throw"===n.type)return e.method="throw",e.arg=n.arg,e.delegate=null,f;var o=n.arg;return o?o.done?(e[t.resultName]=o.value,e.next=t.nextLoc,"return"!==e.method&&(e.method="next",e.arg=void 0),e.delegate=null,f):o:(e.method="throw",e.arg=new TypeError("iterator result is not an object"),e.delegate=null,f)}function x(t){var e={tryLoc:t[0]};1 in t&&(e.catchLoc=t[1]),2 in t&&(e.finallyLoc=t[2],e.afterLoc=t[3]),this.tryEntries.push(e)}function E(t){var e=t.completion||{};e.type="normal",delete e.arg,t.completion=e}function k(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(x,this),this.reset(!0)}function _(t){if(t){var e=t[o];if(e)return e.call(t);if("function"==typeof t.next)return t;if(!isNaN(t.length)){var n=-1,i=function e(){for(;++n<t.length;)if(r.call(t,n))return e.value=t[n],e.done=!1,e;return e.value=void 0,e.done=!0,e};return i.next=i}}return{next:O}}function O(){return{value:void 0,done:!0}}return l.prototype=m.constructor=h,h.constructor=l,l.displayName=s(h,a,"GeneratorFunction"),t.isGeneratorFunction=function(t){var e="function"==typeof t&&t.constructor;return!!e&&(e===l||"GeneratorFunction"===(e.displayName||e.name))},t.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,h):(t.__proto__=h,s(t,a,"GeneratorFunction")),t.prototype=Object.create(m),t},t.awrap=function(t){return{__await:t}},w(b.prototype),b.prototype[i]=function(){return this},t.AsyncIterator=b,t.async=function(e,r,n,o,i){void 0===i&&(i=Promise);var a=new b(u(e,r,n,o),i);return t.isGeneratorFunction(r)?a:a.next().then((function(t){return t.done?t.value:a.next()}))},w(m),s(m,a,"Generator"),m[o]=function(){return this},m.toString=function(){return"[object Generator]"},t.keys=function(t){var e=[];for(var r in t)e.push(r);return e.reverse(),function r(){for(;e.length;){var n=e.pop();if(n in t)return r.value=n,r.done=!1,r}return r.done=!0,r}},t.values=_,k.prototype={constructor:k,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(E),!t)for(var e in this)"t"===e.charAt(0)&&r.call(this,e)&&!isNaN(+e.slice(1))&&(this[e]=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 e=this;function n(r,n){return a.type="throw",a.arg=t,e.next=r,n&&(e.method="next",e.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 s=r.call(i,"catchLoc"),u=r.call(i,"finallyLoc");if(s&&u){if(this.prev<i.catchLoc)return n(i.catchLoc,!0);if(this.prev<i.finallyLoc)return n(i.finallyLoc)}else if(s){if(this.prev<i.catchLoc)return n(i.catchLoc,!0)}else{if(!u)throw new Error("try statement without catch or finally");if(this.prev<i.finallyLoc)return n(i.finallyLoc)}}}},abrupt:function(t,e){for(var n=this.tryEntries.length-1;n>=0;--n){var o=this.tryEntries[n];if(o.tryLoc<=this.prev&&r.call(o,"finallyLoc")&&this.prev<o.finallyLoc){var i=o;break}}i&&("break"===t||"continue"===t)&&i.tryLoc<=e&&e<=i.finallyLoc&&(i=null);var a=i?i.completion:{};return a.type=t,a.arg=e,i?(this.method="next",this.next=i.finallyLoc,f):this.complete(a)},complete:function(t,e){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&&e&&(this.next=e),f},finish:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.finallyLoc===t)return this.complete(r.completion,r.afterLoc),E(r),f}},catch:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.tryLoc===t){var n=r.completion;if("throw"===n.type){var o=n.arg;E(r)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(t,e,r){return this.delegate={iterator:_(t),resultName:e,nextLoc:r},"next"===this.method&&(this.arg=void 0),f}},t}(t.exports);try{regeneratorRuntime=e}catch(t){Function("r","regeneratorRuntime = r")(e)}})),d=function(){var t;return(t=console).log.apply(t,arguments)},y=function(t){function e(r){var n;return(n=t.call(this,r)||this).reason=r,Object.setPrototypeOf(p(n),e.prototype),n}return i(e,t),e}(f(Error)),v=function(t){function e(){return t.apply(this,arguments)||this}return i(e,t),e}(t.EventEmitter),m=function(){function t(t){this.isDestroyed=!1,this.events=new v,this.opts=o({getInitialData:function(){}},t),d("Subscription.constructor()")}var e=t.prototype;return e.destroy=function(t){this.isDestroyed||(d("Subscription.destroy()",t),this.isDestroyed=!0,this.events.emit("destroy",t),this.events.removeAllListeners())},e.start=function(){var t=n(h.mark((function t(){var e,r=this;return h.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(!this.isDestroyed){t.next=2;break}throw new Error("Called start() on a destroyed subscription");case 2:return t.prev=2,e={error:function(t){return r.emitError(t)},data:function(t){return r.emitData(t)}},t.next=6,this.opts.getInitialData(e);case 6:this.opts.start(e),t.next=12;break;case 9:t.prev=9,t.t0=t.catch(2),this.emitError(t.t0);case 12:case"end":return t.stop()}}),t,this,[[2,9]])})));return function(){return t.apply(this,arguments)}}(),e.onceDataAndStop=function(){var t=n(h.mark((function t(){var e=this;return h.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return d("Subscription.onceDataAsync()"),t.abrupt("return",new Promise(function(){var t=n(h.mark((function t(r,n){var o,i,a,s;return h.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:o=function(t){n(new y(t)),s()},i=function(t){r(t),s(),e.destroy("stopped")},a=function(t){n(t),s(),e.destroy("stopped")},s=function(){e.events.off("data",i),e.events.off("destroy",o),e.events.off("error",a)},e.events.once("data",i),e.events.once("destroy",o),e.events.once("error",a),e.start().catch((function(){}));case 8:case"end":return t.stop()}}),t)})));return function(e,r){return t.apply(this,arguments)}}()));case 2:case"end":return t.stop()}}),t)})));return function(){return t.apply(this,arguments)}}(),e.emitData=function(t){this.events.emit("data",this.opts.router.serializeData(t))},e.emitError=function(t){this.events.emit("error",t)},t}();e();var w=function(t){function e(r,n){var o;return(o=t.call(this,n)||this).statusCode=r,Object.setPrototypeOf(p(o),e.prototype),o}return i(e,t),e}(f(Error)),b={forbidden:function(t){return new w(403,null!=t?t:"Forbidden")},unauthorized:function(t){return new w(401,null!=t?t:"Unauthorized")},badRequest:function(t){return new w(400,null!=t?t:"Bad Request")},notFound:function(t){return new w(404,null!=t?t:"Not found")}};function g(t){return{ok:!1,statusCode:"number"==typeof(null==t?void 0:t.statusCode)?t.statusCode:500,error:{message:"string"==typeof(null==t?void 0:t.message)?t.message:"Internal Server Error",stack:void 0}}}function x(t){var e=[],r=t.query.args;if(!r)return e;if("string"!=typeof r)throw b.badRequest("Expected query.args to be a JSON string");try{e=JSON.parse(r)}catch(t){throw b.badRequest("Expected query.args to be a JSON string")}if(!Array.isArray(e))throw b.badRequest("Expected query.args to be parsed as an JSON-array");return e}function E(t){return k.apply(this,arguments)}function k(){return(k=n(h.mark((function t(e){var r,n,o,i,a,s,u,c,f,p,l,d,v,m,E,k,_,O,q,j,L,S,A,P;return h.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return r=e.req,n=e.res,o=e.router,i=e.endpoint,a=e.subscriptions,s=e.createContext,u=e.teardown,t.prev=1,t.next=4,s({req:r,res:n});case 4:if(l=t.sent,"POST"!==(d=null!=(c=r.method)?c:"GET")){t.next=17;break}if(o.has("mutations",i)){t.next=9;break}throw b.notFound('Unknown mutation "'+i+'"');case 9:if(m=null!=(v=r.body.args)?v:[],Array.isArray(m)){t.next=12;break}throw b.badRequest("Expected body.args to be an array");case 12:return t.next=14,o.invokeMutation(l).apply(void 0,[i].concat(m));case 14:p=t.sent,t.next=56;break;case 17:if("GET"!==d){t.next=26;break}if(o.has("queries",i)){t.next=20;break}throw b.notFound('Unknown query "'+i+'"');case 20:return E=x(r),t.next=23,o.invokeQuery(l).apply(void 0,[i].concat(E));case 23:p=t.sent,t.next=56;break;case 26:if("PATCH"!==d){t.next=55;break}if(o.has("subscriptions",i)){t.next=29;break}throw b.notFound('Unknown subscription "'+i+'"');case 29:if(O=null!=(k=r.body.args)?k:[],Array.isArray(O)){t.next=32;break}throw b.badRequest("Expected body.args to be an array");case 32:return t.next=34,o.invokeSubscription(l).apply(void 0,[i].concat(O));case 34:return q=t.sent,n.once("close",j=function(){q.destroy("closed")}),L=null!=(_=null==a?void 0:a.timeout)?_:9e3,S=setTimeout((function(){q.destroy("timeout")}),L),t.prev=39,t.next=42,q.onceDataAndStop();case 42:p=t.sent,n.off("close",j),t.next=53;break;case 46:if(t.prev=46,t.t0=t.catch(39),n.off("close",j),clearTimeout(S),!(t.t0 instanceof y&&"timeout"===t.t0.reason)){t.next=52;break}throw new w(408,"Subscription exceeded "+L+"ms - please reconnect.");case 52:throw t.t0;case 53:t.next=56;break;case 55:throw b.badRequest("Unexpected request method "+d);case 56:A={ok:!0,statusCode:null!=(f=n.statusCode)?f:200,data:p},n.status(A.statusCode).json(A),t.next=64;break;case 60:t.prev=60,t.t1=t.catch(1),P=g(t.t1),n.status(P.statusCode).json(P);case 64:if(t.prev=64,t.t2=u,!t.t2){t.next=69;break}return t.next=69,u();case 69:t.next=75;break;case 71:throw t.prev=71,t.t3=t.catch(64),console.error("Teardown failed"),t.t3;case 75:case"end":return t.stop()}}),t,null,[[1,60],[39,46],[64,71]])})))).apply(this,arguments)}e();var _=function(){function t(t){this._def=null!=t?t:{queries:{},mutations:{},subscriptions:{},transformers:[]}}t.prefixEndpoints=function(t,e){var r={};for(var n in t)r[e+n]=t[n];return r};var e=t.prototype;return e.transformer=function(t){return this._def.transformers.push(t),this},e.queries=function(e){var r=new t({queries:e,mutations:{},subscriptions:{},transformers:[]});return this.merge(r)},e.mutations=function(e){var r=new t({mutations:e,queries:{},subscriptions:{},transformers:[]});return this.merge(r)},e.subscriptions=function(e){var r=new t({subscriptions:e,queries:{},mutations:{},transformers:[]});return this.merge(r)},e.merge=function(e,r){var n,i=this,a="";if("string"==typeof e&&r instanceof t)a=e,n=r;else{if(!(e instanceof t))throw new Error("Invalid args");n=e}var s=Object.keys(n._def.queries).filter((function(t){return i.has("queries",t)})),u=Object.keys(n._def.mutations).filter((function(t){return i.has("mutations",t)})),c=Object.keys(n._def.subscriptions).filter((function(t){return i.has("subscriptions",t)})),f=[].concat(s,u,c);if(f.length)throw new Error("Duplicate endpoint(s): "+f.join(", "));return new t({queries:o({},this._def.queries,t.prefixEndpoints(n._def.queries,a)),mutations:o({},this._def.mutations,t.prefixEndpoints(n._def.mutations,a)),subscriptions:o({},this._def.subscriptions,t.prefixEndpoints(n._def.subscriptions,a)),transformers:[].concat(this._def.transformers,n._def.transformers)})},e.serializeData=function(){var t=n(h.mark((function t(e){return h.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,e;case 2:return t.abrupt("return",this._def.transformers.reduce((function(t,e){return e.serialize(t)}),t.sent));case 4:case"end":return t.stop()}}),t,this)})));return function(e){return t.apply(this,arguments)}}(),e.deserializeArgs=function(t){var e=this;return t.map((function(t){return e._def.transformers.reduce((function(t,e){return e.deserialize(t)}),t)}))},e.invokeMutation=function(t){var e=this;return function(r){for(var n,o=arguments.length,i=new Array(o>1?o-1:0),a=1;a<o;a++)i[a-1]=arguments[a];return e.serializeData((n=e._def.mutations)[r].apply(n,[t].concat(e.deserializeArgs(i))))}},e.invokeQuery=function(t){var e=this;return function(r){for(var n,o=arguments.length,i=new Array(o>1?o-1:0),a=1;a<o;a++)i[a-1]=arguments[a];return e.serializeData((n=e._def.queries)[r].apply(n,[t].concat(e.deserializeArgs(i))))}},e.invokeSubscription=function(t){var e=this;return function(r){for(var n,o=arguments.length,i=new Array(o>1?o-1:0),a=1;a<o;a++)i[a-1]=arguments[a];return(n=e._def.subscriptions)[r].apply(n,[t].concat(e.deserializeArgs(i)))}},e.has=function(t,e){return!!this._def[t][e]},t}();exports.HTTPError=w,exports.Router=_,exports.Subscription=m,exports.SubscriptionDestroyError=y,exports.assertNotBrowser=e,exports.createExpressMiddleware=function(t){return function(){var e=n(h.mark((function e(r,n){var i;return h.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:i=r.path.substr(1),E(o({},t,{req:r,res:n,endpoint:i}));case 2:case"end":return e.stop()}}),e)})));return function(t,r){return e.apply(this,arguments)}}()},exports.createNextApiHandler=function(t){return function(){var e=n(h.mark((function e(r,n){var i,a;return h.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(null!==(i=Array.isArray(r.query.trpc)?r.query.trpc.join("/"):null)){e.next=5;break}return a=g(new Error('Query "trpc" not found - is the file named [...trpc].ts?')),n.status(a.statusCode).json(a),e.abrupt("return");case 5:return e.next=7,E(o({},t,{req:r,res:n,endpoint:i}));case 7:case"end":return e.stop()}}),e)})));return function(t,r){return e.apply(this,arguments)}}()},exports.getErrorResponseEnvelope=g,exports.getQueryArgs=x,exports.httpError=b,exports.requestHandler=E,exports.router=function(){return new _};
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require("events");function e(){if("undefined"!=typeof window)throw new Error("Imported server-only code in the broowser")}function r(t,e,r,n,o,i,a){try{var s=t[i](a),u=s.value}catch(t){return void r(t)}s.done?e(u):Promise.resolve(u).then(n,o)}function n(t){return function(){var e=this,n=arguments;return new Promise((function(o,i){var a=t.apply(e,n);function s(t){r(a,o,i,s,u,"next",t)}function u(t){r(a,o,i,s,u,"throw",t)}s(void 0)}))}}function o(){return(o=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var r=arguments[e];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(t[n]=r[n])}return t}).apply(this,arguments)}function i(t,e){t.prototype=Object.create(e.prototype),t.prototype.constructor=t,t.__proto__=e}function a(t){return(a=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}function s(t,e){return(s=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t})(t,e)}function u(){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 c(t,e,r){return(c=u()?Reflect.construct:function(t,e,r){var n=[null];n.push.apply(n,e);var o=new(Function.bind.apply(t,n));return r&&s(o,r.prototype),o}).apply(null,arguments)}function f(t){var e="function"==typeof Map?new Map:void 0;return(f=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!==e){if(e.has(t))return e.get(t);e.set(t,r)}function r(){return c(t,arguments,a(this).constructor)}return r.prototype=Object.create(t.prototype,{constructor:{value:r,enumerable:!1,writable:!0,configurable:!0}}),s(r,t)})(t)}function p(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}function l(t,e){return t(e={exports:{}},e.exports),e.exports}var h=l((function(t){var e=function(t){var e=Object.prototype,r=e.hasOwnProperty,n="function"==typeof Symbol?Symbol:{},o=n.iterator||"@@iterator",i=n.asyncIterator||"@@asyncIterator",a=n.toStringTag||"@@toStringTag";function s(t,e,r){return Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}),t[e]}try{s({},"")}catch(t){s=function(t,e,r){return t[e]=r}}function u(t,e,r,n){var o=Object.create((e&&e.prototype instanceof p?e:p).prototype),i=new k(n||[]);return o._invoke=function(t,e,r){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(r.method=o,r.arg=i;;){var a=r.delegate;if(a){var s=g(a,r);if(s){if(s===f)continue;return s}}if("next"===r.method)r.sent=r._sent=r.arg;else if("throw"===r.method){if("suspendedStart"===n)throw n="completed",r.arg;r.dispatchException(r.arg)}else"return"===r.method&&r.abrupt("return",r.arg);n="executing";var u=c(t,e,r);if("normal"===u.type){if(n=r.done?"completed":"suspendedYield",u.arg===f)continue;return{value:u.arg,done:r.done}}"throw"===u.type&&(n="completed",r.method="throw",r.arg=u.arg)}}}(t,r,i),o}function c(t,e,r){try{return{type:"normal",arg:t.call(e,r)}}catch(t){return{type:"throw",arg:t}}}t.wrap=u;var f={};function p(){}function l(){}function h(){}var d={};d[o]=function(){return this};var y=Object.getPrototypeOf,v=y&&y(y(_([])));v&&v!==e&&r.call(v,o)&&(d=v);var m=h.prototype=p.prototype=Object.create(d);function w(t){["next","throw","return"].forEach((function(e){s(t,e,(function(t){return this._invoke(e,t)}))}))}function b(t,e){var n;this._invoke=function(o,i){function a(){return new e((function(n,a){!function n(o,i,a,s){var u=c(t[o],t,i);if("throw"!==u.type){var f=u.arg,p=f.value;return p&&"object"==typeof p&&r.call(p,"__await")?e.resolve(p.__await).then((function(t){n("next",t,a,s)}),(function(t){n("throw",t,a,s)})):e.resolve(p).then((function(t){f.value=t,a(f)}),(function(t){return n("throw",t,a,s)}))}s(u.arg)}(o,i,n,a)}))}return n=n?n.then(a,a):a()}}function g(t,e){var r=t.iterator[e.method];if(void 0===r){if(e.delegate=null,"throw"===e.method){if(t.iterator.return&&(e.method="return",e.arg=void 0,g(t,e),"throw"===e.method))return f;e.method="throw",e.arg=new TypeError("The iterator does not provide a 'throw' method")}return f}var n=c(r,t.iterator,e.arg);if("throw"===n.type)return e.method="throw",e.arg=n.arg,e.delegate=null,f;var o=n.arg;return o?o.done?(e[t.resultName]=o.value,e.next=t.nextLoc,"return"!==e.method&&(e.method="next",e.arg=void 0),e.delegate=null,f):o:(e.method="throw",e.arg=new TypeError("iterator result is not an object"),e.delegate=null,f)}function x(t){var e={tryLoc:t[0]};1 in t&&(e.catchLoc=t[1]),2 in t&&(e.finallyLoc=t[2],e.afterLoc=t[3]),this.tryEntries.push(e)}function E(t){var e=t.completion||{};e.type="normal",delete e.arg,t.completion=e}function k(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(x,this),this.reset(!0)}function _(t){if(t){var e=t[o];if(e)return e.call(t);if("function"==typeof t.next)return t;if(!isNaN(t.length)){var n=-1,i=function e(){for(;++n<t.length;)if(r.call(t,n))return e.value=t[n],e.done=!1,e;return e.value=void 0,e.done=!0,e};return i.next=i}}return{next:O}}function O(){return{value:void 0,done:!0}}return l.prototype=m.constructor=h,h.constructor=l,l.displayName=s(h,a,"GeneratorFunction"),t.isGeneratorFunction=function(t){var e="function"==typeof t&&t.constructor;return!!e&&(e===l||"GeneratorFunction"===(e.displayName||e.name))},t.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,h):(t.__proto__=h,s(t,a,"GeneratorFunction")),t.prototype=Object.create(m),t},t.awrap=function(t){return{__await:t}},w(b.prototype),b.prototype[i]=function(){return this},t.AsyncIterator=b,t.async=function(e,r,n,o,i){void 0===i&&(i=Promise);var a=new b(u(e,r,n,o),i);return t.isGeneratorFunction(r)?a:a.next().then((function(t){return t.done?t.value:a.next()}))},w(m),s(m,a,"Generator"),m[o]=function(){return this},m.toString=function(){return"[object Generator]"},t.keys=function(t){var e=[];for(var r in t)e.push(r);return e.reverse(),function r(){for(;e.length;){var n=e.pop();if(n in t)return r.value=n,r.done=!1,r}return r.done=!0,r}},t.values=_,k.prototype={constructor:k,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(E),!t)for(var e in this)"t"===e.charAt(0)&&r.call(this,e)&&!isNaN(+e.slice(1))&&(this[e]=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 e=this;function n(r,n){return a.type="throw",a.arg=t,e.next=r,n&&(e.method="next",e.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 s=r.call(i,"catchLoc"),u=r.call(i,"finallyLoc");if(s&&u){if(this.prev<i.catchLoc)return n(i.catchLoc,!0);if(this.prev<i.finallyLoc)return n(i.finallyLoc)}else if(s){if(this.prev<i.catchLoc)return n(i.catchLoc,!0)}else{if(!u)throw new Error("try statement without catch or finally");if(this.prev<i.finallyLoc)return n(i.finallyLoc)}}}},abrupt:function(t,e){for(var n=this.tryEntries.length-1;n>=0;--n){var o=this.tryEntries[n];if(o.tryLoc<=this.prev&&r.call(o,"finallyLoc")&&this.prev<o.finallyLoc){var i=o;break}}i&&("break"===t||"continue"===t)&&i.tryLoc<=e&&e<=i.finallyLoc&&(i=null);var a=i?i.completion:{};return a.type=t,a.arg=e,i?(this.method="next",this.next=i.finallyLoc,f):this.complete(a)},complete:function(t,e){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&&e&&(this.next=e),f},finish:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.finallyLoc===t)return this.complete(r.completion,r.afterLoc),E(r),f}},catch:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.tryLoc===t){var n=r.completion;if("throw"===n.type){var o=n.arg;E(r)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(t,e,r){return this.delegate={iterator:_(t),resultName:e,nextLoc:r},"next"===this.method&&(this.arg=void 0),f}},t}(t.exports);try{regeneratorRuntime=e}catch(t){Function("r","regeneratorRuntime = r")(e)}})),d=function(){var t;return(t=console).log.apply(t,arguments)},y=function(t){function e(r){var n;return(n=t.call(this,r)||this).reason=r,Object.setPrototypeOf(p(n),e.prototype),n}return i(e,t),e}(f(Error)),v=function(t){function e(){return t.apply(this,arguments)||this}return i(e,t),e}(t.EventEmitter),m=function(){function t(t){this.isDestroyed=!1,this.events=new v,this.opts=o({getInitialData:function(){}},t),d("Subscription.constructor()")}var e=t.prototype;return e.destroy=function(t){this.isDestroyed||(d("Subscription.destroy()",t),this.isDestroyed=!0,this.events.emit("destroy",t),this.events.removeAllListeners())},e.start=function(){var t=n(h.mark((function t(){var e,r=this;return h.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(!this.isDestroyed){t.next=2;break}throw new Error("Called start() on a destroyed subscription");case 2:return t.prev=2,e={error:function(t){return r.emitError(t)},data:function(t){return r.emitData(t)}},t.next=6,this.opts.getInitialData(e);case 6:this.opts.start(e),t.next=12;break;case 9:t.prev=9,t.t0=t.catch(2),this.emitError(t.t0);case 12:case"end":return t.stop()}}),t,this,[[2,9]])})));return function(){return t.apply(this,arguments)}}(),e.onceDataAndStop=function(){var t=n(h.mark((function t(){var e=this;return h.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return d("Subscription.onceDataAsync()"),t.abrupt("return",new Promise(function(){var t=n(h.mark((function t(r,n){var o,i,a,s;return h.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:o=function(t){n(new y(t)),s()},i=function(t){r(t),s(),e.destroy("stopped")},a=function(t){n(t),s(),e.destroy("stopped")},s=function(){e.events.off("data",i),e.events.off("destroy",o),e.events.off("error",a)},e.events.once("data",i),e.events.once("destroy",o),e.events.once("error",a),e.start().catch((function(){}));case 8:case"end":return t.stop()}}),t)})));return function(e,r){return t.apply(this,arguments)}}()));case 2:case"end":return t.stop()}}),t)})));return function(){return t.apply(this,arguments)}}(),e.emitData=function(t){this.events.emit("data",this.opts.router.serializeData(t))},e.emitError=function(t){this.events.emit("error",t)},t}();e();var w=function(t){function e(r,n){var o;return(o=t.call(this,n)||this).statusCode=r,Object.setPrototypeOf(p(o),e.prototype),o}return i(e,t),e}(f(Error)),b={forbidden:function(t){return new w(403,null!=t?t:"Forbidden")},unauthorized:function(t){return new w(401,null!=t?t:"Unauthorized")},badRequest:function(t){return new w(400,null!=t?t:"Bad Request")},notFound:function(t){return new w(404,null!=t?t:"Not found")}};function g(t){return{ok:!1,statusCode:"number"==typeof(null==t?void 0:t.statusCode)?t.statusCode:500,error:{message:"string"==typeof(null==t?void 0:t.message)?t.message:"Internal Server Error",stack:void 0}}}function x(t){var e=[],r=t.query.args;if(!r)return e;if("string"!=typeof r)throw b.badRequest("Expected query.args to be a JSON string");try{e=JSON.parse(r)}catch(t){throw b.badRequest("Expected query.args to be a JSON string")}if(!Array.isArray(e))throw b.badRequest("Expected query.args to be parsed as an JSON-array");return e}function E(t){return k.apply(this,arguments)}function k(){return(k=n(h.mark((function t(e){var r,n,o,i,a,s,u,c,f,p,l,d,v,m,E,k,_,O,q,j,L,S,A,P;return h.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return r=e.req,n=e.res,o=e.router,i=e.endpoint,a=e.subscriptions,s=e.createContext,u=e.teardown,t.prev=1,t.next=4,s({req:r,res:n});case 4:if(l=t.sent,"POST"!==(d=null!=(c=r.method)?c:"GET")){t.next=17;break}if(o.has("mutations",i)){t.next=9;break}throw b.notFound('Unknown mutation "'+i+'"');case 9:if(m=null!=(v=r.body.args)?v:[],Array.isArray(m)){t.next=12;break}throw b.badRequest("Expected body.args to be an array");case 12:return t.next=14,o.invokeMutation(l).apply(void 0,[i].concat(m));case 14:p=t.sent,t.next=56;break;case 17:if("GET"!==d){t.next=26;break}if(o.has("queries",i)){t.next=20;break}throw b.notFound('Unknown query "'+i+'"');case 20:return E=x(r),t.next=23,o.invokeQuery(l).apply(void 0,[i].concat(E));case 23:p=t.sent,t.next=56;break;case 26:if("PATCH"!==d){t.next=55;break}if(o.has("subscriptions",i)){t.next=29;break}throw b.notFound('Unknown subscription "'+i+'"');case 29:if(O=null!=(k=r.body.args)?k:[],Array.isArray(O)){t.next=32;break}throw b.badRequest("Expected body.args to be an array");case 32:return t.next=34,o.invokeSubscription(l).apply(void 0,[i].concat(O));case 34:return q=t.sent,n.once("close",j=function(){q.destroy("closed")}),L=null!=(_=null==a?void 0:a.timeout)?_:9e3,S=setTimeout((function(){q.destroy("timeout")}),L),t.prev=39,t.next=42,q.onceDataAndStop();case 42:p=t.sent,n.off("close",j),t.next=53;break;case 46:if(t.prev=46,t.t0=t.catch(39),n.off("close",j),clearTimeout(S),!(t.t0 instanceof y&&"timeout"===t.t0.reason)){t.next=52;break}throw new w(408,"Subscription exceeded "+L+"ms - please reconnect.");case 52:throw t.t0;case 53:t.next=56;break;case 55:throw b.badRequest("Unexpected request method "+d);case 56:A={ok:!0,statusCode:null!=(f=n.statusCode)?f:200,data:p},n.status(A.statusCode).json(A),t.next=64;break;case 60:t.prev=60,t.t1=t.catch(1),P=g(t.t1),n.status(P.statusCode).json(P);case 64:if(t.prev=64,t.t2=u,!t.t2){t.next=69;break}return t.next=69,u();case 69:t.next=74;break;case 71:t.prev=71,t.t3=t.catch(64),console.error("Teardown failed",t.t3);case 74:case"end":return t.stop()}}),t,null,[[1,60],[39,46],[64,71]])})))).apply(this,arguments)}e();var _=function(){function t(t){this._def=null!=t?t:{queries:{},mutations:{},subscriptions:{},transformers:[]}}t.prefixEndpoints=function(t,e){var r={};for(var n in t)r[e+n]=t[n];return r};var e=t.prototype;return e.transformer=function(t){return this._def.transformers.push(t),this},e.queries=function(e){var r=new t({queries:e,mutations:{},subscriptions:{},transformers:[]});return this.merge(r)},e.mutations=function(e){var r=new t({mutations:e,queries:{},subscriptions:{},transformers:[]});return this.merge(r)},e.subscriptions=function(e){var r=new t({subscriptions:e,queries:{},mutations:{},transformers:[]});return this.merge(r)},e.merge=function(e,r){var n,i=this,a="";if("string"==typeof e&&r instanceof t)a=e,n=r;else{if(!(e instanceof t))throw new Error("Invalid args");n=e}var s=Object.keys(n._def.queries).filter((function(t){return i.has("queries",t)})),u=Object.keys(n._def.mutations).filter((function(t){return i.has("mutations",t)})),c=Object.keys(n._def.subscriptions).filter((function(t){return i.has("subscriptions",t)})),f=[].concat(s,u,c);if(f.length)throw new Error("Duplicate endpoint(s): "+f.join(", "));return new t({queries:o({},this._def.queries,t.prefixEndpoints(n._def.queries,a)),mutations:o({},this._def.mutations,t.prefixEndpoints(n._def.mutations,a)),subscriptions:o({},this._def.subscriptions,t.prefixEndpoints(n._def.subscriptions,a)),transformers:[].concat(this._def.transformers,n._def.transformers)})},e.serializeData=function(){var t=n(h.mark((function t(e){return h.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,e;case 2:return t.abrupt("return",this._def.transformers.reduce((function(t,e){return e.serialize(t)}),t.sent));case 4:case"end":return t.stop()}}),t,this)})));return function(e){return t.apply(this,arguments)}}(),e.deserializeArgs=function(t){var e=this;return t.map((function(t){return e._def.transformers.reduce((function(t,e){return e.deserialize(t)}),t)}))},e.invokeMutation=function(t){var e=this;return function(r){for(var n,o=arguments.length,i=new Array(o>1?o-1:0),a=1;a<o;a++)i[a-1]=arguments[a];return e.serializeData((n=e._def.mutations)[r].apply(n,[t].concat(e.deserializeArgs(i))))}},e.invokeQuery=function(t){var e=this;return function(r){for(var n,o=arguments.length,i=new Array(o>1?o-1:0),a=1;a<o;a++)i[a-1]=arguments[a];return e.serializeData((n=e._def.queries)[r].apply(n,[t].concat(e.deserializeArgs(i))))}},e.invokeSubscription=function(t){var e=this;return function(r){for(var n,o=arguments.length,i=new Array(o>1?o-1:0),a=1;a<o;a++)i[a-1]=arguments[a];return(n=e._def.subscriptions)[r].apply(n,[t].concat(e.deserializeArgs(i)))}},e.has=function(t,e){return!!this._def[t][e]},t}();exports.HTTPError=w,exports.Router=_,exports.Subscription=m,exports.SubscriptionDestroyError=y,exports.assertNotBrowser=e,exports.createExpressMiddleware=function(t){return function(){var e=n(h.mark((function e(r,n){var i;return h.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:i=r.path.substr(1),E(o({},t,{req:r,res:n,endpoint:i}));case 2:case"end":return e.stop()}}),e)})));return function(t,r){return e.apply(this,arguments)}}()},exports.createNextApiHandler=function(t){return function(){var e=n(h.mark((function e(r,n){var i,a;return h.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(null!==(i=Array.isArray(r.query.trpc)?r.query.trpc.join("/"):null)){e.next=5;break}return a=g(new Error('Query "trpc" not found - is the file named [...trpc].ts?')),n.status(a.statusCode).json(a),e.abrupt("return");case 5:return e.next=7,E(o({},t,{req:r,res:n,endpoint:i}));case 7:case"end":return e.stop()}}),e)})));return function(t,r){return e.apply(this,arguments)}}()},exports.getErrorResponseEnvelope=g,exports.getQueryArgs=x,exports.httpError=b,exports.requestHandler=E,exports.router=function(){return new _};
//# sourceMappingURL=trpc-server.cjs.production.min.js.map

@@ -1371,3 +1371,3 @@ import { EventEmitter } from 'events';

case 69:
_context.next = 75;
_context.next = 74;
break;

@@ -1378,6 +1378,5 @@

_context.t3 = _context["catch"](64);
console.error('Teardown failed');
throw _context.t3;
console.error('Teardown failed', _context.t3);
case 75:
case 74:
case "end":

@@ -1384,0 +1383,0 @@ return _context.stop();

{
"name": "@katt/trpc-server",
"version": "1.0.0-alpha.9",
"version": "1.0.0-alpha.10",
"description": "TRPC Server",

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

},
"gitHead": "bc992454cc7123e5f01a9e8849a9c8f5d0b64c30"
"gitHead": "d9c5eeeb33f65699e06d3d77b5a31221ead5be00"
}

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