@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/src/index.ts CHANGED
@@ -9,15 +9,15 @@ import snakecaseKeys from 'snakecase-keys';
9
9
  import { createCommitBuilder, FetchCommitTransport, resolveCommitTtlSeconds } from './commit';
10
10
  import { RefUpdateError } from './errors';
11
11
  import { ApiFetcher } from './fetch';
12
- import type { ResetCommitAckRaw } from './schemas';
12
+ import type { RestoreCommitAckRaw } from './schemas';
13
13
  import {
14
14
  branchDiffResponseSchema,
15
15
  commitDiffResponseSchema,
16
16
  listBranchesResponseSchema,
17
17
  listCommitsResponseSchema,
18
18
  listFilesResponseSchema,
19
- resetCommitAckSchema,
20
- resetCommitResponseSchema,
19
+ restoreCommitAckSchema,
20
+ restoreCommitResponseSchema,
21
21
  } from './schemas';
22
22
  import type {
23
23
  BranchInfo,
@@ -54,8 +54,8 @@ import type {
54
54
  RawFilteredFile,
55
55
  RefUpdate,
56
56
  Repo,
57
- ResetCommitOptions,
58
- ResetCommitResult,
57
+ RestoreCommitOptions,
58
+ RestoreCommitResult,
59
59
  ValidAPIVersion,
60
60
  } from './types';
61
61
 
@@ -84,7 +84,7 @@ const API_VERSION: ValidAPIVersion = 1;
84
84
 
85
85
  const apiInstanceMap = new Map<string, ApiFetcher>();
86
86
  const DEFAULT_TOKEN_TTL_SECONDS = 60 * 60; // 1 hour
87
- const RESET_COMMIT_ALLOWED_STATUS = [
87
+ const RESTORE_COMMIT_ALLOWED_STATUS = [
88
88
  400, // Bad Request - validation errors
89
89
  401, // Unauthorized - missing/invalid auth header
90
90
  403, // Forbidden - missing git:write scope
@@ -111,9 +111,9 @@ function resolveInvocationTtlSeconds(
111
111
  return defaultValue;
112
112
  }
113
113
 
114
- type ResetCommitAck = ResetCommitAckRaw;
114
+ type RestoreCommitAck = RestoreCommitAckRaw;
115
115
 
116
- function toRefUpdate(result: ResetCommitAck['result']): RefUpdate {
116
+ function toRefUpdate(result: RestoreCommitAck['result']): RefUpdate {
117
117
  return {
118
118
  branch: result.branch,
119
119
  oldSha: result.old_sha,
@@ -121,11 +121,11 @@ function toRefUpdate(result: ResetCommitAck['result']): RefUpdate {
121
121
  };
122
122
  }
123
123
 
124
- function buildResetCommitResult(ack: ResetCommitAck): ResetCommitResult {
124
+ function buildRestoreCommitResult(ack: RestoreCommitAck): RestoreCommitResult {
125
125
  const refUpdate = toRefUpdate(ack.result);
126
126
  if (!ack.result.success) {
127
127
  throw new RefUpdateError(
128
- ack.result.message ?? `Reset commit failed with status ${ack.result.status}`,
128
+ ack.result.message ?? `Restore commit failed with status ${ack.result.status}`,
129
129
  {
130
130
  status: ack.result.status,
131
131
  message: ack.result.message,
@@ -142,7 +142,7 @@ function buildResetCommitResult(ack: ResetCommitAck): ResetCommitResult {
142
142
  };
143
143
  }
144
144
 
145
- interface ResetCommitFailureInfo {
145
+ interface RestoreCommitFailureInfo {
146
146
  status?: string;
147
147
  message?: string;
148
148
  refUpdate?: Partial<RefUpdate>;
@@ -166,15 +166,15 @@ function toPartialRefUpdate(
166
166
  return Object.keys(refUpdate).length > 0 ? refUpdate : undefined;
167
167
  }
168
168
 
169
- function parseResetCommitPayload(
169
+ function parseRestoreCommitPayload(
170
170
  payload: unknown,
171
- ): { ack: ResetCommitAck } | { failure: ResetCommitFailureInfo } | null {
172
- const ack = resetCommitAckSchema.safeParse(payload);
171
+ ): { ack: RestoreCommitAck } | { failure: RestoreCommitFailureInfo } | null {
172
+ const ack = restoreCommitAckSchema.safeParse(payload);
173
173
  if (ack.success) {
174
174
  return { ack: ack.data };
175
175
  }
176
176
 
177
- const failure = resetCommitResponseSchema.safeParse(payload);
177
+ const failure = restoreCommitResponseSchema.safeParse(payload);
178
178
  if (failure.success) {
179
179
  const result = failure.data.result;
180
180
  return {
@@ -189,7 +189,7 @@ function parseResetCommitPayload(
189
189
  return null;
190
190
  }
191
191
 
192
- function httpStatusToResetStatus(status: number): string {
192
+ function httpStatusToRestoreStatus(status: number): string {
193
193
  switch (status) {
194
194
  case 409:
195
195
  return 'conflict';
@@ -500,25 +500,25 @@ class RepoImpl implements Repo {
500
500
  return;
501
501
  }
502
502
 
503
- async resetCommit(options: ResetCommitOptions): Promise<ResetCommitResult> {
503
+ async restoreCommit(options: RestoreCommitOptions): Promise<RestoreCommitResult> {
504
504
  const targetBranch = options?.targetBranch?.trim();
505
505
  if (!targetBranch) {
506
- throw new Error('resetCommit targetBranch is required');
506
+ throw new Error('restoreCommit targetBranch is required');
507
507
  }
508
508
  if (targetBranch.startsWith('refs/')) {
509
- throw new Error('resetCommit targetBranch must not include refs/ prefix');
509
+ throw new Error('restoreCommit targetBranch must not include refs/ prefix');
510
510
  }
511
511
 
512
512
  const targetCommitSha = options?.targetCommitSha?.trim();
513
513
  if (!targetCommitSha) {
514
- throw new Error('resetCommit targetCommitSha is required');
514
+ throw new Error('restoreCommit targetCommitSha is required');
515
515
  }
516
516
  const commitMessage = options?.commitMessage?.trim();
517
517
 
518
518
  const authorName = options.author?.name?.trim();
519
519
  const authorEmail = options.author?.email?.trim();
520
520
  if (!authorName || !authorEmail) {
521
- throw new Error('resetCommit author name and email are required');
521
+ throw new Error('restoreCommit author name and email are required');
522
522
  }
523
523
 
524
524
  const ttl = resolveCommitTtlSeconds(options);
@@ -549,7 +549,7 @@ class RepoImpl implements Repo {
549
549
  const committerName = options.committer.name?.trim();
550
550
  const committerEmail = options.committer.email?.trim();
551
551
  if (!committerName || !committerEmail) {
552
- throw new Error('resetCommit committer name and email are required when provided');
552
+ throw new Error('restoreCommit committer name and email are required when provided');
553
553
  }
554
554
  metadata.committer = {
555
555
  name: committerName,
@@ -557,21 +557,25 @@ class RepoImpl implements Repo {
557
557
  };
558
558
  }
559
559
 
560
- const response = await this.api.post({ path: 'repos/reset-commits', body: { metadata } }, jwt, {
561
- allowedStatus: [...RESET_COMMIT_ALLOWED_STATUS],
562
- });
560
+ const response = await this.api.post(
561
+ { path: 'repos/restore-commit', body: { metadata } },
562
+ jwt,
563
+ {
564
+ allowedStatus: [...RESTORE_COMMIT_ALLOWED_STATUS],
565
+ },
566
+ );
563
567
 
564
568
  const payload = await response.json();
565
- const parsed = parseResetCommitPayload(payload);
569
+ const parsed = parseRestoreCommitPayload(payload);
566
570
  if (parsed && 'ack' in parsed) {
567
- return buildResetCommitResult(parsed.ack);
571
+ return buildRestoreCommitResult(parsed.ack);
568
572
  }
569
573
 
570
574
  const failure = parsed && 'failure' in parsed ? parsed.failure : undefined;
571
- const status = failure?.status ?? httpStatusToResetStatus(response.status);
575
+ const status = failure?.status ?? httpStatusToRestoreStatus(response.status);
572
576
  const message =
573
577
  failure?.message ??
574
- `Reset commit failed with HTTP ${response.status}` +
578
+ `Restore commit failed with HTTP ${response.status}` +
575
579
  (response.statusText ? ` ${response.statusText}` : '');
576
580
 
577
581
  throw new RefUpdateError(message, {
package/src/schemas.ts CHANGED
@@ -90,7 +90,7 @@ export const commitPackCommitSchema = z.object({
90
90
  blob_count: z.number(),
91
91
  });
92
92
 
93
- export const resetCommitCommitSchema = commitPackCommitSchema.omit({ blob_count: true });
93
+ export const restoreCommitCommitSchema = commitPackCommitSchema.omit({ blob_count: true });
94
94
 
95
95
  export const refUpdateResultWithOptionalsSchema = z.object({
96
96
  branch: z.string().optional(),
@@ -106,8 +106,8 @@ export const commitPackAckSchema = z.object({
106
106
  result: refUpdateResultSchema,
107
107
  });
108
108
 
109
- export const resetCommitAckSchema = z.object({
110
- commit: resetCommitCommitSchema,
109
+ export const restoreCommitAckSchema = z.object({
110
+ commit: restoreCommitCommitSchema,
111
111
  result: refUpdateResultSchema.extend({ success: z.literal(true) }),
112
112
  });
113
113
 
@@ -116,8 +116,8 @@ export const commitPackResponseSchema = z.object({
116
116
  result: refUpdateResultWithOptionalsSchema,
117
117
  });
118
118
 
119
- export const resetCommitResponseSchema = z.object({
120
- commit: resetCommitCommitSchema.partial().optional().nullable(),
119
+ export const restoreCommitResponseSchema = z.object({
120
+ commit: restoreCommitCommitSchema.partial().optional().nullable(),
121
121
  result: refUpdateResultWithOptionalsSchema,
122
122
  });
123
123
 
@@ -135,4 +135,4 @@ export type RawFilteredFile = z.infer<typeof filteredFileRawSchema>;
135
135
  export type GetBranchDiffResponseRaw = z.infer<typeof branchDiffResponseSchema>;
136
136
  export type GetCommitDiffResponseRaw = z.infer<typeof commitDiffResponseSchema>;
137
137
  export type CommitPackAckRaw = z.infer<typeof commitPackAckSchema>;
138
- export type ResetCommitAckRaw = z.infer<typeof resetCommitAckSchema>;
138
+ export type RestoreCommitAckRaw = z.infer<typeof restoreCommitAckSchema>;
package/src/types.ts CHANGED
@@ -45,7 +45,7 @@ export interface Repo {
45
45
  getBranchDiff(options: GetBranchDiffOptions): Promise<GetBranchDiffResult>;
46
46
  getCommitDiff(options: GetCommitDiffOptions): Promise<GetCommitDiffResult>;
47
47
  pullUpstream(options: PullUpstreamOptions): Promise<void>;
48
- resetCommit(options: ResetCommitOptions): Promise<ResetCommitResult>;
48
+ restoreCommit(options: RestoreCommitOptions): Promise<RestoreCommitResult>;
49
49
  createCommit(options: CreateCommitOptions): CommitBuilder;
50
50
  }
51
51
 
@@ -325,7 +325,7 @@ export interface CommitResult {
325
325
  refUpdate: RefUpdate;
326
326
  }
327
327
 
328
- export interface ResetCommitOptions extends GitStorageInvocationOptions {
328
+ export interface RestoreCommitOptions extends GitStorageInvocationOptions {
329
329
  targetBranch: string;
330
330
  targetCommitSha: string;
331
331
  commitMessage?: string;
@@ -334,7 +334,7 @@ export interface ResetCommitOptions extends GitStorageInvocationOptions {
334
334
  committer?: CommitSignature;
335
335
  }
336
336
 
337
- export interface ResetCommitResult {
337
+ export interface RestoreCommitResult {
338
338
  commitSha: string;
339
339
  treeSha: string;
340
340
  targetBranch: string;