@panter/cloud-tasks 3.3.0 → 3.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +1 -1
- package/dist/index.mjs +1 -1
- package/dist/server.cjs +1 -1
- package/dist/server.d.ts +23 -3
- package/dist/server.d.ts.map +1 -1
- package/dist/server.mjs +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var M=Object.create;var g=Object.defineProperty;var K=Object.getOwnPropertyDescriptor;var _=Object.getOwnPropertyNames;var j=Object.getPrototypeOf,H=Object.prototype.hasOwnProperty;var s=(r,t)=>g(r,"name",{value:t,configurable:!0});var Q=(r,t)=>{for(var e in t)g(r,e,{get:t[e],enumerable:!0})},x=(r,t,e,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of _(t))!H.call(r,n)&&n!==e&&g(r,n,{get:()=>t[n],enumerable:!(o=K(t,n))||o.enumerable});return r};var G=(r,t,e)=>(e=r!=null?M(j(r)):{},x(t||!r||!r.__esModule?g(e,"default",{value:r,enumerable:!0}):e,r)),F=r=>x(g({},"__esModule",{value:!0}),r);var $={};Q($,{TRPC_PATH_PREFIX:()=>y,createExpressTaskServer:()=>B,createExpressTaskServerMiddleware:()=>L,createTasksClient:()=>U,trpcHttpCall:()=>S});module.exports=F($);var E=require("@google-cloud/tasks"),q=require("@grpc/grpc-js"),v=require("google-gax"),d=require("ts-results-es");var w=require("google-auth-library"),k=require("google-gax"),u=require("ts-results-es");function l(r){return r instanceof Error&&"code"in r&&Number.isInteger(r.code)}s(l,"isRpcError");function p(r){return l(r)?{...r,type:"rpc"}:{type:"unknown",error:r}}s(p,"toTasksError");function P(r){let t=new Uint8Array(3);crypto.getRandomValues(t);let e=Buffer.from(t).toString("hex");return`${r}-${Date.now()}-${e}`}s(P,"createUniqueName");var m=class{constructor(t,e,o,n){this.client=t;this.location=e;this.queueName=o;this.logger=n;this.projectIdPromise=this.client.getProjectId(),this.serviceAccountEmailPromise=new w.GoogleAuth().getCredentials().then(a=>a.client_email??null)}static{s(this,"CommonTasksClient")}serviceAccountEmailPromise;projectIdPromise;async upsertQueue(t){try{let e=await this.projectIdPromise,o=this.client.queuePath(e,this.location,this.queueName),n=this.client.locationPath(e,this.location);this.logger.info({queuePath:o,parentPath:n},"upserting tasks queue");let a="create";try{await this.client.getQueue({name:o}),a="update"}catch(i){if(l(i)&&i.code===k.Status.NOT_FOUND)a="create";else throw i}return a==="update"?(this.logger.info({queuePath:o},"updating existing queue"),await this.client.updateQueue({queue:{name:o,...t}})):(this.logger.info({queuePath:o},"creating new queue"),await this.client.createQueue({parent:n,queue:{name:o,...t}})),u.Ok.EMPTY}catch(e){return(0,u.Err)(p(e))}}async listTasks(){try{let t=await this.projectIdPromise,e=this.client.queuePath(t,this.location,this.queueName),[o]=await this.client.listTasks({parent:e});return(0,u.Ok)(o)}catch(t){return(0,u.Err)(p(t))}}async createTask(t,e){try{let o=await this.projectIdPromise,n=this.client.queuePath(o,this.location,this.queueName),a=this.client.taskPath(o,this.location,this.queueName,P(t)),i=await this.serviceAccountEmailPromise;return this.logger.info({queuePath:n,taskPath:a,url:e?.httpRequest?.url,payload:e?.httpRequest?.body,serviceAccountEmail:i},"scheduling task"),await this.client.createTask({parent:n,task:{...e,name:a,httpRequest:{...e?.httpRequest,oidcToken:{serviceAccountEmail:i}}}}),(0,u.Ok)(a)}catch(o){return(0,u.Err)(p(o))}}async getTask(t){try{let[e]=await this.client.getTask({name:t});return(0,u.Ok)(e)}catch(e){return l(e)&&e.code===k.Status.NOT_FOUND?(0,u.Ok)(null):(0,u.Err)(p(e))}}};var f=class extends m{static{s(this,"EmulatorTasksClient")}constructor(t,e,o,n){super(new E.CloudTasksClient({sslCreds:q.credentials.createInsecure(),servicePath:n.host??"localhost",port:n.port}),t,e,o)}async upsertQueue(t){try{let e=await this.projectIdPromise,o=this.client.queuePath(e,this.location,this.queueName),n=this.client.locationPath(e,this.location);this.logger.info({queuePath:o,parentPath:n},"upserting simulator tasks queue");try{return await this.client.createQueue({parent:n,queue:{name:o,...t}}),d.Ok.EMPTY}catch(a){return l(a)&&a.code!==v.Status.ALREADY_EXISTS?(0,d.Err)(p(a)):(this.logger.warn({},"dev warning: the queue was not updated due to the emulator not supporting update"),this.logger.warn({},"if you need to update queue options, restart the emulator"),d.Ok.EMPTY)}}catch(e){return(0,d.Err)(p(e))}}async createTask(t,e){return super.createTask(t,{...e,httpRequest:{...e?.httpRequest,url:e?.httpRequest?.url?.replace("//localhost","//host.containers.internal")}})}};var A=require("@google-cloud/tasks");var T=class extends m{static{s(this,"RegularTasksClient")}constructor(t,e,o){super(new A.CloudTasksClient({}),t,e,o)}};function I({queueName:r,emulator:t=!1,location:e="europe-west6",logger:o={error:console.error,info:console.info,warn:console.warn}}){return o.info({queueName:r,emulator:t,location:e},"creating base tasks client"),t?new f(e,r,o,t):new T(e,r,o)}s(I,"createBaseTaskClient");function U({tasksWorkerUrl:r,queueOptions:t,...e}){let o=I(e),n=e.logger??{error:console.error,info:console.info,warn:console.warn};return new Proxy({},{get:s((a,i)=>i==="_manage"?{find:s(c=>o.getTask(c).then(h=>h.unwrap()),"find"),list:s(()=>o.listTasks().then(c=>c.unwrap()),"list")}:{schedule:s(async(c,h)=>{let C=i.toString();await o.upsertQueue(t);let R=new URL(`/trpc/${C}`,r).toString();return n.info({url:R,input:c},"scheduling http request that calls trpc mutation of tasks worker"),(await o.createTask(C,{...h,httpRequest:{httpMethod:"POST",url:R,headers:{"Content-Type":"application/json"},body:c?Buffer.from(JSON.stringify(c)).toString("base64"):null}})).unwrap()},"schedule")},"get")})}s(U,"createTasksClient");var N=require("@trpc/server"),O=require("@trpc/server/adapters/express"),b=G(require("express"));var y="/trpc";function S(r){let t=r?.pathPrefix??y;return(e,o)=>({path:`${t}/${e}`,method:"POST",body:JSON.stringify(o),headers:{"Content-Type":"application/json"}})}s(S,"trpcHttpCall");var L=s(({createRouter:r,createContext:t,onError:e})=>{let o=N.initTRPC.context().create(),n=r(o);return{expressMiddleware:(0,O.createExpressMiddleware)({router:n,createContext:t,onError:e}),router:n}},"createExpressTaskServerMiddleware");function B({createRouter:r,createContext:t,onError:e,app:o=(0,b.default)()}){let{expressMiddleware:n,router:a}=L({createRouter:r,createContext:t,onError:e});return o.use(y,n),{runServer:s(i=>{o.listen({port:i})},"runServer"),router:a}}s(B,"createExpressTaskServer");
|
package/dist/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var E=Object.defineProperty;var
|
|
1
|
+
var E=Object.defineProperty;var n=(o,r)=>E(o,"name",{value:r,configurable:!0});import{CloudTasksClient as v}from"@google-cloud/tasks";import{credentials as A}from"@grpc/grpc-js";import{Status as I}from"google-gax";import{Err as x,Ok as P}from"ts-results-es";import{GoogleAuth as q}from"google-auth-library";import{Status as R}from"google-gax";import{Err as f,Ok as m}from"ts-results-es";function c(o){return o instanceof Error&&"code"in o&&Number.isInteger(o.code)}n(c,"isRpcError");function u(o){return c(o)?{...o,type:"rpc"}:{type:"unknown",error:o}}n(u,"toTasksError");function C(o){let r=new Uint8Array(3);crypto.getRandomValues(r);let e=Buffer.from(r).toString("hex");return`${o}-${Date.now()}-${e}`}n(C,"createUniqueName");var l=class{constructor(r,e,t,s){this.client=r;this.location=e;this.queueName=t;this.logger=s;this.projectIdPromise=this.client.getProjectId(),this.serviceAccountEmailPromise=new q().getCredentials().then(a=>a.client_email??null)}static{n(this,"CommonTasksClient")}serviceAccountEmailPromise;projectIdPromise;async upsertQueue(r){try{let e=await this.projectIdPromise,t=this.client.queuePath(e,this.location,this.queueName),s=this.client.locationPath(e,this.location);this.logger.info({queuePath:t,parentPath:s},"upserting tasks queue");let a="create";try{await this.client.getQueue({name:t}),a="update"}catch(i){if(c(i)&&i.code===R.NOT_FOUND)a="create";else throw i}return a==="update"?(this.logger.info({queuePath:t},"updating existing queue"),await this.client.updateQueue({queue:{name:t,...r}})):(this.logger.info({queuePath:t},"creating new queue"),await this.client.createQueue({parent:s,queue:{name:t,...r}})),m.EMPTY}catch(e){return f(u(e))}}async listTasks(){try{let r=await this.projectIdPromise,e=this.client.queuePath(r,this.location,this.queueName),[t]=await this.client.listTasks({parent:e});return m(t)}catch(r){return f(u(r))}}async createTask(r,e){try{let t=await this.projectIdPromise,s=this.client.queuePath(t,this.location,this.queueName),a=this.client.taskPath(t,this.location,this.queueName,C(r)),i=await this.serviceAccountEmailPromise;return this.logger.info({queuePath:s,taskPath:a,url:e?.httpRequest?.url,payload:e?.httpRequest?.body,serviceAccountEmail:i},"scheduling task"),await this.client.createTask({parent:s,task:{...e,name:a,httpRequest:{...e?.httpRequest,oidcToken:{serviceAccountEmail:i}}}}),m(a)}catch(t){return f(u(t))}}async getTask(r){try{let[e]=await this.client.getTask({name:r});return m(e)}catch(e){return c(e)&&e.code===R.NOT_FOUND?m(null):f(u(e))}}};var d=class extends l{static{n(this,"EmulatorTasksClient")}constructor(r,e,t,s){super(new v({sslCreds:A.createInsecure(),servicePath:s.host??"localhost",port:s.port}),r,e,t)}async upsertQueue(r){try{let e=await this.projectIdPromise,t=this.client.queuePath(e,this.location,this.queueName),s=this.client.locationPath(e,this.location);this.logger.info({queuePath:t,parentPath:s},"upserting simulator tasks queue");try{return await this.client.createQueue({parent:s,queue:{name:t,...r}}),P.EMPTY}catch(a){return c(a)&&a.code!==I.ALREADY_EXISTS?x(u(a)):(this.logger.warn({},"dev warning: the queue was not updated due to the emulator not supporting update"),this.logger.warn({},"if you need to update queue options, restart the emulator"),P.EMPTY)}}catch(e){return x(u(e))}}async createTask(r,e){return super.createTask(r,{...e,httpRequest:{...e?.httpRequest,url:e?.httpRequest?.url?.replace("//localhost","//host.containers.internal")}})}};import{CloudTasksClient as S}from"@google-cloud/tasks";var g=class extends l{static{n(this,"RegularTasksClient")}constructor(r,e,t){super(new S({}),r,e,t)}};function w({queueName:o,emulator:r=!1,location:e="europe-west6",logger:t={error:console.error,info:console.info,warn:console.warn}}){return t.info({queueName:o,emulator:r,location:e},"creating base tasks client"),r?new d(e,o,t,r):new g(e,o,t)}n(w,"createBaseTaskClient");function le({tasksWorkerUrl:o,queueOptions:r,...e}){let t=w(e),s=e.logger??{error:console.error,info:console.info,warn:console.warn};return new Proxy({},{get:n((a,i)=>i==="_manage"?{find:n(p=>t.getTask(p).then(y=>y.unwrap()),"find"),list:n(()=>t.listTasks().then(p=>p.unwrap()),"list")}:{schedule:n(async(p,y)=>{let h=i.toString();await t.upsertQueue(r);let k=new URL(`/trpc/${h}`,o).toString();return s.info({url:k,input:p},"scheduling http request that calls trpc mutation of tasks worker"),(await t.createTask(h,{...y,httpRequest:{httpMethod:"POST",url:k,headers:{"Content-Type":"application/json"},body:p?Buffer.from(JSON.stringify(p)).toString("base64"):null}})).unwrap()},"schedule")},"get")})}n(le,"createTasksClient");import{initTRPC as O}from"@trpc/server";import{createExpressMiddleware as b}from"@trpc/server/adapters/express";import L from"express";var T="/trpc";function N(o){let r=o?.pathPrefix??T;return(e,t)=>({path:`${r}/${e}`,method:"POST",body:JSON.stringify(t),headers:{"Content-Type":"application/json"}})}n(N,"trpcHttpCall");var M=n(({createRouter:o,createContext:r,onError:e})=>{let t=O.context().create(),s=o(t);return{expressMiddleware:b({router:s,createContext:r,onError:e}),router:s}},"createExpressTaskServerMiddleware");function Ce({createRouter:o,createContext:r,onError:e,app:t=L()}){let{expressMiddleware:s,router:a}=M({createRouter:o,createContext:r,onError:e});return t.use(T,s),{runServer:n(i=>{t.listen({port:i})},"runServer"),router:a}}n(Ce,"createExpressTaskServer");export{T as TRPC_PATH_PREFIX,Ce as createExpressTaskServer,M as createExpressTaskServerMiddleware,le as createTasksClient,N as trpcHttpCall};
|
package/dist/server.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var T=Object.create;var p=Object.defineProperty;var P=Object.getOwnPropertyDescriptor;var f=Object.getOwnPropertyNames;var l=Object.getPrototypeOf,m=Object.prototype.hasOwnProperty;var s=(e,t)=>p(e,"name",{value:t,configurable:!0});var A=(e,t)=>{for(var r in t)p(e,r,{get:t[r],enumerable:!0})},x=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of f(t))!m.call(e,o)&&o!==r&&p(e,o,{get:()=>t[o],enumerable:!(n=P(t,o))||n.enumerable});return e};var E=(e,t,r)=>(r=e!=null?T(l(e)):{},x(t||!e||!e.__esModule?p(r,"default",{value:e,enumerable:!0}):r,e)),H=e=>x(p({},"__esModule",{value:!0}),e);var h={};A(h,{TRPC_PATH_PREFIX:()=>a,createExpressTaskServer:()=>w,createExpressTaskServerMiddleware:()=>c,trpcHttpCall:()=>i});module.exports=H(h);var d=require("@trpc/server"),R=require("@trpc/server/adapters/express"),C=E(require("express"));var a="/trpc";function i(e){let t=e?.pathPrefix??a;return(r,n)=>({path:`${t}/${r}`,method:"POST",body:JSON.stringify(n),headers:{"Content-Type":"application/json"}})}s(i,"trpcHttpCall");var c=s(({createRouter:e,createContext:t,onError:r})=>{let n=d.initTRPC.context().create(),o=e(n);return{expressMiddleware:(0,R.createExpressMiddleware)({router:o,createContext:t,onError:r}),router:o}},"createExpressTaskServerMiddleware");function w({createRouter:e,createContext:t,onError:r,app:n=(0,C.default)()}){let{expressMiddleware:o,router:u}=c({createRouter:e,createContext:t,onError:r});return n.use(a,o),{runServer:s(y=>{n.listen({port:y})},"runServer"),router:u}}s(w,"createExpressTaskServer");
|
package/dist/server.d.ts
CHANGED
|
@@ -1,20 +1,40 @@
|
|
|
1
|
-
import type { AnyRouter } from "@trpc/server";
|
|
1
|
+
import type { AnyRouter, TRPCError } from "@trpc/server";
|
|
2
2
|
import { initTRPC } from "@trpc/server";
|
|
3
3
|
import type { NodeHTTPCreateContextFnOptions } from "@trpc/server/adapters/node-http";
|
|
4
4
|
import express from "express";
|
|
5
5
|
export { TRPC_PATH_PREFIX, trpcHttpCall } from "./httpCall";
|
|
6
6
|
type TRPCInstance<Context extends object> = ReturnType<ReturnType<typeof initTRPC.context<Context>>["create"]>;
|
|
7
7
|
type CreateRouter<Router extends AnyRouter, Context extends object> = (t: TRPCInstance<Context>) => Router;
|
|
8
|
-
|
|
8
|
+
/**
|
|
9
|
+
* Error handler invoked whenever a tRPC procedure (or context creation) throws.
|
|
10
|
+
*
|
|
11
|
+
* tRPC does not log errors by default — without an `onError` handler a failing
|
|
12
|
+
* procedure returns HTTP 500 to the caller (e.g. Cloud Tasks, which then
|
|
13
|
+
* retries) but nothing is ever logged server-side. Provide this to surface the
|
|
14
|
+
* error, ideally through the request-scoped logger available on `ctx`.
|
|
15
|
+
*
|
|
16
|
+
* `ctx` may be `undefined` if the error happened while creating the context.
|
|
17
|
+
*/
|
|
18
|
+
export type TaskErrorHandler<Context extends object> = (opts: {
|
|
19
|
+
error: TRPCError;
|
|
20
|
+
type: "query" | "mutation" | "subscription" | "unknown";
|
|
21
|
+
path: string | undefined;
|
|
22
|
+
input: unknown;
|
|
23
|
+
ctx: Context | undefined;
|
|
24
|
+
req: express.Request;
|
|
25
|
+
}) => void;
|
|
26
|
+
export declare const createExpressTaskServerMiddleware: <Router extends AnyRouter, CreateContext extends (opts: NodeHTTPCreateContextFnOptions<express.Request, express.Response>) => any>({ createRouter, createContext, onError, }: {
|
|
9
27
|
createRouter: CreateRouter<Router, Awaited<ReturnType<CreateContext>>>;
|
|
10
28
|
createContext?: CreateContext;
|
|
29
|
+
onError?: TaskErrorHandler<Awaited<ReturnType<CreateContext>>>;
|
|
11
30
|
}) => {
|
|
12
31
|
expressMiddleware: express.Handler;
|
|
13
32
|
router: Router;
|
|
14
33
|
};
|
|
15
|
-
export declare function createExpressTaskServer<Router extends AnyRouter, CreateContext extends (opts: NodeHTTPCreateContextFnOptions<express.Request, express.Response>) => any>({ createRouter, createContext, app, }: {
|
|
34
|
+
export declare function createExpressTaskServer<Router extends AnyRouter, CreateContext extends (opts: NodeHTTPCreateContextFnOptions<express.Request, express.Response>) => any>({ createRouter, createContext, onError, app, }: {
|
|
16
35
|
createRouter: CreateRouter<Router, Awaited<ReturnType<CreateContext>>>;
|
|
17
36
|
createContext: CreateContext;
|
|
37
|
+
onError?: TaskErrorHandler<Awaited<ReturnType<CreateContext>>>;
|
|
18
38
|
app?: express.Application;
|
|
19
39
|
}): {
|
|
20
40
|
runServer: (port: number) => void;
|
package/dist/server.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzD,OAAO,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AAExC,OAAO,KAAK,EAAE,8BAA8B,EAAE,MAAM,iCAAiC,CAAC;AACtF,OAAO,OAAO,MAAM,SAAS,CAAC;AAI9B,OAAO,EAAE,gBAAgB,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAE5D,KAAK,YAAY,CAAC,OAAO,SAAS,MAAM,IAAI,UAAU,CACpD,UAAU,CAAC,OAAO,QAAQ,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,QAAQ,CAAC,CACvD,CAAC;AAEF,KAAK,YAAY,CAAC,MAAM,SAAS,SAAS,EAAE,OAAO,SAAS,MAAM,IAAI,CACpE,CAAC,EAAE,YAAY,CAAC,OAAO,CAAC,KACrB,MAAM,CAAC;AAEZ;;;;;;;;;GASG;AACH,MAAM,MAAM,gBAAgB,CAAC,OAAO,SAAS,MAAM,IAAI,CAAC,IAAI,EAAE;IAC5D,KAAK,EAAE,SAAS,CAAC;IACjB,IAAI,EAAE,OAAO,GAAG,UAAU,GAAG,cAAc,GAAG,SAAS,CAAC;IACxD,IAAI,EAAE,MAAM,GAAG,SAAS,CAAC;IACzB,KAAK,EAAE,OAAO,CAAC;IACf,GAAG,EAAE,OAAO,GAAG,SAAS,CAAC;IACzB,GAAG,EAAE,OAAO,CAAC,OAAO,CAAC;CACtB,KAAK,IAAI,CAAC;AAEX,eAAO,MAAM,iCAAiC,GAC5C,MAAM,SAAS,SAAS,EACxB,aAAa,SAAS,CACpB,IAAI,EAAE,8BAA8B,CAAC,OAAO,CAAC,OAAO,EAAE,OAAO,CAAC,QAAQ,CAAC,KACpE,GAAG,EACR,2CAIC;IACD,YAAY,EAAE,YAAY,CAAC,MAAM,EAAE,OAAO,CAAC,UAAU,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC;IACvE,aAAa,CAAC,EAAE,aAAa,CAAC;IAC9B,OAAO,CAAC,EAAE,gBAAgB,CAAC,OAAO,CAAC,UAAU,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC;CAChE;;;CAgBA,CAAC;AACF,wBAAgB,uBAAuB,CACrC,MAAM,SAAS,SAAS,EACxB,aAAa,SAAS,CACpB,IAAI,EAAE,8BAA8B,CAAC,OAAO,CAAC,OAAO,EAAE,OAAO,CAAC,QAAQ,CAAC,KACpE,GAAG,EACR,EACA,YAAY,EACZ,aAAa,EACb,OAAO,EACP,GAAe,GAChB,EAAE;IACD,YAAY,EAAE,YAAY,CAAC,MAAM,EAAE,OAAO,CAAC,UAAU,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC;IACvE,aAAa,EAAE,aAAa,CAAC;IAC7B,OAAO,CAAC,EAAE,gBAAgB,CAAC,OAAO,CAAC,UAAU,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC;IAC/D,GAAG,CAAC,EAAE,OAAO,CAAC,WAAW,CAAC;CAC3B;sBASqB,MAAM;;EAK3B"}
|
package/dist/server.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var
|
|
1
|
+
var x=Object.defineProperty;var o=(e,t)=>x(e,"name",{value:t,configurable:!0});import{initTRPC as d}from"@trpc/server";import{createExpressMiddleware as R}from"@trpc/server/adapters/express";import C from"express";var p="/trpc";function i(e){let t=e?.pathPrefix??p;return(n,r)=>({path:`${t}/${n}`,method:"POST",body:JSON.stringify(r),headers:{"Content-Type":"application/json"}})}o(i,"trpcHttpCall");var c=o(({createRouter:e,createContext:t,onError:n})=>{let r=d.context().create(),s=e(r);return{expressMiddleware:R({router:s,createContext:t,onError:n}),router:s}},"createExpressTaskServerMiddleware");function E({createRouter:e,createContext:t,onError:n,app:r=C()}){let{expressMiddleware:s,router:a}=c({createRouter:e,createContext:t,onError:n});return r.use(p,s),{runServer:o(u=>{r.listen({port:u})},"runServer"),router:a}}o(E,"createExpressTaskServer");export{p as TRPC_PATH_PREFIX,E as createExpressTaskServer,c as createExpressTaskServerMiddleware,i as trpcHttpCall};
|