/** * API token used to authenticate requests. Either a static string or a factory * that resolves one on demand (e.g. to refresh short-lived tokens). */ type TursoToken = string | (() => Promise); interface TursoConfig { /** * Organization slug. Provide either `org` or `orgId`. */ org?: string; /** * Organization id. Can be provided instead of the organization slug (`org`). * Takes precedence over `org` when both are set. * * Requires v3 of the Turso API. */ orgId?: string; token: TursoToken; baseUrl?: string; } interface ApiToken { id: string; name: string; } interface ApiTokenWithJWT extends ApiToken { token: string; } interface RevokedApiToken { token: string; } interface ApiTokenValidation { valid: boolean; expiry: number; } declare class ApiTokenClient { private config; constructor(config: TursoConfig); list(): Promise; create(name: string): Promise; revoke(name: string): Promise; validate(token: string): Promise; } interface Organization { name: string; slug: string; type: "personal" | "team"; overages: boolean; blocked_reads: boolean; blocked_writes: boolean; } interface OrganizationMember { role: "owner" | "admin" | "member"; username: string; email: string; } interface OrganizationInvite { id: number; email: string; role: "admin" | "member" | "viewer"; token: string; created_at: string; } interface OrganizationInviteCreated { email: string; role: "admin" | "member" | "viewer"; organization: string; token: string; } interface Invoice { invoice_number: string; amount_due: string; due_date: string; paid_at: string; payment_failed_at: string; invoice_pdf: string; } type OrganizationMemberRole = "admin" | "member"; interface OrganizationAddedMember { member: string; role: OrganizationMemberRole; } interface OrganizationRemovedMember { member: string; } declare class OrganizationClient { private config; constructor(config: TursoConfig); private get org(); list(): Promise; update(options: { overages: boolean; }): Promise; delete(): Promise; members(): Promise; addMember(username: string, role?: "admin" | "member"): Promise; removeMember(username: string): Promise; listInvites(): Promise; inviteUser(email: string, role?: OrganizationMemberRole): Promise; deleteInvite(email: string): Promise; invoices(): Promise; } type LocationKeys = { ams: string; arn: string; bog: string; bos: string; cdg: string; den: string; dfw: string; ewr: string; fra: string; gdl: string; gig: string; gru: string; hkg: string; iad: string; jnb: string; lax: string; lhr: string; mad: string; mia: string; nrt: string; ord: string; otp: string; qro: string; scl: string; sea: string; sin: string; sjc: string; syd: string; waw: string; yul: string; yyz: string; [key: string]: string; }; type Location = { [K in keyof LocationKeys]: { code: K; description: LocationKeys[K]; }; }[keyof LocationKeys]; interface ClosestLocation { server: keyof LocationKeys; client: keyof LocationKeys; } declare class LocationClient { private config; constructor(config: TursoConfig); list(): Promise; closest(): Promise; } interface Database { name: string; id: string; hostname: string; regions?: Array; primaryRegion?: keyof LocationKeys; type: string; version: string; group?: string; sleeping: boolean; archived: boolean; allow_attach: boolean; block_reads: boolean; block_writes: boolean; schema?: string; is_schema: boolean; } interface CreatedDatabase { name: string; id: string; hostname: string; } interface DatabaseInstanceUsageDetail { rows_read: number; rows_written: number; storage_bytes: number; } interface DatabaseInstanceUsage { uuid: string; usage: DatabaseInstanceUsageDetail; } interface DatabaseUsage { uuid: string; instances: DatabaseInstanceUsage[]; usage: DatabaseInstanceUsageDetail; } interface InstanceUsages { [instanceUuid: string]: DatabaseInstanceUsageDetail; } interface TotalUsage { rows_read: number; rows_written: number; storage_bytes: number; } interface DatabaseInstance { uuid: string; name: keyof LocationKeys; type: "primary" | "replica"; region: keyof LocationKeys; hostname: string; } interface DeletedDatabase { database: string; } interface DatabaseToken { jwt: string; } type EncryptionCipher = "aes256gcm" | "aes128gcm" | "chacha20poly1305" | "aegis128l" | "aegis128x2" | "aegis128x4" | "aegis256" | "aegis256x2" | "aegis256x4"; interface RemoteEncryption { /** * Base64-encoded encryption key. Key size depends on the cipher: 32 bytes * for aes256gcm, chacha20poly1305 and aegis256 variants; 16 bytes for * aes128gcm and aegis128l variants. */ encryption_key: string; encryption_cipher: EncryptionCipher; } type MultiDBSchemaOptions = { is_schema: boolean; schema?: never; } | { is_schema?: never; schema: string; } | {}; /** * Methods that operate on a single database take a `dbName` positional * argument that identifies the database in the request path. On v1/v2 of the * Turso API this is the database name; on v3 it is the database id. */ declare class DatabaseClient { private config; constructor(config: TursoConfig); private get org(); list(options?: { schema?: string; group?: string; type?: "schema"; }): Promise; get(dbName: string): Promise; create(dbName: string, options?: { image?: "latest" | "canary"; /** Name of the group where the database should be created. */ group?: string; /** * Id of the group where the database should be created. Mutually * exclusive with `group`. Requires v3 of the Turso API. */ groupId?: string; seed?: { type: "database" | "dump"; name?: string; url?: string; timestamp?: string | Date; }; size_limit?: string; remote_encryption?: RemoteEncryption; /** When true, provisions the database using TursoDB. */ useTursoDb?: boolean; } & MultiDBSchemaOptions): Promise; updateVersion(dbName: string): Promise; delete(dbName: string): Promise; listInstances(dbName: string): Promise; getInstance(dbName: string, instanceName: keyof LocationKeys): Promise; createToken(dbName: string, options?: { expiration?: string; authorization?: "read-only" | "full-access"; permissions?: { read_attach: { databases: Database["name"][]; }; }; }): Promise; rotateTokens(dbName: string): Promise; usage(dbName: string, options?: { from?: Date | string; to?: Date | string; }): Promise; private formatDateParameter; private formatResponse; private formatCreateResponse; } interface Group { locations: Array; name: string; primary: keyof LocationKeys; } type ExtensionType = "vector" | "vec" | "crypto" | "fuzzy" | "math" | "stats" | "text" | "unicode" | "uuid" | "regexp"; interface GroupToken { jwt: string; } declare class GroupClient { private config; constructor(config: TursoConfig); private get org(); list(): Promise; get(name: string): Promise; create(name: string, location: keyof LocationKeys, options?: { extensions?: Array | "all"; }): Promise; delete(name: string): Promise; /** * @deprecated Turso Cloud deprecated edge replicas */ addLocation(groupName: string, location: keyof LocationKeys): Promise; /** * @deprecated Turso Cloud deprecated edge replicas */ removeLocation(groupName: string, location: keyof LocationKeys): Promise; /** * Creates a token for a group * @param groupName The name of the group * @param options Token creation options * @param options.expiration Token expiration * @param options.authorization Token authorization level * @param options.permissions - @deprecated This parameter is deprecated and will be removed in a future version */ createToken(groupName: string, options?: { expiration?: string; authorization?: "read-only" | "full-access"; permissions?: { read_attach: { databases: Database["name"][]; }; }; }): Promise; rotateTokens(groupName: string): Promise; } interface AdditionalInfo { status?: number; } declare class TursoClientError extends Error { status?: number; constructor(message: string, additionalInfo?: AdditionalInfo); } declare class TursoClient { private config; apiTokens: ApiTokenClient; organizations: OrganizationClient; locations: LocationClient; groups: GroupClient; databases: DatabaseClient; constructor(config: TursoConfig); static request(url: string, config: TursoConfig, options?: RequestInit): Promise; } declare function createClient(config: TursoConfig): TursoClient; export { type ApiToken, type ApiTokenValidation, type ApiTokenWithJWT, type ClosestLocation, type CreatedDatabase, type Database, type DatabaseInstance, type DatabaseToken, type DatabaseUsage, type DeletedDatabase, type ExtensionType, type Group, type GroupToken, type InstanceUsages, type Invoice, type Location, type LocationKeys, type Organization, type OrganizationAddedMember, type OrganizationInvite, type OrganizationInviteCreated, type OrganizationMember, type OrganizationMemberRole, type OrganizationRemovedMember, type RevokedApiToken, type TotalUsage, TursoClientError, type TursoConfig, type TursoToken, createClient };