How to use the json-merge-patch.generate function in json-merge-patch

To help you get started, we’ve selected a few json-merge-patch examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github amtrack / sfdx-browserforce-plugin / src / plugins / security / certificate-and-key-management / index.ts View on Github external
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);
  }
github argoproj / argo-workflows / ui / src / app / cron-workflows / components / cron-workflow-summary-panel.tsx View on Github external
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));
                        }}
                    />
github amtrack / sfdx-browserforce-plugin / src / plugins / customer-portal / availableCustomObjects / index.ts View on Github external
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;
  }
github mozilla-lockwise / lockbox-datastore / lib / items.js View on Github external
// 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;
}
github amtrack / sfdx-browserforce-plugin / src / plugins / customer-portal / portals / index.ts View on Github external
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);
github amtrack / sfdx-browserforce-plugin / src / plugins / company-settings / critical-updates / index.ts View on Github external
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;
  }
github amtrack / sfdx-browserforce-plugin / src / plugins / customer-portal / portals / index.ts View on Github external
}
            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;
  }
github argoproj / argo-cd / ui / src / app / shared / components / yaml-editor / yaml-editor.tsx View on Github external
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'>
github amtrack / sfdx-browserforce-plugin / src / plugins / security / identity-provider / index.ts View on Github external
public diff(state, definition) {
    return removeNullValues(jsonMergePatch.generate(state, definition));
  }
github amtrack / sfdx-browserforce-plugin / src / plugins / home-page-layouts / index.ts View on Github external
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);
  }

json-merge-patch

Implementation of JSON Merge Patch (RFC 7396)

MIT
Latest version published 3 years ago

Package Health Score

53 / 100
Full package analysis