lib/main.js
/**
 * Configures Express middleware for composing optional pagination tokens.
 * @param {Object} [options]
 * @param {String} [options.readFrom=query]
 * @param {String} [options.writeTo=pagination]
 * @param {String} [options.uuidKey]
 * @param {String} [options.secret]
 * @return {Function} Configured Express middleware
 */
Configures Express middleware for composing optional pagination tokens.
Configures Express middleware for composing optional pagination tokens .
function tokenize({
  readFrom = 'query',
  writeTo = 'pagination',
  uuidKey,
  secret
} = {}) {
  return (req, {locals}, next) => {
    const {[readFrom]: readRef, list} = locals;
    if (!readRef.count) {
      const {error, value} = cursorCompose(readRef, list, {uuidKey, secret});
      if (error !== null) return next(error);
      locals[writeTo] = {...locals[writeTo], ...value};
    }
    next();
  };
}
function tokenize ( { readFrom = 'query' , writeTo = 'pagination' , uuidKey , secret } = { } ) { return ( req , { locals } , next ) => { const { [ readFrom ] : readRef , list } = locals ; if ( ! readRef . count ) { const { error , value } = cursorCompose ( readRef , list , { uuidKey , secret } ) ; if ( error !== null ) return next ( error ) ; locals [ writeTo ] = { ... locals [ writeTo ] , ... value } ; } next ( ) ; } ; }
Configures Express middleware for composing optional pagination tokens.
Configures Express middleware for composing optional pagination tokens .