falcor-json-graph
Advanced tools
Comparing version 3.1.0 to 3.2.0
// | ||
'use strict'; | ||
"use strict"; | ||
function atom(value, props) { | ||
const result = | ||
typeof value === 'undefined' | ||
? { $type: 'atom' } | ||
: { $type: 'atom', value: value }; | ||
return props ? Object.assign({}, props, result) : result; | ||
const result = | ||
typeof value === "undefined" | ||
? { $type: "atom" } | ||
: { $type: "atom", value: value }; | ||
return props ? Object.assign({}, props, result) : result; | ||
} | ||
function undefinedAtom() { | ||
return { $type: 'atom' }; | ||
return { $type: "atom" }; | ||
} | ||
module.exports = { | ||
ref: function ref(path , props ) { | ||
const result = { $type: 'ref', value: path }; | ||
return props ? Object.assign({}, props, result) : result; | ||
}, | ||
atom: atom, | ||
undefinedAtom: undefinedAtom, | ||
error: function error( | ||
errorValue , | ||
props | ||
) { | ||
const result = { $type: 'error', value: errorValue }; | ||
return props ? Object.assign({}, props, result) : result; | ||
}, | ||
pathValue: function pathValue( | ||
path , | ||
value | ||
) { | ||
return { path: path, value: value }; | ||
}, | ||
pathInvalidation: function pathInvalidation( | ||
path | ||
) { | ||
return { path: path, invalidated: true }; | ||
} | ||
ref: function ref(path , props ) { | ||
const result = { $type: "ref", value: path }; | ||
return props ? Object.assign({}, props, result) : result; | ||
}, | ||
atom: atom, | ||
undefinedAtom: undefinedAtom, | ||
error: function error( | ||
errorValue , | ||
props | ||
) { | ||
const result = { $type: "error", value: errorValue }; | ||
return props ? Object.assign({}, props, result) : result; | ||
}, | ||
pathValue: function pathValue( | ||
path , | ||
value | ||
) { | ||
return { path: path, value: value }; | ||
}, | ||
pathInvalidation: function pathInvalidation(path ) { | ||
return { path: path, invalidated: true }; | ||
} | ||
}; |
122
lib/index.js
// | ||
'use strict'; | ||
"use strict"; | ||
@@ -18,115 +18,85 @@ | ||
const { | ||
ref, | ||
atom, | ||
undefinedAtom, | ||
error, | ||
pathValue, | ||
pathInvalidation | ||
} = require('./factories'); | ||
ref, | ||
atom, | ||
undefinedAtom, | ||
error, | ||
pathValue, | ||
pathInvalidation | ||
} = require("./factories"); | ||
const { | ||
mergeJsonGraph, | ||
mergeJsonGraphEnvelope, | ||
mergeJsonGraphNode | ||
} = require('./merge'); | ||
mergeJsonGraph, | ||
mergeJsonGraphEnvelope, | ||
mergeJsonGraphNode | ||
} = require("./merge"); | ||
module.exports = { | ||
ref, | ||
atom, | ||
undefinedAtom, | ||
undefined: undefinedAtom, | ||
error, | ||
pathValue, | ||
pathInvalidation, | ||
mergeJsonGraph, | ||
mergeJsonGraphEnvelope, | ||
mergeJsonGraphNode | ||
ref, | ||
atom, | ||
undefinedAtom, | ||
undefined: undefinedAtom, | ||
error, | ||
pathValue, | ||
pathInvalidation, | ||
mergeJsonGraph, | ||
mergeJsonGraphEnvelope, | ||
mergeJsonGraphNode | ||
}; |
148
lib/merge.js
// | ||
'use strict'; | ||
"use strict"; | ||
function mergeJsonGraphNode( | ||
left , | ||
right | ||
left , | ||
right | ||
) { | ||
if (right === null || typeof right !== 'object' || right.$type) { | ||
return right; | ||
} | ||
if (left === null || typeof left !== 'object' || left.$type) { | ||
return left; | ||
} | ||
return mergeJsonGraph(left, right); | ||
if (right === null || typeof right !== "object" || right.$type) { | ||
return right; | ||
} | ||
if (left === null || typeof left !== "object" || left.$type) { | ||
return left; | ||
} | ||
return mergeJsonGraph(left, right); | ||
} | ||
function mergeJsonGraph(left , right ) { | ||
if (left === right) { | ||
return right; | ||
} | ||
const acc = Object.assign({}, left); | ||
for (const key in right) { | ||
if (Object.prototype.hasOwnProperty.call(right, key)) { | ||
const rightValue = right[key]; | ||
if (typeof rightValue !== 'undefined') { | ||
const leftValue = acc[key]; | ||
if (leftValue !== rightValue) { | ||
acc[key] = | ||
typeof leftValue !== 'undefined' | ||
? mergeJsonGraphNode(leftValue, rightValue) | ||
: rightValue; | ||
} | ||
} | ||
if (left === right) { | ||
return right; | ||
} | ||
const acc = Object.assign({}, left); | ||
for (const key in right) { | ||
if (Object.prototype.hasOwnProperty.call(right, key)) { | ||
const rightValue = right[key]; | ||
if (typeof rightValue !== "undefined") { | ||
const leftValue = acc[key]; | ||
if (leftValue !== rightValue) { | ||
acc[key] = | ||
typeof leftValue !== "undefined" | ||
? mergeJsonGraphNode(leftValue, rightValue) | ||
: rightValue; | ||
} | ||
} | ||
} | ||
return acc; | ||
} | ||
return acc; | ||
} | ||
function mergeJsonGraphEnvelope( | ||
left , | ||
right | ||
left , | ||
right | ||
) { | ||
if ( | ||
left === right || | ||
(left.paths && | ||
left.paths.length === 0 && | ||
!left.invalidated && | ||
!left.context) | ||
) { | ||
return right; | ||
} | ||
const result = { | ||
jsonGraph: right.jsonGraph | ||
? mergeJsonGraph(left.jsonGraph, right.jsonGraph) | ||
: left.jsonGraph | ||
}; | ||
if ( | ||
left === right || | ||
(left.paths && | ||
left.paths.length === 0 && | ||
!left.invalidated && | ||
!left.context) | ||
) { | ||
return right; | ||
} | ||
const result = { | ||
jsonGraph: right.jsonGraph | ||
? mergeJsonGraph(left.jsonGraph, right.jsonGraph) | ||
: left.jsonGraph | ||
}; | ||
tentativeMerge(result, left, right, 'paths'); | ||
tentativeMerge(result, left, right, 'errors'); | ||
tentativeMerge(result, left, right, "paths"); | ||
tentativeMerge(result, left, right, "errors"); | ||
if (right.invalidated) { | ||
result.invalidated = left.invalidated | ||
? left.invalidated.concat(right.invalidated) | ||
: right.invalidated; | ||
} else if (left.invalidated) { | ||
result.invalidated = left.invalidated; | ||
} | ||
if (right.context) { | ||
result.context = left.context | ||
? mergeJsonGraph(left.context, right.context) | ||
: right.context; | ||
} else if (left.context) { | ||
result.context = left.context; | ||
} | ||
return result; | ||
if (right.invalidated) { | ||
result.invalidated = left.invalidated | ||
? left.invalidated.concat(right.invalidated) | ||
: right.invalidated; | ||
} else if (left.invalidated) { | ||
result.invalidated = left.invalidated; | ||
} | ||
if (right.context) { | ||
result.context = left.context | ||
? mergeJsonGraph(left.context, right.context) | ||
: right.context; | ||
} else if (left.context) { | ||
result.context = left.context; | ||
} | ||
return result; | ||
} | ||
@@ -82,21 +82,21 @@ | ||
function tentativeMerge( | ||
result , | ||
left , | ||
right , | ||
property | ||
result , | ||
left , | ||
right , | ||
property | ||
) { | ||
const leftValues = left[property] || []; | ||
const rightValues = right[property] || []; | ||
const leftValues = left[property] || []; | ||
const rightValues = right[property] || []; | ||
if (Array.isArray(left[property]) || Array.isArray(right[property])) { | ||
if (leftValues.length && !rightValues.length) { | ||
result[property] = leftValues; | ||
} else if (!leftValues.length && rightValues.length) { | ||
result[property] = rightValues; | ||
} else { | ||
result[property] = leftValues.concat(rightValues); | ||
} | ||
if (Array.isArray(left[property]) || Array.isArray(right[property])) { | ||
if (leftValues.length && !rightValues.length) { | ||
result[property] = leftValues; | ||
} else if (!leftValues.length && rightValues.length) { | ||
result[property] = rightValues; | ||
} else { | ||
result[property] = leftValues.concat(rightValues); | ||
} | ||
} | ||
} | ||
module.exports = { mergeJsonGraph, mergeJsonGraphEnvelope, mergeJsonGraphNode }; |
{ | ||
"name": "falcor-json-graph", | ||
"version": "3.1.0", | ||
"version": "3.2.0", | ||
"description": "A set of factory functions for creating JSON Graph values.", | ||
"main": "lib/index.js", | ||
"main": "./lib/index.js", | ||
"types": "./src/index.d.ts", | ||
"scripts": { | ||
@@ -35,10 +36,10 @@ "flow": "flow", | ||
"@lrowe/eslint-plugin-flow-remove-types": "^0.0.1", | ||
"chai": "^4.1.2", | ||
"eslint": "^4.12.1", | ||
"chai": "^4.2.0", | ||
"eslint": "^4.19.1", | ||
"flow-bin": "^0.62.0", | ||
"flow-coverage-report": "^0.4.0", | ||
"flow-coverage-report": "^0.4.1", | ||
"flow-remove-types": "^1.2.3", | ||
"mocha": "^4.0.1", | ||
"prettier": "^1.9.1", | ||
"standard-version": "^4.2.0" | ||
"mocha": "^4.1.0", | ||
"prettier": "^1.19.1", | ||
"standard-version": "^7.1.0" | ||
}, | ||
@@ -49,3 +50,7 @@ "flow-coverage-report": { | ||
] | ||
}, | ||
"publishConfig": { | ||
"access": "public", | ||
"registry": "https://registry.npmjs.org/" | ||
} | ||
} | ||
} |
// @flow | ||
'use strict'; | ||
"use strict"; | ||
import type { | ||
JsonGraphAtomDefined, | ||
JsonGraphAtomUndefined, | ||
JsonGraphError, | ||
JsonGraphLeaf, | ||
JsonGraphMetadata, | ||
JsonGraphRef, | ||
JsonValue, | ||
Path, | ||
PathInvalidation, | ||
PathSet, | ||
PathValue | ||
} from '.'; | ||
JsonGraphAtomDefined, | ||
JsonGraphAtomUndefined, | ||
JsonGraphError, | ||
JsonGraphLeaf, | ||
JsonGraphMetadata, | ||
JsonGraphRef, | ||
JsonValue, | ||
Path, | ||
PathInvalidation, | ||
PathSet, | ||
PathValue | ||
} from "."; | ||
declare function atom<T: JsonValue>( | ||
value: T, | ||
props?: JsonGraphMetadata | ||
value: T, | ||
props?: JsonGraphMetadata | ||
): JsonGraphAtomDefined<T>; | ||
declare function atom( | ||
value?: void, | ||
props?: JsonGraphMetadata | ||
value?: void, | ||
props?: JsonGraphMetadata | ||
): JsonGraphAtomUndefined; | ||
function atom(value, props) { | ||
const result = | ||
typeof value === 'undefined' | ||
? { $type: 'atom' } | ||
: { $type: 'atom', value: value }; | ||
return props ? Object.assign({}, props, result) : result; | ||
const result = | ||
typeof value === "undefined" | ||
? { $type: "atom" } | ||
: { $type: "atom", value: value }; | ||
return props ? Object.assign({}, props, result) : result; | ||
} | ||
function undefinedAtom(): JsonGraphAtomUndefined { | ||
return { $type: 'atom' }; | ||
return { $type: "atom" }; | ||
} | ||
module.exports = { | ||
ref: function ref(path: Path, props?: JsonGraphMetadata): JsonGraphRef { | ||
const result = { $type: 'ref', value: path }; | ||
return props ? Object.assign({}, props, result) : result; | ||
}, | ||
atom: atom, | ||
undefinedAtom: undefinedAtom, | ||
error: function error( | ||
errorValue: string, | ||
props?: JsonGraphMetadata | ||
): JsonGraphError { | ||
const result = { $type: 'error', value: errorValue }; | ||
return props ? Object.assign({}, props, result) : result; | ||
}, | ||
pathValue: function pathValue( | ||
path: PathSet, | ||
value: JsonGraphLeaf | ||
): PathValue { | ||
return { path: path, value: value }; | ||
}, | ||
pathInvalidation: function pathInvalidation( | ||
path: PathSet | ||
): PathInvalidation { | ||
return { path: path, invalidated: true }; | ||
} | ||
ref: function ref(path: Path, props?: JsonGraphMetadata): JsonGraphRef { | ||
const result = { $type: "ref", value: path }; | ||
return props ? Object.assign({}, props, result) : result; | ||
}, | ||
atom: atom, | ||
undefinedAtom: undefinedAtom, | ||
error: function error( | ||
errorValue: string, | ||
props?: JsonGraphMetadata | ||
): JsonGraphError { | ||
const result = { $type: "error", value: errorValue }; | ||
return props ? Object.assign({}, props, result) : result; | ||
}, | ||
pathValue: function pathValue( | ||
path: PathSet, | ||
value: JsonGraphLeaf | ||
): PathValue { | ||
return { path: path, value: value }; | ||
}, | ||
pathInvalidation: function pathInvalidation(path: PathSet): PathInvalidation { | ||
return { path: path, invalidated: true }; | ||
} | ||
}; |
134
src/index.js
// @flow | ||
'use strict'; | ||
"use strict"; | ||
export type Primitive = string | number | boolean | null; | ||
@@ -18,115 +18,85 @@ export type JsonValue = Primitive | JsonMap | JsonValue[]; | ||
export type JsonGraphLeaf = | ||
| JsonGraphAtom | ||
| JsonGraphError | ||
| JsonGraphRef | ||
| Primitive; | ||
| JsonGraphAtom | ||
| JsonGraphError | ||
| JsonGraphRef | ||
| Primitive; | ||
export type JsonGraphAtomDefined<T: ?JsonValue> = JsonGraphMetadata & { | ||
+$type: 'atom', | ||
+value: T | ||
+$type: "atom", | ||
+value: T | ||
}; | ||
export type JsonGraphAtomUndefined = JsonGraphMetadata & { | ||
+$type: 'atom', | ||
+value?: void | ||
+$type: "atom", | ||
+value?: void | ||
}; | ||
export type JsonGraphAtom = JsonGraphMetadata & { | ||
+$type: 'atom', | ||
+value?: ?JsonValue | ||
+$type: "atom", | ||
+value?: ?JsonValue | ||
}; | ||
export type JsonGraphError = JsonGraphMetadata & { | ||
+$type: 'error', | ||
+value: JsonValue | ||
+$type: "error", | ||
+value: JsonValue | ||
}; | ||
export type JsonGraphRef = JsonGraphMetadata & { | ||
+$type: 'ref', | ||
+value: Path | ||
+$type: "ref", | ||
+value: Path | ||
}; | ||
export type JsonGraphMetadata = { | ||
+$expires?: number, | ||
+$size?: number, | ||
+$timestamp?: number | ||
+$expires?: number, | ||
+$size?: number, | ||
+$timestamp?: number | ||
}; | ||
export type JsonGraphEnvelope = { | ||
errors?: Error[], | ||
jsonGraph: JsonGraph, | ||
paths?: PathSet[], | ||
invalidated?: PathSet[], | ||
context?: JsonGraph | ||
errors?: Error[], | ||
jsonGraph: JsonGraph, | ||
paths?: PathSet[], | ||
invalidated?: PathSet[], | ||
context?: JsonGraph | ||
}; | ||
export type PathValue = { | ||
path: PathSet, | ||
value: JsonGraphLeaf, | ||
invalidated?: empty, | ||
jsonGraph?: empty | ||
path: PathSet, | ||
value: JsonGraphLeaf, | ||
invalidated?: empty, | ||
jsonGraph?: empty | ||
}; | ||
export type PathInvalidation = { | ||
path: PathSet, | ||
value?: empty, | ||
invalidated: true, | ||
jsonGraph?: empty | ||
path: PathSet, | ||
value?: empty, | ||
invalidated: true, | ||
jsonGraph?: empty | ||
}; | ||
export interface IDisposable { | ||
dispose(): void; | ||
+isDisposed: boolean; | ||
} | ||
export type PartialObserver<T> = { | ||
+onNext?: (value: T) => void, | ||
+onError?: (error: Error) => void, | ||
+onCompleted?: () => void | ||
}; | ||
export interface IObservable<T> { | ||
subscribe( | ||
onNext: ?PartialObserver<T> | ((value: T) => void), | ||
onError: ?(error: Error) => void, | ||
onCompleted: ?() => void | ||
): IDisposable; | ||
} | ||
export interface IDataSource { | ||
get(paths: PathSet[]): IObservable<JsonGraphEnvelope>; | ||
set(jsonGraphEnvelope: JsonGraphEnvelope): IObservable<JsonGraphEnvelope>; | ||
call( | ||
functionPath: Path, | ||
args?: JsonGraphNode[], | ||
refSuffixes?: PathSet[], | ||
thisPaths?: PathSet[] | ||
): IObservable<JsonGraphEnvelope>; | ||
} | ||
const { | ||
ref, | ||
atom, | ||
undefinedAtom, | ||
error, | ||
pathValue, | ||
pathInvalidation | ||
} = require('./factories'); | ||
ref, | ||
atom, | ||
undefinedAtom, | ||
error, | ||
pathValue, | ||
pathInvalidation | ||
} = require("./factories"); | ||
const { | ||
mergeJsonGraph, | ||
mergeJsonGraphEnvelope, | ||
mergeJsonGraphNode | ||
} = require('./merge'); | ||
mergeJsonGraph, | ||
mergeJsonGraphEnvelope, | ||
mergeJsonGraphNode | ||
} = require("./merge"); | ||
module.exports = { | ||
ref, | ||
atom, | ||
undefinedAtom, | ||
undefined: undefinedAtom, | ||
error, | ||
pathValue, | ||
pathInvalidation, | ||
mergeJsonGraph, | ||
mergeJsonGraphEnvelope, | ||
mergeJsonGraphNode | ||
ref, | ||
atom, | ||
undefinedAtom, | ||
undefined: undefinedAtom, | ||
error, | ||
pathValue, | ||
pathInvalidation, | ||
mergeJsonGraph, | ||
mergeJsonGraphEnvelope, | ||
mergeJsonGraphNode | ||
}; |
150
src/merge.js
//@flow | ||
'use strict'; | ||
import type { JsonGraph, JsonGraphNode, JsonGraphEnvelope } from '.'; | ||
"use strict"; | ||
import type { JsonGraph, JsonGraphNode, JsonGraphEnvelope } from "."; | ||
function mergeJsonGraphNode( | ||
left: JsonGraphNode, | ||
right: JsonGraphNode | ||
left: JsonGraphNode, | ||
right: JsonGraphNode | ||
): JsonGraphNode { | ||
if (right === null || typeof right !== 'object' || right.$type) { | ||
return right; | ||
} | ||
if (left === null || typeof left !== 'object' || left.$type) { | ||
return left; | ||
} | ||
return mergeJsonGraph(left, right); | ||
if (right === null || typeof right !== "object" || right.$type) { | ||
return right; | ||
} | ||
if (left === null || typeof left !== "object" || left.$type) { | ||
return left; | ||
} | ||
return mergeJsonGraph(left, right); | ||
} | ||
function mergeJsonGraph(left: JsonGraph, right: JsonGraph): JsonGraph { | ||
if (left === right) { | ||
return right; | ||
} | ||
const acc: JsonGraph = Object.assign({}, left); | ||
for (const key in right) { | ||
if (Object.prototype.hasOwnProperty.call(right, key)) { | ||
const rightValue = right[key]; | ||
if (typeof rightValue !== 'undefined') { | ||
const leftValue = acc[key]; | ||
if (leftValue !== rightValue) { | ||
acc[key] = | ||
typeof leftValue !== 'undefined' | ||
? mergeJsonGraphNode(leftValue, rightValue) | ||
: rightValue; | ||
} | ||
} | ||
if (left === right) { | ||
return right; | ||
} | ||
const acc: JsonGraph = Object.assign({}, left); | ||
for (const key in right) { | ||
if (Object.prototype.hasOwnProperty.call(right, key)) { | ||
const rightValue = right[key]; | ||
if (typeof rightValue !== "undefined") { | ||
const leftValue = acc[key]; | ||
if (leftValue !== rightValue) { | ||
acc[key] = | ||
typeof leftValue !== "undefined" | ||
? mergeJsonGraphNode(leftValue, rightValue) | ||
: rightValue; | ||
} | ||
} | ||
} | ||
return acc; | ||
} | ||
return acc; | ||
} | ||
function mergeJsonGraphEnvelope( | ||
left: JsonGraphEnvelope, | ||
right: JsonGraphEnvelope | ||
left: JsonGraphEnvelope, | ||
right: JsonGraphEnvelope | ||
): JsonGraphEnvelope { | ||
if ( | ||
left === right || | ||
(left.paths && | ||
left.paths.length === 0 && | ||
!left.invalidated && | ||
!left.context) | ||
) { | ||
return right; | ||
} | ||
const result: JsonGraphEnvelope = { | ||
jsonGraph: right.jsonGraph | ||
? mergeJsonGraph(left.jsonGraph, right.jsonGraph) | ||
: left.jsonGraph | ||
}; | ||
if ( | ||
left === right || | ||
(left.paths && | ||
left.paths.length === 0 && | ||
!left.invalidated && | ||
!left.context) | ||
) { | ||
return right; | ||
} | ||
const result: JsonGraphEnvelope = { | ||
jsonGraph: right.jsonGraph | ||
? mergeJsonGraph(left.jsonGraph, right.jsonGraph) | ||
: left.jsonGraph | ||
}; | ||
tentativeMerge(result, left, right, 'paths'); | ||
tentativeMerge(result, left, right, 'errors'); | ||
tentativeMerge(result, left, right, "paths"); | ||
tentativeMerge(result, left, right, "errors"); | ||
if (right.invalidated) { | ||
result.invalidated = left.invalidated | ||
? left.invalidated.concat(right.invalidated) | ||
: right.invalidated; | ||
} else if (left.invalidated) { | ||
result.invalidated = left.invalidated; | ||
} | ||
if (right.context) { | ||
result.context = left.context | ||
? mergeJsonGraph(left.context, right.context) | ||
: right.context; | ||
} else if (left.context) { | ||
result.context = left.context; | ||
} | ||
return result; | ||
if (right.invalidated) { | ||
result.invalidated = left.invalidated | ||
? left.invalidated.concat(right.invalidated) | ||
: right.invalidated; | ||
} else if (left.invalidated) { | ||
result.invalidated = left.invalidated; | ||
} | ||
if (right.context) { | ||
result.context = left.context | ||
? mergeJsonGraph(left.context, right.context) | ||
: right.context; | ||
} else if (left.context) { | ||
result.context = left.context; | ||
} | ||
return result; | ||
} | ||
@@ -82,21 +82,21 @@ | ||
function tentativeMerge( | ||
result: JsonGraphEnvelope, | ||
left: JsonGraphEnvelope, | ||
right: JsonGraphEnvelope, | ||
property: string | ||
result: JsonGraphEnvelope, | ||
left: JsonGraphEnvelope, | ||
right: JsonGraphEnvelope, | ||
property: string | ||
): void { | ||
const leftValues = left[property] || []; | ||
const rightValues = right[property] || []; | ||
const leftValues = left[property] || []; | ||
const rightValues = right[property] || []; | ||
if (Array.isArray(left[property]) || Array.isArray(right[property])) { | ||
if (leftValues.length && !rightValues.length) { | ||
result[property] = leftValues; | ||
} else if (!leftValues.length && rightValues.length) { | ||
result[property] = rightValues; | ||
} else { | ||
result[property] = leftValues.concat(rightValues); | ||
} | ||
if (Array.isArray(left[property]) || Array.isArray(right[property])) { | ||
if (leftValues.length && !rightValues.length) { | ||
result[property] = leftValues; | ||
} else if (!leftValues.length && rightValues.length) { | ||
result[property] = rightValues; | ||
} else { | ||
result[property] = leftValues.concat(rightValues); | ||
} | ||
} | ||
} | ||
module.exports = { mergeJsonGraph, mergeJsonGraphEnvelope, mergeJsonGraphNode }; |
// @flow | ||
'use strict'; | ||
const { expect } = require('chai'); | ||
"use strict"; | ||
const { expect } = require("chai"); | ||
const { | ||
atom, | ||
undefinedAtom, | ||
ref, | ||
error, | ||
pathValue, | ||
pathInvalidation | ||
} = require('../src'); | ||
atom, | ||
undefinedAtom, | ||
ref, | ||
error, | ||
pathValue, | ||
pathInvalidation | ||
} = require("../src"); | ||
describe('atom', function() { | ||
it('undefined atom', () => expect(atom()).to.deep.equal({ $type: 'atom' })); | ||
it('atom of string', () => | ||
expect(atom('foo')).to.deep.equal({ $type: 'atom', value: 'foo' })); | ||
it('atom with props', () => | ||
expect(atom('foo', { $expires: 0 })).to.deep.equal({ | ||
$type: 'atom', | ||
value: 'foo', | ||
$expires: 0 | ||
})); | ||
describe("atom", function() { | ||
it("undefined atom", () => expect(atom()).to.deep.equal({ $type: "atom" })); | ||
it("atom of string", () => | ||
expect(atom("foo")).to.deep.equal({ $type: "atom", value: "foo" })); | ||
it("atom with props", () => | ||
expect(atom("foo", { $expires: 0 })).to.deep.equal({ | ||
$type: "atom", | ||
value: "foo", | ||
$expires: 0 | ||
})); | ||
}); | ||
describe('undefinedAtom', function() { | ||
it('undefined atom', () => | ||
expect(undefinedAtom()).to.deep.equal({ $type: 'atom' })); | ||
describe("undefinedAtom", function() { | ||
it("undefined atom", () => | ||
expect(undefinedAtom()).to.deep.equal({ $type: "atom" })); | ||
}); | ||
describe('ref', function() { | ||
it('ref', () => | ||
expect(ref(['foo'])).to.deep.equal({ $type: 'ref', value: ['foo'] })); | ||
it('ref with props', () => | ||
expect(ref(['foo'], { $expires: 0 })).to.deep.equal({ | ||
$type: 'ref', | ||
value: ['foo'], | ||
$expires: 0 | ||
})); | ||
describe("ref", function() { | ||
it("ref", () => | ||
expect(ref(["foo"])).to.deep.equal({ $type: "ref", value: ["foo"] })); | ||
it("ref with props", () => | ||
expect(ref(["foo"], { $expires: 0 })).to.deep.equal({ | ||
$type: "ref", | ||
value: ["foo"], | ||
$expires: 0 | ||
})); | ||
}); | ||
describe('error', function() { | ||
it('error', () => | ||
expect(error('foo')).to.deep.equal({ $type: 'error', value: 'foo' })); | ||
it('error with props', () => | ||
expect(error('foo', { $expires: 0 })).to.deep.equal({ | ||
$type: 'error', | ||
value: 'foo', | ||
$expires: 0 | ||
})); | ||
describe("error", function() { | ||
it("error", () => | ||
expect(error("foo")).to.deep.equal({ $type: "error", value: "foo" })); | ||
it("error with props", () => | ||
expect(error("foo", { $expires: 0 })).to.deep.equal({ | ||
$type: "error", | ||
value: "foo", | ||
$expires: 0 | ||
})); | ||
}); | ||
describe('pathValue', function() { | ||
it('pathValue of string', () => | ||
expect(pathValue(['foo'], 'bar')).to.deep.equal({ | ||
path: ['foo'], | ||
value: 'bar' | ||
})); | ||
it('pathValue of atom of string', () => | ||
expect(pathValue(['foo'], atom('bar'))).to.deep.equal({ | ||
path: ['foo'], | ||
value: { $type: 'atom', value: 'bar' } | ||
})); | ||
describe("pathValue", function() { | ||
it("pathValue of string", () => | ||
expect(pathValue(["foo"], "bar")).to.deep.equal({ | ||
path: ["foo"], | ||
value: "bar" | ||
})); | ||
it("pathValue of atom of string", () => | ||
expect(pathValue(["foo"], atom("bar"))).to.deep.equal({ | ||
path: ["foo"], | ||
value: { $type: "atom", value: "bar" } | ||
})); | ||
}); | ||
describe('pathInvalidation', function() { | ||
it('pathInvalidation', () => | ||
expect(pathInvalidation(['foo'])).to.deep.equal({ | ||
path: ['foo'], | ||
invalidated: true | ||
})); | ||
describe("pathInvalidation", function() { | ||
it("pathInvalidation", () => | ||
expect(pathInvalidation(["foo"])).to.deep.equal({ | ||
path: ["foo"], | ||
invalidated: true | ||
})); | ||
}); |
// @flow | ||
'use strict'; | ||
const { mergeJsonGraphEnvelope } = require('../src'); | ||
const { expect } = require('chai'); | ||
"use strict"; | ||
const { mergeJsonGraphEnvelope } = require("../src"); | ||
const { expect } = require("chai"); | ||
describe('mergeJsonGraphEnvelope', function() { | ||
it('merges jsonGraph', function() { | ||
const left = { | ||
jsonGraph: { | ||
foo: 1 | ||
} | ||
}; | ||
const right = { | ||
jsonGraph: { | ||
bar: 2 | ||
} | ||
}; | ||
const expected = { | ||
jsonGraph: { | ||
foo: 1, | ||
bar: 2 | ||
} | ||
}; | ||
const result = mergeJsonGraphEnvelope(left, right); | ||
expect(result).to.deep.equal(expected); | ||
}); | ||
describe("mergeJsonGraphEnvelope", function() { | ||
it("merges jsonGraph", function() { | ||
const left = { | ||
jsonGraph: { | ||
foo: 1 | ||
} | ||
}; | ||
const right = { | ||
jsonGraph: { | ||
bar: 2 | ||
} | ||
}; | ||
const expected = { | ||
jsonGraph: { | ||
foo: 1, | ||
bar: 2 | ||
} | ||
}; | ||
const result = mergeJsonGraphEnvelope(left, right); | ||
expect(result).to.deep.equal(expected); | ||
}); | ||
it('merges jsonGraph paths', function() { | ||
const left = { | ||
paths: [['foo']] | ||
}; | ||
const right = { | ||
paths: [['bar']], | ||
jsonGraph: { | ||
bar: 2 | ||
} | ||
}; | ||
const expected = { | ||
paths: [['foo'], ['bar']], | ||
jsonGraph: { | ||
bar: 2 | ||
} | ||
}; | ||
const result = mergeJsonGraphEnvelope((left: any), right); | ||
expect(result).to.deep.equal(expected); | ||
}); | ||
it("merges jsonGraph paths", function() { | ||
const left = { | ||
paths: [["foo"]] | ||
}; | ||
const right = { | ||
paths: [["bar"]], | ||
jsonGraph: { | ||
bar: 2 | ||
} | ||
}; | ||
const expected = { | ||
paths: [["foo"], ["bar"]], | ||
jsonGraph: { | ||
bar: 2 | ||
} | ||
}; | ||
const result = mergeJsonGraphEnvelope((left: any), right); | ||
expect(result).to.deep.equal(expected); | ||
}); | ||
it('merges with missing left jsonGraph paths', function() { | ||
const left = {}; | ||
const right = { | ||
paths: [['bar']], | ||
jsonGraph: { | ||
bar: 2 | ||
} | ||
}; | ||
const expected = { | ||
paths: [['bar']], | ||
jsonGraph: { | ||
bar: 2 | ||
} | ||
}; | ||
const result = mergeJsonGraphEnvelope((left: any), right); | ||
expect(result).to.deep.equal(expected); | ||
}); | ||
it("merges with missing left jsonGraph paths", function() { | ||
const left = {}; | ||
const right = { | ||
paths: [["bar"]], | ||
jsonGraph: { | ||
bar: 2 | ||
} | ||
}; | ||
const expected = { | ||
paths: [["bar"]], | ||
jsonGraph: { | ||
bar: 2 | ||
} | ||
}; | ||
const result = mergeJsonGraphEnvelope((left: any), right); | ||
expect(result).to.deep.equal(expected); | ||
}); | ||
it('merges with missing right jsonGraph paths', function() { | ||
const left = { | ||
paths: [['bar']] | ||
}; | ||
const right = { | ||
jsonGraph: { | ||
bar: 2 | ||
} | ||
}; | ||
const expected = { | ||
paths: [['bar']], | ||
jsonGraph: { | ||
bar: 2 | ||
} | ||
}; | ||
const result = mergeJsonGraphEnvelope((left: any), right); | ||
expect(result).to.deep.equal(expected); | ||
}); | ||
it("merges with missing right jsonGraph paths", function() { | ||
const left = { | ||
paths: [["bar"]] | ||
}; | ||
const right = { | ||
jsonGraph: { | ||
bar: 2 | ||
} | ||
}; | ||
const expected = { | ||
paths: [["bar"]], | ||
jsonGraph: { | ||
bar: 2 | ||
} | ||
}; | ||
const result = mergeJsonGraphEnvelope((left: any), right); | ||
expect(result).to.deep.equal(expected); | ||
}); | ||
it('merges jsonGraph errors', function() { | ||
const err1 = new Error('My Error 1'); | ||
const err2 = new Error('My Error 2'); | ||
const left = { | ||
errors: [err1] | ||
}; | ||
const right = { | ||
errors: [err2], | ||
jsonGraph: { | ||
bar: 2 | ||
} | ||
}; | ||
const expected = { | ||
errors: [err1, err2], | ||
jsonGraph: { | ||
bar: 2 | ||
} | ||
}; | ||
const result = mergeJsonGraphEnvelope((left: any), right); | ||
expect(result).to.deep.equal(expected); | ||
}); | ||
it("merges jsonGraph errors", function() { | ||
const err1 = new Error("My Error 1"); | ||
const err2 = new Error("My Error 2"); | ||
const left = { | ||
errors: [err1] | ||
}; | ||
const right = { | ||
errors: [err2], | ||
jsonGraph: { | ||
bar: 2 | ||
} | ||
}; | ||
const expected = { | ||
errors: [err1, err2], | ||
jsonGraph: { | ||
bar: 2 | ||
} | ||
}; | ||
const result = mergeJsonGraphEnvelope((left: any), right); | ||
expect(result).to.deep.equal(expected); | ||
}); | ||
it('ignores missing left jsonGraph', function() { | ||
const left = {}; | ||
const right = { | ||
jsonGraph: { | ||
bar: 2 | ||
} | ||
}; | ||
const expected = { | ||
jsonGraph: { | ||
bar: 2 | ||
} | ||
}; | ||
const result = mergeJsonGraphEnvelope((left: any), right); | ||
expect(result).to.deep.equal(expected); | ||
}); | ||
it("ignores missing left jsonGraph", function() { | ||
const left = {}; | ||
const right = { | ||
jsonGraph: { | ||
bar: 2 | ||
} | ||
}; | ||
const expected = { | ||
jsonGraph: { | ||
bar: 2 | ||
} | ||
}; | ||
const result = mergeJsonGraphEnvelope((left: any), right); | ||
expect(result).to.deep.equal(expected); | ||
}); | ||
it('ignores missing right jsonGraph', function() { | ||
const left = { | ||
jsonGraph: { | ||
foo: 1 | ||
} | ||
}; | ||
const right = {}; | ||
const expected = { | ||
jsonGraph: { | ||
foo: 1 | ||
} | ||
}; | ||
const result = mergeJsonGraphEnvelope(left, (right: any)); | ||
expect(result).to.deep.equal(expected); | ||
}); | ||
it("ignores missing right jsonGraph", function() { | ||
const left = { | ||
jsonGraph: { | ||
foo: 1 | ||
} | ||
}; | ||
const right = {}; | ||
const expected = { | ||
jsonGraph: { | ||
foo: 1 | ||
} | ||
}; | ||
const result = mergeJsonGraphEnvelope(left, (right: any)); | ||
expect(result).to.deep.equal(expected); | ||
}); | ||
it('merges invalidated', function() { | ||
const left = { | ||
jsonGraph: {}, | ||
invalidated: [['foo']] | ||
}; | ||
const right = { | ||
jsonGraph: {}, | ||
invalidated: [['bar']] | ||
}; | ||
const expected = { | ||
jsonGraph: {}, | ||
invalidated: [['foo'], ['bar']] | ||
}; | ||
const result = mergeJsonGraphEnvelope(left, right); | ||
expect(result).to.deep.equal(expected); | ||
}); | ||
it("merges invalidated", function() { | ||
const left = { | ||
jsonGraph: {}, | ||
invalidated: [["foo"]] | ||
}; | ||
const right = { | ||
jsonGraph: {}, | ||
invalidated: [["bar"]] | ||
}; | ||
const expected = { | ||
jsonGraph: {}, | ||
invalidated: [["foo"], ["bar"]] | ||
}; | ||
const result = mergeJsonGraphEnvelope(left, right); | ||
expect(result).to.deep.equal(expected); | ||
}); | ||
it('merges context when paths are empty', function() { | ||
const left = { | ||
jsonGraph: {}, | ||
paths: [], | ||
context: { | ||
foo: 1 | ||
} | ||
}; | ||
const right = { | ||
jsonGraph: {}, | ||
paths: [], | ||
context: { | ||
bar: 2 | ||
} | ||
}; | ||
const expected = { | ||
jsonGraph: {}, | ||
paths: [], | ||
context: { | ||
foo: 1, | ||
bar: 2 | ||
} | ||
}; | ||
const result = mergeJsonGraphEnvelope(left, right); | ||
expect(result).to.deep.equal(expected); | ||
}); | ||
it("merges context when paths are empty", function() { | ||
const left = { | ||
jsonGraph: {}, | ||
paths: [], | ||
context: { | ||
foo: 1 | ||
} | ||
}; | ||
const right = { | ||
jsonGraph: {}, | ||
paths: [], | ||
context: { | ||
bar: 2 | ||
} | ||
}; | ||
const expected = { | ||
jsonGraph: {}, | ||
paths: [], | ||
context: { | ||
foo: 1, | ||
bar: 2 | ||
} | ||
}; | ||
const result = mergeJsonGraphEnvelope(left, right); | ||
expect(result).to.deep.equal(expected); | ||
}); | ||
it('merges context using jsonGraph merge', function() { | ||
const left = { | ||
jsonGraph: {}, | ||
context: { | ||
branch: { | ||
foo: 1, | ||
atom: { | ||
$type: 'atom', | ||
value: { | ||
foo: 1 | ||
} | ||
} | ||
} | ||
it("merges context using jsonGraph merge", function() { | ||
const left = { | ||
jsonGraph: {}, | ||
context: { | ||
branch: { | ||
foo: 1, | ||
atom: { | ||
$type: "atom", | ||
value: { | ||
foo: 1 | ||
} | ||
}; | ||
const right = { | ||
jsonGraph: {}, | ||
context: { | ||
branch: { | ||
bar: 2, | ||
atom: { | ||
$type: 'atom', | ||
value: { | ||
bar: 2 | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
}; | ||
const right = { | ||
jsonGraph: {}, | ||
context: { | ||
branch: { | ||
bar: 2, | ||
atom: { | ||
$type: "atom", | ||
value: { | ||
bar: 2 | ||
} | ||
}; | ||
const expected = { | ||
jsonGraph: {}, | ||
context: { | ||
branch: { | ||
foo: 1, | ||
bar: 2, | ||
atom: { | ||
$type: 'atom', | ||
value: { | ||
bar: 2 | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
}; | ||
const expected = { | ||
jsonGraph: {}, | ||
context: { | ||
branch: { | ||
foo: 1, | ||
bar: 2, | ||
atom: { | ||
$type: "atom", | ||
value: { | ||
bar: 2 | ||
} | ||
}; | ||
const result = mergeJsonGraphEnvelope(left, right); | ||
expect(result).to.deep.equal(expected); | ||
}); | ||
} | ||
} | ||
} | ||
}; | ||
const result = mergeJsonGraphEnvelope(left, right); | ||
expect(result).to.deep.equal(expected); | ||
}); | ||
}); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
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
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
23
1102
66246