@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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pierre/storage",
3
- "version": "0.9.2",
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"
@@ -1,4 +1,4 @@
1
- import { inferRefUpdateReason, RefUpdateError } from './errors';
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
- 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
- };
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
- return {
32
- branch: result.branch,
33
- oldSha: result.old_sha,
34
- newSha: result.new_sha,
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
- response: Response,
40
- fallbackMessage: string,
39
+ response: Response,
40
+ fallbackMessage: string
41
41
  ): Promise<{
42
- statusMessage: string;
43
- statusLabel: string;
44
- refUpdate?: Partial<RefUpdate>;
42
+ statusMessage: string;
43
+ statusLabel: string;
44
+ refUpdate?: Partial<RefUpdate>;
45
45
  }> {
46
- const cloned = response.clone();
47
- let jsonBody: unknown;
48
- try {
49
- jsonBody = await cloned.json();
50
- } catch {
51
- jsonBody = undefined;
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
- let textBody: string | undefined;
55
- if (jsonBody === undefined) {
56
- try {
57
- textBody = await response.text();
58
- } catch {
59
- textBody = undefined;
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
- 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;
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
- 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(result.branch, result.old_sha, result.new_sha);
79
- if (typeof result.message === 'string' && result.message.trim() !== '') {
80
- message = result.message.trim();
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
- if (!message) {
85
- const parsedError = errorEnvelopeSchema.safeParse(jsonBody);
86
- if (parsedError.success) {
87
- const trimmed = parsedError.data.error.trim();
88
- if (trimmed) {
89
- message = trimmed;
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
- if (!message && typeof jsonBody === 'string' && jsonBody.trim() !== '') {
96
- message = jsonBody.trim();
97
- }
99
+ if (!message && typeof jsonBody === 'string' && jsonBody.trim() !== '') {
100
+ message = jsonBody.trim();
101
+ }
98
102
 
99
- if (!message && textBody && textBody.trim() !== '') {
100
- message = textBody.trim();
101
- }
103
+ if (!message && textBody && textBody.trim() !== '') {
104
+ message = textBody.trim();
105
+ }
102
106
 
103
- return {
104
- statusMessage: message ?? fallbackMessage,
105
- statusLabel,
106
- refUpdate,
107
- };
107
+ return {
108
+ statusMessage: message ?? fallbackMessage,
109
+ statusLabel,
110
+ refUpdate,
111
+ };
108
112
  }
109
113
 
110
114
  function toPartialRefUpdateFields(
111
- branch?: string | null,
112
- oldSha?: string | null,
113
- newSha?: string | null,
115
+ branch?: string | null,
116
+ oldSha?: string | null,
117
+ newSha?: string | null
114
118
  ): Partial<RefUpdate> | undefined {
115
- const refUpdate: Partial<RefUpdate> = {};
119
+ const refUpdate: Partial<RefUpdate> = {};
116
120
 
117
- if (typeof branch === 'string' && branch.trim() !== '') {
118
- refUpdate.branch = branch.trim();
119
- }
120
- if (typeof oldSha === 'string' && oldSha.trim() !== '') {
121
- refUpdate.oldSha = oldSha.trim();
122
- }
123
- if (typeof newSha === 'string' && newSha.trim() !== '') {
124
- refUpdate.newSha = newSha.trim();
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
- return Object.keys(refUpdate).length > 0 ? refUpdate : undefined;
131
+ return Object.keys(refUpdate).length > 0 ? refUpdate : undefined;
128
132
  }