Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ module.exports = {
'no-useless-call': 'error',
'no-useless-computed-key': 'error',
'no-useless-concat': 'error',
'no-useless-constructor': 'warn',
'no-useless-constructor': 'off',
'no-useless-escape': 'off',
'no-useless-rename': 'error',
'no-useless-return': 'error',
Expand Down
3 changes: 2 additions & 1 deletion .prettierrc
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
"arrowParens": "always",
"trailingComma": "es5",
"bracketSpacing": true,
"singleQuote": true
"singleQuote": true,
"printWidth": 110
}
8 changes: 3 additions & 5 deletions examples/embedded/index.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
import weaviate from 'weaviate-ts-client';
import weaviate, { EmbeddedOptions } from 'weaviate-ts-client';

if (process.platform !== 'linux') {
throw new Error(
'EmbeddedDB only supports Linux at the moment. Try me in a Docker container!'
);
throw new Error('EmbeddedDB only supports Linux at the moment. Try me in a Docker container!');
}

const client = weaviate.client({
scheme: 'http',
host: 'localhost:9898',
embedded: new weaviate.EmbeddedOptions({
embedded: new EmbeddedOptions({
port: 9898,
}),
});
Expand Down
6 changes: 0 additions & 6 deletions examples/javascript/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,6 @@ console.log(

console.log(JSON.stringify(new weaviate.ApiKey('abcd1234')));

console.log(weaviate.backup.Backend.GCS);
console.log(weaviate.batch.DeleteOutput.MINIMAL);
console.log(weaviate.cluster.NodeStatus.HEALTHY);
console.log(weaviate.filters.Operator.AND);
console.log(weaviate.replication.ConsistencyLevel.QUORUM);

client.misc
.metaGetter()
.do()
Expand Down
21 changes: 10 additions & 11 deletions examples/typescript/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import weaviate from 'weaviate-ts-client';
import weaviate, {
AuthClientCredentials,
AuthUserPasswordCredentials,
ApiKey,
AuthAccessTokenCredentials,
} from 'weaviate-ts-client';

const client = weaviate.client({
scheme: 'http',
Expand All @@ -7,7 +12,7 @@ const client = weaviate.client({

console.log(
JSON.stringify(
new weaviate.AuthAccessTokenCredentials({
new AuthAccessTokenCredentials({
accessToken: 'token123',
expiresIn: 123,
})
Expand All @@ -16,7 +21,7 @@ console.log(

console.log(
JSON.stringify(
new weaviate.AuthUserPasswordCredentials({
new AuthUserPasswordCredentials({
username: 'user123',
password: 'password',
})
Expand All @@ -25,19 +30,13 @@ console.log(

console.log(
JSON.stringify(
new weaviate.AuthClientCredentials({
new AuthClientCredentials({
clientSecret: 'secret123',
})
)
);

console.log(JSON.stringify(new weaviate.ApiKey('abcd1234')));

console.log(weaviate.backup.Backend.GCS);
console.log(weaviate.batch.DeleteOutput.MINIMAL);
console.log(weaviate.cluster.NodeStatus.HEALTHY);
console.log(weaviate.filters.Operator.AND);
console.log(weaviate.replication.ConsistencyLevel.QUORUM);
console.log(JSON.stringify(new ApiKey('abcd1234')));

client.misc
.metaGetter()
Expand Down
29 changes: 13 additions & 16 deletions src/backup/backupCreateStatusGetter.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
import Connection from '../connection';
import { validateBackupId, validateBackend } from './validation';
import { CommandBase } from '../validation/commandBase';
import { BackupCreateStatusResponse } from '../openapi/types';
import { Backend } from '.';

export default class BackupCreateStatusGetter extends CommandBase {
private backend?: string;
private backend?: Backend;
private backupId?: string;

constructor(client: Connection) {
super(client);
}

withBackend(backend: string) {
withBackend(backend: Backend) {
this.backend = backend;
return this;
}
Expand All @@ -20,24 +22,19 @@ export default class BackupCreateStatusGetter extends CommandBase {
return this;
}

validate() {
this.addErrors([
...validateBackend(this.backend),
...validateBackupId(this.backupId),
]);
}
validate = (): void => {
this.addErrors([...validateBackend(this.backend), ...validateBackupId(this.backupId)]);
};

do() {
do = (): Promise<BackupCreateStatusResponse> => {
this.validate();
if (this.errors.length > 0) {
return Promise.reject(
new Error('invalid usage: ' + this.errors.join(', '))
);
return Promise.reject(new Error('invalid usage: ' + this.errors.join(', ')));
}
return this.client.get(this._path());
}
return this.client.get(this._path()) as Promise<BackupCreateStatusResponse>;
};

_path() {
private _path = (): string => {
return `/backups/${this.backend}/${this.backupId}`;
}
};
}
57 changes: 27 additions & 30 deletions src/backup/backupCreator.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { CreateStatus } from './consts';
import {
validateBackend,
validateBackupId,
Expand All @@ -8,12 +7,14 @@ import {
import BackupCreateStatusGetter from './backupCreateStatusGetter';
import Connection from '../connection';
import { CommandBase } from '../validation/commandBase';
import { BackupCreateRequest, BackupCreateResponse, BackupCreateStatusResponse } from '../openapi/types';
import { Backend } from '.';

const WAIT_INTERVAL = 1000;

export default class BackupCreator extends CommandBase {
private backend?: string;
private backupId?: string;
private backend!: Backend;
private backupId!: string;
private excludeClassNames?: string[];
private includeClassNames?: string[];
private statusGetter: BackupCreateStatusGetter;
Expand Down Expand Up @@ -42,7 +43,7 @@ export default class BackupCreator extends CommandBase {
return this;
}

withBackend(backend: string) {
withBackend(backend: Backend) {
this.backend = backend;
return this;
}
Expand All @@ -57,56 +58,49 @@ export default class BackupCreator extends CommandBase {
return this;
}

validate() {
validate = (): void => {
this.addErrors([
...validateIncludeClassNames(this.includeClassNames),
...validateExcludeClassNames(this.excludeClassNames),
...validateBackend(this.backend),
...validateBackupId(this.backupId),
]);
}
};

do() {
do = (): Promise<BackupCreateResponse> => {
this.validate();
if (this.errors.length > 0) {
return Promise.reject(
new Error('invalid usage: ' + this.errors.join(', '))
);
return Promise.reject(new Error('invalid usage: ' + this.errors.join(', ')));
}

const payload = {
id: this.backupId,
config: {},
include: this.includeClassNames,
exclude: this.excludeClassNames,
};
} as BackupCreateRequest;

if (this.waitForCompletion) {
return this._createAndWaitForCompletion(payload);
}
return this._create(payload);
}
};

_create(payload: any) {
return this.client.post(this._path(), payload);
}
_create = (payload: BackupCreateRequest): Promise<BackupCreateResponse> => {
return this.client.post(this._path(), payload) as Promise<BackupCreateResponse>;
};

_createAndWaitForCompletion(payload: any) {
return new Promise((resolve, reject) => {
_createAndWaitForCompletion = (payload: BackupCreateRequest): Promise<BackupCreateResponse> => {
return new Promise<BackupCreateResponse>((resolve, reject) => {
this._create(payload)
.then((createResponse: any) => {
this.statusGetter
.withBackend(this.backend!)
.withBackupId(this.backupId!);
this.statusGetter.withBackend(this.backend).withBackupId(this.backupId);

const loop = () => {
this.statusGetter
.do()
.then((createStatusResponse: any) => {
if (
createStatusResponse.status == CreateStatus.SUCCESS ||
createStatusResponse.status == CreateStatus.FAILED
) {
if (createStatusResponse.status == 'SUCCESS' || createStatusResponse.status == 'FAILED') {
resolve(this._merge(createStatusResponse, createResponse));
} else {
setTimeout(loop, WAIT_INTERVAL);
Expand All @@ -119,14 +113,17 @@ export default class BackupCreator extends CommandBase {
})
.catch(reject);
});
}
};

_path() {
private _path = (): string => {
return `/backups/${this.backend}`;
}
};

_merge(createStatusResponse: any, createResponse: any) {
const merged: any = {};
_merge = (
createStatusResponse: BackupCreateStatusResponse,
createResponse: BackupCreateResponse
): BackupCreateResponse => {
const merged: BackupCreateResponse = {};
if ('id' in createStatusResponse) {
merged.id = createStatusResponse.id;
}
Expand All @@ -146,5 +143,5 @@ export default class BackupCreator extends CommandBase {
merged.classes = createResponse.classes;
}
return merged;
}
};
}
22 changes: 11 additions & 11 deletions src/backup/backupGetter.ts
Original file line number Diff line number Diff line change
@@ -1,35 +1,35 @@
import { validateBackend } from './validation';
import Connection from '../connection';
import { CommandBase } from '../validation/commandBase';
import { BackupCreateResponse } from '../openapi/types';
import { Backend } from '.';

export default class BackupGetter extends CommandBase {
private backend?: string;
private backend?: Backend;

constructor(client: Connection) {
super(client);
}

withBackend(backend: string) {
withBackend(backend: Backend) {
this.backend = backend;
return this;
}

validate() {
validate = (): void => {
this.addErrors(validateBackend(this.backend));
}
};

do() {
do = (): Promise<BackupCreateResponse[]> => {
this.validate();
if (this.errors.length > 0) {
return Promise.reject(
new Error('invalid usage: ' + this.errors.join(', '))
);
return Promise.reject(new Error('invalid usage: ' + this.errors.join(', ')));
}

return this.client.get(this._path());
}
};

_path() {
private _path = (): string => {
return `/backups/${this.backend}`;
}
};
}
27 changes: 12 additions & 15 deletions src/backup/backupRestoreStatusGetter.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
import { validateBackupId, validateBackend } from './validation';
import Connection from '../connection';
import { CommandBase } from '../validation/commandBase';
import { BackupRestoreStatusResponse } from '../openapi/types';
import { Backend } from '.';

export default class BackupRestoreStatusGetter extends CommandBase {
private backend?: string;
private backend?: Backend;
private backupId?: string;

constructor(client: Connection) {
super(client);
}

withBackend(backend: string) {
withBackend(backend: Backend) {
this.backend = backend;
return this;
}
Expand All @@ -20,25 +22,20 @@ export default class BackupRestoreStatusGetter extends CommandBase {
return this;
}

validate() {
this.addErrors([
...validateBackend(this.backend),
...validateBackupId(this.backupId),
]);
}
validate = (): void => {
this.addErrors([...validateBackend(this.backend), ...validateBackupId(this.backupId)]);
};

do() {
do = (): Promise<BackupRestoreStatusResponse> => {
this.validate();
if (this.errors.length > 0) {
return Promise.reject(
new Error('invalid usage: ' + this.errors.join(', '))
);
return Promise.reject(new Error('invalid usage: ' + this.errors.join(', ')));
}

return this.client.get(this._path());
}
};

_path() {
private _path = (): string => {
return `/backups/${this.backend}/${this.backupId}/restore`;
}
};
}
Loading