Skip to content

Commit

Permalink
Merge pull request #224 from weaviate/fix/stats-undefined-in-isFilePr…
Browse files Browse the repository at this point in the history
…omise

Resolve `false` for `isFilePromise` if `stats` is undefined
  • Loading branch information
tsmith023 authored Nov 6, 2024
2 parents 196b074 + 1a1cecc commit 5c0b1d4
Show file tree
Hide file tree
Showing 676 changed files with 93,844 additions and 1 deletion.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
.DS_Store
dist/
coverage/
node_modules/
config.yaml
Expand Down
14 changes: 14 additions & 0 deletions dist/node/cjs/backup/backupCreateStatusGetter.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import Connection from '../connection/index.js';
import { BackupCreateStatusResponse } from '../openapi/types.js';
import { CommandBase } from '../validation/commandBase.js';
import { Backend } from './index.js';
export default class BackupCreateStatusGetter extends CommandBase {
private backend?;
private backupId?;
constructor(client: Connection);
withBackend(backend: Backend): this;
withBackupId(backupId: string): this;
validate: () => void;
do: () => Promise<BackupCreateStatusResponse>;
private _path;
}
37 changes: 37 additions & 0 deletions dist/node/cjs/backup/backupCreateStatusGetter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
const errors_js_1 = require('../errors.js');
const commandBase_js_1 = require('../validation/commandBase.js');
const validation_js_1 = require('./validation.js');
class BackupCreateStatusGetter extends commandBase_js_1.CommandBase {
constructor(client) {
super(client);
this.validate = () => {
this.addErrors([
...(0, validation_js_1.validateBackend)(this.backend),
...(0, validation_js_1.validateBackupId)(this.backupId),
]);
};
this.do = () => {
this.validate();
if (this.errors.length > 0) {
return Promise.reject(
new errors_js_1.WeaviateInvalidInputError('invalid usage: ' + this.errors.join(', '))
);
}
return this.client.get(this._path());
};
this._path = () => {
return `/backups/${this.backend}/${this.backupId}`;
};
}
withBackend(backend) {
this.backend = backend;
return this;
}
withBackupId(backupId) {
this.backupId = backupId;
return this;
}
}
exports.default = BackupCreateStatusGetter;
35 changes: 35 additions & 0 deletions dist/node/cjs/backup/backupCreator.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import Connection from '../connection/index.js';
import {
BackupConfig,
BackupCreateRequest,
BackupCreateResponse,
BackupCreateStatusResponse,
} from '../openapi/types.js';
import { CommandBase } from '../validation/commandBase.js';
import BackupCreateStatusGetter from './backupCreateStatusGetter.js';
import { Backend } from './index.js';
export default class BackupCreator extends CommandBase {
private backend;
private backupId;
private excludeClassNames?;
private includeClassNames?;
private statusGetter;
private waitForCompletion;
private config?;
constructor(client: Connection, statusGetter: BackupCreateStatusGetter);
withIncludeClassNames(...classNames: string[]): this;
withExcludeClassNames(...classNames: string[]): this;
withBackend(backend: Backend): this;
withBackupId(backupId: string): this;
withWaitForCompletion(waitForCompletion: boolean): this;
withConfig(cfg: BackupConfig): this;
validate: () => void;
do: () => Promise<BackupCreateResponse>;
_create: (payload: BackupCreateRequest) => Promise<BackupCreateResponse>;
_createAndWaitForCompletion: (payload: BackupCreateRequest) => Promise<BackupCreateResponse>;
private _path;
_merge: (
createStatusResponse: BackupCreateStatusResponse,
createResponse: BackupCreateResponse
) => BackupCreateResponse;
}
121 changes: 121 additions & 0 deletions dist/node/cjs/backup/backupCreator.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
const errors_js_1 = require('../errors.js');
const commandBase_js_1 = require('../validation/commandBase.js');
const validation_js_1 = require('./validation.js');
const WAIT_INTERVAL = 1000;
class BackupCreator extends commandBase_js_1.CommandBase {
constructor(client, statusGetter) {
super(client);
this.validate = () => {
this.addErrors([
...(0, validation_js_1.validateIncludeClassNames)(this.includeClassNames),
...(0, validation_js_1.validateExcludeClassNames)(this.excludeClassNames),
...(0, validation_js_1.validateBackend)(this.backend),
...(0, validation_js_1.validateBackupId)(this.backupId),
]);
};
this.do = () => {
this.validate();
if (this.errors.length > 0) {
return Promise.reject(
new errors_js_1.WeaviateInvalidInputError('invalid usage: ' + this.errors.join(', '))
);
}
const payload = {
id: this.backupId,
config: this.config,
include: this.includeClassNames,
exclude: this.excludeClassNames,
};
if (this.waitForCompletion) {
return this._createAndWaitForCompletion(payload);
}
return this._create(payload);
};
this._create = (payload) => {
return this.client.postReturn(this._path(), payload);
};
this._createAndWaitForCompletion = (payload) => {
return new Promise((resolve, reject) => {
this._create(payload)
.then((createResponse) => {
this.statusGetter.withBackend(this.backend).withBackupId(this.backupId);
const loop = () => {
this.statusGetter
.do()
.then((createStatusResponse) => {
if (createStatusResponse.status == 'SUCCESS' || createStatusResponse.status == 'FAILED') {
resolve(this._merge(createStatusResponse, createResponse));
} else {
setTimeout(loop, WAIT_INTERVAL);
}
})
.catch(reject);
};
loop();
})
.catch(reject);
});
};
this._path = () => {
return `/backups/${this.backend}`;
};
this._merge = (createStatusResponse, createResponse) => {
const merged = {};
if ('id' in createStatusResponse) {
merged.id = createStatusResponse.id;
}
if ('path' in createStatusResponse) {
merged.path = createStatusResponse.path;
}
if ('backend' in createStatusResponse) {
merged.backend = createStatusResponse.backend;
}
if ('status' in createStatusResponse) {
merged.status = createStatusResponse.status;
}
if ('error' in createStatusResponse) {
merged.error = createStatusResponse.error;
}
if ('classes' in createResponse) {
merged.classes = createResponse.classes;
}
return merged;
};
this.statusGetter = statusGetter;
}
withIncludeClassNames(...classNames) {
let cls = classNames;
if (classNames.length && Array.isArray(classNames[0])) {
cls = classNames[0];
}
this.includeClassNames = cls;
return this;
}
withExcludeClassNames(...classNames) {
let cls = classNames;
if (classNames.length && Array.isArray(classNames[0])) {
cls = classNames[0];
}
this.excludeClassNames = cls;
return this;
}
withBackend(backend) {
this.backend = backend;
return this;
}
withBackupId(backupId) {
this.backupId = backupId;
return this;
}
withWaitForCompletion(waitForCompletion) {
this.waitForCompletion = waitForCompletion;
return this;
}
withConfig(cfg) {
this.config = cfg;
return this;
}
}
exports.default = BackupCreator;
12 changes: 12 additions & 0 deletions dist/node/cjs/backup/backupGetter.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import Connection from '../connection/index.js';
import { BackupCreateResponse } from '../openapi/types.js';
import { CommandBase } from '../validation/commandBase.js';
import { Backend } from './index.js';
export default class BackupGetter extends CommandBase {
private backend?;
constructor(client: Connection);
withBackend(backend: Backend): this;
validate: () => void;
do: () => Promise<BackupCreateResponse[]>;
private _path;
}
30 changes: 30 additions & 0 deletions dist/node/cjs/backup/backupGetter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
const errors_js_1 = require('../errors.js');
const commandBase_js_1 = require('../validation/commandBase.js');
const validation_js_1 = require('./validation.js');
class BackupGetter extends commandBase_js_1.CommandBase {
constructor(client) {
super(client);
this.validate = () => {
this.addErrors((0, validation_js_1.validateBackend)(this.backend));
};
this.do = () => {
this.validate();
if (this.errors.length > 0) {
return Promise.reject(
new errors_js_1.WeaviateInvalidInputError('invalid usage: ' + this.errors.join(', '))
);
}
return this.client.get(this._path());
};
this._path = () => {
return `/backups/${this.backend}`;
};
}
withBackend(backend) {
this.backend = backend;
return this;
}
}
exports.default = BackupGetter;
14 changes: 14 additions & 0 deletions dist/node/cjs/backup/backupRestoreStatusGetter.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import Connection from '../connection/index.js';
import { BackupRestoreStatusResponse } from '../openapi/types.js';
import { CommandBase } from '../validation/commandBase.js';
import { Backend } from './index.js';
export default class BackupRestoreStatusGetter extends CommandBase {
private backend?;
private backupId?;
constructor(client: Connection);
withBackend(backend: Backend): this;
withBackupId(backupId: string): this;
validate: () => void;
do: () => Promise<BackupRestoreStatusResponse>;
private _path;
}
37 changes: 37 additions & 0 deletions dist/node/cjs/backup/backupRestoreStatusGetter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
const errors_js_1 = require('../errors.js');
const commandBase_js_1 = require('../validation/commandBase.js');
const validation_js_1 = require('./validation.js');
class BackupRestoreStatusGetter extends commandBase_js_1.CommandBase {
constructor(client) {
super(client);
this.validate = () => {
this.addErrors([
...(0, validation_js_1.validateBackend)(this.backend),
...(0, validation_js_1.validateBackupId)(this.backupId),
]);
};
this.do = () => {
this.validate();
if (this.errors.length > 0) {
return Promise.reject(
new errors_js_1.WeaviateInvalidInputError('invalid usage: ' + this.errors.join(', '))
);
}
return this.client.get(this._path());
};
this._path = () => {
return `/backups/${this.backend}/${this.backupId}/restore`;
};
}
withBackend(backend) {
this.backend = backend;
return this;
}
withBackupId(backupId) {
this.backupId = backupId;
return this;
}
}
exports.default = BackupRestoreStatusGetter;
35 changes: 35 additions & 0 deletions dist/node/cjs/backup/backupRestorer.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import Connection from '../connection/index.js';
import {
BackupRestoreRequest,
BackupRestoreResponse,
BackupRestoreStatusResponse,
RestoreConfig,
} from '../openapi/types.js';
import { CommandBase } from '../validation/commandBase.js';
import BackupRestoreStatusGetter from './backupRestoreStatusGetter.js';
import { Backend } from './index.js';
export default class BackupRestorer extends CommandBase {
private backend;
private backupId;
private excludeClassNames?;
private includeClassNames?;
private statusGetter;
private waitForCompletion?;
private config?;
constructor(client: Connection, statusGetter: BackupRestoreStatusGetter);
withIncludeClassNames(...classNames: string[]): this;
withExcludeClassNames(...classNames: string[]): this;
withBackend(backend: Backend): this;
withBackupId(backupId: string): this;
withWaitForCompletion(waitForCompletion: boolean): this;
withConfig(cfg: RestoreConfig): this;
validate: () => void;
do: () => Promise<BackupRestoreResponse>;
_restore: (payload: BackupRestoreRequest) => Promise<BackupRestoreResponse>;
_restoreAndWaitForCompletion: (payload: BackupRestoreRequest) => Promise<BackupRestoreResponse>;
private _path;
_merge: (
restoreStatusResponse: BackupRestoreStatusResponse,
restoreResponse: BackupRestoreResponse
) => BackupRestoreResponse;
}
Loading

0 comments on commit 5c0b1d4

Please sign in to comment.