Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
126 changes: 126 additions & 0 deletions CLAUDE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
# CLAUDE.md

This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.

## Project Overview

JSON-DOC is a standardized format for storing structured content in JSON files, inspired by Notion's data model. It supports a wide variety of content types including paragraphs, headings, lists, tables, images, code blocks, and more.

The project consists of:
1. A JSON schema specification for the format
2. A Python implementation
3. A TypeScript implementation (in progress)
4. Converters for various formats (HTML, Markdown, etc.)

## Project Structure

- `/schema/`: JSON schemas defining the structure of JSON-DOC files
- `/python/`: Python implementation
- `/ts/`: TypeScript implementation (in progress)
- `/docs/`: Documentation
- `/examples/`: Example files showing the format
- `/tests/`: Tests for both implementations

## Development Commands

### Python Development

```bash
# Set up development environment
cd /Users/onur/tc/JSON-DOC/python
python -m pip install -e .
python -m pip install -e ".[dev]"

# Run tests
cd /Users/onur/tc/JSON-DOC/python
pytest

# Run a specific test
cd /Users/onur/tc/JSON-DOC/python
pytest tests/test_serialization.py -v

# Run validation tests
cd /Users/onur/tc/JSON-DOC/python
python tests/test_validation.py schema

# Run linting
cd /Users/onur/tc/JSON-DOC/python
ruff check .
ruff format .
```

### TypeScript Development

```bash
# Set up development environment
cd /Users/onur/tc/JSON-DOC/ts
npm install

# Build TypeScript
cd /Users/onur/tc/JSON-DOC/ts
npm run build

# Run tests
cd /Users/onur/tc/JSON-DOC/ts
npm test
```

## Architecture Overview

### JSON-DOC Schema

The JSON-DOC schema is defined in JSONSchema format, with the following primary components:

1. **Page**: The top-level container for all content
2. **Block**: Content blocks of various types (paragraph, heading, list item, etc.)
3. **Rich Text**: Text content with formatting (bold, italic, etc.)
4. **File**: External file references (images, etc.)

Each block type has specific schemas and validation rules.

### Python Implementation

The Python implementation uses Pydantic models for validation and serialization, with:

- Block types implemented as classes inheriting from a base Block class
- Rich text types implemented as classes inheriting from a base RichText class
- Serialization/deserialization functions for loading and saving JSON-DOC files
- Converters for HTML, Markdown, and other formats

Key modules:
- `jsondoc.models`: Pydantic models for JSON-DOC
- `jsondoc.serialize`: Functions for loading/saving JSON-DOC
- `jsondoc.validate`: Schema validation
- `jsondoc.convert`: Conversion between formats

### TypeScript Implementation

The TypeScript implementation is in progress, following similar architecture to the Python version:

- Type definitions for all JSON-DOC structures
- Functions for loading/saving JSON-DOC files
- Schema validation
- Converters for other formats

## Testing Strategy

- Schema validation tests ensure examples conform to schemas
- Serialization tests ensure round-trip conversion preserves data
- Conversion tests verify correct transformation between formats
- Integration tests for end-to-end workflows

## Implementation Notes

1. The project follows a modular architecture with clear separation between:
- Schema definition
- Model implementation
- Validation
- Serialization
- Conversion

2. The TypeScript implementation should follow the same patterns as the Python implementation, with appropriate adaptations for the TypeScript ecosystem.

3. The core functionality is focused on:
- Loading JSON-DOC files into typed objects
- Validating JSON-DOC files against schemas
- Converting between JSON-DOC and other formats
134 changes: 134 additions & 0 deletions docs/typescript-implementation.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
---
title: "TypeScript Implementation"
author: "TextCortex Dev Team"
date: "2025-05-21"
---

This file was generated by Claude Code.

---

# JSON-DOC TypeScript Implementation

In addition to the Python implementation, JSON-DOC is also available as a TypeScript library. This allows for better integration with JavaScript/TypeScript projects and web applications.

## Installation

```bash
# Using npm
npm install jsondoc

# Using yarn
yarn add jsondoc
```

## Features

The TypeScript implementation provides the following features:

- Full TypeScript type definitions for all JSON-DOC objects
- Loader/serializer functions similar to the Python implementation
- Runtime validation using JSON Schema (via ajv)
- Support for all block types defined in the JSON-DOC specification

## Usage

```typescript
import { loadJsonDoc, jsonDocDumpJson } from 'jsondoc';

// Load JSON-DOC from a string
const jsonString = '{"object":"page","id":"page-id","children":[...]}';
const doc = loadJsonDoc(jsonString);

// Or load from an object
const jsonObject = {
object: 'page',
id: 'page-id',
children: [...]
};
const doc2 = loadJsonDoc(jsonObject);

// Serialize back to JSON
const serialized = jsonDocDumpJson(doc, 2); // 2 spaces indentation
```

## Type Definitions

The TypeScript implementation provides type-safe interfaces for all JSON-DOC objects. These are automatically generated from the same JSON schemas used by the Python implementation.

```typescript
import {
Page,
BlockBase,
BlockType,
RichTextText
} from 'jsondoc';

// Create a simple page
const page: Page = {
object: 'page',
id: 'page-id',
children: [
{
object: 'block',
type: BlockType.Paragraph,
paragraph: {
rich_text: [
{
type: 'text',
text: {
content: 'Hello, world!'
}
}
]
}
}
]
};
```

## Validation

The TypeScript implementation includes validation functions similar to the Python implementation:

```typescript
import { validateAgainstSchema, loadSchema } from 'jsondoc';

// Load a schema
const schema = await loadSchema('path/to/schema.json');

// Validate a document
try {
validateAgainstSchema(document, schema);
console.log('Document is valid');
} catch (error) {
console.error('Validation failed:', error.message);
}
```

## Implementation Details

### Code Generation

The TypeScript interfaces are generated directly from the JSON schemas using `json-schema-to-typescript`. This ensures that the TypeScript types match the JSON schema definitions exactly.

### Architecture

The TypeScript implementation follows a similar architecture to the Python implementation:

- **models/**: TypeScript interfaces for JSON-DOC objects
- **validation/**: Schema validation functionality
- **serialization/**: Loading and serializing JSON-DOC objects
- **utils/**: Utility functions

### Differences from Python Implementation

While we strive to keep the API similar between the Python and TypeScript implementations, there are some differences due to the nature of the languages:

1. TypeScript's type system is compile-time only, so runtime validation is handled separately using ajv
2. The TypeScript implementation uses standard ES modules for imports/exports
3. Function naming follows JavaScript conventions (camelCase instead of snake_case)

## Development

If you want to contribute to the TypeScript implementation, see the [README.md](../ts/README.md) file in the `ts` directory for development instructions.
43 changes: 43 additions & 0 deletions ts/.github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: Build and Test

on:
push:
branches: [main]
paths:
- "ts/**"
pull_request:
branches: [main]
paths:
- "ts/**"

jobs:
build:
runs-on: ubuntu-latest
defaults:
run:
working-directory: ./ts

strategy:
matrix:
node-version: [16.x, 18.x, 20.x]

steps:
- uses: actions/checkout@v3
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
cache: "npm"
cache-dependency-path: ./ts/package-lock.json

- name: Install dependencies
run: npm ci

- name: Generate types
run: npm run generate-types

- name: Build
run: npm run build

- name: Test
run: npm test
36 changes: 36 additions & 0 deletions ts/.github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: Publish Package

on:
release:
types: [created]

jobs:
build:
runs-on: ubuntu-latest
defaults:
run:
working-directory: ./ts

steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: "16.x"
registry-url: "https://registry.npmjs.org"

- name: Install dependencies
run: npm ci

- name: Generate types
run: npm run generate-types

- name: Build
run: npm run build

- name: Test
run: npm test

- name: Publish
run: npm publish
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
Loading