MCPcopy Create free account
hub / github.com/ModelEngine-Group/app-platform / createGraphOperator

Function createGraphOperator

frontend/src/shared/utils/common.ts:496–574  ·  view source on GitHub ↗
(graphString: string)

Source from the content-addressed store, hash-verified

494 * @return {{}} 画布操纵器对象
495 */
496export const createGraphOperator = (graphString: string) => {
497 const graph = JSON.parse(graphString);
498 const shapes = graph.pages[0].shapes;
499
500 const getInputParams = (shape: any) => {
501 if (shape.type === 'startNodeStart') {
502 return shape.flowMeta.inputParams;
503 } else if (shape.type === 'endNodeEnd') {
504 return shape.flowMeta.callback.converter.entity.inputParams;
505 } else {
506 return shape.flowMeta.jober.converter.entity.inputParams;
507 }
508 };
509
510 const getConfigByKeys = (keys: string[]) => {
511 if (!Array.isArray(keys)) {
512 throw new Error('Expected keys to be an array');
513 }
514
515 if (keys.length === 0) {
516 return null;
517 }
518
519 const tmpKeys = [...keys];
520 const shapeId = tmpKeys.shift();
521 const shape = getShapeById(shapeId);
522 const inputParams = getInputParams(shape);
523 if (!inputParams) {
524 throw new Error('Expected inputParams exists');
525 }
526 let config = {type: DATA_TYPES.OBJECT, value: inputParams};
527 while (tmpKeys.length > 0 && config && config.value) {
528 const key = tmpKeys.shift();
529 config = config.value.find(v => v.name === key);
530 }
531 return config;
532 };
533
534 const getShapeById = (shapeId: string) => {
535 return shapes.find((shape) => shape.id === shapeId);
536 };
537
538 return {
539 /**
540 * 获取配置信息
541 * @param keys 键值数组
542 * @return {{}|*|null} 配置信息
543 */
544 getConfig: (keys: string[]) => {
545 const config = getConfigByKeys(keys);
546 return config ? configToStruct(config) : null;
547 },
548
549 /**
550 * 获取画布中开始节点的入参信息
551 * @return {array} 开始节点入参信息
552 */
553 getStartNodeInputParams: (): any[] => {

Callers 3

findConfigValueFunction · 0.70
getConfigurationFunction · 0.70
getAppConfigFunction · 0.70

Calls 5

getConfigByKeysFunction · 0.70
configToStructFunction · 0.70
parseMethod · 0.65
mapMethod · 0.65
filterMethod · 0.45

Tested by

no test coverage detected