From 72b22e1dba79aff7d85c69bb4eed2879af27739a Mon Sep 17 00:00:00 2001 From: Parker Duckworth Date: Mon, 13 Jun 2022 11:06:21 -0500 Subject: [PATCH 1/7] update object getById to use class name --- data/getterById.js | 18 +++++++++++++++++- data/journey.test.js | 28 ++++++++++++++++++++++++++++ docker-compose.yml | 3 ++- 3 files changed, 47 insertions(+), 2 deletions(-) diff --git a/data/getterById.js b/data/getterById.js index 043c2f9..06f5574 100644 --- a/data/getterById.js +++ b/data/getterById.js @@ -1,3 +1,5 @@ +import { isValidStringProperty } from "../validation/string"; + export default class GetterById { constructor(client) { this.client = client; @@ -10,6 +12,19 @@ export default class GetterById { return this; }; + withClassName = (className) => { + this.className = className; + return this; + }; + + buildPath = () => { + let path = `/objects`; + if (isValidStringProperty(this.className)) { + path = `${path}/${this.className}` + } + return `/${path}/${this.id}`; + } + extendAdditionals = (prop) => { this.additionals = [...this.additionals, prop]; return this; @@ -45,7 +60,8 @@ export default class GetterById { ); } - let path = `/objects/${this.id}`; + let path = this.buildPath(); + if (this.additionals.length > 0) { path += `?include=${this.additionals.join(",")}`; } diff --git a/data/journey.test.js b/data/journey.test.js index 826a19f..413862d 100644 --- a/data/journey.test.js +++ b/data/journey.test.js @@ -178,6 +178,34 @@ describe("data", () => { .catch((e) => fail("it should not have errord: " + e)); }); + it("gets one thing by id with class name", () => { + return client.data + .getterById() + .withClassName(thingClassName) + .withId("1565c06c-463f-466c-9092-5930dbac3887") + .do() + .then((res) => { + expect(res).toEqual( + expect.objectContaining({ + id: "1565c06c-463f-466c-9092-5930dbac3887", + properties: { stringProp: "with-id" }, + }) + ); + }) + .catch((e) => fail("it should not have errord: " + e)); + }); + + it("fails to get one thing by id with invalid class name", () => { + return client.data + .getterById() + .withClassName("DoesNotExist") + .withId("1565c06c-463f-466c-9092-5930dbac3887") + .do() + .catch(err => + expect(err).toEqual("it should not have errord: usage error (500): {\"error\":[{\"message\":\"repo: object by id: index not found for class DoesNotExist\"}]}") + ); + }); + it("gets one thing by id with all optional additional props", () => { return client.data .getterById() diff --git a/docker-compose.yml b/docker-compose.yml index 368c186..d327bb0 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,7 +1,8 @@ version: '3.4' services: weaviate: - image: semitechnologies/weaviate:1.13.2 + # TODO: temporarily use this version until next release + image: semitechnologies/weaviate:latest@sha256:248a1e1f6f0ba817c00ead4edeecf9d19961d482a3c432165d95762bd44e3a0c restart: on-failure:0 ports: - "8080:8080" From 8437b5c06c0a8f85374f1638564f328ac1d3b0ca Mon Sep 17 00:00:00 2001 From: Parker Duckworth Date: Mon, 13 Jun 2022 11:26:01 -0500 Subject: [PATCH 2/7] update object delete to use class name --- data/deleter.js | 17 ++++++++++++++++- data/journey.test.js | 26 +++++++++++++++++++++++++- 2 files changed, 41 insertions(+), 2 deletions(-) diff --git a/data/deleter.js b/data/deleter.js index 8d5bfee..c2af3c4 100644 --- a/data/deleter.js +++ b/data/deleter.js @@ -1,3 +1,5 @@ +import { isValidStringProperty } from "../validation/string"; + export default class Deleter { constructor(client) { this.client = client; @@ -9,6 +11,19 @@ export default class Deleter { return this; }; + withClassName = (className) => { + this.className = className; + return this; + } + + buildPath = () => { + let path = `/objects`; + if (isValidStringProperty(this.className)) { + path = `${path}/${this.className}` + } + return `/${path}/${this.id}`; + } + validateIsSet = (prop, name, setter) => { if (prop == undefined || prop == null || prop.length == 0) { this.errors = [ @@ -34,7 +49,7 @@ export default class Deleter { } this.validate(); - const path = `/objects/${this.id}`; + const path = this.buildPath(); return this.client.delete(path); }; } diff --git a/data/journey.test.js b/data/journey.test.js index 413862d..63dde27 100644 --- a/data/journey.test.js +++ b/data/journey.test.js @@ -202,7 +202,7 @@ describe("data", () => { .withId("1565c06c-463f-466c-9092-5930dbac3887") .do() .catch(err => - expect(err).toEqual("it should not have errord: usage error (500): {\"error\":[{\"message\":\"repo: object by id: index not found for class DoesNotExist\"}]}") + expect(err).toEqual("usage error (500): {\"error\":[{\"message\":\"repo: object by id: index not found for class DoesNotExist\"}]}") ); }); @@ -370,6 +370,30 @@ describe("data", () => { }); }); + it("deletes a thing with class name", async () => { + const properties = { stringProp: "with-id" }; + const id = "6781a974-cfbf-455d-ace8-f1dba4564230"; + + client.data + .creator() + .withClassName(thingClassName) + .withProperties(properties) + .withId(id) + .do() + .then((res) => { + expect(res.properties).toEqual(properties); + expect(res.id).toEqual(id); + }) + .catch((e) => fail("it should not have errord: " + e)); + + return client.data + .deleter() + .withId(id) + .withClassName(thingClassName) + .do() + .catch((e) => fail("it should not have errord: " + e)); + }) + it("verifies there are now fewer things (after delete)", () => { return Promise.all([ client.data From 706701c0cc8dadc112bf566beb5243fe1d08a874 Mon Sep 17 00:00:00 2001 From: Parker Duckworth Date: Mon, 13 Jun 2022 13:02:49 -0500 Subject: [PATCH 3/7] update object update to use class name --- data/journey.test.js | 59 +++++++++++++++++++++++++++++++++----------- data/updater.js | 10 +++++++- 2 files changed, 54 insertions(+), 15 deletions(-) diff --git a/data/journey.test.js b/data/journey.test.js index 63dde27..7478a76 100644 --- a/data/journey.test.js +++ b/data/journey.test.js @@ -162,7 +162,7 @@ describe("data", () => { .catch((e) => fail("it should not have errord: " + e)); }); - it("gets one thing by id", () => { + it("gets one thing by id only", () => { return client.data .getterById() .withId("1565c06c-463f-466c-9092-5930dbac3887") @@ -178,7 +178,7 @@ describe("data", () => { .catch((e) => fail("it should not have errord: " + e)); }); - it("gets one thing by id with class name", () => { + it("gets one thing by id and class name", () => { return client.data .getterById() .withClassName(thingClassName) @@ -239,7 +239,7 @@ describe("data", () => { }); }); - it("updates a thing", () => { + it("updates a thing by id only", () => { const id = "1565c06c-463f-466c-9092-5930dbac3887"; return client.data .getterById() @@ -264,6 +264,31 @@ describe("data", () => { .catch((e) => fail("it should not have errord: " + e)); }); + it("updates a thing by id and class name", () => { + const id = "1565c06c-463f-466c-9092-5930dbac3887"; + return client.data + .getterById() + .withId(id) + .withClassName(thingClassName) + .do() + .then((res) => { + const properties = res.properties; + properties.stringProp = "thing-updated-with-class-name"; + return client.data + .updater() + .withId(id) + .withClassName(thingClassName) + .withProperties(properties) + .do(); + }) + .then((res) => { + expect(res.properties).toEqual({ + stringProp: "thing-updated-with-class-name", + }); + }) + .catch((e) => fail("it should not have errord: " + e)); + }); + it("merges a thing", () => { const id = "1565c06c-463f-466c-9092-5930dbac3887"; return client.data @@ -342,7 +367,7 @@ describe("data", () => { .catch((e) => fail("it should not have errord: " + e)); }); - it("deletes a thing", () => { + it("deletes a thing by id only", () => { return client.data .deleter() .withId("1565c06c-463f-466c-9092-5930dbac3887") @@ -350,7 +375,7 @@ describe("data", () => { .catch((e) => fail("it should not have errord: " + e)); }); - it("checks that object doesn't exist anymore", () => { + it("checks that object doesn't exist anymore with delete by id only", () => { return client.data .checker() .withId("1565c06c-463f-466c-9092-5930dbac3887") @@ -363,18 +388,11 @@ describe("data", () => { .catch((e) => fail("it should not have errord: " + e)); }); - it("waits for es index updates", () => { - return new Promise((resolve, reject) => { - // TODO: remove in 1.0.0 - setTimeout(resolve, 1000); - }); - }); - - it("deletes a thing with class name", async () => { + it("deletes a thing with id and class name", async () => { const properties = { stringProp: "with-id" }; const id = "6781a974-cfbf-455d-ace8-f1dba4564230"; - client.data + await client.data .creator() .withClassName(thingClassName) .withProperties(properties) @@ -394,6 +412,19 @@ describe("data", () => { .catch((e) => fail("it should not have errord: " + e)); }) + it("checks that object doesn't exist anymore with delete by id and class name", () => { + return client.data + .checker() + .withId("6781a974-cfbf-455d-ace8-f1dba4564230") + .do() + .then((exists) => { + if (exists) { + fail("it should not exist in DB") + } + }) + .catch((e) => fail("it should not have errord: " + e)); + }); + it("verifies there are now fewer things (after delete)", () => { return Promise.all([ client.data diff --git a/data/updater.js b/data/updater.js index c1db80d..06d9389 100644 --- a/data/updater.js +++ b/data/updater.js @@ -39,6 +39,14 @@ export default class Updater { } }; + buildPath = () => { + let path = `/objects`; + if (isValidStringProperty(this.className)) { + path = `${path}/${this.className}` + } + return `/${path}/${this.id}`; + } + payload = () => ({ properties: this.properties, class: this.className, @@ -58,7 +66,7 @@ export default class Updater { new Error("invalid usage: " + this.errors.join(", ")) ); } - const path = `/objects/${this.id}`; + const path = this.buildPath(); return this.client.put(path, this.payload()); }; } From 322a96151650c61da86da1812b733af312ff34a9 Mon Sep 17 00:00:00 2001 From: Parker Duckworth Date: Mon, 13 Jun 2022 13:28:57 -0500 Subject: [PATCH 4/7] update object metadata to use class name --- data/checker.js | 9 ++++++++- data/deleter.js | 12 ++---------- data/getterById.js | 12 ++---------- data/journey.test.js | 16 +++++++++++++++- data/path.js | 9 +++++++++ data/updater.js | 14 ++++---------- 6 files changed, 40 insertions(+), 32 deletions(-) create mode 100644 data/path.js diff --git a/data/checker.js b/data/checker.js index 07c61e7..3daef09 100644 --- a/data/checker.js +++ b/data/checker.js @@ -1,3 +1,5 @@ +import { buildObjectsPath } from "./path" + export default class Checker { constructor(client) { this.client = client; @@ -9,6 +11,11 @@ export default class Checker { return this; }; + withClassName = (className) => { + this.className = className; + return this; + }; + validateIsSet = (prop, name, setter) => { if (prop == undefined || prop == null || prop.length == 0) { this.errors = [ @@ -34,7 +41,7 @@ export default class Checker { } this.validate(); - const path = `/objects/${this.id}`; + const path = buildObjectsPath(this.id, this.className); return this.client.head(path); }; } diff --git a/data/deleter.js b/data/deleter.js index c2af3c4..4f6364d 100644 --- a/data/deleter.js +++ b/data/deleter.js @@ -1,4 +1,4 @@ -import { isValidStringProperty } from "../validation/string"; +import { buildObjectsPath } from "./path" export default class Deleter { constructor(client) { @@ -16,14 +16,6 @@ export default class Deleter { return this; } - buildPath = () => { - let path = `/objects`; - if (isValidStringProperty(this.className)) { - path = `${path}/${this.className}` - } - return `/${path}/${this.id}`; - } - validateIsSet = (prop, name, setter) => { if (prop == undefined || prop == null || prop.length == 0) { this.errors = [ @@ -49,7 +41,7 @@ export default class Deleter { } this.validate(); - const path = this.buildPath(); + const path = buildObjectsPath(this.id, this.className); return this.client.delete(path); }; } diff --git a/data/getterById.js b/data/getterById.js index 06f5574..4c806fc 100644 --- a/data/getterById.js +++ b/data/getterById.js @@ -1,4 +1,4 @@ -import { isValidStringProperty } from "../validation/string"; +import { buildObjectsPath } from "./path" export default class GetterById { constructor(client) { @@ -17,14 +17,6 @@ export default class GetterById { return this; }; - buildPath = () => { - let path = `/objects`; - if (isValidStringProperty(this.className)) { - path = `${path}/${this.className}` - } - return `/${path}/${this.id}`; - } - extendAdditionals = (prop) => { this.additionals = [...this.additionals, prop]; return this; @@ -60,7 +52,7 @@ export default class GetterById { ); } - let path = this.buildPath(); + let path = buildObjectsPath(this.id, this.className); if (this.additionals.length > 0) { path += `?include=${this.additionals.join(",")}`; diff --git a/data/journey.test.js b/data/journey.test.js index 7478a76..e2c6def 100644 --- a/data/journey.test.js +++ b/data/journey.test.js @@ -354,7 +354,7 @@ describe("data", () => { .catch((e) => fail("it should not have errord: " + e)); }); - it("checks that object exists", () => { + it("checks that object exists by id only", () => { return client.data .checker() .withId("1565c06c-463f-466c-9092-5930dbac3887") @@ -367,6 +367,20 @@ describe("data", () => { .catch((e) => fail("it should not have errord: " + e)); }); + it("checks that object exists by id and class name", () => { + return client.data + .checker() + .withId("1565c06c-463f-466c-9092-5930dbac3887") + .withClassName(thingClassName) + .do() + .then((exists) => { + if (!exists) { + fail("it should exist in DB") + } + }) + .catch((e) => fail("it should not have errord: " + e)); + }); + it("deletes a thing by id only", () => { return client.data .deleter() diff --git a/data/path.js b/data/path.js new file mode 100644 index 0000000..ad168dc --- /dev/null +++ b/data/path.js @@ -0,0 +1,9 @@ +import { isValidStringProperty } from "../validation/string"; + +export function buildObjectsPath(id, className) { + let path = `/objects`; + if (isValidStringProperty(className)) { + path = `${path}/${className}`; + } + return `/${path}/${id}`; +} diff --git a/data/updater.js b/data/updater.js index 06d9389..c084ede 100644 --- a/data/updater.js +++ b/data/updater.js @@ -1,4 +1,5 @@ import { isValidStringProperty } from "../validation/string"; +import { buildObjectsPath } from "./path"; export default class Updater { constructor(client) { @@ -25,7 +26,7 @@ export default class Updater { if (!isValidStringProperty(this.className)) { this.errors = [ ...this.errors, - "className must be set - set with withId(id)", + "className must be set - use withClassName(className)", ]; } }; @@ -39,14 +40,6 @@ export default class Updater { } }; - buildPath = () => { - let path = `/objects`; - if (isValidStringProperty(this.className)) { - path = `${path}/${this.className}` - } - return `/${path}/${this.id}`; - } - payload = () => ({ properties: this.properties, class: this.className, @@ -66,7 +59,8 @@ export default class Updater { new Error("invalid usage: " + this.errors.join(", ")) ); } - const path = this.buildPath(); + + const path = buildObjectsPath(this.id, this.className); return this.client.put(path, this.payload()); }; } From 5b01c87322edf3ba9e96d64e9ab8fbeb346eab74 Mon Sep 17 00:00:00 2001 From: Parker Duckworth Date: Mon, 13 Jun 2022 13:33:11 -0500 Subject: [PATCH 5/7] update object merge to use class name --- data/checker.js | 2 +- data/deleter.js | 2 +- data/getterById.js | 2 +- data/merger.js | 4 +++- 4 files changed, 6 insertions(+), 4 deletions(-) diff --git a/data/checker.js b/data/checker.js index 3daef09..335cfe9 100644 --- a/data/checker.js +++ b/data/checker.js @@ -1,4 +1,4 @@ -import { buildObjectsPath } from "./path" +import { buildObjectsPath } from "./path"; export default class Checker { constructor(client) { diff --git a/data/deleter.js b/data/deleter.js index 4f6364d..79c5d50 100644 --- a/data/deleter.js +++ b/data/deleter.js @@ -1,4 +1,4 @@ -import { buildObjectsPath } from "./path" +import { buildObjectsPath } from "./path"; export default class Deleter { constructor(client) { diff --git a/data/getterById.js b/data/getterById.js index 4c806fc..d35793e 100644 --- a/data/getterById.js +++ b/data/getterById.js @@ -1,4 +1,4 @@ -import { buildObjectsPath } from "./path" +import { buildObjectsPath } from "./path"; export default class GetterById { constructor(client) { diff --git a/data/merger.js b/data/merger.js index 153afe6..3afc97b 100644 --- a/data/merger.js +++ b/data/merger.js @@ -1,4 +1,5 @@ import { isValidStringProperty } from "../validation/string"; +import { buildObjectsPath } from "./path"; export default class Merger { constructor(client) { @@ -55,7 +56,8 @@ export default class Merger { new Error("invalid usage: " + this.errors.join(", ")) ); } - const path = `/objects/${this.id}`; + + const path = buildObjectsPath(this.id, this.className); return this.client.patch(path, this.payload()); }; } From 03003a23ad7ef60e076675489a6f580385bf0e77 Mon Sep 17 00:00:00 2001 From: Parker Duckworth Date: Tue, 14 Jun 2022 17:29:04 -0500 Subject: [PATCH 6/7] remove redundant forward slash --- data/path.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/data/path.js b/data/path.js index ad168dc..8a99623 100644 --- a/data/path.js +++ b/data/path.js @@ -1,7 +1,7 @@ import { isValidStringProperty } from "../validation/string"; export function buildObjectsPath(id, className) { - let path = `/objects`; + let path = `objects`; if (isValidStringProperty(className)) { path = `${path}/${className}`; } From 0a15f486e24df4bdece4b94cffb4146429b9ab25 Mon Sep 17 00:00:00 2001 From: Parker Duckworth Date: Wed, 22 Jun 2022 11:04:54 -0500 Subject: [PATCH 7/7] add fetchVersion to MetaGetter --- misc/journey.test.js | 16 ++++++++++++++++ misc/metaGetter.js | 10 ++++++++++ 2 files changed, 26 insertions(+) diff --git a/misc/journey.test.js b/misc/journey.test.js index 249c7d3..1fd75d9 100644 --- a/misc/journey.test.js +++ b/misc/journey.test.js @@ -70,4 +70,20 @@ describe("misc endpoints", () => { }) .catch((e) => fail("it should not have errord: " + e)); }); + + it("fetches the server version", async () => { + let version = await client.misc.metaGetter() + .do() + .then(res => { + return res.version; + }) + .catch((e) => fail("it should not have errord: " + e)); + + return client.misc.metaGetter() + .fetchVersion() + .then(res => { + expect(res).toEqual(version); + }) + .catch((e) => fail("it should not have errord: " + e)); + }); }); diff --git a/misc/metaGetter.js b/misc/metaGetter.js index c0a7900..7045e3e 100644 --- a/misc/metaGetter.js +++ b/misc/metaGetter.js @@ -6,4 +6,14 @@ export default class MetaGetter { do = () => { return this.client.get("/meta", true); }; + + fetchVersion = () => { + return this.client.get("/meta", true) + .then(res => { + return res.version; + }) + .catch(err => { + return Promise.reject(err); + }); + } }