Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

falcor-json-graph

Package Overview
Dependencies
Maintainers
3
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

falcor-json-graph - npm Package Compare versions

Comparing version 2.0.0 to 2.1.0

.eslintrc

31

package.json
{
"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"])
```

@@ -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 };
}
};
.npmignore
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc