@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/dist/index.d.cts CHANGED
@@ -631,6 +631,7 @@ interface Repo {
631
631
  getRemoteURL(options?: GetRemoteURLOptions): Promise<string>;
632
632
  getEphemeralRemoteURL(options?: GetRemoteURLOptions): Promise<string>;
633
633
  getFileStream(options: GetFileOptions): Promise<Response>;
634
+ getArchiveStream(options?: ArchiveOptions): Promise<Response>;
634
635
  listFiles(options?: ListFilesOptions): Promise<ListFilesResult>;
635
636
  listBranches(options?: ListBranchesOptions): Promise<ListBranchesResult>;
636
637
  listCommits(options?: ListCommitsOptions): Promise<ListCommitsResult>;
@@ -719,6 +720,12 @@ interface GetFileOptions extends GitStorageInvocationOptions {
719
720
  ephemeral?: boolean;
720
721
  ephemeralBase?: boolean;
721
722
  }
723
+ interface ArchiveOptions extends GitStorageInvocationOptions {
724
+ ref?: string;
725
+ includeGlobs?: string[];
726
+ excludeGlobs?: string[];
727
+ archivePrefix?: string;
728
+ }
722
729
  interface PullUpstreamOptions extends GitStorageInvocationOptions {
723
730
  ref?: string;
724
731
  }
@@ -849,6 +856,10 @@ interface GetCommitDiffResult {
849
856
  }
850
857
  interface GrepOptions extends GitStorageInvocationOptions {
851
858
  ref?: string;
859
+ /**
860
+ * @deprecated Use ref instead.
861
+ */
862
+ rev?: string;
852
863
  paths?: string[];
853
864
  query: {
854
865
  pattern: string;
@@ -1172,12 +1183,6 @@ declare function validateWebhook(payload: string | Buffer, headers: Record<strin
1172
1183
  payload?: WebhookEventPayload;
1173
1184
  }>;
1174
1185
 
1175
- /**
1176
- * Pierre Git Storage SDK
1177
- *
1178
- * A TypeScript SDK for interacting with Pierre's git storage system
1179
- */
1180
-
1181
1186
  declare class GitStorage {
1182
1187
  private options;
1183
1188
  private api;
@@ -1221,4 +1226,4 @@ declare function createClient(options: GitStorageOptions): GitStorage;
1221
1226
 
1222
1227
  type StorageOptions = GitStorageOptions;
1223
1228
 
1224
- export { ApiError, type AppendNoteOptions, type BaseRepo, type BlobLike, type BranchInfo, GitStorage as CodeStorage, type CommitBuilder, type CommitFileOptions, type CommitFileSource, type CommitInfo, type CommitResult, type CommitSignature, type CommitTextFileOptions, type CreateBranchOptions, type CreateBranchResponse, type CreateBranchResult, type CreateCommitBranchOptions, type CreateCommitFromDiffOptions, type CreateCommitOptions, type CreateNoteOptions, type CreateRepoOptions, type DeleteNoteOptions, type DeleteRepoOptions, type DeleteRepoResult, type DiffFileBase, type DiffFileState, type DiffSource, type DiffStats, type FileDiff, type FileLike, type FilteredFile, type FindOneOptions, type ForkBaseRepo, type GetBranchDiffOptions, type GetBranchDiffResponse, type GetBranchDiffResult, type GetCommitDiffOptions, type GetCommitDiffResponse, type GetCommitDiffResult, type GetFileOptions, type GetNoteOptions, type GetNoteResponse, type GetNoteResult, type GetRemoteURLOptions, type GitFileMode, type GitHubBaseRepo, GitStorage, type GitStorageOptions, type GrepFileMatch, type GrepLine, type GrepOptions, type GrepResult, type LegacyCreateCommitOptions, type ListBranchesOptions, type ListBranchesResponse, type ListBranchesResult, type ListCommitsOptions, type ListCommitsResponse, type ListCommitsResult, type ListFilesOptions, type ListFilesResponse, type ListFilesResult, type ListReposOptions, type ListReposResponse, type ListReposResult, type NoteWriteResponse, type NoteWriteResult, type NoteWriteResultPayload, type OverrideableGitStorageOptions, type ParsedWebhookSignature, type PullUpstreamOptions, type RawBranchInfo, type RawCommitInfo, type RawFileDiff, type RawFilteredFile, type RawRepoBaseInfo, type RawRepoInfo, type RawWebhookPushEvent, type ReadableStreamLike, type ReadableStreamReaderLike, type RefUpdate, RefUpdateError, type RefUpdateReason, type Repo, type RepoBaseInfo, type RepoInfo, type RestoreCommitOptions, type RestoreCommitResult, type StorageOptions, type SupportedRepoProvider, type TextEncoding, type ValidAPIVersion, type ValidMethod, type ValidPath, type WebhookEventPayload, type WebhookPushEvent, type WebhookUnknownEvent, type WebhookValidationOptions, type WebhookValidationResult, createClient, parseSignatureHeader, validateWebhook, validateWebhookSignature };
1229
+ export { ApiError, type AppendNoteOptions, type ArchiveOptions, type BaseRepo, type BlobLike, type BranchInfo, GitStorage as CodeStorage, type CommitBuilder, type CommitFileOptions, type CommitFileSource, type CommitInfo, type CommitResult, type CommitSignature, type CommitTextFileOptions, type CreateBranchOptions, type CreateBranchResponse, type CreateBranchResult, type CreateCommitBranchOptions, type CreateCommitFromDiffOptions, type CreateCommitOptions, type CreateNoteOptions, type CreateRepoOptions, type DeleteNoteOptions, type DeleteRepoOptions, type DeleteRepoResult, type DiffFileBase, type DiffFileState, type DiffSource, type DiffStats, type FileDiff, type FileLike, type FilteredFile, type FindOneOptions, type ForkBaseRepo, type GetBranchDiffOptions, type GetBranchDiffResponse, type GetBranchDiffResult, type GetCommitDiffOptions, type GetCommitDiffResponse, type GetCommitDiffResult, type GetFileOptions, type GetNoteOptions, type GetNoteResponse, type GetNoteResult, type GetRemoteURLOptions, type GitFileMode, type GitHubBaseRepo, GitStorage, type GitStorageOptions, type GrepFileMatch, type GrepLine, type GrepOptions, type GrepResult, type LegacyCreateCommitOptions, type ListBranchesOptions, type ListBranchesResponse, type ListBranchesResult, type ListCommitsOptions, type ListCommitsResponse, type ListCommitsResult, type ListFilesOptions, type ListFilesResponse, type ListFilesResult, type ListReposOptions, type ListReposResponse, type ListReposResult, type NoteWriteResponse, type NoteWriteResult, type NoteWriteResultPayload, type OverrideableGitStorageOptions, type ParsedWebhookSignature, type PullUpstreamOptions, type RawBranchInfo, type RawCommitInfo, type RawFileDiff, type RawFilteredFile, type RawRepoBaseInfo, type RawRepoInfo, type RawWebhookPushEvent, type ReadableStreamLike, type ReadableStreamReaderLike, type RefUpdate, RefUpdateError, type RefUpdateReason, type Repo, type RepoBaseInfo, type RepoInfo, type RestoreCommitOptions, type RestoreCommitResult, type StorageOptions, type SupportedRepoProvider, type TextEncoding, type ValidAPIVersion, type ValidMethod, type ValidPath, type WebhookEventPayload, type WebhookPushEvent, type WebhookUnknownEvent, type WebhookValidationOptions, type WebhookValidationResult, createClient, parseSignatureHeader, validateWebhook, validateWebhookSignature };
package/dist/index.d.ts CHANGED
@@ -631,6 +631,7 @@ interface Repo {
631
631
  getRemoteURL(options?: GetRemoteURLOptions): Promise<string>;
632
632
  getEphemeralRemoteURL(options?: GetRemoteURLOptions): Promise<string>;
633
633
  getFileStream(options: GetFileOptions): Promise<Response>;
634
+ getArchiveStream(options?: ArchiveOptions): Promise<Response>;
634
635
  listFiles(options?: ListFilesOptions): Promise<ListFilesResult>;
635
636
  listBranches(options?: ListBranchesOptions): Promise<ListBranchesResult>;
636
637
  listCommits(options?: ListCommitsOptions): Promise<ListCommitsResult>;
@@ -719,6 +720,12 @@ interface GetFileOptions extends GitStorageInvocationOptions {
719
720
  ephemeral?: boolean;
720
721
  ephemeralBase?: boolean;
721
722
  }
723
+ interface ArchiveOptions extends GitStorageInvocationOptions {
724
+ ref?: string;
725
+ includeGlobs?: string[];
726
+ excludeGlobs?: string[];
727
+ archivePrefix?: string;
728
+ }
722
729
  interface PullUpstreamOptions extends GitStorageInvocationOptions {
723
730
  ref?: string;
724
731
  }
@@ -849,6 +856,10 @@ interface GetCommitDiffResult {
849
856
  }
850
857
  interface GrepOptions extends GitStorageInvocationOptions {
851
858
  ref?: string;
859
+ /**
860
+ * @deprecated Use ref instead.
861
+ */
862
+ rev?: string;
852
863
  paths?: string[];
853
864
  query: {
854
865
  pattern: string;
@@ -1172,12 +1183,6 @@ declare function validateWebhook(payload: string | Buffer, headers: Record<strin
1172
1183
  payload?: WebhookEventPayload;
1173
1184
  }>;
1174
1185
 
1175
- /**
1176
- * Pierre Git Storage SDK
1177
- *
1178
- * A TypeScript SDK for interacting with Pierre's git storage system
1179
- */
1180
-
1181
1186
  declare class GitStorage {
1182
1187
  private options;
1183
1188
  private api;
@@ -1221,4 +1226,4 @@ declare function createClient(options: GitStorageOptions): GitStorage;
1221
1226
 
1222
1227
  type StorageOptions = GitStorageOptions;
1223
1228
 
1224
- export { ApiError, type AppendNoteOptions, type BaseRepo, type BlobLike, type BranchInfo, GitStorage as CodeStorage, type CommitBuilder, type CommitFileOptions, type CommitFileSource, type CommitInfo, type CommitResult, type CommitSignature, type CommitTextFileOptions, type CreateBranchOptions, type CreateBranchResponse, type CreateBranchResult, type CreateCommitBranchOptions, type CreateCommitFromDiffOptions, type CreateCommitOptions, type CreateNoteOptions, type CreateRepoOptions, type DeleteNoteOptions, type DeleteRepoOptions, type DeleteRepoResult, type DiffFileBase, type DiffFileState, type DiffSource, type DiffStats, type FileDiff, type FileLike, type FilteredFile, type FindOneOptions, type ForkBaseRepo, type GetBranchDiffOptions, type GetBranchDiffResponse, type GetBranchDiffResult, type GetCommitDiffOptions, type GetCommitDiffResponse, type GetCommitDiffResult, type GetFileOptions, type GetNoteOptions, type GetNoteResponse, type GetNoteResult, type GetRemoteURLOptions, type GitFileMode, type GitHubBaseRepo, GitStorage, type GitStorageOptions, type GrepFileMatch, type GrepLine, type GrepOptions, type GrepResult, type LegacyCreateCommitOptions, type ListBranchesOptions, type ListBranchesResponse, type ListBranchesResult, type ListCommitsOptions, type ListCommitsResponse, type ListCommitsResult, type ListFilesOptions, type ListFilesResponse, type ListFilesResult, type ListReposOptions, type ListReposResponse, type ListReposResult, type NoteWriteResponse, type NoteWriteResult, type NoteWriteResultPayload, type OverrideableGitStorageOptions, type ParsedWebhookSignature, type PullUpstreamOptions, type RawBranchInfo, type RawCommitInfo, type RawFileDiff, type RawFilteredFile, type RawRepoBaseInfo, type RawRepoInfo, type RawWebhookPushEvent, type ReadableStreamLike, type ReadableStreamReaderLike, type RefUpdate, RefUpdateError, type RefUpdateReason, type Repo, type RepoBaseInfo, type RepoInfo, type RestoreCommitOptions, type RestoreCommitResult, type StorageOptions, type SupportedRepoProvider, type TextEncoding, type ValidAPIVersion, type ValidMethod, type ValidPath, type WebhookEventPayload, type WebhookPushEvent, type WebhookUnknownEvent, type WebhookValidationOptions, type WebhookValidationResult, createClient, parseSignatureHeader, validateWebhook, validateWebhookSignature };
1229
+ export { ApiError, type AppendNoteOptions, type ArchiveOptions, type BaseRepo, type BlobLike, type BranchInfo, GitStorage as CodeStorage, type CommitBuilder, type CommitFileOptions, type CommitFileSource, type CommitInfo, type CommitResult, type CommitSignature, type CommitTextFileOptions, type CreateBranchOptions, type CreateBranchResponse, type CreateBranchResult, type CreateCommitBranchOptions, type CreateCommitFromDiffOptions, type CreateCommitOptions, type CreateNoteOptions, type CreateRepoOptions, type DeleteNoteOptions, type DeleteRepoOptions, type DeleteRepoResult, type DiffFileBase, type DiffFileState, type DiffSource, type DiffStats, type FileDiff, type FileLike, type FilteredFile, type FindOneOptions, type ForkBaseRepo, type GetBranchDiffOptions, type GetBranchDiffResponse, type GetBranchDiffResult, type GetCommitDiffOptions, type GetCommitDiffResponse, type GetCommitDiffResult, type GetFileOptions, type GetNoteOptions, type GetNoteResponse, type GetNoteResult, type GetRemoteURLOptions, type GitFileMode, type GitHubBaseRepo, GitStorage, type GitStorageOptions, type GrepFileMatch, type GrepLine, type GrepOptions, type GrepResult, type LegacyCreateCommitOptions, type ListBranchesOptions, type ListBranchesResponse, type ListBranchesResult, type ListCommitsOptions, type ListCommitsResponse, type ListCommitsResult, type ListFilesOptions, type ListFilesResponse, type ListFilesResult, type ListReposOptions, type ListReposResponse, type ListReposResult, type NoteWriteResponse, type NoteWriteResult, type NoteWriteResultPayload, type OverrideableGitStorageOptions, type ParsedWebhookSignature, type PullUpstreamOptions, type RawBranchInfo, type RawCommitInfo, type RawFileDiff, type RawFilteredFile, type RawRepoBaseInfo, type RawRepoInfo, type RawWebhookPushEvent, type ReadableStreamLike, type ReadableStreamReaderLike, type RefUpdate, RefUpdateError, type RefUpdateReason, type Repo, type RepoBaseInfo, type RepoInfo, type RestoreCommitOptions, type RestoreCommitResult, type StorageOptions, type SupportedRepoProvider, type TextEncoding, type ValidAPIVersion, type ValidMethod, type ValidPath, type WebhookEventPayload, type WebhookPushEvent, type WebhookUnknownEvent, type WebhookValidationOptions, type WebhookValidationResult, createClient, parseSignatureHeader, validateWebhook, validateWebhookSignature };
package/dist/index.js CHANGED
@@ -159,7 +159,9 @@ var commitPackCommitSchema = z.object({
159
159
  pack_bytes: z.number(),
160
160
  blob_count: z.number()
161
161
  });
162
- var restoreCommitCommitSchema = commitPackCommitSchema.omit({ blob_count: true });
162
+ var restoreCommitCommitSchema = commitPackCommitSchema.omit({
163
+ blob_count: true
164
+ });
163
165
  var refUpdateResultWithOptionalsSchema = z.object({
164
166
  branch: z.string().optional(),
165
167
  old_sha: z.string().optional(),
@@ -269,7 +271,11 @@ async function parseCommitPackError(response, fallbackMessage) {
269
271
  if (typeof result.status === "string" && result.status.trim() !== "") {
270
272
  statusLabel = result.status.trim();
271
273
  }
272
- refUpdate = toPartialRefUpdateFields(result.branch, result.old_sha, result.new_sha);
274
+ refUpdate = toPartialRefUpdateFields(
275
+ result.branch,
276
+ result.old_sha,
277
+ result.new_sha
278
+ );
273
279
  if (typeof result.message === "string" && result.message.trim() !== "") {
274
280
  message = result.message.trim();
275
281
  }
@@ -500,7 +506,7 @@ function concatChunks(a, b) {
500
506
 
501
507
  // package.json
502
508
  var package_default = {
503
- version: "0.9.2"};
509
+ version: "1.0.0"};
504
510
 
505
511
  // src/version.ts
506
512
  var PACKAGE_NAME = "code-storage-sdk";
@@ -546,7 +552,9 @@ var CommitBuilderImpl = class {
546
552
  delete this.options.baseBranch;
547
553
  } else {
548
554
  if (trimmedBase.startsWith("refs/")) {
549
- throw new Error("createCommit baseBranch must not include refs/ prefix");
555
+ throw new Error(
556
+ "createCommit baseBranch must not include refs/ prefix"
557
+ );
550
558
  }
551
559
  this.options.baseBranch = trimmedBase;
552
560
  }
@@ -693,10 +701,7 @@ var FetchCommitTransport = class {
693
701
  const response = await fetch(this.url, init);
694
702
  if (!response.ok) {
695
703
  const fallbackMessage = `createCommit request failed (${response.status} ${response.statusText})`;
696
- const { statusMessage, statusLabel, refUpdate } = await parseCommitPackError(
697
- response,
698
- fallbackMessage
699
- );
704
+ const { statusMessage, statusLabel, refUpdate } = await parseCommitPackError(response, fallbackMessage);
700
705
  throw new RefUpdateError(statusMessage, {
701
706
  status: statusLabel,
702
707
  message: statusMessage,
@@ -823,7 +828,9 @@ var DiffCommitExecutor = class {
823
828
  throw new Error("createCommitFromDiff commitMessage is required");
824
829
  }
825
830
  if (!trimmedAuthorName || !trimmedAuthorEmail) {
826
- throw new Error("createCommitFromDiff author name and email are required");
831
+ throw new Error(
832
+ "createCommitFromDiff author name and email are required"
833
+ );
827
834
  }
828
835
  this.options.commitMessage = trimmedMessage;
829
836
  this.options.author = {
@@ -839,7 +846,9 @@ var DiffCommitExecutor = class {
839
846
  delete this.options.baseBranch;
840
847
  } else {
841
848
  if (trimmedBase.startsWith("refs/")) {
842
- throw new Error("createCommitFromDiff baseBranch must not include refs/ prefix");
849
+ throw new Error(
850
+ "createCommitFromDiff baseBranch must not include refs/ prefix"
851
+ );
843
852
  }
844
853
  this.options.baseBranch = trimmedBase;
845
854
  }
@@ -905,7 +914,10 @@ var FetchDiffCommitTransport = class {
905
914
  this.url = `${trimmedBase}/api/v${config.version}/repos/diff-commit`;
906
915
  }
907
916
  async send(request) {
908
- const bodyIterable = buildMessageIterable2(request.metadata, request.diffChunks);
917
+ const bodyIterable = buildMessageIterable2(
918
+ request.metadata,
919
+ request.diffChunks
920
+ );
909
921
  const body = toRequestBody(bodyIterable);
910
922
  const init = {
911
923
  method: "POST",
@@ -924,10 +936,7 @@ var FetchDiffCommitTransport = class {
924
936
  const response = await fetch(this.url, init);
925
937
  if (!response.ok) {
926
938
  const fallbackMessage = `createCommitFromDiff request failed (${response.status} ${response.statusText})`;
927
- const { statusMessage, statusLabel, refUpdate } = await parseCommitPackError(
928
- response,
929
- fallbackMessage
930
- );
939
+ const { statusMessage, statusLabel, refUpdate } = await parseCommitPackError(response, fallbackMessage);
931
940
  throw new RefUpdateError(statusMessage, {
932
941
  status: statusLabel,
933
942
  message: statusMessage,
@@ -969,7 +978,9 @@ function normalizeDiffCommitOptions(options) {
969
978
  const name = options.committer.name?.trim();
970
979
  const email = options.committer.email?.trim();
971
980
  if (!name || !email) {
972
- throw new Error("createCommitFromDiff committer name and email are required when provided");
981
+ throw new Error(
982
+ "createCommitFromDiff committer name and email are required when provided"
983
+ );
973
984
  }
974
985
  committer = { name, email };
975
986
  }
@@ -995,12 +1006,16 @@ function normalizeBranchName2(value) {
995
1006
  if (trimmed.startsWith("refs/heads/")) {
996
1007
  const branch = trimmed.slice("refs/heads/".length).trim();
997
1008
  if (!branch) {
998
- throw new Error("createCommitFromDiff targetBranch must include a branch name");
1009
+ throw new Error(
1010
+ "createCommitFromDiff targetBranch must include a branch name"
1011
+ );
999
1012
  }
1000
1013
  return branch;
1001
1014
  }
1002
1015
  if (trimmed.startsWith("refs/")) {
1003
- throw new Error("createCommitFromDiff targetBranch must not include refs/ prefix");
1016
+ throw new Error(
1017
+ "createCommitFromDiff targetBranch must not include refs/ prefix"
1018
+ );
1004
1019
  }
1005
1020
  return trimmed;
1006
1021
  }
@@ -1480,7 +1495,11 @@ function parseRestoreCommitPayload(payload) {
1480
1495
  failure: {
1481
1496
  status: result.status,
1482
1497
  message: result.message,
1483
- refUpdate: toPartialRefUpdate(result.branch, result.old_sha, result.new_sha)
1498
+ refUpdate: toPartialRefUpdate(
1499
+ result.branch,
1500
+ result.old_sha,
1501
+ result.new_sha
1502
+ )
1484
1503
  }
1485
1504
  };
1486
1505
  }
@@ -1498,7 +1517,10 @@ function httpStatusToRestoreStatus(status) {
1498
1517
  }
1499
1518
  function getApiInstance(baseUrl, version) {
1500
1519
  if (!apiInstanceMap.has(`${baseUrl}--${version}`)) {
1501
- apiInstanceMap.set(`${baseUrl}--${version}`, new ApiFetcher(baseUrl, version));
1520
+ apiInstanceMap.set(
1521
+ `${baseUrl}--${version}`,
1522
+ new ApiFetcher(baseUrl, version)
1523
+ );
1502
1524
  }
1503
1525
  return apiInstanceMap.get(`${baseUrl}--${version}`);
1504
1526
  }
@@ -1734,13 +1756,17 @@ var RepoImpl = class {
1734
1756
  }
1735
1757
  api;
1736
1758
  async getRemoteURL(urlOptions) {
1737
- const url = new URL(`https://${this.options.storageBaseUrl}/${this.id}.git`);
1759
+ const url = new URL(
1760
+ `https://${this.options.storageBaseUrl}/${this.id}.git`
1761
+ );
1738
1762
  url.username = `t`;
1739
1763
  url.password = await this.generateJWT(this.id, urlOptions);
1740
1764
  return url.toString();
1741
1765
  }
1742
1766
  async getEphemeralRemoteURL(urlOptions) {
1743
- const url = new URL(`https://${this.options.storageBaseUrl}/${this.id}+ephemeral.git`);
1767
+ const url = new URL(
1768
+ `https://${this.options.storageBaseUrl}/${this.id}+ephemeral.git`
1769
+ );
1744
1770
  url.username = `t`;
1745
1771
  url.password = await this.generateJWT(this.id, urlOptions);
1746
1772
  return url.toString();
@@ -1765,6 +1791,32 @@ var RepoImpl = class {
1765
1791
  }
1766
1792
  return this.api.get({ path: "repos/file", params }, jwt);
1767
1793
  }
1794
+ async getArchiveStream(options = {}) {
1795
+ const ttl = resolveInvocationTtlSeconds(options, DEFAULT_TOKEN_TTL_SECONDS);
1796
+ const jwt = await this.generateJWT(this.id, {
1797
+ permissions: ["git:read"],
1798
+ ttl
1799
+ });
1800
+ const body = {};
1801
+ const ref = options.ref?.trim();
1802
+ if (ref) {
1803
+ body.ref = ref;
1804
+ }
1805
+ if (Array.isArray(options.includeGlobs) && options.includeGlobs.length > 0) {
1806
+ body.include_globs = options.includeGlobs;
1807
+ }
1808
+ if (Array.isArray(options.excludeGlobs) && options.excludeGlobs.length > 0) {
1809
+ body.exclude_globs = options.excludeGlobs;
1810
+ }
1811
+ if (typeof options.archivePrefix === "string") {
1812
+ const prefix = options.archivePrefix.trim();
1813
+ if (prefix) {
1814
+ body.archive = { prefix };
1815
+ }
1816
+ }
1817
+ const path = Object.keys(body).length > 0 ? { path: "repos/archive", body } : "repos/archive";
1818
+ return this.api.post(path, jwt);
1819
+ }
1768
1820
  async listFiles(options) {
1769
1821
  const ttl = resolveInvocationTtlSeconds(options, DEFAULT_TOKEN_TTL_SECONDS);
1770
1822
  const jwt = await this.generateJWT(this.id, {
@@ -1779,7 +1831,10 @@ var RepoImpl = class {
1779
1831
  params.ephemeral = String(options.ephemeral);
1780
1832
  }
1781
1833
  const response = await this.api.get(
1782
- { path: "repos/files", params: Object.keys(params).length ? params : void 0 },
1834
+ {
1835
+ path: "repos/files",
1836
+ params: Object.keys(params).length ? params : void 0
1837
+ },
1783
1838
  jwt
1784
1839
  );
1785
1840
  const raw = listFilesResponseSchema.parse(await response.json());
@@ -1803,7 +1858,10 @@ var RepoImpl = class {
1803
1858
  params.limit = limit.toString();
1804
1859
  }
1805
1860
  }
1806
- const response = await this.api.get({ path: "repos/branches", params }, jwt);
1861
+ const response = await this.api.get(
1862
+ { path: "repos/branches", params },
1863
+ jwt
1864
+ );
1807
1865
  const raw = listBranchesResponseSchema.parse(await response.json());
1808
1866
  return transformListBranchesResult({
1809
1867
  ...raw,
@@ -1846,7 +1904,10 @@ var RepoImpl = class {
1846
1904
  permissions: ["git:read"],
1847
1905
  ttl
1848
1906
  });
1849
- const response = await this.api.get({ path: "repos/notes", params: { sha } }, jwt);
1907
+ const response = await this.api.get(
1908
+ { path: "repos/notes", params: { sha } },
1909
+ jwt
1910
+ );
1850
1911
  const raw = noteReadResponseSchema.parse(await response.json());
1851
1912
  return transformNoteReadResult(raw);
1852
1913
  }
@@ -1878,7 +1939,11 @@ var RepoImpl = class {
1878
1939
  {
1879
1940
  status: result.result.status,
1880
1941
  message: result.result.message,
1881
- refUpdate: toPartialRefUpdate(result.targetRef, result.baseCommit, result.newRefSha)
1942
+ refUpdate: toPartialRefUpdate(
1943
+ result.targetRef,
1944
+ result.baseCommit,
1945
+ result.newRefSha
1946
+ )
1882
1947
  }
1883
1948
  );
1884
1949
  }
@@ -1912,7 +1977,11 @@ var RepoImpl = class {
1912
1977
  {
1913
1978
  status: result.result.status,
1914
1979
  message: result.result.message,
1915
- refUpdate: toPartialRefUpdate(result.targetRef, result.baseCommit, result.newRefSha)
1980
+ refUpdate: toPartialRefUpdate(
1981
+ result.targetRef,
1982
+ result.baseCommit,
1983
+ result.newRefSha
1984
+ )
1916
1985
  }
1917
1986
  );
1918
1987
  }
@@ -1939,7 +2008,9 @@ var RepoImpl = class {
1939
2008
  const authorName = options.author.name?.trim();
1940
2009
  const authorEmail = options.author.email?.trim();
1941
2010
  if (!authorName || !authorEmail) {
1942
- throw new Error("deleteNote author name and email are required when provided");
2011
+ throw new Error(
2012
+ "deleteNote author name and email are required when provided"
2013
+ );
1943
2014
  }
1944
2015
  body.author = {
1945
2016
  name: authorName,
@@ -1956,7 +2027,11 @@ var RepoImpl = class {
1956
2027
  {
1957
2028
  status: result.result.status,
1958
2029
  message: result.result.message,
1959
- refUpdate: toPartialRefUpdate(result.targetRef, result.baseCommit, result.newRefSha)
2030
+ refUpdate: toPartialRefUpdate(
2031
+ result.targetRef,
2032
+ result.baseCommit,
2033
+ result.newRefSha
2034
+ )
1960
2035
  }
1961
2036
  );
1962
2037
  }
@@ -1983,7 +2058,10 @@ var RepoImpl = class {
1983
2058
  if (options.paths && options.paths.length > 0) {
1984
2059
  params.path = options.paths;
1985
2060
  }
1986
- const response = await this.api.get({ path: "repos/branches/diff", params }, jwt);
2061
+ const response = await this.api.get(
2062
+ { path: "repos/branches/diff", params },
2063
+ jwt
2064
+ );
1987
2065
  const raw = branchDiffResponseSchema.parse(await response.json());
1988
2066
  return transformBranchDiffResult(raw);
1989
2067
  }
@@ -2022,8 +2100,9 @@ var RepoImpl = class {
2022
2100
  ...typeof options.query.caseSensitive === "boolean" ? { case_sensitive: options.query.caseSensitive } : {}
2023
2101
  }
2024
2102
  };
2025
- if (options.ref) {
2026
- body.rev = options.ref;
2103
+ const ref = options.ref?.trim() || options.rev?.trim();
2104
+ if (ref) {
2105
+ body.ref = ref;
2027
2106
  }
2028
2107
  if (Array.isArray(options.paths) && options.paths.length > 0) {
2029
2108
  body.paths = options.paths;
@@ -2079,9 +2158,14 @@ var RepoImpl = class {
2079
2158
  if (options.ref) {
2080
2159
  body.ref = options.ref;
2081
2160
  }
2082
- const response = await this.api.post({ path: "repos/pull-upstream", body }, jwt);
2161
+ const response = await this.api.post(
2162
+ { path: "repos/pull-upstream", body },
2163
+ jwt
2164
+ );
2083
2165
  if (response.status !== 202) {
2084
- throw new Error(`Pull Upstream failed: ${response.status} ${await response.text()}`);
2166
+ throw new Error(
2167
+ `Pull Upstream failed: ${response.status} ${await response.text()}`
2168
+ );
2085
2169
  }
2086
2170
  return;
2087
2171
  }
@@ -2109,7 +2193,10 @@ var RepoImpl = class {
2109
2193
  if (options.targetIsEphemeral === true) {
2110
2194
  body.target_is_ephemeral = true;
2111
2195
  }
2112
- const response = await this.api.post({ path: "repos/branches/create", body }, jwt);
2196
+ const response = await this.api.post(
2197
+ { path: "repos/branches/create", body },
2198
+ jwt
2199
+ );
2113
2200
  const raw = createBranchResponseSchema.parse(await response.json());
2114
2201
  return transformCreateBranchResult(raw);
2115
2202
  }
@@ -2119,7 +2206,9 @@ var RepoImpl = class {
2119
2206
  throw new Error("restoreCommit targetBranch is required");
2120
2207
  }
2121
2208
  if (targetBranch.startsWith("refs/")) {
2122
- throw new Error("restoreCommit targetBranch must not include refs/ prefix");
2209
+ throw new Error(
2210
+ "restoreCommit targetBranch must not include refs/ prefix"
2211
+ );
2123
2212
  }
2124
2213
  const targetCommitSha = options?.targetCommitSha?.trim();
2125
2214
  if (!targetCommitSha) {
@@ -2155,7 +2244,9 @@ var RepoImpl = class {
2155
2244
  const committerName = options.committer.name?.trim();
2156
2245
  const committerEmail = options.committer.email?.trim();
2157
2246
  if (!committerName || !committerEmail) {
2158
- throw new Error("restoreCommit committer name and email are required when provided");
2247
+ throw new Error(
2248
+ "restoreCommit committer name and email are required when provided"
2249
+ );
2159
2250
  }
2160
2251
  metadata.committer = {
2161
2252
  name: committerName,
@@ -2273,7 +2364,7 @@ var GitStorage = class _GitStorage {
2273
2364
  let resolvedDefaultBranch;
2274
2365
  if (baseRepo) {
2275
2366
  if ("id" in baseRepo) {
2276
- const baseRepoToken = await this.generateJWT(`${this.options.name}/${baseRepo.id}`, {
2367
+ const baseRepoToken = await this.generateJWT(baseRepo.id, {
2277
2368
  permissions: ["git:read"],
2278
2369
  ttl
2279
2370
  });
@@ -2305,10 +2396,14 @@ var GitStorage = class _GitStorage {
2305
2396
  path: "repos",
2306
2397
  body: {
2307
2398
  ...baseRepoOptions && { base_repo: baseRepoOptions },
2308
- ...resolvedDefaultBranch && { default_branch: resolvedDefaultBranch }
2399
+ ...resolvedDefaultBranch && {
2400
+ default_branch: resolvedDefaultBranch
2401
+ }
2309
2402
  }
2310
2403
  } : "repos";
2311
- const resp = await this.api.post(createRepoPath, jwt, { allowedStatus: [409] });
2404
+ const resp = await this.api.post(createRepoPath, jwt, {
2405
+ allowedStatus: [409]
2406
+ });
2312
2407
  if (resp.status === 409) {
2313
2408
  throw new Error("Repository already exists");
2314
2409
  }
@@ -2362,7 +2457,12 @@ var GitStorage = class _GitStorage {
2362
2457
  }
2363
2458
  const body = await resp.json();
2364
2459
  const defaultBranch = body.default_branch ?? "main";
2365
- return new RepoImpl(options.id, defaultBranch, this.options, this.generateJWT.bind(this));
2460
+ return new RepoImpl(
2461
+ options.id,
2462
+ defaultBranch,
2463
+ this.options,
2464
+ this.generateJWT.bind(this)
2465
+ );
2366
2466
  }
2367
2467
  /**
2368
2468
  * Delete a repository by ID
@@ -2375,7 +2475,9 @@ var GitStorage = class _GitStorage {
2375
2475
  permissions: ["repo:write"],
2376
2476
  ttl
2377
2477
  });
2378
- const resp = await this.api.delete("repos/delete", jwt, { allowedStatus: [404, 409] });
2478
+ const resp = await this.api.delete("repos/delete", jwt, {
2479
+ allowedStatus: [404, 409]
2480
+ });
2379
2481
  if (resp.status === 404) {
2380
2482
  throw new Error("Repository not found");
2381
2483
  }
@@ -2401,7 +2503,10 @@ var GitStorage = class _GitStorage {
2401
2503
  */
2402
2504
  async generateJWT(repoId, options) {
2403
2505
  const permissions = options?.permissions || ["git:write", "git:read"];
2404
- const ttl = resolveInvocationTtlSeconds(options, this.options.defaultTTL ?? 365 * 24 * 60 * 60);
2506
+ const ttl = resolveInvocationTtlSeconds(
2507
+ options,
2508
+ this.options.defaultTTL ?? 365 * 24 * 60 * 60
2509
+ );
2405
2510
  const now = Math.floor(Date.now() / 1e3);
2406
2511
  const payload = {
2407
2512
  iss: this.options.name,