🚀 Socket Launch Week Day 5:Introducing Repository Access Permissions and Custom Roles.Learn more
Sign In

@inferagraph/file

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@inferagraph/file

File datasource for InferaGraph (CSV, TSV, Markdown folders)

latest
Source
npmnpm
Version
0.2.2
Version published
Weekly downloads
7
-46.15%
Maintainers
1
Weekly downloads
 
Created
Source

@inferagraph/file

File-based datasource plugin for @inferagraph/core. Loads nodes from delimited files (CSV/TSV) or a folder of Markdown files with frontmatter.

Migration from @inferagraph/file-datasource

pnpm remove @inferagraph/file-datasource
pnpm add @inferagraph/file

The class was also renamed FileDatasourceFileDataSource. Most hosts can switch to the new factory:

import { fileDataSource } from '@inferagraph/file';

Installation

pnpm add @inferagraph/file @inferagraph/core

Usage

CSV / TSV

import { fileDataSource } from '@inferagraph/file';

const datasource = fileDataSource({
  type: 'csv',
  path: './data/nodes.csv',
  hasHeader: true,           // first row contains column names
  contentFields: ['summary'], // optional: surface columns via getContent
  edges: [
    {
      id: 'e1',
      sourceId: 'n1',
      targetId: 'n2',
      attributes: { type: 'related_to' },
    },
  ],
});

await datasource.connect();

const view = await datasource.getInitialView();
const node = await datasource.getNode('n1');
const neighbors = await datasource.getNeighbors('n1');
const results = await datasource.search('keyword');

await datasource.disconnect();

Markdown folder

import { fileDataSource } from '@inferagraph/file';

const datasource = fileDataSource({
  type: 'markdown',
  path: './data/nodes',                          // folder containing .md files
  frontmatter: ['id', 'name', 'type'],           // required keys per file (exact match)
  edges: [],
});

await datasource.connect();

// Each .md file becomes a node with frontmatter as attributes;
// the body is exposed via getContent.
const content = await datasource.getContent('n1');
// { nodeId: 'n1', content: '<body markdown>', contentType: 'markdown' }

Class escape hatch

The factory is the preferred entry point, but the class is exported for hosts that need to subclass:

import { FileDataSource } from '@inferagraph/file';

class MyFileDataSource extends FileDataSource {
  // ...
}

Configuration

Common options

OptionTypeDescription
type'csv' | 'tsv' | 'markdown'File format
pathstringFile path (csv/tsv) or folder path (markdown)
edgesEdgeData[]Host-supplied relationships
idFieldstringColumn / frontmatter key for the node id (default: 'id')

CSV / TSV options

OptionTypeDescription
hasHeaderbooleanFirst row is column names (default: true)
columnsstring[]Required when hasHeader=false. Length must match the parsed first row.
contentFieldsstring[]Columns surfaced via getContent as metadata. When unset, getContent returns undefined.

Markdown options

OptionTypeDescription
frontmatterstring[]Required keys. Each .md file must contain EXACTLY this set (extras and missing keys throw).

Behavior

  • connect() reads and parses every file up-front (deterministic, fail-fast).
  • disconnect() clears the parsed state.
  • All seven DataAdapter methods (getInitialView, getNode, getNeighbors, findPath, search, filter, getContent) require an active connection.
  • Edges supplied in config.edges are stored as-is and used for graph traversal.

License

MIT

FAQs

Package last updated on 07 May 2026

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts