jexidb 2.1.0 → 2.1.2

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 (41) hide show
  1. package/dist/Database.cjs +9253 -437
  2. package/package.json +9 -2
  3. package/src/Database.mjs +1572 -212
  4. package/src/FileHandler.mjs +83 -44
  5. package/src/OperationQueue.mjs +23 -23
  6. package/src/SchemaManager.mjs +325 -268
  7. package/src/Serializer.mjs +234 -24
  8. package/src/managers/IndexManager.mjs +778 -87
  9. package/src/managers/QueryManager.mjs +340 -67
  10. package/src/managers/TermManager.mjs +7 -7
  11. package/src/utils/operatorNormalizer.mjs +116 -0
  12. package/.babelrc +0 -13
  13. package/.gitattributes +0 -2
  14. package/CHANGELOG.md +0 -140
  15. package/babel.config.json +0 -5
  16. package/docs/API.md +0 -1051
  17. package/docs/EXAMPLES.md +0 -701
  18. package/docs/README.md +0 -194
  19. package/examples/iterate-usage-example.js +0 -157
  20. package/examples/simple-iterate-example.js +0 -115
  21. package/jest.config.js +0 -24
  22. package/scripts/README.md +0 -47
  23. package/scripts/clean-test-files.js +0 -75
  24. package/scripts/prepare.js +0 -31
  25. package/scripts/run-tests.js +0 -80
  26. package/test/$not-operator-with-and.test.js +0 -282
  27. package/test/README.md +0 -8
  28. package/test/close-init-cycle.test.js +0 -256
  29. package/test/critical-bugs-fixes.test.js +0 -1069
  30. package/test/index-persistence.test.js +0 -306
  31. package/test/index-serialization.test.js +0 -314
  32. package/test/indexed-query-mode.test.js +0 -360
  33. package/test/iterate-method.test.js +0 -272
  34. package/test/query-operators.test.js +0 -238
  35. package/test/regex-array-fields.test.js +0 -129
  36. package/test/score-method.test.js +0 -238
  37. package/test/setup.js +0 -17
  38. package/test/term-mapping-minimal.test.js +0 -154
  39. package/test/term-mapping-simple.test.js +0 -257
  40. package/test/term-mapping.test.js +0 -514
  41. package/test/writebuffer-flush-resilience.test.js +0 -204
@@ -0,0 +1,116 @@
1
+ const aliasToCanonical = {
2
+ '>': '$gt',
3
+ '>=': '$gte',
4
+ '<': '$lt',
5
+ '<=': '$lte',
6
+ '!=': '$ne',
7
+ '=': '$eq',
8
+ '==': '$eq',
9
+ eq: '$eq',
10
+ equals: '$eq',
11
+ in: '$in',
12
+ nin: '$nin',
13
+ regex: '$regex',
14
+ contains: '$contains',
15
+ all: '$all',
16
+ exists: '$exists',
17
+ size: '$size',
18
+ not: '$not'
19
+ }
20
+
21
+ const canonicalToLegacy = {
22
+ '$gt': '>',
23
+ '$gte': '>=',
24
+ '$lt': '<',
25
+ '$lte': '<=',
26
+ '$ne': '!=',
27
+ '$eq': '=',
28
+ '$contains': 'contains',
29
+ '$regex': 'regex'
30
+ }
31
+
32
+ /**
33
+ * Normalize an operator to its canonical Mongo-style representation (prefixed with $)
34
+ * @param {string} operator
35
+ * @returns {string}
36
+ */
37
+ export function normalizeOperator(operator) {
38
+ if (typeof operator !== 'string') {
39
+ return operator
40
+ }
41
+
42
+ if (operator.startsWith('$')) {
43
+ return operator
44
+ }
45
+
46
+ if (aliasToCanonical[operator] !== undefined) {
47
+ return aliasToCanonical[operator]
48
+ }
49
+
50
+ const lowerCase = operator.toLowerCase()
51
+ if (aliasToCanonical[lowerCase] !== undefined) {
52
+ return aliasToCanonical[lowerCase]
53
+ }
54
+
55
+ return operator
56
+ }
57
+
58
+ /**
59
+ * Convert an operator to its legacy (non-prefixed) alias when available
60
+ * @param {string} operator
61
+ * @returns {string}
62
+ */
63
+ export function operatorToLegacy(operator) {
64
+ if (typeof operator !== 'string') {
65
+ return operator
66
+ }
67
+
68
+ const canonical = normalizeOperator(operator)
69
+ if (canonicalToLegacy[canonical]) {
70
+ return canonicalToLegacy[canonical]
71
+ }
72
+
73
+ return operator
74
+ }
75
+
76
+ /**
77
+ * Normalize operator keys in a criteria object
78
+ * @param {Object} criteriaValue
79
+ * @param {Object} options
80
+ * @param {'canonical'|'legacy'} options.target - Preferred operator style
81
+ * @param {boolean} [options.preserveOriginal=false] - Whether to keep the original keys alongside normalized ones
82
+ * @returns {Object}
83
+ */
84
+ export function normalizeCriteriaOperators(criteriaValue, { target = 'canonical', preserveOriginal = false } = {}) {
85
+ if (!criteriaValue || typeof criteriaValue !== 'object' || Array.isArray(criteriaValue)) {
86
+ return criteriaValue
87
+ }
88
+
89
+ const normalized = preserveOriginal ? { ...criteriaValue } : {}
90
+
91
+ for (const [operator, value] of Object.entries(criteriaValue)) {
92
+ const canonical = normalizeOperator(operator)
93
+
94
+ if (target === 'canonical') {
95
+ normalized[canonical] = value
96
+ if (preserveOriginal && canonical !== operator) {
97
+ normalized[operator] = value
98
+ }
99
+ } else if (target === 'legacy') {
100
+ const legacy = operatorToLegacy(operator)
101
+ normalized[legacy] = value
102
+
103
+ if (preserveOriginal) {
104
+ if (legacy !== canonical) {
105
+ normalized[canonical] = value
106
+ }
107
+ if (operator !== legacy && operator !== canonical) {
108
+ normalized[operator] = value
109
+ }
110
+ }
111
+ }
112
+ }
113
+
114
+ return normalized
115
+ }
116
+
package/.babelrc DELETED
@@ -1,13 +0,0 @@
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 DELETED
@@ -1,2 +0,0 @@
1
- # Auto detect text files and perform LF normalization
2
- * text=auto
package/CHANGELOG.md DELETED
@@ -1,140 +0,0 @@
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/babel.config.json DELETED
@@ -1,5 +0,0 @@
1
- {
2
- "presets": ["@babel/preset-env"],
3
- "plugins": ["@babel/plugin-transform-async-generator-functions"]
4
- }
5
-