zova-module-a-command 5.1.17
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/command/boilerplate/{{sceneName}}.{{beanName}}.tsx_ +15 -0
- package/dist/.metadata/index.d.ts +18 -0
- package/dist/.metadata/index.d.ts.map +1 -0
- package/dist/.metadata/this.d.ts +3 -0
- package/dist/.metadata/this.d.ts.map +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +59 -0
- package/dist/index.js.map +1 -0
- package/dist/lib/command.d.ts +4 -0
- package/dist/lib/command.d.ts.map +1 -0
- package/dist/lib/index.d.ts +3 -0
- package/dist/lib/index.d.ts.map +1 -0
- package/dist/lib/performCommand.d.ts +5 -0
- package/dist/lib/performCommand.d.ts.map +1 -0
- package/dist/monkey.d.ts +6 -0
- package/dist/monkey.d.ts.map +1 -0
- package/dist/types/command.d.ts +42 -0
- package/dist/types/command.d.ts.map +1 -0
- package/dist/types/index.d.ts +3 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/performCommand.d.ts +9 -0
- package/dist/types/performCommand.d.ts.map +1 -0
- package/package.json +48 -0
- package/src/.metadata/index.ts +28 -0
- package/src/.metadata/this.ts +2 -0
- package/src/index.ts +3 -0
- package/src/lib/command.ts +11 -0
- package/src/lib/index.ts +2 -0
- package/src/lib/performCommand.ts +43 -0
- package/src/monkey.ts +36 -0
- package/src/types/command.ts +53 -0
- package/src/types/index.ts +2 -0
- package/src/types/performCommand.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,15 @@
|
|
|
1
|
+
import type { IJsxRenderContextBase } from 'zova-module-a-openapi';
|
|
2
|
+
|
|
3
|
+
import { BeanBase } from 'zova';
|
|
4
|
+
import { Command, type ICommandExecute, type ICommandOptionsBase, type NextCommandExecute } from 'zova-module-a-command';
|
|
5
|
+
|
|
6
|
+
export type TypeCommand<%=argv.beanNameCapitalize%>Result = unknown;
|
|
7
|
+
|
|
8
|
+
export interface ICommandOptions<%=argv.beanNameCapitalize%> extends ICommandOptionsBase<TypeCommand<%=argv.beanNameCapitalize%>Result> {}
|
|
9
|
+
|
|
10
|
+
@Command<ICommandOptions<%=argv.beanNameCapitalize%>>()
|
|
11
|
+
export class Command<%=argv.beanNameCapitalize%> extends BeanBase implements ICommandExecute {
|
|
12
|
+
execute(_options: ICommandOptions<%=argv.beanNameCapitalize%>, _renderContext: IJsxRenderContextBase, next: NextCommandExecute) {
|
|
13
|
+
return next();
|
|
14
|
+
}
|
|
15
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/** monkey: begin */
|
|
2
|
+
export * from '../monkey.js';
|
|
3
|
+
/** monkey: end */
|
|
4
|
+
/** scope: begin */
|
|
5
|
+
import { BeanScopeBase, type BeanScopeUtil } from 'zova';
|
|
6
|
+
export declare class ScopeModuleACommand extends BeanScopeBase {
|
|
7
|
+
}
|
|
8
|
+
export interface ScopeModuleACommand {
|
|
9
|
+
util: BeanScopeUtil;
|
|
10
|
+
}
|
|
11
|
+
import 'zova';
|
|
12
|
+
declare module 'zova' {
|
|
13
|
+
interface IBeanScopeRecord {
|
|
14
|
+
'a-command': ScopeModuleACommand;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
/** scope: end */
|
|
18
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/.metadata/index.ts"],"names":[],"mappings":"AACA,oBAAoB;AACpB,cAAc,cAAc,CAAC;AAC7B,kBAAkB;AAClB,mBAAmB;AACnB,OAAO,EAAE,aAAa,EAAE,KAAK,aAAa,EAAE,MAAM,MAAM,CAAC;AAGzD,qBACa,mBAAoB,SAAQ,aAAa;CAAG;AAEzD,MAAM,WAAW,mBAAmB;IAClC,IAAI,EAAE,aAAa,CAAC;CACrB;AAED,OAAO,MAAM,CAAC;AACd,OAAO,QAAQ,MAAM,CAAC;IACpB,UAAiB,gBAAgB;QAC/B,WAAW,EAAE,mBAAmB,CAAC;KAClC;CAMF;AAED,iBAAiB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"this.d.ts","sourceRoot":"","sources":["../../src/.metadata/this.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,cAAc,cAAc,CAAC;AAC1C,OAAO,EAAE,mBAAmB,IAAI,WAAW,EAAE,MAAM,YAAY,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,sBAAsB,CAAC;AACrC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,kBAAkB,CAAC"}
|
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/performCommand.ts
|
|
4
|
+
function $performCommand(sys, commandName, options, renderContext, next) {
|
|
5
|
+
if (!next) next = (commandRes) => {
|
|
6
|
+
return commandRes;
|
|
7
|
+
};
|
|
8
|
+
const beanFullName = beanFullNameFromOnionName(commandName, "command");
|
|
9
|
+
const beanInstance = sys.bean._getBeanSyncOnly(beanFullName);
|
|
10
|
+
if (beanInstance) return _renderEventCommandNormal_inner(beanInstance, options, renderContext, next);
|
|
11
|
+
return sys.bean._getBean(beanFullName, false).then((beanInstance) => {
|
|
12
|
+
return _renderEventCommandNormal_inner(beanInstance, options, renderContext, next);
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
function _renderEventCommandNormal_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, "$performCommand", {
|
|
26
|
+
enumerable: false,
|
|
27
|
+
configurable: true,
|
|
28
|
+
get() {
|
|
29
|
+
return function(commandName, options, renderContext, next) {
|
|
30
|
+
renderContext = Object.assign({
|
|
31
|
+
app: cast(beanInstance).app,
|
|
32
|
+
ctx: cast(beanInstance).ctx,
|
|
33
|
+
$host: beanInstance
|
|
34
|
+
}, renderContext);
|
|
35
|
+
return $performCommand(self.sys, commandName, 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 ScopeModuleACommand = (_dec = Scope(), _dec2 = BeanInfo({ module: "a-command" }), _dec(_class = _dec2(_class = class ScopeModuleACommand extends BeanScopeBase {}) || _class) || _class);
|
|
47
|
+
/** scope: end */
|
|
48
|
+
//#endregion
|
|
49
|
+
//#region src/lib/command.ts
|
|
50
|
+
function Command(options) {
|
|
51
|
+
return createBeanDecorator("command", "sys", true, options);
|
|
52
|
+
}
|
|
53
|
+
//#endregion
|
|
54
|
+
//#region src/types/command.ts
|
|
55
|
+
var SymbolCommandResult = Symbol("SymbolCommandResult");
|
|
56
|
+
//#endregion
|
|
57
|
+
export { $performCommand, Command, Monkey, ScopeModuleACommand, SymbolCommandResult };
|
|
58
|
+
|
|
59
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../src/lib/performCommand.ts","../src/monkey.ts","../src/.metadata/index.ts","../src/lib/command.ts","../src/types/command.ts"],"sourcesContent":["import type { ZovaSys } from 'zova';\nimport type { IJsxRenderContextBase } from 'zova-module-a-openapi';\n\nimport { beanFullNameFromOnionName, deepExtend } from 'zova';\n\nimport type { ICommandRecord, SymbolCommandResult } from '../types/command.js';\n\nexport function $performCommand<T extends keyof ICommandRecord>(\n sys: ZovaSys,\n commandName: T,\n options: Partial<ICommandRecord[T]> | undefined,\n renderContext: IJsxRenderContextBase,\n next?: Function,\n): ICommandRecord[T][typeof SymbolCommandResult] {\n if (!next) {\n next = commandRes => {\n return commandRes;\n };\n }\n // command\n const beanFullName = beanFullNameFromOnionName(commandName, 'command');\n const beanInstance = sys.bean._getBeanSyncOnly(beanFullName);\n if (beanInstance) {\n // sync\n return _renderEventCommandNormal_inner(beanInstance, options, renderContext, next);\n }\n // async\n return sys.bean._getBean(beanFullName, false).then(beanInstance => {\n return _renderEventCommandNormal_inner(beanInstance, options, renderContext, next);\n });\n}\n\nfunction _renderEventCommandNormal_inner(\n beanInstance: any,\n options: {} | undefined,\n renderContext: IJsxRenderContextBase,\n next?: Function,\n) {\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 { ICommandRecord } from './types/command.js';\n\nimport { $performCommand } from './lib/performCommand.js';\n\nexport class Monkey extends BeanSimple implements IMonkeyBeanInit {\n async beanInit(bean: BeanContainer, beanInstance: BeanBase) {\n const self = this;\n bean.defineProperty(beanInstance, '$performCommand', {\n enumerable: false,\n configurable: true,\n get() {\n return function <T extends keyof ICommandRecord>(\n commandName: T,\n options: Partial<ICommandRecord[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 $performCommand(self.sys, commandName, 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 ScopeModuleACommand extends BeanScopeBase {}\n\nexport interface ScopeModuleACommand {\n util: BeanScopeUtil;\n}\n\nimport 'zova';\ndeclare module 'zova' {\n export interface IBeanScopeRecord {\n 'a-command': ScopeModuleACommand;\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 { IDecoratorCommandOptions } from '../types/command.js';\n\nexport function Command<T extends IDecoratorCommandOptions>(\n options?: PowerPartial<T>,\n): ClassDecorator {\n return createBeanDecorator('command', '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\nimport { TableIdentity } from 'table-identity';\n\nexport const SymbolCommandResult = Symbol('SymbolCommandResult');\n\nexport type TypeCommandOptions<K extends keyof ICommandRecord> = {\n name: K;\n options?: Omit<ICommandRecord[K], typeof SymbolCommandResult>;\n res?: string;\n};\n\nexport type NextCommandExecute = (res?: any) => any | Promise<any>;\n\nexport interface ICommandRecord {}\n\nexport interface ICommandExecute {\n execute(options: IDecoratorCommandOptions, renderContext: IJsxRenderContextBase, next: NextCommandExecute): any | Promise<any>;\n}\n\nexport interface IDecoratorCommandOptions<Result = any> {\n [SymbolCommandResult]: Result;\n // res?: string; // need not define here\n}\n\nexport interface ICommandOptionsBase<Result = any> extends IDecoratorCommandOptions<Result> {}\n\nexport interface ICommandBulkOptionsBase<Result = any> extends ICommandOptionsBase<Result> {\n resource?: string;\n}\n\nexport interface ICommandRowOptionsBase<Result = any> extends ICommandOptionsBase<Result> {\n resource?: string;\n id?: TableIdentity;\n}\n\ndeclare module 'zova-module-a-bean' {\n export interface SysOnion {\n command: ServiceOnion<IDecoratorCommandOptions, keyof ICommandRecord>;\n }\n}\n\ndeclare module 'zova' {\n export interface ConfigOnions {\n command: OmitNever<ICommandRecord>;\n }\n\n export interface IBeanSceneRecord {\n command: never;\n }\n}\n"],"mappings":";;;AACA,SAAc,gBAAA,KAAuB,aAAY,SAAS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,EAAE,wBAAwB,EAAE,MAAM,qBAAqB,CAAC;AAEpE,wBAAgB,OAAO,CAAC,CAAC,SAAS,wBAAwB,EACxD,OAAO,CAAC,EAAE,YAAY,CAAC,CAAC,CAAC,GACxB,cAAc,CAEhB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/lib/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,qBAAqB,CAAC"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { ZovaSys } from 'zova';
|
|
2
|
+
import type { IJsxRenderContextBase } from 'zova-module-a-openapi';
|
|
3
|
+
import type { ICommandRecord, SymbolCommandResult } from '../types/command.js';
|
|
4
|
+
export declare function $performCommand<T extends keyof ICommandRecord>(sys: ZovaSys, commandName: T, options: Partial<ICommandRecord[T]> | undefined, renderContext: IJsxRenderContextBase, next?: Function): ICommandRecord[T][typeof SymbolCommandResult];
|
|
5
|
+
//# sourceMappingURL=performCommand.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"performCommand.d.ts","sourceRoot":"","sources":["../../src/lib/performCommand.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AACpC,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,uBAAuB,CAAC;AAInE,OAAO,KAAK,EAAE,cAAc,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAE/E,wBAAgB,eAAe,CAAC,CAAC,SAAS,MAAM,cAAc,EAC5D,GAAG,EAAE,OAAO,EACZ,WAAW,EAAE,CAAC,EACd,OAAO,EAAE,OAAO,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,GAAG,SAAS,EAC/C,aAAa,EAAE,qBAAqB,EACpC,IAAI,CAAC,EAAE,QAAQ,GACd,cAAc,CAAC,CAAC,CAAC,CAAC,OAAO,mBAAmB,CAAC,CAiB/C"}
|
package/dist/monkey.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { BeanBase, BeanContainer, IMonkeyBeanInit } from 'zova';
|
|
2
|
+
import { BeanSimple } from 'zova';
|
|
3
|
+
export declare class Monkey extends BeanSimple implements IMonkeyBeanInit {
|
|
4
|
+
beanInit(bean: BeanContainer, beanInstance: BeanBase): Promise<void>;
|
|
5
|
+
}
|
|
6
|
+
//# sourceMappingURL=monkey.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"monkey.d.ts","sourceRoot":"","sources":["../src/monkey.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,MAAM,CAAC;AAGrE,OAAO,EAAE,UAAU,EAAQ,MAAM,MAAM,CAAC;AAMxC,qBAAa,MAAO,SAAQ,UAAW,YAAW,eAAe;IACzD,QAAQ,CAAC,IAAI,EAAE,aAAa,EAAE,YAAY,EAAE,QAAQ;CAyB3D"}
|
|
@@ -0,0 +1,42 @@
|
|
|
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
|
+
import { TableIdentity } from 'table-identity';
|
|
5
|
+
export declare const SymbolCommandResult: unique symbol;
|
|
6
|
+
export type TypeCommandOptions<K extends keyof ICommandRecord> = {
|
|
7
|
+
name: K;
|
|
8
|
+
options?: Omit<ICommandRecord[K], typeof SymbolCommandResult>;
|
|
9
|
+
res?: string;
|
|
10
|
+
};
|
|
11
|
+
export type NextCommandExecute = (res?: any) => any | Promise<any>;
|
|
12
|
+
export interface ICommandRecord {
|
|
13
|
+
}
|
|
14
|
+
export interface ICommandExecute {
|
|
15
|
+
execute(options: IDecoratorCommandOptions, renderContext: IJsxRenderContextBase, next: NextCommandExecute): any | Promise<any>;
|
|
16
|
+
}
|
|
17
|
+
export interface IDecoratorCommandOptions<Result = any> {
|
|
18
|
+
[SymbolCommandResult]: Result;
|
|
19
|
+
}
|
|
20
|
+
export interface ICommandOptionsBase<Result = any> extends IDecoratorCommandOptions<Result> {
|
|
21
|
+
}
|
|
22
|
+
export interface ICommandBulkOptionsBase<Result = any> extends ICommandOptionsBase<Result> {
|
|
23
|
+
resource?: string;
|
|
24
|
+
}
|
|
25
|
+
export interface ICommandRowOptionsBase<Result = any> extends ICommandOptionsBase<Result> {
|
|
26
|
+
resource?: string;
|
|
27
|
+
id?: TableIdentity;
|
|
28
|
+
}
|
|
29
|
+
declare module 'zova-module-a-bean' {
|
|
30
|
+
interface SysOnion {
|
|
31
|
+
command: ServiceOnion<IDecoratorCommandOptions, keyof ICommandRecord>;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
declare module 'zova' {
|
|
35
|
+
interface ConfigOnions {
|
|
36
|
+
command: OmitNever<ICommandRecord>;
|
|
37
|
+
}
|
|
38
|
+
interface IBeanSceneRecord {
|
|
39
|
+
command: never;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
//# sourceMappingURL=command.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"command.d.ts","sourceRoot":"","sources":["../../src/types/command.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,MAAM,CAAC;AACtC,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AACvD,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,uBAAuB,CAAC;AAEnE,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAE/C,eAAO,MAAM,mBAAmB,eAAgC,CAAC;AAEjE,MAAM,MAAM,kBAAkB,CAAC,CAAC,SAAS,MAAM,cAAc,IAAI;IAC/D,IAAI,EAAE,CAAC,CAAC;IACR,OAAO,CAAC,EAAE,IAAI,CAAC,cAAc,CAAC,CAAC,CA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+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,qBAAqB,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { IJsxRenderContextBase } from 'zova-module-a-openapi';
|
|
2
|
+
import type { ICommandRecord, SymbolCommandResult } from './command.js';
|
|
3
|
+
import 'zova';
|
|
4
|
+
declare module 'zova' {
|
|
5
|
+
interface BeanBase {
|
|
6
|
+
$performCommand: <T extends keyof ICommandRecord>(commandName: T, options: Partial<ICommandRecord[T]> | undefined, renderContext?: IJsxRenderContextBase, next?: Function) => ICommandRecord[T][typeof SymbolCommandResult];
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
//# sourceMappingURL=performCommand.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"performCommand.d.ts","sourceRoot":"","sources":["../../src/types/performCommand.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,uBAAuB,CAAC;AAEnE,OAAO,KAAK,EAAE,cAAc,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC;AACxE,OAAO,MAAM,CAAC;AAEd,OAAO,QAAQ,MAAM,CAAC;IACpB,UAAiB,QAAQ;QACvB,eAAe,EAAE,CAAC,CAAC,SAAS,MAAM,cAAc,EAC9C,WAAW,EAAE,CAAC,EACd,OAAO,EAAE,OAAO,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,GAAG,SAAS,EAC/C,aAAa,CAAC,EAAE,qBAAqB,EACrC,IAAI,CAAC,EAAE,QAAQ,KACZ,cAAc,CAAC,CAAC,CAAC,CAAC,OAAO,mBAAmB,CAAC,CAAC;KACpD;CACF"}
|
package/package.json
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "zova-module-a-command",
|
|
3
|
+
"version": "5.1.17",
|
|
4
|
+
"gitHead": "87d2202a9a86869e6933c17fc78d6f0728400296",
|
|
5
|
+
"description": "",
|
|
6
|
+
"keywords": [
|
|
7
|
+
"Zova Module"
|
|
8
|
+
],
|
|
9
|
+
"author": "",
|
|
10
|
+
"files": [
|
|
11
|
+
"cli",
|
|
12
|
+
"dist",
|
|
13
|
+
"mock",
|
|
14
|
+
"src",
|
|
15
|
+
"icons",
|
|
16
|
+
"assets"
|
|
17
|
+
],
|
|
18
|
+
"type": "module",
|
|
19
|
+
"exports": {
|
|
20
|
+
".": {
|
|
21
|
+
"types": "./dist/index.d.ts",
|
|
22
|
+
"default": "./dist/index.js"
|
|
23
|
+
},
|
|
24
|
+
"./*": "./*"
|
|
25
|
+
},
|
|
26
|
+
"scripts": {
|
|
27
|
+
"clean": "rimraf dist tsconfig.build.tsbuildinfo",
|
|
28
|
+
"tsc:publish": "npm run clean && zova :bin:buildModule --sourcemap && tsc -p tsconfig.build.json",
|
|
29
|
+
"prepublishOnly": "npm run tsc:publish",
|
|
30
|
+
"prepack": "clean-package",
|
|
31
|
+
"postpack": "clean-package restore && npm run clean"
|
|
32
|
+
},
|
|
33
|
+
"title": "a-command",
|
|
34
|
+
"zovaModule": {
|
|
35
|
+
"onions": {
|
|
36
|
+
"command": {
|
|
37
|
+
"beanGeneral": true,
|
|
38
|
+
"optionsGlobalInterfaceName": "IDecoratorCommandOptions",
|
|
39
|
+
"optionsGlobalInterfaceFrom": "zova-module-a-command",
|
|
40
|
+
"boilerplate": "command/boilerplate"
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
"capabilities": {
|
|
44
|
+
"monkey": true
|
|
45
|
+
},
|
|
46
|
+
"dependencies": {}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
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 ScopeModuleACommand extends BeanScopeBase {}
|
|
11
|
+
|
|
12
|
+
export interface ScopeModuleACommand {
|
|
13
|
+
util: BeanScopeUtil;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
import 'zova';
|
|
17
|
+
declare module 'zova' {
|
|
18
|
+
export interface IBeanScopeRecord {
|
|
19
|
+
'a-command': ScopeModuleACommand;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/** scope: end */
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { PowerPartial } from 'zova';
|
|
2
|
+
|
|
3
|
+
import { createBeanDecorator } from 'zova';
|
|
4
|
+
|
|
5
|
+
import type { IDecoratorCommandOptions } from '../types/command.js';
|
|
6
|
+
|
|
7
|
+
export function Command<T extends IDecoratorCommandOptions>(
|
|
8
|
+
options?: PowerPartial<T>,
|
|
9
|
+
): ClassDecorator {
|
|
10
|
+
return createBeanDecorator('command', 'sys', true, options);
|
|
11
|
+
}
|
package/src/lib/index.ts
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
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 { ICommandRecord, SymbolCommandResult } from '../types/command.js';
|
|
7
|
+
|
|
8
|
+
export function $performCommand<T extends keyof ICommandRecord>(
|
|
9
|
+
sys: ZovaSys,
|
|
10
|
+
commandName: T,
|
|
11
|
+
options: Partial<ICommandRecord[T]> | undefined,
|
|
12
|
+
renderContext: IJsxRenderContextBase,
|
|
13
|
+
next?: Function,
|
|
14
|
+
): ICommandRecord[T][typeof SymbolCommandResult] {
|
|
15
|
+
if (!next) {
|
|
16
|
+
next = commandRes => {
|
|
17
|
+
return commandRes;
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
// command
|
|
21
|
+
const beanFullName = beanFullNameFromOnionName(commandName, 'command');
|
|
22
|
+
const beanInstance = sys.bean._getBeanSyncOnly(beanFullName);
|
|
23
|
+
if (beanInstance) {
|
|
24
|
+
// sync
|
|
25
|
+
return _renderEventCommandNormal_inner(beanInstance, options, renderContext, next);
|
|
26
|
+
}
|
|
27
|
+
// async
|
|
28
|
+
return sys.bean._getBean(beanFullName, false).then(beanInstance => {
|
|
29
|
+
return _renderEventCommandNormal_inner(beanInstance, options, renderContext, next);
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function _renderEventCommandNormal_inner(
|
|
34
|
+
beanInstance: any,
|
|
35
|
+
options: {} | undefined,
|
|
36
|
+
renderContext: IJsxRenderContextBase,
|
|
37
|
+
next?: Function,
|
|
38
|
+
) {
|
|
39
|
+
const onionOptions = beanInstance.$onionOptions;
|
|
40
|
+
// props
|
|
41
|
+
const props = onionOptions ? deepExtend({}, onionOptions, options) : (options ?? {});
|
|
42
|
+
return beanInstance.execute(props, renderContext, next);
|
|
43
|
+
}
|
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 { ICommandRecord } from './types/command.js';
|
|
7
|
+
|
|
8
|
+
import { $performCommand } from './lib/performCommand.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, '$performCommand', {
|
|
14
|
+
enumerable: false,
|
|
15
|
+
configurable: true,
|
|
16
|
+
get() {
|
|
17
|
+
return function <T extends keyof ICommandRecord>(
|
|
18
|
+
commandName: T,
|
|
19
|
+
options: Partial<ICommandRecord[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 $performCommand(self.sys, commandName, options, renderContext, next);
|
|
32
|
+
};
|
|
33
|
+
},
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
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
|
+
import { TableIdentity } from 'table-identity';
|
|
6
|
+
|
|
7
|
+
export const SymbolCommandResult = Symbol('SymbolCommandResult');
|
|
8
|
+
|
|
9
|
+
export type TypeCommandOptions<K extends keyof ICommandRecord> = {
|
|
10
|
+
name: K;
|
|
11
|
+
options?: Omit<ICommandRecord[K], typeof SymbolCommandResult>;
|
|
12
|
+
res?: string;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export type NextCommandExecute = (res?: any) => any | Promise<any>;
|
|
16
|
+
|
|
17
|
+
export interface ICommandRecord {}
|
|
18
|
+
|
|
19
|
+
export interface ICommandExecute {
|
|
20
|
+
execute(options: IDecoratorCommandOptions, renderContext: IJsxRenderContextBase, next: NextCommandExecute): any | Promise<any>;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export interface IDecoratorCommandOptions<Result = any> {
|
|
24
|
+
[SymbolCommandResult]: Result;
|
|
25
|
+
// res?: string; // need not define here
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export interface ICommandOptionsBase<Result = any> extends IDecoratorCommandOptions<Result> {}
|
|
29
|
+
|
|
30
|
+
export interface ICommandBulkOptionsBase<Result = any> extends ICommandOptionsBase<Result> {
|
|
31
|
+
resource?: string;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export interface ICommandRowOptionsBase<Result = any> extends ICommandOptionsBase<Result> {
|
|
35
|
+
resource?: string;
|
|
36
|
+
id?: TableIdentity;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
declare module 'zova-module-a-bean' {
|
|
40
|
+
export interface SysOnion {
|
|
41
|
+
command: ServiceOnion<IDecoratorCommandOptions, keyof ICommandRecord>;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
declare module 'zova' {
|
|
46
|
+
export interface ConfigOnions {
|
|
47
|
+
command: OmitNever<ICommandRecord>;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export interface IBeanSceneRecord {
|
|
51
|
+
command: never;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { IJsxRenderContextBase } from 'zova-module-a-openapi';
|
|
2
|
+
|
|
3
|
+
import type { ICommandRecord, SymbolCommandResult } from './command.js';
|
|
4
|
+
import 'zova';
|
|
5
|
+
|
|
6
|
+
declare module 'zova' {
|
|
7
|
+
export interface BeanBase {
|
|
8
|
+
$performCommand: <T extends keyof ICommandRecord>(
|
|
9
|
+
commandName: T,
|
|
10
|
+
options: Partial<ICommandRecord[T]> | undefined,
|
|
11
|
+
renderContext?: IJsxRenderContextBase,
|
|
12
|
+
next?: Function,
|
|
13
|
+
) => ICommandRecord[T][typeof SymbolCommandResult];
|
|
14
|
+
}
|
|
15
|
+
}
|