Comparing version 1.1.3 to 1.2.0
10
diff.js
@@ -149,3 +149,3 @@ import { compare } from './equal'; | ||
// sort by cost to find the lowest one (might be several ties for lowest) | ||
// [4, 6, 7, 1, 2].sort(function(a, b) {return a - b;}); -> [ 1, 2, 4, 6, 7 ] | ||
// [4, 6, 7, 1, 2].sort((a, b) => a - b); -> [ 1, 2, 4, 6, 7 ] | ||
const best = alternatives.sort((a, b) => a.cost - b.cost)[0]; | ||
@@ -158,7 +158,11 @@ memoized = best; | ||
} | ||
const array_operations = dist(input.length, output.length).operations; | ||
// handle weird objects masquerading as Arrays that don't have proper length | ||
// properties by using 0 for everything but positive numbers | ||
const input_length = (isNaN(input.length) || input.length <= 0) ? 0 : input.length; | ||
const output_length = (isNaN(output.length) || output.length <= 0) ? 0 : output.length; | ||
const array_operations = dist(input_length, output_length).operations; | ||
const [operations, padding] = array_operations.reduce(([operations, padding], array_operation) => { | ||
if (isArrayAdd(array_operation)) { | ||
const padded_index = array_operation.index + 1 + padding; | ||
const index_token = padded_index < input.length ? String(padded_index) : '-'; | ||
const index_token = padded_index < input_length ? String(padded_index) : '-'; | ||
const operation = { | ||
@@ -165,0 +169,0 @@ op: array_operation.op, |
export class MissingError extends Error { | ||
constructor(path) { | ||
super(`Value required at path: ${path}`); | ||
this.name = this.constructor.name; | ||
this.path = path; | ||
} | ||
constructor(path) { | ||
super(`Value required at path: ${path}`); | ||
this.path = path; | ||
this.name = this.constructor.name; | ||
} | ||
} | ||
export class InvalidOperationError extends Error { | ||
constructor(op) { | ||
super(`Invalid operation: ${op}`); | ||
this.name = this.constructor.name; | ||
this.op = op; | ||
} | ||
constructor(op) { | ||
super(`Invalid operation: ${op}`); | ||
this.op = op; | ||
this.name = this.constructor.name; | ||
} | ||
} | ||
export class TestError extends Error { | ||
constructor(actual, expected) { | ||
super(`Test failed: ${actual} != ${expected}`); | ||
this.name = this.constructor.name; | ||
this.actual = actual; | ||
this.expected = expected; | ||
} | ||
constructor(actual, expected) { | ||
super(`Test failed: ${actual} != ${expected}`); | ||
this.actual = actual; | ||
this.expected = expected; | ||
this.name = this.constructor.name; | ||
this.actual = actual; | ||
this.expected = expected; | ||
} | ||
} |
38
index.js
@@ -1,10 +0,5 @@ | ||
import {InvalidOperationError} from './errors'; | ||
import {Pointer} from './pointer'; | ||
import { InvalidOperationError } from './errors'; | ||
import { Pointer } from './pointer'; | ||
import * as operationFunctions from './patch'; | ||
import {diffAny} from './diff'; | ||
import package_json from './package'; | ||
export var version = package_json.version; | ||
import { diffAny } from './diff'; | ||
/** | ||
@@ -28,12 +23,11 @@ Apply a 'application/json-patch+json'-type patch to an object. | ||
export function applyPatch(object, patch) { | ||
return patch.map(operation => { | ||
var operationFunction = operationFunctions[operation.op]; | ||
// speedy exit if we don't recognize the operation name | ||
if (operationFunction === undefined) { | ||
return new InvalidOperationError(operation.op); | ||
} | ||
return operationFunction(object, operation); | ||
}); | ||
return patch.map(operation => { | ||
const operationFunction = operationFunctions[operation.op]; | ||
// speedy exit if we don't recognize the operation name | ||
if (operationFunction === undefined) { | ||
return new InvalidOperationError(operation.op); | ||
} | ||
return operationFunction(object, operation); | ||
}); | ||
} | ||
/** | ||
@@ -49,9 +43,5 @@ Produce a 'application/json-patch+json'-type patch to get from one object to | ||
export function createPatch(input, output) { | ||
var ptr = new Pointer(); | ||
// a new Pointer gets a default path of [''] if not specified | ||
var operations = diffAny(input, output, ptr); | ||
operations.forEach(function(operation) { | ||
operation.path = operation.path.toString(); | ||
}); | ||
return operations; | ||
const ptr = new Pointer(); | ||
// a new Pointer gets a default path of [''] if not specified | ||
return diffAny(input, output, ptr); | ||
} |
{ | ||
"name": "rfc6902", | ||
"version": "1.1.3", | ||
"version": "1.2.0", | ||
"description": "Complete implementation of RFC6902 (patch and diff)", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
132
patch.js
@@ -1,31 +0,28 @@ | ||
import {Pointer} from './pointer'; | ||
import {compare} from './equal'; | ||
import {MissingError, TestError} from './errors'; | ||
import { Pointer } from './pointer'; | ||
import { compare } from './equal'; | ||
import { MissingError, TestError } from './errors'; | ||
function _add(object, key, value) { | ||
if (Array.isArray(object)) { | ||
// `key` must be an index | ||
if (key == '-') { | ||
object.push(value); | ||
if (Array.isArray(object)) { | ||
// `key` must be an index | ||
if (key == '-') { | ||
object.push(value); | ||
} | ||
else { | ||
object.splice(key, 0, value); | ||
} | ||
} | ||
else { | ||
object.splice(key, 0, value); | ||
object[key] = value; | ||
} | ||
} | ||
else { | ||
object[key] = value; | ||
} | ||
} | ||
function _remove(object, key) { | ||
if (Array.isArray(object)) { | ||
// '-' syntax doesn't make sense when removing | ||
object.splice(key, 1); | ||
} | ||
else { | ||
// not sure what the proper behavior is when path = '' | ||
delete object[key]; | ||
} | ||
if (Array.isArray(object)) { | ||
// '-' syntax doesn't make sense when removing | ||
object.splice(key, 1); | ||
} | ||
else { | ||
// not sure what the proper behavior is when path = '' | ||
delete object[key]; | ||
} | ||
} | ||
/** | ||
@@ -40,11 +37,10 @@ > o If the target location specifies an array index, a new value is | ||
export function add(object, operation) { | ||
var endpoint = Pointer.fromJSON(operation.path).evaluate(object); | ||
// it's not exactly a "MissingError" in the same way that `remove` is -- more like a MissingParent, or something | ||
if (endpoint.parent === undefined) { | ||
return new MissingError(operation.path); | ||
} | ||
_add(endpoint.parent, endpoint.key, operation.value); | ||
return null; | ||
var endpoint = Pointer.fromJSON(operation.path).evaluate(object); | ||
// it's not exactly a "MissingError" in the same way that `remove` is -- more like a MissingParent, or something | ||
if (endpoint.parent === undefined) { | ||
return new MissingError(operation.path); | ||
} | ||
_add(endpoint.parent, endpoint.key, operation.value); | ||
return null; | ||
} | ||
/** | ||
@@ -55,12 +51,11 @@ > The "remove" operation removes the value at the target location. | ||
export function remove(object, operation) { | ||
// endpoint has parent, key, and value properties | ||
var endpoint = Pointer.fromJSON(operation.path).evaluate(object); | ||
if (endpoint.value === undefined) { | ||
return new MissingError(operation.path); | ||
} | ||
// not sure what the proper behavior is when path = '' | ||
_remove(endpoint.parent, endpoint.key); | ||
return null; | ||
// endpoint has parent, key, and value properties | ||
var endpoint = Pointer.fromJSON(operation.path).evaluate(object); | ||
if (endpoint.value === undefined) { | ||
return new MissingError(operation.path); | ||
} | ||
// not sure what the proper behavior is when path = '' | ||
_remove(endpoint.parent, endpoint.key); | ||
return null; | ||
} | ||
/** | ||
@@ -79,9 +74,8 @@ > The "replace" operation replaces the value at the target location | ||
export function replace(object, operation) { | ||
var endpoint = Pointer.fromJSON(operation.path).evaluate(object); | ||
if (endpoint.value === undefined) return new MissingError(operation.path); | ||
endpoint.parent[endpoint.key] = operation.value; | ||
return null; | ||
var endpoint = Pointer.fromJSON(operation.path).evaluate(object); | ||
if (endpoint.value === undefined) | ||
return new MissingError(operation.path); | ||
endpoint.parent[endpoint.key] = operation.value; | ||
return null; | ||
} | ||
/** | ||
@@ -103,13 +97,12 @@ > The "move" operation removes the value at a specified location and | ||
export function move(object, operation) { | ||
var from_endpoint = Pointer.fromJSON(operation.from).evaluate(object); | ||
if (from_endpoint.value === undefined) return new MissingError(operation.from); | ||
var endpoint = Pointer.fromJSON(operation.path).evaluate(object); | ||
if (endpoint.parent === undefined) return new MissingError(operation.path); | ||
_remove(from_endpoint.parent, from_endpoint.key); | ||
_add(endpoint.parent, endpoint.key, from_endpoint.value); | ||
return null; | ||
var from_endpoint = Pointer.fromJSON(operation.from).evaluate(object); | ||
if (from_endpoint.value === undefined) | ||
return new MissingError(operation.from); | ||
var endpoint = Pointer.fromJSON(operation.path).evaluate(object); | ||
if (endpoint.parent === undefined) | ||
return new MissingError(operation.path); | ||
_remove(from_endpoint.parent, from_endpoint.key); | ||
_add(endpoint.parent, endpoint.key, from_endpoint.value); | ||
return null; | ||
} | ||
/** | ||
@@ -129,12 +122,12 @@ > The "copy" operation copies the value at a specified location to the | ||
export function copy(object, operation) { | ||
var from_endpoint = Pointer.fromJSON(operation.from).evaluate(object); | ||
if (from_endpoint.value === undefined) return new MissingError(operation.from); | ||
var endpoint = Pointer.fromJSON(operation.path).evaluate(object); | ||
if (endpoint.parent === undefined) return new MissingError(operation.path); | ||
_remove(from_endpoint.parent, from_endpoint.key); | ||
_add(endpoint.parent, endpoint.key, from_endpoint.value); | ||
return null; | ||
var from_endpoint = Pointer.fromJSON(operation.from).evaluate(object); | ||
if (from_endpoint.value === undefined) | ||
return new MissingError(operation.from); | ||
var endpoint = Pointer.fromJSON(operation.path).evaluate(object); | ||
if (endpoint.parent === undefined) | ||
return new MissingError(operation.path); | ||
_remove(from_endpoint.parent, from_endpoint.key); | ||
_add(endpoint.parent, endpoint.key, from_endpoint.value); | ||
return null; | ||
} | ||
/** | ||
@@ -149,6 +142,7 @@ > The "test" operation tests that a value at the target location is | ||
export function test(object, operation) { | ||
var endpoint = Pointer.fromJSON(operation.path).evaluate(object); | ||
var result = compare(endpoint.value, operation.value); | ||
if (!result) return new TestError(endpoint.value, operation.value); | ||
return null; | ||
var endpoint = Pointer.fromJSON(operation.path).evaluate(object); | ||
var result = compare(endpoint.value, operation.value); | ||
if (!result) | ||
return new TestError(endpoint.value, operation.value); | ||
return null; | ||
} |
@@ -11,16 +11,2 @@ # rfc6902 | ||
**Important news!** `v1.0.2`, published on **2015**-06-09, renames a few of the public API methods from `v0.0.6`, the previous version, which was published on **2014**-01-23. | ||
| `v0.0.6` name | `v1.0.2` equivalent | | ||
|:------------------------------------|:-------------------------------------| | ||
| `rfc6902.patch(object, operations)` | `rfc6902.applyPatch(object, patch)` | | ||
| `rfc6902.diff(input, output)` | `rfc6902.createPatch(input, output)` | | ||
The arguments and return values are unchanged, except that the list of operation results returned by `rfc6902.applyPatch()` contains `null` (in `v1.0.2`) for each successful operation, instead of `undefined` (which was `v0.0.6` behavior). | ||
The old names are currently aliased to the new names, but will print a deprecation warning via `console.error()`. | ||
See [API](#api) below for details. | ||
## Quickstart | ||
@@ -34,3 +20,3 @@ | ||
Calculate diff between two objects: | ||
**Calculate diff** between two objects: | ||
@@ -41,3 +27,3 @@ rfc6902.createPatch({first: 'Chris'}, {first: 'Chris', last: 'Brown'}); | ||
Apply a patch to some object. | ||
**Apply a patch** to some object. | ||
@@ -79,3 +65,2 @@ var users = [{first: 'Chris', last: 'Brown', age: 20}]; | ||
you'll realize that computing diffs is rarely deterministic. | ||
(This explains why 2 out of the 103 tests are currently failing.) | ||
@@ -187,2 +172,2 @@ Applying `json-patch` documents is way easier than generating them, | ||
Copyright 2014-2015 Christopher Brown. [MIT Licensed](http://chbrown.github.io/licenses/MIT/#2014-2015). | ||
Copyright 2014-2016 Christopher Brown. [MIT Licensed](http://chbrown.github.io/licenses/MIT/#2014-2016). |
258
rfc6902.js
@@ -153,3 +153,3 @@ (function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.rfc6902 = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(_dereq_,module,exports){ | ||
// sort by cost to find the lowest one (might be several ties for lowest) | ||
// [4, 6, 7, 1, 2].sort(function(a, b) {return a - b;}); -> [ 1, 2, 4, 6, 7 ] | ||
// [4, 6, 7, 1, 2].sort((a, b) => a - b); -> [ 1, 2, 4, 6, 7 ] | ||
var best = alternatives.sort(function (a, b) { | ||
@@ -164,3 +164,7 @@ return a.cost - b.cost; | ||
} | ||
var array_operations = dist(input.length, output.length).operations; | ||
// handle weird objects masquerading as Arrays that don't have proper length | ||
// properties by using 0 for everything but positive numbers | ||
var input_length = isNaN(input.length) || input.length <= 0 ? 0 : input.length; | ||
var output_length = isNaN(output.length) || output.length <= 0 ? 0 : output.length; | ||
var array_operations = dist(input_length, output_length).operations; | ||
@@ -175,3 +179,3 @@ var _array_operations$reduce = array_operations.reduce(function (_ref, array_operation) { | ||
var padded_index = array_operation.index + 1 + padding; | ||
var index_token = padded_index < input.length ? String(padded_index) : "-"; | ||
var index_token = padded_index < input_length ? String(padded_index) : "-"; | ||
var operation = { | ||
@@ -328,46 +332,48 @@ op: array_operation.op, | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
value: true | ||
}); | ||
var MissingError = exports.MissingError = (function (_Error) { | ||
function MissingError(path) { | ||
_classCallCheck(this, MissingError); | ||
function MissingError(path) { | ||
_classCallCheck(this, MissingError); | ||
_get(Object.getPrototypeOf(MissingError.prototype), "constructor", this).call(this, "Value required at path: " + path); | ||
this.name = this.constructor.name; | ||
this.path = path; | ||
} | ||
_get(Object.getPrototypeOf(MissingError.prototype), "constructor", this).call(this, "Value required at path: " + path); | ||
this.path = path; | ||
this.name = this.constructor.name; | ||
} | ||
_inherits(MissingError, _Error); | ||
_inherits(MissingError, _Error); | ||
return MissingError; | ||
return MissingError; | ||
})(Error); | ||
var InvalidOperationError = exports.InvalidOperationError = (function (_Error2) { | ||
function InvalidOperationError(op) { | ||
_classCallCheck(this, InvalidOperationError); | ||
function InvalidOperationError(op) { | ||
_classCallCheck(this, InvalidOperationError); | ||
_get(Object.getPrototypeOf(InvalidOperationError.prototype), "constructor", this).call(this, "Invalid operation: " + op); | ||
this.name = this.constructor.name; | ||
this.op = op; | ||
} | ||
_get(Object.getPrototypeOf(InvalidOperationError.prototype), "constructor", this).call(this, "Invalid operation: " + op); | ||
this.op = op; | ||
this.name = this.constructor.name; | ||
} | ||
_inherits(InvalidOperationError, _Error2); | ||
_inherits(InvalidOperationError, _Error2); | ||
return InvalidOperationError; | ||
return InvalidOperationError; | ||
})(Error); | ||
var TestError = exports.TestError = (function (_Error3) { | ||
function TestError(actual, expected) { | ||
_classCallCheck(this, TestError); | ||
function TestError(actual, expected) { | ||
_classCallCheck(this, TestError); | ||
_get(Object.getPrototypeOf(TestError.prototype), "constructor", this).call(this, "Test failed: " + actual + " != " + expected); | ||
this.name = this.constructor.name; | ||
this.actual = actual; | ||
this.expected = expected; | ||
} | ||
_get(Object.getPrototypeOf(TestError.prototype), "constructor", this).call(this, "Test failed: " + actual + " != " + expected); | ||
this.actual = actual; | ||
this.expected = expected; | ||
this.name = this.constructor.name; | ||
this.actual = actual; | ||
this.expected = expected; | ||
} | ||
_inherits(TestError, _Error3); | ||
_inherits(TestError, _Error3); | ||
return TestError; | ||
return TestError; | ||
})(Error); | ||
@@ -378,4 +384,2 @@ | ||
var _interopRequire = function (obj) { return obj && obj.__esModule ? obj["default"] : obj; }; | ||
var _interopRequireWildcard = function (obj) { return obj && obj.__esModule ? obj : { "default": obj }; }; | ||
@@ -413,3 +417,3 @@ | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
value: true | ||
}); | ||
@@ -425,66 +429,21 @@ | ||
var package_json = _interopRequire(_dereq_("./package")); | ||
var version = package_json.version;exports.version = version; | ||
function applyPatch(object, patch) { | ||
return patch.map(function (operation) { | ||
var operationFunction = operationFunctions[operation.op]; | ||
// speedy exit if we don't recognize the operation name | ||
if (operationFunction === undefined) { | ||
return new InvalidOperationError(operation.op); | ||
} | ||
return operationFunction(object, operation); | ||
}); | ||
return patch.map(function (operation) { | ||
var operationFunction = operationFunctions[operation.op]; | ||
// speedy exit if we don't recognize the operation name | ||
if (operationFunction === undefined) { | ||
return new InvalidOperationError(operation.op); | ||
} | ||
return operationFunction(object, operation); | ||
}); | ||
} | ||
function createPatch(input, output) { | ||
var ptr = new Pointer(); | ||
// a new Pointer gets a default path of [''] if not specified | ||
var operations = diffAny(input, output, ptr); | ||
operations.forEach(function (operation) { | ||
operation.path = operation.path.toString(); | ||
}); | ||
return operations; | ||
var ptr = new Pointer(); | ||
// a new Pointer gets a default path of [''] if not specified | ||
return diffAny(input, output, ptr); | ||
} | ||
},{"./diff":1,"./errors":3,"./package":5,"./patch":6,"./pointer":7}],5:[function(_dereq_,module,exports){ | ||
module.exports={ | ||
"name": "rfc6902", | ||
"version": "1.1.2", | ||
"description": "Complete implementation of RFC6902 (patch and diff)", | ||
"keywords": [ | ||
"json", | ||
"patch", | ||
"diff", | ||
"rfc6902" | ||
], | ||
"homepage": "https://github.com/chbrown/rfc6902", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/chbrown/rfc6902.git" | ||
}, | ||
"author": "Christopher Brown <io@henrian.com> (http://henrian.com)", | ||
"license": "MIT", | ||
"main": "./rfc6902.js", | ||
"devDependencies": { | ||
"babel-core": "^5.0.0", | ||
"babelify": "^5.0.0", | ||
"browserify": "12.0.1", | ||
"coveralls": "*", | ||
"derequire": "2.0.3", | ||
"istanbul": "*", | ||
"js-yaml": "*", | ||
"mocha": "*", | ||
"mocha-lcov-reporter": "*", | ||
"typescript": "*" | ||
}, | ||
"scripts": { | ||
"test": "make test" | ||
} | ||
} | ||
},{"./diff":1,"./errors":3,"./patch":5,"./pointer":6}],5:[function(_dereq_,module,exports){ | ||
},{}],6:[function(_dereq_,module,exports){ | ||
/** | ||
@@ -564,3 +523,3 @@ > o If the target location specifies an array index, a new value is | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
value: true | ||
}); | ||
@@ -578,85 +537,84 @@ | ||
function _add(object, key, value) { | ||
if (Array.isArray(object)) { | ||
// `key` must be an index | ||
if (key == "-") { | ||
object.push(value); | ||
if (Array.isArray(object)) { | ||
// `key` must be an index | ||
if (key == "-") { | ||
object.push(value); | ||
} else { | ||
object.splice(key, 0, value); | ||
} | ||
} else { | ||
object.splice(key, 0, value); | ||
object[key] = value; | ||
} | ||
} else { | ||
object[key] = value; | ||
} | ||
} | ||
function _remove(object, key) { | ||
if (Array.isArray(object)) { | ||
// '-' syntax doesn't make sense when removing | ||
object.splice(key, 1); | ||
} else { | ||
// not sure what the proper behavior is when path = '' | ||
delete object[key]; | ||
} | ||
if (Array.isArray(object)) { | ||
// '-' syntax doesn't make sense when removing | ||
object.splice(key, 1); | ||
} else { | ||
// not sure what the proper behavior is when path = '' | ||
delete object[key]; | ||
} | ||
} | ||
function add(object, operation) { | ||
var endpoint = Pointer.fromJSON(operation.path).evaluate(object); | ||
// it's not exactly a "MissingError" in the same way that `remove` is -- more like a MissingParent, or something | ||
if (endpoint.parent === undefined) { | ||
return new MissingError(operation.path); | ||
} | ||
_add(endpoint.parent, endpoint.key, operation.value); | ||
return null; | ||
var endpoint = Pointer.fromJSON(operation.path).evaluate(object); | ||
// it's not exactly a "MissingError" in the same way that `remove` is -- more like a MissingParent, or something | ||
if (endpoint.parent === undefined) { | ||
return new MissingError(operation.path); | ||
} | ||
_add(endpoint.parent, endpoint.key, operation.value); | ||
return null; | ||
} | ||
function remove(object, operation) { | ||
// endpoint has parent, key, and value properties | ||
var endpoint = Pointer.fromJSON(operation.path).evaluate(object); | ||
if (endpoint.value === undefined) { | ||
return new MissingError(operation.path); | ||
} | ||
// not sure what the proper behavior is when path = '' | ||
_remove(endpoint.parent, endpoint.key); | ||
return null; | ||
// endpoint has parent, key, and value properties | ||
var endpoint = Pointer.fromJSON(operation.path).evaluate(object); | ||
if (endpoint.value === undefined) { | ||
return new MissingError(operation.path); | ||
} | ||
// not sure what the proper behavior is when path = '' | ||
_remove(endpoint.parent, endpoint.key); | ||
return null; | ||
} | ||
function replace(object, operation) { | ||
var endpoint = Pointer.fromJSON(operation.path).evaluate(object); | ||
if (endpoint.value === undefined) { | ||
return new MissingError(operation.path); | ||
}endpoint.parent[endpoint.key] = operation.value; | ||
return null; | ||
var endpoint = Pointer.fromJSON(operation.path).evaluate(object); | ||
if (endpoint.value === undefined) { | ||
return new MissingError(operation.path); | ||
}endpoint.parent[endpoint.key] = operation.value; | ||
return null; | ||
} | ||
function move(object, operation) { | ||
var from_endpoint = Pointer.fromJSON(operation.from).evaluate(object); | ||
if (from_endpoint.value === undefined) { | ||
return new MissingError(operation.from); | ||
}var endpoint = Pointer.fromJSON(operation.path).evaluate(object); | ||
if (endpoint.parent === undefined) { | ||
return new MissingError(operation.path); | ||
}_remove(from_endpoint.parent, from_endpoint.key); | ||
_add(endpoint.parent, endpoint.key, from_endpoint.value); | ||
return null; | ||
var from_endpoint = Pointer.fromJSON(operation.from).evaluate(object); | ||
if (from_endpoint.value === undefined) { | ||
return new MissingError(operation.from); | ||
}var endpoint = Pointer.fromJSON(operation.path).evaluate(object); | ||
if (endpoint.parent === undefined) { | ||
return new MissingError(operation.path); | ||
}_remove(from_endpoint.parent, from_endpoint.key); | ||
_add(endpoint.parent, endpoint.key, from_endpoint.value); | ||
return null; | ||
} | ||
function copy(object, operation) { | ||
var from_endpoint = Pointer.fromJSON(operation.from).evaluate(object); | ||
if (from_endpoint.value === undefined) { | ||
return new MissingError(operation.from); | ||
}var endpoint = Pointer.fromJSON(operation.path).evaluate(object); | ||
if (endpoint.parent === undefined) { | ||
return new MissingError(operation.path); | ||
}_remove(from_endpoint.parent, from_endpoint.key); | ||
_add(endpoint.parent, endpoint.key, from_endpoint.value); | ||
return null; | ||
var from_endpoint = Pointer.fromJSON(operation.from).evaluate(object); | ||
if (from_endpoint.value === undefined) { | ||
return new MissingError(operation.from); | ||
}var endpoint = Pointer.fromJSON(operation.path).evaluate(object); | ||
if (endpoint.parent === undefined) { | ||
return new MissingError(operation.path); | ||
}_remove(from_endpoint.parent, from_endpoint.key); | ||
_add(endpoint.parent, endpoint.key, from_endpoint.value); | ||
return null; | ||
} | ||
function test(object, operation) { | ||
var endpoint = Pointer.fromJSON(operation.path).evaluate(object); | ||
var result = compare(endpoint.value, operation.value); | ||
if (!result) { | ||
return new TestError(endpoint.value, operation.value); | ||
}return null; | ||
var endpoint = Pointer.fromJSON(operation.path).evaluate(object); | ||
var result = compare(endpoint.value, operation.value); | ||
if (!result) { | ||
return new TestError(endpoint.value, operation.value); | ||
}return null; | ||
} | ||
},{"./equal":2,"./errors":3,"./pointer":7}],7:[function(_dereq_,module,exports){ | ||
},{"./equal":2,"./errors":3,"./pointer":6}],6:[function(_dereq_,module,exports){ | ||
"use strict"; | ||
@@ -663,0 +621,0 @@ |
@@ -1,17 +0,16 @@ | ||
(function(p){"object"===typeof exports&&"undefined"!==typeof module?module.exports=p():"function"===typeof define&&define.amd?define([],p):("undefined"!==typeof window?window:"undefined"!==typeof global?global:"undefined"!==typeof self?self:this).rfc6902=p()})(function(){return function g(m,c,h){function l(a,b){if(!c[a]){if(!m[a]){var d="function"==typeof require&&require;if(!b&&d)return d(a,!0);if(f)return f(a,!0);d=Error("Cannot find module '"+a+"'");throw d.code="MODULE_NOT_FOUND",d;}d=c[a]={exports:{}}; | ||
m[a][0].call(d.exports,function(d){var b=m[a][1][d];return l(b?b:d)},d,d.exports,g,m,c,h)}return c[a].exports}for(var f="function"==typeof require&&require,e=0;e<h.length;e++)l(h[e]);return l}({1:[function(g,m,c){function h(a,d){var b={},k;for(k in a)b[k]=1;for(var n in d)delete b[n];return Object.keys(b)}function l(a){var d={};a.forEach(function(a){for(var b in a)d[b]=(d[b]||0)+1});a=a.length;for(var b in d)d[b]<a&&delete d[b];return Object.keys(d)}function f(a){return void 0===a?"undefined":null=== | ||
a?"null":Array.isArray(a)?"array":typeof a}function e(a,c,e){function f(d,b){var k=g[d+","+b];if(void 0===k){if(n(a[d-1],c[b-1]))k=f(d-1,b-1);else{k=[];if(0<d){var e=f(d-1,b);k.push({operations:e.operations.concat({op:"remove",index:d-1}),cost:e.cost+1})}0<b&&(e=f(d,b-1),k.push({operations:e.operations.concat({op:"add",index:d-1,value:c[b-1]}),cost:e.cost+1}));0<d&&0<b&&(e=f(d-1,b-1),k.push({operations:e.operations.concat({op:"replace",index:d-1,original:a[d-1],value:c[b-1]}),cost:e.cost+1}));k=k.sort(function(a, | ||
d){return a.cost-d.cost})[0]}g[d+","+b]=k}return k}var g={"0,0":{operations:[],cost:0}},h=f(a.length,c.length).operations.reduce(function(n,c){var f=d(n,2),g=f[0],f=f[1];if("add"===c.op){var h=c.index+1+f,h={op:c.op,path:e.add(h<a.length?String(h):"-").toString(),value:c.value};return[g.concat(h),f+1]}if("remove"===c.op)return h={op:c.op,path:e.add(String(c.index+f)).toString()},[g.concat(h),f-1];h=e.add(String(c.index+f));h=b(c.original,c.value,h);return[g.concat.apply(g,k(h)),f]},[[],0]);return d(h, | ||
2)[0]}function a(a,d,c){var n=[];h(a,d).forEach(function(a){n.push({op:"remove",path:c.add(a).toString()})});h(d,a).forEach(function(a){n.push({op:"add",path:c.add(a).toString(),value:d[a]})});l([a,d]).forEach(function(f){n.push.apply(n,k(b(a[f],d[f],c.add(f))))});return n}function b(d,b,k){var c=f(d),h=f(b);if("array"==c&&"array"==h)return e(d,b,k);if("object"==c&&"object"==h)return a(d,b,k);d=n(d,b)?[]:[{op:"replace",path:k.toString(),value:b}];return d}var d=function(a,d){if(Array.isArray(a))return a; | ||
if(Symbol.iterator in Object(a)){for(var b=[],k=a[Symbol.iterator](),c;!(c=k.next()).done&&(b.push(c.value),!d||b.length!==d););return b}throw new TypeError("Invalid attempt to destructure non-iterable instance");},k=function(a){if(Array.isArray(a)){for(var d=0,b=Array(a.length);d<a.length;d++)b[d]=a[d];return b}return Array.from(a)};c.diffAny=b;Object.defineProperty(c,"__esModule",{value:!0});var n=g("./equal").compare},{"./equal":2}],2:[function(g,m,c){function h(a,b){for(var d=[],k=0,c=a.length;k< | ||
c;k++)d.push([a[k],b[k]]);return d}function l(a,b){return a.length!==b.length?!1:h(a,b).every(function(a){return e(a[0],a[1])})}function f(a,b){var d=Object.keys(a),k=Object.keys(b);return l(d,k)?d.every(function(d){return e(a[d],b[d])}):!1}function e(a,b){return a===b?!0:Array.isArray(a)&&Array.isArray(b)?l(a,b):Object(a)===a&&Object(b)===b?f(a,b):!1}c.compare=e;Object.defineProperty(c,"__esModule",{value:!0})},{}],3:[function(g,m,c){var h=function a(b,d,k){var c=Object.getOwnPropertyDescriptor(b, | ||
d);if(void 0===c)return b=Object.getPrototypeOf(b),null===b?void 0:a(b,d,k);if("value"in c&&c.writable)return c.value;d=c.get;return void 0===d?void 0:d.call(k)},l=function(a,b){if("function"!==typeof b&&null!==b)throw new TypeError("Super expression must either be null or a function, not "+typeof b);a.prototype=Object.create(b&&b.prototype,{constructor:{value:a,enumerable:!1,writable:!0,configurable:!0}});b&&(a.__proto__=b)},f=function(a,b){if(!(a instanceof b))throw new TypeError("Cannot call a class as a function"); | ||
};Object.defineProperty(c,"__esModule",{value:!0});c.MissingError=function(a){function b(a){f(this,b);h(Object.getPrototypeOf(b.prototype),"constructor",this).call(this,"Value required at path: "+a);this.name=this.constructor.name;this.path=a}l(b,a);return b}(Error);c.InvalidOperationError=function(a){function b(a){f(this,b);h(Object.getPrototypeOf(b.prototype),"constructor",this).call(this,"Invalid operation: "+a);this.name=this.constructor.name;this.op=a}l(b,a);return b}(Error);c.TestError=function(a){function b(a, | ||
k){f(this,b);h(Object.getPrototypeOf(b.prototype),"constructor",this).call(this,"Test failed: "+a+" != "+k);this.name=this.constructor.name;this.actual=a;this.expected=k}l(b,a);return b}(Error)},{}],4:[function(g,m,c){c.applyPatch=function(a,b){return b.map(function(d){var b=f[d.op];return void 0===b?new h(d.op):b(a,d)})};c.createPatch=function(a,b){var d=new l,d=e(a,b,d);d.forEach(function(a){a.path=a.path.toString()});return d};Object.defineProperty(c,"__esModule",{value:!0});var h=g("./errors").InvalidOperationError, | ||
l=g("./pointer").Pointer,f=function(a){return a&&a.__esModule?a:{"default":a}}(g("./patch")),e=g("./diff").diffAny;g=function(a){return a&&a.__esModule?a["default"]:a}(g("./package")).version;c.version=g},{"./diff":1,"./errors":3,"./package":5,"./patch":6,"./pointer":7}],5:[function(g,m,c){m.exports={name:"rfc6902",version:"1.1.2",description:"Complete implementation of RFC6902 (patch and diff)",keywords:["json","patch","diff","rfc6902"],homepage:"https://github.com/chbrown/rfc6902",repository:{type:"git", | ||
url:"https://github.com/chbrown/rfc6902.git"},author:"Christopher Brown <io@henrian.com> (http://henrian.com)",license:"MIT",main:"./rfc6902.js",devDependencies:{"babel-core":"^5.0.0",babelify:"^5.0.0",browserify:"12.0.1",coveralls:"*",derequire:"2.0.3",istanbul:"*","js-yaml":"*",mocha:"*","mocha-lcov-reporter":"*",typescript:"*"},scripts:{test:"make test"}}},{}],6:[function(g,m,c){function h(a,b,c){Array.isArray(a)?"-"==b?a.push(c):a.splice(b,0,c):a[b]=c}function l(a,b){Array.isArray(a)?a.splice(b, | ||
1):delete a[b]}c.add=function(b,c){var e=f.fromJSON(c.path).evaluate(b);if(void 0===e.parent)return new a(c.path);h(e.parent,e.key,c.value);return null};c.remove=function(b,c){var e=f.fromJSON(c.path).evaluate(b);if(void 0===e.value)return new a(c.path);l(e.parent,e.key);return null};c.replace=function(b,c){var e=f.fromJSON(c.path).evaluate(b);if(void 0===e.value)return new a(c.path);e.parent[e.key]=c.value;return null};c.move=function(b,c){var e=f.fromJSON(c.from).evaluate(b);if(void 0===e.value)return new a(c.from); | ||
var g=f.fromJSON(c.path).evaluate(b);if(void 0===g.parent)return new a(c.path);l(e.parent,e.key);h(g.parent,g.key,e.value);return null};c.copy=function(b,c){var e=f.fromJSON(c.from).evaluate(b);if(void 0===e.value)return new a(c.from);var g=f.fromJSON(c.path).evaluate(b);if(void 0===g.parent)return new a(c.path);l(e.parent,e.key);h(g.parent,g.key,e.value);return null};c.test=function(a,c){var g=f.fromJSON(c.path).evaluate(a);return e(g.value,c.value)?null:new b(g.value,c.value)};Object.defineProperty(c, | ||
"__esModule",{value:!0});var f=g("./pointer").Pointer,e=g("./equal").compare;g=g("./errors");var a=g.MissingError,b=g.TestError},{"./equal":2,"./errors":3,"./pointer":7}],7:[function(g,m,c){function h(c){return c.replace(/~1/g,"/").replace(/~0/g,"~")}function l(c){return c.replace(/~/g,"~0").replace(/\//g,"~1")}var f=function(){function c(a,b){for(var d in b){var e=b[d];e.configurable=!0;e.value&&(e.writable=!0)}Object.defineProperties(a,b)}return function(a,b,d){b&&c(a.prototype,b);d&&c(a,d);return a}}(); | ||
Object.defineProperty(c,"__esModule",{value:!0});c.Pointer=function(){function c(a){a=void 0===a?[""]:a;if(!(this instanceof c))throw new TypeError("Cannot call a class as a function");this.tokens=a}f(c,{toString:{value:function(){return this.tokens.map(l).join("/")}},evaluate:{value:function(a){for(var b=null,c=null,e=1,f=this.tokens.length;e<f;e++)b=a,c=this.tokens[e],a=(b||{})[c];return{parent:b,key:c,value:a}}},push:{value:function(a){this.tokens.push(a)}},add:{value:function(a){a=this.tokens.concat(String(a)); | ||
return new c(a)}}},{fromJSON:{value:function(a){var b=a.split("/").map(h);if(""!==b[0])throw Error("Invalid JSON Pointer: "+a);return new c(b)}}});return c}()},{}]},{},[4])(4)}); | ||
(function(q){"object"===typeof exports&&"undefined"!==typeof module?module.exports=q():"function"===typeof define&&define.amd?define([],q):("undefined"!==typeof window?window:"undefined"!==typeof global?global:"undefined"!==typeof self?self:this).rfc6902=q()})(function(){return function m(n,d,k){function l(a,b){if(!d[a]){if(!n[a]){var c="function"==typeof require&&require;if(!b&&c)return c(a,!0);if(g)return g(a,!0);c=Error("Cannot find module '"+a+"'");throw c.code="MODULE_NOT_FOUND",c;}c=d[a]={exports:{}}; | ||
n[a][0].call(c.exports,function(c){var b=n[a][1][c];return l(b?b:c)},c,c.exports,m,n,d,k)}return d[a].exports}for(var g="function"==typeof require&&require,h=0;h<k.length;h++)l(k[h]);return l}({1:[function(m,n,d){function k(a,c){var b={},e;for(e in a)b[e]=1;for(var f in c)delete b[f];return Object.keys(b)}function l(a){var c={};a.forEach(function(a){for(var b in a)c[b]=(c[b]||0)+1});a=a.length;for(var b in c)c[b]<a&&delete c[b];return Object.keys(c)}function g(a){return void 0===a?"undefined":null=== | ||
a?"null":Array.isArray(a)?"array":typeof a}function h(a,d,h){function g(c,b){var e=k[c+","+b];if(void 0===e){if(f(a[c-1],d[b-1]))e=g(c-1,b-1);else{e=[];if(0<c){var h=g(c-1,b);e.push({operations:h.operations.concat({op:"remove",index:c-1}),cost:h.cost+1})}0<b&&(h=g(c,b-1),e.push({operations:h.operations.concat({op:"add",index:c-1,value:d[b-1]}),cost:h.cost+1}));0<c&&0<b&&(h=g(c-1,b-1),e.push({operations:h.operations.concat({op:"replace",index:c-1,original:a[c-1],value:d[b-1]}),cost:h.cost+1}));e=e.sort(function(a, | ||
c){return a.cost-c.cost})[0]}k[c+","+b]=e}return e}var k={"0,0":{operations:[],cost:0}},l=isNaN(a.length)||0>=a.length?0:a.length,m=isNaN(d.length)||0>=d.length?0:d.length,m=g(l,m).operations.reduce(function(a,f){var d=c(a,2),g=d[0],d=d[1];if("add"===f.op){var p=f.index+1+d,p={op:f.op,path:h.add(p<l?String(p):"-").toString(),value:f.value};return[g.concat(p),d+1]}if("remove"===f.op)return p={op:f.op,path:h.add(String(f.index+d)).toString()},[g.concat(p),d-1];p=h.add(String(f.index+d));p=b(f.original, | ||
f.value,p);return[g.concat.apply(g,e(p)),d]},[[],0]);return c(m,2)[0]}function a(a,c,f){var d=[];k(a,c).forEach(function(a){d.push({op:"remove",path:f.add(a).toString()})});k(c,a).forEach(function(a){d.push({op:"add",path:f.add(a).toString(),value:c[a]})});l([a,c]).forEach(function(h){d.push.apply(d,e(b(a[h],c[h],f.add(h))))});return d}function b(c,b,e){var d=g(c),k=g(b);if("array"==d&&"array"==k)return h(c,b,e);if("object"==d&&"object"==k)return a(c,b,e);c=f(c,b)?[]:[{op:"replace",path:e.toString(), | ||
value:b}];return c}var c=function(a,c){if(Array.isArray(a))return a;if(Symbol.iterator in Object(a)){for(var b=[],e=a[Symbol.iterator](),f;!(f=e.next()).done&&(b.push(f.value),!c||b.length!==c););return b}throw new TypeError("Invalid attempt to destructure non-iterable instance");},e=function(a){if(Array.isArray(a)){for(var c=0,b=Array(a.length);c<a.length;c++)b[c]=a[c];return b}return Array.from(a)};d.diffAny=b;Object.defineProperty(d,"__esModule",{value:!0});var f=m("./equal").compare},{"./equal":2}], | ||
2:[function(m,n,d){function k(a,b){for(var c=[],e=0,f=a.length;e<f;e++)c.push([a[e],b[e]]);return c}function l(a,b){return a.length!==b.length?!1:k(a,b).every(function(a){return h(a[0],a[1])})}function g(a,b){var c=Object.keys(a),e=Object.keys(b);return l(c,e)?c.every(function(c){return h(a[c],b[c])}):!1}function h(a,b){return a===b?!0:Array.isArray(a)&&Array.isArray(b)?l(a,b):Object(a)===a&&Object(b)===b?g(a,b):!1}d.compare=h;Object.defineProperty(d,"__esModule",{value:!0})},{}],3:[function(m,n, | ||
d){var k=function a(b,c,e){var f=Object.getOwnPropertyDescriptor(b,c);if(void 0===f)return b=Object.getPrototypeOf(b),null===b?void 0:a(b,c,e);if("value"in f&&f.writable)return f.value;c=f.get;return void 0===c?void 0:c.call(e)},l=function(a,b){if("function"!==typeof b&&null!==b)throw new TypeError("Super expression must either be null or a function, not "+typeof b);a.prototype=Object.create(b&&b.prototype,{constructor:{value:a,enumerable:!1,writable:!0,configurable:!0}});b&&(a.__proto__=b)},g=function(a, | ||
b){if(!(a instanceof b))throw new TypeError("Cannot call a class as a function");};Object.defineProperty(d,"__esModule",{value:!0});d.MissingError=function(a){function b(a){g(this,b);k(Object.getPrototypeOf(b.prototype),"constructor",this).call(this,"Value required at path: "+a);this.path=a;this.name=this.constructor.name}l(b,a);return b}(Error);d.InvalidOperationError=function(a){function b(a){g(this,b);k(Object.getPrototypeOf(b.prototype),"constructor",this).call(this,"Invalid operation: "+a);this.op= | ||
a;this.name=this.constructor.name}l(b,a);return b}(Error);d.TestError=function(a){function b(a,e){g(this,b);k(Object.getPrototypeOf(b.prototype),"constructor",this).call(this,"Test failed: "+a+" != "+e);this.actual=a;this.expected=e;this.name=this.constructor.name;this.actual=a;this.expected=e}l(b,a);return b}(Error)},{}],4:[function(m,n,d){d.applyPatch=function(a,b){return b.map(function(c){var b=g[c.op];return void 0===b?new k(c.op):b(a,c)})};d.createPatch=function(a,b){var c=new l;return h(a,b, | ||
c)};Object.defineProperty(d,"__esModule",{value:!0});var k=m("./errors").InvalidOperationError,l=m("./pointer").Pointer,g=function(a){return a&&a.__esModule?a:{"default":a}}(m("./patch")),h=m("./diff").diffAny},{"./diff":1,"./errors":3,"./patch":5,"./pointer":6}],5:[function(m,n,d){function k(a,b,f){Array.isArray(a)?"-"==b?a.push(f):a.splice(b,0,f):a[b]=f}function l(a,b){Array.isArray(a)?a.splice(b,1):delete a[b]}d.add=function(b,e){var f=g.fromJSON(e.path).evaluate(b);if(void 0===f.parent)return new a(e.path); | ||
k(f.parent,f.key,e.value);return null};d.remove=function(b,e){var f=g.fromJSON(e.path).evaluate(b);if(void 0===f.value)return new a(e.path);l(f.parent,f.key);return null};d.replace=function(b,e){var f=g.fromJSON(e.path).evaluate(b);if(void 0===f.value)return new a(e.path);f.parent[f.key]=e.value;return null};d.move=function(b,e){var f=g.fromJSON(e.from).evaluate(b);if(void 0===f.value)return new a(e.from);var d=g.fromJSON(e.path).evaluate(b);if(void 0===d.parent)return new a(e.path);l(f.parent,f.key); | ||
k(d.parent,d.key,f.value);return null};d.copy=function(b,e){var f=g.fromJSON(e.from).evaluate(b);if(void 0===f.value)return new a(e.from);var d=g.fromJSON(e.path).evaluate(b);if(void 0===d.parent)return new a(e.path);l(f.parent,f.key);k(d.parent,d.key,f.value);return null};d.test=function(a,e){var d=g.fromJSON(e.path).evaluate(a);return h(d.value,e.value)?null:new b(d.value,e.value)};Object.defineProperty(d,"__esModule",{value:!0});var g=m("./pointer").Pointer,h=m("./equal").compare;m=m("./errors"); | ||
var a=m.MissingError,b=m.TestError},{"./equal":2,"./errors":3,"./pointer":6}],6:[function(m,n,d){function k(d){return d.replace(/~1/g,"/").replace(/~0/g,"~")}function l(d){return d.replace(/~/g,"~0").replace(/\//g,"~1")}var g=function(){function d(a,b){for(var c in b){var e=b[c];e.configurable=!0;e.value&&(e.writable=!0)}Object.defineProperties(a,b)}return function(a,b,c){b&&d(a.prototype,b);c&&d(a,c);return a}}();Object.defineProperty(d,"__esModule",{value:!0});d.Pointer=function(){function d(a){a= | ||
void 0===a?[""]:a;if(!(this instanceof d))throw new TypeError("Cannot call a class as a function");this.tokens=a}g(d,{toString:{value:function(){return this.tokens.map(l).join("/")}},evaluate:{value:function(a){for(var b=null,c=null,d=1,f=this.tokens.length;d<f;d++)b=a,c=this.tokens[d],a=(b||{})[c];return{parent:b,key:c,value:a}}},push:{value:function(a){this.tokens.push(a)}},add:{value:function(a){a=this.tokens.concat(String(a));return new d(a)}}},{fromJSON:{value:function(a){var b=a.split("/").map(k); | ||
if(""!==b[0])throw Error("Invalid JSON Pointer: "+a);return new d(b)}}});return d}()},{}]},{},[4])(4)}); |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
90062
22
1726
169