falcor-json-graph
Advanced tools
Comparing version 2.0.0 to 2.1.0
{ | ||
"name": "falcor-json-graph", | ||
"version": "2.0.0", | ||
"version": "2.1.0", | ||
"description": "A set of factory functions for creating JSON Graph values.", | ||
"main": "src/index.js", | ||
"main": "lib/index.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
"flow": "flow", | ||
"flow-coverage": "flow-coverage-report", | ||
"lint": "eslint src/ test/", | ||
"prepare": "test -e lib && rm -r lib; flow-remove-types --out-dir lib/ src/ && (cd src/; find * -type f -name '*.js' -exec cp {} ../lib/{}.flow \\;)", | ||
"prettier": "prettier --write src/**.js test/**.js", | ||
"check-formatting": "prettier --list-different src/**.js test/**.js", | ||
"test": "mocha -r flow-remove-types/register", | ||
"release": "standard-version" | ||
}, | ||
@@ -25,3 +32,19 @@ "repository": { | ||
"homepage": "https://github.com/Netflix/falcor-json-graph", | ||
"dependencies": {} | ||
"dependencies": {}, | ||
"devDependencies": { | ||
"@lrowe/eslint-plugin-flow-remove-types": "^0.0.1", | ||
"chai": "^4.1.2", | ||
"eslint": "^4.12.1", | ||
"flow-bin": "^0.60.1", | ||
"flow-coverage-report": "^0.4.0", | ||
"flow-remove-types": "^1.2.3", | ||
"mocha": "^4.0.1", | ||
"prettier": "^1.9.1", | ||
"standard-version": "^4.2.0" | ||
}, | ||
"flow-coverage-report": { | ||
"includeGlob": [ | ||
"src/**/*.js" | ||
] | ||
} | ||
} |
@@ -5,9 +5,24 @@ # falcor-json-graph | ||
## API | ||
```JavaScript | ||
var jsonGraph = require('falcor-json-graph'); | ||
var atom = jsonGraph.atom("a string wrapped in an atom"); // creates { $type: "atom", value: "a string wrapped in an atom" } | ||
var ref = jsonGraph.ref("todos[0].name"); // creates { $type: "ref", value: ["todos", 0, "name"] } | ||
var error = jsonGraph.error("something bad happened."); // creates { $type: "error", value: "something bad happened." } | ||
// { $type: "atom", value: "a string wrapped in an atom" } | ||
var atom = jsonGraph.atom("a string wrapped in an atom"); | ||
// { $type: "atom" } | ||
var undefinedAtom = jsonGraph.undefinedAtom(); | ||
// { $type: "ref", value: ["todos", 0, "name"] } | ||
var ref = jsonGraph.ref(["todos", 0, "name"]); | ||
// { $type: "error", value: "something bad happened." } | ||
var error = jsonGraph.error("something bad happened."); | ||
// { path: [ 'user', 'age' ], value: 25 } | ||
var pathValue = jsonGraph.pathValue(["user", "age"], 25); | ||
// { path: [ 'user', 'age' ], invalidated: true } | ||
var pathValue = jsonGraph.pathInvalidation(["user", "age"]) | ||
``` |
175
src/index.js
@@ -1,36 +0,149 @@ | ||
function sentinel(type, value, props) { | ||
var copy = Object.create(null); | ||
if (props != null) { | ||
for(var key in props) { | ||
copy[key] = props[key]; | ||
} | ||
// @flow | ||
"use strict"; | ||
export type Primitive = string | number | boolean | null; | ||
export type JsonValue = Primitive | JsonMap | JsonValue[]; | ||
export type JsonMap = { [key: string]: JsonValue }; | ||
copy["$type"] = type; | ||
copy.value = value; | ||
return copy; | ||
} | ||
else { | ||
return { $type: type, value: value }; | ||
} | ||
export type Key = Primitive; | ||
export type KeyRangeTo = { from?: number, to: number }; | ||
export type KeyRangeLength = { from?: number, length: number }; | ||
export type KeyRange = KeyRangeTo | KeyRangeLength; | ||
export type Path = Key[]; | ||
export type KeySet = Key | KeyRange | Array<Key | KeyRange>; | ||
export type PathSet = KeySet[]; | ||
export type JsonGraph = { [key: string]: JsonGraphNode, $type?: empty }; | ||
export type JsonGraphNode = JsonGraph | JsonGraphLeaf; | ||
export type JsonGraphLeaf = | ||
| JsonGraphAtom | ||
| JsonGraphError | ||
| JsonGraphRef | ||
| Primitive; | ||
export type JsonGraphAtomDefined<T: JsonValue> = JsonGraphMetadata & { | ||
$type: "atom", | ||
value: T | ||
}; | ||
export type JsonGraphAtomUndefined = JsonGraphMetadata & { | ||
$type: "atom", | ||
value?: empty | ||
}; | ||
export type JsonGraphAtom = | ||
| JsonGraphAtomDefined<JsonValue> | ||
| JsonGraphAtomUndefined; | ||
export type JsonGraphError = JsonGraphMetadata & { | ||
$type: "error", | ||
value: JsonValue | ||
}; | ||
export type JsonGraphRef = JsonGraphMetadata & { | ||
$type: "ref", | ||
value: Path | ||
}; | ||
export type JsonGraphMetadata = { | ||
$expires?: number, | ||
$size?: number, | ||
$timestamp?: number | ||
}; | ||
export type JsonGraphEnvelope = { | ||
jsonGraph: JsonGraph, | ||
paths?: PathSet[], | ||
invalidated?: PathSet[], | ||
context?: JsonGraph | ||
}; | ||
export type PathValue = { | ||
path: PathSet, | ||
value: JsonGraphLeaf, | ||
invalidated?: empty, | ||
jsonGraph?: empty | ||
}; | ||
export type PathInvalidation = { | ||
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>; | ||
} | ||
declare function atom<T: JsonValue>( | ||
value: T, | ||
props?: JsonGraphMetadata | ||
): JsonGraphAtomDefined<T>; | ||
declare function atom( | ||
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; | ||
} | ||
function undefinedAtom(): JsonGraphAtomUndefined { | ||
return { $type: "atom" }; | ||
} | ||
module.exports = { | ||
ref: function ref(path, props) { | ||
return sentinel("ref", path, props); | ||
}, | ||
atom: function atom(value, props) { | ||
return sentinel("atom", value, props); | ||
}, | ||
undefined: function() { | ||
return sentinel("atom"); | ||
}, | ||
error: function error(errorValue, props) { | ||
return sentinel("error", errorValue, props); | ||
}, | ||
pathValue: function pathValue(path, value) { | ||
return { path: path, value: value }; | ||
}, | ||
pathInvalidation: function pathInvalidation(path) { | ||
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, | ||
undefined: 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 }; | ||
} | ||
}; |
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
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
No tests
QualityPackage does not have any tests. This is a strong signal of a poorly maintained or low quality package.
Found 1 instance in 1 package
49439
15
598
0
28
9
2