Mentions légales du service

Skip to content
Snippets Groups Projects
Commit 03c35c7d authored by Ludovic Le Frioux's avatar Ludovic Le Frioux
Browse files

updateObject merges CRDTs

parent aaafb000
No related branches found
No related tags found
2 merge requests!48Release v1.1.4,!34Resolve "updateObject should handle CRDT conflict"
Pipeline #197576 passed
...@@ -27,6 +27,7 @@ import express from "express"; ...@@ -27,6 +27,7 @@ import express from "express";
import { makeExecutableSchema } from "graphql-tools"; import { makeExecutableSchema } from "graphql-tools";
import Nano, { MaybeDocument } from "nano"; import Nano, { MaybeDocument } from "nano";
import { OpenAPI, useSofa } from "sofa-api"; import { OpenAPI, useSofa } from "sofa-api";
import { crdtlib } from "@concordant/c-crdtlib";
// http://USERNAME:PASSWORD/URL:PORT // http://USERNAME:PASSWORD/URL:PORT
const dbUrl = process.env.COUCHDB_URL || "http://localhost:5984/"; const dbUrl = process.env.COUCHDB_URL || "http://localhost:5984/";
...@@ -225,7 +226,12 @@ function updateObject(dbName: string, docName: string, document: string) { ...@@ -225,7 +226,12 @@ function updateObject(dbName: string, docName: string, document: string) {
.use(dbName) .use(dbName)
.get(docName) .get(docName)
.then((body) => { .then((body) => {
const newDocument = JSON.parse(document); const CRDT = crdtlib.crdt.DeltaCRDT.Companion.fromJson(document);
const bodyCRDT = crdtlib.crdt.DeltaCRDT.Companion.fromJson(
JSON.stringify(body)
);
bodyCRDT.merge(CRDT);
const newDocument = JSON.parse(bodyCRDT.toJson());
newDocument._rev = body._rev; newDocument._rev = body._rev;
client.db client.db
.use(dbName) .use(dbName)
......
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