Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
public diff(state, definition) {
const response = {
certificates: [],
importFromKeystore: []
};
if (state && definition && state.certificates && definition.certificates) {
for (const cert of definition.certificates) {
const existingCert = state.certificates.find(
c => c.name === cert.DeveloperName
);
if (existingCert) {
// move id from state to definition to be retained and used
cert.id = existingCert.id;
delete existingCert.id;
}
response.certificates.push(jsonMergePatch.generate(existingCert, cert));
}
}
if (definition && definition.importFromKeystore) {
response.importFromKeystore = definition.importFromKeystore;
}
return removeEmptyValues(response);
}
onSubmit={(value: CronWorkflow) => {
// magic - we get the latest from the server and then apply the changes from the rendered version to this
const original = props.cronWorkflow;
const patch = jsonMergePatch.generate(original, value) || {};
return services.cronWorkflows
.get(props.cronWorkflow.metadata.name, props.cronWorkflow.metadata.namespace)
.then(latest => jsonMergePatch.apply(latest, patch))
.then(patched => services.cronWorkflows.update(patched, props.cronWorkflow.metadata.name, props.cronWorkflow.metadata.namespace))
.then(updated => props.onChange(updated));
}}
/>
if (state && definition) {
for (const availableCustomObject of definition) {
const oldCustomObject = state.find(customObject => {
if (availableCustomObject.namespacePrefix === undefined) {
availableCustomObject.namespacePrefix = null;
}
return (
customObject.name === availableCustomObject.name &&
customObject.namespacePrefix ===
availableCustomObject.namespacePrefix
);
});
// move id of existing object to new object to be retained and used
availableCustomObject.id = oldCustomObject.id;
delete oldCustomObject.id;
const diff = jsonMergePatch.generate(
oldCustomObject,
availableCustomObject
);
if (diff.available !== undefined) {
response.push(diff);
}
}
}
return response;
}
// apply read-only values
source = source || {};
destination.id = source.id || UUID();
destination.last_used = source.last_used || null;
destination.disabled = source.disabled || false;
destination.created = source.created || new Date().toISOString();
// always assume the item is modified
destination.modified = new Date().toISOString();
// generate history patch (to go backward)
let history = [];
if (source && source.entry) {
history = (source.history || []).slice(0, HISTORY_MAX - 1);
let dstEntry = destination.entry,
srcEntry = source.entry;
let patch = jsonmergepatch.generate(dstEntry, srcEntry);
if (undefined !== patch) {
history.unshift({
created: new Date().toISOString(),
patch
});
}
}
destination.history = history;
return destination;
}
const membershipResponse = [];
for (const member of portal.portalProfileMemberships) {
// move id of existing member to new member to be retained and used
const sourceMember = sourcePortal.portalProfileMemberships.find(
m => m.name === member.name
);
if (sourceMember) {
member.id = sourceMember.id;
delete sourceMember.id;
} else {
throw new Error(
`Could not find portal profile membership for '${member.name}'`
);
}
const membershipDiff = semanticallyCleanObject(
removeNullValues(jsonMergePatch.generate(sourceMember, member))
);
if (membershipDiff) {
membershipResponse.push(membershipDiff);
}
}
delete sourcePortal.portalProfileMemberships;
delete portal.portalProfileMemberships;
if (membershipResponse.length) {
portal['portalProfileMemberships'] = membershipResponse;
}
}
const diff = semanticallyCleanObject(
removeNullValues(jsonMergePatch.generate(sourcePortal, portal))
);
if (diff) {
response.push(diff);
const response = [];
for (const stateItem of state) {
const targetMatch = definition.find(
item =>
multimatch(
[stateItem.name],
Array.isArray(item.name) ? item.name : [item.name]
).length > 0
);
if (targetMatch) {
const newDefinition = Object.assign({}, targetMatch);
// replace the pattern by the real name
newDefinition.name = stateItem.name;
// copy comment to state for diffing
stateItem['comment'] = newDefinition.comment;
const diff = jsonMergePatch.generate(stateItem, newDefinition);
if (diff) {
response.push(newDefinition);
}
}
}
return response;
}
}
const membershipDiff = semanticallyCleanObject(
removeNullValues(jsonMergePatch.generate(sourceMember, member))
);
if (membershipDiff) {
membershipResponse.push(membershipDiff);
}
}
delete sourcePortal.portalProfileMemberships;
delete portal.portalProfileMemberships;
if (membershipResponse.length) {
portal['portalProfileMemberships'] = membershipResponse;
}
}
const diff = semanticallyCleanObject(
removeNullValues(jsonMergePatch.generate(sourcePortal, portal))
);
if (diff) {
response.push(diff);
}
}
}
return response;
}
onClick={async () => {
try {
const updated = jsYaml.load(this.model.getLinesContent().join('\n'));
const patch = jsonMergePatch.generate(props.input, updated);
const unmounted = await this.props.onSave(JSON.stringify(patch || {}), 'application/merge-patch+json');
if (unmounted !== true) {
this.setState({editing: false});
}
} catch (e) {
ctx.notifications.show({
content: ,
type: NotificationType.Error
});
}
}}
className='argo-button argo-button--base'>
public diff(state, definition) {
return removeNullValues(jsonMergePatch.generate(state, definition));
}
public diff(source, target) {
const profileNames = target.homePageLayoutAssignments.map(
assignment => assignment.profile
);
source.homePageLayoutAssignments = source.homePageLayoutAssignments.filter(
assignment => profileNames.includes(assignment.profile)
);
return jsonMergePatch.generate(source, target);
}