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
6 changes: 6 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[*]
charset = utf-8
indent_style = space
indent_size = 2
insert_final_newline = true
trim_trailing_whitespace = true
7 changes: 5 additions & 2 deletions batch/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@ import ObjectsBatcher from "./objectsBatcher";
import ObjectsBatchDeleter from "./objectsBatchDeleter";
import ReferencesBatcher from "./referencesBatcher";
import ReferencePayloadBuilder from "./referencePayloadBuilder";
import { BeaconPath } from "../utils/beaconPath";

const batch = (client, dbVersionSupport) => {
const beaconPath = new BeaconPath(dbVersionSupport);

const batch = (client) => {
return {
objectsBatcher: () => new ObjectsBatcher(client),
objectsBatchDeleter: () => new ObjectsBatchDeleter(client),
referencesBatcher: () => new ReferencesBatcher(client),
referencesBatcher: () => new ReferencesBatcher(client, beaconPath),
referencePayloadBuilder: () => new ReferencePayloadBuilder(client),
};
};
Expand Down
40 changes: 21 additions & 19 deletions batch/journey.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ describe("batch importing", () => {

it("verifies they are now queryable", () => {
return Promise.all([
client.data.getterById().withId(thingIds[0]).do(),
client.data.getterById().withId(thingIds[1]).do(),
client.data.getterById().withId(thingIds[0]).withClassName(thingClassName).do(),
client.data.getterById().withId(thingIds[1]).withClassName(thingClassName).do(),
]).catch((e) => fail("it should not have error'd " + e));
});
});
Expand Down Expand Up @@ -94,8 +94,8 @@ describe("batch importing", () => {

it("verifies they are now queryable", () => {
return Promise.all([
client.data.getterById().withId(thingIds[2]).do(),
client.data.getterById().withId(thingIds[3]).do(),
client.data.getterById().withId(thingIds[2]).withClassName(thingClassName).do(),
client.data.getterById().withId(thingIds[3]).withClassName(thingClassName).do(),
]).catch((e) => fail("it should not have error'd " + e));
});
});
Expand Down Expand Up @@ -132,8 +132,8 @@ describe("batch importing", () => {

it("verifies they are now queryable", () => {
return Promise.all([
client.data.getterById().withId(toImport[0].id).do(),
client.data.getterById().withId(toImport[1].id).do(),
client.data.getterById().withId(toImport[0].id).withClassName(toImport[0].class).do(),
client.data.getterById().withId(toImport[1].id).withClassName(toImport[1].class).do(),
]).catch((e) => fail("it should not have error'd " + e));
});
});
Expand All @@ -144,16 +144,12 @@ describe("batch importing", () => {
return client.batch
.referencesBatcher()
.withReference({
from:
`weaviate://localhost/${thingClassName}/` +
`${thingIds[0]}/refProp`,
to: `weaviate://localhost/${otherThingIds[0]}`,
from: `weaviate://localhost/${thingClassName}/${thingIds[0]}/refProp`,
to: `weaviate://localhost/${otherThingClassName}/${otherThingIds[0]}`,
})
.withReference({
from:
`weaviate://localhost/${thingClassName}/` +
`${thingIds[1]}/refProp`,
to: `weaviate://localhost/${otherThingIds[1]}`,
from: `weaviate://localhost/${thingClassName}/${thingIds[1]}/refProp`,
to: `weaviate://localhost/${otherThingClassName}/${otherThingIds[1]}`,
})
.do()
.then((res) => {
Expand All @@ -174,6 +170,7 @@ describe("batch importing", () => {
.withFromRefProp("refProp")
.withFromId(thingIds[2])
.withToId(otherThingIds[0])
.withToClassName(otherThingClassName)
.payload()
)
.withReference(
Expand All @@ -183,6 +180,7 @@ describe("batch importing", () => {
.withFromRefProp("refProp")
.withFromId(thingIds[3])
.withToId(otherThingIds[1])
.withToClassName(otherThingClassName)
.payload()
)
.do()
Expand All @@ -203,37 +201,41 @@ describe("batch importing", () => {
client.data
.getterById()
.withId(thingIds[0])
.withClassName(thingClassName)
.do()
.then((res) => {
expect(res.properties.refProp[0].beacon).toEqual(
`weaviate://localhost/${otherThingIds[0]}`
`weaviate://localhost/${otherThingClassName}/${otherThingIds[0]}`
);
}),
client.data
.getterById()
.withId(thingIds[1])
.withClassName(thingClassName)
.do()
.then((res) => {
expect(res.properties.refProp[0].beacon).toEqual(
`weaviate://localhost/${otherThingIds[1]}`
`weaviate://localhost/${otherThingClassName}/${otherThingIds[1]}`
);
}),
client.data
.getterById()
.withId(thingIds[2])
.withClassName(thingClassName)
.do()
.then((res) => {
expect(res.properties.refProp[0].beacon).toEqual(
`weaviate://localhost/${otherThingIds[0]}`
`weaviate://localhost/${otherThingClassName}/${otherThingIds[0]}`
);
}),
client.data
.getterById()
.withId(thingIds[3])
.withClassName(thingClassName)
.do()
.then((res) => {
expect(res.properties.refProp[0].beacon).toEqual(
`weaviate://localhost/${otherThingIds[1]}`
`weaviate://localhost/${otherThingClassName}/${otherThingIds[1]}`
);
}),
]).catch((e) => fail("it should not have error'd " + e));
Expand Down Expand Up @@ -395,7 +397,7 @@ describe("batch deleting", () => {
})
})

it("batch deletes fails due to validation", () =>
it("batch deletes fails due to validation", () =>
client.batch
.objectsBatchDeleter()
.withClassName("")
Expand Down
14 changes: 13 additions & 1 deletion batch/referencePayloadBuilder.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { isValidStringProperty } from "../validation/string";

export default class ReferencesBatcher {
constructor(client) {
this.client = client;
Expand All @@ -24,6 +26,11 @@ export default class ReferencesBatcher {
return this;
};

withToClassName(className) {
this.toClassName = className;
return this;
}

validateIsSet = (prop, name, setter) => {
if (prop == undefined || prop == null || prop.length == 0) {
this.errors = [
Expand Down Expand Up @@ -54,11 +61,16 @@ export default class ReferencesBatcher {
throw new Error(this.errors.join(", "));
}

var beaconTo = `weaviate://localhost`;
if (isValidStringProperty(this.toClassName)) {
beaconTo = `${beaconTo}/${this.toClassName}`;
}

return {
from:
`weaviate://localhost/${this.fromClassName}` +
`/${this.fromId}/${this.fromRefProp}`,
to: `weaviate://localhost/${this.toId}`,
to: `${beaconTo}/${this.toId}`,
};
};
}
15 changes: 13 additions & 2 deletions batch/referencesBatcher.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
export default class ReferencesBatcher {
constructor(client) {
constructor(client, beaconPath) {
this.client = client;
this.beaconPath = beaconPath;
this.references = [];
this.errors = [];
}
Expand Down Expand Up @@ -34,6 +35,16 @@ export default class ReferencesBatcher {
);
}
const path = `/batch/references`;
return this.client.post(path, this.payload());
const payloadPromise = Promise.all(this.references.map(ref => this.rebuildReferencePromise(ref)));

return payloadPromise.then(payload => this.client.post(path, payload));
};

rebuildReferencePromise(reference) {
return this.beaconPath.rebuild(reference.to)
.then(beaconTo => ({
from: reference.from,
to: beaconTo
}));
}
}
9 changes: 4 additions & 5 deletions data/checker.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { buildObjectsPath } from "./path";

export default class Checker {
constructor(client) {
constructor(client, objectsPath) {
this.client = client;
this.objectsPath = objectsPath;
this.errors = [];
}

Expand Down Expand Up @@ -41,7 +40,7 @@ export default class Checker {
}
this.validate();

const path = buildObjectsPath(this.id, this.className);
return this.client.head(path);
return this.objectsPath.buildCheck(this.id, this.className)
.then(this.client.head)
};
}
8 changes: 5 additions & 3 deletions data/creator.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { isValidStringProperty } from "../validation/string";

export default class Creator {
constructor(client) {
constructor(client, objectsPath) {
this.client = client;
this.objectsPath = objectsPath;
this.errors = [];
}

Expand Down Expand Up @@ -53,7 +54,8 @@ export default class Creator {
new Error("invalid usage: " + this.errors.join(", "))
);
}
const path = `/objects`;
return this.client.post(path, this.payload());

return this.objectsPath.buildCreate()
.then(path => this.client.post(path, this.payload()))
};
}
9 changes: 4 additions & 5 deletions data/deleter.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { buildObjectsPath } from "./path";

export default class Deleter {
constructor(client) {
constructor(client, objectsPath) {
this.client = client;
this.objectsPath = objectsPath;
this.errors = [];
}

Expand Down Expand Up @@ -41,7 +40,7 @@ export default class Deleter {
}
this.validate();

const path = buildObjectsPath(this.id, this.className);
return this.client.delete(path);
return this.objectsPath.buildDelete(this.id, this.className)
.then(this.client.delete);
};
}
25 changes: 9 additions & 16 deletions data/getter.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
export default class Getter {
constructor(client) {
constructor(client, objectsPath) {
this.client = client;
this.objectsPath = objectsPath;
this.errors = [];
this.additionals = [];
}

withClassName = (className) => {
this.className = className;
return this;
};

withLimit = (limit) => {
this.limit = limit;
return this;
Expand All @@ -25,21 +31,8 @@ export default class Getter {
new Error("invalid usage: " + this.errors.join(", "))
);
}
let path = `/objects`;

let params = [];
if (this.additionals.length > 0) {
params = [...params, `include=${this.additionals.join(",")}`];
}

if (this.limit) {
params = [...params, `limit=${this.limit}`];
}

if (params.length > 0) {
path += `?${params.join("&")}`;
}

return this.client.get(path);
return this.objectsPath.buildGet(this.className, this.limit, this.additionals)
.then(this.client.get);
};
}
18 changes: 4 additions & 14 deletions data/getterById.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { buildObjectsPath } from "./path";

export default class GetterById {
constructor(client) {
constructor(client, objectsPath) {
this.client = client;
this.objectsPath = objectsPath;
this.errors = [];
this.additionals = [];
}
Expand All @@ -22,11 +21,6 @@ export default class GetterById {
return this;
};

extendAdditionals = (prop) => {
this.additionals = [...this.additionals, prop];
return this;
};

withAdditional = (additionalFlag) => this.extendAdditionals(additionalFlag);

withVector = () => this.extendAdditionals("vector");
Expand All @@ -52,11 +46,7 @@ export default class GetterById {
);
}

let path = buildObjectsPath(this.id, this.className);

if (this.additionals.length > 0) {
path += `?include=${this.additionals.join(",")}`;
}
return this.client.get(path);
return this.objectsPath.buildGetOne(this.id, this.className, this.additionals)
.then(this.client.get);
};
}
28 changes: 17 additions & 11 deletions data/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,26 @@ import ReferenceCreator from "./referenceCreator";
import ReferenceReplacer from "./referenceReplacer";
import ReferenceDeleter from "./referenceDeleter";
import ReferencePayloadBuilder from "./referencePayloadBuilder";
import { ObjectsPath, ReferencesPath } from "./path";
import { BeaconPath } from "../utils/beaconPath";

const data = (client, dbVersionSupport) => {
const objectsPath = new ObjectsPath(dbVersionSupport);
const referencesPath = new ReferencesPath(dbVersionSupport);
const beaconPath = new BeaconPath(dbVersionSupport);

const data = (client) => {
return {
creator: () => new Creator(client),
creator: () => new Creator(client, objectsPath),
validator: () => new Validator(client),
updater: () => new Updater(client),
merger: () => new Merger(client),
getter: () => new Getter(client),
getterById: () => new GetterById(client),
deleter: () => new Deleter(client),
checker: () => new Checker(client),
referenceCreator: () => new ReferenceCreator(client),
referenceReplacer: () => new ReferenceReplacer(client),
referenceDeleter: () => new ReferenceDeleter(client),
updater: () => new Updater(client, objectsPath),
merger: () => new Merger(client, objectsPath),
getter: () => new Getter(client, objectsPath),
getterById: () => new GetterById(client, objectsPath),
deleter: () => new Deleter(client, objectsPath),
checker: () => new Checker(client, objectsPath),
referenceCreator: () => new ReferenceCreator(client, referencesPath, beaconPath),
referenceReplacer: () => new ReferenceReplacer(client, referencesPath, beaconPath),
referenceDeleter: () => new ReferenceDeleter(client, referencesPath, beaconPath),
referencePayloadBuilder: () => new ReferencePayloadBuilder(client),
};
};
Expand Down
Loading