All notable changes to this project will be documented in this file.
The format is based on Keep a Changelog, and this project adheres to Semantic Versioning.
- Enhanced error messages in
DBConnectionto include detailed API response data for better debugging - All error messages now display both HTTP status text and JSON response from the API
- Added safe JSON parsing fallback to prevent errors when API response is not valid JSON
- Updated error handling in all
DBConnectionmethods:insertOne()- Now includes API error response detailsinsertMany()- Now includes API error response detailsquery()- Now includes API error response detailsupdateById()- Now includes API error response detailsupdateOne()- Now includes API error response detailsupdateMany()- Now includes API error response detailsdeleteById()- Now includes API error response detailsdeleteOne()- Now includes API error response detailsdeleteMany()- Now includes API error response detailscount()- Now includes API error response detailsexists()- Now includes API error response details
- Significantly improved debugging experience with detailed error information
- Error messages now show the exact error response from the server, making it easier to identify and fix issues
domainconfiguration option toDBConnectionto support custom API domains- Automatic injection of
x-article-idandx-product-idheaders whenwindow.store_postorwindow.store_productare present - Updated documentation to reflect new configuration options
- Enhanced TypeScript definitions for better type safety and IntelliSense support
- Added
DBConnectionHeadersinterface with specific header properties for better autocomplete - Improved type definitions for
PopulateConfigto maketableandreferenceFieldoptional for more flexible usage
DBConnectionConfig.headersnow usesDBConnectionHeadersinterface instead of genericRecord<string, string>DBConnection.headersproperty now has explicit typeDBConnectionHeadersfor better type checkingPopulateConfig.tableandPopulateConfig.referenceFieldare now optional to support more flexible populate configurations
- TypeScript autocomplete support for common headers:
Content-TypeAuthorizationx-cms-api-keyx-article-idx-product-id
- Index signature in
DBConnectionHeadersto allow custom headers while maintaining type safety
DBModel.findOne()andDBModel.findById()now accept options forselect,sort, andpopulateto match QueryBuilder capabilities
- Automatically include
x-article-idheader whenwindow.store_post.viewPost.idis available - Automatically include
x-product-idheader whenwindow.store_product.viewProduct.idis available
- Guard browser-specific headers during
DBConnectioninitialization to ensure window dependencies are optional
- Enhanced
QueryBuilder.where()method to support object-based filters - Enhanced
populate()method to support object-basedwhereandsortparameters - Improved API consistency between QueryBuilder and populate methods
QueryBuilder.where()now supports three calling patterns:where(filters)- Pass an object with filter conditionswhere(field, value)- Pass field and value (equals)where(field, operator, value)- Pass field, operator, and value
populate()now acceptswhereandsortas objects (like QueryBuilder) or strings- Updated response handling in
updateOne,updateMany,deleteOne, anddeleteManymethods - Added
window.DBConnectionglobal export for easier browser usage
- Fixed
DBModel.find()to use object-based filter application - Updated TypeScript definitions for better type safety
- Added comprehensive examples for new
where()object syntax - Updated all populate examples to use object-based
whereandsort - Enhanced documentation with clearer examples
- Initial release of WebCake Data library
- Initial release of WebCake Data library
DBConnectionclass for managing database connectionsDBModelclass for collection operationsQueryBuilderclass with fluent API for complex queries- Full TypeScript support with type definitions
- ES6 module support for modern JavaScript environments
- Browser compatibility with global window object
- Comprehensive documentation and usage examples
- MIT license
- MongoDB-like query interface
- Fluent query builder with method chaining
- Support for all CRUD operations (Create, Read, Update, Delete)
- Advanced querying with comparison operators (eq, gt, gte, lt, lte, in, nin, ne, between, like)
- Population (join) functionality for related data
- Sorting, limiting, and pagination support
- Field selection for optimized queries
- Batch operations for multiple records
- Error handling with clean error messages
- Zero dependencies for lightweight integration
model(collectionName)- Create a model for a collectioninsertOne(tableName, fields)- Insert a single recordinsertMany(tableName, records)- Insert multiple recordsquery(tableName, queryParams)- Query recordsupdateById(tableName, id, fields)- Update record by IDupdateOne(tableName, filters, fields)- Update one recordupdateMany(tableName, filters, fields)- Update multiple recordsdeleteById(tableName, id)- Delete record by IDdeleteOne(tableName, filters)- Delete one recorddeleteMany(tableName, filters)- Delete multiple recordscount(tableName, filters)- Count recordsexists(tableName, filters)- Check if records exist
create(data)- Create a new documentinsertMany(dataArray)- Create multiple documentsfind(filters)- Find documents (returns QueryBuilder)findOne(filters)- Find one documentfindById(id)- Find document by IDupdateOne(filters, updateData)- Update one documentfindByIdAndUpdate(id, updateData, options)- Update document by IDfindOneAndUpdate(filters, updateData)- Find and update one documentupdateMany(filters, updateData)- Update multiple documentsdeleteOne(filters)- Delete one documentfindByIdAndDelete(id)- Delete document by IDfindOneAndDelete(filters)- Find and delete one documentdeleteMany(filters)- Delete multiple documentscountDocuments(filters)- Count documentsexists(filters)- Check if documents exist
where(field, operator, value)- Add filter conditioneq(field, value)- Equality filtergt(field, value)- Greater than filtergte(field, value)- Greater than or equal filterlt(field, value)- Less than filterlte(field, value)- Less than or equal filterin(field, values)- In array filternin(field, values)- Not in array filterne(field, value)- Not equal filterbetween(field, value1, value2)- Between values filterlike(field, pattern)- Pattern matching filtersort(sortObj)- Sort resultslimit(n)- Limit number of resultsskip(n)- Skip number of resultsselect(fields)- Select specific fieldspopulate(config)- Populate related dataexec()- Execute query
npm install webcake-dataimport { DBConnection } from 'webcake-data';
const db = new DBConnection({
baseURL: 'https://api.webcake.com/api/v1',
siteId: 'your-site-id',
token: 'your-auth-token'
});
const User = db.model('users');
const users = await User.find({ active: true }).exec();