Files
ocas/packages/core/src/mem-store.ts
T
xiaoju 0041fc4e23 fix(core,fs): phase 3 cleanup — drop legacy Store, sync bootstrap, dedup VarStore
- Remove legacy `Store` type with `Promise<Hash>` `put`; rename `OcasStore` → `Store`
  across @ocas/core, @ocas/fs, @ocas/cli (production + tests).
- Migrate `BootstrapCapableStore` to `CasStore`; `[BOOTSTRAP_STORE]` returns `Hash`
  synchronously.
- Make `bootstrap()` and `putSchema()` synchronous; remove `await` at all call sites.
- Extract pure VarStore helpers into `packages/core/src/var-store-helpers.ts`
  (`varKey`, `addNameIndex`, `removeNameIndex`, `extractSchema`, `checkTagLabelConflict`,
  `pushHistory`, `cloneVarRecord`, `VarRecord`); both `MemoryVarStore` (-74 lines) and
  `FsVarStore` (-63 lines) now delegate to them while keeping persistence separate.

Refs #47
2026-06-02 10:02:19 +00:00

38 lines
1.4 KiB
TypeScript

import { createMemoryStore } from "./store.js";
import type { CasStore, Store, TagStore, VarStore } from "./types.js";
/**
* In-memory `Store` used by schema validation tests. It exposes the
* `cas`, `var`, and `tag` sub-stores of an `Store` plus a few legacy
* pass-through helpers (`get`, `put`, `has`, …) that some older tests still
* use directly.
*/
export class MemStore implements Store {
readonly cas: CasStore;
readonly var: VarStore;
readonly tag: TagStore;
constructor() {
const store = createMemoryStore();
this.cas = store.cas;
this.var = store.var;
this.tag = store.tag;
}
// Legacy convenience pass-throughs ----------------------------------------
get = (hash: Parameters<CasStore["get"]>[0]): ReturnType<CasStore["get"]> =>
this.cas.get(hash);
has = (hash: Parameters<CasStore["has"]>[0]): ReturnType<CasStore["has"]> =>
this.cas.has(hash);
put = (
typeHash: Parameters<CasStore["put"]>[0],
payload: unknown,
): ReturnType<CasStore["put"]> => this.cas.put(typeHash, payload);
listByType: CasStore["listByType"] = (typeHash, options) =>
this.cas.listByType(typeHash, options);
listAll: CasStore["listAll"] = () => this.cas.listAll();
listMeta: CasStore["listMeta"] = (options) => this.cas.listMeta(options);
listSchemas: CasStore["listSchemas"] = (options) =>
this.cas.listSchemas(options);
}