Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export function relatedRecordsReplaced(
schema: Schema,
record: RecordIdentity,
relationship: string,
relatedRecords: RecordIdentity[],
currentRelatedRecords?: RecordIdentity[]
): RecordOperation[] {
const ops: RecordOperation[] = [];
const relationshipDef = schema.getRelationship(record.type, relationship);
let addedRecords: RecordIdentity[];
if (currentRelatedRecords && currentRelatedRecords.length > 0) {
let removedRecords = uniqueRecordIdentities(
currentRelatedRecords,
relatedRecords
);
Array.prototype.push.apply(
ops,
removeRelatedRecordsOps(schema, record, relationshipDef, removedRecords)
);
addedRecords = uniqueRecordIdentities(
relatedRecords,
currentRelatedRecords
);
} else {
addedRecords = relatedRecords;
}
const ops: RecordOperation[] = [];
const relationshipDef = schema.getRelationship(record.type, relationship);
let addedRecords: RecordIdentity[];
if (currentRelatedRecords && currentRelatedRecords.length > 0) {
let removedRecords = uniqueRecordIdentities(
currentRelatedRecords,
relatedRecords
);
Array.prototype.push.apply(
ops,
removeRelatedRecordsOps(schema, record, relationshipDef, removedRecords)
);
addedRecords = uniqueRecordIdentities(
relatedRecords,
currentRelatedRecords
);
} else {
addedRecords = relatedRecords;
}
Array.prototype.push.apply(
ops,
addRelatedRecordsOps(schema, record, relationshipDef, addedRecords)
);
return ops;
}