Skip to content

Commit 29ea08d

Browse files
cnadeauChristian Nadeauparkerduckworth
authored
Typescript migration (#121)
Co-authored-by: Christian Nadeau <[email protected]> Co-authored-by: Parker Duckworth <[email protected]>
1 parent 8425b95 commit 29ea08d

File tree

124 files changed

+7096
-11555
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

124 files changed

+7096
-11555
lines changed

.github/workflows/tests.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515
- uses: actions/checkout@v3
1616
- uses: actions/setup-node@v3
1717
with:
18-
node-version: '16.x'
18+
node-version: '18.x'
1919
- name: "Install dependencies"
2020
run: |
2121
npm install
@@ -47,7 +47,7 @@ jobs:
4747
# Setup .npmrc file to publish to npm
4848
- uses: actions/setup-node@v3
4949
with:
50-
node-version: '16.x'
50+
node-version: '18.x'
5151
registry-url: 'https://registry.npmjs.org'
5252
- run: npm ci && npm run build
5353
- run: npm publish

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
.DS_Store
2+
dist/
3+
coverage/
24
node_modules/
35
config.yaml
46
lib.js
57
weaviate-data/
68
.vscode/
79
.idea/
10+
*.tgz

.npmignore

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
.github/
2+
ci/
3+
coverage/
4+
test/
5+
**/*.test.js
6+
**/*.test.ts
7+
.babelrc
8+
.editorconfig
9+
CODE_OF_CONDUCT.md
10+
CONTRIBUTE.md
11+
build.js
12+
*/**/*.test.js

backup/backupCreateStatusGetter.js renamed to backup/backupCreateStatusGetter.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,30 @@
1+
import Connection from '../connection'
12
import { validateBackupId, validateBackend } from "./validation";
3+
import {CommandBase} from "../validation/commandBase";
24

3-
export default class BackupCreateStatusGetter {
5+
export default class BackupCreateStatusGetter extends CommandBase {
6+
private backend?: string;
7+
private backupId?: string;
48

5-
backend;
6-
backupId;
7-
errors;
8-
9-
constructor(client) {
10-
this.client = client;
9+
constructor(client: Connection) {
10+
super(client)
1111
}
1212

13-
withBackend(backend) {
13+
withBackend(backend: string) {
1414
this.backend = backend;
1515
return this;
1616
}
1717

18-
withBackupId(backupId) {
18+
withBackupId(backupId: string) {
1919
this.backupId = backupId;
2020
return this;
2121
}
2222

2323
validate() {
24-
this.errors = [
24+
this.addErrors([
2525
...validateBackend(this.backend),
2626
...validateBackupId(this.backupId),
27-
];
27+
])
2828
}
2929

3030
do() {

backup/backupCreator.js renamed to backup/backupCreator.ts

Lines changed: 29 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,26 @@
1-
import { CreateStatus } from "./consts";
2-
import { validateBackupId, validateExcludeClassNames, validateIncludeClassNames, validateBackend } from "./validation";
1+
import {CreateStatus} from "./consts";
2+
import {validateBackend, validateBackupId, validateExcludeClassNames, validateIncludeClassNames} from "./validation";
3+
import BackupCreateStatusGetter from "./backupCreateStatusGetter";
4+
import Connection from "../connection";
5+
import {CommandBase} from "../validation/commandBase";
36

47
const WAIT_INTERVAL = 1000;
58

6-
export default class BackupCreator {
9+
export default class BackupCreator extends CommandBase {
710

8-
includeClassNames;
9-
excludeClassNames;
10-
backend;
11-
backupId;
12-
waitForCompletion;
13-
errors;
11+
private backend?: string;
12+
private backupId?: string;
13+
private excludeClassNames?: string[];
14+
private includeClassNames?: string[];
15+
private statusGetter: BackupCreateStatusGetter;
16+
private waitForCompletion!: boolean;
1417

15-
constructor(client, statusGetter) {
16-
this.client = client;
18+
constructor(client: Connection, statusGetter: BackupCreateStatusGetter) {
19+
super(client)
1720
this.statusGetter = statusGetter;
1821
}
1922

20-
withIncludeClassNames(...classNames) {
23+
withIncludeClassNames(...classNames: string[]) {
2124
let cls = classNames;
2225
if (classNames.length && Array.isArray(classNames[0])) {
2326
cls = classNames[0];
@@ -26,7 +29,7 @@ export default class BackupCreator {
2629
return this;
2730
}
2831

29-
withExcludeClassNames(...classNames) {
32+
withExcludeClassNames(...classNames: string[]) {
3033
let cls = classNames;
3134
if (classNames.length && Array.isArray(classNames[0])) {
3235
cls = classNames[0];
@@ -35,28 +38,28 @@ export default class BackupCreator {
3538
return this;
3639
}
3740

38-
withBackend(backend) {
41+
withBackend(backend: string) {
3942
this.backend = backend;
4043
return this;
4144
}
4245

43-
withBackupId(backupId) {
46+
withBackupId(backupId: string) {
4447
this.backupId = backupId;
4548
return this;
4649
}
4750

48-
withWaitForCompletion(waitForCompletion) {
51+
withWaitForCompletion(waitForCompletion: boolean) {
4952
this.waitForCompletion = waitForCompletion;
5053
return this;
5154
}
5255

5356
validate() {
54-
this.errors = [
57+
this.addErrors([
5558
...validateIncludeClassNames(this.includeClassNames),
5659
...validateExcludeClassNames(this.excludeClassNames),
5760
...validateBackend(this.backend),
5861
...validateBackupId(this.backupId),
59-
];
62+
])
6063
}
6164

6265
do() {
@@ -80,21 +83,21 @@ export default class BackupCreator {
8083
return this._create(payload);
8184
}
8285

83-
_create(payload) {
86+
_create(payload: any) {
8487
return this.client.post(this._path(), payload);
8588
}
8689

87-
_createAndWaitForCompletion(payload) {
90+
_createAndWaitForCompletion(payload: any) {
8891
return new Promise((resolve, reject) => {
8992
this._create(payload)
90-
.then(createResponse => {
93+
.then((createResponse: any) => {
9194
this.statusGetter
92-
.withBackend(this.backend)
93-
.withBackupId(this.backupId);
95+
.withBackend(this.backend!)
96+
.withBackupId(this.backupId!);
9497

9598
const loop = () => {
9699
this.statusGetter.do()
97-
.then(createStatusResponse => {
100+
.then((createStatusResponse: any) => {
98101
if (createStatusResponse.status == CreateStatus.SUCCESS
99102
|| createStatusResponse.status == CreateStatus.FAILED
100103
) {
@@ -116,8 +119,8 @@ export default class BackupCreator {
116119
return `/backups/${this.backend}`;
117120
}
118121

119-
_merge(createStatusResponse, createResponse) {
120-
const merged = {};
122+
_merge(createStatusResponse: any, createResponse: any) {
123+
const merged: any = {};
121124
if ('id' in createStatusResponse) {
122125
merged.id = createStatusResponse.id;
123126
}

backup/backupGetter.js renamed to backup/backupGetter.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,22 @@
11
import { validateBackend } from "./validation";
2+
import Connection from "../connection";
3+
import {CommandBase} from "../validation/commandBase";
24

3-
export default class BackupGetter {
5+
export default class BackupGetter extends CommandBase {
46

5-
backend;
6-
errors;
7+
private backend?: string;
78

8-
constructor(client) {
9-
this.client = client;
9+
constructor(client: Connection) {
10+
super(client)
1011
}
1112

12-
withBackend(backend) {
13+
withBackend(backend: string) {
1314
this.backend = backend;
1415
return this;
1516
}
1617

1718
validate() {
18-
this.errors = validateBackend(this.backend);
19+
this.addErrors(validateBackend(this.backend))
1920
}
2021

2122
do() {

backup/backupRestoreStatusGetter.js renamed to backup/backupRestoreStatusGetter.ts

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,31 @@
11
import { validateBackupId, validateBackend } from "./validation";
2+
import Connection from "../connection";
3+
import {CommandBase} from "../validation/commandBase";
24

3-
export default class BackupRestoreStatusGetter {
5+
export default class BackupRestoreStatusGetter extends CommandBase {
46

5-
backend;
6-
backupId;
7-
errors;
7+
private backend?: string
8+
private backupId?: string;
89

9-
constructor(client) {
10-
this.client = client;
10+
constructor(client: Connection) {
11+
super(client)
1112
}
1213

13-
withBackend(backend) {
14+
withBackend(backend: string) {
1415
this.backend = backend;
1516
return this;
1617
}
1718

18-
withBackupId(backupId) {
19+
withBackupId(backupId: string) {
1920
this.backupId = backupId;
2021
return this;
2122
}
2223

2324
validate() {
24-
this.errors = [
25+
this.addErrors([
2526
...validateBackend(this.backend),
2627
...validateBackupId(this.backupId),
27-
];
28+
])
2829
}
2930

3031
do() {

backup/backupRestorer.js renamed to backup/backupRestorer.ts

Lines changed: 31 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,26 @@
1-
import { RestoreStatus } from "./consts";
2-
import { validateBackupId, validateExcludeClassNames, validateIncludeClassNames, validateBackend } from "./validation";
1+
import {RestoreStatus} from "./consts";
2+
import {validateBackend, validateBackupId, validateExcludeClassNames, validateIncludeClassNames} from "./validation";
3+
import Connection from "../connection";
4+
import BackupRestoreStatusGetter from "./backupRestoreStatusGetter";
5+
import {CommandBase} from "../validation/commandBase";
36

47
const WAIT_INTERVAL = 1000;
58

6-
export default class BackupRestorer {
9+
export default class BackupRestorer extends CommandBase {
710

8-
includeClassNames;
9-
excludeClassNames;
10-
backend;
11-
backupId;
12-
waitForCompletion;
13-
errors;
11+
private backend?: string;
12+
private backupId?: string;
13+
private excludeClassNames?: string[];
14+
private includeClassNames?: string[];
15+
private statusGetter: BackupRestoreStatusGetter;
16+
private waitForCompletion?: boolean;
1417

15-
constructor(client, statusGetter) {
16-
this.client = client;
18+
constructor(client: Connection, statusGetter: BackupRestoreStatusGetter) {
19+
super(client)
1720
this.statusGetter = statusGetter;
1821
}
1922

20-
withIncludeClassNames(...classNames) {
23+
withIncludeClassNames(...classNames: string[]) {
2124
let cls = classNames;
2225
if (classNames.length && Array.isArray(classNames[0])) {
2326
cls = classNames[0];
@@ -26,7 +29,7 @@ export default class BackupRestorer {
2629
return this;
2730
}
2831

29-
withExcludeClassNames(...classNames) {
32+
withExcludeClassNames(...classNames: string[]) {
3033
let cls = classNames;
3134
if (classNames.length && Array.isArray(classNames[0])) {
3235
cls = classNames[0];
@@ -35,28 +38,28 @@ export default class BackupRestorer {
3538
return this;
3639
}
3740

38-
withBackend(backend) {
41+
withBackend(backend: string) {
3942
this.backend = backend;
4043
return this;
4144
}
4245

43-
withBackupId(backupId) {
46+
withBackupId(backupId: string) {
4447
this.backupId = backupId;
4548
return this;
4649
}
4750

48-
withWaitForCompletion(waitForCompletion) {
51+
withWaitForCompletion(waitForCompletion: boolean) {
4952
this.waitForCompletion = waitForCompletion;
5053
return this;
5154
}
5255

5356
validate() {
54-
this.errors = [
55-
...validateIncludeClassNames(this.includeClassNames),
56-
...validateExcludeClassNames(this.excludeClassNames),
57+
this.addErrors([
58+
...validateIncludeClassNames(this.includeClassNames || []),
59+
...validateExcludeClassNames(this.excludeClassNames || []),
5760
...validateBackend(this.backend),
5861
...validateBackupId(this.backupId),
59-
];
62+
])
6063
}
6164

6265
do() {
@@ -79,21 +82,21 @@ export default class BackupRestorer {
7982
return this._restore(payload);
8083
}
8184

82-
_restore(payload) {
85+
_restore(payload: any) {
8386
return this.client.post(this._path(), payload);
8487
}
8588

86-
_restoreAndWaitForCompletion(payload) {
89+
_restoreAndWaitForCompletion(payload: any) {
8790
return new Promise((resolve, reject) => {
8891
this._restore(payload)
89-
.then(restoreResponse => {
92+
.then((restoreResponse: any)=> {
9093
this.statusGetter
91-
.withBackend(this.backend)
92-
.withBackupId(this.backupId);
94+
.withBackend(this.backend!)
95+
.withBackupId(this.backupId!);
9396

9497
const loop = () => {
9598
this.statusGetter.do()
96-
.then(restoreStatusResponse => {
99+
.then((restoreStatusResponse: any) => {
97100
if (restoreStatusResponse.status == RestoreStatus.SUCCESS
98101
|| restoreStatusResponse.status == RestoreStatus.FAILED
99102
) {
@@ -115,8 +118,8 @@ export default class BackupRestorer {
115118
return `/backups/${this.backend}/${this.backupId}/restore`;
116119
}
117120

118-
_merge(restoreStatusResponse, restoreResponse) {
119-
const merged = {};
121+
_merge(restoreStatusResponse: any, restoreResponse: any) {
122+
const merged: any = {};
120123
if ('id' in restoreStatusResponse) {
121124
merged.id = restoreStatusResponse.id;
122125
}
File renamed without changes.

0 commit comments

Comments
 (0)