-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathdbVersion.ts
81 lines (69 loc) · 3.38 KB
/
dbVersion.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
export class DbVersionSupport {
private dbVersionProvider: IDbVersionProvider
constructor(dbVersionProvider: IDbVersionProvider) {
this.dbVersionProvider = dbVersionProvider;
}
supportsClassNameNamespacedEndpointsPromise() {
return this.dbVersionProvider.getVersionPromise().then((version?: string) => ({
version,
supports: this.supportsClassNameNamespacedEndpoints(version),
warns: {
deprecatedNonClassNameNamespacedEndpointsForObjects: () => console.warn(`Usage of objects paths without className is deprecated in Weaviate ${version}. Please provide className parameter`),
deprecatedNonClassNameNamespacedEndpointsForReferences: () => console.warn(`Usage of references paths without className is deprecated in Weaviate ${version}. Please provide className parameter`),
deprecatedNonClassNameNamespacedEndpointsForBeacons: () => console.warn(`Usage of beacons paths without className is deprecated in Weaviate ${version}. Please provide className parameter`),
notSupportedClassNamespacedEndpointsForObjects: () => console.warn(`Usage of objects paths with className is not supported in Weaviate ${version}. className parameter is ignored`),
notSupportedClassNamespacedEndpointsForReferences: () => console.warn(`Usage of references paths with className is not supported in Weaviate ${version}. className parameter is ignored`),
notSupportedClassNamespacedEndpointsForBeacons: () => console.warn(`Usage of beacons paths with className is not supported in Weaviate ${version}. className parameter is ignored`),
notSupportedClassParameterInEndpointsForObjects: () => console.warn(`Usage of objects paths with class query parameter is not supported in Weaviate ${version}. class query parameter is ignored`),
}
}));
}
// >= 1.14
supportsClassNameNamespacedEndpoints(version?: string) {
if (typeof version === "string") {
const versionNumbers = version.split(".");
if (versionNumbers.length >= 2) {
const major = parseInt(versionNumbers[0]);
const minor = parseInt(versionNumbers[1]);
return (major == 1 && minor >= 14) || major >= 2;
}
}
return false;
}
}
const EMPTY_VERSION = "";
export interface IDbVersionProvider {
getVersionPromise(): Promise<string>
}
export class DbVersionProvider implements IDbVersionProvider{
private versionPromise?: Promise<string>;
private readonly emptyVersionPromise: Promise<string>;
private versionGetter: () => Promise<string>;
constructor(versionGetter: () => Promise<string>) {
this.versionGetter = versionGetter;
this.emptyVersionPromise = Promise.resolve(EMPTY_VERSION);
this.versionPromise = undefined;
}
getVersionPromise(): Promise<string> {
if (this.versionPromise) {
return this.versionPromise;
}
return this.versionGetter().then(version => this.assignPromise(version));
}
refresh(force = false): Promise<boolean> {
if (force || !this.versionPromise) {
this.versionPromise = undefined;
return this.versionGetter()
.then(version => this.assignPromise(version))
.then(() => Promise.resolve(true));
}
return Promise.resolve(false);
}
assignPromise(version: string): Promise<string> {
if (version === EMPTY_VERSION) {
return this.emptyVersionPromise;
}
this.versionPromise = Promise.resolve(version);
return this.versionPromise;
}
}