1.5 KiB
1.5 KiB
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
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