Skip to content

Commit

Permalink
feat: released new update for batch commits to add writeTime
Browse files Browse the repository at this point in the history
  • Loading branch information
agrohs committed Jul 9, 2024
1 parent e26a9c5 commit 1a41acf
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 16 deletions.
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "firebase-mock",
"version": "2.3.5",
"version": "2.3.6",
"homepage": "https://github.com/soumak77/firebase-mock",
"authors": [
"Kato"
Expand Down
29 changes: 16 additions & 13 deletions browser/firebasemock.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/** firebase-mock - v2.3.5
/** firebase-mock - v2.3.6
https://github.com/dmurvihill/firebase-mock
* Copyright (c) 2016 Brian Soumakian
* License: MIT */
Expand Down Expand Up @@ -56696,10 +56696,11 @@ MockFirestoreDocument.prototype.create = function (data, callback) {
};

MockFirestoreDocument.prototype.set = function (data, opts, callback) {
const writeTime = new Timestamp(Math.floor(Date.now() / 1000), 0);
var serverTime = utils.getServerTime();
var result = new WriteResult(Timestamp.fromMillis(serverTime));
var _opts = _.assign({}, { merge: false }, opts);
if (_opts.merge) {
return this._update(data, { setMerge: true }, callback).then(() => ({ writeTime }));
return this._update(data, { setMerge: true }, callback).then(() => (result));
}
var err = this._nextErr('set');
data = _.cloneDeep(data);
Expand All @@ -56709,7 +56710,7 @@ MockFirestoreDocument.prototype.set = function (data, opts, callback) {
if (err === null) {
data = utils.removeEmptyFirestoreProperties(data, utils.getServerTime());
self._dataChanged(data);
resolve({ writeTime });
resolve(result);
} else {
if (callback) {
callback(err);
Expand Down Expand Up @@ -57367,6 +57368,7 @@ var FieldValue = require('./firestore-field-value');
var Queue = require('./queue').Queue;
var Timestamp = require('./timestamp');
var utils = require('./utils');
var WriteResult = require('./write-result');
var validate = require('./validators');
var DEFAULT_PATH = 'Mock://';

Expand Down Expand Up @@ -57446,7 +57448,8 @@ MockFirestore.prototype.runTransaction = function(transFunc) {
var processBatchQueue = function (queue) {
return Promise.all(_.map(queue, (queueItem) => {
return new Promise((resolve) => {
const writeTime = new Timestamp(Math.floor(Date.now() / 1000), 0);
var serverTime = utils.getServerTime();
var result = new WriteResult(Timestamp.fromMillis(serverTime));
var method = queueItem.method;
var doc = queueItem.args[0];
var data = queueItem.args[1];
Expand All @@ -57455,20 +57458,20 @@ var processBatchQueue = function (queue) {
if (method === 'set') {
if (opts && opts.merge === true) {
return doc._update(data, { setMerge: true })
.then(resolve({ writeTime }));
.then(resolve(result));
} else {
return doc.set(data)
.then(resolve({ writeTime }));
.then(resolve(result));
}
} else if (method === 'create') {
return doc.create(data)
.then(resolve({ writeTime }));
.then(resolve(result));
} else if (method === 'update') {
return doc.update(data)
.then(resolve({ writeTime }));
.then(resolve(result));
} else if (method === 'delete') {
return doc.delete()
.then(resolve({ writeTime }));
.then(resolve(result));
}

return resolve();
Expand Down Expand Up @@ -57497,11 +57500,11 @@ MockFirestore.prototype.batch = function () {
return batch;
},
commit: function() {
const commited = processBatchQueue(queue);
const committed = processBatchQueue(queue);
if (self.queue.events.length > 0) {
self.flush();
}
return Promise.resolve(commited);
return Promise.resolve(committed);
}
};
return batch;
Expand Down Expand Up @@ -57592,7 +57595,7 @@ function extractName(path) {

module.exports = MockFirestore;

},{"./firestore-collection":84,"./firestore-document":87,"./firestore-field-path":88,"./firestore-field-value":89,"./lodash":93,"./queue":96,"./timestamp":104,"./utils":106,"./validators":107,"assert":1,"rsvp":74}],93:[function(require,module,exports){
},{"./firestore-collection":84,"./firestore-document":87,"./firestore-field-path":88,"./firestore-field-value":89,"./lodash":93,"./queue":96,"./timestamp":104,"./utils":106,"./validators":107,"./write-result":108,"assert":1,"rsvp":74}],93:[function(require,module,exports){
module.exports = {
assign: require('lodash.assign'),
bind: require('lodash.bind'),
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "firebase-mock",
"version": "2.3.5",
"version": "2.3.6",
"description": "Firebase mock library for writing unit tests",
"scripts": {
"hmm": "gulp hmm",
Expand Down
2 changes: 1 addition & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@


"@sinonjs/commons@^1", "@sinonjs/commons@^1.3.0", "@sinonjs/commons@^1.7.0":
version "2.3.5"
version "2.3.6"
resolved "https://registry.yarnpkg.com/@sinonjs/commons/-/commons-1.8.6.tgz#80c516a4dc264c2a69115e7578d62581ff455ed9"
integrity sha512-Ky+XkAkqPZSm3NLBeUng77EBQl3cmeJhITaGHdYH8kjVB+aun3S4XBRti2zt17mtt0mIUDiNxYeoJm6drVvBJQ==
dependencies:
Expand Down

0 comments on commit 1a41acf

Please sign in to comment.