@t1mmen/srtd
Version:
Supabase Repeatable Template Definitions (srtd): 🪄 Live-reloading SQL templates for Supabase DX. Make your database changes reviewable and migrations maintainable! 🚀
55 lines • 1.76 kB
JavaScript
/**
* Create the base JSON output envelope.
* Used by all commands for consistent structure.
*/
export function createBaseJsonOutput(command, success, error) {
const output = {
success,
command,
timestamp: new Date().toISOString(),
};
if (error)
output.error = error;
return output;
}
/**
* Write a JSON object to stdout with pretty formatting and trailing newline.
* Centralized helper to ensure consistent JSON output across all commands.
*/
export function writeJson(output) {
process.stdout.write(`${JSON.stringify(output, null, 2)}\n`);
}
/**
* Format a fatal error response for batch commands (build/apply).
* Used in catch blocks when the entire operation fails before processing templates.
*/
export function formatFatalError(command, error) {
return {
success: false,
command,
timestamp: new Date().toISOString(),
error,
results: [],
summary: { total: 0, success: 0, error: 1, unchanged: 0, skipped: 0 },
};
}
export function formatJsonOutput(results, command) {
const countByStatus = (status) => results.filter(r => r.status === status).length;
// Count 'built' as success too (per plan requirement)
const successCount = countByStatus('success') + countByStatus('built');
const errorCount = countByStatus('error');
return {
success: errorCount === 0,
command,
timestamp: new Date().toISOString(),
results,
summary: {
total: results.length,
success: successCount,
error: errorCount,
unchanged: countByStatus('unchanged'),
skipped: countByStatus('skipped'),
},
};
}
//# sourceMappingURL=jsonOutput.js.map