@nyrra/prismantix-cli 0.0.3-next.17 → 0.0.3-next.2

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 (56) hide show
  1. package/README.md +20 -28
  2. package/bin/dev.js +1 -3
  3. package/bin/run.js +1 -3
  4. package/dist/api.d.ts +200 -173
  5. package/dist/api.d.ts.map +1 -1
  6. package/dist/api.js +236 -110
  7. package/dist/command-support.d.ts +13 -0
  8. package/dist/command-support.d.ts.map +1 -0
  9. package/dist/command-support.js +40 -0
  10. package/dist/commands/object/details.d.ts +13 -0
  11. package/dist/commands/object/details.d.ts.map +1 -0
  12. package/dist/commands/object/details.js +28 -0
  13. package/dist/commands/object/list.d.ts +13 -0
  14. package/dist/commands/object/list.d.ts.map +1 -0
  15. package/dist/commands/object/list.js +27 -0
  16. package/dist/commands/ontology/list.d.ts +10 -0
  17. package/dist/commands/ontology/list.d.ts.map +1 -0
  18. package/dist/commands/ontology/list.js +25 -0
  19. package/dist/commands/records/cancel.d.ts +13 -0
  20. package/dist/commands/records/cancel.d.ts.map +1 -0
  21. package/dist/commands/records/cancel.js +21 -0
  22. package/dist/commands/records/generate.d.ts +15 -0
  23. package/dist/commands/records/generate.d.ts.map +1 -0
  24. package/dist/commands/records/generate.js +56 -0
  25. package/dist/commands/{download.d.ts → records/pull.d.ts} +5 -11
  26. package/dist/commands/records/pull.d.ts.map +1 -0
  27. package/dist/commands/records/pull.js +59 -0
  28. package/dist/commands/records/status.d.ts +13 -0
  29. package/dist/commands/records/status.d.ts.map +1 -0
  30. package/dist/commands/records/status.js +22 -0
  31. package/dist/constants.d.ts +2 -1
  32. package/dist/constants.d.ts.map +1 -1
  33. package/dist/constants.js +2 -1
  34. package/dist/errors.d.ts.map +1 -1
  35. package/dist/errors.js +39 -0
  36. package/dist/generation.d.ts +13 -0
  37. package/dist/generation.d.ts.map +1 -0
  38. package/dist/generation.js +77 -0
  39. package/dist/io.d.ts.map +1 -1
  40. package/dist/io.js +1 -1
  41. package/dist/runtime.d.ts +3 -0
  42. package/dist/runtime.d.ts.map +1 -0
  43. package/dist/runtime.js +10 -0
  44. package/dist/workflow.d.ts +3 -14
  45. package/dist/workflow.d.ts.map +1 -1
  46. package/dist/workflow.js +85 -61
  47. package/oclif.manifest.json +266 -40
  48. package/package.json +22 -22
  49. package/dist/commands/download.d.ts.map +0 -1
  50. package/dist/commands/download.js +0 -136
  51. package/dist/commands/guided.d.ts +0 -7
  52. package/dist/commands/guided.d.ts.map +0 -1
  53. package/dist/commands/guided.js +0 -15
  54. package/dist/ui/guided-flow.d.ts +0 -20
  55. package/dist/ui/guided-flow.d.ts.map +0 -1
  56. package/dist/ui/guided-flow.js +0 -156
@@ -1,156 +0,0 @@
1
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { Alert, PasswordInput, Spinner, StatusMessage, TextInput, UnorderedList, } from "@inkjs/ui";
3
- import { Box, render, Text, useApp } from "ink";
4
- import { useEffect, useMemo, useState } from "react";
5
- import { DEFAULT_API_BASE_URL, DEFAULT_POLL_INTERVAL_MS, DEFAULT_TIMEOUT_MS, } from "../constants.js";
6
- import { toCliUserError } from "../errors.js";
7
- import { runDownloadWorkflow, summarizeManifest, } from "../workflow.js";
8
- export async function renderGuidedFlow(props = {}) {
9
- let result = { ok: false };
10
- const instance = render(_jsx(GuidedFlow, { ...props, onComplete: (nextResult) => {
11
- result = nextResult;
12
- props.onComplete?.(nextResult);
13
- } }));
14
- await instance.waitUntilExit();
15
- return result;
16
- }
17
- export function GuidedFlow({ cwd, env = process.env, fetchImpl, now, onComplete, sleep, }) {
18
- const { exit } = useApp();
19
- const envApiKey = env.PRISMANTIX_API_KEY?.trim();
20
- const envClientId = env.PRISMANTIX_CLIENT_ID?.trim().toUpperCase();
21
- const [apiKey, setApiKey] = useState(envApiKey ?? "");
22
- const [clientId, setClientId] = useState(envClientId ?? "");
23
- const [step, setStep] = useState(envApiKey ? "client" : "api-key");
24
- const [events, setEvents] = useState([]);
25
- const [inputError, setInputError] = useState();
26
- const [manifestSummary, setManifestSummary] = useState();
27
- const [result, setResult] = useState();
28
- const [fatalError, setFatalError] = useState();
29
- const apiBaseUrl = env.PRISMANTIX_API_BASE ?? DEFAULT_API_BASE_URL;
30
- const outputDir = env.PRISMANTIX_OUTPUT_DIR;
31
- const pollIntervalMs = readPositiveInteger(env.PRISMANTIX_POLL_INTERVAL_MS, DEFAULT_POLL_INTERVAL_MS);
32
- const timeoutMs = readPositiveInteger(env.PRISMANTIX_TIMEOUT_MS, DEFAULT_TIMEOUT_MS);
33
- useEffect(() => {
34
- if (step !== "running") {
35
- return;
36
- }
37
- let cancelled = false;
38
- runDownloadWorkflow({
39
- apiBaseUrl,
40
- apiKey,
41
- clientId,
42
- outputDir,
43
- pollIntervalMs,
44
- timeoutMs,
45
- }, {
46
- cwd,
47
- fetchImpl,
48
- now,
49
- onEvent: (event) => {
50
- if (cancelled) {
51
- return;
52
- }
53
- if (event.type === "manifest") {
54
- setManifestSummary(summarizeManifest(event.manifest));
55
- }
56
- setEvents((previousEvents) => [
57
- ...previousEvents.slice(-7),
58
- formatEvent(event),
59
- ]);
60
- },
61
- sleep,
62
- })
63
- .then((downloadResult) => {
64
- if (cancelled) {
65
- return;
66
- }
67
- setResult(downloadResult);
68
- setStep("done");
69
- onComplete?.({ ok: true, result: downloadResult });
70
- setTimeout(() => exit(), 0);
71
- })
72
- .catch((error) => {
73
- if (cancelled) {
74
- return;
75
- }
76
- const cliError = toCliUserError(error);
77
- setFatalError(cliError.message);
78
- setStep("error");
79
- onComplete?.({ error: cliError.message, ok: false });
80
- setTimeout(() => exit(), 0);
81
- });
82
- return () => {
83
- cancelled = true;
84
- };
85
- }, [
86
- apiBaseUrl,
87
- apiKey,
88
- clientId,
89
- cwd,
90
- exit,
91
- fetchImpl,
92
- now,
93
- onComplete,
94
- outputDir,
95
- pollIntervalMs,
96
- sleep,
97
- step,
98
- timeoutMs,
99
- ]);
100
- const header = useMemo(() => (_jsxs(Box, { flexDirection: "column", gap: 1, children: [_jsx(Text, { bold: true, children: "PrismantiX Export" }), _jsxs(Text, { color: "gray", children: ["API: ", apiBaseUrl] })] })), [apiBaseUrl]);
101
- if (step === "api-key") {
102
- return (_jsxs(Box, { flexDirection: "column", gap: 1, children: [header, _jsx(Text, { children: "Enter PRISMANTIX_API_KEY" }), _jsx(PasswordInput, { placeholder: "API key", onSubmit: (value) => {
103
- const nextApiKey = value.trim();
104
- if (!nextApiKey) {
105
- setInputError("API key is required.");
106
- return;
107
- }
108
- setInputError(undefined);
109
- setApiKey(nextApiKey);
110
- setStep("client");
111
- } }), inputError ? (_jsx(StatusMessage, { variant: "error", children: inputError })) : null] }));
112
- }
113
- if (step === "client") {
114
- return (_jsxs(Box, { flexDirection: "column", gap: 1, children: [header, _jsxs(StatusMessage, { variant: "info", children: ["API key loaded from ", envApiKey ? "environment" : "prompt", "."] }), _jsx(Text, { children: "Enter client ID" }), _jsx(TextInput, { placeholder: clientId ? `Client ID (${clientId})` : "Client ID", onSubmit: (value) => {
115
- const nextClientId = (value.trim() || clientId).toUpperCase();
116
- if (!nextClientId) {
117
- setInputError("Client ID is required.");
118
- return;
119
- }
120
- setInputError(undefined);
121
- setClientId(nextClientId);
122
- setStep("running");
123
- } }), inputError ? (_jsx(StatusMessage, { variant: "error", children: inputError })) : null] }));
124
- }
125
- return (_jsxs(Box, { flexDirection: "column", gap: 1, children: [header, step === "running" ? _jsx(Spinner, { label: "Creating export" }) : null, manifestSummary ? (_jsx(ManifestSummaryView, { summary: manifestSummary })) : null, _jsx(EventLog, { events: events }), step === "done" && result ? (_jsxs(StatusMessage, { variant: "success", children: ["Downloaded ", result.files.length, " file(s) to ", result.outputDir] })) : null, step === "error" && fatalError ? (_jsx(Alert, { variant: "error", children: fatalError })) : null] }));
126
- }
127
- export function ManifestSummaryView({ summary, }) {
128
- return (_jsxs(Box, { flexDirection: "column", children: [_jsxs(Text, { children: ["Manifest: ", summary.fileCount, " file(s), ", summary.totalRows, " total row(s)"] }), _jsx(UnorderedList, { children: summary.tables.map((table) => (_jsx(UnorderedList.Item, { children: _jsxs(Text, { children: [table.tableName, ": ", table.rowCount ?? 0, " row(s)"] }) }, table.tableName))) })] }));
129
- }
130
- function EventLog({ events }) {
131
- if (events.length === 0) {
132
- return null;
133
- }
134
- return (_jsx(Box, { flexDirection: "column", children: events.map((event) => (_jsx(Text, { color: "gray", children: event }, event))) }));
135
- }
136
- function formatEvent(event) {
137
- switch (event.type) {
138
- case "created":
139
- return `Queued export ${event.exportId} for ${event.clientId}.`;
140
- case "poll":
141
- return `Export ${event.status.exportId}: ${event.status.status}.`;
142
- case "manifest":
143
- return `Manifest fetched for ${event.manifest.exportId}.`;
144
- case "download-start":
145
- return `Downloading ${event.file.tableName}.`;
146
- case "download-complete":
147
- return `Downloaded ${event.file.tableName}.`;
148
- }
149
- }
150
- function readPositiveInteger(value, fallback) {
151
- if (!value) {
152
- return fallback;
153
- }
154
- const parsed = Number(value);
155
- return Number.isInteger(parsed) && parsed > 0 ? parsed : fallback;
156
- }