@pierre/storage 0.9.2 → 1.0.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 +77 -43
- package/dist/index.cjs +148 -43
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +12 -7
- package/dist/index.d.ts +12 -7
- package/dist/index.js +148 -43
- package/dist/index.js.map +1 -1
- package/package.json +2 -1
- package/src/commit-pack.ts +103 -99
- package/src/commit.ts +373 -365
- package/src/diff-commit.ts +272 -259
- package/src/errors.ts +34 -34
- package/src/fetch.ts +146 -141
- package/src/index.ts +1400 -1249
- package/src/schemas.ts +120 -114
- package/src/stream-utils.ts +225 -208
- package/src/types.ts +378 -354
- package/src/util.ts +41 -34
- package/src/version.ts +1 -1
- package/src/webhook.ts +244 -239
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pierre/storage",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "1.0.0",
|
|
4
4
|
"description": "Pierre Git Storage SDK",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -25,6 +25,7 @@
|
|
|
25
25
|
"zod": "^3.23.8"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
|
+
"@types/node": "^22.0.0",
|
|
28
29
|
"tsup": "8.5.0",
|
|
29
30
|
"typescript": "5.8.3",
|
|
30
31
|
"vitest": "3.2.4"
|
package/src/commit-pack.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { RefUpdateError, inferRefUpdateReason } from './errors';
|
|
2
2
|
import type { CommitPackAckRaw } from './schemas';
|
|
3
3
|
import { commitPackResponseSchema, errorEnvelopeSchema } from './schemas';
|
|
4
4
|
import type { CommitResult, RefUpdate } from './types';
|
|
@@ -6,123 +6,127 @@ import type { CommitResult, RefUpdate } from './types';
|
|
|
6
6
|
export type CommitPackAck = CommitPackAckRaw;
|
|
7
7
|
|
|
8
8
|
export function buildCommitResult(ack: CommitPackAckRaw): CommitResult {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
9
|
+
const refUpdate = toRefUpdate(ack.result);
|
|
10
|
+
if (!ack.result.success) {
|
|
11
|
+
throw new RefUpdateError(
|
|
12
|
+
ack.result.message ?? `Commit failed with status ${ack.result.status}`,
|
|
13
|
+
{
|
|
14
|
+
status: ack.result.status,
|
|
15
|
+
message: ack.result.message,
|
|
16
|
+
refUpdate,
|
|
17
|
+
}
|
|
18
|
+
);
|
|
19
|
+
}
|
|
20
|
+
return {
|
|
21
|
+
commitSha: ack.commit.commit_sha,
|
|
22
|
+
treeSha: ack.commit.tree_sha,
|
|
23
|
+
targetBranch: ack.commit.target_branch,
|
|
24
|
+
packBytes: ack.commit.pack_bytes,
|
|
25
|
+
blobCount: ack.commit.blob_count,
|
|
26
|
+
refUpdate,
|
|
27
|
+
};
|
|
28
28
|
}
|
|
29
29
|
|
|
30
30
|
export function toRefUpdate(result: CommitPackAckRaw['result']): RefUpdate {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
31
|
+
return {
|
|
32
|
+
branch: result.branch,
|
|
33
|
+
oldSha: result.old_sha,
|
|
34
|
+
newSha: result.new_sha,
|
|
35
|
+
};
|
|
36
36
|
}
|
|
37
37
|
|
|
38
38
|
export async function parseCommitPackError(
|
|
39
|
-
|
|
40
|
-
|
|
39
|
+
response: Response,
|
|
40
|
+
fallbackMessage: string
|
|
41
41
|
): Promise<{
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
42
|
+
statusMessage: string;
|
|
43
|
+
statusLabel: string;
|
|
44
|
+
refUpdate?: Partial<RefUpdate>;
|
|
45
45
|
}> {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
46
|
+
const cloned = response.clone();
|
|
47
|
+
let jsonBody: unknown;
|
|
48
|
+
try {
|
|
49
|
+
jsonBody = await cloned.json();
|
|
50
|
+
} catch {
|
|
51
|
+
jsonBody = undefined;
|
|
52
|
+
}
|
|
53
53
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
54
|
+
let textBody: string | undefined;
|
|
55
|
+
if (jsonBody === undefined) {
|
|
56
|
+
try {
|
|
57
|
+
textBody = await response.text();
|
|
58
|
+
} catch {
|
|
59
|
+
textBody = undefined;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
62
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
63
|
+
const defaultStatus = (() => {
|
|
64
|
+
const inferred = inferRefUpdateReason(String(response.status));
|
|
65
|
+
return inferred === 'unknown' ? 'failed' : inferred;
|
|
66
|
+
})();
|
|
67
|
+
let statusLabel = defaultStatus;
|
|
68
|
+
let refUpdate: Partial<RefUpdate> | undefined;
|
|
69
|
+
let message: string | undefined;
|
|
70
70
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
71
|
+
if (jsonBody !== undefined) {
|
|
72
|
+
const parsedResponse = commitPackResponseSchema.safeParse(jsonBody);
|
|
73
|
+
if (parsedResponse.success) {
|
|
74
|
+
const result = parsedResponse.data.result;
|
|
75
|
+
if (typeof result.status === 'string' && result.status.trim() !== '') {
|
|
76
|
+
statusLabel = result.status.trim() as typeof statusLabel;
|
|
77
|
+
}
|
|
78
|
+
refUpdate = toPartialRefUpdateFields(
|
|
79
|
+
result.branch,
|
|
80
|
+
result.old_sha,
|
|
81
|
+
result.new_sha
|
|
82
|
+
);
|
|
83
|
+
if (typeof result.message === 'string' && result.message.trim() !== '') {
|
|
84
|
+
message = result.message.trim();
|
|
85
|
+
}
|
|
86
|
+
}
|
|
83
87
|
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
88
|
+
if (!message) {
|
|
89
|
+
const parsedError = errorEnvelopeSchema.safeParse(jsonBody);
|
|
90
|
+
if (parsedError.success) {
|
|
91
|
+
const trimmed = parsedError.data.error.trim();
|
|
92
|
+
if (trimmed) {
|
|
93
|
+
message = trimmed;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
94
98
|
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
99
|
+
if (!message && typeof jsonBody === 'string' && jsonBody.trim() !== '') {
|
|
100
|
+
message = jsonBody.trim();
|
|
101
|
+
}
|
|
98
102
|
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
103
|
+
if (!message && textBody && textBody.trim() !== '') {
|
|
104
|
+
message = textBody.trim();
|
|
105
|
+
}
|
|
102
106
|
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
107
|
+
return {
|
|
108
|
+
statusMessage: message ?? fallbackMessage,
|
|
109
|
+
statusLabel,
|
|
110
|
+
refUpdate,
|
|
111
|
+
};
|
|
108
112
|
}
|
|
109
113
|
|
|
110
114
|
function toPartialRefUpdateFields(
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
115
|
+
branch?: string | null,
|
|
116
|
+
oldSha?: string | null,
|
|
117
|
+
newSha?: string | null
|
|
114
118
|
): Partial<RefUpdate> | undefined {
|
|
115
|
-
|
|
119
|
+
const refUpdate: Partial<RefUpdate> = {};
|
|
116
120
|
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
121
|
+
if (typeof branch === 'string' && branch.trim() !== '') {
|
|
122
|
+
refUpdate.branch = branch.trim();
|
|
123
|
+
}
|
|
124
|
+
if (typeof oldSha === 'string' && oldSha.trim() !== '') {
|
|
125
|
+
refUpdate.oldSha = oldSha.trim();
|
|
126
|
+
}
|
|
127
|
+
if (typeof newSha === 'string' && newSha.trim() !== '') {
|
|
128
|
+
refUpdate.newSha = newSha.trim();
|
|
129
|
+
}
|
|
126
130
|
|
|
127
|
-
|
|
131
|
+
return Object.keys(refUpdate).length > 0 ? refUpdate : undefined;
|
|
128
132
|
}
|