Detalhes do pacote

@ts-graphviz/common

ts-graphviz2.8mMIT3.0.3

Graphviz Types and Utilities

graphviz, dot

readme (leia-me)

Main CodeQL License: MIT All Contributors OpenSSF Best Practices OpenSSF Scorecard Tidelift npm version node version deno version npm # @ts-graphviz/common Type information, constants, and utility functions related to the DOT language attributes, attribute values, and models for ts-graphviz. 🔗 GitHub npm Reference Ask DeepWiki Sponsor OpenCollective format: Biome test: Vitest build: Vite

It is part of the ts-graphviz library, which is split into modular packages to improve maintainability, flexibility, and ease of use.

Features

  • Type definitions for DOT language elements, including attributes and attribute values
  • Constants representing common attribute names and values
  • Comprehensive type guards for runtime type checking and TypeScript type narrowing
  • Node reference utilities for parsing and converting complex node references
  • Performance-optimized utilities for working with large model collections
  • Seamless integration with @ts-graphviz/react for type-safe model filtering
  • Dual-mode type handling - runtime validation or trusted user assertions

Usage

Basic Type Definitions

Import the necessary types, constants, or utility functions from the @ts-graphviz/common package:

import {
  NodeAttributesObject,
  EdgeAttributesObject,
  isNodeModel,
  isEdgeModel,
  toNodeRef
} from '@ts-graphviz/common';

Type-Safe Model Operations

The package excels at providing type safety for graph model operations:

const nodeAttr: NodeAttributesObject = {
  label: 'Node label',
  shape: 'ellipse',
};

const edgeAttr: EdgeAttributesObject = {
  label: 'Edge label',
  color: 'red',
};

Type Guards and Model Utilities

The package provides powerful type guards for working with graph models with full TypeScript integration:

import {
  isNodeModel,
  isEdgeModel,
  isRootGraphModel,
  isSubgraphModel,
  isAttributeListModel
} from '@ts-graphviz/common';

// Type-safe model checking
if (isNodeModel(someModel)) {
  // TypeScript knows someModel is NodeModel
  console.log(someModel.id);
}

if (isEdgeModel(someModel)) {
  // TypeScript knows someModel is EdgeModel
  console.log(someModel.targets);
}

Node Reference Utilities

Utilities for working with node references and compass directions:

import {
  isNodeRef,
  isNodeRefLike,
  isCompass,
  toNodeRef,
  toNodeRefGroup
} from '@ts-graphviz/common';

// Check if a value is a valid node reference
if (isNodeRefLike('node1:port:n')) {
  const nodeRef = toNodeRef('node1:port:n');
  console.log(nodeRef); // { id: 'node1', port: 'port', compass: 'n' }
}

// Convert multiple node references
const targets = toNodeRefGroup(['node1', 'node2:port', 'node3::s']);
console.log(targets);
// [
//   { id: 'node1' },
//   { id: 'node2', port: 'port' },
//   { id: 'node3', port: '', compass: 's' }
// ]

// Validate compass directions
if (isCompass('ne')) {
  console.log('Valid compass direction');
}

Advanced Type Checking

The package provides additional utilities for complex type checking scenarios:

import {
  isForwardRefNode,
  isNodeRefGroupLike,
  isNodeRef,
  isNodeRefLike,
  FilterableModel
} from '@ts-graphviz/common';

// Check for forward reference nodes
const forwardRef = { id: 'futureNode' };
if (isForwardRefNode(forwardRef)) {
  console.log('Valid forward reference');
}

// Validate arrays of node references
const targets = ['node1', 'node2:port'];
if (isNodeRefGroupLike(targets)) {
  const nodeRefs = toNodeRefGroup(targets);
  // Process validated node references
}

For more examples and usage details, please refer to the ts-graphviz documentation.

Contributors 👥

Thanks goes to these wonderful people (emoji key):

Yuki Yamazaki
Yuki Yamazaki

💻 ⚠️ 📖 🤔
LaySent
LaySent

🐛 ⚠️
elasticdotventures
elasticdotventures

📖
Christian Murphy
Christian Murphy

💻 🤔 📖
Artem
Artem

🐛
fredericohpandolfo
fredericohpandolfo

🐛
diegoquinteiro
diegoquinteiro

🐛
robross0606
robross0606

🤔
Blake Regalia
Blake Regalia

🐛
bigbug
bigbug

💬
mrwk
mrwk

💬
svdvonde
svdvonde

💬
Adam
Adam

💬
Trevor Scheer
Trevor Scheer

️️️️♿️
Prem Pillai
Prem Pillai

🐛
nagasawaryoya
nagasawaryoya

💻 ⚠️
YukiSasaki
YukiSasaki

💻 ⚠️
Madd0g
Madd0g

🐛
j4k0xb
j4k0xb

🐛
HKrogstie
HKrogstie

🐛
Nils K
Nils K

🐛
hao2013
hao2013

🚧 👀
Walter Rafelsberger
Walter Rafelsberger

💬
grsjst
grsjst

🐛
Steve
Steve

🐛

This project follows the all-contributors specification. Contributions of any kind welcome!

Changelog 📜

See CHANGELOG.md for more details.

License ⚖️

This software is released under the MIT License, see LICENSE.

changelog (log de mudanças)

@ts-graphviz/common

3.0.3

Patch Changes

  • #1513 9d52d28 Thanks @kamiazya! - Fix @next tag publishing pipeline to prevent incorrect releases

    This fix addresses issues with the @next tag publishing workflow where stable versions were incorrectly published with @next tag, and subsequently, @next versions stopped being published entirely.

    Problem 1 (PR #1513): Stable package versions were being incorrectly published with the @next tag instead of the latest tag. The Changesets action switches to changeset-release/main and updates package.json versions, but the @next publish step would run on this branch where no unreleased changesets remain, causing stable versions to be published with @next tag.

    Solution 1: Added a branch check step to verify the current working directory is on the main branch before executing @next publish.

    Problem 2 (This PR): The branch check from PR #1513 prevented ALL @next publishes because the changesets action never switches back to main, causing the branch check to always fail.

    Solution 2: Added a step to switch back to the main branch after the changesets action completes. This ensures the working directory is in the correct state for snapshot versioning while maintaining the safety check.

    Changes:

    • Added branch check to verify current branch before @next publish
    • Added git checkout main step after changesets action
    • Updated @next publish condition to include branch verification
    • Removed redundant commit message check that was ineffective
  • #1514 d74172a Thanks @kamiazya! - Migrate npm publishing to OIDC trusted publishing

    This change migrates the npm publishing workflow from using long-lived NPM_TOKEN secrets to OIDC (OpenID Connect) trusted publishing, following GitHub's security recommendations announced in September 2025.

    Benefits:

    • Enhanced security: No more long-lived tokens to manage, rotate, or accidentally expose
    • Automatic provenance: Provenance attestations are generated automatically without the --provenance flag
    • Compliance: Aligns with npm's new authentication requirements (token expiration limits)
    • Short-lived credentials: Each publish uses workflow-specific, ephemeral credentials

    Changes:

    • Added environment: npm to the release job to match trusted publisher configuration
    • Upgraded npm CLI to latest version (≥11.5.1) for OIDC support
    • Removed NPM_TOKEN from changesets action and snapshot publish steps
    • Removed manual .npmrc creation as authentication now uses OIDC tokens
    • Updated id-token permission comment to reflect OIDC usage

    Requirements:

    • npm CLI v11.5.1 or later (automatically installed in workflow)
    • Trusted publisher configured for each package on npmjs.com
    • GitHub Actions environment named "npm" configured for the repository
  • #1512 de566db Thanks @anubhav-goel! - Updated broken monorepo package links to valid URLs

3.0.2

Patch Changes

  • #1483 a07d3b7 Thanks @kamiazya! - Fix CI workflow to prevent @next tag publishing after Version Packages PR merge

3.0.1

Patch Changes

3.0.0

Major Changes

  • #1363 9328563 Thanks @kamiazya! - 🚨 Breaking Changes: Drop Node.js 18 support

    Minimum required version is now Node.js 20+

    ESM-Only Distribution

    • Remove CommonJS builds: All packages now distribute only ESM (ECMAScript Modules)
    • Package exports: Removed require fields from package.json exports
    • Module type: All packages are now "type": "module"

    🔄 Migration Guide

    For ESM Projects (Recommended)

    {
      "type": "module"
    }
    
    // Import syntax remains unchanged
    import { Digraph, Node, Edge, toDot } from "ts-graphviz";
    import { toFile } from "ts-graphviz/adapter";
    import { parse } from "ts-graphviz/ast";
    

    For CommonJS Projects

    If you are using CommonJS (CJS) and need to migrate to ESM, you will need to update your project to support dynamic imports. This is necessary because the packages no longer provide CommonJS builds.

    Before (CJS)

    // JavaScript (CommonJS)
    function createGraph() {
      // Dynamic import is required because the packages no longer provide CommonJS builds.
      const { Digraph, Node, Edge, toDot } = require("ts-graphviz");
      const graph = new Digraph();
      return toDot(graph);
    }
    

    After (ESM)

    async function createGraph() {
      const { Digraph, Node, Edge, toDot } = await import("ts-graphviz");
    
      const graph = new Digraph();
      // Create your graph...
      return toDot(graph);
    }
    
    // TypeScript (CommonJS)
    // Update tsconfig.json
    {
      "compilerOptions": {
        "module": "Node16",
        "moduleResolution": "Node16"
      }
    }
    
    // Use dynamic imports
    async function createGraph() {
      const tsGraphviz = await import('ts-graphviz');
      const { Digraph, Node, Edge, toDot } = tsGraphviz;
    
      const graph = new Digraph();
      // Create your graph...
      return toDot(graph);
    }
    

    🎯 Benefits

    • Modern JavaScript: Leveraging native ES modules for better performance
    • Smaller bundle sizes: ESM enables better tree-shaking
    • Future-proof: Aligning with the JavaScript ecosystem direction
    • Better TypeScript support: Enhanced module resolution

Minor Changes

  • #1363 9328563 Thanks @kamiazya! - Define Supported environment and Support levels

    To provide clarity on the environments in which ts-graphviz operates, we have categorized support levels:

    Support Levels

    Tier 1: Full Support

    • Definition: Environments that are fully supported, with comprehensive automated testing and maintenance.
    • Environments:
      • Node.js LTS versions: All active Long-Term Support (LTS) versions.
        • If a Node.js LTS version is released, we will ensure compatibility with it.
        • If a Node.js LTS version is deprecated, we will drop support for it in the next major release.
    • Details:
      • We run automated tests on all LTS versions of Node.js.
      • Full compatibility and performance are ensured.
      • Critical issues are prioritized for fixes.

    Tier 2: Active Support

    • Definition: Environments that receive active support with limited automated testing.
    • Environments:
      • Deno Latest LTS version: The latest Long-Term Support (LTS) version of Deno.
        • If a new Deno LTS version is released, we will ensure compatibility with it.
        • If a Deno LTS version is deprecated, we will drop support for it in the next minor release.
      • Node.js Current Release: The latest Node.js release outside the LTS schedule.
        • If a new Node.js current release is available, we will ensure compatibility with it.
        • If a Node.js current release is deprecated, we will drop support for it in the next minor release.
    • Details:
      • Compatibility is maintained, and issues are addressed.

    Tier 3: Community Support

    • Definition: Environments that are not officially tested but are supported on a best-effort basis.
    • Environments:
      • Modern Browsers: Latest versions of major browsers, including:
        • Google Chrome
        • Mozilla Firefox
        • Microsoft Edge
        • Apple Safari
      • Deno Current Release: The latest Deno release outside the LTS schedule.
    • Details:
      • Installation methods are provided.
      • No automated testing is performed.
      • Issues reported by users will be addressed.
      • Targeting the latest versions ensures compatibility with modern web standards.
      • We will not actively test or maintain compatibility with older versions of browsers.
  • #1363 9328563 Thanks @kamiazya! - Export type guard and node reference utility APIs

    New Public APIs

    Type Guard Functions

    • isNodeModel(object: unknown): object is NodeModel - Type guard for NodeModel objects
    • isEdgeModel(object: unknown): object is EdgeModel - Type guard for EdgeModel objects
    • isSubgraphModel(object: unknown): object is SubgraphModel - Type guard for SubgraphModel objects
    • isRootGraphModel(object: unknown): object is RootGraphModel - Type guard for RootGraphModel objects
    • isAttributeListModel(object: unknown): object is AttributeListModel - Type guard for AttributeListModel objects

    Node Reference Utilities

    • isForwardRefNode(object: unknown): object is ForwardRefNode - Type guard for ForwardRefNode objects
    • isNodeRef(node: unknown): node is NodeRef - Type guard for NodeRef objects (NodeModel or ForwardRefNode)
    • isNodeRefLike(node: unknown): node is NodeRefLike - Type guard for NodeRefLike objects (string or NodeRef)
    • isNodeRefGroupLike(target: NodeRefLike | NodeRefGroupLike): target is NodeRefGroupLike - Type guard for arrays of NodeRefLike
    • isCompass(c: string): c is Compass - Type guard for valid compass directions ('n', 'ne', 'e', 'se', 's', 'sw', 'w', 'nw', 'c')

    Conversion Utilities

    • toNodeRef(target: NodeRefLike): NodeRef - Converts NodeRefLike to structured NodeRef object
    • toNodeRefGroup(targets: NodeRefGroupLike): NodeRefGroup - Converts array of NodeRefLike to array of NodeRef objects

    New Types

    • FilterableModel - Union type of all model types that can be filtered using type guards

    Features

    • Enhanced Type Safety: All functions provide strict runtime type checking with TypeScript type narrowing
    • Comprehensive Documentation: Full JSDoc comments with usage examples for all public APIs
    • Node Reference Parsing: Parse complex node reference strings like "node1:port:n" into structured objects
    • Compass Direction Validation: Validate and work with Graphviz compass directions

Patch Changes

  • #1363 9328563 Thanks @kamiazya! - Update Develop Environment

    • Drop turbo
    • Upgrade biome to 2.0
    • Upgrade TypeScript to 5.8
    • Upgrade Vite to 7.0
    • Upgrade Vitest to 3.2
    • Upgrade Peggy to 5.0 and drop ts-pegjs
    • Implement new E2E test workflow
  • #1363 9328563 Thanks @kamiazya! - New GitHub Action main workflow and tests

2.1.5

Patch Changes

2.1.4

Patch Changes

2.1.3

Patch Changes

2.1.2

Patch Changes

2.1.1

Patch Changes

2.1.0

Minor Changes

Patch Changes

2.0.0

It is part of the ts-graphviz library, which is split into modular packages to improve maintainability, flexibility, and ease of use.

This package contains type information, constants, and utility functions related to the DOT language attributes, attribute values, and models for ts-graphviz.

Features

  • Type definitions for DOT language elements, such as attributes and attribute values
  • Constants representing common attribute names and values
  • Utility functions for working with DOT language elements

Usage

Import the necessary types, constants, or utility functions from the @ts-graphviz/common package:

import {
  NodeAttributesObject,
  EdgeAttributesObject,
} from "@ts-graphviz/common";

Use the imported items in your project to work with the DOT language elements:

const nodeAttr: NodeAttributesObject = {
  label: "Node label",
  shape: "ellipse",
};

const edgeAttr: EdgeAttributesObject = {
  label: "Edge label",
  color: "red",
};