UNPKG

@struktoai/mirage-core

Version:

A Unified Virtual Filesystem For AI Agents

56 lines • 2.13 kB
// ========= Copyright 2026 @ Strukto.AI All Rights Reserved. ========= // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // ========= Copyright 2026 @ Strukto.AI All Rights Reserved. ========= import { generationOf } from "../../record/types.js"; import { NamespaceStore } from "./store.js"; // NamespaceStore held in process memory (the default). Durability equals // the process lifetime; snapshots remain the only persistence. Redis-backed // workspaces pass a RedisNamespaceStore instead and survive restarts. export class RAMNamespaceStore extends NamespaceStore { entries = new Map(); load() { const out = new Map(); for (const [key, fields] of this.entries) out.set(key, { ...fields }); return Promise.resolve(out); } set(key, fields) { this.entries.set(key, { ...fields }); return Promise.resolve(); } casSet(key, fields, expectedGeneration) { if (generationOf(this.entries.get(key)) !== expectedGeneration) return Promise.resolve(false); this.entries.set(key, { ...fields }); return Promise.resolve(true); } delete(keys) { for (const key of keys) this.entries.delete(key); return Promise.resolve(); } replaceAll(entries) { this.entries.clear(); for (const [key, fields] of entries) this.entries.set(key, { ...fields }); return Promise.resolve(); } clear() { this.entries.clear(); return Promise.resolve(); } close() { return Promise.resolve(); } } //# sourceMappingURL=ram.js.map