-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(onUnhandled*): UnhandledGet works as specced.
Unhandled paths that are from get requests will be fed to the unhandled handler after the get operation. The results from the handler will be merged into the overal results. Any subsequent missing data will be materialized.
- Loading branch information
1 parent
10d6a26
commit ed15ff2
Showing
21 changed files
with
614 additions
and
214 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
var runGetAction = require('../run/get/runGetAction'); | ||
var get = 'get'; | ||
var recurseMatchAndExecute = require('../run/recurseMatchAndExecute'); | ||
var normalizePathSets = require('../operations/ranges/normalizePathSets'); | ||
var materialize = require('../run/materialize'); | ||
var Observable = require('rx').Observable; | ||
|
||
/** | ||
* The router get function | ||
*/ | ||
module.exports = function routerGet(paths) { | ||
var jsongCache = {}; | ||
var router = this; | ||
var action = runGetAction(router, jsongCache); | ||
var normPS = normalizePathSets(paths); | ||
return recurseMatchAndExecute(router._matcher, action, normPS, | ||
get, router, jsongCache). | ||
|
||
// Turn it(jsongGraph, invalidations, missing, etc.) into a | ||
// jsonGraph envelope | ||
flatMap(function flatMapAfterRouterGet(details) { | ||
var out = { | ||
jsonGraph: details.jsonGraph | ||
}; | ||
|
||
|
||
// If the unhandledPaths are present then we need to | ||
// call the backup method for generating materialized. | ||
if (details.unhandledPaths.length && router._unhandled.get) { | ||
var unhandledPaths = details.unhandledPaths; | ||
|
||
// The 3rd argument is the beginning of the actions arguments, | ||
// which for get is the same as the unhandledPaths. | ||
return router._unhandled.get(out, | ||
unhandledPaths, | ||
unhandledPaths); | ||
} | ||
|
||
return Observable.return(out); | ||
}). | ||
|
||
// We will continue to materialize over the whole jsonGraph message. | ||
// This makes sense if you think about pathValues and an API that if | ||
// ask for a range of 10 and only 8 were returned, it would not | ||
// materialize for you, instead, allow the router to do that. | ||
map(function(jsonGraphEnvelope) { | ||
return materialize(router, normPS, jsonGraphEnvelope); | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
var JSONGraphError = require('./../../errors/JSONGraphError'); | ||
module.exports = function errorToPathValue(error, path) { | ||
var typeValue = { | ||
$type: 'error', | ||
value: {} | ||
}; | ||
|
||
if (error.throwToNext) { | ||
throw error; | ||
} | ||
|
||
// If it is a special JSONGraph error then pull all the data | ||
if (error instanceof JSONGraphError) { | ||
typeValue = error.typeValue; | ||
} | ||
|
||
else if (error instanceof Error) { | ||
typeValue.value.message = error.message; | ||
} | ||
|
||
return { | ||
path: path, | ||
value: typeValue | ||
}; | ||
}; |
Oops, something went wrong.