@osdlc/typed-git 0.5.3 → 0.6.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/CHANGELOG.md +30 -1
- package/CONTRIBUTING.md +3 -4
- package/README.md +40 -16
- package/dist/async.d.ts +3 -4
- package/dist/async.js +3 -3
- package/dist/backend.d.ts +1 -2
- package/dist/checkout-root.d.ts +0 -1
- package/dist/client.d.ts +2 -2
- package/dist/client.js +1 -0
- package/dist/failure.d.ts +64 -0
- package/dist/failure.js +126 -0
- package/dist/git-url.d.ts +0 -1
- package/dist/index.d.ts +1 -2
- package/dist/index.js +1 -1
- package/dist/outcome.d.ts +13 -18
- package/dist/outcome.js +21 -16
- package/dist/remote-url.d.ts +0 -1
- package/dist/soft.d.ts +0 -1
- package/dist/sync.d.ts +5 -5
- package/dist/sync.js +4 -3
- package/dist/testing.d.ts +0 -1
- package/dist/verbs.d.ts +5 -7
- package/dist/verbs.js +18 -11
- package/package.json +10 -23
- package/async.ts +0 -753
- package/backend.ts +0 -574
- package/checkout-root.ts +0 -164
- package/client.ts +0 -102
- package/dist/async.d.ts.map +0 -1
- package/dist/backend.d.ts.map +0 -1
- package/dist/checkout-root.d.ts.map +0 -1
- package/dist/client.d.ts.map +0 -1
- package/dist/git-url.d.ts.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/outcome.d.ts.map +0 -1
- package/dist/remote-url.d.ts.map +0 -1
- package/dist/soft.d.ts.map +0 -1
- package/dist/sync.d.ts.map +0 -1
- package/dist/testing.d.ts.map +0 -1
- package/dist/verbs.d.ts.map +0 -1
- package/git-url.ts +0 -102
- package/hosted-git-info.d.ts +0 -24
- package/index.ts +0 -52
- package/outcome.ts +0 -191
- package/remote-url.ts +0 -46
- package/soft.ts +0 -60
- package/sync.ts +0 -827
- package/testing.ts +0 -291
- package/verbs.ts +0 -2300
package/dist/outcome.js
CHANGED
|
@@ -1,22 +1,27 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* The inspection door — `git.try.*`, and the
|
|
2
|
+
* The inspection door — `git.try.*`, and the `Result<T, GitFailure>` it returns.
|
|
3
3
|
*
|
|
4
4
|
* For callers that genuinely tolerate failure: a hook that must never break a
|
|
5
5
|
* commit, a status endpoint that must always answer. `try` is a facade over
|
|
6
6
|
* the whole client rather than a per-verb option, so a new verb costs nothing
|
|
7
7
|
* here. Two rules make it honest:
|
|
8
8
|
*
|
|
9
|
-
* - It catches
|
|
10
|
-
*
|
|
9
|
+
* - It catches a thrown git failure (the `FailureError` the plain door throws,
|
|
10
|
+
* or a bare `CommandFailed`, both recognised by shape so two installed copies
|
|
11
|
+
* of command-seam or result agree) and nothing else, and returns the
|
|
12
|
+
* {@link GitFailure}, whose `cause` is the `CommandFailed`. A `TypeError`
|
|
13
|
+
* from a programmer mistake propagates; this is not a blanket catch.
|
|
11
14
|
* - A declared absence is `{ ok: true }`. `git.try.configGet("no.such.key")`
|
|
12
15
|
* is `{ ok: true, value: null }`, because absence is an answer, not a
|
|
13
16
|
* failure.
|
|
14
17
|
*/
|
|
15
|
-
import {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
18
|
+
import { err, ok } from '@osdlc/result';
|
|
19
|
+
import { thrownGitFailure } from "./failure.js";
|
|
20
|
+
/** `CommandFailed` becomes a classified failure; anything else stays a throw. */
|
|
21
|
+
function asFailure(error) {
|
|
22
|
+
const failure = thrownGitFailure(error);
|
|
23
|
+
if (failure !== null)
|
|
24
|
+
return err(failure);
|
|
20
25
|
throw error;
|
|
21
26
|
}
|
|
22
27
|
/**
|
|
@@ -39,25 +44,25 @@ function facade(client, wrap) {
|
|
|
39
44
|
},
|
|
40
45
|
});
|
|
41
46
|
}
|
|
42
|
-
/** Wrap a synchronous client so every method returns a
|
|
47
|
+
/** Wrap a synchronous client so every method returns a `Result<T, GitFailure>`. */
|
|
43
48
|
export function triedSync(client) {
|
|
44
49
|
return facade(client, (call) => {
|
|
45
50
|
try {
|
|
46
|
-
return
|
|
51
|
+
return ok(call());
|
|
47
52
|
}
|
|
48
53
|
catch (error) {
|
|
49
|
-
return
|
|
54
|
+
return asFailure(error);
|
|
50
55
|
}
|
|
51
56
|
});
|
|
52
57
|
}
|
|
53
|
-
/** Wrap an awaitable client so every method promises a
|
|
58
|
+
/** Wrap an awaitable client so every method promises a `Result<T, GitFailure>`. */
|
|
54
59
|
export function triedAsync(client) {
|
|
55
60
|
return facade(client, async (call) => {
|
|
56
61
|
try {
|
|
57
|
-
return
|
|
62
|
+
return ok(await call());
|
|
58
63
|
}
|
|
59
64
|
catch (error) {
|
|
60
|
-
return
|
|
65
|
+
return asFailure(error);
|
|
61
66
|
}
|
|
62
67
|
});
|
|
63
68
|
}
|
|
@@ -75,7 +80,7 @@ export function softSync(client, table) {
|
|
|
75
80
|
return call();
|
|
76
81
|
}
|
|
77
82
|
catch (error) {
|
|
78
|
-
if (error
|
|
83
|
+
if (thrownGitFailure(error) !== null)
|
|
79
84
|
return fallbackFor(table, name);
|
|
80
85
|
throw error;
|
|
81
86
|
}
|
|
@@ -88,7 +93,7 @@ export function softAsync(client, table) {
|
|
|
88
93
|
return await call();
|
|
89
94
|
}
|
|
90
95
|
catch (error) {
|
|
91
|
-
if (error
|
|
96
|
+
if (thrownGitFailure(error) !== null)
|
|
92
97
|
return fallbackFor(table, name);
|
|
93
98
|
throw error;
|
|
94
99
|
}
|
package/dist/remote-url.d.ts
CHANGED
package/dist/soft.d.ts
CHANGED
package/dist/sync.d.ts
CHANGED
|
@@ -37,7 +37,7 @@ export interface GitSyncCallOptions {
|
|
|
37
37
|
env?: Record<string, string> | undefined;
|
|
38
38
|
/**
|
|
39
39
|
* Cap on each output stream, in bytes; 256 MB when omitted. Past it the
|
|
40
|
-
* runner kills the child and the call throws
|
|
40
|
+
* runner kills the child and the call throws the classified failure. command-seam's
|
|
41
41
|
* Bun test capture path (the Bun runtime with `NODE_ENV=test`) does not
|
|
42
42
|
* apply it.
|
|
43
43
|
*/
|
|
@@ -87,7 +87,8 @@ export declare class Git {
|
|
|
87
87
|
at(cwd: string): Git;
|
|
88
88
|
/**
|
|
89
89
|
* The whole surface again, reporting failure instead of throwing:
|
|
90
|
-
* `git.try.topLevel()` is `
|
|
90
|
+
* `git.try.topLevel()` is a `Result<string | null, GitFailure>`: `{ ok: true, value }`
|
|
91
|
+
* or `{ ok: false, error }` with a classified {@link GitFailure}.
|
|
91
92
|
* A declared absence is `ok: true` — see `./outcome.ts`.
|
|
92
93
|
*
|
|
93
94
|
* The type leaves out `raw`, `rawChecked` and `at`, but at runtime the proxy
|
|
@@ -111,7 +112,7 @@ export declare class Git {
|
|
|
111
112
|
input?: string | undefined;
|
|
112
113
|
}): CommandResult;
|
|
113
114
|
/**
|
|
114
|
-
* Checked passthrough — throws
|
|
115
|
+
* Checked passthrough — throws the classified failure on a non-zero exit, and on
|
|
115
116
|
* output cut short at the output cap or a timeout, as every verb does.
|
|
116
117
|
*
|
|
117
118
|
* `CommandFailed.message` interpolates stderr only, and several git commands
|
|
@@ -400,7 +401,7 @@ export declare class Git {
|
|
|
400
401
|
/**
|
|
401
402
|
* Merge `ref` into the current branch. A conflict is a value, not a throw:
|
|
402
403
|
* the outcome is `clean` or `conflict`. Git refusing to merge at all still
|
|
403
|
-
* throws
|
|
404
|
+
* throws the classified failure.
|
|
404
405
|
*/
|
|
405
406
|
merge(ref: string, opts?: MergeOptions & GitSyncCallOptions): MergeOutcome;
|
|
406
407
|
/** `git merge --abort`. Throws when no merge is in progress. */
|
|
@@ -432,4 +433,3 @@ export declare class Git {
|
|
|
432
433
|
/** `git checkout [-f] [-b|-B <branch>] <ref>`. */
|
|
433
434
|
checkout(ref: string, opts?: CheckoutOptions & GitSyncCallOptions): void;
|
|
434
435
|
}
|
|
435
|
-
//# sourceMappingURL=sync.d.ts.map
|
package/dist/sync.js
CHANGED
|
@@ -74,7 +74,8 @@ export class Git {
|
|
|
74
74
|
}
|
|
75
75
|
/**
|
|
76
76
|
* The whole surface again, reporting failure instead of throwing:
|
|
77
|
-
* `git.try.topLevel()` is `
|
|
77
|
+
* `git.try.topLevel()` is a `Result<string | null, GitFailure>`: `{ ok: true, value }`
|
|
78
|
+
* or `{ ok: false, error }` with a classified {@link GitFailure}.
|
|
78
79
|
* A declared absence is `ok: true` — see `./outcome.ts`.
|
|
79
80
|
*
|
|
80
81
|
* The type leaves out `raw`, `rawChecked` and `at`, but at runtime the proxy
|
|
@@ -103,7 +104,7 @@ export class Git {
|
|
|
103
104
|
return this.runner.run(this.argv(argv), this.runOpts(opts));
|
|
104
105
|
}
|
|
105
106
|
/**
|
|
106
|
-
* Checked passthrough — throws
|
|
107
|
+
* Checked passthrough — throws the classified failure on a non-zero exit, and on
|
|
107
108
|
* output cut short at the output cap or a timeout, as every verb does.
|
|
108
109
|
*
|
|
109
110
|
* `CommandFailed.message` interpolates stderr only, and several git commands
|
|
@@ -555,7 +556,7 @@ export class Git {
|
|
|
555
556
|
/**
|
|
556
557
|
* Merge `ref` into the current branch. A conflict is a value, not a throw:
|
|
557
558
|
* the outcome is `clean` or `conflict`. Git refusing to merge at all still
|
|
558
|
-
* throws
|
|
559
|
+
* throws the classified failure.
|
|
559
560
|
*/
|
|
560
561
|
merge(ref, opts = {}) {
|
|
561
562
|
return this.exec(v.merge(ref, opts), opts);
|
package/dist/testing.d.ts
CHANGED
package/dist/verbs.d.ts
CHANGED
|
@@ -48,15 +48,14 @@ export interface GitVerb<T> {
|
|
|
48
48
|
parse(result: CommandResult, argv: string[]): T;
|
|
49
49
|
}
|
|
50
50
|
/**
|
|
51
|
-
* Turn one git result into a value or a `
|
|
51
|
+
* Turn one git result into a value or a thrown failure: a `FailureError`
|
|
52
|
+
* carrying the classified `GitFailure`, whose `cause` is the `CommandFailed`.
|
|
52
53
|
*
|
|
53
54
|
* The exit-code throw site for the whole library, shared by both clients so
|
|
54
55
|
* they cannot disagree. A parse can raise its own `CommandFailed` for output
|
|
55
56
|
* it cannot read (`aheadBehind`, the integration verbs); it is handed the same
|
|
56
|
-
* argv this reports. `CommandFailed` is
|
|
57
|
-
*
|
|
58
|
-
* from any other command-seam caller; a caller that must tell which git call
|
|
59
|
-
* failed reads `e.argv`.
|
|
57
|
+
* argv this reports. The `CommandFailed` is the `failure.cause`; a caller
|
|
58
|
+
* that must tell which git call failed reads `e.failure.argv`.
|
|
60
59
|
*
|
|
61
60
|
* `argv` overrides what the error reports. Both clients pass the argv they
|
|
62
61
|
* actually ran, so a failure from a repository-bound client names its store.
|
|
@@ -665,7 +664,7 @@ export declare function diffText(rev?: string | undefined, opts?: DiffTextOption
|
|
|
665
664
|
*
|
|
666
665
|
* `--no-index` exits 1 whenever the inputs differ, which for a real file is
|
|
667
666
|
* always, so exit 1 is the success case. git also exits 1, with empty stdout,
|
|
668
|
-
* for a path it cannot read; that throws
|
|
667
|
+
* for a path it cannot read; that throws the classified failure. Exit 2 (a usage or
|
|
669
668
|
* read error) throws too.
|
|
670
669
|
*/
|
|
671
670
|
export declare function diffAddedFile(relPath: string): GitVerb<string>;
|
|
@@ -1232,4 +1231,3 @@ export interface CheckoutOptions {
|
|
|
1232
1231
|
* not an absence.
|
|
1233
1232
|
*/
|
|
1234
1233
|
export declare function checkout(ref: string, opts?: CheckoutOptions): GitVerb<void>;
|
|
1235
|
-
//# sourceMappingURL=verbs.d.ts.map
|
package/dist/verbs.js
CHANGED
|
@@ -13,16 +13,16 @@
|
|
|
13
13
|
* `GitVerb` and `gate` are internal: the package entries do not export them.
|
|
14
14
|
*/
|
|
15
15
|
import { CommandFailed } from '@osdlc/command-seam';
|
|
16
|
+
import { gitFailureError } from "./failure.js";
|
|
16
17
|
/**
|
|
17
|
-
* Turn one git result into a value or a `
|
|
18
|
+
* Turn one git result into a value or a thrown failure: a `FailureError`
|
|
19
|
+
* carrying the classified `GitFailure`, whose `cause` is the `CommandFailed`.
|
|
18
20
|
*
|
|
19
21
|
* The exit-code throw site for the whole library, shared by both clients so
|
|
20
22
|
* they cannot disagree. A parse can raise its own `CommandFailed` for output
|
|
21
23
|
* it cannot read (`aheadBehind`, the integration verbs); it is handed the same
|
|
22
|
-
* argv this reports. `CommandFailed` is
|
|
23
|
-
*
|
|
24
|
-
* from any other command-seam caller; a caller that must tell which git call
|
|
25
|
-
* failed reads `e.argv`.
|
|
24
|
+
* argv this reports. The `CommandFailed` is the `failure.cause`; a caller
|
|
25
|
+
* that must tell which git call failed reads `e.failure.argv`.
|
|
26
26
|
*
|
|
27
27
|
* `argv` overrides what the error reports. Both clients pass the argv they
|
|
28
28
|
* actually ran, so a failure from a repository-bound client names its store.
|
|
@@ -39,12 +39,19 @@ import { CommandFailed } from '@osdlc/command-seam';
|
|
|
39
39
|
* timeout, so a parse would read cut-short output as the whole answer.
|
|
40
40
|
*/
|
|
41
41
|
export function gate(verb, result, argv) {
|
|
42
|
-
|
|
43
|
-
result.
|
|
44
|
-
|
|
45
|
-
|
|
42
|
+
try {
|
|
43
|
+
if (result.neverExited ||
|
|
44
|
+
result.outputIncomplete ||
|
|
45
|
+
(result.exitCode !== 0 && !verb.absent.includes(result.exitCode))) {
|
|
46
|
+
throw new CommandFailed(argv ?? verb.argv, result);
|
|
47
|
+
}
|
|
48
|
+
return verb.parse(result, argv ?? verb.argv);
|
|
49
|
+
}
|
|
50
|
+
catch (error) {
|
|
51
|
+
// The plain door throws the classified failure, a parse's own
|
|
52
|
+
// `CommandFailed` included; its `cause` is the `CommandFailed`.
|
|
53
|
+
throw gitFailureError(error);
|
|
46
54
|
}
|
|
47
|
-
return verb.parse(result, argv ?? verb.argv);
|
|
48
55
|
}
|
|
49
56
|
/**
|
|
50
57
|
* A client-level environment bag under a per-call one, or `undefined` when
|
|
@@ -894,7 +901,7 @@ export function diffText(rev, opts = {}) {
|
|
|
894
901
|
*
|
|
895
902
|
* `--no-index` exits 1 whenever the inputs differ, which for a real file is
|
|
896
903
|
* always, so exit 1 is the success case. git also exits 1, with empty stdout,
|
|
897
|
-
* for a path it cannot read; that throws
|
|
904
|
+
* for a path it cannot read; that throws the classified failure. Exit 2 (a usage or
|
|
898
905
|
* read error) throws too.
|
|
899
906
|
*/
|
|
900
907
|
export function diffAddedFile(relPath) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@osdlc/typed-git",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"description": "A typed git client for TypeScript, sync and awaitable. Each verb declares what absence means for it; every other failure throws. git.try.* inspects, raw() bypasses — over an injectable backend that drives the git CLI or any other implementation.",
|
|
5
5
|
"license": "MIT OR Apache-2.0",
|
|
6
6
|
"author": "sksizer",
|
|
@@ -29,36 +29,20 @@
|
|
|
29
29
|
},
|
|
30
30
|
"exports": {
|
|
31
31
|
".": {
|
|
32
|
-
"bun": "./index.ts",
|
|
33
32
|
"types": "./dist/index.d.ts",
|
|
34
33
|
"default": "./dist/index.js"
|
|
35
34
|
},
|
|
36
35
|
"./client": {
|
|
37
|
-
"bun": "./client.ts",
|
|
38
36
|
"types": "./dist/client.d.ts",
|
|
39
37
|
"default": "./dist/client.js"
|
|
40
38
|
},
|
|
41
39
|
"./testing": {
|
|
42
|
-
"bun": "./testing.ts",
|
|
43
40
|
"types": "./dist/testing.d.ts",
|
|
44
41
|
"default": "./dist/testing.js"
|
|
45
42
|
}
|
|
46
43
|
},
|
|
47
44
|
"files": [
|
|
48
45
|
"dist/",
|
|
49
|
-
"index.ts",
|
|
50
|
-
"client.ts",
|
|
51
|
-
"testing.ts",
|
|
52
|
-
"outcome.ts",
|
|
53
|
-
"soft.ts",
|
|
54
|
-
"sync.ts",
|
|
55
|
-
"async.ts",
|
|
56
|
-
"backend.ts",
|
|
57
|
-
"verbs.ts",
|
|
58
|
-
"git-url.ts",
|
|
59
|
-
"remote-url.ts",
|
|
60
|
-
"checkout-root.ts",
|
|
61
|
-
"hosted-git-info.d.ts",
|
|
62
46
|
"README.md",
|
|
63
47
|
"CHANGELOG.md",
|
|
64
48
|
"LICENSE-MIT",
|
|
@@ -68,25 +52,28 @@
|
|
|
68
52
|
],
|
|
69
53
|
"dependencies": {
|
|
70
54
|
"hosted-git-info": "^10.1.1",
|
|
71
|
-
"@osdlc/
|
|
55
|
+
"@osdlc/result": "^0.1.0",
|
|
56
|
+
"@osdlc/command-seam": "^0.9.0"
|
|
72
57
|
},
|
|
73
58
|
"devDependencies": {
|
|
74
|
-
"@types/bun": "^1.1.14",
|
|
75
59
|
"@types/node": "^26.1.0",
|
|
60
|
+
"@vitest/coverage-v8": "^5.0.5",
|
|
76
61
|
"oxlint": "^1.65.0",
|
|
77
62
|
"prettier": "3.9.6",
|
|
78
63
|
"typescript": "~6.0.3",
|
|
79
|
-
"
|
|
80
|
-
"@osdlc/prettier-config": "^0.3.
|
|
64
|
+
"vitest": "^5.0.5",
|
|
65
|
+
"@osdlc/prettier-config": "^0.3.1",
|
|
66
|
+
"@osdlc/tsconfig": "^0.4.1"
|
|
81
67
|
},
|
|
82
68
|
"scripts": {
|
|
83
69
|
"build": "tsc -p tsconfig.build.json",
|
|
84
70
|
"clean": "node -e \"require('node:fs').rmSync('dist', { recursive: true, force: true })\"",
|
|
85
|
-
"test": "
|
|
71
|
+
"test": "vitest run",
|
|
86
72
|
"smoke": "node tests/smoke.mjs",
|
|
87
73
|
"format": "prettier --write .",
|
|
88
74
|
"format:check": "prettier --check .",
|
|
89
75
|
"lint": "oxlint .",
|
|
90
|
-
"typecheck": "tsc --noEmit && tsc -p tsconfig.build.json --noEmit"
|
|
76
|
+
"typecheck": "tsc --noEmit && tsc -p tsconfig.build.json --noEmit",
|
|
77
|
+
"coverage": "vitest run --coverage"
|
|
91
78
|
}
|
|
92
79
|
}
|