23 Commits

Author SHA1 Message Date
xiaoju 1bd4edbdd1 fix: disable pnpm minimumReleaseAge in CI
CI / check (pull_request) Failing after 1m21s
pnpm 11 defaults minimumReleaseAge to 1440 min. Set to 0 in
pnpm-workspace.yaml for our own packages.
2026-06-04 10:13:46 +00:00
xiaoju 49f096b18f fix: use corepack for pnpm in CI
CI / check (pull_request) Failing after 32s
Drop pnpm/action-setup (requires explicit version), use corepack enable instead.
Also align Node to 22 (consistent with uwf).

Closes #76
2026-06-04 10:07:28 +00:00
xiaoju 6b9ebd1796 chore: add Gitea CI workflow (build + lint + test)
CI / check (pull_request) Failing after 1m18s
小橘 🍊(NEKO Team)
2026-06-04 09:36:51 +00:00
xiaomo b3879c583a Merge pull request 'chore: use proman test instead of vitest run' (#75) from chore/proman-test-script into main
chore: use proman test instead of vitest run (#75)
2026-06-04 01:57:23 +00:00
xingyue 01d4f0fa14 chore: use proman test instead of vitest run 2026-06-04 09:51:30 +08:00
xiaomo d79d0227fa Merge pull request 'fix: resolve prompt files from package root instead of dist' (#74) from fix/prompt-path into main
fix: resolve prompt files from package root, suppress ExperimentalWarning in tests (#74)
2026-06-04 00:38:14 +00:00
tuanzi e4e4ce0f73 fix: suppress SQLite ExperimentalWarning in edge-cases and schema-validation tests
The local runCli helpers in edge-cases.test.ts (Phase 3/4/7) and raw
execFileSync calls in schema-validation.test.ts (tests 2.1, 2.3) were
missing NODE_NO_WARNINGS=1, causing ExperimentalWarning to leak into
stderr snapshots. Added env override to match what helpers.runCli
already does.
2026-06-04 00:36:38 +00:00
tuanzi 13b12ef50c fix: resolve prompt files from package root instead of dist
prompts/*.md files are not copied to dist/ during tsc build,
causing `ocas prompt setup/usage` to fail with ENOENT.

- Change join(__dirname, "prompts") → join(__dirname, "..", "prompts")
- Add prompts/ to package.json "files" for npm publishing
- Update snapshots (Node.js SQLite ExperimentalWarning + version string)
2026-06-04 00:11:28 +00:00
xiaomo a9d43abf28 release: @ocas/cli@0.3.1 2026-06-04 00:01:29 +00:00
xiaomo 6f054f6447 fix(cli): update prompts — bun→pnpm, remove stale --var-db flag 2026-06-03 23:49:11 +00:00
xiaomo 5e9b266ebd docs: add pkg descriptions/keywords/engines, fix core README
Fixes #70, #71, #72, #73
2026-06-03 23:23:48 +00:00
xiaomo c4d9205eb2 docs: update all documentation for node:sqlite, pnpm, proman workflow
- README: bun → pnpm, update API examples, add Node >=22.5.0 requirement
- CLAUDE.md: replace 3-phase release process with proman bump/publish
- Package READMEs: fix package names, update storage/API descriptions
- Cards: update store.md (sqlite), cli.md (db filename, remove --var-db)
- docs/sync-readme.md: update to proman workflow
2026-06-03 23:21:30 +00:00
xiaoju 9d17be8b7b release: v0.3.0 2026-06-03 23:06:00 +00:00
xiaomo 7e9bd26fec fix: suppress ExperimentalWarning in tests via NODE_NO_WARNINGS env
- Use NODE_NO_WARNINGS=1 in execFileSync env instead of --no-warnings flag
- Remove overly broad process.removeAllListeners('warning') from CLI entry
- Add engines field requiring Node >=22.5.0 (node:sqlite availability)
- Update proman to 0.4.2
2026-06-03 23:02:43 +00:00
xiaomo 3168bf55c3 chore: add changeset for node:sqlite migration 2026-06-03 22:30:15 +00:00
xiaomo 00a536631a refactor: migrate from better-sqlite3 to node:sqlite
- Replace better-sqlite3 with built-in node:sqlite (DatabaseSync)
- Add transaction() helper for manual BEGIN/COMMIT/ROLLBACK
- Suppress ExperimentalWarning in CLI tests with --no-warnings
- Remove better-sqlite3 from dependencies and onlyBuiltDependencies
- No more native addon compilation issues across Node versions
2026-06-03 22:11:44 +00:00
xiaomo f8103e20ce chore: bump @shazhou/proman to 0.4.0, remove link override 2026-06-03 16:30:24 +00:00
xiaomo 5c567dc455 Revert "Merge pull request 'chore: remove redundant vite/vitest devDeps' (#69) from chore/remove-redundant-devdeps into main"
This reverts commit 08a2bddcf0, reversing
changes made to 36ebf42f2f.
2026-06-03 15:15:38 +00:00
xiaomo 08a2bddcf0 Merge pull request 'chore: remove redundant vite/vitest devDeps' (#69) from chore/remove-redundant-devdeps into main 2026-06-03 14:28:35 +00:00
xiaomo 6fc3b9030b chore: remove redundant vite/vitest devDeps (proman bundles them) 2026-06-03 14:25:35 +00:00
xiaoju 36ebf42f2f chore: bump 0.2.2, fix lint, biome format
- Bump all packages to 0.2.2
- Fix noNonNullAssertion in cli/index.ts
- Fix unused imports in fs/sqlite-store.ts
- Biome 2.4.16 migration + format all files
- Update snapshots for version change
2026-06-03 11:16:16 +00:00
xiaoju f286df91f0 chore: restore workspace:* 2026-06-03 09:43:57 +00:00
xiaoju 8971206a3e Merge release/0.2.1 into main 2026-06-03 09:43:37 +00:00
52 changed files with 734 additions and 1715 deletions
+1 -1
View File
@@ -17,7 +17,7 @@ The `ocas` CLI is the primary interface for interacting with an OCAS [[Store]].
| 2 | `OCAS_HOME` env var | `export OCAS_HOME=/data/ocas` |
| 3 | Default | `~/.ocas` |
The variable database lives at `<home>/variables.db` by default, overridable with `--var-db <path>`.
The SQLite database lives at `<home>/_store.db`.
## Commands
+1 -1
View File
@@ -53,7 +53,7 @@ In-memory `Map<Hash, CasNode>`. Used in tests and for ephemeral computation (e.g
### FsStore (`@ocas/fs`)
Filesystem-backed store. Nodes are serialized as CBOR files under a content-addressed directory tree. Created via `openStore(path)`, which:
Filesystem-backed store. CAS nodes are stored as CBOR files; variables and tags use SQLite (`node:sqlite`). Created via `openStore(path)`, which:
1. Creates the directory if it doesn't exist
2. Runs [[Bootstrap]] automatically
+28
View File
@@ -0,0 +1,28 @@
name: CI
on:
push:
branches: ['*']
pull_request:
branches: [main]
jobs:
check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 22
- run: corepack enable && pnpm install
- name: Build
run: pnpm run build
- name: Lint
run: pnpm run check
- name: Test
run: pnpm run test
+9 -41
View File
@@ -20,7 +20,7 @@ Monorepo with 3 packages under `packages/`:
- **Test:** Vitest (`npx vitest run`)
- **Package Manager:** pnpm (workspace)
- **Lint/Format:** Biome (`biome check .` / `biome format --write .`)
- **Publish:** Changesets + `pnpm publish` → npmjs (`@ocas/*`)
- **Publish:** @shazhou/proman (`proman bump` + `proman publish`)
## Commands
@@ -98,10 +98,7 @@ This is resolved to real version numbers only during publishing (see below).
## Release Process
Releases use a **release branch** workflow with three phases: prepare → candidate → finalize.
`main` always keeps `workspace:*` for internal deps; release branches fix them to real versions.
Changeset files are **only consumed once** during finalize — prerelease (rc) never touches them.
Uses `@shazhou/proman` for releases. No release branches needed.
### Adding a Changeset
@@ -110,7 +107,7 @@ Add changesets alongside feature PRs on `main`:
```markdown
<!-- .changeset/my-change.md -->
---
"@ocas/cli": patch
"@ocas/fs": minor
---
Description of the change
@@ -119,44 +116,15 @@ Description of the change
Changesets live in `.changeset/` as markdown files. Bump types: `patch` / `minor` / `major`.
One changeset can cover multiple packages.
### Phase 1: Prepare (cut release branch)
### Release Steps
- **Precondition:** on `main`, clean tree, `.changeset/` has pending changesets
- **Steps:**
1. Determine target version (from changeset bump types or manually)
2. `git checkout -b release/<version>`
3. Fix `workspace:*` → real version numbers in all `package.json`
4. Commit
- **Does NOT** run `changeset version`, does NOT write CHANGELOG
1. `proman bump` — consume changesets and bump versions
2. `proman publish` — build → test → check → publish → changelog → tag → push
### Phase 2: Candidate (publish rc for validation)
- **Precondition:** on `release/*` branch
- **Steps:**
1. Set version to `<version>-rc.N` (first time rc.1, increment on subsequent runs)
2. `pnpm install && pnpm run build && pnpm run test && pnpm run check`
3. Publish: `pnpm publish --tag rc` (order: core → fs → cli)
4. Commit + push
- **Repeatable:** fix bugs → add new changesets on the release branch → rc.N+1
- **Does NOT** consume changesets, does NOT write CHANGELOG
- Install for testing: `pnpm add -g @ocas/cli@rc`
### Phase 3: Finalize (official release)
- **Precondition:** on `release/*` branch, rc validated
- **Steps:**
1. Consume all `.changeset/*.md` → write CHANGELOG entries (use `changeset version` or manual)
2. Set final version `<version>` (remove `-rc.N`)
3. `pnpm install && pnpm run build && pnpm run test && pnpm run check`
4. Publish: `pnpm publish --tag latest` (order: core → fs → cli)
5. Git tag `v<version>`
6. Merge back to `main` (CHANGELOG comes along)
7. Restore `workspace:*` on `main`
8. Delete release branch
The publish command handles everything: workspace dependency resolution, npm publish order (core → fs → cli), changelog generation, git tagging, and pushing.
### Key Rules
- **Publish order** is always `@ocas/core``@ocas/fs``@ocas/cli`
- **`workspace:*`** must be fixed before any publish — `pnpm publish` does NOT auto-replace them
- **CHANGELOG** only contains official releases, never rc entries
- **Changesets added on release branch** (bug fixes during rc) are consumed together at finalize
- **`workspace:*`** is auto-resolved by pnpm during publish
- **CHANGELOG** only contains official releases
+12 -10
View File
@@ -7,11 +7,13 @@ Every node has a typed payload: its `type` field is the hash of a JSON Schema th
## Install
```bash
bun add -g @ocas/cli
pnpm add -g @ocas/cli
```
The store is auto-created and bootstrapped on first use — no `init` command needed.
> Requires Node.js >= 22.5.0 (uses built-in node:sqlite)
## Quick Start
```bash
@@ -190,8 +192,8 @@ Nodes reachable from any variable binding are kept; everything else is swept.
## Using as a Library
```bash
bun add @ocas/core # in-memory store
bun add @ocas/core @ocas/fs # + filesystem persistence
pnpm add @ocas/core # in-memory store
pnpm add @ocas/core @ocas/fs # + filesystem persistence
```
```typescript
@@ -214,9 +216,9 @@ const node = store.get(hash);
For filesystem persistence, use `@ocas/fs`:
```typescript
import { openStoreAndVarStore } from "@ocas/fs";
import { openStore } from "@ocas/fs";
const { store, varStore } = await openStoreAndVarStore("/path/to/store");
const store = await openStore("/path/to/store");
```
See individual package READMEs for full API docs:
@@ -228,11 +230,11 @@ See individual package READMEs for full API docs:
```bash
git clone <repo-url> && cd ocas
bun install --no-cache
bun run build # tsc --build
bun test # run all tests
bun run check # biome lint
bun run format # biome format
pnpm install
pnpm run build # tsc --build
pnpm test # run all tests
pnpm run check # biome lint
pnpm run format # biome format
```
## License
+4 -4
View File
@@ -17,8 +17,8 @@ The root README should have these sections in order:
4. **Packages** — table with ALL packages from packages/ directory, columns: Package, Description, Type (cli/lib)
5. **Quick Start** — install, build, basic usage
6. **CLI Reference** — brief command list, detailed usage in cli README
7. **Development**bun install / build / check / test
8. **Publishing**changeset workflow (bun run release)
7. **Development**pnpm install / build / check / test
8. **Publishing**`proman bump` + `proman publish`
## Per-Package README Structure
@@ -27,7 +27,7 @@ Each package README should have:
1. **Title** — package name
2. **One-line description** — matching package.json
3. **Overview** — what it does, where it sits in the architecture, dependencies
4. **Installation**bun add (for libs) or "included as binary" (for cli)
4. **Installation**pnpm add (for libs) or "included as binary" (for cli)
5. **API** (lib packages) — all exports from src/index.ts with type signatures, grouped by category, minimal usage examples
6. **CLI Usage** (cli packages) — command reference with examples
7. **Internal Structure** — brief src/ file organization
@@ -57,7 +57,7 @@ For each package read:
- All relative links work
- Package names match package.json
- No references to removed/renamed packages
- bun run build still passes
- pnpm run build still passes
## Guidelines
+10 -5
View File
@@ -2,16 +2,18 @@
"name": "@ocas/workspace",
"private": true,
"devDependencies": {
"@shazhou/proman": "0.2.2",
"@biomejs/biome": "^2.4.16",
"@shazhou/proman": "0.4.2",
"@types/node": "^25.9.1",
"tsx": "^4.22.4",
"typescript": "^6.0.3",
"ulidx": "^2.4.1",
"vite": "^8.0.16",
"vitest": "^4.1.8"
},
"scripts": {
"build": "proman build",
"test": "vitest run",
"test": "proman test",
"check": "proman check",
"format": "proman format"
},
@@ -20,13 +22,16 @@
"url": "https://github.com/shazhou-ww/ocas.git"
},
"homepage": "https://github.com/shazhou-ww/ocas",
"engines": {
"node": ">=22.5.0"
},
"bugs": {
"url": "https://github.com/shazhou-ww/ocas/issues"
},
"pnpm": {
"onlyBuiltDependencies": [
"esbuild",
"better-sqlite3"
]
"esbuild"
],
"overrides": {}
}
}
+6
View File
@@ -1,5 +1,11 @@
# @ocas/cli
## 0.3.1
### Patch Changes
- Fix prompt docs: `bun``pnpm` install instructions, remove stale `--var-db` flag from usage docs.
## 0.2.0
### Breaking Changes
+4 -4
View File
@@ -15,17 +15,17 @@ The store is **auto-created and bootstrapped** on first use, so there is no `ini
Published as an npm package with a binary entry:
```bash
bun add -g @ocas/cli
pnpm add -g @ocas/cli
# or from the monorepo workspace:
bun link
pnpm link
```
**Binary name:** `ocas` (points to `src/index.ts`, run with Bun).
**Binary name:** `ocas` (points to `dist/index.js`, run with Node).
In development:
```bash
bun packages/cli-ocas/src/index.ts <command> [args]
node packages/cli/dist/index.js <command> [args]
```
## CLI Usage
+16 -3
View File
@@ -1,13 +1,26 @@
{
"name": "@ocas/cli",
"version": "0.2.1",
"version": "0.3.1",
"description": "CLI for OCAS content-addressed store",
"keywords": [
"cas",
"cli",
"content-addressing"
],
"engines": {
"node": ">=22.5.0"
},
"type": "module",
"bin": {
"ocas": "dist/index.js"
},
"files": [
"dist",
"prompts"
],
"dependencies": {
"@ocas/core": "0.2.1",
"@ocas/fs": "0.2.1"
"@ocas/core": "workspace:*",
"@ocas/fs": "workspace:*"
},
"repository": {
"type": "git",
+1 -1
View File
@@ -9,7 +9,7 @@ so that you know how to use the `ocas` CLI.
```bash
ocas --help
```
If not installed: `bun add -g @ocas/cli`
If not installed: `pnpm add -g @ocas/cli`
2. **Clean up old versions of the skill** (if any exist):
- Look for any existing OCAS/ocas skill files in your skill directories
+1 -2
View File
@@ -6,7 +6,7 @@ OCAS is a self-describing content-addressable store for typed JSON data. Every n
All commands output `{ type, value }` JSON envelopes, making them composable via pipes.
**Install:** `bun add -g @ocas/cli`
**Install:** `pnpm add -g @ocas/cli`
**Packages:** `@ocas/core` (engine) · `@ocas/fs` (filesystem store) · `@ocas/cli` (CLI)
@@ -138,7 +138,6 @@ ocas gc | ocas render -p # human-readable stats
| Flag | Description |
|------|-------------|
| `--home <path>` | Store directory (default: `$OCAS_HOME` or `~/.ocas`) |
| `--var-db <path>` | Variable database path |
| `--json` | Compact JSON output |
| `-p`, `--pipe` | Read from stdin |
| `-r`, `--render` | Render output inline |
+5 -4
View File
@@ -1,11 +1,12 @@
#!/usr/bin/env node
import { existsSync, readFileSync } from "node:fs";
import { fileURLToPath } from "node:url";
import { homedir } from "node:os";
import { dirname, join, resolve } from "node:path";
import { fileURLToPath } from "node:url";
const __dirname = dirname(fileURLToPath(import.meta.url));
import type { Hash, ListEntry, ListOptions, Store, TagOp } from "@ocas/core";
import {
applyListOptions,
@@ -1040,7 +1041,7 @@ async function cmdList(_args: string[]): Promise<void> {
...(opts.desc !== undefined ? { desc: opts.desc } : {}),
});
const filtered: ListEntry[] = allOfType.filter((e) =>
intersection!.has(e.hash),
intersection?.has(e.hash),
);
const paged = applyListOptions(filtered, opts);
await out(await wrapEnvelope(store, "@ocas/output/list", paged), store);
@@ -1233,7 +1234,7 @@ switch (cmd) {
switch (sub) {
case "usage": {
const content = readFileSync(
join(__dirname, "prompts", "usage.md"),
join(__dirname, "..", "prompts", "usage.md"),
"utf-8",
);
process.stdout.write(content);
@@ -1241,7 +1242,7 @@ switch (cmd) {
}
case "setup": {
const content = readFileSync(
join(__dirname, "prompts", "setup.md"),
join(__dirname, "..", "prompts", "setup.md"),
"utf-8",
);
process.stdout.write(content);
@@ -375,381 +375,6 @@ exports[`Phase 3: Variable System > 3.10 var delete removes variable 1`] = `
exports[`Phase 3: Variable System > 3.11 var get deleted variable returns not found 1`] = `"Error: Variable not found: name=@myapp/config, schema=FRBAB1BF0ZBCS"`;
exports[`Phase 3: Variable System 3.1 var set creates variable 1`] = `
{
"type": "0Q5EMYK4SYSS9",
"value": {
"labels": [],
"name": "@myapp/config",
"schema": "FRBAB1BF0ZBCS",
"tags": {},
"value": "9W3MGR3184QYE",
},
}
`;
exports[`Phase 3: Variable System 3.2 var get returns variable 1`] = `
{
"type": "F5RRJTXP8Z99D",
"value": {
"labels": [],
"name": "@myapp/config",
"schema": "FRBAB1BF0ZBCS",
"tags": {},
"value": "9W3MGR3184QYE",
},
}
`;
exports[`Phase 3: Variable System 3.3 var list shows all variables 1`] = `
{
"type": "AF0XACGXHPMC1",
"value": [
{
"labels": [],
"name": "@myapp/config",
"schema": "FRBAB1BF0ZBCS",
"tags": {},
"value": "9W3MGR3184QYE",
},
{
"labels": [],
"name": "@ocas/array",
"schema": "CTS5P6RD8HMCS",
"tags": {},
"value": "D45CW047XS17Y",
},
{
"labels": [],
"name": "@ocas/bool",
"schema": "CTS5P6RD8HMCS",
"tags": {},
"value": "1AVHCXEJVDCPP",
},
{
"labels": [],
"name": "@ocas/boolean",
"schema": "CTS5P6RD8HMCS",
"tags": {},
"value": "1AVHCXEJVDCPP",
},
{
"labels": [],
"name": "@ocas/integer",
"schema": "CTS5P6RD8HMCS",
"tags": {},
"value": "B26JM4PBHPAFK",
},
{
"labels": [],
"name": "@ocas/null",
"schema": "CTS5P6RD8HMCS",
"tags": {},
"value": "8E33KAS0HMAZ7",
},
{
"labels": [],
"name": "@ocas/number",
"schema": "CTS5P6RD8HMCS",
"tags": {},
"value": "BEAZQGKVXMZT8",
},
{
"labels": [],
"name": "@ocas/object",
"schema": "CTS5P6RD8HMCS",
"tags": {},
"value": "944RT37WX1PQ5",
},
{
"labels": [],
"name": "@ocas/output/gc",
"schema": "CTS5P6RD8HMCS",
"tags": {},
"value": "7KHZTY010988K",
},
{
"labels": [],
"name": "@ocas/output/get",
"schema": "CTS5P6RD8HMCS",
"tags": {},
"value": "7V5G8E2VW8B2G",
},
{
"labels": [],
"name": "@ocas/output/has",
"schema": "CTS5P6RD8HMCS",
"tags": {},
"value": "FHXQQZMVHW924",
},
{
"labels": [],
"name": "@ocas/output/hash",
"schema": "CTS5P6RD8HMCS",
"tags": {},
"value": "1B24CBF95Q5G6",
},
{
"labels": [],
"name": "@ocas/output/list",
"schema": "CTS5P6RD8HMCS",
"tags": {},
"value": "7BWZ3JKKMSH4N",
},
{
"labels": [],
"name": "@ocas/output/list-meta",
"schema": "CTS5P6RD8HMCS",
"tags": {},
"value": "1WQ7C0EV8QGA4",
},
{
"labels": [],
"name": "@ocas/output/list-schema",
"schema": "CTS5P6RD8HMCS",
"tags": {},
"value": "7FYGS2KQ3REM9",
},
{
"labels": [],
"name": "@ocas/output/put",
"schema": "CTS5P6RD8HMCS",
"tags": {},
"value": "4ZHWK21APCFZ5",
},
{
"labels": [],
"name": "@ocas/output/refs",
"schema": "CTS5P6RD8HMCS",
"tags": {},
"value": "2TKP4RGBJ4V43",
},
{
"labels": [],
"name": "@ocas/output/tag",
"schema": "CTS5P6RD8HMCS",
"tags": {},
"value": "CPSWA9TB2JMWP",
},
{
"labels": [],
"name": "@ocas/output/template-delete",
"schema": "CTS5P6RD8HMCS",
"tags": {},
"value": "BY7BGZJND3N7R",
},
{
"labels": [],
"name": "@ocas/output/template-get",
"schema": "CTS5P6RD8HMCS",
"tags": {},
"value": "0B0HBHZGYHR84",
},
{
"labels": [],
"name": "@ocas/output/template-list",
"schema": "CTS5P6RD8HMCS",
"tags": {},
"value": "8917JQTD1R5JF",
},
{
"labels": [],
"name": "@ocas/output/template-set",
"schema": "CTS5P6RD8HMCS",
"tags": {},
"value": "BJDHPAE4Q8TXM",
},
{
"labels": [],
"name": "@ocas/output/untag",
"schema": "CTS5P6RD8HMCS",
"tags": {},
"value": "BPEQMRQNJK80Z",
},
{
"labels": [],
"name": "@ocas/output/var-delete",
"schema": "CTS5P6RD8HMCS",
"tags": {},
"value": "C3MYPR5RGQFZT",
},
{
"labels": [],
"name": "@ocas/output/var-get",
"schema": "CTS5P6RD8HMCS",
"tags": {},
"value": "F5RRJTXP8Z99D",
},
{
"labels": [],
"name": "@ocas/output/var-history",
"schema": "CTS5P6RD8HMCS",
"tags": {},
"value": "EVZJS80TRFKE1",
},
{
"labels": [],
"name": "@ocas/output/var-list",
"schema": "CTS5P6RD8HMCS",
"tags": {},
"value": "AF0XACGXHPMC1",
},
{
"labels": [],
"name": "@ocas/output/var-set",
"schema": "CTS5P6RD8HMCS",
"tags": {},
"value": "0Q5EMYK4SYSS9",
},
{
"labels": [],
"name": "@ocas/output/verify",
"schema": "CTS5P6RD8HMCS",
"tags": {},
"value": "52HEFB52BD0GF",
},
{
"labels": [],
"name": "@ocas/output/walk",
"schema": "CTS5P6RD8HMCS",
"tags": {},
"value": "4HG6MD3XG5H5C",
},
{
"labels": [],
"name": "@ocas/schema",
"schema": "CTS5P6RD8HMCS",
"tags": {},
"value": "CTS5P6RD8HMCS",
},
{
"labels": [],
"name": "@ocas/string",
"schema": "CTS5P6RD8HMCS",
"tags": {},
"value": "7VQ43ZSJTEWA7",
},
],
}
`;
exports[`Phase 3: Variable System 3.4 var list prefix filters by prefix 1`] = `
{
"type": "AF0XACGXHPMC1",
"value": [
{
"labels": [],
"name": "@myapp/config",
"schema": "FRBAB1BF0ZBCS",
"tags": {},
"value": "9W3MGR3184QYE",
},
],
}
`;
exports[`Phase 3: Variable System 3.5 var set upsert updates existing variable 1`] = `
{
"type": "0Q5EMYK4SYSS9",
"value": {
"labels": [],
"name": "@myapp/config",
"schema": "FRBAB1BF0ZBCS",
"tags": {},
"value": "A6QPKJAFR68NP",
},
}
`;
exports[`Phase 3: Variable System 3.6 var set with tag and label adds them 1`] = `
{
"type": "0Q5EMYK4SYSS9",
"value": {
"labels": [
"important",
],
"name": "@myapp/config",
"schema": "FRBAB1BF0ZBCS",
"tags": {
"env": "prod",
},
"value": "9W3MGR3184QYE",
},
}
`;
exports[`Phase 3: Variable System 3.7 var list --tag env:prod filters by kv tag 1`] = `
{
"type": "AF0XACGXHPMC1",
"value": [
{
"labels": [
"important",
],
"name": "@myapp/config",
"schema": "FRBAB1BF0ZBCS",
"tags": {
"env": "prod",
},
"value": "9W3MGR3184QYE",
},
],
}
`;
exports[`Phase 3: Variable System 3.8 var list --tag important filters by label 1`] = `
{
"type": "AF0XACGXHPMC1",
"value": [
{
"labels": [
"important",
],
"name": "@myapp/config",
"schema": "FRBAB1BF0ZBCS",
"tags": {
"env": "prod",
},
"value": "9W3MGR3184QYE",
},
],
}
`;
exports[`Phase 3: Variable System 3.9 var set without label removes it 1`] = `
{
"type": "0Q5EMYK4SYSS9",
"value": {
"labels": [],
"name": "@myapp/config",
"schema": "FRBAB1BF0ZBCS",
"tags": {
"env": "prod",
},
"value": "9W3MGR3184QYE",
},
}
`;
exports[`Phase 3: Variable System 3.10 var delete removes variable 1`] = `
{
"type": "C3MYPR5RGQFZT",
"value": [
{
"labels": [],
"name": "@myapp/config",
"schema": "FRBAB1BF0ZBCS",
"tags": {
"env": "prod",
},
"value": "9W3MGR3184QYE",
},
],
}
`;
exports[`Phase 3: Variable System 3.11 var get deleted variable returns not found 1`] = `"Error: Variable not found: name=@myapp/config, schema=FRBAB1BF0ZBCS"`;
exports[`Phase 4: Template System > 4.1 template set registers template 1`] = `
{
"type": "BJDHPAE4Q8TXM",
@@ -790,46 +415,6 @@ exports[`Phase 4: Template System > 4.4 template delete removes template 1`] = `
exports[`Phase 4: Template System > 4.5 template get deleted template returns not found 1`] = `"Error: Template not found for schema: FRBAB1BF0ZBCS"`;
exports[`Phase 4: Template System 4.1 template set registers template 1`] = `
{
"type": "BJDHPAE4Q8TXM",
"value": {
"contentHash": "6WW8WNB38GTTP",
"schemaHash": "FRBAB1BF0ZBCS",
},
}
`;
exports[`Phase 4: Template System 4.2 template get returns template text 1`] = `
{
"type": "0B0HBHZGYHR84",
"value": "Name: {{ payload.name }}, Age: {{ payload.age }}",
}
`;
exports[`Phase 4: Template System 4.3 template list shows registered templates 1`] = `
{
"type": "8917JQTD1R5JF",
"value": [
{
"contentHash": "6WW8WNB38GTTP",
"schemaHash": "FRBAB1BF0ZBCS",
},
],
}
`;
exports[`Phase 4: Template System 4.4 template delete removes template 1`] = `
{
"type": "BY7BGZJND3N7R",
"value": {
"deleted": true,
},
}
`;
exports[`Phase 4: Template System 4.5 template get deleted template returns not found 1`] = `"Error: Template not found for schema: FRBAB1BF0ZBCS"`;
exports[`Phase 7: Edge Cases > 7.1 get non-existent hash errors gracefully 1`] = `"Node not found: AAAAAAAAAAAAA"`;
exports[`Phase 7: Edge Cases > 7.3 var set empty name errors 1`] = `"Usage: ocas var set <name> <hash> [--tag <tag>...]"`;
@@ -881,59 +466,5 @@ Flags:
--epsilon <n> Cutoff threshold for render (default: 0.01)
--pipe, -p Read from stdin (put/hash: raw JSON payload; render: { type, value } envelope)
Agent: If you have not installed the ocas skill for this version (0.2.0), run \`ocas prompt setup\` and follow the instructions."
`;
exports[`Phase 7: Edge Cases 7.1 get non-existent hash errors gracefully 1`] = `"Node not found: AAAAAAAAAAAAA"`;
exports[`Phase 7: Edge Cases 7.3 var set empty name errors 1`] = `"Usage: ocas var set <name> <hash> [--tag <tag>...]"`;
exports[`Phase 7: Edge Cases 7.4 var set name with invalid chars errors 1`] = `"Error: Invalid variable name "invalid name!": Name must follow @scope/name format (e.g. @myapp/config)"`;
exports[`Phase 7: Edge Cases 7.5 no subcommand shows help text 1`] = `
"Usage: ocas [--home <path>] [--json] <command> [args]
All JSON commands emit a { type, value } envelope. The type is the hash of the
command's @ocas/output/* schema (shown in parentheses); pipe any envelope into
\`render -p\` to render its value (ocas_ref hashes are expanded).
Commands:
put <type-hash> <file.json|--pipe> Store node, print envelope (value=hash) (@ocas/output/put)
get <hash> Print node as envelope (@ocas/output/get)
has <hash> Print envelope (value=boolean) (@ocas/output/has)
verify <hash> Verify integrity + schema (value=ok/corrupted/invalid) (@ocas/output/verify)
refs <hash> List direct ocas_ref edges (@ocas/output/refs)
walk <hash> [--format tree] Recursive traversal (@ocas/output/walk)
hash <type-hash> <file.json|--pipe> Compute hash without storing (@ocas/output/hash)
render <hash> [options] Render node as text with resolution decay (raw output)
render --pipe/-p [options] Render { type, value } from stdin (raw output)
list --type <hash-or-name> [--tag <tag>...] List hashes for a type, optionally filtered by tags (@ocas/output/list)
list-meta List meta-schema hashes (value=string[]) (@ocas/output/list-meta)
list-schema List all schema hashes (value=string[]) (@ocas/output/list-schema)
tag <target> <tag>... Apply tags/labels to a target (@ocas/output/tag)
untag <target> <tag>... Remove tags/labels from a target (@ocas/output/untag)
var set <name> <hash> [--tag <tag>...] Create/update a variable (@ocas/output/var-set)
var get <name> --schema <hash> Get a variable by name + schema (@ocas/output/var-get)
var delete <name> [--schema <hash>] Delete variable(s) (@ocas/output/var-delete)
var list [prefix] [--schema <hash>] [--tag <tag>...] List variables (@ocas/output/var-list)
var history <name> [--schema <hash>] Show value history (LRU) (@ocas/output/var-history)
template set <schema-hash> <file> | --inline <text> Set template for schema (@ocas/output/template-set)
template get <schema-hash> Get template content (value=string) (@ocas/output/template-get)
template list List all templates (@ocas/output/template-list)
template delete <schema-hash> Delete template for schema (@ocas/output/template-delete)
gc Run garbage collection (@ocas/output/gc)
Flags:
--home <path> Store directory (default: $OCAS_HOME or ~/.ocas)
--json Compact JSON output
--render, -r Render output inline (equivalent to | ocas render -p)
--schema <hash> Schema hash filter for var get/delete/tag/list
--tag <tag> Tag/label (can be repeated): key:value (tag), name (label), :name (delete)
--inline <text> Inline text content for template set
--resolution <n> Initial resolution for render (default: 1.0)
--decay <n> Decay factor for render (default: 0.5)
--epsilon <n> Cutoff threshold for render (default: 0.01)
--pipe, -p Read from stdin (put/hash: raw JSON payload; render: { type, value } envelope)
Agent: If you have not installed the ocas skill for this version (0.2.0), run \`ocas prompt setup\` and follow the instructions."
Agent: If you have not installed the ocas skill for this version (0.3.1), run \`ocas prompt setup\` and follow the instructions."
`;
@@ -12,16 +12,3 @@ exports[`Phase 1: CAS Core > 1.6 get returns node JSON (snapshot) 1`] = `
},
}
`;
exports[`Phase 1: CAS Core 1.6 get returns node JSON (snapshot) 1`] = `
{
"type": "7V5G8E2VW8B2G",
"value": {
"payload": {
"age": 30,
"name": "Alice",
},
"type": "FRBAB1BF0ZBCS",
},
}
`;
@@ -3,7 +3,3 @@
exports[`Phase 5: Render > 5.1 render fills payload variables 1`] = `"Hello Alice!"`;
exports[`Phase 5: Render > 5.2 render --resolution with different value 1`] = `"Hello Alice!"`;
exports[`Phase 5: Render 5.1 render fills payload variables 1`] = `"Hello Alice!"`;
exports[`Phase 5: Render 5.2 render --resolution with different value 1`] = `"Hello Alice!"`;
@@ -1,5 +1,3 @@
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
exports[`Phase 2: Schema Validation > 2.3 put against non-existent schema hash fails 1`] = `"Schema not found: AAAAAAAAAAAAA"`;
exports[`Phase 2: Schema Validation 2.3 put against non-existent schema hash fails 1`] = `"Schema not found: AAAAAAAAAAAAA"`;
@@ -22,26 +22,3 @@ exports[`Phase 1: CAS Core > 1.11 walk shows traversal tree (snapshot) 1`] = `
]
}"
`;
exports[`Phase 1: CAS Core 1.9 verify returns ok for valid node 1`] = `
{
"type": "52HEFB52BD0GF",
"value": "ok",
}
`;
exports[`Phase 1: CAS Core 1.10 refs lists direct references (snapshot) 1`] = `
"{
"type": "2TKP4RGBJ4V43",
"value": []
}"
`;
exports[`Phase 1: CAS Core 1.11 walk shows traversal tree (snapshot) 1`] = `
"{
"type": "4HG6MD3XG5H5C",
"value": [
"9W3MGR3184QYE"
]
}"
`;
+20 -8
View File
@@ -1,8 +1,8 @@
import { afterEach, beforeEach, describe, expect, test } from "vitest";
import { mkdirSync, rmSync, writeFileSync } from "node:fs";
import { execFileSync } from "node:child_process";
import { mkdirSync, rmSync, writeFileSync } from "node:fs";
import { tmpdir } from "node:os";
import { join } from "node:path";
import { afterEach, beforeEach, describe, expect, test } from "vitest";
// ---- @ Alias Resolution Tests ----
@@ -35,17 +35,29 @@ afterEach(() => {
/**
* Run CLI command and return stdout, stderr, and exit code
*/
function runCliAlias(...rawArgs: (string | string[])[]): { stdout: string; stderr: string; exitCode: number } {
function runCliAlias(...rawArgs: (string | string[])[]): {
stdout: string;
stderr: string;
exitCode: number;
} {
const args = rawArgs.flat();
try {
const stdout = execFileSync("node", [cliPath, "--home", storePath, ...args], {
encoding: "utf-8",
timeout: 10000,
});
const stdout = execFileSync(
"node",
[cliPath, "--home", storePath, ...args],
{
encoding: "utf-8",
timeout: 10000,
},
);
return { stdout: stdout.trim(), stderr: "", exitCode: 0 };
} catch (e: unknown) {
const err = e as { stdout?: string; stderr?: string; status?: number };
return { stdout: (err.stdout ?? "").trim(), stderr: (err.stderr ?? "").trim(), exitCode: err.status ?? 1 };
return {
stdout: (err.stdout ?? "").trim(),
stderr: (err.stderr ?? "").trim(),
exitCode: err.status ?? 1,
};
}
}
+67 -24
View File
@@ -1,8 +1,8 @@
import { afterAll, beforeAll, describe, expect, test } from "vitest";
import { mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";
import { execFileSync } from "node:child_process";
import { mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";
import { tmpdir } from "node:os";
import { join, resolve } from "node:path";
import { afterAll, beforeAll, describe, expect, test } from "vitest";
import { envValue, stripVolatile } from "./helpers";
const entrypoint = resolve(import.meta.dirname, "../dist/index.js");
@@ -39,17 +39,30 @@ describe("Phase 7: Edge Cases", () => {
let typeHash: string;
let nodeHash: string;
function runCli(...rawArgs: (string | string[])[]): { stdout: string; stderr: string; exitCode: number } {
function runCli(...rawArgs: (string | string[])[]): {
stdout: string;
stderr: string;
exitCode: number;
} {
const args = rawArgs.flat();
try {
const stdout = execFileSync("node", [entrypoint, "--home", tmpStore, ...args], {
encoding: "utf-8",
timeout: 10000,
});
const stdout = execFileSync(
"node",
[entrypoint, "--home", tmpStore, ...args],
{
encoding: "utf-8",
timeout: 10000,
env: { ...process.env, NODE_NO_WARNINGS: "1" },
},
);
return { stdout: stdout.trim(), stderr: "", exitCode: 0 };
} catch (e: unknown) {
const err = e as { stdout?: string; stderr?: string; status?: number };
return { stdout: (err.stdout ?? "").trim(), stderr: (err.stderr ?? "").trim(), exitCode: err.status ?? 1 };
return {
stdout: (err.stdout ?? "").trim(),
stderr: (err.stderr ?? "").trim(),
exitCode: err.status ?? 1,
};
}
}
@@ -128,10 +141,14 @@ describe("Phase 7: Edge Cases", () => {
const fileAsStore = join(tmpStore, "not-a-directory");
writeFileSync(fileAsStore, "test");
try {
execFileSync("node", [entrypoint, "--home", fileAsStore, "get", "AAAAAAAAAAAAA"], {
encoding: "utf-8",
timeout: 10000,
});
execFileSync(
"node",
[entrypoint, "--home", fileAsStore, "get", "AAAAAAAAAAAAA"],
{
encoding: "utf-8",
timeout: 10000,
},
);
expect.unreachable("should have thrown");
} catch (e: unknown) {
const err = e as { stderr?: string; status?: number };
@@ -148,17 +165,30 @@ describe("Phase 3: Variable System", () => {
let typeHash: string;
let nodeHash: string;
function runCli(...rawArgs: (string | string[])[]): { stdout: string; stderr: string; exitCode: number } {
function runCli(...rawArgs: (string | string[])[]): {
stdout: string;
stderr: string;
exitCode: number;
} {
const args = rawArgs.flat();
try {
const stdout = execFileSync("node", [entrypoint, "--home", tmpStore, ...args], {
encoding: "utf-8",
timeout: 10000,
});
const stdout = execFileSync(
"node",
[entrypoint, "--home", tmpStore, ...args],
{
encoding: "utf-8",
timeout: 10000,
env: { ...process.env, NODE_NO_WARNINGS: "1" },
},
);
return { stdout: stdout.trim(), stderr: "", exitCode: 0 };
} catch (e: unknown) {
const err = e as { stdout?: string; stderr?: string; status?: number };
return { stdout: (err.stdout ?? "").trim(), stderr: (err.stderr ?? "").trim(), exitCode: err.status ?? 1 };
return {
stdout: (err.stdout ?? "").trim(),
stderr: (err.stderr ?? "").trim(),
exitCode: err.status ?? 1,
};
}
}
@@ -338,17 +368,30 @@ describe("Phase 4: Template System", () => {
let tmpStore: string;
let typeHash: string;
function runCli(...rawArgs: (string | string[])[]): { stdout: string; stderr: string; exitCode: number } {
function runCli(...rawArgs: (string | string[])[]): {
stdout: string;
stderr: string;
exitCode: number;
} {
const args = rawArgs.flat();
try {
const stdout = execFileSync("node", [entrypoint, "--home", tmpStore, ...args], {
encoding: "utf-8",
timeout: 10000,
});
const stdout = execFileSync(
"node",
[entrypoint, "--home", tmpStore, ...args],
{
encoding: "utf-8",
timeout: 10000,
env: { ...process.env, NODE_NO_WARNINGS: "1" },
},
);
return { stdout: stdout.trim(), stderr: "", exitCode: 0 };
} catch (e: unknown) {
const err = e as { stdout?: string; stderr?: string; status?: number };
return { stdout: (err.stdout ?? "").trim(), stderr: (err.stderr ?? "").trim(), exitCode: err.status ?? 1 };
return {
stdout: (err.stdout ?? "").trim(),
stderr: (err.stderr ?? "").trim(),
exitCode: err.status ?? 1,
};
}
}
+29 -13
View File
@@ -1,8 +1,8 @@
import { afterAll, beforeAll, describe, expect, test } from "vitest";
import { mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";
import { execFileSync } from "node:child_process";
import { mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";
import { tmpdir } from "node:os";
import { join, resolve } from "node:path";
import { afterAll, beforeAll, describe, expect, test } from "vitest";
import { envValue } from "./helpers";
const entrypoint = resolve(import.meta.dirname, "../dist/index.js");
@@ -42,17 +42,29 @@ afterAll(() => {
rmSync(tmpStore, { recursive: true, force: true });
});
function runCli(...rawArgs: (string | string[])[]): { stdout: string; stderr: string; exitCode: number } {
function runCli(...rawArgs: (string | string[])[]): {
stdout: string;
stderr: string;
exitCode: number;
} {
const args = rawArgs.flat();
try {
const stdout = execFileSync("node", [entrypoint, "--home", tmpStore, ...args], {
encoding: "utf-8",
timeout: 10000,
});
const stdout = execFileSync(
"node",
[entrypoint, "--home", tmpStore, ...args],
{
encoding: "utf-8",
timeout: 10000,
},
);
return { stdout: stdout.trim(), stderr: "", exitCode: 0 };
} catch (e: unknown) {
const err = e as { stdout?: string; stderr?: string; status?: number };
return { stdout: (err.stdout ?? "").trim(), stderr: (err.stderr ?? "").trim(), exitCode: err.status ?? 1 };
return {
stdout: (err.stdout ?? "").trim(),
stderr: (err.stderr ?? "").trim(),
exitCode: err.status ?? 1,
};
}
}
@@ -77,11 +89,15 @@ describe("Phase 6: GC", () => {
const { stdout: gcOut, exitCode: gcExit } = runCli(["gc"]);
expect(gcExit).toBe(0);
const stdout = execFileSync("node", [entrypoint, "--home", tmpStore, "render", "--pipe"], {
input: gcOut,
encoding: "utf-8",
timeout: 10000,
}).trim();
const stdout = execFileSync(
"node",
[entrypoint, "--home", tmpStore, "render", "--pipe"],
{
input: gcOut,
encoding: "utf-8",
timeout: 10000,
},
).trim();
// gc value is an object { total, reachable, collected, scanned }
expect(stdout).toContain("total:");
});
+20 -8
View File
@@ -1,11 +1,11 @@
import { afterEach, beforeEach, describe, expect, test } from "vitest";
import { mkdirSync, rmSync } from "node:fs";
import { execFileSync } from "node:child_process";
import { mkdirSync, rmSync } from "node:fs";
import { tmpdir } from "node:os";
import { join } from "node:path";
import type { Hash } from "@ocas/core";
import { bootstrap, validate } from "@ocas/core";
import { openStore as openFsStore } from "@ocas/fs";
import { afterEach, beforeEach, describe, expect, test } from "vitest";
let testDir: string;
let storePath: string;
@@ -30,17 +30,29 @@ afterEach(() => {
}
});
function runCli(...rawArgs: (string | string[])[]): { stdout: string; stderr: string; exitCode: number } {
function runCli(...rawArgs: (string | string[])[]): {
stdout: string;
stderr: string;
exitCode: number;
} {
const args = rawArgs.flat();
try {
const stdout = execFileSync("node", [cliPath, "--home", storePath, ...args], {
encoding: "utf-8",
timeout: 10000,
});
const stdout = execFileSync(
"node",
[cliPath, "--home", storePath, ...args],
{
encoding: "utf-8",
timeout: 10000,
},
);
return { stdout: stdout.trim(), stderr: "", exitCode: 0 };
} catch (e: unknown) {
const err = e as { stdout?: string; stderr?: string; status?: number };
return { stdout: (err.stdout ?? "").trim(), stderr: (err.stderr ?? "").trim(), exitCode: err.status ?? 1 };
return {
stdout: (err.stdout ?? "").trim(),
stderr: (err.stderr ?? "").trim(),
exitCode: err.status ?? 1,
};
}
}
+15 -3
View File
@@ -1,3 +1,4 @@
import { execFileSync } from "node:child_process";
import {
mkdirSync,
mkdtempSync,
@@ -5,7 +6,6 @@ import {
rmSync,
writeFileSync,
} from "node:fs";
import { execFileSync } from "node:child_process";
import { tmpdir } from "node:os";
import { join, resolve } from "node:path";
import type { JSONSchema } from "@ocas/core";
@@ -47,6 +47,8 @@ export async function putSchemaFile(
return hash;
}
const quietEnv = { ...process.env, NODE_NO_WARNINGS: "1" };
/**
* Run CLI command. Accepts either a string[] or ...string[] (rest args).
* If first arg is an array, uses that as args. Otherwise treats all args as the command.
@@ -62,11 +64,16 @@ export function runCli(
const stdout = execFileSync("node", finalArgs, {
encoding: "utf-8",
timeout: 10000,
env: quietEnv,
});
return { stdout, stderr: "", exitCode: 0 };
} catch (e: unknown) {
const err = e as { stdout?: string; stderr?: string; status?: number };
return { stdout: err.stdout ?? "", stderr: err.stderr ?? "", exitCode: err.status ?? 1 };
return {
stdout: err.stdout ?? "",
stderr: err.stderr ?? "",
exitCode: err.status ?? 1,
};
}
}
@@ -81,11 +88,16 @@ export function runCliWithStdin(
input: stdin,
encoding: "utf-8",
timeout: 10000,
env: quietEnv,
});
return { stdout, stderr: "", exitCode: 0 };
} catch (e: unknown) {
const err = e as { stdout?: string; stderr?: string; status?: number };
return { stdout: err.stdout ?? "", stderr: err.stderr ?? "", exitCode: err.status ?? 1 };
return {
stdout: err.stdout ?? "",
stderr: err.stderr ?? "",
exitCode: err.status ?? 1,
};
}
}
+1 -1
View File
@@ -1,9 +1,9 @@
import { afterEach, beforeEach, describe, expect, test } from "vitest";
import { mkdirSync, mkdtempSync, rmSync } from "node:fs";
import { tmpdir } from "node:os";
import { join } from "node:path";
import { BOOTSTRAP_STORE } from "@ocas/core";
import { openStore as openFsStore } from "@ocas/fs";
import { afterEach, beforeEach, describe, expect, test } from "vitest";
import { envValue, runCli } from "./helpers.js";
let storePath: string;
+11 -7
View File
@@ -1,8 +1,8 @@
import { afterEach, beforeEach, describe, expect, test } from "vitest";
import { mkdirSync, mkdtempSync, rmSync } from "node:fs";
import { execFileSync } from "node:child_process";
import { mkdirSync, mkdtempSync, rmSync } from "node:fs";
import { tmpdir } from "node:os";
import { join } from "node:path";
import { afterEach, beforeEach, describe, expect, test } from "vitest";
import { envValue, runCli } from "./helpers.js";
const HASH_RE = /^[0-9A-HJKMNP-TV-Z]{13}$/;
@@ -20,11 +20,15 @@ afterEach(() => {
async function putString(text: string): Promise<string> {
const entrypoint = join(import.meta.dirname, "../dist/index.js");
const out = execFileSync("node", [entrypoint, "--home", storePath, "put", "@ocas/string", "--pipe"], {
input: JSON.stringify(text),
encoding: "utf-8",
timeout: 10000,
});
const out = execFileSync(
"node",
[entrypoint, "--home", storePath, "put", "@ocas/string", "--pipe"],
{
input: JSON.stringify(text),
encoding: "utf-8",
timeout: 10000,
},
);
return (JSON.parse(out) as { value: string }).value;
}
+29 -13
View File
@@ -1,8 +1,8 @@
import { afterEach, beforeEach, describe, expect, test } from "vitest";
import { mkdirSync, rmSync } from "node:fs";
import { execFileSync } from "node:child_process";
import { mkdirSync, rmSync } from "node:fs";
import { tmpdir } from "node:os";
import { join } from "node:path";
import { afterEach, beforeEach, describe, expect, test } from "vitest";
let testDir: string;
let storePath: string;
@@ -27,27 +27,43 @@ afterEach(() => {
}
});
function runCli(...rawArgs: (string | string[])[]): { stdout: string; stderr: string; exitCode: number } {
function runCli(...rawArgs: (string | string[])[]): {
stdout: string;
stderr: string;
exitCode: number;
} {
const args = rawArgs.flat();
try {
const stdout = execFileSync("node", [cliPath, "--home", storePath, ...args], {
encoding: "utf-8",
timeout: 10000,
});
const stdout = execFileSync(
"node",
[cliPath, "--home", storePath, ...args],
{
encoding: "utf-8",
timeout: 10000,
},
);
return { stdout: stdout.trim(), stderr: "", exitCode: 0 };
} catch (e: unknown) {
const err = e as { stdout?: string; stderr?: string; status?: number };
return { stdout: (err.stdout ?? "").trim(), stderr: (err.stderr ?? "").trim(), exitCode: err.status ?? 1 };
return {
stdout: (err.stdout ?? "").trim(),
stderr: (err.stderr ?? "").trim(),
exitCode: err.status ?? 1,
};
}
}
function putString(value: string): string {
try {
const out = execFileSync("node", [cliPath, "--home", storePath, "put", "@ocas/string", "--pipe"], {
input: JSON.stringify(value),
encoding: "utf-8",
timeout: 10000,
});
const out = execFileSync(
"node",
[cliPath, "--home", storePath, "put", "@ocas/string", "--pipe"],
{
input: JSON.stringify(value),
encoding: "utf-8",
timeout: 10000,
},
);
return JSON.parse(out.trim()).value as string;
} catch (e: unknown) {
const err = e as { stderr?: string };
+34 -14
View File
@@ -1,8 +1,8 @@
import { afterAll, beforeAll, describe, expect, test } from "vitest";
import { mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";
import { execFileSync } from "node:child_process";
import { mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";
import { tmpdir } from "node:os";
import { join, resolve } from "node:path";
import { afterAll, beforeAll, describe, expect, test } from "vitest";
import { envValue } from "./helpers";
const entrypoint = resolve(import.meta.dirname, "../dist/index.js");
@@ -44,17 +44,29 @@ afterAll(() => {
rmSync(tmpStore, { recursive: true, force: true });
});
function runCli(...rawArgs: (string | string[])[]): { stdout: string; stderr: string; exitCode: number } {
function runCli(...rawArgs: (string | string[])[]): {
stdout: string;
stderr: string;
exitCode: number;
} {
const args = rawArgs.flat();
try {
const stdout = execFileSync("node", [entrypoint, "--home", tmpStore, ...args], {
encoding: "utf-8",
timeout: 10000,
});
const stdout = execFileSync(
"node",
[entrypoint, "--home", tmpStore, ...args],
{
encoding: "utf-8",
timeout: 10000,
},
);
return { stdout: stdout.trim(), stderr: "", exitCode: 0 };
} catch (e: unknown) {
const err = e as { stdout?: string; stderr?: string; status?: number };
return { stdout: (err.stdout ?? "").trim(), stderr: (err.stderr ?? "").trim(), exitCode: err.status ?? 1 };
return {
stdout: (err.stdout ?? "").trim(),
stderr: (err.stderr ?? "").trim(),
exitCode: err.status ?? 1,
};
}
}
@@ -63,15 +75,23 @@ function runCliWithStdin(
stdin: string,
): { stdout: string; stderr: string; exitCode: number } {
try {
const stdout = execFileSync("node", [entrypoint, "--home", tmpStore, ...args], {
input: stdin,
encoding: "utf-8",
timeout: 10000,
});
const stdout = execFileSync(
"node",
[entrypoint, "--home", tmpStore, ...args],
{
input: stdin,
encoding: "utf-8",
timeout: 10000,
},
);
return { stdout: stdout.trim(), stderr: "", exitCode: 0 };
} catch (e: unknown) {
const err = e as { stdout?: string; stderr?: string; status?: number };
return { stdout: (err.stdout ?? "").trim(), stderr: (err.stderr ?? "").trim(), exitCode: err.status ?? 1 };
return {
stdout: (err.stdout ?? "").trim(),
stderr: (err.stderr ?? "").trim(),
exitCode: err.status ?? 1,
};
}
}
+20 -10
View File
@@ -1,8 +1,8 @@
import { afterAll, beforeAll, describe, expect, test } from "vitest";
import { mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";
import { execFileSync } from "node:child_process";
import { mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";
import { tmpdir } from "node:os";
import { join, resolve } from "node:path";
import { afterAll, beforeAll, describe, expect, test } from "vitest";
import { envValue, stripVolatile } from "./helpers";
const entrypoint = resolve(import.meta.dirname, "../dist/index.js");
@@ -42,18 +42,28 @@ afterAll(() => {
rmSync(tmpStore, { recursive: true, force: true });
});
function runCli(
args: string[],
): { stdout: string; stderr: string; exitCode: number } {
function runCli(args: string[]): {
stdout: string;
stderr: string;
exitCode: number;
} {
try {
const stdout = execFileSync("node", [entrypoint, "--home", tmpStore, ...args], {
encoding: "utf-8",
timeout: 10000,
});
const stdout = execFileSync(
"node",
[entrypoint, "--home", tmpStore, ...args],
{
encoding: "utf-8",
timeout: 10000,
},
);
return { stdout: stdout.trim(), stderr: "", exitCode: 0 };
} catch (e: unknown) {
const err = e as { stdout?: string; stderr?: string; status?: number };
return { stdout: (err.stdout ?? "").trim(), stderr: (err.stderr ?? "").trim(), exitCode: err.status ?? 1 };
return {
stdout: (err.stdout ?? "").trim(),
stderr: (err.stderr ?? "").trim(),
exitCode: err.status ?? 1,
};
}
}
+34 -14
View File
@@ -1,10 +1,10 @@
import { afterAll, beforeAll, describe, expect, test } from "vitest";
import { mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";
import { execFileSync } from "node:child_process";
import { mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";
import { tmpdir } from "node:os";
import { join, resolve } from "node:path";
import { bootstrap } from "@ocas/core";
import { openStore as openFsStore } from "@ocas/fs";
import { afterAll, beforeAll, describe, expect, test } from "vitest";
import { envValue, putSchemaFile, runCli, runCliWithStdin } from "./helpers";
const entrypoint = resolve(import.meta.dirname, "../dist/index.js");
@@ -58,17 +58,29 @@ describe("Phase 5: Render", () => {
let typeHash: string;
let nodeHash: string;
function runCliE2e(...rawArgs: (string | string[])[]): { stdout: string; stderr: string; exitCode: number } {
function runCliE2e(...rawArgs: (string | string[])[]): {
stdout: string;
stderr: string;
exitCode: number;
} {
const args = rawArgs.flat();
try {
const stdout = execFileSync("node", [entrypoint, "--home", tmpStore, ...args], {
encoding: "utf-8",
timeout: 10000,
});
const stdout = execFileSync(
"node",
[entrypoint, "--home", tmpStore, ...args],
{
encoding: "utf-8",
timeout: 10000,
},
);
return { stdout: stdout.trim(), stderr: "", exitCode: 0 };
} catch (e: unknown) {
const err = e as { stdout?: string; stderr?: string; status?: number };
return { stdout: (err.stdout ?? "").trim(), stderr: (err.stderr ?? "").trim(), exitCode: err.status ?? 1 };
return {
stdout: (err.stdout ?? "").trim(),
stderr: (err.stderr ?? "").trim(),
exitCode: err.status ?? 1,
};
}
}
@@ -77,15 +89,23 @@ describe("Phase 5: Render", () => {
stdin: string,
): Promise<{ stdout: string; stderr: string; exitCode: number }> {
try {
const stdout = execFileSync("node", [entrypoint, "--home", tmpStore, ...args], {
input: stdin,
encoding: "utf-8",
timeout: 10000,
});
const stdout = execFileSync(
"node",
[entrypoint, "--home", tmpStore, ...args],
{
input: stdin,
encoding: "utf-8",
timeout: 10000,
},
);
return { stdout: stdout.trim(), stderr: "", exitCode: 0 };
} catch (e: unknown) {
const err = e as { stdout?: string; stderr?: string; status?: number };
return { stdout: (err.stdout ?? "").trim(), stderr: (err.stderr ?? "").trim(), exitCode: err.status ?? 1 };
return {
stdout: (err.stdout ?? "").trim(),
stderr: (err.stderr ?? "").trim(),
exitCode: err.status ?? 1,
};
}
}
+33 -16
View File
@@ -1,8 +1,8 @@
import { afterAll, beforeAll, describe, expect, test } from "vitest";
import { mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";
import { execFileSync } from "node:child_process";
import { mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";
import { tmpdir } from "node:os";
import { join, resolve } from "node:path";
import { afterAll, beforeAll, describe, expect, test } from "vitest";
import { envValue, putSchemaFile, runCli } from "./helpers";
// ---- Issue #50: Schema Validation in put Command ----
@@ -582,10 +582,14 @@ describe("Phase 2: Schema Validation", () => {
const nodeFile = join(tmpStore, "test-node.json");
writeFileSync(nodeFile, JSON.stringify({ name: "Alice", age: 30 }));
const stdout = execFileSync("node", [entrypoint, "--home", tmpStore, "put", typeHash, nodeFile], {
encoding: "utf-8",
timeout: 10000,
}).trim();
const stdout = execFileSync(
"node",
[entrypoint, "--home", tmpStore, "put", typeHash, nodeFile],
{
encoding: "utf-8",
timeout: 10000,
},
).trim();
_nodeHash = envValue(stdout) as string;
});
@@ -596,12 +600,19 @@ describe("Phase 2: Schema Validation", () => {
test("2.1 put {name:123} against string-schema fails with non-zero exit", async () => {
const badFile = join(tmpStore, "bad-node.json");
writeFileSync(badFile, JSON.stringify({ name: 123 }));
let stdout = "", stderr = "", exitCode = 0;
let stdout = "",
stderr = "",
exitCode = 0;
try {
stdout = execFileSync("node", [entrypoint, "--home", tmpStore, "put", typeHash, badFile], {
encoding: "utf-8",
timeout: 10000,
}).trim();
stdout = execFileSync(
"node",
[entrypoint, "--home", tmpStore, "put", typeHash, badFile],
{
encoding: "utf-8",
timeout: 10000,
env: { ...process.env, NODE_NO_WARNINGS: "1" },
},
).trim();
} catch (e: unknown) {
const err = e as { stdout?: string; stderr?: string; status?: number };
stdout = (err.stdout ?? "").trim();
@@ -616,12 +627,18 @@ describe("Phase 2: Schema Validation", () => {
test("2.3 put against non-existent schema hash fails", async () => {
const nodeFile = join(tmpStore, "test-node.json");
let exitCode = 0, stderr = "";
let exitCode = 0,
stderr = "";
try {
execFileSync("node", [entrypoint, "--home", tmpStore, "put", "AAAAAAAAAAAAA", nodeFile], {
encoding: "utf-8",
timeout: 10000,
});
execFileSync(
"node",
[entrypoint, "--home", tmpStore, "put", "AAAAAAAAAAAAA", nodeFile],
{
encoding: "utf-8",
timeout: 10000,
env: { ...process.env, NODE_NO_WARNINGS: "1" },
},
);
} catch (e: unknown) {
const err = e as { stderr?: string; status?: number };
stderr = (err.stderr ?? "").trim();
+20 -8
View File
@@ -1,11 +1,11 @@
import { afterEach, beforeEach, describe, expect, test } from "vitest";
import { mkdirSync, rmSync } from "node:fs";
import { execFileSync } from "node:child_process";
import { mkdirSync, rmSync } from "node:fs";
import { tmpdir } from "node:os";
import { join } from "node:path";
import type { Hash } from "@ocas/core";
import { bootstrap } from "@ocas/core";
import { openStore as openFsStore } from "@ocas/fs";
import { afterEach, beforeEach, describe, expect, test } from "vitest";
let testDir: string;
let storePath: string;
@@ -30,17 +30,29 @@ afterEach(() => {
}
});
function runCli(...rawArgs: (string | string[])[]): { stdout: string; stderr: string; exitCode: number } {
function runCli(...rawArgs: (string | string[])[]): {
stdout: string;
stderr: string;
exitCode: number;
} {
const args = rawArgs.flat();
try {
const stdout = execFileSync("node", [cliPath, "--home", storePath, ...args], {
encoding: "utf-8",
timeout: 10000,
});
const stdout = execFileSync(
"node",
[cliPath, "--home", storePath, ...args],
{
encoding: "utf-8",
timeout: 10000,
},
);
return { stdout: stdout.trim(), stderr: "", exitCode: 0 };
} catch (e: unknown) {
const err = e as { stdout?: string; stderr?: string; status?: number };
return { stdout: (err.stdout ?? "").trim(), stderr: (err.stderr ?? "").trim(), exitCode: err.status ?? 1 };
return {
stdout: (err.stdout ?? "").trim(),
stderr: (err.stderr ?? "").trim(),
exitCode: err.status ?? 1,
};
}
}
+20 -8
View File
@@ -1,11 +1,11 @@
import { afterEach, beforeEach, describe, expect, test } from "vitest";
import { mkdirSync, rmSync, writeFileSync } from "node:fs";
import { execFileSync } from "node:child_process";
import { mkdirSync, rmSync, writeFileSync } from "node:fs";
import { tmpdir } from "node:os";
import { join } from "node:path";
import type { Hash, Store } from "@ocas/core";
import { bootstrap } from "@ocas/core";
import { openStore as openFsStore } from "@ocas/fs";
import { afterEach, beforeEach, describe, expect, test } from "vitest";
// ---- Test helpers ----
@@ -38,17 +38,29 @@ afterEach(() => {
/**
* Run CLI command and return stdout, stderr, and exit code
*/
function runCli(...rawArgs: (string | string[])[]): { stdout: string; stderr: string; exitCode: number } {
function runCli(...rawArgs: (string | string[])[]): {
stdout: string;
stderr: string;
exitCode: number;
} {
const args = rawArgs.flat();
try {
const stdout = execFileSync("node", [cliPath, "--home", storePath, ...args], {
encoding: "utf-8",
timeout: 10000,
});
const stdout = execFileSync(
"node",
[cliPath, "--home", storePath, ...args],
{
encoding: "utf-8",
timeout: 10000,
},
);
return { stdout: stdout.trim(), stderr: "", exitCode: 0 };
} catch (e: unknown) {
const err = e as { stdout?: string; stderr?: string; status?: number };
return { stdout: (err.stdout ?? "").trim(), stderr: (err.stderr ?? "").trim(), exitCode: err.status ?? 1 };
return {
stdout: (err.stdout ?? "").trim(),
stderr: (err.stderr ?? "").trim(),
exitCode: err.status ?? 1,
};
}
}
+1 -1
View File
@@ -1,6 +1,6 @@
import { describe, expect, test } from "vitest";
import { readFileSync } from "node:fs";
import { join } from "node:path";
import { describe, expect, test } from "vitest";
const usagePath = join(import.meta.dirname, "..", "prompts", "usage.md");
+20 -8
View File
@@ -1,11 +1,11 @@
import { afterEach, beforeEach, describe, expect, test } from "vitest";
import { mkdirSync, rmSync } from "node:fs";
import { execFileSync } from "node:child_process";
import { mkdirSync, rmSync } from "node:fs";
import { tmpdir } from "node:os";
import { join } from "node:path";
import type { Hash, Store } from "@ocas/core";
import { bootstrap } from "@ocas/core";
import { openStore as openFsStore } from "@ocas/fs";
import { afterEach, beforeEach, describe, expect, test } from "vitest";
let testDir: string;
let storePath: string;
@@ -31,17 +31,29 @@ afterEach(() => {
}
});
function runCli(...rawArgs: (string | string[])[]): { stdout: string; stderr: string; exitCode: number } {
function runCli(...rawArgs: (string | string[])[]): {
stdout: string;
stderr: string;
exitCode: number;
} {
const args = rawArgs.flat();
try {
const stdout = execFileSync("node", [cliPath, "--home", storePath, ...args], {
encoding: "utf-8",
timeout: 10000,
});
const stdout = execFileSync(
"node",
[cliPath, "--home", storePath, ...args],
{
encoding: "utf-8",
timeout: 10000,
},
);
return { stdout: stdout.trim(), stderr: "", exitCode: 0 };
} catch (e: unknown) {
const err = e as { stdout?: string; stderr?: string; status?: number };
return { stdout: (err.stdout ?? "").trim(), stderr: (err.stderr ?? "").trim(), exitCode: err.status ?? 1 };
return {
stdout: (err.stdout ?? "").trim(),
stderr: (err.stderr ?? "").trim(),
exitCode: err.status ?? 1,
};
}
}
+28 -12
View File
@@ -1,11 +1,11 @@
import { afterEach, beforeEach, describe, expect, test } from "vitest";
import { mkdirSync, rmSync } from "node:fs";
import { execFileSync } from "node:child_process";
import { mkdirSync, rmSync } from "node:fs";
import { tmpdir } from "node:os";
import { join } from "node:path";
import type { Hash, Store } from "@ocas/core";
import { bootstrap, putSchema } from "@ocas/core";
import { openStore as openFsStore } from "@ocas/fs";
import { afterEach, beforeEach, describe, expect, test } from "vitest";
// ---- Test helpers ----
@@ -38,17 +38,29 @@ afterEach(() => {
/**
* Run CLI command and return stdout, stderr, and exit code
*/
function runCli(...rawArgs: (string | string[])[]): { stdout: string; stderr: string; exitCode: number } {
function runCli(...rawArgs: (string | string[])[]): {
stdout: string;
stderr: string;
exitCode: number;
} {
const args = rawArgs.flat();
try {
const stdout = execFileSync("node", [cliPath, "--home", storePath, ...args], {
encoding: "utf-8",
timeout: 10000,
});
const stdout = execFileSync(
"node",
[cliPath, "--home", storePath, ...args],
{
encoding: "utf-8",
timeout: 10000,
},
);
return { stdout: stdout.trim(), stderr: "", exitCode: 0 };
} catch (e: unknown) {
const err = e as { stdout?: string; stderr?: string; status?: number };
return { stdout: (err.stdout ?? "").trim(), stderr: (err.stderr ?? "").trim(), exitCode: err.status ?? 1 };
return {
stdout: (err.stdout ?? "").trim(),
stderr: (err.stderr ?? "").trim(),
exitCode: err.status ?? 1,
};
}
}
@@ -771,10 +783,14 @@ describe("global options", () => {
const hash = await createTestNode(store, typeHash, { test: "data" });
// Override with custom store path
execFileSync("node", [cliPath, "--home", customStorePath, "var", "set", "@test/x", hash], {
encoding: "utf-8",
timeout: 10000,
});
execFileSync(
"node",
[cliPath, "--home", customStorePath, "var", "set", "@test/x", hash],
{
encoding: "utf-8",
timeout: 10000,
},
);
});
});
+20 -10
View File
@@ -1,8 +1,8 @@
import { afterAll, beforeAll, describe, expect, test } from "vitest";
import { mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";
import { execFileSync } from "node:child_process";
import { mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";
import { tmpdir } from "node:os";
import { join, resolve } from "node:path";
import { afterAll, beforeAll, describe, expect, test } from "vitest";
import { envValue, stripVolatile } from "./helpers";
const entrypoint = resolve(import.meta.dirname, "../dist/index.js");
@@ -39,18 +39,28 @@ afterAll(() => {
rmSync(tmpStore, { recursive: true, force: true });
});
function runCli(
args: string[],
): { stdout: string; stderr: string; exitCode: number } {
function runCli(args: string[]): {
stdout: string;
stderr: string;
exitCode: number;
} {
try {
const stdout = execFileSync("node", [entrypoint, "--home", tmpStore, ...args], {
encoding: "utf-8",
timeout: 10000,
});
const stdout = execFileSync(
"node",
[entrypoint, "--home", tmpStore, ...args],
{
encoding: "utf-8",
timeout: 10000,
},
);
return { stdout: stdout.trim(), stderr: "", exitCode: 0 };
} catch (e: unknown) {
const err = e as { stdout?: string; stderr?: string; status?: number };
return { stdout: (err.stdout ?? "").trim(), stderr: (err.stderr ?? "").trim(), exitCode: err.status ?? 1 };
return {
stdout: (err.stdout ?? "").trim(),
stderr: (err.stderr ?? "").trim(),
exitCode: err.status ?? 1,
};
}
}
+1 -4
View File
@@ -6,8 +6,5 @@
},
"include": ["src"],
"exclude": ["src/**/*.test.ts"],
"references": [
{ "path": "../core" },
{ "path": "../fs" }
]
"references": [{ "path": "../core" }, { "path": "../fs" }]
}
+4 -9
View File
@@ -6,14 +6,14 @@ Core CAS engine — hashing, schema, store, verify, bootstrap.
`@ocas/core` is the foundation of the ocas monorepo. It defines content-addressed nodes (`CasNode`), the `Store` interface, XXH64-based hashing with deterministic CBOR, JSON Schema registration and validation (including `cas_ref` links between nodes), bootstrap seeding, and integrity verification.
Other packages build on this layer: `ocas-fs` provides persistence, and `cli-ocas` exposes store operations on the command line.
Other packages build on this layer: `@ocas/fs` provides persistence, and `@ocas/cli` exposes store operations on the command line.
**Dependencies:** `ajv`, `cborg`, `xxhash-wasm`
**Dependencies:** `ajv`, `cborg`, `liquidjs`, `xxhash-wasm`
## Installation
```bash
bun add @ocas/core
pnpm add @ocas/core
```
## API
@@ -32,12 +32,7 @@ type CasNode<T = unknown> = {
timestamp: number; // Unix epoch ms
};
type Store = {
put(typeHash: Hash, payload: unknown): Promise<Hash>;
get(hash: Hash): CasNode | null;
has(hash: Hash): boolean;
listByType(typeHash: Hash): Hash[];
};
type Store = { cas: CasStore; var: VarStore; tag: TagStore; };
type JSONSchema = Record<string, unknown>;
+11 -1
View File
@@ -1,6 +1,16 @@
{
"name": "@ocas/core",
"version": "0.2.1",
"version": "0.3.0",
"description": "Core CAS engine — hashing, schema, store, verify, bootstrap",
"keywords": [
"cas",
"content-addressing",
"json-schema",
"typescript"
],
"engines": {
"node": ">=22.5.0"
},
"type": "module",
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
+1 -1
View File
@@ -1,6 +1,6 @@
import { describe, expect, test } from "vitest";
import { readdirSync, readFileSync, statSync } from "node:fs";
import { join } from "node:path";
import { describe, expect, test } from "vitest";
function* walk(dir: string): Generator<string> {
for (const name of readdirSync(dir)) {
+1 -1
View File
@@ -1,6 +1,6 @@
import { describe, expect, test } from "vitest";
import { readFileSync } from "node:fs";
import { join } from "node:path";
import { describe, expect, test } from "vitest";
import type {
CasNode,
CasStore,
@@ -258,7 +258,9 @@ describe("Test Suite 3: putSchema Validation - Invalid Schemas", () => {
test("3.1: Reject schema with invalid type value", async () => {
const store = new MemStore();
bootstrap(store);
await expect(async () => putSchema(store, { type: "garbage" })).rejects.toThrow();
await expect(async () =>
putSchema(store, { type: "garbage" }),
).rejects.toThrow();
});
test("3.2: Reject schema with type as number", async () => {
+4
View File
@@ -1,5 +1,9 @@
# @ocas/fs
## 0.3.0 — 2026-06-03
- Migrate from better-sqlite3 to built-in node:sqlite — zero native addon dependencies, no more NODE_MODULE_VERSION mismatch across Node upgrades.
## 0.2.0
### Breaking Changes
+7 -20
View File
@@ -4,7 +4,7 @@ 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.
`@ocas/fs` implements a persistent `Store` backed by `node:sqlite` (`DatabaseSync`). Nodes are stored as CBOR blobs in SQLite tables. Stores support bootstrap via the same `BOOTSTRAP_STORE` symbol as the in-memory implementation.
Depends on `@ocas/core` for hashing, CBOR encoding, and types.
@@ -13,7 +13,7 @@ Depends on `@ocas/core` for hashing, CBOR encoding, and types.
## Installation
```bash
bun add @ocas/fs
pnpm add @ocas/fs
```
## API
@@ -21,19 +21,18 @@ bun add @ocas/fs
Exported from `src/index.ts`:
```typescript
function createFsStore(dir: string): BootstrapCapableStore;
function openStore(path: string): Promise<Store>;
```
Returns a `BootstrapCapableStore` from `@ocas/core`. The store loads existing `.bin` files on open and migrates or builds the type index on first use.
Returns a unified `Store` with `cas`, `var`, and `tag` sub-stores, backed by SQLite. Bootstraps automatically on open.
### Example
```typescript
import { bootstrap, putSchema } from "@ocas/core";
import { createFsStore } from "@ocas/fs";
import { putSchema } from "@ocas/core";
import { openStore } from "@ocas/fs";
const store = createFsStore("./my-cas-store");
await bootstrap(store);
const store = await openStore("./my-cas-store");
const typeHash = await putSchema(store, {
type: "object",
@@ -46,18 +45,6 @@ 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 |
+12 -4
View File
@@ -1,6 +1,16 @@
{
"name": "@ocas/fs",
"version": "0.2.1",
"version": "0.3.0",
"description": "Filesystem-backed CAS store with SQLite",
"keywords": [
"cas",
"filesystem",
"sqlite",
"storage"
],
"engines": {
"node": ">=22.5.0"
},
"type": "module",
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
@@ -15,8 +25,7 @@
"src"
],
"dependencies": {
"@ocas/core": "0.2.1",
"better-sqlite3": "^12.10.0",
"@ocas/core": "workspace:*",
"cborg": "^4.2.3"
},
"repository": {
@@ -29,7 +38,6 @@
"url": "https://github.com/shazhou-ww/ocas/issues"
},
"devDependencies": {
"@types/better-sqlite3": "^7.6.13",
"@types/node": "^25.9.1"
}
}
+1 -1
View File
@@ -1,2 +1,2 @@
export { createFsStore, openStore, prepareStore } from "./store.js";
export { createSqliteVarStore } from "./sqlite-store.js";
export { createFsStore, openStore, prepareStore } from "./store.js";
+55 -50
View File
@@ -1,11 +1,10 @@
import { existsSync, mkdirSync, readFileSync } from "node:fs";
import { join } from "node:path";
import Database from "better-sqlite3";
import { DatabaseSync } from "node:sqlite";
import type {
CasStore,
Hash,
HistoryEntry,
ListEntry,
ListOptions,
Tag,
TagOp,
@@ -20,29 +19,39 @@ import {
checkTagLabelConflict,
extractSchema,
MAX_HISTORY,
pushHistory,
removeNameIndex,
SchemaMismatchError,
VariableNotFoundError,
type VarRecord,
validateName,
varKey,
cloneVarRecord,
} from "@ocas/core";
function transaction<T>(db: DatabaseSync, fn: () => T): T {
db.exec("BEGIN");
try {
const r = fn();
db.exec("COMMIT");
return r;
} catch (e) {
db.exec("ROLLBACK");
throw e;
}
}
const DB_FILE = "_store.db";
const VARS_FILE = "_vars.jsonl";
const TAGS_FILE = "_tags.jsonl";
function openDb(dir: string): Database.Database {
function openDb(dir: string): DatabaseSync {
mkdirSync(dir, { recursive: true });
const db = new Database(join(dir, DB_FILE));
db.pragma("journal_mode = WAL");
db.pragma("foreign_keys = ON");
const db = new DatabaseSync(join(dir, DB_FILE));
db.exec("PRAGMA journal_mode = WAL");
db.exec("PRAGMA foreign_keys = ON");
return db;
}
function initVarTables(db: Database.Database): void {
function initVarTables(db: DatabaseSync): void {
db.exec(`
CREATE TABLE IF NOT EXISTS vars (
name TEXT NOT NULL,
@@ -70,7 +79,7 @@ function initVarTables(db: Database.Database): void {
`);
}
function initTagTables(db: Database.Database): void {
function initTagTables(db: DatabaseSync): void {
db.exec(`
CREATE TABLE IF NOT EXISTS tags (
target TEXT NOT NULL,
@@ -93,11 +102,7 @@ type StoredTag = {
created: number;
};
function migrateJsonlVars(
db: Database.Database,
dir: string,
cas: CasStore,
): void {
function migrateJsonlVars(db: DatabaseSync, dir: string, _cas: CasStore): void {
const path = join(dir, VARS_FILE);
if (!existsSync(path)) return;
@@ -134,7 +139,7 @@ function migrateJsonlVars(
VALUES (?, ?, ?, ?, ?)
`);
const migrate = db.transaction(() => {
transaction(db, () => {
for (const rec of records.values()) {
insertVar.run(
rec.name,
@@ -150,10 +155,9 @@ function migrateJsonlVars(
}
}
});
migrate();
}
function migrateJsonlTags(db: Database.Database, dir: string): void {
function migrateJsonlTags(db: DatabaseSync, dir: string): void {
const path = join(dir, TAGS_FILE);
if (!existsSync(path)) return;
@@ -199,14 +203,13 @@ function migrateJsonlTags(db: Database.Database, dir: string): void {
VALUES (?, ?, ?, ?)
`);
const migrate = db.transaction(() => {
transaction(db, () => {
for (const tm of byTarget.values()) {
for (const tag of tm.values()) {
insertTag.run(tag.target, tag.key, tag.value, tag.created);
}
}
});
migrate();
}
// ── Row helpers ──
@@ -307,17 +310,17 @@ export function createSqliteVarStore(
// ── Transactional helpers ──
const txnSetVar = db.transaction(
(
name: string,
schema: Hash,
hash: Hash,
now: number,
tagsJson: string,
labelsJson: string,
isNew: boolean,
valueChanged: boolean,
) => {
function txnSetVar(
name: string,
schema: Hash,
hash: Hash,
now: number,
tagsJson: string,
labelsJson: string,
isNew: boolean,
valueChanged: boolean,
): void {
transaction(db, () => {
if (isNew) {
stmtInsertVar.run(name, schema, hash, now, now, tagsJson, labelsJson);
stmtInsertHistory.run(name, schema, hash, 0, now);
@@ -332,11 +335,11 @@ export function createSqliteVarStore(
} else {
stmtUpdateVar.run(hash, now, tagsJson, labelsJson, name, schema);
}
},
);
});
}
const txnTagOps = db.transaction(
(target: Hash, operations: TagOp[], now: number) => {
function txnTagOps(target: Hash, operations: TagOp[], now: number): void {
transaction(db, () => {
for (const op of operations) {
if (op.op === "set") {
// Use ON CONFLICT to preserve created time — but we need existing created
@@ -349,14 +352,16 @@ export function createSqliteVarStore(
stmtDeleteTag.run(target, op.key);
}
}
},
);
});
}
const txnUntag = db.transaction((target: Hash, keys: string[]) => {
for (const k of keys) {
stmtDeleteTag.run(target, k);
}
});
function txnUntag(target: Hash, keys: string[]): void {
transaction(db, () => {
for (const k of keys) {
stmtDeleteTag.run(target, k);
}
});
}
// ── VarStore implementation ──
const varStore: VarStore = {
@@ -519,7 +524,7 @@ export function createSqliteVarStore(
// Build dynamic query
const conditions: string[] = [];
const params: unknown[] = [];
const params: (string | number | null)[] = [];
if (options?.exactName !== undefined) {
conditions.push("name = ?");
@@ -622,9 +627,9 @@ export function createSqliteVarStore(
tag(target: Hash, operations: TagOp[]): Tag[] {
const now = Date.now();
txnTagOps(target, operations, now);
return (
stmtGetTagsByTarget.all(target) as Record<string, unknown>[]
).map((r) => toTag(r, target));
return (stmtGetTagsByTarget.all(target) as Record<string, unknown>[]).map(
(r) => toTag(r, target),
);
},
untag(target: Hash, keys: string[]): void {
@@ -632,9 +637,9 @@ export function createSqliteVarStore(
},
tags(target: Hash): Tag[] {
return (
stmtGetTagsByTarget.all(target) as Record<string, unknown>[]
).map((r) => toTag(r, target));
return (stmtGetTagsByTarget.all(target) as Record<string, unknown>[]).map(
(r) => toTag(r, target),
);
},
listByTag(tag: string, options?: ListOptions): Hash[] {
@@ -653,7 +658,7 @@ export function createSqliteVarStore(
const limit = options?.limit;
let sql: string;
const params: unknown[] = [key];
const params: (string | number | null)[] = [key];
if (value !== undefined) {
sql = `SELECT target FROM tags WHERE key = ? AND value = ? ORDER BY ${sortCol} ${sortDir}`;
params.push(value);
+1 -1
View File
@@ -1,4 +1,3 @@
import { afterEach, beforeEach, describe, expect, test } from "vitest";
import {
existsSync,
mkdtempSync,
@@ -17,6 +16,7 @@ import {
computeSelfHash,
verify,
} from "@ocas/core";
import { afterEach, beforeEach, describe, expect, test } from "vitest";
import { createFsStore, openStore } from "./store.js";
+1 -1
View File
@@ -1,7 +1,7 @@
import { afterEach, beforeEach, describe, expect, test } from "vitest";
import { existsSync, mkdtempSync, rmSync } from "node:fs";
import { tmpdir } from "node:os";
import { join } from "node:path";
import { afterEach, beforeEach, describe, expect, test } from "vitest";
import { openStore } from "./store.js";
const T1 = "AAAAAAAAAAAAA";
+1 -1
View File
@@ -1,4 +1,3 @@
import { afterEach, beforeEach, describe, expect, test } from "vitest";
import { existsSync, mkdtempSync, rmSync } from "node:fs";
import { tmpdir } from "node:os";
import { join } from "node:path";
@@ -11,6 +10,7 @@ import {
TagLabelConflictError,
VariableNotFoundError,
} from "@ocas/core";
import { afterEach, beforeEach, describe, expect, test } from "vitest";
import { openStore } from "./store.js";
const META_TYPE_KEY = Symbol.for("@ocas/core/bootstrap-store");
+108 -854
View File
File diff suppressed because it is too large Load Diff
+2
View File
@@ -1,2 +1,4 @@
packages:
- "packages/*"
minimumReleaseAge: 0