@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/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 resetCommitCommitSchema = commitPackCommitSchema.omit({ blob_count: true });
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 resetCommitAckSchema = z.object({
136
- commit: resetCommitCommitSchema,
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 resetCommitResponseSchema = z.object({
144
- commit: resetCommitCommitSchema.partial().optional().nullable(),
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 RESET_COMMIT_ALLOWED_STATUS = [
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 buildResetCommitResult(ack) {
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 ?? `Reset commit failed with status ${ack.result.status}`,
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 parseResetCommitPayload(payload) {
1054
- const ack = resetCommitAckSchema.safeParse(payload);
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 = resetCommitResponseSchema.safeParse(payload);
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 httpStatusToResetStatus(status) {
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 resetCommit(options) {
1325
+ async restoreCommit(options) {
1326
1326
  const targetBranch = options?.targetBranch?.trim();
1327
1327
  if (!targetBranch) {
1328
- throw new Error("resetCommit targetBranch is required");
1328
+ throw new Error("restoreCommit targetBranch is required");
1329
1329
  }
1330
1330
  if (targetBranch.startsWith("refs/")) {
1331
- throw new Error("resetCommit targetBranch must not include refs/ prefix");
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("resetCommit targetCommitSha is required");
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("resetCommit author name and email are required");
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("resetCommit committer name and email are required when provided");
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({ path: "repos/reset-commits", body: { metadata } }, jwt, {
1375
- allowedStatus: [...RESET_COMMIT_ALLOWED_STATUS]
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 = parseResetCommitPayload(payload);
1382
+ const parsed = parseRestoreCommitPayload(payload);
1379
1383
  if (parsed && "ack" in parsed) {
1380
- return buildResetCommitResult(parsed.ack);
1384
+ return buildRestoreCommitResult(parsed.ack);
1381
1385
  }
1382
1386
  const failure = parsed && "failure" in parsed ? parsed.failure : void 0;
1383
- const status = failure?.status ?? httpStatusToResetStatus(response.status);
1384
- const message = failure?.message ?? `Reset commit failed with HTTP ${response.status}` + (response.statusText ? ` ${response.statusText}` : "");
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