Skip to content

Commit 105ad18

Browse files
Add TypeScript Renderer (#10)
* Move Python code to its own dir * Checkpoint * Checkpoint * Add prompt * Fix validation test * Claude code test (ts implementation for types) (#13) * Add CLAUDE.md * Commit first passing version * Checkpoint * Model did reward hacking * Checkpoint * Second try * Don't hardcode enums as well * Use the main page example for serialization test * Run prettier * Rename ts -> typescript * Add script to reduce example html * Add example html and css files over from notion * Save context in CLAUDE.md * React renderer with Claude Code (#15) * Add prompt * Checkpoint * Renderer launches and views some of the blocks * Add new round prompt * Checkpoint * Checkpoint * Checkpoint * Checkpoint * Checkpoint * Checkpoint * Checkpoint * Add prompt * Checkpoint * Add report * Run prettier to compare diffs * use vite to serve html * add ol and ul * checkpoint * tsup setup * improve tsconfig and tsup * setup eslint with import and bunch of plugins * vscode settings * add generated types to ts and eslint ingnore * setup prettier * eslint fix * make block container div open for modification + make blocks overriable * Undo changes to python and schema dirs --------- Co-authored-by: Abreham Gezahegn <[email protected]>
1 parent def0b15 commit 105ad18

File tree

220 files changed

+43797
-399
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

220 files changed

+43797
-399
lines changed

.github/workflows/build.yaml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,21 +24,25 @@ jobs:
2424
with:
2525
python-version: "3.12"
2626
enable-cache: true
27-
cache-dependency-glob: "requirements.txt"
27+
cache-dependency-glob: "python/requirements.txt"
2828

2929
- name: Install dependencies
30+
working-directory: ./python
3031
run: |
3132
if [ -f requirements.txt ]; then uv pip install -r requirements.txt; fi
3233
uv pip install pytest
3334
3435
- name: Install the package
36+
working-directory: ./python
3537
run: |
3638
uv pip install .
3739
3840
- name: Test with pytest
41+
working-directory: ./python
3942
run: |
40-
uv run pytest
43+
PYTHONPATH=.. uv run pytest
4144
4245
- name: Check if the main script is installed
46+
working-directory: ./python
4347
run: |
4448
uv run convert_jsondoc --help

.github/workflows/publish.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,12 @@ jobs:
3434
uses: astral-sh/setup-uv@v5
3535

3636
- name: Install dependencies
37+
working-directory: ./python
3738
run: |
3839
uv pip install --system toml
3940
4041
- name: Extract version from tag and update pyproject.toml
42+
working-directory: ./python
4143
run: |
4244
# Get the version from the tag (remove 'v' prefix)
4345
TAG_VERSION=${GITHUB_REF#refs/tags/v}
@@ -58,11 +60,13 @@ jobs:
5860
cat pyproject.toml | grep version
5961
6062
- name: Build package
63+
working-directory: ./python
6164
run: uv build --no-sources
6265

6366
- name: Publish package to PyPI
6467
uses: pypa/[email protected]
6568
with:
69+
packages-dir: python/dist/
6670
user: __token__
6771
password: ${{ secrets.PYPI_API_TOKEN }}
6872
verbose: true

.github/workflows/test.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,12 @@ jobs:
2626
uses: astral-sh/setup-uv@v5
2727

2828
- name: Install dependencies
29+
working-directory: ./python
2930
run: uv sync --all-extras --dev
3031

3132
- name: Run tests
33+
working-directory: ./python
3234
run: |
33-
uv run pytest
35+
PYTHONPATH=.. uv run pytest
3436
3537

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@ __pycache__
66
build/
77
*.docx
88
*.pptx
9-
scratch/
9+
scratch/
10+
dist/

.vscode/settings.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"eslint.validate": [
3+
"javascript",
4+
"javascriptreact",
5+
"typescript",
6+
"typescriptreact"
7+
],
8+
"editor.codeActionsOnSave": {
9+
"source.fixAll.eslint": "explicit"
10+
},
11+
"eslint.useFlatConfig": true
12+
}

CLAUDE.md

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
# CLAUDE.md
2+
3+
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
4+
5+
## Project Overview
6+
7+
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.
8+
9+
The project consists of:
10+
1. A JSON schema specification for the format
11+
2. A Python implementation
12+
3. A TypeScript implementation (in progress)
13+
4. Converters for various formats (HTML, Markdown, etc.)
14+
15+
## Project Structure
16+
17+
- `/schema/`: JSON schemas defining the structure of JSON-DOC files
18+
- `/python/`: Python implementation
19+
- `/ts/`: TypeScript implementation (in progress)
20+
- `/docs/`: Documentation
21+
- `/examples/`: Example files showing the format
22+
- `/tests/`: Tests for both implementations
23+
24+
## Development Commands
25+
26+
### Python Development
27+
28+
```bash
29+
# Set up development environment
30+
cd /Users/onur/tc/JSON-DOC/python
31+
python -m pip install -e .
32+
python -m pip install -e ".[dev]"
33+
34+
# Run tests
35+
cd /Users/onur/tc/JSON-DOC/python
36+
pytest
37+
38+
# Run a specific test
39+
cd /Users/onur/tc/JSON-DOC/python
40+
pytest tests/test_serialization.py -v
41+
42+
# Run validation tests
43+
cd /Users/onur/tc/JSON-DOC/python
44+
python tests/test_validation.py schema
45+
46+
# Run linting
47+
cd /Users/onur/tc/JSON-DOC/python
48+
ruff check .
49+
ruff format .
50+
```
51+
52+
### TypeScript Development
53+
54+
```bash
55+
# Set up development environment
56+
cd /Users/onur/tc/JSON-DOC/ts
57+
npm install
58+
59+
# Build TypeScript
60+
cd /Users/onur/tc/JSON-DOC/ts
61+
npm run build
62+
63+
# Run tests
64+
cd /Users/onur/tc/JSON-DOC/ts
65+
npm test
66+
```
67+
68+
## Architecture Overview
69+
70+
### JSON-DOC Schema
71+
72+
The JSON-DOC schema is defined in JSONSchema format, with the following primary components:
73+
74+
1. **Page**: The top-level container for all content
75+
2. **Block**: Content blocks of various types (paragraph, heading, list item, etc.)
76+
3. **Rich Text**: Text content with formatting (bold, italic, etc.)
77+
4. **File**: External file references (images, etc.)
78+
79+
Each block type has specific schemas and validation rules.
80+
81+
### Python Implementation
82+
83+
The Python implementation uses Pydantic models for validation and serialization, with:
84+
85+
- Block types implemented as classes inheriting from a base Block class
86+
- Rich text types implemented as classes inheriting from a base RichText class
87+
- Serialization/deserialization functions for loading and saving JSON-DOC files
88+
- Converters for HTML, Markdown, and other formats
89+
90+
Key modules:
91+
- `jsondoc.models`: Pydantic models for JSON-DOC
92+
- `jsondoc.serialize`: Functions for loading/saving JSON-DOC
93+
- `jsondoc.validate`: Schema validation
94+
- `jsondoc.convert`: Conversion between formats
95+
96+
### TypeScript Implementation
97+
98+
The TypeScript implementation is in progress, following similar architecture to the Python version:
99+
100+
- Type definitions for all JSON-DOC structures
101+
- Functions for loading/saving JSON-DOC files
102+
- Schema validation
103+
- Converters for other formats
104+
105+
## Testing Strategy
106+
107+
- Schema validation tests ensure examples conform to schemas
108+
- Serialization tests ensure round-trip conversion preserves data
109+
- Conversion tests verify correct transformation between formats
110+
- Integration tests for end-to-end workflows
111+
112+
## Implementation Notes
113+
114+
1. The project follows a modular architecture with clear separation between:
115+
- Schema definition
116+
- Model implementation
117+
- Validation
118+
- Serialization
119+
- Conversion
120+
121+
2. The TypeScript implementation should follow the same patterns as the Python implementation, with appropriate adaptations for the TypeScript ecosystem.
122+
123+
3. The core functionality is focused on:
124+
- Loading JSON-DOC files into typed objects
125+
- Validating JSON-DOC files against schemas
126+
- Converting between JSON-DOC and other formats
127+
128+
129+
# Code generation guidelines
130+
- don's assume things, if some things are clear, ask for clarification

docs/2025-05-21-json-doc-ts-prompt.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
---
2+
title: "Implementing JSON-DOC TypeScript parser"
3+
author: "Onur <[email protected]>"
4+
date: "2025-05-21"
5+
---
6+
7+
A lot of coding agent products went into production recently, such as OpenAI Codex, Google Jules, Claude Code, etc. The TypeScript implementation is an ideal task, thanks to existing tests.
8+
9+
Below is the prompt:
10+
11+
```
12+
Convert JSON Schemas into TS interfaces similar to what is in Python with datamodel-codegen. See https://github.com/bcherny/json-schema-to-typescript and https://github.com/ThomasAribart/json-schema-to-ts. Compare the two and choose the best option.
13+
14+
The interfaces MUST BE generated programmatically, just as how we do in Python. Understand the directory structure first, list, navigate and read files. Look at the json schema files under /schema, and compare them with the generated files in the python directory
15+
16+
We basically need to implement parsing of a JSON-DOC file into typed objects in typescript, similar to Python load_jsondoc() and similar functions
17+
18+
Note that we use uv for running python. There are example json-doc files and tests under /tests and github actions that make sure that the parsing and validation logic in python is correct
19+
20+
For a correct ts implementation, similar tests and checks need to be implemented. Make sure to use up-to-date typescript tooling and conventions. This library is supposed to be installed universally, keep that in mind. Do not use obscure or non-general tooling for packaging and distribution. Follow today's best practices
21+
```
22+

0 commit comments

Comments
 (0)