Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 | /**
* Metadata handling for Rosetta configurations
*/
/**
* Create default metadata
* @param {Object} options - Options for metadata creation
* @returns {Object} Metadata object
*/
export function createMetadata(options = {}) {
const now = new Date().toISOString();
return {
created_at: options.createdAt || now,
updated_at: options.updatedAt || now,
version: options.version || '1.0.0',
source: options.source || null,
migrations: options.migrations || []
};
}
/**
* Update metadata with new timestamp
* @param {Object} metadata - Existing metadata
* @returns {Object} Updated metadata
*/
export function updateMetadata(metadata = {}) {
return {
...metadata,
updated_at: new Date().toISOString()
};
}
/**
* Add migration record to metadata
* @param {Object} metadata - Existing metadata
* @param {string} from - Source format
* @param {string} to - Target format
* @returns {Object} Updated metadata
*/
export function addMigrationRecord(metadata, from, to) {
const migrations = metadata.migrations || [];
return {
...metadata,
migrations: [
...migrations,
{
from,
to,
timestamp: new Date().toISOString()
}
],
updated_at: new Date().toISOString()
};
}
/**
* Extract metadata for IDE-specific output
* @param {Object} metadata - Full metadata object
* @param {string} format - Target format (yaml, markdown, etc.)
* @returns {string} Formatted metadata string
*/
export function formatMetadata(metadata, format = 'markdown') {
if (format === 'yaml') {
return formatMetadataAsYaml(metadata);
}
return formatMetadataAsMarkdown(metadata);
}
/**
* Format metadata as YAML comment block
*/
function formatMetadataAsYaml(metadata) {
const lines = ['# Rosetta Metadata'];
if (metadata.created_at) {
lines.push(`# Created: ${metadata.created_at}`);
}
if (metadata.updated_at) {
lines.push(`# Updated: ${metadata.updated_at}`);
}
if (metadata.version) {
lines.push(`# Version: ${metadata.version}`);
}
if (metadata.source) {
lines.push(`# Source: ${metadata.source}`);
}
return lines.join('\n');
}
/**
* Format metadata as markdown comment block
*/
function formatMetadataAsMarkdown(metadata) {
const lines = ['<!--'];
lines.push(' Rosetta Metadata');
lines.push('');
if (metadata.created_at) {
lines.push(` Created: ${metadata.created_at}`);
}
if (metadata.updated_at) {
lines.push(` Updated: ${metadata.updated_at}`);
}
if (metadata.version) {
lines.push(` Version: ${metadata.version}`);
}
if (metadata.source) {
lines.push(` Source: ${metadata.source}`);
}
lines.push('-->');
return lines.join('\n');
}
|