@ibiz-template/runtime 0.7.41-alpha.137 → 0.7.41-alpha.139

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 (47) hide show
  1. package/dist/index.esm.js +328 -275
  2. package/dist/index.system.min.js +1 -1
  3. package/out/app-hub.d.ts.map +1 -1
  4. package/out/app-hub.js +47 -21
  5. package/out/config/global-config.d.ts.map +1 -1
  6. package/out/config/global-config.js +1 -0
  7. package/out/de-logic/de-logic-context.d.ts +14 -4
  8. package/out/de-logic/de-logic-context.d.ts.map +1 -1
  9. package/out/de-logic/de-logic-context.js +4 -3
  10. package/out/de-logic/de-logic.d.ts.map +1 -1
  11. package/out/de-logic/de-logic.js +4 -7
  12. package/out/de-logic/index.js +1 -1
  13. package/out/interface/api/common/global-config/i-api-global-common-config.d.ts +6 -0
  14. package/out/interface/api/common/global-config/i-api-global-common-config.d.ts.map +1 -1
  15. package/out/interface/api/common/i-api-de-logic-params.d.ts +7 -0
  16. package/out/interface/api/common/i-api-de-logic-params.d.ts.map +1 -1
  17. package/out/interface/api/common/i-api-logic-params.d.ts +1 -7
  18. package/out/interface/api/common/i-api-logic-params.d.ts.map +1 -1
  19. package/out/interface/api/common/i-api-ui-logic-params.d.ts +7 -0
  20. package/out/interface/api/common/i-api-ui-logic-params.d.ts.map +1 -1
  21. package/out/interface/api/util/i-api-app-util.d.ts +6 -0
  22. package/out/interface/api/util/i-api-app-util.d.ts.map +1 -1
  23. package/out/interface/de-logic/i-de-logic-context.d.ts +10 -0
  24. package/out/interface/de-logic/i-de-logic-context.d.ts.map +1 -1
  25. package/out/interface/util/i-app-util/i-app-util.d.ts +7 -0
  26. package/out/interface/util/i-app-util/i-app-util.d.ts.map +1 -1
  27. package/out/utils/index.d.ts +1 -0
  28. package/out/utils/index.d.ts.map +1 -1
  29. package/out/utils/index.js +1 -0
  30. package/out/utils/task-util/task-util.d.ts +8 -0
  31. package/out/utils/task-util/task-util.d.ts.map +1 -0
  32. package/out/utils/task-util/task-util.js +38 -0
  33. package/package.json +3 -3
  34. package/src/app-hub.ts +51 -22
  35. package/src/config/global-config.ts +1 -0
  36. package/src/de-logic/de-logic-context.ts +17 -4
  37. package/src/de-logic/de-logic.ts +4 -7
  38. package/src/de-logic/index.ts +1 -1
  39. package/src/interface/api/common/global-config/i-api-global-common-config.ts +7 -0
  40. package/src/interface/api/common/i-api-de-logic-params.ts +9 -1
  41. package/src/interface/api/common/i-api-logic-params.ts +1 -8
  42. package/src/interface/api/common/i-api-ui-logic-params.ts +8 -0
  43. package/src/interface/api/util/i-api-app-util.ts +7 -0
  44. package/src/interface/de-logic/i-de-logic-context.ts +8 -1
  45. package/src/interface/util/i-app-util/i-app-util.ts +9 -1
  46. package/src/utils/index.ts +1 -0
  47. package/src/utils/task-util/task-util.ts +45 -0
package/src/app-hub.ts CHANGED
@@ -24,6 +24,7 @@ import { HubController } from './controller';
24
24
  import { ConfigService, MqttService } from './service';
25
25
  import { NoticeController } from './controller/notification';
26
26
  import { MicroAppConfigCenter } from './micro-app';
27
+ import { runWithConcurrency } from './utils';
27
28
 
28
29
  /**
29
30
  * 运行时总集
@@ -856,30 +857,54 @@ export class AppHub implements IAppHubService {
856
857
  * @memberof AppHub
857
858
  */
858
859
  public async loadMainExtensionPlugin(): Promise<void> {
859
- // 从 1 开始递增加载扩展插件,加载失败时终止
860
- // 第一组为 ExtensionPlugin/ext,之后为 ExtensionPlugin1/ext2、ExtensionPlugin2/ext3 ...
861
- let index = 1;
862
- let success = true;
863
- do {
860
+ const { enableExternalPlugin, concurrentPluginCount } =
861
+ ibiz.appUtil.getRuntimeDevToolConfig();
862
+ if (!enableExternalPlugin) {
863
+ return;
864
+ }
865
+ // 获取扩展插件总数
866
+ let pluginListLength: number = 0;
867
+ const res = await ibiz.net.axios({
868
+ method: 'get',
869
+ url: `${ibiz.env.baseUrl}/${ibiz.env.appId}${ibiz.env.remoteModelUrl}/extension`,
870
+ });
871
+ if (res.status === 200 && res.data) {
872
+ pluginListLength = Number(res.data);
873
+ }
874
+ if (pluginListLength === 0) return;
875
+ // 构建任务列表
876
+ const pluginTasks = Array.from({ length: pluginListLength }, (_, i) => {
877
+ const index = i + 1;
864
878
  const suffix = index === 1 ? '' : `${index}`;
865
879
  const targetUrl = `${ibiz.env.baseUrl}/${ibiz.env.appId}${ibiz.env.remoteModelUrl}/ext${suffix}`;
866
- try {
867
- await ibiz.plugin.loadPlugin({
868
- runtimeObject: true,
869
- rtobjectName: `ExtensionPlugin${suffix}`,
870
- rtobjectRepo: targetUrl,
871
- } as IAppPFPluginRef);
872
- index += 1;
873
- success = true;
874
- } catch (error) {
875
- ibiz.log.warn(
876
- ibiz.i18n.t('runtime.hub.noExtensionPlugin', {
877
- targetUrl,
878
- }),
879
- );
880
- success = false;
881
- }
882
- } while (success);
880
+ return async (): Promise<{ ok: boolean; data: IData }> => {
881
+ try {
882
+ await ibiz.plugin.loadPlugin({
883
+ runtimeObject: true,
884
+ rtobjectName: `ExtensionPlugin${suffix}`,
885
+ rtobjectRepo: targetUrl,
886
+ } as IAppPFPluginRef);
887
+
888
+ return { ok: true, data: { index, targetUrl } };
889
+ } catch (error) {
890
+ return { ok: false, data: { index, targetUrl, error } };
891
+ }
892
+ };
893
+ });
894
+ // 并发执行任务
895
+ const results = await runWithConcurrency(
896
+ pluginTasks,
897
+ concurrentPluginCount || 1,
898
+ );
899
+ // 处理结果
900
+ const errorResults = results.filter(result => !result?.ok);
901
+ if (errorResults && errorResults.length > 0) {
902
+ ibiz.log.warn(
903
+ ibiz.i18n.t('runtime.hub.noExtensionPlugin', {
904
+ targetUrl: errorResults[0].data?.targetUrl || 'Unknown',
905
+ }),
906
+ );
907
+ }
883
908
  }
884
909
 
885
910
  /**
@@ -889,6 +914,10 @@ export class AppHub implements IAppHubService {
889
914
  * @memberof AppHub
890
915
  */
891
916
  public async loadSubExtensionPlugin(appId: string): Promise<void> {
917
+ const { enableExternalPlugin } = ibiz.appUtil.getRuntimeDevToolConfig();
918
+ if (!enableExternalPlugin) {
919
+ return;
920
+ }
892
921
  const targetUrl = `${ibiz.env.baseUrl}/${ibiz.env.appId}${ibiz.env.remoteModelUrl}/subapps/${appId}/ext`;
893
922
  try {
894
923
  await ibiz.plugin.loadPlugin({
@@ -141,6 +141,7 @@ export class GlobalConfig implements IGlobalConfig {
141
141
  aiAutoQuestion: true,
142
142
  asyncImport: false,
143
143
  aiTopicStorageMode: 'DEFAULT',
144
+ aiInputPlaceholder: '',
144
145
  };
145
146
 
146
147
  // 全局分页流布局配置
@@ -1,5 +1,6 @@
1
+ import { isArray } from 'lodash-es';
1
2
  import { DELogicParam } from './de-logic-param/de-logic-param';
2
- import { IDeLogicContext, IDeLogicParams } from '../interface';
3
+ import { IDeLogicContext } from '../interface';
3
4
 
4
5
  /**
5
6
  * 实体逻辑执行上下文
@@ -18,6 +19,14 @@ export class DELogicContext implements IDeLogicContext {
18
19
  */
19
20
  lastReturn: unknown;
20
21
 
22
+ /**
23
+ * 实体逻辑执行参数
24
+ * @author lxm
25
+ * @date 2023-10-16 02:22:31
26
+ * @type {{ context: IContext; data: IData[]; params: IParams }}
27
+ */
28
+ parameters: { context: IContext; data: IData[]; params: IParams };
29
+
21
30
  /**
22
31
  * 上下文
23
32
  */
@@ -51,13 +60,17 @@ export class DELogicContext implements IDeLogicContext {
51
60
  * @date 2023-03-24 09:15:14
52
61
  * @param {Map<string, DELogicParam>} deLogicParams 实体逻辑参数集合
53
62
  * @param {IContext} context 上下文
54
- * @param {IData} data 数据对象
63
+ * @param {IData | IData[]} data 数据对象
55
64
  * @param {IParams} params 视图参数
56
65
  */
57
66
  constructor(
58
67
  private deLogicParams: Map<string, DELogicParam>,
59
- public parameters: IDeLogicParams,
60
- ) {}
68
+ context: IContext,
69
+ data: IData | IData[],
70
+ params: IParams,
71
+ ) {
72
+ this.parameters = { context, data: isArray(data) ? data : [data], params };
73
+ }
61
74
 
62
75
  /**
63
76
  * 重置实体逻辑参数
@@ -1,6 +1,5 @@
1
1
  /* eslint-disable no-await-in-loop */
2
- import { IBizContext, RuntimeModelError } from '@ibiz-template/core';
3
- import { clone } from 'ramda';
2
+ import { RuntimeModelError } from '@ibiz-template/core';
4
3
  import { IAppDELogic, IAppDataEntity } from '@ibiz/model-core';
5
4
  import { ScriptFactory, ScriptFunction } from '../utils';
6
5
  import { DELogicContext } from './de-logic-context';
@@ -124,13 +123,11 @@ export class DELogic implements IDeLogic {
124
123
  * @memberof DELogic
125
124
  */
126
125
  async exec(parameters: IDeLogicParams): Promise<unknown> {
127
- // 克隆传入应用上下文参数和视图参数
128
- parameters.context = IBizContext.create(parameters.context);
129
- parameters.params = clone(parameters.params || {});
126
+ const { context, params, data } = parameters;
130
127
  if (this.scriptFn) {
131
- return this.scriptFn.exec({ ...parameters });
128
+ return this.scriptFn.exec({ context, data, params });
132
129
  }
133
- const ctx = new DELogicContext(this.params, parameters);
130
+ const ctx = new DELogicContext(this.params, context, data, params);
134
131
  this.initLogicParams(ctx);
135
132
  const { startDELogicNodeId } = this.model;
136
133
  if (startDELogicNodeId && this.nodes.has(startDELogicNodeId)) {
@@ -45,7 +45,7 @@ export async function execDELogic(
45
45
  const deLogic = deLogicMap.get(deDELogic)!;
46
46
  const result = await deLogic.exec({
47
47
  context,
48
- data: Array.isArray(data) ? data : [data],
48
+ data,
49
49
  params,
50
50
  });
51
51
  ibiz.log.debug(
@@ -316,4 +316,11 @@ export interface IApiGlobalCommonConfig {
316
316
  * @memberof IApiGlobalCommonConfig
317
317
  */
318
318
  aiTopicStorageMode: 'DEFAULT' | 'REMOTESESSION';
319
+
320
+ /**
321
+ * @description AI输入框空白占位
322
+ * @type {''}
323
+ * @memberof IApiGlobalCommonConfig
324
+ */
325
+ aiInputPlaceholder: '';
319
326
  }
@@ -1,3 +1,4 @@
1
+ import { IApiData } from '@ibiz-template/core';
1
2
  import { IApiLogicParams } from './i-api-logic-params';
2
3
 
3
4
  /**
@@ -5,4 +6,11 @@ import { IApiLogicParams } from './i-api-logic-params';
5
6
  * @export
6
7
  * @interface IApiDELogicParams
7
8
  */
8
- export interface IApiDeLogicParams extends IApiLogicParams {}
9
+ export interface IApiDeLogicParams extends IApiLogicParams {
10
+ /**
11
+ * @description 数据集合
12
+ * @type {(IApiData | IApiData[])}
13
+ * @memberof IApiDeLogicParams
14
+ */
15
+ data: IApiData | IApiData[];
16
+ }
@@ -1,4 +1,4 @@
1
- import { IApiContext, IApiData, IApiParams } from '@ibiz-template/core';
1
+ import { IApiContext, IApiParams } from '@ibiz-template/core';
2
2
 
3
3
  /**
4
4
  * @description 逻辑通用参数接口
@@ -19,11 +19,4 @@ export interface IApiLogicParams {
19
19
  * @memberof IApiLogicParams
20
20
  */
21
21
  params: IApiParams;
22
-
23
- /**
24
- * @description 数据集合
25
- * @type {IApiData[]}
26
- * @memberof IApiLogicParams
27
- */
28
- data: IApiData[];
29
22
  }
@@ -1,3 +1,4 @@
1
+ import { IApiData } from '@ibiz-template/core';
1
2
  import { IApiControlController, IApiViewController } from '../controller';
2
3
  import { IApiLogicParams } from './i-api-logic-params';
3
4
 
@@ -34,4 +35,11 @@ export interface IApiUILogicParams extends IApiLogicParams {
34
35
  * @memberof IApiUILogicParams
35
36
  */
36
37
  noWaitRoute?: boolean;
38
+
39
+ /**
40
+ * @description 数据集合
41
+ * @type {IApiData[]}
42
+ * @memberof IApiLogicParams
43
+ */
44
+ data: IApiData[];
37
45
  }
@@ -277,4 +277,11 @@ export interface IApiAppUtil {
277
277
  * @memberof IApiAppUtil
278
278
  */
279
279
  resolveI18nText(text: string): string;
280
+
281
+ /**
282
+ * @description 获取运行时开发工具配置
283
+ * @returns {*} {IApiData}
284
+ * @memberof IApiAppUtil
285
+ */
286
+ getRuntimeDevToolConfig(): IApiData;
280
287
  }
@@ -6,4 +6,11 @@ import { ILogicContext } from '../common';
6
6
  * @interface IDeLogicContext
7
7
  * @extends {ILogicContext}
8
8
  */
9
- export interface IDeLogicContext extends ILogicContext {}
9
+ export interface IDeLogicContext extends ILogicContext {
10
+ /**
11
+ * @description 实体逻辑执行参数
12
+ * @type {{ context: IContext; data: IData[]; params: IParams }}
13
+ * @memberof IDeLogicContext
14
+ */
15
+ parameters: { context: IContext; data: IData[]; params: IParams };
16
+ }
@@ -1,3 +1,4 @@
1
+ import { IDevToolConfig } from '@ibiz-template/core';
1
2
  import { IApiAiChatParam, IApiAppUtil } from '../../api';
2
3
 
3
4
  /**
@@ -14,4 +15,11 @@ export interface IAiChatParam extends IApiAiChatParam {}
14
15
  * @interface IAppUtil
15
16
  * @extends {IApiAppUtil}
16
17
  */
17
- export interface IAppUtil extends IApiAppUtil {}
18
+ export interface IAppUtil extends IApiAppUtil {
19
+ /**
20
+ * @description 获取运行时开发工具配置
21
+ * @returns {*} {IDevToolConfig}
22
+ * @memberof IAppUtil
23
+ */
24
+ getRuntimeDevToolConfig(): IDevToolConfig;
25
+ }
@@ -37,6 +37,7 @@ export * from './date-util';
37
37
  export { ChangeTracker } from './change-tracker/change-tracker';
38
38
  export { ViewShellHooks } from './view-shell-hooks/view-shell-hooks';
39
39
  export { WaterMarkUtil } from './water-mark-util/water-mark-util';
40
+ export { runWithConcurrency } from './task-util/task-util';
40
41
  export * from './map-util/map-util';
41
42
  export * from './wechat-util/wechat-util';
42
43
  export * from './json-util/json-util';
@@ -0,0 +1,45 @@
1
+ /* eslint-disable no-plusplus */
2
+ /**
3
+ * 并发控制函数
4
+ * @param tasks 需要执行的任务数组
5
+ * @param concurrency 最大并发数量
6
+ * @returns 所有任务执行结果的数组(保持与输入顺序一致)
7
+ */
8
+ export async function runWithConcurrency<T>(
9
+ tasks: (() => Promise<T>)[],
10
+ concurrency: number,
11
+ ): Promise<T[]> {
12
+ const results: T[] = new Array(tasks.length);
13
+ // 使用 Map 记录正在执行的任务,防止重复领取
14
+ const executing = new Map<number, Promise<void>>();
15
+ let currentIndex = 0;
16
+
17
+ const runTask = async (index: number): Promise<void> => {
18
+ try {
19
+ const data = await tasks[index]();
20
+ results[index] = data;
21
+ } finally {
22
+ // 任务完成后,从执行池中移除
23
+ executing.delete(index);
24
+ }
25
+ };
26
+
27
+ // 只要还有待处理的任务,就持续调度
28
+ while (currentIndex < tasks.length) {
29
+ // 如果当前并发数已满,等待最先完成的一个任务
30
+ if (executing.size >= concurrency) {
31
+ await Promise.race(executing.values());
32
+ continue;
33
+ }
34
+
35
+ // 领取任务并加入执行池
36
+ const index = currentIndex++;
37
+ const taskPromise = runTask(index);
38
+ executing.set(index, taskPromise);
39
+ }
40
+
41
+ // 等待所有剩余的执行中任务完成
42
+ await Promise.all(executing.values());
43
+
44
+ return results;
45
+ }