Files
ocas/packages/fs/README.md
T
xiaoju 1edb09a8b0 feat: rebrand json-cas → OCAS (Object Content Addressable Store)
- Rename packages: @uncaged/json-cas → @ocas/core, @uncaged/json-cas-fs → @ocas/fs, @uncaged/cli-json-cas → @ocas/cli
- Rename dirs: packages/json-cas → core, json-cas-fs → fs, cli-json-cas → cli
- CLI binary: ocas (removed json-cas and ucas aliases)
- Default store: ~/.ocas (was ~/.uncaged/json-cas)
- Update all imports, tsconfig, biome, docs, tests, snapshots
- Changeset config targets @ocas org and shazhou-ww/ocas GitHub

Closes #3, Closes #4, Closes #5, Closes #6, Closes #7
2026-06-01 06:21:56 +00:00

1.6 KiB

@ocas/fs

Filesystem-backed CAS store.

Overview

@ocas/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 @ocas/core for hashing, CBOR encoding, and types.

Dependencies: @ocas/core, cborg

Installation

bun add @ocas/fs

API

Exported from src/index.ts:

function createFsStore(dir: string): BootstrapCapableStore;

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

Example

import { bootstrap, putSchema } from "@ocas/core";
import { createFsStore } from "@ocas/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