@aomex/common-middleware 3.28.2 → 3.29.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.
- package/CHANGELOG.md +16 -0
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,22 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
# [3.29.0](https://github.com/aomex/aomex/compare/v3.28.3...v3.29.0) (2025-07-17)
|
|
7
|
+
|
|
8
|
+
**Note:** Version bump only for package @aomex/common-middleware
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
## [3.28.3](https://github.com/aomex/aomex/compare/v3.28.2...v3.28.3) (2025-07-10)
|
|
15
|
+
|
|
16
|
+
**Note:** Version bump only for package @aomex/common-middleware
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
|
|
6
22
|
## [3.28.2](https://github.com/aomex/aomex/compare/v3.28.1...v3.28.2) (2025-07-09)
|
|
7
23
|
|
|
8
24
|
**Note:** Version bump only for package @aomex/common-middleware
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/i18n/index.ts","../src/i18n/locales/zh-cn.ts","../src/i18n/locales/en-us.ts","../src/i18n/locales/index.ts","../src/compose.ts","../src/middleware.ts","../src/mixin-middleware.ts"],"sourcesContent":["import { I18n } from '@aomex/internal-tools';\nimport { locales } from './locales';\n\nexport const i18n = new I18n({\n resources: locales,\n defaultLanguage: 'zh_CN',\n});\n","import { I18n } from '@aomex/internal-tools';\n\nexport const zh = I18n.define({\n middleware: {\n call_next_multiple: '多次执行中间件next()函数',\n },\n});\n","import { I18n } from '@aomex/internal-tools';\nimport { zh } from './zh-cn';\n\nexport const en = I18n.satisfies(zh).define({\n middleware: {\n call_next_multiple: 'call next() multiple times',\n },\n});\n","import { zh } from './zh-cn';\nimport { en } from './en-us';\n\nexport const locales = {\n zh_CN: zh,\n en_US: en,\n};\n","import { i18n } from './i18n';\nimport type { Middleware } from './middleware';\n\nexport type Next = () => Promise<any>;\nexport type ComposeFn = (ctx: any, next?: Next) => Promise<void>;\nconst noop = (): any => {};\n\n/**\n * 组合中间件\n */\nexport const compose = (middlewareList: Middleware[]): ComposeFn => {\n const total = middlewareList.length;\n const fns = middlewareList.map((md) => md['fn']);\n\n return (ctx, next) => {\n let lastIndex = -1;\n const dispatch = async (i: number): Promise<void> => {\n if (i <= lastIndex) {\n throw new Error(i18n.t('middleware.call_next_multiple'));\n }\n const finished = (lastIndex = i) === total;\n const fn = finished ? next : fns[lastIndex];\n if (fn) {\n await fn(ctx, finished ? noop : dispatch.bind(null, i + 1));\n }\n };\n return dispatch(0);\n };\n};\n","import type { Next } from './compose';\nimport type { MixinMiddleware } from './mixin-middleware';\n\nexport declare namespace Middleware {\n export type Infer<T> =\n T extends Middleware<infer R>\n ? R\n : T extends (...args: any[]) => Middleware<infer R>\n ? R\n : never;\n\n export type Fn<Ctx = any> = (ctx: Ctx, next: Next) => any;\n\n export type CollectArrayType<T> = T extends Middleware<infer R> ? R : unknown;\n}\n\nexport interface MiddlewarePlatform {}\n\n/**\n * 中间件基类\n */\nexport abstract class Middleware<Props extends object = object> {\n public
|
|
1
|
+
{"version":3,"sources":["../src/i18n/index.ts","../src/i18n/locales/zh-cn.ts","../src/i18n/locales/en-us.ts","../src/i18n/locales/index.ts","../src/compose.ts","../src/middleware.ts","../src/mixin-middleware.ts"],"sourcesContent":["import { I18n } from '@aomex/internal-tools';\nimport { locales } from './locales';\n\nexport const i18n = new I18n({\n resources: locales,\n defaultLanguage: 'zh_CN',\n});\n","import { I18n } from '@aomex/internal-tools';\n\nexport const zh = I18n.define({\n middleware: {\n call_next_multiple: '多次执行中间件next()函数',\n },\n});\n","import { I18n } from '@aomex/internal-tools';\nimport { zh } from './zh-cn';\n\nexport const en = I18n.satisfies(zh).define({\n middleware: {\n call_next_multiple: 'call next() multiple times',\n },\n});\n","import { zh } from './zh-cn';\nimport { en } from './en-us';\n\nexport const locales = {\n zh_CN: zh,\n en_US: en,\n};\n","import { i18n } from './i18n';\nimport type { Middleware } from './middleware';\n\nexport type Next = () => Promise<any>;\nexport type ComposeFn = (ctx: any, next?: Next) => Promise<void>;\nconst noop = (): any => {};\n\n/**\n * 组合中间件\n */\nexport const compose = (middlewareList: Middleware[]): ComposeFn => {\n const total = middlewareList.length;\n const fns = middlewareList.map((md) => md['fn']);\n\n return (ctx, next) => {\n let lastIndex = -1;\n const dispatch = async (i: number): Promise<void> => {\n if (i <= lastIndex) {\n throw new Error(i18n.t('middleware.call_next_multiple'));\n }\n const finished = (lastIndex = i) === total;\n const fn = finished ? next : fns[lastIndex];\n if (fn) {\n await fn(ctx, finished ? noop : dispatch.bind(null, i + 1));\n }\n };\n return dispatch(0);\n };\n};\n","import type { Next } from './compose';\nimport type { MixinMiddleware } from './mixin-middleware';\n\nexport declare namespace Middleware {\n export type Infer<T> =\n T extends Middleware<infer R>\n ? R\n : T extends (...args: any[]) => Middleware<infer R>\n ? R\n : never;\n\n export type Fn<Ctx = any> = (ctx: Ctx, next: Next) => any;\n\n export type CollectArrayType<T> = T extends Middleware<infer R> ? R : unknown;\n}\n\nexport interface MiddlewarePlatform {}\n\n/**\n * 中间件基类\n */\nexport abstract class Middleware<Props extends object = object> {\n declare public _contextType: object;\n\n declare protected _props_must_be_used_: Props;\n\n constructor(protected readonly fn: Middleware.Fn) {}\n\n /**\n * 跳过执行中间件。\n *\n * 返回的类型未使用Partial,因为skip的设计是在部分场景下才需要触发的。\n */\n public skip(\n when: (ctx: this['_contextType']) => boolean | Promise<boolean>,\n ): MixinMiddleware<Props> {\n return middleware.mixin(async (ctx, next) => {\n const skipped = await when(ctx);\n return skipped ? next() : this.fn(ctx, next);\n });\n }\n\n /**\n * 注册中间件\n */\n static register(\n platform: keyof MiddlewarePlatform,\n SubMiddleware: new (...args: any[]) => Middleware,\n ) {\n Object.defineProperty(middleware, platform, {\n get() {\n return (...args: any[]) => new SubMiddleware(...args);\n },\n });\n }\n}\n\nexport const middleware: MiddlewarePlatform = {} as any;\n","import type { NonReadonly } from '@aomex/internal-tools';\nimport type { Next } from './compose';\nimport { Middleware } from './middleware';\n\ndeclare module './middleware' {\n export interface MiddlewarePlatform {\n /**\n * 没有特定上下文的纯中间件,支持所有应用\n */\n readonly mixin: {\n <Props extends object = object>(\n fn: (ctx: NonReadonly<Props>, next: Next) => any,\n ): MixinMiddleware<Props>;\n };\n }\n}\n\nexport class MixinMiddleware<Props extends object = object> extends Middleware<Props> {\n declare protected _mixin_middleware_: 'mixin-middleware';\n}\n\nMiddleware.register('mixin', MixinMiddleware);\n"],"mappings":";AAAA,SAAS,QAAAA,aAAY;;;ACArB,SAAS,YAAY;AAEd,IAAM,KAAK,KAAK,OAAO;AAAA,EAC5B,YAAY;AAAA,IACV,oBAAoB;AAAA,EACtB;AACF,CAAC;;;ACND,SAAS,QAAAC,aAAY;AAGd,IAAM,KAAKC,MAAK,UAAU,EAAE,EAAE,OAAO;AAAA,EAC1C,YAAY;AAAA,IACV,oBAAoB;AAAA,EACtB;AACF,CAAC;;;ACJM,IAAM,UAAU;AAAA,EACrB,OAAO;AAAA,EACP,OAAO;AACT;;;AHHO,IAAM,OAAO,IAAIC,MAAK;AAAA,EAC3B,WAAW;AAAA,EACX,iBAAiB;AACnB,CAAC;;;AIDD,IAAM,OAAO,MAAW;AAAC;AAKlB,IAAM,UAAU,CAAC,mBAA4C;AAClE,QAAM,QAAQ,eAAe;AAC7B,QAAM,MAAM,eAAe,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC;AAE/C,SAAO,CAAC,KAAK,SAAS;AACpB,QAAI,YAAY;AAChB,UAAM,WAAW,OAAO,MAA6B;AACnD,UAAI,KAAK,WAAW;AAClB,cAAM,IAAI,MA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