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 🙏

© 2024 – Pkg Stats / Ryan Hefner

db.mw

v0.1.0

Published

A powerful MDX-based database with JSON-LD and vector search support

Downloads

57

Readme

mdxdb

A powerful MDX-based database that treats MDX documents as collections, with built-in support for JSON-LD, vector search, and multiple storage backends.

npm version License: MIT

Features

  • 📝 MDX-Native: Built with first-class MDX support
  • 🔍 Vector Search: Built-in support for semantic search using embeddings
  • 🌐 JSON-LD: Native support for linked data through JSON-LD conventions
  • 🔄 Multiple Backends: Support for both filesystem and HTTP/API backends
  • 🎯 Type-Safe: Written in TypeScript with comprehensive type definitions
  • Async/Await: Modern Promise-based API
  • 🔒 Error Handling: Comprehensive error handling with detailed error types
  • 📊 Debugging: Built-in logging and debugging support

Installation

npm install mdxdb

Quick Start

import { db } from '@mdxdb'

// Create a collection
const posts = db('https://example.com/posts')

// Create a document
const post = await posts.create({
  mdx: '# Hello World\nThis is my first post!',
  data: {
    title: 'Hello World',
    published: true
  }
})

// Search documents
const results = await posts.search('hello')

// Query with filters
const published = await posts.find({ published: true })

// Vector search
const similar = await posts.semanticSearch('concept', {
  k: 5,
  threshold: 0.7
})

Configuration

Environment Variables

  • MDXDB_URL: Default base URL for collections
  • MDXDB_TOKEN: API authentication token

Custom Configuration

import { createDatabase } from '@mdx.do/db'

const db = createDatabase({
  base: 'https://example.com',
  apiKey: 'your-api-key',
  // For filesystem provider
  basePath: '/path/to/data'
})

API Reference

Database

The main database function creates and manages collections:

// Using URL
const posts = db('https://example.com/posts')

// Using proxy syntax
const posts = db.posts

// Custom configuration
const posts = db('https://example.com/posts', {
  apiKey: 'custom-key'
})

Collection

Collections provide CRUD operations and querying capabilities:

Basic Operations

// Get a document
const doc = await collection.get('doc-id')

// Create a document
const doc = await collection.create({
  mdx: '# New Document',
  data: { title: 'New' }
})

// Update a document
const updated = await collection.update('doc-id', {
  data: { published: true }
})

// Delete a document
await collection.delete('doc-id')

Querying

// List all documents
const docs = await collection.list()

// Search by text
const results = await collection.search('query')

// Filter documents
const published = await collection.find({ published: true })

// Namespace search
const allDocs = await collection.namespace()

Vector Search

Built-in support for semantic search using embeddings:

// Search using vector
const results = await collection.vectorSearch({
  vector: [0.1, 0.2, ...],
  k: 10,
  threshold: 0.8
})

// Semantic search using text
const similar = await collection.semanticSearch('concept', {
  k: 5,
  threshold: 0.7
})

Document Interface

Documents follow JSON-LD conventions and include MDX capabilities:

interface Document {
  // JSON-LD metadata
  id: string
  context: string | Record<string, any>
  type?: string
  
  // MDX content
  mdx: string
  data: Record<string, any>
  
  // React components
  default: ComponentType<any>
  markdown: ComponentType<any>
  
  // Operations
  merge(update: Record<string, any>): Promise<Document>
  append(content: string): Promise<Document>
}

Providers

Filesystem Provider

import { db } from '@mdx.do/db/fs'

const posts = db('file:///posts', {
  basePath: '/path/to/data'
})

HTTP/API Provider

import { db } from '@mdx.do/db'

const posts = db('https://example.com/posts', {
  apiKey: 'your-api-key',
  apiURI: uri => `${uri}.json` // Custom API endpoint
})

Error Handling

The library provides detailed error types for better error handling:

try {
  await collection.get('non-existent')
} catch (error) {
  if (error instanceof DocumentNotFoundError) {
    console.log('Document not found:', error.message)
  } else if (error instanceof ValidationError) {
    console.log('Validation failed:', error.message)
  }
}

Debugging

Enable debug logging by setting the DEBUG environment variable:

# Enable all debug logs
DEBUG=mdxdb:* npm test

# Enable specific components
DEBUG=mdxdb:fs:*,mdxdb:vector:* npm test

Development

# Install dependencies
npm install

# Run tests
npm test

# Run tests with debug output
npm run debug

# Run tests with coverage
npm run test:coverage

License

MIT © mdxdb