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
json-cas/packages/json-cas-fs/README.md

1.7 KiB

@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