@trpc/server
Advanced tools
Comparing version 1.2.0 to 1.3.0-alpha.0
@@ -10,8 +10,3 @@ import { Subscription } from './subscription'; | ||
}; | ||
export declare type RouteInputParserJoiEsque<TInput = unknown> = { | ||
validate: (input: unknown) => { | ||
value: TInput; | ||
}; | ||
}; | ||
export declare type RouteInputParser<TInput = unknown> = RouteInputParserZodEsque<TInput> | RouteInputParserYupEsque<TInput> | RouteInputParserCustomValidatorEsque<TInput> | RouteInputParserJoiEsque<TInput>; | ||
export declare type RouteInputParser<TInput = unknown> = RouteInputParserZodEsque<TInput> | RouteInputParserYupEsque<TInput> | RouteInputParserCustomValidatorEsque<TInput>; | ||
export declare type RouteResolver<TContext = unknown, TInput = unknown, TOutput = unknown> = (opts: { | ||
@@ -18,0 +13,0 @@ ctx: TContext; |
@@ -1490,7 +1490,7 @@ 'use strict'; | ||
statusCode: (_res$statusCode = res.statusCode) != null ? _res$statusCode : 200, | ||
data: transformer.serialize(output) | ||
data: output | ||
}; | ||
res.statusCode = json.statusCode; | ||
res.setHeader('Content-Type', 'application/json'); | ||
res.end(JSON.stringify(json)); | ||
res.end(JSON.stringify(transformer.serialize(json))); | ||
_context2.next = 69; | ||
@@ -1505,3 +1505,3 @@ break; | ||
res.setHeader('Content-Type', 'application/json'); | ||
res.end(JSON.stringify(_json)); | ||
res.end(JSON.stringify(transformer.serialize(_json))); | ||
@@ -1508,0 +1508,0 @@ case 69: |
@@ -1,2 +0,2 @@ | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t,e=require("events"),r=(t=require("url"))&&"object"==typeof t&&"default"in t?t.default:t;function n(){if("undefined"!=typeof window&&void 0===process.env.JEST_WORKER_ID)throw new Error("Imported server-only code in the broowser")}function o(t,e,r,n,o,i,u){try{var a=t[i](u),s=a.value}catch(t){return void r(t)}a.done?e(s):Promise.resolve(s).then(n,o)}function i(t){return function(){var e=this,r=arguments;return new Promise((function(n,i){var u=t.apply(e,r);function a(t){o(u,n,i,a,s,"next",t)}function s(t){o(u,n,i,a,s,"throw",t)}a(void 0)}))}}function u(){return(u=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 a(t,e){t.prototype=Object.create(e.prototype),t.prototype.constructor=t,t.__proto__=e}function s(t){return(s=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}function c(t,e){return(c=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t})(t,e)}function f(){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 p(t,e,r){return(p=f()?Reflect.construct:function(t,e,r){var n=[null];n.push.apply(n,e);var o=new(Function.bind.apply(t,n));return r&&c(o,r.prototype),o}).apply(null,arguments)}function l(t){var e="function"==typeof Map?new Map:void 0;return(l=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 p(t,arguments,s(this).constructor)}return r.prototype=Object.create(t.prototype,{constructor:{value:r,enumerable:!1,writable:!0,configurable:!0}}),c(r,t)})(t)}function h(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}function d(t,e){return t(e={exports:{}},e.exports),e.exports}var y=d((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",u=n.toStringTag||"@@toStringTag";function a(t,e,r){return Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}),t[e]}try{a({},"")}catch(t){a=function(t,e,r){return t[e]=r}}function s(t,e,r,n){var o=Object.create((e&&e.prototype instanceof p?e:p).prototype),i=new O(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 u=r.delegate;if(u){var a=g(u,r);if(a){if(a===f)continue;return a}}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 s=c(t,e,r);if("normal"===s.type){if(n=r.done?"completed":"suspendedYield",s.arg===f)continue;return{value:s.arg,done:r.done}}"throw"===s.type&&(n="completed",r.method="throw",r.arg=s.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=s;var f={};function p(){}function l(){}function h(){}var d={};d[o]=function(){return this};var y=Object.getPrototypeOf,v=y&&y(y(k([])));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){a(t,e,(function(t){return this._invoke(e,t)}))}))}function x(t,e){var n;this._invoke=function(o,i){function u(){return new e((function(n,u){!function n(o,i,u,a){var s=c(t[o],t,i);if("throw"!==s.type){var f=s.arg,p=f.value;return p&&"object"==typeof p&&r.call(p,"__await")?e.resolve(p.__await).then((function(t){n("next",t,u,a)}),(function(t){n("throw",t,u,a)})):e.resolve(p).then((function(t){f.value=t,u(f)}),(function(t){return n("throw",t,u,a)}))}a(s.arg)}(o,i,n,u)}))}return n=n?n.then(u,u):u()}}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 b(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 O(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(b,this),this.reset(!0)}function k(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:_}}function _(){return{value:void 0,done:!0}}return l.prototype=m.constructor=h,h.constructor=l,l.displayName=a(h,u,"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,a(t,u,"GeneratorFunction")),t.prototype=Object.create(m),t},t.awrap=function(t){return{__await:t}},w(x.prototype),x.prototype[i]=function(){return this},t.AsyncIterator=x,t.async=function(e,r,n,o,i){void 0===i&&(i=Promise);var u=new x(s(e,r,n,o),i);return t.isGeneratorFunction(r)?u:u.next().then((function(t){return t.done?t.value:u.next()}))},w(m),a(m,u,"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,O.prototype={constructor:O,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 u.type="throw",u.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],u=i.completion;if("root"===i.tryLoc)return n("end");if(i.tryLoc<=this.prev){var a=r.call(i,"catchLoc"),s=r.call(i,"finallyLoc");if(a&&s){if(this.prev<i.catchLoc)return n(i.catchLoc,!0);if(this.prev<i.finallyLoc)return n(i.finallyLoc)}else if(a){if(this.prev<i.catchLoc)return n(i.catchLoc,!0)}else{if(!s)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 u=i?i.completion:{};return u.type=t,u.arg=e,i?(this.method="next",this.next=i.finallyLoc,f):this.complete(u)},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:k(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)}})),v=function(t){function e(r){var n;return(n=t.call(this,r.message)||this).originalError=r,Object.setPrototypeOf(h(n),e.prototype),n}return a(e,t),e}(l(Error)),m=function(t){function e(r){var n;return n=t.call(this,r)||this,Object.setPrototypeOf(h(n),e.prototype),n}return a(e,t),e}(l(Error)),w=function(t){function e(r){var n;return(n=t.call(this,r)||this).reason=r,Object.setPrototypeOf(h(n),e.prototype),n}return a(e,t),e}(l(Error)),x=function(t){function e(){return t.apply(this,arguments)||this}return a(e,t),e}(e.EventEmitter),g=function(){function t(t){this.isDestroyed=!1,this.events=new x,this.opts=u({getInitialOutput:function(){}},t)}var e=t.prototype;return e.destroy=function(t){this.isDestroyed||(this.isDestroyed=!0,this.events.emit("destroy",t),this.events.removeAllListeners())},e.start=function(){var t=i(y.mark((function t(){var e,r,n=this;return y.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 n.emitError(t)},data:function(t){return n.emitOutput(t)}},t.next=6,this.opts.getInitialOutput(e);case 6:r=this.opts.start(e),this.events.on("destroy",(function(){r()})),t.next=13;break;case 10:t.prev=10,t.t0=t.catch(2),this.emitError(t.t0);case 13:case"end":return t.stop()}}),t,this,[[2,10]])})));return function(){return t.apply(this,arguments)}}(),e.onceOutputAndStop=function(){var t=i(y.mark((function t(){var e=this;return y.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.abrupt("return",new Promise(function(){var t=i(y.mark((function t(r,n){var o,i,u,a;return y.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:o=function(t){n(new w(t)),a()},i=function(t){r(t),a(),e.destroy("stopped")},u=function(t){n(t),a(),e.destroy("stopped")},a=function(){e.events.off("data",i),e.events.off("destroy",o),e.events.off("error",u)},e.events.once("data",i),e.events.once("destroy",o),e.events.once("error",u),e.start().catch((function(){}));case 8:case"end":return t.stop()}}),t)})));return function(e,r){return t.apply(this,arguments)}}()));case 1:case"end":return t.stop()}}),t)})));return function(){return t.apply(this,arguments)}}(),e.emitOutput=function(t){this.events.emit("data",t)},e.emitError=function(t){this.events.emit("error",t)},t}();n();var b=function(t){function e(r,n){var o;return(o=t.call(this,n)||this).statusCode=r,Object.setPrototypeOf(h(o),e.prototype),o}return a(e,t),e}(l(Error)),E={forbidden:function(t){return new b(403,null!=t?t:"Forbidden")},unauthorized:function(t){return new b(401,null!=t?t:"Unauthorized")},badRequest:function(t){return new b(400,null!=t?t:"Bad Request")},notFound:function(t){return new b(404,null!=t?t:"Not found")},payloadTooLarge:function(t){return new b(413,null!=t?t:"Payload Too Large")}};function O(t){var e,r,n=t;return n instanceof v?n=E.badRequest(n.message):n instanceof m&&(n=E.notFound(n.message)),{ok:!1,statusCode:"number"==typeof(null==(e=n)?void 0:e.statusCode)?n.statusCode:500,error:{message:"string"==typeof(null==(r=n)?void 0:r.message)?n.message:"Internal Server Error",stack:void 0}}}function k(t){var e=void 0,r=t.input;if(!r)return e;if("string"!=typeof r)throw E.badRequest("Expected query.input to be a JSON string");try{e=JSON.parse(r)}catch(t){throw E.badRequest("Expected query.input to be a JSON string")}return e}function _(t){return q.apply(this,arguments)}function q(){return(q=i(y.mark((function t(e){var r,n;return y.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return r=e.req,n=e.maxBodySize,t.abrupt("return",new Promise((function(t,e){if(r.body)t(r.body);else{var o="";r.on("data",(function(t){o+=t,"number"==typeof n&&o.length>n&&(e(E.payloadTooLarge()),r.connection.destroy())})),r.on("end",(function(){try{var r=JSON.parse(o);t(r)}catch(t){e(E.badRequest("Body couldn't be parsed as json"))}}))}})));case 2:case"end":return t.stop()}}),t)})))).apply(this,arguments)}function j(t){return L.apply(this,arguments)}function L(){return(L=i(y.mark((function t(e){var n,o,i,u,a,s,c,f,p,l,h,d,v,m,x,g,q,j,L,S,P,R,T,N,C,F,I;return y.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(n=e.req,o=e.res,i=e.router,u=e.endpoint,a=e.subscriptions,s=e.createContext,c=e.teardown,p=void 0===(f=e.transformer)?{serialize:function(t){return t},deserialize:function(t){return t}}:f,l=e.maxBodySize,t.prev=1,t.t0=s,!t.t0){t.next=7;break}return t.next=6,s({req:n,res:o});case 6:t.t0=t.sent;case 7:if(m=t.t0,x=null!=(h=n.method)?h:"GET",g=function(t){return t?p.deserialize(t):t},"POST"!==x){t.next=20;break}return t.next=13,_({req:n,maxBodySize:l});case 13:return q=g(t.sent.input),t.next=17,i.invoke({target:"mutations",input:q,ctx:m,path:u});case 17:v=t.sent,t.next=57;break;case 20:if("GET"!==x){t.next=28;break}return j=n.query?n.query:r.parse(n.url,!0).query,L=g(k(j)),t.next=25,i.invoke({target:"queries",input:L,ctx:m,path:u});case 25:v=t.sent,t.next=57;break;case 28:if("PATCH"!==x){t.next=56;break}return t.next=31,_({req:n,maxBodySize:l});case 31:return P=g(t.sent.input),t.next=35,i.invoke({target:"subscriptions",input:P,ctx:m,path:u});case 35:return R=t.sent,o.once("close",T=function(){R.destroy("closed")}),N=null!=(S=null==a?void 0:a.timeout)?S:9e3,C=setTimeout((function(){R.destroy("timeout")}),N),t.prev=40,t.next=43,R.onceOutputAndStop();case 43:v=t.sent,o.off("close",T),t.next=54;break;case 47:if(t.prev=47,t.t1=t.catch(40),o.off("close",T),clearTimeout(C),!(t.t1 instanceof w&&"timeout"===t.t1.reason)){t.next=53;break}throw new b(408,"Subscription exceeded "+N+"ms - please reconnect.");case 53:throw t.t1;case 54:t.next=57;break;case 56:throw E.badRequest("Unexpected request method "+x);case 57:F={ok:!0,statusCode:null!=(d=o.statusCode)?d:200,data:p.serialize(v)},o.statusCode=F.statusCode,o.setHeader("Content-Type","application/json"),o.end(JSON.stringify(F)),t.next=69;break;case 63:t.prev=63,t.t2=t.catch(1),I=O(t.t2),o.statusCode=I.statusCode,o.setHeader("Content-Type","application/json"),o.end(JSON.stringify(I));case 69:if(t.prev=69,t.t3=c,!t.t3){t.next=74;break}return t.next=74,c();case 74:t.next=79;break;case 76:t.prev=76,t.t4=t.catch(69),console.error("Teardown failed",t.t4);case 79:case"end":return t.stop()}}),t,null,[[1,63],[40,47],[69,76]])})))).apply(this,arguments)}n();var S=function(){function t(t){this._def=null!=t?t:{queries:{},mutations:{},subscriptions:{}}}t.prefixRoutes=function(t,e){var r={};for(var n in t)r[e+n]=t[n];return r};var e=t.prototype;return e.query=function(e,r){var n,o=new t({queries:(n={},n[e]=r,n),mutations:{},subscriptions:{}});return this.merge(o)},e.mutation=function(e,r){var n,o=new t({queries:{},mutations:(n={},n[e]=r,n),subscriptions:{}});return this.merge(o)},e.subscription=function(e,r){var n,o=new t({queries:{},mutations:{},subscriptions:(n={},n[e]=r,n)});return this.merge(o)},e.merge=function(e,r){var n,o=this,i="";if("string"==typeof e&&r instanceof t)i=e,n=r;else{if(!(e instanceof t))throw new Error("Invalid args");n=e}var a=Object.keys(n._def.queries).filter((function(t){return o.has("queries",t)})),s=Object.keys(n._def.mutations).filter((function(t){return o.has("mutations",t)})),c=Object.keys(n._def.subscriptions).filter((function(t){return o.has("subscriptions",t)})),f=[].concat(a,s,c);if(f.length)throw new Error("Duplicate endpoint(s): "+f.join(", "));return new t({queries:u({},this._def.queries,t.prefixRoutes(n._def.queries,i)),mutations:u({},this._def.mutations,t.prefixRoutes(n._def.mutations,i)),subscriptions:u({},this._def.subscriptions,t.prefixRoutes(n._def.subscriptions,i))})},t.getInput=function(t,e){if(t.input)try{var r=t.input;if("function"==typeof r.parse)return r.parse(e);if("function"==typeof r)return r(e);if("function"==typeof r.validateSync)return r.validateSync(e);throw new Error("Could not find a validator fn")}catch(t){throw new v(t)}},e.invoke=function(){var e=i(y.mark((function e(r){var n,o;return y.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(this.has(r.target,r.path)){e.next=2;break}throw new m('No such route "'+r.path+'"');case 2:return o=t.getInput(n=this._def[r.target][r.path],r.input),e.abrupt("return",n.resolve({ctx:r.ctx,input:o}));case 7:case"end":return e.stop()}}),e,this)})));return function(t){return e.apply(this,arguments)}}(),e.has=function(t,e){return!!this._def[t][e]},t}();exports.HTTPError=b,exports.Router=S,exports.Subscription=g,exports.SubscriptionDestroyError=w,exports.assertNotBrowser=n,exports.createExpressMiddleware=function(t){return function(e,r){var n=e.path.substr(1);j(u({},t,{req:e,res:r,endpoint:n}))}},exports.createNextApiHandler=function(t){return function(){var e=i(y.mark((function e(r,n){var o,i;return y.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(null!==(o=Array.isArray(r.query.trpc)?r.query.trpc.join("/"):null)){e.next=5;break}return i=O(new Error('Query "trpc" not found - is the file named [...trpc].ts?')),n.status(i.statusCode).json(i),e.abrupt("return");case 5:return e.next=7,j(u({},t,{req:r,res:n,endpoint:o}));case 7:case"end":return e.stop()}}),e)})));return function(t,r){return e.apply(this,arguments)}}()},exports.getErrorResponseEnvelope=O,exports.getQueryInput=k,exports.httpError=E,exports.requestHandler=j,exports.router=function(){return new S},exports.subscriptionPullFatory=function(t){var e,r=!1;function n(t){return o.apply(this,arguments)}function o(){return(o=i(y.mark((function o(i){return y.wrap((function(o){for(;;)switch(o.prev=o.next){case 0:if(!r){o.next=2;break}return o.abrupt("return");case 2:return o.prev=2,o.next=5,t.pull(i);case 5:o.next=10;break;case 7:o.prev=7,o.t0=o.catch(2),i.error(o.t0);case 10:r||(e=setTimeout((function(){return n(i)}),t.interval));case 11:case"end":return o.stop()}}),o,null,[[2,7]])})))).apply(this,arguments)}return new g({start:function(t){return n(t),function(){clearTimeout(e),r=!0}}})}; | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t,e=require("events"),r=(t=require("url"))&&"object"==typeof t&&"default"in t?t.default:t;function n(){if("undefined"!=typeof window&&void 0===process.env.JEST_WORKER_ID)throw new Error("Imported server-only code in the broowser")}function o(t,e,r,n,o,i,u){try{var a=t[i](u),s=a.value}catch(t){return void r(t)}a.done?e(s):Promise.resolve(s).then(n,o)}function i(t){return function(){var e=this,r=arguments;return new Promise((function(n,i){var u=t.apply(e,r);function a(t){o(u,n,i,a,s,"next",t)}function s(t){o(u,n,i,a,s,"throw",t)}a(void 0)}))}}function u(){return(u=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 a(t,e){t.prototype=Object.create(e.prototype),t.prototype.constructor=t,t.__proto__=e}function s(t){return(s=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}function c(t,e){return(c=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t})(t,e)}function f(){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 p(t,e,r){return(p=f()?Reflect.construct:function(t,e,r){var n=[null];n.push.apply(n,e);var o=new(Function.bind.apply(t,n));return r&&c(o,r.prototype),o}).apply(null,arguments)}function l(t){var e="function"==typeof Map?new Map:void 0;return(l=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 p(t,arguments,s(this).constructor)}return r.prototype=Object.create(t.prototype,{constructor:{value:r,enumerable:!1,writable:!0,configurable:!0}}),c(r,t)})(t)}function h(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}function d(t,e){return t(e={exports:{}},e.exports),e.exports}var y=d((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",u=n.toStringTag||"@@toStringTag";function a(t,e,r){return Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}),t[e]}try{a({},"")}catch(t){a=function(t,e,r){return t[e]=r}}function s(t,e,r,n){var o=Object.create((e&&e.prototype instanceof p?e:p).prototype),i=new O(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 u=r.delegate;if(u){var a=g(u,r);if(a){if(a===f)continue;return a}}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 s=c(t,e,r);if("normal"===s.type){if(n=r.done?"completed":"suspendedYield",s.arg===f)continue;return{value:s.arg,done:r.done}}"throw"===s.type&&(n="completed",r.method="throw",r.arg=s.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=s;var f={};function p(){}function l(){}function h(){}var d={};d[o]=function(){return this};var y=Object.getPrototypeOf,v=y&&y(y(k([])));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){a(t,e,(function(t){return this._invoke(e,t)}))}))}function x(t,e){var n;this._invoke=function(o,i){function u(){return new e((function(n,u){!function n(o,i,u,a){var s=c(t[o],t,i);if("throw"!==s.type){var f=s.arg,p=f.value;return p&&"object"==typeof p&&r.call(p,"__await")?e.resolve(p.__await).then((function(t){n("next",t,u,a)}),(function(t){n("throw",t,u,a)})):e.resolve(p).then((function(t){f.value=t,u(f)}),(function(t){return n("throw",t,u,a)}))}a(s.arg)}(o,i,n,u)}))}return n=n?n.then(u,u):u()}}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 b(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 O(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(b,this),this.reset(!0)}function k(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:_}}function _(){return{value:void 0,done:!0}}return l.prototype=m.constructor=h,h.constructor=l,l.displayName=a(h,u,"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,a(t,u,"GeneratorFunction")),t.prototype=Object.create(m),t},t.awrap=function(t){return{__await:t}},w(x.prototype),x.prototype[i]=function(){return this},t.AsyncIterator=x,t.async=function(e,r,n,o,i){void 0===i&&(i=Promise);var u=new x(s(e,r,n,o),i);return t.isGeneratorFunction(r)?u:u.next().then((function(t){return t.done?t.value:u.next()}))},w(m),a(m,u,"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,O.prototype={constructor:O,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 u.type="throw",u.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],u=i.completion;if("root"===i.tryLoc)return n("end");if(i.tryLoc<=this.prev){var a=r.call(i,"catchLoc"),s=r.call(i,"finallyLoc");if(a&&s){if(this.prev<i.catchLoc)return n(i.catchLoc,!0);if(this.prev<i.finallyLoc)return n(i.finallyLoc)}else if(a){if(this.prev<i.catchLoc)return n(i.catchLoc,!0)}else{if(!s)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 u=i?i.completion:{};return u.type=t,u.arg=e,i?(this.method="next",this.next=i.finallyLoc,f):this.complete(u)},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:k(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)}})),v=function(t){function e(r){var n;return(n=t.call(this,r.message)||this).originalError=r,Object.setPrototypeOf(h(n),e.prototype),n}return a(e,t),e}(l(Error)),m=function(t){function e(r){var n;return n=t.call(this,r)||this,Object.setPrototypeOf(h(n),e.prototype),n}return a(e,t),e}(l(Error)),w=function(t){function e(r){var n;return(n=t.call(this,r)||this).reason=r,Object.setPrototypeOf(h(n),e.prototype),n}return a(e,t),e}(l(Error)),x=function(t){function e(){return t.apply(this,arguments)||this}return a(e,t),e}(e.EventEmitter),g=function(){function t(t){this.isDestroyed=!1,this.events=new x,this.opts=u({getInitialOutput:function(){}},t)}var e=t.prototype;return e.destroy=function(t){this.isDestroyed||(this.isDestroyed=!0,this.events.emit("destroy",t),this.events.removeAllListeners())},e.start=function(){var t=i(y.mark((function t(){var e,r,n=this;return y.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 n.emitError(t)},data:function(t){return n.emitOutput(t)}},t.next=6,this.opts.getInitialOutput(e);case 6:r=this.opts.start(e),this.events.on("destroy",(function(){r()})),t.next=13;break;case 10:t.prev=10,t.t0=t.catch(2),this.emitError(t.t0);case 13:case"end":return t.stop()}}),t,this,[[2,10]])})));return function(){return t.apply(this,arguments)}}(),e.onceOutputAndStop=function(){var t=i(y.mark((function t(){var e=this;return y.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.abrupt("return",new Promise(function(){var t=i(y.mark((function t(r,n){var o,i,u,a;return y.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:o=function(t){n(new w(t)),a()},i=function(t){r(t),a(),e.destroy("stopped")},u=function(t){n(t),a(),e.destroy("stopped")},a=function(){e.events.off("data",i),e.events.off("destroy",o),e.events.off("error",u)},e.events.once("data",i),e.events.once("destroy",o),e.events.once("error",u),e.start().catch((function(){}));case 8:case"end":return t.stop()}}),t)})));return function(e,r){return t.apply(this,arguments)}}()));case 1:case"end":return t.stop()}}),t)})));return function(){return t.apply(this,arguments)}}(),e.emitOutput=function(t){this.events.emit("data",t)},e.emitError=function(t){this.events.emit("error",t)},t}();n();var b=function(t){function e(r,n){var o;return(o=t.call(this,n)||this).statusCode=r,Object.setPrototypeOf(h(o),e.prototype),o}return a(e,t),e}(l(Error)),E={forbidden:function(t){return new b(403,null!=t?t:"Forbidden")},unauthorized:function(t){return new b(401,null!=t?t:"Unauthorized")},badRequest:function(t){return new b(400,null!=t?t:"Bad Request")},notFound:function(t){return new b(404,null!=t?t:"Not found")},payloadTooLarge:function(t){return new b(413,null!=t?t:"Payload Too Large")}};function O(t){var e,r,n=t;return n instanceof v?n=E.badRequest(n.message):n instanceof m&&(n=E.notFound(n.message)),{ok:!1,statusCode:"number"==typeof(null==(e=n)?void 0:e.statusCode)?n.statusCode:500,error:{message:"string"==typeof(null==(r=n)?void 0:r.message)?n.message:"Internal Server Error",stack:void 0}}}function k(t){var e=void 0,r=t.input;if(!r)return e;if("string"!=typeof r)throw E.badRequest("Expected query.input to be a JSON string");try{e=JSON.parse(r)}catch(t){throw E.badRequest("Expected query.input to be a JSON string")}return e}function _(t){return q.apply(this,arguments)}function q(){return(q=i(y.mark((function t(e){var r,n;return y.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return r=e.req,n=e.maxBodySize,t.abrupt("return",new Promise((function(t,e){if(r.body)t(r.body);else{var o="";r.on("data",(function(t){o+=t,"number"==typeof n&&o.length>n&&(e(E.payloadTooLarge()),r.connection.destroy())})),r.on("end",(function(){try{var r=JSON.parse(o);t(r)}catch(t){e(E.badRequest("Body couldn't be parsed as json"))}}))}})));case 2:case"end":return t.stop()}}),t)})))).apply(this,arguments)}function j(t){return L.apply(this,arguments)}function L(){return(L=i(y.mark((function t(e){var n,o,i,u,a,s,c,f,p,l,h,d,v,m,x,g,q,j,L,S,P,R,T,N,C,F,I;return y.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(n=e.req,o=e.res,i=e.router,u=e.endpoint,a=e.subscriptions,s=e.createContext,c=e.teardown,p=void 0===(f=e.transformer)?{serialize:function(t){return t},deserialize:function(t){return t}}:f,l=e.maxBodySize,t.prev=1,t.t0=s,!t.t0){t.next=7;break}return t.next=6,s({req:n,res:o});case 6:t.t0=t.sent;case 7:if(m=t.t0,x=null!=(h=n.method)?h:"GET",g=function(t){return t?p.deserialize(t):t},"POST"!==x){t.next=20;break}return t.next=13,_({req:n,maxBodySize:l});case 13:return q=g(t.sent.input),t.next=17,i.invoke({target:"mutations",input:q,ctx:m,path:u});case 17:v=t.sent,t.next=57;break;case 20:if("GET"!==x){t.next=28;break}return j=n.query?n.query:r.parse(n.url,!0).query,L=g(k(j)),t.next=25,i.invoke({target:"queries",input:L,ctx:m,path:u});case 25:v=t.sent,t.next=57;break;case 28:if("PATCH"!==x){t.next=56;break}return t.next=31,_({req:n,maxBodySize:l});case 31:return P=g(t.sent.input),t.next=35,i.invoke({target:"subscriptions",input:P,ctx:m,path:u});case 35:return R=t.sent,o.once("close",T=function(){R.destroy("closed")}),N=null!=(S=null==a?void 0:a.timeout)?S:9e3,C=setTimeout((function(){R.destroy("timeout")}),N),t.prev=40,t.next=43,R.onceOutputAndStop();case 43:v=t.sent,o.off("close",T),t.next=54;break;case 47:if(t.prev=47,t.t1=t.catch(40),o.off("close",T),clearTimeout(C),!(t.t1 instanceof w&&"timeout"===t.t1.reason)){t.next=53;break}throw new b(408,"Subscription exceeded "+N+"ms - please reconnect.");case 53:throw t.t1;case 54:t.next=57;break;case 56:throw E.badRequest("Unexpected request method "+x);case 57:F={ok:!0,statusCode:null!=(d=o.statusCode)?d:200,data:v},o.statusCode=F.statusCode,o.setHeader("Content-Type","application/json"),o.end(JSON.stringify(p.serialize(F))),t.next=69;break;case 63:t.prev=63,t.t2=t.catch(1),I=O(t.t2),o.statusCode=I.statusCode,o.setHeader("Content-Type","application/json"),o.end(JSON.stringify(p.serialize(I)));case 69:if(t.prev=69,t.t3=c,!t.t3){t.next=74;break}return t.next=74,c();case 74:t.next=79;break;case 76:t.prev=76,t.t4=t.catch(69),console.error("Teardown failed",t.t4);case 79:case"end":return t.stop()}}),t,null,[[1,63],[40,47],[69,76]])})))).apply(this,arguments)}n();var S=function(){function t(t){this._def=null!=t?t:{queries:{},mutations:{},subscriptions:{}}}t.prefixRoutes=function(t,e){var r={};for(var n in t)r[e+n]=t[n];return r};var e=t.prototype;return e.query=function(e,r){var n,o=new t({queries:(n={},n[e]=r,n),mutations:{},subscriptions:{}});return this.merge(o)},e.mutation=function(e,r){var n,o=new t({queries:{},mutations:(n={},n[e]=r,n),subscriptions:{}});return this.merge(o)},e.subscription=function(e,r){var n,o=new t({queries:{},mutations:{},subscriptions:(n={},n[e]=r,n)});return this.merge(o)},e.merge=function(e,r){var n,o=this,i="";if("string"==typeof e&&r instanceof t)i=e,n=r;else{if(!(e instanceof t))throw new Error("Invalid args");n=e}var a=Object.keys(n._def.queries).filter((function(t){return o.has("queries",t)})),s=Object.keys(n._def.mutations).filter((function(t){return o.has("mutations",t)})),c=Object.keys(n._def.subscriptions).filter((function(t){return o.has("subscriptions",t)})),f=[].concat(a,s,c);if(f.length)throw new Error("Duplicate endpoint(s): "+f.join(", "));return new t({queries:u({},this._def.queries,t.prefixRoutes(n._def.queries,i)),mutations:u({},this._def.mutations,t.prefixRoutes(n._def.mutations,i)),subscriptions:u({},this._def.subscriptions,t.prefixRoutes(n._def.subscriptions,i))})},t.getInput=function(t,e){if(t.input)try{var r=t.input;if("function"==typeof r.parse)return r.parse(e);if("function"==typeof r)return r(e);if("function"==typeof r.validateSync)return r.validateSync(e);throw new Error("Could not find a validator fn")}catch(t){throw new v(t)}},e.invoke=function(){var e=i(y.mark((function e(r){var n,o;return y.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(this.has(r.target,r.path)){e.next=2;break}throw new m('No such route "'+r.path+'"');case 2:return o=t.getInput(n=this._def[r.target][r.path],r.input),e.abrupt("return",n.resolve({ctx:r.ctx,input:o}));case 7:case"end":return e.stop()}}),e,this)})));return function(t){return e.apply(this,arguments)}}(),e.has=function(t,e){return!!this._def[t][e]},t}();exports.HTTPError=b,exports.Router=S,exports.Subscription=g,exports.SubscriptionDestroyError=w,exports.assertNotBrowser=n,exports.createExpressMiddleware=function(t){return function(e,r){var n=e.path.substr(1);j(u({},t,{req:e,res:r,endpoint:n}))}},exports.createNextApiHandler=function(t){return function(){var e=i(y.mark((function e(r,n){var o,i;return y.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(null!==(o=Array.isArray(r.query.trpc)?r.query.trpc.join("/"):null)){e.next=5;break}return i=O(new Error('Query "trpc" not found - is the file named [...trpc].ts?')),n.status(i.statusCode).json(i),e.abrupt("return");case 5:return e.next=7,j(u({},t,{req:r,res:n,endpoint:o}));case 7:case"end":return e.stop()}}),e)})));return function(t,r){return e.apply(this,arguments)}}()},exports.getErrorResponseEnvelope=O,exports.getQueryInput=k,exports.httpError=E,exports.requestHandler=j,exports.router=function(){return new S},exports.subscriptionPullFatory=function(t){var e,r=!1;function n(t){return o.apply(this,arguments)}function o(){return(o=i(y.mark((function o(i){return y.wrap((function(o){for(;;)switch(o.prev=o.next){case 0:if(!r){o.next=2;break}return o.abrupt("return");case 2:return o.prev=2,o.next=5,t.pull(i);case 5:o.next=10;break;case 7:o.prev=7,o.t0=o.catch(2),i.error(o.t0);case 10:r||(e=setTimeout((function(){return n(i)}),t.interval));case 11:case"end":return o.stop()}}),o,null,[[2,7]])})))).apply(this,arguments)}return new g({start:function(t){return n(t),function(){clearTimeout(e),r=!0}}})}; | ||
//# sourceMappingURL=server.cjs.production.min.js.map |
@@ -1484,7 +1484,7 @@ import { EventEmitter } from 'events'; | ||
statusCode: (_res$statusCode = res.statusCode) != null ? _res$statusCode : 200, | ||
data: transformer.serialize(output) | ||
data: output | ||
}; | ||
res.statusCode = json.statusCode; | ||
res.setHeader('Content-Type', 'application/json'); | ||
res.end(JSON.stringify(json)); | ||
res.end(JSON.stringify(transformer.serialize(json))); | ||
_context2.next = 69; | ||
@@ -1499,3 +1499,3 @@ break; | ||
res.setHeader('Content-Type', 'application/json'); | ||
res.end(JSON.stringify(_json)); | ||
res.end(JSON.stringify(transformer.serialize(_json))); | ||
@@ -1502,0 +1502,0 @@ case 69: |
{ | ||
"name": "@trpc/server", | ||
"version": "1.2.0", | ||
"version": "1.3.0-alpha.0", | ||
"description": "TRPC Server", | ||
@@ -46,3 +46,3 @@ "author": "KATT", | ||
}, | ||
"gitHead": "d4d5e7a347c39d2169a87fdb207de669db60758b" | ||
"gitHead": "8c68a448dbcec281e55af8c3251b9e5cd416b2b1" | ||
} |
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
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
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
386890
3251
3