@orion-js/helpers 3.3.20 → 3.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Compose `middleware` returning
3
+ * a fully valid middleware comprised
4
+ * of all those which are passed.
5
+ */
6
+ export declare function composeMiddlewares(middleware: any): (context: any, next?: any) => Promise<any>;
@@ -0,0 +1,44 @@
1
+ "use strict";
2
+ // from https://github.com/koajs/compose/blob/master/index.js
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.composeMiddlewares = void 0;
5
+ /**
6
+ * Compose `middleware` returning
7
+ * a fully valid middleware comprised
8
+ * of all those which are passed.
9
+ */
10
+ function composeMiddlewares(middleware) {
11
+ if (!Array.isArray(middleware))
12
+ throw new TypeError('Middleware stack must be an array!');
13
+ for (const fn of middleware) {
14
+ if (typeof fn !== 'function')
15
+ throw new TypeError('Middleware must be composed of functions!');
16
+ }
17
+ /**
18
+ * @param {Object} context
19
+ * @return {Promise}
20
+ * @api public
21
+ */
22
+ return function (context, next) {
23
+ // last called middleware #
24
+ let index = -1;
25
+ return dispatch(0);
26
+ function dispatch(i) {
27
+ if (i <= index)
28
+ return Promise.reject(new Error('next() called multiple times'));
29
+ index = i;
30
+ let fn = middleware[i];
31
+ if (i === middleware.length)
32
+ fn = next;
33
+ if (!fn)
34
+ return Promise.resolve();
35
+ try {
36
+ return Promise.resolve(fn(context, dispatch.bind(null, i + 1)));
37
+ }
38
+ catch (err) {
39
+ return Promise.reject(err);
40
+ }
41
+ }
42
+ };
43
+ }
44
+ exports.composeMiddlewares = composeMiddlewares;
package/lib/index.d.ts CHANGED
@@ -6,4 +6,5 @@ import { OrionError, OrionErrorInformation } from './Errors/OrionError';
6
6
  import PermissionsError from './Errors/PermissionsError';
7
7
  import UserError from './Errors/UserError';
8
8
  import createMapArray from './createMapArray';
9
+ export * from './composeMiddlewares';
9
10
  export { createMap, createMapArray, generateId, hashObject, sleep, OrionError, PermissionsError, UserError, OrionErrorInformation };
package/lib/index.js CHANGED
@@ -1,4 +1,14 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ }) : (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ o[k2] = m[k];
8
+ }));
9
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
10
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
11
+ };
2
12
  var __importDefault = (this && this.__importDefault) || function (mod) {
3
13
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
14
  };
@@ -20,3 +30,4 @@ const UserError_1 = __importDefault(require("./Errors/UserError"));
20
30
  exports.UserError = UserError_1.default;
21
31
  const createMapArray_1 = __importDefault(require("./createMapArray"));
22
32
  exports.createMapArray = createMapArray_1.default;
33
+ __exportStar(require("./composeMiddlewares"), exports);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@orion-js/helpers",
3
- "version": "3.3.20",
3
+ "version": "3.5.0",
4
4
  "main": "lib/index.js",
5
5
  "author": "nicolaslopezj",
6
6
  "license": "MIT",
@@ -23,5 +23,5 @@
23
23
  "publishConfig": {
24
24
  "access": "public"
25
25
  },
26
- "gitHead": "fc4d8447758abffb74834f58443e7489cee3a454"
26
+ "gitHead": "6fc8b0e40fad04d7ff84cf0849cbf260a66b6641"
27
27
  }