json-atom 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- json_atom-0.1.0/.github/workflows/ci.yml +41 -0
- json_atom-0.1.0/.github/workflows/publish.yml +71 -0
- json_atom-0.1.0/.gitignore +18 -0
- json_atom-0.1.0/.pre-commit-config.yaml +25 -0
- json_atom-0.1.0/CLAUDE.md +78 -0
- json_atom-0.1.0/LICENSE +21 -0
- json_atom-0.1.0/PKG-INFO +444 -0
- json_atom-0.1.0/README.md +423 -0
- json_atom-0.1.0/examples/advanced_identity.py +255 -0
- json_atom-0.1.0/examples/audit_log.py +79 -0
- json_atom-0.1.0/examples/data_sync.py +66 -0
- json_atom-0.1.0/examples/index_vs_keyed.py +114 -0
- json_atom-0.1.0/examples/keyed_arrays.py +60 -0
- json_atom-0.1.0/examples/quick_api_payload.py +61 -0
- json_atom-0.1.0/examples/state_transitions.py +75 -0
- json_atom-0.1.0/examples/undo_redo.py +91 -0
- json_atom-0.1.0/pyproject.toml +51 -0
- json_atom-0.1.0/src/json_atom/__init__.py +71 -0
- json_atom-0.1.0/src/json_atom/_identity.py +180 -0
- json_atom-0.1.0/src/json_atom/_utils.py +117 -0
- json_atom-0.1.0/src/json_atom/apply.py +391 -0
- json_atom-0.1.0/src/json_atom/compare.py +381 -0
- json_atom-0.1.0/src/json_atom/diff.py +553 -0
- json_atom-0.1.0/src/json_atom/errors.py +25 -0
- json_atom-0.1.0/src/json_atom/invert.py +110 -0
- json_atom-0.1.0/src/json_atom/json_patch.py +203 -0
- json_atom-0.1.0/src/json_atom/models.py +893 -0
- json_atom-0.1.0/src/json_atom/path.py +469 -0
- json_atom-0.1.0/src/json_atom/py.typed +0 -0
- json_atom-0.1.0/src/json_atom/validate.py +97 -0
- json_atom-0.1.0/tests/__init__.py +0 -0
- json_atom-0.1.0/tests/conftest.py +22 -0
- json_atom-0.1.0/tests/fixtures/basic-replace.json +25 -0
- json_atom-0.1.0/tests/fixtures/keyed-array-update.json +52 -0
- json_atom-0.1.0/tests/test_apply.py +604 -0
- json_atom-0.1.0/tests/test_compare.py +748 -0
- json_atom-0.1.0/tests/test_conformance.py +70 -0
- json_atom-0.1.0/tests/test_cross_validation.py +1028 -0
- json_atom-0.1.0/tests/test_diff.py +924 -0
- json_atom-0.1.0/tests/test_edge_cases.py +273 -0
- json_atom-0.1.0/tests/test_extensions.py +136 -0
- json_atom-0.1.0/tests/test_invert.py +185 -0
- json_atom-0.1.0/tests/test_json_patch.py +246 -0
- json_atom-0.1.0/tests/test_models.py +1035 -0
- json_atom-0.1.0/tests/test_path.py +596 -0
- json_atom-0.1.0/tests/test_pydantic.py +200 -0
- json_atom-0.1.0/tests/test_utils.py +184 -0
- json_atom-0.1.0/tests/test_validate.py +202 -0
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
name: CI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [main]
|
|
6
|
+
pull_request:
|
|
7
|
+
branches: [main]
|
|
8
|
+
|
|
9
|
+
permissions:
|
|
10
|
+
contents: read
|
|
11
|
+
|
|
12
|
+
jobs:
|
|
13
|
+
test:
|
|
14
|
+
runs-on: ubuntu-latest
|
|
15
|
+
strategy:
|
|
16
|
+
matrix:
|
|
17
|
+
python-version: ["3.12", "3.13"]
|
|
18
|
+
steps:
|
|
19
|
+
- uses: actions/checkout@v4
|
|
20
|
+
|
|
21
|
+
- uses: astral-sh/setup-uv@v5
|
|
22
|
+
with:
|
|
23
|
+
version: "latest"
|
|
24
|
+
|
|
25
|
+
- name: Set up Python ${{ matrix.python-version }}
|
|
26
|
+
run: uv python install ${{ matrix.python-version }}
|
|
27
|
+
|
|
28
|
+
- name: Install dependencies
|
|
29
|
+
run: uv sync --python ${{ matrix.python-version }}
|
|
30
|
+
|
|
31
|
+
- name: Lint
|
|
32
|
+
run: uv run ruff check src/
|
|
33
|
+
|
|
34
|
+
- name: Type check
|
|
35
|
+
run: uv run mypy src/
|
|
36
|
+
|
|
37
|
+
- name: Test
|
|
38
|
+
run: uv run pytest tests/ -q --tb=short
|
|
39
|
+
|
|
40
|
+
- name: Test with coverage
|
|
41
|
+
run: uv run pytest tests/ --cov=json_atom --cov-report=term-missing --cov-fail-under=90
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
name: Publish to PyPI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
tags:
|
|
6
|
+
- "v*.*.*"
|
|
7
|
+
|
|
8
|
+
permissions:
|
|
9
|
+
contents: read
|
|
10
|
+
|
|
11
|
+
jobs:
|
|
12
|
+
test:
|
|
13
|
+
name: Run tests
|
|
14
|
+
runs-on: ubuntu-latest
|
|
15
|
+
steps:
|
|
16
|
+
- uses: actions/checkout@v4
|
|
17
|
+
|
|
18
|
+
- uses: astral-sh/setup-uv@v5
|
|
19
|
+
with:
|
|
20
|
+
version: "latest"
|
|
21
|
+
|
|
22
|
+
- name: Install dependencies
|
|
23
|
+
run: uv sync --python 3.12
|
|
24
|
+
|
|
25
|
+
- name: Lint
|
|
26
|
+
run: uv run ruff check src/
|
|
27
|
+
|
|
28
|
+
- name: Type check
|
|
29
|
+
run: uv run mypy src/
|
|
30
|
+
|
|
31
|
+
- name: Test
|
|
32
|
+
run: uv run pytest tests/ -q --tb=short
|
|
33
|
+
|
|
34
|
+
build:
|
|
35
|
+
name: Build distribution
|
|
36
|
+
needs: test
|
|
37
|
+
runs-on: ubuntu-latest
|
|
38
|
+
steps:
|
|
39
|
+
- uses: actions/checkout@v4
|
|
40
|
+
|
|
41
|
+
- uses: astral-sh/setup-uv@v5
|
|
42
|
+
with:
|
|
43
|
+
version: "latest"
|
|
44
|
+
|
|
45
|
+
- name: Build wheel and sdist
|
|
46
|
+
run: uv build
|
|
47
|
+
|
|
48
|
+
- name: Upload dist artifacts
|
|
49
|
+
uses: actions/upload-artifact@v4
|
|
50
|
+
with:
|
|
51
|
+
name: dist
|
|
52
|
+
path: dist/
|
|
53
|
+
|
|
54
|
+
publish:
|
|
55
|
+
name: Publish to PyPI
|
|
56
|
+
needs: build
|
|
57
|
+
runs-on: ubuntu-latest
|
|
58
|
+
environment:
|
|
59
|
+
name: pypi
|
|
60
|
+
url: https://pypi.org/p/json-atom
|
|
61
|
+
permissions:
|
|
62
|
+
id-token: write # required for Trusted Publishing (OIDC)
|
|
63
|
+
steps:
|
|
64
|
+
- name: Download dist artifacts
|
|
65
|
+
uses: actions/download-artifact@v4
|
|
66
|
+
with:
|
|
67
|
+
name: dist
|
|
68
|
+
path: dist/
|
|
69
|
+
|
|
70
|
+
- name: Publish to PyPI
|
|
71
|
+
uses: pypa/gh-action-pypi-publish@release/v1
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
repos:
|
|
2
|
+
- repo: https://github.com/astral-sh/ruff-pre-commit
|
|
3
|
+
rev: v0.8.6
|
|
4
|
+
hooks:
|
|
5
|
+
- id: ruff
|
|
6
|
+
args: [--fix]
|
|
7
|
+
- id: ruff-format
|
|
8
|
+
|
|
9
|
+
- repo: https://github.com/pre-commit/mirrors-mypy
|
|
10
|
+
rev: v1.14.1
|
|
11
|
+
hooks:
|
|
12
|
+
- id: mypy
|
|
13
|
+
additional_dependencies: []
|
|
14
|
+
args: [--strict]
|
|
15
|
+
pass_filenames: false
|
|
16
|
+
entry: mypy src/
|
|
17
|
+
|
|
18
|
+
- repo: local
|
|
19
|
+
hooks:
|
|
20
|
+
- id: pytest
|
|
21
|
+
name: pytest
|
|
22
|
+
entry: uv run pytest tests/ -q
|
|
23
|
+
language: system
|
|
24
|
+
pass_filenames: false
|
|
25
|
+
always_run: true
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
# CLAUDE.md — Developer Guide for json-atom-py
|
|
2
|
+
|
|
3
|
+
## Build & Test Commands
|
|
4
|
+
|
|
5
|
+
```bash
|
|
6
|
+
uv sync # Install dependencies
|
|
7
|
+
uv run pytest tests/ # Run all tests
|
|
8
|
+
uv run pytest tests/ -v # Verbose output
|
|
9
|
+
uv run pytest tests/ --cov=json_atom # With coverage
|
|
10
|
+
uv run ruff check src/ # Lint
|
|
11
|
+
uv run mypy src/ # Type check
|
|
12
|
+
uv run python examples/keyed_arrays.py # Run an example
|
|
13
|
+
uv build # Build wheel + sdist
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
## Project Structure
|
|
17
|
+
|
|
18
|
+
```
|
|
19
|
+
src/json_atom/
|
|
20
|
+
__init__.py # Public API re-exports and __all__
|
|
21
|
+
errors.py # Exception hierarchy (JsonDeltaError → PathError, ApplyError, etc.)
|
|
22
|
+
models.py # PathSegment dataclasses, ValidationResult, ChangeType, ComparisonNode, Delta/Operation
|
|
23
|
+
_utils.py # Internal helpers: json_equal, json_type_of
|
|
24
|
+
_identity.py # Shared identity resolution (IdentityResolver, resolve_identity, extract_identity)
|
|
25
|
+
path.py # Path parser/builder + describe_path, resolve_path
|
|
26
|
+
validate.py # Structural validation (validate_delta)
|
|
27
|
+
apply.py # Delta application (apply_delta)
|
|
28
|
+
invert.py # Delta inversion (invert_delta, revert_delta)
|
|
29
|
+
diff.py # Delta computation (diff_delta) — callable keys, regex routing, exclude_paths
|
|
30
|
+
compare.py # Enriched comparison tree (compare) — visual diff rendering
|
|
31
|
+
json_patch.py # JSON Patch (RFC 6902) interop: to_json_patch, from_json_patch
|
|
32
|
+
py.typed # PEP 561 marker
|
|
33
|
+
|
|
34
|
+
tests/
|
|
35
|
+
conftest.py # Shared helpers: load_fixture, deep_clone
|
|
36
|
+
fixtures/ # Conformance fixtures from json-atom-format repo
|
|
37
|
+
test_models.py # PathSegment, ValidationResult, Delta/Operation types
|
|
38
|
+
test_utils.py # json_equal edge cases (bool vs int, int vs float)
|
|
39
|
+
test_path.py # Path parser/builder, describe_path, resolve_path
|
|
40
|
+
test_validate.py # Delta validation
|
|
41
|
+
test_apply.py # Delta application + Level 1 conformance
|
|
42
|
+
test_invert.py # Inversion + revert round-trips
|
|
43
|
+
test_extensions.py # Extension property preservation
|
|
44
|
+
test_conformance.py # Level 1 + Level 2 conformance fixtures
|
|
45
|
+
test_diff.py # Diff computation + all identity models + callable/regex/exclude_paths
|
|
46
|
+
test_compare.py # Enriched comparison tree tests
|
|
47
|
+
test_cross_validation.py # Cross-validation with json-diff-ts
|
|
48
|
+
test_edge_cases.py # Cross-module edge cases
|
|
49
|
+
test_json_patch.py # JSON Patch (RFC 6902) interop
|
|
50
|
+
test_pydantic.py # Pydantic v2 integration (conditional on pydantic)
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
## Architecture
|
|
54
|
+
|
|
55
|
+
- **Zero runtime dependencies** — uses only stdlib (re, copy, math, dataclasses)
|
|
56
|
+
- **Delta/Operation are dict subclasses** — typed property access (`delta.operations`, `op.path`) + full dict compat (`json.dumps`, `[]` access, extensions)
|
|
57
|
+
- **Extension properties** accessible as attributes (`op.x_editor`) or dict syntax (`op["x_editor"]`), via `__getattr__` fallback. `op.extensions` returns all non-spec keys
|
|
58
|
+
- **Pydantic v2 native** — `__get_pydantic_core_schema__` on both classes, zero runtime dependency on pydantic. Use as `BaseModel` fields without `arbitrary_types_allowed`
|
|
59
|
+
- **Cached properties** — `op.segments` and `op.filter_values` are `cached_property` (parsed once per instance)
|
|
60
|
+
- **Path segments are frozen dataclasses** — immutable, hashable, printable
|
|
61
|
+
- **apply_delta mutates in place** — always use the return value (root ops return new objects)
|
|
62
|
+
- **json_equal handles Python's bool⊂int** — `True != 1` in JSON semantics
|
|
63
|
+
|
|
64
|
+
## Spec Compliance
|
|
65
|
+
|
|
66
|
+
- **Specification**: [JSON Atom v0](https://github.com/ltwlf/json-atom-format/blob/main/spec/v0.md)
|
|
67
|
+
- **Conformance**: Level 2 (Apply + Reversible) — passes all fixtures
|
|
68
|
+
- **Spec is source of truth** — when spec and TypeScript reference diverge, follow the spec
|
|
69
|
+
- **Spec-faithful divergence from TS**: digit-after-dot (`$.items.0`) is a PathError per spec grammar
|
|
70
|
+
- **remove without oldValue**: valid per spec (OPTIONAL), unlike TS which requires it
|
|
71
|
+
|
|
72
|
+
## Coding Conventions
|
|
73
|
+
|
|
74
|
+
- Python 3.12+ — uses `type` statement, `X | Y` union syntax, `@dataclass(slots=True)`
|
|
75
|
+
- Strict mypy on library source (`uv run mypy src/`; tests are not strict-checked)
|
|
76
|
+
- Ruff for linting (line-length=120)
|
|
77
|
+
- All public functions have docstrings
|
|
78
|
+
- Tests organized by module with descriptive class names
|
json_atom-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Christian Glessner
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|