fix(core): Improve error handling and logging; enhance search query sanitization; update dependency versions and documentation

This commit is contained in:
2025-08-12 11:25:42 +00:00
parent a91fac450a
commit e58c0fd215
17 changed files with 3068 additions and 1596 deletions

View File

@@ -0,0 +1,44 @@
# Code Style & Conventions
## TypeScript Standards
- **Target**: ES2022
- **Module System**: ESM with NodeNext resolution
- **Decorators**: Experimental decorators enabled
- **Strict Mode**: Implied through TypeScript configuration
## Naming Conventions
- **Interfaces**: Prefix with `I` (e.g., `IUserData`, `IConfig`)
- **Types**: Prefix with `T` (e.g., `TResponseType`, `TQueryResult`)
- **Classes**: PascalCase (e.g., `SmartdataDb`, `SmartDataDbDoc`)
- **Files**: All lowercase (e.g., `classes.doc.ts`, `plugins.ts`)
- **Methods**: camelCase (e.g., `findOne`, `saveToDb`)
## Import Patterns
- All external dependencies imported in `ts/plugins.ts`
- Reference as `plugins.moduleName.method()`
- Use full import paths for internal modules
- Maintain ESM syntax throughout
## Class Structure
- Use decorators for MongoDB document definitions
- Extend base classes (SmartDataDbDoc, SmartDataDbCollection)
- Static methods for factory patterns
- Instance methods for document operations
## Async Patterns
- Preserve Promise-based patterns
- Use async/await for clarity
- Handle errors appropriately
- Return typed Promises
## MongoDB Specifics
- Use `@unify()` decorator for unique fields
- Use `@svDb()` decorator for database fields
- Implement proper serialization/deserialization
- Type-safe query construction with DeepQuery<T>
## Testing Patterns
- Import from `@git.zone/tstest/tapbundle`
- End test files with `export default tap.start()`
- Use descriptive test names
- Cover edge cases and error conditions

View File

@@ -0,0 +1,37 @@
# Project Overview: @push.rocks/smartdata
## Purpose
An advanced TypeScript-first MongoDB wrapper library providing enterprise-grade features for distributed systems, real-time data synchronization, and easy data management.
## Tech Stack
- **Language**: TypeScript (ES2022 target)
- **Runtime**: Node.js >= 16.x
- **Database**: MongoDB >= 4.4
- **Build System**: tsbuild
- **Test Framework**: tstest with tapbundle
- **Package Manager**: pnpm (v10.7.0)
- **Module System**: ESM (ES Modules)
## Key Features
- Type-safe MongoDB integration with decorators
- Document management with automatic timestamps
- EasyStore for key-value storage
- Distributed coordination with leader election
- Real-time data sync with RxJS watchers
- Deep query type safety
- Enhanced cursor API
- Powerful search capabilities
## Project Structure
- **ts/**: Main TypeScript source code
- Core classes for DB, Collections, Documents, Cursors
- Distributed coordinator, EasyStore, Watchers
- Lucene adapter for search functionality
- **test/**: Test files using tstest framework
- **dist_ts/**: Compiled JavaScript output
## Key Dependencies
- MongoDB driver (v6.18.0)
- @push.rocks ecosystem packages
- @tsclass/tsclass for decorators
- RxJS for reactive programming

View File

@@ -0,0 +1,35 @@
# Suggested Commands for @push.rocks/smartdata
## Build & Development
- `pnpm build` - Build the TypeScript project with web support
- `pnpm buildDocs` - Generate documentation using tsdoc
- `tsbuild --web --allowimplicitany` - Direct build command
## Testing
- `pnpm test` - Run all tests in test/ directory
- `pnpm testSearch` - Run specific search test
- `tstest test/test.specific.ts --verbose` - Run specific test with verbose output
- `tsbuild check test/**/* --skiplibcheck` - Type check test files
## Package Management
- `pnpm install` - Install dependencies
- `pnpm install --save-dev <package>` - Add dev dependency
- `pnpm add <package>` - Add production dependency
## Version Control
- `git status` - Check current changes
- `git diff` - View uncommitted changes
- `git log --oneline -10` - View recent commits
- `git mv <old> <new>` - Move/rename files preserving history
## System Utilities (Linux)
- `ls -la` - List all files with details
- `grep -r "pattern" .` - Search for pattern in files
- `find . -name "*.ts"` - Find TypeScript files
- `ps aux | grep node` - Find Node.js processes
- `lsof -i :80` - Check process on port 80
## Debug & Development
- `tsx <script.ts>` - Run TypeScript file directly
- Store debug scripts in `.nogit/debug/`
- Curl endpoints for API testing

View File

@@ -0,0 +1,33 @@
# Task Completion Checklist
When completing any coding task in this project, always:
## Before Committing
1. **Build the project**: Run `pnpm build` to ensure TypeScript compiles
2. **Run tests**: Execute `pnpm test` to verify nothing is broken
3. **Type check**: Verify types compile correctly
4. **Check for lint issues**: Look for any code style violations
## Code Quality Checks
- Verify all imports are in `ts/plugins.ts` for external dependencies
- Check that interfaces are prefixed with `I`
- Check that types are prefixed with `T`
- Ensure filenames are lowercase
- Verify async patterns are preserved where needed
- Check that decorators are properly used for MongoDB documents
## Documentation
- Update relevant comments if functionality changed
- Ensure new exports are properly documented
- Update readme.md if new features added (only if explicitly requested)
## Git Hygiene
- Make small, focused commits
- Write clear commit messages
- Use `git mv` for file operations
- Never commit sensitive data or keys
## Final Verification
- Test the specific functionality that was changed
- Ensure no unintended side effects
- Verify the change solves the original problem completely