@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 CHANGED
@@ -2,6 +2,14 @@
2
2
 
3
3
  Pierre Git Storage SDK for TypeScript/JavaScript applications.
4
4
 
5
+ ## End-to-End Smoke Test
6
+
7
+ - `node packages/git-storage-sdk/tests/full-workflow.js -e production -s pierre -k /home/ian/pierre-prod-key.pem`
8
+ Drives
9
+ the Pierre workflow via the SDK: creates a repository, writes commits, fetches branch and diff
10
+ data, and confirms storage APIs. Swap in your own private key path when running outside this
11
+ workstation and adjust `-e`/`-s` for non-production environments.
12
+
5
13
  ## Installation
6
14
 
7
15
  ```bash
@@ -431,7 +439,7 @@ interface CommitResult {
431
439
  refUpdate: RefUpdate;
432
440
  }
433
441
 
434
- interface ResetCommitOptions {
442
+ interface RestoreCommitOptions {
435
443
  targetBranch: string;
436
444
  targetCommitSha: string;
437
445
  commitMessage?: string;
@@ -440,7 +448,7 @@ interface ResetCommitOptions {
440
448
  committer?: CommitSignature;
441
449
  }
442
450
 
443
- interface ResetCommitResult {
451
+ interface RestoreCommitResult {
444
452
  commitSha: string;
445
453
  treeSha: string;
446
454
  targetBranch: string;
@@ -483,7 +491,7 @@ try {
483
491
  -
484
492
  ```
485
493
 
486
- - Mutating operations (commit builder, `resetCommit`) throw `RefUpdateError` when the backend
494
+ - Mutating operations (commit builder, `restoreCommit`) throw `RefUpdateError` when the backend
487
495
  reports a ref failure. Inspect `error.status`, `error.reason`, `error.message`, and
488
496
  `error.refUpdate` for details.
489
497
 
package/dist/index.cjs CHANGED
@@ -125,7 +125,7 @@ var commitPackCommitSchema = zod.z.object({
125
125
  pack_bytes: zod.z.number(),
126
126
  blob_count: zod.z.number()
127
127
  });
128
- var resetCommitCommitSchema = commitPackCommitSchema.omit({ blob_count: true });
128
+ var restoreCommitCommitSchema = commitPackCommitSchema.omit({ blob_count: true });
129
129
  var refUpdateResultWithOptionalsSchema = zod.z.object({
130
130
  branch: zod.z.string().optional(),
131
131
  old_sha: zod.z.string().optional(),
@@ -138,16 +138,16 @@ var commitPackAckSchema = zod.z.object({
138
138
  commit: commitPackCommitSchema,
139
139
  result: refUpdateResultSchema
140
140
  });
141
- var resetCommitAckSchema = zod.z.object({
142
- commit: resetCommitCommitSchema,
141
+ var restoreCommitAckSchema = zod.z.object({
142
+ commit: restoreCommitCommitSchema,
143
143
  result: refUpdateResultSchema.extend({ success: zod.z.literal(true) })
144
144
  });
145
145
  var commitPackResponseSchema = zod.z.object({
146
146
  commit: commitPackCommitSchema.partial().optional().nullable(),
147
147
  result: refUpdateResultWithOptionalsSchema
148
148
  });
149
- var resetCommitResponseSchema = zod.z.object({
150
- commit: resetCommitCommitSchema.partial().optional().nullable(),
149
+ var restoreCommitResponseSchema = zod.z.object({
150
+ commit: restoreCommitCommitSchema.partial().optional().nullable(),
151
151
  result: refUpdateResultWithOptionalsSchema
152
152
  });
153
153
  var errorEnvelopeSchema = zod.z.object({
@@ -980,7 +980,7 @@ var STORAGE_BASE_URL = "code.storage";
980
980
  var API_VERSION = 1;
981
981
  var apiInstanceMap = /* @__PURE__ */ new Map();
982
982
  var DEFAULT_TOKEN_TTL_SECONDS = 60 * 60;
983
- var RESET_COMMIT_ALLOWED_STATUS = [
983
+ var RESTORE_COMMIT_ALLOWED_STATUS = [
984
984
  400,
985
985
  // Bad Request - validation errors
986
986
  401,
@@ -1023,11 +1023,11 @@ function toRefUpdate2(result) {
1023
1023
  newSha: result.new_sha
1024
1024
  };
1025
1025
  }
1026
- function buildResetCommitResult(ack) {
1026
+ function buildRestoreCommitResult(ack) {
1027
1027
  const refUpdate = toRefUpdate2(ack.result);
1028
1028
  if (!ack.result.success) {
1029
1029
  throw new RefUpdateError(
1030
- ack.result.message ?? `Reset commit failed with status ${ack.result.status}`,
1030
+ ack.result.message ?? `Restore commit failed with status ${ack.result.status}`,
1031
1031
  {
1032
1032
  status: ack.result.status,
1033
1033
  message: ack.result.message,
@@ -1056,12 +1056,12 @@ function toPartialRefUpdate(branch, oldSha, newSha) {
1056
1056
  }
1057
1057
  return Object.keys(refUpdate).length > 0 ? refUpdate : void 0;
1058
1058
  }
1059
- function parseResetCommitPayload(payload) {
1060
- const ack = resetCommitAckSchema.safeParse(payload);
1059
+ function parseRestoreCommitPayload(payload) {
1060
+ const ack = restoreCommitAckSchema.safeParse(payload);
1061
1061
  if (ack.success) {
1062
1062
  return { ack: ack.data };
1063
1063
  }
1064
- const failure = resetCommitResponseSchema.safeParse(payload);
1064
+ const failure = restoreCommitResponseSchema.safeParse(payload);
1065
1065
  if (failure.success) {
1066
1066
  const result = failure.data.result;
1067
1067
  return {
@@ -1074,7 +1074,7 @@ function parseResetCommitPayload(payload) {
1074
1074
  }
1075
1075
  return null;
1076
1076
  }
1077
- function httpStatusToResetStatus(status) {
1077
+ function httpStatusToRestoreStatus(status) {
1078
1078
  switch (status) {
1079
1079
  case 409:
1080
1080
  return "conflict";
@@ -1328,23 +1328,23 @@ var RepoImpl = class {
1328
1328
  }
1329
1329
  return;
1330
1330
  }
1331
- async resetCommit(options) {
1331
+ async restoreCommit(options) {
1332
1332
  const targetBranch = options?.targetBranch?.trim();
1333
1333
  if (!targetBranch) {
1334
- throw new Error("resetCommit targetBranch is required");
1334
+ throw new Error("restoreCommit targetBranch is required");
1335
1335
  }
1336
1336
  if (targetBranch.startsWith("refs/")) {
1337
- throw new Error("resetCommit targetBranch must not include refs/ prefix");
1337
+ throw new Error("restoreCommit targetBranch must not include refs/ prefix");
1338
1338
  }
1339
1339
  const targetCommitSha = options?.targetCommitSha?.trim();
1340
1340
  if (!targetCommitSha) {
1341
- throw new Error("resetCommit targetCommitSha is required");
1341
+ throw new Error("restoreCommit targetCommitSha is required");
1342
1342
  }
1343
1343
  const commitMessage = options?.commitMessage?.trim();
1344
1344
  const authorName = options.author?.name?.trim();
1345
1345
  const authorEmail = options.author?.email?.trim();
1346
1346
  if (!authorName || !authorEmail) {
1347
- throw new Error("resetCommit author name and email are required");
1347
+ throw new Error("restoreCommit author name and email are required");
1348
1348
  }
1349
1349
  const ttl = resolveCommitTtlSeconds(options);
1350
1350
  const jwt = await this.generateJWT(this.id, {
@@ -1370,24 +1370,28 @@ var RepoImpl = class {
1370
1370
  const committerName = options.committer.name?.trim();
1371
1371
  const committerEmail = options.committer.email?.trim();
1372
1372
  if (!committerName || !committerEmail) {
1373
- throw new Error("resetCommit committer name and email are required when provided");
1373
+ throw new Error("restoreCommit committer name and email are required when provided");
1374
1374
  }
1375
1375
  metadata.committer = {
1376
1376
  name: committerName,
1377
1377
  email: committerEmail
1378
1378
  };
1379
1379
  }
1380
- const response = await this.api.post({ path: "repos/reset-commits", body: { metadata } }, jwt, {
1381
- allowedStatus: [...RESET_COMMIT_ALLOWED_STATUS]
1382
- });
1380
+ const response = await this.api.post(
1381
+ { path: "repos/restore-commit", body: { metadata } },
1382
+ jwt,
1383
+ {
1384
+ allowedStatus: [...RESTORE_COMMIT_ALLOWED_STATUS]
1385
+ }
1386
+ );
1383
1387
  const payload = await response.json();
1384
- const parsed = parseResetCommitPayload(payload);
1388
+ const parsed = parseRestoreCommitPayload(payload);
1385
1389
  if (parsed && "ack" in parsed) {
1386
- return buildResetCommitResult(parsed.ack);
1390
+ return buildRestoreCommitResult(parsed.ack);
1387
1391
  }
1388
1392
  const failure = parsed && "failure" in parsed ? parsed.failure : void 0;
1389
- const status = failure?.status ?? httpStatusToResetStatus(response.status);
1390
- const message = failure?.message ?? `Reset commit failed with HTTP ${response.status}` + (response.statusText ? ` ${response.statusText}` : "");
1393
+ const status = failure?.status ?? httpStatusToRestoreStatus(response.status);
1394
+ const message = failure?.message ?? `Restore commit failed with HTTP ${response.status}` + (response.statusText ? ` ${response.statusText}` : "");
1391
1395
  throw new RefUpdateError(message, {
1392
1396
  status,
1393
1397
  refUpdate: failure?.refUpdate