jexidb 2.1.2 → 2.1.4

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.
@@ -163,38 +163,10 @@ export default class SchemaManager {
163
163
  const obj = {}
164
164
  const idIndex = this.schema.indexOf('id')
165
165
 
166
- // CRITICAL FIX: Handle schema migration where 'id' was first field in old schema
167
- // but is not in current schema. Check if first element looks like an ID.
168
- // Only do this if:
169
- // 1. 'id' is not in current schema
170
- // 2. Array has significantly more elements than current schema (2+ extra elements)
171
- // This suggests the old schema had more fields, and 'id' was likely the first
172
- // 3. First element is a very short string (max 20 chars) that looks like a generated ID
173
- // (typically alphanumeric, often starting with letters like 'mit...' or similar patterns)
174
- // 4. First field in current schema is not 'id' (to avoid false positives)
175
- // 5. First element is not an array (to avoid false positives with array fields)
166
+ // DISABLED: Schema migration detection was causing field mapping corruption
167
+ // The logic was incorrectly assuming ID was in first position when it's appended at the end
168
+ // This caused fields to be shifted incorrectly during object-to-array-to-object conversion
176
169
  let arrayOffset = 0
177
- if (idIndex === -1 && arr.length >= this.schema.length + 2 && this.schema.length > 0) {
178
- // Only apply if array has at least 2 extra elements (suggests old schema had more fields)
179
- const firstElement = arr[0]
180
- const firstFieldName = this.schema[0]
181
-
182
- // Only apply shift if:
183
- // - First field is not 'id'
184
- // - First element is a very short string (max 20 chars) that looks like a generated ID
185
- // - First element is not an array (to avoid false positives)
186
- // - Array has at least 2 extra elements (strong indicator of schema migration)
187
- if (firstFieldName !== 'id' &&
188
- typeof firstElement === 'string' &&
189
- !Array.isArray(firstElement) &&
190
- firstElement.length > 0 &&
191
- firstElement.length <= 20 && // Very conservative: max 20 chars (typical ID length)
192
- /^[a-zA-Z0-9_-]+$/.test(firstElement)) {
193
- // First element is likely the ID from old schema
194
- obj.id = firstElement
195
- arrayOffset = 1
196
- }
197
- }
198
170
 
199
171
  // Map array values to object properties
200
172
  // Only include fields that are in the schema
@@ -1022,11 +1022,11 @@ export default class IndexManager {
1022
1022
  continue;
1023
1023
  }
1024
1024
 
1025
- if (typeof criteriaValue === 'object' && !Array.isArray(criteriaValue)) {
1025
+ if (typeof criteriaValue === 'object' && !Array.isArray(criteriaValue) && criteriaValue !== null) {
1026
1026
  const fieldIndex = data[field];
1027
-
1027
+
1028
1028
  // Handle $in operator for array queries
1029
- if (criteriaValue.$in !== undefined) {
1029
+ if (criteriaValue.$in !== undefined && criteriaValue.$in !== null) {
1030
1030
  const inValues = Array.isArray(criteriaValue.$in) ? criteriaValue.$in : [criteriaValue.$in];
1031
1031
 
1032
1032
  // PERFORMANCE: Cache term mapping field check once
@@ -1969,6 +1969,14 @@ export default class IndexManager {
1969
1969
  return
1970
1970
  }
1971
1971
 
1972
+ // Restore totalLines from saved data
1973
+ if (index.totalLines !== undefined) {
1974
+ this.totalLines = index.totalLines
1975
+ if (this.opts.debugMode) {
1976
+ console.log(`🔍 IndexManager.load: Restored totalLines=${this.totalLines}`)
1977
+ }
1978
+ }
1979
+
1972
1980
  this.index = processedIndex
1973
1981
  }
1974
1982
 
@@ -2008,7 +2016,10 @@ export default class IndexManager {
2008
2016
  * This resolves the issue where Sets appear as empty objects in JSON.stringify
2009
2017
  */
2010
2018
  toJSON() {
2011
- const serializable = { data: {} }
2019
+ const serializable = {
2020
+ data: {},
2021
+ totalLines: this.totalLines
2022
+ }
2012
2023
 
2013
2024
  // Check if this is a term mapping field for conversion
2014
2025
  const isTermMappingField = (field) => {
@@ -1215,7 +1215,7 @@ export class QueryManager {
1215
1215
  return false;
1216
1216
  }
1217
1217
 
1218
- if (typeof condition === 'object' && !Array.isArray(condition)) {
1218
+ if (typeof condition === 'object' && !Array.isArray(condition) && condition !== null) {
1219
1219
  const operators = Object.keys(condition).map(op => normalizeOperator(op));
1220
1220
  if (this.opts.debugMode) {
1221
1221
  console.log(`🔍 Field '${field}' has operators:`, operators)
@@ -1532,8 +1532,8 @@ export class QueryManager {
1532
1532
 
1533
1533
  if (termMappingFields.includes(field)) {
1534
1534
  // For term mapping fields, simple equality or $in queries work well
1535
- if (typeof condition === 'string' ||
1536
- (typeof condition === 'object' && condition.$in && Array.isArray(condition.$in))) {
1535
+ if (typeof condition === 'string' ||
1536
+ (typeof condition === 'object' && condition !== null && condition.$in && Array.isArray(condition.$in))) {
1537
1537
  return true;
1538
1538
  }
1539
1539
  }