UNPKG

@sidekick-coder/db

Version:

Cli Tool to manipulate data from diferent sources

23 lines (21 loc) 610 B
// src/providers/file/create.ts async function create(payload) { const { filesystem, root, options, makeId, parser } = payload; const resolve = (...args) => filesystem.path.resolve(root, ...args); const data = options.data; const id = data.id || await makeId(); const filename = resolve(`${id}.${parser.ext}`); if (filesystem.existsSync(filename)) { throw new Error(`Item with id "${id}" already exists`); } const raw = parser.stringify(data); filesystem.writeSync.text(filename, raw); const item = { id, raw, filename, ...data }; return item; } export { create };