UNPKG

@variablesoftware/mock-d1

Version:

🎛️🗂️🧠 Mock D1 Database implementation for testing Cloudflare Workers

19 lines (18 loc) 819 B
import { log } from '@variablesoftware/logface'; /** * Returns a snapshot of the current database state (mock only). * Emits a warning if used outside of test environments. * @param db - The internal Map of tables to rows. * @returns An object mapping table names to their rows. */ export function mockDump(db) { if (typeof process !== 'undefined' && process.env.NODE_ENV !== 'test') { log.warn('mockDump() is a mock/test-only API and should not be used in production.'); } if (process.env.DEBUG || process.env.MOCK_D1_DEBUG) { log.debug('called', { dbKeys: Array.from(db.keys()) }); log.debug('db snapshot', Object.fromEntries(db.entries())); } // Return a stringified dump for test compatibility return JSON.stringify(Object.fromEntries(db.entries()), null, 2); }