npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@michael_home/workflow-engine-core

v1.0.3

Published

Workflow engine core library with graph management and routing algorithms

Readme

@workflow-engine/core

核心图表引擎库,提供图数据结构、管理和路由算法。

安装

npm install @workflow-engine/core

基础概念

节点(Node)

工作流中的任务或决策点

interface GraphNode<TData = any> {
  id: string                    // 节点唯一标识
  type: NodeType               // 节点类型
  position: Point              // 节点位置 { x, y }
  size: Size                   // 节点大小 { width, height }
  ports: Port[]                // 端口列表(连接点)
  data?: TData                 // 自定义数据
  selected?: boolean           // 是否选中
}

边(Edge)

节点之间的连接

interface GraphEdge<TData = any> {
  id: string                   // 边唯一标识
  source: Endpoint             // 源端点 { nodeId, portId }
  target: Endpoint             // 目标端点 { nodeId, portId }
  points?: Point[]             // 路由点(曲线路径)
  data?: TData                 // 自定义数据
  selected?: boolean           // 是否选中
}

端口(Port)

节点上的连接点

interface Port {
  id: string                   // 端口唯一标识
  nodeId: string               // 所属节点 ID
  direction: PortDirection     // 方向 (TOP, RIGHT, BOTTOM, LEFT)
  offset?: number              // 偏移量(相对于边界)
}

使用示例

1. 创建图表

import { GraphStore } from '@workflow-engine/core'

const graph = new GraphStore()

// 添加节点
graph.addNode({
  id: 'node1',
  type: 'USER',
  position: { x: 100, y: 100 },
  size: { width: 100, height: 50 },
  ports: [
    { id: 'in', nodeId: 'node1', direction: 'LEFT' },
    { id: 'out', nodeId: 'node1', direction: 'RIGHT' }
  ]
})

// 添加边
graph.addEdge({
  id: 'edge1',
  source: { nodeId: 'node1', portId: 'out' },
  target: { nodeId: 'node2', portId: 'in' }
})

2. 查询图表

// 获取所有节点
const nodes = graph.getNodes()

// 获取单个节点
const node = graph.getNode('node1')

// 查询入边和出边
const incomingEdges = graph.getIncomingEdges('node2')
const outgoingEdges = graph.getOutgoingEdges('node1')

// 查询两节点间的边
const edge = graph.findEdgeBetween('node1', 'node2')

3. 路由(计算边的路径)

import { RouterType } from '@workflow-engine/core'

// 直线路由
graph.routeOneEdge('edge1', RouterType.STRAIGHT)

// 曼哈顿路由(正交、更美观)
graph.routeOneEdge('edge1', RouterType.MANHATTAN)

// 正交路由(高级)
graph.routeOneEdge('edge1', RouterType.ORTHOGONAL)

// 一次路由所有边
graph.routeAllEdges(RouterType.MANHATTAN)

// 节点移动后重新路由相关边
graph.rerouteConnectedEdges('node1', RouterType.MANHATTAN)

4. 移动节点

// 移动节点
graph.moveNode('node1', { x: 200, y: 200 })

// 同时重新路由关联的边
graph.rerouteConnectedEdges('node1', RouterType.MANHATTAN)

5. 删除元素

// 删除节点(自动删除相关的边)
graph.removeNode('node1')

// 删除边
graph.removeEdge('edge1')

// 清空整个图表
graph.clear()

节点类型

type NodeType = 'START'      // 开始节点
              | 'END'        // 结束节点
              | 'USER'       // 用户审批
              | 'SYSTEM'     // 系统处理
              | 'subFlow'    // 子流程
              | 'CONNECTION' // 连接器
              | 'CIRCULATE'  // 抄送

路由算法

| 算法 | 说明 | 适用场景 | |------|------|---------| | STRAIGHT | 直线路由 | 简单拓扑、性能优先 | | MANHATTAN | 曼哈顿路由 | 正交风格、默认推荐 | | ORTHOGONAL | 正交路由 | 复杂拓扑、美观优先 |

API 参考

GraphStore

节点操作

  • addNode(node: GraphNode): void
  • removeNode(nodeId: string): void
  • getNode(nodeId: string): GraphNode | undefined
  • getNodes(): GraphNode[]
  • moveNode(nodeId: string, position: Point): void

边操作

  • addEdge(edge: GraphEdge): void
  • removeEdge(edgeId: string): void
  • getEdge(edgeId: string): GraphEdge | undefined
  • getEdges(): GraphEdge[]

查询操作

  • getIncomingEdges(nodeId: string): GraphEdge[]
  • getOutgoingEdges(nodeId: string): GraphEdge[]
  • findEdgeBetween(sourceNodeId: string, targetNodeId: string): GraphEdge | undefined

路由操作

  • routeOneEdge(edgeId: string, routerType: RouterType): RouteResult
  • routeAllEdges(routerType: RouterType): void
  • rerouteConnectedEdges(nodeId: string, routerType?: RouterType): void

其他

  • clear(): void - 清空整个图表

泛型自定义

支持为节点和边配置自定义数据类型:

interface CustomNodeData {
  title: string
  status: 'pending' | 'approved' | 'rejected'
  assignee: string
}

interface CustomEdgeData {
  condition: string
  probability: number
}

const graph = new GraphStore<CustomNodeData, CustomEdgeData>()

const node: GraphNode<CustomNodeData> = {
  id: 'approve',
  type: 'USER',
  position: { x: 100, y: 100 },
  size: { width: 100, height: 50 },
  ports: [],
  data: {
    title: '审批',
    status: 'pending',
    assignee: 'admin'
  }
}

许可

MIT