agoge-pouchdb-plugins
Advanced tools
Comparing version 1.0.18 to 1.0.19
@@ -164,11 +164,13 @@ var CryptoJS = require('crypto-js'); | ||
exports.upsert = async function(doc) { | ||
module.upserted = module.upserted || []; | ||
exports.upsert = async function(doc, byPassSingleton = false) { | ||
module.upserted = module.upserte || []; | ||
var docHash = CryptoJS.MD5(JSON.stringify(doc)).toString(); | ||
if ( ! byPassSingleton ) { | ||
var docHash = CryptoJS.MD5(JSON.stringify(doc)).toString(); | ||
if (module.upserted.includes(docHash)) | ||
return doc; | ||
if (module.upserted.includes(docHash)) | ||
return doc; | ||
module.upserted.push(docHash); | ||
module.upserted.push(docHash); | ||
} | ||
@@ -207,23 +209,4 @@ try { | ||
exports.save = async function(doc) { | ||
var parts = doc._id.split('-'); | ||
doc.type = parts[0]; | ||
doc.id = Number(parts[1]) || parts[1]; | ||
doc.modified = new Date(); | ||
var currentVersionJson = JSON.stringify(doc, null, 4); | ||
if ( ! doc._rev ) { | ||
var docRevNo = 0; | ||
var docRevGuid = 0; | ||
} else { | ||
var docRevisionParts = doc._rev.split('-'); | ||
var docRevNo = docRevisionParts[0]; | ||
var docRevGuid = docRevisionParts[1]; | ||
} | ||
var o = JSON.parse(JSON.stringify(doc)); | ||
o._id = o._id.replace('-', '@') + '.' + (Number(docRevNo)+1); | ||
delete o._rev; | ||
await db.put(o); | ||
var doc = await this.standardizeDoc(doc); | ||
var rev = await this.storeRevision(doc); | ||
var ret = await this.put(doc); | ||
@@ -240,3 +223,3 @@ return ret; | ||
result.rows.forEach(function(row) { | ||
for ( row of result.rows ) { | ||
var x = row.doc; | ||
@@ -250,5 +233,8 @@ | ||
if (before != after) | ||
if (before != after) { | ||
await this.standardizeDoc(x); | ||
await this.storeRevision(x); | ||
mods.push(x); | ||
}); | ||
} | ||
} | ||
@@ -259,1 +245,50 @@ //console.log('Atualizando ' + mods.length + ' documentos'); | ||
exports.standardizeDoc = async function(doc) { | ||
var parts = doc._id.split('-'); | ||
doc.type = parts[0]; | ||
doc.id = Number(parts[1]) || parts[1]; | ||
doc.modified = new Date(); | ||
try { | ||
var meta = await this.get('meta-' + doc.type); | ||
var descKey; | ||
for (key in meta) { | ||
if ( meta[key].type == "description" ) { | ||
var descKey = key; | ||
break; | ||
} | ||
} | ||
if ( descKey ) | ||
doc.desc = doc[descKey]; | ||
else | ||
doc.desc = doc.type.toUpperCase() + ': ' + doc.id; | ||
} catch(err) { | ||
doc.desc = doc.type.toLowerCase() + ': ' + doc.id; | ||
} | ||
return doc; | ||
} | ||
exports.storeRevision = async function(doc) { | ||
var currentVersionJson = JSON.stringify(doc, null, 4); | ||
if ( ! doc._rev ) { | ||
var docRevNo = 0; | ||
var docRevGuid = 0; | ||
} else { | ||
var docRevisionParts = doc._rev.split('-'); | ||
var docRevNo = docRevisionParts[0]; | ||
var docRevGuid = docRevisionParts[1]; | ||
} | ||
var o = JSON.parse(JSON.stringify(doc)); | ||
o._id = o._id.replace('-', '@') + '.' + (Number(docRevNo)+1); | ||
delete o._rev; | ||
var ret = await db.upsert(o); | ||
return ret; | ||
} |
{ | ||
"name": "agoge-pouchdb-plugins", | ||
"version": "1.0.18", | ||
"version": "1.0.19", | ||
"description": "My personal plugin functions to pouchdb-couchdb", | ||
@@ -5,0 +5,0 @@ "main": "agoge-pouchdb-plugins.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
6601
216