zova-module-a-router 5.0.35 → 5.0.38

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zova-module-a-router",
3
- "version": "5.0.35",
3
+ "version": "5.0.38",
4
4
  "title": "a-router",
5
5
  "zovaModule": {
6
6
  "capabilities": {
@@ -37,5 +37,5 @@
37
37
  "dependencies": {
38
38
  "vue-router": "^4.3.2"
39
39
  },
40
- "gitHead": "66609919a02dea2e2e6818412225d719223ae290"
40
+ "gitHead": "90bb78df182aa8db862d6b44e86d23aa33b195fa"
41
41
  }
@@ -0,0 +1,2 @@
1
+ export * from './interface/index.js';
2
+ export * from './service/index.js';
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export const services = {};
@@ -1,14 +1,14 @@
1
- import { BeanBase, Cast, IModule, IPageNameRecord, IPagePathRecord, Store, TypeEventOff } from 'zova';
1
+ import { Bean, BeanBase, Cast, IModule, IPageNameRecord, IPagePathRecord, TypeEventOff } from 'zova';
2
2
  import { Router } from 'vue-router';
3
3
  import * as ModuleInfo from '@cabloy/module-info';
4
4
  import { IModuleRoute, IModuleRouteComponent } from '../types.js';
5
5
 
6
6
  const SymbolRouter = Symbol('SymbolRouter');
7
7
 
8
- export type StoreRouterLike = StoreRouter & Router;
8
+ export type BeanRouterLike = BeanRouter & Router;
9
9
 
10
- @Store()
11
- export class StoreRouter extends BeanBase {
10
+ @Bean({ scene: 'bean', name: 'router', containerScope: 'ctx' })
11
+ export class BeanRouter extends BeanBase {
12
12
  [SymbolRouter]: Router;
13
13
  eventRouterGuards: TypeEventOff;
14
14
 
@@ -27,7 +27,7 @@ export class StoreRouter extends BeanBase {
27
27
  if (!router) {
28
28
  throw new Error('Should provide router');
29
29
  }
30
- this.bean.provide('a-router:router', Cast<StoreRouterLike>(this));
30
+ this.bean.provide('a-router:router', Cast<BeanRouterLike>(this));
31
31
  // event
32
32
  this.eventRouterGuards = this.app.meta.event.on('a-router:routerGuards', async (context, next) => {
33
33
  this._routerGuards(context.data);
@@ -98,7 +98,7 @@ export class StoreRouter extends BeanBase {
98
98
  return `${fullPath}${join}${query2str}`;
99
99
  }
100
100
 
101
- private _routerGuards(router: StoreRouterLike) {
101
+ private _routerGuards(router: BeanRouterLike) {
102
102
  router.beforeEach(async to => {
103
103
  // fullPath
104
104
  const fullPath = to.fullPath;
@@ -1,5 +1,5 @@
1
1
  import { BeanBase, TypeEventOff, Virtual } from 'zova';
2
- import { StoreRouterLike } from './store.router.js';
2
+ import { BeanRouterLike } from './bean.router.js';
3
3
 
4
4
  @Virtual()
5
5
  export class BeanRouterBase<TScopeModule = unknown> extends BeanBase<TScopeModule> {
@@ -18,5 +18,5 @@ export class BeanRouterBase<TScopeModule = unknown> extends BeanBase<TScopeModul
18
18
  }
19
19
  }
20
20
 
21
- protected onRouterGuards(_router: StoreRouterLike) {}
21
+ protected onRouterGuards(_router: BeanRouterLike) {}
22
22
  }
package/src/index.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  export * from './config/index.js';
2
2
  export * from './resource/index.js';
3
+ export * from './api/index.js';
3
4
  export * from './routes.js';
4
5
  export * from './types.js';
5
6
  export * from './monkey.js';
package/src/monkey.ts CHANGED
@@ -13,10 +13,10 @@ import {
13
13
  } from 'zova';
14
14
  import * as ModuleInfo from '@cabloy/module-info';
15
15
  import { useRoute } from 'vue-router';
16
- import { StoreRouterLike } from './bean/store.router.js';
16
+ import { BeanRouterLike } from './bean/bean.router.js';
17
17
 
18
18
  export class Monkey extends BeanSimple implements IMonkeySystem, IMonkeyModule, IMonkeyController {
19
- private _storeRouter: StoreRouterLike;
19
+ private _beanRouter: BeanRouterLike;
20
20
  private _moduleSelf: IModule;
21
21
 
22
22
  constructor(moduleSelf: IModule) {
@@ -24,15 +24,15 @@ export class Monkey extends BeanSimple implements IMonkeySystem, IMonkeyModule,
24
24
  this._moduleSelf = moduleSelf;
25
25
  }
26
26
 
27
- async getStoreRouter() {
28
- if (!this._storeRouter) {
29
- this._storeRouter = (await this.bean._getBean('a-router.store.router', false)) as StoreRouterLike;
27
+ async getBeanRouter() {
28
+ if (!this._beanRouter) {
29
+ this._beanRouter = (await this.bean._getBean('a-router.bean.router', false)) as BeanRouterLike;
30
30
  }
31
- return this._storeRouter;
31
+ return this._beanRouter;
32
32
  }
33
33
 
34
- async appInitialize() {}
35
- async appInitialized() {
34
+ async appInitialize(_bean: BeanContainerLike) {}
35
+ async appInitialized(_bean: BeanContainerLike) {
36
36
  // emit event
37
37
  const router = this.bean.inject('a-router:router');
38
38
  await this.app.meta.event.emit('a-router:routerGuards', router);
@@ -51,8 +51,8 @@ export class Monkey extends BeanSimple implements IMonkeySystem, IMonkeyModule,
51
51
  beanDisposed(_bean: BeanContainerLike, _beanInstance: BeanBase) {}
52
52
  async moduleLoading(module: IModule) {
53
53
  if (this._moduleSelf === module) return;
54
- const storeRouter = await this.getStoreRouter();
55
- storeRouter._registerRoutes(module);
54
+ const beanRouter = await this.getBeanRouter();
55
+ beanRouter._registerRoutes(module);
56
56
  }
57
57
  async moduleLoaded(_module: IModule) {}
58
58
  async configLoaded(_module: IModule, _config) {}
@@ -61,25 +61,29 @@ export class Monkey extends BeanSimple implements IMonkeySystem, IMonkeyModule,
61
61
  }
62
62
  controllerDataInit(controllerData: IControllerData, controller: BeanBase) {
63
63
  // only for controller page
64
- if (controller instanceof BeanControllerPageBase) {
65
- const route = controllerData.context.route;
66
- const schemaKey = String(route.name || route.path);
67
- let schemas: TypePageSchema | undefined;
68
- const moduleName = ModuleInfo.parseName(schemaKey)!;
69
- const module = this.app.meta.module.get(moduleName)!;
70
- if (route.name) {
71
- schemas = module.resource.pageNameSchemas?.[schemaKey];
72
- } else {
73
- schemas = module.resource.pagePathSchemas?.[schemaKey];
74
- }
75
- controller.$params = useComputed(() => {
76
- if (!schemas?.params) throw new Error(`page params schema not found: ${schemaKey}`);
77
- return schemas.params.parse(route.params);
78
- });
79
- controller.$query = useComputed(() => {
80
- if (!schemas?.query) throw new Error(`page query schema not found: ${schemaKey}`);
81
- return schemas.query.parse(route.query);
82
- });
64
+ if (!(controller instanceof BeanControllerPageBase)) return;
65
+ const route = controllerData.context.route;
66
+ if (!route) return;
67
+ const schemaKey = String(route.name || route.path);
68
+ let schemas: TypePageSchema | undefined;
69
+ const moduleInfo = ModuleInfo.parseInfo(ModuleInfo.parseName(schemaKey));
70
+ if (!moduleInfo) {
71
+ // do nothing
72
+ return;
83
73
  }
74
+ const module = this.app.meta.module.get(moduleInfo.relativeName)!;
75
+ if (route.name) {
76
+ schemas = module.resource.pageNameSchemas?.[schemaKey];
77
+ } else {
78
+ schemas = module.resource.pagePathSchemas?.[schemaKey];
79
+ }
80
+ controller.$params = useComputed(() => {
81
+ if (!schemas?.params) throw new Error(`page params schema not found: ${schemaKey}`);
82
+ return schemas.params.parse(route.params);
83
+ });
84
+ controller.$query = useComputed(() => {
85
+ if (!schemas?.query) throw new Error(`page query schema not found: ${schemaKey}`);
86
+ return schemas.query.parse(route.query);
87
+ });
84
88
  }
85
89
  }
@@ -1,9 +1,9 @@
1
- export * from '../bean/store.router.js';
1
+ export * from '../bean/bean.router.js';
2
2
  export * from '../bean/virtual.router.js';
3
- import { StoreRouter } from '../bean/store.router.js';
3
+ import { BeanRouter } from '../bean/bean.router.js';
4
4
  import 'zova';
5
5
  declare module 'zova' {
6
6
  export interface IBeanRecord {
7
- 'a-router.store.router': StoreRouter;
7
+ 'a-router.bean.router': BeanRouter;
8
8
  }
9
9
  }
@@ -1,9 +1,9 @@
1
- import { StoreRouterLike } from './beans.js';
1
+ import { BeanRouterLike } from './beans.js';
2
2
 
3
3
  import 'zova';
4
4
  declare module 'zova' {
5
5
  export interface IEventRecord {
6
- 'a-router:routerGuards': StoreRouterLike;
6
+ 'a-router:routerGuards': BeanRouterLike;
7
7
  }
8
8
 
9
9
  export interface IEventResultRecord {
@@ -1,10 +1,10 @@
1
1
  import { Router } from 'vue-router';
2
- import { StoreRouterLike } from '../bean/store.router.js';
2
+ import { BeanRouterLike } from '../bean/bean.router.js';
3
3
 
4
4
  import 'zova';
5
5
  declare module 'zova' {
6
6
  export interface IInjectRecord {
7
7
  'a-router:appRouter': Router;
8
- 'a-router:router': StoreRouterLike;
8
+ 'a-router:router': BeanRouterLike;
9
9
  }
10
10
  }
@@ -1,6 +1,7 @@
1
1
  import { BeanScopeBase, Scope, TypeLocaleBase, TypeModuleResource } from 'zova';
2
2
  import { config, Errors, locales, constants } from '../config/index.js';
3
3
  import { components } from './components.js';
4
+ import { services } from '../api/service/index.js';
4
5
 
5
6
  @Scope()
6
7
  export class ScopeModuleARouter extends BeanScopeBase {}
@@ -11,7 +12,8 @@ export interface ScopeModuleARouter
11
12
  typeof config,
12
13
  typeof Errors,
13
14
  (typeof locales)[TypeLocaleBase],
14
- typeof constants
15
+ typeof constants,
16
+ typeof services
15
17
  > {}
16
18
 
17
19
  import 'zova';
package/src/types.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { IComponentLayoutRecord, TypePageSchemas } from 'zova';
2
2
  import { RouteComponent, RouteLocationNormalizedLoaded, RouteRecordRaw } from 'vue-router';
3
- import { StoreRouterLike } from './bean/store.router.js';
3
+ import { BeanRouterLike } from './bean/bean.router.js';
4
4
 
5
5
  export type Lazy<T> = () => Promise<T>;
6
6
  export type IModuleRouteComponent = RouteComponent | Lazy<RouteComponent>;
@@ -17,7 +17,7 @@ declare module 'vue-router' {
17
17
 
18
18
  declare module 'zova' {
19
19
  export interface BeanBase {
20
- $router: StoreRouterLike;
20
+ $router: BeanRouterLike;
21
21
  }
22
22
 
23
23
  export interface IModuleResource {