From b4e409979d94142ff75ac2ffaed3a66854d38ac1 Mon Sep 17 00:00:00 2001 From: Iheanyi Ekechukwu Date: Mon, 1 Aug 2022 14:18:23 -0500 Subject: [PATCH] Rename Credentials to Config. --- src/index.ts | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/src/index.ts b/src/index.ts index 72575fc..16ca586 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,6 +1,6 @@ import { utf8Encode } from './text.js' -export interface Credentials { +export interface Config { username: string password: string host: string @@ -55,10 +55,10 @@ export interface QueryResult { } export class Client { - credentials: Credentials + config: Config - constructor(credentials: Credentials) { - this.credentials = credentials + constructor(config: Config) { + this.config = config } async execute(query: string): Promise { @@ -66,23 +66,23 @@ export class Client { } connection(): Connection { - return new Connection(this.credentials) + return new Connection(this.config) } } -export function connect(credentials: Credentials): Connection { - return new Connection(credentials) +export function connect(config: Config): Connection { + return new Connection(config) } export class Connection { - private credentials: Credentials + private config: Config private session: QuerySession | null - constructor(credentials: Credentials) { + constructor(config: Config) { if (typeof fetch !== 'undefined') { - credentials = { fetch, ...credentials } + config = { fetch, ...config } } - this.credentials = credentials + this.config = config this.session = null } @@ -96,15 +96,15 @@ export class Connection { } private async createSession(): Promise { - const url = new URL('/psdb.v1alpha1.Database/CreateSession', `https://${this.credentials.host}`) + const url = new URL('/psdb.v1alpha1.Database/CreateSession', `https://${this.config.host}`) const { session } = await this.postJSON(url) this.session = session return session } private async postJSON(url: string | URL, body = {}): Promise { - const auth = btoa(`${this.credentials.username}:${this.credentials.password}`) - const response = await this.credentials.fetch(url.toString(), { + const auth = btoa(`${this.config.username}:${this.config.password}`) + const response = await this.config.fetch(url.toString(), { method: 'POST', body: JSON.stringify(body), headers: { @@ -123,7 +123,7 @@ export class Connection { async execute(query: string): Promise { const startTime = Date.now() - const url = new URL('/psdb.v1alpha1.Database/Execute', `https://${this.credentials.host}`) + const url = new URL('/psdb.v1alpha1.Database/Execute', `https://${this.config.host}`) const saved = await this.postJSON(url, { query: query, session: this.session