From e5e9d769ab819a35e64266ae67fb70f8d98fca17 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BD=99=E6=B5=A9=E5=9D=9A?= Date: Tue, 22 Dec 2020 22:43:04 +0800 Subject: [PATCH 1/4] subscribe return meta --- lib/agent.js | 3 ++- lib/backend.js | 2 +- lib/client/doc.js | 3 +++ 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/agent.js b/lib/agent.js index 1154b9b4c..b059d008c 100644 --- a/lib/agent.js +++ b/lib/agent.js @@ -557,7 +557,8 @@ function getMapResult(snapshotMap) { function getSnapshotData(snapshot) { var data = { v: snapshot.v, - data: snapshot.data + data: snapshot.data, + m: snapshot.m }; if (types.defaultType !== types.map[snapshot.type]) { data.type = snapshot.type; diff --git a/lib/backend.js b/lib/backend.js index 923dc33b3..e4707fbe8 100644 --- a/lib/backend.js +++ b/lib/backend.js @@ -492,7 +492,7 @@ Backend.prototype.subscribe = function(agent, index, id, version, options, callb if (version == null) { // Subscribing from null means that the agent doesn't have a document // and needs to fetch it as well as subscribing - backend.fetch(agent, index, id, function(err, snapshot) { + backend.fetch(agent, index, id, {snapshotOptions: {metadata: true}}, function(err, snapshot) { if (err) { stream.destroy(); return callback(err); diff --git a/lib/client/doc.js b/lib/client/doc.js index ac6b7881f..c95c1d0a1 100644 --- a/lib/client/doc.js +++ b/lib/client/doc.js @@ -214,6 +214,9 @@ Doc.prototype.ingestSnapshot = function(snapshot, callback) { this.data = (this.type && this.type.deserialize) ? this.type.deserialize(snapshot.data) : snapshot.data; + if (snapshot.m) { + this.meta = snapshot.m; + } this.emit('load'); callback && callback(); }; From c226ccd89f83b2a229262e206818fca8f87870b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BD=99=E6=B5=A9=E5=9D=9A?= Date: Tue, 22 Dec 2020 22:57:17 +0800 Subject: [PATCH 2/4] fixed test --- lib/agent.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/agent.js b/lib/agent.js index b059d008c..313d2ff45 100644 --- a/lib/agent.js +++ b/lib/agent.js @@ -557,9 +557,11 @@ function getMapResult(snapshotMap) { function getSnapshotData(snapshot) { var data = { v: snapshot.v, - data: snapshot.data, - m: snapshot.m + data: snapshot.data }; + if (snapshot.m) { + data.m = snapshot.m; + } if (types.defaultType !== types.map[snapshot.type]) { data.type = snapshot.type; } From 1fe9959374f19b7d3fc833e7fa94e98c9e7b5b23 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BD=99=E6=B5=A9=E5=9D=9A?= Date: Fri, 29 Jan 2021 21:21:57 +0800 Subject: [PATCH 3/4] =?UTF-8?q?feat-jan-op=E5=A2=9E=E5=8A=A0=E7=89=88?= =?UTF-8?q?=E6=9C=AC=E8=BF=94=E5=9B=9E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/client/doc.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/client/doc.js b/lib/client/doc.js index c95c1d0a1..f13e922d4 100644 --- a/lib/client/doc.js +++ b/lib/client/doc.js @@ -583,7 +583,7 @@ Doc.prototype._otApply = function(op, source) { 'Cannot apply op to uncreated document. ' + this.collection + '.' + this.id ); } - + var extra = {v: source ? this.version : op.v, serverTime: op.serverTime}; // NB: If we need to add another argument to this event, we should consider // the fact that the 'op' event has op.src as its 3rd argument this.emit('before op batch', op.op, source); @@ -621,7 +621,7 @@ Doc.prototype._otApply = function(op, source) { this.data = this.type.apply(this.data, componentOp.op); this.emit('op', componentOp.op, source, op.src); } - this.emit('op batch', op.op, source); + this.emit('op batch', op.op, source, extra); // Pop whatever was submitted since we started applying this op this._popApplyStack(stackLength); return; @@ -638,7 +638,7 @@ Doc.prototype._otApply = function(op, source) { // For ops from other clients, this will be after the op has been // committed to the database and published this.emit('op', op.op, source, op.src); - this.emit('op batch', op.op, source); + this.emit('op batch', op.op, source, extra); return; } From 99a73b19b002ee94bbff1b86a848f97671cbd64a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BD=99=E6=B5=A9=E5=9D=9A?= Date: Mon, 8 Feb 2021 17:40:20 +0800 Subject: [PATCH 4/4] =?UTF-8?q?Revert=20"feat-jan-op=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E7=89=88=E6=9C=AC=E8=BF=94=E5=9B=9E"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit 1fe99593 返回版本信息有误,本地提交需要在提交callback里获取 --- lib/client/doc.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/client/doc.js b/lib/client/doc.js index f13e922d4..c95c1d0a1 100644 --- a/lib/client/doc.js +++ b/lib/client/doc.js @@ -583,7 +583,7 @@ Doc.prototype._otApply = function(op, source) { 'Cannot apply op to uncreated document. ' + this.collection + '.' + this.id ); } - var extra = {v: source ? this.version : op.v, serverTime: op.serverTime}; + // NB: If we need to add another argument to this event, we should consider // the fact that the 'op' event has op.src as its 3rd argument this.emit('before op batch', op.op, source); @@ -621,7 +621,7 @@ Doc.prototype._otApply = function(op, source) { this.data = this.type.apply(this.data, componentOp.op); this.emit('op', componentOp.op, source, op.src); } - this.emit('op batch', op.op, source, extra); + this.emit('op batch', op.op, source); // Pop whatever was submitted since we started applying this op this._popApplyStack(stackLength); return; @@ -638,7 +638,7 @@ Doc.prototype._otApply = function(op, source) { // For ops from other clients, this will be after the op has been // committed to the database and published this.emit('op', op.op, source, op.src); - this.emit('op batch', op.op, source, extra); + this.emit('op batch', op.op, source); return; }