zova-core 5.0.110 → 5.0.113

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.
Files changed (133) hide show
  1. package/dist/bean/beanBaseSimple.d.ts.map +1 -1
  2. package/dist/bean/beanBaseSimple.js +10 -2
  3. package/dist/bean/beanBaseSimple.js.map +1 -1
  4. package/dist/core/resource.d.ts +6 -6
  5. package/dist/core/resource.d.ts.map +1 -1
  6. package/dist/core/resource.js +2 -6
  7. package/dist/core/resource.js.map +1 -1
  8. package/dist/decorator/class/use.js +8 -5
  9. package/dist/decorator/class/use.js.map +1 -1
  10. package/package.json +4 -3
  11. package/src/bean/beanBase.ts +53 -0
  12. package/src/bean/beanBaseSimple.ts +38 -0
  13. package/src/bean/beanContainer.ts +963 -0
  14. package/src/bean/beanControllerBase.ts +58 -0
  15. package/src/bean/beanControllerLike.ts +29 -0
  16. package/src/bean/beanControllerPageBase.ts +18 -0
  17. package/src/bean/beanRenderBase.ts +7 -0
  18. package/src/bean/beanRenderLike.ts +33 -0
  19. package/src/bean/beanSimple.ts +11 -0
  20. package/src/bean/beanStyleBase.ts +3 -0
  21. package/src/bean/index.ts +13 -0
  22. package/src/bean/resource/component/index.ts +1 -0
  23. package/src/bean/resource/component/type.ts +5 -0
  24. package/src/bean/resource/config/index.ts +1 -0
  25. package/src/bean/resource/config/type.ts +32 -0
  26. package/src/bean/resource/constant/index.ts +1 -0
  27. package/src/bean/resource/constant/type.ts +1 -0
  28. package/src/bean/resource/error/beanScopeError.ts +21 -0
  29. package/src/bean/resource/error/errorClass.ts +57 -0
  30. package/src/bean/resource/error/errorGlobal.ts +7 -0
  31. package/src/bean/resource/error/errorInternal.ts +66 -0
  32. package/src/bean/resource/error/errorObject.ts +4 -0
  33. package/src/bean/resource/error/index.ts +6 -0
  34. package/src/bean/resource/error/type.ts +10 -0
  35. package/src/bean/resource/icon/icon.ts +161 -0
  36. package/src/bean/resource/icon/iconGroup.ts +10 -0
  37. package/src/bean/resource/icon/index.ts +4 -0
  38. package/src/bean/resource/icon/types.ts +21 -0
  39. package/src/bean/resource/icon/useZovaIcon.ts +20 -0
  40. package/src/bean/resource/icon/utils.ts +20 -0
  41. package/src/bean/resource/icon/zovaIcon.ts +52 -0
  42. package/src/bean/resource/index.ts +8 -0
  43. package/src/bean/resource/locale/beanScopeLocale.ts +22 -0
  44. package/src/bean/resource/locale/index.ts +2 -0
  45. package/src/bean/resource/locale/type.ts +21 -0
  46. package/src/bean/resource/page/index.ts +1 -0
  47. package/src/bean/resource/page/type.ts +12 -0
  48. package/src/bean/resource/service/beanScopeService.ts +24 -0
  49. package/src/bean/resource/service/index.ts +2 -0
  50. package/src/bean/resource/service/type.ts +8 -0
  51. package/src/bean/scope/beanScopeBase.ts +74 -0
  52. package/src/bean/scope/index.ts +4 -0
  53. package/src/bean/scope/type.ts +23 -0
  54. package/src/bean/type.ts +31 -0
  55. package/src/composables/index.ts +4 -0
  56. package/src/composables/onControllerMounted.ts +12 -0
  57. package/src/composables/useApp.ts +7 -0
  58. package/src/composables/useContext.ts +7 -0
  59. package/src/composables/useController.ts +125 -0
  60. package/src/core/app/application.ts +76 -0
  61. package/src/core/app/config.ts +68 -0
  62. package/src/core/app/constant.ts +11 -0
  63. package/src/core/app/index.ts +6 -0
  64. package/src/core/app/locale.ts +12 -0
  65. package/src/core/app/meta.ts +44 -0
  66. package/src/core/app/util.ts +31 -0
  67. package/src/core/component/component.ts +44 -0
  68. package/src/core/component/cookie.ts +16 -0
  69. package/src/core/component/error.ts +18 -0
  70. package/src/core/component/event.ts +87 -0
  71. package/src/core/component/index.ts +3 -0
  72. package/src/core/component/locale.ts +97 -0
  73. package/src/core/component/module.ts +281 -0
  74. package/src/core/context/component.ts +34 -0
  75. package/src/core/context/context.ts +38 -0
  76. package/src/core/context/index.ts +4 -0
  77. package/src/core/context/meta.ts +26 -0
  78. package/src/core/context/state.ts +28 -0
  79. package/src/core/context/util.ts +20 -0
  80. package/src/core/index.ts +5 -0
  81. package/src/core/metadata.ts +54 -0
  82. package/src/core/resource.ts +186 -0
  83. package/src/decorator/class/bean.ts +19 -0
  84. package/src/decorator/class/index.ts +12 -0
  85. package/src/decorator/class/local.ts +18 -0
  86. package/src/decorator/class/model.ts +18 -0
  87. package/src/decorator/class/scope.ts +18 -0
  88. package/src/decorator/class/store.ts +18 -0
  89. package/src/decorator/class/style.ts +18 -0
  90. package/src/decorator/class/theme.ts +18 -0
  91. package/src/decorator/class/tool.ts +18 -0
  92. package/src/decorator/class/use.ts +37 -0
  93. package/src/decorator/class/useComposable.ts +16 -0
  94. package/src/decorator/class/useScope.ts +21 -0
  95. package/src/decorator/class/virtual.ts +20 -0
  96. package/src/decorator/index.ts +7 -0
  97. package/src/decorator/interface/beanOptions.ts +80 -0
  98. package/src/decorator/interface/useOptions.ts +37 -0
  99. package/src/decorator/type/constructable.ts +1 -0
  100. package/src/decorator/type/containerScope.ts +1 -0
  101. package/src/decorator/type/functionable.ts +1 -0
  102. package/src/decorator/type/injectionScope.ts +1 -0
  103. package/src/index.ts +9 -0
  104. package/src/plugins/bean.ts +16 -0
  105. package/src/plugins/index.ts +2 -0
  106. package/src/plugins/zova.ts +28 -0
  107. package/src/types/index.ts +2 -0
  108. package/src/types/interface/component.ts +36 -0
  109. package/src/types/interface/event.ts +28 -0
  110. package/src/types/interface/index.ts +6 -0
  111. package/src/types/interface/inject.ts +2 -0
  112. package/src/types/interface/module.ts +38 -0
  113. package/src/types/interface/monkey.ts +38 -0
  114. package/src/types/interface/pluginZova.ts +17 -0
  115. package/src/types/utils/cast.ts +8 -0
  116. package/src/types/utils/env.ts +35 -0
  117. package/src/types/utils/index.ts +3 -0
  118. package/src/types/utils/powerPartial.ts +3 -0
  119. package/src/utils/index.ts +1 -0
  120. package/src/utils/isClass.ts +17 -0
  121. package/src/utils/stateLock.ts +47 -0
  122. package/src/utils/uuid.ts +84 -0
  123. package/src/vue/composable.ts +10 -0
  124. package/src/vue/computed.ts +7 -0
  125. package/src/vue/customRef.ts +5 -0
  126. package/src/vue/index.ts +4 -0
  127. package/src/vue/ref.ts +12 -0
  128. package/src/zod/index.ts +2 -0
  129. package/src/zod/zz.ts +77 -0
  130. package/dist/decorator/class/data.d.ts +0 -3
  131. package/dist/decorator/class/data.d.ts.map +0 -1
  132. package/dist/decorator/class/data.js +0 -18
  133. package/dist/decorator/class/data.js.map +0 -1
@@ -0,0 +1,38 @@
1
+ import { ComponentInternalInstance, markRaw } from 'vue';
2
+ import { ZovaApplication } from '../app/application.js';
3
+ import { BeanContainer } from '../../bean/beanContainer.js';
4
+ import { CtxMeta } from './meta.js';
5
+ import { Cast } from '../../types/utils/cast.js';
6
+
7
+ export class ZovaContext {
8
+ instance: ComponentInternalInstance;
9
+ app: ZovaApplication;
10
+ bean: BeanContainer;
11
+ meta: CtxMeta;
12
+ //config: ContextConfig;
13
+
14
+ constructor(instance: ComponentInternalInstance) {
15
+ markRaw(this);
16
+ instance.zova = this;
17
+ this.instance = instance;
18
+ this.app = instance.appContext.app.zova;
19
+ this.bean = BeanContainer.create(this.app, this);
20
+ this.meta = this.bean._newBeanSimple(CtxMeta, false);
21
+ }
22
+
23
+ /** @internal */
24
+ public dispose() {
25
+ this.meta.dispose();
26
+ Cast(this.instance).zova = null;
27
+ Cast(this).instance = null;
28
+ Cast(this).app = null;
29
+ Cast(this).bean = null;
30
+ Cast(this).meta = null;
31
+ }
32
+ }
33
+
34
+ declare module 'vue' {
35
+ export interface ComponentInternalInstance {
36
+ zova: ZovaContext;
37
+ }
38
+ }
@@ -0,0 +1,4 @@
1
+ export * from './component.js';
2
+ export * from './context.js';
3
+ export * from './meta.js';
4
+ export * from './util.js';
@@ -0,0 +1,26 @@
1
+ import { RendererNode } from 'vue';
2
+ import { BeanSimple } from '../../bean/beanSimple.js';
3
+ import { CtxState } from './state.js';
4
+ import { CtxUtil } from './util.js';
5
+ import { CtxComponent } from './component.js';
6
+
7
+ export class CtxMeta extends BeanSimple {
8
+ util: CtxUtil;
9
+ state: CtxState;
10
+ component: CtxComponent;
11
+
12
+ get el(): RendererNode {
13
+ return this.ctx.instance.vnode.el!;
14
+ }
15
+
16
+ protected __init__() {
17
+ this.util = this.bean._newBeanSimple(CtxUtil, false);
18
+ this.state = this.bean._newBeanSimple(CtxState, true);
19
+ this.component = this.bean._newBeanSimple(CtxComponent, false);
20
+ }
21
+
22
+ /** @internal */
23
+ public dispose() {
24
+ this.component.dispose();
25
+ }
26
+ }
@@ -0,0 +1,28 @@
1
+ import { BeanSimple } from '../../bean/beanSimple.js';
2
+ import { StateLock } from '../../utils/stateLock.js';
3
+
4
+ let __id: number = 0;
5
+
6
+ export class CtxState extends BeanSimple {
7
+ private _id: number;
8
+ private _inited: StateLock;
9
+ private _mounted: StateLock;
10
+
11
+ protected __init__() {
12
+ this._id = ++__id;
13
+ this._inited = StateLock.create();
14
+ this._mounted = StateLock.create();
15
+ }
16
+
17
+ get id() {
18
+ return this._id;
19
+ }
20
+
21
+ get inited() {
22
+ return this._inited;
23
+ }
24
+
25
+ get mounted() {
26
+ return this._mounted;
27
+ }
28
+ }
@@ -0,0 +1,20 @@
1
+ import { setCurrentInstance } from '@cabloy/vue-runtime-core';
2
+ import { pauseTracking, resetTracking } from '@vue/reactivity';
3
+ import { BeanSimple } from '../../bean/beanSimple.js';
4
+
5
+ export class CtxUtil extends BeanSimple {
6
+ instanceScope(fn, tracking?: boolean) {
7
+ const reset = setCurrentInstance(this.ctx.instance as any);
8
+ if (!tracking) {
9
+ pauseTracking();
10
+ }
11
+ try {
12
+ return fn();
13
+ } finally {
14
+ if (!tracking) {
15
+ resetTracking();
16
+ }
17
+ reset();
18
+ }
19
+ }
20
+ }
@@ -0,0 +1,5 @@
1
+ export * from './app/index.js';
2
+ export * from './component/index.js';
3
+ export * from './context/index.js';
4
+ export * from './resource.js';
5
+ export * from './metadata.js';
@@ -0,0 +1,54 @@
1
+ import 'reflect-metadata';
2
+
3
+ export type MetadataKey = symbol | string;
4
+
5
+ export class AppMetadata {
6
+ defineMetadata<V>(metadataKey: MetadataKey, metadataValue: V, target: object) {
7
+ Reflect.defineMetadata(metadataKey, metadataValue, target);
8
+ }
9
+
10
+ getOwnMetadata<V>(metadataKey: MetadataKey, target: object): V | undefined {
11
+ return Reflect.getOwnMetadata(metadataKey, target);
12
+ }
13
+
14
+ getMetadata<V>(metadataKey: MetadataKey, target: object, prop?: MetadataKey): V | undefined {
15
+ if (prop) {
16
+ return Reflect.getMetadata(metadataKey, target, prop);
17
+ }
18
+ return Reflect.getMetadata(metadataKey, target);
19
+ }
20
+
21
+ getOwnMetadataArray<Entry>(metadataKey: MetadataKey, target: object): Array<Entry> {
22
+ let own: Array<Entry> | undefined = this.getOwnMetadata(metadataKey, target);
23
+ if (!own) {
24
+ const parent: Array<Entry> | undefined = this.getMetadata(metadataKey, target);
25
+ if (parent) {
26
+ own = parent.slice();
27
+ } else {
28
+ own = [];
29
+ }
30
+ this.defineMetadata(metadataKey, own, target);
31
+ }
32
+ return own;
33
+ }
34
+
35
+ getOwnMetadataMap<K extends PropertyKey, V>(metadataKey: MetadataKey, target): Record<K, V> {
36
+ let own: Record<K, V> | undefined = this.getOwnMetadata(metadataKey, target);
37
+ if (!own) {
38
+ const parent: Record<K, V> | undefined = this.getMetadata(metadataKey, target);
39
+ if (parent) {
40
+ own = Object.assign({}, parent);
41
+ } else {
42
+ own = {} as Record<K, V>;
43
+ }
44
+ this.defineMetadata(metadataKey, own, target);
45
+ }
46
+ return own;
47
+ }
48
+
49
+ getDesignType(target: object, prop?: MetadataKey) {
50
+ return this.getMetadata('design:type', target as any, prop);
51
+ }
52
+ }
53
+
54
+ export const appMetadata = new AppMetadata();
@@ -0,0 +1,186 @@
1
+ import { isClass } from '../utils/isClass.js';
2
+ import {
3
+ Constructable,
4
+ Functionable,
5
+ IDecoratorBeanOptionsBase,
6
+ IDecoratorUseOptionsBase,
7
+ } from '../decorator/index.js';
8
+ import { MetadataKey, appMetadata } from './metadata.js';
9
+ import { IBeanRecord } from '../bean/type.js';
10
+ import { BeanSimple } from '../bean/beanSimple.js';
11
+ import { parseLastWord, skipLastWord, skipPrefix, splitWords } from '@cabloy/last-word';
12
+ import { uuid } from '../utils/uuid.js';
13
+
14
+ export const DecoratorBeanFullName = Symbol.for('Decorator#BeanFullName');
15
+ export const DecoratorUse = Symbol.for('Decorator#Use');
16
+ export const DecoratorBeanFullNameOfComposable = Symbol.for('Decorator#BeanFullNameOfComposable');
17
+
18
+ export class AppResource extends BeanSimple {
19
+ beans: Record<string, IDecoratorBeanOptionsBase> = {};
20
+ aops: Record<string, IDecoratorBeanOptionsBase> = {};
21
+
22
+ addUse(target: object, options: IDecoratorUseOptionsBase) {
23
+ const uses = appMetadata.getOwnMetadataMap(DecoratorUse, target);
24
+ uses[options.prop] = options;
25
+ if (process.env.NODE_ENV === 'development') {
26
+ if (typeof options.prop === 'string' && !options.prop.startsWith('$$')) {
27
+ console.error(`inject prop name should start with $$: ${options.prop}`);
28
+ }
29
+ }
30
+ }
31
+
32
+ getUses(target: object): Record<MetadataKey, IDecoratorUseOptionsBase> | undefined {
33
+ return appMetadata.getMetadata(DecoratorUse, target);
34
+ }
35
+
36
+ addAop<T>(options: Partial<IDecoratorBeanOptionsBase<T>>) {
37
+ // bean
38
+ const beanOptions = this.addBean(options);
39
+ // aop
40
+ this.aops[beanOptions.beanFullName] = beanOptions;
41
+ // ok
42
+ return beanOptions;
43
+ }
44
+
45
+ addBean<T>(options: Partial<IDecoratorBeanOptionsBase<T>>) {
46
+ const { module, beanClass, virtual } = options;
47
+ // name
48
+ const { scene, name } = this._parseSceneAndBeanName(beanClass!, options.scene, options.name);
49
+ // uuid
50
+ const beanUuid = uuid();
51
+ // beanFullName
52
+ let beanFullName;
53
+ if (['local'].includes(scene)) {
54
+ beanFullName = beanUuid;
55
+ } else {
56
+ beanFullName = `${module}.${scene}.${name}`;
57
+ }
58
+ // moduleBelong
59
+ const moduleBelong = this._parseModuleBelong(module, beanClass, virtual);
60
+ // options
61
+ const beanOptions = {
62
+ ...options,
63
+ scene,
64
+ name,
65
+ beanUuid,
66
+ beanFullName,
67
+ moduleBelong,
68
+ } as IDecoratorBeanOptionsBase<T>;
69
+ beanOptions.__aopChains__ = null!;
70
+ beanOptions.__aopChainsKey__ = {};
71
+ // record
72
+ this.beans[beanOptions.beanFullName] = beanOptions;
73
+ // set metadata
74
+ appMetadata.defineMetadata(DecoratorBeanFullName, beanOptions.beanFullName, beanOptions.beanClass);
75
+ // ok
76
+ return beanOptions;
77
+ }
78
+
79
+ getBeanFullName<T>(A: Constructable<T>): string | undefined {
80
+ return appMetadata.getOwnMetadata(DecoratorBeanFullName, A);
81
+ }
82
+
83
+ getBeanFullNameOfComposable(beanComposable: Functionable | undefined): string | undefined {
84
+ if (!beanComposable) return;
85
+ if (!beanComposable[DecoratorBeanFullNameOfComposable]) {
86
+ beanComposable[DecoratorBeanFullNameOfComposable] = `useComposable.${uuid()}`;
87
+ }
88
+ return beanComposable[DecoratorBeanFullNameOfComposable];
89
+ }
90
+
91
+ getBean<T>(A: Constructable<T>): IDecoratorBeanOptionsBase<T> | undefined;
92
+ getBean<K extends keyof IBeanRecord>(beanFullName: K): IDecoratorBeanOptionsBase<IBeanRecord[K]> | undefined;
93
+ getBean<T>(beanFullName: string): IDecoratorBeanOptionsBase<T> | undefined;
94
+ getBean<T>(beanFullName: Constructable<T> | string): IDecoratorBeanOptionsBase<T> | undefined {
95
+ let fullName: string | undefined;
96
+ if (typeof beanFullName === 'function' && isClass(beanFullName)) {
97
+ fullName = appMetadata.getOwnMetadata(DecoratorBeanFullName, beanFullName);
98
+ } else {
99
+ fullName = beanFullName as string;
100
+ }
101
+ if (!fullName) return null!;
102
+ return this.beans[fullName] as IDecoratorBeanOptionsBase<T>;
103
+ }
104
+
105
+ _fixClassName(className: string) {
106
+ const ch = className.charAt(className.length - 1);
107
+ if (ch >= '0' && ch <= '9') return className.substring(0, className.length - 1);
108
+ return className;
109
+ }
110
+
111
+ _parseSceneAndBeanName<T>(
112
+ beanClass: Constructable<T>,
113
+ scene?: string,
114
+ name?: string,
115
+ ): { scene: string; name: string } {
116
+ if (scene && name) {
117
+ return { scene, name };
118
+ }
119
+ // bean class name
120
+ let beanClassName = this._fixClassName(beanClass.name);
121
+ // skip prefix: Bean
122
+ if (beanClassName.toLowerCase().startsWith('bean')) {
123
+ beanClassName = beanClassName.substring('bean'.length);
124
+ } else {
125
+ beanClassName = beanClassName;
126
+ }
127
+ // name
128
+ if (!name) {
129
+ if (scene) {
130
+ name = skipPrefix(beanClassName, scene, true)!;
131
+ } else {
132
+ name = parseLastWord(beanClassName, true)!;
133
+ }
134
+ }
135
+ // scene
136
+ if (!scene) {
137
+ scene = skipLastWord(beanClassName, name, true)!;
138
+ scene = splitWords(scene, true, '.')!;
139
+ }
140
+ // ok
141
+ return { scene, name };
142
+ }
143
+
144
+ _parseModuleBelong(module, beanClass, virtual) {
145
+ // not set when virtual
146
+ if (virtual) return;
147
+ // check parent
148
+ let moduleBelong;
149
+ let parent = Object.getPrototypeOf(beanClass);
150
+ while (parent) {
151
+ const beanOptions = this.getBean(parent);
152
+ if (beanOptions && beanOptions.moduleBelong) {
153
+ moduleBelong = beanOptions.moduleBelong;
154
+ break;
155
+ }
156
+ parent = Object.getPrototypeOf(parent);
157
+ }
158
+ // set to current when parent not set
159
+ if (!moduleBelong) {
160
+ moduleBelong = module;
161
+ }
162
+ return moduleBelong;
163
+ }
164
+
165
+ _getModuleBelong<T>(A: Constructable<T>): string | undefined;
166
+ _getModuleBelong<K extends keyof IBeanRecord>(beanFullName: K): string | undefined;
167
+ _getModuleBelong(beanFullName: string): string | undefined;
168
+ _getModuleBelong<T>(beanFullName: Constructable<T> | string): string | undefined {
169
+ const beanOptions = this.getBean(beanFullName as any);
170
+ return beanOptions?.moduleBelong;
171
+ }
172
+
173
+ _getModuleName<T>(A: Constructable<T>): string | undefined;
174
+ _getModuleName<K extends keyof IBeanRecord>(beanFullName: K): string | undefined;
175
+ _getModuleName(beanFullName: string): string | undefined;
176
+ _getModuleName<T>(beanFullName: Constructable<T> | string): string | undefined {
177
+ const beanOptions = this.getBean(beanFullName as any);
178
+ return beanOptions?.module;
179
+ }
180
+
181
+ findAopsMatched(_beanFullName: string): any[] {
182
+ return [];
183
+ }
184
+ }
185
+
186
+ export const appResource = new AppResource();
@@ -0,0 +1,19 @@
1
+ import { appResource } from '../../core/resource.js';
2
+ import { Cast } from '../../types/utils/cast.js';
3
+ import { IDecoratorBeanOptions } from '../interface/beanOptions.js';
4
+ import { Constructable } from '../type/constructable.js';
5
+
6
+ export function Bean<T>(options?: IDecoratorBeanOptions): ClassDecorator {
7
+ return function (target) {
8
+ if (!options) options = {};
9
+ // add
10
+ appResource.addBean({
11
+ module: Cast(options).module,
12
+ scene: options.scene || 'bean',
13
+ name: options.name,
14
+ containerScope: options.containerScope,
15
+ markReactive: options.markReactive,
16
+ beanClass: target as unknown as Constructable<T>,
17
+ });
18
+ };
19
+ }
@@ -0,0 +1,12 @@
1
+ export * from './bean.js';
2
+ export * from './model.js';
3
+ export * from './local.js';
4
+ export * from './scope.js';
5
+ export * from './store.js';
6
+ export * from './style.js';
7
+ export * from './theme.js';
8
+ export * from './tool.js';
9
+ export * from './use.js';
10
+ export * from './useComposable.js';
11
+ export * from './useScope.js';
12
+ export * from './virtual.js';
@@ -0,0 +1,18 @@
1
+ import { appResource } from '../../core/resource.js';
2
+ import { Cast } from '../../types/utils/cast.js';
3
+ import { IDecoratorLocalOptions } from '../interface/beanOptions.js';
4
+ import { Constructable } from '../type/constructable.js';
5
+
6
+ export function Local<T>(options?: IDecoratorLocalOptions): ClassDecorator {
7
+ return function (target) {
8
+ if (!options) options = {};
9
+ // add
10
+ appResource.addBean({
11
+ module: Cast(options).module,
12
+ scene: 'local',
13
+ containerScope: options.containerScope,
14
+ markReactive: options.markReactive,
15
+ beanClass: target as unknown as Constructable<T>,
16
+ });
17
+ };
18
+ }
@@ -0,0 +1,18 @@
1
+ import { appResource } from '../../core/resource.js';
2
+ import { Cast } from '../../types/utils/cast.js';
3
+ import { Constructable, IDecoratorModelOptions } from '../index.js';
4
+
5
+ export function Model<T>(options?: IDecoratorModelOptions): ClassDecorator {
6
+ return function (target) {
7
+ if (!options) options = {};
8
+ // add
9
+ appResource.addBean({
10
+ module: Cast(options).module,
11
+ scene: options.scene || 'model',
12
+ name: options.name,
13
+ containerScope: 'ctx',
14
+ markReactive: options.markReactive,
15
+ beanClass: target as unknown as Constructable<T>,
16
+ });
17
+ };
18
+ }
@@ -0,0 +1,18 @@
1
+ import { appResource } from '../../core/resource.js';
2
+ import { Cast } from '../../types/utils/cast.js';
3
+ import { Constructable, IDecoratorScopeOptions } from '../index.js';
4
+
5
+ export function Scope<T>(options?: IDecoratorScopeOptions): ClassDecorator {
6
+ return function (target) {
7
+ if (!options) options = {};
8
+ // add
9
+ appResource.addBean({
10
+ module: Cast(options).module,
11
+ scene: 'scope',
12
+ name: 'module', // force to the same name
13
+ containerScope: 'app',
14
+ markReactive: false,
15
+ beanClass: target as unknown as Constructable<T>,
16
+ });
17
+ };
18
+ }
@@ -0,0 +1,18 @@
1
+ import { appResource } from '../../core/resource.js';
2
+ import { Cast } from '../../types/utils/cast.js';
3
+ import { Constructable, IDecoratorStoreOptions } from '../index.js';
4
+
5
+ export function Store<T>(options?: IDecoratorStoreOptions): ClassDecorator {
6
+ return function (target) {
7
+ if (!options) options = {};
8
+ // add
9
+ appResource.addBean({
10
+ module: Cast(options).module,
11
+ scene: options.scene || 'store',
12
+ name: options.name,
13
+ containerScope: 'app',
14
+ markReactive: options.markReactive,
15
+ beanClass: target as unknown as Constructable<T>,
16
+ });
17
+ };
18
+ }
@@ -0,0 +1,18 @@
1
+ import { appResource } from '../../core/resource.js';
2
+ import { Cast } from '../../types/utils/cast.js';
3
+ import { Constructable, IDecoratorStyleOptions } from '../index.js';
4
+
5
+ export function Style<T>(options?: IDecoratorStyleOptions): ClassDecorator {
6
+ return function (target) {
7
+ if (!options) options = {};
8
+ // add
9
+ appResource.addBean({
10
+ module: Cast(options).module,
11
+ scene: options.scene || 'style',
12
+ name: options.name,
13
+ containerScope: 'app',
14
+ markReactive: options.markReactive,
15
+ beanClass: target as unknown as Constructable<T>,
16
+ });
17
+ };
18
+ }
@@ -0,0 +1,18 @@
1
+ import { appResource } from '../../core/resource.js';
2
+ import { Cast } from '../../types/utils/cast.js';
3
+ import { Constructable, IDecoratorThemeOptions } from '../index.js';
4
+
5
+ export function Theme<T>(options?: IDecoratorThemeOptions): ClassDecorator {
6
+ return function (target) {
7
+ if (!options) options = {};
8
+ // add
9
+ appResource.addBean({
10
+ module: Cast(options).module,
11
+ scene: options.scene || 'theme',
12
+ name: options.name,
13
+ containerScope: 'app',
14
+ markReactive: options.markReactive,
15
+ beanClass: target as unknown as Constructable<T>,
16
+ });
17
+ };
18
+ }
@@ -0,0 +1,18 @@
1
+ import { appResource } from '../../core/resource.js';
2
+ import { Cast } from '../../types/utils/cast.js';
3
+ import { Constructable, IDecoratorToolOptions } from '../index.js';
4
+
5
+ export function Tool<T>(options?: IDecoratorToolOptions): ClassDecorator {
6
+ return function (target) {
7
+ if (!options) options = {};
8
+ // add
9
+ appResource.addBean({
10
+ module: Cast(options).module,
11
+ scene: options.scene || 'tool',
12
+ name: options.name,
13
+ containerScope: 'app',
14
+ markReactive: options.markReactive,
15
+ beanClass: target as unknown as Constructable<T>,
16
+ });
17
+ };
18
+ }
@@ -0,0 +1,37 @@
1
+ import { IBeanRecord } from '../../bean/type.js';
2
+ import { appMetadata, MetadataKey } from '../../core/metadata.js';
3
+ import { appResource } from '../../core/resource.js';
4
+ import { Constructable, IDecoratorUseOptions } from '../index.js';
5
+
6
+ export function Use(options?: IDecoratorUseOptions): PropertyDecorator;
7
+ export function Use<T extends keyof IBeanRecord>(beanFullName?: T): PropertyDecorator;
8
+ export function Use(options?: IDecoratorUseOptions | string): PropertyDecorator {
9
+ return function (target: object, prop: MetadataKey) {
10
+ if (!options) options = {};
11
+ if (typeof options === 'string') {
12
+ options = { beanFullName: options } as unknown as IDecoratorUseOptions;
13
+ }
14
+ // beanClass
15
+ const beanClass = appMetadata.getDesignType(target, prop) as Constructable;
16
+ // record
17
+ appResource.addUse(target, {
18
+ ...options,
19
+ prop,
20
+ beanClass,
21
+ });
22
+ // chech beanClass
23
+ if (process.env.NODE_ENV === 'development') {
24
+ const moduleSource = appResource._getModuleName(beanClass);
25
+ if (moduleSource) {
26
+ window.setTimeout(() => {
27
+ const moduleTarget = appResource._getModuleName(target.constructor as any);
28
+ if (moduleSource !== moduleTarget) {
29
+ console.error(
30
+ `inject class should be imported by type, such as: import type { ${appResource._fixClassName(beanClass.name)} } from 'zova-module-xxx-xxx'`,
31
+ );
32
+ }
33
+ }, 0);
34
+ }
35
+ }
36
+ };
37
+ }
@@ -0,0 +1,16 @@
1
+ import { MetadataKey } from '../../core/metadata.js';
2
+ import { appResource } from '../../core/resource.js';
3
+ import { Functionable, IDecoratorUseComposableOptions } from '../index.js';
4
+
5
+ export function UseComposable(options: IDecoratorUseComposableOptions | Functionable): PropertyDecorator {
6
+ return function (target: object, prop: MetadataKey) {
7
+ if (typeof options === 'function') {
8
+ options = { beanComposable: options } as IDecoratorUseComposableOptions;
9
+ }
10
+ // record
11
+ appResource.addUse(target, {
12
+ ...options,
13
+ prop,
14
+ });
15
+ };
16
+ }
@@ -0,0 +1,21 @@
1
+ import { IBeanScopeRecord } from '../../bean/type.js';
2
+ import { MetadataKey } from '../../core/metadata.js';
3
+ import { appResource } from '../../core/resource.js';
4
+ import { IDecoratorUseScopeOptions } from '../index.js';
5
+
6
+ export function UseScope(options: IDecoratorUseScopeOptions): PropertyDecorator;
7
+ export function UseScope<T extends keyof IBeanScopeRecord>(module: T): PropertyDecorator;
8
+ export function UseScope(options: IDecoratorUseScopeOptions | string): PropertyDecorator {
9
+ return function (target: object, prop: MetadataKey) {
10
+ if (typeof options === 'string') {
11
+ options = { module: options } as IDecoratorUseScopeOptions;
12
+ }
13
+ const beanFullName = `${options.module}.scope.module`;
14
+ // record
15
+ appResource.addUse(target, {
16
+ ...options,
17
+ prop,
18
+ beanFullName,
19
+ });
20
+ };
21
+ }
@@ -0,0 +1,20 @@
1
+ import { appResource } from '../../core/resource.js';
2
+ import { Cast } from '../../types/utils/cast.js';
3
+ import { IDecoratorVirtualOptions } from '../interface/beanOptions.js';
4
+ import { Constructable } from '../type/constructable.js';
5
+
6
+ export function Virtual<T>(options?: IDecoratorVirtualOptions): ClassDecorator {
7
+ return function (target) {
8
+ if (!options) options = {};
9
+ // add
10
+ appResource.addBean({
11
+ module: Cast(options).module,
12
+ scene: options.scene || 'virtual',
13
+ name: options.name,
14
+ containerScope: options.containerScope,
15
+ markReactive: options.markReactive,
16
+ beanClass: target as unknown as Constructable<T>,
17
+ virtual: true,
18
+ });
19
+ };
20
+ }
@@ -0,0 +1,7 @@
1
+ export * from './class/index.js';
2
+ export * from './interface/beanOptions.js';
3
+ export * from './interface/useOptions.js';
4
+ export * from './type/constructable.js';
5
+ export * from './type/containerScope.js';
6
+ export * from './type/injectionScope.js';
7
+ export * from './type/functionable.js';