zova-module-a-action 5.1.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/LICENSE +21 -0
- package/cli/action/boilerplate/{{sceneName}}.{{beanName}}.tsx_ +14 -0
- package/cli/action/metadata/generate.ts +61 -0
- package/cli/action/metadata/utils.ts +15 -0
- package/cli/tsconfig.json +8 -0
- package/dist/index.js +59 -0
- package/dist/index.js.map +1 -0
- package/dist-cli/action/metadata/generate.js +56 -0
- package/dist-cli/action/metadata/utils.js +14 -0
- package/package.json +54 -0
- package/src/.metadata/index.ts +29 -0
- package/src/.metadata/this.ts +2 -0
- package/src/index.ts +3 -0
- package/src/lib/action.ts +9 -0
- package/src/lib/index.ts +2 -0
- package/src/lib/performAction.ts +38 -0
- package/src/monkey.ts +36 -0
- package/src/types/action.ts +38 -0
- package/src/types/index.ts +2 -0
- package/src/types/performAction.ts +15 -0
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,14 @@
|
|
|
1
|
+
import { BeanBase } from 'zova';
|
|
2
|
+
import { Action, IActionExecute, IDecoratorActionOptions, NextActionExecute } from 'zova-module-a-action';
|
|
3
|
+
import { IJsxRenderContextBase } from 'zova-module-a-openapi';
|
|
4
|
+
|
|
5
|
+
export type TypeAction<%=argv.beanNameCapitalize%>Result = unknown;
|
|
6
|
+
|
|
7
|
+
export interface IActionOptions<%=argv.beanNameCapitalize%> extends IDecoratorActionOptions<TypeAction<%=argv.beanNameCapitalize%>Result> {}
|
|
8
|
+
|
|
9
|
+
@Action<IActionOptions<%=argv.beanNameCapitalize%>>()
|
|
10
|
+
export class Action<%=argv.beanNameCapitalize%> extends BeanBase implements IActionExecute {
|
|
11
|
+
execute(_options: IActionOptions<%=argv.beanNameCapitalize%>, _renderContext: IJsxRenderContextBase, next: NextActionExecute) {
|
|
12
|
+
return next();
|
|
13
|
+
}
|
|
14
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import type { IMetadataCustomGenerateOptions } from '@cabloy/cli';
|
|
2
|
+
import type { IGlobBeanFile } from '@cabloy/module-info';
|
|
3
|
+
|
|
4
|
+
import { combineResourceName } from '@cabloy/utils';
|
|
5
|
+
import { toUpperCaseFirstChar } from '@cabloy/word-utils';
|
|
6
|
+
import fse from 'fs-extra';
|
|
7
|
+
import path from 'node:path';
|
|
8
|
+
|
|
9
|
+
import { generateRestIndex } from './utils.ts';
|
|
10
|
+
|
|
11
|
+
export default async function (options: IMetadataCustomGenerateOptions): Promise<string> {
|
|
12
|
+
const { globFiles } = options;
|
|
13
|
+
for (const globFile of globFiles) {
|
|
14
|
+
if (globFile.isIgnore) continue;
|
|
15
|
+
// restComponent
|
|
16
|
+
await generateRestAction(options, globFile);
|
|
17
|
+
}
|
|
18
|
+
return '';
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
async function generateRestAction(options: IMetadataCustomGenerateOptions, globFile: IGlobBeanFile) {
|
|
22
|
+
const { moduleName, modulePath } = options;
|
|
23
|
+
const { beanName, beanNameCapitalize, fileNameJS } = globFile;
|
|
24
|
+
// options
|
|
25
|
+
const typeOptionsName = `IActionOptions${beanNameCapitalize}`;
|
|
26
|
+
// import
|
|
27
|
+
const contentImports: string[] = [];
|
|
28
|
+
contentImports.push("import type { TypeActionOptionsRest } from 'zova-module-a-action';");
|
|
29
|
+
contentImports.push(`import type { ${typeOptionsName} } from '../../src/bean/${fileNameJS}';`);
|
|
30
|
+
// component
|
|
31
|
+
const componentNamePrefix = 'AA';
|
|
32
|
+
const componentName = beanName;
|
|
33
|
+
const componentNameFull = `${componentNamePrefix}${toUpperCaseFirstChar(combineResourceName(componentName, moduleName, true, true))}`;
|
|
34
|
+
const contentComponent = `export function ${componentNameFull}(
|
|
35
|
+
_props: TypeActionOptionsRest<${typeOptionsName}>,
|
|
36
|
+
) {
|
|
37
|
+
return '${moduleName}:${beanName}';
|
|
38
|
+
}`;
|
|
39
|
+
// content
|
|
40
|
+
const content = `${contentImports.join('\n')}
|
|
41
|
+
|
|
42
|
+
${contentComponent}
|
|
43
|
+
`;
|
|
44
|
+
// output
|
|
45
|
+
const fileDest = path.join(modulePath, `rest/action/${beanName}.ts`);
|
|
46
|
+
await fse.outputFile(fileDest, content);
|
|
47
|
+
// actions
|
|
48
|
+
const fileComponents = path.join(modulePath, 'rest/actions.ts');
|
|
49
|
+
let contentComponents = '';
|
|
50
|
+
if (fse.existsSync(fileComponents)) {
|
|
51
|
+
contentComponents = (await fse.readFile(fileComponents)).toString();
|
|
52
|
+
}
|
|
53
|
+
const exportContent = `export * from './action/${beanName}.js';`;
|
|
54
|
+
if (!contentComponents.includes(exportContent)) {
|
|
55
|
+
contentComponents = `${contentComponents}${exportContent}\n`;
|
|
56
|
+
await fse.outputFile(fileComponents, contentComponents);
|
|
57
|
+
}
|
|
58
|
+
// index
|
|
59
|
+
const exportIndexContent = "export * from './actions.js';";
|
|
60
|
+
await generateRestIndex(modulePath, exportIndexContent);
|
|
61
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import fse from 'fs-extra';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
|
|
4
|
+
export async function generateRestIndex(modulePath: string, append: string) {
|
|
5
|
+
// index
|
|
6
|
+
const fileIndex = path.join(modulePath, 'rest/index.ts');
|
|
7
|
+
let contentIndex = '';
|
|
8
|
+
if (fse.existsSync(fileIndex)) {
|
|
9
|
+
contentIndex = (await fse.readFile(fileIndex)).toString();
|
|
10
|
+
}
|
|
11
|
+
if (!contentIndex.includes(append)) {
|
|
12
|
+
contentIndex = `${contentIndex}${append}\n`;
|
|
13
|
+
await fse.outputFile(fileIndex, contentIndex);
|
|
14
|
+
}
|
|
15
|
+
}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { BeanInfo, BeanScopeBase, BeanSimple, beanFullNameFromOnionName, cast, createBeanDecorator, deepExtend } from "zova";
|
|
2
|
+
import { Scope } from "zova-module-a-bean";
|
|
3
|
+
//#region src/lib/performAction.ts
|
|
4
|
+
function $performAction(sys, actionName, options, renderContext, next) {
|
|
5
|
+
if (!next) next = (actionRes) => {
|
|
6
|
+
return actionRes;
|
|
7
|
+
};
|
|
8
|
+
const beanFullName = beanFullNameFromOnionName(actionName, "action");
|
|
9
|
+
const beanInstance = sys.bean._getBeanSyncOnly(beanFullName);
|
|
10
|
+
if (beanInstance) return _renderEventActionNormal_inner(beanInstance, options, renderContext, next);
|
|
11
|
+
return sys.bean._getBean(beanFullName, false).then((beanInstance) => {
|
|
12
|
+
return _renderEventActionNormal_inner(beanInstance, options, renderContext, next);
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
function _renderEventActionNormal_inner(beanInstance, options, renderContext, next) {
|
|
16
|
+
const onionOptions = beanInstance.$onionOptions;
|
|
17
|
+
const props = onionOptions ? deepExtend({}, onionOptions, options) : options ?? {};
|
|
18
|
+
return beanInstance.execute(props, renderContext, next);
|
|
19
|
+
}
|
|
20
|
+
//#endregion
|
|
21
|
+
//#region src/monkey.ts
|
|
22
|
+
var Monkey = class extends BeanSimple {
|
|
23
|
+
async beanInit(bean, beanInstance) {
|
|
24
|
+
const self = this;
|
|
25
|
+
bean.defineProperty(beanInstance, "$performAction", {
|
|
26
|
+
enumerable: false,
|
|
27
|
+
configurable: true,
|
|
28
|
+
get() {
|
|
29
|
+
return function(actionName, options, renderContext, next) {
|
|
30
|
+
renderContext = Object.assign({
|
|
31
|
+
app: cast(beanInstance).app,
|
|
32
|
+
ctx: cast(beanInstance).ctx,
|
|
33
|
+
$host: beanInstance
|
|
34
|
+
}, renderContext);
|
|
35
|
+
return $performAction(self.sys, actionName, options, renderContext, next);
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
//#endregion
|
|
42
|
+
//#region src/.metadata/index.ts
|
|
43
|
+
/** monkey: end */
|
|
44
|
+
/** scope: begin */
|
|
45
|
+
var _dec, _dec2, _class;
|
|
46
|
+
var ScopeModuleAAction = (_dec = Scope(), _dec2 = BeanInfo({ module: "a-action" }), _dec(_class = _dec2(_class = class ScopeModuleAAction extends BeanScopeBase {}) || _class) || _class);
|
|
47
|
+
/** scope: end */
|
|
48
|
+
//#endregion
|
|
49
|
+
//#region src/lib/action.ts
|
|
50
|
+
function Action(options) {
|
|
51
|
+
return createBeanDecorator("action", "sys", true, options);
|
|
52
|
+
}
|
|
53
|
+
//#endregion
|
|
54
|
+
//#region src/types/action.ts
|
|
55
|
+
var SymbolActionResult = Symbol("SymbolActionResult");
|
|
56
|
+
//#endregion
|
|
57
|
+
export { $performAction, Action, Monkey, ScopeModuleAAction, SymbolActionResult };
|
|
58
|
+
|
|
59
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../src/lib/performAction.ts","../src/monkey.ts","../src/.metadata/index.ts","../src/lib/action.ts","../src/types/action.ts"],"sourcesContent":["import type { ZovaSys } from 'zova';\nimport type { IJsxRenderContextBase } from 'zova-module-a-openapi';\n\nimport { beanFullNameFromOnionName, deepExtend } from 'zova';\n\nimport type { IActionRecord, SymbolActionResult } from '../types/action.js';\n\nexport function $performAction<T extends keyof IActionRecord>(\n sys: ZovaSys,\n actionName: T,\n options: Partial<IActionRecord[T]> | undefined,\n renderContext: IJsxRenderContextBase,\n next?: Function,\n): IActionRecord[T][typeof SymbolActionResult] {\n if (!next) {\n next = actionRes => {\n return actionRes;\n };\n }\n // action\n const beanFullName = beanFullNameFromOnionName(actionName, 'action');\n const beanInstance = sys.bean._getBeanSyncOnly(beanFullName);\n if (beanInstance) {\n // sync\n return _renderEventActionNormal_inner(beanInstance, options, renderContext, next);\n }\n // async\n return sys.bean._getBean(beanFullName, false).then(beanInstance => {\n return _renderEventActionNormal_inner(beanInstance, options, renderContext, next);\n });\n}\n\nfunction _renderEventActionNormal_inner(beanInstance: any, options: {} | undefined, renderContext: IJsxRenderContextBase, next?: Function) {\n const onionOptions = beanInstance.$onionOptions;\n // props\n const props = onionOptions ? deepExtend({}, onionOptions, options) : (options ?? {});\n return beanInstance.execute(props, renderContext, next);\n}\n","import type { BeanBase, BeanContainer, IMonkeyBeanInit } from 'zova';\nimport type { IJsxRenderContextBase } from 'zova-module-a-openapi';\n\nimport { BeanSimple, cast } from 'zova';\n\nimport type { IActionRecord } from './types/action.js';\n\nimport { $performAction } from './lib/performAction.js';\n\nexport class Monkey extends BeanSimple implements IMonkeyBeanInit {\n async beanInit(bean: BeanContainer, beanInstance: BeanBase) {\n const self = this;\n bean.defineProperty(beanInstance, '$performAction', {\n enumerable: false,\n configurable: true,\n get() {\n return function <T extends keyof IActionRecord>(\n actionName: T,\n options: Partial<IActionRecord[T]> | undefined,\n renderContext?: IJsxRenderContextBase,\n next?: Function,\n ) {\n renderContext = Object.assign(\n {\n app: cast(beanInstance).app,\n ctx: cast(beanInstance).ctx,\n $host: beanInstance,\n },\n renderContext,\n );\n return $performAction(self.sys, actionName, options, renderContext, next);\n };\n },\n });\n }\n}\n","// eslint-disable\n/** monkey: begin */\nexport * from '../monkey.js';\n/** monkey: end */\n/** scope: begin */\nimport { BeanScopeBase, type BeanScopeUtil } from 'zova';\nimport { Scope } from 'zova-module-a-bean';\n\n@Scope()\nexport class ScopeModuleAAction extends BeanScopeBase {}\n\nexport interface ScopeModuleAAction {\n util: BeanScopeUtil;\n}\n\nimport 'zova';\ndeclare module 'zova' {\n export interface IBeanScopeRecord {\n 'a-action': ScopeModuleAAction;\n }\n \n \n\n \n\n \n}\n \n/** scope: end */\n","import type { PowerPartial } from 'zova';\n\nimport { createBeanDecorator } from 'zova';\n\nimport type { IDecoratorActionOptions } from '../types/action.js';\n\nexport function Action<T extends IDecoratorActionOptions>(options?: PowerPartial<T>): ClassDecorator {\n return createBeanDecorator('action', 'sys', true, options);\n}\n","import type { OmitNever } from 'zova';\nimport type { ServiceOnion } from 'zova-module-a-bean';\nimport type { IJsxRenderContextBase } from 'zova-module-a-openapi';\n\nexport const SymbolActionResult = Symbol('SymbolActionResult');\n\nexport type TypeActionOptionsRest<T> = Omit<T, typeof SymbolActionResult> & { res?: string };\n\nexport type NextActionExecute = (res?: any) => any | Promise<any>;\n\nexport interface IActionsRecord {}\n\nexport interface IActionRecord {}\n\nexport interface IActionExecute {\n execute(options: IDecoratorActionOptions, renderContext: IJsxRenderContextBase, next: NextActionExecute): any | Promise<any>;\n}\n\nexport interface IDecoratorActionOptions<Result = any> {\n [SymbolActionResult]: Result;\n // res?: string; // need not define here\n}\n\ndeclare module 'zova-module-a-bean' {\n export interface SysOnion {\n action: ServiceOnion<IDecoratorActionOptions, keyof IActionRecord>;\n }\n}\n\ndeclare module 'zova' {\n export interface ConfigOnions {\n action: OmitNever<IActionRecord>;\n }\n\n export interface IBeanSceneRecord {\n action: never;\n }\n}\n"],"mappings":";;;AACA,SAAc,eAAA,KAAsB,YAAY,SAAS,eAAS,MAAA;WAElE,SAAS,cAAA;;;CAKP,MAAK,eAAO,0BAAA,YAAA,SAAA;CACZ,MAAA,eAAa,IAAA,KAAA,iBAAA,aAAA;AACb,KAAA,aAEA,QAAO,+BAAQ,cAAA,SAAA,eAAA,KAAA;AAGf,QAAO,IAAE,KAAA,SAAa,cAAA,MAAA,CAAA,MAAA,iBAAA;AACpB,SAAE,+BAAgB,cAAA,SAAA,eAAA,KAAA;GAClB;;AAEJ,SAAK,+BAAA,cAAA,SAAA,eAAA,MAAA;CACH,MAAM,eAAe,aAAA;CAErB,MAAI,QAAA,eAAc,WAAA,EAAA,EAAA,cAAA,QAAA,GAAA,WAAA,EAAA;AAClB,QAAK,aAAA,QAAA,OAAA,eAAA,KAAA;;;;;CCpBP,MAAQ,SAAC,MAAY,cAAa;;AAElC,OAAO,eAAO,cAAwB,kBAAgB;;GAEhD,cAAI;;AAEH,WAAM,SAAO,YAAQ,SAAW,eAAW,MAAgB;AAC1D,qBAAe,OAAA,OAAe;MAC5B,KAAO,KAAI,aAAA,CAAA;MACZ,KAAA,KAAA,aAAe,CAAY;MAC9B,OAAY;MACZ,EAAA,cAAkB;AACd,YAAE,eAAA,KAAA,KAAA,YAAA,SAAA,eAAA,KAAA;;;GAGP,CAAC;;;;;;;AClBN,IAAG,MAAO,OAAA;AASV,IAAO,sBAAyB,OAAQ,OAAA,EAAA,QAAe,SAAA,EAAA,QAAA,YAEvD,CAAA,EAAA,KAAO,SAAU,MAAA,SAAA,MAAmB,2BAAA,cAAA,GAAA,IAAA,OAAA,IAAA;;;;;ACTpC,QAAS,oBAAoB,UAAQ,OAAK,MAAA,QAAA;;;;ACF1C,IAAa,qBAAmB,OAAK,qBAAA"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { combineResourceName } from '@cabloy/utils';
|
|
2
|
+
import { toUpperCaseFirstChar } from '@cabloy/word-utils';
|
|
3
|
+
import fse from 'fs-extra';
|
|
4
|
+
import path from 'node:path';
|
|
5
|
+
import { generateRestIndex } from "./utils.js";
|
|
6
|
+
export default async function (options) {
|
|
7
|
+
const { globFiles } = options;
|
|
8
|
+
for (const globFile of globFiles) {
|
|
9
|
+
if (globFile.isIgnore)
|
|
10
|
+
continue;
|
|
11
|
+
// restComponent
|
|
12
|
+
await generateRestAction(options, globFile);
|
|
13
|
+
}
|
|
14
|
+
return '';
|
|
15
|
+
}
|
|
16
|
+
async function generateRestAction(options, globFile) {
|
|
17
|
+
const { moduleName, modulePath } = options;
|
|
18
|
+
const { beanName, beanNameCapitalize, fileNameJS } = globFile;
|
|
19
|
+
// options
|
|
20
|
+
const typeOptionsName = `IActionOptions${beanNameCapitalize}`;
|
|
21
|
+
// import
|
|
22
|
+
const contentImports = [];
|
|
23
|
+
contentImports.push("import type { TypeActionOptionsRest } from 'zova-module-a-action';");
|
|
24
|
+
contentImports.push(`import type { ${typeOptionsName} } from '../../src/bean/${fileNameJS}';`);
|
|
25
|
+
// component
|
|
26
|
+
const componentNamePrefix = 'AA';
|
|
27
|
+
const componentName = beanName;
|
|
28
|
+
const componentNameFull = `${componentNamePrefix}${toUpperCaseFirstChar(combineResourceName(componentName, moduleName, true, true))}`;
|
|
29
|
+
const contentComponent = `export function ${componentNameFull}(
|
|
30
|
+
_props: TypeActionOptionsRest<${typeOptionsName}>,
|
|
31
|
+
) {
|
|
32
|
+
return '${moduleName}:${beanName}';
|
|
33
|
+
}`;
|
|
34
|
+
// content
|
|
35
|
+
const content = `${contentImports.join('\n')}
|
|
36
|
+
|
|
37
|
+
${contentComponent}
|
|
38
|
+
`;
|
|
39
|
+
// output
|
|
40
|
+
const fileDest = path.join(modulePath, `rest/action/${beanName}.ts`);
|
|
41
|
+
await fse.outputFile(fileDest, content);
|
|
42
|
+
// actions
|
|
43
|
+
const fileComponents = path.join(modulePath, 'rest/actions.ts');
|
|
44
|
+
let contentComponents = '';
|
|
45
|
+
if (fse.existsSync(fileComponents)) {
|
|
46
|
+
contentComponents = (await fse.readFile(fileComponents)).toString();
|
|
47
|
+
}
|
|
48
|
+
const exportContent = `export * from './action/${beanName}.js';`;
|
|
49
|
+
if (!contentComponents.includes(exportContent)) {
|
|
50
|
+
contentComponents = `${contentComponents}${exportContent}\n`;
|
|
51
|
+
await fse.outputFile(fileComponents, contentComponents);
|
|
52
|
+
}
|
|
53
|
+
// index
|
|
54
|
+
const exportIndexContent = "export * from './actions.js';";
|
|
55
|
+
await generateRestIndex(modulePath, exportIndexContent);
|
|
56
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import fse from 'fs-extra';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
export async function generateRestIndex(modulePath, append) {
|
|
4
|
+
// index
|
|
5
|
+
const fileIndex = path.join(modulePath, 'rest/index.ts');
|
|
6
|
+
let contentIndex = '';
|
|
7
|
+
if (fse.existsSync(fileIndex)) {
|
|
8
|
+
contentIndex = (await fse.readFile(fileIndex)).toString();
|
|
9
|
+
}
|
|
10
|
+
if (!contentIndex.includes(append)) {
|
|
11
|
+
contentIndex = `${contentIndex}${append}\n`;
|
|
12
|
+
await fse.outputFile(fileIndex, contentIndex);
|
|
13
|
+
}
|
|
14
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "zova-module-a-action",
|
|
3
|
+
"version": "5.1.0",
|
|
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
|
+
],
|
|
19
|
+
"type": "module",
|
|
20
|
+
"exports": {
|
|
21
|
+
".": {
|
|
22
|
+
"types": [
|
|
23
|
+
"./src/index.ts",
|
|
24
|
+
"./dist/index.d.ts"
|
|
25
|
+
],
|
|
26
|
+
"default": "./dist/index.js"
|
|
27
|
+
},
|
|
28
|
+
"./*": "./*"
|
|
29
|
+
},
|
|
30
|
+
"scripts": {
|
|
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"
|
|
36
|
+
},
|
|
37
|
+
"title": "a-action",
|
|
38
|
+
"zovaModule": {
|
|
39
|
+
"onions": {
|
|
40
|
+
"action": {
|
|
41
|
+
"beanGeneral": true,
|
|
42
|
+
"optionsGlobalInterfaceName": "IDecoratorActionOptions",
|
|
43
|
+
"optionsGlobalInterfaceFrom": "zova-module-a-action",
|
|
44
|
+
"boilerplate": "action/boilerplate",
|
|
45
|
+
"metadataCustom": "action/metadata/generate.ts"
|
|
46
|
+
}
|
|
47
|
+
},
|
|
48
|
+
"capabilities": {
|
|
49
|
+
"monkey": true
|
|
50
|
+
},
|
|
51
|
+
"dependencies": {}
|
|
52
|
+
},
|
|
53
|
+
"gitHead": "bf1ceb4582381c74ba41ccf11b89d3b9e7b73628"
|
|
54
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
// eslint-disable
|
|
2
|
+
/** monkey: begin */
|
|
3
|
+
export * from '../monkey.js';
|
|
4
|
+
/** monkey: end */
|
|
5
|
+
/** scope: begin */
|
|
6
|
+
import { BeanScopeBase, type BeanScopeUtil } from 'zova';
|
|
7
|
+
import { Scope } from 'zova-module-a-bean';
|
|
8
|
+
|
|
9
|
+
@Scope()
|
|
10
|
+
export class ScopeModuleAAction extends BeanScopeBase {}
|
|
11
|
+
|
|
12
|
+
export interface ScopeModuleAAction {
|
|
13
|
+
util: BeanScopeUtil;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
import 'zova';
|
|
17
|
+
declare module 'zova' {
|
|
18
|
+
export interface IBeanScopeRecord {
|
|
19
|
+
'a-action': ScopeModuleAAction;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/** scope: end */
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { PowerPartial } from 'zova';
|
|
2
|
+
|
|
3
|
+
import { createBeanDecorator } from 'zova';
|
|
4
|
+
|
|
5
|
+
import type { IDecoratorActionOptions } from '../types/action.js';
|
|
6
|
+
|
|
7
|
+
export function Action<T extends IDecoratorActionOptions>(options?: PowerPartial<T>): ClassDecorator {
|
|
8
|
+
return createBeanDecorator('action', 'sys', true, options);
|
|
9
|
+
}
|
package/src/lib/index.ts
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { ZovaSys } from 'zova';
|
|
2
|
+
import type { IJsxRenderContextBase } from 'zova-module-a-openapi';
|
|
3
|
+
|
|
4
|
+
import { beanFullNameFromOnionName, deepExtend } from 'zova';
|
|
5
|
+
|
|
6
|
+
import type { IActionRecord, SymbolActionResult } from '../types/action.js';
|
|
7
|
+
|
|
8
|
+
export function $performAction<T extends keyof IActionRecord>(
|
|
9
|
+
sys: ZovaSys,
|
|
10
|
+
actionName: T,
|
|
11
|
+
options: Partial<IActionRecord[T]> | undefined,
|
|
12
|
+
renderContext: IJsxRenderContextBase,
|
|
13
|
+
next?: Function,
|
|
14
|
+
): IActionRecord[T][typeof SymbolActionResult] {
|
|
15
|
+
if (!next) {
|
|
16
|
+
next = actionRes => {
|
|
17
|
+
return actionRes;
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
// action
|
|
21
|
+
const beanFullName = beanFullNameFromOnionName(actionName, 'action');
|
|
22
|
+
const beanInstance = sys.bean._getBeanSyncOnly(beanFullName);
|
|
23
|
+
if (beanInstance) {
|
|
24
|
+
// sync
|
|
25
|
+
return _renderEventActionNormal_inner(beanInstance, options, renderContext, next);
|
|
26
|
+
}
|
|
27
|
+
// async
|
|
28
|
+
return sys.bean._getBean(beanFullName, false).then(beanInstance => {
|
|
29
|
+
return _renderEventActionNormal_inner(beanInstance, options, renderContext, next);
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function _renderEventActionNormal_inner(beanInstance: any, options: {} | undefined, renderContext: IJsxRenderContextBase, next?: Function) {
|
|
34
|
+
const onionOptions = beanInstance.$onionOptions;
|
|
35
|
+
// props
|
|
36
|
+
const props = onionOptions ? deepExtend({}, onionOptions, options) : (options ?? {});
|
|
37
|
+
return beanInstance.execute(props, renderContext, next);
|
|
38
|
+
}
|
package/src/monkey.ts
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { BeanBase, BeanContainer, IMonkeyBeanInit } from 'zova';
|
|
2
|
+
import type { IJsxRenderContextBase } from 'zova-module-a-openapi';
|
|
3
|
+
|
|
4
|
+
import { BeanSimple, cast } from 'zova';
|
|
5
|
+
|
|
6
|
+
import type { IActionRecord } from './types/action.js';
|
|
7
|
+
|
|
8
|
+
import { $performAction } from './lib/performAction.js';
|
|
9
|
+
|
|
10
|
+
export class Monkey extends BeanSimple implements IMonkeyBeanInit {
|
|
11
|
+
async beanInit(bean: BeanContainer, beanInstance: BeanBase) {
|
|
12
|
+
const self = this;
|
|
13
|
+
bean.defineProperty(beanInstance, '$performAction', {
|
|
14
|
+
enumerable: false,
|
|
15
|
+
configurable: true,
|
|
16
|
+
get() {
|
|
17
|
+
return function <T extends keyof IActionRecord>(
|
|
18
|
+
actionName: T,
|
|
19
|
+
options: Partial<IActionRecord[T]> | undefined,
|
|
20
|
+
renderContext?: IJsxRenderContextBase,
|
|
21
|
+
next?: Function,
|
|
22
|
+
) {
|
|
23
|
+
renderContext = Object.assign(
|
|
24
|
+
{
|
|
25
|
+
app: cast(beanInstance).app,
|
|
26
|
+
ctx: cast(beanInstance).ctx,
|
|
27
|
+
$host: beanInstance,
|
|
28
|
+
},
|
|
29
|
+
renderContext,
|
|
30
|
+
);
|
|
31
|
+
return $performAction(self.sys, actionName, options, renderContext, next);
|
|
32
|
+
};
|
|
33
|
+
},
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { OmitNever } from 'zova';
|
|
2
|
+
import type { ServiceOnion } from 'zova-module-a-bean';
|
|
3
|
+
import type { IJsxRenderContextBase } from 'zova-module-a-openapi';
|
|
4
|
+
|
|
5
|
+
export const SymbolActionResult = Symbol('SymbolActionResult');
|
|
6
|
+
|
|
7
|
+
export type TypeActionOptionsRest<T> = Omit<T, typeof SymbolActionResult> & { res?: string };
|
|
8
|
+
|
|
9
|
+
export type NextActionExecute = (res?: any) => any | Promise<any>;
|
|
10
|
+
|
|
11
|
+
export interface IActionsRecord {}
|
|
12
|
+
|
|
13
|
+
export interface IActionRecord {}
|
|
14
|
+
|
|
15
|
+
export interface IActionExecute {
|
|
16
|
+
execute(options: IDecoratorActionOptions, renderContext: IJsxRenderContextBase, next: NextActionExecute): any | Promise<any>;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export interface IDecoratorActionOptions<Result = any> {
|
|
20
|
+
[SymbolActionResult]: Result;
|
|
21
|
+
// res?: string; // need not define here
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
declare module 'zova-module-a-bean' {
|
|
25
|
+
export interface SysOnion {
|
|
26
|
+
action: ServiceOnion<IDecoratorActionOptions, keyof IActionRecord>;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
declare module 'zova' {
|
|
31
|
+
export interface ConfigOnions {
|
|
32
|
+
action: OmitNever<IActionRecord>;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export interface IBeanSceneRecord {
|
|
36
|
+
action: never;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { IJsxRenderContextBase } from 'zova-module-a-openapi';
|
|
2
|
+
|
|
3
|
+
import type { IActionRecord, SymbolActionResult } from './action.js';
|
|
4
|
+
import 'zova';
|
|
5
|
+
|
|
6
|
+
declare module 'zova' {
|
|
7
|
+
export interface BeanBase {
|
|
8
|
+
$performAction: <T extends keyof IActionRecord>(
|
|
9
|
+
actionName: T,
|
|
10
|
+
options: Partial<IActionRecord[T]> | undefined,
|
|
11
|
+
renderContext?: IJsxRenderContextBase,
|
|
12
|
+
next?: Function,
|
|
13
|
+
) => IActionRecord[T][typeof SymbolActionResult];
|
|
14
|
+
}
|
|
15
|
+
}
|