diff --git a/deno.json b/deno.json index 76547c1..ab3a2df 100644 --- a/deno.json +++ b/deno.json @@ -4,7 +4,7 @@ "fmt:fix": "deno fmt library/ tests/ www/ docs/", "fmt:check": "deno fmt --check library/ tests/ www/ docs/", "lint": "deno lint library/ tests/ www/ docs/", - "test": "deno test -A ./tests -- --nolog", + "test": "deno test -A --parallel ./tests -- --nolog", "dnt": "deno run -A --importmap ./scripts/dnt_import_map.json ./scripts/dnt.ts", "generate_api": "deno run -A ./scripts/generate_api.ts" }, diff --git a/library/lens/update_helper.ts b/library/lens/update_helper.ts index 3a5964d..6154522 100644 --- a/library/lens/update_helper.ts +++ b/library/lens/update_helper.ts @@ -51,7 +51,7 @@ export class UpdateHelper { } if (property["@array"]) { - this.processArrayProperty(entity, propertyName, value); + this.processArrayProperty(entity, propertyName, value, property); } else { this.processSingleProperty(entity, propertyName, value, property); } @@ -93,10 +93,11 @@ export class UpdateHelper { entity: Entity, propertyName: string, propertyValue: unknown, + property: ExpandedProperty, ) { const config = this.parseArrayUpdateConfig(propertyValue); if (config.$set) { - this.processArraySet(entity, propertyName, config.$set); + this.processArraySet(entity, propertyName, config.$set, property); } else { this.processArrayAddRemove( entity, @@ -111,6 +112,7 @@ export class UpdateHelper { entity: Entity, propertyName: string, propertyValue: unknown[], + property: ExpandedProperty, ) { const deletePattern = { $id: entity.$id, @@ -118,7 +120,11 @@ export class UpdateHelper { }; const quadsToDelete = this.encode(deletePattern); this.deleteQuads.push(...quadsToDelete); - this.whereQuads.push(...quadsToDelete); + if (property["@optional"]) { + this.whereQuads.push(OPTIONAL`${quadsToDelete}`); + } else { + this.whereQuads.push(...quadsToDelete); + } const insertPattern = { $id: entity.$id, diff --git a/tests/e2e/dbpedia.test.ts b/tests/e2e/dbpedia.test.ts index 87da48f..dd8ac69 100644 --- a/tests/e2e/dbpedia.test.ts +++ b/tests/e2e/dbpedia.test.ts @@ -37,7 +37,7 @@ const favouriteActors = [ "http://dbpedia.org/resource/Gal_Gadot", ]; -Deno.test("E2E / DBpedia / Query single remote entity", async () => { +Deno.test.ignore("E2E / DBpedia / Query single remote entity", async () => { const BradId = "http://dbpedia.org/resource/Brad_Pitt"; const BradName = "Brad Pitt"; const actor = await Actors.findByIri(favouriteActors[0]); @@ -46,18 +46,24 @@ Deno.test("E2E / DBpedia / Query single remote entity", async () => { assert(actor.name === BradName); }); -Deno.test("E2E / DBpedia / Query multiple specific remote entities", async () => { - const actors = await Actors.findByIris(favouriteActors); - assert(actors); - assert(actors.length === favouriteActors.length); -}); +Deno.test.ignore( + "E2E / DBpedia / Query multiple specific remote entities", + async () => { + const actors = await Actors.findByIris(favouriteActors); + assert(actors); + assert(actors.length === favouriteActors.length); + }, +); -Deno.test("E2E / DBpedia / Query multiple random remote entities", async () => { - const actors = await Actors.find({ take: 7 }); - assert(actors.length == 7); -}); +Deno.test.ignore( + "E2E / DBpedia / Query multiple random remote entities", + async () => { + const actors = await Actors.find({ take: 7 }); + assert(actors.length == 7); + }, +); -Deno.test("E2E / DBpedia / Query count", async () => { +Deno.test.ignore("E2E / DBpedia / Query count", async () => { const count = await Actors.count({ max: 100 }); assert(count > 0); }); diff --git a/tests/e2e/optional.test.ts b/tests/e2e/optional.test.ts index efe68c6..fa9a59b 100644 --- a/tests/e2e/optional.test.ts +++ b/tests/e2e/optional.test.ts @@ -60,6 +60,62 @@ Deno.test("E2E / Optional / Insert with optional properties", async () => { `); }); +Deno.test("E2E / Optional / Set to empty optional array property", async () => { + const { Entities, assertStore } = init(); + + await Entities.insert({ + $id: x.Entity, + requiredString: "required", + optionalArray: [], + }); + + assertStore(` + x:Entity + a x:Entity ; + x:requiredString "required" . + `); + + await Entities.update({ + $id: x.Entity, + optionalArray: { $set: ["setArray"] }, + }); + + assertStore(` + x:Entity + a x:Entity ; + x:requiredString "required" ; + x:optionalArray "setArray" . + `); +}); + +Deno.test("E2E / Optional / Add to empty optional array property", async () => { + const { Entities, assertStore } = init(); + + await Entities.insert({ + $id: x.Entity, + requiredString: "required", + optionalArray: [], + }); + + assertStore(` + x:Entity + a x:Entity ; + x:requiredString "required" . + `); + + await Entities.update({ + $id: x.Entity, + optionalArray: { $add: ["addArray"] }, + }); + + assertStore(` + x:Entity + a x:Entity ; + x:requiredString "required" ; + x:optionalArray "addArray" . + `); +}); + Deno.test("E2E / Optional / Unset optional existing property", async () => { const { Entities, assertStore } = init();