@tinybirdco/sdk 0.0.12 → 0.0.13

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.
@@ -0,0 +1,173 @@
1
+ /**
2
+ * Console output utilities with color support
3
+ * Provides consistent formatting similar to the Python CLI
4
+ */
5
+
6
+ // ANSI color codes
7
+ const colors = {
8
+ reset: "\x1b[0m",
9
+ bold: "\x1b[1m",
10
+ red: "\x1b[91m",
11
+ green: "\x1b[92m",
12
+ yellow: "\x1b[38;5;208m",
13
+ blue: "\x1b[94m",
14
+ gray: "\x1b[90m",
15
+ } as const;
16
+
17
+ // Check if colors should be disabled
18
+ const noColor = process.env.NO_COLOR !== undefined || !process.stdout.isTTY;
19
+
20
+ function colorize(text: string, color: keyof typeof colors): string {
21
+ if (noColor) return text;
22
+ return `${colors[color]}${text}${colors.reset}`;
23
+ }
24
+
25
+ /**
26
+ * Output a success message (green)
27
+ */
28
+ export function success(message: string): void {
29
+ console.log(colorize(message, "green"));
30
+ }
31
+
32
+ /**
33
+ * Output an error message (red)
34
+ */
35
+ export function error(message: string): void {
36
+ console.error(colorize(message, "red"));
37
+ }
38
+
39
+ /**
40
+ * Output a warning message (yellow/orange)
41
+ */
42
+ export function warning(message: string): void {
43
+ console.log(colorize(message, "yellow"));
44
+ }
45
+
46
+ /**
47
+ * Output an info message (default color)
48
+ */
49
+ export function info(message: string): void {
50
+ console.log(message);
51
+ }
52
+
53
+ /**
54
+ * Output a highlighted message (blue)
55
+ */
56
+ export function highlight(message: string): void {
57
+ console.log(colorize(message, "blue"));
58
+ }
59
+
60
+ /**
61
+ * Output a gray message (dimmed)
62
+ */
63
+ export function gray(message: string): void {
64
+ console.log(colorize(message, "gray"));
65
+ }
66
+
67
+ /**
68
+ * Output a bold message
69
+ */
70
+ export function bold(message: string): void {
71
+ console.log(colorize(message, "bold"));
72
+ }
73
+
74
+ /**
75
+ * Format a timestamp for console output
76
+ */
77
+ export function formatTime(): string {
78
+ return new Date().toLocaleTimeString("en-US", { hour12: false });
79
+ }
80
+
81
+ /**
82
+ * Format duration in human-readable format
83
+ */
84
+ export function formatDuration(ms: number): string {
85
+ if (ms < 1000) {
86
+ return `${ms}ms`;
87
+ }
88
+ return `${(ms / 1000).toFixed(1)}s`;
89
+ }
90
+
91
+ /**
92
+ * Show a resource change (checkmark + path + status)
93
+ */
94
+ export function showResourceChange(
95
+ path: string,
96
+ status: "created" | "changed" | "deleted"
97
+ ): void {
98
+ console.log(`✓ ${path} ${status}`);
99
+ }
100
+
101
+ /**
102
+ * Show a warning for a resource
103
+ */
104
+ export function showResourceWarning(
105
+ level: string,
106
+ resource: string,
107
+ message: string
108
+ ): void {
109
+ warning(`△ ${level}: ${resource}: ${message}`);
110
+ }
111
+
112
+ /**
113
+ * Show build errors in formatted style
114
+ */
115
+ export function showBuildErrors(errors: Array<{ filename?: string; error: string }>): void {
116
+ for (const err of errors) {
117
+ if (err.filename) {
118
+ error(`${err.filename}`);
119
+ // Indent the error message
120
+ const lines = err.error.split("\n");
121
+ for (const line of lines) {
122
+ error(` ${line}`);
123
+ }
124
+ } else {
125
+ error(err.error);
126
+ }
127
+ console.log(); // Empty line between errors
128
+ }
129
+ }
130
+
131
+ /**
132
+ * Show final build success message
133
+ */
134
+ export function showBuildSuccess(durationMs: number, isRebuild = false): void {
135
+ const prefix = isRebuild ? "Rebuild" : "Build";
136
+ success(`\n✓ ${prefix} completed in ${formatDuration(durationMs)}`);
137
+ }
138
+
139
+ /**
140
+ * Show final build failure message
141
+ */
142
+ export function showBuildFailure(isRebuild = false): void {
143
+ const prefix = isRebuild ? "Rebuild" : "Build";
144
+ error(`\n✗ ${prefix} failed`);
145
+ }
146
+
147
+ /**
148
+ * Show no changes message
149
+ */
150
+ export function showNoChanges(): void {
151
+ info("No changes. Build skipped.");
152
+ }
153
+
154
+ /**
155
+ * Output object containing all output functions
156
+ */
157
+ export const output = {
158
+ success,
159
+ error,
160
+ warning,
161
+ info,
162
+ highlight,
163
+ gray,
164
+ bold,
165
+ formatTime,
166
+ formatDuration,
167
+ showResourceChange,
168
+ showResourceWarning,
169
+ showBuildErrors,
170
+ showBuildSuccess,
171
+ showBuildFailure,
172
+ showNoChanges,
173
+ };