Skip to content

Commit bd05720

Browse files
authored
refactor: use TRPCUntypedClient (#62)
1 parent d7b6478 commit bd05720

8 files changed

Lines changed: 171 additions & 177 deletions

File tree

auth.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import open from "open";
44
import { encodeBase64 } from "@std/encoding";
55
import { green } from "@std/fmt/colors";
66
import {
7-
createTRPCClient,
7+
createTRPCUntypedClient,
88
httpBatchStreamLink,
99
httpSubscriptionLink,
1010
retryLink,
@@ -63,8 +63,7 @@ export function createTrpcClient(
6363

6464
let retryPromise: Promise<void> | undefined = undefined;
6565

66-
// deno-lint-ignore no-explicit-any
67-
return createTRPCClient<any>({
66+
return createTRPCUntypedClient({
6867
links: [
6968
errorLink,
7069
retryLink({
@@ -281,7 +280,7 @@ export async function authedFetch(
281280
endpoint: string,
282281
init: RequestInit,
283282
) {
284-
let auth = await tokenStorage.get();
283+
let auth = tokenStorage.get();
285284

286285
if (!auth) {
287286
auth = await getAuth(context);

config.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,11 @@ export async function getOrg(
3333
if (!org) {
3434
const trpcClient = createTrpcClient(context);
3535

36-
const orgs: Array<{
36+
const orgs = await trpcClient.query("orgs.list") as Array<{
3737
name: string;
3838
slug: string;
3939
id: string;
40-
// deno-lint-ignore no-explicit-any
41-
}> = await (trpcClient.orgs as any).list.query();
40+
}>;
4241

4342
if (org !== undefined) {
4443
const fullOrg = orgs.find((fullOrg) => fullOrg.slug === org);
@@ -111,9 +110,10 @@ export async function getApp(
111110
if (app === undefined) {
112111
const trpcClient = createTrpcClient(context);
113112

114-
const apps: Array<{ name: string; slug: string }> =
115-
// deno-lint-ignore no-explicit-any
116-
await (trpcClient.apps as any).list.query({ org });
113+
const apps = await trpcClient.query("apps.list", { org }) as Array<{
114+
name: string;
115+
slug: string;
116+
}>;
117117
const appStrings: PromptEntry<{ name: string; slug: string } | null>[] =
118118
apps.map((app) => ({ label: app.slug, value: app }));
119119
if (canCreate) {

deploy/database.ts

Lines changed: 16 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,10 @@ const databasesProvisionCommand = new Command<DatabaseContext>()
3434
const trpcClient = createTrpcClient(options);
3535

3636
if (options.kind === "prisma" && !options.region) {
37-
// deno-lint-ignore no-explicit-any
38-
const regions: Array<{ id: string }> = await (trpcClient.databases as any)
39-
.prismaRegions.query({
40-
org,
41-
});
37+
const regions = await trpcClient.query(
38+
"databases.prismaRegions",
39+
{ org },
40+
) as Array<{ id: string }>;
4241

4342
throw new ValidationError(
4443
`region is required for Prisma databases.\n Valid values are: ${
@@ -47,8 +46,7 @@ const databasesProvisionCommand = new Command<DatabaseContext>()
4746
);
4847
}
4948

50-
// deno-lint-ignore no-explicit-any
51-
await (trpcClient.databases as any).createInstance.mutate({
49+
await trpcClient.mutation("databases.createInstance", {
5250
org: org,
5351
slug: name,
5452
engine: options.kind,
@@ -136,15 +134,13 @@ const databasesLinkCommand = new Command<DatabaseContext>()
136134
};
137135

138136
if (options.dryRun) {
139-
// deno-lint-ignore no-explicit-any
140-
await (trpcClient.databases as any).testConnection.mutate({
137+
await trpcClient.mutation("databases.testConnection", {
141138
org: org,
142139
engine,
143140
connection_config: connectionConfig,
144141
});
145142
} else {
146-
// deno-lint-ignore no-explicit-any
147-
await (trpcClient.databases as any).createInstance.mutate({
143+
await trpcClient.mutation("databases.createInstance", {
148144
org: org,
149145
slug: name,
150146
engine,
@@ -164,8 +160,7 @@ const databasesAssignCommand = new Command<DatabaseContext>()
164160
const { app } = await getApp(options, config, false, org, options.app);
165161
const trpcClient = createTrpcClient(options);
166162

167-
// deno-lint-ignore no-explicit-any
168-
await (trpcClient.apps as any).assignDatabaseAttachment.mutate({
163+
await trpcClient.mutation("apps.assignDatabaseAttachment", {
169164
org,
170165
app,
171166
databaseInstance: name,
@@ -183,8 +178,7 @@ const databasesDetachCommand = new Command<DatabaseContext>()
183178
const { app } = await getApp(options, config, false, org, options.app);
184179
const trpcClient = createTrpcClient(options);
185180

186-
// deno-lint-ignore no-explicit-any
187-
await (trpcClient.apps as any).removeDatabaseAttachment.mutate({
181+
await trpcClient.mutation("apps.removeDatabaseAttachment", {
188182
org,
189183
app,
190184
databaseInstance: name,
@@ -206,7 +200,7 @@ const databasesQueryCommand = new Command<DatabaseContext>()
206200
: query;
207201

208202
// deno-lint-ignore no-explicit-any
209-
const res = await (trpcClient.databases as any).executeQuery.mutate({
203+
const res: any = await trpcClient.mutation("databases.executeQuery", {
210204
org,
211205
databaseInstance: name,
212206
databaseName: database,
@@ -261,18 +255,17 @@ const databasesListCommand = new Command<DatabaseContext>()
261255
const org = await getOrg(options, config, options.org);
262256
const trpcClient = createTrpcClient(options);
263257

264-
const list: Array<
258+
const list = await trpcClient.query("databases.listInstances", {
259+
org: org,
260+
search,
261+
}) as Array<
265262
{
266263
slug: string;
267264
created_at: Date;
268265
databases: Array<{ name: string; status: string; created_at: Date }>;
269266
assignments: Array<{ app_slug: string }>;
270267
} & ConnectionInfo
271-
> // deno-lint-ignore no-explicit-any
272-
= await (trpcClient.databases as any).listInstances.query({
273-
org: org,
274-
search,
275-
});
268+
>;
276269

277270
tablePrinter(
278271
["NAME", "ENGINE", "ASSIGNMENTS", "CONNECTION DETAILS"],
@@ -316,8 +309,7 @@ const databasesDeleteCommand = new Command<DatabaseContext>()
316309
const org = await getOrg(options, config, options.org);
317310
const trpcClient = createTrpcClient(options);
318311

319-
// deno-lint-ignore no-explicit-any
320-
await (trpcClient.databases as any).delete.mutate({
312+
await trpcClient.mutation("databases.delete", {
321313
org,
322314
databaseInstance: name,
323315
});

deploy/env.ts

Lines changed: 38 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,10 @@ const envListCommand = new Command<EnvCommandContext>()
3131

3232
const trpcClient = createTrpcClient(options);
3333

34-
// deno-lint-ignore no-explicit-any
35-
const envVars: EnvVar[] = await (trpcClient.envVarsContexts as any).list
36-
.query({ org, app });
34+
const envVars = await trpcClient.query("envVarsContexts.list", {
35+
org,
36+
app,
37+
}) as EnvVar[];
3738

3839
if (envVars.length === 0) {
3940
console.log(
@@ -42,9 +43,10 @@ const envListCommand = new Command<EnvCommandContext>()
4243
return;
4344
}
4445

45-
// deno-lint-ignore no-explicit-any
46-
const contexts: Context[] = await (trpcClient.envVarsContexts as any)
47-
.listContexts.query({ org });
46+
const contexts = await trpcClient.query(
47+
"envVarsContexts.listContexts",
48+
{ org },
49+
) as Context[];
4850

4951
const contextTitle = `CONTEXTS (${
5052
contexts.map((context) => context.name).join(", ")
@@ -85,14 +87,12 @@ const envAddCommand = new Command<EnvCommandContext>()
8587

8688
const trpcClient = createTrpcClient(options);
8789

88-
// deno-lint-ignore no-explicit-any
89-
const fullApp = await (trpcClient.apps as any).get.query({
90+
const fullApp = await trpcClient.query("apps.get", {
9091
org,
9192
app,
92-
});
93+
}) as { id: string };
9394

94-
// deno-lint-ignore no-explicit-any
95-
await (trpcClient.envVarsContexts as any).updateEnvVars.mutate({
95+
await trpcClient.mutation("envVarsContexts.updateEnvVars", {
9696
org,
9797
add: [
9898
{
@@ -123,18 +123,18 @@ const envUpdateValueCommand = new Command<EnvCommandContext>()
123123

124124
const trpcClient = createTrpcClient(options);
125125

126-
// deno-lint-ignore no-explicit-any
127-
const envVars: EnvVar[] = await (trpcClient.envVarsContexts as any).list
128-
.query({ org, app });
126+
const envVars = await trpcClient.query("envVarsContexts.list", {
127+
org,
128+
app,
129+
}) as EnvVar[];
129130

130131
const envVar = envVars.find((envVar) => envVar.key === variable);
131132

132133
if (!envVar) {
133134
error(options, `Environment variable '${variable}' not found`);
134135
}
135136

136-
// deno-lint-ignore no-explicit-any
137-
await (trpcClient.envVarsContexts as any).updateEnvVars.mutate({
137+
await trpcClient.mutation("envVarsContexts.updateEnvVars", {
138138
org,
139139
add: [],
140140
update: [{
@@ -160,19 +160,21 @@ You can define no contexts, which is the equivalent to "All"`,
160160
const { app } = await getApp(options, config, false, org, options.app);
161161
const trpcClient = createTrpcClient(options);
162162

163-
// deno-lint-ignore no-explicit-any
164-
const envVars: EnvVar[] = await (trpcClient.envVarsContexts as any).list
165-
.query({ org, app });
163+
const envVars = await trpcClient.query("envVarsContexts.list", {
164+
org,
165+
app,
166+
}) as EnvVar[];
166167

167168
const envVar = envVars.find((envVar) => envVar.key === variable);
168169

169170
if (!envVar) {
170171
error(options, `Environment variable '${variable}' not found`);
171172
}
172173

173-
// deno-lint-ignore no-explicit-any
174-
const contexts: Context[] = await (trpcClient.envVarsContexts as any)
175-
.listContexts.query({ org });
174+
const contexts = await trpcClient.query(
175+
"envVarsContexts.listContexts",
176+
{ org },
177+
) as Context[];
176178

177179
const contextIds = [];
178180

@@ -185,8 +187,7 @@ You can define no contexts, which is the equivalent to "All"`,
185187
contextIds.push(context.id);
186188
}
187189

188-
// deno-lint-ignore no-explicit-any
189-
await (trpcClient.envVarsContexts as any).updateEnvVars.mutate({
190+
await trpcClient.mutation("envVarsContexts.updateEnvVars", {
190191
org,
191192
add: [],
192193
update: [{
@@ -209,18 +210,18 @@ const envDeleteCommand = new Command<EnvCommandContext>()
209210
const { app } = await getApp(options, config, false, org, options.app);
210211
const trpcClient = createTrpcClient(options);
211212

212-
// deno-lint-ignore no-explicit-any
213-
const envVars: EnvVar[] = await (trpcClient.envVarsContexts as any).list
214-
.query({ org, app });
213+
const envVars = await trpcClient.query("envVarsContexts.list", {
214+
org,
215+
app,
216+
}) as EnvVar[];
215217

216218
const envVar = envVars.find((envVar) => envVar.key === variable);
217219

218220
if (!envVar) {
219221
error(options, `Environment variable '${variable}' not found`);
220222
}
221223

222-
// deno-lint-ignore no-explicit-any
223-
await (trpcClient.envVarsContexts as any).updateEnvVars.mutate({
224+
await trpcClient.mutation("envVarsContexts.updateEnvVars", {
224225
org,
225226
add: [],
226227
update: [],
@@ -255,14 +256,16 @@ const envLoadCommand = new Command<EnvCommandContext>()
255256
const { app } = await getApp(options, config, false, org, options.app);
256257
const trpcClient = createTrpcClient(options);
257258

258-
// deno-lint-ignore no-explicit-any
259-
const fullApp = await (trpcClient.apps as any).get.query({ org, app });
259+
const fullApp = await trpcClient.query("apps.get", { org, app }) as {
260+
id: string;
261+
};
260262

261263
const variables = dotEnvParse(await Deno.readTextFile(file));
262264

263-
// deno-lint-ignore no-explicit-any
264-
const existingEnvVars: EnvVar[] = await (trpcClient.envVarsContexts as any)
265-
.list.query({ org, app });
265+
const existingEnvVars = await trpcClient.query(
266+
"envVarsContexts.list",
267+
{ org, app },
268+
) as EnvVar[];
266269

267270
const addEnvVars = [];
268271
let updateEnvVars = [];
@@ -334,8 +337,7 @@ const envLoadCommand = new Command<EnvCommandContext>()
334337
console.log();
335338
}
336339

337-
// deno-lint-ignore no-explicit-any
338-
await (trpcClient.envVarsContexts as any).updateEnvVars.mutate({
340+
await trpcClient.mutation("envVarsContexts.updateEnvVars", {
339341
org,
340342
add: addEnvVars,
341343
update: updateEnvVars,

0 commit comments

Comments
 (0)