vona-module-a-onion 5.0.28 → 5.0.30

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/dist/index.js CHANGED
@@ -29,12 +29,22 @@ let ServiceOnion = (_dec$2 = ProxyDisable(), _dec2$2 = Service(), _dec3$1 = Bean
29
29
  __init__(sceneName) {
30
30
  this.sceneName = sceneName;
31
31
  this.sceneMeta = getOnionScenesMeta(this.app.meta.modules)[this.sceneName];
32
+ this.load();
33
+ }
34
+ load() {
32
35
  this._loadOnions();
33
36
  this._swapOnions(this.onionsGlobal);
37
+ this[SymbolOnionsEnabled] = {};
38
+ this[SymbolOnionsEnabledWrapped] = {};
39
+ this.clearCache();
40
+ }
41
+ clearCache() {
42
+ this._cacheOnionsGlobal = undefined;
43
+ this._cacheOnionsHandler = {};
34
44
  }
35
- compose(ctx, fnStart, fnMid, fnEnd, executeCustom) {
45
+ compose(route, fnStart, fnMid, fnEnd, executeCustom) {
36
46
  // compose
37
- const onions = this._composeOnionsHandler(ctx, fnStart, fnMid, fnEnd, executeCustom);
47
+ const onions = this._composeOnionsHandler(route, fnStart, fnMid, fnEnd, executeCustom);
38
48
  // invoke
39
49
  return compose(onions);
40
50
  }
@@ -94,9 +104,9 @@ let ServiceOnion = (_dec$2 = ProxyDisable(), _dec2$2 = Service(), _dec3$1 = Bean
94
104
  }
95
105
  return this._cacheOnionsGlobal;
96
106
  }
97
- _composeOnionsHandler(ctx, fnStart, fnMid, fnEnd, executeCustom) {
98
- const beanFullName = ctx?.getControllerBeanFullName();
99
- const handlerName = ctx?.getHandler()?.name;
107
+ _composeOnionsHandler(route, fnStart, fnMid, fnEnd, executeCustom) {
108
+ const beanFullName = route?.controllerBeanFullName;
109
+ const handlerName = route?.action;
100
110
  const key = beanFullName ? `${beanFullName}:${handlerName}` : '';
101
111
  if (!this._cacheOnionsHandler[key]) {
102
112
  let onions = [];
@@ -105,7 +115,7 @@ let ServiceOnion = (_dec$2 = ProxyDisable(), _dec2$2 = Service(), _dec3$1 = Bean
105
115
  onions = onions.concat(this._composeOnionsGlobal(executeCustom));
106
116
  if (fnMid) onions = onions.concat(fnMid);
107
117
  // onions: handler
108
- const onionsLocal = this._collectOnionsHandler(ctx);
118
+ const onionsLocal = this._collectOnionsHandler(route);
109
119
  for (const item of onionsLocal) {
110
120
  onions.push(this._wrapOnion(item, executeCustom));
111
121
  }
@@ -114,13 +124,13 @@ let ServiceOnion = (_dec$2 = ProxyDisable(), _dec2$2 = Service(), _dec3$1 = Bean
114
124
  }
115
125
  return this._cacheOnionsHandler[key];
116
126
  }
117
- _collectOnionsHandler(ctx) {
118
- if (!ctx?.getController()) return [];
127
+ _collectOnionsHandler(route) {
128
+ if (!route?.controller) return [];
119
129
  // onionsLocal: controller
120
- const controllerOnionsLocal = appMetadata.getMetadata(SymbolUseOnionLocal, ctx.getController())?.[this.sceneName];
130
+ const controllerOnionsLocal = appMetadata.getMetadata(SymbolUseOnionLocal, route.controller)?.[this.sceneName];
121
131
  // onionsLocal: action
122
132
  const onionsLocal = [];
123
- const actionOnionsLocal = appMetadata.getMetadata(SymbolUseOnionLocal, ctx.getControllerPrototype(), ctx.getHandlerName())?.[this.sceneName];
133
+ const actionOnionsLocal = appMetadata.getMetadata(SymbolUseOnionLocal, route.controller.prototype, route.action)?.[this.sceneName];
124
134
  const onionsLocalAll = [];
125
135
  if (actionOnionsLocal) {
126
136
  actionOnionsLocal.forEach(item => {
@@ -1,7 +1,8 @@
1
1
  import type { OnionSceneMeta } from '@cabloy/module-info';
2
- import type { Next, VonaContext } from 'vona';
2
+ import type { Next } from 'vona';
3
3
  import type { IEventRecord } from 'vona-module-a-event';
4
4
  import type { IMetaNameRecord } from 'vona-module-a-meta';
5
+ import type { ContextRoute } from 'vona-module-a-web';
5
6
  import type { IOnionExecuteCustom, IOnionSlice, TypeOnionsNormal } from '../types/onion.ts';
6
7
  import { BeanBase } from 'vona';
7
8
  declare const SymbolOnionsEnabled: unique symbol;
@@ -13,10 +14,12 @@ export declare class ServiceOnion<ONIONRECORD> extends BeanBase {
13
14
  onionsGlobal: IOnionSlice<ONIONRECORD, keyof ONIONRECORD>[];
14
15
  private [SymbolOnionsEnabled];
15
16
  private [SymbolOnionsEnabledWrapped];
16
- _cacheOnionsGlobal: Function[];
17
- _cacheOnionsHandler: Record<string, Function[]>;
17
+ private _cacheOnionsGlobal;
18
+ private _cacheOnionsHandler;
18
19
  protected __init__(sceneName: string): void;
19
- compose(ctx: VonaContext | undefined, fnStart?: Function | Function[], fnMid?: Function | Function[], fnEnd?: Function | Function[], executeCustom?: IOnionExecuteCustom): (context: any, next?: any) => any;
20
+ load(): void;
21
+ clearCache(): void;
22
+ compose(route: ContextRoute | undefined, fnStart?: Function | Function[], fnMid?: Function | Function[], fnEnd?: Function | Function[], executeCustom?: IOnionExecuteCustom): (context: any, next?: any) => any;
20
23
  getOnionsEnabled(selector?: string | boolean, matchThis?: any, ...matchArgs: any[]): IOnionSlice<ONIONRECORD, keyof ONIONRECORD, unknown>[];
21
24
  getOnionsEnabledCached(_selector?: string | boolean, matchThis?: any, ...matchArgs: any[]): IOnionSlice<ONIONRECORD, keyof ONIONRECORD, unknown>[];
22
25
  getOnionsEnabledOfMeta(useCache: boolean, beanName: keyof IMetaNameRecord, selector?: string | boolean, matchThis?: any, ...matchArgs: any[]): IOnionSlice<ONIONRECORD, keyof ONIONRECORD, unknown>[];
@@ -27,7 +30,7 @@ export declare class ServiceOnion<ONIONRECORD> extends BeanBase {
27
30
  get composedOnionsGlobal(): Function[];
28
31
  private _composeOnionsGlobal;
29
32
  private _composeOnionsHandler;
30
- _collectOnionsHandler(ctx: VonaContext | undefined): IOnionSlice<ONIONRECORD, keyof ONIONRECORD, unknown>[];
33
+ _collectOnionsHandler(route: ContextRoute | undefined): IOnionSlice<ONIONRECORD, keyof ONIONRECORD, unknown>[];
31
34
  getOnionOptions<T extends keyof ONIONRECORD>(onionName: T): ONIONRECORD[T] | undefined;
32
35
  getOnionOptionsDynamic<T extends keyof ONIONRECORD>(onionName: T, optionsCustom?: Partial<ONIONRECORD[T]>): ONIONRECORD[T];
33
36
  combineOnionOptions<T extends keyof ONIONRECORD>(item: IOnionSlice<ONIONRECORD, T>, optionsCustom?: Partial<ONIONRECORD[T]>): ONIONRECORD[T];
@@ -30,6 +30,8 @@ export interface IOnionOptionsMeta extends VonaOnionOptionsMeta {
30
30
  }
31
31
  export interface IOnionOptionsBase<T extends string> extends IOnionOptionsEnable, IOnionOptionsMatch<TypeOnionOptionsMatchRule<T>> {
32
32
  }
33
+ export interface TypeOnionOptionsBaseSimple<T extends string> extends TypeOnionOptionsEnableSimple, IOnionOptionsMatch<TypeOnionOptionsMatchRule<T>> {
34
+ }
33
35
  export interface IOnionSlice<ONIONRECORD = unknown, ONIONNAME extends keyof ONIONRECORD = any, T = unknown> {
34
36
  name: ONIONNAME;
35
37
  beanOptions: IDecoratorBeanOptionsBase<T, ONIONRECORD[ONIONNAME]>;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "vona-module-a-onion",
3
3
  "type": "module",
4
- "version": "5.0.28",
4
+ "version": "5.0.30",
5
5
  "title": "a-onion",
6
6
  "vonaModule": {
7
7
  "dependencies": {}