Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const upsertWithFields = async (json, fields: string[] = []) => {
json = clone(json);
const primary = json[$this.schema.primaryPath];
if (!primary) {
throw new Error("RxCollection.upsertWithFields() does not work without primary");
}
const existing = await $this.findOne(primary).exec();
if (existing) {
for (let prop in json) {
if (json.hasOwnProperty(prop) && fields.indexOf(prop) < 0) {
delete json[prop];
}
}
const data = existing._data;
json = Object.assign({}, data, json);
json._rev = existing._rev;
function recursiveDeepCopy(o: T): T {
if (!o) return o;
return deepClone(o, false);
}
export const clone = recursiveDeepCopy;
function recursiveDeepCopy(o) {
if (!o) return o;
return deepClone(o, false);
}
const upsertExcludeFields = async (json, fields = []) => {
json = clone(json);
const primary = json[$this.schema.primaryPath];
if (!primary) {
throw new Error("RxCollection.upsertExcludeFields() does not work without primary");
}
const existing = await $this.findOne(primary).exec();
if (existing) {
fields.forEach(field => {
delete json[field];
});
const data = Object.assign({}, existing._data, json);
data._rev = existing._rev;
existing._data = data;
await existing.save();
return existing;
} else {