mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-08-12 13:00:19 +00:00
Create Falcor definitions (#8882)
* Create Falcor definitions * Rename some interfaces(Upper camel)
This commit is contained in:
committed by
Masahiro Wakame
parent
5387ccca33
commit
98b3d3dc0a
@@ -0,0 +1,25 @@
|
||||
/// <reference path="../express/express.d.ts" />
|
||||
/// <reference path="../falcor/falcor.d.ts" />
|
||||
/// <reference path="../falcor-router/falcor-router.d.ts" />
|
||||
/// <reference path="falcor-express.d.ts" />
|
||||
|
||||
import express = require('express');
|
||||
import Router = require('falcor-router');
|
||||
import falcorExpress = require('falcor-express')
|
||||
|
||||
const app = express();
|
||||
class MyRouter extends Router.createClass([{
|
||||
route: 'greeting',
|
||||
get() {
|
||||
return {json: {greeting: 'Hello, world'}};
|
||||
}
|
||||
}]){
|
||||
constructor() {
|
||||
super();
|
||||
}
|
||||
}
|
||||
|
||||
app.use('/model.json', falcorExpress.dataSourceRoute((req, res) => new MyRouter()));
|
||||
|
||||
app.listen(3000);
|
||||
|
||||
Vendored
+14
@@ -0,0 +1,14 @@
|
||||
// Type definitions for falcor-express 0.1.2
|
||||
// Project: https://github.com/Netflix/falcor-express
|
||||
// Definitions by: Quramy <https://github.com/Quramy/>
|
||||
// Definitions: https://github.com/borisyankov/DefinitelyTyped
|
||||
|
||||
/// <reference path="../falcor/falcor.d.ts" />
|
||||
/// <reference path="../express/express.d.ts" />
|
||||
|
||||
declare module 'falcor-express' {
|
||||
import {Request, Response, Handler} from 'express';
|
||||
import {DataSource} from 'falcor';
|
||||
function dataSourceRoute(getDataSource: (req: Request, res: Response) => DataSource): Handler;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
///<reference path="falcor-http-datasource.d.ts" />
|
||||
|
||||
import HttpDataSource from 'falcor-http-datasource';
|
||||
import {Model} from 'falcor';
|
||||
|
||||
const model = new Model({
|
||||
source: new HttpDataSource('/model.json')
|
||||
});
|
||||
@@ -0,0 +1,23 @@
|
||||
// Type definitions for falcor-http-datasource 0.1.3
|
||||
// Project: https://github.com/Netflix/falcor-http-datasource
|
||||
// Definitions by: Quramy <https://github.com/Quramy/>
|
||||
// Definitions: https://github.com/borisyankov/DefinitelyTyped
|
||||
|
||||
/// <reference path="../falcor/falcor.d.ts" />
|
||||
|
||||
declare namespace FalcorHttpDataSource {
|
||||
|
||||
/**
|
||||
* A HttpDataSource object is a {@link DataSource} can be used to retrieve data from a remote JSONGraph object using the browser's XMLHttpRequest.
|
||||
**/
|
||||
class XMlHttpSource extends FalcorModel.DataSource {
|
||||
constructor(jsonGraphUrl: string);
|
||||
}
|
||||
}
|
||||
|
||||
declare module 'falcor-http-datasource' {
|
||||
import XMlHttpSource = FalcorHttpDataSource.XMlHttpSource;
|
||||
export {XMlHttpSource};
|
||||
export default XMlHttpSource;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
/// <reference path="falcor-json-graph.d.ts" />
|
||||
|
||||
import {Key, KeySet, Path, PathSet, ref, atom, error, pathValue, pathInvalidation} from 'falcor-json-graph';
|
||||
|
||||
const stringKey: Key = "productsById";
|
||||
const numberKey: Key = 10;
|
||||
const booleanKey: Key = true;
|
||||
|
||||
const keySet01: KeySet = stringKey;
|
||||
const keySet02: KeySet = [stringKey];
|
||||
const KeySet03: KeySet = {from: 1, to: 10};
|
||||
const KeySet04: KeySet = ["name", {from: 0, length: 10}];
|
||||
|
||||
const path0: Path = ["productsById", "1234", "name"];
|
||||
const path1: Path = [stringKey, numberKey, booleanKey];
|
||||
|
||||
const pathSet01: PathSet = ["productsById", ["1234", "5678"], ["name", "price"]];
|
||||
const pathSet02: PathSet = ["products", [{from: 0, length: 10}, "length"], ["name", "price"]];
|
||||
|
||||
var ref01 = ref(['hoge']);
|
||||
var ref02 = ref(['hoge'], {$expires: 1000});
|
||||
console.log(ref02.$type, ref02.value, ref02.$expires);
|
||||
|
||||
var atom01 = atom('hoge');
|
||||
var atom02 = atom('hoge', {$expires: 1000});
|
||||
console.log(atom02.$type, atom02.value, atom02.$expires);
|
||||
|
||||
var err01 = error('some error!');
|
||||
var err02 = error('some error!', {$expires: 1000});
|
||||
console.log(err02.$type === 'error', ref02.value, ref02.$expires);
|
||||
|
||||
var pv01 = pathValue('hoge', 'FOO');
|
||||
var pv02 = pathValue('hoge[0].bar', 'FOO');
|
||||
var pv03 = pathValue('hoge[0...100].bar', 'FOO');
|
||||
var pv04 = pathValue(['hoge', {from: 0, to: 100}, 'bar'], 'FOO');
|
||||
console.log(pv04.path, pv04.value);
|
||||
|
||||
var ip01 = pathInvalidation('hoge');
|
||||
console.log(ip01.path, ip01.invalidate);
|
||||
+104
@@ -0,0 +1,104 @@
|
||||
// Type definitions for falcor-json-graph 1.1.7
|
||||
// Project: https://github.com/Netflix/falcor-json-graph
|
||||
// Definitions by: Quramy <https://github.com/Quramy/>
|
||||
// Definitions: https://github.com/borisyankov/DefinitelyTyped
|
||||
|
||||
declare namespace FalcorJsonGraph {
|
||||
|
||||
// NOTE: The following types are described at https://github.com/Netflix/falcor/tree/master/lib/typedefs .
|
||||
|
||||
/**
|
||||
* An atom allows you to treat a JSON value as atomic regardless of its type, ensuring that a JSON object or array is always returned in its entirety. The JSON value must be treated as immutable. Atoms can also be used to associate metadata with a JSON value. This metadata can be used to influence the way values are handled.
|
||||
**/
|
||||
interface Atom extends Sentinel {
|
||||
$type: 'atom';
|
||||
value: any;
|
||||
}
|
||||
|
||||
interface Error extends Sentinel {
|
||||
$type: 'error';
|
||||
value: any;
|
||||
}
|
||||
|
||||
interface InvalidPath {
|
||||
path: PathSet;
|
||||
invalidate: boolean;
|
||||
}
|
||||
/**
|
||||
* A part of a {@link Path} that can be any JSON value type. All types are coerced to string, except null. This makes the number 1 and the string "1" equivalent.
|
||||
**/
|
||||
type Key = string | number | boolean;
|
||||
|
||||
/**
|
||||
* A part of a {@link PathSet} that can be either a {@link Key}, {@link Range}, or Array of either.
|
||||
**/
|
||||
type KeySet = Key | Range | Array<Key | Range>;
|
||||
|
||||
/**
|
||||
* An ordered list of {@link Key}s that point to a value in a {@link JSONGraph}.
|
||||
**/
|
||||
type Path = Array<Key>;
|
||||
|
||||
/**
|
||||
* An ordered list of {@link KeySet}s that point to location(s) in the {@link JSONGraph}. It enables pointing to multiple locations in a more terse format than a set of {@link Path}s and is generally more efficient to evaluate.
|
||||
**/
|
||||
type PathSet = Array<KeySet>;
|
||||
|
||||
/**
|
||||
* A wrapper around a path and its value.
|
||||
**/
|
||||
interface PathValue {
|
||||
path: string | PathSet;
|
||||
value: any;
|
||||
}
|
||||
|
||||
/**
|
||||
* An envelope that wraps a JSON object.
|
||||
**/
|
||||
interface JSONEnvelope<T> {
|
||||
json: T;
|
||||
}
|
||||
|
||||
/**
|
||||
* JavaScript Object Notation Graph (JSONGraph) is a notation for expressing graphs in JSON. For more information, see the [JSONGraph Guide]{@link http://netflix.github.io/falcor/documentation/jsongraph.html}.
|
||||
**/
|
||||
type JSONGraph = any;
|
||||
|
||||
/**
|
||||
* An envelope that wraps a {@link JSONGraph} fragment.
|
||||
**/
|
||||
interface JSONGraphEnvelope {
|
||||
jsonGraph: JSONGraph;
|
||||
paths?: Array<PathSet>;
|
||||
invalidate?: Array<PathSet>;
|
||||
}
|
||||
|
||||
/**
|
||||
* Describe a range of integers. Must contain either a "to" or "length" property.
|
||||
**/
|
||||
interface Range {
|
||||
from?: number;
|
||||
to?: number;
|
||||
length?: number;
|
||||
}
|
||||
|
||||
interface Reference extends Sentinel {
|
||||
$type: 'reference';
|
||||
value: Path;
|
||||
}
|
||||
|
||||
interface Sentinel {
|
||||
$expires?: number;
|
||||
}
|
||||
|
||||
function ref(path: string | FalcorJsonGraph.PathSet, props?: FalcorJsonGraph.Sentinel): FalcorJsonGraph.Reference;
|
||||
function atom (value: any, props?: FalcorJsonGraph.Sentinel): FalcorJsonGraph.Atom;
|
||||
function error(errorValue: any, props?: FalcorJsonGraph.Sentinel): FalcorJsonGraph.Error;
|
||||
function pathValue(path: string | FalcorJsonGraph.PathSet, value: any): FalcorJsonGraph.PathValue;
|
||||
function pathInvalidation(path: string | FalcorJsonGraph.PathSet): FalcorJsonGraph.InvalidPath;
|
||||
}
|
||||
|
||||
declare module 'falcor-json-graph' {
|
||||
export = FalcorJsonGraph;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,102 @@
|
||||
/// <reference path="falcor-router.d.ts" />
|
||||
|
||||
import falcor = require('falcor');
|
||||
import Router = require('falcor-router');
|
||||
|
||||
new Router([]);
|
||||
new Router([], {});
|
||||
new Router([], {debug: true});
|
||||
new Router([], {maxPaths: 10});
|
||||
new Router([], {maxRefFollow: 10});
|
||||
new Router([{route: "greeting", get: () =>({path:["greeting"], value: "Hello World"})}]);
|
||||
|
||||
new falcor.Model({source: new Router([])});
|
||||
|
||||
class MyRouter extends Router.createClass([]) {
|
||||
constructor() {
|
||||
super({debug: true, maxPaths: 10, maxRefFollow: 10});
|
||||
}
|
||||
}
|
||||
new falcor.Model({source: new MyRouter()});
|
||||
|
||||
new Router([{
|
||||
route: 'todos.length',
|
||||
get() {
|
||||
return {path: 'todos.length', value: 10};
|
||||
},
|
||||
}]);
|
||||
|
||||
new Router([{
|
||||
route: 'todos.length',
|
||||
get() {
|
||||
return [{path: 'todos.length', value: 10}];
|
||||
},
|
||||
}]);
|
||||
|
||||
new Router([{
|
||||
route: 'todos.length',
|
||||
get() {
|
||||
return {json: { todos: {length : 10}}};
|
||||
}
|
||||
}]);
|
||||
|
||||
new Router([{
|
||||
route: 'todos.length',
|
||||
get() {
|
||||
return new Promise<falcor.PathValue>(resolve => {
|
||||
resolve({path: 'todos.length', value: 10});
|
||||
});
|
||||
},
|
||||
}]);
|
||||
|
||||
new Router([{
|
||||
route: 'todos.length',
|
||||
get() {
|
||||
return new Promise<falcor.PathValue[]>(resolve => {
|
||||
resolve([{path: 'todos.length', value: 10}]);
|
||||
});
|
||||
},
|
||||
}]);
|
||||
|
||||
new Router([{
|
||||
route: 'todos.length',
|
||||
get() {
|
||||
return new Promise<falcor.JSONEnvelope<any>>(resolve => {
|
||||
resolve({json: { todos: {length : 10}}});
|
||||
});
|
||||
}
|
||||
}]);
|
||||
|
||||
new Router([{
|
||||
route: 'todos[{integers:indicies}]',
|
||||
get(pathset: FalcorRouter.RoutePathSet & {indicies: number[]}) {
|
||||
return pathset.indicies.map(idx => {
|
||||
const id = 'id' + idx;
|
||||
return {
|
||||
path: `todos[${idx}]`,
|
||||
value: {
|
||||
$type: 'ref',
|
||||
value: `todosById.${id}`
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}]);
|
||||
|
||||
new Router([{
|
||||
route: 'todos[{integers:number}]',
|
||||
set(jsonGraph) {
|
||||
return {json: jsonGraph};
|
||||
}
|
||||
}]);
|
||||
|
||||
new Router([{
|
||||
route: 'todos.push',
|
||||
call(callpath, args) {
|
||||
return [
|
||||
{path: 'json.todos.length', value: 11},
|
||||
{path: 'json.todos[10].name', value: args[0].name}
|
||||
];
|
||||
}
|
||||
}]);
|
||||
|
||||
Vendored
+59
@@ -0,0 +1,59 @@
|
||||
// Type definitions for falcor-router 0.4.0
|
||||
// Project: https://github.com/Netflix/falcor-router
|
||||
// Definitions by: Quramy <https://github.com/Quramy/>
|
||||
// Definitions: https://github.com/borisyankov/DefinitelyTyped
|
||||
|
||||
/// <reference path="../falcor/falcor.d.ts" />
|
||||
declare namespace FalcorRouter {
|
||||
|
||||
import DataSource = FalcorModel.DataSource;
|
||||
|
||||
class Router extends DataSource {
|
||||
|
||||
constructor(routes: Array<RouteDefinition>, options?: RouterOptions);
|
||||
|
||||
/**
|
||||
* When a route misses on a call, get, or set the unhandledDataSource will
|
||||
* have a chance to fulfill that request.
|
||||
**/
|
||||
routeUnhandledPathsTo(dataSource: DataSource): void;
|
||||
|
||||
static createClass(routes?: Array<RouteDefinition>): typeof CreatedRouter;
|
||||
}
|
||||
|
||||
class CreatedRouter extends Router {
|
||||
constructor(options?: RouterOptions);
|
||||
}
|
||||
|
||||
interface Route {
|
||||
route: string;
|
||||
}
|
||||
|
||||
type RoutePathSet = FalcorJsonGraph.PathSet;
|
||||
|
||||
interface CallRoute extends Route {
|
||||
call(callPath: RoutePathSet, args: Array<any>): RouteResult | Promise<RouteResult>;
|
||||
}
|
||||
|
||||
interface GetRoute extends Route {
|
||||
get(pathset: RoutePathSet): RouteResult | Promise<RouteResult>;
|
||||
}
|
||||
|
||||
interface SetRoute extends Route {
|
||||
set(jsonGraph: FalcorJsonGraph.JSONGraph): RouteResult | Promise<RouteResult>;
|
||||
}
|
||||
|
||||
type RouteDefinition = GetRoute | SetRoute | CallRoute;
|
||||
type RouteResult = FalcorJsonGraph.PathValue | Array<FalcorJsonGraph.PathValue> | FalcorJsonGraph.JSONEnvelope<any>;
|
||||
|
||||
interface RouterOptions {
|
||||
debug?: boolean;
|
||||
maxPaths?: number;
|
||||
maxRefFollow?: number;
|
||||
}
|
||||
}
|
||||
|
||||
declare module 'falcor-router' {
|
||||
export = FalcorRouter.Router;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
/// <reference path="falcor-browser.d.ts" />
|
||||
|
||||
var model = new falcor.Model({source: new falcor.HttpDataSource('/model.json')});
|
||||
|
||||
model.get('greeting').then(response => {
|
||||
document.write(response.json.greeting);
|
||||
});
|
||||
|
||||
model.set({
|
||||
json: {
|
||||
someAtom: falcor.atom('value'),
|
||||
someRef: falcor.ref('someAtom'),
|
||||
someError: falcor.error('an error'),
|
||||
}
|
||||
});
|
||||
|
||||
model.set(falcor.pathValue('greeting', 'Hello, world'));
|
||||
|
||||
Vendored
+20
@@ -0,0 +1,20 @@
|
||||
// Type definitions for falcor 0.1.17
|
||||
// Project: http://netflix.github.io/falcor/
|
||||
// Definitions by: Quramy <https://github.com/Quramy/>
|
||||
// Definitions: https://github.com/borisyankov/DefinitelyTyped
|
||||
|
||||
/// <reference path="falcor.d.ts" />
|
||||
/// <reference path="../falcor-http-datasource/falcor-http-datasource.d.ts" />
|
||||
|
||||
declare interface FalcorStatic {
|
||||
Model: typeof FalcorModel.Model;
|
||||
DataSource: typeof FalcorModel.DataSource;
|
||||
HttpDataSource: typeof FalcorHttpDataSource.XMlHttpSource;
|
||||
ref: typeof FalcorJsonGraph.ref;
|
||||
atom: typeof FalcorJsonGraph.atom;
|
||||
error: typeof FalcorJsonGraph.error;
|
||||
pathValue: typeof FalcorJsonGraph.pathValue;
|
||||
}
|
||||
|
||||
declare var falcor: FalcorStatic;
|
||||
|
||||
@@ -0,0 +1,132 @@
|
||||
/// <reference path="falcor.d.ts" />
|
||||
|
||||
import falcor = require('falcor');
|
||||
|
||||
let dataSource: falcor.DataSource;
|
||||
dataSource.get([['someParam']]).subscribe(jsonGraphEnvelope => {
|
||||
console.log(jsonGraphEnvelope.jsonGraph);
|
||||
});
|
||||
dataSource.set({
|
||||
jsonGraph: {
|
||||
someParam: 'value',
|
||||
},
|
||||
paths: [['someParam']]
|
||||
}).subscribe(jsonGraphEnvelope => {
|
||||
console.log(jsonGraphEnvelope.jsonGraph);
|
||||
});
|
||||
|
||||
dataSource.call(['items', 'push']);
|
||||
dataSource.call(['items', 'push'], [{id: 'i003', name: 'item003'}]);
|
||||
dataSource.call(['items', 'push'], [{id: 'i003', name: 'item003'}], [['id', 'name']]);
|
||||
dataSource.call(['items', 'push'], [{id: 'i003', name: 'item003'}], [['id', 'name']], [['length']]).subscribe(jsonGraphEnvelope => {
|
||||
console.log(jsonGraphEnvelope.jsonGraph);
|
||||
console.log(jsonGraphEnvelope.invalidate);
|
||||
console.log(jsonGraphEnvelope.paths[0]);
|
||||
});
|
||||
|
||||
new falcor.Model();
|
||||
new falcor.Model({});
|
||||
new falcor.Model({
|
||||
source: dataSource,
|
||||
cache: {},
|
||||
maxSize: 100,
|
||||
collectRatio: 0.5,
|
||||
comparator: (a, b) => {
|
||||
return a === b;
|
||||
},
|
||||
errorSelector: (jsonGraphError: any) => {
|
||||
console.error(jsonGraphError);
|
||||
},
|
||||
onChange: () => {
|
||||
console.log('Changed!');
|
||||
}
|
||||
});
|
||||
|
||||
const model = new falcor.Model({
|
||||
cache: {
|
||||
itemsById: {
|
||||
i01: {id: 'i01', name: 'item 01'},
|
||||
i27: {id: 'i27', name: 'item 27'},
|
||||
},
|
||||
items: [
|
||||
{$type: 'ref', value: ['itemsById', 'i01']},
|
||||
{$type: 'ref', value: ['itemsById', 'i27']},
|
||||
],
|
||||
}
|
||||
});
|
||||
|
||||
model.get('items[0].name');
|
||||
model.get(['items', 0, 'name']);
|
||||
model.get(['items', {from: 0, to: 1}, 'name']);
|
||||
model.get(['items', {from: 0, length: 2, hoge: 3}, 'name']);
|
||||
model.get('items[0].name', 'items[1].name');
|
||||
|
||||
model.set({path: 'items[0].name', value: 'ITEM 01'}, {path: ['items', 1, 'name'], value: 'ITEM 27'});
|
||||
model.set({
|
||||
itemsById: {
|
||||
i01: {
|
||||
name: 'ITEM 01'
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
model.preload();
|
||||
model.preload(['items', 0, 'name']);
|
||||
model.preload(['items', 0, 'name'], ['items', 1, 'name']);
|
||||
model.preload(['items', {from: 0, to: 1}, 'name']);
|
||||
|
||||
model.call('items.push');
|
||||
model.call(['items', 'push']);
|
||||
model.call('items.push', [{id: 'i02', name: 'item02'}], ["length"]);
|
||||
model.call('items.push', [{id: 'i02', name: 'item02'}], ["name", "length"], []);
|
||||
|
||||
model.invalidate();
|
||||
model.invalidate(['items', 0, 'name']);
|
||||
model.invalidate(['items', 0, 'name'], ['items', 1, 'name']);
|
||||
model.invalidate(['items', {from: 0, to: 1}, 'name']);
|
||||
|
||||
model.get('items[0].["name", "id"]').then(res => {
|
||||
const derefedModel = model.deref(res.json.items[0])
|
||||
derefedModel.get('name', 'id');
|
||||
});
|
||||
|
||||
model.getValue('items[0].name').subscribe();
|
||||
model.getValue(['items', 0, 'name']).subscribe();
|
||||
|
||||
model.setValue('items[0].name', 'item001').subscribe();
|
||||
model.setValue(['items', 0, 'name'], 'item001').subscribe();
|
||||
|
||||
model.setCache({itemsById: {}});
|
||||
|
||||
const cache = model.getCache();
|
||||
|
||||
let version: number;
|
||||
version = model.getVersion();
|
||||
version = model.getVersion(['items']);
|
||||
|
||||
const delayedBatchingModel: falcor.Model = model.batch(100);
|
||||
delayedBatchingModel.unbatch();
|
||||
|
||||
const teabModel: falcor.Model = model.treatErrorsAsValues();
|
||||
|
||||
const sourceFromModel: falcor.DataSource = model.asDataSource();
|
||||
|
||||
const boxingModel: falcor.Model = model.boxValues();
|
||||
const unboxingModel: falcor.Model = boxingModel.unboxValues();
|
||||
const noDataSourceModel: falcor.Model = model.withoutDataSource();
|
||||
const somePath: falcor.Path = model.getPath();
|
||||
|
||||
const modelResponse = model.get<{items: {length: number}}>('items.length');
|
||||
|
||||
modelResponse.subscribe();
|
||||
modelResponse.subscribe(res => res.json.items.length);
|
||||
modelResponse.subscribe(res => res.json.items.length, error => console.error.bind(error));
|
||||
modelResponse.subscribe(res => res.json.items.length, error => console.error.bind(error), () => null);
|
||||
|
||||
const subscription = modelResponse.subscribe(res => res);
|
||||
subscription.dispose();
|
||||
|
||||
modelResponse.then(res => res.json.items.length);
|
||||
modelResponse.then(res => res, error => console.error.bind(error));
|
||||
modelResponse.then<number>(res => res.json.items.length).then((l: number) => l + 1);
|
||||
|
||||
Vendored
+277
@@ -0,0 +1,277 @@
|
||||
// Type definitions for falcor 0.1.17
|
||||
// Project: http://netflix.github.io/falcor/
|
||||
// Definitions by: Quramy <https://github.com/Quramy/>
|
||||
// Definitions: https://github.com/borisyankov/DefinitelyTyped
|
||||
|
||||
/// <reference path="../falcor-json-graph/falcor-json-graph.d.ts" />
|
||||
|
||||
declare namespace FalcorModel {
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
// Global types
|
||||
/////////////////////////////////////////////////////
|
||||
|
||||
export import Atom = FalcorJsonGraph.Atom;
|
||||
export import Error = FalcorJsonGraph.Error;
|
||||
export import Key = FalcorJsonGraph.Key;
|
||||
export import KeySet = FalcorJsonGraph.KeySet;
|
||||
export import Path = FalcorJsonGraph.Path;
|
||||
export import PathSet = FalcorJsonGraph.PathSet;
|
||||
export import PathValue = FalcorJsonGraph.PathValue;
|
||||
export import JSONEnvelope = FalcorJsonGraph.JSONEnvelope;
|
||||
export import JSONGraph = FalcorJsonGraph.JSONGraph;
|
||||
export import JSONGraphEnvelope = FalcorJsonGraph.JSONGraphEnvelope;
|
||||
export import Range = FalcorJsonGraph.Range;
|
||||
export import Reference = FalcorJsonGraph.Reference;
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
// DataSource
|
||||
/////////////////////////////////////////////////////
|
||||
|
||||
/**
|
||||
* A DataSource is an interface which can be implemented to expose JSON Graph information to a Model. Every DataSource is associated with a single JSON Graph object. Models execute JSON Graph operations (get, set, and call) to retrieve values from the DataSource’s JSON Graph object. DataSources may retrieve JSON Graph information from anywhere, including device memory, a remote machine, or even a lazily-run computation.
|
||||
**/
|
||||
abstract class DataSource {
|
||||
|
||||
/**
|
||||
* The get method retrieves values from the DataSource's associated JSONGraph object.
|
||||
**/
|
||||
get(pathSets: Array<PathSet>): Observable<JSONGraphEnvelope>;
|
||||
|
||||
|
||||
/**
|
||||
* The set method accepts values to set in the DataSource's associated JSONGraph object.
|
||||
**/
|
||||
set(jsonGraphEnvelope: JSONGraphEnvelope): Observable<JSONGraphEnvelope>;
|
||||
|
||||
|
||||
/**
|
||||
* Invokes a function in the DataSource's JSONGraph object.
|
||||
**/
|
||||
call(functionPath: Path, args?: Array<any>, refSuffixes?: Array<PathSet>, thisPaths?: Array<PathSet>): Observable<JSONGraphEnvelope>;
|
||||
}
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
// Model
|
||||
/////////////////////////////////////////////////////
|
||||
|
||||
interface ModelOptions {
|
||||
source?: DataSource;
|
||||
cache?: JSONGraph;
|
||||
maxSize?: number;
|
||||
collectRatio?: number;
|
||||
errorSelector?: ModelErrorSelector;
|
||||
onChange?: ModelOnChange;
|
||||
comparator?: ModelComparator;
|
||||
}
|
||||
|
||||
/**
|
||||
* This callback is invoked when the Model's cache is changed.
|
||||
**/
|
||||
interface ModelOnChange {
|
||||
(): void;
|
||||
}
|
||||
|
||||
/**
|
||||
* This function is invoked on every JSONGraph Error retrieved from the DataSource. This function allows Error objects to be transformed before being stored in the Model's cache.
|
||||
**/
|
||||
interface ModelErrorSelector {
|
||||
(jsonGraphError: any): any;
|
||||
}
|
||||
|
||||
/**
|
||||
* This function is invoked every time a value in the Model cache is about to be replaced with a new value. If the function returns true, the existing value is replaced with a new value and the version flag on all of the value's ancestors in the tree are incremented.
|
||||
**/
|
||||
interface ModelComparator {
|
||||
(existingValue: any, newValue: any): boolean;
|
||||
}
|
||||
|
||||
/**
|
||||
* A Model object is used to execute commands against a {@link JSONGraph} object. {@link Model}s can work with a local JSONGraph cache, or it can work with a remote {@link JSONGraph} object through a {@link DataSource}.
|
||||
**/
|
||||
class Model {
|
||||
constructor(options?: ModelOptions);
|
||||
|
||||
/**
|
||||
* The get method retrieves several {@link Path}s or {@link PathSet}s from a {@link Model}. The get method loads each value into a JSON object and returns in a ModelResponse.
|
||||
**/
|
||||
get(...path: Array<string | PathSet>): ModelResponse<JSONEnvelope<any>>;
|
||||
get<T>(...path: Array<string | PathSet>): ModelResponse<JSONEnvelope<T>>;
|
||||
|
||||
/**
|
||||
* Sets the value at one or more places in the JSONGraph model. The set method accepts one or more {@link PathValue}s, each of which is a combination of a location in the document and the value to place there. In addition to accepting {@link PathValue}s, the set method also returns the values after the set operation is complete.
|
||||
**/
|
||||
set(...args: Array<PathValue>): ModelResponse<JSONEnvelope<any>>;
|
||||
set<T>(...args: Array<PathValue>): ModelResponse<JSONEnvelope<T>>;
|
||||
set(jsonGraph: JSONGraph): ModelResponse<JSONEnvelope<any>>;
|
||||
set<T>(jsonGraph: JSONGraph): ModelResponse<JSONEnvelope<T>>;
|
||||
|
||||
/**
|
||||
* The preload method retrieves several {@link Path}s or {@link PathSet}s from a {@link Model} and loads them into the Model cache.
|
||||
**/
|
||||
preload(...path: Array<PathSet>): void;
|
||||
|
||||
/**
|
||||
* Invokes a function in the JSON Graph.
|
||||
**/
|
||||
// NOTE: In http://netflix.github.io/falcor/doc/Model.html#call, it says that refPaths should be an array<PathSet>.
|
||||
// However, model implementation returns an error with setting refPaths as Array<PathSet> and it works with refPaths as PathSet.
|
||||
// So refPaths is defined as a PathSet in this .d.ts.
|
||||
call(functionPath: string | Path, args?: Array<any>, refPaths?: PathSet, thisPaths?: Array<PathSet>): ModelResponse<JSONEnvelope<any>>;
|
||||
call<T>(functionPath: string | Path, args?: Array<any>, refPaths?: PathSet, thisPaths?: Array<PathSet>): ModelResponse<JSONEnvelope<T>>;
|
||||
|
||||
/**
|
||||
* The invalidate method synchronously removes several {@link Path}s or {@link PathSet}s from a {@link Model} cache.
|
||||
**/
|
||||
invalidate(...path: Array<PathSet>): void;
|
||||
|
||||
/**
|
||||
* Returns a new {@link Model} bound to a location within the {@link JSONGraph}. The bound location is never a {@link Reference}: any {@link Reference}s encountered while resolving the bound {@link Path} are always replaced with the {@link Reference}s target value. For subsequent operations on the {@link Model}, all paths will be evaluated relative to the bound path. Deref allows you to:
|
||||
* - Expose only a fragment of the {@link JSONGraph} to components, rather than the entire graph
|
||||
* - Hide the location of a {@link JSONGraph} fragment from components
|
||||
* - Optimize for executing multiple operations and path looksup at/below the same location in the {@link JSONGraph}
|
||||
**/
|
||||
deref(responseObject: any): Model;
|
||||
|
||||
/**
|
||||
* Get data for a single {@link Path}.
|
||||
**/
|
||||
getValue(path: string | Path): ModelResponse<any>;
|
||||
getValue<T>(path: string | Path): ModelResponse<T>;
|
||||
|
||||
/**
|
||||
* Set value for a single {@link Path}.
|
||||
**/
|
||||
setValue(path: string | Path, value: any): ModelResponse<any>;
|
||||
setValue<T>(path: string | Path, value: any): ModelResponse<T>;
|
||||
|
||||
/**
|
||||
* Set the local cache to a {@link JSONGraph} fragment. This method can be a useful way of mocking a remote document, or restoring the local cache from a previously stored state.
|
||||
**/
|
||||
setCache(jsonGraph: JSONGraph): void;
|
||||
|
||||
/**
|
||||
* Get the local {@link JSONGraph} cache. This method can be a useful to store the state of the cache.
|
||||
**/
|
||||
getCache(...path: Array<PathSet>): JSONGraph;
|
||||
|
||||
/**
|
||||
* Retrieves a number which is incremented every single time a value is changed underneath the Model or the object at an optionally-provided Path beneath the Model.
|
||||
**/
|
||||
getVersion(path?: Path): number;
|
||||
|
||||
/**
|
||||
* Returns a clone of the {@link Model} that enables batching. Within the configured time period, paths for get operations are collected and sent to the {@link DataSource} in a batch. Batching can be more efficient if the {@link DataSource} access the network, potentially reducing the number of HTTP requests to the server.
|
||||
**/
|
||||
batch(schedulerOrDelay?: number | Scheduler): Model; // FIXME what's a valid type for scheduler?
|
||||
|
||||
/**
|
||||
* Returns a clone of the {@link Model} that disables batching. This is the default mode. Each get operation will be executed on the {@link DataSource} separately.
|
||||
**/
|
||||
unbatch(): Model;
|
||||
|
||||
/**
|
||||
* Returns a clone of the {@link Model} that treats errors as values. Errors will be reported in the same callback used to report data. Errors will appear as objects in responses, rather than being sent to the {@link Observable~onErrorCallback} callback of the {@link ModelResponse}.
|
||||
**/
|
||||
treatErrorsAsValues(): Model;
|
||||
|
||||
/**
|
||||
* Adapts a Model to the {@link DataSource} interface.
|
||||
**/
|
||||
asDataSource(): DataSource;
|
||||
|
||||
/**
|
||||
* Returns a clone of the {@link Model} that boxes values returning the wrapper ({@link Atom}, {@link Reference}, or {@link Error}), rather than the value inside it. This allows any metadata attached to the wrapper to be inspected.
|
||||
**/
|
||||
boxValues(): Model;
|
||||
|
||||
/**
|
||||
* Returns a clone of the {@link Model} that unboxes values, returning the value inside of the wrapper ({@link Atom}, {@link Reference}, or {@link Error}), rather than the wrapper itself. This is the default mode.
|
||||
**/
|
||||
unboxValues(): Model;
|
||||
|
||||
/**
|
||||
* Returns a clone of the {@link Model} that only uses the local {@link JSONGraph} and never uses a {@link DataSource} to retrieve missing paths.
|
||||
**/
|
||||
withoutDataSource(): Model;
|
||||
|
||||
/**
|
||||
* Returns the {@link Path} to the object within the JSON Graph that this Model references.
|
||||
**/
|
||||
getPath(): Path;
|
||||
}
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
// ModelResponse
|
||||
/////////////////////////////////////////////////////
|
||||
|
||||
class ModelResponse<T> extends Observable<T>{
|
||||
constructor(observable: Observable<T>);
|
||||
progressively(): ModelResponse<JSONEnvelope<T>>;
|
||||
forEach(onNext: (value: T) => void, onError?: (error: Error) => void, onCompleted?: () => void): Subscription;
|
||||
then(onFulfilled?: (value: T) => any | Thenable<any>, onRejected?: (error: any) => void): Thenable<any>;
|
||||
then<U>(onFulfilled?: (value: T) => U | Thenable<U>, onRejected?: (error: any) => void): Thenable<U>;
|
||||
}
|
||||
|
||||
interface Thenable<T> {
|
||||
then<U>(onFulfilled?: (value: T) => U | Thenable<U>, onRejected?: (error: any) => U | Thenable<U>): Thenable<U>;
|
||||
then<U>(onFulfilled?: (value: T) => U | Thenable<U>, onRejected?: (error: any) => void): Thenable<U>;
|
||||
}
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
// Observable
|
||||
/////////////////////////////////////////////////////
|
||||
|
||||
class Observable<T>{
|
||||
|
||||
/**
|
||||
* The forEach method is a synonym for {@link Observable.prototype.subscribe} and triggers the execution of the Observable, causing the values within to be pushed to a callback. An Observable is like a pipe of water that is closed. When forEach is called, we open the valve and the values within are pushed at us. These values can be received using either callbacks or an {@link Observer} object.
|
||||
**/
|
||||
forEach(onNext?: ObservableOnNextCallback<T>, onError?: ObservableOnErrorCallback , onCompleted?: ObservableOnCompletedCallback ): Subscription;
|
||||
|
||||
/**
|
||||
* The subscribe method is a synonym for {@link Observable.prototype.forEach} and triggers the execution of the Observable, causing the values within to be pushed to a callback. An Observable is like a pipe of water that is closed. When forEach is called, we open the valve and the values within are pushed at us. These values can be received using either callbacks or an {@link Observer} object.
|
||||
**/
|
||||
subscribe(onNext?: ObservableOnNextCallback<T>, onError?: ObservableOnErrorCallback , onCompleted?: ObservableOnCompletedCallback ): Subscription;
|
||||
}
|
||||
|
||||
/**
|
||||
* This callback accepts a value that was emitted while evaluating the operation underlying the {@link Observable} stream.
|
||||
**/
|
||||
interface ObservableOnNextCallback<T> {
|
||||
(value: T): void;
|
||||
}
|
||||
|
||||
/**
|
||||
* This callback accepts an error that occurred while evaluating the operation underlying the {@link Observable} stream. When this callback is invoked, the {@link Observable} stream ends and no more values will be received by the {@link Observable~onNextCallback}.
|
||||
**/
|
||||
interface ObservableOnErrorCallback {
|
||||
(error: Error): void;
|
||||
}
|
||||
|
||||
/**
|
||||
* This callback is invoked when the {@link Observable} stream ends. When this callback is invoked the {@link Observable} stream has ended, and therefore the {@link Observable~onNextCallback} will not receive any more values.
|
||||
**/
|
||||
interface ObservableOnCompletedCallback {
|
||||
(): void;
|
||||
}
|
||||
|
||||
class Subscription {
|
||||
/**
|
||||
* When this method is called on the Subscription, the Observable that created the Subscription will stop sending values to the callbacks passed when the Subscription was created.
|
||||
**/
|
||||
dispose(): void;
|
||||
}
|
||||
|
||||
interface Scheduler {
|
||||
catch(handler: (exception: any) => boolean): Scheduler;
|
||||
catchException(handler: (exception: any) => boolean): Scheduler;
|
||||
}
|
||||
}
|
||||
|
||||
declare module 'falcor' {
|
||||
export = FalcorModel;
|
||||
}
|
||||
Reference in New Issue
Block a user