@pierre/storage 0.1.2 → 0.1.3

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.ts CHANGED
@@ -568,14 +568,26 @@ interface FileDiff extends DiffFileBase {
568
568
  }
569
569
  interface FilteredFile extends DiffFileBase {
570
570
  }
571
- interface CreateCommitOptions extends GitStorageInvocationOptions {
572
- targetBranch: string;
571
+ interface CreateCommitBaseOptions extends GitStorageInvocationOptions {
573
572
  commitMessage: string;
574
573
  expectedHeadSha?: string;
574
+ baseBranch?: string;
575
575
  author: CommitSignature;
576
576
  committer?: CommitSignature;
577
577
  signal?: AbortSignal;
578
578
  }
579
+ interface CreateCommitBranchOptions extends CreateCommitBaseOptions {
580
+ targetBranch: string;
581
+ targetRef?: never;
582
+ }
583
+ /**
584
+ * @deprecated Use {@link CreateCommitBranchOptions} instead.
585
+ */
586
+ interface LegacyCreateCommitOptions extends CreateCommitBaseOptions {
587
+ targetBranch?: never;
588
+ targetRef: string;
589
+ }
590
+ type CreateCommitOptions = CreateCommitBranchOptions | LegacyCreateCommitOptions;
579
591
  interface CommitSignature {
580
592
  name: string;
581
593
  email: string;
@@ -830,4 +842,4 @@ declare class GitStorage {
830
842
  declare function createClient(options: GitStorageOptions): GitStorage;
831
843
  type StorageOptions = GitStorageOptions;
832
844
 
833
- export { ApiError, type BaseRepo, type BlobLike, type BranchInfo, type CommitBuilder, type CommitFileOptions, type CommitFileSource, type CommitInfo, type CommitResult, type CommitSignature, type CommitTextFileOptions, type CreateCommitOptions, type CreateRepoOptions, type DiffFileBase, type DiffFileState, type DiffStats, type FileDiff, type FileLike, type FilteredFile, type FindOneOptions, type GetBranchDiffOptions, type GetBranchDiffResponse, type GetBranchDiffResult, type GetCommitDiffOptions, type GetCommitDiffResponse, type GetCommitDiffResult, type GetFileOptions, type GetRemoteURLOptions, type GitFileMode, GitStorage, type GitStorageOptions, type ListBranchesOptions, type ListBranchesResponse, type ListBranchesResult, type ListCommitsOptions, type ListCommitsResponse, type ListCommitsResult, type ListFilesOptions, type ListFilesResponse, type ListFilesResult, type OverrideableGitStorageOptions, type ParsedWebhookSignature, type PullUpstreamOptions, type RawBranchInfo, type RawCommitInfo, type RawFileDiff, type RawFilteredFile, type RawWebhookPushEvent, type ReadableStreamLike, type ReadableStreamReaderLike, type RefUpdate, RefUpdateError, type RefUpdateReason, type Repo, 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 };
845
+ export { ApiError, type BaseRepo, type BlobLike, type BranchInfo, type CommitBuilder, type CommitFileOptions, type CommitFileSource, type CommitInfo, type CommitResult, type CommitSignature, type CommitTextFileOptions, type CreateCommitBranchOptions, type CreateCommitOptions, type CreateRepoOptions, type DiffFileBase, type DiffFileState, type DiffStats, type FileDiff, type FileLike, type FilteredFile, type FindOneOptions, type GetBranchDiffOptions, type GetBranchDiffResponse, type GetBranchDiffResult, type GetCommitDiffOptions, type GetCommitDiffResponse, type GetCommitDiffResult, type GetFileOptions, type GetRemoteURLOptions, type GitFileMode, GitStorage, type GitStorageOptions, type LegacyCreateCommitOptions, type ListBranchesOptions, type ListBranchesResponse, type ListBranchesResult, type ListCommitsOptions, type ListCommitsResponse, type ListCommitsResult, type ListFilesOptions, type ListFilesResponse, type ListFilesResult, type OverrideableGitStorageOptions, type ParsedWebhookSignature, type PullUpstreamOptions, type RawBranchInfo, type RawCommitInfo, type RawFileDiff, type RawFilteredFile, type RawWebhookPushEvent, type ReadableStreamLike, type ReadableStreamReaderLike, type RefUpdate, RefUpdateError, type RefUpdateReason, type Repo, 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
@@ -151,6 +151,7 @@ var errorEnvelopeSchema = z.object({
151
151
  // src/commit.ts
152
152
  var MAX_CHUNK_BYTES = 4 * 1024 * 1024;
153
153
  var DEFAULT_TTL_SECONDS = 60 * 60;
154
+ var HEADS_REF_PREFIX = "refs/heads/";
154
155
  var BufferCtor = globalThis.Buffer;
155
156
  var CommitBuilderImpl = class {
156
157
  options;
@@ -159,26 +160,18 @@ var CommitBuilderImpl = class {
159
160
  operations = [];
160
161
  sent = false;
161
162
  constructor(deps) {
162
- this.options = { ...deps.options };
163
+ this.options = normalizeCommitOptions(deps.options);
163
164
  this.getAuthToken = deps.getAuthToken;
164
165
  this.transport = deps.transport;
165
- const trimmedTarget = this.options.targetBranch?.trim();
166
166
  const trimmedMessage = this.options.commitMessage?.trim();
167
167
  const trimmedAuthorName = this.options.author?.name?.trim();
168
168
  const trimmedAuthorEmail = this.options.author?.email?.trim();
169
- if (!trimmedTarget) {
170
- throw new Error("createCommit targetBranch is required");
171
- }
172
- if (trimmedTarget.startsWith("refs/")) {
173
- throw new Error("createCommit targetBranch must not include refs/ prefix");
174
- }
175
169
  if (!trimmedMessage) {
176
170
  throw new Error("createCommit commitMessage is required");
177
171
  }
178
172
  if (!trimmedAuthorName || !trimmedAuthorEmail) {
179
173
  throw new Error("createCommit author name and email are required");
180
174
  }
181
- this.options.targetBranch = trimmedTarget;
182
175
  this.options.commitMessage = trimmedMessage;
183
176
  this.options.author = {
184
177
  name: trimmedAuthorName,
@@ -187,6 +180,17 @@ var CommitBuilderImpl = class {
187
180
  if (typeof this.options.expectedHeadSha === "string") {
188
181
  this.options.expectedHeadSha = this.options.expectedHeadSha.trim();
189
182
  }
183
+ if (typeof this.options.baseBranch === "string") {
184
+ const trimmedBase = this.options.baseBranch.trim();
185
+ if (trimmedBase === "") {
186
+ delete this.options.baseBranch;
187
+ } else {
188
+ if (trimmedBase.startsWith("refs/")) {
189
+ throw new Error("createCommit baseBranch must not include refs/ prefix");
190
+ }
191
+ this.options.baseBranch = trimmedBase;
192
+ }
193
+ }
190
194
  }
191
195
  addFile(path, source, options) {
192
196
  this.ensureNotSent();
@@ -271,6 +275,9 @@ var CommitBuilderImpl = class {
271
275
  if (this.options.expectedHeadSha) {
272
276
  metadata.expected_head_sha = this.options.expectedHeadSha;
273
277
  }
278
+ if (this.options.baseBranch) {
279
+ metadata.base_branch = this.options.baseBranch;
280
+ }
274
281
  if (this.options.committer) {
275
282
  metadata.committer = {
276
283
  name: this.options.committer.name,
@@ -551,6 +558,62 @@ function randomContentId() {
551
558
  const random = Math.random().toString(36).slice(2);
552
559
  return `cid-${Date.now().toString(36)}-${random}`;
553
560
  }
561
+ function normalizeCommitOptions(options) {
562
+ return {
563
+ targetBranch: resolveTargetBranch(options),
564
+ commitMessage: options.commitMessage,
565
+ expectedHeadSha: options.expectedHeadSha,
566
+ baseBranch: options.baseBranch,
567
+ author: options.author,
568
+ committer: options.committer,
569
+ signal: options.signal,
570
+ ttl: options.ttl
571
+ };
572
+ }
573
+ function resolveTargetBranch(options) {
574
+ const branchCandidate = typeof options.targetBranch === "string" ? options.targetBranch.trim() : "";
575
+ if (branchCandidate) {
576
+ return normalizeBranchName(branchCandidate);
577
+ }
578
+ if (hasLegacyTargetRef(options)) {
579
+ return normalizeLegacyTargetRef(options.targetRef);
580
+ }
581
+ throw new Error("createCommit targetBranch is required");
582
+ }
583
+ function normalizeBranchName(value) {
584
+ const trimmed = value.trim();
585
+ if (!trimmed) {
586
+ throw new Error("createCommit targetBranch is required");
587
+ }
588
+ if (trimmed.startsWith(HEADS_REF_PREFIX)) {
589
+ const branch = trimmed.slice(HEADS_REF_PREFIX.length).trim();
590
+ if (!branch) {
591
+ throw new Error("createCommit targetBranch is required");
592
+ }
593
+ return branch;
594
+ }
595
+ if (trimmed.startsWith("refs/")) {
596
+ throw new Error("createCommit targetBranch must not include refs/ prefix");
597
+ }
598
+ return trimmed;
599
+ }
600
+ function normalizeLegacyTargetRef(ref) {
601
+ const trimmed = ref.trim();
602
+ if (!trimmed) {
603
+ throw new Error("createCommit targetRef is required");
604
+ }
605
+ if (!trimmed.startsWith(HEADS_REF_PREFIX)) {
606
+ throw new Error("createCommit targetRef must start with refs/heads/");
607
+ }
608
+ const branch = trimmed.slice(HEADS_REF_PREFIX.length).trim();
609
+ if (!branch) {
610
+ throw new Error("createCommit targetRef must include a branch name");
611
+ }
612
+ return branch;
613
+ }
614
+ function hasLegacyTargetRef(options) {
615
+ return typeof options.targetRef === "string";
616
+ }
554
617
  function createCommitBuilder(deps) {
555
618
  return new CommitBuilderImpl(deps);
556
619
  }