@optique/git 0.9.0-dev.1
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/LICENSE +20 -0
- package/README.md +272 -0
- package/dist/index.cjs +553 -0
- package/dist/index.d.cts +215 -0
- package/dist/index.d.ts +215 -0
- package/dist/index.js +489 -0
- package/package.json +76 -0
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
import { ValueParser } from "@optique/core/valueparser";
|
|
2
|
+
import { NonEmptyString } from "@optique/core/nonempty";
|
|
3
|
+
import { expandOid, listBranches, listRemotes, listTags, readObject, resolveRef } from "isomorphic-git";
|
|
4
|
+
|
|
5
|
+
//#region src/index.d.ts
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Interface for FileSystem operations required by git parsers.
|
|
9
|
+
* This allows custom filesystem implementations for different environments.
|
|
10
|
+
*
|
|
11
|
+
* @since 0.9.0
|
|
12
|
+
*/
|
|
13
|
+
interface FileSystem {
|
|
14
|
+
readFile(path: string): Promise<Uint8Array | string>;
|
|
15
|
+
writeFile(path: string, data: Uint8Array | string): Promise<void>;
|
|
16
|
+
mkdir(path: string, options?: {
|
|
17
|
+
recursive?: boolean;
|
|
18
|
+
}): Promise<void>;
|
|
19
|
+
rmdir(path: string, options?: {
|
|
20
|
+
recursive?: boolean;
|
|
21
|
+
}): Promise<void>;
|
|
22
|
+
unlink(path: string): Promise<void>;
|
|
23
|
+
readdir(path: string): Promise<string[]>;
|
|
24
|
+
lstat(path: string): Promise<{
|
|
25
|
+
isSymbolicLink(): boolean;
|
|
26
|
+
isDirectory(): boolean;
|
|
27
|
+
isFile(): boolean;
|
|
28
|
+
}>;
|
|
29
|
+
stat(path: string): Promise<{
|
|
30
|
+
isSymbolicLink(): boolean;
|
|
31
|
+
isDirectory(): boolean;
|
|
32
|
+
isFile(): boolean;
|
|
33
|
+
}>;
|
|
34
|
+
readlink(path: string): Promise<string>;
|
|
35
|
+
symlink(target: string, path: string): Promise<void>;
|
|
36
|
+
chmod(path: string, mode: number): Promise<void>;
|
|
37
|
+
chown(path: string, uid: number, gid: number): Promise<void>;
|
|
38
|
+
rename(oldPath: string, newPath: string): Promise<void>;
|
|
39
|
+
copyFile(srcPath: string, destPath: string): Promise<void>;
|
|
40
|
+
exists(path: string): Promise<boolean>;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Options for creating git value parsers.
|
|
44
|
+
*
|
|
45
|
+
* @since 0.9.0
|
|
46
|
+
*/
|
|
47
|
+
interface GitParserOptions {
|
|
48
|
+
/**
|
|
49
|
+
* The filesystem implementation to use.
|
|
50
|
+
* Defaults to node:fs/promises (works in Deno and Node.js).
|
|
51
|
+
*/
|
|
52
|
+
fs?: FileSystem;
|
|
53
|
+
/**
|
|
54
|
+
* The directory of the git repository.
|
|
55
|
+
* Defaults to the current working directory.
|
|
56
|
+
*/
|
|
57
|
+
dir?: string;
|
|
58
|
+
/**
|
|
59
|
+
* The metavar name for this parser.
|
|
60
|
+
* Used in help messages to indicate what kind of value this parser expects.
|
|
61
|
+
*/
|
|
62
|
+
metavar?: NonEmptyString;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Git parsers factory interface.
|
|
66
|
+
*
|
|
67
|
+
* @since 0.9.0
|
|
68
|
+
*/
|
|
69
|
+
interface GitParsers {
|
|
70
|
+
branch(options?: GitParserOptions): ValueParser<"async", string>;
|
|
71
|
+
remoteBranch(remote: string, options?: GitParserOptions): ValueParser<"async", string>;
|
|
72
|
+
tag(options?: GitParserOptions): ValueParser<"async", string>;
|
|
73
|
+
remote(options?: GitParserOptions): ValueParser<"async", string>;
|
|
74
|
+
commit(options?: GitParserOptions): ValueParser<"async", string>;
|
|
75
|
+
ref(options?: GitParserOptions): ValueParser<"async", string>;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Creates a value parser that validates local branch names.
|
|
79
|
+
*
|
|
80
|
+
* This parser uses isomorphic-git to verify that the provided input
|
|
81
|
+
* matches an existing branch in the repository.
|
|
82
|
+
*
|
|
83
|
+
* @param options Configuration options for the parser.
|
|
84
|
+
* @returns A value parser that accepts existing branch names.
|
|
85
|
+
* @since 0.9.0
|
|
86
|
+
*
|
|
87
|
+
* @example
|
|
88
|
+
* ~~~~ typescript
|
|
89
|
+
* import { gitBranch } from "@optique/git";
|
|
90
|
+
* import { argument } from "@optique/core/primitives";
|
|
91
|
+
*
|
|
92
|
+
* const parser = argument(gitBranch());
|
|
93
|
+
* ~~~~
|
|
94
|
+
*/
|
|
95
|
+
declare function gitBranch(options?: GitParserOptions): ValueParser<"async", string>;
|
|
96
|
+
/**
|
|
97
|
+
* Creates a value parser that validates remote branch names.
|
|
98
|
+
*
|
|
99
|
+
* This parser uses isomorphic-git to verify that the provided input
|
|
100
|
+
* matches an existing branch on the specified remote.
|
|
101
|
+
*
|
|
102
|
+
* @param remote The remote name to validate against.
|
|
103
|
+
* @param options Configuration options for the parser.
|
|
104
|
+
* @returns A value parser that accepts existing remote branch names.
|
|
105
|
+
* @since 0.9.0
|
|
106
|
+
*
|
|
107
|
+
* @example
|
|
108
|
+
* ~~~~ typescript
|
|
109
|
+
* import { gitRemoteBranch } from "@optique/git";
|
|
110
|
+
* import { option } from "@optique/core/primitives";
|
|
111
|
+
*
|
|
112
|
+
* const parser = option("-b", "--branch", gitRemoteBranch("origin"));
|
|
113
|
+
* ~~~~
|
|
114
|
+
*/
|
|
115
|
+
declare function gitRemoteBranch(remote: string, options?: GitParserOptions): ValueParser<"async", string>;
|
|
116
|
+
/**
|
|
117
|
+
* Creates a value parser that validates tag names.
|
|
118
|
+
*
|
|
119
|
+
* This parser uses isomorphic-git to verify that the provided input
|
|
120
|
+
* matches an existing tag in the repository.
|
|
121
|
+
*
|
|
122
|
+
* @param options Configuration options for the parser.
|
|
123
|
+
* @returns A value parser that accepts existing tag names.
|
|
124
|
+
* @since 0.9.0
|
|
125
|
+
*
|
|
126
|
+
* @example
|
|
127
|
+
* ~~~~ typescript
|
|
128
|
+
* import { gitTag } from "@optique/git";
|
|
129
|
+
* import { option } from "@optique/core/primitives";
|
|
130
|
+
*
|
|
131
|
+
* const parser = option("-t", "--tag", gitTag());
|
|
132
|
+
* ~~~~
|
|
133
|
+
*/
|
|
134
|
+
declare function gitTag(options?: GitParserOptions): ValueParser<"async", string>;
|
|
135
|
+
/**
|
|
136
|
+
* Creates a value parser that validates remote names.
|
|
137
|
+
*
|
|
138
|
+
* This parser uses isomorphic-git to verify that the provided input
|
|
139
|
+
* matches an existing remote in the repository.
|
|
140
|
+
*
|
|
141
|
+
* @param options Configuration options for the parser.
|
|
142
|
+
* @returns A value parser that accepts existing remote names.
|
|
143
|
+
* @since 0.9.0
|
|
144
|
+
*
|
|
145
|
+
* @example
|
|
146
|
+
* ~~~~ typescript
|
|
147
|
+
* import { gitRemote } from "@optique/git";
|
|
148
|
+
* import { option } from "@optique/core/primitives";
|
|
149
|
+
*
|
|
150
|
+
* const parser = option("-r", "--remote", gitRemote());
|
|
151
|
+
* ~~~~
|
|
152
|
+
*/
|
|
153
|
+
declare function gitRemote(options?: GitParserOptions): ValueParser<"async", string>;
|
|
154
|
+
/**
|
|
155
|
+
* Creates a value parser that validates commit SHAs.
|
|
156
|
+
*
|
|
157
|
+
* This parser uses isomorphic-git to verify that the provided input
|
|
158
|
+
* is a valid commit SHA (full or shortened) that exists in the repository.
|
|
159
|
+
*
|
|
160
|
+
* @param options Configuration options for the parser.
|
|
161
|
+
* @returns A value parser that accepts valid commit SHAs.
|
|
162
|
+
* @since 0.9.0
|
|
163
|
+
*
|
|
164
|
+
* @example
|
|
165
|
+
* ~~~~ typescript
|
|
166
|
+
* import { gitCommit } from "@optique/git";
|
|
167
|
+
* import { option } from "@optique/core/primitives";
|
|
168
|
+
*
|
|
169
|
+
* const parser = option("-c", "--commit", gitCommit());
|
|
170
|
+
* ~~~~
|
|
171
|
+
*/
|
|
172
|
+
declare function gitCommit(options?: GitParserOptions): ValueParser<"async", string>;
|
|
173
|
+
/**
|
|
174
|
+
* Creates a value parser that validates any git reference
|
|
175
|
+
* (branches, tags, or commits).
|
|
176
|
+
*
|
|
177
|
+
* This parser uses isomorphic-git to verify that the provided input
|
|
178
|
+
* resolves to a valid git reference (branch, tag, or commit SHA).
|
|
179
|
+
*
|
|
180
|
+
* @param options Configuration options for the parser.
|
|
181
|
+
* @returns A value parser that accepts branches, tags, or commit SHAs.
|
|
182
|
+
* @since 0.9.0
|
|
183
|
+
*
|
|
184
|
+
* @example
|
|
185
|
+
* ~~~~ typescript
|
|
186
|
+
* import { gitRef } from "@optique/git";
|
|
187
|
+
* import { option } from "@optique/core/primitives";
|
|
188
|
+
*
|
|
189
|
+
* const parser = option("--ref", gitRef());
|
|
190
|
+
* ~~~~
|
|
191
|
+
*/
|
|
192
|
+
declare function gitRef(options?: GitParserOptions): ValueParser<"async", string>;
|
|
193
|
+
/**
|
|
194
|
+
* Creates a factory for git parsers with shared configuration.
|
|
195
|
+
*
|
|
196
|
+
* This function returns an object with methods for creating individual git
|
|
197
|
+
* parsers that share the same configuration (filesystem and directory).
|
|
198
|
+
*
|
|
199
|
+
* @param options Shared configuration options for all parsers.
|
|
200
|
+
* @returns An object with methods for creating individual git parsers.
|
|
201
|
+
* @since 0.9.0
|
|
202
|
+
*
|
|
203
|
+
* @example
|
|
204
|
+
* ~~~~ typescript
|
|
205
|
+
* import { createGitParsers } from "@optique/git";
|
|
206
|
+
*
|
|
207
|
+
* const git = createGitParsers({ dir: "/path/to/repo" });
|
|
208
|
+
*
|
|
209
|
+
* const branchParser = git.branch();
|
|
210
|
+
* const tagParser = git.tag();
|
|
211
|
+
* ~~~~
|
|
212
|
+
*/
|
|
213
|
+
declare function createGitParsers(options?: GitParserOptions): GitParsers;
|
|
214
|
+
//#endregion
|
|
215
|
+
export { FileSystem, GitParserOptions, GitParsers, createGitParsers, expandOid, gitBranch, gitCommit, gitRef, gitRemote, gitRemoteBranch, gitTag, listBranches, listRemotes, listTags, readObject, resolveRef };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
import { NonEmptyString } from "@optique/core/nonempty";
|
|
2
|
+
import { expandOid, listBranches, listRemotes, listTags, readObject, resolveRef } from "isomorphic-git";
|
|
3
|
+
import { ValueParser } from "@optique/core/valueparser";
|
|
4
|
+
|
|
5
|
+
//#region src/index.d.ts
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Interface for FileSystem operations required by git parsers.
|
|
9
|
+
* This allows custom filesystem implementations for different environments.
|
|
10
|
+
*
|
|
11
|
+
* @since 0.9.0
|
|
12
|
+
*/
|
|
13
|
+
interface FileSystem {
|
|
14
|
+
readFile(path: string): Promise<Uint8Array | string>;
|
|
15
|
+
writeFile(path: string, data: Uint8Array | string): Promise<void>;
|
|
16
|
+
mkdir(path: string, options?: {
|
|
17
|
+
recursive?: boolean;
|
|
18
|
+
}): Promise<void>;
|
|
19
|
+
rmdir(path: string, options?: {
|
|
20
|
+
recursive?: boolean;
|
|
21
|
+
}): Promise<void>;
|
|
22
|
+
unlink(path: string): Promise<void>;
|
|
23
|
+
readdir(path: string): Promise<string[]>;
|
|
24
|
+
lstat(path: string): Promise<{
|
|
25
|
+
isSymbolicLink(): boolean;
|
|
26
|
+
isDirectory(): boolean;
|
|
27
|
+
isFile(): boolean;
|
|
28
|
+
}>;
|
|
29
|
+
stat(path: string): Promise<{
|
|
30
|
+
isSymbolicLink(): boolean;
|
|
31
|
+
isDirectory(): boolean;
|
|
32
|
+
isFile(): boolean;
|
|
33
|
+
}>;
|
|
34
|
+
readlink(path: string): Promise<string>;
|
|
35
|
+
symlink(target: string, path: string): Promise<void>;
|
|
36
|
+
chmod(path: string, mode: number): Promise<void>;
|
|
37
|
+
chown(path: string, uid: number, gid: number): Promise<void>;
|
|
38
|
+
rename(oldPath: string, newPath: string): Promise<void>;
|
|
39
|
+
copyFile(srcPath: string, destPath: string): Promise<void>;
|
|
40
|
+
exists(path: string): Promise<boolean>;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Options for creating git value parsers.
|
|
44
|
+
*
|
|
45
|
+
* @since 0.9.0
|
|
46
|
+
*/
|
|
47
|
+
interface GitParserOptions {
|
|
48
|
+
/**
|
|
49
|
+
* The filesystem implementation to use.
|
|
50
|
+
* Defaults to node:fs/promises (works in Deno and Node.js).
|
|
51
|
+
*/
|
|
52
|
+
fs?: FileSystem;
|
|
53
|
+
/**
|
|
54
|
+
* The directory of the git repository.
|
|
55
|
+
* Defaults to the current working directory.
|
|
56
|
+
*/
|
|
57
|
+
dir?: string;
|
|
58
|
+
/**
|
|
59
|
+
* The metavar name for this parser.
|
|
60
|
+
* Used in help messages to indicate what kind of value this parser expects.
|
|
61
|
+
*/
|
|
62
|
+
metavar?: NonEmptyString;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Git parsers factory interface.
|
|
66
|
+
*
|
|
67
|
+
* @since 0.9.0
|
|
68
|
+
*/
|
|
69
|
+
interface GitParsers {
|
|
70
|
+
branch(options?: GitParserOptions): ValueParser<"async", string>;
|
|
71
|
+
remoteBranch(remote: string, options?: GitParserOptions): ValueParser<"async", string>;
|
|
72
|
+
tag(options?: GitParserOptions): ValueParser<"async", string>;
|
|
73
|
+
remote(options?: GitParserOptions): ValueParser<"async", string>;
|
|
74
|
+
commit(options?: GitParserOptions): ValueParser<"async", string>;
|
|
75
|
+
ref(options?: GitParserOptions): ValueParser<"async", string>;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Creates a value parser that validates local branch names.
|
|
79
|
+
*
|
|
80
|
+
* This parser uses isomorphic-git to verify that the provided input
|
|
81
|
+
* matches an existing branch in the repository.
|
|
82
|
+
*
|
|
83
|
+
* @param options Configuration options for the parser.
|
|
84
|
+
* @returns A value parser that accepts existing branch names.
|
|
85
|
+
* @since 0.9.0
|
|
86
|
+
*
|
|
87
|
+
* @example
|
|
88
|
+
* ~~~~ typescript
|
|
89
|
+
* import { gitBranch } from "@optique/git";
|
|
90
|
+
* import { argument } from "@optique/core/primitives";
|
|
91
|
+
*
|
|
92
|
+
* const parser = argument(gitBranch());
|
|
93
|
+
* ~~~~
|
|
94
|
+
*/
|
|
95
|
+
declare function gitBranch(options?: GitParserOptions): ValueParser<"async", string>;
|
|
96
|
+
/**
|
|
97
|
+
* Creates a value parser that validates remote branch names.
|
|
98
|
+
*
|
|
99
|
+
* This parser uses isomorphic-git to verify that the provided input
|
|
100
|
+
* matches an existing branch on the specified remote.
|
|
101
|
+
*
|
|
102
|
+
* @param remote The remote name to validate against.
|
|
103
|
+
* @param options Configuration options for the parser.
|
|
104
|
+
* @returns A value parser that accepts existing remote branch names.
|
|
105
|
+
* @since 0.9.0
|
|
106
|
+
*
|
|
107
|
+
* @example
|
|
108
|
+
* ~~~~ typescript
|
|
109
|
+
* import { gitRemoteBranch } from "@optique/git";
|
|
110
|
+
* import { option } from "@optique/core/primitives";
|
|
111
|
+
*
|
|
112
|
+
* const parser = option("-b", "--branch", gitRemoteBranch("origin"));
|
|
113
|
+
* ~~~~
|
|
114
|
+
*/
|
|
115
|
+
declare function gitRemoteBranch(remote: string, options?: GitParserOptions): ValueParser<"async", string>;
|
|
116
|
+
/**
|
|
117
|
+
* Creates a value parser that validates tag names.
|
|
118
|
+
*
|
|
119
|
+
* This parser uses isomorphic-git to verify that the provided input
|
|
120
|
+
* matches an existing tag in the repository.
|
|
121
|
+
*
|
|
122
|
+
* @param options Configuration options for the parser.
|
|
123
|
+
* @returns A value parser that accepts existing tag names.
|
|
124
|
+
* @since 0.9.0
|
|
125
|
+
*
|
|
126
|
+
* @example
|
|
127
|
+
* ~~~~ typescript
|
|
128
|
+
* import { gitTag } from "@optique/git";
|
|
129
|
+
* import { option } from "@optique/core/primitives";
|
|
130
|
+
*
|
|
131
|
+
* const parser = option("-t", "--tag", gitTag());
|
|
132
|
+
* ~~~~
|
|
133
|
+
*/
|
|
134
|
+
declare function gitTag(options?: GitParserOptions): ValueParser<"async", string>;
|
|
135
|
+
/**
|
|
136
|
+
* Creates a value parser that validates remote names.
|
|
137
|
+
*
|
|
138
|
+
* This parser uses isomorphic-git to verify that the provided input
|
|
139
|
+
* matches an existing remote in the repository.
|
|
140
|
+
*
|
|
141
|
+
* @param options Configuration options for the parser.
|
|
142
|
+
* @returns A value parser that accepts existing remote names.
|
|
143
|
+
* @since 0.9.0
|
|
144
|
+
*
|
|
145
|
+
* @example
|
|
146
|
+
* ~~~~ typescript
|
|
147
|
+
* import { gitRemote } from "@optique/git";
|
|
148
|
+
* import { option } from "@optique/core/primitives";
|
|
149
|
+
*
|
|
150
|
+
* const parser = option("-r", "--remote", gitRemote());
|
|
151
|
+
* ~~~~
|
|
152
|
+
*/
|
|
153
|
+
declare function gitRemote(options?: GitParserOptions): ValueParser<"async", string>;
|
|
154
|
+
/**
|
|
155
|
+
* Creates a value parser that validates commit SHAs.
|
|
156
|
+
*
|
|
157
|
+
* This parser uses isomorphic-git to verify that the provided input
|
|
158
|
+
* is a valid commit SHA (full or shortened) that exists in the repository.
|
|
159
|
+
*
|
|
160
|
+
* @param options Configuration options for the parser.
|
|
161
|
+
* @returns A value parser that accepts valid commit SHAs.
|
|
162
|
+
* @since 0.9.0
|
|
163
|
+
*
|
|
164
|
+
* @example
|
|
165
|
+
* ~~~~ typescript
|
|
166
|
+
* import { gitCommit } from "@optique/git";
|
|
167
|
+
* import { option } from "@optique/core/primitives";
|
|
168
|
+
*
|
|
169
|
+
* const parser = option("-c", "--commit", gitCommit());
|
|
170
|
+
* ~~~~
|
|
171
|
+
*/
|
|
172
|
+
declare function gitCommit(options?: GitParserOptions): ValueParser<"async", string>;
|
|
173
|
+
/**
|
|
174
|
+
* Creates a value parser that validates any git reference
|
|
175
|
+
* (branches, tags, or commits).
|
|
176
|
+
*
|
|
177
|
+
* This parser uses isomorphic-git to verify that the provided input
|
|
178
|
+
* resolves to a valid git reference (branch, tag, or commit SHA).
|
|
179
|
+
*
|
|
180
|
+
* @param options Configuration options for the parser.
|
|
181
|
+
* @returns A value parser that accepts branches, tags, or commit SHAs.
|
|
182
|
+
* @since 0.9.0
|
|
183
|
+
*
|
|
184
|
+
* @example
|
|
185
|
+
* ~~~~ typescript
|
|
186
|
+
* import { gitRef } from "@optique/git";
|
|
187
|
+
* import { option } from "@optique/core/primitives";
|
|
188
|
+
*
|
|
189
|
+
* const parser = option("--ref", gitRef());
|
|
190
|
+
* ~~~~
|
|
191
|
+
*/
|
|
192
|
+
declare function gitRef(options?: GitParserOptions): ValueParser<"async", string>;
|
|
193
|
+
/**
|
|
194
|
+
* Creates a factory for git parsers with shared configuration.
|
|
195
|
+
*
|
|
196
|
+
* This function returns an object with methods for creating individual git
|
|
197
|
+
* parsers that share the same configuration (filesystem and directory).
|
|
198
|
+
*
|
|
199
|
+
* @param options Shared configuration options for all parsers.
|
|
200
|
+
* @returns An object with methods for creating individual git parsers.
|
|
201
|
+
* @since 0.9.0
|
|
202
|
+
*
|
|
203
|
+
* @example
|
|
204
|
+
* ~~~~ typescript
|
|
205
|
+
* import { createGitParsers } from "@optique/git";
|
|
206
|
+
*
|
|
207
|
+
* const git = createGitParsers({ dir: "/path/to/repo" });
|
|
208
|
+
*
|
|
209
|
+
* const branchParser = git.branch();
|
|
210
|
+
* const tagParser = git.tag();
|
|
211
|
+
* ~~~~
|
|
212
|
+
*/
|
|
213
|
+
declare function createGitParsers(options?: GitParserOptions): GitParsers;
|
|
214
|
+
//#endregion
|
|
215
|
+
export { FileSystem, GitParserOptions, GitParsers, createGitParsers, expandOid, gitBranch, gitCommit, gitRef, gitRemote, gitRemoteBranch, gitTag, listBranches, listRemotes, listTags, readObject, resolveRef };
|