Renamed field 'jsoneditor' to 'meta' in extended JSON Patch

This commit is contained in:
jos 2017-12-17 13:53:06 +01:00
parent 1f5f85a4e0
commit dd22b97eb0
3 changed files with 30 additions and 30 deletions

View File

@ -26,7 +26,7 @@ export function changeValue (eson, path, value) {
op: 'replace',
path: compileJSONPointer(path),
value: value,
jsoneditor: {
meta: {
type: oldDataValue[META].type
}
}]
@ -51,7 +51,7 @@ export function changeProperty (eson, parentPath, oldProp, newProp) {
op: 'move',
from: compileJSONPointer(parentPath.concat(oldProp)),
path: compileJSONPointer(parentPath.concat(uniqueNewProp)),
jsoneditor: {
meta: {
before: findNextProp(parent, oldProp)
}
}]
@ -74,7 +74,7 @@ export function changeType (eson, path, type) {
op: 'replace',
path: compileJSONPointer(path),
value: newValue,
jsoneditor: {
meta: {
type
}
}]
@ -120,7 +120,7 @@ export function duplicate (eson, selection) {
op: 'copy',
from: compileJSONPointer(path),
path: compileJSONPointer(rootPath.concat(newProp)),
jsoneditor: {
meta: {
before
}
}
@ -150,7 +150,7 @@ export function insertBefore (eson, path, values) { // TODO: find a better name
op: 'add',
path: compileJSONPointer(parentPath.concat(startIndex + offset)),
value: entry.value,
jsoneditor: {
meta: {
type: entry.type
}
}))
@ -163,7 +163,7 @@ export function insertBefore (eson, path, values) { // TODO: find a better name
op: 'add',
path: compileJSONPointer(parentPath.concat(newProp)),
value: entry.value,
jsoneditor: {
meta: {
type: entry.type,
before
}
@ -195,7 +195,7 @@ export function replace (eson, selection, values) { // TODO: find a better name
op: 'add',
path: compileJSONPointer(rootPath.concat(minIndex + offset)),
value: entry.value,
jsoneditor: {
meta: {
type: entry.type
}
}))
@ -212,7 +212,7 @@ export function replace (eson, selection, values) { // TODO: find a better name
op: 'add',
path: compileJSONPointer(rootPath.concat(newProp)),
value: entry.value,
jsoneditor: {
meta: {
type: entry.type,
before
}
@ -246,7 +246,7 @@ export function append (eson, parentPath, type) {
op: 'add',
path: compileJSONPointer(parentPath.concat('-')),
value,
jsoneditor: {
meta: {
type
}
}]
@ -258,7 +258,7 @@ export function append (eson, parentPath, type) {
op: 'add',
path: compileJSONPointer(parentPath.concat(newProp)),
value,
jsoneditor: {
meta: {
type
}
}]
@ -346,7 +346,7 @@ export function sort (eson, path, order = null) {
op: 'replace',
path: compileJSONPointer(path),
value: esonToJson(orderedObject),
jsoneditor: {
meta: {
order: orderedProps // TODO: order isn't used right now in patchEson.
}
}]

View File

@ -30,7 +30,7 @@ export function patchEson (eson, patch, expand = expandAll) {
const action = patch[i]
const path = action.path ? parseJSONPointer(action.path) : null
const from = action.from ? parseJSONPointer(action.from) : null
const options = action.jsoneditor
const options = action.meta
// TODO: check whether action.op and action.path exist
@ -141,7 +141,7 @@ export function replace (data, path, value) {
op: 'replace',
path: compileJSONPointer(path),
value: esonToJson(oldValue),
jsoneditor: {
meta: {
type: oldValue[META].type
}
}]
@ -170,7 +170,7 @@ export function remove (data, path) {
op: 'add',
path: compileJSONPointer(path),
value,
jsoneditor: {
meta: {
type: dataValue[META].type
}
}]
@ -190,7 +190,7 @@ export function remove (data, path) {
op: 'add',
path: compileJSONPointer(path),
value,
jsoneditor: {
meta: {
type: dataValue[META].type,
before: nextProp
}
@ -258,7 +258,7 @@ export function add (data, path, value, options) {
op: 'replace',
path: compileJSONPointer(resolvedPath),
value: esonToJson(oldValue),
jsoneditor: { type: oldValue[META].type }
meta: { type: oldValue[META].type }
}]
}
}
@ -311,19 +311,19 @@ export function move (data, path, from, options) {
const result2 = add(result1.data, path, dataValue, options)
// FIXME: passing id as parameter is ugly, make that redundant (use replace instead of remove/add? (that would give less predictive output :( ))
const before = result1.revert[0].jsoneditor.before
const before = result1.revert[0].meta.before
const beforeNeeded = (parent[META].type === 'Object' && before)
if (result2.revert[0].op === 'replace') {
const value = result2.revert[0].value
const type = result2.revert[0].jsoneditor.type
const type = result2.revert[0].meta.type
const options = beforeNeeded ? { type, before } : { type }
return {
data: result2.data,
revert: [
{ op: 'move', from: compileJSONPointer(path), path: compileJSONPointer(from) },
{ op: 'add', path: compileJSONPointer(path), value, jsoneditor: options}
{ op: 'add', path: compileJSONPointer(path), value, meta: options}
]
}
}
@ -331,7 +331,7 @@ export function move (data, path, from, options) {
return {
data: result2.data,
revert: beforeNeeded
? [{ op: 'move', from: compileJSONPointer(path), path: compileJSONPointer(from), jsoneditor: { before } }]
? [{ op: 'move', from: compileJSONPointer(path), path: compileJSONPointer(from), meta: { before } }]
: [{ op: 'move', from: compileJSONPointer(path), path: compileJSONPointer(from) }]
}
}

View File

@ -98,8 +98,8 @@ test('jsonpatch remove', t => {
obj: {}
}))
t.deepEqual(revert, [
{op: 'add', path: '/arr/1', value: 2, jsoneditor: {type: 'value'}},
{op: 'add', path: '/obj/a', value: 4, jsoneditor: {type: 'value', before: null}}
{op: 'add', path: '/arr/1', value: 2, meta: {type: 'value'}},
{op: 'add', path: '/obj/a', value: 4, meta: {type: 'value', before: null}}
])
// test revert
@ -135,8 +135,8 @@ test('jsonpatch replace', t => {
obj: {a: 400}
}))
t.deepEqual(revert, [
{op: 'replace', path: '/arr/1', value: 2, jsoneditor: {type: 'value'}},
{op: 'replace', path: '/obj/a', value: 4, jsoneditor: {type: 'value'}}
{op: 'replace', path: '/arr/1', value: 2, meta: {type: 'value'}},
{op: 'replace', path: '/obj/a', value: 4, meta: {type: 'value'}}
])
// test revert
@ -148,8 +148,8 @@ test('jsonpatch replace', t => {
t.deepEqual(patchedJson2, json)
t.deepEqual(revert2, [
{op: 'replace', path: '/obj/a', value: 400, jsoneditor: {type: 'value'}},
{op: 'replace', path: '/arr/1', value: 200, jsoneditor: {type: 'value'}}
{op: 'replace', path: '/obj/a', value: 400, meta: {type: 'value'}},
{op: 'replace', path: '/arr/1', value: 200, meta: {type: 'value'}}
])
})
@ -202,7 +202,7 @@ test('jsonpatch copy', t => {
t.deepEqual(patchedJson2, json)
t.deepEqual(revert2, [
{op: 'add', path: '/arr/2', value: {a: 4}, jsoneditor: {type: 'Object'}}
{op: 'add', path: '/arr/2', value: {a: 4}, meta: {type: 'Object'}}
])
})
@ -289,7 +289,7 @@ test('jsonpatch move before', t => {
zzz: 'zzz'
})
t.deepEqual(revert, [
{op: 'move', from: '/arr/2', path: '/obj', jsoneditor: {before: 'zzz'}}
{op: 'move', from: '/arr/2', path: '/obj', meta: {before: 'zzz'}}
])
// test revert
@ -324,7 +324,7 @@ test('jsonpatch move and replace', t => {
t.deepEqual(patchedJson, { b : 2 })
t.deepEqual(revert, [
{op:'move', from: '/b', path: '/a'},
{op:'add', path:'/b', value: 3, jsoneditor: {type: 'value', before: 'b'}}
{op:'add', path:'/b', value: 3, meta: {type: 'value', before: 'b'}}
])
// test revert
@ -362,7 +362,7 @@ test('jsonpatch move and replace (nested)', t => {
})
t.deepEqual(revert, [
{op:'move', from: '/arr', path: '/obj'},
{op:'add', path:'/arr', value: [1,2,3], jsoneditor: {type: 'Array'}}
{op:'add', path:'/arr', value: [1,2,3], meta: {type: 'Array'}}
])
// test revert