Module: x2node-patches

JSON Patch imlpementation module.

Requires

Classes

RecordPatch

Methods


<static> build(recordTypes, recordTypeName, patch)

Build record patch object from JSON Patch specification.
Parameters:
Name Type Description
recordTypes module:x2node-records~RecordTypesLibrary Record types library.
recordTypeName string Name of the record type, against records of which the patch will be applied.
patch Array.<Object> RFC 6902 JSON patch specification.
Throws:
Returns:
The patch object that can be used to apply the patch to records.
Type
module:x2node-patches~RecordPatch

<static> buildMerge(recordTypes, recordTypeName, mergePatch)

Build record patch object from Merge Patch specification.
Parameters:
Name Type Description
recordTypes module:x2node-records~RecordTypesLibrary Record types library.
recordTypeName string Name of the record type, against records of which the patch will be applied.
mergePatch Object RFC 7396 merge patch specification.
Throws:
Returns:
The patch object that can be used to apply the patch to records.
Type
module:x2node-patches~RecordPatch

<static> fromDiff(recordTypes, recordTypeName, recOld, recNew)

Build patch specification by analyzing the difference between two record versions. The top record id property is allowed to be missing in the provided new record (if present, must be the same). View, calculated and record meta-info properties are ignored. Unrecognized properties in the new record are not allowed. The resulting patch specification may still be invalid. For example, the function does not check if properties are modifiable or optional. Attempt to build a patch from the resulting specification will reveal the error. The array properties are assumed to be sorted using the same criteria in both old and new records. Elements of nested object arrays must have id property. All elements in the old record must have an id value. Elements in the new record without the id or with an id that is not found in the old array are assumed to be new and are inserted.
Parameters:
Name Type Description
recordTypes module:x2node-records~RecordTypesLibrary Record types library.
recordTypeName string Name of the record type.
recOld Object Original record.
recNew Object New record.
Throws:
  • If the provided record type name is invalid, or the specified old record object is not an object or is null.
    Type
    module:x2node-common.X2UsageError
  • If the provided new record object is not an object, is null, or contains invalid property values. Note, that the validity of the specified old object property values is not checked and is assumed to be always valid and complete.
    Type
    module:x2node-common.X2SyntaxError
Returns:
RFC 6902 JSON patch specification, which, when applied to recOld updates it to become identical to recNew.
Type
Array.<Object>