@nocobase/flow-engine 2.1.0-alpha.3 → 2.1.0-alpha.31
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/FormItem.d.ts +6 -0
- package/lib/components/FormItem.js +11 -3
- package/lib/components/MobilePopup.js +6 -5
- package/lib/components/dnd/gridDragPlanner.d.ts +59 -2
- package/lib/components/dnd/gridDragPlanner.js +613 -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 +75 -0
- package/lib/data-source/index.js +246 -4
- 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/FormItem.tsx +7 -1
- package/src/components/MobilePopup.tsx +4 -2
- package/src/components/__tests__/FlowModelRenderer.test.tsx +65 -2
- package/src/components/__tests__/FormItem.test.tsx +25 -0
- 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 +558 -3
- package/src/components/dnd/__tests__/DndProvider.test.tsx +98 -0
- package/src/components/dnd/gridDragPlanner.ts +758 -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__/collection.test.ts +41 -2
- package/src/data-source/__tests__/index.test.ts +68 -1
- package/src/data-source/index.ts +303 -5
- 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
|
@@ -42,6 +42,7 @@ __export(data_source_exports, {
|
|
|
42
42
|
CollectionManager: () => CollectionManager,
|
|
43
43
|
DataSource: () => DataSource,
|
|
44
44
|
DataSourceManager: () => DataSourceManager,
|
|
45
|
+
getCollectionFieldInterface: () => getCollectionFieldInterface,
|
|
45
46
|
isFieldInterfaceMatch: () => isFieldInterfaceMatch,
|
|
46
47
|
jioToJoiSchema: () => import_jioToJoiSchema.jioToJoiSchema
|
|
47
48
|
});
|
|
@@ -53,12 +54,47 @@ var import_sortCollectionsByInherits = require("./sortCollectionsByInherits");
|
|
|
53
54
|
const _DataSourceManager = class _DataSourceManager {
|
|
54
55
|
dataSources;
|
|
55
56
|
flowEngine;
|
|
57
|
+
requester;
|
|
58
|
+
collectionFieldInterfaceManager;
|
|
59
|
+
loaders = /* @__PURE__ */ new Map();
|
|
60
|
+
loadedKeys = /* @__PURE__ */ new Set();
|
|
61
|
+
loadingKeys = /* @__PURE__ */ new Set();
|
|
62
|
+
loadErrors = /* @__PURE__ */ new Map();
|
|
63
|
+
loadingPromise = null;
|
|
56
64
|
constructor() {
|
|
57
65
|
this.dataSources = import_reactive.observable.shallow(/* @__PURE__ */ new Map());
|
|
58
66
|
}
|
|
59
67
|
setFlowEngine(flowEngine) {
|
|
60
68
|
this.flowEngine = flowEngine;
|
|
61
69
|
}
|
|
70
|
+
setRequester(requester) {
|
|
71
|
+
this.requester = requester;
|
|
72
|
+
}
|
|
73
|
+
setCollectionFieldInterfaceManager(manager) {
|
|
74
|
+
this.collectionFieldInterfaceManager = manager;
|
|
75
|
+
}
|
|
76
|
+
addFieldInterfaces(fieldInterfaceClasses = []) {
|
|
77
|
+
var _a, _b;
|
|
78
|
+
(_b = (_a = this.collectionFieldInterfaceManager) == null ? void 0 : _a.addFieldInterfaces) == null ? void 0 : _b.call(_a, fieldInterfaceClasses);
|
|
79
|
+
}
|
|
80
|
+
addFieldInterfaceGroups(groups) {
|
|
81
|
+
var _a, _b;
|
|
82
|
+
(_b = (_a = this.collectionFieldInterfaceManager) == null ? void 0 : _a.addFieldInterfaceGroups) == null ? void 0 : _b.call(_a, groups);
|
|
83
|
+
}
|
|
84
|
+
addFieldInterfaceComponentOption(name, option) {
|
|
85
|
+
var _a, _b;
|
|
86
|
+
(_b = (_a = this.collectionFieldInterfaceManager) == null ? void 0 : _a.addFieldInterfaceComponentOption) == null ? void 0 : _b.call(_a, name, option);
|
|
87
|
+
}
|
|
88
|
+
addFieldInterfaceOperator(name, operator) {
|
|
89
|
+
var _a, _b;
|
|
90
|
+
(_b = (_a = this.collectionFieldInterfaceManager) == null ? void 0 : _a.addFieldInterfaceOperator) == null ? void 0 : _b.call(_a, name, operator);
|
|
91
|
+
}
|
|
92
|
+
registerLoader(key, loader) {
|
|
93
|
+
this.loaders.set(key, loader);
|
|
94
|
+
}
|
|
95
|
+
removeLoader(key) {
|
|
96
|
+
this.loaders.delete(key);
|
|
97
|
+
}
|
|
62
98
|
addDataSource(ds) {
|
|
63
99
|
if (this.dataSources.has(ds.key)) {
|
|
64
100
|
throw new Error(`DataSource with name ${ds.key} already exists`);
|
|
@@ -75,7 +111,7 @@ const _DataSourceManager = class _DataSourceManager {
|
|
|
75
111
|
upsertDataSource(ds) {
|
|
76
112
|
var _a;
|
|
77
113
|
if (this.dataSources.has(ds.key)) {
|
|
78
|
-
(_a = this.dataSources.get(ds.key)) == null ? void 0 : _a.
|
|
114
|
+
(_a = this.dataSources.get(ds.key)) == null ? void 0 : _a.patchOptions(ds);
|
|
79
115
|
} else {
|
|
80
116
|
this.addDataSource(ds);
|
|
81
117
|
}
|
|
@@ -103,9 +139,161 @@ const _DataSourceManager = class _DataSourceManager {
|
|
|
103
139
|
if (!ds) return void 0;
|
|
104
140
|
return ds.getCollectionField(otherKeys.join("."));
|
|
105
141
|
}
|
|
142
|
+
async ensureLoaded(options = {}) {
|
|
143
|
+
const { force = false } = options;
|
|
144
|
+
const keys = this.resolveLoadKeys(options.keys);
|
|
145
|
+
const pendingKeys = force ? keys : keys.filter((key) => !this.loadedKeys.has(key));
|
|
146
|
+
if (!pendingKeys.length) {
|
|
147
|
+
return;
|
|
148
|
+
}
|
|
149
|
+
if (this.loadingPromise) {
|
|
150
|
+
return this.loadingPromise;
|
|
151
|
+
}
|
|
152
|
+
this.loadingPromise = (async () => {
|
|
153
|
+
try {
|
|
154
|
+
for (const key of pendingKeys) {
|
|
155
|
+
await this.loadKey(key, { initial: !this.loadedKeys.has(key), force });
|
|
156
|
+
}
|
|
157
|
+
} finally {
|
|
158
|
+
this.loadingPromise = null;
|
|
159
|
+
}
|
|
160
|
+
})();
|
|
161
|
+
return this.loadingPromise;
|
|
162
|
+
}
|
|
163
|
+
async reload(options = {}) {
|
|
164
|
+
const keys = this.resolveLoadKeys(options.keys);
|
|
165
|
+
if (!keys.length) {
|
|
166
|
+
return;
|
|
167
|
+
}
|
|
168
|
+
if (this.loadingPromise) {
|
|
169
|
+
return this.loadingPromise;
|
|
170
|
+
}
|
|
171
|
+
this.loadingPromise = (async () => {
|
|
172
|
+
try {
|
|
173
|
+
for (const key of keys) {
|
|
174
|
+
await this.loadKey(key, { initial: false, force: true });
|
|
175
|
+
}
|
|
176
|
+
} finally {
|
|
177
|
+
this.loadingPromise = null;
|
|
178
|
+
}
|
|
179
|
+
})();
|
|
180
|
+
return this.loadingPromise;
|
|
181
|
+
}
|
|
182
|
+
async reloadDataSource(key) {
|
|
183
|
+
if (this.loadingKeys.has(key) && this.loadingPromise) {
|
|
184
|
+
return this.loadingPromise;
|
|
185
|
+
}
|
|
186
|
+
if (!this.loaders.has(key) && this.loaders.has("*")) {
|
|
187
|
+
return this.reload({ keys: ["*"] });
|
|
188
|
+
}
|
|
189
|
+
return this.reload({ keys: [key] });
|
|
190
|
+
}
|
|
191
|
+
resolveLoadKeys(requestedKeys) {
|
|
192
|
+
const normalizedKeys = (requestedKeys == null ? void 0 : requestedKeys.length) ? requestedKeys : ["main"];
|
|
193
|
+
const explicitKeys = normalizedKeys.filter((key) => this.loaders.has(key));
|
|
194
|
+
if (this.loaders.has("*")) {
|
|
195
|
+
return import_lodash.default.uniq(["*", ...explicitKeys]);
|
|
196
|
+
}
|
|
197
|
+
return explicitKeys.length ? explicitKeys : normalizedKeys;
|
|
198
|
+
}
|
|
199
|
+
getApp() {
|
|
200
|
+
var _a, _b;
|
|
201
|
+
return (_b = (_a = this.flowEngine) == null ? void 0 : _a.context) == null ? void 0 : _b.app;
|
|
202
|
+
}
|
|
203
|
+
dispatchDataSourceEvent(type, detail) {
|
|
204
|
+
var _a, _b;
|
|
205
|
+
(_b = (_a = this.getApp()) == null ? void 0 : _a.eventBus) == null ? void 0 : _b.dispatchEvent(new CustomEvent(type, { detail }));
|
|
206
|
+
}
|
|
207
|
+
setDataSourceState(key, options) {
|
|
208
|
+
const dataSource = this.getDataSource(key);
|
|
209
|
+
if (!dataSource) {
|
|
210
|
+
return;
|
|
211
|
+
}
|
|
212
|
+
dataSource.patchOptions(options);
|
|
213
|
+
}
|
|
214
|
+
applyDataSourceLoadResult(key, result) {
|
|
215
|
+
if (key === "*") {
|
|
216
|
+
const dataSources = (result == null ? void 0 : result.dataSources) || [];
|
|
217
|
+
dataSources.forEach((dataSourceOptions) => {
|
|
218
|
+
var _a;
|
|
219
|
+
const { collections, ...dataSource2 } = dataSourceOptions;
|
|
220
|
+
this.upsertDataSource(dataSource2);
|
|
221
|
+
if (collections) {
|
|
222
|
+
(_a = this.getDataSource(dataSource2.key)) == null ? void 0 : _a.setCollections(collections, { clearFields: true });
|
|
223
|
+
}
|
|
224
|
+
});
|
|
225
|
+
return;
|
|
226
|
+
}
|
|
227
|
+
const dataSource = this.getDataSource(key);
|
|
228
|
+
if (!dataSource) {
|
|
229
|
+
return;
|
|
230
|
+
}
|
|
231
|
+
dataSource.setCollections((result == null ? void 0 : result.collections) || [], { clearFields: true });
|
|
232
|
+
}
|
|
233
|
+
async loadKey(key, options) {
|
|
234
|
+
const loader = this.loaders.get(key);
|
|
235
|
+
if (!loader) {
|
|
236
|
+
return;
|
|
237
|
+
}
|
|
238
|
+
if (!this.getDataSource(key) && key !== "*") {
|
|
239
|
+
this.addDataSource({ key });
|
|
240
|
+
}
|
|
241
|
+
const { initial } = options;
|
|
242
|
+
this.loadingKeys.add(key);
|
|
243
|
+
if (key !== "*") {
|
|
244
|
+
this.setDataSourceState(key, {
|
|
245
|
+
status: initial ? "loading" : "reloading",
|
|
246
|
+
errorMessage: void 0
|
|
247
|
+
});
|
|
248
|
+
}
|
|
249
|
+
this.loadErrors.set(key, null);
|
|
250
|
+
try {
|
|
251
|
+
const result = await loader({ key, manager: this }) || {};
|
|
252
|
+
this.applyDataSourceLoadResult(key, result);
|
|
253
|
+
this.loadedKeys.add(key);
|
|
254
|
+
if (key !== "*") {
|
|
255
|
+
this.setDataSourceState(key, {
|
|
256
|
+
status: "loaded",
|
|
257
|
+
errorMessage: void 0
|
|
258
|
+
});
|
|
259
|
+
}
|
|
260
|
+
this.dispatchDataSourceEvent("dataSource:loaded", { dataSourceKey: key, initial });
|
|
261
|
+
} catch (error) {
|
|
262
|
+
const normalizedError = error instanceof Error ? error : new Error(String(error));
|
|
263
|
+
this.loadErrors.set(key, normalizedError);
|
|
264
|
+
if (key !== "*") {
|
|
265
|
+
this.setDataSourceState(key, {
|
|
266
|
+
status: initial ? "loading-failed" : "reloading-failed",
|
|
267
|
+
errorMessage: normalizedError.message
|
|
268
|
+
});
|
|
269
|
+
}
|
|
270
|
+
this.dispatchDataSourceEvent("dataSource:loadFailed", {
|
|
271
|
+
dataSourceKey: key,
|
|
272
|
+
initial,
|
|
273
|
+
error: normalizedError
|
|
274
|
+
});
|
|
275
|
+
throw normalizedError;
|
|
276
|
+
} finally {
|
|
277
|
+
this.loadingKeys.delete(key);
|
|
278
|
+
}
|
|
279
|
+
}
|
|
106
280
|
};
|
|
107
281
|
__name(_DataSourceManager, "DataSourceManager");
|
|
108
282
|
let DataSourceManager = _DataSourceManager;
|
|
283
|
+
function getCollectionFieldInterface(interfaceName, ...dataSourceManagers) {
|
|
284
|
+
if (!interfaceName) {
|
|
285
|
+
return void 0;
|
|
286
|
+
}
|
|
287
|
+
for (const dataSourceManager of dataSourceManagers) {
|
|
288
|
+
const collectionFieldInterfaceManager = dataSourceManager == null ? void 0 : dataSourceManager.collectionFieldInterfaceManager;
|
|
289
|
+
const getFieldInterface = collectionFieldInterfaceManager == null ? void 0 : collectionFieldInterfaceManager.getFieldInterface;
|
|
290
|
+
if (typeof getFieldInterface === "function") {
|
|
291
|
+
return getFieldInterface.call(collectionFieldInterfaceManager, interfaceName);
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
return void 0;
|
|
295
|
+
}
|
|
296
|
+
__name(getCollectionFieldInterface, "getCollectionFieldInterface");
|
|
109
297
|
const _DataSource = class _DataSource {
|
|
110
298
|
dataSourceManager;
|
|
111
299
|
collectionManager;
|
|
@@ -126,6 +314,12 @@ const _DataSource = class _DataSource {
|
|
|
126
314
|
get name() {
|
|
127
315
|
return this.options.key;
|
|
128
316
|
}
|
|
317
|
+
get status() {
|
|
318
|
+
return this.options.status;
|
|
319
|
+
}
|
|
320
|
+
get errorMessage() {
|
|
321
|
+
return this.options.errorMessage;
|
|
322
|
+
}
|
|
129
323
|
setDataSourceManager(dataSourceManager) {
|
|
130
324
|
this.dataSourceManager = dataSourceManager;
|
|
131
325
|
}
|
|
@@ -156,6 +350,9 @@ const _DataSource = class _DataSource {
|
|
|
156
350
|
upsertCollections(collections, options = {}) {
|
|
157
351
|
return this.collectionManager.upsertCollections(collections, options);
|
|
158
352
|
}
|
|
353
|
+
setCollections(collections, options = {}) {
|
|
354
|
+
return this.collectionManager.setCollections(collections, options);
|
|
355
|
+
}
|
|
159
356
|
removeCollection(name) {
|
|
160
357
|
return this.collectionManager.removeCollection(name);
|
|
161
358
|
}
|
|
@@ -166,6 +363,12 @@ const _DataSource = class _DataSource {
|
|
|
166
363
|
Object.keys(this.options).forEach((key) => delete this.options[key]);
|
|
167
364
|
Object.assign(this.options, newOptions);
|
|
168
365
|
}
|
|
366
|
+
patchOptions(newOptions = {}) {
|
|
367
|
+
Object.assign(this.options, newOptions);
|
|
368
|
+
}
|
|
369
|
+
reload() {
|
|
370
|
+
return this.dataSourceManager.reloadDataSource(this.key);
|
|
371
|
+
}
|
|
169
372
|
getCollectionField(fieldPath) {
|
|
170
373
|
const [collectionName, ...otherKeys] = fieldPath.split(".");
|
|
171
374
|
const fieldName = otherKeys.join(".");
|
|
@@ -190,6 +393,10 @@ const _CollectionManager = class _CollectionManager {
|
|
|
190
393
|
collections;
|
|
191
394
|
allCollectionsInheritChain;
|
|
192
395
|
childrenCollectionsName = {};
|
|
396
|
+
resetCaches() {
|
|
397
|
+
this.childrenCollectionsName = {};
|
|
398
|
+
this.allCollectionsInheritChain = void 0;
|
|
399
|
+
}
|
|
193
400
|
get flowEngine() {
|
|
194
401
|
return this.dataSource.flowEngine;
|
|
195
402
|
}
|
|
@@ -203,9 +410,11 @@ const _CollectionManager = class _CollectionManager {
|
|
|
203
410
|
col.setDataSource(this.dataSource);
|
|
204
411
|
col.initInherits();
|
|
205
412
|
this.collections.set(col.name, col);
|
|
413
|
+
this.resetCaches();
|
|
206
414
|
}
|
|
207
415
|
removeCollection(name) {
|
|
208
416
|
this.collections.delete(name);
|
|
417
|
+
this.resetCaches();
|
|
209
418
|
}
|
|
210
419
|
updateCollection(newOptions, options = {}) {
|
|
211
420
|
const collection = this.getCollection(newOptions.name);
|
|
@@ -213,6 +422,7 @@ const _CollectionManager = class _CollectionManager {
|
|
|
213
422
|
throw new Error(`Collection ${newOptions.name} not found`);
|
|
214
423
|
}
|
|
215
424
|
collection.setOptions(newOptions, options);
|
|
425
|
+
this.resetCaches();
|
|
216
426
|
}
|
|
217
427
|
upsertCollection(options) {
|
|
218
428
|
if (this.collections.has(options.name)) {
|
|
@@ -230,6 +440,11 @@ const _CollectionManager = class _CollectionManager {
|
|
|
230
440
|
this.addCollection(collection);
|
|
231
441
|
}
|
|
232
442
|
}
|
|
443
|
+
this.resetCaches();
|
|
444
|
+
}
|
|
445
|
+
setCollections(collections, options = {}) {
|
|
446
|
+
this.clearCollections();
|
|
447
|
+
this.upsertCollections(collections, options);
|
|
233
448
|
}
|
|
234
449
|
sortCollectionsByInherits(collections) {
|
|
235
450
|
const map = /* @__PURE__ */ new Map();
|
|
@@ -293,6 +508,7 @@ const _CollectionManager = class _CollectionManager {
|
|
|
293
508
|
}
|
|
294
509
|
clearCollections() {
|
|
295
510
|
this.collections.clear();
|
|
511
|
+
this.resetCaches();
|
|
296
512
|
}
|
|
297
513
|
getAssociation(associationName) {
|
|
298
514
|
const [collectionName, fieldName] = associationName.split(".");
|
|
@@ -461,6 +677,12 @@ const _Collection = class _Collection {
|
|
|
461
677
|
}
|
|
462
678
|
get titleCollectionField() {
|
|
463
679
|
const titleFieldName = this.options.titleField || this.filterTargetKey;
|
|
680
|
+
if (Array.isArray(titleFieldName)) {
|
|
681
|
+
if (titleFieldName.length !== 1) {
|
|
682
|
+
return void 0;
|
|
683
|
+
}
|
|
684
|
+
return this.getField(titleFieldName[0]);
|
|
685
|
+
}
|
|
464
686
|
const titleCollectionField = this.getField(titleFieldName);
|
|
465
687
|
return titleCollectionField;
|
|
466
688
|
}
|
|
@@ -487,6 +709,9 @@ const _Collection = class _Collection {
|
|
|
487
709
|
}
|
|
488
710
|
this.upsertFields(this.options.fields || []);
|
|
489
711
|
}
|
|
712
|
+
setOption(key, value) {
|
|
713
|
+
this.options[key] = value;
|
|
714
|
+
}
|
|
490
715
|
getFields() {
|
|
491
716
|
const fieldMap = /* @__PURE__ */ new Map();
|
|
492
717
|
for (const inherit of this.inherits.values()) {
|
|
@@ -772,7 +997,17 @@ const _CollectionField = class _CollectionField {
|
|
|
772
997
|
abortEarly: false
|
|
773
998
|
});
|
|
774
999
|
if (error) {
|
|
775
|
-
const message = error.details.map((d) =>
|
|
1000
|
+
const message = error.details.map((d) => {
|
|
1001
|
+
const translated = this.flowEngine.translate(d.type, {
|
|
1002
|
+
...d.context,
|
|
1003
|
+
ns: "data-source-main",
|
|
1004
|
+
label
|
|
1005
|
+
});
|
|
1006
|
+
if (translated && translated !== d.type) {
|
|
1007
|
+
return translated;
|
|
1008
|
+
}
|
|
1009
|
+
return d.message.replace(/"value"/g, `"${label}"`);
|
|
1010
|
+
}).join(", ");
|
|
776
1011
|
return Promise.reject(message);
|
|
777
1012
|
}
|
|
778
1013
|
return Promise.resolve();
|
|
@@ -792,8 +1027,14 @@ const _CollectionField = class _CollectionField {
|
|
|
792
1027
|
return this.targetCollection.getFields();
|
|
793
1028
|
}
|
|
794
1029
|
getInterfaceOptions() {
|
|
795
|
-
|
|
796
|
-
|
|
1030
|
+
var _a, _b, _c;
|
|
1031
|
+
const ctx = this.flowEngine.context;
|
|
1032
|
+
return getCollectionFieldInterface(
|
|
1033
|
+
this.interface,
|
|
1034
|
+
(_b = (_a = this.collection) == null ? void 0 : _a.dataSource) == null ? void 0 : _b.dataSourceManager,
|
|
1035
|
+
ctx.dataSourceManager,
|
|
1036
|
+
(_c = ctx.app) == null ? void 0 : _c.dataSourceManager
|
|
1037
|
+
);
|
|
797
1038
|
}
|
|
798
1039
|
getFilterOperators() {
|
|
799
1040
|
var _a;
|
|
@@ -858,6 +1099,7 @@ __name(isFieldInterfaceMatch, "isFieldInterfaceMatch");
|
|
|
858
1099
|
CollectionManager,
|
|
859
1100
|
DataSource,
|
|
860
1101
|
DataSourceManager,
|
|
1102
|
+
getCollectionFieldInterface,
|
|
861
1103
|
isFieldInterfaceMatch,
|
|
862
1104
|
jioToJoiSchema
|
|
863
1105
|
});
|
|
@@ -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
|
}
|