-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathindex.ts
90 lines (79 loc) · 3.08 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
import Connection from "./connection/index"
import graphql, {IWeaviateClientGraphQL} from "./graphql/index";
import schema, {IWeaviateClientSchema} from "./schema/index";
import data, {IWeaviateClientData} from "./data/index";
import classifications, {IWeaviateClientClassifications} from "./classifications/index";
import batch, {IWeaviateClientBatch} from "./batch/index";
import misc, {IWeaviateClientMisc} from "./misc/index";
import c11y, {IWeaviateClientC11y} from "./c11y/index";
import {DbVersionProvider, DbVersionSupport} from "./utils/dbVersion";
import backup, {IWeaviateClientBackup} from "./backup/index";
import backupConsts from "./backup/consts";
import batchConsts from "./batch/consts";
import filtersConsts from "./filters/consts";
import cluster, {IWeaviateClientCluster} from "./cluster/index";
import clusterConsts from "./cluster/consts";
import replicationConsts from "./data/replication/consts";
import {AuthAccessTokenCredentials, AuthClientCredentials, AuthUserPasswordCredentials} from "./connection/auth";
import MetaGetter from "./misc/metaGetter";
import {Operator} from "./filters/consts";
export interface IConnectionParams {
authClientSecret?: AuthClientCredentials | AuthAccessTokenCredentials | AuthUserPasswordCredentials;
host: string
scheme: string
headers?: any
}
export interface IWeaviateClient {
graphql: IWeaviateClientGraphQL,
schema: IWeaviateClientSchema,
data: IWeaviateClientData,
classifications: IWeaviateClientClassifications,
batch: IWeaviateClientBatch,
misc: IWeaviateClientMisc,
c11y: IWeaviateClientC11y,
backup: IWeaviateClientBackup,
cluster: IWeaviateClientCluster
}
const app = {
client: function (params: IConnectionParams): IWeaviateClient {
// check if the URL is set
if (!params.host) throw new Error("Missing `host` parameter");
// check if the scheme is set
if (!params.scheme) throw new Error("Missing `scheme` parameter");
// check if headers are set
if (!params.headers) params.headers = {};
const conn = new Connection(params);
const dbVersionProvider = initDbVersionProvider(conn);
const dbVersionSupport = new DbVersionSupport(dbVersionProvider);
return {
graphql: graphql(conn),
schema: schema(conn),
data: data(conn, dbVersionSupport),
classifications: classifications(conn),
batch: batch(conn, dbVersionSupport),
misc: misc(conn, dbVersionProvider),
c11y: c11y(conn),
backup: backup(conn),
cluster: cluster(conn),
};
},
// constants
backup: backupConsts,
batch: batchConsts,
filters: filtersConsts,
cluster: clusterConsts,
replication: replicationConsts,
};
function initDbVersionProvider(conn: Connection) {
const metaGetter = new MetaGetter(conn);
const versionGetter = () => {
return metaGetter.do()
.then((result: any) => result.version)
.catch(() => Promise.resolve(''));
}
const dbVersionProvider = new DbVersionProvider(versionGetter);
dbVersionProvider.refresh();
return dbVersionProvider;
}
export default app
export { AuthUserPasswordCredentials, AuthAccessTokenCredentials, Operator };