aboutsummaryrefslogtreecommitdiff
path: root/node_modules/app-builder/lib
diff options
context:
space:
mode:
authorMinteck <nekostarfan@gmail.com>2021-08-24 14:41:48 +0200
committerMinteck <nekostarfan@gmail.com>2021-08-24 14:41:48 +0200
commitd25e11bee6ca5ca523884da132d18e1400e077b9 (patch)
tree8af39fde19f7ed640a60fb397c7edd647dff1c4c /node_modules/app-builder/lib
downloadkartik-iridium-d25e11bee6ca5ca523884da132d18e1400e077b9.tar.gz
kartik-iridium-d25e11bee6ca5ca523884da132d18e1400e077b9.tar.bz2
kartik-iridium-d25e11bee6ca5ca523884da132d18e1400e077b9.zip
Initial commit
Diffstat (limited to 'node_modules/app-builder/lib')
-rw-r--r--node_modules/app-builder/lib/app-builder.d.ts8
-rw-r--r--node_modules/app-builder/lib/app-builder.js29
-rw-r--r--node_modules/app-builder/lib/compose.d.ts13
-rw-r--r--node_modules/app-builder/lib/compose.js48
-rw-r--r--node_modules/app-builder/lib/test.spec.d.ts1
5 files changed, 99 insertions, 0 deletions
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<T = any> {
+ private middleware;
+ build(): ContinuationMiddleware<T>;
+ use(mw: Middleware<T>): this;
+}
+export default function createAppBuilder<T = any>(): AppBuilder<T>;
+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<T> {
+ (context: T, next: ContinuationMiddleware<T>): any;
+}
+export interface ContinuationMiddleware<T> {
+ (context?: T, next?: Middleware<T>): any;
+}
+export declare function functionList<T = any>(list: Function | Function[], ...args: any[]): Middleware<T>[];
+/**
+ * Create a function to invoke all passed middleware functions
+ * with a single argument <T>context
+ * @param middleware
+ */
+export declare function compose<T = any>(...middleware: (Middleware<T> | Middleware<T>[])[]): ContinuationMiddleware<T>;
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 <T>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,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY29tcG9zZS5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3NyYy9jb21wb3NlLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7O0FBT0EsTUFBTSxPQUFPLEdBQUcsQ0FBSSxNQUEyQixFQUFFLEVBQUUsQ0FBRSxFQUFVLENBQUMsTUFBTSxDQUFDLEdBQUcsTUFBTSxDQUFRLEVBQ3RGLElBQUksR0FBRyxTQUFTLElBQUk7SUFDbEIsT0FBTyxPQUFPLENBQUMsT0FBTyxFQUFFLENBQUE7QUFDMUIsQ0FBQyxDQUFBO0FBRUgsU0FBUyxvQkFBb0IsQ0FBQyxFQUFPO0lBQ25DLElBQUksRUFBRSxDQUFDLGtCQUFrQixFQUFFO1FBQ3pCLE1BQU0sSUFBSSxLQUFLLENBQUMsaUNBQWlDLENBQUMsQ0FBQTtLQUNuRDtJQUNELE9BQU8sQ0FBQyxFQUFFLENBQUMsa0JBQWtCLEdBQUcsSUFBSSxDQUFDLENBQUE7QUFDdkMsQ0FBQztBQUVELFNBQVMsbUJBQW1CLENBQUksT0FBVSxFQUFFLFVBQXlCLEVBQUUsT0FBa0MsSUFBSTtJQUMzRyxJQUFJO1FBQ0YsT0FBTyxPQUFPLENBQUMsT0FBTyxDQUFDLFVBQVUsQ0FBQyxDQUFDLENBQUMsVUFBVSxDQUFDLE9BQU8sRUFBRSxJQUFJLENBQUMsQ0FBQyxDQUFDLENBQUMsT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UFPLFVBQVUsT0FBVSxFQUFFLE1BQWlDO1lBQzVELE1BQU0sSUFBSSxHQUFHLEdBQUcsRUFBRSxDQUFDLG9CQUFvQixDQUFDLElBQUksQ0FBQyxJQUFJLFFBQVEsQ0FBQyxPQUFPLEVBQUUsTUFBTSxDQUFDLENBQUE7WUFDMUUsT0FBTyxtQkFBbUIsQ0FBQyxPQUFPLEVBQUUsRUFBRSxFQUFFLElBQUksQ0FBQyxDQUFBO1FBQy9DLENBQUMsQ0FBQTtJQUNILENBQUMsRUFBRSxtQkFBbUIsQ0FBOEIsQ0FBQTtBQUN4RCxDQUFDO0FBZEQsMEJBY0MifQ== \ 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 {};