incremnt 0.2.0 → 0.3.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.
- package/package.json +1 -1
- package/src/browse.js +37 -2
package/package.json
CHANGED
package/src/browse.js
CHANGED
|
@@ -2,6 +2,8 @@ import React, { useEffect, useMemo, useRef, useState } from 'react';
|
|
|
2
2
|
import chalk from 'chalk';
|
|
3
3
|
import { Box, Text, render, useApp, useInput, useStdout } from 'ink';
|
|
4
4
|
import { formatPretty } from './format.js';
|
|
5
|
+
import { readSnapshot } from './local.js';
|
|
6
|
+
import { executeReadCommand as executeLocalReadCommand } from './queries.js';
|
|
5
7
|
|
|
6
8
|
const UI = {
|
|
7
9
|
sectionWidth: 26,
|
|
@@ -22,10 +24,11 @@ export async function runBrowseCli({ transport, stdout, stderr, options = {} })
|
|
|
22
24
|
}
|
|
23
25
|
|
|
24
26
|
try {
|
|
25
|
-
const
|
|
27
|
+
const browseTransport = createBrowseTransport(transport);
|
|
28
|
+
const data = await loadBrowseData(browseTransport, options);
|
|
26
29
|
const app = render(
|
|
27
30
|
React.createElement(BrowseApp, {
|
|
28
|
-
transport,
|
|
31
|
+
transport: browseTransport,
|
|
29
32
|
data,
|
|
30
33
|
options
|
|
31
34
|
}),
|
|
@@ -45,6 +48,38 @@ export async function runBrowseCli({ transport, stdout, stderr, options = {} })
|
|
|
45
48
|
}
|
|
46
49
|
}
|
|
47
50
|
|
|
51
|
+
export function createBrowseTransport(transport) {
|
|
52
|
+
const snapshotPath = transport?.kind === 'local' ? transport?.snapshotSource?.path : null;
|
|
53
|
+
if (!snapshotPath) {
|
|
54
|
+
return transport;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
let snapshotPromise = null;
|
|
58
|
+
|
|
59
|
+
const loadSnapshot = async () => {
|
|
60
|
+
if (!snapshotPromise) {
|
|
61
|
+
snapshotPromise = readSnapshot(snapshotPath);
|
|
62
|
+
}
|
|
63
|
+
return snapshotPromise;
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
return {
|
|
67
|
+
...transport,
|
|
68
|
+
async executeReadCommand(normalizedCommand, options = {}) {
|
|
69
|
+
const snapshot = await loadSnapshot();
|
|
70
|
+
const result = executeLocalReadCommand(snapshot, normalizedCommand, options);
|
|
71
|
+
|
|
72
|
+
if (!result.ok) {
|
|
73
|
+
const error = new Error(result.error);
|
|
74
|
+
error.code = 'READ_COMMAND_ERROR';
|
|
75
|
+
throw error;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
return result.payload;
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
|
|
48
83
|
async function loadBrowseData(transport, options) {
|
|
49
84
|
const requests = [
|
|
50
85
|
{ key: 'sessions', command: 'session-insights', options: { limit: options.limit ?? '12' }, fallback: [] },
|