@nocobase/flow-engine 2.1.0-alpha.1 → 2.1.0-alpha.11
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 +201 -661
- package/README.md +79 -10
- package/lib/BlockScopedFlowEngine.js +0 -1
- package/lib/FlowDefinition.d.ts +6 -0
- package/lib/FlowSchemaRegistry.d.ts +154 -0
- package/lib/FlowSchemaRegistry.js +1427 -0
- package/lib/JSRunner.d.ts +15 -0
- package/lib/JSRunner.js +82 -7
- package/lib/ViewScopedFlowEngine.js +8 -1
- package/lib/acl/Acl.js +13 -3
- package/lib/components/FlowContextSelector.js +155 -10
- package/lib/components/MobilePopup.js +6 -5
- package/lib/components/dnd/gridDragPlanner.d.ts +1 -0
- package/lib/components/dnd/gridDragPlanner.js +59 -3
- package/lib/components/settings/wrappers/component/SwitchWithTitle.js +2 -1
- package/lib/components/settings/wrappers/contextual/DefaultSettingsIcon.js +76 -15
- package/lib/components/settings/wrappers/contextual/FlowsContextMenu.js +24 -4
- package/lib/components/settings/wrappers/contextual/StepSettingsDialog.js +21 -3
- package/lib/components/subModel/AddSubModelButton.js +27 -1
- package/lib/components/subModel/utils.js +2 -2
- package/lib/components/variables/VariableInput.js +9 -4
- package/lib/components/variables/VariableTag.js +46 -39
- package/lib/components/variables/utils.d.ts +7 -0
- package/lib/components/variables/utils.js +42 -2
- package/lib/data-source/index.d.ts +7 -27
- package/lib/data-source/index.js +84 -51
- package/lib/executor/FlowExecutor.d.ts +2 -1
- package/lib/executor/FlowExecutor.js +190 -26
- package/lib/flow-schema-registry/fieldBinding.d.ts +32 -0
- package/lib/flow-schema-registry/fieldBinding.js +165 -0
- package/lib/flow-schema-registry/modelPatches.d.ts +16 -0
- package/lib/flow-schema-registry/modelPatches.js +235 -0
- package/lib/flow-schema-registry/schemaInference.d.ts +17 -0
- package/lib/flow-schema-registry/schemaInference.js +207 -0
- package/lib/flow-schema-registry/utils.d.ts +25 -0
- package/lib/flow-schema-registry/utils.js +293 -0
- package/lib/flowContext.d.ts +230 -7
- package/lib/flowContext.js +2270 -148
- package/lib/flowEngine.d.ts +160 -1
- package/lib/flowEngine.js +387 -27
- package/lib/flowI18n.js +6 -4
- package/lib/flowSettings.d.ts +14 -6
- package/lib/flowSettings.js +51 -17
- package/lib/index.d.ts +8 -1
- package/lib/index.js +24 -1
- package/lib/lazy-helper.d.ts +14 -0
- package/lib/lazy-helper.js +71 -0
- package/lib/locale/en-US.json +9 -2
- package/lib/locale/index.d.ts +14 -0
- package/lib/locale/zh-CN.json +8 -1
- package/lib/models/CollectionFieldModel.d.ts +1 -0
- package/lib/models/CollectionFieldModel.js +3 -2
- package/lib/models/DisplayItemModel.d.ts +1 -1
- package/lib/models/EditableItemModel.d.ts +1 -1
- package/lib/models/FilterableItemModel.d.ts +1 -1
- package/lib/models/flowModel.d.ts +7 -0
- package/lib/models/flowModel.js +83 -8
- package/lib/provider.js +7 -6
- package/lib/resources/baseRecordResource.d.ts +5 -0
- package/lib/resources/baseRecordResource.js +24 -0
- package/lib/resources/multiRecordResource.d.ts +1 -0
- package/lib/resources/multiRecordResource.js +11 -4
- package/lib/resources/singleRecordResource.js +2 -0
- package/lib/resources/sqlResource.d.ts +4 -3
- package/lib/resources/sqlResource.js +8 -3
- package/lib/runjs-context/contexts/FormJSFieldItemRunJSContext.js +12 -2
- package/lib/runjs-context/contexts/JSBlockRunJSContext.js +2 -2
- package/lib/runjs-context/contexts/JSEditableFieldRunJSContext.d.ts +16 -0
- package/lib/runjs-context/contexts/JSEditableFieldRunJSContext.js +125 -0
- package/lib/runjs-context/contexts/JSItemRunJSContext.js +12 -2
- package/lib/runjs-context/contexts/base.js +706 -41
- package/lib/runjs-context/contributions.d.ts +33 -0
- package/lib/runjs-context/contributions.js +88 -0
- package/lib/runjs-context/helpers.js +12 -1
- package/lib/runjs-context/registry.d.ts +1 -1
- package/lib/runjs-context/setup.js +23 -9
- package/lib/runjs-context/snippets/global/api-request.snippet.js +3 -3
- package/lib/runjs-context/snippets/global/import-esm.snippet.js +2 -3
- package/lib/runjs-context/snippets/global/query-selector.snippet.js +8 -3
- package/lib/runjs-context/snippets/global/require-amd.snippet.js +1 -1
- package/lib/runjs-context/snippets/index.d.ts +11 -1
- package/lib/runjs-context/snippets/index.js +61 -40
- package/lib/runjs-context/snippets/scene/block/add-event-listener.snippet.js +10 -7
- package/lib/runjs-context/snippets/scene/block/api-fetch-render-list.snippet.js +3 -3
- package/lib/runjs-context/snippets/scene/block/chartjs-bar.snippet.js +2 -2
- package/lib/runjs-context/snippets/scene/block/echarts-init.snippet.js +2 -2
- package/lib/runjs-context/snippets/scene/block/render-iframe.snippet.js +2 -2
- package/lib/runjs-context/snippets/scene/block/render-react.snippet.js +1 -1
- package/lib/runjs-context/snippets/scene/block/render-statistics.snippet.js +1 -1
- package/lib/runjs-context/snippets/scene/block/render-timeline.snippet.js +1 -1
- package/lib/runjs-context/snippets/scene/block/resource-example.snippet.js +5 -5
- package/lib/runjs-context/snippets/scene/block/three-users-orbit.snippet.js +6 -6
- package/lib/runjs-context/snippets/scene/block/vue-component.snippet.js +3 -4
- package/lib/runjs-context/snippets/scene/detail/color-by-value.snippet.js +1 -1
- package/lib/runjs-context/snippets/scene/detail/copy-to-clipboard.snippet.js +20 -3
- package/lib/runjs-context/snippets/scene/detail/format-number.snippet.js +1 -1
- package/lib/runjs-context/snippets/scene/detail/innerHTML-value.snippet.js +1 -1
- package/lib/runjs-context/snippets/scene/detail/percentage-bar.snippet.js +3 -3
- package/lib/runjs-context/snippets/scene/detail/relative-time.snippet.js +3 -3
- package/lib/runjs-context/snippets/scene/detail/status-tag.snippet.js +2 -2
- package/lib/runjs-context/snippets/scene/form/cascade-select.snippet.js +1 -1
- package/lib/runjs-context/snippets/scene/form/render-basic.snippet.js +2 -2
- package/lib/runjs-context/snippets/scene/table/cell-open-dialog.snippet.js +6 -3
- package/lib/runjs-context/snippets/scene/table/concat-fields.snippet.js +3 -1
- package/lib/runjsLibs.d.ts +28 -0
- package/lib/runjsLibs.js +532 -0
- package/lib/scheduler/ModelOperationScheduler.d.ts +7 -1
- package/lib/scheduler/ModelOperationScheduler.js +28 -23
- package/lib/server.d.ts +10 -0
- package/lib/server.js +32 -0
- package/lib/types.d.ts +296 -1
- package/lib/utils/associationObjectVariable.d.ts +2 -2
- package/lib/utils/createCollectionContextMeta.js +1 -0
- package/lib/utils/createEphemeralContext.js +2 -2
- package/lib/utils/dateVariable.d.ts +16 -0
- package/lib/utils/dateVariable.js +380 -0
- package/lib/utils/exceptions.d.ts +7 -0
- package/lib/utils/exceptions.js +10 -0
- package/lib/utils/index.d.ts +8 -3
- package/lib/utils/index.js +49 -0
- package/lib/utils/params-resolvers.js +16 -9
- package/lib/utils/parsePathnameToViewParams.js +1 -1
- package/lib/utils/resolveModuleUrl.d.ts +58 -0
- package/lib/utils/resolveModuleUrl.js +65 -0
- package/lib/utils/resolveRunJSObjectValues.d.ts +16 -0
- package/lib/utils/resolveRunJSObjectValues.js +61 -0
- package/lib/utils/runjsModuleLoader.d.ts +58 -0
- package/lib/utils/runjsModuleLoader.js +422 -0
- package/lib/utils/runjsTemplateCompat.d.ts +35 -0
- package/lib/utils/runjsTemplateCompat.js +743 -0
- package/lib/utils/runjsValue.d.ts +29 -0
- package/lib/utils/runjsValue.js +275 -0
- package/lib/utils/safeGlobals.d.ts +18 -8
- package/lib/utils/safeGlobals.js +164 -17
- package/lib/utils/schema-utils.d.ts +17 -1
- package/lib/utils/schema-utils.js +80 -0
- package/lib/views/FlowView.d.ts +7 -1
- package/lib/views/createViewMeta.d.ts +0 -7
- package/lib/views/createViewMeta.js +19 -70
- package/lib/views/index.d.ts +1 -2
- package/lib/views/index.js +4 -3
- package/lib/views/runViewBeforeClose.d.ts +10 -0
- package/lib/views/runViewBeforeClose.js +45 -0
- package/lib/views/useDialog.d.ts +2 -1
- package/lib/views/useDialog.js +28 -6
- package/lib/views/useDrawer.d.ts +2 -1
- package/lib/views/useDrawer.js +27 -5
- package/lib/views/usePage.d.ts +6 -1
- package/lib/views/usePage.js +53 -9
- package/lib/views/usePopover.js +4 -1
- package/lib/views/viewEvents.d.ts +17 -0
- package/lib/views/viewEvents.js +90 -0
- package/package.json +5 -5
- package/server.d.ts +1 -0
- package/server.js +1 -0
- package/src/BlockScopedFlowEngine.ts +2 -5
- package/src/FlowSchemaRegistry.ts +1799 -0
- package/src/JSRunner.ts +111 -5
- package/src/ViewScopedFlowEngine.ts +8 -0
- package/src/__tests__/FlowSchemaRegistry.test.ts +1951 -0
- package/src/__tests__/JSRunner.test.ts +91 -1
- package/src/__tests__/createViewMeta.popup.test.ts +62 -1
- package/src/__tests__/flow-engine.test.ts +48 -0
- package/src/__tests__/flowContext.test.ts +693 -1
- package/src/__tests__/flowEngine.dataSourceDirty.test.ts +63 -0
- package/src/__tests__/flowEngine.modelLoaders.test.ts +249 -0
- package/src/__tests__/flowEngine.saveModel.test.ts +4 -0
- package/src/__tests__/flowModel.openView.navigation.test.ts +28 -0
- package/src/__tests__/flowRunJSContextDefine.test.ts +63 -0
- package/src/__tests__/flowRuntimeContext.test.ts +2 -1
- package/src/__tests__/flowSettings.open.test.tsx +123 -19
- package/src/__tests__/flowSettings.test.ts +94 -15
- package/src/__tests__/provider.test.tsx +0 -5
- package/src/__tests__/renderHiddenInConfig.test.tsx +6 -6
- package/src/__tests__/runjsContext.test.ts +26 -7
- package/src/__tests__/runjsContextImplementations.test.ts +34 -3
- package/src/__tests__/runjsContextRuntime.test.ts +5 -3
- package/src/__tests__/runjsContributions.test.ts +89 -0
- package/src/__tests__/runjsExternalLibs.test.ts +242 -0
- package/src/__tests__/runjsLibsLazyLoading.test.ts +44 -0
- package/src/__tests__/runjsLocales.test.ts +4 -1
- package/src/__tests__/runjsPreprocessDefault.test.ts +72 -0
- package/src/__tests__/runjsRuntimeFeatures.test.ts +166 -0
- package/src/__tests__/runjsSnippets.test.ts +40 -3
- package/src/__tests__/viewScopedFlowEngine.test.ts +3 -3
- package/src/acl/Acl.tsx +3 -3
- package/src/components/FlowContextSelector.tsx +208 -12
- package/src/components/MobilePopup.tsx +4 -2
- package/src/components/__tests__/flow-model-render-error-fallback.test.tsx +3 -3
- package/src/components/__tests__/gridDragPlanner.test.ts +229 -1
- package/src/components/dnd/gridDragPlanner.ts +68 -2
- package/src/components/settings/wrappers/component/SwitchWithTitle.tsx +2 -1
- package/src/components/settings/wrappers/component/__tests__/InlineControls.test.tsx +74 -0
- package/src/components/settings/wrappers/contextual/DefaultSettingsIcon.tsx +109 -16
- package/src/components/settings/wrappers/contextual/FlowsContextMenu.tsx +41 -7
- package/src/components/settings/wrappers/contextual/StepSettingsDialog.tsx +31 -4
- package/src/components/settings/wrappers/contextual/__tests__/DefaultSettingsIcon.test.tsx +157 -5
- package/src/components/subModel/AddSubModelButton.tsx +32 -2
- package/src/components/subModel/__tests__/AddSubModelButton.test.tsx +143 -32
- package/src/components/subModel/utils.ts +1 -1
- package/src/components/variables/VariableInput.tsx +12 -4
- package/src/components/variables/VariableTag.tsx +54 -45
- package/src/components/variables/__tests__/FlowContextSelector.test.tsx +260 -3
- package/src/components/variables/__tests__/VariableTag.test.tsx +50 -0
- package/src/components/variables/__tests__/utils.test.ts +81 -3
- package/src/components/variables/utils.ts +67 -6
- package/src/data-source/index.ts +88 -110
- package/src/executor/FlowExecutor.ts +230 -28
- package/src/executor/__tests__/flowExecutor.test.ts +123 -0
- package/src/flow-schema-registry/fieldBinding.ts +171 -0
- package/src/flow-schema-registry/modelPatches.ts +260 -0
- package/src/flow-schema-registry/schemaInference.ts +210 -0
- package/src/flow-schema-registry/utils.ts +268 -0
- package/src/flowContext.ts +2989 -212
- package/src/flowEngine.ts +434 -23
- package/src/flowI18n.ts +7 -5
- package/src/flowSettings.ts +58 -18
- package/src/index.ts +15 -1
- package/src/lazy-helper.tsx +57 -0
- package/src/locale/en-US.json +9 -2
- package/src/locale/zh-CN.json +8 -1
- package/src/models/CollectionFieldModel.tsx +3 -1
- package/src/models/DisplayItemModel.tsx +1 -1
- package/src/models/EditableItemModel.tsx +1 -1
- package/src/models/FilterableItemModel.tsx +1 -1
- package/src/models/__tests__/dispatchEvent.when.test.ts +768 -0
- package/src/models/__tests__/flowModel.clone.test.ts +416 -0
- package/src/models/__tests__/flowModel.test.ts +20 -4
- package/src/models/flowModel.tsx +112 -7
- package/src/provider.tsx +9 -7
- package/src/resources/__tests__/multiRecordResource.test.ts +44 -0
- package/src/resources/__tests__/sqlResource.test.ts +60 -0
- package/src/resources/baseRecordResource.ts +31 -0
- package/src/resources/multiRecordResource.ts +11 -4
- package/src/resources/singleRecordResource.ts +3 -0
- package/src/resources/sqlResource.ts +11 -6
- package/src/runjs-context/contexts/FormJSFieldItemRunJSContext.ts +10 -0
- package/src/runjs-context/contexts/JSBlockRunJSContext.ts +6 -2
- package/src/runjs-context/contexts/JSEditableFieldRunJSContext.ts +106 -0
- package/src/runjs-context/contexts/JSItemRunJSContext.ts +10 -0
- package/src/runjs-context/contexts/base.ts +715 -44
- package/src/runjs-context/contributions.ts +88 -0
- package/src/runjs-context/helpers.ts +11 -1
- package/src/runjs-context/registry.ts +1 -1
- package/src/runjs-context/setup.ts +25 -9
- package/src/runjs-context/snippets/global/api-request.snippet.ts +3 -3
- package/src/runjs-context/snippets/global/import-esm.snippet.ts +2 -3
- package/src/runjs-context/snippets/global/query-selector.snippet.ts +8 -3
- package/src/runjs-context/snippets/global/require-amd.snippet.ts +1 -1
- package/src/runjs-context/snippets/index.ts +75 -41
- package/src/runjs-context/snippets/scene/block/add-event-listener.snippet.ts +11 -13
- package/src/runjs-context/snippets/scene/block/api-fetch-render-list.snippet.ts +3 -3
- package/src/runjs-context/snippets/scene/block/chartjs-bar.snippet.ts +2 -2
- package/src/runjs-context/snippets/scene/block/echarts-init.snippet.ts +2 -2
- package/src/runjs-context/snippets/scene/block/render-iframe.snippet.ts +2 -2
- package/src/runjs-context/snippets/scene/block/render-react.snippet.ts +1 -1
- package/src/runjs-context/snippets/scene/block/render-statistics.snippet.ts +1 -1
- package/src/runjs-context/snippets/scene/block/render-timeline.snippet.ts +1 -1
- package/src/runjs-context/snippets/scene/block/resource-example.snippet.ts +6 -11
- package/src/runjs-context/snippets/scene/block/three-users-orbit.snippet.ts +6 -6
- package/src/runjs-context/snippets/scene/block/vue-component.snippet.ts +3 -4
- package/src/runjs-context/snippets/scene/detail/color-by-value.snippet.ts +1 -1
- package/src/runjs-context/snippets/scene/detail/copy-to-clipboard.snippet.ts +20 -3
- package/src/runjs-context/snippets/scene/detail/format-number.snippet.ts +1 -1
- package/src/runjs-context/snippets/scene/detail/innerHTML-value.snippet.ts +1 -1
- package/src/runjs-context/snippets/scene/detail/percentage-bar.snippet.ts +3 -3
- package/src/runjs-context/snippets/scene/detail/relative-time.snippet.ts +3 -3
- package/src/runjs-context/snippets/scene/detail/status-tag.snippet.ts +2 -2
- package/src/runjs-context/snippets/scene/form/cascade-select.snippet.ts +1 -1
- package/src/runjs-context/snippets/scene/form/render-basic.snippet.ts +3 -8
- package/src/runjs-context/snippets/scene/table/cell-open-dialog.snippet.ts +6 -3
- package/src/runjs-context/snippets/scene/table/concat-fields.snippet.ts +3 -1
- package/src/runjsLibs.ts +622 -0
- package/src/scheduler/ModelOperationScheduler.ts +41 -24
- package/src/server.ts +11 -0
- package/src/types.ts +359 -1
- package/src/utils/__tests__/dateVariable.test.ts +101 -0
- package/src/utils/__tests__/params-resolvers.test.ts +40 -0
- package/src/utils/__tests__/parsePathnameToViewParams.test.ts +7 -0
- package/src/utils/__tests__/runjsRequireAsyncAutoWhitelist.test.ts +38 -0
- package/src/utils/__tests__/runjsTemplateCompat.test.ts +159 -0
- package/src/utils/__tests__/runjsValue.test.ts +44 -0
- package/src/utils/__tests__/safeGlobals.test.ts +57 -2
- package/src/utils/__tests__/utils.test.ts +157 -0
- package/src/utils/associationObjectVariable.ts +2 -2
- package/src/utils/createCollectionContextMeta.ts +1 -0
- package/src/utils/createEphemeralContext.ts +5 -4
- package/src/utils/dateVariable.ts +397 -0
- package/src/utils/exceptions.ts +11 -0
- package/src/utils/index.ts +38 -3
- package/src/utils/params-resolvers.ts +23 -9
- package/src/utils/parsePathnameToViewParams.ts +2 -2
- package/src/utils/resolveModuleUrl.ts +91 -0
- package/src/utils/resolveRunJSObjectValues.ts +46 -0
- package/src/utils/runjsModuleLoader.ts +553 -0
- package/src/utils/runjsTemplateCompat.ts +828 -0
- package/src/utils/runjsValue.ts +287 -0
- package/src/utils/safeGlobals.ts +188 -17
- package/src/utils/schema-utils.ts +109 -1
- package/src/views/FlowView.tsx +11 -1
- package/src/views/__tests__/FlowView.usePage.test.tsx +54 -1
- package/src/views/__tests__/runViewBeforeClose.test.ts +30 -0
- package/src/views/__tests__/useDialog.closeDestroy.test.tsx +44 -16
- package/src/views/__tests__/viewEvents.resolveOpenerEngine.test.ts +28 -0
- package/src/views/createViewMeta.ts +22 -75
- package/src/views/index.tsx +1 -2
- package/src/views/runViewBeforeClose.ts +19 -0
- package/src/views/useDialog.tsx +34 -5
- package/src/views/useDrawer.tsx +33 -4
- package/src/views/usePage.tsx +63 -8
- package/src/views/usePopover.tsx +4 -1
- package/src/views/viewEvents.ts +55 -0
|
@@ -66,6 +66,11 @@ export interface CollectionOptions {
|
|
|
66
66
|
export declare class CollectionManager {
|
|
67
67
|
dataSource: DataSource;
|
|
68
68
|
collections: Map<string, Collection>;
|
|
69
|
+
allCollectionsInheritChain: string[];
|
|
70
|
+
protected childrenCollectionsName: {
|
|
71
|
+
supportView?: string[];
|
|
72
|
+
notSupportView?: string[];
|
|
73
|
+
};
|
|
69
74
|
constructor(dataSource: DataSource);
|
|
70
75
|
get flowEngine(): FlowEngine;
|
|
71
76
|
addCollection(collection: Collection | CollectionOptions): void;
|
|
@@ -83,33 +88,8 @@ export declare class CollectionManager {
|
|
|
83
88
|
clearCollections(): void;
|
|
84
89
|
getAssociation(associationName: string): CollectionField | undefined;
|
|
85
90
|
getChildrenCollections(name: any): any[];
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
cached?: Record<string, any>;
|
|
89
|
-
collectionNames?: string[];
|
|
90
|
-
/**
|
|
91
|
-
* 为 true 时允许查询所有关联字段
|
|
92
|
-
* 为 Array<string> 时仅允许查询指定的关联字段
|
|
93
|
-
*/
|
|
94
|
-
association?: boolean | string[];
|
|
95
|
-
/**
|
|
96
|
-
* Max depth of recursion
|
|
97
|
-
*/
|
|
98
|
-
maxDepth?: number;
|
|
99
|
-
allowAllTypes?: boolean;
|
|
100
|
-
/**
|
|
101
|
-
* 排除这些接口的字段
|
|
102
|
-
*/
|
|
103
|
-
exceptInterfaces?: string[];
|
|
104
|
-
/**
|
|
105
|
-
* field value 的前缀,用 . 连接,比如 a.b.c
|
|
106
|
-
*/
|
|
107
|
-
prefixFieldValue?: string;
|
|
108
|
-
/**
|
|
109
|
-
* 是否使用 prefixFieldValue 作为 field value
|
|
110
|
-
*/
|
|
111
|
-
usePrefix?: boolean;
|
|
112
|
-
}): any;
|
|
91
|
+
getChildrenCollectionsName(name: any, isSupportView?: boolean): string[];
|
|
92
|
+
getAllCollectionsInheritChain(name: any): string[];
|
|
113
93
|
}
|
|
114
94
|
export declare class Collection {
|
|
115
95
|
fields: Map<string, CollectionField>;
|
package/lib/data-source/index.js
CHANGED
|
@@ -118,7 +118,7 @@ const _DataSource = class _DataSource {
|
|
|
118
118
|
return this.dataSourceManager.flowEngine;
|
|
119
119
|
}
|
|
120
120
|
get displayName() {
|
|
121
|
-
return this.
|
|
121
|
+
return this.flowEngine.translate(this.options.displayName, { ns: "lm-collections" }) || this.key;
|
|
122
122
|
}
|
|
123
123
|
get key() {
|
|
124
124
|
return this.options.key;
|
|
@@ -188,6 +188,8 @@ const _CollectionManager = class _CollectionManager {
|
|
|
188
188
|
this.collections = import_reactive.observable.shallow(/* @__PURE__ */ new Map());
|
|
189
189
|
}
|
|
190
190
|
collections;
|
|
191
|
+
allCollectionsInheritChain;
|
|
192
|
+
childrenCollectionsName = {};
|
|
191
193
|
get flowEngine() {
|
|
192
194
|
return this.dataSource.flowEngine;
|
|
193
195
|
}
|
|
@@ -317,56 +319,75 @@ const _CollectionManager = class _CollectionManager {
|
|
|
317
319
|
}, "getChildrens");
|
|
318
320
|
return getChildrens(name);
|
|
319
321
|
}
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
cached = {},
|
|
325
|
-
collectionNames = [collectionName],
|
|
326
|
-
maxDepth = 1,
|
|
327
|
-
allowAllTypes = false,
|
|
328
|
-
exceptInterfaces = [],
|
|
329
|
-
prefixFieldValue = "",
|
|
330
|
-
usePrefix = false,
|
|
331
|
-
dataSource: customDataSourceNameValue
|
|
332
|
-
} = opts || {};
|
|
333
|
-
if (collectionNames.length - 1 > maxDepth) {
|
|
334
|
-
return;
|
|
335
|
-
}
|
|
336
|
-
if (cached[collectionName]) {
|
|
337
|
-
return import_lodash.default.cloneDeep(cached[collectionName]);
|
|
322
|
+
getChildrenCollectionsName(name, isSupportView = false) {
|
|
323
|
+
const cacheKey = isSupportView ? "supportView" : "notSupportView";
|
|
324
|
+
if (this.childrenCollectionsName[cacheKey]) {
|
|
325
|
+
return this.childrenCollectionsName[cacheKey].slice();
|
|
338
326
|
}
|
|
339
|
-
const
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
usePrefix
|
|
327
|
+
const children = [];
|
|
328
|
+
const collections = [...this.getCollections()];
|
|
329
|
+
const getChildrenCollectionsInner = /* @__PURE__ */ __name((collectionName) => {
|
|
330
|
+
const inheritCollections = collections.filter((v) => {
|
|
331
|
+
var _a;
|
|
332
|
+
return (_a = [...v.inherits]) == null ? void 0 : _a.includes(collectionName);
|
|
333
|
+
});
|
|
334
|
+
inheritCollections.forEach((v) => {
|
|
335
|
+
const collectionKey = v.name;
|
|
336
|
+
children.push(collectionKey);
|
|
337
|
+
return getChildrenCollectionsInner(collectionKey);
|
|
338
|
+
});
|
|
339
|
+
if (isSupportView) {
|
|
340
|
+
const sourceCollections = collections.filter((v) => {
|
|
341
|
+
var _a;
|
|
342
|
+
return ((_a = [...v.sources]) == null ? void 0 : _a.length) === 1 && (v == null ? void 0 : v.sources[0]) === collectionName;
|
|
343
|
+
});
|
|
344
|
+
sourceCollections.forEach((v) => {
|
|
345
|
+
const collectionKey = v.name;
|
|
346
|
+
children.push(v.name);
|
|
347
|
+
return getChildrenCollectionsInner(collectionKey);
|
|
361
348
|
});
|
|
362
|
-
|
|
363
|
-
|
|
349
|
+
}
|
|
350
|
+
return import_lodash.default.uniq(children);
|
|
351
|
+
}, "getChildrenCollectionsInner");
|
|
352
|
+
this.childrenCollectionsName[cacheKey] = getChildrenCollectionsInner(name);
|
|
353
|
+
return this.childrenCollectionsName[cacheKey];
|
|
354
|
+
}
|
|
355
|
+
getAllCollectionsInheritChain(name) {
|
|
356
|
+
if (this.allCollectionsInheritChain) {
|
|
357
|
+
return this.allCollectionsInheritChain.slice();
|
|
358
|
+
}
|
|
359
|
+
const collectionsInheritChain = [name];
|
|
360
|
+
const getInheritChain = /* @__PURE__ */ __name((name2) => {
|
|
361
|
+
const collection = this.getCollection(name2);
|
|
362
|
+
if (collection) {
|
|
363
|
+
const { inherits } = collection;
|
|
364
|
+
const children = this.getChildrenCollectionsName(name2);
|
|
365
|
+
if (inherits) {
|
|
366
|
+
for (let index = 0; index < inherits.length; index++) {
|
|
367
|
+
const collectionKey = inherits[index];
|
|
368
|
+
if (collectionsInheritChain.includes(collectionKey)) {
|
|
369
|
+
continue;
|
|
370
|
+
}
|
|
371
|
+
collectionsInheritChain.push(collectionKey);
|
|
372
|
+
getInheritChain(collectionKey);
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
if (children) {
|
|
376
|
+
for (let index = 0; index < children.length; index++) {
|
|
377
|
+
const collection2 = this.getCollection(children[index]);
|
|
378
|
+
const collectionKey = collection2.name;
|
|
379
|
+
if (collectionsInheritChain.includes(collectionKey)) {
|
|
380
|
+
continue;
|
|
381
|
+
}
|
|
382
|
+
collectionsInheritChain.push(collectionKey);
|
|
383
|
+
getInheritChain(collectionKey);
|
|
384
|
+
}
|
|
364
385
|
}
|
|
365
386
|
}
|
|
366
|
-
return
|
|
367
|
-
})
|
|
368
|
-
|
|
369
|
-
return
|
|
387
|
+
return collectionsInheritChain;
|
|
388
|
+
}, "getInheritChain");
|
|
389
|
+
this.allCollectionsInheritChain = getInheritChain(name);
|
|
390
|
+
return this.allCollectionsInheritChain || [];
|
|
370
391
|
}
|
|
371
392
|
};
|
|
372
393
|
__name(_CollectionManager, "CollectionManager");
|
|
@@ -400,6 +421,9 @@ const _Collection = class _Collection {
|
|
|
400
421
|
if (typeof this.filterTargetKey === "string") {
|
|
401
422
|
return record[this.filterTargetKey];
|
|
402
423
|
}
|
|
424
|
+
if (Array.isArray(this.filterTargetKey) && this.filterTargetKey.length === 1) {
|
|
425
|
+
return record[this.filterTargetKey[0]];
|
|
426
|
+
}
|
|
403
427
|
return import_lodash.default.pick(record, this.filterTargetKey);
|
|
404
428
|
}
|
|
405
429
|
get titleableFields() {
|
|
@@ -433,7 +457,7 @@ const _Collection = class _Collection {
|
|
|
433
457
|
return this.options.storage || "local";
|
|
434
458
|
}
|
|
435
459
|
get title() {
|
|
436
|
-
return this.
|
|
460
|
+
return this.flowEngine.translate(this.options.title, { ns: "lm-collections" }) || this.name;
|
|
437
461
|
}
|
|
438
462
|
get titleCollectionField() {
|
|
439
463
|
const titleFieldName = this.options.titleField || this.filterTargetKey;
|
|
@@ -668,8 +692,8 @@ const _CollectionField = class _CollectionField {
|
|
|
668
692
|
}
|
|
669
693
|
get title() {
|
|
670
694
|
var _a, _b, _c;
|
|
671
|
-
const titleValue = ((_b = (_a = this.options) == null ? void 0 : _a.uiSchema) == null ? void 0 : _b.title) || ((_c = this.options) == null ? void 0 : _c.title)
|
|
672
|
-
return this.flowEngine.translate(titleValue);
|
|
695
|
+
const titleValue = ((_b = (_a = this.options) == null ? void 0 : _a.uiSchema) == null ? void 0 : _b.title) || ((_c = this.options) == null ? void 0 : _c.title);
|
|
696
|
+
return this.flowEngine.translate(titleValue, { ns: "lm-collections" }) || this.options.name;
|
|
673
697
|
}
|
|
674
698
|
set title(value) {
|
|
675
699
|
this.options.title = value;
|
|
@@ -682,13 +706,22 @@ const _CollectionField = class _CollectionField {
|
|
|
682
706
|
if (typeof v !== "object") {
|
|
683
707
|
return v;
|
|
684
708
|
}
|
|
709
|
+
if (v.value === null || v.value === void 0) {
|
|
710
|
+
return v;
|
|
711
|
+
}
|
|
685
712
|
return {
|
|
686
713
|
...v,
|
|
714
|
+
label: v.label ? this.flowEngine.translate(v.label, { ns: "lm-collections" }) : v.label,
|
|
687
715
|
value: Number(v.value)
|
|
688
716
|
};
|
|
689
717
|
});
|
|
690
718
|
}
|
|
691
|
-
return options
|
|
719
|
+
return options.map((v) => {
|
|
720
|
+
return {
|
|
721
|
+
...v,
|
|
722
|
+
label: this.flowEngine.translate(v.label, { ns: "lm-collections" })
|
|
723
|
+
};
|
|
724
|
+
});
|
|
692
725
|
}
|
|
693
726
|
get defaultValue() {
|
|
694
727
|
return this.options.defaultValue == null ? void 0 : this.options.defaultValue;
|
|
@@ -12,12 +12,13 @@ import type { DispatchEventOptions } from '../types';
|
|
|
12
12
|
export declare class FlowExecutor {
|
|
13
13
|
private readonly engine;
|
|
14
14
|
constructor(engine: FlowEngine);
|
|
15
|
+
private emitModelEventIf;
|
|
15
16
|
/** Cache wrapper for applyFlow cache lifecycle */
|
|
16
17
|
private withApplyFlowCache;
|
|
17
18
|
/**
|
|
18
19
|
* Execute a single flow on model.
|
|
19
20
|
*/
|
|
20
|
-
runFlow(model: FlowModel, flowKey: string, inputArgs?: Record<string, any>, runId?: string): Promise<any>;
|
|
21
|
+
runFlow(model: FlowModel, flowKey: string, inputArgs?: Record<string, any>, runId?: string, eventName?: string): Promise<any>;
|
|
21
22
|
/**
|
|
22
23
|
* Dispatch an event to flows bound via flow.on and execute them.
|
|
23
24
|
*/
|
|
@@ -51,6 +51,10 @@ const _FlowExecutor = class _FlowExecutor {
|
|
|
51
51
|
constructor(engine) {
|
|
52
52
|
this.engine = engine;
|
|
53
53
|
}
|
|
54
|
+
async emitModelEventIf(eventName, topic, payload) {
|
|
55
|
+
if (!eventName) return;
|
|
56
|
+
await this.engine.emitter.emitAsync(`model:event:${eventName}:${topic}`, payload);
|
|
57
|
+
}
|
|
54
58
|
/** Cache wrapper for applyFlow cache lifecycle */
|
|
55
59
|
async withApplyFlowCache(cacheKey, executor) {
|
|
56
60
|
if (!cacheKey || !this.engine) return await executor();
|
|
@@ -81,7 +85,7 @@ const _FlowExecutor = class _FlowExecutor {
|
|
|
81
85
|
/**
|
|
82
86
|
* Execute a single flow on model.
|
|
83
87
|
*/
|
|
84
|
-
async runFlow(model, flowKey, inputArgs, runId) {
|
|
88
|
+
async runFlow(model, flowKey, inputArgs, runId, eventName) {
|
|
85
89
|
var _a;
|
|
86
90
|
const flow = model.getFlow(flowKey);
|
|
87
91
|
if (!flow) {
|
|
@@ -113,6 +117,14 @@ const _FlowExecutor = class _FlowExecutor {
|
|
|
113
117
|
const stepDefs = eventStep ? { eventStep, ...flow.steps } : flow.steps;
|
|
114
118
|
(0, import_setupRuntimeContextSteps.setupRuntimeContextSteps)(flowContext, stepDefs, model, flowKey);
|
|
115
119
|
const stepsRuntime = flowContext.steps;
|
|
120
|
+
const flowEventBasePayload = {
|
|
121
|
+
uid: model.uid,
|
|
122
|
+
model,
|
|
123
|
+
runId: flowContext.runId,
|
|
124
|
+
inputArgs,
|
|
125
|
+
flowKey
|
|
126
|
+
};
|
|
127
|
+
await this.emitModelEventIf(eventName, `flow:${flowKey}:start`, flowEventBasePayload);
|
|
116
128
|
for (const [stepKey, step] of Object.entries(stepDefs)) {
|
|
117
129
|
let handler;
|
|
118
130
|
let combinedParams = {};
|
|
@@ -163,20 +175,58 @@ const _FlowExecutor = class _FlowExecutor {
|
|
|
163
175
|
);
|
|
164
176
|
continue;
|
|
165
177
|
}
|
|
178
|
+
await this.emitModelEventIf(eventName, `flow:${flowKey}:step:${stepKey}:start`, {
|
|
179
|
+
...flowEventBasePayload,
|
|
180
|
+
stepKey
|
|
181
|
+
});
|
|
166
182
|
const currentStepResult = handler(runtimeCtx, combinedParams);
|
|
167
183
|
const isAwait = step.isAwait !== false;
|
|
168
184
|
lastResult = isAwait ? await currentStepResult : currentStepResult;
|
|
169
185
|
stepResults[stepKey] = lastResult;
|
|
170
186
|
stepsRuntime[stepKey].result = stepResults[stepKey];
|
|
187
|
+
await this.emitModelEventIf(eventName, `flow:${flowKey}:step:${stepKey}:end`, {
|
|
188
|
+
...flowEventBasePayload,
|
|
189
|
+
result: lastResult,
|
|
190
|
+
stepKey
|
|
191
|
+
});
|
|
171
192
|
} catch (error) {
|
|
193
|
+
if (!(error instanceof import_utils.FlowExitException) && !(error instanceof import_exceptions.FlowExitAllException)) {
|
|
194
|
+
await this.emitModelEventIf(eventName, `flow:${flowKey}:step:${stepKey}:error`, {
|
|
195
|
+
...flowEventBasePayload,
|
|
196
|
+
error,
|
|
197
|
+
stepKey
|
|
198
|
+
});
|
|
199
|
+
}
|
|
172
200
|
if (error instanceof import_utils.FlowExitException) {
|
|
173
201
|
flowContext.logger.info(`[FlowEngine] ${error.message}`);
|
|
202
|
+
await this.emitModelEventIf(eventName, `flow:${flowKey}:step:${stepKey}:end`, {
|
|
203
|
+
...flowEventBasePayload,
|
|
204
|
+
stepKey
|
|
205
|
+
});
|
|
206
|
+
await this.emitModelEventIf(eventName, `flow:${flowKey}:end`, {
|
|
207
|
+
...flowEventBasePayload,
|
|
208
|
+
result: stepResults
|
|
209
|
+
});
|
|
174
210
|
return Promise.resolve(stepResults);
|
|
175
211
|
}
|
|
176
212
|
if (error instanceof import_exceptions.FlowExitAllException) {
|
|
177
213
|
flowContext.logger.info(`[FlowEngine] ${error.message}`);
|
|
214
|
+
await this.emitModelEventIf(eventName, `flow:${flowKey}:step:${stepKey}:end`, {
|
|
215
|
+
...flowEventBasePayload,
|
|
216
|
+
stepKey,
|
|
217
|
+
aborted: true
|
|
218
|
+
});
|
|
219
|
+
await this.emitModelEventIf(eventName, `flow:${flowKey}:end`, {
|
|
220
|
+
...flowEventBasePayload,
|
|
221
|
+
result: error,
|
|
222
|
+
aborted: true
|
|
223
|
+
});
|
|
178
224
|
return Promise.resolve(error);
|
|
179
225
|
}
|
|
226
|
+
await this.emitModelEventIf(eventName, `flow:${flowKey}:error`, {
|
|
227
|
+
...flowEventBasePayload,
|
|
228
|
+
error
|
|
229
|
+
});
|
|
180
230
|
flowContext.logger.error(
|
|
181
231
|
{ err: error },
|
|
182
232
|
`BaseModel.applyFlow: Error executing step '${stepKey}' in flow '${flowKey}':`
|
|
@@ -184,9 +234,12 @@ const _FlowExecutor = class _FlowExecutor {
|
|
|
184
234
|
return Promise.reject(error);
|
|
185
235
|
}
|
|
186
236
|
}
|
|
237
|
+
await this.emitModelEventIf(eventName, `flow:${flowKey}:end`, {
|
|
238
|
+
...flowEventBasePayload,
|
|
239
|
+
result: stepResults
|
|
240
|
+
});
|
|
187
241
|
return Promise.resolve(stepResults);
|
|
188
242
|
}
|
|
189
|
-
// runAutoFlows 已移除:统一通过 dispatchEvent('beforeRender') + useCache 控制
|
|
190
243
|
/**
|
|
191
244
|
* Dispatch an event to flows bound via flow.on and execute them.
|
|
192
245
|
*/
|
|
@@ -198,13 +251,14 @@ const _FlowExecutor = class _FlowExecutor {
|
|
|
198
251
|
const throwOnError = isBeforeRender;
|
|
199
252
|
const runId = `${model.uid}-${eventName}-${Date.now()}`;
|
|
200
253
|
const logger = model.context.logger;
|
|
254
|
+
const eventBasePayload = {
|
|
255
|
+
uid: model.uid,
|
|
256
|
+
model,
|
|
257
|
+
runId,
|
|
258
|
+
inputArgs
|
|
259
|
+
};
|
|
201
260
|
try {
|
|
202
|
-
await this.
|
|
203
|
-
uid: model.uid,
|
|
204
|
-
model,
|
|
205
|
-
runId,
|
|
206
|
-
inputArgs
|
|
207
|
-
});
|
|
261
|
+
await this.emitModelEventIf(eventName, "start", eventBasePayload);
|
|
208
262
|
await ((_a = model.onDispatchEventStart) == null ? void 0 : _a.call(model, eventName, options, inputArgs));
|
|
209
263
|
} catch (err) {
|
|
210
264
|
if (isBeforeRender && err instanceof import_utils.FlowExitException) {
|
|
@@ -226,9 +280,18 @@ const _FlowExecutor = class _FlowExecutor {
|
|
|
226
280
|
if (typeof on === "object") return on.eventName === eventName;
|
|
227
281
|
return false;
|
|
228
282
|
});
|
|
283
|
+
const isRouterReplayClick = eventName === "click" && (inputArgs == null ? void 0 : inputArgs.triggerByRouter) === true;
|
|
284
|
+
const flowsToRun = isRouterReplayClick ? flows.filter((flow) => {
|
|
285
|
+
var _a2;
|
|
286
|
+
const reg = flow["flowRegistry"];
|
|
287
|
+
const type = (_a2 = reg == null ? void 0 : reg.constructor) == null ? void 0 : _a2._type;
|
|
288
|
+
return type !== "instance";
|
|
289
|
+
}) : flows;
|
|
290
|
+
const scheduledCancels = [];
|
|
229
291
|
const execute = /* @__PURE__ */ __name(async () => {
|
|
292
|
+
let abortedByExitAll = false;
|
|
230
293
|
if (sequential) {
|
|
231
|
-
const flowsWithIndex =
|
|
294
|
+
const flowsWithIndex = flowsToRun.map((f, i) => ({ f, i }));
|
|
232
295
|
const ordered = flowsWithIndex.slice().sort((a, b) => {
|
|
233
296
|
var _a2, _b2;
|
|
234
297
|
const regA = a.f["flowRegistry"];
|
|
@@ -244,18 +307,110 @@ const _FlowExecutor = class _FlowExecutor {
|
|
|
244
307
|
return a.i - b.i;
|
|
245
308
|
}).map((x) => x.f);
|
|
246
309
|
const results2 = [];
|
|
310
|
+
const staticFlowsByKey = new Map(
|
|
311
|
+
ordered.filter((f) => {
|
|
312
|
+
var _a2;
|
|
313
|
+
const reg = f["flowRegistry"];
|
|
314
|
+
const type = (_a2 = reg == null ? void 0 : reg.constructor) == null ? void 0 : _a2._type;
|
|
315
|
+
return type !== "instance";
|
|
316
|
+
}).map((f) => [f.key, f])
|
|
317
|
+
);
|
|
318
|
+
const scheduled = /* @__PURE__ */ new Set();
|
|
319
|
+
const scheduleGroups = /* @__PURE__ */ new Map();
|
|
320
|
+
ordered.forEach((flow, indexInOrdered) => {
|
|
321
|
+
var _a2;
|
|
322
|
+
const on = flow.on;
|
|
323
|
+
const onObj = typeof on === "object" ? on : void 0;
|
|
324
|
+
if (!onObj) return;
|
|
325
|
+
const phase = onObj.phase;
|
|
326
|
+
const flowKey = onObj.flowKey;
|
|
327
|
+
const stepKey = onObj.stepKey;
|
|
328
|
+
if (!phase || phase === "beforeAllFlows") return;
|
|
329
|
+
let whenKey = null;
|
|
330
|
+
if (phase === "afterAllFlows") {
|
|
331
|
+
whenKey = `event:${eventName}:end`;
|
|
332
|
+
} else if (phase === "beforeFlow" || phase === "afterFlow") {
|
|
333
|
+
if (!flowKey) {
|
|
334
|
+
whenKey = `event:${eventName}:end`;
|
|
335
|
+
} else {
|
|
336
|
+
const anchorFlow = staticFlowsByKey.get(String(flowKey));
|
|
337
|
+
if (anchorFlow) {
|
|
338
|
+
const anchorPhase = phase === "beforeFlow" ? "start" : "end";
|
|
339
|
+
whenKey = `event:${eventName}:flow:${String(flowKey)}:${anchorPhase}`;
|
|
340
|
+
} else {
|
|
341
|
+
whenKey = `event:${eventName}:end`;
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
} else if (phase === "beforeStep" || phase === "afterStep") {
|
|
345
|
+
if (!flowKey || !stepKey) {
|
|
346
|
+
whenKey = `event:${eventName}:end`;
|
|
347
|
+
} else {
|
|
348
|
+
const anchorFlow = staticFlowsByKey.get(String(flowKey));
|
|
349
|
+
const anchorStepExists = !!((_a2 = anchorFlow == null ? void 0 : anchorFlow.hasStep) == null ? void 0 : _a2.call(anchorFlow, String(stepKey)));
|
|
350
|
+
if (anchorFlow && anchorStepExists) {
|
|
351
|
+
const anchorPhase = phase === "beforeStep" ? "start" : "end";
|
|
352
|
+
whenKey = `event:${eventName}:flow:${String(flowKey)}:step:${String(stepKey)}:${anchorPhase}`;
|
|
353
|
+
} else {
|
|
354
|
+
whenKey = `event:${eventName}:end`;
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
} else {
|
|
358
|
+
return;
|
|
359
|
+
}
|
|
360
|
+
if (!whenKey) return;
|
|
361
|
+
const shouldSkipOnAborted = whenKey === `event:${eventName}:end` || phase === "afterFlow" || phase === "afterStep";
|
|
362
|
+
scheduled.add(flow.key);
|
|
363
|
+
const list = scheduleGroups.get(whenKey) || [];
|
|
364
|
+
list.push({ flow, order: indexInOrdered, shouldSkipOnAborted });
|
|
365
|
+
scheduleGroups.set(whenKey, list);
|
|
366
|
+
});
|
|
367
|
+
for (const [whenKey, list] of scheduleGroups.entries()) {
|
|
368
|
+
const sorted = list.slice().sort((a, b) => {
|
|
369
|
+
const sa = a.flow.sort ?? 0;
|
|
370
|
+
const sb = b.flow.sort ?? 0;
|
|
371
|
+
if (sa !== sb) return sa - sb;
|
|
372
|
+
return a.order - b.order;
|
|
373
|
+
});
|
|
374
|
+
for (const it of sorted) {
|
|
375
|
+
const when = it.shouldSkipOnAborted ? Object.assign(
|
|
376
|
+
(event) => event.type === whenKey && event.aborted !== true,
|
|
377
|
+
{
|
|
378
|
+
__eventType: whenKey
|
|
379
|
+
}
|
|
380
|
+
) : whenKey;
|
|
381
|
+
const cancel = model.scheduleModelOperation(
|
|
382
|
+
model.uid,
|
|
383
|
+
async (m) => {
|
|
384
|
+
const res = await this.runFlow(m, it.flow.key, inputArgs, runId, eventName);
|
|
385
|
+
if (res instanceof import_exceptions.FlowExitAllException) {
|
|
386
|
+
throw res;
|
|
387
|
+
}
|
|
388
|
+
results2.push(res);
|
|
389
|
+
},
|
|
390
|
+
{ when }
|
|
391
|
+
);
|
|
392
|
+
scheduledCancels.push(cancel);
|
|
393
|
+
}
|
|
394
|
+
}
|
|
247
395
|
for (const flow of ordered) {
|
|
396
|
+
if (scheduled.has(flow.key)) continue;
|
|
248
397
|
try {
|
|
249
398
|
logger.debug(
|
|
250
399
|
`BaseModel '${model.uid}' dispatching event '${eventName}' to flow '${flow.key}' (sequential).`
|
|
251
400
|
);
|
|
252
|
-
const result = await this.runFlow(model, flow.key, inputArgs, runId);
|
|
401
|
+
const result = await this.runFlow(model, flow.key, inputArgs, runId, eventName);
|
|
253
402
|
if (result instanceof import_exceptions.FlowExitAllException) {
|
|
254
403
|
logger.debug(`[FlowEngine.dispatchEvent] ${result.message}`);
|
|
404
|
+
abortedByExitAll = true;
|
|
255
405
|
break;
|
|
256
406
|
}
|
|
257
407
|
results2.push(result);
|
|
258
408
|
} catch (error) {
|
|
409
|
+
if (error instanceof import_exceptions.FlowExitAllException) {
|
|
410
|
+
logger.debug(`[FlowEngine.dispatchEvent] ${error.message}`);
|
|
411
|
+
abortedByExitAll = true;
|
|
412
|
+
break;
|
|
413
|
+
}
|
|
259
414
|
logger.error(
|
|
260
415
|
{ err: error },
|
|
261
416
|
`BaseModel.dispatchEvent: Error executing event-triggered flow '${flow.key}' for event '${eventName}' (sequential):`
|
|
@@ -263,13 +418,13 @@ const _FlowExecutor = class _FlowExecutor {
|
|
|
263
418
|
throw error;
|
|
264
419
|
}
|
|
265
420
|
}
|
|
266
|
-
return results2;
|
|
421
|
+
return { result: results2, abortedByExitAll };
|
|
267
422
|
}
|
|
268
423
|
const results = await Promise.all(
|
|
269
|
-
|
|
424
|
+
flowsToRun.map(async (flow) => {
|
|
270
425
|
logger.debug(`BaseModel '${model.uid}' dispatching event '${eventName}' to flow '${flow.key}'.`);
|
|
271
426
|
try {
|
|
272
|
-
return await this.runFlow(model, flow.key, inputArgs, runId);
|
|
427
|
+
return await this.runFlow(model, flow.key, inputArgs, runId, eventName);
|
|
273
428
|
} catch (error) {
|
|
274
429
|
logger.error(
|
|
275
430
|
{ err: error },
|
|
@@ -280,7 +435,11 @@ const _FlowExecutor = class _FlowExecutor {
|
|
|
280
435
|
}
|
|
281
436
|
})
|
|
282
437
|
);
|
|
283
|
-
|
|
438
|
+
const filteredResults = results.filter((x) => x !== void 0);
|
|
439
|
+
if (filteredResults.some((x) => x instanceof import_exceptions.FlowExitAllException)) {
|
|
440
|
+
abortedByExitAll = true;
|
|
441
|
+
}
|
|
442
|
+
return { result: filteredResults, abortedByExitAll };
|
|
284
443
|
}, "execute");
|
|
285
444
|
const argsKey = useCache ? JSON.stringify(inputArgs ?? {}) : "";
|
|
286
445
|
const cacheKey = useCache ? import_flowEngine.FlowEngine.generateApplyFlowCacheKey(
|
|
@@ -289,19 +448,23 @@ const _FlowExecutor = class _FlowExecutor {
|
|
|
289
448
|
model.uid
|
|
290
449
|
) : null;
|
|
291
450
|
try {
|
|
292
|
-
const result = await this.withApplyFlowCache(cacheKey, execute);
|
|
451
|
+
const { result, abortedByExitAll } = await this.withApplyFlowCache(cacheKey, execute);
|
|
293
452
|
try {
|
|
294
453
|
await ((_c = model.onDispatchEventEnd) == null ? void 0 : _c.call(model, eventName, options, inputArgs, result));
|
|
295
454
|
} catch (hookErr) {
|
|
296
455
|
logger.error({ err: hookErr }, `BaseModel.dispatchEvent: End hook error for event '${eventName}'`);
|
|
297
456
|
}
|
|
298
|
-
await this.
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
inputArgs,
|
|
303
|
-
result
|
|
457
|
+
await this.emitModelEventIf(eventName, "end", {
|
|
458
|
+
...eventBasePayload,
|
|
459
|
+
result,
|
|
460
|
+
...abortedByExitAll ? { aborted: true } : {}
|
|
304
461
|
});
|
|
462
|
+
if (result && typeof result === "object") {
|
|
463
|
+
Object.defineProperty(result, "__abortedByExitAll", {
|
|
464
|
+
value: abortedByExitAll,
|
|
465
|
+
configurable: true
|
|
466
|
+
});
|
|
467
|
+
}
|
|
305
468
|
return result;
|
|
306
469
|
} catch (error) {
|
|
307
470
|
try {
|
|
@@ -312,14 +475,15 @@ const _FlowExecutor = class _FlowExecutor {
|
|
|
312
475
|
{ err: error },
|
|
313
476
|
`BaseModel.dispatchEvent: Error executing event '${eventName}' for model '${model.uid}':`
|
|
314
477
|
);
|
|
315
|
-
await this.
|
|
316
|
-
|
|
317
|
-
model,
|
|
318
|
-
runId,
|
|
319
|
-
inputArgs,
|
|
478
|
+
await this.emitModelEventIf(eventName, "error", {
|
|
479
|
+
...eventBasePayload,
|
|
320
480
|
error
|
|
321
481
|
});
|
|
322
482
|
if (throwOnError) throw error;
|
|
483
|
+
} finally {
|
|
484
|
+
for (const cancel of scheduledCancels) {
|
|
485
|
+
cancel();
|
|
486
|
+
}
|
|
323
487
|
}
|
|
324
488
|
}
|
|
325
489
|
};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file is part of the NocoBase (R) project.
|
|
3
|
+
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
|
|
4
|
+
* Authors: NocoBase Team.
|
|
5
|
+
*
|
|
6
|
+
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
|
7
|
+
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
|
+
*/
|
|
9
|
+
import type { FlowFieldBindingConditions, FlowFieldBindingContextContribution, FlowFieldBindingContribution, FlowFieldModelCompatibility, FlowSchemaCoverage } from '../types';
|
|
10
|
+
export type RegisteredFieldBindingContext = {
|
|
11
|
+
name: string;
|
|
12
|
+
inherits: string[];
|
|
13
|
+
};
|
|
14
|
+
export type RegisteredFieldBinding = {
|
|
15
|
+
context: string;
|
|
16
|
+
use: string;
|
|
17
|
+
interfaces: string[];
|
|
18
|
+
isDefault: boolean;
|
|
19
|
+
order?: number;
|
|
20
|
+
conditions?: FlowFieldBindingConditions;
|
|
21
|
+
defaultProps?: any;
|
|
22
|
+
source: FlowSchemaCoverage['source'];
|
|
23
|
+
};
|
|
24
|
+
export declare function normalizeFieldBindingContextContribution(contribution?: FlowFieldBindingContextContribution, fallbackName?: string): RegisteredFieldBindingContext | undefined;
|
|
25
|
+
export declare function normalizeFieldBindingContribution(contribution?: FlowFieldBindingContribution, source?: FlowSchemaCoverage['source']): RegisteredFieldBinding | undefined;
|
|
26
|
+
export declare function matchesFieldBinding(binding: RegisteredFieldBinding, options: {
|
|
27
|
+
interface?: string;
|
|
28
|
+
fieldType?: string;
|
|
29
|
+
association?: boolean;
|
|
30
|
+
targetCollectionTemplate?: string;
|
|
31
|
+
}): boolean;
|
|
32
|
+
export declare function buildFieldModelCompatibility(binding: RegisteredFieldBinding): FlowFieldModelCompatibility;
|