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
@@ -0,0 +1,75 @@
1
+ #!/usr/bin/env node
2
+
3
+ import fs from 'fs';
4
+ import path from 'path';
5
+
6
+ function cleanTestFiles() {
7
+ const startTime = Date.now();
8
+ const currentDir = process.cwd();
9
+ const files = fs.readdirSync(currentDir);
10
+
11
+ const testFilePatterns = [
12
+ /^test-db-.*\.jdb$/,
13
+ /^test-db-.*\.offsets\.jdb$/,
14
+ /^test-db-.*\.idx\.jdb$/,
15
+ /^test-db-.*$/, // Files without extension
16
+ /^test-normalize.*\.jdb$/,
17
+ /^test-normalize.*\.offsets\.jdb$/,
18
+ /^test-normalize.*\.idx\.jdb$/,
19
+ /^test-normalize.*$/, // Files without extension
20
+ /^test-confusion.*\.jdb$/,
21
+ /^test-confusion.*\.offsets\.jdb$/,
22
+ /^test-confusion.*\.idx\.jdb$/,
23
+ /^test-confusion.*$/, // Files without extension
24
+ /^debug-.*\.jdb$/,
25
+ /^debug-.*\.offsets\.jdb$/,
26
+ /^debug-.*\.idx\.jdb$/,
27
+ /^debug-.*$/, // Files without extension
28
+ /^test-simple-.*$/, // test-simple files
29
+ /^test-count\.jdb$/, // test-count.jdb file
30
+ /^test-index-persistence-.*\.jdb$/, // index persistence test files
31
+ /^test-index-persistence-.*\.idx\.jdb$/, // index persistence idx files
32
+ /^test-indexed-mode-.*\.jdb$/, // indexed mode test files
33
+ /^test-indexed-mode-.*\.idx\.jdb$/, // indexed mode idx files
34
+ /^test-term-mapping-.*\.jdb$/, // term mapping test files
35
+ /^test-term-mapping-.*\.idx\.jdb$/, // term mapping idx files
36
+ /^test-.*\.jdb$/, // Any test file with .jdb extension
37
+ /^test-.*\.idx\.jdb$/ // Any test file with .idx.jdb extension
38
+ ];
39
+
40
+ let cleanedCount = 0;
41
+
42
+ files.forEach(file => {
43
+ const filePath = path.join(currentDir, file);
44
+ const stats = fs.statSync(filePath);
45
+
46
+ if (stats.isFile()) {
47
+ const shouldDelete = testFilePatterns.some(pattern => pattern.test(file));
48
+
49
+ if (shouldDelete) {
50
+ try {
51
+ fs.unlinkSync(filePath);
52
+ cleanedCount++;
53
+ } catch (error) {
54
+ console.warn(`Warning: Could not delete ${file}: ${error.message}`);
55
+ }
56
+ }
57
+ }
58
+ });
59
+
60
+ const endTime = Date.now();
61
+ const duration = endTime - startTime;
62
+
63
+ if (cleanedCount > 0) {
64
+ console.log(`✅ Cleaned ${cleanedCount} test files.`);
65
+ } else {
66
+ console.log('No test files found to clean.');
67
+ }
68
+ }
69
+
70
+ // Run cleanup if this script is executed directly
71
+ if (import.meta.url === `file://${process.argv[1]}` || process.argv[1]?.endsWith('clean-test-files.js')) {
72
+ cleanTestFiles();
73
+ }
74
+
75
+ export default cleanTestFiles;
@@ -0,0 +1,31 @@
1
+ #!/usr/bin/env node
2
+
3
+ import { existsSync } from 'fs';
4
+ import { execSync } from 'child_process';
5
+ import { fileURLToPath } from 'url';
6
+ import { dirname, join } from 'path';
7
+
8
+ const __filename = fileURLToPath(import.meta.url);
9
+ const __dirname = dirname(__filename);
10
+ const rootDir = join(__dirname, '..');
11
+ const distFile = join(rootDir, 'dist', 'Database.cjs');
12
+
13
+ // Check if the bundle already exists
14
+ if (existsSync(distFile)) {
15
+ console.log('✅ Bundle already exists, skipping build');
16
+ process.exit(0);
17
+ }
18
+
19
+ console.log('📦 Bundle not found, building...');
20
+
21
+ try {
22
+ execSync('npm run build', {
23
+ stdio: 'inherit',
24
+ cwd: rootDir
25
+ });
26
+ console.log('✅ Build completed successfully');
27
+ } catch (error) {
28
+ console.error('❌ Build failed:', error.message);
29
+ process.exit(1);
30
+ }
31
+
@@ -0,0 +1,80 @@
1
+ #!/usr/bin/env node
2
+
3
+ import { spawn } from 'child_process'
4
+ import { fileURLToPath } from 'url'
5
+ import { dirname, join } from 'path'
6
+
7
+ const __filename = fileURLToPath(import.meta.url)
8
+ const __dirname = dirname(__filename)
9
+
10
+ async function runTests() {
11
+ const startTime = Date.now()
12
+
13
+ console.log('🧪 Running JexiDB tests...')
14
+
15
+ // Run Jest tests
16
+ const jestProcess = spawn('npx', ['jest', ...process.argv.slice(2)], {
17
+ stdio: 'inherit',
18
+ shell: true
19
+ })
20
+
21
+ jestProcess.on('close', async (code) => {
22
+ if (code !== 0) {
23
+ console.error(`❌ Tests failed with exit code ${code}`)
24
+ process.exit(code)
25
+ }
26
+
27
+ // Run cleanup
28
+ const cleanupProcess = spawn('npm', ['run', 'clean:test-files'], {
29
+ stdio: 'inherit',
30
+ shell: true
31
+ })
32
+
33
+ cleanupProcess.on('close', (cleanupCode) => {
34
+ const endTime = Date.now()
35
+ const duration = Math.round((endTime - startTime) / 1000)
36
+
37
+ // Display completion time
38
+ const completionTime = new Date().toLocaleString('en-US', {
39
+ year: 'numeric',
40
+ month: '2-digit',
41
+ day: '2-digit',
42
+ hour: '2-digit',
43
+ minute: '2-digit',
44
+ second: '2-digit',
45
+ hour12: true
46
+ });
47
+
48
+ console.log(`✅ Tests completed at: ${completionTime}`);
49
+ console.log(`📦 Total execution time: ${duration}s`)
50
+
51
+ if (cleanupCode !== 0) {
52
+ console.warn(`⚠️ Cleanup completed with warnings (exit code: ${cleanupCode})`)
53
+ }
54
+
55
+ process.exit(0)
56
+ })
57
+ })
58
+
59
+ jestProcess.on('error', (error) => {
60
+ console.error('❌ Failed to start Jest:', error.message)
61
+ process.exit(1)
62
+ })
63
+ }
64
+
65
+ // Handle process termination
66
+ process.on('SIGINT', () => {
67
+ console.log('\n🛑 Test execution interrupted by user')
68
+ process.exit(0)
69
+ })
70
+
71
+ process.on('SIGTERM', () => {
72
+ console.log('\n🛑 Test execution terminated')
73
+ process.exit(0)
74
+ })
75
+
76
+ // Run the tests
77
+ runTests().catch(error => {
78
+ console.error('❌ Fatal error:', error.message)
79
+ process.exit(1)
80
+ })