type-git 0.0.2 → 0.1.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/README.md +33 -4
- package/dist/adapters/bun/index.cjs +421 -0
- package/dist/adapters/bun/index.cjs.map +1 -0
- package/dist/adapters/bun/index.d.cts +44 -0
- package/dist/adapters/bun/index.d.ts +38 -5
- package/dist/adapters/bun/index.js +388 -13
- package/dist/adapters/bun/index.js.map +1 -1
- package/dist/adapters/deno/index.cjs +472 -0
- package/dist/adapters/deno/index.cjs.map +1 -0
- package/dist/adapters/deno/index.d.cts +46 -0
- package/dist/adapters/deno/index.d.ts +40 -5
- package/dist/adapters/deno/index.js +439 -13
- package/dist/adapters/deno/index.js.map +1 -1
- package/dist/adapters/node/index.cjs +6254 -0
- package/dist/adapters/node/index.cjs.map +1 -0
- package/dist/{core/repo.d.ts → adapters/node/index.d.cts} +1452 -184
- package/dist/adapters/node/index.d.ts +4123 -13
- package/dist/adapters/node/index.js +6210 -119
- package/dist/adapters/node/index.js.map +1 -1
- package/dist/{core/types.d.ts → adapters-DehG3CsV.d.cts} +223 -29
- package/dist/adapters-DehG3CsV.d.ts +574 -0
- package/dist/index.cjs +6383 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +2 -0
- package/dist/index.d.ts +2 -9
- package/dist/index.js +6320 -13
- package/dist/index.js.map +1 -1
- package/package.json +13 -7
- package/dist/adapters/bun/exec.d.ts +0 -13
- package/dist/adapters/bun/exec.d.ts.map +0 -1
- package/dist/adapters/bun/exec.js +0 -242
- package/dist/adapters/bun/exec.js.map +0 -1
- package/dist/adapters/bun/fs.d.ts +0 -20
- package/dist/adapters/bun/fs.d.ts.map +0 -1
- package/dist/adapters/bun/fs.js +0 -148
- package/dist/adapters/bun/fs.js.map +0 -1
- package/dist/adapters/bun/index.d.ts.map +0 -1
- package/dist/adapters/deno/exec.d.ts +0 -14
- package/dist/adapters/deno/exec.d.ts.map +0 -1
- package/dist/adapters/deno/exec.js +0 -266
- package/dist/adapters/deno/exec.js.map +0 -1
- package/dist/adapters/deno/fs.d.ts +0 -21
- package/dist/adapters/deno/fs.d.ts.map +0 -1
- package/dist/adapters/deno/fs.js +0 -191
- package/dist/adapters/deno/fs.js.map +0 -1
- package/dist/adapters/deno/index.d.ts.map +0 -1
- package/dist/adapters/node/exec.d.ts +0 -11
- package/dist/adapters/node/exec.d.ts.map +0 -1
- package/dist/adapters/node/exec.js +0 -161
- package/dist/adapters/node/exec.js.map +0 -1
- package/dist/adapters/node/fs.d.ts +0 -18
- package/dist/adapters/node/fs.d.ts.map +0 -1
- package/dist/adapters/node/fs.js +0 -164
- package/dist/adapters/node/fs.js.map +0 -1
- package/dist/adapters/node/index.d.ts.map +0 -1
- package/dist/core/adapters.d.ts +0 -192
- package/dist/core/adapters.d.ts.map +0 -1
- package/dist/core/adapters.js +0 -10
- package/dist/core/adapters.js.map +0 -1
- package/dist/core/git.d.ts +0 -426
- package/dist/core/git.d.ts.map +0 -1
- package/dist/core/git.js +0 -5
- package/dist/core/git.js.map +0 -1
- package/dist/core/index.d.ts +0 -8
- package/dist/core/index.d.ts.map +0 -1
- package/dist/core/index.js +0 -8
- package/dist/core/index.js.map +0 -1
- package/dist/core/repo.d.ts.map +0 -1
- package/dist/core/repo.js +0 -5
- package/dist/core/repo.js.map +0 -1
- package/dist/core/types.d.ts.map +0 -1
- package/dist/core/types.js +0 -100
- package/dist/core/types.js.map +0 -1
- package/dist/impl/bare-repo-impl.d.ts +0 -91
- package/dist/impl/bare-repo-impl.d.ts.map +0 -1
- package/dist/impl/bare-repo-impl.js +0 -446
- package/dist/impl/bare-repo-impl.js.map +0 -1
- package/dist/impl/git-impl.d.ts +0 -125
- package/dist/impl/git-impl.d.ts.map +0 -1
- package/dist/impl/git-impl.js +0 -554
- package/dist/impl/git-impl.js.map +0 -1
- package/dist/impl/index.d.ts +0 -7
- package/dist/impl/index.d.ts.map +0 -1
- package/dist/impl/index.js +0 -7
- package/dist/impl/index.js.map +0 -1
- package/dist/impl/worktree-repo-impl.d.ts +0 -226
- package/dist/impl/worktree-repo-impl.d.ts.map +0 -1
- package/dist/impl/worktree-repo-impl.js +0 -3887
- package/dist/impl/worktree-repo-impl.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/parsers/index.d.ts +0 -230
- package/dist/parsers/index.d.ts.map +0 -1
- package/dist/parsers/index.js +0 -529
- package/dist/parsers/index.js.map +0 -1
- package/dist/runner/cli-runner.d.ts +0 -94
- package/dist/runner/cli-runner.d.ts.map +0 -1
- package/dist/runner/cli-runner.js +0 -315
- package/dist/runner/cli-runner.js.map +0 -1
- package/dist/runner/index.d.ts +0 -5
- package/dist/runner/index.d.ts.map +0 -1
- package/dist/runner/index.js +0 -5
- package/dist/runner/index.js.map +0 -1
|
@@ -0,0 +1,574 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Core type definitions for the type-safe Git wrapper library
|
|
3
|
+
*
|
|
4
|
+
* This module defines:
|
|
5
|
+
* - Progress events (Git and LFS)
|
|
6
|
+
* - Execution options and results
|
|
7
|
+
* - Error types and handling
|
|
8
|
+
* - Runtime capabilities
|
|
9
|
+
* - Output contracts for typed parsing
|
|
10
|
+
* - Branded types for type safety
|
|
11
|
+
*/
|
|
12
|
+
/**
|
|
13
|
+
* Brand symbol for NonEmptyString
|
|
14
|
+
* @internal
|
|
15
|
+
*/
|
|
16
|
+
declare const NonEmptyBrand: unique symbol;
|
|
17
|
+
/**
|
|
18
|
+
* A string that is guaranteed to be non-empty at the type level.
|
|
19
|
+
*
|
|
20
|
+
* Use the `nonEmpty()` helper function to create NonEmptyString values,
|
|
21
|
+
* or cast string literals directly: `'main' as NonEmptyString`
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* ```typescript
|
|
25
|
+
* // Using helper function (recommended for variables)
|
|
26
|
+
* const branch = nonEmpty(userInput);
|
|
27
|
+
* await repo.branch.create(branch);
|
|
28
|
+
*
|
|
29
|
+
* // Casting literals (safe for known values)
|
|
30
|
+
* await repo.checkout('main' as NonEmptyString);
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
type NonEmptyString = string & {
|
|
34
|
+
readonly [NonEmptyBrand]: never;
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* Validates and converts a string to NonEmptyString.
|
|
38
|
+
*
|
|
39
|
+
* @param s - The string to validate
|
|
40
|
+
* @returns The string as NonEmptyString
|
|
41
|
+
* @throws GitArgumentError if the string is empty
|
|
42
|
+
*
|
|
43
|
+
* @example
|
|
44
|
+
* ```typescript
|
|
45
|
+
* const branchName = nonEmpty('feature-branch'); // OK
|
|
46
|
+
* const invalid = nonEmpty(''); // throws GitArgumentError
|
|
47
|
+
* ```
|
|
48
|
+
*/
|
|
49
|
+
declare function nonEmpty(s: string): NonEmptyString;
|
|
50
|
+
/**
|
|
51
|
+
* Type guard to check if a string is non-empty.
|
|
52
|
+
*
|
|
53
|
+
* @param s - The string to check
|
|
54
|
+
* @returns true if the string is non-empty
|
|
55
|
+
*
|
|
56
|
+
* @example
|
|
57
|
+
* ```typescript
|
|
58
|
+
* const input = getUserInput();
|
|
59
|
+
* if (isNonEmpty(input)) {
|
|
60
|
+
* await repo.branch.create(input); // input is NonEmptyString here
|
|
61
|
+
* }
|
|
62
|
+
* ```
|
|
63
|
+
*/
|
|
64
|
+
declare function isNonEmpty(s: string): s is NonEmptyString;
|
|
65
|
+
/**
|
|
66
|
+
* Progress event for Git operations
|
|
67
|
+
*
|
|
68
|
+
* Parsed from git's stderr progress output like:
|
|
69
|
+
* - "Counting objects: 100% (10/10), done."
|
|
70
|
+
* - "Compressing objects: 100% (8/8), done."
|
|
71
|
+
*/
|
|
72
|
+
type GitProgress = {
|
|
73
|
+
/** The phase of the git operation */
|
|
74
|
+
phase: string;
|
|
75
|
+
/** Current progress value */
|
|
76
|
+
current: number;
|
|
77
|
+
/** Total value (null if unknown) */
|
|
78
|
+
total: number | null;
|
|
79
|
+
/** Percentage (null if unknown) */
|
|
80
|
+
percent: number | null;
|
|
81
|
+
/** Raw message from stderr */
|
|
82
|
+
message?: string;
|
|
83
|
+
};
|
|
84
|
+
/**
|
|
85
|
+
* Progress event for LFS operations (§7.3)
|
|
86
|
+
*
|
|
87
|
+
* Parsed from LFS stderr output when GIT_LFS_FORCE_PROGRESS=1:
|
|
88
|
+
* "Downloading LFS objects: 50% (1/2), 1.2 MB | 500 KB/s"
|
|
89
|
+
*/
|
|
90
|
+
type LfsProgress = {
|
|
91
|
+
/** Direction of the transfer */
|
|
92
|
+
direction: 'download' | 'upload' | 'checkout';
|
|
93
|
+
/** Total bytes transferred so far */
|
|
94
|
+
bytesSoFar: number;
|
|
95
|
+
/** Total bytes to transfer */
|
|
96
|
+
bytesTotal: number;
|
|
97
|
+
/** Transfer rate in bytes per second */
|
|
98
|
+
bitrate?: number;
|
|
99
|
+
/** Number of files completed */
|
|
100
|
+
filesCompleted: number;
|
|
101
|
+
/** Total number of files */
|
|
102
|
+
filesTotal: number;
|
|
103
|
+
/** Progress percentage (0-100) */
|
|
104
|
+
percent: number;
|
|
105
|
+
};
|
|
106
|
+
/**
|
|
107
|
+
* Execution options common to all Git operations
|
|
108
|
+
*/
|
|
109
|
+
type ExecOpts = {
|
|
110
|
+
/** AbortSignal for cancellation */
|
|
111
|
+
signal?: AbortSignal;
|
|
112
|
+
/** Git progress callback (for operations like fetch, push, clone) */
|
|
113
|
+
onProgress?: (progress: GitProgress) => void;
|
|
114
|
+
/** LFS progress callback (for LFS transfer operations) */
|
|
115
|
+
onLfsProgress?: (progress: LfsProgress) => void;
|
|
116
|
+
};
|
|
117
|
+
/**
|
|
118
|
+
* Result from raw Git command execution
|
|
119
|
+
*/
|
|
120
|
+
type RawResult = {
|
|
121
|
+
/** Standard output */
|
|
122
|
+
stdout: string;
|
|
123
|
+
/** Standard error */
|
|
124
|
+
stderr: string;
|
|
125
|
+
/** Exit code (0 = success) */
|
|
126
|
+
exitCode: number;
|
|
127
|
+
/** Whether the command was aborted via AbortSignal */
|
|
128
|
+
aborted: boolean;
|
|
129
|
+
};
|
|
130
|
+
/**
|
|
131
|
+
* Git error kinds
|
|
132
|
+
*/
|
|
133
|
+
type GitErrorKind =
|
|
134
|
+
/** Failed to spawn the git process */
|
|
135
|
+
'SpawnFailed'
|
|
136
|
+
/** Git exited with non-zero exit code */
|
|
137
|
+
| 'NonZeroExit'
|
|
138
|
+
/** Failed to parse git output */
|
|
139
|
+
| 'ParseError'
|
|
140
|
+
/** Command was aborted via AbortSignal */
|
|
141
|
+
| 'Aborted'
|
|
142
|
+
/** Required capability is missing (e.g., Deno permissions) */
|
|
143
|
+
| 'CapabilityMissing'
|
|
144
|
+
/** Expected a worktree repository but found bare repository */
|
|
145
|
+
| 'NotWorktreeRepo'
|
|
146
|
+
/** Expected a bare repository but found worktree repository */
|
|
147
|
+
| 'NotBareRepo'
|
|
148
|
+
/** Git version is below minimum supported version */
|
|
149
|
+
| 'UnsupportedGitVersion';
|
|
150
|
+
/**
|
|
151
|
+
* Git error category for error handling (§13.2)
|
|
152
|
+
*
|
|
153
|
+
* Categorizes errors by their nature to enable appropriate handling strategies.
|
|
154
|
+
*/
|
|
155
|
+
type GitErrorCategory =
|
|
156
|
+
/** Authentication errors (401, credential related) */
|
|
157
|
+
'auth'
|
|
158
|
+
/** Network errors (timeout, DNS resolution failure, etc.) */
|
|
159
|
+
| 'network'
|
|
160
|
+
/** Merge/rebase conflicts */
|
|
161
|
+
| 'conflict'
|
|
162
|
+
/** LFS-specific errors (storage capacity, transfer failure, etc.) */
|
|
163
|
+
| 'lfs'
|
|
164
|
+
/** Permission errors (directory access, file lock) */
|
|
165
|
+
| 'permission'
|
|
166
|
+
/** Repository corruption */
|
|
167
|
+
| 'corruption'
|
|
168
|
+
/** Unclassifiable */
|
|
169
|
+
| 'unknown';
|
|
170
|
+
/**
|
|
171
|
+
* Git error with detailed context
|
|
172
|
+
*/
|
|
173
|
+
declare class GitError extends Error {
|
|
174
|
+
readonly kind: GitErrorKind;
|
|
175
|
+
readonly context: {
|
|
176
|
+
argv?: string[];
|
|
177
|
+
workdir?: string;
|
|
178
|
+
gitDir?: string;
|
|
179
|
+
exitCode?: number;
|
|
180
|
+
stdout?: string;
|
|
181
|
+
stderr?: string;
|
|
182
|
+
};
|
|
183
|
+
readonly category: GitErrorCategory;
|
|
184
|
+
constructor(kind: GitErrorKind, message: string, context?: {
|
|
185
|
+
argv?: string[];
|
|
186
|
+
workdir?: string;
|
|
187
|
+
gitDir?: string;
|
|
188
|
+
exitCode?: number;
|
|
189
|
+
stdout?: string;
|
|
190
|
+
stderr?: string;
|
|
191
|
+
}, category?: GitErrorCategory);
|
|
192
|
+
/**
|
|
193
|
+
* Check if the error is retryable (§13.2)
|
|
194
|
+
*
|
|
195
|
+
* Network errors and some LFS errors are typically retryable.
|
|
196
|
+
*/
|
|
197
|
+
isRetryable(): boolean;
|
|
198
|
+
/**
|
|
199
|
+
* Check if authentication is needed (§13.2)
|
|
200
|
+
*/
|
|
201
|
+
needsAuthentication(): boolean;
|
|
202
|
+
}
|
|
203
|
+
/**
|
|
204
|
+
* Error thrown when an argument is invalid (e.g., empty string where non-empty is required)
|
|
205
|
+
*
|
|
206
|
+
* This error is thrown at the API boundary before the git command is executed,
|
|
207
|
+
* providing early feedback for invalid arguments.
|
|
208
|
+
*
|
|
209
|
+
* @example
|
|
210
|
+
* ```typescript
|
|
211
|
+
* try {
|
|
212
|
+
* await repo.branch.create(nonEmpty('')); // throws GitArgumentError
|
|
213
|
+
* } catch (e) {
|
|
214
|
+
* if (e instanceof GitArgumentError) {
|
|
215
|
+
* console.log('Invalid argument:', e.message);
|
|
216
|
+
* }
|
|
217
|
+
* }
|
|
218
|
+
* ```
|
|
219
|
+
*/
|
|
220
|
+
declare class GitArgumentError extends Error {
|
|
221
|
+
constructor(message: string);
|
|
222
|
+
}
|
|
223
|
+
/**
|
|
224
|
+
* Runtime identifier
|
|
225
|
+
*/
|
|
226
|
+
type Runtime = 'node' | 'deno' | 'bun';
|
|
227
|
+
/**
|
|
228
|
+
* Runtime capabilities
|
|
229
|
+
*
|
|
230
|
+
* Used to determine what features are available in the current runtime.
|
|
231
|
+
*/
|
|
232
|
+
type Capabilities = {
|
|
233
|
+
/** Whether process spawning is available */
|
|
234
|
+
canSpawnProcess: boolean;
|
|
235
|
+
/** Whether environment variables can be read */
|
|
236
|
+
canReadEnv: boolean;
|
|
237
|
+
/** Whether temporary files can be written (for LFS progress) */
|
|
238
|
+
canWriteTemp: boolean;
|
|
239
|
+
/** Whether AbortSignal is supported */
|
|
240
|
+
supportsAbortSignal: boolean;
|
|
241
|
+
/** Whether kill signals can be sent to processes */
|
|
242
|
+
supportsKillSignal: boolean;
|
|
243
|
+
/** Runtime identifier */
|
|
244
|
+
runtime: Runtime;
|
|
245
|
+
/** Git version (if detected) */
|
|
246
|
+
gitVersion?: string;
|
|
247
|
+
/** Git LFS version (if detected) */
|
|
248
|
+
lfsVersion?: string;
|
|
249
|
+
};
|
|
250
|
+
/**
|
|
251
|
+
* LFS mode configuration
|
|
252
|
+
*/
|
|
253
|
+
type LfsMode = 'enabled' | 'disabled' | {
|
|
254
|
+
/** Skip smudge filter (don't download LFS files on checkout) */
|
|
255
|
+
skipSmudge?: boolean;
|
|
256
|
+
/** Skip download (keep pointer files) */
|
|
257
|
+
skipDownload?: boolean;
|
|
258
|
+
};
|
|
259
|
+
/**
|
|
260
|
+
* Output contract types for typed API
|
|
261
|
+
*
|
|
262
|
+
* Typed API only supports commands with predictable output formats.
|
|
263
|
+
*/
|
|
264
|
+
type OutputContract =
|
|
265
|
+
/** Raw output - no parsing */
|
|
266
|
+
{
|
|
267
|
+
type: 'raw';
|
|
268
|
+
}
|
|
269
|
+
/** Porcelain format (v1 or v2) */
|
|
270
|
+
| {
|
|
271
|
+
type: 'porcelain';
|
|
272
|
+
version: 1 | 2;
|
|
273
|
+
}
|
|
274
|
+
/** JSON output */
|
|
275
|
+
| {
|
|
276
|
+
type: 'json';
|
|
277
|
+
}
|
|
278
|
+
/** Custom format with a specific delimiter */
|
|
279
|
+
| {
|
|
280
|
+
type: 'delimited';
|
|
281
|
+
delimiter: string;
|
|
282
|
+
nullTerminated?: boolean;
|
|
283
|
+
}
|
|
284
|
+
/** Custom pretty format for git log */
|
|
285
|
+
| {
|
|
286
|
+
type: 'pretty';
|
|
287
|
+
format: string;
|
|
288
|
+
};
|
|
289
|
+
/**
|
|
290
|
+
* Command specification for typed API
|
|
291
|
+
*/
|
|
292
|
+
type CommandSpec<TOptions, TResult> = {
|
|
293
|
+
/** Command name (e.g., "status", "log") */
|
|
294
|
+
name: string;
|
|
295
|
+
/** Subcommands (e.g., ["lfs", "pull"]) */
|
|
296
|
+
subcommands?: string[];
|
|
297
|
+
/** Build argv from options */
|
|
298
|
+
buildArgs: (options: TOptions) => string[];
|
|
299
|
+
/** Output contract */
|
|
300
|
+
outputContract: OutputContract;
|
|
301
|
+
/** Parse stdout/stderr to result */
|
|
302
|
+
parse: (stdout: string, stderr: string) => TResult;
|
|
303
|
+
};
|
|
304
|
+
/**
|
|
305
|
+
* Execution context for git commands
|
|
306
|
+
*
|
|
307
|
+
* Determines how git commands are executed:
|
|
308
|
+
* - Worktree: `git -C <workdir> <command>`
|
|
309
|
+
* - Bare: `git --git-dir=<gitDir> <command>`
|
|
310
|
+
*/
|
|
311
|
+
type ExecutionContext = {
|
|
312
|
+
type: 'global';
|
|
313
|
+
} | {
|
|
314
|
+
type: 'worktree';
|
|
315
|
+
workdir: string;
|
|
316
|
+
} | {
|
|
317
|
+
type: 'bare';
|
|
318
|
+
gitDir: string;
|
|
319
|
+
};
|
|
320
|
+
/**
|
|
321
|
+
* Options for opening a repository with environment isolation (§6.3)
|
|
322
|
+
*
|
|
323
|
+
* Provides declarative environment configuration for Git operations.
|
|
324
|
+
*/
|
|
325
|
+
type GitOpenOptions = {
|
|
326
|
+
/** Custom HOME directory (~/.gitconfig source) */
|
|
327
|
+
home?: string;
|
|
328
|
+
/** Ignore system config (--config-env=GIT_CONFIG_GLOBAL=/dev/null equivalent) */
|
|
329
|
+
ignoreSystemConfig?: boolean;
|
|
330
|
+
/** Custom credential helper */
|
|
331
|
+
credentialHelper?: string;
|
|
332
|
+
/** Additional environment variables */
|
|
333
|
+
env?: Record<string, string>;
|
|
334
|
+
/** Directories to prepend to PATH */
|
|
335
|
+
pathPrefix?: string[];
|
|
336
|
+
/** Credential configuration (§6.4) */
|
|
337
|
+
credential?: CredentialConfig;
|
|
338
|
+
/** LFS mode configuration */
|
|
339
|
+
lfs?: LfsMode;
|
|
340
|
+
};
|
|
341
|
+
/**
|
|
342
|
+
* Credential request information
|
|
343
|
+
*/
|
|
344
|
+
type CredentialRequest = {
|
|
345
|
+
protocol: 'https' | 'ssh';
|
|
346
|
+
host: string;
|
|
347
|
+
path?: string;
|
|
348
|
+
};
|
|
349
|
+
/**
|
|
350
|
+
* Credential response
|
|
351
|
+
*/
|
|
352
|
+
type Credential = {
|
|
353
|
+
username: string;
|
|
354
|
+
password: string;
|
|
355
|
+
};
|
|
356
|
+
/**
|
|
357
|
+
* Credential configuration for Git authentication (§6.4)
|
|
358
|
+
*
|
|
359
|
+
* Supports multiple authentication methods:
|
|
360
|
+
* 1. Built-in helper (store, cache, manager-core)
|
|
361
|
+
* 2. Custom helper binary
|
|
362
|
+
* 3. Programmatic authentication (recommended)
|
|
363
|
+
* 4. Static credentials (dev/test only)
|
|
364
|
+
*/
|
|
365
|
+
type CredentialConfig = {
|
|
366
|
+
/** Method 1: Built-in helper name */
|
|
367
|
+
helper?: 'store' | 'cache' | 'manager-core' | string;
|
|
368
|
+
/** Method 2: Custom helper binary path */
|
|
369
|
+
helperPath?: string;
|
|
370
|
+
/** Method 3: Programmatic authentication provider (recommended) */
|
|
371
|
+
provider?: (request: CredentialRequest) => Promise<Credential>;
|
|
372
|
+
/** Method 4: Static credentials (dev/test only) */
|
|
373
|
+
username?: string;
|
|
374
|
+
password?: string;
|
|
375
|
+
token?: string;
|
|
376
|
+
/** Fallback credential configuration */
|
|
377
|
+
fallback?: CredentialConfig;
|
|
378
|
+
/** Callback when authentication fails */
|
|
379
|
+
onAuthFailure?: (error: Error, request: CredentialRequest) => void;
|
|
380
|
+
};
|
|
381
|
+
|
|
382
|
+
/**
|
|
383
|
+
* Runtime adapter interfaces for cross-platform support (Node/Deno/Bun)
|
|
384
|
+
*
|
|
385
|
+
* This module defines:
|
|
386
|
+
* - ExecAdapter: Process execution abstraction (#15)
|
|
387
|
+
* - FsAdapter: Filesystem operations abstraction (#16)
|
|
388
|
+
* - Related types and options
|
|
389
|
+
*/
|
|
390
|
+
|
|
391
|
+
/**
|
|
392
|
+
* Options for spawning a process
|
|
393
|
+
*/
|
|
394
|
+
type SpawnOptions = {
|
|
395
|
+
/** Command and arguments (first element is the command) */
|
|
396
|
+
argv: string[];
|
|
397
|
+
/** Additional environment variables */
|
|
398
|
+
env?: Record<string, string>;
|
|
399
|
+
/** Working directory */
|
|
400
|
+
cwd?: string;
|
|
401
|
+
/** AbortSignal for cancellation */
|
|
402
|
+
signal?: AbortSignal;
|
|
403
|
+
/** Kill signal to use when aborting (default: SIGTERM) */
|
|
404
|
+
killSignal?: 'SIGTERM' | 'SIGKILL';
|
|
405
|
+
};
|
|
406
|
+
/**
|
|
407
|
+
* Result from spawning a process
|
|
408
|
+
*/
|
|
409
|
+
type SpawnResult = {
|
|
410
|
+
/** Standard output */
|
|
411
|
+
stdout: string;
|
|
412
|
+
/** Standard error */
|
|
413
|
+
stderr: string;
|
|
414
|
+
/** Exit code (-1 if unknown) */
|
|
415
|
+
exitCode: number;
|
|
416
|
+
/** Signal that terminated the process (if any) */
|
|
417
|
+
signal?: string;
|
|
418
|
+
/** Whether the process was aborted via AbortSignal */
|
|
419
|
+
aborted: boolean;
|
|
420
|
+
};
|
|
421
|
+
/**
|
|
422
|
+
* Stream handler for incremental output
|
|
423
|
+
*
|
|
424
|
+
* Used for progress tracking and real-time output processing.
|
|
425
|
+
*/
|
|
426
|
+
type StreamHandler = {
|
|
427
|
+
/** Called when stdout data is received */
|
|
428
|
+
onStdout?: (chunk: string) => void;
|
|
429
|
+
/** Called when stderr data is received */
|
|
430
|
+
onStderr?: (chunk: string) => void;
|
|
431
|
+
};
|
|
432
|
+
/**
|
|
433
|
+
* Handle to a spawned process
|
|
434
|
+
*
|
|
435
|
+
* Allows streaming output and waiting for completion.
|
|
436
|
+
*/
|
|
437
|
+
interface SpawnHandle {
|
|
438
|
+
/** Async iterator for stdout lines */
|
|
439
|
+
readonly stdout: AsyncIterable<string>;
|
|
440
|
+
/** Async iterator for stderr lines */
|
|
441
|
+
readonly stderr: AsyncIterable<string>;
|
|
442
|
+
/** Wait for process completion */
|
|
443
|
+
wait(): Promise<SpawnResult>;
|
|
444
|
+
/** Kill the process */
|
|
445
|
+
kill(signal?: 'SIGTERM' | 'SIGKILL'): void;
|
|
446
|
+
}
|
|
447
|
+
/**
|
|
448
|
+
* Adapter interface for process execution
|
|
449
|
+
*
|
|
450
|
+
* Abstracts process spawning across Node.js, Deno, and Bun.
|
|
451
|
+
*/
|
|
452
|
+
interface ExecAdapter {
|
|
453
|
+
/**
|
|
454
|
+
* Get the capabilities of this runtime
|
|
455
|
+
*/
|
|
456
|
+
getCapabilities(): Capabilities;
|
|
457
|
+
/**
|
|
458
|
+
* Spawn a process and wait for completion
|
|
459
|
+
*
|
|
460
|
+
* @param options - Spawn options
|
|
461
|
+
* @param handlers - Optional stream handlers for real-time output
|
|
462
|
+
* @returns Promise resolving to spawn result
|
|
463
|
+
*/
|
|
464
|
+
spawn(options: SpawnOptions, handlers?: StreamHandler): Promise<SpawnResult>;
|
|
465
|
+
/**
|
|
466
|
+
* Spawn a process with streaming support
|
|
467
|
+
*
|
|
468
|
+
* @param options - Spawn options
|
|
469
|
+
* @returns Handle to the spawned process
|
|
470
|
+
*/
|
|
471
|
+
spawnStreaming?(options: SpawnOptions): SpawnHandle;
|
|
472
|
+
}
|
|
473
|
+
/**
|
|
474
|
+
* Options for tailing a file
|
|
475
|
+
*/
|
|
476
|
+
type TailOptions = {
|
|
477
|
+
/** Path to the file to tail */
|
|
478
|
+
filePath: string;
|
|
479
|
+
/** AbortSignal for cancellation */
|
|
480
|
+
signal?: AbortSignal;
|
|
481
|
+
/** Callback for each new line */
|
|
482
|
+
onLine: (line: string) => void;
|
|
483
|
+
/** Start offset in bytes (default: 0) */
|
|
484
|
+
startOffset?: number;
|
|
485
|
+
/** Polling interval in milliseconds (default: 100) */
|
|
486
|
+
pollInterval?: number;
|
|
487
|
+
};
|
|
488
|
+
/**
|
|
489
|
+
* Handle to a tail operation
|
|
490
|
+
*/
|
|
491
|
+
interface TailHandle {
|
|
492
|
+
/** Async iterator for new lines */
|
|
493
|
+
readonly lines: AsyncIterable<string>;
|
|
494
|
+
/** Stop tailing */
|
|
495
|
+
stop(): void;
|
|
496
|
+
}
|
|
497
|
+
/**
|
|
498
|
+
* Adapter interface for filesystem operations
|
|
499
|
+
*
|
|
500
|
+
* Used primarily for LFS progress tracking via GIT_LFS_PROGRESS.
|
|
501
|
+
*/
|
|
502
|
+
interface FsAdapter {
|
|
503
|
+
/**
|
|
504
|
+
* Create a temporary file and return its path
|
|
505
|
+
*
|
|
506
|
+
* @param prefix - Optional prefix for the temp file name
|
|
507
|
+
* @returns Path to the created temporary file
|
|
508
|
+
*/
|
|
509
|
+
createTempFile(prefix?: string): Promise<string>;
|
|
510
|
+
/**
|
|
511
|
+
* Start tailing a file (watching for new lines)
|
|
512
|
+
*
|
|
513
|
+
* @param options - Tail options
|
|
514
|
+
* @returns Promise that resolves when tailing stops
|
|
515
|
+
*/
|
|
516
|
+
tail(options: TailOptions): Promise<void>;
|
|
517
|
+
/**
|
|
518
|
+
* Start tailing a file with streaming support
|
|
519
|
+
*
|
|
520
|
+
* @param filePath - Path to the file to tail
|
|
521
|
+
* @param options - Optional tail options
|
|
522
|
+
* @returns Handle to the tail operation
|
|
523
|
+
*/
|
|
524
|
+
tailStreaming?(filePath: string, options?: {
|
|
525
|
+
signal?: AbortSignal;
|
|
526
|
+
pollInterval?: number;
|
|
527
|
+
}): TailHandle;
|
|
528
|
+
/**
|
|
529
|
+
* Delete a file
|
|
530
|
+
*
|
|
531
|
+
* @param filePath - Path to the file to delete
|
|
532
|
+
*/
|
|
533
|
+
deleteFile(filePath: string): Promise<void>;
|
|
534
|
+
/**
|
|
535
|
+
* Delete a directory recursively
|
|
536
|
+
*
|
|
537
|
+
* @param dirPath - Path to the directory to delete
|
|
538
|
+
*/
|
|
539
|
+
deleteDirectory(dirPath: string): Promise<void>;
|
|
540
|
+
/**
|
|
541
|
+
* Check if a file exists
|
|
542
|
+
*
|
|
543
|
+
* @param filePath - Path to check
|
|
544
|
+
* @returns Whether the file exists
|
|
545
|
+
*/
|
|
546
|
+
exists(filePath: string): Promise<boolean>;
|
|
547
|
+
/**
|
|
548
|
+
* Read a file's contents
|
|
549
|
+
*
|
|
550
|
+
* @param filePath - Path to the file
|
|
551
|
+
* @returns File contents as string
|
|
552
|
+
*/
|
|
553
|
+
readFile?(filePath: string): Promise<string>;
|
|
554
|
+
/**
|
|
555
|
+
* Write contents to a file
|
|
556
|
+
*
|
|
557
|
+
* @param filePath - Path to the file
|
|
558
|
+
* @param contents - Contents to write
|
|
559
|
+
*/
|
|
560
|
+
writeFile?(filePath: string, contents: string): Promise<void>;
|
|
561
|
+
}
|
|
562
|
+
/**
|
|
563
|
+
* Combined adapters for a runtime
|
|
564
|
+
*/
|
|
565
|
+
interface RuntimeAdapters {
|
|
566
|
+
exec: ExecAdapter;
|
|
567
|
+
fs: FsAdapter;
|
|
568
|
+
}
|
|
569
|
+
/**
|
|
570
|
+
* Factory function type for creating runtime adapters
|
|
571
|
+
*/
|
|
572
|
+
type AdapterFactory = () => RuntimeAdapters;
|
|
573
|
+
|
|
574
|
+
export { type AdapterFactory as A, type Capabilities as C, type ExecAdapter as E, type FsAdapter as F, type GitErrorCategory as G, type LfsMode as L, type NonEmptyString as N, type OutputContract as O, type RuntimeAdapters as R, type SpawnOptions as S, type TailOptions as T, type StreamHandler as a, type SpawnResult as b, type SpawnHandle as c, type TailHandle as d, type ExecOpts as e, type RawResult as f, type GitProgress as g, type GitOpenOptions as h, type ExecutionContext as i, GitError as j, isNonEmpty as k, type LfsProgress as l, type GitErrorKind as m, nonEmpty as n, GitArgumentError as o, type Runtime as p, type CommandSpec as q, type CredentialRequest as r, type Credential as s, type CredentialConfig as t };
|