zova-module-a-api 5.0.0 → 5.1.2

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2016-present Zova
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,12 @@
1
+ import { Api, BeanApiBase } from 'zova-module-a-api';
2
+
3
+ export interface Api<%=argv.beanNameCapitalize%>EchoResult {
4
+ message: string;
5
+ }
6
+
7
+ @Api()
8
+ export class Api<%=argv.beanNameCapitalize%> extends BeanApiBase {
9
+ echo() {
10
+ return this.$fetch.get<any, Api<%=argv.beanNameCapitalize%>EchoResult>('/<%=argv.beanName%>/echo');
11
+ }
12
+ }
@@ -0,0 +1,19 @@
1
+ import type { IMetadataCustomGenerateOptions } from '@cabloy/cli';
2
+
3
+ import fse from 'fs-extra';
4
+ import path from 'node:path';
5
+
6
+ export default async function (options: IMetadataCustomGenerateOptions): Promise<string> {
7
+ const { modulePath } = options;
8
+ const contentExports: string[] = [];
9
+ // openapi
10
+ if (fse.existsSync(path.join(modulePath, 'src/api/openapi/index.ts'))) {
11
+ contentExports.push("export * from '../api/openapi/index.js';");
12
+ }
13
+ // combine
14
+ const content = `/** openapi: begin */
15
+ ${contentExports.join('\n')}
16
+ /** openapi: end */
17
+ `;
18
+ return content;
19
+ }
@@ -0,0 +1,8 @@
1
+ {
2
+ "extends": "../../../tsconfig.base",
3
+ "compilerOptions": {
4
+ "allowImportingTsExtensions": true,
5
+ "rewriteRelativeImportExtensions": true,
6
+ "verbatimModuleSyntax": true
7
+ }
8
+ }
package/dist/index.js ADDED
@@ -0,0 +1,95 @@
1
+ import { BeanBase, BeanInfo, BeanScopeBase, BeanSimple, Virtual, appResource, cast, createBeanDecorator } from "zova";
2
+ import { Bean, Scope } from "zova-module-a-bean";
3
+ //#region src/bean/bean.apiBase.ts
4
+ var _dec$1, _dec2$1, _dec3, _class$1;
5
+ var BeanApiBase = (_dec$1 = Bean(), _dec2$1 = Virtual(), _dec3 = BeanInfo({ module: "a-api" }), _dec$1(_class$1 = _dec2$1(_class$1 = _dec3(_class$1 = class BeanApiBase extends BeanBase {
6
+ $pathTranslate(pathName, pathParams) {
7
+ return this.sys.util.apiActionPathTranslate(pathName, pathParams);
8
+ }
9
+ $configPrepare(baseURL, options, authToken) {
10
+ return this.sys.util.apiActionConfigPrepare(baseURL, options, authToken);
11
+ }
12
+ $formData(body) {
13
+ const formData = new FormData();
14
+ for (const key in body) {
15
+ const value = body[key];
16
+ if (Array.isArray(value)) for (const item of value) formData.append(key, item);
17
+ else formData.append(key, value);
18
+ }
19
+ return formData;
20
+ }
21
+ }) || _class$1) || _class$1) || _class$1);
22
+ //#endregion
23
+ //#region src/config/config.ts
24
+ var config = (_sys) => {
25
+ return { defaultModuleApi: "home-api" };
26
+ };
27
+ //#endregion
28
+ //#region src/.metadata/this.ts
29
+ var __ThisModule__ = "a-api";
30
+ //#endregion
31
+ //#region src/monkey.ts
32
+ var Monkey = class extends BeanSimple {
33
+ constructor(moduleSelf) {
34
+ super();
35
+ this._moduleSelf = void 0;
36
+ this._defaultModuleApi = void 0;
37
+ this._moduleSelf = moduleSelf;
38
+ }
39
+ async moduleLoading(_module) {}
40
+ async moduleLoaded(module) {
41
+ const promises = [];
42
+ promises.push(this._loadApis(module, "api"));
43
+ promises.push(this._loadApis(module, "apiSchema"));
44
+ await Promise.all(promises);
45
+ if (this._moduleSelf === module) {
46
+ this._defaultModuleApi = (await this.bean.getScope(__ThisModule__)).config.defaultModuleApi;
47
+ await this.app.meta.module.use(this._defaultModuleApi);
48
+ }
49
+ }
50
+ async beanInit(bean, beanInstance) {
51
+ const self = this;
52
+ for (const sceneName of ["api", "apiSchema"]) bean.defineProperty(beanInstance, `$${sceneName}`, {
53
+ enumerable: false,
54
+ configurable: true,
55
+ get() {
56
+ return cast(self.app.bean.scope(self._defaultModuleApi))[sceneName];
57
+ }
58
+ });
59
+ }
60
+ async _loadApis(module, sceneName) {
61
+ const onions = appResource.scenes[sceneName]?.[module.info.relativeName];
62
+ if (!onions) return;
63
+ const scope = this.bean.scope(module.info.relativeName);
64
+ const beanFullNames = Object.keys(onions);
65
+ const promises = [];
66
+ for (const beanFullName of beanFullNames) promises.push(this.bean._getBean(beanFullName, true));
67
+ const values = await Promise.all(promises);
68
+ for (let index = 0; index < beanFullNames.length; index++) {
69
+ const beanOptions = onions[beanFullNames[index]];
70
+ scope[sceneName][beanOptions.name] = values[index];
71
+ }
72
+ }
73
+ };
74
+ //#endregion
75
+ //#region src/.metadata/index.ts
76
+ /** monkey: end */
77
+ /** scope: begin */
78
+ var _dec, _dec2, _class;
79
+ var ScopeModuleAApi = (_dec = Scope(), _dec2 = BeanInfo({ module: "a-api" }), _dec(_class = _dec2(_class = class ScopeModuleAApi extends BeanScopeBase {}) || _class) || _class);
80
+ /** scope: end */
81
+ //#endregion
82
+ //#region src/lib/api.ts
83
+ function Api() {
84
+ return createBeanDecorator("api", "app");
85
+ }
86
+ function ApiMeta() {
87
+ return createBeanDecorator("apiMeta", "app");
88
+ }
89
+ function ApiSchema() {
90
+ return createBeanDecorator("apiSchema", "app");
91
+ }
92
+ //#endregion
93
+ export { Api, ApiMeta, ApiSchema, BeanApiBase, Monkey, ScopeModuleAApi, config };
94
+
95
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","names":[],"sources":["../src/bean/bean.apiBase.ts","../src/config/config.ts","../src/.metadata/this.ts","../src/monkey.ts","../src/.metadata/index.ts","../src/lib/api.ts"],"sourcesContent":["import type { AxiosRequestConfig } from 'axios';\n\nimport { BeanBase, TypeAuthToken, Virtual } from 'zova';\nimport { Bean } from 'zova-module-a-bean';\n\nimport type { IApiActionOptions } from '../types/api.js';\n\n@Bean()\n@Virtual()\nexport class BeanApiBase extends BeanBase {\n $pathTranslate(pathName: string, pathParams?: Record<string, any>): string {\n return this.sys.util.apiActionPathTranslate(pathName, pathParams);\n }\n\n $configPrepare(baseURL?: string, options?: IApiActionOptions, authToken?: TypeAuthToken): AxiosRequestConfig {\n return this.sys.util.apiActionConfigPrepare(baseURL, options, authToken);\n }\n\n $formData(body: object) {\n const formData = new FormData();\n for (const key in body) {\n const value = body[key];\n if (Array.isArray(value)) {\n for (const item of value) {\n formData.append(key, item);\n }\n } else {\n formData.append(key, value);\n }\n }\n return formData;\n }\n}\n","import type { IBeanScopeRecord, ZovaSys } from 'zova';\n\nexport const config = (_sys: ZovaSys) => {\n return {\n defaultModuleApi: 'home-api' as keyof IBeanScopeRecord,\n };\n};\n","export const __ThisModule__ = 'a-api';\nexport { ScopeModuleAApi as ScopeModule } from './index.js';\n","import type { IModule } from '@cabloy/module-info';\nimport type { BeanBase, BeanContainer, IBeanScopeRecord, IMonkeyBeanInit, IMonkeyModule } from 'zova';\n\nimport { appResource, BeanSimple, cast } from 'zova';\n\nimport type { ScopeModule } from './.metadata/this.js';\n\nimport { __ThisModule__ } from './.metadata/this.js';\n\nexport class Monkey extends BeanSimple implements IMonkeyModule, IMonkeyBeanInit {\n private _moduleSelf: IModule;\n private _defaultModuleApi: keyof IBeanScopeRecord;\n\n constructor(moduleSelf: IModule) {\n super();\n this._moduleSelf = moduleSelf;\n }\n\n async moduleLoading(_module: IModule) {}\n async moduleLoaded(module: IModule) {\n // load apis\n const promises: Promise<any>[] = [];\n promises.push(this._loadApis(module, 'api'));\n promises.push(this._loadApis(module, 'apiSchema'));\n await Promise.all(promises);\n // self\n if (this._moduleSelf === module) {\n const scopeSelf: ScopeModule = await this.bean.getScope(__ThisModule__);\n this._defaultModuleApi = scopeSelf.config.defaultModuleApi;\n await this.app.meta.module.use(this._defaultModuleApi);\n }\n }\n\n async beanInit(bean: BeanContainer, beanInstance: BeanBase) {\n const self = this;\n for (const sceneName of ['api', 'apiSchema']) {\n bean.defineProperty(beanInstance, `$${sceneName}`, {\n enumerable: false,\n configurable: true,\n get() {\n return cast(self.app.bean.scope(self._defaultModuleApi))[sceneName];\n },\n });\n }\n }\n\n private async _loadApis(module: IModule, sceneName: 'api' | 'apiSchema') {\n const onions = appResource.scenes[sceneName]?.[module.info.relativeName];\n if (!onions) return;\n const scope = this.bean.scope(module.info.relativeName as any) as any;\n const beanFullNames = Object.keys(onions);\n const promises: Promise<any>[] = [];\n for (const beanFullName of beanFullNames) {\n promises.push(this.bean._getBean(beanFullName as any, true));\n }\n const values = await Promise.all(promises);\n for (let index = 0; index < beanFullNames.length; index++) {\n const beanFullName = beanFullNames[index];\n const beanOptions = onions[beanFullName];\n scope[sceneName][beanOptions.name] = values[index];\n }\n }\n}\n","// eslint-disable\n/** bean: begin */\nexport * from '../bean/bean.apiBase.js';\n\nimport 'zova';\ndeclare module 'zova' {\n \n \n}\ndeclare module 'zova-module-a-api' {\n \n}\n/** bean: end */\n/** bean: begin */\nimport { BeanApiBase } from '../bean/bean.apiBase.js';\nimport 'zova';\ndeclare module 'zova' {\n export interface IBeanRecordGeneral {\n 'a-api.bean.apiBase': BeanApiBase;\n }\n}\n/** bean: end */\n/** config: begin */\nexport * from '../config/config.js';\nimport { config } from '../config/config.js';\n/** config: end */\n/** monkey: begin */\nexport * from '../monkey.js';\n/** monkey: end */\n/** scope: begin */\nimport { BeanScopeBase, type BeanScopeUtil, TypeModuleConfig } from 'zova';\nimport { Scope } from 'zova-module-a-bean';\n\n@Scope()\nexport class ScopeModuleAApi extends BeanScopeBase {}\n\nexport interface ScopeModuleAApi {\n util: BeanScopeUtil;\nconfig: TypeModuleConfig<typeof config>;\n}\n\nimport 'zova';\ndeclare module 'zova' {\n export interface IBeanScopeRecord {\n 'a-api': ScopeModuleAApi;\n }\n \n export interface IBeanScopeConfig {\n 'a-api': ReturnType<typeof config>;\n }\n\n \n\n \n}\n \n/** scope: end */\n","import { createBeanDecorator } from 'zova';\n\nexport function Api(): ClassDecorator {\n return createBeanDecorator('api', 'app');\n}\n\nexport function ApiMeta(): ClassDecorator {\n return createBeanDecorator('apiMeta', 'app');\n}\n\nexport function ApiSchema(): ClassDecorator {\n return createBeanDecorator('apiSchema', 'app');\n}\n"],"mappings":";;;AAAA,IAAA,QAAO,SAAO,OAAA;4EAKd,QAAO,SAAA,CAAA,EAAA,OAAA,WAAA,QAAA,WAAA,MAAA,WAAA,MAAA,oBAAA,SAAA;CAEN,eAAK,UAAA,YAAA;AACL,SAAQ,KAAA,IAAA,KAAA,uBAAA,UAAA,WAAA;;CAEP,eAAe,SAAS,SAAS,WAAW;AAC1C,SAAO,KAAK,IAAI,KAAK,uBAAuB,SAAS,SAAC,UAAW;;;EAGlE,MAAA,WAAc,IAAQ,UAAU;AAC/B,OAAA,MAAW,OAAK,MAAK;GACvB,MAAA,QAAA,KAAA;4BAEC,MAAS,MAAM,QAAQ,MAChB,UAAS,OAAM,KAAA,KAAU;OAG3B,UAAQ,OAAQ,KAAK,MAAG;;AAG5B,SAAI;;EAEN,IAAI,SAAE,IAAS,SAAO,IAAI;;;AC3B5B,IAAa,UAAC,SAAgB;UAE9B,kBAAsB,YACpB;;;;ACHF,IAAa,iBAAiB;;;;CCG9B,YAAS,YAAa;;AAEtB,OAAO,cAAO,KAAc;;AAE5B,OAAS,cAAc;;CAEvB,MAAO,cAAa,SAAQ;CAC1B,MAAA,aAAmB,QAAE;;AAGrB,WAAW,KAAC,KAAA,UAAmB,QAAE,MAAA,CAAA;AAC/B,WAAO,KAAA,KAAA,UAAA,QAAA,YAAA,CAAA;AACP,QAAK,QAAA,IAAa,SAAC;;AAIrB,QAAM,qBADc,MAAQ,KAAC,KAAS,SAAC,eAAA,EACH,OAAA;AAChC,SAAM,KAAA,IAAA,KAAA,OAAA,IAAA,KAAA,kBAAA;;;CAGV,MAAE,SAAa,MAAM,cAAU;EAC7B,MAAM,OAAO;AACb,OAAG,MAAA,aAAA,CAAA,OAAA,YAAA,CACD,MAAE,eAAkB,cAAW,IAAA,aAAA;GAC/B,YAAM;GACN,cAAK;GACL,MAAM;AACR,WAAA,KAAA,KAAA,IAAA,KAAA,MAAA,KAAA,kBAAA,CAAA,CAAA;;;;CAKF,MAAM,UAAO,QAAU,WAAY;EACjC,MAAM,SAAC,YAAe,OAAY,aAAM,OAAa,KAAA;AACrD,MAAI,CAAA,OAAA;EACJ,MAAI,QAAA,KAAc,KAAI,MAAA,OAAA,KAAA,aAAA;EACtB,MAAI,gBAAM,OAAA,KAAA,OAAA;EACV,MAAM,WAAW,EAAC;AAClB,OAAK,MAAA,gBAAA,cACH,UAAE,KAAA,KAAA,KAAA,SAAA,cAAA,KAAA,CAAA;EAEN,MAAA,SAAA,MAAA,QAAA,IAAA,SAAA;;GAGE,MAAM,cAAS,OADO,cAAe;AAEnC,SAAG,WAAc,YAAA,QAAA,OAAA;;;;;;;;AChDvB,IAAG,MAAO,OAAA;AAoBV,IAAA,mBAAA,OAAA,OAAA,EAAA,QAAA,SAAA,EACE,QAAQ,SACT,CAAC,EAAE,KAAA,SAAc,MAAC,SAAA,MAAA,wBAAA,cAAA,GAAA,IAAA,OAAA,IAAA;;;;;ACpBnB,QAAO,oBAAgB,OAAA,MAAe;;AAEtC,SAAA,UAAA;;;AAGA,SAAS,YAAmB;AAC5B,QAAA,oBAAA,aAAA,MAAA"}
@@ -0,0 +1,16 @@
1
+ import fse from 'fs-extra';
2
+ import path from 'node:path';
3
+ export default async function (options) {
4
+ const { modulePath } = options;
5
+ const contentExports = [];
6
+ // openapi
7
+ if (fse.existsSync(path.join(modulePath, 'src/api/openapi/index.ts'))) {
8
+ contentExports.push("export * from '../api/openapi/index.js';");
9
+ }
10
+ // combine
11
+ const content = `/** openapi: begin */
12
+ ${contentExports.join('\n')}
13
+ /** openapi: end */
14
+ `;
15
+ return content;
16
+ }
package/package.json CHANGED
@@ -1,38 +1,71 @@
1
1
  {
2
- "aaaa":"zova-module/zova-suite/a-home/a-demo/a-base/a-core/a-flow/a-cms",
3
2
  "name": "zova-module-a-api",
4
- "version": "5.0.0",
3
+ "version": "5.1.2",
4
+ "description": "",
5
+ "keywords": [
6
+ "Zova Module"
7
+ ],
8
+ "author": "",
9
+ "files": [
10
+ "cli",
11
+ "dist",
12
+ "mock",
13
+ "src",
14
+ "icons",
15
+ "assets",
16
+ "rest",
17
+ "dist-cli"
18
+ ],
5
19
  "type": "module",
6
- "publishConfig": {
7
- "access": "public"
8
- },
9
20
  "exports": {
10
21
  ".": {
11
22
  "types": [
12
23
  "./src/index.ts",
13
24
  "./dist/index.d.ts"
14
25
  ],
15
- "development": "./src/index.ts",
16
- "import": "./dist/index.js",
17
- "default": "./src/index.ts"
26
+ "default": "./dist/index.js"
18
27
  },
19
- "./package.json": "./package.json"
28
+ "./*": "./*"
20
29
  },
21
- "description": "",
22
- "files": [
23
- "dist",
24
- "static",
25
- "typings"
26
- ],
27
30
  "scripts": {
28
- "build:front": "node ../../../../../scripts/egg-born-bin.js front-build-module",
29
- "build:backend": "node ../../../../../scripts/egg-born-bin.js backend-build-module",
30
- "build:all": "npm run build:front && npm run build:backend",
31
- "preversion": "npm run build:all && git add ."
31
+ "clean": "rimraf dist dist-cli tsconfig.build.tsbuildinfo tsconfig.cli.tsbuildinfo",
32
+ "tsc:publish": "npm run clean && zova :bin:buildModule --sourcemap && tsc -p tsconfig.cli.json",
33
+ "prepublishOnly": "npm run tsc:publish",
34
+ "prepack": "clean-package",
35
+ "postpack": "clean-package restore && npm run clean"
32
36
  },
33
- "keywords": [
34
- "Cabloy Module"
35
- ],
36
- "author": "zhennann",
37
- "dependencies": {}
37
+ "title": "a-api",
38
+ "zovaModule": {
39
+ "capabilities": {
40
+ "monkey": true
41
+ },
42
+ "dependencies": {
43
+ "a-fetch": "5.0.0",
44
+ "a-openapi": "5.0.0",
45
+ "a-model": "5.0.0"
46
+ },
47
+ "onions": {
48
+ "api": {
49
+ "sceneIsolate": true,
50
+ "scopeResource": true,
51
+ "beanGeneral": true,
52
+ "optionsNone": true,
53
+ "boilerplate": "api/boilerplate",
54
+ "metadataCustom": "api/metadata/generate.ts"
55
+ },
56
+ "apiMeta": {
57
+ "sceneIsolate": true,
58
+ "scopeResource": true,
59
+ "beanGeneral": true,
60
+ "optionsNone": true
61
+ },
62
+ "apiSchema": {
63
+ "sceneIsolate": true,
64
+ "scopeResource": true,
65
+ "beanGeneral": true,
66
+ "optionsNone": true
67
+ }
68
+ }
69
+ },
70
+ "gitHead": "5517baba5865ac348af5be8e3a0f7506b0a67f9c"
38
71
  }
@@ -0,0 +1,57 @@
1
+ // eslint-disable
2
+ /** bean: begin */
3
+ export * from '../bean/bean.apiBase.js';
4
+
5
+ import 'zova';
6
+ declare module 'zova' {
7
+
8
+
9
+ }
10
+ declare module 'zova-module-a-api' {
11
+
12
+ }
13
+ /** bean: end */
14
+ /** bean: begin */
15
+ import { BeanApiBase } from '../bean/bean.apiBase.js';
16
+ import 'zova';
17
+ declare module 'zova' {
18
+ export interface IBeanRecordGeneral {
19
+ 'a-api.bean.apiBase': BeanApiBase;
20
+ }
21
+ }
22
+ /** bean: end */
23
+ /** config: begin */
24
+ export * from '../config/config.js';
25
+ import { config } from '../config/config.js';
26
+ /** config: end */
27
+ /** monkey: begin */
28
+ export * from '../monkey.js';
29
+ /** monkey: end */
30
+ /** scope: begin */
31
+ import { BeanScopeBase, type BeanScopeUtil, TypeModuleConfig } from 'zova';
32
+ import { Scope } from 'zova-module-a-bean';
33
+
34
+ @Scope()
35
+ export class ScopeModuleAApi extends BeanScopeBase {}
36
+
37
+ export interface ScopeModuleAApi {
38
+ util: BeanScopeUtil;
39
+ config: TypeModuleConfig<typeof config>;
40
+ }
41
+
42
+ import 'zova';
43
+ declare module 'zova' {
44
+ export interface IBeanScopeRecord {
45
+ 'a-api': ScopeModuleAApi;
46
+ }
47
+
48
+ export interface IBeanScopeConfig {
49
+ 'a-api': ReturnType<typeof config>;
50
+ }
51
+
52
+
53
+
54
+
55
+ }
56
+
57
+ /** scope: end */
@@ -0,0 +1,2 @@
1
+ export const __ThisModule__ = 'a-api';
2
+ export { ScopeModuleAApi as ScopeModule } from './index.js';
@@ -0,0 +1,33 @@
1
+ import type { AxiosRequestConfig } from 'axios';
2
+
3
+ import { BeanBase, TypeAuthToken, Virtual } from 'zova';
4
+ import { Bean } from 'zova-module-a-bean';
5
+
6
+ import type { IApiActionOptions } from '../types/api.js';
7
+
8
+ @Bean()
9
+ @Virtual()
10
+ export class BeanApiBase extends BeanBase {
11
+ $pathTranslate(pathName: string, pathParams?: Record<string, any>): string {
12
+ return this.sys.util.apiActionPathTranslate(pathName, pathParams);
13
+ }
14
+
15
+ $configPrepare(baseURL?: string, options?: IApiActionOptions, authToken?: TypeAuthToken): AxiosRequestConfig {
16
+ return this.sys.util.apiActionConfigPrepare(baseURL, options, authToken);
17
+ }
18
+
19
+ $formData(body: object) {
20
+ const formData = new FormData();
21
+ for (const key in body) {
22
+ const value = body[key];
23
+ if (Array.isArray(value)) {
24
+ for (const item of value) {
25
+ formData.append(key, item);
26
+ }
27
+ } else {
28
+ formData.append(key, value);
29
+ }
30
+ }
31
+ return formData;
32
+ }
33
+ }
@@ -0,0 +1,7 @@
1
+ import type { IBeanScopeRecord, ZovaSys } from 'zova';
2
+
3
+ export const config = (_sys: ZovaSys) => {
4
+ return {
5
+ defaultModuleApi: 'home-api' as keyof IBeanScopeRecord,
6
+ };
7
+ };
package/src/index.ts ADDED
@@ -0,0 +1,3 @@
1
+ export * from './.metadata/index.js';
2
+ export * from './lib/index.js';
3
+ export * from './types/index.js';
package/src/lib/api.ts ADDED
@@ -0,0 +1,13 @@
1
+ import { createBeanDecorator } from 'zova';
2
+
3
+ export function Api(): ClassDecorator {
4
+ return createBeanDecorator('api', 'app');
5
+ }
6
+
7
+ export function ApiMeta(): ClassDecorator {
8
+ return createBeanDecorator('apiMeta', 'app');
9
+ }
10
+
11
+ export function ApiSchema(): ClassDecorator {
12
+ return createBeanDecorator('apiSchema', 'app');
13
+ }
@@ -0,0 +1 @@
1
+ export * from './api.js';
package/src/monkey.ts ADDED
@@ -0,0 +1,63 @@
1
+ import type { IModule } from '@cabloy/module-info';
2
+ import type { BeanBase, BeanContainer, IBeanScopeRecord, IMonkeyBeanInit, IMonkeyModule } from 'zova';
3
+
4
+ import { appResource, BeanSimple, cast } from 'zova';
5
+
6
+ import type { ScopeModule } from './.metadata/this.js';
7
+
8
+ import { __ThisModule__ } from './.metadata/this.js';
9
+
10
+ export class Monkey extends BeanSimple implements IMonkeyModule, IMonkeyBeanInit {
11
+ private _moduleSelf: IModule;
12
+ private _defaultModuleApi: keyof IBeanScopeRecord;
13
+
14
+ constructor(moduleSelf: IModule) {
15
+ super();
16
+ this._moduleSelf = moduleSelf;
17
+ }
18
+
19
+ async moduleLoading(_module: IModule) {}
20
+ async moduleLoaded(module: IModule) {
21
+ // load apis
22
+ const promises: Promise<any>[] = [];
23
+ promises.push(this._loadApis(module, 'api'));
24
+ promises.push(this._loadApis(module, 'apiSchema'));
25
+ await Promise.all(promises);
26
+ // self
27
+ if (this._moduleSelf === module) {
28
+ const scopeSelf: ScopeModule = await this.bean.getScope(__ThisModule__);
29
+ this._defaultModuleApi = scopeSelf.config.defaultModuleApi;
30
+ await this.app.meta.module.use(this._defaultModuleApi);
31
+ }
32
+ }
33
+
34
+ async beanInit(bean: BeanContainer, beanInstance: BeanBase) {
35
+ const self = this;
36
+ for (const sceneName of ['api', 'apiSchema']) {
37
+ bean.defineProperty(beanInstance, `$${sceneName}`, {
38
+ enumerable: false,
39
+ configurable: true,
40
+ get() {
41
+ return cast(self.app.bean.scope(self._defaultModuleApi))[sceneName];
42
+ },
43
+ });
44
+ }
45
+ }
46
+
47
+ private async _loadApis(module: IModule, sceneName: 'api' | 'apiSchema') {
48
+ const onions = appResource.scenes[sceneName]?.[module.info.relativeName];
49
+ if (!onions) return;
50
+ const scope = this.bean.scope(module.info.relativeName as any) as any;
51
+ const beanFullNames = Object.keys(onions);
52
+ const promises: Promise<any>[] = [];
53
+ for (const beanFullName of beanFullNames) {
54
+ promises.push(this.bean._getBean(beanFullName as any, true));
55
+ }
56
+ const values = await Promise.all(promises);
57
+ for (let index = 0; index < beanFullNames.length; index++) {
58
+ const beanFullName = beanFullNames[index];
59
+ const beanOptions = onions[beanFullName];
60
+ scope[sceneName][beanOptions.name] = values[index];
61
+ }
62
+ }
63
+ }
@@ -0,0 +1,15 @@
1
+ import type { AxiosRequestConfig } from 'axios';
2
+ import type { PowerPartial } from 'zova';
3
+ import type { IInterceptorRecord } from 'zova-module-a-fetch';
4
+
5
+ export interface IApiActionOptions extends AxiosRequestConfig {
6
+ interceptors?: PowerPartial<IInterceptorRecord>;
7
+ authToken?: boolean | string;
8
+ openapiSchema?: boolean;
9
+ }
10
+
11
+ declare module 'zova' {
12
+ export interface IBeanSceneRecord {
13
+ api: never;
14
+ }
15
+ }
@@ -0,0 +1,7 @@
1
+ import 'zova';
2
+
3
+ declare module 'zova' {
4
+ export interface IBeanSceneRecord {
5
+ apiMeta: never;
6
+ }
7
+ }
@@ -0,0 +1,11 @@
1
+ import 'zova';
2
+
3
+ export interface IApiSchemaOptions {
4
+ authToken?: boolean;
5
+ }
6
+
7
+ declare module 'zova' {
8
+ export interface IBeanSceneRecord {
9
+ apiSchema: never;
10
+ }
11
+ }
@@ -0,0 +1,3 @@
1
+ export * from './api.js';
2
+ export * from './apiMeta.js';
3
+ export * from './apiSchema.js';
package/README.md DELETED
@@ -1 +0,0 @@
1
- # @cabloy/set