falcor-json-graph
Advanced tools
Comparing version 2.2.2 to 3.0.0
@@ -0,1 +1,17 @@ | ||
<a name="3.0.0"></a> | ||
## 3.0.0 (2019-01-08) | ||
#### Bug Fixes | ||
* **merge:** merge paths even if one side is missing (#14) BREAKING CHANGE: paths will be pre ([794b0baf](https://github.com/Netflix/falcor-json-graph.git/commit/794b0baf)) | ||
#### Breaking Changes | ||
* paths will be present if any of the sides have paths in the envelope, earlier it was skipped if any of them were missing | ||
([794b0baf](https://github.com/Netflix/falcor-json-graph.git/commit/794b0baf)) | ||
# Change Log | ||
@@ -2,0 +18,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 }; | ||
} | ||
}; |
126
lib/index.js
// | ||
"use strict"; | ||
'use strict'; | ||
@@ -18,114 +18,114 @@ | ||
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 | ||
}; |
132
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.paths && right.paths) { | ||
result.paths = left.paths.concat(right.paths); | ||
} | ||
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 ( | ||
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 | ||
}; | ||
const leftPaths = left.paths || []; | ||
const rightPaths = right.paths || []; | ||
if (Array.isArray(left.paths) || Array.isArray(right.paths)) { | ||
if (leftPaths.length && !rightPaths.length) { | ||
result.paths = leftPaths; | ||
} else if (!leftPaths.length && rightPaths.length) { | ||
result.paths = rightPaths; | ||
} else { | ||
result.paths = leftPaths.concat(rightPaths); | ||
} | ||
} | ||
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; | ||
} | ||
module.exports = { mergeJsonGraph, mergeJsonGraphEnvelope, mergeJsonGraphNode }; |
{ | ||
"name": "falcor-json-graph", | ||
"version": "2.2.2", | ||
"version": "3.0.0", | ||
"description": "A set of factory functions for creating JSON Graph values.", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
// @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 }; | ||
} | ||
}; |
138
src/index.js
// @flow | ||
"use strict"; | ||
'use strict'; | ||
export type Primitive = string | number | boolean | null; | ||
@@ -18,114 +18,114 @@ 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 = { | ||
jsonGraph: JsonGraph, | ||
paths?: PathSet[], | ||
invalidated?: PathSet[], | ||
context?: JsonGraph | ||
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; | ||
dispose(): void; | ||
+isDisposed: boolean; | ||
} | ||
export type PartialObserver<T> = { | ||
+onNext?: (value: T) => void, | ||
+onError?: (error: Error) => void, | ||
+onCompleted?: () => void | ||
+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; | ||
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>; | ||
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 | ||
}; |
134
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.paths && right.paths) { | ||
result.paths = left.paths.concat(right.paths); | ||
} | ||
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 ( | ||
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 | ||
}; | ||
const leftPaths = left.paths || []; | ||
const rightPaths = right.paths || []; | ||
if (Array.isArray(left.paths) || Array.isArray(right.paths)) { | ||
if (leftPaths.length && !rightPaths.length) { | ||
result.paths = leftPaths; | ||
} else if (!leftPaths.length && rightPaths.length) { | ||
result.paths = rightPaths; | ||
} else { | ||
result.paths = leftPaths.concat(rightPaths); | ||
} | ||
} | ||
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; | ||
} | ||
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("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('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("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 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 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 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 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('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("merges context using jsonGraph merge", function() { | ||
const left = { | ||
jsonGraph: {}, | ||
context: { | ||
branch: { | ||
foo: 1, | ||
atom: { | ||
$type: "atom", | ||
value: { | ||
foo: 1 | ||
it('ignores missing right jsonGraph', function() { | ||
const left = { | ||
jsonGraph: { | ||
foo: 1 | ||
} | ||
} | ||
} | ||
} | ||
}; | ||
const right = { | ||
jsonGraph: {}, | ||
context: { | ||
branch: { | ||
bar: 2, | ||
atom: { | ||
$type: "atom", | ||
value: { | ||
bar: 2 | ||
}; | ||
const right = {}; | ||
const expected = { | ||
jsonGraph: { | ||
foo: 1 | ||
} | ||
} | ||
} | ||
} | ||
}; | ||
const expected = { | ||
jsonGraph: {}, | ||
context: { | ||
branch: { | ||
foo: 1, | ||
bar: 2, | ||
atom: { | ||
$type: "atom", | ||
value: { | ||
bar: 2 | ||
}; | ||
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 context when paths are empty', function() { | ||
const left = { | ||
jsonGraph: {}, | ||
paths: [], | ||
context: { | ||
foo: 1 | ||
} | ||
} | ||
} | ||
} | ||
}; | ||
const result = mergeJsonGraphEnvelope(left, right); | ||
expect(result).to.deep.equal(expected); | ||
}); | ||
}; | ||
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 | ||
} | ||
} | ||
} | ||
} | ||
}; | ||
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 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
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
67288
1030
1