@panter/cloud-tasks 1.1.4 → 2.0.1
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/client.cjs +1 -1
- package/dist/client.d.ts +2 -2
- package/dist/client.d.ts.map +1 -1
- package/dist/client.mjs +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.mjs +1 -1
- package/dist/server.cjs +1 -1
- package/dist/server.d.ts +13 -2
- package/dist/server.d.ts.map +1 -1
- package/dist/server.mjs +1 -1
- package/dist/tasksClients.cjs +1 -1
- package/dist/tasksClients.mjs +1 -1
- package/package.json +11 -11
package/dist/client.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var p=Object.defineProperty;var q=Object.getOwnPropertyDescriptor;var E=Object.getOwnPropertyNames;var v=Object.prototype.hasOwnProperty;var i=(o,t)=>p(o,"name",{value:t,configurable:!0});var
|
|
1
|
+
"use strict";var p=Object.defineProperty;var q=Object.getOwnPropertyDescriptor;var E=Object.getOwnPropertyNames;var v=Object.prototype.hasOwnProperty;var i=(o,t)=>p(o,"name",{value:t,configurable:!0});var I=(o,t)=>{for(var e in t)p(o,e,{get:t[e],enumerable:!0})},x=(o,t,e,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of E(t))!v.call(o,s)&&s!==e&&p(o,s,{get:()=>t[s],enumerable:!(r=q(t,s))||r.enumerable});return o};var S=o=>x(p({},"__esModule",{value:!0}),o);var L={};I(L,{createTasksClient:()=>O});module.exports=S(L);var f=require("@google-cloud/tasks"),R=require("@grpc/grpc-js"),C=require("google-auth-library"),g=require("google-gax"),a=require("ts-results-es");var h=class{constructor(t,e,r,s){this.client=t;this.location=e;this.queueName=r;this.logger=s;this.projectIdPromise=this.client.getProjectId(),this.serviceAccountEmailPromise=new C.GoogleAuth().getCredentials().then(n=>n.client_email??null)}static{i(this,"CommonTasksClient")}serviceAccountEmailPromise;projectIdPromise;async upsertQueue(t){try{let e=await this.projectIdPromise,r=this.client.queuePath(e,this.location,this.queueName),s=this.client.locationPath(e,this.location);this.logger.info({queuePath:r,parentPath:s},"upserting tasks queue");let n="create";try{await this.client.getQueue({name:r}),n="update"}catch(u){if(k(u)&&u.code===g.Status.NOT_FOUND)n="create";else throw u}return n==="update"?(this.logger.info({queuePath:r},"updating existing queue"),await this.client.updateQueue({queue:{name:r,...t}})):(this.logger.info({queuePath:r},"creating new queue"),await this.client.createQueue({parent:s,queue:{name:r,...t}})),a.Ok.EMPTY}catch(e){return(0,a.Err)(l(e))}}async listTasks(){try{let t=await this.projectIdPromise,e=this.client.queuePath(t,this.location,this.queueName),[r]=await this.client.listTasks({parent:e});return(0,a.Ok)(r)}catch(t){return(0,a.Err)(l(t))}}async createTask(t,e){try{let r=await this.projectIdPromise,s=this.client.queuePath(r,this.location,this.queueName),n=this.client.taskPath(r,this.location,this.queueName,N(t)),u=await this.serviceAccountEmailPromise;return this.logger.info({queuePath:s,taskPath:n,url:e?.httpRequest?.url,payload:e?.httpRequest?.body,serviceAccountEmail:u},"scheduling task"),await this.client.createTask({parent:s,task:{...e,name:n,httpRequest:{...e?.httpRequest,oidcToken:{serviceAccountEmail:u}}}}),(0,a.Ok)(n)}catch(r){return(0,a.Err)(l(r))}}async getTask(t){try{let[e]=await this.client.getTask({name:t});return(0,a.Ok)(e)}catch(e){return k(e)&&e.code===g.Status.NOT_FOUND?(0,a.Ok)(null):(0,a.Err)(l(e))}}},m=class extends h{static{i(this,"RegularTasksClient")}constructor(t,e,r){super(new f.CloudTasksClient({}),t,e,r)}},d=class extends h{static{i(this,"EmulatorTasksClient")}constructor(t,e,r,s){super(new f.CloudTasksClient({sslCreds:R.credentials.createInsecure(),servicePath:s.host??"localhost",port:s.port}),t,e,r)}async upsertQueue(t){try{let e=await this.projectIdPromise,r=this.client.queuePath(e,this.location,this.queueName),s=this.client.locationPath(e,this.location);this.logger.info({queuePath:r,parentPath:s},"upserting simulator tasks queue");try{return await this.client.createQueue({parent:s,queue:{name:r,...t}}),a.Ok.EMPTY}catch(n){return k(n)&&n.code!==g.Status.ALREADY_EXISTS?(0,a.Err)(l(n)):(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"),a.Ok.EMPTY)}}catch(e){return(0,a.Err)(l(e))}}async createTask(t,e){return super.createTask(t,{...e,httpRequest:{...e?.httpRequest,url:e?.httpRequest?.url?.replace("//localhost","//host.containers.internal")}})}};function N(o){let t=new Uint8Array(3);crypto.getRandomValues(t);let e=Buffer.from(t).toString("hex");return`${o}-${Date.now()}-${e}`}i(N,"createUniqueName");function k(o){return o instanceof Error&&"code"in o&&Number.isInteger(o.code)}i(k,"isRpcError");function l(o){return k(o)?{...o,type:"rpc"}:{type:"unknown",error:o}}i(l,"toTasksError");function O({queueName:o,emulator:t=!1,location:e="europe-west6",tasksWorkerUrl:r,queueOptions:s,logger:n={error:console.error,info:console.info,warn:console.warn}}){n.info({queueName:o,emulator:t,location:e,tasksWorkerUrl:r},"creating tasks client");let u=t?new d(e,o,n,t):new m(e,o,n);return new Proxy({},{get:i((j,y)=>y==="_manage"?{find:i(c=>u.getTask(c).then(T=>T.unwrap()),"find"),list:i(()=>u.listTasks().then(c=>c.unwrap()),"list")}:{schedule:i(async(c,T)=>{let w=y.toString();await u.upsertQueue(s);let P=new URL(`/trpc/${w}`,r).toString();return n.info({url:P,input:c},"scheduling http request that calls trpc mutation of tasks worker"),(await u.createTask(w,{...T,httpRequest:{httpMethod:"POST",url:P,headers:{"Content-Type":"application/json"},body:c?Buffer.from(JSON.stringify(c)).toString("base64"):null}})).unwrap()},"schedule")},"get")})}i(O,"createTasksClient");
|
package/dist/client.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { google } from "@google-cloud/tasks/build/protos";
|
|
2
|
-
import type {
|
|
2
|
+
import type { TRPCClient } from "@trpc/client";
|
|
3
3
|
import type { AnyRouter } from "@trpc/server";
|
|
4
4
|
import type { EmulatorConfig, GcpLocation, TaskConfig } from "./tasksClients";
|
|
5
5
|
export declare function createTasksClient<Router extends AnyRouter>({ queueName, emulator, location, tasksWorkerUrl, queueOptions, logger, }: {
|
|
@@ -9,7 +9,7 @@ export declare function createTasksClient<Router extends AnyRouter>({ queueName,
|
|
|
9
9
|
tasksWorkerUrl: URL;
|
|
10
10
|
logger?: Logger;
|
|
11
11
|
emulator?: false | EmulatorConfig;
|
|
12
|
-
}): ScheduleClient<
|
|
12
|
+
}): ScheduleClient<TRPCClient<Router>>;
|
|
13
13
|
type RemoveNeverKeys<T> = {
|
|
14
14
|
[K in keyof T as T[K] extends never ? never : K]: T[K];
|
|
15
15
|
};
|
package/dist/client.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,kCAAkC,CAAC;AAC/D,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"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"}
|
package/dist/client.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var
|
|
1
|
+
var R=Object.defineProperty;var a=(o,t)=>R(o,"name",{value:t,configurable:!0});import{CloudTasksClient as P}from"@google-cloud/tasks";import{credentials as C}from"@grpc/grpc-js";import{GoogleAuth as q}from"google-auth-library";import{Status as T}from"google-gax";import{Err as l,Ok as c}from"ts-results-es";var g=class{constructor(t,e,r,n){this.client=t;this.location=e;this.queueName=r;this.logger=n;this.projectIdPromise=this.client.getProjectId(),this.serviceAccountEmailPromise=new q().getCredentials().then(s=>s.client_email??null)}static{a(this,"CommonTasksClient")}serviceAccountEmailPromise;projectIdPromise;async upsertQueue(t){try{let e=await this.projectIdPromise,r=this.client.queuePath(e,this.location,this.queueName),n=this.client.locationPath(e,this.location);this.logger.info({queuePath:r,parentPath:n},"upserting tasks queue");let s="create";try{await this.client.getQueue({name:r}),s="update"}catch(i){if(d(i)&&i.code===T.NOT_FOUND)s="create";else throw i}return s==="update"?(this.logger.info({queuePath:r},"updating existing queue"),await this.client.updateQueue({queue:{name:r,...t}})):(this.logger.info({queuePath:r},"creating new queue"),await this.client.createQueue({parent:n,queue:{name:r,...t}})),c.EMPTY}catch(e){return l(p(e))}}async listTasks(){try{let t=await this.projectIdPromise,e=this.client.queuePath(t,this.location,this.queueName),[r]=await this.client.listTasks({parent:e});return c(r)}catch(t){return l(p(t))}}async createTask(t,e){try{let r=await this.projectIdPromise,n=this.client.queuePath(r,this.location,this.queueName),s=this.client.taskPath(r,this.location,this.queueName,E(t)),i=await this.serviceAccountEmailPromise;return this.logger.info({queuePath:n,taskPath:s,url:e?.httpRequest?.url,payload:e?.httpRequest?.body,serviceAccountEmail:i},"scheduling task"),await this.client.createTask({parent:n,task:{...e,name:s,httpRequest:{...e?.httpRequest,oidcToken:{serviceAccountEmail:i}}}}),c(s)}catch(r){return l(p(r))}}async getTask(t){try{let[e]=await this.client.getTask({name:t});return c(e)}catch(e){return d(e)&&e.code===T.NOT_FOUND?c(null):l(p(e))}}},h=class extends g{static{a(this,"RegularTasksClient")}constructor(t,e,r){super(new P({}),t,e,r)}},m=class extends g{static{a(this,"EmulatorTasksClient")}constructor(t,e,r,n){super(new P({sslCreds:C.createInsecure(),servicePath:n.host??"localhost",port:n.port}),t,e,r)}async upsertQueue(t){try{let e=await this.projectIdPromise,r=this.client.queuePath(e,this.location,this.queueName),n=this.client.locationPath(e,this.location);this.logger.info({queuePath:r,parentPath:n},"upserting simulator tasks queue");try{return await this.client.createQueue({parent:n,queue:{name:r,...t}}),c.EMPTY}catch(s){return d(s)&&s.code!==T.ALREADY_EXISTS?l(p(s)):(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"),c.EMPTY)}}catch(e){return l(p(e))}}async createTask(t,e){return super.createTask(t,{...e,httpRequest:{...e?.httpRequest,url:e?.httpRequest?.url?.replace("//localhost","//host.containers.internal")}})}};function E(o){let t=new Uint8Array(3);crypto.getRandomValues(t);let e=Buffer.from(t).toString("hex");return`${o}-${Date.now()}-${e}`}a(E,"createUniqueName");function d(o){return o instanceof Error&&"code"in o&&Number.isInteger(o.code)}a(d,"isRpcError");function p(o){return d(o)?{...o,type:"rpc"}:{type:"unknown",error:o}}a(p,"toTasksError");function K({queueName:o,emulator:t=!1,location:e="europe-west6",tasksWorkerUrl:r,queueOptions:n,logger:s={error:console.error,info:console.info,warn:console.warn}}){s.info({queueName:o,emulator:t,location:e,tasksWorkerUrl:r},"creating tasks client");let i=t?new m(e,o,s,t):new h(e,o,s);return new Proxy({},{get:a((v,f)=>f==="_manage"?{find:a(u=>i.getTask(u).then(k=>k.unwrap()),"find"),list:a(()=>i.listTasks().then(u=>u.unwrap()),"list")}:{schedule:a(async(u,k)=>{let y=f.toString();await i.upsertQueue(n);let w=new URL(`/trpc/${y}`,r).toString();return s.info({url:w,input:u},"scheduling http request that calls trpc mutation of tasks worker"),(await i.createTask(y,{...k,httpRequest:{httpMethod:"POST",url:w,headers:{"Content-Type":"application/json"},body:u?Buffer.from(JSON.stringify(u)).toString("base64"):null}})).unwrap()},"schedule")},"get")})}a(K,"createTasksClient");export{K as createTasksClient};
|
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var N=Object.create;var p=Object.defineProperty;var A=Object.getOwnPropertyDescriptor;var M=Object.getOwnPropertyNames;var O=Object.getPrototypeOf,L=Object.prototype.hasOwnProperty;var a=(r,t)=>p(r,"name",{value:t,configurable:!0});var j=(r,t)=>{for(var e in t)p(r,e,{get:t[e],enumerable:!0})},P=(r,t,e,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of M(t))!L.call(r,s)&&s!==e&&p(r,s,{get:()=>t[s],enumerable:!(o=A(t,s))||o.enumerable});return r};var Q=(r,t,e)=>(e=r!=null?N(O(r)):{},P(t||!r||!r.__esModule?p(e,"default",{value:r,enumerable:!0}):e,r)),K=r=>P(p({},"__esModule",{value:!0}),r);var G={};j(G,{createExpressTaskServer:()=>I,createExpressTaskServerMiddleware:()=>S,createTasksClient:()=>_,createTasksServer:()=>U});module.exports=K(G);var T=require("@google-cloud/tasks"),C=require("@grpc/grpc-js"),x=require("google-auth-library"),g=require("google-gax"),i=require("ts-results-es");var d=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 x.GoogleAuth().getCredentials().then(n=>n.client_email??null)}static{a(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 n="create";try{await this.client.getQueue({name:o}),n="update"}catch(u){if(k(u)&&u.code===g.Status.NOT_FOUND)n="create";else throw u}return n==="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)(l(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)(l(t))}}async createTask(t,e){try{let o=await this.projectIdPromise,s=this.client.queuePath(o,this.location,this.queueName),n=this.client.taskPath(o,this.location,this.queueName,b(t)),u=await this.serviceAccountEmailPromise;return this.logger.info({queuePath:s,taskPath:n,url:e?.httpRequest?.url,payload:e?.httpRequest?.body,serviceAccountEmail:u},"scheduling task"),await this.client.createTask({parent:s,task:{...e,name:n,httpRequest:{...e?.httpRequest,oidcToken:{serviceAccountEmail:u}}}}),(0,i.Ok)(n)}catch(o){return(0,i.Err)(l(o))}}async getTask(t){try{let[e]=await this.client.getTask({name:t});return(0,i.Ok)(e)}catch(e){return k(e)&&e.code===g.Status.NOT_FOUND?(0,i.Ok)(null):(0,i.Err)(l(e))}}},m=class extends d{static{a(this,"RegularTasksClient")}constructor(t,e,o){super(new T.CloudTasksClient({}),t,e,o)}},h=class extends d{static{a(this,"EmulatorTasksClient")}constructor(t,e,o,s){super(new T.CloudTasksClient({sslCreds:C.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}}),i.Ok.EMPTY}catch(n){return k(n)&&n.code!==g.Status.ALREADY_EXISTS?(0,i.Err)(l(n)):(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"),i.Ok.EMPTY)}}catch(e){return(0,i.Err)(l(e))}}async createTask(t,e){return super.createTask(t,{...e,httpRequest:{...e?.httpRequest,url:e?.httpRequest?.url?.replace("//localhost","//host.containers.internal")}})}};function b(r){let t=new Uint8Array(3);crypto.getRandomValues(t);let e=Buffer.from(t).toString("hex");return`${r}-${Date.now()}-${e}`}a(b,"createUniqueName");function k(r){return r instanceof Error&&"code"in r&&Number.isInteger(r.code)}a(k,"isRpcError");function l(r){return k(r)?{...r,type:"rpc"}:{type:"unknown",error:r}}a(l,"toTasksError");function _({queueName:r,emulator:t=!1,location:e="europe-west6",tasksWorkerUrl:o,queueOptions:s,logger:n={error:console.error,info:console.info,warn:console.warn}}){n.info({queueName:r,emulator:t,location:e,tasksWorkerUrl:o},"creating tasks client");let u=t?new h(e,r,n,t):new m(e,r,n);return new Proxy({},{get:a((D,y)=>y==="_manage"?{find:a(c=>u.getTask(c).then(f=>f.unwrap()),"find"),list:a(()=>u.listTasks().then(c=>c.unwrap()),"list")}:{schedule:a(async(c,f)=>{let w=y.toString();await u.upsertQueue(s);let R=new URL(`/trpc/${w}`,o).toString();return n.info({url:R,input:c},"scheduling http request that calls trpc mutation of tasks worker"),(await u.createTask(w,{...f,httpRequest:{httpMethod:"POST",url:R,headers:{"Content-Type":"application/json"},body:c?Buffer.from(JSON.stringify(c)).toString("base64"):null}})).unwrap()},"schedule")},"get")})}a(_,"createTasksClient");var v=require("@trpc/server"),q=require("@trpc/server/adapters/express"),E=Q(require("express"));var S=a(r=>{let t=v.initTRPC.create(),e=r(t);return{expressMiddleware:(0,q.createExpressMiddleware)({router:e}),router:e}},"createExpressTaskServerMiddleware");function I(r,t){let e=t??(0,E.default)(),{expressMiddleware:o,router:s}=S(r);return e.use("/trpc",o),{runServer:a(n=>{e.listen({port:n})},"runServer"),router:s}}a(I,"createExpressTaskServer");var U=I;
|
package/dist/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var
|
|
1
|
+
var P=Object.defineProperty;var n=(o,t)=>P(o,"name",{value:t,configurable:!0});import{CloudTasksClient as R}from"@google-cloud/tasks";import{credentials as C}from"@grpc/grpc-js";import{GoogleAuth as x}from"google-auth-library";import{Status as f}from"google-gax";import{Err as l,Ok as c}from"ts-results-es";var g=class{constructor(t,e,r,a){this.client=t;this.location=e;this.queueName=r;this.logger=a;this.projectIdPromise=this.client.getProjectId(),this.serviceAccountEmailPromise=new x().getCredentials().then(s=>s.client_email??null)}static{n(this,"CommonTasksClient")}serviceAccountEmailPromise;projectIdPromise;async upsertQueue(t){try{let e=await this.projectIdPromise,r=this.client.queuePath(e,this.location,this.queueName),a=this.client.locationPath(e,this.location);this.logger.info({queuePath:r,parentPath:a},"upserting tasks queue");let s="create";try{await this.client.getQueue({name:r}),s="update"}catch(i){if(h(i)&&i.code===f.NOT_FOUND)s="create";else throw i}return s==="update"?(this.logger.info({queuePath:r},"updating existing queue"),await this.client.updateQueue({queue:{name:r,...t}})):(this.logger.info({queuePath:r},"creating new queue"),await this.client.createQueue({parent:a,queue:{name:r,...t}})),c.EMPTY}catch(e){return l(p(e))}}async listTasks(){try{let t=await this.projectIdPromise,e=this.client.queuePath(t,this.location,this.queueName),[r]=await this.client.listTasks({parent:e});return c(r)}catch(t){return l(p(t))}}async createTask(t,e){try{let r=await this.projectIdPromise,a=this.client.queuePath(r,this.location,this.queueName),s=this.client.taskPath(r,this.location,this.queueName,v(t)),i=await this.serviceAccountEmailPromise;return this.logger.info({queuePath:a,taskPath:s,url:e?.httpRequest?.url,payload:e?.httpRequest?.body,serviceAccountEmail:i},"scheduling task"),await this.client.createTask({parent:a,task:{...e,name:s,httpRequest:{...e?.httpRequest,oidcToken:{serviceAccountEmail:i}}}}),c(s)}catch(r){return l(p(r))}}async getTask(t){try{let[e]=await this.client.getTask({name:t});return c(e)}catch(e){return h(e)&&e.code===f.NOT_FOUND?c(null):l(p(e))}}},d=class extends g{static{n(this,"RegularTasksClient")}constructor(t,e,r){super(new R({}),t,e,r)}},m=class extends g{static{n(this,"EmulatorTasksClient")}constructor(t,e,r,a){super(new R({sslCreds:C.createInsecure(),servicePath:a.host??"localhost",port:a.port}),t,e,r)}async upsertQueue(t){try{let e=await this.projectIdPromise,r=this.client.queuePath(e,this.location,this.queueName),a=this.client.locationPath(e,this.location);this.logger.info({queuePath:r,parentPath:a},"upserting simulator tasks queue");try{return await this.client.createQueue({parent:a,queue:{name:r,...t}}),c.EMPTY}catch(s){return h(s)&&s.code!==f.ALREADY_EXISTS?l(p(s)):(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"),c.EMPTY)}}catch(e){return l(p(e))}}async createTask(t,e){return super.createTask(t,{...e,httpRequest:{...e?.httpRequest,url:e?.httpRequest?.url?.replace("//localhost","//host.containers.internal")}})}};function v(o){let t=new Uint8Array(3);crypto.getRandomValues(t);let e=Buffer.from(t).toString("hex");return`${o}-${Date.now()}-${e}`}n(v,"createUniqueName");function h(o){return o instanceof Error&&"code"in o&&Number.isInteger(o.code)}n(h,"isRpcError");function p(o){return h(o)?{...o,type:"rpc"}:{type:"unknown",error:o}}n(p,"toTasksError");function D({queueName:o,emulator:t=!1,location:e="europe-west6",tasksWorkerUrl:r,queueOptions:a,logger:s={error:console.error,info:console.info,warn:console.warn}}){s.info({queueName:o,emulator:t,location:e,tasksWorkerUrl:r},"creating tasks client");let i=t?new m(e,o,s,t):new d(e,o,s);return new Proxy({},{get:n((A,T)=>T==="_manage"?{find:n(u=>i.getTask(u).then(k=>k.unwrap()),"find"),list:n(()=>i.listTasks().then(u=>u.unwrap()),"list")}:{schedule:n(async(u,k)=>{let y=T.toString();await i.upsertQueue(a);let w=new URL(`/trpc/${y}`,r).toString();return s.info({url:w,input:u},"scheduling http request that calls trpc mutation of tasks worker"),(await i.createTask(y,{...k,httpRequest:{httpMethod:"POST",url:w,headers:{"Content-Type":"application/json"},body:u?Buffer.from(JSON.stringify(u)).toString("base64"):null}})).unwrap()},"schedule")},"get")})}n(D,"createTasksClient");import{initTRPC as q}from"@trpc/server";import{createExpressMiddleware as E}from"@trpc/server/adapters/express";import S from"express";var I=n(o=>{let t=q.create(),e=o(t);return{expressMiddleware:E({router:e}),router:e}},"createExpressTaskServerMiddleware");function N(o,t){let e=t??S(),{expressMiddleware:r,router:a}=I(o);return e.use("/trpc",r),{runServer:n(s=>{e.listen({port:s})},"runServer"),router:a}}n(N,"createExpressTaskServer");var V=N;export{N as createExpressTaskServer,I as createExpressTaskServerMiddleware,D as createTasksClient,V as createTasksServer};
|
package/dist/server.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var m=Object.create;var p=Object.defineProperty;var y=Object.getOwnPropertyDescriptor;var l=Object.getOwnPropertyNames;var f=Object.getPrototypeOf,T=Object.prototype.hasOwnProperty;var n=(e,r)=>p(e,"name",{value:r,configurable:!0});var v=(e,r)=>{for(var t in r)p(e,t,{get:r[t],enumerable:!0})},u=(e,r,t,s)=>{if(r&&typeof r=="object"||typeof r=="function")for(let o of l(r))!T.call(e,o)&&o!==t&&p(e,o,{get:()=>r[o],enumerable:!(s=y(r,o))||s.enumerable});return e};var w=(e,r,t)=>(t=e!=null?m(f(e)):{},u(r||!e||!e.__esModule?p(t,"default",{value:e,enumerable:!0}):t,e)),A=e=>u(p({},"__esModule",{value:!0}),e);var M={};v(M,{createExpressTaskServer:()=>x,createExpressTaskServerMiddleware:()=>R,createTasksServer:()=>C});module.exports=A(M);var a=require("@trpc/server"),c=require("@trpc/server/adapters/express"),i=w(require("express"));var R=n(e=>{let r=a.initTRPC.create(),t=e(r);return{expressMiddleware:(0,c.createExpressMiddleware)({router:t}),router:t}},"createExpressTaskServerMiddleware");function x(e,r){let t=r??(0,i.default)(),{expressMiddleware:s,router:o}=R(e);return t.use("/trpc",s),{runServer:n(d=>{t.listen({port:d})},"runServer"),router:o}}n(x,"createExpressTaskServer");var C=x;
|
package/dist/server.d.ts
CHANGED
|
@@ -1,7 +1,18 @@
|
|
|
1
1
|
import type { AnyRouter } from "@trpc/server";
|
|
2
2
|
import { initTRPC } from "@trpc/server";
|
|
3
|
-
|
|
3
|
+
import express from "express";
|
|
4
|
+
type CreateRouter<Router extends AnyRouter> = (t: ReturnType<(typeof initTRPC)["create"]>) => Router;
|
|
5
|
+
export declare const createExpressTaskServerMiddleware: (createRouter: CreateRouter<AnyRouter>) => {
|
|
6
|
+
expressMiddleware: express.Handler;
|
|
7
|
+
router: AnyRouter;
|
|
8
|
+
};
|
|
9
|
+
export declare function createExpressTaskServer<Router extends AnyRouter>(createRouter: CreateRouter<Router>, existingApp?: express.Application): {
|
|
4
10
|
runServer: (port: number) => void;
|
|
5
|
-
router:
|
|
11
|
+
router: AnyRouter;
|
|
6
12
|
};
|
|
13
|
+
/**
|
|
14
|
+
* @deprecated Use `createExpressTaskServer` instead
|
|
15
|
+
*/
|
|
16
|
+
export declare const createTasksServer: typeof createExpressTaskServer;
|
|
17
|
+
export {};
|
|
7
18
|
//# sourceMappingURL=server.d.ts.map
|
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;AAC9C,OAAO,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAC9C,OAAO,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AAExC,OAAO,OAAO,MAAM,SAAS,CAAC;AAE9B,KAAK,YAAY,CAAC,MAAM,SAAS,SAAS,IAAI,CAC5C,CAAC,EAAE,UAAU,CAAC,CAAC,OAAO,QAAQ,CAAC,CAAC,QAAQ,CAAC,CAAC,KACvC,MAAM,CAAC;AAEZ,eAAO,MAAM,iCAAiC,GAC5C,cAAc,YAAY,CAAC,SAAS,CAAC;;;CAStC,CAAC;AACF,wBAAgB,uBAAuB,CAAC,MAAM,SAAS,SAAS,EAC9D,YAAY,EAAE,YAAY,CAAC,MAAM,CAAC,EAClC,WAAW,CAAC,EAAE,OAAO,CAAC,WAAW;sBAQb,MAAM;;EAK3B;AAED;;GAEG;AACH,eAAO,MAAM,iBAAiB,gCAA0B,CAAC"}
|
package/dist/server.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var
|
|
1
|
+
var u=Object.defineProperty;var o=(e,r)=>u(e,"name",{value:r,configurable:!0});import{initTRPC as a}from"@trpc/server";import{createExpressMiddleware as c}from"@trpc/server/adapters/express";import i from"express";var R=o(e=>{let r=a.create(),t=e(r);return{expressMiddleware:c({router:t}),router:t}},"createExpressTaskServerMiddleware");function x(e,r){let t=r??i(),{expressMiddleware:s,router:p}=R(e);return t.use("/trpc",s),{runServer:o(n=>{t.listen({port:n})},"runServer"),router:p}}o(x,"createExpressTaskServer");var f=x;export{x as createExpressTaskServer,R as createExpressTaskServerMiddleware,f as createTasksServer};
|
package/dist/tasksClients.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var l=Object.defineProperty;var T=Object.getOwnPropertyDescriptor;var f=Object.getOwnPropertyNames;var w=Object.prototype.hasOwnProperty;var i=(o,e)=>l(o,"name",{value:e,configurable:!0});var q=(o,e)=>{for(var t in e)l(o,t,{get:e[t],enumerable:!0})},E=(o,e,t,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of f(e))!w.call(o,s)&&s!==t&&l(o,s,{get:()=>e[s],enumerable:!(r=T(e,s))||r.enumerable});return o};var I=o=>E(l({},"__esModule",{value:!0}),o);var v={};q(v,{EmulatorTasksClient:()=>d,RegularTasksClient:()=>m});module.exports=I(v);var k=require("@google-cloud/tasks"),y=require("@grpc/grpc-js"),P=require("google-auth-library"),p=require("google-gax"),n=require("ts-results-es");var h=class{constructor(e,t,r,s){this.client=e;this.location=t;this.queueName=r;this.logger=s;this.projectIdPromise=this.client.getProjectId(),this.serviceAccountEmailPromise=new P.GoogleAuth().getCredentials().then(a=>a.client_email??null)}static{i(this,"CommonTasksClient")}serviceAccountEmailPromise;projectIdPromise;async upsertQueue(e){try{let t=await this.projectIdPromise,r=this.client.queuePath(t,this.location,this.queueName),s=this.client.locationPath(t,this.location);this.logger.info({queuePath:r,parentPath:s},"upserting tasks queue");let a="create";try{await this.client.getQueue({name:r}),a="update"}catch(u){if(g(u)&&u.code===p.Status.NOT_FOUND)a="create";else throw u}return a==="update"?(this.logger.info({queuePath:r},"updating existing queue"),await this.client.updateQueue({queue:{name:r,...e}})):(this.logger.info({queuePath:r},"creating new queue"),await this.client.createQueue({parent:s,queue:{name:r,...e}})),n.Ok.EMPTY}catch(t){return(0,n.Err)(c(t))}}async listTasks(){try{let e=await this.projectIdPromise,t=this.client.queuePath(e,this.location,this.queueName),[r]=await this.client.listTasks({parent:t});return(0,n.Ok)(r)}catch(e){return(0,n.Err)(c(e))}}async createTask(e,t){try{let r=await this.projectIdPromise,s=this.client.queuePath(r,this.location,this.queueName),a=this.client.taskPath(r,this.location,this.queueName,R(e)),u=await this.serviceAccountEmailPromise;return this.logger.info({queuePath:s,taskPath:a,url:t?.httpRequest?.url,payload:t?.httpRequest?.body,serviceAccountEmail:u},"scheduling task"),await this.client.createTask({parent:s,task:{...t,name:a,httpRequest:{...t?.httpRequest,oidcToken:{serviceAccountEmail:u}}}}),(0,n.Ok)(a)}catch(r){return(0,n.Err)(c(r))}}async getTask(e){try{let[t]=await this.client.getTask({name:e});return(0,n.Ok)(t)}catch(t){return g(t)&&t.code===p.Status.NOT_FOUND?(0,n.Ok)(null):(0,n.Err)(c(t))}}},m=class extends h{static{i(this,"RegularTasksClient")}constructor(e,t,r){super(new k.CloudTasksClient({}),e,t,r)}},d=class extends h{static{i(this,"EmulatorTasksClient")}constructor(e,t,r,s){super(new k.CloudTasksClient({sslCreds:y.credentials.createInsecure(),servicePath:s.host??"localhost",port:s.port}),e,t,r)}async upsertQueue(e){try{let t=await this.projectIdPromise,r=this.client.queuePath(t,this.location,this.queueName),s=this.client.locationPath(t,this.location);this.logger.info({queuePath:r,parentPath:s},"upserting simulator tasks queue");try{return await this.client.createQueue({parent:s,queue:{name:r,...e}}),n.Ok.EMPTY}catch(a){return g(a)&&a.code!==p.Status.ALREADY_EXISTS?(0,n.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"),n.Ok.EMPTY)}}catch(t){return(0,n.Err)(c(t))}}async createTask(e,t){return super.createTask(e,{...t,httpRequest:{...t?.httpRequest,url:t?.httpRequest?.url?.replace("//localhost","//host.containers.internal")}})}};function R(o){let e=new Uint8Array(3);crypto.getRandomValues(e);let t=Buffer.from(e).toString("hex");return`${o}-${
|
|
1
|
+
"use strict";var l=Object.defineProperty;var T=Object.getOwnPropertyDescriptor;var f=Object.getOwnPropertyNames;var w=Object.prototype.hasOwnProperty;var i=(o,e)=>l(o,"name",{value:e,configurable:!0});var q=(o,e)=>{for(var t in e)l(o,t,{get:e[t],enumerable:!0})},E=(o,e,t,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of f(e))!w.call(o,s)&&s!==t&&l(o,s,{get:()=>e[s],enumerable:!(r=T(e,s))||r.enumerable});return o};var I=o=>E(l({},"__esModule",{value:!0}),o);var v={};q(v,{EmulatorTasksClient:()=>d,RegularTasksClient:()=>m});module.exports=I(v);var k=require("@google-cloud/tasks"),y=require("@grpc/grpc-js"),P=require("google-auth-library"),p=require("google-gax"),n=require("ts-results-es");var h=class{constructor(e,t,r,s){this.client=e;this.location=t;this.queueName=r;this.logger=s;this.projectIdPromise=this.client.getProjectId(),this.serviceAccountEmailPromise=new P.GoogleAuth().getCredentials().then(a=>a.client_email??null)}static{i(this,"CommonTasksClient")}serviceAccountEmailPromise;projectIdPromise;async upsertQueue(e){try{let t=await this.projectIdPromise,r=this.client.queuePath(t,this.location,this.queueName),s=this.client.locationPath(t,this.location);this.logger.info({queuePath:r,parentPath:s},"upserting tasks queue");let a="create";try{await this.client.getQueue({name:r}),a="update"}catch(u){if(g(u)&&u.code===p.Status.NOT_FOUND)a="create";else throw u}return a==="update"?(this.logger.info({queuePath:r},"updating existing queue"),await this.client.updateQueue({queue:{name:r,...e}})):(this.logger.info({queuePath:r},"creating new queue"),await this.client.createQueue({parent:s,queue:{name:r,...e}})),n.Ok.EMPTY}catch(t){return(0,n.Err)(c(t))}}async listTasks(){try{let e=await this.projectIdPromise,t=this.client.queuePath(e,this.location,this.queueName),[r]=await this.client.listTasks({parent:t});return(0,n.Ok)(r)}catch(e){return(0,n.Err)(c(e))}}async createTask(e,t){try{let r=await this.projectIdPromise,s=this.client.queuePath(r,this.location,this.queueName),a=this.client.taskPath(r,this.location,this.queueName,R(e)),u=await this.serviceAccountEmailPromise;return this.logger.info({queuePath:s,taskPath:a,url:t?.httpRequest?.url,payload:t?.httpRequest?.body,serviceAccountEmail:u},"scheduling task"),await this.client.createTask({parent:s,task:{...t,name:a,httpRequest:{...t?.httpRequest,oidcToken:{serviceAccountEmail:u}}}}),(0,n.Ok)(a)}catch(r){return(0,n.Err)(c(r))}}async getTask(e){try{let[t]=await this.client.getTask({name:e});return(0,n.Ok)(t)}catch(t){return g(t)&&t.code===p.Status.NOT_FOUND?(0,n.Ok)(null):(0,n.Err)(c(t))}}},m=class extends h{static{i(this,"RegularTasksClient")}constructor(e,t,r){super(new k.CloudTasksClient({}),e,t,r)}},d=class extends h{static{i(this,"EmulatorTasksClient")}constructor(e,t,r,s){super(new k.CloudTasksClient({sslCreds:y.credentials.createInsecure(),servicePath:s.host??"localhost",port:s.port}),e,t,r)}async upsertQueue(e){try{let t=await this.projectIdPromise,r=this.client.queuePath(t,this.location,this.queueName),s=this.client.locationPath(t,this.location);this.logger.info({queuePath:r,parentPath:s},"upserting simulator tasks queue");try{return await this.client.createQueue({parent:s,queue:{name:r,...e}}),n.Ok.EMPTY}catch(a){return g(a)&&a.code!==p.Status.ALREADY_EXISTS?(0,n.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"),n.Ok.EMPTY)}}catch(t){return(0,n.Err)(c(t))}}async createTask(e,t){return super.createTask(e,{...t,httpRequest:{...t?.httpRequest,url:t?.httpRequest?.url?.replace("//localhost","//host.containers.internal")}})}};function R(o){let e=new Uint8Array(3);crypto.getRandomValues(e);let t=Buffer.from(e).toString("hex");return`${o}-${Date.now()}-${t}`}i(R,"createUniqueName");function g(o){return o instanceof Error&&"code"in o&&Number.isInteger(o.code)}i(g,"isRpcError");function c(o){return g(o)?{...o,type:"rpc"}:{type:"unknown",error:o}}i(c,"toTasksError");
|
package/dist/tasksClients.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var y=Object.defineProperty;var a=(o,e)=>y(o,"name",{value:e,configurable:!0});import{CloudTasksClient as k}from"@google-cloud/tasks";import{credentials as P}from"@grpc/grpc-js";import{GoogleAuth as T}from"google-auth-library";import{Status as g}from"google-gax";import{Err as c,Ok as i}from"ts-results-es";var p=class{constructor(e,t,r,n){this.client=e;this.location=t;this.queueName=r;this.logger=n;this.projectIdPromise=this.client.getProjectId(),this.serviceAccountEmailPromise=new T().getCredentials().then(s=>s.client_email??null)}static{a(this,"CommonTasksClient")}serviceAccountEmailPromise;projectIdPromise;async upsertQueue(e){try{let t=await this.projectIdPromise,r=this.client.queuePath(t,this.location,this.queueName),n=this.client.locationPath(t,this.location);this.logger.info({queuePath:r,parentPath:n},"upserting tasks queue");let s="create";try{await this.client.getQueue({name:r}),s="update"}catch(u){if(h(u)&&u.code===g.NOT_FOUND)s="create";else throw u}return s==="update"?(this.logger.info({queuePath:r},"updating existing queue"),await this.client.updateQueue({queue:{name:r,...e}})):(this.logger.info({queuePath:r},"creating new queue"),await this.client.createQueue({parent:n,queue:{name:r,...e}})),i.EMPTY}catch(t){return c(l(t))}}async listTasks(){try{let e=await this.projectIdPromise,t=this.client.queuePath(e,this.location,this.queueName),[r]=await this.client.listTasks({parent:t});return i(r)}catch(e){return c(l(e))}}async createTask(e,t){try{let r=await this.projectIdPromise,n=this.client.queuePath(r,this.location,this.queueName),s=this.client.taskPath(r,this.location,this.queueName,f(e)),u=await this.serviceAccountEmailPromise;return this.logger.info({queuePath:n,taskPath:s,url:t?.httpRequest?.url,payload:t?.httpRequest?.body,serviceAccountEmail:u},"scheduling task"),await this.client.createTask({parent:n,task:{...t,name:s,httpRequest:{...t?.httpRequest,oidcToken:{serviceAccountEmail:u}}}}),i(s)}catch(r){return c(l(r))}}async getTask(e){try{let[t]=await this.client.getTask({name:e});return i(t)}catch(t){return h(t)&&t.code===g.NOT_FOUND?i(null):c(l(t))}}},m=class extends p{static{a(this,"RegularTasksClient")}constructor(e,t,r){super(new k({}),e,t,r)}},d=class extends p{static{a(this,"EmulatorTasksClient")}constructor(e,t,r,n){super(new k({sslCreds:P.createInsecure(),servicePath:n.host??"localhost",port:n.port}),e,t,r)}async upsertQueue(e){try{let t=await this.projectIdPromise,r=this.client.queuePath(t,this.location,this.queueName),n=this.client.locationPath(t,this.location);this.logger.info({queuePath:r,parentPath:n},"upserting simulator tasks queue");try{return await this.client.createQueue({parent:n,queue:{name:r,...e}}),i.EMPTY}catch(s){return h(s)&&s.code!==g.ALREADY_EXISTS?c(l(s)):(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"),i.EMPTY)}}catch(t){return c(l(t))}}async createTask(e,t){return super.createTask(e,{...t,httpRequest:{...t?.httpRequest,url:t?.httpRequest?.url?.replace("//localhost","//host.containers.internal")}})}};function f(o){let e=new Uint8Array(3);crypto.getRandomValues(e);let t=Buffer.from(e).toString("hex");return`${o}-${
|
|
1
|
+
var y=Object.defineProperty;var a=(o,e)=>y(o,"name",{value:e,configurable:!0});import{CloudTasksClient as k}from"@google-cloud/tasks";import{credentials as P}from"@grpc/grpc-js";import{GoogleAuth as T}from"google-auth-library";import{Status as g}from"google-gax";import{Err as c,Ok as i}from"ts-results-es";var p=class{constructor(e,t,r,n){this.client=e;this.location=t;this.queueName=r;this.logger=n;this.projectIdPromise=this.client.getProjectId(),this.serviceAccountEmailPromise=new T().getCredentials().then(s=>s.client_email??null)}static{a(this,"CommonTasksClient")}serviceAccountEmailPromise;projectIdPromise;async upsertQueue(e){try{let t=await this.projectIdPromise,r=this.client.queuePath(t,this.location,this.queueName),n=this.client.locationPath(t,this.location);this.logger.info({queuePath:r,parentPath:n},"upserting tasks queue");let s="create";try{await this.client.getQueue({name:r}),s="update"}catch(u){if(h(u)&&u.code===g.NOT_FOUND)s="create";else throw u}return s==="update"?(this.logger.info({queuePath:r},"updating existing queue"),await this.client.updateQueue({queue:{name:r,...e}})):(this.logger.info({queuePath:r},"creating new queue"),await this.client.createQueue({parent:n,queue:{name:r,...e}})),i.EMPTY}catch(t){return c(l(t))}}async listTasks(){try{let e=await this.projectIdPromise,t=this.client.queuePath(e,this.location,this.queueName),[r]=await this.client.listTasks({parent:t});return i(r)}catch(e){return c(l(e))}}async createTask(e,t){try{let r=await this.projectIdPromise,n=this.client.queuePath(r,this.location,this.queueName),s=this.client.taskPath(r,this.location,this.queueName,f(e)),u=await this.serviceAccountEmailPromise;return this.logger.info({queuePath:n,taskPath:s,url:t?.httpRequest?.url,payload:t?.httpRequest?.body,serviceAccountEmail:u},"scheduling task"),await this.client.createTask({parent:n,task:{...t,name:s,httpRequest:{...t?.httpRequest,oidcToken:{serviceAccountEmail:u}}}}),i(s)}catch(r){return c(l(r))}}async getTask(e){try{let[t]=await this.client.getTask({name:e});return i(t)}catch(t){return h(t)&&t.code===g.NOT_FOUND?i(null):c(l(t))}}},m=class extends p{static{a(this,"RegularTasksClient")}constructor(e,t,r){super(new k({}),e,t,r)}},d=class extends p{static{a(this,"EmulatorTasksClient")}constructor(e,t,r,n){super(new k({sslCreds:P.createInsecure(),servicePath:n.host??"localhost",port:n.port}),e,t,r)}async upsertQueue(e){try{let t=await this.projectIdPromise,r=this.client.queuePath(t,this.location,this.queueName),n=this.client.locationPath(t,this.location);this.logger.info({queuePath:r,parentPath:n},"upserting simulator tasks queue");try{return await this.client.createQueue({parent:n,queue:{name:r,...e}}),i.EMPTY}catch(s){return h(s)&&s.code!==g.ALREADY_EXISTS?c(l(s)):(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"),i.EMPTY)}}catch(t){return c(l(t))}}async createTask(e,t){return super.createTask(e,{...t,httpRequest:{...t?.httpRequest,url:t?.httpRequest?.url?.replace("//localhost","//host.containers.internal")}})}};function f(o){let e=new Uint8Array(3);crypto.getRandomValues(e);let t=Buffer.from(e).toString("hex");return`${o}-${Date.now()}-${t}`}a(f,"createUniqueName");function h(o){return o instanceof Error&&"code"in o&&Number.isInteger(o.code)}a(h,"isRpcError");function l(o){return h(o)?{...o,type:"rpc"}:{type:"unknown",error:o}}a(l,"toTasksError");export{d as EmulatorTasksClient,m as RegularTasksClient};
|
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": "
|
|
7
|
+
"version": "2.0.1",
|
|
8
8
|
"sideEffects": false,
|
|
9
9
|
"exports": {
|
|
10
10
|
".": {
|
|
@@ -47,18 +47,18 @@
|
|
|
47
47
|
"test": "echo 'todo: write tests'"
|
|
48
48
|
},
|
|
49
49
|
"dependencies": {
|
|
50
|
-
"@google-cloud/tasks": "^
|
|
51
|
-
"@trpc/client": "^
|
|
52
|
-
"@trpc/server": "^
|
|
53
|
-
"express": "^
|
|
54
|
-
"ts-results-es": "^
|
|
50
|
+
"@google-cloud/tasks": "^6.2.1",
|
|
51
|
+
"@trpc/client": "^11.8.1",
|
|
52
|
+
"@trpc/server": "^11.8.1",
|
|
53
|
+
"express": "^5",
|
|
54
|
+
"ts-results-es": "^6.0.0"
|
|
55
55
|
},
|
|
56
56
|
"devDependencies": {
|
|
57
|
-
"@biomejs/biome": "
|
|
58
|
-
"@types/express": "^
|
|
59
|
-
"esbuild": "^0.
|
|
60
|
-
"prettier": "^3.4
|
|
61
|
-
"typescript": "5.
|
|
57
|
+
"@biomejs/biome": "2.3.10",
|
|
58
|
+
"@types/express": "^5.0.6",
|
|
59
|
+
"esbuild": "^0.27.2",
|
|
60
|
+
"prettier": "^3.7.4",
|
|
61
|
+
"typescript": "^5.9.3"
|
|
62
62
|
},
|
|
63
63
|
"packageManager": "yarn@4.6.0"
|
|
64
64
|
}
|