Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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) {
var change = {
source: trans.source || null, // If a "source" is marked on the transaction, store it. Useful for observers that want to ignore their own changes.
table: tableName,
key: primKey,
type: UPDATE,
mods: modsWithoutUndefined,
oldObj: oldObj,
obj: newObj
};
var promise = db._changes.add(change); // Just so we get the correct revision order of the update...
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) {
var change = {
source: trans.source || null, // If a "source" is marked on the transaction, store it. Useful for observers that want to ignore their own changes.
table: tableName,
key: primKey,
type: UPDATE,
mods: modsWithoutUndefined,
oldObj: oldObj,
obj: newObj
};
var promise = trans.tables._changes.add(change); // Just so we get the correct revision order of the update...
table.hook('creating').subscribe(function(primKey, obj, trans) {
///
var rv = undefined;
if (primKey === undefined && table.schema.primKey.uuid) {
primKey = rv = Observable.createUUID();
if (table.schema.primKey.keyPath) {
Dexie.setByKeyPath(obj, table.schema.primKey.keyPath, primKey);
}
}
var change = {
source: trans.source || null, // If a "source" is marked on the transaction, store it. Useful for observers that want to ignore their own changes.
table: tableName,
key: primKey === undefined ? null : primKey,
type: CREATE,
obj: obj
};
var promise = trans.tables._changes.add(change).then(function(rev) {
trans._lastWrittenRevision = Math.max(trans._lastWrittenRevision, rev);
return rev;
});
table.hook('creating').subscribe(function (primKey, obj, trans) {
///
var rv = undefined;
if (primKey === undefined && table.schema.primKey.uuid) {
primKey = rv = Observable.createUUID();
if (table.schema.primKey.keyPath) {
Dexie.setByKeyPath(obj, table.schema.primKey.keyPath, primKey);
}
}
var change = {
source: trans.source || null, // If a "source" is marked on the transaction, store it. Useful for observers that want to ignore their own changes.
table: tableName,
key: primKey === undefined ? null : primKey,
type: CREATE,
obj: obj
};
var promise = trans.tables._changes.add(change).then(function (rev) {
trans._lastWrittenRevision = Math.max(trans._lastWrittenRevision, rev);
return rev;
});
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) {
var change = {
source: trans.source || null, // If a "source" is marked on the transaction, store it. Useful for observers that want to ignore their own changes.
table: tableName,
key: primKey,
type: UPDATE,
mods: modsWithoutUndefined,
oldObj: oldObj,
obj: newObj
};
var promise = trans.tables._changes.add(change); // Just so we get the correct revision order of the update...
await tx.settings.toCollection().modify((setting, ref) => {
const c = configMap.find(c => c.settingsKey === setting.key)
if (c) {
try {
const defaultValue = Dexie.getByKeyPath(config, c.configPath)
let value = Dexie.getByKeyPath(setting, c.settingsPath)
// Apply value mapper if there is one.
if (c.configMutator) {
value = c.configMutator(value)
}
// If the value differes from the default, save it into the config.
if (value && value !== defaultValue) {
Dexie.setByKeyPath(newConfig, c.configPath, value)
}
// Finally, delete the old setting.
delete ref.value
} catch (e) {
// If there was a problem migrating the old setting just delete the setting altogether.
delete ref.value
}
}
})
// Save the migrated config overrides.
Object.keys(modifications).forEach(function(keyPath) {
Dexie.setByKeyPath(obj, keyPath, modifications[keyPath]);
});
return obj;
Object.keys(nodeModificationsOnAck).forEach(function (keyPath) {
Dexie.setByKeyPath(node, keyPath, nodeModificationsOnAck[keyPath]);
});
node.save().catch('DatabaseClosedError', ()=> {
Object.keys(nodeModificationsOnAck).forEach(function(keyPath) {
Dexie.setByKeyPath(node, keyPath, nodeModificationsOnAck[keyPath]);
});
node.save();