From 94d8fbf62d5c8fdb72bf7a2568d4603b6213e5fd Mon Sep 17 00:00:00 2001 From: Anselm Date: Thu, 20 Jul 2023 18:26:21 +0100 Subject: [PATCH] Change default set & delete privacy to "private" --- src/coValue.test.ts | 26 +++++++++++++------------- src/coValue.ts | 6 ++---- src/permissions.test.ts | 10 +++++----- 3 files changed, 20 insertions(+), 22 deletions(-) diff --git a/src/coValue.test.ts b/src/coValue.test.ts index bb7906df4..a437a99c8 100644 --- a/src/coValue.test.ts +++ b/src/coValue.test.ts @@ -54,12 +54,12 @@ test("Can insert and delete Map entries in edit()", () => { expect(content.type).toEqual("comap"); content.edit((editable) => { - editable.set("hello", "world"); + editable.set("hello", "world", "trusting"); expect(editable.get("hello")).toEqual("world"); - editable.set("foo", "bar"); + editable.set("foo", "bar", "trusting"); expect(editable.get("foo")).toEqual("bar"); expect([...editable.keys()]).toEqual(["hello", "foo"]); - editable.delete("foo"); + editable.delete("foo", "trusting"); expect(editable.get("foo")).toEqual(undefined); }); }); @@ -88,13 +88,13 @@ test("Can get map entry values at different points in time", () => { content.edit((editable) => { const beforeA = Date.now(); Bun.sleepSync(1); - editable.set("hello", "A"); + editable.set("hello", "A", "trusting"); const beforeB = Date.now(); Bun.sleepSync(1); - editable.set("hello", "B"); + editable.set("hello", "B", "trusting"); const beforeC = Date.now(); Bun.sleepSync(1); - editable.set("hello", "C"); + editable.set("hello", "C", "trusting"); expect(editable.get("hello")).toEqual("C"); expect(editable.getAtTime("hello", Date.now())).toEqual("C"); expect(editable.getAtTime("hello", beforeA)).toEqual(undefined); @@ -125,13 +125,13 @@ test("Can get all historic values of key", () => { expect(content.type).toEqual("comap"); content.edit((editable) => { - editable.set("hello", "A"); + editable.set("hello", "A", "trusting"); const txA = editable.getLastTxID("hello"); - editable.set("hello", "B"); + editable.set("hello", "B", "trusting"); const txB = editable.getLastTxID("hello"); - editable.delete("hello"); + editable.delete("hello", "trusting"); const txDel = editable.getLastTxID("hello"); - editable.set("hello", "C"); + editable.set("hello", "C", "trusting"); const txC = editable.getLastTxID("hello"); expect( editable.getHistory("hello") @@ -183,15 +183,15 @@ test("Can get last tx ID for a key", () => { content.edit((editable) => { expect(editable.getLastTxID("hello")).toEqual(undefined); - editable.set("hello", "A"); + editable.set("hello", "A", "trusting"); const sessionID = editable.getLastTxID("hello")?.sessionID; expect(sessionID && agentIDfromSessionID(sessionID)).toEqual( getAgentID(getAgent(agentCredential)) ); expect(editable.getLastTxID("hello")?.txIndex).toEqual(0); - editable.set("hello", "B"); + editable.set("hello", "B", "trusting"); expect(editable.getLastTxID("hello")?.txIndex).toEqual(1); - editable.set("hello", "C"); + editable.set("hello", "C", "trusting"); expect(editable.getLastTxID("hello")?.txIndex).toEqual(2); }); }); diff --git a/src/coValue.ts b/src/coValue.ts index eb0b12bf7..c04d99801 100644 --- a/src/coValue.ts +++ b/src/coValue.ts @@ -166,8 +166,7 @@ export class WriteableCoMap< V extends JsonValue = M[K], MM extends {[key: string]: JsonValue} = {[KK in K]: M[KK]} > extends CoMap { - // TODO: change default to private - set(key: KK, value: M[KK], privacy: "private" | "trusting" = "trusting"): void { + set(key: KK, value: M[KK], privacy: "private" | "trusting" = "private"): void { this.multiLog.makeTransaction([ { op: "insert", @@ -179,8 +178,7 @@ export class WriteableCoMap< this.fillOpsFromMultilog(); } - // TODO: change default to private - delete(key: K, privacy: "private" | "trusting" = "trusting"): void { + delete(key: K, privacy: "private" | "trusting" = "private"): void { this.multiLog.makeTransaction([ { op: "delete", diff --git a/src/permissions.test.ts b/src/permissions.test.ts index 748e10ada..6586892c4 100644 --- a/src/permissions.test.ts +++ b/src/permissions.test.ts @@ -307,7 +307,7 @@ test("Admins can set team read key and then use it to create and read private tr tx: team.nextTransactionID(), } ); - editable.set("readKey", { keyID: readKeyID, revelation }); + editable.set("readKey", { keyID: readKeyID, revelation }, "trusting"); expect(editable.get("readKey")).toEqual({ keyID: readKeyID, revelation, @@ -354,7 +354,7 @@ test("Admins can set team read key and then writers can use it to create and rea tx: team.nextTransactionID(), } ); - editable.set("readKey", { keyID: readKeyID, revelation }); + editable.set("readKey", { keyID: readKeyID, revelation }, "trusting"); }); const childObject = node.createMultiLog({ @@ -404,7 +404,7 @@ test("Admins can set team read key and then use it to create private transaction tx: team.nextTransactionID(), } ); - editable.set("readKey", { keyID: readKeyID, revelation }); + editable.set("readKey", { keyID: readKeyID, revelation }, "trusting"); }); const childObject = node.createMultiLog({ @@ -446,7 +446,7 @@ test("Admins can set team read key, make a private transaction in an owned objec tx: team.nextTransactionID(), } ); - editable.set("readKey", { keyID: readKeyID, revelation }); + editable.set("readKey", { keyID: readKeyID, revelation }, "trusting"); expect(editable.get("readKey")).toEqual({ keyID: readKeyID, revelation, @@ -483,7 +483,7 @@ test("Admins can set team read key, make a private transaction in an owned objec } ); - editable.set("readKey", { keyID: readKeyID2, revelation }); + editable.set("readKey", { keyID: readKeyID2, revelation }, "trusting"); expect(editable.get("readKey")).toEqual({ keyID: readKeyID2, revelation,