@panter/cloud-tasks 3.2.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.
@@ -0,0 +1 @@
1
+ "use strict";var p=Object.defineProperty;var i=Object.getOwnPropertyDescriptor;var a=Object.getOwnPropertyNames;var d=Object.prototype.hasOwnProperty;var s=(e,t)=>p(e,"name",{value:t,configurable:!0});var c=(e,t)=>{for(var r in t)p(e,r,{get:t[r],enumerable:!0})},y=(e,t,r,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of a(t))!d.call(e,n)&&n!==r&&p(e,n,{get:()=>t[n],enumerable:!(o=i(t,n))||o.enumerable});return e};var R=e=>y(p({},"__esModule",{value:!0}),e);var l={};c(l,{TRPC_PATH_PREFIX:()=>u,trpcHttpCall:()=>f});module.exports=R(l);var u="/trpc";function f(e){let t=e?.pathPrefix??u;return(r,o)=>({path:`${t}/${r}`,method:"POST",body:JSON.stringify(o),headers:{"Content-Type":"application/json"}})}s(f,"trpcHttpCall");
@@ -0,0 +1,37 @@
1
+ import type { AnyMutationProcedure, AnyRouter, inferRouterInputs } from "@trpc/server";
2
+ export declare const TRPC_PATH_PREFIX = "/trpc";
3
+ /** Extract only mutation procedure keys from a Router */
4
+ type MutationKeys<R extends AnyRouter> = {
5
+ [K in keyof R["_def"]["procedures"]]: R["_def"]["procedures"][K] extends AnyMutationProcedure ? K : never;
6
+ }[keyof R["_def"]["procedures"]];
7
+ type TrpcHttpCallResult = {
8
+ path: string;
9
+ method: "POST";
10
+ body: string;
11
+ headers: {
12
+ "Content-Type": "application/json";
13
+ };
14
+ };
15
+ /**
16
+ * Create a typesafe helper to produce HTTP call details for tRPC task procedures.
17
+ *
18
+ * Useful for constructing cron job / Cloud Scheduler HTTP targets without importing
19
+ * the service module (which would trigger side effects).
20
+ *
21
+ * @example
22
+ * ```ts
23
+ * import type { Router } from "@repo/zfv-factsheet-syncer/api"
24
+ * import { trpcHttpCall } from "@panter/cloud-tasks/httpCall"
25
+ *
26
+ * const syncAll = trpcHttpCall<Router>()("syncAll", { syncOpeningHours: "upcoming" })
27
+ * // syncAll.path === "/trpc/syncAll"
28
+ * // syncAll.method === "POST"
29
+ * // syncAll.body === '{"syncOpeningHours":"upcoming"}'
30
+ * // syncAll.headers === { "Content-Type": "application/json" }
31
+ * ```
32
+ */
33
+ export declare function trpcHttpCall<Router extends AnyRouter>(options?: {
34
+ pathPrefix?: string;
35
+ }): <K extends string & MutationKeys<Router>>(procedureName: K, input: inferRouterInputs<Router>[K]) => TrpcHttpCallResult;
36
+ export {};
37
+ //# sourceMappingURL=httpCall.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"httpCall.d.ts","sourceRoot":"","sources":["../src/httpCall.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,oBAAoB,EACpB,SAAS,EACT,iBAAiB,EAClB,MAAM,cAAc,CAAC;AAEtB,eAAO,MAAM,gBAAgB,UAAU,CAAC;AAExC,yDAAyD;AACzD,KAAK,YAAY,CAAC,CAAC,SAAS,SAAS,IAAI;KACtC,CAAC,IAAI,MAAM,CAAC,CAAC,MAAM,CAAC,CAAC,YAAY,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,SAAS,oBAAoB,GACzF,CAAC,GACD,KAAK;CACV,CAAC,MAAM,CAAC,CAAC,MAAM,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC;AAEjC,KAAK,kBAAkB,GAAG;IACxB,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE;QAAE,cAAc,EAAE,kBAAkB,CAAA;KAAE,CAAC;CACjD,CAAC;AAEF;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,YAAY,CAAC,MAAM,SAAS,SAAS,EAAE,OAAO,CAAC,EAAE;IAC/D,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB,IAES,CAAC,SAAS,MAAM,GAAG,YAAY,CAAC,MAAM,CAAC,EAC7C,eAAe,CAAC,EAChB,OAAO,iBAAiB,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,KAClC,kBAAkB,CAMtB"}
@@ -0,0 +1 @@
1
+ var p=Object.defineProperty;var r=(t,e)=>p(t,"name",{value:e,configurable:!0});var s="/trpc";function i(t){let e=t?.pathPrefix??s;return(n,o)=>({path:`${e}/${n}`,method:"POST",body:JSON.stringify(o),headers:{"Content-Type":"application/json"}})}r(i,"trpcHttpCall");export{s as TRPC_PATH_PREFIX,i as trpcHttpCall};
package/dist/index.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";var M=Object.create;var d=Object.defineProperty;var b=Object.getOwnPropertyDescriptor;var K=Object.getOwnPropertyNames;var j=Object.getPrototypeOf,_=Object.prototype.hasOwnProperty;var n=(r,t)=>d(r,"name",{value:t,configurable:!0});var Q=(r,t)=>{for(var e in t)d(r,e,{get:t[e],enumerable:!0})},R=(r,t,e,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of K(t))!_.call(r,s)&&s!==e&&d(r,s,{get:()=>t[s],enumerable:!(o=b(t,s))||o.enumerable});return r};var G=(r,t,e)=>(e=r!=null?M(j(r)):{},R(t||!r||!r.__esModule?d(e,"default",{value:r,enumerable:!0}):e,r)),U=r=>R(d({},"__esModule",{value:!0}),r);var $={};Q($,{createExpressTaskServer:()=>F,createExpressTaskServerMiddleware:()=>L,createTasksClient:()=>B,trpcHttpCall:()=>H});module.exports=U($);var w=require("@google-cloud/tasks"),E=require("@grpc/grpc-js"),q=require("google-gax"),g=require("ts-results-es");var P=require("google-auth-library"),y=require("google-gax"),i=require("ts-results-es");function l(r){return r instanceof Error&&"code"in r&&Number.isInteger(r.code)}n(l,"isRpcError");function c(r){return l(r)?{...r,type:"rpc"}:{type:"unknown",error:r}}n(c,"toTasksError");function x(r){let t=new Uint8Array(3);crypto.getRandomValues(t);let e=Buffer.from(t).toString("hex");return`${r}-${Date.now()}-${e}`}n(x,"createUniqueName");var m=class{constructor(t,e,o,s){this.client=t;this.location=e;this.queueName=o;this.logger=s;this.projectIdPromise=this.client.getProjectId(),this.serviceAccountEmailPromise=new P.GoogleAuth().getCredentials().then(a=>a.client_email??null)}static{n(this,"CommonTasksClient")}serviceAccountEmailPromise;projectIdPromise;async upsertQueue(t){try{let e=await this.projectIdPromise,o=this.client.queuePath(e,this.location,this.queueName),s=this.client.locationPath(e,this.location);this.logger.info({queuePath:o,parentPath:s},"upserting tasks queue");let a="create";try{await this.client.getQueue({name:o}),a="update"}catch(u){if(l(u)&&u.code===y.Status.NOT_FOUND)a="create";else throw u}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:s,queue:{name:o,...t}})),i.Ok.EMPTY}catch(e){return(0,i.Err)(c(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,i.Ok)(o)}catch(t){return(0,i.Err)(c(t))}}async createTask(t,e){try{let o=await this.projectIdPromise,s=this.client.queuePath(o,this.location,this.queueName),a=this.client.taskPath(o,this.location,this.queueName,x(t)),u=await this.serviceAccountEmailPromise;return this.logger.info({queuePath:s,taskPath:a,url:e?.httpRequest?.url,payload:e?.httpRequest?.body,serviceAccountEmail:u},"scheduling task"),await this.client.createTask({parent:s,task:{...e,name:a,httpRequest:{...e?.httpRequest,oidcToken:{serviceAccountEmail:u}}}}),(0,i.Ok)(a)}catch(o){return(0,i.Err)(c(o))}}async getTask(t){try{let[e]=await this.client.getTask({name:t});return(0,i.Ok)(e)}catch(e){return l(e)&&e.code===y.Status.NOT_FOUND?(0,i.Ok)(null):(0,i.Err)(c(e))}}};var f=class extends m{static{n(this,"EmulatorTasksClient")}constructor(t,e,o,s){super(new w.CloudTasksClient({sslCreds:E.credentials.createInsecure(),servicePath:s.host??"localhost",port:s.port}),t,e,o)}async upsertQueue(t){try{let e=await this.projectIdPromise,o=this.client.queuePath(e,this.location,this.queueName),s=this.client.locationPath(e,this.location);this.logger.info({queuePath:o,parentPath:s},"upserting simulator tasks queue");try{return await this.client.createQueue({parent:s,queue:{name:o,...t}}),g.Ok.EMPTY}catch(a){return l(a)&&a.code!==q.Status.ALREADY_EXISTS?(0,g.Err)(c(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"),g.Ok.EMPTY)}}catch(e){return(0,g.Err)(c(e))}}async createTask(t,e){return super.createTask(t,{...e,httpRequest:{...e?.httpRequest,url:e?.httpRequest?.url?.replace("//localhost","//host.containers.internal")}})}};var v=require("@google-cloud/tasks");var h=class extends m{static{n(this,"RegularTasksClient")}constructor(t,e,o){super(new v.CloudTasksClient({}),t,e,o)}};function S({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 h(e,r,o)}n(S,"createBaseTaskClient");function B({tasksWorkerUrl:r,queueOptions:t,...e}){let o=S(e),s=e.logger??{error:console.error,info:console.info,warn:console.warn};return new Proxy({},{get:n((a,u)=>u==="_manage"?{find:n(p=>o.getTask(p).then(k=>k.unwrap()),"find"),list:n(()=>o.listTasks().then(p=>p.unwrap()),"list")}:{schedule:n(async(p,k)=>{let T=u.toString();await o.upsertQueue(t);let C=new URL(`/trpc/${T}`,r).toString();return s.info({url:C,input:p},"scheduling http request that calls trpc mutation of tasks worker"),(await o.createTask(T,{...k,httpRequest:{httpMethod:"POST",url:C,headers:{"Content-Type":"application/json"},body:p?Buffer.from(JSON.stringify(p)).toString("base64"):null}})).unwrap()},"schedule")},"get")})}n(B,"createTasksClient");var I=require("@trpc/server"),A=require("@trpc/server/adapters/express"),N=G(require("express"));var O="/trpc",L=n(({createRouter:r,createContext:t})=>{let e=I.initTRPC.context().create(),o=r(e);return{expressMiddleware:(0,A.createExpressMiddleware)({router:o,createContext:t}),router:o}},"createExpressTaskServerMiddleware");function F({createRouter:r,createContext:t,app:e=(0,N.default)()}){let{expressMiddleware:o,router:s}=L({createRouter:r,createContext:t});return e.use(O,o),{runServer:n(a=>{e.listen({port:a})},"runServer"),router:s}}n(F,"createExpressTaskServer");function H(r){let t=r?.pathPrefix??O;return(e,o)=>({path:`${t}/${e}`,method:"POST",body:JSON.stringify(o),headers:{"Content-Type":"application/json"}})}n(H,"trpcHttpCall");
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 s=(o,r)=>E(o,"name",{value:r,configurable:!0});import{CloudTasksClient as v}from"@google-cloud/tasks";import{credentials as S}from"@grpc/grpc-js";import{Status as I}from"google-gax";import{Err as R,Ok as x}from"ts-results-es";import{GoogleAuth as q}from"google-auth-library";import{Status as C}from"google-gax";import{Err as f,Ok as m}from"ts-results-es";function p(o){return o instanceof Error&&"code"in o&&Number.isInteger(o.code)}s(p,"isRpcError");function u(o){return p(o)?{...o,type:"rpc"}:{type:"unknown",error:o}}s(u,"toTasksError");function T(o){let r=new Uint8Array(3);crypto.getRandomValues(r);let e=Buffer.from(r).toString("hex");return`${o}-${Date.now()}-${e}`}s(T,"createUniqueName");var l=class{constructor(r,e,t,n){this.client=r;this.location=e;this.queueName=t;this.logger=n;this.projectIdPromise=this.client.getProjectId(),this.serviceAccountEmailPromise=new q().getCredentials().then(a=>a.client_email??null)}static{s(this,"CommonTasksClient")}serviceAccountEmailPromise;projectIdPromise;async upsertQueue(r){try{let e=await this.projectIdPromise,t=this.client.queuePath(e,this.location,this.queueName),n=this.client.locationPath(e,this.location);this.logger.info({queuePath:t,parentPath:n},"upserting tasks queue");let a="create";try{await this.client.getQueue({name:t}),a="update"}catch(i){if(p(i)&&i.code===C.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:n,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,n=this.client.queuePath(t,this.location,this.queueName),a=this.client.taskPath(t,this.location,this.queueName,T(r)),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}}}}),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 p(e)&&e.code===C.NOT_FOUND?m(null):f(u(e))}}};var g=class extends l{static{s(this,"EmulatorTasksClient")}constructor(r,e,t,n){super(new v({sslCreds:S.createInsecure(),servicePath:n.host??"localhost",port:n.port}),r,e,t)}async upsertQueue(r){try{let e=await this.projectIdPromise,t=this.client.queuePath(e,this.location,this.queueName),n=this.client.locationPath(e,this.location);this.logger.info({queuePath:t,parentPath:n},"upserting simulator tasks queue");try{return await this.client.createQueue({parent:n,queue:{name:t,...r}}),x.EMPTY}catch(a){return p(a)&&a.code!==I.ALREADY_EXISTS?R(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"),x.EMPTY)}}catch(e){return R(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 A}from"@google-cloud/tasks";var d=class extends l{static{s(this,"RegularTasksClient")}constructor(r,e,t){super(new A({}),r,e,t)}};function P({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 g(e,o,t,r):new d(e,o,t)}s(P,"createBaseTaskClient");function pe({tasksWorkerUrl:o,queueOptions:r,...e}){let t=P(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=>t.getTask(c).then(h=>h.unwrap()),"find"),list:s(()=>t.listTasks().then(c=>c.unwrap()),"list")}:{schedule:s(async(c,h)=>{let k=i.toString();await t.upsertQueue(r);let y=new URL(`/trpc/${k}`,o).toString();return n.info({url:y,input:c},"scheduling http request that calls trpc mutation of tasks worker"),(await t.createTask(k,{...h,httpRequest:{httpMethod:"POST",url:y,headers:{"Content-Type":"application/json"},body:c?Buffer.from(JSON.stringify(c)).toString("base64"):null}})).unwrap()},"schedule")},"get")})}s(pe,"createTasksClient");import{initTRPC as N}from"@trpc/server";import{createExpressMiddleware as O}from"@trpc/server/adapters/express";import L from"express";var w="/trpc",M=s(({createRouter:o,createContext:r})=>{let e=N.context().create(),t=o(e);return{expressMiddleware:O({router:t,createContext:r}),router:t}},"createExpressTaskServerMiddleware");function he({createRouter:o,createContext:r,app:e=L()}){let{expressMiddleware:t,router:n}=M({createRouter:o,createContext:r});return e.use(w,t),{runServer:s(a=>{e.listen({port:a})},"runServer"),router:n}}s(he,"createExpressTaskServer");function ke(o){let r=o?.pathPrefix??w;return(e,t)=>({path:`${r}/${e}`,method:"POST",body:JSON.stringify(t),headers:{"Content-Type":"application/json"}})}s(ke,"trpcHttpCall");export{he as createExpressTaskServer,M as createExpressTaskServerMiddleware,pe as createTasksClient,ke as trpcHttpCall};
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 c=Object.create;var s=Object.defineProperty;var y=Object.getOwnPropertyDescriptor;var T=Object.getOwnPropertyNames;var f=Object.getPrototypeOf,l=Object.prototype.hasOwnProperty;var p=(e,t)=>s(e,"name",{value:t,configurable:!0});var P=(e,t)=>{for(var r in t)s(e,r,{get:t[r],enumerable:!0})},a=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of T(t))!l.call(e,o)&&o!==r&&s(e,o,{get:()=>t[o],enumerable:!(n=y(t,o))||n.enumerable});return e};var A=(e,t,r)=>(r=e!=null?c(f(e)):{},a(t||!e||!e.__esModule?s(r,"default",{value:e,enumerable:!0}):r,e)),m=e=>a(s({},"__esModule",{value:!0}),e);var w={};P(w,{createExpressTaskServer:()=>h,createExpressTaskServerMiddleware:()=>d,trpcHttpCall:()=>M});module.exports=m(w);var u=require("@trpc/server"),x=require("@trpc/server/adapters/express"),i=A(require("express"));var R="/trpc",d=p(({createRouter:e,createContext:t})=>{let r=u.initTRPC.context().create(),n=e(r);return{expressMiddleware:(0,x.createExpressMiddleware)({router:n,createContext:t}),router:n}},"createExpressTaskServerMiddleware");function h({createRouter:e,createContext:t,app:r=(0,i.default)()}){let{expressMiddleware:n,router:o}=d({createRouter:e,createContext:t});return r.use(R,n),{runServer:p(C=>{r.listen({port:C})},"runServer"),router:o}}p(h,"createExpressTaskServer");function M(e){let t=e?.pathPrefix??R;return(r,n)=>({path:`${t}/${r}`,method:"POST",body:JSON.stringify(n),headers:{"Content-Type":"application/json"}})}p(M,"trpcHttpCall");
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,56 +1,43 @@
1
- import type { AnyMutationProcedure, AnyRouter, inferRouterInputs } from "@trpc/server";
1
+ import type { AnyRouter, TRPCError } from "@trpc/server";
2
2
  import { initTRPC } from "@trpc/server";
3
- import { NodeHTTPCreateContextFnOptions } from "@trpc/server/adapters/node-http";
3
+ import type { NodeHTTPCreateContextFnOptions } from "@trpc/server/adapters/node-http";
4
4
  import express from "express";
5
+ export { TRPC_PATH_PREFIX, trpcHttpCall } from "./httpCall";
5
6
  type TRPCInstance<Context extends object> = ReturnType<ReturnType<typeof initTRPC.context<Context>>["create"]>;
6
7
  type CreateRouter<Router extends AnyRouter, Context extends object> = (t: TRPCInstance<Context>) => Router;
7
- export declare const createExpressTaskServerMiddleware: <Router extends AnyRouter, CreateContext extends (opts: NodeHTTPCreateContextFnOptions<express.Request, express.Response>) => any>({ createRouter, createContext, }: {
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, }: {
8
27
  createRouter: CreateRouter<Router, Awaited<ReturnType<CreateContext>>>;
9
28
  createContext?: CreateContext;
29
+ onError?: TaskErrorHandler<Awaited<ReturnType<CreateContext>>>;
10
30
  }) => {
11
31
  expressMiddleware: express.Handler;
12
32
  router: Router;
13
33
  };
14
- 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, }: {
15
35
  createRouter: CreateRouter<Router, Awaited<ReturnType<CreateContext>>>;
16
36
  createContext: CreateContext;
37
+ onError?: TaskErrorHandler<Awaited<ReturnType<CreateContext>>>;
17
38
  app?: express.Application;
18
39
  }): {
19
40
  runServer: (port: number) => void;
20
41
  router: Router;
21
42
  };
22
- /** Extract only mutation procedure keys from a Router */
23
- type MutationKeys<R extends AnyRouter> = {
24
- [K in keyof R["_def"]["procedures"]]: R["_def"]["procedures"][K] extends AnyMutationProcedure ? K : never;
25
- }[keyof R["_def"]["procedures"]];
26
- type TrpcHttpCallResult = {
27
- path: string;
28
- method: "POST";
29
- body: string;
30
- headers: {
31
- "Content-Type": "application/json";
32
- };
33
- };
34
- /**
35
- * Create a typesafe helper to produce HTTP call details for tRPC task procedures.
36
- *
37
- * Useful for constructing cron job / Cloud Scheduler HTTP targets without importing
38
- * the service module (which would trigger side effects).
39
- *
40
- * @example
41
- * ```ts
42
- * import type { Router } from "@repo/zfv-factsheet-syncer/api"
43
- * import { trpcHttpCall } from "@panter/cloud-tasks/server"
44
- *
45
- * const syncAll = trpcHttpCall<Router>()("syncAll", { syncOpeningHours: "upcoming" })
46
- * // syncAll.path === "/trpc/syncAll"
47
- * // syncAll.method === "POST"
48
- * // syncAll.body === '{"syncOpeningHours":"upcoming"}'
49
- * // syncAll.headers === { "Content-Type": "application/json" }
50
- * ```
51
- */
52
- export declare function trpcHttpCall<Router extends AnyRouter>(options?: {
53
- pathPrefix?: string;
54
- }): <K extends string & MutationKeys<Router>>(procedureName: K, input: inferRouterInputs<Router>[K]) => TrpcHttpCallResult;
55
- export {};
56
43
  //# sourceMappingURL=server.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,oBAAoB,EACpB,SAAS,EACT,iBAAiB,EAClB,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AAExC,OAAO,EAAE,8BAA8B,EAAE,MAAM,iCAAiC,CAAC;AACjF,OAAO,OAAO,MAAM,SAAS,CAAC;AAI9B,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,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,kCAGC;IACD,YAAY,EAAE,YAAY,CAAC,MAAM,EAAE,OAAO,CAAC,UAAU,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC;IACvE,aAAa,CAAC,EAAE,aAAa,CAAC;CAC/B;;;CAaA,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,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,GAAG,CAAC,EAAE,OAAO,CAAC,WAAW,CAAC;CAC3B;sBAQqB,MAAM;;EAK3B;AAID,yDAAyD;AACzD,KAAK,YAAY,CAAC,CAAC,SAAS,SAAS,IAAI;KACtC,CAAC,IAAI,MAAM,CAAC,CAAC,MAAM,CAAC,CAAC,YAAY,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,SAAS,oBAAoB,GACzF,CAAC,GACD,KAAK;CACV,CAAC,MAAM,CAAC,CAAC,MAAM,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC;AAEjC,KAAK,kBAAkB,GAAG;IACxB,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE;QAAE,cAAc,EAAE,kBAAkB,CAAA;KAAE,CAAC;CACjD,CAAC;AAEF;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,YAAY,CAAC,MAAM,SAAS,SAAS,EAAE,OAAO,CAAC,EAAE;IAC/D,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB,IAES,CAAC,SAAS,MAAM,GAAG,YAAY,CAAC,MAAM,CAAC,EAC7C,eAAe,CAAC,EAChB,OAAO,iBAAiB,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,KAClC,kBAAkB,CAMtB"}
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 u=Object.defineProperty;var o=(e,t)=>u(e,"name",{value:t,configurable:!0});import{initTRPC as x}from"@trpc/server";import{createExpressMiddleware as i}from"@trpc/server/adapters/express";import R from"express";var p="/trpc",d=o(({createRouter:e,createContext:t})=>{let r=x.context().create(),n=e(r);return{expressMiddleware:i({router:n,createContext:t}),router:n}},"createExpressTaskServerMiddleware");function f({createRouter:e,createContext:t,app:r=R()}){let{expressMiddleware:n,router:s}=d({createRouter:e,createContext:t});return r.use(p,n),{runServer:o(a=>{r.listen({port:a})},"runServer"),router:s}}o(f,"createExpressTaskServer");function l(e){let t=e?.pathPrefix??p;return(r,n)=>({path:`${t}/${r}`,method:"POST",body:JSON.stringify(n),headers:{"Content-Type":"application/json"}})}o(l,"trpcHttpCall");export{f as createExpressTaskServer,d as createExpressTaskServerMiddleware,l as trpcHttpCall};
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};
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "type": "git",
5
5
  "url": "https://git.panter.ch/open-source/cloud-tasks.git"
6
6
  },
7
- "version": "3.2.0",
7
+ "version": "3.4.0",
8
8
  "sideEffects": false,
9
9
  "exports": {
10
10
  ".": {
@@ -37,6 +37,16 @@
37
37
  "default": "./dist/base.cjs"
38
38
  }
39
39
  },
40
+ "./httpCall": {
41
+ "import": {
42
+ "types": "./dist/httpCall.d.ts",
43
+ "default": "./dist/httpCall.mjs"
44
+ },
45
+ "require": {
46
+ "types": "./dist/httpCall.d.ts",
47
+ "default": "./dist/httpCall.cjs"
48
+ }
49
+ },
40
50
  "./server": {
41
51
  "import": {
42
52
  "types": "./dist/server.d.ts",