Mentions légales du service

Skip to content
Snippets Groups Projects
Commit aaafb000 authored by Yannick Li's avatar Yannick Li
Browse files

Merge branch '28-update-c-crdtlib-to-v0-0-7' into 'dev'

Resolve "Update C-CRDTLib to v0.0.7"

See merge request !29
parents 276cc09c 5b196a21
No related branches found
No related tags found
2 merge requests!48Release v1.1.4,!29Resolve "Update C-CRDTLib to v0.0.7"
Pipeline #195237 passed
...@@ -2559,9 +2559,9 @@ ...@@ -2559,9 +2559,9 @@
} }
}, },
"@concordant/c-crdtlib": { "@concordant/c-crdtlib": {
"version": "0.0.1", "version": "0.0.7-1",
"resolved": "https://gitlab.inria.fr/api/v4/projects/18591/packages/npm/@concordant/c-crdtlib/-/@concordant/c-crdtlib-0.0.1.tgz", "resolved": "https://gitlab.inria.fr/api/v4/projects/18591/packages/npm/@concordant/c-crdtlib/-/@concordant/c-crdtlib-0.0.7-1.tgz",
"integrity": "sha1-BLJO4ekZytccKTpa+xjYWkGfHRg=", "integrity": "sha1-lkVUeMFQAuVhS5pP4gjGdN4vaUs=",
"requires": { "requires": {
"kotlin": "1.4.10", "kotlin": "1.4.10",
"kotlinx-serialization-kotlinx-serialization-core-jsLegacy": "1.0.0", "kotlinx-serialization-kotlinx-serialization-core-jsLegacy": "1.0.0",
......
...@@ -44,7 +44,7 @@ ...@@ -44,7 +44,7 @@
"typescript": "^3.9.7" "typescript": "^3.9.7"
}, },
"dependencies": { "dependencies": {
"@concordant/c-crdtlib": "0.0.1", "@concordant/c-crdtlib": "0.0.7-1",
"@types/uuid": "^3.4.9", "@types/uuid": "^3.4.9",
"apollo-server-express": "^2.19.0", "apollo-server-express": "^2.19.0",
"body-parser": "^1.19.0", "body-parser": "^1.19.0",
......
...@@ -23,34 +23,13 @@ ...@@ -23,34 +23,13 @@
*/ */
import { crdtlib } from "@concordant/c-crdtlib"; import { crdtlib } from "@concordant/c-crdtlib";
export default class CRDTWrapper<T> { export default class CRDTWrapper {
public static wrap<T>(crdt: any): CRDTWrapper<T> { public static wrap(crdt: any): CRDTWrapper {
return new CRDTWrapper(crdt.toJson()); return new CRDTWrapper(crdt.toJson());
} }
public static unwrap<T>(wrapper: CRDTWrapper<T>): any { public static unwrap(wrapper: CRDTWrapper): any {
const crdtType = JSON.parse(wrapper.crdtJson)["_type"]; return crdtlib.crdt.DeltaCRDT.Companion.fromJson(wrapper.crdtJson);
switch (crdtType) {
case "PNCounter":
return crdtlib.crdt.PNCounter.Companion.fromJson(wrapper.crdtJson);
case "MVRegister":
return crdtlib.crdt.MVRegister.Companion.fromJson(wrapper.crdtJson);
case "LWWRegister":
return crdtlib.crdt.LWWRegister.Companion.fromJson(wrapper.crdtJson);
case "Ratchet":
return crdtlib.crdt.Ratchet.Companion.fromJson(wrapper.crdtJson);
case "RGA":
return crdtlib.crdt.RGA.Companion.fromJson(wrapper.crdtJson);
case "LWWMap":
return crdtlib.crdt.LWWMap.Companion.fromJson(wrapper.crdtJson);
case "MVMap":
return crdtlib.crdt.MVMap.Companion.fromJson(wrapper.crdtJson);
case "Map":
return crdtlib.crdt.Map.Companion.fromJson(wrapper.crdtJson);
default:
break;
}
throw new Error("Unknown CRDT type");
} }
constructor(public crdtJson: string) { constructor(public crdtJson: string) {
......
...@@ -94,15 +94,15 @@ describe("Basic usage", () => { ...@@ -94,15 +94,15 @@ describe("Basic usage", () => {
TEST_KEY = uuid(); TEST_KEY = uuid();
const defaultObject = CRDTWrapper.wrap(new crdtlib.crdt.PNCounter()); const defaultObject = CRDTWrapper.wrap(new crdtlib.crdt.PNCounter());
return connection2 return connection2
.get<CRDTWrapper<any>>(TEST_KEY, () => defaultObject) .get<CRDTWrapper>(TEST_KEY, () => defaultObject)
.then(() => connection2.get<CRDTWrapper<any>>(TEST_KEY)) .then(() => connection2.get<CRDTWrapper>(TEST_KEY))
.then((obj: Document<CRDTWrapper<any>>) => { .then((obj: Document<CRDTWrapper>) => {
const newCRDT = CRDTWrapper.unwrap(obj.current()); const newCRDT = CRDTWrapper.unwrap(obj.current());
newCRDT.increment(42, environment1.tick()); newCRDT.increment(42, environment1.tick());
return obj.update(CRDTWrapper.wrap(newCRDT)).save(); return obj.update(CRDTWrapper.wrap(newCRDT)).save();
}) })
.then(() => connection2.get<CRDTWrapper<any>>(TEST_KEY)) .then(() => connection2.get<CRDTWrapper>(TEST_KEY))
.then((obj: Document<CRDTWrapper<any>>) => { .then((obj: Document<CRDTWrapper>) => {
const newCRDT = CRDTWrapper.unwrap(obj.current()); const newCRDT = CRDTWrapper.unwrap(obj.current());
expect(newCRDT.get()).toBe(42); expect(newCRDT.get()).toBe(42);
}) })
...@@ -118,15 +118,15 @@ describe("Basic usage", () => { ...@@ -118,15 +118,15 @@ describe("Basic usage", () => {
const client2DefaultObjectWrapped = CRDTWrapper.wrap( const client2DefaultObjectWrapped = CRDTWrapper.wrap(
new crdtlib.crdt.PNCounter() new crdtlib.crdt.PNCounter()
); );
let remoteObj: Document<CRDTWrapper<any>>; let remoteObj: Document<CRDTWrapper>;
let onlyAfter = false; let onlyAfter = false;
// hooks are handled by client2 // hooks are handled by client2
// need to create hooks for different connections to set different clientIds. // need to create hooks for different connections to set different clientIds.
const hooks: DatabaseHooks = { const hooks: DatabaseHooks = {
conflictHandler: ( conflictHandler: (
obj: Document<CRDTWrapper<any>>, obj: Document<CRDTWrapper>,
objs: Array<Document<CRDTWrapper<any>>> objs: Array<Document<CRDTWrapper>>
) => { ) => {
if (!onlyAfter) { if (!onlyAfter) {
fail("Unexpected conflict trigger"); fail("Unexpected conflict trigger");
...@@ -146,7 +146,7 @@ describe("Basic usage", () => { ...@@ -146,7 +146,7 @@ describe("Basic usage", () => {
connection2.registerHooks(hooks); connection2.registerHooks(hooks);
const sub = connection1.subscribe<CRDTWrapper<any>>(TEST_KEY, { const sub = connection1.subscribe<CRDTWrapper>(TEST_KEY, {
change: (key, newObj) => { change: (key, newObj) => {
connection1.cancel(sub); connection1.cancel(sub);
onlyAfter = true; onlyAfter = true;
...@@ -163,7 +163,7 @@ describe("Basic usage", () => { ...@@ -163,7 +163,7 @@ describe("Basic usage", () => {
.catch((err) => fail(err)); .catch((err) => fail(err));
}) })
.then(() => promiseDelay(null, 200)) .then(() => promiseDelay(null, 200))
.then(() => connection2.get<CRDTWrapper<any>>(TEST_KEY)) .then(() => connection2.get<CRDTWrapper>(TEST_KEY))
.then((obj) => { .then((obj) => {
const unwrapped = CRDTWrapper.unwrap(obj.current()); const unwrapped = CRDTWrapper.unwrap(obj.current());
expect(unwrapped.get()).toBe(42); expect(unwrapped.get()).toBe(42);
...@@ -173,8 +173,8 @@ describe("Basic usage", () => { ...@@ -173,8 +173,8 @@ describe("Basic usage", () => {
}); });
return connection2 return connection2
.get<CRDTWrapper<any>>(TEST_KEY, () => client2DefaultObjectWrapped) .get<CRDTWrapper>(TEST_KEY, () => client2DefaultObjectWrapped)
.then((obj: Document<CRDTWrapper<any>>) => (remoteObj = obj)) .then((obj: Document<CRDTWrapper>) => (remoteObj = obj))
.catch((error) => fail(error)); .catch((error) => fail(error));
}); });
}); });
...@@ -245,13 +245,13 @@ describe("Test offline support with CRDTs", () => { ...@@ -245,13 +245,13 @@ describe("Test offline support with CRDTs", () => {
const client2DefaultObjectWrapped = CRDTWrapper.wrap( const client2DefaultObjectWrapped = CRDTWrapper.wrap(
new crdtlib.crdt.PNCounter() new crdtlib.crdt.PNCounter()
); );
let remoteObj: Document<CRDTWrapper<any>>; let remoteObj: Document<CRDTWrapper>;
let onlyAfter = false; let onlyAfter = false;
const hooks: DatabaseHooks = { const hooks: DatabaseHooks = {
conflictHandler: ( conflictHandler: (
obj: Document<CRDTWrapper<any>>, obj: Document<CRDTWrapper>,
objs: Array<Document<CRDTWrapper<any>>> objs: Array<Document<CRDTWrapper>>
) => { ) => {
if (!onlyAfter) { if (!onlyAfter) {
fail("Unexpected conflict trigger"); fail("Unexpected conflict trigger");
...@@ -270,7 +270,7 @@ describe("Test offline support with CRDTs", () => { ...@@ -270,7 +270,7 @@ describe("Test offline support with CRDTs", () => {
connection2.registerHooks(hooks); connection2.registerHooks(hooks);
const sub = connection1.subscribe<CRDTWrapper<any>>(TEST_KEY, { const sub = connection1.subscribe<CRDTWrapper>(TEST_KEY, {
change: (key, newObj) => { change: (key, newObj) => {
connection1.cancel(sub); connection1.cancel(sub);
onlyAfter = true; onlyAfter = true;
...@@ -288,7 +288,7 @@ describe("Test offline support with CRDTs", () => { ...@@ -288,7 +288,7 @@ describe("Test offline support with CRDTs", () => {
}) })
.then(() => promiseDelay(null, 200)) .then(() => promiseDelay(null, 200))
// .then(() => connection2.goOnline()) // .then(() => connection2.goOnline())
.then(() => connection2.get<CRDTWrapper<any>>(TEST_KEY)) .then(() => connection2.get<CRDTWrapper>(TEST_KEY))
.then((obj) => { .then((obj) => {
const unwrapped = CRDTWrapper.unwrap(obj.current()); const unwrapped = CRDTWrapper.unwrap(obj.current());
expect(unwrapped.get()).toBe(42); expect(unwrapped.get()).toBe(42);
...@@ -298,8 +298,8 @@ describe("Test offline support with CRDTs", () => { ...@@ -298,8 +298,8 @@ describe("Test offline support with CRDTs", () => {
}); });
return connection2 return connection2
.get<CRDTWrapper<any>>(TEST_KEY, () => client2DefaultObjectWrapped) .get<CRDTWrapper>(TEST_KEY, () => client2DefaultObjectWrapped)
.then((obj: Document<CRDTWrapper<any>>) => (remoteObj = obj)) .then((obj: Document<CRDTWrapper>) => (remoteObj = obj))
.then(() => connection2.goOffline()) .then(() => connection2.goOffline())
.catch((error) => fail(error)); .catch((error) => fail(error));
}); });
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment