Skip to content

Commit 13660f8

Browse files
rename interfaces to be more idiomatic (#12)
1 parent 9788a66 commit 13660f8

File tree

22 files changed

+104
-113
lines changed

22 files changed

+104
-113
lines changed

src/backup/index.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,21 @@ import BackupRestorer from './backupRestorer';
44
import BackupRestoreStatusGetter from './backupRestoreStatusGetter';
55
import Connection from '../connection';
66

7-
// import BackupGetter from "./backupGetter";
8-
9-
export interface IWeaviateClientBackup {
7+
export interface Backup {
108
creator: () => BackupCreator;
119
createStatusGetter: () => BackupCreateStatusGetter;
1210
restorer: () => BackupRestorer;
1311
restoreStatusGetter: () => BackupRestoreStatusGetter;
14-
// getter: () => BackupGetter
1512
}
1613

17-
const backup = (client: Connection): IWeaviateClientBackup => {
14+
const backup = (client: Connection): Backup => {
1815
return {
1916
creator: () =>
2017
new BackupCreator(client, new BackupCreateStatusGetter(client)),
2118
createStatusGetter: () => new BackupCreateStatusGetter(client),
2219
restorer: () =>
2320
new BackupRestorer(client, new BackupRestoreStatusGetter(client)),
2421
restoreStatusGetter: () => new BackupRestoreStatusGetter(client),
25-
// getter: () => new BackupGetter(client),
2622
};
2723
};
2824

src/backup/journey.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import weaviate, { IWeaviateClient } from '../index';
1+
import weaviate, { WeaviateClient } from '../index';
22

33
const {
44
createTestFoodSchemaAndData,
@@ -886,16 +886,16 @@ describe('fail restoring backup for both include and exclude classes', () => {
886886
// it("cleans up", () => cleanupTestFood(client));
887887
// });
888888

889-
function assertThatAllPizzasExist(client: IWeaviateClient) {
889+
function assertThatAllPizzasExist(client: WeaviateClient) {
890890
return assertThatAllFoodObjectsExist(client, 'Pizza', 4);
891891
}
892892

893-
function assertThatAllSoupsExist(client: IWeaviateClient) {
893+
function assertThatAllSoupsExist(client: WeaviateClient) {
894894
return assertThatAllFoodObjectsExist(client, 'Soup', 2);
895895
}
896896

897897
function assertThatAllFoodObjectsExist(
898-
client: IWeaviateClient,
898+
client: WeaviateClient,
899899
className: string,
900900
number: number
901901
) {

src/batch/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { BeaconPath } from '../utils/beaconPath';
66
import { DbVersionSupport } from '../utils/dbVersion';
77
import Connection from '../connection';
88

9-
export interface IWeaviateClientBatch {
9+
export interface Batch {
1010
objectsBatcher: () => ObjectsBatcher;
1111
objectsBatchDeleter: () => ObjectsBatchDeleter;
1212
referencesBatcher: () => ReferencesBatcher;
@@ -16,7 +16,7 @@ export interface IWeaviateClientBatch {
1616
const batch = (
1717
client: Connection,
1818
dbVersionSupport: DbVersionSupport
19-
): IWeaviateClientBatch => {
19+
): Batch => {
2020
const beaconPath = new BeaconPath(dbVersionSupport);
2121

2222
return {

src/batch/journey.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import weaviate, { IWeaviateClient } from '../index';
1+
import weaviate, { WeaviateClient } from '../index';
22

33
const thingClassName = 'BatchJourneyTestThing';
44
const otherThingClassName = 'BatchJourneyTestOtherThing';
@@ -530,7 +530,7 @@ describe('batch deleting', () => {
530530
it('tears down and cleans up', () => cleanup(client));
531531
});
532532

533-
const setup = async (client: IWeaviateClient) => {
533+
const setup = async (client: WeaviateClient) => {
534534
// first import the classes
535535
await Promise.all([
536536
client.schema
@@ -572,11 +572,11 @@ const setup = async (client: IWeaviateClient) => {
572572
.do();
573573
};
574574

575-
const setupData = (client: IWeaviateClient) => {
575+
const setupData = (client: WeaviateClient) => {
576576
return client.batch.objectsBatcher().withObjects(someObjects).do();
577577
};
578578

579-
const cleanup = (client: IWeaviateClient) =>
579+
const cleanup = (client: WeaviateClient) =>
580580
Promise.all([
581581
client.schema.classDeleter().withClassName(thingClassName).do(),
582582
client.schema.classDeleter().withClassName(otherThingClassName).do(),

src/c11y/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@ import ExtensionCreator from './extensionCreator';
22
import ConceptsGetter from './conceptsGetter';
33
import Connection from '../connection';
44

5-
export interface IWeaviateClientC11y {
5+
export interface C11y {
66
conceptsGetter: () => ConceptsGetter;
77
extensionCreator: () => ExtensionCreator;
88
}
99

10-
const c11y = (client: Connection): IWeaviateClientC11y => {
10+
const c11y = (client: Connection): C11y => {
1111
return {
1212
conceptsGetter: () => new ConceptsGetter(client),
1313
extensionCreator: () => new ExtensionCreator(client),

src/classifications/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@ import Scheduler from './scheduler';
22
import Getter from './getter';
33
import Connection from '../connection';
44

5-
export interface IWeaviateClientClassifications {
5+
export interface Classifications {
66
scheduler: () => Scheduler;
77
getter: () => Getter;
88
}
99

10-
const data = (client: Connection): IWeaviateClientClassifications => {
10+
const data = (client: Connection): Classifications => {
1111
return {
1212
scheduler: () => new Scheduler(client),
1313
getter: () => new Getter(client),

src/classifications/knn.journey.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import weaviate, { IWeaviateClient } from '../index';
1+
import weaviate, { WeaviateClient } from '../index';
22
import Connection from '../connection';
33

44
const targetDessertId = 'cd54852a-209d-423b-bf1c-884468215237';
@@ -205,7 +205,7 @@ describe('a classification journey', () => {
205205
});
206206
});
207207

208-
const setup = async (client: IWeaviateClient) => {
208+
const setup = async (client: WeaviateClient) => {
209209
let targetClass = {
210210
class: 'ClassificationJourneyTarget',
211211
properties: [
@@ -286,7 +286,7 @@ const setup = async (client: IWeaviateClient) => {
286286
.do();
287287
};
288288

289-
const cleanup = (client: IWeaviateClient) => {
289+
const cleanup = (client: WeaviateClient) => {
290290
return Promise.all([
291291
client.schema
292292
.classDeleter()

src/cluster/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import NodesStatusGetter from './nodesStatusGetter';
22
import Connection from '../connection';
33

4-
export interface IWeaviateClientCluster {
4+
export interface Cluster {
55
nodesStatusGetter: () => NodesStatusGetter;
66
}
77

8-
const cluster = (client: Connection): IWeaviateClientCluster => {
8+
const cluster = (client: Connection): Cluster => {
99
return {
1010
nodesStatusGetter: () => new NodesStatusGetter(client),
1111
};

src/connection/auth.ts

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
1-
import { IHttpClient } from './httpClient';
1+
import { HttpClient } from './httpClient';
22

3-
interface IAuthenticatorResult {
3+
interface AuthenticatorResult {
44
accessToken: string;
55
expiresAt: number;
66
refreshToken: string;
77
}
88

9-
interface IAuthenticator {
10-
refresh: () => Promise<IAuthenticatorResult>;
9+
interface OIDCAuthFlow {
10+
refresh: () => Promise<AuthenticatorResult>;
1111
}
1212

1313
export class Authenticator {
14-
private readonly http: IHttpClient;
14+
private readonly http: HttpClient;
1515
private readonly creds: any;
1616
private accessToken: string;
1717
private refreshToken?: string;
1818
private expiresAt: number;
1919
private refreshRunning: boolean;
2020

21-
constructor(http: IHttpClient, creds: any) {
21+
constructor(http: HttpClient, creds: any) {
2222
this.http = http;
2323
this.creds = creds;
2424
this.accessToken = '';
@@ -38,7 +38,7 @@ export class Authenticator {
3838
refresh = async (localConfig: any) => {
3939
const config = await this.getOpenidConfig(localConfig);
4040

41-
let authenticator: IAuthenticator;
41+
let authenticator: OIDCAuthFlow;
4242
switch (this.creds.constructor) {
4343
case AuthUserPasswordCredentials:
4444
authenticator = new UserPasswordAuthenticator(
@@ -107,7 +107,7 @@ export class Authenticator {
107107
};
108108
}
109109

110-
export interface IAuthUserPasswordCredentials {
110+
export interface UserPasswordCredentialsInput {
111111
username: string;
112112
password?: string;
113113
scopes?: any[];
@@ -117,20 +117,20 @@ export class AuthUserPasswordCredentials {
117117
private username: string;
118118
private password?: string;
119119
private scopes?: any[];
120-
constructor(creds: IAuthUserPasswordCredentials) {
120+
constructor(creds: UserPasswordCredentialsInput) {
121121
this.username = creds.username;
122122
this.password = creds.password;
123123
this.scopes = creds.scopes;
124124
}
125125
}
126126

127-
interface IRequestAccessTokenResponse {
127+
interface RequestAccessTokenResponse {
128128
access_token: string;
129129
expires_in: number;
130130
refresh_token: string;
131131
}
132132

133-
class UserPasswordAuthenticator implements IAuthenticator {
133+
class UserPasswordAuthenticator implements OIDCAuthFlow {
134134
private creds: any;
135135
private http: any;
136136
private openidConfig: any;
@@ -146,7 +146,7 @@ class UserPasswordAuthenticator implements IAuthenticator {
146146
refresh = () => {
147147
this.validateOpenidConfig();
148148
return this.requestAccessToken()
149-
.then((tokenResp: IRequestAccessTokenResponse) => {
149+
.then((tokenResp: RequestAccessTokenResponse) => {
150150
return {
151151
accessToken: tokenResp.access_token,
152152
expiresAt: calcExpirationEpoch(tokenResp.expires_in),
@@ -194,7 +194,7 @@ class UserPasswordAuthenticator implements IAuthenticator {
194194
};
195195
}
196196

197-
export interface IAuthAccessTokenCredentials {
197+
export interface AccessTokenCredentialsInput {
198198
accessToken: string;
199199
expiresIn: number;
200200
refreshToken?: string;
@@ -205,14 +205,14 @@ export class AuthAccessTokenCredentials {
205205
public readonly expiresAt: number;
206206
public readonly refreshToken?: string;
207207

208-
constructor(creds: IAuthAccessTokenCredentials) {
208+
constructor(creds: AccessTokenCredentialsInput) {
209209
this.validate(creds);
210210
this.accessToken = creds.accessToken;
211211
this.expiresAt = calcExpirationEpoch(creds.expiresIn);
212212
this.refreshToken = creds.refreshToken;
213213
}
214214

215-
validate = (creds: IAuthAccessTokenCredentials) => {
215+
validate = (creds: AccessTokenCredentialsInput) => {
216216
if (creds.expiresIn === undefined) {
217217
throw new Error('AuthAccessTokenCredentials: expiresIn is required');
218218
}
@@ -222,7 +222,7 @@ export class AuthAccessTokenCredentials {
222222
};
223223
}
224224

225-
class AccessTokenAuthenticator implements IAuthenticator {
225+
class AccessTokenAuthenticator implements OIDCAuthFlow {
226226
private creds: any;
227227
private http: any;
228228
private openidConfig: any;
@@ -247,7 +247,7 @@ class AccessTokenAuthenticator implements IAuthenticator {
247247
}
248248
this.validateOpenidConfig();
249249
return this.requestAccessToken()
250-
.then((tokenResp: IRequestAccessTokenResponse) => {
250+
.then((tokenResp: RequestAccessTokenResponse) => {
251251
return {
252252
accessToken: tokenResp.access_token,
253253
expiresAt: calcExpirationEpoch(tokenResp.expires_in),
@@ -284,7 +284,7 @@ class AccessTokenAuthenticator implements IAuthenticator {
284284
};
285285
}
286286

287-
export interface IAuthClientCredentials {
287+
export interface ClientCredentialsInput {
288288
clientSecret: string;
289289
scopes?: any[];
290290
}
@@ -293,13 +293,13 @@ export class AuthClientCredentials {
293293
private clientSecret: any;
294294
private scopes?: any[];
295295

296-
constructor(creds: IAuthClientCredentials) {
296+
constructor(creds: ClientCredentialsInput) {
297297
this.clientSecret = creds.clientSecret;
298298
this.scopes = creds.scopes;
299299
}
300300
}
301301

302-
class ClientCredentialsAuthenticator implements IAuthenticator {
302+
class ClientCredentialsAuthenticator implements OIDCAuthFlow {
303303
private creds: any;
304304
private http: any;
305305
private openidConfig: any;
@@ -316,7 +316,7 @@ class ClientCredentialsAuthenticator implements IAuthenticator {
316316
refresh = () => {
317317
this.validateOpenidConfig();
318318
return this.requestAccessToken()
319-
.then((tokenResp: IRequestAccessTokenResponse) => {
319+
.then((tokenResp: RequestAccessTokenResponse) => {
320320
return {
321321
accessToken: tokenResp.access_token,
322322
expiresAt: calcExpirationEpoch(tokenResp.expires_in),

src/connection/gqlClient.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
1-
import { GraphQLClient } from 'graphql-request';
2-
import { IConnectionParams } from '../index';
1+
import { GraphQLClient as Client } from 'graphql-request';
2+
import { ConnectionParams } from '../index';
33

44
export type TQuery = any;
5-
export interface IGraphQLClient {
5+
export interface GraphQLClient {
66
query: (query: TQuery, headers?: HeadersInit) => Promise<{ data: any }>;
77
}
88

9-
export const gqlClient = (config: IConnectionParams): IGraphQLClient => {
9+
export const gqlClient = (config: ConnectionParams): GraphQLClient => {
1010
const scheme = config.scheme;
1111
const host = config.host;
1212
const defaultHeaders = config.headers;
1313
return {
1414
// for backward compatibility with replaced graphql-client lib,
1515
// results are wrapped into { data: data }
1616
query: (query: TQuery, headers?: HeadersInit) => {
17-
return new GraphQLClient(`${scheme}://${host}/v1/graphql`, {
17+
return new Client(`${scheme}://${host}/v1/graphql`, {
1818
headers: {
1919
...defaultHeaders,
2020
...headers,

0 commit comments

Comments
 (0)