@nocobase/flow-engine 2.1.0-alpha.3 → 2.1.0-alpha.30
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/JSRunner.d.ts +10 -1
- package/lib/JSRunner.js +50 -5
- package/lib/ViewScopedFlowEngine.js +5 -1
- package/lib/components/FieldModelRenderer.js +2 -2
- package/lib/components/FlowModelRenderer.d.ts +3 -1
- package/lib/components/FlowModelRenderer.js +12 -6
- package/lib/components/MobilePopup.js +6 -5
- package/lib/components/dnd/gridDragPlanner.d.ts +59 -2
- package/lib/components/dnd/gridDragPlanner.js +601 -21
- package/lib/components/dnd/index.d.ts +19 -1
- package/lib/components/dnd/index.js +243 -23
- package/lib/components/settings/wrappers/component/SelectWithTitle.d.ts +2 -1
- package/lib/components/settings/wrappers/component/SelectWithTitle.js +14 -12
- package/lib/components/settings/wrappers/contextual/DefaultSettingsIcon.d.ts +3 -0
- package/lib/components/settings/wrappers/contextual/DefaultSettingsIcon.js +68 -10
- package/lib/components/settings/wrappers/contextual/FlowsFloatContextMenu.d.ts +23 -43
- package/lib/components/settings/wrappers/contextual/FlowsFloatContextMenu.js +352 -295
- package/lib/components/settings/wrappers/contextual/StepSettingsDialog.js +16 -2
- package/lib/components/settings/wrappers/contextual/useFloatToolbarPortal.d.ts +36 -0
- package/lib/components/settings/wrappers/contextual/useFloatToolbarPortal.js +274 -0
- package/lib/components/settings/wrappers/contextual/useFloatToolbarVisibility.d.ts +30 -0
- package/lib/components/settings/wrappers/contextual/useFloatToolbarVisibility.js +315 -0
- package/lib/components/subModel/AddSubModelButton.js +27 -1
- package/lib/components/subModel/index.d.ts +1 -0
- package/lib/components/subModel/index.js +19 -0
- package/lib/components/subModel/utils.d.ts +1 -1
- package/lib/components/subModel/utils.js +2 -2
- package/lib/data-source/index.d.ts +73 -0
- package/lib/data-source/index.js +211 -1
- package/lib/executor/FlowExecutor.js +31 -8
- package/lib/flowContext.d.ts +2 -0
- package/lib/flowContext.js +31 -1
- package/lib/flowEngine.d.ts +151 -1
- package/lib/flowEngine.js +389 -15
- package/lib/flowI18n.js +2 -1
- package/lib/flowSettings.d.ts +14 -6
- package/lib/flowSettings.js +34 -6
- package/lib/lazy-helper.d.ts +14 -0
- package/lib/lazy-helper.js +71 -0
- package/lib/locale/en-US.json +1 -0
- package/lib/locale/index.d.ts +2 -0
- package/lib/locale/zh-CN.json +1 -0
- 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 +13 -10
- package/lib/models/flowModel.js +78 -18
- package/lib/provider.js +38 -23
- package/lib/reactive/observer.js +46 -16
- package/lib/runjs-context/registry.d.ts +1 -1
- package/lib/runjs-context/setup.js +20 -12
- package/lib/runjs-context/snippets/index.js +13 -2
- package/lib/runjs-context/snippets/scene/detail/set-field-style.snippet.d.ts +11 -0
- package/lib/runjs-context/snippets/scene/detail/set-field-style.snippet.js +50 -0
- package/lib/runjs-context/snippets/scene/table/set-cell-style.snippet.d.ts +11 -0
- package/lib/runjs-context/snippets/scene/table/set-cell-style.snippet.js +54 -0
- package/lib/scheduler/ModelOperationScheduler.d.ts +5 -1
- package/lib/scheduler/ModelOperationScheduler.js +3 -2
- package/lib/types.d.ts +47 -1
- package/lib/utils/createCollectionContextMeta.js +6 -2
- package/lib/utils/index.d.ts +2 -2
- package/lib/utils/index.js +4 -0
- package/lib/utils/parsePathnameToViewParams.js +1 -1
- package/lib/utils/runjsTemplateCompat.js +1 -1
- package/lib/utils/runjsValue.js +41 -11
- package/lib/utils/schema-utils.d.ts +7 -1
- package/lib/utils/schema-utils.js +19 -0
- package/lib/views/FlowView.d.ts +7 -1
- 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 +20 -3
- package/lib/views/useDrawer.d.ts +2 -1
- package/lib/views/useDrawer.js +20 -3
- package/lib/views/usePage.d.ts +2 -1
- package/lib/views/usePage.js +10 -3
- package/package.json +6 -5
- package/src/JSRunner.ts +68 -4
- package/src/ViewScopedFlowEngine.ts +4 -0
- package/src/__tests__/JSRunner.test.ts +27 -1
- package/src/__tests__/flow-engine.test.ts +166 -0
- package/src/__tests__/flowContext.test.ts +65 -1
- package/src/__tests__/flowEngine.modelLoaders.test.ts +245 -0
- package/src/__tests__/flowSettings.test.ts +94 -15
- package/src/__tests__/objectVariable.test.ts +24 -0
- package/src/__tests__/provider.test.tsx +24 -2
- package/src/__tests__/renderHiddenInConfig.test.tsx +6 -6
- package/src/__tests__/runjsContext.test.ts +16 -0
- package/src/__tests__/runjsContextRuntime.test.ts +2 -0
- package/src/__tests__/runjsPreprocessDefault.test.ts +23 -0
- package/src/__tests__/runjsSnippets.test.ts +21 -0
- package/src/__tests__/viewScopedFlowEngine.test.ts +3 -3
- package/src/components/FieldModelRenderer.tsx +2 -1
- package/src/components/FlowModelRenderer.tsx +18 -6
- package/src/components/MobilePopup.tsx +4 -2
- package/src/components/__tests__/FlowModelRenderer.test.tsx +65 -2
- package/src/components/__tests__/dnd.test.ts +44 -0
- package/src/components/__tests__/flow-model-render-error-fallback.test.tsx +20 -10
- package/src/components/__tests__/gridDragPlanner.test.ts +512 -3
- package/src/components/dnd/__tests__/DndProvider.test.tsx +98 -0
- package/src/components/dnd/gridDragPlanner.ts +743 -19
- package/src/components/dnd/index.tsx +291 -27
- package/src/components/settings/wrappers/component/SelectWithTitle.tsx +21 -9
- package/src/components/settings/wrappers/contextual/DefaultSettingsIcon.tsx +88 -10
- package/src/components/settings/wrappers/contextual/FlowsFloatContextMenu.tsx +487 -440
- package/src/components/settings/wrappers/contextual/StepSettingsDialog.tsx +18 -2
- package/src/components/settings/wrappers/contextual/__tests__/DefaultSettingsIcon.test.tsx +189 -3
- package/src/components/settings/wrappers/contextual/__tests__/FlowsFloatContextMenu.test.tsx +778 -0
- package/src/components/settings/wrappers/contextual/useFloatToolbarPortal.ts +360 -0
- package/src/components/settings/wrappers/contextual/useFloatToolbarVisibility.ts +361 -0
- package/src/components/subModel/AddSubModelButton.tsx +32 -2
- package/src/components/subModel/__tests__/AddSubModelButton.test.tsx +142 -32
- package/src/components/subModel/index.ts +1 -0
- package/src/components/subModel/utils.ts +1 -1
- package/src/data-source/__tests__/index.test.ts +34 -1
- package/src/data-source/index.ts +258 -2
- package/src/executor/FlowExecutor.ts +34 -9
- package/src/executor/__tests__/flowExecutor.test.ts +57 -0
- package/src/flowContext.ts +37 -3
- package/src/flowEngine.ts +445 -11
- package/src/flowI18n.ts +2 -1
- package/src/flowSettings.ts +40 -6
- package/src/lazy-helper.tsx +57 -0
- package/src/locale/en-US.json +1 -0
- package/src/locale/zh-CN.json +1 -0
- 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 +214 -0
- package/src/models/__tests__/flowModel.test.ts +19 -3
- package/src/models/flowModel.tsx +119 -33
- package/src/provider.tsx +41 -25
- package/src/reactive/__tests__/observer.test.tsx +82 -0
- package/src/reactive/observer.tsx +87 -25
- package/src/runjs-context/registry.ts +1 -1
- package/src/runjs-context/setup.ts +22 -12
- package/src/runjs-context/snippets/index.ts +12 -1
- package/src/runjs-context/snippets/scene/detail/set-field-style.snippet.ts +30 -0
- package/src/runjs-context/snippets/scene/table/set-cell-style.snippet.ts +34 -0
- package/src/scheduler/ModelOperationScheduler.ts +14 -3
- package/src/types.ts +60 -0
- package/src/utils/__tests__/createCollectionContextMeta.test.ts +48 -0
- package/src/utils/__tests__/parsePathnameToViewParams.test.ts +7 -0
- package/src/utils/__tests__/runjsValue.test.ts +11 -0
- package/src/utils/__tests__/utils.test.ts +62 -0
- package/src/utils/createCollectionContextMeta.ts +6 -2
- package/src/utils/index.ts +2 -1
- package/src/utils/parsePathnameToViewParams.ts +2 -2
- package/src/utils/runjsTemplateCompat.ts +1 -1
- package/src/utils/runjsValue.ts +50 -11
- package/src/utils/schema-utils.ts +30 -1
- package/src/views/FlowView.tsx +11 -1
- package/src/views/__tests__/runViewBeforeClose.test.ts +30 -0
- package/src/views/__tests__/useDialog.closeDestroy.test.tsx +13 -12
- package/src/views/runViewBeforeClose.ts +19 -0
- package/src/views/useDialog.tsx +25 -3
- package/src/views/useDrawer.tsx +25 -3
- package/src/views/usePage.tsx +12 -3
package/lib/data-source/index.js
CHANGED
|
@@ -53,12 +53,47 @@ var import_sortCollectionsByInherits = require("./sortCollectionsByInherits");
|
|
|
53
53
|
const _DataSourceManager = class _DataSourceManager {
|
|
54
54
|
dataSources;
|
|
55
55
|
flowEngine;
|
|
56
|
+
requester;
|
|
57
|
+
collectionFieldInterfaceManager;
|
|
58
|
+
loaders = /* @__PURE__ */ new Map();
|
|
59
|
+
loadedKeys = /* @__PURE__ */ new Set();
|
|
60
|
+
loadingKeys = /* @__PURE__ */ new Set();
|
|
61
|
+
loadErrors = /* @__PURE__ */ new Map();
|
|
62
|
+
loadingPromise = null;
|
|
56
63
|
constructor() {
|
|
57
64
|
this.dataSources = import_reactive.observable.shallow(/* @__PURE__ */ new Map());
|
|
58
65
|
}
|
|
59
66
|
setFlowEngine(flowEngine) {
|
|
60
67
|
this.flowEngine = flowEngine;
|
|
61
68
|
}
|
|
69
|
+
setRequester(requester) {
|
|
70
|
+
this.requester = requester;
|
|
71
|
+
}
|
|
72
|
+
setCollectionFieldInterfaceManager(manager) {
|
|
73
|
+
this.collectionFieldInterfaceManager = manager;
|
|
74
|
+
}
|
|
75
|
+
addFieldInterfaces(fieldInterfaceClasses = []) {
|
|
76
|
+
var _a, _b;
|
|
77
|
+
(_b = (_a = this.collectionFieldInterfaceManager) == null ? void 0 : _a.addFieldInterfaces) == null ? void 0 : _b.call(_a, fieldInterfaceClasses);
|
|
78
|
+
}
|
|
79
|
+
addFieldInterfaceGroups(groups) {
|
|
80
|
+
var _a, _b;
|
|
81
|
+
(_b = (_a = this.collectionFieldInterfaceManager) == null ? void 0 : _a.addFieldInterfaceGroups) == null ? void 0 : _b.call(_a, groups);
|
|
82
|
+
}
|
|
83
|
+
addFieldInterfaceComponentOption(name, option) {
|
|
84
|
+
var _a, _b;
|
|
85
|
+
(_b = (_a = this.collectionFieldInterfaceManager) == null ? void 0 : _a.addFieldInterfaceComponentOption) == null ? void 0 : _b.call(_a, name, option);
|
|
86
|
+
}
|
|
87
|
+
addFieldInterfaceOperator(name, operator) {
|
|
88
|
+
var _a, _b;
|
|
89
|
+
(_b = (_a = this.collectionFieldInterfaceManager) == null ? void 0 : _a.addFieldInterfaceOperator) == null ? void 0 : _b.call(_a, name, operator);
|
|
90
|
+
}
|
|
91
|
+
registerLoader(key, loader) {
|
|
92
|
+
this.loaders.set(key, loader);
|
|
93
|
+
}
|
|
94
|
+
removeLoader(key) {
|
|
95
|
+
this.loaders.delete(key);
|
|
96
|
+
}
|
|
62
97
|
addDataSource(ds) {
|
|
63
98
|
if (this.dataSources.has(ds.key)) {
|
|
64
99
|
throw new Error(`DataSource with name ${ds.key} already exists`);
|
|
@@ -75,7 +110,7 @@ const _DataSourceManager = class _DataSourceManager {
|
|
|
75
110
|
upsertDataSource(ds) {
|
|
76
111
|
var _a;
|
|
77
112
|
if (this.dataSources.has(ds.key)) {
|
|
78
|
-
(_a = this.dataSources.get(ds.key)) == null ? void 0 : _a.
|
|
113
|
+
(_a = this.dataSources.get(ds.key)) == null ? void 0 : _a.patchOptions(ds);
|
|
79
114
|
} else {
|
|
80
115
|
this.addDataSource(ds);
|
|
81
116
|
}
|
|
@@ -103,6 +138,144 @@ const _DataSourceManager = class _DataSourceManager {
|
|
|
103
138
|
if (!ds) return void 0;
|
|
104
139
|
return ds.getCollectionField(otherKeys.join("."));
|
|
105
140
|
}
|
|
141
|
+
async ensureLoaded(options = {}) {
|
|
142
|
+
const { force = false } = options;
|
|
143
|
+
const keys = this.resolveLoadKeys(options.keys);
|
|
144
|
+
const pendingKeys = force ? keys : keys.filter((key) => !this.loadedKeys.has(key));
|
|
145
|
+
if (!pendingKeys.length) {
|
|
146
|
+
return;
|
|
147
|
+
}
|
|
148
|
+
if (this.loadingPromise) {
|
|
149
|
+
return this.loadingPromise;
|
|
150
|
+
}
|
|
151
|
+
this.loadingPromise = (async () => {
|
|
152
|
+
try {
|
|
153
|
+
for (const key of pendingKeys) {
|
|
154
|
+
await this.loadKey(key, { initial: !this.loadedKeys.has(key), force });
|
|
155
|
+
}
|
|
156
|
+
} finally {
|
|
157
|
+
this.loadingPromise = null;
|
|
158
|
+
}
|
|
159
|
+
})();
|
|
160
|
+
return this.loadingPromise;
|
|
161
|
+
}
|
|
162
|
+
async reload(options = {}) {
|
|
163
|
+
const keys = this.resolveLoadKeys(options.keys);
|
|
164
|
+
if (!keys.length) {
|
|
165
|
+
return;
|
|
166
|
+
}
|
|
167
|
+
if (this.loadingPromise) {
|
|
168
|
+
return this.loadingPromise;
|
|
169
|
+
}
|
|
170
|
+
this.loadingPromise = (async () => {
|
|
171
|
+
try {
|
|
172
|
+
for (const key of keys) {
|
|
173
|
+
await this.loadKey(key, { initial: false, force: true });
|
|
174
|
+
}
|
|
175
|
+
} finally {
|
|
176
|
+
this.loadingPromise = null;
|
|
177
|
+
}
|
|
178
|
+
})();
|
|
179
|
+
return this.loadingPromise;
|
|
180
|
+
}
|
|
181
|
+
async reloadDataSource(key) {
|
|
182
|
+
if (this.loadingKeys.has(key) && this.loadingPromise) {
|
|
183
|
+
return this.loadingPromise;
|
|
184
|
+
}
|
|
185
|
+
if (!this.loaders.has(key) && this.loaders.has("*")) {
|
|
186
|
+
return this.reload({ keys: ["*"] });
|
|
187
|
+
}
|
|
188
|
+
return this.reload({ keys: [key] });
|
|
189
|
+
}
|
|
190
|
+
resolveLoadKeys(requestedKeys) {
|
|
191
|
+
const normalizedKeys = (requestedKeys == null ? void 0 : requestedKeys.length) ? requestedKeys : ["main"];
|
|
192
|
+
const explicitKeys = normalizedKeys.filter((key) => this.loaders.has(key));
|
|
193
|
+
if (this.loaders.has("*")) {
|
|
194
|
+
return import_lodash.default.uniq(["*", ...explicitKeys]);
|
|
195
|
+
}
|
|
196
|
+
return explicitKeys.length ? explicitKeys : normalizedKeys;
|
|
197
|
+
}
|
|
198
|
+
getApp() {
|
|
199
|
+
var _a, _b;
|
|
200
|
+
return (_b = (_a = this.flowEngine) == null ? void 0 : _a.context) == null ? void 0 : _b.app;
|
|
201
|
+
}
|
|
202
|
+
dispatchDataSourceEvent(type, detail) {
|
|
203
|
+
var _a, _b;
|
|
204
|
+
(_b = (_a = this.getApp()) == null ? void 0 : _a.eventBus) == null ? void 0 : _b.dispatchEvent(new CustomEvent(type, { detail }));
|
|
205
|
+
}
|
|
206
|
+
setDataSourceState(key, options) {
|
|
207
|
+
const dataSource = this.getDataSource(key);
|
|
208
|
+
if (!dataSource) {
|
|
209
|
+
return;
|
|
210
|
+
}
|
|
211
|
+
dataSource.patchOptions(options);
|
|
212
|
+
}
|
|
213
|
+
applyDataSourceLoadResult(key, result) {
|
|
214
|
+
if (key === "*") {
|
|
215
|
+
const dataSources = (result == null ? void 0 : result.dataSources) || [];
|
|
216
|
+
dataSources.forEach((dataSourceOptions) => {
|
|
217
|
+
var _a;
|
|
218
|
+
const { collections, ...dataSource2 } = dataSourceOptions;
|
|
219
|
+
this.upsertDataSource(dataSource2);
|
|
220
|
+
if (collections) {
|
|
221
|
+
(_a = this.getDataSource(dataSource2.key)) == null ? void 0 : _a.setCollections(collections, { clearFields: true });
|
|
222
|
+
}
|
|
223
|
+
});
|
|
224
|
+
return;
|
|
225
|
+
}
|
|
226
|
+
const dataSource = this.getDataSource(key);
|
|
227
|
+
if (!dataSource) {
|
|
228
|
+
return;
|
|
229
|
+
}
|
|
230
|
+
dataSource.setCollections((result == null ? void 0 : result.collections) || [], { clearFields: true });
|
|
231
|
+
}
|
|
232
|
+
async loadKey(key, options) {
|
|
233
|
+
const loader = this.loaders.get(key);
|
|
234
|
+
if (!loader) {
|
|
235
|
+
return;
|
|
236
|
+
}
|
|
237
|
+
if (!this.getDataSource(key) && key !== "*") {
|
|
238
|
+
this.addDataSource({ key });
|
|
239
|
+
}
|
|
240
|
+
const { initial } = options;
|
|
241
|
+
this.loadingKeys.add(key);
|
|
242
|
+
if (key !== "*") {
|
|
243
|
+
this.setDataSourceState(key, {
|
|
244
|
+
status: initial ? "loading" : "reloading",
|
|
245
|
+
errorMessage: void 0
|
|
246
|
+
});
|
|
247
|
+
}
|
|
248
|
+
this.loadErrors.set(key, null);
|
|
249
|
+
try {
|
|
250
|
+
const result = await loader({ key, manager: this }) || {};
|
|
251
|
+
this.applyDataSourceLoadResult(key, result);
|
|
252
|
+
this.loadedKeys.add(key);
|
|
253
|
+
if (key !== "*") {
|
|
254
|
+
this.setDataSourceState(key, {
|
|
255
|
+
status: "loaded",
|
|
256
|
+
errorMessage: void 0
|
|
257
|
+
});
|
|
258
|
+
}
|
|
259
|
+
this.dispatchDataSourceEvent("dataSource:loaded", { dataSourceKey: key, initial });
|
|
260
|
+
} catch (error) {
|
|
261
|
+
const normalizedError = error instanceof Error ? error : new Error(String(error));
|
|
262
|
+
this.loadErrors.set(key, normalizedError);
|
|
263
|
+
if (key !== "*") {
|
|
264
|
+
this.setDataSourceState(key, {
|
|
265
|
+
status: initial ? "loading-failed" : "reloading-failed",
|
|
266
|
+
errorMessage: normalizedError.message
|
|
267
|
+
});
|
|
268
|
+
}
|
|
269
|
+
this.dispatchDataSourceEvent("dataSource:loadFailed", {
|
|
270
|
+
dataSourceKey: key,
|
|
271
|
+
initial,
|
|
272
|
+
error: normalizedError
|
|
273
|
+
});
|
|
274
|
+
throw normalizedError;
|
|
275
|
+
} finally {
|
|
276
|
+
this.loadingKeys.delete(key);
|
|
277
|
+
}
|
|
278
|
+
}
|
|
106
279
|
};
|
|
107
280
|
__name(_DataSourceManager, "DataSourceManager");
|
|
108
281
|
let DataSourceManager = _DataSourceManager;
|
|
@@ -126,6 +299,12 @@ const _DataSource = class _DataSource {
|
|
|
126
299
|
get name() {
|
|
127
300
|
return this.options.key;
|
|
128
301
|
}
|
|
302
|
+
get status() {
|
|
303
|
+
return this.options.status;
|
|
304
|
+
}
|
|
305
|
+
get errorMessage() {
|
|
306
|
+
return this.options.errorMessage;
|
|
307
|
+
}
|
|
129
308
|
setDataSourceManager(dataSourceManager) {
|
|
130
309
|
this.dataSourceManager = dataSourceManager;
|
|
131
310
|
}
|
|
@@ -156,6 +335,9 @@ const _DataSource = class _DataSource {
|
|
|
156
335
|
upsertCollections(collections, options = {}) {
|
|
157
336
|
return this.collectionManager.upsertCollections(collections, options);
|
|
158
337
|
}
|
|
338
|
+
setCollections(collections, options = {}) {
|
|
339
|
+
return this.collectionManager.setCollections(collections, options);
|
|
340
|
+
}
|
|
159
341
|
removeCollection(name) {
|
|
160
342
|
return this.collectionManager.removeCollection(name);
|
|
161
343
|
}
|
|
@@ -166,6 +348,12 @@ const _DataSource = class _DataSource {
|
|
|
166
348
|
Object.keys(this.options).forEach((key) => delete this.options[key]);
|
|
167
349
|
Object.assign(this.options, newOptions);
|
|
168
350
|
}
|
|
351
|
+
patchOptions(newOptions = {}) {
|
|
352
|
+
Object.assign(this.options, newOptions);
|
|
353
|
+
}
|
|
354
|
+
reload() {
|
|
355
|
+
return this.dataSourceManager.reloadDataSource(this.key);
|
|
356
|
+
}
|
|
169
357
|
getCollectionField(fieldPath) {
|
|
170
358
|
const [collectionName, ...otherKeys] = fieldPath.split(".");
|
|
171
359
|
const fieldName = otherKeys.join(".");
|
|
@@ -190,6 +378,10 @@ const _CollectionManager = class _CollectionManager {
|
|
|
190
378
|
collections;
|
|
191
379
|
allCollectionsInheritChain;
|
|
192
380
|
childrenCollectionsName = {};
|
|
381
|
+
resetCaches() {
|
|
382
|
+
this.childrenCollectionsName = {};
|
|
383
|
+
this.allCollectionsInheritChain = void 0;
|
|
384
|
+
}
|
|
193
385
|
get flowEngine() {
|
|
194
386
|
return this.dataSource.flowEngine;
|
|
195
387
|
}
|
|
@@ -203,9 +395,11 @@ const _CollectionManager = class _CollectionManager {
|
|
|
203
395
|
col.setDataSource(this.dataSource);
|
|
204
396
|
col.initInherits();
|
|
205
397
|
this.collections.set(col.name, col);
|
|
398
|
+
this.resetCaches();
|
|
206
399
|
}
|
|
207
400
|
removeCollection(name) {
|
|
208
401
|
this.collections.delete(name);
|
|
402
|
+
this.resetCaches();
|
|
209
403
|
}
|
|
210
404
|
updateCollection(newOptions, options = {}) {
|
|
211
405
|
const collection = this.getCollection(newOptions.name);
|
|
@@ -213,6 +407,7 @@ const _CollectionManager = class _CollectionManager {
|
|
|
213
407
|
throw new Error(`Collection ${newOptions.name} not found`);
|
|
214
408
|
}
|
|
215
409
|
collection.setOptions(newOptions, options);
|
|
410
|
+
this.resetCaches();
|
|
216
411
|
}
|
|
217
412
|
upsertCollection(options) {
|
|
218
413
|
if (this.collections.has(options.name)) {
|
|
@@ -230,6 +425,11 @@ const _CollectionManager = class _CollectionManager {
|
|
|
230
425
|
this.addCollection(collection);
|
|
231
426
|
}
|
|
232
427
|
}
|
|
428
|
+
this.resetCaches();
|
|
429
|
+
}
|
|
430
|
+
setCollections(collections, options = {}) {
|
|
431
|
+
this.clearCollections();
|
|
432
|
+
this.upsertCollections(collections, options);
|
|
233
433
|
}
|
|
234
434
|
sortCollectionsByInherits(collections) {
|
|
235
435
|
const map = /* @__PURE__ */ new Map();
|
|
@@ -293,6 +493,7 @@ const _CollectionManager = class _CollectionManager {
|
|
|
293
493
|
}
|
|
294
494
|
clearCollections() {
|
|
295
495
|
this.collections.clear();
|
|
496
|
+
this.resetCaches();
|
|
296
497
|
}
|
|
297
498
|
getAssociation(associationName) {
|
|
298
499
|
const [collectionName, fieldName] = associationName.split(".");
|
|
@@ -461,6 +662,12 @@ const _Collection = class _Collection {
|
|
|
461
662
|
}
|
|
462
663
|
get titleCollectionField() {
|
|
463
664
|
const titleFieldName = this.options.titleField || this.filterTargetKey;
|
|
665
|
+
if (Array.isArray(titleFieldName)) {
|
|
666
|
+
if (titleFieldName.length !== 1) {
|
|
667
|
+
return void 0;
|
|
668
|
+
}
|
|
669
|
+
return this.getField(titleFieldName[0]);
|
|
670
|
+
}
|
|
464
671
|
const titleCollectionField = this.getField(titleFieldName);
|
|
465
672
|
return titleCollectionField;
|
|
466
673
|
}
|
|
@@ -487,6 +694,9 @@ const _Collection = class _Collection {
|
|
|
487
694
|
}
|
|
488
695
|
this.upsertFields(this.options.fields || []);
|
|
489
696
|
}
|
|
697
|
+
setOption(key, value) {
|
|
698
|
+
this.options[key] = value;
|
|
699
|
+
}
|
|
490
700
|
getFields() {
|
|
491
701
|
const fieldMap = /* @__PURE__ */ new Map();
|
|
492
702
|
for (const inherit of this.inherits.values()) {
|
|
@@ -213,11 +213,13 @@ const _FlowExecutor = class _FlowExecutor {
|
|
|
213
213
|
flowContext.logger.info(`[FlowEngine] ${error.message}`);
|
|
214
214
|
await this.emitModelEventIf(eventName, `flow:${flowKey}:step:${stepKey}:end`, {
|
|
215
215
|
...flowEventBasePayload,
|
|
216
|
-
stepKey
|
|
216
|
+
stepKey,
|
|
217
|
+
aborted: true
|
|
217
218
|
});
|
|
218
219
|
await this.emitModelEventIf(eventName, `flow:${flowKey}:end`, {
|
|
219
220
|
...flowEventBasePayload,
|
|
220
|
-
result: error
|
|
221
|
+
result: error,
|
|
222
|
+
aborted: true
|
|
221
223
|
});
|
|
222
224
|
return Promise.resolve(error);
|
|
223
225
|
}
|
|
@@ -287,6 +289,7 @@ const _FlowExecutor = class _FlowExecutor {
|
|
|
287
289
|
}) : flows;
|
|
288
290
|
const scheduledCancels = [];
|
|
289
291
|
const execute = /* @__PURE__ */ __name(async () => {
|
|
292
|
+
let abortedByExitAll = false;
|
|
290
293
|
if (sequential) {
|
|
291
294
|
const flowsWithIndex = flowsToRun.map((f, i) => ({ f, i }));
|
|
292
295
|
const ordered = flowsWithIndex.slice().sort((a, b) => {
|
|
@@ -355,9 +358,10 @@ const _FlowExecutor = class _FlowExecutor {
|
|
|
355
358
|
return;
|
|
356
359
|
}
|
|
357
360
|
if (!whenKey) return;
|
|
361
|
+
const shouldSkipOnAborted = whenKey === `event:${eventName}:end` || phase === "afterFlow" || phase === "afterStep";
|
|
358
362
|
scheduled.add(flow.key);
|
|
359
363
|
const list = scheduleGroups.get(whenKey) || [];
|
|
360
|
-
list.push({ flow, order: indexInOrdered });
|
|
364
|
+
list.push({ flow, order: indexInOrdered, shouldSkipOnAborted });
|
|
361
365
|
scheduleGroups.set(whenKey, list);
|
|
362
366
|
});
|
|
363
367
|
for (const [whenKey, list] of scheduleGroups.entries()) {
|
|
@@ -368,6 +372,12 @@ const _FlowExecutor = class _FlowExecutor {
|
|
|
368
372
|
return a.order - b.order;
|
|
369
373
|
});
|
|
370
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;
|
|
371
381
|
const cancel = model.scheduleModelOperation(
|
|
372
382
|
model.uid,
|
|
373
383
|
async (m) => {
|
|
@@ -377,7 +387,7 @@ const _FlowExecutor = class _FlowExecutor {
|
|
|
377
387
|
}
|
|
378
388
|
results2.push(res);
|
|
379
389
|
},
|
|
380
|
-
{ when
|
|
390
|
+
{ when }
|
|
381
391
|
);
|
|
382
392
|
scheduledCancels.push(cancel);
|
|
383
393
|
}
|
|
@@ -391,12 +401,14 @@ const _FlowExecutor = class _FlowExecutor {
|
|
|
391
401
|
const result = await this.runFlow(model, flow.key, inputArgs, runId, eventName);
|
|
392
402
|
if (result instanceof import_exceptions.FlowExitAllException) {
|
|
393
403
|
logger.debug(`[FlowEngine.dispatchEvent] ${result.message}`);
|
|
404
|
+
abortedByExitAll = true;
|
|
394
405
|
break;
|
|
395
406
|
}
|
|
396
407
|
results2.push(result);
|
|
397
408
|
} catch (error) {
|
|
398
409
|
if (error instanceof import_exceptions.FlowExitAllException) {
|
|
399
410
|
logger.debug(`[FlowEngine.dispatchEvent] ${error.message}`);
|
|
411
|
+
abortedByExitAll = true;
|
|
400
412
|
break;
|
|
401
413
|
}
|
|
402
414
|
logger.error(
|
|
@@ -406,7 +418,7 @@ const _FlowExecutor = class _FlowExecutor {
|
|
|
406
418
|
throw error;
|
|
407
419
|
}
|
|
408
420
|
}
|
|
409
|
-
return results2;
|
|
421
|
+
return { result: results2, abortedByExitAll };
|
|
410
422
|
}
|
|
411
423
|
const results = await Promise.all(
|
|
412
424
|
flowsToRun.map(async (flow) => {
|
|
@@ -423,7 +435,11 @@ const _FlowExecutor = class _FlowExecutor {
|
|
|
423
435
|
}
|
|
424
436
|
})
|
|
425
437
|
);
|
|
426
|
-
|
|
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 };
|
|
427
443
|
}, "execute");
|
|
428
444
|
const argsKey = useCache ? JSON.stringify(inputArgs ?? {}) : "";
|
|
429
445
|
const cacheKey = useCache ? import_flowEngine.FlowEngine.generateApplyFlowCacheKey(
|
|
@@ -432,7 +448,7 @@ const _FlowExecutor = class _FlowExecutor {
|
|
|
432
448
|
model.uid
|
|
433
449
|
) : null;
|
|
434
450
|
try {
|
|
435
|
-
const result = await this.withApplyFlowCache(cacheKey, execute);
|
|
451
|
+
const { result, abortedByExitAll } = await this.withApplyFlowCache(cacheKey, execute);
|
|
436
452
|
try {
|
|
437
453
|
await ((_c = model.onDispatchEventEnd) == null ? void 0 : _c.call(model, eventName, options, inputArgs, result));
|
|
438
454
|
} catch (hookErr) {
|
|
@@ -440,8 +456,15 @@ const _FlowExecutor = class _FlowExecutor {
|
|
|
440
456
|
}
|
|
441
457
|
await this.emitModelEventIf(eventName, "end", {
|
|
442
458
|
...eventBasePayload,
|
|
443
|
-
result
|
|
459
|
+
result,
|
|
460
|
+
...abortedByExitAll ? { aborted: true } : {}
|
|
444
461
|
});
|
|
462
|
+
if (result && typeof result === "object") {
|
|
463
|
+
Object.defineProperty(result, "__abortedByExitAll", {
|
|
464
|
+
value: abortedByExitAll,
|
|
465
|
+
configurable: true
|
|
466
|
+
});
|
|
467
|
+
}
|
|
445
468
|
return result;
|
|
446
469
|
} catch (error) {
|
|
447
470
|
try {
|
package/lib/flowContext.d.ts
CHANGED
|
@@ -325,8 +325,10 @@ export declare class FlowContext {
|
|
|
325
325
|
getPropertyOptions(key: string): PropertyOptions | undefined;
|
|
326
326
|
}
|
|
327
327
|
declare class BaseFlowEngineContext extends FlowContext {
|
|
328
|
+
t: (key: any, options?: any) => string;
|
|
328
329
|
router: Router;
|
|
329
330
|
dataSourceManager: DataSourceManager;
|
|
331
|
+
isDarkTheme: boolean;
|
|
330
332
|
requireAsync: (url: string) => Promise<any>;
|
|
331
333
|
importAsync: (url: string) => Promise<any>;
|
|
332
334
|
createJSRunner: (options?: JSRunnerOptions) => Promise<JSRunner>;
|
package/lib/flowContext.js
CHANGED
|
@@ -57,6 +57,7 @@ __export(flowContext_exports, {
|
|
|
57
57
|
});
|
|
58
58
|
module.exports = __toCommonJS(flowContext_exports);
|
|
59
59
|
var import_reactive = require("@formily/reactive");
|
|
60
|
+
var import_axios = __toESM(require("axios"));
|
|
60
61
|
var antd = __toESM(require("antd"));
|
|
61
62
|
var import_lodash = __toESM(require("lodash"));
|
|
62
63
|
var import_qs = __toESM(require("qs"));
|
|
@@ -81,6 +82,28 @@ var import_dayjs = __toESM(require("dayjs"));
|
|
|
81
82
|
var import_runjsLibs = require("./runjsLibs");
|
|
82
83
|
var import_runjsModuleLoader = require("./utils/runjsModuleLoader");
|
|
83
84
|
var _proxy, _FlowContext_instances, createChildNodes_fn, findMetaByPath_fn, findMetaInDelegatesDeep_fn, findMetaInProperty_fn, resolvePathInMeta_fn, resolvePathInMetaAsync_fn, buildParentTitles_fn, toTreeNode_fn;
|
|
85
|
+
function normalizePathname(pathname) {
|
|
86
|
+
return pathname.endsWith("/") ? pathname : `${pathname}/`;
|
|
87
|
+
}
|
|
88
|
+
__name(normalizePathname, "normalizePathname");
|
|
89
|
+
function shouldBypassApiClient(url, app) {
|
|
90
|
+
try {
|
|
91
|
+
const requestUrl = new URL(url);
|
|
92
|
+
if (!["http:", "https:"].includes(requestUrl.protocol)) {
|
|
93
|
+
return false;
|
|
94
|
+
}
|
|
95
|
+
if (!(app == null ? void 0 : app.getApiUrl)) {
|
|
96
|
+
return true;
|
|
97
|
+
}
|
|
98
|
+
const apiUrl = new URL(app.getApiUrl());
|
|
99
|
+
const apiPath = normalizePathname(apiUrl.pathname);
|
|
100
|
+
const requestPath = normalizePathname(requestUrl.pathname);
|
|
101
|
+
return requestUrl.origin !== apiUrl.origin || !requestPath.startsWith(apiPath);
|
|
102
|
+
} catch {
|
|
103
|
+
return false;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
__name(shouldBypassApiClient, "shouldBypassApiClient");
|
|
84
107
|
function isRecordRefLike(val) {
|
|
85
108
|
return !!(val && typeof val === "object" && "collection" in val && "filterByTk" in val);
|
|
86
109
|
}
|
|
@@ -2211,6 +2234,10 @@ const _BaseFlowEngineContext = class _BaseFlowEngineContext extends FlowContext
|
|
|
2211
2234
|
return this.engine.getModel(modelName, searchInPreviousEngines);
|
|
2212
2235
|
});
|
|
2213
2236
|
this.defineMethod("request", (options) => {
|
|
2237
|
+
const app = this.app;
|
|
2238
|
+
if (typeof (options == null ? void 0 : options.url) === "string" && shouldBypassApiClient(options.url, app)) {
|
|
2239
|
+
return import_axios.default.request(options);
|
|
2240
|
+
}
|
|
2214
2241
|
return this.api.request(options);
|
|
2215
2242
|
});
|
|
2216
2243
|
this.defineMethod(
|
|
@@ -2222,7 +2249,10 @@ const _BaseFlowEngineContext = class _BaseFlowEngineContext extends FlowContext
|
|
|
2222
2249
|
...runnerOptions || {},
|
|
2223
2250
|
globals: mergedGlobals
|
|
2224
2251
|
});
|
|
2225
|
-
const shouldPreprocessTemplates =
|
|
2252
|
+
const shouldPreprocessTemplates = (0, import_JSRunner.shouldPreprocessRunJSTemplates)({
|
|
2253
|
+
version: runnerOptions == null ? void 0 : runnerOptions.version,
|
|
2254
|
+
preprocessTemplates
|
|
2255
|
+
});
|
|
2226
2256
|
const jsCode = await (0, import_utils.prepareRunJsCode)(String(code ?? ""), { preprocessTemplates: shouldPreprocessTemplates });
|
|
2227
2257
|
return runner.run(jsCode);
|
|
2228
2258
|
}
|