forked from tarasglek/eget.wasm
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patheget.d.ts
More file actions
254 lines (231 loc) · 7.06 KB
/
eget.d.ts
File metadata and controls
254 lines (231 loc) · 7.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
/**
* Callback function for download progress updates.
* @param url - The URL being downloaded.
* @param currentBytes - The number of bytes downloaded so far.
* @param totalBytes - The total number of bytes to download.
* Can be -1 if the total size is unknown.
*/
export type ProgressCallback = (
url: string,
currentBytes: number,
totalBytes: number,
) => void;
/**
* Configuration options for creating a new Eget instance.
*/
export interface EgetOptions {
/** Host's working directory for final output (defaults to `process.cwd()`). */
cwd?: string;
/** Temporary directory for downloaded files (defaults to `./.eget`). */
tmpDir?: string;
/** Optional callback for download progress updates. */
onProgress?: ProgressCallback;
/** Enable verbose logging, useful for debugging eget.wasm. */
verbose?: boolean;
}
/**
* Represents a parsed error from the eget WASM binary.
*/
export interface EgetError {
/** The file path associated with the error, if available. */
path: string | null;
/** The URL associated with the error, if available. */
url: string | null;
/** The error message. */
error: string;
}
/**
* Options for the `eget.download()` method.
*/
export interface DownloadOptions {
/** Target system (e.g., 'linux/amd64'). Auto-detected if not provided. */
system?: string;
/** Asset name pattern to match. */
asset?: string;
/** Specific release tag. */
tag?: string;
/** Include pre-release versions. */
preRelease?: boolean;
/** Extract specific file from archive. */
file?: string;
/**
* Path relative to the Eget instance's `cwd`.
* If a single asset results, 'to' is its target path.
* If multiple assets or `all` is included, 'to' is a subdirectory.
*/
to?: string;
/** Only upgrade if newer version available. */
upgradeOnly?: boolean;
/** Remove archive after extraction. */
removeArchive?: boolean;
/** Extract all files from archive. */
extractAll?: boolean;
/** Download the source code for the target repo instead of a release. */
source?: boolean;
/** Stop after downloading the asset (no extraction). */
downloadOnly?: boolean;
/** Timeout (ms) for downloads. */
timeout?: number;
/** Optional callback for download progress updates. */
onProgress?: ProgressCallback;
}
/**
* The result of a `eget.run()` operation.
*/
export interface RunResult {
/** Whether the operation succeeded. */
success: boolean;
/** URL that needs to be downloaded (if success is false). */
url?: string | null;
/** Path associated with the error. */
path?: string | null;
/** Error message. */
error?: string;
}
/**
* Options for the `eget()` convenience function.
* Combines EgetOptions and DownloadOptions with an extra `skipCleanup` flag.
*/
export type EgetFunctionOptions = EgetOptions &
DownloadOptions & {
/** Whether to skip automatic cleanup of temp files (for debugging). */
skipCleanup?: boolean;
};
/**
* HTTP errors
*/
export declare class HttpError extends Error {
statusCode: number;
url: string;
constructor(message: string, statusCode: number, url: string);
}
/**
* Error for 404 Not Found responses.
*/
export declare class HttpErrorNotFound extends HttpError {
constructor(message: string, url: string);
}
/**
* Error for 500/503 server responses.
*/
export declare class HttpErrorServer extends HttpError {
constructor(message: string, statusCode: number, url: string);
}
/**
* Error for 403/429 Rate Limit responses.
*/
export declare class HttpErrorRateLimit extends HttpError {
retryAfter: Date | null;
constructor(
message: string,
statusCode: number,
url: string,
headers: Headers,
);
calculateRetryAfter(headers: Headers): Date | null;
}
/**
* Node.js wrapper for eget WASM binary.
*/
export declare class Eget {
/** Cached promise for the compiled WASM module. */
static wasmCompilationPromise: Promise<WebAssembly.Module> | null;
/** Temporary directory for downloaded files. */
readonly tmpDir: string;
/** Host's working directory for final output. */
readonly cwd: string;
/** Enable verbose logging. */
readonly verbose: boolean;
/** Optional callback for download progress updates. */
readonly onProgress: ProgressCallback | undefined;
/**
* Creates a new Eget instance.
* @param options - Configuration options
*/
constructor(options?: EgetOptions);
/**
* Loads and compiles the WASM module, caching the compilation promise.
* @returns Compiled WASM module
* @throws If WASM file cannot be loaded or compiled
*/
getWasmModule(): Promise<WebAssembly.Module>;
/**
* Logs a message to stderr if verbose mode is enabled.
* @param message - Messages to log
*/
log(...message: any[]): void;
/**
* Downloads a file from a URL to a local path.
* @param url - URL to download from
* @param filePath - Local file path to save to
* @param onProgress - Optional callback for progress updates
* @param timeoutMs - The timeout (ms) to wait (defaults to 30s)
*/
downloadFile(
url: string,
filePath: string,
onProgress?: ProgressCallback,
timeoutMs?: number,
): Promise<void>;
/**
* Runs the eget WASM binary with the given arguments.
* @param args - Command line arguments for eget
* @param runOptions - Options for WASI execution
* @returns Result of the operation
*/
run(
args: string[],
runOptions?: { wasmSandboxDir?: string },
): Promise<RunResult>;
/**
* Downloads assets from a GitHub repository using eget.
* @param repo - GitHub repository in format 'owner/repo'
* @param options - Download options
* @returns True if download succeeded, false otherwise
* @throws HttpError if a recoverable HTTP error occurs
* @throws Error if a non-recoverable error occurs
*/
download(repo: string, options?: DownloadOptions): Promise<boolean>;
/**
* Cleans up temporary files created during downloads.
*/
cleanup(): Promise<void>;
}
/**
* Detects the current system platform and architecture as expected by eget.
* @returns System string in format 'platform/arch' (e.g., 'linux/amd64')
*/
export declare function detectSystem(): string;
/**
* Convenience function to download a GitHub repository release with automatic cleanup.
* Creates an Eget instance, downloads the specified release, and cleans up temporary files.
*
* @param repo - GitHub repository in format 'owner/repo'
* @param options - Download options
* @returns True if download succeeded, false otherwise
*
* @example
* // Download sops for current platform to current dir
* await eget('getsops/sops');
*
* @example
* // Download repo release with specific version to a custom location
* await eget('cli/cli', {
* system: 'linux/amd64',
* tag: 'v2.40.1',
* to: './bin/custom-name',
* verbose: true
* });
*
* @example
* // Download with asset filtering, put in different directory
* await eget('goreleaser/goreleaser', {
* asset: '^json', // Exclude JSON files
* extractAll: true,
* cwd: '/usr/local/eget_downloads'
* });
*/
export declare function eget(
repo: string,
options?: EgetFunctionOptions,
): Promise<boolean>;