Thanks for contributing to @statelyai/graph.
pnpm install
pnpm verifypnpm verify runs the same core checks we rely on before release:
pnpm typecheckpnpm test -- --runpnpm buildpnpm validate:package
src/graph.ts- graph factories, lookups, and mutationssrc/queries.ts- neighborhood, hierarchy, degree, and port queriessrc/algorithms.ts- traversal, paths, components, cycles, ordering, MSTsrc/transforms.ts- flattening and graph transformssrc/formats/- per-format converters and serializerssrc/indexing.ts- WeakMap-backed indexingsrc/types.ts- public type definitionstests/- Vitest coverage for library behavior and integrationsexamples/- runnable usage examples for common graph workflows
This package is intentionally plain:
- Graphs are JSON-serializable objects
- No classes on graph/node/edge/port data structures
graphis always the first parameter, except forcreate*factories- Collection queries return
[]when empty - Mutations happen in place and should be documented with
/** **Mutable.** */
All functions use a prefix:
get*- lookup/query returning a value, array, orundefinedgen*- generator-based queryis*/has*- boolean checkscreate*- factoriesto*/from*- format conversionadd*/delete*/update*- in-place mutation
Avoid introducing unprefixed helpers to the public API.
Follow the established type naming:
Graph*for resolved primary types*Configfor lenient input types*Optionsfor algorithm/configuration parametersVisual*for required position/size shapes*Updatefor batch mutation payloads
Generic order is <TNodeData, TEdgeData, TGraphData, TPortData>, shortened to <N, E, G, P> in function signatures.
Tests use Vitest. Keep new tests close to the behavior they exercise:
- graph/mutation/query work ->
tests/*.test.ts - format converters ->
tests/formats/*.test.ts - Mermaid variants ->
tests/formats/mermaid/*.test.ts
When changing runtime behavior, add or update tests before finalizing the implementation.
Format adapters are published as subpath imports such as @statelyai/graph/graphml and @statelyai/graph/mermaid.
If you add a new format:
- Add the source under
src/formats/<name>/ - Add tests under
tests/formats/ - Add the entry to
tsdown.config.ts - Add the subpath to
package.json#exports - Document it in the root README and the format README
This repo uses Changesets. For user-visible changes:
pnpm changesetKeep change summaries focused on public API, behavior, and migration impact.