@nocobase/flow-engine
Version:
A standalone flow engine for NocoBase, managing workflows, models, and actions.
94 lines (92 loc) • 4.41 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 __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
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 __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
var registry_exports = {};
__export(registry_exports, {
RunJSContextRegistry: () => RunJSContextRegistry,
getModelClassName: () => getModelClassName
});
module.exports = __toCommonJS(registry_exports);
var import_FlowRunJSContext = require("./contexts/FlowRunJSContext");
var import_JSBlockRunJSContext = require("./contexts/JSBlockRunJSContext");
var import_JSFieldRunJSContext = require("./contexts/JSFieldRunJSContext");
var import_JSItemRunJSContext = require("./contexts/JSItemRunJSContext");
var import_FormJSFieldItemRunJSContext = require("./contexts/FormJSFieldItemRunJSContext");
var import_JSRecordActionRunJSContext = require("./contexts/JSRecordActionRunJSContext");
var import_JSCollectionActionRunJSContext = require("./contexts/JSCollectionActionRunJSContext");
const _RunJSContextRegistry = class _RunJSContextRegistry {
static ensureDefaults() {
if (this.defaultsRegistered) return;
const v = "v1";
try {
const ensure = /* @__PURE__ */ __name((model, ctor) => {
const key = `${v}:${model}`;
if (!this.map.has(key)) this.map.set(key, ctor);
}, "ensure");
ensure("JSBlockModel", import_JSBlockRunJSContext.JSBlockRunJSContext);
ensure("JSFieldModel", import_JSFieldRunJSContext.JSFieldRunJSContext);
ensure("JSItemModel", import_JSItemRunJSContext.JSItemRunJSContext);
ensure("FormJSFieldItemModel", import_FormJSFieldItemRunJSContext.FormJSFieldItemRunJSContext);
ensure("JSRecordActionModel", import_JSRecordActionRunJSContext.JSRecordActionRunJSContext);
ensure("JSCollectionActionModel", import_JSCollectionActionRunJSContext.JSCollectionActionRunJSContext);
ensure("*", import_FlowRunJSContext.FlowRunJSContext);
} finally {
this.defaultsRegistered = true;
}
}
static register(version, modelClass, ctor) {
this.map.set(`${version}:${modelClass}`, ctor);
}
static resolve(version, modelClass) {
this.ensureDefaults();
return this.map.get(`${version}:${modelClass}`) || this.map.get(`${version}:*`);
}
};
__name(_RunJSContextRegistry, "RunJSContextRegistry");
__publicField(_RunJSContextRegistry, "map", /* @__PURE__ */ new Map());
__publicField(_RunJSContextRegistry, "defaultsRegistered", false);
let RunJSContextRegistry = _RunJSContextRegistry;
function getModelClassName(ctx) {
var _a, _b, _c;
const model = ctx == null ? void 0 : ctx.model;
if (!model) return "*";
try {
const Ctor = model.constructor;
const use = (_b = (_a = Ctor == null ? void 0 : Ctor.meta) == null ? void 0 : _a.createModelOptions) == null ? void 0 : _b.use;
if (typeof use === "string" && use) return use;
} catch (_) {
}
const byName = (_c = model == null ? void 0 : model.constructor) == null ? void 0 : _c.name;
return byName || "*";
}
__name(getModelClassName, "getModelClassName");
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
RunJSContextRegistry,
getModelClassName
});