jexidb 2.0.2 → 2.1.0

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 (55) hide show
  1. package/.babelrc +13 -0
  2. package/.gitattributes +2 -0
  3. package/CHANGELOG.md +140 -0
  4. package/LICENSE +21 -21
  5. package/README.md +301 -527
  6. package/babel.config.json +5 -0
  7. package/dist/Database.cjs +3896 -0
  8. package/docs/API.md +1051 -0
  9. package/docs/EXAMPLES.md +701 -0
  10. package/docs/README.md +194 -0
  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 -51
  15. package/scripts/README.md +47 -0
  16. package/scripts/clean-test-files.js +75 -0
  17. package/scripts/prepare.js +31 -0
  18. package/scripts/run-tests.js +80 -0
  19. package/src/Database.mjs +4130 -0
  20. package/src/FileHandler.mjs +1101 -0
  21. package/src/OperationQueue.mjs +279 -0
  22. package/src/SchemaManager.mjs +268 -0
  23. package/src/Serializer.mjs +511 -0
  24. package/src/managers/ConcurrencyManager.mjs +257 -0
  25. package/src/managers/IndexManager.mjs +1403 -0
  26. package/src/managers/QueryManager.mjs +1273 -0
  27. package/src/managers/StatisticsManager.mjs +262 -0
  28. package/src/managers/StreamingProcessor.mjs +429 -0
  29. package/src/managers/TermManager.mjs +278 -0
  30. package/test/$not-operator-with-and.test.js +282 -0
  31. package/test/README.md +8 -0
  32. package/test/close-init-cycle.test.js +256 -0
  33. package/test/critical-bugs-fixes.test.js +1069 -0
  34. package/test/index-persistence.test.js +306 -0
  35. package/test/index-serialization.test.js +314 -0
  36. package/test/indexed-query-mode.test.js +360 -0
  37. package/test/iterate-method.test.js +272 -0
  38. package/test/query-operators.test.js +238 -0
  39. package/test/regex-array-fields.test.js +129 -0
  40. package/test/score-method.test.js +238 -0
  41. package/test/setup.js +17 -0
  42. package/test/term-mapping-minimal.test.js +154 -0
  43. package/test/term-mapping-simple.test.js +257 -0
  44. package/test/term-mapping.test.js +514 -0
  45. package/test/writebuffer-flush-resilience.test.js +204 -0
  46. package/dist/FileHandler.js +0 -688
  47. package/dist/IndexManager.js +0 -353
  48. package/dist/IntegrityChecker.js +0 -364
  49. package/dist/JSONLDatabase.js +0 -1194
  50. package/dist/index.js +0 -617
  51. package/src/FileHandler.js +0 -674
  52. package/src/IndexManager.js +0 -363
  53. package/src/IntegrityChecker.js +0 -379
  54. package/src/JSONLDatabase.js +0 -1248
  55. 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 ADDED
@@ -0,0 +1,140 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
+
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
116
+
117
+ ### 🧪 Testing
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.