@nocobase/flow-engine
Version:
A standalone flow engine for NocoBase, managing workflows, models, and actions.
96 lines (94 loc) • 3.56 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 GlobalFlowRegistry_exports = {};
__export(GlobalFlowRegistry_exports, {
GlobalFlowRegistry: () => GlobalFlowRegistry
});
module.exports = __toCommonJS(GlobalFlowRegistry_exports);
var import_models = require("../models");
var import_BaseFlowRegistry = require("./BaseFlowRegistry");
const _GlobalFlowRegistry = class _GlobalFlowRegistry extends import_BaseFlowRegistry.BaseFlowRegistry {
constructor(target) {
super();
this.target = target;
}
removeFlow(flowKey) {
console.warn(`GlobalFlowRegistry.removeFlow: removing static flow '${flowKey}' is not supported.`);
}
getFlow(flowKey) {
if (this.flows.has(flowKey)) {
return this.flows.get(flowKey);
}
const proto = Object.getPrototypeOf(this.target);
if (proto !== Function.prototype && proto !== Object.prototype && (proto == null ? void 0 : proto.globalFlowRegistry)) {
return proto.globalFlowRegistry.getFlow(flowKey);
}
return void 0;
}
getFlows() {
const flows = new Map(this.flows);
const proto = Object.getPrototypeOf(this.target);
if (proto !== Function.prototype && proto !== Object.prototype && (proto == null ? void 0 : proto.globalFlowRegistry)) {
for (const [key, def] of proto.globalFlowRegistry.getFlows().entries()) {
if (!flows.has(key)) {
flows.set(key, def);
}
}
}
const getClassDepth = /* @__PURE__ */ __name((klass) => {
let depth = 0;
let cur = klass;
while (cur && cur !== import_models.FlowModel && cur !== Function.prototype && cur !== Object.prototype) {
cur = Object.getPrototypeOf(cur);
depth += 1;
}
return depth;
}, "getClassDepth");
const sortedEntries = Array.from(flows.entries()).sort(([, a], [, b]) => {
const sa = a.sort ?? 0;
const sb = b.sort ?? 0;
if (sa !== sb) return sa - sb;
const ra = a["flowRegistry"];
const rb = b["flowRegistry"];
const da = getClassDepth(ra["target"]);
const db = getClassDepth(rb["target"]);
if (da !== db) return da - db;
return 0;
});
return new Map(sortedEntries);
}
saveFlow(flow) {
}
destroyFlow(flowKey) {
}
};
__name(_GlobalFlowRegistry, "GlobalFlowRegistry");
let GlobalFlowRegistry = _GlobalFlowRegistry;
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
GlobalFlowRegistry
});