This repository has been archived on 2026-06-01. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
xiaoju 7242588dd9 feat: implement RFC-20 Phase 3 GC integration
Implements garbage collection (GC) with mark-and-sweep algorithm:
- Mark phase: recursively walks references from all variable values (global, not scoped)
- Sweep phase: deletes unmarked CAS nodes
- Schema preservation: schemas referenced by reachable nodes are preserved
- Bootstrap preservation: self-referencing meta-schema always preserved

New features:
- Core gc() function in packages/json-cas/src/gc.ts with GcStats interface
- Extended Store interface with listAll() and delete() methods
- CLI command: json-cas gc (outputs JSON stats)
- Comprehensive test suite with 16 test scenarios

Implements: #23

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-05-30 08:16:20 +00:00
..
2026-05-25 13:10:49 +00:00

@uncaged/json-cas-fs

Filesystem-backed CAS store.

Overview

@uncaged/json-cas-fs implements a persistent Store on disk. Each node is stored as <hash>.bin (CBOR-encoded CasNode). A _index/ directory maps type hashes to content hashes for listByType. Stores support bootstrap via the same BOOTSTRAP_STORE symbol as the in-memory implementation.

Depends on @uncaged/json-cas for hashing, CBOR encoding, and types.

Dependencies: @uncaged/json-cas, cborg

Installation

bun add @uncaged/json-cas-fs

API

Exported from src/index.ts:

function createFsStore(dir: string): BootstrapCapableStore;

Returns a BootstrapCapableStore from @uncaged/json-cas. The store loads existing .bin files on open and migrates or builds the type index on first use.

Example

import { bootstrap, putSchema } from "@uncaged/json-cas";
import { createFsStore } from "@uncaged/json-cas-fs";

const store = createFsStore("./my-cas-store");
await bootstrap(store);

const typeHash = await putSchema(store, {
  type: "object",
  properties: { id: { type: "string" } },
  required: ["id"],
  additionalProperties: false,
});

const hash = await store.put(typeHash, { id: "item-1" });
console.log(store.has(hash)); // true after restart if same dir

On-disk layout

my-cas-store/
├── <hash>.bin          # CBOR CasNode
├── _index/
│   └── <typeHash>      # newline-separated content hashes
└── ...

Writes use atomic rename (<hash>.tmp<hash>.bin).

Internal Structure

File Purpose
store.ts createFsStore, load/save nodes and type index
index.ts Public export
store.test.ts Filesystem store tests