UNPKG

@nocobase/flow-engine

Version:

A standalone flow engine for NocoBase, managing workflows, models, and actions.

107 lines (105 loc) 4.04 kB
/** * 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 serverContextParams_exports = {}; __export(serverContextParams_exports, { buildServerContextParams: () => buildServerContextParams }); module.exports = __toCommonJS(serverContextParams_exports); function pickDefined(obj) { const out = {}; Object.entries(obj || {}).forEach(([k, v]) => { if (typeof v !== "undefined" && v !== null) out[k] = v; }); return out; } __name(pickDefined, "pickDefined"); function resolvePrimaryKey(ctx, dataSourceKey, collection) { var _a, _b, _c, _d, _e; try { const ds = (_b = (_a = ctx.dataSourceManager) == null ? void 0 : _a.getDataSource) == null ? void 0 : _b.call(_a, dataSourceKey || "main"); const col = (_d = (_c = ds == null ? void 0 : ds.collectionManager) == null ? void 0 : _c.getCollection) == null ? void 0 : _d.call(_c, collection); const pk = (_e = col == null ? void 0 : col.getPrimaryKey) == null ? void 0 : _e.call(col); return pk || "id"; } catch (e) { return "id"; } } __name(resolvePrimaryKey, "resolvePrimaryKey"); function normalizeOne(ctx, ref) { var _a, _b; if (!ref) return void 0; const dataSourceKey = ref.dataSourceKey || "main"; const collection = ref.collection || ((_a = ref.record) == null ? void 0 : _a.__collectionName); if (!collection) return void 0; const pk = resolvePrimaryKey(ctx, dataSourceKey, collection) || "id"; const filterByTk = typeof ref.filterByTk !== "undefined" ? ref.filterByTk : typeof ref.id !== "undefined" ? ref.id : (_b = ref.record) == null ? void 0 : _b[pk]; if (typeof filterByTk === "undefined") return void 0; return pickDefined({ collection, filterByTk, dataSourceKey, fields: ref.fields, appends: ref.appends }); } __name(normalizeOne, "normalizeOne"); function buildServerContextParams(ctx, input = {}) { const isRecordRef = /* @__PURE__ */ __name((val) => { if (!val || typeof val !== "object") return false; return typeof val.collection === "string" && (typeof val.filterByTk !== "undefined" || typeof val.id !== "undefined" || val.record); }, "isRecordRef"); const out = {}; const visit = /* @__PURE__ */ __name((src, path) => { if (isRecordRef(src)) { const norm = normalizeOne(ctx, src); if (norm) { const key = path.join("."); out[key] = norm; } return; } if (Array.isArray(src)) { for (let i = 0; i < src.length; i++) { visit(src[i], [...path, String(i)]); } return; } if (src && typeof src === "object") { for (const [k, v] of Object.entries(src)) { visit(v, [...path, k]); } return; } }, "visit"); visit(input, []); return Object.keys(out).length ? out : void 0; } __name(buildServerContextParams, "buildServerContextParams"); // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = { buildServerContextParams });