Skip to content

Privacy-first password manager with built-in email aliasing. Fully encrypted and self-hostable.

1.3 KB
Raw Blame
#!/usr/bin/env node
/**
 * Writes the complete vault schema from the TypeScript source to a .sql file that the Rust core embeds,
 */

const fs = require('fs');
const path = require('path');

const REPO_ROOT = path.join(__dirname, '../../..');
const TS_SQL_SOURCE = path.join(REPO_ROOT, 'core/vault/src/sql/SqlConstants.ts');
const SQL_OUTPUT = path.join(REPO_ROOT, 'core/rust/src/sqlite_host/vault_schema.sql');

/**
 * Parse COMPLETE_SCHEMA_SQL from TypeScript source
 */
function parseCompleteSchemaSql(tsContent) {
  const match = tsContent.match(/export const COMPLETE_SCHEMA_SQL\s*=\s*`([\s\S]*?)`;/);
  if (!match) {
    throw new Error('Could not find COMPLETE_SCHEMA_SQL in source');
  }

  return match[1].replace(//g, '').trim();
}

/**
 * Main execution
 */
function main() {
  if (!fs.existsSync(TS_SQL_SOURCE)) {
    throw new Error(`Source file not found: ${TS_SQL_SOURCE}`);
  }

  const completeSchemaSql = parseCompleteSchemaSql(fs.readFileSync(TS_SQL_SOURCE, 'utf8'));
  const header = '-- <auto-generated />\n-- Generated from core/vault/src/sql/SqlConstants.ts by core/vault/scripts/generate-vault-sql.cjs. Do not edit manually.\n';
  fs.writeFileSync(SQL_OUTPUT, `${header}${completeSchemaSql}\n`, 'utf8');
  console.log(`Generated: ${SQL_OUTPUT} (${completeSchemaSql.length} chars)`);
}

main();