Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function creating1 (primKey, obj, transaction) {
// You may do additional database operations using given transaction object.
// You may also modify given obj
// You may set this.onsuccess = function (primKey){}. Called when autoincremented key is known.
// You may set this.onerror = callback if create operation fails.
// If returning any value other than undefined, the returned value will be used as primary key
transLog.push({trans: transaction, current: Dexie.currentTransaction});
let op = {
op: "create",
key: primKey,
value: Dexie.deepClone(obj)
};
opLog.push(op);
if (watchSuccess) {
this.onsuccess = primKey => successLog.push(primKey);
}
if (watchError) {
this.onerror = e => errorLog.push(e);
}
if (deliverKeys[opLog.length-1])
return deliverKeys[opLog.length-1];
}
function updating2 (modifications, primKey, obj, transaction) {
// You may use transaction to do additional database operations.
// You may not do any modifications on any of the given arguments.
// You may set this.onsuccess = function (updatedObj){} when update operation completes.
// You may set this.onerror = callback if update operation fails.
// If you want to make additional modifications, return another modifications object
// containing the additional or overridden modifications to make. Any returned
// object will be merged to the given modifications object.
let op = {
op: "update",
key: primKey,
obj: Dexie.deepClone(obj),
mods: Dexie.shallowClone(modifications)
};
opLog2.push(op);
if (watchSuccess) {
this.onsuccess = (updatedObj) => successLog2.push(updatedObj);
}
if (watchError) {
this.onerror = e => errorLog2.push(e);
}
if (deliverModifications2) return deliverModifications2;
}
function updating1 (modifications, primKey, obj, transaction) {
// You may use transaction to do additional database operations.
// You may not do any modifications on any of the given arguments.
// You may set this.onsuccess = function (updatedObj){} when update operation completes.
// You may set this.onerror = callback if update operation fails.
// If you want to make additional modifications, return another modifications object
// containing the additional or overridden modifications to make. Any returned
// object will be merged to the given modifications object.
transLog.push({trans: transaction, current: Dexie.currentTransaction});
let op = {
op: "update",
key: primKey,
obj: Dexie.deepClone(obj),
mods: Dexie.shallowClone(modifications),
};
opLog.push(op);
if (watchSuccess) {
this.onsuccess = (updatedObj) => successLog.push(updatedObj);
}
if (watchError) {
this.onerror = e => errorLog.push(e);
}
if (deliverModifications) return deliverModifications;
}
table.hook('updating').subscribe(function(mods, primKey, oldObj, trans) {
///
// mods may contain property paths with undefined as value if the property
// is being deleted. Since we cannot persist undefined we need to act
// like those changes is setting the value to null instead.
var modsWithoutUndefined = {};
// As of current Dexie version (1.0.3) hook may be called even if it wouldnt really change.
// Therefore we may do that kind of optimization here - to not add change entries if
// there's nothing to change.
var anythingChanged = false;
var newObj = Dexie.deepClone(oldObj);
for (var propPath in mods) {
var mod = mods[propPath];
if (typeof mod === 'undefined') {
Dexie.delByKeyPath(newObj, propPath);
modsWithoutUndefined[propPath] = null; // Null is as close we could come to deleting a property when not allowing undefined.
anythingChanged = true;
} else {
var currentValue = Dexie.getByKeyPath(oldObj, propPath);
if (mod !== currentValue && JSON.stringify(mod) !== JSON.stringify(currentValue)) {
Dexie.setByKeyPath(newObj, propPath, mod);
modsWithoutUndefined[propPath] = mod;
anythingChanged = true;
}
}
}
if (anythingChanged) {
function combineUpdateAndUpdate(prevChange, nextChange) {
var clonedChange = Dexie.deepClone(prevChange); // Clone object before modifying since the earlier change in db.changes[] would otherwise be altered.
Object.keys(nextChange.mods).forEach(function (keyPath) {
// If prev-change was changing a parent path of this keyPath, we must update the parent path rather than adding this keyPath
var hadParentPath = false;
Object.keys(prevChange.mods).filter(function (parentPath) { return keyPath.indexOf(parentPath + '.') === 0; }).forEach(function (parentPath) {
setByKeyPath(clonedChange[parentPath], keyPath.substr(parentPath.length + 1), nextChange.mods[keyPath]);
hadParentPath = true;
});
if (!hadParentPath) {
// Add or replace this keyPath and its new value
clonedChange.mods[keyPath] = nextChange.mods[keyPath];
}
// In case prevChange contained sub-paths to the new keyPath, we must make sure that those sub-paths are removed since
// we must mimic what would happen if applying the two changes after each other:
Object.keys(prevChange.mods).filter(function (subPath) { return subPath.indexOf(keyPath + '.') === 0; }).forEach(function (subPath) {
delete clonedChange[subPath];
});
table.hook('updating').subscribe(function (mods, primKey, oldObj, trans) {
///
// mods may contain property paths with undefined as value if the property
// is being deleted. Since we cannot persist undefined we need to act
// like those changes is setting the value to null instead.
var modsWithoutUndefined = {};
// As of current Dexie version (1.0.3) hook may be called even if it wouldnt really change.
// Therefore we may do that kind of optimization here - to not add change entries if
// there's nothing to change.
var anythingChanged = false;
var newObj = Dexie.deepClone(oldObj);
for (var propPath in mods) {
var mod = mods[propPath];
if (typeof mod === 'undefined') {
Dexie.delByKeyPath(newObj, propPath);
modsWithoutUndefined[propPath] = null; // Null is as close we could come to deleting a property when not allowing undefined.
anythingChanged = true;
} else {
var currentValue = Dexie.getByKeyPath(oldObj, propPath);
if (mod !== currentValue && JSON.stringify(mod) !== JSON.stringify(currentValue)) {
Dexie.setByKeyPath(newObj, propPath, mod);
modsWithoutUndefined[propPath] = mod;
anythingChanged = true;
}
}
}
if (anythingChanged) {
table.hook('updating').subscribe(function(mods, primKey, oldObj, trans) {
///
// mods may contain property paths with undefined as value if the property
// is being deleted. Since we cannot persist undefined we need to act
// like those changes is setting the value to null instead.
var modsWithoutUndefined = {};
// As of current Dexie version (1.0.3) hook may be called even if it wouldnt really change.
// Therefore we may do that kind of optimization here - to not add change entries if
// there's nothing to change.
var anythingChanged = false;
var newObj = Dexie.deepClone(oldObj);
for (var propPath in mods) {
var mod = mods[propPath];
if (typeof mod === 'undefined') {
Dexie.delByKeyPath(newObj, propPath);
modsWithoutUndefined[propPath] = null; // Null is as close we could come to deleting a property when not allowing undefined.
anythingChanged = true;
} else {
var currentValue = Dexie.getByKeyPath(oldObj, propPath);
if (mod !== currentValue && JSON.stringify(mod) !== JSON.stringify(currentValue)) {
Dexie.setByKeyPath(newObj, propPath, mod);
modsWithoutUndefined[propPath] = mod;
anythingChanged = true;
}
}
}
if (anythingChanged) {
function creating2 (primKey, obj, transaction) {
let op = {
op: "create",
key: primKey,
value: Dexie.deepClone(obj)
};
opLog2.push(op);
if (watchSuccess) {
this.onsuccess = primKey => successLog2.push(primKey);
}
if (watchError) {
this.onerror = e => errorLog2.push(e);
}
if (deliverKeys2[opLog2.length-1])
return deliverKeys2[opLog2.length-1];
}
function reading2 (obj) {
opLog2.push({
op: "read",
obj: Dexie.deepClone(obj)
});
return obj.theObject;
}
function reading1 (obj) {
opLog.push({
op: "read",
obj: Dexie.deepClone(obj)
});
return {theObject: obj};
}