sqlite-hub 1.2.0 → 1.4.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 (152) hide show
  1. package/README.md +106 -73
  2. package/bin/sqlite-hub.js +176 -2
  3. package/docs/API.md +122 -0
  4. package/docs/CLI.md +227 -0
  5. package/docs/DESIGN_GUIDELINES.md +45 -0
  6. package/docs/changelog.md +141 -0
  7. package/docs/shortkeys.md +27 -0
  8. package/docs/todo.md +16 -0
  9. package/examples/api/generate-types.js +52 -0
  10. package/frontend/assets/mockups/backups_1_1920.webp +0 -0
  11. package/frontend/assets/mockups/backups_2_create_backup_modal_1920.webp +0 -0
  12. package/frontend/assets/mockups/backups_3_edit_backup_modal_1920.webp +0 -0
  13. package/frontend/assets/mockups/backups_4_restore_backup_modal_1920.webp +0 -0
  14. package/frontend/assets/mockups/backups_5_delete_backup_modal_1920.webp +0 -0
  15. package/frontend/assets/mockups/charts_1_1920.webp +0 -0
  16. package/frontend/assets/mockups/charts_2_query_detail_1920.webp +0 -0
  17. package/frontend/assets/mockups/charts_3_create_query_chart_modal_1920.webp +0 -0
  18. package/frontend/assets/mockups/charts_4_edit_query_chart_modal_1920.webp +0 -0
  19. package/frontend/assets/mockups/charts_5_delete_query_chart_modal_1920.webp +0 -0
  20. package/frontend/assets/mockups/charts_6_copy_column_modal_1920.webp +0 -0
  21. package/frontend/assets/mockups/connections_1_1920.webp +0 -0
  22. package/frontend/assets/mockups/connections_2_create_connection_modal_1920.webp +0 -0
  23. package/frontend/assets/mockups/connections_3_open_connection_modal_1920.webp +0 -0
  24. package/frontend/assets/mockups/data_1_1920.webp +0 -0
  25. package/frontend/assets/mockups/data_2_roweditor_1920.webp +0 -0
  26. package/frontend/assets/mockups/data_3_data_export_modal_1920.webp +0 -0
  27. package/frontend/assets/mockups/documents_1_1920.webp +0 -0
  28. package/frontend/assets/mockups/documents_2_document_insert_table_modal_1920.webp +0 -0
  29. package/frontend/assets/mockups/documents_3_document_insert_note_modal_1920.webp +0 -0
  30. package/frontend/assets/mockups/media_tagging_queue_1_1920.webp +0 -0
  31. package/frontend/assets/mockups/media_tagging_setup_1_1920.webp +0 -0
  32. package/frontend/assets/mockups/media_tagging_setup_2_create_media_tagging_tag_table_modal_1920.webp +0 -0
  33. package/frontend/assets/mockups/media_tagging_setup_3_create_media_tagging_mapping_table_modal_1920.webp +0 -0
  34. package/frontend/assets/mockups/overview_1_1920.webp +0 -0
  35. package/frontend/assets/mockups/settings_1_1920.webp +0 -0
  36. package/frontend/assets/mockups/sql_editor_1_1920.webp +0 -0
  37. package/frontend/assets/mockups/sql_editor_2_query_detail_1920.webp +0 -0
  38. package/frontend/assets/mockups/sql_editor_3_query_export_modal_1920.webp +0 -0
  39. package/frontend/assets/mockups/structure_1_1920.webp +0 -0
  40. package/frontend/assets/mockups/structure_2_generate_types_modal_1920.webp +0 -0
  41. package/frontend/assets/mockups/structure_3_generate_types_modal_1920.webp +0 -0
  42. package/frontend/assets/mockups/table_designer_1_1920.webp +0 -0
  43. package/frontend/assets/mockups/table_designer_2_table_designer_constraints_modal_1920.webp +0 -0
  44. package/frontend/js/api.js +18 -0
  45. package/frontend/js/app.js +118 -8
  46. package/frontend/js/components/connectionCard.js +1 -1
  47. package/frontend/js/components/emptyState.js +4 -4
  48. package/frontend/js/components/generateTypesDropdown.js +33 -0
  49. package/frontend/js/components/metricCard.js +1 -1
  50. package/frontend/js/components/modal.js +211 -18
  51. package/frontend/js/components/pageHeader.js +1 -1
  52. package/frontend/js/components/queryHistoryDetail.js +3 -3
  53. package/frontend/js/components/queryHistoryHeader.js +1 -1
  54. package/frontend/js/components/queryHistoryPanel.js +1 -1
  55. package/frontend/js/components/rowEditorPanel.js +13 -3
  56. package/frontend/js/router.js +28 -6
  57. package/frontend/js/store.js +422 -8
  58. package/frontend/js/views/backups.js +529 -37
  59. package/frontend/js/views/charts.js +9 -9
  60. package/frontend/js/views/connections.js +2 -2
  61. package/frontend/js/views/data.js +1 -1
  62. package/frontend/js/views/documents.js +3 -3
  63. package/frontend/js/views/editor.js +6 -6
  64. package/frontend/js/views/mediaTagging.js +7 -5
  65. package/frontend/js/views/overview.js +3 -3
  66. package/frontend/js/views/settings.js +3 -3
  67. package/frontend/js/views/structure.js +6 -1
  68. package/frontend/styles/base.css +1 -40
  69. package/frontend/styles/components.css +109 -232
  70. package/frontend/styles/structure-graph.css +32 -68
  71. package/frontend/styles/tailwind.css +8 -4
  72. package/frontend/styles/tailwind.generated.css +1 -1
  73. package/frontend/styles/tokens.css +28 -21
  74. package/frontend/styles/views.css +94 -261
  75. package/package.json +18 -2
  76. package/server/routes/backups.js +18 -2
  77. package/server/routes/externalApi.js +36 -0
  78. package/server/routes/structure.js +22 -0
  79. package/server/services/databaseCommandService.js +14 -0
  80. package/server/services/sqlite/backupDiff.js +914 -0
  81. package/server/services/sqlite/backupService.js +77 -1
  82. package/server/services/sqlite/structureService.js +7 -0
  83. package/server/services/typeGenerationService.js +663 -0
  84. package/tailwind.config.cjs +0 -1
  85. package/.github/funding.yml +0 -2
  86. package/.github/workflows/ci.yml +0 -36
  87. package/database.sqlite +0 -0
  88. package/frontend/assets/mockups/charts_1_bars_1200.webp +0 -0
  89. package/frontend/assets/mockups/charts_2_pie_1200.webp +0 -0
  90. package/frontend/assets/mockups/charts_3_scatter_plot_1200.webp +0 -0
  91. package/frontend/assets/mockups/connections_1200.webp +0 -0
  92. package/frontend/assets/mockups/data_1_1200.webp +0 -0
  93. package/frontend/assets/mockups/data_2_row_editor_1200.webp +0 -0
  94. package/frontend/assets/mockups/documents_1200.webp +0 -0
  95. package/frontend/assets/mockups/media_tagging_1_setup_1200.webp +0 -0
  96. package/frontend/assets/mockups/media_tagging_2_tagging_queue_1200.webp +0 -0
  97. package/frontend/assets/mockups/media_tagging_3_media_viewer_1200.webp +0 -0
  98. package/frontend/assets/mockups/overview_1200.webp +0 -0
  99. package/frontend/assets/mockups/settings_1200.webp +0 -0
  100. package/frontend/assets/mockups/sql_editor_1_1200.webp +0 -0
  101. package/frontend/assets/mockups/sql_editor_2_query_details_1200.webp +0 -0
  102. package/frontend/assets/mockups/sql_editor_3_export_column_1200.webp +0 -0
  103. package/frontend/assets/mockups/sql_editor_4_export_column_as_markdown_1200.webp +0 -0
  104. package/frontend/assets/mockups/sql_editor_5_export_query_result_1200.webp +0 -0
  105. package/frontend/assets/mockups/structure_1_1200.webp +0 -0
  106. package/frontend/assets/mockups/structure_2_inspector_1200.webp +0 -0
  107. package/frontend/assets/mockups/table_designer_1_1200.webp +0 -0
  108. package/frontend/assets/mockups/table_designer_2_checks_1200.webp +0 -0
  109. package/tests/api-token-auth.test.js +0 -279
  110. package/tests/backup-manager.test.js +0 -140
  111. package/tests/backups-view.test.js +0 -70
  112. package/tests/charts-height-preset-storage.test.js +0 -60
  113. package/tests/charts-route-state.test.js +0 -144
  114. package/tests/check-constraint-options.test.js +0 -90
  115. package/tests/cli-args.test.js +0 -113
  116. package/tests/cli-service-delegation.test.js +0 -140
  117. package/tests/connection-removal.test.js +0 -52
  118. package/tests/connections-file-dialog-route.test.js +0 -89
  119. package/tests/copy-column-modal.test.js +0 -131
  120. package/tests/database-command-service.test.js +0 -174
  121. package/tests/database-documents.test.js +0 -85
  122. package/tests/documents-view.test.js +0 -132
  123. package/tests/dropdown-button.test.js +0 -101
  124. package/tests/email-preview.test.js +0 -89
  125. package/tests/export-blob.test.js +0 -99
  126. package/tests/export-filenames.test.js +0 -38
  127. package/tests/file-path-preview.test.js +0 -165
  128. package/tests/form-controls.test.js +0 -34
  129. package/tests/json-preview.test.js +0 -49
  130. package/tests/local-request-security.test.js +0 -85
  131. package/tests/markdown-documents.test.js +0 -103
  132. package/tests/native-file-dialog.test.js +0 -105
  133. package/tests/query-editor.test.js +0 -28
  134. package/tests/query-history-detail.test.js +0 -37
  135. package/tests/query-history-header.test.js +0 -30
  136. package/tests/query-results-truncation.test.js +0 -20
  137. package/tests/risky-sql.test.js +0 -30
  138. package/tests/row-editor-json.test.js +0 -82
  139. package/tests/row-editor-null-values.test.js +0 -184
  140. package/tests/row-editor-timestamp-preview.test.js +0 -192
  141. package/tests/security-paths.test.js +0 -84
  142. package/tests/settings-api-tokens-route.test.js +0 -97
  143. package/tests/settings-metadata.test.js +0 -114
  144. package/tests/settings-view.test.js +0 -108
  145. package/tests/sql-formatter.test.js +0 -173
  146. package/tests/sql-highlight.test.js +0 -38
  147. package/tests/sql-identifier-safety.test.js +0 -171
  148. package/tests/sql-result-limit.test.js +0 -66
  149. package/tests/structure-view.test.js +0 -60
  150. package/tests/table-designer-v2-unique-constraints.test.js +0 -78
  151. package/tests/table-scroll-state.test.js +0 -70
  152. package/tests/text-cell-stats.test.js +0 -38
@@ -19,6 +19,10 @@ const {
19
19
  validateSqlitePath,
20
20
  } = require("../../utils/fileValidation");
21
21
  const { quoteIdentifier } = require("../../utils/identifier");
22
+ const {
23
+ buildBackupDiff,
24
+ normalizeBackupDiffSampleLimit,
25
+ } = require("./backupDiff");
22
26
 
23
27
  const BACKUP_TYPES = new Set([
24
28
  "manual",
@@ -161,8 +165,9 @@ class BackupService {
161
165
  return this.decorateBackupFileState(backup);
162
166
  }
163
167
 
164
- updateBackupNotes(backupId, notes = "") {
168
+ updateBackupDetails(backupId, { name, notes } = {}) {
165
169
  const backup = this.appStateStore.updateBackupRecord(backupId, {
170
+ name,
166
171
  notes,
167
172
  });
168
173
 
@@ -393,6 +398,77 @@ class BackupService {
393
398
  };
394
399
  }
395
400
 
401
+ backupBelongsToConnection(backup, connection) {
402
+ if (!backup || !connection) {
403
+ return false;
404
+ }
405
+
406
+ if (backup.connectionId && backup.connectionId === connection.id) {
407
+ return true;
408
+ }
409
+
410
+ if (backup.sourcePath && connection.path) {
411
+ return path.resolve(backup.sourcePath) === path.resolve(connection.path);
412
+ }
413
+
414
+ return false;
415
+ }
416
+
417
+ diffBackupWithCurrent(backupId, { sampleLimit } = {}) {
418
+ const normalizedSampleLimit = normalizeBackupDiffSampleLimit(sampleLimit);
419
+ const activeConnection = this.connectionManager.getActiveConnection();
420
+
421
+ if (!activeConnection) {
422
+ throw new DatabaseRequiredError("No active SQLite database selected for backup comparison.");
423
+ }
424
+
425
+ if (this.activeOperations.size > 0) {
426
+ throw new ConflictError("A backup operation is already running.");
427
+ }
428
+
429
+ const backup = this.getBackup(backupId);
430
+
431
+ if (backup.status !== "verified") {
432
+ throw new ValidationError("Only verified backups can be compared.");
433
+ }
434
+
435
+ if (!backup.fileExists) {
436
+ throw new NotFoundError("Backup file is missing.");
437
+ }
438
+
439
+ if (!this.backupBelongsToConnection(backup, activeConnection)) {
440
+ throw new ValidationError("Backup does not belong to the active database.");
441
+ }
442
+
443
+ let backupDb = null;
444
+
445
+ try {
446
+ backupDb = new Database(backup.path, {
447
+ readonly: true,
448
+ fileMustExist: true,
449
+ });
450
+
451
+ const quickCheck = readQuickCheckResult(backupDb);
452
+
453
+ if (quickCheck !== "ok") {
454
+ throw new ValidationError(`Backup verification failed: ${quickCheck}`);
455
+ }
456
+
457
+ return buildBackupDiff({
458
+ backupDb,
459
+ currentDb: this.connectionManager.getActiveDatabase(),
460
+ backup,
461
+ currentConnection: activeConnection,
462
+ comparedAt: new Date(),
463
+ sampleLimit: normalizedSampleLimit,
464
+ });
465
+ } catch (error) {
466
+ throw mapSqliteError(error);
467
+ } finally {
468
+ backupDb?.close();
469
+ }
470
+ }
471
+
396
472
  deleteBackup(backupId) {
397
473
  const backup = this.getBackup(backupId);
398
474
 
@@ -1,11 +1,13 @@
1
1
  const { getRawStructureEntries, getTableDetail } = require("./introspection");
2
2
  const { quoteIdentifier } = require("../../utils/identifier");
3
3
  const { serializeRows } = require("../../utils/sqliteTypes");
4
+ const { TypeGenerationService } = require("../typeGenerationService");
4
5
 
5
6
  class StructureService {
6
7
  constructor({ connectionManager, appStateStore }) {
7
8
  this.connectionManager = connectionManager;
8
9
  this.appStateStore = appStateStore;
10
+ this.typeGenerationService = new TypeGenerationService();
9
11
  }
10
12
 
11
13
  getStructureOverview() {
@@ -79,6 +81,11 @@ class StructureService {
79
81
  notSafelyUpdatable: table.notSafelyUpdatable,
80
82
  };
81
83
  }
84
+
85
+ generateTableTypes(tableName, target, options = {}) {
86
+ const db = this.connectionManager.getActiveDatabase();
87
+ return this.typeGenerationService.generateTypesFromDatabase(db, tableName, target, options);
88
+ }
82
89
  }
83
90
 
84
91
  module.exports = {