diff --git a/falcor-router/falcor-router-tests.ts b/falcor-router/falcor-router-tests.ts index 5f5bdca0e4..7358ab2e02 100644 --- a/falcor-router/falcor-router-tests.ts +++ b/falcor-router/falcor-router-tests.ts @@ -2,6 +2,7 @@ import falcor = require('falcor'); import Router = require('falcor-router'); +import falcorJsonGraph = require('falcor-json-graph'); new Router([]); new Router([], {}); @@ -100,3 +101,76 @@ new Router([{ } }]); +new Router([{ + route: 'todos.new', + call(callpath, args) { + return {path: 'json.todosById.1234.name', value: 'Buy cheese'}; + } +}]); + +new Router([{ + route: 'todos.new', + call(callpath, args) { + return falcorJsonGraph.pathInvalidation('json.todos.length'); + } +}]); + +new Router([{ + route: 'todos.new', + call(callpath, args) { + return [ + falcorJsonGraph.pathInvalidation('json.todos.length'), + {path: 'json.todosById.1234.name', value: 'Buy cheese'} + ] + } +}]); + +new Router([{ + route: 'todos.new', + call(callpath, args) { + return new Promise((resolve, reject): void => { + resolve([ + falcorJsonGraph.pathInvalidation('json.todos.length'), + {path: 'json.todosById.1234.name', value: 'Buy cheese'} + ]); + }); + } +}]); + +new Router([{ + route: 'todos.new', + call(callpath, args) { + return { + paths: [['json', 'todosById', '1234', 'name']], + jsonGraph: { + json: { + todosById: { + 1234: { + name: 'Buy cheese' + } + } + } + } + }; + } +}]); + +new Router([{ + route: 'todos.new', + call(callpath, args) { + return new Promise((resolve, reject): void => { + resolve({ + paths: [['json', 'todosById', '1234', 'name']], + jsonGraph: { + json: { + todosById: { + 1234: { + name: 'Buy cheese' + } + } + } + } + }); + }); + } +}]); diff --git a/falcor-router/index.d.ts b/falcor-router/index.d.ts index 659f45767f..daef26f379 100644 --- a/falcor-router/index.d.ts +++ b/falcor-router/index.d.ts @@ -1,6 +1,6 @@ // Type definitions for falcor-router 0.4.0 // Project: https://github.com/Netflix/falcor-router -// Definitions by: Quramy +// Definitions by: Quramy , cdhgee // Definitions: https://github.com/borisyankov/DefinitelyTyped /// @@ -34,7 +34,7 @@ declare namespace FalcorRouter { type RoutePathSet = FalcorJsonGraph.PathSet; interface CallRoute extends Route { - call(callPath: RoutePathSet, args: Array): RouteResult | Promise; + call(callPath: RoutePathSet, args: Array): CallRouteResult | Promise; } interface GetRoute extends Route { @@ -47,6 +47,7 @@ declare namespace FalcorRouter { type RouteDefinition = GetRoute | SetRoute | CallRoute; type RouteResult = FalcorJsonGraph.PathValue | Array | FalcorJsonGraph.JSONEnvelope; + type CallRouteResult = FalcorJsonGraph.PathValue | FalcorJsonGraph.InvalidPath | Array | FalcorJsonGraph.JSONGraphEnvelope; interface RouterOptions { debug?: boolean;