From d25e11bee6ca5ca523884da132d18e1400e077b9 Mon Sep 17 00:00:00 2001 From: Minteck Date: Tue, 24 Aug 2021 14:41:48 +0200 Subject: Initial commit --- node_modules/app-builder/lib/app-builder.d.ts | 8 +++++ node_modules/app-builder/lib/app-builder.js | 29 ++++++++++++++++ node_modules/app-builder/lib/compose.d.ts | 13 ++++++++ node_modules/app-builder/lib/compose.js | 48 +++++++++++++++++++++++++++ node_modules/app-builder/lib/test.spec.d.ts | 1 + 5 files changed, 99 insertions(+) create mode 100644 node_modules/app-builder/lib/app-builder.d.ts create mode 100644 node_modules/app-builder/lib/app-builder.js create mode 100644 node_modules/app-builder/lib/compose.d.ts create mode 100644 node_modules/app-builder/lib/compose.js create mode 100644 node_modules/app-builder/lib/test.spec.d.ts (limited to 'node_modules/app-builder/lib') diff --git a/node_modules/app-builder/lib/app-builder.d.ts b/node_modules/app-builder/lib/app-builder.d.ts new file mode 100644 index 0000000..e475725 --- /dev/null +++ b/node_modules/app-builder/lib/app-builder.d.ts @@ -0,0 +1,8 @@ +import { compose, Middleware, ContinuationMiddleware, functionList } from './compose'; +export declare class AppBuilder { + private middleware; + build(): ContinuationMiddleware; + use(mw: Middleware): this; +} +export default function createAppBuilder(): AppBuilder; +export { compose, functionList, Middleware, ContinuationMiddleware }; diff --git a/node_modules/app-builder/lib/app-builder.js b/node_modules/app-builder/lib/app-builder.js new file mode 100644 index 0000000..c2c0cd4 --- /dev/null +++ b/node_modules/app-builder/lib/app-builder.js @@ -0,0 +1,29 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const compose_1 = require("./compose"); +exports.compose = compose_1.compose; +exports.functionList = compose_1.functionList; +class AppBuilder { + constructor() { + this.middleware = []; + } + build() { + if (!this.middleware.length) { + throw new Error('Usage error: must have at least one middleware'); + } + return compose_1.compose(this.middleware); + } + use(mw) { + if ('function' !== typeof mw) { + throw new TypeError(`${mw}, must be a middleware function accpeting (context, next) arguments`); + } + this.middleware.push(mw); + return this; + } +} +exports.AppBuilder = AppBuilder; +function createAppBuilder() { + return new AppBuilder(); +} +exports.default = createAppBuilder; +//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiYXBwLWJ1aWxkZXIuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi9zcmMvYXBwLWJ1aWxkZXIudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7QUFBQSx1Q0FBcUY7QUF5QjVFLGtCQXpCQSxpQkFBTyxDQXlCQTtBQUFFLHVCQXpCb0Msc0JBQVksQ0F5QnBDO0FBdkI5QixNQUFhLFVBQVU7SUFBdkI7UUFDVSxlQUFVLEdBQXlCLEVBQUUsQ0FBQTtJQWdCL0MsQ0FBQztJQWRDLEtBQUs7UUFDSCxJQUFJLENBQUMsSUFBSSxDQUFDLFVBQVUsQ0FBQyxNQUFNLEVBQUU7WUFDM0IsTUFBTSxJQUFJLEtBQUssQ0FBQyxnREFBZ0QsQ0FBQyxDQUFBO1NBQ2xFO1FBQ0QsT0FBTyxpQkFBTyxDQUFDLElBQUksQ0FBQyxVQUFVLENBQUMsQ0FBQTtJQUNqQyxDQUFDO0lBRUQsR0FBRyxDQUFDLEVBQWlCO1FBQ25CLElBQUksVUFBVSxLQUFLLE9BQU8sRUFBRSxFQUFFO1lBQzVCLE1BQU0sSUFBSSxTQUFTLENBQUMsR0FBRyxFQUFFLHFFQUFxRSxDQUFDLENBQUE7U0FDaEc7UUFDRCxJQUFJLENBQUMsVUFBVSxDQUFDLElBQUksQ0FBQyxFQUFFLENBQUMsQ0FBQTtRQUN4QixPQUFPLElBQUksQ0FBQTtJQUNiLENBQUM7Q0FDRjtBQWpCRCxnQ0FpQkM7QUFFRCxTQUF3QixnQkFBZ0I7SUFDdEMsT0FBTyxJQUFJLFVBQVUsRUFBSyxDQUFBO0FBQzVCLENBQUM7QUFGRCxtQ0FFQyJ9 \ No newline at end of file diff --git a/node_modules/app-builder/lib/compose.d.ts b/node_modules/app-builder/lib/compose.d.ts new file mode 100644 index 0000000..7c848af --- /dev/null +++ b/node_modules/app-builder/lib/compose.d.ts @@ -0,0 +1,13 @@ +export interface Middleware { + (context: T, next: ContinuationMiddleware): any; +} +export interface ContinuationMiddleware { + (context?: T, next?: Middleware): any; +} +export declare function functionList(list: Function | Function[], ...args: any[]): Middleware[]; +/** + * Create a function to invoke all passed middleware functions + * with a single argument context + * @param middleware + */ +export declare function compose(...middleware: (Middleware | Middleware[])[]): ContinuationMiddleware; diff --git a/node_modules/app-builder/lib/compose.js b/node_modules/app-builder/lib/compose.js new file mode 100644 index 0000000..e615d57 --- /dev/null +++ b/node_modules/app-builder/lib/compose.js @@ -0,0 +1,48 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const flatten = (values) => [].concat(...values), noop = function noop() { + return Promise.resolve(); +}; +function throwIfHasBeenCalled(fn) { + if (fn.__appbuildercalled) { + throw new Error('Cannot call next more than once'); + } + return (fn.__appbuildercalled = true); +} +function tryInvokeMiddleware(context, middleware, next = noop) { + try { + return Promise.resolve(middleware ? middleware(context, next) : context); + } + catch (error) { + return Promise.reject(error); + } +} +function functionList(list, ...args) { + const arrayList = Symbol.iterator in list ? Array.from(list) : [list]; + return arrayList.map((x) => { + return (_, next) => Promise.resolve(x(...args)).then(next); + }); +} +exports.functionList = functionList; +/** + * Create a function to invoke all passed middleware functions + * with a single argument context + * @param middleware + */ +function compose(...middleware) { + return flatten(middleware) + .filter((x) => { + if ('function' !== typeof x) { + throw new TypeError(`${x}, must be a middleware function accpeting (context, next) arguments`); + } + return x; + }) + .reduceRight((composed, mw) => { + return function (context, nextFn) { + const next = () => throwIfHasBeenCalled(next) && composed(context, nextFn); + return tryInvokeMiddleware(context, mw, next); + }; + }, tryInvokeMiddleware); +} +exports.compose = compose; +//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY29tcG9zZS5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2Vz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O0FBZEQsMEJBY0MifQ== \ No newline at end of file diff --git a/node_modules/app-builder/lib/test.spec.d.ts b/node_modules/app-builder/lib/test.spec.d.ts new file mode 100644 index 0000000..cb0ff5c --- /dev/null +++ b/node_modules/app-builder/lib/test.spec.d.ts @@ -0,0 +1 @@ +export {}; -- cgit