@mhjuma/traverse 0.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 (90) hide show
  1. package/LICENSE +21 -0
  2. package/package.json +46 -0
  3. package/src/bootstrap.spec.tsx +290 -0
  4. package/src/bootstrap.tsx +195 -0
  5. package/src/colors.ts +23 -0
  6. package/src/components/ChartPanel/ChartPanel.logic.spec.ts +358 -0
  7. package/src/components/ChartPanel/ChartPanel.logic.ts +318 -0
  8. package/src/components/ChartPanel/ChartPanel.spec.tsx +331 -0
  9. package/src/components/ChartPanel/ChartPanel.styles.ts +14 -0
  10. package/src/components/ChartPanel/ChartPanel.tsx +151 -0
  11. package/src/components/ConnectionDialog/ConnectionDialog.spec.tsx +767 -0
  12. package/src/components/ConnectionDialog/ConnectionDialog.tsx +652 -0
  13. package/src/components/ConnectionDialog/ConnectionRow.spec.tsx +104 -0
  14. package/src/components/ConnectionDialog/ConnectionRow.tsx +177 -0
  15. package/src/components/EditorToolbar/EditorToolbar.spec.tsx +599 -0
  16. package/src/components/EditorToolbar/EditorToolbar.tsx +259 -0
  17. package/src/components/Explorer/Explorer.spec.tsx +615 -0
  18. package/src/components/Explorer/Explorer.tsx +49 -0
  19. package/src/components/ExplorerWorkspace/ExplorerWorkspace.logic.spec.ts +715 -0
  20. package/src/components/ExplorerWorkspace/ExplorerWorkspace.logic.ts +324 -0
  21. package/src/components/ExplorerWorkspace/ExplorerWorkspace.spec.tsx +450 -0
  22. package/src/components/ExplorerWorkspace/ExplorerWorkspace.styles.ts +478 -0
  23. package/src/components/ExplorerWorkspace/ExplorerWorkspace.tsx +648 -0
  24. package/src/components/ExplorerWorkspace/kqlLanguage.spec.ts +321 -0
  25. package/src/components/ExplorerWorkspace/kqlLanguage.ts +155 -0
  26. package/src/components/ResultsPanel/ElapsedTimer.spec.tsx +51 -0
  27. package/src/components/ResultsPanel/ElapsedTimer.tsx +15 -0
  28. package/src/components/ResultsPanel/HistoryItem.spec.tsx +123 -0
  29. package/src/components/ResultsPanel/HistoryItem.tsx +56 -0
  30. package/src/components/ResultsPanel/ResultSetTab.tsx +18 -0
  31. package/src/components/ResultsPanel/ResultsPanel.spec.tsx +1194 -0
  32. package/src/components/ResultsPanel/ResultsPanel.tsx +321 -0
  33. package/src/components/ResultsPanel/TabButton.tsx +11 -0
  34. package/src/components/ResultsTable/ColumnHeader.tsx +42 -0
  35. package/src/components/ResultsTable/ColumnPickerItem.tsx +16 -0
  36. package/src/components/ResultsTable/FilterCell.tsx +24 -0
  37. package/src/components/ResultsTable/ResultsTable.logic.spec.ts +655 -0
  38. package/src/components/ResultsTable/ResultsTable.logic.ts +264 -0
  39. package/src/components/ResultsTable/ResultsTable.spec.tsx +930 -0
  40. package/src/components/ResultsTable/ResultsTable.styles.ts +108 -0
  41. package/src/components/ResultsTable/ResultsTable.tsx +501 -0
  42. package/src/components/ResultsTable/VirtualCell.spec.tsx +55 -0
  43. package/src/components/ResultsTable/VirtualCell.tsx +32 -0
  44. package/src/components/ResultsTable/VirtualRow.tsx +55 -0
  45. package/src/components/SchemaSidebar/FolderRow.tsx +35 -0
  46. package/src/components/SchemaSidebar/SchemaColumnItem.tsx +41 -0
  47. package/src/components/SchemaSidebar/SchemaContextMenu.spec.tsx +148 -0
  48. package/src/components/SchemaSidebar/SchemaContextMenu.tsx +49 -0
  49. package/src/components/SchemaSidebar/SchemaSidebar.logic.spec.ts +230 -0
  50. package/src/components/SchemaSidebar/SchemaSidebar.logic.ts +74 -0
  51. package/src/components/SchemaSidebar/SchemaSidebar.spec.tsx +1111 -0
  52. package/src/components/SchemaSidebar/SchemaSidebar.tsx +244 -0
  53. package/src/components/SchemaSidebar/SchemaTableItem.tsx +77 -0
  54. package/src/components/TabBar/TabBar.logic.spec.ts +127 -0
  55. package/src/components/TabBar/TabBar.logic.ts +35 -0
  56. package/src/components/TabBar/TabBar.spec.tsx +929 -0
  57. package/src/components/TabBar/TabBar.tsx +284 -0
  58. package/src/components/TabBar/TabItem.tsx +166 -0
  59. package/src/components/VegaChart/VegaChart.spec.tsx +126 -0
  60. package/src/components/VegaChart/VegaChart.tsx +224 -0
  61. package/src/config.spec.ts +44 -0
  62. package/src/config.ts +47 -0
  63. package/src/context/ExplorerColorContext.ts +14 -0
  64. package/src/context/ExplorerStateContext.ts +49 -0
  65. package/src/context/KustoClientContext.ts +12 -0
  66. package/src/context/context.spec.tsx +183 -0
  67. package/src/index.ts +14 -0
  68. package/src/services/cache.spec.ts +31 -0
  69. package/src/services/cache.ts +16 -0
  70. package/src/services/concurrency.spec.ts +139 -0
  71. package/src/services/concurrency.ts +46 -0
  72. package/src/services/kusto.spec.ts +919 -0
  73. package/src/services/kusto.ts +472 -0
  74. package/src/services/queryHistory.spec.ts +287 -0
  75. package/src/services/queryHistory.ts +146 -0
  76. package/src/services/schema.spec.ts +618 -0
  77. package/src/services/schema.ts +294 -0
  78. package/src/services/state-service.spec.ts +670 -0
  79. package/src/services/state-service.ts +602 -0
  80. package/src/services/useKustoQuery.spec.ts +234 -0
  81. package/src/services/useKustoQuery.ts +124 -0
  82. package/src/state/actions.ts +50 -0
  83. package/src/state/index.ts +3 -0
  84. package/src/state/reducer.spec.ts +644 -0
  85. package/src/state/reducer.ts +207 -0
  86. package/src/state/types.ts +54 -0
  87. package/tsconfig.json +7 -0
  88. package/tsconfig.lint.json +4 -0
  89. package/tsconfig.spec.json +7 -0
  90. package/vitest.config.ts +34 -0
@@ -0,0 +1,207 @@
1
+ /**
2
+ * Explorer state reducer — pure function, fully unit-testable.
3
+ * All state mutations go through typed actions.
4
+ */
5
+
6
+ import type { ExplorerState, InitialStateArgs } from './types';
7
+ import type { ExplorerAction } from './actions';
8
+ import { createTab, nextQueryTitle, loadConnections, loadActiveConnectionId } from '../components/ExplorerWorkspace/ExplorerWorkspace.logic';
9
+ import { SUPPORTED_RENDER_TYPES } from '../components/ChartPanel/ChartPanel.logic';
10
+
11
+ export function createInitialState({ initialQuery, defaultClusters }: InitialStateArgs): ExplorerState {
12
+ const connections = loadConnections(defaultClusters);
13
+ const firstTab = createTab(initialQuery, 'Query 1', loadActiveConnectionId(connections));
14
+ return {
15
+ connections,
16
+
17
+ schema: [],
18
+ schemaSearch: '',
19
+ expandedFolders: new Set(),
20
+ expandedTables: new Set(),
21
+ schemaContextMenu: null,
22
+
23
+ tabs: [firstTab],
24
+ activeTabId: firstTab.id,
25
+ splitEnabled: false,
26
+ splitDirection: 'vertical',
27
+ splitTabId: null,
28
+ focusedPane: 'primary',
29
+
30
+ loading: false,
31
+ error: null,
32
+ queryStartTime: null,
33
+ runningQueryKey: null,
34
+
35
+ rows: null,
36
+ columns: [],
37
+ columnTypes: {},
38
+ elapsed: null,
39
+ resultTime: null,
40
+ queryStats: null,
41
+ resultSets: [],
42
+ activeResultSet: 0,
43
+ resultsTab: 'results',
44
+
45
+ history: [],
46
+
47
+ editorHeight: 50,
48
+ hasSelection: false,
49
+ canRecall: false,
50
+ };
51
+ }
52
+
53
+ export function explorerReducer(state: ExplorerState, action: ExplorerAction): ExplorerState {
54
+ switch (action.type) {
55
+ // Connections
56
+ case 'SET_CONNECTIONS':
57
+ return { ...state, connections: action.connections };
58
+ case 'SET_TAB_CONNECTION':
59
+ return { ...state, tabs: state.tabs.map((t) => t.id === action.tabId ? { ...t, connectionId: action.connectionId } : t) };
60
+
61
+ // Schema
62
+ case 'SET_SCHEMA':
63
+ return { ...state, schema: action.schema };
64
+ case 'SET_SCHEMA_SEARCH':
65
+ return { ...state, schemaSearch: action.search };
66
+ case 'TOGGLE_FOLDER': {
67
+ const next = new Set(state.expandedFolders);
68
+ if (next.has(action.folder)) { next.delete(action.folder); } else { next.add(action.folder); }
69
+ return { ...state, expandedFolders: next };
70
+ }
71
+ case 'TOGGLE_TABLE': {
72
+ const next = new Set(state.expandedTables);
73
+ if (next.has(action.table)) { next.delete(action.table); } else { next.add(action.table); }
74
+ return { ...state, expandedTables: next };
75
+ }
76
+ case 'EXPAND_ALL_FOLDERS':
77
+ return { ...state, expandedFolders: new Set(action.folders), expandedTables: new Set(state.schema.map((t) => t.name)) };
78
+ case 'COLLAPSE_ALL_FOLDERS':
79
+ return { ...state, expandedFolders: new Set(), expandedTables: new Set() };
80
+ case 'SET_SCHEMA_CONTEXT_MENU':
81
+ return { ...state, schemaContextMenu: action.menu };
82
+
83
+ // Tabs
84
+ case 'ADD_TAB': {
85
+ const activeConn = state.tabs.find((t) => t.id === state.activeTabId)?.connectionId ?? state.connections[0]?.id;
86
+ const title = nextQueryTitle(state.tabs);
87
+ const tab = createTab('', title, activeConn);
88
+ return { ...state, tabs: [...state.tabs, tab], activeTabId: tab.id, splitEnabled: false, splitTabId: null, focusedPane: 'primary' };
89
+ }
90
+ case 'CLOSE_TAB': {
91
+ if (state.tabs.length <= 1) {
92
+ return state;
93
+ }
94
+ const idx = state.tabs.findIndex((t) => t.id === action.tabId);
95
+ const next = state.tabs.filter((t) => t.id !== action.tabId);
96
+ let { activeTabId, splitTabId, splitEnabled, focusedPane } = state;
97
+ if (activeTabId === action.tabId) {
98
+ activeTabId = next[Math.max(0, idx - 1)].id;
99
+ if (splitTabId === activeTabId) { splitEnabled = false; splitTabId = null; focusedPane = 'primary'; }
100
+ }
101
+ if (splitTabId === action.tabId) { splitEnabled = false; splitTabId = null; focusedPane = 'primary'; }
102
+ return { ...state, tabs: next, activeTabId, splitTabId, splitEnabled, focusedPane };
103
+ }
104
+ case 'CLOSE_OTHER_TABS': {
105
+ const kept = state.tabs.filter((t) => t.id === action.tabId);
106
+ if (kept.length === 0) {
107
+ return state;
108
+ }
109
+ return { ...state, tabs: kept, activeTabId: action.tabId, splitEnabled: false, splitTabId: null, focusedPane: 'primary' };
110
+ }
111
+ case 'CLOSE_ALL_TABS': {
112
+ const conn = state.tabs.find((t) => t.id === state.activeTabId)?.connectionId ?? state.connections[0]?.id;
113
+ const tab = createTab('', 'Query 1', conn);
114
+ return { ...state, tabs: [tab], activeTabId: tab.id, splitEnabled: false, splitTabId: null, focusedPane: 'primary' };
115
+ }
116
+ case 'DUPLICATE_TAB': {
117
+ const source = state.tabs.find((t) => t.id === action.tabId);
118
+ if (!source) {
119
+ return state;
120
+ }
121
+ const title = nextQueryTitle(state.tabs);
122
+ const dup = createTab(source.kql, title, source.connectionId);
123
+ const idx = state.tabs.findIndex((t) => t.id === action.tabId);
124
+ const tabs = [...state.tabs];
125
+ tabs.splice(idx + 1, 0, dup);
126
+ return { ...state, tabs, activeTabId: dup.id };
127
+ }
128
+ case 'SWITCH_TAB':
129
+ return state.focusedPane === 'primary'
130
+ ? { ...state, activeTabId: action.tabId }
131
+ : { ...state, splitTabId: action.tabId };
132
+ case 'UPDATE_TAB_KQL':
133
+ return { ...state, tabs: state.tabs.map((t) => t.id === action.tabId ? { ...t, kql: action.kql } : t) };
134
+ case 'RENAME_TAB':
135
+ return { ...state, tabs: state.tabs.map((t) => t.id === action.tabId ? { ...t, title: action.title } : t) };
136
+ case 'REORDER_TABS': {
137
+ const next = [...state.tabs];
138
+ const [moved] = next.splice(action.fromIdx, 1);
139
+ next.splice(action.toIdx, 0, moved);
140
+ return { ...state, tabs: next };
141
+ }
142
+ case 'TOGGLE_SPLIT': {
143
+ if (state.splitEnabled && state.splitDirection === action.direction) {
144
+ return { ...state, splitEnabled: false, splitTabId: null, focusedPane: 'primary' };
145
+ }
146
+ const targetSplitTabId = action.splitTabId ?? state.splitTabId;
147
+ if (!targetSplitTabId || targetSplitTabId === state.activeTabId) {
148
+ const activeConn = state.tabs.find((t) => t.id === state.activeTabId)?.connectionId ?? state.connections[0]?.id;
149
+ const tab = createTab('', undefined, activeConn);
150
+ return { ...state, splitEnabled: true, splitDirection: action.direction, splitTabId: tab.id, tabs: [...state.tabs, tab] };
151
+ }
152
+ return { ...state, splitEnabled: true, splitDirection: action.direction, splitTabId: targetSplitTabId };
153
+ }
154
+ case 'CLOSE_SPLIT':
155
+ return { ...state, splitEnabled: false, splitTabId: null, focusedPane: 'primary' };
156
+ case 'SET_FOCUSED_PANE':
157
+ return { ...state, focusedPane: action.pane };
158
+
159
+ // Query execution
160
+ case 'QUERY_START':
161
+ return { ...state, loading: true, error: null, queryStartTime: Date.now(), runningQueryKey: action.queryKey, resultsTab: 'results' };
162
+ case 'QUERY_SUCCESS': {
163
+ const viz = action.resultSets[0]?.visualization;
164
+ const hasChart = viz ? SUPPORTED_RENDER_TYPES.has(viz.type.toLowerCase()) : false;
165
+ return {
166
+ ...state,
167
+ loading: false,
168
+ rows: action.rows,
169
+ columns: action.columns,
170
+ columnTypes: action.columnTypes,
171
+ elapsed: action.elapsed,
172
+ resultTime: new Date(),
173
+ queryStats: action.stats,
174
+ resultSets: action.resultSets,
175
+ activeResultSet: 0,
176
+ queryStartTime: null,
177
+ runningQueryKey: null,
178
+ resultsTab: hasChart ? 'chart' : 'results',
179
+ };
180
+ }
181
+ case 'QUERY_ERROR':
182
+ return { ...state, loading: false, error: action.error, queryStartTime: null, runningQueryKey: null };
183
+ case 'QUERY_CANCEL':
184
+ return { ...state, loading: false, queryStartTime: null, runningQueryKey: null };
185
+
186
+ // Results
187
+ case 'SET_RESULTS_TAB':
188
+ return { ...state, resultsTab: action.tab };
189
+ case 'SET_ACTIVE_RESULT_SET':
190
+ return { ...state, activeResultSet: action.index };
191
+ case 'SET_HISTORY':
192
+ return { ...state, history: action.history };
193
+ case 'LOAD_HISTORY_ENTRY':
194
+ return { ...state, rows: action.rows, columns: action.columns, columnTypes: action.columnTypes, resultsTab: 'results' };
195
+
196
+ // UI
197
+ case 'SET_EDITOR_HEIGHT':
198
+ return { ...state, editorHeight: action.height };
199
+ case 'SET_HAS_SELECTION':
200
+ return { ...state, hasSelection: action.hasSelection };
201
+ case 'SET_CAN_RECALL':
202
+ return { ...state, canRecall: action.canRecall };
203
+
204
+ default:
205
+ return state;
206
+ }
207
+ }
@@ -0,0 +1,54 @@
1
+ import type { QueryStats, KustoResultSet } from '../services/kusto';
2
+ import type { QueryHistoryEntry } from '../services/queryHistory';
3
+ import type { SchemaTable } from '../services/schema';
4
+ import type { QueryTab, KustoConnection } from '../components/ExplorerWorkspace/ExplorerWorkspace.logic';
5
+
6
+ export interface ExplorerState {
7
+ // Connections
8
+ connections: KustoConnection[];
9
+
10
+ // Schema
11
+ schema: SchemaTable[];
12
+ schemaSearch: string;
13
+ expandedFolders: Set<string>;
14
+ expandedTables: Set<string>;
15
+ schemaContextMenu: { tableName: string; x: number; y: number } | null;
16
+
17
+ // Tabs
18
+ tabs: QueryTab[];
19
+ activeTabId: string;
20
+ splitEnabled: boolean;
21
+ splitDirection: 'vertical' | 'horizontal';
22
+ splitTabId: string | null;
23
+ focusedPane: 'primary' | 'secondary';
24
+
25
+ // Query execution
26
+ loading: boolean;
27
+ error: string | null;
28
+ queryStartTime: number | null;
29
+ runningQueryKey: string | null;
30
+
31
+ // Results
32
+ rows: Record<string, unknown>[] | null;
33
+ columns: string[];
34
+ columnTypes: Record<string, string>;
35
+ elapsed: number | null;
36
+ resultTime: Date | null;
37
+ queryStats: QueryStats | null;
38
+ resultSets: KustoResultSet[];
39
+ activeResultSet: number;
40
+ resultsTab: 'results' | 'chart' | 'stats' | 'history';
41
+
42
+ // History
43
+ history: QueryHistoryEntry[];
44
+
45
+ // UI
46
+ editorHeight: number;
47
+ hasSelection: boolean;
48
+ canRecall: boolean;
49
+ }
50
+
51
+ export interface InitialStateArgs {
52
+ initialQuery: string;
53
+ defaultClusters: KustoConnection[];
54
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,7 @@
1
+ {
2
+ "extends": "../../tsconfig.base.json",
3
+ "compilerOptions": {
4
+ "lib": ["ES2022", "DOM", "DOM.Iterable"]
5
+ },
6
+ "include": ["src"]
7
+ }
@@ -0,0 +1,4 @@
1
+ {
2
+ "extends": "./tsconfig.json",
3
+ "include": ["src"]
4
+ }
@@ -0,0 +1,7 @@
1
+ {
2
+ "extends": "./tsconfig.json",
3
+ "include": [
4
+ "src/**/*.spec.ts",
5
+ "src/**/*.spec.tsx"
6
+ ]
7
+ }
@@ -0,0 +1,34 @@
1
+ import { defineConfig } from 'vitest/config';
2
+
3
+ export default defineConfig({
4
+ test: {
5
+ globals: false,
6
+ environment: 'jsdom',
7
+ include: ['src/**/*.spec.{ts,tsx}'],
8
+ exclude: ['**/node_modules/**', '**/.{idea,git,cache,output,temp}/**'],
9
+ passWithNoTests: false,
10
+ retry: 0,
11
+ typecheck: {
12
+ enabled: true,
13
+ tsconfig: 'tsconfig.spec.json',
14
+ },
15
+ coverage: {
16
+ enabled: true,
17
+ provider: 'v8',
18
+ reporter: ['text', 'cobertura'],
19
+ include: ['src/**/*.{ts,tsx}'],
20
+ exclude: [
21
+ '**/*.d.ts',
22
+ '**/index.ts',
23
+ '**/*.spec.{ts,tsx}',
24
+ '**/*.mock.ts',
25
+ ],
26
+ thresholds: {
27
+ statements: 85,
28
+ branches: 80,
29
+ functions: 85,
30
+ lines: 85,
31
+ },
32
+ },
33
+ },
34
+ });