Skip to content

Commit 88420d5

Browse files
authored
feat: Export types (#19)
* feat: export types * fix: add missing types * fix: tidy up exported types
1 parent f493b14 commit 88420d5

6 files changed

Lines changed: 90 additions & 24 deletions

File tree

src/api-token.ts

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,19 @@ export interface ApiToken {
66
name: string;
77
}
88

9+
export interface ApiTokenWithJWT extends ApiToken {
10+
token: string;
11+
}
12+
13+
export interface RevokedApiToken {
14+
token: string;
15+
}
16+
17+
export interface ApiTokenValidation {
18+
valid: boolean;
19+
expiry: number;
20+
}
21+
922
export class ApiTokenClient {
1023
constructor(private config: TursoConfig) {}
1124

@@ -18,8 +31,8 @@ export class ApiTokenClient {
1831
return response.tokens ?? [];
1932
}
2033

21-
async create(name: string) {
22-
const response = await TursoClient.request<ApiToken & { token: string }>(
34+
async create(name: string): Promise<ApiTokenWithJWT> {
35+
const response = await TursoClient.request<ApiTokenWithJWT>(
2336
`auth/api-tokens/${name}`,
2437
this.config,
2538
{
@@ -33,8 +46,8 @@ export class ApiTokenClient {
3346
return response;
3447
}
3548

36-
async revoke(name: string) {
37-
const response = await TursoClient.request<{ token: string }>(
49+
async revoke(name: string): Promise<RevokedApiToken> {
50+
const response = await TursoClient.request<RevokedApiToken>(
3851
`auth/api-tokens/${name}`,
3952
this.config,
4053
{
@@ -45,7 +58,7 @@ export class ApiTokenClient {
4558
return response;
4659
}
4760

48-
async validate(token: string): Promise<{ valid: boolean; expiry: number }> {
61+
async validate(token: string): Promise<ApiTokenValidation> {
4962
const response = await TursoClient.request<{ exp: number }>(
5063
"auth/api-tokens/validate",
5164
this.config,

src/database.ts

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,19 +29,19 @@ export interface ApiCreateDatabaseResponse {
2929
Name: string;
3030
}
3131

32-
export interface DatabaseCreateResponse {
32+
export interface CreatedDatabase {
3333
name: string;
3434
id: string;
3535
hostname: string;
3636
}
3737

38-
export interface DatabaseInstanceUsageDetail {
38+
interface DatabaseInstanceUsageDetail {
3939
rows_read: number;
4040
rows_written: number;
4141
storage_bytes: number;
4242
}
4343

44-
export interface DatabaseInstanceUsage {
44+
interface DatabaseInstanceUsage {
4545
uuid: string;
4646
usage: DatabaseInstanceUsageDetail;
4747
}
@@ -70,6 +70,14 @@ export interface DatabaseInstance {
7070
hostname: string;
7171
}
7272

73+
export interface DeletedDatabase {
74+
database: string;
75+
}
76+
77+
export interface DatabaseToken {
78+
jwt: string;
79+
}
80+
7381
type MultiDBSchemaOptions =
7482
| { is_schema: boolean; schema?: never }
7583
| { is_schema?: never; schema: string }
@@ -118,7 +126,7 @@ export class DatabaseClient {
118126
timestamp?: string | Date;
119127
};
120128
} & MultiDBSchemaOptions
121-
): Promise<DatabaseCreateResponse> {
129+
): Promise<CreatedDatabase> {
122130
if (hasIsSchemaOption(options) && hasSchemaOption(options)) {
123131
throw new Error("'is_schema' and 'schema' cannot both be provided");
124132
}
@@ -163,7 +171,7 @@ export class DatabaseClient {
163171
}
164172

165173
async delete(dbName: string) {
166-
const response = await TursoClient.request<{ database: string }>(
174+
const response = await TursoClient.request<DeletedDatabase>(
167175
`organizations/${this.config.org}/databases/${dbName}`,
168176
this.config,
169177
{
@@ -205,7 +213,7 @@ export class DatabaseClient {
205213
expiration: string;
206214
authorization: "read-only" | "full-access";
207215
}
208-
) {
216+
): Promise<DatabaseToken> {
209217
const queryParams = new URLSearchParams();
210218

211219
if (options?.expiration) {
@@ -216,7 +224,7 @@ export class DatabaseClient {
216224
queryParams.set("authorization", options.authorization);
217225
}
218226

219-
const response = await TursoClient.request<{ jwt: string }>(
227+
const response = await TursoClient.request<DatabaseToken>(
220228
`organizations/${this.config.org}/databases/${dbName}/auth/tokens?${queryParams}`,
221229
this.config,
222230
{
@@ -286,9 +294,7 @@ export class DatabaseClient {
286294
};
287295
}
288296

289-
private formatCreateResponse(
290-
db: ApiCreateDatabaseResponse
291-
): DatabaseCreateResponse {
297+
private formatCreateResponse(db: ApiCreateDatabaseResponse): CreatedDatabase {
292298
return {
293299
id: db.DbId,
294300
hostname: db.Hostname,

src/group.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ export type ExtensionType =
2020
| "uuid"
2121
| "regexp";
2222

23+
export interface GroupToken {
24+
jwt: string;
25+
}
26+
2327
export class GroupClient {
2428
constructor(private config: TursoConfig) {}
2529

@@ -113,7 +117,7 @@ export class GroupClient {
113117
expiration: string;
114118
authorization: "read-only" | "full-access";
115119
}
116-
) {
120+
): Promise<GroupToken> {
117121
const queryParams = new URLSearchParams();
118122

119123
if (options?.expiration) {
@@ -124,7 +128,7 @@ export class GroupClient {
124128
queryParams.set("authorization", options.authorization);
125129
}
126130

127-
const response = await TursoClient.request<{ jwt: string }>(
131+
const response = await TursoClient.request<GroupToken>(
128132
`organizations/${this.config.org}/groups/${groupName}/auth/tokens?${queryParams}`,
129133
this.config,
130134
{

src/index.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,33 @@
11
import "whatwg-fetch";
22

33
export { createClient } from "./client";
4+
5+
export type {
6+
ApiToken,
7+
ApiTokenWithJWT,
8+
RevokedApiToken,
9+
ApiTokenValidation,
10+
} from "./api-token";
11+
export type { TursoClientError } from "./client";
12+
export type { TursoConfig } from "./config";
13+
export type {
14+
Database,
15+
CreatedDatabase,
16+
DatabaseUsage,
17+
InstanceUsages,
18+
TotalUsage,
19+
DatabaseInstance,
20+
DeletedDatabase,
21+
DatabaseToken,
22+
} from "./database";
23+
export type { Group, ExtensionType, GroupToken } from "./group";
24+
export type { LocationKeys, Location, ClosestLocation } from "./location";
25+
export type {
26+
Organization,
27+
OrganizationMember,
28+
OrganizationInvite,
29+
Invoice,
30+
OrganizationMemberRole,
31+
OrganizationAddedMember,
32+
OrganizationRemovedMember,
33+
} from "./organization";

src/location.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@ export type Location = {
4040
[K in keyof LocationKeys]: { code: K; description: LocationKeys[K] };
4141
}[keyof LocationKeys];
4242

43+
export interface ClosestLocation {
44+
server: keyof LocationKeys;
45+
client: keyof LocationKeys;
46+
}
47+
4348
export class LocationClient {
4449
constructor(private config: TursoConfig) {}
4550

@@ -58,10 +63,7 @@ export class LocationClient {
5863
}));
5964
}
6065

61-
async closest(): Promise<{
62-
server: keyof LocationKeys;
63-
client: keyof LocationKeys;
64-
}> {
66+
async closest(): Promise<ClosestLocation> {
6567
return fetch("https://region.turso.io/").then((res) => res.json());
6668
}
6769
}

src/organization.ts

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,17 @@ export interface Invoice {
3737
invoice_pdf: string;
3838
}
3939

40+
export type OrganizationMemberRole = "admin" | "member";
41+
42+
export interface OrganizationAddedMember {
43+
member: string;
44+
role: OrganizationMemberRole;
45+
}
46+
47+
export interface OrganizationRemovedMember {
48+
member: string;
49+
}
50+
4051
export class OrganizationClient {
4152
constructor(private config: TursoConfig) {}
4253

@@ -80,7 +91,7 @@ export class OrganizationClient {
8091
async addMember(
8192
username: string,
8293
role?: "admin" | "member"
83-
): Promise<{ member: string; role: "admin" | "member" }> {
94+
): Promise<OrganizationAddedMember> {
8495
return TursoClient.request(
8596
`organizations/${this.config.org}/members/${username}`,
8697
this.config,
@@ -94,7 +105,7 @@ export class OrganizationClient {
94105
);
95106
}
96107

97-
async removeMember(username: string): Promise<{ member: string }> {
108+
async removeMember(username: string): Promise<OrganizationRemovedMember> {
98109
return TursoClient.request(
99110
`organizations/${this.config.org}/members/${username}`,
100111
this.config,
@@ -106,7 +117,7 @@ export class OrganizationClient {
106117

107118
async inviteUser(
108119
email: string,
109-
role?: "admin" | "member"
120+
role?: OrganizationMemberRole
110121
): Promise<OrganizationInvite> {
111122
const response = await TursoClient.request<{ invited: OrganizationInvite }>(
112123
`organizations/${this.config.org}/invites`,

0 commit comments

Comments
 (0)