@pierre/storage 0.1.0 → 0.1.2
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 +11 -3
- package/dist/index.cjs +29 -25
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +4 -4
- package/dist/index.d.ts +4 -4
- package/dist/index.js +29 -25
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/index.ts +33 -29
- package/src/schemas.ts +6 -6
- package/src/types.ts +3 -3
package/dist/index.js
CHANGED
|
@@ -119,7 +119,7 @@ var commitPackCommitSchema = z.object({
|
|
|
119
119
|
pack_bytes: z.number(),
|
|
120
120
|
blob_count: z.number()
|
|
121
121
|
});
|
|
122
|
-
var
|
|
122
|
+
var restoreCommitCommitSchema = commitPackCommitSchema.omit({ blob_count: true });
|
|
123
123
|
var refUpdateResultWithOptionalsSchema = z.object({
|
|
124
124
|
branch: z.string().optional(),
|
|
125
125
|
old_sha: z.string().optional(),
|
|
@@ -132,16 +132,16 @@ var commitPackAckSchema = z.object({
|
|
|
132
132
|
commit: commitPackCommitSchema,
|
|
133
133
|
result: refUpdateResultSchema
|
|
134
134
|
});
|
|
135
|
-
var
|
|
136
|
-
commit:
|
|
135
|
+
var restoreCommitAckSchema = z.object({
|
|
136
|
+
commit: restoreCommitCommitSchema,
|
|
137
137
|
result: refUpdateResultSchema.extend({ success: z.literal(true) })
|
|
138
138
|
});
|
|
139
139
|
var commitPackResponseSchema = z.object({
|
|
140
140
|
commit: commitPackCommitSchema.partial().optional().nullable(),
|
|
141
141
|
result: refUpdateResultWithOptionalsSchema
|
|
142
142
|
});
|
|
143
|
-
var
|
|
144
|
-
commit:
|
|
143
|
+
var restoreCommitResponseSchema = z.object({
|
|
144
|
+
commit: restoreCommitCommitSchema.partial().optional().nullable(),
|
|
145
145
|
result: refUpdateResultWithOptionalsSchema
|
|
146
146
|
});
|
|
147
147
|
var errorEnvelopeSchema = z.object({
|
|
@@ -974,7 +974,7 @@ var STORAGE_BASE_URL = "code.storage";
|
|
|
974
974
|
var API_VERSION = 1;
|
|
975
975
|
var apiInstanceMap = /* @__PURE__ */ new Map();
|
|
976
976
|
var DEFAULT_TOKEN_TTL_SECONDS = 60 * 60;
|
|
977
|
-
var
|
|
977
|
+
var RESTORE_COMMIT_ALLOWED_STATUS = [
|
|
978
978
|
400,
|
|
979
979
|
// Bad Request - validation errors
|
|
980
980
|
401,
|
|
@@ -1017,11 +1017,11 @@ function toRefUpdate2(result) {
|
|
|
1017
1017
|
newSha: result.new_sha
|
|
1018
1018
|
};
|
|
1019
1019
|
}
|
|
1020
|
-
function
|
|
1020
|
+
function buildRestoreCommitResult(ack) {
|
|
1021
1021
|
const refUpdate = toRefUpdate2(ack.result);
|
|
1022
1022
|
if (!ack.result.success) {
|
|
1023
1023
|
throw new RefUpdateError(
|
|
1024
|
-
ack.result.message ?? `
|
|
1024
|
+
ack.result.message ?? `Restore commit failed with status ${ack.result.status}`,
|
|
1025
1025
|
{
|
|
1026
1026
|
status: ack.result.status,
|
|
1027
1027
|
message: ack.result.message,
|
|
@@ -1050,12 +1050,12 @@ function toPartialRefUpdate(branch, oldSha, newSha) {
|
|
|
1050
1050
|
}
|
|
1051
1051
|
return Object.keys(refUpdate).length > 0 ? refUpdate : void 0;
|
|
1052
1052
|
}
|
|
1053
|
-
function
|
|
1054
|
-
const ack =
|
|
1053
|
+
function parseRestoreCommitPayload(payload) {
|
|
1054
|
+
const ack = restoreCommitAckSchema.safeParse(payload);
|
|
1055
1055
|
if (ack.success) {
|
|
1056
1056
|
return { ack: ack.data };
|
|
1057
1057
|
}
|
|
1058
|
-
const failure =
|
|
1058
|
+
const failure = restoreCommitResponseSchema.safeParse(payload);
|
|
1059
1059
|
if (failure.success) {
|
|
1060
1060
|
const result = failure.data.result;
|
|
1061
1061
|
return {
|
|
@@ -1068,7 +1068,7 @@ function parseResetCommitPayload(payload) {
|
|
|
1068
1068
|
}
|
|
1069
1069
|
return null;
|
|
1070
1070
|
}
|
|
1071
|
-
function
|
|
1071
|
+
function httpStatusToRestoreStatus(status) {
|
|
1072
1072
|
switch (status) {
|
|
1073
1073
|
case 409:
|
|
1074
1074
|
return "conflict";
|
|
@@ -1322,23 +1322,23 @@ var RepoImpl = class {
|
|
|
1322
1322
|
}
|
|
1323
1323
|
return;
|
|
1324
1324
|
}
|
|
1325
|
-
async
|
|
1325
|
+
async restoreCommit(options) {
|
|
1326
1326
|
const targetBranch = options?.targetBranch?.trim();
|
|
1327
1327
|
if (!targetBranch) {
|
|
1328
|
-
throw new Error("
|
|
1328
|
+
throw new Error("restoreCommit targetBranch is required");
|
|
1329
1329
|
}
|
|
1330
1330
|
if (targetBranch.startsWith("refs/")) {
|
|
1331
|
-
throw new Error("
|
|
1331
|
+
throw new Error("restoreCommit targetBranch must not include refs/ prefix");
|
|
1332
1332
|
}
|
|
1333
1333
|
const targetCommitSha = options?.targetCommitSha?.trim();
|
|
1334
1334
|
if (!targetCommitSha) {
|
|
1335
|
-
throw new Error("
|
|
1335
|
+
throw new Error("restoreCommit targetCommitSha is required");
|
|
1336
1336
|
}
|
|
1337
1337
|
const commitMessage = options?.commitMessage?.trim();
|
|
1338
1338
|
const authorName = options.author?.name?.trim();
|
|
1339
1339
|
const authorEmail = options.author?.email?.trim();
|
|
1340
1340
|
if (!authorName || !authorEmail) {
|
|
1341
|
-
throw new Error("
|
|
1341
|
+
throw new Error("restoreCommit author name and email are required");
|
|
1342
1342
|
}
|
|
1343
1343
|
const ttl = resolveCommitTtlSeconds(options);
|
|
1344
1344
|
const jwt = await this.generateJWT(this.id, {
|
|
@@ -1364,24 +1364,28 @@ var RepoImpl = class {
|
|
|
1364
1364
|
const committerName = options.committer.name?.trim();
|
|
1365
1365
|
const committerEmail = options.committer.email?.trim();
|
|
1366
1366
|
if (!committerName || !committerEmail) {
|
|
1367
|
-
throw new Error("
|
|
1367
|
+
throw new Error("restoreCommit committer name and email are required when provided");
|
|
1368
1368
|
}
|
|
1369
1369
|
metadata.committer = {
|
|
1370
1370
|
name: committerName,
|
|
1371
1371
|
email: committerEmail
|
|
1372
1372
|
};
|
|
1373
1373
|
}
|
|
1374
|
-
const response = await this.api.post(
|
|
1375
|
-
|
|
1376
|
-
|
|
1374
|
+
const response = await this.api.post(
|
|
1375
|
+
{ path: "repos/restore-commit", body: { metadata } },
|
|
1376
|
+
jwt,
|
|
1377
|
+
{
|
|
1378
|
+
allowedStatus: [...RESTORE_COMMIT_ALLOWED_STATUS]
|
|
1379
|
+
}
|
|
1380
|
+
);
|
|
1377
1381
|
const payload = await response.json();
|
|
1378
|
-
const parsed =
|
|
1382
|
+
const parsed = parseRestoreCommitPayload(payload);
|
|
1379
1383
|
if (parsed && "ack" in parsed) {
|
|
1380
|
-
return
|
|
1384
|
+
return buildRestoreCommitResult(parsed.ack);
|
|
1381
1385
|
}
|
|
1382
1386
|
const failure = parsed && "failure" in parsed ? parsed.failure : void 0;
|
|
1383
|
-
const status = failure?.status ??
|
|
1384
|
-
const message = failure?.message ?? `
|
|
1387
|
+
const status = failure?.status ?? httpStatusToRestoreStatus(response.status);
|
|
1388
|
+
const message = failure?.message ?? `Restore commit failed with HTTP ${response.status}` + (response.statusText ? ` ${response.statusText}` : "");
|
|
1385
1389
|
throw new RefUpdateError(message, {
|
|
1386
1390
|
status,
|
|
1387
1391
|
refUpdate: failure?.refUpdate
|