diff --git a/.cursor/rules/absurd-sql.mdc b/.cursor/rules/absurd-sql.mdc index 56729c2a..b141d415 100644 --- a/.cursor/rules/absurd-sql.mdc +++ b/.cursor/rules/absurd-sql.mdc @@ -3,50 +3,50 @@ description: globs: alwaysApply: true --- -# Absurd SQL - Cursor Development Guide +# Absurd SQL - Cursor Development Guide (Directive Style) ## Project Overview -Absurd SQL is a backend implementation for sql.js that enables persistent SQLite databases in the browser by using IndexedDB as a block storage system. This guide provides rules and best practices for developing with this project in Cursor. +Implement persistent SQLite databases in the browser using **Absurd SQL** with IndexedDB as block storage. Execute all SQL operations according to the following directives. ## Project Structure ``` absurd-sql/ -├── src/ # Source code -├── dist/ # Built files -├── package.json # Dependencies and scripts -├── rollup.config.js # Build configuration -└── jest.config.js # Test configuration +├── src/ # Place source code here +├── dist/ # Place built files here +├── package.json # Maintain dependencies and scripts here +├── rollup.config.js # Maintain build configuration here +└── jest.config.js # Maintain test configuration here ``` -## Development Rules +## Directives -### 1. Worker Thread Requirements -- All SQL operations MUST be performed in a worker thread -- Main thread should only handle worker initialization and communication -- Never block the main thread with database operations +### 1. Worker Thread Execution +- Execute **all SQL operations** inside worker threads. +- Restrict the main thread to **initialization** and **communication only**. +- Block **no operations** on the main thread. ### 2. Code Organization -- Keep worker code in separate files (e.g., `*.worker.js`) -- Use ES modules for imports/exports -- Follow the project's existing module structure +- Store worker logic in dedicated files: `*.worker.js`. +- Use **ES modules** exclusively. +- Conform to the existing **module structure**. -### 3. Required Headers -When developing locally or deploying, ensure these headers are set: +### 3. Headers Enforcement +Always set the following headers: ``` Cross-Origin-Opener-Policy: same-origin Cross-Origin-Embedder-Policy: require-corp ``` ### 4. Browser Compatibility -- Primary target: Modern browsers with SharedArrayBuffer support -- Fallback mode: Safari (with limitations) -- Always test in both modes +- Target **modern browsers with SharedArrayBuffer support**. +- Activate fallback mode for Safari when required. +- Test in **both primary and fallback modes** without exception. ### 5. Database Configuration -Recommended database settings: +Apply the following PRAGMA settings immediately: ```sql PRAGMA journal_mode=MEMORY; -PRAGMA page_size=8192; -- Optional, but recommended +PRAGMA page_size=8192; ``` ### 6. Development Workflow @@ -54,100 +54,96 @@ PRAGMA page_size=8192; -- Optional, but recommended ```bash yarn add @jlongster/sql.js absurd-sql ``` - -2. Development commands: - - `yarn build` - Build the project - - `yarn jest` - Run tests - - `yarn serve` - Start development server - -### 7. Testing Guidelines -- Write tests for both SharedArrayBuffer and fallback modes -- Use Jest for testing -- Include performance benchmarks for critical operations - -### 8. Performance Considerations -- Use bulk operations when possible -- Monitor read/write performance -- Consider using transactions for multiple operations -- Avoid unnecessary database connections +2. Execute commands as follows: + - `yarn build` → build the project + - `yarn jest` → run all tests + - `yarn serve` → launch development server + +### 7. Testing +- Write tests for both **SharedArrayBuffer** and **fallback modes**. +- Use **Jest** exclusively. +- Include **performance benchmarks** for critical paths. + +### 8. Performance Optimization +- Execute bulk operations when available. +- Enforce **transactions** for multi-step operations. +- Monitor read/write throughput continuously. +- Reuse database connections. Do **not** open unnecessary ones. ### 9. Error Handling -- Implement proper error handling for: - - Worker initialization failures - - Database connection issues - - Concurrent access conflicts (in fallback mode) - - Storage quota exceeded scenarios - -### 10. Security Best Practices -- Never expose database operations directly to the client -- Validate all SQL queries -- Implement proper access controls -- Handle sensitive data appropriately +Implement error handling for: +- Worker initialization failures +- Database connection issues +- Concurrent access conflicts (fallback mode) +- Storage quota exceeded scenarios + +### 10. Security +- Forbid direct client access to database operations. +- Validate every SQL query. +- Enforce access control measures. +- Handle sensitive data with strict isolation. ### 11. Code Style -- Follow ESLint configuration -- Use async/await for asynchronous operations -- Document complex database operations -- Include comments for non-obvious optimizations +- Follow ESLint configuration. +- Use `async/await` for asynchronous operations. +- Document complex operations thoroughly. +- Comment all optimizations that are not obvious. ### 12. Debugging -- Use `jest-debug` for debugging tests -- Monitor IndexedDB usage in browser dev tools -- Check worker communication in console -- Use performance monitoring tools +- Use `jest-debug` for test debugging. +- Inspect IndexedDB in browser developer tools. +- Trace worker communication in console logs. +- Apply browser performance monitoring tools. -## Common Patterns +## Required Patterns ### Worker Initialization ```javascript -// Main thread import { initBackend } from 'absurd-sql/dist/indexeddb-main-thread'; function init() { - let worker = new Worker(new URL('./index.worker.js', import.meta.url)); + const worker = new Worker(new URL('./index.worker.js', import.meta.url)); initBackend(worker); } ``` ### Database Setup ```javascript -// Worker thread import initSqlJs from '@jlongster/sql.js'; import { SQLiteFS } from 'absurd-sql'; import IndexedDBBackend from 'absurd-sql/dist/indexeddb-backend'; async function setupDatabase() { - let SQL = await initSqlJs({ locateFile: file => file }); - let sqlFS = new SQLiteFS(SQL.FS, new IndexedDBBackend()); + const SQL = await initSqlJs({ locateFile: f => f }); + const sqlFS = new SQLiteFS(SQL.FS, new IndexedDBBackend()); SQL.register_for_idb(sqlFS); - + SQL.FS.mkdir('/sql'); SQL.FS.mount(sqlFS, {}, '/sql'); - + return new SQL.Database('/sql/db.sqlite', { filename: true }); } ``` -## Troubleshooting - -### Common Issues -1. SharedArrayBuffer not available - - Check COOP/COEP headers - - Verify browser support - - Test fallback mode - -2. Worker initialization failures - - Check file paths - - Verify module imports - - Check browser console for errors - -3. Performance issues - - Monitor IndexedDB usage - - Check for unnecessary operations - - Verify transaction usage - -## Resources -- [Project Demo](https://priceless-keller-d097e5.netlify.app/) -- [Example Project](https://github.com/jlongster/absurd-example-project) -- [Blog Post](https://jlongster.com/future-sql-web) -- [SQL.js Documentation](https://github.com/sql-js/sql.js/) \ No newline at end of file +## Troubleshooting Directives + +### If SharedArrayBuffer is unavailable: +- Verify COOP/COEP headers. +- Check browser support. +- Activate fallback mode. + +### If worker initialization fails: +- Verify file paths. +- Confirm module imports. +- Inspect browser console for errors. + +### If performance degrades: +- Inspect IndexedDB usage. +- Eliminate redundant operations. +- Confirm transaction enforcement. + +## Reference Materials +- [Project Demo](https://priceless-keller-d097e5.netlify.app/) +- [Example Project](https://github.com/jlongster/absurd-example-project) +- [Blog Post](https://jlongster.com/future-sql-web) +- [SQL.js Documentation](https://github.com/sql-js/sql.js/) diff --git a/src/views/ContactImportView.vue b/src/views/ContactImportView.vue index a926d189..280450fa 100644 --- a/src/views/ContactImportView.vue +++ b/src/views/ContactImportView.vue @@ -123,74 +123,222 @@