pythx-cli 0.0.5 → 0.0.6
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/dist/cli.js +17 -10
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -608,15 +608,15 @@ async function loadCachedPosts(entityId, limit = 50) {
|
|
|
608
608
|
|
|
609
609
|
// src/hooks/use-live-data.ts
|
|
610
610
|
var POLL_INTERVAL = 30 * 6e4;
|
|
611
|
-
function useLiveData(
|
|
611
|
+
function useLiveData(apiUrl2) {
|
|
612
612
|
const [data, setData] = useState2([]);
|
|
613
613
|
const [loading, setLoading] = useState2(true);
|
|
614
614
|
const [error, setError] = useState2(null);
|
|
615
615
|
const [lastUpdated, setLastUpdated] = useState2(null);
|
|
616
616
|
const fetchViaApi = useCallback(async () => {
|
|
617
|
-
if (!
|
|
617
|
+
if (!apiUrl2) return;
|
|
618
618
|
try {
|
|
619
|
-
const res = await fetch(`${
|
|
619
|
+
const res = await fetch(`${apiUrl2}/api/compare`, {
|
|
620
620
|
method: "POST",
|
|
621
621
|
headers: { "Content-Type": "application/json" },
|
|
622
622
|
body: JSON.stringify({
|
|
@@ -637,7 +637,7 @@ function useLiveData(apiUrl) {
|
|
|
637
637
|
} finally {
|
|
638
638
|
setLoading(false);
|
|
639
639
|
}
|
|
640
|
-
}, [
|
|
640
|
+
}, [apiUrl2]);
|
|
641
641
|
const loadFromCache = useCallback(async () => {
|
|
642
642
|
const results = [];
|
|
643
643
|
for (const entity of DEFAULT_ENTITIES) {
|
|
@@ -696,7 +696,7 @@ function useLiveData(apiUrl) {
|
|
|
696
696
|
setLoading(false);
|
|
697
697
|
}
|
|
698
698
|
}, [loadFromCache]);
|
|
699
|
-
const fetchData =
|
|
699
|
+
const fetchData = apiUrl2 ? fetchViaApi : fetchDirect;
|
|
700
700
|
useEffect2(() => {
|
|
701
701
|
fetchData();
|
|
702
702
|
const interval = setInterval(fetchData, POLL_INTERVAL);
|
|
@@ -707,8 +707,8 @@ function useLiveData(apiUrl) {
|
|
|
707
707
|
|
|
708
708
|
// src/app.tsx
|
|
709
709
|
import { jsx as jsx5, jsxs as jsxs5 } from "react/jsx-runtime";
|
|
710
|
-
function App({ apiUrl }) {
|
|
711
|
-
const { data, loading, error, lastUpdated, refresh } = useLiveData(
|
|
710
|
+
function App({ apiUrl: apiUrl2 }) {
|
|
711
|
+
const { data, loading, error, lastUpdated, refresh } = useLiveData(apiUrl2);
|
|
712
712
|
const [activeIndex, setActiveIndex] = useState3(0);
|
|
713
713
|
const [showDetail, setShowDetail] = useState3(true);
|
|
714
714
|
const { exit } = useApp();
|
|
@@ -754,31 +754,38 @@ function App({ apiUrl }) {
|
|
|
754
754
|
|
|
755
755
|
// src/cli.tsx
|
|
756
756
|
import { jsx as jsx6 } from "react/jsx-runtime";
|
|
757
|
+
var DEFAULT_API_URL = "https://pythx.vercel.app";
|
|
757
758
|
var cli = meow(
|
|
758
759
|
`
|
|
759
760
|
Usage
|
|
760
761
|
$ pythx
|
|
761
762
|
|
|
762
763
|
Options
|
|
763
|
-
--api-url URL of the Pythx web API (default:
|
|
764
|
+
--api-url URL of the Pythx web API (default: ${DEFAULT_API_URL})
|
|
765
|
+
--direct Use direct mode (requires HF_API_TOKEN and POSTGRES_URL env vars)
|
|
764
766
|
|
|
765
767
|
Examples
|
|
766
768
|
$ pythx
|
|
767
769
|
$ pythx --api-url http://localhost:3000
|
|
768
|
-
$ pythx --
|
|
770
|
+
$ pythx --direct
|
|
769
771
|
`,
|
|
770
772
|
{
|
|
771
773
|
importMeta: import.meta,
|
|
772
774
|
flags: {
|
|
773
775
|
apiUrl: {
|
|
774
776
|
type: "string"
|
|
777
|
+
},
|
|
778
|
+
direct: {
|
|
779
|
+
type: "boolean",
|
|
780
|
+
default: false
|
|
775
781
|
}
|
|
776
782
|
}
|
|
777
783
|
}
|
|
778
784
|
);
|
|
785
|
+
var apiUrl = cli.flags.direct ? void 0 : cli.flags.apiUrl ?? DEFAULT_API_URL;
|
|
779
786
|
process.stdout.write("\x1B[?1049h");
|
|
780
787
|
process.stdout.write("\x1B[H");
|
|
781
|
-
var instance = render(/* @__PURE__ */ jsx6(App, { apiUrl
|
|
788
|
+
var instance = render(/* @__PURE__ */ jsx6(App, { apiUrl }), { patchConsole: false });
|
|
782
789
|
instance.waitUntilExit().then(() => {
|
|
783
790
|
process.stdout.write("\x1B[?1049l");
|
|
784
791
|
});
|