Skip to content
Moku
@moku-labs/ai pages

store

The content-addressed artifact store: durable writes, verified reads and gc. Injected as ctx.store.

On this page

What it does

Core plugin. store keeps artifact bytes under their sha256, at {dir}/{hash[0..2]}/{hash}. A write goes to a temp file, then fsync, rename and an fsync of the folder. The same bytes are stored once.

Config

pluginConfigs.store.

OptionTypeDefaultDescription
dirstring".moku/store"The root folder. Created on the first put.
algo"sha256""sha256"The only value today.

API

Mounted at app.store and ctx.store. A malformed hash throws.

MethodSignatureDescription
put(content: Uint8Array) => Promise<PutResult>{ hash, path, existed }.
has(hash: string) => Promise<boolean>Whether the object exists.
pathOf(hash: string) => stringThe absolute path. Does not check it.
read(hash: string) => Promise<Uint8Array>The bytes, with the hash verified.
hashOf(content: Uint8Array) => stringThe hash, with no write.
gc(keep: ReadonlySet<string>) => Promise<GcResult>Removes every object not in keep. { removed, bytesFreed }.
read.ts
import { app } from "./app";

await app.start();
const { hash } = await app.store.put(new TextEncoder().encode("hello"));
console.log(new TextDecoder().decode(await app.store.read(hash)));
await app.stop();

Events

Emits

None.

Listens to

None.

Depends on

Nothing.