esfunctional
Advanced tools
Comparing version 1.0.4 to 1.0.5
@@ -380,1 +380,76 @@ 'use strict'; | ||
global.delay = (msec) => new Promise((ok) => setTimeout(ok, msec)); | ||
// express helpers globals | ||
/** | ||
* @callback Next | ||
* @description Callback given by Express to call for executing next middleware. | ||
* @param {*} data Data to pass to next middleware | ||
* @param {Response} res | ||
* @param {Next} next | ||
*/ | ||
/** | ||
* @callback Middleware | ||
* @description Callback is called by Express to process the request, make a response and/or call next middleware. | ||
* @param {Request} req A request from client. | ||
* @param {Response} res A response to be replied to client | ||
* @param {Next} next Call next middleware | ||
*/ | ||
/** | ||
* @callback Promiseware | ||
* @description A Promise-optimal middleware, which gets converted to native Express middleware | ||
* to take advantage of using Promises and functional programming. | ||
* @param {Request} req A request from client. `req.res` is a `Response`. | ||
* @returns {Promise} A Promise, which is resolved to call the next middleware. | ||
*/ | ||
/** | ||
* @name errorware | ||
* @description Symbol, indicating an erroneous object after `promiseware` or `spawnware`. | ||
* Use `oldPromise [catchify] ()`. | ||
* @type {Symbol} | ||
*/ | ||
global.errorware = Symbol('errorware'); | ||
/** | ||
* @function promiseware | ||
* @description Convert Promise-optimal representation of middleware to native Express middleware. | ||
* @param {Promiseware} func A promiseware to be converted. | ||
* @returns {Middleware} An Express middleware. | ||
*/ | ||
global.promiseware = (func) => (req, res, next) => ( | ||
global.vala(req) | ||
[global.thena](func) | ||
[global.thena](next) | ||
[global.catcha]((err) => { | ||
if (err != null) err[global.errorware] = true; | ||
next(err); | ||
}) | ||
); | ||
/** | ||
* @function spawnware | ||
* @description Convert Promise-optimal and Spawn-style representation of middleware to native Express middleware. | ||
* @param {Spawnware} func A promiseware to be converted. | ||
* @returns {Middleware} An Express middleware. | ||
*/ | ||
global.spawnware = (func) => global.promiseware((req) => global.spawn(func, req)); | ||
// mongoose helpers | ||
/** | ||
* @function indexesFor | ||
* @description Create a function, which is called to set indexes for `Schema`. | ||
* @param {Schema} schema A schema to create index-declaring function to. | ||
* @returns {IndexMaker} A function which should be called to make indexes. | ||
*/ | ||
global.indexesFor = (schema) => (sort, opts) => (!opts || !opts.disabled) && schema.index(sort, opts) && sort; | ||
/** | ||
* @name byId | ||
* @description An object, used in hints etc. to identify usage of only `_id` path. | ||
* @type {Object} | ||
*/ | ||
global.byId = {_id: 1}; |
{ | ||
"name": "esfunctional", | ||
"version": "1.0.4", | ||
"version": "1.0.5", | ||
"description": "Next Generation EcmaScript Functional Helpers", | ||
@@ -5,0 +5,0 @@ "main": "lib/v1/index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
15432
378