@guanghechen/middleware 1.0.0-alpha.1

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.
package/CHANGELOG.md ADDED
@@ -0,0 +1,11 @@
1
+ # Change Log
2
+
3
+ All notable changes to this project will be documented in this file.
4
+ See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
+
6
+ # 1.0.0-alpha.1 (2023-10-10)
7
+
8
+
9
+ ### Features
10
+
11
+ * ✨ add @guanghechen/middleware ([dada126](https://github.com/guanghechen/sora/commit/dada12623f1fcbe3d4968ba80fbc5bfb75ee6116))
@@ -0,0 +1,40 @@
1
+ 'use strict';
2
+
3
+ var middleware_types = require('@guanghechen/middleware.types');
4
+
5
+ class AsyncMiddlewares {
6
+ _middlewares;
7
+ constructor() {
8
+ this._middlewares = [];
9
+ }
10
+ use(middleware) {
11
+ this._middlewares.push(middleware);
12
+ }
13
+ reducer(input, api) {
14
+ const reducer = this._middlewares.reduceRight((next, middleware) => embryo => middleware(input, embryo, api, next), async (embryo) => embryo);
15
+ return reducer;
16
+ }
17
+ }
18
+
19
+ class Middlewares {
20
+ _middlewares;
21
+ constructor() {
22
+ this._middlewares = [];
23
+ }
24
+ use(middleware) {
25
+ this._middlewares.push(middleware);
26
+ }
27
+ reducer(input, api) {
28
+ const reducer = this._middlewares.reduceRight((next, middleware) => embryo => middleware(input, embryo, api, next), embryo => embryo);
29
+ return reducer;
30
+ }
31
+ }
32
+
33
+ exports.AsyncMiddlewares = AsyncMiddlewares;
34
+ exports.Middlewares = Middlewares;
35
+ Object.keys(middleware_types).forEach(function (k) {
36
+ if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
37
+ enumerable: true,
38
+ get: function () { return middleware_types[k]; }
39
+ });
40
+ });
@@ -0,0 +1,31 @@
1
+ export * from '@guanghechen/middleware.types';
2
+
3
+ class AsyncMiddlewares {
4
+ _middlewares;
5
+ constructor() {
6
+ this._middlewares = [];
7
+ }
8
+ use(middleware) {
9
+ this._middlewares.push(middleware);
10
+ }
11
+ reducer(input, api) {
12
+ const reducer = this._middlewares.reduceRight((next, middleware) => embryo => middleware(input, embryo, api, next), async (embryo) => embryo);
13
+ return reducer;
14
+ }
15
+ }
16
+
17
+ class Middlewares {
18
+ _middlewares;
19
+ constructor() {
20
+ this._middlewares = [];
21
+ }
22
+ use(middleware) {
23
+ this._middlewares.push(middleware);
24
+ }
25
+ reducer(input, api) {
26
+ const reducer = this._middlewares.reduceRight((next, middleware) => embryo => middleware(input, embryo, api, next), embryo => embryo);
27
+ return reducer;
28
+ }
29
+ }
30
+
31
+ export { AsyncMiddlewares, Middlewares };
@@ -0,0 +1,18 @@
1
+ import { IAsyncMiddlewares, IAsyncMiddleware, IAsyncMiddlewareNext, IMiddlewares, IMiddleware, IMiddlewareNext } from '@guanghechen/middleware.types';
2
+ export * from '@guanghechen/middleware.types';
3
+
4
+ declare class AsyncMiddlewares<Input, Output, Api> implements IAsyncMiddlewares<Input, Output, Api> {
5
+ protected readonly _middlewares: Array<IAsyncMiddleware<Input, Output, Api>>;
6
+ constructor();
7
+ use(middleware: IAsyncMiddleware<Input, Output, Api>): void;
8
+ reducer(input: Readonly<Input>, api: Readonly<Api>): IAsyncMiddlewareNext<Output>;
9
+ }
10
+
11
+ declare class Middlewares<Input, Output, Api> implements IMiddlewares<Input, Output, Api> {
12
+ protected readonly _middlewares: Array<IMiddleware<Input, Output, Api>>;
13
+ constructor();
14
+ use(middleware: IMiddleware<Input, Output, Api>): void;
15
+ reducer(input: Readonly<Input>, api: Readonly<Api>): IMiddlewareNext<Output>;
16
+ }
17
+
18
+ export { AsyncMiddlewares, Middlewares };
package/package.json ADDED
@@ -0,0 +1,53 @@
1
+ {
2
+ "name": "@guanghechen/middleware",
3
+ "version": "1.0.0-alpha.1",
4
+ "description": "types of @guanghechen/middleware",
5
+ "author": {
6
+ "name": "guanghechen",
7
+ "url": "https://github.com/guanghechen/"
8
+ },
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "https://github.com/guanghechen/sora/tree/@guanghechen/middleware@1.0.0-alpha.0",
12
+ "directory": "packages/middleware"
13
+ },
14
+ "homepage": "https://github.com/guanghechen/sora/tree/@guanghechen/middleware@1.0.0-alpha.0/packages/middleware#readme",
15
+ "type": "module",
16
+ "exports": {
17
+ ".": {
18
+ "source": "./src/index.ts",
19
+ "import": "./lib/esm/index.mjs",
20
+ "require": "./lib/cjs/index.cjs",
21
+ "types": "./lib/types/index.d.ts"
22
+ }
23
+ },
24
+ "source": "./src/index.ts",
25
+ "main": "./lib/cjs/index.cjs",
26
+ "module": "./lib/esm/index.mjs",
27
+ "types": "./lib/types/index.d.ts",
28
+ "license": "MIT",
29
+ "engines": {
30
+ "node": ">= 16.0.0"
31
+ },
32
+ "files": [
33
+ "lib/",
34
+ "!lib/**/*.map",
35
+ "package.json",
36
+ "CHANGELOG.md",
37
+ "LICENSE",
38
+ "README.md"
39
+ ],
40
+ "scripts": {
41
+ "build": "rimraf lib/ && cross-env NODE_ENV=production rollup -c ../../rollup.config.mjs",
42
+ "prepublishOnly": "yarn build"
43
+ },
44
+ "dependencies": {
45
+ "@guanghechen/middleware.types": "^1.0.0-alpha.1"
46
+ },
47
+ "devDependencies": {
48
+ "cross-env": "*",
49
+ "rimraf": "*",
50
+ "rollup": "*"
51
+ },
52
+ "gitHead": "208ce260c87a55fc8b52650541486be2f94e90be"
53
+ }