jexidb 2.0.3 โ†’ 2.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (79) hide show
  1. package/.babelrc +13 -0
  2. package/.gitattributes +2 -0
  3. package/CHANGELOG.md +132 -101
  4. package/LICENSE +21 -21
  5. package/README.md +301 -639
  6. package/babel.config.json +5 -0
  7. package/dist/Database.cjs +5204 -0
  8. package/docs/API.md +908 -241
  9. package/docs/EXAMPLES.md +701 -177
  10. package/docs/README.md +194 -184
  11. package/examples/iterate-usage-example.js +157 -0
  12. package/examples/simple-iterate-example.js +115 -0
  13. package/jest.config.js +24 -0
  14. package/package.json +63 -54
  15. package/scripts/README.md +47 -0
  16. package/scripts/benchmark-array-serialization.js +108 -0
  17. package/scripts/clean-test-files.js +75 -0
  18. package/scripts/prepare.js +31 -0
  19. package/scripts/run-tests.js +80 -0
  20. package/scripts/score-mode-demo.js +45 -0
  21. package/src/Database.mjs +5325 -0
  22. package/src/FileHandler.mjs +1140 -0
  23. package/src/OperationQueue.mjs +279 -0
  24. package/src/SchemaManager.mjs +268 -0
  25. package/src/Serializer.mjs +702 -0
  26. package/src/managers/ConcurrencyManager.mjs +257 -0
  27. package/src/managers/IndexManager.mjs +2094 -0
  28. package/src/managers/QueryManager.mjs +1490 -0
  29. package/src/managers/StatisticsManager.mjs +262 -0
  30. package/src/managers/StreamingProcessor.mjs +429 -0
  31. package/src/managers/TermManager.mjs +278 -0
  32. package/src/utils/operatorNormalizer.mjs +116 -0
  33. package/test/$not-operator-with-and.test.js +282 -0
  34. package/test/README.md +8 -0
  35. package/test/close-init-cycle.test.js +256 -0
  36. package/test/coverage-method.test.js +93 -0
  37. package/test/critical-bugs-fixes.test.js +1069 -0
  38. package/test/deserialize-corruption-fixes.test.js +296 -0
  39. package/test/exists-method.test.js +318 -0
  40. package/test/explicit-indexes-comparison.test.js +219 -0
  41. package/test/filehandler-non-adjacent-ranges-bug.test.js +175 -0
  42. package/test/index-line-number-regression.test.js +100 -0
  43. package/test/index-missing-index-data.test.js +91 -0
  44. package/test/index-persistence.test.js +491 -0
  45. package/test/index-serialization.test.js +314 -0
  46. package/test/indexed-query-mode.test.js +360 -0
  47. package/test/insert-session-auto-flush.test.js +353 -0
  48. package/test/iterate-method.test.js +272 -0
  49. package/test/legacy-operator-compat.test.js +154 -0
  50. package/test/query-operators.test.js +238 -0
  51. package/test/regex-array-fields.test.js +129 -0
  52. package/test/score-method.test.js +298 -0
  53. package/test/setup.js +17 -0
  54. package/test/term-mapping-minimal.test.js +154 -0
  55. package/test/term-mapping-simple.test.js +257 -0
  56. package/test/term-mapping.test.js +514 -0
  57. package/test/writebuffer-flush-resilience.test.js +204 -0
  58. package/dist/FileHandler.js +0 -688
  59. package/dist/IndexManager.js +0 -353
  60. package/dist/IntegrityChecker.js +0 -364
  61. package/dist/JSONLDatabase.js +0 -1333
  62. package/dist/index.js +0 -617
  63. package/docs/MIGRATION.md +0 -295
  64. package/examples/auto-save-example.js +0 -158
  65. package/examples/cjs-usage.cjs +0 -82
  66. package/examples/close-vs-delete-example.js +0 -71
  67. package/examples/esm-usage.js +0 -113
  68. package/examples/example-columns.idx.jdb +0 -0
  69. package/examples/example-columns.jdb +0 -9
  70. package/examples/example-options.idx.jdb +0 -0
  71. package/examples/example-options.jdb +0 -0
  72. package/examples/example-users.idx.jdb +0 -0
  73. package/examples/example-users.jdb +0 -5
  74. package/examples/simple-test.js +0 -55
  75. package/src/FileHandler.js +0 -674
  76. package/src/IndexManager.js +0 -363
  77. package/src/IntegrityChecker.js +0 -379
  78. package/src/JSONLDatabase.js +0 -1391
  79. package/src/index.js +0 -608
package/.babelrc ADDED
@@ -0,0 +1,13 @@
1
+
2
+ {
3
+ "presets": [
4
+ ["@babel/preset-env", {
5
+ "targets": {
6
+ "node": "current"
7
+ }
8
+ }]
9
+ ],
10
+ "plugins": [
11
+ "@babel/plugin-transform-async-generator-functions"
12
+ ]
13
+ }
package/.gitattributes ADDED
@@ -0,0 +1,2 @@
1
+ # Auto detect text files and perform LF normalization
2
+ * text=auto
package/CHANGELOG.md CHANGED
@@ -1,109 +1,140 @@
1
1
  # Changelog
2
2
 
3
- All notable changes to JexiDB will be documented in this file.
3
+ All notable changes to this project will be documented in this file.
4
4
 
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
- ## [2.0.3] - 2024-12-19
9
-
10
- ### ๐Ÿš€ Added
11
- - **Intelligent Auto-Save System**: Automatic data persistence with configurable thresholds and intervals
12
- - `autoSaveThreshold`: Flush buffer when it reaches N records (default: 50)
13
- - `autoSaveInterval`: Flush buffer every N milliseconds (default: 5000ms)
14
- - `forceSaveOnClose`: Always save when closing database (default: true)
15
- - **New Public Methods**:
16
- - `flush()`: Explicitly flush insertion buffer to disk
17
- - `forceSave()`: Force save operation regardless of buffer size
18
- - `getBufferStatus()`: Get current buffer state information
19
- - `configurePerformance(settings)`: Dynamic performance configuration
20
- - `getPerformanceConfig()`: Get current performance settings
21
- - `deleteDatabase()`: Permanently delete database file
22
- - `removeDatabase()`: Alias for deleteDatabase()
23
- - **Event-Driven Monitoring**: New events for auto-save operations
24
- - `buffer-flush`: Emitted when buffer is flushed
25
- - `buffer-full`: Emitted when buffer reaches threshold
26
- - `auto-save-timer`: Emitted when time-based auto-save triggers
27
- - `save-complete`: Emitted when save operation completes
28
- - `close-save-complete`: Emitted when database closes with final save
29
- - `performance-configured`: Emitted when performance settings change
30
- - `delete-database`: Emitted when database file is deleted
31
- - **Performance Configuration Options**:
32
- - `adaptiveBatchSize`: Adjust batch size based on usage (default: true)
33
- - `minBatchSize`: Minimum batch size for flush (default: 10)
34
- - `maxBatchSize`: Maximum batch size for performance (default: 200)
35
- - `maxMemoryUsage`: Memory usage limits
36
- - `maxFlushChunkBytes`: Maximum bytes per flush chunk (default: 8MB)
37
-
38
- ### ๐Ÿ”ง Changed
39
- - **API Simplification**: Removed confirmation requirements from `deleteDatabase()` and `removeDatabase()`
40
- - Methods now work directly without `force` or `confirm` options
41
- - Names are self-explanatory and follow industry standards
42
- - **Constructor Defaults**: Updated default options for better performance
43
- - `batchSize`: Reduced from 100 to 50 for faster response
44
- - `autoSave`: Enabled by default (true)
45
- - `autoSaveThreshold`: 50 records
46
- - `autoSaveInterval`: 5000ms (5 seconds)
47
- - `forceSaveOnClose`: Enabled by default (true)
48
- - **Method Behavior**:
49
- - `destroy()`: Now equivalent to `close()` (closes instance, keeps file)
50
- - `deleteDatabase()`: Permanently deletes database file
51
- - `removeDatabase()`: Alias for `deleteDatabase()`
52
-
53
- ### ๐Ÿ› Fixed
54
- - **Query Operators**: Fixed issues with `$gt`, `$gte`, `$lt`, `$lte`, `$ne`, `$nin` operators
55
- - **Data Duplication**: Resolved duplicate results in `find()` operations
56
- - **Type Preservation**: Fixed numeric values being stored as strings in persistent indexes
57
- - **Persistence Issues**: Corrected data persistence between database instances
58
- - **Performance Test Logic**: Fixed test expectations for large dataset operations
59
-
60
- ### ๐Ÿ“š Documentation
61
- - **Updated README.md**: Added comprehensive auto-save documentation and examples
62
- - **Updated API.md**: Added new methods, events, and configuration options
63
- - **New Examples**: Created `auto-save-example.js` and `close-vs-delete-example.js`
64
- - **Enhanced Tests**: Added comprehensive test suite for auto-save functionality
8
+ ## [2.1.0] - 2024-12-19
9
+
10
+ ### โš ๏ธ BREAKING CHANGES
11
+
12
+ This version is **NOT backward compatible** with databases created with previous versions.
13
+
14
+ ### ๐Ÿš€ Major Features
15
+
16
+ #### **Term Mapping Auto-Detection**
17
+
18
+ - **BREAKING**: `termMapping` is now `true` by default (was `false`)
19
+ - **BREAKING**: `termMappingFields` is now auto-detected from `indexes` (was manual configuration)
20
+ - **NEW**: Automatic detection of `string` and `array:string` fields for term mapping
21
+ - **NEW**: Zero-configuration term mapping for optimal performance
22
+
23
+ #### **Schema Requirements**
24
+
25
+ - **BREAKING**: `fields` option is now **MANDATORY** (was optional)
26
+ - **NEW**: Clear distinction between `fields` (schema definition) and `indexes` (performance optimization)
27
+ - **NEW**: Enhanced schema validation and error messages
28
+
29
+ #### **Index Management**
30
+
31
+ - **BREAKING**: `array:string` fields now use term IDs in indexes (was string values)
32
+ - **BREAKING**: `array:number` fields use direct numeric values (was incorrectly term-mapped)
33
+ - **NEW**: Improved index performance for array fields
34
+ - **NEW**: Better memory usage for repetitive string data
35
+
36
+ ### ๐Ÿ”ง Improvements
37
+
38
+ #### **Database Constructor**
39
+
40
+ - **BREAKING**: `fields` parameter is now required
41
+ - **NEW**: Auto-detection of term mapping fields
42
+ - **NEW**: Enhanced error messages for missing schema
43
+ - **NEW**: Better validation of field types
44
+
45
+ #### **Query Performance**
46
+
47
+ - **NEW**: Optimized query processing for term-mapped fields
48
+ - **NEW**: Improved `$in` operator handling for arrays
49
+ - **NEW**: Better support for mixed field types in queries
50
+
51
+ #### **Documentation**
52
+
53
+ - **NEW**: Complete API documentation overhaul
54
+ - **NEW**: Practical examples with proper schema usage
55
+ - **NEW**: Performance optimization guidelines
56
+ - **NEW**: Migration guide for version 2.x
57
+
58
+ ### ๐Ÿ› Bug Fixes
59
+
60
+ - Fixed `array:string` fields incorrectly using string values instead of term IDs
61
+ - Fixed `array:number` fields being incorrectly term-mapped
62
+ - Fixed term mapping not being enabled by default
63
+ - Fixed missing `termMappingFields` property on TermManager
64
+ - Fixed IndexManager not correctly identifying term mapping fields
65
+
66
+ ### ๐Ÿ“š Documentation Updates
67
+
68
+ - **NEW**: Comprehensive API reference with examples
69
+ - **NEW**: Schema vs Indexes distinction clearly explained
70
+ - **NEW**: Performance tips and best practices
71
+ - **NEW**: Migration guide for existing users
72
+ - **NEW**: `beginInsertSession()` documentation
73
+
74
+ ### ๐Ÿ”„ Migration Guide
75
+
76
+ #### **For Existing Users (1.x.x โ†’ 2.1.0)**
77
+
78
+ 1. **Update your database initialization:**
79
+
80
+ ```javascript
81
+ // โŒ OLD (1.x.x)
82
+ const db = new Database('db.jdb', {
83
+ indexes: { name: 'string', tags: 'array:string' }
84
+ })
85
+
86
+ // โœ… NEW (2.1.0)
87
+ const db = new Database('db.jdb', {
88
+ fields: { // REQUIRED - Define schema
89
+ id: 'number',
90
+ name: 'string',
91
+ tags: 'array:string'
92
+ },
93
+ indexes: { // OPTIONAL - Performance optimization
94
+ name: 'string',
95
+ tags: 'array:string'
96
+ }
97
+ })
98
+ ```
99
+ 2. **Database files are NOT compatible:**
100
+
101
+ - Existing `.jdb` files from 1.x.x will not work with 2.1.0
102
+ - You need to export data from 1.x.x and re-import to 2.1.0
103
+ - Consider this a fresh start for your database files
104
+ 3. **Term mapping is now automatic:**
105
+
106
+ - No need to manually configure `termMapping: true`
107
+ - No need to specify `termMappingFields`
108
+ - Fields are auto-detected from your `indexes` configuration
109
+
110
+ ### ๐ŸŽฏ Performance Improvements
111
+
112
+ - **Up to 77% reduction** in database size for repetitive string data
113
+ - **Faster queries** on term-mapped fields
114
+ - **Better memory usage** for large datasets
115
+ - **Optimized indexing** for array fields
65
116
 
66
117
  ### ๐Ÿงช Testing
67
- - **New Test Suite**: Added `tests/auto-save.test.js` with 10 comprehensive tests
68
- - **All Tests Passing**: 86 tests passing (100% success rate)
69
- - **Improved Coverage**: Better test coverage for new auto-save features
70
-
71
- ## [2.0.2] - 2024-12-18
72
-
73
- ### ๐Ÿš€ Added
74
- - **Persistent Indexes**: Indexes are now saved to disk and loaded on startup
75
- - **Point Reading**: Efficient memory usage - only reads necessary data
76
- - **Rich Query API**: Support for complex queries with operators, sorting, and pagination
77
- - **Event-Driven Architecture**: Real-time notifications for all database operations
78
- - **Automatic Integrity Validation**: Built-in data integrity checking and repair
79
- - **Legacy Compatibility**: Automatic migration from JexiDB 1.x databases
80
- - **Pure JavaScript**: No native dependencies, works everywhere
81
-
82
- ### ๐Ÿ”ง Changed
83
- - **Performance**: 10-100x faster than JexiDB 1.x
84
- - **Memory Usage**: 25% less memory consumption
85
- - **File Format**: Improved JSONL architecture with separate index files
86
- - **API**: Enhanced query methods with MongoDB-style operators
87
-
88
- ### ๐Ÿ› Fixed
89
- - **Data Integrity**: Safe truncation and consistent offsets
90
- - **Test Isolation**: Proper test isolation and cleanup
91
- - **V8 Dependency**: Removed dependency on V8 engine
92
-
93
- ## [2.0.1] - 2024-12-17
94
-
95
- ### ๐Ÿš€ Added
96
- - **Initial Release**: First stable version of JexiDB 2.0
97
- - **JSONL Architecture**: Pure JavaScript JSONL database implementation
98
- - **Basic CRUD Operations**: Insert, find, update, delete operations
99
- - **Index Support**: Basic indexing for fast queries
100
- - **File Management**: Database file creation and management
101
-
102
- ### ๐Ÿ”ง Changed
103
- - **Complete Rewrite**: New architecture from ground up
104
- - **Performance Focus**: Optimized for speed and efficiency
105
- - **Modern JavaScript**: ES6+ features and async/await support
106
-
107
- ### ๐Ÿ› Fixed
108
- - **Stability**: Improved error handling and edge cases
109
- - **Compatibility**: Better Node.js version support
118
+
119
+ - **NEW**: Comprehensive test suite for term mapping
120
+ - **NEW**: Performance benchmarks for large datasets
121
+ - **NEW**: Migration compatibility tests
122
+ - **NEW**: Edge case testing for array fields
123
+
124
+ ---
125
+
126
+ ## [1.1.0] - Previous Version
127
+
128
+ ### Features
129
+
130
+ - Basic database functionality
131
+ - Manual term mapping configuration
132
+ - Optional schema definition
133
+ - Basic indexing support
134
+
135
+ ### Limitations
136
+
137
+ - Term mapping required manual configuration
138
+ - Schema was optional, leading to confusion
139
+ - Array fields had indexing issues
140
+ - Performance not optimized for repetitive data
package/LICENSE CHANGED
@@ -1,21 +1,21 @@
1
- MIT License
2
-
3
- Copyright (c) 2024 Edenware
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Edenware.app
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.