@nocobase/flow-engine
Version:
A standalone flow engine for NocoBase, managing workflows, models, and actions.
87 lines (85 loc) • 2.79 kB
JavaScript
/**
* This file is part of the NocoBase (R) project.
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
* Authors: NocoBase Team.
*
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
* For more information, please refer to: https://www.nocobase.com/agreement.
*/
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var BaseFlowRegistry_exports = {};
__export(BaseFlowRegistry_exports, {
BaseFlowRegistry: () => BaseFlowRegistry
});
module.exports = __toCommonJS(BaseFlowRegistry_exports);
var import_FlowDefinition = require("../FlowDefinition");
var import_reactive = require("@formily/reactive");
const _BaseFlowRegistry = class _BaseFlowRegistry {
flows;
constructor() {
this.flows = import_reactive.observable.shallow(/* @__PURE__ */ new Map());
}
addFlows(flows) {
for (const [flowKey, flowOptions] of Object.entries(flows || {})) {
this.addFlow(flowKey, flowOptions);
}
}
addFlow(flowKey, flowOptions) {
const flow = new import_FlowDefinition.FlowDefinition(
{
...flowOptions,
key: flowKey
},
this
);
this.flows.set(flowKey, flow);
return flow;
}
hasFlow(flowKey) {
const flow = this.flows.get(flowKey);
return !!flow;
}
getFlow(flowKey) {
return this.flows.get(flowKey);
}
getFlows() {
return this.flows;
}
removeFlow(flowKey) {
this.flows.delete(flowKey);
}
mapFlows(callback) {
const flows = this.getFlows();
return [...flows.values()].map((flow) => callback(flow));
}
moveStep(flowKey, sourceStepKey, targetStepKey) {
const flow = this.getFlow(flowKey);
if (!flow) {
throw new Error(`Flow '${flowKey}' not found`);
}
flow.moveStep(sourceStepKey, targetStepKey);
}
};
__name(_BaseFlowRegistry, "BaseFlowRegistry");
let BaseFlowRegistry = _BaseFlowRegistry;
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
BaseFlowRegistry
});