UNPKG

traverson

Version:

Hypermedia API/HATEOAS client for Node.js and the browser

28 lines (23 loc) 851 B
'use strict'; var minilog = require('minilog') , log = minilog('traverson'); /* * This transform is meant to be run at the very end of a getResource call. It * just extracts the last doc from the step and calls t.callback with it. */ module.exports = function extractDoc(t) { log.debug('walker.walk has finished'); /* TODO Breaks a lot of tests although it seems to make perfect sense?!? if (!t.doc) { t.callback(createError('No document available', errors.InvalidStateError)); return false; } */ t.callback(null, t.step.doc); // This is a so called final transform that is only applied at the very end // and it always calls t.callback - in contrast to other transforms it does // not call t.callback in the error case, but as a success. // We return false to make sure processing ends here. return false; };