feat: RFC-20 Phase 1 - Variable CRUD Operations #25

Merged
xiaonuo merged 1 commits from fix/21-variable-crud into main 2026-05-30 06:22:44 +00:00
Owner

What

Implements RFC-20 Phase 1: Variable CRUD system for json-cas, providing mutable named bindings to immutable CAS nodes.

Why

Users need a way to:

  • Create named references to CAS nodes
  • Update variable values while maintaining type safety
  • Organize variables hierarchically using scopes
  • Persist variable state across sessions

Changes

New Components

  1. Variable Type System (packages/json-cas/src/variable.ts)

    • ULID-based identifiers (26-char Crockford Base32)
    • Variable structure: id, scope, value, schema, created, updated
  2. VariableStore (packages/json-cas/src/variable-store.ts)

    • SQLite-backed persistence (~/.uncaged/json-cas/variables.db)
    • CRUD operations: create, get, update, delete
    • Scope validation (must end with /)
    • Schema validation on updates (prevents type mismatches)
    • Custom error types: VariableNotFoundError, SchemaMismatchError, InvalidScopeError, CasNodeNotFoundError
  3. CLI Commands (packages/cli-json-cas/src/index.ts)

    • json-cas var create --scope --value - Create variable
    • json-cas var get - Retrieve variable
    • json-cas var update - Update variable value
    • json-cas var delete - Delete variable

Tests

  • 16 unit tests in variable-store.test.ts - Core functionality
  • 12 CLI integration tests in var.test.ts - End-to-end validation
  • All 158 tests pass (100% pass rate)

Dependencies

  • Added ulidx (v2.4.1) for ULID generation

Test Coverage

All test scenarios from spec (CAS: DTMAXD3FVH85Z) verified:

  • Variable creation with scope validation
  • Retrieval of existing/non-existent variables
  • Updates with matching schemas
  • Rejection of schema mismatches
  • Idempotent deletion
  • Full lifecycle integration tests
  • Hierarchical scope support

Code Quality

  • TypeScript strict mode compliance
  • Biome lint: no errors
  • Build: clean
  • No console.log in production code
  • Proper import/export conventions
  • Comprehensive error handling

Ref

Fixes #21

🤖 Generated with Claude Code

## What Implements RFC-20 Phase 1: Variable CRUD system for json-cas, providing mutable named bindings to immutable CAS nodes. ## Why Users need a way to: - Create named references to CAS nodes - Update variable values while maintaining type safety - Organize variables hierarchically using scopes - Persist variable state across sessions ## Changes ### New Components 1. **Variable Type System** (packages/json-cas/src/variable.ts) - ULID-based identifiers (26-char Crockford Base32) - Variable structure: id, scope, value, schema, created, updated 2. **VariableStore** (packages/json-cas/src/variable-store.ts) - SQLite-backed persistence (~/.uncaged/json-cas/variables.db) - CRUD operations: create, get, update, delete - Scope validation (must end with /) - Schema validation on updates (prevents type mismatches) - Custom error types: VariableNotFoundError, SchemaMismatchError, InvalidScopeError, CasNodeNotFoundError 3. **CLI Commands** (packages/cli-json-cas/src/index.ts) - json-cas var create --scope <scope> --value <hash> - Create variable - json-cas var get <id> - Retrieve variable - json-cas var update <id> <hash> - Update variable value - json-cas var delete <id> - Delete variable ### Tests - 16 unit tests in variable-store.test.ts - Core functionality - 12 CLI integration tests in var.test.ts - End-to-end validation - All 158 tests pass (100% pass rate) ### Dependencies - Added ulidx (v2.4.1) for ULID generation ## Test Coverage All test scenarios from spec (CAS: DTMAXD3FVH85Z) verified: - Variable creation with scope validation - Retrieval of existing/non-existent variables - Updates with matching schemas - Rejection of schema mismatches - Idempotent deletion - Full lifecycle integration tests - Hierarchical scope support ## Code Quality - TypeScript strict mode compliance - Biome lint: no errors - Build: clean - No console.log in production code - Proper import/export conventions - Comprehensive error handling ## Ref Fixes #21 🤖 Generated with [Claude Code](https://claude.com/claude-code)
xiaoju added 1 commit 2026-05-30 06:03:38 +00:00
Add a complete variable system for json-cas that provides mutable named
bindings to immutable CAS nodes.

Features:
- ULID-based variable identifiers (26-char Crockford Base32)
- Hierarchical scope validation (must end with /)
- Schema validation on update (prevents type mismatches)
- SQLite persistence (~/.uncaged/json-cas/variables.db)
- CLI commands: var create, get, update, delete

Implementation:
- Core types in variable.ts (Variable, VariableId)
- VariableStore class with SQLite backend
- Custom error types (VariableNotFoundError, SchemaMismatchError, etc.)
- Comprehensive unit tests (16 tests)
- CLI integration tests (12 tests)
- All outputs use JSON format

Test coverage:
- Variable creation with scope validation
- CRUD operations (create, read, update, delete)
- Schema consistency enforcement
- Error handling for all edge cases
- Full lifecycle integration tests

All tests pass (158 total), build clean, lint clean.

Fixes #21

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
xiaonuo merged commit 76dab6737c into main 2026-05-30 06:22:44 +00:00
This repo is archived. You cannot comment on pull requests.
No Reviewers
No Label
1 Participants
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: uncaged/json-cas#25