UNPKG

@juspay/neurolink

Version:

Universal AI Development Platform with working MCP integration, multi-provider support, voice (TTS/STT/realtime), and professional CLI. 58+ external MCP servers discoverable, multimodal file processing, RAG pipelines. Build, test, and deploy AI applicatio

41 lines 1.42 kB
import { randomUUID } from "node:crypto"; import { mkdir, rename, rm, writeFile } from "node:fs/promises"; import { basename, dirname, join } from "node:path"; const writeLocks = new Map(); async function writeSnapshotFile(targetPath, payload, mode) { const dir = dirname(targetPath); const baseName = basename(targetPath); await mkdir(dir, { recursive: true }); const tempPath = join(dir, `.${baseName}.${process.pid}.${randomUUID()}.tmp`); try { await writeFile(tempPath, payload, { mode }); await rename(tempPath, targetPath); } finally { await rm(tempPath, { force: true }).catch(() => { // Best-effort cleanup only. }); } } export async function writeJsonSnapshotAtomically(targetPath, data, mode = 0o600) { const payload = JSON.stringify(data, null, 2); const previous = writeLocks.get(targetPath) ?? Promise.resolve(); const next = previous .catch(() => { // Preserve the queue even if a previous write failed. }) .then(() => writeSnapshotFile(targetPath, payload, mode)); writeLocks.set(targetPath, next); try { await next; } finally { if (writeLocks.get(targetPath) === next) { writeLocks.delete(targetPath); } } } export function clearSnapshotWriteLocksForTests() { writeLocks.clear(); } //# sourceMappingURL=snapshotPersistence.js.map