@adecore/database 0.62.1 → 0.63.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 (231) hide show
  1. package/README.md +1 -1
  2. package/dist/DatabaseProvider.d.ts +1 -1
  3. package/dist/client/types.js +0 -1
  4. package/dist/client-context.d.ts +3 -2
  5. package/dist/connections/EngineIcon.d.ts +2 -1
  6. package/dist/connections/docker.js +0 -3
  7. package/dist/connections/use-docker-containers.d.ts +2 -1
  8. package/dist/console/DestructiveDialog.d.ts +2 -1
  9. package/dist/console/HistoryPanel.d.ts +2 -1
  10. package/dist/console/QueryConsole.js +0 -3
  11. package/dist/console/SchemaPicker.d.ts +2 -1
  12. package/dist/console/StatementResultView.d.ts +2 -1
  13. package/dist/console/TransactionControls.d.ts +2 -1
  14. package/dist/console/labels.js +0 -1
  15. package/dist/console/useConsoleHistory.d.ts +2 -1
  16. package/dist/ddl/alter-sqlite.js +0 -1
  17. package/dist/ddl/alter.js +0 -1
  18. package/dist/ddl/column.d.ts +2 -1
  19. package/dist/ddl/column.js +0 -1
  20. package/dist/ddl/create.d.ts +2 -1
  21. package/dist/ddl/create.js +0 -2
  22. package/dist/ddl/dialect.js +0 -1
  23. package/dist/ddl/diff.d.ts +4 -3
  24. package/dist/ddl/diff.js +0 -3
  25. package/dist/ddl/draft.js +0 -2
  26. package/dist/ddl/parse.js +0 -4
  27. package/dist/designer/ColumnsEditor.js +0 -1
  28. package/dist/designer/DesignerView.js +0 -1
  29. package/dist/designer/ForeignKeysEditor.d.ts +2 -1
  30. package/dist/designer/NamePicker.d.ts +2 -1
  31. package/dist/designer/SqlPreview.d.ts +2 -1
  32. package/dist/designer/SqlPreview.js +0 -2
  33. package/dist/designer/TableDesigner.js +0 -1
  34. package/dist/designer/edit.js +0 -1
  35. package/dist/designer/plan.js +0 -1
  36. package/dist/explorer/DatabaseExplorer.js +0 -1
  37. package/dist/explorer/RowMenu.d.ts +2 -1
  38. package/dist/explorer/TableDialog.d.ts +2 -1
  39. package/dist/explorer/tree.d.ts +11 -13
  40. package/dist/explorer/tree.js +3 -16
  41. package/dist/explorer/use-explorer-loads.d.ts +2 -1
  42. package/dist/explorer/use-explorer-loads.js +0 -2
  43. package/dist/explorer/use-stored-expansion.d.ts +1 -1
  44. package/dist/grid/CellEditor.d.ts +2 -1
  45. package/dist/grid/CellEditor.js +0 -1
  46. package/dist/grid/CopyAsMenu.d.ts +2 -1
  47. package/dist/grid/DataGrid.js +1 -1
  48. package/dist/grid/EnumPicker.d.ts +2 -1
  49. package/dist/grid/GridHeaderCell.js +0 -3
  50. package/dist/grid/GridRowView.d.ts +3 -2
  51. package/dist/grid/GridRowView.js +1 -0
  52. package/dist/grid/ValueDock.d.ts +2 -3
  53. package/dist/grid/ValueDock.js +2 -3
  54. package/dist/grid/aggregates.d.ts +2 -1
  55. package/dist/grid/cell-range.d.ts +2 -1
  56. package/dist/grid/cell-range.js +0 -2
  57. package/dist/grid/column-layout.d.ts +2 -1
  58. package/dist/grid/column-layout.js +0 -1
  59. package/dist/grid/column-selection.js +0 -1
  60. package/dist/grid/column-view.js +0 -2
  61. package/dist/grid/copy-formats.d.ts +2 -1
  62. package/dist/grid/display.d.ts +3 -2
  63. package/dist/grid/display.js +0 -5
  64. package/dist/grid/edit-value.js +0 -1
  65. package/dist/grid/enum-type.js +0 -1
  66. package/dist/grid/focused-value.js +0 -1
  67. package/dist/grid/layout.d.ts +2 -2
  68. package/dist/grid/layout.js +1 -9
  69. package/dist/grid/navigation.d.ts +2 -1
  70. package/dist/grid/navigation.js +0 -1
  71. package/dist/grid/row-selection.d.ts +3 -2
  72. package/dist/grid/sort.js +0 -2
  73. package/dist/grid/types.js +0 -1
  74. package/dist/grid/whole-cells.d.ts +2 -1
  75. package/dist/host/helper-path.d.ts +1 -0
  76. package/dist/host/helper-path.js +3 -1
  77. package/dist/host/host.js +0 -4
  78. package/dist/host/index.d.ts +1 -1
  79. package/dist/host/index.js +1 -1
  80. package/dist/host/spawn.js +0 -1
  81. package/dist/index.d.ts +1 -1
  82. package/dist/number-notation.d.ts +1 -0
  83. package/dist/number-notation.js +1 -0
  84. package/dist/sql-split.d.ts +3 -2
  85. package/dist/structure/StructureView.js +0 -1
  86. package/dist/table/CommandField.d.ts +2 -1
  87. package/dist/table/ImportDialog.d.ts +2 -1
  88. package/dist/table/ImportDialog.js +0 -3
  89. package/dist/{grid → table}/RecordView.d.ts +3 -2
  90. package/dist/{grid → table}/RecordView.js +5 -6
  91. package/dist/table/TableStatusBar.d.ts +2 -1
  92. package/dist/table/TableStatusBar.js +0 -1
  93. package/dist/table/TableToolbar.d.ts +2 -1
  94. package/dist/table/TableToolbar.js +0 -1
  95. package/dist/table/TableView.d.ts +0 -1
  96. package/dist/table/TableView.js +2 -3
  97. package/dist/table/command-field.d.ts +4 -5
  98. package/dist/table/command-field.js +2 -11
  99. package/dist/table/grid-rows.d.ts +3 -2
  100. package/dist/table/grid-rows.js +0 -1
  101. package/dist/table/import-mapping.js +0 -2
  102. package/dist/table/layout-store.d.ts +0 -1
  103. package/dist/table/layout-store.js +1 -1
  104. package/dist/table/paging.js +0 -1
  105. package/dist/table/pending.d.ts +1 -2
  106. package/dist/table/pending.js +1 -6
  107. package/dist/table/useStoredLayout.d.ts +2 -2
  108. package/dist/table/useStoredLayout.js +1 -1
  109. package/dist/table/useTableTransfer.d.ts +4 -3
  110. package/dist/table/useTableTransfer.js +0 -2
  111. package/dist/testing/fake.js +0 -3
  112. package/dist/value/ValueEditor.d.ts +2 -1
  113. package/dist/value/ValueEditor.js +0 -4
  114. package/dist/value/ValuePanel.js +0 -1
  115. package/dist/value/draft.d.ts +2 -1
  116. package/dist/value/draft.js +0 -1
  117. package/dist/value/hex.d.ts +2 -2
  118. package/dist/value/hex.js +1 -2
  119. package/dist/value/json.d.ts +2 -1
  120. package/dist/value/json.js +0 -1
  121. package/dist/value/views.d.ts +0 -1
  122. package/dist/value/views.js +1 -3
  123. package/dist/workbench/DatabaseWorkbench.js +0 -2
  124. package/dist/workbench/DesignerTab.d.ts +2 -1
  125. package/dist/workbench/TableTab.d.ts +2 -1
  126. package/dist/workbench/tabs.d.ts +3 -2
  127. package/dist/workbench/tabs.js +0 -3
  128. package/package.json +9 -10
  129. package/src/DatabaseProvider.tsx +1 -1
  130. package/src/client/types.ts +0 -2
  131. package/src/client-context.ts +2 -2
  132. package/src/connections/EngineIcon.tsx +1 -1
  133. package/src/connections/docker.ts +0 -3
  134. package/src/connections/use-docker-containers.ts +1 -1
  135. package/src/console/DestructiveDialog.tsx +1 -1
  136. package/src/console/HistoryPanel.tsx +1 -1
  137. package/src/console/QueryConsole.tsx +0 -3
  138. package/src/console/SchemaPicker.tsx +1 -1
  139. package/src/console/StatementResultView.tsx +1 -1
  140. package/src/console/TransactionControls.tsx +1 -1
  141. package/src/console/destructive.ts +0 -1
  142. package/src/console/labels.ts +0 -1
  143. package/src/console/useConsoleHistory.ts +1 -1
  144. package/src/ddl/alter-sqlite.ts +0 -1
  145. package/src/ddl/alter.ts +0 -1
  146. package/src/ddl/column.ts +1 -2
  147. package/src/ddl/create.ts +1 -3
  148. package/src/ddl/dialect.ts +0 -1
  149. package/src/ddl/diff.ts +3 -6
  150. package/src/ddl/draft.ts +0 -2
  151. package/src/ddl/parse.ts +0 -4
  152. package/src/designer/ColumnsEditor.tsx +0 -2
  153. package/src/designer/DesignerView.tsx +0 -5
  154. package/src/designer/ForeignKeysEditor.tsx +1 -1
  155. package/src/designer/NamePicker.tsx +1 -3
  156. package/src/designer/SqlPreview.tsx +1 -3
  157. package/src/designer/TableDesigner.tsx +0 -2
  158. package/src/designer/edit.ts +0 -2
  159. package/src/designer/editor-props.ts +0 -1
  160. package/src/designer/plan.ts +0 -2
  161. package/src/explorer/DatabaseExplorer.tsx +0 -1
  162. package/src/explorer/RowMenu.tsx +1 -1
  163. package/src/explorer/TableDialog.tsx +1 -1
  164. package/src/explorer/expansion.ts +0 -1
  165. package/src/explorer/table-statements.ts +0 -1
  166. package/src/explorer/tree.ts +13 -31
  167. package/src/explorer/use-explorer-loads.ts +1 -4
  168. package/src/explorer/use-stored-expansion.ts +1 -2
  169. package/src/grid/CellEditor.tsx +1 -2
  170. package/src/grid/CopyAsMenu.tsx +1 -1
  171. package/src/grid/DataGrid.tsx +2 -4
  172. package/src/grid/EnumPicker.tsx +1 -2
  173. package/src/grid/GridHeaderCell.tsx +0 -3
  174. package/src/grid/GridRowView.tsx +3 -4
  175. package/src/grid/ValueDock.tsx +3 -6
  176. package/src/grid/aggregates.ts +1 -2
  177. package/src/grid/cell-range.ts +1 -3
  178. package/src/grid/column-layout.ts +1 -2
  179. package/src/grid/column-selection.ts +0 -1
  180. package/src/grid/column-view.ts +0 -2
  181. package/src/grid/copy-formats.ts +1 -2
  182. package/src/grid/display.ts +2 -9
  183. package/src/grid/edit-value.ts +0 -1
  184. package/src/grid/enum-type.ts +0 -1
  185. package/src/grid/focused-value.ts +0 -1
  186. package/src/grid/layout.ts +2 -12
  187. package/src/grid/navigation.ts +1 -3
  188. package/src/grid/row-selection.ts +2 -2
  189. package/src/grid/sort.ts +0 -2
  190. package/src/grid/types.ts +0 -5
  191. package/src/grid/whole-cells.ts +1 -2
  192. package/src/host/helper-path.ts +4 -1
  193. package/src/host/host.ts +0 -6
  194. package/src/host/index.ts +1 -1
  195. package/src/host/spawn.ts +0 -2
  196. package/src/host/types.ts +0 -3
  197. package/src/index.ts +1 -1
  198. package/src/number-notation.ts +2 -0
  199. package/src/protocol/connection.ts +0 -2
  200. package/src/protocol/errors.ts +0 -3
  201. package/src/protocol/messages.ts +0 -1
  202. package/src/protocol/schema.ts +0 -2
  203. package/src/protocol/values.ts +0 -2
  204. package/src/sql-split.ts +2 -2
  205. package/src/structure/StructureView.tsx +0 -1
  206. package/src/table/CommandField.tsx +1 -1
  207. package/src/table/ImportDialog.tsx +1 -7
  208. package/src/{grid → table}/RecordView.tsx +9 -12
  209. package/src/table/TableStatusBar.tsx +1 -3
  210. package/src/table/TableToolbar.tsx +1 -6
  211. package/src/table/TableView.tsx +2 -4
  212. package/src/table/command-field.ts +5 -14
  213. package/src/table/grid-rows.ts +2 -3
  214. package/src/table/import-mapping.ts +0 -2
  215. package/src/table/layout-store.ts +1 -2
  216. package/src/table/paging.ts +0 -1
  217. package/src/table/pending.ts +2 -9
  218. package/src/table/references.ts +0 -1
  219. package/src/table/useStoredLayout.ts +2 -4
  220. package/src/table/useTableTransfer.ts +3 -8
  221. package/src/testing/fake.ts +0 -5
  222. package/src/value/ValueEditor.tsx +1 -5
  223. package/src/value/ValuePanel.tsx +0 -1
  224. package/src/value/draft.ts +1 -2
  225. package/src/value/hex.ts +2 -3
  226. package/src/value/json.ts +1 -2
  227. package/src/value/views.ts +1 -4
  228. package/src/workbench/DatabaseWorkbench.tsx +0 -2
  229. package/src/workbench/DesignerTab.tsx +1 -2
  230. package/src/workbench/TableTab.tsx +1 -1
  231. package/src/workbench/tabs.ts +2 -7
@@ -1,14 +1,13 @@
1
1
  import type { CellPosition } from './navigation.ts';
2
2
 
3
3
  /* A block of cells, both ends included. Columns are positions as drawn, so a block stays rectangular on screen. */
4
- export interface CellRect {
4
+ interface CellRect {
5
5
  readonly top: number;
6
6
  readonly bottom: number;
7
7
  readonly left: number;
8
8
  readonly right: number;
9
9
  }
10
10
 
11
- /* The block between two cells, whichever corner each one is. */
12
11
  export const rectBetween = (from: CellPosition, to: CellPosition): CellRect => ({
13
12
  top: Math.min(from.row, to.row),
14
13
  bottom: Math.max(from.row, to.row),
@@ -19,7 +18,6 @@ export const rectBetween = (from: CellPosition, to: CellPosition): CellRect => (
19
18
  export const rectContains = (rect: CellRect | null, row: number, column: number): boolean =>
20
19
  rect !== null && row >= rect.top && row <= rect.bottom && column >= rect.left && column <= rect.right;
21
20
 
22
- /* Every cell of a grid, or `null` when it has none. */
23
21
  export const fullRect = (rows: number, columns: number): CellRect | null =>
24
22
  rows === 0 || columns === 0 ? null : { top: 0, bottom: rows - 1, left: 0, right: columns - 1 };
25
23
 
@@ -11,7 +11,7 @@ export interface GridLayout {
11
11
  readonly pinned: readonly string[];
12
12
  }
13
13
 
14
- export interface ColumnState {
14
+ interface ColumnState {
15
15
  readonly resized: Readonly<Record<number, number>>;
16
16
  readonly view: ColumnView;
17
17
  }
@@ -47,7 +47,6 @@ export const restoreLayout = (columns: readonly { readonly name: string }[], lay
47
47
  return { resized, view: { hidden: hidden.size >= columns.length ? new Set() : hidden, pinned } };
48
48
  };
49
49
 
50
- /* The layout of a grid's state, with the columns by name. */
51
50
  export const captureLayout = (columns: readonly { readonly name: string }[], state: ColumnState): GridLayout => {
52
51
  const widths: Record<string, number> = {};
53
52
 
@@ -47,5 +47,4 @@ export const selectColumn = (current: ColumnSelection, order: readonly number[],
47
47
  return { columns: new Set([index]), anchor: index };
48
48
  };
49
49
 
50
- /* The picked columns that are drawn, in the order they are drawn. */
51
50
  export const shownSelection = (current: ColumnSelection, order: readonly number[]): number[] => order.filter((index) => current.columns.has(index));
@@ -9,7 +9,6 @@ export const NO_COLUMN_VIEW: ColumnView = { hidden: new Set(), pinned: [] };
9
9
 
10
10
  const shownPins = (count: number, view: ColumnView): number[] => view.pinned.filter((index) => index < count && !view.hidden.has(index));
11
11
 
12
- /* The columns to draw as indexes: the pinned ones first in pin order, then the rest as they come, hidden ones left out. */
13
12
  export const displayOrder = (count: number, view: ColumnView): number[] => {
14
13
  const pinned = shownPins(count, view);
15
14
  const rest: number[] = [];
@@ -35,5 +34,4 @@ export const togglePin = (view: ColumnView, index: number): ColumnView => ({
35
34
  pinned: view.pinned.includes(index) ? view.pinned.filter((pinned) => pinned !== index) : [...view.pinned, index]
36
35
  });
37
36
 
38
- /* How many of the first columns of `displayOrder` are pinned. */
39
37
  export const pinnedCount = (count: number, view: ColumnView): number => shownPins(count, view).length;
@@ -6,7 +6,7 @@ export type CopyFormat = 'tsv' | 'csv' | 'json' | 'sql';
6
6
 
7
7
  export const COPY_FORMATS: readonly CopyFormat[] = ['tsv', 'csv', 'json', 'sql'];
8
8
 
9
- export interface CopyColumn {
9
+ interface CopyColumn {
10
10
  readonly name: string;
11
11
  readonly kind: ValueKind;
12
12
  }
@@ -15,7 +15,6 @@ export interface CopyInput {
15
15
  readonly columns: readonly CopyColumn[];
16
16
  /* One array per row, one cell per column. A preview copies as the preview. */
17
17
  readonly rows: readonly (readonly Shown[])[];
18
- /* Needed for `sql`. */
19
18
  readonly target?: SqlTarget;
20
19
  }
21
20
 
@@ -1,4 +1,5 @@
1
1
  import { formatBytes, formatNumeral } from '@adecore/ui/format';
2
+ import type { NumberNotation } from '../number-notation.ts';
2
3
  import type { Cell, EditValue, ValueKind } from '../protocol/index.ts';
3
4
  import { isNumericKind } from '../sql.ts';
4
5
  import type { GridColumn } from './types.ts';
@@ -6,7 +7,7 @@ import type { GridColumn } from './types.ts';
6
7
  /* What a cell shows: a cell of a result, or the column's default for a value an edit set to `DEFAULT`. */
7
8
  export type Shown = Cell | { readonly kind: 'default' };
8
9
 
9
- export type CellTone = 'value' | 'null' | 'default';
10
+ type CellTone = 'value' | 'null' | 'default';
10
11
 
11
12
  export interface CellView {
12
13
  readonly text: string;
@@ -16,20 +17,15 @@ export interface CellView {
16
17
  readonly suffix?: string;
17
18
  }
18
19
 
19
- /* How a numeric cell is drawn: as the server wrote it, or in the notation of the person's region. */
20
- export type NumberNotation = 'database' | 'region';
21
-
22
20
  /* A cell never draws more than this, however long the text, so the DOM stays small. The cell is one line anyway. */
23
21
  export const DISPLAY_LIMIT = 200;
24
22
 
25
- /* How many bytes of a binary value the cell spells out. */
26
23
  export const BINARY_PREVIEW_BYTES = 8;
27
24
 
28
25
  const ELLIPSIS = '…';
29
26
 
30
27
  const isObject = (cell: Shown): cell is Exclude<Shown, null | boolean | number | string> => cell !== null && typeof cell === 'object';
31
28
 
32
- /* Whether a cell is only the start of its value, so editing it needs the whole value first. */
33
29
  export const isPreview = (cell: Shown): boolean => {
34
30
  if (!isObject(cell)) {
35
31
  return false;
@@ -42,7 +38,6 @@ export const isPreview = (cell: Shown): boolean => {
42
38
  return cell.kind === 'binary' && cell.hex.length < cell.length * 2;
43
39
  };
44
40
 
45
- /* A numeral in the notation asked for; text that is no numeral stays as it is. */
46
41
  export const numeralText = (numeral: string | number, notation: NumberNotation): string => {
47
42
  if (notation === 'database') {
48
43
  return String(numeral);
@@ -102,7 +97,6 @@ export const cellView = (cell: Shown, kind: ValueKind, notation: NumberNotation
102
97
  }
103
98
  };
104
99
 
105
- /* The text a copy puts on the clipboard: the value as the cell has it, a preview as far as it goes. */
106
100
  export const copyTextOf = (cell: Shown): string => {
107
101
  if (cell === null) {
108
102
  return 'NULL';
@@ -122,7 +116,6 @@ export const copyTextOf = (cell: Shown): string => {
122
116
  }
123
117
  };
124
118
 
125
- /* An edit as a cell, so the grid draws a pending value the way it draws a loaded one. */
126
119
  export const shownOfEdit = (value: EditValue): Shown => {
127
120
  if (value !== null && typeof value === 'object' && value.kind === 'binary') {
128
121
  return { kind: 'binary', hex: value.hex, length: value.hex.length / 2 };
@@ -6,7 +6,6 @@ const EMPTY_IS_NULL: ReadonlySet<ValueKind> = new Set(['integer', 'decimal', 'fl
6
6
  const INTEGER = /^[+-]?\d+$/;
7
7
  const HEX = /^0x([0-9a-f]*)$/i;
8
8
 
9
- /* The text an editor starts with for a value that is whole (a preview has to be loaded first). */
10
9
  export const draftOf = (value: Cell | Value | { readonly kind: 'default' }): string => {
11
10
  if (value === null) {
12
11
  return '';
@@ -70,7 +70,6 @@ export const parseEnumType = (type: string): EnumType | null => {
70
70
  const tidy = (kind: string, values: string[]): EnumType | null =>
71
71
  values.length === 0 ? null : { kind: kind.toLowerCase() === 'set' ? 'set' : 'enum', values };
72
72
 
73
- /* The members a SET value holds: the text split on commas, empty for the empty set. */
74
73
  export const membersOf = (value: string): string[] => (value === '' ? [] : value.split(','));
75
74
 
76
75
  /* A SET value in the order of the column's values, which is the order the server writes it in. */
@@ -5,7 +5,6 @@ import type { Shown } from './display.ts';
5
5
  export const wholeValueOf = (cell: Shown): Value | undefined =>
6
6
  cell !== null && typeof cell === 'object' && cell.kind === 'default' ? undefined : valueOfCell(cell as Cell);
7
7
 
8
- /* What a cell holds as far as it goes: the whole value, or the preview of a long text or a binary value. */
9
8
  export const previewValueOf = (cell: Shown): Value => {
10
9
  const whole = wholeValueOf(cell);
11
10
 
@@ -7,14 +7,12 @@ export const MAX_COLUMN_WIDTH = 320;
7
7
  /* How far a drag may widen a column; the estimate stops at `MAX_COLUMN_WIDTH`, a person may go further. */
8
8
  export const MAX_RESIZED_WIDTH = 1200;
9
9
 
10
- /* How wide fitting a column to its content may make it. */
11
10
  export const MAX_FIT_WIDTH = 640;
12
11
 
13
12
  /* The window of drawn rows moves in blocks of this many rows, so a scroll within a block draws nothing. */
14
13
  export const ROW_BLOCK = 16;
15
14
 
16
- /* Two presses on a resize handle this close are a double click. */
17
- export const DOUBLE_CLICK_MS = 350;
15
+ const DOUBLE_CLICK_MS = 350;
18
16
 
19
17
  /* What a viewport is taken to be until it is measured, so a first paint already holds rows. */
20
18
  export const FALLBACK_VIEWPORT_HEIGHT = 600;
@@ -29,14 +27,11 @@ const SAMPLE_ROWS = 50;
29
27
  /* The arrow and the position number a sorted header carries after its name. */
30
28
  const SORT_ROOM = 24;
31
29
 
32
- export interface VisibleRange {
33
- /* Index of the first row to draw. */
30
+ interface VisibleRange {
34
31
  readonly start: number;
35
- /* One past the last row to draw. */
36
32
  readonly end: number;
37
33
  }
38
34
 
39
- /* The block the top of the viewport is in, for a viewport `top` pixels into the rows. */
40
35
  export const scrollBlock = (top: number): number => Math.floor(Math.max(0, top) / (ROW_BLOCK * ROW_HEIGHT));
41
36
 
42
37
  /*
@@ -73,7 +68,6 @@ export const scrollToReveal = (start: number, size: number, scroll: number, view
73
68
  return scroll;
74
69
  };
75
70
 
76
- /* The left edge of every column, counted from the first one. */
77
71
  export const columnOffsets = (widths: readonly number[]): number[] => {
78
72
  let offset = 0;
79
73
 
@@ -85,21 +79,17 @@ export const columnOffsets = (widths: readonly number[]): number[] => {
85
79
  });
86
80
  };
87
81
 
88
- /* Wide enough for the largest row number, never narrower than `GUTTER_MIN_WIDTH`. */
89
82
  export const gutterWidth = (rowCount: number): number => Math.max(GUTTER_MIN_WIDTH, String(Math.max(rowCount, 1)).length * CHARACTER_WIDTH + CELL_PADDING);
90
83
 
91
84
  export const clampColumnWidth = (width: number): number => Math.max(MIN_COLUMN_WIDTH, Math.min(Math.ceil(width), MAX_COLUMN_WIDTH));
92
85
 
93
86
  const bodyWidth = (texts: readonly string[]): number => texts.reduce((longest, text) => Math.max(longest, text.length), 0) * CHARACTER_WIDTH;
94
87
 
95
- /* `keyed` makes room for the key icon in front of the name. */
96
88
  const headerWidth = (header: string, keyed: boolean): number => header.length * CHARACTER_WIDTH + (keyed ? KEY_ICON_ROOM : 0) + SORT_ROOM;
97
89
 
98
- /* From the longest text among the header and the first rows. */
99
90
  export const estimateColumnWidth = (header: string, samples: readonly string[], keyed: boolean): number =>
100
91
  clampColumnWidth(Math.max(bodyWidth(samples.slice(0, SAMPLE_ROWS)), headerWidth(header, keyed)) + CELL_PADDING);
101
92
 
102
- /* Wide enough for the header and every text of the column, up to `MAX_FIT_WIDTH`. */
103
93
  export const fitColumnWidth = (header: string, texts: readonly string[], keyed: boolean): number =>
104
94
  Math.max(MIN_COLUMN_WIDTH, Math.min(Math.ceil(Math.max(bodyWidth(texts), headerWidth(header, keyed)) + CELL_PADDING), MAX_FIT_WIDTH));
105
95
 
@@ -3,10 +3,9 @@ export interface CellPosition {
3
3
  readonly column: number;
4
4
  }
5
5
 
6
- export interface GridSize {
6
+ interface GridSize {
7
7
  readonly rows: number;
8
8
  readonly columns: number;
9
- /* How many rows a PageUp or PageDown moves. */
10
9
  readonly page: number;
11
10
  }
12
11
 
@@ -17,7 +16,6 @@ export interface NavigationKey {
17
16
  readonly mod: boolean;
18
17
  }
19
18
 
20
- /* Keys that, with no cell focused yet, only put the focus on the first one. */
21
19
  const ENTERING_KEYS: ReadonlySet<string> = new Set(['ArrowUp', 'ArrowDown', 'ArrowLeft', 'ArrowRight', 'PageUp', 'PageDown', 'Tab']);
22
20
 
23
21
  const clamp = (value: number, max: number): number => Math.max(0, Math.min(value, max - 1));
@@ -1,10 +1,10 @@
1
- export interface RowSelection {
1
+ interface RowSelection {
2
2
  readonly selected: ReadonlySet<string>;
3
3
  /* The row a Shift-click extends from. */
4
4
  readonly anchor: number;
5
5
  }
6
6
 
7
- export interface RowClick {
7
+ interface RowClick {
8
8
  readonly shiftKey: boolean;
9
9
  readonly mod: boolean;
10
10
  }
package/src/grid/sort.ts CHANGED
@@ -2,10 +2,8 @@ import type { ColumnSort, SortDirection } from '../sql.ts';
2
2
 
3
3
  export type GridSort = ColumnSort;
4
4
 
5
- /* The column as the only sort, in a direction a menu picked. */
6
5
  export const sortOnly = (column: string, direction: SortDirection): GridSort[] => [{ column, direction }];
7
6
 
8
- /* The sort of a column and its place among the sorts counted from one, or `null` when it is not sorted. */
9
7
  export const sortStateOf = (sorts: readonly GridSort[], column: string): { direction: SortDirection; position: number } | null => {
10
8
  const index = sorts.findIndex((sort) => sort.column === column);
11
9
 
package/src/grid/types.ts CHANGED
@@ -1,16 +1,13 @@
1
1
  import type { ColumnInfo, ResultColumn } from '../protocol/index.ts';
2
2
  import type { Shown } from './display.ts';
3
3
 
4
- /* A column of a result, with what the grid draws from its table when it comes from one. */
5
4
  export interface GridColumn extends ResultColumn {
6
5
  readonly primaryKey?: boolean;
7
- /* A column of a foreign key of its table. */
8
6
  readonly foreignKey?: boolean;
9
7
  /* `false` makes Set NULL unavailable; unknown (an expression) leaves it open. */
10
8
  readonly nullable?: boolean;
11
9
  /* A column no cell of which can be edited, such as a generated one. */
12
10
  readonly readOnly?: boolean;
13
- /* The default as an SQL expression, for the hint on the header. */
14
11
  readonly defaultValue?: string | null;
15
12
  /* A cloned row leaves this column to the server. */
16
13
  readonly autoIncrement?: boolean;
@@ -26,13 +23,11 @@ export interface GridRow {
26
23
  /* One per column, in the order of the columns. A `null` draws as a faint NULL, so an empty text is `''`. */
27
24
  readonly cells: readonly Shown[];
28
25
  readonly state?: GridRowState;
29
- /* Indexes of the cells with a pending edit. */
30
26
  readonly edited?: ReadonlySet<number>;
31
27
  /* A row that cannot be edited even though the grid can, such as one whose key is only a preview. */
32
28
  readonly locked?: boolean;
33
29
  }
34
30
 
35
- /* Builds the column of a table from the result column, the structure's column of the same name and the columns of its keys. */
36
31
  export const gridColumnOf = (
37
32
  column: ResultColumn,
38
33
  info: ColumnInfo | undefined,
@@ -7,9 +7,8 @@ export const WHOLE_COPY_LIMIT = 16 * 1024 * 1024;
7
7
  /* The helper runs the requests of a session one after another, so more at once would only wait in its queue. */
8
8
  const PARALLEL_LOADS = 4;
9
9
 
10
- export interface WholeCells {
10
+ interface WholeCells {
11
11
  readonly rows: readonly (readonly Shown[])[];
12
- /* The cells that are still previews. */
13
12
  readonly previews: number;
14
13
  /* Whether the previews stayed because the whole values are larger than `WHOLE_COPY_LIMIT`, rather than because they could not be loaded. */
15
14
  readonly tooLarge: boolean;
@@ -15,6 +15,9 @@ export interface HelperPathOptions {
15
15
  readonly exists?: (path: string) => boolean;
16
16
  }
17
17
 
18
+ /* The file name of the helper binary, which an app that packages it beside its own binary has to use as well. */
19
+ export const helperFileName = (platform: string = process.platform): string => (platform === 'win32' ? 'adecore-database.exe' : 'adecore-database');
20
+
18
21
  /*
19
22
  * Finds the helper for this machine, or null when there is none. In order: the path in `ADECORE_DATABASE_HELPER`;
20
23
  * the prebuilt binary npm installed in the `@adecore/database-<platform>-<arch>` package, absent on an
@@ -39,7 +42,7 @@ export const helperPath = ({
39
42
  return override;
40
43
  }
41
44
 
42
- const binary = platform === 'win32' ? 'adecore-database.exe' : 'adecore-database';
45
+ const binary = helperFileName(platform);
43
46
 
44
47
  return packagedHelper(platform, arch, binary, resolve, exists) ?? checkoutHelper(binary, exists);
45
48
  };
package/src/host/host.ts CHANGED
@@ -16,7 +16,6 @@ class Failure extends Error {
16
16
  }
17
17
  }
18
18
 
19
- /* One helper process, from its start to its end. */
20
19
  interface Run {
21
20
  readonly process: HelperProcess;
22
21
  readonly ready: Promise<void>;
@@ -27,7 +26,6 @@ interface Run {
27
26
  state: 'starting' | 'ready' | 'dead';
28
27
  }
29
28
 
30
- /* A request of an owner as the host tracks it, from the moment it arrives until it is answered. */
31
29
  interface Entry {
32
30
  /* The id toward the helper; `null` while the request waits for the app's check or for the helper. */
33
31
  helperId: string | null;
@@ -40,7 +38,6 @@ const failure = (id: string, code: DatabaseErrorCode, message: string): Database
40
38
 
41
39
  const messageOf = (error: unknown): string => (error instanceof Error ? error.message : String(error));
42
40
 
43
- /* `undefined` for a line that is not JSON. */
44
41
  const parseLine = (line: string): unknown => {
45
42
  try {
46
43
  return JSON.parse(line);
@@ -64,7 +61,6 @@ const settleWithin = async (promises: readonly Promise<unknown>[]): Promise<void
64
61
  }
65
62
  };
66
63
 
67
- /* Reads what the helper wrote for a request; anything that is not a response of the protocol becomes an `internal` error. */
68
64
  const normalize = (id: string, message: Record<string, unknown>): DatabaseResponse => {
69
65
  if (message.ok === true) {
70
66
  return { id, ok: true, result: message.result ?? null } as DatabaseResponse;
@@ -210,7 +206,6 @@ export const createDatabaseHost = (options: DatabaseHostOptions): DatabaseHost =
210
206
  return run;
211
207
  };
212
208
 
213
- /* Sends a message under a helper id of the host's own; the promise never rejects. */
214
209
  const dispatch = (run: Run, method: string, params: unknown): { readonly id: string; readonly response: Promise<DatabaseResponse> } => {
215
210
  const id = `h${++counter}`;
216
211
 
@@ -323,7 +318,6 @@ export const createDatabaseHost = (options: DatabaseHostOptions): DatabaseHost =
323
318
  return { ...sent, id: request.id } as DatabaseResponse;
324
319
  };
325
320
 
326
- /* Remembers what a response changed about the sessions, then hands it back under the caller's id. */
327
321
  const settle = (request: DatabaseRequest, owner: string, entry: Entry, run: Run, response: DatabaseResponse): DatabaseResponse => {
328
322
  if (request.method === 'close') {
329
323
  sessions.delete(request.params.session);
package/src/host/index.ts CHANGED
@@ -1,4 +1,4 @@
1
- export { helperPath, type HelperPathOptions } from './helper-path.ts';
1
+ export { helperFileName, helperPath, type HelperPathOptions } from './helper-path.ts';
2
2
  export { createDatabaseHost } from './host.ts';
3
3
  export { spawnHelper, type SpawnHelperOptions } from './spawn.ts';
4
4
  export type { DatabaseHost, DatabaseHostOptions, HelperProcess } from './types.ts';
package/src/host/spawn.ts CHANGED
@@ -5,7 +5,6 @@ export interface SpawnHelperOptions {
5
5
  readonly args?: readonly string[];
6
6
  /* Added over the environment of this process. */
7
7
  readonly env?: Readonly<Record<string, string>>;
8
- /* Receives each line the helper writes to stderr. */
9
8
  readonly onLog?: (line: string) => void;
10
9
  }
11
10
 
@@ -50,7 +49,6 @@ const createLineSplitter = (onLine: (line: string) => void) => {
50
49
  };
51
50
  };
52
51
 
53
- /* Runs the helper binary at `path`, speaking one JSON message per line over stdin and stdout. */
54
52
  export const spawnHelper = (path: string, options: SpawnHelperOptions = {}): HelperProcess => {
55
53
  const lineListeners: ((line: string) => void)[] = [];
56
54
  const exitListeners: ((code: number | null, signal: string | null) => void)[] = [];
package/src/host/types.ts CHANGED
@@ -2,7 +2,6 @@ import type { ConnectionConfig, DatabaseResponse } from '../protocol/index.ts';
2
2
 
3
3
  /* A running helper as the host sees it: lines in, lines out. `spawnHelper` makes one from a path. */
4
4
  export interface HelperProcess {
5
- /* One message, without its line break. */
6
5
  write(line: string): void;
7
6
  onLine(listener: (line: string) => void): void;
8
7
  onExit(listener: (code: number | null, signal?: string | null) => void): void;
@@ -39,8 +38,6 @@ export interface DatabaseHostOptions {
39
38
  export interface DatabaseHost {
40
39
  /* Takes what came over the channel as it is, and checks its shape before anything reaches the helper. */
41
40
  handle(request: unknown, owner: string): Promise<DatabaseResponse>;
42
- /* Closes every session of an owner that went away. */
43
41
  release(owner: string): Promise<void>;
44
- /* Closes every session and stops the helper. */
45
42
  dispose(): Promise<void>;
46
43
  }
package/src/index.ts CHANGED
@@ -35,7 +35,7 @@ export { DatabaseProvider, type DatabaseProviderProps } from './DatabaseProvider
35
35
  export { useDatabaseClient } from './client-context.ts';
36
36
  export { DataGrid, type DataGridProps } from './grid/DataGrid.tsx';
37
37
  export type { GridLayout } from './grid/column-layout.ts';
38
- export type { NumberNotation } from './grid/display.ts';
38
+ export type { NumberNotation } from './number-notation.ts';
39
39
  export type { GridSort } from './grid/sort.ts';
40
40
  export type { FocusedCell, GridColumn, GridMenuContext, GridRow, GridRowState } from './grid/types.ts';
41
41
  export { QueryConsole, type QueryConsoleProps } from './console/QueryConsole.tsx';
@@ -0,0 +1,2 @@
1
+ /* How a numeric cell is drawn: as the server wrote it, or in the notation of the person's region. */
2
+ export type NumberNotation = 'database' | 'region';
@@ -30,11 +30,9 @@ export interface SshTunnel {
30
30
  */
31
31
  export interface DockerTunnel {
32
32
  readonly kind: 'docker';
33
- /* The name or id of the container. */
34
33
  readonly container: string;
35
34
  /* The port inside the container; the engine's default when left out. */
36
35
  readonly port?: number;
37
- /* A Docker context other than the current one. */
38
36
  readonly context?: string;
39
37
  }
40
38
 
@@ -3,7 +3,6 @@
3
3
  * `helper-unavailable`, and `forbidden` when the app's check turns a connection, a file or a discovery down.
4
4
  */
5
5
  export type DatabaseErrorCode =
6
- /* The request does not have the shape of the protocol. */
7
6
  | 'invalid-request'
8
7
  /* The session was closed, or belonged to a helper that has since exited. */
9
8
  | 'unknown-session'
@@ -13,7 +12,6 @@ export type DatabaseErrorCode =
13
12
  | 'tunnel-failed'
14
13
  /* The server turned the SQL down; `sqlState` and `message` say why. */
15
14
  | 'query-failed'
16
- /* A write on a connection opened read only. */
17
15
  | 'read-only'
18
16
  /* An update or a delete on a table without a primary key or a unique key over columns that cannot be null. */
19
17
  | 'no-row-key'
@@ -21,7 +19,6 @@ export type DatabaseErrorCode =
21
19
  | 'conflict'
22
20
  | 'cancelled'
23
21
  | 'unsupported'
24
- /* A file to export to or import from could not be read or written. */
25
22
  | 'file-failed'
26
23
  | 'forbidden'
27
24
  | 'helper-exited'
@@ -152,7 +152,6 @@ export interface DatabaseMethods {
152
152
  };
153
153
  result: { readonly rows: number; readonly elapsedMs: number };
154
154
  };
155
- /* The running containers that look like database servers. */
156
155
  discover: { params: { readonly kind: 'docker'; readonly context?: string }; result: { readonly containers: readonly DockerContainer[] } };
157
156
  /*
158
157
  * Stops the request with this id. Answers whether it was still running. The request itself fails with
@@ -86,14 +86,12 @@ export interface TableStructure {
86
86
  readonly ddl: string | null;
87
87
  }
88
88
 
89
- /* The column of a table a result column holds, as the server reports it. */
90
89
  export interface ColumnSource {
91
90
  readonly schema: string;
92
91
  readonly table: string;
93
92
  readonly column: string;
94
93
  }
95
94
 
96
- /* A column of a result, which may come from a table or from an expression. */
97
95
  export interface ResultColumn {
98
96
  readonly name: string;
99
97
  /* The engine's name for the type of the value, such as `VARCHAR`; empty when it reports none. */
@@ -10,10 +10,8 @@ export interface BinaryValue {
10
10
  readonly hex: string;
11
11
  }
12
12
 
13
- /* A whole value, as a key or an edit carries it. */
14
13
  export type Value = null | boolean | number | string | BinaryValue;
15
14
 
16
- /* What a cell in an edit is set to: a value, or the column's default. */
17
15
  export type EditValue = Value | { readonly kind: 'default' };
18
16
 
19
17
  /* Bytes in a result. `hex` holds the first bytes only when `length` is larger than `hex.length / 2`. */
package/src/sql-split.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import type { Engine } from './protocol/index.ts';
2
2
 
3
3
  /* One piece of SQL text. Whitespace is no token; every other character is part of one. */
4
- export interface SqlToken {
4
+ interface SqlToken {
5
5
  readonly kind: 'word' | 'quoted' | 'comment' | 'punct' | 'semicolon';
6
6
  /* Offsets into the text, `end` exclusive. */
7
7
  readonly start: number;
@@ -9,7 +9,7 @@ export interface SqlToken {
9
9
  }
10
10
 
11
11
  /* A statement of a script, trimmed. `start` and `end` are offsets into the script, `end` exclusive and before the semicolon. */
12
- export interface SqlStatement {
12
+ interface SqlStatement {
13
13
  readonly text: string;
14
14
  readonly start: number;
15
15
  readonly end: number;
@@ -37,7 +37,6 @@ interface Answer {
37
37
  const TH = 'sticky top-0 h-7 bg-surface px-3 text-left text-xs font-medium whitespace-nowrap text-text-faint';
38
38
  const TD = 'h-7 border-t border-border-soft px-3 text-xs whitespace-nowrap text-text select-text';
39
39
 
40
- /* The columns, indexes, foreign keys and DDL of one table or view. */
41
40
  export function StructureView({ connection, schema, table, toolbarStart, className, ref }: StructureViewProps) {
42
41
  const { t } = useTranslation('database');
43
42
  const client = useDatabaseClient();
@@ -19,7 +19,7 @@ import {
19
19
 
20
20
  const FOCUS_SHORTCUT = shortcut('Mod+F');
21
21
 
22
- export interface CommandFieldProps {
22
+ interface CommandFieldProps {
23
23
  chips: readonly Chip[];
24
24
  columns: readonly CommandColumn[];
25
25
  engine: Engine;
@@ -6,20 +6,16 @@ import { useTranslation } from 'react-i18next';
6
6
  import type { ColumnInfo } from '../protocol/index.ts';
7
7
  import { hasMapping } from './import-mapping.ts';
8
8
 
9
- /* What a file's first lines look like, as the client samples them. */
10
9
  export interface ImportSample {
11
10
  readonly columns: readonly string[];
12
11
  readonly rows: readonly (readonly string[])[];
13
12
  }
14
13
 
15
- /* How many of the sampled rows the preview shows. */
16
14
  const PREVIEW_ROWS = 8;
17
15
  const SKIP = '-1';
18
16
 
19
17
  export interface ImportFormProps {
20
- /* The file's path, which the person confirms the import of. */
21
18
  path: string;
22
- /* The columns of the table a file column can go to. */
23
19
  tableColumns: readonly ColumnInfo[];
24
20
  /* `null` while a new sample is read. */
25
21
  sample: ImportSample | null;
@@ -36,7 +32,6 @@ export interface ImportFormProps {
36
32
  ref?: Ref<HTMLDivElement>;
37
33
  }
38
34
 
39
- /* The body of the import dialog: how the file's columns map onto the table's, and a look at the rows. */
40
35
  export function ImportForm({
41
36
  path,
42
37
  tableColumns,
@@ -151,12 +146,11 @@ function MappingRow({ name, value, items, disabled, label, onChange }: MappingRo
151
146
  );
152
147
  }
153
148
 
154
- export interface ImportDialogProps extends ImportFormProps {
149
+ interface ImportDialogProps extends ImportFormProps {
155
150
  open: boolean;
156
151
  onOpenChange(open: boolean): void;
157
152
  }
158
153
 
159
- /* The import of a file into the table: pick how the columns map, look at the rows, confirm. */
160
154
  export function ImportDialog({ open, onOpenChange, ...form }: ImportDialogProps) {
161
155
  const { t } = useTranslation('database');
162
156
 
@@ -20,17 +20,18 @@ import { useEffect, useMemo, useRef, useState, type KeyboardEvent, type Ref } fr
20
20
  import { useTranslation } from 'react-i18next';
21
21
  import { useNumberNotation } from '../client-context.ts';
22
22
  import { CODE_TEXT } from '../code-text.ts';
23
+ import { columnNotation, cellView, copyTextOf, isPreview, numeralText } from '../grid/display.ts';
24
+ import { draftOf, parseDraft } from '../grid/edit-value.ts';
25
+ import { parseEnumType } from '../grid/enum-type.ts';
26
+ import { EnumPicker } from '../grid/EnumPicker.tsx';
27
+ import { wholeValueOf } from '../grid/focused-value.ts';
28
+ import type { FocusedCell, GridColumn, GridRow } from '../grid/types.ts';
29
+ import type { NumberNotation } from '../number-notation.ts';
23
30
  import type { EditValue, Value } from '../protocol/index.ts';
24
31
  import { isNumericKind } from '../sql.ts';
25
32
  import { ValueEditor } from '../value/ValueEditor.tsx';
26
- import { columnNotation, cellView, copyTextOf, isPreview, numeralText, type NumberNotation } from './display.ts';
27
- import { draftOf, parseDraft } from './edit-value.ts';
28
- import { parseEnumType } from './enum-type.ts';
29
- import { EnumPicker } from './EnumPicker.tsx';
30
- import { wholeValueOf } from './focused-value.ts';
31
- import type { FocusedCell, GridColumn, GridRow } from './types.ts';
32
-
33
- export interface RecordViewProps {
33
+
34
+ interface RecordViewProps {
34
35
  columns: readonly GridColumn[];
35
36
  rows: readonly GridRow[];
36
37
  /* The row shown, an index into `rows`; -1 shows none. */
@@ -43,14 +44,11 @@ export interface RecordViewProps {
43
44
  onCommit?(rowKey: string, column: number, value: EditValue): void;
44
45
  /* The whole value of a field that is only a preview. Resolves `undefined` when it cannot be had. */
45
46
  loadValue?(rowKey: string, column: number): Promise<Value | undefined>;
46
- /* A field took the focus. */
47
47
  onFocusedCellChange?(cell: FocusedCell): void;
48
48
  onFollow?(cell: FocusedCell): void;
49
49
  canFollow?(cell: FocusedCell): boolean;
50
50
  onClose(): void;
51
- /* The accessible name of the list of fields. */
52
51
  label: string;
53
- /* Drawn while there is no row. */
54
52
  empty?: string;
55
53
  className?: string;
56
54
  ref?: Ref<HTMLDivElement>;
@@ -385,7 +383,6 @@ export function RecordView({
385
383
  );
386
384
  }
387
385
 
388
- /* A field opened up to its whole value, fetched with `loadValue` when the row holds only a preview. */
389
386
  function WholeValue({
390
387
  row,
391
388
  column,